Skip to content

fix(hooks): anchor plan-gate to project root + exempt plan file#876

Open
thecodingshrimp wants to merge 1 commit into
notque:mainfrom
thecodingshrimp:fix/plan-gate-hook-cwd-resolution
Open

fix(hooks): anchor plan-gate to project root + exempt plan file#876
thecodingshrimp wants to merge 1 commit into
notque:mainfrom
thecodingshrimp:fix/plan-gate-hook-cwd-resolution

Conversation

@thecodingshrimp

Copy link
Copy Markdown
Contributor

Summary

Two defects in pretool-plan-gate.py caused false denials and false allows. The hook now anchors task_plan.md lookup to the project root (not session cwd), and never gates writes to task_plan.md itself.

Changes

  • hooks/pretool-plan-gate.py — add _find_project_root (walks .git; respects CLAUDE_PROJECT_DIR env); exempt task_plan.md target from gating; update docstring to state all agents//skills/ files are gated regardless of extension
  • tests/test_plan_gate_hook.py — add 7 TDD tests covering: deny on missing plan, allow with plan at git root + deep cwd, allow writing task_plan.md, allow non-gated path, PLAN_GATE_BYPASS=1, CLAUDE_PROJECT_DIR override, docstring accuracy

Notes

High-risk path (hooks/pretool-plan-gate.py) — behavioral gate change; hook was blocking the plan file itself, preventing the plans skill from creating the unblocker. Tests were written before fixes and verified to fail on unfixed code.

Fix three defects in pretool-plan-gate.py per docs/handoff-plan-gate-hook-fix.md:

- Defect 1 (cwd resolution): add _find_project_root() — resolves via
  CLAUDE_PROJECT_DIR, then nearest .git ancestor, then cwd. A task_plan.md
  at the git root now satisfies the gate from any subdirectory depth,
  instead of only when the session pwd is the repo root.
- Defect 2 (chicken-and-egg): short-circuit before the gate check so a file
  named task_plan.md is never blocked, even inside a gated subtree.
- Defect 3 (docstring drift): docstring and inline comments now state that
  all files under agents/ and skills/ are gated regardless of extension,
  because SKILL.md and agent .md files are behavioral specs.

Add tests/test_plan_gate_hook.py covering all five handoff scenarios.
PLAN_GATE_BYPASS=1 escape hatch and gated-directory scope unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant