@cleocode/contracts 2026.4.96 → 2026.4.98

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 (68) hide show
  1. package/dist/config.d.ts +21 -0
  2. package/dist/config.d.ts.map +1 -1
  3. package/dist/facade.d.ts +64 -2
  4. package/dist/facade.d.ts.map +1 -1
  5. package/dist/facade.js +1 -0
  6. package/dist/facade.js.map +1 -1
  7. package/dist/index.d.ts +3 -2
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/operations/brain.d.ts +579 -0
  11. package/dist/operations/brain.d.ts.map +1 -0
  12. package/dist/operations/brain.js +39 -0
  13. package/dist/operations/brain.js.map +1 -0
  14. package/dist/operations/conduit.d.ts +151 -0
  15. package/dist/operations/conduit.d.ts.map +1 -0
  16. package/dist/operations/conduit.js +29 -0
  17. package/dist/operations/conduit.js.map +1 -0
  18. package/dist/operations/index.d.ts +4 -0
  19. package/dist/operations/index.d.ts.map +1 -1
  20. package/dist/operations/index.js +4 -0
  21. package/dist/operations/index.js.map +1 -1
  22. package/dist/operations/lifecycle.d.ts +29 -1
  23. package/dist/operations/lifecycle.d.ts.map +1 -1
  24. package/dist/operations/memory.d.ts +899 -0
  25. package/dist/operations/memory.d.ts.map +1 -0
  26. package/dist/operations/memory.js +26 -0
  27. package/dist/operations/memory.js.map +1 -0
  28. package/dist/operations/nexus.d.ts +577 -0
  29. package/dist/operations/nexus.d.ts.map +1 -0
  30. package/dist/operations/nexus.js +22 -0
  31. package/dist/operations/nexus.js.map +1 -0
  32. package/dist/operations/orchestrate.d.ts +451 -38
  33. package/dist/operations/orchestrate.d.ts.map +1 -1
  34. package/dist/operations/orchestrate.js +6 -0
  35. package/dist/operations/orchestrate.js.map +1 -1
  36. package/dist/operations/release.d.ts +78 -8
  37. package/dist/operations/release.d.ts.map +1 -1
  38. package/dist/operations/session.d.ts +26 -3
  39. package/dist/operations/session.d.ts.map +1 -1
  40. package/dist/operations/tasks.d.ts +140 -2
  41. package/dist/operations/tasks.d.ts.map +1 -1
  42. package/dist/sentient.d.ts +85 -0
  43. package/dist/sentient.d.ts.map +1 -0
  44. package/dist/sentient.js +13 -0
  45. package/dist/sentient.js.map +1 -0
  46. package/dist/status-registry.d.ts +1 -1
  47. package/dist/status-registry.d.ts.map +1 -1
  48. package/dist/status-registry.js +3 -0
  49. package/dist/status-registry.js.map +1 -1
  50. package/dist/task.d.ts +66 -0
  51. package/dist/task.d.ts.map +1 -1
  52. package/package.json +1 -1
  53. package/src/config.ts +22 -0
  54. package/src/facade.ts +65 -1
  55. package/src/index.ts +12 -0
  56. package/src/operations/brain.ts +635 -0
  57. package/src/operations/conduit.ts +189 -0
  58. package/src/operations/index.ts +4 -0
  59. package/src/operations/lifecycle.ts +29 -1
  60. package/src/operations/memory.ts +1053 -0
  61. package/src/operations/nexus.ts +711 -0
  62. package/src/operations/orchestrate.ts +447 -38
  63. package/src/operations/release.ts +77 -7
  64. package/src/operations/session.ts +26 -3
  65. package/src/operations/tasks.ts +141 -3
  66. package/src/sentient.ts +100 -0
  67. package/src/status-registry.ts +3 -0
  68. package/src/task.ts +75 -0
@@ -0,0 +1,579 @@
1
+ /**
2
+ * BRAIN Super-Domain Operations (8 operations)
3
+ *
4
+ * BRAIN is the **unified cross-substrate graph** wrapping
5
+ * `memory + nexus + tasks + conduit + signaldock` into a single
6
+ * super-graph substrate. It is distinct from (and layered above) the
7
+ * memory-only operations in `./memory.ts` which own observations,
8
+ * patterns, decisions, learnings, tiers, and the PageIndex graph
9
+ * scoped to `brain.db`.
10
+ *
11
+ * These wire-format contracts are the API surface consumed by:
12
+ * - `@cleocode/brain` (T969 — living-brain package extraction)
13
+ * - `packages/studio/src/routes/api/brain/*` HTTP routes (T970 — renamed
14
+ * from `/api/living-brain` as the canonical unified super-graph surface)
15
+ * - CLI / SDK clients performing cross-substrate graph queries
16
+ *
17
+ * Node IDs are **substrate-prefixed** (`"task:T949"`, `"memory:O-abc"`,
18
+ * `"code:symbol:foo"`) so cross-substrate edges are unambiguous and
19
+ * deduplication is safe by ID equality alone. The substrate-specific
20
+ * payload on `BrainNode.data` / `BrainEdge.data` is the ONE place where
21
+ * `Record<string, unknown>` is legitimate — super-graph callers treat
22
+ * it opaquely; individual substrate adapters own the concrete shape.
23
+ *
24
+ * SYNC: Canonical runtime implementation now lives at
25
+ * `@cleocode/brain` (BrainNode, BrainEdge, BrainGraph, adapters, SSE
26
+ * stream). The runtime shapes there are intentionally structurally
27
+ * distinct from these wire-format contracts — runtime `BrainNode` uses
28
+ * `kind: BrainNodeKind` + `meta` + optional adapter-produced `weight`,
29
+ * whereas contract `BrainNode` below uses `type: string` + `data`.
30
+ *
31
+ * @task T962 — Orchestration Coherence v4 (BRAIN super-domain)
32
+ * @task T968 — operations/brain.ts contract authoring (Wave B)
33
+ * @task T969 — `@cleocode/brain` package extraction
34
+ * @task T973 — runtime LB* → Brain* rename
35
+ * @see packages/brain/src/types.ts (runtime shapes)
36
+ * @see packages/contracts/src/operations/memory.ts (distinct domain)
37
+ */
38
+ /**
39
+ * Substrate name enum — which underlying database a node/edge came from.
40
+ *
41
+ * @remarks
42
+ * Intentionally distinct from the runtime
43
+ * `@cleocode/brain :: BrainSubstrate` type — the contracts layer uses
44
+ * `memory` (aligning with the cognitive-memory domain rename produced by
45
+ * `./memory.ts` in T965), while the runtime layer uses the legacy
46
+ * `brain` literal to match the on-disk `brain.db` file name. Callers
47
+ * translate between the two naming planes when bridging API wire format
48
+ * to live adapter output.
49
+ *
50
+ * @task T962 / T968
51
+ */
52
+ export type BrainSubstrateName = 'memory' | 'nexus' | 'tasks' | 'conduit' | 'signaldock';
53
+ /**
54
+ * Concrete node type within a substrate (e.g. `observation`, `symbol`,
55
+ * `task`, `session`, `agent`, `message`). Not constrained here because the
56
+ * set is substrate-owned and open-ended; each substrate adapter documents
57
+ * its own vocabulary.
58
+ *
59
+ * @task T962 / T968
60
+ */
61
+ export type BrainNodeType = string;
62
+ /**
63
+ * Substrate-prefixed node identifier.
64
+ *
65
+ * @example
66
+ * "task:T949"
67
+ * "memory:O-mo4abc123"
68
+ * "nexus:packages/core/src/store/sqlite-data-accessor.ts::createSqliteDataAccessor"
69
+ * "conduit:msg-7f3a2b1c"
70
+ * "signaldock:agent-cleo-prime"
71
+ *
72
+ * @remarks
73
+ * The substrate prefix (before the first `:`) MUST match one of
74
+ * `BrainSubstrateName`. The remainder is substrate-specific and opaque
75
+ * to super-graph callers.
76
+ *
77
+ * @task T962 / T968
78
+ */
79
+ export type BrainNodeId = string;
80
+ /**
81
+ * Edge kind taxonomy used across the super-graph.
82
+ *
83
+ * @remarks
84
+ * Concrete built-ins are enumerated for tooling autocompletion; the
85
+ * `string` fallback keeps the type open-ended because substrate
86
+ * adapters may introduce new kinds (e.g. `touches_code`, `authored_by`,
87
+ * `supersedes`, `derived_from`) without a schema migration at this
88
+ * layer.
89
+ *
90
+ * @task T962 / T968
91
+ */
92
+ export type BrainEdgeKind = 'parent' | 'depends' | 'blocks' | 'references' | 'discusses' | 'cites' | 'embeds' | 'touches_code' | 'messages' | string;
93
+ /**
94
+ * A single node in the BRAIN super-graph.
95
+ *
96
+ * @remarks
97
+ * The `data` field carries substrate-specific metadata (memory-tier info,
98
+ * task status, nexus symbol kind, conduit message preview, etc.). This
99
+ * is the ONE place `Record<string, unknown>` is justified: the
100
+ * super-graph is polymorphic across substrates by definition, and the
101
+ * statically-typed payload belongs inside each substrate adapter.
102
+ *
103
+ * @task T962 / T968
104
+ */
105
+ export interface BrainNode {
106
+ /** Substrate-prefixed identifier (see {@link BrainNodeId}). */
107
+ id: BrainNodeId;
108
+ /** Source substrate. */
109
+ substrate: BrainSubstrateName;
110
+ /** Concrete node type within the substrate (e.g. `observation`, `symbol`). */
111
+ type: BrainNodeType;
112
+ /** Human-readable display label. */
113
+ label: string;
114
+ /**
115
+ * Substrate-specific payload. Shape is owned by the substrate adapter;
116
+ * super-graph callers treat it opaquely.
117
+ */
118
+ data: Record<string, unknown>;
119
+ /** ISO 8601 creation timestamp, when exposed by the substrate. */
120
+ createdAt?: string;
121
+ /** ISO 8601 last-update timestamp, when exposed by the substrate. */
122
+ updatedAt?: string;
123
+ }
124
+ /**
125
+ * A directed edge between two super-graph nodes.
126
+ *
127
+ * @remarks
128
+ * Both endpoints reference {@link BrainNodeId} values. Edges may be
129
+ * in-substrate (both endpoints share the same prefix) or cross-substrate
130
+ * (bridges between e.g. `memory:…` and `nexus:…`).
131
+ *
132
+ * @task T962 / T968
133
+ */
134
+ export interface BrainEdge {
135
+ /** Source node id. */
136
+ from: BrainNodeId;
137
+ /** Target node id. */
138
+ to: BrainNodeId;
139
+ /** Semantic edge kind (see {@link BrainEdgeKind}). */
140
+ kind: BrainEdgeKind;
141
+ /**
142
+ * Normalised weight in `[0, 1]`. Higher = stronger/more confident.
143
+ * Produced by Hebbian/STDP training on memory edges, relation
144
+ * confidence on nexus edges, and substrate-specific heuristics
145
+ * elsewhere.
146
+ */
147
+ weight?: number;
148
+ /** Substrate-specific payload (opaque at super-graph level). */
149
+ data?: Record<string, unknown>;
150
+ }
151
+ /**
152
+ * Per-substrate node and edge counters returned inside query results.
153
+ *
154
+ * @task T962 / T968
155
+ */
156
+ export interface BrainSubstrateStats {
157
+ /** Number of nodes contributed by the substrate. */
158
+ nodes: number;
159
+ /** Number of edges contributed by the substrate. */
160
+ edges: number;
161
+ }
162
+ /**
163
+ * Predicate bag applied per-substrate when filtering graph queries.
164
+ *
165
+ * @remarks
166
+ * Each field is optional; adapters apply them in-substrate and ignore
167
+ * any dimension they don't support. When multiple fields are set the
168
+ * filter is an AND (e.g. `nodeType` ∈ {…} AND `labels` ⊆ node.labels
169
+ * AND `textMatch` matches).
170
+ *
171
+ * @task T962 / T968
172
+ */
173
+ export interface BrainGraphFilter {
174
+ /** Restrict to these node types (per-substrate vocabulary). */
175
+ nodeType?: string[];
176
+ /** Restrict to nodes carrying all of these labels. */
177
+ labels?: string[];
178
+ /** Free-text filter applied to the node label (substrate-dependent matcher). */
179
+ textMatch?: string;
180
+ }
181
+ /**
182
+ * Parameters for `brain.query`.
183
+ *
184
+ * @remarks
185
+ * `limit` is a cross-substrate total cap; adapters share the budget
186
+ * evenly (`limit / substrates.length`). Omitting `substrates`
187
+ * requests all five.
188
+ *
189
+ * @task T962 / T968
190
+ */
191
+ export interface BrainQueryParams {
192
+ /** Filter by substrate names. Default: all substrates. */
193
+ substrates?: BrainSubstrateName[];
194
+ /**
195
+ * Maximum total nodes to return across all requested substrates.
196
+ * Per-substrate budget is `limit / substrates.length`. Default `500`.
197
+ */
198
+ limit?: number;
199
+ /** Predicate bag applied per-substrate. */
200
+ filter?: BrainGraphFilter;
201
+ }
202
+ /**
203
+ * Result of `brain.query`.
204
+ *
205
+ * @task T962 / T968
206
+ */
207
+ export interface BrainQueryResult {
208
+ /** Merged, deduplicated nodes across substrates. */
209
+ nodes: BrainNode[];
210
+ /** Edges (may reference stub nodes injected for cross-substrate targets). */
211
+ edges: BrainEdge[];
212
+ /** Aggregate and per-substrate counters. */
213
+ stats: {
214
+ /** Per-substrate node/edge contribution. */
215
+ perSubstrate: Record<BrainSubstrateName, BrainSubstrateStats>;
216
+ /** Deduplicated total node count. */
217
+ totalNodes: number;
218
+ /** Edge count (no dedup — edges are unique by (from,to,kind)). */
219
+ totalEdges: number;
220
+ };
221
+ }
222
+ /**
223
+ * Parameters for `brain.node`.
224
+ *
225
+ * @task T962 / T968
226
+ */
227
+ export interface BrainNodeParams {
228
+ /**
229
+ * Substrate-prefixed id to fetch.
230
+ *
231
+ * @example `"task:T949"`, `"memory:O-abc"`, `"code:symbol:foo"`.
232
+ */
233
+ id: BrainNodeId;
234
+ }
235
+ /**
236
+ * Result of `brain.node`.
237
+ *
238
+ * @task T962 / T968
239
+ */
240
+ export interface BrainNodeResult {
241
+ /** The requested node. */
242
+ node: BrainNode;
243
+ /** Neighbour edges partitioned by direction relative to `node.id`. */
244
+ neighbors: {
245
+ /** Edges whose `to` equals the requested node. */
246
+ inbound: BrainEdge[];
247
+ /** Edges whose `from` equals the requested node. */
248
+ outbound: BrainEdge[];
249
+ };
250
+ }
251
+ /**
252
+ * Parameters for `brain.substrate`.
253
+ *
254
+ * @remarks
255
+ * Equivalent to `brain.query` with `substrates: [substrate]`, but
256
+ * provides a cleaner URL binding at the HTTP layer and emits a
257
+ * structured 400 error for unknown substrate names.
258
+ *
259
+ * @task T962 / T968
260
+ */
261
+ export interface BrainSubstrateParams {
262
+ /** Which substrate to project. */
263
+ substrate: BrainSubstrateName;
264
+ /** Maximum nodes to return. Default `500`. */
265
+ limit?: number;
266
+ /** Predicate bag applied to the substrate. */
267
+ filter?: BrainGraphFilter;
268
+ }
269
+ /**
270
+ * Result of `brain.substrate`.
271
+ *
272
+ * @task T962 / T968
273
+ */
274
+ export interface BrainSubstrateResult {
275
+ /** The substrate that was projected. */
276
+ substrate: BrainSubstrateName;
277
+ /** Nodes contributed by this substrate. */
278
+ nodes: BrainNode[];
279
+ /** Edges contributed by this substrate. */
280
+ edges: BrainEdge[];
281
+ /** True when the result was capped by `limit`. */
282
+ truncated: boolean;
283
+ }
284
+ /**
285
+ * Discriminated union of BRAIN super-graph mutation events.
286
+ *
287
+ * @remarks
288
+ * Emitted as Server-Sent Events by the `brain.stream` endpoint. Every
289
+ * variant carries an ISO 8601 `ts` field so clients can sequence events
290
+ * even when they arrive out-of-order.
291
+ *
292
+ * - `hello` — sent immediately on connect; confirms the stream is live.
293
+ * - `heartbeat` — sent every 30 s to prevent connection timeout.
294
+ * - `node.create` — a new node appeared in any substrate.
295
+ * - `node.update` — an existing node's metadata changed.
296
+ * - `edge.strengthen` — an edge weight was updated (Hebbian/STDP or relation).
297
+ * - `edge.create` — a new edge appeared.
298
+ * - `task.status` — shortcut for tasks-substrate status changes.
299
+ * - `message.send` — shortcut for conduit-substrate message inserts.
300
+ *
301
+ * Mirrors `@cleocode/brain :: BrainStreamEvent` with super-graph-aligned
302
+ * identifiers (ids are substrate-prefixed).
303
+ *
304
+ * @task T962 / T968
305
+ */
306
+ export type BrainStreamEvent = {
307
+ type: 'hello';
308
+ ts: string;
309
+ } | {
310
+ type: 'heartbeat';
311
+ ts: string;
312
+ } | {
313
+ type: 'node.create';
314
+ node: BrainNode;
315
+ ts: string;
316
+ } | {
317
+ type: 'node.update';
318
+ node: BrainNode;
319
+ ts: string;
320
+ } | {
321
+ type: 'edge.strengthen';
322
+ from: BrainNodeId;
323
+ to: BrainNodeId;
324
+ kind: BrainEdgeKind;
325
+ weight: number;
326
+ ts: string;
327
+ } | {
328
+ type: 'edge.create';
329
+ from: BrainNodeId;
330
+ to: BrainNodeId;
331
+ kind: BrainEdgeKind;
332
+ weight?: number;
333
+ ts: string;
334
+ } | {
335
+ type: 'task.status';
336
+ taskId: string;
337
+ status: string;
338
+ ts: string;
339
+ } | {
340
+ type: 'message.send';
341
+ messageId: string;
342
+ fromAgentId: string;
343
+ toAgentId: string;
344
+ preview: string;
345
+ ts: string;
346
+ };
347
+ /**
348
+ * Parameters for `brain.stream`.
349
+ *
350
+ * @remarks
351
+ * Clients may filter by substrate (only emit events from those DBs) and
352
+ * by event kind (only emit e.g. `node.create`). Both default to "all".
353
+ * `sinceTs` resumes from a prior ISO 8601 cursor when reconnecting.
354
+ *
355
+ * @task T962 / T968
356
+ */
357
+ export interface BrainStreamParams {
358
+ /** Restrict events to these substrates. Default: all. */
359
+ substrates?: BrainSubstrateName[];
360
+ /** Restrict to these event kinds (e.g. `['node.create', 'edge.strengthen']`). */
361
+ kinds?: Array<BrainStreamEvent['type']>;
362
+ /**
363
+ * ISO 8601 resume cursor. When set, the server replays events emitted
364
+ * at or after `sinceTs` before tailing the live stream.
365
+ */
366
+ sinceTs?: string;
367
+ }
368
+ /**
369
+ * Result of `brain.stream`.
370
+ *
371
+ * @remarks
372
+ * The stream is transport-flexible (HTTP SSE in the reference adapter,
373
+ * WebSocket or long-poll in alternates). The `Result` shape describes
374
+ * the **per-frame** payload clients receive; transport framing is an
375
+ * adapter concern.
376
+ *
377
+ * @task T962 / T968
378
+ */
379
+ export interface BrainStreamResult {
380
+ /** One decoded SSE frame. */
381
+ event: BrainStreamEvent;
382
+ }
383
+ /**
384
+ * Parameters for `brain.bridges`.
385
+ *
386
+ * @remarks
387
+ * Returns edges whose endpoints are in **different** substrates — e.g.
388
+ * `memory:O-abc → nexus:symbol:foo` (cognitive memory citing code) or
389
+ * `task:T949 → memory:D-decision-123` (task grounded in a decision).
390
+ * These are the substrate bridges that let the super-graph behave as a
391
+ * single knowledge surface rather than five isolated databases.
392
+ *
393
+ * @task T962 / T968
394
+ */
395
+ export interface BrainBridgesParams {
396
+ /**
397
+ * Restrict to bridges whose endpoints lie in this substrate set.
398
+ * When set, only bridges where **both** endpoints fall inside
399
+ * `substrates` are returned. Default: all substrates.
400
+ */
401
+ substrates?: BrainSubstrateName[];
402
+ /** Restrict to these edge kinds. Default: all kinds. */
403
+ kinds?: BrainEdgeKind[];
404
+ /** Minimum edge weight to include. Default `0`. */
405
+ minWeight?: number;
406
+ /** Max edges to return. Default `500`. */
407
+ limit?: number;
408
+ }
409
+ /**
410
+ * Result of `brain.bridges`.
411
+ *
412
+ * @task T962 / T968
413
+ */
414
+ export interface BrainBridgesResult {
415
+ /** Cross-substrate edges matching the query. */
416
+ bridges: BrainEdge[];
417
+ /** Per-pair counts keyed by `"${fromSubstrate}->${toSubstrate}"`. */
418
+ pairCounts: Record<string, number>;
419
+ /** Total bridges returned. */
420
+ total: number;
421
+ }
422
+ /**
423
+ * Parameters for `brain.neighborhood`.
424
+ *
425
+ * @remarks
426
+ * Breadth-first expansion from `seed` up to `hops` edges. Callers that
427
+ * need only direct neighbours should use `hops: 1`. Deep traversals
428
+ * should pair `hops` with `maxNodes` to bound fan-out.
429
+ *
430
+ * @task T962 / T968
431
+ */
432
+ export interface BrainNeighborhoodParams {
433
+ /** Seed node id. */
434
+ seed: BrainNodeId;
435
+ /** Max hops (BFS depth). Default `1`. */
436
+ hops?: number;
437
+ /** Cap on total returned nodes. Default `200`. */
438
+ maxNodes?: number;
439
+ /** Restrict traversal to these edge kinds. Default: all. */
440
+ edgeKinds?: BrainEdgeKind[];
441
+ /** Restrict traversal to these substrates. Default: all. */
442
+ substrates?: BrainSubstrateName[];
443
+ /** Minimum edge weight to traverse. Default `0`. */
444
+ minWeight?: number;
445
+ }
446
+ /**
447
+ * A single node visited during neighborhood expansion.
448
+ *
449
+ * @task T962 / T968
450
+ */
451
+ export interface BrainNeighborhoodNode {
452
+ /** The visited node. */
453
+ node: BrainNode;
454
+ /** BFS distance from the seed (`0` = seed itself). */
455
+ depth: number;
456
+ }
457
+ /**
458
+ * Result of `brain.neighborhood`.
459
+ *
460
+ * @task T962 / T968
461
+ */
462
+ export interface BrainNeighborhoodResult {
463
+ /** Seed node id that was expanded. */
464
+ seed: BrainNodeId;
465
+ /** Nodes visited, annotated with BFS depth. */
466
+ nodes: BrainNeighborhoodNode[];
467
+ /** Edges traversed during expansion. */
468
+ edges: BrainEdge[];
469
+ /** Maximum depth actually reached (≤ requested `hops`). */
470
+ reachedDepth: number;
471
+ /** True when the traversal was capped by `maxNodes`. */
472
+ truncated: boolean;
473
+ }
474
+ /**
475
+ * Parameters for `brain.search`.
476
+ *
477
+ * @remarks
478
+ * Cross-substrate text search. Each adapter picks the best available
479
+ * matcher (FTS5 for memory.db, identifier-substring for nexus, title
480
+ * match for tasks, etc.) and contributes hits scored on a normalised
481
+ * `[0, 1]` relevance axis. Results are fused by relevance desc.
482
+ *
483
+ * @task T962 / T968
484
+ */
485
+ export interface BrainSearchParams {
486
+ /** Search query (required, non-empty). */
487
+ query: string;
488
+ /** Restrict to these substrates. Default: all. */
489
+ substrates?: BrainSubstrateName[];
490
+ /** Restrict to these node types. Default: all. */
491
+ nodeTypes?: BrainNodeType[];
492
+ /** Max results. Default `50`. */
493
+ limit?: number;
494
+ }
495
+ /**
496
+ * A single fused search hit.
497
+ *
498
+ * @task T962 / T968
499
+ */
500
+ export interface BrainSearchHit {
501
+ /** The matched node. */
502
+ node: BrainNode;
503
+ /** Normalised relevance in `[0, 1]`. Higher = better. */
504
+ score: number;
505
+ /** Which substrate contributed this hit. */
506
+ substrate: BrainSubstrateName;
507
+ /** Adapter that produced the score (e.g. `fts`, `identifier`, `title`). */
508
+ matcher: string;
509
+ }
510
+ /**
511
+ * Result of `brain.search`.
512
+ *
513
+ * @task T962 / T968
514
+ */
515
+ export interface BrainSearchResult {
516
+ /** Hits ranked by `score` desc. */
517
+ hits: BrainSearchHit[];
518
+ /** Total hit count (may exceed `hits.length` when `limit` applied). */
519
+ total: number;
520
+ /** Estimated token weight of the payload (for JIT retrieval budgeting). */
521
+ tokensEstimated: number;
522
+ }
523
+ /**
524
+ * Parameters for `brain.stats`.
525
+ *
526
+ * @remarks
527
+ * Zero required params — returns the full super-graph telemetry
528
+ * snapshot. `substrates` narrows the report when only part of the
529
+ * graph matters to the caller.
530
+ *
531
+ * @task T962 / T968
532
+ */
533
+ export interface BrainStatsParams {
534
+ /** Restrict the report to these substrates. Default: all. */
535
+ substrates?: BrainSubstrateName[];
536
+ }
537
+ /**
538
+ * Per-substrate statistics returned inside `BrainStatsResult`.
539
+ *
540
+ * @task T962 / T968
541
+ */
542
+ export interface BrainSubstrateReport {
543
+ /** Substrate name. */
544
+ substrate: BrainSubstrateName;
545
+ /** Node count by {@link BrainNodeType}. */
546
+ nodesByType: Array<{
547
+ type: BrainNodeType;
548
+ count: number;
549
+ }>;
550
+ /** Edge count by {@link BrainEdgeKind}. */
551
+ edgesByKind: Array<{
552
+ kind: BrainEdgeKind;
553
+ count: number;
554
+ }>;
555
+ /** Total nodes for the substrate. */
556
+ totalNodes: number;
557
+ /** Total edges for the substrate. */
558
+ totalEdges: number;
559
+ /** ISO 8601 timestamp of the most recent mutation, when known. */
560
+ lastMutationAt: string | null;
561
+ }
562
+ /**
563
+ * Result of `brain.stats`.
564
+ *
565
+ * @task T962 / T968
566
+ */
567
+ export interface BrainStatsResult {
568
+ /** Per-substrate telemetry. */
569
+ perSubstrate: BrainSubstrateReport[];
570
+ /** Total nodes across all reported substrates. */
571
+ totalNodes: number;
572
+ /** Total edges across all reported substrates. */
573
+ totalEdges: number;
574
+ /** Count of cross-substrate bridges included in `totalEdges`. */
575
+ bridgeCount: number;
576
+ /** ISO 8601 timestamp when the report was computed. */
577
+ generatedAt: string;
578
+ }
579
+ //# sourceMappingURL=brain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brain.d.ts","sourceRoot":"","sources":["../../src/operations/brain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAMH;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,YAAY,CAAC;AAEzF;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,aAAa,GACrB,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,YAAY,GACZ,WAAW,GACX,OAAO,GACP,QAAQ,GACR,cAAc,GACd,UAAU,GACV,MAAM,CAAC;AAEX;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,SAAS;IACxB,+DAA+D;IAC/D,EAAE,EAAE,WAAW,CAAC;IAChB,wBAAwB;IACxB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,8EAA8E;IAC9E,IAAI,EAAE,aAAa,CAAC;IACpB,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,M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AAM,CAAC;IACnB,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * BRAIN Super-Domain Operations (8 operations)
3
+ *
4
+ * BRAIN is the **unified cross-substrate graph** wrapping
5
+ * `memory + nexus + tasks + conduit + signaldock` into a single
6
+ * super-graph substrate. It is distinct from (and layered above) the
7
+ * memory-only operations in `./memory.ts` which own observations,
8
+ * patterns, decisions, learnings, tiers, and the PageIndex graph
9
+ * scoped to `brain.db`.
10
+ *
11
+ * These wire-format contracts are the API surface consumed by:
12
+ * - `@cleocode/brain` (T969 — living-brain package extraction)
13
+ * - `packages/studio/src/routes/api/brain/*` HTTP routes (T970 — renamed
14
+ * from `/api/living-brain` as the canonical unified super-graph surface)
15
+ * - CLI / SDK clients performing cross-substrate graph queries
16
+ *
17
+ * Node IDs are **substrate-prefixed** (`"task:T949"`, `"memory:O-abc"`,
18
+ * `"code:symbol:foo"`) so cross-substrate edges are unambiguous and
19
+ * deduplication is safe by ID equality alone. The substrate-specific
20
+ * payload on `BrainNode.data` / `BrainEdge.data` is the ONE place where
21
+ * `Record<string, unknown>` is legitimate — super-graph callers treat
22
+ * it opaquely; individual substrate adapters own the concrete shape.
23
+ *
24
+ * SYNC: Canonical runtime implementation now lives at
25
+ * `@cleocode/brain` (BrainNode, BrainEdge, BrainGraph, adapters, SSE
26
+ * stream). The runtime shapes there are intentionally structurally
27
+ * distinct from these wire-format contracts — runtime `BrainNode` uses
28
+ * `kind: BrainNodeKind` + `meta` + optional adapter-produced `weight`,
29
+ * whereas contract `BrainNode` below uses `type: string` + `data`.
30
+ *
31
+ * @task T962 — Orchestration Coherence v4 (BRAIN super-domain)
32
+ * @task T968 — operations/brain.ts contract authoring (Wave B)
33
+ * @task T969 — `@cleocode/brain` package extraction
34
+ * @task T973 — runtime LB* → Brain* rename
35
+ * @see packages/brain/src/types.ts (runtime shapes)
36
+ * @see packages/contracts/src/operations/memory.ts (distinct domain)
37
+ */
38
+ export {};
39
+ //# sourceMappingURL=brain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brain.js","sourceRoot":"","sources":["../../src/operations/brain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG"}