@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
@@ -455,8 +455,15 @@ 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>;
459
- memory_rate(args: { id: string; useful: boolean; note?: string }): Promise<unknown>;
458
+ memory_get(args: { memoryId?: string; id?: string; intent: string }): Promise<unknown>;
459
+ memory_rate(args: {
460
+ id?: string;
461
+ memoryId?: string;
462
+ useful: boolean;
463
+ note?: string;
464
+ taskId?: string;
465
+ referencesSource?: string;
466
+ }): Promise<unknown>;
460
467
  // --- tasks ---
461
468
  task_list(args?: Record<string, unknown>): Promise<unknown>;
462
469
  task_get(args: { taskId: string }): Promise<unknown>;
@@ -821,6 +828,7 @@ declare module "swarm-sdk" {
821
828
  agentId?: string;
822
829
  workflowId?: string;
823
830
  name?: string;
831
+ defaultThreadId?: string;
824
832
  }): Promise<unknown>;
825
833
  chat_unregisterChannel(args: {
826
834
  adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat";
@@ -1025,6 +1033,8 @@ declare module "swarm-sdk" {
1025
1033
  }): Promise<unknown>;
1026
1034
  page_create(args: Record<string, unknown>): Promise<unknown>;
1027
1035
  page_delete(args: { pageId?: string; slug?: string }): Promise<unknown>;
1036
+ designSystem_get(args?: Record<string, never>): Promise<unknown>;
1037
+ designSystem_set(args: Record<string, unknown>): Promise<unknown>;
1028
1038
  metric_create(args: Record<string, unknown>): Promise<unknown>;
1029
1039
 
1030
1040
  // --- 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();
@@ -252,7 +255,7 @@ export function registerActionHandlers(app: App): void {
252
255
  if (!task) return;
253
256
 
254
257
  // Cancel the task in DB
255
- const cancelled = await cancelTask(taskId, "Cancelled via Slack");
258
+ const cancelled = await cancelTask(taskId, "Cancelled via Slack", { statusKind: "user" });
256
259
  if (!cancelled) {
257
260
  // Task was already in a terminal state
258
261
  return;
@@ -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
+ }
@@ -63,6 +63,7 @@ import {
63
63
  splitSlackSectionText,
64
64
  } from "./blocks";
65
65
  import { buildAskClosure, type ClosureState, closureState } from "./closure";
66
+ import { getChannelExternality } from "./external-channel";
66
67
  import {
67
68
  completedStatusIcon,
68
69
  iconPrefix,
@@ -1179,6 +1180,121 @@ async function isSlackContinuation(task: AgentTask): Promise<boolean> {
1179
1180
  );
1180
1181
  }
1181
1182
 
1183
+ /** Lead review tasks the engine creates when a worker finishes or a session resumes. */
1184
+ const SLACK_LEAD_FOLLOW_UP_TYPES = new Set(["follow-up", "resume"]);
1185
+ /** Guards the ancestor walk against a corrupt parent cycle or a pathological chain. */
1186
+ const SLACK_ANCESTOR_WALK_LIMIT = 50;
1187
+
1188
+ /** True when `task`'s parent chain holds a task a person started in Slack. */
1189
+ async function hasSlackAskAncestor(
1190
+ task: AgentTask,
1191
+ threadTasks: readonly AgentTask[],
1192
+ ): Promise<boolean> {
1193
+ const byId = new Map(threadTasks.map((candidate) => [candidate.id, candidate]));
1194
+ const seen = new Set<string>([task.id]);
1195
+ let parentId = task.parentTaskId;
1196
+ while (parentId && !seen.has(parentId) && seen.size <= SLACK_ANCESTOR_WALK_LIMIT) {
1197
+ seen.add(parentId);
1198
+ const parent = byId.get(parentId) ?? (await getTaskById(parentId));
1199
+ if (!parent) return false;
1200
+ if (parent.source === "slack") return true;
1201
+ parentId = parent.parentTaskId;
1202
+ }
1203
+ return false;
1204
+ }
1205
+
1206
+ /**
1207
+ * A Lead follow-up (worker completion) or resume task in a tree a person
1208
+ * started in Slack is "eligible": its output is the answer the thread waits
1209
+ * for, so it gets an outcome card like the ask did. Before this, the thread
1210
+ * stayed silent until someone asked "status?". A Lead follow-up with Slack
1211
+ * context but no Slack ask in its parent chain is an "orphan": it posts
1212
+ * nothing, and its card is settled so the thread does not wait on it.
1213
+ */
1214
+ async function classifyLeadFollowUp(
1215
+ task: AgentTask,
1216
+ threadTasks: readonly AgentTask[],
1217
+ ): Promise<"none" | "eligible" | "orphan"> {
1218
+ if (
1219
+ task.source !== "system" ||
1220
+ !SLACK_LEAD_FOLLOW_UP_TYPES.has(task.taskType ?? "") ||
1221
+ !task.slackChannelId ||
1222
+ !task.slackThreadTs ||
1223
+ !task.agentId ||
1224
+ !(await getAgentById(task.agentId))?.isLead
1225
+ ) {
1226
+ return "none";
1227
+ }
1228
+ return (await hasSlackAskAncestor(task, threadTasks)) ? "eligible" : "orphan";
1229
+ }
1230
+
1231
+ /**
1232
+ * Settles a Lead follow-up's card as abandoned without posting anything, so
1233
+ * slackThreadHasOutcomeWork stops counting it and the thread can close.
1234
+ */
1235
+ async function settleLeadFollowUpWithoutCard(task: AgentTask, reason: string): Promise<void> {
1236
+ if (!task.slackChannelId || !task.slackThreadTs) return;
1237
+ // A bound card is a stream Slack already holds; it keeps its own bounded
1238
+ // recovery. A pending one has no bound message, so it is settled here.
1239
+ const card = await getSlackOutcomeMessage(task.id);
1240
+ if (card && !isPendingSlackMessage(card)) return;
1241
+ await reserveSlackMessage({
1242
+ contextKey:
1243
+ task.contextKey ??
1244
+ slackContextKey({ channelId: task.slackChannelId, threadTs: task.slackThreadTs }),
1245
+ channelId: task.slackChannelId,
1246
+ threadTs: task.slackThreadTs,
1247
+ kind: "outcome",
1248
+ taskId: task.id,
1249
+ });
1250
+ await abandonSlackOutcomeDelivery(task.id, reason);
1251
+ }
1252
+
1253
+ /**
1254
+ * Gates a new outcome card for a Lead follow-up; every other task passes.
1255
+ * No card when the Lead already answered with `slack-reply` (it would repeat
1256
+ * that answer), when the delegation child pass owns the card, or when Slack
1257
+ * does not confirm the channel is internal: a Slack Connect channel is a
1258
+ * customer's, and posting there needs a person's explicit yes. An external
1259
+ * verdict settles the card as abandoned so the thread can close.
1260
+ */
1261
+ async function mayPostLeadFollowUpCard(
1262
+ task: AgentTask,
1263
+ threadTasks: readonly AgentTask[],
1264
+ ownerAskId: ReadonlyMap<string, string>,
1265
+ delegationActivatedAt: string | null,
1266
+ ): Promise<boolean> {
1267
+ if (task.source !== "system" || !SLACK_LEAD_FOLLOW_UP_TYPES.has(task.taskType ?? "")) {
1268
+ return true;
1269
+ }
1270
+ if ((await getTaskById(task.id))?.slackReplySent ?? task.slackReplySent) {
1271
+ // A reservation left by a failed delivery would keep the thread open.
1272
+ if (await getSlackOutcomeMessage(task.id)) {
1273
+ await settleLeadFollowUpWithoutCard(task, "slack_reply_sent: Lead follow-up not posted");
1274
+ }
1275
+ return false;
1276
+ }
1277
+ const askId = ownerAskId.get(task.id);
1278
+ const ownerAsk = askId ? threadTasks.find((candidate) => candidate.id === askId) : undefined;
1279
+ if (
1280
+ delegationActivatedAt !== null &&
1281
+ ownerAsk &&
1282
+ ownerAsk.createdAt >= delegationActivatedAt &&
1283
+ isChildCardCandidate(task, delegationActivatedAt)
1284
+ ) {
1285
+ return false;
1286
+ }
1287
+ const app = getSlackApp();
1288
+ if (!app || !task.slackChannelId || !task.slackThreadTs) return false;
1289
+ const externality = await getChannelExternality(app.client, task.slackChannelId);
1290
+ if (externality === "external") {
1291
+ // "unknown" is not settled: it retries on the next tick.
1292
+ await settleLeadFollowUpWithoutCard(task, "external_channel: Lead follow-up not posted");
1293
+ return false;
1294
+ }
1295
+ return externality === "internal";
1296
+ }
1297
+
1182
1298
  /**
1183
1299
  * True when `task` is a candidate for its own child result card (plan
1184
1300
  * section 3.4, rules 1-4, 3, and part of rule 6). Callers still need the
@@ -1216,12 +1332,15 @@ export async function slackDelegationOwnsChildCard(task: AgentTask): Promise<boo
1216
1332
  return !!ownerAsk && ownerAsk.createdAt >= delegationActivatedAt;
1217
1333
  }
1218
1334
 
1219
- async function taskNeedsDirectOutcome(task: AgentTask, activatedAt: string): Promise<boolean> {
1220
- return (
1221
- ((task.source === "slack" && isAskOutcomeStatus(task.status)) ||
1222
- ((await isSlackContinuation(task)) && isOutcomeStatus(task.status))) &&
1223
- task.createdAt >= activatedAt
1224
- );
1335
+ async function taskNeedsDirectOutcome(
1336
+ task: AgentTask,
1337
+ activatedAt: string,
1338
+ leadFollowUp: "none" | "eligible" | "orphan",
1339
+ ): Promise<boolean> {
1340
+ if (task.createdAt < activatedAt) return false;
1341
+ if (task.source === "slack") return isAskOutcomeStatus(task.status);
1342
+ if (!isOutcomeStatus(task.status)) return false;
1343
+ return leadFollowUp === "eligible" || (await isSlackContinuation(task));
1225
1344
  }
1226
1345
 
1227
1346
  /**
@@ -2072,10 +2191,32 @@ async function processSlackThread(
2072
2191
 
2073
2192
  for (const task of tasks) {
2074
2193
  if (!isSlackRenderV2Enabled()) return "stop";
2075
- if (!(await taskNeedsDirectOutcome(task, activatedAt))) continue;
2194
+ const leadFollowUp = isOutcomeStatus(task.status)
2195
+ ? await classifyLeadFollowUp(task, tasks)
2196
+ : "none";
2197
+ if (
2198
+ leadFollowUp === "orphan" &&
2199
+ isOutcomeStatus(task.status) &&
2200
+ !task.slackReplySent &&
2201
+ task.createdAt >= activatedAt &&
2202
+ !endedBefore(task, outcomeWindow.finishedAfter)
2203
+ ) {
2204
+ // The reconcile SQL cannot walk the parent chain, so it counts this one.
2205
+ await settleLeadFollowUpWithoutCard(task, "no_slack_ask: Lead follow-up not posted");
2206
+ continue;
2207
+ }
2208
+ if (!(await taskNeedsDirectOutcome(task, activatedAt, leadFollowUp))) continue;
2076
2209
  const card = await getSlackOutcomeMessage(task.id);
2077
2210
  if (card && isSettledSlackMessage(card)) continue;
2078
2211
  if (await isAnsweredByDeferralCard(task, tasks)) continue;
2212
+ // A pending card has no bound Slack message, so its retry would create
2213
+ // the first one: it passes the same gate as a new card.
2214
+ if (
2215
+ (!card || isPendingSlackMessage(card)) &&
2216
+ !(await mayPostLeadFollowUpCard(task, tasks, ownerAskId, delegationActivatedAt))
2217
+ ) {
2218
+ continue;
2219
+ }
2079
2220
  const deferByClosure =
2080
2221
  task.source === "slack" &&
2081
2222
  delegationEnabled &&
@@ -229,8 +229,6 @@ describe("API drain with a real worker", () => {
229
229
 
230
230
  try {
231
231
  await waitForTask(taskId, (task) => task.status === "in_progress");
232
- // Give the runner a few ping iterations with the task in flight.
233
- await Bun.sleep(2_000);
234
232
 
235
233
  const signalledAt = Date.now();
236
234
  sut.process.kill("SIGTERM");
@@ -16,20 +16,8 @@ async function removeDb(): Promise<void> {
16
16
 
17
17
  afterEach(removeDb);
18
18
 
19
- type Row = {
20
- id: string;
21
- status: string;
22
- resolvedBy: string | null;
23
- resolvedAt: string | null;
24
- resolutionReason: string | null;
25
- };
26
-
27
- function readRows(db: Database): Row[] {
28
- return db
29
- .query<Row, []>(
30
- "SELECT id, status, resolvedBy, resolvedAt, resolutionReason FROM approval_requests ORDER BY id",
31
- )
32
- .all();
19
+ function readRows(db: Database) {
20
+ return db.query("SELECT * FROM approval_requests ORDER BY id").all();
33
21
  }
34
22
 
35
23
  describe("migration 166 approval auto-cancellation index", () => {
@@ -38,7 +26,7 @@ describe("migration 166 approval auto-cancellation index", () => {
38
26
  const db = new Database(DB_PATH, { create: true });
39
27
  try {
40
28
  runMigrations(db);
41
- // Roll the database back to the state before migration 166.
29
+ // Replay migration 166 on the current schema with its index removed.
42
30
  db.run("DROP INDEX idx_approval_requests_pending_created");
43
31
  db.run("DELETE FROM _migrations WHERE version = 166");
44
32
  db.run(`INSERT INTO approval_requests
@@ -73,13 +61,14 @@ describe("migration 166 approval auto-cancellation index", () => {
73
61
  ]),
74
62
  );
75
63
 
76
- const tableSql = db
64
+ const indexSql = db
77
65
  .query<{ sql: string }, []>(
78
- "SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'approval_requests'",
66
+ "SELECT sql FROM sqlite_master WHERE type = 'index' AND name = 'idx_approval_requests_pending_created'",
79
67
  )
80
68
  .get()?.sql;
81
- expect(tableSql).toContain("'cancelled'");
82
- expect(tableSql).toContain("'timeout'");
69
+ expect(indexSql?.replace(/\s+/g, " ").trim()).toBe(
70
+ "CREATE INDEX idx_approval_requests_pending_created ON approval_requests(createdAt) WHERE status = 'pending' AND expiresAt IS NULL",
71
+ );
83
72
 
84
73
  const insert = (id: string, status: string) =>
85
74
  db.run(
@@ -137,6 +137,7 @@ describe("resolved approval Slack card", () => {
137
137
  await settle(1);
138
138
 
139
139
  expect(updates).toHaveLength(1);
140
+ expect(posts).toHaveLength(0);
140
141
  const call = updates[0]!;
141
142
  expect(call.channel).toBe("C0CHAN");
142
143
  expect(call.ts).toBe("1700000000.000100");
@@ -153,14 +154,6 @@ describe("resolved approval Slack card", () => {
153
154
  expect(text).not.toContain("Approval Required");
154
155
  });
155
156
 
156
- test("rejected: header names the responder", async () => {
157
- const approval = await createPosted();
158
- await resolveApprovalRequest(approval.id, { status: "rejected", resolvedBy: "operator" });
159
- await settle(1);
160
- expect(updates).toHaveLength(1);
161
- expect(cardText(updates[0]!)).toContain("❌ *Rejected by operator*");
162
- });
163
-
164
157
  for (const status of ["approved", "rejected"] as const) {
165
158
  for (const identity of ["email", "name", "unknown", "missing"] as const) {
166
159
  test(`${status}: operator vote displays ${identity} claim`, async () => {
@@ -199,7 +192,7 @@ describe("resolved approval Slack card", () => {
199
192
  : `operator key (as ${user.name})`;
200
193
  expect(updates).toHaveLength(1);
201
194
  expect(cardText(updates[0]!)).toContain(
202
- `*${status === "approved" ? "Approved" : "Rejected"} by ${expected}*`,
195
+ `${status === "approved" ? "✅ *Approved" : "❌ *Rejected"} by ${expected}*`,
203
196
  );
204
197
  expect(resolved?.resolvedBy).toBe("operator");
205
198
  expect(resolved?.approvals?.[1]?.responder).toBe("operator");
@@ -391,12 +384,4 @@ describe("resolved approval Slack card", () => {
391
384
  expect(posts).toHaveLength(1);
392
385
  expect(posts[0]!).toMatchObject({ channel: botDm("U0NEW"), thread_ts: "1700000000.000200" });
393
386
  });
394
-
395
- test("a stored channelId or a channel target is edited in place", async () => {
396
- await resolveApprovalRequest((await createPosted()).id, { status: "approved" });
397
- await settle(1);
398
- expect(updates).toHaveLength(1);
399
- expect(updates[0]!.channel).toBe("C0CHAN");
400
- expect(posts).toHaveLength(0);
401
- });
402
387
  });