agent-recall-core 3.4.46 → 3.4.48

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 (102) hide show
  1. package/dist/helpers/handoff.d.ts.map +1 -1
  2. package/dist/helpers/handoff.js +17 -9
  3. package/dist/helpers/handoff.js.map +1 -1
  4. package/dist/helpers/journal-files.d.ts +24 -1
  5. package/dist/helpers/journal-files.d.ts.map +1 -1
  6. package/dist/helpers/journal-files.js +29 -10
  7. package/dist/helpers/journal-files.js.map +1 -1
  8. package/dist/helpers/journal-filter.d.ts +25 -0
  9. package/dist/helpers/journal-filter.d.ts.map +1 -1
  10. package/dist/helpers/journal-filter.js +12 -1
  11. package/dist/helpers/journal-filter.js.map +1 -1
  12. package/dist/index.d.ts +18 -9
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +45 -6
  15. package/dist/index.js.map +1 -1
  16. package/dist/retrieval/candidates.d.ts +339 -0
  17. package/dist/retrieval/candidates.d.ts.map +1 -0
  18. package/dist/retrieval/candidates.js +473 -0
  19. package/dist/retrieval/candidates.js.map +1 -0
  20. package/dist/retrieval/contradiction.d.ts +284 -0
  21. package/dist/retrieval/contradiction.d.ts.map +1 -0
  22. package/dist/retrieval/contradiction.js +343 -0
  23. package/dist/retrieval/contradiction.js.map +1 -0
  24. package/dist/retrieval/query-memory.d.ts +464 -0
  25. package/dist/retrieval/query-memory.d.ts.map +1 -0
  26. package/dist/retrieval/query-memory.js +1189 -0
  27. package/dist/retrieval/query-memory.js.map +1 -0
  28. package/dist/retrieval/scope.d.ts +75 -0
  29. package/dist/retrieval/scope.d.ts.map +1 -0
  30. package/dist/retrieval/scope.js +91 -0
  31. package/dist/retrieval/scope.js.map +1 -0
  32. package/dist/storage/corrections.d.ts +163 -2
  33. package/dist/storage/corrections.d.ts.map +1 -1
  34. package/dist/storage/corrections.js +147 -3
  35. package/dist/storage/corrections.js.map +1 -1
  36. package/dist/storage/lifecycle-telemetry.d.ts +20 -5
  37. package/dist/storage/lifecycle-telemetry.d.ts.map +1 -1
  38. package/dist/storage/lifecycle-telemetry.js +16 -5
  39. package/dist/storage/lifecycle-telemetry.js.map +1 -1
  40. package/dist/storage/session.d.ts +28 -1
  41. package/dist/storage/session.d.ts.map +1 -1
  42. package/dist/storage/session.js +41 -8
  43. package/dist/storage/session.js.map +1 -1
  44. package/dist/supabase/recall-backend.d.ts +26 -2
  45. package/dist/supabase/recall-backend.d.ts.map +1 -1
  46. package/dist/supabase/recall-backend.js +233 -27
  47. package/dist/supabase/recall-backend.js.map +1 -1
  48. package/dist/supabase/sync.d.ts +41 -0
  49. package/dist/supabase/sync.d.ts.map +1 -1
  50. package/dist/supabase/sync.js +46 -0
  51. package/dist/supabase/sync.js.map +1 -1
  52. package/dist/tools-logic/check.d.ts.map +1 -1
  53. package/dist/tools-logic/check.js +62 -36
  54. package/dist/tools-logic/check.js.map +1 -1
  55. package/dist/tools-logic/drill-down.d.ts +24 -0
  56. package/dist/tools-logic/drill-down.d.ts.map +1 -1
  57. package/dist/tools-logic/drill-down.js +36 -0
  58. package/dist/tools-logic/drill-down.js.map +1 -1
  59. package/dist/tools-logic/journal-cold-start.d.ts.map +1 -1
  60. package/dist/tools-logic/journal-cold-start.js +48 -9
  61. package/dist/tools-logic/journal-cold-start.js.map +1 -1
  62. package/dist/tools-logic/journal-list.d.ts +42 -0
  63. package/dist/tools-logic/journal-list.d.ts.map +1 -1
  64. package/dist/tools-logic/journal-list.js +60 -10
  65. package/dist/tools-logic/journal-list.js.map +1 -1
  66. package/dist/tools-logic/journal-read.d.ts.map +1 -1
  67. package/dist/tools-logic/journal-read.js +22 -13
  68. package/dist/tools-logic/journal-read.js.map +1 -1
  69. package/dist/tools-logic/journal-search.d.ts +58 -0
  70. package/dist/tools-logic/journal-search.d.ts.map +1 -1
  71. package/dist/tools-logic/journal-search.js +123 -92
  72. package/dist/tools-logic/journal-search.js.map +1 -1
  73. package/dist/tools-logic/palace-search.d.ts.map +1 -1
  74. package/dist/tools-logic/palace-search.js +30 -11
  75. package/dist/tools-logic/palace-search.js.map +1 -1
  76. package/dist/tools-logic/palace-walk.d.ts +10 -0
  77. package/dist/tools-logic/palace-walk.d.ts.map +1 -1
  78. package/dist/tools-logic/palace-walk.js +25 -16
  79. package/dist/tools-logic/palace-walk.js.map +1 -1
  80. package/dist/tools-logic/recall-insight.d.ts +20 -0
  81. package/dist/tools-logic/recall-insight.d.ts.map +1 -1
  82. package/dist/tools-logic/recall-insight.js +12 -1
  83. package/dist/tools-logic/recall-insight.js.map +1 -1
  84. package/dist/tools-logic/session-end.d.ts.map +1 -1
  85. package/dist/tools-logic/session-end.js +23 -7
  86. package/dist/tools-logic/session-end.js.map +1 -1
  87. package/dist/tools-logic/session-start.d.ts +85 -0
  88. package/dist/tools-logic/session-start.d.ts.map +1 -1
  89. package/dist/tools-logic/session-start.js +245 -108
  90. package/dist/tools-logic/session-start.js.map +1 -1
  91. package/dist/tools-logic/smart-recall.d.ts +87 -62
  92. package/dist/tools-logic/smart-recall.d.ts.map +1 -1
  93. package/dist/tools-logic/smart-recall.js +183 -508
  94. package/dist/tools-logic/smart-recall.js.map +1 -1
  95. package/dist/tools-logic/supersession.d.ts +63 -2
  96. package/dist/tools-logic/supersession.d.ts.map +1 -1
  97. package/dist/tools-logic/supersession.js +153 -48
  98. package/dist/tools-logic/supersession.js.map +1 -1
  99. package/dist/types.d.ts +12 -1
  100. package/dist/types.d.ts.map +1 -1
  101. package/dist/types.js +1 -1
  102. package/package.json +1 -1
@@ -0,0 +1,284 @@
1
+ /**
2
+ * retrieval/contradiction.ts — the CONTRADICTION pipeline stage (Wave 5a,
3
+ * 2026-08-31, reports/2026-08-31-pipe-w5a-contradiction-report.md).
4
+ *
5
+ * ── W5a SALVAGE (2026-08-31, same date, "## W5a salvage" section of the same
6
+ * report) ── An INDEPENDENT review (separate from — and after — the W5a
7
+ * code-reviewer pass named below) passed the mechanism (down-rank+annotate+
8
+ * never-drop, the re-sort→RRF propagation) but found the token grammar's
9
+ * status/kv branches were false-positive-PRONE in a way that actively
10
+ * defeats the stage's own safety intent, not merely "wider than ideal":
11
+ * - HIGH-1 (safeguard defeat): the status branch extracts categories via
12
+ * `extractStatusTokens`, which maps "blocked"/"stuck" to the SAME
13
+ * category (both → "blocked") — so category-EQUIVALENT common phrasing
14
+ * ("status: blocked" vs "status: stuck", genuinely the same fact) should
15
+ * never conflict. It didn't, by that safeguard's own design — but the
16
+ * status branch is un-keyed (see below) and the KV branch's own separate
17
+ * "key: value" extraction treats "status" as a literal KV KEY with
18
+ * "blocked"/"stuck" as different raw VALUES, flagging a conflict the
19
+ * status-category-equivalence check was specifically built to prevent.
20
+ * Two branches reusing overlapping vocabulary defeated each other.
21
+ * - HIGH-2 (generic-key false positive): both the kv branch and (to a
22
+ * narrower degree) the version branch key off whatever single word
23
+ * immediately precedes the value — "priority: high" (a marketing
24
+ * decision) vs "priority: low" (an unrelated cleanup task) share the
25
+ * generic key `priority` and got flagged conflicting despite being
26
+ * about entirely different topics; "key match" gave no topical
27
+ * protection at all for common one-word keys.
28
+ * - HIGH-3 (invisible annotation): `supersededBy`/`conflictsWith` never
29
+ * reached `SmartRecallResultItem`/`JournalSearchResult.results` — fixed
30
+ * separately, see smart-recall.ts's `localRecallSearch` and
31
+ * journal-search.ts's `journalSearch` field-list maps.
32
+ *
33
+ * FIX (this file): restrict `grammarConflict` to `extractVersionTokens`
34
+ * ONLY — status and kv detection are REMOVED from this module entirely
35
+ * (not just gated/pre-filtered). Semver (`\d+\.\d+\.\d+`) is a much
36
+ * narrower, more self-describing pattern than a bare "word: word" or
37
+ * status-category match — a shared key + differing semver value is a
38
+ * strong, low-false-positive signal of a genuine version supersession, and
39
+ * removing the other two branches removes HIGH-1 (the category-vs-KV
40
+ * cross-branch defeat cannot happen when the KV branch does not exist) and
41
+ * the dominant real-world instance of HIGH-2 (KV keys off ANY generic
42
+ * one-word label — "priority", "status", "mode", "env" — a pattern that
43
+ * recurs constantly in prose; a version-shaped `\d+\.\d+\.\d+` collision
44
+ * between two topically-unrelated candidates is comparatively rare, though
45
+ * not literally impossible — e.g. a shared generic key like "step 1.2.3" vs
46
+ * "step 5.6.7" — an acknowledged, narrower residual risk, not claimed to be
47
+ * zero). `extractStatusTokens`/`extractKVTokens` remain exported from
48
+ * `helpers/conflict-scan.ts` and are UNCHANGED there — `conflict-scan.ts`'s
49
+ * own `scanForConflicts` (the separate smart-remember pre-save warning flow)
50
+ * still uses all three extractors; this restriction applies ONLY to this
51
+ * module's pairwise same-tier retrieval-time comparison (see the v4
52
+ * PRE-SHIP GATE FIX addendum below for why `tools-logic/supersession.ts`'s
53
+ * `compareForConflicts` — previously also a three-extractor consumer —
54
+ * no longer is one).
55
+ *
56
+ * WHY THIS IS ITS OWN MODULE, not a function inside query-memory.ts: mirrors
57
+ * `retrieval/scope.ts`'s own precedent — a small, dependency-light, pure
58
+ * comparator that query-memory.ts (this wave) consumes, and that a later
59
+ * wave's caller (e.g. a future `recallInsight()`-style direct consumer) can
60
+ * import without creating an import cycle back into query-memory.ts (which
61
+ * already imports FROM tools-logic — see scope.ts's header for the exact
62
+ * cycle this pattern avoids).
63
+ *
64
+ * WHAT THIS DOES NOT DO (scope, read the eval fixtures before extending):
65
+ * this comparator reuses ONLY `helpers/conflict-scan.ts`'s `extractVersionTokens`
66
+ * semver extractor (post-salvage — see above; status/kv were removed, not
67
+ * merely descoped from the start). It does NOT detect arbitrary
68
+ * semantic-prose contradictions ("we fully migrated OFF Postgres to
69
+ * CockroachDB" vs "we use Postgres") — confirmed empirically against the
70
+ * redteam eval fixture (reports/2026-08-18-eval-redteam.md HIGH-2) while
71
+ * resolving this wave's pre-loaded Challenge A: the version extractor
72
+ * produces no matching key with differing values for that pair at all (no
73
+ * version numbers appear in either sentence). Prose-semantic contradiction
74
+ * detection is a genuinely harder, separate problem (conflict-scan.ts's own
75
+ * header already says so) and is explicitly OUT of this wave's scope — see
76
+ * the wave report's "prose-semantic gap" follow-up section, not silently
77
+ * absorbed into this grammar.
78
+ *
79
+ * ALGORITHM: pairwise, O(n²) over one tier's already-scored item list (n is
80
+ * a per-tier result count, bounded by `perTierLimit`, never the full corpus).
81
+ * For every pair (i, j):
82
+ * 1. GRAMMAR CHECK — same key across version tokens, different semver
83
+ * value → conflict. Symmetric (order of i/j does not matter for
84
+ * whether a conflict exists, only for which side is stale — see 2).
85
+ * 2. DIRECTION — decide which side is stale, if determinable at all:
86
+ * - both items carry a `date` and the dates differ → the OLDER
87
+ * `date` is superseded by the newer one (journal's own authored-
88
+ * date semantics; this only requires "the two dates differ", so it
89
+ * applies to any date-bearing tier, not journal-specifically —
90
+ * journal simply always has a `date`, so this branch always fires
91
+ * for it unless two journal hits share the exact SAME date).
92
+ * - dates are equal, or one/both undefined, AND both items carry an
93
+ * `order` that differs → the LOWER `order` is superseded by the
94
+ * HIGHER `order` (append-order tie-break: palace's same-day-tie
95
+ * policy, per this wave's Challenge B — `order` is populated from
96
+ * the room file's LINE NUMBER for palace items only; journal items
97
+ * are deliberately NOT given an `order` value by this wave's
98
+ * query-memory.ts wiring, so a same-date journal tie falls through
99
+ * to the next bullet instead of guessing off line position, per
100
+ * the wave brief's literal instruction).
101
+ * - neither resolves → AMBIGUOUS: both sides are annotated as
102
+ * conflicting with each other, NEITHER is marked superseded, and
103
+ * (by construction, see query-memory.ts's stage) neither is
104
+ * penalized. Never guess which side to demote from no signal.
105
+ *
106
+ * NEVER DROPS: this module only classifies relations between items already
107
+ * present in the input array — it never removes, reorders, or mutates the
108
+ * input array itself (that is query-memory.ts's stage's job, immediately
109
+ * downstream). A caller that ignores this module's output entirely gets
110
+ * back the exact same candidate set it passed in.
111
+ *
112
+ * ── HIGH-PRECISION GRAMMAR (pre-ship red-team fix, STEP 4b, 2026-09-01,
113
+ * wave/pipe-w5fix — correctness red-team, reports/2026-09-01-pipe-w5fix-
114
+ * report.md) ──
115
+ * The W5a-salvage grammar above (line ~45-46) already NAMED "step 1.2.3 vs
116
+ * step 5.6.7" as "an acknowledged, narrower residual risk, not claimed to be
117
+ * zero" — a second, independent (correctness, not security) red-team then
118
+ * PROVED that risk is much wider and actively harmful, not narrow: the
119
+ * plain `helpers/conflict-scan.ts` `extractVersionTokens` extractor's
120
+ * `(?:v|@|version\s+)?` marker is OPTIONAL, so ANY bare `N.N.N`-shaped
121
+ * digit run gets treated as a version — which false-positives on:
122
+ * - IP addresses: "at 10.0.0.1" / "at 10.0.1.5" (the first 3 octets of a
123
+ * dotted-quad ARE a valid `\d+\.\d+\.\d+` match on their own).
124
+ * - dot-formatted dates: "08.15.2026" / "08.16.2026" (MM.DD.YYYY is
125
+ * structurally IDENTICAL to a semver's `\d+\.\d+\.\d+` shape — nothing
126
+ * about the digits themselves can distinguish a date from a version).
127
+ * - dotted step/section numbers: "step 1.2.3" / "step 5.6.7".
128
+ * Combined with the ORIGINAL (pre-STEP-4a) down-rank+re-sort mechanism, a
129
+ * false-positive match like this didn't just add noise — it actively
130
+ * INVERTED ranking, demoting a correct, unrelated fact below a weaker match.
131
+ * STEP 4a (query-memory.ts's `applyContradictionStage`) already made a false
132
+ * positive here harmless (annotate-only, never reorders/rescores) — this
133
+ * fix is the SECOND, independent layer: shrink how often the false
134
+ * positive fires AT ALL, so even the harmless annotation is rare and
135
+ * meaningful rather than routinely wrong.
136
+ *
137
+ * `extractHighPrecisionVersionTokens` below is a module-scoped extractor — a
138
+ * modified copy of `extractVersionTokens`'s regex, NOT an edit to the shared
139
+ * `helpers/conflict-scan.ts` export. `extractVersionTokens` itself is
140
+ * UNCHANGED and remains exactly as permissive as before for its one
141
+ * remaining loose-grammar caller (`conflict-scan.ts`'s own `scanForConflicts`
142
+ * — the smart-remember pre-save warning flow, a soft non-mutating notice
143
+ * shown at save time, not a supersession/retraction surface), which is a
144
+ * structurally distinct consumer this fix's scope (the retrieval area) does
145
+ * not touch and whose own false-positive tolerance was never in question
146
+ * here (see this file's original header, "FIX (this file)", for why
147
+ * `contradiction.ts` choosing a narrower grammar than `conflict-scan.ts`
148
+ * offers was already the file's own precedent).
149
+ *
150
+ * v4 PRE-SHIP GATE FIX (2026-09-08, reports/2026-09-08-v4-gatefix-report.md)
151
+ * — `extractHighPrecisionVersionTokens` is now EXPORTED (it previously was
152
+ * not) and imported directly by `tools-logic/supersession.ts`'s
153
+ * `compareForConflicts`. That module's OWN plain `extractVersionTokens` use
154
+ * (the "`ar correct` CorrectionRecord flow" this section originally named as
155
+ * a second, still-loose caller) was retired by that same gate fix — a
156
+ * correctness red-team reproduced the identical generic-key false-positive
157
+ * class described above (e.g. two topically-unrelated corrections that both
158
+ * say "deployed 1.2.3"/"deployed 5.6.7" with no explicit version marker) on
159
+ * `listCorrectionConflicts`/`ar corrections conflicts`, the NEW human-facing
160
+ * surface v4 W5 added on top of `compareForConflicts`. Rather than fork a
161
+ * THIRD copy of this regex into `supersession.ts` (or re-derive a laxer one
162
+ * there), that module now imports and calls this exact function — see
163
+ * `supersession.ts`'s own header for the full status/kv removal rationale
164
+ * (citing 79fc3e2, the same precedent this file's own W5a-salvage section
165
+ * above documents) and its test suite for the FP-pair proofs. This module
166
+ * has zero imports of its own (see this file's header, "WHY THIS IS ITS OWN
167
+ * MODULE"), so `supersession.ts` (tools-logic/) importing FROM it here
168
+ * creates no import cycle.
169
+ *
170
+ * THE TIGHTENING: require an explicit version marker (`v`, `@`, `ver`,
171
+ * `version`, or `#`) IMMEDIATELY adjacent to the digits, AND reject a
172
+ * trailing 4th dot-group (`(?!\.\d)`, an IPv4-shape defense-in-depth layered
173
+ * on top of the marker requirement, in case a marker-adjacent IP ever
174
+ * occurs, e.g. "v10.0.0.1"). Neither an IP address, a plain date, nor a
175
+ * bare "step N.N.N" carries any of these markers in ordinary prose, so all
176
+ * three false-positive classes above no longer extract a token at all —
177
+ * verified empirically (node REPL, this wave's own report) against every
178
+ * named case. The real L1-C1 case ("AgentRecall version 3.5.0" / "AgentRecall
179
+ * version 3.4.41") keeps working: the word "version" IS the marker. See the
180
+ * PART E test suite (`query-memory-pipeline.test.mjs`) for the fixture-level
181
+ * proof of both the false-positive exclusions and the still-detected real
182
+ * case.
183
+ *
184
+ * ACCEPTED RECALL LOSS (code-review LOW note, 2026-09-01, not a regression —
185
+ * precision over recall is this fix's explicit brief): the `(?!\.\d)`
186
+ * IPv4-shape guard also excludes a genuine 4-COMPONENT version string (e.g.
187
+ * a Windows-style "3.5.0.1" vs "3.5.0.2") — the same lookahead cannot tell
188
+ * "this is a 4-octet IP" from "this is a 4-part semver" any more than the
189
+ * plain extractor's digits alone could tell a date from a version. AgentRecall's
190
+ * own versioning (and this stage's own worked example) is 3-part, so this is
191
+ * a narrow, acceptable trade — a missed 4-component version conflict decays
192
+ * away naturally (recency still favors the newer mention); a false-positive
193
+ * IP match would not have.
194
+ */
195
+ /**
196
+ * The minimal shape this comparator needs from a candidate — deliberately
197
+ * NOT `QueryMemoryItem` itself, so this module has zero dependency on
198
+ * query-memory.ts (avoiding the import-cycle query-memory.ts's own header
199
+ * already worries about for scope.ts, and keeping this module trivially
200
+ * unit-testable without any pipeline machinery).
201
+ */
202
+ export interface ContradictionItem {
203
+ /** Text the grammar extractors scan — callers typically pass `${title} ${excerpt}`. */
204
+ text: string;
205
+ /** Best-effort ISO date (YYYY-MM-DD). Absent/unparseable dates never
206
+ * resolve a direction on their own — see DIRECTION above. */
207
+ date?: string;
208
+ /** Append-order signal (e.g. a room file's line number). Only meaningful
209
+ * as a same-tier, same-day tie-break — see DIRECTION above. A caller that
210
+ * never wants order-based tie-breaking (this wave's journal wiring) simply
211
+ * omits it. */
212
+ order?: number;
213
+ }
214
+ export interface ContradictionResult {
215
+ /**
216
+ * index -> the OTHER indices this index's item conflicts with (grammar
217
+ * match found), REGARDLESS of whether a direction could be resolved.
218
+ * Symmetric: if `conflictsWith.get(i)` contains `j`, `conflictsWith.get(j)`
219
+ * contains `i`. This is the full annotation set — a caller uses this for
220
+ * the additive `conflictsWith` field even when no `supersededBy` could be
221
+ * determined (the ambiguous, down-rank-neither case).
222
+ */
223
+ conflictsWith: Map<number, number[]>;
224
+ /**
225
+ * index of the STALE item -> index of the item that supersedes it. Only
226
+ * populated for pairs where a direction was confidently resolved (see
227
+ * DIRECTION above). An index present here is a candidate for down-
228
+ * ranking; an index present ONLY in `conflictsWith` (never as a key here)
229
+ * must be annotated but NOT penalized — the ambiguous-tie safety
230
+ * guarantee this stage exists to prove.
231
+ *
232
+ * If more than one sibling supersedes the same stale item (3+ conflicting
233
+ * items in one tier), this keeps the MOST CURRENT superseder found (the
234
+ * one that would itself win a direct pairwise comparison against any
235
+ * earlier candidate), not simply the last one processed.
236
+ */
237
+ supersededBy: Map<number, number>;
238
+ }
239
+ /**
240
+ * High-precision version-token extractor — a NARROWER variant of
241
+ * `helpers/conflict-scan.ts`'s `extractVersionTokens` (see this file's
242
+ * header, "HIGH-PRECISION GRAMMAR", for the full false-positive analysis
243
+ * this exists to close; that shared export is intentionally left UNCHANGED
244
+ * for its one remaining loose-grammar caller). EXPORTED (v4 pre-ship gate
245
+ * fix, 2026-09-08, see this file's header addendum) so
246
+ * `tools-logic/supersession.ts` can import this exact implementation
247
+ * instead of forking a third copy — not, itself, a change in behavior.
248
+ *
249
+ * Differences from the plain extractor:
250
+ * 1. The version MARKER (`v`, `@`, `ver`, `version`, or `#`) is now
251
+ * MANDATORY, not optional — a bare `\d+\.\d+\.\d+` run with no marker
252
+ * immediately before it (an IP address, a MM.DD.YYYY date, a "step
253
+ * N.N.N" reference) extracts NOTHING. `v` and `#` attach directly to
254
+ * the digits (e.g. "v3.5.0", "#3.5.0"); `@` optionally allows
255
+ * whitespace (e.g. "pkg@3.5.0" or "pkg @ 3.5.0"); `ver`/`version` are
256
+ * whole-word-bounded (so "versioning" never matches as "ver" + "sion")
257
+ * and allow an optional trailing "." plus whitespace before the digits
258
+ * ("version 3.5.0", "ver. 3.5.0").
259
+ * 2. `(?!\.\d)` rejects a match immediately followed by a 4th
260
+ * dot-digit-group — an IPv4 defense-in-depth layered on top of (1), in
261
+ * case a marker ever directly precedes an IP-shaped run (e.g.
262
+ * "v10.0.0.1"), which (1) alone would not catch since the marker IS
263
+ * present there.
264
+ * The captured KEY (group 1: the word/token immediately preceding the
265
+ * marker) is unchanged in spirit from the plain extractor — still "whatever
266
+ * word sits before the version mention", lowercased and stripped to
267
+ * `[a-z0-9_-]` by the caller (matching `grammarConflict`'s own usage
268
+ * pattern, ported verbatim from the plain extractor's callers).
269
+ */
270
+ export declare function extractHighPrecisionVersionTokens(text: string): Map<string, string>;
271
+ /**
272
+ * Pairwise contradiction scan over one tier's candidate list. O(n²) — the
273
+ * caller (query-memory.ts) is expected to run this AFTER tokenize+score
274
+ * (so `items.length` is already bounded by `perTierLimit`, not the full
275
+ * on-disk corpus) and to skip tiers with fewer than 2 items (nothing to
276
+ * compare) or with no date signal at all (this wave: the insight tier).
277
+ *
278
+ * Never drops, never reorders, never mutates `items` — returns relations
279
+ * ONLY. The caller decides what to do with them (annotate + down-rank,
280
+ * per this wave's brief; a future caller could choose differently without
281
+ * this module changing).
282
+ */
283
+ export declare function detectContradictions(items: ContradictionItem[]): ContradictionResult;
284
+ //# sourceMappingURL=contradiction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contradiction.d.ts","sourceRoot":"","sources":["../../src/retrieval/contradiction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiMG;AAcH;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,uFAAuF;IACvF,IAAI,EAAE,MAAM,CAAC;IACb;kEAC8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;oBAGgB;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC;;;;;;;OAOG;IACH,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACrC;;;;;;;;;;;;OAYG;IACH,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AA0CD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,iCAAiC,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAWnF;AA2BD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,mBAAmB,CAmCpF"}
@@ -0,0 +1,343 @@
1
+ /**
2
+ * retrieval/contradiction.ts — the CONTRADICTION pipeline stage (Wave 5a,
3
+ * 2026-08-31, reports/2026-08-31-pipe-w5a-contradiction-report.md).
4
+ *
5
+ * ── W5a SALVAGE (2026-08-31, same date, "## W5a salvage" section of the same
6
+ * report) ── An INDEPENDENT review (separate from — and after — the W5a
7
+ * code-reviewer pass named below) passed the mechanism (down-rank+annotate+
8
+ * never-drop, the re-sort→RRF propagation) but found the token grammar's
9
+ * status/kv branches were false-positive-PRONE in a way that actively
10
+ * defeats the stage's own safety intent, not merely "wider than ideal":
11
+ * - HIGH-1 (safeguard defeat): the status branch extracts categories via
12
+ * `extractStatusTokens`, which maps "blocked"/"stuck" to the SAME
13
+ * category (both → "blocked") — so category-EQUIVALENT common phrasing
14
+ * ("status: blocked" vs "status: stuck", genuinely the same fact) should
15
+ * never conflict. It didn't, by that safeguard's own design — but the
16
+ * status branch is un-keyed (see below) and the KV branch's own separate
17
+ * "key: value" extraction treats "status" as a literal KV KEY with
18
+ * "blocked"/"stuck" as different raw VALUES, flagging a conflict the
19
+ * status-category-equivalence check was specifically built to prevent.
20
+ * Two branches reusing overlapping vocabulary defeated each other.
21
+ * - HIGH-2 (generic-key false positive): both the kv branch and (to a
22
+ * narrower degree) the version branch key off whatever single word
23
+ * immediately precedes the value — "priority: high" (a marketing
24
+ * decision) vs "priority: low" (an unrelated cleanup task) share the
25
+ * generic key `priority` and got flagged conflicting despite being
26
+ * about entirely different topics; "key match" gave no topical
27
+ * protection at all for common one-word keys.
28
+ * - HIGH-3 (invisible annotation): `supersededBy`/`conflictsWith` never
29
+ * reached `SmartRecallResultItem`/`JournalSearchResult.results` — fixed
30
+ * separately, see smart-recall.ts's `localRecallSearch` and
31
+ * journal-search.ts's `journalSearch` field-list maps.
32
+ *
33
+ * FIX (this file): restrict `grammarConflict` to `extractVersionTokens`
34
+ * ONLY — status and kv detection are REMOVED from this module entirely
35
+ * (not just gated/pre-filtered). Semver (`\d+\.\d+\.\d+`) is a much
36
+ * narrower, more self-describing pattern than a bare "word: word" or
37
+ * status-category match — a shared key + differing semver value is a
38
+ * strong, low-false-positive signal of a genuine version supersession, and
39
+ * removing the other two branches removes HIGH-1 (the category-vs-KV
40
+ * cross-branch defeat cannot happen when the KV branch does not exist) and
41
+ * the dominant real-world instance of HIGH-2 (KV keys off ANY generic
42
+ * one-word label — "priority", "status", "mode", "env" — a pattern that
43
+ * recurs constantly in prose; a version-shaped `\d+\.\d+\.\d+` collision
44
+ * between two topically-unrelated candidates is comparatively rare, though
45
+ * not literally impossible — e.g. a shared generic key like "step 1.2.3" vs
46
+ * "step 5.6.7" — an acknowledged, narrower residual risk, not claimed to be
47
+ * zero). `extractStatusTokens`/`extractKVTokens` remain exported from
48
+ * `helpers/conflict-scan.ts` and are UNCHANGED there — `conflict-scan.ts`'s
49
+ * own `scanForConflicts` (the separate smart-remember pre-save warning flow)
50
+ * still uses all three extractors; this restriction applies ONLY to this
51
+ * module's pairwise same-tier retrieval-time comparison (see the v4
52
+ * PRE-SHIP GATE FIX addendum below for why `tools-logic/supersession.ts`'s
53
+ * `compareForConflicts` — previously also a three-extractor consumer —
54
+ * no longer is one).
55
+ *
56
+ * WHY THIS IS ITS OWN MODULE, not a function inside query-memory.ts: mirrors
57
+ * `retrieval/scope.ts`'s own precedent — a small, dependency-light, pure
58
+ * comparator that query-memory.ts (this wave) consumes, and that a later
59
+ * wave's caller (e.g. a future `recallInsight()`-style direct consumer) can
60
+ * import without creating an import cycle back into query-memory.ts (which
61
+ * already imports FROM tools-logic — see scope.ts's header for the exact
62
+ * cycle this pattern avoids).
63
+ *
64
+ * WHAT THIS DOES NOT DO (scope, read the eval fixtures before extending):
65
+ * this comparator reuses ONLY `helpers/conflict-scan.ts`'s `extractVersionTokens`
66
+ * semver extractor (post-salvage — see above; status/kv were removed, not
67
+ * merely descoped from the start). It does NOT detect arbitrary
68
+ * semantic-prose contradictions ("we fully migrated OFF Postgres to
69
+ * CockroachDB" vs "we use Postgres") — confirmed empirically against the
70
+ * redteam eval fixture (reports/2026-08-18-eval-redteam.md HIGH-2) while
71
+ * resolving this wave's pre-loaded Challenge A: the version extractor
72
+ * produces no matching key with differing values for that pair at all (no
73
+ * version numbers appear in either sentence). Prose-semantic contradiction
74
+ * detection is a genuinely harder, separate problem (conflict-scan.ts's own
75
+ * header already says so) and is explicitly OUT of this wave's scope — see
76
+ * the wave report's "prose-semantic gap" follow-up section, not silently
77
+ * absorbed into this grammar.
78
+ *
79
+ * ALGORITHM: pairwise, O(n²) over one tier's already-scored item list (n is
80
+ * a per-tier result count, bounded by `perTierLimit`, never the full corpus).
81
+ * For every pair (i, j):
82
+ * 1. GRAMMAR CHECK — same key across version tokens, different semver
83
+ * value → conflict. Symmetric (order of i/j does not matter for
84
+ * whether a conflict exists, only for which side is stale — see 2).
85
+ * 2. DIRECTION — decide which side is stale, if determinable at all:
86
+ * - both items carry a `date` and the dates differ → the OLDER
87
+ * `date` is superseded by the newer one (journal's own authored-
88
+ * date semantics; this only requires "the two dates differ", so it
89
+ * applies to any date-bearing tier, not journal-specifically —
90
+ * journal simply always has a `date`, so this branch always fires
91
+ * for it unless two journal hits share the exact SAME date).
92
+ * - dates are equal, or one/both undefined, AND both items carry an
93
+ * `order` that differs → the LOWER `order` is superseded by the
94
+ * HIGHER `order` (append-order tie-break: palace's same-day-tie
95
+ * policy, per this wave's Challenge B — `order` is populated from
96
+ * the room file's LINE NUMBER for palace items only; journal items
97
+ * are deliberately NOT given an `order` value by this wave's
98
+ * query-memory.ts wiring, so a same-date journal tie falls through
99
+ * to the next bullet instead of guessing off line position, per
100
+ * the wave brief's literal instruction).
101
+ * - neither resolves → AMBIGUOUS: both sides are annotated as
102
+ * conflicting with each other, NEITHER is marked superseded, and
103
+ * (by construction, see query-memory.ts's stage) neither is
104
+ * penalized. Never guess which side to demote from no signal.
105
+ *
106
+ * NEVER DROPS: this module only classifies relations between items already
107
+ * present in the input array — it never removes, reorders, or mutates the
108
+ * input array itself (that is query-memory.ts's stage's job, immediately
109
+ * downstream). A caller that ignores this module's output entirely gets
110
+ * back the exact same candidate set it passed in.
111
+ *
112
+ * ── HIGH-PRECISION GRAMMAR (pre-ship red-team fix, STEP 4b, 2026-09-01,
113
+ * wave/pipe-w5fix — correctness red-team, reports/2026-09-01-pipe-w5fix-
114
+ * report.md) ──
115
+ * The W5a-salvage grammar above (line ~45-46) already NAMED "step 1.2.3 vs
116
+ * step 5.6.7" as "an acknowledged, narrower residual risk, not claimed to be
117
+ * zero" — a second, independent (correctness, not security) red-team then
118
+ * PROVED that risk is much wider and actively harmful, not narrow: the
119
+ * plain `helpers/conflict-scan.ts` `extractVersionTokens` extractor's
120
+ * `(?:v|@|version\s+)?` marker is OPTIONAL, so ANY bare `N.N.N`-shaped
121
+ * digit run gets treated as a version — which false-positives on:
122
+ * - IP addresses: "at 10.0.0.1" / "at 10.0.1.5" (the first 3 octets of a
123
+ * dotted-quad ARE a valid `\d+\.\d+\.\d+` match on their own).
124
+ * - dot-formatted dates: "08.15.2026" / "08.16.2026" (MM.DD.YYYY is
125
+ * structurally IDENTICAL to a semver's `\d+\.\d+\.\d+` shape — nothing
126
+ * about the digits themselves can distinguish a date from a version).
127
+ * - dotted step/section numbers: "step 1.2.3" / "step 5.6.7".
128
+ * Combined with the ORIGINAL (pre-STEP-4a) down-rank+re-sort mechanism, a
129
+ * false-positive match like this didn't just add noise — it actively
130
+ * INVERTED ranking, demoting a correct, unrelated fact below a weaker match.
131
+ * STEP 4a (query-memory.ts's `applyContradictionStage`) already made a false
132
+ * positive here harmless (annotate-only, never reorders/rescores) — this
133
+ * fix is the SECOND, independent layer: shrink how often the false
134
+ * positive fires AT ALL, so even the harmless annotation is rare and
135
+ * meaningful rather than routinely wrong.
136
+ *
137
+ * `extractHighPrecisionVersionTokens` below is a module-scoped extractor — a
138
+ * modified copy of `extractVersionTokens`'s regex, NOT an edit to the shared
139
+ * `helpers/conflict-scan.ts` export. `extractVersionTokens` itself is
140
+ * UNCHANGED and remains exactly as permissive as before for its one
141
+ * remaining loose-grammar caller (`conflict-scan.ts`'s own `scanForConflicts`
142
+ * — the smart-remember pre-save warning flow, a soft non-mutating notice
143
+ * shown at save time, not a supersession/retraction surface), which is a
144
+ * structurally distinct consumer this fix's scope (the retrieval area) does
145
+ * not touch and whose own false-positive tolerance was never in question
146
+ * here (see this file's original header, "FIX (this file)", for why
147
+ * `contradiction.ts` choosing a narrower grammar than `conflict-scan.ts`
148
+ * offers was already the file's own precedent).
149
+ *
150
+ * v4 PRE-SHIP GATE FIX (2026-09-08, reports/2026-09-08-v4-gatefix-report.md)
151
+ * — `extractHighPrecisionVersionTokens` is now EXPORTED (it previously was
152
+ * not) and imported directly by `tools-logic/supersession.ts`'s
153
+ * `compareForConflicts`. That module's OWN plain `extractVersionTokens` use
154
+ * (the "`ar correct` CorrectionRecord flow" this section originally named as
155
+ * a second, still-loose caller) was retired by that same gate fix — a
156
+ * correctness red-team reproduced the identical generic-key false-positive
157
+ * class described above (e.g. two topically-unrelated corrections that both
158
+ * say "deployed 1.2.3"/"deployed 5.6.7" with no explicit version marker) on
159
+ * `listCorrectionConflicts`/`ar corrections conflicts`, the NEW human-facing
160
+ * surface v4 W5 added on top of `compareForConflicts`. Rather than fork a
161
+ * THIRD copy of this regex into `supersession.ts` (or re-derive a laxer one
162
+ * there), that module now imports and calls this exact function — see
163
+ * `supersession.ts`'s own header for the full status/kv removal rationale
164
+ * (citing 79fc3e2, the same precedent this file's own W5a-salvage section
165
+ * above documents) and its test suite for the FP-pair proofs. This module
166
+ * has zero imports of its own (see this file's header, "WHY THIS IS ITS OWN
167
+ * MODULE"), so `supersession.ts` (tools-logic/) importing FROM it here
168
+ * creates no import cycle.
169
+ *
170
+ * THE TIGHTENING: require an explicit version marker (`v`, `@`, `ver`,
171
+ * `version`, or `#`) IMMEDIATELY adjacent to the digits, AND reject a
172
+ * trailing 4th dot-group (`(?!\.\d)`, an IPv4-shape defense-in-depth layered
173
+ * on top of the marker requirement, in case a marker-adjacent IP ever
174
+ * occurs, e.g. "v10.0.0.1"). Neither an IP address, a plain date, nor a
175
+ * bare "step N.N.N" carries any of these markers in ordinary prose, so all
176
+ * three false-positive classes above no longer extract a token at all —
177
+ * verified empirically (node REPL, this wave's own report) against every
178
+ * named case. The real L1-C1 case ("AgentRecall version 3.5.0" / "AgentRecall
179
+ * version 3.4.41") keeps working: the word "version" IS the marker. See the
180
+ * PART E test suite (`query-memory-pipeline.test.mjs`) for the fixture-level
181
+ * proof of both the false-positive exclusions and the still-detected real
182
+ * case.
183
+ *
184
+ * ACCEPTED RECALL LOSS (code-review LOW note, 2026-09-01, not a regression —
185
+ * precision over recall is this fix's explicit brief): the `(?!\.\d)`
186
+ * IPv4-shape guard also excludes a genuine 4-COMPONENT version string (e.g.
187
+ * a Windows-style "3.5.0.1" vs "3.5.0.2") — the same lookahead cannot tell
188
+ * "this is a 4-octet IP" from "this is a 4-part semver" any more than the
189
+ * plain extractor's digits alone could tell a date from a version. AgentRecall's
190
+ * own versioning (and this stage's own worked example) is 3-part, so this is
191
+ * a narrow, acceptable trade — a missed 4-component version conflict decays
192
+ * away naturally (recency still favors the newer mention); a false-positive
193
+ * IP match would not have.
194
+ */
195
+ // ---------------------------------------------------------------------------
196
+ // Grammar check — reuses conflict-scan.ts's token extractors verbatim; does
197
+ // not fork or reimplement the grammar (see this file's header).
198
+ // ---------------------------------------------------------------------------
199
+ /**
200
+ * True iff `a` and `b` share a version-extracted key with a differing semver
201
+ * value. Symmetric.
202
+ *
203
+ * W5a SALVAGE (2026-08-31): this function previously also checked
204
+ * status-category tokens and generic key-value tokens (`extractStatusTokens`/
205
+ * `extractKVTokens`) — REMOVED per an independent review's HIGH-1/HIGH-2
206
+ * findings (see this file's header for the full reasoning): the status
207
+ * branch's un-keyed, both-directions category comparison could be defeated
208
+ * by the KV branch treating the SAME words ("status: blocked" vs "status:
209
+ * stuck") as differing raw values even though the status branch's own
210
+ * category map treats them as equivalent (HIGH-1); and the KV branch's
211
+ * generic single-word key ("priority", "mode", "env", ...) gave no topical
212
+ * protection at all, flagging topically-unrelated candidates that merely
213
+ * happened to share a common label (HIGH-2). Neither branch is reinstated
214
+ * with a topical pre-filter this wave — that would be new, unscoped grammar
215
+ * behavior; the fix is to not run the two branches at all, not to patch them.
216
+ *
217
+ * STEP 4b (2026-09-01): now backed by `extractHighPrecisionVersionTokens`
218
+ * (this file, below) instead of `helpers/conflict-scan.ts`'s plain
219
+ * `extractVersionTokens` — see this file's header, "HIGH-PRECISION GRAMMAR",
220
+ * for the false-positive classes (IP addresses, dot-dates, dotted step
221
+ * numbers) this closes and why the real L1-C1 version case is unaffected.
222
+ */
223
+ function grammarConflict(a, b) {
224
+ const av = extractHighPrecisionVersionTokens(a.text);
225
+ if (av.size === 0)
226
+ return false;
227
+ const bv = extractHighPrecisionVersionTokens(b.text);
228
+ for (const [key, val] of av) {
229
+ const bval = bv.get(key);
230
+ if (bval && bval !== val)
231
+ return true;
232
+ }
233
+ return false;
234
+ }
235
+ /**
236
+ * High-precision version-token extractor — a NARROWER variant of
237
+ * `helpers/conflict-scan.ts`'s `extractVersionTokens` (see this file's
238
+ * header, "HIGH-PRECISION GRAMMAR", for the full false-positive analysis
239
+ * this exists to close; that shared export is intentionally left UNCHANGED
240
+ * for its one remaining loose-grammar caller). EXPORTED (v4 pre-ship gate
241
+ * fix, 2026-09-08, see this file's header addendum) so
242
+ * `tools-logic/supersession.ts` can import this exact implementation
243
+ * instead of forking a third copy — not, itself, a change in behavior.
244
+ *
245
+ * Differences from the plain extractor:
246
+ * 1. The version MARKER (`v`, `@`, `ver`, `version`, or `#`) is now
247
+ * MANDATORY, not optional — a bare `\d+\.\d+\.\d+` run with no marker
248
+ * immediately before it (an IP address, a MM.DD.YYYY date, a "step
249
+ * N.N.N" reference) extracts NOTHING. `v` and `#` attach directly to
250
+ * the digits (e.g. "v3.5.0", "#3.5.0"); `@` optionally allows
251
+ * whitespace (e.g. "pkg@3.5.0" or "pkg @ 3.5.0"); `ver`/`version` are
252
+ * whole-word-bounded (so "versioning" never matches as "ver" + "sion")
253
+ * and allow an optional trailing "." plus whitespace before the digits
254
+ * ("version 3.5.0", "ver. 3.5.0").
255
+ * 2. `(?!\.\d)` rejects a match immediately followed by a 4th
256
+ * dot-digit-group — an IPv4 defense-in-depth layered on top of (1), in
257
+ * case a marker ever directly precedes an IP-shaped run (e.g.
258
+ * "v10.0.0.1"), which (1) alone would not catch since the marker IS
259
+ * present there.
260
+ * The captured KEY (group 1: the word/token immediately preceding the
261
+ * marker) is unchanged in spirit from the plain extractor — still "whatever
262
+ * word sits before the version mention", lowercased and stripped to
263
+ * `[a-z0-9_-]` by the caller (matching `grammarConflict`'s own usage
264
+ * pattern, ported verbatim from the plain extractor's callers).
265
+ */
266
+ export function extractHighPrecisionVersionTokens(text) {
267
+ const result = new Map();
268
+ const pattern = /(\w[\w.-]{0,30}?)\s*(?:v(?=\d)|@\s*|\bver\b\.?\s*|\bversion\b\.?\s*|#\s*)(\d+\.\d+\.\d+)(?!\.\d)/gi;
269
+ let m;
270
+ while ((m = pattern.exec(text)) !== null) {
271
+ const key = m[1].toLowerCase().replace(/[^a-z0-9_-]/g, "");
272
+ if (key.length > 0) {
273
+ result.set(key, m[2]);
274
+ }
275
+ }
276
+ return result;
277
+ }
278
+ function resolveDirection(a, b) {
279
+ if (a.date && b.date) {
280
+ const da = Date.parse(a.date);
281
+ const db = Date.parse(b.date);
282
+ if (!isNaN(da) && !isNaN(db) && da !== db) {
283
+ return da > db ? "a-newer" : "b-newer";
284
+ }
285
+ // dates equal (same day) or unparseable — fall through to order.
286
+ }
287
+ if (a.order !== undefined && b.order !== undefined && a.order !== b.order) {
288
+ return a.order > b.order ? "a-newer" : "b-newer";
289
+ }
290
+ return "tie";
291
+ }
292
+ // ---------------------------------------------------------------------------
293
+ // Main
294
+ // ---------------------------------------------------------------------------
295
+ /**
296
+ * Pairwise contradiction scan over one tier's candidate list. O(n²) — the
297
+ * caller (query-memory.ts) is expected to run this AFTER tokenize+score
298
+ * (so `items.length` is already bounded by `perTierLimit`, not the full
299
+ * on-disk corpus) and to skip tiers with fewer than 2 items (nothing to
300
+ * compare) or with no date signal at all (this wave: the insight tier).
301
+ *
302
+ * Never drops, never reorders, never mutates `items` — returns relations
303
+ * ONLY. The caller decides what to do with them (annotate + down-rank,
304
+ * per this wave's brief; a future caller could choose differently without
305
+ * this module changing).
306
+ */
307
+ export function detectContradictions(items) {
308
+ const conflictsWith = new Map();
309
+ const supersededBy = new Map();
310
+ const addConflict = (i, j) => {
311
+ const existing = conflictsWith.get(i);
312
+ if (existing)
313
+ existing.push(j);
314
+ else
315
+ conflictsWith.set(i, [j]);
316
+ };
317
+ for (let i = 0; i < items.length; i++) {
318
+ for (let j = i + 1; j < items.length; j++) {
319
+ if (!grammarConflict(items[i], items[j]))
320
+ continue;
321
+ addConflict(i, j);
322
+ addConflict(j, i);
323
+ const dir = resolveDirection(items[i], items[j]);
324
+ if (dir === "tie")
325
+ continue; // annotate-only, never guess a direction
326
+ const staleIdx = dir === "a-newer" ? j : i;
327
+ const currentIdx = dir === "a-newer" ? i : j;
328
+ const existingSuperseder = supersededBy.get(staleIdx);
329
+ if (existingSuperseder === undefined) {
330
+ supersededBy.set(staleIdx, currentIdx);
331
+ }
332
+ else {
333
+ // Keep whichever superseder is itself more current, so a stale item
334
+ // conflicting with 3+ siblings always points at the most-current one.
335
+ const better = resolveDirection(items[currentIdx], items[existingSuperseder]);
336
+ if (better === "a-newer")
337
+ supersededBy.set(staleIdx, currentIdx);
338
+ }
339
+ }
340
+ }
341
+ return { conflictsWith, supersededBy };
342
+ }
343
+ //# sourceMappingURL=contradiction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contradiction.js","sourceRoot":"","sources":["../../src/retrieval/contradiction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiMG;AA4DH,8EAA8E;AAC9E,4EAA4E;AAC5E,gEAAgE;AAChE,8EAA8E;AAE9E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAS,eAAe,CAAC,CAAoB,EAAE,CAAoB;IACjE,MAAM,EAAE,GAAG,iCAAiC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACrD,IAAI,EAAE,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAChC,MAAM,EAAE,GAAG,iCAAiC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACrD,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,IAAI,IAAI,IAAI,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;IACxC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;A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