@desplega.ai/agent-swarm 2.13.3 → 2.13.4

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 (289) hide show
  1. package/dist/acp-adapter-mr4temec.js +17 -0
  2. package/dist/{acp-targets-k8xs4tj8.js → acp-targets-zrk9k0n7.js} +10 -10
  3. package/dist/{actions-pg5fxjer.js → actions-acqqj9jn.js} +236 -26
  4. package/dist/{agent-fs-provision-vbk3fppw.js → agent-fs-provision-zmaykqnd.js} +4 -4
  5. package/dist/{amp-adapter-adbhxsz9.js → amp-adapter-a7ts8tmw.js} +3 -3
  6. package/dist/{app-b267ggx1.js → app-tmwa442h.js} +7 -7
  7. package/dist/{approval-notifications-evc1a9z5.js → approval-notifications-6psaaaye.js} +8 -8
  8. package/dist/{assistant-wgz2ab84.js → assistant-564v6emv.js} +24 -24
  9. package/dist/{boot-args-schema-6tpk28j4.js → boot-args-schema-n099e0f2.js} +1 -1
  10. package/dist/{boot-reembed-ankp369c.js → boot-reembed-chx66qfk.js} +1 -1
  11. package/dist/{boot-reembed-r1zyvefv.js → boot-reembed-epvg4fp9.js} +1 -1
  12. package/dist/{boot-scrub-sweep-cgb6r5bd.js → boot-scrub-sweep-dhkfp0a7.js} +2 -2
  13. package/dist/{boot-seeds-bjceqg7b.js → boot-seeds-m74fc07r.js} +4 -4
  14. package/dist/{boxd-hr8rsxzq.js → boxd-451q55ys.js} +1 -1
  15. package/dist/{claude-adapter-knztdnff.js → claude-adapter-hw63yj3j.js} +9 -9
  16. package/dist/{claude-managed-adapter-qwejzqkk.js → claude-managed-adapter-z5s7fx6p.js} +3 -3
  17. package/dist/{claude-managed-setup-0vgz4d1j.js → claude-managed-setup-wee1762m.js} +3 -3
  18. package/dist/{claude-sdk-session-c3g6dv0g.js → claude-sdk-session-cktyqkpk.js} +11 -11
  19. package/dist/{cli-7fa6yv98.js → cli-0fgvnb0x.js} +6 -6
  20. package/dist/{cli-2v4xxnx2.js → cli-0h8skzss.js} +1 -1
  21. package/dist/{cli-hhb8kbwd.js → cli-0p76my9q.js} +29 -14
  22. package/dist/{cli-fp65jdp2.js → cli-1kvcsd2f.js} +219 -155
  23. package/dist/{cli-wtffytm8.js → cli-1vmhnncj.js} +3 -3
  24. package/dist/{cli-268b3dgn.js → cli-29h5239w.js} +5 -5
  25. package/dist/{cli-8fj8yfmk.js → cli-2vp0z049.js} +1 -1
  26. package/dist/{cli-bh53ppqm.js → cli-3bxrrh53.js} +4 -4
  27. package/dist/{cli-61fzwtjk.js → cli-3tzmh38q.js} +9 -9
  28. package/dist/{cli-88np9va3.js → cli-3xqad83h.js} +1 -1
  29. package/dist/{cli-gc715jrc.js → cli-3zrwrnz7.js} +1 -1
  30. package/dist/{cli-dw43pnzp.js → cli-404am6f3.js} +7 -7
  31. package/dist/{cli-8pnawt98.js → cli-49aq3cyn.js} +4 -4
  32. package/dist/{cli-fbmgpt72.js → cli-4fpa0zns.js} +3 -3
  33. package/dist/{cli-kwm1bek7.js → cli-4pbwg7sn.js} +2 -2
  34. package/dist/{cli-djwt4mtn.js → cli-4q2c8rxw.js} +9 -9
  35. package/dist/{cli-3mf04tkh.js → cli-4vynxtrb.js} +1 -1
  36. package/dist/{cli-80d5g0fa.js → cli-5ashycw3.js} +3 -3
  37. package/dist/{cli-61p7ty8d.js → cli-5rgm8p39.js} +3 -3
  38. package/dist/{cli-r6xnchva.js → cli-5rxsb3wq.js} +6 -6
  39. package/dist/{cli-a21cwm89.js → cli-60dwk8tx.js} +3 -3
  40. package/dist/{cli-v1v49t36.js → cli-7by7vp6m.js} +2 -2
  41. package/dist/{cli-vgh5adn9.js → cli-7g3fg4gf.js} +7 -7
  42. package/dist/{cli-hxj888w3.js → cli-7gbff32z.js} +2 -2
  43. package/dist/{cli-q8aq48v1.js → cli-8b4rpnwj.js} +1 -1
  44. package/dist/{cli-xc8m5cjn.js → cli-8cas2xvp.js} +3 -3
  45. package/dist/{cli-1606qw3n.js → cli-904wk98s.js} +797 -369
  46. package/dist/{cli-h3drhntp.js → cli-93n305hm.js} +2 -2
  47. package/dist/{cli-1wew39p0.js → cli-944w9wb4.js} +20 -16
  48. package/dist/{cli-je587f74.js → cli-94gx6ze9.js} +1 -1
  49. package/dist/{cli-hpxcfvdm.js → cli-9ah37a8a.js} +6 -6
  50. package/dist/{cli-rfejbpe1.js → cli-akm6y2a8.js} +1 -1
  51. package/dist/{cli-f8rcvf2x.js → cli-azj9t1f9.js} +37 -2
  52. package/dist/{cli-ef590376.js → cli-bv4vvnmg.js} +3 -3
  53. package/dist/{cli-ppf9ap9n.js → cli-bzcwwebm.js} +1 -1
  54. package/dist/{cli-sy2ge2ye.js → cli-cq4am6vg.js} +2 -2
  55. package/dist/{cli-gxqwm3k3.js → cli-d5pc8ep0.js} +102 -8
  56. package/dist/{cli-hd2a204w.js → cli-ea7nz50q.js} +12 -12
  57. package/dist/{cli-zkbz8m2q.js → cli-fkpnx3vf.js} +1 -1
  58. package/dist/{cli-ya1cj689.js → cli-fw67mnyc.js} +1 -1
  59. package/dist/{cli-5basv0e7.js → cli-gkv0r2hq.js} +1 -1
  60. package/dist/{cli-ka4tqjzd.js → cli-gse7bp3z.js} +12 -10
  61. package/dist/{cli-v8rpjrnx.js → cli-gtj12v95.js} +1 -1
  62. package/dist/{cli-g4dhd3pr.js → cli-hdhpdrka.js} +6 -23
  63. package/dist/{cli-dq30fq3q.js → cli-hhtbandk.js} +2 -2
  64. package/dist/cli-hyqksecw.js +1907 -0
  65. package/dist/{cli-t25rq8mg.js → cli-ja450998.js} +40 -11
  66. package/dist/{cli-43dsqhcp.js → cli-jbrc98qb.js} +4 -4
  67. package/dist/{cli-8sayvj48.js → cli-jyhbvdga.js} +3 -3
  68. package/dist/{cli-55fqpd9q.js → cli-jzerrzgc.js} +8 -8
  69. package/dist/{cli-hv3820ez.js → cli-k0nebh10.js} +1 -1
  70. package/dist/{cli-aytna2fm.js → cli-ka48vpev.js} +5 -5
  71. package/dist/{cli-d2epqm0y.js → cli-kezzteka.js} +1 -1
  72. package/dist/{cli-grk77aen.js → cli-kj84fqxz.js} +2 -2
  73. package/dist/{cli-h0ewec3d.js → cli-kr0jpw9c.js} +1 -1
  74. package/dist/{cli-wsnradtk.js → cli-m1sns1da.js} +2 -2
  75. package/dist/{cli-7kv5d674.js → cli-n1kjs58m.js} +4 -4
  76. package/dist/{cli-syqcny89.js → cli-nc4pbwmp.js} +9 -9
  77. package/dist/{cli-9gmkw6xn.js → cli-p3knvk62.js} +48 -42
  78. package/dist/{cli-50whymxq.js → cli-p436yrzp.js} +2 -2
  79. package/dist/{cli-0j4qmc80.js → cli-phdzn699.js} +7 -7
  80. package/dist/{cli-1gnf5c7x.js → cli-pz1dp12c.js} +1 -1
  81. package/dist/{cli-nbawx3s0.js → cli-pz1nq5xm.js} +6 -6
  82. package/dist/{cli-4dyhzhpx.js → cli-qzz6tz8s.js} +1 -1
  83. package/dist/{cli-ea367bdn.js → cli-rmgvwcmy.js} +22 -22
  84. package/dist/{cli-mgr3gatr.js → cli-rv3y60bt.js} +4 -4
  85. package/dist/cli-s33bzmk0.js +27 -0
  86. package/dist/{cli-at67kvnp.js → cli-srktrbby.js} +1 -1
  87. package/dist/{cli-pzsedyb0.js → cli-t0jmkcah.js} +14 -14
  88. package/dist/{cli-eetzmsy5.js → cli-t9pzz2eq.js} +2 -2
  89. package/dist/{cli-w24741sm.js → cli-tr19nyn9.js} +4 -4
  90. package/dist/{cli-e4gx499y.js → cli-ts5yv7dn.js} +163 -86
  91. package/dist/{cli-czeh7x13.js → cli-tsc3pdfd.js} +4 -4
  92. package/dist/{cli-y0q92v4r.js → cli-tzw1jr2t.js} +2 -2
  93. package/dist/{cli-tjf1bh1v.js → cli-x2cem5vy.js} +6 -4
  94. package/dist/{cli-vx9acp12.js → cli-ybte1fqc.js} +1 -1
  95. package/dist/{cli-gkjw33x5.js → cli-ysv0k1we.js} +2 -2
  96. package/dist/{cli-vdfngx2g.js → cli-ywy8yz6t.js} +2 -2
  97. package/dist/{cli-cpkxh68d.js → cli-z1vam71h.js} +2 -2
  98. package/dist/{cli-8m6gqnf1.js → cli-zexwhj3f.js} +3 -3
  99. package/dist/{cli-snwz16eg.js → cli-zhwjdhjr.js} +2 -2
  100. package/dist/{cli-y754psdt.js → cli-zjdhrzm0.js} +4 -4
  101. package/dist/cli.js +19 -19
  102. package/dist/{codex-adapter-493vb8cv.js → codex-adapter-2fs2c0n6.js} +8 -8
  103. package/dist/{codex-hook-ej8hn6z5.js → codex-hook-jxjv6dy5.js} +1 -1
  104. package/dist/{codex-login-ven5cz5j.js → codex-login-ktfg1cxk.js} +1 -1
  105. package/dist/{codex-session-runner-ps5m4z1g.js → codex-session-runner-r55tmx4c.js} +9 -9
  106. package/dist/{commands-shktk0b8.js → commands-0mxdy9x8.js} +3 -3
  107. package/dist/{controller-wn3vd217.js → controller-g3vkfhr4.js} +4 -4
  108. package/dist/{controllers-connect-yft057ws.js → controllers-connect-4wdmncqt.js} +25 -25
  109. package/dist/core-gsvj5f3z.js +42 -0
  110. package/dist/{cursor-adapter-8fpm4dng.js → cursor-adapter-t9qb96q2.js} +2 -2
  111. package/dist/{db-0ezhdhz5.js → db-487vvyv9.js} +3 -3
  112. package/dist/{db-84pz2w5c.js → db-76p7w3gr.js} +2 -2
  113. package/dist/{devin-adapter-fs90ab4v.js → devin-adapter-3bp6rape.js} +1 -1
  114. package/dist/{dispatcher-h2rz69f6.js → dispatcher-64rp6w67.js} +22 -22
  115. package/dist/{docker-1h33jvh9.js → docker-a59g3ebm.js} +2 -2
  116. package/dist/{dsh-adapter-g9yqv09y.js → dsh-adapter-8abzqk5c.js} +2 -2
  117. package/dist/{e2b-y7e5kmzf.js → e2b-3ykbe805.js} +2 -2
  118. package/dist/{e2b-jnk0yeva.js → e2b-dc8f6ctq.js} +2 -2
  119. package/dist/{easter-egg-3d-m41ad78v.js → easter-egg-3d-jrrwyf55.js} +1 -1
  120. package/dist/{embedding-space-yam9zwzj.js → embedding-space-001hhhpk.js} +6 -6
  121. package/dist/{embeddings-g2be0y8q.js → embeddings-esj19cnw.js} +1 -1
  122. package/dist/{event-bus-08t2b4y2.js → event-bus-7gbsr0g4.js} +1 -1
  123. package/dist/{execute-hhdejgzf.js → execute-301hkxqg.js} +1 -1
  124. package/dist/{external-channel-kjt2yzfj.js → external-channel-w10e2j05.js} +2 -2
  125. package/dist/fx-adapter-4sjrbdne.js +20 -0
  126. package/dist/grok-adapter-3a0ezfee.js +20 -0
  127. package/dist/handlers-ef3k11hb.js +41 -0
  128. package/dist/{heartbeat-2e5jdexj.js → heartbeat-tbrj7vhq.js} +25 -25
  129. package/dist/{hook-acg9saz7.js → hook-3am1sq68.js} +6 -6
  130. package/dist/{hook-34s8cmgn.js → hook-tx917rqw.js} +8 -8
  131. package/dist/{http-ra2zr2f8.js → http-3rmemtqy.js} +335 -1829
  132. package/dist/{index-mbpxhc4w.js → index-126v2d0t.js} +1 -4
  133. package/dist/{index-2z1z7qx6.js → index-2jw11t8s.js} +26 -26
  134. package/dist/{index-9q42cr54.js → index-aetfyx6p.js} +1 -1
  135. package/dist/index-e6bq0exk.js +42 -0
  136. package/dist/{index-9r4j0a60.js → index-gfnq66t1.js} +223 -25
  137. package/dist/index-hf2k1vge.js +39 -0
  138. package/dist/{index-93bw5wds.js → index-s7xtvc0f.js} +1 -1
  139. package/dist/index-taxmejj3.js +44 -0
  140. package/dist/{k8s-8326q0rq.js → k8s-36gfn847.js} +2 -2
  141. package/dist/{keepalive-vjnnqbkm.js → keepalive-9px3t7qj.js} +5 -5
  142. package/dist/lead-5vt6f174.js +83 -0
  143. package/dist/{maintenance-px2g599e.js → maintenance-vwqjwst6.js} +1 -1
  144. package/dist/{oauth-refresh-sweep-nkykf09m.js → oauth-refresh-sweep-yqry3wn4.js} +4 -4
  145. package/dist/{object-webhooks-gt9xnq21.js → object-webhooks-8s1wtths.js} +7 -7
  146. package/dist/{onboard-1f134p65.js → onboard-hb8czx0p.js} +7 -7
  147. package/dist/{opencode-adapter-94976yab.js → opencode-adapter-djd6m6dk.js} +8 -8
  148. package/dist/{otel-impl-5d4p2fqs.js → otel-impl-2ymwyczz.js} +2 -2
  149. package/dist/{pending-vkk0vx6n.js → pending-nxavtvx7.js} +23 -23
  150. package/dist/{pi-mono-adapter-cyzdv5er.js → pi-mono-adapter-d2cpmcy4.js} +12 -12
  151. package/dist/{pricing-refresh-jtmjwss9.js → pricing-refresh-1yz8jkqv.js} +2 -2
  152. package/dist/{rbac-roles-1fvmdyeb.js → rbac-roles-7s6m31xw.js} +6 -4
  153. package/dist/{rbac-roles-yd1fgpsn.js → rbac-roles-dbpx0x9v.js} +3 -3
  154. package/dist/{render-v2-kb5s3vx4.js → render-v2-7y20rjrn.js} +7 -7
  155. package/dist/{resume-z1vs44n5.js → resume-wz546x47.js} +10 -10
  156. package/dist/{runtime-gk6ct7r7.js → runtime-cb5bd9tz.js} +1 -1
  157. package/dist/{session-access-nz6nre4d.js → session-access-4vcft8kq.js} +5 -5
  158. package/dist/{session-source-backfill-wb60zjkd.js → session-source-backfill-57b50tpw.js} +3 -3
  159. package/dist/{setup-2x8g8j4s.js → setup-e1tevjyj.js} +1 -1
  160. package/dist/thread-buffer-686pa1p1.js +42 -0
  161. package/dist/{tree-visibility-ts3z30kw.js → tree-visibility-07wf1nct.js} +2 -2
  162. package/dist/{user-merge-jobs-zetg26e0.js → user-merge-jobs-n20qpv6s.js} +3 -3
  163. package/dist/{virtual-modules-674fka8x.js → virtual-modules-6fxmn1yv.js} +3 -3
  164. package/dist/{work-objects-w52yyjxm.js → work-objects-eg7y48pe.js} +25 -25
  165. package/dist/worker-4vp616ms.js +83 -0
  166. package/dist/{worker-follow-up-dyfxyjbj.js → worker-follow-up-jnvnnf2b.js} +22 -22
  167. package/dist/{x-asbrnafg.js → x-d27jj7z7.js} +2 -2
  168. package/openapi.json +475 -28
  169. package/package.json +2 -2
  170. package/src/be/db/approvals.ts +2 -0
  171. package/src/be/db/runtime.ts +5 -0
  172. package/src/be/db/script-run-sources.ts +17 -0
  173. package/src/be/db-retention.ts +1 -1
  174. package/src/be/db.ts +71 -62
  175. package/src/be/design-system.ts +63 -0
  176. package/src/be/migrations/342_script_run_sources.sql +20 -0
  177. package/src/be/migrations/runner.ts +8 -0
  178. package/src/be/migrations/script-run-sources.ts +51 -0
  179. package/src/be/rbac-roles.ts +2 -0
  180. package/src/be/scripts/typecheck.ts +4 -2
  181. package/src/be/seed-scripts/catalog/design-system-seed.ts +158 -0
  182. package/src/be/seed-scripts/index.ts +9 -0
  183. package/src/be/swarm-config-guard.ts +21 -1
  184. package/src/commands/onboard/agent-fs-version.ts +1 -1
  185. package/src/heartbeat/heartbeat.ts +18 -4
  186. package/src/http/all-routes.ts +1 -0
  187. package/src/http/approval-chat-answer.ts +99 -0
  188. package/src/http/approval-requests.ts +280 -225
  189. package/src/http/design-system.ts +103 -0
  190. package/src/http/index.ts +10 -6
  191. package/src/http/pages-public.ts +25 -10
  192. package/src/http/pages.ts +17 -0
  193. package/src/http/person-responder.ts +28 -0
  194. package/src/integrations/chat-sdk/adapters.ts +33 -3
  195. package/src/integrations/chat-sdk/inbound.ts +6 -18
  196. package/src/integrations/chat-sdk/mentions.ts +188 -0
  197. package/src/integrations/chat-sdk/outbound.ts +20 -3
  198. package/src/integrations/chat-sdk/router.ts +8 -0
  199. package/src/integrations/chat-sdk/telegram-thread.ts +12 -0
  200. package/src/jira/adf.ts +35 -9
  201. package/src/kv-reserved-namespaces.ts +5 -0
  202. package/src/pages/page-head.ts +11 -1
  203. package/src/providers/amp-adapter.ts +1 -1
  204. package/src/providers/dsh-adapter.ts +48 -13
  205. package/src/rbac/legacy-policy.ts +4 -0
  206. package/src/rbac/permissions.ts +8 -0
  207. package/src/scheduler/index.ts +1 -0
  208. package/src/scheduler/scheduler.test.ts +32 -1
  209. package/src/scheduler/scheduler.ts +24 -1
  210. package/src/script-workflows/executor.ts +6 -0
  211. package/src/script-workflows/supervisor.ts +2 -1
  212. package/src/scripts-runtime/sdk-allowlist.ts +2 -0
  213. package/src/scripts-runtime/swarm-sdk.ts +12 -23
  214. package/src/scripts-runtime/types/stdlib.d.ts +4 -1
  215. package/src/scripts-runtime/types/swarm-sdk.d.ts +4 -1
  216. package/src/server.ts +2 -0
  217. package/src/slack/actions.ts +3 -0
  218. package/src/slack/approval-actions.ts +148 -0
  219. package/src/slack/approval-buttons.ts +28 -0
  220. package/src/tests/chat-sdk-mentions.test.ts +183 -0
  221. package/src/tests/create-page-tool.test.ts +5 -0
  222. package/src/tests/dsh-adapter.test.ts +53 -1
  223. package/src/tests/fixtures/compiled-source-schema-boot.ts +24 -0
  224. package/src/tests/fixtures/secret-corpus.ts +43 -1
  225. package/src/tests/heartbeat-stall-thresholds.test.ts +174 -0
  226. package/src/tests/jira-adf.test.ts +42 -2
  227. package/src/tests/merge-gate-detect-changes.test.ts +208 -16
  228. package/src/tests/migration-342-script-run-sources.test.ts +196 -0
  229. package/src/tests/migration-bunfs-compat.test.ts +129 -9
  230. package/src/tests/rbac-e2e-helpers.test.ts +10 -4
  231. package/src/tests/rbac-e2e-helpers.ts +13 -4
  232. package/src/tests/rbac-roles.test.ts +2 -0
  233. package/src/tests/runtime-e2b-pools.test.ts +7 -1
  234. package/src/tests/schedule-target-type.test.ts +4 -1
  235. package/src/tests/script-connections.test.ts +2 -0
  236. package/src/tests/script-runs-retention.test.ts +43 -16
  237. package/src/tests/script-workflows-runtime-e2e.test.ts +56 -22
  238. package/src/tests/scripts-http.test.ts +9 -3
  239. package/src/tests/sdk-allowlist.test.ts +26 -13
  240. package/src/tests/sdk-store-progress-skipped.test.ts +12 -5
  241. package/src/tests/secret-rules.test.ts +34 -0
  242. package/src/tests/secret-scrub-gate.test.ts +7 -0
  243. package/src/tests/secret-scrubber.test.ts +62 -2
  244. package/src/tests/seed-scripts.test.ts +2 -2
  245. package/src/tests/system-one-hosts-ui-mirror.test.ts +1 -0
  246. package/src/tests/vcs-azure-devops.test.ts +10 -0
  247. package/src/tests/vcs-provider.test.ts +8 -0
  248. package/src/themes/design-system.ts +163 -0
  249. package/src/themes/page-theme.ts +28 -19
  250. package/src/tools/chat-post.ts +7 -3
  251. package/src/tools/create-page.ts +3 -0
  252. package/src/tools/design-system.ts +102 -0
  253. package/src/tools/mcp-servers/mcp-server-get.ts +1 -1
  254. package/src/tools/mcp-servers/mcp-server-list.ts +1 -1
  255. package/src/tools/register-chat-channel.ts +11 -2
  256. package/src/tools/skills/skill-get-file.ts +1 -1
  257. package/src/tools/skills/skill-get.ts +1 -1
  258. package/src/tools/skills/skill-list.ts +1 -1
  259. package/src/tools/skills/skill-search.ts +1 -1
  260. package/src/tools/utils.ts +49 -4
  261. package/src/tools/workflows/get-workflow-run.ts +1 -1
  262. package/src/tools/workflows/get-workflow.ts +1 -1
  263. package/src/tools/workflows/list-workflow-runs.ts +1 -1
  264. package/src/tools/workflows/list-workflows.ts +1 -1
  265. package/src/types.ts +65 -0
  266. package/src/utils/secret-rules.generated.ts +149 -149
  267. package/src/utils/secret-scrubber.ts +111 -5
  268. package/src/vcs/azure-devops.ts +22 -1
  269. package/src/vcs/index.ts +3 -1
  270. package/src/workflows/approval-inline.ts +122 -0
  271. package/src/workflows/approval-notifications.ts +7 -2
  272. package/src/workflows/engine.ts +6 -5
  273. package/src/workflows/executors/agent-task.ts +14 -0
  274. package/src/workflows/executors/system-one-providers.ts +23 -0
  275. package/templates/skills/pages/content.md +34 -8
  276. package/templates/skills/swarm-docs/content.md +5 -0
  277. package/templates/skills/workflow-iterate/content.md +1 -1
  278. package/dist/acp-adapter-t2q6nsqv.js +0 -17
  279. package/dist/cli-kh973792.js +0 -98
  280. package/dist/core-nheayfgm.js +0 -42
  281. package/dist/fx-adapter-8g7xsp8q.js +0 -20
  282. package/dist/grok-adapter-ztk2zkz1.js +0 -20
  283. package/dist/handlers-9ywssz71.js +0 -41
  284. package/dist/index-6mgbdtv1.js +0 -44
  285. package/dist/index-hqdsn2t2.js +0 -39
  286. package/dist/index-st231bqv.js +0 -40
  287. package/dist/lead-mk0xkth2.js +0 -82
  288. package/dist/thread-buffer-d50rqpev.js +0 -42
  289. package/dist/worker-662x1vse.js +0 -82
@@ -8,6 +8,11 @@ const RESERVED_FAMILIES = new Map([
8
8
  ["apps", "namespace is reserved for swarm apps; use the app row endpoints"],
9
9
  // step-9: Comb's "Send to swarm" claims (`comb:sent`).
10
10
  ["comb", "namespace is reserved for Comb; use POST /api/comb/review-batches"],
11
+ // The org design system (src/themes/design-system.ts): writes must pass its token checks.
12
+ [
13
+ "design-system",
14
+ "namespace is reserved for the org design system; use design-system-set or PUT /api/design-system",
15
+ ],
11
16
  ["heartbeat-checklist", "namespace is reserved for heartbeat checklist receipts"],
12
17
  ["worker", "namespace is reserved for worker nudges"],
13
18
  // Durable dedupe for SLACK_BLOCK_EXTERNAL_CHANNELS alerts (src/slack/external-channel.ts).
@@ -111,6 +111,13 @@ const FONT_LINKS = `<link rel="preconnect" href="https://fonts.googleapis.com">
111
111
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
112
112
  <link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Space+Mono:wght@400;700&display=swap" rel="stylesheet">`;
113
113
 
114
+ function fontLinks(href: string): string {
115
+ const escaped = href.replaceAll("&", "&amp;").replaceAll('"', "&quot;");
116
+ return `<link rel="preconnect" href="https://fonts.googleapis.com">
117
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
118
+ <link href="${escaped}" rel="stylesheet">`;
119
+ }
120
+
114
121
  /**
115
122
  * The Tailwind source. Theme and utilities only: Preflight stays off, so the
116
123
  * element defaults below survive. `inline reference` maps each token utility
@@ -748,15 +755,18 @@ ${TONE_RULES}
748
755
  export function buildPageHeadV2({
749
756
  theme,
750
757
  mode,
758
+ fontsHref,
751
759
  }: {
752
760
  theme: ResolvedPageTheme;
753
761
  mode: "light" | "dark";
762
+ /** The org design system's Google Fonts stylesheet, already checked to be on fonts.googleapis.com. */
763
+ fontsHref?: string;
754
764
  }): string {
755
765
  return [
756
766
  '<base target="_blank">',
757
767
  IN_PAGE_LINK_SCRIPT,
758
768
  "<style>@layer properties, theme, base, components, utilities;</style>",
759
- FONT_LINKS,
769
+ fontsHref ? fontLinks(fontsHref) : FONT_LINKS,
760
770
  `<style id="swarm-theme">\n${renderPageThemeCss(theme)}\n</style>`,
761
771
  `<style id="swarm-design">\n${PAGE_DESIGN_CSS}\n</style>`,
762
772
  TAILWIND_SOURCE_SCRIPT,
@@ -45,7 +45,7 @@ import type {
45
45
  * default; the image installs exactly this version and the per-task settings
46
46
  * set `amp.updates.mode: "disabled"`. Bump it deliberately, with a live run.
47
47
  */
48
- export const AMP_PACKAGE = "@ampcode/cli@0.0.1794744038-ga74b43";
48
+ export const AMP_PACKAGE = "@ampcode/cli@0.0.1794838312-g371aa5";
49
49
 
50
50
  /** MCP server name. Amp exposes its tools as `agent_swarm` / `store_progress` (dashes become underscores). */
51
51
  const AMP_MCP_SERVER_NAME = "agent-swarm";
@@ -39,6 +39,28 @@ import type {
39
39
  // npm's `latest` is older and lacks the JSON/stdin contract used here.
40
40
  export const DSH_PACKAGE = "@deepseek-ai/dsh@0.2.2-rc.3";
41
41
 
42
+ /** Held stderr past this is flushed as is, so a line with no newline cannot grow without bound. */
43
+ const STDERR_HOLD_MAX = 64 * 1024;
44
+ const PEM_PRIVATE_BEGIN_RE = /^-----BEGIN [A-Z0-9 ]{0,32}PRIVATE KEY/;
45
+
46
+ /**
47
+ * How much of the pending stderr text can be scrubbed and emitted now: every
48
+ * complete line, except a private-key PEM block still waiting for its END
49
+ * line. A token split across two pipe chunks, or a PEM body split across
50
+ * lines, is then scrubbed whole. Past `STDERR_HOLD_MAX` everything goes, and
51
+ * the scrubber's truncated-PEM rule still covers a cut block.
52
+ */
53
+ export function stderrFlushLength(pending: string): number {
54
+ if (pending.length > STDERR_HOLD_MAX) return pending.length;
55
+ let cut = pending.lastIndexOf("\n") + 1;
56
+ const begin = cut > 0 ? pending.lastIndexOf("-----BEGIN ", cut - 1) : -1;
57
+ if (begin >= 0 && !pending.slice(begin, cut).includes("-----END ")) {
58
+ const lineStart = pending.lastIndexOf("\n", begin) + 1;
59
+ if (PEM_PRIVATE_BEGIN_RE.test(pending.slice(begin, begin + 64))) cut = lineStart;
60
+ }
61
+ return cut;
62
+ }
63
+
42
64
  export function checkDshCredentials(env: Record<string, string | undefined>): CredStatus {
43
65
  return env.DEEPSEEK_API_KEY?.trim() || env.OPENROUTER_API_KEY?.trim()
44
66
  ? { ready: true, missing: [], satisfiedBy: "env" }
@@ -234,20 +256,33 @@ class DshSession implements ProviderSession {
234
256
 
235
257
  private async readStderr(): Promise<void> {
236
258
  const decoder = new TextDecoder();
259
+ // Scrub whole lines, not raw chunks: a chunk boundary can split a token.
260
+ let pending = "";
237
261
  for await (const chunk of this.proc.stderr) {
238
- const content = scrubSecrets(decoder.decode(chunk, { stream: true }));
239
- this.stderr = (this.stderr + content).slice(-8000);
240
- this.emit({ type: "raw_stderr", content });
241
- // dsh downgrades a failed plugin to a "did not activate" warning even
242
- // with failOnStartupError, then runs on without the swarm tools. A
243
- // session that cannot reach store-progress must not pass as healthy.
244
- if (
245
- !this.failure &&
246
- this.stderr.includes(`${DSH_MCP_ENTRY_ID} (@deepseek-ai/dsh-mcp-client)`)
247
- ) {
248
- this.failure = `dsh could not connect to the swarm MCP server: ${this.stderr.trim().slice(0, 500)}`;
249
- await terminateProcessGroup(this.proc.pid);
250
- }
262
+ pending += decoder.decode(chunk, { stream: true });
263
+ const cut = stderrFlushLength(pending);
264
+ if (cut === 0) continue;
265
+ const text = pending.slice(0, cut);
266
+ pending = pending.slice(cut);
267
+ await this.consumeStderr(text);
268
+ }
269
+ pending += decoder.decode();
270
+ if (pending) await this.consumeStderr(pending);
271
+ }
272
+
273
+ private async consumeStderr(text: string): Promise<void> {
274
+ const content = scrubSecrets(text);
275
+ this.stderr = (this.stderr + content).slice(-8000);
276
+ this.emit({ type: "raw_stderr", content });
277
+ // dsh downgrades a failed plugin to a "did not activate" warning even
278
+ // with failOnStartupError, then runs on without the swarm tools. A
279
+ // session that cannot reach store-progress must not pass as healthy.
280
+ if (
281
+ !this.failure &&
282
+ this.stderr.includes(`${DSH_MCP_ENTRY_ID} (@deepseek-ai/dsh-mcp-client)`)
283
+ ) {
284
+ this.failure = `dsh could not connect to the swarm MCP server: ${this.stderr.trim().slice(0, 500)}`;
285
+ await terminateProcessGroup(this.proc.pid);
251
286
  }
252
287
  }
253
288
 
@@ -348,6 +348,10 @@ export const LEGACY_POLICY = {
348
348
  "comb.presence": operatorOrUser,
349
349
  "fs.join.own": anyAuthenticated,
350
350
  "page.delete.any": leadOrResourceOwner,
351
+ // Any agent records the requester's answer to the first-page ask (src/tools/design-system.ts).
352
+ "design-system.write": anyAuthenticated,
353
+ // Opening a page is a read. Writes from the page session keep their own verbs.
354
+ "page.launch": anyAuthenticated,
351
355
  // Humans only: agents edit objects with the board-* and sheet-* tools as themselves.
352
356
  "objects.read": operatorOrUser,
353
357
  "objects.write": operatorOrUser,
@@ -356,6 +356,14 @@ export const PERMISSIONS = {
356
356
  description: "Delete a page the caller does not own.",
357
357
  namespace: "page",
358
358
  },
359
+ "design-system.write": {
360
+ description: "Set or decline the org design system that restyles every page.",
361
+ namespace: "page",
362
+ },
363
+ "page.launch": {
364
+ description: "Open a public or authed page: mint its page-session cookie.",
365
+ namespace: "page",
366
+ },
359
367
  "objects.read": {
360
368
  description:
361
369
  "Read a board or sheet on the swarm's shared agent-fs drive through the object routes.",
@@ -2,6 +2,7 @@ export {
2
2
  calculateNextRun,
3
3
  type DispatchScheduleResult,
4
4
  dispatchScheduleTarget,
5
+ parseSchedulerIntervalMs,
5
6
  runScheduleNow,
6
7
  startScheduler,
7
8
  stopScheduler,
@@ -1,7 +1,11 @@
1
1
  import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2
2
  import { unlinkSync } from "node:fs";
3
3
  import { closeDb, createAgent, createScheduledTask, createTaskExtended, initDb } from "../be/db";
4
- import { calculateNextRun, createStandaloneScheduleTask } from "./scheduler";
4
+ import {
5
+ calculateNextRun,
6
+ createStandaloneScheduleTask,
7
+ parseSchedulerIntervalMs,
8
+ } from "./scheduler";
5
9
 
6
10
  const TEST_DB_PATH = "./test-scheduler.sqlite";
7
11
 
@@ -20,6 +24,33 @@ afterAll(() => {
20
24
  }
21
25
  });
22
26
 
27
+ describe("parseSchedulerIntervalMs", () => {
28
+ test("falls back to 10s unless the value is an integer inside the timer range", () => {
29
+ const unusable = [
30
+ undefined,
31
+ "",
32
+ "abc",
33
+ "NaN",
34
+ "Infinity",
35
+ "-Infinity",
36
+ "0",
37
+ "-1",
38
+ "1.5",
39
+ "2147483648",
40
+ "10000000000",
41
+ ];
42
+ for (const raw of unusable) {
43
+ expect(parseSchedulerIntervalMs(raw)).toBe(10_000);
44
+ }
45
+ });
46
+
47
+ test("keeps a positive configured interval unchanged", () => {
48
+ expect(parseSchedulerIntervalMs("2500")).toBe(2500);
49
+ expect(parseSchedulerIntervalMs("30000")).toBe(30_000);
50
+ expect(parseSchedulerIntervalMs("2147483647")).toBe(2_147_483_647);
51
+ });
52
+ });
53
+
23
54
  describe("calculateNextRun", () => {
24
55
  test("calculates next run with cron expression", async () => {
25
56
  const schedule = await createScheduledTask({
@@ -28,6 +28,7 @@ import { buildScriptCredentialBindingsWithFailures } from "@/be/script-credentia
28
28
  import { getScript } from "@/be/scripts/db";
29
29
  import { runScriptWithRunCredential } from "@/be/scripts/run-credential";
30
30
  import { seededWorkflowState } from "@/be/seed/workflows-seeder";
31
+ import { SCHEDULER_INTERVAL_MS_BOUNDS } from "@/be/swarm-config-guard";
31
32
  import { telemetry } from "@/telemetry";
32
33
  import type { AgentTask, ScheduledTask, Workflow } from "@/types";
33
34
  import { getExecutorRegistry as getWorkflowExecutorRegistry } from "@/workflows";
@@ -558,6 +559,28 @@ export async function executeSchedule(
558
559
  }
559
560
  }
560
561
 
562
+ /** Polling interval when `SCHEDULER_INTERVAL_MS` is absent or unusable. */
563
+ const DEFAULT_SCHEDULER_INTERVAL_MS = 10_000;
564
+
565
+ /**
566
+ * Parse SCHEDULER_INTERVAL_MS: an integer inside `SCHEDULER_INTERVAL_MS_BOUNDS`
567
+ * (1 ms to 24.8 days), or the 10-second default.
568
+ *
569
+ * `Number(value) || 10_000` kept a negative interval, and `setInterval` treats a
570
+ * non-positive delay as "as fast as the runtime permits", so a negative value made
571
+ * the scheduler poll in a tight loop (#3169). A delay above the 32-bit timer
572
+ * ceiling overflows to 1 ms and produces the same loop, so it falls back too. The
573
+ * config API validates the key against the same bounds; this is the boot-path
574
+ * guard for the deployment env, and for rows written before those bounds existed.
575
+ */
576
+ export function parseSchedulerIntervalMs(raw: string | undefined): number {
577
+ const value = Number(raw);
578
+ const { min, max } = SCHEDULER_INTERVAL_MS_BOUNDS;
579
+ return Number.isInteger(value) && value >= min && value <= max
580
+ ? value
581
+ : DEFAULT_SCHEDULER_INTERVAL_MS;
582
+ }
583
+
561
584
  /**
562
585
  * Start the scheduler polling loop.
563
586
  * @param registry ExecutorRegistry for triggering workflows linked to schedules
@@ -565,7 +588,7 @@ export async function executeSchedule(
565
588
  */
566
589
  export function startScheduler(
567
590
  registry: ExecutorRegistry,
568
- intervalMs = 10000,
591
+ intervalMs = DEFAULT_SCHEDULER_INTERVAL_MS,
569
592
  opts?: { runId?: string },
570
593
  ): void {
571
594
  if (schedulerRun) {
@@ -32,6 +32,7 @@ export const MAX_ACTIVE_CAPABILITY_DISPATCHES = 8;
32
32
  export type ScriptExecutionResult = {
33
33
  exitCode: number | null;
34
34
  stderr: string;
35
+ terminated?: boolean;
35
36
  };
36
37
 
37
38
  export type ScriptExecutionHandle = {
@@ -193,6 +194,7 @@ export class LocalProcessScriptExecutor implements ScriptExecutor {
193
194
  let proc: Bun.Subprocess<"ignore", "ignore", "pipe"> | undefined;
194
195
  let capabilitySocket: Socket | undefined;
195
196
  let protocolFailure: Error | undefined;
197
+ let terminated = false;
196
198
  const sockets = new Set<Socket>();
197
199
  const server = createServer((socket) => {
198
200
  sockets.add(socket);
@@ -412,6 +414,9 @@ export class LocalProcessScriptExecutor implements ScriptExecutor {
412
414
  clearInterval(heartbeat);
413
415
  await terminateProcessGroup(spawned.pid);
414
416
  let stderr = await stderrPromise;
417
+ // The caller owns the status for pause/cancel/limits. On API shutdown,
418
+ // leaving it running lets the next supervisor replay the durable journal.
419
+ if (terminated) return { exitCode: processExitCode, stderr, terminated: true };
415
420
  try {
416
421
  if (protocolFailure) throw protocolFailure;
417
422
  if (processExitCode !== 0) {
@@ -450,6 +455,7 @@ export class LocalProcessScriptExecutor implements ScriptExecutor {
450
455
  startedAtMs: Date.now(),
451
456
  exited,
452
457
  terminate: async (signal = "SIGTERM") => {
458
+ terminated = true;
453
459
  built.abortInFlightSteps();
454
460
  if (signal === "SIGTERM") await terminateProcessGroup(spawned.pid);
455
461
  else if (signal === "SIGKILL") forceTerminateProcessGroup(spawned.pid);
@@ -58,7 +58,8 @@ export async function startScriptRunProcess(
58
58
  });
59
59
 
60
60
  execution.exited
61
- .then(async ({ exitCode, stderr }) => {
61
+ .then(async ({ exitCode, stderr, terminated }) => {
62
+ if (terminated) return;
62
63
  const current = await getScriptRun(run.id);
63
64
  if (current && current.status === "running") {
64
65
  if (exitCode !== 0) {
@@ -219,6 +219,8 @@ export const SDK_TOOL_NAME_MAP = {
219
219
  app_upsert: "app-upsert",
220
220
  page_create: "create_page",
221
221
  page_delete: "delete-page", // destructive
222
+ designSystem_get: "design-system-get",
223
+ designSystem_set: "design-system-set",
222
224
  metric_create: "create_metric",
223
225
 
224
226
  // ── human input ──
@@ -79,8 +79,13 @@ function bridgeRequestFor(name: string, args: unknown): BridgeRequest | null {
79
79
  case "memory_search":
80
80
  return { method: "POST", path: "/api/memory/search", body };
81
81
  case "memory_get": {
82
- const memoryId = typeof body.memoryId === "string" ? body.memoryId : undefined;
83
- if (!memoryId) throw new Error("memory_get requires string `memoryId`");
82
+ if (body.memoryId && body.id && body.memoryId !== body.id) {
83
+ throw new Error("memoryId and id must identify the same memory; supply only one.");
84
+ }
85
+ const memoryId = body.memoryId ?? body.id;
86
+ if (typeof memoryId !== "string" || !memoryId) {
87
+ throw new Error("Supply memoryId (or its alias id) from memory-search.");
88
+ }
84
89
  const getIntent = typeof body.intent === "string" ? body.intent : "script-sdk";
85
90
  return {
86
91
  method: "GET",
@@ -108,6 +113,11 @@ function bridgeRequestFor(name: string, args: unknown): BridgeRequest | null {
108
113
  }
109
114
 
110
115
  // ── tasks ──
116
+ // task_storeProgress deliberately has no REST shortcut: the store-progress
117
+ // MCP tool owns every completion field (attachments, citations, uiSpec,
118
+ // learning, persistMemory, chainedTaskId), and rebuilding its body by hand
119
+ // silently dropped the fields this switch forgot. Falls through to the
120
+ // generic MCP bridge below, like task_defer and the other lifecycle tools.
111
121
  case "task_list":
112
122
  return { method: "GET", path: appendQuery("/api/tasks", body) };
113
123
  case "task_get": {
@@ -115,27 +125,6 @@ function bridgeRequestFor(name: string, args: unknown): BridgeRequest | null {
115
125
  if (!taskId) throw new Error("task_get requires string `taskId`");
116
126
  return { method: "GET", path: `/api/tasks/${encodeURIComponent(taskId)}` };
117
127
  }
118
- case "task_storeProgress": {
119
- const taskId = typeof body.taskId === "string" ? body.taskId : undefined;
120
- if (!taskId) throw new Error("task_storeProgress requires string `taskId`");
121
- if (body.status === "completed" || body.status === "failed" || body.status === "skipped") {
122
- return {
123
- method: "POST",
124
- path: `/api/tasks/${encodeURIComponent(taskId)}/finish`,
125
- body: {
126
- status: body.status,
127
- output: body.output,
128
- failureReason: body.failureReason,
129
- force: body.force,
130
- },
131
- };
132
- }
133
- return {
134
- method: "POST",
135
- path: `/api/tasks/${encodeURIComponent(taskId)}/progress`,
136
- body: { progress: body.progress ?? "" },
137
- };
138
- }
139
128
  case "task_cancel": {
140
129
  const taskId = typeof body.taskId === "string" ? body.taskId : undefined;
141
130
  if (!taskId) throw new Error("task_cancel requires string `taskId`");
@@ -497,7 +497,7 @@ declare module "swarm-sdk" {
497
497
  source?: string;
498
498
  keyPrefix?: string;
499
499
  }): Promise<unknown>;
500
- memory_get(args: { memoryId: string; intent: string }): Promise<unknown>;
500
+ memory_get(args: { memoryId?: string; id?: string; intent: string }): Promise<unknown>;
501
501
  memory_rate(args: { id: string; useful: boolean; note?: string }): Promise<unknown>;
502
502
  // --- tasks ---
503
503
  task_list(args?: Record<string, unknown>): Promise<unknown>;
@@ -863,6 +863,7 @@ declare module "swarm-sdk" {
863
863
  agentId?: string;
864
864
  workflowId?: string;
865
865
  name?: string;
866
+ defaultThreadId?: string;
866
867
  }): Promise<unknown>;
867
868
  chat_unregisterChannel(args: {
868
869
  adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat";
@@ -1067,6 +1068,8 @@ declare module "swarm-sdk" {
1067
1068
  }): Promise<unknown>;
1068
1069
  page_create(args: Record<string, unknown>): Promise<unknown>;
1069
1070
  page_delete(args: { pageId?: string; slug?: string }): Promise<unknown>;
1071
+ designSystem_get(args?: Record<string, never>): Promise<unknown>;
1072
+ designSystem_set(args: Record<string, unknown>): Promise<unknown>;
1070
1073
  metric_create(args: Record<string, unknown>): Promise<unknown>;
1071
1074
 
1072
1075
  // --- human input ---
@@ -455,7 +455,7 @@ declare module "swarm-sdk" {
455
455
  source?: string;
456
456
  keyPrefix?: string;
457
457
  }): Promise<unknown>;
458
- memory_get(args: { memoryId: string; intent: string }): Promise<unknown>;
458
+ memory_get(args: { memoryId?: string; id?: string; intent: string }): Promise<unknown>;
459
459
  memory_rate(args: { id: string; useful: boolean; note?: string }): Promise<unknown>;
460
460
  // --- tasks ---
461
461
  task_list(args?: Record<string, unknown>): Promise<unknown>;
@@ -821,6 +821,7 @@ declare module "swarm-sdk" {
821
821
  agentId?: string;
822
822
  workflowId?: string;
823
823
  name?: string;
824
+ defaultThreadId?: string;
824
825
  }): Promise<unknown>;
825
826
  chat_unregisterChannel(args: {
826
827
  adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat";
@@ -1025,6 +1026,8 @@ declare module "swarm-sdk" {
1025
1026
  }): Promise<unknown>;
1026
1027
  page_create(args: Record<string, unknown>): Promise<unknown>;
1027
1028
  page_delete(args: { pageId?: string; slug?: string }): Promise<unknown>;
1029
+ designSystem_get(args?: Record<string, never>): Promise<unknown>;
1030
+ designSystem_set(args: Record<string, unknown>): Promise<unknown>;
1028
1031
  metric_create(args: Record<string, unknown>): Promise<unknown>;
1029
1032
 
1030
1033
  // --- human input ---
package/src/server.ts CHANGED
@@ -48,6 +48,7 @@ import { registerDbQueryTool } from "./tools/db-query";
48
48
  import { registerDeferTaskTool } from "./tools/defer-task";
49
49
  import { registerDeleteChannelTool } from "./tools/delete-channel";
50
50
  import { registerDeletePageTool } from "./tools/delete-page";
51
+ import { registerDesignSystemTools } from "./tools/design-system";
51
52
  import { registerExtensionActivateVersionTool } from "./tools/extension-activate-version";
52
53
  import { registerExtensionCatalogTool } from "./tools/extension-catalog";
53
54
  import { registerExtensionDeleteTool } from "./tools/extension-delete";
@@ -693,6 +694,7 @@ export async function createServer(
693
694
  registerAppUpsertTool(server);
694
695
  registerCreatePageTool(server);
695
696
  registerDeletePageTool(server);
697
+ registerDesignSystemTools(server);
696
698
  }
697
699
 
698
700
  // Metrics capability - time-series metrics (DB-backed, for dashboards).
@@ -5,6 +5,7 @@ import { slackContextKey } from "../tasks/context-key";
5
5
  import { createTaskWithSiblingAwareness } from "../tasks/sibling-awareness";
6
6
  import { runTaskUiAction, type TaskUiActionResult } from "../ui-spec/actions";
7
7
  import { UI_SPEC_ACTION_PREFIX } from "../utils/task-ui-spec";
8
+ import { registerApprovalActionHandlers } from "./approval-actions";
8
9
  import { buildCancelledBlocks, getTaskLink } from "./blocks";
9
10
  import { resolveSlackUserId } from "./enrich";
10
11
  import { EXTERNAL_CHANNEL_BLOCKED_REPLY, shouldBlockChannel } from "./external-channel";
@@ -64,6 +65,8 @@ async function postExternalChannelNotice(
64
65
  }
65
66
 
66
67
  export function registerActionHandlers(app: App): void {
68
+ registerApprovalActionHandlers(app);
69
+
67
70
  // "View Full Logs" — URL button, just ack (Slack opens the link automatically)
68
71
  app.action("view_task_logs", async ({ ack }) => {
69
72
  await ack();
@@ -0,0 +1,148 @@
1
+ import type { App } from "@slack/bolt";
2
+ import type { WebClient } from "@slack/web-api";
3
+ import { getApprovalRequestById } from "../be/db";
4
+ import { answerApprovalFromChat } from "../http/approval-chat-answer";
5
+ import {
6
+ type ApprovalQuestionLike,
7
+ INLINE_TEXT_MAX_LENGTH,
8
+ type InlineApprovalQuestion,
9
+ inlineApprovalChoices,
10
+ inlineApprovalQuestion,
11
+ } from "../workflows/approval-inline";
12
+ import { APPROVAL_ACTION_PREFIX } from "./approval-buttons";
13
+ import { EXTERNAL_CHANNEL_BLOCKED_REPLY, shouldBlockChannel } from "./external-channel";
14
+ import { ignoreSlackInbound, noteSlackInboundSideEffect } from "./inbound-dispatch";
15
+
16
+ const APPROVAL_MODAL_CALLBACK = "hitl_answer_modal";
17
+
18
+ interface ModalMetadata {
19
+ r: string;
20
+ c: string;
21
+ ch?: string;
22
+ }
23
+
24
+ function answerModal(
25
+ question: InlineApprovalQuestion,
26
+ metadata: ModalMetadata,
27
+ ): Record<string, unknown> {
28
+ const deny = question.type === "approval";
29
+ return {
30
+ type: "modal",
31
+ callback_id: APPROVAL_MODAL_CALLBACK,
32
+ private_metadata: JSON.stringify(metadata),
33
+ title: { type: "plain_text", text: deny ? "Deny" : "Answer" },
34
+ submit: { type: "plain_text", text: deny ? "Deny" : "Submit" },
35
+ close: { type: "plain_text", text: "Cancel" },
36
+ blocks: [
37
+ {
38
+ type: "input",
39
+ block_id: "answer",
40
+ optional: deny,
41
+ label: {
42
+ type: "plain_text",
43
+ text: deny ? "Reason (optional)" : question.label.slice(0, 2000) || "Answer",
44
+ },
45
+ element: {
46
+ type: "plain_text_input",
47
+ action_id: "text",
48
+ max_length: INLINE_TEXT_MAX_LENGTH,
49
+ },
50
+ },
51
+ ],
52
+ };
53
+ }
54
+
55
+ async function tellClicker(
56
+ client: WebClient,
57
+ channelId: string | undefined,
58
+ userId: string,
59
+ text: string,
60
+ ): Promise<void> {
61
+ if (!channelId) return;
62
+ try {
63
+ await client.chat.postEphemeral({ channel: channelId, user: userId, text });
64
+ } catch (error) {
65
+ console.error("[Slack] Failed to post approval button reply:", error);
66
+ }
67
+ }
68
+
69
+ async function answer(
70
+ client: WebClient,
71
+ input: {
72
+ requestId: string;
73
+ choice: string;
74
+ text?: string;
75
+ slackUserId: string;
76
+ channelId?: string;
77
+ },
78
+ ): Promise<void> {
79
+ noteSlackInboundSideEffect("approval_answer");
80
+ const outcome = await answerApprovalFromChat({
81
+ requestId: input.requestId,
82
+ choice: input.choice,
83
+ text: input.text,
84
+ identity: { kind: "slack", externalId: input.slackUserId },
85
+ });
86
+ if (outcome.kind !== "resolved") {
87
+ await tellClicker(client, input.channelId, input.slackUserId, outcome.message);
88
+ }
89
+ }
90
+
91
+ export function registerApprovalActionHandlers(app: App): void {
92
+ app.action(new RegExp(`^${APPROVAL_ACTION_PREFIX}`), async ({ ack, action, body, client }) => {
93
+ await ack();
94
+ if (action.type !== "button" || !("action_id" in action)) return;
95
+ const requestId = action.value;
96
+ const choice = action.action_id.slice(APPROVAL_ACTION_PREFIX.length);
97
+ if (!requestId || !choice) return ignoreSlackInbound("approval_action_malformed");
98
+
99
+ const channelId = "channel" in body ? body.channel?.id : undefined;
100
+ if (channelId && (await shouldBlockChannel(client, channelId))) {
101
+ await tellClicker(client, channelId, body.user.id, EXTERNAL_CHANNEL_BLOCKED_REPLY);
102
+ return ignoreSlackInbound("external_channel");
103
+ }
104
+
105
+ const request = await getApprovalRequestById(requestId);
106
+ const question = request
107
+ ? inlineApprovalQuestion(request.questions as ApprovalQuestionLike[])
108
+ : null;
109
+ const needsText = question
110
+ ? inlineApprovalChoices(question).find((c) => c.choice === choice)?.needsText
111
+ : undefined;
112
+ const triggerId = "trigger_id" in body ? body.trigger_id : undefined;
113
+ // A pending request opens the modal; anything else is answered now so a stale card catches up.
114
+ if (question && needsText && triggerId && request?.status === "pending") {
115
+ try {
116
+ await client.views.open({
117
+ trigger_id: triggerId,
118
+ // biome-ignore lint/suspicious/noExplicitAny: Block Kit objects
119
+ view: answerModal(question, { r: requestId, c: choice, ch: channelId }) as any,
120
+ });
121
+ } catch (error) {
122
+ console.error("[Slack] Failed to open the approval answer modal:", error);
123
+ await tellClicker(client, channelId, body.user.id, "Could not open the answer form.");
124
+ }
125
+ return;
126
+ }
127
+ await answer(client, { requestId, choice, slackUserId: body.user.id, channelId });
128
+ });
129
+
130
+ app.view(APPROVAL_MODAL_CALLBACK, async ({ ack, view, body, client }) => {
131
+ await ack();
132
+ let metadata: ModalMetadata;
133
+ try {
134
+ metadata = JSON.parse(view.private_metadata) as ModalMetadata;
135
+ } catch {
136
+ return ignoreSlackInbound("approval_modal_malformed");
137
+ }
138
+ if (!metadata.r || !metadata.c) return ignoreSlackInbound("approval_modal_malformed");
139
+ const text = view.state.values.answer?.text?.value ?? "";
140
+ await answer(client, {
141
+ requestId: metadata.r,
142
+ choice: metadata.c,
143
+ text,
144
+ slackUserId: body.user.id,
145
+ channelId: metadata.ch,
146
+ });
147
+ });
148
+ }
@@ -0,0 +1,28 @@
1
+ import { inlineApprovalChoices, inlineApprovalQuestion } from "../workflows/approval-inline";
2
+
3
+ /** Button `action_id` prefix; the rest is the `InlineChoice.choice`, the value the request id. */
4
+ export const APPROVAL_ACTION_PREFIX = "hitl_answer:";
5
+
6
+ /** Slack caps button text at 75 characters. */
7
+ function buttonText(label: string): string {
8
+ return label.length > 75 ? `${label.slice(0, 74)}…` : label;
9
+ }
10
+
11
+ /**
12
+ * The inline answer buttons for a pending approval card, or none when the
13
+ * request needs the dashboard (see `inlineApprovalQuestion`).
14
+ */
15
+ export function buildApprovalAnswerButtons(
16
+ requestId: string,
17
+ questions: Parameters<typeof inlineApprovalQuestion>[0],
18
+ ): Record<string, unknown>[] {
19
+ const question = inlineApprovalQuestion(questions);
20
+ if (!question) return [];
21
+ return inlineApprovalChoices(question).map((choice) => ({
22
+ type: "button",
23
+ action_id: `${APPROVAL_ACTION_PREFIX}${choice.choice}`,
24
+ text: { type: "plain_text", text: buttonText(choice.label) },
25
+ value: requestId,
26
+ ...(choice.style ? { style: choice.style } : {}),
27
+ }));
28
+ }