engine7 7.1.144 → 7.1.146

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.
@@ -873,15 +873,15 @@ var init_sqlite_replication = __esm({
873
873
  requireForeignKeys(this.db);
874
874
  if (captureGuardHash(this.db) !== this.guardHash) throw new Error("REPLICATION_GUARD_MISMATCH");
875
875
  if (sqliteReplicationSchemaHash(this.db) !== this.schemaHash) throw new Error("REPLICATION_SCHEMA_MISMATCH");
876
- const before = sequences(this.db, this.excludedTables), sessions = [];
876
+ const before = sequences(this.db, this.excludedTables), sessions2 = [];
877
877
  try {
878
- if (this.sessionTables) for (const table of this.sessionTables) sessions.push(this.db.createSession({ table }));
879
- else sessions.push(this.db.createSession());
878
+ if (this.sessionTables) for (const table of this.sessionTables) sessions2.push(this.db.createSession({ table }));
879
+ else sessions2.push(this.db.createSession());
880
880
  } catch (error) {
881
- for (const session of sessions) session.close();
881
+ for (const session of sessions2) session.close();
882
882
  throw error;
883
883
  }
884
- this.active = { sessions, sequences: before, closed: false };
884
+ this.active = { sessions: sessions2, sequences: before, closed: false };
885
885
  return this.active;
886
886
  }
887
887
  appendCapture(capture2) {
@@ -1148,31 +1148,31 @@ var init_sqlite_replication = __esm({
1148
1148
  // src/continuity/runtime-replication.ts
1149
1149
  import { constants as constants9, lstatSync as lstatSync7, realpathSync as realpathSync3, mkdirSync as mkdirSync5, openSync as openSync8, closeSync as closeSync7, fstatSync as fstatSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync4, fsyncSync as fsyncSync6 } from "node:fs";
1150
1150
  import { basename as basename3, dirname as dirname6, join as join11, resolve as resolve7 } from "node:path";
1151
- function checkKey(component, key2) {
1152
- if (component === "topics-vectors" && typeof key2 === "string" && /^[a-f0-9]{64}$/.test(key2)) return;
1153
- if (component === "legacy-memory" && typeof key2 === "string" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/.test(key2) && !/[. ]$/.test(key2) && !/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/i.test(key2)) return;
1154
- if (["calendar", "proactive", "session-events"].includes(component) && key2 === void 0) return;
1151
+ function checkKey(component, key3) {
1152
+ if (component === "topics-vectors" && typeof key3 === "string" && /^[a-f0-9]{64}$/.test(key3)) return;
1153
+ if (component === "legacy-memory" && typeof key3 === "string" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/.test(key3) && !/[. ]$/.test(key3) && !/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/i.test(key3)) return;
1154
+ if (["calendar", "proactive", "session-events"].includes(component) && key3 === void 0) return;
1155
1155
  throw new Error("REPLICATION_REGISTRATION_INVALID");
1156
1156
  }
1157
- function location2(stateDir, component, key2) {
1158
- checkKey(component, key2);
1159
- return join11(stateDir, ".continuity", component + (key2 === void 0 ? "" : "-" + key2) + "-replication.json");
1157
+ function location2(stateDir, component, key3) {
1158
+ checkKey(component, key3);
1159
+ return join11(stateDir, ".continuity", component + (key3 === void 0 ? "" : "-" + key3) + "-replication.json");
1160
1160
  }
1161
- function runtimeReplicationFile(stateDir, component, key2) {
1162
- checkKey(component, key2);
1163
- if (component === "legacy-memory") return join11(stateDir, "agents", key2, "memory", "memory.db");
1164
- if (component === "topics-vectors") return join11(stateDir, "topics-history", key2, "vectors.db");
1161
+ function runtimeReplicationFile(stateDir, component, key3) {
1162
+ checkKey(component, key3);
1163
+ if (component === "legacy-memory") return join11(stateDir, "agents", key3, "memory", "memory.db");
1164
+ if (component === "topics-vectors") return join11(stateDir, "topics-history", key3, "vectors.db");
1165
1165
  if (component === "session-events") return join11(stateDir, ".continuity", "session-events.db");
1166
1166
  return join11(stateDir, "." + component, component + ".db");
1167
1167
  }
1168
1168
  function runtimeReplicationLocation(stateDir, component, file) {
1169
- const key2 = component === "legacy-memory" ? basename3(dirname6(dirname6(file))) : component === "topics-vectors" ? basename3(dirname6(file)) : void 0;
1169
+ const key3 = component === "legacy-memory" ? basename3(dirname6(dirname6(file))) : component === "topics-vectors" ? basename3(dirname6(file)) : void 0;
1170
1170
  try {
1171
- if (resolve7(file) !== resolve7(runtimeReplicationFile(stateDir, component, key2))) throw new Error();
1171
+ if (resolve7(file) !== resolve7(runtimeReplicationFile(stateDir, component, key3))) throw new Error();
1172
1172
  } catch (error) {
1173
1173
  throw new Error("REPLICATION_RUNTIME_PATH_UNSUPPORTED", { cause: error });
1174
1174
  }
1175
- return { component, ...key2 === void 0 ? {} : { key: key2 } };
1175
+ return { component, ...key3 === void 0 ? {} : { key: key3 } };
1176
1176
  }
1177
1177
  function normalize3(input) {
1178
1178
  if (!input || !/^[a-f0-9]{64}$/.test(input.schemaHash)) throw new Error("REPLICATION_REGISTRATION_INVALID");
@@ -1183,8 +1183,8 @@ function directory(path2) {
1183
1183
  if (!info.isDirectory() || info.isSymbolicLink() || realpathSync3(path2) !== resolve7(path2) || process.platform !== "win32" && (info.mode & 63 || info.uid !== process.getuid()))
1184
1184
  throw new Error("REPLICATION_REGISTRATION_INVALID");
1185
1185
  }
1186
- function readRuntimeReplicationRegistration(stateDir, component, key2) {
1187
- const file = location2(stateDir, component, key2);
1186
+ function readRuntimeReplicationRegistration(stateDir, component, key3) {
1187
+ const file = location2(stateDir, component, key3);
1188
1188
  try {
1189
1189
  lstatSync7(dirname6(file));
1190
1190
  } catch (error) {
@@ -1247,8 +1247,8 @@ function checkRuntimeReplicationDatabase(db, registration, component, version, r
1247
1247
  }
1248
1248
  return requested ?? registration?.binding;
1249
1249
  }
1250
- function enrollRuntimeReplication(db, stateDir, component, binding, key2) {
1251
- const file = location2(stateDir, component, key2), old = readRuntimeReplicationRegistration(stateDir, component, key2);
1250
+ function enrollRuntimeReplication(db, stateDir, component, binding, key3) {
1251
+ const file = location2(stateDir, component, key3), old = readRuntimeReplicationRegistration(stateDir, component, key3);
1252
1252
  const version = readSchemaVersion(db);
1253
1253
  if (version?.component !== component) throw new Error("REPLICATION_SCHEMA_MISMATCH");
1254
1254
  checkRuntimeReplicationDatabase(db, old, component, version.version, binding);
@@ -1261,7 +1261,7 @@ function enrollRuntimeReplication(db, stateDir, component, binding, key2) {
1261
1261
  writeFileSync4(file, JSON.stringify(input), { mode: 384, flag: "wx", flush: true });
1262
1262
  } catch (error) {
1263
1263
  if (error.code !== "EEXIST") throw error;
1264
- if (JSON.stringify(readRuntimeReplicationRegistration(stateDir, component, key2)) !== JSON.stringify(input)) throw new Error("REPLICATION_REGISTRATION_MISMATCH");
1264
+ if (JSON.stringify(readRuntimeReplicationRegistration(stateDir, component, key3)) !== JSON.stringify(input)) throw new Error("REPLICATION_REGISTRATION_MISMATCH");
1265
1265
  }
1266
1266
  if (process.platform !== "win32") {
1267
1267
  const fd = openSync8(dirname6(file), "r");
@@ -1452,10 +1452,10 @@ var init_live = __esm({
1452
1452
  /** 安全取子段('services.voice-chat.start' → current.services.voice-chat.start) */
1453
1453
  get(dotPath) {
1454
1454
  if (!this.current) return void 0;
1455
- return dotPath.split(".").reduce((acc, key2) => {
1455
+ return dotPath.split(".").reduce((acc, key3) => {
1456
1456
  if (acc == null) return void 0;
1457
- if (key2 === "__proto__" || key2 === "constructor" || key2 === "prototype") return void 0;
1458
- return acc[key2];
1457
+ if (key3 === "__proto__" || key3 === "constructor" || key3 === "prototype") return void 0;
1458
+ return acc[key3];
1459
1459
  }, this.current);
1460
1460
  }
1461
1461
  /** reload 时原地更新(Object.assign 保持引用不变)
@@ -1806,9 +1806,9 @@ async function collectInventory(options2) {
1806
1806
  continue;
1807
1807
  }
1808
1808
  validateRelativePath(path2);
1809
- const key2 = root + "/" + path2.normalize("NFC").toLowerCase();
1810
- if (aliases.has(key2)) throw new Error("PORTABLE_PATH_COLLISION");
1811
- aliases.add(key2);
1809
+ const key3 = root + "/" + path2.normalize("NFC").toLowerCase();
1810
+ if (aliases.has(key3)) throw new Error("PORTABLE_PATH_COLLISION");
1811
+ aliases.add(key3);
1812
1812
  let info = await lstat2(source, { bigint: true }), linkSignature = "";
1813
1813
  if (options2.selection === "core" && root === "workspace" && !prefix && !CORE_DIRECTORIES.has(name) && (info.isDirectory() || info.isSymbolicLink() && !/\.[a-z0-9]+$/i.test(name))) {
1814
1814
  exclusions.push({ root, path: path2, reason: "optional workspace material; outside core travel" });
@@ -3007,7 +3007,7 @@ function canonical(value) {
3007
3007
  if (typeof value === "number" && Number.isFinite(value)) return value;
3008
3008
  if (Array.isArray(value)) return value.map(canonical);
3009
3009
  if (value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype)
3010
- return Object.fromEntries(Object.keys(value).sort().map((key2) => [key2, canonical(value[key2])]));
3010
+ return Object.fromEntries(Object.keys(value).sort().map((key3) => [key3, canonical(value[key3])]));
3011
3011
  throw new Error("TREE_SOURCE_INVALID_ORIGIN");
3012
3012
  }
3013
3013
  var sha2 = (body) => createHash4("sha256").update(body).digest("hex");
@@ -3398,7 +3398,7 @@ import { existsSync as existsSync3, readFileSync as readFileSync5, renameSync as
3398
3398
  function canonicalJson(value) {
3399
3399
  const normalize4 = (input) => {
3400
3400
  if (Array.isArray(input)) return input.map(normalize4);
3401
- if (input && typeof input === "object") return Object.fromEntries(Object.entries(input).filter(([, entry]) => entry !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key2, entry]) => [key2, normalize4(entry)]));
3401
+ if (input && typeof input === "object") return Object.fromEntries(Object.entries(input).filter(([, entry]) => entry !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key3, entry]) => [key3, normalize4(entry)]));
3402
3402
  return input;
3403
3403
  };
3404
3404
  const json = JSON.stringify(normalize4(value));
@@ -3447,9 +3447,9 @@ function invalidateChildren(db, scope, pending, reason) {
3447
3447
  let referencedPlan;
3448
3448
  while (pending.length) {
3449
3449
  const child = pending.shift();
3450
- const key2 = JSON.stringify([child.child_kind, child.child_id]);
3451
- if (visited.has(key2) && (visited.get(key2) || !child.deleted)) continue;
3452
- visited.set(key2, Boolean(child.deleted));
3450
+ const key3 = JSON.stringify([child.child_kind, child.child_id]);
3451
+ if (visited.has(key3) && (visited.get(key3) || !child.deleted)) continue;
3452
+ visited.set(key3, Boolean(child.deleted));
3453
3453
  if (child.child_kind === "graph_plan") {
3454
3454
  referencedPlan ??= db.prepare(`SELECT 1 WHERE EXISTS (SELECT 1 FROM memory_dependencies
3455
3455
  WHERE scope_id=? AND parent_kind='artifact' AND parent_id=?)
@@ -3593,8 +3593,8 @@ var ChangeFeed = class _ChangeFeed {
3593
3593
  * 事件重放失败一次即回死信+skip,不重烧 5 轮预算)。先 UPDATE 后记账:中间崩溃只会
3594
3594
  * 多治一次(幂等无害),反过来会出现"记了账但没治"的永久死锁。 */
3595
3595
  reenqueueGapPrefix(sinkId, head, now2 = Date.now()) {
3596
- const key2 = `${sinkId}:${head.scopeId}:${head.eventSeq}`;
3597
- if (this.healedGaps.has(key2)) return;
3596
+ const key3 = `${sinkId}:${head.scopeId}:${head.eventSeq}`;
3597
+ if (this.healedGaps.has(key3)) return;
3598
3598
  const ledgerPath = this.gapHealLedgerPath;
3599
3599
  let ledger = {};
3600
3600
  if (ledgerPath) {
@@ -3602,8 +3602,8 @@ var ChangeFeed = class _ChangeFeed {
3602
3602
  ledger = JSON.parse(readFileSync5(ledgerPath, "utf8"))?.heals ?? {};
3603
3603
  } catch {
3604
3604
  }
3605
- if (Number.isFinite(ledger[key2])) {
3606
- this.healedGaps.add(key2);
3605
+ if (Number.isFinite(ledger[key3])) {
3606
+ this.healedGaps.add(key3);
3607
3607
  return;
3608
3608
  }
3609
3609
  }
@@ -3617,11 +3617,11 @@ var ChangeFeed = class _ChangeFeed {
3617
3617
  const count = Number(result?.changes ?? 0);
3618
3618
  if (count > 0) console.warn(`[mem7] \u5E8F\u5217\u7F3A\u53E3\u81EA\u6108\uFF1Ahead seq=${head.eventSeq} \u524D ${count} \u6761\u5DF2 ack \u6295\u9012\u884C\u91CD\u7F6E\u5F85\u6295\uFF08\u65B0\u56FE\u5982\u5B9E\u91CD\u653E / \u65E7\u56FE\u5E42\u7B49 duplicate-ack\uFF1B\u6B7B\u4FE1\u884C\u4FDD\u7559 attempts\uFF09`);
3619
3619
  });
3620
- this.healedGaps.add(key2);
3620
+ this.healedGaps.add(key3);
3621
3621
  if (!ledgerPath) return;
3622
3622
  const cutoff = now2 - _ChangeFeed.GAP_HEAL_RETENTION_MS, retained = {};
3623
3623
  for (const [entry, at] of Object.entries(ledger)) if (Number.isFinite(at) && at >= cutoff) retained[entry] = at;
3624
- retained[key2] = now2;
3624
+ retained[key3] = now2;
3625
3625
  const temp = `${ledgerPath}.${randomUUID7()}.tmp`;
3626
3626
  try {
3627
3627
  writeFileSync5(temp, JSON.stringify({ version: 1, heals: retained }));
@@ -3852,6 +3852,15 @@ init_clock();
3852
3852
  init_read_guard();
3853
3853
  init_timing();
3854
3854
  init_runtime_authority();
3855
+
3856
+ // src/mem7/core/lance-cache.ts
3857
+ var LANCE_INDEX_CACHE_BYTES = 256 * 1024 * 1024;
3858
+ var LANCE_METADATA_CACHE_BYTES = 64 * 1024 * 1024;
3859
+ var key = Symbol.for("engine7.mem7.lanceCacheSessions");
3860
+ var globals = globalThis;
3861
+ var sessions = globals[key] ??= /* @__PURE__ */ new WeakMap();
3862
+
3863
+ // src/mem7/core/vector-store.ts
3855
3864
  var isIntelMac = process.platform === "darwin" && process.arch === "x64";
3856
3865
  function lanceSpecifierFor(platform, arch) {
3857
3866
  return platform === "darwin" && arch === "x64" ? "@engine7/lancedb-intel" : "@lancedb/lancedb";
@@ -4844,12 +4853,12 @@ var incarnation2 = (file) => {
4844
4853
  return `${s.dev}:${s.ino}`;
4845
4854
  };
4846
4855
  function validateRecoveryArchiveEntry(entry, identity) {
4847
- if (!entry || Object.keys(entry).some((key2) => !["format", "id", "kind", "manifest", "databases", "publication", "receipt"].includes(key2)) || entry.format !== FORMAT || !ID2.test(entry.id) || !["COMMON", "LOCAL", "REMOTE"].includes(entry.kind)) throw new Error("RECOVERY_ARCHIVE_CORRUPT");
4856
+ if (!entry || Object.keys(entry).some((key3) => !["format", "id", "kind", "manifest", "databases", "publication", "receipt"].includes(key3)) || entry.format !== FORMAT || !ID2.test(entry.id) || !["COMMON", "LOCAL", "REMOTE"].includes(entry.kind)) throw new Error("RECOVERY_ARCHIVE_CORRUPT");
4848
4857
  const manifest = normalizePublication(entry.manifest), manifestDigest = publicationDigest(manifest);
4849
4858
  if (!same3(manifest.profile.identity, identity)) throw new Error("RECOVERY_IDENTITY_MISMATCH");
4850
4859
  if (!Array.isArray(entry.databases) || !same3(entry.databases.map((db) => db.databaseId), manifest.profile.databaseIds)) throw new Error("RECOVERY_INCOMPLETE_DATABASES");
4851
4860
  for (const db of entry.databases) {
4852
- if (Object.keys(db).some((key2) => !["databaseId", "role", "schemaHash", "content"].includes(key2)) || db.role !== (entry.kind === "LOCAL" ? "source" : "replica") || !/^[a-f0-9]{64}$/.test(db.schemaHash)) throw new Error("RECOVERY_ARCHIVE_CORRUPT");
4861
+ if (Object.keys(db).some((key3) => !["databaseId", "role", "schemaHash", "content"].includes(key3)) || db.role !== (entry.kind === "LOCAL" ? "source" : "replica") || !/^[a-f0-9]{64}$/.test(db.schemaHash)) throw new Error("RECOVERY_ARCHIVE_CORRUPT");
4853
4862
  validateFileContent(db.content);
4854
4863
  }
4855
4864
  const publication = { state: "PUBLISHED", sequence: manifest.sequence, digest: manifestDigest, deletionWatermark: manifest.deletionWatermark, activationAllowed: false };
@@ -5265,11 +5274,11 @@ var EVENT_BYTES = 16 * 1024 * 1024;
5265
5274
  function sessionLimits(options2) {
5266
5275
  if (!options2 || typeof options2 !== "object" || Array.isArray(options2)) throw new Error("REPLICATION_INVALID_LIMIT");
5267
5276
  const limits2 = {};
5268
- for (const key2 of ["maximumPendingBytes", "maximumCommitBytes"]) {
5269
- const value = options2[key2];
5277
+ for (const key3 of ["maximumPendingBytes", "maximumCommitBytes"]) {
5278
+ const value = options2[key3];
5270
5279
  if (value !== void 0) {
5271
5280
  if (!Number.isSafeInteger(value) || value < 1 || value > 256 * 1024 * 1024) throw new Error("REPLICATION_INVALID_LIMIT");
5272
- limits2[key2] = value;
5281
+ limits2[key3] = value;
5273
5282
  }
5274
5283
  }
5275
5284
  return limits2;
@@ -5352,16 +5361,16 @@ function* frames(bytes, kind) {
5352
5361
  }
5353
5362
  if (offset !== bytes.length) throw new Error("SESSION_EVENT_TORN_BASELINE");
5354
5363
  }
5355
- function rememberEvent(db, key2, body, kind) {
5364
+ function rememberEvent(db, key3, body, kind) {
5356
5365
  const id2 = eventId(body, kind), digest3 = sha5(body);
5357
- const old = db.prepare("SELECT sequence,digest,body FROM session_events WHERE session_key=? AND event_id=?").get(key2, id2);
5366
+ const old = db.prepare("SELECT sequence,digest,body FROM session_events WHERE session_key=? AND event_id=?").get(key3, id2);
5358
5367
  if (old) {
5359
5368
  if (old.digest !== digest3 || !(old.body instanceof Uint8Array) || !body.equals(Buffer.from(old.body))) throw new Error("SESSION_EVENT_ID_CONFLICT");
5360
5369
  return Number(old.sequence);
5361
5370
  }
5362
5371
  const sequence = Number(db.prepare("SELECT COALESCE(max(sequence),0)+1 n FROM session_events").get().n);
5363
5372
  if (!Number.isSafeInteger(sequence) || sequence < 1) throw new Error("SESSION_EVENT_SEQUENCE_EXHAUSTED");
5364
- db.prepare("INSERT INTO session_events VALUES(?,?,?,?,?)").run(sequence, key2, id2, body, digest3);
5373
+ db.prepare("INSERT INTO session_events VALUES(?,?,?,?,?)").run(sequence, key3, id2, body, digest3);
5365
5374
  return sequence;
5366
5375
  }
5367
5376
  function nextRevision(db) {
@@ -5761,8 +5770,8 @@ async function prepareInitialRuntimeBaseline(options2) {
5761
5770
  writeFileSync10(file, JSON.stringify(index), { mode: 384 });
5762
5771
  }
5763
5772
  const baselineId = "initial-" + candidate.captureId, binding = (databaseId) => ({ ...options2.identity, databaseId, baselineId, epoch: 1 });
5764
- const sessions = await enrollSessionEvents(sourceStateDir, binding("sessions"));
5765
- sessions.close();
5773
+ const sessions2 = await enrollSessionEvents(sourceStateDir, binding("sessions"));
5774
+ sessions2.close();
5766
5775
  const inventory2 = await collectInventory({ stateDir: sourceStateDir, workspace: sourceWorkspace, selection, includeStateEntries: classification.unclassified });
5767
5776
  const known = inventory2.entries.filter((entry) => entry.kind === "sqlite" && sqliteStoreLocation(entry.source)).filter((entry) => {
5768
5777
  const place = sqliteStoreLocation(entry.source);
@@ -5946,9 +5955,9 @@ function publicPairingError(error) {
5946
5955
  var args = process.argv.slice(2);
5947
5956
  if (args.length !== 2 || args[0] !== "--config") throw Error("TRAVEL_INITIAL_BASELINE_CONFIG");
5948
5957
  var options = JSON.parse(readPrivateFile(resolve17(args[1]), 4 * 1024 * 1024).toString());
5949
- var key = readPrivateFile(options.keyFile, 32);
5958
+ var key2 = readPrivateFile(options.keyFile, 32);
5950
5959
  try {
5951
- const baseline = await prepareInitialRuntimeBaseline({ ...options, key, onProgress: (progress) => process.send?.({ type: "progress", progress }) });
5960
+ const baseline = await prepareInitialRuntimeBaseline({ ...options, key: key2, onProgress: (progress) => process.send?.({ type: "progress", progress }) });
5952
5961
  await baseline.close();
5953
5962
  process.stdout.write('{"ready":true}\n');
5954
5963
  } catch (error) {
@@ -5957,5 +5966,5 @@ try {
5957
5966
  process.stderr.write(reason + "\n");
5958
5967
  process.exitCode = 1;
5959
5968
  } finally {
5960
- key.fill(0);
5969
+ key2.fill(0);
5961
5970
  }
@@ -633,15 +633,15 @@ var init_sqlite_replication = __esm({
633
633
  requireForeignKeys(this.db);
634
634
  if (captureGuardHash(this.db) !== this.guardHash) throw new Error("REPLICATION_GUARD_MISMATCH");
635
635
  if (sqliteReplicationSchemaHash(this.db) !== this.schemaHash) throw new Error("REPLICATION_SCHEMA_MISMATCH");
636
- const before = sequences(this.db, this.excludedTables), sessions = [];
636
+ const before = sequences(this.db, this.excludedTables), sessions2 = [];
637
637
  try {
638
- if (this.sessionTables) for (const table of this.sessionTables) sessions.push(this.db.createSession({ table }));
639
- else sessions.push(this.db.createSession());
638
+ if (this.sessionTables) for (const table of this.sessionTables) sessions2.push(this.db.createSession({ table }));
639
+ else sessions2.push(this.db.createSession());
640
640
  } catch (error) {
641
- for (const session of sessions) session.close();
641
+ for (const session of sessions2) session.close();
642
642
  throw error;
643
643
  }
644
- this.active = { sessions, sequences: before, closed: false };
644
+ this.active = { sessions: sessions2, sequences: before, closed: false };
645
645
  return this.active;
646
646
  }
647
647
  appendCapture(capture2) {
@@ -746,31 +746,31 @@ var init_sqlite_replication = __esm({
746
746
  // src/continuity/runtime-replication.ts
747
747
  import { constants as constants6, lstatSync as lstatSync5, realpathSync as realpathSync2, mkdirSync as mkdirSync4, openSync as openSync6, closeSync as closeSync6, fstatSync as fstatSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync4, fsyncSync as fsyncSync6 } from "node:fs";
748
748
  import { basename as basename2, dirname as dirname4, join as join6, resolve as resolve5 } from "node:path";
749
- function checkKey(component, key) {
750
- if (component === "topics-vectors" && typeof key === "string" && /^[a-f0-9]{64}$/.test(key)) return;
751
- if (component === "legacy-memory" && typeof key === "string" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/.test(key) && !/[. ]$/.test(key) && !/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/i.test(key)) return;
752
- if (["calendar", "proactive", "session-events"].includes(component) && key === void 0) return;
749
+ function checkKey(component, key2) {
750
+ if (component === "topics-vectors" && typeof key2 === "string" && /^[a-f0-9]{64}$/.test(key2)) return;
751
+ if (component === "legacy-memory" && typeof key2 === "string" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/.test(key2) && !/[. ]$/.test(key2) && !/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/i.test(key2)) return;
752
+ if (["calendar", "proactive", "session-events"].includes(component) && key2 === void 0) return;
753
753
  throw new Error("REPLICATION_REGISTRATION_INVALID");
754
754
  }
755
- function location2(stateDir, component, key) {
756
- checkKey(component, key);
757
- return join6(stateDir, ".continuity", component + (key === void 0 ? "" : "-" + key) + "-replication.json");
755
+ function location2(stateDir, component, key2) {
756
+ checkKey(component, key2);
757
+ return join6(stateDir, ".continuity", component + (key2 === void 0 ? "" : "-" + key2) + "-replication.json");
758
758
  }
759
- function runtimeReplicationFile(stateDir, component, key) {
760
- checkKey(component, key);
761
- if (component === "legacy-memory") return join6(stateDir, "agents", key, "memory", "memory.db");
762
- if (component === "topics-vectors") return join6(stateDir, "topics-history", key, "vectors.db");
759
+ function runtimeReplicationFile(stateDir, component, key2) {
760
+ checkKey(component, key2);
761
+ if (component === "legacy-memory") return join6(stateDir, "agents", key2, "memory", "memory.db");
762
+ if (component === "topics-vectors") return join6(stateDir, "topics-history", key2, "vectors.db");
763
763
  if (component === "session-events") return join6(stateDir, ".continuity", "session-events.db");
764
764
  return join6(stateDir, "." + component, component + ".db");
765
765
  }
766
766
  function runtimeReplicationLocation(stateDir, component, file) {
767
- const key = component === "legacy-memory" ? basename2(dirname4(dirname4(file))) : component === "topics-vectors" ? basename2(dirname4(file)) : void 0;
767
+ const key2 = component === "legacy-memory" ? basename2(dirname4(dirname4(file))) : component === "topics-vectors" ? basename2(dirname4(file)) : void 0;
768
768
  try {
769
- if (resolve5(file) !== resolve5(runtimeReplicationFile(stateDir, component, key))) throw new Error();
769
+ if (resolve5(file) !== resolve5(runtimeReplicationFile(stateDir, component, key2))) throw new Error();
770
770
  } catch (error) {
771
771
  throw new Error("REPLICATION_RUNTIME_PATH_UNSUPPORTED", { cause: error });
772
772
  }
773
- return { component, ...key === void 0 ? {} : { key } };
773
+ return { component, ...key2 === void 0 ? {} : { key: key2 } };
774
774
  }
775
775
  function normalize2(input) {
776
776
  if (!input || !/^[a-f0-9]{64}$/.test(input.schemaHash)) throw new Error("REPLICATION_REGISTRATION_INVALID");
@@ -781,8 +781,8 @@ function directory(path2) {
781
781
  if (!info.isDirectory() || info.isSymbolicLink() || realpathSync2(path2) !== resolve5(path2) || process.platform !== "win32" && (info.mode & 63 || info.uid !== process.getuid()))
782
782
  throw new Error("REPLICATION_REGISTRATION_INVALID");
783
783
  }
784
- function readRuntimeReplicationRegistration(stateDir, component, key) {
785
- const file = location2(stateDir, component, key);
784
+ function readRuntimeReplicationRegistration(stateDir, component, key2) {
785
+ const file = location2(stateDir, component, key2);
786
786
  try {
787
787
  lstatSync5(dirname4(file));
788
788
  } catch (error) {
@@ -1190,10 +1190,10 @@ var init_live = __esm({
1190
1190
  /** 安全取子段('services.voice-chat.start' → current.services.voice-chat.start) */
1191
1191
  get(dotPath) {
1192
1192
  if (!this.current) return void 0;
1193
- return dotPath.split(".").reduce((acc, key) => {
1193
+ return dotPath.split(".").reduce((acc, key2) => {
1194
1194
  if (acc == null) return void 0;
1195
- if (key === "__proto__" || key === "constructor" || key === "prototype") return void 0;
1196
- return acc[key];
1195
+ if (key2 === "__proto__" || key2 === "constructor" || key2 === "prototype") return void 0;
1196
+ return acc[key2];
1197
1197
  }, this.current);
1198
1198
  }
1199
1199
  /** reload 时原地更新(Object.assign 保持引用不变)
@@ -1476,12 +1476,12 @@ async function fetchTravelKey(options) {
1476
1476
  const wanted = options.identity;
1477
1477
  if (value?.protocolVersion !== 1 || !value.identity || ["tenantId", "companionId", "seatId", "keyId", "generation"].some((k) => value.identity[k] !== wanted[k]) || !Number.isSafeInteger(value.deletionWatermark) || value.deletionWatermark < options.minimumDeletionWatermark || typeof value.key !== "string" || !/^[A-Za-z0-9+/]{43}=$/.test(value.key))
1478
1478
  throw new Error("KEY_SERVICE_INVALID_RESPONSE");
1479
- const key = Buffer.from(value.key, "base64");
1480
- if (key.length !== 32 || key.toString("base64") !== value.key) {
1481
- key.fill(0);
1479
+ const key2 = Buffer.from(value.key, "base64");
1480
+ if (key2.length !== 32 || key2.toString("base64") !== value.key) {
1481
+ key2.fill(0);
1482
1482
  throw new Error("KEY_SERVICE_INVALID_RESPONSE");
1483
1483
  }
1484
- return { key, deletionWatermark: value.deletionWatermark };
1484
+ return { key: key2, deletionWatermark: value.deletionWatermark };
1485
1485
  }
1486
1486
 
1487
1487
  // src/continuity/publication-objects.ts
@@ -2115,9 +2115,9 @@ async function collectInventory(options) {
2115
2115
  continue;
2116
2116
  }
2117
2117
  validateRelativePath(path2);
2118
- const key = root + "/" + path2.normalize("NFC").toLowerCase();
2119
- if (aliases.has(key)) throw new Error("PORTABLE_PATH_COLLISION");
2120
- aliases.add(key);
2118
+ const key2 = root + "/" + path2.normalize("NFC").toLowerCase();
2119
+ if (aliases.has(key2)) throw new Error("PORTABLE_PATH_COLLISION");
2120
+ aliases.add(key2);
2121
2121
  let info = await lstat(source, { bigint: true }), linkSignature = "";
2122
2122
  if (options.selection === "core" && root === "workspace" && !prefix && !CORE_DIRECTORIES.has(name) && (info.isDirectory() || info.isSymbolicLink() && !/\.[a-z0-9]+$/i.test(name))) {
2123
2123
  exclusions.push({ root, path: path2, reason: "optional workspace material; outside core travel" });
@@ -2322,7 +2322,7 @@ function canonical(value) {
2322
2322
  if (typeof value === "number" && Number.isFinite(value)) return value;
2323
2323
  if (Array.isArray(value)) return value.map(canonical);
2324
2324
  if (value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype)
2325
- return Object.fromEntries(Object.keys(value).sort().map((key) => [key, canonical(value[key])]));
2325
+ return Object.fromEntries(Object.keys(value).sort().map((key2) => [key2, canonical(value[key2])]));
2326
2326
  throw new Error("TREE_SOURCE_INVALID_ORIGIN");
2327
2327
  }
2328
2328
  var sha2 = (body) => createHash3("sha256").update(body).digest("hex");
@@ -2690,7 +2690,7 @@ import { existsSync as existsSync3, readFileSync as readFileSync5, renameSync as
2690
2690
  function canonicalJson(value) {
2691
2691
  const normalize4 = (input) => {
2692
2692
  if (Array.isArray(input)) return input.map(normalize4);
2693
- if (input && typeof input === "object") return Object.fromEntries(Object.entries(input).filter(([, entry]) => entry !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, entry]) => [key, normalize4(entry)]));
2693
+ if (input && typeof input === "object") return Object.fromEntries(Object.entries(input).filter(([, entry]) => entry !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key2, entry]) => [key2, normalize4(entry)]));
2694
2694
  return input;
2695
2695
  };
2696
2696
  const json = JSON.stringify(normalize4(value));
@@ -2739,9 +2739,9 @@ function invalidateChildren(db, scope, pending, reason) {
2739
2739
  let referencedPlan;
2740
2740
  while (pending.length) {
2741
2741
  const child = pending.shift();
2742
- const key = JSON.stringify([child.child_kind, child.child_id]);
2743
- if (visited.has(key) && (visited.get(key) || !child.deleted)) continue;
2744
- visited.set(key, Boolean(child.deleted));
2742
+ const key2 = JSON.stringify([child.child_kind, child.child_id]);
2743
+ if (visited.has(key2) && (visited.get(key2) || !child.deleted)) continue;
2744
+ visited.set(key2, Boolean(child.deleted));
2745
2745
  if (child.child_kind === "graph_plan") {
2746
2746
  referencedPlan ??= db.prepare(`SELECT 1 WHERE EXISTS (SELECT 1 FROM memory_dependencies
2747
2747
  WHERE scope_id=? AND parent_kind='artifact' AND parent_id=?)
@@ -2885,8 +2885,8 @@ var ChangeFeed = class _ChangeFeed {
2885
2885
  * 事件重放失败一次即回死信+skip,不重烧 5 轮预算)。先 UPDATE 后记账:中间崩溃只会
2886
2886
  * 多治一次(幂等无害),反过来会出现"记了账但没治"的永久死锁。 */
2887
2887
  reenqueueGapPrefix(sinkId, head, now2 = Date.now()) {
2888
- const key = `${sinkId}:${head.scopeId}:${head.eventSeq}`;
2889
- if (this.healedGaps.has(key)) return;
2888
+ const key2 = `${sinkId}:${head.scopeId}:${head.eventSeq}`;
2889
+ if (this.healedGaps.has(key2)) return;
2890
2890
  const ledgerPath = this.gapHealLedgerPath;
2891
2891
  let ledger = {};
2892
2892
  if (ledgerPath) {
@@ -2894,8 +2894,8 @@ var ChangeFeed = class _ChangeFeed {
2894
2894
  ledger = JSON.parse(readFileSync5(ledgerPath, "utf8"))?.heals ?? {};
2895
2895
  } catch {
2896
2896
  }
2897
- if (Number.isFinite(ledger[key])) {
2898
- this.healedGaps.add(key);
2897
+ if (Number.isFinite(ledger[key2])) {
2898
+ this.healedGaps.add(key2);
2899
2899
  return;
2900
2900
  }
2901
2901
  }
@@ -2909,11 +2909,11 @@ var ChangeFeed = class _ChangeFeed {
2909
2909
  const count = Number(result?.changes ?? 0);
2910
2910
  if (count > 0) console.warn(`[mem7] \u5E8F\u5217\u7F3A\u53E3\u81EA\u6108\uFF1Ahead seq=${head.eventSeq} \u524D ${count} \u6761\u5DF2 ack \u6295\u9012\u884C\u91CD\u7F6E\u5F85\u6295\uFF08\u65B0\u56FE\u5982\u5B9E\u91CD\u653E / \u65E7\u56FE\u5E42\u7B49 duplicate-ack\uFF1B\u6B7B\u4FE1\u884C\u4FDD\u7559 attempts\uFF09`);
2911
2911
  });
2912
- this.healedGaps.add(key);
2912
+ this.healedGaps.add(key2);
2913
2913
  if (!ledgerPath) return;
2914
2914
  const cutoff = now2 - _ChangeFeed.GAP_HEAL_RETENTION_MS, retained = {};
2915
2915
  for (const [entry, at] of Object.entries(ledger)) if (Number.isFinite(at) && at >= cutoff) retained[entry] = at;
2916
- retained[key] = now2;
2916
+ retained[key2] = now2;
2917
2917
  const temp = `${ledgerPath}.${randomUUID4()}.tmp`;
2918
2918
  try {
2919
2919
  writeFileSync5(temp, JSON.stringify({ version: 1, heals: retained }));
@@ -3122,6 +3122,15 @@ init_clock();
3122
3122
  init_read_guard();
3123
3123
  init_timing();
3124
3124
  init_runtime_authority();
3125
+
3126
+ // src/mem7/core/lance-cache.ts
3127
+ var LANCE_INDEX_CACHE_BYTES = 256 * 1024 * 1024;
3128
+ var LANCE_METADATA_CACHE_BYTES = 64 * 1024 * 1024;
3129
+ var key = Symbol.for("engine7.mem7.lanceCacheSessions");
3130
+ var globals = globalThis;
3131
+ var sessions = globals[key] ??= /* @__PURE__ */ new WeakMap();
3132
+
3133
+ // src/mem7/core/vector-store.ts
3125
3134
  var isIntelMac = process.platform === "darwin" && process.arch === "x64";
3126
3135
  function lanceSpecifierFor(platform, arch) {
3127
3136
  return platform === "darwin" && arch === "x64" ? "@engine7/lancedb-intel" : "@lancedb/lancedb";
@@ -4170,12 +4179,12 @@ var incarnation2 = (file) => {
4170
4179
  return `${s.dev}:${s.ino}`;
4171
4180
  };
4172
4181
  function validateRecoveryArchiveEntry(entry, identity) {
4173
- if (!entry || Object.keys(entry).some((key) => !["format", "id", "kind", "manifest", "databases", "publication", "receipt"].includes(key)) || entry.format !== FORMAT || !ID2.test(entry.id) || !["COMMON", "LOCAL", "REMOTE"].includes(entry.kind)) throw new Error("RECOVERY_ARCHIVE_CORRUPT");
4182
+ if (!entry || Object.keys(entry).some((key2) => !["format", "id", "kind", "manifest", "databases", "publication", "receipt"].includes(key2)) || entry.format !== FORMAT || !ID2.test(entry.id) || !["COMMON", "LOCAL", "REMOTE"].includes(entry.kind)) throw new Error("RECOVERY_ARCHIVE_CORRUPT");
4174
4183
  const manifest = normalizePublication(entry.manifest), manifestDigest = publicationDigest(manifest);
4175
4184
  if (!same4(manifest.profile.identity, identity)) throw new Error("RECOVERY_IDENTITY_MISMATCH");
4176
4185
  if (!Array.isArray(entry.databases) || !same4(entry.databases.map((db) => db.databaseId), manifest.profile.databaseIds)) throw new Error("RECOVERY_INCOMPLETE_DATABASES");
4177
4186
  for (const db of entry.databases) {
4178
- if (Object.keys(db).some((key) => !["databaseId", "role", "schemaHash", "content"].includes(key)) || db.role !== (entry.kind === "LOCAL" ? "source" : "replica") || !/^[a-f0-9]{64}$/.test(db.schemaHash)) throw new Error("RECOVERY_ARCHIVE_CORRUPT");
4187
+ if (Object.keys(db).some((key2) => !["databaseId", "role", "schemaHash", "content"].includes(key2)) || db.role !== (entry.kind === "LOCAL" ? "source" : "replica") || !/^[a-f0-9]{64}$/.test(db.schemaHash)) throw new Error("RECOVERY_ARCHIVE_CORRUPT");
4179
4188
  validateFileContent(db.content);
4180
4189
  }
4181
4190
  const publication = { state: "PUBLISHED", sequence: manifest.sequence, digest: manifestDigest, deletionWatermark: manifest.deletionWatermark, activationAllowed: false };