@cleocode/contracts 2026.5.95 → 2026.5.97

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 (121) hide show
  1. package/dist/__tests__/enums.test.d.ts +14 -0
  2. package/dist/__tests__/enums.test.d.ts.map +1 -0
  3. package/dist/__tests__/enums.test.js +75 -0
  4. package/dist/__tests__/enums.test.js.map +1 -0
  5. package/dist/__tests__/jobs.test.d.ts +11 -0
  6. package/dist/__tests__/jobs.test.d.ts.map +1 -0
  7. package/dist/__tests__/jobs.test.js +48 -0
  8. package/dist/__tests__/jobs.test.js.map +1 -0
  9. package/dist/__tests__/memory-wire-shapes.test.d.ts +19 -0
  10. package/dist/__tests__/memory-wire-shapes.test.d.ts.map +1 -0
  11. package/dist/__tests__/memory-wire-shapes.test.js +119 -0
  12. package/dist/__tests__/memory-wire-shapes.test.js.map +1 -0
  13. package/dist/__tests__/operation-def.test.d.ts +20 -0
  14. package/dist/__tests__/operation-def.test.d.ts.map +1 -0
  15. package/dist/__tests__/operation-def.test.js +111 -0
  16. package/dist/__tests__/operation-def.test.js.map +1 -0
  17. package/dist/__tests__/provenance.test.d.ts +18 -0
  18. package/dist/__tests__/provenance.test.d.ts.map +1 -0
  19. package/dist/__tests__/provenance.test.js +142 -0
  20. package/dist/__tests__/provenance.test.js.map +1 -0
  21. package/dist/__tests__/scaffold-diagnostics.test.d.ts +19 -0
  22. package/dist/__tests__/scaffold-diagnostics.test.d.ts.map +1 -0
  23. package/dist/__tests__/scaffold-diagnostics.test.js +70 -0
  24. package/dist/__tests__/scaffold-diagnostics.test.js.map +1 -0
  25. package/dist/dispatch/identity.d.ts +72 -0
  26. package/dist/dispatch/identity.d.ts.map +1 -0
  27. package/dist/dispatch/identity.js +72 -0
  28. package/dist/dispatch/identity.js.map +1 -0
  29. package/dist/dispatch/operation-def.d.ts +92 -0
  30. package/dist/dispatch/operation-def.d.ts.map +1 -0
  31. package/dist/dispatch/operation-def.js +31 -0
  32. package/dist/dispatch/operation-def.js.map +1 -0
  33. package/dist/doctor.d.ts +52 -0
  34. package/dist/doctor.d.ts.map +1 -1
  35. package/dist/doctor.js +7 -0
  36. package/dist/doctor.js.map +1 -1
  37. package/dist/enums.d.ts +123 -0
  38. package/dist/enums.d.ts.map +1 -0
  39. package/dist/enums.js +139 -0
  40. package/dist/enums.js.map +1 -0
  41. package/dist/index.d.ts +16 -3
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +4 -0
  44. package/dist/index.js.map +1 -1
  45. package/dist/jobs.d.ts +39 -0
  46. package/dist/jobs.d.ts.map +1 -0
  47. package/dist/jobs.js +19 -0
  48. package/dist/jobs.js.map +1 -0
  49. package/dist/memory/budgeted.d.ts +67 -0
  50. package/dist/memory/budgeted.d.ts.map +1 -0
  51. package/dist/memory/budgeted.js +17 -0
  52. package/dist/memory/budgeted.js.map +1 -0
  53. package/dist/memory/fetch.d.ts +58 -0
  54. package/dist/memory/fetch.d.ts.map +1 -0
  55. package/dist/memory/fetch.js +19 -0
  56. package/dist/memory/fetch.js.map +1 -0
  57. package/dist/memory/observe.d.ts +158 -0
  58. package/dist/memory/observe.d.ts.map +1 -0
  59. package/dist/memory/observe.js +46 -0
  60. package/dist/memory/observe.js.map +1 -0
  61. package/dist/memory/search.d.ts +137 -0
  62. package/dist/memory/search.d.ts.map +1 -0
  63. package/dist/memory/search.js +22 -0
  64. package/dist/memory/search.js.map +1 -0
  65. package/dist/memory/timeline.d.ts +89 -0
  66. package/dist/memory/timeline.d.ts.map +1 -0
  67. package/dist/memory/timeline.js +22 -0
  68. package/dist/memory/timeline.js.map +1 -0
  69. package/dist/operations/focus.d.ts +199 -0
  70. package/dist/operations/focus.d.ts.map +1 -0
  71. package/dist/operations/focus.js +15 -0
  72. package/dist/operations/focus.js.map +1 -0
  73. package/dist/operations/index.d.ts +1 -0
  74. package/dist/operations/index.d.ts.map +1 -1
  75. package/dist/operations/index.js +1 -0
  76. package/dist/operations/index.js.map +1 -1
  77. package/dist/operations/session.d.ts +54 -0
  78. package/dist/operations/session.d.ts.map +1 -1
  79. package/dist/operations/tasks.d.ts +38 -0
  80. package/dist/operations/tasks.d.ts.map +1 -1
  81. package/dist/operations/worktree.d.ts +138 -1
  82. package/dist/operations/worktree.d.ts.map +1 -1
  83. package/dist/provenance.d.ts +257 -0
  84. package/dist/provenance.d.ts.map +1 -0
  85. package/dist/provenance.js +42 -0
  86. package/dist/provenance.js.map +1 -0
  87. package/dist/release/plan.d.ts +7 -7
  88. package/dist/scaffold-diagnostics.d.ts +110 -0
  89. package/dist/scaffold-diagnostics.d.ts.map +1 -0
  90. package/dist/scaffold-diagnostics.js +28 -0
  91. package/dist/scaffold-diagnostics.js.map +1 -0
  92. package/dist/session.d.ts +37 -0
  93. package/dist/session.d.ts.map +1 -1
  94. package/dist/session.js.map +1 -1
  95. package/dist/tasks/archive.d.ts +3 -3
  96. package/package.json +42 -2
  97. package/src/__tests__/enums.test.ts +114 -0
  98. package/src/__tests__/jobs.test.ts +76 -0
  99. package/src/__tests__/memory-wire-shapes.test.ts +371 -0
  100. package/src/__tests__/operation-def.test.ts +185 -0
  101. package/src/__tests__/provenance.test.ts +259 -0
  102. package/src/__tests__/scaffold-diagnostics.test.ts +137 -0
  103. package/src/dispatch/identity.ts +109 -0
  104. package/src/dispatch/operation-def.ts +102 -0
  105. package/src/doctor.ts +62 -0
  106. package/src/enums.ts +144 -0
  107. package/src/index.ts +89 -2
  108. package/src/jobs.ts +45 -0
  109. package/src/memory/budgeted.ts +75 -0
  110. package/src/memory/fetch.ts +66 -0
  111. package/src/memory/observe.ts +176 -0
  112. package/src/memory/search.ts +145 -0
  113. package/src/memory/timeline.ts +100 -0
  114. package/src/operations/focus.ts +226 -0
  115. package/src/operations/index.ts +1 -0
  116. package/src/operations/session.ts +56 -0
  117. package/src/operations/tasks.ts +40 -0
  118. package/src/operations/worktree.ts +149 -1
  119. package/src/provenance.ts +335 -0
  120. package/src/scaffold-diagnostics.ts +119 -0
  121. package/src/session.ts +37 -0
@@ -0,0 +1,158 @@
1
+ /**
2
+ * BRAIN observation-write wire shapes.
3
+ *
4
+ * Canonical home for the parameters and result types of the public
5
+ * `observeBrain` operation — the unified BRAIN write path that persists
6
+ * agent observations into `brain_observations`. Companion to the
7
+ * read-side trio in {@link ./search.ts}, {@link ./timeline.ts}, and
8
+ * {@link ./fetch.ts}.
9
+ *
10
+ * The `BRAIN_OBSERVATION_SOURCE_TYPES` const is co-located here so the
11
+ * derived `BrainObservationSourceType` union has a single source of truth.
12
+ * `packages/core/src/store/memory-schema.ts` re-exports the const for
13
+ * Drizzle's `enum: [...]` column constraint, which requires the runtime
14
+ * tuple literal.
15
+ *
16
+ * Promoted from `packages/core/src/memory/brain-retrieval.ts` to
17
+ * `@cleocode/contracts` in Phase 0e of SG-ARCH-SOLID
18
+ * (E-CONTRACTS-FOUNDATION).
19
+ *
20
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
21
+ */
22
+ import type { BrainSourceConfidence } from '../brain.js';
23
+ import type { BrainObservationType } from '../facade.js';
24
+ /**
25
+ * Source-type tuple for `brain_observations.source_type` — how the
26
+ * observation was created.
27
+ *
28
+ * Originally defined in `packages/core/src/store/memory-schema.ts:134`.
29
+ * Promoted here so the derived {@link BrainObservationSourceType} union
30
+ * lives alongside its source. `memory-schema.ts` re-exports the const
31
+ * because Drizzle's `{ enum: ... }` column constraint requires the runtime
32
+ * tuple literal.
33
+ *
34
+ * - `agent` — produced by a spawned agent at task time.
35
+ * - `session-debrief` — synthesized at session end by the debrief pipeline.
36
+ * - `claude-mem` — imported from a claude-mem migration batch.
37
+ * - `manual` — typed directly by the owner via `cleo memory observe`.
38
+ *
39
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
40
+ */
41
+ export declare const BRAIN_OBSERVATION_SOURCE_TYPES: readonly ["agent", "session-debrief", "claude-mem", "manual"];
42
+ /**
43
+ * Derived string-literal union of valid `source_type` values.
44
+ *
45
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
46
+ */
47
+ export type BrainObservationSourceType = (typeof BRAIN_OBSERVATION_SOURCE_TYPES)[number];
48
+ /**
49
+ * Parameters for `observeBrain`.
50
+ *
51
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
52
+ */
53
+ export interface ObserveBrainParams {
54
+ /** Observation narrative — the free-form text persisted to `brain_observations.narrative`. */
55
+ text: string;
56
+ /** Optional display title; auto-derived from `text` when omitted. */
57
+ title?: string;
58
+ /** Optional cognitive observation type (`feature`, `bugfix`, `decision`, …). */
59
+ type?: BrainObservationType;
60
+ /** Optional project scope ID; defaults to the current project root. */
61
+ project?: string;
62
+ /** Session ID that produced the observation (provenance). */
63
+ sourceSessionId?: string;
64
+ /** How the observation was created (default `agent`). */
65
+ sourceType?: BrainObservationSourceType;
66
+ /** T417: agent provenance — the name of the spawned agent producing this observation. */
67
+ agent?: string;
68
+ /**
69
+ * T549 Wave 1-A: source reliability level.
70
+ * Overrides the default routing. If omitted, routing is determined automatically:
71
+ * - sourceType 'manual' → 'owner'
72
+ * - sourceType 'session-debrief' → 'task-outcome'
73
+ * - otherwise → 'agent'
74
+ */
75
+ sourceConfidence?: BrainSourceConfidence;
76
+ /**
77
+ * T794 BRAIN-05: cross-references to other memory entries or external IDs.
78
+ * When this array has ≥1 entry, the observation is auto-promoted from
79
+ * 'short' to 'medium' tier at write time to protect it from soft-eviction.
80
+ */
81
+ crossRef?: string[];
82
+ /**
83
+ * T799: SHA-256 refs of attachments to link to this observation.
84
+ *
85
+ * Stored as a JSON-encoded string in the `attachments_json` column.
86
+ * Each entry must be a 64-char hex SHA-256 from the tasks.db attachment store.
87
+ */
88
+ attachmentRefs?: string[];
89
+ /**
90
+ * T1897: Producer pipeline that created this observation.
91
+ * - `manual` — typed directly by owner
92
+ * - `auto-extract` — from fulfillPromotionLog / LLM extraction
93
+ * - `transcript-ingest`— imported from raw session transcript
94
+ * - `session-debrief` — synthesized at session end
95
+ * - `test` — inserted by test code
96
+ *
97
+ * Null on legacy rows and when not specified.
98
+ */
99
+ origin?: string | null;
100
+ /**
101
+ * T1897: JSON array of source brain_observations.id values this row was derived from.
102
+ * Null for directly-observed rows.
103
+ */
104
+ provenanceChain?: string[] | null;
105
+ /**
106
+ * T992: Internal flag — when true, bypasses the verifyAndStore gate.
107
+ * Set only by storeVerifiedCandidate in extraction-gate.ts to avoid
108
+ * infinite recursion (gate → storeVerifiedCandidate → observeBrain → gate).
109
+ * External callers MUST NOT set this flag.
110
+ */
111
+ _skipGate?: boolean;
112
+ }
113
+ /**
114
+ * Result envelope returned by `observeBrain`.
115
+ *
116
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
117
+ */
118
+ export interface ObserveBrainResult {
119
+ /** Identifier of the newly-persisted observation row. */
120
+ id: string;
121
+ /** Resolved BRAIN table name (always `observation` for `observeBrain`). */
122
+ type: string;
123
+ /** ISO 8601 creation timestamp. */
124
+ createdAt: string;
125
+ }
126
+ /**
127
+ * Structured payload stored in the `narrative` of a doc-attachment memory
128
+ * observation emitted by `cleo docs add` (T9976).
129
+ *
130
+ * The observation title is `"Doc attached: <slug>"` (or
131
+ * `"Doc attached: <attachmentId>"` when no slug is set) so
132
+ * `cleo memory find '<slug>'` reliably surfaces the entry via FTS.
133
+ *
134
+ * The payload is serialised as JSON and embedded in the observation
135
+ * `narrative` field so it can be recovered by `cleo memory verify`
136
+ * for round-trip attachment-existence checks.
137
+ *
138
+ * @task T9976
139
+ */
140
+ export interface DocAttachmentObservationPayload {
141
+ /** Slug recorded for this attachment (optional — omitted when none set). */
142
+ slug?: string;
143
+ /** Owner entity ID (task, session, observation, …). */
144
+ ownerId: string;
145
+ /** Taxonomy type classification (optional). */
146
+ type?: string;
147
+ /** Attachment ID assigned by the store. */
148
+ attachmentId: string;
149
+ /** ISO 8601 timestamp when the attachment was added. */
150
+ addedAt: string;
151
+ /**
152
+ * Observation kind discriminator — always `"doc-attachment"`.
153
+ * Used by `cleo memory verify` to identify doc-attachment observations
154
+ * and perform round-trip checks against the docs store.
155
+ */
156
+ kind: 'doc-attachment';
157
+ }
158
+ //# sourceMappingURL=observe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../../src/memory/observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAIzD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,8BAA8B,+DAKjC,CAAC;AAEX;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,OAAO,8BAA8B,CAAC,CAAC,MAAM,CAAC,CAAC;AAIzF;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,8FAA8F;IAC9F,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,IAAI,CAAC,EAAE,oBAAoB,CAAC;IAC5B,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,UAAU,CAAC,EAAE,0BAA0B,CAAC;IACxC,yFAAyF;IACzF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;IACzC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAClC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAID;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,yDAAyD;IACzD,EAAE,EAAE,MAAM,CAAC;IACX,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAID;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,+BAA+B;IAC9C,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,IAAI,EAAE,gBAAgB,CAAC;CACxB"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * BRAIN observation-write wire shapes.
3
+ *
4
+ * Canonical home for the parameters and result types of the public
5
+ * `observeBrain` operation — the unified BRAIN write path that persists
6
+ * agent observations into `brain_observations`. Companion to the
7
+ * read-side trio in {@link ./search.ts}, {@link ./timeline.ts}, and
8
+ * {@link ./fetch.ts}.
9
+ *
10
+ * The `BRAIN_OBSERVATION_SOURCE_TYPES` const is co-located here so the
11
+ * derived `BrainObservationSourceType` union has a single source of truth.
12
+ * `packages/core/src/store/memory-schema.ts` re-exports the const for
13
+ * Drizzle's `enum: [...]` column constraint, which requires the runtime
14
+ * tuple literal.
15
+ *
16
+ * Promoted from `packages/core/src/memory/brain-retrieval.ts` to
17
+ * `@cleocode/contracts` in Phase 0e of SG-ARCH-SOLID
18
+ * (E-CONTRACTS-FOUNDATION).
19
+ *
20
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
21
+ */
22
+ // ── BRAIN_OBSERVATION_SOURCE_TYPES + BrainObservationSourceType ─────
23
+ /**
24
+ * Source-type tuple for `brain_observations.source_type` — how the
25
+ * observation was created.
26
+ *
27
+ * Originally defined in `packages/core/src/store/memory-schema.ts:134`.
28
+ * Promoted here so the derived {@link BrainObservationSourceType} union
29
+ * lives alongside its source. `memory-schema.ts` re-exports the const
30
+ * because Drizzle's `{ enum: ... }` column constraint requires the runtime
31
+ * tuple literal.
32
+ *
33
+ * - `agent` — produced by a spawned agent at task time.
34
+ * - `session-debrief` — synthesized at session end by the debrief pipeline.
35
+ * - `claude-mem` — imported from a claude-mem migration batch.
36
+ * - `manual` — typed directly by the owner via `cleo memory observe`.
37
+ *
38
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
39
+ */
40
+ export const BRAIN_OBSERVATION_SOURCE_TYPES = [
41
+ 'agent',
42
+ 'session-debrief',
43
+ 'claude-mem',
44
+ 'manual',
45
+ ];
46
+ //# sourceMappingURL=observe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observe.js","sourceRoot":"","sources":["../../src/memory/observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH,uEAAuE;AAEvE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,OAAO;IACP,iBAAiB;IACjB,YAAY;IACZ,QAAQ;CACA,CAAC"}
@@ -0,0 +1,137 @@
1
+ /**
2
+ * BRAIN compact-search wire shapes.
3
+ *
4
+ * Canonical home for the parameters and result types of the public
5
+ * `searchBrainCompact` operation — Layer 1 of CLEO's 3-layer BRAIN retrieval
6
+ * pattern (search → timeline → fetch). Returns index-level hits (~50 tokens
7
+ * per result) so agents can scan a wide candidate set cheaply before drilling
8
+ * into a specific entry.
9
+ *
10
+ * Promoted from `packages/core/src/memory/brain-retrieval.ts` to
11
+ * `@cleocode/contracts` in Phase 0e of SG-ARCH-SOLID
12
+ * (E-CONTRACTS-FOUNDATION) so the Studio + CLI + downstream consumers can
13
+ * depend on the shape without importing core. Unblocks the
14
+ * `brain-retrieval.ts` god-module split tracked under E-CORE-DECOMP
15
+ * (T9834).
16
+ *
17
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
18
+ * @see Layer 2: {@link ./timeline.ts}
19
+ * @see Layer 3: {@link ./fetch.ts}
20
+ */
21
+ /**
22
+ * Single compact hit returned by `searchBrainCompact`.
23
+ *
24
+ * Minimal projection of a BRAIN table row designed for cheap scanning —
25
+ * the full payload is fetched on demand via `fetchBrainEntries` (Layer 3).
26
+ *
27
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
28
+ */
29
+ export interface BrainCompactHit {
30
+ /** Entry identifier (e.g. `D-arch-001`, `P-feat-042`). */
31
+ id: string;
32
+ /** Source BRAIN table that produced the hit. */
33
+ type: 'decision' | 'pattern' | 'learning' | 'observation';
34
+ /** Display title for the entry. */
35
+ title: string;
36
+ /** ISO 8601 creation date. */
37
+ date: string;
38
+ /** Legacy relevance score (BM25-only path); omit when `rrfScore` is set. */
39
+ relevance?: number;
40
+ /**
41
+ * RRF-fused score: sum of 1/(rank+60) across all retrieval sources.
42
+ * Present only when the RRF path is used (`useRRF=true`, default).
43
+ * Higher = stronger match. Comparable across results in the same query.
44
+ */
45
+ rrfScore?: number;
46
+ /**
47
+ * BM25-derived score, min-max normalized to [0, 1] across the result set.
48
+ * 1.0 = best BM25 rank in this query, 0.0 = worst (or not found via FTS).
49
+ * Present only when the RRF path is used and at least one FTS result exists.
50
+ */
51
+ bm25Score?: number;
52
+ /**
53
+ * Progressive-disclosure directives for follow-up operations.
54
+ *
55
+ * Maps follow-up keys (e.g. `fetch`, `timeline`) to suggested CLI commands.
56
+ * `Record<string, string>` mirrors the runtime `NextDirectives` alias used
57
+ * by `@cleocode/core`'s `mvi-helpers`.
58
+ */
59
+ _next?: Record<string, string>;
60
+ }
61
+ /**
62
+ * Parameters for `searchBrainCompact`.
63
+ *
64
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
65
+ */
66
+ export interface SearchBrainCompactParams {
67
+ /** Free-text query (FTS5 + optional vector recall). */
68
+ query: string;
69
+ /** Maximum number of hits to return (caller-bounded). */
70
+ limit?: number;
71
+ /** Restrict the search to a subset of BRAIN tables. */
72
+ tables?: Array<'decisions' | 'patterns' | 'learnings' | 'observations'>;
73
+ /** ISO 8601 lower-bound date filter (inclusive). */
74
+ dateStart?: string;
75
+ /** ISO 8601 upper-bound date filter (inclusive). */
76
+ dateEnd?: string;
77
+ /** T418: filter results to observations produced by a specific agent (Wave 8 mental models). */
78
+ agent?: string;
79
+ /**
80
+ * When true (default), use Reciprocal Rank Fusion to combine FTS5 and
81
+ * vector search results for higher recall and better ranking.
82
+ * When false, fall back to FTS5-only search (faster, no embeddings needed).
83
+ */
84
+ useRRF?: boolean;
85
+ /**
86
+ * T1085: Peer ID filter for CANT agent memory isolation (PSYCHE Wave 2).
87
+ *
88
+ * When provided, search results are scoped to entries where:
89
+ * `peer_id = peerId OR peer_id = 'global'`
90
+ *
91
+ * When omitted, all entries are returned — backward-compatible behavior.
92
+ */
93
+ peerId?: string;
94
+ /**
95
+ * T1085: When true (default when peerId is provided), include entries with
96
+ * `peer_id = 'global'` alongside the peer-specific entries.
97
+ *
98
+ * Set to false for strict per-peer isolation (no global pool bleed-through).
99
+ */
100
+ includeGlobal?: boolean;
101
+ /**
102
+ * T1900: ranking mode.
103
+ *
104
+ * - `recency` — ORDER BY created_at DESC, no BM25/RRF contribution.
105
+ * Use for recentObservations / recentLearnings where
106
+ * chronological freshness matters more than textual match.
107
+ * - `lexical` — FTS5 BM25 only (useRRF=false legacy path).
108
+ * - `hybrid` — Reciprocal Rank Fusion (default, useRRF=true path).
109
+ *
110
+ * @default 'hybrid'
111
+ */
112
+ mode?: 'recency' | 'lexical' | 'hybrid';
113
+ /**
114
+ * T1900: ISO 8601 timestamp lower-bound filter (inclusive).
115
+ *
116
+ * When provided, only rows with `created_at >= since` are returned.
117
+ * Applies to all modes including recency. Useful with `mode=hybrid`
118
+ * (e.g., `since=<30d>`) to limit pattern staleness.
119
+ *
120
+ * When omitted, no lower-bound date filter is applied.
121
+ */
122
+ since?: string;
123
+ }
124
+ /**
125
+ * Result envelope returned by `searchBrainCompact`.
126
+ *
127
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
128
+ */
129
+ export interface SearchBrainCompactResult {
130
+ /** Ordered compact hits (best match first). */
131
+ results: BrainCompactHit[];
132
+ /** Total number of matches before `limit` truncation. */
133
+ total: number;
134
+ /** Approximate token cost of the returned payload (~chars/4). */
135
+ tokensEstimated: number;
136
+ }
137
+ //# sourceMappingURL=search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/memory/search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,0DAA0D;IAC1D,EAAE,EAAE,MAAM,CAAC;IACX,gDAAgD;IAChD,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,UAAU,GAAG,aAAa,CAAC;IAC1D,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAID;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,MAAM,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,UAAU,GAAG,WAAW,GAAG,cAAc,CAAC,CAAC;IACxE,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gGAAgG;IAChG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;;;;OAUG;IACH,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IACxC;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,+CAA+C;IAC/C,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,eAAe,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * BRAIN compact-search wire shapes.
3
+ *
4
+ * Canonical home for the parameters and result types of the public
5
+ * `searchBrainCompact` operation — Layer 1 of CLEO's 3-layer BRAIN retrieval
6
+ * pattern (search → timeline → fetch). Returns index-level hits (~50 tokens
7
+ * per result) so agents can scan a wide candidate set cheaply before drilling
8
+ * into a specific entry.
9
+ *
10
+ * Promoted from `packages/core/src/memory/brain-retrieval.ts` to
11
+ * `@cleocode/contracts` in Phase 0e of SG-ARCH-SOLID
12
+ * (E-CONTRACTS-FOUNDATION) so the Studio + CLI + downstream consumers can
13
+ * depend on the shape without importing core. Unblocks the
14
+ * `brain-retrieval.ts` god-module split tracked under E-CORE-DECOMP
15
+ * (T9834).
16
+ *
17
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
18
+ * @see Layer 2: {@link ./timeline.ts}
19
+ * @see Layer 3: {@link ./fetch.ts}
20
+ */
21
+ export {};
22
+ //# sourceMappingURL=search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/memory/search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * BRAIN timeline wire shapes.
3
+ *
4
+ * Canonical home for the parameters and result types of the public
5
+ * `timelineBrain` operation — Layer 2 of CLEO's 3-layer BRAIN retrieval
6
+ * pattern (search → timeline → fetch). Surfaces chronological neighbors
7
+ * around an anchor entry so an agent can reconstruct the surrounding
8
+ * memory context cheaply.
9
+ *
10
+ * Promoted from `packages/core/src/memory/brain-retrieval.ts` to
11
+ * `@cleocode/contracts` in Phase 0e of SG-ARCH-SOLID
12
+ * (E-CONTRACTS-FOUNDATION). `BrainAnchor` is co-located here because it
13
+ * is the only `brain-row-types.ts` shape that escapes the core boundary
14
+ * via `TimelineBrainResult`; `packages/core/src/memory/brain-row-types.ts`
15
+ * continues to re-export it for internal callers.
16
+ *
17
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
18
+ * @see Layer 1: {@link ./search.ts}
19
+ * @see Layer 3: {@link ./fetch.ts}
20
+ */
21
+ /**
22
+ * Anchor entry around which a timeline is built.
23
+ *
24
+ * Carries the entry identifier, its source table (`type`), and the full
25
+ * payload (`data`) so the caller can render the anchor inline with the
26
+ * neighbor list without an additional `fetchBrainEntries` round trip.
27
+ *
28
+ * Originally defined in `packages/core/src/memory/brain-row-types.ts:46`.
29
+ *
30
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
31
+ */
32
+ export interface BrainAnchor {
33
+ /** Entry identifier (e.g. `O-abc123`, `D-arch-001`). */
34
+ id: string;
35
+ /** Source BRAIN table (e.g. `observation`, `decision`, `pattern`, `learning`). */
36
+ type: string;
37
+ /**
38
+ * Raw row payload as returned by the underlying SQL query.
39
+ *
40
+ * Typed as `unknown` because the shape varies by `type`. Callers narrow
41
+ * via a discriminated read or pass the value through to a renderer that
42
+ * already understands every BRAIN table shape.
43
+ */
44
+ data: unknown;
45
+ }
46
+ /**
47
+ * Parameters for `timelineBrain`.
48
+ *
49
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
50
+ */
51
+ export interface TimelineBrainParams {
52
+ /** Anchor entry ID to build the timeline around. */
53
+ anchor: string;
54
+ /** Number of chronologically-earlier neighbors to include. */
55
+ depthBefore?: number;
56
+ /** Number of chronologically-later neighbors to include. */
57
+ depthAfter?: number;
58
+ }
59
+ /**
60
+ * Compact neighbor projection used in timeline results.
61
+ *
62
+ * Each neighbor is reduced to an `{id, type, date}` triple so callers can
63
+ * cheaply scan a large window before drilling into specific entries via
64
+ * `fetchBrainEntries`.
65
+ *
66
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
67
+ */
68
+ export interface TimelineNeighbor {
69
+ /** Entry identifier. */
70
+ id: string;
71
+ /** Source BRAIN table (e.g. `observation`, `decision`). */
72
+ type: string;
73
+ /** ISO 8601 creation date. */
74
+ date: string;
75
+ }
76
+ /**
77
+ * Result envelope returned by `timelineBrain`.
78
+ *
79
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
80
+ */
81
+ export interface TimelineBrainResult {
82
+ /** The anchor entry, or `null` when the requested ID does not resolve. */
83
+ anchor: BrainAnchor | null;
84
+ /** Chronologically-earlier neighbors, oldest first. */
85
+ before: TimelineNeighbor[];
86
+ /** Chronologically-later neighbors, newest last. */
87
+ after: TimelineNeighbor[];
88
+ }
89
+ //# sourceMappingURL=timeline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/memory/timeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,WAAW;IAC1B,wDAAwD;IACxD,EAAE,EAAE,MAAM,CAAC;IACX,kFAAkF;IAClF,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,IAAI,EAAE,OAAO,CAAC;CACf;AAID;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAID;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wBAAwB;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd;AAID;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,0EAA0E;IAC1E,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3B,uDAAuD;IACvD,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,oDAAoD;IACpD,KAAK,EAAE,gBAAgB,EAAE,CAAC;CAC3B"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * BRAIN timeline wire shapes.
3
+ *
4
+ * Canonical home for the parameters and result types of the public
5
+ * `timelineBrain` operation — Layer 2 of CLEO's 3-layer BRAIN retrieval
6
+ * pattern (search → timeline → fetch). Surfaces chronological neighbors
7
+ * around an anchor entry so an agent can reconstruct the surrounding
8
+ * memory context cheaply.
9
+ *
10
+ * Promoted from `packages/core/src/memory/brain-retrieval.ts` to
11
+ * `@cleocode/contracts` in Phase 0e of SG-ARCH-SOLID
12
+ * (E-CONTRACTS-FOUNDATION). `BrainAnchor` is co-located here because it
13
+ * is the only `brain-row-types.ts` shape that escapes the core boundary
14
+ * via `TimelineBrainResult`; `packages/core/src/memory/brain-row-types.ts`
15
+ * continues to re-export it for internal callers.
16
+ *
17
+ * @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
18
+ * @see Layer 1: {@link ./search.ts}
19
+ * @see Layer 3: {@link ./fetch.ts}
20
+ */
21
+ export {};
22
+ //# sourceMappingURL=timeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/memory/timeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}