@cleocode/brain 2026.6.14 → 2026.6.17

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 (46) hide show
  1. package/dist/src/adapters/agent-registry.d.ts +35 -0
  2. package/dist/src/adapters/agent-registry.d.ts.map +1 -0
  3. package/dist/src/adapters/agent-registry.js +96 -0
  4. package/dist/src/adapters/agent-registry.js.map +1 -0
  5. package/dist/src/adapters/brain.d.ts +35 -0
  6. package/dist/src/adapters/brain.d.ts.map +1 -0
  7. package/dist/src/adapters/brain.js +303 -0
  8. package/dist/src/adapters/brain.js.map +1 -0
  9. package/dist/src/adapters/conduit.d.ts +25 -0
  10. package/dist/src/adapters/conduit.d.ts.map +1 -0
  11. package/dist/src/adapters/conduit.js +94 -0
  12. package/dist/src/adapters/conduit.js.map +1 -0
  13. package/dist/src/adapters/index.d.ts +32 -0
  14. package/dist/src/adapters/index.d.ts.map +1 -0
  15. package/dist/src/adapters/index.js +194 -0
  16. package/dist/src/adapters/index.js.map +1 -0
  17. package/dist/src/adapters/nexus.d.ts +24 -0
  18. package/dist/src/adapters/nexus.d.ts.map +1 -0
  19. package/dist/src/adapters/nexus.js +83 -0
  20. package/dist/src/adapters/nexus.js.map +1 -0
  21. package/dist/src/adapters/tasks.d.ts +23 -0
  22. package/dist/src/adapters/tasks.d.ts.map +1 -0
  23. package/dist/src/adapters/tasks.js +143 -0
  24. package/dist/src/adapters/tasks.js.map +1 -0
  25. package/dist/src/cleo-home.d.ts +47 -0
  26. package/dist/src/cleo-home.d.ts.map +1 -0
  27. package/dist/src/cleo-home.js +73 -0
  28. package/dist/src/cleo-home.js.map +1 -0
  29. package/dist/src/db-connections.d.ts +143 -0
  30. package/dist/src/db-connections.d.ts.map +1 -0
  31. package/dist/src/db-connections.js +215 -0
  32. package/dist/src/db-connections.js.map +1 -0
  33. package/dist/src/index.d.ts +26 -0
  34. package/dist/src/index.d.ts.map +1 -0
  35. package/dist/src/index.js +29 -0
  36. package/dist/src/index.js.map +1 -0
  37. package/dist/src/project-context.d.ts +47 -0
  38. package/dist/src/project-context.d.ts.map +1 -0
  39. package/dist/src/project-context.js +52 -0
  40. package/dist/src/project-context.js.map +1 -0
  41. package/dist/src/types.d.ts +22 -0
  42. package/dist/src/types.d.ts.map +1 -0
  43. package/dist/src/types.js +22 -0
  44. package/dist/src/types.js.map +1 -0
  45. package/dist/tsconfig.build.tsbuildinfo +1 -0
  46. package/package.json +4 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/C,OAAO,KAAK,EAEV,UAAU,EAEV,iBAAiB,EAElB,MAAM,aAAa,CAAC;AAgIrB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,iBAAsB,GAAG,UAAU,CAuE5E"}
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Barrel for all substrate adapters.
3
+ *
4
+ * Re-exports individual adapter functions and provides the unified
5
+ * `getAllSubstrates()` function that merges results from all five databases
6
+ * into a single BrainGraph.
7
+ */
8
+ export { getAgentRegistrySubstrate } from './agent-registry.js';
9
+ export { getBrainSubstrate } from './brain.js';
10
+ export { getConduitSubstrate } from './conduit.js';
11
+ export { getNexusSubstrate } from './nexus.js';
12
+ export { getTasksSubstrate } from './tasks.js';
13
+ import { allTyped, getNexusDb } from '../db-connections.js';
14
+ import { getAgentRegistrySubstrate } from './agent-registry.js';
15
+ import { getBrainSubstrate } from './brain.js';
16
+ import { getConduitSubstrate } from './conduit.js';
17
+ import { getNexusSubstrate } from './nexus.js';
18
+ import { getTasksSubstrate } from './tasks.js';
19
+ /** Substrate names ordered for iteration. */
20
+ const ALL_SUBSTRATES = ['brain', 'nexus', 'tasks', 'conduit', 'agent-registry'];
21
+ /** Maps substrate name to its adapter function. */
22
+ const ADAPTER_MAP = {
23
+ brain: getBrainSubstrate,
24
+ nexus: getNexusSubstrate,
25
+ tasks: getTasksSubstrate,
26
+ conduit: getConduitSubstrate,
27
+ 'agent-registry': getAgentRegistrySubstrate,
28
+ };
29
+ /**
30
+ * Loads minimal stub nodes for any edge target IDs not already loaded.
31
+ *
32
+ * This second-pass loader ensures that cross-substrate edges
33
+ * (particularly brain→nexus bridges) don't reference unloaded target nodes.
34
+ *
35
+ * Stub nodes carry only minimal metadata: {id, substrate, kind, label}.
36
+ * Full details defer to side-panel click or future full-load request.
37
+ *
38
+ * @param loadedNodeIds - Set of already-loaded node IDs (substrate-prefixed).
39
+ * @param edges - All edges collected from substrates (may reference unloaded targets).
40
+ * @returns Array of stub BrainNode objects for missing targets.
41
+ */
42
+ function loadStubNodesForEdgeTargets(loadedNodeIds, edges) {
43
+ // Collect all target IDs referenced by edges but not yet loaded
44
+ const missingTargetIds = new Set();
45
+ for (const edge of edges) {
46
+ if (!loadedNodeIds.has(edge.target)) {
47
+ missingTargetIds.add(edge.target);
48
+ }
49
+ }
50
+ if (missingTargetIds.size === 0)
51
+ return [];
52
+ // Partition missing target IDs by substrate
53
+ const stubsBySubstrate = new Map();
54
+ for (const nodeId of missingTargetIds) {
55
+ const sep = nodeId.indexOf(':');
56
+ if (sep === -1)
57
+ continue;
58
+ const substrateStr = nodeId.slice(0, sep);
59
+ const substrate = substrateStr;
60
+ if (!['brain', 'nexus', 'tasks', 'conduit', 'agent-registry'].includes(substrate)) {
61
+ continue;
62
+ }
63
+ if (!stubsBySubstrate.has(substrate)) {
64
+ stubsBySubstrate.set(substrate, []);
65
+ }
66
+ stubsBySubstrate.get(substrate).push(nodeId);
67
+ }
68
+ const stubs = [];
69
+ // Load stubs for nexus targets (most common cross-substrate case)
70
+ const nexusStubs = stubsBySubstrate.get('nexus');
71
+ if (nexusStubs && nexusStubs.length > 0) {
72
+ const db = getNexusDb();
73
+ if (db) {
74
+ try {
75
+ const rawNexusIds = nexusStubs.map((id) => id.replace(/^nexus:/, ''));
76
+ const placeholders = rawNexusIds.map(() => '?').join(',');
77
+ // Query minimal node data: id, kind, name
78
+ const stubRows = allTyped(db.prepare(`SELECT id, kind, name
79
+ FROM nexus_nodes
80
+ WHERE id IN (${placeholders})`), ...rawNexusIds);
81
+ for (const row of stubRows) {
82
+ const kind = row.kind === 'file' || row.kind === 'folder' || row.kind === 'module'
83
+ ? 'file'
84
+ : 'symbol';
85
+ stubs.push({
86
+ id: `nexus:${row.id}`,
87
+ kind,
88
+ substrate: 'nexus',
89
+ label: row.name,
90
+ weight: undefined,
91
+ createdAt: null,
92
+ meta: { nexus_kind: row.kind, isStub: true },
93
+ });
94
+ }
95
+ }
96
+ catch {
97
+ // Silently continue on error; stubs are supplemental
98
+ }
99
+ }
100
+ }
101
+ // For other substrates (tasks, brain, conduit, signaldock), create minimal stubs
102
+ // without DB queries — they are rare as cross-substrate edge targets.
103
+ for (const [substrate, nodeIds] of stubsBySubstrate) {
104
+ if (substrate === 'nexus')
105
+ continue; // already handled above
106
+ for (const nodeId of nodeIds) {
107
+ const rawId = nodeId.replace(new RegExp(`^${substrate}:`), '');
108
+ stubs.push({
109
+ id: nodeId,
110
+ kind: 'observation', // generic fallback kind
111
+ substrate,
112
+ label: rawId,
113
+ weight: undefined,
114
+ createdAt: null,
115
+ meta: { isStub: true },
116
+ });
117
+ }
118
+ }
119
+ return stubs;
120
+ }
121
+ /**
122
+ * Queries all five substrates and merges the results into a unified BrainGraph.
123
+ *
124
+ * When `options.substrates` is provided, only those substrates are queried.
125
+ * Node IDs are substrate-prefixed, so deduplication is safe to perform
126
+ * by ID equality alone.
127
+ *
128
+ * After all substrates are loaded, performs a second-pass stub-node load:
129
+ * any edge target ID not yet in the loaded node set is fetched as a minimal
130
+ * stub (id, substrate, kind, label). This recovers cross-substrate edges
131
+ * that would otherwise be silently dropped.
132
+ *
133
+ * Stub nodes carry `meta.isStub: true` for optional UI differentiation.
134
+ *
135
+ * @param options - Query options forwarded to each substrate adapter.
136
+ * @returns Merged BrainGraph across all requested substrates, with stub nodes for unresolved edge targets.
137
+ */
138
+ export function getAllSubstrates(options = {}) {
139
+ const substrates = options.substrates ?? ALL_SUBSTRATES;
140
+ const limit = options.limit ?? 500;
141
+ const allNodes = [];
142
+ const allEdges = [];
143
+ const nodeCounts = Object.fromEntries(ALL_SUBSTRATES.map((s) => [s, 0]));
144
+ const edgeCounts = Object.fromEntries([...ALL_SUBSTRATES, 'cross'].map((s) => [s, 0]));
145
+ for (const substrate of substrates) {
146
+ const adapter = ADAPTER_MAP[substrate];
147
+ if (!adapter)
148
+ continue;
149
+ const { nodes, edges } = adapter({ ...options, limit });
150
+ allNodes.push(...nodes);
151
+ allEdges.push(...edges);
152
+ nodeCounts[substrate] = nodes.length;
153
+ for (const edge of edges) {
154
+ edgeCounts[edge.substrate] = (edgeCounts[edge.substrate] ?? 0) + 1;
155
+ }
156
+ }
157
+ // Deduplicate nodes by ID (substrate-prefix guarantees uniqueness across
158
+ // substrates; duplicates can only occur within a substrate on malformed data)
159
+ const seenIds = new Set();
160
+ const uniqueNodes = [];
161
+ for (const node of allNodes) {
162
+ if (!seenIds.has(node.id)) {
163
+ seenIds.add(node.id);
164
+ uniqueNodes.push(node);
165
+ }
166
+ }
167
+ // Second pass: load stub nodes for any edge target IDs not yet loaded.
168
+ // This recovers cross-substrate edges that would otherwise be silently dropped
169
+ // (e.g. brain→nexus bridges to low-in-degree symbols).
170
+ //
171
+ // When a substrates filter is explicitly provided, only add stubs for substrates
172
+ // within the requested set — never inject nodes from excluded substrates, as that
173
+ // would violate the caller's filter contract.
174
+ const requestedSubstrateSet = options.substrates ? new Set(options.substrates) : null;
175
+ const stubNodes = loadStubNodesForEdgeTargets(seenIds, allEdges);
176
+ for (const stubNode of stubNodes) {
177
+ if (!seenIds.has(stubNode.id)) {
178
+ // Skip stubs from substrates not in the requested set
179
+ if (requestedSubstrateSet && !requestedSubstrateSet.has(stubNode.substrate)) {
180
+ continue;
181
+ }
182
+ seenIds.add(stubNode.id);
183
+ uniqueNodes.push(stubNode);
184
+ }
185
+ }
186
+ const truncated = uniqueNodes.length >= limit;
187
+ return {
188
+ nodes: truncated ? uniqueNodes.slice(0, limit) : uniqueNodes,
189
+ edges: allEdges,
190
+ counts: { nodes: nodeCounts, edges: edgeCounts },
191
+ truncated,
192
+ };
193
+ }
194
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAQ5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,6CAA6C;AAC7C,MAAM,cAAc,GAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SA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IAC/E,uDAAuD;IACvD,EAAE;IACF,iFAAiF;IACjF,kFAAkF;IAClF,8CAA8C;IAC9C,MAAM,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,GAAG,CAAS,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC9F,MAAM,SAAS,GAAG,2BAA2B,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACjE,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YAC9B,sDAAsD;YACtD,IAAI,qBAAqB,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5E,SAAS;YACX,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YACzB,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,IAAI,KAAK,CAAC;IAE9C,OAAO;QACL,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW;QAC5D,KAAK,EAAE,QAAQ;QACf,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE;QAChD,SAAS;KACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * NEXUS substrate adapter for the Living Brain API.
3
+ *
4
+ * Queries nexus.db (global) and returns BrainNodes/BrainEdges for code symbols and files.
5
+ * Prioritises high-in-degree nodes (most-called functions, most-imported files)
6
+ * since the full nexus graph can exceed 10k nodes.
7
+ *
8
+ * Node IDs are prefixed with "nexus:" to prevent collisions.
9
+ */
10
+ import type { BrainEdge, BrainNode, BrainQueryOptions } from '../types.js';
11
+ /**
12
+ * Returns all BrainNodes and BrainEdges sourced from nexus.db.
13
+ *
14
+ * Fetches the highest in-degree nodes (capped at perSubstrateLimit) and
15
+ * all relations between those nodes.
16
+ *
17
+ * @param options - Query options (limit, minWeight).
18
+ * @returns Nodes and edges from the NEXUS substrate.
19
+ */
20
+ export declare function getNexusSubstrate(options?: BrainQueryOptions): {
21
+ nodes: BrainNode[];
22
+ edges: BrainEdge[];
23
+ };
24
+ //# sourceMappingURL=nexus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nexus.d.ts","sourceRoot":"","sources":["../../../src/adapters/nexus.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAiB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAyB1F;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,iBAAsB,GAAG;IAClE,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,KAAK,EAAE,SAAS,EAAE,CAAC;CACpB,CAyEA"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * NEXUS substrate adapter for the Living Brain API.
3
+ *
4
+ * Queries nexus.db (global) and returns BrainNodes/BrainEdges for code symbols and files.
5
+ * Prioritises high-in-degree nodes (most-called functions, most-imported files)
6
+ * since the full nexus graph can exceed 10k nodes.
7
+ *
8
+ * Node IDs are prefixed with "nexus:" to prevent collisions.
9
+ */
10
+ import { allTyped, getNexusDb } from '../db-connections.js';
11
+ /** Maps nexus node kinds to BrainNodeKind. */
12
+ function mapKind(nexusKind) {
13
+ if (nexusKind === 'file' || nexusKind === 'folder' || nexusKind === 'module')
14
+ return 'file';
15
+ return 'symbol';
16
+ }
17
+ /**
18
+ * Returns all BrainNodes and BrainEdges sourced from nexus.db.
19
+ *
20
+ * Fetches the highest in-degree nodes (capped at perSubstrateLimit) and
21
+ * all relations between those nodes.
22
+ *
23
+ * @param options - Query options (limit, minWeight).
24
+ * @returns Nodes and edges from the NEXUS substrate.
25
+ */
26
+ export function getNexusSubstrate(options = {}) {
27
+ const db = getNexusDb();
28
+ if (!db)
29
+ return { nodes: [], edges: [] };
30
+ const perSubstrateLimit = Math.ceil((options.limit ?? 500) / 5);
31
+ const nodes = [];
32
+ const edges = [];
33
+ try {
34
+ // Count in-degree for each node to use as weight
35
+ const nodeRows = allTyped(db.prepare(`SELECT n.id, n.kind, n.name, n.indexed_at,
36
+ COUNT(r.target_id) AS in_degree
37
+ FROM nexus_nodes n
38
+ LEFT JOIN nexus_relations r ON r.target_id = n.id
39
+ WHERE n.kind IN (
40
+ 'file', 'function', 'method', 'class', 'interface',
41
+ 'type_alias', 'constant', 'module', 'enum'
42
+ )
43
+ GROUP BY n.id
44
+ ORDER BY in_degree DESC
45
+ LIMIT ?`), perSubstrateLimit);
46
+ for (const row of nodeRows) {
47
+ nodes.push({
48
+ id: `nexus:${row.id}`,
49
+ kind: mapKind(row.kind),
50
+ substrate: 'nexus',
51
+ label: row.name,
52
+ weight: row.in_degree > 0 ? Math.min(1, row.in_degree / 50) : undefined,
53
+ createdAt: row.indexed_at ?? null,
54
+ meta: { nexus_kind: row.kind, in_degree: row.in_degree },
55
+ });
56
+ }
57
+ // Edges between loaded nodes only
58
+ const nodeIds = new Set(nodes.map((n) => n.id));
59
+ const rawIds = new Set([...nodeIds].map((id) => id.replace(/^nexus:/, '')));
60
+ // Fetch all relations touching these nodes (both directions)
61
+ const placeholders = [...rawIds].map(() => '?').join(',');
62
+ if (rawIds.size === 0)
63
+ return { nodes, edges };
64
+ const relRows = allTyped(db.prepare(`SELECT source_id, target_id, type, confidence
65
+ FROM nexus_relations
66
+ WHERE source_id IN (${placeholders})
67
+ AND target_id IN (${placeholders})`), ...rawIds, ...rawIds);
68
+ for (const row of relRows) {
69
+ edges.push({
70
+ source: `nexus:${row.source_id}`,
71
+ target: `nexus:${row.target_id}`,
72
+ type: row.type,
73
+ weight: row.confidence ?? 0.5,
74
+ substrate: 'nexus',
75
+ });
76
+ }
77
+ }
78
+ catch {
79
+ // Return partial results on error
80
+ }
81
+ return { nodes, edges };
82
+ }
83
+ //# sourceMappingURL=nexus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nexus.js","sourceRoot":"","sources":["../../../src/adapters/nexus.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAoB5D,8CAA8C;AAC9C,SAAS,OAAO,CAAC,SAAiB;IAChC,IAAI,SAAS,KAAK,MAAM,IAAI,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAC5F,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAA6B,EAAE;IAI/D,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;IACxB,IAAI,CAAC,EAAE;QAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IAEzC,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAEhE,MAAM,KAAK,GAAgB,EAAE,CAAC;IAC9B,MAAM,KAAK,GAAgB,EAAE,CAAC;IAE9B,IAAI,CAAC;QACH,iDAAiD;QACjD,MAAM,QAAQ,GAAG,QAAQ,CACvB,EAAE,CAAC,OAAO,CACR;;;;;;;;;;iBAUS,CACV,EACD,iBAAiB,CAClB,CAAC;QAEF,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YAC3B,KAAK,CAAC,IAAI,CAAC;gBACT,EAAE,EAAE,SAAS,GAAG,CAAC,EAAE,EAAE;gBACrB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC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AAG,CAAC,SAAS,EAAE;gBAChC,MAAM,EAAE,SAAS,GAAG,CAAC,SAAS,EAAE;gBAChC,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,MAAM,EAAE,GAAG,CAAC,UAAU,IAAI,GAAG;gBAC7B,SAAS,EAAE,OAAO;aACnB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,kCAAkC;IACpC,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * TASKS substrate adapter for the Living Brain API.
3
+ *
4
+ * Queries tasks.db and returns BrainNodes/BrainEdges for tasks and sessions.
5
+ * Prioritises critical/high priority tasks and active sessions.
6
+ *
7
+ * Node IDs are prefixed with "tasks:" to prevent collisions.
8
+ */
9
+ import type { BrainEdge, BrainNode, BrainQueryOptions } from '../types.js';
10
+ /**
11
+ * Returns all BrainNodes and BrainEdges sourced from tasks.db.
12
+ *
13
+ * Fetches tasks ordered by priority, plus recent sessions.
14
+ * Synthesizes parent→child, dependency, and relation edges.
15
+ *
16
+ * @param options - Query options (limit, minWeight).
17
+ * @returns Nodes and edges from the TASKS substrate.
18
+ */
19
+ export declare function getTasksSubstrate(options?: BrainQueryOptions): {
20
+ nodes: BrainNode[];
21
+ edges: BrainEdge[];
22
+ };
23
+ //# sourceMappingURL=tasks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../../../src/adapters/tasks.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA6C3E;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,iBAAsB,GAAG;IAClE,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,KAAK,EAAE,SAAS,EAAE,CAAC;CACpB,CA+IA"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * TASKS substrate adapter for the Living Brain API.
3
+ *
4
+ * Queries tasks.db and returns BrainNodes/BrainEdges for tasks and sessions.
5
+ * Prioritises critical/high priority tasks and active sessions.
6
+ *
7
+ * Node IDs are prefixed with "tasks:" to prevent collisions.
8
+ */
9
+ import { allTyped, getTasksDb } from '../db-connections.js';
10
+ import { resolveDefaultProjectContext } from '../project-context.js';
11
+ /** Maps priority string to numeric weight for BrainNode.weight. */
12
+ function priorityWeight(priority) {
13
+ const map = {
14
+ critical: 1.0,
15
+ high: 0.75,
16
+ medium: 0.5,
17
+ low: 0.25,
18
+ };
19
+ return map[priority] ?? 0.25;
20
+ }
21
+ /**
22
+ * Returns all BrainNodes and BrainEdges sourced from tasks.db.
23
+ *
24
+ * Fetches tasks ordered by priority, plus recent sessions.
25
+ * Synthesizes parent→child, dependency, and relation edges.
26
+ *
27
+ * @param options - Query options (limit, minWeight).
28
+ * @returns Nodes and edges from the TASKS substrate.
29
+ */
30
+ export function getTasksSubstrate(options = {}) {
31
+ const ctx = options.projectCtx ?? resolveDefaultProjectContext();
32
+ const db = getTasksDb(ctx);
33
+ if (!db)
34
+ return { nodes: [], edges: [] };
35
+ const perSubstrateLimit = Math.ceil((options.limit ?? 500) / 5);
36
+ const minWeight = options.minWeight ?? 0;
37
+ const nodes = [];
38
+ const edges = [];
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
42
+ FROM tasks
43
+ WHERE status NOT IN ('archived', 'cancelled')
44
+ ORDER BY
45
+ CASE priority
46
+ WHEN 'critical' THEN 0 WHEN 'high' THEN 1 WHEN 'medium' THEN 2 ELSE 3
47
+ END,
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
74
+ FROM sessions
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',
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,
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_task_id, relation_type
110
+ FROM task_relations
111
+ WHERE task_id IN (${placeholders})
112
+ AND related_task_id IN (${placeholders})`), ...taskIds, ...taskIds);
113
+ for (const row of relRows) {
114
+ edges.push({
115
+ source: `tasks:${row.task_id}`,
116
+ target: `tasks:${row.related_task_id}`,
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_task_id
124
+ FROM task_dependencies
125
+ WHERE task_id IN (${placeholders})
126
+ AND depends_on_task_id 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_task_id}`,
131
+ type: 'depends_on',
132
+ weight: 0.85,
133
+ substrate: 'tasks',
134
+ });
135
+ }
136
+ }
137
+ }
138
+ catch {
139
+ // Return partial results on error
140
+ }
141
+ return { nodes, edges };
142
+ }
143
+ //# sourceMappingURL=tasks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../../src/adapters/tasks.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC5D,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,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,CAAC,EAAE;QAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IAEzC,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,OA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C,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC3D,MAAM,OAAO,GAAG,QAAQ,CACtB,EAAE,CAAC,OAAO,CACR;;+BAEqB,YAAY;uCACJ,YAAY,GAAG,CAC7C,EACD,GAAG,OAAO,EACV,GAAG,OAAO,CACX,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,eAAe,EAAE;oBACtC,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,CACtB,EAAE,CAAC,OAAO,CACR;;+BAEqB,YAAY;0CACD,YAAY,GAAG,CAChD,EACD,GAAG,OAAO,EACV,GAAG,OAAO,CACX,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,kBAAkB,EAAE;oBACzC,IAAI,EAAE,YAAY;oBAClB,MAAM,EAAE,IAAI;oBACZ,SAAS,EAAE,OAAO;iBACnB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,kCAAkC;IACpC,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * CLEO home + project DB path resolution for `@cleocode/brain`.
3
+ *
4
+ * Path resolution delegates to the `@cleocode/paths` SSoT
5
+ * ({@link getCleoHome}). Project data (tasks.db, brain.db, conduit.db) is
6
+ * resolved via projectId → nexus.db registry lookup
7
+ * ({@link resolveProjectByCwd} + {@link resolveCanonicalCleoDir}), with a
8
+ * `CLEO_ROOT` / `process.cwd()` fallback for non-project contexts.
9
+ *
10
+ * Previously this module imported `env-paths` directly which caused a Windows
11
+ * path mismatch with the rest of the CLEO ecosystem (the CLI used env-paths
12
+ * returning `%LOCALAPPDATA%\cleo\Data` while brain used a bare
13
+ * `%LOCALAPPDATA%\cleo`, looking up `nexus.db` one directory shallower than
14
+ * where it was written). Fixed in T1874 (Closes #102, supersedes #103).
15
+ *
16
+ * @task T1874 (original Windows fix)
17
+ * @task T1886 (migrated to @cleocode/paths SSoT)
18
+ * @task T11040 (verified 2026-05-27: projectId-based resolution confirmed; 72/72 tests pass)
19
+ */
20
+ import { getCleoHome } from '@cleocode/paths';
21
+ export { getCleoHome };
22
+ /**
23
+ * Returns the project's `.cleo/` directory.
24
+ *
25
+ * Resolution order:
26
+ * 1. {@link resolveProjectByCwd} — reads `.cleo/project-info.json` for a stable
27
+ * `projectId`, then resolves the canonical `.cleo/` path via
28
+ * {@link resolveCanonicalCleoDir} (nexus.db registry lookup).
29
+ * 2. Fallback: `CLEO_ROOT` env var or `process.cwd()` + `'.cleo'` for
30
+ * non-project contexts (e.g., before `cleo init`).
31
+ *
32
+ * @task T11040 — migrate from CWD-walk-up to projectId-based resolution
33
+ */
34
+ export declare function getCleoProjectDir(): string;
35
+ /** Returns the absolute path to the global nexus.db file. */
36
+ export declare function getNexusDbPath(): string;
37
+ /** Returns the absolute path to the project-scoped brain.db file. */
38
+ export declare function getBrainDbPath(): string;
39
+ /** Returns the absolute path to the project-scoped tasks.db file. */
40
+ export declare function getTasksDbPath(): string;
41
+ /** Returns the absolute path to the project-scoped conduit.db file. */
42
+ export declare function getConduitDbPath(): string;
43
+ /** Returns the absolute path to the global signaldock.db file. */
44
+ export declare function getAgentRegistryDbPath(): string;
45
+ /** Returns true when the given DB file exists on disk. */
46
+ export declare function dbExists(dbPath: string): boolean;
47
+ //# sourceMappingURL=cleo-home.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleo-home.d.ts","sourceRoot":"","sources":["../../src/cleo-home.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,WAAW,EAAgD,MAAM,iBAAiB,CAAC;AAE5F,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAW1C;AAED,6DAA6D;AAC7D,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,qEAAqE;AACrE,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,qEAAqE;AACrE,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,uEAAuE;AACvE,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,kEAAkE;AAClE,wBAAgB,sBAAsB,IAAI,MAAM,CAE/C;AAED,0DAA0D;AAC1D,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhD"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * CLEO home + project DB path resolution for `@cleocode/brain`.
3
+ *
4
+ * Path resolution delegates to the `@cleocode/paths` SSoT
5
+ * ({@link getCleoHome}). Project data (tasks.db, brain.db, conduit.db) is
6
+ * resolved via projectId → nexus.db registry lookup
7
+ * ({@link resolveProjectByCwd} + {@link resolveCanonicalCleoDir}), with a
8
+ * `CLEO_ROOT` / `process.cwd()` fallback for non-project contexts.
9
+ *
10
+ * Previously this module imported `env-paths` directly which caused a Windows
11
+ * path mismatch with the rest of the CLEO ecosystem (the CLI used env-paths
12
+ * returning `%LOCALAPPDATA%\cleo\Data` while brain used a bare
13
+ * `%LOCALAPPDATA%\cleo`, looking up `nexus.db` one directory shallower than
14
+ * where it was written). Fixed in T1874 (Closes #102, supersedes #103).
15
+ *
16
+ * @task T1874 (original Windows fix)
17
+ * @task T1886 (migrated to @cleocode/paths SSoT)
18
+ * @task T11040 (verified 2026-05-27: projectId-based resolution confirmed; 72/72 tests pass)
19
+ */
20
+ import { existsSync } from 'node:fs';
21
+ import { join } from 'node:path';
22
+ import { getCleoHome, resolveCanonicalCleoDir, resolveProjectByCwd } from '@cleocode/paths';
23
+ export { getCleoHome };
24
+ /**
25
+ * Returns the project's `.cleo/` directory.
26
+ *
27
+ * Resolution order:
28
+ * 1. {@link resolveProjectByCwd} — reads `.cleo/project-info.json` for a stable
29
+ * `projectId`, then resolves the canonical `.cleo/` path via
30
+ * {@link resolveCanonicalCleoDir} (nexus.db registry lookup).
31
+ * 2. Fallback: `CLEO_ROOT` env var or `process.cwd()` + `'.cleo'` for
32
+ * non-project contexts (e.g., before `cleo init`).
33
+ *
34
+ * @task T11040 — migrate from CWD-walk-up to projectId-based resolution
35
+ */
36
+ export function getCleoProjectDir() {
37
+ const project = resolveProjectByCwd();
38
+ if (project !== null) {
39
+ const canonical = resolveCanonicalCleoDir(project.projectId);
40
+ if (canonical !== null)
41
+ return canonical;
42
+ // Project found but not in nexus registry yet — use projectRoot fallback.
43
+ return join(project.projectRoot, '.cleo');
44
+ }
45
+ // Fallback for non-project contexts (pre-init, CLEO_ROOT override).
46
+ const root = process.env['CLEO_ROOT'] ?? process.cwd();
47
+ return join(root, '.cleo');
48
+ }
49
+ /** Returns the absolute path to the global nexus.db file. */
50
+ export function getNexusDbPath() {
51
+ return join(getCleoHome(), 'nexus.db');
52
+ }
53
+ /** Returns the absolute path to the project-scoped brain.db file. */
54
+ export function getBrainDbPath() {
55
+ return join(getCleoProjectDir(), 'brain.db');
56
+ }
57
+ /** Returns the absolute path to the project-scoped tasks.db file. */
58
+ export function getTasksDbPath() {
59
+ return join(getCleoProjectDir(), 'tasks.db');
60
+ }
61
+ /** Returns the absolute path to the project-scoped conduit.db file. */
62
+ export function getConduitDbPath() {
63
+ return join(getCleoProjectDir(), 'conduit.db');
64
+ }
65
+ /** Returns the absolute path to the global signaldock.db file. */
66
+ export function getAgentRegistryDbPath() {
67
+ return join(getCleoHome(), 'signaldock.db');
68
+ }
69
+ /** Returns true when the given DB file exists on disk. */
70
+ export function dbExists(dbPath) {
71
+ return existsSync(dbPath);
72
+ }
73
+ //# sourceMappingURL=cleo-home.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleo-home.js","sourceRoot":"","sources":["../../src/cleo-home.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE5F,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,OAAO,GAAG,mBAAmB,EAAE,CAAC;IACtC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,MAAM,SAAS,GAAG,uBAAuB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,SAAS,KAAK,IAAI;YAAE,OAAO,SAAS,CAAC;QACzC,0EAA0E;QAC1E,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IACD,oEAAoE;IACpE,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACvD,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC7B,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,CAAC,iBAAiB,EA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