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
package/dist/sdk.js CHANGED
@@ -5010,6 +5010,96 @@ var init_transformers_provider = __esm({
5010
5010
  }
5011
5011
  });
5012
5012
 
5013
+ // src/embedding/ollama-embed.ts
5014
+ async function routeOllamaEmbedding(url, body, fetchImpl = fetch, probeOptions) {
5015
+ const parsed = parseUrl(url);
5016
+ if (!parsed) return { url, body, rewritten: false };
5017
+ const openAIRoute = parsed.pathname.endsWith("/v1/embeddings");
5018
+ const nativeRoute = parsed.pathname.endsWith("/api/embed");
5019
+ if (!openAIRoute && !nativeRoute) return { url, body, rewritten: false };
5020
+ if (!await originServesOllama(parsed.origin, fetchImpl, probeOptions)) return { url, body, rewritten: false };
5021
+ if (nativeRoute) return { url, body, rewritten: true };
5022
+ parsed.pathname = parsed.pathname.replace(/\/v1\/embeddings$/, "/api/embed");
5023
+ return { url: parsed.toString(), body: withEmbeddingKeepAlive(body), rewritten: true };
5024
+ }
5025
+ async function originServesOllama(origin, fetchImpl = fetch, probeOptions) {
5026
+ const cached = ollamaOrigins.get(origin);
5027
+ if (cached != null) return cached;
5028
+ if (probeOptions?.signal?.aborted) return false;
5029
+ try {
5030
+ const response = await fetchImpl(`${origin}/api/version`, {
5031
+ method: "GET",
5032
+ signal: buildProbeSignal(probeOptions)
5033
+ });
5034
+ if (!response.ok) {
5035
+ ollamaOrigins.set(origin, false);
5036
+ return false;
5037
+ }
5038
+ const detected = isOllamaVersionPayload(await response.json());
5039
+ ollamaOrigins.set(origin, detected);
5040
+ return detected;
5041
+ } catch (err) {
5042
+ if (isAbortError(err) || probeOptions?.signal?.aborted) return false;
5043
+ ollamaOrigins.set(origin, false);
5044
+ return false;
5045
+ }
5046
+ }
5047
+ function mapOllamaEmbeddingResponse(payload) {
5048
+ if (!payload || typeof payload !== "object") return payload;
5049
+ const record80 = payload;
5050
+ if (Array.isArray(record80.data) || !Array.isArray(record80.embeddings)) return payload;
5051
+ const embeddings = record80.embeddings.filter((item) => Array.isArray(item));
5052
+ return {
5053
+ ...record80,
5054
+ object: "list",
5055
+ data: embeddings.map((embedding, index) => ({
5056
+ object: "embedding",
5057
+ index,
5058
+ embedding
5059
+ }))
5060
+ };
5061
+ }
5062
+ function withEmbeddingKeepAlive(body) {
5063
+ if (body.keep_alive != null && body.keep_alive !== "") return body;
5064
+ return { ...body, keep_alive: OLLAMA_EMBED_KEEP_ALIVE };
5065
+ }
5066
+ function isOllamaVersionPayload(payload) {
5067
+ if (!payload || typeof payload !== "object") return false;
5068
+ const version = payload.version;
5069
+ return typeof version === "string" && /^\d+\.\d+\.\d+/.test(version);
5070
+ }
5071
+ function parseUrl(url) {
5072
+ try {
5073
+ return new URL(url);
5074
+ } catch {
5075
+ return null;
5076
+ }
5077
+ }
5078
+ function buildProbeSignal(probeOptions) {
5079
+ const timeoutMs = Math.max(
5080
+ 1,
5081
+ Math.min(
5082
+ typeof probeOptions?.probeTimeoutMs === "number" && Number.isFinite(probeOptions.probeTimeoutMs) ? Math.floor(probeOptions.probeTimeoutMs) : 1e3,
5083
+ 6e4
5084
+ )
5085
+ );
5086
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
5087
+ if (probeOptions?.signal) return AbortSignal.any([probeOptions.signal, timeoutSignal]);
5088
+ return timeoutSignal;
5089
+ }
5090
+ function isAbortError(err) {
5091
+ return err instanceof Error && err.name === "AbortError";
5092
+ }
5093
+ var OLLAMA_EMBED_KEEP_ALIVE, ollamaOrigins;
5094
+ var init_ollama_embed = __esm({
5095
+ "src/embedding/ollama-embed.ts"() {
5096
+ "use strict";
5097
+ init_esm_shims();
5098
+ OLLAMA_EMBED_KEEP_ALIVE = "5m";
5099
+ ollamaOrigins = /* @__PURE__ */ new Map();
5100
+ }
5101
+ });
5102
+
5013
5103
  // src/embedding/api-provider.ts
5014
5104
  var api_provider_exports = {};
5015
5105
  __export(api_provider_exports, {
@@ -5711,8 +5801,18 @@ function parseBatchLimit(error) {
5711
5801
  return null;
5712
5802
  }
5713
5803
  async function fetchWithRetry(url, apiKey, body, options = {}, attempt = 0, nativeGemini = false) {
5714
- const controller = new AbortController();
5715
5804
  const timeoutMs = typeof options.timeoutMs === "number" && Number.isFinite(options.timeoutMs) ? Math.max(100, Math.min(Math.floor(options.timeoutMs), 6e4)) : 1e4;
5805
+ let rewritten = false;
5806
+ if (!nativeGemini) {
5807
+ const routed = await routeOllamaEmbedding(url, body, fetch, {
5808
+ signal: options.signal,
5809
+ probeTimeoutMs: Math.min(1e3, timeoutMs)
5810
+ });
5811
+ url = routed.url;
5812
+ body = routed.body;
5813
+ rewritten = routed.rewritten;
5814
+ }
5815
+ const controller = new AbortController();
5716
5816
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
5717
5817
  const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
5718
5818
  let response;
@@ -5738,10 +5838,11 @@ async function fetchWithRetry(url, apiKey, body, options = {}, attempt = 0, nati
5738
5838
  }
5739
5839
  try {
5740
5840
  if (response.ok) {
5741
- return await raceWithAbort(
5841
+ const payload = await raceWithAbort(
5742
5842
  response.json(),
5743
5843
  signal
5744
5844
  );
5845
+ return rewritten ? mapOllamaEmbeddingResponse(payload) : payload;
5745
5846
  }
5746
5847
  if (options.retry !== false && (response.status === 429 || response.status >= 500) && attempt < MAX_RETRIES2) {
5747
5848
  const delay3 = BASE_DELAY_MS * Math.pow(2, attempt);
@@ -5818,6 +5919,7 @@ var init_api_provider = __esm({
5818
5919
  "use strict";
5819
5920
  init_esm_shims();
5820
5921
  init_provider();
5922
+ init_ollama_embed();
5821
5923
  cache3 = /* @__PURE__ */ new Map();
5822
5924
  MAX_CACHE_ENTRIES = 2e5;
5823
5925
  MAX_CACHE_PAYLOAD_BYTES = 256 * 1024 * 1024;
@@ -7704,10 +7806,12 @@ __export(semantic_index_exports, {
7704
7806
  getSemanticIndexStats: () => getSemanticIndexStats,
7705
7807
  isSemanticIndexAvailable: () => isSemanticIndexAvailable,
7706
7808
  listSemanticVectorIds: () => listSemanticVectorIds,
7809
+ listSemanticVectorKeys: () => listSemanticVectorKeys,
7707
7810
  optimizeSemanticIndex: () => optimizeSemanticIndex,
7708
7811
  optimizeSemanticIndexes: () => optimizeSemanticIndexes,
7709
7812
  resetSemanticIndexRuntime: () => resetSemanticIndexRuntime,
7710
7813
  searchSemanticVectors: () => searchSemanticVectors,
7814
+ semanticVectorKey: () => semanticVectorKey,
7711
7815
  upsertSemanticVector: () => upsertSemanticVector,
7712
7816
  upsertSemanticVectors: () => upsertSemanticVectors
7713
7817
  });
@@ -7772,6 +7876,9 @@ async function openState(dataDir, profile) {
7772
7876
  const table = names.includes(name) ? await connection.openTable(name) : null;
7773
7877
  return { key: stateKey(dataDir, profile), dataDir, profile, connection, table };
7774
7878
  }
7879
+ function semanticVectorKey(projectId, observationId2) {
7880
+ return `${projectId}:${Math.trunc(observationId2)}`;
7881
+ }
7775
7882
  function toLanceRow(record80) {
7776
7883
  return {
7777
7884
  observation_id: record80.observationId,
@@ -7842,7 +7949,7 @@ async function mergeVectors(dataDir, profile, records) {
7842
7949
  const state = await getState(dataDir, profile, records);
7843
7950
  if (!state?.table) return;
7844
7951
  const rows = records.map(toLanceRow);
7845
- await state.table.mergeInsert("observation_id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows);
7952
+ await state.table.mergeInsert(["project_id", "observation_id"]).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows);
7846
7953
  const key = stateKey(dataDir, profile);
7847
7954
  const mutationCount = (mutationCounts.get(key) ?? 0) + 1;
7848
7955
  if (mutationCount >= semanticOptimizeEvery()) {
@@ -7882,11 +7989,28 @@ function upsertSemanticVector(dataDir, profile, record80) {
7882
7989
  function upsertSemanticVectors(dataDir, profile, records) {
7883
7990
  return queueOperation(stateKey(dataDir, profile), () => mergeVectors(dataDir, profile, records));
7884
7991
  }
7885
- async function listSemanticVectorIds(dataDir, profile) {
7992
+ async function listSemanticVectorKeys(dataDir, profile) {
7886
7993
  const state = await getState(dataDir, profile);
7887
7994
  if (!state?.table) return null;
7888
- const rows = await state.table.query().select(["observation_id"]).toArray();
7889
- return new Set(rows.map((row) => Number(row.observation_id)).filter(Number.isSafeInteger));
7995
+ const rows = await state.table.query().select(["observation_id", "project_id"]).toArray();
7996
+ const keys = /* @__PURE__ */ new Set();
7997
+ for (const row of rows) {
7998
+ const observationId2 = Number(row.observation_id);
7999
+ const projectId = String(row.project_id ?? "");
8000
+ if (!Number.isSafeInteger(observationId2) || !projectId) continue;
8001
+ keys.add(semanticVectorKey(projectId, observationId2));
8002
+ }
8003
+ return keys;
8004
+ }
8005
+ async function listSemanticVectorIds(dataDir, profile) {
8006
+ const keys = await listSemanticVectorKeys(dataDir, profile);
8007
+ if (!keys) return null;
8008
+ const ids = /* @__PURE__ */ new Set();
8009
+ for (const key of keys) {
8010
+ const observationId2 = Number(key.slice(key.lastIndexOf(":") + 1));
8011
+ if (Number.isSafeInteger(observationId2)) ids.add(observationId2);
8012
+ }
8013
+ return ids;
7890
8014
  }
7891
8015
  async function getSemanticIndexStats(dataDir, profile) {
7892
8016
  const state = await getState(dataDir, profile);
@@ -7928,11 +8052,13 @@ async function optimizeSemanticIndexes(dataDir) {
7928
8052
  }
7929
8053
  }
7930
8054
  }
7931
- function deleteSemanticVector(dataDir, profile, observationId2) {
8055
+ function deleteSemanticVector(dataDir, profile, observationId2, projectId) {
7932
8056
  return queueOperation(stateKey(dataDir, profile), async () => {
7933
8057
  const state = await getState(dataDir, profile);
7934
8058
  if (!state?.table) return;
7935
- await state.table.delete(`observation_id = ${Math.trunc(observationId2)}`);
8059
+ const idFilter = `observation_id = ${Math.trunc(observationId2)}`;
8060
+ const filter = projectId ? `${idFilter} AND project_id = '${escapeSqlString(projectId)}'` : idFilter;
8061
+ await state.table.delete(filter);
7936
8062
  });
7937
8063
  }
7938
8064
  function resolveIndexThreshold() {
@@ -8155,6 +8281,37 @@ var init_derived_view_receipt = __esm({
8155
8281
  }
8156
8282
  });
8157
8283
 
8284
+ // src/core/derived-view-registry.ts
8285
+ var DerivedViewRegistry;
8286
+ var init_derived_view_registry = __esm({
8287
+ "src/core/derived-view-registry.ts"() {
8288
+ "use strict";
8289
+ init_esm_shims();
8290
+ DerivedViewRegistry = class {
8291
+ readers = /* @__PURE__ */ new Map();
8292
+ register(name, reader2) {
8293
+ const normalized = name.trim();
8294
+ if (!normalized) throw new Error("Derived view name must not be empty");
8295
+ this.readers.set(normalized, reader2);
8296
+ return () => {
8297
+ if (this.readers.get(normalized) === reader2) this.readers.delete(normalized);
8298
+ };
8299
+ }
8300
+ snapshot() {
8301
+ const result = {};
8302
+ for (const [name, reader2] of this.readers) {
8303
+ try {
8304
+ result[name] = reader2();
8305
+ } catch {
8306
+ result[name] = { state: "degraded", reason: "derived view reader failed" };
8307
+ }
8308
+ }
8309
+ return result;
8310
+ }
8311
+ };
8312
+ }
8313
+ });
8314
+
8158
8315
  // src/memory/entity-extractor.ts
8159
8316
  function extractEntities(content) {
8160
8317
  const result = {
@@ -19280,7 +19437,7 @@ var init_uuid = __esm({
19280
19437
  });
19281
19438
 
19282
19439
  // node_modules/openai/internal/errors.mjs
19283
- function isAbortError(err) {
19440
+ function isAbortError2(err) {
19284
19441
  return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
19285
19442
  ("name" in err && err.name === "AbortError" || // Expo fetch
19286
19443
  "message" in err && String(err.message).includes("FetchRequestCanceledException"));
@@ -20460,7 +20617,7 @@ var init_streaming = __esm({
20460
20617
  }
20461
20618
  done = true;
20462
20619
  } catch (e2) {
20463
- if (isAbortError(e2))
20620
+ if (isAbortError2(e2))
20464
20621
  return;
20465
20622
  throw e2;
20466
20623
  } finally {
@@ -20503,7 +20660,7 @@ var init_streaming = __esm({
20503
20660
  }
20504
20661
  done = true;
20505
20662
  } catch (e2) {
20506
- if (isAbortError(e2))
20663
+ if (isAbortError2(e2))
20507
20664
  return;
20508
20665
  throw e2;
20509
20666
  } finally {
@@ -27052,7 +27209,7 @@ var init_client = __esm({
27052
27209
  if (options.signal?.aborted) {
27053
27210
  throw new APIUserAbortError();
27054
27211
  }
27055
- const isTimeout = isAbortError(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
27212
+ const isTimeout = isAbortError2(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
27056
27213
  if (retriesRemaining) {
27057
27214
  loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
27058
27215
  loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails({
@@ -46152,7 +46309,7 @@ var init_uuid2 = __esm({
46152
46309
  });
46153
46310
 
46154
46311
  // node_modules/@anthropic-ai/sdk/internal/errors.mjs
46155
- function isAbortError2(err) {
46312
+ function isAbortError3(err) {
46156
46313
  return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
46157
46314
  ("name" in err && err.name === "AbortError" || // Expo fetch
46158
46315
  "message" in err && String(err.message).includes("FetchRequestCanceledException"));
@@ -46923,7 +47080,7 @@ var init_streaming3 = __esm({
46923
47080
  }
46924
47081
  done = true;
46925
47082
  } catch (e2) {
46926
- if (isAbortError2(e2))
47083
+ if (isAbortError3(e2))
46927
47084
  return;
46928
47085
  throw e2;
46929
47086
  } finally {
@@ -46966,7 +47123,7 @@ var init_streaming3 = __esm({
46966
47123
  }
46967
47124
  done = true;
46968
47125
  } catch (e2) {
46969
- if (isAbortError2(e2))
47126
+ if (isAbortError3(e2))
46970
47127
  return;
46971
47128
  throw e2;
46972
47129
  } finally {
@@ -49088,7 +49245,7 @@ var init_BetaMessageStream = __esm({
49088
49245
  _BetaMessageStream_logger.set(this, void 0);
49089
49246
  _BetaMessageStream_handleError.set(this, (error) => {
49090
49247
  __classPrivateFieldSet2(this, _BetaMessageStream_errored, true, "f");
49091
- if (isAbortError2(error)) {
49248
+ if (isAbortError3(error)) {
49092
49249
  error = new APIUserAbortError2();
49093
49250
  }
49094
49251
  if (error instanceof APIUserAbortError2) {
@@ -51549,7 +51706,7 @@ var init_MessageStream = __esm({
51549
51706
  _MessageStream_logger.set(this, void 0);
51550
51707
  _MessageStream_handleError.set(this, (error) => {
51551
51708
  __classPrivateFieldSet2(this, _MessageStream_errored, true, "f");
51552
- if (isAbortError2(error)) {
51709
+ if (isAbortError3(error)) {
51553
51710
  error = new APIUserAbortError2();
51554
51711
  }
51555
51712
  if (error instanceof APIUserAbortError2) {
@@ -52679,7 +52836,7 @@ var init_client2 = __esm({
52679
52836
  if (options.signal?.aborted) {
52680
52837
  throw new APIUserAbortError2();
52681
52838
  }
52682
- const isTimeout = isAbortError2(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
52839
+ const isTimeout = isAbortError3(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
52683
52840
  if (retriesRemaining) {
52684
52841
  loggerFor2(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
52685
52842
  loggerFor2(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails2({
@@ -87187,7 +87344,7 @@ function listDocumentsResponseFromMldev(fromObject) {
87187
87344
  }
87188
87345
  return toObject;
87189
87346
  }
87190
- function isAbortError3(err) {
87347
+ function isAbortError4(err) {
87191
87348
  return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
87192
87349
  ("name" in err && err.name === "AbortError" || // Expo fetch
87193
87350
  "message" in err && String(err.message).includes("FetchRequestCanceledException"));
@@ -94401,7 +94558,7 @@ ${underline}`);
94401
94558
  }
94402
94559
  done = true;
94403
94560
  } catch (e2) {
94404
- if (isAbortError3(e2))
94561
+ if (isAbortError4(e2))
94405
94562
  return yield __await(void 0);
94406
94563
  throw e2;
94407
94564
  } finally {
@@ -94476,7 +94633,7 @@ ${underline}`);
94476
94633
  }
94477
94634
  done = true;
94478
94635
  } catch (e2) {
94479
- if (isAbortError3(e2))
94636
+ if (isAbortError4(e2))
94480
94637
  return yield __await(void 0);
94481
94638
  throw e2;
94482
94639
  } finally {
@@ -94852,7 +95009,7 @@ ${underline}`);
94852
95009
  if ((_d = options.signal) === null || _d === void 0 ? void 0 : _d.aborted) {
94853
95010
  throw new APIUserAbortError3();
94854
95011
  }
94855
- const isTimeout = isAbortError3(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
95012
+ const isTimeout = isAbortError4(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
94856
95013
  if (retriesRemaining) {
94857
95014
  loggerFor3(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
94858
95015
  loggerFor3(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails3({
@@ -97076,7 +97233,7 @@ function isTimeoutError(err) {
97076
97233
  const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
97077
97234
  return isNative || isLegacyNative || isGenericErr;
97078
97235
  }
97079
- function isAbortError4(err) {
97236
+ function isAbortError5(err) {
97080
97237
  if (typeof err !== "object" || err == null) {
97081
97238
  return false;
97082
97239
  }
@@ -98088,7 +98245,7 @@ var init_sdks = __esm({
98088
98245
  return response;
98089
98246
  }, { config: options.retryConfig, statusCodes: options.retryCodes }).then((r2) => OK(r2), (err) => {
98090
98247
  switch (true) {
98091
- case isAbortError4(err):
98248
+ case isAbortError5(err):
98092
98249
  return ERR(new RequestAbortedError("Request aborted by client", {
98093
98250
  cause: err
98094
98251
  }));
@@ -152277,13 +152434,17 @@ async function enqueueObservationDerivedWork(tx, observation) {
152277
152434
  payload: { observationId: observation.id }
152278
152435
  });
152279
152436
  }
152437
+ await enqueueObservationProjectionWork(tx, observation);
152438
+ return true;
152439
+ }
152440
+ async function enqueueObservationProjectionWork(tx, observation) {
152441
+ if (!tx.enqueueMaintenanceJob) return;
152280
152442
  await tx.enqueueMaintenanceJob({
152281
152443
  projectId: observation.projectId,
152282
152444
  kind: "observation-project",
152283
152445
  dedupeKey: "observation-project:" + observation.id,
152284
152446
  payload: { observationId: observation.id }
152285
152447
  });
152286
- return true;
152287
152448
  }
152288
152449
  function isVectorCompatibleWithCurrentIndex(embedding) {
152289
152450
  if (!embedding) return false;
@@ -152817,6 +152978,7 @@ async function updateObservationAdmission(input) {
152817
152978
  const next = apply(current);
152818
152979
  if (!next) return;
152819
152980
  await tx.update(next);
152981
+ await enqueueObservationProjectionWork(tx, next);
152820
152982
  updated = next;
152821
152983
  });
152822
152984
  } else {
@@ -152834,6 +152996,9 @@ async function updateObservationAdmission(input) {
152834
152996
  });
152835
152997
  } catch {
152836
152998
  }
152999
+ if (await persistEvidenceCard(updated)) {
153000
+ await acknowledgeObservationProjection(updated);
153001
+ }
152837
153002
  if (updated.admissionState === "qualified" && resolveObservationVisibility(updated) === "project") {
152838
153003
  queueClaimDerivation(updated);
152839
153004
  }
@@ -152904,10 +153069,17 @@ async function resolveObservations(ids, status = "resolved") {
152904
153069
  if (projectDir && resolved.length > 0) {
152905
153070
  const store = getObservationStore();
152906
153071
  await store.atomic(async (tx) => {
152907
- await Promise.all(changed.map((observation) => tx.update(observation)));
153072
+ await Promise.all(changed.map(async (observation) => {
153073
+ await tx.update(observation);
153074
+ await enqueueObservationProjectionWork(tx, observation);
153075
+ }));
152908
153076
  });
152909
153077
  }
152910
- for (const observation of changed) await persistEvidenceCard(observation);
153078
+ for (const observation of changed) {
153079
+ if (await persistEvidenceCard(observation)) {
153080
+ await acknowledgeObservationProjection(observation);
153081
+ }
153082
+ }
152911
153083
  return { resolved, notFound };
152912
153084
  }
152913
153085
  function getProjectObservations(projectId) {
@@ -153060,9 +153232,9 @@ async function prepareSearchIndex(options = {}) {
153060
153232
  for (const projectId of projects) {
153061
153233
  const projectObservations = await store.loadByProject(projectId);
153062
153234
  for (const observation of projectObservations) {
153063
- if (!persistedIds?.has(observation.id)) markVectorMissing(observation.id, observation.projectId);
153235
+ if (!persistedIds?.has(semanticVectorKey(observation.projectId, observation.id))) markVectorMissing(observation.id, observation.projectId);
153064
153236
  }
153065
- if (projectObservations.some((observation) => !persistedIds?.has(observation.id))) {
153237
+ if (projectObservations.some((observation) => !persistedIds?.has(semanticVectorKey(observation.projectId, observation.id)))) {
153066
153238
  queueVectorBackfill(projectId);
153067
153239
  }
153068
153240
  }
@@ -153084,7 +153256,7 @@ async function prepareSearchIndex(options = {}) {
153084
153256
  const persistedSemanticIds = await getPersistentSemanticVectorIds(hydratedProjectDir).catch(() => null);
153085
153257
  const projectsWithMissingVectors = /* @__PURE__ */ new Set();
153086
153258
  for (const obs of observations) {
153087
- if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(obs.id)) {
153259
+ if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(semanticVectorKey(obs.projectId, obs.id))) {
153088
153260
  markVectorMissing(obs.id, obs.projectId);
153089
153261
  projectsWithMissingVectors.add(obs.projectId);
153090
153262
  }
@@ -153288,6 +153460,7 @@ var init_observations = __esm({
153288
153460
  init_token_budget();
153289
153461
  init_entity_extractor();
153290
153462
  init_provider();
153463
+ init_semantic_index();
153291
153464
  init_secret_filter();
153292
153465
  init_lifecycle();
153293
153466
  init_visibility();
@@ -153963,15 +154136,17 @@ function getLastSearchDiagnostics(projectId) {
153963
154136
  return diagnostics ? { ...diagnostics } : void 0;
153964
154137
  }
153965
154138
  function getSearchDerivedViews() {
153966
- const views = {};
154139
+ return searchDerivedViewRegistry.snapshot();
154140
+ }
154141
+ function readFtsDerivedViewReceipt() {
153967
154142
  const store = getOptionalObservationStore();
153968
154143
  if (store) {
153969
154144
  try {
153970
154145
  const generation = store.getGeneration();
153971
154146
  if (store.hasLexicalIndex?.()) {
153972
- views.fts = { generation, freshness: "current", rebuildStatus: "idle" };
154147
+ return { generation, freshness: "current", rebuildStatus: "idle" };
153973
154148
  } else {
153974
- views.fts = {
154149
+ return {
153975
154150
  generation,
153976
154151
  freshness: "unknown",
153977
154152
  rebuildStatus: "unavailable",
@@ -153981,32 +154156,34 @@ function getSearchDerivedViews() {
153981
154156
  };
153982
154157
  }
153983
154158
  } catch (error) {
153984
- views.fts = {
154159
+ return {
153985
154160
  freshness: "unknown",
153986
154161
  rebuildStatus: "failed",
153987
154162
  failureReason: sanitizeDerivedViewFailureReason(error instanceof Error ? error.message : String(error))
153988
154163
  };
153989
154164
  }
153990
- } else {
153991
- views.fts = {
153992
- freshness: "unknown",
153993
- rebuildStatus: "unavailable",
153994
- failureReason: "observation store is not initialized"
153995
- };
153996
154165
  }
153997
- views.orama = db ? { generation: dbGeneration, freshness: "current", rebuildStatus: "idle" } : {
154166
+ return {
154167
+ freshness: "unknown",
154168
+ rebuildStatus: "unavailable",
154169
+ failureReason: "observation store is not initialized"
154170
+ };
154171
+ }
154172
+ function readOramaDerivedViewReceipt() {
154173
+ return db ? { generation: dbGeneration, freshness: "current", rebuildStatus: "idle" } : {
153998
154174
  generation: dbGeneration,
153999
154175
  freshness: "unknown",
154000
154176
  rebuildStatus: "unavailable",
154001
154177
  failureReason: "Orama index is not initialized"
154002
154178
  };
154179
+ }
154180
+ function readEmbeddingDerivedViewReceipt() {
154003
154181
  let embeddingHealth;
154004
154182
  try {
154005
154183
  embeddingHealth = getEmbeddingRuntimeHealth?.();
154006
154184
  } catch {
154007
154185
  }
154008
- views.embedding = embeddingHealthReceipt(embeddingHealth, embeddingEnabled);
154009
- return views;
154186
+ return embeddingHealthReceipt(embeddingHealth, embeddingEnabled);
154010
154187
  }
154011
154188
  function rememberSearchDiagnostics(key, value) {
154012
154189
  if (!lastSearchDiagnosticsByProject.has(key) && lastSearchDiagnosticsByProject.size >= MAX_SEARCH_MODE_KEYS) {
@@ -154143,10 +154320,12 @@ async function searchLanceInVectorOrder(options, projectIds, limit2, queryVector
154143
154320
  const hits = [];
154144
154321
  const seen = /* @__PURE__ */ new Set();
154145
154322
  for (const hit of vectorHits) {
154146
- if (seen.has(hit.observationId)) continue;
154147
- seen.add(hit.observationId);
154323
+ if (projectIds ? !projectIds.includes(hit.projectId) : options.projectId && hit.projectId !== options.projectId) continue;
154324
+ const key = semanticVectorKey(hit.projectId, hit.observationId);
154325
+ if (seen.has(key)) continue;
154326
+ seen.add(key);
154148
154327
  const observation = await store.getById(hit.observationId);
154149
- if (!observation) continue;
154328
+ if (!observation || observation.projectId !== hit.projectId) continue;
154150
154329
  if (projectIds && !projectIds.includes(observation.projectId)) continue;
154151
154330
  if (options.status !== "all" && (observation.status ?? "active") !== (options.status ?? "active")) continue;
154152
154331
  if (options.type && observation.type !== options.type) continue;
@@ -154192,14 +154371,15 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
154192
154371
  documents.set(makeEntryKey(hit.document.projectId, hit.document.observationId), hit.document);
154193
154372
  }
154194
154373
  const vectorObservations = await Promise.all(vectorHits.map(async (hit) => {
154374
+ if (projectIds ? !projectIds.includes(hit.projectId) : options.projectId && hit.projectId !== options.projectId) return null;
154195
154375
  const observation = await store.getById(hit.observationId);
154196
- if (!observation) return null;
154376
+ if (!observation || observation.projectId !== hit.projectId) return null;
154197
154377
  if (projectIds && !projectIds.includes(observation.projectId)) return null;
154198
154378
  if (options.status !== "all" && (observation.status ?? "active") !== (options.status ?? "active")) return null;
154199
154379
  if (options.type && observation.type !== options.type) return null;
154200
154380
  if (options.source && observation.source !== options.source) return null;
154201
154381
  addObservation(observation);
154202
- vectorDocumentKeys.set(hit.observationId, makeEntryKey(observation.projectId, observation.id));
154382
+ vectorDocumentKeys.set(semanticVectorKey(hit.projectId, hit.observationId), makeEntryKey(observation.projectId, observation.id));
154203
154383
  return observation;
154204
154384
  }));
154205
154385
  const RRF_K = 60;
@@ -154209,7 +154389,8 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
154209
154389
  scores.set(key, (scores.get(key) ?? 0) + 0.6 / (RRF_K + index + 1));
154210
154390
  }
154211
154391
  for (const [index, hit] of vectorHits.entries()) {
154212
- const key = vectorDocumentKeys.get(hit.observationId) ?? makeEntryKey(hit.projectId, hit.observationId);
154392
+ const key = vectorDocumentKeys.get(semanticVectorKey(hit.projectId, hit.observationId));
154393
+ if (!key) continue;
154213
154394
  if (!documents.has(key)) continue;
154214
154395
  scores.set(key, (scores.get(key) ?? 0) + 0.4 / (RRF_K + index + 1));
154215
154396
  }
@@ -154222,8 +154403,8 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
154222
154403
  return {
154223
154404
  count: vectorHits.length,
154224
154405
  hits: vectorHits.map((hit, index) => {
154225
- const key = vectorDocumentKeys.get(hit.observationId) ?? makeEntryKey(hit.projectId, hit.observationId);
154226
- const document2 = documents.get(key);
154406
+ const key = vectorDocumentKeys.get(semanticVectorKey(hit.projectId, hit.observationId));
154407
+ const document2 = key ? documents.get(key) : void 0;
154227
154408
  return document2 ? { id: document2.id, score: 0.4 / (RRF_K + index + 1), document: document2 } : null;
154228
154409
  }).filter((hit) => hit !== null).slice(0, limit2)
154229
154410
  };
@@ -154354,7 +154535,7 @@ function getActiveSemanticIndexProfile() {
154354
154535
  }
154355
154536
  async function getPersistentSemanticVectorIds(dataDir) {
154356
154537
  if (!indexEmbeddingProvider) return null;
154357
- return listSemanticVectorIds(dataDir, createSemanticIndexProfile(indexEmbeddingProvider));
154538
+ return listSemanticVectorKeys(dataDir, createSemanticIndexProfile(indexEmbeddingProvider));
154358
154539
  }
154359
154540
  async function queueSemanticVector(dataDir, record80) {
154360
154541
  const provider2 = indexEmbeddingProvider ?? await getEmbeddingProvider();
@@ -154423,7 +154604,7 @@ function isCompatibleCachedVector(vector) {
154423
154604
  async function attachCachedVectors(database, observations2) {
154424
154605
  const semanticDataDir = (await Promise.resolve().then(() => (init_observations(), observations_exports))).getObservationDataDir();
154425
154606
  const semanticProfile = getActiveSemanticIndexProfile();
154426
- const persistedSemanticIds = semanticDataDir && semanticProfile ? await listSemanticVectorIds(semanticDataDir, semanticProfile).catch(() => null) : null;
154607
+ const persistedSemanticIds = semanticDataDir && semanticProfile ? await listSemanticVectorKeys(semanticDataDir, semanticProfile).catch(() => null) : null;
154427
154608
  const batchSize = 200;
154428
154609
  for (let start = 0; start < observations2.length; start += batchSize) {
154429
154610
  const batch = observations2.slice(start, start + batchSize);
@@ -154434,7 +154615,7 @@ async function attachCachedVectors(database, observations2) {
154434
154615
  const vector = cachedVectors[index];
154435
154616
  if (!isCompatibleCachedVector(vector)) continue;
154436
154617
  const observation = batch[index];
154437
- if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(observation.id)) {
154618
+ if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(semanticVectorKey(observation.projectId, observation.id))) {
154438
154619
  semanticRecords.push({
154439
154620
  observationId: observation.id,
154440
154621
  projectId: observation.projectId,
@@ -155224,7 +155405,7 @@ function formatTime(isoDate) {
155224
155405
  return isoDate;
155225
155406
  }
155226
155407
  }
155227
- 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_TITLE2, COMMAND_STYLE_TITLE, COMMAND_LIKE_QUERY2, COMMAND_INTENT_QUERY, NATURAL_LANGUAGE_MARKERS;
155408
+ 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_TITLE2, COMMAND_STYLE_TITLE, COMMAND_LIKE_QUERY2, COMMAND_INTENT_QUERY, NATURAL_LANGUAGE_MARKERS;
155228
155409
  var init_orama_store = __esm({
155229
155410
  "src/store/orama-store.ts"() {
155230
155411
  "use strict";
@@ -155246,6 +155427,7 @@ var init_orama_store = __esm({
155246
155427
  init_retrieval_contracts();
155247
155428
  init_semantic_index();
155248
155429
  init_derived_view_receipt();
155430
+ init_derived_view_registry();
155249
155431
  db = null;
155250
155432
  dbInitPromise = null;
155251
155433
  dbGeneration = 0;
@@ -155257,8 +155439,12 @@ var init_orama_store = __esm({
155257
155439
  CJK_RUN = /[\u3400-\u4dbf\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]+/gu;
155258
155440
  lastSearchModeByProject = /* @__PURE__ */ new Map();
155259
155441
  lastSearchDiagnosticsByProject = /* @__PURE__ */ new Map();
155442
+ searchDerivedViewRegistry = new DerivedViewRegistry();
155260
155443
  SEARCH_MODE_DEFAULT_KEY = "__global__";
155261
155444
  MAX_SEARCH_MODE_KEYS = 4096;
155445
+ searchDerivedViewRegistry.register("fts", readFtsDerivedViewReceipt);
155446
+ searchDerivedViewRegistry.register("orama", readOramaDerivedViewReceipt);
155447
+ searchDerivedViewRegistry.register("embedding", readEmbeddingDerivedViewReceipt);
155262
155448
  COMMAND_LOG_TITLE2 = /^(Ran:|Command:|Executed:)\s/i;
155263
155449
  COMMAND_STYLE_TITLE = /(\bfindstr\b|\bSelect-String\b|\bGet-Content\b|\bnpx\s+vitest\b|\bnpx\s+tsc\b|\b2>&1\b)/i;
155264
155450
  COMMAND_LIKE_QUERY2 = /\b(git|npm|npx|pnpm|yarn|node|bash|powershell|curl|memorix)\b/i;
@@ -172421,7 +172607,7 @@ var MCP_SERVER_INFO_META_KEY = "io.modelcontextprotocol/serverInfo";
172421
172607
  function getMcpServerInfo() {
172422
172608
  return {
172423
172609
  name: "memorix",
172424
- version: true ? "1.10.3" : "1.0.1"
172610
+ version: true ? "1.10.5" : "1.0.1"
172425
172611
  };
172426
172612
  }
172427
172613
  function createMcpDiscoverResult(capabilities, serverInfo) {