fix(agent hooks): wire hooks into real harness entry points and fix payload parsing

Claude Code never reads a standalone .claude/hooks.json, so the PostToolUse and
Stop pipeline is moved into .claude/settings.json and hooks.json is removed;
.cursor/hooks.json is rewritten in Cursor's version+afterFileEdit/stop schema;
.codex/hooks.json is already Codex-valid and stays. The shared scripts now
parse both the Cursor file_path and Claude/Codex tool_input.file_path stdin
shapes and normalize absolute paths, so the format, yarn-install, and
react-pattern-review hooks stop being silent no-ops. verify.sh blocks with
exit 2 plus a stderr reason, guards stop_hook_active, and skips clean trees;
react-pattern-review surfaces its reminder via hookSpecificOutput on
PostToolUse; sync-git-branches no longer misreports open PRs as merged. The
validator now checks that the three harness-specific entry points wire the
same hook scripts instead of requiring byte-identical hooks.json copies.
This commit is contained in:
Tommaso Casaburi
2026-07-03 13:58:36 +07:00
parent 0166f2f4e8
commit 1ac3e5883b
9 changed files with 190 additions and 123 deletions
+20 -3
View File
@@ -11,10 +11,24 @@ if [ "${1:-}" = "--advisory" ]; then
shift
fi
cat > /dev/null
input="$(cat)"
# Avoid infinite stop loops: when a previous blocking verify already forced the
# agent to continue, Claude Code/Codex set stop_hook_active on the next Stop.
if command -v jq >/dev/null 2>&1; then
if [ "$(printf '%s' "$input" | jq -r '.stop_hook_active // false' 2>/dev/null)" = "true" ]; then
exit 0
fi
fi
cd "$(git rev-parse --show-toplevel 2>/dev/null || pwd)" || exit 0
# Read-only sessions change nothing; skip the expensive full verification.
if git rev-parse --is-inside-work-tree >/dev/null 2>&1 && [ -z "$(git status --porcelain 2>/dev/null)" ]; then
echo "Working tree clean; skipping verification."
exit 0
fi
cleanup_generated_dir() {
local path="$1"
@@ -76,8 +90,11 @@ if [ "$failures" -ne 0 ]; then
exit 0
fi
echo "Verification failed."
exit 1
# Exit 2 is the only exit code that blocks the stop and feeds the reason back
# to the agent in Claude Code and Codex; exit 1 would be a silent, non-blocking
# error. The full logs are on stdout above; keep the stderr reason short.
echo "Verification failed: build, lint, or type-check reported errors (see hook output). Fix them before finishing, or rerun with AGENT_VERIFY_MODE=advisory to intentionally stop on a broken tree." >&2
exit 2
fi
echo "Verification complete."