engine7 7.1.143 → 7.1.145

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.
@@ -687,15 +687,15 @@ var init_sqlite_replication = __esm({
687
687
  requireForeignKeys(this.db);
688
688
  if (captureGuardHash(this.db) !== this.guardHash) throw new Error("REPLICATION_GUARD_MISMATCH");
689
689
  if (sqliteReplicationSchemaHash(this.db) !== this.schemaHash) throw new Error("REPLICATION_SCHEMA_MISMATCH");
690
- const before = sequences(this.db, this.excludedTables), sessions = [];
690
+ const before = sequences(this.db, this.excludedTables), sessions2 = [];
691
691
  try {
692
- if (this.sessionTables) for (const table of this.sessionTables) sessions.push(this.db.createSession({ table }));
693
- else sessions.push(this.db.createSession());
692
+ if (this.sessionTables) for (const table of this.sessionTables) sessions2.push(this.db.createSession({ table }));
693
+ else sessions2.push(this.db.createSession());
694
694
  } catch (error) {
695
- for (const session of sessions) session.close();
695
+ for (const session of sessions2) session.close();
696
696
  throw error;
697
697
  }
698
- this.active = { sessions, sequences: before, closed: false };
698
+ this.active = { sessions: sessions2, sequences: before, closed: false };
699
699
  return this.active;
700
700
  }
701
701
  appendCapture(capture2) {
@@ -962,31 +962,31 @@ var init_sqlite_replication = __esm({
962
962
  // src/continuity/runtime-replication.ts
963
963
  import { constants as constants8, lstatSync as lstatSync7, realpathSync as realpathSync3, mkdirSync as mkdirSync5, openSync as openSync7, closeSync as closeSync6, fstatSync as fstatSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync4, fsyncSync as fsyncSync6 } from "node:fs";
964
964
  import { basename as basename2, dirname as dirname6, join as join8, resolve as resolve6 } from "node:path";
965
- function checkKey(component, key2) {
966
- if (component === "topics-vectors" && typeof key2 === "string" && /^[a-f0-9]{64}$/.test(key2)) return;
967
- 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;
968
- if (["calendar", "proactive", "session-events"].includes(component) && key2 === void 0) return;
965
+ function checkKey(component, key3) {
966
+ if (component === "topics-vectors" && typeof key3 === "string" && /^[a-f0-9]{64}$/.test(key3)) return;
967
+ 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;
968
+ if (["calendar", "proactive", "session-events"].includes(component) && key3 === void 0) return;
969
969
  throw new Error("REPLICATION_REGISTRATION_INVALID");
970
970
  }
971
- function location2(stateDir, component, key2) {
972
- checkKey(component, key2);
973
- return join8(stateDir, ".continuity", component + (key2 === void 0 ? "" : "-" + key2) + "-replication.json");
971
+ function location2(stateDir, component, key3) {
972
+ checkKey(component, key3);
973
+ return join8(stateDir, ".continuity", component + (key3 === void 0 ? "" : "-" + key3) + "-replication.json");
974
974
  }
975
- function runtimeReplicationFile(stateDir, component, key2) {
976
- checkKey(component, key2);
977
- if (component === "legacy-memory") return join8(stateDir, "agents", key2, "memory", "memory.db");
978
- if (component === "topics-vectors") return join8(stateDir, "topics-history", key2, "vectors.db");
975
+ function runtimeReplicationFile(stateDir, component, key3) {
976
+ checkKey(component, key3);
977
+ if (component === "legacy-memory") return join8(stateDir, "agents", key3, "memory", "memory.db");
978
+ if (component === "topics-vectors") return join8(stateDir, "topics-history", key3, "vectors.db");
979
979
  if (component === "session-events") return join8(stateDir, ".continuity", "session-events.db");
980
980
  return join8(stateDir, "." + component, component + ".db");
981
981
  }
982
982
  function runtimeReplicationLocation(stateDir, component, file) {
983
- const key2 = component === "legacy-memory" ? basename2(dirname6(dirname6(file))) : component === "topics-vectors" ? basename2(dirname6(file)) : void 0;
983
+ const key3 = component === "legacy-memory" ? basename2(dirname6(dirname6(file))) : component === "topics-vectors" ? basename2(dirname6(file)) : void 0;
984
984
  try {
985
- if (resolve6(file) !== resolve6(runtimeReplicationFile(stateDir, component, key2))) throw new Error();
985
+ if (resolve6(file) !== resolve6(runtimeReplicationFile(stateDir, component, key3))) throw new Error();
986
986
  } catch (error) {
987
987
  throw new Error("REPLICATION_RUNTIME_PATH_UNSUPPORTED", { cause: error });
988
988
  }
989
- return { component, ...key2 === void 0 ? {} : { key: key2 } };
989
+ return { component, ...key3 === void 0 ? {} : { key: key3 } };
990
990
  }
991
991
  function normalize2(input) {
992
992
  if (!input || !/^[a-f0-9]{64}$/.test(input.schemaHash)) throw new Error("REPLICATION_REGISTRATION_INVALID");
@@ -997,8 +997,8 @@ function directory(path3) {
997
997
  if (!info.isDirectory() || info.isSymbolicLink() || realpathSync3(path3) !== resolve6(path3) || process.platform !== "win32" && (info.mode & 63 || info.uid !== process.getuid()))
998
998
  throw new Error("REPLICATION_REGISTRATION_INVALID");
999
999
  }
1000
- function readRuntimeReplicationRegistration(stateDir, component, key2) {
1001
- const file = location2(stateDir, component, key2);
1000
+ function readRuntimeReplicationRegistration(stateDir, component, key3) {
1001
+ const file = location2(stateDir, component, key3);
1002
1002
  try {
1003
1003
  lstatSync7(dirname6(file));
1004
1004
  } catch (error) {
@@ -1061,8 +1061,8 @@ function checkRuntimeReplicationDatabase(db, registration, component, version, r
1061
1061
  }
1062
1062
  return requested ?? registration?.binding;
1063
1063
  }
1064
- function enrollRuntimeReplication(db, stateDir, component, binding, key2) {
1065
- const file = location2(stateDir, component, key2), old = readRuntimeReplicationRegistration(stateDir, component, key2);
1064
+ function enrollRuntimeReplication(db, stateDir, component, binding, key3) {
1065
+ const file = location2(stateDir, component, key3), old = readRuntimeReplicationRegistration(stateDir, component, key3);
1066
1066
  const version = readSchemaVersion(db);
1067
1067
  if (version?.component !== component) throw new Error("REPLICATION_SCHEMA_MISMATCH");
1068
1068
  checkRuntimeReplicationDatabase(db, old, component, version.version, binding);
@@ -1075,7 +1075,7 @@ function enrollRuntimeReplication(db, stateDir, component, binding, key2) {
1075
1075
  writeFileSync4(file, JSON.stringify(input), { mode: 384, flag: "wx", flush: true });
1076
1076
  } catch (error) {
1077
1077
  if (error.code !== "EEXIST") throw error;
1078
- if (JSON.stringify(readRuntimeReplicationRegistration(stateDir, component, key2)) !== JSON.stringify(input)) throw new Error("REPLICATION_REGISTRATION_MISMATCH");
1078
+ if (JSON.stringify(readRuntimeReplicationRegistration(stateDir, component, key3)) !== JSON.stringify(input)) throw new Error("REPLICATION_REGISTRATION_MISMATCH");
1079
1079
  }
1080
1080
  if (process.platform !== "win32") {
1081
1081
  const fd = openSync7(dirname6(file), "r");
@@ -1433,10 +1433,10 @@ var init_live = __esm({
1433
1433
  /** 安全取子段('services.voice-chat.start' → current.services.voice-chat.start) */
1434
1434
  get(dotPath) {
1435
1435
  if (!this.current) return void 0;
1436
- return dotPath.split(".").reduce((acc, key2) => {
1436
+ return dotPath.split(".").reduce((acc, key3) => {
1437
1437
  if (acc == null) return void 0;
1438
- if (key2 === "__proto__" || key2 === "constructor" || key2 === "prototype") return void 0;
1439
- return acc[key2];
1438
+ if (key3 === "__proto__" || key3 === "constructor" || key3 === "prototype") return void 0;
1439
+ return acc[key3];
1440
1440
  }, this.current);
1441
1441
  }
1442
1442
  /** reload 时原地更新(Object.assign 保持引用不变)
@@ -2281,9 +2281,9 @@ async function collectInventory(options) {
2281
2281
  continue;
2282
2282
  }
2283
2283
  validateRelativePath(path3);
2284
- const key2 = root + "/" + path3.normalize("NFC").toLowerCase();
2285
- if (aliases.has(key2)) throw new Error("PORTABLE_PATH_COLLISION");
2286
- aliases.add(key2);
2284
+ const key3 = root + "/" + path3.normalize("NFC").toLowerCase();
2285
+ if (aliases.has(key3)) throw new Error("PORTABLE_PATH_COLLISION");
2286
+ aliases.add(key3);
2287
2287
  let info = await lstat(source, { bigint: true }), linkSignature = "";
2288
2288
  if (options.selection === "core" && root === "workspace" && !prefix && !CORE_DIRECTORIES.has(name) && (info.isDirectory() || info.isSymbolicLink() && !/\.[a-z0-9]+$/i.test(name))) {
2289
2289
  exclusions2.push({ root, path: path3, reason: "optional workspace material; outside core travel" });
@@ -3482,7 +3482,7 @@ function canonical(value2) {
3482
3482
  if (typeof value2 === "number" && Number.isFinite(value2)) return value2;
3483
3483
  if (Array.isArray(value2)) return value2.map(canonical);
3484
3484
  if (value2 && typeof value2 === "object" && Object.getPrototypeOf(value2) === Object.prototype)
3485
- return Object.fromEntries(Object.keys(value2).sort().map((key2) => [key2, canonical(value2[key2])]));
3485
+ return Object.fromEntries(Object.keys(value2).sort().map((key3) => [key3, canonical(value2[key3])]));
3486
3486
  throw new Error("TREE_SOURCE_INVALID_ORIGIN");
3487
3487
  }
3488
3488
  var sha2 = (body) => createHash5("sha256").update(body).digest("hex");
@@ -3776,7 +3776,7 @@ import { existsSync as existsSync3, readFileSync as readFileSync5, renameSync as
3776
3776
  function canonicalJson(value2) {
3777
3777
  const normalize4 = (input) => {
3778
3778
  if (Array.isArray(input)) return input.map(normalize4);
3779
- 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)]));
3779
+ 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)]));
3780
3780
  return input;
3781
3781
  };
3782
3782
  const json = JSON.stringify(normalize4(value2));
@@ -3825,9 +3825,9 @@ function invalidateChildren(db, scope, pending, reason) {
3825
3825
  let referencedPlan;
3826
3826
  while (pending.length) {
3827
3827
  const child = pending.shift();
3828
- const key2 = JSON.stringify([child.child_kind, child.child_id]);
3829
- if (visited.has(key2) && (visited.get(key2) || !child.deleted)) continue;
3830
- visited.set(key2, Boolean(child.deleted));
3828
+ const key3 = JSON.stringify([child.child_kind, child.child_id]);
3829
+ if (visited.has(key3) && (visited.get(key3) || !child.deleted)) continue;
3830
+ visited.set(key3, Boolean(child.deleted));
3831
3831
  if (child.child_kind === "graph_plan") {
3832
3832
  referencedPlan ??= db.prepare(`SELECT 1 WHERE EXISTS (SELECT 1 FROM memory_dependencies
3833
3833
  WHERE scope_id=? AND parent_kind='artifact' AND parent_id=?)
@@ -3971,8 +3971,8 @@ var ChangeFeed = class _ChangeFeed {
3971
3971
  * 事件重放失败一次即回死信+skip,不重烧 5 轮预算)。先 UPDATE 后记账:中间崩溃只会
3972
3972
  * 多治一次(幂等无害),反过来会出现"记了账但没治"的永久死锁。 */
3973
3973
  reenqueueGapPrefix(sinkId, head, now2 = Date.now()) {
3974
- const key2 = `${sinkId}:${head.scopeId}:${head.eventSeq}`;
3975
- if (this.healedGaps.has(key2)) return;
3974
+ const key3 = `${sinkId}:${head.scopeId}:${head.eventSeq}`;
3975
+ if (this.healedGaps.has(key3)) return;
3976
3976
  const ledgerPath = this.gapHealLedgerPath;
3977
3977
  let ledger = {};
3978
3978
  if (ledgerPath) {
@@ -3980,8 +3980,8 @@ var ChangeFeed = class _ChangeFeed {
3980
3980
  ledger = JSON.parse(readFileSync5(ledgerPath, "utf8"))?.heals ?? {};
3981
3981
  } catch {
3982
3982
  }
3983
- if (Number.isFinite(ledger[key2])) {
3984
- this.healedGaps.add(key2);
3983
+ if (Number.isFinite(ledger[key3])) {
3984
+ this.healedGaps.add(key3);
3985
3985
  return;
3986
3986
  }
3987
3987
  }
@@ -3995,11 +3995,11 @@ var ChangeFeed = class _ChangeFeed {
3995
3995
  const count = Number(result?.changes ?? 0);
3996
3996
  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`);
3997
3997
  });
3998
- this.healedGaps.add(key2);
3998
+ this.healedGaps.add(key3);
3999
3999
  if (!ledgerPath) return;
4000
4000
  const cutoff = now2 - _ChangeFeed.GAP_HEAL_RETENTION_MS, retained = {};
4001
4001
  for (const [entry, at] of Object.entries(ledger)) if (Number.isFinite(at) && at >= cutoff) retained[entry] = at;
4002
- retained[key2] = now2;
4002
+ retained[key3] = now2;
4003
4003
  const temp = `${ledgerPath}.${randomUUID5()}.tmp`;
4004
4004
  try {
4005
4005
  writeFileSync6(temp, JSON.stringify({ version: 1, heals: retained }));
@@ -4106,7 +4106,7 @@ import { createHash as createHash8 } from "node:crypto";
4106
4106
  var recoveryOriginalSourceId = (scope, origin, version) => "src_" + createHash8("sha256").update(JSON.stringify([scope, origin, version])).digest("hex");
4107
4107
 
4108
4108
  // src/continuity/recovery-deletion.ts
4109
- var text = (row, key2) => row[key2]?.[0] === "text" ? row[key2][1] : void 0;
4109
+ var text = (row, key3) => row[key3]?.[0] === "text" ? row[key3][1] : void 0;
4110
4110
  var key = (scope, kind, id2) => JSON.stringify([scope, kind, id2]);
4111
4111
  var RecoveryDeletionGraph = class {
4112
4112
  edges = /* @__PURE__ */ new Map();
@@ -4356,6 +4356,15 @@ init_clock();
4356
4356
  init_read_guard();
4357
4357
  init_timing();
4358
4358
  init_runtime_authority();
4359
+
4360
+ // src/mem7/core/lance-cache.ts
4361
+ var LANCE_INDEX_CACHE_BYTES = 256 * 1024 * 1024;
4362
+ var LANCE_METADATA_CACHE_BYTES = 64 * 1024 * 1024;
4363
+ var key2 = Symbol.for("engine7.mem7.lanceCacheSessions");
4364
+ var globals = globalThis;
4365
+ var sessions = globals[key2] ??= /* @__PURE__ */ new WeakMap();
4366
+
4367
+ // src/mem7/core/vector-store.ts
4359
4368
  var isIntelMac = process.platform === "darwin" && process.arch === "x64";
4360
4369
  function lanceSpecifierFor(platform, arch) {
4361
4370
  return platform === "darwin" && arch === "x64" ? "@engine7/lancedb-intel" : "@lancedb/lancedb";
@@ -4901,11 +4910,11 @@ var EVENT_BYTES = 16 * 1024 * 1024;
4901
4910
  function sessionLimits(options) {
4902
4911
  if (!options || typeof options !== "object" || Array.isArray(options)) throw new Error("REPLICATION_INVALID_LIMIT");
4903
4912
  const limits2 = {};
4904
- for (const key2 of ["maximumPendingBytes", "maximumCommitBytes"]) {
4905
- const value2 = options[key2];
4913
+ for (const key3 of ["maximumPendingBytes", "maximumCommitBytes"]) {
4914
+ const value2 = options[key3];
4906
4915
  if (value2 !== void 0) {
4907
4916
  if (!Number.isSafeInteger(value2) || value2 < 1 || value2 > 256 * 1024 * 1024) throw new Error("REPLICATION_INVALID_LIMIT");
4908
- limits2[key2] = value2;
4917
+ limits2[key3] = value2;
4909
4918
  }
4910
4919
  }
4911
4920
  return limits2;
@@ -4988,16 +4997,16 @@ function* frames(bytes, kind) {
4988
4997
  }
4989
4998
  if (offset !== bytes.length) throw new Error("SESSION_EVENT_TORN_BASELINE");
4990
4999
  }
4991
- function rememberEvent(db, key2, body, kind) {
5000
+ function rememberEvent(db, key3, body, kind) {
4992
5001
  const id2 = eventId(body, kind), digest3 = sha4(body);
4993
- const old = db.prepare("SELECT sequence,digest,body FROM session_events WHERE session_key=? AND event_id=?").get(key2, id2);
5002
+ const old = db.prepare("SELECT sequence,digest,body FROM session_events WHERE session_key=? AND event_id=?").get(key3, id2);
4994
5003
  if (old) {
4995
5004
  if (old.digest !== digest3 || !(old.body instanceof Uint8Array) || !body.equals(Buffer.from(old.body))) throw new Error("SESSION_EVENT_ID_CONFLICT");
4996
5005
  return Number(old.sequence);
4997
5006
  }
4998
5007
  const sequence = Number(db.prepare("SELECT COALESCE(max(sequence),0)+1 n FROM session_events").get().n);
4999
5008
  if (!Number.isSafeInteger(sequence) || sequence < 1) throw new Error("SESSION_EVENT_SEQUENCE_EXHAUSTED");
5000
- db.prepare("INSERT INTO session_events VALUES(?,?,?,?,?)").run(sequence, key2, id2, body, digest3);
5009
+ db.prepare("INSERT INTO session_events VALUES(?,?,?,?,?)").run(sequence, key3, id2, body, digest3);
5001
5010
  return sequence;
5002
5011
  }
5003
5012
  function nextRevision(db) {
@@ -5452,9 +5461,9 @@ async function runRuntimeArtifactCli(command, config) {
5452
5461
  }
5453
5462
  const profile = normalizePublicationProfile(config.profile), dataDir = absolute(config.dataDir), keyFile = absolute(config.dataKeyFile);
5454
5463
  if (isWithin(stateDir, dataDir) || isWithin(dataDir, stateDir) || isWithin(stateDir, keyFile) || isWithin(dataDir, keyFile)) throw new Error("PUBLICATION_OVERLAPPING_PATHS");
5455
- const key2 = readPrivateFile(keyFile, 32);
5456
- if (key2.length !== 32) {
5457
- key2.fill(0);
5464
+ const key3 = readPrivateFile(keyFile, 32);
5465
+ if (key3.length !== 32) {
5466
+ key3.fill(0);
5458
5467
  throw new Error("PUBLICATION_INVALID_KEY");
5459
5468
  }
5460
5469
  const releases2 = [];
@@ -5487,7 +5496,7 @@ async function runRuntimeArtifactCli(command, config) {
5487
5496
  }
5488
5497
  for (const root of [...runtimeRoots].sort()) releases2.push(registerRuntimeWriter(root, "travel-data-runtime-capture"));
5489
5498
  } else if (command !== "restore-lance") throw new Error("PUBLICATION_INVALID_COMMAND");
5490
- objects = await PublicationObjects.open({ directory: join15(dataDir, "objects"), key: key2, identity: profile.identity, maximumBytes: config.maximumBytes });
5499
+ objects = await PublicationObjects.open({ directory: join15(dataDir, "objects"), key: key3, identity: profile.identity, maximumBytes: config.maximumBytes });
5491
5500
  source = await RuntimeTreeSource.open({
5492
5501
  directory: join15(dataDir, "runtime-trees"),
5493
5502
  profile,
@@ -5538,7 +5547,7 @@ async function runRuntimeArtifactCli(command, config) {
5538
5547
  source?.close();
5539
5548
  objects?.close();
5540
5549
  for (const release of releases2.reverse()) release();
5541
- key2.fill(0);
5550
+ key3.fill(0);
5542
5551
  }
5543
5552
  }
5544
5553
 
@@ -6302,12 +6311,12 @@ var incarnation2 = (file) => {
6302
6311
  return `${s.dev}:${s.ino}`;
6303
6312
  };
6304
6313
  function validateRecoveryArchiveEntry(entry, identity) {
6305
- 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");
6314
+ 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");
6306
6315
  const manifest = normalizePublication(entry.manifest), manifestDigest = publicationDigest(manifest);
6307
6316
  if (!same5(manifest.profile.identity, identity)) throw new Error("RECOVERY_IDENTITY_MISMATCH");
6308
6317
  if (!Array.isArray(entry.databases) || !same5(entry.databases.map((db) => db.databaseId), manifest.profile.databaseIds)) throw new Error("RECOVERY_INCOMPLETE_DATABASES");
6309
6318
  for (const db of entry.databases) {
6310
- 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");
6319
+ 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");
6311
6320
  validateFileContent(db.content);
6312
6321
  }
6313
6322
  const publication = { state: "PUBLISHED", sequence: manifest.sequence, digest: manifestDigest, deletionWatermark: manifest.deletionWatermark, activationAllowed: false };
@@ -6828,7 +6837,7 @@ async function compareRecoveryArchives(options) {
6828
6837
  if (readSchemaVersion(db)?.component === "legacy-memory") loadLegacySQLiteVectorExtension(db);
6829
6838
  db.exec("PRAGMA temp_store=FILE; PRAGMA cache_size=-8192");
6830
6839
  db.function("e7_recovery_key", { varargs: true, useBigIntArguments: true, deterministic: true }, (...cells) => JSON.stringify(cells.map(value)));
6831
- db.function("e7_recovery_order", { deterministic: true }, (key2) => Buffer.from(String(key2), "utf16le").swap16().toString("hex"));
6840
+ db.function("e7_recovery_order", { deterministic: true }, (key3) => Buffer.from(String(key3), "utf16le").swap16().toString("hex"));
6832
6841
  }
6833
6842
  const schemas = handles.map(tables);
6834
6843
  if (!same6(schemas[0], schemas[1]) || !same6(schemas[0], schemas[2])) throw new Error("RECOVERY_DIFF_SCHEMA_MISMATCH");
@@ -6836,10 +6845,10 @@ async function compareRecoveryArchives(options) {
6836
6845
  for (const table of schemas[0]) {
6837
6846
  await check();
6838
6847
  const records = handles.map((db) => {
6839
- const key2 = "e7_recovery_key(" + table.keys.map(quote2).join(",") + ")";
6848
+ const key3 = "e7_recovery_key(" + table.keys.map(quote2).join(",") + ")";
6840
6849
  const sizes = table.columns.map((column) => "coalesce(length(CAST(" + quote2(column) + " AS BLOB)),0)").join("+");
6841
6850
  if (db.prepare("SELECT 1 FROM " + quote2(table.name) + " WHERE (" + sizes + ")>16777216 LIMIT 1").get()) throw new Error("RECOVERY_DIFF_LIMIT");
6842
- const statement = db.prepare("SELECT " + table.columns.map(quote2).join(",") + " FROM " + quote2(table.name) + " ORDER BY e7_recovery_order(" + key2 + ")");
6851
+ const statement = db.prepare("SELECT " + table.columns.map(quote2).join(",") + " FROM " + quote2(table.name) + " ORDER BY e7_recovery_order(" + key3 + ")");
6843
6852
  statement.setReadBigInts(true);
6844
6853
  return statement.iterate()[Symbol.iterator]();
6845
6854
  });
@@ -6857,11 +6866,11 @@ async function compareRecoveryArchives(options) {
6857
6866
  try {
6858
6867
  const current2 = records.map((_, index) => next(index));
6859
6868
  while (current2.some(Boolean)) {
6860
- const key2 = current2.filter((row) => !!row).map((row) => row.key).sort()[0];
6861
- emit({ databaseId, table: table.name, key: JSON.parse(key2) }, ...current2.map((row) => row?.key === key2 ? row.row : null));
6862
- for (let index = 0; index < current2.length; index++) if (current2[index]?.key === key2) {
6863
- if (previous[index] === key2) throw new Error("RECOVERY_DIFF_INVALID_KEY");
6864
- previous[index] = key2;
6869
+ const key3 = current2.filter((row) => !!row).map((row) => row.key).sort()[0];
6870
+ emit({ databaseId, table: table.name, key: JSON.parse(key3) }, ...current2.map((row) => row?.key === key3 ? row.row : null));
6871
+ for (let index = 0; index < current2.length; index++) if (current2[index]?.key === key3) {
6872
+ if (previous[index] === key3) throw new Error("RECOVERY_DIFF_INVALID_KEY");
6873
+ previous[index] = key3;
6865
6874
  current2[index] = next(index);
6866
6875
  }
6867
6876
  if (scannedRecords % 128 === 0 || performance.now() - lastYield >= 25) {
@@ -7018,14 +7027,14 @@ function recoveryDeletionReader(config) {
7018
7027
  async function runRecoveryCli(command, config) {
7019
7028
  if (!recoveryCommands.includes(command)) throw new Error("PUBLICATION_INVALID_COMMAND");
7020
7029
  if (command === "admit-recovery") {
7021
- const key2 = readPrivateFile(absolute2(config.privateKeyFile), 16384);
7030
+ const key3 = readPrivateFile(absolute2(config.privateKeyFile), 16384);
7022
7031
  try {
7023
7032
  return await requestRecoveryAdmission({
7024
7033
  url: config.url,
7025
7034
  timeoutMs: config.timeoutMs,
7026
7035
  ca: readPrivateFile(absolute2(config.caFile), 1024 * 1024),
7027
7036
  cert: readPrivateFile(absolute2(config.certificateFile), 16384),
7028
- key: key2,
7037
+ key: key3,
7029
7038
  request: {
7030
7039
  format: "engine7-recovery-admission-request-v1",
7031
7040
  batchId: config.batchId,
@@ -7036,7 +7045,7 @@ async function runRecoveryCli(command, config) {
7036
7045
  }
7037
7046
  });
7038
7047
  } finally {
7039
- key2.fill(0);
7048
+ key3.fill(0);
7040
7049
  }
7041
7050
  }
7042
7051
  const deletionWatermark = recoveryDeletionReader(config);
@@ -7047,10 +7056,10 @@ async function runRecoveryCli(command, config) {
7047
7056
  if (isWithin(dataDir, keyFile)) throw new Error("RECOVERY_OVERLAPPING_PATHS");
7048
7057
  assertPrivateDirectory(dataDir);
7049
7058
  if (!existsSync7(join20(dataDir, "objects/catalog.sqlite"))) throw new Error("RECOVERY_ARCHIVE_REQUIRED");
7050
- const key2 = readPrivateFile(keyFile, 32);
7051
- keys.push(key2);
7052
- if (key2.length !== 32) throw new Error("PUBLICATION_INVALID_KEY");
7053
- const objects = await PublicationObjects.open({ directory: join20(dataDir, "objects"), key: key2, identity: c.identity });
7059
+ const key3 = readPrivateFile(keyFile, 32);
7060
+ keys.push(key3);
7061
+ if (key3.length !== 32) throw new Error("PUBLICATION_INVALID_KEY");
7062
+ const objects = await PublicationObjects.open({ directory: join20(dataDir, "objects"), key: key3, identity: c.identity });
7054
7063
  handles.push(objects);
7055
7064
  const archive = await RuntimeRecoveryArchive.open({ directory: join20(dataDir, "recovery"), objects });
7056
7065
  handles.push(archive);
@@ -7081,7 +7090,7 @@ async function runRecoveryCli(command, config) {
7081
7090
  return { digest: report.digest, reportFile, counts: report.counts, scannedRecords: report.scannedRecords, admissionAllowed: false, activationAllowed: false };
7082
7091
  } finally {
7083
7092
  for (const handle of handles.reverse()) handle.close();
7084
- for (const key2 of keys) key2.fill(0);
7093
+ for (const key3 of keys) key3.fill(0);
7085
7094
  }
7086
7095
  }
7087
7096
 
@@ -7107,9 +7116,9 @@ function exclusions(value2) {
7107
7116
  if (value2 === void 0) return {};
7108
7117
  if (!value2 || typeof value2 !== "object" || Array.isArray(value2)) throw new Error("PUBLICATION_INVALID_PATH_LIST");
7109
7118
  const result = {};
7110
- for (const [key2, reason] of Object.entries(value2).sort(([a], [b]) => a.localeCompare(b, "en"))) {
7119
+ for (const [key3, reason] of Object.entries(value2).sort(([a], [b]) => a.localeCompare(b, "en"))) {
7111
7120
  if (typeof reason !== "string" || !reason.trim()) throw new Error("PUBLICATION_INVALID_PATH_LIST");
7112
- result[key2] = reason;
7121
+ result[key3] = reason;
7113
7122
  }
7114
7123
  return result;
7115
7124
  }
@@ -7164,9 +7173,9 @@ async function runRuntimeSyncCli(command, config) {
7164
7173
  if (!place || !isWithin(stateDir, place.stateDir)) throw new Error("REPLICATION_RUNTIME_PATH_UNSUPPORTED");
7165
7174
  roots.add(place.stateDir);
7166
7175
  }
7167
- const key2 = readPrivateFile(keyFile, 32);
7168
- if (key2.length !== 32) {
7169
- key2.fill(0);
7176
+ const key3 = readPrivateFile(keyFile, 32);
7177
+ if (key3.length !== 32) {
7178
+ key3.fill(0);
7170
7179
  throw new Error("PUBLICATION_INVALID_KEY");
7171
7180
  }
7172
7181
  const releases2 = [], databases = {};
@@ -7205,7 +7214,7 @@ async function runRuntimeSyncCli(command, config) {
7205
7214
  if (stopped) databases[d.id] = { file: d.file, source: new SQLiteReplicationSourceReader(db, binding) };
7206
7215
  else databases[d.id] = writableDatabases[d.id] = { file: d.file, source: new SQLiteReplicationSource(db, binding) };
7207
7216
  }
7208
- objects = await PublicationObjects.open({ directory: join21(dataDir, "objects"), key: key2, identity: profile.identity, maximumBytes: config.maximumBytes });
7217
+ objects = await PublicationObjects.open({ directory: join21(dataDir, "objects"), key: key3, identity: profile.identity, maximumBytes: config.maximumBytes });
7209
7218
  const initialize2 = command === "prepare-runtime";
7210
7219
  trees = await RuntimeTreeSource.open({ directory: join21(dataDir, "runtime-trees"), profile, objects, initialize: initialize2 && config.initializeTreeSource === true, maximumBytes: config.maximumTreeBytes });
7211
7220
  source = await RuntimePublicationSource.open({
@@ -7307,7 +7316,7 @@ async function runRuntimeSyncCli(command, config) {
7307
7316
  try {
7308
7317
  return await operate();
7309
7318
  } finally {
7310
- key2.fill(0);
7319
+ key3.fill(0);
7311
7320
  }
7312
7321
  }
7313
7322
 
@@ -7377,7 +7386,7 @@ async function restoreRuntimePublication(options) {
7377
7386
  if (!status.published || !status.dataReady) throw new Error("PUBLICATION_NOT_READY");
7378
7387
  if (options.sequence !== void 0 && options.sequence !== status.published.sequence) throw new Error("PUBLICATION_STALE_PUBLICATION");
7379
7388
  const manifest = await receiver.manifest(status.published.sequence), destination = resolve21(options.destination);
7380
- const sessions = [];
7389
+ const sessions2 = [];
7381
7390
  for (const kind of manifest.profile.trees.filter((tree) => tree.kind === "session")) {
7382
7391
  const tree = manifest.trees.find((tree2) => tree2.id === kind.id);
7383
7392
  if (tree.directories.length || tree.files.length !== 1 || tree.files[0].path !== "manifest.json") throw new Error("RUNTIME_INCOMPLETE_SESSIONS");
@@ -7390,7 +7399,7 @@ async function restoreRuntimePublication(options) {
7390
7399
  epoch: manifest.profile.epoch
7391
7400
  });
7392
7401
  if (metadata4.format !== "engine7-session-events-publication-v1" || !database || JSON.stringify(metadata4.binding) !== JSON.stringify(binding) || JSON.stringify(metadata4.head) !== JSON.stringify(database.head)) throw new Error("RUNTIME_INCOMPLETE_SESSIONS");
7393
- sessions.push({ treeId: tree.id, databaseId: database.databaseId, head: database.head, binding });
7402
+ sessions2.push({ treeId: tree.id, databaseId: database.databaseId, head: database.head, binding });
7394
7403
  }
7395
7404
  await restorePublication({ ...options, destination, deferReceipt: true });
7396
7405
  const lance = [], sessionStates = [];
@@ -7404,7 +7413,7 @@ async function restoreRuntimePublication(options) {
7404
7413
  await syncDirectory(join23(destination, "lance"));
7405
7414
  lance.push({ treeId: tree.id, directory: `lance/${tree.id}` });
7406
7415
  }
7407
- for (const session of sessions) {
7416
+ for (const session of sessions2) {
7408
7417
  const directory2 = join23(destination, "sessions", session.treeId), db = new DatabaseSync19(join23(destination, "databases", session.databaseId + ".sqlite"), { readOnly: true });
7409
7418
  try {
7410
7419
  const head = db.prepare("SELECT head,digest FROM e7_replication_control WHERE role='replica'").get();
@@ -7479,14 +7488,14 @@ async function runPublicationCli(args) {
7479
7488
  return place ? [place.stateDir] : [];
7480
7489
  })])].sort();
7481
7490
  if (sourceMode) for (const root of runtimeRoots) assertStateDirUsable(root);
7482
- const key2 = readPrivateFile(keyFile, 32);
7483
- if (key2.length !== 32) {
7484
- key2.fill(0);
7491
+ const key3 = readPrivateFile(keyFile, 32);
7492
+ if (key3.length !== 32) {
7493
+ key3.fill(0);
7485
7494
  throw new Error("PUBLICATION_INVALID_KEY");
7486
7495
  }
7487
7496
  try {
7488
7497
  const operate = async () => {
7489
- const objects = await PublicationObjects.open({ directory: join24(dataDir, "objects"), key: key2, identity: profile.identity, maximumBytes: config.maximumBytes });
7498
+ const objects = await PublicationObjects.open({ directory: join24(dataDir, "objects"), key: key3, identity: profile.identity, maximumBytes: config.maximumBytes });
7490
7499
  const databases = /* @__PURE__ */ Object.create(null);
7491
7500
  const sources = /* @__PURE__ */ Object.create(null), replicas = /* @__PURE__ */ Object.create(null);
7492
7501
  let receiver;
@@ -7639,7 +7648,7 @@ async function runPublicationCli(args) {
7639
7648
  }
7640
7649
  return await locked();
7641
7650
  } finally {
7642
- key2.fill(0);
7651
+ key3.fill(0);
7643
7652
  }
7644
7653
  }
7645
7654
  if (process.argv[1] && fileURLToPath2(import.meta.url) === resolve22(process.argv[1])) {