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.
@@ -11836,6 +11836,16 @@ function recoverCwd(file2) {
11836
11836
  }
11837
11837
  return null;
11838
11838
  }
11839
+ function userText(content) {
11840
+ if (typeof content === "string") return content.trim() ? content : null;
11841
+ if (Array.isArray(content)) {
11842
+ const text2 = content.filter(
11843
+ (b) => !!b && typeof b === "object" && b.type === "text" && typeof b.text === "string"
11844
+ ).map((b) => b.text).join(" ");
11845
+ return text2.trim() ? text2 : null;
11846
+ }
11847
+ return null;
11848
+ }
11839
11849
  function firstUserText(file2) {
11840
11850
  try {
11841
11851
  const text2 = headBytes(file2, 65536).toString("utf-8");
@@ -11847,9 +11857,12 @@ function firstUserText(file2) {
11847
11857
  } catch {
11848
11858
  continue;
11849
11859
  }
11850
- if (entry.type === "user" && typeof entry.message?.content === "string") {
11851
- const s = entry.message.content.replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim();
11852
- if (s) return s.length > 40 ? s.slice(0, 40) + "\u2026" : s;
11860
+ if (entry.type === "user") {
11861
+ const t = userText(entry.message?.content);
11862
+ if (t) {
11863
+ const s = t.replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim();
11864
+ if (s) return s.length > 40 ? s.slice(0, 40) + "\u2026" : s;
11865
+ }
11853
11866
  }
11854
11867
  }
11855
11868
  } catch {
@@ -17761,6 +17774,9 @@ var TravelAuthority = class {
17761
17774
  CREATE TABLE IF NOT EXISTS recovery_branches(identity TEXT NOT NULL,common TEXT NOT NULL,local TEXT NOT NULL,
17762
17775
  chain TEXT NOT NULL,PRIMARY KEY(identity,common,local));`);
17763
17776
  this.db.exec("CREATE TABLE IF NOT EXISTS retirement_sources(identity TEXT PRIMARY KEY,body TEXT NOT NULL)");
17777
+ if (!this.db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='leased_seats'").get()) {
17778
+ this.transaction(() => this.db.exec("CREATE TABLE leased_seats(identity TEXT PRIMARY KEY); INSERT INTO leased_seats SELECT identity FROM seats"));
17779
+ }
17764
17780
  if (this.db.prepare("PRAGMA quick_check").get()?.quick_check !== "ok") throw new Error("TRAVEL_AUTHORITY_CORRUPT");
17765
17781
  this.transaction(() => {
17766
17782
  this.db.exec("UPDATE seats SET epoch=epoch+1,active_node=NULL,active_boot=NULL,frozen=0 WHERE retired IS NULL");
@@ -17825,7 +17841,7 @@ var TravelAuthority = class {
17825
17841
  }
17826
17842
  /** Trusted pairing owner binds the first real H to an unused reservation.
17827
17843
  * This does not grant a lease and never rewrites a used seat's history. */
17828
- bindInitialCheckpoint(principal, digest7, buildManifestId) {
17844
+ bindInitialCheckpoint(principal, digest7, buildManifestId, previousDigest) {
17829
17845
  if (!HASH2.test(digest7) || digest7 === "0".repeat(64)) throw new Error("TRAVEL_INITIAL_BASELINE");
17830
17846
  id(buildManifestId);
17831
17847
  const text2 = identityText(principal);
@@ -17834,7 +17850,9 @@ var TravelAuthority = class {
17834
17850
  this.principal(principal);
17835
17851
  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");
17836
17852
  if (row.checkpoint === digest7) return;
17837
- if (row.checkpoint !== "0".repeat(64)) throw new Error("TRAVEL_INITIAL_BASELINE");
17853
+ if (this.db.prepare("SELECT 1 FROM leased_seats WHERE identity=?").get(text2)) throw new Error("TRAVEL_INITIAL_BASELINE");
17854
+ if (previousDigest !== void 0 && (!HASH2.test(previousDigest) || row.checkpoint !== previousDigest)) throw new Error("TRAVEL_INITIAL_BASELINE");
17855
+ if (row.checkpoint !== "0".repeat(64) && previousDigest !== row.checkpoint) throw new Error("TRAVEL_INITIAL_BASELINE");
17838
17856
  this.db.prepare("DELETE FROM checkpoints WHERE identity=?").run(text2);
17839
17857
  this.db.prepare("INSERT INTO checkpoints VALUES(?,?,NULL,1)").run(text2, digest7);
17840
17858
  this.db.prepare("UPDATE seats SET checkpoint=? WHERE identity=?").run(digest7, text2);
@@ -17905,6 +17923,7 @@ var TravelAuthority = class {
17905
17923
  if (row.active_node && ((this.deadlines.get(text2) ?? 0) <= this.monotonicNow() || row.active_boot !== node.boot)) row.epoch++;
17906
17924
  row.active_node = principal.nodeId;
17907
17925
  row.active_boot = String(node.boot);
17926
+ this.db.prepare("INSERT OR IGNORE INTO leased_seats VALUES(?)").run(text2);
17908
17927
  this.db.prepare("UPDATE seats SET epoch=?,active_node=?,active_boot=? WHERE identity=?").run(row.epoch, row.active_node, row.active_boot, text2);
17909
17928
  this.deadlines.set(text2, this.monotonicNow() + this.leaseMs);
17910
17929
  this.healthy.set(text2 + principal.nodeId, this.monotonicNow() + this.leaseMs);