agent-recall-core 3.4.46 → 3.4.47

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 (95) 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 +12 -4
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +33 -4
  15. package/dist/index.js.map +1 -1
  16. package/dist/retrieval/candidates.d.ts +314 -0
  17. package/dist/retrieval/candidates.d.ts.map +1 -0
  18. package/dist/retrieval/candidates.js +321 -0
  19. package/dist/retrieval/candidates.js.map +1 -0
  20. package/dist/retrieval/contradiction.d.ts +232 -0
  21. package/dist/retrieval/contradiction.d.ts.map +1 -0
  22. package/dist/retrieval/contradiction.js +320 -0
  23. package/dist/retrieval/contradiction.js.map +1 -0
  24. package/dist/retrieval/query-memory.d.ts +419 -0
  25. package/dist/retrieval/query-memory.d.ts.map +1 -0
  26. package/dist/retrieval/query-memory.js +1068 -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 +31 -1
  33. package/dist/storage/corrections.d.ts.map +1 -1
  34. package/dist/storage/corrections.js +34 -1
  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 +25 -2
  45. package/dist/supabase/recall-backend.d.ts.map +1 -1
  46. package/dist/supabase/recall-backend.js +82 -21
  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 +159 -510
  94. package/dist/tools-logic/smart-recall.js.map +1 -1
  95. package/package.json +1 -1
@@ -0,0 +1,314 @@
1
+ /**
2
+ * retrieval/candidates.ts — Wave 1 of the shared retrieval pipeline
3
+ * (reports/2026-08-21-architecture-review.md §4, reports/2026-08-29-kickoff-plan.md §2,
4
+ * plywood SOP 58053587).
5
+ *
6
+ * THE PROBLEM THIS FILE FIXES: the journal and palace-room storage tiers each
7
+ * have MANY independent `readdir`+`readFileSync` scanners (9+ for journal,
8
+ * ~10 for palace-room content — see this file's own header comment sections
9
+ * below for the enumerated class), each deciding filtering/trust/scoping
10
+ * independently. Per the architecture review: "a directory-scanning,
11
+ * tokenizing, trust-tagging, or scoping boundary decided independently, once
12
+ * per surface, with no single place that decision has to be made correctly
13
+ * exactly once" is the actual root cause behind the L1/L2/redteam findings.
14
+ *
15
+ * THIS WAVE (1 of ~4-5): build ONE typed candidate reader per tier, with
16
+ * identity-trust tagging baked in at read time (not deferred to a caller
17
+ * that might forget it, per CRITICAL-1's "3 prior waves each missed
18
+ * same-class members" lesson). `tier` is an ENUMERATED table entry
19
+ * (`TIER_READERS` below) — adding a future tier (e.g. `"palace-pipeline"`,
20
+ * see the CHALLENGE note below) is a new ROW, never a new branch.
21
+ *
22
+ * WAVE 1 SCOPE, EXPLICIT: this module is purely ADDITIVE. Zero existing call
23
+ * site (`journalSearch`, `smartRecall`, `palaceSearch`, `resurrect`,
24
+ * `sessionStart`, etc.) is touched or imports from here yet — that migration
25
+ * is Wave 2+ (`retrieval/pipeline.ts`'s `queryMemory()`). This file only adds
26
+ * a new, unused-by-anyone-yet reader, so it carries zero behavior-change
27
+ * risk for any live surface.
28
+ *
29
+ * ── CHALLENGE outcome: does `tier` need a 3rd value for palace/pipeline? ──
30
+ * The kickoff plan invited this challenge explicitly. Verdict: NO, not this
31
+ * wave — `palace/pipeline/` (numbered `NNNN-slug.md` milestone files with
32
+ * `phase`/`order`/`status`/`opened`/`closed` frontmatter, read via
33
+ * `palace/pipeline.ts`'s `listMilestones()`/`parseMilestoneFile()`) is
34
+ * structurally a DIFFERENT shape from `palace/rooms/<slug>/*.md` (no
35
+ * `_room.json`, no `listRooms()` entry point, no salience/access-count
36
+ * metadata, a different frontmatter schema entirely) — forcing it through
37
+ * the SAME `"palace-room"` reader would be lossy, not a clean fit. It is a
38
+ * genuine sibling tier and deserves its own `"palace-pipeline"` table row in
39
+ * a later wave (architecture review P10 names this explicitly: "CONFIRM
40
+ * this explicitly, don't assume" — confirmed here: it does NOT ride in for
41
+ * free, a dedicated reader is still needed). Tier stays exactly
42
+ * `"journal" | "palace-room"` for Wave 1, matching the task's literal scope.
43
+ *
44
+ * ── W2 INDEPENDENT-REVIEW FIX (2026-08-30): the leaf-utility-vs-pipeline-
45
+ * stage anti-pattern, moved one level down ──
46
+ * `readTierCandidates` is exported (this file's header above literally tells
47
+ * a future surface to call it), but Wave 2's `queryMemory()` pipeline is the
48
+ * ONLY thing that historically applied a trust filter to its output — a
49
+ * naive caller of this function directly got raw, unfiltered rescue-tagged
50
+ * content back, reopening CRITICAL-2. Fixed by making this reader SAFE BY
51
+ * DEFAULT (`ReadTierCandidatesOpts.includeUntrusted`, default `false`, drops
52
+ * `untrusted === true` before returning) and promoting the trust predicate
53
+ * itself (`filterTrusted`, below) to a public, canonical export — the SAME
54
+ * implementation `queryMemory()`'s own trust-filter stage now delegates to,
55
+ * not a forked second copy. See retrieval/query-memory.ts's header for how
56
+ * the pipeline's own stage stays intact around this change.
57
+ */
58
+ /**
59
+ * Enumerated storage tiers `readTierCandidates` knows how to read. A future
60
+ * tier is a new value here + a new `TIER_READERS` row — never a new
61
+ * per-tier function (class-not-instance; see this file's own header).
62
+ */
63
+ export type MemoryTier = "journal" | "palace-room";
64
+ /**
65
+ * Distinguishes WHICH on-disk source produced a candidate, even within the
66
+ * same declared `tier` — e.g. a `"journal"` tier candidate can come from the
67
+ * live/rollup-archive journal directory (safe-by-default, always included)
68
+ * or from the raw hook-archive verbatim tier (opt-in only, historically
69
+ * gated behind smart-recall's explicit low-confidence "archive" source —
70
+ * see `journalDirs()`'s own doc comment in storage/paths.ts for the
71
+ * "accidental 4th journal source" incident this distinction preserves).
72
+ */
73
+ export type CandidateSourceKind = "journal-live" | "journal-rollup-archive" | "journal-archive-raw" | "palace-room";
74
+ /**
75
+ * The typed unit every future retrieval surface will consume. Trust and
76
+ * provenance are properties OF the candidate, computed once here — never
77
+ * re-derived per surface (architecture review §4.1: "trust, staleness, and
78
+ * scope become properties of the type, checked once by the pipeline").
79
+ */
80
+ export interface MemoryCandidate {
81
+ /** Raw file content (or, for a raw-archive candidate, the raw transcript dump). Never pre-scrubbed/truncated here — that is a rendering-boundary concern for a later stage, not the fetch stage. */
82
+ content: string;
83
+ /** Which enumerated tier this candidate was read from. */
84
+ tier: MemoryTier;
85
+ /** Project slug this candidate belongs to (assumed already resolved by the caller — this function does not call resolveProject). */
86
+ project: string;
87
+ /**
88
+ * Best-effort ISO date (YYYY-MM-DD) for this candidate. **Semantics differ
89
+ * by `tier` — this is NOT one consistent notion of "date" across the
90
+ * type**, and a future consumer that compares/sorts across tiers must not
91
+ * assume otherwise (independent review fix, 2026-08-29, plywood SOP
92
+ * 58053587 — flagged as under-documented at the type level, only present
93
+ * inline per-reader before this fix):
94
+ *
95
+ * - `tier: "journal"` — the FILENAME's date prefix (`YYYY-MM-DD--...`,
96
+ * or the leading `YYYY-MM-DD` match on an archive filename). This is the
97
+ * date the entry was AUTHORED/FILED, fixed at write time, independent of
98
+ * any later edit.
99
+ * - `tier: "palace-room"` — the file's `mtime` (falling back to
100
+ * `RoomMeta.updated` if `stat()` fails), because room files carry no
101
+ * per-file authored-date of their own (rooms are living documents that
102
+ * get appended/edited in place — see `countRoomEntries`'s own
103
+ * per-entry-not-per-file granularity note in `palace/rooms.ts`). This is
104
+ * the date the file was LAST MODIFIED, which can drift forward every
105
+ * time an entry is added to an existing room file — the opposite
106
+ * stability property from the journal tier's fixed filename date.
107
+ *
108
+ * Empty string when undeterminable for either tier.
109
+ */
110
+ date: string;
111
+ /** Absolute filesystem path this candidate was read from — the provenance field every caller needs for backlink resolution, dedup, or audit. */
112
+ sourcePath: string;
113
+ /** Basename of `sourcePath`. */
114
+ file: string;
115
+ /** Finer-grained provenance within `tier` — see `CandidateSourceKind`. */
116
+ sourceKind: CandidateSourceKind;
117
+ /**
118
+ * True when this candidate's content carries the rescue-quarantine
119
+ * provenance tag (`helpers/journal-filter.ts`'s `isRescueSourcedContent` —
120
+ * an unauthenticated, self-claimed `cwd` majority-vote rather than a
121
+ * verified identity signal). Computed HERE, inside the reader, so every
122
+ * future consumer of `readTierCandidates` inherits trust-tiering for
123
+ * free — this is the whole point of Wave 1 folding trust-tagging into the
124
+ * same commit as the reader rather than deferring it (CRITICAL-1's "3
125
+ * prior waves each missed same-class members" failure pattern).
126
+ */
127
+ untrusted: boolean;
128
+ /**
129
+ * The RAW frontmatter `source:` value this candidate's content carries
130
+ * (e.g. `"hook-end"`, `"working-memory-rescue"`), via
131
+ * `helpers/journal-filter.ts`'s `extractFrontmatterSource` — the same
132
+ * value `untrusted` above is derived FROM (`isRescueSourceTag(sourceTag)`),
133
+ * kept alongside it rather than reduced away.
134
+ *
135
+ * Independent review fix (2026-08-29, plywood SOP 58053587): `untrusted`
136
+ * answers one cheap binary question ("is this rescue-sourced") and every
137
+ * existing/near-term consumer should keep using it for that. `sourceTag`
138
+ * preserves the full provenance string so a LATER wave's finer
139
+ * trust/supersession stage (e.g. distinguishing multiple non-rescue
140
+ * `source` values, or a future tag this file's author hasn't invented yet)
141
+ * can branch on it WITHOUT re-parsing frontmatter per surface — exactly
142
+ * the anti-pattern (independent re-parsing at each retrieval surface)
143
+ * this whole module exists to kill. `undefined` when the candidate has no
144
+ * frontmatter block, or no `source:` field within it (e.g. a legacy file
145
+ * predating the frontmatter convention) — the SAME "absent" case
146
+ * `isRescueSourceTag(undefined)` already treats as `false`/trusted, so
147
+ * `untrusted` and `sourceTag` never disagree about a missing tag.
148
+ */
149
+ sourceTag?: string;
150
+ /**
151
+ * Forward-compatible bag for already-parsed frontmatter fields a LATER
152
+ * wave's score stage will consume instead of re-parsing frontmatter per
153
+ * surface (independent review fix, 2026-08-29, plywood SOP 58053587 —
154
+ * the kickoff plan named a `scoreInputs` field this shipped type omitted;
155
+ * CHALLENGED and resolved as `meta`, see this file's own PR report for the
156
+ * full reasoning). Deliberately a `Record<string,string>` bag, not a typed
157
+ * struct with named fields (`tag`/`salience`/…): Wave 1's reader parses
158
+ * NOTHING from frontmatter beyond `source` (already surfaced via
159
+ * `sourceTag` above) — it has no basis to invent a schema for fields it
160
+ * doesn't read, and a fixed struct would force this wave to guess Wave 2's
161
+ * scoring inputs rather than let Wave 2 add fields incrementally without
162
+ * changing `MemoryCandidate`'s shape each time. THE READER'S JOB IS FETCH,
163
+ * NOT SCORING: this field exists so a future frontmatter-field addition
164
+ * has somewhere to land without re-opening this type — it is NOT a place
165
+ * to pre-compute scores, salience, or ranking signals. Left `undefined`
166
+ * on every candidate this wave (no call site below sets it) — a real,
167
+ * documented "possibly-empty-now" placeholder, not a silently-broken
168
+ * promise.
169
+ */
170
+ meta?: Record<string, string>;
171
+ /** Room slug — present only for `tier: "palace-room"` candidates. */
172
+ room?: string;
173
+ }
174
+ /** Options narrowing/widening what `readTierCandidates` reads within a tier. */
175
+ export interface ReadTierCandidatesOpts {
176
+ /**
177
+ * journal tier only. When true, also includes `journal/archive/*.md`
178
+ * (rollup-archived entries) — matches `journalDirs(project, true)` /
179
+ * `listJournalFiles(project, true)`'s existing `includeArchive` semantics.
180
+ * Default false (matches `journalDirs`'s own safety default: counting
181
+ * paths must not be inflated by archived entries).
182
+ */
183
+ includeRollupArchive?: boolean;
184
+ /**
185
+ * journal tier only. When true, ALSO includes `journal/archive/raw/*.md`
186
+ * (the lossless, unstructured hook-archive verbatim tier) as
187
+ * `sourceKind: "journal-archive-raw"` candidates. This is the tier
188
+ * `journalDirs()`'s own doc comment says must NEVER be silently folded in
189
+ * — "any caller that intentionally wants raw/ content should use
190
+ * archiveRawDir(project) directly". Default false, preserving that
191
+ * safety property: a caller must opt in explicitly to see raw-archive
192
+ * candidates, same as every existing consumer of this tier does today
193
+ * (resurrect.ts Source 2, smart-recall.ts's archiveSearch fallback).
194
+ */
195
+ includeRawArchive?: boolean;
196
+ /**
197
+ * palace-room tier only. When set, restricts to a single room slug
198
+ * (matches `palaceSearch`'s `input.room` filter). Omit to read every
199
+ * room.
200
+ */
201
+ room?: string;
202
+ /**
203
+ * Independent review fix (W2, 2026-08-30, reports/2026-08-29-pipe-w2-query-report.md):
204
+ * `readTierCandidates` is a PUBLIC, exported function — a future surface
205
+ * author calling it directly (as this file's own header instructs future
206
+ * Wave 3+ migrations to do) got raw candidates back with `untrusted` as a
207
+ * mere FIELD, no filtering applied, reopening the exact CRITICAL-2
208
+ * rescue-quarantine injection gap this whole retrieval-pipeline effort
209
+ * exists to close — just one function further down than `queryMemory()`.
210
+ *
211
+ * Default `false` (the safe, naive-caller default): every candidate whose
212
+ * `untrusted` flag is exactly `true` is dropped via `filterTrusted` BEFORE
213
+ * this function returns. A candidate with `untrusted === undefined` is
214
+ * treated as trusted (kept) — `filterTrusted` only drops `=== true`, never
215
+ * "anything not explicitly false". A candidate that carries a `sourceTag`
216
+ * but is NOT untrusted is UNAFFECTED — `sourceTag` is a down-tier/
217
+ * attribution axis, never a drop axis; dropping those would lose genuine,
218
+ * merely-attributed content.
219
+ *
220
+ * Set `true` only when the caller has its own reason to see untrusted
221
+ * candidates and will apply its own trust decision afterward — e.g.
222
+ * `queryMemory()`'s own mandatory TRUST-FILTER pipeline stage (see
223
+ * retrieval/query-memory.ts), which calls this with `includeUntrusted:
224
+ * true` and then explicitly re-applies `filterTrusted` itself as a
225
+ * separate, still-mandatory stage — preserving both "no bypassable
226
+ * stage" AND this reader's own safe-by-default boundary.
227
+ */
228
+ includeUntrusted?: boolean;
229
+ }
230
+ /**
231
+ * Canonical trust-filter: drops every candidate whose `untrusted` flag is
232
+ * exactly `true`. A candidate with `untrusted === undefined` (never actually
233
+ * produced by `readTierCandidates`'s own readers today, which always set a
234
+ * boolean, but defensive for any future non-reader-produced MemoryCandidate)
235
+ * is treated as trusted and kept — only a literal `true` drops.
236
+ *
237
+ * THE single implementation both `readTierCandidates`'s own safe-by-default
238
+ * filtering AND `queryMemory()`'s mandatory TRUST-FILTER pipeline stage
239
+ * delegate to (independent review fix, W2, 2026-08-30) — do not fork a
240
+ * second copy of this predicate.
241
+ */
242
+ export declare function filterTrusted(candidates: MemoryCandidate[]): MemoryCandidate[];
243
+ /**
244
+ * A quarantine-safe VIEW of a candidate: existence (date/file/sourcePath)
245
+ * plus a `trusted` flag, WITHOUT ever exposing `content` for a candidate
246
+ * whose `untrusted` flag is `true`.
247
+ *
248
+ * P0 independent-review fix (FIX 1, 2026-08-30, wave/pipe-p0-trustclass):
249
+ * `journal-list.ts::journalList` needed to show a rescue-tagged entry EXISTS
250
+ * (at its real, non-attacker-controlled date — see `listCandidateStubs`'s own
251
+ * caller for why the date field itself is safe to surface) while never
252
+ * surfacing its title/momentum (which ARE derived from raw body text, the
253
+ * actual injection vector). Dropping the row outright hides existence for no
254
+ * security reason and silently shifts a `limit`-bounded window's contents
255
+ * (see journal-list.ts's own header comment); showing the raw `content` for
256
+ * a quarantined row would reopen exactly the surfacing gap this file exists
257
+ * to close. This helper is the sanctioned middle ground.
258
+ *
259
+ * NOT a raw exposure: `content` is populated ONLY when `untrusted !== true`.
260
+ * It deliberately does NOT go through `readTierCandidates`'s own
261
+ * `includeUntrusted` opt-in (that flag is reserved, by a workspace-wide
262
+ * completeness-harness guard, for `retrieval/query-memory.ts`'s own
263
+ * mandatory trust-filter stage — see this file's `ReadTierCandidatesOpts.
264
+ * includeUntrusted` doc comment) — instead it calls the SAME underlying
265
+ * `TIER_READERS[tier]` reader `readTierCandidates` itself calls, and applies
266
+ * its OWN content-stripping decision immediately, inline, before returning.
267
+ */
268
+ export interface CandidateStub {
269
+ /** See `MemoryCandidate.date`'s own doc comment for tier-dependent semantics. */
270
+ date: string;
271
+ file: string;
272
+ sourcePath: string;
273
+ /** `true` iff the underlying candidate's `untrusted` flag is NOT `true` (mirrors `filterTrusted`'s own predicate). */
274
+ trusted: boolean;
275
+ /**
276
+ * The candidate's raw content — present if and ONLY IF `trusted` is
277
+ * `true`. A quarantined (untrusted) row NEVER carries this field, by
278
+ * construction (see this interface's own header) — never merely "the
279
+ * caller shouldn't read it".
280
+ */
281
+ content?: string;
282
+ }
283
+ /**
284
+ * Read every candidate for one tier, reduced to the quarantine-safe
285
+ * `CandidateStub` shape: existence (date/file/sourcePath) is preserved for
286
+ * EVERY candidate, trusted or not, but `content` is stripped for any
287
+ * candidate whose `untrusted` flag is `true`. See `CandidateStub`'s own doc
288
+ * comment for the full rationale (FIX 1, P0 independent-review fix,
289
+ * 2026-08-30).
290
+ *
291
+ * Ordering is preserved from the underlying tier reader (the SAME ordering
292
+ * `readTierCandidates` itself would return for the same `tier`/`opts`) — a
293
+ * caller that needs a `limit`-bounded window must slice AFTER mapping this
294
+ * function's full output, never before, so a quarantined row's real
295
+ * position is never silently skipped past (see journal-list.ts's own
296
+ * header comment for the "silent backfill" bug this ordering guarantee
297
+ * closes).
298
+ */
299
+ export declare function listCandidateStubs(tier: MemoryTier, project: string, opts?: ReadTierCandidatesOpts): CandidateStub[];
300
+ /**
301
+ * Read every candidate for one tier of one project, with identity-trust
302
+ * tagging (`untrusted`) already computed. This is the SOLE function future
303
+ * retrieval surfaces should call instead of touching `journalDirs()`/
304
+ * `listRooms()`/raw `readdirSync` directly (Wave 2+ migration).
305
+ *
306
+ * SAFE BY DEFAULT (independent review fix, W2, 2026-08-30): unless
307
+ * `opts.includeUntrusted` is `true`, every `untrusted === true` candidate is
308
+ * dropped here, before returning — see `ReadTierCandidatesOpts.includeUntrusted`'s
309
+ * own doc comment for the full reasoning. A direct caller that never learns
310
+ * about `untrusted` at all still gets trusted-only content, closing the
311
+ * public escape hatch around `queryMemory()`'s own trust-filter stage.
312
+ */
313
+ export declare function readTierCandidates(tier: MemoryTier, project: string, opts?: ReadTierCandidatesOpts): MemoryCandidate[];
314
+ //# sourceMappingURL=candidates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"candidates.d.ts","sourceRoot":"","sources":["../../src/retrieval/candidates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AASH;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,aAAa,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,MAAM,mBAAmB,GAC3B,cAAc,GACd,wBAAwB,GACxB,qBAAqB,GACrB,aAAa,CAAC;AAElB;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,oMAAoM;IACpM,OAAO,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,I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eG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,sBAA2B,GAChC,aAAa,EAAE,CAYjB;AAwMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,sBAA2B,GAChC,eAAe,EAAE,CAGnB"}
@@ -0,0 +1,321 @@
1
+ /**
2
+ * retrieval/candidates.ts — Wave 1 of the shared retrieval pipeline
3
+ * (reports/2026-08-21-architecture-review.md §4, reports/2026-08-29-kickoff-plan.md §2,
4
+ * plywood SOP 58053587).
5
+ *
6
+ * THE PROBLEM THIS FILE FIXES: the journal and palace-room storage tiers each
7
+ * have MANY independent `readdir`+`readFileSync` scanners (9+ for journal,
8
+ * ~10 for palace-room content — see this file's own header comment sections
9
+ * below for the enumerated class), each deciding filtering/trust/scoping
10
+ * independently. Per the architecture review: "a directory-scanning,
11
+ * tokenizing, trust-tagging, or scoping boundary decided independently, once
12
+ * per surface, with no single place that decision has to be made correctly
13
+ * exactly once" is the actual root cause behind the L1/L2/redteam findings.
14
+ *
15
+ * THIS WAVE (1 of ~4-5): build ONE typed candidate reader per tier, with
16
+ * identity-trust tagging baked in at read time (not deferred to a caller
17
+ * that might forget it, per CRITICAL-1's "3 prior waves each missed
18
+ * same-class members" lesson). `tier` is an ENUMERATED table entry
19
+ * (`TIER_READERS` below) — adding a future tier (e.g. `"palace-pipeline"`,
20
+ * see the CHALLENGE note below) is a new ROW, never a new branch.
21
+ *
22
+ * WAVE 1 SCOPE, EXPLICIT: this module is purely ADDITIVE. Zero existing call
23
+ * site (`journalSearch`, `smartRecall`, `palaceSearch`, `resurrect`,
24
+ * `sessionStart`, etc.) is touched or imports from here yet — that migration
25
+ * is Wave 2+ (`retrieval/pipeline.ts`'s `queryMemory()`). This file only adds
26
+ * a new, unused-by-anyone-yet reader, so it carries zero behavior-change
27
+ * risk for any live surface.
28
+ *
29
+ * ── CHALLENGE outcome: does `tier` need a 3rd value for palace/pipeline? ──
30
+ * The kickoff plan invited this challenge explicitly. Verdict: NO, not this
31
+ * wave — `palace/pipeline/` (numbered `NNNN-slug.md` milestone files with
32
+ * `phase`/`order`/`status`/`opened`/`closed` frontmatter, read via
33
+ * `palace/pipeline.ts`'s `listMilestones()`/`parseMilestoneFile()`) is
34
+ * structurally a DIFFERENT shape from `palace/rooms/<slug>/*.md` (no
35
+ * `_room.json`, no `listRooms()` entry point, no salience/access-count
36
+ * metadata, a different frontmatter schema entirely) — forcing it through
37
+ * the SAME `"palace-room"` reader would be lossy, not a clean fit. It is a
38
+ * genuine sibling tier and deserves its own `"palace-pipeline"` table row in
39
+ * a later wave (architecture review P10 names this explicitly: "CONFIRM
40
+ * this explicitly, don't assume" — confirmed here: it does NOT ride in for
41
+ * free, a dedicated reader is still needed). Tier stays exactly
42
+ * `"journal" | "palace-room"` for Wave 1, matching the task's literal scope.
43
+ *
44
+ * ── W2 INDEPENDENT-REVIEW FIX (2026-08-30): the leaf-utility-vs-pipeline-
45
+ * stage anti-pattern, moved one level down ──
46
+ * `readTierCandidates` is exported (this file's header above literally tells
47
+ * a future surface to call it), but Wave 2's `queryMemory()` pipeline is the
48
+ * ONLY thing that historically applied a trust filter to its output — a
49
+ * naive caller of this function directly got raw, unfiltered rescue-tagged
50
+ * content back, reopening CRITICAL-2. Fixed by making this reader SAFE BY
51
+ * DEFAULT (`ReadTierCandidatesOpts.includeUntrusted`, default `false`, drops
52
+ * `untrusted === true` before returning) and promoting the trust predicate
53
+ * itself (`filterTrusted`, below) to a public, canonical export — the SAME
54
+ * implementation `queryMemory()`'s own trust-filter stage now delegates to,
55
+ * not a forked second copy. See retrieval/query-memory.ts's header for how
56
+ * the pipeline's own stage stays intact around this change.
57
+ */
58
+ import * as fs from "node:fs";
59
+ import * as path from "node:path";
60
+ import { journalDir, archiveRawDir, palaceDir } from "../storage/paths.js";
61
+ import { listJournalFiles } from "../helpers/journal-files.js";
62
+ import { isRescueSourcedContent, extractFrontmatterSource } from "../helpers/journal-filter.js";
63
+ import { listRooms } from "../palace/rooms.js";
64
+ /**
65
+ * Canonical trust-filter: drops every candidate whose `untrusted` flag is
66
+ * exactly `true`. A candidate with `untrusted === undefined` (never actually
67
+ * produced by `readTierCandidates`'s own readers today, which always set a
68
+ * boolean, but defensive for any future non-reader-produced MemoryCandidate)
69
+ * is treated as trusted and kept — only a literal `true` drops.
70
+ *
71
+ * THE single implementation both `readTierCandidates`'s own safe-by-default
72
+ * filtering AND `queryMemory()`'s mandatory TRUST-FILTER pipeline stage
73
+ * delegate to (independent review fix, W2, 2026-08-30) — do not fork a
74
+ * second copy of this predicate.
75
+ */
76
+ export function filterTrusted(candidates) {
77
+ return candidates.filter((c) => c.untrusted !== true);
78
+ }
79
+ /**
80
+ * Read every candidate for one tier, reduced to the quarantine-safe
81
+ * `CandidateStub` shape: existence (date/file/sourcePath) is preserved for
82
+ * EVERY candidate, trusted or not, but `content` is stripped for any
83
+ * candidate whose `untrusted` flag is `true`. See `CandidateStub`'s own doc
84
+ * comment for the full rationale (FIX 1, P0 independent-review fix,
85
+ * 2026-08-30).
86
+ *
87
+ * Ordering is preserved from the underlying tier reader (the SAME ordering
88
+ * `readTierCandidates` itself would return for the same `tier`/`opts`) — a
89
+ * caller that needs a `limit`-bounded window must slice AFTER mapping this
90
+ * function's full output, never before, so a quarantined row's real
91
+ * position is never silently skipped past (see journal-list.ts's own
92
+ * header comment for the "silent backfill" bug this ordering guarantee
93
+ * closes).
94
+ */
95
+ export function listCandidateStubs(tier, project, opts = {}) {
96
+ const candidates = TIER_READERS[tier](project, opts);
97
+ return candidates.map((c) => {
98
+ const trusted = c.untrusted !== true;
99
+ return {
100
+ date: c.date,
101
+ file: c.file,
102
+ sourcePath: c.sourcePath,
103
+ trusted,
104
+ content: trusted ? c.content : undefined,
105
+ };
106
+ });
107
+ }
108
+ function safeReadFile(p) {
109
+ try {
110
+ return fs.readFileSync(p, "utf-8");
111
+ }
112
+ catch {
113
+ return null; // unreadable/missing file — never throw, caller skips it
114
+ }
115
+ }
116
+ /**
117
+ * journal tier — consolidates the ~5 independent journal-archive-raw
118
+ * scanners (resurrect.ts Source 2, smart-recall.ts's archiveSearch,
119
+ * session-end-reflect.ts's collectRawUnconsumed, store-doctor.ts ×2
120
+ * filename-only scans) with `helpers/journal-files.ts`'s existing
121
+ * `listJournalFiles()` as the live/rollup-archive half (per the kickoff
122
+ * plan's "fold in listJournalFiles() as the live-file half"). See this
123
+ * module's own PR report for the full scanner enumeration table.
124
+ */
125
+ function readJournalCandidates(project, opts) {
126
+ const out = [];
127
+ const primaryDir = journalDir(project);
128
+ // ---- live half (delegates to the existing shared reader) ----
129
+ // Deliberately called with includeArchive=false here — see the rollup-
130
+ // archive half below for why archive/ is scanned independently rather
131
+ // than via listJournalFiles(project, true).
132
+ const entries = listJournalFiles(project, false);
133
+ for (const entry of entries) {
134
+ const sourcePath = path.join(entry.dir, entry.file);
135
+ const content = safeReadFile(sourcePath);
136
+ if (content === null)
137
+ continue;
138
+ out.push({
139
+ content,
140
+ tier: "journal",
141
+ project,
142
+ date: entry.date,
143
+ sourcePath,
144
+ file: entry.file,
145
+ sourceKind: "journal-live",
146
+ untrusted: isRescueSourcedContent(content),
147
+ sourceTag: extractFrontmatterSource(content),
148
+ });
149
+ }
150
+ // ---- opt-in rollup-archive half ----
151
+ // NOT delegated to listJournalFiles(project, true): that path requires a
152
+ // leading YYYY-MM-DD date match on every filename (its `dateMatch` guard),
153
+ // which silently drops a week-summary-shaped file (`YYYY-Wnn.md`) living
154
+ // in archive/ — exactly the shape journal-search.test.mjs's own fixture
155
+ // uses and journal-search.ts's independent raw scan (readdirSync +
156
+ // f.endsWith(".md"), NO date-match requirement) correctly picks up. This
157
+ // divergence was found empirically while proving behavioral equivalence
158
+ // (retrieval-candidates.test.mjs) — listJournalFiles() and journal-search.ts
159
+ // are NOT strictly equivalent for archive/ content today. Scanning archive/
160
+ // independently here, matching journal-search.ts's broader (no-date-match)
161
+ // filter, is what makes this reader an honest superset of BOTH existing
162
+ // scanners rather than silently inheriting the narrower one's gap.
163
+ if (opts.includeRollupArchive) {
164
+ const archiveDir = path.join(primaryDir, "archive");
165
+ let archiveFiles = [];
166
+ try {
167
+ archiveFiles = fs.readdirSync(archiveDir).filter((f) => f.endsWith(".md"));
168
+ }
169
+ catch {
170
+ archiveFiles = []; // missing/unreadable archive dir — treat as empty, never throw
171
+ }
172
+ // Independent review fix (MEDIUM-1, W2, 2026-08-30): build this half into
173
+ // its own array and sort it date-descending BEFORE appending to `out` —
174
+ // same pattern the live half above already gets for free from
175
+ // `listJournalFiles()`'s own `entries.sort((a,b) => b.date.localeCompare(a.date))`.
176
+ // Without this, `archiveFiles` is in raw `readdirSync` enumeration order
177
+ // (filesystem-dependent, not date order), so a downstream consumer that
178
+ // truncates before fully consuming this half (e.g. query-memory.ts's
179
+ // `scoreJournalTier` perTierLimit break) would keep an arbitrary
180
+ // enumeration-order subset instead of the newest archived entries — the
181
+ // exact "sort-before-truncate" bug class this fix closes for the archive
182
+ // half, matching what the live half already had.
183
+ const archiveCandidates = [];
184
+ for (const file of archiveFiles) {
185
+ const sourcePath = path.join(archiveDir, file);
186
+ const content = safeReadFile(sourcePath);
187
+ if (content === null)
188
+ continue;
189
+ const dateMatch = file.match(/^(\d{4}-\d{2}-\d{2})/);
190
+ archiveCandidates.push({
191
+ content,
192
+ tier: "journal",
193
+ project,
194
+ date: dateMatch ? dateMatch[1] : "",
195
+ sourcePath,
196
+ file,
197
+ sourceKind: "journal-rollup-archive",
198
+ untrusted: isRescueSourcedContent(content),
199
+ sourceTag: extractFrontmatterSource(content),
200
+ });
201
+ }
202
+ archiveCandidates.sort((a, b) => b.date.localeCompare(a.date));
203
+ out.push(...archiveCandidates);
204
+ }
205
+ // ---- opt-in raw-archive half (the previously-unconsolidated 5 scanners) ----
206
+ if (opts.includeRawArchive) {
207
+ const dir = archiveRawDir(project);
208
+ let files = [];
209
+ try {
210
+ files = fs.readdirSync(dir).filter((f) => f.endsWith(".md") && f !== "index.md");
211
+ }
212
+ catch {
213
+ files = []; // missing/unreadable raw-archive dir — treat as empty, never throw
214
+ }
215
+ for (const file of files) {
216
+ const sourcePath = path.join(dir, file);
217
+ const content = safeReadFile(sourcePath);
218
+ if (content === null)
219
+ continue;
220
+ const dateMatch = file.match(/^(\d{4}-\d{2}-\d{2})/);
221
+ out.push({
222
+ content,
223
+ tier: "journal",
224
+ project,
225
+ date: dateMatch ? dateMatch[1] : "",
226
+ sourcePath,
227
+ file,
228
+ sourceKind: "journal-archive-raw",
229
+ untrusted: isRescueSourcedContent(content),
230
+ sourceTag: extractFrontmatterSource(content),
231
+ });
232
+ }
233
+ }
234
+ return out;
235
+ }
236
+ /**
237
+ * palace-room tier — net-new; no existing function to copy (`palace/rooms.ts`
238
+ * exports metadata only: `listRooms`/`getRoomMeta`/`countRoomEntries`, no
239
+ * content reader). Matches the INCLUSIVE behavior most existing scanners
240
+ * agree on (README.md counts as real room content — countRoomEntries's own
241
+ * doc comment: "both README.md's '## Memories' section and any topic
242
+ * files"): palace-search.ts, palace-walk.ts's readRoomContent,
243
+ * journal-search.ts's include_palace branch, and session-start.ts's
244
+ * autoBackfill all include README.md. A minority (palace-lint.ts, check.ts's
245
+ * alignment-room scanner, palace/fan-out.ts's auto-link keyword scan)
246
+ * exclude README.md/_room.json for their own narrower, non-retrieval
247
+ * purposes (linting the topic files only; keyword-linking heuristics) — see
248
+ * this module's own PR report for the full scanner enumeration table and
249
+ * why those are narrower special-purpose scans, not full content readers.
250
+ */
251
+ function readPalaceRoomCandidates(project, opts) {
252
+ const out = [];
253
+ const pd = palaceDir(project);
254
+ const allRooms = listRooms(project);
255
+ const rooms = opts.room ? allRooms.filter((r) => r.slug === opts.room) : allRooms;
256
+ for (const roomMeta of rooms) {
257
+ const roomPath = path.join(pd, "rooms", roomMeta.slug);
258
+ let files = [];
259
+ try {
260
+ if (!fs.existsSync(roomPath))
261
+ continue;
262
+ files = fs.readdirSync(roomPath).filter((f) => f.endsWith(".md"));
263
+ }
264
+ catch {
265
+ continue; // unreadable room dir — skip, never throw
266
+ }
267
+ for (const file of files) {
268
+ const sourcePath = path.join(roomPath, file);
269
+ const content = safeReadFile(sourcePath);
270
+ if (content === null)
271
+ continue;
272
+ let date = "";
273
+ try {
274
+ date = fs.statSync(sourcePath).mtime.toISOString().slice(0, 10);
275
+ }
276
+ catch {
277
+ date = (roomMeta.updated ?? "").slice(0, 10);
278
+ }
279
+ out.push({
280
+ content,
281
+ tier: "palace-room",
282
+ project,
283
+ date,
284
+ sourcePath,
285
+ file,
286
+ sourceKind: "palace-room",
287
+ untrusted: isRescueSourcedContent(content),
288
+ sourceTag: extractFrontmatterSource(content),
289
+ room: roomMeta.slug,
290
+ });
291
+ }
292
+ }
293
+ return out;
294
+ }
295
+ /**
296
+ * Class-not-instance table: one row per enumerated tier. Extending coverage
297
+ * (a future `"palace-pipeline"` tier, see this file's header CHALLENGE note)
298
+ * is a new row here, never a new branch in `readTierCandidates` itself.
299
+ */
300
+ const TIER_READERS = {
301
+ journal: readJournalCandidates,
302
+ "palace-room": readPalaceRoomCandidates,
303
+ };
304
+ /**
305
+ * Read every candidate for one tier of one project, with identity-trust
306
+ * tagging (`untrusted`) already computed. This is the SOLE function future
307
+ * retrieval surfaces should call instead of touching `journalDirs()`/
308
+ * `listRooms()`/raw `readdirSync` directly (Wave 2+ migration).
309
+ *
310
+ * SAFE BY DEFAULT (independent review fix, W2, 2026-08-30): unless
311
+ * `opts.includeUntrusted` is `true`, every `untrusted === true` candidate is
312
+ * dropped here, before returning — see `ReadTierCandidatesOpts.includeUntrusted`'s
313
+ * own doc comment for the full reasoning. A direct caller that never learns
314
+ * about `untrusted` at all still gets trusted-only content, closing the
315
+ * public escape hatch around `queryMemory()`'s own trust-filter stage.
316
+ */
317
+ export function readTierCandidates(tier, project, opts = {}) {
318
+ const candidates = TIER_READERS[tier](project, opts);
319
+ return opts.includeUntrusted ? candidates : filterTrusted(candidates);
320
+ }
321
+ //# sourceMappingURL=candidates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"candidates.js","sourceRoot":"","sources":["../../src/retrieval/candidates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAsL/C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,UAA6B;IACzD,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC;AACxD,CAAC;AA2CD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAgB,EAChB,OAAe,EACf,OAA+B,EAAE;IAEjC,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACrD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QAC1B,MAAM,OAAO,GAAG,CAAC,CAAC,SAAS,KAAK,IAAI,CAAC;QACrC,OAAO;YACL,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,UAAU,EAAE,CAAC,CAAC,UAAU;YACxB,OAAO;YACP,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,C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