@cleocode/core 2026.3.71 → 2026.3.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/cleo.d.ts.map +1 -1
  2. package/dist/hooks/handlers/agent-hooks.d.ts +48 -0
  3. package/dist/hooks/handlers/agent-hooks.d.ts.map +1 -0
  4. package/dist/hooks/handlers/context-hooks.d.ts +53 -0
  5. package/dist/hooks/handlers/context-hooks.d.ts.map +1 -0
  6. package/dist/hooks/handlers/error-hooks.d.ts +4 -4
  7. package/dist/hooks/handlers/error-hooks.d.ts.map +1 -1
  8. package/dist/hooks/handlers/file-hooks.d.ts +3 -3
  9. package/dist/hooks/handlers/file-hooks.d.ts.map +1 -1
  10. package/dist/hooks/handlers/index.d.ts +8 -1
  11. package/dist/hooks/handlers/index.d.ts.map +1 -1
  12. package/dist/hooks/handlers/mcp-hooks.d.ts +29 -7
  13. package/dist/hooks/handlers/mcp-hooks.d.ts.map +1 -1
  14. package/dist/hooks/handlers/session-hooks.d.ts +5 -5
  15. package/dist/hooks/handlers/session-hooks.d.ts.map +1 -1
  16. package/dist/hooks/handlers/task-hooks.d.ts +5 -5
  17. package/dist/hooks/handlers/task-hooks.d.ts.map +1 -1
  18. package/dist/hooks/handlers/work-capture-hooks.d.ts +7 -7
  19. package/dist/hooks/handlers/work-capture-hooks.d.ts.map +1 -1
  20. package/dist/hooks/payload-schemas.d.ts +177 -11
  21. package/dist/hooks/payload-schemas.d.ts.map +1 -1
  22. package/dist/hooks/provider-hooks.d.ts +33 -7
  23. package/dist/hooks/provider-hooks.d.ts.map +1 -1
  24. package/dist/hooks/registry.d.ts +26 -6
  25. package/dist/hooks/registry.d.ts.map +1 -1
  26. package/dist/hooks/types.d.ts +132 -38
  27. package/dist/hooks/types.d.ts.map +1 -1
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +497 -59
  31. package/dist/index.js.map +4 -4
  32. package/dist/sessions/snapshot.d.ts +125 -0
  33. package/dist/sessions/snapshot.d.ts.map +1 -0
  34. package/package.json +6 -6
  35. package/src/cleo.ts +12 -0
  36. package/src/hooks/handlers/__tests__/hook-automation-e2e.test.ts +634 -0
  37. package/src/hooks/handlers/agent-hooks.ts +148 -0
  38. package/src/hooks/handlers/context-hooks.ts +156 -0
  39. package/src/hooks/handlers/error-hooks.ts +8 -5
  40. package/src/hooks/handlers/file-hooks.ts +6 -4
  41. package/src/hooks/handlers/index.ts +12 -1
  42. package/src/hooks/handlers/mcp-hooks.ts +74 -9
  43. package/src/hooks/handlers/session-hooks.ts +7 -7
  44. package/src/hooks/handlers/task-hooks.ts +7 -7
  45. package/src/hooks/handlers/work-capture-hooks.ts +12 -12
  46. package/src/hooks/payload-schemas.ts +96 -26
  47. package/src/hooks/provider-hooks.ts +50 -9
  48. package/src/hooks/registry.ts +86 -23
  49. package/src/hooks/types.ts +175 -39
  50. package/src/index.ts +10 -0
  51. package/src/sessions/index.ts +4 -4
  52. package/src/sessions/snapshot.ts +343 -0
  53. package/src/store/json.ts +2 -2
  54. package/src/task-work/index.ts +4 -4
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Session snapshot serialization and restoration.
3
+ *
4
+ * Provides `serializeSession()` and `restoreSession()` for full session
5
+ * state capture and hydration. Designed for CleoOS agent session persistence:
6
+ * when an agent dies, CleoOS serializes the session snapshot, and when a new
7
+ * agent connects, it restores the snapshot to resume seamlessly.
8
+ *
9
+ * The snapshot captures everything needed to resume work:
10
+ * - Full session object (scope, taskWork, notes, stats)
11
+ * - Handoff data (completed tasks, decisions, next suggested)
12
+ * - Brain context (recent observations linked to this session)
13
+ * - Active task state (current focus, blockers)
14
+ *
15
+ * @module sessions/snapshot
16
+ */
17
+ import type { Session } from '@cleocode/contracts';
18
+ import type { DataAccessor } from '../store/data-accessor.js';
19
+ import { type HandoffData } from './handoff.js';
20
+ /** Version of the snapshot schema. Increment on breaking changes. */
21
+ export declare const SNAPSHOT_VERSION = 1;
22
+ /** A decision recorded during the session. */
23
+ export interface SnapshotDecision {
24
+ /** Decision text. */
25
+ decision: string;
26
+ /** Rationale for the decision. */
27
+ rationale: string;
28
+ /** Task ID context. */
29
+ taskId: string;
30
+ /** When the decision was recorded. */
31
+ recordedAt: string;
32
+ }
33
+ /** Brain observation linked to this session. */
34
+ export interface SnapshotObservation {
35
+ /** Observation ID. */
36
+ id: string;
37
+ /** Observation text. */
38
+ text: string;
39
+ /** Observation type (discovery, change, feature, etc.). */
40
+ type: string;
41
+ /** When the observation was created. */
42
+ createdAt: string;
43
+ }
44
+ /** Active task context at snapshot time. */
45
+ export interface SnapshotTaskContext {
46
+ /** Task ID currently in focus. */
47
+ taskId: string;
48
+ /** Task title. */
49
+ title: string;
50
+ /** Task status. */
51
+ status: string;
52
+ /** Task priority. */
53
+ priority: string;
54
+ /** Task description (truncated to save space). */
55
+ description: string;
56
+ /** Acceptance criteria if any. */
57
+ acceptance?: string;
58
+ }
59
+ /**
60
+ * Complete session snapshot — everything needed to resume.
61
+ *
62
+ * This is the serialization format. It is JSON-safe and can be stored
63
+ * in a file, database column, or transmitted over the network.
64
+ */
65
+ export interface SessionSnapshot {
66
+ /** Schema version for forward compatibility. */
67
+ version: number;
68
+ /** When the snapshot was created. */
69
+ capturedAt: string;
70
+ /** The full session object. */
71
+ session: Session;
72
+ /** Computed handoff data. */
73
+ handoff: HandoffData;
74
+ /** Decisions recorded in this session. */
75
+ decisions: SnapshotDecision[];
76
+ /** Recent brain observations linked to this session. */
77
+ observations: SnapshotObservation[];
78
+ /** Current task context (if a task is focused). */
79
+ activeTask: SnapshotTaskContext | null;
80
+ /** Session duration in minutes at snapshot time. */
81
+ durationMinutes: number;
82
+ }
83
+ /** Options for serializing a session. */
84
+ export interface SerializeOptions {
85
+ /** Session ID to serialize. If omitted, uses the active session. */
86
+ sessionId?: string;
87
+ /** Maximum number of brain observations to include. Default: 10. */
88
+ maxObservations?: number;
89
+ /** Maximum description length for active task. Default: 500. */
90
+ maxDescriptionLength?: number;
91
+ }
92
+ /** Options for restoring a session. */
93
+ export interface RestoreOptions {
94
+ /** Agent identifier for the new agent taking over. */
95
+ agent?: string;
96
+ /** Whether to resume the session (set status to active). Default: true. */
97
+ activate?: boolean;
98
+ }
99
+ /**
100
+ * Serialize a session into a complete snapshot.
101
+ *
102
+ * Captures the full session state including handoff data, decisions,
103
+ * brain observations, and active task context. The result is a
104
+ * JSON-serializable object that can be stored and later restored.
105
+ *
106
+ * @param projectRoot - Project root directory
107
+ * @param options - Serialization options
108
+ * @returns Complete session snapshot
109
+ */
110
+ export declare function serializeSession(projectRoot: string, options?: SerializeOptions, accessor?: DataAccessor): Promise<SessionSnapshot>;
111
+ /**
112
+ * Restore a session from a snapshot.
113
+ *
114
+ * Hydrates a session from a previously serialized snapshot. The session
115
+ * is re-inserted into the sessions store and optionally activated.
116
+ * Brain observations from the snapshot are NOT re-inserted (they already
117
+ * exist in brain.db) — only the session state is restored.
118
+ *
119
+ * @param projectRoot - Project root directory
120
+ * @param snapshot - The snapshot to restore from
121
+ * @param options - Restoration options
122
+ * @returns The restored session
123
+ */
124
+ export declare function restoreSession(projectRoot: string, snapshot: SessionSnapshot, options?: RestoreOptions, accessor?: DataAccessor): Promise<Session>;
125
+ //# sourceMappingURL=snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/sessions/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAMhE,qEAAqE;AACrE,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,8CAA8C;AAC9C,MAAM,WAAW,gBAAgB;IAC/B,qBAAqB;IACrB,Q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ACnB,oEAAoE;IACpE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gEAAgE;IAChE,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAMD;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,gBAAqB,EAC9B,QAAQ,CAAC,EAAE,YAAY,GACtB,OAAO,CAAC,eAAe,CAAC,CAsG1B;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,eAAe,EACzB,OAAO,GAAE,cAAmB,EAC5B,QAAQ,CAAC,EAAE,YAAY,GACtB,OAAO,CAAC,OAAO,CAAC,CAkFlB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleocode/core",
3
- "version": "2026.3.71",
3
+ "version": "2026.3.73",
4
4
  "description": "CLEO core business logic kernel — tasks, sessions, memory, orchestration, lifecycle, with bundled SQLite store",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "@cleocode/caamp": "^1.8.1",
26
+ "@cleocode/caamp": "^1.9.1",
27
27
  "@cleocode/lafs-protocol": "^1.8.0",
28
28
  "@xenova/transformers": "^2.17.2",
29
29
  "ajv": "^8.18.0",
@@ -37,10 +37,10 @@
37
37
  "write-file-atomic": "^6.0.0",
38
38
  "yaml": "^2.8.2",
39
39
  "zod": "^3.25.76",
40
- "@cleocode/agents": "2026.3.71",
41
- "@cleocode/adapters": "2026.3.71",
42
- "@cleocode/skills": "2026.3.71",
43
- "@cleocode/contracts": "2026.3.71"
40
+ "@cleocode/adapters": "2026.3.73",
41
+ "@cleocode/agents": "2026.3.73",
42
+ "@cleocode/contracts": "2026.3.73",
43
+ "@cleocode/skills": "2026.3.73"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=24.0.0"
package/src/cleo.ts CHANGED
@@ -129,6 +129,8 @@ import {
129
129
  startSession,
130
130
  suspendSession,
131
131
  } from './sessions/index.js';
132
+ // Session snapshots (Phase 3: persistence)
133
+ import { restoreSession, serializeSession } from './sessions/snapshot.js';
132
134
  // Sticky
133
135
  import {
134
136
  addSticky,
@@ -289,6 +291,16 @@ export class Cleo {
289
291
  contextDrift: (p) => getContextDrift(root, p),
290
292
  decisionLog: (p) => getDecisionLog(root, { sessionId: p?.sessionId, taskId: p?.taskId }),
291
293
  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
+ }),
292
304
  };
293
305
  }
294
306