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
package/dist/cli/index.js CHANGED
@@ -3232,7 +3232,7 @@ ${import_picocolors.default.gray(m3)} ${s4}
3232
3232
 
3233
3233
  // src/cli/version.ts
3234
3234
  function getCliVersion() {
3235
- return true ? "1.10.1" : pkg.version;
3235
+ return true ? "1.10.2" : pkg.version;
3236
3236
  }
3237
3237
  var init_version = __esm({
3238
3238
  "src/cli/version.ts"() {
@@ -26111,7 +26111,25 @@ var init_obs_store = __esm({
26111
26111
  });
26112
26112
 
26113
26113
  // src/search/semantic-index.ts
26114
+ var semantic_index_exports = {};
26115
+ __export(semantic_index_exports, {
26116
+ closeSemanticIndex: () => closeSemanticIndex,
26117
+ closeSemanticIndexes: () => closeSemanticIndexes,
26118
+ createSemanticIndexProfile: () => createSemanticIndexProfile,
26119
+ deleteSemanticVector: () => deleteSemanticVector,
26120
+ ensureSemanticIndex: () => ensureSemanticIndex,
26121
+ getSemanticIndexStats: () => getSemanticIndexStats,
26122
+ isSemanticIndexAvailable: () => isSemanticIndexAvailable,
26123
+ listSemanticVectorIds: () => listSemanticVectorIds,
26124
+ optimizeSemanticIndex: () => optimizeSemanticIndex,
26125
+ optimizeSemanticIndexes: () => optimizeSemanticIndexes,
26126
+ resetSemanticIndexRuntime: () => resetSemanticIndexRuntime,
26127
+ searchSemanticVectors: () => searchSemanticVectors,
26128
+ upsertSemanticVector: () => upsertSemanticVector,
26129
+ upsertSemanticVectors: () => upsertSemanticVectors
26130
+ });
26114
26131
  import { createHash as createHash4 } from "crypto";
26132
+ import { existsSync as existsSync10 } from "fs";
26115
26133
  import { createRequire as createRequire3 } from "module";
26116
26134
  import path10 from "path";
26117
26135
  function createSemanticIndexProfile(provider2) {
@@ -26155,6 +26173,9 @@ async function loadLanceDb() {
26155
26173
  return null;
26156
26174
  }
26157
26175
  }
26176
+ async function isSemanticIndexAvailable() {
26177
+ return await loadLanceDb() !== null;
26178
+ }
26158
26179
  function semanticIndexEnabled() {
26159
26180
  return process.env.MEMORIX_SEMANTIC_INDEX !== "off" && process.env.MEMORIX_SEMANTIC_INDEX !== "orama";
26160
26181
  }
@@ -26210,17 +26231,127 @@ function queueOperation(key, operation) {
26210
26231
  writeQueues.set(key, run.catch(() => void 0));
26211
26232
  return run;
26212
26233
  }
26234
+ function positiveEnvInt(name, fallback) {
26235
+ const value = Number.parseInt(process.env[name] ?? "", 10);
26236
+ return Number.isSafeInteger(value) && value > 0 ? value : fallback;
26237
+ }
26238
+ function semanticWriteBatchSize() {
26239
+ return positiveEnvInt("MEMORIX_SEMANTIC_WRITE_BATCH_SIZE", DEFAULT_WRITE_BATCH_SIZE);
26240
+ }
26241
+ function semanticWriteFlushMs() {
26242
+ return positiveEnvInt("MEMORIX_SEMANTIC_WRITE_FLUSH_MS", DEFAULT_WRITE_FLUSH_MS);
26243
+ }
26244
+ function semanticOptimizeEvery() {
26245
+ return positiveEnvInt("MEMORIX_SEMANTIC_OPTIMIZE_EVERY", DEFAULT_OPTIMIZE_EVERY);
26246
+ }
26247
+ function semanticVersionRetentionMs() {
26248
+ return positiveEnvInt("MEMORIX_SEMANTIC_VERSION_RETENTION_MS", DEFAULT_VERSION_RETENTION_MS);
26249
+ }
26250
+ async function optimizeState(state) {
26251
+ if (!state.table || typeof state.table.optimize !== "function") return;
26252
+ await state.table.optimize({
26253
+ cleanupOlderThan: new Date(Date.now() - semanticVersionRetentionMs()),
26254
+ deleteUnverified: false
26255
+ });
26256
+ }
26213
26257
  async function mergeVectors(dataDir, profile, records) {
26214
26258
  if (records.length === 0) return;
26215
26259
  const state = await getState(dataDir, profile, records);
26216
26260
  if (!state?.table) return;
26217
26261
  const rows = records.map(toLanceRow);
26218
26262
  await state.table.mergeInsert("observation_id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows);
26263
+ const key = stateKey(dataDir, profile);
26264
+ const mutationCount = (mutationCounts.get(key) ?? 0) + 1;
26265
+ if (mutationCount >= semanticOptimizeEvery()) {
26266
+ mutationCounts.set(key, 0);
26267
+ await optimizeState(state).catch(() => void 0);
26268
+ } else {
26269
+ mutationCounts.set(key, mutationCount);
26270
+ }
26219
26271
  void ensureSemanticIndex(dataDir, profile);
26220
26272
  }
26273
+ function flushPendingVectorBatch(key) {
26274
+ const pending = pendingVectorBatches.get(key);
26275
+ if (!pending) return Promise.resolve();
26276
+ if (pending.timer) clearTimeout(pending.timer);
26277
+ pendingVectorBatches.delete(key);
26278
+ const records = [...pending.records.values()];
26279
+ const waiters = pending.waiters.splice(0);
26280
+ return queueOperation(key, () => mergeVectors(pending.dataDir, pending.profile, records)).then(() => waiters.forEach((waiter) => waiter.resolve())).catch((error40) => {
26281
+ waiters.forEach((waiter) => waiter.reject(error40));
26282
+ });
26283
+ }
26284
+ function upsertSemanticVector(dataDir, profile, record2) {
26285
+ const key = stateKey(dataDir, profile);
26286
+ let pending = pendingVectorBatches.get(key);
26287
+ if (!pending) {
26288
+ pending = { dataDir, profile, records: /* @__PURE__ */ new Map(), waiters: [] };
26289
+ pendingVectorBatches.set(key, pending);
26290
+ }
26291
+ pending.records.set(`${record2.projectId}:${record2.observationId}`, record2);
26292
+ const promise2 = new Promise((resolve9, reject) => pending.waiters.push({ resolve: resolve9, reject }));
26293
+ if (pending.records.size >= semanticWriteBatchSize()) void flushPendingVectorBatch(key);
26294
+ else if (!pending.timer) pending.timer = setTimeout(() => {
26295
+ void flushPendingVectorBatch(key);
26296
+ }, semanticWriteFlushMs());
26297
+ return promise2;
26298
+ }
26221
26299
  function upsertSemanticVectors(dataDir, profile, records) {
26222
26300
  return queueOperation(stateKey(dataDir, profile), () => mergeVectors(dataDir, profile, records));
26223
26301
  }
26302
+ async function listSemanticVectorIds(dataDir, profile) {
26303
+ const state = await getState(dataDir, profile);
26304
+ if (!state?.table) return null;
26305
+ const rows = await state.table.query().select(["observation_id"]).toArray();
26306
+ return new Set(rows.map((row) => Number(row.observation_id)).filter(Number.isSafeInteger));
26307
+ }
26308
+ async function getSemanticIndexStats(dataDir, profile) {
26309
+ const state = await getState(dataDir, profile);
26310
+ if (!state?.table) return null;
26311
+ return {
26312
+ rowCount: await state.table.countRows(),
26313
+ version: typeof state.table.version === "function" ? await state.table.version() : 0
26314
+ };
26315
+ }
26316
+ function optimizeSemanticIndex(dataDir, profile) {
26317
+ const key = stateKey(dataDir, profile);
26318
+ return queueOperation(key, async () => {
26319
+ const state = await getState(dataDir, profile);
26320
+ if (state) await optimizeState(state);
26321
+ mutationCounts.set(key, 0);
26322
+ });
26323
+ }
26324
+ async function optimizeSemanticIndexes(dataDir) {
26325
+ if (!existsSync10(indexRoot(dataDir))) return [];
26326
+ const lance = await loadLanceDb();
26327
+ if (!lance) throw new Error("LanceDB is unavailable; install the optional @lancedb/lancedb package");
26328
+ const connection = await lance.connect(indexRoot(dataDir));
26329
+ try {
26330
+ const names = typeof connection.tableNames === "function" ? await connection.tableNames() : (await connection.listTables()).tables;
26331
+ const optimized = [];
26332
+ for (const name of names.filter((value) => value.startsWith(TABLE_PREFIX))) {
26333
+ const table = await connection.openTable(name);
26334
+ await table.optimize({
26335
+ cleanupOlderThan: new Date(Date.now() - semanticVersionRetentionMs()),
26336
+ deleteUnverified: false
26337
+ });
26338
+ optimized.push(name);
26339
+ }
26340
+ return optimized;
26341
+ } finally {
26342
+ try {
26343
+ connection.close?.();
26344
+ } catch {
26345
+ }
26346
+ }
26347
+ }
26348
+ function deleteSemanticVector(dataDir, profile, observationId2) {
26349
+ return queueOperation(stateKey(dataDir, profile), async () => {
26350
+ const state = await getState(dataDir, profile);
26351
+ if (!state?.table) return;
26352
+ await state.table.delete(`observation_id = ${Math.trunc(observationId2)}`);
26353
+ });
26354
+ }
26224
26355
  function resolveIndexThreshold() {
26225
26356
  const raw = Number.parseInt(process.env.MEMORIX_SEMANTIC_INDEX_THRESHOLD ?? "", 10);
26226
26357
  return Number.isSafeInteger(raw) && raw > 0 ? raw : DEFAULT_INDEX_THRESHOLD;
@@ -26272,7 +26403,50 @@ async function searchSemanticVectors(options) {
26272
26403
  distance: Number(row._distance ?? Number.POSITIVE_INFINITY)
26273
26404
  })).filter((row) => Number.isFinite(row.distance));
26274
26405
  }
26275
- var SEMANTIC_INDEX_DIR, TABLE_PREFIX, DEFAULT_INDEX_THRESHOLD, MAX_INDEX_PARTITIONS, statePromises, writeQueues, indexBuilds, availability, requireFromHere2;
26406
+ async function closeSemanticIndexes() {
26407
+ await Promise.all([...pendingVectorBatches.keys()].map((key) => flushPendingVectorBatch(key)));
26408
+ await Promise.all([...writeQueues.values()]);
26409
+ for (const statePromise of statePromises.values()) {
26410
+ const state = await statePromise.catch(() => null);
26411
+ try {
26412
+ state?.connection?.close?.();
26413
+ } catch {
26414
+ }
26415
+ }
26416
+ statePromises.clear();
26417
+ writeQueues.clear();
26418
+ indexBuilds.clear();
26419
+ mutationCounts.clear();
26420
+ }
26421
+ async function closeSemanticIndex(dataDir) {
26422
+ const prefix = `${path10.resolve(dataDir)}::`;
26423
+ await Promise.all([...pendingVectorBatches.keys()].filter((key) => key.startsWith(prefix)).map(flushPendingVectorBatch));
26424
+ await Promise.all([...writeQueues.entries()].filter(([key]) => key.startsWith(prefix)).map(([, queue2]) => queue2));
26425
+ for (const [key, statePromise] of statePromises.entries()) {
26426
+ if (!key.startsWith(prefix)) continue;
26427
+ const state = await statePromise.catch(() => null);
26428
+ try {
26429
+ state?.connection?.close?.();
26430
+ } catch {
26431
+ }
26432
+ statePromises.delete(key);
26433
+ writeQueues.delete(key);
26434
+ indexBuilds.delete(key);
26435
+ mutationCounts.delete(key);
26436
+ }
26437
+ }
26438
+ function resetSemanticIndexRuntime() {
26439
+ for (const pending of pendingVectorBatches.values()) {
26440
+ if (pending.timer) clearTimeout(pending.timer);
26441
+ }
26442
+ pendingVectorBatches.clear();
26443
+ statePromises.clear();
26444
+ writeQueues.clear();
26445
+ indexBuilds.clear();
26446
+ mutationCounts.clear();
26447
+ availability = void 0;
26448
+ }
26449
+ 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;
26276
26450
  var init_semantic_index = __esm({
26277
26451
  "src/search/semantic-index.ts"() {
26278
26452
  "use strict";
@@ -26281,13 +26455,84 @@ var init_semantic_index = __esm({
26281
26455
  TABLE_PREFIX = "observations_";
26282
26456
  DEFAULT_INDEX_THRESHOLD = 1e4;
26283
26457
  MAX_INDEX_PARTITIONS = 32;
26458
+ DEFAULT_WRITE_BATCH_SIZE = 100;
26459
+ DEFAULT_WRITE_FLUSH_MS = 50;
26460
+ DEFAULT_OPTIMIZE_EVERY = 20;
26461
+ DEFAULT_VERSION_RETENTION_MS = 24 * 60 * 60 * 1e3;
26284
26462
  statePromises = /* @__PURE__ */ new Map();
26285
26463
  writeQueues = /* @__PURE__ */ new Map();
26286
26464
  indexBuilds = /* @__PURE__ */ new Map();
26465
+ mutationCounts = /* @__PURE__ */ new Map();
26466
+ pendingVectorBatches = /* @__PURE__ */ new Map();
26287
26467
  requireFromHere2 = createRequire3(import.meta.url);
26288
26468
  }
26289
26469
  });
26290
26470
 
26471
+ // src/memory/secret-filter.ts
26472
+ function applyRedaction(text3) {
26473
+ if (!text3) return text3;
26474
+ let out = text3;
26475
+ out = out.replace(
26476
+ /((?:password|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|access[_-]?key|private[_-]?key|client[_-]?secret)\s*[:=]\s*["']?)([^\s"',;\n]{6,})/gi,
26477
+ "$1[REDACTED]"
26478
+ );
26479
+ out = out.replace(
26480
+ /(Bearer\s+)([A-Za-z0-9._\-/+]{20,})/g,
26481
+ "$1[REDACTED]"
26482
+ );
26483
+ out = out.replace(/\b(?:ghp|ghs|gho|github_pat)_[A-Za-z0-9]{36,}\b/g, "[REDACTED]");
26484
+ out = out.replace(/\bsk-[A-Za-z0-9T-]{20,}\b/g, "[REDACTED]");
26485
+ out = out.replace(/\beyJ[A-Za-z0-9._-]{40,}\b/g, "[REDACTED]");
26486
+ return out;
26487
+ }
26488
+ function sanitizeCredentials(text3) {
26489
+ return applyRedaction(text3);
26490
+ }
26491
+ function redactCredentials(text3) {
26492
+ return applyRedaction(text3);
26493
+ }
26494
+ var init_secret_filter = __esm({
26495
+ "src/memory/secret-filter.ts"() {
26496
+ "use strict";
26497
+ init_esm_shims();
26498
+ }
26499
+ });
26500
+
26501
+ // src/search/derived-view-receipt.ts
26502
+ function sanitizeDerivedViewFailureReason(reason) {
26503
+ const safe = sanitizeCredentials(reason).replace(/(?:[A-Za-z]:[\\/]|\\\\[^\\/\s]+[\\/]|\/(?:home|Users|tmp|var|private|mnt|workspace|workspaces)\/)[^\s"'<>|]*/gi, "[path]").replace(/\s+/g, " ").trim();
26504
+ return safe.slice(0, 240) || "derived view failed";
26505
+ }
26506
+ function embeddingHealthReceipt(health, embeddingEnabled2) {
26507
+ if (health?.status === "disabled") {
26508
+ return { freshness: "current", rebuildStatus: "disabled" };
26509
+ }
26510
+ if (health?.status === "ready" || embeddingEnabled2) {
26511
+ return { freshness: "current", rebuildStatus: "idle" };
26512
+ }
26513
+ if (health?.status === "degraded") {
26514
+ return {
26515
+ freshness: "stale",
26516
+ rebuildStatus: "failed",
26517
+ ...health.failure ? {
26518
+ failureReason: `embedding ${health.failure.kind}; retry in ${health.failure.retryAfterMs}ms`
26519
+ } : { failureReason: "embedding provider degraded" }
26520
+ };
26521
+ }
26522
+ return {
26523
+ freshness: "unknown",
26524
+ rebuildStatus: "unavailable",
26525
+ failureReason: "embedding provider is not initialized"
26526
+ };
26527
+ }
26528
+ var init_derived_view_receipt = __esm({
26529
+ "src/search/derived-view-receipt.ts"() {
26530
+ "use strict";
26531
+ init_esm_shims();
26532
+ init_secret_filter();
26533
+ }
26534
+ });
26535
+
26291
26536
  // src/memory/entity-extractor.ts
26292
26537
  function extractEntities(content) {
26293
26538
  const result = {
@@ -26391,36 +26636,6 @@ var init_entity_extractor = __esm({
26391
26636
  }
26392
26637
  });
26393
26638
 
26394
- // src/memory/secret-filter.ts
26395
- function applyRedaction(text3) {
26396
- if (!text3) return text3;
26397
- let out = text3;
26398
- out = out.replace(
26399
- /((?:password|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|access[_-]?key|private[_-]?key|client[_-]?secret)\s*[:=]\s*["']?)([^\s"',;\n]{6,})/gi,
26400
- "$1[REDACTED]"
26401
- );
26402
- out = out.replace(
26403
- /(Bearer\s+)([A-Za-z0-9._\-/+]{20,})/g,
26404
- "$1[REDACTED]"
26405
- );
26406
- out = out.replace(/\b(?:ghp|ghs|gho|github_pat)_[A-Za-z0-9]{36,}\b/g, "[REDACTED]");
26407
- out = out.replace(/\bsk-[A-Za-z0-9T-]{20,}\b/g, "[REDACTED]");
26408
- out = out.replace(/\beyJ[A-Za-z0-9._-]{40,}\b/g, "[REDACTED]");
26409
- return out;
26410
- }
26411
- function sanitizeCredentials(text3) {
26412
- return applyRedaction(text3);
26413
- }
26414
- function redactCredentials(text3) {
26415
- return applyRedaction(text3);
26416
- }
26417
- var init_secret_filter = __esm({
26418
- "src/memory/secret-filter.ts"() {
26419
- "use strict";
26420
- init_esm_shims();
26421
- }
26422
- });
26423
-
26424
26639
  // src/runtime/maintenance-jobs.ts
26425
26640
  var maintenance_jobs_exports = {};
26426
26641
  __export(maintenance_jobs_exports, {
@@ -27279,7 +27494,7 @@ var init_maintenance_targets = __esm({
27279
27494
 
27280
27495
  // src/runtime/isolated-maintenance.ts
27281
27496
  import { spawn } from "child_process";
27282
- import { existsSync as existsSync10 } from "fs";
27497
+ import { existsSync as existsSync11 } from "fs";
27283
27498
  import os3 from "os";
27284
27499
  import path11 from "path";
27285
27500
  import { fileURLToPath as fileURLToPath3 } from "url";
@@ -27297,7 +27512,7 @@ function childError(prefix, detail) {
27297
27512
  }
27298
27513
  function isolatedMaintenanceCwd() {
27299
27514
  const tmp = os3.tmpdir();
27300
- return existsSync10(tmp) ? tmp : process.cwd();
27515
+ return existsSync11(tmp) ? tmp : process.cwd();
27301
27516
  }
27302
27517
  function resolveMaintenanceRunnerPath(moduleUrl = import.meta.url) {
27303
27518
  const moduleDir = path11.dirname(fileURLToPath3(moduleUrl));
@@ -27354,7 +27569,7 @@ function collectOutput(stream2, limit2, onOverflow) {
27354
27569
  async function runMaintenanceInChildProcess(request, options = {}) {
27355
27570
  validateRequest(request);
27356
27571
  const runnerPath = options.runnerPath ?? resolveMaintenanceRunnerPath();
27357
- if (!existsSync10(runnerPath)) {
27572
+ if (!existsSync11(runnerPath)) {
27358
27573
  throw new Error(`Maintenance runner is unavailable at ${runnerPath}. Reinstall or rebuild Memorix.`);
27359
27574
  }
27360
27575
  const timeoutMs = Number.isFinite(options.timeoutMs) ? Math.max(1e3, Math.floor(options.timeoutMs)) : DEFAULT_TIMEOUT_MS;
@@ -178372,7 +178587,7 @@ __export(video_jobs_exports, {
178372
178587
  runMiniMaxVideoGenerationJob: () => runMiniMaxVideoGenerationJob
178373
178588
  });
178374
178589
  import { spawn as spawn2 } from "child_process";
178375
- import { existsSync as existsSync11 } from "fs";
178590
+ import { existsSync as existsSync12 } from "fs";
178376
178591
  import path17 from "path";
178377
178592
  import { fileURLToPath as fileURLToPath4 } from "url";
178378
178593
  function safeError2(error40) {
@@ -178620,7 +178835,7 @@ function resolveMediaVideoRunnerPath(moduleUrl = import.meta.url) {
178620
178835
  }
178621
178836
  function launchMediaVideoRunner(request, options = {}) {
178622
178837
  const runnerPath = options.runnerPath ?? resolveMediaVideoRunnerPath();
178623
- if (!existsSync11(runnerPath)) {
178838
+ if (!existsSync12(runnerPath)) {
178624
178839
  return { launched: false, reason: "Media video runner is unavailable until Memorix is built or reinstalled." };
178625
178840
  }
178626
178841
  try {
@@ -178665,7 +178880,7 @@ __export(audio_jobs_exports, {
178665
178880
  transcribeAudio: () => transcribeAudio
178666
178881
  });
178667
178882
  import { spawn as spawn3 } from "child_process";
178668
- import { existsSync as existsSync12 } from "fs";
178883
+ import { existsSync as existsSync13 } from "fs";
178669
178884
  import path18 from "path";
178670
178885
  import { fileURLToPath as fileURLToPath5 } from "url";
178671
178886
  function safeError3(error40) {
@@ -178916,7 +179131,7 @@ function resolveMediaAudioRunnerPath(moduleUrl = import.meta.url) {
178916
179131
  }
178917
179132
  function launchMediaAudioRunner(request, options = {}) {
178918
179133
  const runnerPath = options.runnerPath ?? resolveMediaAudioRunnerPath();
178919
- if (!existsSync12(runnerPath)) return { launched: false, reason: "Audio runner is unavailable until Memorix is built or reinstalled." };
179134
+ if (!existsSync13(runnerPath)) return { launched: false, reason: "Audio runner is unavailable until Memorix is built or reinstalled." };
178920
179135
  try {
178921
179136
  const child = spawn3(process.execPath, [runnerPath, JSON.stringify(request)], {
178922
179137
  cwd: request.projectRoot,
@@ -181889,7 +182104,7 @@ __export(lite_provider_exports, {
181889
182104
  refreshProjectLite: () => refreshProjectLite
181890
182105
  });
181891
182106
  import { createHash as createHash11 } from "crypto";
181892
- import { existsSync as existsSync14, readdirSync as readdirSync2, readFileSync as readFileSync9, statSync as statSync4 } from "fs";
182107
+ import { existsSync as existsSync15, readdirSync as readdirSync2, readFileSync as readFileSync9, statSync as statSync4 } from "fs";
181893
182108
  import { join as join5, relative as relative2 } from "path";
181894
182109
  function hashText2(text3) {
181895
182110
  return createHash11("sha256").update(text3).digest("hex");
@@ -181907,7 +182122,7 @@ function resolveMaxFileBytes(value) {
181907
182122
  return Math.max(1, Math.floor(value));
181908
182123
  }
181909
182124
  function isPythonVirtualenvDir(dir) {
181910
- return existsSync14(join5(dir, "pyvenv.cfg"));
182125
+ return existsSync15(join5(dir, "pyvenv.cfg"));
181911
182126
  }
181912
182127
  function walk(root, exclude, maxFiles) {
181913
182128
  const out = [];
@@ -185823,7 +186038,7 @@ __export(vector_backfill_runner_exports, {
185823
186038
  import { spawn as spawn4 } from "child_process";
185824
186039
  import {
185825
186040
  closeSync,
185826
- existsSync as existsSync15,
186041
+ existsSync as existsSync16,
185827
186042
  mkdirSync as mkdirSync2,
185828
186043
  openSync,
185829
186044
  readFileSync as readFileSync10,
@@ -185951,7 +186166,7 @@ function releaseVectorBackfillLock(lockPath = process.env.MEMORIX_VECTOR_BACKFIL
185951
186166
  }
185952
186167
  function launchDetachedVectorBackfill(request, options = {}) {
185953
186168
  const runnerPath = options.runnerPath ?? resolveVectorBackfillRunnerPath();
185954
- const exists3 = options.exists ?? existsSync15;
186169
+ const exists3 = options.exists ?? existsSync16;
185955
186170
  if (!exists3(runnerPath)) return false;
185956
186171
  const lock = acquireVectorBackfillLock(request.dataDir, request.projectId, options.lockPath);
185957
186172
  if (!lock) return false;
@@ -186970,13 +187185,14 @@ async function prepareSearchIndex(options = {}) {
186970
187185
  return 0;
186971
187186
  }
186972
187187
  const hydratedProjectDir = projectDir;
186973
- const queueMissingVectors = () => {
186974
- if (projectDir !== hydratedProjectDir) return;
187188
+ const queueMissingVectors = async () => {
187189
+ if (!hydratedProjectDir || projectDir !== hydratedProjectDir) return;
186975
187190
  vectorMissingIds.clear();
186976
187191
  if (!isEmbeddingExplicitlyDisabled()) {
187192
+ const persistedSemanticIds = await getPersistentSemanticVectorIds(hydratedProjectDir).catch(() => null);
186977
187193
  const projectsWithMissingVectors = /* @__PURE__ */ new Set();
186978
187194
  for (const obs of observations) {
186979
- if (!hasObservationVector(obs.projectId, obs.id)) {
187195
+ if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(obs.id)) {
186980
187196
  vectorMissingIds.add(obs.id);
186981
187197
  projectsWithMissingVectors.add(obs.projectId);
186982
187198
  }
@@ -186986,9 +187202,9 @@ async function prepareSearchIndex(options = {}) {
186986
187202
  };
186987
187203
  const cacheHydration = getDeferredCachedVectorHydration();
186988
187204
  if (cacheHydration) {
186989
- void cacheHydration.finally(queueMissingVectors);
187205
+ void cacheHydration.then(queueMissingVectors, queueMissingVectors).catch(() => void 0);
186990
187206
  } else {
186991
- queueMissingVectors();
187207
+ await queueMissingVectors();
186992
187208
  }
186993
187209
  searchIndexPrepared = true;
186994
187210
  return count3;
@@ -187807,6 +188023,7 @@ __export(orama_store_exports, {
187807
188023
  getLastSearchMode: () => getLastSearchMode,
187808
188024
  getObservationCount: () => getObservationCount2,
187809
188025
  getObservationsByIds: () => getObservationsByIds,
188026
+ getPersistentSemanticVectorIds: () => getPersistentSemanticVectorIds,
187810
188027
  getSearchDerivedViews: () => getSearchDerivedViews,
187811
188028
  getTimeline: () => getTimeline,
187812
188029
  getVectorDimensions: () => getVectorDimensions,
@@ -187850,14 +188067,16 @@ function getSearchDerivedViews() {
187850
188067
  generation,
187851
188068
  freshness: "unknown",
187852
188069
  rebuildStatus: "unavailable",
187853
- failureReason: store2.getBackendReason?.() ?? "persistent lexical index unavailable"
188070
+ failureReason: sanitizeDerivedViewFailureReason(
188071
+ store2.getBackendReason?.() ?? "persistent lexical index unavailable"
188072
+ )
187854
188073
  };
187855
188074
  }
187856
188075
  } catch (error40) {
187857
188076
  views.fts = {
187858
188077
  freshness: "unknown",
187859
188078
  rebuildStatus: "failed",
187860
- failureReason: error40 instanceof Error ? error40.message.slice(0, 240) : String(error40).slice(0, 240)
188079
+ failureReason: sanitizeDerivedViewFailureReason(error40 instanceof Error ? error40.message : String(error40))
187861
188080
  };
187862
188081
  }
187863
188082
  } else {
@@ -187873,18 +188092,12 @@ function getSearchDerivedViews() {
187873
188092
  rebuildStatus: "unavailable",
187874
188093
  failureReason: "Orama index is not initialized"
187875
188094
  };
187876
- const configuredEmbeddingMode = process.env.MEMORIX_EMBEDDING?.trim().toLowerCase();
187877
- if (configuredEmbeddingMode === "off") {
187878
- views.embedding = { freshness: "current", rebuildStatus: "disabled" };
187879
- } else if (embeddingEnabled) {
187880
- views.embedding = { freshness: "current", rebuildStatus: "idle" };
187881
- } else {
187882
- views.embedding = {
187883
- freshness: "unknown",
187884
- rebuildStatus: "unavailable",
187885
- failureReason: "embedding provider is not initialized"
187886
- };
188095
+ let embeddingHealth;
188096
+ try {
188097
+ embeddingHealth = getEmbeddingRuntimeHealth?.();
188098
+ } catch {
187887
188099
  }
188100
+ views.embedding = embeddingHealthReceipt(embeddingHealth, embeddingEnabled);
187888
188101
  return views;
187889
188102
  }
187890
188103
  function rememberSearchDiagnostics(key, value) {
@@ -188188,12 +188401,16 @@ function getVectorDimensions() {
188188
188401
  function getActiveSemanticIndexProfile() {
188189
188402
  return indexEmbeddingProvider ? createSemanticIndexProfile(indexEmbeddingProvider) : null;
188190
188403
  }
188404
+ async function getPersistentSemanticVectorIds(dataDir) {
188405
+ if (!indexEmbeddingProvider) return null;
188406
+ return listSemanticVectorIds(dataDir, createSemanticIndexProfile(indexEmbeddingProvider));
188407
+ }
188191
188408
  async function queueSemanticVector(dataDir, record2) {
188192
188409
  const provider2 = indexEmbeddingProvider ?? await getEmbeddingProvider();
188193
188410
  const profile = provider2 ? createSemanticIndexProfile(provider2) : null;
188194
188411
  if (!profile) return;
188195
188412
  try {
188196
- await upsertSemanticVectors(dataDir, profile, [record2]);
188413
+ await upsertSemanticVector(dataDir, profile, record2);
188197
188414
  } catch {
188198
188415
  }
188199
188416
  }
@@ -188255,6 +188472,7 @@ function isCompatibleCachedVector(vector) {
188255
188472
  async function attachCachedVectors(database, observations2) {
188256
188473
  const semanticDataDir = (await Promise.resolve().then(() => (init_observations(), observations_exports))).getObservationDataDir();
188257
188474
  const semanticProfile = getActiveSemanticIndexProfile();
188475
+ const persistedSemanticIds = semanticDataDir && semanticProfile ? await listSemanticVectorIds(semanticDataDir, semanticProfile).catch(() => null) : null;
188258
188476
  const batchSize = 200;
188259
188477
  for (let start = 0; start < observations2.length; start += batchSize) {
188260
188478
  const batch = observations2.slice(start, start + batchSize);
@@ -188265,7 +188483,7 @@ async function attachCachedVectors(database, observations2) {
188265
188483
  const vector = cachedVectors[index];
188266
188484
  if (!isCompatibleCachedVector(vector)) continue;
188267
188485
  const observation = batch[index];
188268
- if (semanticDataDir && semanticProfile) {
188486
+ if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(observation.id)) {
188269
188487
  semanticRecords.push({
188270
188488
  observationId: observation.id,
188271
188489
  projectId: observation.projectId,
@@ -189039,6 +189257,7 @@ var init_orama_store = __esm({
189039
189257
  init_mini_skills();
189040
189258
  init_visibility();
189041
189259
  init_provider();
189260
+ init_provider();
189042
189261
  init_project_affinity();
189043
189262
  init_intent_detector();
189044
189263
  init_query_expansion();
@@ -189046,6 +189265,7 @@ var init_orama_store = __esm({
189046
189265
  init_timeout();
189047
189266
  init_obs_store();
189048
189267
  init_semantic_index();
189268
+ init_derived_view_receipt();
189049
189269
  db = null;
189050
189270
  dbInitPromise = null;
189051
189271
  dbGeneration = 0;
@@ -193352,7 +193572,7 @@ __export(init_exports, {
193352
193572
  buildInitTomlConfig: () => buildInitTomlConfig,
193353
193573
  default: () => init_default5
193354
193574
  });
193355
- import { existsSync as existsSync16, mkdirSync as mkdirSync3, writeFileSync as writeFileSync3 } from "fs";
193575
+ import { existsSync as existsSync17, mkdirSync as mkdirSync3, writeFileSync as writeFileSync3 } from "fs";
193356
193576
  import { homedir as homedir8 } from "os";
193357
193577
  import path29 from "path";
193358
193578
  function buildInitTomlConfig(options) {
@@ -193509,7 +193729,7 @@ var init_init = __esm({
193509
193729
  const targetPath = path29.join(targetDir, isGlobal ? getInitConfigFilename() : getInitProjectConfigFilename());
193510
193730
  const envPath = path29.join(targetDir, ".env");
193511
193731
  v3.info(getInitScopeDescription(scope));
193512
- if (existsSync16(targetPath)) {
193732
+ if (existsSync17(targetPath)) {
193513
193733
  const overwrite = await me({
193514
193734
  message: `${targetPath} already exists. Overwrite it?`,
193515
193735
  initialValue: false
@@ -193626,10 +193846,10 @@ var init_init = __esm({
193626
193846
  v3.success(`Created ${targetPath}`);
193627
193847
  if (shouldOfferDotenv(scope)) {
193628
193848
  const envExamplePath = getEnvTemplateTarget(targetDir, {
193629
- hasDotenvExample: existsSync16(path29.join(targetDir, ".env.example"))
193849
+ hasDotenvExample: existsSync17(path29.join(targetDir, ".env.example"))
193630
193850
  });
193631
193851
  const envContent = envLines.join("\n");
193632
- if (existsSync16(envExamplePath)) {
193852
+ if (existsSync17(envExamplePath)) {
193633
193853
  const overwriteEnvTemplate = await me({
193634
193854
  message: `${envExamplePath} already exists. Overwrite it?`,
193635
193855
  initialValue: false
@@ -193641,7 +193861,7 @@ var init_init = __esm({
193641
193861
  }
193642
193862
  writeFileSync3(envExamplePath, envContent, "utf-8");
193643
193863
  v3.success(`Created ${envExamplePath}`);
193644
- const createEnv = !existsSync16(envPath) ? await me({
193864
+ const createEnv = !existsSync17(envPath) ? await me({
193645
193865
  message: `Create .env from ${path29.basename(envExamplePath)} now? (you can fill in keys later)`,
193646
193866
  initialValue: true
193647
193867
  }) : false;
@@ -197247,7 +197467,7 @@ __export(setup_exports, {
197247
197467
  tryInstallCodexPlugin: () => tryInstallCodexPlugin
197248
197468
  });
197249
197469
  import { spawnSync } from "child_process";
197250
- import { existsSync as existsSync17 } from "fs";
197470
+ import { existsSync as existsSync18 } from "fs";
197251
197471
  import { copyFile as copyFile2, mkdir as mkdir6, readFile as readFile6, readdir as readdir3, rm as rm2, writeFile as writeFile7 } from "fs/promises";
197252
197472
  import { homedir as homedir28 } from "os";
197253
197473
  import path32 from "path";
@@ -197292,7 +197512,7 @@ function buildSetupPlan(options) {
197292
197512
  function findPackageRoot(start = path32.dirname(fileURLToPath7(import.meta.url))) {
197293
197513
  let dir = start;
197294
197514
  for (let i4 = 0; i4 < 8; i4++) {
197295
- if (existsSync17(path32.join(dir, "package.json")) && existsSync17(path32.join(dir, "plugins"))) {
197515
+ if (existsSync18(path32.join(dir, "package.json")) && existsSync18(path32.join(dir, "plugins"))) {
197296
197516
  return dir;
197297
197517
  }
197298
197518
  const parent = path32.dirname(dir);
@@ -197444,7 +197664,7 @@ async function rewriteBundledMemorixMcpToHttp(root) {
197444
197664
  const candidates = [".mcp.json", "mcp_config.json", "gemini-extension.json"].map((name) => path32.join(root, name));
197445
197665
  const rewritten = [];
197446
197666
  for (const filePath of candidates) {
197447
- if (!existsSync17(filePath)) continue;
197667
+ if (!existsSync18(filePath)) continue;
197448
197668
  let doc;
197449
197669
  try {
197450
197670
  doc = JSON.parse(await readFile6(filePath, "utf-8"));
@@ -197609,8 +197829,8 @@ function isOwnedLegacyCodexHooks(content) {
197609
197829
  async function removeOwnedLegacyCodexPluginFolder(homeDir) {
197610
197830
  const canonicalPath2 = path32.join(homeDir, "plugins", "memorix");
197611
197831
  const legacyPath = path32.join(homeDir, ".codex", "plugins", "memorix");
197612
- if (!existsSync17(legacyPath)) return "missing";
197613
- if (!existsSync17(canonicalPath2)) return "preserved";
197832
+ if (!existsSync18(legacyPath)) return "missing";
197833
+ if (!existsSync18(canonicalPath2)) return "preserved";
197614
197834
  try {
197615
197835
  const manifest = JSON.parse(await readFile6(path32.join(legacyPath, ".codex-plugin", "plugin.json"), "utf-8"));
197616
197836
  const repository = String(manifest.repository ?? "");
@@ -197826,7 +198046,7 @@ async function installCodeBuddyPluginPackage(options = {}) {
197826
198046
  const home = options.homeDir ?? homedir28();
197827
198047
  const packageRoot2 = findPackageRoot();
197828
198048
  const source = path32.join(packageRoot2, "plugins", "codebuddy", "memorix");
197829
- if (!existsSync17(source)) throw new Error(`CodeBuddy plugin template not found: ${source}`);
198049
+ if (!existsSync18(source)) throw new Error(`CodeBuddy plugin template not found: ${source}`);
197830
198050
  const marketplaceRoot = path32.join(home, ".codebuddy", "memorix-local");
197831
198051
  const marketplacePath = path32.join(marketplaceRoot, ".codebuddy-plugin", "marketplace.json");
197832
198052
  const pluginPath = path32.join(marketplaceRoot, "plugins", "memorix");
@@ -197847,7 +198067,7 @@ async function installPluginPackage(options) {
197847
198067
  const packageRoot2 = findPackageRoot();
197848
198068
  const source = path32.join(packageRoot2, "plugins", options.agent, "memorix");
197849
198069
  const includeHooks = options.includeHooks ?? true;
197850
- if (!existsSync17(source)) {
198070
+ if (!existsSync18(source)) {
197851
198071
  throw new Error(`Plugin package template not found: ${source}`);
197852
198072
  }
197853
198073
  if (options.agent === "codex") {
@@ -197895,7 +198115,7 @@ async function installGeminiExtensionPackage(options = {}) {
197895
198115
  const home = options.homeDir ?? homedir28();
197896
198116
  const packageRoot2 = findPackageRoot();
197897
198117
  const source = path32.join(packageRoot2, "plugins", "gemini", "memorix");
197898
- if (!existsSync17(source)) {
198118
+ if (!existsSync18(source)) {
197899
198119
  throw new Error(`Gemini extension template not found: ${source}`);
197900
198120
  }
197901
198121
  const extensionPath = path32.join(home, ".gemini", "extensions", "memorix");
@@ -197909,7 +198129,7 @@ async function installGeminiExtensionPackage(options = {}) {
197909
198129
  async function installAntigravityPluginPackage(options = {}) {
197910
198130
  const packageRoot2 = findPackageRoot();
197911
198131
  const source = path32.join(packageRoot2, "plugins", "antigravity", "memorix");
197912
- if (!existsSync17(source)) {
198132
+ if (!existsSync18(source)) {
197913
198133
  throw new Error(`Antigravity plugin template not found: ${source}`);
197914
198134
  }
197915
198135
  const pluginPath = options.global === false ? path32.join(options.projectRoot ?? process.cwd(), ".agents", "plugins", "memorix") : path32.join(options.homeDir ?? homedir28(), ".gemini", "config", "plugins", "memorix");
@@ -197927,7 +198147,7 @@ async function installAntigravityPluginPackage(options = {}) {
197927
198147
  async function installPiPackage(options = {}) {
197928
198148
  const packageRoot2 = findPackageRoot();
197929
198149
  const source = path32.join(packageRoot2, "plugins", "pi", "memorix");
197930
- if (!existsSync17(source)) {
198150
+ if (!existsSync18(source)) {
197931
198151
  throw new Error(`Pi package template not found: ${source}`);
197932
198152
  }
197933
198153
  const defaultRoot = options.global ? path32.join(options.homeDir ?? homedir28(), ".pi", "agent", "packages") : path32.join(process.cwd(), ".pi", "packages");
@@ -197945,7 +198165,7 @@ async function installOpenClawBundlePackage(options = {}) {
197945
198165
  const home = options.homeDir ?? homedir28();
197946
198166
  const packageRoot2 = findPackageRoot();
197947
198167
  const source = path32.join(packageRoot2, "plugins", "openclaw", "memorix");
197948
- if (!existsSync17(source)) {
198168
+ if (!existsSync18(source)) {
197949
198169
  throw new Error(`OpenClaw bundle template not found: ${source}`);
197950
198170
  }
197951
198171
  const bundlePath = path32.join(home, ".openclaw", "extensions", "memorix");
@@ -197961,7 +198181,7 @@ async function installOpenClawBundlePackage(options = {}) {
197961
198181
  async function installHermesPluginPackage(options = {}) {
197962
198182
  const packageRoot2 = findPackageRoot();
197963
198183
  const source = path32.join(packageRoot2, "plugins", "hermes", "memorix");
197964
- if (!existsSync17(source)) {
198184
+ if (!existsSync18(source)) {
197965
198185
  throw new Error(`Hermes plugin template not found: ${source}`);
197966
198186
  }
197967
198187
  const hermesHome = resolveHermesHome(options.homeDir);
@@ -197988,7 +198208,7 @@ async function installHermesPluginPackage(options = {}) {
197988
198208
  async function installOmpPackage(options = {}) {
197989
198209
  const packageRoot2 = findPackageRoot();
197990
198210
  const source = path32.join(packageRoot2, "plugins", "omp", "memorix");
197991
- if (!existsSync17(source)) {
198211
+ if (!existsSync18(source)) {
197992
198212
  throw new Error(`Oh-my-Pi package template not found: ${source}`);
197993
198213
  }
197994
198214
  const defaultRoot = options.global ? path32.join(options.homeDir ?? homedir28(), ".omp", "agent", "packages") : path32.join(process.cwd(), ".omp", "packages");
@@ -198215,7 +198435,7 @@ ${hook.stdout || ""}`.toLowerCase();
198215
198435
  function resolveHermesCommand(hermesHome) {
198216
198436
  if (process.platform === "win32") {
198217
198437
  const localHermes = path32.join(hermesHome, "hermes-agent", "venv", "Scripts", "hermes.exe");
198218
- if (existsSync17(localHermes)) return localHermes;
198438
+ if (existsSync18(localHermes)) return localHermes;
198219
198439
  }
198220
198440
  return "hermes";
198221
198441
  }
@@ -199937,11 +200157,11 @@ __export(current_facts_exports, {
199937
200157
  formatGitFact: () => formatGitFact
199938
200158
  });
199939
200159
  import { execFileSync } from "child_process";
199940
- import { existsSync as existsSync18, readFileSync as readFileSync11 } from "fs";
200160
+ import { existsSync as existsSync19, readFileSync as readFileSync11 } from "fs";
199941
200161
  import path33 from "path";
199942
200162
  function readTextIfExists(filePath) {
199943
200163
  try {
199944
- if (!existsSync18(filePath)) return null;
200164
+ if (!existsSync19(filePath)) return null;
199945
200165
  return readFileSync11(filePath, "utf8");
199946
200166
  } catch {
199947
200167
  return null;
@@ -200232,7 +200452,7 @@ __export(external_provider_exports, {
200232
200452
  runExternalCodeGraphLifecycle: () => runExternalCodeGraphLifecycle
200233
200453
  });
200234
200454
  import { spawn as spawn5 } from "child_process";
200235
- import { existsSync as existsSync19, readFileSync as readFileSync12 } from "fs";
200455
+ import { existsSync as existsSync20, readFileSync as readFileSync12 } from "fs";
200236
200456
  import { delimiter, dirname as dirname5, extname, isAbsolute as isAbsolute4, join as join25, relative as relative4, resolve as resolve6, sep as sep2 } from "path";
200237
200457
  function boundedTimeout(value) {
200238
200458
  if (!Number.isFinite(value)) return DEFAULT_EXTERNAL_CODEGRAPH_TIMEOUT_MS;
@@ -200269,13 +200489,13 @@ function resolveCommandCandidates(command) {
200269
200489
  }
200270
200490
  function resolveLaunch(command) {
200271
200491
  for (const candidate2 of resolveCommandCandidates(command)) {
200272
- if (!existsSync19(candidate2)) continue;
200492
+ if (!existsSync20(candidate2)) continue;
200273
200493
  const extension3 = extname(candidate2).toLowerCase();
200274
200494
  if (extension3 === ".cmd") {
200275
200495
  const bundleRoot = resolve6(dirname5(candidate2), "..");
200276
200496
  const node = join25(bundleRoot, "node.exe");
200277
200497
  const entry = join25(bundleRoot, "lib", "dist", "bin", "codegraph.js");
200278
- if (existsSync19(node) && existsSync19(entry)) {
200498
+ if (existsSync20(node) && existsSync20(entry)) {
200279
200499
  return { executable: node, prefixArgs: ["--liftoff-only", entry] };
200280
200500
  }
200281
200501
  try {
@@ -200284,7 +200504,7 @@ function resolveLaunch(command) {
200284
200504
  if (match2?.[1]) {
200285
200505
  const base = dirname5(candidate2).endsWith(sep2) ? dirname5(candidate2) : dirname5(candidate2) + sep2;
200286
200506
  const entry2 = resolve6(match2[1].replace(/%(?:~)?dp0%?/gi, base));
200287
- if (existsSync19(entry2)) return { executable: process.execPath, prefixArgs: [entry2] };
200507
+ if (existsSync20(entry2)) return { executable: process.execPath, prefixArgs: [entry2] };
200288
200508
  }
200289
200509
  } catch {
200290
200510
  }
@@ -200432,7 +200652,7 @@ async function inspectExternalCodeGraph(input) {
200432
200652
  const health2 = { state: "disabled", reason: "External CodeGraph is disabled by configuration." };
200433
200653
  return { health: health2, quality: providerQuality({ mode, health: health2 }) };
200434
200654
  }
200435
- if (!existsSync19(join25(input.projectRoot, ".codegraph"))) {
200655
+ if (!existsSync20(join25(input.projectRoot, ".codegraph"))) {
200436
200656
  const health2 = { state: "not-detected", reason: "No local .codegraph index is present for this project." };
200437
200657
  return { health: health2, quality: providerQuality({ mode, health: health2 }) };
200438
200658
  }
@@ -200468,7 +200688,7 @@ async function runExternalCodeGraphLifecycle(input) {
200468
200688
  };
200469
200689
  }
200470
200690
  const indexPath = join25(input.projectRoot, ".codegraph");
200471
- if (input.action === "sync" && !existsSync19(indexPath)) {
200691
+ if (input.action === "sync" && !existsSync20(indexPath)) {
200472
200692
  const health = { state: "not-detected", reason: "No local .codegraph index is present for this project." };
200473
200693
  return {
200474
200694
  action: input.action,
@@ -200478,7 +200698,7 @@ async function runExternalCodeGraphLifecycle(input) {
200478
200698
  quality: providerQuality({ mode, health })
200479
200699
  };
200480
200700
  }
200481
- if (input.action === "init" && existsSync19(indexPath)) {
200701
+ if (input.action === "init" && existsSync20(indexPath)) {
200482
200702
  const inspected2 = await inspectExternalCodeGraph(input);
200483
200703
  return {
200484
200704
  action: input.action,
@@ -202253,13 +202473,13 @@ function buildCodeGraphDerivedView(input) {
202253
202473
  ...snapshot.sourceEpoch !== void 0 ? { generation: snapshot.sourceEpoch } : {},
202254
202474
  freshness: snapshot.incomplete ? "stale" : "current",
202255
202475
  rebuildStatus: snapshot.incomplete ? "failed" : "idle",
202256
- ...snapshot.incomplete ? { failureReason: "latest CodeGraph snapshot is incomplete" } : externalFailure && provider2?.external.reason ? { failureReason: provider2.external.reason.slice(0, 240) } : {}
202476
+ ...snapshot.incomplete ? { failureReason: "latest CodeGraph snapshot is incomplete" } : externalFailure && provider2?.external.reason ? { failureReason: sanitizeDerivedViewFailureReason(provider2.external.reason) } : {}
202257
202477
  };
202258
202478
  }
202259
202479
  return {
202260
202480
  freshness: "unknown",
202261
202481
  rebuildStatus: externalFailure ? "failed" : "unavailable",
202262
- ...provider2?.external.reason ? { failureReason: provider2.external.reason.slice(0, 240) } : { failureReason: "CodeGraph snapshot is not initialized" }
202482
+ ...provider2?.external.reason ? { failureReason: sanitizeDerivedViewFailureReason(provider2.external.reason) } : { failureReason: "CodeGraph snapshot is not initialized" }
202263
202483
  };
202264
202484
  }
202265
202485
  function buildBoundedContextReceipt(input) {
@@ -202289,6 +202509,7 @@ var init_context_receipt = __esm({
202289
202509
  "src/knowledge/context-receipt.ts"() {
202290
202510
  "use strict";
202291
202511
  init_esm_shims();
202512
+ init_derived_view_receipt();
202292
202513
  }
202293
202514
  });
202294
202515
 
@@ -202905,7 +203126,7 @@ __export(auto_context_exports, {
202905
203126
  formatAutoProjectContextSummary: () => formatAutoProjectContextSummary,
202906
203127
  formatLegacyAutoProjectContextPrompt: () => formatLegacyAutoProjectContextPrompt
202907
203128
  });
202908
- import { existsSync as existsSync20, statSync as statSync6 } from "fs";
203129
+ import { existsSync as existsSync21, statSync as statSync6 } from "fs";
202909
203130
  import path35 from "path";
202910
203131
  function activeProjectObservations(observations2, projectId) {
202911
203132
  return observations2.filter((obs) => obs.projectId === projectId && (obs.status ?? "active") === "active");
@@ -203280,7 +203501,7 @@ function existingLensCandidates(rootPath, lens) {
203280
203501
  for (const candidate2 of lensPathCandidates(lens)) {
203281
203502
  const absolute = path35.join(rootPath, candidate2);
203282
203503
  try {
203283
- if (!existsSync20(absolute)) continue;
203504
+ if (!existsSync21(absolute)) continue;
203284
203505
  const stat6 = statSync6(absolute);
203285
203506
  if (stat6.isFile()) out.push(candidate2);
203286
203507
  if (stat6.isDirectory()) out.push(candidate2.replace(/\\/g, "/"));
@@ -207079,7 +207300,7 @@ var engine_exports2 = {};
207079
207300
  __export(engine_exports2, {
207080
207301
  SkillsEngine: () => SkillsEngine
207081
207302
  });
207082
- import { existsSync as existsSync21, readFileSync as readFileSync13, writeFileSync as writeFileSync5, mkdirSync as mkdirSync5, readdirSync as readdirSync3 } from "fs";
207303
+ import { existsSync as existsSync22, readFileSync as readFileSync13, writeFileSync as writeFileSync5, mkdirSync as mkdirSync5, readdirSync as readdirSync3 } from "fs";
207083
207304
  import { join as join26 } from "path";
207084
207305
  import { homedir as homedir32 } from "os";
207085
207306
  var SKILLS_DIRS, SKILL_WORTHY_TYPES, MIN_OBS_FOR_SKILL, MIN_SCORE_FOR_SKILL, LOW_SIGNAL_TITLE_PATTERNS, LOW_SIGNAL_ENTITY_PATTERNS, COMMAND_TRACE_PATTERNS2, SkillsEngine;
@@ -207160,7 +207381,7 @@ var init_engine4 = __esm({
207160
207381
  paths.push(join26(home, dir));
207161
207382
  }
207162
207383
  for (const skillsRoot of paths) {
207163
- if (!existsSync21(skillsRoot)) continue;
207384
+ if (!existsSync22(skillsRoot)) continue;
207164
207385
  try {
207165
207386
  const entries = readdirSync3(skillsRoot, { withFileTypes: true });
207166
207387
  for (const entry of entries) {
@@ -207168,7 +207389,7 @@ var init_engine4 = __esm({
207168
207389
  const name = entry.name;
207169
207390
  if (seen.has(name)) continue;
207170
207391
  const skillMd = join26(skillsRoot, name, "SKILL.md");
207171
- if (!existsSync21(skillMd)) continue;
207392
+ if (!existsSync22(skillMd)) continue;
207172
207393
  try {
207173
207394
  const content = readFileSync13(skillMd, "utf-8");
207174
207395
  const description = this.parseDescription(content);
@@ -208390,7 +208611,7 @@ var init_task_graph = __esm({
208390
208611
 
208391
208612
  // src/orchestrate/context-collector.ts
208392
208613
  import { execFileSync as execFileSync2 } from "child_process";
208393
- import { readFileSync as readFileSync14, existsSync as existsSync22 } from "fs";
208614
+ import { readFileSync as readFileSync14, existsSync as existsSync23 } from "fs";
208394
208615
  import { join as join27 } from "path";
208395
208616
  function normalizeEntryLimit(value, fallback) {
208396
208617
  if (!Number.isSafeInteger(value) || value < 1) return fallback;
@@ -208467,7 +208688,7 @@ function collectFileTree(projectDir2, maxEntries) {
208467
208688
  function collectDependencies(projectDir2) {
208468
208689
  try {
208469
208690
  const pkgPath = join27(projectDir2, "package.json");
208470
- if (!existsSync22(pkgPath)) return "";
208691
+ if (!existsSync23(pkgPath)) return "";
208471
208692
  const pkg = JSON.parse(readFileSync14(pkgPath, "utf-8"));
208472
208693
  const parts = [];
208473
208694
  if (pkg.dependencies && Object.keys(pkg.dependencies).length > 0) {
@@ -209517,7 +209738,7 @@ __export(receipt_service_exports, {
209517
209738
  formatHandoffReceipt: () => formatHandoffReceipt
209518
209739
  });
209519
209740
  import { createHash as createHash19 } from "crypto";
209520
- import { existsSync as existsSync23, readFileSync as readFileSync15 } from "fs";
209741
+ import { existsSync as existsSync24, readFileSync as readFileSync15 } from "fs";
209521
209742
  import path37 from "path";
209522
209743
  function sha256(value) {
209523
209744
  return `sha256:${createHash19("sha256").update(value).digest("hex")}`;
@@ -209548,7 +209769,7 @@ function safeJsonArray(value) {
209548
209769
  }
209549
209770
  async function loadReceiptObservations(dataDir, projectId) {
209550
209771
  const dbPath = path37.join(dataDir, "memorix.db");
209551
- if (existsSync23(dbPath)) {
209772
+ if (existsSync24(dbPath)) {
209552
209773
  try {
209553
209774
  const DB = loadBetterSqlite3();
209554
209775
  const db2 = new DB(dbPath, { readonly: true, fileMustExist: true });
@@ -209565,7 +209786,7 @@ async function loadReceiptObservations(dataDir, projectId) {
209565
209786
  }
209566
209787
  }
209567
209788
  const jsonPath = path37.join(dataDir, "observations.json");
209568
- if (!existsSync23(jsonPath)) return [];
209789
+ if (!existsSync24(jsonPath)) return [];
209569
209790
  try {
209570
209791
  const parsed = JSON.parse(readFileSync15(jsonPath, "utf-8"));
209571
209792
  if (!Array.isArray(parsed)) return [];
@@ -209804,7 +210025,7 @@ var init_tool_profile = __esm({
209804
210025
  function getMcpServerInfo() {
209805
210026
  return {
209806
210027
  name: "memorix",
209807
- version: true ? "1.10.1" : "1.0.1"
210028
+ version: true ? "1.10.2" : "1.0.1"
209808
210029
  };
209809
210030
  }
209810
210031
  function createMcpDiscoverResult(capabilities, serverInfo) {
@@ -223849,7 +224070,7 @@ var init_sanitizer = __esm({
223849
224070
  });
223850
224071
 
223851
224072
  // src/workspace/applier.ts
223852
- import { existsSync as existsSync24, mkdirSync as mkdirSync6, copyFileSync, writeFileSync as writeFileSync6, unlinkSync as unlinkSync2, renameSync } from "fs";
224073
+ import { existsSync as existsSync25, mkdirSync as mkdirSync6, copyFileSync, writeFileSync as writeFileSync6, unlinkSync as unlinkSync2, renameSync } from "fs";
223853
224074
  import { dirname as dirname6 } from "path";
223854
224075
  var WorkspaceSyncApplier;
223855
224076
  var init_applier = __esm({
@@ -223880,7 +224101,7 @@ var init_applier = __esm({
223880
224101
  for (const file2 of files) {
223881
224102
  try {
223882
224103
  const dir = dirname6(file2.filePath);
223883
- if (!existsSync24(dir)) {
224104
+ if (!existsSync25(dir)) {
223884
224105
  mkdirSync6(dir, { recursive: true });
223885
224106
  }
223886
224107
  } catch (err) {
@@ -223889,7 +224110,7 @@ var init_applier = __esm({
223889
224110
  }
223890
224111
  }
223891
224112
  for (const file2 of files) {
223892
- if (existsSync24(file2.filePath)) {
224113
+ if (existsSync25(file2.filePath)) {
223893
224114
  try {
223894
224115
  const backupPath = file2.filePath + `.backup-${Date.now()}`;
223895
224116
  copyFileSync(file2.filePath, backupPath);
@@ -223940,7 +224161,7 @@ var init_applier = __esm({
223940
224161
  cleanBackups(backups) {
223941
224162
  for (const backup of backups) {
223942
224163
  try {
223943
- if (existsSync24(backup.backupPath)) {
224164
+ if (existsSync25(backup.backupPath)) {
223944
224165
  unlinkSync2(backup.backupPath);
223945
224166
  }
223946
224167
  } catch {
@@ -223956,7 +224177,7 @@ var engine_exports3 = {};
223956
224177
  __export(engine_exports3, {
223957
224178
  WorkspaceSyncEngine: () => WorkspaceSyncEngine
223958
224179
  });
223959
- import { readFileSync as readFileSync16, readdirSync as readdirSync4, existsSync as existsSync25, cpSync, mkdirSync as mkdirSync7 } from "fs";
224180
+ import { readFileSync as readFileSync16, readdirSync as readdirSync4, existsSync as existsSync26, cpSync, mkdirSync as mkdirSync7 } from "fs";
223960
224181
  import { join as join29 } from "path";
223961
224182
  import { homedir as homedir33 } from "os";
223962
224183
  var WorkspaceSyncEngine;
@@ -224036,7 +224257,7 @@ var init_engine5 = __esm({
224036
224257
  }
224037
224258
  const merged = /* @__PURE__ */ new Map();
224038
224259
  for (const path50 of pathsToCheck) {
224039
- if (existsSync25(path50)) {
224260
+ if (existsSync26(path50)) {
224040
224261
  try {
224041
224262
  const content = readFileSync16(path50, "utf-8");
224042
224263
  const servers = adapter.parse(content);
@@ -224090,7 +224311,7 @@ var init_engine5 = __esm({
224090
224311
  const adapter = this.adapters.get(target);
224091
224312
  const configPath = adapter.getConfigPath(this.projectRoot);
224092
224313
  let configContent;
224093
- if (target === "antigravity" && existsSync25(configPath)) {
224314
+ if (target === "antigravity" && existsSync26(configPath)) {
224094
224315
  try {
224095
224316
  const existing = JSON.parse(readFileSync16(configPath, "utf-8"));
224096
224317
  const generated = JSON.parse(adapter.generate(result.mcpServers.scanned));
@@ -224166,13 +224387,13 @@ var init_engine5 = __esm({
224166
224387
  join29(home, dir)
224167
224388
  ];
224168
224389
  for (const skillsRoot of paths) {
224169
- if (!existsSync25(skillsRoot)) continue;
224390
+ if (!existsSync26(skillsRoot)) continue;
224170
224391
  try {
224171
224392
  const entries = readdirSync4(skillsRoot, { withFileTypes: true });
224172
224393
  for (const entry of entries) {
224173
224394
  if (!entry.isDirectory()) continue;
224174
224395
  const skillMd = join29(skillsRoot, entry.name, "SKILL.md");
224175
- if (!existsSync25(skillMd)) continue;
224396
+ if (!existsSync26(skillMd)) continue;
224176
224397
  let description = "";
224177
224398
  try {
224178
224399
  const content = readFileSync16(skillMd, "utf-8");
@@ -224221,7 +224442,7 @@ var init_engine5 = __esm({
224221
224442
  for (const skill2 of skills) {
224222
224443
  if (skill2.sourceAgent === target) continue;
224223
224444
  const dest = join29(targetDir, skill2.name);
224224
- if (existsSync25(dest)) {
224445
+ if (existsSync26(dest)) {
224225
224446
  skipped.push(`${skill2.name} (already exists in ${target})`);
224226
224447
  continue;
224227
224448
  }
@@ -224237,7 +224458,7 @@ var init_engine5 = __esm({
224237
224458
  scanWorkflows() {
224238
224459
  const workflows = [];
224239
224460
  const wfDir = join29(this.projectRoot, ".windsurf", "workflows");
224240
- if (!existsSync25(wfDir)) return workflows;
224461
+ if (!existsSync26(wfDir)) return workflows;
224241
224462
  try {
224242
224463
  const files = readdirSync4(wfDir).filter((f7) => f7.endsWith(".md"));
224243
224464
  for (const file2 of files) {
@@ -224563,7 +224784,7 @@ __export(behavior_exports, {
224563
224784
  getBehaviorConfig: () => getBehaviorConfig,
224564
224785
  resetBehaviorConfigCache: () => resetBehaviorConfigCache
224565
224786
  });
224566
- import { existsSync as existsSync26, readFileSync as readFileSync17 } from "fs";
224787
+ import { existsSync as existsSync27, readFileSync as readFileSync17 } from "fs";
224567
224788
  import { homedir as homedir34 } from "os";
224568
224789
  function isSessionInject(value) {
224569
224790
  return value === "full" || value === "minimal" || value === "silent";
@@ -224574,7 +224795,7 @@ function isFormationMode(value) {
224574
224795
  function legacyBehavior(homeDir) {
224575
224796
  const configPath = getLegacyConfigJsonPath(homeDir);
224576
224797
  try {
224577
- if (!existsSync26(configPath)) return {};
224798
+ if (!existsSync27(configPath)) return {};
224578
224799
  const parsed = JSON.parse(readFileSync17(configPath, "utf-8"));
224579
224800
  return parsed.behavior && typeof parsed.behavior === "object" && !Array.isArray(parsed.behavior) ? parsed.behavior : {};
224580
224801
  } catch {
@@ -226080,7 +226301,7 @@ async function handleApi(req, res, dataDir, projectId, projectName, baseDir, pro
226080
226301
  }
226081
226302
  case "/config": {
226082
226303
  const os10 = await import("os");
226083
- const { existsSync: existsSync36 } = await import("fs");
226304
+ const { existsSync: existsSync37 } = await import("fs");
226084
226305
  const { join: join36 } = await import("path");
226085
226306
  const configProjectRoot = effectiveProjectRoot;
226086
226307
  const resolved = getResolvedConfig({ projectRoot: configProjectRoot });
@@ -226108,7 +226329,7 @@ async function handleApi(req, res, dataDir, projectId, projectName, baseDir, pro
226108
226329
  if (fpath === null) {
226109
226330
  files[key] = { exists: false, path: "unavailable", unavailable: true };
226110
226331
  } else {
226111
- files[key] = { exists: existsSync36(fpath), path: fpath };
226332
+ files[key] = { exists: existsSync37(fpath), path: fpath };
226112
226333
  }
226113
226334
  }
226114
226335
  } catch {
@@ -266580,11 +266801,11 @@ __export(hooks_path_exports, {
266580
266801
  resolveGitDir: () => resolveGitDir,
266581
266802
  resolveHooksDir: () => resolveHooksDir
266582
266803
  });
266583
- import { existsSync as existsSync27, readFileSync as readFileSync18, statSync as statSync7, mkdirSync as mkdirSync8 } from "fs";
266804
+ import { existsSync as existsSync28, readFileSync as readFileSync18, statSync as statSync7, mkdirSync as mkdirSync8 } from "fs";
266584
266805
  import path42 from "path";
266585
266806
  function resolveGitDir(projectRoot) {
266586
266807
  const dotGit = path42.join(projectRoot, ".git");
266587
- if (!existsSync27(dotGit)) return null;
266808
+ if (!existsSync28(dotGit)) return null;
266588
266809
  const stat6 = statSync7(dotGit);
266589
266810
  if (stat6.isDirectory()) {
266590
266811
  return dotGit;
@@ -266596,7 +266817,7 @@ function resolveGitDir(projectRoot) {
266596
266817
  if (match2) {
266597
266818
  const gitdir = match2[1].trim();
266598
266819
  const resolved = path42.isAbsolute(gitdir) ? gitdir : path42.resolve(projectRoot, gitdir);
266599
- if (existsSync27(resolved)) {
266820
+ if (existsSync28(resolved)) {
266600
266821
  return resolved;
266601
266822
  }
266602
266823
  }
@@ -267802,7 +268023,18 @@ _Search mode: ${result.receipt.mode}_`;
267802
268023
  text: text3
267803
268024
  }
267804
268025
  ],
267805
- structuredContent: { retrieval: result.receipt }
268026
+ // Clients that surface only structuredContent (e.g. Claude Code) must
268027
+ // still see the results, not just the retrieval diagnostics.
268028
+ structuredContent: {
268029
+ results: result.entries.map((entry) => ({
268030
+ ref: formatEntryRef(entry),
268031
+ title: entry.title,
268032
+ type: entry.type,
268033
+ time: entry.time,
268034
+ tokens: entry.tokens
268035
+ })),
268036
+ retrieval: result.receipt
268037
+ }
267806
268038
  };
267807
268039
  }, { loadCorpus: false });
267808
268040
  }
@@ -269870,9 +270102,12 @@ ${s4.instruction}`.toLowerCase();
269870
270102
  }
269871
270103
  } catch {
269872
270104
  }
270105
+ const card = lines.filter(Boolean).join("\n");
269873
270106
  return {
269874
- content: [{ type: "text", text: lines.filter(Boolean).join("\n") }],
269875
- structuredContent: { binding: bindingReceipt }
270107
+ content: [{ type: "text", text: card }],
270108
+ // Clients that surface only structuredContent (e.g. Claude Code) must
270109
+ // still see the session card, not just the binding receipt.
270110
+ structuredContent: { card, binding: bindingReceipt }
269876
270111
  };
269877
270112
  }
269878
270113
  );
@@ -271302,10 +271537,10 @@ Preview: ${analysis.description.slice(0, 300)}${analysis.description.length > 30
271302
271537
  const { ensureHooksDir: ensureHooksDir2 } = await Promise.resolve().then(() => (init_hooks_path(), hooks_path_exports));
271303
271538
  const resolved = ensureHooksDir2(project.rootPath);
271304
271539
  if (resolved) {
271305
- const { existsSync: existsSync36, readFileSync: readFileSync25, writeFileSync: writeFileSync13, chmodSync: chmodSync2 } = await import("fs");
271540
+ const { existsSync: existsSync37, readFileSync: readFileSync25, writeFileSync: writeFileSync13, chmodSync: chmodSync2 } = await import("fs");
271306
271541
  const { hookPath } = resolved;
271307
271542
  const HOOK_MARKER3 = "# [memorix-git-hook]";
271308
- const needsInstall = !existsSync36(hookPath) || !readFileSync25(hookPath, "utf-8").includes(HOOK_MARKER3);
271543
+ const needsInstall = !existsSync37(hookPath) || !readFileSync25(hookPath, "utf-8").includes(HOOK_MARKER3);
271309
271544
  if (needsInstall) {
271310
271545
  const hookScript = `#!/bin/sh
271311
271546
  ${HOOK_MARKER3}
@@ -271314,7 +271549,7 @@ if command -v memorix >/dev/null 2>&1; then
271314
271549
  memorix ingest commit --auto >/dev/null 2>&1 &
271315
271550
  fi
271316
271551
  `;
271317
- if (existsSync36(hookPath)) {
271552
+ if (existsSync37(hookPath)) {
271318
271553
  const existing = readFileSync25(hookPath, "utf-8");
271319
271554
  writeFileSync13(hookPath, existing.trimEnd() + `
271320
271555
 
@@ -271482,6 +271717,7 @@ var init_server4 = __esm({
271482
271717
  init_graph_scope();
271483
271718
  init_visibility();
271484
271719
  init_engine3();
271720
+ init_index_format();
271485
271721
  init_graph_context();
271486
271722
  init_detector();
271487
271723
  init_launch_root();
@@ -275813,7 +276049,7 @@ ${stack}` : ""}`);
275813
276049
  if (apiPath === "/config") {
275814
276050
  const { projectId: configProjectId } = await resolveRequestProject(url2);
275815
276051
  const os10 = await import("os");
275816
- const { existsSync: existsSync36 } = await import("fs");
276052
+ const { existsSync: existsSync37 } = await import("fs");
275817
276053
  const { join: join36 } = await import("path");
275818
276054
  const { loadYamlConfig: loadYamlConfig2 } = await Promise.resolve().then(() => (init_yaml_loader(), yaml_loader_exports));
275819
276055
  const { loadFileConfig: loadFileConfig2, loadDotenv: loadDotenv2, getLoadedEnvFiles: getLoadedEnvFiles2 } = await Promise.resolve().then(() => (init_config(), config_exports));
@@ -275835,7 +276071,7 @@ ${stack}` : ""}`);
275835
276071
  "legacy config.json": join36(home, ".memorix", "config.json")
275836
276072
  };
275837
276073
  for (const [key, fpath] of Object.entries(paths)) {
275838
- files[key] = { exists: existsSync36(fpath), path: fpath };
276074
+ files[key] = { exists: existsSync37(fpath), path: fpath };
275839
276075
  }
275840
276076
  } else {
275841
276077
  files["project memorix.yml"] = { exists: false, path: "unavailable", unavailable: true };
@@ -275846,7 +276082,7 @@ ${stack}` : ""}`);
275846
276082
  "legacy config.json": join36(home, ".memorix", "config.json")
275847
276083
  };
275848
276084
  for (const [key, fpath] of Object.entries(userPaths)) {
275849
- files[key] = { exists: existsSync36(fpath), path: fpath };
276085
+ files[key] = { exists: existsSync37(fpath), path: fpath };
275850
276086
  }
275851
276087
  }
275852
276088
  const values = [];
@@ -276475,7 +276711,7 @@ var init_status = __esm({
276475
276711
  const { getProjectDataDir: getProjectDataDir2 } = await Promise.resolve().then(() => (init_persistence(), persistence_exports));
276476
276712
  const { getEmbeddingProvider: getEmbeddingProvider2 } = await Promise.resolve().then(() => (init_provider(), provider_exports));
276477
276713
  const { getResolvedConfig: getResolvedConfig2, getResolvedAgentLane: getResolvedAgentLane2 } = await Promise.resolve().then(() => (init_resolved_config(), resolved_config_exports));
276478
- const { existsSync: existsSync36, readFileSync: readFileSync25 } = await import("fs");
276714
+ const { existsSync: existsSync37, readFileSync: readFileSync25 } = await import("fs");
276479
276715
  const project = detectProject2();
276480
276716
  if (!project) {
276481
276717
  const message = "Memorix requires a git repo to establish project identity. Run `git init` in this workspace first.";
@@ -276558,7 +276794,7 @@ var init_status = __esm({
276558
276794
  try {
276559
276795
  const { resolveHooksDir: resolveHooksDir2 } = await Promise.resolve().then(() => (init_hooks_path(), hooks_path_exports));
276560
276796
  const resolved2 = resolveHooksDir2(project.rootPath);
276561
- if (resolved2 && existsSync36(resolved2.hookPath)) {
276797
+ if (resolved2 && existsSync37(resolved2.hookPath)) {
276562
276798
  const hookContent = readFileSync25(resolved2.hookPath, "utf-8");
276563
276799
  if (hookContent.includes("# [memorix-git-hook]")) {
276564
276800
  diagLines.push(` Git hook: installed [OK]`);
@@ -282630,7 +282866,7 @@ var git_hook_install_exports = {};
282630
282866
  __export(git_hook_install_exports, {
282631
282867
  default: () => git_hook_install_default
282632
282868
  });
282633
- import { existsSync as existsSync28, readFileSync as readFileSync19, writeFileSync as writeFileSync7, chmodSync } from "fs";
282869
+ import { existsSync as existsSync29, readFileSync as readFileSync19, writeFileSync as writeFileSync7, chmodSync } from "fs";
282634
282870
  function generateHookScript() {
282635
282871
  return `${HOOK_MARKER}
282636
282872
  # Memorix: Auto-ingest git commits as memories
@@ -282677,7 +282913,7 @@ var init_git_hook_install = __esm({
282677
282913
  return;
282678
282914
  }
282679
282915
  const { hookPath } = resolved;
282680
- if (existsSync28(hookPath)) {
282916
+ if (existsSync29(hookPath)) {
282681
282917
  const existing = readFileSync19(hookPath, "utf-8");
282682
282918
  if (existing.includes(HOOK_MARKER)) {
282683
282919
  v3.warn("Memorix git hook is already installed.");
@@ -282727,7 +282963,7 @@ var git_hook_uninstall_exports = {};
282727
282963
  __export(git_hook_uninstall_exports, {
282728
282964
  default: () => git_hook_uninstall_default
282729
282965
  });
282730
- import { existsSync as existsSync29, readFileSync as readFileSync20, writeFileSync as writeFileSync8, unlinkSync as unlinkSync3 } from "fs";
282966
+ import { existsSync as existsSync30, readFileSync as readFileSync20, writeFileSync as writeFileSync8, unlinkSync as unlinkSync3 } from "fs";
282731
282967
  var HOOK_MARKER2, git_hook_uninstall_default;
282732
282968
  var init_git_hook_uninstall = __esm({
282733
282969
  "src/cli/commands/git-hook-uninstall.ts"() {
@@ -282759,7 +282995,7 @@ var init_git_hook_uninstall = __esm({
282759
282995
  return;
282760
282996
  }
282761
282997
  const { hookPath } = resolved;
282762
- if (!existsSync29(hookPath)) {
282998
+ if (!existsSync30(hookPath)) {
282763
282999
  v3.warn("No post-commit hook found.");
282764
283000
  fe2("Nothing to uninstall.");
282765
283001
  return;
@@ -283618,7 +283854,7 @@ __export(agent_integrations_exports, {
283618
283854
  repairAgentIntegrations: () => repairAgentIntegrations
283619
283855
  });
283620
283856
  import { spawnSync as spawnSync2 } from "child_process";
283621
- import { existsSync as existsSync31, realpathSync as realpathSync2 } from "fs";
283857
+ import { existsSync as existsSync32, realpathSync as realpathSync2 } from "fs";
283622
283858
  import { mkdir as mkdir9, readFile as readFile10, writeFile as writeFile10 } from "fs/promises";
283623
283859
  import { basename as basename5, dirname as dirname8, resolve as resolve7 } from "path";
283624
283860
  import { homedir as homedir36 } from "os";
@@ -283703,7 +283939,7 @@ function capabilityParity(agent, projectRoot, scope, mcp, guidance, plugin) {
283703
283939
  for (const artifactScope of artifactScopes) {
283704
283940
  const path50 = artifactScope === "project" ? getProjectConfigPath(agent, projectRoot) : getGlobalConfigPath(agent);
283705
283941
  if (!path50) continue;
283706
- const exists3 = existsSync31(path50);
283942
+ const exists3 = existsSync32(path50);
283707
283943
  artifactChecks.push({
283708
283944
  kind: "hooks",
283709
283945
  scope: artifactScope,
@@ -283831,7 +284067,7 @@ async function inspectCodexPluginBundle() {
283831
284067
  const manifestPath = `${pluginPath}/.codex-plugin/plugin.json`;
283832
284068
  const hooksPath = `${pluginPath}/hooks/hooks.json`;
283833
284069
  const mcpPath = codexPluginMcpPath();
283834
- if (!existsSync31(pluginPath)) {
284070
+ if (!existsSync32(pluginPath)) {
283835
284071
  return {
283836
284072
  scope: "global",
283837
284073
  kind: "bundle",
@@ -283841,7 +284077,7 @@ async function inspectCodexPluginBundle() {
283841
284077
  issues: ["codex-plugin-bundle-missing"]
283842
284078
  };
283843
284079
  }
283844
- if (!existsSync31(manifestPath)) {
284080
+ if (!existsSync32(manifestPath)) {
283845
284081
  return {
283846
284082
  scope: "global",
283847
284083
  kind: "bundle",
@@ -283878,7 +284114,7 @@ async function inspectCodexPluginBundle() {
283878
284114
  const issues = [];
283879
284115
  if (version2 !== getCliVersion()) issues.push("codex-plugin-version-mismatch");
283880
284116
  if (manifest.hooks !== "./hooks/hooks.json") issues.push("codex-hook-manifest-missing");
283881
- if (!existsSync31(mcpPath)) {
284117
+ if (!existsSync32(mcpPath)) {
283882
284118
  issues.push("codex-plugin-mcp-manifest-missing");
283883
284119
  } else {
283884
284120
  try {
@@ -283892,7 +284128,7 @@ async function inspectCodexPluginBundle() {
283892
284128
  }
283893
284129
  }
283894
284130
  let declared = [];
283895
- if (!existsSync31(hooksPath)) {
284131
+ if (!existsSync32(hooksPath)) {
283896
284132
  issues.push("codex-hook-manifest-missing");
283897
284133
  } else {
283898
284134
  try {
@@ -283919,7 +284155,7 @@ async function inspectCodexPluginBundle() {
283919
284155
  }
283920
284156
  async function inspectCodexMarketplace() {
283921
284157
  const marketplacePath = codexMarketplacePath();
283922
- if (!existsSync31(marketplacePath)) {
284158
+ if (!existsSync32(marketplacePath)) {
283923
284159
  return {
283924
284160
  scope: "global",
283925
284161
  kind: "marketplace",
@@ -284009,7 +284245,7 @@ function inspectCodexPluginRuntime() {
284009
284245
  }
284010
284246
  async function inspectCodexHookTrust() {
284011
284247
  const configPath = codexConfigPath();
284012
- if (!existsSync31(configPath)) {
284248
+ if (!existsSync32(configPath)) {
284013
284249
  return {
284014
284250
  scope: "global",
284015
284251
  kind: "hook-trust",
@@ -284110,7 +284346,7 @@ function defaultClaudeProjectKey(projectRoot) {
284110
284346
  }
284111
284347
  function canonicalProjectPath(projectRoot) {
284112
284348
  const resolved = resolve7(projectRoot);
284113
- const canonical = existsSync31(resolved) ? realpathSync2(resolved) : resolved;
284349
+ const canonical = existsSync32(resolved) ? realpathSync2(resolved) : resolved;
284114
284350
  return canonical.replace(/\\/g, "/");
284115
284351
  }
284116
284352
  function getClaudeLocalConfigPath() {
@@ -284142,7 +284378,7 @@ function findClaudeLocalProject(config2, projectRoot) {
284142
284378
  }
284143
284379
  async function inspectClaudeLocalMcp(projectRoot) {
284144
284380
  const configPath = getClaudeLocalConfigPath();
284145
- if (!existsSync31(configPath)) {
284381
+ if (!existsSync32(configPath)) {
284146
284382
  return {
284147
284383
  scope: "local",
284148
284384
  path: configPath,
@@ -284230,7 +284466,7 @@ async function inspectCodexPluginMcp() {
284230
284466
  const runtime = inspectCodexPluginRuntime();
284231
284467
  if (!runtime.runtime?.installed || !runtime.runtime.enabled) return null;
284232
284468
  const mcpPath = codexPluginMcpPath();
284233
- if (!existsSync31(mcpPath)) {
284469
+ if (!existsSync32(mcpPath)) {
284234
284470
  return {
284235
284471
  scope: "global",
284236
284472
  path: mcpPath,
@@ -284282,7 +284518,7 @@ async function inspectOptionalGrokMcp(scope) {
284282
284518
  }
284283
284519
  const adapter = getMcpAdapter("grok");
284284
284520
  const configPath = adapter.getConfigPath();
284285
- if (!existsSync31(configPath)) {
284521
+ if (!existsSync32(configPath)) {
284286
284522
  return {
284287
284523
  status: "skipped",
284288
284524
  issues: ["mcp-host-owned"],
@@ -284349,7 +284585,7 @@ async function inspectMcp(agent, projectRoot, scope) {
284349
284585
  if (targetScope === "global" && configPath === adapter.getConfigPath(projectRoot) && scope === "all") {
284350
284586
  continue;
284351
284587
  }
284352
- if (!existsSync31(configPath)) {
284588
+ if (!existsSync32(configPath)) {
284353
284589
  checks.push({
284354
284590
  scope: targetScope,
284355
284591
  path: configPath,
@@ -284426,7 +284662,7 @@ async function inspectGuidance(agent, projectRoot, scope) {
284426
284662
  for (const targetScope of requestedGuidanceScopes(scope)) {
284427
284663
  const root = targetScope === "project" ? projectRoot : homedir36();
284428
284664
  const rulesPath = getAgentRulesPath(agent, root, targetScope === "global");
284429
- if (!existsSync31(rulesPath)) {
284665
+ if (!existsSync32(rulesPath)) {
284430
284666
  checks.push({
284431
284667
  scope: targetScope,
284432
284668
  path: rulesPath,
@@ -284713,7 +284949,7 @@ var init_doctor = __esm({
284713
284949
  }
284714
284950
  return;
284715
284951
  }
284716
- const { existsSync: existsSync36, readFileSync: readFileSync25 } = await import("fs");
284952
+ const { existsSync: existsSync37, readFileSync: readFileSync25 } = await import("fs");
284717
284953
  const { join: join36, basename: basename7 } = await import("path");
284718
284954
  const { homedir: homedir38 } = await import("os");
284719
284955
  const { execSync: execSync5 } = await import("child_process");
@@ -284784,7 +285020,7 @@ var init_doctor = __esm({
284784
285020
  let bgPid = 0;
284785
285021
  let backgroundHealthy = false;
284786
285022
  try {
284787
- if (existsSync36(bgStatePath)) {
285023
+ if (existsSync37(bgStatePath)) {
284788
285024
  const bgState = JSON.parse(readFileSync25(bgStatePath, "utf-8"));
284789
285025
  bgPid = bgState.pid;
284790
285026
  bgPort = bgState.port;
@@ -284899,7 +285135,7 @@ var init_doctor = __esm({
284899
285135
  }
284900
285136
  try {
284901
285137
  const cachePath = join36(memorixDir, "embedding-cache.json");
284902
- if (existsSync36(cachePath)) {
285138
+ if (existsSync37(cachePath)) {
284903
285139
  const cache5 = JSON.parse(readFileSync25(cachePath, "utf-8"));
284904
285140
  const cacheCount = Object.keys(cache5).length;
284905
285141
  lines.push(info2(`Cached embeddings: ${cacheCount}`));
@@ -284914,7 +285150,7 @@ var init_doctor = __esm({
284914
285150
  }
284915
285151
  lines.push("");
284916
285152
  lines.push("\u250C\u2500 Data Status \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
284917
- if (dataDir && existsSync36(dataDir)) {
285153
+ if (dataDir && existsSync37(dataDir)) {
284918
285154
  let obsCount = 0;
284919
285155
  let activeCount = 0;
284920
285156
  let ranCount = 0;
@@ -285153,7 +285389,7 @@ var init_doctor = __esm({
285153
285389
  let conflictsFound = false;
285154
285390
  if (dataDir) {
285155
285391
  const lockFile = join36(dataDir, ".memorix.lock");
285156
- if (existsSync36(lockFile)) {
285392
+ if (existsSync37(lockFile)) {
285157
285393
  try {
285158
285394
  const lockData = JSON.parse(readFileSync25(lockFile, "utf-8"));
285159
285395
  const lockAge = Date.now() - lockData.time;
@@ -285287,7 +285523,7 @@ var init_repair3 = __esm({
285287
285523
  repair_default = defineCommand({
285288
285524
  meta: {
285289
285525
  name: "repair",
285290
- description: "Repair Memorix-owned agent integration files"
285526
+ description: "Repair agent integrations or compact the semantic index"
285291
285527
  },
285292
285528
  args: {
285293
285529
  agent: {
@@ -285312,8 +285548,21 @@ var init_repair3 = __esm({
285312
285548
  run: async ({ args }) => {
285313
285549
  const positional = args._ ?? [];
285314
285550
  const action = positional[0] || "agents";
285551
+ if (action === "index") {
285552
+ if (args.dry) throw new Error("`memorix repair index` does not support --dry");
285553
+ const { detectProject: detectProject2 } = await Promise.resolve().then(() => (init_detector(), detector_exports));
285554
+ const { getProjectDataDir: getProjectDataDir2 } = await Promise.resolve().then(() => (init_persistence(), persistence_exports));
285555
+ const { optimizeSemanticIndexes: optimizeSemanticIndexes2 } = await Promise.resolve().then(() => (init_semantic_index(), semantic_index_exports));
285556
+ const project = detectProject2(process.cwd());
285557
+ if (!project) throw new Error("Run `memorix repair index` inside a Git project");
285558
+ const dataDir = await getProjectDataDir2(project.id);
285559
+ const tables = await optimizeSemanticIndexes2(dataDir);
285560
+ if (args.json) console.log(JSON.stringify({ dataDir, optimizedTables: tables }, null, 2));
285561
+ else console.log(`Optimized ${tables.length} semantic table(s) in ${dataDir}`);
285562
+ return;
285563
+ }
285315
285564
  if (action !== "agents") {
285316
- const message = "Usage: memorix repair agents [--agent <agent>] [--scope local|project|global|all] [--dry]";
285565
+ const message = "Usage: memorix repair agents [--agent <agent>] [--scope local|project|global|all] [--dry] | memorix repair index [--json]";
285317
285566
  if (args.json) {
285318
285567
  console.log(JSON.stringify({ error: message }, null, 2));
285319
285568
  } else {
@@ -287380,7 +287629,7 @@ var init_pipeline_trace = __esm({
287380
287629
 
287381
287630
  // src/orchestrate/worktree.ts
287382
287631
  import { execFileSync as execFileSync5 } from "child_process";
287383
- import { existsSync as existsSync33, rmSync as rmSync2 } from "fs";
287632
+ import { existsSync as existsSync34, rmSync as rmSync2 } from "fs";
287384
287633
  import { join as join34, basename as basename6 } from "path";
287385
287634
  function runGit4(cwd, args, timeout = 5e3) {
287386
287635
  return String(execFileSync5("git", args, {
@@ -287426,7 +287675,7 @@ function createWorktree(projectDir2, taskId, pipelineId) {
287426
287675
  const suffix = attempt === 1 ? "" : `-${attempt}`;
287427
287676
  const worktreePath = `${worktreeBase}${suffix}`;
287428
287677
  const branch = `${branchBase}${suffix}`;
287429
- if (existsSync33(worktreePath)) continue;
287678
+ if (existsSync34(worktreePath)) continue;
287430
287679
  if (!isBranchAvailable(projectDir2, branch)) continue;
287431
287680
  runGit4(projectDir2, ["worktree", "add", "-b", branch, worktreePath], 3e4);
287432
287681
  return { worktreePath, branch };
@@ -287477,7 +287726,7 @@ function removeWorktree(projectDir2, worktreePath, branch) {
287477
287726
  try {
287478
287727
  runGit4(projectDir2, ["worktree", "remove", worktreePath, "--force"], 1e4);
287479
287728
  } catch {
287480
- if (existsSync33(worktreePath)) {
287729
+ if (existsSync34(worktreePath)) {
287481
287730
  try {
287482
287731
  rmSync2(worktreePath, { recursive: true, force: true });
287483
287732
  } catch {
@@ -293619,10 +293868,10 @@ function WorkbenchApp({ version: version2, onExitForInteractive }) {
293619
293868
  }
293620
293869
  try {
293621
293870
  const { resolveHooksDir: resolveHooksDir2 } = await Promise.resolve().then(() => (init_hooks_path(), hooks_path_exports));
293622
- const { existsSync: existsSync36, readFileSync: readFileSync25, writeFileSync: writeFileSync13, unlinkSync: unlinkSync5 } = await import("fs");
293871
+ const { existsSync: existsSync37, readFileSync: readFileSync25, writeFileSync: writeFileSync13, unlinkSync: unlinkSync5 } = await import("fs");
293623
293872
  const resolved = resolveHooksDir2(proj.rootPath);
293624
293873
  const hookMarker = "# [memorix-git-hook]";
293625
- if (!resolved || !existsSync36(resolved.hookPath)) {
293874
+ if (!resolved || !existsSync37(resolved.hookPath)) {
293626
293875
  setActionStatus("No post-commit hook found.");
293627
293876
  return;
293628
293877
  }
@@ -293777,7 +294026,7 @@ function WorkbenchApp({ version: version2, onExitForInteractive }) {
293777
294026
  break;
293778
294027
  }
293779
294028
  case "3": {
293780
- const { existsSync: existsSync36, readFileSync: readFileSync25, writeFileSync: writeFileSync13, chmodSync: chmodSync2 } = await import("fs");
294029
+ const { existsSync: existsSync37, readFileSync: readFileSync25, writeFileSync: writeFileSync13, chmodSync: chmodSync2 } = await import("fs");
293781
294030
  const { ensureHooksDir: ensureHooksDir2 } = await Promise.resolve().then(() => (init_hooks_path(), hooks_path_exports));
293782
294031
  const hookMarker = "# [memorix-git-hook]";
293783
294032
  const resolved = ensureHooksDir2(cwd);
@@ -293791,7 +294040,7 @@ if command -v memorix >/dev/null 2>&1; then
293791
294040
  memorix ingest commit --auto >/dev/null 2>&1 &
293792
294041
  fi
293793
294042
  `;
293794
- if (existsSync36(resolved.hookPath)) {
294043
+ if (existsSync37(resolved.hookPath)) {
293795
294044
  if (readFileSync25(resolved.hookPath, "utf-8").includes(hookMarker)) {
293796
294045
  setActionStatus("Post-commit hook already installed.");
293797
294046
  break;
@@ -293811,11 +294060,11 @@ ${hookScript}`, "utf-8");
293811
294060
  break;
293812
294061
  }
293813
294062
  case "4": {
293814
- const { existsSync: existsSync36, readFileSync: readFileSync25, writeFileSync: writeFileSync13, unlinkSync: unlinkSync5 } = await import("fs");
294063
+ const { existsSync: existsSync37, readFileSync: readFileSync25, writeFileSync: writeFileSync13, unlinkSync: unlinkSync5 } = await import("fs");
293815
294064
  const { resolveHooksDir: resolveHooksDir2 } = await Promise.resolve().then(() => (init_hooks_path(), hooks_path_exports));
293816
294065
  const hookMarker = "# [memorix-git-hook]";
293817
294066
  const resolved = resolveHooksDir2(cwd);
293818
- if (!resolved || !existsSync36(resolved.hookPath)) {
294067
+ if (!resolved || !existsSync37(resolved.hookPath)) {
293819
294068
  setActionStatus("No post-commit hook found.");
293820
294069
  break;
293821
294070
  }