@zq-silk/yui 0.13.9 → 0.13.10

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.
@@ -29,7 +29,7 @@ import { mailboxTargetKey } from "../../coordination/workMailbox.js";
29
29
  import { managedWorkspaceKey } from "../../worktree/managedWorkspace.js";
30
30
  import { SqliteTaskStore } from "../sqliteStore.js";
31
31
  import { readStorageSchemaManifest } from "../storageSchema.js";
32
- import { CURRENT_STORED_TASK_SCHEMA_VERSION } from "../taskStore.js";
32
+ import { CURRENT_STORED_TASK_SCHEMA_VERSION, CURRENT_WORK_MAILBOX_SCHEMA_VERSION } from "../taskStore.js";
33
33
  /** The sidecar database filename used during staging. */
34
34
  export const STAGED_DATABASE_FILENAME = "yui.db.staged";
35
35
  /** The committed database filename. */
@@ -62,7 +62,8 @@ export function readMigrationSourceStateFromSqlite(home) {
62
62
  // Physical migration 14 rewrites the WorkMailbox family while adding its
63
63
  // current columns. Preserve the source rows before applying it so the
64
64
  // logical record migration still sees and transforms v1 exactly once.
65
- const sourceMailboxes = readWorkMailboxesFromSqlite(snapshotPath);
65
+ const sourceManifest = readStorageSchemaManifest(home);
66
+ const sourceMailboxes = readWorkMailboxesFromSqlite(snapshotPath, requireWorkMailboxSchemaVersion(sourceManifest.recordVersions?.workMailbox));
66
67
  const stagedStore = new SqliteTaskStore(home, {
67
68
  databaseFilename: MIGRATION_SOURCE_DATABASE_FILENAME,
68
69
  migration: true
@@ -596,7 +597,7 @@ function hashPayloadTable(db, sql) {
596
597
  const rows = db.prepare(sql).all();
597
598
  return hashRecords(rows.map((row) => JSON.parse(row.payload)));
598
599
  }
599
- export function rowToMailbox(row) {
600
+ export function rowToMailbox(row, schemaVersion) {
600
601
  let target;
601
602
  switch (row.target_kind) {
602
603
  case "operator":
@@ -623,9 +624,9 @@ export function rowToMailbox(row) {
623
624
  processing: row.processing === null ? null : JSON.parse(row.processing),
624
625
  pending: row.pending === null ? null : JSON.parse(row.pending)
625
626
  };
626
- return Object.hasOwn(row, "input_delivery")
627
+ return schemaVersion > 1
627
628
  ? {
628
- schemaVersion: 2,
629
+ schemaVersion,
629
630
  ...common,
630
631
  inputDelivery: row.input_delivery === null
631
632
  ? null
@@ -633,16 +634,22 @@ export function rowToMailbox(row) {
633
634
  }
634
635
  : { schemaVersion: 1, ...common };
635
636
  }
637
+ function requireWorkMailboxSchemaVersion(value) {
638
+ if (value !== 1 && value !== 2 && value !== 3) {
639
+ throw new Error(`WorkMailbox manifest version is invalid: ${String(value)}.`);
640
+ }
641
+ return value;
642
+ }
636
643
  function readWorkMailboxRows(db) {
637
644
  const hasInputDelivery = db.prepare("PRAGMA table_info(mailboxes)").all().some(({ name }) => name === "input_delivery");
638
645
  return db.prepare(`SELECT target_kind, task_id, role_name, next_sequence, processing, pending${hasInputDelivery ? ", input_delivery" : ""} FROM mailboxes ORDER BY target_key`).all();
639
646
  }
640
- function readWorkMailboxesFromSqlite(dbPath) {
647
+ function readWorkMailboxesFromSqlite(dbPath, schemaVersion) {
641
648
  const db = new Database(dbPath, { readonly: true });
642
649
  try {
643
650
  const mailboxes = {};
644
651
  for (const row of readWorkMailboxRows(db)) {
645
- const mailbox = rowToMailbox(row);
652
+ const mailbox = rowToMailbox(row, schemaVersion);
646
653
  mailboxes[mailboxTargetKey(mailbox.target)] = mailbox;
647
654
  }
648
655
  return mailboxes;
@@ -699,7 +706,7 @@ export function computeDbFamilyChecksums(home, databaseFilename) {
699
706
  checksums.publicationReference = hashPayloadTable(db, "SELECT payload FROM publication_references");
700
707
  // Mailboxes are reconstructed from typed columns (no payload column).
701
708
  const mailboxRows = readWorkMailboxRows(db);
702
- checksums.workMailbox = hashRecords(mailboxRows.map(rowToMailbox));
709
+ checksums.workMailbox = hashRecords(mailboxRows.map((row) => rowToMailbox(row, CURRENT_WORK_MAILBOX_SCHEMA_VERSION)));
703
710
  return checksums;
704
711
  }
705
712
  finally {
@@ -756,6 +763,7 @@ export function readStateFromSqlite(home, databaseFilename = COMMITTED_DATABASE_
756
763
  const storedTaskVersion = typeof manifest.recordVersions?.storedTask === "number"
757
764
  ? manifest.recordVersions.storedTask
758
765
  : CURRENT_STORED_TASK_SCHEMA_VERSION;
766
+ const storedWorkMailboxVersion = requireWorkMailboxSchemaVersion(manifest.recordVersions?.workMailbox);
759
767
  // Home identity + revision continuity.
760
768
  const meta = db.prepare("SELECT home_identity, revision FROM home_meta WHERE id = 1").get();
761
769
  const state = {
@@ -880,7 +888,7 @@ export function readStateFromSqlite(home, databaseFilename = COMMITTED_DATABASE_
880
888
  const mailboxRows = readWorkMailboxRows(db);
881
889
  const mailboxes = state.mailboxes;
882
890
  for (const row of mailboxRows) {
883
- const mailbox = rowToMailbox(row);
891
+ const mailbox = rowToMailbox(row, storedWorkMailboxVersion);
884
892
  mailboxes[mailboxTargetKey(mailbox.target)] = mailbox;
885
893
  }
886
894
  return state;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zq-silk/yui",
3
- "version": "0.13.9",
3
+ "version": "0.13.10",
4
4
  "description": "Local control plane for long-running native agent CLI sessions backed by tmux.",
5
5
  "license": "MIT",
6
6
  "private": false,