#!/usr/bin/env bash # Hook: exit-protocol (PreToolUse, matcher: .*) — catch-all. # Enforces the project's definition of "done": if WORKING.md has any unchecked # task, inject context ordering the agent to finish them before responding. # This prevents premature "Done" responses. set -euo pipefail # Required by the hook protocol: consume stdin. cat >/dev/null REPO_ROOT="${CRUSH_PROJECT_DIR:-$(pwd)}" WORKING_FILE="$REPO_ROOT/WORKING.md" if [ -f "$WORKING_FILE" ]; then UNCHECKED="$(grep -cF -- '- [ ]' "$WORKING_FILE" || true)" if [ "$UNCHECKED" -gt 0 ]; then TASKS_JSON="$(grep -F -- '- [ ]' "$WORKING_FILE" \ | sed 's/\\/\\\\/g; s/"/\\"/g' \ | awk -v ORS='\\n' '{print}' | sed 's/\\n$//')" printf '{"context": "STOP. WORKING.md has %s unfinished task(s). You cannot declare work done or respond to the user while these remain:\\n%s\\nFinish them now. Do not respond until all are checked. Then clear WORKING.md and commit."}\n' \ "$UNCHECKED" "$TASKS_JSON" exit 0 fi fi echo '{}'