mirror of
https://github.com/codeflash-ai/codeflash-agent.git
synced 2026-05-04 18:25:19 +00:00
58 lines
2.3 KiB
Bash
Executable file
58 lines
2.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Hook: check if github-app changes warrant a ROADMAP.md update.
|
|
# Runs as a Stop hook — if relevant source changes are detected,
|
|
# tells Claude to spawn a background agent for the analysis.
|
|
|
|
set -euo pipefail
|
|
|
|
ROADMAP="services/github-app/ROADMAP.md"
|
|
SRC_DIR="services/github-app/github_app/"
|
|
|
|
HOOK_INPUT=$(cat || true)
|
|
|
|
# Avoid re-triggering the Stop hook if Claude already re-entered after
|
|
# surfacing the roadmap reminder once.
|
|
if printf '%s' "$HOOK_INPUT" | grep -q '"stop_hook_active"[[:space:]]*:[[:space:]]*true'; then
|
|
exit 0
|
|
fi
|
|
|
|
# Get both staged and unstaged changes to source files.
|
|
diff_output=$(git diff HEAD -- "$SRC_DIR" 2>/dev/null || true)
|
|
|
|
# No source changes — nothing to check.
|
|
if [ -z "$diff_output" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
# Patterns that suggest roadmap-relevant changes.
|
|
roadmap_signals=(
|
|
'^\+.*class Config' # new config fields
|
|
'^\+.*@app\.(post|get|put|delete|patch)' # new endpoints
|
|
'^\+.*COMMAND_PROMPTS' # new slash commands
|
|
'^\+.*EVENT_HANDLERS' # new event handlers
|
|
'^\+.*async def handle_' # new handler functions
|
|
'^\+.*rate.limit' # rate limiting (roadmap item)
|
|
'^\+.*deploy' # deployment-related
|
|
'^\+.*TODO|FIXME|HACK|XXX' # explicit markers
|
|
)
|
|
|
|
pattern=$(IFS='|'; echo "${roadmap_signals[*]}")
|
|
|
|
matches=$(echo "$diff_output" | grep -cE "$pattern" 2>/dev/null || true)
|
|
|
|
if [ "$matches" -gt 0 ]; then
|
|
# Check if ROADMAP.md was also modified in this session.
|
|
roadmap_changed=$(git diff HEAD -- "$ROADMAP" 2>/dev/null | head -1 || true)
|
|
if [ -n "$roadmap_changed" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
# Dump the matched lines to a temp file so the agent can read them.
|
|
matches_file=$(mktemp /tmp/roadmap-signals-XXXXXX.txt)
|
|
echo "$diff_output" | grep -E "$pattern" > "$matches_file" 2>/dev/null || true
|
|
|
|
echo "[roadmap-hook] $matches roadmap-relevant signal(s) in $SRC_DIR but $ROADMAP was not updated. Spawn a background Agent (subagent_type=general-purpose, run_in_background=true) to: read $ROADMAP, read $matches_file for the flagged diff lines, and determine if any roadmap items should be added or updated. The agent should edit $ROADMAP directly if updates are warranted. Do NOT do this analysis yourself — delegate it." >&2
|
|
exit 2
|
|
fi
|
|
|
|
exit 0
|