Skip to content
Shell
10.3 KB
Raw Blame

Session-Resilient Development System

Status: PLANNING

Created: 2025-11-28 Last Updated: 2025-11-28 Session: Initial Planning


Problem Statement

Context windows are ephemeral, but work shouldn't be. When sessions timeout or crash:

  • Plans are lost
  • Progress is unclear
  • Tool/agent assignments forgotten
  • Work must be reconstructed from scratch

Requirements (Confirmed with User)

Requirement Details
Scope Global - all projects, not just id8
SDK Agents Initializer + Coding agent
Slash Commands For invoking patterns
Hooks Auto-save on session events
Testing Automatic via Playwright MCP
Progress Tracking .claude-progress.txt + Notion sync
Plan Persistence Save to file with tool assignments
Crash Recovery Checkpoints, resumable anywhere

Core Components to Build

1. SDK Agents (TypeScript)

  • session-initializer - Project scaffolding
  • session-coder - Incremental progress with auto-testing

2. Slash Commands

  • /init-project - Run initializer
  • /resume - Continue from last checkpoint
  • /save-state - Force save current state
  • /status - Show current progress

3. Hooks

  • on-session-start - Load state, read progress
  • on-session-end - Auto-commit, sync Notion
  • on-plan-create - Persist plan to file

4. Progress System

  • .claude-progress.txt format spec
  • claude-plan.json format spec
  • Notion integration for cloud backup

5. Plan Persistence Format

Plans should include:

  • Task description
  • Assigned agents/subagents
  • Assigned MCPs/plugins
  • Checkpoints with status
  • Tool configurations

Exploration Completed

Existing Infrastructure (Highly Sophisticated)

  • 37 specialized agents (Leonardo strategist, KRANG brain, operations-manager, etc.)
  • 18 automation hooks (verify-after-write, auto-commit, progress-report, etc.)
  • 18 slash commands (/start, /test, /fix, /ship, /status, etc.)
  • 17 plugins (agent-sdk-dev, testing-suite, git-workflow, etc.)
  • 8 MCP servers (Notion, Supabase, Playwright, GitHub, Perplexity, Firecrawl)

Key Existing Patterns to Leverage

  1. verify-after-write.sh / verify-after-edit.sh - Verification hooks
  2. progress-report.sh - Progress logging
  3. milestone-tracker.sh - Milestone tracking
  4. auto-commit.sh / auto-git-workflow.sh - Git automation
  5. /start [name] - Feature branch creation
  6. /status - Project state report

Agent SDK Dev Plugin

  • Already installed at ~/.claude/plugins/marketplaces/claude-code-plugins/plugins/agent-sdk-dev
  • Can use /agent-sdk-dev:new-sdk-app to scaffold new agents
  • No existing Agent SDK projects yet (using direct Anthropic SDK)

Critical Files to Modify

  • ~/.claude/CLAUDE.md - Add session resilience instructions
  • ~/.claude/settings.local.json - Add new hooks
  • ~/.claude/hooks.json - Register new hooks
  • ~/.claude/commands/ - Add new slash commands
  • ~/.claude/agents/ - Add new agent definitions

Synthesized Implementation Plan

Architecture: Hybrid Approach

Combines best of both perspectives:

  • SDK Agents: Standalone TypeScript project at ~/Development/session-resilience-agents/
  • Claude Code Integration: Extend existing hooks and commands in ~/.claude/
  • State Persistence: Local checkpoints + Notion sync (dual redundancy)
  • Testing: Playwright MCP auto-testing integrated into coding agent

Why Hybrid?

Aspect Decision Rationale
Agent Location ~/Development/ Standalone project, version-controlled, reusable
Integration Extend existing hooks Leverage 18 hooks already in place
Commands New + Extend existing /resume, /save-state new; /start, /status extended
State Local + Notion Crash recovery (local) + Cloud backup (Notion)

Implementation Phases

Phase 1: SDK Agent Project Setup

Goal: Scaffold TypeScript Agent SDK project

  1. Run /agent-sdk-dev:new-sdk-app session-resilience-agents
  2. Configure MCP connections (Notion, Playwright)
  3. Create state directory structure
  4. Define TypeScript schemas for session state

Files Created:

~/Development/session-resilience-agents/
├── package.json
├── src/
│   ├── agents/
│   │   ├── initializer-agent.ts
│   │   └── coding-agent.ts
│   ├── tools/
│   │   ├── notion-sync.ts
│   │   ├── checkpoint-manager.ts
│   │   └── playwright-runner.ts
│   └── schemas/
│       └── session-state.ts
└── state/
    ├── sessions/
    └── checkpoints/

Phase 2: Session State System

Goal: Implement state persistence with crash recovery

Session State Schema:

{
  "session_id": "uuid",
  "project_path": "/path/to/project",
  "notion_page_id": "abc123",
  "plan": {
    "file": "~/.claude/plans/plan-name.md",
    "tasks": [
      {
        "id": "task-001",
        "description": "Implement feature X",
        "status": "in_progress",
        "assigned_agent": "code-reviewer",
        "assigned_mcp": ["playwright"],
        "checkpoint": "CP-003"
      }
    ]
  },
  "context": {
    "files_modified": [],
    "decisions_made": [],
    "last_activity": "2025-11-28T12:00:00Z"
  },
  "recovery_instructions": "Continue with task-002..."
}

Checkpoint Strategy (User Confirmed):

  • Auto-checkpoint every 5 significant tool uses (balanced)
  • Also checkpoint on task completion
  • Also checkpoint before test runs

Recovery Behavior (User Confirmed):

  • Auto-prompt on session start if crashed session detected
  • Show recovery options (files modified, current task, decisions)
  • User chooses: Resume, Start Fresh, or Review Plan

Notion Setup (User Confirmed):

  • Create NEW "Claude Sessions" database
  • Link from existing workspace

Phase 3: Slash Commands

Goal: Create/extend commands for session control

Command Type Purpose
/resume NEW Load session from checkpoint, continue work
/save-state NEW Force checkpoint, sync to Notion
/start EXTEND Add session initialization
/status EXTEND Show session state, progress

Phase 4: Hooks Integration

Goal: Extend existing hooks for auto-persistence

Hook Action
session-persist.sh (NEW) Save state after Write/Edit
session-recovery-check.sh (NEW) Check for crashed session on start
progress-report.sh (EXTEND) Add session state to progress
verify-after-write.sh (EXTEND) Trigger Playwright after changes

Phase 5: Notion Integration

Goal: Cloud backup and visibility

  1. Create "Claude Sessions" database in Notion
  2. Schema: Session ID, Status, Project, Progress %, Last Updated
  3. Sync triggers: session start, checkpoint, task completion, session end

Phase 6: Auto-Testing Integration

Goal: Playwright runs automatically after code changes

  • Detect project test config (playwright.config.ts)
  • Run relevant tests after code changes
  • Update session state with test results
  • Screenshot on failure for evidence

CLAUDE.md Additions

## Session Resilience Protocol

### On Session Start
1. Check for incomplete sessions: `~/.claude/session-state/`
2. If found, prompt: "Resume session from [checkpoint]?"
3. Run `/resume` to continue or `/start` for fresh session

### During Work
- State auto-saves after every code change
- Use `/save-state` for immediate checkpoint
- Plans persist with tool/agent assignments

### On Crash Recovery
1. Next session detects incomplete work
2. `/resume` shows: files modified, decisions made, current task
3. Continue from last checkpoint

### Progress Tracking
- Local: `.claude-progress.txt` in project
- Cloud: Notion "Claude Sessions" database
- Plans: `~/.claude/plans/` with checkpoints

File Modification Summary

File Action
~/Development/session-resilience-agents/ CREATE (SDK project)
~/.claude/commands/resume.md CREATE
~/.claude/commands/save-state.md CREATE
~/.claude/commands/start.md EXTEND
~/.claude/commands/status.md EXTEND
~/.claude/hooks/session-persist.sh CREATE
~/.claude/hooks/session-recovery-check.sh CREATE
~/.claude/hooks/progress-report.sh EXTEND
~/.claude/settings.local.json EXTEND (add hooks)
~/.claude/CLAUDE.md EXTEND (add protocol)

Checkpoints

  • Requirements gathered
  • Existing setup explored (37 agents, 18 hooks, 18 commands found)
  • Architecture designed (Hybrid: SDK agents + extend existing)
  • User decisions captured:
    • Checkpoint frequency: Every 5 changes
    • Notion: Create new database
    • Recovery: Auto-prompt on session start
  • Plan approved by user
  • Implementation started
  • SDK project created (~/Development/session-resilience-agents/)
  • Slash commands created (/resume, /save-state)
  • Hooks created and registered
  • CLAUDE.md updated with Session Resilience Protocol
  • Notion database setup (user action required)
  • End-to-end testing

Resume Instructions

If this session crashes, the next session should:

  1. Read this file at ~/.claude/plans/zany-inventing-whistle.md
  2. Check the "Checkpoints" section for current status
  3. Continue from the last incomplete checkpoint

Implementation Order (Ready to Execute)

  1. Phase 1: Scaffold SDK project with /agent-sdk-dev:new-sdk-app
  2. Phase 2: Create session state schemas and checkpoint manager
  3. Phase 3: Create /resume and /save-state slash commands
  4. Phase 4: Create hooks (session-persist.sh, session-recovery-check.sh)
  5. Phase 5: Set up Notion database and sync integration
  6. Phase 6: Integrate Playwright auto-testing
  7. Phase 7: Extend /start and /status commands
  8. Phase 8: Update CLAUDE.md with Session Resilience Protocol
  9. Phase 9: Test crash recovery workflow end-to-end

Critical Files to Read Before Implementation

  1. ~/.claude/settings.local.json - Current hooks configuration
  2. ~/.claude/hooks/progress-report.sh - Existing progress pattern
  3. ~/.claude/commands/start.md - Existing start command to extend
  4. ~/.claude/agents/operations-manager.md - Agent coordination pattern
  5. ~/.claude/agents/krang-brain-agent.md - Project brain pattern for state