@prismshadow/penguin-server 0.2.10 → 0.2.13

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 (80) hide show
  1. package/README.md +1 -1
  2. package/dist/api/types.d.ts +1014 -12
  3. package/dist/api/types.js +7 -0
  4. package/dist/auth-token.js +6 -4
  5. package/dist/auth-token.js.map +1 -1
  6. package/dist/{chunk-Q65VPAQS.js → chunk-3I2XOPJB.js} +102 -55
  7. package/dist/chunk-3I2XOPJB.js.map +1 -0
  8. package/dist/{chunk-ADZJYDNC.js → chunk-A3QANMU5.js} +293 -3
  9. package/dist/chunk-A3QANMU5.js.map +1 -0
  10. package/dist/chunk-B5IP37ZQ.js +56 -0
  11. package/dist/chunk-L2H3K4DT.js +7 -0
  12. package/dist/chunk-L2H3K4DT.js.map +1 -0
  13. package/dist/chunk-LPPVGHYD.js +83 -0
  14. package/dist/chunk-LPPVGHYD.js.map +1 -0
  15. package/dist/{chunk-TTGGJDNA.js → chunk-S3BI6R7I.js} +2 -2
  16. package/dist/{chunk-HOS3W3UP.js → chunk-TOOTEEM4.js} +50 -8
  17. package/dist/chunk-TOOTEEM4.js.map +1 -0
  18. package/dist/hmr/manifest.d.ts +1 -77
  19. package/dist/hmr/manifest.js +6 -1
  20. package/dist/index.js +50757 -20174
  21. package/dist/index.js.map +1 -1
  22. package/dist/initial-password.js +1 -0
  23. package/dist/lock.js +1 -0
  24. package/dist/machine-status.js +2 -1
  25. package/dist/machine-status.js.map +1 -1
  26. package/dist/plugin/index.d.ts +2595 -0
  27. package/dist/plugin/index.js.map +1 -0
  28. package/dist/reset-admin-password.js +7 -5
  29. package/dist/reset-admin-password.js.map +1 -1
  30. package/dist/secret-file.js +2 -0
  31. package/dist/secret-file.js.map +1 -1
  32. package/dist/version-report.js +3 -2
  33. package/package.json +11 -9
  34. package/web-dist/assets/{addon-clipboard-1cARCaK9.js → addon-clipboard-DrZY90Ks.js} +1 -1
  35. package/web-dist/assets/{addon-fit-BWdzl8Er.js → addon-fit-CtEAdAax.js} +1 -1
  36. package/web-dist/assets/{addon-web-links-DjXuvn4Z.js → addon-web-links-DJL13cYY.js} +1 -1
  37. package/web-dist/assets/c-BG-tZi7o.js +1 -0
  38. package/web-dist/assets/cpp-CaeG3uDQ.js +1 -0
  39. package/web-dist/assets/css-Br67jR8j.js +1 -0
  40. package/web-dist/assets/diff-jW5kmiru.js +1 -0
  41. package/web-dist/assets/github-dark-BQV5ugrc.js +1 -0
  42. package/web-dist/assets/github-light-Rcb2q3L5.js +1 -0
  43. package/web-dist/assets/go-B7VTfpnm.js +1 -0
  44. package/web-dist/assets/highlighter-CUb4XKtQ.js +2 -0
  45. package/web-dist/assets/{highlighter-Cu43iYr8.js → highlighter-core-CrBdruEx.js} +2 -2
  46. package/web-dist/assets/highlighter.worker-CL6f9Fzw.js +152 -0
  47. package/web-dist/assets/html-BW_6VhB7.js +1 -0
  48. package/web-dist/assets/index-CmfumtXy.js +570 -0
  49. package/web-dist/assets/index-Ywc2uM5u.css +1 -0
  50. package/web-dist/assets/ini-Dix3pTmg.js +1 -0
  51. package/web-dist/assets/java-BTDmaRNO.js +1 -0
  52. package/web-dist/assets/javascript-WyGyM1wV.js +1 -0
  53. package/web-dist/assets/json-B8JryHcM.js +1 -0
  54. package/web-dist/assets/jsx-8cLv2Six.js +1 -0
  55. package/web-dist/assets/log-CcaF_xNv.js +1 -0
  56. package/web-dist/assets/markdown-DX-TNHnc.js +1 -0
  57. package/web-dist/assets/php-CNeTOyEV.js +1 -0
  58. package/web-dist/assets/python-B6Ihcp-E.js +1 -0
  59. package/web-dist/assets/ruby-CYiNE6ps.js +1 -0
  60. package/web-dist/assets/rust-CxuBE0J8.js +1 -0
  61. package/web-dist/assets/shellscript-DgJyDXW6.js +1 -0
  62. package/web-dist/assets/sql-Dq2MiB0T.js +1 -0
  63. package/web-dist/assets/toml-Ms459DBw.js +1 -0
  64. package/web-dist/assets/tsx-D6116Ycy.js +1 -0
  65. package/web-dist/assets/typescript-BqvgUolh.js +1 -0
  66. package/web-dist/assets/xml-BkAJuBCc.js +1 -0
  67. package/web-dist/assets/{xterm-DKcY6q-I.js → xterm-B2oS8Mg8.js} +1 -1
  68. package/web-dist/assets/yaml-Bopit2L3.js +1 -0
  69. package/web-dist/index.html +2 -2
  70. package/dist/chunk-4SXGU7RO.js +0 -50
  71. package/dist/chunk-4SXGU7RO.js.map +0 -1
  72. package/dist/chunk-ADZJYDNC.js.map +0 -1
  73. package/dist/chunk-HOS3W3UP.js.map +0 -1
  74. package/dist/chunk-Q65VPAQS.js.map +0 -1
  75. package/dist/extension/index.d.ts +0 -212
  76. package/web-dist/assets/index-Bm9n7ZV-.js +0 -457
  77. package/web-dist/assets/index-DR4PrRzS.css +0 -1
  78. /package/dist/{extension/index.js.map → chunk-B5IP37ZQ.js.map} +0 -0
  79. /package/dist/{chunk-TTGGJDNA.js.map → chunk-S3BI6R7I.js.map} +0 -0
  80. /package/dist/{extension → plugin}/index.js +0 -0
@@ -136,6 +136,215 @@ var MIGRATIONS = [
136
136
  DROP TABLE IF EXISTS machine;
137
137
  `);
138
138
  }
139
+ },
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
+ }
160
+ },
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
+ }
257
+ },
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) {
297
+ db.exec(`
298
+ DROP TABLE IF EXISTS org_channel_state;
299
+ DROP TABLE IF EXISTS org_channel_reads;
300
+ CREATE TABLE IF NOT EXISTS org_chat_state ( -- DERIVED CACHE (company mode): tail-scan byte cursor per chat day file
301
+ project_id TEXT NOT NULL,
302
+ org_id TEXT NOT NULL,
303
+ date TEXT NOT NULL,
304
+ offset_bytes INTEGER NOT NULL DEFAULT 0,
305
+ PRIMARY KEY (project_id, org_id, date)
306
+ );
307
+ CREATE TABLE IF NOT EXISTS org_chat_reads ( -- user data (company mode): each user's read cursor in an organization's chat
308
+ project_id TEXT NOT NULL,
309
+ org_id TEXT NOT NULL,
310
+ user_id TEXT NOT NULL,
311
+ last_read_id TEXT NOT NULL,
312
+ PRIMARY KEY (project_id, org_id, user_id)
313
+ );
314
+ `);
315
+ }
316
+ },
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
+ }
139
348
  }
140
349
  ];
141
350
  var LATEST_VERSION = MIGRATIONS.reduce((n, m) => Math.max(n, m.version), 0);
@@ -183,6 +392,8 @@ CREATE TABLE IF NOT EXISTS users (
183
392
  password_hash TEXT NOT NULL, -- scrypt$N$r$p$salt$hash(base64)
184
393
  is_admin INTEGER NOT NULL DEFAULT 0, -- 1 for the built-in admin (seeded at startup)
185
394
  password_is_initial INTEGER NOT NULL DEFAULT 0, -- 1=initial password (seeded/admin-set); cleared once the user changes it
395
+ display_name TEXT, -- nickname shown in place of user_id (1-32 characters); NULL = never set, surfaces show the id
396
+ avatar TEXT, -- avatar as a data URL (image/png|jpeg|webp, <= 131072 characters); NULL = never set, surfaces draw the letter placeholder
186
397
  created_at TEXT NOT NULL
187
398
  );
188
399
  -- Server-side sessions backing the HttpOnly cookie: the cookie carries a 32-byte random
@@ -233,7 +444,7 @@ CREATE TABLE IF NOT EXISTS sessions (
233
444
  fork_count INTEGER NOT NULL DEFAULT 0, -- monotonically allocated child-fork number for this source Session; never decremented when a fork is deleted
234
445
  last_active_at TEXT, -- last activity this server drove for the session (ISO; stamped once when a run starts and once when it ends, initialized to created_at); monotonic, never moves backwards; NULL only before openDatabase's one-time backfill
235
446
  created_at TEXT NOT NULL
236
- ); -- the schedule/subagent SOURCE is NOT stored: session_meta in the Trace is the single source of truth (see runtime/session-sources.ts); "client" is a different, DB-only axis (who created the row)
447
+ ); -- the subagent/schedule/benchmark SOURCE is NOT stored: session_meta in the Trace is the single source of truth (see runtime/session-sources.ts); "client" is a different, DB-only axis (who created the row)
237
448
  CREATE INDEX IF NOT EXISTS idx_sessions_agent_created ON sessions(project_id, agent_id, created_at DESC);
238
449
  CREATE TABLE IF NOT EXISTS usage_records (
239
450
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -339,7 +550,7 @@ CREATE TABLE IF NOT EXISTS trace_sessions ( -- per-session facts read ONCE at
339
550
  session_id TEXT PRIMARY KEY,
340
551
  project_id TEXT NOT NULL,
341
552
  agent_id TEXT NOT NULL,
342
- source TEXT, -- session_meta origin: 'subagent' | 'schedule' | NULL = user-created (or head not yet readable)
553
+ source TEXT, -- session_meta origin: 'subagent' | 'schedule' | 'benchmark' | NULL = user-created (or head not yet readable)
343
554
  workspace TEXT NOT NULL DEFAULT '',
344
555
  title TEXT, -- first-prompt fallback title (sessions.title always wins when present)
345
556
  provider TEXT, -- model reference from session_meta (CLI adoption reads it from here; NULL = meta unreadable / legacy without provider)
@@ -348,6 +559,85 @@ CREATE TABLE IF NOT EXISTS trace_sessions ( -- per-session facts read ONCE at
348
559
  meta_read INTEGER NOT NULL DEFAULT 0 -- 1 once the head parsed; 0 = facts unknown, retried by the next reconcile that touches the session
349
560
  );
350
561
  CREATE INDEX IF NOT EXISTS idx_trace_sessions_agent ON trace_sessions(project_id, agent_id);
562
+ 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 mention-chain accounting and reads 0 after a rebuild
563
+ session_id TEXT PRIMARY KEY,
564
+ project_id TEXT NOT NULL,
565
+ org_id TEXT NOT NULL,
566
+ agent_id TEXT NOT NULL,
567
+ current INTEGER NOT NULL DEFAULT 1,
568
+ trigger_hop INTEGER NOT NULL DEFAULT 0
569
+ );
570
+ CREATE INDEX IF NOT EXISTS idx_org_sessions_org ON org_sessions(project_id, org_id);
571
+ CREATE TABLE IF NOT EXISTS org_ticket_sessions ( -- DERIVED CACHE (company mode): ticket <-> contributing session, rebuilt from each ticket's Sessions header
572
+ project_id TEXT NOT NULL,
573
+ org_id TEXT NOT NULL,
574
+ ticket_id TEXT NOT NULL,
575
+ session_id TEXT NOT NULL,
576
+ agent_id TEXT NOT NULL,
577
+ trigger_hop INTEGER NOT NULL DEFAULT 0,
578
+ PRIMARY KEY (project_id, org_id, ticket_id, session_id)
579
+ );
580
+ CREATE INDEX IF NOT EXISTS idx_org_ticket_sessions_session ON org_ticket_sessions(session_id);
581
+ CREATE TABLE IF NOT EXISTS org_calendar_state ( -- calendar run state (company mode; the files are declarative intent), same rules as schedule_state
582
+ project_id TEXT NOT NULL,
583
+ org_id TEXT NOT NULL,
584
+ agent_id TEXT NOT NULL,
585
+ name TEXT NOT NULL,
586
+ start_at_ms INTEGER NOT NULL,
587
+ def_hash TEXT NOT NULL,
588
+ last_slot_ms INTEGER,
589
+ last_fired_at TEXT,
590
+ fired_once INTEGER NOT NULL DEFAULT 0,
591
+ missed INTEGER NOT NULL DEFAULT 0,
592
+ invalid_reason TEXT,
593
+ last_outcome TEXT,
594
+ PRIMARY KEY (project_id, org_id, agent_id, name)
595
+ );
596
+ 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
597
+ project_id TEXT NOT NULL,
598
+ org_id TEXT NOT NULL,
599
+ ticket_id TEXT NOT NULL,
600
+ status TEXT NOT NULL,
601
+ owner TEXT NOT NULL DEFAULT '',
602
+ blocked TEXT NOT NULL DEFAULT '',
603
+ blocked_by TEXT NOT NULL DEFAULT '',
604
+ PRIMARY KEY (project_id, org_id, ticket_id)
605
+ );
606
+ CREATE TABLE IF NOT EXISTS org_channel_state ( -- DERIVED CACHE (company mode): tail-scan byte cursor per channel and day file
607
+ project_id TEXT NOT NULL,
608
+ org_id TEXT NOT NULL,
609
+ channel_id TEXT NOT NULL,
610
+ date TEXT NOT NULL,
611
+ offset_bytes INTEGER NOT NULL DEFAULT 0,
612
+ PRIMARY KEY (project_id, org_id, channel_id, date)
613
+ );
614
+ CREATE TABLE IF NOT EXISTS org_channel_reads ( -- user data (company mode): each user's read cursor in one channel
615
+ project_id TEXT NOT NULL,
616
+ org_id TEXT NOT NULL,
617
+ channel_id TEXT NOT NULL,
618
+ user_id TEXT NOT NULL,
619
+ last_read_id TEXT NOT NULL,
620
+ PRIMARY KEY (project_id, org_id, channel_id, user_id)
621
+ );
622
+ 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
623
+ project_id TEXT NOT NULL,
624
+ org_id TEXT NOT NULL,
625
+ agent_id TEXT NOT NULL,
626
+ period TEXT NOT NULL,
627
+ warned_at TEXT,
628
+ paused_at TEXT,
629
+ PRIMARY KEY (project_id, org_id, agent_id, period)
630
+ );
631
+ 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
632
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
633
+ project_id TEXT NOT NULL,
634
+ org_id TEXT NOT NULL,
635
+ agent_id TEXT NOT NULL,
636
+ ticket_id TEXT NOT NULL,
637
+ change TEXT NOT NULL,
638
+ at TEXT NOT NULL
639
+ );
640
+ CREATE INDEX IF NOT EXISTS idx_org_desk_notices_agent ON org_desk_notices(project_id, org_id, agent_id);
351
641
  `;
352
642
 
353
643
  // src/db/database.ts
@@ -418,4 +708,4 @@ export {
418
708
  openDatabaseReadOnly,
419
709
  openDatabase
420
710
  };
421
- //# sourceMappingURL=chunk-ADZJYDNC.js.map
711
+ //# sourceMappingURL=chunk-A3QANMU5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/db/database.ts","../src/db/migrations.ts","../src/db/schema.ts"],"sourcesContent":["/**\n * SQLite connection & initialization (node:sqlite DatabaseSync).\n *\n * Single process, single writer: a synchronous API is sufficient and avoids a connection\n * pool; WAL mode and foreign key constraints are enabled. Table-creation SQL runs on open\n * (idempotent), with no migration branches (product not yet released).\n */\nimport { mkdirSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type { DatabaseSync } from \"node:sqlite\";\nimport { migrate } from \"./migrations.js\";\nimport { SCHEMA_SQL } from \"./schema.js\";\n\n// Fetch the runtime module via process.getBuiltinModule (node >=22.3): avoids static\n// resolution of `node:sqlite` by bundlers/vite (some tools' builtin lists don't yet\n// recognize this experimental module).\nconst sqlite = process.getBuiltinModule(\"node:sqlite\");\n\n/**\n * Opens an EXISTING database for a narrow write, without running any schema work.\n *\n * `openDatabase` migrates — CREATE TABLE, several ensureColumn calls, a DROP INDEX and a backfill.\n * That is right for the process that owns the database and wrong for a short-lived CLI writing\n * one row (`penguin auth token`): after `penguin update` the CLI on disk can be NEWER than the\n * running server, and migrating under a live server's prepared statements is not something a\n * token mint should do. The caller has already established that the file exists.\n */\nexport function openExistingDatabase(dbPath: string): DatabaseSync {\n const db = new sqlite.DatabaseSync(dbPath);\n db.exec(\"PRAGMA foreign_keys = ON;\");\n // Wait for the live server's write lock instead of failing SQLITE_BUSY at once.\n db.exec(\"PRAGMA busy_timeout = 5000;\");\n return db;\n}\n\n/**\n * Opens an EXISTING database for reading only — SQLite refuses every write on the connection,\n * so a reader cannot change the file even by mistake. For a question asked of a database some\n * other process owns (`penguin server status`, run over ssh by a controller): the answer must\n * not reshape that server's schema, and must not be able to. The caller has established that\n * the file exists; a read-only open of a missing file is an error, not a creation.\n */\nexport function openDatabaseReadOnly(dbPath: string): DatabaseSync {\n const db = new sqlite.DatabaseSync(dbPath, { readOnly: true });\n db.exec(\"PRAGMA busy_timeout = 5000;\");\n return db;\n}\n\n/** Open (creating if necessary) the database: ensure the parent directory exists, set PRAGMAs, run table creation. */\nexport function openDatabase(dbPath: string): DatabaseSync {\n if (dbPath !== \":memory:\") {\n mkdirSync(path.dirname(dbPath), { recursive: true });\n }\n const db = new sqlite.DatabaseSync(dbPath);\n db.exec(\"PRAGMA journal_mode = WAL;\");\n // A second connection (the CLI minting a token while the server runs) waits for the write\n // lock rather than failing SQLITE_BUSY at once.\n db.exec(\"PRAGMA busy_timeout = 5000;\");\n db.exec(\"PRAGMA foreign_keys = ON;\");\n db.exec(SCHEMA_SQL);\n // Columns added to the schema after a web.db was formed: CREATE TABLE IF NOT EXISTS never\n // touches an existing table, so they are ALTERed in here. Keep the list in sync with\n // schema.ts; drop entries only in a release allowed to break existing web.db files.\n ensureColumn(db, \"sessions\", \"client\", \"TEXT\");\n ensureColumn(db, \"sessions\", \"has_trace\", \"INTEGER NOT NULL DEFAULT 0\");\n ensureColumn(db, \"sessions\", \"fork_count\", \"INTEGER NOT NULL DEFAULT 0\");\n ensureColumn(db, \"sessions\", \"thinking_level\", \"TEXT\");\n // A v0.2.0 web.db has auth_sessions without `via`; CREATE TABLE IF NOT EXISTS never adds a\n // column, so every INSERT would fail \"no column named via\" until this runs.\n ensureColumn(db, \"auth_sessions\", \"via\", \"TEXT\");\n ensureColumn(db, \"trace_files\", \"page_stats\", \"TEXT\");\n ensureColumn(db, \"messaging_bindings\", \"line_per_message\", \"INTEGER NOT NULL DEFAULT 0\");\n ensureColumn(db, \"messaging_bindings\", \"final_reply_only\", \"INTEGER NOT NULL DEFAULT 0\");\n // DEFAULT 1, unlike every other added flag here: this one's default is the CORRECTED\n // behaviour, not the previous one. Sending the model's Markdown as characters was the\n // defect, so an existing binding starts rendering it — a visible change to every relayed\n // message, recorded in the release's backward-compatibility entry.\n ensureColumn(db, \"messaging_bindings\", \"render_markdown\", \"INTEGER NOT NULL DEFAULT 1\");\n ensureColumn(db, \"messaging_bindings\", \"last_inbound_message_id\", \"TEXT\");\n // Superseded by idx_usage_session_ts (session_id, ts), which SCHEMA_SQL just created on\n // this database: the old index is a strict prefix of it, so every query it served is\n // served identically. Dropping is safe — an index is derived, never data.\n db.exec(\"DROP INDEX IF EXISTS idx_usage_session\");\n // The uniqueness index of the old binding model, where a bot account belonged to one\n // Session forever and a second Session could not even SAVE its credentials. Enabling a\n // connection is the binding now, so exclusivity is checked per enable (the state route's\n // 409 account_enabled_elsewhere) and the same account may sit saved on many Sessions —\n // which this index would reject. SCHEMA_SQL has just created idx_messaging_by_account\n // over the same columns, so the by-account lookup stays indexed. Dropping is safe: an\n // index is derived, never data. It is however ONE-WAY — an older build recreates the\n // unique index on open, which fails outright once duplicate (channel, account_id) rows\n // exist, so a downgrade after two Sessions saved the same bot needs those rows removed.\n db.exec(\"DROP INDEX IF EXISTS idx_messaging_account\");\n upgradeLastActiveAt(db);\n // The runtime's own open is the ONLY place a restart-only migration may be applied: it\n // owns the process, so there is no boot to roll back out from under it.\n migrate(db);\n return db;\n}\n\n/**\n * One-time `sessions.last_active_at` upgrade, ALTER + backfill in a single transaction.\n *\n * The backfill runs **only in the open that actually adds the column** (SQLite's ALTER\n * TABLE ADD COLUMN is transactional, so a crash mid-upgrade rolls back to \"no column\" and\n * the next open redoes both halves — never a half-migrated table, and never a full\n * `sessions` scan on the millions of opens that follow). Legacy rows take the session's\n * most recent request timestamp — usage_records, covered by idx_usage_session_ts, the\n * closest persisted proxy for \"last Trace activity\" — else their own created_at.\n */\nfunction upgradeLastActiveAt(db: DatabaseSync): void {\n db.exec(\"BEGIN\");\n try {\n if (ensureColumn(db, \"sessions\", \"last_active_at\", \"TEXT\")) {\n db.exec(\n `UPDATE sessions SET last_active_at = COALESCE(\n (SELECT MAX(ts) FROM usage_records WHERE usage_records.session_id = sessions.session_id),\n created_at\n )`,\n );\n }\n db.exec(\"COMMIT\");\n } catch (err) {\n db.exec(\"ROLLBACK\");\n throw err;\n }\n}\n\n/**\n * Idempotent per-column upgrade for databases formed before the column existed.\n * Returns whether this call actually ALTERed the table (false = the column was already\n * there), so a caller can gate one-time backfill work on it.\n */\nexport function ensureColumn(\n db: DatabaseSync,\n table: string,\n column: string,\n ddl: string,\n): boolean {\n const cols = db.prepare(`PRAGMA table_info(${table})`).all() as { name: string }[];\n if (cols.some((c) => c.name === column)) return false;\n db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${ddl}`);\n return true;\n}\n","/**\n * Ordered, versioned schema migrations.\n *\n * `schema.ts` declares the shape a FRESH database is created with. It cannot express a\n * CHANGE — `CREATE TABLE IF NOT EXISTS` only ever says \"should exist\", so re-running it\n * converges a database toward the current declaration without ever knowing, or recording,\n * which state it came from. That is why a build could not tell a 0.2.4 database from a\n * 0.2.7 one, and why the only safe change was an additive one.\n *\n * A migration says what CHANGED, runs once, and leaves the database stamped with how far\n * it has come (`PRAGMA user_version`). Two rules make that stamp trustworthy:\n *\n * FROZEN DDL. A migration spells out its own SQL and never imports SCHEMA_SQL. Referring\n * to the live declaration would make an old migration silently mean something new every\n * time the schema moves, which is the property that makes migrations auditable at all.\n *\n * ONE WAY, IN ORDER. Versions are contiguous from 1 and never renumbered or rewritten\n * once released — a database that already stamped version N will never run N again, so\n * editing N only changes what NEW databases get, and silently forks the two.\n *\n * `swapSafe` is this codebase's extra axis, and it exists because of hot updates. A\n * pushed platform boots against a live database and is ROLLED BACK to its predecessor if\n * it fails; the predecessor then runs on whatever the migration already did. Additive\n * work survives that (the older build does not know the new table, so it never touches\n * it) — narrowing work does not. Anything that drops, retypes, constrains, or reshapes\n * is `swapSafe: false` and must be refused on the swap path rather than half-applied\n * (see `migrate`'s `swapPath` option).\n *\n * DOWN, AND WHO DOES NOT CALL IT. Every migration declares an undo — or declares `null`\n * to say it has none, which is a decision the author has to make rather than omit. What\n * `down` is NOT is the hot-update rollback mechanism. When a pushed platform fails to boot\n * the runtime reverts to its PREDECESSOR and the schema stays where the migration left it:\n * undoing DDL inside a process whose boot just failed would run destructive statements\n * against a half-known state, and `swapSafe` exists precisely so that not undoing is safe —\n * the predecessor does not know the new table or column, so it never touches it. `down` is\n * an operator's tool, called deliberately (`rollbackTo`), never by the swap.\n *\n * It is also LOSSY by nature: undoing \"add a table\" drops that table with its rows in it.\n * Each `down` below names what its rows were.\n *\n * ADOPTION. Databases created before this file existed are all stamped 0 while sitting in\n * genuinely different shapes, so a migration must tolerate finding its work already done.\n * That is not only a version-1 concern: `schema.ts` still DECLARES the current shape in\n * full and `openDatabase` still runs its ensureColumn list, so a database can arrive at a\n * migration with that migration's work already applied by the declarative track. Until\n * SCHEMA_SQL is frozen to a baseline and every later change is a migration, every\n * migration here stays idempotent — `IF NOT EXISTS`, or the same `ensureColumn` guard the\n * declarative track uses. Once that double track is gone, a bare `CREATE TABLE` that\n * fails loudly becomes the point.\n */\nimport type { DatabaseSync } from \"node:sqlite\";\nimport { ensureColumn } from \"./database.js\";\n\nexport interface Migration {\n /** Contiguous from 1. Never renumbered, never edited once released. */\n version: number;\n /** Kebab-case, names the change — read in logs and in the stamp's history. */\n name: string;\n /**\n * May this run while a pushed platform boots? True only for strictly additive work,\n * which a rollback to the previous platform survives. See the module doc.\n */\n swapSafe: boolean;\n /** Applied inside a transaction; throw to abort and leave the version unchanged. */\n up: (db: DatabaseSync) => void;\n /**\n * Undoes `up`, or null when this migration cannot be undone — required, not optional, so\n * \"there is no undo\" is something the author states rather than forgets.\n *\n * Never called by the swap path (see the module doc): a failed boot reverts the platform,\n * not the schema. Reached only through `rollbackTo`, and destructive by nature — dropping\n * a table takes its rows with it.\n */\n down: ((db: DatabaseSync) => void) | null;\n}\n\nexport const MIGRATIONS: readonly Migration[] = [\n {\n version: 1,\n name: \"messaging-bindings\",\n // Purely additive: one new table plus three indexes, no column of any existing table\n // touched. A platform that rolls back to a predecessor without messaging simply never\n // queries them.\n swapSafe: true,\n up(db) {\n // 0.2.4 → 0.2.7. Frozen copy of the DDL as of 0.2.7; do not re-derive from schema.ts.\n // IF NOT EXISTS only because version 1 adopts unstamped databases, which may already\n // be at 0.2.7 (see the module doc's ADOPTION note).\n db.exec(`\n CREATE TABLE IF NOT EXISTS messaging_bindings (\n session_id TEXT NOT NULL,\n channel TEXT NOT NULL,\n account_id TEXT NOT NULL,\n config_json TEXT NOT NULL,\n enabled INTEGER NOT NULL DEFAULT 0,\n line_per_message INTEGER NOT NULL DEFAULT 0,\n last_chat_id TEXT,\n last_chat_is_direct INTEGER NOT NULL DEFAULT 1,\n last_inbound_message_id TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n PRIMARY KEY (session_id, channel)\n );\n CREATE INDEX IF NOT EXISTS idx_messaging_by_account ON messaging_bindings(channel, account_id);\n CREATE INDEX IF NOT EXISTS idx_auth_sessions_expires ON auth_sessions(expires_at);\n CREATE INDEX IF NOT EXISTS idx_auth_sessions_user ON auth_sessions(user_id);\n `);\n },\n // LOSES every messaging binding: the channel credentials, the enabled flag and the\n // last-chat memory all live in the table this drops. The auth_sessions indexes are\n // derived and cost nothing to lose.\n down(db) {\n db.exec(`\n DROP INDEX IF EXISTS idx_auth_sessions_user;\n DROP INDEX IF EXISTS idx_auth_sessions_expires;\n DROP INDEX IF EXISTS idx_messaging_by_account;\n DROP TABLE IF EXISTS messaging_bindings;\n `);\n },\n },\n {\n version: 2,\n name: \"messaging-delivery-flags\",\n // Two columns with defaults on an existing table: a rollback to a predecessor that\n // does not know them leaves them at their defaults and reads nothing.\n swapSafe: true,\n up(db) {\n // 0.2.7 → 0.2.8. ensureColumn rather than a bare ALTER because the declarative\n // track may already have added these (see the module doc's ADOPTION note).\n ensureColumn(db, \"messaging_bindings\", \"final_reply_only\", \"INTEGER NOT NULL DEFAULT 0\");\n ensureColumn(db, \"messaging_bindings\", \"render_markdown\", \"INTEGER NOT NULL DEFAULT 1\");\n },\n // LOSES both delivery preferences on every binding; the bindings themselves survive.\n // Dropped in reverse order for symmetry with `up`. Neither column is indexed, which is\n // what lets SQLite drop them at all.\n down(db) {\n db.exec(\"ALTER TABLE messaging_bindings DROP COLUMN render_markdown\");\n db.exec(\"ALTER TABLE messaging_bindings DROP COLUMN final_reply_only\");\n },\n },\n {\n version: 3,\n name: \"drop-goal-state\",\n // Narrowing: drops a table. A pushed platform rolled back to 0.2.9 mid-process would\n // prepare its goal statements against a table that is gone (its declarative track only\n // runs at the runtime's own open, never at a platform boot), so this is the first\n // restart-only migration: refused on the swap path, applied by the runtime's open.\n swapSafe: false,\n up(db) {\n // 0.2.9 → 0.2.10. goal_state held goal mode's run state, one row per goal run, read\n // back only for the chat page's goal banner; the goal plugin's GOAL.json in the\n // Session scratchpad is that record now (see runtime/goal-events.ts). IF EXISTS only\n // because a database this build created never had the table.\n db.exec(`\n DROP INDEX IF EXISTS idx_goal_session;\n DROP TABLE IF EXISTS goal_state;\n `);\n },\n // Recreates the table exactly as 0.2.9 declared it — EMPTY. LOSES every goal run ever\n // recorded (objective, status, budget, used, rounds per run): the rows only ever fed the\n // banner of a finished goal, and a build with this migration reads the goal file instead.\n down(db) {\n db.exec(`\n CREATE TABLE IF NOT EXISTS goal_state (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n session_id TEXT NOT NULL,\n project_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n objective TEXT NOT NULL,\n status TEXT NOT NULL,\n budget INTEGER NOT NULL,\n used INTEGER NOT NULL DEFAULT 0,\n rounds INTEGER NOT NULL DEFAULT 0,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL\n );\n CREATE INDEX IF NOT EXISTS idx_goal_session ON goal_state(session_id);\n `);\n },\n },\n {\n version: 4,\n name: \"machines\",\n // Three new tables, nothing existing touched: a platform rolled back to one without\n // machines never queries them. Swap-safe on its own; a database still behind\n // drop-goal-state is refused whole by that one first, which is the rule.\n swapSafe: true,\n up(db) {\n // Frozen copy of the DDL as of the machines feature; do not re-derive from schema.ts.\n // IF NOT EXISTS because the declarative track may already have created them (ADOPTION).\n db.exec(`\n CREATE TABLE IF NOT EXISTS machine (\n singleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n machine_id TEXT NOT NULL\n );\n CREATE TABLE IF NOT EXISTS machines (\n address TEXT PRIMARY KEY,\n machine_id TEXT,\n version TEXT,\n installed_at TEXT,\n session_pid INTEGER,\n remote_port INTEGER,\n platform TEXT\n );\n CREATE TABLE IF NOT EXISTS machine_project (\n project_id TEXT PRIMARY KEY REFERENCES projects(project_id) ON DELETE CASCADE,\n addresses TEXT NOT NULL\n );\n `);\n },\n // LOSES this server's own machine id (every stored reference to it on other machines\n // then points at nothing), what was installed where, the sessions held, and which\n // machines each Project used.\n down(db) {\n db.exec(`\n DROP TABLE IF EXISTS machine_project;\n DROP TABLE IF EXISTS machines;\n DROP TABLE IF EXISTS machine;\n `);\n },\n },\n {\n version: 5,\n name: \"user-profile\",\n // Two nullable columns on `users`, no default and nothing existing rewritten: a platform\n // rolled back to a predecessor that does not know them never selects or writes them, and\n // every existing account simply reads NULL — no profile yet.\n swapSafe: true,\n up(db) {\n // Frozen copy of the DDL as of the user-profile feature; do not re-derive from schema.ts.\n // SQLite has no ADD COLUMN IF NOT EXISTS, and the declarative track may already have\n // added both (ADOPTION), so each one goes through the same table_info guard the\n // declarative track uses.\n ensureColumn(db, \"users\", \"display_name\", \"TEXT\");\n ensureColumn(db, \"users\", \"avatar\", \"TEXT\");\n },\n // LOSES every stored nickname and avatar: both live entirely in the two columns this\n // drops, and nothing else on disk holds a copy. Dropped in reverse order for symmetry\n // with `up`; neither column is indexed, which is what lets SQLite drop them at all.\n down(db) {\n const cols = db.prepare(\"PRAGMA table_info(users)\").all() as { name: string }[];\n const has = (name: string): boolean => cols.some((c) => c.name === name);\n if (has(\"avatar\")) db.exec(\"ALTER TABLE users DROP COLUMN avatar\");\n if (has(\"display_name\")) db.exec(\"ALTER TABLE users DROP COLUMN display_name\");\n },\n },\n {\n version: 6,\n name: \"company-mode-org-caches\",\n // Additive: seven new tables for company mode (organizations of Agents), no change to any\n // existing table. Every row is either rebuildable from the organization's files (desks.toml,\n // the tickets' Sessions headers, the calendar files, usage records) or a user's own read\n // cursor; a predecessor build never touches them.\n swapSafe: true,\n up(db) {\n db.exec(`\n 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\n session_id TEXT PRIMARY KEY,\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n current INTEGER NOT NULL DEFAULT 1,\n trigger_hop INTEGER NOT NULL DEFAULT 0\n );\n CREATE INDEX IF NOT EXISTS idx_org_sessions_org ON org_sessions(project_id, org_id);\n CREATE TABLE IF NOT EXISTS org_ticket_sessions ( -- DERIVED CACHE (company mode): ticket <-> contributing session, rebuilt from each ticket's Sessions header\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n ticket_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n trigger_hop INTEGER NOT NULL DEFAULT 0,\n PRIMARY KEY (project_id, org_id, ticket_id, session_id)\n );\n CREATE INDEX IF NOT EXISTS idx_org_ticket_sessions_session ON org_ticket_sessions(session_id);\n CREATE TABLE IF NOT EXISTS org_calendar_state ( -- calendar run state (company mode; the files are declarative intent), same rules as schedule_state\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n name TEXT NOT NULL,\n start_at_ms INTEGER NOT NULL,\n def_hash TEXT NOT NULL,\n last_slot_ms INTEGER,\n last_fired_at TEXT,\n fired_once INTEGER NOT NULL DEFAULT 0,\n missed INTEGER NOT NULL DEFAULT 0,\n invalid_reason TEXT,\n last_outcome TEXT,\n PRIMARY KEY (project_id, org_id, agent_id, name)\n );\n 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\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n ticket_id TEXT NOT NULL,\n status TEXT NOT NULL,\n owner TEXT NOT NULL DEFAULT '',\n blocked TEXT NOT NULL DEFAULT '',\n blocked_by TEXT NOT NULL DEFAULT '',\n PRIMARY KEY (project_id, org_id, ticket_id)\n );\n CREATE TABLE IF NOT EXISTS org_chat_state ( -- DERIVED CACHE (company mode): tail-scan byte cursor per chat day file\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n date TEXT NOT NULL,\n offset_bytes INTEGER NOT NULL DEFAULT 0,\n PRIMARY KEY (project_id, org_id, date)\n );\n CREATE TABLE IF NOT EXISTS org_chat_reads ( -- user data (company mode): each user's read cursor in an organization's chat\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n user_id TEXT NOT NULL,\n last_read_id TEXT NOT NULL,\n PRIMARY KEY (project_id, org_id, user_id)\n );\n 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\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n period TEXT NOT NULL,\n warned_at TEXT,\n paused_at TEXT,\n PRIMARY KEY (project_id, org_id, agent_id, period)\n );\n `);\n },\n // Drops the seven tables. LOSES: chat read cursors (each user's \"read up to here\" marks) and\n // the run marks that stop a calendar slot, a ticket change or a budget alert from firing\n // twice — a build with this migration re-registers everything from the files, without\n // backfilling missed slots, and users see every chat message as unread once.\n down(db) {\n db.exec(`\n DROP INDEX IF EXISTS idx_org_ticket_sessions_session;\n DROP INDEX IF EXISTS idx_org_sessions_org;\n DROP TABLE IF EXISTS org_budget_state;\n DROP TABLE IF EXISTS org_chat_reads;\n DROP TABLE IF EXISTS org_chat_state;\n DROP TABLE IF EXISTS org_ticket_state;\n DROP TABLE IF EXISTS org_calendar_state;\n DROP TABLE IF EXISTS org_ticket_sessions;\n DROP TABLE IF EXISTS org_sessions;\n `);\n },\n },\n {\n version: 7,\n name: \"company-mode-channels\",\n // The organization's single group chat became channels: a message lives in\n // `channels/<channel_id>/<date>.jsonl`, so the tail-scan cursor and each user's read\n // cursor are per channel. `org_chat_state` / `org_chat_reads` are dropped for\n // `org_channel_state` / `org_channel_reads`: the tables are renamed and the channel\n // belongs in the primary key, neither of which SQLite does in place. Nothing is carried\n // over: company mode is unreleased, and every row was either rebuildable from the files\n // (the scan cursor) or one pass of \"everything looks unread\" (the read cursor). A\n // predecessor build reads neither table's shape, only its own writes, so this is\n // swap-safe.\n swapSafe: true,\n up(db) {\n db.exec(`\n DROP TABLE IF EXISTS org_chat_state;\n DROP TABLE IF EXISTS org_chat_reads;\n CREATE TABLE IF NOT EXISTS org_channel_state ( -- DERIVED CACHE (company mode): tail-scan byte cursor per channel and day file\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n channel_id TEXT NOT NULL,\n date TEXT NOT NULL,\n offset_bytes INTEGER NOT NULL DEFAULT 0,\n PRIMARY KEY (project_id, org_id, channel_id, date)\n );\n CREATE TABLE IF NOT EXISTS org_channel_reads ( -- user data (company mode): each user's read cursor in one channel\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n channel_id TEXT NOT NULL,\n user_id TEXT NOT NULL,\n last_read_id TEXT NOT NULL,\n PRIMARY KEY (project_id, org_id, channel_id, user_id)\n );\n `);\n },\n // Recreates the two tables under their old names, exactly as migration 6 declared them —\n // EMPTY. LOSES every scan cursor (re-derived by the next pass, which republishes the\n // messages it re-reads) and every read cursor (users see the recent days as unread once).\n down(db) {\n db.exec(`\n DROP TABLE IF EXISTS org_channel_state;\n DROP TABLE IF EXISTS org_channel_reads;\n CREATE TABLE IF NOT EXISTS org_chat_state ( -- DERIVED CACHE (company mode): tail-scan byte cursor per chat day file\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n date TEXT NOT NULL,\n offset_bytes INTEGER NOT NULL DEFAULT 0,\n PRIMARY KEY (project_id, org_id, date)\n );\n CREATE TABLE IF NOT EXISTS org_chat_reads ( -- user data (company mode): each user's read cursor in an organization's chat\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n user_id TEXT NOT NULL,\n last_read_id TEXT NOT NULL,\n PRIMARY KEY (project_id, org_id, user_id)\n );\n `);\n },\n },\n {\n version: 8,\n name: \"company-mode-desk-notices\",\n // Additive: one new table and its index. A ticket change no longer starts a work run at\n // the owner's desk; it is queued here and delivered inside the body of that employee's\n // next calendar sweep. A predecessor build never reads the table, so a rollback survives\n // it — with whatever rows are in it left undelivered.\n swapSafe: true,\n up(db) {\n db.exec(`\n 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\n seq INTEGER PRIMARY KEY AUTOINCREMENT,\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n ticket_id TEXT NOT NULL,\n change TEXT NOT NULL,\n at TEXT NOT NULL\n );\n CREATE INDEX IF NOT EXISTS idx_org_desk_notices_agent ON org_desk_notices(project_id, org_id, agent_id);\n `);\n },\n // LOSES every queued notice: the ticket changes an employee has not been told about yet.\n // The change itself is in the ticket file and its history either way; what\n // goes is the \"Since your last sweep\" line that would have named it.\n down(db) {\n db.exec(`\n DROP INDEX IF EXISTS idx_org_desk_notices_agent;\n DROP TABLE IF EXISTS org_desk_notices;\n `);\n },\n },\n];\n\n/** The highest version this build knows how to reach. */\nexport const LATEST_VERSION: number = MIGRATIONS.reduce((n, m) => Math.max(n, m.version), 0);\n\n/** How far this database has been migrated. Unstamped (pre-migrations) databases read 0. */\nexport function schemaVersion(db: DatabaseSync): number {\n const row = db.prepare(\"PRAGMA user_version\").get() as { user_version: number } | undefined;\n return row?.user_version ?? 0;\n}\n\nexport class IrreversibleMigrationError extends Error {\n constructor(readonly migration: Migration) {\n super(\n `migration ${migration.version} (${migration.name}) declares no down and cannot be rolled back. ` +\n `Restore the database from a backup taken before it was applied.`,\n );\n this.name = \"IrreversibleMigrationError\";\n }\n}\n\nexport class RestartRequiredError extends Error {\n constructor(readonly migration: Migration) {\n super(\n `migration ${migration.version} (${migration.name}) is restart-only and cannot be applied ` +\n `while a pushed platform boots: it is not safe to leave behind if this boot is rolled back. ` +\n `Restart the runtime on a build that carries it, then push again.`,\n );\n this.name = \"RestartRequiredError\";\n }\n}\n\n/**\n * Applies every migration this database has not reached yet, in order.\n *\n * Each migration and its version stamp commit together, so an interrupted run leaves the\n * database at the last version that fully applied — never half-migrated. Already-current\n * databases do no work and touch nothing.\n *\n * `swapPath` marks the caller as a booting pushed platform: the first pending migration\n * that is not `swapSafe` throws RestartRequiredError BEFORE anything is applied, so the\n * push is refused whole rather than partially landed.\n */\nexport function migrate(\n db: DatabaseSync,\n { swapPath = false }: { swapPath?: boolean } = {},\n): { from: number; to: number; applied: readonly string[] } {\n const from = schemaVersion(db);\n const pending = [...MIGRATIONS]\n .sort((a, b) => a.version - b.version)\n .filter((m) => m.version > from);\n if (swapPath) {\n const blocked = pending.find((m) => !m.swapSafe);\n if (blocked) throw new RestartRequiredError(blocked);\n }\n const applied: string[] = [];\n for (const m of pending) {\n db.exec(\"BEGIN\");\n try {\n m.up(db);\n // PRAGMA takes no bound parameter; the value is this file's own integer literal.\n db.exec(`PRAGMA user_version = ${m.version}`);\n db.exec(\"COMMIT\");\n } catch (err) {\n db.exec(\"ROLLBACK\");\n throw new Error(`migration ${m.version} (${m.name}) failed: ${String(err)}`, { cause: err });\n }\n applied.push(m.name);\n }\n return { from, to: schemaVersion(db), applied };\n}\n\n/**\n * Reverts the database DOWN to `targetVersion`, newest migration first.\n *\n * An operator's tool, and a destructive one — see each migration's `down` for what its rows\n * were. Deliberately not reachable from the swap path: a failed platform boot reverts the\n * PLATFORM, never the schema (module doc).\n *\n * Refused whole, before anything runs, if any migration in range declares no `down`: a\n * partial rollback would leave the database at a version whose meaning nobody wrote down.\n * Each `down` commits with its version stamp, so an interrupted run stops at a real version.\n */\nexport function rollbackTo(\n db: DatabaseSync,\n targetVersion: number,\n): { from: number; to: number; reverted: readonly string[] } {\n const from = schemaVersion(db);\n if (targetVersion < 0) throw new Error(`target version ${targetVersion} is negative`);\n if (targetVersion > from) {\n throw new Error(`database is at version ${from}, which is already below ${targetVersion}`);\n }\n const toRevert = [...MIGRATIONS]\n .filter((m) => m.version > targetVersion && m.version <= from)\n .sort((a, b) => b.version - a.version);\n const blocked = toRevert.find((m) => m.down === null);\n if (blocked) throw new IrreversibleMigrationError(blocked);\n\n const reverted: string[] = [];\n for (const m of toRevert) {\n db.exec(\"BEGIN\");\n try {\n m.down!(db);\n // Versions are contiguous, so the predecessor of `m` is exactly m.version - 1.\n db.exec(`PRAGMA user_version = ${m.version - 1}`);\n db.exec(\"COMMIT\");\n } catch (err) {\n db.exec(\"ROLLBACK\");\n throw new Error(`rollback of migration ${m.version} (${m.name}) failed: ${String(err)}`, {\n cause: err,\n });\n }\n reverted.push(m.name);\n }\n return { from, to: schemaVersion(db), reverted };\n}\n","/**\n * SQLite table-creation SQL.\n *\n * SQLite stores only indexes and aggregates: users / login sessions / Project authorization /\n * Agent & Session indexes / usage summaries / error records / UI preferences. Agent State,\n * Trace, and Workspace still follow the local directory-based storage rules.\n * Product not yet released: no migration branches — everything is CREATE IF NOT EXISTS, formed\n * once. The one exception: columns added to an existing table after release of a web.db are\n * ALTERed in by the idempotent per-column guard in database.ts (ensureColumn), since CREATE\n * TABLE IF NOT EXISTS never touches an existing table. A *reshaped* index follows the same\n * rule under a new name, with the superseded one dropped on open (idx_usage_session →\n * idx_usage_session_ts): CREATE INDEX IF NOT EXISTS never rebuilds an existing index either.\n */\n\nexport const SCHEMA_SQL = `\nCREATE TABLE IF NOT EXISTS users (\n user_id TEXT PRIMARY KEY, -- semantic id doubles as login name: ^[a-z][a-z0-9_-]{1,31}$\n password_hash TEXT NOT NULL, -- scrypt$N$r$p$salt$hash(base64)\n is_admin INTEGER NOT NULL DEFAULT 0, -- 1 for the built-in admin (seeded at startup)\n password_is_initial INTEGER NOT NULL DEFAULT 0, -- 1=initial password (seeded/admin-set); cleared once the user changes it\n display_name TEXT, -- nickname shown in place of user_id (1-32 characters); NULL = never set, surfaces show the id\n avatar TEXT, -- avatar as a data URL (image/png|jpeg|webp, <= 131072 characters); NULL = never set, surfaces draw the letter placeholder\n created_at TEXT NOT NULL\n);\n-- Server-side sessions backing the HttpOnly cookie: the cookie carries a 32-byte random\n-- token, the row stores only its sha256. A session outlives a restart (it is on disk), which\n-- is why the model is a row and not a signed statement.\nCREATE TABLE IF NOT EXISTS auth_sessions (\n token_hash TEXT PRIMARY KEY, -- sha256(token) hex; the cookie stores only the raw token\n user_id TEXT NOT NULL REFERENCES users(user_id) ON DELETE CASCADE,\n created_at TEXT NOT NULL,\n expires_at TEXT NOT NULL, -- 30-day sliding renewal, topped up in place when <29 days remain\n via TEXT -- 'password'|'desktop'|'setup'|'cli'; NULL = legacy (password)\n);\n-- deleteExpired runs on every login and mint, deleteByUser on every admin reset; without\n-- these both scan the whole table.\nCREATE INDEX IF NOT EXISTS idx_auth_sessions_expires ON auth_sessions(expires_at);\nCREATE INDEX IF NOT EXISTS idx_auth_sessions_user ON auth_sessions(user_id);\n\nCREATE TABLE IF NOT EXISTS projects (\n project_id TEXT PRIMARY KEY, -- directory name doubles as id; display name lives in project_config.toml\n owner_user_id TEXT NOT NULL REFERENCES users(user_id),\n created_at TEXT NOT NULL\n);\nCREATE TABLE IF NOT EXISTS project_members ( -- member grants only; owners are not stored here\n project_id TEXT NOT NULL REFERENCES projects(project_id) ON DELETE CASCADE,\n user_id TEXT NOT NULL REFERENCES users(user_id) ON DELETE CASCADE,\n created_at TEXT NOT NULL,\n PRIMARY KEY (project_id, user_id)\n);\nCREATE TABLE IF NOT EXISTS agents ( -- index only; name/description live in system_config.yaml\n project_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n created_at TEXT NOT NULL,\n PRIMARY KEY (project_id, agent_id)\n);\nCREATE TABLE IF NOT EXISTS sessions (\n session_id TEXT PRIMARY KEY,\n project_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n provider TEXT NOT NULL, -- provider group of the session model (paired with model_id as a model reference)\n model_id TEXT NOT NULL, -- upstream model id (sent to AgentHub as-is; never concatenate <provider>/<id>)\n workspace TEXT NOT NULL,\n approval_mode TEXT NOT NULL DEFAULT 'allow-all', -- allow-all|deny-all|read-only|always-ask\n thinking_level TEXT, -- level pinned for THIS session (none|low|medium|high|xhigh|max); NULL=not pinned, runs follow the Agent config\n title TEXT, -- auto-generated by the model after the first exchange; NULL=not yet (frontend shows \"New chat\")\n archived_at TEXT, -- archive time; NULL=not archived (shown by default; archived ones move under \"Archived\")\n client TEXT, -- creating client: 'web' (created via the Web App) | 'cli' (adopted from a CLI Trace); NULL = legacy row, treated as web\n has_trace INTEGER NOT NULL DEFAULT 0, -- cache: a Trace record exists (set at task start / adoption / subagent registration; lazily backfilled by list hydration)\n fork_count INTEGER NOT NULL DEFAULT 0, -- monotonically allocated child-fork number for this source Session; never decremented when a fork is deleted\n last_active_at TEXT, -- last activity this server drove for the session (ISO; stamped once when a run starts and once when it ends, initialized to created_at); monotonic, never moves backwards; NULL only before openDatabase's one-time backfill\n created_at TEXT NOT NULL\n); -- the subagent/schedule/benchmark SOURCE is NOT stored: session_meta in the Trace is the single source of truth (see runtime/session-sources.ts); \"client\" is a different, DB-only axis (who created the row)\nCREATE INDEX IF NOT EXISTS idx_sessions_agent_created ON sessions(project_id, agent_id, created_at DESC);\nCREATE TABLE IF NOT EXISTS usage_records (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n ts TEXT NOT NULL,\n date TEXT NOT NULL, -- local date yyyy-mm-dd (aggregation key; same convention as Trace date directories)\n project_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n session_id TEXT NOT NULL, -- top-level Session (child-session usage counts toward its main Session)\n origin_session_id TEXT, -- immediate source child Session (last of the origin chain); NULL=main session\n provider TEXT NOT NULL, -- provider group: paired with model_id as the attribution key; always GROUP BY provider, model_id\n model_id TEXT NOT NULL, -- upstream model id (paired with provider; same model_id across providers aggregates separately)\n cache_read INTEGER NOT NULL,\n cache_write INTEGER NOT NULL,\n output INTEGER NOT NULL,\n total INTEGER NOT NULL, -- from token_usage.request (one row per Request)\n status TEXT NOT NULL DEFAULT 'completed' -- request outcome: completed=success (with tokens); others=failure (0 tokens, for success rate)\n); -- cost is not stored: computed at query time from current pricing\nCREATE INDEX IF NOT EXISTS idx_usage_project_date ON usage_records(project_id, date);\nCREATE INDEX IF NOT EXISTS idx_usage_session_ts ON usage_records(session_id, ts); -- (session_id) alone was idx_usage_session (dropped on open): ts makes the last_active_at backfill's MAX(ts) a covering index scan instead of a random row lookup per usage record\nCREATE TABLE IF NOT EXISTS error_records ( -- server-side error capture (the Costs page's \"Errors\" tab)\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n ts TEXT NOT NULL,\n date TEXT NOT NULL, -- local date yyyy-mm-dd (same convention as usage_records)\n project_id TEXT, -- nullable: sign-in/registration and process-level errors have no Project context\n agent_id TEXT,\n session_id TEXT,\n source TEXT NOT NULL, -- http | session | usage | title | subagent | process | llm | environment | compaction | schedule | messaging\n kind TEXT NOT NULL, -- expected (HttpError, business 4xx) | unexpected (500/runtime)\n code TEXT NOT NULL, -- HttpError.code / internal / session_run_failed / ...\n status INTEGER, -- HTTP status code; NULL for non-HTTP sources\n message TEXT NOT NULL -- truncated to 500 chars (no stack stored: stacks go to logs only)\n);\nCREATE INDEX IF NOT EXISTS idx_error_project_date ON error_records(project_id, date);\nCREATE TABLE IF NOT EXISTS schedule_state ( -- schedule runtime state (files are declarative intent; the system never writes back)\n project_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n name TEXT NOT NULL, -- file name (without .toml) doubles as the identifier\n creator_user_id TEXT, -- creator (recorded on API create; hand-edited file reconciliation falls back to the Project owner)\n start_at_ms INTEGER NOT NULL, -- defines identity: a start_at change counts as a new task instance, resetting fire state\n def_hash TEXT NOT NULL, -- file content fingerprint: any change clears the invalid flag (the file takes effect again after edits)\n last_slot_ms INTEGER, -- latest due slot already consumed (advances on fire or skip; no re-fire across restarts)\n last_fired_at TEXT, -- last actual fire time (for display)\n fired_once INTEGER NOT NULL DEFAULT 0, -- one-shot task has fired\n missed INTEGER NOT NULL DEFAULT 0, -- one-shot task was missed (flagged by startup/registration reconciliation; not backfilled)\n invalid_reason TEXT, -- invalidation reason (e.g. the bound Session was deleted); NULL=healthy\n PRIMARY KEY (project_id, agent_id, name)\n);\nCREATE TABLE IF NOT EXISTS messaging_bindings ( -- Session ↔ messaging-channel bot bindings (runtime/messaging/ holds the long connections)\n session_id TEXT NOT NULL, -- a Session keeps at most one saved config PER channel (composite PK below); at most ONE of them is enabled at a time (route-enforced, 409 another_channel_enabled), and enabling is what binds the account to this Session\n channel TEXT NOT NULL, -- messaging channel discriminator ('feishu' | 'telegram' | 'qq' | 'wechat')\n account_id TEXT NOT NULL, -- channel-scoped bot/app identity (feishu: app_id; telegram: the bot token's numeric id; qq: the bot's App ID; wechat: the scanned bot id); NOT unique — any number of Sessions may keep the same account saved side by side, each with its own config and last-chat memory; only ENABLING is exclusive (route-enforced, 409 account_enabled_elsewhere: one account has one event stream, two live connections on it would race)\n config_json TEXT NOT NULL, -- channel-specific credentials/config JSON (feishu: appId/appSecret/baseDomain; telegram: botToken; qq: appId/appSecret; wechat: botId/botToken/baseUrl/userId); secrets plaintext at rest (same trade-off as the proxy address in server_settings), masked at every API surface; a cleared secret is stored as \"\" (the row and its account identity stay)\n enabled INTEGER NOT NULL DEFAULT 0, -- INTENT state (the connection's runtime status stays in memory): new bindings start disabled — saving credentials never opens a connection, the explicit state toggle does\n line_per_message INTEGER NOT NULL DEFAULT 0, -- delivery preference: 1 = every non-blank line of a relayed assistant reply is sent as its own message (a reply written as spoken lines arrives as spoken lines), 0 = one message per reply. Channel-agnostic, so it lives here rather than in config_json, which each connector owns\n final_reply_only INTEGER NOT NULL DEFAULT 0, -- delivery preference: 1 = a run's intermediate assistant messages are held and only its LAST completed one is sent, at the run's end, 0 = every completed assistant message mirrors the moment it completes. Channel-agnostic like the column above and independent of it: with both set, that one final text is the one split per line\n render_markdown INTEGER NOT NULL DEFAULT 1, -- delivery preference: 1 = a relayed reply's Markdown is rendered in the channel's own markup (Telegram HTML, a Feishu card, QQ markdown, the subset WeChat itself reads), 0 = the reply's characters are sent as written. DEFAULT 1 because the model writes Markdown and showing it raw was the defect; the per-channel subsets and the plain-text fallback live in the connectors\n last_chat_id TEXT, -- most recent inbound chat (NULL until the bot is messaged once; replies and test messages target it); CONNECTOR-OPAQUE, not necessarily a bare chat id — telegram appends the forum topic (see telegram-connector.ts chatRefOf), so only that channel's connector may interpret it\n last_chat_is_direct INTEGER NOT NULL DEFAULT 1, -- 1 = direct chat (reply by chat id), 0 = group chat (prefer reply-to-message)\n last_inbound_message_id TEXT, -- channel id of the most recently PROCESSED inbound message (NULL until one arrives); the durable half of the bridge's redelivery guard, so a channel replaying an event this server already turned into a Task after a restart does not run it twice\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n PRIMARY KEY (session_id, channel)\n);\nCREATE INDEX IF NOT EXISTS idx_messaging_by_account ON messaging_bindings(channel, account_id); -- serves the enable guard's by-account lookup; deliberately NOT unique, unlike its predecessor idx_messaging_account (dropped on open) which made an account exclusive to one Session forever\nCREATE TABLE IF NOT EXISTS ui_prefs (\n user_id TEXT PRIMARY KEY REFERENCES users(user_id) ON DELETE CASCADE,\n prefs_json TEXT NOT NULL -- {theme?, lastProjectId?, ...} free-form JSON\n);\nCREATE TABLE IF NOT EXISTS server_settings ( -- admin-level server-global settings (GET/PUT /api/admin/settings)\n key TEXT PRIMARY KEY, -- setting name, e.g. 'proxy_for_app'\n value TEXT NOT NULL -- JSON-encoded value; an absent row means the setting's built-in default\n);\nCREATE TABLE IF NOT EXISTS machine ( -- this server's OWN identity, minted here and never assigned from outside (what 'penguin server status' reports)\n singleton INTEGER PRIMARY KEY CHECK (singleton = 1), -- exactly one row, enforced by the schema rather than by convention\n machine_id TEXT NOT NULL -- 16 base64url characters; what every stored reference to this machine points at\n);\nCREATE TABLE IF NOT EXISTS machines ( -- one row per machine this server installed on or reached (machines/service.ts)\n address TEXT PRIMARY KEY, -- 'ssh:<alias>'\n machine_id TEXT, -- that machine's own id, once heard\n version TEXT, -- what this server last installed there; NULL = never\n installed_at TEXT,\n session_pid INTEGER, -- the ssh session this server holds to it; what a successor App closes after a hot swap\n remote_port INTEGER, -- its server's port over there, as of the last connect\n platform TEXT -- linux | darwin | win32, as the install found it: the shell dialect the status probe speaks to it in\n);\nCREATE TABLE IF NOT EXISTS machine_project ( -- which machines a Project uses; no row = none yet. Follows the Project out, like project_members\n project_id TEXT PRIMARY KEY REFERENCES projects(project_id) ON DELETE CASCADE,\n addresses TEXT NOT NULL -- JSON array of 'ssh:<alias>'\n);\nCREATE TABLE IF NOT EXISTS trace_files ( -- DERIVED CACHE of the on-disk Trace tree (services/trace-index.ts): the directories stay the single source of truth, every row is rebuildable from disk, and a row is never authority for absence — consumers reconcile + retry on a miss, so a stale index costs one extra scan, never a false 404\n project_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n file_index INTEGER NOT NULL, -- shard index NNN of <session_id>_NNN.jsonl (name/path are reconstructed from the row, never stored: the data root may move)\n date TEXT NOT NULL, -- date directory name (local yyyy-mm-dd)\n size_bytes INTEGER NOT NULL, -- last observed size (listings stat-refresh the returned page and write back; an actively-appended shard may lag in between)\n page_stats TEXT, -- cached message-window scan state at this shard's END (services/message-window.ts ShardPrefixRecord JSON); immutable shards only, NULL = not yet computed, nulled whenever size_bytes changes\n PRIMARY KEY (project_id, agent_id, session_id, file_index)\n);\nCREATE INDEX IF NOT EXISTS idx_trace_files_agent_date ON trace_files(project_id, agent_id, date);\nCREATE INDEX IF NOT EXISTS idx_trace_files_session ON trace_files(session_id);\nCREATE TABLE IF NOT EXISTS trace_sessions ( -- per-session facts read ONCE at registration from the earliest shard's head (same derived-cache rules as trace_files; listing needs zero head-reads)\n session_id TEXT PRIMARY KEY,\n project_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n source TEXT, -- session_meta origin: 'subagent' | 'schedule' | 'benchmark' | NULL = user-created (or head not yet readable)\n workspace TEXT NOT NULL DEFAULT '',\n title TEXT, -- first-prompt fallback title (sessions.title always wins when present)\n provider TEXT, -- model reference from session_meta (CLI adoption reads it from here; NULL = meta unreadable / legacy without provider)\n model_id TEXT,\n first_ts TEXT, -- first record's timestamp (adoption's createdAt fallback when the id embeds no time)\n meta_read INTEGER NOT NULL DEFAULT 0 -- 1 once the head parsed; 0 = facts unknown, retried by the next reconcile that touches the session\n);\nCREATE INDEX IF NOT EXISTS idx_trace_sessions_agent ON trace_sessions(project_id, agent_id);\nCREATE TABLE IF NOT EXISTS org_sessions ( -- DERIVED CACHE (company mode): desk sessions, rebuilt from each organization's desks.toml (current + previous); trigger_hop is mention-chain accounting and reads 0 after a rebuild\n session_id TEXT PRIMARY KEY,\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n current INTEGER NOT NULL DEFAULT 1,\n trigger_hop INTEGER NOT NULL DEFAULT 0\n);\nCREATE INDEX IF NOT EXISTS idx_org_sessions_org ON org_sessions(project_id, org_id);\nCREATE TABLE IF NOT EXISTS org_ticket_sessions ( -- DERIVED CACHE (company mode): ticket <-> contributing session, rebuilt from each ticket's Sessions header\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n ticket_id TEXT NOT NULL,\n session_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n trigger_hop INTEGER NOT NULL DEFAULT 0,\n PRIMARY KEY (project_id, org_id, ticket_id, session_id)\n);\nCREATE INDEX IF NOT EXISTS idx_org_ticket_sessions_session ON org_ticket_sessions(session_id);\nCREATE TABLE IF NOT EXISTS org_calendar_state ( -- calendar run state (company mode; the files are declarative intent), same rules as schedule_state\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n name TEXT NOT NULL,\n start_at_ms INTEGER NOT NULL,\n def_hash TEXT NOT NULL,\n last_slot_ms INTEGER,\n last_fired_at TEXT,\n fired_once INTEGER NOT NULL DEFAULT 0,\n missed INTEGER NOT NULL DEFAULT 0,\n invalid_reason TEXT,\n last_outcome TEXT,\n PRIMARY KEY (project_id, org_id, agent_id, name)\n);\nCREATE 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\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n ticket_id TEXT NOT NULL,\n status TEXT NOT NULL,\n owner TEXT NOT NULL DEFAULT '',\n blocked TEXT NOT NULL DEFAULT '',\n blocked_by TEXT NOT NULL DEFAULT '',\n PRIMARY KEY (project_id, org_id, ticket_id)\n);\nCREATE TABLE IF NOT EXISTS org_channel_state ( -- DERIVED CACHE (company mode): tail-scan byte cursor per channel and day file\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n channel_id TEXT NOT NULL,\n date TEXT NOT NULL,\n offset_bytes INTEGER NOT NULL DEFAULT 0,\n PRIMARY KEY (project_id, org_id, channel_id, date)\n);\nCREATE TABLE IF NOT EXISTS org_channel_reads ( -- user data (company mode): each user's read cursor in one channel\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n channel_id TEXT NOT NULL,\n user_id TEXT NOT NULL,\n last_read_id TEXT NOT NULL,\n PRIMARY KEY (project_id, org_id, channel_id, user_id)\n);\nCREATE 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\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n period TEXT NOT NULL,\n warned_at TEXT,\n paused_at TEXT,\n PRIMARY KEY (project_id, org_id, agent_id, period)\n);\nCREATE 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\n seq INTEGER PRIMARY KEY AUTOINCREMENT,\n project_id TEXT NOT NULL,\n org_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n ticket_id TEXT NOT NULL,\n change TEXT NOT NULL,\n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AS,oBAAoB,IAAwB;AACnD,KAAG,KAAK,OAAO;AACf,MAAI;AACF,QAAI,aAAa,IAAI,YAAY,kBAAkB,MAAM,GAAG;AAC1D,SAAG;AAAA,QACD;AAAA;AAAA;AAAA;AAAA,MAIF;AAAA,IACF;AACA,OAAG,KAAK,QAAQ;AAAA,EAClB,SAAS,KAAK;AACZ,OAAG,KAAK,UAAU;AAClB,UAAM;AAAA,EACR;AACF;AAOO,SAAS,aACd,IACA,OACA,QACA,KACS;AACT,QAAM,OAAO,GAAG,QAAQ,qBAAqB,KAAK,GAAG,EAAE,IAAI;AAC3D,MAAI,KAAK,KAAK,CAAC,MAAM,EAAE,SAAS,MAAM,EAAG,QAAO;AAChD,KAAG,KAAK,eAAe,KAAK,eAAe,MAAM,IAAI,GAAG,EAAE;AAC1D,SAAO;AACT;","names":[]}
@@ -0,0 +1,56 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
5
+ var __typeError = (msg) => {
6
+ throw TypeError(msg);
7
+ };
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
11
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
12
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
13
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
14
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
15
+ var __runInitializers = (array, flags, self, value) => {
16
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
17
+ return value;
18
+ };
19
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
20
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
21
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
22
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
23
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
24
+ return __privateGet(this, extra);
25
+ }, set [name](x) {
26
+ return __privateSet(this, extra, x);
27
+ } }, name));
28
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
29
+ for (var i = decorators.length - 1; i >= 0; i--) {
30
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
31
+ if (k) {
32
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
33
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
34
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
35
+ }
36
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
37
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
38
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
39
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
40
+ }
41
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
42
+ };
43
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
44
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
45
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
46
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
47
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
48
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
49
+
50
+ export {
51
+ __decoratorStart,
52
+ __runInitializers,
53
+ __decorateElement,
54
+ __publicField
55
+ };
56
+ //# sourceMappingURL=chunk-B5IP37ZQ.js.map
@@ -0,0 +1,7 @@
1
+ // src/api/types.ts
2
+ var TICKET_SLUG_PATTERN = /^[a-z]+(?:-[a-z]+)*$/;
3
+
4
+ export {
5
+ TICKET_SLUG_PATTERN
6
+ };
7
+ //# sourceMappingURL=chunk-L2H3K4DT.js.map