@desplega.ai/agent-swarm 2.13.0 → 2.13.2

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 (306) hide show
  1. package/README.md +1 -1
  2. package/dist/acp-adapter-x1qqgzwx.js +17 -0
  3. package/dist/{acp-targets-86f0sh6g.js → acp-targets-mz8c5dnt.js} +10 -10
  4. package/dist/{actions-zv8vcxvr.js → actions-5ft3qp5a.js} +27 -27
  5. package/dist/{agent-fs-provision-jqshb33y.js → agent-fs-provision-6fgz7wvz.js} +4 -4
  6. package/dist/{amp-adapter-gt503ywc.js → amp-adapter-nthn8ezm.js} +3 -3
  7. package/dist/{app-6t4k5rh1.js → app-535m78qw.js} +10 -10
  8. package/dist/{approval-notifications-fcfw063h.js → approval-notifications-dewbk403.js} +11 -11
  9. package/dist/{assistant-9dzybh12.js → assistant-39zyabv2.js} +28 -28
  10. package/dist/{boot-args-schema-xzfp2feg.js → boot-args-schema-bqv5bf77.js} +1 -1
  11. package/dist/{boot-reembed-3jz0p2jk.js → boot-reembed-157c0gcz.js} +1 -1
  12. package/dist/{boot-reembed-r88wngfg.js → boot-reembed-fas7z3zn.js} +1 -1
  13. package/dist/{boot-scrub-sweep-scrqhw48.js → boot-scrub-sweep-tmec0be2.js} +2 -2
  14. package/dist/{boot-seeds-vb2dcrrb.js → boot-seeds-32zm50x2.js} +4 -4
  15. package/dist/{boxd-68n75y1s.js → boxd-hr8rsxzq.js} +1 -1
  16. package/dist/{claude-adapter-h3mp9hgs.js → claude-adapter-gwq7x2nj.js} +9 -9
  17. package/dist/{claude-managed-adapter-kpbyj2vb.js → claude-managed-adapter-rkvw6fvq.js} +4 -4
  18. package/dist/{claude-managed-setup-0efr3wkg.js → claude-managed-setup-0vgz4d1j.js} +6 -6
  19. package/dist/{claude-sdk-session-03dw669q.js → claude-sdk-session-5wbwxy8c.js} +20967 -19390
  20. package/dist/{cli-z64t9pe6.js → cli-0f7n3td3.js} +1 -1
  21. package/dist/{cli-j53hpbsm.js → cli-0xwb7zpt.js} +2 -2
  22. package/dist/{cli-wxwv3t11.js → cli-1f48qdnb.js} +55 -13
  23. package/dist/{cli-gfcv679k.js → cli-1gevjrc1.js} +1 -1
  24. package/dist/{cli-0jkenasr.js → cli-2v4xxnx2.js} +1 -1
  25. package/dist/{cli-hc6e4tac.js → cli-2wde56gv.js} +6 -6
  26. package/dist/{cli-mh7pdxe0.js → cli-31vt7baf.js} +17 -17
  27. package/dist/{cli-ercwc8xn.js → cli-3mf04tkh.js} +1 -1
  28. package/dist/{cli-s6zk31gr.js → cli-43dsqhcp.js} +4 -4
  29. package/dist/{cli-1dbv9mj9.js → cli-4djg31jh.js} +1 -1
  30. package/dist/{cli-tn91wc6e.js → cli-50whymxq.js} +1 -1
  31. package/dist/{cli-js10kdk7.js → cli-5basv0e7.js} +19 -5
  32. package/dist/{cli-b2jh3dyb.js → cli-5k1hvycs.js} +4 -4
  33. package/dist/{cli-dkejt425.js → cli-62fjschk.js} +7 -7
  34. package/dist/{cli-zqmmy073.js → cli-69eq6gdk.js} +18 -18
  35. package/dist/{cli-qm3ntjqs.js → cli-6rmryz03.js} +13 -13
  36. package/dist/{cli-mz34pxbk.js → cli-7m6bbtab.js} +11 -11
  37. package/dist/{cli-wv20kbr3.js → cli-8a4qg44m.js} +5 -5
  38. package/dist/{cli-2m6yaq6b.js → cli-8fj8yfmk.js} +1 -1
  39. package/dist/{cli-9m9kyw77.js → cli-8qvte9hn.js} +2 -2
  40. package/dist/{cli-x05p2d05.js → cli-9tevdxyf.js} +1 -1
  41. package/dist/{cli-qec9bynj.js → cli-a6rzw649.js} +3 -3
  42. package/dist/{cli-ex1y88j3.js → cli-at67kvnp.js} +1 -1
  43. package/dist/{cli-yn4kt85g.js → cli-b0kqw55g.js} +1 -1
  44. package/dist/{cli-n3qe7tyr.js → cli-b0m3bg0f.js} +134 -3
  45. package/dist/{cli-xfjn2kyq.js → cli-bp2rt28p.js} +9 -9
  46. package/dist/{cli-2jk4s7z1.js → cli-c9bwawf9.js} +3 -3
  47. package/dist/{cli-wndegmns.js → cli-cmgdptmx.js} +3 -3
  48. package/dist/{cli-3p288654.js → cli-cpkxh68d.js} +2 -2
  49. package/dist/{cli-117g15t4.js → cli-cs26ed89.js} +8 -8
  50. package/dist/{cli-prf7kz78.js → cli-d0jb2qnt.js} +603 -78
  51. package/dist/{cli-8hp56wat.js → cli-d2epqm0y.js} +1 -1
  52. package/dist/{cli-wrhbym01.js → cli-d528acsw.js} +6 -6
  53. package/dist/{cli-tstj6e8e.js → cli-dnvmwsvc.js} +310 -88
  54. package/dist/{cli-9fsagra4.js → cli-e87fg3en.js} +1 -1
  55. package/dist/{cli-jj3c5nyb.js → cli-erh1rgh4.js} +116 -56
  56. package/dist/{cli-f1952kjy.js → cli-ewb028rs.js} +4 -4
  57. package/dist/{cli-ct8sz3np.js → cli-f1sdh8ca.js} +6 -6
  58. package/dist/{cli-0b655smz.js → cli-fcwrd7bh.js} +5 -5
  59. package/dist/{cli-eb279wn3.js → cli-fgm2mad9.js} +2 -2
  60. package/dist/{cli-bpje8n65.js → cli-fp65jdp2.js} +31 -6
  61. package/dist/{cli-dnh64e8e.js → cli-g0b3ma7r.js} +7 -7
  62. package/dist/{cli-avxh26pd.js → cli-gc7jkf4a.js} +4 -4
  63. package/dist/{cli-2skf1mdf.js → cli-gedf48yw.js} +4 -4
  64. package/dist/{cli-ajjvqhf3.js → cli-getrvmtx.js} +27 -6
  65. package/dist/{cli-c8v2yvej.js → cli-gq6qhmrr.js} +2 -2
  66. package/dist/{cli-mbwmqb5w.js → cli-h0ewec3d.js} +1 -1
  67. package/dist/{cli-tdk7jtka.js → cli-hv3820ez.js} +1 -1
  68. package/dist/{cli-avqkr20b.js → cli-j2ybkdk2.js} +2 -2
  69. package/dist/{cli-pqfecppn.js → cli-je587f74.js} +1 -1
  70. package/dist/{cli-hgsxnjyg.js → cli-jkkcm72j.js} +13 -13
  71. package/dist/{cli-g6j6ac3h.js → cli-ka13xx6b.js} +2 -2
  72. package/dist/{cli-t35hx078.js → cli-m1wddksc.js} +2 -2
  73. package/dist/{cli-50w82h6m.js → cli-mwxez0pz.js} +1 -0
  74. package/dist/{cli-nc6a8b5b.js → cli-n14r8h4n.js} +2 -2
  75. package/dist/{cli-y4a4458j.js → cli-n46d87mj.js} +3 -3
  76. package/dist/{cli-0dg7ytxm.js → cli-nkfv398a.js} +1096 -75
  77. package/dist/{cli-fhvk2nvp.js → cli-nvqq3232.js} +9 -9
  78. package/dist/{cli-bhgrhedp.js → cli-q8aq48v1.js} +1 -1
  79. package/dist/{cli-6a40p4kv.js → cli-qn79645p.js} +1 -1
  80. package/dist/{cli-hbq0kwxz.js → cli-r4fphq38.js} +4 -4
  81. package/dist/{cli-47hz21se.js → cli-r8ddn0hf.js} +4 -5
  82. package/dist/{cli-hpb9x72z.js → cli-rvhaahfv.js} +9 -9
  83. package/dist/{cli-qhhb30e8.js → cli-s08zsqva.js} +9 -9
  84. package/dist/{cli-sdh61g52.js → cli-s6fhqbz1.js} +2 -2
  85. package/dist/{cli-y518qkjg.js → cli-sjk85d7v.js} +13 -12
  86. package/dist/{cli-ytc7fpza.js → cli-t25rq8mg.js} +4 -4
  87. package/dist/{cli-sq913bh1.js → cli-t9nxq30h.js} +8 -8
  88. package/dist/{cli-49f5jyhh.js → cli-tbdw3f92.js} +3 -3
  89. package/dist/{cli-1v82d2w6.js → cli-tceqvv6h.js} +4 -4
  90. package/dist/{cli-fz9pcjsw.js → cli-tgmate57.js} +4 -4
  91. package/dist/{cli-rtmqzat7.js → cli-vdfngx2g.js} +2 -2
  92. package/dist/{cli-9w8712tq.js → cli-vr4eyq6p.js} +43 -14
  93. package/dist/{cli-z4f346g5.js → cli-vx9acp12.js} +1 -1
  94. package/dist/{cli-7dbhnsj9.js → cli-wdtqkqnq.js} +4 -4
  95. package/dist/{cli-kde4ky90.js → cli-x5yb8zc8.js} +2 -2
  96. package/dist/{cli-w14j2z4k.js → cli-x7aqhxj5.js} +2 -2
  97. package/dist/{cli-kspxjftk.js → cli-xerdrnqs.js} +15 -6
  98. package/dist/{cli-48nvk6sb.js → cli-xhkek467.js} +2 -2
  99. package/dist/{cli-dka73bak.js → cli-xysy1g8x.js} +152 -12
  100. package/dist/{cli-7wy8gbwb.js → cli-ya1cj689.js} +1 -1
  101. package/dist/{cli-n85m2wkq.js → cli-zkbz8m2q.js} +3 -2
  102. package/dist/{cli-0pazkmd4.js → cli-zm6bkx3e.js} +4 -4
  103. package/dist/{cli-6h88mn9q.js → cli-zqy28rwx.js} +4 -4
  104. package/dist/cli.js +30 -29
  105. package/dist/{codex-adapter-f3yp0kaj.js → codex-adapter-x25xfbnh.js} +8 -8
  106. package/dist/{codex-hook-262cekfp.js → codex-hook-c0nvm30r.js} +2 -2
  107. package/dist/{codex-login-1ven7yje.js → codex-login-ven5cz5j.js} +1 -1
  108. package/dist/{codex-session-runner-ns4mv70p.js → codex-session-runner-kn5xnrvp.js} +9 -9
  109. package/dist/{commands-5bzf2tfw.js → commands-8n59gxmy.js} +3 -3
  110. package/dist/{controller-5xt7kvfm.js → controller-wn3vd217.js} +3 -3
  111. package/dist/{controllers-connect-0gg13mzp.js → controllers-connect-09gvkrhc.js} +28 -28
  112. package/dist/core-2b8bv6ny.js +42 -0
  113. package/dist/{cursor-adapter-p0c5zv6r.js → cursor-adapter-w1681kp1.js} +2 -2
  114. package/dist/{db-2s68ycq7.js → db-e71keqxk.js} +3 -3
  115. package/dist/{db-q7q639k5.js → db-spg81qtr.js} +2 -2
  116. package/dist/{devin-adapter-t8d86q9x.js → devin-adapter-fs90ab4v.js} +1 -1
  117. package/dist/{dispatcher-j2y1q7ae.js → dispatcher-fr4vawwb.js} +25 -25
  118. package/dist/{docker-1b41eysj.js → docker-1h33jvh9.js} +2 -2
  119. package/dist/{dsh-adapter-pgnkf4st.js → dsh-adapter-g9yqv09y.js} +2 -2
  120. package/dist/{e2b-xm60c8ad.js → e2b-jnk0yeva.js} +2 -2
  121. package/dist/{e2b-ew8c5j5v.js → e2b-y7e5kmzf.js} +2 -2
  122. package/dist/{easter-egg-3d-0kea97jf.js → easter-egg-3d-ac9tv9a6.js} +1 -1
  123. package/dist/{embedding-space-3n6mhhmy.js → embedding-space-an77f45k.js} +6 -6
  124. package/dist/{embeddings-jfmj6yme.js → embeddings-jkrehejr.js} +1 -1
  125. package/dist/{event-bus-v4ywhc2p.js → event-bus-08t2b4y2.js} +1 -1
  126. package/dist/{execute-tjrej979.js → execute-3mys4nta.js} +1 -1
  127. package/dist/{external-channel-jy8w2gg3.js → external-channel-s6zxpts9.js} +2 -2
  128. package/dist/fx-adapter-4yet1c4f.js +20 -0
  129. package/dist/grok-adapter-8ge6tw7m.js +20 -0
  130. package/dist/handlers-0r9evrdj.js +41 -0
  131. package/dist/heartbeat-jjpb44e5.js +50 -0
  132. package/dist/{hook-fv1jwrv7.js → hook-68gbs87k.js} +6 -6
  133. package/dist/{hook-bpnncsec.js → hook-y6n23zzj.js} +8 -8
  134. package/dist/{http-bpa26czn.js → http-8c6y008s.js} +404 -146
  135. package/dist/{index-w216g9y9.js → index-0vthtbc2.js} +38 -22
  136. package/dist/index-1v23363p.js +39 -0
  137. package/dist/index-30qw6vyw.js +44 -0
  138. package/dist/index-6bm3w6cn.js +40 -0
  139. package/dist/{index-s8re7mvq.js → index-6h3r0vpe.js} +1 -1
  140. package/dist/{index-620y7jzq.js → index-7dgxveck.js} +3 -3
  141. package/dist/{index-4k7m5dgj.js → index-maddg9ys.js} +143 -103
  142. package/dist/{index-0h6qd4p1.js → index-mbpxhc4w.js} +3 -4
  143. package/dist/index-rz8ve510.js +569 -0
  144. package/dist/{index-mpj0z9e0.js → index-we3nd2t0.js} +1 -1
  145. package/dist/{index-pe3d8jfy.js → index-whysn1wf.js} +1 -1
  146. package/dist/{index-52tgbhrw.js → index-xcw7hjt5.js} +28 -28
  147. package/dist/{index-8p0j4h4j.js → index-ym9fgxad.js} +94 -89
  148. package/dist/{k8s-fy8hbhkg.js → k8s-8326q0rq.js} +2 -2
  149. package/dist/{keepalive-d6z12s04.js → keepalive-7e9r5dvp.js} +5 -4
  150. package/dist/lead-3jpc7kcr.js +79 -0
  151. package/dist/{maintenance-7kac6g2g.js → maintenance-d3erjvcg.js} +1 -1
  152. package/dist/{oauth-refresh-sweep-t1xjetbh.js → oauth-refresh-sweep-0qh70988.js} +4 -3
  153. package/dist/{object-webhooks-6rdagg0r.js → object-webhooks-ac7v2q5p.js} +7 -7
  154. package/dist/{onboard-32y1cfxy.js → onboard-5yphtken.js} +4 -4
  155. package/dist/{opencode-adapter-enp3v31n.js → opencode-adapter-0xvyba4m.js} +8 -8
  156. package/dist/{otel-impl-k0tm5ptj.js → otel-impl-svqp691q.js} +2 -2
  157. package/dist/{pending-24zebgvs.js → pending-bn4xe5br.js} +26 -26
  158. package/dist/{pi-mono-adapter-yj72xxxe.js → pi-mono-adapter-763s8a3w.js} +20 -18
  159. package/dist/{pricing-refresh-cf25x38j.js → pricing-refresh-kfc215mf.js} +2 -2
  160. package/dist/{rbac-roles-0wydd22m.js → rbac-roles-3bznvkpt.js} +3 -3
  161. package/dist/{rbac-roles-at6crb3r.js → rbac-roles-6r4h2ghj.js} +2 -2
  162. package/dist/{render-v2-nvcw0jd7.js → render-v2-f3qedbpy.js} +10 -10
  163. package/dist/{resume-y4w0k5v3.js → resume-vcag4ann.js} +13 -13
  164. package/dist/{runtime-vpe43hx0.js → runtime-x0s55z2t.js} +1 -1
  165. package/dist/{session-access-gkyvnfye.js → session-access-nwzve8q2.js} +5 -5
  166. package/dist/{session-source-backfill-3w2st4m2.js → session-source-backfill-jpqfzmgz.js} +2 -2
  167. package/dist/{setup-axxvqtys.js → setup-d2smwaem.js} +1 -1
  168. package/dist/thread-buffer-8fc703jc.js +42 -0
  169. package/dist/{tree-visibility-y4fqvab5.js → tree-visibility-dwzc8en0.js} +2 -2
  170. package/dist/{user-merge-jobs-kcmwvrc6.js → user-merge-jobs-4ce7kma2.js} +3 -3
  171. package/dist/{virtual-modules-7d92dct1.js → virtual-modules-78a6yw71.js} +3 -3
  172. package/dist/{work-objects-f708e069.js → work-objects-m0w1e7q8.js} +28 -28
  173. package/dist/worker-3p2vq107.js +79 -0
  174. package/dist/{worker-follow-up-0by8wztc.js → worker-follow-up-e3t6f895.js} +25 -25
  175. package/dist/{x-3dtaf2r9.js → x-asbrnafg.js} +2 -2
  176. package/openapi.json +1795 -1623
  177. package/package.json +13 -12
  178. package/src/apps/catalog.generated.json +726 -0
  179. package/src/apps/definition.ts +24 -7
  180. package/src/apps/page-validator.ts +225 -3
  181. package/src/be/db.ts +38 -10
  182. package/src/be/mcp-proxy.ts +5 -4
  183. package/src/be/migrations/340_api_key_spend_cap.sql +5 -0
  184. package/src/be/migrations/341_user_token_expiry.sql +4 -0
  185. package/src/be/schedules/validate.ts +26 -0
  186. package/src/be/scripts/run-credential.ts +55 -1
  187. package/src/be/scripts/typecheck.ts +4 -4
  188. package/src/be/scripts/user-code-mode.ts +160 -0
  189. package/src/be/swarm-config-guard.ts +4 -0
  190. package/src/be/users.ts +48 -7
  191. package/src/commands/credential-outcome-report.ts +5 -2
  192. package/src/commands/onboard/agent-fs-version.ts +1 -1
  193. package/src/commands/provider-credentials.ts +19 -0
  194. package/src/commands/provider-error-class.ts +4 -1
  195. package/src/commands/rate-limit-outcome.ts +48 -3
  196. package/src/commands/runner.ts +113 -55
  197. package/src/commands/worktree-reaper.ts +600 -0
  198. package/src/extensions/contract-types.generated.ts +1 -1
  199. package/src/http/agents.ts +4 -0
  200. package/src/http/api-keys.ts +27 -3
  201. package/src/http/pages-public.ts +40 -4
  202. package/src/http/pool-keys.ts +21 -2
  203. package/src/http/schedules.ts +28 -3
  204. package/src/http/script-connection-proxy.ts +18 -6
  205. package/src/http/script-connections.ts +12 -4
  206. package/src/http/script-runs.ts +12 -3
  207. package/src/http/scripts.ts +2 -11
  208. package/src/http/tasks.ts +6 -10
  209. package/src/http/users.ts +1 -0
  210. package/src/integrations/chat-sdk/adapters.ts +29 -0
  211. package/src/integrations/chat-sdk/limits.ts +3 -0
  212. package/src/integrations/chat-sdk/rocketchat/README.md +8 -0
  213. package/src/integrations/chat-sdk/rocketchat/index.ts +790 -0
  214. package/src/integrations/chat-sdk/rocketchat/markdown.ts +210 -0
  215. package/src/integrations/chat-sdk/rocketchat/types.ts +249 -0
  216. package/src/integrations/chat-sdk/runtime.ts +11 -5
  217. package/src/integrations/chat-sdk/schema.ts +37 -3
  218. package/src/integrations/chat-sdk/status.ts +9 -0
  219. package/src/mcp-client/http-client.ts +3 -1
  220. package/src/oauth/identity-capture.ts +6 -1
  221. package/src/oauth/mcp-wrapper.ts +10 -3
  222. package/src/oauth/wrapper.ts +15 -3
  223. package/src/prompts/session-templates.ts +1 -0
  224. package/src/providers/acp-targets.ts +2 -2
  225. package/src/providers/amp-adapter.ts +1 -1
  226. package/src/providers/dsh-adapter.ts +1 -1
  227. package/src/providers/pi-mono-adapter.ts +4 -2
  228. package/src/providers/runtime-dependencies.ts +1 -1
  229. package/src/rbac/legacy-policy.ts +3 -0
  230. package/src/rbac/permissions.ts +9 -0
  231. package/src/scripts-runtime/executors/native.ts +225 -67
  232. package/src/scripts-runtime/mcp-client.ts +2 -1
  233. package/src/scripts-runtime/swarm-sdk.ts +2 -1
  234. package/src/scripts-runtime/types/stdlib.d.ts +4 -4
  235. package/src/scripts-runtime/types/swarm-extension.d.ts +7 -7
  236. package/src/scripts-runtime/types/swarm-sdk.d.ts +4 -4
  237. package/src/server-user.ts +98 -0
  238. package/src/slack/enrich.ts +14 -11
  239. package/src/tests/agents-list-model-display.test.ts +23 -0
  240. package/src/tests/apps-spike2.test.ts +35 -0
  241. package/src/tests/base-prompt.test.ts +1 -0
  242. package/src/tests/chat-sdk-rocketchat-vendored.test.ts +67 -0
  243. package/src/tests/chat-sdk-status-route.test.ts +13 -1
  244. package/src/tests/codex-app-server.test.ts +4 -6
  245. package/src/tests/deploy-guard.test.ts +24 -0
  246. package/src/tests/dsh-adapter.test.ts +1 -1
  247. package/src/tests/ensure-token.test.ts +2 -2
  248. package/src/tests/entrypoint-repo-autoclone-args.test.ts +202 -0
  249. package/src/tests/fake-dns.ts +47 -0
  250. package/src/tests/fixtures/base-prompt-baseline.json +12 -12
  251. package/src/tests/latest-model-report.test.ts +138 -0
  252. package/src/tests/mcp-oauth-dcr-reuse.test.ts +5 -2
  253. package/src/tests/mcp-oauth-ensure-token.test.ts +3 -2
  254. package/src/tests/mcp-oauth-manual-client.test.ts +6 -1
  255. package/src/tests/mcp-oauth-wrapper.test.ts +20 -4
  256. package/src/tests/mcp-outbound-fetch-guard.test.ts +169 -0
  257. package/src/tests/mcp-server-ssrf.test.ts +2 -0
  258. package/src/tests/mcp-user-route.test.ts +10 -1
  259. package/src/tests/memory-search-stall.test.ts +5 -0
  260. package/src/tests/oauth-connection-fetch-guard.test.ts +162 -0
  261. package/src/tests/oauth-token-endpoint-fetch-guard.test.ts +121 -0
  262. package/src/tests/oauth-wrapper.test.ts +1 -2
  263. package/src/tests/pages-head-v2.test.ts +2 -1
  264. package/src/tests/script-connections-http.test.ts +8 -3
  265. package/src/tests/script-connections-mcp.test.ts +14 -10
  266. package/src/tests/script-connections-sql.test.ts +6 -2
  267. package/src/tests/script-connections.test.ts +4 -0
  268. package/src/tests/slack-thread-participants.test.ts +14 -3
  269. package/src/tests/spend-cap-credentials.test.ts +34 -0
  270. package/src/tests/spend-cap-outcome.test.ts +67 -0
  271. package/src/tests/subscription-first.test.ts +119 -0
  272. package/src/tests/worktree-reaper.test.ts +424 -0
  273. package/src/tools/get-task-details.ts +247 -5
  274. package/src/tools/schedules/patch-schedule.ts +26 -1
  275. package/src/tools/schedules/update-schedule.ts +28 -2
  276. package/src/tools/script-common.ts +37 -22
  277. package/src/tools/script-query-types.ts +1 -1
  278. package/src/tools/script-run.ts +1 -1
  279. package/src/tools/script-search.ts +12 -10
  280. package/src/tools/utils.ts +7 -1
  281. package/src/utils/credentials.ts +36 -1
  282. package/src/utils/egress-guard.ts +40 -10
  283. package/src/utils/error-tracker.ts +17 -0
  284. package/templates/skills/apps/SKILL.md +191 -2
  285. package/templates/skills/apps/content.md +191 -2
  286. package/templates/skills/boards-and-sheets/content.md +11 -0
  287. package/templates/skills/chat-sdk/content.md +2 -2
  288. package/templates/skills/pages/content.md +11 -0
  289. package/templates/skills/swarm-docs/content.md +4 -0
  290. package/templates/skills/swarm-scripts/SKILL.md +1 -0
  291. package/templates/skills/swarm-scripts/content.md +1 -0
  292. package/templates/workflows/ralph-loop/content.md +6 -6
  293. package/dist/acp-adapter-cn53011z.js +0 -17
  294. package/dist/cli-pr0eze3x.js +0 -149
  295. package/dist/core-0fqtbrxa.js +0 -42
  296. package/dist/fx-adapter-k6w3jvz9.js +0 -20
  297. package/dist/grok-adapter-4q5tssw0.js +0 -20
  298. package/dist/handlers-qxgfvvsf.js +0 -41
  299. package/dist/heartbeat-6tr2w2da.js +0 -50
  300. package/dist/index-0mcxjdsa.js +0 -44
  301. package/dist/index-dz4q23ag.js +0 -40
  302. package/dist/index-s175jckx.js +0 -39
  303. package/dist/lead-p3hx7h35.js +0 -79
  304. package/dist/thread-buffer-rwa7d4dx.js +0 -42
  305. package/dist/worker-8rg9gz74.js +0 -79
  306. /package/dist/{cli-m4ejz4nj.js → cli-cah298e5.js} +0 -0
@@ -6,6 +6,12 @@ import { isMcpUserEventsEnabled } from "./be/mcp-events/catalog";
6
6
  import { registerUserEvents } from "./be/mcp-events/protocol";
7
7
  import { enqueueAdmissionRow } from "./be/rbac-audit";
8
8
  import { getUserGrant } from "./be/rbac-roles";
9
+ import {
10
+ runScriptForUser,
11
+ scriptTypesForUser,
12
+ searchScriptsForUser,
13
+ type UserCodeModeResponse,
14
+ } from "./be/scripts/user-code-mode";
9
15
  import { MCP_MAX_TOOL_INPUT_ELEMENTS } from "./mcp-limits";
10
16
  import {
11
17
  type AdmissionRbac,
@@ -24,6 +30,14 @@ import {
24
30
  getTaskDetailsOutputSchema,
25
31
  } from "./tools/get-task-details";
26
32
  import { getTasksHandler, getTasksInputSchema, getTasksOutputSchema } from "./tools/get-tasks";
33
+ import {
34
+ scriptNameSchema,
35
+ scriptsApiToolResult,
36
+ scriptToolOutputSchema,
37
+ } from "./tools/script-common";
38
+ import { renderTypeBlobs } from "./tools/script-query-types";
39
+ import { renderRunOutput } from "./tools/script-run";
40
+ import { renderSearchResults, searchSuccessMessage } from "./tools/script-search";
27
41
  import { checkOutputSchemaShape, sendTaskHandler, sendTaskOutputSchema } from "./tools/send-task";
28
42
  import {
29
43
  steerTaskHandler,
@@ -68,6 +82,17 @@ export const userSendTaskInputSchema = z
68
82
  })
69
83
  .superRefine((data, ctx) => checkOutputSchemaShape(data.outputSchema, ctx));
70
84
 
85
+ const USER_CODE_MODE_SCOPE =
86
+ "Runs as you: the script's swarm calls carry your permissions, no agent's credentials or connections, and no task is created. Only global scripts are visible.";
87
+
88
+ function codeModeResult(
89
+ response: UserCodeModeResponse,
90
+ rendering: Parameters<typeof scriptsApiToolResult>[2],
91
+ ): SwarmToolResult {
92
+ const ok = response.status >= 200 && response.status < 300;
93
+ return scriptsApiToolResult(response.body, { ok, status: response.status }, rendering);
94
+ }
95
+
71
96
  function permission(verb: PermissionVerb): AdmissionRbac {
72
97
  return { permission: verb };
73
98
  }
@@ -190,6 +215,79 @@ export function createUserServer(user: User, tokenId?: string): McpServer {
190
215
  return cancelTaskHandler(userCtx(user, info.sessionId), args);
191
216
  });
192
217
 
218
+ // Code mode: the agent-side script-search / script-query-types / script-run,
219
+ // scoped to the user (see src/be/scripts/user-code-mode.ts).
220
+ const scriptSearchConfig = {
221
+ title: "Script Search",
222
+ description: `Search the swarm's reusable TypeScript scripts by intent. ${USER_CODE_MODE_SCOPE}`,
223
+ annotations: { readOnlyHint: true, openWorldHint: false },
224
+ rbac: permission("script.search"),
225
+ inputSchema: z.object({
226
+ query: z.string().default("").describe("What the script should do."),
227
+ limit: z.number().int().min(1).max(100).default(10).describe("Maximum results."),
228
+ }),
229
+ outputSchema: scriptToolOutputSchema,
230
+ };
231
+ registerTool("script-search", scriptSearchConfig, async (args) => {
232
+ const denied = await maybeDenyUserToolAdmission(user, "script-search", scriptSearchConfig);
233
+ if (denied) return denied;
234
+ return codeModeResult(await searchScriptsForUser(args), {
235
+ successMessage: searchSuccessMessage,
236
+ successDetails: renderSearchResults,
237
+ });
238
+ });
239
+
240
+ // Not `script-query-types`: this name is exempt from the result-size spill
241
+ // (CTX_CONTROL_EXEMPT_TOOLS), since a user has no kv to read a spill back from.
242
+ const scriptGetTypesConfig = {
243
+ title: "Script Get Types",
244
+ description: `Get the TypeScript declarations a script is written against: the \`swarm-sdk\` module (\`ScriptContext\`, \`ctx.swarm\`) and the \`stdlib\` module, about 12k tokens. Pass \`name\` to also get that script's signature and args schema. ${USER_CODE_MODE_SCOPE}`,
245
+ annotations: { readOnlyHint: true, openWorldHint: false },
246
+ inputSchema: z.object({
247
+ name: scriptNameSchema.optional().describe("Optional global script name."),
248
+ }),
249
+ outputSchema: scriptToolOutputSchema,
250
+ };
251
+ registerTool("script-get-types", scriptGetTypesConfig, async ({ name }) => {
252
+ const denied = await maybeDenyUserToolAdmission(user, "script-get-types", scriptGetTypesConfig);
253
+ if (denied) return denied;
254
+ const response = await scriptTypesForUser(name);
255
+ const { stdlibTypes: _types, ...small } = response.body as Record<string, unknown>;
256
+ return codeModeResult(
257
+ // The declarations go out once, in details; data keeps only the small fields.
258
+ { status: response.status, body: small },
259
+ {
260
+ successMessage: () =>
261
+ name
262
+ ? `Type definitions for script \`${name}\` fetched.`
263
+ : "Script type definitions fetched.",
264
+ successDetails: () => renderTypeBlobs(response.body),
265
+ uncappedDetails: true,
266
+ },
267
+ );
268
+ });
269
+
270
+ const scriptRunConfig = {
271
+ title: "Script Run",
272
+ description: `Run a global script by \`name\`, or inline TypeScript \`source\` that does \`export default async function (args, ctx)\`. Inline source is not typechecked or saved. ${USER_CODE_MODE_SCOPE}`,
273
+ annotations: { openWorldHint: true },
274
+ rbac: permission("script.run"),
275
+ inputSchema: z.object({
276
+ name: scriptNameSchema.optional().describe("Global script to run."),
277
+ source: z.string().min(1).optional().describe("Inline TypeScript source to run."),
278
+ args: z.unknown().optional().describe("JSON-serializable script arguments."),
279
+ }),
280
+ outputSchema: scriptToolOutputSchema,
281
+ };
282
+ registerTool("script-run", scriptRunConfig, async (args) => {
283
+ const denied = await maybeDenyUserToolAdmission(user, "script-run", scriptRunConfig);
284
+ if (denied) return denied;
285
+ return codeModeResult(await runScriptForUser({ userId: user.id, ...args }), {
286
+ successMessage: () => "Script run completed.",
287
+ successDetails: renderRunOutput,
288
+ });
289
+ });
290
+
193
291
  if (isSteeringEnabled()) {
194
292
  const steerTaskConfig = {
195
293
  title: "Steer Task",
@@ -168,7 +168,7 @@ export async function resolveSlackParticipant(
168
168
  // Another team's profile email is set by that team, not verified as owned by
169
169
  // this sender, so it never links to an existing user. An operator can link
170
170
  // the alias by hand. With our own team unknown (`auth.test` failed), a sender
171
- // that carries a team is not linked either; trust below still reads the email.
171
+ // that carries a team is not linked either, and its email grants no trust.
172
172
  const linkable = !eventContext.userTeam || sameTeam === true;
173
173
  if (!user && email && linkable) {
174
174
  if (isCompanyEmail(email, domains)) {
@@ -207,17 +207,20 @@ export async function resolveSlackParticipant(
207
207
  ? audience
208
208
  : foreignTeam
209
209
  ? "external"
210
- : domains.length === 0
211
- ? user
212
- ? "internal"
213
- : email
214
- ? "external"
215
- : "unknown"
216
- : !email
217
- ? "unknown"
218
- : isCompanyEmail(email, domains)
210
+ : // Own team unknown: the sender's team may be foreign, so its email proves nothing.
211
+ eventContext.userTeam && sameTeam === undefined
212
+ ? "unknown"
213
+ : domains.length === 0
214
+ ? user
219
215
  ? "internal"
220
- : "external";
216
+ : email
217
+ ? "external"
218
+ : "unknown"
219
+ : !email
220
+ ? "unknown"
221
+ : isCompanyEmail(email, domains)
222
+ ? "internal"
223
+ : "external";
221
224
  return { userId: user?.id, trust };
222
225
  }
223
226
 
@@ -56,6 +56,29 @@ describe("agents list model display", () => {
56
56
  });
57
57
  });
58
58
 
59
+ test("a last run whose model the task chose is not flagged as a pending change", () => {
60
+ const display = getAgentModelDisplay(
61
+ "openai-codex/gpt-6.1-sol",
62
+ "openrouter/deepseek/deepseek-v4.1-flash",
63
+ undefined,
64
+ "task",
65
+ );
66
+
67
+ expect(display.diverged).toBe(false);
68
+ expect(display.lastUsedFromTask).toBe(true);
69
+ expect(display.primary).toBe("openai-codex/gpt-6.1-sol");
70
+ });
71
+
72
+ test("a last run on neither the saved model nor a task's pick still reads as next task", () => {
73
+ expect(
74
+ getAgentModelDisplay("claude-opus-4-7", "claude-sonnet-4-6", undefined, "agent_config")
75
+ .diverged,
76
+ ).toBe(true);
77
+ expect(
78
+ getAgentModelDisplay("claude-opus-4-7", "claude-sonnet-4-6", undefined, "custom").diverged,
79
+ ).toBe(true);
80
+ });
81
+
59
82
  test("shows configured model alone before an agent reports a last-used model", () => {
60
83
  const display = getAgentModelDisplay("claude-opus-4-7", null);
61
84
 
@@ -1035,8 +1035,42 @@ describe("custom app actions", () => {
1035
1035
  agentId: OTHER_AGENT_ID,
1036
1036
  typeChecked: true,
1037
1037
  });
1038
+ // A global script another agent wrote runs as that agent at invoke time.
1039
+ const foreignGlobal = await upsertScriptByName({
1040
+ name: `app_action_foreign_global_${crypto.randomUUID().replaceAll("-", "")}`,
1041
+ scope: "global",
1042
+ scopeId: null,
1043
+ source: "export default function run() { return { ok: true }; }",
1044
+ description: "Foreign-written global action fixture",
1045
+ intent: "Prove the script ownership gate for global scripts",
1046
+ signatureJson: JSON.stringify({ args: { type: "object" }, result: { type: "object" } }),
1047
+ agentId: LEAD_ID,
1048
+ typeChecked: true,
1049
+ });
1038
1050
 
1039
1051
  try {
1052
+ const deniedGlobal = await request<{ issues: Array<{ path: string; message: string }> }>(
1053
+ "/api/apps",
1054
+ {
1055
+ method: "POST",
1056
+ body: JSON.stringify({
1057
+ name: "Foreign global wire",
1058
+ definition: {
1059
+ ...baseDefinition,
1060
+ actions: { run: { kind: "script", scriptId: foreignGlobal.script.id } },
1061
+ },
1062
+ }),
1063
+ },
1064
+ );
1065
+ expect(deniedGlobal.status).toBe(400);
1066
+ expect(
1067
+ deniedGlobal.body.issues.some(
1068
+ (issue) =>
1069
+ issue.path === "actions.run.scriptId" &&
1070
+ issue.message.includes("only that agent or the operator"),
1071
+ ),
1072
+ ).toBe(true);
1073
+
1040
1074
  // An agent writer referencing a foreign agent-scoped script is rejected.
1041
1075
  const denied = await request<{ issues: Array<{ path: string; message: string }> }>(
1042
1076
  "/api/apps",
@@ -1084,6 +1118,7 @@ describe("custom app actions", () => {
1084
1118
  expect(patched.status).toBe(200);
1085
1119
  } finally {
1086
1120
  await deleteScript({ name: foreign.script.name, scope: "agent", scopeId: OTHER_AGENT_ID });
1121
+ await deleteScript({ name: foreignGlobal.script.name, scope: "global" });
1087
1122
  }
1088
1123
  });
1089
1124
 
@@ -829,6 +829,7 @@ For task waits, add \`wakeOn:{event:"settled",taskIds:["<id>"],mode:"all"}\`; th
829
829
  ## Workspace
830
830
 
831
831
  \`/workspace/personal/\` is yours. \`get-repos\` returns where a repository is cloned.
832
+ Worktrees without unsaved work are removed after your task. To keep one: \`git worktree lock <path>\`.
832
833
  Your profile lives in the database. Edit it with \`update-profile\`: \`soulMd\`, \`identityMd\`, \`heartbeatMd\`, \`setupScript\`, \`toolsMd\`. The files in \`/workspace/\` are mirrors.
833
834
  Your setup script runs at every container start.
834
835
  \`/workspace/TOOLS.md\` holds your environment notes: repos, hosts, services, tool quirks. Read it when a task touches a repo, host, or service you have not used this session. Update it with \`update-profile\` \`toolsMd\`.
@@ -0,0 +1,67 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { NetworkError } from "@chat-adapter/shared";
3
+ import { createRocketChatAdapter } from "../integrations/chat-sdk/rocketchat/index";
4
+
5
+ const WEBHOOK_TOKEN = "rc-outgoing-webhook-token";
6
+
7
+ function adapterFor(baseUrl: string) {
8
+ return createRocketChatAdapter({
9
+ baseUrl,
10
+ token: "rc-personal-access-token",
11
+ botUserId: "rc-bot-user-id",
12
+ webhookToken: WEBHOOK_TOKEN,
13
+ userName: "swarm",
14
+ });
15
+ }
16
+
17
+ function webhook(token: string | undefined): Request {
18
+ return new Request("http://localhost/webhook", {
19
+ method: "POST",
20
+ body: JSON.stringify({ token, message_id: "m1", channel_id: "room", user_id: "u1", text: "" }),
21
+ });
22
+ }
23
+
24
+ describe("in-repo Rocket.Chat adapter", () => {
25
+ test("loads from the repo with no chat-adapter-rocketchat npm package", async () => {
26
+ expect(() => Bun.resolveSync("chat-adapter-rocketchat", import.meta.dir)).toThrow();
27
+ const pkg = await Bun.file(new URL("../../package.json", import.meta.url)).json();
28
+ expect(pkg.dependencies?.["chat-adapter-rocketchat"]).toBeUndefined();
29
+ expect(adapterFor("https://chat.example.com/").name).toBe("rocketchat");
30
+ });
31
+
32
+ test("the webhook token check rejects a wrong, shorter, longer or missing token", async () => {
33
+ const adapter = adapterFor("https://chat.example.com");
34
+ // No Chat instance is attached, so a valid token answers 200 without processing.
35
+ expect((await adapter.handleWebhook(webhook(WEBHOOK_TOKEN))).status).toBe(200);
36
+ for (const token of ["x".repeat(WEBHOOK_TOKEN.length), "short", `${WEBHOOK_TOKEN}-x`, ""]) {
37
+ expect((await adapter.handleWebhook(webhook(token))).status).toBe(401);
38
+ }
39
+ expect((await adapter.handleWebhook(webhook(undefined))).status).toBe(401);
40
+ });
41
+
42
+ test("the auth token never follows a redirect to another origin", async () => {
43
+ const seen: Array<string | null> = [];
44
+ const foreign = Bun.serve({
45
+ port: 0,
46
+ fetch(request) {
47
+ seen.push(request.headers.get("x-auth-token"));
48
+ return Response.json({ success: true, message: { _id: "m1" } });
49
+ },
50
+ });
51
+ const instance = Bun.serve({
52
+ port: 0,
53
+ fetch: () =>
54
+ Response.redirect(`http://127.0.0.1:${foreign.port}/api/v1/chat.postMessage`, 307),
55
+ });
56
+ try {
57
+ const adapter = adapterFor(`http://localhost:${instance.port}`);
58
+ await expect(
59
+ adapter.postMessage("rocketchat:room", { markdown: "hi" }),
60
+ ).rejects.toBeInstanceOf(NetworkError);
61
+ expect(seen).toEqual([]);
62
+ } finally {
63
+ instance.stop(true);
64
+ foreign.stop(true);
65
+ }
66
+ });
67
+ });
@@ -175,7 +175,13 @@ describe("GET /api/integrations/chat/status", () => {
175
175
  expect(body.enabled).toBe(true);
176
176
  expect(body.slackClash).toBe(false);
177
177
  const byName = Object.fromEntries(body.adapters.map((a) => [a.name, a]));
178
- expect(Object.keys(byName).sort()).toEqual(["discord", "slack", "teams", "telegram"]);
178
+ expect(Object.keys(byName).sort()).toEqual([
179
+ "discord",
180
+ "rocketchat",
181
+ "slack",
182
+ "teams",
183
+ "telegram",
184
+ ]);
179
185
 
180
186
  expect(byName.telegram).toMatchObject({
181
187
  configured: true,
@@ -201,6 +207,12 @@ describe("GET /api/integrations/chat/status", () => {
201
207
  webhookUrl: `${PUBLIC_URL}/api/integrations/chat/discord/webhook`,
202
208
  });
203
209
  expect(byName.teams).toMatchObject({ configured: false, health: "disabled", connected: false });
210
+ expect(byName.rocketchat).toMatchObject({
211
+ configured: false,
212
+ health: "disabled",
213
+ connected: false,
214
+ webhookUrl: `${PUBLIC_URL}/api/integrations/chat/rocketchat/webhook`,
215
+ });
204
216
  });
205
217
 
206
218
  test("flags the Slack clash when SLACK_DISABLE is not true", async () => {
@@ -226,7 +226,9 @@ describe("CodexAppServer", () => {
226
226
 
227
227
  for (const { name, launchOnGateway } of [
228
228
  {
229
- name: "pinned Codex rejects a gateway turn on an app-server launched without it",
229
+ // Codex <= 0.167 rejected this turn ("your current provider is openai").
230
+ // 0.168+ honors the thread-level provider, so both launches start the turn.
231
+ name: "pinned Codex accepts a gateway turn on an app-server launched without it",
230
232
  launchOnGateway: false,
231
233
  },
232
234
  {
@@ -267,11 +269,7 @@ describe("CodexAppServer", () => {
267
269
  threadId: started.thread.id,
268
270
  input: [{ type: "text", text: "hi" }],
269
271
  });
270
- if (launchOnGateway) await turn;
271
- else
272
- await expect(turn).rejects.toThrow(
273
- "This chat uses swarm-gateway, but your current provider is openai",
274
- );
272
+ await turn;
275
273
  } finally {
276
274
  await server.close();
277
275
  await rm(home, { recursive: true, force: true });
@@ -152,3 +152,27 @@ describe.skipIf(!hasYq && !process.env.CI)("deploy guard (scripts/deploy-guard.s
152
152
  CHILD_PROCESS_TEST_BUDGET_MS,
153
153
  );
154
154
  });
155
+
156
+ // Job-level concurrency orders jobs by when they reach the gate, not by commit:
157
+ // with cancel-in-progress an older run whose detect job finished last cancelled
158
+ // the main tip's builds, and :latest stayed on an older build. Builds now never
159
+ // cancel; a superseded run skips them instead.
160
+ test("build jobs never cancel each other and skip when superseded", async () => {
161
+ type Job = { if?: string; concurrency?: Record<string, unknown> };
162
+ const wf = Bun.YAML.parse(await Bun.file(join(REPO_ROOT, WORKFLOW)).text()) as {
163
+ jobs: Record<string, Job>;
164
+ };
165
+ const builds = Object.entries(wf.jobs).filter(([name]) => name.startsWith("build-and-push-"));
166
+ expect(builds.length).toBeGreaterThanOrEqual(7);
167
+ for (const [name, job] of builds) {
168
+ expect({ name, cancel: job.concurrency?.["cancel-in-progress"] }).toEqual({
169
+ name,
170
+ cancel: false,
171
+ });
172
+ expect({ name, queue: job.concurrency?.queue }).toEqual({ name, queue: "max" });
173
+ expect({ name, if: job.if }).toEqual({
174
+ name,
175
+ if: "needs.detect-version-change.outputs.superseded != 'true'",
176
+ });
177
+ }
178
+ });
@@ -376,7 +376,7 @@ describe("dsh harness", () => {
376
376
  await rename(join(config.cwd, "dsh"), join(config.cwd, "npx"));
377
377
  config.env = { ...config.env, DSH_BINARY: "", PATH: config.cwd };
378
378
  await expect(new DshAdapter().createSession(config)).rejects.toThrow(
379
- "dsh CLI not found. Install @deepseek-ai/dsh@0.2.2-rc.2",
379
+ "dsh CLI not found. Install @deepseek-ai/dsh@0.2.2-rc.3",
380
380
  );
381
381
  expect(await Bun.file(join(config.cwd, "invocation.json")).exists()).toBe(false);
382
382
  });
@@ -92,8 +92,8 @@ describe("ensureToken", () => {
92
92
 
93
93
  // Should have called the token endpoint
94
94
  expect(fetchSpy).toHaveBeenCalledTimes(1);
95
- const [url, init] = fetchSpy.mock.calls[0] as [string, RequestInit];
96
- expect(url).toBe("https://example.com/oauth/token");
95
+ const [url, init] = fetchSpy.mock.calls[0] as [string | URL, RequestInit];
96
+ expect(String(url)).toBe("https://example.com/oauth/token");
97
97
  expect(init.method).toBe("POST");
98
98
  expect(init.body).toContain("grant_type=refresh_token");
99
99
  expect(init.body).toContain("refresh_token=example-refresh-token");
@@ -0,0 +1,202 @@
1
+ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2
+ import {
3
+ chmodSync,
4
+ existsSync,
5
+ mkdirSync,
6
+ mkdtempSync,
7
+ readFileSync,
8
+ realpathSync,
9
+ rmSync,
10
+ writeFileSync,
11
+ } from "node:fs";
12
+ import { tmpdir } from "node:os";
13
+ import { join } from "node:path";
14
+ import { CHILD_PROCESS_TEST_BUDGET_MS, expectChildOk, runChild } from "./test-proc";
15
+
16
+ /**
17
+ * Runs the real repo auto-clone loop from docker-entrypoint.sh against a
18
+ * scratch repos.json. gosu, git and gh are stubbed: git and gh log their argv
19
+ * one element per line, so the test can check that every repo field reaches
20
+ * the command as exactly one argument and is never parsed as shell.
21
+ */
22
+ const entrypoint = readFileSync("docker-entrypoint.sh", "utf8");
23
+ const loopStart = entrypoint.indexOf(
24
+ "jq -c '.repos[]' /tmp/swarm_repos.json | while read -r repo; do",
25
+ );
26
+ const loopEnd = entrypoint.indexOf("\n done\n", loopStart);
27
+ const loop = entrypoint
28
+ .slice(loopStart, loopEnd + "\n done\n".length)
29
+ .replace("/tmp/swarm_repos.json", '"$REPOS_JSON"');
30
+
31
+ let root = "";
32
+ let bin = "";
33
+ beforeAll(() => {
34
+ root = realpathSync(mkdtempSync(join(tmpdir(), "entrypoint-autoclone-")));
35
+ bin = join(root, "bin");
36
+ mkdirSync(bin);
37
+ // Each stub appends its name and argv (one element per line) to $ARGV_LOG.
38
+ const stub = (name: string, extra = "") =>
39
+ `#!/usr/bin/env bash\n{ echo "== ${name}"; for a in "$@"; do printf '%s\\n' "$a"; done; } >> "$ARGV_LOG"\n${extra}exit 0\n`;
40
+ writeFileSync(join(bin, "gh"), stub("gh"));
41
+ writeFileSync(
42
+ join(bin, "git"),
43
+ stub("git", 'if [ "$1" = branch ]; then echo "$CURRENT_BRANCH"; fi\n'),
44
+ );
45
+ chmodSync(join(bin, "gh"), 0o755);
46
+ chmodSync(join(bin, "git"), 0o755);
47
+ });
48
+ afterAll(() => {
49
+ rmSync(root, { recursive: true, force: true });
50
+ });
51
+
52
+ interface Repo {
53
+ url: string;
54
+ name: string;
55
+ clonePath: string;
56
+ defaultBranch: string;
57
+ }
58
+
59
+ async function runLoop(caseDir: string, repo: Repo, currentBranch = repo.defaultBranch) {
60
+ const reposJson = join(caseDir, "repos.json");
61
+ const argvLog = join(caseDir, "argv.log");
62
+ writeFileSync(reposJson, JSON.stringify({ repos: [{ ...repo, hooks: { enabled: false } }] }));
63
+ writeFileSync(argvLog, "");
64
+ const result = await runChild(
65
+ [
66
+ "bash",
67
+ "-c",
68
+ [
69
+ 'gosu() { shift; "$@"; }',
70
+ "chown() { :; }",
71
+ "chown_no_follow() { :; }",
72
+ "prepare_clone_target() { :; }",
73
+ loop,
74
+ ].join("\n"),
75
+ ],
76
+ {
77
+ cwd: caseDir,
78
+ env: {
79
+ PATH: `${bin}:${process.env.PATH ?? "/usr/bin:/bin"}`,
80
+ REPOS_JSON: reposJson,
81
+ ARGV_LOG: argvLog,
82
+ CURRENT_BRANCH: currentBranch,
83
+ },
84
+ timeoutMs: CHILD_PROCESS_TEST_BUDGET_MS,
85
+ },
86
+ );
87
+ expectChildOk(result, "repo auto-clone loop");
88
+ return readFileSync(argvLog, "utf8");
89
+ }
90
+
91
+ function freshCase(name: string) {
92
+ const dir = join(root, name);
93
+ mkdirSync(dir, { recursive: true });
94
+ return dir;
95
+ }
96
+
97
+ describe("docker-entrypoint.sh repo auto-clone", () => {
98
+ test("located the loop", () => {
99
+ expect(loopStart).toBeGreaterThan(-1);
100
+ expect(loopEnd).toBeGreaterThan(loopStart);
101
+ });
102
+
103
+ test("control: plain fields reach gh and git unchanged", async () => {
104
+ const dir = freshCase("plain");
105
+ const clonePath = join(dir, "repos", "r");
106
+ const cloneLog = await runLoop(dir, {
107
+ url: "https://github.com/o/r",
108
+ name: "r",
109
+ clonePath,
110
+ defaultBranch: "main",
111
+ });
112
+ expect(cloneLog).toContain(
113
+ `== gh\nrepo\nclone\nhttps://github.com/o/r\n${clonePath}\n--\n--branch\nmain\n--single-branch\n`,
114
+ );
115
+
116
+ mkdirSync(join(clonePath, ".git"), { recursive: true });
117
+ const syncLog = await runLoop(dir, {
118
+ url: "https://github.com/o/r",
119
+ name: "r",
120
+ clonePath,
121
+ defaultBranch: "main",
122
+ });
123
+ expect(syncLog).toContain("== git\nreset\n--hard\norigin/main\n");
124
+ });
125
+
126
+ test("a quote in the url stays inside the url argument", async () => {
127
+ const dir = freshCase("url");
128
+ const marker = join(dir, "marker");
129
+ const url = `https://github.com/o/r'; touch '${marker}'; echo '`;
130
+ const log = await runLoop(dir, {
131
+ url,
132
+ name: "r",
133
+ clonePath: join(dir, "repos", "r"),
134
+ defaultBranch: "main",
135
+ });
136
+ expect(existsSync(marker)).toBe(false);
137
+ expect(log.split("\n")).toContain(url);
138
+ });
139
+
140
+ test("a quote in the url stays inside the url argument for plain git hosts", async () => {
141
+ const dir = freshCase("url-git");
142
+ const marker = join(dir, "marker");
143
+ const url = `https://gitlab.example.com/o/r'; touch '${marker}'; echo '`;
144
+ const log = await runLoop(dir, {
145
+ url,
146
+ name: "r",
147
+ clonePath: join(dir, "repos", "r"),
148
+ defaultBranch: "main",
149
+ });
150
+ expect(existsSync(marker)).toBe(false);
151
+ expect(log.split("\n")).toContain(url);
152
+ });
153
+
154
+ test("a quote in the clone path stays inside the path argument", async () => {
155
+ const dir = freshCase("path");
156
+ const marker = join(dir, "marker");
157
+ const clonePath = join(dir, "repos", `r'; touch '${marker}'; echo '`);
158
+ const log = await runLoop(dir, {
159
+ url: "https://github.com/o/r",
160
+ name: "r",
161
+ clonePath,
162
+ defaultBranch: "main",
163
+ });
164
+ expect(existsSync(marker)).toBe(false);
165
+ expect(log.split("\n")).toContain(clonePath);
166
+ });
167
+
168
+ test("a quote in the default branch stays inside the branch argument when syncing", async () => {
169
+ const dir = freshCase("branch-sync");
170
+ const marker = join(dir, "marker");
171
+ const clonePath = join(dir, "repos", "r");
172
+ mkdirSync(join(clonePath, ".git"), { recursive: true });
173
+ const branch = `main'; touch '${marker}'; echo '`;
174
+ await runLoop(dir, {
175
+ url: "https://github.com/o/r",
176
+ name: "r",
177
+ clonePath,
178
+ defaultBranch: branch,
179
+ });
180
+ expect(existsSync(marker)).toBe(false);
181
+ });
182
+
183
+ test("a url or branch that starts with a dash is skipped, never passed to git as an option", async () => {
184
+ const dir = freshCase("dash");
185
+ const clonePath = join(dir, "repos", "r");
186
+ mkdirSync(join(clonePath, ".git"), { recursive: true });
187
+ const branchLog = await runLoop(dir, {
188
+ url: "https://github.com/o/r",
189
+ name: "r",
190
+ clonePath,
191
+ defaultBranch: "--upload-pack=true",
192
+ });
193
+ const urlLog = await runLoop(dir, {
194
+ url: "--upload-pack=true",
195
+ name: "r",
196
+ clonePath: join(dir, "repos", "fresh"),
197
+ defaultBranch: "main",
198
+ });
199
+ expect(branchLog).not.toContain("--upload-pack");
200
+ expect(urlLog).not.toContain("--upload-pack");
201
+ });
202
+ });