@desplega.ai/agent-swarm 1.160.0 → 1.162.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (398) hide show
  1. package/README.md +4 -3
  2. package/dist/{acp-adapter-2mjwcsfh.js → acp-adapter-74m73ae9.js} +163 -49
  3. package/dist/{actions-e43rxskr.js → actions-4sr14gnt.js} +42 -38
  4. package/dist/{anthropic-messages-5qx80j9k.js → anthropic-messages-8xxrzky9.js} +22 -26
  5. package/dist/{app-mc7xfagn.js → app-pt68fbwp.js} +17 -14
  6. package/dist/{artifact-3v5t9jtg.js → artifact-fey7dvj9.js} +3 -2
  7. package/dist/{assistant-sedkzv3b.js → assistant-cv3jytks.js} +43 -39
  8. package/dist/{azure-openai-responses-nfb21z9a.js → azure-openai-responses-f5cqsyj8.js} +15 -10
  9. package/dist/{boot-reembed-m3656j2n.js → boot-reembed-4ht4gqth.js} +17 -14
  10. package/dist/{boot-reembed-cqz9swn5.js → boot-reembed-nxpcvpj9.js} +16 -13
  11. package/dist/{boot-scrub-logs-xbxf5d7w.js → boot-scrub-logs-k93kyw8k.js} +13 -10
  12. package/dist/boot-seeds-1skcrs0e.js +32 -0
  13. package/dist/{claude-adapter-dc6289mc.js → claude-adapter-r5g0tzge.js} +39 -30
  14. package/dist/{claude-managed-adapter-naaw51me.js → claude-managed-adapter-yxkfxg8j.js} +6 -5
  15. package/dist/{claude-managed-setup-eacvchx0.js → claude-managed-setup-pkyrgshb.js} +27 -27
  16. package/dist/{claude-sdk-session-bqp2xvym.js → claude-sdk-session-jxyxnrwd.js} +8041 -7910
  17. package/dist/{cli-4derpgyk.js → cli-2hhfhfq5.js} +6 -1
  18. package/dist/{cli-rykfmgwg.js → cli-2x0e561b.js} +1 -1
  19. package/dist/{cli-tzx2ke1v.js → cli-2zy95vhm.js} +137 -64
  20. package/dist/{cli-0x01kwrd.js → cli-4cwxn7gp.js} +47 -186
  21. package/dist/{cli-xjcywfsf.js → cli-4dcpaefp.js} +12 -11
  22. package/dist/{cli-v7fn5gms.js → cli-4x0csdjq.js} +164 -76
  23. package/dist/{cli-12tszpk9.js → cli-5bcd7sfy.js} +91 -29
  24. package/dist/{cli-jz4w45qt.js → cli-5k6k8ta3.js} +190 -50
  25. package/dist/{cli-tpq83z89.js → cli-5xhpb3kv.js} +20 -19
  26. package/dist/{cli-r1mxd1xh.js → cli-7af8yhav.js} +6 -179
  27. package/dist/{cli-jajnsm8q.js → cli-7tre70zp.js} +18160 -31345
  28. package/dist/{cli-447dt1h3.js → cli-8ev9xqnx.js} +218 -25
  29. package/dist/cli-bsky8g7w.js +449 -0
  30. package/dist/{cli-0z2v4nhw.js → cli-cat6h73s.js} +1 -1
  31. package/dist/{cli-25fcq4b4.js → cli-cebmgwsc.js} +15 -11
  32. package/dist/{cli-shkxm1vn.js → cli-cvatsam7.js} +189 -13
  33. package/dist/{cli-2658f6at.js → cli-cvk6yzw5.js} +6 -8
  34. package/dist/cli-dbmwby6a.js +9 -0
  35. package/dist/{cli-ptr8h7kp.js → cli-eg0b3p0k.js} +5 -218
  36. package/dist/cli-f9w1semm.js +413 -0
  37. package/dist/{cli-523679eh.js → cli-g739zqzt.js} +6 -5
  38. package/dist/{cli-dv6cdjs2.js → cli-gd4favx9.js} +28 -7
  39. package/dist/{cli-c8a36vcc.js → cli-gpqpmns7.js} +2 -2
  40. package/dist/{cli-5nbmpy8w.js → cli-hb5c2x5y.js} +1 -1
  41. package/dist/{cli-741yb0xx.js → cli-hmsw1gpy.js} +55 -169
  42. package/dist/{cli-qydf22qq.js → cli-jf7wmv1r.js} +2562 -735
  43. package/dist/{cli-mfe5btp9.js → cli-jxs2ygaw.js} +317 -121
  44. package/dist/{cli-kmcpfwn2.js → cli-jyy6pm2f.js} +19 -3
  45. package/dist/cli-kdkwd3yr.js +615 -0
  46. package/dist/{cli-6cs6wzxt.js → cli-kh04eqwe.js} +2 -2
  47. package/dist/{cli-9hsgwz4w.js → cli-kp42yek0.js} +1309 -391
  48. package/dist/cli-ma3zvh39.js +10404 -0
  49. package/dist/{cli-ybgv4kw2.js → cli-mbssg1xv.js} +9 -2
  50. package/dist/{cli-jsp14b6c.js → cli-mzfth0bp.js} +38 -1
  51. package/dist/{cli-r2ap2czm.js → cli-nexqx4ve.js} +6 -0
  52. package/dist/{cli-f8gy6r2r.js → cli-nq7yqw7b.js} +19 -8
  53. package/dist/{cli-10nhj6xq.js → cli-nt8hecg9.js} +34 -33
  54. package/dist/cli-p0r8sxj5.js +303 -0
  55. package/dist/{cli-58e8yr0d.js → cli-pkd6s2wy.js} +4 -2
  56. package/dist/{cli-a8dvhzrt.js → cli-q24re23n.js} +7 -5
  57. package/dist/cli-qjjvzwzd.js +222 -0
  58. package/dist/cli-qrgt5bqf.js +189 -0
  59. package/dist/{cli-et8m9xsv.js → cli-rfjw9jw2.js} +22 -10
  60. package/dist/{cli-7e398j1h.js → cli-rj0gqwwp.js} +3 -3
  61. package/dist/{cli-btfv8y88.js → cli-rnyzn44p.js} +2 -2
  62. package/dist/{cli-d5czme6m.js → cli-s3hwpt9v.js} +4754 -4945
  63. package/dist/{cli-0jwe9034.js → cli-sptrj5f5.js} +3 -3
  64. package/dist/{cli-0q3avq3s.js → cli-sqvfa090.js} +19 -11
  65. package/dist/{cli-azhgzetg.js → cli-swfmp1fx.js} +27 -27
  66. package/dist/{cli-jyk0ynw2.js → cli-t845n9xk.js} +23 -10
  67. package/dist/{cli-zpep9q5e.js → cli-tcen9p5w.js} +20 -15
  68. package/dist/{cli-74h9hscv.js → cli-tre4bdgq.js} +1 -1
  69. package/dist/{cli-pm1rst0h.js → cli-twrh04ap.js} +30 -15
  70. package/dist/{cli-phsaj4xq.js → cli-v0pvvhfq.js} +1 -1
  71. package/dist/{cli-ydmcgve1.js → cli-vc9bp061.js} +5 -5
  72. package/dist/{cli-g2whhdrf.js → cli-vxe6qa4h.js} +1 -1
  73. package/dist/{cli-vctdqs5h.js → cli-vy3ed88x.js} +15 -2
  74. package/dist/{cli-br0qdrnp.js → cli-vyqs9ya8.js} +18 -18
  75. package/dist/{cli-cpvsaqsw.js → cli-w0bwte75.js} +8 -5
  76. package/dist/cli-wbvnn6tk.js +861 -0
  77. package/dist/{cli-r94z9p1z.js → cli-wgbezhw2.js} +3 -0
  78. package/dist/{cli-evvtk35y.js → cli-wjgs5wxe.js} +7 -7
  79. package/dist/cli-wxkkd0e0.js +33 -0
  80. package/dist/{cli-0wgxmwf6.js → cli-xk79303e.js} +20 -7
  81. package/dist/{cli-ktmyrtpn.js → cli-xqpk3rp7.js} +33 -10
  82. package/dist/{cli-ygwm91nt.js → cli-yy6dew39.js} +1 -1
  83. package/dist/cli-zp38xvtm.js +9487 -0
  84. package/dist/{cli-tfky2838.js → cli-zvhd3f64.js} +4 -4
  85. package/dist/{cli-jayjpjmb.js → cli-zxqx25nz.js} +66 -23
  86. package/dist/cli.js +40 -32
  87. package/dist/{cloudflare-workers-ai-system-one-k6fbxw9d.js → cloudflare-workers-ai-system-one-k8ddqjkq.js} +8 -6
  88. package/dist/{codex-adapter-nmxcatww.js → codex-adapter-esvmnhn7.js} +24 -23
  89. package/dist/{codex-hook-20me6byw.js → codex-hook-m73jmqgx.js} +19 -3
  90. package/dist/{codex-login-w6fz4xbz.js → codex-login-cf7mzsgg.js} +2 -2
  91. package/dist/{codex-session-runner-90aa80ev.js → codex-session-runner-ban9excr.js} +24 -23
  92. package/dist/{commands-8wcq1kn7.js → commands-75413p2n.js} +13 -10
  93. package/dist/{db-j40kc4se.js → db-7f5pecwg.js} +17 -10
  94. package/dist/{dispatcher-4zqy768d.js → dispatcher-fh9at8nz.js} +41 -37
  95. package/dist/dsh-adapter-wpze65d4.js +24 -0
  96. package/dist/{e2b-ez07znam.js → e2b-gjgdjp91.js} +12 -9
  97. package/dist/easter-egg-3d-3w5c2n4c.js +1057 -0
  98. package/dist/{execute-6e7qeyk4.js → execute-f50wg9nh.js} +203 -49
  99. package/dist/{google-generative-ai-k6n5nbpp.js → google-generative-ai-jxxpnegy.js} +2 -2
  100. package/dist/{google-vertex-44xxtcvp.js → google-vertex-x7q1angm.js} +5 -5
  101. package/dist/{handlers-kjdce1w5.js → handlers-w13787bb.js} +44 -40
  102. package/dist/{hook-r2t4bqfg.js → hook-46g1jrvx.js} +34 -20
  103. package/dist/{hook-czx13n12.js → hook-4tpts2ry.js} +25 -21
  104. package/dist/{http-3bbb19be.js → http-19pzbfrt.js} +1440 -283
  105. package/dist/{index-668me3f0.js → index-8fd4dm4h.js} +42 -38
  106. package/dist/{index-fg0dsp6c.js → index-dqmp15bq.js} +41 -37
  107. package/dist/{index-kkv84jq9.js → index-qb4q1y3e.js} +41 -37
  108. package/dist/index-s75wc4wd.js +33 -0
  109. package/dist/{index-zg7vp46x.js → index-scptvdxg.js} +64 -38
  110. package/dist/{keepalive-yra8dy57.js → keepalive-xa5ts9cd.js} +15 -12
  111. package/dist/{lead-va0pad2c.js → lead-qp4xkvjq.js} +59 -54
  112. package/dist/{maintenance-hqewtmyg.js → maintenance-rm5885hm.js} +17 -14
  113. package/dist/{mistral-conversations-pc3ntnxt.js → mistral-conversations-rw7fbt22.js} +4 -4
  114. package/dist/{node-a5e00qhp.js → node-8zkdq42h.js} +834 -833
  115. package/dist/node-f0ykebbv.js +2107 -0
  116. package/dist/node-wyamey5r.js +19 -0
  117. package/dist/{oauth-refresh-sweep-7rdt1m9n.js → oauth-refresh-sweep-1csdfebf.js} +14 -11
  118. package/dist/{onboard-j6ms6d0x.js → onboard-r6b78cs4.js} +10 -10
  119. package/dist/{openai-codex-responses-bbancrr0.js → openai-codex-responses-efvrgrq3.js} +4 -4
  120. package/dist/{openai-completions-jpaj5g2b.js → openai-completions-bbbrrz4z.js} +12 -8
  121. package/dist/{openai-responses-200k1wx4.js → openai-responses-9jjyrcm1.js} +15 -10
  122. package/dist/{opencode-adapter-89rabkw2.js → opencode-adapter-kb3g6pkf.js} +12 -9
  123. package/dist/{otel-impl-a792rjz0.js → otel-impl-0y9knpky.js} +6 -6
  124. package/dist/{pi-mono-adapter-g7qzvr3v.js → pi-mono-adapter-z6s1bme2.js} +128 -37
  125. package/dist/{pricing-refresh-wx0tp7cb.js → pricing-refresh-mth26tgp.js} +15 -12
  126. package/dist/{rbac-roles-8tzawacv.js → rbac-roles-kwntb23q.js} +17 -12
  127. package/dist/rbac-roles-vpk4ebm8.js +45 -0
  128. package/dist/{registry-v5wytg0s.js → registry-km6t1jd2.js} +1 -1
  129. package/dist/{render-v2-mm7zswb8.js → render-v2-hcm7h00y.js} +17 -14
  130. package/dist/{runtime-zyssgse0.js → runtime-vfjsfsc5.js} +5 -4
  131. package/dist/{setup-8y70ys6t.js → setup-hbyzd65h.js} +2 -2
  132. package/dist/{virtual-modules-6nmk7h3n.js → virtual-modules-9bv7ry91.js} +9 -7
  133. package/dist/{work-objects-fg6xkb0n.js → work-objects-m09sxnhe.js} +44 -40
  134. package/dist/{worker-wmwhxsph.js → worker-0h35rvk4.js} +59 -54
  135. package/dist/{x-n3e0v3xa.js → x-f1gt1pz3.js} +2 -2
  136. package/openapi.json +699 -26
  137. package/package.json +19 -11
  138. package/src/azure-devops/api.ts +121 -0
  139. package/src/azure-devops/auth.ts +78 -0
  140. package/src/azure-devops/handlers.ts +413 -0
  141. package/src/azure-devops/index.ts +27 -0
  142. package/src/azure-devops/templates.ts +108 -0
  143. package/src/azure-devops/types.ts +90 -0
  144. package/src/be/api-drain.ts +184 -0
  145. package/src/be/db/tasks/read.ts +32 -7
  146. package/src/be/db/tasks/write.ts +21 -4
  147. package/src/be/db-client.ts +11 -2
  148. package/src/be/db-retention.ts +95 -32
  149. package/src/be/db.ts +44 -19
  150. package/src/be/memory/constants.ts +16 -0
  151. package/src/be/memory/graph-expansion.ts +8 -1
  152. package/src/be/memory/index-content.ts +20 -1
  153. package/src/be/memory/key-guard.ts +93 -0
  154. package/src/be/memory/key-paths.ts +103 -0
  155. package/src/be/memory/link-resolver.ts +29 -3
  156. package/src/be/memory/providers/sqlite-store.ts +152 -45
  157. package/src/be/memory/raters/llm-summarizer.ts +10 -4
  158. package/src/be/memory/raters/llm.ts +15 -5
  159. package/src/be/memory/raters/store.ts +6 -3
  160. package/src/be/memory/raters/types.ts +11 -0
  161. package/src/be/memory/reranker.ts +38 -7
  162. package/src/be/memory/types.ts +12 -1
  163. package/src/be/migrations/190_memory_rating_model.sql +7 -0
  164. package/src/be/migrations/191_context_versions_previous_index.sql +8 -0
  165. package/src/be/migrations/192_favorites_agent_fs_path.sql +36 -0
  166. package/src/be/onboarding.ts +7 -1
  167. package/src/be/pricing-normalize.ts +4 -2
  168. package/src/be/scripts/typecheck.ts +4 -3
  169. package/src/be/seed-pricing.ts +16 -0
  170. package/src/be/seed-prompt-templates.ts +1 -0
  171. package/src/be/swarm-config-guard.ts +46 -17
  172. package/src/be/task-citations.ts +11 -5
  173. package/src/be/users.ts +3 -0
  174. package/src/cli.tsx +3 -2
  175. package/src/comb/agent-fs.ts +39 -0
  176. package/src/comb/config.ts +37 -0
  177. package/src/comb/markers.ts +37 -0
  178. package/src/comb/review-batch.ts +486 -0
  179. package/src/comb/templates.ts +88 -0
  180. package/src/commands/claude-managed-setup.ts +33 -31
  181. package/src/commands/context-preamble.ts +4 -1
  182. package/src/commands/hook.ts +2 -1
  183. package/src/commands/provider-credentials.ts +28 -15
  184. package/src/commands/runner.ts +458 -110
  185. package/src/commands/templates.ts +10 -0
  186. package/src/e2b/env.ts +2 -0
  187. package/src/extensions/catalog.generated.json +17 -0
  188. package/src/extensions/contract-types.generated.ts +1 -1
  189. package/src/fs/agent-fs-provider.ts +106 -2
  190. package/src/github/handlers.ts +10 -74
  191. package/src/github/reactions.ts +119 -138
  192. package/src/github/task-reactions.ts +34 -11
  193. package/src/heartbeat/heartbeat.ts +4 -0
  194. package/src/hooks/codex-hook.ts +25 -1
  195. package/src/hooks/hook.ts +14 -1
  196. package/src/hooks/pr-body-guard.ts +983 -0
  197. package/src/http/agents.ts +1 -1
  198. package/src/http/all-routes.ts +1 -0
  199. package/src/http/assets.ts +5 -17
  200. package/src/http/comb.ts +131 -0
  201. package/src/http/core.ts +14 -1
  202. package/src/http/extensions.ts +51 -27
  203. package/src/http/fs.ts +9 -17
  204. package/src/http/index.ts +27 -9
  205. package/src/http/mcp-user.ts +8 -13
  206. package/src/http/mcp.ts +19 -12
  207. package/src/http/memory.ts +80 -14
  208. package/src/http/onboarding.ts +21 -2
  209. package/src/http/poll.ts +30 -3
  210. package/src/http/realtime.ts +62 -0
  211. package/src/http/request-principal.ts +22 -0
  212. package/src/http/session-data.ts +6 -4
  213. package/src/http/stats.ts +1 -0
  214. package/src/http/status.ts +34 -2
  215. package/src/http/tasks.ts +17 -3
  216. package/src/http/users.ts +1 -1
  217. package/src/http/webhooks.ts +120 -2
  218. package/src/kv-reserved-namespaces.ts +10 -5
  219. package/src/providers/claude-adapter.ts +84 -16
  220. package/src/providers/claude-managed-adapter.ts +29 -2
  221. package/src/providers/codex-adapter.ts +1 -1
  222. package/src/providers/codex-skill-resolver.ts +6 -0
  223. package/src/providers/dsh-adapter.ts +204 -7
  224. package/src/providers/opencode-adapter.ts +24 -3
  225. package/src/providers/pi-mono-adapter.ts +154 -5
  226. package/src/providers/pi-mono-extension.ts +1 -1
  227. package/src/providers/pricing-sources.md +5 -1
  228. package/src/providers/reasoning-effort.ts +10 -2
  229. package/src/providers/types.ts +1 -1
  230. package/src/rbac/legacy-policy.ts +3 -0
  231. package/src/rbac/permissions.ts +14 -0
  232. package/src/realtime/auth.ts +63 -1
  233. package/src/realtime/tickets.ts +52 -0
  234. package/src/realtime/transport.ts +51 -22
  235. package/src/scripts-runtime/types/stdlib.d.ts +13 -5
  236. package/src/scripts-runtime/types/swarm-extension.d.ts +7 -3
  237. package/src/scripts-runtime/types/swarm-sdk.d.ts +13 -5
  238. package/src/tasks/context-key.ts +38 -1
  239. package/src/telemetry-context.ts +175 -0
  240. package/src/telemetry-contract/EVENTS.md +81 -0
  241. package/src/telemetry-contract/SOURCE.json +9 -0
  242. package/src/telemetry-contract/catalog.json +1335 -0
  243. package/src/telemetry-contract/index.ts +60 -0
  244. package/src/telemetry-contract/types.gen.ts +1971 -0
  245. package/src/telemetry-identity.ts +129 -0
  246. package/src/telemetry-snapshot.ts +211 -0
  247. package/src/telemetry-trigger.ts +125 -0
  248. package/src/telemetry-types.typetest.ts +40 -0
  249. package/src/telemetry.ts +271 -67
  250. package/src/tests/api-drain-e2e.test.ts +249 -0
  251. package/src/tests/api-drain-worker-e2e.test.ts +216 -0
  252. package/src/tests/api-drain.test.ts +351 -0
  253. package/src/tests/azure-devops-auth.test.ts +100 -0
  254. package/src/tests/azure-devops-handlers.test.ts +324 -0
  255. package/src/tests/azure-devops-webhook-malformed.test.ts +96 -0
  256. package/src/tests/claude-default-route.test.ts +260 -0
  257. package/src/tests/claude-managed-adapter.test.ts +47 -0
  258. package/src/tests/claude-managed-setup.test.ts +48 -0
  259. package/src/tests/claude-prompt-body-once.test.ts +117 -0
  260. package/src/tests/claude-routes-e2e.test.ts +316 -0
  261. package/src/tests/comb-config-guard.test.ts +38 -0
  262. package/src/tests/comb-links.test.ts +162 -0
  263. package/src/tests/comb-markers.test.ts +68 -0
  264. package/src/tests/comb-review-batch.test.ts +770 -0
  265. package/src/tests/comb-status.test.ts +152 -0
  266. package/src/tests/context-versions-retention.test.ts +314 -0
  267. package/src/tests/core-auth.test.ts +7 -0
  268. package/src/tests/db-retention.test.ts +14 -14
  269. package/src/tests/db-task-read-contract.test.ts +3 -0
  270. package/src/tests/db-task-write-contract.test.ts +3 -0
  271. package/src/tests/docs-index-footprint.test.js +3 -3
  272. package/src/tests/dsh-adapter.test.ts +134 -2
  273. package/src/tests/dsh-usage.test.ts +153 -0
  274. package/src/tests/extensions-catalog.test.ts +1 -0
  275. package/src/tests/extensions-example-deploy-awareness.test.ts +301 -0
  276. package/src/tests/extensions-http.test.ts +137 -10
  277. package/src/tests/extensions-mcp-tools.test.ts +28 -0
  278. package/src/tests/favorites-agent-fs-path.test.ts +226 -0
  279. package/src/tests/fetch-resolved-env.test.ts +24 -0
  280. package/src/tests/fixtures/azure-devops/pull-request-commented.json +129 -0
  281. package/src/tests/fixtures/azure-devops/pull-request-created.json +88 -0
  282. package/src/tests/fixtures/fake-claude-routes.ts +229 -0
  283. package/src/tests/github-handlers-reactions.test.ts +486 -0
  284. package/src/tests/github-reactions.test.ts +280 -0
  285. package/src/tests/harness-cli-version.test.ts +62 -0
  286. package/src/tests/http-api-integration.test.ts +21 -0
  287. package/src/tests/http-task-write-ownership.test.ts +24 -1
  288. package/src/tests/internal-ai/complete-structured.test.ts +94 -0
  289. package/src/tests/internal-ai/credentials.test.ts +22 -0
  290. package/src/tests/internal-ai/models.test.ts +36 -2
  291. package/src/tests/internal-ai/schema-parity.test.ts +25 -1
  292. package/src/tests/internal-ai/summarize-session.test.ts +23 -7
  293. package/src/tests/mcp-user-route.test.ts +133 -0
  294. package/src/tests/memory-key-paths.test.ts +1055 -0
  295. package/src/tests/memory-link-resolver.test.ts +34 -0
  296. package/src/tests/memory-rate-endpoint.test.ts +66 -0
  297. package/src/tests/memory-rater-llm-summarizer.test.ts +2 -1
  298. package/src/tests/memory-rater-llm.test.ts +73 -0
  299. package/src/tests/memory-rater-store.test.ts +31 -0
  300. package/src/tests/memory-reranker.test.ts +40 -0
  301. package/src/tests/onboarding.test.ts +108 -0
  302. package/src/tests/opencode-adapter.test.ts +57 -0
  303. package/src/tests/opencode-plugin.test.ts +4 -0
  304. package/src/tests/pi-codemode.test.ts +82 -4
  305. package/src/tests/pi-mono-adapter.test.ts +265 -2
  306. package/src/tests/pr-body-leaks.test.ts +789 -0
  307. package/src/tests/preload.ts +14 -0
  308. package/src/tests/provider-registration.test.ts +0 -2
  309. package/src/tests/providers/pi-cost.test.ts +190 -4
  310. package/src/tests/rbac-engine.test.ts +25 -1
  311. package/src/tests/realtime-room-auth.test.ts +104 -1
  312. package/src/tests/realtime-tickets.test.ts +74 -0
  313. package/src/tests/realtime-transport.test.ts +131 -4
  314. package/src/tests/runner-api-drain.test.ts +301 -0
  315. package/src/tests/runner-fallback-output.test.ts +61 -0
  316. package/src/tests/runner-fenced-json-output.test.ts +178 -0
  317. package/src/tests/runner-slot-reconcile.test.ts +199 -0
  318. package/src/tests/script-connections.test.ts +6 -0
  319. package/src/tests/send-task-requested-by.test.ts +133 -15
  320. package/src/tests/session-costs-recompute-all-providers.test.ts +23 -0
  321. package/src/tests/task-lifecycle-telemetry.test.ts +8 -3
  322. package/src/tests/task-reactions.test.ts +29 -6
  323. package/src/tests/telemetry-context.test.ts +314 -0
  324. package/src/tests/telemetry-init.test.ts +51 -19
  325. package/src/tests/telemetry-snapshot.test.ts +229 -0
  326. package/src/tests/telemetry-trigger.test.ts +200 -0
  327. package/src/tests/template-registry-helpers.ts +1 -0
  328. package/src/tests/vcs-azure-devops.test.ts +73 -0
  329. package/src/tests/webhooks-task-blocked.test.ts +23 -0
  330. package/src/tests/workflow-agent-task-retry.test.ts +363 -0
  331. package/src/tests/workflow-definition-telemetry.test.ts +4 -4
  332. package/src/tests/workflow-llm.test.ts +14 -0
  333. package/src/tools/context-diff.ts +20 -0
  334. package/src/tools/extension-install.ts +27 -16
  335. package/src/tools/memory-edit.ts +47 -3
  336. package/src/tools/memory-search.ts +13 -1
  337. package/src/tools/memory-store.ts +55 -3
  338. package/src/tools/poll-task.ts +20 -1
  339. package/src/tools/send-task.ts +9 -1
  340. package/src/tools/task-action.ts +11 -0
  341. package/src/types.ts +45 -8
  342. package/src/utils/api-drain.ts +24 -0
  343. package/src/utils/constants.ts +57 -16
  344. package/src/utils/credentials.test.ts +31 -1
  345. package/src/utils/credentials.ts +20 -9
  346. package/src/utils/dsh-usage.ts +53 -0
  347. package/src/utils/harness-cli-version.ts +6 -4
  348. package/src/utils/internal-ai/complete-structured.ts +26 -3
  349. package/src/utils/internal-ai/credentials.ts +23 -9
  350. package/src/utils/internal-ai/index.ts +8 -1
  351. package/src/utils/internal-ai/models.ts +34 -8
  352. package/src/utils/internal-ai/summarize-session.ts +22 -8
  353. package/src/utils/pr-body-leaks.ts +172 -0
  354. package/src/utils/secret-scrubber.ts +8 -0
  355. package/src/utils/task-attachment-links.ts +14 -8
  356. package/src/vcs/azure-devops.ts +80 -0
  357. package/src/vcs/index.ts +5 -1
  358. package/src/vcs/types.ts +2 -2
  359. package/src/workflows/recovery.ts +26 -1
  360. package/src/workflows/resume.ts +31 -4
  361. package/src/workflows/task-step-routing.ts +75 -2
  362. package/templates/community/open-prompt-showreel/PLAYBOOK.md +336 -0
  363. package/templates/community/open-prompt-showreel/README.md +33 -0
  364. package/templates/community/open-prompt-showreel/example/tla-races/facts.ts +145 -0
  365. package/templates/community/open-prompt-showreel/example/tla-races/facts.v3.json +140 -0
  366. package/templates/community/open-prompt-showreel/example/tla-races/music.mist-city.json +8 -0
  367. package/templates/community/open-prompt-showreel/example/tla-races/reel.html +805 -0
  368. package/templates/community/open-prompt-showreel/example/tla-races/smoke.sh +48 -0
  369. package/templates/community/open-prompt-showreel/lead-prompt.md +89 -0
  370. package/templates/community/open-prompt-showreel/setup.sh +167 -0
  371. package/templates/community/open-prompt-showreel/skills/motion-design-replication/SKILL.md +85 -0
  372. package/templates/community/open-prompt-showreel/skills/motion-design-video-analysis/SKILL.md +115 -0
  373. package/templates/community/open-prompt-showreel/skills/open-prompt-showreel/SKILL.md +147 -0
  374. package/templates/community/open-prompt-showreel/skills/video-generation/SKILL.md +195 -0
  375. package/templates/community/open-prompt-showreel/tools/fetch-music.sh +65 -0
  376. package/templates/community/open-prompt-showreel/tools/music-analyze.py +69 -0
  377. package/templates/community/open-prompt-showreel/tools/music-current.sh +34 -0
  378. package/templates/community/open-prompt-showreel/tools/music-cut.sh +36 -0
  379. package/templates/community/open-prompt-showreel/tools/music-refine.py +39 -0
  380. package/templates/community/open-prompt-showreel/tools/render.mjs +157 -0
  381. package/templates/community/open-prompt-showreel/tools/sheet.sh +44 -0
  382. package/templates/community/open-prompt-showreel/tools/web-compress.sh +17 -0
  383. package/templates/community/open-prompt-showreel/tools/x-reencode.sh +21 -0
  384. package/templates/extensions/README.md +1 -0
  385. package/templates/extensions/deploy-awareness/README.md +28 -0
  386. package/templates/extensions/deploy-awareness/hooks.ts +152 -0
  387. package/templates/extensions/deploy-awareness/manifest.json +8 -0
  388. package/templates/skills/memory/config.json +2 -2
  389. package/templates/skills/memory/content.md +59 -5
  390. package/templates/skills/swarm-extensions/config.json +1 -1
  391. package/templates/skills/swarm-extensions/content.md +28 -5
  392. package/tsconfig.json +3 -0
  393. package/dist/boot-seeds-gsetbs5y.js +0 -28
  394. package/dist/cli-j490egb5.js +0 -5632
  395. package/dist/cli-tjf4cn8z.js +0 -9119
  396. package/dist/cli-tmqt7dpj.js +0 -572
  397. package/dist/dsh-adapter-mpnzgztj.js +0 -19
  398. package/dist/index-7aj368tw.js +0 -30
@@ -244,6 +244,53 @@ describe("ClaudeManagedAdapter (Phase 3) — session lifecycle", () => {
244
244
  expect(a[1]?.text).not.toBe(b[1]?.text);
245
245
  });
246
246
 
247
+ test("agent.message with a redacted block keeps a visible placeholder instead of dropping it", async () => {
248
+ const events: Array<Record<string, unknown>> = [
249
+ {
250
+ type: "agent.message",
251
+ id: "evt1",
252
+ processed_at: "2026-01-01T00:00:01Z",
253
+ content: [
254
+ { type: "text", text: "before " },
255
+ { type: "redacted" },
256
+ { type: "text", text: " after" },
257
+ ],
258
+ },
259
+ {
260
+ type: "agent.message",
261
+ id: "evt2",
262
+ processed_at: "2026-01-01T00:00:02Z",
263
+ content: [{ type: "redacted" }],
264
+ },
265
+ {
266
+ type: "session.status_idle",
267
+ id: "evt3",
268
+ processed_at: "2026-01-01T00:00:03Z",
269
+ stop_reason: { type: "end_turn" },
270
+ },
271
+ ];
272
+ const spy = makeFakeClient({
273
+ streamEvents: async function* () {
274
+ for (const e of events) yield e;
275
+ },
276
+ });
277
+ const adapter = new ClaudeManagedAdapter({ client: spy.client });
278
+ const session = await adapter.createSession(
279
+ tConfig({ logFile: join(tmpLogDir, "redacted.log") }),
280
+ );
281
+ const emitted: ProviderEvent[] = [];
282
+ session.onEvent((e) => emitted.push(e));
283
+ await session.waitForCompletion();
284
+
285
+ const messages = emitted.flatMap((e) =>
286
+ e.type === "message" && e.role === "assistant" ? [e.content] : [],
287
+ );
288
+ expect(messages).toEqual([
289
+ "before [content redacted by Anthropic model policy] after",
290
+ "[content redacted by Anthropic model policy]",
291
+ ]);
292
+ });
293
+
247
294
  test("happy path: agent.message → message ProviderEvent, span.model_request_end → cost + context_usage, status_idle → result", async () => {
248
295
  const events: Array<Record<string, unknown>> = [
249
296
  { type: "session.status_running", id: "evt1", processed_at: "2026-01-01T00:00:00Z" },
@@ -193,6 +193,54 @@ describe("runClaudeManagedSetupFlow — happy path", () => {
193
193
  });
194
194
  });
195
195
 
196
+ describe("runClaudeManagedSetupFlow — skill dedupe by display_name", () => {
197
+ function skill(id: string, displayName: string, updatedAt: string) {
198
+ return {
199
+ id,
200
+ display_name: displayName,
201
+ updated_at: updatedAt,
202
+ created_at: updatedAt,
203
+ latest_version_id: `skver_${id}`,
204
+ source: { type: "custom" },
205
+ type: "skill",
206
+ };
207
+ }
208
+
209
+ test("reuses existing skills by display_name and creates only the missing ones", async () => {
210
+ const skillsList = mock(async function* () {
211
+ yield skill("skill_old_worker", "start-worker", "2026-09-01T00:00:00Z");
212
+ // display_name is not unique: the newest duplicate wins.
213
+ yield skill("skill_new_worker", "start-worker", "2026-09-20T00:00:00Z");
214
+ yield skill("skill_stale_worker", "start-worker", "2026-08-01T00:00:00Z");
215
+ });
216
+ const skillsCreate = mock(async (params: { display_name?: string }) => ({
217
+ id: `skill_created_${params.display_name}`,
218
+ }));
219
+ const { client } = makeMockClient();
220
+ client.beta.skills = { create: skillsCreate, list: skillsList } as never;
221
+
222
+ const result = await runClaudeManagedSetupFlow(baseConfig, {
223
+ client: client as any,
224
+ fetchConfig: mock(async () => null),
225
+ upsert: mock(async () => undefined),
226
+ loadSkills: mock(async () => fakeSkillFiles),
227
+ loadSeededSkills: mock(async () => []),
228
+ log: mock(() => undefined),
229
+ });
230
+
231
+ expect(result.skillIds).toEqual(["skill_new_worker", "skill_created_create-pr"]);
232
+ expect(skillsList).toHaveBeenCalledTimes(1);
233
+ // GA shape only: sending the old beta header would make the API answer
234
+ // with `display_title`, and the name index would silently be empty.
235
+ expect(skillsList.mock.calls[0]).toEqual([{ source: "custom" }]);
236
+ expect(skillsCreate).toHaveBeenCalledTimes(1);
237
+ const createArgs = skillsCreate.mock.calls[0]?.[0] as Record<string, unknown>;
238
+ expect(createArgs.display_name).toBe("create-pr");
239
+ expect(createArgs).not.toHaveProperty("display_title");
240
+ expect(createArgs).not.toHaveProperty("betas");
241
+ });
242
+ });
243
+
196
244
  describe("runClaudeManagedSetupFlow — idempotent re-run", () => {
197
245
  test("short-circuits with already-configured when managed_agent_id exists in swarm_config", async () => {
198
246
  const { client, environmentsCreate, agentsCreate } = makeMockClient();
@@ -0,0 +1,117 @@
1
+ /**
2
+ * The claude harness must deliver the task body once in a task's first
3
+ * message. Claude Code's native `/<skill> <args>` expansion puts the args in
4
+ * `<command-args>` and again after `ARGUMENTS:`, so the adapter inlines the
5
+ * runner's skill command instead (`resolveClaudePrompt`).
6
+ */
7
+
8
+ import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
9
+ import { cpSync, mkdirSync, rmSync } from "node:fs";
10
+ import { tmpdir } from "node:os";
11
+ import { join } from "node:path";
12
+ import { buildPromptForTrigger, buildResumePrompt } from "../commands/runner";
13
+ import { ClaudeAdapter, resolveClaudePrompt } from "../providers/claude-adapter";
14
+
15
+ const BODY_MARKER = "BODY-MARKER-4c1e";
16
+ const TASK_ID = "00000000-0000-4000-8000-000000000001";
17
+ const BODY = `${BODY_MARKER} Fix the flaky export.\n\nMulti-line body with "quotes" and $ARGUMENTS text.`;
18
+
19
+ let home: string;
20
+ const fmt = (cmd: string) => new ClaudeAdapter().formatCommand(cmd);
21
+
22
+ function countOccurrences(haystack: string, needle: string): number {
23
+ return haystack.split(needle).length - 1;
24
+ }
25
+
26
+ beforeAll(() => {
27
+ home = join(tmpdir(), `claude-prompt-body-once-${crypto.randomUUID()}`);
28
+ for (const skill of ["work-on-task", "review-offered-task"]) {
29
+ const dir = join(home, ".claude", "skills", skill);
30
+ mkdirSync(dir, { recursive: true });
31
+ cpSync(
32
+ join(import.meta.dir, "../../templates/skills", skill, "SKILL.md"),
33
+ join(dir, "SKILL.md"),
34
+ );
35
+ }
36
+ });
37
+
38
+ afterAll(() => {
39
+ rmSync(home, { recursive: true, force: true });
40
+ });
41
+
42
+ beforeEach(async () => {
43
+ // Other test files clear the template registry; re-register the defaults.
44
+ await import(`../commands/templates?t=${Date.now()}`);
45
+ });
46
+
47
+ describe("claude first-message prompt", () => {
48
+ const cases: Array<{ name: string; skill: string; build: () => Promise<string> }> = [
49
+ {
50
+ name: "task_assigned (new tasks, follow-ups, heartbeat checklist)",
51
+ skill: "work-on-task",
52
+ build: () =>
53
+ buildPromptForTrigger(
54
+ { type: "task_assigned", taskId: TASK_ID, task: { id: TASK_ID, task: BODY } },
55
+ "",
56
+ fmt,
57
+ ),
58
+ },
59
+ {
60
+ name: "task_offered",
61
+ skill: "review-offered-task",
62
+ build: () =>
63
+ buildPromptForTrigger(
64
+ { type: "task_offered", taskId: TASK_ID, task: { id: TASK_ID, task: BODY } },
65
+ "",
66
+ fmt,
67
+ ),
68
+ },
69
+ {
70
+ name: "resumed task with progress",
71
+ skill: "work-on-task",
72
+ build: () => buildResumePrompt({ id: TASK_ID, task: BODY, progress: "Read the file" }, fmt),
73
+ },
74
+ {
75
+ name: "resumed task without progress",
76
+ skill: "work-on-task",
77
+ build: () => buildResumePrompt({ id: TASK_ID, task: BODY }, fmt),
78
+ },
79
+ ];
80
+
81
+ for (const { name, skill, build } of cases) {
82
+ test(`${name}: skill inlined, body sent once`, async () => {
83
+ const runnerPrompt = await build();
84
+ // The runner still emits a slash command carrying the body as its args.
85
+ expect(runnerPrompt.startsWith(`/${skill} ${TASK_ID}`)).toBe(true);
86
+
87
+ const prompt = await resolveClaudePrompt(runnerPrompt, home);
88
+
89
+ // No leading slash, so Claude Code does not re-expand (and duplicate) it.
90
+ expect(prompt.startsWith("/")).toBe(false);
91
+ // No leading dash either: `claude -p <prompt>` would parse it as an option.
92
+ expect(prompt.startsWith("-")).toBe(false);
93
+ expect(prompt.startsWith("# ")).toBe(true);
94
+ expect(prompt).not.toContain(`name: ${skill}`);
95
+ expect(prompt).toContain(`User request: ${TASK_ID}`);
96
+ expect(prompt).toContain(TASK_ID);
97
+ expect(countOccurrences(prompt, BODY_MARKER)).toBe(1);
98
+ });
99
+ }
100
+
101
+ test("commands without a SKILL.md pass through for native expansion", async () => {
102
+ const runnerPrompt = `/desplega:research ${TASK_ID}\n\n${BODY}`;
103
+ expect(await resolveClaudePrompt(runnerPrompt, home)).toBe(runnerPrompt);
104
+ });
105
+
106
+ test("a skill that would start the prompt with a dash keeps the native form", async () => {
107
+ const dir = join(home, ".claude", "skills", "dash-skill");
108
+ mkdirSync(dir, { recursive: true });
109
+ await Bun.write(join(dir, "SKILL.md"), "--flag-looking first line\n");
110
+ const runnerPrompt = `/dash-skill ${TASK_ID}\n\n${BODY}`;
111
+ expect(await resolveClaudePrompt(runnerPrompt, home)).toBe(runnerPrompt);
112
+ });
113
+
114
+ test("prompts without a slash command are unchanged", async () => {
115
+ expect(await resolveClaudePrompt(BODY, home)).toBe(BODY);
116
+ });
117
+ });
@@ -0,0 +1,316 @@
1
+ /**
2
+ * Issue #1800 end to end: the real Claude Code CLI completes a prompt on each
3
+ * claude default route (LiteLLM-style gateway, Microsoft Foundry, Amazon
4
+ * Bedrock, Google Vertex AI) against a fake endpoint, through the worker's
5
+ * credential gate and the claude adapter's spawn path.
6
+ *
7
+ * The CLI is the binary @anthropic-ai/claude-agent-sdk ships for this platform
8
+ * (the version the SDK pins), or `CLAUDE_ROUTES_E2E_BINARY`. Without either the
9
+ * suite skips. `CLAUDE_ROUTES_E2E_LOG=1` prints each fake server's requests,
10
+ * auth redacted.
11
+ */
12
+ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
13
+ import { existsSync, mkdtempSync, rmSync } from "node:fs";
14
+ import { createRequire } from "node:module";
15
+ import { tmpdir } from "node:os";
16
+ import { dirname, join } from "node:path";
17
+ import { deriveDefaultRoute } from "@desplega/model-routing";
18
+ import { closeDb, createAgent, getAgentById, initDb, updateAgentCredentialState } from "../be/db";
19
+ import { awaitCredentials } from "../commands/credential-wait";
20
+ import { buildCredStatusReport } from "../commands/provider-credentials";
21
+ import { ClaudeAdapter } from "../providers/claude-adapter";
22
+ import type { CredStatus } from "../providers/types";
23
+ import {
24
+ type CapturedRequest,
25
+ type FakeRouteKind,
26
+ redactedRequestLine,
27
+ startFakeRouteServer,
28
+ } from "./fixtures/fake-claude-routes";
29
+ import { runChild } from "./test-proc";
30
+
31
+ const OAUTH_TOKEN = "sk-ant-oat01-route-e2e-must-not-leak";
32
+ const REPLY = "ROUTE-E2E-FAKE-REPLY";
33
+ const SPAWN_TIMEOUT_MS = 90_000;
34
+
35
+ function sdkClaudeBinary(): string | null {
36
+ const override = process.env.CLAUDE_ROUTES_E2E_BINARY;
37
+ if (override) return existsSync(override) ? override : null;
38
+ const require = createRequire(import.meta.url);
39
+ const platform = `${process.platform}-${process.arch}`;
40
+ for (const pkg of [platform, `${platform}-musl`]) {
41
+ try {
42
+ const dir = dirname(require.resolve(`@anthropic-ai/claude-agent-sdk-${pkg}/package.json`));
43
+ const binary = join(dir, process.platform === "win32" ? "claude.exe" : "claude");
44
+ if (existsSync(binary)) return binary;
45
+ } catch {
46
+ // Optional dependency not installed for this platform.
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+
52
+ const CLAUDE_BINARY = sdkClaudeBinary();
53
+
54
+ interface RouteCase {
55
+ kind: FakeRouteKind;
56
+ provider: string;
57
+ env(baseUrl: string): Record<string, string>;
58
+ /** The streamed turn that carries the prompt. */
59
+ turnPath: RegExp;
60
+ /** Credential header the CLI must send, or null for none (skip-auth). */
61
+ auth: { header: string; value: string } | null;
62
+ /** True when the route has a free key check the credential report runs. */
63
+ liveChecked: boolean;
64
+ }
65
+
66
+ const ROUTES: RouteCase[] = [
67
+ {
68
+ kind: "gateway",
69
+ provider: "anthropic-gateway",
70
+ env: (baseUrl) => ({ ANTHROPIC_BASE_URL: baseUrl, ANTHROPIC_AUTH_TOKEN: "sk-gateway-e2e" }),
71
+ turnPath: /^\/v1\/messages(\?|$)/,
72
+ auth: { header: "authorization", value: "Bearer sk-gateway-e2e" },
73
+ liveChecked: true,
74
+ },
75
+ {
76
+ kind: "foundry",
77
+ provider: "foundry",
78
+ env: (baseUrl) => ({
79
+ CLAUDE_CODE_USE_FOUNDRY: "1",
80
+ ANTHROPIC_FOUNDRY_BASE_URL: `${baseUrl}/anthropic`,
81
+ ANTHROPIC_FOUNDRY_API_KEY: "foundry-e2e-key",
82
+ }),
83
+ turnPath: /^\/anthropic\/v1\/messages(\?|$)/,
84
+ auth: { header: "x-api-key", value: "foundry-e2e-key" },
85
+ liveChecked: false,
86
+ },
87
+ {
88
+ kind: "bedrock",
89
+ provider: "bedrock",
90
+ env: (baseUrl) => ({
91
+ CLAUDE_CODE_USE_BEDROCK: "1",
92
+ AWS_REGION: "us-east-1",
93
+ ANTHROPIC_BEDROCK_BASE_URL: baseUrl,
94
+ AWS_BEARER_TOKEN_BEDROCK: "bedrock-e2e-token",
95
+ }),
96
+ turnPath: /^\/model\/[^/]+\/invoke-with-response-stream$/,
97
+ auth: { header: "authorization", value: "Bearer bedrock-e2e-token" },
98
+ liveChecked: false,
99
+ },
100
+ {
101
+ kind: "vertex",
102
+ provider: "vertex",
103
+ env: (baseUrl) => ({
104
+ CLAUDE_CODE_USE_VERTEX: "1",
105
+ CLOUD_ML_REGION: "us-east5",
106
+ ANTHROPIC_VERTEX_PROJECT_ID: "route-e2e",
107
+ ANTHROPIC_VERTEX_BASE_URL: `${baseUrl}/v1`,
108
+ CLAUDE_CODE_SKIP_VERTEX_AUTH: "1",
109
+ }),
110
+ turnPath:
111
+ /^\/v1\/projects\/route-e2e\/locations\/us-east5\/publishers\/anthropic\/models\/[^/]+:streamRawPredict$/,
112
+ auth: null,
113
+ liveChecked: false,
114
+ },
115
+ ];
116
+
117
+ const tempDirs: string[] = [];
118
+ function tempDir(prefix: string): string {
119
+ const dir = mkdtempSync(join(tmpdir(), prefix));
120
+ tempDirs.push(dir);
121
+ return dir;
122
+ }
123
+
124
+ /**
125
+ * The env an operator gives a worker on this route, plus the two things a
126
+ * fleet carries over from subscription days: a Claude OAuth token and
127
+ * claude-bridge switched on. Isolated HOME so no host settings or hooks load.
128
+ */
129
+ function operatorEnv(route: Record<string, string>): Record<string, string> {
130
+ return {
131
+ PATH: process.env.PATH ?? "",
132
+ HOME: tempDir("claude-route-home-"),
133
+ CLAUDE_BINARY: CLAUDE_BINARY ?? "claude",
134
+ CLAUDE_CODE_OAUTH_TOKEN: OAUTH_TOKEN,
135
+ SWARM_USE_CLAUDE_BRIDGE: "true",
136
+ CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
137
+ ...route,
138
+ };
139
+ }
140
+
141
+ class GateParked extends Error {}
142
+
143
+ /** Runs the worker's boot gate once. Returns the final status, or the first parked one. */
144
+ async function runGate(env: Record<string, string>): Promise<CredStatus> {
145
+ const ticks: CredStatus[] = [];
146
+ try {
147
+ return await awaitCredentials({
148
+ provider: "claude",
149
+ initialEnv: env,
150
+ refreshEnv: async () => ({}),
151
+ onTick: (status) => ticks.push(status),
152
+ sleep: async () => {
153
+ throw new GateParked();
154
+ },
155
+ log: () => {},
156
+ });
157
+ } catch (err) {
158
+ if (!(err instanceof GateParked) || !ticks[0]) throw err;
159
+ return ticks[0];
160
+ }
161
+ }
162
+
163
+ /** The runner's report, as the API applies it to the agent row. */
164
+ async function reportedAgentStatus(env: Record<string, string>) {
165
+ const report = await buildCredStatusReport("claude", env, {}, "boot");
166
+ const agent = await createAgent({
167
+ name: `route-e2e-${crypto.randomUUID().slice(0, 8)}`,
168
+ isLead: false,
169
+ status: "idle",
170
+ capabilities: [],
171
+ });
172
+ await updateAgentCredentialState(agent.id, report.ready, report.missing);
173
+ return { report, agent: await getAgentById(agent.id) };
174
+ }
175
+
176
+ function assertNoOAuthToken(requests: CapturedRequest[]): void {
177
+ for (const req of requests) {
178
+ expect(Object.values(req.headers).some((value) => value.includes(OAUTH_TOKEN))).toBe(false);
179
+ expect(req.body.includes(OAUTH_TOKEN)).toBe(false);
180
+ }
181
+ }
182
+
183
+ function logRequests(label: string, requests: CapturedRequest[]): void {
184
+ if (!process.env.CLAUDE_ROUTES_E2E_LOG) return;
185
+ console.log(`[${label}] ${requests.length} request(s)`);
186
+ for (const req of requests) console.log(` ${redactedRequestLine(req)}`);
187
+ }
188
+
189
+ const TEST_DB_PATH = "./test-claude-routes-e2e.sqlite";
190
+
191
+ describe.skipIf(!CLAUDE_BINARY)("claude routes e2e (real CLI, fake endpoints)", () => {
192
+ beforeAll(() => {
193
+ rmSync(TEST_DB_PATH, { force: true });
194
+ initDb(TEST_DB_PATH);
195
+ });
196
+
197
+ afterAll(() => {
198
+ closeDb();
199
+ for (const path of [TEST_DB_PATH, `${TEST_DB_PATH}-wal`, `${TEST_DB_PATH}-shm`]) {
200
+ rmSync(path, { force: true });
201
+ }
202
+ for (const dir of tempDirs) rmSync(dir, { recursive: true, force: true });
203
+ });
204
+
205
+ for (const route of ROUTES) {
206
+ test(
207
+ `${route.kind}: gate passes and the CLI completes a prompt on the route`,
208
+ async () => {
209
+ const fake = startFakeRouteServer(route.kind, REPLY);
210
+ try {
211
+ const env = operatorEnv(route.env(fake.baseUrl));
212
+ expect(deriveDefaultRoute("claude", env)?.provider).toBe(route.provider);
213
+
214
+ const gate = await runGate(env);
215
+ expect(gate).toMatchObject({ ready: true, missing: [] });
216
+ const { report, agent } = await reportedAgentStatus(env);
217
+ expect(agent?.status).toBe("idle");
218
+ if (route.liveChecked) {
219
+ expect(report.liveTest).toMatchObject({ ok: true });
220
+ } else {
221
+ expect(report.liveTest).toBeNull();
222
+ }
223
+
224
+ const cwd = tempDir("claude-route-cwd-");
225
+ const session = await new ClaudeAdapter(async () => {}).createSession({
226
+ prompt: "Reply with the text the model gives you.",
227
+ systemPrompt: "",
228
+ model: "sonnet",
229
+ role: "worker",
230
+ agentId: crypto.randomUUID(),
231
+ taskId: crypto.randomUUID(),
232
+ apiUrl: "",
233
+ apiKey: "",
234
+ cwd,
235
+ logFile: join(cwd, "session.jsonl"),
236
+ env,
237
+ });
238
+ const result = await session.waitForCompletion();
239
+ logRequests(route.kind, fake.requests);
240
+
241
+ expect(result).toMatchObject({ isError: false, exitCode: 0 });
242
+ expect(result.output).toContain(REPLY);
243
+
244
+ const turn = fake.requests.find(
245
+ (req) => req.method === "POST" && route.turnPath.test(req.path),
246
+ );
247
+ expect(turn).toBeDefined();
248
+ if (route.auth) {
249
+ expect(turn?.headers[route.auth.header]).toBe(route.auth.value);
250
+ } else {
251
+ expect(turn?.headers.authorization).toBeUndefined();
252
+ expect(turn?.headers["x-api-key"]).toBeUndefined();
253
+ }
254
+ assertNoOAuthToken(fake.requests);
255
+ } finally {
256
+ fake.stop();
257
+ }
258
+ },
259
+ SPAWN_TIMEOUT_MS,
260
+ );
261
+ }
262
+
263
+ test("gateway with only CLAUDE_CODE_OAUTH_TOKEN parks and never calls the gateway", async () => {
264
+ const fake = startFakeRouteServer("gateway", REPLY);
265
+ try {
266
+ const env = operatorEnv({ ANTHROPIC_BASE_URL: fake.baseUrl });
267
+
268
+ const gate = await runGate(env);
269
+ expect(gate).toMatchObject({ ready: false, missing: ["ANTHROPIC_AUTH_TOKEN"] });
270
+ const { report, agent } = await reportedAgentStatus(env);
271
+ expect(report.liveTest).toBeNull();
272
+ expect(agent?.status).toBe("waiting_for_credentials");
273
+ expect(agent?.credentialMissing).toEqual(["ANTHROPIC_AUTH_TOKEN"]);
274
+
275
+ const cwd = tempDir("claude-route-cwd-");
276
+ await expect(
277
+ new ClaudeAdapter(async () => {}).createSession({
278
+ prompt: "Reply with the text the model gives you.",
279
+ systemPrompt: "",
280
+ model: "sonnet",
281
+ role: "worker",
282
+ agentId: crypto.randomUUID(),
283
+ taskId: crypto.randomUUID(),
284
+ apiUrl: "",
285
+ apiKey: "",
286
+ cwd,
287
+ logFile: join(cwd, "session.jsonl"),
288
+ env,
289
+ }),
290
+ ).rejects.toThrow("No Claude credentials found");
291
+ logRequests("gateway-oauth-only", fake.requests);
292
+ expect(fake.requests).toHaveLength(0);
293
+ } finally {
294
+ fake.stop();
295
+ }
296
+ });
297
+
298
+ // Control for the leak assertions above: the same env handed straight to the
299
+ // CLI, without the gate or the adapter, does send the OAuth token to the gateway.
300
+ test("control: the bare CLI sends CLAUDE_CODE_OAUTH_TOKEN to a gateway", async () => {
301
+ const fake = startFakeRouteServer("gateway", REPLY);
302
+ try {
303
+ const env = operatorEnv({ ANTHROPIC_BASE_URL: fake.baseUrl });
304
+ const result = await runChild(
305
+ [env.CLAUDE_BINARY, "-p", "hi", "--model", "sonnet", "--output-format", "json"],
306
+ { cwd: tempDir("claude-route-cwd-"), env },
307
+ );
308
+ logRequests("control-bare-cli", fake.requests);
309
+ expect(result.stdout).toContain(REPLY);
310
+ const turn = fake.requests.find((req) => req.method === "POST");
311
+ expect(turn?.headers.authorization).toBe(`Bearer ${OAUTH_TOKEN}`);
312
+ } finally {
313
+ fake.stop();
314
+ }
315
+ });
316
+ });
@@ -0,0 +1,38 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { validateConfigValue } from "../be/swarm-config-guard";
3
+
4
+ describe("Comb config keys", () => {
5
+ test("COMB_ENABLED accepts boolean literals only", () => {
6
+ for (const value of ["true", "false", "1", "0", " TRUE "]) {
7
+ expect(validateConfigValue("COMB_ENABLED", value)).toBeNull();
8
+ }
9
+ for (const value of ["yes", "on", ""]) {
10
+ expect(validateConfigValue("COMB_ENABLED", value)).toContain("Invalid COMB_ENABLED");
11
+ }
12
+ });
13
+
14
+ test("AGENT_FS_PUBLIC_URL accepts blank or an http(s) base URL", () => {
15
+ for (const value of ["", "http://localhost:7433", "https://agent-fs.example.com/base"]) {
16
+ expect(validateConfigValue("AGENT_FS_PUBLIC_URL", value)).toBeNull();
17
+ }
18
+ for (const value of [
19
+ "agent-fs.example.com",
20
+ "not a url",
21
+ "ftp://agent-fs.example.com",
22
+ "https://agent-fs.example.com/?x=1",
23
+ "https://agent-fs.example.com/#frag",
24
+ ]) {
25
+ expect(validateConfigValue("AGENT_FS_PUBLIC_URL", value)).toContain(
26
+ "Invalid AGENT_FS_PUBLIC_URL",
27
+ );
28
+ }
29
+ });
30
+
31
+ test("OPENROUTER_BASE_URL keeps its rules after sharing the URL validator", () => {
32
+ expect(validateConfigValue("OPENROUTER_BASE_URL", "")).toBeNull();
33
+ expect(validateConfigValue("OPENROUTER_BASE_URL", "https://api.example.com/v1")).toBeNull();
34
+ expect(validateConfigValue("OPENROUTER_BASE_URL", "https://api.example.com/v1?x=1")).toContain(
35
+ "Invalid OPENROUTER_BASE_URL",
36
+ );
37
+ });
38
+ });