engine7 7.1.140 → 7.1.141

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.
@@ -12041,6 +12041,16 @@ function recoverCwd(file2) {
12041
12041
  }
12042
12042
  return null;
12043
12043
  }
12044
+ function userText(content) {
12045
+ if (typeof content === "string") return content.trim() ? content : null;
12046
+ if (Array.isArray(content)) {
12047
+ const text2 = content.filter(
12048
+ (b) => !!b && typeof b === "object" && b.type === "text" && typeof b.text === "string"
12049
+ ).map((b) => b.text).join(" ");
12050
+ return text2.trim() ? text2 : null;
12051
+ }
12052
+ return null;
12053
+ }
12044
12054
  function firstUserText(file2) {
12045
12055
  try {
12046
12056
  const text2 = headBytes(file2, 65536).toString("utf-8");
@@ -12052,9 +12062,12 @@ function firstUserText(file2) {
12052
12062
  } catch {
12053
12063
  continue;
12054
12064
  }
12055
- if (entry.type === "user" && typeof entry.message?.content === "string") {
12056
- const s = entry.message.content.replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim();
12057
- if (s) return s.length > 40 ? s.slice(0, 40) + "\u2026" : s;
12065
+ if (entry.type === "user") {
12066
+ const t = userText(entry.message?.content);
12067
+ if (t) {
12068
+ const s = t.replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim();
12069
+ if (s) return s.length > 40 ? s.slice(0, 40) + "\u2026" : s;
12070
+ }
12058
12071
  }
12059
12072
  }
12060
12073
  } catch {
@@ -17967,6 +17980,9 @@ var TravelAuthority = class {
17967
17980
  CREATE TABLE IF NOT EXISTS recovery_branches(identity TEXT NOT NULL,common TEXT NOT NULL,local TEXT NOT NULL,
17968
17981
  chain TEXT NOT NULL,PRIMARY KEY(identity,common,local));`);
17969
17982
  this.db.exec("CREATE TABLE IF NOT EXISTS retirement_sources(identity TEXT PRIMARY KEY,body TEXT NOT NULL)");
17983
+ if (!this.db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='leased_seats'").get()) {
17984
+ this.transaction(() => this.db.exec("CREATE TABLE leased_seats(identity TEXT PRIMARY KEY); INSERT INTO leased_seats SELECT identity FROM seats"));
17985
+ }
17970
17986
  if (this.db.prepare("PRAGMA quick_check").get()?.quick_check !== "ok") throw new Error("TRAVEL_AUTHORITY_CORRUPT");
17971
17987
  this.transaction(() => {
17972
17988
  this.db.exec("UPDATE seats SET epoch=epoch+1,active_node=NULL,active_boot=NULL,frozen=0 WHERE retired IS NULL");
@@ -18031,7 +18047,7 @@ var TravelAuthority = class {
18031
18047
  }
18032
18048
  /** Trusted pairing owner binds the first real H to an unused reservation.
18033
18049
  * This does not grant a lease and never rewrites a used seat's history. */
18034
- bindInitialCheckpoint(principal, digest7, buildManifestId) {
18050
+ bindInitialCheckpoint(principal, digest7, buildManifestId, previousDigest) {
18035
18051
  if (!HASH2.test(digest7) || digest7 === "0".repeat(64)) throw new Error("TRAVEL_INITIAL_BASELINE");
18036
18052
  id(buildManifestId);
18037
18053
  const text2 = identityText2(principal);
@@ -18040,7 +18056,9 @@ var TravelAuthority = class {
18040
18056
  this.principal(principal);
18041
18057
  if (!row || row.active_node !== null || row.active_boot !== null || row.frozen || row.retired !== null || row.floor !== 0 || row.build !== buildManifestId || this.db.prepare("SELECT 1 FROM handoffs WHERE identity=? LIMIT 1").get(text2)) throw new Error("TRAVEL_INITIAL_BASELINE");
18042
18058
  if (row.checkpoint === digest7) return;
18043
- if (row.checkpoint !== "0".repeat(64)) throw new Error("TRAVEL_INITIAL_BASELINE");
18059
+ if (this.db.prepare("SELECT 1 FROM leased_seats WHERE identity=?").get(text2)) throw new Error("TRAVEL_INITIAL_BASELINE");
18060
+ if (previousDigest !== void 0 && (!HASH2.test(previousDigest) || row.checkpoint !== previousDigest)) throw new Error("TRAVEL_INITIAL_BASELINE");
18061
+ if (row.checkpoint !== "0".repeat(64) && previousDigest !== row.checkpoint) throw new Error("TRAVEL_INITIAL_BASELINE");
18044
18062
  this.db.prepare("DELETE FROM checkpoints WHERE identity=?").run(text2);
18045
18063
  this.db.prepare("INSERT INTO checkpoints VALUES(?,?,NULL,1)").run(text2, digest7);
18046
18064
  this.db.prepare("UPDATE seats SET checkpoint=? WHERE identity=?").run(digest7, text2);
@@ -18111,6 +18129,7 @@ var TravelAuthority = class {
18111
18129
  if (row.active_node && ((this.deadlines.get(text2) ?? 0) <= this.monotonicNow() || row.active_boot !== node.boot)) row.epoch++;
18112
18130
  row.active_node = principal.nodeId;
18113
18131
  row.active_boot = String(node.boot);
18132
+ this.db.prepare("INSERT OR IGNORE INTO leased_seats VALUES(?)").run(text2);
18114
18133
  this.db.prepare("UPDATE seats SET epoch=?,active_node=?,active_boot=? WHERE identity=?").run(row.epoch, row.active_node, row.active_boot, text2);
18115
18134
  this.deadlines.set(text2, this.monotonicNow() + this.leaseMs);
18116
18135
  this.healthy.set(text2 + principal.nodeId, this.monotonicNow() + this.leaseMs);
@@ -35842,7 +35861,7 @@ async function startPairingControl(config) {
35842
35861
  chunks.push(chunk);
35843
35862
  }
35844
35863
  const input = JSON.parse(Buffer.concat(chunks).toString());
35845
- if (JSON.stringify(input.identity) !== JSON.stringify(config.identity) || !["status", "enable_ingress", "disable_ingress", "bind_initial", "exit_dedupe"].includes(input.action) || Object.keys(input).some((name) => !["identity", "action", "digest"].includes(name))) throw new Error("TRAVEL_PAIRING_REQUEST");
35864
+ if (JSON.stringify(input.identity) !== JSON.stringify(config.identity) || !["status", "enable_ingress", "disable_ingress", "bind_initial", "exit_dedupe"].includes(input.action) || Object.keys(input).some((name) => !["identity", "action", "digest", "previousDigest"].includes(name)) || input.previousDigest !== void 0 && (input.action !== "bind_initial" || typeof input.previousDigest !== "string")) throw new Error("TRAVEL_PAIRING_REQUEST");
35846
35865
  if (input.action === "exit_dedupe") {
35847
35866
  res.end(JSON.stringify({ ok: true, receipt: gateway.store.recoveryDedupeReceipt(binding.local, input.digest) }));
35848
35867
  return;
@@ -35864,7 +35883,7 @@ async function startPairingControl(config) {
35864
35883
  gateway = await startTravelGateway(gatewayConfig);
35865
35884
  ingress = false;
35866
35885
  }
35867
- if (input.action === "bind_initial") gateway.authority.bindInitialCheckpoint(binding.local, input.digest, config.buildManifestId);
35886
+ if (input.action === "bind_initial") gateway.authority.bindInitialCheckpoint(binding.local, input.digest, config.buildManifestId, input.previousDigest);
35868
35887
  } finally {
35869
35888
  changing = false;
35870
35889
  }