Skip to content

Commit 00b715d

Browse files
feat: session serialize/restore for CleoOS agent persistence (v2026.3.72)
Add serializeSession() and restoreSession() to enable CleoOS to capture full session state when agents die and hydrate it when new agents connect. Snapshot includes: session object, handoff data, decision log, brain observations, active task context, and duration. Restore handles scope conflict detection, agent handoff tracking, and hook dispatch. Wired into Cleo facade as sessions.serialize() and sessions.restore(). Types exported from both @cleocode/core and @cleocode/contracts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ad8dcaf commit 00b715d

11 files changed

Lines changed: 374 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cleocode/monorepo",
3-
"version": "2026.3.71",
3+
"version": "2026.3.72",
44
"private": true,
55
"type": "module",
66
"packageManager": "pnpm@10.30.0",

packages/adapters/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cleocode/adapters",
3-
"version": "2026.3.71",
3+
"version": "2026.3.72",
44
"description": "Unified provider adapters for CLEO (Claude Code, OpenCode, Cursor)",
55
"type": "module",
66
"main": "dist/index.js",

packages/agents/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cleocode/agents",
3-
"version": "2026.3.71",
3+
"version": "2026.3.72",
44
"description": "CLEO agent protocols and templates",
55
"type": "module",
66
"license": "MIT",

packages/cleo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cleocode/cleo",
3-
"version": "2026.3.71",
3+
"version": "2026.3.72",
44
"description": "CLEO CLI + MCP server — the assembled product consuming @cleocode/core",
55
"type": "module",
66
"main": "./dist/cli/index.js",

packages/contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cleocode/contracts",
3-
"version": "2026.3.71",
3+
"version": "2026.3.72",
44
"description": "Domain types, interfaces, and contracts for the CLEO ecosystem",
55
"type": "module",
66
"main": "./dist/index.js",

packages/contracts/src/facade.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ export interface SessionsAPI {
369369
decisionLog(params?: { sessionId?: string; taskId?: string }): Promise<unknown>;
370370
/** Get last handoff for a scope. */
371371
lastHandoff(scope?: { type: string; epicId?: string }): Promise<unknown>;
372+
/** Serialize a session into a complete snapshot for persistence. */
373+
serialize(params?: { sessionId?: string; maxObservations?: number }): Promise<unknown>;
374+
/** Restore a session from a previously serialized snapshot. */
375+
restore(snapshot: unknown, params?: { agent?: string; activate?: boolean }): Promise<unknown>;
372376
}
373377

374378
/** Memory/Brain domain API. */

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cleocode/core",
3-
"version": "2026.3.71",
3+
"version": "2026.3.72",
44
"description": "CLEO core business logic kernel — tasks, sessions, memory, orchestration, lifecycle, with bundled SQLite store",
55
"type": "module",
66
"main": "./dist/index.js",

packages/core/src/cleo.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ import {
129129
startSession,
130130
suspendSession,
131131
} from './sessions/index.js';
132+
// Session snapshots (Phase 3: persistence)
133+
import { restoreSession, serializeSession } from './sessions/snapshot.js';
132134
// Sticky
133135
import {
134136
addSticky,
@@ -289,6 +291,16 @@ export class Cleo {
289291
contextDrift: (p) => getContextDrift(root, p),
290292
decisionLog: (p) => getDecisionLog(root, { sessionId: p?.sessionId, taskId: p?.taskId }),
291293
lastHandoff: (scope) => getLastHandoff(root, scope),
294+
serialize: (p) =>
295+
serializeSession(root, {
296+
sessionId: p?.sessionId,
297+
maxObservations: p?.maxObservations,
298+
}),
299+
restore: (snapshot, p) =>
300+
restoreSession(root, snapshot as import('./sessions/snapshot.js').SessionSnapshot, {
301+
agent: p?.agent,
302+
activate: p?.activate,
303+
}),
292304
};
293305
}
294306

packages/core/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,16 @@ export {
299299
sessionStatus,
300300
startSession,
301301
} from './sessions/index.js';
302+
export type {
303+
RestoreOptions,
304+
SerializeOptions,
305+
SessionSnapshot,
306+
SnapshotDecision,
307+
SnapshotObservation,
308+
SnapshotTaskContext,
309+
} from './sessions/snapshot.js';
310+
// Session snapshots (Phase 3: persistence)
311+
export { restoreSession, serializeSession } from './sessions/snapshot.js';
302312
export { getMigrationStatus as getSystemMigrationStatus } from './system/migrate.js';
303313
export { checkStorageMigration } from './system/storage-preflight.js';
304314
// Task work

0 commit comments

Comments
 (0)