bazilion 0.19.1 → 0.21.0-beta.1

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 (96) hide show
  1. package/dist/cli.js +571 -409
  2. package/dist/cli.js.map +1 -1
  3. package/dist/daemon.js +2144 -917
  4. package/dist/daemon.js.map +1 -1
  5. package/dist/migrations/0001_init.sql +46 -0
  6. package/dist/migrations/0002_device_token_scopes.sql +8 -0
  7. package/dist/migrations/0003_web_pairing_tokens.sql +18 -0
  8. package/dist/web/client/assets/{ChatPane-DCyGcqdh.js → ChatPane--0BWZYHD.js} +1 -1
  9. package/dist/web/client/assets/{ConfirmDialog-C908TxS5.js → ConfirmDialog-D9AiLH_Z.js} +1 -1
  10. package/dist/web/client/assets/{FieldRow-CELqI-1V.js → FieldRow-Cd0EUpYd.js} +1 -1
  11. package/dist/web/client/assets/{ProductionTeamPolicyEditor-DnTcWhG8.js → ProductionTeamPolicyEditor-BR5_1Wyv.js} +1 -1
  12. package/dist/web/client/assets/{ProfileCommunicationEditor-BVIEaW3s.js → ProfileCommunicationEditor-K2wGbGky.js} +1 -1
  13. package/dist/web/client/assets/{ResultSourceConversation-4gbZCh_s.js → ResultSourceConversation-Y9VTd-nz.js} +1 -1
  14. package/dist/web/client/assets/{TeamTabs-V17b45X5.js → TeamTabs-Yuc_lSZ9.js} +1 -1
  15. package/dist/web/client/assets/{TemplatesTabs-BMK3Qok_.js → TemplatesTabs-Pj00chC7.js} +1 -1
  16. package/dist/web/client/assets/{UnsavedChangesGuard-BaE-UzyS.js → UnsavedChangesGuard-BSfJZH7E.js} +1 -1
  17. package/dist/web/client/assets/{_id-Bvh5LyUv.js → _id-B4yPnTNN.js} +1 -1
  18. package/dist/web/client/assets/{_id-BVANQm00.js → _id-CUbb0F4l.js} +1 -1
  19. package/dist/web/client/assets/{_id-BU1l9gP7.js → _id-D2l33vb6.js} +1 -1
  20. package/dist/web/client/assets/{_id-CArZR-IO.js → _id-DCFRZAJN.js} +1 -1
  21. package/dist/web/client/assets/{_id-tUkSe5li.js → _id-UniNI3bQ.js} +1 -1
  22. package/dist/web/client/assets/{activity-CWCnqjqj.js → activity-C5QG0Wgv.js} +1 -1
  23. package/dist/web/client/assets/{agents-CdCnhH06.js → agents-CQo9V1lc.js} +1 -1
  24. package/dist/web/client/assets/{agents-CX4STmGK.js → agents-DVVPYxPM.js} +1 -1
  25. package/dist/web/client/assets/{approvals-CnNpwG78.js → approvals-DQz6TJE8.js} +1 -1
  26. package/dist/web/client/assets/{attention-CEE-wWrx.js → attention-BtCLaWhZ.js} +1 -1
  27. package/dist/web/client/assets/chevron-right-BGFokHDA.js +1 -0
  28. package/dist/web/client/assets/{config-CSEtI-dq.js → config-DuhKvD0X.js} +1 -1
  29. package/dist/web/client/assets/{inbox-MYnBtPdF.js → inbox-Cr7iGkrF.js} +1 -1
  30. package/dist/web/client/assets/{index-Ct31TjS-.js → index-ChXVa4eb.js} +2 -2
  31. package/dist/web/client/assets/{learning-BIR5FTgQ.js → learning-5eO_SZUP.js} +1 -1
  32. package/dist/web/client/assets/{login-DIeceuOs.js → login-Cn9mf44C.js} +1 -1
  33. package/dist/web/client/assets/{mcp-CX3kJpGu.js → mcp-0COajQD4.js} +1 -1
  34. package/dist/web/client/assets/{members-DlhSjye1.js → members-9eTmy1QM.js} +1 -1
  35. package/dist/web/client/assets/{memory-CsDd6b2l.js → memory-CExQd_vP.js} +1 -1
  36. package/dist/web/client/assets/{policy-DkWDhG0x.js → policy-B-zDlt_G.js} +1 -1
  37. package/dist/web/client/assets/{results-BHdhNHJJ.js → results-BUmKkuHo.js} +1 -1
  38. package/dist/web/client/assets/review-BUTz_zRX.js +1 -0
  39. package/dist/web/client/assets/{routes-DtYD4WJL.js → routes-b1FscQsH.js} +1 -1
  40. package/dist/web/client/assets/{services-WUlW7oEo.js → services-D-RdMc8g.js} +1 -1
  41. package/dist/web/client/assets/{skills-jNoUfUSZ.js → skills-CNbkY2ji.js} +1 -1
  42. package/dist/web/client/assets/{teams-D3FaSKE7.js → teams-Dn9o_-P-.js} +1 -1
  43. package/dist/web/client/assets/{teams-C1kYRrtP.js → teams-H4OTWt8E.js} +1 -1
  44. package/dist/web/client/assets/{telegram-D86AO6V9.js → telegram-BnM54CPN.js} +1 -1
  45. package/dist/web/client/assets/tokens-C-I23fVZ.js +1 -0
  46. package/dist/web/client/assets/{triggers-yEfWnQ_K.js → triggers-DG9YoC7B.js} +1 -1
  47. package/dist/web/client/assets/verifications-CzToBSUN.js +2 -0
  48. package/dist/web/client/assets/{welcome-D8IbF_P0.js → welcome-REp-dEfY.js} +1 -1
  49. package/dist/web/client/assets/{x-CXKABZ7C.js → x-C-BpLdcp.js} +1 -1
  50. package/dist/web/server/assets/{_id-bVispdh-.js → _id-Bazctexc.js} +1 -1
  51. package/dist/web/server/assets/{_id-Dab2CVtO2.js → _id-BjvOb4CK2.js} +1 -1
  52. package/dist/web/server/assets/{_id-DL-SnSnK.js → _id-Bn0w00AG.js} +1 -1
  53. package/dist/web/server/assets/{_id-D2bDA1iV.js → _id-DFf_uQiI.js} +1 -1
  54. package/dist/web/server/assets/{_tanstack-start-manifest_v-BcTOb0oj.js → _tanstack-start-manifest_v-BfURdqEL.js} +78 -78
  55. package/dist/web/server/assets/{activity-CLDAy6rk.js → activity-j_Enmf3L.js} +1 -1
  56. package/dist/web/server/assets/{agents-CdB2kuNN.js → agents-BAi0dE66.js} +1 -1
  57. package/dist/web/server/assets/{agents-DfHcb2H2.js → agents-BHUbTrm7.js} +1 -1
  58. package/dist/web/server/assets/{approvals-Bq846WaP.js → approvals-BcUm6IOo.js} +1 -1
  59. package/dist/web/server/assets/{attention-Sm-U7s_0.js → attention-BQBa0Bu5.js} +1 -1
  60. package/dist/web/server/assets/{auth-PB5dVyvX.js → auth-PDNSxrT-.js} +1 -1
  61. package/dist/web/server/assets/{config-BNGTBu80.js → config-Cf7hhsUR.js} +1 -1
  62. package/dist/web/server/assets/{daemon-client-CWQvck6B.js → daemon-client-DY4jE6KU.js} +15 -0
  63. package/dist/web/server/assets/{git-review-C_h_tezf.js → git-review-RvzReZyD.js} +1 -1
  64. package/dist/web/server/assets/{inbox-DJoU-bla.js → inbox-Du1guYth.js} +1 -1
  65. package/dist/web/server/assets/{learning-DVb0I_3Z.js → learning-CjcixPRH.js} +1 -1
  66. package/dist/web/server/assets/{mcp-CeZqOiDG.js → mcp-BCalFLvt.js} +1 -1
  67. package/dist/web/server/assets/{members-CcYjuqxB.js → members-C4TpK50B.js} +1 -1
  68. package/dist/web/server/assets/{memory-CH2yNT89.js → memory-CLZs-XRY.js} +1 -1
  69. package/dist/web/server/assets/{policy-DrRKinMr.js → policy-BrIXpwxZ.js} +1 -1
  70. package/dist/web/server/assets/publications-BrX3-WJf.js +57 -0
  71. package/dist/web/server/assets/{results-fT2zyiJx.js → results-CJR6dNzB.js} +1 -1
  72. package/dist/web/server/assets/{review-CvUPk4HA.js → review-CRHiZfC8.js} +1 -1
  73. package/dist/web/server/assets/{review-DYcYdUTv.js → review-Dqdts12v.js} +205 -3
  74. package/dist/web/server/assets/{review-packets-e36PsTSX.js → review-packets-D3bZ7QYU.js} +1 -1
  75. package/dist/web/server/assets/{router-NYhuYQCd.js → router-CyZ-GH8M.js} +4 -4
  76. package/dist/web/server/assets/{routes-RdppWPiW.js → routes-DizvfkfZ.js} +1 -1
  77. package/dist/web/server/assets/{services-Dgu7dcTC.js → services-DDRj180j.js} +1 -1
  78. package/dist/web/server/assets/{skills-DL7UIWa8.js → skills-Bck9L5oo.js} +1 -1
  79. package/dist/web/server/assets/{teams-DiC-MBg4.js → teams-CSqR5mWl.js} +1 -1
  80. package/dist/web/server/assets/{teams-Cmn7mdx9.js → teams-C_PicOsj.js} +1 -1
  81. package/dist/web/server/assets/{telegram-CLOFnLjF.js → telegram-D0odXx1E.js} +1 -1
  82. package/dist/web/server/assets/{tokens-BVva7GHu.js → tokens-B2O0Di4p.js} +1 -1
  83. package/dist/web/server/assets/{tokens-_2hptHP6.js → tokens-BFhrz5qd.js} +1 -1
  84. package/dist/web/server/assets/{tokens-DDwtO15P.js → tokens-DO_eDpv_.js} +96 -3
  85. package/dist/web/server/assets/{triggers-D4orksJq.js → triggers-DtKMYL2r.js} +1 -1
  86. package/dist/web/server/assets/{verification-C1SHMTX8.js → verification-no5BrOeR.js} +1 -1
  87. package/dist/web/server/assets/{verifications-Ci49n2Km.js → verifications-CM-Bbgjt.js} +114 -91
  88. package/dist/web/server/assets/{verifications-C_ycXrPK.js → verifications-DhGe86E1.js} +1 -1
  89. package/dist/web/server/server.js +56 -48
  90. package/dist/worker.js +70 -19
  91. package/dist/worker.js.map +1 -1
  92. package/package.json +3 -3
  93. package/dist/web/client/assets/chevron-right-CvCEwfSl.js +0 -1
  94. package/dist/web/client/assets/review-Dyw47eM1.js +0 -1
  95. package/dist/web/client/assets/tokens-B42KDisP.js +0 -1
  96. package/dist/web/client/assets/verifications-DrHQEQFx.js +0 -2
package/dist/cli.js CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { defineCommand as defineCommand38, runCommand, showUsage } from "citty";
4
+ import { defineCommand as defineCommand39, runCommand, showUsage } from "citty";
5
5
 
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "bazilion",
9
- version: "0.19.1",
9
+ version: "0.21.0-beta.1",
10
10
  description: "Multi-agent runtime CLI \u2014 spawn LLM agents, manage profiles/teams/skills, and run the local daemon.",
11
11
  license: "MIT",
12
12
  repository: {
@@ -203,6 +203,21 @@ function createClient(cfg) {
203
203
  cancel: (requestId) => request("POST", `${base}/${encodeURIComponent(requestId)}/cancel`)
204
204
  };
205
205
  },
206
+ /**
207
+ * Publications to a code host (BAZ-046).
208
+ *
209
+ * One operator decision about a reviewed revision. Nothing here can merge, deploy, force a push or
210
+ * name a remote: the request has a packet, an optional branch and an optional commit message, and the
211
+ * rest is configuration the operator owns.
212
+ */
213
+ publications: (teamId) => {
214
+ const base = `/api/teams/${encodeURIComponent(teamId)}/publications`;
215
+ return {
216
+ list: () => request("GET", base),
217
+ show: (publicationId2) => request("GET", `${base}/${encodeURIComponent(publicationId2)}`),
218
+ create: (input) => request("POST", base, input)
219
+ };
220
+ },
206
221
  /**
207
222
  * Revision-bound review packets (BAZ-043).
208
223
  *
@@ -1372,69 +1387,34 @@ var chatCmd = defineCommand5({
1372
1387
  }
1373
1388
  return;
1374
1389
  }
1390
+ if (bashApprovalMode === "interactive") {
1391
+ console.error(
1392
+ `usage: bazilion agent chat ${args2.id} --message "..." (one-shot) \u2014 for a conversational surface, use the web UI`
1393
+ );
1394
+ process.exitCode = 1;
1395
+ return;
1396
+ }
1375
1397
  console.log(`chatting with ${resolved.agent.name} (${resolved.model})`);
1376
- console.log("(type /exit to quit)");
1398
+ console.log("(type /exit to quit; input is piped, commands run with auto_deny)");
1377
1399
  const rl = createInterface({ input: stdin, output: stdout });
1378
1400
  try {
1379
- if (bashApprovalMode === "interactive") {
1380
- let retryDraft = "";
1381
- while (true) {
1382
- const observed = await client.get(
1383
- `/api/agents/${resolved.agent.id}/sessions/head`
1384
- );
1385
- let line;
1386
- try {
1387
- const answer = rl.question("> ");
1388
- if (retryDraft) {
1389
- rl.write(retryDraft);
1390
- retryDraft = "";
1391
- }
1392
- line = await answer;
1393
- } catch {
1394
- break;
1395
- }
1396
- const trimmed = line.trim();
1397
- if (trimmed === "/exit" || trimmed === "/quit") break;
1398
- if (!trimmed) continue;
1399
- try {
1400
- await streamTurn(client, resolved.agent.id, trimmed, void 0, {
1401
- bashApprovalMode,
1402
- expectedSelection: observed.selection,
1403
- questionPrompt: {
1404
- question: (text2, signal) => rl.question(text2, { signal }),
1405
- write: (line2) => console.log(line2)
1406
- },
1407
- approvalPrompt: {
1408
- question: (question) => rl.question(question),
1409
- write: (output4) => console.log(output4)
1410
- }
1411
- });
1412
- } catch (err) {
1413
- retryDraft = trimmed;
1414
- console.error(
1415
- `error: ${err.message}. Review the preserved draft before retrying.`
1416
- );
1417
- }
1418
- }
1419
- } else {
1420
- rl.setPrompt("> ");
1421
- rl.prompt();
1422
- for await (const line of rl) {
1423
- const trimmed = line.trim();
1424
- if (trimmed === "/exit" || trimmed === "/quit") break;
1425
- if (!trimmed) {
1426
- rl.prompt();
1427
- continue;
1428
- }
1429
- try {
1430
- await streamTurn(client, resolved.agent.id, trimmed, void 0, {
1431
- bashApprovalMode
1432
- });
1433
- } catch (err) {
1434
- console.error(`error: ${err.message}`);
1435
- }
1401
+ rl.setPrompt("> ");
1402
+ rl.prompt();
1403
+ for await (const line of rl) {
1404
+ const trimmed = line.trim();
1405
+ if (trimmed === "/exit" || trimmed === "/quit") break;
1406
+ if (!trimmed) {
1436
1407
  rl.prompt();
1408
+ continue;
1409
+ }
1410
+ try {
1411
+ await streamTurn(client, resolved.agent.id, trimmed, void 0, {
1412
+ bashApprovalMode
1413
+ });
1414
+ } catch (err) {
1415
+ console.error(`error: ${err.message}`);
1437
1416
  }
1417
+ rl.prompt();
1438
1418
  }
1439
1419
  } finally {
1440
1420
  rl.close();
@@ -2303,16 +2283,16 @@ import {
2303
2283
  mkdirSync as mkdirSync2,
2304
2284
  mkdtempSync,
2305
2285
  openSync as openSync2,
2306
- readdirSync,
2307
- readFileSync as readFileSync5,
2286
+ readdirSync as readdirSync2,
2287
+ readFileSync as readFileSync6,
2308
2288
  readSync,
2309
2289
  renameSync as renameSync2,
2310
2290
  rmSync as rmSync2,
2311
2291
  writeFileSync as writeFileSync2
2312
2292
  } from "fs";
2313
2293
  import { tmpdir } from "os";
2314
- import { basename as basename4, dirname as dirname2, isAbsolute, parse, posix, relative, resolve as resolve3 } from "path";
2315
- import { DatabaseSync as DatabaseSync2, backup as sqliteBackup } from "node:sqlite";
2294
+ import { basename as basename4, dirname as dirname3, isAbsolute, parse, posix, relative, resolve as resolve3 } from "path";
2295
+ import { DatabaseSync as DatabaseSync4, backup as sqliteBackup } from "node:sqlite";
2316
2296
  import { Readable } from "stream";
2317
2297
  import { pipeline } from "stream/promises";
2318
2298
  import { Decrypter, Encrypter } from "age-encryption";
@@ -2460,169 +2440,180 @@ function pauseRestoredUserQueue(database) {
2460
2440
 
2461
2441
  // src/backup-schema.ts
2462
2442
  import { createHash } from "crypto";
2463
- var CANONICAL_MIGRATION = "0001_init";
2464
- var CANONICAL_SCHEMA_HASH = "da37324d58fa517941ec0557529d00a7a812413f9fda7e5d611287ad42b47595";
2465
- var CANONICAL_OBJECTS = [
2466
- ["table", "team_coding_environments"],
2467
- ["table", "workspace_writers"],
2468
- ["table", "workspace_resources"],
2469
- ["table", "coding_commands"],
2470
- ["index", "coding_command_history"],
2471
- ["table", "coding_command_logs"],
2472
- ["index", "coding_command_logs_retention"],
2473
- ["index", "coding_command_logs_team_time"],
2474
- ["table", "source_snapshots"],
2475
- ["index", "source_snapshots_retention"],
2476
- ["index", "source_snapshots_team_time"],
2477
- ["table", "review_packets"],
2478
- ["index", "review_packets_team_time"],
2479
- ["index", "review_packets_reviewer_dispatch"],
2480
- ["index", "review_packets_retention"],
2481
- ["table", "review_findings"],
2482
- ["index", "review_findings_packet"],
2483
- ["index", "review_findings_unresolved"],
2484
- ["table", "review_conclusions"],
2485
- ["index", "review_conclusions_packet"],
2486
- ["table", "review_attempts"],
2487
- ["index", "review_attempts_one_open_per_packet"],
2488
- ["index", "review_attempts_lease"],
2489
- ["table", "verification_requests"],
2490
- ["index", "verification_requests_team_time"],
2491
- ["index", "verification_requests_recipient_dispatch"],
2492
- ["index", "verification_requests_retention"],
2493
- ["table", "verification_checks"],
2494
- ["table", "verification_attempts"],
2495
- ["index", "verification_attempts_one_open_per_request"],
2496
- ["index", "verification_attempts_lease"],
2497
- ["table", "verification_check_outcomes"],
2498
- ["index", "verification_check_outcomes_command"],
2499
- ["table", "notification_settings"],
2500
- ["table", "notification_receipts"],
2501
- ["index", "notification_receipts_state"],
2502
- ["index", "notification_receipts_time"],
2503
- ["table", "agent_questions"],
2504
- ["table", "question_receipt_key"],
2505
- ["index", "agent_questions_one_pending"],
2506
- ["index", "agent_questions_agent_time"],
2507
- ["table", "user_queue_controls"],
2508
- ["table", "user_queue_items"],
2509
- ["table", "user_queue_attachments"],
2510
- ["index", "user_queue_agent_order"],
2511
- ["index", "user_queue_status"],
2512
- ["index", "agent_conversations_agent_time"],
2513
- ["table", "agent_conversations"],
2514
- ["table", "agent_conversation_selection"],
2515
- ["index", "agent_results_team_time"],
2516
- ["index", "agent_results_session_source"],
2517
- ["index", "agent_results_packet_source"],
2518
- ["index", "agent_triggers_agent"],
2519
- ["index", "agent_triggers_enabled"],
2520
- ["index", "agent_loop_break_events_agent_time"],
2521
- ["index", "agent_loop_break_events_team_time"],
2522
- ["index", "agent_lesson_proposals_agent_status_time"],
2523
- ["index", "agent_lesson_proposals_review"],
2524
- ["index", "agent_reviews_agent_time"],
2525
- ["index", "agent_reviews_claimable"],
2526
- ["index", "agent_reviews_one_open_per_agent"],
2527
- ["index", "communication_approval_events_attempt"],
2528
- ["index", "communication_approvals_queue"],
2529
- ["index", "communication_approvals_teams"],
2530
- ["index", "idx_agents_telegram_topic_id"],
2531
- ["index", "idx_provider_models_provider"],
2532
- ["index", "messages_policy_delivery_queue"],
2533
- ["index", "messages_causal_chain"],
2534
- ["index", "messages_to_unread"],
2535
- ["index", "team_policy_baseline_owner"],
2536
- ["index", "team_policy_blocks_team_time"],
2537
- ["index", "team_template_active_position"],
2538
- ["index", "trigger_dispatches_claimable"],
2539
- ["index", "trigger_dispatches_trigger_time"],
2540
- ["index", "web_tokens_active"],
2541
- ["index", "web_sessions_active"],
2542
- ["index", "web_sessions_device"],
2543
- ["table", "agent_results"],
2544
- ["table", "agent_skills"],
2545
- ["table", "agent_loop_break_events"],
2546
- ["table", "agent_lesson_proposals"],
2547
- ["table", "agent_reviews"],
2548
- ["table", "agent_triggers"],
2549
- ["table", "agents"],
2550
- ["table", "attention_acknowledgements"],
2551
- ["table", "communication_approval_events"],
2552
- ["table", "communication_approval_message_grants"],
2553
- ["table", "communication_approvals"],
2554
- ["table", "config"],
2555
- ["table", "mcp_servers"],
2556
- ["table", "messages"],
2557
- ["table", "profile_communication_defaults"],
2558
- ["table", "profile_default_skills"],
2559
- ["table", "profiles"],
2560
- ["table", "provider_models"],
2561
- ["table", "provider_state"],
2562
- ["table", "schema_migrations"],
2563
- ["table", "secrets"],
2564
- ["table", "skill_meta"],
2565
- ["table", "source_slot_bindings"],
2566
- ["table", "team_agent_state"],
2567
- ["table", "team_policies"],
2568
- ["table", "team_policy_block_events"],
2569
- ["table", "team_policy_edges"],
2570
- ["table", "team_template_edges"],
2571
- ["table", "team_template_revision_edges"],
2572
- ["table", "team_template_revision_slots"],
2573
- ["table", "team_template_revisions"],
2574
- ["table", "team_template_slots"],
2575
- ["table", "team_templates"],
2576
- ["table", "teams"],
2577
- ["table", "telegram_allowed_users"],
2578
- ["table", "telegram_pairing_challenge"],
2579
- ["table", "template_instantiations"],
2580
- ["table", "trigger_dispatches"],
2581
- ["table", "web_tokens"],
2582
- ["table", "web_sessions"],
2583
- ["trigger", "create_team_policy"],
2584
- ["trigger", "prevent_detached_team_policy_delete"],
2585
- ["trigger", "validate_source_binding_insert"],
2586
- ["trigger", "validate_team_agent_state_insert"],
2587
- ["trigger", "validate_team_policy_baseline_update"],
2588
- ["trigger", "validate_team_policy_edge_insert"],
2589
- ["trigger", "validate_team_template_edge_insert"]
2590
- ];
2443
+
2444
+ // ../daemon/src/core/db/migrate.ts
2445
+ import { readdirSync, readFileSync as readFileSync4 } from "fs";
2446
+ import { dirname, join as join2 } from "path";
2447
+ import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
2448
+ import { fileURLToPath } from "url";
2449
+
2450
+ // ../daemon/src/core/db/client.ts
2451
+ import { backup, DatabaseSync as DatabaseSync2 } from "node:sqlite";
2452
+ function wrap(rawDb) {
2453
+ const cache = /* @__PURE__ */ new Map();
2454
+ let transactionDepth = 0;
2455
+ let savepointSequence = 0;
2456
+ function getStmt(sql) {
2457
+ let s = cache.get(sql);
2458
+ if (!s) {
2459
+ s = rawDb.prepare(sql);
2460
+ cache.set(sql, s);
2461
+ }
2462
+ return s;
2463
+ }
2464
+ return {
2465
+ query(sql) {
2466
+ const stmt = getStmt(sql);
2467
+ return {
2468
+ get(...params) {
2469
+ const result = stmt.get(...params);
2470
+ return result ?? null;
2471
+ },
2472
+ all(...params) {
2473
+ return stmt.all(...params);
2474
+ },
2475
+ run(...params) {
2476
+ return stmt.run(...params);
2477
+ }
2478
+ };
2479
+ },
2480
+ run(sql, params) {
2481
+ const stmt = getStmt(sql);
2482
+ return stmt.run(...params ?? []);
2483
+ },
2484
+ exec(sql) {
2485
+ rawDb.exec(sql);
2486
+ },
2487
+ // node:sqlite has no callable `transaction` wrapper; use manual BEGIN/COMMIT/ROLLBACK.
2488
+ transaction(fn) {
2489
+ return () => {
2490
+ const outermost = transactionDepth === 0;
2491
+ const savepoint = outermost ? null : `bazilion_nested_${++savepointSequence}`;
2492
+ if (outermost) rawDb.exec("BEGIN");
2493
+ else rawDb.exec(`SAVEPOINT ${savepoint}`);
2494
+ transactionDepth++;
2495
+ try {
2496
+ const result = fn();
2497
+ if (outermost) rawDb.exec("COMMIT");
2498
+ else rawDb.exec(`RELEASE SAVEPOINT ${savepoint}`);
2499
+ return result;
2500
+ } catch (err) {
2501
+ if (outermost) rawDb.exec("ROLLBACK");
2502
+ else {
2503
+ rawDb.exec(`ROLLBACK TO SAVEPOINT ${savepoint}`);
2504
+ rawDb.exec(`RELEASE SAVEPOINT ${savepoint}`);
2505
+ }
2506
+ throw err;
2507
+ } finally {
2508
+ transactionDepth--;
2509
+ }
2510
+ };
2511
+ }
2512
+ };
2513
+ }
2514
+ function applyPragmas(rawDb, includeWal) {
2515
+ if (includeWal) {
2516
+ try {
2517
+ rawDb.exec("PRAGMA journal_mode = WAL");
2518
+ } catch {
2519
+ }
2520
+ }
2521
+ rawDb.exec("PRAGMA foreign_keys = ON");
2522
+ }
2523
+ function openInMemoryDb() {
2524
+ const raw = new DatabaseSync2(":memory:");
2525
+ applyPragmas(raw, false);
2526
+ return {
2527
+ raw: wrap(raw),
2528
+ backupTo(path) {
2529
+ return backup(raw, path);
2530
+ },
2531
+ close() {
2532
+ raw.close();
2533
+ }
2534
+ };
2535
+ }
2536
+
2537
+ // ../daemon/src/core/db/migrate.ts
2538
+ var migrationsDir = join2(dirname(fileURLToPath(import.meta.url)), "migrations");
2539
+ var schemaMigrationsSql = `
2540
+ CREATE TABLE IF NOT EXISTS schema_migrations (
2541
+ version TEXT PRIMARY KEY,
2542
+ applied_at INTEGER NOT NULL
2543
+ )
2544
+ `;
2545
+ function listMigrations() {
2546
+ return readdirSync(migrationsDir).filter((file) => file.endsWith(".sql")).sort().map((file) => ({
2547
+ version: file.replace(/\.sql$/, ""),
2548
+ sql: readFileSync4(join2(migrationsDir, file), "utf8")
2549
+ }));
2550
+ }
2551
+ var canonicalSchemaObjectsByPrefix = /* @__PURE__ */ new Map();
2552
+ function schemaObjects(db) {
2553
+ return db.raw.query(
2554
+ `SELECT type, name, tbl_name, sql
2555
+ FROM sqlite_schema
2556
+ WHERE sql IS NOT NULL AND substr(name, 1, 7) <> 'sqlite_'
2557
+ ORDER BY type, name`
2558
+ ).all();
2559
+ }
2591
2560
  function normalizeSql(sql) {
2592
2561
  return sql.replace(/\s+/g, " ").trim();
2593
2562
  }
2594
- function assertCanonicalBackupSchema(db) {
2595
- const migrations = db.prepare("SELECT version FROM schema_migrations ORDER BY version").all();
2596
- if (migrations.length !== 1 || migrations[0]?.version !== CANONICAL_MIGRATION) {
2563
+ function expectedSchema(files, prefixLength) {
2564
+ const cached = canonicalSchemaObjectsByPrefix.get(prefixLength);
2565
+ if (cached) return cached;
2566
+ const canonical = openInMemoryDb();
2567
+ try {
2568
+ canonical.raw.exec(schemaMigrationsSql);
2569
+ for (const file of files.slice(0, prefixLength)) canonical.raw.exec(file.sql);
2570
+ const objects = schemaObjects(canonical);
2571
+ canonicalSchemaObjectsByPrefix.set(prefixLength, objects);
2572
+ return objects;
2573
+ } finally {
2574
+ canonical.close();
2575
+ }
2576
+ }
2577
+ function assertSchemaMatchesCanonicalChain(raw) {
2578
+ const files = listMigrations();
2579
+ const expectedVersions = files.map((file) => file.version);
2580
+ const applied = raw.prepare("SELECT version FROM schema_migrations ORDER BY version").all().map((row2) => row2.version);
2581
+ if (applied.length !== expectedVersions.length || applied.some((version, index) => version !== expectedVersions[index])) {
2597
2582
  throw new Error(
2598
- `schema_migrations must contain exactly ${CANONICAL_MIGRATION}; found ` + (migrations.map((row2) => row2.version).join(", ") || "none")
2583
+ `schema_migrations must contain exactly ${expectedVersions.join(", ")}; found ` + (applied.join(", ") || "none")
2599
2584
  );
2600
2585
  }
2601
- const rows = db.prepare(
2586
+ const rows = raw.prepare(
2602
2587
  `SELECT type, name, tbl_name, sql
2603
2588
  FROM sqlite_schema
2604
- WHERE sql IS NOT NULL AND name NOT LIKE 'sqlite_%'`
2589
+ WHERE sql IS NOT NULL AND substr(name, 1, 7) <> 'sqlite_'
2590
+ ORDER BY type, name`
2605
2591
  ).all();
2606
- const byKey = new Map(rows.map((row2) => [`${row2.type}\0${row2.name}`, row2]));
2607
- const canonicalKeys = new Set(CANONICAL_OBJECTS.map(([type, name]) => `${type}\0${name}`));
2592
+ const canonical = expectedSchema(files, files.length);
2593
+ const canonicalKeys = new Set(canonical.map((row2) => `${row2.type}\0${row2.name}`));
2594
+ const actualKeys = new Map(rows.map((row2) => [`${row2.type}\0${row2.name}`, row2]));
2595
+ for (const row2 of canonical) {
2596
+ if (!actualKeys.has(`${row2.type}\0${row2.name}`)) {
2597
+ throw new Error(`required canonical schema ${row2.type} is missing: ${row2.name}`);
2598
+ }
2599
+ }
2608
2600
  for (const row2 of rows) {
2609
2601
  if (!canonicalKeys.has(`${row2.type}\0${row2.name}`)) {
2610
2602
  throw new Error(`unexpected schema ${row2.type} is not canonical: ${row2.name}`);
2611
2603
  }
2612
2604
  }
2613
- const canonicalRows = [];
2614
- for (const [type, name] of CANONICAL_OBJECTS) {
2615
- const row2 = byKey.get(`${type}\0${name}`);
2616
- if (!row2) throw new Error(`required canonical schema ${type} is missing: ${name}`);
2617
- canonicalRows.push(row2);
2618
- }
2619
- const payload = canonicalRows.map((row2) => [row2.type, row2.name, row2.tbl_name, normalizeSql(row2.sql)].join("\0")).join("\n");
2620
- const actualHash = createHash("sha256").update(payload).digest("hex");
2621
- if (actualHash !== CANONICAL_SCHEMA_HASH) {
2605
+ const payload = rows.map((row2) => [row2.type, row2.name, row2.tbl_name, normalizeSql(row2.sql)].join("\0")).join("\n");
2606
+ const canonicalPayload = canonical.map((row2) => [row2.type, row2.name, row2.tbl_name, normalizeSql(row2.sql)].join("\0")).join("\n");
2607
+ if (payload !== canonicalPayload) {
2622
2608
  throw new Error(
2623
- "canonical schema fingerprint does not match this Bazilion release; restore a backup created from the current clean-install schema"
2609
+ "database schema does not match this release\u2019s canonical migration chain; restore a backup created from the current release"
2624
2610
  );
2625
2611
  }
2612
+ }
2613
+
2614
+ // src/backup-schema.ts
2615
+ function assertCanonicalBackupSchema(db) {
2616
+ assertSchemaMatchesCanonicalChain(db);
2626
2617
  for (const row2 of db.prepare("SELECT id, bytes, byte_length, sha256 FROM agent_results WHERE deleted_at IS NULL").iterate()) {
2627
2618
  const bytes = row2.bytes;
2628
2619
  if (!(bytes instanceof Uint8Array) || bytes.byteLength !== row2.byte_length || createHash("sha256").update(bytes).digest("hex") !== row2.sha256) {
@@ -2643,13 +2634,13 @@ import {
2643
2634
  lstatSync as lstatSync2,
2644
2635
  mkdirSync,
2645
2636
  openSync,
2646
- readFileSync as readFileSync4,
2637
+ readFileSync as readFileSync5,
2647
2638
  realpathSync,
2648
2639
  renameSync,
2649
2640
  rmSync,
2650
2641
  writeSync
2651
2642
  } from "fs";
2652
- import { basename as basename3, dirname, join as join2, resolve as resolve2 } from "path";
2643
+ import { basename as basename3, dirname as dirname2, join as join3, resolve as resolve2 } from "path";
2653
2644
  var DAEMON_LIVENESS_FILENAME = "daemon-runtime.json";
2654
2645
  var STALE_AFTER_MS = 6e4;
2655
2646
  var PROBE_TIMEOUT_MS = 750;
@@ -2659,15 +2650,15 @@ function canonicalHomeIdentity(home) {
2659
2650
  return realpathSync.native(absolute);
2660
2651
  } catch (error) {
2661
2652
  if (errorCode(error) !== "ENOENT") throw error;
2662
- const parent = dirname(absolute);
2653
+ const parent = dirname2(absolute);
2663
2654
  if (parent === absolute) throw error;
2664
- return join2(canonicalHomeIdentity(parent), basename3(absolute));
2655
+ return join3(canonicalHomeIdentity(parent), basename3(absolute));
2665
2656
  }
2666
2657
  }
2667
2658
  function daemonLivenessPath(home) {
2668
2659
  const canonicalHome = canonicalHomeIdentity(home);
2669
2660
  const identity = createHash2("sha256").update(canonicalHome).digest("hex").slice(0, 24);
2670
- return join2(dirname(canonicalHome), `.bazilion-runtime-${identity}.json`);
2661
+ return join3(dirname2(canonicalHome), `.bazilion-runtime-${identity}.json`);
2671
2662
  }
2672
2663
  function errorCode(error) {
2673
2664
  return error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
@@ -2705,7 +2696,7 @@ function parseRecord(raw) {
2705
2696
  function readRecord(path) {
2706
2697
  try {
2707
2698
  const stat = lstatSync2(path);
2708
- const raw = stat.isFile() ? readFileSync4(path, "utf8") : "";
2699
+ const raw = stat.isFile() ? readFileSync5(path, "utf8") : "";
2709
2700
  return { raw, stat, record: stat.isFile() ? parseRecord(raw) : null };
2710
2701
  } catch (error) {
2711
2702
  if (errorCode(error) === "ENOENT") return null;
@@ -2762,7 +2753,7 @@ function writeRecord(fd, record) {
2762
2753
  function fsyncParentDirectory(path) {
2763
2754
  let directoryFd = null;
2764
2755
  try {
2765
- directoryFd = openSync(dirname(path), "r");
2756
+ directoryFd = openSync(dirname2(path), "r");
2766
2757
  fsyncSync(directoryFd);
2767
2758
  } catch (error) {
2768
2759
  if (process.platform !== "win32") throw error;
@@ -2784,7 +2775,7 @@ function reclaimRecord(path, existing) {
2784
2775
  return null;
2785
2776
  }
2786
2777
  try {
2787
- renameSync(path, join2(claim, "stale-record.json"));
2778
+ renameSync(path, join3(claim, "stale-record.json"));
2788
2779
  return claim;
2789
2780
  } catch (error) {
2790
2781
  if (errorCode(error) === "ENOENT") return null;
@@ -2793,9 +2784,9 @@ function reclaimRecord(path, existing) {
2793
2784
  }
2794
2785
  async function acquireHomeRestoreLock(home, operation = "restoring") {
2795
2786
  const targetHome = resolve2(home);
2796
- mkdirSync(dirname(targetHome), { recursive: true });
2787
+ mkdirSync(dirname2(targetHome), { recursive: true });
2797
2788
  const path = daemonLivenessPath(targetHome);
2798
- mkdirSync(dirname(path), { recursive: true });
2789
+ mkdirSync(dirname2(path), { recursive: true });
2799
2790
  const instanceId = randomUUID6();
2800
2791
  let fd = null;
2801
2792
  let reclaimClaim = null;
@@ -3040,7 +3031,7 @@ var createCmd = defineCommand9({
3040
3031
  } catch (error) {
3041
3032
  if (!(error instanceof Error) || !("code" in error) || error.code !== "EXDEV") throw error;
3042
3033
  const installPartial = resolve3(
3043
- dirname2(outAbs),
3034
+ dirname3(outAbs),
3044
3035
  `.${basename4(outAbs)}.${randomUUID7()}.installing`
3045
3036
  );
3046
3037
  try {
@@ -3227,7 +3218,7 @@ function validateArchiveEntries(entries) {
3227
3218
  function validateAuthFile(path) {
3228
3219
  let parsed;
3229
3220
  try {
3230
- parsed = JSON.parse(readFileSync5(path, "utf8"));
3221
+ parsed = JSON.parse(readFileSync6(path, "utf8"));
3231
3222
  } catch (error) {
3232
3223
  const detail = error instanceof Error ? error.message : String(error);
3233
3224
  throw new Error(`backup auth.json is invalid: ${detail}`);
@@ -3240,7 +3231,7 @@ function validateAuthFile(path) {
3240
3231
  function validateDatabase(path, authToken) {
3241
3232
  let db = null;
3242
3233
  try {
3243
- db = new DatabaseSync2(path, { readOnly: true });
3234
+ db = new DatabaseSync4(path, { readOnly: true });
3244
3235
  const integrity = db.prepare("PRAGMA integrity_check").all();
3245
3236
  if (integrity.length !== 1 || integrity[0]?.integrity_check !== "ok") {
3246
3237
  const detail = integrity.map((row2) => row2.integrity_check).join("; ") || "no result";
@@ -3304,7 +3295,7 @@ function requireExtractedTeamSlot(path, rowLabel) {
3304
3295
  function rebaseRestoredHomeDirectories(database, payload, targetHome) {
3305
3296
  let db = null;
3306
3297
  try {
3307
- db = new DatabaseSync2(database);
3298
+ db = new DatabaseSync4(database);
3308
3299
  db.exec("PRAGMA foreign_keys = ON");
3309
3300
  const profiles = db.prepare("SELECT id FROM profiles ORDER BY id").all();
3310
3301
  const agents = db.prepare("SELECT id FROM agents ORDER BY id").all();
@@ -3381,11 +3372,11 @@ function rebaseRestoredHomeDirectories(database, payload, targetHome) {
3381
3372
  function removeRebuildableQmdIndexes(payload) {
3382
3373
  const teamsDir = resolve3(payload, "teams");
3383
3374
  if (!existsSync2(teamsDir) || !lstatSync3(teamsDir).isDirectory()) return;
3384
- for (const team of readdirSync(teamsDir, { withFileTypes: true })) {
3375
+ for (const team of readdirSync2(teamsDir, { withFileTypes: true })) {
3385
3376
  if (!team.isDirectory() || team.isSymbolicLink()) continue;
3386
3377
  const memoryDir = resolve3(teamsDir, team.name, "memory");
3387
3378
  if (!existsSync2(memoryDir) || !lstatSync3(memoryDir).isDirectory()) continue;
3388
- for (const entry3 of readdirSync(memoryDir, { withFileTypes: true })) {
3379
+ for (const entry3 of readdirSync2(memoryDir, { withFileTypes: true })) {
3389
3380
  if (entry3.isFile() && entry3.name.startsWith(".qmd-index.sqlite")) {
3390
3381
  rmSync2(resolve3(memoryDir, entry3.name), { force: true });
3391
3382
  }
@@ -3393,7 +3384,7 @@ function removeRebuildableQmdIndexes(payload) {
3393
3384
  }
3394
3385
  }
3395
3386
  function revokeRestoredBrowserSessions(database) {
3396
- const db = new DatabaseSync2(database);
3387
+ const db = new DatabaseSync4(database);
3397
3388
  try {
3398
3389
  db.prepare("UPDATE web_sessions SET revoked_at = ? WHERE revoked_at IS NULL").run(Date.now());
3399
3390
  } finally {
@@ -3403,7 +3394,7 @@ function revokeRestoredBrowserSessions(database) {
3403
3394
  function installValidatedPayload(payload, targetHome, staging, lifecycle, operations = { rename: renameSync2 }) {
3404
3395
  const previous = resolve3(staging, "previous-home");
3405
3396
  const hadPrevious = existsSync2(targetHome);
3406
- const targetParent = dirname2(targetHome);
3397
+ const targetParent = dirname3(targetHome);
3407
3398
  const syncDirectory = operations.fsyncDirectory ?? fsyncDirectory;
3408
3399
  const recoveryError = (message, recoveryPath, cause) => {
3409
3400
  let markerError;
@@ -3538,7 +3529,7 @@ function readAgeIdentity(rawPath) {
3538
3529
  if (process.platform !== "win32" && (entry3.mode & 63) !== 0) {
3539
3530
  throw new Error(`age identity must be owner-only (chmod 600): ${path}`);
3540
3531
  }
3541
- const identities = readFileSync5(path, "utf8").split(/\r?\n/).map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
3532
+ const identities = readFileSync6(path, "utf8").split(/\r?\n/).map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
3542
3533
  if (identities.length !== 1 || !identities[0]?.startsWith("AGE-SECRET-KEY-")) {
3543
3534
  throw new Error("age identity file must contain exactly one supported AGE-SECRET-KEY entry");
3544
3535
  }
@@ -3573,7 +3564,7 @@ var restoreCmd = defineCommand9({
3573
3564
  if (targetHome === parse(targetHome).root) {
3574
3565
  throw new Error(`refusing to restore over filesystem root: ${targetHome}`);
3575
3566
  }
3576
- const targetParent = dirname2(targetHome);
3567
+ const targetParent = dirname3(targetHome);
3577
3568
  mkdirSync2(targetParent, { recursive: true });
3578
3569
  const restoreLock = await acquireHomeRestoreLock(targetHome);
3579
3570
  try {
@@ -3591,7 +3582,7 @@ var restoreCmd = defineCommand9({
3591
3582
  if (!lstatSync3(targetHome).isDirectory()) {
3592
3583
  throw new Error(`${targetHome} exists and is not a directory`);
3593
3584
  }
3594
- const entries = readdirSync(targetHome);
3585
+ const entries = readdirSync2(targetHome);
3595
3586
  if (entries.length > 0 && !args2.force) {
3596
3587
  throw new Error(
3597
3588
  `${targetHome} is not empty. Pass --force to overwrite (destroys existing data).`
@@ -3714,7 +3705,7 @@ function credentialInventory(home) {
3714
3705
  const database = resolve3(home, "bazilion.db");
3715
3706
  const token = validateAuthFile(authFile);
3716
3707
  validateDatabase(database, token);
3717
- const db = new DatabaseSync2(database, { readOnly: true });
3708
+ const db = new DatabaseSync4(database, { readOnly: true });
3718
3709
  try {
3719
3710
  const activeTokens = db.prepare(
3720
3711
  "SELECT COUNT(*) AS count FROM web_tokens WHERE revoked_at IS NULL AND kind = 'device' AND expires_at > ?"
@@ -3773,7 +3764,7 @@ var rotateBootstrapCmd = defineCommand9({
3773
3764
  throw new Error(`refusing to rotate filesystem root: ${targetHome}`);
3774
3765
  }
3775
3766
  const lock = await acquireHomeRestoreLock(targetHome);
3776
- const parent = dirname2(targetHome);
3767
+ const parent = dirname3(targetHome);
3777
3768
  const staging = mkdtempSync(resolve3(parent, ".bazilion-rotate-"));
3778
3769
  const payload = resolve3(staging, "payload");
3779
3770
  let preserveStaging = false;
@@ -3783,7 +3774,7 @@ var rotateBootstrapCmd = defineCommand9({
3783
3774
  throw new Error(`bazilion server appears to be running at ${serverUrl} \u2014 stop it first.`);
3784
3775
  }
3785
3776
  }
3786
- const oldAuth = JSON.parse(readFileSync5(paths.authFile, "utf8"));
3777
+ const oldAuth = JSON.parse(readFileSync6(paths.authFile, "utf8"));
3787
3778
  if (typeof oldAuth.token !== "string" || !oldAuth.token) {
3788
3779
  throw new Error("auth.json is missing the bootstrap token");
3789
3780
  }
@@ -3796,7 +3787,7 @@ var rotateBootstrapCmd = defineCommand9({
3796
3787
  });
3797
3788
  const stagedDb = resolve3(payload, "bazilion.db");
3798
3789
  rmSync2(stagedDb, { force: true });
3799
- const sourceDb = new DatabaseSync2(resolve3(targetHome, "bazilion.db"), { readOnly: true });
3790
+ const sourceDb = new DatabaseSync4(resolve3(targetHome, "bazilion.db"), { readOnly: true });
3800
3791
  try {
3801
3792
  await sqliteBackup(sourceDb, stagedDb);
3802
3793
  } finally {
@@ -3805,7 +3796,7 @@ var rotateBootstrapCmd = defineCommand9({
3805
3796
  for (const suffix of ["-wal", "-shm", "-journal"])
3806
3797
  rmSync2(`${stagedDb}${suffix}`, { force: true });
3807
3798
  const newToken = randomBytes(24).toString("hex");
3808
- const db = new DatabaseSync2(stagedDb);
3799
+ const db = new DatabaseSync4(stagedDb);
3809
3800
  try {
3810
3801
  db.exec("PRAGMA foreign_keys = ON; BEGIN IMMEDIATE");
3811
3802
  try {
@@ -4102,16 +4093,16 @@ var configCommand = defineCommand11({
4102
4093
  import { spawn } from "child_process";
4103
4094
  import { existsSync as existsSync3 } from "fs";
4104
4095
  import { connect } from "net";
4105
- import { join as join3 } from "path";
4096
+ import { join as join4 } from "path";
4106
4097
  import { defineCommand as defineCommand12 } from "citty";
4107
- var bundledDaemonEntry = join3(import.meta.dirname, "daemon.js");
4108
- var sourceDaemonEntry = join3(import.meta.dirname, "..", "..", "..", "daemon", "src", "index.ts");
4098
+ var bundledDaemonEntry = join4(import.meta.dirname, "daemon.js");
4099
+ var sourceDaemonEntry = join4(import.meta.dirname, "..", "..", "..", "daemon", "src", "index.ts");
4109
4100
  var daemonEntry = existsSync3(bundledDaemonEntry) ? bundledDaemonEntry : sourceDaemonEntry;
4110
- var bundledWebServerEntry = join3(import.meta.dirname, "web-server.js");
4111
- var sourceWebServerEntry = join3(import.meta.dirname, "..", "web-server.ts");
4101
+ var bundledWebServerEntry = join4(import.meta.dirname, "web-server.js");
4102
+ var sourceWebServerEntry = join4(import.meta.dirname, "..", "web-server.ts");
4112
4103
  var webServerEntry = existsSync3(bundledWebServerEntry) ? bundledWebServerEntry : sourceWebServerEntry;
4113
- var bundledWebDist = join3(import.meta.dirname, "web");
4114
- var sourceWebDist = join3(import.meta.dirname, "..", "..", "..", "web", "dist");
4104
+ var bundledWebDist = join4(import.meta.dirname, "web");
4105
+ var sourceWebDist = join4(import.meta.dirname, "..", "..", "..", "web", "dist");
4115
4106
  var webDist = existsSync3(bundledWebDist) ? bundledWebDist : sourceWebDist;
4116
4107
  function nodeArgs(entry3) {
4117
4108
  return entry3.endsWith(".ts") ? ["--import", "tsx/esm", entry3] : [entry3];
@@ -4274,7 +4265,7 @@ var dashboardCommand = defineCommand12({
4274
4265
  `web UI port ${webPort} is already in use. Re-run with --port <free-port>.`
4275
4266
  );
4276
4267
  }
4277
- if (!existsSync3(join3(webDist, "server", "server.js"))) {
4268
+ if (!existsSync3(join4(webDist, "server", "server.js"))) {
4278
4269
  throw new Error(
4279
4270
  `bazilion web UI bundle not found at ${webDist}. Run "pnpm --filter @bazilion/web build" from the repository root of a source checkout, or reinstall the published package.`
4280
4271
  );
@@ -4679,7 +4670,7 @@ var inboxCommand = defineCommand15({
4679
4670
  });
4680
4671
 
4681
4672
  // src/commands/login.ts
4682
- import { existsSync as existsSync4, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "fs";
4673
+ import { existsSync as existsSync4, readFileSync as readFileSync7, writeFileSync as writeFileSync3 } from "fs";
4683
4674
  import { defineCommand as defineCommand16 } from "citty";
4684
4675
  function normalizeServer(raw) {
4685
4676
  let url;
@@ -4722,7 +4713,7 @@ var loginCommand = defineCommand16({
4722
4713
  `${paths.authFile} not found. Start the daemon with "bazilion serve" first \u2014 login stores the remote there.`
4723
4714
  );
4724
4715
  }
4725
- const auth = JSON.parse(readFileSync6(paths.authFile, "utf8"));
4716
+ const auth = JSON.parse(readFileSync7(paths.authFile, "utf8"));
4726
4717
  if (args2.clear) {
4727
4718
  if (!auth.remote) {
4728
4719
  console.log("no remote stored \u2014 nothing to clear");
@@ -4972,9 +4963,9 @@ var memoryCommand = defineCommand18({
4972
4963
  // src/commands/profile.ts
4973
4964
  import { spawn as spawn2 } from "child_process";
4974
4965
  import { randomBytes as randomBytes2 } from "crypto";
4975
- import { readFileSync as readFileSync7, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "fs";
4966
+ import { readFileSync as readFileSync8, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "fs";
4976
4967
  import { tmpdir as tmpdir2 } from "os";
4977
- import { join as join4 } from "path";
4968
+ import { join as join5 } from "path";
4978
4969
 
4979
4970
  // ../../packages/api-types/src/git-review.ts
4980
4971
  var REVIEW_LIMITS = {
@@ -5051,7 +5042,7 @@ var createCmd2 = defineCommand19({
5051
5042
  },
5052
5043
  async run({ args: args2 }) {
5053
5044
  const skillsMode = parseSkillsMode(args2["skills-mode"]);
5054
- const readTemplate = (path) => path ? readFileSync7(path, "utf8") : void 0;
5045
+ const readTemplate = (path) => path ? readFileSync8(path, "utf8") : void 0;
5055
5046
  const body = {
5056
5047
  id: args2.id,
5057
5048
  name: args2.name,
@@ -5126,7 +5117,7 @@ var editCmd2 = defineCommand19({
5126
5117
  const { content } = await client.get(
5127
5118
  `/api/profiles/${args2.id}/files/${file}`
5128
5119
  );
5129
- const tmpPath = join4(tmpdir2(), `bazilion-${args2.id}-${file}-${randomBytes2(4).toString("hex")}`);
5120
+ const tmpPath = join5(tmpdir2(), `bazilion-${args2.id}-${file}-${randomBytes2(4).toString("hex")}`);
5130
5121
  writeFileSync4(tmpPath, content);
5131
5122
  try {
5132
5123
  const editor = process.env.EDITOR ?? process.env.VISUAL ?? "vi";
@@ -5136,7 +5127,7 @@ var editCmd2 = defineCommand19({
5136
5127
  child.on("close", (c) => resolve6(c ?? 0));
5137
5128
  });
5138
5129
  if (code !== 0) throw new Error(`editor exited with code ${code}`);
5139
- const updated = readFileSync7(tmpPath, "utf8");
5130
+ const updated = readFileSync8(tmpPath, "utf8");
5140
5131
  if (updated === content) {
5141
5132
  console.log("(no changes)");
5142
5133
  return;
@@ -5482,10 +5473,10 @@ var sendCommand = defineCommand22({
5482
5473
  // src/commands/serve.ts
5483
5474
  import { spawn as spawn3 } from "child_process";
5484
5475
  import { existsSync as existsSync5 } from "fs";
5485
- import { join as join5 } from "path";
5476
+ import { join as join6 } from "path";
5486
5477
  import { defineCommand as defineCommand23 } from "citty";
5487
- var bundledDaemonEntry2 = join5(import.meta.dirname, "daemon.js");
5488
- var sourceDaemonEntry2 = join5(import.meta.dirname, "..", "..", "..", "daemon", "src", "index.ts");
5478
+ var bundledDaemonEntry2 = join6(import.meta.dirname, "daemon.js");
5479
+ var sourceDaemonEntry2 = join6(import.meta.dirname, "..", "..", "..", "daemon", "src", "index.ts");
5489
5480
  var daemonEntry2 = existsSync5(bundledDaemonEntry2) ? bundledDaemonEntry2 : sourceDaemonEntry2;
5490
5481
  var serveCommand = defineCommand23({
5491
5482
  meta: {
@@ -5591,7 +5582,7 @@ var sessionCommand = defineCommand24({
5591
5582
  });
5592
5583
 
5593
5584
  // src/commands/skill.ts
5594
- import { existsSync as existsSync6, readFileSync as readFileSync8, statSync as statSync2 } from "fs";
5585
+ import { existsSync as existsSync6, readFileSync as readFileSync9, statSync as statSync2 } from "fs";
5595
5586
  import { basename as basename5, resolve as resolve4 } from "path";
5596
5587
  import { defineCommand as defineCommand25 } from "citty";
5597
5588
  function printFindings(findings, prefix = " ") {
@@ -5661,7 +5652,7 @@ var importCmd = defineCommand25({
5661
5652
  let result;
5662
5653
  try {
5663
5654
  if (isLocalZip) {
5664
- const bytes = readFileSync8(absFrom);
5655
+ const bytes = readFileSync9(absFrom);
5665
5656
  const file = new File([bytes], basename5(absFrom), { type: "application/zip" });
5666
5657
  const fd = new FormData();
5667
5658
  fd.set("file", file);
@@ -5731,9 +5722,9 @@ var skillCommand = defineCommand25({
5731
5722
  });
5732
5723
 
5733
5724
  // src/commands/team.ts
5734
- import { readFileSync as readFileSync11 } from "fs";
5725
+ import { readFileSync as readFileSync12 } from "fs";
5735
5726
  import { stdin as stdin2 } from "process";
5736
- import { defineCommand as defineCommand32 } from "citty";
5727
+ import { defineCommand as defineCommand33 } from "citty";
5737
5728
 
5738
5729
  // src/commands/team-coding-log.ts
5739
5730
  import { defineCommand as defineCommand26 } from "citty";
@@ -5793,7 +5784,7 @@ var teamCodingLogCommand = defineCommand26({
5793
5784
  });
5794
5785
 
5795
5786
  // src/commands/team-environment.ts
5796
- import { readFileSync as readFileSync9 } from "fs";
5787
+ import { readFileSync as readFileSync10 } from "fs";
5797
5788
  import { defineCommand as defineCommand27 } from "citty";
5798
5789
  var args = { id: { type: "positional", required: true, description: "Team slug" } };
5799
5790
  var teamEnvironmentCommand = defineCommand27({
@@ -5819,7 +5810,7 @@ var teamEnvironmentCommand = defineCommand27({
5819
5810
  },
5820
5811
  async run({ args: args2 }) {
5821
5812
  const input = JSON.parse(
5822
- readFileSync9(args2.file, "utf8")
5813
+ readFileSync10(args2.file, "utf8")
5823
5814
  );
5824
5815
  console.log(
5825
5816
  JSON.stringify(await createClient2().codingEnvironment.configure(args2.id, input), null, 2)
@@ -5830,7 +5821,7 @@ var teamEnvironmentCommand = defineCommand27({
5830
5821
  });
5831
5822
 
5832
5823
  // src/commands/team-policy.ts
5833
- import { readFileSync as readFileSync10 } from "fs";
5824
+ import { readFileSync as readFileSync11 } from "fs";
5834
5825
  import { defineCommand as defineCommand28 } from "citty";
5835
5826
 
5836
5827
  // src/team-interchange.ts
@@ -6047,7 +6038,7 @@ function edgeDiff(before, after) {
6047
6038
  // src/commands/team-policy.ts
6048
6039
  function readJson(path) {
6049
6040
  try {
6050
- return JSON.parse(readFileSync10(path, "utf8"));
6041
+ return JSON.parse(readFileSync11(path, "utf8"));
6051
6042
  } catch (error) {
6052
6043
  throw new Error(`invalid JSON: ${error.message}`);
6053
6044
  }
@@ -6288,17 +6279,139 @@ var teamPolicyCommand = defineCommand28({
6288
6279
  }
6289
6280
  });
6290
6281
 
6282
+ // src/commands/team-publish.ts
6283
+ import { defineCommand as defineCommand29 } from "citty";
6284
+ var slug = { id: { type: "positional", required: true, description: "Team slug" } };
6285
+ var publicationId = {
6286
+ publicationId: { type: "positional", required: true, description: "Publication id" }
6287
+ };
6288
+ function printReport(report) {
6289
+ const publication = report.publication;
6290
+ console.log(`${publication.id} ${publication.state}`);
6291
+ console.log(` packet: ${publication.packetId}`);
6292
+ console.log(
6293
+ ` change: snapshot ${publication.snapshotId.slice(0, 12)} (base ${publication.baseOid.slice(0, 12)})`
6294
+ );
6295
+ console.log(` target: ${publication.host} ${publication.repository}`);
6296
+ console.log(
6297
+ ` branch: ${publication.headBranch} (base ${publication.baseBranch})${publication.commitOid ? `
6298
+ commit: ${publication.commitOid}${publication.signed ? "" : " (unsigned)"}` : ""}`
6299
+ );
6300
+ if (publication.pullRequestUrl) {
6301
+ console.log(` pull request: ${publication.pullRequestUrl}`);
6302
+ } else if (publication.state === "published") {
6303
+ console.log(" pull request: none was opened");
6304
+ }
6305
+ if (publication.refusalReason) {
6306
+ console.log(` refused: ${publication.refusalReason} \u2014 ${publication.refusalDetail ?? ""}`);
6307
+ }
6308
+ if (publication.error) console.log(` note: ${publication.error}`);
6309
+ console.log(` ${report.guidance}`);
6310
+ }
6311
+ function printList(list8) {
6312
+ if (list8.publications.length === 0) {
6313
+ console.log("no publications");
6314
+ return;
6315
+ }
6316
+ const rows = list8.publications.map((publication) => [
6317
+ publication.id,
6318
+ publication.state,
6319
+ publication.headBranch,
6320
+ publication.commitOid ? publication.commitOid.slice(0, 10) : "-",
6321
+ publication.pullRequestNumber ? `#${publication.pullRequestNumber}` : "-",
6322
+ publication.refusalReason ?? ""
6323
+ ]);
6324
+ for (const line of columnize(rows)) console.log(line);
6325
+ }
6326
+ var createCmd3 = defineCommand29({
6327
+ meta: {
6328
+ name: "create",
6329
+ description: "Publish a reviewed revision to a new branch (and open a pull request)"
6330
+ },
6331
+ args: {
6332
+ ...slug,
6333
+ packet: { type: "string", required: true, description: "Review packet id to publish" },
6334
+ branch: {
6335
+ type: "string",
6336
+ description: "Branch to publish to (default: bazilion/review-<packet prefix>)"
6337
+ },
6338
+ message: { type: "string", description: "Commit message (default: derived from the packet)" },
6339
+ json: { type: "boolean", description: "Emit JSON" }
6340
+ },
6341
+ async run({ args: args2 }) {
6342
+ const client = createClient2();
6343
+ try {
6344
+ const response = await client.publications(args2.id).create({
6345
+ teamId: args2.id,
6346
+ packetId: args2.packet,
6347
+ ...args2.branch ? { headBranch: args2.branch } : {},
6348
+ ...args2.message ? { commitMessage: args2.message } : {}
6349
+ });
6350
+ if (args2.json) {
6351
+ console.log(JSON.stringify(response, null, 2));
6352
+ return;
6353
+ }
6354
+ if ("blocked" in response) {
6355
+ console.error(`refused: ${response.blocked.reason} \u2014 ${response.blocked.detail}`);
6356
+ process.exit(1);
6357
+ }
6358
+ printReport(response.report);
6359
+ } catch (error) {
6360
+ console.error(error instanceof Error ? error.message : String(error));
6361
+ process.exit(1);
6362
+ }
6363
+ }
6364
+ });
6365
+ var listCmd10 = defineCommand29({
6366
+ meta: { name: "list", description: "List publications for a Team" },
6367
+ args: { ...slug, json: { type: "boolean", description: "Emit JSON" } },
6368
+ async run({ args: args2 }) {
6369
+ const client = createClient2();
6370
+ const response = await client.publications(args2.id).list();
6371
+ if (args2.json) {
6372
+ console.log(JSON.stringify(response, null, 2));
6373
+ return;
6374
+ }
6375
+ printList(response);
6376
+ }
6377
+ });
6378
+ var showCmd5 = defineCommand29({
6379
+ meta: { name: "show", description: "Show one publication and its outcome" },
6380
+ args: { ...slug, ...publicationId, json: { type: "boolean", description: "Emit JSON" } },
6381
+ async run({ args: args2 }) {
6382
+ const client = createClient2();
6383
+ try {
6384
+ const response = await client.publications(args2.id).show(args2.publicationId);
6385
+ if (args2.json) {
6386
+ console.log(JSON.stringify(response, null, 2));
6387
+ return;
6388
+ }
6389
+ printReport(response.report);
6390
+ } catch (error) {
6391
+ console.error(error instanceof Error ? error.message : String(error));
6392
+ process.exit(1);
6393
+ }
6394
+ }
6395
+ });
6396
+ var teamPublishCommand = defineCommand29({
6397
+ meta: {
6398
+ name: "publish",
6399
+ description: "Publish a reviewed revision to a code host (BAZ-046)"
6400
+ },
6401
+ subCommands: { create: createCmd3, list: listCmd10, show: showCmd5 }
6402
+ });
6403
+
6291
6404
  // src/commands/team-review.ts
6292
- import { defineCommand as defineCommand30 } from "citty";
6405
+ import { defineCommand as defineCommand31 } from "citty";
6293
6406
 
6294
6407
  // src/commands/team-review-packet.ts
6295
- import { defineCommand as defineCommand29 } from "citty";
6296
- var slug = { id: { type: "positional", required: true, description: "Team slug" } };
6408
+ import { defineCommand as defineCommand30 } from "citty";
6409
+ var slug2 = { id: { type: "positional", required: true, description: "Team slug" } };
6297
6410
  var packetId = {
6298
6411
  packetId: { type: "positional", required: true, description: "Review packet id" }
6299
6412
  };
6300
6413
  var SEVERITIES = ["blocker", "major", "minor", "info"];
6301
- function printReport(report) {
6414
+ function printReport2(report) {
6302
6415
  const packet = report.packet;
6303
6416
  const requester = packet.requester.kind === "agent" ? `agent ${packet.requester.agentId}` : "operator";
6304
6417
  console.log(`${packet.id} ${packet.state}${report.applicability.stale ? " (stale)" : ""}`);
@@ -6344,10 +6457,10 @@ function printReport(report) {
6344
6457
  " note: a review conclusion is not acceptance, and this command never commits, pushes, merges or deploys"
6345
6458
  );
6346
6459
  }
6347
- var createCmd3 = defineCommand29({
6460
+ var createCmd4 = defineCommand30({
6348
6461
  meta: { name: "create", description: "Capture a review packet for a retained revision" },
6349
6462
  args: {
6350
- ...slug,
6463
+ ...slug2,
6351
6464
  snapshot: {
6352
6465
  type: "string",
6353
6466
  required: true,
@@ -6372,16 +6485,16 @@ var createCmd3 = defineCommand29({
6372
6485
  console.log(JSON.stringify(response, null, 2));
6373
6486
  return;
6374
6487
  }
6375
- printReport(response.report);
6488
+ printReport2(response.report);
6376
6489
  } catch (error) {
6377
6490
  console.error(error instanceof Error ? error.message : String(error));
6378
6491
  process.exit(1);
6379
6492
  }
6380
6493
  }
6381
6494
  });
6382
- var listCmd10 = defineCommand29({
6495
+ var listCmd11 = defineCommand30({
6383
6496
  meta: { name: "list", description: "List review packets for a Team" },
6384
- args: { ...slug, json: { type: "boolean", description: "Emit JSON" } },
6497
+ args: { ...slug2, json: { type: "boolean", description: "Emit JSON" } },
6385
6498
  async run({ args: args2 }) {
6386
6499
  const client = createClient2();
6387
6500
  const response = await client.reviewPackets(args2.id).list();
@@ -6411,9 +6524,9 @@ var listCmd10 = defineCommand29({
6411
6524
  );
6412
6525
  }
6413
6526
  });
6414
- var showCmd5 = defineCommand29({
6527
+ var showCmd6 = defineCommand30({
6415
6528
  meta: { name: "show", description: "Show one review packet, its findings and its conclusions" },
6416
- args: { ...slug, ...packetId, json: { type: "boolean", description: "Emit JSON" } },
6529
+ args: { ...slug2, ...packetId, json: { type: "boolean", description: "Emit JSON" } },
6417
6530
  async run({ args: args2 }) {
6418
6531
  const client = createClient2();
6419
6532
  try {
@@ -6422,17 +6535,17 @@ var showCmd5 = defineCommand29({
6422
6535
  console.log(JSON.stringify(response, null, 2));
6423
6536
  return;
6424
6537
  }
6425
- printReport(response.report);
6538
+ printReport2(response.report);
6426
6539
  } catch (error) {
6427
6540
  console.error(error instanceof Error ? error.message : String(error));
6428
6541
  process.exit(1);
6429
6542
  }
6430
6543
  }
6431
6544
  });
6432
- var findingCmd = defineCommand29({
6545
+ var findingCmd = defineCommand30({
6433
6546
  meta: { name: "finding", description: "Record a finding against the packet\u2019s captured revision" },
6434
6547
  args: {
6435
- ...slug,
6548
+ ...slug2,
6436
6549
  ...packetId,
6437
6550
  path: { type: "string", required: true, description: "Repository-relative path" },
6438
6551
  severity: { type: "string", required: true, description: SEVERITIES.join(" | ") },
@@ -6466,17 +6579,17 @@ var findingCmd = defineCommand29({
6466
6579
  console.log(
6467
6580
  `finding recorded against revision ${response.report.packet.snapshot.id.slice(0, 12)}`
6468
6581
  );
6469
- printReport(response.report);
6582
+ printReport2(response.report);
6470
6583
  } catch (error) {
6471
6584
  console.error(error instanceof Error ? error.message : String(error));
6472
6585
  process.exit(1);
6473
6586
  }
6474
6587
  }
6475
6588
  });
6476
- var resolveCmd = defineCommand29({
6589
+ var resolveCmd = defineCommand30({
6477
6590
  meta: { name: "resolve", description: "Resolve a finding with explicit proof" },
6478
6591
  args: {
6479
- ...slug,
6592
+ ...slug2,
6480
6593
  ...packetId,
6481
6594
  findingId: { type: "positional", required: true, description: "Finding id" },
6482
6595
  kind: {
@@ -6502,17 +6615,17 @@ var resolveCmd = defineCommand29({
6502
6615
  console.log(JSON.stringify(response, null, 2));
6503
6616
  return;
6504
6617
  }
6505
- printReport(response.report);
6618
+ printReport2(response.report);
6506
6619
  } catch (error) {
6507
6620
  console.error(error instanceof Error ? error.message : String(error));
6508
6621
  process.exit(1);
6509
6622
  }
6510
6623
  }
6511
6624
  });
6512
- var concludeCmd = defineCommand29({
6625
+ var concludeCmd = defineCommand30({
6513
6626
  meta: { name: "conclude", description: "Record the reviewer\u2019s conclusion for this revision" },
6514
6627
  args: {
6515
- ...slug,
6628
+ ...slug2,
6516
6629
  ...packetId,
6517
6630
  conclusion: {
6518
6631
  type: "string",
@@ -6538,16 +6651,16 @@ var concludeCmd = defineCommand29({
6538
6651
  console.log(JSON.stringify(response, null, 2));
6539
6652
  return;
6540
6653
  }
6541
- printReport(response.report);
6654
+ printReport2(response.report);
6542
6655
  } catch (error) {
6543
6656
  console.error(error instanceof Error ? error.message : String(error));
6544
6657
  process.exit(1);
6545
6658
  }
6546
6659
  }
6547
6660
  });
6548
- var snapshotCmd = defineCommand29({
6661
+ var snapshotCmd = defineCommand30({
6549
6662
  meta: { name: "snapshots", description: "List retained revisions that could be reviewed" },
6550
- args: { ...slug, json: { type: "boolean", description: "Emit JSON" } },
6663
+ args: { ...slug2, json: { type: "boolean", description: "Emit JSON" } },
6551
6664
  async run({ args: args2 }) {
6552
6665
  const client = createClient2();
6553
6666
  const list8 = await client.repositoryReview(args2.id).snapshots();
@@ -6571,13 +6684,13 @@ var snapshotCmd = defineCommand29({
6571
6684
  for (const line of columnize(rows)) console.log(line);
6572
6685
  }
6573
6686
  });
6574
- var reportedCmd = defineCommand29({
6687
+ var reportedCmd = defineCommand30({
6575
6688
  meta: {
6576
6689
  name: "reported",
6577
6690
  description: "Record an operator-reported external state (never verified by Bazilion)"
6578
6691
  },
6579
6692
  args: {
6580
- ...slug,
6693
+ ...slug2,
6581
6694
  ...packetId,
6582
6695
  state: {
6583
6696
  type: "positional",
@@ -6614,13 +6727,13 @@ var reportedCmd = defineCommand29({
6614
6727
  }
6615
6728
  }
6616
6729
  });
6617
- var linkCmd = defineCommand29({
6730
+ var linkCmd = defineCommand30({
6618
6731
  meta: {
6619
6732
  name: "link",
6620
6733
  description: "Resolve where a file link points, and where it would open"
6621
6734
  },
6622
6735
  args: {
6623
- ...slug,
6736
+ ...slug2,
6624
6737
  ...packetId,
6625
6738
  path: { type: "string", required: true, description: "Changed path in the reviewed revision" },
6626
6739
  line: { type: "string", description: "Line to point at" },
@@ -6662,10 +6775,10 @@ var linkCmd = defineCommand29({
6662
6775
  }
6663
6776
  }
6664
6777
  });
6665
- var exportCmd = defineCommand29({
6778
+ var exportCmd = defineCommand30({
6666
6779
  meta: { name: "export", description: "Print the patch and handoff text for a packet\u2019s revision" },
6667
6780
  args: {
6668
- ...slug,
6781
+ ...slug2,
6669
6782
  ...packetId,
6670
6783
  patch: { type: "boolean", description: "Print only the unified patch" },
6671
6784
  deliver: {
@@ -6716,15 +6829,15 @@ handoff names ${result.limitations.length} limitation(s), and a conclusion is no
6716
6829
  }
6717
6830
  }
6718
6831
  });
6719
- var teamReviewPacketCommand = defineCommand29({
6832
+ var teamReviewPacketCommand = defineCommand30({
6720
6833
  meta: {
6721
6834
  name: "packet",
6722
6835
  description: "Revision-bound review packets: captured revision, findings, conclusion and handoff"
6723
6836
  },
6724
6837
  subCommands: {
6725
- create: createCmd3,
6726
- list: listCmd10,
6727
- show: showCmd5,
6838
+ create: createCmd4,
6839
+ list: listCmd11,
6840
+ show: showCmd6,
6728
6841
  finding: findingCmd,
6729
6842
  resolve: resolveCmd,
6730
6843
  conclude: concludeCmd,
@@ -6736,19 +6849,19 @@ var teamReviewPacketCommand = defineCommand29({
6736
6849
  });
6737
6850
 
6738
6851
  // src/commands/team-review.ts
6739
- var slug2 = {
6852
+ var slug3 = {
6740
6853
  id: { type: "positional", required: true, description: "Team slug" }
6741
6854
  };
6742
6855
  function printIssues(changes) {
6743
6856
  for (const issue of changes.issues) console.log(`note: ${issue.code}: ${issue.message}`);
6744
6857
  }
6745
- var showCmd6 = defineCommand30({
6858
+ var showCmd7 = defineCommand31({
6746
6859
  meta: {
6747
6860
  name: "show",
6748
6861
  description: "List changes since a baseline (read-only)"
6749
6862
  },
6750
6863
  args: {
6751
- ...slug2,
6864
+ ...slug3,
6752
6865
  base: {
6753
6866
  type: "string",
6754
6867
  description: "Comparison base: branch, tag or commit id (default HEAD)"
@@ -6807,13 +6920,13 @@ var showCmd6 = defineCommand30({
6807
6920
  printIssues(changes);
6808
6921
  }
6809
6922
  });
6810
- var captureCmd = defineCommand30({
6923
+ var captureCmd = defineCommand31({
6811
6924
  meta: {
6812
6925
  name: "capture",
6813
6926
  description: "Capture a bounded source snapshot for a Team (read-only)"
6814
6927
  },
6815
6928
  args: {
6816
- ...slug2,
6929
+ ...slug3,
6817
6930
  base: { type: "string", description: "Comparison base (default HEAD)" },
6818
6931
  include: {
6819
6932
  type: "string",
@@ -6850,9 +6963,9 @@ var captureCmd = defineCommand30({
6850
6963
  for (const issue of snapshot.issues) console.log(` note: ${issue.code}: ${issue.message}`);
6851
6964
  }
6852
6965
  });
6853
- var snapshotsCmd = defineCommand30({
6966
+ var snapshotsCmd = defineCommand31({
6854
6967
  meta: { name: "snapshots", description: "List retained source snapshots for a Team" },
6855
- args: { ...slug2, json: { type: "boolean", description: "Emit JSON" } },
6968
+ args: { ...slug3, json: { type: "boolean", description: "Emit JSON" } },
6856
6969
  async run({ args: args2 }) {
6857
6970
  const client = createClient2();
6858
6971
  const list8 = await client.repositoryReview(args2.id).snapshots();
@@ -6874,10 +6987,10 @@ var snapshotsCmd = defineCommand30({
6874
6987
  for (const line of columnize(rows)) console.log(line);
6875
6988
  }
6876
6989
  });
6877
- var snapshotCmd2 = defineCommand30({
6990
+ var snapshotCmd2 = defineCommand31({
6878
6991
  meta: { name: "snapshot", description: "Show one retained source snapshot" },
6879
6992
  args: {
6880
- ...slug2,
6993
+ ...slug3,
6881
6994
  snapshot: { type: "positional", required: true, description: "Snapshot id" },
6882
6995
  json: { type: "boolean", description: "Emit JSON" }
6883
6996
  },
@@ -6900,13 +7013,13 @@ var snapshotCmd2 = defineCommand30({
6900
7013
  for (const line of columnize(rows)) console.log(line);
6901
7014
  }
6902
7015
  });
6903
- var teamReviewCommand = defineCommand30({
7016
+ var teamReviewCommand = defineCommand31({
6904
7017
  meta: {
6905
7018
  name: "review",
6906
7019
  description: "Read-only Git change review and bounded source snapshots"
6907
7020
  },
6908
7021
  subCommands: {
6909
- show: showCmd6,
7022
+ show: showCmd7,
6910
7023
  capture: captureCmd,
6911
7024
  snapshots: snapshotsCmd,
6912
7025
  snapshot: snapshotCmd2,
@@ -6915,8 +7028,8 @@ var teamReviewCommand = defineCommand30({
6915
7028
  });
6916
7029
 
6917
7030
  // src/commands/team-verify.ts
6918
- import { defineCommand as defineCommand31 } from "citty";
6919
- var slug3 = {
7031
+ import { defineCommand as defineCommand32 } from "citty";
7032
+ var slug4 = {
6920
7033
  id: { type: "positional", required: true, description: "Team slug" }
6921
7034
  };
6922
7035
  var OUTCOME_GLYPH = {
@@ -6932,7 +7045,7 @@ var OUTCOME_GLYPH = {
6932
7045
  function latestAttempt(report) {
6933
7046
  return [...report.attempts].sort((a, b) => b.attemptNumber - a.attemptNumber)[0];
6934
7047
  }
6935
- function printReport2(report) {
7048
+ function printReport3(report) {
6936
7049
  const { request } = report;
6937
7050
  const requester = request.requester.kind === "agent" ? `agent ${request.requester.agentId}` : "operator";
6938
7051
  console.log(`${request.id} ${request.state}`);
@@ -6971,13 +7084,13 @@ function printReport2(report) {
6971
7084
  if (attempt?.error) console.log(` note: ${attempt.error}`);
6972
7085
  if (!attempt) console.log(" note: no attempt has run yet");
6973
7086
  }
6974
- var createCmd4 = defineCommand31({
7087
+ var createCmd5 = defineCommand32({
6975
7088
  meta: {
6976
7089
  name: "create",
6977
7090
  description: "Capture a verification request against a snapshot (does not run checks)"
6978
7091
  },
6979
7092
  args: {
6980
- ...slug3,
7093
+ ...slug4,
6981
7094
  agent: { type: "string", required: true, description: "Team member who will verify" },
6982
7095
  snapshot: { type: "string", required: true, description: "BAZ-042 snapshot id to verify" },
6983
7096
  check: {
@@ -7044,10 +7157,10 @@ var createCmd4 = defineCommand31({
7044
7157
  }
7045
7158
  }
7046
7159
  });
7047
- var listCmd11 = defineCommand31({
7160
+ var listCmd12 = defineCommand32({
7048
7161
  meta: { name: "list", description: "List verification requests for a Team" },
7049
7162
  args: {
7050
- ...slug3,
7163
+ ...slug4,
7051
7164
  json: { type: "boolean", description: "Emit JSON" }
7052
7165
  },
7053
7166
  async run({ args: args2 }) {
@@ -7074,10 +7187,10 @@ var listCmd11 = defineCommand31({
7074
7187
  console.log("run `bazilion team verify show <slug> <id>` for a request's current applicability");
7075
7188
  }
7076
7189
  });
7077
- var showCmd7 = defineCommand31({
7190
+ var showCmd8 = defineCommand32({
7078
7191
  meta: { name: "show", description: "Show one verification request and its evidence" },
7079
7192
  args: {
7080
- ...slug3,
7193
+ ...slug4,
7081
7194
  requestId: { type: "positional", required: true, description: "Verification request id" },
7082
7195
  json: { type: "boolean", description: "Emit JSON" }
7083
7196
  },
@@ -7089,17 +7202,17 @@ var showCmd7 = defineCommand31({
7089
7202
  console.log(JSON.stringify(response, null, 2));
7090
7203
  return;
7091
7204
  }
7092
- printReport2(response.request);
7205
+ printReport3(response.request);
7093
7206
  } catch (error) {
7094
7207
  console.error(error instanceof Error ? error.message : String(error));
7095
7208
  process.exit(1);
7096
7209
  }
7097
7210
  }
7098
7211
  });
7099
- var cancelCmd2 = defineCommand31({
7212
+ var cancelCmd2 = defineCommand32({
7100
7213
  meta: { name: "cancel", description: "Cancel a pending or running verification request" },
7101
7214
  args: {
7102
- ...slug3,
7215
+ ...slug4,
7103
7216
  requestId: { type: "positional", required: true, description: "Verification request id" },
7104
7217
  json: { type: "boolean", description: "Emit JSON" }
7105
7218
  },
@@ -7112,28 +7225,28 @@ var cancelCmd2 = defineCommand31({
7112
7225
  return;
7113
7226
  }
7114
7227
  console.log(`cancelled or cancelled-pending: ${response.request.request.id}`);
7115
- printReport2(response.request);
7228
+ printReport3(response.request);
7116
7229
  } catch (error) {
7117
7230
  console.error(error instanceof Error ? error.message : String(error));
7118
7231
  process.exit(1);
7119
7232
  }
7120
7233
  }
7121
7234
  });
7122
- var verifyCommand = defineCommand31({
7235
+ var verifyCommand = defineCommand32({
7123
7236
  meta: {
7124
7237
  name: "verify",
7125
7238
  description: "Specialist verification of a captured code change (BAZ-044)"
7126
7239
  },
7127
7240
  subCommands: {
7128
- create: createCmd4,
7129
- list: listCmd11,
7130
- show: showCmd7,
7241
+ create: createCmd5,
7242
+ list: listCmd12,
7243
+ show: showCmd8,
7131
7244
  cancel: cancelCmd2
7132
7245
  }
7133
7246
  });
7134
7247
 
7135
7248
  // src/commands/team.ts
7136
- var addCmd2 = defineCommand32({
7249
+ var addCmd2 = defineCommand33({
7137
7250
  meta: {
7138
7251
  name: "add",
7139
7252
  description: "Register a team at ~/.bazilion/teams/<slug>/ (use --link to point at an existing tree)"
@@ -7157,7 +7270,7 @@ var addCmd2 = defineCommand32({
7157
7270
  console.log(`registered team ${g.id} at ${g.path}`);
7158
7271
  }
7159
7272
  });
7160
- var listCmd12 = defineCommand32({
7273
+ var listCmd13 = defineCommand33({
7161
7274
  meta: { name: "list", description: "List teams" },
7162
7275
  async run() {
7163
7276
  const client = createClient2();
@@ -7170,7 +7283,7 @@ var listCmd12 = defineCommand32({
7170
7283
  for (const line of columnize(rows)) console.log(line);
7171
7284
  }
7172
7285
  });
7173
- var rmCmd5 = defineCommand32({
7286
+ var rmCmd5 = defineCommand33({
7174
7287
  meta: { name: "rm", description: "Remove a team registration" },
7175
7288
  args: {
7176
7289
  id: { type: "positional", required: true }
@@ -7191,7 +7304,7 @@ async function readStdin() {
7191
7304
  for await (const chunk of stdin2) chunks.push(chunk);
7192
7305
  return Buffer.concat(chunks).toString("utf8");
7193
7306
  }
7194
- var userMdShowCmd = defineCommand32({
7307
+ var userMdShowCmd = defineCommand33({
7195
7308
  meta: { name: "show", description: "Print the team's USER.md" },
7196
7309
  args: { id: { type: "positional", required: true } },
7197
7310
  async run({ args: args2 }) {
@@ -7201,7 +7314,7 @@ var userMdShowCmd = defineCommand32({
7201
7314
  if (g.userMd && !g.userMd.endsWith("\n")) process.stdout.write("\n");
7202
7315
  }
7203
7316
  });
7204
- var userMdSetCmd = defineCommand32({
7317
+ var userMdSetCmd = defineCommand33({
7205
7318
  meta: {
7206
7319
  name: "set",
7207
7320
  description: "Replace the team's USER.md (from --file, --from-stdin, or inline text)"
@@ -7215,7 +7328,7 @@ var userMdSetCmd = defineCommand32({
7215
7328
  async run({ args: args2 }) {
7216
7329
  let content;
7217
7330
  if (args2["from-stdin"]) content = await readStdin();
7218
- else if (args2.file) content = readFileSync11(args2.file, "utf8");
7331
+ else if (args2.file) content = readFileSync12(args2.file, "utf8");
7219
7332
  else if (args2.text !== void 0) content = args2.text;
7220
7333
  else {
7221
7334
  console.error("team user-md set: provide --file, --from-stdin, or --text");
@@ -7227,7 +7340,7 @@ var userMdSetCmd = defineCommand32({
7227
7340
  console.log(`updated USER.md for team ${args2.id} (${content.length} bytes)`);
7228
7341
  }
7229
7342
  });
7230
- var userMdClearCmd = defineCommand32({
7343
+ var userMdClearCmd = defineCommand33({
7231
7344
  meta: { name: "clear", description: "Clear the team's USER.md to empty" },
7232
7345
  args: { id: { type: "positional", required: true } },
7233
7346
  async run({ args: args2 }) {
@@ -7237,7 +7350,7 @@ var userMdClearCmd = defineCommand32({
7237
7350
  console.log(`cleared USER.md for team ${args2.id}`);
7238
7351
  }
7239
7352
  });
7240
- var userMdCmd = defineCommand32({
7353
+ var userMdCmd = defineCommand33({
7241
7354
  meta: { name: "user-md", description: "View or edit a team's USER.md" },
7242
7355
  subCommands: {
7243
7356
  show: userMdShowCmd,
@@ -7245,7 +7358,7 @@ var userMdCmd = defineCommand32({
7245
7358
  clear: userMdClearCmd
7246
7359
  }
7247
7360
  });
7248
- var topicFormatShowCmd = defineCommand32({
7361
+ var topicFormatShowCmd = defineCommand33({
7249
7362
  meta: { name: "show", description: "Print the team's Telegram topic-name template" },
7250
7363
  args: { id: { type: "positional", required: true } },
7251
7364
  async run({ args: args2 }) {
@@ -7254,7 +7367,7 @@ var topicFormatShowCmd = defineCommand32({
7254
7367
  console.log(g.telegramTopicNameFormat ?? "(default naming)");
7255
7368
  }
7256
7369
  });
7257
- var topicFormatSetCmd = defineCommand32({
7370
+ var topicFormatSetCmd = defineCommand33({
7258
7371
  meta: {
7259
7372
  name: "set",
7260
7373
  description: "Set the topic-name template. Tokens: {agent.name} {team.name} {team.slug} (must include {agent.name})"
@@ -7274,7 +7387,7 @@ var topicFormatSetCmd = defineCommand32({
7274
7387
  console.log(`set topic-name template for team ${args2.id}: ${g.telegramTopicNameFormat}`);
7275
7388
  }
7276
7389
  });
7277
- var topicFormatClearCmd = defineCommand32({
7390
+ var topicFormatClearCmd = defineCommand33({
7278
7391
  meta: { name: "clear", description: "Clear the template (revert to built-in naming)" },
7279
7392
  args: { id: { type: "positional", required: true } },
7280
7393
  async run({ args: args2 }) {
@@ -7284,7 +7397,7 @@ var topicFormatClearCmd = defineCommand32({
7284
7397
  console.log(`cleared topic-name template for team ${args2.id}`);
7285
7398
  }
7286
7399
  });
7287
- var topicFormatCmd = defineCommand32({
7400
+ var topicFormatCmd = defineCommand33({
7288
7401
  meta: {
7289
7402
  name: "topic-format",
7290
7403
  description: "View or edit a team's Telegram forum-topic name template"
@@ -7295,7 +7408,7 @@ var topicFormatCmd = defineCommand32({
7295
7408
  clear: topicFormatClearCmd
7296
7409
  }
7297
7410
  });
7298
- var contextCmd = defineCommand32({
7411
+ var contextCmd = defineCommand33({
7299
7412
  meta: {
7300
7413
  name: "context",
7301
7414
  description: "Inspect repository instructions, Git state and command suggestions"
@@ -7342,16 +7455,17 @@ var contextCmd = defineCommand32({
7342
7455
  console.log(` ${issue.code}${issue.path ? `: ${safe2(issue.path)}` : ""} \u2014 ${issue.message}`);
7343
7456
  }
7344
7457
  });
7345
- var teamCommand = defineCommand32({
7458
+ var teamCommand = defineCommand33({
7346
7459
  meta: { name: "team", description: "Manage teams (collaboration contexts)" },
7347
7460
  subCommands: {
7348
7461
  environment: teamEnvironmentCommand,
7349
7462
  log: teamCodingLogCommand,
7350
7463
  review: teamReviewCommand,
7351
7464
  verify: verifyCommand,
7465
+ publish: teamPublishCommand,
7352
7466
  context: contextCmd,
7353
7467
  add: addCmd2,
7354
- list: listCmd12,
7468
+ list: listCmd13,
7355
7469
  rm: rmCmd5,
7356
7470
  "user-md": userMdCmd,
7357
7471
  "topic-format": topicFormatCmd,
@@ -7360,11 +7474,11 @@ var teamCommand = defineCommand32({
7360
7474
  });
7361
7475
 
7362
7476
  // src/commands/team-template.ts
7363
- import { readFileSync as readFileSync12 } from "fs";
7364
- import { defineCommand as defineCommand33 } from "citty";
7477
+ import { readFileSync as readFileSync13 } from "fs";
7478
+ import { defineCommand as defineCommand34 } from "citty";
7365
7479
  function jsonFile(path) {
7366
7480
  try {
7367
- return JSON.parse(readFileSync12(path, "utf8"));
7481
+ return JSON.parse(readFileSync13(path, "utf8"));
7368
7482
  } catch (error) {
7369
7483
  throw new Error(`invalid JSON: ${error.message}`);
7370
7484
  }
@@ -7389,7 +7503,7 @@ function printTeam(detail) {
7389
7503
  console.log(line);
7390
7504
  }
7391
7505
  }
7392
- var list7 = defineCommand33({
7506
+ var list7 = defineCommand34({
7393
7507
  meta: { name: "list", description: "List canonical Team templates" },
7394
7508
  args: { json: { type: "boolean", description: "Emit stable JSON" } },
7395
7509
  async run({ args: args2 }) {
@@ -7403,7 +7517,7 @@ var list7 = defineCommand33({
7403
7517
  console.log(line);
7404
7518
  }
7405
7519
  });
7406
- var show6 = defineCommand33({
7520
+ var show6 = defineCommand34({
7407
7521
  meta: { name: "show", description: "Show a canonical Team template" },
7408
7522
  args: {
7409
7523
  id: { type: "positional", required: true },
@@ -7417,7 +7531,7 @@ var show6 = defineCommand33({
7417
7531
  else printTeam(detail);
7418
7532
  }
7419
7533
  });
7420
- var exportCommand2 = defineCommand33({
7534
+ var exportCommand2 = defineCommand34({
7421
7535
  meta: {
7422
7536
  name: "export",
7423
7537
  description: "Export a portable versioned Team-template document to stdout"
@@ -7457,7 +7571,7 @@ function printImportDiff(current, document) {
7457
7571
  for (const value of diff2.added) console.log(` + ${value}`);
7458
7572
  for (const value of diff2.removed) console.log(` - ${value}`);
7459
7573
  }
7460
- var importCommand2 = defineCommand33({
7574
+ var importCommand2 = defineCommand34({
7461
7575
  meta: {
7462
7576
  name: "import",
7463
7577
  description: "Validate, diff, and explicitly apply a portable Team-template document"
@@ -7538,7 +7652,7 @@ var importCommand2 = defineCommand33({
7538
7652
  );
7539
7653
  }
7540
7654
  });
7541
- var teamTemplateCommand = defineCommand33({
7655
+ var teamTemplateCommand = defineCommand34({
7542
7656
  meta: {
7543
7657
  name: "team-template",
7544
7658
  description: "Inspect and exchange canonical Team templates"
@@ -7547,8 +7661,8 @@ var teamTemplateCommand = defineCommand33({
7547
7661
  });
7548
7662
 
7549
7663
  // src/commands/telegram.ts
7550
- import { defineCommand as defineCommand34 } from "citty";
7551
- var setCmd2 = defineCommand34({
7664
+ import { defineCommand as defineCommand35 } from "citty";
7665
+ var setCmd2 = defineCommand35({
7552
7666
  meta: {
7553
7667
  name: "set",
7554
7668
  description: "Save bot token + supergroup chat ID (paired write)"
@@ -7566,7 +7680,7 @@ var setCmd2 = defineCommand34({
7566
7680
  console.log(`saved \xB7 token ${state.botTokenPreview} \xB7 chat ${state.chatId}`);
7567
7681
  }
7568
7682
  });
7569
- var clearCmd = defineCommand34({
7683
+ var clearCmd = defineCommand35({
7570
7684
  meta: {
7571
7685
  name: "clear",
7572
7686
  description: "Remove stored bot token + chat ID"
@@ -7577,7 +7691,7 @@ var clearCmd = defineCommand34({
7577
7691
  console.log("cleared");
7578
7692
  }
7579
7693
  });
7580
- var showCmd8 = defineCommand34({
7694
+ var showCmd9 = defineCommand35({
7581
7695
  meta: {
7582
7696
  name: "show",
7583
7697
  description: "Show what credentials are stored (token is masked)"
@@ -7598,7 +7712,7 @@ var showCmd8 = defineCommand34({
7598
7712
  }
7599
7713
  }
7600
7714
  });
7601
- var reconnectCmd = defineCommand34({
7715
+ var reconnectCmd = defineCommand35({
7602
7716
  meta: {
7603
7717
  name: "reconnect",
7604
7718
  description: "Apply a pending supergroup chat-id migration + re-activate the bot"
@@ -7609,7 +7723,7 @@ var reconnectCmd = defineCommand34({
7609
7723
  console.log(`reconnected \xB7 chat ${state.chatId}`);
7610
7724
  }
7611
7725
  });
7612
- var configCmd = defineCommand34({
7726
+ var configCmd = defineCommand35({
7613
7727
  meta: {
7614
7728
  name: "config",
7615
7729
  description: "Manage Telegram credentials (bot token + chat ID)"
@@ -7617,10 +7731,10 @@ var configCmd = defineCommand34({
7617
7731
  subCommands: {
7618
7732
  set: setCmd2,
7619
7733
  clear: clearCmd,
7620
- show: showCmd8
7734
+ show: showCmd9
7621
7735
  }
7622
7736
  });
7623
- var healthCmd = defineCommand34({
7737
+ var healthCmd = defineCommand35({
7624
7738
  meta: {
7625
7739
  name: "health",
7626
7740
  description: "Run the four-step preflight against the Telegram Bot API"
@@ -7659,7 +7773,7 @@ var healthCmd = defineCommand34({
7659
7773
  if (!allOk) process.exitCode = 1;
7660
7774
  }
7661
7775
  });
7662
- var botStatusCmd = defineCommand34({
7776
+ var botStatusCmd = defineCommand35({
7663
7777
  meta: {
7664
7778
  name: "status",
7665
7779
  description: "Show polling state of the live bot"
@@ -7684,7 +7798,7 @@ var botStatusCmd = defineCommand34({
7684
7798
  if (!p.running) process.exitCode = 1;
7685
7799
  }
7686
7800
  });
7687
- var botRestartCmd = defineCommand34({
7801
+ var botRestartCmd = defineCommand35({
7688
7802
  meta: {
7689
7803
  name: "restart",
7690
7804
  description: "Force-restart the bot (tears down + brings up from current creds)"
@@ -7695,7 +7809,7 @@ var botRestartCmd = defineCommand34({
7695
7809
  console.log("restart requested");
7696
7810
  }
7697
7811
  });
7698
- var botCmd = defineCommand34({
7812
+ var botCmd = defineCommand35({
7699
7813
  meta: {
7700
7814
  name: "bot",
7701
7815
  description: "Inspect / control the live polling bot"
@@ -7705,7 +7819,7 @@ var botCmd = defineCommand34({
7705
7819
  restart: botRestartCmd
7706
7820
  }
7707
7821
  });
7708
- var bindCmd = defineCommand34({
7822
+ var bindCmd = defineCommand35({
7709
7823
  meta: {
7710
7824
  name: "bind",
7711
7825
  description: "Create a Telegram topic for an agent (manual fallback for /talk)"
@@ -7723,7 +7837,7 @@ var bindCmd = defineCommand34({
7723
7837
  console.log(` ${result.deepLink}`);
7724
7838
  }
7725
7839
  });
7726
- var unbindCmd = defineCommand34({
7840
+ var unbindCmd = defineCommand35({
7727
7841
  meta: {
7728
7842
  name: "unbind",
7729
7843
  description: "Clear an agent's Telegram topic binding (topic stays in Telegram as orphan)"
@@ -7737,7 +7851,7 @@ var unbindCmd = defineCommand34({
7737
7851
  console.log(`unbound agent ${args2.agent}`);
7738
7852
  }
7739
7853
  });
7740
- var listBindingsCmd = defineCommand34({
7854
+ var listBindingsCmd = defineCommand35({
7741
7855
  meta: {
7742
7856
  name: "list",
7743
7857
  description: "List agents and their Telegram topic bindings"
@@ -7765,7 +7879,7 @@ var listBindingsCmd = defineCommand34({
7765
7879
  }
7766
7880
  }
7767
7881
  });
7768
- var allowCmd = defineCommand34({
7882
+ var allowCmd = defineCommand35({
7769
7883
  meta: { name: "allow", description: "Add a Telegram user id to the allowlist" },
7770
7884
  args: {
7771
7885
  userId: { type: "positional", required: true, description: "Numeric Telegram user id" },
@@ -7781,7 +7895,7 @@ var allowCmd = defineCommand34({
7781
7895
  console.log(`allowed ${u.userId} (${u.role})`);
7782
7896
  }
7783
7897
  });
7784
- var denyCmd = defineCommand34({
7898
+ var denyCmd = defineCommand35({
7785
7899
  meta: { name: "deny", description: "Remove a Telegram user id from the allowlist" },
7786
7900
  args: { userId: { type: "positional", required: true } },
7787
7901
  async run({ args: args2 }) {
@@ -7790,7 +7904,7 @@ var denyCmd = defineCommand34({
7790
7904
  console.log(`removed ${args2.userId}`);
7791
7905
  }
7792
7906
  });
7793
- var allowedCmd = defineCommand34({
7907
+ var allowedCmd = defineCommand35({
7794
7908
  meta: { name: "allowed", description: "List allowlisted Telegram users" },
7795
7909
  async run() {
7796
7910
  const client = createClient2();
@@ -7805,7 +7919,7 @@ var allowedCmd = defineCommand34({
7805
7919
  }
7806
7920
  }
7807
7921
  });
7808
- var pairingCreateCmd = defineCommand34({
7922
+ var pairingCreateCmd = defineCommand35({
7809
7923
  meta: { name: "create", description: "Generate a one-time Telegram owner pairing code" },
7810
7924
  async run() {
7811
7925
  const result = await createClient2().post(
@@ -7816,7 +7930,7 @@ var pairingCreateCmd = defineCommand34({
7816
7930
  console.log("send `/pair <code>` in the configured \u2699 bazilion service topic");
7817
7931
  }
7818
7932
  });
7819
- var pairingStatusCmd = defineCommand34({
7933
+ var pairingStatusCmd = defineCommand35({
7820
7934
  meta: { name: "status", description: "Show Telegram owner pairing status" },
7821
7935
  async run() {
7822
7936
  const result = await createClient2().get("/api/config/telegram/pairing");
@@ -7827,14 +7941,14 @@ var pairingStatusCmd = defineCommand34({
7827
7941
  console.log(`expires: ${new Date(result.challengeExpiresAt).toISOString()}`);
7828
7942
  }
7829
7943
  });
7830
- var pairingCancelCmd = defineCommand34({
7944
+ var pairingCancelCmd = defineCommand35({
7831
7945
  meta: { name: "cancel", description: "Cancel the active Telegram pairing code" },
7832
7946
  async run() {
7833
7947
  await createClient2().del("/api/config/telegram/pairing/challenge");
7834
7948
  console.log("pairing challenge cancelled");
7835
7949
  }
7836
7950
  });
7837
- var pairingResetCmd = defineCommand34({
7951
+ var pairingResetCmd = defineCommand35({
7838
7952
  meta: { name: "reset", description: "Revoke the Telegram owner and require re-pairing" },
7839
7953
  args: {
7840
7954
  yes: { type: "boolean", description: "Confirm destructive owner reset", required: true }
@@ -7845,7 +7959,7 @@ var pairingResetCmd = defineCommand34({
7845
7959
  console.log("Telegram owner reset; ingress is closed until re-paired");
7846
7960
  }
7847
7961
  });
7848
- var pairingCmd = defineCommand34({
7962
+ var pairingCmd = defineCommand35({
7849
7963
  meta: { name: "pairing", description: "Manage single-owner Telegram pairing" },
7850
7964
  subCommands: {
7851
7965
  create: pairingCreateCmd,
@@ -7854,7 +7968,7 @@ var pairingCmd = defineCommand34({
7854
7968
  reset: pairingResetCmd
7855
7969
  }
7856
7970
  });
7857
- var telegramCommand = defineCommand34({
7971
+ var telegramCommand = defineCommand35({
7858
7972
  meta: {
7859
7973
  name: "telegram",
7860
7974
  description: "Telegram integration: credentials, health, bot lifecycle, bindings, access"
@@ -7875,14 +7989,14 @@ var telegramCommand = defineCommand34({
7875
7989
  });
7876
7990
 
7877
7991
  // src/commands/token.ts
7878
- import { defineCommand as defineCommand35 } from "citty";
7992
+ import { defineCommand as defineCommand36 } from "citty";
7879
7993
  import qrcode from "qrcode-terminal";
7880
7994
  function tokenRow(t) {
7881
7995
  const last = t.lastUsedAt ? new Date(t.lastUsedAt).toISOString() : "(never)";
7882
7996
  const expired = t.expiresAt !== null && t.expiresAt <= Date.now();
7883
7997
  const state = t.revokedAt ? "revoked" : expired ? "expired" : "active";
7884
7998
  const expires = t.expiresAt ? new Date(t.expiresAt).toISOString() : "(never)";
7885
- return [t.id, t.kind, state, t.label, `expires: ${expires}`, `last: ${last}`];
7999
+ return [t.id, t.kind, state, t.label, t.scopes.join(" "), `expires: ${expires}`, `last: ${last}`];
7886
8000
  }
7887
8001
  function resolveQrServer(override) {
7888
8002
  const raw = override ?? loadClientConfig().serverUrl;
@@ -7904,7 +8018,7 @@ function resolveQrServer(override) {
7904
8018
  }
7905
8019
  return url.origin;
7906
8020
  }
7907
- var createCmd5 = defineCommand35({
8021
+ var createCmd6 = defineCommand36({
7908
8022
  meta: { name: "create", description: "Mint a new web token (shown once)" },
7909
8023
  args: {
7910
8024
  label: { type: "positional", required: true, description: "Human-readable label" },
@@ -7919,19 +8033,29 @@ var createCmd5 = defineCommand35({
7919
8033
  expiresDays: {
7920
8034
  type: "string",
7921
8035
  description: "Device lifetime in days (default 90, maximum 365)"
8036
+ },
8037
+ scope: {
8038
+ type: "string",
8039
+ description: "Authorization scope; repeat for more (read, write, approvals, admin). Default: all scopes."
7922
8040
  }
7923
8041
  },
7924
- async run({ args: args2 }) {
8042
+ async run({ args: args2, rawArgs }) {
7925
8043
  const client = createClient2();
7926
8044
  const expiresInDays = args2.expiresDays === void 0 ? void 0 : Number(args2.expiresDays);
7927
8045
  if (expiresInDays !== void 0 && !Number.isInteger(expiresInDays)) {
7928
8046
  throw new Error("--expires-days must be an integer");
7929
8047
  }
7930
- const body = { label: args2.label, expiresInDays };
8048
+ const scopes = collectFlagValues(rawArgs, "scope");
8049
+ const body = {
8050
+ label: args2.label,
8051
+ expiresInDays,
8052
+ ...scopes.length > 0 ? { scopes } : {}
8053
+ };
7931
8054
  const res = await client.post("/api/tokens", body);
7932
- console.log(`id: ${res.meta.id}`);
7933
- console.log(`label: ${res.meta.label}`);
7934
- console.log(`kind: ${res.meta.kind}`);
8055
+ console.log(`id: ${res.meta.id}`);
8056
+ console.log(`label: ${res.meta.label}`);
8057
+ console.log(`kind: ${res.meta.kind}`);
8058
+ console.log(`scopes: ${res.meta.scopes.join(" ")}`);
7935
8059
  console.log(
7936
8060
  `expires: ${res.meta.expiresAt ? new Date(res.meta.expiresAt).toISOString() : "(never)"}`
7937
8061
  );
@@ -7947,7 +8071,44 @@ var createCmd5 = defineCommand35({
7947
8071
  qrcode.generate(pairUrl, { small: true }, (qr) => console.log(qr));
7948
8072
  }
7949
8073
  });
7950
- var listCmd13 = defineCommand35({
8074
+ var pairCmd = defineCommand36({
8075
+ meta: {
8076
+ name: "pair",
8077
+ description: "Mint a one-paste pairing setup code for a new device (10 min, single use)"
8078
+ },
8079
+ args: {
8080
+ scope: {
8081
+ type: "string",
8082
+ description: "Authorization scope for the minted device credential; repeat for more. Default: all scopes."
8083
+ },
8084
+ server: {
8085
+ type: "string",
8086
+ description: "Server URL to embed in the setup code (default: detect LAN IP; pass the gateway HTTPS origin for remote devices)"
8087
+ }
8088
+ },
8089
+ async run({ args: args2, rawArgs }) {
8090
+ const client = createClient2();
8091
+ const scopes = collectFlagValues(rawArgs, "scope");
8092
+ const res = await client.post("/api/pair/codes", {
8093
+ ...scopes.length > 0 ? { scopes } : {}
8094
+ });
8095
+ let setupUrl = res.setupUrl;
8096
+ if (args2.server) {
8097
+ const serverUrl = resolveQrServer(args2.server);
8098
+ setupUrl = `bazilion-pair://pair?server=${encodeURIComponent(serverUrl)}&code=${encodeURIComponent(res.code)}`;
8099
+ }
8100
+ console.log(`id: ${res.meta.id}`);
8101
+ console.log(`scopes: ${res.meta.scopes.join(" ")}`);
8102
+ console.log(`expires: ${new Date(res.meta.expiresAt).toISOString()} (10 minutes, single use)`);
8103
+ console.log("");
8104
+ console.log(`setup URL (paste or scan on the new device):`);
8105
+ console.log(setupUrl);
8106
+ console.log("");
8107
+ console.log("the code admits exactly one credential exchange; after that it is inert.");
8108
+ qrcode.generate(setupUrl, { small: true }, (qr) => console.log(qr));
8109
+ }
8110
+ });
8111
+ var listCmd14 = defineCommand36({
7951
8112
  meta: { name: "list", description: "List web tokens" },
7952
8113
  args: {
7953
8114
  all: { type: "boolean", description: "Include revoked tokens" }
@@ -7963,7 +8124,7 @@ var listCmd13 = defineCommand35({
7963
8124
  for (const line of columnize(tokens.map(tokenRow))) console.log(line);
7964
8125
  }
7965
8126
  });
7966
- var showLocalCmd = defineCommand35({
8127
+ var showLocalCmd = defineCommand36({
7967
8128
  meta: {
7968
8129
  name: "show-local",
7969
8130
  description: "Print the bootstrap web token stored in ~/.bazilion/auth.json"
@@ -7973,7 +8134,7 @@ var showLocalCmd = defineCommand35({
7973
8134
  console.log(readAuthFile(paths.authFile).token);
7974
8135
  }
7975
8136
  });
7976
- var revokeCmd2 = defineCommand35({
8137
+ var revokeCmd2 = defineCommand36({
7977
8138
  meta: { name: "revoke", description: "Revoke a web token" },
7978
8139
  args: {
7979
8140
  id: { type: "positional", required: true }
@@ -7984,19 +8145,20 @@ var revokeCmd2 = defineCommand35({
7984
8145
  console.log(`revoked token ${args2.id}`);
7985
8146
  }
7986
8147
  });
7987
- var tokenCommand = defineCommand35({
8148
+ var tokenCommand = defineCommand36({
7988
8149
  meta: { name: "token", description: "Manage web tokens for API/CLI clients" },
7989
8150
  subCommands: {
7990
- create: createCmd5,
7991
- list: listCmd13,
8151
+ create: createCmd6,
8152
+ pair: pairCmd,
8153
+ list: listCmd14,
7992
8154
  revoke: revokeCmd2,
7993
8155
  "show-local": showLocalCmd
7994
8156
  }
7995
8157
  });
7996
8158
 
7997
8159
  // src/commands/trigger.ts
7998
- import { defineCommand as defineCommand36 } from "citty";
7999
- var addCmd3 = defineCommand36({
8160
+ import { defineCommand as defineCommand37 } from "citty";
8161
+ var addCmd3 = defineCommand37({
8000
8162
  meta: { name: "add", description: "Add an interval / cron trigger to an agent" },
8001
8163
  args: {
8002
8164
  agent: { type: "positional", required: true },
@@ -8044,7 +8206,7 @@ function triggerRow(t) {
8044
8206
  const msgPreview = t.message.length > 60 ? `${t.message.slice(0, 60)}\u2026` : t.message;
8045
8207
  return [t.id, state, spec, `last: ${last}`, `"${msgPreview}"`];
8046
8208
  }
8047
- var listCmd14 = defineCommand36({
8209
+ var listCmd15 = defineCommand37({
8048
8210
  meta: { name: "list", description: "List triggers for an agent" },
8049
8211
  args: {
8050
8212
  agent: { type: "positional", required: true }
@@ -8061,7 +8223,7 @@ var listCmd14 = defineCommand36({
8061
8223
  for (const line of columnize(triggers.map(triggerRow))) console.log(line);
8062
8224
  }
8063
8225
  });
8064
- var rmCmd6 = defineCommand36({
8226
+ var rmCmd6 = defineCommand37({
8065
8227
  meta: { name: "rm", description: "Delete a trigger" },
8066
8228
  args: {
8067
8229
  id: { type: "positional", required: true }
@@ -8072,7 +8234,7 @@ var rmCmd6 = defineCommand36({
8072
8234
  console.log(`removed trigger ${args2.id}`);
8073
8235
  }
8074
8236
  });
8075
- var enableCmd3 = defineCommand36({
8237
+ var enableCmd3 = defineCommand37({
8076
8238
  meta: { name: "enable", description: "Enable a trigger" },
8077
8239
  args: {
8078
8240
  id: { type: "positional", required: true }
@@ -8084,7 +8246,7 @@ var enableCmd3 = defineCommand36({
8084
8246
  console.log(`enabled trigger ${args2.id}`);
8085
8247
  }
8086
8248
  });
8087
- var disableCmd3 = defineCommand36({
8249
+ var disableCmd3 = defineCommand37({
8088
8250
  meta: { name: "disable", description: "Disable a trigger" },
8089
8251
  args: {
8090
8252
  id: { type: "positional", required: true }
@@ -8096,7 +8258,7 @@ var disableCmd3 = defineCommand36({
8096
8258
  console.log(`disabled trigger ${args2.id}`);
8097
8259
  }
8098
8260
  });
8099
- var historyCmd = defineCommand36({
8261
+ var historyCmd = defineCommand37({
8100
8262
  meta: { name: "history", description: "Show recent dispatches for a trigger" },
8101
8263
  args: {
8102
8264
  id: { type: "positional", required: true },
@@ -8124,11 +8286,11 @@ var historyCmd = defineCommand36({
8124
8286
  for (const line of columnize(rows)) console.log(line);
8125
8287
  }
8126
8288
  });
8127
- var triggerCommand = defineCommand36({
8289
+ var triggerCommand = defineCommand37({
8128
8290
  meta: { name: "trigger", description: "Manage scheduled agent triggers" },
8129
8291
  subCommands: {
8130
8292
  add: addCmd3,
8131
- list: listCmd14,
8293
+ list: listCmd15,
8132
8294
  rm: rmCmd6,
8133
8295
  enable: enableCmd3,
8134
8296
  disable: disableCmd3,
@@ -8137,10 +8299,10 @@ var triggerCommand = defineCommand36({
8137
8299
  });
8138
8300
 
8139
8301
  // src/commands/uninstall.ts
8140
- import { existsSync as existsSync7, lstatSync as lstatSync4, readdirSync as readdirSync2, realpathSync as realpathSync2, rmSync as rmSync4 } from "fs";
8302
+ import { existsSync as existsSync7, lstatSync as lstatSync4, readdirSync as readdirSync3, realpathSync as realpathSync2, rmSync as rmSync4 } from "fs";
8141
8303
  import { homedir as homedir2 } from "os";
8142
- import { isAbsolute as isAbsolute2, join as join6, parse as parse2, relative as relative2, resolve as resolve5, sep } from "path";
8143
- import { defineCommand as defineCommand37 } from "citty";
8304
+ import { isAbsolute as isAbsolute2, join as join7, parse as parse2, relative as relative2, resolve as resolve5, sep } from "path";
8305
+ import { defineCommand as defineCommand38 } from "citty";
8144
8306
  function makeLineReader() {
8145
8307
  let buffer = "";
8146
8308
  let ended = false;
@@ -8227,7 +8389,7 @@ function assertSafeUninstallHome(home) {
8227
8389
  }
8228
8390
  return target;
8229
8391
  }
8230
- var uninstallCommand = defineCommand37({
8392
+ var uninstallCommand = defineCommand38({
8231
8393
  meta: {
8232
8394
  name: "uninstall",
8233
8395
  description: "Wipe bazilion state from ~/.bazilion (or BAZILION_HOME)"
@@ -8246,15 +8408,15 @@ var uninstallCommand = defineCommand37({
8246
8408
  async run({ args: args2 }) {
8247
8409
  const paths = resolveCliPaths(args2.home);
8248
8410
  const targetHome = assertSafeUninstallHome(paths.home);
8249
- const dbFile = join6(targetHome, "bazilion.db");
8250
- const profilesDir = join6(targetHome, "profiles");
8251
- const agentsDir = join6(targetHome, "agents");
8252
- const teamsDir = join6(targetHome, "teams");
8253
- const legacyGroupsDir = join6(targetHome, "groups");
8254
- const skillsDir = join6(targetHome, "skills");
8255
- const logsDir = join6(targetHome, "logs");
8256
- const legacyConfigFile = join6(targetHome, "config.json");
8257
- const legacySecretsFile = join6(targetHome, "secrets.enc");
8411
+ const dbFile = join7(targetHome, "bazilion.db");
8412
+ const profilesDir = join7(targetHome, "profiles");
8413
+ const agentsDir = join7(targetHome, "agents");
8414
+ const teamsDir = join7(targetHome, "teams");
8415
+ const legacyGroupsDir = join7(targetHome, "groups");
8416
+ const skillsDir = join7(targetHome, "skills");
8417
+ const logsDir = join7(targetHome, "logs");
8418
+ const legacyConfigFile = join7(targetHome, "config.json");
8419
+ const legacySecretsFile = join7(targetHome, "secrets.enc");
8258
8420
  if (!existsSync7(targetHome)) {
8259
8421
  const uninstallLock2 = await acquireHomeRestoreLock(targetHome, "uninstalling");
8260
8422
  try {
@@ -8273,7 +8435,7 @@ var uninstallCommand = defineCommand37({
8273
8435
  `${dbFile}-wal`,
8274
8436
  `${dbFile}-shm`,
8275
8437
  `${dbFile}-journal`,
8276
- join6(targetHome, "auth.json"),
8438
+ join7(targetHome, "auth.json"),
8277
8439
  legacyConfigFile,
8278
8440
  legacySecretsFile,
8279
8441
  profilesDir,
@@ -8307,10 +8469,10 @@ var uninstallCommand = defineCommand37({
8307
8469
  for (const p of fullWipeTargets) {
8308
8470
  if (removePath(p)) console.log(`removed ${p}`);
8309
8471
  }
8310
- if (readdirSync2(targetHome).length === 0 && !homeIsSymlink) {
8472
+ if (readdirSync3(targetHome).length === 0 && !homeIsSymlink) {
8311
8473
  rmSync4(targetHome, { recursive: true, force: true });
8312
8474
  console.log(`removed ${targetHome}`);
8313
- } else if (homeIsSymlink && readdirSync2(targetHome).length === 0) {
8475
+ } else if (homeIsSymlink && readdirSync3(targetHome).length === 0) {
8314
8476
  console.log(`kept ${targetHome}: symlinked BAZILION_HOME root is now empty`);
8315
8477
  } else {
8316
8478
  console.log(`${targetHome} still has unmanaged files; left in place`);
@@ -8331,7 +8493,7 @@ var uninstallCommand = defineCommand37({
8331
8493
 
8332
8494
  // src/index.ts
8333
8495
  var VERSION = package_default.version;
8334
- var main = defineCommand38({
8496
+ var main = defineCommand39({
8335
8497
  meta: {
8336
8498
  name: "bazilion",
8337
8499
  version: VERSION,