@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
@@ -4,24 +4,31 @@
4
4
  import { afterAll, beforeAll, beforeEach, describe, expect, spyOn, test } from "bun:test";
5
5
  import { unlink } from "node:fs/promises";
6
6
  import { createServer, type Server } from "node:http";
7
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
8
+ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
7
9
  import {
8
10
  closeDb,
9
11
  createAgent,
12
+ createScheduledTask,
13
+ createSwarmRepo,
10
14
  createTaskExtended,
11
15
  getDbClient,
12
16
  getTaskById,
13
17
  initDb,
18
+ pauseTask,
14
19
  startTask,
15
20
  supersedeTask,
16
21
  upsertSwarmConfig,
17
22
  } from "../be/db";
18
23
  import * as profilesDb from "../be/db/model-profiles";
19
24
  import { createModelProfile, taskProfileError } from "../be/db/model-profiles";
25
+ import { recordClaimModelResolution } from "../be/model-tier-resolution";
20
26
  import { codeLevelTriage } from "../heartbeat/heartbeat";
21
27
  import { handleAgentsRest } from "../http/agents";
22
28
  import { handleModelProfiles } from "../http/model-profiles";
23
29
  import { handleTasks } from "../http/tasks";
24
30
  import * as followUps from "../tasks/worker-follow-up";
31
+ import { registerSendTaskTool } from "../tools/send-task";
25
32
  import type { User } from "../types";
26
33
  import { setRequestAuth } from "../utils/request-auth-context";
27
34
  import { listenOnFreePort } from "./test-net";
@@ -98,7 +105,10 @@ afterAll(async () => {
98
105
  beforeEach(async () => {
99
106
  // References first: migration 220's triggers refuse deleting a named profile.
100
107
  await getDbClient().run("DELETE FROM agent_tasks");
101
- await getDbClient().run("DELETE FROM swarm_config WHERE key = 'MODEL_PROFILE'");
108
+ await getDbClient().run("DELETE FROM scheduled_tasks");
109
+ await getDbClient().run(
110
+ "DELETE FROM swarm_config WHERE key IN ('MODEL_PROFILE', 'CLAUDE_CODE_OAUTH_TOKEN')",
111
+ );
102
112
  await getDbClient().run("DELETE FROM model_profiles");
103
113
  });
104
114
 
@@ -271,6 +281,317 @@ describe("profile CRUD", () => {
271
281
  expect(inUse.status).toBe(409);
272
282
  expect(((await inUse.json()) as { error: string }).error).toContain("1 agent(s)");
273
283
  });
284
+
285
+ test("a paused task holding an agent default's profile keeps it, so its resume keeps the allowlist", async () => {
286
+ await createModelProfile({
287
+ name: "claude-keyed",
288
+ harness: "claude",
289
+ model: "opus",
290
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["aaaaa"] },
291
+ });
292
+ // Claimed under the agent default: resolvedProfile only, no task.profile.
293
+ const task = await createTaskExtended("work", { agentId: CLAUDE_ID });
294
+ await startTask(task.id);
295
+ await getDbClient().run("UPDATE agent_tasks SET resolvedProfile = ? WHERE id = ?", [
296
+ "claude-keyed",
297
+ task.id,
298
+ ]);
299
+ expect(await pauseTask(task.id)).not.toBeNull();
300
+
301
+ const inUse = await call("DELETE", "/api/model-profiles/claude-keyed", undefined);
302
+ expect(inUse.status).toBe(409);
303
+ expect(((await inUse.json()) as { error: string }).error).toContain("1 unfinished");
304
+ const paused = await call("GET", "/api/paused-tasks", undefined, { "x-agent-id": CLAUDE_ID });
305
+ const { tasks } = (await paused.json()) as {
306
+ tasks: { id: string; credentialAllowlist?: Record<string, string[]> }[];
307
+ };
308
+ expect(tasks.find((t) => t.id === task.id)?.credentialAllowlist).toEqual({
309
+ CLAUDE_CODE_OAUTH_TOKEN: ["aaaaa"],
310
+ });
311
+
312
+ // Control: once the task finishes, the profile is free to go.
313
+ await getDbClient().run("UPDATE agent_tasks SET status = 'completed' WHERE id = ?", [task.id]);
314
+ expect((await call("DELETE", "/api/model-profiles/claude-keyed", undefined)).status).toBe(200);
315
+ });
316
+ });
317
+
318
+ describe("profile credential allowlist", () => {
319
+ const base = { harness: "claude", model: "opus" };
320
+
321
+ test("POST and PATCH round-trip `credentials`; null clears it; duplicates collapse", async () => {
322
+ const created = await call("POST", "/api/model-profiles", {
323
+ ...base,
324
+ name: "claude-pinned",
325
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["abcde", "abcde", "fghij"] },
326
+ });
327
+ expect(created.status).toBe(201);
328
+ expect(((await created.json()) as { credentials: unknown }).credentials).toEqual({
329
+ CLAUDE_CODE_OAUTH_TOKEN: ["abcde", "fghij"],
330
+ });
331
+
332
+ const patched = await call("PATCH", "/api/model-profiles/claude-pinned", {
333
+ credentials: { ANTHROPIC_API_KEY: ["zzzzz"] },
334
+ });
335
+ expect(patched.status).toBe(200);
336
+ const read = await call("GET", "/api/model-profiles/claude-pinned", undefined);
337
+ expect(((await read.json()) as { credentials: unknown }).credentials).toEqual({
338
+ ANTHROPIC_API_KEY: ["zzzzz"],
339
+ });
340
+
341
+ // A PATCH that leaves credentials out keeps them.
342
+ const kept = await call("PATCH", "/api/model-profiles/claude-pinned", { description: "x" });
343
+ expect(((await kept.json()) as { credentials: unknown }).credentials).toEqual({
344
+ ANTHROPIC_API_KEY: ["zzzzz"],
345
+ });
346
+
347
+ const cleared = await call("PATCH", "/api/model-profiles/claude-pinned", {
348
+ credentials: null,
349
+ });
350
+ expect(cleared.status).toBe(200);
351
+ expect(((await cleared.json()) as { credentials: unknown }).credentials).toBeNull();
352
+ const row = await getDbClient().get<{ credentialAllowlist: string | null }>(
353
+ "SELECT credentialAllowlist FROM model_profiles WHERE name = 'claude-pinned'",
354
+ );
355
+ expect(row?.credentialAllowlist).toBeNull();
356
+ });
357
+
358
+ test("an unknown var, a CODEX_OAUTH var, an empty list or a bad suffix is 400", async () => {
359
+ const unknownVar = await call("POST", "/api/model-profiles", {
360
+ ...base,
361
+ name: "claude-bad-var",
362
+ credentials: { OPENAI_API_KEY: ["abcde"] },
363
+ });
364
+ expect(unknownVar.status).toBe(400);
365
+ expect(((await unknownVar.json()) as { error: string }).error).toContain("OPENAI_API_KEY");
366
+
367
+ const codexOauth = await call("POST", "/api/model-profiles", {
368
+ harness: "codex",
369
+ model: "gpt-5.6-sol",
370
+ name: "codex-oauth-pinned",
371
+ credentials: { CODEX_OAUTH: ["abcde"] },
372
+ });
373
+ expect(codexOauth.status).toBe(400);
374
+ expect(((await codexOauth.json()) as { error: string }).error).toContain("not supported in v1");
375
+
376
+ const empty = await call("POST", "/api/model-profiles", {
377
+ ...base,
378
+ name: "claude-empty",
379
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: [] },
380
+ });
381
+ expect(empty.status).toBe(400);
382
+
383
+ const longSuffix = await call("POST", "/api/model-profiles", {
384
+ ...base,
385
+ name: "claude-long",
386
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["abcdef"] },
387
+ });
388
+ expect(longSuffix.status).toBe(400);
389
+
390
+ await createModelProfile({ ...base, name: "claude-plain", harness: "claude" });
391
+ const patchBad = await call("PATCH", "/api/model-profiles/claude-plain", {
392
+ credentials: { CODEX_OAUTH: ["abcde"] },
393
+ });
394
+ expect(patchBad.status).toBe(400);
395
+ });
396
+
397
+ test("a model-prefixed key var is accepted on harnesses that pick the key by model", async () => {
398
+ const helm = await call("POST", "/api/model-profiles", {
399
+ harness: "pi",
400
+ model: "helmcode/deepseek-v4-flash",
401
+ name: "pi-helm-pinned",
402
+ credentials: { HELMCODE_API_KEY: ["abcde"] },
403
+ });
404
+ expect(helm.status).toBe(201);
405
+ });
406
+
407
+ test("a var the harness never loads for this model is 400, though the harness loads it for others", async () => {
408
+ // pi drops OPENAI_API_KEY for a slash-qualified model (`getModelAwareCredentialVars`).
409
+ const slash = {
410
+ harness: "pi",
411
+ model: "openrouter/google/gemini-3-flash-preview",
412
+ allowCustomModel: true,
413
+ };
414
+ const openai = await call("POST", "/api/model-profiles", {
415
+ ...slash,
416
+ name: "pi-slash-openai",
417
+ credentials: { OPENAI_API_KEY: ["abcde"] },
418
+ });
419
+ expect(openai.status).toBe(400);
420
+ expect(((await openai.json()) as { error: string }).error).toContain("OPENAI_API_KEY");
421
+
422
+ // Controls: a var this model loads, and the same var on a model that loads it.
423
+ expect(
424
+ (
425
+ await call("POST", "/api/model-profiles", {
426
+ ...slash,
427
+ name: "pi-slash-openrouter",
428
+ credentials: { OPENROUTER_API_KEY: ["abcde"] },
429
+ })
430
+ ).status,
431
+ ).toBe(201);
432
+ expect(
433
+ (
434
+ await call("POST", "/api/model-profiles", {
435
+ harness: "pi",
436
+ model: "gpt-5.6-sol",
437
+ allowCustomModel: true,
438
+ name: "pi-bare-openai",
439
+ credentials: { OPENAI_API_KEY: ["abcde"] },
440
+ })
441
+ ).status,
442
+ ).toBe(201);
443
+ });
444
+
445
+ // A stored allowlist reads back as null when unreadable, and null means the
446
+ // whole pool. Every dispatch path must refuse the profile instead.
447
+ for (const [label, stored] of [
448
+ ["malformed JSON", "{not json"],
449
+ ["schema-invalid JSON", '{"CLAUDE_CODE_OAUTH_TOKEN":[]}'],
450
+ ["empty string", ""],
451
+ ]) {
452
+ test(`an unreadable stored allowlist (${label}) fails closed; list endpoints still render it`, async () => {
453
+ await createModelProfile({
454
+ name: "claude-corrupt",
455
+ harness: "claude",
456
+ model: "opus",
457
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["aaaaa"] },
458
+ });
459
+ await getDbClient().run(
460
+ "UPDATE model_profiles SET credentialAllowlist = ? WHERE name = 'claude-corrupt'",
461
+ [stored],
462
+ );
463
+
464
+ const list = await call("GET", "/api/model-profiles", undefined);
465
+ expect(list.status).toBe(200);
466
+ const { profiles } = (await list.json()) as {
467
+ profiles: { name: string; credentials: unknown }[];
468
+ };
469
+ expect(profiles.find((p) => p.name === "claude-corrupt")?.credentials).toBeNull();
470
+ expect((await call("GET", "/api/model-profiles/claude-corrupt", undefined)).status).toBe(200);
471
+
472
+ // Creation gate: the check fails the allowlist row.
473
+ expect(await taskProfileError({ profile: "claude-corrupt", agentId: CLAUDE_ID })).toContain(
474
+ "unreadable",
475
+ );
476
+
477
+ // Claim: a task's own profile and an agent default both stop, with no allowlist.
478
+ const own = await createTaskExtended("own", { agentId: CLAUDE_ID });
479
+ const ownFields = await recordClaimModelResolution(
480
+ { id: own.id, profile: "claude-corrupt" },
481
+ { id: CLAUDE_ID, harnessProvider: "claude" },
482
+ );
483
+ expect(ownFields.modelUnsupported).toContain("[model-profile-allowlist-unreadable]");
484
+ expect(ownFields.credentialAllowlist).toBeUndefined();
485
+ await upsertSwarmConfig({
486
+ scope: "agent",
487
+ scopeId: CLAUDE_ID,
488
+ key: "MODEL_PROFILE",
489
+ value: "claude-corrupt",
490
+ exportToEnv: false,
491
+ });
492
+ const byDefault = await createTaskExtended("default", { agentId: CLAUDE_ID });
493
+ const defaultFields = await recordClaimModelResolution(
494
+ { id: byDefault.id },
495
+ { id: CLAUDE_ID, harnessProvider: "claude" },
496
+ );
497
+ expect(defaultFields.modelUnsupported).toContain("[model-profile-allowlist-unreadable]");
498
+ expect(defaultFields.credentialAllowlist).toBeUndefined();
499
+
500
+ // Resume: a paused task holding the profile stays paused.
501
+ await startTask(byDefault.id);
502
+ await getDbClient().run("UPDATE agent_tasks SET resolvedProfile = ? WHERE id = ?", [
503
+ "claude-corrupt",
504
+ byDefault.id,
505
+ ]);
506
+ expect(await pauseTask(byDefault.id)).not.toBeNull();
507
+ const pausedIds = async () => {
508
+ const res = await call("GET", "/api/paused-tasks", undefined, { "x-agent-id": CLAUDE_ID });
509
+ const body = (await res.json()) as {
510
+ tasks: { id: string; credentialAllowlist?: Record<string, string[]> }[];
511
+ };
512
+ return body.tasks;
513
+ };
514
+ const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
515
+ try {
516
+ expect((await pausedIds()).map((t) => t.id)).not.toContain(byDefault.id);
517
+ } finally {
518
+ warnSpy.mockRestore();
519
+ }
520
+
521
+ // Control: setting the credentials again restores every path.
522
+ const fixed = await call("PATCH", "/api/model-profiles/claude-corrupt", {
523
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["aaaaa"] },
524
+ });
525
+ expect(fixed.status).toBe(200);
526
+ expect((await pausedIds()).find((t) => t.id === byDefault.id)?.credentialAllowlist).toEqual({
527
+ CLAUDE_CODE_OAUTH_TOKEN: ["aaaaa"],
528
+ });
529
+ const again = await createTaskExtended("again", { agentId: CLAUDE_ID });
530
+ const againFields = await recordClaimModelResolution(
531
+ { id: again.id, profile: "claude-corrupt" },
532
+ { id: CLAUDE_ID, harnessProvider: "claude" },
533
+ );
534
+ expect(againFields.modelUnsupported).toBeUndefined();
535
+ expect(againFields.credentialAllowlist).toEqual({ CLAUDE_CODE_OAUTH_TOKEN: ["aaaaa"] });
536
+ });
537
+ }
538
+ });
539
+
540
+ describe("schedule profile references", () => {
541
+ test("a profile named by a schedule cannot be deleted; the 409 names the schedule", async () => {
542
+ await createModelProfile({ name: "claude-sched", harness: "claude", model: "opus" });
543
+ const schedule = await createScheduledTask({
544
+ name: "profile-sched",
545
+ cronExpression: "0 * * * *",
546
+ taskTemplate: "x",
547
+ profile: "claude-sched",
548
+ });
549
+ expect(schedule.profile).toBe("claude-sched");
550
+
551
+ const inUse = await call("DELETE", "/api/model-profiles/claude-sched", undefined);
552
+ expect(inUse.status).toBe(409);
553
+ const { error } = (await inUse.json()) as { error: string };
554
+ expect(error).toContain("1 schedule(s)");
555
+ expect(error).toContain(schedule.id);
556
+
557
+ // The statement-level guard holds even past the reference count.
558
+ expect(await profilesDb.deleteModelProfile("claude-sched")).toBe("in-use");
559
+
560
+ await getDbClient().run("UPDATE scheduled_tasks SET profile = NULL WHERE id = ?", [
561
+ schedule.id,
562
+ ]);
563
+ expect((await call("DELETE", "/api/model-profiles/claude-sched", undefined)).status).toBe(200);
564
+ });
565
+
566
+ test("a schedule naming a missing profile is refused by the trigger, on insert and update", async () => {
567
+ let insertError: unknown;
568
+ try {
569
+ await createScheduledTask({
570
+ name: "ghost-sched",
571
+ cronExpression: "0 * * * *",
572
+ taskTemplate: "x",
573
+ profile: "no-such-profile",
574
+ });
575
+ } catch (error) {
576
+ insertError = error;
577
+ }
578
+ expect(profilesDb.modelProfileRefError(insertError)).toBe("missing");
579
+
580
+ const schedule = await createScheduledTask({
581
+ name: "plain-sched",
582
+ cronExpression: "0 * * * *",
583
+ taskTemplate: "x",
584
+ });
585
+ let updateError: unknown;
586
+ try {
587
+ await getDbClient().run("UPDATE scheduled_tasks SET profile = 'nope' WHERE id = ?", [
588
+ schedule.id,
589
+ ]);
590
+ } catch (error) {
591
+ updateError = error;
592
+ }
593
+ expect(profilesDb.modelProfileRefError(updateError)).toBe("missing");
594
+ });
274
595
  });
275
596
 
276
597
  describe("profile references and deletion are atomic", () => {
@@ -471,6 +792,7 @@ describe("a superseded task holds its profile until its resume exists", () => {
471
792
  expect(await profilesDb.modelProfileReferences("claude-handoff")).toEqual({
472
793
  agentIds: [],
473
794
  openTaskCount: 0,
795
+ scheduleIds: [],
474
796
  });
475
797
  expect(await profilesDb.deleteModelProfile("claude-handoff")).toBe("deleted");
476
798
 
@@ -587,6 +909,211 @@ describe("agent default via PATCH /api/agents/{id}/runtime", () => {
587
909
  });
588
910
  });
589
911
 
912
+ describe("the profile check gates the agent default and task creation", () => {
913
+ // CLAUDE_ID's pooled key ends 11111. The worker has not reported, so the
914
+ // harness-credentials row is unverified and only the allowlist decides.
915
+ async function poolOneKey(): Promise<void> {
916
+ await upsertSwarmConfig({
917
+ scope: "agent",
918
+ scopeId: CLAUDE_ID,
919
+ key: "CLAUDE_CODE_OAUTH_TOKEN",
920
+ value: "sk-ant-oat01-pooled-key-11111",
921
+ exportToEnv: true,
922
+ });
923
+ }
924
+
925
+ test("PATCH runtime with an allowlist no pooled key matches is 400 naming the var", async () => {
926
+ await poolOneKey();
927
+ await createModelProfile({
928
+ name: "claude-no-key",
929
+ harness: "claude",
930
+ model: "opus",
931
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["zzzzz"] },
932
+ });
933
+ const res = await call("PATCH", `/api/agents/${CLAUDE_ID}/runtime`, {
934
+ harness_provider: "claude",
935
+ profile: "claude-no-key",
936
+ });
937
+ expect(res.status).toBe(400);
938
+ const body = (await res.json()) as { error: string; check: { ok: boolean } };
939
+ expect(body.error).toContain("credential-allowlist");
940
+ expect(body.error).toContain("CLAUDE_CODE_OAUTH_TOKEN");
941
+ expect(body.error).not.toContain("pooled-key");
942
+ expect(body.check.ok).toBe(false);
943
+ expect(await modelProfileConfig(CLAUDE_ID)).toBeNull();
944
+ });
945
+
946
+ test("PATCH runtime with a warn-only profile is 200 and returns profileCheck", async () => {
947
+ await poolOneKey();
948
+ await createModelProfile({
949
+ name: "claude-some-keys",
950
+ harness: "claude",
951
+ model: "opus",
952
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["11111", "zzzzz"] },
953
+ });
954
+ const res = await call("PATCH", `/api/agents/${CLAUDE_ID}/runtime`, {
955
+ harness_provider: "claude",
956
+ profile: "claude-some-keys",
957
+ });
958
+ expect(res.status).toBe(200);
959
+ const body = (await res.json()) as {
960
+ id: string;
961
+ profileCheck: { ok: boolean; profiles: { checks: { check: string; state: string }[] }[] };
962
+ };
963
+ expect(body.id).toBe(CLAUDE_ID);
964
+ expect(body.profileCheck.ok).toBe(true);
965
+ expect(body.profileCheck.profiles[0]?.checks).toContainEqual(
966
+ expect.objectContaining({ check: "credential-allowlist", state: "warn" }),
967
+ );
968
+ expect(await modelProfileConfig(CLAUDE_ID)).toEqual({
969
+ value: "claude-some-keys",
970
+ exportToEnv: 0,
971
+ });
972
+ });
973
+
974
+ test("send-task to an agent that fails the check is a tool error listing the failing rows", async () => {
975
+ await poolOneKey();
976
+ await createModelProfile({
977
+ name: "claude-no-key",
978
+ harness: "claude",
979
+ model: "gpt-5.6-sol",
980
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["zzzzz"] },
981
+ });
982
+ const mcp = new McpServer({ name: "test-model-profiles-send-task", version: "1.0.0" });
983
+ registerSendTaskTool(mcp);
984
+ const tool = (
985
+ mcp as unknown as {
986
+ _registeredTools: Record<
987
+ string,
988
+ { handler: (args: unknown, extra: unknown) => Promise<CallToolResult> }
989
+ >;
990
+ }
991
+ )._registeredTools["send-task"];
992
+ const result = await tool!.handler(
993
+ {
994
+ task: "profile work",
995
+ agentId: CLAUDE_ID,
996
+ routingReason: "human_pinned",
997
+ routingNote: "This test pins the target",
998
+ profile: "claude-no-key",
999
+ allowDuplicate: true,
1000
+ },
1001
+ { sessionId: "test-session", requestInfo: { headers: { "x-agent-id": LEAD_ID } } },
1002
+ );
1003
+ expect(result.isError).toBe(true);
1004
+ const text = (result.content as { type: string; text: string }[])
1005
+ .map((part) => part.text)
1006
+ .join("\n");
1007
+ expect(text).toContain('Model profile "claude-no-key" fails model');
1008
+ expect(text).toContain('Model profile "claude-no-key" fails credential-allowlist');
1009
+ expect(text).toContain("CLAUDE_CODE_OAUTH_TOKEN");
1010
+ expect(
1011
+ await getDbClient().get("SELECT id FROM agent_tasks WHERE profile = 'claude-no-key'"),
1012
+ ).toBeNull();
1013
+ });
1014
+ });
1015
+
1016
+ describe("a child judges the profile on the repo it inherits from its parent", () => {
1017
+ // CLAUDE_ID's own key ends 11111; the parent's repo pools 22222, the only key
1018
+ // the profile allows. createTaskExtended gives the child the parent's repo.
1019
+ async function parents(): Promise<{ inRepo: string; bare: string }> {
1020
+ await getDbClient().run("DELETE FROM swarm_repos");
1021
+ await upsertSwarmConfig({
1022
+ scope: "agent",
1023
+ scopeId: CLAUDE_ID,
1024
+ key: "CLAUDE_CODE_OAUTH_TOKEN",
1025
+ value: "sk-ant-oat01-agent-key-11111",
1026
+ exportToEnv: true,
1027
+ });
1028
+ const repo = await createSwarmRepo({ url: "https://github.com/acme/widgets", name: "widgets" });
1029
+ await upsertSwarmConfig({
1030
+ scope: "repo",
1031
+ scopeId: repo.id,
1032
+ key: "CLAUDE_CODE_OAUTH_TOKEN",
1033
+ value: "sk-ant-oat01-repo-key-22222",
1034
+ exportToEnv: true,
1035
+ });
1036
+ await createModelProfile({
1037
+ name: "claude-repo-key",
1038
+ harness: "claude",
1039
+ model: "opus",
1040
+ credentials: { CLAUDE_CODE_OAUTH_TOKEN: ["22222"] },
1041
+ });
1042
+ const inRepo = await createTaskExtended("parent", {
1043
+ agentId: LEAD_ID,
1044
+ creatorAgentId: LEAD_ID,
1045
+ vcsRepo: "acme/widgets",
1046
+ });
1047
+ const bare = await createTaskExtended("parent", { agentId: LEAD_ID, creatorAgentId: LEAD_ID });
1048
+ return { inRepo: inRepo.id, bare: bare.id };
1049
+ }
1050
+
1051
+ test("POST /api/tasks", async () => {
1052
+ const { inRepo, bare } = await parents();
1053
+ const child = (parentTaskId: string) =>
1054
+ call("POST", "/api/tasks", {
1055
+ task: "child work",
1056
+ agentId: CLAUDE_ID,
1057
+ routingReason: "continuity",
1058
+ parentTaskId,
1059
+ profile: "claude-repo-key",
1060
+ });
1061
+
1062
+ const ok = await child(inRepo);
1063
+ expect(ok.status).toBe(201);
1064
+ const { id } = (await ok.json()) as { id: string };
1065
+ expect(await getTaskById(id)).toMatchObject({
1066
+ vcsRepo: "acme/widgets",
1067
+ profile: "claude-repo-key",
1068
+ });
1069
+ // Control: a parent without a repo leaves the agent's own key, which fails.
1070
+ const refused = await child(bare);
1071
+ expect(refused.status).toBe(400);
1072
+ expect(((await refused.json()) as { error: string }).error).toContain("credential-allowlist");
1073
+ });
1074
+
1075
+ test("send-task", async () => {
1076
+ const { inRepo, bare } = await parents();
1077
+ const mcp = new McpServer({ name: "test-model-profiles-inherited-repo", version: "1.0.0" });
1078
+ registerSendTaskTool(mcp);
1079
+ const tool = (
1080
+ mcp as unknown as {
1081
+ _registeredTools: Record<
1082
+ string,
1083
+ { handler: (args: unknown, extra: unknown) => Promise<CallToolResult> }
1084
+ >;
1085
+ }
1086
+ )._registeredTools["send-task"];
1087
+ const child = (parentTaskId: string) =>
1088
+ tool!.handler(
1089
+ {
1090
+ task: "child work",
1091
+ agentId: CLAUDE_ID,
1092
+ routingReason: "human_pinned",
1093
+ routingNote: "This test pins the target",
1094
+ parentTaskId,
1095
+ profile: "claude-repo-key",
1096
+ allowDuplicate: true,
1097
+ },
1098
+ { sessionId: "test-session", requestInfo: { headers: { "x-agent-id": LEAD_ID } } },
1099
+ );
1100
+
1101
+ const ok = await child(inRepo);
1102
+ expect(ok.isError).toBeFalsy();
1103
+ expect(
1104
+ await getDbClient().get(
1105
+ "SELECT vcsRepo FROM agent_tasks WHERE parentTaskId = ? AND profile = 'claude-repo-key'",
1106
+ [inRepo],
1107
+ ),
1108
+ ).toEqual({ vcsRepo: "acme/widgets" });
1109
+ const refused = await child(bare);
1110
+ expect(refused.isError).toBe(true);
1111
+ expect(
1112
+ (refused.content as { type: string; text: string }[]).map((part) => part.text).join("\n"),
1113
+ ).toContain("credential-allowlist");
1114
+ });
1115
+ });
1116
+
590
1117
  describe("task creation with a profile", () => {
591
1118
  test("POST /api/tasks stores the profile; another harness's profile is 400", async () => {
592
1119
  await createModelProfile({ name: "claude-opus", harness: "claude", model: "opus" });