@desplega.ai/agent-swarm 2.7.10 → 2.8.1

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 (296) hide show
  1. package/dist/acp-adapter-pdy3qsvg.js +15 -0
  2. package/dist/{actions-b8aqhrsg.js → actions-pwjpn0j6.js} +19 -20
  3. package/dist/{amp-adapter-4c165vgn.js → amp-adapter-cq9jgj6x.js} +2 -3
  4. package/dist/{app-m9khefrh.js → app-cnfffgwg.js} +3 -3
  5. package/dist/{assistant-rh4v3ntz.js → assistant-kpn317y1.js} +21 -22
  6. package/dist/{boot-args-schema-hwkc8bzv.js → boot-args-schema-pbbnhmc3.js} +1 -1
  7. package/dist/{boot-reembed-fdyk55h4.js → boot-reembed-9m0ysxma.js} +1 -1
  8. package/dist/{boot-reembed-5y6yw9sj.js → boot-reembed-majbn53m.js} +1 -1
  9. package/dist/{boot-scrub-sweep-r5r8kqsn.js → boot-scrub-sweep-app8g8ym.js} +3 -3
  10. package/dist/{boot-seeds-8f9zt5cm.js → boot-seeds-pbtmvcjm.js} +4 -5
  11. package/dist/{claude-adapter-s5df247c.js → claude-adapter-wn1g3qp5.js} +7 -8
  12. package/dist/{claude-managed-adapter-h74d06yz.js → claude-managed-adapter-jh6c523j.js} +3 -3
  13. package/dist/{claude-managed-setup-9gsmwzyx.js → claude-managed-setup-pd47nzch.js} +6 -6
  14. package/dist/{claude-sdk-session-dq1j4nz9.js → claude-sdk-session-3a2a6589.js} +9066 -8818
  15. package/dist/{cli-n5yexkdg.js → cli-0b4zam62.js} +1 -0
  16. package/dist/{cli-5wfz00be.js → cli-0jzra9ad.js} +2 -2
  17. package/dist/{cli-zjphdj1a.js → cli-0ntbxyaa.js} +40 -18
  18. package/dist/{cli-yz7v0sh4.js → cli-1xh9a7hn.js} +4 -6
  19. package/dist/{cli-eqtfgfr6.js → cli-2gxeg5gr.js} +1 -1
  20. package/dist/{cli-hfkwwy1h.js → cli-2zp0et3v.js} +21 -2
  21. package/dist/{cli-6m6b4bep.js → cli-3rkdne1h.js} +2 -2
  22. package/dist/{cli-mr97t7cc.js → cli-4r05hnqa.js} +263 -14
  23. package/dist/{cli-jc1g9ndz.js → cli-5j88qqa8.js} +10 -5
  24. package/dist/{cli-xfjrc279.js → cli-5mrq3ake.js} +48 -14
  25. package/dist/{cli-an1knn2k.js → cli-6mma83xa.js} +5 -5
  26. package/dist/{cli-tph5wt3y.js → cli-6wj7p986.js} +1 -1
  27. package/dist/{cli-t73cas91.js → cli-7349va39.js} +8100 -7620
  28. package/dist/{cli-5xcb8gxq.js → cli-7b8sbmag.js} +8 -8
  29. package/dist/{cli-3xj33nrx.js → cli-7cp6aa1q.js} +10 -3
  30. package/dist/{cli-mp9aa8g5.js → cli-7p1kvkck.js} +6 -6
  31. package/dist/{cli-j7d73g1y.js → cli-7w69ne2f.js} +3035 -354
  32. package/dist/{cli-cr14kftt.js → cli-89cqnasv.js} +3 -3
  33. package/dist/{cli-w3bk0dgv.js → cli-8aes17e4.js} +2 -2
  34. package/dist/{cli-7wz05bx3.js → cli-93k32c37.js} +468 -745
  35. package/dist/{cli-eqk5p56g.js → cli-9vhebtjz.js} +9 -9
  36. package/dist/{cli-td33w98c.js → cli-9wngrawf.js} +10 -10
  37. package/dist/cli-a3b239vq.js +242 -0
  38. package/dist/{cli-kx4c8j05.js → cli-b085njxz.js} +63 -19
  39. package/dist/{cli-8ewkreqd.js → cli-b5rs97a6.js} +7 -9
  40. package/dist/{cli-bxz823sz.js → cli-b8e9nb04.js} +1 -1
  41. package/dist/{cli-nj3x45rw.js → cli-bb431xey.js} +52 -43
  42. package/dist/{cli-36wdfzgn.js → cli-bsywb58a.js} +8 -8
  43. package/dist/{cli-18qt3few.js → cli-cyhbbd1z.js} +1 -1
  44. package/dist/{cli-eb2azq8n.js → cli-d3p5vwbk.js} +9 -9
  45. package/dist/{cli-2tsfpc70.js → cli-dy32zecz.js} +1 -1
  46. package/dist/{cli-rjyghzg4.js → cli-g70vxtjh.js} +2 -2
  47. package/dist/{cli-55bkx8hh.js → cli-gax7fk3t.js} +1 -1
  48. package/dist/{cli-jg24scat.js → cli-jcpr5smb.js} +3 -3
  49. package/dist/{cli-n07eecjs.js → cli-jywyhqws.js} +3 -3
  50. package/dist/{cli-38yww4e9.js → cli-k0615eh8.js} +8 -8
  51. package/dist/{cli-3xddv0rk.js → cli-k26bkr9t.js} +5 -7
  52. package/dist/{cli-xd5ebp64.js → cli-k93bq1wq.js} +3 -3
  53. package/dist/{cli-f2zenhja.js → cli-kc7v1nfv.js} +1 -1
  54. package/dist/{cli-x9exydey.js → cli-m4dqmnbp.js} +1 -1
  55. package/dist/{cli-gpwhbgx0.js → cli-m9s2qff2.js} +57 -25
  56. package/dist/{cli-ybjdc978.js → cli-mrt48bx7.js} +7 -4
  57. package/dist/{cli-ttbqe3q4.js → cli-p1w18yhx.js} +1 -1
  58. package/dist/{cli-h49ejvmc.js → cli-pcad4cb1.js} +1 -1
  59. package/dist/{cli-tmft5dz2.js → cli-qmqk2yc2.js} +1 -1
  60. package/dist/{cli-g1px1g2e.js → cli-re4raaj0.js} +1 -1
  61. package/dist/{cli-xbtq4d6s.js → cli-sn7rtnj4.js} +12 -8
  62. package/dist/{cli-n9abj89w.js → cli-syybb0p1.js} +8 -8
  63. package/dist/{cli-v2fwbnsk.js → cli-tacge1w0.js} +6 -6
  64. package/dist/{cli-pyrxt9gw.js → cli-tk7cjj8h.js} +1 -1
  65. package/dist/{cli-xvymtmv4.js → cli-tqegb8eq.js} +3 -3
  66. package/dist/{cli-kf3pxxdg.js → cli-v1dv1r37.js} +1 -1
  67. package/dist/{cli-z9cs5m0w.js → cli-vbh10fqa.js} +12 -12
  68. package/dist/{cli-3xcwp3z8.js → cli-vj75tyaw.js} +3 -3
  69. package/dist/{cli-xncjscpm.js → cli-vqptjbr7.js} +50 -24
  70. package/dist/{cli-q581b386.js → cli-wk18cm92.js} +5 -5
  71. package/dist/{cli-4vwxp550.js → cli-x1wa213s.js} +1 -1
  72. package/dist/{cli-n9ftpys4.js → cli-x6t50dmw.js} +7 -7
  73. package/dist/{cli-jrp1dt73.js → cli-xzm9vcfg.js} +1 -1
  74. package/dist/{cli-16phend6.js → cli-yn2bbre9.js} +1 -1
  75. package/dist/{cli-rt0ag4x1.js → cli-yncmerje.js} +5 -5
  76. package/dist/{cli-0m7rtm11.js → cli-zcsw143p.js} +1 -1
  77. package/dist/cli.js +18 -18
  78. package/dist/{codex-adapter-yr60sme6.js → codex-adapter-nha71q3n.js} +5 -6
  79. package/dist/{codex-hook-fac6175r.js → codex-hook-h3vk6xzr.js} +1 -1
  80. package/dist/{codex-session-runner-pch8x584.js → codex-session-runner-ak9x1k1h.js} +5 -6
  81. package/dist/{commands-phjfbkv0.js → commands-f587qpq8.js} +3 -3
  82. package/dist/{controller-jkx994pz.js → controller-hxx8wwy1.js} +2 -2
  83. package/dist/{controllers-connect-c4448kwa.js → controllers-connect-k5sg9m9h.js} +20 -21
  84. package/dist/{cursor-adapter-ndebqnm8.js → cursor-adapter-n5nc3mfe.js} +1 -2
  85. package/dist/{db-ef32tbfc.js → db-amm8w15a.js} +10 -2
  86. package/dist/{db-ez6egt6v.js → db-nzf8zb5z.js} +3 -3
  87. package/dist/{devin-adapter-z46ep5ph.js → devin-adapter-xedz98zv.js} +1 -1
  88. package/dist/{dispatcher-g3tt9hs9.js → dispatcher-89zrts8f.js} +18 -19
  89. package/dist/{dsh-adapter-tcyn3099.js → dsh-adapter-nrhbrjz8.js} +1 -2
  90. package/dist/{easter-egg-3d-e36hk5td.js → easter-egg-3d-533knw22.js} +1 -1
  91. package/dist/{embedding-space-4kyh5qqj.js → embedding-space-ezwenjmj.js} +6 -6
  92. package/dist/{embeddings-6a8v4a6t.js → embeddings-np74ht6g.js} +1 -1
  93. package/dist/{execute-3cbg0twf.js → execute-b3mrb1mv.js} +1 -1
  94. package/dist/{external-channel-se646snz.js → external-channel-z46yx9d7.js} +2 -2
  95. package/dist/{fx-adapter-yw795hqq.js → fx-adapter-3q12snn6.js} +7 -8
  96. package/dist/{grok-adapter-ttmcss2j.js → grok-adapter-ahb1w033.js} +7 -8
  97. package/dist/handlers-vbww69re.js +32 -0
  98. package/dist/heartbeat-dt9qw9c8.js +43 -0
  99. package/dist/{hook-hq93y5ej.js → hook-8k6fbz9b.js} +5 -5
  100. package/dist/{hook-g3nhexsy.js → hook-jgcgygex.js} +6 -6
  101. package/dist/{http-5a9p4h6y.js → http-haw4r8ne.js} +284 -142
  102. package/dist/{index-0eny15vj.js → index-2skqtd76.js} +2 -2
  103. package/dist/{index-6haqt3v5.js → index-4a0670yh.js} +8917 -8476
  104. package/dist/index-4xwaf5th.js +32 -0
  105. package/dist/{index-3c5pxbge.js → index-5gk12my8.js} +1 -1
  106. package/dist/{index-w7em4ktq.js → index-d6wkh8ar.js} +2 -2
  107. package/dist/index-f0hcrs8e.js +33 -0
  108. package/dist/{index-rvccek1w.js → index-gjwaqaq8.js} +5 -5
  109. package/dist/{index-e5pfbsys.js → index-hjhfk3ra.js} +3 -3
  110. package/dist/{index-1qw6f2dc.js → index-khe3gp0k.js} +4 -4
  111. package/dist/index-s4ewdma4.js +37 -0
  112. package/dist/{index-hgn3c961.js → index-tez78qj3.js} +979 -36
  113. package/dist/{index-s72rqgsx.js → index-tvfafeyy.js} +1 -1
  114. package/dist/{keepalive-1j4n4dmk.js → keepalive-xn6s7rmg.js} +3 -3
  115. package/dist/lead-6ygbfhbh.js +70 -0
  116. package/dist/{maintenance-dmghacy5.js → maintenance-vdts800b.js} +1 -1
  117. package/dist/{node-je82wjet.js → node-4c5jqxr3.js} +1 -1
  118. package/dist/{oauth-refresh-sweep-yy06c03c.js → oauth-refresh-sweep-094c8wfk.js} +2 -2
  119. package/dist/{onboard-52f9t5dm.js → onboard-v99eh56m.js} +3 -3
  120. package/dist/{opencode-adapter-krnh9jkn.js → opencode-adapter-dsagkhtw.js} +5 -6
  121. package/dist/{otel-impl-xjqz6wjj.js → otel-impl-q7yr9yp0.js} +1 -1
  122. package/dist/{pi-mono-adapter-dbxyp0qv.js → pi-mono-adapter-546cd1cc.js} +9 -9
  123. package/dist/{pricing-refresh-ctdr74pd.js → pricing-refresh-7dh2yase.js} +2 -3
  124. package/dist/{rbac-roles-ehv8s10n.js → rbac-roles-mdmc96p4.js} +3 -3
  125. package/dist/{rbac-roles-q0gr8eyj.js → rbac-roles-npbmdh77.js} +4 -6
  126. package/dist/{registry-hpjfmcfz.js → registry-32b1mft6.js} +1 -1
  127. package/dist/{render-v2-5b6chvcq.js → render-v2-twhhwmms.js} +3 -3
  128. package/dist/{resume-5a5d2845.js → resume-5gsrjd5e.js} +6 -6
  129. package/dist/{runtime-khxszyfp.js → runtime-1hv06jsn.js} +1 -1
  130. package/dist/{session-access-gj0bjhqg.js → session-access-m191x30x.js} +4 -4
  131. package/dist/{session-source-backfill-2sy0krfk.js → session-source-backfill-nt923ask.js} +2 -2
  132. package/dist/{setup-7ssfakk1.js → setup-wv467afy.js} +1 -1
  133. package/dist/{virtual-modules-pjj0knwf.js → virtual-modules-gazyapte.js} +3 -3
  134. package/dist/{work-objects-bf3syvhq.js → work-objects-8zkrpy13.js} +21 -22
  135. package/dist/{worker-follow-up-38xevga6.js → worker-follow-up-cecqszem.js} +18 -19
  136. package/dist/worker-mz5z7kj0.js +70 -0
  137. package/openapi.json +334 -7
  138. package/package.json +5 -5
  139. package/src/apps/definition.ts +11 -0
  140. package/src/apps/store.ts +28 -8
  141. package/src/be/db/model-profiles.ts +147 -38
  142. package/src/be/db/tasks/read.ts +5 -1
  143. package/src/be/db/workflow-run-definitions.ts +117 -0
  144. package/src/be/db.ts +24 -3
  145. package/src/be/memory/constants.ts +14 -1
  146. package/src/be/memory/key-paths.ts +8 -0
  147. package/src/be/memory/providers/sqlite-store.ts +160 -10
  148. package/src/be/memory/task-learning.ts +79 -14
  149. package/src/be/memory/types.ts +24 -1
  150. package/src/be/migrations/279_backfill_learning_expiry.sql +15 -0
  151. package/src/be/migrations/281_model_profiles_pr2.sql +28 -0
  152. package/src/be/migrations/283_workflow_run_definitions.sql +14 -0
  153. package/src/be/model-profile-check.ts +284 -0
  154. package/src/be/model-tier-resolution.ts +112 -12
  155. package/src/be/multi-runtime.ts +27 -0
  156. package/src/be/runtime-pools/routing.ts +52 -4
  157. package/src/be/scripts/typecheck.ts +1 -0
  158. package/src/be/seed-scripts/catalog/dreaming-learnings.ts +552 -0
  159. package/src/be/seed-scripts/catalog/dreaming-memtax-create.ts +389 -14
  160. package/src/be/seed-scripts/catalog/dreaming-memtax.ts +6 -3
  161. package/src/be/seed-scripts/index.ts +9 -0
  162. package/src/be/steering.ts +8 -2
  163. package/src/commands/onboard/agent-fs-version.ts +1 -1
  164. package/src/commands/runner.ts +32 -1
  165. package/src/fs/provider.ts +17 -3
  166. package/src/heartbeat/heartbeat.ts +12 -1
  167. package/src/heartbeat/index.ts +1 -0
  168. package/src/http/agents.ts +56 -4
  169. package/src/http/apps.ts +3 -1
  170. package/src/http/config.ts +2 -6
  171. package/src/http/index.ts +2 -3
  172. package/src/http/model-profiles.ts +58 -10
  173. package/src/http/poll.ts +36 -3
  174. package/src/http/schedules.ts +42 -3
  175. package/src/http/tasks.ts +37 -12
  176. package/src/http/workflows.ts +15 -2
  177. package/src/prompts/session-templates.ts +1 -1
  178. package/src/providers/acp-targets.ts +11 -6
  179. package/src/providers/amp-adapter.ts +1 -1
  180. package/src/providers/claude-sdk-session.ts +132 -23
  181. package/src/providers/codex-skill-resolver.ts +10 -4
  182. package/src/providers/cursor-adapter.ts +1 -1
  183. package/src/providers/devin-skill-resolver.ts +5 -5
  184. package/src/providers/dsh-adapter.ts +1 -1
  185. package/src/scheduler/schedule-task.ts +1 -0
  186. package/src/scripts-runtime/eval-harness.ts +14 -1
  187. package/src/scripts-runtime/executors/types.ts +3 -0
  188. package/src/scripts-runtime/sdk-allowlist.ts +1 -0
  189. package/src/scripts-runtime/swarm-sdk.ts +18 -1
  190. package/src/scripts-runtime/types/stdlib.d.ts +1 -0
  191. package/src/scripts-runtime/types/swarm-sdk.d.ts +1 -0
  192. package/src/server.ts +2 -0
  193. package/src/slack/app.ts +93 -0
  194. package/src/slack/inbound-dispatch.ts +18 -1
  195. package/src/slack/workspace-guard.ts +345 -0
  196. package/src/tasks/task-terminal-effects.ts +4 -0
  197. package/src/tasks/worker-follow-up.ts +102 -2
  198. package/src/tests/acp-adapter.test.ts +82 -0
  199. package/src/tests/apps-icon.test.ts +120 -0
  200. package/src/tests/chained-task-follow-up.test.ts +248 -0
  201. package/src/tests/check-pr-body.test.ts +40 -0
  202. package/src/tests/claude-sdk-lifecycle.test.ts +216 -1
  203. package/src/tests/claude-sdk-process.fixture.ts +57 -0
  204. package/src/tests/codex-skill-resolver.test.ts +31 -0
  205. package/src/tests/credentials-allowlist.test.ts +470 -0
  206. package/src/tests/db-task-read-contract.test.ts +5 -0
  207. package/src/tests/db-task-write-contract.test.ts +5 -0
  208. package/src/tests/deferred-wake-follow-up.test.ts +47 -0
  209. package/src/tests/docs-index-footprint.test.js +3 -3
  210. package/src/tests/dreaming-learnings.test.ts +1395 -0
  211. package/src/tests/dsh-adapter.test.ts +1 -1
  212. package/src/tests/explicit-model-validation.test.ts +2 -0
  213. package/src/tests/fs-provider.test.ts +42 -0
  214. package/src/tests/heartbeat.test.ts +28 -1
  215. package/src/tests/human-free-reclassify.test.ts +5 -1
  216. package/src/tests/list-endpoint-slimming.test.ts +17 -0
  217. package/src/tests/mcp-tools.test.ts +1 -1
  218. package/src/tests/migration-283-workflow-run-definitions.test.ts +69 -0
  219. package/src/tests/model-profile-check.test.ts +387 -0
  220. package/src/tests/model-profiles-api.test.ts +528 -1
  221. package/src/tests/profile-claim.test.ts +415 -3
  222. package/src/tests/profile-tier-alias.test.ts +382 -0
  223. package/src/tests/schedule-profile.test.ts +359 -0
  224. package/src/tests/script-connections.test.ts +6 -0
  225. package/src/tests/script-native-unawaited-drain.test.ts +167 -0
  226. package/src/tests/script-per-script-executor.test.ts +1 -0
  227. package/src/tests/scripts-sdk-bridge-tool-failure.test.ts +141 -0
  228. package/src/tests/seed-scripts.test.ts +2 -2
  229. package/src/tests/slack-inbound-receipts.test.ts +22 -2
  230. package/src/tests/slack-socket-ack.test.ts +16 -1
  231. package/src/tests/slack-workspace-guard.test.ts +905 -0
  232. package/src/tests/steering-core.test.ts +40 -0
  233. package/src/tests/store-progress-learning.test.ts +605 -20
  234. package/src/tests/tool-annotations.test.ts +1 -1
  235. package/src/tests/workflow-convergence.test.ts +46 -40
  236. package/src/tests/workflow-definition-pinning-recovery.test.ts +552 -0
  237. package/src/tests/workflow-definition-pinning.test.ts +645 -0
  238. package/src/tests/workflow-executors.test.ts +16 -7
  239. package/src/tests/workflow-foreach.test.ts +43 -20
  240. package/src/tests/workflow-notify-slack-ready.test.ts +161 -0
  241. package/src/tests/workflow-profile.test.ts +328 -0
  242. package/src/tools/app-upsert.ts +1 -1
  243. package/src/tools/memory-edit.ts +2 -1
  244. package/src/tools/model-profiles/check-model-profile.ts +63 -0
  245. package/src/tools/schedules/create-schedule.ts +45 -4
  246. package/src/tools/schedules/patch-schedule.ts +50 -4
  247. package/src/tools/schedules/update-schedule.ts +50 -4
  248. package/src/tools/script-run.ts +1 -1
  249. package/src/tools/send-task.ts +17 -2
  250. package/src/tools/store-progress.ts +15 -3
  251. package/src/tools/task-action.ts +9 -1
  252. package/src/tools/templates.ts +13 -0
  253. package/src/tools/tool-config.ts +2 -1
  254. package/src/tools/utils.ts +61 -4
  255. package/src/tools/workflows/create-workflow.ts +1 -1
  256. package/src/tools/workflows/retry-workflow-run.ts +1 -1
  257. package/src/tools/workflows/update-workflow.ts +10 -1
  258. package/src/types.ts +56 -1
  259. package/src/utils/credentials.ts +89 -12
  260. package/src/workflows/engine.ts +10 -1
  261. package/src/workflows/executors/agent-task.ts +21 -2
  262. package/src/workflows/executors/foreach.ts +4 -1
  263. package/src/workflows/executors/notify.ts +62 -6
  264. package/src/workflows/executors/sub-workflow.ts +1 -1
  265. package/src/workflows/executors/swarm-script.ts +4 -1
  266. package/src/workflows/foreach-driver.ts +8 -5
  267. package/src/workflows/limits.ts +2 -1
  268. package/src/workflows/model-validation.ts +27 -2
  269. package/src/workflows/patch-definition.ts +3 -1
  270. package/src/workflows/recovery.ts +6 -6
  271. package/src/workflows/resume.ts +9 -9
  272. package/src/workflows/retry-poller.ts +2 -2
  273. package/templates/skills/apps/SKILL.md +2 -0
  274. package/templates/skills/apps/content.md +2 -0
  275. package/templates/skills/code-quality/content.md +12 -0
  276. package/templates/skills/memory/content.md +8 -0
  277. package/templates/skills/scheduling/config.json +1 -1
  278. package/templates/skills/scheduling/content.md +2 -2
  279. package/templates/skills/swarm-docs/content.md +4 -0
  280. package/templates/skills/swarm-extensions/content.md +1 -1
  281. package/templates/skills/swarm-scripts/SKILL.md +2 -2
  282. package/templates/skills/swarm-scripts/content.md +2 -2
  283. package/templates/skills/work-on-task/SKILL.md +2 -0
  284. package/templates/skills/work-on-task/content.md +2 -0
  285. package/templates/workflows/dreaming/content.md +174 -7
  286. package/dist/acp-adapter-srfhs1s9.js +0 -16
  287. package/dist/cli-bzvs88tv.js +0 -339
  288. package/dist/cli-cyn9v8zr.js +0 -748
  289. package/dist/cli-ed6yqpf1.js +0 -779
  290. package/dist/handlers-17wha3ze.js +0 -33
  291. package/dist/heartbeat-gwewgdms.js +0 -42
  292. package/dist/index-8arwq8mw.js +0 -34
  293. package/dist/index-tpw054az.js +0 -38
  294. package/dist/index-waq75j2j.js +0 -31
  295. package/dist/lead-re73kdgc.js +0 -72
  296. package/dist/worker-r8mz7a65.js +0 -72
@@ -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-alpha.3",
379
+ "dsh CLI not found. Install @deepseek-ai/dsh@0.2.2-rc.1",
380
380
  );
381
381
  expect(await Bun.file(join(config.cwd, "invocation.json")).exists()).toBe(false);
382
382
  });
@@ -549,6 +549,7 @@ describe("workflow agent-task node", () => {
549
549
  db: {
550
550
  getTaskByWorkflowRunStepId: async () => null,
551
551
  getWorkflow: async () => null,
552
+ getRunWorkflow: async () => null,
552
553
  createTaskExtended: async () => ({ id: crypto.randomUUID() }),
553
554
  },
554
555
  } as unknown as ConstructorParameters<typeof AgentTaskExecutor>[0];
@@ -704,6 +705,7 @@ describe("harness compatibility at every create entry point", () => {
704
705
  db: {
705
706
  getTaskByWorkflowRunStepId: async () => null,
706
707
  getWorkflow: async () => null,
708
+ getRunWorkflow: async () => null,
707
709
  createTaskExtended: async () => ({ id: crypto.randomUUID() }),
708
710
  },
709
711
  } as unknown as ConstructorParameters<typeof AgentTaskExecutor>[0];
@@ -6,8 +6,10 @@ import {
6
6
  AgentFsProvider,
7
7
  agentFsUploadTimeoutMs,
8
8
  FilesError,
9
+ fileObjectFromHeaders,
9
10
  LocalFsProvider,
10
11
  normalizeFilesError,
12
+ normalizeStoredKey,
11
13
  resetFileStorageProviderForTests,
12
14
  selectProvider,
13
15
  } from "../fs";
@@ -532,6 +534,46 @@ describe("normalizeFilesError", () => {
532
534
  });
533
535
  });
534
536
 
537
+ describe("normalizeStoredKey", () => {
538
+ test("accepts a concrete relative path and strips leading slashes", () => {
539
+ expect(normalizeStoredKey("/tasks/report.md")).toBe("tasks/report.md");
540
+ });
541
+
542
+ test("rejects '.' and empty path segments", () => {
543
+ expect(() => normalizeStoredKey(".")).toThrow(FilesError);
544
+ expect(() => normalizeStoredKey("tasks//report.md")).toThrow(FilesError);
545
+ expect(() => normalizeStoredKey("tasks/./report.md")).toThrow(FilesError);
546
+ });
547
+
548
+ test("still rejects parent path segments", () => {
549
+ expect(() => normalizeStoredKey("../secret")).toThrow(FilesError);
550
+ expect(() => normalizeStoredKey("tasks/%2e%2e/x")).toThrow(FilesError);
551
+ });
552
+ });
553
+
554
+ describe("fileObjectFromHeaders", () => {
555
+ const scope = { taskId: "task-1", name: "notes.md" };
556
+
557
+ test("keeps a valid Content-Length as sizeBytes", () => {
558
+ const file = fileObjectFromHeaders(
559
+ "agent-fs",
560
+ scope,
561
+ new Headers({ "content-length": "42", "content-type": "text/plain" }),
562
+ );
563
+ expect(file.sizeBytes).toBe(42);
564
+ expect(file.contentType).toBe("text/plain");
565
+ });
566
+
567
+ test("omits sizeBytes for missing, malformed, negative, or non-finite Content-Length", () => {
568
+ for (const value of [null, "unknown", "-1", "NaN", "Infinity"]) {
569
+ const headers = new Headers();
570
+ if (value !== null) headers.set("content-length", value);
571
+ const file = fileObjectFromHeaders("agent-fs", scope, headers);
572
+ expect(file.sizeBytes).toBeUndefined();
573
+ }
574
+ });
575
+ });
576
+
535
577
  describe("selectProvider", () => {
536
578
  test("defaults to local-fs without agent-fs env", () => {
537
579
  delete process.env.AGENT_FS_API_URL;
@@ -1,4 +1,4 @@
1
- import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
1
+ import { afterAll, beforeAll, beforeEach, describe, expect, spyOn, test } from "bun:test";
2
2
  import { unlink } from "node:fs/promises";
3
3
  import {
4
4
  cancelTask,
@@ -29,6 +29,7 @@ import {
29
29
  codeLevelTriage,
30
30
  getBootEpochMs,
31
31
  getRebootAffectedTasks,
32
+ parseHeartbeatIntervalMs,
32
33
  preflightGate,
33
34
  runHeartbeatSweep,
34
35
  runRebootSweep,
@@ -1483,5 +1484,31 @@ describe("Heartbeat Triage", () => {
1483
1484
  // Should not throw when called again
1484
1485
  stopHeartbeat();
1485
1486
  });
1487
+
1488
+ test("HEARTBEAT_INTERVAL_MS falls back to 90s unless it is a positive integer", () => {
1489
+ for (const raw of ["Infinity", "-Infinity", "NaN", "0", "-5", "1.5", ""]) {
1490
+ expect(parseHeartbeatIntervalMs(raw)).toBe(90_000);
1491
+ }
1492
+ expect(parseHeartbeatIntervalMs(undefined)).toBe(90_000);
1493
+ expect(parseHeartbeatIntervalMs("1500")).toBe(1500);
1494
+ });
1495
+
1496
+ test("startHeartbeat schedules the sanitized env interval", () => {
1497
+ const previous = process.env.HEARTBEAT_INTERVAL_MS;
1498
+ const log = spyOn(console, "log");
1499
+ try {
1500
+ process.env.HEARTBEAT_INTERVAL_MS = "Infinity";
1501
+ startHeartbeat();
1502
+ const started = log.mock.calls.some((call) =>
1503
+ String(call[0]).includes("Starting with 90000ms"),
1504
+ );
1505
+ expect(started).toBe(true);
1506
+ } finally {
1507
+ stopHeartbeat();
1508
+ log.mockRestore();
1509
+ if (previous === undefined) delete process.env.HEARTBEAT_INTERVAL_MS;
1510
+ else process.env.HEARTBEAT_INTERVAL_MS = previous;
1511
+ }
1512
+ });
1486
1513
  });
1487
1514
  });
@@ -481,8 +481,12 @@ describe("human-free flag stays correct when a classifying input changes", () =>
481
481
  const fans: string[] = [];
482
482
  for (let i = 0; i < 9; i++) fans.push(await task(`fan ${i}`, { parentTaskId: wide }));
483
483
  const fanChild = await task("below a fan", { parentTaskId: fans[4] });
484
+ // Sibling order out of the `parentTaskId` index follows the random task ids, so
485
+ // which child a batch reaches first is not fixed. The handoff sits deeper
486
+ // than the first batch can reach in any sibling order (root, its two
487
+ // children, one grandchild), so that batch always changes `batchSize` flags.
484
488
  const handedOff = await task("explicitly attributed", {
485
- parentTaskId: wide,
489
+ parentTaskId: fanChild,
486
490
  requestedByUserId: owner.id,
487
491
  });
488
492
  const belowHandedOff = await task("below the handoff", { parentTaskId: handedOff });
@@ -19,6 +19,7 @@ import {
19
19
  listWorkflows,
20
20
  updateAgentProfile,
21
21
  } from "../be/db";
22
+ import { createModelProfile } from "../be/db/model-profiles";
22
23
  import type { Page, Workflow } from "../types";
23
24
 
24
25
  const TEST_DB_PATH = "./test-list-endpoint-slimming.sqlite";
@@ -231,6 +232,22 @@ describe("list-endpoint slimming", () => {
231
232
  expect(full?.totalCostUsd).toBeCloseTo(0.0168, 6);
232
233
  });
233
234
 
235
+ test("getAllTasks — slim keeps the task profile and resolved profile", async () => {
236
+ await createModelProfile({ name: "slim-profile", harness: "claude", model: "opus" });
237
+ const task = await createTaskExtended("slim-profile-row", {
238
+ agentId: "slim-agent-1",
239
+ profile: "slim-profile",
240
+ });
241
+ await getDbClient().run("UPDATE agent_tasks SET resolvedProfile = ? WHERE id = ?", [
242
+ "slim-profile",
243
+ task.id,
244
+ ]);
245
+
246
+ const [row] = await getAllTasks({ search: "slim-profile-row", limit: 1 }, { slim: true });
247
+ expect(row?.profile).toBe("slim-profile");
248
+ expect(row?.resolvedProfile).toBe("slim-profile");
249
+ });
250
+
234
251
  test("getAllTasks — SQL-side preview matches truncating the full text", async () => {
235
252
  // The SQL cut counts UTF-8 bytes while JS slices UTF-16 units, so pin the
236
253
  // boundary with astral (surrogate-pair) and multibyte characters. SQLite's
@@ -48,7 +48,7 @@ describe("script MCP tools", () => {
48
48
  "script-search":
49
49
  "Semantic search over swarm-shared TypeScript scripts (catalog persisted in the agent-swarm DB; callable from agents and workflows). For ephemeral throwaway TS on your local machine, use code-mode instead.",
50
50
  "script-run":
51
- "Run a named swarm-shared script (callable across agents and from workflow `swarm-script` nodes), OR inline source (auto-saved as scratch to the catalog). Inline source executes without the `script-upsert` compile-time typecheck. Use for swarm-visible, durable scripts. For local-only throwaway TS, use code-mode `run`.",
51
+ "Run a named swarm-shared script (callable across agents and from workflow `swarm-script` nodes), OR inline source (auto-saved as scratch to the catalog). Inline source executes without the `script-upsert` compile-time typecheck. Use for swarm-visible, durable scripts. For local-only throwaway TS, use code-mode `run`. The run ends when the script's default export resolves: a call it did not await gets 2 s more, then is stopped (native) or aborted at once (quickjs), so await every write that must land. A `Promise.race` deadline therefore bounds the run; a nested `script_run` that lost the race keeps running on the server under its own wall.",
52
52
  "script-upsert":
53
53
  'Typecheck and persist a TypeScript script to the swarm catalog under your agent scope (or global if you\'re a lead). Import `ScriptContext` from "swarm-sdk" for a real context type. Other agents and workflow nodes will be able to find and run it. For local-only scripts, use code-mode `save`.',
54
54
  "script-delete":
@@ -0,0 +1,69 @@
1
+ import { Database } from "bun:sqlite";
2
+ import { afterAll, beforeAll, expect, test } from "bun:test";
3
+ import { unlink } from "node:fs/promises";
4
+ import { closeDb, getDbClient, initDb } from "../be/db";
5
+
6
+ const TEST_DB_PATH = "./test-migration-283-workflow-run-definitions.sqlite";
7
+ const MIGRATION = "src/be/migrations/283_workflow_run_definitions.sql";
8
+
9
+ beforeAll(() => {
10
+ initDb(TEST_DB_PATH);
11
+ });
12
+
13
+ afterAll(async () => {
14
+ closeDb();
15
+ for (const suffix of ["", "-wal", "-shm"]) {
16
+ await unlink(`${TEST_DB_PATH}${suffix}`).catch(() => {});
17
+ }
18
+ });
19
+
20
+ test("migration 283 applies on a fresh database", async () => {
21
+ const client = getDbClient();
22
+ const columns = await client.query<{ name: string; notnull: number }>(
23
+ "SELECT name, \"notnull\" FROM pragma_table_info('workflow_run_definitions') ORDER BY cid",
24
+ );
25
+ expect(columns).toEqual([
26
+ { name: "hash", notnull: 0 },
27
+ { name: "snapshot", notnull: 1 },
28
+ { name: "createdAt", notnull: 1 },
29
+ ]);
30
+ const runColumn = await client.get<{ name: string }>(
31
+ "SELECT name FROM pragma_table_info('workflow_runs') WHERE name = 'definitionHash'",
32
+ );
33
+ expect(runColumn?.name).toBe("definitionHash");
34
+ const index = await client.get<{ name: string }>(
35
+ "SELECT name FROM sqlite_master WHERE type = 'index' AND name = 'idx_workflow_runs_definitionHash'",
36
+ );
37
+ expect(index?.name).toBe("idx_workflow_runs_definitionHash");
38
+ });
39
+
40
+ test("migration 283 leaves existing runs unpinned and rejects an unknown hash", async () => {
41
+ const db = new Database(":memory:");
42
+ try {
43
+ db.exec("PRAGMA foreign_keys = ON");
44
+ db.exec("CREATE TABLE workflow_runs (id TEXT PRIMARY KEY, workflowId TEXT, status TEXT)");
45
+ db.exec(
46
+ "INSERT INTO workflow_runs (id, workflowId, status) VALUES ('old-done', 'wf', 'completed'), ('old-waiting', 'wf', 'waiting')",
47
+ );
48
+
49
+ db.exec(await Bun.file(MIGRATION).text());
50
+
51
+ expect(db.prepare("SELECT id, definitionHash FROM workflow_runs ORDER BY id").all()).toEqual([
52
+ { id: "old-done", definitionHash: null },
53
+ { id: "old-waiting", definitionHash: null },
54
+ ]);
55
+ db.exec(
56
+ "INSERT INTO workflow_run_definitions (hash, snapshot, createdAt) VALUES ('h1', '{}', '2026-11-04T00:00:00.000Z')",
57
+ );
58
+ db.exec(
59
+ "INSERT INTO workflow_runs (id, workflowId, status, definitionHash) VALUES ('new', 'wf', 'running', 'h1')",
60
+ );
61
+ expect(() =>
62
+ db.exec(
63
+ "INSERT INTO workflow_runs (id, workflowId, status, definitionHash) VALUES ('bad', 'wf', 'running', 'missing')",
64
+ ),
65
+ ).toThrow();
66
+ } finally {
67
+ db.close();
68
+ }
69
+ });
@@ -0,0 +1,387 @@
1
+ // checkProfileForAgent: one case per state per check row (harness, model,
2
+ // harness-credentials, credential-allowlist), and no secret value in any row.
3
+
4
+ import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
5
+ import { unlink } from "node:fs/promises";
6
+ import {
7
+ closeDb,
8
+ createAgent,
9
+ createSwarmRepo,
10
+ getDbClient,
11
+ initDb,
12
+ upsertSwarmConfig,
13
+ } from "../be/db";
14
+ import { updateAgentCredStatus } from "../be/db/agents";
15
+ import { createModelProfile, taskProfileError } from "../be/db/model-profiles";
16
+ import { checkProfileForAgent, formatProfileCheckFailures } from "../be/model-profile-check";
17
+ import type { AgentCredStatus, ProfileCheckResult, ProfileCheckRow } from "../types";
18
+
19
+ const TEST_DB_PATH = "./test-model-profile-check.sqlite";
20
+ const oldEncryptionKey = process.env.SECRETS_ENCRYPTION_KEY;
21
+
22
+ // Two pooled keys; only the last five characters may ever surface.
23
+ const KEY_A = "sk-ant-oat01-secret-material-aaaaaaaa-11111";
24
+ const KEY_B = "sk-ant-oat01-secret-material-bbbbbbbb-22222";
25
+
26
+ async function removeDbFiles(path: string): Promise<void> {
27
+ for (const suffix of ["", "-wal", "-shm"]) {
28
+ try {
29
+ await unlink(path + suffix);
30
+ } catch (error) {
31
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
32
+ }
33
+ }
34
+ }
35
+
36
+ function report(overrides: Partial<AgentCredStatus> = {}): AgentCredStatus {
37
+ return {
38
+ ready: true,
39
+ missing: [],
40
+ satisfiedBy: "env",
41
+ hint: null,
42
+ liveTest: null,
43
+ latestModel: null,
44
+ reportedAt: Date.now(),
45
+ reportKind: "boot",
46
+ bedrock: null,
47
+ acp: null,
48
+ ...overrides,
49
+ };
50
+ }
51
+
52
+ async function agent(harnessProvider: "claude" | "codex" | "pi" | "fx", cred?: AgentCredStatus) {
53
+ const created = await createAgent({
54
+ name: `check-${harnessProvider}-${crypto.randomUUID().slice(0, 8)}`,
55
+ isLead: false,
56
+ status: "idle",
57
+ harnessProvider,
58
+ });
59
+ if (cred) await updateAgentCredStatus(created.id, cred);
60
+ return created.id;
61
+ }
62
+
63
+ async function check(agentId: string, profile: string): Promise<ProfileCheckResult> {
64
+ const result = await checkProfileForAgent(agentId, profile);
65
+ if (!result) throw new Error(`no result for ${profile}`);
66
+ return result;
67
+ }
68
+
69
+ function row(result: ProfileCheckResult, name: ProfileCheckRow["check"]) {
70
+ return result.profiles[0]?.checks.find((r) => r.check === name);
71
+ }
72
+
73
+ async function pool(agentId: string, key: string, value: string): Promise<void> {
74
+ await upsertSwarmConfig({
75
+ scope: "agent",
76
+ scopeId: agentId,
77
+ key,
78
+ value,
79
+ isSecret: true,
80
+ exportToEnv: true,
81
+ });
82
+ }
83
+
84
+ beforeAll(async () => {
85
+ process.env.SECRETS_ENCRYPTION_KEY ??= Buffer.alloc(32, 7).toString("base64");
86
+ await removeDbFiles(TEST_DB_PATH);
87
+ initDb(TEST_DB_PATH);
88
+ });
89
+
90
+ afterAll(async () => {
91
+ closeDb();
92
+ await removeDbFiles(TEST_DB_PATH);
93
+ if (oldEncryptionKey === undefined) delete process.env.SECRETS_ENCRYPTION_KEY;
94
+ else process.env.SECRETS_ENCRYPTION_KEY = oldEncryptionKey;
95
+ });
96
+
97
+ beforeEach(async () => {
98
+ const client = getDbClient();
99
+ await client.run("DELETE FROM agent_tasks");
100
+ await client.run("DELETE FROM scheduled_tasks");
101
+ await client.run("DELETE FROM swarm_config");
102
+ await client.run("DELETE FROM swarm_repos");
103
+ await client.run("DELETE FROM api_key_status");
104
+ await client.run("DELETE FROM agents");
105
+ await client.run("DELETE FROM model_profiles");
106
+ await createModelProfile({ name: "claude-opus", harness: "claude", model: "opus" });
107
+ await createModelProfile({ name: "codex-sol", harness: "codex", model: "gpt-5.6-sol" });
108
+ });
109
+
110
+ describe("unknown inputs", () => {
111
+ test("an unknown agent or profile is null", async () => {
112
+ const id = await agent("claude");
113
+ expect(await checkProfileForAgent(id, "no-such-profile")).toBeNull();
114
+ expect(await checkProfileForAgent(crypto.randomUUID(), "claude-opus")).toBeNull();
115
+ });
116
+ });
117
+
118
+ describe("harness", () => {
119
+ test("the profile's harness on the agent's harness passes", async () => {
120
+ const result = await check(await agent("claude", report()), "claude-opus");
121
+ expect(row(result, "harness")).toEqual({ check: "harness", state: "pass" });
122
+ expect(result.ok).toBe(true);
123
+ expect(result.profiles).toHaveLength(1);
124
+ });
125
+
126
+ test("another harness's profile fails, naming both harnesses", async () => {
127
+ const id = await agent("claude", report());
128
+ const result = await check(id, "codex-sol");
129
+ expect(row(result, "harness")?.state).toBe("fail");
130
+ expect(row(result, "harness")?.detail).toContain("codex");
131
+ expect(row(result, "harness")?.detail).toContain("claude");
132
+ expect(result.ok).toBe(false);
133
+ expect(result.profiles[0]?.ok).toBe(false);
134
+ expect(formatProfileCheckFailures(result)).toContain('Model profile "codex-sol" fails harness');
135
+ });
136
+
137
+ test("the harness override judges a PATCH that switches the harness", async () => {
138
+ const id = await agent("claude", report());
139
+ const result = await checkProfileForAgent(id, "codex-sol", { harness: "codex" });
140
+ expect(row(result as ProfileCheckResult, "harness")?.state).toBe("pass");
141
+ // The worker's report is for claude, so it cannot vouch for codex yet.
142
+ expect(row(result as ProfileCheckResult, "harness-credentials")?.state).toBe("unverified");
143
+ });
144
+ });
145
+
146
+ describe("model", () => {
147
+ test("a catalogued claude model passes", async () => {
148
+ const result = await check(await agent("claude", report()), "claude-opus");
149
+ expect(row(result, "model")?.state).toBe("pass");
150
+ });
151
+
152
+ test("a codex model on a claude profile fails", async () => {
153
+ await createModelProfile({ name: "claude-wrong", harness: "claude", model: "gpt-5.6-sol" });
154
+ const result = await check(await agent("claude", report()), "claude-wrong");
155
+ expect(row(result, "model")?.state).toBe("fail");
156
+ expect(result.ok).toBe(false);
157
+ });
158
+
159
+ test("a custom id is unverified", async () => {
160
+ await createModelProfile({
161
+ name: "claude-gateway",
162
+ harness: "claude",
163
+ model: "my-gateway-model",
164
+ allowCustomModel: true,
165
+ });
166
+ const result = await check(await agent("claude", report()), "claude-gateway");
167
+ expect(row(result, "model")).toEqual({
168
+ check: "model",
169
+ state: "unverified",
170
+ detail: "custom model id",
171
+ });
172
+ expect(result.ok).toBe(true);
173
+ });
174
+ });
175
+
176
+ describe("harness-credentials", () => {
177
+ test("a ready worker report passes", async () => {
178
+ const result = await check(await agent("claude", report()), "claude-opus");
179
+ expect(row(result, "harness-credentials")?.state).toBe("pass");
180
+ });
181
+
182
+ test("a report with ready=false fails, listing the missing vars", async () => {
183
+ const id = await agent(
184
+ "claude",
185
+ report({ ready: false, missing: ["CLAUDE_CODE_OAUTH_TOKEN"], satisfiedBy: null }),
186
+ );
187
+ const result = await check(id, "claude-opus");
188
+ expect(row(result, "harness-credentials")).toEqual({
189
+ check: "harness-credentials",
190
+ state: "fail",
191
+ detail: "missing CLAUDE_CODE_OAUTH_TOKEN",
192
+ });
193
+ expect(result.ok).toBe(false);
194
+ });
195
+
196
+ test("no report is unverified", async () => {
197
+ const result = await check(await agent("claude"), "claude-opus");
198
+ expect(row(result, "harness-credentials")).toEqual({
199
+ check: "harness-credentials",
200
+ state: "unverified",
201
+ detail: "worker has not reported",
202
+ });
203
+ expect(result.ok).toBe(true);
204
+ });
205
+
206
+ test("a helmcode model on pi with no HELMCODE_API_KEY anywhere is unverified", async () => {
207
+ await createModelProfile({
208
+ name: "pi-helmcode",
209
+ harness: "pi",
210
+ model: "helmcode/glm5.3",
211
+ allowCustomModel: true,
212
+ });
213
+ const id = await agent("pi", report());
214
+ const result = await check(id, "pi-helmcode");
215
+ expect(row(result, "harness-credentials")?.state).toBe("unverified");
216
+ expect(row(result, "harness-credentials")?.detail).toContain("HELMCODE_API_KEY");
217
+ expect(result.ok).toBe(true);
218
+
219
+ // Control: the key in the agent's config makes it pass.
220
+ await pool(id, "HELMCODE_API_KEY", "hc-secret-value-12345");
221
+ const withKey = await check(id, "pi-helmcode");
222
+ expect(row(withKey, "harness-credentials")?.state).toBe("pass");
223
+ expect(JSON.stringify(withKey)).not.toContain("hc-secret-value-12345");
224
+ });
225
+
226
+ test("an fx model judges its route's key: absent is unverified, configured passes", async () => {
227
+ await createModelProfile({
228
+ name: "fx-vercel",
229
+ harness: "fx",
230
+ model: "vercel/anthropic/claude-sonnet-4.6",
231
+ allowCustomModel: true,
232
+ });
233
+ const id = await agent("fx", report());
234
+ const result = await check(id, "fx-vercel");
235
+ expect(row(result, "harness-credentials")).toEqual({
236
+ check: "harness-credentials",
237
+ state: "unverified",
238
+ detail:
239
+ "vercel/anthropic/claude-sonnet-4.6 needs AI_GATEWAY_API_KEY; not in the agent's config, so only the worker env can supply it",
240
+ });
241
+ expect(result.ok).toBe(true);
242
+
243
+ // Control: another route's key does not satisfy this route.
244
+ await pool(id, "OPENROUTER_API_KEY", "or-secret-value-12345");
245
+ expect(row(await check(id, "fx-vercel"), "harness-credentials")?.state).toBe("unverified");
246
+
247
+ await pool(id, "AI_GATEWAY_API_KEY", "gw-secret-value-12345");
248
+ const withKey = await check(id, "fx-vercel");
249
+ expect(row(withKey, "harness-credentials")).toEqual({
250
+ check: "harness-credentials",
251
+ state: "pass",
252
+ detail: "vercel/anthropic/claude-sonnet-4.6 uses AI_GATEWAY_API_KEY",
253
+ });
254
+ expect(JSON.stringify(withKey)).not.toContain("gw-secret-value-12345");
255
+ });
256
+ });
257
+
258
+ describe("credential-allowlist", () => {
259
+ test("no allowlist means no row", async () => {
260
+ const result = await check(await agent("claude", report()), "claude-opus");
261
+ expect(row(result, "credential-allowlist")).toBeUndefined();
262
+ });
263
+
264
+ test("every listed suffix matched passes", async () => {
265
+ await createModelProfile({
266
+ name: "claude-pinned",
267
+ harness: "claude",
268
+ model: "opus",
269
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["11111", "22222"] },
270
+ });
271
+ const id = await agent("claude", report());
272
+ await pool(id, "CLAUDE_CODE_OAUTH_TOKEN", `${KEY_A},${KEY_B}`);
273
+ const result = await check(id, "claude-pinned");
274
+ expect(row(result, "credential-allowlist")).toEqual({
275
+ check: "credential-allowlist",
276
+ state: "pass",
277
+ });
278
+ expect(result.ok).toBe(true);
279
+ });
280
+
281
+ test("a partial match warns, naming the missing suffix", async () => {
282
+ await createModelProfile({
283
+ name: "claude-partial",
284
+ harness: "claude",
285
+ model: "opus",
286
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["11111", "99999"] },
287
+ });
288
+ const id = await agent("claude", report());
289
+ await pool(id, "CLAUDE_CODE_OAUTH_TOKEN", `${KEY_A},${KEY_B}`);
290
+ const result = await check(id, "claude-partial");
291
+ expect(row(result, "credential-allowlist")?.state).toBe("warn");
292
+ expect(row(result, "credential-allowlist")?.detail).toContain("99999");
293
+ expect(result.ok).toBe(true);
294
+ expect(formatProfileCheckFailures(result)).toBe("");
295
+ });
296
+
297
+ test("no match fails, naming the var", async () => {
298
+ await createModelProfile({
299
+ name: "claude-none",
300
+ harness: "claude",
301
+ model: "opus",
302
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["zzzzz"] },
303
+ });
304
+ const id = await agent("claude", report());
305
+ await pool(id, "CLAUDE_CODE_OAUTH_TOKEN", `${KEY_A},${KEY_B}`);
306
+ const result = await check(id, "claude-none");
307
+ expect(row(result, "credential-allowlist")?.state).toBe("fail");
308
+ expect(result.ok).toBe(false);
309
+ expect(formatProfileCheckFailures(result)).toContain("CLAUDE_CODE_OAUTH_TOKEN");
310
+ });
311
+
312
+ test("env-only: an api_key_status match passes, no match is unverified", async () => {
313
+ await createModelProfile({
314
+ name: "claude-env",
315
+ harness: "claude",
316
+ model: "opus",
317
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["11111"] },
318
+ });
319
+ const id = await agent("claude", report());
320
+ const before = await check(id, "claude-env");
321
+ expect(row(before, "credential-allowlist")?.state).toBe("unverified");
322
+
323
+ await getDbClient().run(
324
+ "INSERT INTO api_key_status (keyType, keySuffix, keyIndex, scope, scopeId) VALUES (?, ?, 0, 'global', '')",
325
+ ["CLAUDE_CODE_OAUTH_TOKEN", "11111"],
326
+ );
327
+ const after = await check(id, "claude-env");
328
+ expect(row(after, "credential-allowlist")?.state).toBe("pass");
329
+
330
+ // Another agent's key usage does not vouch for this one.
331
+ await getDbClient().run("DELETE FROM api_key_status");
332
+ await getDbClient().run(
333
+ "INSERT INTO api_key_status (keyType, keySuffix, keyIndex, scope, scopeId) VALUES (?, ?, 0, 'agent', ?)",
334
+ ["CLAUDE_CODE_OAUTH_TOKEN", "11111", crypto.randomUUID()],
335
+ );
336
+ expect(row(await check(id, "claude-env"), "credential-allowlist")?.state).toBe("unverified");
337
+ });
338
+
339
+ // The worker loads a task's repo-scoped config over the agent's (repo > agent),
340
+ // so a check for that task judges the same pool.
341
+ test("a repo-scoped pool overrides the agent's for a task in that repo", async () => {
342
+ await createModelProfile({
343
+ name: "claude-repo-key",
344
+ harness: "claude",
345
+ model: "opus",
346
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["22222"] },
347
+ });
348
+ const id = await agent("claude", report());
349
+ await pool(id, "CLAUDE_CODE_OAUTH_TOKEN", KEY_A);
350
+ const repo = await createSwarmRepo({ url: "https://github.com/acme/widgets", name: "widgets" });
351
+ await upsertSwarmConfig({
352
+ scope: "repo",
353
+ scopeId: repo.id,
354
+ key: "CLAUDE_CODE_OAUTH_TOKEN",
355
+ value: KEY_B,
356
+ isSecret: true,
357
+ exportToEnv: true,
358
+ });
359
+
360
+ expect((await check(id, "claude-repo-key")).ok).toBe(false);
361
+ const inRepo = await checkProfileForAgent(id, "claude-repo-key", { vcsRepo: "acme/widgets" });
362
+ expect(inRepo?.ok).toBe(true);
363
+ expect(row(inRepo!, "credential-allowlist")?.state).toBe("pass");
364
+ expect(
365
+ await taskProfileError({ profile: "claude-repo-key", agentId: id, vcsRepo: "acme/widgets" }),
366
+ ).toBeNull();
367
+ expect(await taskProfileError({ profile: "claude-repo-key", agentId: id })).toContain(
368
+ "credential-allowlist",
369
+ );
370
+ });
371
+
372
+ test("no output contains a decrypted value", async () => {
373
+ await createModelProfile({
374
+ name: "claude-secret",
375
+ harness: "claude",
376
+ model: "opus",
377
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["11111", "zzzzz"] },
378
+ });
379
+ const id = await agent("claude", report());
380
+ await pool(id, "CLAUDE_CODE_OAUTH_TOKEN", `${KEY_A},${KEY_B}`);
381
+ const result = await check(id, "claude-secret");
382
+ const wire = JSON.stringify(result) + formatProfileCheckFailures(result);
383
+ expect(wire).not.toContain(KEY_A);
384
+ expect(wire).not.toContain(KEY_B);
385
+ expect(wire).not.toContain("secret-material");
386
+ });
387
+ });