@nxuss/lemma 1.16.1 → 1.17.0
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/bin/init.js +4 -0
- package/dist/cjs/mcp/tools.d.ts.map +1 -1
- package/dist/cjs/mcp/tools.js +279 -9
- package/dist/cjs/mcp/tools.js.map +1 -1
- package/dist/cjs/pr-review/bridge/BrainBridge.js +1 -1
- package/dist/cjs/pr-review/bridge/BrainBridge.js.map +1 -1
- package/dist/cjs/subconscious/BrainEmbeddings.d.ts +59 -0
- package/dist/cjs/subconscious/BrainEmbeddings.d.ts.map +1 -0
- package/dist/cjs/subconscious/BrainEmbeddings.js +222 -0
- package/dist/cjs/subconscious/BrainEmbeddings.js.map +1 -0
- package/dist/cjs/subconscious/GitIngest.js +2 -2
- package/dist/cjs/subconscious/GitIngest.js.map +1 -1
- package/dist/cjs/subconscious/TheBrainV2.d.ts +284 -2
- package/dist/cjs/subconscious/TheBrainV2.d.ts.map +1 -1
- package/dist/cjs/subconscious/TheBrainV2.js +871 -46
- package/dist/cjs/subconscious/TheBrainV2.js.map +1 -1
- package/dist/cjs/utils/ConversationCheckpoint.js +1 -1
- package/dist/cjs/utils/ConversationCheckpoint.js.map +1 -1
- package/dist/esm/mcp/tools.d.ts.map +1 -1
- package/dist/esm/mcp/tools.js +280 -10
- package/dist/esm/mcp/tools.js.map +1 -1
- package/dist/esm/pr-review/bridge/BrainBridge.js +1 -1
- package/dist/esm/pr-review/bridge/BrainBridge.js.map +1 -1
- package/dist/esm/subconscious/BrainEmbeddings.d.ts +59 -0
- package/dist/esm/subconscious/BrainEmbeddings.d.ts.map +1 -0
- package/dist/esm/subconscious/BrainEmbeddings.js +211 -0
- package/dist/esm/subconscious/BrainEmbeddings.js.map +1 -0
- package/dist/esm/subconscious/GitIngest.js +2 -2
- package/dist/esm/subconscious/GitIngest.js.map +1 -1
- package/dist/esm/subconscious/TheBrainV2.d.ts +284 -2
- package/dist/esm/subconscious/TheBrainV2.d.ts.map +1 -1
- package/dist/esm/subconscious/TheBrainV2.js +866 -46
- package/dist/esm/subconscious/TheBrainV2.js.map +1 -1
- package/dist/esm/utils/ConversationCheckpoint.js +1 -1
- package/dist/esm/utils/ConversationCheckpoint.js.map +1 -1
- package/package.json +1 -1
package/bin/init.js
CHANGED
|
@@ -277,6 +277,10 @@ tokens sale más cara que los tokens que ahorra.
|
|
|
277
277
|
| Antes de aplicar un patch generado | \`mcp__lemma__validate_patch_sandbox\` | Valídalo antes de escribirlo, no después |
|
|
278
278
|
| "¿Cuánto ahorramos de verdad?" | \`mcp__lemma__token_receipt\` | Bitácora auditable real, no una cifra inventada |
|
|
279
279
|
| Guardar una solución para el futuro | \`mcp__lemma__store_memory\` | Solo después de verificarla (tests pasaron, el usuario confirmó) — una solución mala guardada se vuelve un cache hit falso más adelante |
|
|
280
|
+
| Una memoria salió STALE pero la verificaste y sigue siendo correcta | \`mcp__lemma__refresh_memory\` | Re-ancla la evidencia conservando id, hits y las aristas \`derivedFrom\`; guardar un casi-duplicado pierde las tres (y el dedup suele rechazarlo) |
|
|
281
|
+
| Una memoria está simplemente mal, no solo mal encajada | \`mcp__lemma__forget_memory\` | Borrado real. Para "no era lo que buscaba en esta consulta" usa \`downvote_memory\`: esa memoria puede ser la correcta para otra pregunta |
|
|
282
|
+
|
|
283
|
+
Ambas están en el toolbox (\`action="call"\`), no en la lista anunciada.
|
|
280
284
|
|
|
281
285
|
## No todas las tools de Lemma están en tu lista
|
|
282
286
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAsgDnE,oFAAoF;AACpF,wBAAgB,kBAAkB,IAAI,MAAM,CAM3C;AAED,oEAAoE;AACpE,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAEjD;AAED,iEAAiE;AACjE,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAEjD;AAED,iFAAiF;AACjF,wBAAgB,qBAAqB,IAAI;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAQA;AA6HD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,MAAM,EAAE,IAAI,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAqCD,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,GAC1C,IAAI,CAiHN"}
|
package/dist/cjs/mcp/tools.js
CHANGED
|
@@ -112,6 +112,10 @@ function isProUser() {
|
|
|
112
112
|
const FREE_TOOLS = new Set([
|
|
113
113
|
// Cache & Memory — the hook that shows instant value
|
|
114
114
|
"smarter_cache", "state_hash_cache", "token_receipt", "search_memory", "store_memory", "downvote_memory", "verify_memory", "get_project_history",
|
|
115
|
+
// Memory upkeep. Deleting your own memories, re-verifying them, and getting them back out
|
|
116
|
+
// of the tool must never be behind a paywall — a user who cannot export or forget what a
|
|
117
|
+
// free tier collected does not really own it.
|
|
118
|
+
"forget_memory", "refresh_memory", "brain_stats", "brain_export", "brain_import",
|
|
115
119
|
// Token optimization — shows what they're saving
|
|
116
120
|
"token_budget", "squeeze_prompt", "turbosqueeze",
|
|
117
121
|
// Utility — just enough to function
|
|
@@ -350,6 +354,81 @@ const toolDefinitions = [
|
|
|
350
354
|
required: ["id"],
|
|
351
355
|
},
|
|
352
356
|
},
|
|
357
|
+
{
|
|
358
|
+
name: "forget_memory",
|
|
359
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
|
|
360
|
+
description: "Permanently delete one memory from the Brain by id. Use when a memory is flat wrong, was captured by mistake, or should never have been stored — not when it is merely a poor match for one query (that is downvote_memory, which keeps it around for a different question later). Deletion is irreversible and the id will not come back from another session's copy.",
|
|
361
|
+
inputSchema: {
|
|
362
|
+
type: "object",
|
|
363
|
+
properties: {
|
|
364
|
+
id: { type: "string", description: "The memory's id, from a search_memory or store_memory result." },
|
|
365
|
+
},
|
|
366
|
+
required: ["id"],
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
name: "refresh_memory",
|
|
371
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
372
|
+
description: "Re-anchor a STALE memory to the code as it stands now, keeping its id, hit count and derivedFrom links (storing a near-duplicate instead loses all three, and dedup often refuses it anyway). Call with just the id after you have verified the memory is still correct; pass filePaths/symbols instead when the code moved and it should track something new. Only call this once you have actually checked — it records your assertion that the memory is true today, it cannot verify that itself.",
|
|
373
|
+
inputSchema: {
|
|
374
|
+
type: "object",
|
|
375
|
+
properties: {
|
|
376
|
+
id: { type: "string", description: "The memory's id, from a search_memory or verify_memory result." },
|
|
377
|
+
filePaths: { type: "array", items: { type: "string" }, description: "New files to track instead of the current ones. Omit to re-hash whatever it already tracks." },
|
|
378
|
+
symbols: {
|
|
379
|
+
type: "array",
|
|
380
|
+
items: {
|
|
381
|
+
type: "object",
|
|
382
|
+
properties: {
|
|
383
|
+
filePath: { type: "string" },
|
|
384
|
+
symbolName: { type: "string" },
|
|
385
|
+
},
|
|
386
|
+
required: ["filePath", "symbolName"],
|
|
387
|
+
},
|
|
388
|
+
description: "New symbols to track instead of the current ones (e.g. the function was renamed or moved).",
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
required: ["id"],
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
name: "brain_stats",
|
|
396
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false },
|
|
397
|
+
description: "Health report for the Brain itself: entry count, how many memories no search has ever reused, how many were downvoted, what wrote them (manual vs. each auto-capture path), projects covered, and corpus size. Pass deep:true to also re-hash every tracked file and report the stale ratio — accurate but thousands of file reads on a large Brain.",
|
|
398
|
+
inputSchema: {
|
|
399
|
+
type: "object",
|
|
400
|
+
properties: {
|
|
401
|
+
deep: { type: "boolean", description: "Also compute the stale ratio by re-hashing all tracked evidence. Slow.", default: false },
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
name: "brain_export",
|
|
407
|
+
annotations: { readOnlyHint: true, idempotentHint: false, openWorldHint: false },
|
|
408
|
+
description: "Write memories to a portable NDJSON bundle for backup, moving to another machine, or sharing with a teammate. Defaults to this project's memories only, and to fresh ones only (a stale memory exported and imported elsewhere is just a wrong answer with a passport).",
|
|
409
|
+
inputSchema: {
|
|
410
|
+
type: "object",
|
|
411
|
+
properties: {
|
|
412
|
+
outPath: { type: "string", description: "Where to write the bundle (relative to the workspace root)." },
|
|
413
|
+
allProjects: { type: "boolean", description: "Export every project's memories, not just this one.", default: false },
|
|
414
|
+
domain: { type: "string", description: "Only export memories tagged with this domain." },
|
|
415
|
+
includeStale: { type: "boolean", description: "Include memories whose tracked evidence no longer matches.", default: false },
|
|
416
|
+
},
|
|
417
|
+
required: ["outPath"],
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
name: "brain_import",
|
|
422
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
423
|
+
description: "Merge a bundle written by brain_export into this Brain. Additive and non-destructive: an id already present keeps the newer version, and anything previously deleted with forget_memory stays deleted. Imported memories track the paths of the machine they came from, so most will read as stale here until refresh_memory re-anchors them.",
|
|
424
|
+
inputSchema: {
|
|
425
|
+
type: "object",
|
|
426
|
+
properties: {
|
|
427
|
+
path: { type: "string", description: "Path to the bundle file (relative to the workspace root)." },
|
|
428
|
+
},
|
|
429
|
+
required: ["path"],
|
|
430
|
+
},
|
|
431
|
+
},
|
|
353
432
|
{
|
|
354
433
|
name: "get_routing_advice",
|
|
355
434
|
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
@@ -1480,6 +1559,11 @@ const toolHandlers = {
|
|
|
1480
1559
|
store_memory: handleStoreMemory,
|
|
1481
1560
|
downvote_memory: handleDownvoteMemory,
|
|
1482
1561
|
verify_memory: handleVerifyMemory,
|
|
1562
|
+
forget_memory: handleForgetMemory,
|
|
1563
|
+
refresh_memory: handleRefreshMemory,
|
|
1564
|
+
brain_stats: handleBrainStats,
|
|
1565
|
+
brain_export: handleBrainExport,
|
|
1566
|
+
brain_import: handleBrainImport,
|
|
1483
1567
|
get_routing_advice: handleGetRoutingAdvice,
|
|
1484
1568
|
auto_heal: handleAutoHeal,
|
|
1485
1569
|
read_workspace_file: handleReadWorkspaceFile,
|
|
@@ -1758,7 +1842,9 @@ async function handleSearchMemory(args) {
|
|
|
1758
1842
|
throw new Error("Query is required");
|
|
1759
1843
|
try {
|
|
1760
1844
|
const brain = (0, TheBrainV2_1.getBrain)();
|
|
1761
|
-
|
|
1845
|
+
// searchHybrid is search() plus one boolean check unless LEMMA_BRAIN_EMBEDDINGS is set,
|
|
1846
|
+
// so this costs nothing by default and picks up the semantic re-rank when it is enabled.
|
|
1847
|
+
const results = await brain.searchHybrid(query, limit, minSimilarity, { projectId: (0, TheBrainV2_1.deriveProjectId)(), domain, semanticDiff });
|
|
1762
1848
|
if (results.length === 0) {
|
|
1763
1849
|
(0, TokenReceipt_1.recordReceiptEvent)("reasoning", query.substring(0, 100), {
|
|
1764
1850
|
tool: "search_memory",
|
|
@@ -1809,7 +1895,15 @@ async function handleSearchMemory(args) {
|
|
|
1809
1895
|
}
|
|
1810
1896
|
if (stale.length > 0) {
|
|
1811
1897
|
const staleText = stale
|
|
1812
|
-
.map((r, i) =>
|
|
1898
|
+
.map((r, i) => {
|
|
1899
|
+
// "You are on a different branch" and "someone rewrote this function" are the same
|
|
1900
|
+
// hash mismatch and completely different situations for the reader: the first is
|
|
1901
|
+
// usually not a reason to distrust the memory at all.
|
|
1902
|
+
const cause = r.staleCause === "branch-changed"
|
|
1903
|
+
? `\nNOTE: stored on branch \`${r.storedOnBranch}\`, you are on \`${(0, TheBrainV2_1.currentGitContext)().branch || "an unknown branch"}\`. The difference may be the branch switch rather than an edit — check before discarding this.`
|
|
1904
|
+
: "";
|
|
1905
|
+
return `${formatResult(r, i)}\nSTALE — changed since stored: ${r.staleFiles.join(", ")}${cause}`;
|
|
1906
|
+
})
|
|
1813
1907
|
.join("\n\n---\n\n");
|
|
1814
1908
|
parts.push(`${stale.length} more ${stale.length === 1 ? "memory is" : "memories are"} similar but STALE (underlying file(s) changed) — do not reuse verbatim, re-verify against current file state:\n\n${staleText}`);
|
|
1815
1909
|
}
|
|
@@ -1843,7 +1937,7 @@ async function handleStoreMemory(args) {
|
|
|
1843
1937
|
throw new Error("Query and response are required");
|
|
1844
1938
|
try {
|
|
1845
1939
|
const brain = (0, TheBrainV2_1.getBrain)();
|
|
1846
|
-
const storeRes = brain.store(query, responseText, provider, 0.92, filePaths, undefined, outcome, symbols, claims, domain, derivedFrom);
|
|
1940
|
+
const storeRes = brain.store(query, responseText, provider, 0.92, filePaths, undefined, outcome, symbols, claims, domain, derivedFrom, { source: "manual" });
|
|
1847
1941
|
// Storing a memory saves nothing — it only creates the chance of a saving later.
|
|
1848
1942
|
// Crediting tokens here inflated the ledger on write and then credited the same
|
|
1849
1943
|
// answer again on every read. The saving is booked by search_memory on a fresh hit.
|
|
@@ -1866,7 +1960,11 @@ async function handleStoreMemory(args) {
|
|
|
1866
1960
|
? `\n\n⚠️ ${storeRes.conflicts.length} existing ${storeRes.conflicts.length === 1 ? "memory shares" : "memories share"} a symbol with this one but disagree on outcome — review before trusting either:\n` +
|
|
1867
1961
|
storeRes.conflicts.map((c) => ` - [${c.outcome}] ${c.id}: ${c.query.substring(0, 120)}`).join("\n")
|
|
1868
1962
|
: "";
|
|
1869
|
-
|
|
1963
|
+
// The id is the handle for every follow-up action on this memory — derivedFrom on a
|
|
1964
|
+
// later store, verify_memory, refresh_memory, forget_memory. Without it the caller had
|
|
1965
|
+
// to search for the memory it had just written to do anything with it.
|
|
1966
|
+
const idNote = storeRes.id ? ` (id: ${storeRes.id})` : "";
|
|
1967
|
+
return { content: [{ type: "text", text: `Success: Memory stored${idNote}. ${storeRes.reason}${trackingNote}${symbolNote}${outcomeNote}${claimsNote}${domainNote}${derivedFromNote}${conflictsNote}` }] };
|
|
1870
1968
|
}
|
|
1871
1969
|
catch (e) {
|
|
1872
1970
|
(0, utils_1.logError)("store_memory", e);
|
|
@@ -1886,6 +1984,138 @@ async function handleDownvoteMemory(args) {
|
|
|
1886
1984
|
return { content: [{ type: "text", text: `Failed to downvote memory: ${e.message}` }] };
|
|
1887
1985
|
}
|
|
1888
1986
|
}
|
|
1987
|
+
/**
|
|
1988
|
+
* Deleting a memory is the one Brain operation with no undo, so it asks the client to
|
|
1989
|
+
* confirm where the client supports it, and echoes back what was destroyed where it doesn't
|
|
1990
|
+
* — an irreversible action must at minimum leave a record of what it removed.
|
|
1991
|
+
*/
|
|
1992
|
+
async function handleForgetMemory(args) {
|
|
1993
|
+
const id = args?.id;
|
|
1994
|
+
if (!id)
|
|
1995
|
+
throw new Error("id is required");
|
|
1996
|
+
try {
|
|
1997
|
+
const brain = (0, TheBrainV2_1.getBrain)();
|
|
1998
|
+
const preview = brain.verifyByIds([id])[0];
|
|
1999
|
+
if (preview?.status === "unknown") {
|
|
2000
|
+
return { content: [{ type: "text", text: `No memory with id "${id}" in the Brain — nothing to delete.` }] };
|
|
2001
|
+
}
|
|
2002
|
+
const elicited = await tryElicitConfirmation(`Permanently delete Brain memory "${id}"? This cannot be undone.`);
|
|
2003
|
+
if (elicited.supported && !elicited.confirmed) {
|
|
2004
|
+
return { content: [{ type: "text", text: `Memory "${id}" was not deleted: declined during confirmation.` }] };
|
|
2005
|
+
}
|
|
2006
|
+
const result = brain.forget(id);
|
|
2007
|
+
if (!result.ok || !result.forgotten) {
|
|
2008
|
+
return { content: [{ type: "text", text: result.message }] };
|
|
2009
|
+
}
|
|
2010
|
+
return {
|
|
2011
|
+
content: [{
|
|
2012
|
+
type: "text",
|
|
2013
|
+
text: `${result.message}\n\nDeleted content, for the record (nothing else can recover it):\n stored: ${result.forgotten.timestamp}\n reused: ${result.forgotten.hits} time(s)\n query: ${result.forgotten.query.substring(0, 300)}`,
|
|
2014
|
+
}],
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
catch (e) {
|
|
2018
|
+
(0, utils_1.logError)("forget_memory", e);
|
|
2019
|
+
return { content: [{ type: "text", text: `Failed to delete memory: ${e.message}` }] };
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
async function handleRefreshMemory(args) {
|
|
2023
|
+
const id = args?.id;
|
|
2024
|
+
if (!id)
|
|
2025
|
+
throw new Error("id is required");
|
|
2026
|
+
const filePaths = Array.isArray(args?.filePaths) ? args.filePaths.filter((p) => typeof p === "string" && p) : undefined;
|
|
2027
|
+
const symbols = Array.isArray(args?.symbols)
|
|
2028
|
+
? args.symbols.filter((sym) => sym?.filePath && sym?.symbolName)
|
|
2029
|
+
: undefined;
|
|
2030
|
+
try {
|
|
2031
|
+
const result = (0, TheBrainV2_1.getBrain)().refresh(id, { filePaths, symbols });
|
|
2032
|
+
if (!result.ok)
|
|
2033
|
+
return { content: [{ type: "text", text: result.message }] };
|
|
2034
|
+
const retrackedNote = result.retracked && result.retracked.length > 0
|
|
2035
|
+
? `\nNow tracking: ${result.retracked.join(", ")}`
|
|
2036
|
+
: "\nThis memory tracks no files or symbols, so there was nothing to re-anchor — its age clock was reset.";
|
|
2037
|
+
return { content: [{ type: "text", text: `${result.message}${retrackedNote}` }] };
|
|
2038
|
+
}
|
|
2039
|
+
catch (e) {
|
|
2040
|
+
(0, utils_1.logError)("refresh_memory", e);
|
|
2041
|
+
return { content: [{ type: "text", text: `Failed to refresh memory: ${e.message}` }] };
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
async function handleBrainStats(args) {
|
|
2045
|
+
try {
|
|
2046
|
+
const stats = (0, TheBrainV2_1.getBrain)().getStats({ deep: args?.deep === true });
|
|
2047
|
+
const lines = [];
|
|
2048
|
+
lines.push(`# Brain health`);
|
|
2049
|
+
lines.push(`Entries: ${stats.totalEntries} (${stats.totalTerms} indexed terms, ${((stats.corpusBytes || 0) / 1024).toFixed(0)} KB on disk)`);
|
|
2050
|
+
lines.push(`This session: ${stats.cacheHits} hit(s), ${stats.cacheMisses} miss(es)`);
|
|
2051
|
+
if (stats.totalEntries > 0) {
|
|
2052
|
+
const neverHitPct = ((stats.neverHit || 0) / stats.totalEntries) * 100;
|
|
2053
|
+
lines.push(`Never reused: ${stats.neverHit} (${neverHitPct.toFixed(0)}% — these are evicted first)`);
|
|
2054
|
+
lines.push(`Downvoted: ${stats.downvoted}`);
|
|
2055
|
+
lines.push(`Projects: ${stats.projects}${stats.unscopedEntries ? ` (+${stats.unscopedEntries} entries predating project scoping)` : ""}`);
|
|
2056
|
+
if (stats.oldestEntry)
|
|
2057
|
+
lines.push(`Oldest entry: ${stats.oldestEntry}`);
|
|
2058
|
+
if (stats.tombstones)
|
|
2059
|
+
lines.push(`Deleted ids still suppressed: ${stats.tombstones}`);
|
|
2060
|
+
const sources = Object.entries(stats.bySource || {}).sort((a, b) => b[1] - a[1]);
|
|
2061
|
+
if (sources.length > 0) {
|
|
2062
|
+
lines.push(`Written by: ${sources.map(([k, v]) => `${k}=${v}`).join(", ")}`);
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
if (stats.staleEntries !== undefined) {
|
|
2066
|
+
lines.push(`Stale: ${stats.staleEntries} of the entries that track evidence (${((stats.staleRatio || 0) * 100).toFixed(0)}%) — refresh_memory re-anchors one, forget_memory drops it.`);
|
|
2067
|
+
}
|
|
2068
|
+
else {
|
|
2069
|
+
lines.push(`(stale ratio not computed — pass deep:true)`);
|
|
2070
|
+
}
|
|
2071
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
2072
|
+
}
|
|
2073
|
+
catch (e) {
|
|
2074
|
+
(0, utils_1.logError)("brain_stats", e);
|
|
2075
|
+
return { content: [{ type: "text", text: `Failed to read Brain stats: ${e.message}` }] };
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
async function handleBrainExport(args) {
|
|
2079
|
+
const outPath = args?.outPath;
|
|
2080
|
+
if (!outPath)
|
|
2081
|
+
throw new Error("outPath is required");
|
|
2082
|
+
try {
|
|
2083
|
+
const bundle = (0, TheBrainV2_1.getBrain)().exportBundle({
|
|
2084
|
+
// Scoped to this project unless asked otherwise: exporting every project's memories
|
|
2085
|
+
// by default is how a bundle meant for one teammate ends up carrying another client's
|
|
2086
|
+
// codebase notes with it.
|
|
2087
|
+
projectId: args?.allProjects === true ? undefined : (0, TheBrainV2_1.deriveProjectId)(),
|
|
2088
|
+
domain: typeof args?.domain === "string" && args.domain.trim() ? args.domain.trim() : undefined,
|
|
2089
|
+
includeStale: args?.includeStale === true,
|
|
2090
|
+
});
|
|
2091
|
+
const { resolved } = (0, utils_1.safeResolvePath)(process.cwd(), outPath);
|
|
2092
|
+
fs_1.default.mkdirSync(path_1.default.dirname(resolved), { recursive: true });
|
|
2093
|
+
fs_1.default.writeFileSync(resolved, bundle.text, "utf8");
|
|
2094
|
+
const staleNote = bundle.skippedStale > 0
|
|
2095
|
+
? ` Skipped ${bundle.skippedStale} stale memor${bundle.skippedStale === 1 ? "y" : "ies"} (pass includeStale:true to export those too).`
|
|
2096
|
+
: "";
|
|
2097
|
+
return { content: [{ type: "text", text: `Exported ${bundle.count} memor${bundle.count === 1 ? "y" : "ies"} to ${outPath}.${staleNote}` }] };
|
|
2098
|
+
}
|
|
2099
|
+
catch (e) {
|
|
2100
|
+
(0, utils_1.logError)("brain_export", e);
|
|
2101
|
+
return { content: [{ type: "text", text: `Failed to export Brain: ${e.message}` }] };
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
async function handleBrainImport(args) {
|
|
2105
|
+
const bundlePath = args?.path;
|
|
2106
|
+
if (!bundlePath)
|
|
2107
|
+
throw new Error("path is required");
|
|
2108
|
+
try {
|
|
2109
|
+
const { resolved } = (0, utils_1.safeResolvePath)(process.cwd(), bundlePath);
|
|
2110
|
+
const text = fs_1.default.readFileSync(resolved, "utf8");
|
|
2111
|
+
const result = (0, TheBrainV2_1.getBrain)().importBundle(text);
|
|
2112
|
+
return { content: [{ type: "text", text: result.message }] };
|
|
2113
|
+
}
|
|
2114
|
+
catch (e) {
|
|
2115
|
+
(0, utils_1.logError)("brain_import", e);
|
|
2116
|
+
return { content: [{ type: "text", text: `Failed to import Brain bundle: ${e.message}` }] };
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
1889
2119
|
async function handleVerifyMemory(args) {
|
|
1890
2120
|
const ids = Array.isArray(args?.ids) ? args.ids.filter((id) => typeof id === "string" && id) : [];
|
|
1891
2121
|
const semanticDiff = args?.semanticDiff === true;
|
|
@@ -2073,7 +2303,7 @@ async function handleReadWorkspaceFile(args) {
|
|
|
2073
2303
|
`If you no longer hold that copy, re-fetch with force:true.`,
|
|
2074
2304
|
``,
|
|
2075
2305
|
delta.body,
|
|
2076
|
-
].join("\n"),
|
|
2306
|
+
].join("\n") + formatRecallNote(filePath),
|
|
2077
2307
|
},
|
|
2078
2308
|
],
|
|
2079
2309
|
};
|
|
@@ -2082,7 +2312,7 @@ async function handleReadWorkspaceFile(args) {
|
|
|
2082
2312
|
}
|
|
2083
2313
|
(0, ReadWorkspaceCache_1.recordSent)(resolved, view, dedup.hash, content);
|
|
2084
2314
|
(0, SpeculativeWarmer_1.warmNeighbors)(workspaceRoot, resolved);
|
|
2085
|
-
return { content: [{ type: "text", text: rangeHeader + content }] };
|
|
2315
|
+
return { content: [{ type: "text", text: rangeHeader + content + formatRecallNote(filePath) }] };
|
|
2086
2316
|
}
|
|
2087
2317
|
catch (err) {
|
|
2088
2318
|
(0, utils_1.logError)("read_workspace_file", err);
|
|
@@ -2172,6 +2402,46 @@ function formatBlastRadiusNote(result) {
|
|
|
2172
2402
|
const failedIds = result.failedHits.map((h) => h.id).join(", ");
|
|
2173
2403
|
return `${base}\n⚠️ ${result.failedHits.length} of those document a PRIOR ATTEMPT THAT FAILED on related code: ${failedIds}. Review before continuing down this path.`;
|
|
2174
2404
|
}
|
|
2405
|
+
/**
|
|
2406
|
+
* The read-side counterpart to formatBlastRadiusNote.
|
|
2407
|
+
*
|
|
2408
|
+
* Fase E made the write path proactive: a tool that stales memories says so on the spot.
|
|
2409
|
+
* The read path stayed entirely opt-in — the Brain only spoke when the agent remembered to
|
|
2410
|
+
* call search_memory, which is exactly the moment an agent that doesn't know a memory exists
|
|
2411
|
+
* has no reason to. This closes that asymmetry: reading code the Brain already has notes on
|
|
2412
|
+
* surfaces them, including any documented dead end, before the investigation restarts from
|
|
2413
|
+
* scratch.
|
|
2414
|
+
*
|
|
2415
|
+
* Same rules as the write-side note: advisory only, never blocks, never mutates, and adds no
|
|
2416
|
+
* tool schema (it enriches an existing response), so it costs nothing per turn. It reports
|
|
2417
|
+
* ids rather than content — pulling whole memories into every file read would spend far more
|
|
2418
|
+
* context than it saves; search_memory or verify_memory fetches the ones that matter.
|
|
2419
|
+
*/
|
|
2420
|
+
const _recallNoted = new Set();
|
|
2421
|
+
function formatRecallNote(filePath, symbolName) {
|
|
2422
|
+
try {
|
|
2423
|
+
const result = (0, TheBrainV2_1.getBrain)().findBlastRadius(filePath, symbolName);
|
|
2424
|
+
if (result.hits.length === 0)
|
|
2425
|
+
return "";
|
|
2426
|
+
// Repeating the identical note on every read of the same file is nagging, not signal.
|
|
2427
|
+
// Keyed by the memory set, so a note reappears when the set genuinely changes.
|
|
2428
|
+
const ids = result.hits.map((h) => h.id).sort();
|
|
2429
|
+
const key = `${path_1.default.resolve(filePath)}::${symbolName || ""}::${ids.join(",")}`;
|
|
2430
|
+
if (_recallNoted.has(key))
|
|
2431
|
+
return "";
|
|
2432
|
+
_recallNoted.add(key);
|
|
2433
|
+
const subject = symbolName ? `\`${symbolName}\`` : "this file";
|
|
2434
|
+
const base = `\n\n🧠 The Brain already has ${result.hits.length} memor${result.hits.length === 1 ? "y" : "ies"} about ${subject}: ${ids.join(", ")}. Call verify_memory on them before investigating from scratch.`;
|
|
2435
|
+
if (result.failedHits.length === 0)
|
|
2436
|
+
return base;
|
|
2437
|
+
const failedIds = result.failedHits.map((h) => h.id).join(", ");
|
|
2438
|
+
return `${base}\n⚠️ ${result.failedHits.length} of those document an approach that was tried here and FAILED: ${failedIds}. Read those first so you don't repeat it.`;
|
|
2439
|
+
}
|
|
2440
|
+
catch {
|
|
2441
|
+
// A recall note must never be the reason a file read fails.
|
|
2442
|
+
return "";
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2175
2445
|
async function applyMatch(match, filePath, resolved, originalContent, searchContent, replaceContent) {
|
|
2176
2446
|
let updatedContent;
|
|
2177
2447
|
if (match.strategy === "exact" && match.charStart !== undefined && match.charEnd !== undefined) {
|
|
@@ -5090,7 +5360,7 @@ async function handleGetSymbolSurgicalContext(args) {
|
|
|
5090
5360
|
filePath
|
|
5091
5361
|
});
|
|
5092
5362
|
return {
|
|
5093
|
-
content: [{ type: "text", text: output }]
|
|
5363
|
+
content: [{ type: "text", text: output + formatRecallNote(filePath, symbolName) }]
|
|
5094
5364
|
};
|
|
5095
5365
|
}
|
|
5096
5366
|
catch (err) {
|
|
@@ -5271,7 +5541,7 @@ async function handleSmartFileSlice(args) {
|
|
|
5271
5541
|
resultText += `${i + 1}: ${lines[i]}\n`;
|
|
5272
5542
|
}
|
|
5273
5543
|
});
|
|
5274
|
-
return { content: [{ type: "text", text: resultText }] };
|
|
5544
|
+
return { content: [{ type: "text", text: resultText + formatRecallNote(filePath) }] };
|
|
5275
5545
|
}
|
|
5276
5546
|
catch (e) {
|
|
5277
5547
|
return { content: [{ type: "text", text: `Error slicing file: ${e.message}` }] };
|
|
@@ -5299,7 +5569,7 @@ function autoStoreGreenTests(command, workspaceRoot) {
|
|
|
5299
5569
|
const domain = deriveDomainForFile(changed[0]);
|
|
5300
5570
|
const query = `tests passing after changes to ${changed.slice(0, 5).join(", ")}${changed.length > 5 ? ` and ${changed.length - 5} more file(s)` : ""}`;
|
|
5301
5571
|
const response = `\`${command}\` passed with these files changed (uncommitted at capture time):\n${changed.join("\n")}`;
|
|
5302
|
-
const storeRes = (0, TheBrainV2_1.getBrain)().store(query, response, "test_oracle_auto", 0.92, changed, undefined, "confirmed", undefined, undefined, domain);
|
|
5572
|
+
const storeRes = (0, TheBrainV2_1.getBrain)().store(query, response, "test_oracle_auto", 0.92, changed, undefined, "confirmed", undefined, undefined, domain, undefined, { source: "auto-test" });
|
|
5303
5573
|
if (!storeRes.stored)
|
|
5304
5574
|
return "";
|
|
5305
5575
|
return `\n\n[Lemma] Auto-captured this green state in Brain (${changed.length} file(s), tagged confirmed) — search_memory will surface it, and will flag it stale the moment any of these files change again.`;
|