/** * Session checkpoints — `/checkpoint` and `/rewind`. * * A checkpoint is a snapshot of the agent conversation at a point in time: * session history, provider/model state, and the list of files the agent has * touched in this session. It does NOT snapshot file content — that's git's * job, and trying to do it ourselves means either a 100KB-per-file ceiling * with surprise truncation, or a real-time disk hog. We surface a hint at * rewind time telling the user how to restore files via git. * * Use cases this is for: * - User suspects the agent is going off the rails after N steps and * wants to roll the conversation back to before that turn. * - User is about to start a risky multi-step refactor and wants a * named bookmark to return to if it gets messy. * * Use cases this is NOT for: * - Replacing git. If you only need file rollback, `git restore` / * `git stash` is faster and reliable. * - Cross-session persistence beyond the workspace's `.codeep/checkpoints/` * folder — checkpoints are per-project, not global. * * On-disk shape (`.codeep/checkpoints/.json`): * { * "id": "ck-2026-05-18-abc123", * "name": "before big refactor", * "createdAt": "...", * "sessionId": "session-2026-05-18-...", * "provider": "z.ai", * "model": "glm-5.2", * "messages": [ ... ], * "filesTouched": ["src/a.ts", "src/b.ts"], * "gitHead": "abcdef0" // optional, recorded only if cwd is a git repo * } */ import type { Message } from '../config/index.js'; export interface Checkpoint { id: string; name?: string; createdAt: string; sessionId: string; provider: string; model: string; messages: Message[]; filesTouched: string[]; gitHead?: string; } /** Lightweight metadata for `/checkpoints` list — avoids loading full message arrays. */ export interface CheckpointMeta { id: string; name?: string; createdAt: string; sessionId: string; messageCount: number; filesTouchedCount: number; gitHead?: string; } /** * Create a new checkpoint snapshot of the current session state. * Returns the persisted checkpoint object. */ export declare function createCheckpoint(opts: { workspaceRoot: string; sessionId: string; provider: string; model: string; messages: Message[]; filesTouched: string[]; name?: string; }): Checkpoint; /** * Load a single checkpoint by id. Returns null if not found or unreadable. */ export declare function loadCheckpoint(workspaceRoot: string, id: string): Checkpoint | null; /** * List checkpoints in the workspace, newest first. Returns metadata only — * the full `messages` array is not loaded so this is cheap for `/checkpoints`. */ export declare function listCheckpoints(workspaceRoot: string): CheckpointMeta[]; /** * Delete a checkpoint by id. Returns true if a file was removed. */ export declare function deleteCheckpoint(workspaceRoot: string, id: string): boolean; /** * Format a checkpoint list as a Markdown block for `/checkpoints` output. */ export declare function formatCheckpointList(metas: CheckpointMeta[]): string; /** * Build the user-facing hint shown after a successful /rewind. Tells the * user how to bring their files back to checkpoint state — checkpoints * don't snapshot file content, so this is the only restore path. */ export declare function buildRewindGitHint(cp: Checkpoint): string;