fix: use env var instead of tmux check for Stop hook scoping
The tmux display-message approach had edge cases: it could succeed outside tmux, fail on first iteration, or behave differently depending on tmux socket state. Replace with AGENT_LOOP_ACTIVE env var exported by loop.sh. CC sessions spawned by the loop inherit it; interactive CC sessions don't. Simple, no external dependencies, no race conditions.
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
"name": "agent-loop",
|
"name": "agent-loop",
|
||||||
"source": "./",
|
"source": "./",
|
||||||
"description": "Autonomous generator-evaluator agent loop for long-running coding tasks. Plan interactively, then execute with full visibility.",
|
"description": "Autonomous generator-evaluator agent loop for long-running coding tasks. Plan interactively, then execute with full visibility.",
|
||||||
"version": "0.10.0",
|
"version": "0.10.1",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Sheldon"
|
"name": "Sheldon"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "agent-loop",
|
"name": "agent-loop",
|
||||||
"version": "0.10.0",
|
"version": "0.10.1",
|
||||||
"description": "Autonomous generator-evaluator agent loop for long-running coding tasks. Run /agent-loop:run to start.",
|
"description": "Autonomous generator-evaluator agent loop for long-running coding tasks. Run /agent-loop:run to start.",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Sheldon"
|
"name": "Sheldon"
|
||||||
|
|||||||
@@ -14,11 +14,10 @@
|
|||||||
|
|
||||||
SETTINGS_FILE="${PROJECT_ROOT}/.claude/settings.local.json"
|
SETTINGS_FILE="${PROJECT_ROOT}/.claude/settings.local.json"
|
||||||
|
|
||||||
# The hook command checks we're inside the agent-loop tmux session before killing.
|
# The hook checks AGENT_LOOP_ACTIVE before killing. This env var is exported by
|
||||||
# This prevents the hook from affecting other CC sessions open in the same project.
|
# loop.sh and inherited by CC sessions it spawns. Interactive CC sessions in the
|
||||||
# IMPORTANT: Must check $TMUX first — tmux display-message can succeed even outside
|
# same project won't have it set, so the hook is a no-op for them.
|
||||||
# tmux by falling back to the most recently created session, which would be agent-loop.
|
HOOK_COMMAND='[ "${AGENT_LOOP_ACTIVE:-}" = "1" ] && kill -INT $PPID || true'
|
||||||
HOOK_COMMAND='[ -n "$TMUX" ] && tmux display-message -p "#{session_name}" 2>/dev/null | grep -q "^agent-loop$" && kill -INT $PPID || true'
|
|
||||||
|
|
||||||
install_hooks() {
|
install_hooks() {
|
||||||
if [ ! -f "$SETTINGS_FILE" ]; then
|
if [ ! -f "$SETTINGS_FILE" ]; then
|
||||||
|
|||||||
1
loop.sh
1
loop.sh
@@ -111,6 +111,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
export ITERATION=0 MAX_ITERATIONS MODE
|
export ITERATION=0 MAX_ITERATIONS MODE
|
||||||
|
export AGENT_LOOP_ACTIVE=1
|
||||||
|
|
||||||
# --- Validate ---
|
# --- Validate ---
|
||||||
if [[ ! "$MODE" =~ ^(implement|explore|fix)$ ]]; then
|
if [[ ! "$MODE" =~ ^(implement|explore|fix)$ ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user