Summary
Add a Stop hook that fires when the agent wants to complete a task, enabling quality enforcement.
Why It's Needed
- Quality Gates: Ensure tests ran before claiming "done"
- Enforce Standards: Require commit, lint pass, etc.
- Prevent Premature Completion: Block if work is incomplete
- Consistency: Same standards applied every session
Hook Interface
interface StopInput {
sessionId: string
reason: string // Agent's completion message
toolsUsed: string[] // Tools invoked this session
filesModified: string[] // Files changed
filesCreated: string[] // New files
duration: number // Session duration in ms
}
interface StopOutput {
decision: "approve" | "block"
continuePrompt?: string // If blocked, what to tell agent
}
Example: Require Tests
export const requireTestsOnStop: StopHook = async (input) => {
// Check if source files were modified
const sourceFiles = input.filesModified.filter(f =>
f.endsWith(".ts") && !f.includes(".test.") && !f.includes(".spec.")
)
if (sourceFiles.length === 0) {
return { decision: "approve" }
}
// Check if tests were run
const testCommands = ["npm test", "bun test", "vitest", "jest"]
const testsRan = input.toolsUsed.some(t =>
testCommands.some(cmd => t.includes(cmd))
)
if (!testsRan) {
return {
decision: "block",
continuePrompt: `You modified ${sourceFiles.length} source files but didn't run tests. Please run tests before completing.`
}
}
return { decision: "approve" }
}
Built-in Stop Hooks (Optional)
require-tests
- Block if source files changed but no test command ran
require-lint
- Block if files changed but no lint command ran
require-commit
- Block if files modified but not committed
no-console-log
- Block if console.log statements were added
no-todo-comments
- Warn if TODO comments were added
Configuration
{
"hooks": {
"builtin": {
"require-tests-on-stop": false,
"require-lint-on-stop": false,
"require-commit-on-stop": false
},
"Stop": [
{
"name": "custom-quality-gate",
"script": ".codetyper/hooks/quality.ts"
}
]
}
}
Acceptance Criteria
Effort Estimate
1 day
Depends On
Summary
Add a Stop hook that fires when the agent wants to complete a task, enabling quality enforcement.
Why It's Needed
Hook Interface
Example: Require Tests
Built-in Stop Hooks (Optional)
require-tests
require-lint
require-commit
no-console-log
no-todo-comments
Configuration
{ "hooks": { "builtin": { "require-tests-on-stop": false, "require-lint-on-stop": false, "require-commit-on-stop": false }, "Stop": [ { "name": "custom-quality-gate", "script": ".codetyper/hooks/quality.ts" } ] } }Acceptance Criteria
Effort Estimate
1 day
Depends On