@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
@@ -18,15 +18,18 @@ import {
18
18
  import { fillOrgLogoFromWebsite } from "../be/org-profile";
19
19
  import { getUserGrant } from "../be/rbac-roles";
20
20
  import {
21
+ humanOnlyConfigKeyError,
22
+ humanOnlyConfigKeyPageError,
21
23
  internalConfigKeyError,
22
24
  isApiOnlyConfigKey,
25
+ isHumanOnlyConfigKey,
23
26
  isInternalConfigKey,
24
27
  validateConfigEntry,
25
28
  } from "../be/swarm-config-guard";
26
29
  import { isScriptRunToken } from "../be/users";
27
30
  import { can, isRbacEnabled, type PermissionVerb } from "../rbac";
28
31
  import { type SwarmConfig, SwarmConfigSchema } from "../types";
29
- import { getRequestAuth, type HttpRequestAuth } from "../utils/request-auth-context";
32
+ import { authUserId, getRequestAuth, type HttpRequestAuth } from "../utils/request-auth-context";
30
33
  import { registerVolatileSecret } from "../utils/secret-scrubber";
31
34
  import { reloadGlobalConfigsAndIntegrations, scheduleIntegrationsReload } from "./core";
32
35
  import { syncRankingAfterConfigChange } from "./ranking";
@@ -185,6 +188,34 @@ export async function ensureConfigAdmin(
185
188
  );
186
189
  }
187
190
 
191
+ /**
192
+ * A human-only key (see `isHumanOnlyConfigKey`) needs an admin user: a user
193
+ * token or a dashboard session. The operator key resolves to the operator,
194
+ * and every worker holds it, so it is refused like an agent or a guest. A
195
+ * page session is refused whoever its viewer is. The operator key can still
196
+ * mint an admin user token; see the limit on `HUMAN_ONLY_CONFIG_KEYS`.
197
+ * Returns true when the request may proceed; on denial it writes a 403.
198
+ */
199
+ export async function ensureHumanOnlyConfigWrite(
200
+ req: IncomingMessage,
201
+ res: ServerResponse,
202
+ key: string,
203
+ ): Promise<boolean> {
204
+ if (!isHumanOnlyConfigKey(key)) return true;
205
+ const auth = getRequestAuth(req);
206
+ // A page session carries its viewer's identity, but the page's code is
207
+ // agent-authored and the page proxy forwards any /api/* route, so a
208
+ // user-bound page session would pass as that admin. Refuse every page.
209
+ if (auth?.page) {
210
+ jsonError(res, humanOnlyConfigKeyPageError(key), 403);
211
+ return false;
212
+ }
213
+ const userId = authUserId(auth);
214
+ if (userId && (!isRbacEnabled() || (await getUserGrant(userId)).grantsAll)) return true;
215
+ jsonError(res, humanOnlyConfigKeyError(key), 403);
216
+ return false;
217
+ }
218
+
188
219
  /**
189
220
  * What a committed config write triggers beyond the row itself. Shared by
190
221
  * `PUT /api/config` and HITL `config` answers.
@@ -531,6 +562,7 @@ export async function handleConfig(
531
562
  if (!parsed) return true;
532
563
  if (!(await ensureConfigAdmin(req, res, "config.write.any"))) return true;
533
564
  const { scope, scopeId, key, value, isSecret, envPath, description, exportToEnv } = parsed.body;
565
+ if (!(await ensureHumanOnlyConfigWrite(req, res, key))) return true;
534
566
 
535
567
  const validationError = validateConfigEntry({ scope, scopeId, key, value, exportToEnv });
536
568
  if (validationError) {
@@ -576,6 +608,7 @@ export async function handleConfig(
576
608
  jsonError(res, internalConfigKeyError(existing.key).message, 400);
577
609
  return true;
578
610
  }
611
+ if (!(await ensureHumanOnlyConfigWrite(req, res, existing.key))) return true;
579
612
  const deleted = await deleteSwarmConfig(parsed.params.id);
580
613
  if (!deleted) {
581
614
  jsonError(res, "Config not found", 404);
package/src/http/index.ts CHANGED
@@ -114,6 +114,7 @@ import { handleMcpServers } from "./mcp-servers";
114
114
  import { closeIdleMcpUserTransports, handleMcpUser } from "./mcp-user";
115
115
  import { handleMemory, startMemoryGc, stopMemoryGc } from "./memory";
116
116
  import { handleMetrics } from "./metrics";
117
+ import { handleModelGroups } from "./model-groups";
117
118
  import { handleModelProfiles } from "./model-profiles";
118
119
  import { handleModelsCatalog } from "./models-catalog";
119
120
  import { handleOAuthCallback, startOAuthPendingGc, stopOAuthPendingGc } from "./oauth-callback";
@@ -150,6 +151,7 @@ import { handleStatus } from "./status";
150
151
  import { handleTaskTemplates } from "./task-templates";
151
152
  import { handleTasks } from "./tasks";
152
153
  import { handleTelemetryUi } from "./telemetry-ui";
154
+ import { handleToolHooks } from "./tool-hooks";
153
155
  import { handleTrackers } from "./trackers";
154
156
  import { handleUsedBy } from "./used-by";
155
157
  import { handleUserRoles } from "./user-roles";
@@ -401,6 +403,7 @@ const httpServer = createHttpServer(async (req, res) => {
401
403
  () => handleMetrics(req, res, pathSegments, queryParams, myAgentId),
402
404
  () => handleModelsCatalog(req, res, pathSegments, queryParams),
403
405
  () => handleModelProfiles(req, res, pathSegments, queryParams, myAgentId),
406
+ () => handleModelGroups(req, res, pathSegments, queryParams, myAgentId),
404
407
  () => handleRepos(req, res, pathSegments, queryParams, myAgentId),
405
408
  () => handleSkills(req, res, pathSegments, queryParams, myAgentId),
406
409
  () => handleScriptConnections(req, res, pathSegments, queryParams, myAgentId),
@@ -424,6 +427,7 @@ const httpServer = createHttpServer(async (req, res) => {
424
427
  () => handleEvents(req, res, pathSegments, queryParams, myAgentId),
425
428
  () => handleRuntimePools(req, res, pathSegments, queryParams, myAgentId),
426
429
  () => handleExtensions(req, res, pathSegments, queryParams, myAgentId),
430
+ () => handleToolHooks(req, res, pathSegments, queryParams, myAgentId),
427
431
  () => handleChecklist(req, res, pathSegments, queryParams, myAgentId),
428
432
  () => handleFavorites(req, res, pathSegments, queryParams, myAgentId),
429
433
  () => handleUserRoles(req, res, pathSegments, queryParams),
@@ -971,6 +975,15 @@ httpServer
971
975
  console.error("[boot-scrub-sweep] startup scrub failed (non-fatal):", err);
972
976
  });
973
977
 
978
+ // User merges queued by POST /api/users/{id}/merge run in batches off the
979
+ // request. A job the previous process left running or failed is re-queued
980
+ // and continues from its last committed batch. See src/be/user-merge-jobs.ts.
981
+ import("../be/user-merge-jobs")
982
+ .then(({ resumeUserMergeJobs }) => resumeUserMergeJobs())
983
+ .catch((err) => {
984
+ console.error("[user-merge] startup resume failed (non-fatal):", err);
985
+ });
986
+
974
987
  // Source key backfill is idempotent, resumable, and non-fatal.
975
988
  import("../be/session-source-backfill")
976
989
  .then(({ runSessionSourceBackfill }) => runSessionSourceBackfill())
@@ -5,6 +5,7 @@ import { withLoopPath } from "../be/event-loop-lag";
5
5
  import { getEmbeddingProvider, getMemoryStore } from "../be/memory";
6
6
  import { canReadMemory } from "../be/memory/access";
7
7
  import { CANDIDATE_SET_MULTIPLIER } from "../be/memory/constants";
8
+ import { attachDemotionEvidence } from "../be/memory/demotion-evidence";
8
9
  import { listEdgesForAgent } from "../be/memory/edges-store";
9
10
  import { expandCandidatesWithGraph } from "../be/memory/graph-expansion";
10
11
  import { indexMemoryContent } from "../be/memory/index-content";
@@ -36,6 +37,7 @@ import {
36
37
  } from "../be/memory/raters/types";
37
38
  import { rerank } from "../be/memory/reranker";
38
39
  import { getRetrievalsForAgent, hasRetrievalForTask } from "../be/memory/retrieval-store";
40
+ import { dropReviewTaskCompletions, isReviewTaskId } from "../be/memory/review-recall-filter";
39
41
  import { searchMemoryCandidates } from "../be/memory/search-candidates";
40
42
  import { getUsefulnessStats } from "../be/memory/usefulness-stats";
41
43
  import { shouldPersistAutomaticTaskMemory } from "../memory/automatic-task-gate";
@@ -908,6 +910,13 @@ export async function handleMemory(
908
910
  const store = getMemoryStore();
909
911
  const queryEmbedding = await provider.embed(query, { kind: "query" });
910
912
 
913
+ const sourceTaskIdHeader = req.headers["x-source-task-id"];
914
+ const sourceTaskId = Array.isArray(sourceTaskIdHeader)
915
+ ? sourceTaskIdHeader[0]
916
+ : sourceTaskIdHeader;
917
+ // A review task never recalls other review tasks' task_completion rows.
918
+ const excludeReviewTaskCompletions = await isReviewTaskId(sourceTaskId);
919
+
911
920
  const candidateLimit = Math.min(limit, 20) * CANDIDATE_SET_MULTIPLIER;
912
921
  const candidates = await searchMemoryCandidates(
913
922
  store,
@@ -920,16 +929,22 @@ export async function handleMemory(
920
929
  isLead: false,
921
930
  queryText: query,
922
931
  keyPrefix,
932
+ excludeReviewTaskCompletions,
923
933
  },
924
934
  );
925
935
  // Default-on 1-hop memory_link neighbor expansion (disable with
926
936
  // MEMORY_GRAPH_EXPANSION=0|false).
927
- const expanded = await expandCandidatesWithGraph(candidates, myAgentId, {
937
+ const graphExpanded = await expandCandidatesWithGraph(candidates, myAgentId, {
928
938
  scope,
929
939
  source,
930
940
  keyPrefix,
931
941
  isLead: false,
932
942
  });
943
+ const expanded = await attachDemotionEvidence(
944
+ excludeReviewTaskCompletions
945
+ ? await dropReviewTaskCompletions(graphExpanded)
946
+ : graphExpanded,
947
+ );
933
948
  const resultLimit = Math.min(limit, 20);
934
949
  // Prompt recall injects only rows above the relevance gate, so the gate
935
950
  // must pick the slots, not trim them afterwards: eligible rows fill the
@@ -950,10 +965,6 @@ export async function handleMemory(
950
965
  // (ImplicitCitationRater, fired from store-progress on task completion)
951
966
  // know which memories were surfaced. Best-effort: a logging failure must
952
967
  // never poison search.
953
- const sourceTaskIdHeader = req.headers["x-source-task-id"];
954
- const sourceTaskId = Array.isArray(sourceTaskIdHeader)
955
- ? sourceTaskIdHeader[0]
956
- : sourceTaskIdHeader;
957
968
  const contextKeyHeader = req.headers["x-context-key"];
958
969
  const contextKey = Array.isArray(contextKeyHeader) ? contextKeyHeader[0] : contextKeyHeader;
959
970
  if (sourceTaskId && intent) {
@@ -1055,7 +1066,9 @@ export async function handleMemory(
1055
1066
  if (pathNeedle) {
1056
1067
  candidates = candidates.filter((c) => matchesPath(c.sourcePath));
1057
1068
  }
1058
- const ranked = rerank(candidates, { limit: candidates.length });
1069
+ const ranked = rerank(await attachDemotionEvidence(candidates), {
1070
+ limit: candidates.length,
1071
+ });
1059
1072
  const page = ranked.slice(offset, offset + pageLimit);
1060
1073
 
1061
1074
  listMemory.respond(res, 200, {
@@ -0,0 +1,277 @@
1
+ // Model groups CRUD (runbooks/model-tiers.md § Model groups).
2
+ //
3
+ // A group is a named, ordered list of model profiles that may span harnesses.
4
+ // Boot seeds the four tier groups (smol, regular, smart, ultra). Nothing
5
+ // resolves a task through a group yet. Reads are open to every caller; writes
6
+ // need `models.groups.write` (the lead, the operator or a dashboard user).
7
+
8
+ import type { IncomingMessage, ServerResponse } from "node:http";
9
+ import { z } from "zod";
10
+ import { resolveHttpAuditUserId } from "../be/audit-user";
11
+ import {
12
+ createModelGroup,
13
+ deleteModelGroup,
14
+ getModelGroupByName,
15
+ listModelGroups,
16
+ MAX_MODEL_GROUP_MEMBERS,
17
+ type ModelGroupWriteResult,
18
+ modelGroupReferences,
19
+ updateModelGroup,
20
+ } from "../be/db/model-groups";
21
+ import { can } from "../rbac";
22
+ import { ModelGroupSchema, ModelProfileNameSchema } from "../types";
23
+ import { agentFirstPrincipal } from "./request-principal";
24
+ import { route } from "./route-def";
25
+ import { jsonError } from "./utils";
26
+
27
+ const MembersSchema = z
28
+ .array(ModelProfileNameSchema)
29
+ .min(1)
30
+ .max(MAX_MODEL_GROUP_MEMBERS)
31
+ .describe("Profile names in preference order, first preferred. Any harness; no repeats.");
32
+
33
+ const listGroups = route({
34
+ method: "get",
35
+ path: "/api/model-groups",
36
+ pattern: ["api", "model-groups"],
37
+ summary: "List model groups",
38
+ description: "Every model group with its member profiles in order, by name.",
39
+ tags: ["Models"],
40
+ responses: {
41
+ 200: { description: "Model groups", schema: z.object({ groups: z.array(ModelGroupSchema) }) },
42
+ },
43
+ });
44
+
45
+ const getGroup = route({
46
+ method: "get",
47
+ path: "/api/model-groups/{name}",
48
+ pattern: ["api", "model-groups", null],
49
+ summary: "Get one model group",
50
+ tags: ["Models"],
51
+ params: z.object({ name: z.string() }),
52
+ responses: {
53
+ 200: { description: "The model group", schema: ModelGroupSchema },
54
+ 404: { description: "No group with that name" },
55
+ },
56
+ });
57
+
58
+ const createGroup = route({
59
+ method: "post",
60
+ path: "/api/model-groups",
61
+ pattern: ["api", "model-groups"],
62
+ summary: "Create a model group",
63
+ description:
64
+ "A group is an ordered list of model profiles that may span harnesses. Every member must be an existing profile, listed once. The name may not be a model profile's (groups and profiles share one name space; 409). Lead, operator or dashboard user.",
65
+ tags: ["Models"],
66
+ rbac: { permission: "models.groups.write" },
67
+ body: z.object({
68
+ name: ModelProfileNameSchema,
69
+ description: z.string().trim().max(500).nullable().optional(),
70
+ members: MembersSchema,
71
+ }),
72
+ responses: {
73
+ 201: { description: "Group created", schema: ModelGroupSchema },
74
+ 400: { description: "Validation error" },
75
+ 403: { description: "Forbidden" },
76
+ 409: { description: "A group or profile with that name exists" },
77
+ },
78
+ });
79
+
80
+ const updateGroup = route({
81
+ method: "patch",
82
+ path: "/api/model-groups/{name}",
83
+ pattern: ["api", "model-groups", null],
84
+ summary: "Update a model group",
85
+ description:
86
+ "Changes the description (`null` clears it). The name is fixed; reorder or replace members with `PUT /api/model-groups/{name}/members`. Lead, operator or dashboard user.",
87
+ tags: ["Models"],
88
+ rbac: { permission: "models.groups.write" },
89
+ params: z.object({ name: z.string() }),
90
+ body: z.object({ description: z.string().trim().max(500).nullable() }),
91
+ responses: {
92
+ 200: { description: "Group updated", schema: ModelGroupSchema },
93
+ 400: { description: "Validation error" },
94
+ 403: { description: "Forbidden" },
95
+ 404: { description: "No group with that name" },
96
+ },
97
+ });
98
+
99
+ const setMembers = route({
100
+ method: "put",
101
+ path: "/api/model-groups/{name}/members",
102
+ pattern: ["api", "model-groups", null, "members"],
103
+ summary: "Replace a model group's members",
104
+ description:
105
+ "Replaces the whole ordered member list in one transaction; send the full list to reorder. Every member must be an existing profile, listed once. Lead, operator or dashboard user.",
106
+ tags: ["Models"],
107
+ rbac: { permission: "models.groups.write" },
108
+ params: z.object({ name: z.string() }),
109
+ body: z.object({ members: MembersSchema }),
110
+ responses: {
111
+ 200: { description: "Members replaced", schema: ModelGroupSchema },
112
+ 400: { description: "Validation error" },
113
+ 403: { description: "Forbidden" },
114
+ 404: { description: "No group with that name" },
115
+ },
116
+ });
117
+
118
+ const deleteGroup = route({
119
+ method: "delete",
120
+ path: "/api/model-groups/{name}",
121
+ pattern: ["api", "model-groups", null],
122
+ summary: "Delete a model group",
123
+ description:
124
+ "Refused (409) for a shipped tier group (`smol`, `regular`, `smart`, `ultra`; edit it instead, it would come back at the next boot), and while a schedule names the group or a task holds it (unfinished, or superseded and still owed its resume). Lead, operator or dashboard user.",
125
+ tags: ["Models"],
126
+ rbac: { permission: "models.groups.write" },
127
+ params: z.object({ name: z.string() }),
128
+ responses: {
129
+ 200: { description: "Group deleted", schema: z.object({ deleted: z.literal(true) }) },
130
+ 403: { description: "Forbidden" },
131
+ 404: { description: "No group with that name" },
132
+ 409: { description: "The group is a seed or still in use" },
133
+ },
134
+ });
135
+
136
+ /** Gate a write on `models.groups.write`; writes a 403 and returns false on denial. */
137
+ async function canWriteGroups(
138
+ req: IncomingMessage,
139
+ res: ServerResponse,
140
+ myAgentId: string | undefined,
141
+ ): Promise<boolean> {
142
+ const decision = can({
143
+ principal: await agentFirstPrincipal(req, myAgentId),
144
+ verb: "models.groups.write",
145
+ resource: { kind: "none" },
146
+ source: "http",
147
+ });
148
+ if (!decision.allow) {
149
+ jsonError(res, "Writing model groups requires the lead, the operator or a dashboard user", 403);
150
+ return false;
151
+ }
152
+ return true;
153
+ }
154
+
155
+ const WRITE_FAILURE_STATUS = { invalid: 400, exists: 409, "name-taken": 409, missing: 404 };
156
+
157
+ /** Send a failed write's status and message; true when the write failed. */
158
+ function writeFailed(
159
+ res: ServerResponse,
160
+ result: ModelGroupWriteResult,
161
+ ): result is Extract<ModelGroupWriteResult, { ok: false }> {
162
+ if (result.ok) return false;
163
+ jsonError(res, result.error, WRITE_FAILURE_STATUS[result.reason]);
164
+ return true;
165
+ }
166
+
167
+ export async function handleModelGroups(
168
+ req: IncomingMessage,
169
+ res: ServerResponse,
170
+ pathSegments: string[],
171
+ queryParams: URLSearchParams,
172
+ myAgentId: string | undefined,
173
+ ): Promise<boolean> {
174
+ if (listGroups.match(req.method, pathSegments)) {
175
+ const parsed = await listGroups.parse(req, res, pathSegments, queryParams);
176
+ if (!parsed) return true;
177
+ listGroups.respond(res, 200, { groups: await listModelGroups() });
178
+ return true;
179
+ }
180
+
181
+ if (getGroup.match(req.method, pathSegments)) {
182
+ const parsed = await getGroup.parse(req, res, pathSegments, queryParams);
183
+ if (!parsed) return true;
184
+ const group = await getModelGroupByName(parsed.params.name);
185
+ if (!group) {
186
+ jsonError(res, "Model group not found", 404);
187
+ return true;
188
+ }
189
+ getGroup.respond(res, 200, group);
190
+ return true;
191
+ }
192
+
193
+ if (createGroup.match(req.method, pathSegments)) {
194
+ const parsed = await createGroup.parse(req, res, pathSegments, queryParams);
195
+ if (!parsed) return true;
196
+ if (!(await canWriteGroups(req, res, myAgentId))) return true;
197
+ const userId = await resolveHttpAuditUserId(req, myAgentId);
198
+ const result = await createModelGroup(parsed.body, { userId });
199
+ if (writeFailed(res, result)) return true;
200
+ createGroup.respond(res, 201, result.group);
201
+ return true;
202
+ }
203
+
204
+ if (updateGroup.match(req.method, pathSegments)) {
205
+ const parsed = await updateGroup.parse(req, res, pathSegments, queryParams);
206
+ if (!parsed) return true;
207
+ if (!(await canWriteGroups(req, res, myAgentId))) return true;
208
+ const userId = await resolveHttpAuditUserId(req, myAgentId);
209
+ const result = await updateModelGroup(
210
+ parsed.params.name,
211
+ { description: parsed.body.description },
212
+ { userId },
213
+ );
214
+ if (writeFailed(res, result)) return true;
215
+ updateGroup.respond(res, 200, result.group);
216
+ return true;
217
+ }
218
+
219
+ if (setMembers.match(req.method, pathSegments)) {
220
+ const parsed = await setMembers.parse(req, res, pathSegments, queryParams);
221
+ if (!parsed) return true;
222
+ if (!(await canWriteGroups(req, res, myAgentId))) return true;
223
+ const userId = await resolveHttpAuditUserId(req, myAgentId);
224
+ const result = await updateModelGroup(
225
+ parsed.params.name,
226
+ { members: parsed.body.members },
227
+ { userId },
228
+ );
229
+ if (writeFailed(res, result)) return true;
230
+ setMembers.respond(res, 200, result.group);
231
+ return true;
232
+ }
233
+
234
+ if (deleteGroup.match(req.method, pathSegments)) {
235
+ const parsed = await deleteGroup.parse(req, res, pathSegments, queryParams);
236
+ if (!parsed) return true;
237
+ if (!(await canWriteGroups(req, res, myAgentId))) return true;
238
+ const current = await getModelGroupByName(parsed.params.name);
239
+ if (!current) {
240
+ jsonError(res, "Model group not found", 404);
241
+ return true;
242
+ }
243
+ if (current.seededFrom?.startsWith("tier:")) {
244
+ jsonError(
245
+ res,
246
+ `"${current.name}" is a shipped tier group and comes back at the next boot; edit it instead.`,
247
+ 409,
248
+ );
249
+ return true;
250
+ }
251
+ const refs = await modelGroupReferences(current.name);
252
+ if (refs.openTaskCount > 0 || refs.scheduleIds.length > 0) {
253
+ const schedules = refs.scheduleIds.length > 0 ? ` (${refs.scheduleIds.join(", ")})` : "";
254
+ jsonError(
255
+ res,
256
+ `"${current.name}" is in use: held by ${refs.openTaskCount} unfinished or awaiting-resume task(s), named by ${refs.scheduleIds.length} schedule(s)${schedules}.`,
257
+ 409,
258
+ );
259
+ return true;
260
+ }
261
+ // The counts above are for the message; the delete re-checks in the same
262
+ // statement, so a reference written since is still a 409.
263
+ const outcome = await deleteModelGroup(current.name);
264
+ if (outcome === "in-use") {
265
+ jsonError(res, `"${current.name}" is in use by a task or a schedule written just now.`, 409);
266
+ return true;
267
+ }
268
+ if (outcome === "missing") {
269
+ jsonError(res, "Model group not found", 404);
270
+ return true;
271
+ }
272
+ deleteGroup.respond(res, 200, { deleted: true });
273
+ return true;
274
+ }
275
+
276
+ return false;
277
+ }
@@ -14,6 +14,7 @@ import {
14
14
  createModelProfile,
15
15
  deleteModelProfile,
16
16
  getModelProfileByName,
17
+ isModelNameTakenError,
17
18
  listModelProfiles,
18
19
  MAX_MODEL_PROFILE_FALLBACKS,
19
20
  modelProfileFallbacksError,
@@ -74,7 +75,7 @@ const createProfile = route({
74
75
  pattern: ["api", "model-profiles"],
75
76
  summary: "Create a model profile",
76
77
  description:
77
- "A profile runs on one harness. `model` must run on that harness and be in the model catalog unless `allowCustomModel` is true (a gateway id, a fresh launch); a `latest:` alias is accepted and resolves at claim. `effort` must be a level the harness and model support. `credentials` pins which pooled keys the profile uses: per credential var of the harness, the last 5 characters of each allowed key (`CODEX_OAUTH` is not supported). `fallbacks` lists profiles on the same harness, in order, that a task on this profile hops to when a provider error (rate limit, seat, overload, auth, empty key pool) ends it; no repeats, no self, no cycle. Operator only (the shared API key).",
78
+ "A profile runs on one harness. `model` must run on that harness and be in the model catalog unless `allowCustomModel` is true (a gateway id, a fresh launch); a `latest:` alias is accepted and resolves at claim. `effort` must be a level the harness and model support. `credentials` pins which pooled keys the profile uses: per credential var of the harness, the last 5 characters of each allowed key (`CODEX_OAUTH` is not supported). `fallbacks` lists profiles on the same harness, in order, that a task on this profile hops to when a provider error (rate limit, seat, overload, auth, empty key pool) ends it; no repeats, no self, no cycle. The name may not be a model group's (one name space; 409). Operator only (the shared API key).",
78
79
  tags: ["Models"],
79
80
  rbac: { permission: "models.profiles.write" },
80
81
  body: z.object({
@@ -91,7 +92,7 @@ const createProfile = route({
91
92
  201: { description: "Profile created", schema: ModelProfileSchema },
92
93
  400: { description: "Validation error" },
93
94
  403: { description: "Forbidden" },
94
- 409: { description: "A profile with that name exists" },
95
+ 409: { description: "A profile or model group with that name exists" },
95
96
  },
96
97
  });
97
98
 
@@ -127,7 +128,7 @@ const deleteProfile = route({
127
128
  pattern: ["api", "model-profiles", null],
128
129
  summary: "Delete a model profile",
129
130
  description:
130
- "Refused (409) for a shipped `<harness>-<tier>` seed (edit it instead; it would come back at the next boot), and while an agent has the profile as its default, a schedule names it, another profile lists it as a fallback, or a task holds it (unfinished, or superseded and still owed its resume). Operator only (the shared API key).",
131
+ "Refused (409) for a shipped `<harness>-<tier>` seed (edit it instead; it would come back at the next boot), and while an agent has the profile as its default, a schedule names it, another profile lists it as a fallback, a model group lists it as a member, or a task holds it (unfinished, or superseded and still owed its resume). Operator only (the shared API key).",
131
132
  tags: ["Models"],
132
133
  rbac: { permission: "models.profiles.write" },
133
134
  params: z.object({ name: z.string() }),
@@ -266,13 +267,27 @@ export async function handleModelProfiles(
266
267
  const userId = await resolveHttpAuditUserId(req, myAgentId);
267
268
  // The fallback graph check and the write share one transaction, so two
268
269
  // concurrent saves cannot each pass and together form a cycle.
269
- const outcome = await getDbClient().transaction(async () => {
270
- const fallbackError = body.fallbacks
271
- ? await modelProfileFallbacksError(body.name, body.harness, body.fallbacks)
272
- : null;
273
- if (fallbackError) return { error: fallbackError };
274
- return { created: await createModelProfile(body, { userId }) };
275
- });
270
+ const outcome = await getDbClient()
271
+ .transaction(async () => {
272
+ const fallbackError = body.fallbacks
273
+ ? await modelProfileFallbacksError(body.name, body.harness, body.fallbacks)
274
+ : null;
275
+ if (fallbackError) return { error: fallbackError };
276
+ return { created: await createModelProfile(body, { userId }) };
277
+ })
278
+ .catch((error: unknown) => {
279
+ // Migration 308's trigger: a model group has this name.
280
+ if (isModelNameTakenError(error)) return { nameTaken: true as const };
281
+ throw error;
282
+ });
283
+ if ("nameTaken" in outcome) {
284
+ jsonError(
285
+ res,
286
+ `"${body.name}" is a model group; profiles and groups share one name space.`,
287
+ 409,
288
+ );
289
+ return true;
290
+ }
276
291
  if (typeof outcome.error === "string") {
277
292
  jsonError(res, outcome.error, 400);
278
293
  return true;
@@ -350,13 +365,15 @@ export async function handleModelProfiles(
350
365
  refs.agentIds.length > 0 ||
351
366
  refs.openTaskCount > 0 ||
352
367
  refs.scheduleIds.length > 0 ||
353
- refs.fallbackOf.length > 0
368
+ refs.fallbackOf.length > 0 ||
369
+ refs.groups.length > 0
354
370
  ) {
355
371
  const schedules = refs.scheduleIds.length > 0 ? ` (${refs.scheduleIds.join(", ")})` : "";
356
372
  const fallbackOf = refs.fallbackOf.length > 0 ? ` (${refs.fallbackOf.join(", ")})` : "";
373
+ const groups = refs.groups.length > 0 ? ` (${refs.groups.join(", ")})` : "";
357
374
  jsonError(
358
375
  res,
359
- `"${current.name}" is in use: default of ${refs.agentIds.length} agent(s), held by ${refs.openTaskCount} unfinished or awaiting-resume task(s), named by ${refs.scheduleIds.length} schedule(s)${schedules}, a fallback of ${refs.fallbackOf.length} profile(s)${fallbackOf}.`,
376
+ `"${current.name}" is in use: default of ${refs.agentIds.length} agent(s), held by ${refs.openTaskCount} unfinished or awaiting-resume task(s), named by ${refs.scheduleIds.length} schedule(s)${schedules}, a fallback of ${refs.fallbackOf.length} profile(s)${fallbackOf}, a member of ${refs.groups.length} model group(s)${groups}.`,
360
377
  409,
361
378
  );
362
379
  return true;
@@ -367,7 +384,7 @@ export async function handleModelProfiles(
367
384
  if (outcome === "in-use") {
368
385
  jsonError(
369
386
  res,
370
- `"${current.name}" is in use by a task, a schedule, an agent default or a fallback list written just now.`,
387
+ `"${current.name}" is in use by a task, a schedule, an agent default, a fallback list or a model group written just now.`,
371
388
  409,
372
389
  );
373
390
  return true;
package/src/http/tasks.ts CHANGED
@@ -796,20 +796,32 @@ const runTaskUiActionRoute = route({
796
796
  rbac: { permission: "task.action.own" },
797
797
  summary: "Run the action a task card Button declares",
798
798
  description:
799
- "Runs the task card action once per task and action. Only the task requester may run it: a user token, or the operator key with the requester in `X-Swarm-User-Id`. Agent callers, and operator calls with no picked user, get 403. Needs UI_SPEC_ACTIONS_ENABLED=true.",
799
+ "Runs a task card action. Only the task requester may run it: a user token, or the operator key with the requester in `X-Swarm-User-Id`. Agent callers, and operator calls with no picked user, get 403. Needs UI_SPEC_ACTIONS_ENABLED=true. A `follow_up` action runs once per task and action. A `script` action re-runs its allowlisted script (UI_SPEC_SCRIPT_ACTIONS) and returns the new card; it can run again after a 30 s cooldown.",
800
800
  tags: ["Tasks"],
801
801
  params: z.object({ id: z.string(), actionId: z.string() }),
802
802
  responses: {
803
803
  200: {
804
- description: "The action started, or it already ran",
804
+ description:
805
+ "The follow-up started or already ran, or the script action replaced the card (`refreshed`, with the new `uiSpec`)",
805
806
  schema: z.object({
806
- status: z.enum(["started", "already_done"]),
807
+ status: z.enum(["started", "already_done", "refreshed"]),
807
808
  taskId: z.string().optional(),
809
+ uiSpec: TaskUiSpecSchema.optional(),
808
810
  }),
809
811
  },
810
- 403: { description: "Only the task requester may run the action" },
812
+ 403: {
813
+ description:
814
+ "Only the task requester may run the action, or the action's script is not allowlisted or changed since it was allowlisted",
815
+ },
811
816
  404: { description: "Task or action not found" },
812
- 409: { description: "Card actions are turned off (UI_SPEC_ACTIONS_ENABLED)" },
817
+ 409: {
818
+ description:
819
+ "Card actions are turned off (UI_SPEC_ACTIONS_ENABLED), or the script action is already running (with `Retry-After`)",
820
+ },
821
+ 422: { description: "The script failed or returned an invalid card; the old card stays" },
822
+ 429: {
823
+ description: "The script action ran recently; `Retry-After` says when it can run again",
824
+ },
813
825
  },
814
826
  });
815
827
 
@@ -820,7 +832,7 @@ const supersedeTaskRoute = route({
820
832
  session: { taskParam: "id" },
821
833
  summary: "Supersede an in-progress task (terminate + spawn resume follow-up)",
822
834
  description:
823
- "Marks the original task `superseded` (terminal) and creates a fresh `taskType=\"resume\"` follow-up so a worker can pick up the work in a new provider session. Workflow-step tasks (those with `workflowRunStepId`) are carved out: the original is marked `failed` with reason `superseded_workflow_task` and no follow-up is created — the workflow engine's retry/failure policy applies, and the task moves to `superseded` once the engine queues the step's retry. With `reason: provider_fallback` (and its `errorClass`), the resume runs on the same agent with the next fallback profile that passes the profile check; when none is left, or the task is a workflow step, nothing changes and `kind: noFallback` tells the worker to fail the task itself, led by `failureReason` when set.",
835
+ "Marks the original task `superseded` (terminal) and creates a fresh `taskType=\"resume\"` follow-up so a worker can pick up the work in a new provider session. Workflow-step tasks (those with `workflowRunStepId`) are carved out: the original is marked `failed` with reason `superseded_workflow_task` and no follow-up is created — the workflow engine's retry/failure policy applies, and the task moves to `superseded` once the engine queues the step's retry or the step ends without failing. With `reason: provider_fallback` (and its `errorClass`), the resume runs on the same agent with the next fallback profile that passes the profile check; when none is left, or the task is a workflow step, nothing changes and `kind: noFallback` tells the worker to fail the task itself, led by `failureReason` when set.",
824
836
  tags: ["Tasks"],
825
837
  params: z.object({ id: z.string() }),
826
838
  body: z
@@ -2235,8 +2247,31 @@ export async function handleTasks(
2235
2247
  runTaskUiActionRoute.respond(res, 200, { status: "already_done" });
2236
2248
  return true;
2237
2249
  case "started":
2250
+ case "refreshed":
2238
2251
  runTaskUiActionRoute.respond(res, 200, result);
2239
2252
  return true;
2253
+ case "not_allowlisted":
2254
+ jsonError(res, "This action's script is not allowlisted (UI_SPEC_SCRIPT_ACTIONS)", 403);
2255
+ return true;
2256
+ case "script_changed":
2257
+ jsonError(
2258
+ res,
2259
+ "This action's script changed since it was allowlisted; an admin must re-pin it in UI_SPEC_SCRIPT_ACTIONS",
2260
+ 403,
2261
+ );
2262
+ return true;
2263
+ case "running":
2264
+ res.setHeader("Retry-After", String(result.retryAfterSec));
2265
+ jsonError(res, "This action is already running", 409);
2266
+ return true;
2267
+ case "rate_limited":
2268
+ res.setHeader("Retry-After", String(result.retryAfterSec));
2269
+ jsonError(res, `This action ran recently; try again in ${result.retryAfterSec}s`, 429);
2270
+ return true;
2271
+ case "script_failed":
2272
+ case "invalid_output":
2273
+ jsonError(res, `Refresh failed: ${result.error}`, 422);
2274
+ return true;
2240
2275
  }
2241
2276
  }
2242
2277