crbro-memory 1.8.2 → 1.9.1

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.
@@ -1,13 +1,28 @@
1
1
  import type { Brain } from '../engine/brain.js';
2
2
  import type { Neuron, SearchResult } from '../types/index.js';
3
- /** Bump when the schema changes so old on-disk indexes are rebuilt, not loaded. */
4
- export declare const INDEX_VERSION = 2;
3
+ /**
4
+ * Bump when the schema changes so old on-disk indexes are rebuilt, not loaded.
5
+ * v3: chunk removal used to rely on an Orama `where` filter that silently
6
+ * matched nothing, so every index built before it carries chunks for facts
7
+ * that were later revised or forgotten. The bump forces those poisoned
8
+ * indexes to rebuild once, which heals them.
9
+ */
10
+ export declare const INDEX_VERSION = 3;
5
11
  export declare class SearchEngine {
6
12
  private brain;
7
13
  private db;
8
14
  private docCount;
9
15
  private dirty;
10
16
  private persistTimer;
17
+ /**
18
+ * Which chunk ids belong to which neuron. Removal used to ask Orama for
19
+ * them with a `where` filter on a plain string field — a query that
20
+ * returns nothing, silently, so "re-index this neuron" never removed a
21
+ * thing and revised facts kept surfacing in recall (observed live: the
22
+ * retired version of a fact outranking its own correction). We are the
23
+ * ones inserting every chunk, so we simply remember what we inserted.
24
+ */
25
+ private chunksByNeuron;
11
26
  constructor(brain: Brain);
12
27
  /**
13
28
  * Load the index from disk, or rebuild it if missing / stale / corrupt.
@@ -59,6 +74,22 @@ export declare class SearchEngine {
59
74
  domain?: string;
60
75
  limit?: number;
61
76
  }): Promise<SearchResult[]>;
77
+ /**
78
+ * Turn per-neuron chunk lists into results, validating each chunk against
79
+ * the neuron on disk before serving it.
80
+ *
81
+ * Two failures end here. An index can carry chunks for knowledge that was
82
+ * revised, forgotten or rewritten (pre-v3 indexes; a second writer; a lost
83
+ * flush) — and serving a retired fact is the one failure a memory system
84
+ * must not have, since the wrong version tends to outrank its own
85
+ * correction. And a neuron whose BEST chunk went stale must not vanish
86
+ * from the answer while it still holds live knowledge that matched: we
87
+ * fall back to its next valid chunk instead. Stale neurons are quietly
88
+ * re-indexed; chunks of deleted neurons are removed on the spot.
89
+ */
90
+ private materializeResults;
91
+ /** Does the chunk still describe something the neuron holds as current? */
92
+ private chunkVive;
62
93
  /**
63
94
  * Search one term. Exact first; only if a reasonably long term finds
64
95
  * nothing do we allow a single edit of slack, which covers typos without
@@ -69,8 +100,21 @@ export declare class SearchEngine {
69
100
  /** Build and insert every chunk of a neuron. */
70
101
  private insertNeuronChunks;
71
102
  private put;
72
- /** Drop every chunk belonging to a neuron. */
103
+ /**
104
+ * Drop every chunk belonging to a neuron.
105
+ *
106
+ * From our own ledger, chunk by chunk — never from an Orama `where`
107
+ * filter. The old filter (string field, empty term) matched nothing and
108
+ * threw nothing, so removal reported success while removing zero chunks,
109
+ * and everything ever revised or forgotten stayed searchable.
110
+ */
73
111
  private removeNeuronChunks;
112
+ /**
113
+ * Rebuild the chunk-ownership ledger from a stored index, so removal keeps
114
+ * working after a load-from-disk. Returns false when the stored shape is
115
+ * not what we expect — the caller then falls back to a full rebuild.
116
+ */
117
+ private recoverChunkMap;
74
118
  private markDirty;
75
119
  private countDocs;
76
120
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAQ,MAAM,mBAAmB,CAAC;AAEpE,mFAAmF;AACnF,eAAO,MAAM,aAAa,IAAI,CAAC;AAwC/B,qBAAa,YAAY;IAMX,OAAO,CAAC,KAAK;IALzB,OAAO,CAAC,EAAE,CAAyB;IACnC,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,YAAY,CAA+B;gBAE/B,KAAK,EAAE,KAAK;IAIhC;;;;;;;;OAQG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;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I,CAAC;IAsB3B;;;;;;;;;;OAUG;YACW,OAAO;IAQrB;;;;;OAKG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAsBhC;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAShD,mCAAmC;IAC7B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAa9B,0EAA0E;IACpE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAM5B;;;;;;;;OAQG;IACG,MAAM,CACV,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAC5C,OAAO,CAAC,YAAY,EAAE,CAAC;IA0D1B;;;;;;;;;;;;OAYG;YACW,kBAAkB;IA8DhC,2EAA2E;IAC3E,OAAO,CAAC,SAAS;IAyBjB;;;;;OAKG;YACW,UAAU;IAyCxB,gDAAgD;YAClC,kBAAkB;YA+FlB,GAAG;IAmBjB;;;;;;;OAOG;YACW,kBAAkB;IAiBhC;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAoBvB,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,SAAS;IAYjB;;;;OAIG;YACW,eAAe;CAO9B"}
@@ -20,8 +20,14 @@ const orama_1 = require("@orama/orama");
20
20
  const fs_js_1 = require("../utils/fs.js");
21
21
  const hash_js_1 = require("../utils/hash.js");
22
22
  const tokenize_js_1 = require("./tokenize.js");
23
- /** Bump when the schema changes so old on-disk indexes are rebuilt, not loaded. */
24
- exports.INDEX_VERSION = 2;
23
+ /**
24
+ * Bump when the schema changes so old on-disk indexes are rebuilt, not loaded.
25
+ * v3: chunk removal used to rely on an Orama `where` filter that silently
26
+ * matched nothing, so every index built before it carries chunks for facts
27
+ * that were later revised or forgotten. The bump forces those poisoned
28
+ * indexes to rebuild once, which heals them.
29
+ */
30
+ exports.INDEX_VERSION = 3;
25
31
  /** Weight given to a neuron for each *additional* chunk that matches. */
26
32
  const BREADTH_BONUS = 0.05;
27
33
  /** Cap on the breadth bonus — breadth is a tiebreaker, never the main signal. */
@@ -47,6 +53,15 @@ class SearchEngine {
47
53
  docCount = 0;
48
54
  dirty = false;
49
55
  persistTimer = null;
56
+ /**
57
+ * Which chunk ids belong to which neuron. Removal used to ask Orama for
58
+ * them with a `where` filter on a plain string field — a query that
59
+ * returns nothing, silently, so "re-index this neuron" never removed a
60
+ * thing and revised facts kept surfacing in recall (observed live: the
61
+ * retired version of a fact outranking its own correction). We are the
62
+ * ones inserting every chunk, so we simply remember what we inserted.
63
+ */
64
+ chunksByNeuron = new Map();
50
65
  constructor(brain) {
51
66
  this.brain = brain;
52
67
  }
@@ -69,7 +84,10 @@ class SearchEngine {
69
84
  this.db = (0, orama_1.create)({ schema: SCHEMA });
70
85
  (0, orama_1.load)(this.db, stored.data);
71
86
  this.docCount = this.countDocs(stored.data);
72
- return;
87
+ if (this.recoverChunkMap(stored.data))
88
+ return;
89
+ // Could not tell which chunk belongs to which neuron — without
90
+ // that, removal is blind, so a rebuild is the only safe answer.
73
91
  }
74
92
  }
75
93
  catch {
@@ -106,6 +124,7 @@ class SearchEngine {
106
124
  async rebuild() {
107
125
  this.db = (0, orama_1.create)({ schema: SCHEMA });
108
126
  this.docCount = 0;
127
+ this.chunksByNeuron.clear();
109
128
  const ids = await (0, fs_js_1.listJSONFiles)(this.brain.paths.cortex);
110
129
  for (const id of ids) {
111
130
  try {
@@ -204,38 +223,109 @@ class SearchEngine {
204
223
  }
205
224
  if (perChunk.size === 0)
206
225
  return [];
207
- // Coverage weighting, then collapse chunks into their neurons.
226
+ // Coverage weighting, then group chunks by neuron, best first.
208
227
  const byNeuron = new Map();
209
228
  for (const chunk of perChunk.values()) {
210
229
  const coverage = chunk.matched / terms.length;
211
230
  chunk.score = chunk.score * Math.pow(coverage, COVERAGE_EXPONENT);
212
- const current = byNeuron.get(chunk.neuron);
213
- if (!current) {
214
- byNeuron.set(chunk.neuron, { best: chunk, extra: 0 });
231
+ const list = byNeuron.get(chunk.neuron);
232
+ if (list)
233
+ list.push(chunk);
234
+ else
235
+ byNeuron.set(chunk.neuron, [chunk]);
236
+ }
237
+ for (const list of byNeuron.values())
238
+ list.sort((a, b) => b.score - a.score);
239
+ return this.materializeResults([...byNeuron.values()], limit);
240
+ }
241
+ /**
242
+ * Turn per-neuron chunk lists into results, validating each chunk against
243
+ * the neuron on disk before serving it.
244
+ *
245
+ * Two failures end here. An index can carry chunks for knowledge that was
246
+ * revised, forgotten or rewritten (pre-v3 indexes; a second writer; a lost
247
+ * flush) — and serving a retired fact is the one failure a memory system
248
+ * must not have, since the wrong version tends to outrank its own
249
+ * correction. And a neuron whose BEST chunk went stale must not vanish
250
+ * from the answer while it still holds live knowledge that matched: we
251
+ * fall back to its next valid chunk instead. Stale neurons are quietly
252
+ * re-indexed; chunks of deleted neurons are removed on the spot.
253
+ */
254
+ async materializeResults(porNeurona, limit) {
255
+ // Only the plausible head pays the neuron reads: nothing below it could
256
+ // reach the answer even if everything above dropped out.
257
+ porNeurona.sort((a, b) => b[0].score - a[0].score);
258
+ const candidatos = porNeurona.slice(0, Math.max(limit * 3, limit + 8));
259
+ const resultados = [];
260
+ for (const chunks of candidatos) {
261
+ const neuronId = chunks[0].neuron;
262
+ let neuron = null;
263
+ let legible = true;
264
+ try {
265
+ neuron = await (0, fs_js_1.readJSON)(this.brain.paths.neuron(neuronId));
215
266
  }
216
- else if (chunk.score > current.best.score) {
217
- byNeuron.set(chunk.neuron, { best: chunk, extra: current.extra + 1 });
267
+ catch {
268
+ legible = false; // exists but unreadable never censor on that
218
269
  }
219
- else {
220
- current.extra += 1;
270
+ if (legible && neuron === null) {
271
+ // The neuron is gone; its chunks are litter. Sweep and move on.
272
+ await this.removeNeuronChunks(neuronId);
273
+ this.markDirty();
274
+ continue;
221
275
  }
222
- }
223
- const results = [];
224
- for (const { best, extra } of byNeuron.values()) {
225
- const breadth = Math.min(extra * BREADTH_BONUS, BREADTH_CAP);
226
- results.push({
227
- neuron_id: best.neuron,
228
- name: best.name,
229
- domain: best.domain,
230
- relevance_score: Math.round((best.score + breadth) * 1000) / 1000,
231
- matching_content: best.text,
232
- matched_kind: best.kind,
233
- matched_added: best.added || '',
234
- heat: best.heat,
276
+ let elegido = null;
277
+ let huboRancio = false;
278
+ for (const chunk of chunks) {
279
+ if (!legible || neuron === null || this.chunkVive(chunk, neuron)) {
280
+ elegido = chunk;
281
+ break;
282
+ }
283
+ huboRancio = true;
284
+ }
285
+ if (huboRancio && neuron) {
286
+ // Heal in the background, never block recall.
287
+ void this.indexNeuron(neuron).catch(() => { });
288
+ }
289
+ if (!elegido)
290
+ continue;
291
+ const breadth = Math.min((chunks.length - 1) * BREADTH_BONUS, BREADTH_CAP);
292
+ resultados.push({
293
+ neuron_id: elegido.neuron,
294
+ name: elegido.name,
295
+ domain: elegido.domain,
296
+ relevance_score: Math.round((elegido.score + breadth) * 1000) / 1000,
297
+ matching_content: elegido.text,
298
+ matched_kind: elegido.kind,
299
+ matched_added: elegido.added || '',
300
+ heat: elegido.heat,
301
+ ...(neuron?.map?.text ? { has_map: true } : {}),
235
302
  });
236
303
  }
237
- results.sort((a, b) => b.relevance_score - a.relevance_score);
238
- return results.slice(0, limit);
304
+ resultados.sort((a, b) => b.relevance_score - a.relevance_score);
305
+ return resultados.slice(0, limit);
306
+ }
307
+ /** Does the chunk still describe something the neuron holds as current? */
308
+ chunkVive(chunk, neuron) {
309
+ switch (chunk.kind) {
310
+ case 'fact':
311
+ return (neuron.facts || []).some(f => !isRetired(f) && f.text === chunk.text);
312
+ case 'error':
313
+ return (neuron.errors || []).includes(chunk.text);
314
+ case 'map':
315
+ return neuron.map?.text === chunk.text;
316
+ case 'pattern':
317
+ return (neuron.patterns || []).includes(chunk.text);
318
+ case 'preference':
319
+ return (neuron.preferences || []).includes(chunk.text);
320
+ case 'decision':
321
+ return (neuron.decisions || []).some(d => {
322
+ const texto = d.rationale ? `${d.text} — ${d.rationale}` : d.text;
323
+ return texto === chunk.text;
324
+ });
325
+ default:
326
+ // Headers describe the neuron itself; identity, not content.
327
+ return true;
328
+ }
239
329
  }
240
330
  // ─── Internals ─────────────────────────────────────────────────
241
331
  /**
@@ -253,10 +343,12 @@ class SearchEngine {
253
343
  limit: Math.max(this.docCount, 10),
254
344
  tolerance,
255
345
  };
256
- if (domain)
257
- params.where = { domain: { eq: domain } };
258
346
  const res = await (0, orama_1.search)(this.db, params);
259
- return res.hits;
347
+ const hits = res.hits;
348
+ // Filtered here, not with an Orama `where` clause: a `where` on a
349
+ // plain string field matches nothing at all, so the old code turned
350
+ // every domain-scoped recall into zero results (measured).
351
+ return domain ? hits.filter(h => h.document.domain === domain) : hits;
260
352
  };
261
353
  let hits = await run(0);
262
354
  // Try the other grammatical number too, and keep the best score each
@@ -354,6 +446,26 @@ class SearchEngine {
354
446
  added: '',
355
447
  });
356
448
  }
449
+ for (const err of neuron.errors || []) {
450
+ if (!err)
451
+ continue;
452
+ await this.put({
453
+ ...base,
454
+ id: (0, hash_js_1.chunkId)(neuron.id, `error:${err}`),
455
+ text: err,
456
+ kind: 'error',
457
+ added: '',
458
+ });
459
+ }
460
+ if (neuron.map && neuron.map.text) {
461
+ await this.put({
462
+ ...base,
463
+ id: (0, hash_js_1.chunkId)(neuron.id, `map:${neuron.map.text}`),
464
+ text: neuron.map.text,
465
+ kind: 'map',
466
+ added: neuron.map.updated || '',
467
+ });
468
+ }
357
469
  }
358
470
  async put(doc) {
359
471
  try {
@@ -363,29 +475,71 @@ class SearchEngine {
363
475
  catch {
364
476
  // Duplicate id (identical text twice in one neuron) — nothing to add.
365
477
  }
478
+ // Registered even on duplicate: the id is in the index either way, and
479
+ // an unregistered chunk is one that removal can never reach again.
480
+ const neuron = String(doc.neuron || '');
481
+ if (!neuron)
482
+ return;
483
+ let ids = this.chunksByNeuron.get(neuron);
484
+ if (!ids) {
485
+ ids = new Set();
486
+ this.chunksByNeuron.set(neuron, ids);
487
+ }
488
+ ids.add(String(doc.id));
366
489
  }
367
- /** Drop every chunk belonging to a neuron. */
490
+ /**
491
+ * Drop every chunk belonging to a neuron.
492
+ *
493
+ * From our own ledger, chunk by chunk — never from an Orama `where`
494
+ * filter. The old filter (string field, empty term) matched nothing and
495
+ * threw nothing, so removal reported success while removing zero chunks,
496
+ * and everything ever revised or forgotten stayed searchable.
497
+ */
368
498
  async removeNeuronChunks(neuronId) {
369
499
  if (!this.db)
370
500
  return;
371
- try {
372
- const res = await (0, orama_1.search)(this.db, {
373
- term: '',
374
- where: { neuron: { eq: neuronId } },
375
- limit: 10000,
376
- });
377
- for (const hit of res.hits) {
378
- try {
379
- await (0, orama_1.remove)(this.db, hit.document.id);
501
+ const ids = this.chunksByNeuron.get(neuronId);
502
+ if (!ids)
503
+ return;
504
+ for (const id of ids) {
505
+ try {
506
+ // remove() returns false (it does not throw) for an absent id, so
507
+ // the count only moves when a document really left the index.
508
+ const fuera = await (0, orama_1.remove)(this.db, id);
509
+ if (fuera)
380
510
  this.docCount = Math.max(0, this.docCount - 1);
511
+ }
512
+ catch {
513
+ // Already gone.
514
+ }
515
+ }
516
+ this.chunksByNeuron.delete(neuronId);
517
+ }
518
+ /**
519
+ * Rebuild the chunk-ownership ledger from a stored index, so removal keeps
520
+ * working after a load-from-disk. Returns false when the stored shape is
521
+ * not what we expect — the caller then falls back to a full rebuild.
522
+ */
523
+ recoverChunkMap(data) {
524
+ try {
525
+ const docs = data?.docs?.docs;
526
+ if (!docs || typeof docs !== 'object')
527
+ return false;
528
+ this.chunksByNeuron.clear();
529
+ for (const doc of Object.values(docs)) {
530
+ if (!doc || !doc.id || !doc.neuron)
531
+ continue;
532
+ let ids = this.chunksByNeuron.get(doc.neuron);
533
+ if (!ids) {
534
+ ids = new Set();
535
+ this.chunksByNeuron.set(doc.neuron, ids);
381
536
  }
382
- catch {
383
- // Already gone.
384
- }
537
+ ids.add(String(doc.id));
385
538
  }
539
+ return this.chunksByNeuron.size > 0 || this.docCount === 0;
386
540
  }
387
541
  catch {
388
- // `where` on a non-filterable field, or empty index — ignore.
542
+ return false;
389
543
  }
390
544
  }
391
545
  markDirty() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":";AAAA,oEAAoE;AACpE,uEAAuE;AACvE,EAAE;AACF,mCAAmC;AACnC,2EAA2E;AAC3E,sEAAsE;AACtE,uEAAuE;AACvE,0EAA0E;AAC1E,4EAA4E;AAC5E,6EAA6E;AAC7E,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,sEAAsE;;;AAEtE,wCAA0E;AAE1E,0CAAoH;AACpH,8CAA2C;AAC3C,+CAAqD;AAIrD,mFAAmF;AACtE,QAAA,aAAa,GAAG,CAAC,CAAC;AAE/B,yEAAyE;AACzE,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,iFAAiF;AACjF,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,8EAA8E;AAC9E,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,+DAA+D;AAC/D,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC,MAAM,MAAM,GAAG;IACb,EAAE,EAAE,QAAiB,EAAQ,iDAAiD;IAC9E,MAAM,EAAE,QAAiB;IACzB,IAAI,EAAE,QAAiB;IACvB,IAAI,EAAE,QAAiB;IACvB,IAAI,EAAE,QAAiB,EAAM,kDAAkD;IAC/E,MAAM,EAAE,QAAiB;IACzB,IAAI,EAAE,QAAiB;IACvB,KAAK,EAAE,QAAiB;IACxB,IAAI,EAAE,QAAiB;CACxB,CAAC;AAmBF,MAAa,YAAY;IAMH;IALZ,EAAE,GAAoB,IAAI,CAAC;IAC3B,QAAQ,GAAG,CAAC,CAAC;IACb,KAAK,GAAG,KAAK,CAAC;IACd,YAAY,GAA0B,IAAI,CAAC;IAEnD,YAAoB,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;IAAG,CA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AAC,MAAM,KAAK,WAAW,CAAC;AACrE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAoCpE,wBAAgB,YAAY,IAAI,SAAS,CAkmCxC"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAoCpE,wBAAgB,YAAY,IAAI,SAAS,CAssCxC"}
package/dist/server.js CHANGED
@@ -154,9 +154,9 @@ function createServer() {
154
154
  // ═══════════════════════════════════════════════════════════════
155
155
  // TOOL 3: crbro_learn — Add knowledge to the brain
156
156
  // ═══════════════════════════════════════════════════════════════
157
- server.tool('crbro_learn', 'Teach the brain a fact, decision, pattern, or preference about a topic. If the neuron (topic) does not exist, it will be created automatically. Use this to store knowledge that should persist across sessions. If this replaces something you stored before, pass `supersedes` - otherwise the old version stays exactly as valid as the new one and both keep coming back on recall.', {
157
+ server.tool('crbro_learn', 'Teach the brain a fact, decision, pattern, preference or error about a topic. If the neuron (topic) does not exist, it will be created automatically. Use this to store knowledge that should persist across sessions. Type `error` is for a mistake you made and how it was corrected - store both halves in one entry, and check for them with crbro_recall before repeating a task where you have slipped before. If this replaces something you stored before, pass `supersedes` - otherwise the old version stays exactly as valid as the new one and both keep coming back on recall.', {
158
158
  topic: zod_1.z.string().describe('The topic name (e.g., "OctoChat", "Firebase", "SEO Strategy")'),
159
- type: zod_1.z.enum(['fact', 'decision', 'pattern', 'preference']).describe('Type of knowledge to store'),
159
+ type: zod_1.z.enum(['fact', 'decision', 'pattern', 'preference', 'error']).describe('Type of knowledge to store. `error` = a mistake plus its correction, kept as a ledger you can check before repeating the task.'),
160
160
  content: zod_1.z.string().describe('The knowledge content to remember'),
161
161
  confidence: zod_1.z.number().min(0).max(1).optional().describe('Confidence level 0.0-1.0 (default 1.0)'),
162
162
  domain: zod_1.z.string().optional().describe('Domain category (e.g., "proyectos-web", "infraestructura")'),
@@ -190,6 +190,14 @@ function createServer() {
190
190
  neuron_id: result.neuron.id,
191
191
  action: result.action,
192
192
  superseded_facts: result.superseded,
193
+ supersedes_unmatched: result.supersedes_unmatched.length > 0
194
+ ? result.supersedes_unmatched
195
+ : undefined,
196
+ supersedes_warning: result.supersedes_unmatched.length > 0
197
+ ? 'These supersedes targets matched NO active fact — the old version is ' +
198
+ 'still live and will keep appearing on recall. Find its id with ' +
199
+ 'crbro_recall and retire it with crbro_revise.'
200
+ : undefined,
193
201
  redacted: result.redacted.length > 0 ? result.redacted : undefined,
194
202
  redaction_note: result.redacted.length > 0
195
203
  ? `Stored, but ${result.redacted.length} credential(s) were replaced with a marker: ` +
@@ -319,7 +327,7 @@ function createServer() {
319
327
  // ═══════════════════════════════════════════════════════════════
320
328
  // TOOL 6: crbro_recall — Search the brain
321
329
  // ═══════════════════════════════════════════════════════════════
322
- server.tool('crbro_recall', 'Search the brain for knowledge saved in earlier sessions. Searches the full text of every fact, decision and pattern, not just topic names, and each result carries the exact fact that matched plus the date it was recorded. Call this before asking the user something they may already have told you, and before assuming a past decision. If a result looks right, pass its neuron_id back to crbro_learn so new knowledge lands in the same place.', {
330
+ server.tool('crbro_recall', 'Search the brain for knowledge saved in earlier sessions. Searches the full text of every fact, decision, pattern, error and system map, not just topic names, and each result carries the exact chunk that matched plus the date it was recorded. Call this before asking the user something they may already have told you, and before assuming a past decision. A result with has_map: true belongs to a neuron that keeps a system map - read it with crbro_map before touching that system. If a result looks right, pass its neuron_id back to crbro_learn so new knowledge lands in the same place.', {
323
331
  query: zod_1.z.string().describe('What to search for (e.g., "Firebase authentication setup")'),
324
332
  domain: zod_1.z.string().optional().describe('Filter by domain'),
325
333
  limit: zod_1.z.number().optional().describe('Max results (default 10)'),
@@ -338,7 +346,7 @@ function createServer() {
338
346
  results,
339
347
  hint: results.length === 0
340
348
  ? 'Nothing matched. Try fewer, more distinctive words - names, ids, filenames - rather than a full sentence.'
341
- : 'matching_content is the fact that matched; matched_added is when it was recorded. Prefer recent facts when two disagree.',
349
+ : 'matching_content is the chunk that matched; matched_added is when it was recorded. Prefer recent facts when two disagree. Results with has_map: true belong to neurons holding a system map - read it with crbro_map before working on that system.',
342
350
  }, null, 2),
343
351
  }],
344
352
  };
@@ -641,6 +649,87 @@ function createServer() {
641
649
  }
642
650
  });
643
651
  // ═══════════════════════════════════════════════════════════════
652
+ // TOOL: crbro_map — The living map of a system
653
+ // ═══════════════════════════════════════════════════════════════
654
+ server.tool('crbro_map', 'Read or replace the system map of a neuron. A map is ONE living document answering: where does this system live, what serves what, which pieces talk to each other, and what are the traps that cost hours. Read it BEFORE working on a system you have touched in past sessions - it is the difference between continuing and re-discovering. After building or changing a system, rewrite the whole map so it stays true: pass `content` and it replaces the previous version entirely (append-only maps rot). Without `content` it returns the current map.', {
655
+ neuron: zod_1.z.string().describe('Neuron ID or name (e.g. "project_octochat" or "OctoChat")'),
656
+ content: zod_1.z.string().optional().describe('The new map, replacing the old one whole. Omit to read. Write it as the reference you will need next time: paths, ids, what-serves-what, gotchas.'),
657
+ domain: zod_1.z.string().optional().describe('Domain for the neuron if it has to be created (e.g. "proyectos-web")'),
658
+ }, async (args) => {
659
+ try {
660
+ if (args.content === undefined) {
661
+ const neuron = (await cortex.peek(args.neuron)) || (await cortex.findByName(args.neuron));
662
+ if (!neuron) {
663
+ return {
664
+ content: [{
665
+ type: 'text',
666
+ text: `Neuron not found: "${args.neuron}". Use crbro_recall to find the right neuron_id first.`,
667
+ }],
668
+ };
669
+ }
670
+ if (!neuron.map || !neuron.map.text) {
671
+ return {
672
+ content: [{
673
+ type: 'text',
674
+ text: JSON.stringify({
675
+ neuron_id: neuron.id,
676
+ map: null,
677
+ message: `"${neuron.name}" has no system map yet. After working on this system, write one with crbro_map + content: where it lives, what serves what, the traps.`,
678
+ }, null, 2),
679
+ }],
680
+ };
681
+ }
682
+ return {
683
+ content: [{
684
+ type: 'text',
685
+ text: JSON.stringify({
686
+ neuron_id: neuron.id,
687
+ updated: neuron.map.updated,
688
+ by: neuron.map.by,
689
+ map: neuron.map.text,
690
+ hint: 'If anything here proved wrong or the system changed, rewrite the map before closing the task.',
691
+ }, null, 2),
692
+ }],
693
+ };
694
+ }
695
+ const result = await cortex.setMap(args.neuron, args.content, {
696
+ domain: args.domain,
697
+ });
698
+ if (!result.neuron) {
699
+ return {
700
+ content: [{
701
+ type: 'text',
702
+ text: `Could not store the map for "${args.neuron}".`,
703
+ }],
704
+ };
705
+ }
706
+ return {
707
+ content: [{
708
+ type: 'text',
709
+ text: JSON.stringify({
710
+ neuron_id: result.neuron.id,
711
+ action: result.action,
712
+ updated: result.neuron.map?.updated,
713
+ length: args.content.length,
714
+ redacted: result.redacted.length > 0 ? result.redacted : undefined,
715
+ message: args.content.trim() === ''
716
+ ? `System map of "${result.neuron.name}" cleared.`
717
+ : `System map of "${result.neuron.name}" replaced. The previous version is gone - this one is now the reference.`,
718
+ }, null, 2),
719
+ }],
720
+ };
721
+ }
722
+ catch (err) {
723
+ return {
724
+ content: [{
725
+ type: 'text',
726
+ text: `CRBRO map error: ${err instanceof Error ? err.message : String(err)}`,
727
+ }],
728
+ isError: true,
729
+ };
730
+ }
731
+ });
732
+ // ═══════════════════════════════════════════════════════════════
644
733
  // TOOL 16: crbro_revise — Retire knowledge that stopped being true
645
734
  // ═══════════════════════════════════════════════════════════════
646
735
  server.tool('crbro_revise', 'Mark stored facts as no longer current. Use this the moment you discover something you saved is out of date or was wrong: a memory that only ever appends keeps serving the old version alongside the new one, with equal confidence. Superseded facts disappear from crbro_recall but stay in the neuron file, so nothing is lost and the correction is auditable.', {
@@ -669,8 +758,12 @@ function createServer() {
669
758
  neuron_id: result.neuron.id,
670
759
  revised: result.revised,
671
760
  status: args.status || 'superseded',
761
+ unmatched: result.unmatched.length > 0 ? result.unmatched : undefined,
672
762
  message: result.revised > 0
673
- ? `${result.revised} fact(s) retired in "${result.neuron.name}". They no longer appear in recall.`
763
+ ? `${result.revised} fact(s) retired in "${result.neuron.name}". They no longer appear in recall.` +
764
+ (result.unmatched.length > 0
765
+ ? ` WARNING: ${result.unmatched.length} target(s) matched nothing and are still live.`
766
+ : '')
674
767
  : 'Nothing matched. Pass the fact id from crbro_recall, or its exact text.',
675
768
  }, null, 2),
676
769
  }],
@@ -807,7 +900,7 @@ function createServer() {
807
900
  // ═══════════════════════════════════════════════════════════════
808
901
  // TOOL 18: crbro_forget — Remove knowledge for good
809
902
  // ═══════════════════════════════════════════════════════════════
810
- server.tool('crbro_forget', 'Permanently remove facts from a neuron. This is for things that must not exist at all — a credential, personal data, something stored by mistake. For knowledge that merely stopped being true, use crbro_revise instead, which keeps the history. The whole neuron is copied to .quarantine/ before anything is removed, so a mistake can be undone by hand. Always tell the user what you are about to remove and get their agreement first.', {
903
+ server.tool('crbro_forget', 'Permanently remove entries from a neuron. This is for things that must not exist at all — a credential, personal data, something stored by mistake. It removes facts, decisions, patterns, preferences and errors matched by id or exact text, and the system map when given its exact full text (or clear the map with crbro_map and empty content). For knowledge that merely stopped being true, use crbro_revise instead, which keeps the history. The whole neuron is copied to .quarantine/ before anything is removed, so a mistake can be undone by hand. On shared neurons the removal travels: facts retract, errors are purged, a cleared map stays cleared. Always tell the user what you are about to remove and get their agreement first.', {
811
904
  neuron: zod_1.z.string().describe('Neuron ID or name holding the entries'),
812
905
  facts: zod_1.z.array(zod_1.z.string()).describe('What to remove: fact ids, or the exact text of a fact, decision, pattern or preference'),
813
906
  }, async (args) => {