@prismshadow/penguin-server 0.2.16 → 0.2.17

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.
Files changed (108) hide show
  1. package/README.md +1 -1
  2. package/dist/api/types.d.ts +233 -47
  3. package/dist/api/types.js +9 -3
  4. package/dist/auth-token.js +1 -1
  5. package/dist/{chunk-HMTT2PX4.js → chunk-2LZDP26O.js} +8 -5
  6. package/dist/chunk-2LZDP26O.js.map +1 -0
  7. package/dist/{chunk-LPPVGHYD.js → chunk-BL4U7GYY.js} +2 -2
  8. package/dist/chunk-BL4U7GYY.js.map +1 -0
  9. package/dist/chunk-GGIINEEK.js +3401 -0
  10. package/dist/chunk-GGIINEEK.js.map +1 -0
  11. package/dist/chunk-HDBZRVA5.js +29 -0
  12. package/dist/chunk-HDBZRVA5.js.map +1 -0
  13. package/dist/{chunk-3SFJKLQU.js → chunk-HPOHMZCH.js} +679 -559
  14. package/dist/chunk-HPOHMZCH.js.map +1 -0
  15. package/dist/{chunk-QFV3ERQO.js → chunk-OQZDL3TR.js} +2 -2
  16. package/dist/hmr/manifest.js +1 -1
  17. package/dist/index.js +7701 -4814
  18. package/dist/index.js.map +1 -1
  19. package/dist/machine-status.js +2 -2
  20. package/dist/model-catalog.d.ts +610 -0
  21. package/dist/model-catalog.js +108 -0
  22. package/dist/model-catalog.js.map +1 -0
  23. package/dist/plugin/index.d.ts +113 -58
  24. package/dist/reset-admin-password.js +1 -1
  25. package/dist/version-report.js +2 -2
  26. package/package.json +14 -9
  27. package/web-dist/assets/{abnfDiagram-VCTEODGH-0AKFiyig.js → abnfDiagram-VCTEODGH-DMzkb4l4.js} +1 -1
  28. package/web-dist/assets/{addon-clipboard-BovFnNVg.js → addon-clipboard-BtD2BVSi.js} +1 -1
  29. package/web-dist/assets/{addon-fit-B1npgxQk.js → addon-fit-Dr6HWsi_.js} +1 -1
  30. package/web-dist/assets/{addon-web-links-D88QHj7A.js → addon-web-links-VEE3YLzQ.js} +1 -1
  31. package/web-dist/assets/{arc-Beox1Cgf.js → arc-CvMPOU_B.js} +1 -1
  32. package/web-dist/assets/{architectureDiagram-5GKGNRK7-CC1sLMY1.js → architectureDiagram-5GKGNRK7-Bk65mIBz.js} +1 -1
  33. package/web-dist/assets/{blockDiagram-I7D4REHJ-B8BY1PkZ.js → blockDiagram-I7D4REHJ-D54-XSNs.js} +1 -1
  34. package/web-dist/assets/{c4Diagram-7LVT6UL2-yjY0BkxQ.js → c4Diagram-7LVT6UL2-Dm954LSt.js} +1 -1
  35. package/web-dist/assets/channel-CVHI75kz.js +1 -0
  36. package/web-dist/assets/{chunk-2Q5K7J3B-DdgIvETg.js → chunk-2Q5K7J3B-D_LJ_7Cn.js} +1 -1
  37. package/web-dist/assets/{chunk-5VM5RSS4-BE38k1Rs.js → chunk-5VM5RSS4-B8RI4tl3.js} +1 -1
  38. package/web-dist/assets/{chunk-F27PBJKO-D4YXmaqQ.js → chunk-F27PBJKO-aVSYH9JV.js} +1 -1
  39. package/web-dist/assets/{chunk-IMKFNOWR-CyJFdThc.js → chunk-IMKFNOWR-DnkdWeq2.js} +1 -1
  40. package/web-dist/assets/{chunk-JWPE2WC7-BAM_oEUU.js → chunk-JWPE2WC7-C2pJzKuW.js} +1 -1
  41. package/web-dist/assets/{chunk-POPQ4Y6H-BP3D0FVi.js → chunk-POPQ4Y6H-Bx7Iikzx.js} +1 -1
  42. package/web-dist/assets/{chunk-SVP7TREG-Clk8PdKZ.js → chunk-SVP7TREG-qJC2SMqr.js} +1 -1
  43. package/web-dist/assets/{chunk-TICWLB2K-EvWPnEGg.js → chunk-TICWLB2K-Crl_BgKI.js} +1 -1
  44. package/web-dist/assets/{chunk-XXDRQBXY-6p5D0UB1.js → chunk-XXDRQBXY-BFFemuGm.js} +1 -1
  45. package/web-dist/assets/classDiagram-ZZMXUADV-CBdzAPFu.js +1 -0
  46. package/web-dist/assets/classDiagram-v2-VYDZK3BY-CBdzAPFu.js +1 -0
  47. package/web-dist/assets/{cose-bilkent-JH36ORCC-bpkI-tLJ.js → cose-bilkent-JH36ORCC-Bmh2Kx7h.js} +1 -1
  48. package/web-dist/assets/{cynefin-OW5HDTMX-srLaqJ4e.js → cynefin-OW5HDTMX-BveNWnUV.js} +1 -1
  49. package/web-dist/assets/{cynefinDiagram-5FMLGOSQ-BPfpHSPc.js → cynefinDiagram-5FMLGOSQ-85itazbJ.js} +1 -1
  50. package/web-dist/assets/{dagre-GXQ25YYZ-C4fF5-j7.js → dagre-GXQ25YYZ-DIZT-KY_.js} +1 -1
  51. package/web-dist/assets/{diagram-S7CK7UJ4-BzBLb_9-.js → diagram-S7CK7UJ4-Dum-g63f.js} +1 -1
  52. package/web-dist/assets/{diagram-UQ7AKVKN-BJuJ1o_T.js → diagram-UQ7AKVKN-DallMKJl.js} +1 -1
  53. package/web-dist/assets/{diagram-VSXAHHWV-DFelN9i9.js → diagram-VSXAHHWV-DWELqxfN.js} +1 -1
  54. package/web-dist/assets/{diagram-VX7I27RA-BgrEoPyp.js → diagram-VX7I27RA-BNs0gB9E.js} +1 -1
  55. package/web-dist/assets/{diagram-Z3DM3KII-C71KiMiX.js → diagram-Z3DM3KII-C9mF9xAd.js} +1 -1
  56. package/web-dist/assets/{ebnfDiagram-PWID7BFC-EYteyp1b.js → ebnfDiagram-PWID7BFC-D_Diy9HH.js} +1 -1
  57. package/web-dist/assets/{erDiagram-RLTQ6QDP-B6n6-sz6.js → erDiagram-RLTQ6QDP-4QTS5VIh.js} +1 -1
  58. package/web-dist/assets/{flowDiagram-HODETNUW-BtoMTdyT.js → flowDiagram-HODETNUW-CliTRrtV.js} +1 -1
  59. package/web-dist/assets/{ganttDiagram-EL5Y4UJY-CbOAa3vS.js → ganttDiagram-EL5Y4UJY-DCRd-Ss4.js} +1 -1
  60. package/web-dist/assets/{gitGraphDiagram-WWUBYQGX-B7-8sszH.js → gitGraphDiagram-WWUBYQGX-CTz13GjS.js} +1 -1
  61. package/web-dist/assets/highlighter-BScH1Ud3.js +2 -0
  62. package/web-dist/assets/{highlighter-core-CMXoD8ze.js → highlighter-core-DKz8Z6-I.js} +1 -1
  63. package/web-dist/assets/{highlighter.worker-D6D9fPma.js → highlighter.worker-CKF6ok1g.js} +1 -1
  64. package/web-dist/assets/index-BUvJ5Ctt.js +1299 -0
  65. package/web-dist/assets/index-DRj7nvPY.css +1 -0
  66. package/web-dist/assets/{infoDiagram-27XIBGKW-BBjf6pkP.js → infoDiagram-27XIBGKW-DNfTEPAV.js} +1 -1
  67. package/web-dist/assets/{ishikawaDiagram-5VMMS53U-BBSvCv45.js → ishikawaDiagram-5VMMS53U-B7aCjjG1.js} +1 -1
  68. package/web-dist/assets/{journeyDiagram-3NMN7TZE-CuHHl5zk.js → journeyDiagram-3NMN7TZE-COmDALVr.js} +1 -1
  69. package/web-dist/assets/{kanban-definition-UXKFOSKX-DJyP4Myw.js → kanban-definition-UXKFOSKX-BzUfPINh.js} +1 -1
  70. package/web-dist/assets/{layout-Bqqhdwtt.js → layout-BwzuPU4M.js} +1 -1
  71. package/web-dist/assets/{linear-BZfUSIf8.js → linear-WPZTYjz3.js} +1 -1
  72. package/web-dist/assets/mermaid.core-zKzlwpkw.js +310 -0
  73. package/web-dist/assets/{mindmap-definition-YA3MSWOX-BtyMD4wz.js → mindmap-definition-YA3MSWOX-DCRg7eAx.js} +1 -1
  74. package/web-dist/assets/{pegDiagram-XKGWAZYB-BUF_GJ0B.js → pegDiagram-XKGWAZYB-DyphzDLU.js} +1 -1
  75. package/web-dist/assets/{pieDiagram-E7YTZNPT-nweubbsU.js → pieDiagram-E7YTZNPT-BI5DueGA.js} +1 -1
  76. package/web-dist/assets/powershell-DXrKVo3G.js +1 -0
  77. package/web-dist/assets/powershell-Dpen1YoG.js +1 -0
  78. package/web-dist/assets/{quadrantDiagram-AXDQQJYC-B_r4Wkxy.js → quadrantDiagram-AXDQQJYC-GZxSMY2Z.js} +1 -1
  79. package/web-dist/assets/{railroadDiagram-O6MQD6OU-Dn7nm0MX.js → railroadDiagram-O6MQD6OU-DEFCigBf.js} +1 -1
  80. package/web-dist/assets/{requirementDiagram-BXWQKSXE-DaagYJ49.js → requirementDiagram-BXWQKSXE-Br0thc4j.js} +1 -1
  81. package/web-dist/assets/{sankeyDiagram-P5KCCOFB-CqEX6H-B.js → sankeyDiagram-P5KCCOFB-DYf0pY67.js} +1 -1
  82. package/web-dist/assets/{sequenceDiagram-WJ2MYXX4-BzLfQO55.js → sequenceDiagram-WJ2MYXX4-1EFMboX4.js} +1 -1
  83. package/web-dist/assets/{sizeCapture-INFHLROL-BcUuVH2L.js → sizeCapture-INFHLROL-BuOFv-5q.js} +1 -1
  84. package/web-dist/assets/{stateDiagram-D77RDMKH-BO3LWLvT.js → stateDiagram-D77RDMKH-Bg3H1tjX.js} +1 -1
  85. package/web-dist/assets/stateDiagram-v2-MP3YSRHH-DfaDaPAd.js +1 -0
  86. package/web-dist/assets/{swimlanes-42K2YHIH-etP_hkIB.js → swimlanes-42K2YHIH-BuOa6Osb.js} +1 -1
  87. package/web-dist/assets/swimlanesDiagram-VR7AAH4N-BopAC7b8.js +8 -0
  88. package/web-dist/assets/{timeline-definition-24CTP7MA-CTLt2XCT.js → timeline-definition-24CTP7MA-BDekfdDT.js} +1 -1
  89. package/web-dist/assets/{vennDiagram-4TSXK5OY-DPO6ZSvH.js → vennDiagram-4TSXK5OY-DnC09UI4.js} +1 -1
  90. package/web-dist/assets/{wardleyDiagram-VM6X3IG4-DFofGg8b.js → wardleyDiagram-VM6X3IG4-BXKvxuZQ.js} +1 -1
  91. package/web-dist/assets/{xterm-RdyTuaAH.js → xterm-oY4DYg5s.js} +1 -1
  92. package/web-dist/assets/{xychartDiagram-S5SC5T6Z-Bgtb34Gu.js → xychartDiagram-S5SC5T6Z-DdDC1VLb.js} +1 -1
  93. package/web-dist/index.html +6 -5
  94. package/dist/chunk-3SFJKLQU.js.map +0 -1
  95. package/dist/chunk-HMTT2PX4.js.map +0 -1
  96. package/dist/chunk-LPPVGHYD.js.map +0 -1
  97. package/dist/chunk-W7JNIJ25.js +0 -19
  98. package/dist/chunk-W7JNIJ25.js.map +0 -1
  99. package/web-dist/assets/channel-mfsAVJLE.js +0 -1
  100. package/web-dist/assets/classDiagram-ZZMXUADV-BPVO1m8i.js +0 -1
  101. package/web-dist/assets/classDiagram-v2-VYDZK3BY-BPVO1m8i.js +0 -1
  102. package/web-dist/assets/highlighter-Bj5l2XH_.js +0 -2
  103. package/web-dist/assets/index-BOCqRT4e.css +0 -1
  104. package/web-dist/assets/index-BrMpjp2s.js +0 -1286
  105. package/web-dist/assets/mermaid.core-BlUspEsI.js +0 -310
  106. package/web-dist/assets/stateDiagram-v2-MP3YSRHH-B-EuucjM.js +0 -1
  107. package/web-dist/assets/swimlanesDiagram-VR7AAH4N-0JbFdDbQ.js +0 -8
  108. /package/dist/{chunk-QFV3ERQO.js.map → chunk-OQZDL3TR.js.map} +0 -0
@@ -2,301 +2,372 @@
2
2
  import { mkdirSync } from "fs";
3
3
  import path from "path";
4
4
 
5
- // src/db/migrations.ts
6
- var MIGRATIONS = [
7
- {
8
- version: 1,
9
- name: "messaging-bindings",
10
- // Purely additive: one new table plus three indexes, no column of any existing table
11
- // touched. A platform that rolls back to a predecessor without messaging simply never
12
- // queries them.
13
- swapSafe: true,
14
- up(db) {
15
- db.exec(`
16
- CREATE TABLE IF NOT EXISTS messaging_bindings (
17
- session_id TEXT NOT NULL,
18
- channel TEXT NOT NULL,
19
- account_id TEXT NOT NULL,
20
- config_json TEXT NOT NULL,
21
- enabled INTEGER NOT NULL DEFAULT 0,
22
- line_per_message INTEGER NOT NULL DEFAULT 0,
23
- last_chat_id TEXT,
24
- last_chat_is_direct INTEGER NOT NULL DEFAULT 1,
25
- last_inbound_message_id TEXT,
26
- created_at TEXT NOT NULL,
27
- updated_at TEXT NOT NULL,
28
- PRIMARY KEY (session_id, channel)
29
- );
30
- CREATE INDEX IF NOT EXISTS idx_messaging_by_account ON messaging_bindings(channel, account_id);
31
- CREATE INDEX IF NOT EXISTS idx_auth_sessions_expires ON auth_sessions(expires_at);
32
- CREATE INDEX IF NOT EXISTS idx_auth_sessions_user ON auth_sessions(user_id);
33
- `);
34
- },
35
- // LOSES every messaging binding: the channel credentials, the enabled flag and the
36
- // last-chat memory all live in the table this drops. The auth_sessions indexes are
37
- // derived and cost nothing to lose.
38
- down(db) {
39
- db.exec(`
40
- DROP INDEX IF EXISTS idx_auth_sessions_user;
41
- DROP INDEX IF EXISTS idx_auth_sessions_expires;
42
- DROP INDEX IF EXISTS idx_messaging_by_account;
43
- DROP TABLE IF EXISTS messaging_bindings;
44
- `);
5
+ // src/db/migrations/runner.ts
6
+ var LEDGER_DDL = `
7
+ CREATE TABLE IF NOT EXISTS schema_migrations (
8
+ name TEXT PRIMARY KEY,
9
+ applied_at TEXT NOT NULL
10
+ );
11
+ `;
12
+ function hasLedger(db) {
13
+ return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'schema_migrations'").get() !== void 0;
14
+ }
15
+ function appliedMigrations(db) {
16
+ if (!hasLedger(db)) return [];
17
+ const rows = db.prepare("SELECT name FROM schema_migrations ORDER BY rowid").all();
18
+ return rows.map((r) => r.name);
19
+ }
20
+ function migrate(db, migrations, { swapPath = false } = {}) {
21
+ const adopted = !hasLedger(db);
22
+ const done = new Set(appliedMigrations(db));
23
+ const pending = migrations.filter((m) => !done.has(m.name));
24
+ if (adopted) db.exec(LEDGER_DDL);
25
+ const record = db.prepare("INSERT INTO schema_migrations (name, applied_at) VALUES (?, ?)");
26
+ const applied = [];
27
+ const deferred = [];
28
+ for (const m of pending) {
29
+ if (swapPath && !m.swapSafe) {
30
+ deferred.push(m.name);
31
+ continue;
45
32
  }
46
- },
47
- {
48
- version: 2,
49
- name: "messaging-delivery-flags",
50
- // Two columns with defaults on an existing table: a rollback to a predecessor that
51
- // does not know them leaves them at their defaults and reads nothing.
52
- swapSafe: true,
53
- up(db) {
54
- ensureColumn(db, "messaging_bindings", "final_reply_only", "INTEGER NOT NULL DEFAULT 0");
55
- ensureColumn(db, "messaging_bindings", "render_markdown", "INTEGER NOT NULL DEFAULT 1");
56
- },
57
- // LOSES both delivery preferences on every binding; the bindings themselves survive.
58
- // Dropped in reverse order for symmetry with `up`. Neither column is indexed, which is
59
- // what lets SQLite drop them at all.
60
- down(db) {
61
- db.exec("ALTER TABLE messaging_bindings DROP COLUMN render_markdown");
62
- db.exec("ALTER TABLE messaging_bindings DROP COLUMN final_reply_only");
33
+ db.exec("BEGIN");
34
+ try {
35
+ m.up(db);
36
+ record.run(m.name, (/* @__PURE__ */ new Date()).toISOString());
37
+ db.exec("COMMIT");
38
+ } catch (err) {
39
+ db.exec("ROLLBACK");
40
+ throw new Error(`migration ${m.name} failed: ${String(err)}`, { cause: err });
63
41
  }
42
+ applied.push(m.name);
43
+ }
44
+ return { adopted, applied, deferred };
45
+ }
46
+
47
+ // src/db/migrations/steps/2026-08-31-messaging-bindings.ts
48
+ var messagingBindings = {
49
+ name: "2026-08-31-messaging-bindings",
50
+ // Purely additive: one new table plus three indexes, no column of any existing table
51
+ // touched. A platform that rolls back to a predecessor without messaging simply never
52
+ // queries them.
53
+ swapSafe: true,
54
+ up(db) {
55
+ db.exec(`
56
+ CREATE TABLE IF NOT EXISTS messaging_bindings (
57
+ session_id TEXT NOT NULL,
58
+ channel TEXT NOT NULL,
59
+ account_id TEXT NOT NULL,
60
+ config_json TEXT NOT NULL,
61
+ enabled INTEGER NOT NULL DEFAULT 0,
62
+ line_per_message INTEGER NOT NULL DEFAULT 0,
63
+ last_chat_id TEXT,
64
+ last_chat_is_direct INTEGER NOT NULL DEFAULT 1,
65
+ last_inbound_message_id TEXT,
66
+ created_at TEXT NOT NULL,
67
+ updated_at TEXT NOT NULL,
68
+ PRIMARY KEY (session_id, channel)
69
+ );
70
+ CREATE INDEX IF NOT EXISTS idx_messaging_by_account ON messaging_bindings(channel, account_id);
71
+ CREATE INDEX IF NOT EXISTS idx_auth_sessions_expires ON auth_sessions(expires_at);
72
+ CREATE INDEX IF NOT EXISTS idx_auth_sessions_user ON auth_sessions(user_id);
73
+ `);
64
74
  },
65
- {
66
- version: 3,
67
- name: "drop-goal-state",
68
- // Narrowing: drops a table. A pushed platform rolled back to 0.2.9 mid-process would
69
- // prepare its goal statements against a table that is gone (its declarative track only
70
- // runs at the runtime's own open, never at a platform boot), so this is the first
71
- // restart-only migration: refused on the swap path, applied by the runtime's open.
72
- swapSafe: false,
73
- up(db) {
74
- db.exec(`
75
- DROP INDEX IF EXISTS idx_goal_session;
76
- DROP TABLE IF EXISTS goal_state;
77
- `);
78
- },
79
- // Recreates the table exactly as 0.2.9 declared it — EMPTY. LOSES every goal run ever
80
- // recorded (objective, status, budget, used, rounds per run): the rows only ever fed the
81
- // banner of a finished goal, and a build with this migration reads the goal file instead.
82
- down(db) {
83
- db.exec(`
84
- CREATE TABLE IF NOT EXISTS goal_state (
85
- id INTEGER PRIMARY KEY AUTOINCREMENT,
86
- session_id TEXT NOT NULL,
87
- project_id TEXT NOT NULL,
88
- agent_id TEXT NOT NULL,
89
- objective TEXT NOT NULL,
90
- status TEXT NOT NULL,
91
- budget INTEGER NOT NULL,
92
- used INTEGER NOT NULL DEFAULT 0,
93
- rounds INTEGER NOT NULL DEFAULT 0,
94
- created_at TEXT NOT NULL,
95
- updated_at TEXT NOT NULL
96
- );
97
- CREATE INDEX IF NOT EXISTS idx_goal_session ON goal_state(session_id);
98
- `);
99
- }
75
+ // LOSES every messaging binding: the channel credentials, the enabled flag and the
76
+ // last-chat memory all live in the table this drops. The auth_sessions indexes are
77
+ // derived and cost nothing to lose.
78
+ down(db) {
79
+ db.exec(`
80
+ DROP INDEX IF EXISTS idx_auth_sessions_user;
81
+ DROP INDEX IF EXISTS idx_auth_sessions_expires;
82
+ DROP INDEX IF EXISTS idx_messaging_by_account;
83
+ DROP TABLE IF EXISTS messaging_bindings;
84
+ `);
85
+ }
86
+ };
87
+
88
+ // src/db/migrations/steps/2026-08-31-messaging-delivery-flags.ts
89
+ var messagingDeliveryFlags = {
90
+ name: "2026-08-31-messaging-delivery-flags",
91
+ // Two columns with defaults on an existing table: a rollback to a predecessor that
92
+ // does not know them leaves them at their defaults and reads nothing.
93
+ swapSafe: true,
94
+ up(db) {
95
+ ensureColumn(db, "messaging_bindings", "final_reply_only", "INTEGER NOT NULL DEFAULT 0");
96
+ ensureColumn(db, "messaging_bindings", "render_markdown", "INTEGER NOT NULL DEFAULT 1");
100
97
  },
101
- {
102
- version: 4,
103
- name: "machines",
104
- // Three new tables, nothing existing touched: a platform rolled back to one without
105
- // machines never queries them. Swap-safe on its own; a database still behind
106
- // drop-goal-state is refused whole by that one first, which is the rule.
107
- swapSafe: true,
108
- up(db) {
109
- db.exec(`
110
- CREATE TABLE IF NOT EXISTS machine (
111
- singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
112
- machine_id TEXT NOT NULL
113
- );
114
- CREATE TABLE IF NOT EXISTS machines (
115
- address TEXT PRIMARY KEY,
116
- machine_id TEXT,
117
- version TEXT,
118
- installed_at TEXT,
119
- session_pid INTEGER,
120
- remote_port INTEGER,
121
- platform TEXT
122
- );
123
- CREATE TABLE IF NOT EXISTS machine_project (
124
- project_id TEXT PRIMARY KEY REFERENCES projects(project_id) ON DELETE CASCADE,
125
- addresses TEXT NOT NULL
126
- );
127
- `);
128
- },
129
- // LOSES this server's own machine id (every stored reference to it on other machines
130
- // then points at nothing), what was installed where, the sessions held, and which
131
- // machines each Project used.
132
- down(db) {
133
- db.exec(`
134
- DROP TABLE IF EXISTS machine_project;
135
- DROP TABLE IF EXISTS machines;
136
- DROP TABLE IF EXISTS machine;
137
- `);
138
- }
98
+ // LOSES both delivery preferences on every binding; the bindings themselves survive.
99
+ // Dropped in reverse order for symmetry with `up`. Neither column is indexed, which is
100
+ // what lets SQLite drop them at all.
101
+ down(db) {
102
+ db.exec("ALTER TABLE messaging_bindings DROP COLUMN render_markdown");
103
+ db.exec("ALTER TABLE messaging_bindings DROP COLUMN final_reply_only");
104
+ }
105
+ };
106
+
107
+ // src/db/migrations/steps/2026-09-02-drop-goal-state.ts
108
+ var dropGoalState = {
109
+ name: "2026-09-02-drop-goal-state",
110
+ // CONTRACT: drops a table no build since 0.2.10 reads. A pushed platform rolled back to
111
+ // 0.2.9 mid-process would prepare its goal statements against a table that is gone, so it
112
+ // is left pending on the swap path and applied by the runtime's own open; until then the
113
+ // table just sits there unused.
114
+ swapSafe: false,
115
+ up(db) {
116
+ db.exec(`
117
+ DROP INDEX IF EXISTS idx_goal_session;
118
+ DROP TABLE IF EXISTS goal_state;
119
+ `);
139
120
  },
140
- {
141
- version: 5,
142
- name: "user-profile",
143
- // Two nullable columns on `users`, no default and nothing existing rewritten: a platform
144
- // rolled back to a predecessor that does not know them never selects or writes them, and
145
- // every existing account simply reads NULL — no profile yet.
146
- swapSafe: true,
147
- up(db) {
148
- ensureColumn(db, "users", "display_name", "TEXT");
149
- ensureColumn(db, "users", "avatar", "TEXT");
150
- },
151
- // LOSES every stored nickname and avatar: both live entirely in the two columns this
152
- // drops, and nothing else on disk holds a copy. Dropped in reverse order for symmetry
153
- // with `up`; neither column is indexed, which is what lets SQLite drop them at all.
154
- down(db) {
155
- const cols = db.prepare("PRAGMA table_info(users)").all();
156
- const has = (name) => cols.some((c) => c.name === name);
157
- if (has("avatar")) db.exec("ALTER TABLE users DROP COLUMN avatar");
158
- if (has("display_name")) db.exec("ALTER TABLE users DROP COLUMN display_name");
159
- }
121
+ // Recreates the table exactly as 0.2.9 declared it — EMPTY. LOSES every goal run ever
122
+ // recorded (objective, status, budget, used, rounds per run): the rows only ever fed the
123
+ // banner of a finished goal, and a build with this migration reads the goal file instead.
124
+ down(db) {
125
+ db.exec(`
126
+ CREATE TABLE IF NOT EXISTS goal_state (
127
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
128
+ session_id TEXT NOT NULL,
129
+ project_id TEXT NOT NULL,
130
+ agent_id TEXT NOT NULL,
131
+ objective TEXT NOT NULL,
132
+ status TEXT NOT NULL,
133
+ budget INTEGER NOT NULL,
134
+ used INTEGER NOT NULL DEFAULT 0,
135
+ rounds INTEGER NOT NULL DEFAULT 0,
136
+ created_at TEXT NOT NULL,
137
+ updated_at TEXT NOT NULL
138
+ );
139
+ CREATE INDEX IF NOT EXISTS idx_goal_session ON goal_state(session_id);
140
+ `);
141
+ }
142
+ };
143
+
144
+ // src/db/migrations/steps/2026-09-04-machines.ts
145
+ var machines = {
146
+ name: "2026-09-04-machines",
147
+ // Three new tables, nothing existing touched: a platform rolled back to one without
148
+ // machines never queries them. Swap-safe on its own; a database still behind
149
+ // 2026-09-02-drop-goal-state is refused whole by that one first, which is the rule.
150
+ swapSafe: true,
151
+ up(db) {
152
+ db.exec(`
153
+ CREATE TABLE IF NOT EXISTS machine (
154
+ singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
155
+ machine_id TEXT NOT NULL
156
+ );
157
+ CREATE TABLE IF NOT EXISTS machines (
158
+ address TEXT PRIMARY KEY,
159
+ machine_id TEXT,
160
+ version TEXT,
161
+ installed_at TEXT,
162
+ session_pid INTEGER,
163
+ remote_port INTEGER,
164
+ platform TEXT
165
+ );
166
+ CREATE TABLE IF NOT EXISTS machine_project (
167
+ project_id TEXT PRIMARY KEY REFERENCES projects(project_id) ON DELETE CASCADE,
168
+ addresses TEXT NOT NULL
169
+ );
170
+ `);
160
171
  },
161
- {
162
- version: 6,
163
- name: "company-mode-org-caches",
164
- // Additive: seven new tables for company mode (organizations of Agents), no change to any
165
- // existing table. Every row is either rebuildable from the organization's files (desks.toml,
166
- // the tickets' Sessions headers, the calendar files, usage records) or a user's own read
167
- // cursor; a predecessor build never touches them.
168
- swapSafe: true,
169
- up(db) {
170
- db.exec(`
171
- CREATE TABLE IF NOT EXISTS org_sessions ( -- DERIVED CACHE (company mode): desk sessions, rebuilt from each organization's desks.toml (current + previous); trigger_hop is chat-chain accounting and reads 0 after a rebuild
172
- session_id TEXT PRIMARY KEY,
173
- project_id TEXT NOT NULL,
174
- org_id TEXT NOT NULL,
175
- agent_id TEXT NOT NULL,
176
- current INTEGER NOT NULL DEFAULT 1,
177
- trigger_hop INTEGER NOT NULL DEFAULT 0
178
- );
179
- CREATE INDEX IF NOT EXISTS idx_org_sessions_org ON org_sessions(project_id, org_id);
180
- CREATE TABLE IF NOT EXISTS org_ticket_sessions ( -- DERIVED CACHE (company mode): ticket <-> contributing session, rebuilt from each ticket's Sessions header
181
- project_id TEXT NOT NULL,
182
- org_id TEXT NOT NULL,
183
- ticket_id TEXT NOT NULL,
184
- session_id TEXT NOT NULL,
185
- agent_id TEXT NOT NULL,
186
- trigger_hop INTEGER NOT NULL DEFAULT 0,
187
- PRIMARY KEY (project_id, org_id, ticket_id, session_id)
188
- );
189
- CREATE INDEX IF NOT EXISTS idx_org_ticket_sessions_session ON org_ticket_sessions(session_id);
190
- CREATE TABLE IF NOT EXISTS org_calendar_state ( -- calendar run state (company mode; the files are declarative intent), same rules as schedule_state
191
- project_id TEXT NOT NULL,
192
- org_id TEXT NOT NULL,
193
- agent_id TEXT NOT NULL,
194
- name TEXT NOT NULL,
195
- start_at_ms INTEGER NOT NULL,
196
- def_hash TEXT NOT NULL,
197
- last_slot_ms INTEGER,
198
- last_fired_at TEXT,
199
- fired_once INTEGER NOT NULL DEFAULT 0,
200
- missed INTEGER NOT NULL DEFAULT 0,
201
- invalid_reason TEXT,
202
- last_outcome TEXT,
203
- PRIMARY KEY (project_id, org_id, agent_id, name)
204
- );
205
- CREATE TABLE IF NOT EXISTS org_ticket_state ( -- DERIVED CACHE (company mode): the last (status, owner, blocked) seen per ticket, so a change is notified once; rebuilt silently from the ticket files
206
- project_id TEXT NOT NULL,
207
- org_id TEXT NOT NULL,
208
- ticket_id TEXT NOT NULL,
209
- status TEXT NOT NULL,
210
- owner TEXT NOT NULL DEFAULT '',
211
- blocked TEXT NOT NULL DEFAULT '',
212
- blocked_by TEXT NOT NULL DEFAULT '',
213
- PRIMARY KEY (project_id, org_id, ticket_id)
214
- );
215
- CREATE TABLE IF NOT EXISTS org_chat_state ( -- DERIVED CACHE (company mode): tail-scan byte cursor per chat day file
216
- project_id TEXT NOT NULL,
217
- org_id TEXT NOT NULL,
218
- date TEXT NOT NULL,
219
- offset_bytes INTEGER NOT NULL DEFAULT 0,
220
- PRIMARY KEY (project_id, org_id, date)
221
- );
222
- CREATE TABLE IF NOT EXISTS org_chat_reads ( -- user data (company mode): each user's read cursor in an organization's chat
223
- project_id TEXT NOT NULL,
224
- org_id TEXT NOT NULL,
225
- user_id TEXT NOT NULL,
226
- last_read_id TEXT NOT NULL,
227
- PRIMARY KEY (project_id, org_id, user_id)
228
- );
229
- CREATE TABLE IF NOT EXISTS org_budget_state ( -- DERIVED CACHE (company mode): warn / pause marks per employee and period, recomputed from usage and the chart's budgets
230
- project_id TEXT NOT NULL,
231
- org_id TEXT NOT NULL,
232
- agent_id TEXT NOT NULL,
233
- period TEXT NOT NULL,
234
- warned_at TEXT,
235
- paused_at TEXT,
236
- PRIMARY KEY (project_id, org_id, agent_id, period)
237
- );
238
- `);
239
- },
240
- // Drops the seven tables. LOSES: chat read cursors (each user's "read up to here" marks) and
241
- // the run marks that stop a calendar slot, a ticket change or a budget alert from firing
242
- // twice — a build with this migration re-registers everything from the files, without
243
- // backfilling missed slots, and users see every chat message as unread once.
244
- down(db) {
245
- db.exec(`
246
- DROP INDEX IF EXISTS idx_org_ticket_sessions_session;
247
- DROP INDEX IF EXISTS idx_org_sessions_org;
248
- DROP TABLE IF EXISTS org_budget_state;
249
- DROP TABLE IF EXISTS org_chat_reads;
250
- DROP TABLE IF EXISTS org_chat_state;
251
- DROP TABLE IF EXISTS org_ticket_state;
252
- DROP TABLE IF EXISTS org_calendar_state;
253
- DROP TABLE IF EXISTS org_ticket_sessions;
254
- DROP TABLE IF EXISTS org_sessions;
255
- `);
256
- }
172
+ // LOSES this server's own machine id (every stored reference to it on other machines
173
+ // then points at nothing), what was installed where, the sessions held, and which
174
+ // machines each Project used.
175
+ down(db) {
176
+ db.exec(`
177
+ DROP TABLE IF EXISTS machine_project;
178
+ DROP TABLE IF EXISTS machines;
179
+ DROP TABLE IF EXISTS machine;
180
+ `);
181
+ }
182
+ };
183
+
184
+ // src/db/migrations/steps/2026-09-14-user-profile.ts
185
+ var userProfile = {
186
+ name: "2026-09-14-user-profile",
187
+ // Two nullable columns on `users`, no default and nothing existing rewritten: a platform
188
+ // rolled back to a predecessor that does not know them never selects or writes them, and
189
+ // every existing account simply reads NULL — no profile yet.
190
+ swapSafe: true,
191
+ up(db) {
192
+ ensureColumn(db, "users", "display_name", "TEXT");
193
+ ensureColumn(db, "users", "avatar", "TEXT");
257
194
  },
258
- {
259
- version: 7,
260
- name: "company-mode-channels",
261
- // The organization's single group chat became channels: a message lives in
262
- // `channels/<channel_id>/<date>.jsonl`, so the tail-scan cursor and each user's read
263
- // cursor are per channel. `org_chat_state` / `org_chat_reads` are dropped for
264
- // `org_channel_state` / `org_channel_reads`: the tables are renamed and the channel
265
- // belongs in the primary key, neither of which SQLite does in place. Nothing is carried
266
- // over: company mode is unreleased, and every row was either rebuildable from the files
267
- // (the scan cursor) or one pass of "everything looks unread" (the read cursor). A
268
- // predecessor build reads neither table's shape, only its own writes, so this is
269
- // swap-safe.
270
- swapSafe: true,
271
- up(db) {
272
- db.exec(`
273
- DROP TABLE IF EXISTS org_chat_state;
274
- DROP TABLE IF EXISTS org_chat_reads;
275
- CREATE TABLE IF NOT EXISTS org_channel_state ( -- DERIVED CACHE (company mode): tail-scan byte cursor per channel and day file
276
- project_id TEXT NOT NULL,
277
- org_id TEXT NOT NULL,
278
- channel_id TEXT NOT NULL,
279
- date TEXT NOT NULL,
280
- offset_bytes INTEGER NOT NULL DEFAULT 0,
281
- PRIMARY KEY (project_id, org_id, channel_id, date)
282
- );
283
- CREATE TABLE IF NOT EXISTS org_channel_reads ( -- user data (company mode): each user's read cursor in one channel
284
- project_id TEXT NOT NULL,
285
- org_id TEXT NOT NULL,
286
- channel_id TEXT NOT NULL,
287
- user_id TEXT NOT NULL,
288
- last_read_id TEXT NOT NULL,
289
- PRIMARY KEY (project_id, org_id, channel_id, user_id)
290
- );
291
- `);
292
- },
293
- // Recreates the two tables under their old names, exactly as migration 6 declared them —
294
- // EMPTY. LOSES every scan cursor (re-derived by the next pass, which republishes the
295
- // messages it re-reads) and every read cursor (users see the recent days as unread once).
296
- down(db) {
195
+ // LOSES every stored nickname and avatar: both live entirely in the two columns this
196
+ // drops, and nothing else on disk holds a copy. Dropped in reverse order for symmetry
197
+ // with `up`; neither column is indexed, which is what lets SQLite drop them at all.
198
+ down(db) {
199
+ const cols = db.prepare("PRAGMA table_info(users)").all();
200
+ const has = (name) => cols.some((c) => c.name === name);
201
+ if (has("avatar")) db.exec("ALTER TABLE users DROP COLUMN avatar");
202
+ if (has("display_name")) db.exec("ALTER TABLE users DROP COLUMN display_name");
203
+ }
204
+ };
205
+
206
+ // src/db/migrations/steps/2026-09-16-company-mode-channels.ts
207
+ var companyModeChannels = {
208
+ name: "2026-09-16-company-mode-channels",
209
+ // The organization's single group chat became channels: a message lives in
210
+ // `channels/<channel_id>/<date>.jsonl`, so the tail-scan cursor and each user's read
211
+ // cursor are per channel. `org_chat_state` / `org_chat_reads` are dropped for
212
+ // `org_channel_state` / `org_channel_reads`: the tables are renamed and the channel
213
+ // belongs in the primary key, neither of which SQLite does in place. Nothing is carried
214
+ // over: company mode is unreleased, and every row was either rebuildable from the files
215
+ // (the scan cursor) or one pass of "everything looks unread" (the read cursor). A
216
+ // predecessor build reads neither table's shape, only its own writes, so this is
217
+ // swap-safe.
218
+ //
219
+ // By the expand / contract rule (migration.ts) the two DROPs are a contract, and this is the
220
+ // one expand that removes anything on the swap path. It stays an expand because it is frozen
221
+ // and cannot be deferred: the same step creates the channel tables a pushed platform needs.
222
+ // A new change of this kind is split into an expand and a later contract instead.
223
+ swapSafe: true,
224
+ up(db) {
225
+ db.exec(`
226
+ DROP TABLE IF EXISTS org_chat_state;
227
+ DROP TABLE IF EXISTS org_chat_reads;
228
+ CREATE TABLE IF NOT EXISTS org_channel_state ( -- DERIVED CACHE (company mode): tail-scan byte cursor per channel and day file
229
+ project_id TEXT NOT NULL,
230
+ org_id TEXT NOT NULL,
231
+ channel_id TEXT NOT NULL,
232
+ date TEXT NOT NULL,
233
+ offset_bytes INTEGER NOT NULL DEFAULT 0,
234
+ PRIMARY KEY (project_id, org_id, channel_id, date)
235
+ );
236
+ CREATE TABLE IF NOT EXISTS org_channel_reads ( -- user data (company mode): each user's read cursor in one channel
237
+ project_id TEXT NOT NULL,
238
+ org_id TEXT NOT NULL,
239
+ channel_id TEXT NOT NULL,
240
+ user_id TEXT NOT NULL,
241
+ last_read_id TEXT NOT NULL,
242
+ PRIMARY KEY (project_id, org_id, channel_id, user_id)
243
+ );
244
+ `);
245
+ },
246
+ // Recreates the two tables under their old names, exactly as 2026-09-16-company-mode-org-caches declared them —
247
+ // EMPTY. LOSES every scan cursor (re-derived by the next pass, which republishes the
248
+ // messages it re-reads) and every read cursor (users see the recent days as unread once).
249
+ down(db) {
250
+ db.exec(`
251
+ DROP TABLE IF EXISTS org_channel_state;
252
+ DROP TABLE IF EXISTS org_channel_reads;
253
+ CREATE TABLE IF NOT EXISTS org_chat_state ( -- DERIVED CACHE (company mode): tail-scan byte cursor per chat day file
254
+ project_id TEXT NOT NULL,
255
+ org_id TEXT NOT NULL,
256
+ date TEXT NOT NULL,
257
+ offset_bytes INTEGER NOT NULL DEFAULT 0,
258
+ PRIMARY KEY (project_id, org_id, date)
259
+ );
260
+ CREATE TABLE IF NOT EXISTS org_chat_reads ( -- user data (company mode): each user's read cursor in an organization's chat
261
+ project_id TEXT NOT NULL,
262
+ org_id TEXT NOT NULL,
263
+ user_id TEXT NOT NULL,
264
+ last_read_id TEXT NOT NULL,
265
+ PRIMARY KEY (project_id, org_id, user_id)
266
+ );
267
+ `);
268
+ }
269
+ };
270
+
271
+ // src/db/migrations/steps/2026-09-16-company-mode-desk-notices.ts
272
+ var companyModeDeskNotices = {
273
+ name: "2026-09-16-company-mode-desk-notices",
274
+ // Additive: one new table and its index. A ticket change no longer starts a work run at
275
+ // the owner's desk; it is queued here and delivered inside the body of that employee's
276
+ // next calendar sweep. A predecessor build never reads the table, so a rollback survives
277
+ // it — with whatever rows are in it left undelivered.
278
+ swapSafe: true,
279
+ up(db) {
280
+ db.exec(`
281
+ CREATE TABLE IF NOT EXISTS org_desk_notices ( -- DERIVED CACHE (company mode): ticket changes waiting for an employee's next calendar sweep; dropping it loses only the digests not delivered yet
282
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
283
+ project_id TEXT NOT NULL,
284
+ org_id TEXT NOT NULL,
285
+ agent_id TEXT NOT NULL,
286
+ ticket_id TEXT NOT NULL,
287
+ change TEXT NOT NULL,
288
+ at TEXT NOT NULL
289
+ );
290
+ CREATE INDEX IF NOT EXISTS idx_org_desk_notices_agent ON org_desk_notices(project_id, org_id, agent_id);
291
+ `);
292
+ },
293
+ // LOSES every queued notice: the ticket changes an employee has not been told about yet.
294
+ // The change itself is in the ticket file and its history either way; what
295
+ // goes is the "Since your last sweep" line that would have named it.
296
+ down(db) {
297
+ db.exec(`
298
+ DROP INDEX IF EXISTS idx_org_desk_notices_agent;
299
+ DROP TABLE IF EXISTS org_desk_notices;
300
+ `);
301
+ }
302
+ };
303
+
304
+ // src/db/migrations/steps/2026-09-16-company-mode-org-caches.ts
305
+ var companyModeOrgCaches = {
306
+ name: "2026-09-16-company-mode-org-caches",
307
+ // Additive: seven new tables for company mode (organizations of Agents), no change to any
308
+ // existing table. Every row is either rebuildable from the organization's files (desks.toml,
309
+ // the tickets' Sessions headers, the calendar files, usage records) or a user's own read
310
+ // cursor; a predecessor build never touches them.
311
+ swapSafe: true,
312
+ up(db) {
313
+ db.exec(`
314
+ CREATE TABLE IF NOT EXISTS org_sessions ( -- DERIVED CACHE (company mode): desk sessions, rebuilt from each organization's desks.toml (current + previous); trigger_hop is chat-chain accounting and reads 0 after a rebuild
315
+ session_id TEXT PRIMARY KEY,
316
+ project_id TEXT NOT NULL,
317
+ org_id TEXT NOT NULL,
318
+ agent_id TEXT NOT NULL,
319
+ current INTEGER NOT NULL DEFAULT 1,
320
+ trigger_hop INTEGER NOT NULL DEFAULT 0
321
+ );
322
+ CREATE INDEX IF NOT EXISTS idx_org_sessions_org ON org_sessions(project_id, org_id);
323
+ CREATE TABLE IF NOT EXISTS org_ticket_sessions ( -- DERIVED CACHE (company mode): ticket <-> contributing session, rebuilt from each ticket's Sessions header
324
+ project_id TEXT NOT NULL,
325
+ org_id TEXT NOT NULL,
326
+ ticket_id TEXT NOT NULL,
327
+ session_id TEXT NOT NULL,
328
+ agent_id TEXT NOT NULL,
329
+ trigger_hop INTEGER NOT NULL DEFAULT 0,
330
+ PRIMARY KEY (project_id, org_id, ticket_id, session_id)
331
+ );
332
+ CREATE INDEX IF NOT EXISTS idx_org_ticket_sessions_session ON org_ticket_sessions(session_id);
333
+ CREATE TABLE IF NOT EXISTS org_calendar_state ( -- calendar run state (company mode; the files are declarative intent), same rules as schedule_state
334
+ project_id TEXT NOT NULL,
335
+ org_id TEXT NOT NULL,
336
+ agent_id TEXT NOT NULL,
337
+ name TEXT NOT NULL,
338
+ start_at_ms INTEGER NOT NULL,
339
+ def_hash TEXT NOT NULL,
340
+ last_slot_ms INTEGER,
341
+ last_fired_at TEXT,
342
+ fired_once INTEGER NOT NULL DEFAULT 0,
343
+ missed INTEGER NOT NULL DEFAULT 0,
344
+ invalid_reason TEXT,
345
+ last_outcome TEXT,
346
+ PRIMARY KEY (project_id, org_id, agent_id, name)
347
+ );
348
+ CREATE TABLE IF NOT EXISTS org_ticket_state ( -- DERIVED CACHE (company mode): the last (status, owner, blocked) seen per ticket, so a change is notified once; rebuilt silently from the ticket files
349
+ project_id TEXT NOT NULL,
350
+ org_id TEXT NOT NULL,
351
+ ticket_id TEXT NOT NULL,
352
+ status TEXT NOT NULL,
353
+ owner TEXT NOT NULL DEFAULT '',
354
+ blocked TEXT NOT NULL DEFAULT '',
355
+ blocked_by TEXT NOT NULL DEFAULT '',
356
+ PRIMARY KEY (project_id, org_id, ticket_id)
357
+ );
358
+ CREATE TABLE IF NOT EXISTS org_budget_state ( -- DERIVED CACHE (company mode): warn / pause marks per employee and period, recomputed from usage and the chart's budgets
359
+ project_id TEXT NOT NULL,
360
+ org_id TEXT NOT NULL,
361
+ agent_id TEXT NOT NULL,
362
+ period TEXT NOT NULL,
363
+ warned_at TEXT,
364
+ paused_at TEXT,
365
+ PRIMARY KEY (project_id, org_id, agent_id, period)
366
+ );
367
+ `);
368
+ const superseded = db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'org_channel_state'").get() !== void 0;
369
+ if (!superseded) {
297
370
  db.exec(`
298
- DROP TABLE IF EXISTS org_channel_state;
299
- DROP TABLE IF EXISTS org_channel_reads;
300
371
  CREATE TABLE IF NOT EXISTS org_chat_state ( -- DERIVED CACHE (company mode): tail-scan byte cursor per chat day file
301
372
  project_id TEXT NOT NULL,
302
373
  org_id TEXT NOT NULL,
@@ -304,7 +375,7 @@ var MIGRATIONS = [
304
375
  offset_bytes INTEGER NOT NULL DEFAULT 0,
305
376
  PRIMARY KEY (project_id, org_id, date)
306
377
  );
307
- CREATE TABLE IF NOT EXISTS org_chat_reads ( -- user data (company mode): each user's read cursor in an organization's chat
378
+ CREATE TABLE IF NOT EXISTS org_chat_reads ( -- user data (company mode): each user's read cursor in an organization's chat
308
379
  project_id TEXT NOT NULL,
309
380
  org_id TEXT NOT NULL,
310
381
  user_id TEXT NOT NULL,
@@ -314,168 +385,203 @@ var MIGRATIONS = [
314
385
  `);
315
386
  }
316
387
  },
317
- {
318
- version: 8,
319
- name: "company-mode-desk-notices",
320
- // Additive: one new table and its index. A ticket change no longer starts a work run at
321
- // the owner's desk; it is queued here and delivered inside the body of that employee's
322
- // next calendar sweep. A predecessor build never reads the table, so a rollback survives
323
- // it — with whatever rows are in it left undelivered.
324
- swapSafe: true,
325
- up(db) {
326
- db.exec(`
327
- CREATE TABLE IF NOT EXISTS org_desk_notices ( -- DERIVED CACHE (company mode): ticket changes waiting for an employee's next calendar sweep; dropping it loses only the digests not delivered yet
328
- seq INTEGER PRIMARY KEY AUTOINCREMENT,
329
- project_id TEXT NOT NULL,
330
- org_id TEXT NOT NULL,
331
- agent_id TEXT NOT NULL,
332
- ticket_id TEXT NOT NULL,
333
- change TEXT NOT NULL,
334
- at TEXT NOT NULL
335
- );
336
- CREATE INDEX IF NOT EXISTS idx_org_desk_notices_agent ON org_desk_notices(project_id, org_id, agent_id);
337
- `);
338
- },
339
- // LOSES every queued notice: the ticket changes an employee has not been told about yet.
340
- // The change itself is in the ticket file and its history either way; what
341
- // goes is the "Since your last sweep" line that would have named it.
342
- down(db) {
343
- db.exec(`
344
- DROP INDEX IF EXISTS idx_org_desk_notices_agent;
345
- DROP TABLE IF EXISTS org_desk_notices;
346
- `);
347
- }
388
+ // Drops the seven tables. LOSES: chat read cursors (each user's "read up to here" marks) and
389
+ // the run marks that stop a calendar slot, a ticket change or a budget alert from firing
390
+ // twice — a build with this migration re-registers everything from the files, without
391
+ // backfilling missed slots, and users see every chat message as unread once.
392
+ down(db) {
393
+ db.exec(`
394
+ DROP INDEX IF EXISTS idx_org_ticket_sessions_session;
395
+ DROP INDEX IF EXISTS idx_org_sessions_org;
396
+ DROP TABLE IF EXISTS org_budget_state;
397
+ DROP TABLE IF EXISTS org_chat_reads;
398
+ DROP TABLE IF EXISTS org_chat_state;
399
+ DROP TABLE IF EXISTS org_ticket_state;
400
+ DROP TABLE IF EXISTS org_calendar_state;
401
+ DROP TABLE IF EXISTS org_ticket_sessions;
402
+ DROP TABLE IF EXISTS org_sessions;
403
+ `);
404
+ }
405
+ };
406
+
407
+ // src/db/migrations/steps/2026-09-17-model-promotions.ts
408
+ var modelPromotions = {
409
+ name: "2026-09-17-model-promotions",
410
+ // Additive: one new table, nothing existing touched. A predecessor build never reads it
411
+ // and prices every row at the number in its Project file, so a rollback survives it.
412
+ swapSafe: true,
413
+ up(db) {
414
+ db.exec(`
415
+ CREATE TABLE IF NOT EXISTS model_promotions ( -- NOT a cache rebuildable from files: the only record of a Project row's running promotion (.project_config.toml keeps the list price), written by preset seeding at Project creation, "sync presets" and Penguin Go authorization / sync, and read by cost; lost rows price usage at list until the next sync writes them back
416
+ project_id TEXT NOT NULL REFERENCES projects(project_id) ON DELETE CASCADE,
417
+ provider TEXT NOT NULL,
418
+ model_id TEXT NOT NULL,
419
+ discount REAL NOT NULL CHECK (discount > 0 AND discount < 1),
420
+ updated_at TEXT NOT NULL,
421
+ PRIMARY KEY (project_id, provider, model_id)
422
+ );
423
+ `);
348
424
  },
349
- {
350
- version: 9,
351
- name: "model-promotions",
352
- // Additive: one new table, nothing existing touched. A predecessor build never reads it
353
- // and prices every row at the number in its Project file, so a rollback survives it.
354
- swapSafe: true,
355
- up(db) {
356
- db.exec(`
357
- CREATE TABLE IF NOT EXISTS model_promotions ( -- NOT a cache rebuildable from files: the only record of a Project row's running promotion (.project_config.toml keeps the list price), written by preset seeding at Project creation, "sync presets" and Penguin Go authorization / sync, and read by cost; lost rows price usage at list until the next sync writes them back
358
- project_id TEXT NOT NULL REFERENCES projects(project_id) ON DELETE CASCADE,
359
- provider TEXT NOT NULL,
360
- model_id TEXT NOT NULL,
361
- discount REAL NOT NULL CHECK (discount > 0 AND discount < 1),
362
- updated_at TEXT NOT NULL,
363
- PRIMARY KEY (project_id, provider, model_id)
364
- );
365
- `);
366
- },
367
- // LOSES every stored promotion: no file holds a copy of the fractions, so usage is priced
368
- // at the Project files' list prices until the next "sync presets" or Penguin Go sync
369
- // writes them back.
370
- down(db) {
371
- db.exec("DROP TABLE IF EXISTS model_promotions");
372
- }
425
+ // LOSES every stored promotion: no file holds a copy of the fractions, so usage is priced
426
+ // at the Project files' list prices until the next "sync presets" or Penguin Go sync
427
+ // writes them back.
428
+ down(db) {
429
+ db.exec("DROP TABLE IF EXISTS model_promotions");
430
+ }
431
+ };
432
+
433
+ // src/db/migrations/steps/2026-09-21-model-provider-auth-tokens.ts
434
+ var modelProviderAuthTokens = {
435
+ name: "2026-09-21-model-provider-auth-tokens",
436
+ // Additive: one new table, nothing existing touched. A predecessor build never reads it;
437
+ // the access token already written into .project_config.toml keeps working until it
438
+ // expires, so rollback only loses silent refresh state.
439
+ // KEEP until every supported upgrade starts from a database that already has this table.
440
+ // The release that raises the minimum database baseline past it owns removing this
441
+ // migration and its fixture; the table itself remains while provider token refresh uses it.
442
+ swapSafe: true,
443
+ up(db) {
444
+ db.exec(`
445
+ CREATE TABLE IF NOT EXISTS model_provider_auth_tokens ( -- Server-side OAuth refresh metadata for provider groups. The current request token remains in .project_config.toml as api_key; this table holds only the refresh material that must never be returned to the frontend or written into Project files.
446
+ project_id TEXT NOT NULL REFERENCES projects(project_id) ON DELETE CASCADE,
447
+ provider TEXT NOT NULL,
448
+ refresh_token TEXT NOT NULL,
449
+ access_token_expires_at TEXT,
450
+ updated_at TEXT NOT NULL,
451
+ PRIMARY KEY (project_id, provider)
452
+ );
453
+ `);
373
454
  },
374
- {
375
- version: 10,
376
- name: "model-provider-auth-tokens",
377
- // Additive: one new table, nothing existing touched. A predecessor build never reads it;
378
- // the access token already written into .project_config.toml keeps working until it
379
- // expires, so rollback only loses silent refresh state.
380
- // KEEP until every supported upgrade starts from schema 10 or newer. The release that
381
- // raises the minimum database baseline past 9 owns removing this migration block and its
382
- // version-9 fixture; the table itself remains while provider token refresh uses it.
383
- swapSafe: true,
384
- up(db) {
385
- db.exec(`
386
- CREATE TABLE IF NOT EXISTS model_provider_auth_tokens ( -- Server-side OAuth refresh metadata for provider groups. The current request token remains in .project_config.toml as api_key; this table holds only the refresh material that must never be returned to the frontend or written into Project files.
387
- project_id TEXT NOT NULL REFERENCES projects(project_id) ON DELETE CASCADE,
388
- provider TEXT NOT NULL,
389
- refresh_token TEXT NOT NULL,
390
- access_token_expires_at TEXT,
391
- updated_at TEXT NOT NULL,
392
- PRIMARY KEY (project_id, provider)
393
- );
394
- `);
395
- },
396
- // LOSES every stored refresh token and access-token expiry. Existing access tokens in
397
- // Project files remain until they expire; users re-authorize to restore silent refresh.
398
- down(db) {
399
- db.exec("DROP TABLE IF EXISTS model_provider_auth_tokens");
400
- }
455
+ // LOSES every stored refresh token and access-token expiry. Existing access tokens in
456
+ // Project files remain until they expire; users re-authorize to restore silent refresh.
457
+ down(db) {
458
+ db.exec("DROP TABLE IF EXISTS model_provider_auth_tokens");
459
+ }
460
+ };
461
+
462
+ // src/db/migrations/steps/2026-09-22-sessions-sandbox.ts
463
+ var sessionsSandbox = {
464
+ name: "2026-09-22-sessions-sandbox",
465
+ // The Session's own sandbox policy (JSON), snapshotted from the server's settings when
466
+ // the Session is created, so a later settings change leaves running Sessions alone.
467
+ // NULL = a row from before this column: it takes the settings in force at its next
468
+ // command and keeps them from then on. Swap-safe: a pushed platform boots against the
469
+ // runtime's already-open database, so the column has to arrive by a migration.
470
+ swapSafe: true,
471
+ up(db) {
472
+ ensureColumn(db, "sessions", "sandbox", "TEXT");
401
473
  },
402
- {
403
- version: 11,
404
- name: "sessions-sandbox",
405
- // The Session's own sandbox policy (JSON), snapshotted from the server's settings when
406
- // the Session is created, so a later settings change leaves running Sessions alone.
407
- // NULL = a row from before this column: it takes the settings in force at its next
408
- // command and keeps them from then on. Swap-safe: a pushed platform boots against the
409
- // runtime's already-open database, so the column has to arrive by a migration.
410
- swapSafe: true,
411
- up(db) {
412
- ensureColumn(db, "sessions", "sandbox", "TEXT");
413
- },
414
- // Not a DROP: schema.ts declares the column, and dropping it would put every Session
415
- // back under whatever the settings say.
416
- down() {
417
- }
474
+ // Not a DROP: schema.ts declares the column, and dropping it would put every Session
475
+ // back under whatever the settings say.
476
+ down() {
477
+ }
478
+ };
479
+
480
+ // src/db/migrations/steps/2026-09-23-machines-columns.ts
481
+ var machinesColumns = {
482
+ name: "2026-09-23-machines-columns",
483
+ // A machines table can predate `machines` — a data root that ran the machines line
484
+ // before it was released kept forwards, not sessions — and that migration's IF NOT
485
+ // EXISTS adopted it whatever its columns were, so the first connect failed on the row's
486
+ // insert. Adds what is missing, nullable; a platform rolled back to `machines` declared these
487
+ // columns itself, so there is nothing for it to mind.
488
+ swapSafe: true,
489
+ up(db) {
490
+ ensureColumn(db, "machines", "session_pid", "INTEGER");
491
+ ensureColumn(db, "machines", "platform", "TEXT");
418
492
  },
419
- {
420
- version: 12,
421
- name: "machines-columns",
422
- // A machines table can predate migration 4 — a data root that ran the machines line
423
- // before it was released kept forwards, not sessions — and that migration's IF NOT
424
- // EXISTS adopted it whatever its columns were, so the first connect failed on the row's
425
- // insert. Adds what is missing, nullable; a platform rolled back to 4 declared these
426
- // columns itself, so there is nothing for it to mind.
427
- swapSafe: true,
428
- up(db) {
429
- ensureColumn(db, "machines", "session_pid", "INTEGER");
430
- ensureColumn(db, "machines", "platform", "TEXT");
431
- },
432
- // Nothing to undo: what this added, 4 already declares, and a column it found in place
433
- // was never this migration's to take away.
434
- down() {
435
- }
493
+ // Nothing to undo: what this added, `machines` already declares, and a column it found in place
494
+ // was never this migration's to take away.
495
+ down() {
496
+ }
497
+ };
498
+
499
+ // src/db/migrations/steps/2026-09-23-model-tables-adoption.ts
500
+ var modelTablesAdoption = {
501
+ name: "2026-09-23-model-tables-adoption",
502
+ // A data root that ran the chain before it was restacked onto main (2026-09-23) is
503
+ // stamped 16 under THAT line's numbering, where 9 and 10 were 2026-09-22-sessions-sandbox and
504
+ // 2026-09-23-machines-columns. This line numbers main's 2026-09-17-model-promotions and
505
+ // 2026-09-21-model-provider-auth-tokens 9 and 10 and everything after them two higher, so such a
506
+ // root reads both as already applied, reaches 18 without `model_promotions` or
507
+ // `model_provider_auth_tokens`, and answers 500 wherever cost or provider auth reads
508
+ // them (the models page, an organization's overview). Seen on the release instance at
509
+ // the first push of the restacked line.
510
+ //
511
+ // Re-runs 9's and 10's own `up` — the frozen DDL, both `IF NOT EXISTS`, so a root that
512
+ // took them in their proper place finds its work done. The ledger ended the numbering
513
+ // hazard: adopting a numbered root runs 2026-09-17-model-promotions and 2026-09-21-model-provider-auth-tokens
514
+ // themselves. Remove together with the ledger's adoption of numbered roots (index.ts).
515
+ swapSafe: true,
516
+ up(db) {
517
+ db.exec(`
518
+ CREATE TABLE IF NOT EXISTS model_promotions (
519
+ project_id TEXT NOT NULL REFERENCES projects(project_id) ON DELETE CASCADE,
520
+ provider TEXT NOT NULL,
521
+ model_id TEXT NOT NULL,
522
+ discount REAL NOT NULL CHECK (discount > 0 AND discount < 1),
523
+ updated_at TEXT NOT NULL,
524
+ PRIMARY KEY (project_id, provider, model_id)
525
+ );
526
+ CREATE TABLE IF NOT EXISTS model_provider_auth_tokens (
527
+ project_id TEXT NOT NULL REFERENCES projects(project_id) ON DELETE CASCADE,
528
+ provider TEXT NOT NULL,
529
+ refresh_token TEXT NOT NULL,
530
+ access_token_expires_at TEXT,
531
+ updated_at TEXT NOT NULL,
532
+ PRIMARY KEY (project_id, provider)
533
+ );
534
+ `);
436
535
  },
437
- {
438
- version: 13,
439
- name: "browser-extensions",
440
- // Additive: one new table and its index. The Chrome backend's pairings — one row per
441
- // PenguinHarness Browser extension a user paired, its token stored hashed. A predecessor
442
- // build never reads the table, so a rollback survives it; the paired extensions then simply
443
- // fail to connect until a build that knows them is back.
444
- swapSafe: true,
445
- up(db) {
446
- db.exec(`
447
- CREATE TABLE IF NOT EXISTS browser_extensions ( -- one row per Chrome paired to a user (builtin-browser/extension-pairing.ts): the PenguinHarness Browser extension's long-lived credential, stored only hashed; NOT rebuildable \u2014 a lost row means pairing that Chrome again
448
- extension_id TEXT PRIMARY KEY,
449
- user_id TEXT NOT NULL REFERENCES users(user_id) ON DELETE CASCADE,
450
- token_hash TEXT NOT NULL UNIQUE,
451
- name TEXT NOT NULL,
452
- version TEXT NOT NULL,
453
- created_at TEXT NOT NULL,
454
- last_seen_at TEXT,
455
- revoked_at TEXT
456
- );
457
- CREATE INDEX IF NOT EXISTS idx_browser_extensions_user ON browser_extensions(user_id);
458
- `);
459
- },
460
- // LOSES every pairing: each user's Chrome has to be paired again (a new code from the
461
- // Browser panel) before agents can drive it.
462
- down(db) {
463
- db.exec(`
464
- DROP INDEX IF EXISTS idx_browser_extensions_user;
465
- DROP TABLE IF EXISTS browser_extensions;
466
- `);
467
- }
536
+ // Nothing to undo: the tables are 2026-09-17-model-promotions' and 2026-09-21-model-provider-auth-tokens', and
537
+ // their own downs drop them.
538
+ down() {
539
+ }
540
+ };
541
+
542
+ // src/db/migrations/steps/2026-10-04-browser-extensions.ts
543
+ var browserExtensions = {
544
+ name: "2026-10-04-browser-extensions",
545
+ // Additive: one new table and its index. The Chrome backend's pairings — one row per
546
+ // PenguinHarness Browser extension a user paired, its token stored hashed. A predecessor
547
+ // build never reads the table, so a rollback survives it; the paired extensions then simply
548
+ // fail to connect until a build that knows them is back.
549
+ swapSafe: true,
550
+ up(db) {
551
+ db.exec(`
552
+ CREATE TABLE IF NOT EXISTS browser_extensions ( -- one row per Chrome paired to a user (builtin-browser/extension-pairing.ts): the PenguinHarness Browser extension's long-lived credential, stored only hashed; NOT rebuildable \u2014 a lost row means pairing that Chrome again
553
+ extension_id TEXT PRIMARY KEY,
554
+ user_id TEXT NOT NULL REFERENCES users(user_id) ON DELETE CASCADE,
555
+ token_hash TEXT NOT NULL UNIQUE,
556
+ name TEXT NOT NULL,
557
+ version TEXT NOT NULL,
558
+ created_at TEXT NOT NULL,
559
+ last_seen_at TEXT,
560
+ revoked_at TEXT
561
+ );
562
+ CREATE INDEX IF NOT EXISTS idx_browser_extensions_user ON browser_extensions(user_id);
563
+ `);
468
564
  },
469
- {
470
- version: 14,
471
- name: "agent-api",
472
- // Additive: two new tables and an index. The Agent API's per-Agent settings (the switch,
473
- // keyless access, the approval mode API Sessions are created with) and its keys, stored
474
- // hashed. A predecessor build never reads them and serves no /api/amsp route, so a
475
- // rollback survives it: callers get 404 until a build that knows the tables is back.
476
- swapSafe: true,
477
- up(db) {
478
- db.exec(`
565
+ // LOSES every pairing: each user's Chrome has to be paired again (a new code from the
566
+ // Browser panel) before agents can drive it.
567
+ down(db) {
568
+ db.exec(`
569
+ DROP INDEX IF EXISTS idx_browser_extensions_user;
570
+ DROP TABLE IF EXISTS browser_extensions;
571
+ `);
572
+ }
573
+ };
574
+
575
+ // src/db/migrations/steps/2026-10-10-agent-api.ts
576
+ var agentApi = {
577
+ name: "2026-10-10-agent-api",
578
+ // Additive: two new tables and an index. The Agent API's per-Agent settings (the switch,
579
+ // keyless access, the approval mode API Sessions are created with) and its keys, stored
580
+ // hashed. A predecessor build never reads them and serves no /api/amsp route, so a
581
+ // rollback survives it: callers get 404 until a build that knows the tables is back.
582
+ swapSafe: true,
583
+ up(db) {
584
+ db.exec(`
479
585
  CREATE TABLE IF NOT EXISTS agent_api ( -- per-Agent public API settings (amsp/routes.ts); NOT rebuildable from files
480
586
  project_id TEXT NOT NULL,
481
587
  agent_id TEXT NOT NULL,
@@ -498,128 +604,141 @@ var MIGRATIONS = [
498
604
  );
499
605
  CREATE INDEX IF NOT EXISTS idx_agent_api_keys_agent ON agent_api_keys(project_id, agent_id);
500
606
  `);
501
- },
502
- // LOSES every Agent's API settings and every key: each exposed Agent reads as disabled
503
- // again (404 to its callers), and every caller needs a newly created key once it is back
504
- // on — no file holds a copy of either.
505
- down(db) {
506
- db.exec(`
607
+ },
608
+ // LOSES every Agent's API settings and every key: each exposed Agent reads as disabled
609
+ // again (404 to its callers), and every caller needs a newly created key once it is back
610
+ // on — no file holds a copy of either.
611
+ down(db) {
612
+ db.exec(`
507
613
  DROP INDEX IF EXISTS idx_agent_api_keys_agent;
508
614
  DROP TABLE IF EXISTS agent_api_keys;
509
615
  DROP TABLE IF EXISTS agent_api;
510
616
  `);
511
- }
512
- },
513
- {
514
- version: 15,
515
- name: "messaging-conversations",
516
- // Additive: one new table. The WeChat connector's per-(bot, user) delivery state — the
517
- // context token every send must echo, how many sends it has funded, and replies held for
518
- // the user's next message. A predecessor build never reads it and keeps its tokens in
519
- // memory as it always did, so a rollback survives it.
520
- swapSafe: true,
521
- up(db) {
522
- db.exec(`
523
- CREATE TABLE IF NOT EXISTS messaging_conversations ( -- per-(bot, chat) delivery state a connector must keep across reconnects and restarts (WeChat: the context token, its send count, held replies); deleted once no messaging_bindings row references (channel, account_id) \u2014 see MessagingBindingsRepo
524
- channel TEXT NOT NULL,
525
- account_id TEXT NOT NULL,
526
- chat_id TEXT NOT NULL,
527
- state_json TEXT NOT NULL,
528
- updated_at TEXT NOT NULL,
529
- PRIMARY KEY (channel, account_id, chat_id)
530
- );
531
- `);
532
- },
533
- // LOSES every stored context token and every held reply: replies sent before each user's
534
- // next message are refused again, and what was held never arrives.
535
- down(db) {
536
- db.exec("DROP TABLE IF EXISTS messaging_conversations");
537
- }
538
- },
539
- {
540
- version: 16,
541
- name: "sessions-kept-at",
542
- // The "keep in sidebar" mark: written when the user unarchives a Session, cleared when they
543
- // archive it. The listing rule files a background Session (api / schedule / cli) away unless
544
- // it carries the mark, so existing rows are listed by the rule as they stand and nothing is
545
- // rewritten. Swap-safe: a pushed platform boots against the runtime's already-open database,
546
- // so the column has to arrive by a migration.
547
- swapSafe: true,
548
- up(db) {
549
- ensureColumn(db, "sessions", "kept_at", "TEXT");
550
- },
551
- // Not a DROP: schema.ts declares the column, and dropping it would file every kept
552
- // background Session away again.
553
- down() {
554
- }
617
+ }
618
+ };
619
+
620
+ // src/db/migrations/steps/2026-10-12-messaging-conversations.ts
621
+ var messagingConversations = {
622
+ name: "2026-10-12-messaging-conversations",
623
+ // Additive: one new table. The WeChat connector's per-(bot, user) delivery state — the
624
+ // context token every send must echo, how many sends it has funded, and replies held for
625
+ // the user's next message. A predecessor build never reads it and keeps its tokens in
626
+ // memory as it always did, so a rollback survives it.
627
+ swapSafe: true,
628
+ up(db) {
629
+ db.exec(`
630
+ CREATE TABLE IF NOT EXISTS messaging_conversations ( -- per-(bot, chat) delivery state a connector must keep across reconnects and restarts (WeChat: the context token, its send count, held replies); deleted once no messaging_bindings row references (channel, account_id) \u2014 see MessagingBindingsRepo
631
+ channel TEXT NOT NULL,
632
+ account_id TEXT NOT NULL,
633
+ chat_id TEXT NOT NULL,
634
+ state_json TEXT NOT NULL,
635
+ updated_at TEXT NOT NULL,
636
+ PRIMARY KEY (channel, account_id, chat_id)
637
+ );
638
+ `);
555
639
  },
556
- {
557
- version: 17,
558
- name: "agent-api-session-settings",
559
- // Retain until the minimum supported database version exceeds 16; the maintainer raising
560
- // that baseline removes this upgrade after all supported data roots have these columns.
561
- // Nullable additions preserve existing keys, exposure, approvals and new-Session defaults.
562
- swapSafe: true,
563
- up(db) {
564
- ensureColumn(db, "agent_api", "provider", "TEXT");
565
- ensureColumn(db, "agent_api", "model_id", "TEXT");
566
- ensureColumn(db, "agent_api", "thinking_level", "TEXT");
567
- ensureColumn(db, "agent_api", "workspace", "TEXT");
568
- },
569
- // Keep the saved defaults on rollback; older builds ignore the additional columns.
570
- down() {
571
- }
640
+ // LOSES every stored context token and every held reply: replies sent before each user's
641
+ // next message are refused again, and what was held never arrives.
642
+ down(db) {
643
+ db.exec("DROP TABLE IF EXISTS messaging_conversations");
644
+ }
645
+ };
646
+
647
+ // src/db/migrations/steps/2026-10-12-sessions-kept-at.ts
648
+ var sessionsKeptAt = {
649
+ name: "2026-10-12-sessions-kept-at",
650
+ // The "keep in sidebar" mark: written when the user unarchives a Session, cleared when they
651
+ // archive it. The listing rule files a background Session (api / schedule / cli) away unless
652
+ // it carries the mark, so existing rows are listed by the rule as they stand and nothing is
653
+ // rewritten. Swap-safe: a pushed platform boots against the runtime's already-open database,
654
+ // so the column has to arrive by a migration.
655
+ swapSafe: true,
656
+ up(db) {
657
+ ensureColumn(db, "sessions", "kept_at", "TEXT");
572
658
  },
573
- {
574
- version: 18,
575
- name: "agent-api-concurrency",
576
- // Retain until the minimum supported database version exceeds 17. The maintainer raising
577
- // that baseline removes this upgrade once every supported data root has the column.
578
- swapSafe: true,
579
- up(db) {
580
- ensureColumn(db, "agent_api", "max_concurrent_runs", "INTEGER NOT NULL DEFAULT 4");
581
- },
582
- // Keep the configured limit on rollback; older builds ignore this column.
583
- down() {
584
- }
659
+ // Not a DROP: schema.ts declares the column, and dropping it would file every kept
660
+ // background Session away again.
661
+ down() {
585
662
  }
586
- ];
587
- var LATEST_VERSION = MIGRATIONS.reduce((n, m) => Math.max(n, m.version), 0);
588
- function schemaVersion(db) {
589
- const row = db.prepare("PRAGMA user_version").get();
590
- return row?.user_version ?? 0;
591
- }
592
- var RestartRequiredError = class extends Error {
593
- constructor(migration) {
594
- super(
595
- `migration ${migration.version} (${migration.name}) is restart-only and cannot be applied while a pushed platform boots: it is not safe to leave behind if this boot is rolled back. Restart the runtime on a build that carries it, then push again.`
596
- );
597
- this.migration = migration;
598
- this.name = "RestartRequiredError";
663
+ };
664
+
665
+ // src/db/migrations/steps/2026-10-14-agent-api-concurrency.ts
666
+ var agentApiConcurrency = {
667
+ name: "2026-10-14-agent-api-concurrency",
668
+ // How many of an Agent API Agent's runs may be live at once.
669
+ // Retain while a supported data root can predate this column; the maintainer raising
670
+ // that baseline removes this upgrade once every supported data root has it.
671
+ swapSafe: true,
672
+ up(db) {
673
+ ensureColumn(db, "agent_api", "max_concurrent_runs", "INTEGER NOT NULL DEFAULT 4");
674
+ },
675
+ // Keep the configured limit on rollback; older builds ignore this column.
676
+ down() {
599
677
  }
600
- migration;
601
678
  };
602
- function migrate(db, { swapPath = false } = {}) {
603
- const from = schemaVersion(db);
604
- const pending = [...MIGRATIONS].sort((a, b) => a.version - b.version).filter((m) => m.version > from);
605
- if (swapPath) {
606
- const blocked = pending.find((m) => !m.swapSafe);
607
- if (blocked) throw new RestartRequiredError(blocked);
679
+
680
+ // src/db/migrations/steps/2026-10-14-agent-api-session-settings.ts
681
+ var agentApiSessionSettings = {
682
+ name: "2026-10-14-agent-api-session-settings",
683
+ // The per-Agent API defaults a new Session starts with: which provider, model, thinking
684
+ // level and workspace it opens in. Nullable additions preserve existing keys, exposure,
685
+ // approvals and new-Session defaults.
686
+ // Retain while a supported data root can predate these columns; the maintainer raising
687
+ // that baseline removes this upgrade after all supported data roots have them.
688
+ swapSafe: true,
689
+ up(db) {
690
+ ensureColumn(db, "agent_api", "provider", "TEXT");
691
+ ensureColumn(db, "agent_api", "model_id", "TEXT");
692
+ ensureColumn(db, "agent_api", "thinking_level", "TEXT");
693
+ ensureColumn(db, "agent_api", "workspace", "TEXT");
694
+ },
695
+ // Keep the saved defaults on rollback; older builds ignore the additional columns.
696
+ down() {
608
697
  }
609
- const applied = [];
610
- for (const m of pending) {
611
- db.exec("BEGIN");
612
- try {
613
- m.up(db);
614
- db.exec(`PRAGMA user_version = ${m.version}`);
615
- db.exec("COMMIT");
616
- } catch (err) {
617
- db.exec("ROLLBACK");
618
- throw new Error(`migration ${m.version} (${m.name}) failed: ${String(err)}`, { cause: err });
619
- }
620
- applied.push(m.name);
698
+ };
699
+
700
+ // src/db/migrations/steps/2026-10-16-machines-adopted-at.ts
701
+ var machinesAdoptedAt = {
702
+ name: "2026-10-16-machines-adopted-at",
703
+ // When this server adopted a machine (first recorded it): the Sessions that machine held
704
+ // before then read as CLI tasks through this server (session-sources.ts sourceSeenBy). A
705
+ // machine recorded before this column has none and never gets one, so the rule does not apply
706
+ // to it (user decision, 2026-10-15) — nothing on either side is rewritten. Swap-safe: a pushed platform boots against the runtime's
707
+ // already-open database, so the column has to arrive by a migration.
708
+ swapSafe: true,
709
+ up(db) {
710
+ ensureColumn(db, "machines", "adopted_at", "TEXT");
711
+ },
712
+ // Keep the adoption times on rollback; older builds ignore the column.
713
+ down() {
621
714
  }
622
- return { from, to: schemaVersion(db), applied };
715
+ };
716
+
717
+ // src/db/migrations/index.ts
718
+ var MIGRATIONS = [
719
+ messagingBindings,
720
+ messagingDeliveryFlags,
721
+ dropGoalState,
722
+ machines,
723
+ userProfile,
724
+ companyModeOrgCaches,
725
+ companyModeChannels,
726
+ companyModeDeskNotices,
727
+ modelPromotions,
728
+ modelProviderAuthTokens,
729
+ sessionsSandbox,
730
+ machinesColumns,
731
+ browserExtensions,
732
+ agentApi,
733
+ messagingConversations,
734
+ sessionsKeptAt,
735
+ agentApiSessionSettings,
736
+ agentApiConcurrency,
737
+ machinesAdoptedAt,
738
+ modelTablesAdoption
739
+ ];
740
+ function migrate2(db, options = {}) {
741
+ return migrate(db, MIGRATIONS, options);
623
742
  }
624
743
 
625
744
  // src/db/schema.ts
@@ -832,7 +951,8 @@ CREATE TABLE IF NOT EXISTS machines ( -- one row per machine this serve
832
951
  installed_at TEXT,
833
952
  session_pid INTEGER, -- the ssh session this server holds to it; what a successor App closes after a hot swap
834
953
  remote_port INTEGER, -- its server's port over there, as of the last connect
835
- platform TEXT -- linux | darwin | win32, as the install found it: the shell dialect the status probe speaks to it in
954
+ platform TEXT, -- linux | darwin | win32, as the install found it: the shell dialect the status probe speaks to it in
955
+ adopted_at TEXT -- when this server first recorded this machine (reset when the address answers with another machine's id): Sessions it held before then read as CLI tasks through this server. NULL = recorded before the column existed; never filled in later, and the rule does not apply
836
956
  );
837
957
  CREATE TABLE IF NOT EXISTS machine_project ( -- which machines a Project uses; no row = none yet. Follows the Project out, like project_members
838
958
  project_id TEXT PRIMARY KEY REFERENCES projects(project_id) ON DELETE CASCADE,
@@ -980,7 +1100,7 @@ function openDatabase(dbPath) {
980
1100
  db.exec("DROP INDEX IF EXISTS idx_usage_session");
981
1101
  db.exec("DROP INDEX IF EXISTS idx_messaging_account");
982
1102
  upgradeLastActiveAt(db);
983
- migrate(db);
1103
+ migrate2(db);
984
1104
  return db;
985
1105
  }
986
1106
  function upgradeLastActiveAt(db) {
@@ -1008,9 +1128,9 @@ function ensureColumn(db, table, column, ddl) {
1008
1128
  }
1009
1129
 
1010
1130
  export {
1011
- migrate,
1131
+ migrate2 as migrate,
1012
1132
  openExistingDatabase,
1013
1133
  openDatabaseReadOnly,
1014
1134
  openDatabase
1015
1135
  };
1016
- //# sourceMappingURL=chunk-3SFJKLQU.js.map
1136
+ //# sourceMappingURL=chunk-HPOHMZCH.js.map