@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,517 @@
1
+ /**
2
+ * Card `script` actions: write-time checks, the pinned allowlist, the lease
3
+ * lock and cooldown, and the in-place card refresh. The script runtime is
4
+ * stubbed; everything else runs on a real DB.
5
+ */
6
+ import { afterAll, beforeAll, beforeEach, describe, expect, spyOn, test } from "bun:test";
7
+ import { rm } from "node:fs/promises";
8
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
9
+ import * as dbModule from "../be/db";
10
+ import {
11
+ closeDb,
12
+ createAgent,
13
+ createTaskExtended,
14
+ createUser,
15
+ deleteSwarmConfigByKey,
16
+ getDbClient,
17
+ getTaskById,
18
+ initDb,
19
+ startTask,
20
+ upsertSwarmConfig,
21
+ } from "../be/db";
22
+ import { isInTransaction } from "../be/db-client";
23
+ import * as scriptsDbModule from "../be/scripts/db";
24
+ import { insertScript, upsertScriptByName } from "../be/scripts/db";
25
+ import * as runSavedModule from "../be/scripts/run-saved";
26
+ import { acquireTaskUiScriptActionRun, getTaskUiSpec, upsertTaskUiSpec } from "../be/task-ui-spec";
27
+ import { __resetInjectedEnvTracking, loadGlobalConfigsIntoEnv } from "../http/core";
28
+ import { registerStoreProgressTool } from "../tools/store-progress";
29
+ import { runTaskUiAction } from "../ui-spec/actions";
30
+ import { TaskUiSpecInputSchema } from "../ui-spec/schema";
31
+ import { scriptActionIssues } from "../ui-spec/script-actions";
32
+ import type { TaskUiSpec, TaskUiSpecDocument } from "../utils/task-ui-spec";
33
+ import { TASK_UI_SPEC_UPDATED_EVENT, UI_SPEC_MAX_ACTIONS } from "../utils/task-ui-spec";
34
+ import { workflowEventBus } from "../workflows/event-bus";
35
+
36
+ const dbPath = `/tmp/test-task-ui-script-actions-${crypto.randomUUID()}.sqlite`;
37
+ const SCRIPT = "deploy-metrics";
38
+ const previousEnv = {
39
+ UI_SPEC_ENABLED: process.env.UI_SPEC_ENABLED,
40
+ UI_SPEC_ACTIONS_ENABLED: process.env.UI_SPEC_ACTIONS_ENABLED,
41
+ UI_SPEC_SCRIPT_ACTIONS: process.env.UI_SPEC_SCRIPT_ACTIONS,
42
+ };
43
+
44
+ type RunOutput = Awaited<ReturnType<typeof runSavedModule.runSavedScriptAsAgent>>;
45
+ const ok = (result: unknown): RunOutput => ({
46
+ result,
47
+ stdout: "",
48
+ stderr: "",
49
+ truncated: { stdout: false, stderr: false },
50
+ durationMs: 5,
51
+ exitCode: 0,
52
+ });
53
+ const runSpy = spyOn(runSavedModule, "runSavedScriptAsAgent");
54
+
55
+ let agentId = "";
56
+ let requesterId = "";
57
+ let otherUserId = "";
58
+ let contentHash = "";
59
+
60
+ const card = (title: string, withButton = true): TaskUiSpecDocument => ({
61
+ root: "c",
62
+ elements: {
63
+ c: { type: "Card", props: { title }, children: withButton ? ["a"] : [] },
64
+ a: { type: "Actions", props: {}, children: ["b"] },
65
+ b: { type: "Button", props: { id: "refresh", label: "Refresh" }, children: [] },
66
+ },
67
+ });
68
+ const refreshAction = { kind: "script" as const, script: SCRIPT, args: { repo: "agent-swarm" } };
69
+ const pin = (hash = contentHash) => `${SCRIPT}@${hash.slice(0, 12)}`;
70
+
71
+ async function taskWithRefresh(): Promise<string> {
72
+ const task = await createTaskExtended("Deploy metrics", {
73
+ agentId,
74
+ source: "api",
75
+ requestedByUserId: requesterId,
76
+ });
77
+ await upsertTaskUiSpec(task.id, {
78
+ spec: card("Deploys: 1"),
79
+ actions: { refresh: refreshAction },
80
+ fallbackText: "Deploys: 1",
81
+ });
82
+ return task.id;
83
+ }
84
+
85
+ type StoreProgressHandler = (
86
+ a: unknown,
87
+ m: unknown,
88
+ ) => Promise<{ structuredContent: { success: boolean; message: string } }>;
89
+
90
+ function storeProgressHandler(): StoreProgressHandler {
91
+ const server = new McpServer({ name: "script-action-test", version: "1" });
92
+ registerStoreProgressTool(server);
93
+ return (
94
+ server as unknown as {
95
+ _registeredTools: Record<string, { handler: StoreProgressHandler }>;
96
+ }
97
+ )._registeredTools["store-progress"]!.handler;
98
+ }
99
+
100
+ const click = (taskId: string, actorUserId = requesterId) =>
101
+ runTaskUiAction({ taskId, actionId: "refresh", surface: "web", actorUserId });
102
+
103
+ const runRow = (taskId: string) =>
104
+ getDbClient().get<{ runCount: number; lastError: string | null; lockedUntil: string | null }>(
105
+ `SELECT run_count AS runCount, last_error AS lastError, locked_until AS lockedUntil
106
+ FROM task_ui_action_runs WHERE task_id = ? AND action_id = 'refresh'`,
107
+ [taskId],
108
+ );
109
+
110
+ /** Moves the last run back past the cooldown. */
111
+ const expireCooldown = (taskId: string) =>
112
+ getDbClient().run(
113
+ "UPDATE task_ui_action_runs SET last_run_at = '2000-01-01T00:00:00.000Z' WHERE task_id = ?",
114
+ [taskId],
115
+ );
116
+
117
+ beforeAll(async () => {
118
+ initDb(dbPath);
119
+ agentId = (
120
+ await createAgent({
121
+ name: "script action test",
122
+ role: "worker",
123
+ isLead: false,
124
+ status: "busy",
125
+ capabilities: [],
126
+ })
127
+ ).id;
128
+ requesterId = (await createUser({ name: "Requester" })).id;
129
+ otherUserId = (await createUser({ name: "Bystander" })).id;
130
+ contentHash = (
131
+ await insertScript({
132
+ name: SCRIPT,
133
+ scope: "global",
134
+ source: "export default async () => ({})",
135
+ description: "Deploy metrics card",
136
+ intent: "Refresh a metrics card",
137
+ signatureJson: "{}",
138
+ argsJsonSchema: JSON.stringify({
139
+ type: "object",
140
+ properties: { repo: { type: "string" } },
141
+ required: ["repo"],
142
+ }),
143
+ embeddingMode: "skip",
144
+ })
145
+ ).contentHash;
146
+ });
147
+
148
+ afterAll(async () => {
149
+ runSpy.mockRestore();
150
+ for (const [key, value] of Object.entries(previousEnv)) {
151
+ if (value === undefined) delete process.env[key];
152
+ else process.env[key] = value;
153
+ }
154
+ closeDb();
155
+ await Promise.all(["", "-wal", "-shm"].map((suffix) => rm(dbPath + suffix, { force: true })));
156
+ });
157
+
158
+ beforeEach(() => {
159
+ process.env.UI_SPEC_ENABLED = "true";
160
+ process.env.UI_SPEC_ACTIONS_ENABLED = "true";
161
+ process.env.UI_SPEC_SCRIPT_ACTIONS = pin();
162
+ runSpy.mockReset();
163
+ runSpy.mockImplementation(async () =>
164
+ ok({ spec: card(`Deploys: ${runSpy.mock.calls.length + 1}`) }),
165
+ );
166
+ });
167
+
168
+ describe("write-time checks", () => {
169
+ test("a pinned global script with valid args passes", async () => {
170
+ expect(await scriptActionIssues({ refresh: refreshAction })).toEqual([]);
171
+ });
172
+
173
+ test("a name not on the allowlist is refused", async () => {
174
+ process.env.UI_SPEC_SCRIPT_ACTIONS = "other@0123456789ab";
175
+ expect((await scriptActionIssues({ refresh: refreshAction }))[0]).toContain(
176
+ "is not allowlisted in UI_SPEC_SCRIPT_ACTIONS",
177
+ );
178
+ });
179
+
180
+ test("a hash that does not match the script reads as changed, not as unlisted", async () => {
181
+ process.env.UI_SPEC_SCRIPT_ACTIONS = `${SCRIPT}@ffffffffffff`;
182
+ expect((await scriptActionIssues({ refresh: refreshAction }))[0]).toContain(
183
+ "changed since it was allowlisted",
184
+ );
185
+ });
186
+
187
+ test("a script that is not global is refused", async () => {
188
+ process.env.UI_SPEC_SCRIPT_ACTIONS = "agent-only@0123456789ab";
189
+ await insertScript({
190
+ name: "agent-only",
191
+ scope: "agent",
192
+ scopeId: agentId,
193
+ source: "export default async () => ({})",
194
+ description: "d",
195
+ intent: "i",
196
+ signatureJson: "{}",
197
+ embeddingMode: "skip",
198
+ });
199
+ const action = { kind: "script" as const, script: "agent-only" };
200
+ expect((await scriptActionIssues({ refresh: action }))[0]).toContain("is not a global script");
201
+ });
202
+
203
+ test("oversized args and args that fail the schema are refused", async () => {
204
+ const big = { ...refreshAction, args: { repo: "x".repeat(5000) } };
205
+ expect((await scriptActionIssues({ refresh: big }))[0]).toContain("the limit is 4096");
206
+ const wrong = { ...refreshAction, args: { repo: 7 } };
207
+ expect((await scriptActionIssues({ refresh: wrong }))[0]).toContain("argsJsonSchema");
208
+ });
209
+
210
+ test("the action flag is required", async () => {
211
+ process.env.UI_SPEC_ACTIONS_ENABLED = "false";
212
+ expect((await scriptActionIssues({ refresh: refreshAction }))[0]).toContain(
213
+ "UI_SPEC_ACTIONS_ENABLED",
214
+ );
215
+ });
216
+
217
+ test(`a uiSpec with more than ${UI_SPEC_MAX_ACTIONS} actions fails the input schema`, () => {
218
+ const actions = (n: number) =>
219
+ Object.fromEntries(Array.from({ length: n }, (_, i) => [`a${i}`, refreshAction]));
220
+ const parse = (n: number) =>
221
+ TaskUiSpecInputSchema.safeParse({ spec: card("Deploys"), actions: actions(n) }).success;
222
+ expect(parse(UI_SPEC_MAX_ACTIONS)).toBe(true);
223
+ expect(parse(UI_SPEC_MAX_ACTIONS + 1)).toBe(false);
224
+ });
225
+
226
+ test("many actions read the allowlist once and each script once", async () => {
227
+ const configSpy = spyOn(dbModule, "getSwarmConfigs");
228
+ const scriptSpy = spyOn(scriptsDbModule, "getScript");
229
+ try {
230
+ const actions = Object.fromEntries(
231
+ Array.from({ length: UI_SPEC_MAX_ACTIONS }, (_, i) => [`a${i}`, refreshAction]),
232
+ );
233
+ expect(await scriptActionIssues(actions)).toEqual([]);
234
+ expect(configSpy).toHaveBeenCalledTimes(1);
235
+ expect(scriptSpy).toHaveBeenCalledTimes(1);
236
+ } finally {
237
+ configSpy.mockRestore();
238
+ scriptSpy.mockRestore();
239
+ }
240
+ });
241
+
242
+ test("store-progress refuses an unlisted script action once", async () => {
243
+ // The allowlist read must not run inside the completion write transaction.
244
+ const realGetSwarmConfigs = dbModule.getSwarmConfigs;
245
+ const allowlistReadsInTransaction: boolean[] = [];
246
+ const configSpy = spyOn(dbModule, "getSwarmConfigs").mockImplementation(async (filter) => {
247
+ if (filter?.key === "UI_SPEC_SCRIPT_ACTIONS")
248
+ allowlistReadsInTransaction.push(isInTransaction());
249
+ return realGetSwarmConfigs(filter);
250
+ });
251
+ process.env.UI_SPEC_SCRIPT_ACTIONS = "";
252
+ const handler = storeProgressHandler();
253
+ const task = await createTaskExtended("Refuse script", { agentId, source: "system" });
254
+ await startTask(task.id);
255
+ const args = {
256
+ taskId: task.id,
257
+ status: "completed",
258
+ output: "Done",
259
+ uiSpec: { spec: card("Deploys"), actions: { refresh: refreshAction } },
260
+ };
261
+ const meta = { requestInfo: { headers: { "x-agent-id": agentId } } };
262
+ const refused = await handler(args, meta);
263
+ expect(refused.structuredContent.success).toBe(false);
264
+ expect(refused.structuredContent.message).toContain("is not allowlisted");
265
+ const accepted = await handler(args, meta);
266
+ expect(accepted.structuredContent.success).toBe(true);
267
+ expect((await getTaskById(task.id))?.status).toBe("completed");
268
+ expect(await getTaskUiSpec(task.id)).toBeNull();
269
+ configSpy.mockRestore();
270
+ expect(allowlistReadsInTransaction).toEqual([false, false]);
271
+ });
272
+
273
+ test("store-progress re-checks pins inside the transaction with bounded work", async () => {
274
+ const handler = storeProgressHandler();
275
+ const meta = { requestInfo: { headers: { "x-agent-id": agentId } } };
276
+ const realGetSwarmConfigs = dbModule.getSwarmConfigs;
277
+ const reads: boolean[] = [];
278
+ let revokeAfterPrecheck = false;
279
+ const configSpy = spyOn(dbModule, "getSwarmConfigs").mockImplementation(async (filter) => {
280
+ if (filter?.key !== "UI_SPEC_SCRIPT_ACTIONS") return realGetSwarmConfigs(filter);
281
+ reads.push(isInTransaction());
282
+ // The pre-check has passed; the pin is gone by the time the transaction reads it.
283
+ if (revokeAfterPrecheck && isInTransaction()) process.env.UI_SPEC_SCRIPT_ACTIONS = "";
284
+ return realGetSwarmConfigs(filter);
285
+ });
286
+ const scriptSpy = spyOn(scriptsDbModule, "getScript");
287
+ const hashSpy = spyOn(scriptsDbModule, "getGlobalScriptContentHashes");
288
+ const complete = async (title: string) => {
289
+ const task = await createTaskExtended(title, { agentId, source: "system" });
290
+ await startTask(task.id);
291
+ const actions = Object.fromEntries(
292
+ Array.from({ length: UI_SPEC_MAX_ACTIONS - 1 }, (_, i) => [`a${i}`, refreshAction]),
293
+ );
294
+ const result = await handler(
295
+ {
296
+ taskId: task.id,
297
+ status: "completed",
298
+ output: "Done",
299
+ uiSpec: { spec: card("Deploys"), actions: { refresh: refreshAction, ...actions } },
300
+ },
301
+ meta,
302
+ );
303
+ return { taskId: task.id, result };
304
+ };
305
+ try {
306
+ // Positive control: the pin holds, the card is stored, and the
307
+ // transaction did one allowlist read and one hash query.
308
+ const kept = await complete("Pin holds");
309
+ expect(kept.result.structuredContent.success).toBe(true);
310
+ expect(await getTaskUiSpec(kept.taskId)).not.toBeNull();
311
+ expect(reads).toEqual([false, true]);
312
+ expect(hashSpy).toHaveBeenCalledTimes(1);
313
+ expect(scriptSpy).toHaveBeenCalledTimes(1);
314
+
315
+ reads.length = 0;
316
+ revokeAfterPrecheck = true;
317
+ const revoked = await complete("Pin revoked before BEGIN");
318
+ expect(revoked.result.structuredContent.success).toBe(false);
319
+ expect(revoked.result.structuredContent.message).toContain("no longer allowlisted");
320
+ expect(await getTaskUiSpec(revoked.taskId)).toBeNull();
321
+ expect((await getTaskById(revoked.taskId))?.status).not.toBe("completed");
322
+ expect(reads).toEqual([false, true]);
323
+ } finally {
324
+ configSpy.mockRestore();
325
+ scriptSpy.mockRestore();
326
+ hashSpy.mockRestore();
327
+ }
328
+ });
329
+ });
330
+
331
+ describe("runTaskUiAction with a script action", () => {
332
+ test("a click runs the script with the frozen args and replaces the card", async () => {
333
+ const taskId = await taskWithRefresh();
334
+ const events: unknown[] = [];
335
+ const onEvent = (data: unknown) => events.push(data);
336
+ workflowEventBus.on(TASK_UI_SPEC_UPDATED_EVENT, onEvent);
337
+ try {
338
+ const result = await click(taskId);
339
+ expect(result.status).toBe("refreshed");
340
+ expect(runSpy).toHaveBeenCalledTimes(1);
341
+ const call = runSpy.mock.calls[0]![0];
342
+ expect(call.input).toEqual({ repo: "agent-swarm" });
343
+ expect(call.agentId).toBe(agentId);
344
+ const stored = (await getTaskUiSpec(taskId)) as TaskUiSpec;
345
+ expect((stored.spec.elements.c as { props: { title: string } }).props.title).toBe(
346
+ "Deploys: 2",
347
+ );
348
+ // The script returned no actions, so the stored Refresh carries over.
349
+ expect(stored.actions).toEqual({ refresh: refreshAction });
350
+ expect(stored.fallbackText).toContain("Deploys: 2");
351
+ expect((await runRow(taskId))?.runCount).toBe(1);
352
+ expect(events).toEqual([{ taskId }]);
353
+ } finally {
354
+ workflowEventBus.off(TASK_UI_SPEC_UPDATED_EVENT, onEvent);
355
+ }
356
+ });
357
+
358
+ test("inside the cooldown a click is rate limited; after it the script runs again", async () => {
359
+ const taskId = await taskWithRefresh();
360
+ expect((await click(taskId)).status).toBe("refreshed");
361
+ const second = await click(taskId);
362
+ expect(second).toMatchObject({ status: "rate_limited" });
363
+ expect((second as { retryAfterSec: number }).retryAfterSec).toBeGreaterThan(0);
364
+ await expireCooldown(taskId);
365
+ expect((await click(taskId)).status).toBe("refreshed");
366
+ expect((await runRow(taskId))?.runCount).toBe(2);
367
+ });
368
+
369
+ test("a held lease answers running; an expired lease is reclaimed", async () => {
370
+ const taskId = await taskWithRefresh();
371
+ const lease = {
372
+ taskId,
373
+ actionId: "refresh",
374
+ surface: "web" as const,
375
+ leaseMs: 45_000,
376
+ cooldownMs: 30_000,
377
+ };
378
+ expect((await acquireTaskUiScriptActionRun(lease)).status).toBe("acquired");
379
+ expect((await click(taskId)).status).toBe("running");
380
+ expect(runSpy).not.toHaveBeenCalled();
381
+ // The holder crashed: a minute later its lease has run out.
382
+ const later = await acquireTaskUiScriptActionRun({ ...lease, nowMs: Date.now() + 60_000 });
383
+ expect(later.status).toBe("acquired");
384
+ });
385
+
386
+ test("five concurrent clicks run the script once", async () => {
387
+ const taskId = await taskWithRefresh();
388
+ const results = await Promise.all(Array.from({ length: 5 }, () => click(taskId)));
389
+ expect(results.filter((r) => r.status === "refreshed")).toHaveLength(1);
390
+ expect(results.every((r) => ["refreshed", "running", "rate_limited"].includes(r.status))).toBe(
391
+ true,
392
+ );
393
+ expect(runSpy).toHaveBeenCalledTimes(1);
394
+ });
395
+
396
+ test("invalid output keeps the old card and records the error", async () => {
397
+ const taskId = await taskWithRefresh();
398
+ runSpy.mockImplementation(async () => ok({ spec: { root: "x", elements: {} } }));
399
+ const result = await click(taskId);
400
+ expect(result.status).toBe("invalid_output");
401
+ expect((await getTaskUiSpec(taskId))?.fallbackText).toBe("Deploys: 1");
402
+ expect((await runRow(taskId))?.lastError).toBeTruthy();
403
+ const log = await getDbClient().get<{ n: number }>(
404
+ "SELECT COUNT(*) AS n FROM agent_log WHERE taskId = ? AND eventType = 'task_ui_script_action_failed'",
405
+ [taskId],
406
+ );
407
+ expect(log?.n).toBe(1);
408
+ });
409
+
410
+ test("a Button naming an undeclared action in the output is invalid", async () => {
411
+ const taskId = await taskWithRefresh();
412
+ runSpy.mockImplementation(async () =>
413
+ ok({ spec: card("New"), actions: { other: { kind: "follow_up", prompt: "go" } } }),
414
+ );
415
+ const result = await click(taskId);
416
+ expect(result).toMatchObject({ status: "invalid_output" });
417
+ expect((result as { error: string }).error).toContain('names action "refresh"');
418
+ });
419
+
420
+ test("a pin removed after the output check keeps the old card", async () => {
421
+ const taskId = await taskWithRefresh();
422
+ const realGetSwarmConfigs = dbModule.getSwarmConfigs;
423
+ const configSpy = spyOn(dbModule, "getSwarmConfigs").mockImplementation(async (filter) => {
424
+ // Every check outside the write passes; the pin is gone when the write re-reads it.
425
+ if (filter?.key === "UI_SPEC_SCRIPT_ACTIONS" && isInTransaction())
426
+ process.env.UI_SPEC_SCRIPT_ACTIONS = "";
427
+ return realGetSwarmConfigs(filter);
428
+ });
429
+ try {
430
+ const result = await click(taskId);
431
+ expect(result).toMatchObject({ status: "invalid_output" });
432
+ expect((result as { error: string }).error).toContain("no longer allowlisted");
433
+ expect(runSpy).toHaveBeenCalledTimes(1);
434
+ expect((await getTaskUiSpec(taskId))?.fallbackText).toBe("Deploys: 1");
435
+ expect((await runRow(taskId))?.lockedUntil).toBeNull();
436
+ } finally {
437
+ configSpy.mockRestore();
438
+ }
439
+ });
440
+
441
+ test("a failed script keeps the old card", async () => {
442
+ const taskId = await taskWithRefresh();
443
+ runSpy.mockImplementation(async () => ({ ...ok(undefined), exitCode: 1 }));
444
+ expect(await click(taskId)).toEqual({ status: "script_failed", error: "script exited 1" });
445
+ expect((await getTaskUiSpec(taskId))?.fallbackText).toBe("Deploys: 1");
446
+ expect((await runRow(taskId))?.lockedUntil).toBeNull();
447
+ });
448
+
449
+ test("a name removed from the allowlist after write is refused at click", async () => {
450
+ const taskId = await taskWithRefresh();
451
+ process.env.UI_SPEC_SCRIPT_ACTIONS = "";
452
+ expect((await click(taskId)).status).toBe("not_allowlisted");
453
+ expect(runSpy).not.toHaveBeenCalled();
454
+ });
455
+
456
+ test("the stored row is read at click time, so a pin removed elsewhere disarms here", async () => {
457
+ const taskId = await taskWithRefresh();
458
+ process.env.UI_SPEC_SCRIPT_ACTIONS = "";
459
+ // Another API process stores the pin: this process never reloaded its env.
460
+ await upsertSwarmConfig({ scope: "global", key: "UI_SPEC_SCRIPT_ACTIONS", value: pin() });
461
+ try {
462
+ expect((await click(taskId)).status).toBe("refreshed");
463
+ // This process loads the pin into its env, then another process deletes it.
464
+ await loadGlobalConfigsIntoEnv(true);
465
+ expect(process.env.UI_SPEC_SCRIPT_ACTIONS).toBe(pin());
466
+ await deleteSwarmConfigByKey("global", null, "UI_SPEC_SCRIPT_ACTIONS");
467
+ await expireCooldown(taskId);
468
+ expect((await click(taskId)).status).toBe("not_allowlisted");
469
+ expect(runSpy).toHaveBeenCalledTimes(1);
470
+ } finally {
471
+ await deleteSwarmConfigByKey("global", null, "UI_SPEC_SCRIPT_ACTIONS");
472
+ __resetInjectedEnvTracking();
473
+ }
474
+ });
475
+
476
+ test("an edited script disarms the card until it is re-pinned", async () => {
477
+ const taskId = await taskWithRefresh();
478
+ const edited = await upsertScriptByName({
479
+ name: SCRIPT,
480
+ scope: "global",
481
+ source: "export default async () => ({ changed: true })",
482
+ description: "Deploy metrics card",
483
+ intent: "Refresh a metrics card",
484
+ signatureJson: "{}",
485
+ embeddingMode: "skip",
486
+ });
487
+ try {
488
+ expect((await click(taskId)).status).toBe("script_changed");
489
+ expect(runSpy).not.toHaveBeenCalled();
490
+ process.env.UI_SPEC_SCRIPT_ACTIONS = pin(edited.script.contentHash);
491
+ expect((await click(taskId)).status).toBe("refreshed");
492
+ } finally {
493
+ contentHash = edited.script.contentHash;
494
+ }
495
+ });
496
+
497
+ test("only the requester may click", async () => {
498
+ const taskId = await taskWithRefresh();
499
+ expect((await click(taskId, otherUserId)).status).toBe("forbidden");
500
+ expect(runSpy).not.toHaveBeenCalled();
501
+ });
502
+
503
+ test("a follow_up action still runs once only", async () => {
504
+ const task = await createTaskExtended("Follow-up once", {
505
+ agentId,
506
+ source: "api",
507
+ requestedByUserId: requesterId,
508
+ });
509
+ await upsertTaskUiSpec(task.id, {
510
+ spec: card("Deploys"),
511
+ actions: { refresh: { kind: "follow_up", prompt: "Run it again." } },
512
+ fallbackText: "Deploys",
513
+ });
514
+ expect((await click(task.id)).status).toBe("started");
515
+ expect((await click(task.id)).status).toBe("already_done");
516
+ });
517
+ });