Skip to content

feat: Add Stop hook for quality enforcement #108

Description

@CarGDev

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

  • Stop hook fires when agent wants to complete
  • Hook receives list of modified files and tools used
  • Hook can approve or block completion
  • Blocked completion returns prompt to agent
  • Built-in require-tests hook (optional)
  • Configurable per-project

Effort Estimate

1 day

Depends On

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthooksHooks systempriority-criticalCritical priority - implement first

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions