@desplega.ai/agent-swarm 2.13.3 → 2.13.5

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 (424) hide show
  1. package/dist/acp-adapter-tbt61zkm.js +17 -0
  2. package/dist/{acp-targets-k8xs4tj8.js → acp-targets-w8dbs4nr.js} +10 -10
  3. package/dist/{actions-pg5fxjer.js → actions-8zrcbjrx.js} +237 -27
  4. package/dist/{agent-fs-provision-vbk3fppw.js → agent-fs-provision-cbt2ttds.js} +4 -4
  5. package/dist/{amp-adapter-adbhxsz9.js → amp-adapter-8x6zp8w4.js} +3 -3
  6. package/dist/{anthropic-messages-88b7s3n9.js → anthropic-messages-vdd1zmha.js} +10 -10
  7. package/dist/{app-b267ggx1.js → app-zfa9dwjw.js} +7 -7
  8. package/dist/{approval-notifications-evc1a9z5.js → approval-notifications-rv92zmza.js} +8 -8
  9. package/dist/{assistant-wgz2ab84.js → assistant-q7s7rm1q.js} +25 -25
  10. package/dist/{boot-args-schema-6tpk28j4.js → boot-args-schema-g27kpzr1.js} +1 -1
  11. package/dist/{boot-reembed-r1zyvefv.js → boot-reembed-1mjs52nt.js} +1 -1
  12. package/dist/{boot-reembed-ankp369c.js → boot-reembed-m62dpdkg.js} +1 -1
  13. package/dist/{boot-scrub-sweep-cgb6r5bd.js → boot-scrub-sweep-ss1vcamw.js} +2 -2
  14. package/dist/{boot-seeds-bjceqg7b.js → boot-seeds-hwnvgbb3.js} +4 -4
  15. package/dist/{boxd-hr8rsxzq.js → boxd-y0szhp0g.js} +2 -2
  16. package/dist/{claude-adapter-knztdnff.js → claude-adapter-0rjmbhjk.js} +9 -9
  17. package/dist/{claude-managed-adapter-qwejzqkk.js → claude-managed-adapter-6k032agg.js} +4 -4
  18. package/dist/{claude-managed-setup-0vgz4d1j.js → claude-managed-setup-6czvve8q.js} +5 -5
  19. package/dist/{claude-sdk-session-c3g6dv0g.js → claude-sdk-session-pr0znb81.js} +12671 -11885
  20. package/dist/{cli-2v4xxnx2.js → cli-0h8skzss.js} +1 -1
  21. package/dist/{cli-7fa6yv98.js → cli-0qt3epg4.js} +7 -7
  22. package/dist/{cli-aytna2fm.js → cli-19d6v8er.js} +7 -7
  23. package/dist/{cli-8m6gqnf1.js → cli-1jq2em7b.js} +4 -4
  24. package/dist/{cli-fp65jdp2.js → cli-1kvcsd2f.js} +219 -155
  25. package/dist/{cli-8fj8yfmk.js → cli-2vp0z049.js} +1 -1
  26. package/dist/{cli-61p7ty8d.js → cli-2wzkvfgm.js} +3 -3
  27. package/dist/{cli-tjf1bh1v.js → cli-34fygf87.js} +6 -4
  28. package/dist/{cli-czeh7x13.js → cli-3860pmrq.js} +4 -4
  29. package/dist/{cli-dq30fq3q.js → cli-3vw6dd4g.js} +2 -2
  30. package/dist/{cli-4dyhzhpx.js → cli-4gaf3tx5.js} +1 -1
  31. package/dist/{cli-3mf04tkh.js → cli-4vynxtrb.js} +1 -1
  32. package/dist/{cli-hpxcfvdm.js → cli-55h8m1x3.js} +10 -7
  33. package/dist/{cli-hxj888w3.js → cli-5n9w2xzx.js} +2 -2
  34. package/dist/{cli-50whymxq.js → cli-5tq15aa7.js} +2 -2
  35. package/dist/{cli-8sayvj48.js → cli-5web09sb.js} +3 -3
  36. package/dist/{cli-gc715jrc.js → cli-69zzpjgh.js} +1 -1
  37. package/dist/{cli-vgh5adn9.js → cli-6msnpj1z.js} +8 -8
  38. package/dist/{cli-f8rcvf2x.js → cli-7r9tvk8v.js} +76 -3
  39. package/dist/{cli-fbmgpt72.js → cli-7ypg8hka.js} +3 -3
  40. package/dist/{cli-xc8m5cjn.js → cli-887vhew6.js} +3 -3
  41. package/dist/{cli-q8aq48v1.js → cli-8b4rpnwj.js} +1 -1
  42. package/dist/{cli-pzsedyb0.js → cli-8pd1t17c.js} +14 -14
  43. package/dist/{cli-je587f74.js → cli-94gx6ze9.js} +1 -1
  44. package/dist/{cli-h9d3sdnc.js → cli-94mxerrp.js} +1 -1
  45. package/dist/{cli-ef590376.js → cli-9n6g14vs.js} +3 -3
  46. package/dist/{cli-80d5g0fa.js → cli-abby987g.js} +3 -3
  47. package/dist/{cli-grk77aen.js → cli-avax5mp9.js} +2 -2
  48. package/dist/{cli-hd2a204w.js → cli-b42yfn17.js} +14 -14
  49. package/dist/{cli-gkjw33x5.js → cli-b9ygp1kz.js} +2 -2
  50. package/dist/{cli-bh53ppqm.js → cli-bvamr9g0.js} +4 -4
  51. package/dist/{cli-ka4tqjzd.js → cli-ced4azn1.js} +15 -12
  52. package/dist/{cli-v1v49t36.js → cli-cmbb2t8a.js} +3 -3
  53. package/dist/{cli-hhb8kbwd.js → cli-cp163xga.js} +31 -16
  54. package/dist/{cli-55fqpd9q.js → cli-ebpq3c5z.js} +8 -8
  55. package/dist/{cli-9gmkw6xn.js → cli-ehg90jd1.js} +128 -48
  56. package/dist/{cli-jg5txpm6.js → cli-emdfd8fh.js} +75 -1
  57. package/dist/{cli-gxqwm3k3.js → cli-evy3egte.js} +104 -10
  58. package/dist/{cli-a21cwm89.js → cli-ewk3sg68.js} +3 -3
  59. package/dist/{cli-syqcny89.js → cli-f7b9nyvk.js} +9 -9
  60. package/dist/{cli-268b3dgn.js → cli-f9xw9pr4.js} +5 -5
  61. package/dist/{cli-61fzwtjk.js → cli-ffn0a515.js} +9 -9
  62. package/dist/{cli-ya1cj689.js → cli-fw67mnyc.js} +1 -1
  63. package/dist/{cli-dqgnbnxs.js → cli-grbngev5.js} +6 -1
  64. package/dist/{cli-sy2ge2ye.js → cli-hd5bm1e1.js} +4 -4
  65. package/dist/{cli-rfejbpe1.js → cli-htb5bpz2.js} +1 -1
  66. package/dist/{cli-w24741sm.js → cli-j69pzrrz.js} +7 -7
  67. package/dist/{cli-g4dhd3pr.js → cli-jdq3jmny.js} +6 -23
  68. package/dist/{cli-hv3820ez.js → cli-k0nebh10.js} +1 -1
  69. package/dist/{cli-d2epqm0y.js → cli-kezzteka.js} +1 -1
  70. package/dist/{cli-h0ewec3d.js → cli-kr0jpw9c.js} +1 -1
  71. package/dist/{cli-t25rq8mg.js → cli-ks06cd0n.js} +40 -11
  72. package/dist/{cli-1gnf5c7x.js → cli-kwj3131p.js} +1 -1
  73. package/dist/{cli-wtffytm8.js → cli-m8f4379k.js} +3 -3
  74. package/dist/{cli-43dsqhcp.js → cli-n79j1vxc.js} +4 -4
  75. package/dist/{cli-b768ek79.js → cli-nrt048ys.js} +1 -0
  76. package/dist/{cli-h3drhntp.js → cli-pedm2kht.js} +2 -2
  77. package/dist/{cli-eds5xnsz.js → cli-phmy14hb.js} +2 -2
  78. package/dist/{cli-7kv5d674.js → cli-prz1p3ft.js} +5 -5
  79. package/dist/{cli-nbawx3s0.js → cli-q1h041y8.js} +6 -6
  80. package/dist/{cli-cah298e5.js → cli-q41qar56.js} +104 -119
  81. package/dist/{cli-kwm1bek7.js → cli-qmx8bnt4.js} +2 -2
  82. package/dist/{cli-1wew39p0.js → cli-qrvk9nka.js} +28 -19
  83. package/dist/{cli-v8rpjrnx.js → cli-r3dxpmyt.js} +1 -1
  84. package/dist/{cli-0j4qmc80.js → cli-ryem5cfq.js} +8 -8
  85. package/dist/{cli-8pnawt98.js → cli-s8dhq7rj.js} +5 -5
  86. package/dist/{cli-zkbz8m2q.js → cli-sejvnjvw.js} +3 -2
  87. package/dist/{cli-at67kvnp.js → cli-srktrbby.js} +1 -1
  88. package/dist/{cli-wsnradtk.js → cli-srre41gb.js} +2 -2
  89. package/dist/{cli-r6xnchva.js → cli-t0n9svkb.js} +7 -7
  90. package/dist/{cli-y0q92v4r.js → cli-t879ww0y.js} +2 -2
  91. package/dist/{cli-eetzmsy5.js → cli-t9pzz2eq.js} +2 -2
  92. package/dist/{cli-xwsm6xkr.js → cli-tgc1kgg3.js} +1 -1
  93. package/dist/{cli-dw43pnzp.js → cli-tt7dkwjj.js} +7 -7
  94. package/dist/{cli-y754psdt.js → cli-tvyt8w6n.js} +5 -5
  95. package/dist/cli-v09eza21.js +1907 -0
  96. package/dist/{cli-mgr3gatr.js → cli-vbge4rsp.js} +4 -4
  97. package/dist/{cli-ppf9ap9n.js → cli-vcpyttcw.js} +1 -1
  98. package/dist/{cli-1606qw3n.js → cli-wzecestt.js} +1100 -432
  99. package/dist/{cli-5basv0e7.js → cli-x2adbg4j.js} +71 -9
  100. package/dist/{cli-vx9acp12.js → cli-ybte1fqc.js} +1 -1
  101. package/dist/{cli-vdfngx2g.js → cli-ywy8yz6t.js} +2 -2
  102. package/dist/{cli-cpkxh68d.js → cli-z1vam71h.js} +2 -2
  103. package/dist/{cli-djwt4mtn.js → cli-z3x7h79n.js} +15 -9
  104. package/dist/cli-z40t85ms.js +27 -0
  105. package/dist/{cli-ea367bdn.js → cli-zbbtp02a.js} +104 -27
  106. package/dist/{cli-88np9va3.js → cli-zntvmqmm.js} +2 -2
  107. package/dist/{cli-snwz16eg.js → cli-zxa1vmx7.js} +2 -2
  108. package/dist/{cli-50wa8k4h.js → cli-zy9bb22b.js} +1 -2
  109. package/dist/{cli-e4gx499y.js → cli-zzq96q57.js} +273 -106
  110. package/dist/cli.js +21 -21
  111. package/dist/{codex-adapter-493vb8cv.js → codex-adapter-bn7eaxk5.js} +8 -8
  112. package/dist/{codex-hook-ej8hn6z5.js → codex-hook-nnmezjg9.js} +3 -3
  113. package/dist/{codex-login-ven5cz5j.js → codex-login-ktfg1cxk.js} +1 -1
  114. package/dist/{codex-session-runner-ps5m4z1g.js → codex-session-runner-j1e9hffc.js} +9 -9
  115. package/dist/{commands-shktk0b8.js → commands-amhpafrr.js} +3 -3
  116. package/dist/{controller-wn3vd217.js → controller-tw7g10j2.js} +4 -4
  117. package/dist/{controllers-connect-yft057ws.js → controllers-connect-2ssqz7f4.js} +25 -25
  118. package/dist/core-bwp98v4w.js +42 -0
  119. package/dist/{cursor-adapter-8fpm4dng.js → cursor-adapter-d6knjmwa.js} +2 -2
  120. package/dist/{db-0ezhdhz5.js → db-fd6xxm77.js} +3 -3
  121. package/dist/{db-84pz2w5c.js → db-sc59379z.js} +2 -2
  122. package/dist/{devin-adapter-fs90ab4v.js → devin-adapter-3bp6rape.js} +1 -1
  123. package/dist/{dispatcher-h2rz69f6.js → dispatcher-a2gdqz8c.js} +22 -22
  124. package/dist/{docker-1h33jvh9.js → docker-a59g3ebm.js} +2 -2
  125. package/dist/{dsh-adapter-g9yqv09y.js → dsh-adapter-43ygwqn7.js} +2 -2
  126. package/dist/{e2b-jnk0yeva.js → e2b-cn7cvjqy.js} +3 -3
  127. package/dist/{e2b-y7e5kmzf.js → e2b-qnxyfea6.js} +3 -3
  128. package/dist/{easter-egg-3d-m41ad78v.js → easter-egg-3d-a0pphy71.js} +1 -1
  129. package/dist/{embedding-space-yam9zwzj.js → embedding-space-qepzrach.js} +6 -6
  130. package/dist/{embeddings-g2be0y8q.js → embeddings-d7vr881x.js} +1 -1
  131. package/dist/{event-bus-08t2b4y2.js → event-bus-7gbsr0g4.js} +1 -1
  132. package/dist/{execute-hhdejgzf.js → execute-6afts2bn.js} +1 -1
  133. package/dist/{external-channel-kjt2yzfj.js → external-channel-881zq1x4.js} +2 -2
  134. package/dist/fx-adapter-cr2hq17y.js +20 -0
  135. package/dist/grok-adapter-ayddnbsc.js +20 -0
  136. package/dist/handlers-7ghs84x2.js +41 -0
  137. package/dist/{heartbeat-2e5jdexj.js → heartbeat-4c022m6a.js} +25 -25
  138. package/dist/{hook-acg9saz7.js → hook-4k84x499.js} +6 -6
  139. package/dist/{hook-34s8cmgn.js → hook-a7eh6zty.js} +9 -9
  140. package/dist/{http-ra2zr2f8.js → http-6aw5wanc.js} +456 -1864
  141. package/dist/{index-mbpxhc4w.js → index-126v2d0t.js} +1 -4
  142. package/dist/index-dtt0d634.js +44 -0
  143. package/dist/index-hmszyqkk.js +42 -0
  144. package/dist/index-j6rm1rtn.js +39 -0
  145. package/dist/{index-9q42cr54.js → index-rwwhsmjg.js} +1 -1
  146. package/dist/{index-93bw5wds.js → index-xhad0n8m.js} +1 -1
  147. package/dist/{index-2z1z7qx6.js → index-yq9hhhhy.js} +26 -26
  148. package/dist/{index-9r4j0a60.js → index-z2g9469g.js} +410 -27
  149. package/dist/{k8s-8326q0rq.js → k8s-36gfn847.js} +2 -2
  150. package/dist/{keepalive-vjnnqbkm.js → keepalive-zhbmztqw.js} +5 -5
  151. package/dist/lead-g2j4q39z.js +83 -0
  152. package/dist/{maintenance-px2g599e.js → maintenance-rsp0591h.js} +1 -1
  153. package/dist/{node-2wfcey7d.js → node-0as4n1ef.js} +3 -3
  154. package/dist/{node-zd6shky9.js → node-dhxbt01p.js} +3 -3
  155. package/dist/{node-z67yjre7.js → node-rxte5hc6.js} +290 -70
  156. package/dist/{node-hjn5n1yp.js → node-t0ct2zpw.js} +3 -5
  157. package/dist/{oauth-refresh-sweep-nkykf09m.js → oauth-refresh-sweep-w3cqmxq7.js} +4 -4
  158. package/dist/{object-webhooks-gt9xnq21.js → object-webhooks-331hay92.js} +7 -7
  159. package/dist/{onboard-1f134p65.js → onboard-n2w80m2n.js} +7 -7
  160. package/dist/{opencode-adapter-94976yab.js → opencode-adapter-z98127cz.js} +8 -8
  161. package/dist/{otel-impl-5d4p2fqs.js → otel-impl-xsk35tvf.js} +2 -2
  162. package/dist/{pending-vkk0vx6n.js → pending-2e6trkxd.js} +23 -23
  163. package/dist/{pi-mono-adapter-cyzdv5er.js → pi-mono-adapter-wh6yndtm.js} +13 -13
  164. package/dist/{pricing-refresh-jtmjwss9.js → pricing-refresh-9355dj1t.js} +2 -2
  165. package/dist/{rbac-roles-yd1fgpsn.js → rbac-roles-58y3m912.js} +3 -3
  166. package/dist/{rbac-roles-1fvmdyeb.js → rbac-roles-8eajw4s6.js} +6 -4
  167. package/dist/{render-v2-kb5s3vx4.js → render-v2-7gskkmd4.js} +7 -7
  168. package/dist/{resume-z1vs44n5.js → resume-0drnmpja.js} +10 -10
  169. package/dist/{runtime-gk6ct7r7.js → runtime-d2tcmqte.js} +1 -1
  170. package/dist/{session-access-nz6nre4d.js → session-access-0ztys6bd.js} +5 -5
  171. package/dist/{session-source-backfill-wb60zjkd.js → session-source-backfill-cdm5s046.js} +3 -3
  172. package/dist/{setup-2x8g8j4s.js → setup-pqwb9tcc.js} +1 -1
  173. package/dist/thread-buffer-epx3san4.js +42 -0
  174. package/dist/{tree-visibility-ts3z30kw.js → tree-visibility-rwz67mje.js} +2 -2
  175. package/dist/{user-merge-jobs-zetg26e0.js → user-merge-jobs-mxrhamwt.js} +3 -3
  176. package/dist/{virtual-modules-674fka8x.js → virtual-modules-71y1gsmg.js} +3 -3
  177. package/dist/{work-objects-w52yyjxm.js → work-objects-3k4ykt9j.js} +25 -25
  178. package/dist/worker-09gqn9xy.js +83 -0
  179. package/dist/{worker-follow-up-dyfxyjbj.js → worker-follow-up-y0h64xpr.js} +22 -22
  180. package/dist/{x-asbrnafg.js → x-d27jj7z7.js} +2 -2
  181. package/openapi.json +861 -33
  182. package/package.json +4 -4
  183. package/src/apps/sync.ts +20 -5
  184. package/src/azure-devops/boards-sync.ts +1 -1
  185. package/src/be/db/approvals.ts +2 -0
  186. package/src/be/db/runtime.ts +5 -0
  187. package/src/be/db/script-run-sources.ts +17 -0
  188. package/src/be/db/slack-trees.ts +12 -1
  189. package/src/be/db/tasks/read.ts +25 -1
  190. package/src/be/db/tasks/write.ts +47 -12
  191. package/src/be/db/users/avatar.ts +12 -0
  192. package/src/be/db-retention.ts +1 -1
  193. package/src/be/db.ts +149 -67
  194. package/src/be/design-system.ts +63 -0
  195. package/src/be/migrations/342_script_run_sources.sql +20 -0
  196. package/src/be/migrations/344_user_avatar.sql +4 -0
  197. package/src/be/migrations/345_task_status_kind.sql +6 -0
  198. package/src/be/migrations/runner.ts +8 -0
  199. package/src/be/migrations/script-run-sources.ts +51 -0
  200. package/src/be/primitives/object-embed.ts +2 -2
  201. package/src/be/primitives/objects.ts +2 -2
  202. package/src/be/rbac-roles.ts +2 -0
  203. package/src/be/runtime-pools/supervisor.ts +1 -0
  204. package/src/be/scripts/typecheck.ts +5 -3
  205. package/src/be/seed-scripts/catalog/design-system-seed.ts +158 -0
  206. package/src/be/seed-scripts/index.ts +9 -0
  207. package/src/be/swarm-config-guard.ts +25 -1
  208. package/src/bitbucket/handlers.ts +1 -1
  209. package/src/commands/credential-outcome-report.ts +96 -0
  210. package/src/commands/onboard/agent-fs-version.ts +1 -1
  211. package/src/commands/runner.ts +49 -3
  212. package/src/event-waits/github.ts +39 -6
  213. package/src/event-waits/index.ts +4 -2
  214. package/src/event-waits/types.ts +10 -3
  215. package/src/extensions/contract-types.generated.ts +1 -1
  216. package/src/github/app.ts +177 -13
  217. package/src/github/handlers.ts +7 -2
  218. package/src/github/pull-request-state.ts +100 -11
  219. package/src/gitlab/handlers.ts +2 -2
  220. package/src/heartbeat/heartbeat.ts +24 -5
  221. package/src/http/all-routes.ts +1 -0
  222. package/src/http/api-keys.ts +26 -0
  223. package/src/http/approval-chat-answer.ts +99 -0
  224. package/src/http/approval-requests.ts +280 -225
  225. package/src/http/asset-key-write.ts +45 -0
  226. package/src/http/assets.ts +4 -3
  227. package/src/http/design-system.ts +103 -0
  228. package/src/http/github-token.ts +27 -6
  229. package/src/http/index.ts +10 -6
  230. package/src/http/pages-public.ts +25 -10
  231. package/src/http/pages.ts +21 -10
  232. package/src/http/person-responder.ts +28 -0
  233. package/src/http/schedules.ts +6 -6
  234. package/src/http/sessions.ts +7 -2
  235. package/src/http/tasks.ts +23 -5
  236. package/src/http/users.ts +5 -0
  237. package/src/http/webhooks.ts +19 -1
  238. package/src/http/workflows.ts +5 -10
  239. package/src/integrations/chat-sdk/adapters.ts +33 -3
  240. package/src/integrations/chat-sdk/commands.ts +3 -1
  241. package/src/integrations/chat-sdk/inbound.ts +6 -18
  242. package/src/integrations/chat-sdk/mentions.ts +188 -0
  243. package/src/integrations/chat-sdk/outbound.ts +20 -3
  244. package/src/integrations/chat-sdk/router.ts +8 -0
  245. package/src/integrations/chat-sdk/telegram-thread.ts +12 -0
  246. package/src/jira/adf.ts +35 -9
  247. package/src/jira/sync.ts +1 -1
  248. package/src/kv-reserved-namespaces.ts +5 -0
  249. package/src/linear/sync.ts +5 -3
  250. package/src/pages/page-head.ts +11 -1
  251. package/src/prompts/session-templates.ts +1 -0
  252. package/src/providers/acp-targets.ts +2 -2
  253. package/src/providers/amp-adapter.ts +1 -1
  254. package/src/providers/claude-adapter.ts +5 -0
  255. package/src/providers/claude-sdk-session.ts +5 -0
  256. package/src/providers/dsh-adapter.ts +48 -13
  257. package/src/providers/runtime-dependencies.ts +1 -1
  258. package/src/rbac/legacy-policy.ts +4 -0
  259. package/src/rbac/permissions.ts +8 -0
  260. package/src/scheduler/deferred-task-waits.ts +74 -13
  261. package/src/scheduler/index.ts +1 -0
  262. package/src/scheduler/scheduler.test.ts +32 -1
  263. package/src/scheduler/scheduler.ts +24 -1
  264. package/src/script-workflows/executor.ts +6 -0
  265. package/src/script-workflows/supervisor.ts +2 -1
  266. package/src/scripts-runtime/sdk-allowlist.ts +2 -0
  267. package/src/scripts-runtime/swarm-sdk.ts +20 -24
  268. package/src/scripts-runtime/types/stdlib.d.ts +12 -2
  269. package/src/scripts-runtime/types/swarm-extension.d.ts +19 -2
  270. package/src/scripts-runtime/types/swarm-sdk.d.ts +12 -2
  271. package/src/server.ts +2 -0
  272. package/src/slack/actions.ts +4 -1
  273. package/src/slack/approval-actions.ts +148 -0
  274. package/src/slack/approval-buttons.ts +28 -0
  275. package/src/slack/render-v2.ts +148 -7
  276. package/src/tests/api-drain-worker-e2e.test.ts +0 -2
  277. package/src/tests/approval-auto-cancellation-migration.test.ts +8 -19
  278. package/src/tests/approval-card-resolution.test.ts +2 -17
  279. package/src/tests/approval-requests-notifications.test.ts +41 -27
  280. package/src/tests/approval-requests.test.ts +137 -369
  281. package/src/tests/apps-sync-engine.test.ts +5 -3
  282. package/src/tests/apps-table-filters-migration.test.ts +44 -25
  283. package/src/tests/bitbucket-handlers.test.ts +2 -0
  284. package/src/tests/chat-sdk-commands.test.ts +1 -0
  285. package/src/tests/chat-sdk-mentions.test.ts +183 -0
  286. package/src/tests/claude-adapter.test.ts +35 -0
  287. package/src/tests/codex-adapter.test.ts +3 -92
  288. package/src/tests/codex-gpt6-release.test.ts +0 -9
  289. package/src/tests/codex-oauth-credential-info.test.ts +35 -18
  290. package/src/tests/codex-oauth.test.ts +0 -6
  291. package/src/tests/codex-pool.test.ts +5 -214
  292. package/src/tests/codex-rate-limit-parse.test.ts +0 -7
  293. package/src/tests/codex-swarm-events.test.ts +11 -54
  294. package/src/tests/create-page-tool.test.ts +5 -0
  295. package/src/tests/db-client-busy-retry.test.ts +49 -16
  296. package/src/tests/defer-task.test.ts +1 -0
  297. package/src/tests/dsh-adapter.test.ts +53 -1
  298. package/src/tests/e2e-shards.test.ts +9 -9
  299. package/src/tests/enabled-tools.test.ts +0 -2
  300. package/src/tests/fixtures/base-prompt-baseline.json +6 -6
  301. package/src/tests/fixtures/compiled-source-schema-boot.ts +24 -0
  302. package/src/tests/fixtures/secret-corpus.ts +43 -1
  303. package/src/tests/github-app-worker-auth-helper.test.ts +147 -1
  304. package/src/tests/gitlab-handlers.test.ts +2 -0
  305. package/src/tests/heartbeat-jev-gate.test.ts +9 -241
  306. package/src/tests/heartbeat-reroute-decision.test.ts +2 -0
  307. package/src/tests/heartbeat-stall-thresholds.test.ts +174 -0
  308. package/src/tests/heartbeat-supersede-resume.test.ts +2 -0
  309. package/src/tests/heartbeat.test.ts +1 -0
  310. package/src/tests/jira-adf.test.ts +42 -2
  311. package/src/tests/key-usage-selection.test.ts +302 -0
  312. package/src/tests/memory-e2e.test.ts +34 -103
  313. package/src/tests/memory-key-paths.test.ts +5 -0
  314. package/src/tests/memory-rater-llm.test.ts +33 -149
  315. package/src/tests/memory-store.test.ts +24 -125
  316. package/src/tests/memory.test.ts +31 -100
  317. package/src/tests/merge-gate-detect-changes.test.ts +314 -16
  318. package/src/tests/migration-342-script-run-sources.test.ts +196 -0
  319. package/src/tests/migration-bunfs-compat.test.ts +129 -9
  320. package/src/tests/otel-service-name.test.ts +0 -9
  321. package/src/tests/otel-session-cost-metrics.test.ts +1 -38
  322. package/src/tests/pool-session-logs.test.ts +8 -42
  323. package/src/tests/pre-push-affected-tests.test.ts +106 -0
  324. package/src/tests/prompt-template-session.test.ts +3 -0
  325. package/src/tests/rbac-e2e-helpers.test.ts +10 -4
  326. package/src/tests/rbac-e2e-helpers.ts +13 -4
  327. package/src/tests/rbac-roles.test.ts +2 -0
  328. package/src/tests/runner-api-drain.test.ts +2 -17
  329. package/src/tests/runner-terminal-window-report.test.ts +132 -0
  330. package/src/tests/runtime-e2b-pools.test.ts +7 -1
  331. package/src/tests/runtime-supervisor-failures.test.ts +1 -0
  332. package/src/tests/sandboxed-process.test.ts +26 -21
  333. package/src/tests/schedule-http-triage-tools.test.ts +12 -9
  334. package/src/tests/schedule-target-type.test.ts +4 -1
  335. package/src/tests/scheduled-tasks.test.ts +14 -51
  336. package/src/tests/script-connections.test.ts +2 -0
  337. package/src/tests/script-executor-conformance.test.ts +4 -48
  338. package/src/tests/script-executor-quickjs-pool.test.ts +9 -7
  339. package/src/tests/script-native-startup.test.ts +21 -25
  340. package/src/tests/script-runs-retention.test.ts +43 -16
  341. package/src/tests/script-workflows-runtime-e2e.test.ts +56 -22
  342. package/src/tests/scripts-http.test.ts +9 -3
  343. package/src/tests/sdk-allowlist.test.ts +26 -13
  344. package/src/tests/sdk-store-progress-skipped.test.ts +12 -5
  345. package/src/tests/secret-rules.test.ts +38 -2
  346. package/src/tests/secret-scrub-gate.test.ts +7 -0
  347. package/src/tests/secret-scrubber.test.ts +62 -2
  348. package/src/tests/seed-scripts.test.ts +2 -2
  349. package/src/tests/session-logs.test.ts +1 -260
  350. package/src/tests/slack-render-v2.test.ts +5 -148
  351. package/src/tests/system-one-hosts-ui-mirror.test.ts +1 -0
  352. package/src/tests/task-cascade-fail.test.ts +1 -0
  353. package/src/tests/task-supersede-resume.test.ts +1 -0
  354. package/src/tests/test-proc.ts +5 -2
  355. package/src/tests/vcs-azure-devops.test.ts +10 -0
  356. package/src/tests/vcs-provider.test.ts +8 -0
  357. package/src/tests/window-stream-reporter.test.ts +122 -0
  358. package/src/tests/workflow-agent-task-retry.test.ts +1 -3
  359. package/src/tests/workflow-cascade-cancel.test.ts +1 -0
  360. package/src/tests/workflow-retry-v2.test.ts +34 -43
  361. package/src/tests/workflow-retry-validation.test.ts +8 -48
  362. package/src/tests/worktree-reaper.test.ts +2 -2
  363. package/src/themes/design-system.ts +163 -0
  364. package/src/themes/page-theme.ts +28 -19
  365. package/src/tools/cancel-task.ts +2 -2
  366. package/src/tools/chat-post.ts +7 -3
  367. package/src/tools/create-page.ts +3 -0
  368. package/src/tools/defer-task.ts +7 -2
  369. package/src/tools/design-system.ts +102 -0
  370. package/src/tools/get-task-details.ts +8 -4
  371. package/src/tools/get-tasks.ts +13 -2
  372. package/src/tools/manage-user.ts +9 -0
  373. package/src/tools/mcp-servers/mcp-server-get.ts +1 -1
  374. package/src/tools/mcp-servers/mcp-server-list.ts +1 -1
  375. package/src/tools/register-chat-channel.ts +11 -2
  376. package/src/tools/skills/skill-get-file.ts +1 -1
  377. package/src/tools/skills/skill-get.ts +1 -1
  378. package/src/tools/skills/skill-list.ts +1 -1
  379. package/src/tools/skills/skill-search.ts +1 -1
  380. package/src/tools/store-progress.ts +5 -3
  381. package/src/tools/utils.ts +49 -4
  382. package/src/tools/workflows/get-workflow-run.ts +1 -1
  383. package/src/tools/workflows/get-workflow.ts +1 -1
  384. package/src/tools/workflows/list-workflow-runs.ts +1 -1
  385. package/src/tools/workflows/list-workflows.ts +1 -1
  386. package/src/types.ts +158 -0
  387. package/src/utils/constants.ts +12 -0
  388. package/src/utils/credentials.ts +42 -5
  389. package/src/utils/error-tracker.ts +6 -0
  390. package/src/utils/key-usage.ts +114 -0
  391. package/src/utils/sandboxed-process.ts +1 -0
  392. package/src/utils/secret-rules.generated.ts +149 -149
  393. package/src/utils/secret-scrubber.ts +111 -5
  394. package/src/vcs/azure-devops.ts +22 -1
  395. package/src/vcs/index.ts +3 -1
  396. package/src/workflows/approval-inline.ts +122 -0
  397. package/src/workflows/approval-notifications.ts +7 -2
  398. package/src/workflows/engine.ts +6 -5
  399. package/src/workflows/executors/agent-task.ts +14 -0
  400. package/src/workflows/executors/system-one-providers.ts +23 -0
  401. package/src/workflows/resume.ts +5 -2
  402. package/templates/skills/apps/SKILL.md +2 -0
  403. package/templates/skills/apps/content.md +2 -0
  404. package/templates/skills/boards-and-sheets/content.md +4 -2
  405. package/templates/skills/pages/content.md +41 -8
  406. package/templates/skills/swarm-docs/content.md +6 -0
  407. package/templates/skills/swarm-scripts/SKILL.md +1 -0
  408. package/templates/skills/swarm-scripts/content.md +1 -0
  409. package/templates/skills/workflow-iterate/content.md +1 -1
  410. package/dist/acp-adapter-t2q6nsqv.js +0 -17
  411. package/dist/cli-kh973792.js +0 -98
  412. package/dist/core-nheayfgm.js +0 -42
  413. package/dist/fx-adapter-8g7xsp8q.js +0 -20
  414. package/dist/grok-adapter-ztk2zkz1.js +0 -20
  415. package/dist/handlers-9ywssz71.js +0 -41
  416. package/dist/index-6mgbdtv1.js +0 -44
  417. package/dist/index-hqdsn2t2.js +0 -39
  418. package/dist/index-st231bqv.js +0 -40
  419. package/dist/lead-mk0xkth2.js +0 -82
  420. package/dist/thread-buffer-d50rqpev.js +0 -42
  421. package/dist/worker-662x1vse.js +0 -82
  422. package/src/tests/apps-table-selection-migration.test.ts +0 -95
  423. package/src/tests/extensions-example-heartbeat-remediate.test.ts +0 -69
  424. package/src/tests/extensions-example-rewrite-and-suppress.test.ts +0 -70
@@ -0,0 +1,122 @@
1
+ /**
2
+ * P2: mid-session window snapshots go out when a window moved 5 points or
3
+ * more, or 60 s passed since the last report. A failed report never throws.
4
+ */
5
+ import { describe, expect, spyOn, test } from "bun:test";
6
+ import { createWindowStreamReporter } from "../commands/credential-outcome-report";
7
+ import type { RateLimitWindowTelemetry } from "../utils/error-tracker";
8
+
9
+ function windows(fiveHour: number, sevenDay = 0.1): RateLimitWindowTelemetry {
10
+ const lastSeenAt = new Date().toISOString();
11
+ return {
12
+ five_hour: { status: "allowed", utilization: fiveHour, resetsAt: 1_900_000_000, lastSeenAt },
13
+ seven_day: { status: "allowed", utilization: sevenDay, resetsAt: 1_900_500_000, lastSeenAt },
14
+ };
15
+ }
16
+
17
+ function harness(post?: (w: RateLimitWindowTelemetry) => Promise<void>) {
18
+ let clock = 1_000_000;
19
+ const sent: RateLimitWindowTelemetry[] = [];
20
+ const report = createWindowStreamReporter({
21
+ post:
22
+ post ??
23
+ (async (w) => {
24
+ sent.push(w);
25
+ }),
26
+ now: () => clock,
27
+ });
28
+ return {
29
+ report,
30
+ sent,
31
+ advance: (ms: number) => {
32
+ clock += ms;
33
+ },
34
+ };
35
+ }
36
+
37
+ describe("createWindowStreamReporter", () => {
38
+ test("the first snapshot is sent", () => {
39
+ const h = harness();
40
+ h.report(windows(0.2));
41
+ expect(h.sent).toHaveLength(1);
42
+ });
43
+
44
+ test("a move under 5 points within 60 s is skipped", () => {
45
+ const h = harness();
46
+ h.report(windows(0.2));
47
+ h.advance(10_000);
48
+ h.report(windows(0.24));
49
+ h.advance(10_000);
50
+ h.report(windows(0.2, 0.14));
51
+ expect(h.sent).toHaveLength(1);
52
+ });
53
+
54
+ test("a move of 5 points or more is sent at once", () => {
55
+ const h = harness();
56
+ h.report(windows(0.2));
57
+ h.advance(1_000);
58
+ h.report(windows(0.25));
59
+ h.advance(1_000);
60
+ h.report(windows(0.25, 0.2));
61
+ expect(h.sent).toHaveLength(3);
62
+ });
63
+
64
+ test("the delta compares with the last sent snapshot, not the last seen one", () => {
65
+ const h = harness();
66
+ h.report(windows(0.2));
67
+ h.report(windows(0.23));
68
+ h.report(windows(0.26));
69
+ expect(h.sent.map((w) => w.five_hour?.utilization)).toEqual([0.2, 0.26]);
70
+ });
71
+
72
+ test("an unchanged snapshot is sent again after 60 s", () => {
73
+ const h = harness();
74
+ h.report(windows(0.2));
75
+ h.advance(59_999);
76
+ h.report(windows(0.2));
77
+ expect(h.sent).toHaveLength(1);
78
+ h.advance(1);
79
+ h.report(windows(0.2));
80
+ expect(h.sent).toHaveLength(2);
81
+ });
82
+
83
+ test("a window the last report did not carry is sent at once", () => {
84
+ const h = harness();
85
+ h.report({ five_hour: windows(0.2).five_hour! });
86
+ h.advance(1_000);
87
+ h.report(windows(0.2));
88
+ expect(h.sent).toHaveLength(2);
89
+ });
90
+
91
+ test("an empty snapshot is never sent", () => {
92
+ const h = harness();
93
+ h.report({});
94
+ expect(h.sent).toHaveLength(0);
95
+ });
96
+
97
+ test("a rejected or throwing post never throws and the next event retries", async () => {
98
+ const warn = spyOn(console, "warn").mockImplementation(() => {});
99
+ try {
100
+ let calls = 0;
101
+ const h = harness(async () => {
102
+ calls++;
103
+ throw new Error("HTTP 503");
104
+ });
105
+ expect(() => h.report(windows(0.2))).not.toThrow();
106
+ await Bun.sleep(0);
107
+ h.advance(1_000);
108
+ h.report(windows(0.2));
109
+ await Bun.sleep(0);
110
+ expect(calls).toBe(2);
111
+ expect(warn).toHaveBeenCalled();
112
+
113
+ const sync = harness(() => {
114
+ throw new Error("boom");
115
+ });
116
+ expect(() => sync.report(windows(0.2))).not.toThrow();
117
+ await Bun.sleep(0);
118
+ } finally {
119
+ warn.mockRestore();
120
+ }
121
+ });
122
+ });
@@ -292,7 +292,6 @@ describe("agent-task node.retry on task failure", () => {
292
292
  teardownResumeListener?.();
293
293
  try {
294
294
  await failTask(first.id, "superseded_workflow_task");
295
- await new Promise((r) => setTimeout(r, 20));
296
295
  await recoverIncompleteRuns(registry);
297
296
  } finally {
298
297
  teardownResumeListener = setupWorkflowResumeListener(workflowEventBus, registry);
@@ -344,6 +343,7 @@ describe("implicit retry for a superseded task on a node without retry", () => {
344
343
  expect(cut.workflowRunStepId).toBeFalsy();
345
344
  // A cut with a queued retry is not a real failure.
346
345
  expect(cut.status).toBe("superseded");
346
+ expect(cut.statusKind).toBe("workflow_retry");
347
347
  expect(cut.failureReason).toBe(SUPERSEDED_WORKFLOW_TASK_REASON);
348
348
  // It never gets a resume: the heartbeat orphan repair must not see it.
349
349
  const orphans = await getSupersededTasksWithoutResume(
@@ -429,7 +429,6 @@ describe("implicit retry for a superseded task on a node without retry", () => {
429
429
  teardownResumeListener?.();
430
430
  try {
431
431
  await failTask(first.id, SUPERSEDED_WORKFLOW_TASK_REASON);
432
- await new Promise((r) => setTimeout(r, 20));
433
432
  await recoverIncompleteRuns(registry);
434
433
  } finally {
435
434
  teardownResumeListener = setupWorkflowResumeListener(workflowEventBus, registry);
@@ -478,7 +477,6 @@ describe("a cut the workflow carries on without", () => {
478
477
  teardownResumeListener?.();
479
478
  try {
480
479
  await failTask(cut.id, SUPERSEDED_WORKFLOW_TASK_REASON);
481
- await new Promise((r) => setTimeout(r, 20));
482
480
  await recoverIncompleteRuns(registry);
483
481
  } finally {
484
482
  teardownResumeListener = setupWorkflowResumeListener(workflowEventBus, registry);
@@ -314,6 +314,7 @@ describe("cascade cancel", () => {
314
314
  }
315
315
  }
316
316
  expect((await getTaskById(task!.id))?.status).toBe("cancelled");
317
+ expect((await getTaskById(task!.id))?.statusKind).toBe("workflow");
317
318
  // A cancelled task is never handed to a worker.
318
319
  expect(await startTask(task!.id)).toBeNull();
319
320
  });
@@ -446,26 +446,25 @@ describe("Workflow Retry v2 (Phase 4)", () => {
446
446
  ],
447
447
  });
448
448
 
449
- // Execute — first attempt will fail, setting nextRetryAt
450
- failCounter = 0;
451
- const runId = await startWorkflowExecution(workflow, {}, registry);
449
+ try {
450
+ const runId = await startWorkflowExecution(workflow, {}, registry);
451
+ const steps = await getWorkflowRunStepsByRunId(runId);
452
+ const step = steps.find((s) => s.nodeId === "n1")!;
453
+ expect(step.status).toBe("failed");
454
+ expect(step.nextRetryAt).toBeTruthy();
455
+ expect(step.retryCount).toBe(1);
452
456
 
453
- // Check step is failed with a nextRetryAt
454
- const steps = await getWorkflowRunStepsByRunId(runId);
455
- const step = steps.find((s) => s.nodeId === "n1")!;
456
- expect(step.status).toBe("failed");
457
- expect(step.nextRetryAt).toBeTruthy();
458
- expect(step.retryCount).toBe(1);
459
-
460
- // Verify getRetryableSteps finds it once nextRetryAt has passed
461
- await waitUntil(
462
- async () => (await getRetryableSteps()).some((s) => s.runId === runId),
463
- () => `step n1 of run ${runId} never became retryable`,
464
- );
465
- const retryable = await getRetryableSteps();
466
- expect(retryable.length).toBeGreaterThanOrEqual(1);
467
- const ourStep = retryable.find((s) => s.runId === runId);
468
- expect(ourStep).toBeTruthy();
457
+ await waitUntil(
458
+ async () => (await getRetryableSteps()).some((s) => s.runId === runId),
459
+ () => `step n1 of run ${runId} never became retryable`,
460
+ );
461
+ const retryable = await getRetryableSteps();
462
+ const ourStep = retryable.find((s) => s.runId === runId);
463
+ expect(ourStep).toBeTruthy();
464
+ } finally {
465
+ // Retire the queued retry before later pollers use the shared executor counter.
466
+ await deleteWorkflow(workflow.id);
467
+ }
469
468
  });
470
469
 
471
470
  test("retry limit respected (does not retry past maxRetries)", async () => {
@@ -488,32 +487,24 @@ describe("Workflow Retry v2 (Phase 4)", () => {
488
487
  failCounter = 0;
489
488
  const runId = await startWorkflowExecution(workflow, {}, registry);
490
489
 
491
- // Step should be failed after first attempt (retryCount=1, maxRetries=1)
492
- const run = await getWorkflowRun(runId);
493
- // With maxRetries=1, the first failure increments to retryCount=1.
494
- // Since retryCount(1) >= maxRetries(1), no more retries — run should be failed.
495
- // Actually: checkpoint checks retryCount < maxRetries. After first failure, retryCount=1 and
496
- // maxRetries=1, so 1 < 1 is false => no retry => run fails.
497
- // Wait, let me re-check: the engine passes currentRetryCount (from existing step, which is 0
498
- // on first attempt), and checkpoint does retryCount + 1 = 1, then checks 0 < 1 = true,
499
- // so it DOES retry once.
500
- const steps = await getWorkflowRunStepsByRunId(runId);
501
- const step = steps.find((s) => s.nodeId === "n1")!;
490
+ const [initial] = await getWorkflowRunStepsByRunId(runId);
491
+ expect(initial?.status).toBe("failed");
492
+ expect(initial?.retryCount).toBe(1);
493
+ expect(initial?.nextRetryAt).toBeTruthy();
494
+ expect(failCounter).toBe(1);
502
495
 
503
- if (step.status === "failed" && step.nextRetryAt) {
504
- // Was given one retry chance: the poller picks it up once it expires.
505
- // After retry, the second failure should be terminal (retryCount >= maxRetries)
506
- startRetryPoller(registry, 10);
507
- try {
508
- const updatedRun = await waitForRunStatus(runId, "failed");
509
- expect(updatedRun.status).toBe("failed");
510
- } finally {
511
- stopRetryPoller();
512
- }
513
- } else {
514
- // Already terminal
515
- expect(run!.status).toBe("failed");
496
+ startRetryPoller(registry, 10);
497
+ try {
498
+ await waitForRunStatus(runId, "failed");
499
+ } finally {
500
+ stopRetryPoller();
516
501
  }
502
+
503
+ const [exhausted] = await getWorkflowRunStepsByRunId(runId);
504
+ expect(exhausted?.status).toBe("failed");
505
+ expect(exhausted?.retryCount).toBe(1);
506
+ expect(exhausted?.nextRetryAt).toBeUndefined();
507
+ expect(failCounter).toBe(2);
517
508
  });
518
509
 
519
510
  test("a tick in flight when the poller stops does not schedule another", async () => {
@@ -170,8 +170,8 @@ afterAll(async () => {
170
170
 
171
171
  // ─── Tests ───────────────────────────────────────────────────
172
172
 
173
- describe("Retry Poller — Validation on Retry", () => {
174
- test("retry succeeds but validation fails → another retry is scheduled", async () => {
173
+ describe("Workflow validation and retries", () => {
174
+ test("validation failure on retry exhausts the retry policy", async () => {
175
175
  validateCallCount = 0;
176
176
  validateAlwaysPass = false;
177
177
 
@@ -205,9 +205,7 @@ describe("Retry Poller — Validation on Retry", () => {
205
205
  expect(step1.status).toBe("failed");
206
206
  expect(step1.nextRetryAt).toBeTruthy();
207
207
  // Validation was called during the initial execution
208
- expect(validateCallCount).toBeGreaterThanOrEqual(1);
209
-
210
- const validationCountAfterInitial = validateCallCount;
208
+ expect(validateCallCount).toBe(1);
211
209
 
212
210
  // Run the poller until the run fails (validation always fails, retries exhausted)
213
211
  startRetryPoller(registry, 10);
@@ -217,48 +215,10 @@ describe("Retry Poller — Validation on Retry", () => {
217
215
  stopRetryPoller();
218
216
  }
219
217
 
220
- // Validation should have been called again during the retry
221
- expect(validateCallCount).toBeGreaterThan(validationCountAfterInitial);
222
- });
223
-
224
- test("retry succeeds and validation passes → step checkpointed, run completes", async () => {
225
- validateCallCount = 0;
226
- // First call: fail, subsequent calls: pass
227
- // We use the validateAlwaysPass flag to simulate this
228
- validateAlwaysPass = false;
229
-
230
- // Node produces value=100 (>50, so validation passes)
231
- const workflow = await makeWorkflow({
232
- nodes: [
233
- {
234
- id: "n1",
235
- type: "number-gen",
236
- config: { value: 100 },
237
- // Add a node-level retry to force initial failure via a trick:
238
- // We'll use the engine's normal path but manually mark the step
239
- // for retry to test the poller's validation path.
240
- validation: {
241
- executor: "validate",
242
- config: { prompt: "Is result > 50?" },
243
- mustPass: true,
244
- retry: {
245
- strategy: "static",
246
- maxRetries: 3,
247
- baseDelayMs: 10,
248
- maxDelayMs: 10,
249
- },
250
- },
251
- },
252
- ],
253
- });
254
-
255
- // Execute — value=100, so validation passes on first try, run completes
256
- const runId = await startWorkflowExecution(workflow, {}, registry);
257
-
258
- // Should complete immediately since validation passes
259
- const run = await getWorkflowRun(runId);
260
- expect(run!.status).toBe("completed");
261
- expect(validateCallCount).toBeGreaterThanOrEqual(1);
218
+ const [exhausted] = await getWorkflowRunStepsByRunId(runId);
219
+ expect(exhausted?.retryCount).toBe(2);
220
+ expect(exhausted?.nextRetryAt).toBeUndefined();
221
+ expect(validateCallCount).toBe(3);
262
222
  });
263
223
 
264
224
  test('retried script-like node routes to "pass" once validation passes', async () => {
@@ -305,7 +265,7 @@ describe("Retry Poller — Validation on Retry", () => {
305
265
  expect(nodeIds).not.toContain("on-fail");
306
266
  });
307
267
 
308
- test("validation halt on retry → step and run marked failed", async () => {
268
+ test("initial mandatory validation failure fails the step and run without retry", async () => {
309
269
  validateCallCount = 0;
310
270
  validateAlwaysPass = false;
311
271
 
@@ -1,6 +1,6 @@
1
1
  import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
2
2
  import { execFile } from "node:child_process";
3
- import { mkdir, mkdtemp, readdir, rm, stat, writeFile } from "node:fs/promises";
3
+ import { mkdir, mkdtemp, readdir, realpath, rm, stat, writeFile } from "node:fs/promises";
4
4
  import { tmpdir } from "node:os";
5
5
  import { join } from "node:path";
6
6
  import { promisify } from "node:util";
@@ -92,7 +92,7 @@ async function worktreeOfEndedTask(
92
92
  }
93
93
 
94
94
  beforeEach(async () => {
95
- root = await mkdtemp(join(tmpdir(), "worktree-reaper-"));
95
+ root = await realpath(await mkdtemp(join(tmpdir(), "worktree-reaper-")));
96
96
  repo = join(root, "repo");
97
97
  const origin = join(root, "origin.git");
98
98
  await execFileAsync("git", ["init", "-q", "--bare", "-b", "main", origin], { env: gitEnv() });
@@ -0,0 +1,163 @@
1
+ /**
2
+ * The org design system: one brand record per swarm deployment, stored in KV
3
+ * (`design-system` / `org`). It restyles every designVersion 2 page that sets
4
+ * no `theme` (see `resolvePageTheme`). `design-system-set` is the only writer;
5
+ * the namespace is reserved, so a raw `kv-set` cannot skip these checks.
6
+ *
7
+ * Writes and reads run the same checks: tokens go through the theme importer,
8
+ * URLs are https (fonts pinned to Google Fonts, which the page CSP allows),
9
+ * and the base preset must exist. A stored record that fails them reads as
10
+ * invalid and pages ignore it.
11
+ */
12
+
13
+ import { type DesignSystem, type DesignSystemInput, DesignSystemSchema } from "../types";
14
+ import { importThemeTokens, ThemeImportError } from "./import";
15
+ import { DEFAULT_THEME_ID, isThemePresetId, THEME_PRESET_IDS } from "./presets";
16
+
17
+ export const DESIGN_SYSTEM_NAMESPACE = "design-system";
18
+ export const DESIGN_SYSTEM_KEY = "org";
19
+ /** The value `design-system-set` replaced, kept for a one-step undo. */
20
+ export const DESIGN_SYSTEM_PREVIOUS_KEY = "org.prev";
21
+ // shortcut: single undo step, upgrade to versions if a second rollback is needed.
22
+
23
+ export type DesignSystemActor = { userId: string | null; agentId?: string };
24
+
25
+ const FONTS_HOST = "fonts.googleapis.com";
26
+ /** Quotes and angle brackets would break out of the `href` attribute even after escaping mistakes. */
27
+ const UNSAFE_URL_CHARACTERS = /["'<>\s\\]/;
28
+
29
+ export class DesignSystemError extends Error {
30
+ override name = "DesignSystemError";
31
+ }
32
+
33
+ function readHttpsUrl(value: string, label: string, host?: string): string {
34
+ let url: URL;
35
+ try {
36
+ url = new URL(value);
37
+ } catch {
38
+ throw new DesignSystemError(`${label} must be an absolute https URL`);
39
+ }
40
+ if (url.protocol !== "https:" || UNSAFE_URL_CHARACTERS.test(value)) {
41
+ throw new DesignSystemError(`${label} must be an absolute https URL`);
42
+ }
43
+ if (host && url.hostname !== host) {
44
+ throw new DesignSystemError(`${label} must be on https://${host}`);
45
+ }
46
+ return url.href;
47
+ }
48
+
49
+ function readColor(value: string, index: number): string {
50
+ try {
51
+ // The importer's value check is the token contract's check, so reuse it.
52
+ const { tokens } = importThemeTokens({ light: { "--color-chart-1": value } });
53
+ const color = tokens.light["--color-chart-1"];
54
+ if (color === undefined) throw new ThemeImportError("not a color value");
55
+ return color;
56
+ } catch (err) {
57
+ if (err instanceof ThemeImportError) {
58
+ throw new DesignSystemError(`chartPalette[${index}]: ${err.message}`);
59
+ }
60
+ throw err;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Checks and normalizes a design system write. Throws `DesignSystemError`
66
+ * with a message that names the bad field. `ignored` lists the token names
67
+ * the importer could not place.
68
+ */
69
+ export function buildDesignSystem(
70
+ input: DesignSystemInput,
71
+ actor: DesignSystemActor,
72
+ now: Date = new Date(),
73
+ ): { record: DesignSystem; ignored: string[] } {
74
+ const stamp = {
75
+ source: input.source ?? { kind: "manual" as const },
76
+ updatedBy: actor.userId,
77
+ ...(actor.agentId ? { updatedByAgentId: actor.agentId } : {}),
78
+ updatedAt: now.toISOString(),
79
+ };
80
+ if (input.status === "declined") {
81
+ return {
82
+ record: {
83
+ v: 1,
84
+ status: "declined",
85
+ basePreset: DEFAULT_THEME_ID,
86
+ tokens: { light: {}, dark: {} },
87
+ mode: "viewer",
88
+ ...stamp,
89
+ },
90
+ ignored: [],
91
+ };
92
+ }
93
+ const basePreset = input.basePreset ?? DEFAULT_THEME_ID;
94
+ if (!isThemePresetId(basePreset)) {
95
+ throw new DesignSystemError(
96
+ `Unknown basePreset "${basePreset}". Use one of: ${THEME_PRESET_IDS.join(", ")}`,
97
+ );
98
+ }
99
+ let imported: ReturnType<typeof importThemeTokens> = {
100
+ tokens: { light: {}, dark: {} },
101
+ ignored: [],
102
+ };
103
+ if (input.themeTokens) {
104
+ try {
105
+ imported = importThemeTokens(input.themeTokens as Parameters<typeof importThemeTokens>[0]);
106
+ } catch (err) {
107
+ if (err instanceof ThemeImportError) {
108
+ throw new DesignSystemError(`Invalid themeTokens: ${err.message}`);
109
+ }
110
+ throw err;
111
+ }
112
+ }
113
+ const record: DesignSystem = {
114
+ v: 1,
115
+ status: "active",
116
+ basePreset,
117
+ tokens: imported.tokens,
118
+ ...(input.fontsHref
119
+ ? { fontsHref: readHttpsUrl(input.fontsHref, "fontsHref", FONTS_HOST) }
120
+ : {}),
121
+ ...(input.logo
122
+ ? { logo: { url: readHttpsUrl(input.logo.url, "logo.url"), alt: input.logo.alt } }
123
+ : {}),
124
+ mode: input.mode ?? "viewer",
125
+ ...(input.chartPalette ? { chartPalette: input.chartPalette.map(readColor) } : {}),
126
+ ...stamp,
127
+ };
128
+ return { record, ignored: imported.ignored };
129
+ }
130
+
131
+ /**
132
+ * Revalidates a stored value. Returns null for a missing value and
133
+ * `{ invalid }` for one that no longer passes the write checks (a hand-edited
134
+ * row, or a preset that was removed), so pages fall back instead of rendering
135
+ * it.
136
+ */
137
+ export function readDesignSystem(
138
+ value: unknown,
139
+ ): { record: DesignSystem } | { invalid: string } | null {
140
+ if (value === undefined || value === null) return null;
141
+ const result = DesignSystemSchema.safeParse(value);
142
+ if (!result.success) return { invalid: "stored design system is not a valid v1 record" };
143
+ const parsed = result.data;
144
+ try {
145
+ const { record } = buildDesignSystem(
146
+ {
147
+ status: parsed.status,
148
+ basePreset: parsed.basePreset,
149
+ themeTokens: parsed.tokens,
150
+ fontsHref: parsed.fontsHref,
151
+ logo: parsed.logo,
152
+ mode: parsed.mode,
153
+ chartPalette: parsed.chartPalette,
154
+ source: parsed.source,
155
+ },
156
+ { userId: parsed.updatedBy, agentId: parsed.updatedByAgentId },
157
+ );
158
+ return { record: { ...record, updatedAt: parsed.updatedAt } };
159
+ } catch (err) {
160
+ if (err instanceof DesignSystemError) return { invalid: err.message };
161
+ throw err;
162
+ }
163
+ }
@@ -1,13 +1,17 @@
1
1
  /**
2
2
  * Theme resolution and CSS for HTML pages (design version 2).
3
3
  *
4
- * Resolution picks one preset, then applies the page's own overrides:
5
- * - Preset: the page `theme` when it names a known preset, else the viewer
6
- * theme (the dashboard's `__swarm-theme` param) when it names a known
7
- * preset, else `hive`. Direct links pass no viewer theme, so they get Hive.
8
- * - Tokens: the Hive values, then the preset's contract keys, then the page
9
- * `themeTokens` overrides. A shared token (font, radius) that the overrides
10
- * set only in `light` applies to dark too.
4
+ * Resolution picks one preset, then applies the token layers on top:
5
+ * - Preset: the page `theme` when it names a known preset, else the org
6
+ * design system's `basePreset`, else the viewer theme (the dashboard's
7
+ * `__swarm-theme` param) when it names a known preset, else `hive`. Direct
8
+ * links pass no viewer theme, so they get Hive. Once an org has a brand,
9
+ * the viewer preset no longer repaints it.
10
+ * - Tokens: the Hive values, then the preset's contract keys, then the org
11
+ * design system tokens, then the page `themeTokens` overrides. A shared
12
+ * token (font, radius) that a layer sets only in `light` applies to dark too.
13
+ * - The caller passes `designSystem` only for a page without its own `theme`
14
+ * (`pageHead` in src/http/pages-public.ts), so a page `theme` ignores it.
11
15
  *
12
16
  * The CSS carries both modes. `.dark` on `<html>` picks dark, and print is
13
17
  * always light.
@@ -60,24 +64,29 @@ export function resolvePageTheme({
60
64
  pageTheme,
61
65
  viewerTheme,
62
66
  overrides,
67
+ designSystem,
63
68
  }: {
64
69
  pageTheme?: string | null;
65
70
  viewerTheme?: string | null;
66
71
  overrides?: PageThemeTokens | null;
72
+ designSystem?: { basePreset: string; tokens: PageThemeTokens } | null;
67
73
  }): ResolvedPageTheme {
68
74
  const preset =
69
- getThemePreset(pageTheme) ?? getThemePreset(viewerTheme) ?? getThemePreset(DEFAULT_THEME_ID);
70
- const lightOverrides = contractValues(overrides?.light);
71
- const darkOverrides = contractValues(overrides?.dark);
72
- const light = {
73
- ...HIVE_PAGE_TOKENS.light,
74
- ...contractValues(preset?.vars.light),
75
- ...lightOverrides,
76
- };
77
- const dark = { ...HIVE_PAGE_TOKENS.dark, ...contractValues(preset?.vars.dark), ...darkOverrides };
78
- for (const token of PAGE_THEME_SHARED_TOKENS) {
79
- const value = lightOverrides[token];
80
- if (value !== undefined && darkOverrides[token] === undefined) dark[token] = value;
75
+ getThemePreset(pageTheme) ??
76
+ getThemePreset(designSystem?.basePreset) ??
77
+ getThemePreset(viewerTheme) ??
78
+ getThemePreset(DEFAULT_THEME_ID);
79
+ const light = { ...HIVE_PAGE_TOKENS.light, ...contractValues(preset?.vars.light) };
80
+ const dark = { ...HIVE_PAGE_TOKENS.dark, ...contractValues(preset?.vars.dark) };
81
+ for (const layer of [designSystem?.tokens, overrides]) {
82
+ const lightValues = contractValues(layer?.light);
83
+ const darkValues = contractValues(layer?.dark);
84
+ Object.assign(light, lightValues);
85
+ Object.assign(dark, darkValues);
86
+ for (const token of PAGE_THEME_SHARED_TOKENS) {
87
+ const value = lightValues[token];
88
+ if (value !== undefined && darkValues[token] === undefined) dark[token] = value;
89
+ }
81
90
  }
82
91
  return { presetId: preset?.id ?? DEFAULT_THEME_ID, light, dark };
83
92
  }
@@ -93,7 +93,7 @@ export async function cancelTaskHandler(
93
93
  };
94
94
  }
95
95
 
96
- const cancelled = await cancelTask(taskId, reason);
96
+ const cancelled = await cancelTask(taskId, reason, { statusKind: "agent" });
97
97
 
98
98
  if (!cancelled) {
99
99
  return {
@@ -126,7 +126,7 @@ export async function cancelTaskHandler(
126
126
  const ownershipError = assertOwnsTask(ctx, existingTask, "task.cancel.own");
127
127
  if (ownershipError) return ownershipError;
128
128
 
129
- const cancelled = await cancelTask(taskId, reason);
129
+ const cancelled = await cancelTask(taskId, reason, { statusKind: "user" });
130
130
 
131
131
  if (!cancelled) {
132
132
  return {
@@ -18,7 +18,7 @@ export const registerChatPostTool = (server: McpServer) => {
18
18
  {
19
19
  title: "Post to a chat thread or channel",
20
20
  description:
21
- "Lead only. Post a message to any Chat SDK thread or channel (Telegram, Slack, Discord, Teams), outside the thread of your current task. Give threadId to reply in a thread, or channelId to start a new message in a channel. Ids carry the adapter prefix, such as telegram:12345. To answer the user of your current chat task, use chat-reply instead. For a structured result (key figures, a table, charts, links), send a `card`; it posts after the text as a native card.",
21
+ "Lead only. Post a message to any Chat SDK thread or channel (Telegram, Slack, Discord, Teams), outside the thread of your current task. Give threadId to reply in a thread or Telegram topic, or channelId to use its registered default topic (otherwise the channel). Ids carry the adapter prefix, such as telegram:12345 or telegram:-100123:42 for topic 42. To answer the user of your current chat task, use chat-reply instead. For a structured result (key figures, a table, charts, links), send a `card`; it posts after the text as a native card.",
22
22
  annotations: { openWorldHint: true },
23
23
  inputSchema: z.object({
24
24
  adapter: z.enum(CHAT_SDK_ADAPTER_NAMES).describe("Chat SDK adapter name."),
@@ -26,12 +26,16 @@ export const registerChatPostTool = (server: McpServer) => {
26
26
  .string()
27
27
  .min(1)
28
28
  .optional()
29
- .describe("Full SDK thread id, such as telegram:12345 or slack:C123:1700000000.000100."),
29
+ .describe(
30
+ "Full SDK thread id, such as telegram:12345, telegram:-100123:42 (positive integer topic id), or slack:C123:1700000000.000100. Overrides the channel default.",
31
+ ),
30
32
  channelId: z
31
33
  .string()
32
34
  .min(1)
33
35
  .optional()
34
- .describe("Full SDK channel id, such as slack:C123. Ignored when threadId is set."),
36
+ .describe(
37
+ "Full SDK channel id, such as telegram:-100123 or slack:C123. Uses its registered default Telegram topic when set. Ignored when threadId is set.",
38
+ ),
35
39
  text: z
36
40
  .string()
37
41
  .min(1)
@@ -28,6 +28,7 @@ import { resolveTaskAuditUserId, resolveTaskGroupKey } from "@/be/audit-user";
28
28
  import { fileCallerSessionIntoGroup } from "@/be/caller-session-group";
29
29
  import { createPage, getPage, getPageBySlug, updatePage } from "@/be/db";
30
30
  import { getPageEditCounter } from "@/be/db/page-versions";
31
+ import { getDesignSystem } from "@/be/design-system";
31
32
  import { classAttributeValues, countColorLiterals } from "@/pages/color-literals";
32
33
  import { snapshotPage } from "@/pages/version";
33
34
  import { readThemeFields } from "@/themes/page-fields";
@@ -175,6 +176,7 @@ export const registerCreatePageTool = (server: McpServer) => {
175
176
  colorLiteralCount: z.number().optional(),
176
177
  usesDesignSystem: z.boolean().optional(),
177
178
  lightOnlyColors: z.boolean().optional(),
179
+ designSystemStatus: z.string().optional(),
178
180
  movedSessionRootId: z.string().optional(),
179
181
  }),
180
182
  },
@@ -303,6 +305,7 @@ export const registerCreatePageTool = (server: McpServer) => {
303
305
  Boolean(input.themeTokens) ||
304
306
  bodyUsesDesignSystem(fresh.body),
305
307
  lightOnlyColors: hasLightOnlyColors(fresh.themeTokens),
308
+ designSystemStatus: (await getDesignSystem()).current.status,
306
309
  ...(fresh.designVersion >= 2
307
310
  ? { colorLiteralCount: countColorLiterals(fresh.body) }
308
311
  : {}),