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
@@ -3151,6 +3151,96 @@ var init_transformers_provider = __esm({
3151
3151
  }
3152
3152
  });
3153
3153
 
3154
+ // src/embedding/ollama-embed.ts
3155
+ async function routeOllamaEmbedding(url, body, fetchImpl = fetch, probeOptions) {
3156
+ const parsed = parseUrl(url);
3157
+ if (!parsed) return { url, body, rewritten: false };
3158
+ const openAIRoute = parsed.pathname.endsWith("/v1/embeddings");
3159
+ const nativeRoute = parsed.pathname.endsWith("/api/embed");
3160
+ if (!openAIRoute && !nativeRoute) return { url, body, rewritten: false };
3161
+ if (!await originServesOllama(parsed.origin, fetchImpl, probeOptions)) return { url, body, rewritten: false };
3162
+ if (nativeRoute) return { url, body, rewritten: true };
3163
+ parsed.pathname = parsed.pathname.replace(/\/v1\/embeddings$/, "/api/embed");
3164
+ return { url: parsed.toString(), body: withEmbeddingKeepAlive(body), rewritten: true };
3165
+ }
3166
+ async function originServesOllama(origin, fetchImpl = fetch, probeOptions) {
3167
+ const cached = ollamaOrigins.get(origin);
3168
+ if (cached != null) return cached;
3169
+ if (probeOptions?.signal?.aborted) return false;
3170
+ try {
3171
+ const response = await fetchImpl(`${origin}/api/version`, {
3172
+ method: "GET",
3173
+ signal: buildProbeSignal(probeOptions)
3174
+ });
3175
+ if (!response.ok) {
3176
+ ollamaOrigins.set(origin, false);
3177
+ return false;
3178
+ }
3179
+ const detected = isOllamaVersionPayload(await response.json());
3180
+ ollamaOrigins.set(origin, detected);
3181
+ return detected;
3182
+ } catch (err) {
3183
+ if (isAbortError(err) || probeOptions?.signal?.aborted) return false;
3184
+ ollamaOrigins.set(origin, false);
3185
+ return false;
3186
+ }
3187
+ }
3188
+ function mapOllamaEmbeddingResponse(payload) {
3189
+ if (!payload || typeof payload !== "object") return payload;
3190
+ const record80 = payload;
3191
+ if (Array.isArray(record80.data) || !Array.isArray(record80.embeddings)) return payload;
3192
+ const embeddings = record80.embeddings.filter((item) => Array.isArray(item));
3193
+ return {
3194
+ ...record80,
3195
+ object: "list",
3196
+ data: embeddings.map((embedding, index) => ({
3197
+ object: "embedding",
3198
+ index,
3199
+ embedding
3200
+ }))
3201
+ };
3202
+ }
3203
+ function withEmbeddingKeepAlive(body) {
3204
+ if (body.keep_alive != null && body.keep_alive !== "") return body;
3205
+ return { ...body, keep_alive: OLLAMA_EMBED_KEEP_ALIVE };
3206
+ }
3207
+ function isOllamaVersionPayload(payload) {
3208
+ if (!payload || typeof payload !== "object") return false;
3209
+ const version = payload.version;
3210
+ return typeof version === "string" && /^\d+\.\d+\.\d+/.test(version);
3211
+ }
3212
+ function parseUrl(url) {
3213
+ try {
3214
+ return new URL(url);
3215
+ } catch {
3216
+ return null;
3217
+ }
3218
+ }
3219
+ function buildProbeSignal(probeOptions) {
3220
+ const timeoutMs = Math.max(
3221
+ 1,
3222
+ Math.min(
3223
+ typeof probeOptions?.probeTimeoutMs === "number" && Number.isFinite(probeOptions.probeTimeoutMs) ? Math.floor(probeOptions.probeTimeoutMs) : 1e3,
3224
+ 6e4
3225
+ )
3226
+ );
3227
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
3228
+ if (probeOptions?.signal) return AbortSignal.any([probeOptions.signal, timeoutSignal]);
3229
+ return timeoutSignal;
3230
+ }
3231
+ function isAbortError(err) {
3232
+ return err instanceof Error && err.name === "AbortError";
3233
+ }
3234
+ var OLLAMA_EMBED_KEEP_ALIVE, ollamaOrigins;
3235
+ var init_ollama_embed = __esm({
3236
+ "src/embedding/ollama-embed.ts"() {
3237
+ "use strict";
3238
+ init_esm_shims();
3239
+ OLLAMA_EMBED_KEEP_ALIVE = "5m";
3240
+ ollamaOrigins = /* @__PURE__ */ new Map();
3241
+ }
3242
+ });
3243
+
3154
3244
  // src/embedding/api-provider.ts
3155
3245
  var api_provider_exports = {};
3156
3246
  __export(api_provider_exports, {
@@ -3852,8 +3942,18 @@ function parseBatchLimit(error) {
3852
3942
  return null;
3853
3943
  }
3854
3944
  async function fetchWithRetry(url, apiKey, body, options = {}, attempt = 0, nativeGemini = false) {
3855
- const controller = new AbortController();
3856
3945
  const timeoutMs = typeof options.timeoutMs === "number" && Number.isFinite(options.timeoutMs) ? Math.max(100, Math.min(Math.floor(options.timeoutMs), 6e4)) : 1e4;
3946
+ let rewritten = false;
3947
+ if (!nativeGemini) {
3948
+ const routed = await routeOllamaEmbedding(url, body, fetch, {
3949
+ signal: options.signal,
3950
+ probeTimeoutMs: Math.min(1e3, timeoutMs)
3951
+ });
3952
+ url = routed.url;
3953
+ body = routed.body;
3954
+ rewritten = routed.rewritten;
3955
+ }
3956
+ const controller = new AbortController();
3857
3957
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
3858
3958
  const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
3859
3959
  let response;
@@ -3879,10 +3979,11 @@ async function fetchWithRetry(url, apiKey, body, options = {}, attempt = 0, nati
3879
3979
  }
3880
3980
  try {
3881
3981
  if (response.ok) {
3882
- return await raceWithAbort(
3982
+ const payload = await raceWithAbort(
3883
3983
  response.json(),
3884
3984
  signal
3885
3985
  );
3986
+ return rewritten ? mapOllamaEmbeddingResponse(payload) : payload;
3886
3987
  }
3887
3988
  if (options.retry !== false && (response.status === 429 || response.status >= 500) && attempt < MAX_RETRIES2) {
3888
3989
  const delay3 = BASE_DELAY_MS * Math.pow(2, attempt);
@@ -3959,6 +4060,7 @@ var init_api_provider = __esm({
3959
4060
  "use strict";
3960
4061
  init_esm_shims();
3961
4062
  init_provider();
4063
+ init_ollama_embed();
3962
4064
  cache3 = /* @__PURE__ */ new Map();
3963
4065
  MAX_CACHE_ENTRIES = 2e5;
3964
4066
  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;
@@ -11266,13 +11422,17 @@ async function enqueueObservationDerivedWork(tx, observation) {
11266
11422
  payload: { observationId: observation.id }
11267
11423
  });
11268
11424
  }
11425
+ await enqueueObservationProjectionWork(tx, observation);
11426
+ return true;
11427
+ }
11428
+ async function enqueueObservationProjectionWork(tx, observation) {
11429
+ if (!tx.enqueueMaintenanceJob) return;
11269
11430
  await tx.enqueueMaintenanceJob({
11270
11431
  projectId: observation.projectId,
11271
11432
  kind: "observation-project",
11272
11433
  dedupeKey: "observation-project:" + observation.id,
11273
11434
  payload: { observationId: observation.id }
11274
11435
  });
11275
- return true;
11276
11436
  }
11277
11437
  function isVectorCompatibleWithCurrentIndex(embedding) {
11278
11438
  if (!embedding) return false;
@@ -11806,6 +11966,7 @@ async function updateObservationAdmission(input) {
11806
11966
  const next = apply(current);
11807
11967
  if (!next) return;
11808
11968
  await tx.update(next);
11969
+ await enqueueObservationProjectionWork(tx, next);
11809
11970
  updated = next;
11810
11971
  });
11811
11972
  } else {
@@ -11823,6 +11984,9 @@ async function updateObservationAdmission(input) {
11823
11984
  });
11824
11985
  } catch {
11825
11986
  }
11987
+ if (await persistEvidenceCard(updated)) {
11988
+ await acknowledgeObservationProjection(updated);
11989
+ }
11826
11990
  if (updated.admissionState === "qualified" && resolveObservationVisibility(updated) === "project") {
11827
11991
  queueClaimDerivation(updated);
11828
11992
  }
@@ -11893,10 +12057,17 @@ async function resolveObservations(ids, status = "resolved") {
11893
12057
  if (projectDir && resolved.length > 0) {
11894
12058
  const store = getObservationStore();
11895
12059
  await store.atomic(async (tx) => {
11896
- await Promise.all(changed.map((observation) => tx.update(observation)));
12060
+ await Promise.all(changed.map(async (observation) => {
12061
+ await tx.update(observation);
12062
+ await enqueueObservationProjectionWork(tx, observation);
12063
+ }));
11897
12064
  });
11898
12065
  }
11899
- for (const observation of changed) await persistEvidenceCard(observation);
12066
+ for (const observation of changed) {
12067
+ if (await persistEvidenceCard(observation)) {
12068
+ await acknowledgeObservationProjection(observation);
12069
+ }
12070
+ }
11900
12071
  return { resolved, notFound };
11901
12072
  }
11902
12073
  function getProjectObservations(projectId) {
@@ -12049,9 +12220,9 @@ async function prepareSearchIndex(options = {}) {
12049
12220
  for (const projectId of projects) {
12050
12221
  const projectObservations = await store.loadByProject(projectId);
12051
12222
  for (const observation of projectObservations) {
12052
- if (!persistedIds?.has(observation.id)) markVectorMissing(observation.id, observation.projectId);
12223
+ if (!persistedIds?.has(semanticVectorKey(observation.projectId, observation.id))) markVectorMissing(observation.id, observation.projectId);
12053
12224
  }
12054
- if (projectObservations.some((observation) => !persistedIds?.has(observation.id))) {
12225
+ if (projectObservations.some((observation) => !persistedIds?.has(semanticVectorKey(observation.projectId, observation.id)))) {
12055
12226
  queueVectorBackfill(projectId);
12056
12227
  }
12057
12228
  }
@@ -12073,7 +12244,7 @@ async function prepareSearchIndex(options = {}) {
12073
12244
  const persistedSemanticIds = await getPersistentSemanticVectorIds(hydratedProjectDir).catch(() => null);
12074
12245
  const projectsWithMissingVectors = /* @__PURE__ */ new Set();
12075
12246
  for (const obs of observations) {
12076
- if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(obs.id)) {
12247
+ if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(semanticVectorKey(obs.projectId, obs.id))) {
12077
12248
  markVectorMissing(obs.id, obs.projectId);
12078
12249
  projectsWithMissingVectors.add(obs.projectId);
12079
12250
  }
@@ -12277,6 +12448,7 @@ var init_observations = __esm({
12277
12448
  init_token_budget();
12278
12449
  init_entity_extractor();
12279
12450
  init_provider();
12451
+ init_semantic_index();
12280
12452
  init_secret_filter();
12281
12453
  init_lifecycle();
12282
12454
  init_visibility();
@@ -22063,7 +22235,7 @@ var init_uuid = __esm({
22063
22235
  });
22064
22236
 
22065
22237
  // node_modules/openai/internal/errors.mjs
22066
- function isAbortError(err) {
22238
+ function isAbortError2(err) {
22067
22239
  return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
22068
22240
  ("name" in err && err.name === "AbortError" || // Expo fetch
22069
22241
  "message" in err && String(err.message).includes("FetchRequestCanceledException"));
@@ -23243,7 +23415,7 @@ var init_streaming = __esm({
23243
23415
  }
23244
23416
  done = true;
23245
23417
  } catch (e2) {
23246
- if (isAbortError(e2))
23418
+ if (isAbortError2(e2))
23247
23419
  return;
23248
23420
  throw e2;
23249
23421
  } finally {
@@ -23286,7 +23458,7 @@ var init_streaming = __esm({
23286
23458
  }
23287
23459
  done = true;
23288
23460
  } catch (e2) {
23289
- if (isAbortError(e2))
23461
+ if (isAbortError2(e2))
23290
23462
  return;
23291
23463
  throw e2;
23292
23464
  } finally {
@@ -29835,7 +30007,7 @@ var init_client = __esm({
29835
30007
  if (options.signal?.aborted) {
29836
30008
  throw new APIUserAbortError();
29837
30009
  }
29838
- const isTimeout = isAbortError(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
30010
+ const isTimeout = isAbortError2(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
29839
30011
  if (retriesRemaining) {
29840
30012
  loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
29841
30013
  loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails({
@@ -48924,7 +49096,7 @@ var init_uuid2 = __esm({
48924
49096
  });
48925
49097
 
48926
49098
  // node_modules/@anthropic-ai/sdk/internal/errors.mjs
48927
- function isAbortError2(err) {
49099
+ function isAbortError3(err) {
48928
49100
  return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
48929
49101
  ("name" in err && err.name === "AbortError" || // Expo fetch
48930
49102
  "message" in err && String(err.message).includes("FetchRequestCanceledException"));
@@ -49695,7 +49867,7 @@ var init_streaming3 = __esm({
49695
49867
  }
49696
49868
  done = true;
49697
49869
  } catch (e2) {
49698
- if (isAbortError2(e2))
49870
+ if (isAbortError3(e2))
49699
49871
  return;
49700
49872
  throw e2;
49701
49873
  } finally {
@@ -49738,7 +49910,7 @@ var init_streaming3 = __esm({
49738
49910
  }
49739
49911
  done = true;
49740
49912
  } catch (e2) {
49741
- if (isAbortError2(e2))
49913
+ if (isAbortError3(e2))
49742
49914
  return;
49743
49915
  throw e2;
49744
49916
  } finally {
@@ -51860,7 +52032,7 @@ var init_BetaMessageStream = __esm({
51860
52032
  _BetaMessageStream_logger.set(this, void 0);
51861
52033
  _BetaMessageStream_handleError.set(this, (error) => {
51862
52034
  __classPrivateFieldSet2(this, _BetaMessageStream_errored, true, "f");
51863
- if (isAbortError2(error)) {
52035
+ if (isAbortError3(error)) {
51864
52036
  error = new APIUserAbortError2();
51865
52037
  }
51866
52038
  if (error instanceof APIUserAbortError2) {
@@ -54321,7 +54493,7 @@ var init_MessageStream = __esm({
54321
54493
  _MessageStream_logger.set(this, void 0);
54322
54494
  _MessageStream_handleError.set(this, (error) => {
54323
54495
  __classPrivateFieldSet2(this, _MessageStream_errored, true, "f");
54324
- if (isAbortError2(error)) {
54496
+ if (isAbortError3(error)) {
54325
54497
  error = new APIUserAbortError2();
54326
54498
  }
54327
54499
  if (error instanceof APIUserAbortError2) {
@@ -55451,7 +55623,7 @@ var init_client2 = __esm({
55451
55623
  if (options.signal?.aborted) {
55452
55624
  throw new APIUserAbortError2();
55453
55625
  }
55454
- const isTimeout = isAbortError2(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
55626
+ const isTimeout = isAbortError3(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
55455
55627
  if (retriesRemaining) {
55456
55628
  loggerFor2(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
55457
55629
  loggerFor2(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails2({
@@ -89959,7 +90131,7 @@ function listDocumentsResponseFromMldev(fromObject) {
89959
90131
  }
89960
90132
  return toObject;
89961
90133
  }
89962
- function isAbortError3(err) {
90134
+ function isAbortError4(err) {
89963
90135
  return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
89964
90136
  ("name" in err && err.name === "AbortError" || // Expo fetch
89965
90137
  "message" in err && String(err.message).includes("FetchRequestCanceledException"));
@@ -97173,7 +97345,7 @@ ${underline}`);
97173
97345
  }
97174
97346
  done = true;
97175
97347
  } catch (e2) {
97176
- if (isAbortError3(e2))
97348
+ if (isAbortError4(e2))
97177
97349
  return yield __await(void 0);
97178
97350
  throw e2;
97179
97351
  } finally {
@@ -97248,7 +97420,7 @@ ${underline}`);
97248
97420
  }
97249
97421
  done = true;
97250
97422
  } catch (e2) {
97251
- if (isAbortError3(e2))
97423
+ if (isAbortError4(e2))
97252
97424
  return yield __await(void 0);
97253
97425
  throw e2;
97254
97426
  } finally {
@@ -97624,7 +97796,7 @@ ${underline}`);
97624
97796
  if ((_d = options.signal) === null || _d === void 0 ? void 0 : _d.aborted) {
97625
97797
  throw new APIUserAbortError3();
97626
97798
  }
97627
- const isTimeout = isAbortError3(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
97799
+ const isTimeout = isAbortError4(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
97628
97800
  if (retriesRemaining) {
97629
97801
  loggerFor3(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
97630
97802
  loggerFor3(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails3({
@@ -99848,7 +100020,7 @@ function isTimeoutError(err) {
99848
100020
  const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
99849
100021
  return isNative || isLegacyNative || isGenericErr;
99850
100022
  }
99851
- function isAbortError4(err) {
100023
+ function isAbortError5(err) {
99852
100024
  if (typeof err !== "object" || err == null) {
99853
100025
  return false;
99854
100026
  }
@@ -100860,7 +101032,7 @@ var init_sdks = __esm({
100860
101032
  return response;
100861
101033
  }, { config: options.retryConfig, statusCodes: options.retryCodes }).then((r2) => OK(r2), (err) => {
100862
101034
  switch (true) {
100863
- case isAbortError4(err):
101035
+ case isAbortError5(err):
100864
101036
  return ERR(new RequestAbortedError("Request aborted by client", {
100865
101037
  cause: err
100866
101038
  }));
@@ -171,6 +171,13 @@ If the user's HTTP MCP client needs a longer idle period, set
171
171
  Example: `MEMORIX_SESSION_TIMEOUT_MS=86400000` keeps sessions alive for 24
172
172
  hours. Set it to `0` only when the host has its own reliable session cleanup.
173
173
 
174
+ Legacy HTTP sessions whose last GET/SSE stream closed are also released after
175
+ two minutes without reconnection or further requests. Queued/running POSTs
176
+ are protected and clients that never open GET streams retain idle-timeout
177
+ behavior. Set `MEMORIX_SESSION_DISCONNECT_GRACE_MS=0` before starting the
178
+ service to disable disconnect cleanup. An expired client should initialize
179
+ again after the explicit `404` reinitialize response.
180
+
174
181
  ### Do not confuse project config and global config
175
182
 
176
183
  Memorix intentionally supports both:
@@ -132,6 +132,12 @@ alongside Lance.
132
132
  Their lifecycle reports missing, stale, unavailable, and ready states instead
133
133
  of making each host infer index health from an empty result.
134
134
 
135
+ The retrieval health receipts now pass through one kernel-owned
136
+ `DerivedViewRegistry`. It owns stable view names, replacement, snapshot
137
+ creation, and reader failure isolation; concrete adapters still own their
138
+ storage lifecycle. Adding a new derived view therefore cannot silently invent
139
+ another receipt shape or leak a raw adapter exception into retrieval context.
140
+
135
141
  **P2 - 1.11 durable write pipeline:** add a small canonical write service and
136
142
  an idempotent derived-work outbox. Observation capture, Git ingest, and
137
143
  explicit MCP store calls use the same pipeline. Keep formation and provider
@@ -155,6 +161,12 @@ new work through retry exhaustion and lease recovery. Recurring jobs process a
155
161
  new event before returning to their long schedule; provider retry cooldowns
156
162
  remain in force. The new SQLite flag defaults to false for pre-1.11 rows.
157
163
 
164
+ Observation lifecycle mutations use the same projection boundary: resolving an
165
+ observation or changing its admission/visibility registers an
166
+ `observation-project` job inside the canonical transaction. Evidence and
167
+ CodeGraph projection success acknowledges that job; a failure leaves it
168
+ recoverable for maintenance.
169
+
158
170
  Automatic cleanup jobs re-check the resolved behavior configuration when they
159
171
  execute. Disabling `memory.autoCleanup` therefore neutralizes already queued
160
172
  retention, consolidation, and long-term maintenance work without affecting
@@ -387,6 +399,13 @@ agent or a deliberately isolated project store.
387
399
 
388
400
  ### Intelligence and Quality Layer
389
401
 
402
+ Persistent semantic rows are keyed by `(project_id, observation_id)`.
403
+ Cache restoration and backfill check the same scoped key; a numeric ID in
404
+ another project cannot suppress missing-vector work. Retrieval verifies the
405
+ vector's project against canonical SQLite before accepting the hit. A normal
406
+ upsert does not delete other projects' rows; destructive stale-row cleanup
407
+ requires canonical ownership evidence.
408
+
390
409
  This layer improves memory quality and retrieval quality.
391
410
 
392
411
  Main pieces: