@cleocode/brain 2026.11.17 → 2026.11.18

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.
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * Node IDs are prefixed with "tasks:" to prevent collisions.
10
10
  */
11
- import { allTyped, readProjectStore } from '../db-connections.js';
11
+ import { allTyped, readProjectStore, substrateResult, tryQuery } from '../db-connections.js';
12
12
  import { resolveDefaultProjectContext } from '../project-context.js';
13
13
  /** Maps priority string to numeric weight for BrainNode.weight. */
14
14
  function priorityWeight(priority) {
@@ -35,10 +35,10 @@ export function getTasksSubstrate(options = {}) {
35
35
  const minWeight = options.minWeight ?? 0;
36
36
  const nodes = [];
37
37
  const edges = [];
38
+ const errors = [];
38
39
  readProjectStore(ctx, (db) => {
39
- try {
40
- // Tasks (prioritised by severity, then recency)
41
- const taskRows = allTyped(db.prepare(`SELECT id, title, status, priority, type, parent_id, created_at
40
+ // Tasks (prioritised by severity, then recency)
41
+ const taskRows = tryQuery(errors, 'tasks_tasks', () => allTyped(db.prepare(`SELECT id, title, status, priority, type, parent_id, created_at
42
42
  FROM main.tasks_tasks
43
43
  WHERE status NOT IN ('archived', 'cancelled')
44
44
  ORDER BY
@@ -46,99 +46,95 @@ export function getTasksSubstrate(options = {}) {
46
46
  WHEN 'critical' THEN 0 WHEN 'high' THEN 1 WHEN 'medium' THEN 2 ELSE 3
47
47
  END,
48
48
  created_at DESC
49
- LIMIT ?`), Math.ceil(perSubstrateLimit * 0.8));
50
- const taskIds = new Set();
51
- for (const row of taskRows) {
52
- const weight = priorityWeight(row.priority);
53
- if (weight < minWeight)
54
- continue;
55
- taskIds.add(row.id);
56
- nodes.push({
57
- id: `tasks:${row.id}`,
58
- kind: 'task',
59
- substrate: 'tasks',
60
- label: row.title,
61
- weight,
62
- createdAt: row.created_at,
63
- meta: {
64
- status: row.status,
65
- priority: row.priority,
66
- type: row.type,
67
- parent_id: row.parent_id,
68
- created_at: row.created_at,
69
- },
70
- });
71
- }
72
- // Sessions (most recent)
73
- const sessionRows = allTyped(db.prepare(`SELECT id, status, started_at, ended_at
49
+ LIMIT ?`), Math.ceil(perSubstrateLimit * 0.8)));
50
+ const taskIds = new Set();
51
+ for (const row of taskRows) {
52
+ const weight = priorityWeight(row.priority);
53
+ if (weight < minWeight)
54
+ continue;
55
+ taskIds.add(row.id);
56
+ nodes.push({
57
+ id: `tasks:${row.id}`,
58
+ kind: 'task',
59
+ substrate: 'tasks',
60
+ label: row.title,
61
+ weight,
62
+ createdAt: row.created_at,
63
+ meta: {
64
+ status: row.status,
65
+ priority: row.priority,
66
+ type: row.type,
67
+ parent_id: row.parent_id,
68
+ created_at: row.created_at,
69
+ },
70
+ });
71
+ }
72
+ // Sessions (most recent)
73
+ const sessionRows = tryQuery(errors, 'tasks_sessions', () => allTyped(db.prepare(`SELECT id, status, started_at, ended_at
74
74
  FROM main.tasks_sessions
75
75
  ORDER BY started_at DESC
76
- LIMIT ?`), Math.ceil(perSubstrateLimit * 0.2));
77
- const sessionIds = new Set();
78
- for (const row of sessionRows) {
79
- sessionIds.add(row.id);
80
- nodes.push({
81
- id: `tasks:${row.id}`,
82
- kind: 'session',
76
+ LIMIT ?`), Math.ceil(perSubstrateLimit * 0.2)));
77
+ const sessionIds = new Set();
78
+ for (const row of sessionRows) {
79
+ sessionIds.add(row.id);
80
+ nodes.push({
81
+ id: `tasks:${row.id}`,
82
+ kind: 'session',
83
+ substrate: 'tasks',
84
+ label: `Session ${row.id.slice(-8)}`,
85
+ weight: row.status === 'active' ? 0.9 : 0.4,
86
+ createdAt: row.started_at,
87
+ meta: {
88
+ status: row.status,
89
+ started_at: row.started_at,
90
+ ended_at: row.ended_at,
91
+ },
92
+ });
93
+ }
94
+ // Parent → child task edges
95
+ for (const row of taskRows) {
96
+ if (row.parent_id && taskIds.has(row.parent_id)) {
97
+ edges.push({
98
+ source: `tasks:${row.parent_id}`,
99
+ target: `tasks:${row.id}`,
100
+ type: 'parent_of',
101
+ weight: 0.9,
83
102
  substrate: 'tasks',
84
- label: `Session ${row.id.slice(-8)}`,
85
- weight: row.status === 'active' ? 0.9 : 0.4,
86
- createdAt: row.started_at,
87
- meta: {
88
- status: row.status,
89
- started_at: row.started_at,
90
- ended_at: row.ended_at,
91
- },
92
103
  });
93
104
  }
94
- // Parent → child task edges
95
- for (const row of taskRows) {
96
- if (row.parent_id && taskIds.has(row.parent_id)) {
97
- edges.push({
98
- source: `tasks:${row.parent_id}`,
99
- target: `tasks:${row.id}`,
100
- type: 'parent_of',
101
- weight: 0.9,
102
- substrate: 'tasks',
103
- });
104
- }
105
- }
106
- // Task relations
107
- if (taskIds.size > 0) {
108
- const placeholders = [...taskIds].map(() => '?').join(',');
109
- const relRows = allTyped(db.prepare(`SELECT task_id, related_to, relation_type
105
+ }
106
+ // Task relations
107
+ if (taskIds.size > 0) {
108
+ const placeholders = [...taskIds].map(() => '?').join(',');
109
+ const relRows = tryQuery(errors, 'tasks_task_relations', () => allTyped(db.prepare(`SELECT task_id, related_to, relation_type
110
110
  FROM main.tasks_task_relations
111
111
  WHERE task_id IN (${placeholders})
112
- AND related_to IN (${placeholders})`), ...taskIds, ...taskIds);
113
- for (const row of relRows) {
114
- edges.push({
115
- source: `tasks:${row.task_id}`,
116
- target: `tasks:${row.related_to}`,
117
- type: row.relation_type,
118
- weight: 0.7,
119
- substrate: 'tasks',
120
- });
121
- }
122
- // Task dependencies
123
- const depRows = allTyped(db.prepare(`SELECT task_id, depends_on
112
+ AND related_to IN (${placeholders})`), ...taskIds, ...taskIds));
113
+ for (const row of relRows) {
114
+ edges.push({
115
+ source: `tasks:${row.task_id}`,
116
+ target: `tasks:${row.related_to}`,
117
+ type: row.relation_type,
118
+ weight: 0.7,
119
+ substrate: 'tasks',
120
+ });
121
+ }
122
+ // Task dependencies
123
+ const depRows = tryQuery(errors, 'tasks_task_dependencies', () => allTyped(db.prepare(`SELECT task_id, depends_on
124
124
  FROM main.tasks_task_dependencies
125
125
  WHERE task_id IN (${placeholders})
126
- AND depends_on IN (${placeholders})`), ...taskIds, ...taskIds);
127
- for (const row of depRows) {
128
- edges.push({
129
- source: `tasks:${row.task_id}`,
130
- target: `tasks:${row.depends_on}`,
131
- type: 'depends_on',
132
- weight: 0.85,
133
- substrate: 'tasks',
134
- });
135
- }
126
+ AND depends_on IN (${placeholders})`), ...taskIds, ...taskIds));
127
+ for (const row of depRows) {
128
+ edges.push({
129
+ source: `tasks:${row.task_id}`,
130
+ target: `tasks:${row.depends_on}`,
131
+ type: 'depends_on',
132
+ weight: 0.85,
133
+ substrate: 'tasks',
134
+ });
136
135
  }
137
136
  }
138
- catch {
139
- // Return partial results on error
140
- }
141
- });
142
- return { nodes, edges };
137
+ }, (message) => errors.push(message));
138
+ return substrateResult(nodes, edges, errors);
143
139
  }
144
140
  //# sourceMappingURL=tasks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../../src/adapters/tasks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAmCrE,mEAAmE;AACnE,SAAS,cAAc,CAAC,QAAgB;IACtC,MAAM,GAAG,GAA2B;QAClC,QAAQ,EAAE,GAAG;QACb,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,GAAG;QACX,GAAG,EAAE,IAAI;KACV,CAAC;IACF,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC;AAC/B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAA6B,EAAE;IAI/D,MAAM,GAAG,GAAG,OAAO,CAAC,UAAU,IAAI,4BAA4B,EAAE,CAAC;IACjE,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,IAAI,GAAG,CAAC,G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EAAE,SAAS,GAAG,CAAC,UAAU,EAAE;oBACjC,IAAI,EAAE,GAAG,CAAC,aAAa;oBACvB,MAAM,EAAE,GAAG;oBACX,SAAS,EAAE,OAAO;iBACnB,CAAC,CAAC;YACL,CAAC;YAED,oBAAoB;YACpB,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,EAAE,yBAAyB,EAAE,GAAG,EAAE,CAC/D,QAAQ,CACN,EAAE,CAAC,OAAO,CACR;;+BAEiB,YAAY;kCACT,YAAY,GAAG,CACpC,EACD,GAAG,OAAO,EACV,GAAG,OAAO,CACX,CACF,CAAC;YAEF,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;gBAC1B,KAAK,CAAC,IAAI,CAAC;oBACT,MAAM,EAAE,SAAS,GAAG,CAAC,OAAO,EAAE;oBAC9B,MAAM,EAAE,SAAS,GAAG,CAAC,UAAU,EAAE;oBACjC,IAAI,EAAE,YAAY;oBAClB,MAAM,EAAE,IAAI;oBACZ,SAAS,EAAE,OAAO;iBACnB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC,EACD,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAClC,CAAC;IAEF,OAAO,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC"}
@@ -19,6 +19,7 @@
19
19
  */
20
20
  import type { DatabaseSync } from 'node:sqlite';
21
21
  import type { ProjectContext } from './project-context.js';
22
+ import type { BrainEdge, BrainNode, BrainSubstrateResult } from './types.js';
22
23
  /**
23
24
  * Minimal structural view of a `node:sqlite` prepared statement.
24
25
  *
@@ -46,20 +47,46 @@ interface PreparedStatementLike {
46
47
  * @returns Rows materialised as `T[]`.
47
48
  */
48
49
  export declare function allTyped<T>(stmt: PreparedStatementLike, ...params: unknown[]): T[];
50
+ /**
51
+ * Receives one read failure of a substrate, so the caller can report it
52
+ * instead of returning a silently empty substrate (T14656).
53
+ */
54
+ export type StoreErrorSink = (message: string) => void;
49
55
  /**
50
56
  * Runs `read` against the project-scope `cleo.db` named by `ctx`.
51
57
  *
52
58
  * @param ctx - The active project context; `tasksDbPath` names its `cleo.db`.
53
59
  * @param read - Synchronous read against the project store.
60
+ * @param onError - Receives an open or read failure (see {@link StoreErrorSink}).
54
61
  * @returns The read's result, or null when the store is missing or unreadable.
55
62
  */
56
- export declare function readProjectStore<T>(ctx: ProjectContext, read: (db: DatabaseSync) => T): T | null;
63
+ export declare function readProjectStore<T>(ctx: ProjectContext, read: (db: DatabaseSync) => T, onError?: StoreErrorSink): T | null;
57
64
  /**
58
65
  * Runs `read` against the global-scope `cleo.db` under CLEO home.
59
66
  *
60
67
  * @param read - Synchronous read against the global store.
68
+ * @param onError - Receives an open or read failure (see {@link StoreErrorSink}).
61
69
  * @returns The read's result, or null when the store is missing or unreadable.
62
70
  */
63
- export declare function readGlobalStore<T>(read: (db: DatabaseSync) => T): T | null;
71
+ export declare function readGlobalStore<T>(read: (db: DatabaseSync) => T, onError?: StoreErrorSink): T | null;
72
+ /**
73
+ * Runs one substrate query, recording its failure instead of throwing, so one
74
+ * failing query never skips the substrate's other queries (T14656).
75
+ *
76
+ * @param errors - Collects `<name>: <message>` for each failed query.
77
+ * @param name - The query's name in the recorded message (usually its table).
78
+ * @param query - The query to run.
79
+ * @returns The query's rows, or an empty array when it failed.
80
+ */
81
+ export declare function tryQuery<T>(errors: string[], name: string, query: () => T[]): T[];
82
+ /**
83
+ * Builds an adapter result, joining the recorded failures into `error`.
84
+ *
85
+ * @param nodes - Nodes read from the substrate.
86
+ * @param edges - Edges read from the substrate.
87
+ * @param errors - Failures recorded while reading; empty when every read succeeded.
88
+ * @returns The result, with `error` set only when a read failed.
89
+ */
90
+ export declare function substrateResult(nodes: BrainNode[], edges: BrainEdge[], errors: string[]): BrainSubstrateResult;
64
91
  export {};
65
92
  //# sourceMappingURL=db-connections.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"db-connections.d.ts","sourceRoot":"","sources":["../../src/db-connections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D;;;;;;;GAOG;AACH,UAAU,qBAAqB;IAC7B,GAAG,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;CACtC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,CAElF;AA8BD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAEhG;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAE1E"}
1
+ {"version":3,"file":"db-connections.d.ts","sourceRoot":"","sources":["../../src/db-connections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAM7E;;;;;;;GAOG;AACH,UAAU,qBAAqB;IAC7B,GAAG,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;CACtC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,CAElF;AAMD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAqCvD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,CAAC,EAC7B,OAAO,CAAC,EAAE,cAAc,GACvB,CAAC,GAAG,IAAI,CAEV;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,IAAI,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,CAAC,EAC7B,OAAO,CAAC,EAAE,cAAc,GACvB,CAAC,GAAG,IAAI,CAEV;AAMD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,EAAE,CAOjF;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,EAAE,EAClB,KAAK,EAAE,SAAS,EAAE,EAClB,MAAM,EAAE,MAAM,EAAE,GACf,oBAAoB,CAEtB"}
@@ -18,6 +18,7 @@
18
18
  * @task T14583 (consolidated cleo.db through the store chokepoint)
19
19
  */
20
20
  import { existsSync } from 'node:fs';
21
+ import { getErrorMessage } from '@cleocode/contracts/errors.js';
21
22
  import { openCleoDbSnapshot } from '@cleocode/core/store/open-cleo-db.js';
22
23
  import { getGlobalStorePath } from './cleo-home.js';
23
24
  /**
@@ -38,31 +39,37 @@ import { getGlobalStorePath } from './cleo-home.js';
38
39
  export function allTyped(stmt, ...params) {
39
40
  return stmt.all(...params);
40
41
  }
41
- // ---------------------------------------------------------------------------
42
- // Store readers
43
- // ---------------------------------------------------------------------------
44
42
  /**
45
43
  * Runs `read` against a read-only snapshot of the store at `path`.
46
44
  *
47
45
  * @param path - Absolute path to a consolidated `cleo.db`.
48
46
  * @param read - Synchronous read; the handle is closed when it returns.
49
- * @returns The read's result, or null when the store is missing or cannot be
50
- * opened (a restore in progress, a malformed file), so the substrate degrades
51
- * to no nodes.
47
+ * @param onError - Receives the failure when the store exists but cannot be
48
+ * opened (a restore in progress, a malformed file) or `read` throws. Without
49
+ * it a failed open returns null and a throwing `read` propagates.
50
+ * @returns The read's result, or null when the store is missing, cannot be
51
+ * opened, or `read` failed and `onError` received the failure.
52
52
  */
53
- function readStore(path, read) {
53
+ function readStore(path, read, onError) {
54
54
  if (!existsSync(path))
55
55
  return null;
56
56
  let snapshot;
57
57
  try {
58
58
  snapshot = openCleoDbSnapshot(path, { readOnly: true });
59
59
  }
60
- catch {
60
+ catch (err) {
61
+ onError?.(`store cannot be opened: ${getErrorMessage(err)}`);
61
62
  return null;
62
63
  }
63
64
  try {
64
65
  return read(snapshot.db);
65
66
  }
67
+ catch (err) {
68
+ if (!onError)
69
+ throw err;
70
+ onError(getErrorMessage(err));
71
+ return null;
72
+ }
66
73
  finally {
67
74
  snapshot.close();
68
75
  }
@@ -72,18 +79,52 @@ function readStore(path, read) {
72
79
  *
73
80
  * @param ctx - The active project context; `tasksDbPath` names its `cleo.db`.
74
81
  * @param read - Synchronous read against the project store.
82
+ * @param onError - Receives an open or read failure (see {@link StoreErrorSink}).
75
83
  * @returns The read's result, or null when the store is missing or unreadable.
76
84
  */
77
- export function readProjectStore(ctx, read) {
78
- return readStore(ctx.tasksDbPath, read);
85
+ export function readProjectStore(ctx, read, onError) {
86
+ return readStore(ctx.tasksDbPath, read, onError);
79
87
  }
80
88
  /**
81
89
  * Runs `read` against the global-scope `cleo.db` under CLEO home.
82
90
  *
83
91
  * @param read - Synchronous read against the global store.
92
+ * @param onError - Receives an open or read failure (see {@link StoreErrorSink}).
84
93
  * @returns The read's result, or null when the store is missing or unreadable.
85
94
  */
86
- export function readGlobalStore(read) {
87
- return readStore(getGlobalStorePath(), read);
95
+ export function readGlobalStore(read, onError) {
96
+ return readStore(getGlobalStorePath(), read, onError);
97
+ }
98
+ // ---------------------------------------------------------------------------
99
+ // Per-query failure capture
100
+ // ---------------------------------------------------------------------------
101
+ /**
102
+ * Runs one substrate query, recording its failure instead of throwing, so one
103
+ * failing query never skips the substrate's other queries (T14656).
104
+ *
105
+ * @param errors - Collects `<name>: <message>` for each failed query.
106
+ * @param name - The query's name in the recorded message (usually its table).
107
+ * @param query - The query to run.
108
+ * @returns The query's rows, or an empty array when it failed.
109
+ */
110
+ export function tryQuery(errors, name, query) {
111
+ try {
112
+ return query();
113
+ }
114
+ catch (err) {
115
+ errors.push(`${name}: ${getErrorMessage(err)}`);
116
+ return [];
117
+ }
118
+ }
119
+ /**
120
+ * Builds an adapter result, joining the recorded failures into `error`.
121
+ *
122
+ * @param nodes - Nodes read from the substrate.
123
+ * @param edges - Edges read from the substrate.
124
+ * @param errors - Failures recorded while reading; empty when every read succeeded.
125
+ * @returns The result, with `error` set only when a read failed.
126
+ */
127
+ export function substrateResult(nodes, edges, errors) {
128
+ return errors.length === 0 ? { nodes, edges } : { nodes, edges, error: errors.join('; ') };
88
129
  }
89
130
  //# sourceMappingURL=db-connections.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"db-connections.js","sourceRoot":"","sources":["../../src/db-connections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAmBpD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,QAAQ,CAAI,IAA2B,EAAE,GAAG,MAAiB;IAC3E,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAQ,CAAC;AAC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MAAgB,EAAE,IAAY,EAAE,KAAgB;IAC1E,IAAI,CAAC;QACH,OAAO,KAAK,EAAE,CAAC;IACjB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,KAAK,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChD,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAkB,EAClB,KAAkB,EAClB,MAAgB;IAEhB,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAC7F,CAAC"}
@@ -18,5 +18,5 @@
18
18
  * @task T969 — `@cleocode/brain` package extraction
19
19
  * @see packages/contracts/src/brain-graph.ts (canonical source)
20
20
  */
21
- export type { BrainConnectionStatus, BrainEdge, BrainGraph, BrainNode, BrainNodeKind, BrainProjectContext, BrainQueryOptions, BrainStreamEvent, BrainSubstrate, } from '@cleocode/contracts';
21
+ export type { BrainConnectionStatus, BrainEdge, BrainGraph, BrainNode, BrainNodeKind, BrainProjectContext, BrainQueryOptions, BrainStreamEvent, BrainSubstrate, BrainSubstrateResult, } from '@cleocode/contracts';
22
22
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,YAAY,EACV,qBAAqB,EACrB,SAAS,EACT,UAAU,EACV,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACf,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,YAAY,EACV,qBAAqB,EACrB,SAAS,EACT,UAAU,EACV,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,oBAAoB,GACrB,MAAM,qBAAqB,CAAC"}