fix(skills): claude review items 4-7 (subscribe timeout, atomic_dump_yaml, hardcoded paths, lifecycle helper)

Item 4: --subscribe gains --timeout/--idle-timeout (idle default raised
        120s->600s, 0=disable); connect-error AND non-zero CONNACK now fall
        back to a polling loop. SKILL.md matches actual behaviour.
Item 5: --subscribe terminal-event YAML writes routed through
        lib.sh::atomic_dump_yaml (flock + schema-validate + .bak).
Item 6: removed hardcoded /home/godopu16/PuKi fallbacks in lib.sh,
        status.sh (x2) and reconcile.sh; paths now BASH_SOURCE-relative.
Item 7: lib.sh::delegate_publish_event helper consolidates the 4 duplicated
        lifecycle publish blocks; delete cwd|jid parser replaced with JSON.

Also: subscribe loop runs under the project venv python (paho) and delegates
all YAML work to atomic_dump_yaml on system python3 (PyYAML), since neither
interpreter has both modules — the original env_python path could never import
paho. Items 3 + 8 out of scope (per user). Verified on -L claude-phase4-test
(kill-server after).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-19 15:11:09 +00:00
parent 0eb1d94a9c
commit 06f076e9cc
7 changed files with 237 additions and 197 deletions
@@ -61,9 +61,10 @@ if [ -z "$AGENT" ]; then
esac
fi
# 세션이 YAML 에 있는지 + 해당 row 의 워크스페이스 cwd 및 delegate_job_id 추출
# 세션이 YAML 에 있는지 + 해당 row 의 워크스페이스 cwd 및 delegate_job_id 추출.
# JSON 으로 emit — cwd 에 '|' 가 들어가도 안전 (review item 7; 기존 cwd|jid 파서 대체).
MAPPED_DATA=$(env_python "$AGENT_SESSIONS_YAML" SESSION_NAME="$SESSION_NAME" <<'PYEOF'
import os, yaml
import os, json, yaml
name = os.environ['SESSION_NAME']
with open(os.environ['YAML_PATH']) as f:
d = yaml.safe_load(f) or {}
@@ -71,7 +72,7 @@ for s in d.get('tmux_sessions', []):
if s.get('name') == name:
cwd = (s.get('pane') or {}).get('cwd', '')
jid = s.get('delegate_job_id', '') or ''
print(f"{cwd}|{jid}")
print(json.dumps({"cwd": cwd, "job_id": jid}))
raise SystemExit(0)
raise SystemExit(7)
PYEOF
@@ -80,8 +81,8 @@ PYEOF
exit 1
}
TARGET_CWD="${MAPPED_DATA%|*}"
DELEGATE_JOB_ID="${MAPPED_DATA#*|}"
TARGET_CWD=$(printf '%s' "$MAPPED_DATA" | python3 -c 'import sys,json; print(json.load(sys.stdin).get("cwd",""))')
DELEGATE_JOB_ID=$(printf '%s' "$MAPPED_DATA" | python3 -c 'import sys,json; print(json.load(sys.stdin).get("job_id",""))')
# purge 확인
if [ "$PURGE" = "1" ] && [ "$YES" != "1" ]; then
@@ -109,19 +110,7 @@ if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
LAST_STATUS=$(tmux capture-pane -t "$SESSION_NAME" -p -S -10 2>/dev/null | tr '\n' ' ' | head -c 500 || true)
fi
if [ -n "$DELEGATE_JOB_ID" ]; then
py_bin="python3"
d_dir="$(dirname "${BASH_SOURCE[0]}")"
while [ "$d_dir" != "/" ] && [ -n "$d_dir" ]; do
if [ -x "$d_dir/.venv/bin/python" ]; then
py_bin="$d_dir/.venv/bin/python"
break
fi
d_dir="$(dirname "$d_dir")"
done
pub_script="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/delegate-job/scripts/publish_event.py"
"$py_bin" "$pub_script" --job "$DELEGATE_JOB_ID" --event progress --detail "terminating" || true
fi
delegate_publish_event "$DELEGATE_JOB_ID" progress "terminating"
# hard 모드면 tmux 죽임
if [ "$MODE" = "hard" ] && [ "$TMUX_ALIVE" = "1" ]; then
@@ -206,19 +195,7 @@ elif purge and not purge_uuid:
print(f"updated: {name} status={target['status']}", flush=True)
PYEOF
if [ -n "$DELEGATE_JOB_ID" ]; then
py_bin="python3"
d_dir="$(dirname "${BASH_SOURCE[0]}")"
while [ "$d_dir" != "/" ] && [ -n "$d_dir" ]; do
if [ -x "$d_dir/.venv/bin/python" ]; then
py_bin="$d_dir/.venv/bin/python"
break
fi
d_dir="$(dirname "$d_dir")"
done
pub_script="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/delegate-job/scripts/publish_event.py"
"$py_bin" "$pub_script" --job "$DELEGATE_JOB_ID" --event completed --detail "session terminated" || true
fi
delegate_publish_event "$DELEGATE_JOB_ID" completed "session terminated"
echo
echo "=== delete complete ==="