38 lines
1.7 KiB
Markdown
38 lines
1.7 KiB
Markdown
# SPEC: Git Pre-Commit Hook for Task Enforcement
|
|||
|
|
|
||
|
|
## Overview
|
||
|
|
|
||
|
|
The `.rules.md` says "All changes must go through a task in tasks/{name}/" but nothing enforces it. The agent repeatedly makes ad-hoc edits and only creates tasks retroactively (or not at all). A pre-commit git hook mechanically blocks commits that lack a corresponding task.
|
||
|
|
|
||
|
|
## Root Cause
|
||
|
|
|
||
|
|
The rule is passive (a file on disk) and relies on the agent remembering to check it. Every session starts fresh — past failures don't carry over. The agent has no active enforcement.
|
||
|
|
|
||
|
|
## Solution
|
||
|
|
|
||
|
|
A `scripts/pre-commit-hook.sh` that:
|
||
|
|
|
||
|
|
1. Gets the list of changed files (staged + unstaged)
|
||
|
|
2. Checks if there's a task in `tasks/` whose SPEC.md keywords match the changed files
|
||
|
|
3. If no matching task found, prints the changed files and asks: "Continue without a task? (y/N)"
|
||
|
|
4. If the user says no, exits non-zero and blocks the commit
|
||
|
|
|
||
|
|
The hook is installed via `scripts/install-hooks.sh` which copies it to `.git/hooks/pre-commit`.
|
||
|
|
|
||
|
|
## Files
|
||
|
|
|
||
|
|
- `scripts/pre-commit-hook.sh` — the hook script
|
||
|
|
- `scripts/install-hooks.sh` — installer
|
||
|
|
|
||
|
|
## Acceptance Criteria
|
||
|
|
|
||
|
|
- [ ] `scripts/pre-commit-hook.sh` blocks commits that change files without a matching task
|
||
|
|
- [ ] `scripts/install-hooks.sh` installs the hook into `.git/hooks/pre-commit`
|
||
|
|
- [ ] Hook allows commits when user confirms (y) despite no task
|
||
|
|
- [ ] Hook allows commits when a matching task exists in tasks/
|
||
|
|
- [ ] README updated to mention hook installation
|
||
|
|
|
||
|
|
## Why This Fix Works
|
||
|
|
|
||
|
|
A pre-commit hook runs before every commit. The agent cannot bypass it without intentionally deciding to — and even then, the prompt forces conscious acknowledgment ("Continue without a task?") rather than simply forgetting.
|