@desplega.ai/agent-swarm 2.9.1 → 2.10.0

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 (315) hide show
  1. package/dist/acp-adapter-bht22g3k.js +16 -0
  2. package/dist/{acp-targets-ny75x1qy.js → acp-targets-arrwv4f0.js} +6 -6
  3. package/dist/{actions-b9qgrmeq.js → actions-y0d2n1c2.js} +49 -28
  4. package/dist/{agent-fs-provision-b5dhdsbd.js → agent-fs-provision-tpj7sktd.js} +4 -4
  5. package/dist/{amp-adapter-vtax2c9s.js → amp-adapter-vmmnmw8d.js} +1 -1
  6. package/dist/{anthropic-messages-r5xf5hqw.js → anthropic-messages-zdca3gv1.js} +13 -13
  7. package/dist/{app-g2z15hax.js → app-wb7w45dq.js} +3 -3
  8. package/dist/{approval-notifications-yt13wp8r.js → approval-notifications-7mqr6vbd.js} +5 -5
  9. package/dist/{assistant-2cgfxsgk.js → assistant-gf60454p.js} +19 -19
  10. package/dist/{boot-args-schema-3gwy0f60.js → boot-args-schema-qxmd59sr.js} +1 -1
  11. package/dist/{boot-reembed-mywmyp4s.js → boot-reembed-5tmeskj2.js} +1 -1
  12. package/dist/{boot-reembed-92g7s5zp.js → boot-reembed-wb44vc3s.js} +1 -1
  13. package/dist/boot-scrub-sweep-25bxhnw4.js +9 -0
  14. package/dist/{boot-seeds-ce7rvgq1.js → boot-seeds-nj9za0vk.js} +4 -4
  15. package/dist/{claude-adapter-3m4q7735.js → claude-adapter-d3krpdyb.js} +5 -5
  16. package/dist/{claude-managed-setup-c217draw.js → claude-managed-setup-7y4pwd81.js} +1 -1
  17. package/dist/{claude-sdk-session-7fbqm51z.js → claude-sdk-session-d138zy0e.js} +5 -5
  18. package/dist/{cli-tvc4jag9.js → cli-01k6wpr9.js} +3 -3
  19. package/dist/{cli-2xs8tsf7.js → cli-124ntmf0.js} +42 -36
  20. package/dist/{cli-jm0hvmz2.js → cli-2rnd5j3t.js} +1 -1
  21. package/dist/{cli-32djehja.js → cli-2spnz7ye.js} +8 -8
  22. package/dist/{cli-2dq9yv8p.js → cli-2v2zdm0a.js} +1 -1
  23. package/dist/{cli-fkef327x.js → cli-3caf7pmg.js} +2 -2
  24. package/dist/{cli-mw620q3n.js → cli-3et6fmfe.js} +1 -1
  25. package/dist/{cli-h9yqfzx9.js → cli-3f8zbtqa.js} +3 -3
  26. package/dist/{cli-mhapr559.js → cli-43evxwj4.js} +1 -1
  27. package/dist/{cli-pyjn0qhk.js → cli-539h29es.js} +138 -21
  28. package/dist/{cli-bnqncekd.js → cli-5qhfv9rw.js} +2 -2
  29. package/dist/{cli-p4kckx1z.js → cli-6037prsx.js} +6 -6
  30. package/dist/{cli-zr6qy15y.js → cli-6cwr32fe.js} +17 -17
  31. package/dist/{cli-1jykg0py.js → cli-7r162fxe.js} +22 -15
  32. package/dist/{cli-sn650d7x.js → cli-8st34zhr.js} +20 -10
  33. package/dist/{cli-rq5rpv6k.js → cli-91pkxres.js} +1 -1
  34. package/dist/{cli-m7zvgt57.js → cli-9fjr27ez.js} +10 -10
  35. package/dist/{cli-f8x9drqr.js → cli-aw83sr40.js} +19 -5
  36. package/dist/{cli-jkw6ptfw.js → cli-cc93xzes.js} +5 -5
  37. package/dist/{cli-gfy38pvt.js → cli-fcfbct2j.js} +5 -5
  38. package/dist/{cli-nafvvsp8.js → cli-fq2rr3jb.js} +5 -5
  39. package/dist/{boot-scrub-sweep-7dkdzqxx.js → cli-had1p04a.js} +8 -9
  40. package/dist/{cli-bg63qmsx.js → cli-j6te8keb.js} +4 -4
  41. package/dist/{cli-br0924pw.js → cli-jrbq4djp.js} +1 -1
  42. package/dist/{cli-kxx4k2jw.js → cli-k3q2va86.js} +2 -2
  43. package/dist/{cli-jaw5v1sy.js → cli-k5yewqgd.js} +3 -3
  44. package/dist/cli-kbtzfrxj.js +404 -0
  45. package/dist/{cli-td9tb872.js → cli-m9cvf7vs.js} +7 -7
  46. package/dist/{cli-f3jyzq4g.js → cli-md50mj0r.js} +2 -2
  47. package/dist/{cli-xag7btpe.js → cli-mk7c5ac4.js} +1 -1
  48. package/dist/cli-mys27d03.js +321 -0
  49. package/dist/{cli-nbt14he0.js → cli-nstkanmx.js} +5 -5
  50. package/dist/{cli-wn13hhdt.js → cli-nv4xsvmk.js} +4 -4
  51. package/dist/{cli-vyff45ve.js → cli-p0c3vtch.js} +2 -2
  52. package/dist/{cli-2czxfnvj.js → cli-p0n7b5rz.js} +662 -93
  53. package/dist/{cli-j7svy295.js → cli-q5srsxq2.js} +12 -12
  54. package/dist/{cli-vt89089n.js → cli-qrta34nb.js} +4 -4
  55. package/dist/{cli-ysvspf5e.js → cli-qx4f057j.js} +2 -2
  56. package/dist/{cli-zh0e5x7p.js → cli-s1khw52h.js} +11 -11
  57. package/dist/{cli-mkwkwq81.js → cli-s1zqk1aj.js} +18 -11
  58. package/dist/{cli-f9gz2vyj.js → cli-sb4426be.js} +7 -7
  59. package/dist/{cli-dgs10ttj.js → cli-th1dkc2v.js} +1 -1
  60. package/dist/{cli-3j873zxq.js → cli-tr27kwyg.js} +2 -2
  61. package/dist/{cli-6945ywhr.js → cli-tvgqesec.js} +6 -4
  62. package/dist/{cli-fjggej24.js → cli-v46zsvqk.js} +1 -1
  63. package/dist/{cli-67mwzr35.js → cli-v8z0yga9.js} +4 -4
  64. package/dist/{cli-pb2ay3sh.js → cli-vfqvrd82.js} +5 -5
  65. package/dist/{cli-fh97xn30.js → cli-vq2eg24x.js} +2 -2
  66. package/dist/{cli-v57d7fmm.js → cli-vsw91x06.js} +23 -22
  67. package/dist/{cli-2yjj3e31.js → cli-w1q68d8x.js} +9 -7
  68. package/dist/{cli-y2ewxhth.js → cli-wafmk3fn.js} +10 -10
  69. package/dist/{cli-ctx0b85j.js → cli-wwp1bd3n.js} +257 -101
  70. package/dist/{cli-bkjdknnp.js → cli-y4ccxtz5.js} +37 -5
  71. package/dist/{cli-w4n323t3.js → cli-y8p78ekx.js} +7 -7
  72. package/dist/{cli-8zh9nrew.js → cli-z0m452jr.js} +1 -1
  73. package/dist/{cli-mjw0yf82.js → cli-zeh2mhkg.js} +1 -1
  74. package/dist/{cli-jwampxxq.js → cli-zk7v5s89.js} +2 -2
  75. package/dist/cli.js +16 -16
  76. package/dist/{cloudflare-workers-ai-system-one-9y1zx3pt.js → cloudflare-workers-ai-system-one-4aysy6rh.js} +2 -2
  77. package/dist/{codex-adapter-n656pvb8.js → codex-adapter-exfdbj73.js} +4 -4
  78. package/dist/{codex-session-runner-p0fbv5y9.js → codex-session-runner-xhznc4g3.js} +4 -4
  79. package/dist/{commands-gwea8z5p.js → commands-d8g349v4.js} +3 -3
  80. package/dist/{controller-t67c3grh.js → controller-mwgdmb8y.js} +3 -3
  81. package/dist/{controllers-connect-ks155r0h.js → controllers-connect-5v7qx04j.js} +19 -19
  82. package/dist/core-sxy4epp2.js +38 -0
  83. package/dist/{cursor-adapter-ygwrtmkv.js → cursor-adapter-p2q5h35d.js} +1 -1
  84. package/dist/{db-rb2xqdb1.js → db-qpganbeb.js} +3 -3
  85. package/dist/{db-kpmx06s9.js → db-wcw0b2j8.js} +2 -2
  86. package/dist/{dispatcher-31sm0ej2.js → dispatcher-8d8s49yz.js} +17 -17
  87. package/dist/{dsh-adapter-qyxh0w31.js → dsh-adapter-me0twn13.js} +1 -1
  88. package/dist/{easter-egg-3d-00wjscn6.js → easter-egg-3d-wv7w5ty6.js} +1 -1
  89. package/dist/{embedding-space-qhw4g68n.js → embedding-space-e48xchqa.js} +6 -6
  90. package/dist/{embeddings-zdv9ke6x.js → embeddings-tgq2afbq.js} +1 -1
  91. package/dist/{execute-zna8wwr7.js → execute-8rhwrk7f.js} +1 -1
  92. package/dist/{external-channel-1ac6t56s.js → external-channel-8bt3j2pm.js} +2 -2
  93. package/dist/{fx-adapter-sk7n0fzc.js → fx-adapter-adtdb3jb.js} +8 -8
  94. package/dist/{grok-adapter-sjbcm5ew.js → grok-adapter-accnn9km.js} +8 -8
  95. package/dist/handlers-1x77561e.js +35 -0
  96. package/dist/{heartbeat-2f6z4kdx.js → heartbeat-x0056ra5.js} +20 -20
  97. package/dist/{hook-w1skzaqc.js → hook-a7vmn2st.js} +4 -4
  98. package/dist/{hook-8y0gvtp1.js → hook-mrd2ayxv.js} +5 -5
  99. package/dist/{http-wghxvpef.js → http-ym9c5svp.js} +676 -273
  100. package/dist/{index-s71ez27v.js → index-01ns1pkw.js} +1 -1
  101. package/dist/index-48qzcqzj.js +35 -0
  102. package/dist/{index-9zkchs9t.js → index-ny60jcat.js} +186 -14
  103. package/dist/{index-rv89fvzf.js → index-p46tvwtx.js} +21 -21
  104. package/dist/index-rkvaambe.js +36 -0
  105. package/dist/{index-8zn8nxn5.js → index-x6azjwm8.js} +1 -1
  106. package/dist/{index-25pvya7q.js → index-xj1mq27m.js} +17 -17
  107. package/dist/k8s-m56sw868.js +217 -0
  108. package/dist/{keepalive-sh02349h.js → keepalive-7yxg8z4c.js} +3 -3
  109. package/dist/lead-enzn86bz.js +74 -0
  110. package/dist/{maintenance-yj0dcjja.js → maintenance-6tefxmk1.js} +1 -1
  111. package/dist/{oauth-refresh-sweep-d9xedk66.js → oauth-refresh-sweep-70cavc3a.js} +2 -2
  112. package/dist/{onboard-dpgjn03r.js → onboard-fja65z08.js} +5 -5
  113. package/dist/{openai-decisions-q3hh60wr.js → openai-decisions-ytp6w6xh.js} +1 -1
  114. package/dist/{opencode-adapter-2d31cpjc.js → opencode-adapter-hakkm7yh.js} +5 -5
  115. package/dist/{otel-impl-1skarpfq.js → otel-impl-7zhnt6gj.js} +1 -1
  116. package/dist/{pending-bfmxtx0g.js → pending-h01yzpx4.js} +18 -18
  117. package/dist/{pi-mono-adapter-gvppnasy.js → pi-mono-adapter-f52hz743.js} +6 -6
  118. package/dist/{pricing-refresh-c6b325mk.js → pricing-refresh-fzxvk2zf.js} +2 -2
  119. package/dist/{rbac-roles-h80qbdbs.js → rbac-roles-9v6vhgbs.js} +3 -3
  120. package/dist/{rbac-roles-zfcx68tx.js → rbac-roles-hfgh8sba.js} +2 -2
  121. package/dist/{render-v2-nx20t3rb.js → render-v2-1rgspxzf.js} +3 -3
  122. package/dist/{resume-5ep8agan.js → resume-tqy61x24.js} +7 -7
  123. package/dist/{runtime-r3pj4mce.js → runtime-exkxyx5f.js} +1 -1
  124. package/dist/{session-access-n7p3m15b.js → session-access-3act7vt4.js} +4 -4
  125. package/dist/{session-source-backfill-v8mt0zwn.js → session-source-backfill-82qe7fqq.js} +2 -2
  126. package/dist/{setup-z1psaqhe.js → setup-ry1vfdef.js} +1 -1
  127. package/dist/thread-buffer-3x93yexa.js +38 -0
  128. package/dist/{typesafe-system-one-f2en2knd.js → typesafe-system-one-vcfj2ak8.js} +2 -2
  129. package/dist/user-merge-jobs-bx6bf7db.js +22 -0
  130. package/dist/{virtual-modules-rrbjdpxn.js → virtual-modules-s0rjzcqq.js} +3 -3
  131. package/dist/{work-objects-4aghh73z.js → work-objects-z2e5tv03.js} +20 -20
  132. package/dist/{worker-follow-up-166zmex1.js → worker-follow-up-y3xeg89w.js} +17 -17
  133. package/dist/worker-zfcv2wbf.js +74 -0
  134. package/openapi.json +1630 -388
  135. package/package.json +3 -3
  136. package/src/be/boot-seeds.ts +7 -1
  137. package/src/be/db/model-groups.ts +238 -0
  138. package/src/be/db/model-profiles.ts +26 -8
  139. package/src/be/db/session-costs.ts +8 -2
  140. package/src/be/db/tasks/read.ts +3 -2
  141. package/src/be/db/tasks/write.ts +2 -1
  142. package/src/be/db/user-references.ts +75 -0
  143. package/src/be/db/users/references.ts +185 -0
  144. package/src/be/db-client.ts +70 -19
  145. package/src/be/db.ts +32 -57
  146. package/src/be/key-window-usage.ts +1 -0
  147. package/src/be/memory/demotion-evidence.ts +34 -0
  148. package/src/be/memory/reranker.ts +34 -12
  149. package/src/be/memory/review-recall-filter.ts +83 -0
  150. package/src/be/memory/search-candidates.ts +19 -6
  151. package/src/be/memory/types.ts +11 -0
  152. package/src/be/migrations/312_task_ui_action_runs_repeatable.sql +6 -0
  153. package/src/be/migrations/314_model_groups.sql +85 -0
  154. package/src/be/migrations/318_superseded_workflow_cut_backfill.sql +22 -0
  155. package/src/be/migrations/319_user_fk_indexes.sql +153 -0
  156. package/src/be/migrations/320_session_costs_kind.sql +4 -0
  157. package/src/be/migrations/321_user_merge_jobs.sql +52 -0
  158. package/src/be/pricing-normalize.ts +2 -0
  159. package/src/be/rbac-roles.ts +6 -4
  160. package/src/be/runtime-pools/db.ts +20 -5
  161. package/src/be/runtime-pools/supervisor.ts +15 -1
  162. package/src/be/scripts/db.ts +11 -0
  163. package/src/be/scripts/typecheck.ts +2 -0
  164. package/src/be/seed-model-groups.ts +86 -0
  165. package/src/be/seed-model-profiles.ts +20 -13
  166. package/src/be/seed-scripts/catalog/dreaming-gather.ts +165 -1
  167. package/src/be/swarm-config-guard.ts +34 -0
  168. package/src/be/task-ui-spec.ts +102 -1
  169. package/src/be/user-merge-jobs.ts +564 -0
  170. package/src/be/users.ts +41 -23
  171. package/src/commands/onboard/agent-fs-version.ts +1 -1
  172. package/src/commands/onboard/compose-generator.ts +1 -1
  173. package/src/commands/onboard/env-generator.ts +1 -1
  174. package/src/commands/provider-credentials.ts +1 -1
  175. package/src/extensions/contract-types.generated.ts +1 -1
  176. package/src/extensions/contract.ts +15 -0
  177. package/src/extensions/dispatcher.ts +14 -4
  178. package/src/github/handlers.ts +57 -0
  179. package/src/github/types.ts +4 -0
  180. package/src/http/all-routes.ts +2 -0
  181. package/src/http/approval-requests.ts +5 -1
  182. package/src/http/auth.ts +3 -1
  183. package/src/http/config.ts +34 -1
  184. package/src/http/index.ts +13 -0
  185. package/src/http/memory.ts +19 -6
  186. package/src/http/model-groups.ts +277 -0
  187. package/src/http/model-profiles.ts +30 -13
  188. package/src/http/tasks.ts +41 -6
  189. package/src/http/tool-hooks.ts +140 -0
  190. package/src/http/users.ts +142 -19
  191. package/src/http/workflows.ts +19 -1
  192. package/src/integrations/chat-sdk/inbound.ts +8 -2
  193. package/src/integrations/chat-sdk/limits.ts +8 -3
  194. package/src/providers/acp-targets.ts +2 -2
  195. package/src/providers/amp-adapter.ts +1 -1
  196. package/src/providers/pricing-sources.md +9 -0
  197. package/src/rbac/legacy-policy.ts +1 -0
  198. package/src/rbac/permissions.ts +5 -0
  199. package/src/runtime-providers/index.ts +7 -5
  200. package/src/runtime-providers/k8s.ts +250 -0
  201. package/src/scripts-runtime/types/stdlib.d.ts +2 -0
  202. package/src/scripts-runtime/types/swarm-extension.d.ts +16 -1
  203. package/src/scripts-runtime/types/swarm-sdk.d.ts +2 -0
  204. package/src/slack/actions.ts +33 -10
  205. package/src/slack/blocks.ts +23 -2
  206. package/src/slack/render-v2.ts +47 -0
  207. package/src/tests/acp-adapter.test.ts +26 -0
  208. package/src/tests/chat-sdk-relay.test.ts +21 -1
  209. package/src/tests/check-pr-body.test.ts +43 -0
  210. package/src/tests/credential-check.test.ts +14 -6
  211. package/src/tests/db-client.test.ts +146 -0
  212. package/src/tests/deploy-guard.test.ts +7 -7
  213. package/src/tests/deploy-select.test.ts +83 -0
  214. package/src/tests/dreaming-gather-corrections.test.ts +467 -0
  215. package/src/tests/event-loop-lag.test.ts +9 -7
  216. package/src/tests/fixtures/extensions/native-tool-recorder/hooks.ts +26 -0
  217. package/src/tests/fixtures/extensions/native-tool-recorder/manifest.json +10 -0
  218. package/src/tests/fixtures/onboard/content.compose.yml.txt +1 -1
  219. package/src/tests/fixtures/onboard/content.env.txt +1 -1
  220. package/src/tests/fixtures/onboard/dev.compose.yml.txt +1 -1
  221. package/src/tests/fixtures/onboard/dev.env.txt +1 -1
  222. package/src/tests/fixtures/onboard/full-all.compose.yml.txt +1 -1
  223. package/src/tests/fixtures/onboard/full-all.env.txt +1 -1
  224. package/src/tests/fixtures/onboard/full.compose.yml.txt +1 -1
  225. package/src/tests/fixtures/onboard/full.env.txt +1 -1
  226. package/src/tests/fixtures/onboard/research.compose.yml.txt +1 -1
  227. package/src/tests/fixtures/onboard/research.env.txt +1 -1
  228. package/src/tests/fixtures/onboard/solo.compose.yml.txt +1 -1
  229. package/src/tests/fixtures/onboard/solo.env.txt +1 -1
  230. package/src/tests/github-event-filter.test.ts +8 -0
  231. package/src/tests/github-handlers-inline-comments.test.ts +2 -0
  232. package/src/tests/github-handlers-reactions.test.ts +4 -0
  233. package/src/tests/github-handlers.test.ts +3 -0
  234. package/src/tests/github-sender-trust.test.ts +223 -0
  235. package/src/tests/http-users.test.ts +142 -41
  236. package/src/tests/k8s-pool-smoke.test.ts +190 -0
  237. package/src/tests/key-window-usage.test.ts +15 -0
  238. package/src/tests/memory-rater-store.test.ts +35 -1
  239. package/src/tests/memory-reranker.test.ts +39 -4
  240. package/src/tests/memory-review-recall-filter.test.ts +205 -0
  241. package/src/tests/migration-318-superseded-workflow-cut-backfill.test.ts +74 -0
  242. package/src/tests/model-groups-api.test.ts +415 -0
  243. package/src/tests/model-profiles-api.test.ts +1 -0
  244. package/src/tests/operator-granted-credentials.test.ts +7 -2
  245. package/src/tests/operator-granted-role-wire.test.ts +2 -1
  246. package/src/tests/rbac-engine.test.ts +1 -0
  247. package/src/tests/runtime-k8s-pools.test.ts +142 -0
  248. package/src/tests/runtime-pools-db.test.ts +42 -2
  249. package/src/tests/runtime-pools-http.test.ts +47 -2
  250. package/src/tests/runtime-provider-registration.test.ts +5 -14
  251. package/src/tests/runtime-providers-k8s.test.ts +303 -0
  252. package/src/tests/script-connections.test.ts +13 -1
  253. package/src/tests/short-id.test.ts +23 -0
  254. package/src/tests/slack-blocks.test.ts +69 -0
  255. package/src/tests/slack-render-v2.test.ts +54 -0
  256. package/src/tests/spec-base-url.test.ts +13 -1
  257. package/src/tests/system-one-decide-session-cost.test.ts +196 -0
  258. package/src/tests/task-ui-action-route.test.ts +59 -1
  259. package/src/tests/task-ui-script-actions.test.ts +517 -0
  260. package/src/tests/tool-hooks-http.test.ts +187 -0
  261. package/src/tests/ui-spec-script-actions-config.test.ts +196 -0
  262. package/src/tests/user-delete-perf.test.ts +321 -0
  263. package/src/tests/user-merge-jobs.test.ts +680 -0
  264. package/src/tests/vcs-provider.test.ts +25 -5
  265. package/src/tests/vendored-openapi.test.ts +13 -1
  266. package/src/tests/workflow-agent-task-retry.test.ts +62 -0
  267. package/src/tests/workflow-foreach-supersede-retry.test.ts +10 -0
  268. package/src/tests/workflow-http-v2.test.ts +27 -0
  269. package/src/tests/workflow-replay.test.ts +10 -1
  270. package/src/tests/workflow-triggers-v2.test.ts +128 -0
  271. package/src/tests/workflow-wait-event.test.ts +109 -1
  272. package/src/tools/memory-search.ts +14 -3
  273. package/src/tools/store-progress.ts +26 -26
  274. package/src/tools/swarm-config/delete-config.ts +12 -1
  275. package/src/tools/swarm-config/set-config.ts +8 -0
  276. package/src/tools/system-one-decide.ts +113 -3
  277. package/src/tools/utils.ts +4 -1
  278. package/src/tools/workflows/create-workflow.ts +2 -0
  279. package/src/tools/workflows/update-workflow.ts +3 -1
  280. package/src/types.ts +86 -2
  281. package/src/ui-spec/actions.ts +30 -4
  282. package/src/ui-spec/schema.ts +38 -0
  283. package/src/ui-spec/script-actions.ts +340 -0
  284. package/src/ui-spec/script-allowlist.ts +48 -0
  285. package/src/utils/short-id.ts +20 -14
  286. package/src/utils/task-ui-spec.ts +16 -4
  287. package/src/vcs/index.ts +12 -2
  288. package/src/workflows/executors/system-one-decision.ts +2 -2
  289. package/src/workflows/resume.ts +3 -2
  290. package/src/workflows/task-step-routing.ts +30 -10
  291. package/src/workflows/triggers.ts +35 -3
  292. package/templates/extensions/manifest.schema.json +13 -0
  293. package/templates/skills/swarm-docs/content.md +2 -0
  294. package/templates/skills/ui-spec/content.md +7 -1
  295. package/templates/workflows/dreaming/content.md +1 -1
  296. package/dist/acp-adapter-g909b5hw.js +0 -16
  297. package/dist/cli-b91nz213.js +0 -93
  298. package/dist/handlers-yzy0c87x.js +0 -35
  299. package/dist/index-2t4859r5.js +0 -35
  300. package/dist/index-cxca2t8y.js +0 -36
  301. package/dist/lead-gk4h5eg7.js +0 -74
  302. package/dist/thread-buffer-a1re2r9r.js +0 -38
  303. package/dist/worker-3dyyb8ev.js +0 -74
  304. package/dist/{azure-openai-responses-590s1eea.js → azure-openai-responses-b3y7fz36.js} +8 -8
  305. package/dist/{cli-m7c2380k.js → cli-3aaeb78m.js} +4 -4
  306. package/dist/{cli-g0vv9dg4.js → cli-8y43jx2r.js} +8 -8
  307. package/dist/{cli-m0cy2vyf.js → cli-k6nejceb.js} +4 -4
  308. package/dist/{google-generative-ai-maq6c9bf.js → google-generative-ai-bh0djqjp.js} +4 -4
  309. package/dist/{google-vertex-2jgsw2nb.js → google-vertex-prjbw8dj.js} +8 -8
  310. package/dist/{mistral-conversations-0c30em7t.js → mistral-conversations-tm2vd4gc.js} +8 -8
  311. package/dist/{node-dqm4xgxw.js → node-2wfcey7d.js} +0 -0
  312. package/dist/{openai-codex-responses-bkcd8pjj.js → openai-codex-responses-sxjv60xx.js} +4 -4
  313. package/dist/{openai-completions-f3n69rep.js → openai-completions-0c7qnhsx.js} +20 -20
  314. package/dist/{openai-responses-gbh0wfqe.js → openai-responses-a7h29chp.js} +15 -15
  315. package/dist/{pi-messages-zebyt7gb.js → pi-messages-2j0fpqwq.js} +5 -5
@@ -0,0 +1,340 @@
1
+ import { createLogEntry, getDbClient, getSwarmConfigs } from "../be/db";
2
+ import { getGlobalScriptContentHashes, getScript } from "../be/scripts/db";
3
+ import { runSavedScriptAsAgent } from "../be/scripts/run-saved";
4
+ import {
5
+ acquireTaskUiScriptActionRun,
6
+ finishTaskUiScriptActionRun,
7
+ getTaskUiSpec,
8
+ type TaskUiActionSurface,
9
+ upsertTaskUiSpec,
10
+ } from "../be/task-ui-spec";
11
+ import type { AgentTask, ScriptRecord } from "../types";
12
+ import { isEnvFlagEnabled } from "../utils/env-flag";
13
+ import { scrubSecrets } from "../utils/secret-scrubber";
14
+ import {
15
+ TASK_UI_SPEC_UPDATED_EVENT,
16
+ type TaskUiSpec,
17
+ type TaskUiSpecAction,
18
+ UI_SPEC_SCRIPT_ARGS_MAX_BYTES,
19
+ } from "../utils/task-ui-spec";
20
+ import { workflowEventBus } from "../workflows/event-bus";
21
+ import { validateJsonSchema } from "../workflows/json-schema-validator";
22
+ import type { TaskUiActionResult } from "./actions";
23
+ import { TaskUiSpecInputSchema } from "./schema";
24
+ import { parseScriptActionAllowlist, UI_SPEC_SCRIPT_ACTIONS_KEY } from "./script-allowlist";
25
+ import { validateTaskUiSpec } from "./validate";
26
+
27
+ /** The script's wall clock. The lease adds a margin, so a crashed run frees itself. */
28
+ export const UI_SPEC_SCRIPT_ACTION_TIMEOUT_MS = 30_000;
29
+ export const UI_SPEC_SCRIPT_ACTION_LEASE_MS = UI_SPEC_SCRIPT_ACTION_TIMEOUT_MS + 15_000;
30
+ /** Minimum gap between two runs of one action on one task. */
31
+ export const UI_SPEC_SCRIPT_ACTION_COOLDOWN_MS = 30_000;
32
+
33
+ type ScriptAction = Extract<TaskUiSpecAction, { kind: "script" }>;
34
+
35
+ type ResolvedScriptAction =
36
+ | { ok: true; script: ScriptRecord }
37
+ | { ok: false; reason: "not_allowlisted" | "script_changed" | "missing"; issue: string };
38
+
39
+ /**
40
+ * The live allowlist. The stored global row is read from the DB on every call,
41
+ * so a pin removed through any API process disarms clicks in every process
42
+ * sharing the DB, not only the one whose `process.env` was reloaded. With no
43
+ * row, the deployment env value, never a stale injected copy of a deleted row.
44
+ */
45
+ async function readScriptActionAllowlist(): Promise<string | undefined> {
46
+ const [row] = await getSwarmConfigs({ scope: "global", key: UI_SPEC_SCRIPT_ACTIONS_KEY });
47
+ if (row) return row.value;
48
+ // Lazy: http/core reaches slack, which imports the ui-spec action path.
49
+ const { getDeploymentEnvValue } = await import("../http/core");
50
+ return getDeploymentEnvValue(UI_SPEC_SCRIPT_ACTIONS_KEY);
51
+ }
52
+
53
+ /**
54
+ * The trust checks of one `script` action, at write time and again at click
55
+ * time: the name is pinned in UI_SPEC_SCRIPT_ACTIONS, a global script with
56
+ * that name exists, and its current contentHash matches a pin. A script edit
57
+ * disarms its cards until a human re-pins it.
58
+ */
59
+ type AllowlistPin = ReturnType<typeof parseScriptActionAllowlist>["pins"][number];
60
+
61
+ /** Per-call lookups, so a uiSpec with many actions reads the allowlist once and each script once. */
62
+ interface ScriptActionLookups {
63
+ allPins: AllowlistPin[];
64
+ scripts: Map<string, Promise<ScriptRecord | null>>;
65
+ }
66
+
67
+ async function loadScriptActionLookups(): Promise<ScriptActionLookups> {
68
+ return {
69
+ allPins: parseScriptActionAllowlist(await readScriptActionAllowlist()).pins,
70
+ scripts: new Map(),
71
+ };
72
+ }
73
+
74
+ export async function resolveScriptAction(
75
+ actionId: string,
76
+ action: ScriptAction,
77
+ lookups?: ScriptActionLookups,
78
+ ): Promise<ResolvedScriptAction> {
79
+ const { allPins, scripts } = lookups ?? (await loadScriptActionLookups());
80
+ const pins = allPins.filter((pin) => pin.name === action.script);
81
+ if (pins.length === 0) {
82
+ return {
83
+ ok: false,
84
+ reason: "not_allowlisted",
85
+ issue: `Action "${actionId}" runs script "${action.script}", which is not allowlisted in UI_SPEC_SCRIPT_ACTIONS.`,
86
+ };
87
+ }
88
+ let lookup = scripts.get(action.script);
89
+ if (!lookup) {
90
+ lookup = getScript({ name: action.script, scope: "global" });
91
+ scripts.set(action.script, lookup);
92
+ }
93
+ const script = await lookup;
94
+ if (!script) {
95
+ return {
96
+ ok: false,
97
+ reason: "missing",
98
+ issue: `Action "${actionId}" runs script "${action.script}", which is not a global script.`,
99
+ };
100
+ }
101
+ if (!pins.some((pin) => script.contentHash.toLowerCase().startsWith(pin.hashPrefix))) {
102
+ return {
103
+ ok: false,
104
+ reason: "script_changed",
105
+ issue: `Action "${actionId}": script "${action.script}" changed since it was allowlisted (contentHash ${script.contentHash.slice(0, 12)}). A human must re-pin it in UI_SPEC_SCRIPT_ACTIONS.`,
106
+ };
107
+ }
108
+ return { ok: true, script };
109
+ }
110
+
111
+ function argsIssue(actionId: string, action: ScriptAction, script: ScriptRecord): string | null {
112
+ const args = action.args ?? {};
113
+ const bytes = new TextEncoder().encode(JSON.stringify(args)).length;
114
+ if (bytes > UI_SPEC_SCRIPT_ARGS_MAX_BYTES) {
115
+ return `Action "${actionId}" args are ${bytes} bytes; the limit is ${UI_SPEC_SCRIPT_ARGS_MAX_BYTES}.`;
116
+ }
117
+ if (!script.argsJsonSchema) return null;
118
+ let schema: Record<string, unknown>;
119
+ try {
120
+ schema = JSON.parse(script.argsJsonSchema) as Record<string, unknown>;
121
+ } catch {
122
+ return `Action "${actionId}": script "${script.name}" has an unreadable argsJsonSchema.`;
123
+ }
124
+ const errors = validateJsonSchema(schema, args);
125
+ return errors.length > 0
126
+ ? `Action "${actionId}" args do not match the script's argsJsonSchema: ${errors[0]}`
127
+ : null;
128
+ }
129
+
130
+ /**
131
+ * Write-time issues of every `script` action in `actions`. Empty when all pass.
132
+ * Reads the allowlist once and each named script once. store-progress calls
133
+ * it before its write transaction, then re-checks only the pins inside it
134
+ * with `scriptActionPinIssues`.
135
+ */
136
+ export async function scriptActionIssues(
137
+ actions: Record<string, TaskUiSpecAction> | undefined,
138
+ ): Promise<string[]> {
139
+ const issues: string[] = [];
140
+ let lookups: ScriptActionLookups | undefined;
141
+ for (const [actionId, action] of Object.entries(actions ?? {})) {
142
+ if (action.kind !== "script") continue;
143
+ if (!isEnvFlagEnabled("UI_SPEC_ACTIONS_ENABLED", false)) {
144
+ issues.push(`Action "${actionId}" needs UI_SPEC_ACTIONS_ENABLED=true.`);
145
+ continue;
146
+ }
147
+ lookups ??= await loadScriptActionLookups();
148
+ const resolved = await resolveScriptAction(actionId, action, lookups);
149
+ const issue = resolved.ok ? argsIssue(actionId, action, resolved.script) : resolved.issue;
150
+ if (issue) issues.push(issue);
151
+ }
152
+ return issues;
153
+ }
154
+
155
+ /**
156
+ * The pin re-check that runs inside the write transaction of every uiSpec
157
+ * store (store-progress and a click refresh), after `scriptActionIssues`
158
+ * passed outside it. It closes the gap where a pin is removed, or a script
159
+ * edited, between that check and the write. Bounded: one
160
+ * allowlist read and one hash query, whatever the number of actions.
161
+ */
162
+ export async function scriptActionPinIssues(
163
+ actions: Record<string, TaskUiSpecAction> | undefined,
164
+ ): Promise<string[]> {
165
+ const scriptActions = Object.entries(actions ?? {}).filter(
166
+ (entry): entry is [string, ScriptAction] => entry[1].kind === "script",
167
+ );
168
+ if (scriptActions.length === 0) return [];
169
+ const allPins = parseScriptActionAllowlist(await readScriptActionAllowlist()).pins;
170
+ const hashes = await getGlobalScriptContentHashes([
171
+ ...new Set(scriptActions.map(([, action]) => action.script)),
172
+ ]);
173
+ const issues: string[] = [];
174
+ for (const [actionId, action] of scriptActions) {
175
+ const hash = hashes.get(action.script)?.toLowerCase();
176
+ const pins = allPins.filter((pin) => pin.name === action.script);
177
+ if (!hash || !pins.some((pin) => hash.startsWith(pin.hashPrefix))) {
178
+ issues.push(
179
+ `Action "${actionId}": script "${action.script}" is no longer allowlisted at its current contentHash in UI_SPEC_SCRIPT_ACTIONS.`,
180
+ );
181
+ }
182
+ }
183
+ return issues;
184
+ }
185
+
186
+ /** One short scrubbed line for the clicker and `last_error`. */
187
+ function shortError(text: string): string {
188
+ const line = scrubSecrets(text).replace(/\s+/g, " ").trim();
189
+ return line.length > 300 ? `${line.slice(0, 297)}...` : line;
190
+ }
191
+
192
+ type ScriptOutcome =
193
+ | { ok: true; uiSpec: TaskUiSpec }
194
+ | { ok: false; kind: "script_failed" | "invalid_output"; error: string };
195
+
196
+ async function runAndValidate(
197
+ task: AgentTask,
198
+ action: ScriptAction,
199
+ script: ScriptRecord,
200
+ stored: TaskUiSpec,
201
+ ): Promise<ScriptOutcome> {
202
+ if (!task.agentId)
203
+ return {
204
+ ok: false,
205
+ kind: "script_failed",
206
+ error: "the task has no agent to run the script as",
207
+ };
208
+ // The script runs as the agent that wrote the card, so it never gets more
209
+ // credentials than that agent. Only the frozen args reach it.
210
+ const output = await runSavedScriptAsAgent({
211
+ script,
212
+ input: action.args ?? {},
213
+ agentId: task.agentId,
214
+ timeoutMs: UI_SPEC_SCRIPT_ACTION_TIMEOUT_MS,
215
+ });
216
+ if (output.exitCode !== 0 || output.error || output.runtimeError) {
217
+ const reason = output.runtimeError
218
+ ? `${output.runtimeError.name}: ${output.runtimeError.message}`
219
+ : output.error
220
+ ? `script ${output.error}`
221
+ : `script exited ${output.exitCode}`;
222
+ return { ok: false, kind: "script_failed", error: reason };
223
+ }
224
+
225
+ const parsed = TaskUiSpecInputSchema.safeParse(output.result);
226
+ if (!parsed.success) {
227
+ const issue = parsed.error.issues[0];
228
+ const path = issue?.path.join(".") || "result";
229
+ return {
230
+ ok: false,
231
+ kind: "invalid_output",
232
+ error: `script output is not { spec, actions? }: ${path}: ${issue?.message ?? "invalid"}`,
233
+ };
234
+ }
235
+ const newActions = parsed.data.actions;
236
+ const scriptIssues = await scriptActionIssues(newActions);
237
+ if (scriptIssues.length > 0)
238
+ return { ok: false, kind: "invalid_output", error: scriptIssues[0] ?? "invalid action" };
239
+ // A script that returns no actions keeps the stored ones, so Refresh survives.
240
+ const actions = newActions ?? stored.actions;
241
+ const validation = validateTaskUiSpec(
242
+ { spec: parsed.data.spec, ...(actions ? { actions } : {}) },
243
+ { taskId: task.id, actionsEnabled: true },
244
+ );
245
+ if (!validation.ok)
246
+ return { ok: false, kind: "invalid_output", error: validation.issues[0] ?? "invalid uiSpec" };
247
+ return {
248
+ ok: true,
249
+ uiSpec: {
250
+ spec: validation.spec,
251
+ ...(validation.actions ? { actions: validation.actions } : {}),
252
+ fallbackText: validation.fallbackText,
253
+ },
254
+ };
255
+ }
256
+
257
+ /**
258
+ * Re-runs a card's `script` action and replaces the card with its output.
259
+ * Repeatable: a lease lock stops overlapping runs and a cooldown spaces them.
260
+ * A failure keeps the old card.
261
+ */
262
+ export async function runTaskUiScriptAction({
263
+ task,
264
+ actionId,
265
+ action,
266
+ stored,
267
+ surface,
268
+ actorUserId,
269
+ slackUserId,
270
+ }: {
271
+ task: AgentTask;
272
+ actionId: string;
273
+ action: ScriptAction;
274
+ stored: TaskUiSpec;
275
+ surface: TaskUiActionSurface;
276
+ actorUserId: string;
277
+ slackUserId?: string;
278
+ }): Promise<TaskUiActionResult> {
279
+ const resolved = await resolveScriptAction(actionId, action);
280
+ if (!resolved.ok) {
281
+ if (resolved.reason === "missing") {
282
+ return { status: "script_failed", error: `script "${action.script}" no longer exists` };
283
+ }
284
+ return { status: resolved.reason };
285
+ }
286
+
287
+ const lock = await acquireTaskUiScriptActionRun({
288
+ taskId: task.id,
289
+ actionId,
290
+ surface,
291
+ slackUserId,
292
+ userId: actorUserId,
293
+ leaseMs: UI_SPEC_SCRIPT_ACTION_LEASE_MS,
294
+ cooldownMs: UI_SPEC_SCRIPT_ACTION_COOLDOWN_MS,
295
+ });
296
+ if (lock.status !== "acquired") return lock;
297
+
298
+ let outcome: ScriptOutcome;
299
+ try {
300
+ outcome = await runAndValidate(task, action, resolved.script, stored);
301
+ } catch (error) {
302
+ outcome = {
303
+ ok: false,
304
+ kind: "script_failed",
305
+ error: error instanceof Error ? error.message : String(error),
306
+ };
307
+ }
308
+
309
+ if (outcome.ok) {
310
+ // Re-check the new card's pins in the write itself, so a pin removed while
311
+ // the script ran never lands as an armed button.
312
+ const okOutcome = outcome;
313
+ const pinIssue = await getDbClient().transaction(async () => {
314
+ const [issue] = await scriptActionPinIssues(okOutcome.uiSpec.actions);
315
+ if (!issue) await upsertTaskUiSpec(task.id, okOutcome.uiSpec, actorUserId);
316
+ return issue;
317
+ });
318
+ if (pinIssue) outcome = { ok: false, kind: "invalid_output", error: pinIssue };
319
+ }
320
+
321
+ if (!outcome.ok) {
322
+ const error = shortError(outcome.error);
323
+ await finishTaskUiScriptActionRun(task.id, actionId, error);
324
+ await createLogEntry({
325
+ eventType: "task_ui_script_action_failed",
326
+ ...(task.agentId ? { agentId: task.agentId } : {}),
327
+ taskId: task.id,
328
+ newValue: error,
329
+ metadata: { actionId, script: action.script, kind: outcome.kind },
330
+ });
331
+ return { status: outcome.kind, error };
332
+ }
333
+
334
+ await finishTaskUiScriptActionRun(task.id, actionId, null);
335
+ getDbClient().afterCommit(() =>
336
+ workflowEventBus.emit(TASK_UI_SPEC_UPDATED_EVENT, { taskId: task.id }),
337
+ );
338
+ // The stored row is the scrubbed one: return that, not the raw script output.
339
+ return { status: "refreshed", uiSpec: (await getTaskUiSpec(task.id)) ?? outcome.uiSpec };
340
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * `UI_SPEC_SCRIPT_ACTIONS`: comma-separated `name@<contentHash prefix>` pins.
3
+ * Pure, so the config guard can validate a value without loading the DB.
4
+ */
5
+
6
+ export const UI_SPEC_SCRIPT_ACTIONS_KEY = "UI_SPEC_SCRIPT_ACTIONS";
7
+
8
+ /** A pinned prefix of the script's sha256 `contentHash`: 12 to 64 hex chars. */
9
+ const PIN_HASH = /^[0-9a-f]{12,64}$/;
10
+
11
+ export type ScriptActionPin = { name: string; hashPrefix: string };
12
+
13
+ export function parseScriptActionAllowlist(raw: string | undefined): {
14
+ pins: ScriptActionPin[];
15
+ issues: string[];
16
+ } {
17
+ const pins: ScriptActionPin[] = [];
18
+ const issues: string[] = [];
19
+ for (const entry of (raw ?? "").split(",")) {
20
+ const trimmed = entry.trim();
21
+ if (!trimmed) continue;
22
+ // Split at the last "@", so a name may itself contain one.
23
+ const at = trimmed.lastIndexOf("@");
24
+ const name = at > 0 ? trimmed.slice(0, at).trim() : "";
25
+ const hashPrefix =
26
+ at > 0
27
+ ? trimmed
28
+ .slice(at + 1)
29
+ .trim()
30
+ .toLowerCase()
31
+ : "";
32
+ if (!name || name.length > 200 || !PIN_HASH.test(hashPrefix)) {
33
+ issues.push(
34
+ `"${trimmed}" must be name@<contentHash>, with at least 12 hex chars of the script's contentHash`,
35
+ );
36
+ continue;
37
+ }
38
+ pins.push({ name, hashPrefix });
39
+ }
40
+ return { pins, issues };
41
+ }
42
+
43
+ /** The `VALIDATED_KEYS` validator for `UI_SPEC_SCRIPT_ACTIONS`. */
44
+ export function validateScriptActionAllowlist(value: unknown): string | null {
45
+ if (typeof value !== "string") return "UI_SPEC_SCRIPT_ACTIONS must be a string";
46
+ const { issues } = parseScriptActionAllowlist(value);
47
+ return issues.length > 0 ? `UI_SPEC_SCRIPT_ACTIONS: ${issues.join("; ")}` : null;
48
+ }
@@ -12,14 +12,27 @@ const BASE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
12
12
  * constraint should regenerate on the (astronomically unlikely) conflict.
13
13
  */
14
14
  export function generateShortId(len = 12): string {
15
- // Rejection-sample bytes into the 52-letter alphabet to avoid modulo bias:
16
- // accept bytes < 208 (= 52 * 4, the largest multiple of 52 ≤ 255) and reject
17
- // the rest so every letter is equally likely.
15
+ return randomChars(LETTERS, len);
16
+ }
17
+
18
+ /**
19
+ * Pick `len` uniformly random characters from `alphabet`. Rejection-samples
20
+ * bytes to avoid modulo bias: accept bytes below the largest multiple of the
21
+ * alphabet size that fits in a byte (208 for 52 letters, 248 for base62) and
22
+ * reject the rest so every character is equally likely. `source` is
23
+ * injectable for tests.
24
+ */
25
+ export function randomChars(
26
+ alphabet: string,
27
+ len: number,
28
+ source: (size: number) => Uint8Array = randomBytes,
29
+ ): string {
30
+ const accept = 256 - (256 % alphabet.length);
18
31
  let out = "";
19
32
  while (out.length < len) {
20
- for (const byte of randomBytes((len - out.length) * 2)) {
21
- if (byte < 208) {
22
- out += LETTERS[byte % 52];
33
+ for (const byte of source((len - out.length) * 2)) {
34
+ if (byte < accept) {
35
+ out += alphabet[byte % alphabet.length];
23
36
  if (out.length === len) break;
24
37
  }
25
38
  }
@@ -27,18 +40,11 @@ export function generateShortId(len = 12): string {
27
40
  return out;
28
41
  }
29
42
 
30
- /** base62-encode raw bytes (URL-safe, unambiguous), mirroring the user-token util. */
31
- function base62(bytes: Uint8Array): string {
32
- let out = "";
33
- for (const byte of bytes) out += BASE62[byte % 62];
34
- return out;
35
- }
36
-
37
43
  /**
38
44
  * Generate a high-entropy bearer secret: `xsk_` + 24 base62 chars (~143 bits),
39
45
  * mirroring the `aswt_` user-token shape in src/be/users.ts. Unlike
40
46
  * {@link generateShortId} this IS a secret and must be stored encrypted.
41
47
  */
42
48
  export function generateBearerToken(): string {
43
- return `xsk_${base62(randomBytes(24))}`;
49
+ return `xsk_${randomChars(BASE62, 24)}`;
44
50
  }
@@ -12,9 +12,15 @@ export const UI_SPEC_MAX_BLOCKS = 45;
12
12
  /** Max elements in one Slack `actions` block. */
13
13
  export const UI_SPEC_MAX_ACTIONS_ROW_ELEMENTS = 25;
14
14
 
15
+ /** Max entries in a uiSpec's `actions` map. Bounds the write-time script checks. */
16
+ export const UI_SPEC_MAX_ACTIONS = 25;
17
+
15
18
  /** Prefix on the Slack `action_id` of every spec Button. */
16
19
  export const UI_SPEC_ACTION_PREFIX = "swarm_ui:";
17
20
 
21
+ /** Emitted after a script action replaced a task's card. Data: `{ taskId }`. */
22
+ export const TASK_UI_SPEC_UPDATED_EVENT = "task.ui_spec_updated";
23
+
18
24
  /** Allowed id of a declared action, and of the Button that names it. */
19
25
  export const UI_SPEC_ACTION_ID = /^[a-z][a-z0-9_]{0,39}$/;
20
26
 
@@ -52,10 +58,16 @@ export interface TaskUiSpecDocument {
52
58
  state?: Record<string, unknown>;
53
59
  }
54
60
 
55
- export interface TaskUiSpecAction {
56
- kind: "follow_up";
57
- prompt: string;
58
- }
61
+ /** Max UTF-8 bytes of `JSON.stringify(args)` on a `script` action. */
62
+ export const UI_SPEC_SCRIPT_ARGS_MAX_BYTES = 4_096;
63
+
64
+ /**
65
+ * `follow_up` starts a Lead task once. `script` re-runs an allowlisted global
66
+ * script with frozen `args` and replaces the card with its output.
67
+ */
68
+ export type TaskUiSpecAction =
69
+ | { kind: "follow_up"; prompt: string }
70
+ | { kind: "script"; script: string; args?: Record<string, unknown> };
59
71
 
60
72
  export interface TaskUiSpec {
61
73
  spec: TaskUiSpecDocument;
package/src/vcs/index.ts CHANGED
@@ -16,9 +16,19 @@ export type { VcsProvider } from "./types";
16
16
  export function detectVcsProvider(url: string): VcsProvider | null {
17
17
  if (isAzureDevOpsUrl(url)) return "azure-devops";
18
18
  if (isBitbucketUrl(url)) return "bitbucket";
19
- // The configured GHES host wins over the loose gitlab substring checks below.
19
+ // The configured GHES host wins even when its hostname starts with gitlab.
20
20
  if (getGitHubLinkConfig().enterprise && isGitHubUrl(url)) return "github";
21
- if (url.includes("gitlab.com") || url.includes("gitlab.")) return "gitlab";
21
+ let hostname: string | undefined;
22
+ try {
23
+ hostname = new URL(url).hostname.toLowerCase();
24
+ } catch {
25
+ // SCP-style SSH remotes: user@host:path.
26
+ hostname = url
27
+ .trim()
28
+ .match(/^[^@/\s:]+@([^:/\s]+):/)?.[1]
29
+ ?.toLowerCase();
30
+ }
31
+ if (hostname?.startsWith("gitlab.")) return "gitlab";
22
32
  if (url.includes("github.com") || /^[\w.-]+\/[\w.-]+$/.test(url)) return "github";
23
33
  return null;
24
34
  }
@@ -916,7 +916,7 @@ export class SystemOneDecisionExecutor extends BaseExecutor<
916
916
  async decide(
917
917
  config: SystemOneDecisionConfig,
918
918
  ): Promise<
919
- | { ok: true; output: SystemOneDecisionOutput }
919
+ | { ok: true; output: SystemOneDecisionOutput; provider: SystemOneProviderId }
920
920
  | { ok: false; error: string; deploymentRefused?: true }
921
921
  > {
922
922
  const providerId = config.provider ?? (await this.defaultProvider());
@@ -980,7 +980,7 @@ export class SystemOneDecisionExecutor extends BaseExecutor<
980
980
  }
981
981
  throw err;
982
982
  }
983
- return { ok: true, output: decision };
983
+ return { ok: true, output: decision, provider: providerId };
984
984
  }
985
985
 
986
986
  /**
@@ -1370,8 +1370,9 @@ async function processBusEvent(eventName: string, payload: unknown): Promise<voi
1370
1370
  }
1371
1371
  }
1372
1372
 
1373
- // Clean up: if all waits for this event resolved, drop the listener.
1374
- if (set.size === 0) {
1373
+ // Resuming can replace this set with a new wait for the same event. Only
1374
+ // clean up the set this handler processed, never its replacement.
1375
+ if (set.size === 0 && waitsByEvent.get(eventName) === set) {
1375
1376
  waitsByEvent.delete(eventName);
1376
1377
  const listener = listenersByEvent.get(eventName);
1377
1378
  if (listener) {
@@ -2,6 +2,7 @@ import {
2
2
  detachTaskFromWorkflowRunStep,
3
3
  getDbClient,
4
4
  getTaskById,
5
+ getTaskByWorkflowRunStepId,
5
6
  getWorkflowRun,
6
7
  getWorkflowRunStep,
7
8
  markWorkflowStepTaskSuperseded,
@@ -284,6 +285,8 @@ async function isSupersedeCut(taskId: string, reason: string): Promise<boolean>
284
285
  /**
285
286
  * Persist an agent-task result and resolve its next nodes. Synthetic foreach
286
287
  * children never checkpoint into workflow context; only their parent join does.
288
+ * With `failureReason` (a failed task the workflow carries on without), a
289
+ * supersede cut on the step's task moves to `superseded`.
287
290
  */
288
291
  export async function completeTaskStepAndResolveSuccessors(
289
292
  def: WorkflowDefinition,
@@ -308,11 +311,19 @@ export async function completeTaskStepAndResolveSuccessors(
308
311
  // A late result inside a cancelled tree routes nothing and revives nothing.
309
312
  if (await getRunLineageBlock(runId)) return UNCLAIMED;
310
313
 
314
+ // Read before the step settles: the task stays bound, so the step's task
315
+ // is the one whose failure this call absorbs.
316
+ const failedTaskId =
317
+ failureReason !== undefined
318
+ ? (ownerTaskId ?? (await getTaskByWorkflowRunStepId(step.id))?.id)
319
+ : undefined;
320
+
321
+ let result: TaskStepRoutingResult;
311
322
  if (resolveForeachParent(def, step.nodeId)) {
312
323
  // onNodeFailure:"continue" completions persist the failure reason as
313
324
  // explicit metadata — the join classifies children on THIS, not on
314
325
  // whether user-controlled output text happens to start with "[FAILED:".
315
- return toRoutingResult(
326
+ result = toRoutingResult(
316
327
  await settleForeachChild(
317
328
  def,
318
329
  runId,
@@ -326,16 +337,25 @@ export async function completeTaskStepAndResolveSuccessors(
326
337
  { registry },
327
338
  ),
328
339
  );
340
+ } else {
341
+ await checkpointStep(runId, step.id, step.nodeId, { output }, ctx);
342
+ await updateWorkflowRun(runId, { status: "running" });
343
+ result = {
344
+ claimed: true,
345
+ foreachChild: false,
346
+ joined: true,
347
+ successors: getSuccessors(def, step.nodeId),
348
+ runFailed: false,
349
+ };
329
350
  }
330
351
 
331
- await checkpointStep(runId, step.id, step.nodeId, { output }, ctx);
332
- await updateWorkflowRun(runId, { status: "running" });
333
- return {
334
- claimed: true,
335
- foreachChild: false,
336
- joined: true,
337
- successors: getSuccessors(def, step.nodeId),
338
- runFailed: false,
339
- };
352
+ // The workflow absorbed the failure (onNodeFailure "continue" or a
353
+ // collect-outcomes fan-out): the step ends `completed` and the run goes on,
354
+ // so a supersede cut behind it is not a real failure either. A cut whose
355
+ // step ends `failed` never reaches here and stays `failed`.
356
+ if (failedTaskId && result.claimed && !result.runFailed) {
357
+ await markWorkflowStepTaskSuperseded(failedTaskId);
358
+ }
359
+ return result;
340
360
  });
341
361
  }
@@ -13,6 +13,9 @@ const DEFAULT_HMAC_HEADER = "X-Hub-Signature-256";
13
13
  /** Fallback header names checked (case-insensitive) after the trigger's configured header. */
14
14
  const FALLBACK_HMAC_HEADERS = ["x-hub-signature-256", "x-signature", "x-webhook-signature"];
15
15
 
16
+ /** Header read for a webhook trigger's `events` allowlist when it configures no `eventHeader`. */
17
+ const DEFAULT_EVENT_HEADER = "X-GitHub-Event";
18
+
16
19
  /** A bag of HTTP headers — values may be a string, a string array, or absent. */
17
20
  export type HeaderBag = Record<string, string | string[] | undefined>;
18
21
 
@@ -152,6 +155,25 @@ export async function verifyWebhookRequest(
152
155
  }
153
156
  }
154
157
 
158
+ /**
159
+ * Event of a delivery a webhook trigger's `events` allowlist does not admit,
160
+ * or `undefined` when the delivery may start a run. A missing header counts
161
+ * as not admitted (`null`): an allowlist is a closed gate.
162
+ */
163
+ function filteredWebhookEvent(
164
+ trigger: WebhookTriggerConfig,
165
+ headers: HeaderBag,
166
+ ): string | null | undefined {
167
+ if (!trigger.events || trigger.events.length === 0) return undefined;
168
+ const event = getHeader(headers, trigger.eventHeader || DEFAULT_EVENT_HEADER) ?? null;
169
+ return event !== null && trigger.events.includes(event) ? undefined : event;
170
+ }
171
+
172
+ /** Outcome of a webhook delivery: a started run, or a delivery the trigger's `events` allowlist dropped. */
173
+ export type WebhookTriggerResult =
174
+ | { runId: string; skipped?: undefined }
175
+ | { runId?: undefined; skipped: true; reason: "event-not-allowed"; event: string | null };
176
+
155
177
  export interface HandleWebhookTriggerOptions {
156
178
  /**
157
179
  * Skip the "workflow must declare a webhook trigger" gate. ONLY for callers
@@ -174,11 +196,14 @@ export interface HandleWebhookTriggerOptions {
174
196
  * trigger — being reachable over `/api/webhooks/:workflowId` is opt-in
175
197
  * 3. If `hmacSecret` / `verification` is set, resolves the signature header +
176
198
  * secret and verifies the signature against the raw body bytes
177
- * 4. Parses the raw body as JSON (falling back to the raw string when the
199
+ * 4. If the trigger sets an `events` allowlist, drops a delivery whose event
200
+ * header is missing or not listed: no run is persisted, and the caller
201
+ * gets a `skipped` result to acknowledge with a 2xx
202
+ * 5. Parses the raw body as JSON (falling back to the raw string when the
178
203
  * body is non-JSON) so downstream `{{trigger.deep.path}}` interpolation
179
204
  * can traverse the object — matches the shape produced by the
180
205
  * `trigger-workflow` MCP tool.
181
- * 5. Starts the workflow execution with the parsed payload
206
+ * 6. Starts the workflow execution with the parsed payload
182
207
  */
183
208
  export async function handleWebhookTrigger(
184
209
  workflowId: string,
@@ -186,7 +211,7 @@ export async function handleWebhookTrigger(
186
211
  headers: HeaderBag,
187
212
  registry: ExecutorRegistry,
188
213
  options: HandleWebhookTriggerOptions = {},
189
- ): Promise<{ runId: string }> {
214
+ ): Promise<WebhookTriggerResult> {
190
215
  const workflow = await getWorkflow(workflowId);
191
216
  if (!workflow) {
192
217
  throw new WebhookError("Workflow not found", 404);
@@ -221,6 +246,13 @@ export async function handleWebhookTrigger(
221
246
  typeof payload === "string" ? payload : JSON.stringify(payload),
222
247
  headers,
223
248
  );
249
+
250
+ // After verification, so a bad signature is still a 401 for any event.
251
+ // Before the run is persisted, so a dropped delivery writes no rows.
252
+ const filtered = filteredWebhookEvent(webhookTrigger, headers);
253
+ if (filtered !== undefined) {
254
+ return { skipped: true, reason: "event-not-allowed", event: filtered };
255
+ }
224
256
  }
225
257
 
226
258
  // Parse the raw body so downstream nodes can interpolate deep paths