@chibitek/chibi 0.1.186 → 0.1.188

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 (97) hide show
  1. package/dist/assets/{abnfDiagram-O67JEVCF-T4rFqxxY.js → abnfDiagram-O67JEVCF-CKDXgnYw.js} +1 -1
  2. package/dist/assets/{arc-BE0n08tb.js → arc--VPK-xet.js} +1 -1
  3. package/dist/assets/{architectureDiagram-NJMV4G6O-W248FhnN.js → architectureDiagram-NJMV4G6O-DSVjpq7n.js} +1 -1
  4. package/dist/assets/{blockDiagram-BEXU5L5S-YQUaYL76.js → blockDiagram-BEXU5L5S-BiQ1JgSl.js} +1 -1
  5. package/dist/assets/{c4Diagram-YGBWAQC7-DvtNnJ7Q.js → c4Diagram-YGBWAQC7-kWWEc-NZ.js} +1 -1
  6. package/dist/assets/channel-CQdxuHwI.js +1 -0
  7. package/dist/assets/{chunk-2Q5K7J3B-r9zB0AN4.js → chunk-2Q5K7J3B-QJYqMtWJ.js} +1 -1
  8. package/dist/assets/{chunk-3FUC2YCW-DcaWZ44l.js → chunk-3FUC2YCW-C7oGYTZS.js} +2 -2
  9. package/dist/assets/{chunk-5VM5RSS4-B9BoCCOM.js → chunk-5VM5RSS4-MahQWTzh.js} +1 -1
  10. package/dist/assets/{chunk-GTNCS2PH-jiyufqr5.js → chunk-GTNCS2PH-CQfOvr7l.js} +1 -1
  11. package/dist/assets/{chunk-GWA4HPMP-86KjuKSi.js → chunk-GWA4HPMP-b0lt02Pi.js} +1 -1
  12. package/dist/assets/{chunk-JWPE2WC7-P-CZmlpX.js → chunk-JWPE2WC7-J1_ylbx8.js} +1 -1
  13. package/dist/assets/{chunk-NETBCI7D-DOwQkah7.js → chunk-NETBCI7D-AWcL9tld.js} +1 -1
  14. package/dist/assets/{chunk-WEXAMYUT-BYpUWdau.js → chunk-WEXAMYUT-DpTrAXJV.js} +1 -1
  15. package/dist/assets/{chunk-XXDRQBXY-BNWicp85.js → chunk-XXDRQBXY-2_DCjtc9.js} +1 -1
  16. package/dist/assets/{classDiagram-v2-NBCMYWYE-DeSoK71a.js → classDiagram-v2-NBCMYWYE-BBQMtHHs.js} +1 -1
  17. package/dist/assets/{cose-bilkent-JH36ORCC-DRvyy4x6.js → cose-bilkent-JH36ORCC-CmxRmDe8.js} +1 -1
  18. package/dist/assets/{cynefin-OW5HDTMX-BPgTdM9o.js → cynefin-OW5HDTMX-DjlothXK.js} +1 -1
  19. package/dist/assets/{cynefinDiagram-VND7K2PF-CVqWmCzX.js → cynefinDiagram-VND7K2PF-D6HfzP26.js} +1 -1
  20. package/dist/assets/{dagre-6A5THRUB-C8Nn1Pd7.js → dagre-6A5THRUB-BtzaxY50.js} +1 -1
  21. package/dist/assets/{diagram-22UHCM2B-BoFPCHMw.js → diagram-22UHCM2B-DsyCiGJD.js} +1 -1
  22. package/dist/assets/{diagram-3UASUU5V-Bw55J1mb.js → diagram-3UASUU5V-CjjvxIr3.js} +1 -1
  23. package/dist/assets/{diagram-ATOU4E4O-DGQrBqML.js → diagram-ATOU4E4O-DDu2iVRb.js} +1 -1
  24. package/dist/assets/{diagram-CDSNMT55-COdY5ptf.js → diagram-CDSNMT55-BBTViw3h.js} +1 -1
  25. package/dist/assets/{diagram-MLGK6HIB-BPZDoncY.js → diagram-MLGK6HIB-D83j4C6w.js} +1 -1
  26. package/dist/assets/{diagram-MPIPVDR6-Fi29WkCR.js → diagram-MPIPVDR6-DTpmpL8Q.js} +1 -1
  27. package/dist/assets/{ebnfDiagram-ZINNZB2B-BXquz6x1.js → ebnfDiagram-ZINNZB2B-D3B4hz_Y.js} +1 -1
  28. package/dist/assets/{elk-276RUBZZ-C_e9eijP.js → elk-276RUBZZ-CbNicGf_.js} +1 -1
  29. package/dist/assets/{erDiagram-OPXOYQCR-C4PKtrfT.js → erDiagram-OPXOYQCR-DeSwxwFC.js} +1 -1
  30. package/dist/assets/{flowDiagram-KWPJA3E3-BlEulfZP.js → flowDiagram-KWPJA3E3-3n_Hk-ZR.js} +1 -1
  31. package/dist/assets/{ganttDiagram-FUAMR5RP-BksDszQx.js → ganttDiagram-FUAMR5RP-BsadEPTf.js} +1 -1
  32. package/dist/assets/{gitGraphDiagram-X574FWY7-EYJKMot5.js → gitGraphDiagram-X574FWY7-DOvqN3Jh.js} +1 -1
  33. package/dist/assets/{index-Bf2yMkX_.js → index-B9LCl5y3.js} +133 -133
  34. package/dist/assets/{index-Do0zrygp.js → index-BmYLMFD8.js} +1 -1
  35. package/dist/assets/{infoDiagram-VRGFBTTK-BuX8YJRd.js → infoDiagram-VRGFBTTK-CI3tfMt9.js} +1 -1
  36. package/dist/assets/{ishikawaDiagram-OU5B5YK6-BOOBBq5e.js → ishikawaDiagram-OU5B5YK6-BE7AjZYf.js} +1 -1
  37. package/dist/assets/{journeyDiagram-ZHPQQLJL-2VfxHa4O.js → journeyDiagram-ZHPQQLJL-DplNZPox.js} +1 -1
  38. package/dist/assets/{kanban-definition-PNTS6WVX-DniBc17b.js → kanban-definition-PNTS6WVX-Cos64we-.js} +1 -1
  39. package/dist/assets/{linear-CrF1eGjn.js → linear-DDfQb-jo.js} +1 -1
  40. package/dist/assets/{mermaid.core-BL_dHjXO.js → mermaid.core-BekbnuLb.js} +5 -5
  41. package/dist/assets/{mindmap-definition-NLK3R4M7-DUGzdUse.js → mindmap-definition-NLK3R4M7-DJ0MbzMW.js} +1 -1
  42. package/dist/assets/{pegDiagram-GJSIUBJH-CO3xT6J0.js → pegDiagram-GJSIUBJH-DZNZCZ4O.js} +1 -1
  43. package/dist/assets/{pieDiagram-5QR66LMP-8gmuAKxu.js → pieDiagram-5QR66LMP-COD5v2yC.js} +1 -1
  44. package/dist/assets/{quadrantDiagram-O4NWA36T-D0I0xUDm.js → quadrantDiagram-O4NWA36T-D4dlLWfv.js} +1 -1
  45. package/dist/assets/{railroadDiagram-XR7U4H2S-DY0BvxgQ.js → railroadDiagram-XR7U4H2S-CEpVYFKl.js} +1 -1
  46. package/dist/assets/{requirementDiagram-PLB6GJNP-DhGe1AaP.js → requirementDiagram-PLB6GJNP-DYD5GX0G.js} +1 -1
  47. package/dist/assets/{sankeyDiagram-IPEJSGJF-CeCrbMFN.js → sankeyDiagram-IPEJSGJF-C9bPeTfK.js} +1 -1
  48. package/dist/assets/{sequenceDiagram-PO4LG4MO-fWSeitKd.js → sequenceDiagram-PO4LG4MO-eXpmPg9C.js} +1 -1
  49. package/dist/assets/{sizeCapture-INFHLROL-Dtg_1bqe.js → sizeCapture-INFHLROL-DfqKWBhp.js} +1 -1
  50. package/dist/assets/{stateDiagram-v2-GCMORJYK-DGUAiQQE.js → stateDiagram-v2-GCMORJYK-DkIf90iA.js} +1 -1
  51. package/dist/assets/{swimlanes-2SLR337P-DebVwPYw.js → swimlanes-2SLR337P-Ds64cQxN.js} +1 -1
  52. package/dist/assets/swimlanesDiagram-TC7HE7FX-bO3Klz6Z.js +8 -0
  53. package/dist/assets/{timeline-definition-EJHVYXUP-Dg7oYgtr.js → timeline-definition-EJHVYXUP-Ci3-31qT.js} +1 -1
  54. package/dist/assets/{usecaseDiagram-POWQR4AR-uqTnPXSC.js → usecaseDiagram-POWQR4AR-DQUGgfBf.js} +1 -1
  55. package/dist/assets/{vennDiagram-UO4OBE2U-CzMUwXwR.js → vennDiagram-UO4OBE2U-DV5_nmWl.js} +1 -1
  56. package/dist/assets/{wardleyDiagram-VNRHLVJA-BsyaKB_7.js → wardleyDiagram-VNRHLVJA-DatPTthc.js} +1 -1
  57. package/dist/assets/{xychartDiagram-PMCCYNJV-7hUye0pF.js → xychartDiagram-PMCCYNJV-ADaxt1QH.js} +1 -1
  58. package/dist/index.html +1 -1
  59. package/dist-server/drivers/agents-proxy.js +41 -1
  60. package/dist-server/index.js +1235 -997
  61. package/dist-server/openmausbot.js +54 -34
  62. package/dist-server/pair-cli.js +54 -34
  63. package/dist-server/server/about-me-sync.js +16 -5
  64. package/dist-server/server/box.js +18 -14
  65. package/dist-server/server/browser-engine.js +4 -26
  66. package/dist-server/server/calendar-calls.js +2 -1
  67. package/dist-server/server/capped-body.js +26 -0
  68. package/dist-server/server/container-computer.js +9 -9
  69. package/dist-server/server/drivers/agents-call.js +3 -3
  70. package/dist-server/server/drivers/agents-catalog.js +2 -2
  71. package/dist-server/server/drivers/agents-credential.js +6 -0
  72. package/dist-server/server/drivers/agents-vault.js +35 -0
  73. package/dist-server/server/engine-failover.js +6 -3
  74. package/dist-server/server/engine-tiers.js +4 -4
  75. package/dist-server/server/index.js +16 -14
  76. package/dist-server/server/local-vm-run.js +10 -0
  77. package/dist-server/server/model-levels/aliases.js +7 -2
  78. package/dist-server/server/model-levels/index.js +7 -0
  79. package/dist-server/server/request-auth.js +15 -18
  80. package/dist-server/server/routes/message-file.js +1 -1
  81. package/dist-server/server/routines.js +6 -6
  82. package/dist-server/server/store.js +1 -1
  83. package/dist-server/server/stream-tail.js +25 -0
  84. package/dist-server/server/team-rooms/backend.js +9 -4
  85. package/dist-server/server/team-rooms/service.js +1 -1
  86. package/dist-server/server/team-rooms/testing/fake-rooms-backend.js +10 -4
  87. package/dist-server/server/vault/request.js +174 -0
  88. package/dist-server/server/vault/runtime.js +13 -3
  89. package/dist-server/server/vault/store.js +22 -4
  90. package/dist-server/server/vps-computer.js +12 -30
  91. package/dist-server/server/watch-along/budget.js +11 -3
  92. package/dist-server/server/watch-along/live.js +4 -2
  93. package/dist-server/shared/vault.js +7 -0
  94. package/dist-server/vps-container-mcp.js +3 -1
  95. package/package.json +1 -1
  96. package/dist/assets/channel-DhsCc8Nd.js +0 -1
  97. package/dist/assets/swimlanesDiagram-TC7HE7FX-B5p2N9qd.js +0 -8
@@ -42292,6 +42292,32 @@ var init_chat_images = __esm({
42292
42292
  }
42293
42293
  });
42294
42294
 
42295
+ // server/capped-body.ts
42296
+ async function readBodyCapped(res, maxBytes) {
42297
+ const declared = Number(res.headers.get("content-length") ?? NaN);
42298
+ if (Number.isFinite(declared) && declared > maxBytes) {
42299
+ await res.body?.cancel().catch(() => void 0);
42300
+ return null;
42301
+ }
42302
+ if (!res.body) {
42303
+ const bytes = Buffer.from(await res.arrayBuffer());
42304
+ return bytes.length > maxBytes ? null : bytes;
42305
+ }
42306
+ const chunks = [];
42307
+ let received = 0;
42308
+ for await (const chunk of res.body) {
42309
+ received += chunk.byteLength;
42310
+ if (received > maxBytes) return null;
42311
+ chunks.push(chunk);
42312
+ }
42313
+ return Buffer.concat(chunks);
42314
+ }
42315
+ var init_capped_body = __esm({
42316
+ "server/capped-body.ts"() {
42317
+ "use strict";
42318
+ }
42319
+ });
42320
+
42295
42321
  // server/environment.ts
42296
42322
  import { randomUUID as randomUUID10 } from "node:crypto";
42297
42323
  import {
@@ -43077,25 +43103,25 @@ function panelShotCommand({ width = PANEL_FRAME_WIDTH, quality = PANEL_FRAME_QUA
43077
43103
  ].join("; ");
43078
43104
  }
43079
43105
  async function readFileBase64(cfg, boxId, path4, signal) {
43080
- let bytes = null;
43081
- let tooLarge = false;
43106
+ let bytes;
43082
43107
  try {
43083
- const res = await boxFetch(cfg, `/boxes/${boxId}/artifacts?path=${encodeURIComponent(path4)}`, { signal });
43084
- if (res.ok) {
43085
- const declaredLength = res.headers.get("content-length");
43086
- if (declaredLength !== null && Number(declaredLength) > MAX_FRAME_BYTES) tooLarge = true;
43087
- else bytes = Buffer.from(await res.arrayBuffer());
43088
- }
43108
+ const res2 = await boxFetch(cfg, `/boxes/${boxId}/artifacts?path=${encodeURIComponent(path4)}`, { signal });
43109
+ if (res2.ok) bytes = await readBodyCapped(res2, MAX_FRAME_BYTES);
43089
43110
  } catch {
43090
43111
  }
43091
- if (tooLarge || bytes !== null && bytes.length > MAX_FRAME_BYTES) {
43092
- throw new Error(FRAME_TOO_LARGE);
43093
- }
43112
+ if (bytes === null) throw new Error(FRAME_TOO_LARGE);
43094
43113
  if (bytes?.length) return bytes.toString("base64");
43095
43114
  signal?.throwIfAborted();
43096
- const { ok, body } = await boxJson(cfg, `/boxes/${boxId}/files?path=${encodeURIComponent(path4)}&encoding=base64`, { signal });
43115
+ const res = await boxFetch(cfg, `/boxes/${boxId}/files?path=${encodeURIComponent(path4)}&encoding=base64`, { signal });
43116
+ const raw = await readBodyCapped(res, MAX_FRAME_JSON_BYTES).catch(() => void 0);
43117
+ if (raw === null) throw new Error(FRAME_TOO_LARGE);
43118
+ let body = null;
43119
+ try {
43120
+ body = JSON.parse(raw?.toString("utf8") ?? "");
43121
+ } catch {
43122
+ }
43097
43123
  const content = body?.content;
43098
- if (ok && typeof content === "string" && content) {
43124
+ if (res.ok && body?.ok !== false && typeof content === "string" && content) {
43099
43125
  if (Buffer.byteLength(content, "base64") > MAX_FRAME_BYTES) throw new Error(FRAME_TOO_LARGE);
43100
43126
  return content;
43101
43127
  }
@@ -43124,10 +43150,11 @@ async function screenshotBox(cfg, botId, knownBoxId, options) {
43124
43150
  if (!data) throw new Error("could not read the frame back from the box");
43125
43151
  return { png: data, format: "jpeg" };
43126
43152
  }
43127
- var shellQuote3, BOX_API2, READY, DEFAULT_BOX_TTL_SECONDS, TRIAL_BOX_TTL_SECONDS, BOX_INVENTORY_PAGE_SIZE, MAX_BOX_INVENTORY_PAGES, BOX_ID3, scopedBoxPrefixCache, boxIdCache, QUIESCE_BROWSER, PANEL_PATH, PANEL_FRAME_WIDTH, PANEL_FRAME_QUALITY, PANEL_FRAME_FFMPEG_Q, SHOT_CMD, MAX_FRAME_BYTES, FRAME_TOO_LARGE;
43153
+ var shellQuote3, BOX_API2, READY, DEFAULT_BOX_TTL_SECONDS, TRIAL_BOX_TTL_SECONDS, BOX_INVENTORY_PAGE_SIZE, MAX_BOX_INVENTORY_PAGES, BOX_ID3, scopedBoxPrefixCache, boxIdCache, QUIESCE_BROWSER, PANEL_PATH, PANEL_FRAME_WIDTH, PANEL_FRAME_QUALITY, PANEL_FRAME_FFMPEG_Q, SHOT_CMD, MAX_FRAME_BYTES, FRAME_TOO_LARGE, MAX_FRAME_JSON_BYTES;
43128
43154
  var init_box = __esm({
43129
43155
  "server/box.ts"() {
43130
43156
  "use strict";
43157
+ init_capped_body();
43131
43158
  init_config();
43132
43159
  init_environment();
43133
43160
  init_box_create_idempotency();
@@ -43153,6 +43180,7 @@ var init_box = __esm({
43153
43180
  SHOT_CMD = panelShotCommand();
43154
43181
  MAX_FRAME_BYTES = 8 * 1024 * 1024;
43155
43182
  FRAME_TOO_LARGE = "the box frame exceeds the 8 MB limit";
43183
+ MAX_FRAME_JSON_BYTES = Math.ceil(MAX_FRAME_BYTES / 3) * 4 + 4096;
43156
43184
  }
43157
43185
  });
43158
43186
 
@@ -59297,26 +59325,7 @@ async function installAgentBrowserBinary(options = {}) {
59297
59325
  if (!response.ok) throw new Error(`the agent-browser download failed (HTTP ${response.status})`);
59298
59326
  const declared = Number(response.headers.get("content-length") ?? NaN);
59299
59327
  if (Number.isFinite(declared) && declared !== asset.bytes) throw new Error("the agent-browser download did not match its pinned size; nothing was installed");
59300
- const chunks = [];
59301
- let received = 0;
59302
- if (response.body) {
59303
- try {
59304
- for await (const chunk of response.body) {
59305
- chunks.push(chunk);
59306
- received += chunk.byteLength;
59307
- if (received > asset.bytes) {
59308
- controller.abort();
59309
- break;
59310
- }
59311
- }
59312
- } catch (error51) {
59313
- if (received <= asset.bytes) throw error51;
59314
- }
59315
- body = Buffer.concat(chunks);
59316
- } else {
59317
- body = Buffer.from(await response.arrayBuffer());
59318
- if (body.length > asset.bytes) controller.abort();
59319
- }
59328
+ body = await readBodyCapped(response, asset.bytes) ?? Buffer.alloc(0);
59320
59329
  } finally {
59321
59330
  clearTimeout(timer);
59322
59331
  }
@@ -59540,6 +59549,7 @@ var init_browser_engine = __esm({
59540
59549
  init_procs();
59541
59550
  init_bundle_process_sweep();
59542
59551
  init_atomic();
59552
+ init_capped_body();
59543
59553
  init_config();
59544
59554
  init_browser_bundle_release();
59545
59555
  init_browser_runtime();
@@ -61280,6 +61290,16 @@ function resolveLoopbackTrust(input) {
61280
61290
  if (input.hostedWorkspace) return { trust: "service", reason: "hosted workspace" };
61281
61291
  return { trust: "owner", reason: "self-hosted default" };
61282
61292
  }
61293
+ function clientPatchViolation(fields) {
61294
+ return (body) => {
61295
+ if (!body || typeof body !== "object" || Array.isArray(body)) return "body";
61296
+ for (const key of Object.keys(body)) if (!fields.has(key)) return key;
61297
+ return null;
61298
+ };
61299
+ }
61300
+ var clientBotPatchViolation = clientPatchViolation(/* @__PURE__ */ new Set(["unread", "pinned", "pinnedMessageId", "color", "mascotExpression", "mascotBody"]));
61301
+ var clientGroupPatchViolation = clientPatchViolation(/* @__PURE__ */ new Set(["name", "bulletin", "unread", "pinned", "pinnedMessageId", "section"]));
61302
+ var clientTaskPatchViolation = clientPatchViolation(/* @__PURE__ */ new Set(["title", "projectId", "archivedAt", "pinned", "pinnedMessageId"]));
61283
61303
 
61284
61304
  // server/cli.ts
61285
61305
  init_atomic();
@@ -42292,6 +42292,32 @@ var init_chat_images = __esm({
42292
42292
  }
42293
42293
  });
42294
42294
 
42295
+ // server/capped-body.ts
42296
+ async function readBodyCapped(res, maxBytes) {
42297
+ const declared = Number(res.headers.get("content-length") ?? NaN);
42298
+ if (Number.isFinite(declared) && declared > maxBytes) {
42299
+ await res.body?.cancel().catch(() => void 0);
42300
+ return null;
42301
+ }
42302
+ if (!res.body) {
42303
+ const bytes = Buffer.from(await res.arrayBuffer());
42304
+ return bytes.length > maxBytes ? null : bytes;
42305
+ }
42306
+ const chunks = [];
42307
+ let received = 0;
42308
+ for await (const chunk of res.body) {
42309
+ received += chunk.byteLength;
42310
+ if (received > maxBytes) return null;
42311
+ chunks.push(chunk);
42312
+ }
42313
+ return Buffer.concat(chunks);
42314
+ }
42315
+ var init_capped_body = __esm({
42316
+ "server/capped-body.ts"() {
42317
+ "use strict";
42318
+ }
42319
+ });
42320
+
42295
42321
  // server/environment.ts
42296
42322
  import { randomUUID as randomUUID10 } from "node:crypto";
42297
42323
  import {
@@ -43077,25 +43103,25 @@ function panelShotCommand({ width = PANEL_FRAME_WIDTH, quality = PANEL_FRAME_QUA
43077
43103
  ].join("; ");
43078
43104
  }
43079
43105
  async function readFileBase64(cfg, boxId, path4, signal) {
43080
- let bytes = null;
43081
- let tooLarge = false;
43106
+ let bytes;
43082
43107
  try {
43083
- const res = await boxFetch(cfg, `/boxes/${boxId}/artifacts?path=${encodeURIComponent(path4)}`, { signal });
43084
- if (res.ok) {
43085
- const declaredLength = res.headers.get("content-length");
43086
- if (declaredLength !== null && Number(declaredLength) > MAX_FRAME_BYTES) tooLarge = true;
43087
- else bytes = Buffer.from(await res.arrayBuffer());
43088
- }
43108
+ const res2 = await boxFetch(cfg, `/boxes/${boxId}/artifacts?path=${encodeURIComponent(path4)}`, { signal });
43109
+ if (res2.ok) bytes = await readBodyCapped(res2, MAX_FRAME_BYTES);
43089
43110
  } catch {
43090
43111
  }
43091
- if (tooLarge || bytes !== null && bytes.length > MAX_FRAME_BYTES) {
43092
- throw new Error(FRAME_TOO_LARGE);
43093
- }
43112
+ if (bytes === null) throw new Error(FRAME_TOO_LARGE);
43094
43113
  if (bytes?.length) return bytes.toString("base64");
43095
43114
  signal?.throwIfAborted();
43096
- const { ok, body } = await boxJson(cfg, `/boxes/${boxId}/files?path=${encodeURIComponent(path4)}&encoding=base64`, { signal });
43115
+ const res = await boxFetch(cfg, `/boxes/${boxId}/files?path=${encodeURIComponent(path4)}&encoding=base64`, { signal });
43116
+ const raw = await readBodyCapped(res, MAX_FRAME_JSON_BYTES).catch(() => void 0);
43117
+ if (raw === null) throw new Error(FRAME_TOO_LARGE);
43118
+ let body = null;
43119
+ try {
43120
+ body = JSON.parse(raw?.toString("utf8") ?? "");
43121
+ } catch {
43122
+ }
43097
43123
  const content = body?.content;
43098
- if (ok && typeof content === "string" && content) {
43124
+ if (res.ok && body?.ok !== false && typeof content === "string" && content) {
43099
43125
  if (Buffer.byteLength(content, "base64") > MAX_FRAME_BYTES) throw new Error(FRAME_TOO_LARGE);
43100
43126
  return content;
43101
43127
  }
@@ -43124,10 +43150,11 @@ async function screenshotBox(cfg, botId, knownBoxId, options) {
43124
43150
  if (!data) throw new Error("could not read the frame back from the box");
43125
43151
  return { png: data, format: "jpeg" };
43126
43152
  }
43127
- var shellQuote3, BOX_API2, READY, DEFAULT_BOX_TTL_SECONDS, TRIAL_BOX_TTL_SECONDS, BOX_INVENTORY_PAGE_SIZE, MAX_BOX_INVENTORY_PAGES, BOX_ID3, scopedBoxPrefixCache, boxIdCache, QUIESCE_BROWSER, PANEL_PATH, PANEL_FRAME_WIDTH, PANEL_FRAME_QUALITY, PANEL_FRAME_FFMPEG_Q, SHOT_CMD, MAX_FRAME_BYTES, FRAME_TOO_LARGE;
43153
+ var shellQuote3, BOX_API2, READY, DEFAULT_BOX_TTL_SECONDS, TRIAL_BOX_TTL_SECONDS, BOX_INVENTORY_PAGE_SIZE, MAX_BOX_INVENTORY_PAGES, BOX_ID3, scopedBoxPrefixCache, boxIdCache, QUIESCE_BROWSER, PANEL_PATH, PANEL_FRAME_WIDTH, PANEL_FRAME_QUALITY, PANEL_FRAME_FFMPEG_Q, SHOT_CMD, MAX_FRAME_BYTES, FRAME_TOO_LARGE, MAX_FRAME_JSON_BYTES;
43128
43154
  var init_box = __esm({
43129
43155
  "server/box.ts"() {
43130
43156
  "use strict";
43157
+ init_capped_body();
43131
43158
  init_config();
43132
43159
  init_environment();
43133
43160
  init_box_create_idempotency();
@@ -43153,6 +43180,7 @@ var init_box = __esm({
43153
43180
  SHOT_CMD = panelShotCommand();
43154
43181
  MAX_FRAME_BYTES = 8 * 1024 * 1024;
43155
43182
  FRAME_TOO_LARGE = "the box frame exceeds the 8 MB limit";
43183
+ MAX_FRAME_JSON_BYTES = Math.ceil(MAX_FRAME_BYTES / 3) * 4 + 4096;
43156
43184
  }
43157
43185
  });
43158
43186
 
@@ -59297,26 +59325,7 @@ async function installAgentBrowserBinary(options = {}) {
59297
59325
  if (!response.ok) throw new Error(`the agent-browser download failed (HTTP ${response.status})`);
59298
59326
  const declared = Number(response.headers.get("content-length") ?? NaN);
59299
59327
  if (Number.isFinite(declared) && declared !== asset.bytes) throw new Error("the agent-browser download did not match its pinned size; nothing was installed");
59300
- const chunks = [];
59301
- let received = 0;
59302
- if (response.body) {
59303
- try {
59304
- for await (const chunk of response.body) {
59305
- chunks.push(chunk);
59306
- received += chunk.byteLength;
59307
- if (received > asset.bytes) {
59308
- controller.abort();
59309
- break;
59310
- }
59311
- }
59312
- } catch (error51) {
59313
- if (received <= asset.bytes) throw error51;
59314
- }
59315
- body = Buffer.concat(chunks);
59316
- } else {
59317
- body = Buffer.from(await response.arrayBuffer());
59318
- if (body.length > asset.bytes) controller.abort();
59319
- }
59328
+ body = await readBodyCapped(response, asset.bytes) ?? Buffer.alloc(0);
59320
59329
  } finally {
59321
59330
  clearTimeout(timer);
59322
59331
  }
@@ -59540,6 +59549,7 @@ var init_browser_engine = __esm({
59540
59549
  init_procs();
59541
59550
  init_bundle_process_sweep();
59542
59551
  init_atomic();
59552
+ init_capped_body();
59543
59553
  init_config();
59544
59554
  init_browser_bundle_release();
59545
59555
  init_browser_runtime();
@@ -61280,6 +61290,16 @@ function resolveLoopbackTrust(input) {
61280
61290
  if (input.hostedWorkspace) return { trust: "service", reason: "hosted workspace" };
61281
61291
  return { trust: "owner", reason: "self-hosted default" };
61282
61292
  }
61293
+ function clientPatchViolation(fields) {
61294
+ return (body) => {
61295
+ if (!body || typeof body !== "object" || Array.isArray(body)) return "body";
61296
+ for (const key of Object.keys(body)) if (!fields.has(key)) return key;
61297
+ return null;
61298
+ };
61299
+ }
61300
+ var clientBotPatchViolation = clientPatchViolation(/* @__PURE__ */ new Set(["unread", "pinned", "pinnedMessageId", "color", "mascotExpression", "mascotBody"]));
61301
+ var clientGroupPatchViolation = clientPatchViolation(/* @__PURE__ */ new Set(["name", "bulletin", "unread", "pinned", "pinnedMessageId", "section"]));
61302
+ var clientTaskPatchViolation = clientPatchViolation(/* @__PURE__ */ new Set(["title", "projectId", "archivedAt", "pinned", "pinnedMessageId"]));
61283
61303
 
61284
61304
  // server/cli.ts
61285
61305
  init_atomic();
@@ -6,6 +6,7 @@
6
6
  import { readFileSync } from "node:fs";
7
7
  import { join } from "node:path";
8
8
  import { writeFileAtomic } from "./atomic.js";
9
+ import { isPlaceholderText } from "./paw/fill.js";
9
10
  export const ABOUT_ME_SIDES = ["atomic", "paw", "nexus"];
10
11
  const norm = (text) => text.replace(/\r\n?/g, "\n").trim();
11
12
  /** One pass. `now` holds each reachable side's text (a side left out is
@@ -14,19 +15,29 @@ const norm = (text) => text.replace(/\r\n?/g, "\n").trim();
14
15
  * edit reaches every other side. Two different edits, or a side seen for
15
16
  * the first time that disagrees with the rest, are a conflict: nothing is
16
17
  * written. `legacy` (an ICM "Who I am") fills everything when all sides are
17
- * empty, and a profile still holding it counts as empty. */
18
+ * empty, and a profile still holding it counts as empty. A PAW template
19
+ * placeholder ("(fill in)" scaffolding) also counts as empty: it is starter
20
+ * text Atomic wrote itself, never the person's words. A profile the person
21
+ * emptied in Settings since the last pass is a deliberate clear, and it
22
+ * reaches the other sides the way an edit does. Only the profile clears: a
23
+ * PAW file or Nexus read that comes back blank may be a missing folder or a
24
+ * bad response, so it is refilled and never wipes the rest. */
18
25
  export function reconcileAboutMe(now, seen, legacy = "") {
19
26
  const sides = ABOUT_ME_SIDES.filter((side) => now[side] !== undefined);
20
- const text = (side) => (side === "atomic" && norm(legacy) && norm(now.atomic) === norm(legacy) ? "" : norm(now[side]));
27
+ const text = (side) => {
28
+ const value = side === "atomic" && norm(legacy) && norm(now.atomic) === norm(legacy) ? "" : norm(now[side]);
29
+ return isPlaceholderText(value) ? "" : value;
30
+ };
21
31
  const filled = sides.filter((side) => text(side));
32
+ const cleared = sides.filter((side) => side === "atomic" && !norm(now[side]) && norm(seen[side] ?? ""));
22
33
  const edited = filled.filter((side) => text(side) !== norm(seen[side] ?? ""));
23
34
  const kept = filled.filter((side) => !edited.includes(side));
24
35
  const firstContact = edited.some((side) => seen[side] === undefined) && kept.some((side) => text(side) !== text(edited[0]));
25
- if (new Set(edited.map(text)).size > 1 || firstContact)
36
+ if (new Set(edited.map(text)).size > 1 || firstContact || (cleared.length > 0 && edited.length > 0))
26
37
  return { writes: {}, seen, conflict: filled };
27
38
  const source = edited[0] ?? kept[0];
28
- const target = source ? now[source] : legacy;
29
- if (!norm(target))
39
+ const target = cleared.length ? "" : source ? now[source] : legacy;
40
+ if (!norm(target) && !cleared.length)
30
41
  return { writes: {}, seen, conflict: [] };
31
42
  const writes = {};
32
43
  for (const side of sides)
@@ -11,6 +11,7 @@
11
11
  // - X11 desktop with Chrome + Ghostty; passwordless sudo; node 24.
12
12
  // - the dedicated IP rotates across archive/resume — never persist it.
13
13
  import { createHash } from "node:crypto";
14
+ import { readBodyCapped } from "./capped-body.js";
14
15
  import { DATA_DIR } from "./config.js";
15
16
  import { loadEnvironmentId } from "./environment.js";
16
17
  import { adoptResolvedBox, beginBoxCreate, boxCreateRecoverySnapshot, discardBoxCreate, rememberCreatedBox, resolveBoxCreate, retireDeletedBoxCreate, } from "./box-create-idempotency.js";
@@ -1235,33 +1236,36 @@ const SHOT_CMD = panelShotCommand();
1235
1236
  // response cannot exhaust memory.
1236
1237
  const MAX_FRAME_BYTES = 8 * 1024 * 1024;
1237
1238
  const FRAME_TOO_LARGE = "the box frame exceeds the 8 MB limit";
1239
+ // The files fallback wraps the frame in base64 (4/3) plus a small envelope.
1240
+ const MAX_FRAME_JSON_BYTES = Math.ceil(MAX_FRAME_BYTES / 3) * 4 + 4096;
1238
1241
  /** Read a file off the box as base64 — raw artifact bytes when the API
1239
1242
  * supports it (33% less transfer, no JSON envelope), else the files API. */
1240
1243
  async function readFileBase64(cfg, boxId, path, signal) {
1241
- let bytes = null;
1242
- let tooLarge = false;
1244
+ let bytes;
1243
1245
  try {
1244
1246
  const res = await boxFetch(cfg, `/boxes/${boxId}/artifacts?path=${encodeURIComponent(path)}`, { signal });
1245
- if (res.ok) {
1246
- const declaredLength = res.headers.get("content-length");
1247
- if (declaredLength !== null && Number(declaredLength) > MAX_FRAME_BYTES)
1248
- tooLarge = true;
1249
- else
1250
- bytes = Buffer.from(await res.arrayBuffer());
1251
- }
1247
+ if (res.ok)
1248
+ bytes = await readBodyCapped(res, MAX_FRAME_BYTES);
1252
1249
  }
1253
1250
  catch {
1254
- /* fall through */
1251
+ /* fall through to the files API */
1255
1252
  }
1256
- if (tooLarge || (bytes !== null && bytes.length > MAX_FRAME_BYTES)) {
1253
+ if (bytes === null)
1257
1254
  throw new Error(FRAME_TOO_LARGE);
1258
- }
1259
1255
  if (bytes?.length)
1260
1256
  return bytes.toString("base64");
1261
1257
  signal?.throwIfAborted();
1262
- const { ok, body } = await boxJson(cfg, `/boxes/${boxId}/files?path=${encodeURIComponent(path)}&encoding=base64`, { signal });
1258
+ const res = await boxFetch(cfg, `/boxes/${boxId}/files?path=${encodeURIComponent(path)}&encoding=base64`, { signal });
1259
+ const raw = await readBodyCapped(res, MAX_FRAME_JSON_BYTES).catch(() => undefined);
1260
+ if (raw === null)
1261
+ throw new Error(FRAME_TOO_LARGE);
1262
+ let body = null;
1263
+ try {
1264
+ body = JSON.parse(raw?.toString("utf8") ?? "");
1265
+ }
1266
+ catch { /* unusable envelope */ }
1263
1267
  const content = body?.content;
1264
- if (ok && typeof content === "string" && content) {
1268
+ if (res.ok && body?.ok !== false && typeof content === "string" && content) {
1265
1269
  if (Buffer.byteLength(content, "base64") > MAX_FRAME_BYTES)
1266
1270
  throw new Error(FRAME_TOO_LARGE);
1267
1271
  return content;
@@ -15,6 +15,7 @@ import { homedir, tmpdir } from "node:os";
15
15
  import { delimiter, dirname, join, resolve } from "node:path";
16
16
  import { sweepRoot } from "../electron/bundle-process-sweep.mjs";
17
17
  import { writeFileAtomic } from "./atomic.js";
18
+ import { readBodyCapped } from "./capped-body.js";
18
19
  import { DATA_DIR } from "./config.js";
19
20
  import { browserBundlePaths } from "./browser-bundle-release.js";
20
21
  import { browserRuntimeEnv } from "./browser-runtime.js";
@@ -298,32 +299,9 @@ export async function installAgentBrowserBinary(options = {}) {
298
299
  const declared = Number(response.headers.get("content-length") ?? NaN);
299
300
  if (Number.isFinite(declared) && declared !== asset.bytes)
300
301
  throw new Error("the agent-browser download did not match its pinned size; nothing was installed");
301
- // Stream, never buffer whole: a body past the pin is cut off mid-flight.
302
- const chunks = [];
303
- let received = 0;
304
- if (response.body) {
305
- try {
306
- for await (const chunk of response.body) {
307
- chunks.push(chunk);
308
- received += chunk.byteLength;
309
- if (received > asset.bytes) {
310
- controller.abort();
311
- break;
312
- }
313
- }
314
- }
315
- catch (error) {
316
- // Only the abort we asked for is swallowed; the size check reports it.
317
- if (received <= asset.bytes)
318
- throw error;
319
- }
320
- body = Buffer.concat(chunks);
321
- }
322
- else {
323
- body = Buffer.from(await response.arrayBuffer());
324
- if (body.length > asset.bytes)
325
- controller.abort();
326
- }
302
+ // Stream, never buffer whole: a body past the pin is cut off mid-flight,
303
+ // and the empty buffer it leaves behind fails the exact-size check below.
304
+ body = (await readBodyCapped(response, asset.bytes)) ?? Buffer.alloc(0);
327
305
  }
328
306
  finally {
329
307
  clearTimeout(timer);
@@ -191,11 +191,12 @@ export class CalendarCallManager {
191
191
  durationMinutes: patch.durationMinutes ?? previous.durationMinutes,
192
192
  attachments: patch.attachments ?? previous.attachments,
193
193
  }, this.botExists);
194
+ const scheduleChanged = JSON.stringify(clean.schedule) !== JSON.stringify(previous.schedule);
194
195
  const updated = {
195
196
  id: previous.id,
196
197
  ...clean,
197
198
  roomId: patch.botIds && !sameRoster(clean.botIds, previous.botIds) ? undefined : previous.roomId,
198
- nextRunAt: this.initialOccurrence(clean.schedule, this.now()),
199
+ nextRunAt: scheduleChanged ? this.initialOccurrence(clean.schedule, this.now()) : previous.nextRunAt,
199
200
  createdAt: previous.createdAt,
200
201
  updatedAt: this.now(),
201
202
  };
@@ -0,0 +1,26 @@
1
+ /** Read a fetch Response body into a Buffer while never holding more than
2
+ * `maxBytes` of it: a longer body is cut off mid-flight and reported as null,
3
+ * so one hostile or broken response cannot exhaust server memory. A declared
4
+ * content-length over the cap skips the read entirely. */
5
+ export async function readBodyCapped(res, maxBytes) {
6
+ const declared = Number(res.headers.get("content-length") ?? NaN);
7
+ if (Number.isFinite(declared) && declared > maxBytes) {
8
+ await res.body?.cancel().catch(() => undefined);
9
+ return null;
10
+ }
11
+ if (!res.body) {
12
+ const bytes = Buffer.from(await res.arrayBuffer());
13
+ return bytes.length > maxBytes ? null : bytes;
14
+ }
15
+ const chunks = [];
16
+ let received = 0;
17
+ // returning out of for await cancels the stream, so nothing past the cap
18
+ // is pulled off the socket, let alone buffered
19
+ for await (const chunk of res.body) {
20
+ received += chunk.byteLength;
21
+ if (received > maxBytes)
22
+ return null;
23
+ chunks.push(chunk);
24
+ }
25
+ return Buffer.concat(chunks);
26
+ }
@@ -17,6 +17,7 @@ import { spawnOptionsFor } from "./spawn-command.js";
17
17
  import { DATA_DIR } from "./config.js";
18
18
  import { SPAWNED_PROXIES } from "./proxy-paths.js";
19
19
  import { localVmStartableWhenStopped } from "./local-vm-start.js";
20
+ import { viewerSecretToEnv } from "./local-vm-run.js";
20
21
  export { localVmStartableWhenStopped };
21
22
  const run = promisify(execFile);
22
23
  const SCREENSHOT_STATUS_TTL_MS = 10_000;
@@ -184,7 +185,7 @@ LABEL ${MANAGED_LABEL}="1" \\
184
185
  ${IMAGE_LAYER_LABEL}="${IMAGE_LAYER_VERSION}"
185
186
  `;
186
187
  }
187
- async function sh(cmd, args, timeout = 8000) {
188
+ async function sh(cmd, args, timeout = 8000, secrets) {
188
189
  const resolved = resolveCliSpawn(cmd, args);
189
190
  const { stdout } = await run(resolved.command, resolved.args, spawnOptionsFor(resolved, {
190
191
  timeout,
@@ -193,8 +194,8 @@ async function sh(cmd, args, timeout = 8000) {
193
194
  // Every docker call on a Mac goes to Colima's socket, whatever docker
194
195
  // context Docker Desktop may have left active.
195
196
  env: cmd === "docker"
196
- ? dockerEnvForColima({ ...process.env, PATH: augmentedPath() })
197
- : { ...process.env, PATH: augmentedPath() },
197
+ ? dockerEnvForColima({ ...process.env, ...secrets, PATH: augmentedPath() })
198
+ : { ...process.env, ...secrets, PATH: augmentedPath() },
198
199
  }));
199
200
  return { stdout };
200
201
  }
@@ -805,12 +806,11 @@ export async function containerComputerAction(action, runner = sh, platform = pr
805
806
  await ensureVmWorkspace(platform, target);
806
807
  if (action === "remove")
807
808
  await rescueFirefoxProfile(runtime, runner, platform, target);
808
- const args = action === "run"
809
- ? containerRunArgs(runtime, randomBytes(6).toString("base64url"), target)
810
- : action === "remove"
811
- ? ["rm", runtime === "container" ? "--force" : "-f", target.containerName]
812
- : [action, target.containerName];
813
- await runner(runtime, args, 2 * 60_000);
809
+ const runArgs = () => containerRunArgs(runtime, randomBytes(6).toString("base64url"), target);
810
+ const launch = action === "run" ? viewerSecretToEnv(runtime, runArgs()) : null;
811
+ const removal = ["rm", runtime === "container" ? "--force" : "-f", target.containerName];
812
+ const args = launch?.args ?? (action === "remove" ? removal : [action, target.containerName]);
813
+ await runner(runtime, args, 2 * 60_000, launch?.env);
814
814
  }
815
815
  return containerComputerStatus(runner, platform, target);
816
816
  }
@@ -6,7 +6,7 @@
6
6
  //
7
7
  // Nothing here reads the environment or holds state of its own. The caller
8
8
  // passes a ToolCallContext, and the per-turn counters live on it.
9
- import { requestCredential } from "./agents-credential.js";
9
+ import { callCredentialTool } from "./agents-credential.js";
10
10
  import { normalizeCronSchedule } from "../../shared/routine-schedule.js";
11
11
  import { peerRecallSpeaker } from "../peer-provenance.js";
12
12
  import { peerName } from "../peer-roster.js";
@@ -835,8 +835,8 @@ export async function callTool(name, args, context) {
835
835
  const message = typeof r.message === "string" ? r.message : `Updated room ${roomId}.`;
836
836
  return { text: message };
837
837
  }
838
- if (name === "request_credential")
839
- return requestCredential(args, BOT_ID, THREAD_ID, api);
838
+ if (name === "request_credential" || name.startsWith("vault_"))
839
+ return callCredentialTool(name, args, BOT_ID, THREAD_ID, api);
840
840
  if (name === "list_routines") {
841
841
  const query = new URLSearchParams({ fromBotId: BOT_ID, fromThreadId: THREAD_ID });
842
842
  const r = await api(`/api/internal/routines?${query.toString()}`);
@@ -10,7 +10,7 @@
10
10
  // turn. It is pinned byte for byte, and its size budgeted, by
11
11
  // agents-catalog-wire.test.ts: change a description or a schema on purpose,
12
12
  // then update the goldens there.
13
- import { credentialTool } from "./agents-credential.js";
13
+ import { credentialTool, vaultTools } from "./agents-credential.js";
14
14
  import { PRIVATE_BOT_HIDDEN_TOOLS, agentToolAnnotations } from "../agent-tool-policy.js";
15
15
  /** The profile a spawned proxy was given. Everything is off unless the
16
16
  * harness says "1". */
@@ -450,7 +450,7 @@ const toolDefinitions = (externalRuntime) => [
450
450
  required: ["room_id", "action"],
451
451
  },
452
452
  },
453
- credentialTool,
453
+ credentialTool, ...vaultTools,
454
454
  {
455
455
  name: "marketplace_search",
456
456
  description: "Find an app or service the person wants connected in Atomic's Marketplace: official servers Atomic connects, and official apps through their Claude account. Then call open_marketplace. Never offer to build a connection or a community server.",
@@ -1,4 +1,10 @@
1
1
  import { CREDENTIAL_TARGETS, isCredentialTargetId } from "../../shared/credential-request.js";
2
+ import { callVaultTool, vaultTools } from "./agents-vault.js";
3
+ export { vaultTools };
4
+ /** request_credential and the Vault tools: every way a bot reaches a secret it never sees. */
5
+ export function callCredentialTool(name, args, BOT_ID, THREAD_ID, api) {
6
+ return name === "request_credential" ? requestCredential(args, BOT_ID, THREAD_ID, api) : callVaultTool(args, api);
7
+ }
2
8
  export async function requestCredential(args, BOT_ID, THREAD_ID, api) {
3
9
  const credentialId = args.credential_id;
4
10
  if (!isCredentialTargetId(credentialId)) {
@@ -0,0 +1,35 @@
1
+ export async function callVaultTool(args, api) {
2
+ try {
3
+ if (args.item_id === undefined && args.url === undefined) {
4
+ const r = await api("/api/internal/vault/keys");
5
+ const items = Array.isArray(r.items) ? r.items : [];
6
+ if (!items.length) {
7
+ return { text: "No Vault API keys are shared with you. The person can add one in Settings > Vault > New API key and tick your name under Allowed bots." };
8
+ }
9
+ return { text: JSON.stringify(items, null, 2) };
10
+ }
11
+ const r = await api("/api/internal/vault/request", { method: "POST", body: JSON.stringify(args) });
12
+ return { text: JSON.stringify(r, null, 2) };
13
+ }
14
+ catch (error) {
15
+ return { text: error instanceof Error ? error.message : "Vault could not complete the request.", isError: true };
16
+ }
17
+ }
18
+ export const vaultTools = [
19
+ {
20
+ name: "vault_request",
21
+ description: "Use an API key from the person's Atomic Vault without seeing it. No arguments: list the keys shared with you (id, name, allowed HTTPS addresses, header). With item_id and url: Atomic sends that request and adds the key header itself, so never set it. Text comes back; other files are saved and their path returned. Check here before asking for an API key.",
22
+ inputSchema: {
23
+ type: "object",
24
+ properties: {
25
+ item_id: { type: "string" },
26
+ url: { type: "string", description: "https:// endpoint at one of the item's addresses." },
27
+ method: { type: "string", enum: ["GET", "POST", "PUT", "PATCH", "DELETE"] },
28
+ headers: { type: "object", additionalProperties: { type: "string" } },
29
+ body: { type: "string" },
30
+ save_as: { type: "string", description: "File name for a response to keep." },
31
+ },
32
+ additionalProperties: false,
33
+ },
34
+ },
35
+ ];
@@ -64,10 +64,13 @@ export const NO_ANSWER_FAILURE = "The engine ended the turn without an answer.";
64
64
  function unrecognisedFailure(turn) {
65
65
  return { kind: "provider_error", message: turn.lastError ?? NO_ANSWER_FAILURE };
66
66
  }
67
- /** Stops that must not dispatch the request again: cancellation or a broken
68
- * checkpoint whose accepted prompt may already have executed actions.
67
+ /** Stops that must not dispatch the request again: cancellation, a broken
68
+ * checkpoint whose accepted prompt may already have executed actions, and a
69
+ * turn ended over failed or denied tool runs (tool_error). Tools are the
70
+ * harness's, not the engine's, so another engine faces the same failure or
71
+ * the same human denial; it must not settle a turn the person refused.
69
72
  * The next explicit turn rebuilds that checkpoint from retained history. */
70
- const NOT_A_PROVIDER_FAILURE = new Set(["interrupted", "cancelled", "invalid_checkpoint"]);
73
+ const NOT_A_PROVIDER_FAILURE = new Set(["interrupted", "cancelled", "invalid_checkpoint", "tool_error"]);
71
74
  export class FailoverGate {
72
75
  turns = new Map();
73
76
  onFailure;
@@ -318,10 +318,10 @@ export function resolveLadder(ladder, stored, context) {
318
318
  key.sort((a, b) => a.step - b.step || storedFirst(a.candidate, b.candidate) || a.index - b.index);
319
319
  free.sort((a, b) => a.step - b.step || storedFirst(a.candidate, b.candidate) || a.index - b.index);
320
320
  for (const { step, entry, candidate, band } of [...subscription, ...key, ...free]) {
321
- const reason = band === "key" && context.keyBandPaused ? "paused"
322
- : band === "free" && !context.includeFree ? "free-off"
323
- : band === "free" && context.clientData ? "client-data"
324
- : skipReason(entry, candidate, context, step < ladder.length);
321
+ // "paused" names a key kept off this turn by policy alone: a key that could not take it anyway (signed out, resting, refused) keeps its real reason.
322
+ const reason = band === "free" && !context.includeFree ? "free-off"
323
+ : band === "free" && context.clientData ? "client-data"
324
+ : skipReason(entry, candidate, context, step < ladder.length) ?? (band === "key" && context.keyBandPaused ? "paused" : undefined);
325
325
  if (reason) {
326
326
  skipped.push({ step, instanceId: candidate.instanceId, reason, band });
327
327
  continue;