agent-recall-core 3.4.51 → 3.5.2

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 (104) hide show
  1. package/README.md +559 -330
  2. package/dist/embeddings/config.d.ts.map +1 -1
  3. package/dist/embeddings/config.js +17 -4
  4. package/dist/embeddings/config.js.map +1 -1
  5. package/dist/helpers/alignment-patterns.d.ts +46 -0
  6. package/dist/helpers/alignment-patterns.d.ts.map +1 -1
  7. package/dist/helpers/alignment-patterns.js +103 -2
  8. package/dist/helpers/alignment-patterns.js.map +1 -1
  9. package/dist/helpers/journal-files.d.ts +12 -6
  10. package/dist/helpers/journal-files.d.ts.map +1 -1
  11. package/dist/helpers/journal-files.js +13 -7
  12. package/dist/helpers/journal-files.js.map +1 -1
  13. package/dist/index.d.ts +8 -4
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +15 -4
  16. package/dist/index.js.map +1 -1
  17. package/dist/prompts/consolidation-prompt.js +14 -14
  18. package/dist/retrieval/candidates.d.ts +17 -0
  19. package/dist/retrieval/candidates.d.ts.map +1 -1
  20. package/dist/retrieval/candidates.js +4 -2
  21. package/dist/retrieval/candidates.js.map +1 -1
  22. package/dist/retrieval/contradiction.d.ts +42 -0
  23. package/dist/retrieval/contradiction.d.ts.map +1 -1
  24. package/dist/retrieval/contradiction.js +126 -7
  25. package/dist/retrieval/contradiction.js.map +1 -1
  26. package/dist/retrieval/lexical-index.d.ts +150 -0
  27. package/dist/retrieval/lexical-index.d.ts.map +1 -0
  28. package/dist/retrieval/lexical-index.js +514 -0
  29. package/dist/retrieval/lexical-index.js.map +1 -0
  30. package/dist/retrieval/query-memory.d.ts +17 -7
  31. package/dist/retrieval/query-memory.d.ts.map +1 -1
  32. package/dist/retrieval/query-memory.js +274 -68
  33. package/dist/retrieval/query-memory.js.map +1 -1
  34. package/dist/storage/classification.d.ts.map +1 -1
  35. package/dist/storage/classification.js +4 -1
  36. package/dist/storage/classification.js.map +1 -1
  37. package/dist/storage/content-guard.d.ts +26 -0
  38. package/dist/storage/content-guard.d.ts.map +1 -1
  39. package/dist/storage/content-guard.js +450 -48
  40. package/dist/storage/content-guard.js.map +1 -1
  41. package/dist/storage/corrections.d.ts.map +1 -1
  42. package/dist/storage/corrections.js +47 -66
  43. package/dist/storage/corrections.js.map +1 -1
  44. package/dist/storage/cwd-allowlist.d.ts +28 -2
  45. package/dist/storage/cwd-allowlist.d.ts.map +1 -1
  46. package/dist/storage/cwd-allowlist.js +61 -13
  47. package/dist/storage/cwd-allowlist.js.map +1 -1
  48. package/dist/storage/filelock.d.ts +26 -8
  49. package/dist/storage/filelock.d.ts.map +1 -1
  50. package/dist/storage/filelock.js +202 -26
  51. package/dist/storage/filelock.js.map +1 -1
  52. package/dist/storage/fs-utils.d.ts +51 -0
  53. package/dist/storage/fs-utils.d.ts.map +1 -1
  54. package/dist/storage/fs-utils.js +123 -2
  55. package/dist/storage/fs-utils.js.map +1 -1
  56. package/dist/storage/memory-protocol.js +55 -55
  57. package/dist/storage/paths.d.ts.map +1 -1
  58. package/dist/storage/paths.js +7 -2
  59. package/dist/storage/paths.js.map +1 -1
  60. package/dist/storage/project.d.ts.map +1 -1
  61. package/dist/storage/project.js +9 -2
  62. package/dist/storage/project.js.map +1 -1
  63. package/dist/storage/store-manifest.js +57 -57
  64. package/dist/supabase/embedding.d.ts.map +1 -1
  65. package/dist/supabase/embedding.js +7 -0
  66. package/dist/supabase/embedding.js.map +1 -1
  67. package/dist/supabase/sync.d.ts.map +1 -1
  68. package/dist/supabase/sync.js +42 -18
  69. package/dist/supabase/sync.js.map +1 -1
  70. package/dist/tools-logic/bootstrap.d.ts.map +1 -1
  71. package/dist/tools-logic/bootstrap.js +4 -2
  72. package/dist/tools-logic/bootstrap.js.map +1 -1
  73. package/dist/tools-logic/check.d.ts +7 -0
  74. package/dist/tools-logic/check.d.ts.map +1 -1
  75. package/dist/tools-logic/check.js +54 -44
  76. package/dist/tools-logic/check.js.map +1 -1
  77. package/dist/tools-logic/dream-admission.js +29 -29
  78. package/dist/tools-logic/recall-backend.d.ts.map +1 -1
  79. package/dist/tools-logic/recall-backend.js +3 -1
  80. package/dist/tools-logic/recall-backend.js.map +1 -1
  81. package/dist/tools-logic/smart-recall.d.ts +52 -0
  82. package/dist/tools-logic/smart-recall.d.ts.map +1 -1
  83. package/dist/tools-logic/smart-recall.js +202 -31
  84. package/dist/tools-logic/smart-recall.js.map +1 -1
  85. package/dist/tools-logic/smart-remember-vector.d.ts +3 -1
  86. package/dist/tools-logic/smart-remember-vector.d.ts.map +1 -1
  87. package/dist/tools-logic/smart-remember-vector.js +3 -1
  88. package/dist/tools-logic/smart-remember-vector.js.map +1 -1
  89. package/dist/tools-logic/smart-remember.d.ts.map +1 -1
  90. package/dist/tools-logic/smart-remember.js +6 -2
  91. package/dist/tools-logic/smart-remember.js.map +1 -1
  92. package/dist/types.d.ts +17 -2
  93. package/dist/types.d.ts.map +1 -1
  94. package/dist/types.js +31 -3
  95. package/dist/types.js.map +1 -1
  96. package/dist/vector/embedding.d.ts +20 -1
  97. package/dist/vector/embedding.d.ts.map +1 -1
  98. package/dist/vector/embedding.js +27 -1
  99. package/dist/vector/embedding.js.map +1 -1
  100. package/dist/vector/local-vector-backend.d.ts +4 -1
  101. package/dist/vector/local-vector-backend.d.ts.map +1 -1
  102. package/dist/vector/local-vector-backend.js +7 -3
  103. package/dist/vector/local-vector-backend.js.map +1 -1
  104. package/package.json +59 -59
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lexical-index.js","sourceRoot":"","sources":["../../src/retrieval/lexical-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6FG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAA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AyB;gBACzB,IAAI,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC;oBAAE,OAAO,IAAI,CAAC;gBAC/C,OAAO,GAAG,CAAC,CAAC,CAAC;YACf,CAAC;SACF,CAAC;QAEF,KAAK,CAAC,IAAI,GAAG,EAAE,oBAAoB,EAAE,IAAI,CAAC,oBAAoB,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;QACpF,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAC9B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC,CAAC,6DAA6D;IAC5E,CAAC;AACH,CAAC"}
@@ -329,10 +329,17 @@ export interface QueryMemoryItem {
329
329
  * with no detected conflict.
330
330
  *
331
331
  * ANNOTATE-ONLY (pre-ship red-team fix, STEP 4a, 2026-09-01): a
332
- * `supersededBy` item's `score`/rank is NEVER changed by this stage — see
333
- * `applyContradictionStage`'s own doc comment for why the original
334
- * down-rank was removed. It is, and always was, NEVER removed from
335
- * `items`.
332
+ * `supersededBy` item's `score`/rank is NEVER changed by this per-tier
333
+ * stage — see `applyContradictionStage`'s own doc comment for why the
334
+ * original down-rank was removed. It is, and always was, NEVER removed
335
+ * from `items`.
336
+ *
337
+ * 3.5.2 (2026-10-16): POST-FUSION, this annotation now has one bounded
338
+ * ranking consequence — `applySupersessionCap` caps the fused score just
339
+ * below the superseder's when BOTH sides are in the fused list, so a
340
+ * confidently-superseded fact never outranks its replacement (adversarial
341
+ * T5a). See that function's doc block for why this is not the removed
342
+ * STEP-4a penalty class.
336
343
  */
337
344
  supersededBy?: string;
338
345
  /**
@@ -451,9 +458,12 @@ export interface QueryMemoryInput {
451
458
  export interface QueryMemoryResult {
452
459
  /** Fused + ranked (RRF, two-stage canonical fusion; `score` is the raw
453
460
  * fused RRF sum — since fix4b, 2026-09-12, NOTHING multiplies it by
454
- * default and no post-fusion freshness signal exists; exact ties resolve
455
- * by the authority/insertion order. Exception: the legacy `freshnessBias`
456
- * opt-in, see QueryMemoryInput) — UNCUT, UNFENCED. Caller applies its own
461
+ * default and no GENERAL post-fusion freshness signal exists; exact ties
462
+ * resolve by the authority/insertion order. Two exceptions: the legacy
463
+ * `freshnessBias` opt-in (see QueryMemoryInput), and — 3.5.2 — the
464
+ * bounded supersession cap, which lowers a `supersededBy`-annotated
465
+ * item's score just below its in-list superseder's (see
466
+ * applySupersessionCap)) — UNCUT, UNFENCED. Caller applies its own
457
467
  * limit/labeling/feedback adjustments. */
458
468
  items: QueryMemoryItem[];
459
469
  /** Raw pre-fusion candidate counts per competing tier (Fix 4/5 semantics —
@@ -1 +1 @@
1
- {"version":3,"file":"query-memory.d.ts","sourceRoot":"","sources":["../../src/retrieval/query-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0OG;AAaH,OAAO,EAAiB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAQzD;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,aAAa,CAAC;AAE/E;mEACmE;AACnE,MAAM,MAAM,iBAAiB,GAAG,eAAe,GAAG,SAAS,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,iBAAiB,CAAC;IAC1B,WAAW,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAClC,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C,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB;yEACqE;IACrE,kBAAkB,EAAE,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7D;;6BAEyB;IACzB,cAAc,EAAE,eAAe,EAAE,CAAC;IAClC;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACtC;AAqLD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAS9D;AA6qCD,wBAAsB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAuLrF;AAmBD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,eAAe,EAAE,CAwDrG"}
@@ -234,6 +234,7 @@
234
234
  * the grammar fix's full false-positive-by-false-positive proof.
235
235
  */
236
236
  import { readTierCandidates, filterTrusted } from "./candidates.js";
237
+ import { loadJournalLexicalSnapshot } from "./lexical-index.js";
237
238
  import { applyScope } from "./scope.js";
238
239
  import { detectContradictions } from "./contradiction.js";
239
240
  import { listRooms, recordAccess, ensurePalaceInitialized } from "../palace/rooms.js";
@@ -327,7 +328,7 @@ function bm25Idf(df, n) {
327
328
  * substring containment (script-agnostic), so a rare Han token earns
328
329
  * exactly the same discriminative weight as a rare ASCII one.
329
330
  */
330
- function buildIdfModel(query, corpusTexts) {
331
+ function buildQueryVariants(query) {
331
332
  const rawWords = tokenizeWords(query);
332
333
  const variantsByRaw = new Map();
333
334
  for (const w of rawWords) {
@@ -338,19 +339,22 @@ function buildIdfModel(query, corpusTexts) {
338
339
  variants.add(v);
339
340
  variantsByRaw.set(w, [...variants]);
340
341
  }
341
- const n = corpusTexts.length;
342
- const docs = corpusTexts.map((t) => {
343
- const lower = t.toLowerCase();
344
- return { lower, tokenSet: new Set(tokenizeWords(t).map((tok) => stem(tok))) };
345
- });
342
+ return { rawWords, variantsByRaw };
343
+ }
344
+ /**
345
+ * Assemble the IDF model from a per-word DF oracle. This is buildIdfModel's
346
+ * exact math (bm25Idf → max-normalize → totalMass → weightedExactness),
347
+ * extracted verbatim so the brute-force corpus scan and the lexical-index
348
+ * postings path (scoreJournalTier) produce byte-identical weights whenever
349
+ * their DF counts agree — the only thing that varies between them is HOW df
350
+ * is counted, pinned equal by test/lexical-index.test.mjs.
351
+ */
352
+ function assembleIdfModel(qv, n, dfOf) {
353
+ const { rawWords, variantsByRaw } = qv;
346
354
  const idf = new Map();
347
355
  let maxIdf = 0;
348
356
  for (const [w, variants] of variantsByRaw) {
349
- let df = 0;
350
- for (const d of docs) {
351
- if (variants.some((v) => d.tokenSet.has(v) || d.lower.includes(v)))
352
- df++;
353
- }
357
+ const df = dfOf(variants);
354
358
  const weight = n > 0 ? bm25Idf(df, n) : 1;
355
359
  idf.set(w, weight);
356
360
  if (weight > maxIdf)
@@ -385,6 +389,22 @@ function buildIdfModel(query, corpusTexts) {
385
389
  },
386
390
  };
387
391
  }
392
+ function buildIdfModel(query, corpusTexts) {
393
+ const qv = buildQueryVariants(query);
394
+ const n = corpusTexts.length;
395
+ const docs = corpusTexts.map((t) => {
396
+ const lower = t.toLowerCase();
397
+ return { lower, tokenSet: new Set(tokenizeWords(t).map((tok) => stem(tok))) };
398
+ });
399
+ return assembleIdfModel(qv, n, (variants) => {
400
+ let df = 0;
401
+ for (const d of docs) {
402
+ if (variants.some((v) => d.tokenSet.has(v) || d.lower.includes(v)))
403
+ df++;
404
+ }
405
+ return df;
406
+ });
407
+ }
388
408
  /**
389
409
  * Simple stable hash for result IDs — ported verbatim from smart-recall.ts.
390
410
  *
@@ -706,74 +726,175 @@ function readLegacyJournalCandidates(project) {
706
726
  out.sort((a, b) => b.date.localeCompare(a.date));
707
727
  return out;
708
728
  }
709
- // ---------------------------------------------------------------------------
710
- // TOKENIZE+SCORE stage — one strategy per tier.
711
- // ---------------------------------------------------------------------------
729
+ /** The journal tier's per-line matcher — the old inline loop body, extracted
730
+ * VERBATIM (perf/lexical-index, 2026-10-16) so the brute-force path and the
731
+ * lexical-index fast path run the IDENTICAL scan (section tracking, excerpt
732
+ * window, per-hit line numbers) over identical content. `dateLabel` is the
733
+ * old loop's `candidate.date || candidate.file` — computed once per
734
+ * candidate by both callers. */
735
+ function collectJournalLineHits(content, dateLabel, keywords, hits) {
736
+ const lines = content.split("\n");
737
+ let currentSection = "top";
738
+ for (let i = 0; i < lines.length; i++) {
739
+ const line = lines[i];
740
+ if (line.startsWith("## ")) {
741
+ currentSection = line.slice(3).trim().toLowerCase().replace(/\s+/g, "_");
742
+ }
743
+ if (!lineMatchesQuery(line, keywords))
744
+ continue;
745
+ const matchIdx = firstMatchIndex(line, keywords);
746
+ const start = Math.max(0, matchIdx - 100);
747
+ const end = Math.min(line.length, matchIdx + 150);
748
+ let excerpt = line.slice(start, end).trim();
749
+ if (start > 0)
750
+ excerpt = "..." + excerpt;
751
+ if (end < line.length)
752
+ excerpt = excerpt + "...";
753
+ hits.push({ title: `${dateLabel} / ${currentSection}`, excerpt, date: dateLabel, line: i + 1 });
754
+ }
755
+ }
712
756
  /** Journal tier: ported from journal-search.ts's per-line matching (section
713
757
  * tracking, excerpt window) + smart-recall.ts's Ebbinghaus×exactness scoring —
714
758
  * now operating on already-fetched MemoryCandidate content instead of a
715
- * fresh fs read. */
716
- function scoreJournalTier(project, query, opts) {
717
- const candidates = filterTrusted(readTierCandidates("journal", project, {
718
- includeRollupArchive: opts.includeRollupArchive ?? true,
719
- includeUntrusted: true,
720
- })).concat(filterTrusted(readLegacyJournalCandidates(project)));
759
+ * fresh fs read.
760
+ *
761
+ * perf/lexical-index (2026-10-16): async, with a persistent-index FAST PATH.
762
+ * When the lexical index is usable (default; AGENT_RECALL_LEXICAL_INDEX=0
763
+ * disables, and ANY index failure falls back), the fetch stage no longer
764
+ * reads/tokenizes the whole corpus per query: trust bits, the line-match
765
+ * prefilter, and IDF document frequencies come from retrieval/lexical-index.ts,
766
+ * and file content is read ONLY for docs that can actually produce a hit.
767
+ * RANKING-IDENTICAL to the brute path by construction (same enumeration
768
+ * order, same trust filter, the same collectJournalLineHits scan, and
769
+ * assembleIdfModel fed DF counts that match buildIdfModel's predicate
770
+ * exactly) — pinned by test/lexical-index.test.mjs. The legacy-journal half
771
+ * (readLegacyJournalCandidates) stays brute-force on both paths: it scans
772
+ * an out-of-root directory tree that is empty on virtually every install. */
773
+ async function scoreJournalTier(project, query, opts) {
721
774
  const keywords = tokenizeWords(query);
722
775
  if (keywords.length === 0)
723
776
  return [];
724
777
  const sinceCutoff = opts.since ? parseSinceDate(opts.since) : null;
725
778
  const limit = opts.perTierLimit ?? 25;
779
+ const includeRollupArchive = opts.includeRollupArchive ?? true;
726
780
  const hits = [];
727
- // fix4 S3 (2026-09-11, reports/agentrecall-fix4-retrieval-2026-09-11.md):
728
- // SCORE-THEN-TRUNCATE. The pre-fix4 loop broke out at `hits.length >=
729
- // limit` while iterating candidates in date-DESCENDING order — i.e. it
730
- // truncated by RECENCY before any hit was ever scored, so an old entry
731
- // matching the query strongly was dropped UNSCORED whenever `limit`
732
- // weaker-but-newer line matches existed (the S2-standard eval's latent
733
- // "journal recency pre-truncation" defect; the W2 sort-before-truncate
734
- // work made the pre-truncation deterministic, not correct). Now every
735
- // matching line across every candidate is collected and SCORED
736
- // (recency×0.5 + exactness×0.5, unchanged formula), and `limit` is
737
- // applied to the score-sorted list at the end — one truncation criterion,
738
- // the same one RRF ranking uses. Cost: the full line scan always runs
739
- // (previously it stopped early once `limit` hits were found) — bounded by
740
- // the same already-read candidate set, and measured within the S11
741
- // latency budget by this tranche's eval runs.
742
- for (const candidate of candidates) {
743
- if (sinceCutoff && candidate.date) {
744
- const fileDate = new Date(candidate.date);
745
- if (!isNaN(fileDate.getTime()) && fileDate < sinceCutoff)
746
- continue;
781
+ let idfModel;
782
+ // ---- FAST PATH: persistent lexical index (null → brute fallback) ----
783
+ let snapshotOrNull = null;
784
+ try {
785
+ snapshotOrNull = await loadJournalLexicalSnapshot(project, { includeRollupArchive });
786
+ }
787
+ catch {
788
+ snapshotOrNull = null; // defense in depth — the loader already never throws
789
+ }
790
+ const snapshot = snapshotOrNull;
791
+ if (snapshot) {
792
+ // TRUST-FILTER stage, same predicate as filterTrusted (drop only
793
+ // untrusted === true) — applied to index docs by flag, with content
794
+ // reads below re-verifying through the rescue choke regardless.
795
+ const trustedIdx = [];
796
+ for (let i = 0; i < snapshot.docs.length; i++) {
797
+ if (snapshot.docs[i].untrusted !== true)
798
+ trustedIdx.push(i);
747
799
  }
748
- const lines = candidate.content.split("\n");
749
- let currentSection = "top";
750
- for (let i = 0; i < lines.length; i++) {
751
- const line = lines[i];
752
- if (line.startsWith("## ")) {
753
- currentSection = line.slice(3).trim().toLowerCase().replace(/\s+/g, "_");
800
+ const legacy = filterTrusted(readLegacyJournalCandidates(project));
801
+ // fix4 S3's SCORE-THEN-TRUNCATE loop (see the brute path below for the
802
+ // full history note) — identical scan, but content is only read for
803
+ // docs the substring prefilter says CAN contain a keyword
804
+ // (lineMatchesQuery is pure `includes` over whitespace-free keywords,
805
+ // so docsContaining has no false negatives — lexical-index.ts header).
806
+ for (const i of trustedIdx) {
807
+ const doc = snapshot.docs[i];
808
+ if (sinceCutoff && doc.date) {
809
+ const fileDate = new Date(doc.date);
810
+ if (!isNaN(fileDate.getTime()) && fileDate < sinceCutoff)
811
+ continue;
754
812
  }
755
- if (!lineMatchesQuery(line, keywords))
813
+ if (!keywords.some((kw) => snapshot.docsContaining(kw).has(i)))
756
814
  continue;
757
- const date = candidate.date || candidate.file;
758
- const matchIdx = firstMatchIndex(line, keywords);
759
- const start = Math.max(0, matchIdx - 100);
760
- const end = Math.min(line.length, matchIdx + 150);
761
- let excerpt = line.slice(start, end).trim();
762
- if (start > 0)
763
- excerpt = "..." + excerpt;
764
- if (end < line.length)
765
- excerpt = excerpt + "...";
766
- hits.push({ title: `${date} / ${currentSection}`, excerpt, date, line: i + 1 });
815
+ const content = snapshot.trustedContent(i);
816
+ if (content === null)
817
+ continue;
818
+ collectJournalLineHits(content, doc.date || doc.file, keywords, hits);
819
+ }
820
+ for (const candidate of legacy) {
821
+ if (sinceCutoff && candidate.date) {
822
+ const fileDate = new Date(candidate.date);
823
+ if (!isNaN(fileDate.getTime()) && fileDate < sinceCutoff)
824
+ continue;
825
+ }
826
+ collectJournalLineHits(candidate.content, candidate.date || candidate.file, keywords, hits);
827
+ }
828
+ if (hits.length === 0)
829
+ return [];
830
+ // fix4 S5's IDF, df counted from the index postings instead of a fresh
831
+ // full-corpus tokenization — same corpus (every trusted candidate,
832
+ // since-filter deliberately NOT applied, matching buildIdfModel's brute
833
+ // call below), same per-word predicate (stemmed-token-set hit OR
834
+ // lowercase substring), same math (assembleIdfModel).
835
+ const qv = buildQueryVariants(query);
836
+ const legacyDocs = legacy.map((c) => ({
837
+ lower: c.content.toLowerCase(),
838
+ tokenSet: new Set(tokenizeWords(c.content).map((tok) => stem(tok))),
839
+ }));
840
+ const trustedSet = new Set(trustedIdx);
841
+ const n = trustedIdx.length + legacyDocs.length;
842
+ idfModel = assembleIdfModel(qv, n, (variants) => {
843
+ const matched = new Set();
844
+ for (const v of variants) {
845
+ for (const d of snapshot.docsWithStemToken(v))
846
+ if (trustedSet.has(d))
847
+ matched.add(d);
848
+ for (const d of snapshot.docsContaining(v))
849
+ if (trustedSet.has(d))
850
+ matched.add(d);
851
+ }
852
+ let df = matched.size;
853
+ for (const d of legacyDocs) {
854
+ if (variants.some((v) => d.tokenSet.has(v) || d.lower.includes(v)))
855
+ df++;
856
+ }
857
+ return df;
858
+ });
859
+ }
860
+ else {
861
+ // ---- BRUTE PATH (pre-index behavior, also the fallback + test oracle) ----
862
+ const candidates = filterTrusted(readTierCandidates("journal", project, {
863
+ includeRollupArchive,
864
+ includeUntrusted: true,
865
+ })).concat(filterTrusted(readLegacyJournalCandidates(project)));
866
+ // fix4 S3 (2026-09-11, reports/agentrecall-fix4-retrieval-2026-09-11.md):
867
+ // SCORE-THEN-TRUNCATE. The pre-fix4 loop broke out at `hits.length >=
868
+ // limit` while iterating candidates in date-DESCENDING order — i.e. it
869
+ // truncated by RECENCY before any hit was ever scored, so an old entry
870
+ // matching the query strongly was dropped UNSCORED whenever `limit`
871
+ // weaker-but-newer line matches existed (the S2-standard eval's latent
872
+ // "journal recency pre-truncation" defect; the W2 sort-before-truncate
873
+ // work made the pre-truncation deterministic, not correct). Now every
874
+ // matching line across every candidate is collected and SCORED
875
+ // (recency×0.5 + exactness×0.5, unchanged formula), and `limit` is
876
+ // applied to the score-sorted list at the end — one truncation criterion,
877
+ // the same one RRF ranking uses. Cost: the full line scan always runs
878
+ // (previously it stopped early once `limit` hits were found) — bounded by
879
+ // the same already-read candidate set, and measured within the S11
880
+ // latency budget by this tranche's eval runs.
881
+ for (const candidate of candidates) {
882
+ if (sinceCutoff && candidate.date) {
883
+ const fileDate = new Date(candidate.date);
884
+ if (!isNaN(fileDate.getTime()) && fileDate < sinceCutoff)
885
+ continue;
886
+ }
887
+ collectJournalLineHits(candidate.content, candidate.date || candidate.file, keywords, hits);
767
888
  }
889
+ // fix4 S5: IDF over the scanned journal corpus (one doc = one journal
890
+ // file's content) — weights each query word by rarity before the
891
+ // unchanged recency*0.5 + exactness*0.5 blend below. Review L2
892
+ // (2026-09-11): skipped entirely when nothing matched — building the
893
+ // model tokenizes/lowercases the whole corpus, pure waste at zero hits.
894
+ if (hits.length === 0)
895
+ return [];
896
+ idfModel = buildIdfModel(query, candidates.map((c) => c.content));
768
897
  }
769
- // fix4 S5: IDF over the scanned journal corpus (one doc = one journal
770
- // file's content) — weights each query word by rarity before the
771
- // unchanged recency*0.5 + exactness*0.5 blend below. Review L2
772
- // (2026-09-11): skipped entirely when nothing matched — building the
773
- // model tokenizes/lowercases the whole corpus, pure waste at zero hits.
774
- if (hits.length === 0)
775
- return [];
776
- const idfModel = buildIdfModel(query, candidates.map((c) => c.content));
777
898
  const items = hits.map((h) => {
778
899
  // Independent review fix (W3b, 2026-08-30): `id` must be unique PER HIT,
779
900
  // not per (date,section) — `applyRRF` (below) groups same-tier items by
@@ -1334,6 +1455,77 @@ function fuseCanonical(rrfMap) {
1334
1455
  // ordering the rest) scored per-query identical to neutralization (75.0%)
1335
1456
  // and is documented in the fix4b report as a future option — deliberately
1336
1457
  // NOT shipped: the brief sanctioned exactly two designs.
1458
+ /**
1459
+ * 3.5.2 BOUNDED SUPERSESSION CAP (2026-10-16, adversarial T5a,
1460
+ * reports/2026-10-15-rigorous-eval.md Finding 2 / §7 item 2).
1461
+ *
1462
+ * THE GAP: `applyContradictionStage` is per-tier and annotate-only, and the
1463
+ * semantic leg's votes carry no recency signal — so under the hybrid opt-in
1464
+ * a confidently-superseded fact ("rate limit 100 req/min", 2026-08-01)
1465
+ * deterministically outranked its own replacement ("500 req/min",
1466
+ * 2026-10-12). A stale-first answer is the most dangerous retrieval failure
1467
+ * mode: confidently wrong, invisible to the caller.
1468
+ *
1469
+ * THE FIX: after fusion, an item carrying `supersededBy` whose superseder is
1470
+ * ALSO present in the fused list has its fused score capped at
1471
+ * `superseder.score × SUPERSEDED_RANK_CAP` — i.e. a superseded fact can
1472
+ * never rank above the sibling that superseded it. Chains (A←B←C) converge
1473
+ * via the fixed-point loop: supersession edges always point stale→newer
1474
+ * (detectContradictions resolves direction from DATES, which totally order),
1475
+ * so the edge graph is acyclic and each pass only ever lowers scores —
1476
+ * convergence in ≤ items.length passes, deterministic.
1477
+ *
1478
+ * WHY THIS IS NOT fix4b's REMOVED HOT-WINDOW (nor STEP 4a's removed
1479
+ * CONTRADICTION_PENALTY) COMING BACK — the three defects that killed those
1480
+ * are each structurally absent here:
1481
+ * 1. NOT a global freshness signal: only items with a grammar-detected,
1482
+ * date-unambiguous `supersededBy` annotation are touched (the
1483
+ * high-precision version grammar + the 3.5.2 rate-fact grammar — see
1484
+ * ./contradiction.ts). An undated, un-conflicted, or ambiguously-tied
1485
+ * item is never moved; there is no time-window bucketing at all.
1486
+ * 2. BOUNDED AND RELATIVE: the cap is relative to the ONE superseding
1487
+ * sibling (≈ one adjacent RRF rank below it — 1/62 ÷ 1/61 ≈ 0.984),
1488
+ * never a flat multiplier that can vault items across relevance bands.
1489
+ * `Math.min` only ever LOWERS the stale side; the superseder and every
1490
+ * unrelated item keep their exact fused scores.
1491
+ * 3. FAIL-SAFE ON FALSE POSITIVES: a wrong grammar match at worst swaps a
1492
+ * near-duplicate pair's relative order (both still returned, both
1493
+ * annotated) — not the old ×0.5 wholesale inversion. And on a missing/
1494
+ * unparseable/equal date, `supersededBy` is never set in the first
1495
+ * place (detectContradictions' never-guess invariant), so this cap
1496
+ * cannot fire from no signal.
1497
+ *
1498
+ * Mutates `fused` items in place (they are already this function's own
1499
+ * spread copies — see the fused-array construction in queryMemory below);
1500
+ * the caller re-sorts immediately after. Skips silently when the superseder
1501
+ * is not in the fused list (e.g. filtered by `since`): the cap is relative
1502
+ * by design, and with no reference score there is nothing bounded to do.
1503
+ */
1504
+ const SUPERSEDED_RANK_CAP = 0.98;
1505
+ function applySupersessionCap(fused) {
1506
+ if (fused.length < 2)
1507
+ return;
1508
+ const byId = new Map();
1509
+ for (const it of fused)
1510
+ byId.set(it.id, it);
1511
+ for (let pass = 0; pass < fused.length; pass++) {
1512
+ let changed = false;
1513
+ for (const it of fused) {
1514
+ if (!it.supersededBy)
1515
+ continue;
1516
+ const superseder = byId.get(it.supersededBy);
1517
+ if (!superseder)
1518
+ continue;
1519
+ const capped = superseder.score * SUPERSEDED_RANK_CAP;
1520
+ if (it.score > capped) {
1521
+ it.score = capped;
1522
+ changed = true;
1523
+ }
1524
+ }
1525
+ if (!changed)
1526
+ break;
1527
+ }
1528
+ }
1337
1529
  /** LEGACY multiplicative boost — the exact pre-fix4b `applyHotWindowBoost`
1338
1530
  * body (all defects included: date-only strings parse to 00:00 UTC so the
1339
1531
  * bucket depends on wall-clock time-of-day — audit Finding 2; palace
@@ -1540,10 +1732,19 @@ export async function queryMemory(input) {
1540
1732
  const alsoFoundIn = [...sources].filter((s) => s !== item.source);
1541
1733
  fused.push({ ...item, score, ...(alsoFoundIn.length > 0 ? { alsoFoundIn } : {}) });
1542
1734
  }
1735
+ // 3.5.2 (2026-10-16): bounded supersession cap — a grammar-detected,
1736
+ // date-unambiguous superseded fact never outranks its own superseder.
1737
+ // Runs BEFORE the sort (order-independent: pure score caps + fixed point).
1738
+ // This is the one deliberate, narrow exception to fix4b's "no post-fusion
1739
+ // freshness signal" — see applySupersessionCap's doc block for why it is
1740
+ // not the removed hot-window/CONTRADICTION_PENALTY class.
1741
+ applySupersessionCap(fused);
1543
1742
  // fix4b (2026-09-12): the sort is stable, so exact fused-score ties
1544
1743
  // resolve purely by insertion order — the fix4 authority tie-break
1545
- // (corrections first). No post-fusion freshness signal touches default
1546
- // ranking; see the fallback doc block above applyLegacyHotWindowBoost.
1744
+ // (corrections first). No GENERAL post-fusion freshness signal touches
1745
+ // default ranking (see the fallback doc block above
1746
+ // applyLegacyHotWindowBoost); the 3.5.2 supersession cap above is
1747
+ // supersession-gated, not time-window-gated.
1547
1748
  fused.sort((a, b) => b.score - a.score);
1548
1749
  return {
1549
1750
  items: fused,
@@ -1579,7 +1780,12 @@ export function queryArchiveFallback(project, query, limit) {
1579
1780
  const keywords = tokenizeWords(query);
1580
1781
  if (keywords.length === 0 || limit <= 0)
1581
1782
  return [];
1582
- const candidates = filterTrusted(readTierCandidates("journal", project, { includeRawArchive: true, includeUntrusted: true }).filter((c) => c.sourceKind === "journal-archive-raw"));
1783
+ // rawArchiveOnly (perf/lexical-index, 2026-10-16): this function keeps only
1784
+ // raw-archive candidates, so the reader is told not to read/trust-tag the
1785
+ // live + rollup halves at all — identical output (the `.filter` is now a
1786
+ // belt-and-braces no-op), minus a full live-journal read per low-confidence
1787
+ // query (~0.8 s at 10k entries — the 2026-10-15 scale eval's p95 driver).
1788
+ const candidates = filterTrusted(readTierCandidates("journal", project, { includeRawArchive: true, rawArchiveOnly: true, includeUntrusted: true }).filter((c) => c.sourceKind === "journal-archive-raw"));
1583
1789
  // Newest raw dump first — matches the original's `files.sort((a,b) =>
1584
1790
  // b.localeCompare(a))` file-order preference for a last-resort fallback.
1585
1791
  candidates.sort((a, b) => b.file.localeCompare(a.file));