# Session Persistence & Checkpoint Rules ## Session State Preservation 1. After each pipeline phase completes, the orchestrator MUST write a checkpoint to `.kilo/logs/checkpoints/{issue}-{phase}.json`. 2. The checkpoint JSON must contain: - `issue_number` - `phase` (e.g., `designing`, `testing`, `implementing`) - `agent_name` - `files_modified` - `status` (`success`, `fail`, `blocked`) - `timestamp` (ISO 8601) - `next_agent` 3. If the pipeline is interrupted (orchestrator restart), the orchestrator MUST read the latest checkpoint and resume from the next phase instead of restarting. ## Session Fork 1. Before any agent that performs destructive edits (`lead-developer`, `the-fixer`, `frontend-developer`), the orchestrator SHOULD create a git stash or worktree to allow rollback. 2. The stash/worktree name format: `checkpoint/{issue}-{agent}-{timestamp}`. ## Diff Viewer 1. After any edit tool execution, the orchestrator MUST log the diff to `.kilo/logs/diffs/{issue}-{agent}.patch`. 2. Diff files are available for per-file revert decisions. ## Worktree Isolation 1. Each agent task SHOULD run in its own git worktree when the agent performs file edits. 2. Worktrees are created under `.kilo/worktrees/{issue}/{agent}/`. 3. After task completion, worktree is merged back or discarded based on checkpoint status.