╔═══════════════════════════════════════════════════════════════════════════╗ ║ GENESIS AUTO-RESPAWN SYSTEM v2.0 ║ ║ 8-Layer Defense System ║ ╚═══════════════════════════════════════════════════════════════════════════╝ ┌───────────────────────────────────────────────────────────────────────────┐ │ RUNNING SESSION │ └───────────────────────────────────────────────────────────────────────────┘ │ ┌────────────────┴────────────────┐ │ Claude Code Runtime │ │ (Opus 4.6, 200K context) │ └────────────────┬────────────────┘ │ ╔═══════════════════════════▼═══════════════════════════╗ ║ LAYER 1: StatusLine (genesis_statusline.sh) ║ ║ Fires: Every assistant message ║ ║ Writes: data/context_state/current.json ║ ║ ┌──────────────────────────────────────────────┐ ║ ║ │ { │ ║ ║ │ "used_percentage": 65, │ ║ ║ │ "remaining_percentage": 35, │ ║ ║ │ "actual_free": 18.5, ← (after 16.5% buf) │ ║ ║ │ "cost_usd": 12.34 │ ║ ║ │ } │ ║ ║ └──────────────────────────────────────────────┘ ║ ╚════════════════════════════════════════════════════════╝ │ ╔═══════════════════════════▼═══════════════════════════╗ ║ LAYER 2: Context Tracker (context_tracker.py) ║ ║ Fires: PostToolUse ║ ║ Reads: current.json ║ ║ ┌────────────────────────────────────────────┐ ║ ║ │ 50% → WARNING logged │ ║ ║ │ 65% → CAUTION logged │ ║ ║ │ 80% → CRITICAL logged │ ║ ║ └────────────────────────────────────────────┘ ║ ╚════════════════════════════════════════════════════════╝ │ ╔═══════════════════════════▼═══════════════════════════╗ ║ LAYER 5: Session Heartbeat (session_heartbeat.py) ║ ║ Fires: Every 25 tool calls ║ ║ Writes: hive/session_recovery/LATEST.md ║ ║ hive/session_backups/heartbeat_.json ║ ╚════════════════════════════════════════════════════════╝ │ ╔═══════════════════════════▼═══════════════════════════╗ ║ LAYER 6: Auto-Respawn (auto_respawn.py) ║ ║ Fires: PostToolUse ║ ║ ┌────────────────────────────────────────────┐ ║ ║ │ 50% → Log warning │ ║ ║ │ 65% → ┌─────────────────────────────┐ │ ║ ║ │ │ EXECUTE CTM FLUSH │ │ ║ ║ │ │ ├─ Write handoff file │ │ ║ ║ │ │ ├─ Save to supermemory │ │ ║ ║ │ │ └─ Log flush event │ │ ║ ║ │ └─────────────────────────────┘ │ ║ ║ │ 70% → ┌─────────────────────────────┐ │ ║ ║ │ │ MANDATORY RESPAWN │ │ ║ ║ │ │ ├─ Execute full CTM flush │ │ ║ ║ │ │ ├─ Write respawn flag │ │ ║ ║ │ │ └─ Inject CRITICAL warning │ │ ║ ║ │ └─────────────────────────────┘ │ ║ ║ └────────────────────────────────────────────┘ ║ ╚════════════════════════════════════════════════════════╝ │ ┌───────────────┴───────────────┐ │ │ ┌─────────▼──────────┐ ┌──────────▼──────────┐ │ Context at 70% │ │ Context at 85% │ │ (respawn trigger) │ │ (compaction trigger)│ └─────────┬──────────┘ └──────────┬──────────┘ │ │ ┌───────────▼───────────┐ ┌──────────▼──────────┐ │ respawn_requested.flag│ │ PreCompact fires │ │ written │ └──────────┬──────────┘ └───────────┬───────────┘ │ │ ╔════════════════▼═════════════════╗ ┌───────────▼───────────┐ ║ LAYER 3: PreCompact CTM ║ │ EXTERNAL WATCHER │ ║ (pre_compact_ctm.py) ║ │ (tmux pane) │ ║ Backs up full transcript ║ │ │ ║ → data/context_backups/ ║ │ respawn_command │ ╚════════════════╤═════════════════╝ │ _centre.sh --watch │ │ │ │ ┌────────▼────────┐ │ Polls every 5 seconds │ │ COMPACTION │ └───────────┬───────────┘ │ Context gets │ │ │ summarized │ │ └────────┬────────┘ ┌───────────▼───────────┐ │ │ FLAG DETECTED! │ │ │ │ │ │ 1. Kill Claude (TERM) │ │ │ 2. Wait 3 seconds │ │ │ 3. Launch new session │ │ └───────────┬───────────┘ │ │ │ └─────────────┬───────────────┘ │ ┌─────────────▼─────────────┐ │ NEW SESSION STARTS │ │ (startup/resume/compact)│ └─────────────┬─────────────┘ │ ╔═════════════════════════▼═══════════════════════════╗ ║ LAYER 8: Session Recovery (session_recovery_start) ║ ║ Fires: SessionStart (startup, resume, compact) ║ ║ ┌────────────────────────────────────────────┐ ║ ║ │ READS: │ ║ ║ │ ├─ hive/progress/session_N_handoff.md │ ║ ║ │ ├─ hive/session_recovery/LATEST.md │ ║ ║ │ ├─ data/context_state/current.json │ ║ ║ │ ├─ MEMORY.md (WAR ROOM STATUS) │ ║ ║ │ └─ data/observability/events.jsonl │ ║ ║ │ │ ║ ║ │ INJECTS: │ ║ ║ │ ┌────────────────────────────────────┐ │ ║ ║ │ │ additionalContext: │ │ ║ ║ │ │ │ │ ║ ║ │ │ ═══ SESSION RECOVERY ACTIVATED ═══ │ │ ║ ║ │ │ │ │ ║ ║ │ │ ═══ WAR ROOM STATUS ═══ │ │ ║ ║ │ │ [Active mission, agents, ...] │ │ ║ ║ │ │ │ │ ║ ║ │ │ ═══ LATEST HANDOFF ═══ │ │ ║ ║ │ │ [Session state, context %, ...] │ │ ║ ║ │ │ │ │ ║ ║ │ │ ═══ RECOVERY INSTRUCTIONS ═══ │ │ ║ ║ │ │ ZERO RE-ORIENTATION. │ │ ║ ║ │ │ PURE CONTINUITY. │ │ ║ ║ │ └────────────────────────────────────┘ │ ║ ║ │ │ ║ ║ │ ACTIONS: │ ║ ║ │ ├─ Clear respawn_requested.flag │ ║ ║ │ └─ Log session_recovery event │ ║ ║ └────────────────────────────────────────────┘ ║ ╚════════════════════════════════════════════════════════╝ │ ┌─────────────▼─────────────┐ │ CLAUDE RESUMES │ │ AUTONOMOUSLY │ │ │ │ ✓ Reads recovery context │ │ ✓ Checks running agents │ │ ✓ Resumes active mission │ │ ✓ Greets user with status │ └─────────────┬─────────────┘ │ ╔═════════════════════════▼═══════════════════════════╗ ║ CORRECT GREETING: ║ ║ "Session 9 online. Resumed building Memory Vault ║ ║ backend. Agent acd355e writing auth.py. Next: ║ ║ deploy landing page." ║ ╚════════════════════════════════════════════════════════╝ ┌───────────────────────────────────────────────────────────────────────────┐ │ TMUX SESSION LAYOUT │ ├───────────────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────────────────────────┬────────────────────────────────┐ │ │ │ │ AUTO-RESPAWN WATCHER │ │ │ │ │ (Pane 1) │ │ │ │ CLAUDE CODE │ │ │ │ │ (Pane 0) │ respawn_command_centre.sh │ │ │ │ │ --watch │ │ │ │ Main interface │ │ │ │ │ 70% width │ Watching for respawn flag... │ │ │ │ │ │ │ │ │ ├────────────────────────────────┤ │ │ │ │ LIVE EVENT LOG │ │ │ │ │ (Pane 2) │ │ │ │ │ │ │ │ │ │ tail -f events.jsonl | jq │ │ │ │ │ │ │ │ │ │ {...} │ │ │ │ │ {...} │ │ │ └─────────────────────────────────┴────────────────────────────────┘ │ │ │ │ Switch panes: Ctrl+B → Arrow keys │ │ Detach: Ctrl+B → D │ │ Re-attach: tmux attach -t genesis │ └───────────────────────────────────────────────────────────────────────────┘ ┌───────────────────────────────────────────────────────────────────────────┐ │ CONTEXT THRESHOLDS │ ├───────────────────────────────────────────────────────────────────────────┤ │ │ │ 0% ──────────────────────────────────────────────────────────► 100% │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 50% 65% 70% 85% 100% │ │ │ │ │ │ │ │ │ ▼ ▼ ▼ ▼ ▼ │ │ WARNING CTM FLUSH RESPAWN AUTOCOMPACT OVERFLOW │ │ │ │ Actual free space = Remaining - 16.5% (autocompact buffer) │ │ │ │ Example: 25% remaining → 8.5% actual free before compaction │ └───────────────────────────────────────────────────────────────────────────┘ ┌───────────────────────────────────────────────────────────────────────────┐ │ FILE LOCATIONS │ ├───────────────────────────────────────────────────────────────────────────┤ │ │ │ REAL-TIME STATE: │ │ data/context_state/current.json ← StatusLine writes here │ │ data/context_state/respawn_requested.flag ← Triggers watcher │ │ │ │ HANDOFFS: │ │ hive/progress/session_N_handoff.md ← Auto-respawn writes here │ │ hive/session_recovery/LATEST.md ← Heartbeat writes here │ │ │ │ BACKUPS: │ │ hive/session_backups/heartbeat_*.json ← Periodic snapshots │ │ data/context_backups/transcript_*.jsonl ← PreCompact backups │ │ │ │ LOGS: │ │ data/observability/events.jsonl ← All hook events │ │ data/context_state/respawn_log.jsonl ← Watcher actions │ └───────────────────────────────────────────────────────────────────────────┘ ╔═══════════════════════════════════════════════════════════════════════════╗ ║ PRODUCTION STATUS ║ ║ ║ ║ ✓ SessionStart recovery hook operational ║ ║ ✓ Recovery context injection working ║ ║ ✓ Respawn flag cleanup working ║ ║ ✓ Observability logging working ║ ║ ✓ Works for all SessionStart sources (startup, resume, compact) ║ ║ ✓ Hook registered in settings.json ║ ║ ✓ tmux commander script ready ║ ║ ✓ All integration tests PASSING ║ ║ ║ ║ SYSTEM IS PRODUCTION READY ║ ╚═══════════════════════════════════════════════════════════════════════════╝