memorix 1.10.1 → 1.10.2

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 (34) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cli/index.js +416 -167
  3. package/dist/index.js +232 -106
  4. package/dist/maintenance-runner.js +167 -57
  5. package/dist/media-audio-runner.js +139 -29
  6. package/dist/media-video-runner.js +166 -56
  7. package/dist/memcode-runtime/CHANGELOG.md +14 -0
  8. package/dist/sdk.js +283 -106
  9. package/dist/vector-backfill-runner.js +166 -56
  10. package/docs/DEVELOPMENT.md +3 -4
  11. package/docs/PERFORMANCE.md +23 -0
  12. package/docs/README.md +2 -2
  13. package/docs/ROADMAP-1.9.12-2.0.md +2 -2
  14. package/package.json +1 -1
  15. package/plugins/antigravity/memorix/plugin.json +1 -1
  16. package/plugins/claude/memorix/.claude-plugin/plugin.json +1 -1
  17. package/plugins/codebuddy/memorix/.codebuddy-plugin/plugin.json +1 -1
  18. package/plugins/codex/memorix/.codex-plugin/plugin.json +1 -1
  19. package/plugins/copilot/memorix/plugin.json +1 -1
  20. package/plugins/gemini/memorix/gemini-extension.json +1 -1
  21. package/plugins/hermes/memorix/__init__.py +1 -2
  22. package/plugins/hermes/memorix/plugin.yaml +1 -1
  23. package/plugins/omp/memorix/package.json +1 -1
  24. package/plugins/openclaw/memorix/.codex-plugin/plugin.json +1 -1
  25. package/plugins/pi/memorix/package.json +1 -1
  26. package/server.json +2 -2
  27. package/src/cli/commands/repair.ts +17 -3
  28. package/src/compact/index-format.ts +1 -1
  29. package/src/knowledge/context-receipt.ts +6 -3
  30. package/src/memory/observations.ts +7 -5
  31. package/src/search/derived-view-receipt.ts +40 -0
  32. package/src/search/semantic-index.ts +149 -1
  33. package/src/server.ts +18 -3
  34. package/src/store/orama-store.ts +32 -16
@@ -7362,6 +7362,7 @@ var init_obs_store = __esm({
7362
7362
 
7363
7363
  // src/search/semantic-index.ts
7364
7364
  import { createHash as createHash4 } from "crypto";
7365
+ import { existsSync as existsSync8 } from "fs";
7365
7366
  import { createRequire as createRequire3 } from "module";
7366
7367
  import path8 from "path";
7367
7368
  function createSemanticIndexProfile(provider2) {
@@ -7460,17 +7461,80 @@ function queueOperation(key, operation) {
7460
7461
  writeQueues.set(key, run.catch(() => void 0));
7461
7462
  return run;
7462
7463
  }
7464
+ function positiveEnvInt(name, fallback) {
7465
+ const value = Number.parseInt(process.env[name] ?? "", 10);
7466
+ return Number.isSafeInteger(value) && value > 0 ? value : fallback;
7467
+ }
7468
+ function semanticWriteBatchSize() {
7469
+ return positiveEnvInt("MEMORIX_SEMANTIC_WRITE_BATCH_SIZE", DEFAULT_WRITE_BATCH_SIZE);
7470
+ }
7471
+ function semanticWriteFlushMs() {
7472
+ return positiveEnvInt("MEMORIX_SEMANTIC_WRITE_FLUSH_MS", DEFAULT_WRITE_FLUSH_MS);
7473
+ }
7474
+ function semanticOptimizeEvery() {
7475
+ return positiveEnvInt("MEMORIX_SEMANTIC_OPTIMIZE_EVERY", DEFAULT_OPTIMIZE_EVERY);
7476
+ }
7477
+ function semanticVersionRetentionMs() {
7478
+ return positiveEnvInt("MEMORIX_SEMANTIC_VERSION_RETENTION_MS", DEFAULT_VERSION_RETENTION_MS);
7479
+ }
7480
+ async function optimizeState(state) {
7481
+ if (!state.table || typeof state.table.optimize !== "function") return;
7482
+ await state.table.optimize({
7483
+ cleanupOlderThan: new Date(Date.now() - semanticVersionRetentionMs()),
7484
+ deleteUnverified: false
7485
+ });
7486
+ }
7463
7487
  async function mergeVectors(dataDir, profile, records) {
7464
7488
  if (records.length === 0) return;
7465
7489
  const state = await getState(dataDir, profile, records);
7466
7490
  if (!state?.table) return;
7467
7491
  const rows = records.map(toLanceRow);
7468
7492
  await state.table.mergeInsert("observation_id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows);
7493
+ const key = stateKey(dataDir, profile);
7494
+ const mutationCount = (mutationCounts.get(key) ?? 0) + 1;
7495
+ if (mutationCount >= semanticOptimizeEvery()) {
7496
+ mutationCounts.set(key, 0);
7497
+ await optimizeState(state).catch(() => void 0);
7498
+ } else {
7499
+ mutationCounts.set(key, mutationCount);
7500
+ }
7469
7501
  void ensureSemanticIndex(dataDir, profile);
7470
7502
  }
7503
+ function flushPendingVectorBatch(key) {
7504
+ const pending = pendingVectorBatches.get(key);
7505
+ if (!pending) return Promise.resolve();
7506
+ if (pending.timer) clearTimeout(pending.timer);
7507
+ pendingVectorBatches.delete(key);
7508
+ const records = [...pending.records.values()];
7509
+ const waiters = pending.waiters.splice(0);
7510
+ return queueOperation(key, () => mergeVectors(pending.dataDir, pending.profile, records)).then(() => waiters.forEach((waiter) => waiter.resolve())).catch((error) => {
7511
+ waiters.forEach((waiter) => waiter.reject(error));
7512
+ });
7513
+ }
7514
+ function upsertSemanticVector(dataDir, profile, record80) {
7515
+ const key = stateKey(dataDir, profile);
7516
+ let pending = pendingVectorBatches.get(key);
7517
+ if (!pending) {
7518
+ pending = { dataDir, profile, records: /* @__PURE__ */ new Map(), waiters: [] };
7519
+ pendingVectorBatches.set(key, pending);
7520
+ }
7521
+ pending.records.set(`${record80.projectId}:${record80.observationId}`, record80);
7522
+ const promise = new Promise((resolve2, reject) => pending.waiters.push({ resolve: resolve2, reject }));
7523
+ if (pending.records.size >= semanticWriteBatchSize()) void flushPendingVectorBatch(key);
7524
+ else if (!pending.timer) pending.timer = setTimeout(() => {
7525
+ void flushPendingVectorBatch(key);
7526
+ }, semanticWriteFlushMs());
7527
+ return promise;
7528
+ }
7471
7529
  function upsertSemanticVectors(dataDir, profile, records) {
7472
7530
  return queueOperation(stateKey(dataDir, profile), () => mergeVectors(dataDir, profile, records));
7473
7531
  }
7532
+ async function listSemanticVectorIds(dataDir, profile) {
7533
+ const state = await getState(dataDir, profile);
7534
+ if (!state?.table) return null;
7535
+ const rows = await state.table.query().select(["observation_id"]).toArray();
7536
+ return new Set(rows.map((row) => Number(row.observation_id)).filter(Number.isSafeInteger));
7537
+ }
7474
7538
  function resolveIndexThreshold() {
7475
7539
  const raw = Number.parseInt(process.env.MEMORIX_SEMANTIC_INDEX_THRESHOLD ?? "", 10);
7476
7540
  return Number.isSafeInteger(raw) && raw > 0 ? raw : DEFAULT_INDEX_THRESHOLD;
@@ -7522,7 +7586,7 @@ async function searchSemanticVectors(options) {
7522
7586
  distance: Number(row._distance ?? Number.POSITIVE_INFINITY)
7523
7587
  })).filter((row) => Number.isFinite(row.distance));
7524
7588
  }
7525
- var SEMANTIC_INDEX_DIR, TABLE_PREFIX, DEFAULT_INDEX_THRESHOLD, MAX_INDEX_PARTITIONS, statePromises, writeQueues, indexBuilds, availability, requireFromHere2;
7589
+ var SEMANTIC_INDEX_DIR, TABLE_PREFIX, DEFAULT_INDEX_THRESHOLD, MAX_INDEX_PARTITIONS, DEFAULT_WRITE_BATCH_SIZE, DEFAULT_WRITE_FLUSH_MS, DEFAULT_OPTIMIZE_EVERY, DEFAULT_VERSION_RETENTION_MS, statePromises, writeQueues, indexBuilds, mutationCounts, pendingVectorBatches, availability, requireFromHere2;
7526
7590
  var init_semantic_index = __esm({
7527
7591
  "src/search/semantic-index.ts"() {
7528
7592
  "use strict";
@@ -7531,13 +7595,54 @@ var init_semantic_index = __esm({
7531
7595
  TABLE_PREFIX = "observations_";
7532
7596
  DEFAULT_INDEX_THRESHOLD = 1e4;
7533
7597
  MAX_INDEX_PARTITIONS = 32;
7598
+ DEFAULT_WRITE_BATCH_SIZE = 100;
7599
+ DEFAULT_WRITE_FLUSH_MS = 50;
7600
+ DEFAULT_OPTIMIZE_EVERY = 20;
7601
+ DEFAULT_VERSION_RETENTION_MS = 24 * 60 * 60 * 1e3;
7534
7602
  statePromises = /* @__PURE__ */ new Map();
7535
7603
  writeQueues = /* @__PURE__ */ new Map();
7536
7604
  indexBuilds = /* @__PURE__ */ new Map();
7605
+ mutationCounts = /* @__PURE__ */ new Map();
7606
+ pendingVectorBatches = /* @__PURE__ */ new Map();
7537
7607
  requireFromHere2 = createRequire3(import.meta.url);
7538
7608
  }
7539
7609
  });
7540
7610
 
7611
+ // src/search/derived-view-receipt.ts
7612
+ function sanitizeDerivedViewFailureReason(reason) {
7613
+ const safe = sanitizeCredentials(reason).replace(/(?:[A-Za-z]:[\\/]|\\\\[^\\/\s]+[\\/]|\/(?:home|Users|tmp|var|private|mnt|workspace|workspaces)\/)[^\s"'<>|]*/gi, "[path]").replace(/\s+/g, " ").trim();
7614
+ return safe.slice(0, 240) || "derived view failed";
7615
+ }
7616
+ function embeddingHealthReceipt(health, embeddingEnabled2) {
7617
+ if (health?.status === "disabled") {
7618
+ return { freshness: "current", rebuildStatus: "disabled" };
7619
+ }
7620
+ if (health?.status === "ready" || embeddingEnabled2) {
7621
+ return { freshness: "current", rebuildStatus: "idle" };
7622
+ }
7623
+ if (health?.status === "degraded") {
7624
+ return {
7625
+ freshness: "stale",
7626
+ rebuildStatus: "failed",
7627
+ ...health.failure ? {
7628
+ failureReason: `embedding ${health.failure.kind}; retry in ${health.failure.retryAfterMs}ms`
7629
+ } : { failureReason: "embedding provider degraded" }
7630
+ };
7631
+ }
7632
+ return {
7633
+ freshness: "unknown",
7634
+ rebuildStatus: "unavailable",
7635
+ failureReason: "embedding provider is not initialized"
7636
+ };
7637
+ }
7638
+ var init_derived_view_receipt = __esm({
7639
+ "src/search/derived-view-receipt.ts"() {
7640
+ "use strict";
7641
+ init_esm_shims();
7642
+ init_secret_filter();
7643
+ }
7644
+ });
7645
+
7541
7646
  // src/project/aliases.ts
7542
7647
  var aliases_exports = {};
7543
7648
  __export(aliases_exports, {
@@ -8146,6 +8251,7 @@ __export(orama_store_exports, {
8146
8251
  getLastSearchMode: () => getLastSearchMode,
8147
8252
  getObservationCount: () => getObservationCount,
8148
8253
  getObservationsByIds: () => getObservationsByIds,
8254
+ getPersistentSemanticVectorIds: () => getPersistentSemanticVectorIds,
8149
8255
  getSearchDerivedViews: () => getSearchDerivedViews,
8150
8256
  getTimeline: () => getTimeline,
8151
8257
  getVectorDimensions: () => getVectorDimensions,
@@ -8190,14 +8296,16 @@ function getSearchDerivedViews() {
8190
8296
  generation,
8191
8297
  freshness: "unknown",
8192
8298
  rebuildStatus: "unavailable",
8193
- failureReason: store.getBackendReason?.() ?? "persistent lexical index unavailable"
8299
+ failureReason: sanitizeDerivedViewFailureReason(
8300
+ store.getBackendReason?.() ?? "persistent lexical index unavailable"
8301
+ )
8194
8302
  };
8195
8303
  }
8196
8304
  } catch (error) {
8197
8305
  views.fts = {
8198
8306
  freshness: "unknown",
8199
8307
  rebuildStatus: "failed",
8200
- failureReason: error instanceof Error ? error.message.slice(0, 240) : String(error).slice(0, 240)
8308
+ failureReason: sanitizeDerivedViewFailureReason(error instanceof Error ? error.message : String(error))
8201
8309
  };
8202
8310
  }
8203
8311
  } else {
@@ -8213,18 +8321,12 @@ function getSearchDerivedViews() {
8213
8321
  rebuildStatus: "unavailable",
8214
8322
  failureReason: "Orama index is not initialized"
8215
8323
  };
8216
- const configuredEmbeddingMode = process.env.MEMORIX_EMBEDDING?.trim().toLowerCase();
8217
- if (configuredEmbeddingMode === "off") {
8218
- views.embedding = { freshness: "current", rebuildStatus: "disabled" };
8219
- } else if (embeddingEnabled) {
8220
- views.embedding = { freshness: "current", rebuildStatus: "idle" };
8221
- } else {
8222
- views.embedding = {
8223
- freshness: "unknown",
8224
- rebuildStatus: "unavailable",
8225
- failureReason: "embedding provider is not initialized"
8226
- };
8324
+ let embeddingHealth;
8325
+ try {
8326
+ embeddingHealth = getEmbeddingRuntimeHealth?.();
8327
+ } catch {
8227
8328
  }
8329
+ views.embedding = embeddingHealthReceipt(embeddingHealth, embeddingEnabled);
8228
8330
  return views;
8229
8331
  }
8230
8332
  function rememberSearchDiagnostics(key, value) {
@@ -8528,12 +8630,16 @@ function getVectorDimensions() {
8528
8630
  function getActiveSemanticIndexProfile() {
8529
8631
  return indexEmbeddingProvider ? createSemanticIndexProfile(indexEmbeddingProvider) : null;
8530
8632
  }
8633
+ async function getPersistentSemanticVectorIds(dataDir) {
8634
+ if (!indexEmbeddingProvider) return null;
8635
+ return listSemanticVectorIds(dataDir, createSemanticIndexProfile(indexEmbeddingProvider));
8636
+ }
8531
8637
  async function queueSemanticVector(dataDir, record80) {
8532
8638
  const provider2 = indexEmbeddingProvider ?? await getEmbeddingProvider();
8533
8639
  const profile = provider2 ? createSemanticIndexProfile(provider2) : null;
8534
8640
  if (!profile) return;
8535
8641
  try {
8536
- await upsertSemanticVectors(dataDir, profile, [record80]);
8642
+ await upsertSemanticVector(dataDir, profile, record80);
8537
8643
  } catch {
8538
8644
  }
8539
8645
  }
@@ -8595,6 +8701,7 @@ function isCompatibleCachedVector(vector) {
8595
8701
  async function attachCachedVectors(database, observations2) {
8596
8702
  const semanticDataDir = (await Promise.resolve().then(() => (init_observations(), observations_exports))).getObservationDataDir();
8597
8703
  const semanticProfile = getActiveSemanticIndexProfile();
8704
+ const persistedSemanticIds = semanticDataDir && semanticProfile ? await listSemanticVectorIds(semanticDataDir, semanticProfile).catch(() => null) : null;
8598
8705
  const batchSize = 200;
8599
8706
  for (let start = 0; start < observations2.length; start += batchSize) {
8600
8707
  const batch = observations2.slice(start, start + batchSize);
@@ -8605,7 +8712,7 @@ async function attachCachedVectors(database, observations2) {
8605
8712
  const vector = cachedVectors[index];
8606
8713
  if (!isCompatibleCachedVector(vector)) continue;
8607
8714
  const observation = batch[index];
8608
- if (semanticDataDir && semanticProfile) {
8715
+ if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(observation.id)) {
8609
8716
  semanticRecords.push({
8610
8717
  observationId: observation.id,
8611
8718
  projectId: observation.projectId,
@@ -9378,6 +9485,7 @@ var init_orama_store = __esm({
9378
9485
  init_mini_skills();
9379
9486
  init_visibility();
9380
9487
  init_provider();
9488
+ init_provider();
9381
9489
  init_project_affinity();
9382
9490
  init_intent_detector();
9383
9491
  init_query_expansion();
@@ -9385,6 +9493,7 @@ var init_orama_store = __esm({
9385
9493
  init_timeout();
9386
9494
  init_obs_store();
9387
9495
  init_semantic_index();
9496
+ init_derived_view_receipt();
9388
9497
  db = null;
9389
9498
  dbInitPromise = null;
9390
9499
  dbGeneration = 0;
@@ -144081,7 +144190,7 @@ __export(video_jobs_exports, {
144081
144190
  runMiniMaxVideoGenerationJob: () => runMiniMaxVideoGenerationJob
144082
144191
  });
144083
144192
  import { spawn } from "child_process";
144084
- import { existsSync as existsSync8 } from "fs";
144193
+ import { existsSync as existsSync9 } from "fs";
144085
144194
  import path15 from "path";
144086
144195
  import { fileURLToPath as fileURLToPath2 } from "url";
144087
144196
  function safeError2(error) {
@@ -144329,7 +144438,7 @@ function resolveMediaVideoRunnerPath(moduleUrl = import.meta.url) {
144329
144438
  }
144330
144439
  function launchMediaVideoRunner(request, options = {}) {
144331
144440
  const runnerPath = options.runnerPath ?? resolveMediaVideoRunnerPath();
144332
- if (!existsSync8(runnerPath)) {
144441
+ if (!existsSync9(runnerPath)) {
144333
144442
  return { launched: false, reason: "Media video runner is unavailable until Memorix is built or reinstalled." };
144334
144443
  }
144335
144444
  try {
@@ -147296,7 +147405,7 @@ __export(lite_provider_exports, {
147296
147405
  refreshProjectLite: () => refreshProjectLite
147297
147406
  });
147298
147407
  import { createHash as createHash11 } from "crypto";
147299
- import { existsSync as existsSync10, readdirSync as readdirSync2, readFileSync as readFileSync8, statSync as statSync3 } from "fs";
147408
+ import { existsSync as existsSync11, readdirSync as readdirSync2, readFileSync as readFileSync8, statSync as statSync3 } from "fs";
147300
147409
  import { join as join4, relative as relative2 } from "path";
147301
147410
  function hashText2(text2) {
147302
147411
  return createHash11("sha256").update(text2).digest("hex");
@@ -147314,7 +147423,7 @@ function resolveMaxFileBytes(value) {
147314
147423
  return Math.max(1, Math.floor(value));
147315
147424
  }
147316
147425
  function isPythonVirtualenvDir(dir) {
147317
- return existsSync10(join4(dir, "pyvenv.cfg"));
147426
+ return existsSync11(join4(dir, "pyvenv.cfg"));
147318
147427
  }
147319
147428
  function walk(root, exclude, maxFiles) {
147320
147429
  const out = [];
@@ -150853,7 +150962,7 @@ __export(vector_backfill_runner_exports, {
150853
150962
  import { spawn as spawn2 } from "child_process";
150854
150963
  import {
150855
150964
  closeSync,
150856
- existsSync as existsSync11,
150965
+ existsSync as existsSync12,
150857
150966
  mkdirSync as mkdirSync2,
150858
150967
  openSync,
150859
150968
  readFileSync as readFileSync9,
@@ -150981,7 +151090,7 @@ function releaseVectorBackfillLock(lockPath = process.env.MEMORIX_VECTOR_BACKFIL
150981
151090
  }
150982
151091
  function launchDetachedVectorBackfill(request, options = {}) {
150983
151092
  const runnerPath = options.runnerPath ?? resolveVectorBackfillRunnerPath();
150984
- const exists = options.exists ?? existsSync11;
151093
+ const exists = options.exists ?? existsSync12;
150985
151094
  if (!exists(runnerPath)) return false;
150986
151095
  const lock = acquireVectorBackfillLock(request.dataDir, request.projectId, options.lockPath);
150987
151096
  if (!lock) return false;
@@ -152000,13 +152109,14 @@ async function prepareSearchIndex(options = {}) {
152000
152109
  return 0;
152001
152110
  }
152002
152111
  const hydratedProjectDir = projectDir;
152003
- const queueMissingVectors = () => {
152004
- if (projectDir !== hydratedProjectDir) return;
152112
+ const queueMissingVectors = async () => {
152113
+ if (!hydratedProjectDir || projectDir !== hydratedProjectDir) return;
152005
152114
  vectorMissingIds.clear();
152006
152115
  if (!isEmbeddingExplicitlyDisabled()) {
152116
+ const persistedSemanticIds = await getPersistentSemanticVectorIds(hydratedProjectDir).catch(() => null);
152007
152117
  const projectsWithMissingVectors = /* @__PURE__ */ new Set();
152008
152118
  for (const obs of observations) {
152009
- if (!hasObservationVector(obs.projectId, obs.id)) {
152119
+ if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(obs.id)) {
152010
152120
  vectorMissingIds.add(obs.id);
152011
152121
  projectsWithMissingVectors.add(obs.projectId);
152012
152122
  }
@@ -152016,9 +152126,9 @@ async function prepareSearchIndex(options = {}) {
152016
152126
  };
152017
152127
  const cacheHydration = getDeferredCachedVectorHydration();
152018
152128
  if (cacheHydration) {
152019
- void cacheHydration.finally(queueMissingVectors);
152129
+ void cacheHydration.then(queueMissingVectors, queueMissingVectors).catch(() => void 0);
152020
152130
  } else {
152021
- queueMissingVectors();
152131
+ await queueMissingVectors();
152022
152132
  }
152023
152133
  searchIndexPrepared = true;
152024
152134
  return count2;
@@ -152286,7 +152396,7 @@ __export(audio_jobs_exports, {
152286
152396
  transcribeAudio: () => transcribeAudio
152287
152397
  });
152288
152398
  import { spawn as spawn3 } from "child_process";
152289
- import { existsSync as existsSync12 } from "fs";
152399
+ import { existsSync as existsSync13 } from "fs";
152290
152400
  import path21 from "path";
152291
152401
  import { fileURLToPath as fileURLToPath4 } from "url";
152292
152402
  function safeError3(error) {
@@ -152537,7 +152647,7 @@ function resolveMediaAudioRunnerPath(moduleUrl = import.meta.url) {
152537
152647
  }
152538
152648
  function launchMediaAudioRunner(request, options = {}) {
152539
152649
  const runnerPath = options.runnerPath ?? resolveMediaAudioRunnerPath();
152540
- if (!existsSync12(runnerPath)) return { launched: false, reason: "Audio runner is unavailable until Memorix is built or reinstalled." };
152650
+ if (!existsSync13(runnerPath)) return { launched: false, reason: "Audio runner is unavailable until Memorix is built or reinstalled." };
152541
152651
  try {
152542
152652
  const child = spawn3(process.execPath, [runnerPath, JSON.stringify(request)], {
152543
152653
  cwd: request.projectRoot,