/** * Session snapshot serialization and restoration. * * Provides `serializeSession()` and `restoreSession()` for full session * state capture and hydration. Designed for CleoOS agent session persistence: * when an agent dies, CleoOS serializes the session snapshot, and when a new * agent connects, it restores the snapshot to resume seamlessly. * * The snapshot captures everything needed to resume work: * - Full session object (scope, taskWork, notes, stats) * - Handoff data (completed tasks, decisions, next suggested) * - Brain context (recent observations linked to this session) * - Active task state (current focus, blockers) * * @module sessions/snapshot */ import type { Session } from '@cleocode/contracts'; import type { DataAccessor } from '../store/data-accessor.js'; import { type HandoffData } from './handoff.js'; /** Version of the snapshot schema. Increment on breaking changes. */ export declare const SNAPSHOT_VERSION = 1; /** A decision recorded during the session. */ export interface SnapshotDecision { /** Decision text. */ decision: string; /** Rationale for the decision. */ rationale: string; /** Task ID context. */ taskId: string; /** When the decision was recorded. */ recordedAt: string; } /** Brain observation linked to this session. */ export interface SnapshotObservation { /** Observation ID. */ id: string; /** Observation text. */ text: string; /** Observation type (discovery, change, feature, etc.). */ type: string; /** When the observation was created. */ createdAt: string; } /** Active task context at snapshot time. */ export interface SnapshotTaskContext { /** Task ID currently in focus. */ taskId: string; /** Task title. */ title: string; /** Task status. */ status: string; /** Task priority. */ priority: string; /** Task description (truncated to save space). */ description: string; /** Acceptance criteria if any. */ acceptance?: string; } /** * Complete session snapshot — everything needed to resume. * * This is the serialization format. It is JSON-safe and can be stored * in a file, database column, or transmitted over the network. */ export interface SessionSnapshot { /** Schema version for forward compatibility. */ version: number; /** When the snapshot was created. */ capturedAt: string; /** The full session object. */ session: Session; /** Computed handoff data. */ handoff: HandoffData; /** Decisions recorded in this session. */ decisions: SnapshotDecision[]; /** Recent brain observations linked to this session. */ observations: SnapshotObservation[]; /** Current task context (if a task is focused). */ activeTask: SnapshotTaskContext | null; /** Session duration in minutes at snapshot time. */ durationMinutes: number; } /** Options for serializing a session. */ export interface SerializeOptions { /** Session ID to serialize. If omitted, uses the active session. */ sessionId?: string; /** Maximum number of brain observations to include. Default: 10. */ maxObservations?: number; /** Maximum description length for active task. Default: 500. */ maxDescriptionLength?: number; } /** Options for restoring a session. */ export interface RestoreOptions { /** Agent identifier for the new agent taking over. */ agent?: string; /** Whether to resume the session (set status to active). Default: true. */ activate?: boolean; } /** * Serialize a session into a complete snapshot. * * Captures the full session state including handoff data, decisions, * brain observations, and active task context. The result is a * JSON-serializable object that can be stored and later restored. * * @param projectRoot - Project root directory * @param options - Serialization options * @returns Complete session snapshot */ export declare function serializeSession(projectRoot: string, options?: SerializeOptions, accessor?: DataAccessor): Promise; /** * Restore a session from a snapshot. * * Hydrates a session from a previously serialized snapshot. The session * is re-inserted into the sessions store and optionally activated. * Brain observations from the snapshot are NOT re-inserted (they already * exist in brain.db) — only the session state is restored. * * @param projectRoot - Project root directory * @param snapshot - The snapshot to restore from * @param options - Restoration options * @returns The restored session */ export declare function restoreSession(projectRoot: string, snapshot: SessionSnapshot, options?: RestoreOptions, accessor?: DataAccessor): Promise; //# sourceMappingURL=snapshot.d.ts.map