agent-recall-core 3.4.47 → 3.4.49

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 (221) hide show
  1. package/README.md +25 -0
  2. package/dist/digest/store.d.ts +15 -6
  3. package/dist/digest/store.d.ts.map +1 -1
  4. package/dist/digest/store.js +33 -20
  5. package/dist/digest/store.js.map +1 -1
  6. package/dist/embeddings/chunker.d.ts +102 -0
  7. package/dist/embeddings/chunker.d.ts.map +1 -0
  8. package/dist/embeddings/chunker.js +260 -0
  9. package/dist/embeddings/chunker.js.map +1 -0
  10. package/dist/embeddings/config.d.ts +93 -0
  11. package/dist/embeddings/config.d.ts.map +1 -0
  12. package/dist/embeddings/config.js +174 -0
  13. package/dist/embeddings/config.js.map +1 -0
  14. package/dist/embeddings/index-store.d.ts +61 -0
  15. package/dist/embeddings/index-store.d.ts.map +1 -0
  16. package/dist/embeddings/index-store.js +158 -0
  17. package/dist/embeddings/index-store.js.map +1 -0
  18. package/dist/embeddings/indexer.d.ts +75 -0
  19. package/dist/embeddings/indexer.d.ts.map +1 -0
  20. package/dist/embeddings/indexer.js +196 -0
  21. package/dist/embeddings/indexer.js.map +1 -0
  22. package/dist/embeddings/runtime.d.ts +66 -0
  23. package/dist/embeddings/runtime.d.ts.map +1 -0
  24. package/dist/embeddings/runtime.js +197 -0
  25. package/dist/embeddings/runtime.js.map +1 -0
  26. package/dist/helpers/associative-link.d.ts.map +1 -1
  27. package/dist/helpers/associative-link.js +26 -1
  28. package/dist/helpers/associative-link.js.map +1 -1
  29. package/dist/helpers/tokenize.d.ts +1 -0
  30. package/dist/helpers/tokenize.d.ts.map +1 -1
  31. package/dist/helpers/tokenize.js +18 -0
  32. package/dist/helpers/tokenize.js.map +1 -1
  33. package/dist/index.d.ts +27 -10
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +50 -6
  36. package/dist/index.js.map +1 -1
  37. package/dist/palace/awareness.d.ts +34 -10
  38. package/dist/palace/awareness.d.ts.map +1 -1
  39. package/dist/palace/awareness.js +249 -180
  40. package/dist/palace/awareness.js.map +1 -1
  41. package/dist/palace/consolidate.d.ts +1 -1
  42. package/dist/palace/consolidate.d.ts.map +1 -1
  43. package/dist/palace/consolidate.js +9 -9
  44. package/dist/palace/consolidate.js.map +1 -1
  45. package/dist/palace/decay-pass.d.ts +1 -1
  46. package/dist/palace/decay-pass.d.ts.map +1 -1
  47. package/dist/palace/decay-pass.js +2 -2
  48. package/dist/palace/decay-pass.js.map +1 -1
  49. package/dist/palace/fan-out.d.ts +1 -1
  50. package/dist/palace/fan-out.d.ts.map +1 -1
  51. package/dist/palace/fan-out.js +5 -5
  52. package/dist/palace/fan-out.js.map +1 -1
  53. package/dist/palace/index-manager.d.ts +1 -1
  54. package/dist/palace/index-manager.d.ts.map +1 -1
  55. package/dist/palace/index-manager.js +1 -1
  56. package/dist/palace/index-manager.js.map +1 -1
  57. package/dist/palace/insights-index.d.ts +19 -6
  58. package/dist/palace/insights-index.d.ts.map +1 -1
  59. package/dist/palace/insights-index.js +36 -13
  60. package/dist/palace/insights-index.js.map +1 -1
  61. package/dist/palace/keystone.d.ts +1 -1
  62. package/dist/palace/keystone.d.ts.map +1 -1
  63. package/dist/palace/keystone.js +2 -2
  64. package/dist/palace/keystone.js.map +1 -1
  65. package/dist/palace/rooms.d.ts +3 -3
  66. package/dist/palace/rooms.d.ts.map +1 -1
  67. package/dist/palace/rooms.js +34 -6
  68. package/dist/palace/rooms.js.map +1 -1
  69. package/dist/retrieval/candidates.d.ts +27 -2
  70. package/dist/retrieval/candidates.d.ts.map +1 -1
  71. package/dist/retrieval/candidates.js +170 -3
  72. package/dist/retrieval/candidates.js.map +1 -1
  73. package/dist/retrieval/contradiction.d.ts +65 -13
  74. package/dist/retrieval/contradiction.d.ts.map +1 -1
  75. package/dist/retrieval/contradiction.js +40 -17
  76. package/dist/retrieval/contradiction.js.map +1 -1
  77. package/dist/retrieval/query-memory.d.ts +112 -9
  78. package/dist/retrieval/query-memory.d.ts.map +1 -1
  79. package/dist/retrieval/query-memory.js +623 -62
  80. package/dist/retrieval/query-memory.js.map +1 -1
  81. package/dist/retrieval/semantic-leg.d.ts +74 -0
  82. package/dist/retrieval/semantic-leg.d.ts.map +1 -0
  83. package/dist/retrieval/semantic-leg.js +180 -0
  84. package/dist/retrieval/semantic-leg.js.map +1 -0
  85. package/dist/storage/archive-write.d.ts.map +1 -1
  86. package/dist/storage/archive-write.js +29 -8
  87. package/dist/storage/archive-write.js.map +1 -1
  88. package/dist/storage/capture-router.d.ts +1 -1
  89. package/dist/storage/capture-router.d.ts.map +1 -1
  90. package/dist/storage/capture-router.js +26 -9
  91. package/dist/storage/capture-router.js.map +1 -1
  92. package/dist/storage/consolidation-queue.d.ts +11 -2
  93. package/dist/storage/consolidation-queue.d.ts.map +1 -1
  94. package/dist/storage/consolidation-queue.js +45 -16
  95. package/dist/storage/consolidation-queue.js.map +1 -1
  96. package/dist/storage/corrections.d.ts +185 -6
  97. package/dist/storage/corrections.d.ts.map +1 -1
  98. package/dist/storage/corrections.js +525 -126
  99. package/dist/storage/corrections.js.map +1 -1
  100. package/dist/storage/durable-intent.d.ts.map +1 -1
  101. package/dist/storage/durable-intent.js +24 -1
  102. package/dist/storage/durable-intent.js.map +1 -1
  103. package/dist/storage/filelock.d.ts +84 -12
  104. package/dist/storage/filelock.d.ts.map +1 -1
  105. package/dist/storage/filelock.js +309 -47
  106. package/dist/storage/filelock.js.map +1 -1
  107. package/dist/storage/fs-utils.d.ts +20 -0
  108. package/dist/storage/fs-utils.d.ts.map +1 -1
  109. package/dist/storage/fs-utils.js +27 -0
  110. package/dist/storage/fs-utils.js.map +1 -1
  111. package/dist/storage/paths.d.ts +34 -0
  112. package/dist/storage/paths.d.ts.map +1 -1
  113. package/dist/storage/paths.js +71 -0
  114. package/dist/storage/paths.js.map +1 -1
  115. package/dist/storage/pending.d.ts +154 -0
  116. package/dist/storage/pending.d.ts.map +1 -0
  117. package/dist/storage/pending.js +454 -0
  118. package/dist/storage/pending.js.map +1 -0
  119. package/dist/storage/project.d.ts.map +1 -1
  120. package/dist/storage/project.js +68 -16
  121. package/dist/storage/project.js.map +1 -1
  122. package/dist/storage/session-card.d.ts +13 -0
  123. package/dist/storage/session-card.d.ts.map +1 -1
  124. package/dist/storage/session-card.js +34 -3
  125. package/dist/storage/session-card.js.map +1 -1
  126. package/dist/storage/unclaimed.d.ts +165 -0
  127. package/dist/storage/unclaimed.d.ts.map +1 -0
  128. package/dist/storage/unclaimed.js +442 -0
  129. package/dist/storage/unclaimed.js.map +1 -0
  130. package/dist/storage/working-memory.d.ts.map +1 -1
  131. package/dist/storage/working-memory.js +19 -1
  132. package/dist/storage/working-memory.js.map +1 -1
  133. package/dist/supabase/recall-backend.d.ts +29 -2
  134. package/dist/supabase/recall-backend.d.ts.map +1 -1
  135. package/dist/supabase/recall-backend.js +231 -29
  136. package/dist/supabase/recall-backend.js.map +1 -1
  137. package/dist/supabase/sync.d.ts.map +1 -1
  138. package/dist/supabase/sync.js +13 -0
  139. package/dist/supabase/sync.js.map +1 -1
  140. package/dist/tools-logic/alignment-check.js +1 -1
  141. package/dist/tools-logic/alignment-check.js.map +1 -1
  142. package/dist/tools-logic/awareness-update.d.ts.map +1 -1
  143. package/dist/tools-logic/awareness-update.js +25 -16
  144. package/dist/tools-logic/awareness-update.js.map +1 -1
  145. package/dist/tools-logic/check-action.js +1 -1
  146. package/dist/tools-logic/check-action.js.map +1 -1
  147. package/dist/tools-logic/check.d.ts +55 -1
  148. package/dist/tools-logic/check.d.ts.map +1 -1
  149. package/dist/tools-logic/check.js +230 -57
  150. package/dist/tools-logic/check.js.map +1 -1
  151. package/dist/tools-logic/confidence.d.ts +11 -6
  152. package/dist/tools-logic/confidence.d.ts.map +1 -1
  153. package/dist/tools-logic/confidence.js +11 -6
  154. package/dist/tools-logic/confidence.js.map +1 -1
  155. package/dist/tools-logic/context-synthesize.js +2 -2
  156. package/dist/tools-logic/context-synthesize.js.map +1 -1
  157. package/dist/tools-logic/digest-read.js +2 -2
  158. package/dist/tools-logic/digest-read.js.map +1 -1
  159. package/dist/tools-logic/digest-recall.js +1 -1
  160. package/dist/tools-logic/digest-recall.js.map +1 -1
  161. package/dist/tools-logic/insight-promotion.d.ts +1 -1
  162. package/dist/tools-logic/insight-promotion.d.ts.map +1 -1
  163. package/dist/tools-logic/insight-promotion.js +17 -6
  164. package/dist/tools-logic/insight-promotion.js.map +1 -1
  165. package/dist/tools-logic/journal-capture.js +3 -3
  166. package/dist/tools-logic/journal-capture.js.map +1 -1
  167. package/dist/tools-logic/journal-write.js +3 -3
  168. package/dist/tools-logic/journal-write.js.map +1 -1
  169. package/dist/tools-logic/knowledge-write.js +2 -2
  170. package/dist/tools-logic/knowledge-write.js.map +1 -1
  171. package/dist/tools-logic/palace-lint.js +1 -1
  172. package/dist/tools-logic/palace-lint.js.map +1 -1
  173. package/dist/tools-logic/palace-read.js +1 -1
  174. package/dist/tools-logic/palace-read.js.map +1 -1
  175. package/dist/tools-logic/palace-search.js +1 -1
  176. package/dist/tools-logic/palace-search.js.map +1 -1
  177. package/dist/tools-logic/palace-walk.js +3 -3
  178. package/dist/tools-logic/palace-walk.js.map +1 -1
  179. package/dist/tools-logic/palace-write.js +4 -4
  180. package/dist/tools-logic/palace-write.js.map +1 -1
  181. package/dist/tools-logic/predict-correction.js +1 -1
  182. package/dist/tools-logic/predict-correction.js.map +1 -1
  183. package/dist/tools-logic/recall-backend.d.ts +11 -2
  184. package/dist/tools-logic/recall-backend.d.ts.map +1 -1
  185. package/dist/tools-logic/recall-backend.js +2 -2
  186. package/dist/tools-logic/recall-backend.js.map +1 -1
  187. package/dist/tools-logic/resurrect.d.ts.map +1 -1
  188. package/dist/tools-logic/resurrect.js +9 -1
  189. package/dist/tools-logic/resurrect.js.map +1 -1
  190. package/dist/tools-logic/safety-consolidation.d.ts.map +1 -1
  191. package/dist/tools-logic/safety-consolidation.js +32 -30
  192. package/dist/tools-logic/safety-consolidation.js.map +1 -1
  193. package/dist/tools-logic/session-end.d.ts +8 -0
  194. package/dist/tools-logic/session-end.d.ts.map +1 -1
  195. package/dist/tools-logic/session-end.js +51 -13
  196. package/dist/tools-logic/session-end.js.map +1 -1
  197. package/dist/tools-logic/session-start.d.ts +23 -0
  198. package/dist/tools-logic/session-start.d.ts.map +1 -1
  199. package/dist/tools-logic/session-start.js +44 -1
  200. package/dist/tools-logic/session-start.js.map +1 -1
  201. package/dist/tools-logic/smart-recall.d.ts +185 -10
  202. package/dist/tools-logic/smart-recall.d.ts.map +1 -1
  203. package/dist/tools-logic/smart-recall.js +364 -60
  204. package/dist/tools-logic/smart-recall.js.map +1 -1
  205. package/dist/tools-logic/store-doctor.d.ts.map +1 -1
  206. package/dist/tools-logic/store-doctor.js +7 -4
  207. package/dist/tools-logic/store-doctor.js.map +1 -1
  208. package/dist/tools-logic/store-repair.js +1 -1
  209. package/dist/tools-logic/store-repair.js.map +1 -1
  210. package/dist/tools-logic/supersession.d.ts +64 -3
  211. package/dist/tools-logic/supersession.d.ts.map +1 -1
  212. package/dist/tools-logic/supersession.js +155 -50
  213. package/dist/tools-logic/supersession.js.map +1 -1
  214. package/dist/types.d.ts +12 -1
  215. package/dist/types.d.ts.map +1 -1
  216. package/dist/types.js +1 -1
  217. package/dist/vector/embedding.d.ts +8 -0
  218. package/dist/vector/embedding.d.ts.map +1 -1
  219. package/dist/vector/embedding.js +8 -0
  220. package/dist/vector/embedding.js.map +1 -1
  221. package/package.json +1 -1
@@ -106,7 +106,7 @@
106
106
  import * as fs from "node:fs";
107
107
  import * as path from "node:path";
108
108
  import { getRoot } from "../types.js";
109
- import { ensureDir } from "../storage/fs-utils.js";
109
+ import { ensureDir, writeTextAtomic } from "../storage/fs-utils.js";
110
110
  import { expandQuery } from "../helpers/normalize.js";
111
111
  import { tokenizeWords } from "../helpers/tokenize.js";
112
112
  import { getConnectedRooms } from "../palace/graph.js";
@@ -114,6 +114,7 @@ import { palaceDir } from "../storage/paths.js";
114
114
  import { calibratedConfidence, CONFIDENCE_FLOOR } from "./confidence.js";
115
115
  import { fetchVerbatim } from "./drill-down.js";
116
116
  import { resolveProject } from "../storage/project.js";
117
+ import { withLock, LockContentionError } from "../storage/filelock.js";
117
118
  import { queryMemory, queryArchiveFallback } from "../retrieval/query-memory.js";
118
119
  /** Compute both the human label and the stored calibrated value for a score. */
119
120
  function label(score, scale) {
@@ -154,23 +155,46 @@ function readFeedbackLog() {
154
155
  return [];
155
156
  }
156
157
  }
157
- function processFeedback(feedback, query) {
158
+ async function processFeedback(feedback, query) {
158
159
  ensureDir(path.dirname(feedbackLogPath()));
159
- const log = readFeedbackLog();
160
- const date = new Date().toISOString().slice(0, 10);
161
- for (const f of feedback) {
162
- // Only deduplicate when a stable ID is present. Without an ID there's no
163
- // reliable key, so always log the entry (allows accumulation across calls).
164
- const isDuplicate = f.id
165
- ? log.some((existing) => existing.query === query && existing.id === f.id && existing.date === date)
166
- : false;
167
- if (!isDuplicate) {
168
- log.push({ query, id: f.id, title: f.title ?? "", useful: f.useful, date });
160
+ try {
161
+ // fix6-locks: the read→push→write span runs as ONE locked critical section.
162
+ // feedback-log.json is GLOBAL and written by every live session that
163
+ // submits recall feedback — the old unlocked read-modify-write dropped
164
+ // concurrent sessions' entries (feedback-log-concurrency.test.mjs
165
+ // reproduced 46/120 lost on main HEAD).
166
+ return await withLock("feedback-log", () => {
167
+ const log = readFeedbackLog();
168
+ const date = new Date().toISOString().slice(0, 10);
169
+ for (const f of feedback) {
170
+ // Only deduplicate when a stable ID is present. Without an ID there's no
171
+ // reliable key, so always log the entry (allows accumulation across calls).
172
+ const isDuplicate = f.id
173
+ ? log.some((existing) => existing.query === query && existing.id === f.id && existing.date === date)
174
+ : false;
175
+ if (!isDuplicate) {
176
+ log.push({ query, id: f.id, title: f.title ?? "", useful: f.useful, date });
177
+ }
178
+ }
179
+ const updated = log.slice(-1000);
180
+ // Atomic: readers (readFeedbackLog in every smartRecall call) are
181
+ // lock-free — never let them observe a truncated file.
182
+ writeTextAtomic(feedbackLogPath(), JSON.stringify(updated, null, 2));
183
+ return { log: updated, persistenceSkipped: false };
184
+ });
185
+ }
186
+ catch (err) {
187
+ if (err instanceof LockContentionError) {
188
+ // Advisory ranking data: never fail (or stall) a recall because the
189
+ // feedback log is contended past the timeout — log the skip explicitly
190
+ // and rank with the current on-disk log. The entries are lost, loudly:
191
+ // stderr for the host log AND persistenceSkipped for the caller
192
+ // (surfaced as SmartRecallResult.feedback_log_skipped — review LOW-3).
193
+ console.error(`[agent-recall] smart_recall feedback: ${err.message} — this call's feedback entries were NOT persisted.`);
194
+ return { log: readFeedbackLog(), persistenceSkipped: true };
169
195
  }
196
+ throw err;
170
197
  }
171
- const updated = log.slice(-1000);
172
- fs.writeFileSync(feedbackLogPath(), JSON.stringify(updated, null, 2), "utf-8");
173
- return updated;
174
198
  }
175
199
  /** Count positive and negative feedback for a result item. Query-aware. */
176
200
  function getFeedbackCounts(id, title, queryWords, log) {
@@ -228,7 +252,7 @@ function verbatimKeyFor(item) {
228
252
  * side-channel contract are UNCHANGED, since those are real, direct external
229
253
  * callers, not just smartRecall()'s own internals.
230
254
  */
231
- export async function localRecallSearch(query, project, limit, since) {
255
+ export async function localRecallSearch(query, project, limit, since, freshnessBias) {
232
256
  let resolvedProject;
233
257
  try {
234
258
  resolvedProject = await resolveProject(project);
@@ -239,14 +263,38 @@ export async function localRecallSearch(query, project, limit, since) {
239
263
  const result = await queryMemory({
240
264
  query,
241
265
  project: resolvedProject,
242
- // Order matters: RRF/fuseCanonical's "primary/display source" is
243
- // whichever source's items were inserted into the fusion map FIRST (Map
244
- // iteration = insertion order). The ORIGINAL localRecallSearch queried
245
- // palace, then journal, then insight — this order must be preserved
246
- // exactly (audit-retrieval-accounting.test.mjs asserts on it directly).
247
- tiers: ["palace", "journal", "insight"],
266
+ // Order matters TWICE: (a) RRF/fuseCanonical's "primary/display source"
267
+ // is whichever source's items were inserted into the fusion map FIRST
268
+ // (Map iteration = insertion order), and (b) the final fused sort is
269
+ // stable, so EXACT fused-score ties resolve in insertion order too.
270
+ // The ORIGINAL localRecallSearch queried palace, then journal, then
271
+ // insight — that relative order is preserved exactly
272
+ // (audit-retrieval-accounting.test.mjs asserts on it directly).
273
+ // fix4 S1 (2026-09-11) added "corrections" as the 4th competing tier;
274
+ // the v4 W3 shim (`excludeCorrectionsSource`) that guarded this exact
275
+ // wiring was retired in the same change that widened
276
+ // `SmartRecallResultItem.source`'s contract — the ordering its doc
277
+ // comment mandated ("update the contract first").
278
+ // fix4 S1-refinement (same day): corrections moved FIRST. With
279
+ // one-doc-one-vote scoring, single-source fused scores cluster at
280
+ // exactly 1/(60+rank), so cross-tier ties are the COMMON case — and a
281
+ // last-place insertion order systematically ranked the OWNER'S OWN
282
+ // CAPTURED RULE below every same-evidence derivative mention of it
283
+ // (palace notes, journal transcript lines). Authority order matches the
284
+ // product's existing doctrine (session_start P0 always-load, check()'s
285
+ // authoritative-override gate): at equal rank evidence, ground truth
286
+ // wins the tie. Fusion SCORES are order-independent (applyRRF sums per
287
+ // tier); only tie-break order and duplicate display-source change.
288
+ tiers: ["corrections", "palace", "journal", "insight"],
248
289
  limit,
249
290
  since,
291
+ // fix4 S4-completion: on THIS competitive surface one journal
292
+ // (date, section) gets one slot — see QueryMemoryInput.journal's own
293
+ // doc comment; journalSearch's per-line contract is unaffected.
294
+ journal: { perSectionDedupe: true },
295
+ // fix4b (2026-09-12): legacy boost opt-in, default OFF — see
296
+ // SmartRecallInput.freshnessBias.
297
+ ...(freshnessBias ? { freshnessBias: true } : {}),
250
298
  });
251
299
  // Final materialization: rrf-local confidence label (matches the ORIGINAL
252
300
  // dedup loop's `...label(score, "rrf-local")` — the only labeling that
@@ -257,7 +305,9 @@ export async function localRecallSearch(query, project, limit, since) {
257
305
  const deduped = result.items.map((item) => ({
258
306
  id: item.id,
259
307
  source: item.source,
260
- ...(item.alsoFoundIn && item.alsoFoundIn.length > 0 ? { alsoFoundIn: item.alsoFoundIn } : {}),
308
+ ...(item.alsoFoundIn && item.alsoFoundIn.length > 0
309
+ ? { alsoFoundIn: item.alsoFoundIn }
310
+ : {}),
261
311
  title: item.title,
262
312
  excerpt: item.excerpt,
263
313
  score: item.score,
@@ -272,8 +322,20 @@ export async function localRecallSearch(query, project, limit, since) {
272
322
  // though they had already, invisibly, changed this item's `score`/rank.
273
323
  ...(item.supersededBy ? { supersededBy: item.supersededBy } : {}),
274
324
  ...(item.conflictsWith && item.conflictsWith.length > 0 ? { conflictsWith: item.conflictsWith } : {}),
325
+ // fix7: semantic-origin marker (see SmartRecallResultItem.foundBySemantic).
326
+ ...(item.semantic ? { foundBySemantic: true } : {}),
275
327
  }));
276
- // Graph walk — surface 1-hop linked memories not already in results.
328
+ // Graph walk — fix4 S2 (2026-09-11): the 1-hop graph signal is now
329
+ // METADATA on its parent result (`alsoLinked` on the top hit), never a
330
+ // competing result row. The old form pushed synthetic "↳ linked: <room>"
331
+ // stub items at 0.6× the top score, which the global re-sort landed at
332
+ // ranks 2-4 — the S2-standard golden eval measured them burning 24/100
333
+ // top-5 slots (a pure precision loss: a stub carries no retrievable
334
+ // content, no verbatimKey, no excerpt beyond a template line). The graph
335
+ // SIGNAL is preserved verbatim — same source (getConnectedRooms on the
336
+ // top result's room), same 2-room cap — an agent that wants the linked
337
+ // rooms' content follows up with a room-scoped query, exactly what it had
338
+ // to do with the stub rows anyway.
277
339
  // Uses the RESOLVED project (a characterized fix over the original, which
278
340
  // used the raw, possibly-unresolved `project` parameter here — a latent
279
341
  // H1-class inconsistency for the "auto"-literal edge case; every existing
@@ -281,25 +343,36 @@ export async function localRecallSearch(query, project, limit, since) {
281
343
  // difference for the common case and a strict improvement otherwise).
282
344
  if (deduped.length > 0 && resolvedProject) {
283
345
  const pd = palaceDir(resolvedProject);
284
- const resultIds = new Set(deduped.map((r) => r.id));
285
346
  const topRoom = deduped[0].room;
286
347
  if (topRoom) {
287
- const linked = getConnectedRooms(pd, topRoom);
288
- for (const linkedRoom of linked.slice(0, 2)) {
289
- if (!resultIds.has(linkedRoom)) {
290
- // Graph-walk items have NO verbatimKey → skipped by the bridge by design.
291
- const linkedScore = deduped[0].score * 0.6;
292
- deduped.push({
293
- id: linkedRoom,
294
- source: "palace",
295
- title: `↳ linked: ${linkedRoom}`,
296
- excerpt: `Connected to ${topRoom} via memory graph`,
297
- score: linkedScore,
298
- ...label(linkedScore, "rrf-local"),
299
- room: linkedRoom,
300
- });
301
- resultIds.add(linkedRoom);
348
+ // Rooms already visible among the substantive results carry their own
349
+ // slot — advertising them again as a link is redundant. (The OLD stub
350
+ // code's `resultIds.has(linkedRoom)` check compared room slugs against
351
+ // stableId hashes and so never excluded anything but its own earlier
352
+ // stubs; matching on the items' real `room` field is the check that
353
+ // comment always described.)
354
+ const visibleRooms = new Set(deduped.map((r) => r.room).filter(Boolean));
355
+ const linked = getConnectedRooms(pd, topRoom)
356
+ .filter((room) => !visibleRooms.has(room))
357
+ // Review M2-adjacent fix (2026-09-11): graph edge targets are not
358
+ // always room slugs — linkToSimilar historically minted edges to
359
+ // journal/correction item IDS (its `candidate.room ? room/id : id`
360
+ // target shape), and getConnectedRooms's `split("/")[0]` hands the
361
+ // bare id back as a pseudo-room. The old stub rows advertised those
362
+ // hashes verbatim ("↳ linked: k3f9a2"); alsoLinked only names
363
+ // targets that are REAL rooms on disk (_room.json exists — the same
364
+ // existence notion listRooms uses).
365
+ .filter((room) => {
366
+ try {
367
+ return fs.existsSync(path.join(pd, "rooms", room, "_room.json"));
368
+ }
369
+ catch {
370
+ return false;
302
371
  }
372
+ })
373
+ .slice(0, 2);
374
+ if (linked.length > 0) {
375
+ deduped[0] = { ...deduped[0], alsoLinked: linked };
303
376
  }
304
377
  }
305
378
  }
@@ -310,8 +383,15 @@ export async function localRecallSearch(query, project, limit, since) {
310
383
  palace: result.candidatesBySource.palace ?? 0,
311
384
  journal: result.candidatesBySource.journal ?? 0,
312
385
  insight: result.candidatesBySource.insight ?? 0,
386
+ corrections: result.candidatesBySource.corrections ?? 0,
313
387
  };
314
388
  deduped[RAW_CANDIDATE_COUNTS] = rawCandidateCounts;
389
+ // fix7: semantic-leg diagnostics ride the same hidden-side-channel pattern
390
+ // (invisible to JSON/Object.keys — flag-off arrays carry NO new symbol
391
+ // because queryMemory only sets semanticLeg under the opt-in).
392
+ if (result.semanticLeg) {
393
+ deduped[SEMANTIC_LEG_NOTE] = result.semanticLeg;
394
+ }
315
395
  return deduped;
316
396
  }
317
397
  /**
@@ -322,11 +402,28 @@ export async function localRecallSearch(query, project, limit, since) {
322
402
  * existing tests and recall-backend.ts depend on that exact shape).
323
403
  */
324
404
  const RAW_CANDIDATE_COUNTS = Symbol("rawCandidateCounts");
405
+ /**
406
+ * fix7: second hidden side channel — the semantic-leg note (set by
407
+ * localRecallSearch ONLY when queryMemory ran under the embeddings opt-in),
408
+ * surfaced by smartRecall() as `SmartRecallResult.semantic_leg`. Same
409
+ * pattern and rationale as RAW_CANDIDATE_COUNTS immediately above.
410
+ */
411
+ const SEMANTIC_LEG_NOTE = Symbol("semanticLegNote");
325
412
  /**
326
413
  * Budget for the semantic (remote) backend in ms.
327
- * Overridable via AGENT_RECALL_RECALL_BUDGET_MS for tuning / tests.
414
+ * Overridable via AGENT_RECALL_RECALL_BUDGET_MS for tuning / tests. Read
415
+ * PER-CALL, not cached at module load — this used to be a module-level
416
+ * `const` (frozen at first import), which silently made a per-test env-var
417
+ * override a no-op whenever the module had already been imported earlier in
418
+ * the same process (caught by independent code review, build #24,
419
+ * 2026-09-09 — the exact hazard `fusionEnabled()` below was already written
420
+ * to avoid for its own env var; this constant just hadn't been swept yet).
421
+ * `parseInt` on every call is negligible cost against an already-async
422
+ * network race.
328
423
  */
329
- const RECALL_BUDGET_MS = parseInt(process.env.AGENT_RECALL_RECALL_BUDGET_MS ?? "2500", 10);
424
+ function recallBudgetMs() {
425
+ return parseInt(process.env.AGENT_RECALL_RECALL_BUDGET_MS ?? "2500", 10);
426
+ }
330
427
  /**
331
428
  * Wrap a promise with a wall-clock timeout.
332
429
  * Resolves to null (never throws) when the deadline passes.
@@ -337,6 +434,168 @@ function withTimeout(promise, ms) {
337
434
  promise.then((value) => { clearTimeout(timer); resolve(value); }, () => { clearTimeout(timer); resolve(null); });
338
435
  });
339
436
  }
437
+ // ---------------------------------------------------------------------------
438
+ // Remote+local fusion (#24, 2026-09-09) — feature-flagged.
439
+ // ---------------------------------------------------------------------------
440
+ /**
441
+ * Kill-switch / enable-switch for remote+local fusion. Mirrors
442
+ * `recallBudgetMs()`'s own `AGENT_RECALL_RECALL_BUDGET_MS` env convention —
443
+ * read PER-CALL, not cached, for the identical reason: this flag's own
444
+ * equivalence test (flag OFF ⇒ byte-identical to pre-wave) and dedup tests
445
+ * (flag ON) both need to toggle it within the SAME test file/process.
446
+ */
447
+ function fusionEnabled() {
448
+ return process.env.AGENT_RECALL_RECALL_FUSION === "1";
449
+ }
450
+ /** RRF constant for the local<->remote merge below — same constant every
451
+ * other RRF pass in this codebase uses (query-memory.ts's `RRF_K`,
452
+ * supabase/recall-backend.ts's `RRF_K`). */
453
+ const FUSION_RRF_K = 60;
454
+ /** Normalize an excerpt for identity comparison — BYTE-IDENTICAL to
455
+ * query-memory.ts's `normalizeExcerpt` and supabase/recall-backend.ts's own
456
+ * inline dedup key (`item.excerpt.toLowerCase().replace(/\s+/g, " ").trim()`)
457
+ * — the SAME normalization every existing RRF/dedup pass in this codebase
458
+ * already uses, not a fourth reinvention. */
459
+ function normalizeExcerptForFusion(excerpt) {
460
+ return excerpt.toLowerCase().replace(/\s+/g, " ").trim();
461
+ }
462
+ /**
463
+ * Cross-origin fusion identity for one item. Prefers a `deriveSlug()`-shaped
464
+ * identity (EXACT — collapses a local item and a remote item that are
465
+ * genuinely the same on-disk file) and falls back to normalized-excerpt
466
+ * identity (the same fallback every existing RRF/dedup pass in this codebase
467
+ * already uses) when no slug-comparable identity can be produced:
468
+ *
469
+ * - Remote-origin items: `item.slug` is already populated verbatim by
470
+ * `supabase/recall-backend.ts`'s `mapSemanticRows`/`mapFtsRows` (INC1
471
+ * enrichment) — used directly.
472
+ * - Local-origin PALACE items: reconstructed from `verbatimKey.room`/
473
+ * `.file` — `palace--${room}--${file}`, matching `sync.ts`'s
474
+ * `deriveSlug()` output EXACTLY, since both derive from the same
475
+ * underlying room/file-basename pair for the same on-disk file.
476
+ * - INSIGHT items (either origin): `ar_insights.title` is UNIQUE at the DB
477
+ * level (migration.sql) and the LOCAL insight tier mints its own item id
478
+ * via `stableId("insight", i.title)` (query-memory.ts's
479
+ * `scoreInsightTier`) — `title` is therefore a genuinely precise,
480
+ * cross-origin-stable identity for this tier on BOTH sides, unlike its
481
+ * `excerpt` (`[${severity}] ${applies_when...}` locally, `[${severity}]
482
+ * confirmed ${n}x` remotely — exactly the low-entropy shape this file's
483
+ * own header (Fix 5b) already documents as UNSAFE as a fusion identity:
484
+ * two DIFFERENT insights sharing a severity + confirmation-count would
485
+ * falsely collapse under excerpt identity). Used in preference to the
486
+ * excerpt fallback below.
487
+ * - Every other local-origin item (journal, archive, graph-walk): CANNOT
488
+ * reconstruct an exact slug. Journal in particular carries only the bare
489
+ * authored `date` (`YYYY-MM-DD`), not the slug-suffixed filename
490
+ * `deriveSlug()` needs (`journal--${date}-${suffix}`) — two DIFFERENT
491
+ * journal entries from the same day would collapse under a date-only
492
+ * identity, a FALSE dedup that is worse than missing a true one. These
493
+ * fall back to normalized-excerpt identity instead.
494
+ */
495
+ function fusionIdentity(item) {
496
+ if (item.slug)
497
+ return item.slug;
498
+ if (item.source === "palace" && item.verbatimKey?.kind === "palace" && item.verbatimKey.room && item.verbatimKey.file) {
499
+ return `palace--${item.verbatimKey.room}--${item.verbatimKey.file}`;
500
+ }
501
+ if (item.source === "insight" && item.title) {
502
+ return `insight::${item.title.toLowerCase().trim()}`;
503
+ }
504
+ return normalizeExcerptForFusion(item.excerpt);
505
+ }
506
+ /**
507
+ * remote-fusion wave #24 (2026-09-09) — rank-based RRF fusion of the local
508
+ * keyword-search results and the remote (Supabase) semantic-search results.
509
+ *
510
+ * THE BUG THIS FIXES: today, `smartRecall()`'s remote path is
511
+ * `results = remoteResults.length > 0 ? remoteResults : localResults` — the
512
+ * moment the remote backend answers with ANY non-empty result set, the ENTIRE
513
+ * local result set is discarded, even a genuine local-only hit the remote
514
+ * backend simply missed (e.g. a very recent journal entry not yet
515
+ * embedded/synced to Supabase — sync is fire-and-forget, see `sync.ts`'s
516
+ * `syncToSupabase()`). This function merges instead of replacing.
517
+ *
518
+ * RANK-BASED, NEVER RAW-SCORE (see this file's header, Fix 1, and
519
+ * confidence.ts's own header for the bug class this avoids): local's native
520
+ * score scale (~0..0.12, a 3-tier internal RRF) and remote's (~0..0.049, a
521
+ * 3-leg internal RRF, itself already re-labeled through a THIRD "cosine"/
522
+ * "rrf-supabase" scale) are mutually incompatible — summing them directly
523
+ * would let one origin systematically dominate, exactly the
524
+ * cross-source-raw-score-averaging bug this codebase has already fixed once.
525
+ * So neither list's `.score` is read here — only each item's RANK (its
526
+ * position within its OWN already-sorted list) feeds the RRF contribution
527
+ * `1/(FUSION_RRF_K+rank)`, the identical formula `query-memory.ts`'s
528
+ * `applyRRF` uses one layer down (there: fusing TIERS; here: fusing
529
+ * BACKENDS).
530
+ *
531
+ * ON A DUP (same `fusionIdentity()`): the LOCAL item's fields ALWAYS win —
532
+ * richer (real trust-filtered annotations: `supersededBy`/`conflictsWith`,
533
+ * match-anchored excerpt, `verbatimKey` for the Bridge) — only `.score` is
534
+ * replaced (the summed RRF contribution, used for this array's own sort
535
+ * order) and `foundInRemote` is set. `.confidence`/`.calibrated` are NEVER
536
+ * recomputed here: they stay exactly whatever the SURVIVING item's own
537
+ * origin already computed them as at ITS OWN scoring time (local items:
538
+ * "rrf-local" scale, set in `localRecallSearch`; remote-only items: "cosine"/
539
+ * "rrf-supabase", set in `recall-backend.ts`'s row mappers) — this is the
540
+ * safest possible way to keep `calibrated` correctly scaled to each item's
541
+ * ORIGIN: never re-deriving it from the new blended rank-score at all means
542
+ * it can never be accidentally run through the WRONG scale (Risk #8,
543
+ * confidence.ts's own header — the exact hazard this satisfies rather than
544
+ * reintroduces).
545
+ *
546
+ * Both input lists are assumed already rank-sorted (best first) — exactly
547
+ * what `localRecallSearch()`'s and `SupabaseRecallBackend.search()`'s own
548
+ * return values already are. Each input list is ALSO assumed to already be
549
+ * internally deduped (unique `fusionIdentity()` within its own list) —
550
+ * true today for both origins (`SupabaseRecallBackend.search()` already
551
+ * dedupes by id then by normalized excerpt before returning;
552
+ * `localRecallSearch()`'s own pipeline dedupes via `fuseCanonical()`). If
553
+ * that precondition were ever violated, a second same-identity item WITHIN
554
+ * one origin's own list would fold into the FIRST-seen item's map entry
555
+ * (same-origin collision, not a cross-origin one) — for a remote-side
556
+ * collision this would incorrectly leave `foundInRemote` at its default
557
+ * `false` (the field's own contract is "found in the OTHER origin", not
558
+ * "found more than once"); not a live bug given the precondition above, but
559
+ * worth knowing if either origin's own de-dup is ever relaxed.
560
+ */
561
+ export function fuseRemoteWithLocal(localResults, remoteResults) {
562
+ const map = new Map();
563
+ // LOCAL pass first — a local item always seeds/owns its identity slot, so
564
+ // a later remote match folds INTO it rather than the reverse.
565
+ localResults.forEach((item, idx) => {
566
+ const contribution = 1 / (FUSION_RRF_K + (idx + 1));
567
+ const key = fusionIdentity(item);
568
+ const existing = map.get(key);
569
+ if (existing) {
570
+ existing.score += contribution;
571
+ }
572
+ else {
573
+ map.set(key, { score: contribution, item, foundInRemote: false });
574
+ }
575
+ });
576
+ // REMOTE pass — a match folds its rank contribution into the LOCAL entry
577
+ // (local item's own fields kept, `foundInRemote` marked); a remote-only
578
+ // identity becomes its own new entry (remote item's fields kept as-is).
579
+ remoteResults.forEach((item, idx) => {
580
+ const contribution = 1 / (FUSION_RRF_K + (idx + 1));
581
+ const key = fusionIdentity(item);
582
+ const existing = map.get(key);
583
+ if (existing) {
584
+ existing.score += contribution;
585
+ existing.foundInRemote = true;
586
+ }
587
+ else {
588
+ map.set(key, { score: contribution, item, foundInRemote: false });
589
+ }
590
+ });
591
+ const fused = [...map.values()].map(({ score, item, foundInRemote }) => ({
592
+ ...item,
593
+ score,
594
+ ...(foundInRemote ? { foundInRemote: true } : {}),
595
+ }));
596
+ fused.sort((a, b) => b.score - a.score);
597
+ return fused;
598
+ }
340
599
  export async function smartRecall(input) {
341
600
  // H1 fix (continuity wave review, 2026-07-31): resolve `project` ONCE here,
342
601
  // the same way journalSearch/palaceSearch already resolve it internally on
@@ -358,9 +617,16 @@ export async function smartRecall(input) {
358
617
  resolvedProject = input.project ?? "auto";
359
618
  }
360
619
  // Process feedback first; reuse the returned log to avoid a second disk read
361
- const feedbackLog = (input.feedback && input.feedback.length > 0)
362
- ? processFeedback(input.feedback, input.query)
363
- : readFeedbackLog();
620
+ let feedbackLogSkipped = false;
621
+ let feedbackLog;
622
+ if (input.feedback && input.feedback.length > 0) {
623
+ const fb = await processFeedback(input.feedback, input.query);
624
+ feedbackLog = fb.log;
625
+ feedbackLogSkipped = fb.persistenceSkipped;
626
+ }
627
+ else {
628
+ feedbackLog = readFeedbackLog();
629
+ }
364
630
  const limit = input.limit ?? 10;
365
631
  // CJK-aware (P0-b): shared tokenizer — feeds getFeedbackCounts' relevance
366
632
  // weighting below with real word-segmented tokens instead of one giant
@@ -368,9 +634,14 @@ export async function smartRecall(input) {
368
634
  const queryWords = expandQuery(tokenizeWords(input.query));
369
635
  let results;
370
636
  let degraded;
637
+ // remote-fusion wave #24 (2026-09-09) — additive observability only; see
638
+ // `SmartRecallResult.recall_path`'s own doc comment for why this stays
639
+ // `undefined` (never added to the returned object) whenever the fusion
640
+ // flag is off, which is what keeps flag-off output byte-identical.
641
+ let recallPath;
371
642
  if (input.since) {
372
643
  // `since` filter is only supported by localRecallSearch — always use local.
373
- results = await localRecallSearch(input.query, input.project, limit, input.since);
644
+ results = await localRecallSearch(input.query, input.project, limit, input.since, input.freshnessBias);
374
645
  }
375
646
  else {
376
647
  const { getRecallBackend, recordRemoteFailure, recordRemoteSuccess } = await import("./recall-backend.js");
@@ -379,32 +650,56 @@ export async function smartRecall(input) {
379
650
  const isRemote = backendName === "SupabaseRecallBackend";
380
651
  if (!isRemote) {
381
652
  // Pure-local path: no budget needed.
382
- results = await backend.search(input.query, input.project, limit);
653
+ results = await backend.search(input.query, input.project, limit, input.freshnessBias ? { freshnessBias: true } : undefined);
383
654
  // If the vector backend returned nothing (index not yet populated), fall back to keyword search.
384
655
  if (results.length === 0 && backendName === "LocalVectorRecallBackend") {
385
- results = await localRecallSearch(input.query, input.project, limit);
656
+ results = await localRecallSearch(input.query, input.project, limit, undefined, input.freshnessBias);
386
657
  }
387
658
  }
388
659
  else {
389
660
  // Remote path: run local keyword search in parallel from the start.
390
- // Use semantic results if they arrive within RECALL_BUDGET_MS; otherwise
391
- // use local results (already computed — zero extra wait).
392
- const localPromise = localRecallSearch(input.query, input.project, limit);
393
- const remotePromise = backend.search(input.query, input.project, limit);
661
+ // Use semantic results if they arrive within the budget; otherwise use
662
+ // local results (already computed — zero extra wait).
663
+ const localPromise = localRecallSearch(input.query, input.project, limit, undefined, input.freshnessBias);
664
+ // fix4b review MEDIUM-1: the remote backend's own scoring ignores the
665
+ // flag, but its INTERNAL local fallbacks (missing client / embed()
666
+ // failure return local results AS the "remote" result and record a
667
+ // remote success) must carry it — see SupabaseRecallBackend.search.
668
+ const remotePromise = backend.search(input.query, input.project, limit, input.freshnessBias ? { freshnessBias: true } : undefined);
394
669
  const [localResults, remoteResults] = await Promise.all([
395
670
  localPromise,
396
- withTimeout(remotePromise, RECALL_BUDGET_MS),
671
+ withTimeout(remotePromise, recallBudgetMs()),
397
672
  ]);
398
673
  if (remoteResults !== null) {
399
674
  // Semantic results arrived in time — use them.
400
675
  recordRemoteSuccess();
401
- results = remoteResults.length > 0 ? remoteResults : localResults;
676
+ // #24 fusion gate: ONLY when the flag is on AND both sides answered
677
+ // non-empty — every other case (flag off, or either side empty)
678
+ // falls through to the pre-existing ternary UNCHANGED, so this
679
+ // `if` can only ever ADD a new branch, never alter the existing
680
+ // one's condition or result.
681
+ if (fusionEnabled() && localResults.length > 0 && remoteResults.length > 0) {
682
+ results = fuseRemoteWithLocal(localResults, remoteResults);
683
+ recallPath = "fused";
684
+ }
685
+ else {
686
+ results = remoteResults.length > 0 ? remoteResults : localResults;
687
+ // F-1 fix (pre-ship gate review, 2026-09-09): the label must match
688
+ // which side's data is actually in `results` — remote only when it
689
+ // genuinely answered non-empty; otherwise "local" (covers both
690
+ // "remote resolved empty, local had data" and "both empty"), never
691
+ // a hardcoded "remote" regardless of outcome.
692
+ if (fusionEnabled())
693
+ recallPath = remoteResults.length > 0 ? "remote" : "local";
694
+ }
402
695
  }
403
696
  else {
404
697
  // Timed out (or errored inside withTimeout) — fall back to local.
405
698
  recordRemoteFailure();
406
699
  degraded = { reason: "timeout", backend: backendName };
407
700
  results = localResults;
701
+ if (fusionEnabled())
702
+ recallPath = "local-timeout";
408
703
  }
409
704
  }
410
705
  }
@@ -417,8 +712,10 @@ export async function smartRecall(input) {
417
712
  const multiplier = betaUtility(positives, negatives) * 2;
418
713
  item.score *= multiplier;
419
714
  // Update the human-readable label only. `calibrated` stays the
420
- // SCORING-TIME value so the bridge gate is not fooled by the ×3–6 boost
421
- // chain (Risk #8). Backends without `calibrated` (defensive) get one.
715
+ // SCORING-TIME value so the bridge gate is not fooled by the boost
716
+ // (Risk #8; since fix4b 2026-09-12 this Beta ×≤2 is the only remaining
717
+ // post-RRF score mutation — the hot-window no longer multiplies).
718
+ // Backends without `calibrated` (defensive) get one.
422
719
  item.confidence = calibratedConfidence(item.score, "rrf-local").label;
423
720
  if (typeof item.calibrated !== "number") {
424
721
  item.calibrated = calibratedConfidence(item.score, "rrf-local").calibrated;
@@ -459,7 +756,7 @@ export async function smartRecall(input) {
459
756
  // fused top-confidence of palace/journal/insight". This adds brand-new
460
757
  // result items sourced from journal/archive/raw/, so it must never compete
461
758
  // for rank inside the palace/journal/insight RRF fusion — it only steps in
462
- // once those 3 sources have already failed to produce a confident #1
759
+ // once those 4 competing sources have already failed to produce a confident #1
463
760
  // answer. Placed AFTER the Bridge above so the Bridge's own `low` filter
464
761
  // (which also matches any verbatimKey-bearing item) only ever considers
465
762
  // genuine palace/journal/insight items — an archive item is already a raw
@@ -509,14 +806,18 @@ export async function smartRecall(input) {
509
806
  // survivor count and can legitimately be smaller). The raw counts side
510
807
  // channel is only present when `results` came straight from
511
808
  // localRecallSearch's local multi-source pipeline; remote/vector-backend
512
- // results have no "before fusion across 3 sources" notion, so fall back to
809
+ // results have no "before fusion across 4 sources" notion, so fall back to
513
810
  // results.length for those (unchanged prior behavior). The archive source
514
811
  // is intentionally excluded from this count — it is not part of the
515
- // 3-source fan-out this diagnostic describes.
812
+ // 4-source fan-out this diagnostic describes.
516
813
  const rawCandidateCounts = results[RAW_CANDIDATE_COUNTS];
517
814
  const totalSearched = rawCandidateCounts
518
- ? rawCandidateCounts.palace + rawCandidateCounts.journal + rawCandidateCounts.insight
815
+ ? rawCandidateCounts.palace + rawCandidateCounts.journal + rawCandidateCounts.insight + rawCandidateCounts.corrections
519
816
  : results.length;
817
+ // fix7: only ever set when the embeddings opt-in was on (see the side
818
+ // channel's own doc comment) — absent otherwise, keeping flag-off output
819
+ // byte-identical.
820
+ const semanticLegNote = results[SEMANTIC_LEG_NOTE];
520
821
  const sourcesQueried = [...new Set(results.map((r) => r.source))];
521
822
  // "archive" is reported whenever the gate ran, regardless of hit count —
522
823
  // matches the existing convention in localRecallSearch (a source is
@@ -528,8 +829,11 @@ export async function smartRecall(input) {
528
829
  results: finalResults,
529
830
  total_searched: totalSearched,
530
831
  sources_queried: sourcesQueried,
832
+ ...(feedbackLogSkipped ? { feedback_log_skipped: true } : {}),
531
833
  ...(rawCandidateCounts ? { candidates_by_source: rawCandidateCounts } : {}),
532
834
  ...(degraded ? { degraded } : {}),
835
+ ...(recallPath ? { recall_path: recallPath } : {}),
836
+ ...(semanticLegNote ? { semantic_leg: semanticLegNote } : {}),
533
837
  ...(bridged ? { bridged } : {}),
534
838
  ...(finalResults.length === 0
535
839
  ? { guidance: "No results found. Try `session_start` to initialize this project, or `bootstrap_scan` to import existing context." }