memorix 1.10.4 → 1.10.5

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 (41) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/cli/index.js +418 -74
  3. package/dist/index.js +227 -55
  4. package/dist/maintenance-runner.js +225 -53
  5. package/dist/media-audio-runner.js +225 -53
  6. package/dist/media-video-runner.js +225 -53
  7. package/dist/memcode-runtime/CHANGELOG.md +44 -0
  8. package/dist/sdk.js +242 -56
  9. package/dist/vector-backfill-runner.js +225 -53
  10. package/docs/AGENT_OPERATOR_PLAYBOOK.md +7 -0
  11. package/docs/ARCHITECTURE.md +19 -0
  12. package/docs/CONFIGURATION.md +2 -0
  13. package/docs/DEVELOPMENT.md +8 -1
  14. package/docs/MODULES.md +1 -1
  15. package/docs/PERFORMANCE.md +7 -0
  16. package/docs/README.md +3 -1
  17. package/docs/ROADMAP-1.9.12-2.0.md +1 -1
  18. package/package.json +1 -1
  19. package/plugins/antigravity/memorix/plugin.json +1 -1
  20. package/plugins/claude/memorix/.claude-plugin/plugin.json +1 -1
  21. package/plugins/codebuddy/memorix/.codebuddy-plugin/plugin.json +1 -1
  22. package/plugins/codex/memorix/.codex-plugin/plugin.json +1 -1
  23. package/plugins/copilot/memorix/plugin.json +1 -1
  24. package/plugins/gemini/memorix/gemini-extension.json +1 -1
  25. package/plugins/hermes/memorix/plugin.yaml +1 -1
  26. package/plugins/omp/memorix/package.json +1 -1
  27. package/plugins/openclaw/memorix/.codex-plugin/plugin.json +1 -1
  28. package/plugins/pi/memorix/package.json +1 -1
  29. package/server.json +2 -2
  30. package/src/cli/command-guide.ts +3 -1
  31. package/src/cli/commands/http-session-stream-watch.ts +138 -0
  32. package/src/cli/commands/memory.ts +3 -1
  33. package/src/cli/commands/project-detection-cache.ts +61 -0
  34. package/src/cli/commands/serve-http.ts +63 -13
  35. package/src/cli/index.ts +1 -1
  36. package/src/core/derived-view-registry.ts +33 -0
  37. package/src/embedding/api-provider.ts +14 -2
  38. package/src/embedding/ollama-embed.ts +118 -0
  39. package/src/memory/observations.ts +28 -6
  40. package/src/search/semantic-index.ts +38 -6
  41. package/src/store/orama-store.ts +46 -30
@@ -4428,6 +4428,96 @@ var init_transformers_provider = __esm({
4428
4428
  }
4429
4429
  });
4430
4430
 
4431
+ // src/embedding/ollama-embed.ts
4432
+ async function routeOllamaEmbedding(url, body, fetchImpl = fetch, probeOptions) {
4433
+ const parsed = parseUrl(url);
4434
+ if (!parsed) return { url, body, rewritten: false };
4435
+ const openAIRoute = parsed.pathname.endsWith("/v1/embeddings");
4436
+ const nativeRoute = parsed.pathname.endsWith("/api/embed");
4437
+ if (!openAIRoute && !nativeRoute) return { url, body, rewritten: false };
4438
+ if (!await originServesOllama(parsed.origin, fetchImpl, probeOptions)) return { url, body, rewritten: false };
4439
+ if (nativeRoute) return { url, body, rewritten: true };
4440
+ parsed.pathname = parsed.pathname.replace(/\/v1\/embeddings$/, "/api/embed");
4441
+ return { url: parsed.toString(), body: withEmbeddingKeepAlive(body), rewritten: true };
4442
+ }
4443
+ async function originServesOllama(origin, fetchImpl = fetch, probeOptions) {
4444
+ const cached = ollamaOrigins.get(origin);
4445
+ if (cached != null) return cached;
4446
+ if (probeOptions?.signal?.aborted) return false;
4447
+ try {
4448
+ const response = await fetchImpl(`${origin}/api/version`, {
4449
+ method: "GET",
4450
+ signal: buildProbeSignal(probeOptions)
4451
+ });
4452
+ if (!response.ok) {
4453
+ ollamaOrigins.set(origin, false);
4454
+ return false;
4455
+ }
4456
+ const detected = isOllamaVersionPayload(await response.json());
4457
+ ollamaOrigins.set(origin, detected);
4458
+ return detected;
4459
+ } catch (err) {
4460
+ if (isAbortError(err) || probeOptions?.signal?.aborted) return false;
4461
+ ollamaOrigins.set(origin, false);
4462
+ return false;
4463
+ }
4464
+ }
4465
+ function mapOllamaEmbeddingResponse(payload) {
4466
+ if (!payload || typeof payload !== "object") return payload;
4467
+ const record80 = payload;
4468
+ if (Array.isArray(record80.data) || !Array.isArray(record80.embeddings)) return payload;
4469
+ const embeddings = record80.embeddings.filter((item) => Array.isArray(item));
4470
+ return {
4471
+ ...record80,
4472
+ object: "list",
4473
+ data: embeddings.map((embedding, index) => ({
4474
+ object: "embedding",
4475
+ index,
4476
+ embedding
4477
+ }))
4478
+ };
4479
+ }
4480
+ function withEmbeddingKeepAlive(body) {
4481
+ if (body.keep_alive != null && body.keep_alive !== "") return body;
4482
+ return { ...body, keep_alive: OLLAMA_EMBED_KEEP_ALIVE };
4483
+ }
4484
+ function isOllamaVersionPayload(payload) {
4485
+ if (!payload || typeof payload !== "object") return false;
4486
+ const version = payload.version;
4487
+ return typeof version === "string" && /^\d+\.\d+\.\d+/.test(version);
4488
+ }
4489
+ function parseUrl(url) {
4490
+ try {
4491
+ return new URL(url);
4492
+ } catch {
4493
+ return null;
4494
+ }
4495
+ }
4496
+ function buildProbeSignal(probeOptions) {
4497
+ const timeoutMs = Math.max(
4498
+ 1,
4499
+ Math.min(
4500
+ typeof probeOptions?.probeTimeoutMs === "number" && Number.isFinite(probeOptions.probeTimeoutMs) ? Math.floor(probeOptions.probeTimeoutMs) : 1e3,
4501
+ 6e4
4502
+ )
4503
+ );
4504
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
4505
+ if (probeOptions?.signal) return AbortSignal.any([probeOptions.signal, timeoutSignal]);
4506
+ return timeoutSignal;
4507
+ }
4508
+ function isAbortError(err) {
4509
+ return err instanceof Error && err.name === "AbortError";
4510
+ }
4511
+ var OLLAMA_EMBED_KEEP_ALIVE, ollamaOrigins;
4512
+ var init_ollama_embed = __esm({
4513
+ "src/embedding/ollama-embed.ts"() {
4514
+ "use strict";
4515
+ init_esm_shims();
4516
+ OLLAMA_EMBED_KEEP_ALIVE = "5m";
4517
+ ollamaOrigins = /* @__PURE__ */ new Map();
4518
+ }
4519
+ });
4520
+
4431
4521
  // src/embedding/api-provider.ts
4432
4522
  var api_provider_exports = {};
4433
4523
  __export(api_provider_exports, {
@@ -5129,8 +5219,18 @@ function parseBatchLimit(error) {
5129
5219
  return null;
5130
5220
  }
5131
5221
  async function fetchWithRetry(url, apiKey, body, options = {}, attempt = 0, nativeGemini = false) {
5132
- const controller = new AbortController();
5133
5222
  const timeoutMs = typeof options.timeoutMs === "number" && Number.isFinite(options.timeoutMs) ? Math.max(100, Math.min(Math.floor(options.timeoutMs), 6e4)) : 1e4;
5223
+ let rewritten = false;
5224
+ if (!nativeGemini) {
5225
+ const routed = await routeOllamaEmbedding(url, body, fetch, {
5226
+ signal: options.signal,
5227
+ probeTimeoutMs: Math.min(1e3, timeoutMs)
5228
+ });
5229
+ url = routed.url;
5230
+ body = routed.body;
5231
+ rewritten = routed.rewritten;
5232
+ }
5233
+ const controller = new AbortController();
5134
5234
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
5135
5235
  const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
5136
5236
  let response;
@@ -5156,10 +5256,11 @@ async function fetchWithRetry(url, apiKey, body, options = {}, attempt = 0, nati
5156
5256
  }
5157
5257
  try {
5158
5258
  if (response.ok) {
5159
- return await raceWithAbort(
5259
+ const payload = await raceWithAbort(
5160
5260
  response.json(),
5161
5261
  signal
5162
5262
  );
5263
+ return rewritten ? mapOllamaEmbeddingResponse(payload) : payload;
5163
5264
  }
5164
5265
  if (options.retry !== false && (response.status === 429 || response.status >= 500) && attempt < MAX_RETRIES2) {
5165
5266
  const delay3 = BASE_DELAY_MS * Math.pow(2, attempt);
@@ -5236,6 +5337,7 @@ var init_api_provider = __esm({
5236
5337
  "use strict";
5237
5338
  init_esm_shims();
5238
5339
  init_provider2();
5340
+ init_ollama_embed();
5239
5341
  cache3 = /* @__PURE__ */ new Map();
5240
5342
  MAX_CACHE_ENTRIES = 2e5;
5241
5343
  MAX_CACHE_PAYLOAD_BYTES = 256 * 1024 * 1024;
@@ -6534,6 +6636,9 @@ async function openState(dataDir, profile) {
6534
6636
  const table = names.includes(name) ? await connection.openTable(name) : null;
6535
6637
  return { key: stateKey(dataDir, profile), dataDir, profile, connection, table };
6536
6638
  }
6639
+ function semanticVectorKey(projectId, observationId2) {
6640
+ return `${projectId}:${Math.trunc(observationId2)}`;
6641
+ }
6537
6642
  function toLanceRow(record80) {
6538
6643
  return {
6539
6644
  observation_id: record80.observationId,
@@ -6604,7 +6709,7 @@ async function mergeVectors(dataDir, profile, records) {
6604
6709
  const state = await getState(dataDir, profile, records);
6605
6710
  if (!state?.table) return;
6606
6711
  const rows = records.map(toLanceRow);
6607
- await state.table.mergeInsert("observation_id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows);
6712
+ await state.table.mergeInsert(["project_id", "observation_id"]).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows);
6608
6713
  const key = stateKey(dataDir, profile);
6609
6714
  const mutationCount = (mutationCounts.get(key) ?? 0) + 1;
6610
6715
  if (mutationCount >= semanticOptimizeEvery()) {
@@ -6644,11 +6749,18 @@ function upsertSemanticVector(dataDir, profile, record80) {
6644
6749
  function upsertSemanticVectors(dataDir, profile, records) {
6645
6750
  return queueOperation(stateKey(dataDir, profile), () => mergeVectors(dataDir, profile, records));
6646
6751
  }
6647
- async function listSemanticVectorIds(dataDir, profile) {
6752
+ async function listSemanticVectorKeys(dataDir, profile) {
6648
6753
  const state = await getState(dataDir, profile);
6649
6754
  if (!state?.table) return null;
6650
- const rows = await state.table.query().select(["observation_id"]).toArray();
6651
- return new Set(rows.map((row) => Number(row.observation_id)).filter(Number.isSafeInteger));
6755
+ const rows = await state.table.query().select(["observation_id", "project_id"]).toArray();
6756
+ const keys = /* @__PURE__ */ new Set();
6757
+ for (const row of rows) {
6758
+ const observationId2 = Number(row.observation_id);
6759
+ const projectId = String(row.project_id ?? "");
6760
+ if (!Number.isSafeInteger(observationId2) || !projectId) continue;
6761
+ keys.add(semanticVectorKey(projectId, observationId2));
6762
+ }
6763
+ return keys;
6652
6764
  }
6653
6765
  async function getSemanticIndexStats(dataDir, profile) {
6654
6766
  const state = await getState(dataDir, profile);
@@ -6868,6 +6980,37 @@ var init_derived_view_receipt = __esm({
6868
6980
  }
6869
6981
  });
6870
6982
 
6983
+ // src/core/derived-view-registry.ts
6984
+ var DerivedViewRegistry;
6985
+ var init_derived_view_registry = __esm({
6986
+ "src/core/derived-view-registry.ts"() {
6987
+ "use strict";
6988
+ init_esm_shims();
6989
+ DerivedViewRegistry = class {
6990
+ readers = /* @__PURE__ */ new Map();
6991
+ register(name, reader) {
6992
+ const normalized = name.trim();
6993
+ if (!normalized) throw new Error("Derived view name must not be empty");
6994
+ this.readers.set(normalized, reader);
6995
+ return () => {
6996
+ if (this.readers.get(normalized) === reader) this.readers.delete(normalized);
6997
+ };
6998
+ }
6999
+ snapshot() {
7000
+ const result = {};
7001
+ for (const [name, reader] of this.readers) {
7002
+ try {
7003
+ result[name] = reader();
7004
+ } catch {
7005
+ result[name] = { state: "degraded", reason: "derived view reader failed" };
7006
+ }
7007
+ }
7008
+ return result;
7009
+ }
7010
+ };
7011
+ }
7012
+ });
7013
+
6871
7014
  // src/project/aliases.ts
6872
7015
  var aliases_exports = {};
6873
7016
  __export(aliases_exports, {
@@ -7519,15 +7662,17 @@ function getLastSearchDiagnostics(projectId) {
7519
7662
  return diagnostics ? { ...diagnostics } : void 0;
7520
7663
  }
7521
7664
  function getSearchDerivedViews() {
7522
- const views = {};
7665
+ return searchDerivedViewRegistry.snapshot();
7666
+ }
7667
+ function readFtsDerivedViewReceipt() {
7523
7668
  const store = getOptionalObservationStore();
7524
7669
  if (store) {
7525
7670
  try {
7526
7671
  const generation = store.getGeneration();
7527
7672
  if (store.hasLexicalIndex?.()) {
7528
- views.fts = { generation, freshness: "current", rebuildStatus: "idle" };
7673
+ return { generation, freshness: "current", rebuildStatus: "idle" };
7529
7674
  } else {
7530
- views.fts = {
7675
+ return {
7531
7676
  generation,
7532
7677
  freshness: "unknown",
7533
7678
  rebuildStatus: "unavailable",
@@ -7537,32 +7682,34 @@ function getSearchDerivedViews() {
7537
7682
  };
7538
7683
  }
7539
7684
  } catch (error) {
7540
- views.fts = {
7685
+ return {
7541
7686
  freshness: "unknown",
7542
7687
  rebuildStatus: "failed",
7543
7688
  failureReason: sanitizeDerivedViewFailureReason(error instanceof Error ? error.message : String(error))
7544
7689
  };
7545
7690
  }
7546
- } else {
7547
- views.fts = {
7548
- freshness: "unknown",
7549
- rebuildStatus: "unavailable",
7550
- failureReason: "observation store is not initialized"
7551
- };
7552
7691
  }
7553
- views.orama = db ? { generation: dbGeneration, freshness: "current", rebuildStatus: "idle" } : {
7692
+ return {
7693
+ freshness: "unknown",
7694
+ rebuildStatus: "unavailable",
7695
+ failureReason: "observation store is not initialized"
7696
+ };
7697
+ }
7698
+ function readOramaDerivedViewReceipt() {
7699
+ return db ? { generation: dbGeneration, freshness: "current", rebuildStatus: "idle" } : {
7554
7700
  generation: dbGeneration,
7555
7701
  freshness: "unknown",
7556
7702
  rebuildStatus: "unavailable",
7557
7703
  failureReason: "Orama index is not initialized"
7558
7704
  };
7705
+ }
7706
+ function readEmbeddingDerivedViewReceipt() {
7559
7707
  let embeddingHealth;
7560
7708
  try {
7561
7709
  embeddingHealth = getEmbeddingRuntimeHealth?.();
7562
7710
  } catch {
7563
7711
  }
7564
- views.embedding = embeddingHealthReceipt(embeddingHealth, embeddingEnabled);
7565
- return views;
7712
+ return embeddingHealthReceipt(embeddingHealth, embeddingEnabled);
7566
7713
  }
7567
7714
  function rememberSearchDiagnostics(key, value) {
7568
7715
  if (!lastSearchDiagnosticsByProject.has(key) && lastSearchDiagnosticsByProject.size >= MAX_SEARCH_MODE_KEYS) {
@@ -7699,10 +7846,12 @@ async function searchLanceInVectorOrder(options, projectIds, limit2, queryVector
7699
7846
  const hits = [];
7700
7847
  const seen = /* @__PURE__ */ new Set();
7701
7848
  for (const hit of vectorHits) {
7702
- if (seen.has(hit.observationId)) continue;
7703
- seen.add(hit.observationId);
7849
+ if (projectIds ? !projectIds.includes(hit.projectId) : options.projectId && hit.projectId !== options.projectId) continue;
7850
+ const key = semanticVectorKey(hit.projectId, hit.observationId);
7851
+ if (seen.has(key)) continue;
7852
+ seen.add(key);
7704
7853
  const observation = await store.getById(hit.observationId);
7705
- if (!observation) continue;
7854
+ if (!observation || observation.projectId !== hit.projectId) continue;
7706
7855
  if (projectIds && !projectIds.includes(observation.projectId)) continue;
7707
7856
  if (options.status !== "all" && (observation.status ?? "active") !== (options.status ?? "active")) continue;
7708
7857
  if (options.type && observation.type !== options.type) continue;
@@ -7748,14 +7897,15 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
7748
7897
  documents.set(makeEntryKey(hit.document.projectId, hit.document.observationId), hit.document);
7749
7898
  }
7750
7899
  const vectorObservations = await Promise.all(vectorHits.map(async (hit) => {
7900
+ if (projectIds ? !projectIds.includes(hit.projectId) : options.projectId && hit.projectId !== options.projectId) return null;
7751
7901
  const observation = await store.getById(hit.observationId);
7752
- if (!observation) return null;
7902
+ if (!observation || observation.projectId !== hit.projectId) return null;
7753
7903
  if (projectIds && !projectIds.includes(observation.projectId)) return null;
7754
7904
  if (options.status !== "all" && (observation.status ?? "active") !== (options.status ?? "active")) return null;
7755
7905
  if (options.type && observation.type !== options.type) return null;
7756
7906
  if (options.source && observation.source !== options.source) return null;
7757
7907
  addObservation(observation);
7758
- vectorDocumentKeys.set(hit.observationId, makeEntryKey(observation.projectId, observation.id));
7908
+ vectorDocumentKeys.set(semanticVectorKey(hit.projectId, hit.observationId), makeEntryKey(observation.projectId, observation.id));
7759
7909
  return observation;
7760
7910
  }));
7761
7911
  const RRF_K = 60;
@@ -7765,7 +7915,8 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
7765
7915
  scores.set(key, (scores.get(key) ?? 0) + 0.6 / (RRF_K + index + 1));
7766
7916
  }
7767
7917
  for (const [index, hit] of vectorHits.entries()) {
7768
- const key = vectorDocumentKeys.get(hit.observationId) ?? makeEntryKey(hit.projectId, hit.observationId);
7918
+ const key = vectorDocumentKeys.get(semanticVectorKey(hit.projectId, hit.observationId));
7919
+ if (!key) continue;
7769
7920
  if (!documents.has(key)) continue;
7770
7921
  scores.set(key, (scores.get(key) ?? 0) + 0.4 / (RRF_K + index + 1));
7771
7922
  }
@@ -7778,8 +7929,8 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
7778
7929
  return {
7779
7930
  count: vectorHits.length,
7780
7931
  hits: vectorHits.map((hit, index) => {
7781
- const key = vectorDocumentKeys.get(hit.observationId) ?? makeEntryKey(hit.projectId, hit.observationId);
7782
- const document2 = documents.get(key);
7932
+ const key = vectorDocumentKeys.get(semanticVectorKey(hit.projectId, hit.observationId));
7933
+ const document2 = key ? documents.get(key) : void 0;
7783
7934
  return document2 ? { id: document2.id, score: 0.4 / (RRF_K + index + 1), document: document2 } : null;
7784
7935
  }).filter((hit) => hit !== null).slice(0, limit2)
7785
7936
  };
@@ -7910,7 +8061,7 @@ function getActiveSemanticIndexProfile() {
7910
8061
  }
7911
8062
  async function getPersistentSemanticVectorIds(dataDir) {
7912
8063
  if (!indexEmbeddingProvider) return null;
7913
- return listSemanticVectorIds(dataDir, createSemanticIndexProfile(indexEmbeddingProvider));
8064
+ return listSemanticVectorKeys(dataDir, createSemanticIndexProfile(indexEmbeddingProvider));
7914
8065
  }
7915
8066
  async function queueSemanticVector(dataDir, record80) {
7916
8067
  const provider2 = indexEmbeddingProvider ?? await getEmbeddingProvider();
@@ -7979,7 +8130,7 @@ function isCompatibleCachedVector(vector) {
7979
8130
  async function attachCachedVectors(database, observations2) {
7980
8131
  const semanticDataDir = (await Promise.resolve().then(() => (init_observations(), observations_exports))).getObservationDataDir();
7981
8132
  const semanticProfile = getActiveSemanticIndexProfile();
7982
- const persistedSemanticIds = semanticDataDir && semanticProfile ? await listSemanticVectorIds(semanticDataDir, semanticProfile).catch(() => null) : null;
8133
+ const persistedSemanticIds = semanticDataDir && semanticProfile ? await listSemanticVectorKeys(semanticDataDir, semanticProfile).catch(() => null) : null;
7983
8134
  const batchSize = 200;
7984
8135
  for (let start = 0; start < observations2.length; start += batchSize) {
7985
8136
  const batch = observations2.slice(start, start + batchSize);
@@ -7990,7 +8141,7 @@ async function attachCachedVectors(database, observations2) {
7990
8141
  const vector = cachedVectors[index];
7991
8142
  if (!isCompatibleCachedVector(vector)) continue;
7992
8143
  const observation = batch[index];
7993
- if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(observation.id)) {
8144
+ if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(semanticVectorKey(observation.projectId, observation.id))) {
7994
8145
  semanticRecords.push({
7995
8146
  observationId: observation.id,
7996
8147
  projectId: observation.projectId,
@@ -8780,7 +8931,7 @@ function formatTime(isoDate) {
8780
8931
  return isoDate;
8781
8932
  }
8782
8933
  }
8783
- var db, dbInitPromise, dbGeneration, embeddingEnabled, embeddingDimensions, indexEmbeddingProvider, deferredCachedVectorHydration, NON_CJK_HYBRID_SIMILARITY, CJK_RUN, lastSearchModeByProject, lastSearchDiagnosticsByProject, SEARCH_MODE_DEFAULT_KEY, MAX_SEARCH_MODE_KEYS, COMMAND_LOG_TITLE, COMMAND_STYLE_TITLE, COMMAND_LIKE_QUERY2, COMMAND_INTENT_QUERY, NATURAL_LANGUAGE_MARKERS;
8934
+ var db, dbInitPromise, dbGeneration, embeddingEnabled, embeddingDimensions, indexEmbeddingProvider, deferredCachedVectorHydration, NON_CJK_HYBRID_SIMILARITY, CJK_RUN, lastSearchModeByProject, lastSearchDiagnosticsByProject, searchDerivedViewRegistry, SEARCH_MODE_DEFAULT_KEY, MAX_SEARCH_MODE_KEYS, COMMAND_LOG_TITLE, COMMAND_STYLE_TITLE, COMMAND_LIKE_QUERY2, COMMAND_INTENT_QUERY, NATURAL_LANGUAGE_MARKERS;
8784
8935
  var init_orama_store = __esm({
8785
8936
  "src/store/orama-store.ts"() {
8786
8937
  "use strict";
@@ -8802,6 +8953,7 @@ var init_orama_store = __esm({
8802
8953
  init_retrieval_contracts();
8803
8954
  init_semantic_index();
8804
8955
  init_derived_view_receipt();
8956
+ init_derived_view_registry();
8805
8957
  db = null;
8806
8958
  dbInitPromise = null;
8807
8959
  dbGeneration = 0;
@@ -8813,8 +8965,12 @@ var init_orama_store = __esm({
8813
8965
  CJK_RUN = /[\u3400-\u4dbf\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]+/gu;
8814
8966
  lastSearchModeByProject = /* @__PURE__ */ new Map();
8815
8967
  lastSearchDiagnosticsByProject = /* @__PURE__ */ new Map();
8968
+ searchDerivedViewRegistry = new DerivedViewRegistry();
8816
8969
  SEARCH_MODE_DEFAULT_KEY = "__global__";
8817
8970
  MAX_SEARCH_MODE_KEYS = 4096;
8971
+ searchDerivedViewRegistry.register("fts", readFtsDerivedViewReceipt);
8972
+ searchDerivedViewRegistry.register("orama", readOramaDerivedViewReceipt);
8973
+ searchDerivedViewRegistry.register("embedding", readEmbeddingDerivedViewReceipt);
8818
8974
  COMMAND_LOG_TITLE = /^(Ran:|Command:|Executed:)\s/i;
8819
8975
  COMMAND_STYLE_TITLE = /(\bfindstr\b|\bSelect-String\b|\bGet-Content\b|\bnpx\s+vitest\b|\bnpx\s+tsc\b|\b2>&1\b)/i;
8820
8976
  COMMAND_LIKE_QUERY2 = /\b(git|npm|npx|pnpm|yarn|node|bash|powershell|curl|memorix)\b/i;
@@ -19603,7 +19759,7 @@ var init_uuid = __esm({
19603
19759
  });
19604
19760
 
19605
19761
  // node_modules/openai/internal/errors.mjs
19606
- function isAbortError(err) {
19762
+ function isAbortError2(err) {
19607
19763
  return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
19608
19764
  ("name" in err && err.name === "AbortError" || // Expo fetch
19609
19765
  "message" in err && String(err.message).includes("FetchRequestCanceledException"));
@@ -20783,7 +20939,7 @@ var init_streaming = __esm({
20783
20939
  }
20784
20940
  done = true;
20785
20941
  } catch (e2) {
20786
- if (isAbortError(e2))
20942
+ if (isAbortError2(e2))
20787
20943
  return;
20788
20944
  throw e2;
20789
20945
  } finally {
@@ -20826,7 +20982,7 @@ var init_streaming = __esm({
20826
20982
  }
20827
20983
  done = true;
20828
20984
  } catch (e2) {
20829
- if (isAbortError(e2))
20985
+ if (isAbortError2(e2))
20830
20986
  return;
20831
20987
  throw e2;
20832
20988
  } finally {
@@ -27375,7 +27531,7 @@ var init_client = __esm({
27375
27531
  if (options.signal?.aborted) {
27376
27532
  throw new APIUserAbortError();
27377
27533
  }
27378
- const isTimeout = isAbortError(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
27534
+ const isTimeout = isAbortError2(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
27379
27535
  if (retriesRemaining) {
27380
27536
  loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
27381
27537
  loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails({
@@ -46464,7 +46620,7 @@ var init_uuid2 = __esm({
46464
46620
  });
46465
46621
 
46466
46622
  // node_modules/@anthropic-ai/sdk/internal/errors.mjs
46467
- function isAbortError2(err) {
46623
+ function isAbortError3(err) {
46468
46624
  return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
46469
46625
  ("name" in err && err.name === "AbortError" || // Expo fetch
46470
46626
  "message" in err && String(err.message).includes("FetchRequestCanceledException"));
@@ -47235,7 +47391,7 @@ var init_streaming3 = __esm({
47235
47391
  }
47236
47392
  done = true;
47237
47393
  } catch (e2) {
47238
- if (isAbortError2(e2))
47394
+ if (isAbortError3(e2))
47239
47395
  return;
47240
47396
  throw e2;
47241
47397
  } finally {
@@ -47278,7 +47434,7 @@ var init_streaming3 = __esm({
47278
47434
  }
47279
47435
  done = true;
47280
47436
  } catch (e2) {
47281
- if (isAbortError2(e2))
47437
+ if (isAbortError3(e2))
47282
47438
  return;
47283
47439
  throw e2;
47284
47440
  } finally {
@@ -49400,7 +49556,7 @@ var init_BetaMessageStream = __esm({
49400
49556
  _BetaMessageStream_logger.set(this, void 0);
49401
49557
  _BetaMessageStream_handleError.set(this, (error) => {
49402
49558
  __classPrivateFieldSet2(this, _BetaMessageStream_errored, true, "f");
49403
- if (isAbortError2(error)) {
49559
+ if (isAbortError3(error)) {
49404
49560
  error = new APIUserAbortError2();
49405
49561
  }
49406
49562
  if (error instanceof APIUserAbortError2) {
@@ -51861,7 +52017,7 @@ var init_MessageStream = __esm({
51861
52017
  _MessageStream_logger.set(this, void 0);
51862
52018
  _MessageStream_handleError.set(this, (error) => {
51863
52019
  __classPrivateFieldSet2(this, _MessageStream_errored, true, "f");
51864
- if (isAbortError2(error)) {
52020
+ if (isAbortError3(error)) {
51865
52021
  error = new APIUserAbortError2();
51866
52022
  }
51867
52023
  if (error instanceof APIUserAbortError2) {
@@ -52991,7 +53147,7 @@ var init_client2 = __esm({
52991
53147
  if (options.signal?.aborted) {
52992
53148
  throw new APIUserAbortError2();
52993
53149
  }
52994
- const isTimeout = isAbortError2(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
53150
+ const isTimeout = isAbortError3(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
52995
53151
  if (retriesRemaining) {
52996
53152
  loggerFor2(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
52997
53153
  loggerFor2(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails2({
@@ -87499,7 +87655,7 @@ function listDocumentsResponseFromMldev(fromObject) {
87499
87655
  }
87500
87656
  return toObject;
87501
87657
  }
87502
- function isAbortError3(err) {
87658
+ function isAbortError4(err) {
87503
87659
  return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
87504
87660
  ("name" in err && err.name === "AbortError" || // Expo fetch
87505
87661
  "message" in err && String(err.message).includes("FetchRequestCanceledException"));
@@ -94713,7 +94869,7 @@ ${underline}`);
94713
94869
  }
94714
94870
  done = true;
94715
94871
  } catch (e2) {
94716
- if (isAbortError3(e2))
94872
+ if (isAbortError4(e2))
94717
94873
  return yield __await(void 0);
94718
94874
  throw e2;
94719
94875
  } finally {
@@ -94788,7 +94944,7 @@ ${underline}`);
94788
94944
  }
94789
94945
  done = true;
94790
94946
  } catch (e2) {
94791
- if (isAbortError3(e2))
94947
+ if (isAbortError4(e2))
94792
94948
  return yield __await(void 0);
94793
94949
  throw e2;
94794
94950
  } finally {
@@ -95164,7 +95320,7 @@ ${underline}`);
95164
95320
  if ((_d = options.signal) === null || _d === void 0 ? void 0 : _d.aborted) {
95165
95321
  throw new APIUserAbortError3();
95166
95322
  }
95167
- const isTimeout = isAbortError3(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
95323
+ const isTimeout = isAbortError4(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
95168
95324
  if (retriesRemaining) {
95169
95325
  loggerFor3(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
95170
95326
  loggerFor3(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails3({
@@ -97388,7 +97544,7 @@ function isTimeoutError(err) {
97388
97544
  const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
97389
97545
  return isNative || isLegacyNative || isGenericErr;
97390
97546
  }
97391
- function isAbortError4(err) {
97547
+ function isAbortError5(err) {
97392
97548
  if (typeof err !== "object" || err == null) {
97393
97549
  return false;
97394
97550
  }
@@ -98400,7 +98556,7 @@ var init_sdks = __esm({
98400
98556
  return response;
98401
98557
  }, { config: options.retryConfig, statusCodes: options.retryCodes }).then((r2) => OK(r2), (err) => {
98402
98558
  switch (true) {
98403
- case isAbortError4(err):
98559
+ case isAbortError5(err):
98404
98560
  return ERR(new RequestAbortedError("Request aborted by client", {
98405
98561
  cause: err
98406
98562
  }));
@@ -152281,13 +152437,17 @@ async function enqueueObservationDerivedWork(tx, observation) {
152281
152437
  payload: { observationId: observation.id }
152282
152438
  });
152283
152439
  }
152440
+ await enqueueObservationProjectionWork(tx, observation);
152441
+ return true;
152442
+ }
152443
+ async function enqueueObservationProjectionWork(tx, observation) {
152444
+ if (!tx.enqueueMaintenanceJob) return;
152284
152445
  await tx.enqueueMaintenanceJob({
152285
152446
  projectId: observation.projectId,
152286
152447
  kind: "observation-project",
152287
152448
  dedupeKey: "observation-project:" + observation.id,
152288
152449
  payload: { observationId: observation.id }
152289
152450
  });
152290
- return true;
152291
152451
  }
152292
152452
  function isVectorCompatibleWithCurrentIndex(embedding) {
152293
152453
  if (!embedding) return false;
@@ -152821,6 +152981,7 @@ async function updateObservationAdmission(input) {
152821
152981
  const next = apply(current);
152822
152982
  if (!next) return;
152823
152983
  await tx.update(next);
152984
+ await enqueueObservationProjectionWork(tx, next);
152824
152985
  updated = next;
152825
152986
  });
152826
152987
  } else {
@@ -152838,6 +152999,9 @@ async function updateObservationAdmission(input) {
152838
152999
  });
152839
153000
  } catch {
152840
153001
  }
153002
+ if (await persistEvidenceCard(updated)) {
153003
+ await acknowledgeObservationProjection(updated);
153004
+ }
152841
153005
  if (updated.admissionState === "qualified" && resolveObservationVisibility(updated) === "project") {
152842
153006
  queueClaimDerivation(updated);
152843
153007
  }
@@ -152908,10 +153072,17 @@ async function resolveObservations(ids, status = "resolved") {
152908
153072
  if (projectDir && resolved.length > 0) {
152909
153073
  const store = getObservationStore();
152910
153074
  await store.atomic(async (tx) => {
152911
- await Promise.all(changed.map((observation) => tx.update(observation)));
153075
+ await Promise.all(changed.map(async (observation) => {
153076
+ await tx.update(observation);
153077
+ await enqueueObservationProjectionWork(tx, observation);
153078
+ }));
152912
153079
  });
152913
153080
  }
152914
- for (const observation of changed) await persistEvidenceCard(observation);
153081
+ for (const observation of changed) {
153082
+ if (await persistEvidenceCard(observation)) {
153083
+ await acknowledgeObservationProjection(observation);
153084
+ }
153085
+ }
152915
153086
  return { resolved, notFound };
152916
153087
  }
152917
153088
  function getProjectObservations(projectId) {
@@ -153064,9 +153235,9 @@ async function prepareSearchIndex(options = {}) {
153064
153235
  for (const projectId of projects) {
153065
153236
  const projectObservations = await store.loadByProject(projectId);
153066
153237
  for (const observation of projectObservations) {
153067
- if (!persistedIds?.has(observation.id)) markVectorMissing(observation.id, observation.projectId);
153238
+ if (!persistedIds?.has(semanticVectorKey(observation.projectId, observation.id))) markVectorMissing(observation.id, observation.projectId);
153068
153239
  }
153069
- if (projectObservations.some((observation) => !persistedIds?.has(observation.id))) {
153240
+ if (projectObservations.some((observation) => !persistedIds?.has(semanticVectorKey(observation.projectId, observation.id)))) {
153070
153241
  queueVectorBackfill(projectId);
153071
153242
  }
153072
153243
  }
@@ -153088,7 +153259,7 @@ async function prepareSearchIndex(options = {}) {
153088
153259
  const persistedSemanticIds = await getPersistentSemanticVectorIds(hydratedProjectDir).catch(() => null);
153089
153260
  const projectsWithMissingVectors = /* @__PURE__ */ new Set();
153090
153261
  for (const obs of observations) {
153091
- if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(obs.id)) {
153262
+ if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(semanticVectorKey(obs.projectId, obs.id))) {
153092
153263
  markVectorMissing(obs.id, obs.projectId);
153093
153264
  projectsWithMissingVectors.add(obs.projectId);
153094
153265
  }
@@ -153292,6 +153463,7 @@ var init_observations = __esm({
153292
153463
  init_token_budget();
153293
153464
  init_entity_extractor();
153294
153465
  init_provider2();
153466
+ init_semantic_index();
153295
153467
  init_secret_filter();
153296
153468
  init_lifecycle();
153297
153469
  init_visibility();