@desplega.ai/agent-swarm 2.7.8 → 2.7.9

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 (309) hide show
  1. package/dist/acp-adapter-dn4gdsgr.js +16 -0
  2. package/dist/{actions-4m1ct4nh.js → actions-g563mbn2.js} +19 -19
  3. package/dist/{amp-adapter-txqh7eqj.js → amp-adapter-q61w05eb.js} +3 -3
  4. package/dist/{anthropic-messages-xey2skwx.js → anthropic-messages-jkva0zps.js} +68 -78
  5. package/dist/{app-e00m45gn.js → app-a66ssc4k.js} +3 -3
  6. package/dist/{assistant-gd08kr9e.js → assistant-p477rjwj.js} +21 -21
  7. package/dist/{azure-openai-responses-26t7j9ra.js → azure-openai-responses-wgtqkbr3.js} +5 -10
  8. package/dist/{boot-args-schema-tjrkpbvm.js → boot-args-schema-h4qj462e.js} +1 -1
  9. package/dist/{boot-reembed-21hbck22.js → boot-reembed-n1ehfbsw.js} +1 -1
  10. package/dist/{boot-reembed-mdxd3wgp.js → boot-reembed-qw4mc0pt.js} +1 -1
  11. package/dist/{boot-scrub-sweep-qy0zr9t2.js → boot-scrub-sweep-9w9jp4sm.js} +4 -4
  12. package/dist/{boot-seeds-n46eaxdv.js → boot-seeds-qdaf3sdy.js} +5 -4
  13. package/dist/{boxd-nv507va8.js → boxd-qbkxy6ap.js} +1 -1
  14. package/dist/{claude-adapter-j37w2eds.js → claude-adapter-348p5hx9.js} +8 -8
  15. package/dist/{claude-managed-adapter-8jvcma9a.js → claude-managed-adapter-h74d06yz.js} +4 -4
  16. package/dist/{claude-managed-setup-rzkjmgc1.js → claude-managed-setup-7787fxtp.js} +4 -4
  17. package/dist/{claude-sdk-session-4k7w73t0.js → claude-sdk-session-hbszbt8a.js} +7901 -7718
  18. package/dist/{cli-sq4n7af4.js → cli-09kmfkmq.js} +4 -6
  19. package/dist/{cli-p3vsj0d3.js → cli-0whpms1z.js} +15 -10
  20. package/dist/{cli-4t50yq3j.js → cli-12xyjhws.js} +29 -12
  21. package/dist/{cli-snpj5zbj.js → cli-1z4qggfe.js} +9 -36
  22. package/dist/{cli-bb0mmdk8.js → cli-21159vea.js} +35 -12
  23. package/dist/{cli-s0qnd4wv.js → cli-28fq781p.js} +1 -1
  24. package/dist/{cli-rjknb2ae.js → cli-2a8py3sx.js} +6 -6
  25. package/dist/{cli-tpksw2nr.js → cli-2ccpqyyf.js} +397 -105
  26. package/dist/{cli-1p89xny0.js → cli-2r0jcc3k.js} +1 -1
  27. package/dist/{cli-rvtm68yy.js → cli-2xv18ywz.js} +2 -2
  28. package/dist/{cli-5xaqj21p.js → cli-3kd08rej.js} +1 -1
  29. package/dist/{cli-bbw9wj9m.js → cli-3tqcamp6.js} +12 -12
  30. package/dist/{cli-ae7mrdf9.js → cli-3vjhs18n.js} +4 -6
  31. package/dist/{cli-ssnjfg5p.js → cli-3xcwp3z8.js} +8 -10
  32. package/dist/{cli-az48n0nr.js → cli-4caa1x7d.js} +67 -64
  33. package/dist/{cli-269q28a1.js → cli-4t0fmf3z.js} +27 -6
  34. package/dist/{cli-1cxrbkk6.js → cli-530hkwdy.js} +7 -9
  35. package/dist/{cli-pz4rk021.js → cli-54vrpgm0.js} +1 -1
  36. package/dist/{cli-eyg1pa00.js → cli-587857ys.js} +7 -7
  37. package/dist/{cli-r9jqcehk.js → cli-5mpy301f.js} +38 -2
  38. package/dist/{cli-xq9r2wtt.js → cli-605nn699.js} +47 -34
  39. package/dist/{cli-msg9m2ny.js → cli-650zv9q9.js} +8 -10
  40. package/dist/cli-6pzk82fd.js +778 -0
  41. package/dist/{cli-84rj785g.js → cli-715t1gx6.js} +9 -9
  42. package/dist/{cli-btfsp3mv.js → cli-9aezs55w.js} +9 -11
  43. package/dist/{cli-dq8x79v8.js → cli-9r5gtwjr.js} +2 -2
  44. package/dist/{cli-jdv6ypxs.js → cli-a0657jmf.js} +2 -2
  45. package/dist/{cli-bshb7jas.js → cli-agyaeef4.js} +3 -3
  46. package/dist/cli-b932gexn.js +5266 -0
  47. package/dist/{cli-gvx71kqv.js → cli-bc779n4v.js} +3 -3
  48. package/dist/{cli-z1srzaf6.js → cli-btc9cb4c.js} +70 -5
  49. package/dist/{cli-s4ss5g59.js → cli-btf6fw39.js} +5 -5
  50. package/dist/{cli-fzachfnf.js → cli-cseh6f8w.js} +5 -5
  51. package/dist/{cli-5j0m12ns.js → cli-cvs2r2vq.js} +13 -11
  52. package/dist/{cli-njwac61j.js → cli-cyn9v8zr.js} +12 -2
  53. package/dist/{cli-a22h291q.js → cli-d6521kb5.js} +1 -1
  54. package/dist/{cli-1b7btd38.js → cli-d84byzn8.js} +869 -5
  55. package/dist/{cli-wx3rhnm0.js → cli-eddnyg3t.js} +1 -1
  56. package/dist/{cli-7axf41jq.js → cli-ejkvvqbe.js} +40 -42
  57. package/dist/{cli-mthwvjre.js → cli-f2zenhja.js} +1 -1
  58. package/dist/{cli-8sdejs1f.js → cli-fayav105.js} +538 -205
  59. package/dist/{cli-ferkkrg9.js → cli-fjggej24.js} +2 -2
  60. package/dist/{cli-g7s47cc5.js → cli-fsgttth8.js} +123 -102
  61. package/dist/{cli-9m8hdawy.js → cli-gce09r66.js} +4 -4
  62. package/dist/{cli-mkk9rnzz.js → cli-gxy8y1dt.js} +51 -4
  63. package/dist/{cli-85gzce7b.js → cli-hae9j8sv.js} +287 -75
  64. package/dist/{cli-agfm16v9.js → cli-hg42n3hx.js} +12 -12
  65. package/dist/{cli-8rpcng8j.js → cli-hwprv9e4.js} +8 -10
  66. package/dist/{cli-yndmfxb3.js → cli-hxpyc9sn.js} +3 -3
  67. package/dist/{cli-ppjxh6ah.js → cli-jfx48xrj.js} +10 -12
  68. package/dist/{cli-5ja3b75e.js → cli-jrp1dt73.js} +1 -1
  69. package/dist/{cli-98rw5dt5.js → cli-jrzkw01m.js} +2 -2
  70. package/dist/{cli-ga786dzg.js → cli-k70e3x9e.js} +18 -17
  71. package/dist/{cli-583frbyr.js → cli-kchjb7qy.js} +1 -1
  72. package/dist/{cli-fmjd0t1y.js → cli-m0cy2vyf.js} +2 -2
  73. package/dist/{cli-c0kqky8y.js → cli-m5akxq8q.js} +1 -1
  74. package/dist/{cli-ycscb2ar.js → cli-m88rpzkh.js} +2 -2
  75. package/dist/{cli-m0hmeqma.js → cli-mnrkgg60.js} +4 -4
  76. package/dist/{cli-yqefz277.js → cli-ms5m5r1y.js} +1 -1
  77. package/dist/{cli-fy6x31ps.js → cli-n5yexkdg.js} +1 -0
  78. package/dist/{cli-w4xnbm46.js → cli-neyag5p6.js} +53 -39
  79. package/dist/cli-p0m0p34z.js +9321 -0
  80. package/dist/{cli-gazw7kpa.js → cli-p17970qv.js} +8 -10
  81. package/dist/{cli-6vcp76qk.js → cli-p74md7t8.js} +42 -23
  82. package/dist/{cli-rjcbm574.js → cli-pr0eze3x.js} +2 -2
  83. package/dist/{cli-3e4snnzf.js → cli-qkdmz8c8.js} +1 -1
  84. package/dist/{cli-0ykgn1h5.js → cli-qmd3mse0.js} +2 -2
  85. package/dist/{cli-t60ajbbp.js → cli-qzt90yze.js} +20 -20
  86. package/dist/cli-rkc97c6a.js +39 -0
  87. package/dist/{cli-qd57hhhh.js → cli-rvhdmjvt.js} +6 -10
  88. package/dist/{cli-kyr67fgx.js → cli-rwymrnaz.js} +18608 -9089
  89. package/dist/{cli-8h0ayw8c.js → cli-serm8zrx.js} +6 -6
  90. package/dist/{cli-66ww7fer.js → cli-sgs5k6yd.js} +1 -1
  91. package/dist/{cli-nbsf8yvn.js → cli-sya22y84.js} +9 -9
  92. package/dist/{cli-318r69gq.js → cli-t73cas91.js} +440 -9
  93. package/dist/{cli-zkky4t5g.js → cli-tqq0hspb.js} +2 -2
  94. package/dist/{cli-z75yxkjh.js → cli-v3cf1ts9.js} +3 -3
  95. package/dist/{cli-xr8908my.js → cli-varqt4d1.js} +26 -14
  96. package/dist/{cli-q4ebh7h7.js → cli-vxh6acp7.js} +6 -6
  97. package/dist/{cli-g83s9ewh.js → cli-xfjrc279.js} +1 -1
  98. package/dist/{cli-32m9eda8.js → cli-xk879m3k.js} +111 -109
  99. package/dist/{cli-7cx2m6t2.js → cli-y5rbvxhc.js} +2 -2
  100. package/dist/{cli-fyhr5h4s.js → cli-y8nbefpb.js} +13 -13
  101. package/dist/{cli-81p9jd57.js → cli-yab6sh8p.js} +9 -3
  102. package/dist/{cli-srye3vdt.js → cli-ybjdc978.js} +1 -1
  103. package/dist/{cli-k5671be5.js → cli-zcfpsfzf.js} +5 -5
  104. package/dist/{cli-vf078p3e.js → cli-zfqg6fzn.js} +1 -1
  105. package/dist/{cli-wemma3jd.js → cli-zgv8gxgs.js} +7 -7
  106. package/dist/cli.js +31 -51
  107. package/dist/{cloudflare-workers-ai-system-one-ef2a980q.js → cloudflare-workers-ai-system-one-9y1zx3pt.js} +2 -2
  108. package/dist/{codex-adapter-88z6psm4.js → codex-adapter-ysq6bzha.js} +7 -7
  109. package/dist/{codex-login-74wa4hmq.js → codex-login-bcda78ge.js} +2 -2
  110. package/dist/{codex-session-runner-zwbcwzvx.js → codex-session-runner-qakzfx93.js} +8 -8
  111. package/dist/{commands-7amxs716.js → commands-rs7hkv9r.js} +3 -3
  112. package/dist/{controller-5rkkc37m.js → controller-r5x9bg6e.js} +4 -4
  113. package/dist/{controllers-connect-m7d4vxxb.js → controllers-connect-498hrxvk.js} +24 -24
  114. package/dist/{cursor-adapter-x1q18693.js → cursor-adapter-d46qszer.js} +2 -2
  115. package/dist/{db-athc68zt.js → db-pm96nhdb.js} +4 -2
  116. package/dist/{db-h2fsfve3.js → db-s13dqhr6.js} +3 -3
  117. package/dist/{devin-adapter-r9phbnc9.js → devin-adapter-z46ep5ph.js} +1 -1
  118. package/dist/{dispatcher-b1yz2bnn.js → dispatcher-j3h81t7m.js} +18 -18
  119. package/dist/{docker-c1a3gqmf.js → docker-866qpzt9.js} +2 -2
  120. package/dist/{dsh-adapter-e33bkxq9.js → dsh-adapter-rw0d5rc4.js} +2 -2
  121. package/dist/{e2b-fr12yccx.js → e2b-jkwfhbcv.js} +2 -2
  122. package/dist/{e2b-x6ywzak3.js → e2b-s16txnpx.js} +2 -3
  123. package/dist/{easter-egg-3d-pv5qnzc8.js → easter-egg-3d-qtgfxgze.js} +1 -1
  124. package/dist/{embedding-space-b4txbwrk.js → embedding-space-xh8p4q4x.js} +6 -6
  125. package/dist/{embeddings-m6zn6tad.js → embeddings-wp745m91.js} +1 -1
  126. package/dist/{event-bus-g0ka3pbw.js → event-bus-e66gh7cc.js} +1 -1
  127. package/dist/{execute-68nwny8m.js → execute-2fzb9z74.js} +1 -1
  128. package/dist/{external-channel-gkckmhzh.js → external-channel-ys21h3sy.js} +2 -2
  129. package/dist/fx-adapter-vz0b9z3g.js +19 -0
  130. package/dist/{google-generative-ai-v94hr7h0.js → google-generative-ai-ytpgncx9.js} +7 -12
  131. package/dist/{google-vertex-g7vr6cf8.js → google-vertex-tqhze5j7.js} +7 -12
  132. package/dist/grok-adapter-spea7zkj.js +19 -0
  133. package/dist/handlers-crckt5dq.js +32 -0
  134. package/dist/{heartbeat-6c2y3267.js → heartbeat-8phn1kdq.js} +21 -21
  135. package/dist/{hook-q5fv0jy2.js → hook-amcj4s10.js} +16 -11
  136. package/dist/{hook-w0q2wcrv.js → hook-bc6n49qn.js} +5 -5
  137. package/dist/{http-bxat8dg3.js → http-7374brv5.js} +642 -260
  138. package/dist/index-4x08sjtk.js +30 -0
  139. package/dist/{index-6cxzwfen.js → index-5a9jtqde.js} +26 -26
  140. package/dist/index-8ybffts4.js +37 -0
  141. package/dist/{index-bxrexmfy.js → index-c9y31ytf.js} +13 -13
  142. package/dist/{index-h39zbx67.js → index-hsad2t3r.js} +31 -31
  143. package/dist/index-nfy4kkg5.js +33 -0
  144. package/dist/{index-cqhqpgrv.js → index-p4hjwbvw.js} +1 -1
  145. package/dist/{index-k7fj52d3.js → index-q5cmtbz5.js} +6 -6
  146. package/dist/{index-fm0czesf.js → index-w4m9z29z.js} +1 -1
  147. package/dist/{keepalive-qnt21cv0.js → keepalive-wy29kbrg.js} +4 -4
  148. package/dist/lead-zdqxsvjn.js +71 -0
  149. package/dist/{llama-cpp-classify-s5c47rwh.js → llama-cpp-classify-nfgswa1m.js} +2 -2
  150. package/dist/{maintenance-btdr68y4.js → maintenance-h2ds9w6c.js} +1 -1
  151. package/dist/{mistral-conversations-3gjpdb4b.js → mistral-conversations-a45tx39a.js} +29 -51
  152. package/dist/{oauth-refresh-sweep-vczabeh4.js → oauth-refresh-sweep-q7mtbyp3.js} +3 -3
  153. package/dist/{onboard-k33ezyq8.js → onboard-vw8r2fdw.js} +68 -16
  154. package/dist/{openai-codex-responses-8pbxq9h5.js → openai-codex-responses-k9gapdze.js} +7 -11
  155. package/dist/{openai-completions-rm00s912.js → openai-completions-xd579js7.js} +50 -58
  156. package/dist/{openai-decisions-8v957r2r.js → openai-decisions-q3hh60wr.js} +2 -2
  157. package/dist/{openai-responses-agxpf96k.js → openai-responses-4d5dx3c7.js} +5 -10
  158. package/dist/{opencode-adapter-3dst2ka7.js → opencode-adapter-mtb0953j.js} +6 -6
  159. package/dist/{openrouter-images-3ecegv0d.js → openrouter-images-xr9gme9x.js} +4 -3
  160. package/dist/{otel-impl-13am7a65.js → otel-impl-j42czw3r.js} +2 -2
  161. package/dist/{pi-messages-pchtw4he.js → pi-messages-hjbv8v10.js} +28 -12
  162. package/dist/{pi-mono-adapter-c53de1gd.js → pi-mono-adapter-zk8pg9jr.js} +23 -26
  163. package/dist/{pricing-refresh-9fcbnq3f.js → pricing-refresh-x7nhv23d.js} +3 -3
  164. package/dist/{rbac-roles-gw0p9h3j.js → rbac-roles-9044425x.js} +16 -2
  165. package/dist/{rbac-roles-66j5h4y5.js → rbac-roles-bzvee6cf.js} +12 -3
  166. package/dist/{render-v2-fg8bmdn4.js → render-v2-t7bn4skz.js} +3 -3
  167. package/dist/{resume-1c8kr3nh.js → resume-x94gemep.js} +7 -7
  168. package/dist/{runtime-tzf9j7tc.js → runtime-breq6fmv.js} +1 -1
  169. package/dist/{session-access-d0atq10j.js → session-access-q7dmqjvt.js} +4 -4
  170. package/dist/{session-source-backfill-0vscqmsa.js → session-source-backfill-440ysamr.js} +3 -3
  171. package/dist/{setup-tvfa7rwe.js → setup-07n4727s.js} +1 -1
  172. package/dist/{typesafe-system-one-0bmqcxfg.js → typesafe-system-one-f2en2knd.js} +2 -2
  173. package/dist/virtual-modules-z5h6mcyf.js +362 -0
  174. package/dist/{work-objects-ks71xqeb.js → work-objects-pnq5y534.js} +21 -21
  175. package/dist/{worker-follow-up-bfx0h9hg.js → worker-follow-up-7z1gfkr8.js} +18 -18
  176. package/dist/worker-y62rvvq3.js +71 -0
  177. package/dist/{x-vmmye1kb.js → x-2fyrt5pp.js} +2 -2
  178. package/openapi.json +1169 -257
  179. package/package.json +8 -10
  180. package/src/apps/catalog.generated.json +299 -82
  181. package/src/apps/page-validator.ts +115 -2
  182. package/src/be/connector-codes.ts +21 -6
  183. package/src/be/db/tasks/read.ts +22 -0
  184. package/src/be/db.ts +4 -2
  185. package/src/be/improvements.ts +416 -0
  186. package/src/be/migrations/274_improvements.sql +27 -0
  187. package/src/be/migrations/275_task_dispatched_by.sql +8 -0
  188. package/src/be/rbac-roles.ts +123 -1
  189. package/src/be/swarm-config-guard.ts +1 -0
  190. package/src/be/users.ts +58 -1
  191. package/src/cli.tsx +5 -25
  192. package/src/commands/codex-login.ts +1 -1
  193. package/src/commands/e2b.ts +0 -1
  194. package/src/commands/onboard/agent-fs-version.ts +1 -1
  195. package/src/commands/onboard/compose-generator.ts +0 -1
  196. package/src/commands/onboard/dashboard-url.ts +31 -0
  197. package/src/commands/onboard/steps/generate.tsx +17 -1
  198. package/src/commands/onboard/steps/post-dashboard.tsx +9 -3
  199. package/src/commands/onboard.tsx +19 -6
  200. package/src/commands/runner.ts +117 -96
  201. package/src/extensions/contract-types.generated.ts +1 -1
  202. package/src/hooks/hook.ts +13 -5
  203. package/src/http/all-routes.ts +1 -0
  204. package/src/http/approval-requests.ts +2 -44
  205. package/src/http/auth.ts +5 -4
  206. package/src/http/codex-oauth-accounts.ts +31 -23
  207. package/src/http/codex-oauth-device.ts +1 -1
  208. package/src/http/codex-oauth-keep-warm.ts +1 -1
  209. package/src/http/improvements.ts +317 -0
  210. package/src/http/index.ts +2 -0
  211. package/src/http/operator-actor.ts +2 -1
  212. package/src/http/person-responder.ts +66 -0
  213. package/src/http/sessions.ts +49 -7
  214. package/src/http/tasks.ts +1 -1
  215. package/src/http/user-roles.ts +11 -2
  216. package/src/http/users.ts +194 -104
  217. package/src/providers/acp-targets.ts +1 -1
  218. package/src/providers/amp-adapter.ts +1 -1
  219. package/src/providers/codex-adapter.ts +8 -1
  220. package/src/providers/codex-models.ts +4 -3
  221. package/src/providers/codex-oauth/auth-json.ts +14 -18
  222. package/src/providers/codex-oauth/storage.ts +2 -2
  223. package/src/rbac/legacy-policy.ts +2 -0
  224. package/src/rbac/permissions.ts +10 -0
  225. package/src/scripts-runtime/types/swarm-extension.d.ts +2 -0
  226. package/src/server.ts +2 -0
  227. package/src/slack/ack.ts +20 -14
  228. package/src/slack/render-v2.ts +42 -17
  229. package/src/tests/api-drain-worker-e2e.test.ts +69 -2
  230. package/src/tests/apps-catalog-drift.test.ts +35 -0
  231. package/src/tests/apps-catalog-table.test.ts +203 -0
  232. package/src/tests/apps-element-assembly.test.ts +28 -0
  233. package/src/tests/apps-smart-links.test.ts +151 -0
  234. package/src/tests/apps-table-filters-migration.test.ts +96 -0
  235. package/src/tests/apps-table-selection-migration.test.ts +95 -0
  236. package/src/tests/chatgpt-subscription-session-bench.test.ts +2 -2
  237. package/src/tests/claude-worker-parity.test.ts +2 -2
  238. package/src/tests/codex-adapter.test.ts +30 -0
  239. package/src/tests/codex-login.test.ts +2 -2
  240. package/src/tests/codex-oauth-accounts.test.ts +48 -12
  241. package/src/tests/codex-oauth-credential-info.test.ts +77 -1
  242. package/src/tests/codex-oauth-device.test.ts +1 -1
  243. package/src/tests/codex-oauth-keep-warm.test.ts +2 -2
  244. package/src/tests/codex-oauth.test.ts +25 -4
  245. package/src/tests/codex-pool.test.ts +2 -2
  246. package/src/tests/db-task-read-contract.test.ts +2 -0
  247. package/src/tests/db-task-write-contract.test.ts +1 -0
  248. package/src/tests/deploy-one-box.test.ts +39 -1
  249. package/src/tests/docs-index-footprint.test.js +3 -3
  250. package/src/tests/fixtures/onboard/content.compose.yml.txt +0 -4
  251. package/src/tests/fixtures/onboard/dev.compose.yml.txt +0 -3
  252. package/src/tests/fixtures/onboard/full-all.compose.yml.txt +0 -11
  253. package/src/tests/fixtures/onboard/full.compose.yml.txt +0 -11
  254. package/src/tests/fixtures/onboard/research.compose.yml.txt +0 -3
  255. package/src/tests/fixtures/onboard/solo.compose.yml.txt +0 -1
  256. package/src/tests/fixtures/prs-app-definition.json.txt +784 -0
  257. package/src/tests/fixtures/prs-filters-migration.patch.json.txt +318 -0
  258. package/src/tests/fixtures/prs-selection-migration.patch.json.txt +373 -0
  259. package/src/tests/fixtures/runner-identity-refresh.ts +3 -0
  260. package/src/tests/fixtures/runner-legacy-resume-prompt.ts +3 -0
  261. package/src/tests/fixtures/runner-task-start-reads.ts +140 -0
  262. package/src/tests/hook-ping-me-order.test.ts +85 -0
  263. package/src/tests/improvements-payload.test.ts +200 -0
  264. package/src/tests/improvements-route.test.ts +419 -0
  265. package/src/tests/install-sh-setup-url.test.ts +190 -0
  266. package/src/tests/onboard-dashboard-output.test.ts +109 -0
  267. package/src/tests/onboard-dashboard-url.test.ts +83 -0
  268. package/src/tests/operator-granted-credentials.test.ts +561 -0
  269. package/src/tests/operator-granted-role-wire.test.ts +222 -0
  270. package/src/tests/rbac-engine.test.ts +2 -0
  271. package/src/tests/runner-context-usage.test.ts +0 -1
  272. package/src/tests/runner-legacy-options.test.ts +55 -0
  273. package/src/tests/runner-slot-reconcile.test.ts +38 -0
  274. package/src/tests/runner-task-start-reads.test.ts +58 -0
  275. package/src/tests/send-task-dispatched-by.test.ts +129 -0
  276. package/src/tests/session-dispatched-tasks.test.ts +115 -0
  277. package/src/tests/session-sharing.test.ts +198 -9
  278. package/src/tests/slack-file-tools-attachments.test.ts +95 -3
  279. package/src/tests/slack-reaction-config.test.ts +39 -0
  280. package/src/tests/slack-render-v2.test.ts +47 -0
  281. package/src/tests/submit-improvement-tool.test.ts +82 -0
  282. package/src/tests/tool-annotations.test.ts +1 -1
  283. package/src/tools/manage-user.ts +88 -58
  284. package/src/tools/send-task.ts +3 -0
  285. package/src/tools/slack-read.ts +61 -33
  286. package/src/tools/submit-improvement.ts +68 -0
  287. package/src/tools/tool-config.ts +3 -0
  288. package/src/types.ts +5 -0
  289. package/src/utils/request-auth-context.ts +6 -1
  290. package/templates/skills/apps/SKILL.md +22 -11
  291. package/templates/skills/apps/content.md +22 -11
  292. package/templates/skills/swarm-scripts/SKILL.md +1 -1
  293. package/templates/skills/swarm-scripts/content.md +1 -1
  294. package/templates/skills/work-on-task/SKILL.md +1 -1
  295. package/templates/skills/work-on-task/content.md +1 -1
  296. package/dist/acp-adapter-vg5hqkvj.js +0 -16
  297. package/dist/cli-5c4hjzne.js +0 -873
  298. package/dist/cli-ae0dnfee.js +0 -20222
  299. package/dist/cli-nn3ysbqk.js +0 -428
  300. package/dist/cli-pc5znp64.js +0 -364
  301. package/dist/fx-adapter-m5jbgd5q.js +0 -19
  302. package/dist/grok-adapter-csvv7sac.js +0 -19
  303. package/dist/handlers-8x5gfbzx.js +0 -32
  304. package/dist/index-hpfte8jd.js +0 -33
  305. package/dist/index-ncf7yb5s.js +0 -30
  306. package/dist/index-vte6dyeh.js +0 -37
  307. package/dist/lead-4bvftzm6.js +0 -71
  308. package/dist/virtual-modules-efxcp740.js +0 -59
  309. package/dist/worker-e7v2bvm9.js +0 -71
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  bedrockProviderModule
3
- } from "./cli-g7s47cc5.js";
3
+ } from "./cli-fsgttth8.js";
4
4
  import {
5
5
  chatThreadOfContextKey,
6
6
  agentContextKey,
@@ -60,6 +60,32 @@ import {
60
60
  closeDb2,
61
61
  getDbClient2,
62
62
  init_runtime2,
63
+ CHAT_SDK_ADAPTER_NAMES,
64
+ isAdapterEntryEnabled,
65
+ init_schema,
66
+ TELEMETRY_RANKING_KEY,
67
+ PUBLIC_RANKING_ENABLED_KEY,
68
+ RANKING_CATEGORIES,
69
+ readTelemetryRanking,
70
+ rankingFormSchema,
71
+ buildListing,
72
+ init_telemetry_ranking,
73
+ API_DRAINING_HEADER,
74
+ init_api_drain2,
75
+ parseTaskToolManifest,
76
+ CHAT_TASK_ONLY_TOOLS,
77
+ isChatSdkTask,
78
+ selectTaskTools,
79
+ init_task_tool_manifest,
80
+ isApiOnlyConfigKey,
81
+ isInternalConfigKey,
82
+ internalConfigKeyError,
83
+ MAX_DB_RETENTION_DAYS,
84
+ DB_RETENTION_TUNING_BOUNDS,
85
+ CODEX_OAUTH_KEEP_WARM_MAX_AGE_HOURS_BOUNDS,
86
+ validateConfigValue,
87
+ validateConfigEntry,
88
+ init_swarm_config_guard,
63
89
  cachedUserRole,
64
90
  cachedUserFunction,
65
91
  configureOrgDomainPersistence,
@@ -110,6 +136,7 @@ import {
110
136
  getTaskById2,
111
137
  TASK_LINEAGE_LIMITS2,
112
138
  getTaskLineage2,
139
+ getTasksDispatchedFrom2,
113
140
  getAllTasks2,
114
141
  getTasksCount2,
115
142
  getTaskStats2,
@@ -147,32 +174,6 @@ import {
147
174
  init_channels,
148
175
  publishWorkerNudge,
149
176
  init_worker_nudges,
150
- CHAT_SDK_ADAPTER_NAMES,
151
- isAdapterEntryEnabled,
152
- init_schema,
153
- TELEMETRY_RANKING_KEY,
154
- PUBLIC_RANKING_ENABLED_KEY,
155
- RANKING_CATEGORIES,
156
- readTelemetryRanking,
157
- rankingFormSchema,
158
- buildListing,
159
- init_telemetry_ranking,
160
- API_DRAINING_HEADER,
161
- init_api_drain2,
162
- parseTaskToolManifest,
163
- CHAT_TASK_ONLY_TOOLS,
164
- isChatSdkTask,
165
- selectTaskTools,
166
- init_task_tool_manifest,
167
- isApiOnlyConfigKey,
168
- isInternalConfigKey,
169
- internalConfigKeyError,
170
- MAX_DB_RETENTION_DAYS,
171
- DB_RETENTION_TUNING_BOUNDS,
172
- CODEX_OAUTH_KEEP_WARM_MAX_AGE_HOURS_BOUNDS,
173
- validateConfigValue,
174
- validateConfigEntry,
175
- init_swarm_config_guard,
176
177
  getDefaultAuthorizationIdForProvider,
177
178
  getOAuthApp,
178
179
  getOAuthAppById,
@@ -479,19 +480,22 @@ import {
479
480
  countScriptRunJournalSteps2,
480
481
  countScriptRunJournalAgentTaskSteps2,
481
482
  init_db4
482
- } from "./cli-w4xnbm46.js";
483
+ } from "./cli-neyag5p6.js";
483
484
  import {
484
485
  PRIMARY_ROLE_NAMES2,
486
+ OperatorGrantedTargetError2,
487
+ assertMayActOnOperatorGrantedTarget2,
485
488
  getUserGrant2,
486
489
  listUserRoles2,
487
490
  listRbacRoles2,
488
491
  InvalidRoleSetError2,
492
+ OperatorGrantedRoleError2,
489
493
  LastAdminError2,
490
494
  assertNotLastAdmin2,
491
495
  setUserRoles2,
492
496
  init_rbac_roles
493
- } from "./cli-z1srzaf6.js";
494
- import"./cli-rjknb2ae.js";
497
+ } from "./cli-btc9cb4c.js";
498
+ import"./cli-2a8py3sx.js";
495
499
  import {
496
500
  upsertModelCatalogOverlay,
497
501
  deleteModelCatalogOverlay,
@@ -499,12 +503,12 @@ import {
499
503
  init_model_catalog_store,
500
504
  requestModelCatalogRefresh2,
501
505
  init_pricing_refresh
502
- } from "./cli-1cxrbkk6.js";
506
+ } from "./cli-530hkwdy.js";
503
507
  import {
504
508
  workflowEventBus2,
505
509
  init_event_bus
506
- } from "./cli-wx3rhnm0.js";
507
- import"./cli-0ykgn1h5.js";
510
+ } from "./cli-eddnyg3t.js";
511
+ import"./cli-qmd3mse0.js";
508
512
  import {
509
513
  require_dist4,
510
514
  getSlackConnectionState,
@@ -535,12 +539,12 @@ import {
535
539
  startSlackApp2,
536
540
  stopSlackApp2,
537
541
  init_app3
538
- } from "./cli-xq9r2wtt.js";
542
+ } from "./cli-605nn699.js";
539
543
  import {
540
544
  retryFailedRun2,
541
545
  cancelWorkflowRun2,
542
546
  init_resume
543
- } from "./cli-nbsf8yvn.js";
547
+ } from "./cli-sya22y84.js";
544
548
  import {
545
549
  DEFAULT_NEGOTIATED_PROTOCOL_VERSION,
546
550
  SUPPORTED_PROTOCOL_VERSIONS,
@@ -945,6 +949,18 @@ import {
945
949
  skipReasonFrom,
946
950
  finalizeSkippedTaskReaction,
947
951
  init_task_skip,
952
+ IMPROVEMENT_TEXT_MAX,
953
+ IMPROVEMENT_STATUSES,
954
+ IMPROVEMENT_SOURCES,
955
+ ImprovementError,
956
+ isImprovementsEnabled,
957
+ getImprovement,
958
+ listImprovements,
959
+ createImprovement,
960
+ approveAndSend,
961
+ discardImprovement,
962
+ improvementLeakHints,
963
+ init_improvements,
948
964
  canClaim,
949
965
  init_budget_admission,
950
966
  emitBudgetRefusalSideEffects,
@@ -964,7 +980,7 @@ import {
964
980
  getEnabledCapabilities,
965
981
  createServer,
966
982
  init_server
967
- } from "./cli-8sdejs1f.js";
983
+ } from "./cli-fayav105.js";
968
984
  import {
969
985
  FilesError,
970
986
  normalizeFilesError,
@@ -996,7 +1012,7 @@ import {
996
1012
  resolvePoolDelivery2,
997
1013
  createPoolAgent2,
998
1014
  init_db2
999
- } from "./cli-eyg1pa00.js";
1015
+ } from "./cli-587857ys.js";
1000
1016
  import {
1001
1017
  duplicateGuardedQueryKey,
1002
1018
  warnIfCorsAllowsAnyOrigin,
@@ -1022,6 +1038,7 @@ import {
1022
1038
  init_utils2,
1023
1039
  hasSessionAccess,
1024
1040
  getSessionRoot,
1041
+ getSessionRoots,
1025
1042
  sessionAccessForRoot,
1026
1043
  listActiveSessionShares,
1027
1044
  toSessionSharesState,
@@ -1051,7 +1068,7 @@ import {
1051
1068
  describeRequestRoute,
1052
1069
  route,
1053
1070
  init_route_def
1054
- } from "./cli-fyhr5h4s.js";
1071
+ } from "./cli-y8nbefpb.js";
1055
1072
  import {
1056
1073
  startPoolRouting,
1057
1074
  stopPoolRouting,
@@ -1064,28 +1081,28 @@ import {
1064
1081
  checkHeartbeatChecklist2,
1065
1082
  runHeartbeatSweep2,
1066
1083
  stopHeartbeat2
1067
- } from "./cli-xr8908my.js";
1068
- import"./cli-8h0ayw8c.js";
1084
+ } from "./cli-varqt4d1.js";
1085
+ import"./cli-serm8zrx.js";
1069
1086
  import {
1070
1087
  runtimeSupervisorStatus,
1071
1088
  startRuntimeSupervisor,
1072
1089
  stopRuntimeSupervisor
1073
- } from "./cli-t60ajbbp.js";
1090
+ } from "./cli-qzt90yze.js";
1074
1091
  import {
1075
1092
  TASK_TITLE_TIMEOUT_MS,
1076
1093
  generateTaskTitle
1077
- } from "./cli-nn3ysbqk.js";
1094
+ } from "./cli-b932gexn.js";
1078
1095
  import"./cli-ns59dc6r.js";
1079
1096
  import {
1080
1097
  ACP_TARGET_IDS
1081
- } from "./cli-a22h291q.js";
1098
+ } from "./cli-d6521kb5.js";
1082
1099
  import {
1083
1100
  reasoningCapability,
1084
1101
  supportedReasoningLevels
1085
- } from "./cli-98rw5dt5.js";
1102
+ } from "./cli-jrzkw01m.js";
1086
1103
  import {
1087
1104
  MAX_RATE_LIMIT_RESET_MS
1088
- } from "./cli-mthwvjre.js";
1105
+ } from "./cli-f2zenhja.js";
1089
1106
  import {
1090
1107
  isLeadChannelMonitoringEnabled,
1091
1108
  ORG_IDENTITY_KEYS,
@@ -1095,14 +1112,14 @@ import {
1095
1112
  isUnknownModelError,
1096
1113
  checkProviderPoolKey,
1097
1114
  writeSkillsToFilesystem
1098
- } from "./cli-gazw7kpa.js";
1115
+ } from "./cli-p17970qv.js";
1099
1116
  import {
1100
1117
  inviteEmailToSharedOrg,
1101
1118
  ensureAgentFsCredentialsForAgent
1102
- } from "./cli-bshb7jas.js";
1119
+ } from "./cli-agyaeef4.js";
1103
1120
  import {
1104
1121
  Anthropic
1105
- } from "./cli-318r69gq.js";
1122
+ } from "./cli-t73cas91.js";
1106
1123
  import {
1107
1124
  isCodexOAuthConfigKey
1108
1125
  } from "./cli-j4bwnpkm.js";
@@ -1115,17 +1132,17 @@ import {
1115
1132
  ampBillsCacheWrites,
1116
1133
  resolveAmpModel,
1117
1134
  init_amp_models
1118
- } from "./cli-3e4snnzf.js";
1135
+ } from "./cli-qkdmz8c8.js";
1119
1136
  import {
1120
1137
  RATING_MODEL_MAX_LENGTH,
1121
1138
  REFERENCES_SOURCE_MAX_LENGTH,
1122
1139
  sanitizeReferencesSource,
1123
1140
  init_types2
1124
- } from "./cli-rvtm68yy.js";
1141
+ } from "./cli-2xv18ywz.js";
1125
1142
  import {
1126
1143
  normalizeModelKey,
1127
1144
  init_pricing_normalize
1128
- } from "./cli-jdv6ypxs.js";
1145
+ } from "./cli-a0657jmf.js";
1129
1146
  import {
1130
1147
  require_dist2,
1131
1148
  getMcpOAuthToken,
@@ -1214,7 +1231,7 @@ import {
1214
1231
  init_typecheck,
1215
1232
  parseSkillContent,
1216
1233
  init_skill_parser
1217
- } from "./cli-tpksw2nr.js";
1234
+ } from "./cli-2ccpqyyf.js";
1218
1235
  import {
1219
1236
  signalProcessGroup,
1220
1237
  detachedProcessGroup,
@@ -1231,7 +1248,7 @@ import {
1231
1248
  forceRefreshAuthorizationOrThrow,
1232
1249
  forceRefreshTokenOrThrow,
1233
1250
  init_ensure_token
1234
- } from "./cli-fzachfnf.js";
1251
+ } from "./cli-cseh6f8w.js";
1235
1252
  import {
1236
1253
  automationIntegrationFixUrl,
1237
1254
  preflightAutomation,
@@ -1275,7 +1292,7 @@ import {
1275
1292
  definitionNodeIds,
1276
1293
  validateDefinition,
1277
1294
  init_definition2
1278
- } from "./cli-7axf41jq.js";
1295
+ } from "./cli-ejkvvqbe.js";
1279
1296
  import {
1280
1297
  _fetchHolder,
1281
1298
  CLIENT_ID,
@@ -1291,7 +1308,7 @@ import {
1291
1308
  loadAllCodexOAuthSlots,
1292
1309
  getValidCodexOAuth,
1293
1310
  init_storage
1294
- } from "./cli-qd57hhhh.js";
1311
+ } from "./cli-rvhdmjvt.js";
1295
1312
  import {
1296
1313
  isMultiRuntimeEnabled,
1297
1314
  init_multi_runtime2
@@ -1299,7 +1316,7 @@ import {
1299
1316
  import {
1300
1317
  require_content_type
1301
1318
  } from "./cli-yjdgea32.js";
1302
- import"./cli-66ww7fer.js";
1319
+ import"./cli-sgs5k6yd.js";
1303
1320
  import {
1304
1321
  isInvalidClientError,
1305
1322
  publicEndpointSsrfOptions,
@@ -1317,11 +1334,30 @@ import {
1317
1334
  revokeMcpToken,
1318
1335
  computeExpiresAt,
1319
1336
  init_mcp_wrapper
1320
- } from "./cli-s4ss5g59.js";
1337
+ } from "./cli-btf6fw39.js";
1321
1338
  import {
1322
1339
  createRuntimeProvider,
1323
1340
  init_runtime_providers
1324
- } from "./cli-yndmfxb3.js";
1341
+ } from "./cli-hxpyc9sn.js";
1342
+ import"./cli-v41kn3cd.js";
1343
+ import {
1344
+ setBedrockProviderModule,
1345
+ init_bedrock_converse_stream_lazy
1346
+ } from "./cli-54vrpgm0.js";
1347
+ import {
1348
+ import_websocket,
1349
+ import_websocket_server,
1350
+ init_wrapper2
1351
+ } from "./cli-69szn7w7.js";
1352
+ import {
1353
+ isRbacEnabled,
1354
+ decideToolAdmission,
1355
+ LEGACY_RULES,
1356
+ setAuditSink,
1357
+ clearAuditSink,
1358
+ can,
1359
+ init_rbac
1360
+ } from "./cli-cyn9v8zr.js";
1325
1361
  import {
1326
1362
  registerSessionTokenConnection,
1327
1363
  init_session_token_connections,
@@ -1348,26 +1384,7 @@ import {
1348
1384
  revokeAgentTokens,
1349
1385
  fingerprintApiKey,
1350
1386
  init_users
1351
- } from "./cli-269q28a1.js";
1352
- import"./cli-v41kn3cd.js";
1353
- import {
1354
- setBedrockProviderModule,
1355
- init_bedrock_converse_stream_lazy
1356
- } from "./cli-pz4rk021.js";
1357
- import {
1358
- import_websocket,
1359
- import_websocket_server,
1360
- init_wrapper2
1361
- } from "./cli-69szn7w7.js";
1362
- import {
1363
- isRbacEnabled,
1364
- decideToolAdmission,
1365
- LEGACY_RULES,
1366
- setAuditSink,
1367
- clearAuditSink,
1368
- can,
1369
- init_rbac
1370
- } from "./cli-njwac61j.js";
1387
+ } from "./cli-4t0fmf3z.js";
1371
1388
  import {
1372
1389
  ASSET_KEY_MAX_LENGTH,
1373
1390
  normalizeAssetKey,
@@ -1525,7 +1542,7 @@ import {
1525
1542
  KvKeySchema,
1526
1543
  KvEntrySchema,
1527
1544
  init_types4
1528
- } from "./cli-5j0m12ns.js";
1545
+ } from "./cli-cvs2r2vq.js";
1529
1546
  import {
1530
1547
  CODEX_AUTH_FAILURE_BENCH_THRESHOLD,
1531
1548
  CODEX_AUTH_WATCH_NAMESPACE,
@@ -1536,7 +1553,7 @@ import {
1536
1553
  IDENTITY_FIELD_BUDGETS,
1537
1554
  IdentityFieldBudgetError,
1538
1555
  init_identity_field_budget
1539
- } from "./cli-dq8x79v8.js";
1556
+ } from "./cli-9r5gtwjr.js";
1540
1557
  import {
1541
1558
  getSlackConfiguration,
1542
1559
  init_config4
@@ -1563,7 +1580,7 @@ import {
1563
1580
  splitCredentialPool,
1564
1581
  selectCredential,
1565
1582
  init_credentials2
1566
- } from "./cli-g83s9ewh.js";
1583
+ } from "./cli-xfjrc279.js";
1567
1584
  import {
1568
1585
  interpolate,
1569
1586
  init_template2,
@@ -1576,7 +1593,7 @@ import {
1576
1593
  } from "./cli-kf3pxxdg.js";
1577
1594
  import {
1578
1595
  init_zod
1579
- } from "./cli-k5671be5.js";
1596
+ } from "./cli-zcfpsfzf.js";
1580
1597
  import {
1581
1598
  NEVER,
1582
1599
  toJSONSchema,
@@ -1591,7 +1608,7 @@ import {
1591
1608
  array2,
1592
1609
  object2,
1593
1610
  looseObject,
1594
- union2,
1611
+ union3,
1595
1612
  discriminatedUnion,
1596
1613
  record2,
1597
1614
  partialRecord,
@@ -1601,11 +1618,11 @@ import {
1601
1618
  preprocess,
1602
1619
  ZodIssueCode,
1603
1620
  exports_coerce
1604
- } from "./cli-agfm16v9.js";
1621
+ } from "./cli-hg42n3hx.js";
1605
1622
  import {
1606
1623
  init_package,
1607
1624
  package_default
1608
- } from "./cli-msg9m2ny.js";
1625
+ } from "./cli-650zv9q9.js";
1609
1626
  import {
1610
1627
  realtimeBus,
1611
1628
  init_bus
@@ -1633,19 +1650,17 @@ import {
1633
1650
  init_api_key
1634
1651
  } from "./cli-pax9q4ff.js";
1635
1652
  import {
1653
+ isAlias,
1654
+ baseUrlEnvVar,
1655
+ providerForKeyVar,
1656
+ init_src2,
1636
1657
  scrubSecrets,
1637
1658
  findSecretsIn,
1638
1659
  scrubObject,
1639
1660
  registerVolatileSecret,
1640
1661
  registerEnvSecrets,
1641
1662
  init_secret_scrubber
1642
- } from "./cli-1b7btd38.js";
1643
- import {
1644
- isAlias,
1645
- baseUrlEnvVar,
1646
- providerForKeyVar,
1647
- init_src2
1648
- } from "./cli-5c4hjzne.js";
1663
+ } from "./cli-d84byzn8.js";
1649
1664
  import {
1650
1665
  __toESM
1651
1666
  } from "./cli-242037k3.js";
@@ -5168,7 +5183,7 @@ var AcpRuntimeConfigSchema = object2({
5168
5183
  args: array2(string2()).optional(),
5169
5184
  envKeys: array2(string2().regex(/^[A-Za-z_][A-Za-z0-9_]*$/)).optional(),
5170
5185
  modelEnvKey: string2().regex(/^[A-Za-z_][A-Za-z0-9_]*$/).nullable().optional(),
5171
- options: record2(string2(), union2([string2(), boolean()])).optional()
5186
+ options: record2(string2(), union3([string2(), boolean()])).optional()
5172
5187
  }).superRefine((value, ctx) => {
5173
5188
  if (value.target === "custom" && !value.command) {
5174
5189
  ctx.addIssue({
@@ -7803,6 +7818,44 @@ async function handleConfig(req, res, pathSegments, queryParams) {
7803
7818
  return false;
7804
7819
  }
7805
7820
 
7821
+ // src/http/person-responder.ts
7822
+ init_rbac_roles();
7823
+ init_rbac();
7824
+ init_request_auth_context();
7825
+ init_request_principal();
7826
+ var AGENT_RESPONSE_REFUSED = "Agents cannot answer approval requests. A person must respond with a user token or the dashboard.";
7827
+ async function approvalResponder(req, options) {
7828
+ const auth = getRequestAuth(req);
7829
+ const rawAgentId = req.headers["x-agent-id"];
7830
+ const headerAgentId = Array.isArray(rawAgentId) ? rawAgentId[0] : rawAgentId;
7831
+ const principal = await agentFirstPrincipal(req, headerAgentId);
7832
+ if (principal.kind !== "user" && principal.kind !== "agent" && auth?.page) {
7833
+ return {
7834
+ ok: false,
7835
+ message: options?.pageMessage ?? "A page session without a signed-in user cannot answer approval requests."
7836
+ };
7837
+ }
7838
+ const user = authUser(auth);
7839
+ const responder = principal.kind === "user" && user ? { kind: "user", user } : principal.kind === "operator" ? { kind: "operator" } : null;
7840
+ const verb = options?.verb ?? "approval.respond";
7841
+ const refused = {
7842
+ ok: false,
7843
+ message: options?.refusedMessage ?? AGENT_RESPONSE_REFUSED
7844
+ };
7845
+ const decision = can({ principal, verb, source: "http" });
7846
+ if (!decision.allow || !responder)
7847
+ return refused;
7848
+ if (responder.kind === "user" && isRbacEnabled()) {
7849
+ const grant = await getUserGrant2(responder.user.id);
7850
+ if (!grant.grantsAll && !grant.verbs.has(verb))
7851
+ return refused;
7852
+ }
7853
+ return { ok: true, responder };
7854
+ }
7855
+ function responderKey(responder) {
7856
+ return responder.kind === "user" ? responder.user.id : "operator";
7857
+ }
7858
+
7806
7859
  // src/http/approval-requests.ts
7807
7860
  init_request_principal();
7808
7861
  init_route_def();
@@ -7832,7 +7885,7 @@ var QuestionInputSchema = QuestionSchema.extend({
7832
7885
  var ApproversSchema = object2({
7833
7886
  users: array2(string2()).optional(),
7834
7887
  roles: array2(string2()).optional(),
7835
- policy: union2([literal2("any"), literal2("all"), object2({ min: number2().int().min(1) })])
7888
+ policy: union3([literal2("any"), literal2("all"), object2({ min: number2().int().min(1) })])
7836
7889
  });
7837
7890
  var NotificationChannelSchema = object2({
7838
7891
  channel: _enum2(["slack", "email"]),
@@ -8000,7 +8053,7 @@ var createRoute = route({
8000
8053
  approvers: object2({
8001
8054
  users: array2(string2()).optional(),
8002
8055
  roles: array2(string2()).optional(),
8003
- policy: union2([
8056
+ policy: union3([
8004
8057
  literal2("any"),
8005
8058
  literal2("all"),
8006
8059
  object2({ min: number2().int().min(1) })
@@ -8110,7 +8163,7 @@ var listRoute = route({
8110
8163
  200: {
8111
8164
  description: "List of approval requests",
8112
8165
  schema: object2({
8113
- approvalRequests: union2([
8166
+ approvalRequests: union3([
8114
8167
  array2(ApprovalRequestSchema),
8115
8168
  array2(ApprovalRequestSummarySchema)
8116
8169
  ])
@@ -8418,28 +8471,6 @@ async function approvalCallerPrincipal(req) {
8418
8471
  const resolvedBy = principal.kind === "user" ? principal.userId : principal.kind === "agent" ? principal.agentId : principal.kind === "operator" ? "operator" : null;
8419
8472
  return { principal, resolvedBy };
8420
8473
  }
8421
- var AGENT_RESPONSE_REFUSED = "Agents cannot answer approval requests. A person must respond with a user token or the dashboard.";
8422
- async function approvalResponder(req) {
8423
- const auth = getRequestAuth(req);
8424
- const rawAgentId = req.headers["x-agent-id"];
8425
- const headerAgentId = Array.isArray(rawAgentId) ? rawAgentId[0] : rawAgentId;
8426
- const principal = await agentFirstPrincipal(req, headerAgentId);
8427
- if (principal.kind !== "user" && principal.kind !== "agent" && auth?.page) {
8428
- return {
8429
- ok: false,
8430
- message: "A page session without a signed-in user cannot answer approval requests."
8431
- };
8432
- }
8433
- const user = authUser(auth);
8434
- const responder = principal.kind === "user" && user ? { kind: "user", user } : principal.kind === "operator" ? { kind: "operator" } : null;
8435
- const decision = can({ principal, verb: "approval.respond", source: "http" });
8436
- if (!decision.allow || !responder)
8437
- return { ok: false, message: AGENT_RESPONSE_REFUSED };
8438
- return { ok: true, responder };
8439
- }
8440
- function responderKey(responder) {
8441
- return responder.kind === "user" ? responder.user.id : "operator";
8442
- }
8443
8474
  function userMatchesListed(user, listed) {
8444
8475
  if (listed === user.id)
8445
8476
  return true;
@@ -8995,7 +9026,6 @@ async function handleBudgets(req, res, pathSegments, queryParams, _myAgentId) {
8995
9026
  init_zod();
8996
9027
  init_crypto();
8997
9028
  init_db4();
8998
- init_api_keys();
8999
9029
  init_auth_json();
9000
9030
  init_flow();
9001
9031
  init_storage();
@@ -9065,10 +9095,6 @@ function readCredentials(row) {
9065
9095
  return null;
9066
9096
  }
9067
9097
  }
9068
- function accountSuffix(row) {
9069
- const credentials = readCredentials(row);
9070
- return credentials ? deriveCodexKeySuffix(credentials.access, credentials.accountId) : null;
9071
- }
9072
9098
  async function accountsResponse() {
9073
9099
  const rows = await accountRows();
9074
9100
  const statuses = await getKeyStatuses2("CODEX_OAUTH", "global", null);
@@ -9088,15 +9114,16 @@ async function accountsResponse() {
9088
9114
  accounts.push(account);
9089
9115
  continue;
9090
9116
  }
9091
- account.suffix = deriveCodexKeySuffix(credentials.access, credentials.accountId);
9117
+ account.suffix = deriveCodexKeySuffix(credentials.access, credentials.accountId, row.slot);
9092
9118
  account.plan = extractChatgptPlanType(credentials.access);
9093
9119
  const profile = decodeJwt(credentials.access)?.["https://api.openai.com/profile"];
9094
9120
  if (profile && typeof profile === "object" && "email" in profile) {
9095
9121
  account.email = typeof profile.email === "string" && profile.email ? profile.email : null;
9096
9122
  }
9097
- const status = statuses.find((entry) => entry.keySuffix === account.suffix);
9123
+ const slotStatuses = statuses.filter((entry) => entry.keySuffix === account.suffix || entry.keyIndex === row.slot);
9124
+ const status = slotStatuses.find((entry) => entry.keySuffix === account.suffix);
9098
9125
  const marker = await getKv2(CODEX_AUTH_WATCH_NAMESPACE, codexAuthBenchMarkerKey(account.suffix));
9099
- const statusBenched = status && status.consecutiveAuthFailures >= CODEX_AUTH_FAILURE_BENCH_THRESHOLD && status.status === "rate_limited";
9126
+ const statusBenched = slotStatuses.some((entry) => entry.consecutiveAuthFailures >= CODEX_AUTH_FAILURE_BENCH_THRESHOLD && entry.status === "rate_limited");
9100
9127
  account.status = marker || statusBenched ? "needs_login" : status ? "ok" : "unchecked";
9101
9128
  accounts.push(account);
9102
9129
  }
@@ -9131,16 +9158,17 @@ async function handleCodexOAuthAccounts(req, res, pathSegments, queryParams) {
9131
9158
  const account = rows.find((row) => row.slot === parsed.params.slot);
9132
9159
  if (!account || !await deleteSwarmConfigByKey2("global", null, account.key))
9133
9160
  return null;
9134
- const suffix = accountSuffix(account);
9135
- if (suffix) {
9136
- const remaining = rows.flatMap((row) => {
9137
- const keySuffix = row === account ? null : accountSuffix(row);
9138
- return keySuffix ? [{ keySuffix, keyIndex: row.slot }] : [];
9139
- });
9140
- await retirePoolKeyStatus("CODEX_OAUTH", suffix, remaining);
9141
- if (!remaining.some((row) => row.keySuffix === suffix)) {
9142
- await deleteKv2(CODEX_AUTH_WATCH_NAMESPACE, codexAuthBenchMarkerKey(suffix));
9143
- }
9161
+ const credentials = readCredentials(account);
9162
+ const suffix = credentials ? deriveCodexKeySuffix(credentials.access, credentials.accountId, account.slot) : null;
9163
+ const retired = await getDbClient2().query(`DELETE FROM api_key_status
9164
+ WHERE keyType = 'CODEX_OAUTH' AND scope = 'global' AND scopeId = ''
9165
+ AND (keyIndex = ? OR keySuffix = ?)
9166
+ RETURNING keySuffix`, [account.slot, suffix]);
9167
+ for (const keySuffix of new Set([
9168
+ ...suffix ? [suffix] : [],
9169
+ ...retired.map((r) => r.keySuffix)
9170
+ ])) {
9171
+ await deleteKv2(CODEX_AUTH_WATCH_NAMESPACE, codexAuthBenchMarkerKey(keySuffix));
9144
9172
  }
9145
9173
  return account.key;
9146
9174
  });
@@ -9252,7 +9280,7 @@ var OnboardingIntegrationMethodSchema = _enum2([
9252
9280
  ]);
9253
9281
  var OnboardingFilesMethodSchema = _enum2(["created", "connected"]);
9254
9282
  var OnboardingFirstTaskMethodSchema = _enum2(["suggestion", "free_form"]);
9255
- var OnboardingStepMethodSchema = union2([
9283
+ var OnboardingStepMethodSchema = union3([
9256
9284
  OnboardingConnectMethodSchema,
9257
9285
  OnboardingNameMethodSchema,
9258
9286
  OnboardingAiMethodSchema,
@@ -9339,7 +9367,7 @@ var OnboardingResponseSchema = object2({
9339
9367
  state: OnboardingStateSchema,
9340
9368
  signals: OnboardingSignalsSchema
9341
9369
  });
9342
- var OnboardingActionSchema = union2([
9370
+ var OnboardingActionSchema = union3([
9343
9371
  object2({ action: literal2("view"), step: OnboardingStepIdSchema }).strict(),
9344
9372
  object2({
9345
9373
  action: literal2("complete"),
@@ -10066,7 +10094,7 @@ async function completeFlow(flowId, credentials) {
10066
10094
  isSecret: true,
10067
10095
  description: `Codex ChatGPT OAuth credentials slot ${slot} (stored by dashboard device login)`
10068
10096
  });
10069
- const keySuffix = deriveCodexKeySuffix(credentials.access, credentials.accountId);
10097
+ const keySuffix = deriveCodexKeySuffix(credentials.access, credentials.accountId, slot);
10070
10098
  const checked = [{ keyIndex: slot, keySuffix, ok: true }];
10071
10099
  await recordKeyValidation2("CODEX_OAUTH", checked, "global", null, { retireAbsent: false });
10072
10100
  await updateOnboardingAiFromCodexDevice({ status: "complete" });
@@ -10246,7 +10274,7 @@ async function handleCodexOAuthKeepWarm(req, res, pathSegments) {
10246
10274
  const slots = await loadAllCodexOAuthSlots(apiUrl, apiKey);
10247
10275
  const results = [];
10248
10276
  for (const { slot, creds } of slots) {
10249
- const keySuffix = deriveCodexKeySuffix(creds.access, creds.accountId);
10277
+ const keySuffix = deriveCodexKeySuffix(creds.access, creds.accountId, slot);
10250
10278
  if (await getKv2(CODEX_AUTH_WATCH_NAMESPACE, codexAuthBenchMarkerKey(keySuffix))) {
10251
10279
  results.push({ slot, keySuffix, outcome: "skipped-benched" });
10252
10280
  continue;
@@ -11188,6 +11216,7 @@ declare module "swarm-extension" {
11188
11216
  workflowRunId?: string | undefined;
11189
11217
  workflowRunStepId?: string | undefined;
11190
11218
  sourceTaskId?: string | undefined;
11219
+ dispatchedByTaskId?: string | undefined;
11191
11220
  outputSchema?: Record<string, unknown> | undefined;
11192
11221
  inheritParentOutputSchema?: boolean | undefined;
11193
11222
  inheritParentRequester?: boolean | undefined;
@@ -11314,6 +11343,7 @@ declare module "swarm-extension" {
11314
11343
  mentionChannelId?: string | undefined;
11315
11344
  dir?: string | undefined;
11316
11345
  parentTaskId?: string | undefined;
11346
+ dispatchedByTaskId?: string | undefined;
11317
11347
  claudeSessionId?: string | undefined;
11318
11348
  model?: string | undefined;
11319
11349
  modelTier?: "smol" | "regular" | "smart" | "ultra" | undefined;
@@ -15668,6 +15698,268 @@ async function handleHeartbeat(req, res, pathSegments) {
15668
15698
  return false;
15669
15699
  }
15670
15700
 
15701
+ // src/http/improvements.ts
15702
+ init_zod();
15703
+ init_improvements();
15704
+ init_rbac();
15705
+ init_request_principal();
15706
+ init_route_def();
15707
+ init_utils2();
15708
+ var ImprovementSchema = object2({
15709
+ id: string2(),
15710
+ text: string2(),
15711
+ email: string2().nullable(),
15712
+ status: _enum2(IMPROVEMENT_STATUSES),
15713
+ source: _enum2(IMPROVEMENT_SOURCES),
15714
+ requestedByAgentId: string2().nullable(),
15715
+ approvedBy: string2().nullable(),
15716
+ approvedAt: string2().nullable(),
15717
+ sentAt: string2().nullable(),
15718
+ proxyStatus: number2().nullable(),
15719
+ proxyId: string2().nullable(),
15720
+ proxyError: string2().nullable(),
15721
+ createdAt: string2(),
15722
+ updatedAt: string2(),
15723
+ leakHints: array2(string2()).optional().describe("Substrings that look install-specific (agent, repo, host, org or user email). Pending and failed rows only. They warn; they never block.")
15724
+ });
15725
+ var EmailSchema = string2().max(320, "Email must be at most 320 characters").email("Email must be a valid email address");
15726
+ var PERSON_REFUSED = "Agents cannot approve improvements. A person must approve with a user token or the dashboard.";
15727
+ var listRoute3 = route({
15728
+ method: "get",
15729
+ path: "/api/improvements",
15730
+ pattern: ["api", "improvements"],
15731
+ summary: "List product improvements",
15732
+ description: "Lists improvements newest first, with `enabled` for the `IMPROVEMENTS_ENABLED` switch: every pending and failed row, plus the newest 100 other rows. Pending and failed rows carry `leakHints` for the approver.",
15733
+ tags: ["Improvements"],
15734
+ responses: {
15735
+ 200: {
15736
+ description: "Improvements and the switch state",
15737
+ schema: object2({ enabled: boolean(), improvements: array2(ImprovementSchema) })
15738
+ }
15739
+ },
15740
+ auth: { apiKey: true }
15741
+ });
15742
+ var createRoute2 = route({
15743
+ method: "post",
15744
+ path: "/api/improvements",
15745
+ pattern: ["api", "improvements"],
15746
+ summary: "Draft a product improvement, or send one as a person",
15747
+ description: "Stores the text, scrubbed of known secrets, as `pending_approval`. An agent caller always gets a pending draft. A person (user token, or the shared key with no agent identity) may pass `sendNow: true` to approve and send in one call, unless scrubbing changed the text: then it stays pending so they can review it. `sendNow` needs a valid `email` (400 without one); a draft does not. Only `install_id` (always), `text` and `email` are sent to desplega.",
15748
+ tags: ["Improvements"],
15749
+ body: object2({
15750
+ text: string2().max(IMPROVEMENT_TEXT_MAX * 2),
15751
+ email: EmailSchema.optional(),
15752
+ sendNow: boolean().optional(),
15753
+ source: _enum2(["ui", "api"]).optional()
15754
+ }),
15755
+ responses: {
15756
+ 200: {
15757
+ description: "A person's `sendNow` was approved and sent (see `status`)",
15758
+ schema: object2({ improvement: ImprovementSchema })
15759
+ },
15760
+ 201: {
15761
+ description: "Draft stored as `pending_approval`",
15762
+ schema: object2({ improvement: ImprovementSchema })
15763
+ },
15764
+ 400: { description: "Invalid text or email, or `sendNow` without an email" },
15765
+ 403: { description: "The caller may not draft improvements" },
15766
+ 409: { description: "Improvements are turned off" }
15767
+ },
15768
+ auth: { apiKey: true },
15769
+ rbac: { permission: "improvement.submit" }
15770
+ });
15771
+ var approveRoute = route({
15772
+ method: "post",
15773
+ path: "/api/improvements/{id}/approve",
15774
+ pattern: ["api", "improvements", null, "approve"],
15775
+ summary: "Approve and send a drafted improvement",
15776
+ description: "Only a person may approve: a user token, or the shared key with no agent identity (recorded as `operator`). `approvedBy` is taken from the credential, never the body. `email` is required and is sent with the text and the install id. The stored text is sent as is; to change it, discard and draft again. A failed send can be approved again. There is no automatic retry.",
15777
+ tags: ["Improvements"],
15778
+ params: object2({ id: string2().uuid() }),
15779
+ body: object2({ email: EmailSchema.describe("The approver's email, sent with the text.") }),
15780
+ responses: {
15781
+ 200: {
15782
+ description: "Approved. `status` is `sent`, or `failed` with the proxy status and error.",
15783
+ schema: object2({ improvement: ImprovementSchema })
15784
+ },
15785
+ 400: { description: "Missing or invalid email" },
15786
+ 403: { description: "Caller is an agent" },
15787
+ 404: { description: "Not found" },
15788
+ 409: { description: "Already sent, sending or discarded, or improvements are turned off" }
15789
+ },
15790
+ auth: { apiKey: true },
15791
+ rbac: { permission: "improvement.approve" }
15792
+ });
15793
+ var discardRoute = route({
15794
+ method: "post",
15795
+ path: "/api/improvements/{id}/discard",
15796
+ pattern: ["api", "improvements", null, "discard"],
15797
+ summary: "Discard a drafted improvement",
15798
+ description: "A person may discard any pending or failed improvement. An agent may discard only a draft it requested.",
15799
+ tags: ["Improvements"],
15800
+ params: object2({ id: string2().uuid() }),
15801
+ responses: {
15802
+ 200: {
15803
+ description: "Discarded",
15804
+ schema: object2({ improvement: ImprovementSchema })
15805
+ },
15806
+ 403: { description: "Caller is an agent that did not request this draft" },
15807
+ 404: { description: "Not found" },
15808
+ 409: { description: "Already sent or discarded, or improvements are turned off" }
15809
+ },
15810
+ auth: { apiKey: true },
15811
+ rbac: { permission: "improvement.submit" }
15812
+ });
15813
+ function headerAgentId(req) {
15814
+ const raw = req.headers["x-agent-id"];
15815
+ return Array.isArray(raw) ? raw[0] : raw;
15816
+ }
15817
+ function writeImprovementError(res, error) {
15818
+ if (!(error instanceof ImprovementError))
15819
+ return false;
15820
+ const status = error.code === "invalid_text" || error.code === "invalid_email" ? 400 : error.code === "not_found" ? 404 : 409;
15821
+ if (error.code === "improvements_disabled") {
15822
+ res.writeHead(409, { "Content-Type": "application/json" });
15823
+ res.end(JSON.stringify({ error: error.message, code: error.code }));
15824
+ return true;
15825
+ }
15826
+ jsonError(res, error.message, status);
15827
+ return true;
15828
+ }
15829
+ async function withLeakHints(improvement) {
15830
+ if (improvement.status !== "pending_approval" && improvement.status !== "failed") {
15831
+ return improvement;
15832
+ }
15833
+ return { ...improvement, leakHints: await improvementLeakHints(improvement.text) };
15834
+ }
15835
+ async function improvementsEndpoint() {
15836
+ return telemetryProxyEndpoint("/v1/improvements");
15837
+ }
15838
+ async function handleImprovements(req, res, pathSegments, queryParams) {
15839
+ if (listRoute3.match(req.method, pathSegments)) {
15840
+ const parsed = await listRoute3.parse(req, res, pathSegments, queryParams);
15841
+ if (!parsed)
15842
+ return true;
15843
+ const rows = await listImprovements();
15844
+ listRoute3.respond(res, 200, {
15845
+ enabled: await isImprovementsEnabled(),
15846
+ improvements: await Promise.all(rows.map(withLeakHints))
15847
+ });
15848
+ return true;
15849
+ }
15850
+ if (createRoute2.match(req.method, pathSegments)) {
15851
+ const parsed = await createRoute2.parse(req, res, pathSegments, queryParams);
15852
+ if (!parsed)
15853
+ return true;
15854
+ const { text, email, sendNow, source } = parsed.body;
15855
+ if (sendNow && !email) {
15856
+ jsonError(res, "sendNow needs a valid email.", 400);
15857
+ return true;
15858
+ }
15859
+ const principal = await agentFirstPrincipal(req, headerAgentId(req));
15860
+ const decision = can({ principal, verb: "improvement.submit", source: "http" });
15861
+ if (!decision.allow) {
15862
+ jsonError(res, decision.reason, 403);
15863
+ return true;
15864
+ }
15865
+ const agentId = principal.kind === "agent" ? principal.agentId || null : null;
15866
+ const userId = principal.kind === "user" ? principal.userId : null;
15867
+ try {
15868
+ const { improvement, scrubChanged } = await createImprovement({
15869
+ text,
15870
+ source: source ?? "api",
15871
+ requestedByAgentId: agentId,
15872
+ createdBy: userId
15873
+ });
15874
+ if (sendNow && email && !scrubChanged) {
15875
+ const person = await approvalResponder(req, {
15876
+ verb: "improvement.approve",
15877
+ refusedMessage: PERSON_REFUSED
15878
+ });
15879
+ if (person.ok) {
15880
+ const sent = await approveAndSend(improvement.id, {
15881
+ approvedBy: responderKey(person.responder),
15882
+ email,
15883
+ endpoint: await improvementsEndpoint(),
15884
+ updatedBy: person.responder.kind === "user" ? person.responder.user.id : null
15885
+ });
15886
+ createRoute2.respond(res, 200, { improvement: sent });
15887
+ return true;
15888
+ }
15889
+ }
15890
+ createRoute2.respond(res, 201, { improvement: await withLeakHints(improvement) });
15891
+ } catch (error) {
15892
+ if (!writeImprovementError(res, error))
15893
+ throw error;
15894
+ }
15895
+ return true;
15896
+ }
15897
+ if (approveRoute.match(req.method, pathSegments)) {
15898
+ const parsed = await approveRoute.parse(req, res, pathSegments, queryParams);
15899
+ if (!parsed)
15900
+ return true;
15901
+ const person = await approvalResponder(req, {
15902
+ verb: "improvement.approve",
15903
+ refusedMessage: PERSON_REFUSED,
15904
+ pageMessage: "A page session without a signed-in user cannot approve improvements."
15905
+ });
15906
+ if (!person.ok) {
15907
+ jsonError(res, person.message, 403);
15908
+ return true;
15909
+ }
15910
+ try {
15911
+ const improvement = await approveAndSend(parsed.params.id, {
15912
+ approvedBy: responderKey(person.responder),
15913
+ email: parsed.body.email,
15914
+ endpoint: await improvementsEndpoint(),
15915
+ updatedBy: person.responder.kind === "user" ? person.responder.user.id : null
15916
+ });
15917
+ approveRoute.respond(res, 200, { improvement });
15918
+ } catch (error) {
15919
+ if (!writeImprovementError(res, error))
15920
+ throw error;
15921
+ }
15922
+ return true;
15923
+ }
15924
+ if (discardRoute.match(req.method, pathSegments)) {
15925
+ const parsed = await discardRoute.parse(req, res, pathSegments, queryParams);
15926
+ if (!parsed)
15927
+ return true;
15928
+ const existing = await getImprovement(parsed.params.id);
15929
+ if (!existing) {
15930
+ jsonError(res, "Improvement not found", 404);
15931
+ return true;
15932
+ }
15933
+ const principal = await agentFirstPrincipal(req, headerAgentId(req));
15934
+ let updatedBy = null;
15935
+ if (principal.kind === "agent") {
15936
+ if (!principal.agentId || principal.agentId !== existing.requestedByAgentId) {
15937
+ jsonError(res, "An agent may discard only an improvement it drafted.", 403);
15938
+ return true;
15939
+ }
15940
+ } else {
15941
+ const person = await approvalResponder(req, {
15942
+ verb: "improvement.approve",
15943
+ refusedMessage: "Only a person or the drafting agent may discard this improvement."
15944
+ });
15945
+ if (!person.ok) {
15946
+ jsonError(res, person.message, 403);
15947
+ return true;
15948
+ }
15949
+ updatedBy = person.responder.kind === "user" ? person.responder.user.id : null;
15950
+ }
15951
+ try {
15952
+ const improvement = await discardImprovement(parsed.params.id, { updatedBy });
15953
+ discardRoute.respond(res, 200, { improvement });
15954
+ } catch (error) {
15955
+ if (!writeImprovementError(res, error))
15956
+ throw error;
15957
+ }
15958
+ return true;
15959
+ }
15960
+ return false;
15961
+ }
15962
+
15671
15963
  // src/http/inbox-state.ts
15672
15964
  init_zod();
15673
15965
  init_db4();
@@ -16226,7 +16518,7 @@ async function resolveAppUrl() {
16226
16518
  // src/http/integrations.ts
16227
16519
  init_route_def();
16228
16520
  init_utils2();
16229
- var ClaudeManagedTestResultSchema = union2([
16521
+ var ClaudeManagedTestResultSchema = union3([
16230
16522
  object2({
16231
16523
  ok: literal2(true),
16232
16524
  agentName: string2().nullable(),
@@ -18649,7 +18941,7 @@ var DiscoveryResultSchema = object2({
18649
18941
  bearerMethodsSupported: array2(string2()).nullable(),
18650
18942
  tokenEndpointAuthMethodsSupported: array2(string2()).nullable()
18651
18943
  });
18652
- var MetadataResponseSchema = union2([
18944
+ var MetadataResponseSchema = union3([
18653
18945
  object2({ requiresOAuth: literal2(false) }),
18654
18946
  DiscoveryResultSchema
18655
18947
  ]);
@@ -21604,7 +21896,7 @@ var DEFAULT_METRIC_MAX_ROWS = 100;
21604
21896
  var HARD_METRIC_MAX_ROWS = 500;
21605
21897
  var VARIABLE_TOKEN_RE = /^\{\{([a-zA-Z][a-zA-Z0-9_]*)\}\}$/;
21606
21898
  var MetricRunBodySchema = object2({
21607
- variables: record2(string2(), union2([string2(), number2(), boolean(), _null()])).optional()
21899
+ variables: record2(string2(), union3([string2(), number2(), boolean(), _null()])).optional()
21608
21900
  }).optional();
21609
21901
  function slugify(input) {
21610
21902
  const slug = input.toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
@@ -21765,7 +22057,7 @@ var listMetricsRoute = route({
21765
22057
  200: {
21766
22058
  description: "Metric definitions",
21767
22059
  schema: object2({
21768
- metrics: array2(union2([MetricSchema, metricSummarySchema])),
22060
+ metrics: array2(union3([MetricSchema, metricSummarySchema])),
21769
22061
  total: number2(),
21770
22062
  limit: number2(),
21771
22063
  offset: number2()
@@ -21820,7 +22112,7 @@ var metricRunWidgetResultSchema = object2({
21820
22112
  });
21821
22113
  var metricRunResultSchema = object2({
21822
22114
  metric: MetricSchema,
21823
- variables: record2(string2(), union2([string2(), number2(), boolean(), _null()])),
22115
+ variables: record2(string2(), union3([string2(), number2(), boolean(), _null()])),
21824
22116
  widgets: array2(object2({
21825
22117
  widget: MetricWidgetSchema,
21826
22118
  result: metricRunWidgetResultSchema
@@ -24542,13 +24834,13 @@ var listTasks = route({
24542
24834
  offset: exports_coerce.number().int().optional(),
24543
24835
  fields: _enum2(["full", "slim", "timeline"]).optional(),
24544
24836
  includeTotal: _enum2(["true", "false"]).optional(),
24545
- scope: _enum2(["all"]).optional().describe("all: every user's tasks, read-only, for a user with an admin role or session.read.all; ignored for anyone else. The X-Swarm-Session-Scope: all header opts in the same way.")
24837
+ scope: _enum2(["all"]).optional().describe("all: every user's tasks, read-only, for a user whose role lists session.read.all (the built-in auditor role; the grant-all admin role alone does not count); ignored for anyone else. The X-Swarm-Session-Scope: all header opts in the same way.")
24546
24838
  }),
24547
24839
  responses: {
24548
24840
  200: {
24549
24841
  description: "Paginated task list",
24550
24842
  schema: object2({
24551
- tasks: union2([
24843
+ tasks: union3([
24552
24844
  array2(AgentTaskSchema),
24553
24845
  array2(AgentTaskSummarySchema),
24554
24846
  array2(AgentTaskTimelineItemSchema)
@@ -24640,7 +24932,7 @@ var updateSession = route({
24640
24932
  summary: "Update provider session ID and harness metadata for a task",
24641
24933
  tags: ["Tasks"],
24642
24934
  params: object2({ id: string2() }),
24643
- body: union2([
24935
+ body: union3([
24644
24936
  object2({
24645
24937
  claudeSessionId: string2().min(1),
24646
24938
  provider: literal2("devin"),
@@ -30409,7 +30701,7 @@ var ResolveResultSchema = object2({
30409
30701
  skipped: boolean(),
30410
30702
  unresolved: array2(string2())
30411
30703
  });
30412
- var DbResolveResultSchema = union2([
30704
+ var DbResolveResultSchema = union3([
30413
30705
  object2({ template: PromptTemplateResponseSchema }),
30414
30706
  object2({ skip: literal2(true) })
30415
30707
  ]).nullable();
@@ -30559,7 +30851,7 @@ var deleteByIdRoute = route({
30559
30851
  },
30560
30852
  auth: { apiKey: true }
30561
30853
  });
30562
- var listRoute3 = route({
30854
+ var listRoute4 = route({
30563
30855
  method: "get",
30564
30856
  path: "/api/prompt-templates",
30565
30857
  pattern: ["api", "prompt-templates"],
@@ -30739,8 +31031,8 @@ ${templateBody}` : templateBody;
30739
31031
  }
30740
31032
  return true;
30741
31033
  }
30742
- if (listRoute3.match(req.method, pathSegments)) {
30743
- const parsed = await listRoute3.parse(req, res, pathSegments, queryParams);
31034
+ if (listRoute4.match(req.method, pathSegments)) {
31035
+ const parsed = await listRoute4.parse(req, res, pathSegments, queryParams);
30744
31036
  if (!parsed)
30745
31037
  return true;
30746
31038
  const templates = getPromptTemplates2({
@@ -30749,7 +31041,7 @@ ${templateBody}` : templateBody;
30749
31041
  scopeId: parsed.query.scopeId || undefined,
30750
31042
  isDefault: parsed.query.isDefault ? parsed.query.isDefault === "true" : undefined
30751
31043
  });
30752
- listRoute3.respond(res, 200, { templates: templates.map(toPromptTemplateResponse) });
31044
+ listRoute4.respond(res, 200, { templates: templates.map(toPromptTemplateResponse) });
30753
31045
  return true;
30754
31046
  }
30755
31047
  if (upsertRoute.match(req.method, pathSegments)) {
@@ -31925,7 +32217,7 @@ var listSchedules = route({
31925
32217
  200: {
31926
32218
  description: "List of schedules",
31927
32219
  schema: object2({
31928
- schedules: union2([
32220
+ schedules: union3([
31929
32221
  array2(scheduleSummaryWithFavoriteSchema),
31930
32222
  array2(scheduleWithFavoriteSchema)
31931
32223
  ]),
@@ -32427,9 +32719,9 @@ var McpJsonRpcErrorSchema = object2({
32427
32719
  message: string2().optional(),
32428
32720
  data: unknown().optional()
32429
32721
  });
32430
- var McpToolCallEnvelopeSchema = union2([
32722
+ var McpToolCallEnvelopeSchema = union3([
32431
32723
  object2({ ok: literal2(true), result: McpToolCallResultSchema }),
32432
- object2({ ok: literal2(false), error: union2([McpJsonRpcErrorSchema, string2()]) })
32724
+ object2({ ok: literal2(false), error: union3([McpJsonRpcErrorSchema, string2()]) })
32433
32725
  ]);
32434
32726
  var mcpCallRoute = route({
32435
32727
  method: "post",
@@ -32451,7 +32743,7 @@ var mcpCallRoute = route({
32451
32743
  404: { description: "Script connection or agent not found" }
32452
32744
  }
32453
32745
  });
32454
- var SqlQueryEnvelopeSchema = union2([
32746
+ var SqlQueryEnvelopeSchema = union3([
32455
32747
  object2({
32456
32748
  ok: literal2(true),
32457
32749
  rows: array2(record2(string2(), unknown())),
@@ -33255,7 +33547,7 @@ var disconnectOAuthAppRoute = route({
33255
33547
  responses: {
33256
33548
  200: {
33257
33549
  description: "Disconnect result",
33258
- schema: union2([
33550
+ schema: union3([
33259
33551
  object2({ disconnected: literal2(false), message: string2() }),
33260
33552
  object2({ disconnected: literal2(true), revocationAttempted: boolean() })
33261
33553
  ])
@@ -35599,7 +35891,7 @@ var patchScriptApiRoute = route({
35599
35891
  responses: {
35600
35892
  200: {
35601
35893
  description: "Updated endpoint",
35602
- schema: union2([ScriptApiRecordSchema, _null()])
35894
+ schema: union3([ScriptApiRecordSchema, _null()])
35603
35895
  },
35604
35896
  404: { description: "Endpoint not found" }
35605
35897
  },
@@ -36834,7 +37126,7 @@ var AgentTaskSummarySchema2 = AgentTaskSchema.pick({
36834
37126
  totalCostUsd: true
36835
37127
  });
36836
37128
  var SessionListItemSchema = object2({
36837
- root: union2([AgentTaskSchema, AgentTaskSummarySchema2]),
37129
+ root: union3([AgentTaskSchema, AgentTaskSummarySchema2]),
36838
37130
  chainTaskCount: number2().int(),
36839
37131
  lastActivityAt: string2(),
36840
37132
  latestStatus: AgentTaskStatusSchema,
@@ -37152,7 +37444,7 @@ var listSessions = route({
37152
37444
  status: _enum2(["running", "failed", "needs"]).optional(),
37153
37445
  withUserId: string2().min(1).optional(),
37154
37446
  fields: _enum2(["full", "slim"]).optional(),
37155
- scope: _enum2(["mine", "shared", "tree", "all"]).optional().describe("mine: owned sessions. shared: sessions shared with me. tree: Sessions that GET /api/session-tree counts: mine plus shared with me, no ownerless roots. A bypass actor sees every root with tree scope. all: every user's sessions, read-only, for a user with an admin role or session.read.all; ignored for anyone else. The X-Swarm-Session-Scope: all header opts in the same way, also for tree."),
37447
+ scope: _enum2(["mine", "shared", "tree", "all"]).optional().describe("mine: owned sessions. shared: sessions shared with me. tree: Sessions that GET /api/session-tree counts: mine plus shared with me, no ownerless roots. A bypass actor sees every root with tree scope. all: every user's sessions, read-only, for a user whose role lists session.read.all (the built-in auditor role; the grant-all admin role alone does not count); ignored for anyone else. The X-Swarm-Session-Scope: all header opts in the same way, also for tree."),
37156
37448
  show: SessionShowSchema,
37157
37449
  hideSource: SessionHideSourceSchema,
37158
37450
  showSource: SessionShowSourceSchema
@@ -37312,6 +37604,29 @@ async function checkSessionMove(rootTaskId, actor, req, myAgentId, options = {})
37312
37604
  }
37313
37605
  return { taskIds: tasks.map((task) => task.id) };
37314
37606
  }
37607
+ async function withDispatchedTasks(chain, sessionRootId, actor) {
37608
+ const dispatched = await getTasksDispatchedFrom2(chain.map((task) => task.id));
37609
+ if (dispatched.length === 0)
37610
+ return chain;
37611
+ const roots = await getSessionRoots(dispatched.map((task) => task.id));
37612
+ const foreignRoots = new Map;
37613
+ for (const root of roots.values()) {
37614
+ if (root.id !== sessionRootId)
37615
+ foreignRoots.set(root.id, root);
37616
+ }
37617
+ const readable = new Set([sessionRootId]);
37618
+ await Promise.all([...foreignRoots.values()].map(async (root) => {
37619
+ if (await accessForRoot(actor, root) !== "none")
37620
+ readable.add(root.id);
37621
+ }));
37622
+ const visible = dispatched.filter((task) => {
37623
+ const root = roots.get(task.id);
37624
+ return root !== undefined && readable.has(root.id);
37625
+ });
37626
+ if (visible.length === 0)
37627
+ return chain;
37628
+ return [...chain, ...visible].sort((a, b) => a.createdAt.localeCompare(b.createdAt));
37629
+ }
37315
37630
  var getSession = route({
37316
37631
  method: "get",
37317
37632
  path: "/api/sessions/{rootTaskId}",
@@ -37322,7 +37637,7 @@ var getSession = route({
37322
37637
  params: object2({ rootTaskId: string2() }),
37323
37638
  responses: {
37324
37639
  200: {
37325
- description: "Root task + chain (ordered by createdAt), plus the caller's `access` and the session `owner`",
37640
+ description: "Root task + chain (ordered by createdAt), plus the caller's `access` and the session `owner`. The chain also holds tasks a chain task dispatched (`dispatchedByTaskId`) that sit elsewhere: in the same session, or in another session the caller can read.",
37326
37641
  schema: object2({
37327
37642
  root: TaskWithSteeringSchema,
37328
37643
  chain: array2(TaskWithSteeringSchema),
@@ -37660,7 +37975,7 @@ async function handleSessions(req, res, pathSegments, queryParams, myAgentId) {
37660
37975
  id: sessionRoot.requestedByUserId,
37661
37976
  name: ownerUser?.name ?? sessionRoot.requestedByUserId
37662
37977
  } : null;
37663
- const chain = await getRootTaskChain2(parsed.params.rootTaskId);
37978
+ const chain = await withDispatchedTasks(await getRootTaskChain2(parsed.params.rootTaskId), sessionRoot.id, actor);
37664
37979
  const tasks = [root, ...chain];
37665
37980
  const [steering, citations, approvals, read, groupKey] = await Promise.all([
37666
37981
  getTaskSteeringFieldsForTasks(tasks),
@@ -39165,7 +39480,7 @@ var listScheduledTasks = route({
39165
39480
  200: {
39166
39481
  description: "Scheduled tasks list",
39167
39482
  schema: object2({
39168
- scheduledTasks: union2([
39483
+ scheduledTasks: union3([
39169
39484
  array2(ScheduledTaskSchema),
39170
39485
  array2(scheduleSummaryWithFavoriteSchema)
39171
39486
  ])
@@ -39495,7 +39810,7 @@ var JiraStatusPayloadSchema = object2({
39495
39810
  webhookIds: array2(JiraWebhookIdEntrySchema),
39496
39811
  manualWebhookInstructions: string2().optional()
39497
39812
  });
39498
- var JiraWebhookEventResultSchema = union2([
39813
+ var JiraWebhookEventResultSchema = union3([
39499
39814
  object2({ status: literal2("accepted") }),
39500
39815
  object2({ status: literal2("duplicate") }),
39501
39816
  object2({ status: literal2("ignored"), reason: literal2("invalid-json") })
@@ -40191,7 +40506,8 @@ function getOperatorActor(req, res) {
40191
40506
  const auth = getRequestAuth(req);
40192
40507
  const userId = authUserId(auth);
40193
40508
  if (userId) {
40194
- return { kind: "user", id: userId };
40509
+ const tokenId = auth?.kind === "user" ? auth.tokenId : undefined;
40510
+ return tokenId ? { kind: "user", id: userId, tokenId } : { kind: "user", id: userId };
40195
40511
  }
40196
40512
  if (isOperatorAuth(auth)) {
40197
40513
  return { kind: "operator", id: auth.fingerprint };
@@ -40242,14 +40558,16 @@ var setUserRolesRoute = route({
40242
40558
  pattern: ["api", "users", null, "roles"],
40243
40559
  operationId: "users_setRbacRoles",
40244
40560
  summary: "Set a user's RBAC roles",
40245
- description: `Replaces the user's roles. The set holds exactly one of ${PRIMARY_ROLE_NAMES2.join(", ")} plus any extra roles. Demoting a user below admin removes the ability to answer approval requests, even when the user is listed as an approver. Fails with 409 when it would leave no active admin.`,
40561
+ description: `Replaces the user's roles. The set holds exactly one of ${PRIMARY_ROLE_NAMES2.join(", ")} plus any extra roles. Demoting a user below admin removes the ability to answer approval requests, even when the user is listed as an approver. Fails with 409 when it would leave no active admin. Adding a role that grants session.read.all (the built-in auditor role) requires the operator key: every new user is a grant-all admin, so a user token could grant it to itself. Adding such a role revokes the user's MCP tokens and spends its unused connector and invite codes.`,
40246
40562
  tags: ["Users"],
40247
40563
  params: object2({ id: string2().min(1) }),
40248
40564
  body: object2({ roles: array2(string2().min(1)).min(1) }).strict(),
40249
40565
  responses: {
40250
40566
  200: { description: "The user's roles after the change", schema: UserRbacRolesSchema },
40251
40567
  400: { description: "Invalid role set" },
40252
- 403: { description: "Not allowed to change roles" },
40568
+ 403: {
40569
+ description: "Not allowed to change roles, or adding an operator-only role with a user token"
40570
+ },
40253
40571
  404: { description: "User not found" },
40254
40572
  409: { description: "Would leave no active admin" }
40255
40573
  },
@@ -40330,6 +40648,10 @@ async function handleUserRoles(req, res, pathSegments, queryParams) {
40330
40648
  jsonError(res, err.message, 400);
40331
40649
  return true;
40332
40650
  }
40651
+ if (err instanceof OperatorGrantedRoleError2) {
40652
+ jsonError(res, err.message, 403);
40653
+ return true;
40654
+ }
40333
40655
  throw err;
40334
40656
  }
40335
40657
  setUserRolesRoute.respond(res, 200, await composeRoles(userId));
@@ -40422,7 +40744,7 @@ var whoamiRoute = route({
40422
40744
  description: "Authenticated principal",
40423
40745
  schema: object2({
40424
40746
  kind: _enum2(["operator", "user"]),
40425
- user: union2([UserSchema, _null()]),
40747
+ user: union3([UserSchema, _null()]),
40426
40748
  grants: object2({
40427
40749
  grantsAll: boolean(),
40428
40750
  verbs: array2(string2()),
@@ -40509,7 +40831,7 @@ var resolveUnmapped = route({
40509
40831
  summary: "Resolve an unmapped identity — link to an existing user or create a new one",
40510
40832
  tags: ["Users"],
40511
40833
  params: object2({ kind: string2(), externalId: string2() }),
40512
- body: union2([
40834
+ body: union3([
40513
40835
  object2({ userId: string2().min(1) }),
40514
40836
  object2({
40515
40837
  name: string2().min(1),
@@ -40524,6 +40846,9 @@ var resolveUnmapped = route({
40524
40846
  },
40525
40847
  400: { description: "Validation error" },
40526
40848
  401: { description: "Unauthorized" },
40849
+ 403: {
40850
+ description: "Target holds an operator-granted role (auditor) and the caller is not the operator key"
40851
+ },
40527
40852
  404: { description: "Target user not found" }
40528
40853
  },
40529
40854
  auth: { apiKey: true }
@@ -40578,6 +40903,9 @@ var updateUserRoute = route({
40578
40903
  },
40579
40904
  400: { description: "Validation error or empty body" },
40580
40905
  401: { description: "Unauthorized" },
40906
+ 403: {
40907
+ description: "Target holds an operator-granted role (auditor) and the caller is not the operator key"
40908
+ },
40581
40909
  404: { description: "User not found" }
40582
40910
  },
40583
40911
  auth: { apiKey: true }
@@ -40603,6 +40931,9 @@ var mintUserMcpTokenRoute = route({
40603
40931
  })
40604
40932
  },
40605
40933
  401: { description: "Unauthorized" },
40934
+ 403: {
40935
+ description: "Target holds an operator-granted role (auditor) and the caller is not the operator key"
40936
+ },
40606
40937
  404: { description: "User not found" }
40607
40938
  },
40608
40939
  auth: { apiKey: true }
@@ -40646,6 +40977,9 @@ var createConnectorCodeRoute = route({
40646
40977
  },
40647
40978
  400: { description: "The public API origin or CONNECTOR_CONNECT_URL is not HTTPS" },
40648
40979
  401: { description: "Unauthorized" },
40980
+ 403: {
40981
+ description: "Target holds an operator-granted role (auditor) and the caller is not the operator key"
40982
+ },
40649
40983
  404: { description: "User not found" }
40650
40984
  },
40651
40985
  auth: { apiKey: true },
@@ -40778,6 +41112,9 @@ var mergeUsersRoute = route({
40778
41112
  },
40779
41113
  400: { description: "Validation error (e.g. target == source)" },
40780
41114
  401: { description: "Unauthorized" },
41115
+ 403: {
41116
+ description: "Target holds an operator-granted role (auditor) and the caller is not the operator key"
41117
+ },
40781
41118
  404: { description: "Target or source user not found" },
40782
41119
  409: { description: "Source is the last active admin (last_admin)" }
40783
41120
  },
@@ -40819,6 +41156,9 @@ var addIdentityRoute = route({
40819
41156
  },
40820
41157
  400: { description: "Validation error" },
40821
41158
  401: { description: "Unauthorized" },
41159
+ 403: {
41160
+ description: "Target holds an operator-granted role (auditor) and the caller is not the operator key"
41161
+ },
40822
41162
  404: { description: "User not found" },
40823
41163
  409: { description: "The (kind, externalId) identity is already linked (identity_taken)" }
40824
41164
  },
@@ -40841,6 +41181,18 @@ var deleteIdentityRoute = route({
40841
41181
  },
40842
41182
  auth: { apiKey: true }
40843
41183
  });
41184
+ function writeGuarded(actor, targetUserId, write) {
41185
+ return getDbClient2().transaction(async () => {
41186
+ await assertMayActOnOperatorGrantedTarget2(actor, targetUserId);
41187
+ return await write();
41188
+ });
41189
+ }
41190
+ function respondOperatorGrantedRefusal(res, err) {
41191
+ if (!(err instanceof OperatorGrantedTargetError2))
41192
+ return false;
41193
+ jsonError(res, err.message, 403);
41194
+ return true;
41195
+ }
40844
41196
  function isUniqueViolation(err, target) {
40845
41197
  return err instanceof Error && err.message.includes("UNIQUE constraint") && err.message.includes(target);
40846
41198
  }
@@ -40998,16 +41350,19 @@ async function handleUsers(req, res, pathSegments, queryParams) {
40998
41350
  return true;
40999
41351
  try {
41000
41352
  const { identities, ...userFields } = parsed.body;
41001
- const user = await createUser2(userFields);
41002
- await syncUserBudgetMirror(user.id, userFields.dailyBudgetUsd);
41003
- for (const ident of identities ?? []) {
41004
- await linkIdentity(user.id, ident.kind, ident.externalId, actor);
41005
- }
41006
- if (userFields.dailyBudgetUsd !== undefined) {
41007
- await recordIdentityEvent(user.id, "budget_changed", actor, null, {
41008
- dailyBudgetUsd: userFields.dailyBudgetUsd
41009
- });
41010
- }
41353
+ const user = await getDbClient2().transaction(async () => {
41354
+ const created = await createUser2(userFields);
41355
+ await syncUserBudgetMirror(created.id, userFields.dailyBudgetUsd);
41356
+ for (const ident of identities ?? []) {
41357
+ await linkIdentity(created.id, ident.kind, ident.externalId, actor);
41358
+ }
41359
+ if (userFields.dailyBudgetUsd !== undefined) {
41360
+ await recordIdentityEvent(created.id, "budget_changed", actor, null, {
41361
+ dailyBudgetUsd: userFields.dailyBudgetUsd
41362
+ });
41363
+ }
41364
+ return created;
41365
+ });
41011
41366
  const composed = await composeUser(user.id);
41012
41367
  createUserRoute.respond(res, 200, { user: composed });
41013
41368
  } catch (err) {
@@ -41054,21 +41409,27 @@ async function handleUsers(req, res, pathSegments, queryParams) {
41054
41409
  return true;
41055
41410
  }
41056
41411
  targetUserId = existing.id;
41412
+ await writeGuarded(actor, targetUserId, () => linkIdentity(targetUserId, kind, externalId, actor));
41057
41413
  } else {
41058
- const created = await createUser2({
41059
- name: parsed.body.name,
41060
- email: parsed.body.email,
41061
- notes: parsed.body.notes
41414
+ const body = parsed.body;
41415
+ targetUserId = await getDbClient2().transaction(async () => {
41416
+ const created = await createUser2({
41417
+ name: body.name,
41418
+ email: body.email,
41419
+ notes: body.notes
41420
+ });
41421
+ await linkIdentity(created.id, kind, externalId, actor);
41422
+ return created.id;
41062
41423
  });
41063
- targetUserId = created.id;
41064
41424
  }
41065
- await linkIdentity(targetUserId, kind, externalId, actor);
41066
41425
  const ns = `integration:unmapped:${kind}`;
41067
41426
  await deleteKv2(ns, `${externalId}:meta`);
41068
41427
  await deleteKv2(ns, `${externalId}:count`);
41069
41428
  const user = await composeUser(targetUserId);
41070
41429
  resolveUnmapped.respond(res, 200, { user });
41071
41430
  } catch (err) {
41431
+ if (respondOperatorGrantedRefusal(res, err))
41432
+ return true;
41072
41433
  jsonError(res, err instanceof Error ? err.message : "Failed to resolve unmapped", 500);
41073
41434
  }
41074
41435
  return true;
@@ -41100,7 +41461,7 @@ async function handleUsers(req, res, pathSegments, queryParams) {
41100
41461
  return true;
41101
41462
  }
41102
41463
  try {
41103
- const { tokenId, plaintext } = await mintToken(parsed.params.id, parsed.body.label ?? null, actor);
41464
+ const { tokenId, plaintext } = await writeGuarded(actor, parsed.params.id, () => mintToken(parsed.params.id, parsed.body.label ?? null, actor));
41104
41465
  const token = (await listUserTokens(parsed.params.id)).find((t) => t.id === tokenId);
41105
41466
  mintUserMcpTokenRoute.respond(res, 200, {
41106
41467
  plaintext,
@@ -41108,6 +41469,8 @@ async function handleUsers(req, res, pathSegments, queryParams) {
41108
41469
  user: await composeUser(parsed.params.id)
41109
41470
  });
41110
41471
  } catch (err) {
41472
+ if (respondOperatorGrantedRefusal(res, err))
41473
+ return true;
41111
41474
  jsonError(res, err instanceof Error ? err.message : "Failed to mint token", 500);
41112
41475
  }
41113
41476
  return true;
@@ -41140,6 +41503,8 @@ async function handleUsers(req, res, pathSegments, queryParams) {
41140
41503
  const connectUrl = connect.toString();
41141
41504
  createConnectorCodeRoute.respond(res, 201, { code, expiresAt, connectUrl });
41142
41505
  } catch (err) {
41506
+ if (respondOperatorGrantedRefusal(res, err))
41507
+ return true;
41143
41508
  jsonError(res, err instanceof Error ? err.message : "Failed to create connector code", 500);
41144
41509
  }
41145
41510
  return true;
@@ -41328,11 +41693,13 @@ async function handleUsers(req, res, pathSegments, queryParams) {
41328
41693
  return true;
41329
41694
  }
41330
41695
  try {
41331
- await linkIdentity(parsed.params.id, parsed.body.kind, parsed.body.externalId, actor);
41696
+ await writeGuarded(actor, parsed.params.id, () => linkIdentity(parsed.params.id, parsed.body.kind, parsed.body.externalId, actor));
41332
41697
  addIdentityRoute.respond(res, 200, {
41333
41698
  identities: await getUserIdentities(parsed.params.id)
41334
41699
  });
41335
41700
  } catch (err) {
41701
+ if (respondOperatorGrantedRefusal(res, err))
41702
+ return true;
41336
41703
  if (isUniqueViolation(err, "user_external_ids")) {
41337
41704
  jsonError(res, "identity_taken", 409);
41338
41705
  return true;
@@ -41389,6 +41756,7 @@ async function handleUsers(req, res, pathSegments, queryParams) {
41389
41756
  }
41390
41757
  try {
41391
41758
  const mergedUser = await getDbClient2().transaction(async () => {
41759
+ await assertMayActOnOperatorGrantedTarget2(actor, targetId);
41392
41760
  for (const ident of sourceBefore.identities) {
41393
41761
  await unlinkIdentity(sourceId, ident.kind, ident.externalId, actor);
41394
41762
  await linkIdentity(targetId, ident.kind, ident.externalId, actor);
@@ -41430,6 +41798,8 @@ async function handleUsers(req, res, pathSegments, queryParams) {
41430
41798
  });
41431
41799
  mergeUsersRoute.respond(res, 200, { user: mergedUser });
41432
41800
  } catch (err) {
41801
+ if (respondOperatorGrantedRefusal(res, err))
41802
+ return true;
41433
41803
  if (err instanceof LastAdminError2) {
41434
41804
  jsonError(res, "last_admin", 409);
41435
41805
  return true;
@@ -41462,6 +41832,8 @@ async function handleUsers(req, res, pathSegments, queryParams) {
41462
41832
  jsonError(res, "User not found", 404);
41463
41833
  return true;
41464
41834
  }
41835
+ const { identities: newIdentities, email: newEmail, emailAliases: newAliases } = parsed.body;
41836
+ const bindsIdentity = newIdentities !== undefined || newEmail !== undefined || newAliases !== undefined;
41465
41837
  try {
41466
41838
  const { identities, metadata, comms, ...rest } = parsed.body;
41467
41839
  const update = { ...rest };
@@ -41478,68 +41850,77 @@ async function handleUsers(req, res, pathSegments, queryParams) {
41478
41850
  } else if (metadata !== undefined) {
41479
41851
  update.metadata = metadata;
41480
41852
  }
41481
- const updated = await updateUser2(parsed.params.id, update);
41482
- if (!updated) {
41483
- jsonError(res, "User not found", 404);
41484
- return true;
41485
- }
41486
- await syncUserBudgetMirror(parsed.params.id, parsed.body.dailyBudgetUsd);
41487
- if (parsed.body.dailyBudgetUsd !== undefined && (before.dailyBudgetUsd ?? null) !== (parsed.body.dailyBudgetUsd ?? null)) {
41488
- await recordIdentityEvent(parsed.params.id, "budget_changed", actor, { dailyBudgetUsd: before.dailyBudgetUsd ?? null }, { dailyBudgetUsd: parsed.body.dailyBudgetUsd ?? null });
41489
- }
41490
- if (parsed.body.status !== undefined && before.status !== parsed.body.status) {
41491
- await recordIdentityEvent(parsed.params.id, "status_changed", actor, { status: before.status }, { status: parsed.body.status });
41492
- }
41493
- if (parsed.body.emailAliases !== undefined) {
41494
- const beforeSet = new Set((before.emailAliases ?? []).map((a) => a.toLowerCase()));
41495
- const afterSet = new Set(parsed.body.emailAliases.map((a) => a.toLowerCase()));
41496
- for (const a of parsed.body.emailAliases) {
41497
- if (!beforeSet.has(a.toLowerCase())) {
41498
- await recordIdentityEvent(parsed.params.id, "email_added", actor, null, { email: a });
41499
- }
41853
+ const found = await getDbClient2().transaction(async () => {
41854
+ if (bindsIdentity)
41855
+ await assertMayActOnOperatorGrantedTarget2(actor, parsed.params.id);
41856
+ const updated = await updateUser2(parsed.params.id, update);
41857
+ if (!updated)
41858
+ return false;
41859
+ await syncUserBudgetMirror(parsed.params.id, parsed.body.dailyBudgetUsd);
41860
+ if (parsed.body.dailyBudgetUsd !== undefined && (before.dailyBudgetUsd ?? null) !== (parsed.body.dailyBudgetUsd ?? null)) {
41861
+ await recordIdentityEvent(parsed.params.id, "budget_changed", actor, { dailyBudgetUsd: before.dailyBudgetUsd ?? null }, { dailyBudgetUsd: parsed.body.dailyBudgetUsd ?? null });
41500
41862
  }
41501
- for (const a of before.emailAliases ?? []) {
41502
- if (!afterSet.has(a.toLowerCase())) {
41503
- await recordIdentityEvent(parsed.params.id, "email_removed", actor, { email: a }, null);
41504
- }
41863
+ if (parsed.body.status !== undefined && before.status !== parsed.body.status) {
41864
+ await recordIdentityEvent(parsed.params.id, "status_changed", actor, { status: before.status }, { status: parsed.body.status });
41505
41865
  }
41506
- }
41507
- const PROFILE_FIELDS = [
41508
- "name",
41509
- "email",
41510
- "role",
41511
- "timezone",
41512
- "preferredChannel",
41513
- "notes",
41514
- "metadata"
41515
- ];
41516
- for (const field of PROFILE_FIELDS) {
41517
- if (parsed.body[field] === undefined)
41518
- continue;
41519
- const beforeVal = before[field] ?? null;
41520
- const afterVal = parsed.body[field] ?? null;
41521
- if (JSON.stringify(beforeVal) === JSON.stringify(afterVal))
41522
- continue;
41523
- await recordIdentityEvent(parsed.params.id, "profile_changed", actor, { [field]: beforeVal }, { [field]: afterVal });
41524
- }
41525
- if (identities !== undefined) {
41526
- const beforeIds = await getUserIdentities(parsed.params.id);
41527
- const beforeKeys = new Set(beforeIds.map((i) => `${i.kind}:${i.externalId}`));
41528
- const afterKeys = new Set(identities.map((i) => `${i.kind}:${i.externalId}`));
41529
- for (const i of identities) {
41530
- if (!beforeKeys.has(`${i.kind}:${i.externalId}`)) {
41531
- await linkIdentity(parsed.params.id, i.kind, i.externalId, actor);
41866
+ if (parsed.body.emailAliases !== undefined) {
41867
+ const beforeSet = new Set((before.emailAliases ?? []).map((a) => a.toLowerCase()));
41868
+ const afterSet = new Set(parsed.body.emailAliases.map((a) => a.toLowerCase()));
41869
+ for (const a of parsed.body.emailAliases) {
41870
+ if (!beforeSet.has(a.toLowerCase())) {
41871
+ await recordIdentityEvent(parsed.params.id, "email_added", actor, null, { email: a });
41872
+ }
41873
+ }
41874
+ for (const a of before.emailAliases ?? []) {
41875
+ if (!afterSet.has(a.toLowerCase())) {
41876
+ await recordIdentityEvent(parsed.params.id, "email_removed", actor, { email: a }, null);
41877
+ }
41532
41878
  }
41533
41879
  }
41534
- for (const i of beforeIds) {
41535
- if (!afterKeys.has(`${i.kind}:${i.externalId}`)) {
41536
- await unlinkIdentity(parsed.params.id, i.kind, i.externalId, actor);
41880
+ const PROFILE_FIELDS = [
41881
+ "name",
41882
+ "email",
41883
+ "role",
41884
+ "timezone",
41885
+ "preferredChannel",
41886
+ "notes",
41887
+ "metadata"
41888
+ ];
41889
+ for (const field of PROFILE_FIELDS) {
41890
+ if (parsed.body[field] === undefined)
41891
+ continue;
41892
+ const beforeVal = before[field] ?? null;
41893
+ const afterVal = parsed.body[field] ?? null;
41894
+ if (JSON.stringify(beforeVal) === JSON.stringify(afterVal))
41895
+ continue;
41896
+ await recordIdentityEvent(parsed.params.id, "profile_changed", actor, { [field]: beforeVal }, { [field]: afterVal });
41897
+ }
41898
+ if (identities !== undefined) {
41899
+ const beforeIds = await getUserIdentities(parsed.params.id);
41900
+ const beforeKeys = new Set(beforeIds.map((i) => `${i.kind}:${i.externalId}`));
41901
+ const afterKeys = new Set(identities.map((i) => `${i.kind}:${i.externalId}`));
41902
+ for (const i of identities) {
41903
+ if (!beforeKeys.has(`${i.kind}:${i.externalId}`)) {
41904
+ await linkIdentity(parsed.params.id, i.kind, i.externalId, actor);
41905
+ }
41906
+ }
41907
+ for (const i of beforeIds) {
41908
+ if (!afterKeys.has(`${i.kind}:${i.externalId}`)) {
41909
+ await unlinkIdentity(parsed.params.id, i.kind, i.externalId, actor);
41910
+ }
41537
41911
  }
41538
41912
  }
41913
+ return true;
41914
+ });
41915
+ if (!found) {
41916
+ jsonError(res, "User not found", 404);
41917
+ return true;
41539
41918
  }
41540
41919
  const composed = await composeUser(parsed.params.id);
41541
41920
  updateUserRoute.respond(res, 200, { user: composed });
41542
41921
  } catch (err) {
41922
+ if (respondOperatorGrantedRefusal(res, err))
41923
+ return true;
41543
41924
  jsonError(res, err instanceof Error ? err.message : "Failed to update user", 500);
41544
41925
  }
41545
41926
  return true;
@@ -41780,7 +42161,7 @@ var githubWebhook = route({
41780
42161
  responses: {
41781
42162
  200: {
41782
42163
  description: "Event processed",
41783
- schema: union2([object2({ message: literal2("pong") }), WebhookDispatchResultSchema])
42164
+ schema: union3([object2({ message: literal2("pong") }), WebhookDispatchResultSchema])
41784
42165
  },
41785
42166
  401: { description: "Invalid signature" },
41786
42167
  503: { description: "GitHub integration not configured" }
@@ -42749,7 +43130,7 @@ var listWorkflowsRoute = route({
42749
43130
  responses: {
42750
43131
  200: {
42751
43132
  description: "Workflow list",
42752
- schema: union2([array2(WorkflowSummarySchema), array2(WorkflowWithFavoriteSchema)])
43133
+ schema: union3([array2(WorkflowSummarySchema), array2(WorkflowWithFavoriteSchema)])
42753
43134
  }
42754
43135
  }
42755
43136
  });
@@ -42952,7 +43333,7 @@ var getWorkflowRunRoute = route({
42952
43333
  responses: {
42953
43334
  200: {
42954
43335
  description: "Workflow run details with steps including retry info",
42955
- schema: union2([
43336
+ schema: union3([
42956
43337
  object2({
42957
43338
  run: WorkflowRunSchema,
42958
43339
  steps: array2(WorkflowRunStepSchema),
@@ -44000,6 +44381,7 @@ var httpServer = createHttpServer(async (req, res) => {
44000
44381
  () => handleInboxState(req, res, pathSegments, queryParams),
44001
44382
  () => handleTelemetryUi(req, res, pathSegments, queryParams, myAgentId),
44002
44383
  () => handleUsedBy(req, res, pathSegments, queryParams, myAgentId),
44384
+ () => handleImprovements(req, res, pathSegments, queryParams),
44003
44385
  () => handleRanking(req, res, pathSegments, queryParams),
44004
44386
  () => handleFleetBenchmark(req, res, pathSegments, queryParams),
44005
44387
  () => handleTaskTemplates(req, res, pathSegments, queryParams),
@@ -44032,7 +44414,7 @@ var httpServer = createHttpServer(async (req, res) => {
44032
44414
  });
44033
44415
  });
44034
44416
  var detachRealtime = attachRealtimeTransport(httpServer);
44035
- var { attachControllerTransport } = await import("./controllers-connect-m7d4vxxb.js");
44417
+ var { attachControllerTransport } = await import("./controllers-connect-498hrxvk.js");
44036
44418
  var detachControllers = attachControllerTransport(httpServer);
44037
44419
  var stopWorkerNudges = startWorkerNudgeListener();
44038
44420
  var taskAutoTitles = startTaskAutoTitleListener();
@@ -44063,7 +44445,7 @@ async function shutdown() {
44063
44445
  sessionsProcessed: getServerSessionsProcessed()
44064
44446
  });
44065
44447
  if (hasCapability("scheduling")) {
44066
- const { stopScheduler } = await import("./index-hpfte8jd.js");
44448
+ const { stopScheduler } = await import("./index-nfy4kkg5.js");
44067
44449
  stopScheduler();
44068
44450
  }
44069
44451
  stopHeartbeat2();
@@ -44075,7 +44457,7 @@ async function shutdown() {
44075
44457
  await stopSlackApp2();
44076
44458
  await stopChatSdk();
44077
44459
  if (!isEnvFlagEnabled("OAUTH_KEEPALIVE_DISABLE", false)) {
44078
- const { stopOAuthKeepalive } = await import("./keepalive-qnt21cv0.js");
44460
+ const { stopOAuthKeepalive } = await import("./keepalive-wy29kbrg.js");
44079
44461
  await stopOAuthKeepalive();
44080
44462
  }
44081
44463
  stopOAuthPendingGc();
@@ -44157,21 +44539,21 @@ try {
44157
44539
  console.warn("[startup] CAPABILITIES upgrade seed failed (non-fatal):", err);
44158
44540
  }
44159
44541
  try {
44160
- const { ensurePricingSeeded } = await import("./boot-seeds-n46eaxdv.js");
44542
+ const { ensurePricingSeeded } = await import("./boot-seeds-qdaf3sdy.js");
44161
44543
  ensurePricingSeeded();
44162
- const { startPricingRefreshLoop } = await import("./pricing-refresh-9fcbnq3f.js");
44544
+ const { startPricingRefreshLoop } = await import("./pricing-refresh-x7nhv23d.js");
44163
44545
  startPricingRefreshLoop();
44164
44546
  } catch (err) {
44165
44547
  console.error("[startup] Failed to seed pricing rows:", err);
44166
44548
  }
44167
44549
  try {
44168
- const { ensureModelProfilesSeeded } = await import("./boot-seeds-n46eaxdv.js");
44550
+ const { ensureModelProfilesSeeded } = await import("./boot-seeds-qdaf3sdy.js");
44169
44551
  await ensureModelProfilesSeeded();
44170
44552
  } catch (err) {
44171
44553
  console.error("[startup] Failed to seed model profiles:", err);
44172
44554
  }
44173
44555
  try {
44174
- const { ensureRbacSeeded } = await import("./boot-seeds-n46eaxdv.js");
44556
+ const { ensureRbacSeeded } = await import("./boot-seeds-qdaf3sdy.js");
44175
44557
  ensureRbacSeeded();
44176
44558
  } catch (err) {
44177
44559
  console.error("[startup] Failed to sync RBAC seed rows:", err);
@@ -44179,7 +44561,7 @@ try {
44179
44561
  throw err;
44180
44562
  }
44181
44563
  try {
44182
- const { runAllSeeders } = await import("./index-bxrexmfy.js");
44564
+ const { runAllSeeders } = await import("./index-c9y31ytf.js");
44183
44565
  await runAllSeeders({ scriptEmbeddingMode: "skip" });
44184
44566
  } catch (err) {
44185
44567
  console.error("[startup] Failed to seed built-in entities:", err);
@@ -44242,26 +44624,26 @@ httpServer.listen(port, async () => {
44242
44624
  await initWorkflows2();
44243
44625
  await startScriptRunSupervisor(getMcpBaseUrl());
44244
44626
  if (hasCapability("scheduling")) {
44245
- const { startScheduler } = await import("./index-hpfte8jd.js");
44246
- const { getExecutorRegistry } = await import("./index-vte6dyeh.js");
44627
+ const { startScheduler } = await import("./index-nfy4kkg5.js");
44628
+ const { getExecutorRegistry } = await import("./index-8ybffts4.js");
44247
44629
  const intervalMs = Number(process.env.SCHEDULER_INTERVAL_MS) || 1e4;
44248
44630
  startScheduler(getExecutorRegistry(), intervalMs, {
44249
44631
  runId: globalState.__runId
44250
44632
  });
44251
44633
  }
44252
44634
  if (!isEnvFlagEnabled("HEARTBEAT_DISABLE", false)) {
44253
- const { startHeartbeat } = await import("./index-ncf7yb5s.js");
44635
+ const { startHeartbeat } = await import("./index-4x08sjtk.js");
44254
44636
  const heartbeatMs = Number(process.env.HEARTBEAT_INTERVAL_MS) || 90000;
44255
44637
  startHeartbeat(heartbeatMs);
44256
44638
  }
44257
44639
  startPoolRouting();
44258
44640
  startRuntimeSupervisor();
44259
44641
  if (!isEnvFlagEnabled("OAUTH_KEEPALIVE_DISABLE", false)) {
44260
- const { startOAuthKeepalive } = await import("./keepalive-qnt21cv0.js");
44642
+ const { startOAuthKeepalive } = await import("./keepalive-wy29kbrg.js");
44261
44643
  startOAuthKeepalive();
44262
44644
  }
44263
44645
  if (!isEnvFlagEnabled("OAUTH_REFRESH_SWEEP_DISABLE", false)) {
44264
- const { startOAuthRefreshSweep } = await import("./oauth-refresh-sweep-vczabeh4.js");
44646
+ const { startOAuthRefreshSweep } = await import("./oauth-refresh-sweep-q7mtbyp3.js");
44265
44647
  startOAuthRefreshSweep();
44266
44648
  }
44267
44649
  startOAuthPendingGc();
@@ -44270,19 +44652,19 @@ httpServer.listen(port, async () => {
44270
44652
  await startDbRetention();
44271
44653
  startHumanFreeDrain();
44272
44654
  startTaskSearchBackfill();
44273
- import("./embedding-space-b4txbwrk.js").then(({ runEmbeddingMaintenance, setDeploymentEnvReader }) => {
44655
+ import("./embedding-space-xh8p4q4x.js").then(({ runEmbeddingMaintenance, setDeploymentEnvReader }) => {
44274
44656
  setDeploymentEnvReader(getDeploymentEnvValue);
44275
44657
  return runEmbeddingMaintenance({ backfill: true });
44276
44658
  }).catch((err) => {
44277
44659
  console.error("[embedding-space] startup maintenance failed (non-fatal):", err);
44278
44660
  });
44279
- import("./boot-args-schema-tjrkpbvm.js").then(({ runBootArgsSchemaBackfill }) => runBootArgsSchemaBackfill()).catch((err) => {
44661
+ import("./boot-args-schema-h4qj462e.js").then(({ runBootArgsSchemaBackfill }) => runBootArgsSchemaBackfill()).catch((err) => {
44280
44662
  console.error("[boot-args-schema] startup backfill failed (non-fatal):", err);
44281
44663
  });
44282
- import("./boot-scrub-sweep-qy0zr9t2.js").then(({ runBootScrubSweep }) => runBootScrubSweep()).catch((err) => {
44664
+ import("./boot-scrub-sweep-9w9jp4sm.js").then(({ runBootScrubSweep }) => runBootScrubSweep()).catch((err) => {
44283
44665
  console.error("[boot-scrub-sweep] startup scrub failed (non-fatal):", err);
44284
44666
  });
44285
- import("./session-source-backfill-0vscqmsa.js").then(({ runSessionSourceBackfill }) => runSessionSourceBackfill()).catch((err) => {
44667
+ import("./session-source-backfill-440ysamr.js").then(({ runSessionSourceBackfill }) => runSessionSourceBackfill()).catch((err) => {
44286
44668
  console.error("[session-source-backfill] startup run failed (non-fatal):", err);
44287
44669
  });
44288
44670
  }).on("error", (err) => {