e9fc763d31
Renamed 6 skills directories to tmux-agent-orchestrate-* prefix: - multi-agent-create → tmux-agent-orchestrate-create - multi-agent-resume → tmux-agent-orchestrate-resume - multi-agent-delete → tmux-agent-orchestrate-delete - multi-agent-status → tmux-agent-orchestrate-status - agent-sessions-monitor → tmux-agent-orchestrate-monitor - delegate-job → tmux-agent-orchestrate-delegate-job Updated: - skills/lib.sh internal paths (delegate_submit_job etc.) - skills/tmux-agent-orchestrate-status/scripts/status.sh (monitor path) - skills/tmux-agent-orchestrate-monitor/scripts/reconcile.sh - .gitignore (HTML ignore patterns) - 6 SKILL.md frontmatter (name, related_skills, prereq_skills) and body - All script headers and Korean comments Notes: - tmux session naming convention unchanged (<slug>-creator-<agent>) — workspace identifier based, kept for backward compatibility - Existing 2 sessions in -L multi-agent-canary untouched - YAML delegate_job_id / agent-session (tmux:canary-...) preserved for log history compatibility Verified on isolated server -L agy-rename-test (kill-server after).
210 lines
7.9 KiB
Bash
Executable File
210 lines
7.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# delete_session.sh — tmux-agent-orchestrate-delete 의 부속 스크립트
|
|
# Usage:
|
|
# bash delete_session.sh --session <name> [--agent claude|agy] \
|
|
# [--mode soft|hard] [--purge-conversation] [--yes]
|
|
#
|
|
# mode:
|
|
# soft — YAML 을 status=archived 로 마크, tmux 세션은 그대로 둠 (P1-A:
|
|
# terminated 는 tmux 가 실제로 죽은 상태에만 사용)
|
|
# hard — tmux kill-session + YAML status=terminated
|
|
# --purge-conversation: --mode hard 일 때만. 삭제 대상 세션의 *워크스페이스에
|
|
# 격리된* conversation artifact 만 삭제 (P0-C). 전역
|
|
# agent_identities 를 참조하지 않음. resume 불가.
|
|
#
|
|
# Exit codes:
|
|
# 0 = success | 1 = YAML not found / not registered | 2 = invalid args
|
|
# 3 = interactive confirmation required (--yes 누락)
|
|
set -euo pipefail
|
|
|
|
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/lib.sh"
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: $0 --session <name> [--agent claude|agy] [--mode soft|hard] [--purge-conversation] [--yes]
|
|
|
|
Modes:
|
|
soft — update YAML to status=archived, leave tmux running
|
|
hard (default) — tmux kill-session + update YAML to status=terminated
|
|
EOF
|
|
}
|
|
|
|
SESSION_NAME=""
|
|
AGENT=""
|
|
MODE="hard" # "delete" 의 자연스러운 의미 = tmux 까지 종료
|
|
PURGE=0
|
|
YES=0
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--session) SESSION_NAME="$2"; shift 2 ;;
|
|
--agent) AGENT="$2"; shift 2 ;;
|
|
--mode) MODE="$2"; shift 2 ;;
|
|
--purge-conversation) PURGE=1; shift ;;
|
|
--yes) YES=1; shift ;;
|
|
-h|--help) usage; exit 0 ;;
|
|
*) echo "ERROR: unknown arg: $1" >&2; usage; exit 2 ;;
|
|
esac
|
|
done
|
|
[ -n "$SESSION_NAME" ] || { echo "ERROR: --session required" >&2; usage; exit 2; }
|
|
[ "$MODE" = "soft" ] || [ "$MODE" = "hard" ] || { echo "ERROR: --mode must be soft or hard" >&2; exit 2; }
|
|
[ -f "$AGENT_SESSIONS_YAML" ] || { echo "ERROR: $AGENT_SESSIONS_YAML not found" >&2; exit 1; }
|
|
|
|
export TMUX_SERVER_NAME="$(resolve_tmux_server "$SESSION_NAME")"
|
|
|
|
# --agent 미지정 시 이름 suffix 로 fallback (P1-F)
|
|
if [ -z "$AGENT" ]; then
|
|
case "$SESSION_NAME" in
|
|
*-creator-claude) AGENT=claude ;;
|
|
*-creator-agy) AGENT=agy ;;
|
|
*) echo "ERROR: cannot infer agent from '$SESSION_NAME'; pass --agent" >&2; exit 2 ;;
|
|
esac
|
|
fi
|
|
|
|
# 세션이 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, json, yaml
|
|
name = os.environ['SESSION_NAME']
|
|
with open(os.environ['YAML_PATH']) as f:
|
|
d = yaml.safe_load(f) or {}
|
|
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(json.dumps({"cwd": cwd, "job_id": jid}))
|
|
raise SystemExit(0)
|
|
raise SystemExit(7)
|
|
PYEOF
|
|
) || {
|
|
echo "ERROR: session '$SESSION_NAME' not in $AGENT_SESSIONS_YAML" >&2
|
|
exit 1
|
|
}
|
|
|
|
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
|
|
echo "DANGER: --purge-conversation will DELETE this workspace's on-disk conversation."
|
|
echo " workspace: ${TARGET_CWD:-<unknown>}"
|
|
echo " This means: no future tmux-agent-orchestrate-resume for this session."
|
|
echo " Re-run with --yes to confirm."
|
|
exit 3
|
|
fi
|
|
|
|
# purge 대상 UUID 를 워크스페이스 격리해서 해결 (P0-C — 전역 참조 금지)
|
|
PURGE_UUID=""
|
|
if [ "$PURGE" = "1" ] && [ -n "$TARGET_CWD" ]; then
|
|
PURGE_UUID=$(find_workspace_uuid "$TARGET_CWD" "$AGENT" || true)
|
|
fi
|
|
|
|
NOW_ISO=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
|
NOW_EPOCH=$(date +%s)
|
|
|
|
# tmux 상태 + 마지막 TUI 스냅샷 (살아있을 때만; capture-pane 내용은 env 로만 전달)
|
|
TMUX_ALIVE=0
|
|
LAST_STATUS=""
|
|
if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
|
|
TMUX_ALIVE=1
|
|
LAST_STATUS=$(tmux capture-pane -t "$SESSION_NAME" -p -S -10 2>/dev/null | tr '\n' ' ' | head -c 500 || true)
|
|
fi
|
|
|
|
delegate_publish_event "$DELEGATE_JOB_ID" progress "terminating"
|
|
|
|
# hard 모드면 tmux 죽임
|
|
if [ "$MODE" = "hard" ] && [ "$TMUX_ALIVE" = "1" ]; then
|
|
tmux kill-session -t "$SESSION_NAME"
|
|
echo "killed tmux: $SESSION_NAME"
|
|
elif [ "$MODE" = "hard" ]; then
|
|
echo "tmux already dead, just updating YAML"
|
|
fi
|
|
|
|
atomic_dump_yaml "$AGENT_SESSIONS_YAML" \
|
|
SESSION_NAME="$SESSION_NAME" AGENT="$AGENT" MODE="$MODE" PURGE="$PURGE" \
|
|
NOW_ISO="$NOW_ISO" NOW_EPOCH="$NOW_EPOCH" LAST_STATUS="$LAST_STATUS" \
|
|
PURGE_UUID="$PURGE_UUID" TARGET_CWD="$TARGET_CWD" <<'PYEOF'
|
|
import shutil
|
|
name = os.environ['SESSION_NAME']
|
|
agent = os.environ['AGENT']
|
|
mode = os.environ['MODE']
|
|
purge = os.environ['PURGE'] == '1'
|
|
now = os.environ['NOW_ISO']
|
|
home = os.environ['HOME_DIR']
|
|
last_status = os.environ.get('LAST_STATUS', '')
|
|
purge_uuid = os.environ.get('PURGE_UUID', '').strip()
|
|
ws = os.environ.get('TARGET_CWD', '')
|
|
|
|
target = None
|
|
for s in d.get('tmux_sessions', []):
|
|
if s.get('name') == name:
|
|
target = s
|
|
break
|
|
if target is None:
|
|
print(f"ERROR: disappeared during script: {name}", flush=True)
|
|
raise SystemExit(1)
|
|
|
|
if mode == 'soft':
|
|
# P1-A: soft 는 tmux 가 살아있으니 archived. terminated 아님.
|
|
target['status'] = 'archived'
|
|
target['archived_at'] = now
|
|
target['termination_mode'] = 'soft'
|
|
else:
|
|
target['status'] = 'terminated'
|
|
target['terminated_at'] = now
|
|
target['terminated_at_epoch'] = int(os.environ['NOW_EPOCH'])
|
|
target['termination_mode'] = 'hard'
|
|
|
|
if last_status:
|
|
target['last_visible_status_at_termination'] = last_status
|
|
|
|
# --purge-conversation: 워크스페이스 격리된 UUID 의 디스크 artifact 만 삭제 (P0-C)
|
|
if purge and purge_uuid:
|
|
if agent == 'claude':
|
|
key = ws.replace('/', '-').replace('_', '-')
|
|
jsonl = f"{home}/.claude/projects/{key}/{purge_uuid}.jsonl"
|
|
if os.path.exists(jsonl):
|
|
os.remove(jsonl)
|
|
print(f"purged: {jsonl}", flush=True)
|
|
target['claude_session_id_own'] = None
|
|
elif agent == 'agy':
|
|
db = f"{home}/.gemini/antigravity-cli/conversations/{purge_uuid}.db"
|
|
if os.path.exists(db):
|
|
os.remove(db)
|
|
print(f"purged: {db}", flush=True)
|
|
brain = f"{home}/.gemini/antigravity-cli/brain/{purge_uuid}"
|
|
if os.path.isdir(brain):
|
|
shutil.rmtree(brain)
|
|
print(f"purged: {brain}", flush=True)
|
|
target['agy_conversation_id_own'] = None
|
|
# agent_identities 는 cache — 이 워크스페이스 것일 때만 비운다
|
|
ai = (d.get('agent_identities') or {}).get(agent) or {}
|
|
if ai.get('project_cwd') == ws:
|
|
if agent == 'claude' and ai.get('session_id') == purge_uuid:
|
|
ai['session_id'] = None
|
|
ai['session_jsonl'] = None
|
|
ai.pop('session_size_bytes', None)
|
|
ai.pop('session_lines', None)
|
|
elif agent == 'agy' and ai.get('conversation_id') == purge_uuid:
|
|
ai['conversation_id'] = None
|
|
ai['conversation_db'] = None
|
|
ai['conversation_brain_dir'] = None
|
|
elif purge and not purge_uuid:
|
|
print("WARN: --purge-conversation requested but no workspace-scoped UUID resolved; nothing purged", flush=True)
|
|
|
|
print(f"updated: {name} status={target['status']}", flush=True)
|
|
PYEOF
|
|
|
|
delegate_publish_event "$DELEGATE_JOB_ID" completed "session terminated"
|
|
|
|
echo
|
|
echo "=== delete complete ==="
|
|
echo " session: $SESSION_NAME"
|
|
echo " agent: $AGENT"
|
|
echo " mode: $MODE"
|
|
echo " purge: $PURGE${PURGE_UUID:+ (uuid $PURGE_UUID)}"
|
|
echo " time: $NOW_ISO"
|
|
echo
|
|
echo "Recovery: tmux-agent-orchestrate-create + tmux-agent-orchestrate-resume 로 동일 컨텍스트 복원 가능"
|
|
echo " (단 --purge-conversation 사용 시 복원 불가)"
|