@cleocode/cleo 2026.4.38 → 2026.4.40

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.
package/dist/cli/index.js CHANGED
@@ -45821,6 +45821,390 @@ var init_brain_consolidator = __esm({
45821
45821
  }
45822
45822
  });
45823
45823
 
45824
+ // packages/core/src/memory/graph-memory-bridge.ts
45825
+ var graph_memory_bridge_exports = {};
45826
+ __export(graph_memory_bridge_exports, {
45827
+ autoLinkMemories: () => autoLinkMemories,
45828
+ linkMemoryToCode: () => linkMemoryToCode,
45829
+ listCodeLinks: () => listCodeLinks,
45830
+ queryCodeForMemory: () => queryCodeForMemory,
45831
+ queryMemoriesForCode: () => queryMemoriesForCode
45832
+ });
45833
+ function extractFilePaths(text3) {
45834
+ const paths = /* @__PURE__ */ new Set();
45835
+ for (const m2 of text3.matchAll(FILE_PATH_PATTERN)) {
45836
+ const p2 = m2[1];
45837
+ if (p2) paths.add(p2);
45838
+ }
45839
+ return Array.from(paths);
45840
+ }
45841
+ function extractSymbolCandidates(text3) {
45842
+ const syms = /* @__PURE__ */ new Set();
45843
+ for (const m2 of text3.matchAll(SYMBOL_PATTERN)) {
45844
+ const s3 = m2[1];
45845
+ if (s3 && s3.length >= 4 && !SYMBOL_STOP_WORDS.has(s3.toLowerCase())) {
45846
+ syms.add(s3);
45847
+ }
45848
+ }
45849
+ return Array.from(syms);
45850
+ }
45851
+ function metadataText(metaJson) {
45852
+ if (!metaJson) return "";
45853
+ try {
45854
+ const obj = JSON.parse(metaJson);
45855
+ return Object.values(obj).filter((v2) => typeof v2 === "string").join(" ");
45856
+ } catch {
45857
+ return "";
45858
+ }
45859
+ }
45860
+ async function linkMemoryToCode(projectRoot, memoryId, codeSymbol) {
45861
+ try {
45862
+ const brainDb = await getBrainDb(projectRoot);
45863
+ await getNexusDb();
45864
+ const nexusNative = getNexusNativeDb();
45865
+ if (!nexusNative) return false;
45866
+ const nexusNode = nexusNative.prepare("SELECT id, label, file_path, kind FROM nexus_nodes WHERE id = ? LIMIT 1").get(codeSymbol);
45867
+ if (!nexusNode) return false;
45868
+ const now2 = (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19);
45869
+ const idParts = memoryId.split(":");
45870
+ const nodeType = idParts[0] ?? "observation";
45871
+ await brainDb.insert(brainPageNodes).values({
45872
+ id: memoryId,
45873
+ nodeType,
45874
+ label: memoryId,
45875
+ qualityScore: 0.5,
45876
+ contentHash: null,
45877
+ lastActivityAt: now2,
45878
+ createdAt: now2,
45879
+ updatedAt: now2
45880
+ }).onConflictDoUpdate({
45881
+ target: brainPageNodes.id,
45882
+ set: { lastActivityAt: now2, updatedAt: now2 }
45883
+ });
45884
+ await brainDb.insert(brainPageEdges).values({
45885
+ fromId: memoryId,
45886
+ toId: codeSymbol,
45887
+ edgeType: "code_reference",
45888
+ weight: 1,
45889
+ provenance: "manual",
45890
+ createdAt: now2
45891
+ }).onConflictDoNothing();
45892
+ return true;
45893
+ } catch (err) {
45894
+ console.warn("[graph-memory-bridge] linkMemoryToCode failed:", err);
45895
+ return false;
45896
+ }
45897
+ }
45898
+ async function autoLinkMemories(projectRoot) {
45899
+ const result = { scanned: 0, linked: 0, alreadyLinked: 0, links: [] };
45900
+ try {
45901
+ await getBrainDb(projectRoot);
45902
+ const brainNative = getBrainNativeDb();
45903
+ await getNexusDb();
45904
+ const nexusNative = getNexusNativeDb();
45905
+ if (!brainNative || !nexusNative) return result;
45906
+ const brainNodes = typedAll(
45907
+ brainNative.prepare(`
45908
+ SELECT id, node_type, label, quality_score, metadata_json
45909
+ FROM brain_page_nodes
45910
+ WHERE node_type IN ('observation', 'decision', 'pattern', 'learning')
45911
+ AND quality_score >= 0.3
45912
+ ORDER BY quality_score DESC
45913
+ LIMIT 500
45914
+ `)
45915
+ );
45916
+ result.scanned = brainNodes.length;
45917
+ if (brainNodes.length === 0) return result;
45918
+ const nexusNodes2 = typedAll(
45919
+ nexusNative.prepare(`
45920
+ SELECT id, label, name, file_path, kind
45921
+ FROM nexus_nodes
45922
+ WHERE kind NOT IN ('community', 'process', 'folder')
45923
+ LIMIT 20000
45924
+ `)
45925
+ );
45926
+ if (nexusNodes2.length === 0) return result;
45927
+ const byFilePath = /* @__PURE__ */ new Map();
45928
+ const byNameExact = /* @__PURE__ */ new Map();
45929
+ const byNameLower = /* @__PURE__ */ new Map();
45930
+ for (const node of nexusNodes2) {
45931
+ if (node.file_path) {
45932
+ const fp = node.file_path.toLowerCase();
45933
+ const existing = byFilePath.get(fp) ?? [];
45934
+ existing.push(node);
45935
+ byFilePath.set(fp, existing);
45936
+ }
45937
+ if (node.name) {
45938
+ const exact = byNameExact.get(node.name) ?? [];
45939
+ exact.push(node);
45940
+ byNameExact.set(node.name, exact);
45941
+ const lower = node.name.toLowerCase();
45942
+ const fuzzy = byNameLower.get(lower) ?? [];
45943
+ fuzzy.push(node);
45944
+ byNameLower.set(lower, fuzzy);
45945
+ }
45946
+ }
45947
+ const now2 = (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19);
45948
+ const existingEdges = /* @__PURE__ */ new Set();
45949
+ const rawEdges = typedAll(
45950
+ brainNative.prepare(`
45951
+ SELECT from_id, to_id FROM brain_page_edges WHERE edge_type = 'code_reference'
45952
+ `)
45953
+ );
45954
+ for (const e of rawEdges) {
45955
+ existingEdges.add(`${e.from_id}|${e.to_id}`);
45956
+ }
45957
+ for (const brainNode of brainNodes) {
45958
+ const corpus = `${brainNode.label} ${metadataText(brainNode.metadata_json)}`;
45959
+ const filePaths = extractFilePaths(corpus);
45960
+ const symbolCandidates = extractSymbolCandidates(corpus);
45961
+ const candidates = [];
45962
+ for (const fp of filePaths) {
45963
+ const matches = byFilePath.get(fp.toLowerCase());
45964
+ if (matches) {
45965
+ for (const n of matches) {
45966
+ candidates.push({ nexusNode: n, strategy: "exact-file", weight: 1 });
45967
+ }
45968
+ }
45969
+ }
45970
+ for (const sym of symbolCandidates) {
45971
+ const exactMatches = byNameExact.get(sym);
45972
+ if (exactMatches) {
45973
+ for (const n of exactMatches) {
45974
+ candidates.push({ nexusNode: n, strategy: "exact-symbol", weight: 1 });
45975
+ }
45976
+ }
45977
+ }
45978
+ const exactSymSet = new Set(
45979
+ symbolCandidates.flatMap((s3) => byNameExact.get(s3) ?? []).map((n) => n.id)
45980
+ );
45981
+ for (const sym of symbolCandidates) {
45982
+ if (sym.length < 5) continue;
45983
+ const lower = sym.toLowerCase();
45984
+ const fuzzyMatches = byNameLower.get(lower);
45985
+ if (fuzzyMatches) {
45986
+ for (const n of fuzzyMatches) {
45987
+ if (!exactSymSet.has(n.id)) {
45988
+ candidates.push({ nexusNode: n, strategy: "fuzzy-symbol", weight: 0.6 });
45989
+ }
45990
+ }
45991
+ }
45992
+ }
45993
+ const bestByNexusId = /* @__PURE__ */ new Map();
45994
+ for (const c of candidates) {
45995
+ const existing = bestByNexusId.get(c.nexusNode.id);
45996
+ if (!existing || c.weight > existing.weight) {
45997
+ bestByNexusId.set(c.nexusNode.id, c);
45998
+ }
45999
+ }
46000
+ const sortedCandidates = Array.from(bestByNexusId.values()).sort((a, b2) => b2.weight - a.weight).slice(0, 10);
46001
+ for (const { nexusNode, strategy, weight } of sortedCandidates) {
46002
+ const edgeKey = `${brainNode.id}|${nexusNode.id}`;
46003
+ if (existingEdges.has(edgeKey)) {
46004
+ result.alreadyLinked++;
46005
+ continue;
46006
+ }
46007
+ brainNative.prepare(`
46008
+ INSERT OR IGNORE INTO brain_page_nodes
46009
+ (id, node_type, label, quality_score, content_hash, metadata_json, last_activity_at, created_at, updated_at)
46010
+ VALUES (?, ?, ?, ?, NULL, NULL, ?, ?, ?)
46011
+ `).run(
46012
+ brainNode.id,
46013
+ brainNode.node_type,
46014
+ brainNode.label,
46015
+ brainNode.quality_score,
46016
+ now2,
46017
+ now2,
46018
+ now2
46019
+ );
46020
+ try {
46021
+ brainNative.prepare(`
46022
+ INSERT OR IGNORE INTO brain_page_edges
46023
+ (from_id, to_id, edge_type, weight, provenance, created_at)
46024
+ VALUES (?, ?, 'code_reference', ?, ?, ?)
46025
+ `).run(brainNode.id, nexusNode.id, weight, `auto:${strategy}`, now2);
46026
+ existingEdges.add(edgeKey);
46027
+ result.linked++;
46028
+ result.links.push({
46029
+ brainNodeId: brainNode.id,
46030
+ nexusNodeId: nexusNode.id,
46031
+ nexusLabel: nexusNode.label,
46032
+ matchStrategy: strategy,
46033
+ weight
46034
+ });
46035
+ } catch (edgeErr) {
46036
+ console.warn("[graph-memory-bridge] edge insert failed:", edgeErr);
46037
+ }
46038
+ }
46039
+ }
46040
+ } catch (err) {
46041
+ console.warn("[graph-memory-bridge] autoLinkMemories failed:", err);
46042
+ }
46043
+ return result;
46044
+ }
46045
+ async function queryMemoriesForCode(projectRoot, symbol2) {
46046
+ const result = { nexusNodeId: symbol2, memories: [] };
46047
+ try {
46048
+ await getBrainDb(projectRoot);
46049
+ const brainNative = getBrainNativeDb();
46050
+ if (!brainNative) return result;
46051
+ const rows = typedAll(
46052
+ brainNative.prepare(`
46053
+ SELECT n.id, n.node_type, n.label, n.quality_score,
46054
+ e.weight, e.provenance
46055
+ FROM brain_page_edges e
46056
+ JOIN brain_page_nodes n ON n.id = e.from_id
46057
+ WHERE e.to_id = ?
46058
+ AND e.edge_type = 'code_reference'
46059
+ ORDER BY e.weight DESC, n.quality_score DESC
46060
+ LIMIT 50
46061
+ `),
46062
+ symbol2
46063
+ );
46064
+ result.memories = rows.map((r) => ({
46065
+ nodeId: r.id,
46066
+ nodeType: r.node_type,
46067
+ label: r.label,
46068
+ qualityScore: r.quality_score,
46069
+ edgeWeight: r.weight,
46070
+ matchStrategy: r.provenance?.replace("auto:", "") ?? "manual"
46071
+ }));
46072
+ } catch (err) {
46073
+ console.warn("[graph-memory-bridge] queryMemoriesForCode failed:", err);
46074
+ }
46075
+ return result;
46076
+ }
46077
+ async function queryCodeForMemory(projectRoot, memoryId) {
46078
+ const result = { brainNodeId: memoryId, codeNodes: [] };
46079
+ try {
46080
+ await getBrainDb(projectRoot);
46081
+ const brainNative = getBrainNativeDb();
46082
+ await getNexusDb();
46083
+ const nexusNative = getNexusNativeDb();
46084
+ if (!brainNative || !nexusNative) return result;
46085
+ const brainEdges = typedAll(
46086
+ brainNative.prepare(`
46087
+ SELECT to_id, weight, provenance
46088
+ FROM brain_page_edges
46089
+ WHERE from_id = ?
46090
+ AND edge_type = 'code_reference'
46091
+ ORDER BY weight DESC
46092
+ LIMIT 50
46093
+ `),
46094
+ memoryId
46095
+ );
46096
+ if (brainEdges.length === 0) return result;
46097
+ for (const edge of brainEdges) {
46098
+ const nexusNode = nexusNative.prepare("SELECT id, label, file_path, kind FROM nexus_nodes WHERE id = ? LIMIT 1").get(edge.to_id);
46099
+ if (nexusNode) {
46100
+ result.codeNodes.push({
46101
+ nexusNodeId: nexusNode.id,
46102
+ label: nexusNode.label,
46103
+ filePath: nexusNode.file_path,
46104
+ kind: nexusNode.kind,
46105
+ edgeWeight: edge.weight,
46106
+ matchStrategy: edge.provenance?.replace("auto:", "") ?? "manual"
46107
+ });
46108
+ }
46109
+ }
46110
+ } catch (err) {
46111
+ console.warn("[graph-memory-bridge] queryCodeForMemory failed:", err);
46112
+ }
46113
+ return result;
46114
+ }
46115
+ async function listCodeLinks(projectRoot, limit = 100) {
46116
+ const entries = [];
46117
+ try {
46118
+ await getBrainDb(projectRoot);
46119
+ const brainNative = getBrainNativeDb();
46120
+ await getNexusDb();
46121
+ const nexusNative = getNexusNativeDb();
46122
+ if (!brainNative || !nexusNative) return entries;
46123
+ const rows = typedAll(
46124
+ brainNative.prepare(`
46125
+ SELECT e.from_id, e.to_id, e.weight, e.created_at,
46126
+ n.node_type, n.label
46127
+ FROM brain_page_edges e
46128
+ JOIN brain_page_nodes n ON n.id = e.from_id
46129
+ WHERE e.edge_type = 'code_reference'
46130
+ ORDER BY e.weight DESC, e.created_at DESC
46131
+ LIMIT ?
46132
+ `),
46133
+ limit
46134
+ );
46135
+ for (const row of rows) {
46136
+ const nexusNode = nexusNative.prepare("SELECT id, label, file_path, kind FROM nexus_nodes WHERE id = ? LIMIT 1").get(row.to_id);
46137
+ entries.push({
46138
+ brainNodeId: row.from_id,
46139
+ brainNodeType: row.node_type,
46140
+ brainNodeLabel: row.label,
46141
+ nexusNodeId: row.to_id,
46142
+ nexusNodeLabel: nexusNode?.label ?? row.to_id,
46143
+ filePath: nexusNode?.file_path ?? null,
46144
+ kind: nexusNode?.kind ?? "unknown",
46145
+ weight: row.weight,
46146
+ createdAt: row.created_at
46147
+ });
46148
+ }
46149
+ } catch (err) {
46150
+ console.warn("[graph-memory-bridge] listCodeLinks failed:", err);
46151
+ }
46152
+ return entries;
46153
+ }
46154
+ var FILE_PATH_PATTERN, SYMBOL_PATTERN, SYMBOL_STOP_WORDS;
46155
+ var init_graph_memory_bridge = __esm({
46156
+ "packages/core/src/memory/graph-memory-bridge.ts"() {
46157
+ "use strict";
46158
+ init_brain_schema();
46159
+ init_brain_sqlite();
46160
+ init_nexus_sqlite();
46161
+ init_typed_query();
46162
+ FILE_PATH_PATTERN = /(?:^|\s|['"`(])([a-zA-Z0-9_\-./]+\.(?:ts|tsx|js|jsx|rs|go|py|mjs|cjs))(?:$|\s|['"`)])/g;
46163
+ SYMBOL_PATTERN = /\b([a-zA-Z_][a-zA-Z0-9_]*(?:[A-Z][a-zA-Z0-9_]*)+|[a-zA-Z_]{4,}[a-zA-Z0-9_]*)\b/g;
46164
+ SYMBOL_STOP_WORDS = /* @__PURE__ */ new Set([
46165
+ "true",
46166
+ "false",
46167
+ "null",
46168
+ "undefined",
46169
+ "const",
46170
+ "async",
46171
+ "await",
46172
+ "return",
46173
+ "export",
46174
+ "import",
46175
+ "from",
46176
+ "type",
46177
+ "interface",
46178
+ "function",
46179
+ "class",
46180
+ "this",
46181
+ "super",
46182
+ "extends",
46183
+ "implements",
46184
+ "with",
46185
+ "that",
46186
+ "then",
46187
+ "when",
46188
+ "have",
46189
+ "been",
46190
+ "will",
46191
+ "should",
46192
+ "could",
46193
+ "would",
46194
+ "error",
46195
+ "result",
46196
+ "value",
46197
+ "data",
46198
+ "info",
46199
+ "note",
46200
+ "todo",
46201
+ "done",
46202
+ "fail",
46203
+ "pass"
46204
+ ]);
46205
+ }
46206
+ });
46207
+
45824
46208
  // packages/core/src/memory/brain-lifecycle.ts
45825
46209
  var brain_lifecycle_exports = {};
45826
46210
  __export(brain_lifecycle_exports, {
@@ -46120,6 +46504,13 @@ async function runConsolidation(projectRoot) {
46120
46504
  } catch (err) {
46121
46505
  console.warn("[consolidation] Step 7 summary generation failed:", err);
46122
46506
  }
46507
+ try {
46508
+ const { autoLinkMemories: autoLinkMemories2 } = await Promise.resolve().then(() => (init_graph_memory_bridge(), graph_memory_bridge_exports));
46509
+ const bridgeResult = await autoLinkMemories2(projectRoot);
46510
+ result.graphLinksCreated = bridgeResult.linked;
46511
+ } catch (err) {
46512
+ console.warn("[consolidation] Step 8 graph memory bridge failed:", err);
46513
+ }
46123
46514
  return result;
46124
46515
  }
46125
46516
  async function deduplicateByEmbedding(projectRoot) {
@@ -65809,6 +66200,19 @@ async function completeTask(options, cwd, accessor) {
65809
66200
  })()
65810
66201
  ).catch(() => {
65811
66202
  });
66203
+ try {
66204
+ const { hooks: hooks2 } = await Promise.resolve().then(() => (init_registry(), registry_exports));
66205
+ await hooks2.dispatch("PostToolUse", cwd ?? process.cwd(), {
66206
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
66207
+ taskId: options.taskId,
66208
+ taskTitle: task.title,
66209
+ previousStatus: before.status,
66210
+ newStatus: "done",
66211
+ unblockedCount: unblockedTasks.length
66212
+ }).catch(() => {
66213
+ });
66214
+ } catch {
66215
+ }
65812
66216
  return {
65813
66217
  task,
65814
66218
  ...autoCompleted.length > 0 && { autoCompleted },
@@ -85212,6 +85616,7 @@ var init_error_registry = __esm({
85212
85616
  // packages/core/src/init.ts
85213
85617
  var init_exports = {};
85214
85618
  __export(init_exports, {
85619
+ deployStarterBundle: () => deployStarterBundle,
85215
85620
  ensureInitialized: () => ensureInitialized,
85216
85621
  getVersion: () => getVersion2,
85217
85622
  initAgentDefinition: () => initAgentDefinition,
@@ -85697,53 +86102,7 @@ async function initProject(opts = {}) {
85697
86102
  );
85698
86103
  }
85699
86104
  try {
85700
- const cantDir = join106(cleoDir, "cant");
85701
- const cantAgentsDir = join106(cantDir, "agents");
85702
- const hasCantFiles = existsSync107(cantDir) && readdirSync36(cantDir, { recursive: true }).some(
85703
- (f2) => typeof f2 === "string" && f2.endsWith(".cant")
85704
- );
85705
- if (!hasCantFiles) {
85706
- let starterBundleSrc = null;
85707
- try {
85708
- const { createRequire: createRequire19 } = await import("node:module");
85709
- const req = createRequire19(import.meta.url);
85710
- const cleoOsPkgMain = req.resolve("@cleocode/cleo-os/package.json");
85711
- const cleoOsPkgRoot = dirname22(cleoOsPkgMain);
85712
- const candidate = join106(cleoOsPkgRoot, "starter-bundle");
85713
- if (existsSync107(candidate)) {
85714
- starterBundleSrc = candidate;
85715
- }
85716
- } catch {
85717
- }
85718
- if (!starterBundleSrc) {
85719
- const packageRoot = getPackageRoot();
85720
- const fallbacks = [
85721
- join106(packageRoot, "..", "cleo-os", "starter-bundle"),
85722
- join106(packageRoot, "..", "..", "packages", "cleo-os", "starter-bundle")
85723
- ];
85724
- starterBundleSrc = fallbacks.find((p2) => existsSync107(p2)) ?? null;
85725
- }
85726
- if (starterBundleSrc) {
85727
- await mkdir16(cantDir, { recursive: true });
85728
- await mkdir16(cantAgentsDir, { recursive: true });
85729
- const teamSrc = join106(starterBundleSrc, "team.cant");
85730
- const teamDst = join106(cantDir, "team.cant");
85731
- if (existsSync107(teamSrc) && !existsSync107(teamDst)) {
85732
- await copyFile4(teamSrc, teamDst);
85733
- }
85734
- const agentsSrc = join106(starterBundleSrc, "agents");
85735
- if (existsSync107(agentsSrc)) {
85736
- const agentFiles = readdirSync36(agentsSrc).filter((f2) => f2.endsWith(".cant"));
85737
- for (const agentFile of agentFiles) {
85738
- const dst = join106(cantAgentsDir, agentFile);
85739
- if (!existsSync107(dst)) {
85740
- await copyFile4(join106(agentsSrc, agentFile), dst);
85741
- }
85742
- }
85743
- }
85744
- created.push("starter-bundle: team + agent .cant files deployed to .cleo/cant/");
85745
- }
85746
- }
86105
+ await deployStarterBundle(cleoDir, created, warnings);
85747
86106
  } catch (err) {
85748
86107
  warnings.push(`Starter bundle deploy: ${err instanceof Error ? err.message : String(err)}`);
85749
86108
  }
@@ -85871,6 +86230,58 @@ async function getVersion2(projectRoot) {
85871
86230
  }
85872
86231
  return { version: "0.0.0" };
85873
86232
  }
86233
+ async function deployStarterBundle(cleoDir, created, warnings) {
86234
+ const cantDir = join106(cleoDir, "cant");
86235
+ const cantAgentsDir = join106(cantDir, "agents");
86236
+ const hasCantFiles = existsSync107(cantDir) && readdirSync36(cantDir, { recursive: true }).some(
86237
+ (f2) => typeof f2 === "string" && f2.endsWith(".cant")
86238
+ );
86239
+ if (hasCantFiles) return;
86240
+ let starterBundleSrc = null;
86241
+ try {
86242
+ const { createRequire: createRequire19 } = await import("node:module");
86243
+ const req = createRequire19(import.meta.url);
86244
+ const cleoOsPkgMain = req.resolve("@cleocode/cleo-os/package.json");
86245
+ const cleoOsPkgRoot = dirname22(cleoOsPkgMain);
86246
+ const candidate = join106(cleoOsPkgRoot, "starter-bundle");
86247
+ if (existsSync107(candidate)) {
86248
+ starterBundleSrc = candidate;
86249
+ }
86250
+ } catch {
86251
+ }
86252
+ if (!starterBundleSrc) {
86253
+ const packageRoot = getPackageRoot();
86254
+ const fallbacks = [
86255
+ join106(packageRoot, "..", "cleo-os", "starter-bundle"),
86256
+ join106(packageRoot, "..", "..", "packages", "cleo-os", "starter-bundle")
86257
+ ];
86258
+ starterBundleSrc = fallbacks.find((p2) => existsSync107(p2)) ?? null;
86259
+ }
86260
+ if (!starterBundleSrc) {
86261
+ warnings.push(
86262
+ "Starter bundle not found \u2014 .cleo/cant/ will remain empty. Run cleo init in a project with @cleocode/cleo-os installed."
86263
+ );
86264
+ return;
86265
+ }
86266
+ await mkdir16(cantDir, { recursive: true });
86267
+ await mkdir16(cantAgentsDir, { recursive: true });
86268
+ const teamSrc = join106(starterBundleSrc, "team.cant");
86269
+ const teamDst = join106(cantDir, "team.cant");
86270
+ if (existsSync107(teamSrc) && !existsSync107(teamDst)) {
86271
+ await copyFile4(teamSrc, teamDst);
86272
+ }
86273
+ const agentsSrc = join106(starterBundleSrc, "agents");
86274
+ if (existsSync107(agentsSrc)) {
86275
+ const agentFiles = readdirSync36(agentsSrc).filter((f2) => f2.endsWith(".cant"));
86276
+ for (const agentFile of agentFiles) {
86277
+ const dst = join106(cantAgentsDir, agentFile);
86278
+ if (!existsSync107(dst)) {
86279
+ await copyFile4(join106(agentsSrc, agentFile), dst);
86280
+ }
86281
+ }
86282
+ }
86283
+ created.push("starter-bundle: team + agent .cant files deployed to .cleo/cant/");
86284
+ }
85874
86285
  var DIR_SYMLINK_TYPE2;
85875
86286
  var init_init = __esm({
85876
86287
  "packages/core/src/init.ts"() {
@@ -99759,6 +100170,27 @@ async function runUpgrade(options = {}) {
99759
100170
  }
99760
100171
  } catch {
99761
100172
  }
100173
+ try {
100174
+ const { deployStarterBundle: deployStarterBundle2 } = await Promise.resolve().then(() => (init_init(), init_exports));
100175
+ const cantCreated = [];
100176
+ const cantWarnings = [];
100177
+ await deployStarterBundle2(cleoDir, cantCreated, cantWarnings);
100178
+ if (cantCreated.length > 0) {
100179
+ actions.push({
100180
+ action: "cant_starter_bundle",
100181
+ status: "applied",
100182
+ details: cantCreated.join(", ")
100183
+ });
100184
+ }
100185
+ for (const w2 of cantWarnings) {
100186
+ actions.push({
100187
+ action: "cant_starter_bundle",
100188
+ status: "skipped",
100189
+ details: w2
100190
+ });
100191
+ }
100192
+ } catch {
100193
+ }
99762
100194
  try {
99763
100195
  const skillsCreated = [];
99764
100196
  const skillsWarnings = [];
@@ -111714,6 +112146,7 @@ __export(internal_exports, {
111714
112146
  attachAgentToProject: () => attachAgentToProject2,
111715
112147
  auditData: () => auditData,
111716
112148
  auditLog: () => auditLog,
112149
+ autoLinkMemories: () => autoLinkMemories,
111717
112150
  autoRecordDispatchTokenUsage: () => autoRecordDispatchTokenUsage,
111718
112151
  backfillBrainGraph: () => backfillBrainGraph,
111719
112152
  backfillTasks: () => backfillTasks,
@@ -112127,12 +112560,14 @@ __export(internal_exports, {
112127
112560
  lifecycleStageNameSchema: () => lifecycleStageNameSchema,
112128
112561
  lifecycleStageStatusSchema: () => lifecycleStageStatusSchema,
112129
112562
  lifecycleTransitionTypeSchema: () => lifecycleTransitionTypeSchema,
112563
+ linkMemoryToCode: () => linkMemoryToCode,
112130
112564
  listAdrs: () => listAdrs,
112131
112565
  listAgentInstances: () => listAgentInstances,
112132
112566
  listAgentsForProject: () => listAgentsForProject,
112133
112567
  listBackups: () => listBackups,
112134
112568
  listBrainBackups: () => listBrainBackups,
112135
112569
  listChains: () => listChains,
112570
+ listCodeLinks: () => listCodeLinks,
112136
112571
  listEpicsWithLifecycle: () => listEpicsWithLifecycle,
112137
112572
  listGlobalSaltBackups: () => listGlobalSaltBackups,
112138
112573
  listGlobalSqliteBackups: () => listGlobalSqliteBackups,
@@ -112256,6 +112691,8 @@ __export(internal_exports, {
112256
112691
  pushRelease: () => pushRelease,
112257
112692
  pushWarning: () => pushWarning,
112258
112693
  queryAudit: () => queryAudit,
112694
+ queryCodeForMemory: () => queryCodeForMemory,
112695
+ queryMemoriesForCode: () => queryMemoriesForCode,
112259
112696
  readGrades: () => readGrades,
112260
112697
  readJson: () => readJson,
112261
112698
  readManifestEntries: () => readManifestEntries2,
@@ -112613,6 +113050,7 @@ var init_internal = __esm({
112613
113050
  init_init();
112614
113051
  init_auto_extract();
112615
113052
  init_brain_embedding();
113053
+ init_graph_memory_bridge();
112616
113054
  init_llm_extraction();
112617
113055
  init_memory_bridge();
112618
113056
  init_session_memory();
@@ -118731,7 +119169,31 @@ async function orchestrateSpawnExecute(taskId, adapterId, protocolType, projectR
118731
119169
  }
118732
119170
  } catch {
118733
119171
  }
119172
+ try {
119173
+ const { hooks: hooks2 } = await Promise.resolve().then(() => (init_internal(), internal_exports));
119174
+ await hooks2.dispatch("SubagentStart", cwd, {
119175
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
119176
+ taskId,
119177
+ agentId: cleoSpawnContext.options?.preferredAgent ?? `worker-${taskId}`,
119178
+ role: protocolType || "worker",
119179
+ providerId: adapter.providerId
119180
+ }).catch(() => {
119181
+ });
119182
+ } catch {
119183
+ }
118734
119184
  const result = await adapter.spawn(cleoSpawnContext);
119185
+ try {
119186
+ const { hooks: hooks2 } = await Promise.resolve().then(() => (init_internal(), internal_exports));
119187
+ await hooks2.dispatch("SubagentStop", cwd, {
119188
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
119189
+ taskId,
119190
+ agentId: cleoSpawnContext.options?.preferredAgent ?? `worker-${taskId}`,
119191
+ status: result.status,
119192
+ instanceId: result.instanceId
119193
+ }).catch(() => {
119194
+ });
119195
+ } catch {
119196
+ }
118735
119197
  void sendConduitEvent(cwd, "cleo-core", {
118736
119198
  event: "agent.spawned",
118737
119199
  taskId,
@@ -124218,27 +124680,59 @@ var init_memory2 = __esm({
124218
124680
  return wrapResult(result, "query", "memory", operation, startTime);
124219
124681
  }
124220
124682
  case "code.links": {
124221
- const { listCodeLinks } = await Promise.resolve().then(() => (init_internal(), internal_exports));
124222
- const result = await listCodeLinks(projectRoot);
124223
- return wrapResult(result, "query", "memory", operation, startTime);
124683
+ const { listCodeLinks: listCodeLinks2 } = await Promise.resolve().then(() => (init_internal(), internal_exports));
124684
+ const links = await listCodeLinks2(projectRoot);
124685
+ return wrapResult(
124686
+ { success: true, data: links },
124687
+ "query",
124688
+ "memory",
124689
+ operation,
124690
+ startTime
124691
+ );
124224
124692
  }
124225
124693
  case "code.memories-for-code": {
124226
124694
  const symbol2 = params?.symbol;
124227
124695
  if (!symbol2) {
124228
- return errorResult("query", "memory", operation, "E_INVALID_INPUT", "symbol is required", startTime);
124696
+ return errorResult(
124697
+ "query",
124698
+ "memory",
124699
+ operation,
124700
+ "E_INVALID_INPUT",
124701
+ "symbol is required",
124702
+ startTime
124703
+ );
124229
124704
  }
124230
- const { queryMemoriesForCode } = await Promise.resolve().then(() => (init_internal(), internal_exports));
124231
- const result = await queryMemoriesForCode(projectRoot, symbol2);
124232
- return wrapResult({ success: true, data: result }, "query", "memory", operation, startTime);
124705
+ const { queryMemoriesForCode: queryMemoriesForCode2 } = await Promise.resolve().then(() => (init_internal(), internal_exports));
124706
+ const result = await queryMemoriesForCode2(projectRoot, symbol2);
124707
+ return wrapResult(
124708
+ { success: true, data: result },
124709
+ "query",
124710
+ "memory",
124711
+ operation,
124712
+ startTime
124713
+ );
124233
124714
  }
124234
124715
  case "code.for-memory": {
124235
124716
  const memoryId = params?.memoryId;
124236
124717
  if (!memoryId) {
124237
- return errorResult("query", "memory", operation, "E_INVALID_INPUT", "memoryId is required", startTime);
124718
+ return errorResult(
124719
+ "query",
124720
+ "memory",
124721
+ operation,
124722
+ "E_INVALID_INPUT",
124723
+ "memoryId is required",
124724
+ startTime
124725
+ );
124238
124726
  }
124239
- const { queryCodeForMemory } = await Promise.resolve().then(() => (init_internal(), internal_exports));
124240
- const result = await queryCodeForMemory(projectRoot, memoryId);
124241
- return wrapResult({ success: true, data: result }, "query", "memory", operation, startTime);
124727
+ const { queryCodeForMemory: queryCodeForMemory2 } = await Promise.resolve().then(() => (init_internal(), internal_exports));
124728
+ const result = await queryCodeForMemory2(projectRoot, memoryId);
124729
+ return wrapResult(
124730
+ { success: true, data: result },
124731
+ "query",
124732
+ "memory",
124733
+ operation,
124734
+ startTime
124735
+ );
124242
124736
  }
124243
124737
  default:
124244
124738
  return unsupportedOp("query", "memory", operation, startTime);
@@ -124414,16 +124908,35 @@ var init_memory2 = __esm({
124414
124908
  const memoryId = params?.memoryId;
124415
124909
  const codeSymbol = params?.codeSymbol;
124416
124910
  if (!memoryId || !codeSymbol) {
124417
- return errorResult("mutate", "memory", operation, "E_INVALID_INPUT", "memoryId and codeSymbol are required", startTime);
124911
+ return errorResult(
124912
+ "mutate",
124913
+ "memory",
124914
+ operation,
124915
+ "E_INVALID_INPUT",
124916
+ "memoryId and codeSymbol are required",
124917
+ startTime
124918
+ );
124418
124919
  }
124419
- const { linkMemoryToCode } = await Promise.resolve().then(() => (init_internal(), internal_exports));
124420
- const linked = await linkMemoryToCode(projectRoot, memoryId, codeSymbol);
124421
- return wrapResult({ success: true, data: { linked } }, "mutate", "memory", operation, startTime);
124920
+ const { linkMemoryToCode: linkMemoryToCode2 } = await Promise.resolve().then(() => (init_internal(), internal_exports));
124921
+ const linked = await linkMemoryToCode2(projectRoot, memoryId, codeSymbol);
124922
+ return wrapResult(
124923
+ { success: true, data: { linked } },
124924
+ "mutate",
124925
+ "memory",
124926
+ operation,
124927
+ startTime
124928
+ );
124422
124929
  }
124423
124930
  case "code.auto-link": {
124424
- const { autoLinkMemories } = await Promise.resolve().then(() => (init_internal(), internal_exports));
124425
- const result = await autoLinkMemories(projectRoot);
124426
- return wrapResult({ success: true, data: result }, "mutate", "memory", operation, startTime);
124931
+ const { autoLinkMemories: autoLinkMemories2 } = await Promise.resolve().then(() => (init_internal(), internal_exports));
124932
+ const result = await autoLinkMemories2(projectRoot);
124933
+ return wrapResult(
124934
+ { success: true, data: result },
124935
+ "mutate",
124936
+ "memory",
124937
+ operation,
124938
+ startTime
124939
+ );
124427
124940
  }
124428
124941
  default:
124429
124942
  return unsupportedOp("mutate", "memory", operation, startTime);