@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
@@ -2,9 +2,11 @@ import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
2
2
  import { mkdtemp, readFile, realpath, rm } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
+ import { createSteeringDispatchState, pollAndDispatchSteering } from "../commands/runner";
5
6
  import { ClaudeAdapter, getTaskFilePath } from "../providers/claude-adapter";
6
7
  import { userClaudeMdExclude } from "../providers/claude-flag-settings";
7
8
  import type { ProviderEvent, ProviderSessionConfig } from "../providers/types";
9
+ import type { SteeringMessage } from "../types";
8
10
  import { CHILD_PROCESS_TEST_BUDGET_MS, runChild } from "./test-proc";
9
11
 
10
12
  const fixturePath = join(import.meta.dir, "claude-sdk-process.fixture.ts");
@@ -18,7 +20,15 @@ async function temporaryDirectory(): Promise<string> {
18
20
 
19
21
  function config(
20
22
  directory: string,
21
- mode: "queue" | "cancel" | "stderr-error",
23
+ mode:
24
+ | "queue"
25
+ | "cancel"
26
+ | "stderr-error"
27
+ | "redirect"
28
+ | "redirect-error"
29
+ | "redirect-cancel"
30
+ | "redirect-retry"
31
+ | "coalesce",
22
32
  stateFile: string,
23
33
  ): ProviderSessionConfig {
24
34
  return {
@@ -159,6 +169,211 @@ describe("Claude SDK production adapter lifecycle", () => {
159
169
  { timeout: CHILD_PROCESS_TEST_BUDGET_MS },
160
170
  );
161
171
 
172
+ test(
173
+ "redirect waits for the interrupted result and serializes queue and completion-time input",
174
+ async () => {
175
+ const directory = await temporaryDirectory();
176
+ const stateFile = join(directory, "redirect-state.json");
177
+ let summaries = 0;
178
+ const session = await new ClaudeAdapter(async () => {
179
+ summaries++;
180
+ }).createSession(config(directory, "redirect", stateFile));
181
+ const events: ProviderEvent[] = [];
182
+ let late: Promise<unknown> | undefined;
183
+ session.onEvent((event) => {
184
+ events.push(event);
185
+ if (event.type === "message" && event.content === "accepted:queued") {
186
+ late = session.deliverSteering!({ mode: "queue", text: "completion-message" });
187
+ }
188
+ });
189
+ await waitForFile(stateFile);
190
+ expect(
191
+ await Promise.all([
192
+ session.deliverSteering!({ mode: "steer", text: "redirected" }),
193
+ session.deliverSteering!({ mode: "queue", text: "queued" }),
194
+ ]),
195
+ ).toEqual([
196
+ { delivered: true, mode: "steer" },
197
+ { delivered: true, mode: "queue" },
198
+ ]);
199
+ const result = await session.waitForCompletion();
200
+ expect(await late).toEqual({ delivered: true, mode: "queue" });
201
+ expect(result).toMatchObject({
202
+ exitCode: 0,
203
+ isError: false,
204
+ output: "accepted:completion-message",
205
+ });
206
+ expect(result.cost).toMatchObject({ totalCostUsd: 0.004, numTurns: 4 });
207
+ expect(JSON.parse(await Bun.file(stateFile).text())).toMatchObject({
208
+ interrupts: 1,
209
+ userMessages: ["initial-message", "redirected", "queued", "completion-message"],
210
+ });
211
+ expect(events.filter((e) => e.type === "session_init")).toHaveLength(1);
212
+ expect(events.some((e) => e.type === "context_usage")).toBeTrue();
213
+ expect(summaries).toBe(1);
214
+ expect(await session.deliverSteering!({ mode: "steer", text: "too-late" })).toMatchObject({
215
+ delivered: false,
216
+ });
217
+ },
218
+ { timeout: CHILD_PROCESS_TEST_BUDGET_MS },
219
+ );
220
+
221
+ test(
222
+ "a rejected interrupt does not deliver its text and later queue delivery still completes",
223
+ async () => {
224
+ const directory = await temporaryDirectory();
225
+ const stateFile = join(directory, "redirect-error.json");
226
+ const session = await new ClaudeAdapter(async () => {}).createSession(
227
+ config(directory, "redirect-error", stateFile),
228
+ );
229
+ try {
230
+ await waitForFile(stateFile);
231
+ expect(await session.deliverSteering!({ mode: "steer", text: "rejected" })).toMatchObject({
232
+ delivered: false,
233
+ });
234
+ expect(await session.deliverSteering!({ mode: "queue", text: "recovery" })).toEqual({
235
+ delivered: true,
236
+ mode: "queue",
237
+ });
238
+ expect((await session.waitForCompletion()).exitCode).toBe(0);
239
+ expect(JSON.parse(await Bun.file(stateFile).text()).userMessages).toEqual([
240
+ "initial-message",
241
+ "recovery",
242
+ ]);
243
+ } finally {
244
+ await session.abort("test cleanup");
245
+ }
246
+ },
247
+ { timeout: CHILD_PROCESS_TEST_BUDGET_MS },
248
+ );
249
+
250
+ test(
251
+ "cancellation during redirect rejects pending input and wins over interrupted completion",
252
+ async () => {
253
+ const directory = await temporaryDirectory();
254
+ const stateFile = join(directory, "redirect-cancel.json");
255
+ const session = await new ClaudeAdapter(async () => {}).createSession(
256
+ config(directory, "redirect-cancel", stateFile),
257
+ );
258
+ await waitForFile(stateFile);
259
+ const redirect = session.deliverSteering!({ mode: "steer", text: "must-not-arrive" });
260
+ const queued = session.deliverSteering!({ mode: "queue", text: "also-cancelled" });
261
+ await waitForFile(`${stateFile}.interrupt`);
262
+ await session.abort("cancel during redirect");
263
+ expect(await redirect).toMatchObject({ delivered: false });
264
+ expect(await queued).toMatchObject({ delivered: false });
265
+ expect(await session.waitForCompletion()).toMatchObject({
266
+ exitCode: 130,
267
+ errorCategory: "cancelled",
268
+ });
269
+ expect(JSON.parse(await Bun.file(stateFile).text()).userMessages).toEqual([
270
+ "initial-message",
271
+ ]);
272
+ },
273
+ { timeout: CHILD_PROCESS_TEST_BUDGET_MS },
274
+ );
275
+
276
+ test(
277
+ "a singular UUID result answers coalesced inputs and leaves a later input open",
278
+ async () => {
279
+ const directory = await temporaryDirectory();
280
+ const stateFile = join(directory, "coalesce.json");
281
+ const session = await new ClaudeAdapter(async () => {}).createSession(
282
+ config(directory, "coalesce", stateFile),
283
+ );
284
+ try {
285
+ await waitForFile(stateFile);
286
+ expect(await session.deliverSteering!({ mode: "queue", text: "second" })).toEqual({
287
+ delivered: true,
288
+ mode: "queue",
289
+ });
290
+ // The fixture's first result echoes only the initial id. "second" is
291
+ // still outstanding, so completion must not have closed the input.
292
+ expect(await session.deliverSteering!({ mode: "queue", text: "third" })).toEqual({
293
+ delivered: true,
294
+ mode: "queue",
295
+ });
296
+ const result = await Promise.race([
297
+ session.waitForCompletion(),
298
+ Bun.sleep(3_000).then(() => {
299
+ throw new Error("coalesced singular-UUID result left inputs unanswered");
300
+ }),
301
+ ]);
302
+ expect(result.exitCode).toBe(0);
303
+ expect(JSON.parse(await Bun.file(stateFile).text()).userMessages).toEqual([
304
+ "initial-message",
305
+ "second",
306
+ "third",
307
+ ]);
308
+ } finally {
309
+ await session.abort("coalesce test cleanup");
310
+ }
311
+ },
312
+ { timeout: CHILD_PROCESS_TEST_BUDGET_MS },
313
+ );
314
+
315
+ test(
316
+ "SDK delivery-report retries retain steering IDs without interrupting or injecting twice",
317
+ async () => {
318
+ const directory = await temporaryDirectory();
319
+ const stateFile = join(directory, "redirect-retry.json");
320
+ const sessionConfig = config(directory, "redirect-retry", stateFile);
321
+ const session = await new ClaudeAdapter(async () => {}).createSession(sessionConfig);
322
+ try {
323
+ await waitForFile(stateFile);
324
+ const messages: SteeringMessage[] = (["queue", "steer"] as const).map((mode) => ({
325
+ id: crypto.randomUUID(),
326
+ taskId: sessionConfig.taskId,
327
+ mode,
328
+ body: `${mode} body`,
329
+ status: "pending",
330
+ source: "api",
331
+ createdByKind: "user",
332
+ createdAt: new Date().toISOString(),
333
+ }));
334
+ let failReport = true;
335
+ const reports: string[] = [];
336
+ const fetchImpl = (async (input: string | URL | Request) => {
337
+ const url = new URL(String(input));
338
+ if (url.pathname === "/api/steering-messages") return Response.json({ messages });
339
+ reports.push(url.pathname);
340
+ return new Response("{}", { status: failReport ? 503 : 200 });
341
+ }) as typeof fetch;
342
+ const api = {
343
+ apiUrl: "http://steering.test",
344
+ apiKey: "fixture",
345
+ agentId: sessionConfig.agentId,
346
+ };
347
+ const state = createSteeringDispatchState();
348
+ await expect(
349
+ pollAndDispatchSteering(api, sessionConfig.taskId, session, state, fetchImpl),
350
+ ).rejects.toThrow("report failed");
351
+ // Promise.all rejects at the first failed report; let every active
352
+ // delivery settle before retrying the still-pending server rows.
353
+ while (state.inFlightMessageIds.size > 0) await Bun.sleep(10);
354
+ failReport = false;
355
+ await pollAndDispatchSteering(api, sessionConfig.taskId, session, state, fetchImpl);
356
+ await session.deliverSteering!({ mode: "queue", text: "finish" });
357
+ expect((await session.waitForCompletion()).exitCode).toBe(0);
358
+ const captured = JSON.parse(await Bun.file(stateFile).text());
359
+ expect(captured.interrupts).toBe(1);
360
+ expect(captured.userMessages).toHaveLength(4);
361
+ for (const message of messages) {
362
+ expect(
363
+ captured.userMessages.filter((text: string) => text.includes(message.id)),
364
+ ).toHaveLength(1);
365
+ expect(captured.userMessages.find((text: string) => text.includes(message.id))).toContain(
366
+ message.body,
367
+ );
368
+ expect(reports.filter((path) => path.includes(message.id))).toHaveLength(2);
369
+ }
370
+ } finally {
371
+ await session.abort("retry test cleanup");
372
+ }
373
+ },
374
+ { timeout: CHILD_PROCESS_TEST_BUDGET_MS },
375
+ );
376
+
162
377
  test(
163
378
  "merges caller --settings from additionalArgs and CLAUDE_BINARY into the SDK's one flag",
164
379
  async () => {
@@ -85,6 +85,10 @@ function resultMessage(
85
85
  queued_turn_count: queuedTurnCount,
86
86
  uuid: crypto.randomUUID(),
87
87
  session_id: sessionId,
88
+ user_message_uuid: userUuids[turn - 1],
89
+ // redirect-retry echoes only the singular id. A cumulative list would hide
90
+ // coalesced inputs that a real singular result leaves unanswered.
91
+ ...(mode === "redirect-error" ? { user_message_uuids: userUuids } : {}),
88
92
  };
89
93
  }
90
94
 
@@ -154,7 +158,9 @@ function answerInitialize(requestId: string): void {
154
158
  const decoder = new TextDecoder();
155
159
  let buffer = "";
156
160
  let initialized = false;
161
+ let interrupts = 0;
157
162
  const userMessages: string[] = [];
163
+ const userUuids: string[] = [];
158
164
  const argv = process.argv.slice(2);
159
165
 
160
166
  if (mode === "cancel") {
@@ -171,6 +177,7 @@ async function handleLine(line: string): Promise<boolean> {
171
177
  const message = JSON.parse(line) as {
172
178
  type?: string;
173
179
  request_id?: string;
180
+ uuid?: string;
174
181
  request?: { subtype?: string };
175
182
  message?: { content?: unknown };
176
183
  };
@@ -182,6 +189,30 @@ async function handleLine(line: string): Promise<boolean> {
182
189
  }
183
190
  return false;
184
191
  }
192
+ if (
193
+ message.type === "control_request" &&
194
+ message.request?.subtype === "interrupt" &&
195
+ mode?.startsWith("redirect")
196
+ ) {
197
+ interrupts++;
198
+ writeMessage({
199
+ type: "control_response",
200
+ response: {
201
+ subtype: mode === "redirect-error" ? "error" : "success",
202
+ request_id: message.request_id,
203
+ ...(mode === "redirect-error"
204
+ ? { error: "fixture interrupt rejected" }
205
+ : { response: { still_queued: [] } }),
206
+ },
207
+ });
208
+ if (mode === "redirect-error") return false;
209
+ // Exercise the receipt/result gap. The redirect must not be sent into
210
+ // the interrupted turn, whose final result reports no queued work.
211
+ await writeStateFile(`${stateFile}.interrupt`, { interrupts });
212
+ await Bun.sleep(mode === "redirect-cancel" ? 500 : 30);
213
+ writeMessage(resultMessage("interrupted", 1, 0));
214
+ return false;
215
+ }
185
216
  if (message.type !== "user") return false;
186
217
  const content = message.message?.content;
187
218
  const text =
@@ -200,6 +231,32 @@ async function handleLine(line: string): Promise<boolean> {
200
231
  .join("")
201
232
  : "";
202
233
  userMessages.push(text);
234
+ userUuids.push(message.uuid ?? "");
235
+
236
+ if (mode === "coalesce") {
237
+ await writeStateFile(stateFile, { argv, userMessages });
238
+ if (userMessages.length === 2) {
239
+ // Singular echo of the first input. The second stays unanswered.
240
+ writeMessage(assistantMessage("partial", 1));
241
+ writeMessage(resultMessage("partial", 1, 0));
242
+ } else if (userMessages.length >= 3) {
243
+ // Singular echo of the last merged input, with no UUID list.
244
+ writeMessage(assistantMessage("coalesced", userMessages.length));
245
+ writeMessage(resultMessage("coalesced", userMessages.length, 0));
246
+ }
247
+ return false;
248
+ }
249
+
250
+ if (mode?.startsWith("redirect")) {
251
+ await writeStateFile(stateFile, { argv, userMessages, interrupts });
252
+ if (userMessages.length === 1) {
253
+ writeMessage(assistantMessage("working", 1));
254
+ } else if (mode !== "redirect-retry" || text === "finish") {
255
+ writeMessage(assistantMessage(`accepted:${text}`, userMessages.length));
256
+ writeMessage(resultMessage(`accepted:${text}`, userMessages.length, 0));
257
+ }
258
+ return false;
259
+ }
203
260
 
204
261
  if (mode === "stderr-error") {
205
262
  writeMessage(errorResultMessage());
@@ -13,6 +13,7 @@ import { tmpdir } from "node:os";
13
13
  import { join } from "node:path";
14
14
  import { prependContextPreamble } from "../commands/context-preamble";
15
15
  import { resolveCodexPrompt } from "../providers/codex-skill-resolver";
16
+ import { resolveDevinPrompt } from "../providers/devin-skill-resolver";
16
17
  import type { ProviderEvent } from "../providers/types";
17
18
 
18
19
  /** Create a fresh tmp skills dir for each test to avoid cross-test leakage. */
@@ -165,4 +166,34 @@ describe("resolveCodexPrompt", () => {
165
166
  expect(result.startsWith(skillBody)).toBe(true);
166
167
  expect(result).toContain("User request: abc");
167
168
  });
169
+
170
+ test("enforces 100,000-char default cap when MAX_SKILL_CHARS is non-finite, non-positive, or non-integer, and honors valid positive integer overrides", async () => {
171
+ const prev = process.env.MAX_SKILL_CHARS;
172
+ try {
173
+ const oversized = "x".repeat(100_050);
174
+ await writeSkill("huge-skill", oversized);
175
+
176
+ for (const badVal of ["Infinity", "-Infinity", "NaN", "0", "-50", "12.5", "not-a-number"]) {
177
+ process.env.MAX_SKILL_CHARS = badVal;
178
+ const codexRes = await resolveCodexPrompt("/huge-skill go", skillsDir);
179
+ expect(codexRes.startsWith("x".repeat(100_000) + "\n\n---\n\n")).toBe(true);
180
+
181
+ const devinRes = await resolveDevinPrompt("@skills:huge-skill go", skillsDir);
182
+ expect(devinRes.startsWith("x".repeat(100_000) + "\n\n---\n\n")).toBe(true);
183
+ }
184
+
185
+ process.env.MAX_SKILL_CHARS = "120";
186
+ const customCodex = await resolveCodexPrompt("/huge-skill go", skillsDir);
187
+ expect(customCodex.startsWith("x".repeat(120) + "\n\n---\n\n")).toBe(true);
188
+
189
+ const customDevin = await resolveDevinPrompt("@skills:huge-skill go", skillsDir);
190
+ expect(customDevin.startsWith("x".repeat(120) + "\n\n---\n\n")).toBe(true);
191
+ } finally {
192
+ if (prev === undefined) {
193
+ delete process.env.MAX_SKILL_CHARS;
194
+ } else {
195
+ process.env.MAX_SKILL_CHARS = prev;
196
+ }
197
+ }
198
+ });
168
199
  });