@remnic/core 9.3.603 → 9.3.605

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 (64) hide show
  1. package/dist/access-cli.js +9 -9
  2. package/dist/access-schema.d.ts +34 -34
  3. package/dist/{chunk-JTDRJQ3K.js → chunk-6JGNHWCI.js} +2 -2
  4. package/dist/{chunk-M6I5Z4SR.js → chunk-6ZZP4EJF.js} +2 -2
  5. package/dist/{chunk-75O6YQ63.js → chunk-G6R5UD3Q.js} +10 -3
  6. package/dist/chunk-G6R5UD3Q.js.map +1 -0
  7. package/dist/{chunk-I4UNL747.js → chunk-GMAG2HS4.js} +7 -3
  8. package/dist/chunk-GMAG2HS4.js.map +1 -0
  9. package/dist/{chunk-5SQ5CQJP.js → chunk-HSVJGWYS.js} +2 -2
  10. package/dist/{chunk-RUYYYLDT.js → chunk-IOTENEVL.js} +3 -3
  11. package/dist/{chunk-M46RYSMW.js → chunk-JHMFYY7L.js} +5 -2
  12. package/dist/chunk-JHMFYY7L.js.map +1 -0
  13. package/dist/{chunk-2ESBDLT5.js → chunk-VJXSUAO7.js} +2 -2
  14. package/dist/{chunk-Z5AAYHUC.js → chunk-VOUOLGIP.js} +13 -2
  15. package/dist/chunk-VOUOLGIP.js.map +1 -0
  16. package/dist/{chunk-OB6353F7.js → chunk-XPSVGJYA.js} +4 -4
  17. package/dist/{chunk-MTGOAU7A.js → chunk-YJ6QCQNE.js} +336 -300
  18. package/dist/chunk-YJ6QCQNE.js.map +1 -0
  19. package/dist/{chunk-6PTSXBPE.js → chunk-ZDTVJXIP.js} +5 -2
  20. package/dist/chunk-ZDTVJXIP.js.map +1 -0
  21. package/dist/cli.js +8 -8
  22. package/dist/{first-start-migration-CKTCTCQI.js → first-start-migration-GYJWIH36.js} +2 -2
  23. package/dist/index.js +12 -12
  24. package/dist/namespaces/migrate.js +6 -6
  25. package/dist/namespaces/search.js +5 -5
  26. package/dist/operator-toolkit.js +7 -7
  27. package/dist/orchestrator.js +9 -9
  28. package/dist/retrieval-agents.js +2 -2
  29. package/dist/schemas.d.ts +42 -42
  30. package/dist/search/factory.js +4 -4
  31. package/dist/search/index.js +4 -4
  32. package/dist/search/lancedb-backend.d.ts +1 -0
  33. package/dist/search/lancedb-backend.js +1 -1
  34. package/dist/search/meilisearch-backend.d.ts +1 -0
  35. package/dist/search/meilisearch-backend.js +1 -1
  36. package/dist/search/orama-backend.d.ts +1 -0
  37. package/dist/search/orama-backend.js +1 -1
  38. package/dist/search/port.d.ts +1 -0
  39. package/dist/shared-context/manager.d.ts +2 -2
  40. package/dist/temporal-index.js +1 -1
  41. package/dist/tier-migration.d.ts +1 -0
  42. package/dist/tier-migration.js +1 -1
  43. package/package.json +1 -1
  44. package/src/orchestrator.ts +51 -8
  45. package/src/search/lancedb-backend.ts +5 -1
  46. package/src/search/meilisearch-backend.ts +7 -2
  47. package/src/search/orama-backend.ts +5 -1
  48. package/src/search/port.ts +1 -0
  49. package/src/temporal-index.test.ts +30 -1
  50. package/src/temporal-index.ts +10 -3
  51. package/src/tier-migration.ts +13 -2
  52. package/dist/chunk-6PTSXBPE.js.map +0 -1
  53. package/dist/chunk-75O6YQ63.js.map +0 -1
  54. package/dist/chunk-I4UNL747.js.map +0 -1
  55. package/dist/chunk-M46RYSMW.js.map +0 -1
  56. package/dist/chunk-MTGOAU7A.js.map +0 -1
  57. package/dist/chunk-Z5AAYHUC.js.map +0 -1
  58. /package/dist/{chunk-JTDRJQ3K.js.map → chunk-6JGNHWCI.js.map} +0 -0
  59. /package/dist/{chunk-M6I5Z4SR.js.map → chunk-6ZZP4EJF.js.map} +0 -0
  60. /package/dist/{chunk-5SQ5CQJP.js.map → chunk-HSVJGWYS.js.map} +0 -0
  61. /package/dist/{chunk-RUYYYLDT.js.map → chunk-IOTENEVL.js.map} +0 -0
  62. /package/dist/{chunk-2ESBDLT5.js.map → chunk-VJXSUAO7.js.map} +0 -0
  63. /package/dist/{chunk-OB6353F7.js.map → chunk-XPSVGJYA.js.map} +0 -0
  64. /package/dist/{first-start-migration-CKTCTCQI.js.map → first-start-migration-GYJWIH36.js.map} +0 -0
@@ -953,7 +953,8 @@ function applyQueryAwareCandidateFilter(
953
953
  candidates: QmdSearchResult[],
954
954
  candidatePaths: Set<string> | null,
955
955
  ): QmdSearchResult[] {
956
- if (!candidatePaths || candidatePaths.size === 0) return candidates;
956
+ if (!candidatePaths) return candidates;
957
+ if (candidatePaths.size === 0) return [];
957
958
  const filtered = candidates.filter((candidate) =>
958
959
  candidatePaths.has(candidate.path),
959
960
  );
@@ -5316,7 +5317,7 @@ export class Orchestrator {
5316
5317
  paths: Set<string> | null,
5317
5318
  recallNamespaces: string[],
5318
5319
  ): Set<string> | null {
5319
- if (!paths || paths.size === 0) return null;
5320
+ if (!paths) return null;
5320
5321
  const scoped = new Set<string>();
5321
5322
  for (const memoryPath of paths) {
5322
5323
  if (!memoryPath || isArtifactMemoryPath(memoryPath)) continue;
@@ -5328,7 +5329,7 @@ export class Orchestrator {
5328
5329
  }
5329
5330
  scoped.add(memoryPath);
5330
5331
  }
5331
- return scoped.size > 0 ? scoped : null;
5332
+ return scoped;
5332
5333
  }
5333
5334
 
5334
5335
  private async buildQueryAwarePrefilter(
@@ -5376,7 +5377,14 @@ export class Orchestrator {
5376
5377
  let combination: QueryAwarePrefilter["combination"] = "none";
5377
5378
  let filteredToFullSearch = false;
5378
5379
 
5379
- if (temporalCandidates && tagCandidates) {
5380
+ if (
5381
+ tagSignals.matchedTags.length > 0 &&
5382
+ tagCandidates !== null &&
5383
+ tagCandidates.size === 0
5384
+ ) {
5385
+ candidatePaths = tagCandidates;
5386
+ combination = "tag";
5387
+ } else if (temporalCandidates !== null && tagCandidates !== null) {
5380
5388
  const intersection = new Set(
5381
5389
  Array.from(temporalCandidates).filter((memoryPath) =>
5382
5390
  tagCandidates.has(memoryPath),
@@ -5389,10 +5397,10 @@ export class Orchestrator {
5389
5397
  candidatePaths = new Set([...temporalCandidates, ...tagCandidates]);
5390
5398
  combination = "union";
5391
5399
  }
5392
- } else if (temporalCandidates) {
5400
+ } else if (temporalCandidates !== null) {
5393
5401
  candidatePaths = temporalCandidates;
5394
5402
  combination = "temporal";
5395
- } else if (tagCandidates) {
5403
+ } else if (tagCandidates !== null) {
5396
5404
  candidatePaths = tagCandidates;
5397
5405
  combination = "tag";
5398
5406
  }
@@ -5565,6 +5573,10 @@ export class Orchestrator {
5565
5573
  })),
5566
5574
  });
5567
5575
  };
5576
+ if (queryAwarePrefilter.candidatePaths?.size === 0) {
5577
+ await emitDebugSnapshot([], fetchLimit);
5578
+ return [];
5579
+ }
5568
5580
 
5569
5581
  for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt += 1) {
5570
5582
  throwIfRecallAborted(options.abortSignal);
@@ -7778,6 +7790,15 @@ export class Orchestrator {
7778
7790
  );
7779
7791
  const staleQmdFallback =
7780
7792
  cachedQmd?.source === "stale" ? cachedQmd : null;
7793
+ const queryAwarePrefilter = await queryAwarePrefilterPromise;
7794
+ const queryAwarePrefilterIsEmpty =
7795
+ queryAwarePrefilter.candidatePaths?.size === 0;
7796
+ const emptyQueryAwareQmdResult: Exclude<QmdPhaseResult, null> = {
7797
+ memoryResultsLists: [[]],
7798
+ globalResults: [],
7799
+ preAugmentTopScore: 0,
7800
+ maxSpecializedScore: 0,
7801
+ };
7781
7802
  if (cachedQmd?.source === "fresh") {
7782
7803
  recordRecallSectionMetric({
7783
7804
  section: "qmd",
@@ -7788,6 +7809,9 @@ export class Orchestrator {
7788
7809
  success: true,
7789
7810
  timing: `${Math.max(0, Math.round(cachedQmd.ageMs))}ms-cache`,
7790
7811
  });
7812
+ if (queryAwarePrefilterIsEmpty) {
7813
+ return emptyQueryAwareQmdResult;
7814
+ }
7791
7815
  return cachedQmd.value;
7792
7816
  }
7793
7817
 
@@ -7808,6 +7832,9 @@ export class Orchestrator {
7808
7832
  success: true,
7809
7833
  timing: `stale-cache(reprobe-cooldown:${Math.max(0, Math.round(staleQmdFallback.ageMs))}ms)`,
7810
7834
  });
7835
+ if (queryAwarePrefilterIsEmpty) {
7836
+ return emptyQueryAwareQmdResult;
7837
+ }
7811
7838
  return staleQmdFallback.value;
7812
7839
  }
7813
7840
  recordRecallSectionMetric({
@@ -7834,6 +7861,9 @@ export class Orchestrator {
7834
7861
  success: true,
7835
7862
  timing: `stale-cache(reprobe-failed:${Math.max(0, Math.round(staleQmdFallback.ageMs))}ms)`,
7836
7863
  });
7864
+ if (queryAwarePrefilterIsEmpty) {
7865
+ return emptyQueryAwareQmdResult;
7866
+ }
7837
7867
  return staleQmdFallback.value;
7838
7868
  }
7839
7869
  recordRecallSectionMetric({
@@ -7853,11 +7883,11 @@ export class Orchestrator {
7853
7883
  log.info(`QMD re-probe succeeded: ${this.qmd.debugStatus()}`);
7854
7884
  }
7855
7885
 
7856
- const queryAwarePrefilter = await queryAwarePrefilterPromise;
7857
7886
  const maxPerAgent = this.config.parallelMaxResultsPerAgent;
7858
7887
  const specializedAgentPromise: Promise<
7859
7888
  [ParallelSearchResult[], ParallelSearchResult[]]
7860
7889
  > | null =
7890
+ !queryAwarePrefilterIsEmpty &&
7861
7891
  this.config.parallelRetrievalEnabled && maxPerAgent > 0
7862
7892
  ? Promise.all([
7863
7893
  shouldRunAgent("direct", retrievalQuery, 0)
@@ -7981,6 +8011,9 @@ export class Orchestrator {
7981
8011
  success: true,
7982
8012
  timing: `stale-cache(${err instanceof Error ? err.message : String(err)})`,
7983
8013
  });
8014
+ if (queryAwarePrefilterIsEmpty) {
8015
+ return emptyQueryAwareQmdResult;
8016
+ }
7984
8017
  return staleQmdFallback.value;
7985
8018
  }
7986
8019
  throw err;
@@ -9462,6 +9495,7 @@ export class Orchestrator {
9462
9495
  // When the gate rejects, all recall pathways are skipped to prevent
9463
9496
  // low-relevance results from polluting context.
9464
9497
  const queryAwarePrefilter = await queryAwarePrefilterPromise;
9498
+ if (queryAwarePrefilter.candidatePaths?.size !== 0) {
9465
9499
  const embeddingResults = await this.searchEmbeddingFallback(
9466
9500
  retrievalQuery,
9467
9501
  embeddingFetchLimit,
@@ -9566,6 +9600,7 @@ export class Orchestrator {
9566
9600
  impressionRecorded = true;
9567
9601
  }
9568
9602
  }
9603
+ }
9569
9604
  }
9570
9605
 
9571
9606
  if (globalResults.length > 0) {
@@ -9607,6 +9642,7 @@ export class Orchestrator {
9607
9642
  } else if (recallResultLimit > 0 && !this.qmd.isAvailable()) {
9608
9643
  // Fallback: embeddings first, then recency-only.
9609
9644
  const queryAwarePrefilter = await queryAwarePrefilterPromise;
9645
+ if (queryAwarePrefilter.candidatePaths?.size !== 0) {
9610
9646
  const embeddingResults = await this.searchEmbeddingFallback(
9611
9647
  retrievalQuery,
9612
9648
  embeddingFetchLimit,
@@ -9922,6 +9958,7 @@ export class Orchestrator {
9922
9958
  }
9923
9959
  }
9924
9960
  }
9961
+ }
9925
9962
 
9926
9963
  if (isDisagreementPrompt(prompt)) {
9927
9964
  this.appendRecallSection(
@@ -15553,6 +15590,7 @@ export class Orchestrator {
15553
15590
  throwIfRecallAborted(abortSignal);
15554
15591
  const cappedLimit = Math.max(0, limit);
15555
15592
  if (cappedLimit === 0) return [];
15593
+ if (queryAwarePrefilter?.candidatePaths?.size === 0) return [];
15556
15594
 
15557
15595
  const scopedSeedResults = queryAwarePrefilter?.candidatePaths?.size
15558
15596
  ? await this.searchScopedMemoryCandidates(
@@ -15639,6 +15677,11 @@ export class Orchestrator {
15639
15677
  /** Issue #681 — when true, bypass graphTraversalConfidenceFloor. */
15640
15678
  includeLowConfidence?: boolean;
15641
15679
  }): Promise<QmdSearchResult[]> {
15680
+ if (options.queryAwarePrefilter?.candidatePaths?.size === 0) {
15681
+ if (options.xrayPoolSizeSink) options.xrayPoolSizeSink.size = 0;
15682
+ return [];
15683
+ }
15684
+
15642
15685
  const coldQmdEnabled = this.config.qmdColdTierEnabled === true;
15643
15686
  const coldCollection =
15644
15687
  this.config.qmdColdCollection ?? "openclaw-engram-cold";
@@ -15953,7 +15996,7 @@ export class Orchestrator {
15953
15996
  // Intersect with result paths first so out-of-scope paths don't exhaust the budget
15954
15997
  const scoped = new Set(Array.from(s).filter((p) => resultPaths.has(p)));
15955
15998
  if (maxCandidates === 0 || scoped.size <= maxCandidates)
15956
- return scoped.size > 0 ? scoped : null;
15999
+ return scoped;
15957
16000
  return new Set(Array.from(scoped).slice(0, maxCandidates));
15958
16001
  };
15959
16002
  if (temporalFromDate !== null) {
@@ -128,12 +128,16 @@ export class LanceDbBackend implements SearchBackend {
128
128
  }
129
129
 
130
130
  async updateCollection(collection: string, execution?: SearchExecutionOptions): Promise<void> {
131
+ await this.updateCollectionFromDir(collection, this.memoryDir, execution);
132
+ }
133
+
134
+ async updateCollectionFromDir(collection: string, memoryDir: string, execution?: SearchExecutionOptions): Promise<void> {
131
135
  if (isSearchAborted(execution)) return;
132
136
  let table = await this.ensureTableForCollection(collection);
133
137
  if (isSearchAborted(execution)) return;
134
138
  if (!table) return;
135
139
 
136
- const docs = await scanMemoryDir(this.memoryDir);
140
+ const docs = await scanMemoryDir(memoryDir);
137
141
  if (isSearchAborted(execution)) return;
138
142
  if (docs.length === 0) {
139
143
  // Clear stale data when no docs remain
@@ -124,14 +124,19 @@ export class MeilisearchBackend implements SearchBackend {
124
124
  }
125
125
 
126
126
  async updateCollection(collection: string, execution?: SearchExecutionOptions): Promise<void> {
127
- if (!this.autoIndex || !this.memoryDir) return;
127
+ if (!this.memoryDir) return;
128
+ await this.updateCollectionFromDir(collection, this.memoryDir, execution);
129
+ }
130
+
131
+ async updateCollectionFromDir(collection: string, memoryDir: string, execution?: SearchExecutionOptions): Promise<void> {
132
+ if (!this.autoIndex) return;
128
133
  if (!this.available) return;
129
134
  if (isSearchAborted(execution)) return;
130
135
 
131
136
  try {
132
137
  const client = await this.ensureClient();
133
138
  if (isSearchAborted(execution)) return;
134
- const docs = await scanMemoryDir(this.memoryDir);
139
+ const docs = await scanMemoryDir(memoryDir);
135
140
  if (isSearchAborted(execution)) return;
136
141
  const index = client.index(collection);
137
142
 
@@ -149,13 +149,17 @@ export class OramaBackend implements SearchBackend {
149
149
  }
150
150
 
151
151
  async updateCollection(collection: string, execution?: SearchExecutionOptions): Promise<void> {
152
+ await this.updateCollectionFromDir(collection, this.memoryDir, execution);
153
+ }
154
+
155
+ async updateCollectionFromDir(collection: string, memoryDir: string, execution?: SearchExecutionOptions): Promise<void> {
152
156
  if (isSearchAborted(execution)) return;
153
157
  const db = await this.ensureDbForCollection(collection);
154
158
  if (isSearchAborted(execution)) return;
155
159
  if (!db) return;
156
160
  const { search: oramaSearch, insert, remove, count, getByID } = this.oramaModule;
157
161
 
158
- const docs = await scanMemoryDir(this.memoryDir);
162
+ const docs = await scanMemoryDir(memoryDir);
159
163
  if (isSearchAborted(execution)) return;
160
164
  const docMap = new Map(docs.map((d) => [d.docid, d]));
161
165
  const { update: oramaUpdate } = this.oramaModule;
@@ -66,6 +66,7 @@ export interface SearchBackend {
66
66
  // ── Maintenance ──
67
67
  update(execution?: SearchExecutionOptions): Promise<void>;
68
68
  updateCollection(collection: string, execution?: SearchExecutionOptions): Promise<void>;
69
+ updateCollectionFromDir?(collection: string, memoryDir: string, execution?: SearchExecutionOptions): Promise<void>;
69
70
  /**
70
71
  * True when update() refreshes every indexed collection, not just this
71
72
  * backend's configured collection. Namespace routers use this to avoid
@@ -6,7 +6,12 @@ import { join } from "node:path";
6
6
  import test from "node:test";
7
7
  import { setTimeout as delay } from "node:timers/promises";
8
8
 
9
- import { queryByDateRangeAsync, queryByTagsAsync } from "./temporal-index.js";
9
+ import {
10
+ indexMemory,
11
+ queryByDateRangeAsync,
12
+ queryByTagsAsync,
13
+ resolvePromptTagPrefilterAsync,
14
+ } from "./temporal-index.js";
10
15
 
11
16
  async function runIndexWorker(moduleUrl: string, memoryDir: string, workerId: number, count: number): Promise<void> {
12
17
  const workerSource = `
@@ -189,3 +194,27 @@ test("temporal index writers fail open on symlink lock blockers", async () => {
189
194
  assert.equal(dateMatches, null);
190
195
  assert.deepEqual(tagMatches, new Set(["/tmp/remnic-temporal-worker-101-memory-0.md"]));
191
196
  });
197
+
198
+ test("tag queries distinguish missing index from valid no-match results", async () => {
199
+ const memoryDir = await mkdtemp(join(tmpdir(), "remnic-temporal-index-tag-miss-"));
200
+
201
+ const unavailableMatches = await queryByTagsAsync(memoryDir, ["beta"]);
202
+ assert.equal(unavailableMatches, null);
203
+
204
+ indexMemory(memoryDir, "/tmp/remnic-temporal-alpha-memory.md", "2026-03-11T12:00:00.000Z", ["alpha"]);
205
+
206
+ const matchingPaths = await queryByTagsAsync(memoryDir, ["alpha"]);
207
+ assert.deepEqual(matchingPaths, new Set(["/tmp/remnic-temporal-alpha-memory.md"]));
208
+
209
+ const noMatchPaths = await queryByTagsAsync(memoryDir, ["beta"]);
210
+ assert.deepEqual(noMatchPaths, new Set());
211
+
212
+ const promptPrefilter = await resolvePromptTagPrefilterAsync(memoryDir, "find #beta notes");
213
+ assert.deepEqual(promptPrefilter.matchedTags, ["beta"]);
214
+ assert.deepEqual(promptPrefilter.paths, new Set());
215
+
216
+ const noFilterPrefilter = await resolvePromptTagPrefilterAsync(memoryDir, "find project notes");
217
+ assert.deepEqual(noFilterPrefilter.matchedTags, []);
218
+ assert.deepEqual(noFilterPrefilter.expandedTags, []);
219
+ assert.equal(noFilterPrefilter.paths, null);
220
+ });
@@ -732,7 +732,7 @@ export async function queryByTagsAsync(memoryDir: string, tags: string[]): Promi
732
732
  try {
733
733
  gIndex = normalizeTagIndex(JSON.parse(raw) as TagIndex);
734
734
  } catch {
735
- gIndex = { version: TAG_INDEX_VERSION, tags: {}, aliases: {} };
735
+ return null;
736
736
  }
737
737
 
738
738
  return queryByTagsFromIndex(gIndex, tags);
@@ -741,7 +741,7 @@ export async function queryByTagsAsync(memoryDir: string, tags: string[]): Promi
741
741
  }
742
742
  }
743
743
 
744
- function queryByTagsFromIndex(index: TagIndex, tags: string[]): Set<string> | null {
744
+ function queryByTagsFromIndex(index: TagIndex, tags: string[]): Set<string> {
745
745
  const expandedTags = expandCanonicalTags(index, tags);
746
746
  const results = new Set<string>();
747
747
  for (const canonical of expandedTags) {
@@ -751,7 +751,7 @@ function queryByTagsFromIndex(index: TagIndex, tags: string[]): Set<string> | nu
751
751
  results.add(pathValue);
752
752
  }
753
753
  }
754
- return results.size > 0 ? results : null;
754
+ return results;
755
755
  }
756
756
 
757
757
  /**
@@ -797,6 +797,13 @@ export async function resolvePromptTagPrefilterAsync(
797
797
  matched.add(canonical);
798
798
  }
799
799
  }
800
+ if (matched.size === 0) {
801
+ return {
802
+ matchedTags: [],
803
+ expandedTags: [],
804
+ paths: null,
805
+ };
806
+ }
800
807
 
801
808
  const expandedTags = expandCanonicalTags(tagIndex, Array.from(matched));
802
809
  const paths = queryByTagsFromIndex(tagIndex, expandedTags);
@@ -91,8 +91,10 @@ export class TierMigrationExecutor {
91
91
  if (result.changed) {
92
92
  const destinationCollection = this.collectionForTier(toTier);
93
93
  const sourceCollection = this.collectionForTier(fromTier);
94
- // QMD update is effectively global in current CLI versions. One update call is enough.
95
- await this.qmd.updateCollection(destinationCollection);
94
+ await this.updateCollectionFromTierRoot(destinationCollection, toTier);
95
+ if (sourceCollection !== destinationCollection && this.qmd.updatesAllCollections?.() !== true) {
96
+ await this.updateCollectionFromTierRoot(sourceCollection, fromTier);
97
+ }
96
98
  if (this.autoEmbed) {
97
99
  await this.qmd.embedCollection(destinationCollection);
98
100
  if (sourceCollection !== destinationCollection) {
@@ -108,6 +110,15 @@ export class TierMigrationExecutor {
108
110
  return tier === "cold" ? this.coldCollection : this.hotCollection;
109
111
  }
110
112
 
113
+ private async updateCollectionFromTierRoot(collection: string, tier: MemoryTier): Promise<void> {
114
+ const memoryDir = tier === "cold" ? path.join(this.storage.dir, "cold") : this.storage.dir;
115
+ if (this.qmd.updatesAllCollections?.() !== true && this.qmd.updateCollectionFromDir) {
116
+ await this.qmd.updateCollectionFromDir(collection, memoryDir);
117
+ return;
118
+ }
119
+ await this.qmd.updateCollection(collection);
120
+ }
121
+
111
122
  private async appendJournal(result: TierMigrationResult): Promise<void> {
112
123
  const entry: TierMigrationJournalEntry = {
113
124
  ts: new Date().toISOString(),
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/search/lancedb-backend.ts"],"sourcesContent":["import { log } from \"../logger.js\";\nimport type { SearchBackend, SearchExecutionOptions, SearchQueryOptions, SearchResult } from \"./port.js\";\nimport type { EmbedHelper, EmbedProviderIdentity, EmbedWithProviderResult } from \"./embed-helper.js\";\nimport { scanMemoryDir } from \"./document-scanner.js\";\nimport { isSearchAborted, throwIfSearchAborted } from \"./abort.js\";\n\nexport interface LanceDbBackendOptions {\n dbPath: string;\n collection: string;\n embedHelper: EmbedHelper;\n memoryDir: string;\n embeddingDimension: number;\n}\n\n/**\n * LanceDB search backend — embedded hybrid FTS+vector with RRF reranking.\n *\n * Uses @lancedb/lancedb for native Arrow-backed storage.\n * One table per collection. Supports full-text, vector, and hybrid search.\n */\nexport class LanceDbBackend implements SearchBackend {\n private readonly dbPath: string;\n private readonly collection: string;\n private readonly embedHelper: EmbedHelper;\n private readonly memoryDir: string;\n private readonly embeddingDimension: number;\n private available = false;\n private db: any = null;\n private lanceModule: any = null;\n private readonly vectorProviderCompatibility = new WeakMap<\n object,\n { providerIdentity: EmbedProviderIdentity; compatible: boolean }\n >();\n\n constructor(opts: LanceDbBackendOptions) {\n this.dbPath = opts.dbPath;\n this.collection = opts.collection;\n this.embedHelper = opts.embedHelper;\n this.memoryDir = opts.memoryDir;\n this.embeddingDimension = opts.embeddingDimension;\n }\n\n async probe(): Promise<boolean> {\n try {\n await this.ensureDb();\n this.available = true;\n return true;\n } catch (err) {\n log.debug(`LanceDbBackend probe failed: ${err}`);\n this.available = false;\n return false;\n }\n }\n\n isAvailable(): boolean {\n return this.available;\n }\n\n debugStatus(): string {\n return `backend=lancedb available=${this.available} dbPath=${this.dbPath}`;\n }\n\n async search(\n query: string,\n _collection?: string,\n maxResults?: number,\n _options?: SearchQueryOptions,\n execution?: SearchExecutionOptions,\n ): Promise<SearchResult[]> {\n return this.hybridSearch(query, _collection, maxResults, execution);\n }\n\n async searchGlobal(query: string, maxResults?: number, execution?: SearchExecutionOptions): Promise<SearchResult[]> {\n const limit = maxResults ?? 10;\n if (!this.available) return [];\n\n try {\n throwIfSearchAborted(execution, \"LanceDbBackend global search aborted\");\n const db = await this.ensureDb();\n const tableNames = await db.tableNames();\n const allResults: SearchResult[] = [];\n\n for (const name of tableNames) {\n throwIfSearchAborted(execution, \"LanceDbBackend global search aborted\");\n try {\n const table = await db.openTable(name);\n const results = await this.searchTable(table, query, \"hybrid\", limit, execution);\n allResults.push(...results);\n } catch {\n // Skip tables that fail\n }\n }\n\n allResults.sort((a, b) => b.score - a.score);\n return allResults.slice(0, limit);\n } catch (err) {\n log.debug(`LanceDbBackend searchGlobal failed: ${err}`);\n return [];\n }\n }\n\n async bm25Search(query: string, collection?: string, maxResults?: number, execution?: SearchExecutionOptions): Promise<SearchResult[]> {\n if (isSearchAborted(execution)) return [];\n const table = await this.ensureTableForCollection(collection ?? this.collection);\n if (isSearchAborted(execution)) return [];\n if (!table) return [];\n return this.searchTable(table, query, \"fts\", maxResults ?? 10, execution);\n }\n\n async vectorSearch(query: string, collection?: string, maxResults?: number, execution?: SearchExecutionOptions): Promise<SearchResult[]> {\n if (isSearchAborted(execution)) return [];\n const table = await this.ensureTableForCollection(collection ?? this.collection);\n if (isSearchAborted(execution)) return [];\n if (!table) return [];\n return this.searchTable(table, query, \"vector\", maxResults ?? 10, execution);\n }\n\n async hybridSearch(query: string, collection?: string, maxResults?: number, execution?: SearchExecutionOptions): Promise<SearchResult[]> {\n if (isSearchAborted(execution)) return [];\n const table = await this.ensureTableForCollection(collection ?? this.collection);\n if (isSearchAborted(execution)) return [];\n if (!table) return [];\n return this.searchTable(table, query, \"hybrid\", maxResults ?? 10, execution);\n }\n\n async update(execution?: SearchExecutionOptions): Promise<void> {\n await this.updateCollection(this.collection, execution);\n }\n\n async updateCollection(collection: string, execution?: SearchExecutionOptions): Promise<void> {\n if (isSearchAborted(execution)) return;\n let table = await this.ensureTableForCollection(collection);\n if (isSearchAborted(execution)) return;\n if (!table) return;\n\n const docs = await scanMemoryDir(this.memoryDir);\n if (isSearchAborted(execution)) return;\n if (docs.length === 0) {\n // Clear stale data when no docs remain\n try {\n const db = await this.ensureDb();\n await db.dropTable(collection).catch(() => {});\n if (collection === this.collection) this.table = null;\n } catch {\n // Best-effort cleanup\n }\n return;\n }\n\n const embeddingProviderIdentity = this.embedHelper.getProviderIdentity();\n const existingVectors = new Map<string, {\n vector: number[];\n providerIdentity?: string;\n }>();\n const vectorProviderColumnState = await this.tableVectorProviderColumnState(table);\n if (vectorProviderColumnState === \"missing\") {\n table = await this.recreateTableForCollection(collection);\n if (isSearchAborted(execution)) return;\n if (!table) return;\n } else if (vectorProviderColumnState === \"present\") {\n try {\n const existingRows = await table.query().select([\"docid\", \"vector\", \"vectorProvider\"]).toArray();\n for (const row of existingRows ?? []) {\n if (isSearchAborted(execution)) return;\n const docid = row.docid;\n if (typeof docid !== \"string\") continue;\n const vector = row.vector;\n if (!vector || typeof vector !== \"object\") continue;\n existingVectors.set(docid, {\n vector: Array.from(vector as ArrayLike<number>),\n providerIdentity: typeof row.vectorProvider === \"string\" ? row.vectorProvider : undefined,\n });\n }\n } catch {\n log.debug(\"LanceDbBackend skipped refresh after vector preservation failed\");\n return;\n }\n } else {\n log.debug(\"LanceDbBackend skipped vector preservation after vectorProvider probe failed\");\n return;\n }\n\n const rows = docs.map((d) => {\n const existing = existingVectors.get(d.docid);\n const canPreserveVector =\n existing &&\n this.isCompatibleStoredVector(existing.vector) &&\n (!embeddingProviderIdentity ||\n existing.providerIdentity === embeddingProviderIdentity);\n return {\n docid: d.docid,\n path: d.path,\n content: d.content,\n snippet: d.snippet,\n vector: canPreserveVector\n ? existing.vector\n : new Array(this.embeddingDimension).fill(0),\n vectorProvider: canPreserveVector\n ? existing.providerIdentity ?? \"\"\n : \"\",\n };\n });\n\n try {\n if (isSearchAborted(execution)) return;\n await table.add(rows, { mode: \"overwrite\" });\n this.rememberVectorProviderCompatibility(\n table,\n embeddingProviderIdentity,\n rows.length > 0 && rows.every((row) => row.vectorProvider === embeddingProviderIdentity),\n );\n if (isSearchAborted(execution)) return;\n // Create FTS index on content column\n try {\n await table.createIndex(\"content\", { config: this.lanceIndex.fts() });\n } catch {\n // FTS index creation may fail on some platforms — degrade gracefully\n }\n if (collection === this.collection) this.table = table;\n } catch (err) {\n log.debug(`LanceDbBackend update failed: ${err}`);\n }\n }\n\n async embed(): Promise<void> {\n await this.embedCollection(this.collection);\n }\n\n async embedCollection(collection: string): Promise<void> {\n if (!this.embedHelper.isAvailable()) return;\n\n const table = await this.ensureTableForCollection(collection);\n if (!table) return;\n\n try {\n const embeddingProviderIdentity = this.embedHelper.getProviderIdentity();\n const allRows = await table.query().select([\"docid\", \"content\", \"vector\", \"vectorProvider\"]).toArray();\n const needsEmbed = allRows.filter((row: any) => {\n if (embeddingProviderIdentity && row.vectorProvider !== embeddingProviderIdentity) {\n return true;\n }\n return !this.isCompatibleStoredVector(row.vector);\n });\n\n if (needsEmbed.length === 0) {\n this.rememberVectorProviderCompatibility(table, embeddingProviderIdentity, true);\n return;\n }\n\n let rowsToEmbed = needsEmbed;\n let embedResult = await this.embedHelper.embedBatchWithProvider(\n rowsToEmbed.map((row: any) => row.content as string),\n );\n if (!embedResult) return;\n if (\n embeddingProviderIdentity &&\n embedResult.providerIdentity !== embeddingProviderIdentity\n ) {\n const effectiveProviderIdentity = embedResult.providerIdentity;\n const originalDocids = new Set(rowsToEmbed.map((row: any) => row.docid));\n const effectiveNeedsEmbed = allRows.filter((row: any) => (\n row.vectorProvider !== effectiveProviderIdentity ||\n !this.isCompatibleStoredVector(row.vector)\n ));\n const sameRows =\n effectiveNeedsEmbed.length === rowsToEmbed.length &&\n effectiveNeedsEmbed.every((row: any) => originalDocids.has(row.docid));\n if (!sameRows) {\n const effectiveTexts = effectiveNeedsEmbed.map((row: any) => row.content as string);\n const effectiveEmbedResult = await this.embedHelper.embedBatchWithProvider(effectiveTexts);\n if (effectiveEmbedResult) {\n rowsToEmbed = effectiveNeedsEmbed;\n embedResult = effectiveEmbedResult;\n }\n }\n }\n const { vectors, providerIdentity } = embedResult;\n\n let allEmbedded = true;\n for (let i = 0; i < rowsToEmbed.length; i++) {\n const vec = vectors[i];\n if (!this.isExpectedDimensionVector(vec)) {\n allEmbedded = false;\n continue;\n }\n const docid = rowsToEmbed[i].docid;\n await table.update({\n where: `docid = '${docid.replace(/'/g, \"''\")}'`,\n values: { vector: vec, vectorProvider: providerIdentity },\n });\n }\n if (allEmbedded) {\n this.rememberVectorProviderCompatibility(table, providerIdentity, true);\n } else {\n this.rememberVectorProviderCompatibility(table, providerIdentity, false);\n }\n } catch (err) {\n log.debug(`LanceDbBackend embed failed: ${err}`);\n }\n }\n\n async ensureCollection(\n _memoryDir: string,\n _execution?: SearchExecutionOptions,\n ): Promise<\"present\" | \"missing\" | \"unknown\" | \"skipped\"> {\n try {\n await this.ensureTable();\n return \"present\";\n } catch {\n return \"missing\";\n }\n }\n\n private table: any = null;\n\n private get lanceIndex(): any {\n return this.lanceModule.Index ?? this.lanceModule.default?.Index;\n }\n\n private async ensureDb(): Promise<any> {\n if (this.db) return this.db;\n if (!this.lanceModule) {\n this.lanceModule = await import(\"@lancedb/lancedb\");\n }\n const connect = this.lanceModule.connect ?? this.lanceModule.default?.connect;\n this.db = await connect(this.dbPath);\n return this.db;\n }\n\n private async ensureTableForCollection(collection: string): Promise<any> {\n // For the default collection, use the cached instance\n if (collection === this.collection) return this.ensureTable();\n\n const db = await this.ensureDb();\n const tables = await db.tableNames();\n\n if (tables.includes(collection)) {\n return await db.openTable(collection);\n }\n\n // Create empty table with schema\n const emptyRow = {\n docid: \"__placeholder__\",\n path: \"\",\n content: \"\",\n snippet: \"\",\n vector: new Array(this.embeddingDimension).fill(0),\n vectorProvider: \"\",\n };\n const newTable = await db.createTable(collection, [emptyRow]);\n try {\n await newTable.createIndex(\"content\", { config: this.lanceIndex.fts() });\n } catch {\n // FTS index creation may fail — degrade gracefully\n }\n try {\n await newTable.delete(\"docid = '__placeholder__'\");\n } catch {\n // May fail if delete isn't supported on empty-ish tables\n }\n return newTable;\n }\n\n private async recreateTableForCollection(collection: string): Promise<any> {\n const db = await this.ensureDb();\n try {\n await db.dropTable(collection).catch(() => {});\n } catch {\n // Best-effort legacy schema migration; table creation below may still recover.\n }\n if (collection === this.collection) this.table = null;\n return this.ensureTableForCollection(collection);\n }\n\n private async tableVectorProviderColumnState(table: any): Promise<\"present\" | \"missing\" | \"unknown\"> {\n try {\n await table.query().select([\"vectorProvider\"]).toArray();\n return \"present\";\n } catch (err) {\n if (isMissingVectorProviderColumnError(err)) {\n return \"missing\";\n }\n log.debug(`LanceDbBackend vectorProvider column probe failed: ${err}`);\n return \"unknown\";\n }\n }\n\n private async ensureTable(): Promise<any> {\n if (this.table) return this.table;\n\n const db = await this.ensureDb();\n const tables = await db.tableNames();\n\n if (tables.includes(this.collection)) {\n this.table = await db.openTable(this.collection);\n return this.table;\n }\n\n // Create empty table with schema\n const emptyRow = {\n docid: \"__placeholder__\",\n path: \"\",\n content: \"\",\n snippet: \"\",\n vector: new Array(this.embeddingDimension).fill(0),\n vectorProvider: \"\",\n };\n this.table = await db.createTable(this.collection, [emptyRow]);\n // Create FTS index on content column\n try {\n await this.table.createIndex(\"content\", { config: this.lanceIndex.fts() });\n } catch {\n // FTS index creation may fail — degrade gracefully\n }\n // Remove placeholder row\n try {\n await this.table.delete(\"docid = '__placeholder__'\");\n } catch {\n // May fail if delete isn't supported on empty-ish tables\n }\n return this.table;\n }\n\n private async searchTable(\n table: any,\n query: string,\n mode: \"fts\" | \"vector\" | \"hybrid\",\n limit: number,\n execution?: SearchExecutionOptions,\n ): Promise<SearchResult[]> {\n try {\n throwIfSearchAborted(execution, `LanceDbBackend ${mode} search aborted`);\n if (mode === \"fts\") {\n const results = await table.search(query, \"fts\").limit(limit).toArray();\n throwIfSearchAborted(execution, `LanceDbBackend ${mode} search aborted`);\n return this.mapRows(results);\n }\n\n if (mode === \"vector\") {\n const embedResult = await this.resolveCompatibleQueryEmbedding(table, query, execution);\n throwIfSearchAborted(execution, `LanceDbBackend ${mode} search aborted`);\n if (!embedResult) {\n // Fall back to FTS\n const results = await table.search(query, \"fts\").limit(limit).toArray();\n throwIfSearchAborted(execution, `LanceDbBackend ${mode} search aborted`);\n return this.mapRows(results);\n }\n const results = await table.search(embedResult.vector).limit(limit).toArray();\n throwIfSearchAborted(execution, `LanceDbBackend ${mode} search aborted`);\n return this.mapRows(results);\n }\n\n // hybrid — try FTS+vector with RRF reranking\n const embedResult = await this.resolveCompatibleQueryEmbedding(table, query, execution);\n throwIfSearchAborted(execution, `LanceDbBackend ${mode} search aborted`);\n if (!embedResult) {\n const results = await table.search(query, \"fts\").limit(limit).toArray();\n throwIfSearchAborted(execution, `LanceDbBackend ${mode} search aborted`);\n return this.mapRows(results);\n }\n\n try {\n const results = await table\n .search(query, \"hybrid\")\n .vector(embedResult.vector)\n .limit(limit)\n .toArray();\n throwIfSearchAborted(execution, `LanceDbBackend ${mode} search aborted`);\n return this.mapRows(results);\n } catch {\n // Hybrid may not be supported in all LanceDB versions — fall back to vector\n const results = await table.search(embedResult.vector).limit(limit).toArray();\n throwIfSearchAborted(execution, `LanceDbBackend ${mode} search aborted`);\n return this.mapRows(results);\n }\n } catch (err) {\n log.debug(`LanceDbBackend search (${mode}) failed: ${err}`);\n return [];\n }\n }\n\n private async resolveCompatibleQueryEmbedding(\n table: any,\n query: string,\n execution?: SearchExecutionOptions,\n ): Promise<EmbedWithProviderResult | null> {\n const embedResult = await this.embedHelper.embedWithProvider(query, { signal: execution?.signal });\n throwIfSearchAborted(execution, \"LanceDbBackend query embedding aborted\");\n if (!embedResult || !this.isExpectedDimensionVector(embedResult.vector)) return null;\n\n const storedProviderIdentity = await this.findCompatibleStoredVectorProvider(table, execution);\n if (!storedProviderIdentity) {\n this.rememberVectorProviderCompatibility(table, embedResult.providerIdentity, false);\n return null;\n }\n if (storedProviderIdentity === embedResult.providerIdentity) return embedResult;\n\n const fallbackEmbed = await this.embedQueryWithStoredFallbackProvider(query, storedProviderIdentity, execution);\n throwIfSearchAborted(execution, \"LanceDbBackend fallback query embedding aborted\");\n if (\n fallbackEmbed &&\n fallbackEmbed.providerIdentity === storedProviderIdentity &&\n this.isExpectedDimensionVector(fallbackEmbed.vector)\n ) {\n return fallbackEmbed;\n }\n\n this.rememberVectorProviderCompatibility(table, embedResult.providerIdentity, false);\n return null;\n }\n\n private async embedQueryWithStoredFallbackProvider(\n query: string,\n providerIdentity: EmbedProviderIdentity,\n execution?: SearchExecutionOptions,\n ): Promise<EmbedWithProviderResult | null> {\n const embedWithIdentity = (this.embedHelper as unknown as {\n embedWithFallbackProviderIdentity?: (\n text: string,\n identity: EmbedProviderIdentity,\n options?: { signal?: AbortSignal },\n ) => Promise<EmbedWithProviderResult | null>;\n }).embedWithFallbackProviderIdentity;\n if (typeof embedWithIdentity !== \"function\") return null;\n return embedWithIdentity.call(this.embedHelper, query, providerIdentity, { signal: execution?.signal });\n }\n\n private async findCompatibleStoredVectorProvider(\n table: any,\n execution?: SearchExecutionOptions,\n ): Promise<EmbedProviderIdentity | null> {\n try {\n const cached = this.vectorProviderCompatibility.get(table);\n if (cached?.compatible) return cached.providerIdentity;\n const rows = await table.query().select([\"vector\", \"vectorProvider\"]).toArray();\n let providerIdentity: EmbedProviderIdentity | null = null;\n let compatible = rows.length > 0;\n for (const row of rows ?? []) {\n throwIfSearchAborted(execution, \"LanceDbBackend vector provider check aborted\");\n if (\n typeof row.vectorProvider !== \"string\" ||\n row.vectorProvider.length === 0 ||\n !this.isCompatibleStoredVector(row.vector)\n ) {\n compatible = false;\n break;\n }\n if (providerIdentity && row.vectorProvider !== providerIdentity) {\n compatible = false;\n break;\n }\n providerIdentity = row.vectorProvider as EmbedProviderIdentity;\n }\n if (compatible && providerIdentity) {\n this.vectorProviderCompatibility.set(table, {\n providerIdentity,\n compatible: true,\n });\n return providerIdentity;\n }\n return null;\n } catch (err) {\n if (isSearchAborted(execution)) throw err;\n log.debug(`LanceDbBackend stored vector provider check failed: ${err}`);\n return null;\n }\n }\n\n private mapRows(rows: any[]): SearchResult[] {\n return (rows ?? [])\n .filter((row) => row.docid && row.docid !== \"__placeholder__\")\n .map((row) => ({\n docid: row.docid ?? \"\",\n path: row.path ?? \"\",\n snippet: row.snippet ?? row.content?.slice(0, 200) ?? \"\",\n score: row._relevance_score ?? (row._distance != null ? 1 / (1 + (row._distance ?? 0)) : 0.5),\n }));\n }\n\n private async tableHasCompatibleVectors(\n table: any,\n providerIdentity: EmbedProviderIdentity,\n execution?: SearchExecutionOptions,\n ): Promise<boolean> {\n try {\n const cached = this.vectorProviderCompatibility.get(table);\n if (cached?.providerIdentity === providerIdentity) return cached.compatible;\n const rows = await table.query().select([\"vector\", \"vectorProvider\"]).toArray();\n let compatible = rows.length > 0;\n for (const row of rows ?? []) {\n throwIfSearchAborted(execution, \"LanceDbBackend vector provider check aborted\");\n if (\n row.vectorProvider !== providerIdentity ||\n !this.isCompatibleStoredVector(row.vector)\n ) {\n compatible = false;\n break;\n }\n }\n this.vectorProviderCompatibility.set(table, { providerIdentity, compatible });\n return compatible;\n } catch (err) {\n if (isSearchAborted(execution)) throw err;\n log.debug(`LanceDbBackend vector provider check failed: ${err}`);\n return false;\n }\n }\n\n private rememberVectorProviderCompatibility(\n table: unknown,\n providerIdentity: EmbedProviderIdentity | null,\n compatible: boolean,\n ): void {\n if (!table || typeof table !== \"object\") return;\n if (!providerIdentity) {\n this.vectorProviderCompatibility.delete(table);\n return;\n }\n this.vectorProviderCompatibility.set(table, { providerIdentity, compatible });\n }\n\n private isExpectedDimensionVector(vector: number[] | null | undefined): vector is number[] {\n return Array.isArray(vector) && vector.length === this.embeddingDimension;\n }\n\n private isCompatibleStoredVector(vector: unknown): boolean {\n if (!vector || typeof vector !== \"object\") return false;\n const arr = Array.from(vector as ArrayLike<number>);\n return (\n arr.length === this.embeddingDimension &&\n arr.every((value) => Number.isFinite(value)) &&\n arr.some((value) => value !== 0)\n );\n }\n}\n\nfunction isMissingVectorProviderColumnError(err: unknown): boolean {\n const message = err instanceof Error ? err.message : String(err);\n return /\\bvectorProvider\\b/i.test(message) &&\n /\\b(column|field|schema|missing|not found|not exist|does not exist|unknown)\\b/i.test(message);\n}\n"],"mappings":";;;;;;;;;;;;AAoBO,IAAM,iBAAN,MAA8C;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACT,YAAY;AAAA,EACZ,KAAU;AAAA,EACV,cAAmB;AAAA,EACV,8BAA8B,oBAAI,QAGjD;AAAA,EAEF,YAAY,MAA6B;AACvC,SAAK,SAAS,KAAK;AACnB,SAAK,aAAa,KAAK;AACvB,SAAK,cAAc,KAAK;AACxB,SAAK,YAAY,KAAK;AACtB,SAAK,qBAAqB,KAAK;AAAA,EACjC;AAAA,EAEA,MAAM,QAA0B;AAC9B,QAAI;AACF,YAAM,KAAK,SAAS;AACpB,WAAK,YAAY;AACjB,aAAO;AAAA,IACT,SAAS,KAAK;AACZ,UAAI,MAAM,gCAAgC,GAAG,EAAE;AAC/C,WAAK,YAAY;AACjB,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,cAAuB;AACrB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,cAAsB;AACpB,WAAO,6BAA6B,KAAK,SAAS,WAAW,KAAK,MAAM;AAAA,EAC1E;AAAA,EAEA,MAAM,OACJ,OACA,aACA,YACA,UACA,WACyB;AACzB,WAAO,KAAK,aAAa,OAAO,aAAa,YAAY,SAAS;AAAA,EACpE;AAAA,EAEA,MAAM,aAAa,OAAe,YAAqB,WAA6D;AAClH,UAAM,QAAQ,cAAc;AAC5B,QAAI,CAAC,KAAK,UAAW,QAAO,CAAC;AAE7B,QAAI;AACF,2BAAqB,WAAW,sCAAsC;AACtE,YAAM,KAAK,MAAM,KAAK,SAAS;AAC/B,Y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ACzC;AACA,uBAAa;AACb;AAAA,QACF;AAAA,MACF;AACA,WAAK,4BAA4B,IAAI,OAAO,EAAE,kBAAkB,WAAW,CAAC;AAC5E,aAAO;AAAA,IACT,SAAS,KAAK;AACZ,UAAI,gBAAgB,SAAS,EAAG,OAAM;AACtC,UAAI,MAAM,gDAAgD,GAAG,EAAE;AAC/D,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEQ,oCACN,OACA,kBACA,YACM;AACN,QAAI,CAAC,SAAS,OAAO,UAAU,SAAU;AACzC,QAAI,CAAC,kBAAkB;AACrB,WAAK,4BAA4B,OAAO,KAAK;AAC7C;AAAA,IACF;AACA,SAAK,4BAA4B,IAAI,OAAO,EAAE,kBAAkB,WAAW,CAAC;AAAA,EAC9E;AAAA,EAEQ,0BAA0B,QAAyD;AACzF,WAAO,MAAM,QAAQ,MAAM,KAAK,OAAO,WAAW,KAAK;AAAA,EACzD;AAAA,EAEQ,yBAAyB,QAA0B;AACzD,QAAI,CAAC,UAAU,OAAO,WAAW,SAAU,QAAO;AAClD,UAAM,MAAM,MAAM,KAAK,MAA2B;AAClD,WACE,IAAI,WAAW,KAAK,sBACpB,IAAI,MAAM,CAAC,UAAU,OAAO,SAAS,KAAK,CAAC,KAC3C,IAAI,KAAK,CAAC,UAAU,UAAU,CAAC;AAAA,EAEnC;AACF;AAEA,SAAS,mCAAmC,KAAuB;AACjE,QAAM,UAAU,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC/D,SAAO,sBAAsB,KAAK,OAAO,KACvC,gFAAgF,KAAK,OAAO;AAChG;","names":["embedResult","results"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/temporal-index.ts"],"sourcesContent":["/**\n * Temporal and Tag Indexes (v8.1 — SwiftMem-inspired)\n *\n * Maintains two fast on-disk lookup structures in `state/`:\n * index_time.json — maps YYYY-MM-DD date buckets to memory file paths\n * index_tags.json — maps tag strings to memory file paths\n *\n * Used as an optional prefilter in the retrieval pipeline:\n * given a time range or a set of tags, narrow the candidate set\n * before the QMD hybrid search so we can pass a smaller pool to scoring.\n *\n * Design constraints:\n * - Must be fail-open (any error returns empty / unfiltered)\n * - Reads/writes are batched per extraction run\n * - Both indexes are plain JSON; no external dependencies\n */\n\nimport { execFileSync } from \"node:child_process\";\nimport * as crypto from \"node:crypto\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\n\nexport interface TemporalIndex {\n /** version bumped when schema changes */\n version: number;\n /** Last full rebuild timestamp (ISO string) */\n lastRebuildAt?: string;\n /** Map from YYYY-MM-DD → array of memory paths */\n dates: Record<string, string[]>;\n}\n\nexport interface TagIndex {\n version: number;\n lastRebuildAt?: string;\n /** Map from canonical tag string → node metadata */\n tags: Record<string, TagNode | string[]>;\n /** Map from alias string → canonical tags */\n aliases?: Record<string, string[]>;\n}\n\nexport interface TagNode {\n paths: string[];\n aliases?: string[];\n parents?: string[];\n}\n\nconst INDEX_VERSION = 1;\nconst TEMPORAL_INDEX_FILE = \"index_time.json\";\nconst TAG_INDEX_FILE = \"index_tags.json\";\nconst TAG_INDEX_VERSION = 2;\nconst INDEX_LOCK_STALE_MS = 60_000;\nconst INDEX_LOCK_POLL_MS = 10;\nconst INDEX_PROCESS_START_TOLERANCE_MS = 2_000;\nconst INDEX_LOCK_SLEEP = new Int32Array(new SharedArrayBuffer(4));\nconst INDEX_PROCESS_STARTED_AT_MS = Date.now() - process.uptime() * 1000;\n\ninterface IndexLockOwner {\n pid: number;\n createdAt?: string;\n processStartedAtMs?: number;\n}\n\ntype IndexLockCleanupResult = \"removed\" | \"wait\" | \"blocked\";\n\nfunction stateDir(memoryDir: string): string {\n return path.join(memoryDir, \"state\");\n}\n\nfunction temporalIndexPath(memoryDir: string): string {\n return path.join(stateDir(memoryDir), TEMPORAL_INDEX_FILE);\n}\n\nfunction tagIndexPath(memoryDir: string): string {\n return path.join(stateDir(memoryDir), TAG_INDEX_FILE);\n}\n\nfunction ensureStateDir(memoryDir: string): void {\n const dir = stateDir(memoryDir);\n fs.mkdirSync(dir, { recursive: true });\n}\n\nfunction readJsonSafe<T>(filePath: string, fallback: T): T {\n try {\n const raw = fs.readFileSync(filePath, \"utf8\");\n return JSON.parse(raw) as T;\n } catch {\n return fallback;\n }\n}\n\nfunction writeJsonSafe(filePath: string, data: unknown): void {\n try {\n fs.writeFileSync(filePath, JSON.stringify(data, null, 2), \"utf8\");\n } catch {\n // Fail silently — indexes are advisory only\n }\n}\n\nfunction sleepSync(ms: number): void {\n Atomics.wait(INDEX_LOCK_SLEEP, 0, 0, ms);\n}\n\nfunction uniqueTempPath(filePath: string): string {\n const dir = path.dirname(filePath);\n const base = path.basename(filePath);\n const nonce = crypto.randomBytes(6).toString(\"hex\");\n return path.join(dir, `.${base}.${process.pid}.${Date.now()}.${nonce}.tmp`);\n}\n\nfunction lockOwnerPath(lockDir: string): string {\n return path.join(lockDir, \"owner.json\");\n}\n\nfunction writeIndexLockOwner(lockDir: string): void {\n try {\n fs.writeFileSync(\n lockOwnerPath(lockDir),\n JSON.stringify({\n pid: process.pid,\n createdAt: new Date().toISOString(),\n processStartedAtMs: INDEX_PROCESS_STARTED_AT_MS,\n }),\n {\n encoding: \"utf8\",\n flag: \"wx\",\n }\n );\n } catch {\n // Fail silently — the directory lock is still the serialization primitive.\n }\n}\n\nfunction readIndexLockOwner(lockDir: string): IndexLockOwner | null {\n try {\n const parsed = JSON.parse(fs.readFileSync(lockOwnerPath(lockDir), \"utf8\")) as { pid?: unknown };\n if (!(typeof parsed.pid === \"number\" && Number.isInteger(parsed.pid) && parsed.pid > 0)) return null;\n const owner: IndexLockOwner = { pid: parsed.pid };\n if (\n \"createdAt\" in parsed &&\n typeof (parsed as { createdAt?: unknown }).createdAt === \"string\" &&\n (parsed as { createdAt: string }).createdAt.length > 0\n ) {\n owner.createdAt = (parsed as { createdAt: string }).createdAt;\n }\n const processStartedAtMs = (parsed as { processStartedAtMs?: unknown }).processStartedAtMs;\n if (typeof processStartedAtMs === \"number\" && Number.isFinite(processStartedAtMs) && processStartedAtMs > 0) {\n owner.processStartedAtMs = processStartedAtMs;\n }\n return owner;\n } catch {\n return null;\n }\n}\n\nfunction processIsAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch (error) {\n const code = (error as NodeJS.ErrnoException)?.code;\n return code === \"EPERM\";\n }\n}\n\nfunction readProcessStartedAtMs(pid: number): number | null {\n try {\n const output = execFileSync(\"ps\", [\"-p\", String(pid), \"-o\", \"lstart=\"], {\n encoding: \"utf8\",\n stdio: [\"ignore\", \"pipe\", \"ignore\"],\n timeout: 1_000,\n }).trim();\n if (!output) return null;\n const startedAtMs = Date.parse(output);\n return Number.isFinite(startedAtMs) ? startedAtMs : null;\n } catch {\n return null;\n }\n}\n\nfunction lockOwnerIsRunning(owner: IndexLockOwner): boolean {\n if (!processIsAlive(owner.pid)) return false;\n if (owner.processStartedAtMs === undefined) return true;\n const runningStartedAtMs = readProcessStartedAtMs(owner.pid);\n if (runningStartedAtMs === null) return true;\n return runningStartedAtMs <= owner.processStartedAtMs + INDEX_PROCESS_START_TOLERANCE_MS;\n}\n\nfunction lockIsFresh(lockInfo: fs.Stats, owner: IndexLockOwner | null): boolean {\n const ownerCreatedAtMs =\n typeof owner?.createdAt === \"string\" && owner.createdAt.length > 0 ? Date.parse(owner.createdAt) : Number.NaN;\n const referenceMs = Number.isFinite(ownerCreatedAtMs) ? ownerCreatedAtMs : lockInfo.mtimeMs;\n return Date.now() - referenceMs < INDEX_LOCK_STALE_MS;\n}\n\nfunction removeAbandonedIndexLock(lockDir: string): IndexLockCleanupResult {\n try {\n const info = fs.lstatSync(lockDir);\n if (info.isSymbolicLink()) return \"blocked\";\n if (!info.isDirectory()) {\n fs.rmSync(lockDir, { force: true });\n return \"removed\";\n }\n const owner = readIndexLockOwner(lockDir);\n if (owner !== null) {\n if (lockOwnerIsRunning(owner)) return \"wait\";\n }\n if (owner === null && lockIsFresh(info, null)) return \"wait\";\n fs.rmSync(lockDir, { recursive: true, force: true });\n return \"removed\";\n } catch (error) {\n if ((error as NodeJS.ErrnoException)?.code === \"ENOENT\") return \"removed\";\n // Fail silently — indexes are advisory only\n return \"blocked\";\n }\n}\n\nfunction withIndexFileLock(filePath: string, update: () => void): void {\n const lockDir = `${filePath}.lock.d`;\n let acquired = false;\n\n while (!acquired) {\n try {\n fs.mkdirSync(lockDir);\n writeIndexLockOwner(lockDir);\n acquired = true;\n } catch (error) {\n const code = (error as NodeJS.ErrnoException)?.code;\n if (code === \"ENOENT\") {\n try {\n fs.mkdirSync(path.dirname(lockDir), { recursive: true });\n } catch {\n return;\n }\n sleepSync(INDEX_LOCK_POLL_MS);\n continue;\n }\n if (code !== \"EEXIST\") return;\n const cleanupResult = removeAbandonedIndexLock(lockDir);\n if (cleanupResult === \"blocked\") return;\n sleepSync(INDEX_LOCK_POLL_MS);\n }\n }\n\n try {\n update();\n } finally {\n try {\n fs.rmSync(lockDir, { recursive: true, force: true });\n } catch {\n // Fail silently — indexes are advisory only\n }\n }\n}\n\n/**\n * Atomic write: write to a unique `.tmp` sibling then rename so readers never\n * observe a partially-written file.\n */\nfunction writeJsonAtomic(filePath: string, data: unknown): void {\n const payload = JSON.stringify(data, null, 2);\n for (let attempt = 0; attempt < 3; attempt += 1) {\n const tmp = uniqueTempPath(filePath);\n try {\n fs.writeFileSync(tmp, payload, \"utf8\");\n fs.renameSync(tmp, filePath);\n return;\n } catch {\n try {\n fs.unlinkSync(tmp);\n } catch {\n // Fail silently — indexes are advisory only\n }\n sleepSync(INDEX_LOCK_POLL_MS);\n }\n }\n}\n\nfunction updateTemporalIndex(memoryDir: string, update: (index: TemporalIndex) => void): void {\n const indexPath = temporalIndexPath(memoryDir);\n withIndexFileLock(indexPath, () => {\n const index = readJsonSafe<TemporalIndex>(indexPath, { version: INDEX_VERSION, dates: {} });\n update(index);\n writeJsonAtomic(indexPath, index);\n });\n}\n\nfunction updateTagIndex(memoryDir: string, update: (index: TagIndex) => void): void {\n const indexPath = tagIndexPath(memoryDir);\n withIndexFileLock(indexPath, () => {\n const index = normalizeTagIndex(\n readJsonSafe<TagIndex>(indexPath, { version: TAG_INDEX_VERSION, tags: {}, aliases: {} })\n );\n update(index);\n writeJsonAtomic(indexPath, index);\n });\n}\n\nfunction isoDateFromTimestamp(isoString: string): string {\n if (typeof isoString !== \"string\" || isoString.length < 10) {\n // Malformed frontmatter — fall back to today so the memory is still indexed.\n // Log a warning to surface data-quality issues without aborting the write.\n console.warn(`[engram] temporal-index: malformed timestamp \"${isoString}\", falling back to today`);\n return new Date().toISOString().slice(0, 10);\n }\n return isoString.slice(0, 10); // YYYY-MM-DD\n}\n\nfunction addPathToSet(record: Record<string, string[]>, key: string, p: string): void {\n if (!record[key]) {\n record[key] = [];\n }\n if (!record[key].includes(p)) {\n record[key].push(p);\n }\n}\n\nfunction removePathFromSet(record: Record<string, string[]>, key: string, p: string): void {\n if (!record[key]) return;\n record[key] = record[key].filter((x) => x !== p);\n if (record[key].length === 0) {\n delete record[key];\n }\n}\n\nfunction normalizeTagSegment(segment: string): string {\n return segment\n .trim()\n .toLowerCase()\n .replace(/[_\\s]+/g, \"-\")\n .replace(/[^a-z0-9-]/g, \"-\")\n .replace(/-+/g, \"-\")\n .replace(/^-|-$/g, \"\");\n}\n\nfunction normalizeCanonicalTag(tag: string): string {\n return tag\n .trim()\n .toLowerCase()\n .replace(/\\s*[>:|.]+\\s*/g, \"/\")\n .replace(/\\s*\\/\\s*/g, \"/\")\n .split(\"/\")\n .map(normalizeTagSegment)\n .filter(Boolean)\n .join(\"/\");\n}\n\nfunction normalizeAliasKey(tag: string): string {\n return tag\n .trim()\n .toLowerCase()\n .replace(/[\\/_.:-]+/g, \" \")\n .replace(/[-]+/g, \" \")\n .replace(/[^a-z0-9\\s]+/g, \" \")\n .replace(/\\s+/g, \" \")\n .trim();\n}\n\nfunction singularizeAlias(alias: string): string | null {\n if (!alias.endsWith(\"s\") || alias.length <= 3) return null;\n return alias.slice(0, -1);\n}\n\nfunction deriveParentTags(canonical: string): string[] {\n const parts = canonical.split(\"/\").filter(Boolean);\n const parents: string[] = [];\n for (let i = parts.length - 1; i > 0; i -= 1) {\n parents.push(parts.slice(0, i).join(\"/\"));\n }\n return parents;\n}\n\nfunction deriveTagAliases(rawTag: string, canonical: string): string[] {\n const aliases = new Set<string>();\n const canonicalAlias = normalizeAliasKey(canonical);\n const rawAlias = normalizeAliasKey(rawTag);\n const leaf = canonical.split(\"/\").at(-1) ?? canonical;\n const leafAlias = normalizeAliasKey(leaf);\n\n for (const candidate of [canonicalAlias, rawAlias, leafAlias]) {\n if (!candidate) continue;\n aliases.add(candidate);\n const singular = singularizeAlias(candidate);\n if (singular) aliases.add(singular);\n }\n\n return Array.from(aliases);\n}\n\nfunction normalizeTagIndex(raw: TagIndex | null | undefined): TagIndex {\n const normalized: TagIndex = {\n version: TAG_INDEX_VERSION,\n tags: {},\n aliases: {},\n };\n\n if (!raw || typeof raw !== \"object\") {\n return normalized;\n }\n\n const sourceTags = raw.tags ?? {};\n for (const [rawCanonical, nodeOrPaths] of Object.entries(sourceTags)) {\n const canonical = normalizeCanonicalTag(rawCanonical);\n if (!canonical) continue;\n const node: TagNode = Array.isArray(nodeOrPaths)\n ? { paths: [...new Set(nodeOrPaths)] }\n : {\n paths: Array.isArray(nodeOrPaths?.paths) ? [...new Set(nodeOrPaths.paths)] : [],\n aliases: Array.isArray(nodeOrPaths?.aliases) ? [...new Set(nodeOrPaths.aliases)] : [],\n parents: Array.isArray(nodeOrPaths?.parents) ? [...new Set(nodeOrPaths.parents)] : [],\n };\n const existingNode = normalized.tags[canonical];\n if (existingNode && !Array.isArray(existingNode)) {\n existingNode.paths = [...new Set([...existingNode.paths, ...node.paths])];\n existingNode.aliases = [...new Set([...(existingNode.aliases ?? []), ...(node.aliases ?? [])])];\n existingNode.parents = [...new Set([...(existingNode.parents ?? []), ...(node.parents ?? [])])];\n } else if (Array.isArray(existingNode)) {\n normalized.tags[canonical] = {\n paths: [...new Set([...existingNode, ...node.paths])],\n aliases: [...new Set(node.aliases ?? [])],\n parents: [...new Set(node.parents ?? deriveParentTags(canonical))],\n };\n } else {\n normalized.tags[canonical] = node;\n }\n for (const alias of deriveTagAliases(canonical, canonical)) {\n const list = normalized.aliases![alias] ?? [];\n if (!list.includes(canonical)) list.push(canonical);\n normalized.aliases![alias] = list;\n }\n for (const alias of node.aliases ?? []) {\n const aliasKey = normalizeAliasKey(alias);\n if (!aliasKey) continue;\n const list = normalized.aliases![aliasKey] ?? [];\n if (!list.includes(canonical)) list.push(canonical);\n normalized.aliases![aliasKey] = list;\n }\n const mergedNode = normalized.tags[canonical];\n if (mergedNode && !Array.isArray(mergedNode)) {\n mergedNode.parents = [...new Set(mergedNode.parents ?? deriveParentTags(canonical))];\n }\n }\n\n for (const [alias, canonicals] of Object.entries(raw.aliases ?? {})) {\n const aliasKey = normalizeAliasKey(alias);\n if (!aliasKey) continue;\n const list = normalized.aliases![aliasKey] ?? [];\n for (const canonical of canonicals ?? []) {\n const normalizedCanonical = normalizeCanonicalTag(canonical);\n if (normalizedCanonical && !list.includes(normalizedCanonical)) {\n list.push(normalizedCanonical);\n }\n }\n normalized.aliases![aliasKey] = list;\n }\n\n return normalized;\n}\n\nfunction ensureTagNode(index: TagIndex, canonical: string): TagNode {\n const existing = index.tags[canonical];\n if (existing && !Array.isArray(existing)) {\n return existing;\n }\n const created: TagNode = {\n paths: Array.isArray(existing) ? [...new Set(existing)] : [],\n aliases: [],\n parents: deriveParentTags(canonical),\n };\n index.tags[canonical] = created;\n return created;\n}\n\nfunction addTagGraphEntry(index: TagIndex, rawTag: string, memoryPath: string): void {\n const canonical = normalizeCanonicalTag(rawTag);\n if (!canonical) return;\n const node = ensureTagNode(index, canonical);\n if (!node.paths.includes(memoryPath)) {\n node.paths.push(memoryPath);\n }\n\n for (const alias of deriveTagAliases(rawTag, canonical)) {\n const aliasKey = normalizeAliasKey(alias);\n if (!aliasKey) continue;\n if (!node.aliases?.includes(aliasKey)) {\n node.aliases = [...new Set([...(node.aliases ?? []), aliasKey])];\n }\n const list = index.aliases?.[aliasKey] ?? [];\n if (!list.includes(canonical)) {\n index.aliases![aliasKey] = [...list, canonical];\n }\n }\n}\n\nfunction removeTagGraphEntry(index: TagIndex, rawTag: string, memoryPath: string): void {\n const canonical = normalizeCanonicalTag(rawTag);\n if (!canonical) return;\n const node = index.tags[canonical];\n if (!node || Array.isArray(node)) return;\n node.paths = node.paths.filter((value) => value !== memoryPath);\n if (node.paths.length === 0) {\n delete index.tags[canonical];\n }\n}\n\nfunction expandCanonicalTags(index: TagIndex, rawTags: string[]): string[] {\n const canonicals = new Set<string>();\n for (const rawTag of rawTags) {\n const canonical = normalizeCanonicalTag(rawTag);\n if (canonical && index.tags[canonical]) {\n canonicals.add(canonical);\n }\n const aliasKey = normalizeAliasKey(rawTag);\n for (const resolved of index.aliases?.[aliasKey] ?? []) {\n canonicals.add(resolved);\n }\n }\n\n const expanded = new Set<string>();\n for (const canonical of canonicals) {\n expanded.add(canonical);\n const node = index.tags[canonical];\n if (node && !Array.isArray(node)) {\n for (const parent of node.parents ?? []) {\n expanded.add(parent);\n }\n }\n }\n return Array.from(expanded);\n}\n\nfunction aliasPhrase(alias: string): string {\n return alias.replace(/\\//g, \" \").replace(/-/g, \" \").replace(/\\s+/g, \" \").trim();\n}\n\nfunction promptContainsAlias(prompt: string, alias: string): boolean {\n const phrase = aliasPhrase(alias);\n if (!phrase) return false;\n const normalizedPrompt = ` ${normalizeAliasKey(prompt)} `;\n return normalizedPrompt.includes(` ${phrase} `);\n}\n\n// ─── Public API ────────────────────────────────────────────────────────────────\n\n/**\n * Add (or update) a memory file in both indexes.\n *\n * @param memoryDir Root memory directory\n * @param memoryPath Absolute path to the memory file\n * @param createdAt ISO timestamp of the memory's creation date\n * @param tags Array of tag strings from the memory's frontmatter\n */\nexport function indexMemory(memoryDir: string, memoryPath: string, createdAt: string, tags: string[]): void {\n try {\n ensureStateDir(memoryDir);\n\n const dateKey = isoDateFromTimestamp(createdAt);\n updateTemporalIndex(memoryDir, (index) => {\n addPathToSet(index.dates, dateKey, memoryPath);\n });\n\n updateTagIndex(memoryDir, (index) => {\n for (const tag of tags) {\n if (tag && typeof tag === \"string\") {\n addTagGraphEntry(index, tag, memoryPath);\n }\n }\n });\n } catch {\n // Fail silently\n }\n}\n\n/**\n * Remove a memory file from both indexes (called on deletion/archival).\n */\nexport function deindexMemory(memoryDir: string, memoryPath: string, createdAt: string, tags: string[]): void {\n try {\n ensureStateDir(memoryDir);\n\n const dateKey = isoDateFromTimestamp(createdAt);\n updateTemporalIndex(memoryDir, (index) => {\n removePathFromSet(index.dates, dateKey, memoryPath);\n });\n\n updateTagIndex(memoryDir, (index) => {\n for (const tag of tags) {\n if (tag && typeof tag === \"string\") {\n removeTagGraphEntry(index, tag, memoryPath);\n }\n }\n });\n } catch {\n // Fail silently\n }\n}\n\n/**\n * Reset both index files to empty state.\n * Called before a full-corpus rebuild so stale paths in any surviving index\n * file do not persist after the rebuild completes.\n */\nexport function clearIndexes(memoryDir: string): void {\n try {\n ensureStateDir(memoryDir);\n updateTemporalIndex(memoryDir, (index) => {\n index.version = INDEX_VERSION;\n index.lastRebuildAt = undefined;\n index.dates = {};\n });\n updateTagIndex(memoryDir, (index) => {\n index.version = TAG_INDEX_VERSION;\n index.lastRebuildAt = undefined;\n index.tags = {};\n index.aliases = {};\n });\n } catch {\n // Fail silently — indexes are advisory only\n }\n}\n\n/**\n * Returns true when both index files exist on disk.\n * Used to detect first-time enablement so callers can trigger a full rebuild.\n */\nexport function indexesExist(memoryDir: string): boolean {\n try {\n return fs.existsSync(temporalIndexPath(memoryDir)) && fs.existsSync(tagIndexPath(memoryDir));\n } catch {\n return false;\n }\n}\n\n/**\n * Batch-add multiple memories to both indexes in a single read-modify-write cycle.\n * More efficient than calling indexMemory() per file when adding many at once.\n */\nexport function indexMemoriesBatch(\n memoryDir: string,\n entries: Array<{ path: string; createdAt: string; tags: string[] }>\n): void {\n if (entries.length === 0) return;\n try {\n ensureStateDir(memoryDir);\n\n updateTemporalIndex(memoryDir, (index) => {\n for (const entry of entries) {\n const dateKey = isoDateFromTimestamp(entry.createdAt);\n addPathToSet(index.dates, dateKey, entry.path);\n }\n });\n\n updateTagIndex(memoryDir, (index) => {\n for (const entry of entries) {\n for (const tag of entry.tags) {\n if (tag && typeof tag === \"string\") {\n addTagGraphEntry(index, tag, entry.path);\n }\n }\n }\n });\n } catch {\n // Fail silently\n }\n}\n\n/**\n * Return the set of memory paths whose index date falls in [fromDate, toDate).\n *\n * Boundary semantics (exclusive upper bound):\n * - `fromDate` is INCLUSIVE — entries on this date ARE returned.\n * - `toDate` is EXCLUSIVE — entries on this date are NOT returned.\n * Pass `recencyWindowBoundsFromPrompt(query).toDate` to get the correct\n * exclusive boundary; do NOT add +1 day yourself.\n * - Default `toDate` = tomorrow, so omitting it includes all of today.\n *\n * @param memoryDir - root memory directory (contains state/index_time.json)\n * @param fromDate - inclusive start date, YYYY-MM-DD\n * @param toDate - exclusive end date, YYYY-MM-DD (default: tomorrow)\n * @returns Set of matching file paths, or null if the index is unavailable.\n */\nexport async function queryByDateRangeAsync(\n memoryDir: string,\n fromDate: string,\n toDate?: string\n): Promise<Set<string> | null> {\n try {\n const tPath = temporalIndexPath(memoryDir);\n let raw: string;\n try {\n raw = await fs.promises.readFile(tPath, \"utf8\");\n } catch {\n return null; // File missing or unreadable\n }\n let tIndex: TemporalIndex;\n try {\n tIndex = JSON.parse(raw) as TemporalIndex;\n } catch {\n tIndex = { version: INDEX_VERSION, dates: {} };\n }\n // toDate is exclusive (first day NOT included). Default: tomorrow so \"all of today\" is included.\n const end = toDate ?? new Date(Date.now() + 86_400_000).toISOString().slice(0, 10);\n\n const results = new Set<string>();\n for (const [date, paths] of Object.entries(tIndex.dates)) {\n if (date >= fromDate && date < end) {\n for (const p of paths) {\n results.add(p);\n }\n }\n }\n return results;\n } catch {\n return null;\n }\n}\n\n/**\n * Async version of queryByTags — uses non-blocking fs.promises.readFile\n * to avoid blocking the Node.js event loop.\n */\nexport async function queryByTagsAsync(memoryDir: string, tags: string[]): Promise<Set<string> | null> {\n if (tags.length === 0) return null;\n try {\n const gPath = tagIndexPath(memoryDir);\n let raw: string;\n try {\n raw = await fs.promises.readFile(gPath, \"utf8\");\n } catch {\n return null; // File missing or unreadable\n }\n let gIndex: TagIndex;\n try {\n gIndex = normalizeTagIndex(JSON.parse(raw) as TagIndex);\n } catch {\n gIndex = { version: TAG_INDEX_VERSION, tags: {}, aliases: {} };\n }\n\n return queryByTagsFromIndex(gIndex, tags);\n } catch {\n return null;\n }\n}\n\nfunction queryByTagsFromIndex(index: TagIndex, tags: string[]): Set<string> | null {\n const expandedTags = expandCanonicalTags(index, tags);\n const results = new Set<string>();\n for (const canonical of expandedTags) {\n const nodeOrPaths = index.tags[canonical];\n const paths = Array.isArray(nodeOrPaths) ? nodeOrPaths : (nodeOrPaths?.paths ?? []);\n for (const pathValue of paths) {\n results.add(pathValue);\n }\n }\n return results.size > 0 ? results : null;\n}\n\n/**\n * Extract tags from a prompt for tag-based prefiltering.\n * Looks for hashtag-style tokens (#foo).\n * Returns lowercase, deduplicated list.\n */\nexport function extractTagsFromPrompt(prompt: string): string[] {\n const found = new Set<string>();\n\n // Match #tag style tokens\n const hashMatches = prompt.matchAll(/#([a-zA-Z][\\w-]{1,30})/g);\n for (const m of hashMatches) {\n const canonical = normalizeCanonicalTag(m[1]);\n if (canonical) found.add(canonical);\n }\n\n return Array.from(found);\n}\n\nexport async function resolvePromptTagPrefilterAsync(\n memoryDir: string,\n prompt: string\n): Promise<{\n matchedTags: string[];\n expandedTags: string[];\n paths: Set<string> | null;\n}> {\n const explicitTags = extractTagsFromPrompt(prompt);\n try {\n const raw = await fs.promises.readFile(tagIndexPath(memoryDir), \"utf8\");\n const tagIndex = normalizeTagIndex(JSON.parse(raw) as TagIndex);\n const matched = new Set<string>(explicitTags);\n\n for (const canonical of Object.keys(tagIndex.tags)) {\n if (promptContainsAlias(prompt, canonical)) {\n matched.add(canonical);\n }\n }\n for (const [alias, canonicals] of Object.entries(tagIndex.aliases ?? {})) {\n if (!promptContainsAlias(prompt, alias)) continue;\n for (const canonical of canonicals) {\n matched.add(canonical);\n }\n }\n\n const expandedTags = expandCanonicalTags(tagIndex, Array.from(matched));\n const paths = queryByTagsFromIndex(tagIndex, expandedTags);\n return {\n matchedTags: Array.from(matched),\n expandedTags,\n paths,\n };\n } catch {\n return { matchedTags: explicitTags, expandedTags: explicitTags, paths: null };\n }\n}\n\n/**\n * Detect if a prompt is time-sensitive (mentions specific time references).\n * Used to decide whether to activate the temporal prefilter.\n */\nexport function isTemporalQuery(prompt: string): boolean {\n return /\\b(today|yesterday|this week|last week|this month|last month|recent(?:ly)?|lately|just now|earlier today|this morning|last night|last year|this year|\\d+ days? ago|\\d+ hours? ago|\\d+ weeks? ago|\\d+ months? ago|(?:in |on |during |since |before |after )?(?:january|february|march|april|may|june|july|august|september|october|november|december)(?:\\s+\\d{1,4})?|\\d{4}-\\d{2}-\\d{2}|\\d{1,2}\\/\\d{1,2}\\/\\d{2,4}|(?:spring|summer|fall|autumn|winter)\\s+\\d{4}|on the \\d{1,2}(?:st|nd|rd|th)?|last (?:monday|tuesday|wednesday|thursday|friday|saturday|sunday))\\b/i.test(\n prompt\n );\n}\n\n/**\n * Compute a \"from date\" string (YYYY-MM-DD) for a recency-based temporal query.\n * For \"recent\" / \"lately\" returns 7 days ago; for today/yesterday the obvious window.\n */\nexport function recencyWindowFromPrompt(prompt: string, nowMs: number = Date.now()): string {\n const p = prompt.toLowerCase();\n const now = new Date(nowMs);\n let daysBack = 7; // default\n\n if (/\\btoday\\b/.test(p) || /\\bthis morning\\b/.test(p) || /\\bjust now\\b/.test(p) || /\\bearlier today\\b/.test(p)) {\n daysBack = 0; // fromDate = today → window [today, today]\n } else if (/\\byesterday\\b/.test(p) || /\\blast night\\b/.test(p)) {\n daysBack = 1; // fromDate = yesterday → window [yesterday, today]\n } else if (/\\bthis week\\b/.test(p)) {\n daysBack = 7;\n } else if (/\\blast week\\b/.test(p)) {\n daysBack = 14;\n } else if (/\\bthis month\\b/.test(p)) {\n daysBack = 31;\n } else if (/\\blast month\\b/.test(p)) {\n daysBack = 62;\n } else if (/\\bthis year\\b/.test(p)) {\n // From Jan 1 of current year\n const jan1 = new Date(now.getFullYear(), 0, 1);\n return jan1.toISOString().slice(0, 10);\n } else if (/\\blast year\\b/.test(p)) {\n const jan1LastYear = new Date(now.getFullYear() - 1, 0, 1);\n return jan1LastYear.toISOString().slice(0, 10);\n } else {\n // Try specific month references: \"in March\", \"during January\", \"since February\"\n const monthNames = [\n \"january\",\n \"february\",\n \"march\",\n \"april\",\n \"may\",\n \"june\",\n \"july\",\n \"august\",\n \"september\",\n \"october\",\n \"november\",\n \"december\",\n ];\n const monthMatch = p.match(\n /\\b(january|february|march|april|may|june|july|august|september|october|november|december)(?:\\s+(\\d{4}))?\\b/\n );\n if (monthMatch) {\n const monthIdx = monthNames.indexOf(monthMatch[1]);\n const year = monthMatch[2] ? Number.parseInt(monthMatch[2], 10) : now.getFullYear();\n // \"before <month>\" means everything prior to that month: use 2-year lookback\n // as fromDate so the window isn't unbounded. toDate is set to the month start\n // in recencyWindowBoundsFromPrompt.\n // IMPORTANT: when an explicit year is given, anchor the lookback to the named\n // month start (not to today). \"before January 2024\" should produce\n // fromDate ≈ 2022-01 — not today-730 days, which could land after 2024-01 and\n // invert the window for any explicitly past month within the 730-day horizon.\n if (/\\bbefore\\b/.test(p)) {\n if (monthMatch[2]) {\n // Explicit year: anchor fromDate 730 days before the named month start.\n const monthStart = new Date(year, monthIdx, 1);\n return new Date(monthStart.getTime() - 730 * 86_400_000).toISOString().slice(0, 10);\n }\n daysBack = 730;\n } else {\n const monthStart = new Date(year, monthIdx, 1);\n return monthStart.toISOString().slice(0, 10);\n }\n }\n\n // Try \"N weeks ago\"\n const weekMatch = p.match(/(\\d{1,5})\\s*weeks?\\s*ago/);\n if (weekMatch) {\n daysBack = Math.min(365, Number.parseInt(weekMatch[1], 10) * 7);\n } else {\n // Try \"N months ago\"\n const monthsAgoMatch = p.match(/(\\d{1,5})\\s*months?\\s*ago/);\n if (monthsAgoMatch) {\n daysBack = Math.min(730, Number.parseInt(monthsAgoMatch[1], 10) * 31);\n } else {\n const numMatch = p.match(/(\\d{1,5})\\s*days?\\s*ago/);\n if (numMatch) {\n daysBack = Math.min(365, Number.parseInt(numMatch[1], 10)); // no off-by-one: \"3 days ago\" → 3\n } else {\n const hrMatch = p.match(/(\\d{1,5})\\s*hours?\\s*ago/);\n if (hrMatch) {\n // Convert hours to days (ceiling); at least 1 day window\n daysBack = Math.max(1, Math.ceil(Number.parseInt(hrMatch[1], 10) / 24));\n }\n }\n }\n }\n\n // Try explicit date patterns: YYYY-MM-DD or MM/DD/YYYY\n const isoMatch = p.match(/(\\d{4})-(\\d{2})-(\\d{2})/);\n if (isoMatch) {\n return `${isoMatch[1]}-${isoMatch[2]}-${isoMatch[3]}`;\n }\n const usMatch = p.match(/(\\d{1,2})\\/(\\d{1,2})\\/(\\d{2,4})/);\n if (usMatch) {\n const year = usMatch[3].length === 2 ? 2000 + Number.parseInt(usMatch[3], 10) : Number.parseInt(usMatch[3], 10);\n return `${year}-${usMatch[1].padStart(2, \"0\")}-${usMatch[2].padStart(2, \"0\")}`;\n }\n\n // Try \"last Monday/Tuesday/etc\"\n const dayOfWeekMatch = p.match(/\\blast\\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday)\\b/);\n if (dayOfWeekMatch) {\n const dayNames = [\"sunday\", \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\"];\n const targetDay = dayNames.indexOf(dayOfWeekMatch[1]);\n const currentDay = now.getDay();\n daysBack = (currentDay - targetDay + 7) % 7 || 7; // at least 7 days back\n }\n }\n\n const from = new Date(nowMs - daysBack * 24 * 60 * 60 * 1000);\n return from.toISOString().slice(0, 10);\n}\n\n/**\n * Returns both the start and end of the temporal window implied by the prompt.\n *\n * `fromDate` is computed by delegating to `recencyWindowFromPrompt`, so the two\n * functions cannot diverge on the lower bound. `toDate` is computed independently\n * here using the same pattern-priority ordering, because the upper-bound arithmetic\n * differs (exclusive end vs. inclusive start) and would not be expressible as a\n * simple wrapper.\n *\n * Known divergence to be aware of: for \"N hours ago\", `recencyWindowFromPrompt`\n * uses `Math.max(1, Math.ceil(hours/24))` days back, so `fromDate` = yesterday for\n * sub-24h values. `toDate` here is always `tomorrow` when no explicit date is\n * specified (see the `toDaysBack === 0` branch), giving a 2-day window. This is\n * intentional — the window must cover both yesterday and today for recent hour-level\n * queries. Any fix to the hours formula in `recencyWindowFromPrompt` must be\n * manually reflected here.\n *\n * - `fromDate`: first day of the implied window (same as `recencyWindowFromPrompt`)\n * - `toDate`: first day NOT in the window (exclusive upper bound), so callers\n * should filter with `date >= fromDate && date < toDate`.\n */\nexport function recencyWindowBoundsFromPrompt(\n prompt: string,\n nowMs: number = Date.now()\n): { fromDate: string; toDate: string } {\n const fromDate = recencyWindowFromPrompt(prompt, nowMs);\n const p = prompt.toLowerCase();\n const now = new Date(nowMs);\n const today = now.toISOString().slice(0, 10);\n const tomorrow = new Date(nowMs + 86_400_000).toISOString().slice(0, 10);\n\n let toDate: string;\n\n if (/\\btoday\\b|\\bthis morning\\b|\\bjust now\\b|\\bearlier today\\b/.test(p)) {\n toDate = tomorrow; // exclusive: include all of today\n } else if (/\\byesterday\\b|\\blast night\\b/.test(p)) {\n toDate = today; // exclusive: include all of yesterday, stop before today\n } else if (/\\bthis week\\b|\\bthis month\\b|\\bthis year\\b/.test(p)) {\n toDate = tomorrow; // exclusive: include all of today\n } else if (/\\blast week\\b/.test(p)) {\n toDate = new Date(nowMs - 7 * 86_400_000).toISOString().slice(0, 10); // already exclusive\n } else if (/\\blast month\\b/.test(p)) {\n toDate = new Date(nowMs - 31 * 86_400_000).toISOString().slice(0, 10); // approximately exclusive\n } else if (/\\blast year\\b/.test(p)) {\n toDate = `${now.getFullYear()}-01-01`; // exclusive: stop at Jan 1 of current year\n } else {\n // Mirror the structure of recencyWindowFromPrompt's else branch:\n // month name → early set (highest priority), then ago patterns set a\n // working offset, then ISO/US/weekday patterns run AFTER ago patterns\n // and can override them — matching the priority ordering in recencyWindowFromPrompt.\n\n const monthNames = [\n \"january\",\n \"february\",\n \"march\",\n \"april\",\n \"may\",\n \"june\",\n \"july\",\n \"august\",\n \"september\",\n \"october\",\n \"november\",\n \"december\",\n ];\n const monthMatch = p.match(\n /\\b(january|february|march|april|may|june|july|august|september|october|november|december)(?:\\s+(\\d{4}))?\\b/\n );\n if (monthMatch) {\n // \"since <month>\" / \"after <month>\" — open-ended: everything from that month to now.\n // \"before <month>\" — closed upper bound: everything before that month starts.\n // Plain \"<month>\" — just that calendar month.\n const monthIdx = monthNames.indexOf(monthMatch[1]);\n const year = monthMatch[2] ? Number.parseInt(monthMatch[2], 10) : now.getFullYear();\n const isSinceOrAfter = /\\b(since|after)\\b/.test(p);\n const isBefore = /\\bbefore\\b/.test(p);\n if (isSinceOrAfter) {\n toDate = tomorrow;\n } else if (isBefore) {\n // \"before <month>\" means everything prior to that month.\n // toDate = first day of that month (exclusive upper bound).\n toDate = new Date(year, monthIdx, 1).toISOString().slice(0, 10);\n } else {\n // Closed window: first day of the NEXT month is the exclusive upper bound.\n toDate = new Date(year, monthIdx + 1, 1).toISOString().slice(0, 10);\n }\n } else {\n // Ago patterns set a working offset (recent edge of the N-ago window).\n // Same nesting order as recencyWindowFromPrompt.\n // Sentinel -1 means \"no ago pattern matched\" → toDate falls back to tomorrow.\n let toDaysBack = -1;\n const weekMatch = p.match(/(\\d{1,5})\\s*weeks?\\s*ago/);\n if (weekMatch) {\n toDaysBack = Math.max(0, Math.min(52, Number.parseInt(weekMatch[1], 10)) - 1) * 7;\n } else {\n const monthsAgoMatch = p.match(/(\\d{1,5})\\s*months?\\s*ago/);\n if (monthsAgoMatch) {\n toDaysBack = Math.max(0, Math.min(24, Number.parseInt(monthsAgoMatch[1], 10)) - 1) * 31;\n } else {\n const numMatch = p.match(/(\\d{1,5})\\s*days?\\s*ago/);\n if (numMatch) {\n // (N-1) mirrors the weeks/months ago formula: \"3 days ago\" → window [today-3, today-2]\n // N=1 → toDaysBack=0 → toDate=today (exclusive) → window [yesterday, today) = 1 day. ✓\n toDaysBack = Math.max(0, Math.min(365, Number.parseInt(numMatch[1], 10)) - 1);\n } else {\n const hrMatch = p.match(/(\\d{1,5})\\s*hours?\\s*ago/);\n if (hrMatch) {\n // Sub-day precision: keep sentinel -1 so toDate falls back to tomorrow,\n // which includes today. fromDate = yesterday (recencyWindowFromPrompt uses ceiling).\n toDaysBack = -1;\n }\n }\n }\n }\n\n // Explicit date/weekday patterns run AFTER ago patterns (same as recencyWindowFromPrompt)\n // and override the ago-derived offset when present.\n const isoMatch = p.match(/(\\d{4})-(\\d{2})-(\\d{2})/);\n if (isoMatch) {\n // +1 day: exclusive upper bound includes the named date\n const d = new Date(`${isoMatch[1]}-${isoMatch[2]}-${isoMatch[3]}T00:00:00Z`);\n toDate = new Date(d.getTime() + 86_400_000).toISOString().slice(0, 10);\n } else {\n const usMatch = p.match(/(\\d{1,2})\\/(\\d{1,2})\\/(\\d{2,4})/);\n if (usMatch) {\n const year =\n usMatch[3].length === 2 ? 2000 + Number.parseInt(usMatch[3], 10) : Number.parseInt(usMatch[3], 10);\n // +1 day: exclusive upper bound includes the named date\n const d = new Date(`${year}-${usMatch[1].padStart(2, \"0\")}-${usMatch[2].padStart(2, \"0\")}T00:00:00Z`);\n toDate = new Date(d.getTime() + 86_400_000).toISOString().slice(0, 10);\n } else {\n const dayOfWeekMatch = p.match(/\\blast\\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday)\\b/);\n if (dayOfWeekMatch) {\n const dayNames = [\"sunday\", \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\"];\n const targetDay = dayNames.indexOf(dayOfWeekMatch[1]);\n const currentDay = now.getDay();\n const daysBack = (currentDay - targetDay + 7) % 7 || 7;\n // +1 day: exclusive upper bound includes the named weekday\n toDate = new Date(nowMs - (daysBack - 1) * 86_400_000).toISOString().slice(0, 10);\n } else {\n // Use the ago-derived offset.\n // toDaysBack=-1 means no pattern matched (or hours-ago): use tomorrow so today\n // is included in the window. toDaysBack=0 means N=1 ago (e.g. \"1 day ago\"):\n // toDate = today (exclusive) correctly creates a 1-day window [yesterday, today).\n toDate = toDaysBack < 0 ? tomorrow : new Date(nowMs - toDaysBack * 86_400_000).toISOString().slice(0, 10);\n }\n }\n }\n }\n }\n\n // Guard: if toDate would precede fromDate (inverted window from conflicting keywords),\n // fall back to tomorrow (exclusive upper bound that covers today) so we never produce\n // an empty window. Using `today` is insufficient because `date < today` excludes today.\n if (toDate <= fromDate) toDate = tomorrow;\n\n return { fromDate, toDate };\n}\n"],"mappings":";AAiBA,SAAS,oBAAoB;AAC7B,YAAY,YAAY;AACxB,YAAY,QAAQ;AACpB,YAAY,UAAU;AA0BtB,IAAM,gBAAgB;AACtB,IAAM,sBAAsB;AAC5B,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAC5B,IAAM,qBAAqB;AAC3B,IAAM,mCAAmC;AACzC,IAAM,mBAAmB,IAAI,WAAW,IAAI,kBAAkB,CAAC,CAAC;AAChE,IAAM,8BAA8B,KAAK,IAAI,IAAI,QAAQ,OAAO,IAAI;AAUpE,SAAS,SAAS,WAA2B;AAC3C,SAAY,UAAK,WAAW,OAAO;AACrC;AAEA,SAAS,kBAAkB,WAA2B;AACpD,SAAY,UAAK,SAAS,SAAS,GAAG,mBAAmB;AAC3D;AAEA,SAAS,aAAa,WAA2B;AAC/C,SAAY,UAAK,SAAS,SAAS,GAAG,cAAc;AACtD;AAEA,SAAS,eAAe,WAAyB;AAC/C,QAAM,MAAM,SAAS,SAAS;AAC9B,EAAG,aAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AACvC;AAEA,SAAS,aAAgB,UAAkB,UAAgB;AACzD,MAAI;AACF,UAAM,MAAS,gBAAa,UAAU,MAAM;AAC5C,WAAO,K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