Files
loop-loop/lib/hooks.sh
Sheldon Finlay b3d263258a fix: critical bugs, stale refs, README rewrite, security fixes
- Fix evaluator bypass on last story (moved completion check)
- Fix all stale command name references across README, loop.sh, skills, plugin.json
- Fix explore evaluator false rejects (.loop/ files are expected)
- Fix stderr capture order in headless mode
- Fix shell injection risk in hooks.sh python fallback
- Remove .DS_Store from tracking
- Rewrite README to match current architecture (single entry point, tmux, optional tools)
- Add XcodeBuildMCP and iOS simulator MCP to optional tools docs
2026-03-27 14:58:01 -04:00

52 lines
1.8 KiB
Bash

#!/bin/bash
# Stop hook management for the agent loop.
#
# The Stop hook sends SIGINT to the loop's parent process when a claude session
# finishes. This is how claude signals "I'm done" back to the bash loop —
# the Ralph pattern (ghuntley.com/ralph).
#
# Without this hook, claude would exit to an interactive prompt instead of
# returning control to the loop script.
SETTINGS_FILE="${PROJECT_ROOT}/.claude/settings.local.json"
install_hooks() {
if [ ! -f "$SETTINGS_FILE" ]; then
mkdir -p "$(dirname "$SETTINGS_FILE")"
echo '{}' > "$SETTINGS_FILE"
fi
if command -v jq &>/dev/null; then
jq '.hooks.Stop = [{"matcher": "", "hooks": [{"type": "command", "command": "kill -INT $PPID || true"}]}]' \
"$SETTINGS_FILE" > "${SETTINGS_FILE}.tmp" && mv "${SETTINGS_FILE}.tmp" "$SETTINGS_FILE"
else
LOOP_SETTINGS="$SETTINGS_FILE" python3 -c "
import json, os
p = os.environ['LOOP_SETTINGS']
s = json.load(open(p)) if os.path.exists(p) else {}
s.setdefault('hooks', {})['Stop'] = [{'matcher': '', 'hooks': [{'type': 'command', 'command': 'kill -INT \$PPID || true'}]}]
json.dump(s, open(p, 'w'), indent=2)
"
fi
log "Stop hook installed"
}
remove_hooks() {
if [ -f "$SETTINGS_FILE" ]; then
if command -v jq &>/dev/null; then
jq 'del(.hooks.Stop)' "$SETTINGS_FILE" > "${SETTINGS_FILE}.tmp" && mv "${SETTINGS_FILE}.tmp" "$SETTINGS_FILE"
jq 'if .hooks == {} then del(.hooks) else . end' "$SETTINGS_FILE" > "${SETTINGS_FILE}.tmp" && mv "${SETTINGS_FILE}.tmp" "$SETTINGS_FILE"
else
LOOP_SETTINGS="$SETTINGS_FILE" python3 -c "
import json, os
p = os.environ['LOOP_SETTINGS']
s = json.load(open(p))
s.get('hooks', {}).pop('Stop', None)
if not s.get('hooks'): s.pop('hooks', None)
json.dump(s, open(p, 'w'), indent=2)
"
fi
log "Stop hook removed"
fi
}