@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
@@ -0,0 +1,284 @@
1
+ /**
2
+ * Whether an agent can run a model profile (runbooks/model-tiers.md § Model
3
+ * profiles). The one judge every profile gate calls: the runtime PATCH, task
4
+ * creation, schedules, workflows and the pooled claim format its failing rows.
5
+ *
6
+ * Read-only. Each check row is `pass`, `warn`, `fail` or `unverified`; only a
7
+ * `fail` on the primary profile makes the result not ok. No secret value ever
8
+ * reaches a row's `detail`: rows name vars and 5-character key suffixes only.
9
+ */
10
+ import { harnessModelMismatch, isAlias, isHarnessModelJudged } from "@desplega/model-catalog";
11
+ import { can } from "../rbac";
12
+ import type {
13
+ Agent,
14
+ ModelProfile,
15
+ ProfileCheckResult,
16
+ ProfileCheckRow,
17
+ ProfileCheckState,
18
+ } from "../types";
19
+ import { getModelAwareCredentialVars, keySuffix, splitCredentialPool } from "../utils/credentials";
20
+ import { runtimeHarnessSections } from "../utils/runtime-model-catalog";
21
+ import { vcsRepoName, vcsRepoUrlMatches } from "../utils/vcs-repo-match";
22
+ import { getAgentById, getDbClient, getResolvedConfig } from "./db";
23
+ import { getModelProfileByName, hasUnreadableCredentialAllowlist } from "./db/model-profiles";
24
+ import { isKnownCatalogModel } from "./model-validation";
25
+
26
+ /** Harnesses whose credential var depends on the model prefix (`getModelAwareCredentialVars`). */
27
+ const MODEL_AWARE_CREDENTIAL_HARNESSES = new Set(["pi", "opencode", "dsh", "grok", "fx"]);
28
+
29
+ const STATE_RANK: Record<ProfileCheckState, number> = { pass: 0, unverified: 1, warn: 2, fail: 3 };
30
+
31
+ function worst(states: ProfileCheckState[]): ProfileCheckState {
32
+ return states.reduce<ProfileCheckState>(
33
+ (acc, state) => (STATE_RANK[state] > STATE_RANK[acc] ? state : acc),
34
+ "pass",
35
+ );
36
+ }
37
+
38
+ export interface ProfileCheckOptions {
39
+ /**
40
+ * Judge against this harness instead of the agent's current one (a runtime
41
+ * PATCH that also switches the harness). The worker's credential report is
42
+ * then for the old harness, so that row is `unverified`.
43
+ */
44
+ harness?: string | null;
45
+ /**
46
+ * The task's `vcsRepo`. The worker loads that repo's scoped config over the
47
+ * agent's (repo > agent), so the check judges the same pool.
48
+ */
49
+ vcsRepo?: string | null;
50
+ /** Whether the worker's config read includes secret repo rows (`readsRepoSecrets`). */
51
+ includeRepoSecrets?: boolean;
52
+ }
53
+
54
+ /**
55
+ * Whether a runtime-token agent's config read includes secret repo rows: only
56
+ * with `config.read.secrets`. Other callers always get them.
57
+ */
58
+ export function runtimeReadsRepoSecrets(agent: { id: string; isLead?: boolean }): boolean {
59
+ return can({
60
+ principal: { kind: "agent", agentId: agent.id, isLead: agent.isLead ?? false },
61
+ verb: "config.read.secrets",
62
+ resource: { kind: "none" },
63
+ source: "http",
64
+ }).allow;
65
+ }
66
+
67
+ /**
68
+ * The `swarm_repos` id `vcsRepo` names, matched as the worker's
69
+ * `fetchRepoConfig` matches it. Null when no registered repo matches.
70
+ */
71
+ export async function vcsRepoId(vcsRepo: string | null | undefined): Promise<string | null> {
72
+ if (!vcsRepo?.trim()) return null;
73
+ const repos = await getDbClient().query<{ id: string; url: string }>(
74
+ "SELECT id, url FROM swarm_repos WHERE name = ? ORDER BY name ASC",
75
+ [vcsRepoName(vcsRepo)],
76
+ );
77
+ return repos.find((r) => vcsRepoUrlMatches(r.url, vcsRepo))?.id ?? null;
78
+ }
79
+
80
+ /** Pooled credential values the worker would get, by var: exported config rows only. */
81
+ async function configPools(
82
+ agentId: string,
83
+ { vcsRepo, includeRepoSecrets = true }: ProfileCheckOptions,
84
+ ): Promise<Map<string, string>> {
85
+ const pools = new Map<string, string>();
86
+ const repoId = (await vcsRepoId(vcsRepo)) ?? undefined;
87
+ for (const row of await getResolvedConfig(agentId, repoId, { includeRepoSecrets })) {
88
+ if (row.exportToEnv && row.value.trim()) pools.set(row.key, row.value);
89
+ }
90
+ return pools;
91
+ }
92
+
93
+ function harnessRow(profile: ModelProfile, harness: string | null): ProfileCheckRow {
94
+ if (!harness) {
95
+ return { check: "harness", state: "unverified", detail: "the agent has no harness yet" };
96
+ }
97
+ if (profile.harness === harness) return { check: "harness", state: "pass" };
98
+ return {
99
+ check: "harness",
100
+ state: "fail",
101
+ detail: `profile runs on the ${profile.harness} harness; the agent runs ${harness}`,
102
+ };
103
+ }
104
+
105
+ function modelRow(profile: ModelProfile, harness: string | null): ProfileCheckRow {
106
+ const judgeHarness = harness ?? profile.harness;
107
+ const sections = runtimeHarnessSections();
108
+ const mismatch = harnessModelMismatch(profile.model, judgeHarness, sections);
109
+ if (mismatch) return { check: "model", state: "fail", detail: mismatch };
110
+ if (!isHarnessModelJudged(judgeHarness)) {
111
+ return {
112
+ check: "model",
113
+ state: "unverified",
114
+ detail: `the model catalog does not judge ${judgeHarness} models`,
115
+ };
116
+ }
117
+ if (
118
+ profile.allowCustomModel &&
119
+ !isAlias(profile.model) &&
120
+ !isKnownCatalogModel(profile.model, sections)
121
+ ) {
122
+ return { check: "model", state: "unverified", detail: "custom model id" };
123
+ }
124
+ return { check: "model", state: "pass" };
125
+ }
126
+
127
+ function harnessCredentialsRow(
128
+ agent: Agent,
129
+ profile: ModelProfile,
130
+ harness: string | null,
131
+ agentHarness: string | null,
132
+ pools: Map<string, string>,
133
+ ): ProfileCheckRow {
134
+ const report = agent.credStatus ?? null;
135
+ const missing = [...new Set([...(report?.missing ?? []), ...(agent.credentialMissing ?? [])])];
136
+ if (harness && agentHarness && harness !== agentHarness) {
137
+ return {
138
+ check: "harness-credentials",
139
+ state: "unverified",
140
+ detail: `the worker's credential report is for ${agentHarness}, not ${harness}`,
141
+ };
142
+ }
143
+ if (report?.ready === false || (!report && missing.length > 0)) {
144
+ return {
145
+ check: "harness-credentials",
146
+ state: "fail",
147
+ detail: missing.length > 0 ? `missing ${missing.join(", ")}` : "worker reports not ready",
148
+ };
149
+ }
150
+ if (!report) {
151
+ return {
152
+ check: "harness-credentials",
153
+ state: "unverified",
154
+ detail: "worker has not reported",
155
+ };
156
+ }
157
+ // The key this model needs may differ from the one the worker checked
158
+ // (helmcode/<id> on pi needs HELMCODE_API_KEY). The worker's container env
159
+ // may still supply it, so absent from config is unverified, not fail.
160
+ const judgeHarness = harness ?? profile.harness;
161
+ if (MODEL_AWARE_CREDENTIAL_HARNESSES.has(judgeHarness)) {
162
+ const vars = getModelAwareCredentialVars(judgeHarness, profile.model);
163
+ const named = vars.join(" or ");
164
+ if (!vars.some((v) => pools.has(v))) {
165
+ return {
166
+ check: "harness-credentials",
167
+ state: "unverified",
168
+ detail: `${profile.model} needs ${named}; not in the agent's config, so only the worker env can supply it`,
169
+ };
170
+ }
171
+ return {
172
+ check: "harness-credentials",
173
+ state: "pass",
174
+ detail: `${profile.model} uses ${named}`,
175
+ };
176
+ }
177
+ return { check: "harness-credentials", state: "pass" };
178
+ }
179
+
180
+ /** Whether `api_key_status` has seen any of `suffixes` for `keyType`, at agent or global scope. */
181
+ async function keyStatusHasSuffix(
182
+ agentId: string,
183
+ keyType: string,
184
+ suffixes: string[],
185
+ ): Promise<boolean> {
186
+ const row = await getDbClient().get<{ n: number }>(
187
+ `SELECT COUNT(*) AS n FROM api_key_status
188
+ WHERE keyType = ?
189
+ AND keySuffix IN (${suffixes.map(() => "?").join(", ")})
190
+ AND ((scope = 'agent' AND scopeId = ?) OR scope = 'global')`,
191
+ [keyType, ...suffixes, agentId],
192
+ );
193
+ return (row?.n ?? 0) > 0;
194
+ }
195
+
196
+ async function credentialAllowlistRow(
197
+ agentId: string,
198
+ allowlist: Record<string, string[]>,
199
+ pools: Map<string, string>,
200
+ ): Promise<ProfileCheckRow> {
201
+ const states: ProfileCheckState[] = [];
202
+ const details: string[] = [];
203
+ for (const [envVar, wanted] of Object.entries(allowlist)) {
204
+ const pool = pools.get(envVar);
205
+ if (pool === undefined) {
206
+ // Not in config: the worker env supplies it. Fall back to the key usage
207
+ // the workers have reported.
208
+ if (await keyStatusHasSuffix(agentId, envVar, wanted)) {
209
+ states.push("pass");
210
+ } else {
211
+ states.push("unverified");
212
+ details.push(`${envVar} is not in the agent's config and no worker reported a listed key`);
213
+ }
214
+ continue;
215
+ }
216
+ const have = new Set(splitCredentialPool(pool).map(keySuffix));
217
+ const absent = wanted.filter((suffix) => !have.has(suffix));
218
+ if (absent.length === wanted.length) {
219
+ states.push("fail");
220
+ details.push(`no ${envVar} key matches the allowlist (wanted ${wanted.join(", ")})`);
221
+ } else if (absent.length > 0) {
222
+ states.push("warn");
223
+ details.push(`${envVar} has no key ending ${absent.join(", ")}`);
224
+ } else {
225
+ states.push("pass");
226
+ }
227
+ }
228
+ return {
229
+ check: "credential-allowlist",
230
+ state: worst(states),
231
+ ...(details.length > 0 ? { detail: details.join("; ") } : {}),
232
+ };
233
+ }
234
+
235
+ /**
236
+ * Judge whether `agentId` can run `profileName`. Null when the agent or the
237
+ * profile does not exist. PR 2 has no fallbacks, so `profiles` holds the
238
+ * primary only.
239
+ */
240
+ export async function checkProfileForAgent(
241
+ agentId: string,
242
+ profileName: string,
243
+ options: ProfileCheckOptions = {},
244
+ ): Promise<ProfileCheckResult | null> {
245
+ const [agent, profile] = await Promise.all([
246
+ getAgentById(agentId),
247
+ getModelProfileByName(profileName),
248
+ ]);
249
+ if (!agent || !profile) return null;
250
+ const agentHarness = agent.harnessProvider ?? agent.provider ?? null;
251
+ const harness = options.harness === undefined ? agentHarness : options.harness;
252
+ const pools = await configPools(agentId, options);
253
+
254
+ const checks: ProfileCheckRow[] = [
255
+ harnessRow(profile, harness),
256
+ modelRow(profile, harness),
257
+ harnessCredentialsRow(agent, profile, harness, agentHarness, pools),
258
+ ];
259
+ if (hasUnreadableCredentialAllowlist(profile)) {
260
+ // Null credentials here would read as the whole pool; fail closed instead.
261
+ checks.push({
262
+ check: "credential-allowlist",
263
+ state: "fail",
264
+ detail: "the stored credential allowlist is unreadable; set the profile's credentials again",
265
+ });
266
+ } else if (profile.credentials) {
267
+ checks.push(await credentialAllowlistRow(agentId, profile.credentials, pools));
268
+ }
269
+ const ok = !checks.some((row) => row.state === "fail");
270
+ return { agentId, ok, profiles: [{ name: profile.name, ok, checks }] };
271
+ }
272
+
273
+ /** One line per failing row of the primary profile, for a gate's error message. */
274
+ export function formatProfileCheckFailures(result: ProfileCheckResult): string {
275
+ const primary = result.profiles[0];
276
+ if (!primary) return "";
277
+ return primary.checks
278
+ .filter((row) => row.state === "fail")
279
+ .map(
280
+ (row) =>
281
+ `Model profile "${primary.name}" fails ${row.check}${row.detail ? `: ${row.detail}` : ""}`,
282
+ )
283
+ .join("\n");
284
+ }
@@ -10,7 +10,9 @@
10
10
  * 2. task `profile` → "profile:task"
11
11
  * 3. the claiming worker's MODEL_TIER_* → "worker-env" (agents.modelTierOverrides)
12
12
  * 4. swarm_config MODEL_TIER_<PROV>_<TIER> → "tier-config"
13
- * 5. DEFAULT_MODEL_TIER_MAP → "tier-default"
13
+ * 5. DEFAULT_MODEL_TIER_MAP → "tier-default", or "profile:tier-alias" when the
14
+ * seeded `<harness>-<tier>` profile exists (its model, same as the map unless edited).
15
+ * A worker-env or tier-config win logs a deprecation line: edit the profile instead.
14
16
  * 6. the agent's default profile → "profile:agent-default" (no model, no tier,
15
17
  * no repo-scoped MODEL_OVERRIDE on the task's repo)
16
18
  *
@@ -43,6 +45,7 @@ import { z } from "zod";
43
45
  import {
44
46
  DEFAULT_MODEL_TIER_MAP,
45
47
  MODEL_TIERS,
48
+ type ModelProfileCredentials,
46
49
  type ModelTier,
47
50
  type ModelTierOverrides,
48
51
  type ProviderName,
@@ -54,6 +57,7 @@ import { getDbClient } from "./db";
54
57
  import {
55
58
  getAgentDefaultProfileName,
56
59
  getModelProfileByName,
60
+ hasUnreadableCredentialAllowlist,
57
61
  repoModelOverrideKeys,
58
62
  } from "./db/model-profiles";
59
63
  import {
@@ -85,7 +89,8 @@ export type ModelSource =
85
89
  | "fallback:cli-unsupported"
86
90
  | "fallback:cli-unsupported:model"
87
91
  | "profile:task"
88
- | "profile:agent-default";
92
+ | "profile:agent-default"
93
+ | "profile:tier-alias";
89
94
 
90
95
  export interface TaskModelResolution {
91
96
  resolvedModel: string;
@@ -516,6 +521,11 @@ export type ClaimModelFields = Partial<TaskModelResolution> & {
516
521
  resolvedProfile?: string;
517
522
  /** The profile's effort, when it has one and the task set none; the worker spawns with it. */
518
523
  effort?: ReasoningEffort;
524
+ /**
525
+ * The applied profile's pooled-key allowlist (`{ VAR: [suffix] }`). Trigger only, never
526
+ * stored on the task: a re-claim re-resolves it. The worker picks keys within it.
527
+ */
528
+ credentialAllowlist?: ModelProfileCredentials;
519
529
  /**
520
530
  * Set when the task's explicit model is rejected by this worker's CLI, or belongs to another
521
531
  * harness family (`[model-harness-mismatch]`); the worker fails the task without a spawn.
@@ -523,20 +533,27 @@ export type ClaimModelFields = Partial<TaskModelResolution> & {
523
533
  modelUnsupported?: string;
524
534
  };
525
535
 
536
+ /** A profile that applies at claim, and the model it resolves to. */
537
+ type ClaimProfile = {
538
+ profile: {
539
+ name: string;
540
+ effort: ReasoningEffort | null;
541
+ credentials: ModelProfileCredentials | null;
542
+ };
543
+ resolution: TaskModelResolution;
544
+ };
545
+
526
546
  /**
527
547
  * Resolve a model profile for a claim. Null when the profile does not apply:
528
- * an agent default that is missing or on another harness falls through to the
529
- * tier chain. For a task's own `profile` both are a hard stop.
548
+ * an agent default or tier alias that is missing, on another harness, or
549
+ * unresolved falls through to the tier chain. For a task's own `profile` each
550
+ * is a hard stop. An unreadable credential allowlist is a hard stop for all.
530
551
  */
531
552
  async function resolveClaimProfile(
532
553
  name: string,
533
- source: "profile:task" | "profile:agent-default",
554
+ source: "profile:task" | "profile:agent-default" | "profile:tier-alias",
534
555
  harness: ProviderName | null,
535
- ): Promise<
536
- | { profile: { name: string; effort: ReasoningEffort | null }; resolution: TaskModelResolution }
537
- | { modelUnsupported: string }
538
- | null
539
- > {
556
+ ): Promise<ClaimProfile | { modelUnsupported: string } | null> {
540
557
  const isTask = source === "profile:task";
541
558
  const profile = await getModelProfileByName(name);
542
559
  if (!profile) {
@@ -569,7 +586,59 @@ async function resolveClaimProfile(
569
586
  modelAlias: profile.model.trim().toLowerCase(),
570
587
  };
571
588
  }
572
- return { profile: { name: profile.name, effort: profile.effort }, resolution };
589
+ // Null credentials would hand the worker the whole pool, so an unreadable
590
+ // allowlist is a hard stop for every source, never a fall-through.
591
+ if (hasUnreadableCredentialAllowlist(profile)) {
592
+ return {
593
+ modelUnsupported: `[model-profile-allowlist-unreadable] Model profile "${name}" has an unreadable credential allowlist. Set its credentials again.`,
594
+ };
595
+ }
596
+ return {
597
+ profile: { name: profile.name, effort: profile.effort, credentials: profile.credentials },
598
+ resolution,
599
+ };
600
+ }
601
+
602
+ /**
603
+ * `modelTier` as an alias for the seeded `<harness>-<tier>` profile. Applies
604
+ * only where the tier chain landed on `tier-default`: a worker-env or
605
+ * tier-config override keeps winning, with a deprecation line. Null keeps the
606
+ * tier result (no tier, no such profile, or a profile that does not apply).
607
+ * A profile with an unreadable credential allowlist returns `modelUnsupported`.
608
+ */
609
+ async function resolveTierAlias(
610
+ resolved: TaskModelResolution | TaskModelHarnessMismatch | null,
611
+ task: { modelTier?: string | null },
612
+ harness: ProviderName | null,
613
+ ): Promise<ClaimProfile | { modelUnsupported: string } | null> {
614
+ const tier = parseModelTier(task.modelTier);
615
+ if (!resolved || "harnessMismatch" in resolved || !tier || !harness) return null;
616
+ const name = `${harness}-${tier}`;
617
+ if (resolved.modelSource === "worker-env" || resolved.modelSource === "tier-config") {
618
+ console.log(
619
+ `[model-tier] deprecated: ${resolved.modelSource} override for ${name}; edit profile ${name} instead`,
620
+ );
621
+ return null;
622
+ }
623
+ if (resolved.modelSource !== "tier-default") return null;
624
+ const picked = await resolveClaimProfile(name, "profile:tier-alias", harness);
625
+ if (!picked || !("profile" in picked)) return picked;
626
+ // A seed copied from a stale MODEL_TIER_* row can name another harness's model.
627
+ // The tier chain skipped that value, so the alias skips it too.
628
+ if (
629
+ isHarnessModelJudged(harness) &&
630
+ harnessModelMismatch(
631
+ picked.resolution.resolvedModel,
632
+ harness,
633
+ (await loadResolutionCatalog()).catalog as HarnessCatalogSections,
634
+ )
635
+ ) {
636
+ console.warn(
637
+ `[model-tiers] profile ${name} names ${picked.resolution.resolvedModel}, which does not run on ${harness}; keeping the tier result`,
638
+ );
639
+ return null;
640
+ }
641
+ return picked;
573
642
  }
574
643
 
575
644
  /**
@@ -646,16 +715,47 @@ export async function recordClaimModelResolution(
646
715
  ...(!task.effort && picked.profile.effort && !repoKeys.has("REASONING_EFFORT_OVERRIDE")
647
716
  ? { effort: picked.profile.effort }
648
717
  : {}),
718
+ ...(picked.profile.credentials ? { credentialAllowlist: picked.profile.credentials } : {}),
649
719
  };
650
720
  }
651
721
  }
652
722
 
653
- const resolved = await resolveTaskModel({
723
+ const resolvedTier = await resolveTaskModel({
654
724
  model: task.model,
655
725
  modelTier: task.modelTier,
656
726
  harnessProvider,
657
727
  workerOverrides: await getAgentModelTierOverrides(agent.id),
658
728
  });
729
+ const alias = await resolveTierAlias(resolvedTier, task, harnessProvider);
730
+ if (alias && "modelUnsupported" in alias) return { modelUnsupported: alias.modelUnsupported };
731
+ if (alias) {
732
+ const checked = await applyCliSupport(
733
+ alias.resolution,
734
+ harnessProvider,
735
+ await getAgentHarnessCliVersion(agent.id),
736
+ );
737
+ // A profile source never fails fast on the CLI check, as for a task's own profile.
738
+ const resolution = "unsupported" in checked ? alias.resolution : checked;
739
+ await getDbClient().run(
740
+ "UPDATE agent_tasks SET resolvedModel = ?, modelSource = ?, modelAlias = ?, resolvedProfile = ? WHERE id = ?",
741
+ [
742
+ resolution.resolvedModel,
743
+ resolution.modelSource,
744
+ resolution.modelAlias,
745
+ alias.profile.name,
746
+ task.id,
747
+ ],
748
+ );
749
+ return {
750
+ resolvedModel: resolution.resolvedModel,
751
+ modelSource: resolution.modelSource,
752
+ ...(resolution.modelAlias ? { modelAlias: resolution.modelAlias } : {}),
753
+ resolvedProfile: alias.profile.name,
754
+ ...(!task.effort && alias.profile.effort ? { effort: alias.profile.effort } : {}),
755
+ ...(alias.profile.credentials ? { credentialAllowlist: alias.profile.credentials } : {}),
756
+ };
757
+ }
758
+ const resolved = resolvedTier;
659
759
  if (!resolved) {
660
760
  // A re-claimed row keeps the claim record of its previous run; drop it so
661
761
  // the trigger and the row do not replay that run's model.
@@ -453,6 +453,33 @@ export async function agentsWithLiveRuntime(): Promise<Set<string>> {
453
453
  return new Set(rows.map((r) => r.agent_id));
454
454
  }
455
455
 
456
+ /**
457
+ * How each agent's live runtimes authenticate: true for a runtime token, false
458
+ * for the shared API key. Registration binds a runtime token to its runtime id,
459
+ * so a live runtime with no unrevoked, unexpired token row uses the shared key.
460
+ * Draining runtimes stay in: MCP poll-task can still start a pending task on one.
461
+ */
462
+ export async function liveRuntimeAuthModes(): Promise<Map<string, boolean[]>> {
463
+ const now = new Date().toISOString();
464
+ const rows = await getDbClient().query<{ agent_id: string; runtime_token: number }>(
465
+ `SELECT r.agent_id, EXISTS(
466
+ SELECT 1 FROM session_tokens s
467
+ WHERE s.runtimeId = r.id AND s.agentId = r.agent_id
468
+ AND s.revokedAt IS NULL AND s.expiresAt > ?
469
+ ) AS runtime_token
470
+ FROM runtime_instances r
471
+ WHERE r.status = 'active' AND r.last_seen_at >= ?`,
472
+ [now, runtimeLivenessCutoff()],
473
+ );
474
+ const modes = new Map<string, boolean[]>();
475
+ for (const row of rows) {
476
+ const list = modes.get(row.agent_id) ?? [];
477
+ list.push(row.runtime_token === 1);
478
+ modes.set(row.agent_id, list);
479
+ }
480
+ return modes;
481
+ }
482
+
456
483
  /**
457
484
  * Retire runtimes that stopped pinging and take their agents offline when
458
485
  * nothing live remains.
@@ -17,8 +17,13 @@ import {
17
17
  releaseTask,
18
18
  } from "../db";
19
19
  import { type AgentTaskRow, rowToAgentTask } from "../db/tasks/read";
20
+ import { checkProfileForAgent, runtimeReadsRepoSecrets } from "../model-profile-check";
20
21
  import { poolTaskRunsOnHarness } from "../model-validation";
21
- import { agentsWithLiveRuntime, runtimeStaleThresholdMinutes } from "../multi-runtime";
22
+ import {
23
+ agentsWithLiveRuntime,
24
+ liveRuntimeAuthModes,
25
+ runtimeStaleThresholdMinutes,
26
+ } from "../multi-runtime";
22
27
  import { listRuntimePools } from "./db";
23
28
  import { isRuntimePoolWakeable } from "./reachability";
24
29
 
@@ -162,10 +167,53 @@ export async function routePoolTasks(
162
167
  }
163
168
  return (agent.maxTasks ?? 1) - count;
164
169
  };
165
- const eligible = async (agent: Agent, task: AgentTask): Promise<boolean> =>
170
+ // A task with an explicit `profile` waits for an agent that passes the profile
171
+ // check, as on the poll's unassigned scan. Memoized per pass. A runtime token's
172
+ // config read may omit secret repo rows while a shared-key runtime reads them,
173
+ // so judge the config each runtime that could start the task gets: every live
174
+ // runtime, plus the token a woken runtime is minted for a wake.
175
+ const runtimeAuthModes = withLiveRuntime === null ? null : await liveRuntimeAuthModes();
176
+ const secretViews = (agent: Agent, viaWake: boolean): boolean[] => {
177
+ if (runtimeAuthModes === null) return [true];
178
+ const tokenView = runtimeReadsRepoSecrets(agent);
179
+ const views = (runtimeAuthModes.get(agent.id) ?? []).map((runtimeToken) =>
180
+ runtimeToken ? tokenView : true,
181
+ );
182
+ if (viaWake || !views.length) views.push(tokenView);
183
+ return [...new Set(views)];
184
+ };
185
+ const profileOk = new Map<string, boolean>();
186
+ const passesProfileCheck = async (
187
+ agent: Agent,
188
+ task: AgentTask,
189
+ viaWake: boolean,
190
+ ): Promise<boolean> => {
191
+ if (!task.profile) return true;
192
+ for (const includeRepoSecrets of secretViews(agent, viaWake)) {
193
+ const memoKey = JSON.stringify([
194
+ agent.id,
195
+ task.profile,
196
+ task.vcsRepo ?? null,
197
+ includeRepoSecrets,
198
+ ]);
199
+ let ok = profileOk.get(memoKey);
200
+ if (ok === undefined) {
201
+ const result = await checkProfileForAgent(agent.id, task.profile, {
202
+ vcsRepo: task.vcsRepo,
203
+ includeRepoSecrets,
204
+ });
205
+ ok = result?.ok !== false;
206
+ profileOk.set(memoKey, ok);
207
+ }
208
+ if (!ok) return false;
209
+ }
210
+ return true;
211
+ };
212
+ const eligible = async (agent: Agent, task: AgentTask, viaWake = false): Promise<boolean> =>
166
213
  (await headroom(agent)) > 0 &&
167
214
  isAgentEligibleForTask(agent, task) &&
168
- (await poolTaskRunsOnHarness(task, agent.harnessProvider ?? agent.provider ?? null));
215
+ (await poolTaskRunsOnHarness(task, agent.harnessProvider ?? agent.provider ?? null)) &&
216
+ (await passesProfileCheck(agent, task, viaWake));
169
217
 
170
218
  const assigned: Array<{ taskId: string; agentId: string }> = [];
171
219
  const limit = nonnegativeEnv("HEARTBEAT_MAX_AUTO_ASSIGN", 5);
@@ -204,7 +252,7 @@ export async function routePoolTasks(
204
252
  ) {
205
253
  const candidates: Array<{ agent: Agent; headroom: number }> = [];
206
254
  for (const agent of wake) {
207
- if (await eligible(agent, task))
255
+ if (await eligible(agent, task, true))
208
256
  candidates.push({ agent, headroom: await headroom(agent) });
209
257
  }
210
258
  candidates.sort(
@@ -239,6 +239,7 @@ export interface SwarmSdk {
239
239
  config_list(args?: { scope?: "global" | "agent" | "repo"; scopeId?: string; key?: string; includeSecrets?: boolean }): Promise<unknown>;
240
240
  // --- model profiles ---
241
241
  modelProfile_list(args?: { harness?: string }): Promise<unknown>;
242
+ modelProfile_check(args: { agentId: string; profile: string }): Promise<unknown>;
242
243
  // --- slack ---
243
244
  slack_read(args?: { inboxMessageId?: string; taskId?: string; channelId?: string; threadTs?: string; limit?: number; includeFiles?: boolean }): Promise<unknown>;
244
245
  slack_listChannels(args?: { types?: Array<"public" | "private" | "dm" | "mpim">; limit?: number }): Promise<unknown>;