@desplega.ai/agent-swarm 2.9.0 → 2.9.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 (305) hide show
  1. package/dist/acp-adapter-g909b5hw.js +16 -0
  2. package/dist/{acp-targets-swxq55dr.js → acp-targets-ny75x1qy.js} +7 -7
  3. package/dist/{actions-pb678g3e.js → actions-b9qgrmeq.js} +81 -21
  4. package/dist/{agent-fs-provision-dmhnc38q.js → agent-fs-provision-b5dhdsbd.js} +4 -4
  5. package/dist/{amp-adapter-3pa66q27.js → amp-adapter-vtax2c9s.js} +2 -2
  6. package/dist/{anthropic-messages-x2cp5fvf.js → anthropic-messages-r5xf5hqw.js} +10 -10
  7. package/dist/{app-17d12ev4.js → app-g2z15hax.js} +6 -3
  8. package/dist/{approval-notifications-h7vd9pmg.js → approval-notifications-yt13wp8r.js} +8 -5
  9. package/dist/{assistant-t7k39ree.js → assistant-2cgfxsgk.js} +23 -21
  10. package/dist/{boot-args-schema-0gqmkfbe.js → boot-args-schema-3gwy0f60.js} +1 -1
  11. package/dist/{boot-reembed-n6anc01d.js → boot-reembed-92g7s5zp.js} +1 -1
  12. package/dist/{boot-reembed-f064w382.js → boot-reembed-mywmyp4s.js} +1 -1
  13. package/dist/{boot-scrub-sweep-ejd5dnrz.js → boot-scrub-sweep-7dkdzqxx.js} +3 -3
  14. package/dist/{boot-seeds-f99fjs5q.js → boot-seeds-ce7rvgq1.js} +4 -4
  15. package/dist/{claude-adapter-gvznwxgc.js → claude-adapter-3m4q7735.js} +7 -7
  16. package/dist/{claude-managed-adapter-pbrbvc64.js → claude-managed-adapter-t8nfgcgz.js} +2 -2
  17. package/dist/{claude-managed-setup-kdxttvc3.js → claude-managed-setup-c217draw.js} +3 -3
  18. package/dist/{claude-sdk-session-0t2teq6n.js → claude-sdk-session-7fbqm51z.js} +7 -7
  19. package/dist/{cli-9a2rtd77.js → cli-1jykg0py.js} +6 -4
  20. package/dist/{cli-5ntc4we6.js → cli-2czxfnvj.js} +235 -2003
  21. package/dist/{cli-dd37e0cm.js → cli-2dq9yv8p.js} +1 -1
  22. package/dist/{cli-c07v0qfa.js → cli-2xs8tsf7.js} +69 -66
  23. package/dist/{cli-7fx9jyfs.js → cli-2yjj3e31.js} +64 -10
  24. package/dist/{cli-4ghh072d.js → cli-32djehja.js} +36 -36
  25. package/dist/{cli-cw7mc1je.js → cli-3j873zxq.js} +3 -3
  26. package/dist/cli-43ms35q9.js +270 -0
  27. package/dist/cli-47hz21se.js +25584 -0
  28. package/dist/{cli-n515ex5z.js → cli-4ymxrwg5.js} +16 -16
  29. package/dist/{cli-5gygrr67.js → cli-67mwzr35.js} +1 -1
  30. package/dist/{cli-5kcmxwxv.js → cli-6945ywhr.js} +1 -1
  31. package/dist/{cli-812paz57.js → cli-6ehs4mta.js} +18 -2
  32. package/dist/{cli-95930z69.js → cli-6ym4jhzp.js} +2 -2
  33. package/dist/{cli-zg3z63x3.js → cli-7mv4h3sn.js} +1 -1
  34. package/dist/{cli-eg437b5p.js → cli-7sf9sb0w.js} +2 -1
  35. package/dist/{cli-nr46j5pw.js → cli-8zh9nrew.js} +1 -1
  36. package/dist/{cli-wr1h0k28.js → cli-9w8712tq.js} +617 -278
  37. package/dist/{cli-ssvdrk4y.js → cli-b6px1k1q.js} +1 -1
  38. package/dist/{cli-7831nhaw.js → cli-b91nz213.js} +3 -3
  39. package/dist/{cli-7cgf614g.js → cli-bg63qmsx.js} +2 -2
  40. package/dist/{cli-me4maa4j.js → cli-bkjdknnp.js} +9 -5
  41. package/dist/{cli-rts1qvb4.js → cli-bnqncekd.js} +2 -2
  42. package/dist/{cli-25nstr34.js → cli-br0924pw.js} +1 -1
  43. package/dist/{cli-ymct0ycy.js → cli-ctx0b85j.js} +5222 -4978
  44. package/dist/{cli-kqh27v2y.js → cli-dgs10ttj.js} +1 -1
  45. package/dist/{cli-kmvcm34h.js → cli-f3jyzq4g.js} +2 -2
  46. package/dist/cli-f8x9drqr.js +84 -0
  47. package/dist/{cli-8axx8vnw.js → cli-f9gz2vyj.js} +5 -5
  48. package/dist/{cli-vvgaz8t6.js → cli-fh97xn30.js} +2 -2
  49. package/dist/{cli-8x8y70av.js → cli-fkef327x.js} +2 -2
  50. package/dist/{cli-js8zrfyg.js → cli-gfy38pvt.js} +2 -2
  51. package/dist/{cli-kaa4bd7x.js → cli-h9yqfzx9.js} +7 -6
  52. package/dist/{cli-svc803vq.js → cli-j7svy295.js} +11 -11
  53. package/dist/{cli-nhq5js1b.js → cli-jaw5v1sy.js} +3 -3
  54. package/dist/{cli-w7dxb2fj.js → cli-jkw6ptfw.js} +6 -6
  55. package/dist/{cli-1tvdx9t5.js → cli-jm0hvmz2.js} +1 -1
  56. package/dist/{cli-e9973bf0.js → cli-jwampxxq.js} +2 -2
  57. package/dist/{cli-dx439zpg.js → cli-kpgcm7xy.js} +13 -1
  58. package/dist/{cli-pz1c00aa.js → cli-kxx4k2jw.js} +2 -2
  59. package/dist/{cli-aa8s22gn.js → cli-m7c2380k.js} +191 -182
  60. package/dist/{cli-2kg31ted.js → cli-m7zvgt57.js} +11 -11
  61. package/dist/{cli-57pvhnyt.js → cli-mhapr559.js} +1 -1
  62. package/dist/{cli-gddgcnav.js → cli-mjw0yf82.js} +1 -1
  63. package/dist/{cli-h474mvp5.js → cli-mkwkwq81.js} +7 -4
  64. package/dist/{cli-jd3kxppb.js → cli-mw620q3n.js} +1 -1
  65. package/dist/{cli-spzkdgtg.js → cli-n3qe7tyr.js} +172 -168
  66. package/dist/{cli-3zxdz9r7.js → cli-nafvvsp8.js} +3 -3
  67. package/dist/{cli-fnh4b12r.js → cli-nbt14he0.js} +6 -6
  68. package/dist/{cli-7akn6ze9.js → cli-nh7x3133.js} +7 -28
  69. package/dist/{cli-faf46gdq.js → cli-p4kckx1z.js} +10 -10
  70. package/dist/{cli-k7pt28ad.js → cli-pb2ay3sh.js} +2 -2
  71. package/dist/{cli-pn1v1pb0.js → cli-psffsanb.js} +3 -2
  72. package/dist/{cli-2tnbc3gw.js → cli-pyjn0qhk.js} +2257 -61
  73. package/dist/{cli-fgphc007.js → cli-rq5rpv6k.js} +1 -1
  74. package/dist/{cli-vw5x18yj.js → cli-sn650d7x.js} +9 -9
  75. package/dist/{cli-mc1fx4xd.js → cli-td9tb872.js} +10 -10
  76. package/dist/{cli-6dp0jkfj.js → cli-tvc4jag9.js} +3 -3
  77. package/dist/{cli-a9hfzg2r.js → cli-ty3gha1p.js} +6 -6
  78. package/dist/{cli-pwsax0vp.js → cli-v57d7fmm.js} +1 -1
  79. package/dist/{cli-nmcpzbty.js → cli-vt89089n.js} +4 -4
  80. package/dist/{cli-sn4pc4qx.js → cli-vyff45ve.js} +2 -2
  81. package/dist/{cli-m1fbz2wj.js → cli-w4n323t3.js} +175 -16
  82. package/dist/{cli-g3zzby8t.js → cli-wn13hhdt.js} +5 -5
  83. package/dist/{cli-q8cfh1t9.js → cli-xag7btpe.js} +1 -1
  84. package/dist/{cli-c5cspahx.js → cli-y2ewxhth.js} +38 -13
  85. package/dist/{cli-k09cxm6m.js → cli-ysvspf5e.js} +2 -2
  86. package/dist/{cli-eepnpee7.js → cli-zh0e5x7p.js} +4 -4
  87. package/dist/{cli-bk9v1xrv.js → cli-zr6qy15y.js} +11 -11
  88. package/dist/cli.js +21 -20
  89. package/dist/{codex-adapter-44yq2fkn.js → codex-adapter-n656pvb8.js} +6 -6
  90. package/dist/{codex-hook-h1zb7cfk.js → codex-hook-59atdwd8.js} +1 -1
  91. package/dist/{codex-login-cdyrr5y1.js → codex-login-a239g1ah.js} +1 -1
  92. package/dist/{codex-session-runner-zbh26gbw.js → codex-session-runner-p0fbv5y9.js} +6 -6
  93. package/dist/{commands-54f02v5b.js → commands-gwea8z5p.js} +3 -3
  94. package/dist/{controller-9gpwcdek.js → controller-t67c3grh.js} +6 -3
  95. package/dist/{controllers-connect-61re6k1n.js → controllers-connect-ks155r0h.js} +22 -20
  96. package/dist/{cursor-adapter-7e4g81vd.js → cursor-adapter-ygwrtmkv.js} +1 -1
  97. package/dist/{db-dg2gc7fd.js → db-kpmx06s9.js} +8 -2
  98. package/dist/{db-wnh0qjy1.js → db-rb2xqdb1.js} +3 -3
  99. package/dist/{dispatcher-jrm24r43.js → dispatcher-31sm0ej2.js} +20 -18
  100. package/dist/{docker-9aq30pp2.js → docker-09tkkg0n.js} +42 -3
  101. package/dist/{dsh-adapter-1yqk267c.js → dsh-adapter-qyxh0w31.js} +1 -1
  102. package/dist/{easter-egg-3d-r4h9cs9m.js → easter-egg-3d-00wjscn6.js} +1 -1
  103. package/dist/{embedding-space-bafjr5f7.js → embedding-space-qhw4g68n.js} +6 -6
  104. package/dist/{embeddings-7xmgqe0e.js → embeddings-zdv9ke6x.js} +1 -1
  105. package/dist/{execute-d6jg5ns0.js → execute-zna8wwr7.js} +1 -1
  106. package/dist/{external-channel-frq1xvq2.js → external-channel-1ac6t56s.js} +2 -2
  107. package/dist/fx-adapter-sk7n0fzc.js +19 -0
  108. package/dist/{google-generative-ai-hh7strj3.js → google-generative-ai-maq6c9bf.js} +1 -1
  109. package/dist/{google-vertex-fy5bw2pm.js → google-vertex-2jgsw2nb.js} +1 -1
  110. package/dist/grok-adapter-sjbcm5ew.js +19 -0
  111. package/dist/handlers-yzy0c87x.js +35 -0
  112. package/dist/{heartbeat-6bpa611t.js → heartbeat-2f6z4kdx.js} +23 -21
  113. package/dist/{hook-w12k146y.js → hook-8y0gvtp1.js} +6 -6
  114. package/dist/{hook-hvm5nf46.js → hook-w1skzaqc.js} +5 -5
  115. package/dist/{http-43tthdvs.js → http-wghxvpef.js} +714 -145
  116. package/dist/{index-1f0vypbg.js → index-0h6qd4p1.js} +34 -24
  117. package/dist/index-25pvya7q.js +40 -0
  118. package/dist/index-2t4859r5.js +35 -0
  119. package/dist/{index-4b1q8kan.js → index-4k7m5dgj.js} +629 -354
  120. package/dist/index-620y7jzq.js +15 -0
  121. package/dist/{index-cret47a5.js → index-8p0j4h4j.js} +506 -43
  122. package/dist/{index-mhq4sh5w.js → index-8zn8nxn5.js} +1 -1
  123. package/dist/{index-m5gx1xd6.js → index-9myfj74s.js} +40 -40
  124. package/dist/{index-ftywhyr0.js → index-9zkchs9t.js} +221 -65
  125. package/dist/{index-bs7gw5fd.js → index-b5wgnm78.js} +44 -44
  126. package/dist/index-cxca2t8y.js +36 -0
  127. package/dist/{index-585gyczt.js → index-pe3d8jfy.js} +3 -3
  128. package/dist/{index-tx9mc2ap.js → index-rv89fvzf.js} +24 -22
  129. package/dist/{index-fn054vsf.js → index-s71ez27v.js} +1 -1
  130. package/dist/{keepalive-rk0j0jvh.js → keepalive-sh02349h.js} +3 -3
  131. package/dist/lead-gk4h5eg7.js +74 -0
  132. package/dist/{maintenance-g6z6kaxw.js → maintenance-yj0dcjja.js} +1 -1
  133. package/dist/{node-jftbyawr.js → node-dqm4xgxw.js} +1 -1
  134. package/dist/{oauth-refresh-sweep-2k3g2q4w.js → oauth-refresh-sweep-d9xedk66.js} +2 -2
  135. package/dist/{onboard-6fdbvh3v.js → onboard-dpgjn03r.js} +2 -2
  136. package/dist/{opencode-adapter-fdbsvts7.js → opencode-adapter-2d31cpjc.js} +6 -6
  137. package/dist/{otel-impl-rvwtc09q.js → otel-impl-1skarpfq.js} +1 -1
  138. package/dist/{pending-sqkrb836.js → pending-bfmxtx0g.js} +21 -19
  139. package/dist/{pi-mono-adapter-asqayqcg.js → pi-mono-adapter-gvppnasy.js} +40 -13
  140. package/dist/{pricing-refresh-f5tkgmw2.js → pricing-refresh-c6b325mk.js} +2 -2
  141. package/dist/{rbac-roles-06s555fa.js → rbac-roles-h80qbdbs.js} +3 -3
  142. package/dist/{rbac-roles-szxsg8t1.js → rbac-roles-zfcx68tx.js} +2 -2
  143. package/dist/{render-v2-103p266q.js → render-v2-nx20t3rb.js} +6 -3
  144. package/dist/{resume-v7kjewt9.js → resume-5ep8agan.js} +10 -7
  145. package/dist/{runtime-f1gmk0b7.js → runtime-r3pj4mce.js} +1 -1
  146. package/dist/{session-access-6shev8ts.js → session-access-n7p3m15b.js} +4 -4
  147. package/dist/{session-source-backfill-bd7spzjd.js → session-source-backfill-v8mt0zwn.js} +3 -3
  148. package/dist/{setup-kmxmztdb.js → setup-z1psaqhe.js} +1 -1
  149. package/dist/thread-buffer-a1re2r9r.js +38 -0
  150. package/dist/{virtual-modules-57eje5wy.js → virtual-modules-rrbjdpxn.js} +3 -3
  151. package/dist/{work-objects-zr47ygmf.js → work-objects-4aghh73z.js} +29 -23
  152. package/dist/worker-3dyyb8ev.js +74 -0
  153. package/dist/{worker-follow-up-grrr3fda.js → worker-follow-up-166zmex1.js} +20 -18
  154. package/openapi.json +1387 -13
  155. package/package.json +7 -6
  156. package/src/apps/catalog.generated.json +43 -3
  157. package/src/apps/page-validator.ts +27 -0
  158. package/src/be/db/model-profiles.ts +4 -1
  159. package/src/be/db/session-costs.ts +219 -0
  160. package/src/be/db/session-log-reasoning.ts +36 -0
  161. package/src/be/db/tasks/read.ts +7 -3
  162. package/src/be/db/tasks/write.ts +33 -1
  163. package/src/be/db.ts +200 -304
  164. package/src/be/key-window-usage.ts +385 -0
  165. package/src/be/migrations/303_task_ui_specs.sql +28 -0
  166. package/src/be/migrations/306_provider_account_telemetry.sql +1 -0
  167. package/src/be/migrations/307_session_cost_credential_attribution.sql +23 -0
  168. package/src/be/migrations/310_session_logs_reasoning.sql +12 -0
  169. package/src/be/runtime-pools/db.ts +3 -0
  170. package/src/be/seed-scripts/catalog/boot-triage.inline.ts +1 -0
  171. package/src/be/seed-scripts/catalog/boot-triage.ts +1 -0
  172. package/src/be/seed-scripts/catalog/wait-for-task.ts +5 -1
  173. package/src/be/seed-skills/index.ts +3 -0
  174. package/src/be/swarm-config-guard.ts +24 -1
  175. package/src/be/task-ui-spec.ts +158 -0
  176. package/src/commands/controller.ts +3 -0
  177. package/src/commands/credential-outcome-report.ts +13 -3
  178. package/src/commands/rate-limit-outcome.ts +6 -0
  179. package/src/commands/runner.ts +34 -53
  180. package/src/extensions/catalog.generated.json +3 -3
  181. package/src/extensions/contract-types.generated.ts +1 -1
  182. package/src/http/api-keys.ts +258 -30
  183. package/src/http/session-data.ts +74 -23
  184. package/src/http/sessions.ts +6 -2
  185. package/src/http/tasks.ts +105 -5
  186. package/src/integrations/chat-sdk/relay.ts +87 -0
  187. package/src/jira/outbound.ts +5 -3
  188. package/src/linear/outbound.ts +5 -1
  189. package/src/prompts/base-prompt.ts +8 -0
  190. package/src/prompts/session-templates.ts +19 -2
  191. package/src/providers/acp-targets.ts +1 -1
  192. package/src/providers/amp-adapter.ts +1 -1
  193. package/src/providers/claude-adapter.ts +27 -4
  194. package/src/providers/claude-flag-settings.ts +39 -1
  195. package/src/providers/codex-adapter.ts +85 -3
  196. package/src/providers/codex-app-server.ts +9 -5
  197. package/src/providers/codex-oauth/auth-json.ts +1 -0
  198. package/src/providers/pi-mono-adapter.ts +35 -2
  199. package/src/providers/pricing-sources.md +32 -0
  200. package/src/providers/types.ts +11 -0
  201. package/src/runtime-providers/docker.ts +65 -1
  202. package/src/scheduler/deferred-task-waits.ts +18 -5
  203. package/src/scripts-runtime/types/swarm-extension.d.ts +8 -8
  204. package/src/slack/actions.ts +56 -0
  205. package/src/slack/app.ts +22 -15
  206. package/src/slack/inbound-files.ts +2 -0
  207. package/src/slack/render-v2.ts +107 -23
  208. package/src/slack/responses.ts +3 -2
  209. package/src/slack/work-objects.ts +4 -1
  210. package/src/tasks/errors.ts +5 -0
  211. package/src/tests/acp-adapter.test.ts +4 -6
  212. package/src/tests/api-key-tracking.test.ts +0 -72
  213. package/src/tests/api-keys-status-model-limits.test.ts +93 -1
  214. package/src/tests/api-keys-validation.test.ts +42 -0
  215. package/src/tests/approval-card-resolution.test.ts +7 -1
  216. package/src/tests/approval-requests-notifications.test.ts +11 -1
  217. package/src/tests/apps-catalog-page-frame.test.ts +49 -0
  218. package/src/tests/apps-session-thread.test.ts +79 -0
  219. package/src/tests/base-prompt.test.ts +111 -5
  220. package/src/tests/chat-sdk-relay.test.ts +149 -1
  221. package/src/tests/claude-adapter-binary.test.ts +67 -6
  222. package/src/tests/claude-flag-settings.test.ts +29 -0
  223. package/src/tests/claude-sdk-lifecycle.test.ts +5 -0
  224. package/src/tests/codex-adapter.test.ts +340 -2
  225. package/src/tests/codex-app-server.test.ts +16 -0
  226. package/src/tests/codex-oauth.test.ts +3 -1
  227. package/src/tests/codex-rate-limits.test.ts +384 -0
  228. package/src/tests/credential-outcome-report.test.ts +20 -0
  229. package/src/tests/db-task-read-contract.test.ts +3 -0
  230. package/src/tests/db-task-write-contract.test.ts +4 -0
  231. package/src/tests/deferred-task-wake.test.ts +63 -1
  232. package/src/tests/docker-isolation-config-guard.test.ts +29 -0
  233. package/src/tests/docs-index-footprint.test.js +11 -3
  234. package/src/tests/e2e-visuals-comment.test.ts +82 -0
  235. package/src/tests/e2e-visuals-verify-pr.test.ts +138 -0
  236. package/src/tests/extensions-example-sql-admin-only.test.ts +7 -4
  237. package/src/tests/fixtures/ui-spec-slack/deploys.json +121 -0
  238. package/src/tests/fixtures/ui-spec-slack/incident.json +183 -0
  239. package/src/tests/fixtures/ui-spec-slack/three-charts-stale.json +196 -0
  240. package/src/tests/fixtures/ui-spec-slack/video-rejected-by-slack.json +183 -0
  241. package/src/tests/fixtures/ui-spec-slack/video.json +446 -0
  242. package/src/tests/gitleaks-download-retry.test.ts +85 -0
  243. package/src/tests/human-thread-routing.test.ts +187 -0
  244. package/src/tests/jira-outbound-sync.test.ts +33 -1
  245. package/src/tests/key-window-usage.test.ts +831 -0
  246. package/src/tests/linear-outbound-sync.test.ts +30 -1
  247. package/src/tests/pi-mono-adapter.test.ts +79 -0
  248. package/src/tests/preload-env.test.ts +2 -0
  249. package/src/tests/preload.ts +3 -1
  250. package/src/tests/prompt-template-session.test.ts +4 -3
  251. package/src/tests/provider-quota-persistence.test.ts +362 -0
  252. package/src/tests/rate-limit-event.test.ts +22 -0
  253. package/src/tests/reasoning-events.test.ts +164 -0
  254. package/src/tests/routing-affinity-inventory.test.ts +22 -0
  255. package/src/tests/runtime-providers-docker.test.ts +91 -0
  256. package/src/tests/script-connections.test.ts +5 -0
  257. package/src/tests/secret-canary-sweep.test.ts +41 -5
  258. package/src/tests/seed-scripts.test.ts +23 -0
  259. package/src/tests/session-cost-attribution.test.ts +748 -0
  260. package/src/tests/session-costs.test.ts +14 -15
  261. package/src/tests/session-logs.test.ts +83 -0
  262. package/src/tests/sessions-detail-batch.test.ts +7 -0
  263. package/src/tests/slack-render-v2.test.ts +357 -0
  264. package/src/tests/slack-start-reload-race.test.ts +67 -0
  265. package/src/tests/subscription-plans.test.ts +20 -1
  266. package/src/tests/task-ui-action-route.test.ts +191 -0
  267. package/src/tests/task-ui-actions.test.ts +195 -0
  268. package/src/tests/task-ui-spec-fallback.test.ts +65 -0
  269. package/src/tests/task-ui-spec.test.ts +368 -0
  270. package/src/tests/workflow-agent-task-retry.test.ts +34 -1
  271. package/src/tools/defer-task.ts +1 -1
  272. package/src/tools/store-progress.ts +69 -3
  273. package/src/types.ts +7 -2
  274. package/src/ui-spec/actions.ts +86 -0
  275. package/src/ui-spec/fallback.ts +19 -0
  276. package/src/ui-spec/slack.ts +17 -0
  277. package/src/ui-spec/validate.ts +169 -0
  278. package/src/utils/codex-rate-limits.ts +159 -0
  279. package/src/utils/credentials.ts +2 -0
  280. package/src/utils/error-tracker.ts +19 -0
  281. package/src/utils/provider-account-telemetry.ts +331 -0
  282. package/src/utils/reasoning-events.ts +107 -0
  283. package/src/utils/subscription-plans.ts +11 -59
  284. package/src/utils/task-ui-spec.ts +67 -0
  285. package/src/workflows/task-step-routing.ts +8 -3
  286. package/templates/extensions/sql-admin-only/README.md +2 -1
  287. package/templates/extensions/sql-admin-only/hooks.ts +7 -3
  288. package/templates/extensions/sql-admin-only/manifest.json +1 -1
  289. package/templates/skills/apps/SKILL.md +32 -5
  290. package/templates/skills/apps/content.md +32 -5
  291. package/templates/skills/ui-spec/config.json +14 -0
  292. package/templates/skills/ui-spec/content.md +127 -0
  293. package/dist/acp-adapter-jqn86aam.js +0 -16
  294. package/dist/cli-srtkr1h2.js +0 -12078
  295. package/dist/fx-adapter-0zrkfbkd.js +0 -19
  296. package/dist/grok-adapter-3db1c538.js +0 -19
  297. package/dist/handlers-k22n8mnn.js +0 -33
  298. package/dist/index-8xcyd3mc.js +0 -33
  299. package/dist/index-9sy2bh6n.js +0 -38
  300. package/dist/index-b24j7t2m.js +0 -12797
  301. package/dist/index-wjd56k1v.js +0 -34
  302. package/dist/lead-atxf3q6e.js +0 -72
  303. package/dist/thread-buffer-4yz236d0.js +0 -36
  304. package/dist/worker-p4hbtcy3.js +0 -72
  305. package/dist/{cli-j49yqpvh.js → cli-7evph51z.js} +3 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@desplega.ai/agent-swarm",
3
- "version": "2.9.0",
3
+ "version": "2.9.1",
4
4
  "description": "agent-swarm.dev — an open-source operating system for AI work: a lead agent breaks goals into tasks, routes them to specialized workers such as Claude Code or Codex, runs each worker in an isolated container, and preserves shared memory, tools, schedules, and review gates so delegated work compounds across sessions.",
5
5
  "keywords": [
6
6
  "agent-swarm.dev",
@@ -211,10 +211,10 @@
211
211
  "@asteasolutions/zod-to-openapi": "^8.0.0",
212
212
  "@aws-sdk/client-bedrock": "3.1048.0",
213
213
  "@boxd-sh/sdk": "0.2.20",
214
- "@chat-adapter/discord": "4.41.1",
215
- "@chat-adapter/slack": "4.41.1",
216
- "@chat-adapter/teams": "4.41.1",
217
- "@chat-adapter/telegram": "4.41.1",
214
+ "@chat-adapter/discord": "4.44.0",
215
+ "@chat-adapter/slack": "4.44.0",
216
+ "@chat-adapter/teams": "4.44.0",
217
+ "@chat-adapter/telegram": "4.44.0",
218
218
  "@cursor/sdk": "1.3.1",
219
219
  "@desplega.ai/agent-fs-just-bash": "0.18.23",
220
220
  "@desplega.ai/business-use": "^0.4.2",
@@ -224,6 +224,7 @@
224
224
  "@inkjs/ui": "^2.0.0",
225
225
  "@jitl/quickjs-singlefile-mjs-release-sync": "0.32.0",
226
226
  "@json-render/chat": "0.22.0",
227
+ "@json-render/core": "0.22.0",
227
228
  "@linear/sdk": "^77.0.0",
228
229
  "@modelcontextprotocol/sdk": "1.32.1",
229
230
  "@openai/codex": "0.167.0",
@@ -243,7 +244,7 @@
243
244
  "@x402/evm": "^2.5.0",
244
245
  "@x402/fetch": "^2.5.0",
245
246
  "ai": "^6.0.116",
246
- "chat": "4.41.1",
247
+ "chat": "4.44.0",
247
248
  "cron-parser": "^5.4.0",
248
249
  "date-fns": "^4.1.0",
249
250
  "e2b": "2.26.0",
@@ -47,6 +47,7 @@
47
47
  "Timeline",
48
48
  "SchemaForm",
49
49
  "SessionThread",
50
+ "PageFrame",
50
51
  "ElementRef",
51
52
  "ElementSlot"
52
53
  ],
@@ -2212,7 +2213,7 @@
2212
2213
  }
2213
2214
  },
2214
2215
  "Form": {
2215
- "description": "Field form. Values live in state under `/forms/<id>/<field>`; `onSubmit` chains receive `$form` (all collected values) and `$form: \"<field>\"` for one. `app.mutate` failures in the chain surface inline under the fields (not the page banner), and the submit button shows a pending spinner while the chain runs. `kind: \"file\"` attaches agent-fs files with the VIEWER's own agent-fs key (swarm default drive): `source: \"upload\"` (default) picks local files and uploads them on submit, before the chain, to `<dir>/<timestamp>-<id>-<n>-<name>` (unique per file, across fields and submits); `\"pick\"` opens a browser of `dir` (or `/`) to attach a file that already exists; `\"both\"` offers both. `$form.<name>` is the path, or an array of paths with `multiple: true`. `accept` filters the file picker. An upload failure stops the chain and keeps the values. Without an agent-fs connection the field shows a \"Connect agent-fs\" card, and a required file field disables submit.",
2216
+ "description": "Field form. Values live in state under `/forms/<id>/<field>`; `onSubmit` chains receive `$form` (all collected values) and `$form: \"<field>\"` for one. `app.mutate` failures in the chain surface inline under the fields (not the page banner), and the submit button shows a pending spinner while the chain runs. `kind: \"file\"` attaches agent-fs files with the VIEWER's own agent-fs key (swarm default drive): `source: \"upload\"` (default) picks local files and uploads them on submit, before the chain, to `<dir>/<timestamp>-<id>-<n>-<name>` (unique per file, across fields and submits); `\"pick\"` opens a browser of `dir` (or `/`) to attach a file that already exists; `\"both\"` offers both. `$form.<name>` is the path, or an array of paths with `multiple: true`. `accept` filters the file picker. An upload failure stops the chain and keeps the values. After an `app.mutate` create step, later steps read the new row's id as `{ \"$chain\": \"createdRowId\" }` (to open it, or as an `app.action` session key); before one runs the key is null and its param is dropped. Use it, not `$state`: the renderer resolves a chain's `$state` reads when the form renders. Without an agent-fs connection the field shows a \"Connect agent-fs\" card, and a required file field disables submit.",
2216
2217
  "props": {
2217
2218
  "$schema": "http://json-schema.org/draft-07/schema#",
2218
2219
  "type": "object",
@@ -3440,7 +3441,7 @@
3440
3441
  }
3441
3442
  },
3442
3443
  "SessionThread": {
3443
- "description": "A chat on an app page, rendered as the dashboard's session conversation (the same turn timeline and composer as the \"Session about this page\" panel). The session is found by key, not stored in a row: the server keys each task an `app.action` step creates as `task:app:<appId>:<sessionKey>:user:<viewer>`, and the thread shows the viewer's newest session with that key. The viewer must have an identity: with none picked the composer is disabled. `scope: \"shared\"` (one session for everyone) comes in a follow-up PR and is rejected today. A person bubble shows the `message` of an app-action input (cut at 4,000 characters), not the whole agent prompt. Sending routes three ways: no session yet → run `onDispatch`, whose `app.action` creates the session's root task; a task in the session not finished → the shared composer steers the newest unfinished task on any agent (steering source `app-page`; Queue, or Interrupt where the harness supports it); every task finished → run `onDispatch` again, chaining off the newest task via `\"parentTaskId\": { \"$chain\": \"leafTaskId\" }`. `$chain.leafTaskId` is `null` when there is no session, and a null `$chain` key drops the param, so one `onDispatch` covers the first message and follow-ups. Each `app.action` step is sent with the session and `followUp: false` (unless it sets `followUp` itself), so the Lead adds no review task. Messages are text only (no attachments or mic). After each send the composer stays busy until the new task shows up (at most 30 s). \"New session\" starts over: the next message creates a new root, and the older session is no longer shown. The composer draft is mirrored to `/ui/<id>/value` (namespaced per instance inside an element). The thread is 420 px tall; `fill: true` fills a `fill`-aware parent instead, with the timeline scrolling inside it and the composer pinned to the bottom.",
3444
+ "description": "A chat on an app page, rendered as the dashboard's session conversation (the same turn timeline and composer as the \"Session about this page\" panel). The session is found by key, not stored in a row: the server keys each task an `app.action` step creates as `task:app:<appId>:<sessionKey>:user:<viewer>`, and the thread shows the viewer's newest session with that key. The viewer must have an identity: with none picked the composer is disabled. `scope: \"shared\"` (one session for everyone) comes in a follow-up PR and is rejected today. A person bubble shows the `message` of an app-action input (cut at 4,000 characters), not the whole agent prompt. Sending routes three ways: no session yet → run `onDispatch`, whose `app.action` creates the session's root task; a task in the session not finished → the shared composer steers the newest unfinished task on any agent (steering source `app-page`; Queue, or Interrupt where the harness supports it); every task finished → run `onDispatch` again, chaining off the newest task via `\"parentTaskId\": { \"$chain\": \"leafTaskId\" }`. `$chain.leafTaskId` is `null` when there is no session, and a null `$chain` key drops the param, so one `onDispatch` covers the first message and follow-ups. Each `app.action` step is sent with the session and `followUp: false` (unless it sets `followUp` itself), so the Lead adds no review task. A chain elsewhere can start the session for the viewer before the thread mounts: an `app.action` step with `session: { key: <this sessionKey> }` (e.g. a create form that sends the idea, then navigates here) creates the root, and the thread shows it as its first message with no second send. Messages are text only (no attachments or mic). After each send the composer stays busy until the new task shows up (at most 30 s). \"New session\" starts over: the next message creates a new root, and the older session is no longer shown. The composer draft is mirrored to `/ui/<id>/value` (namespaced per instance inside an element). The thread is 420 px tall; `fill: true` fills a `fill`-aware parent instead, with the timeline scrolling inside it and the composer pinned to the bottom.",
3444
3445
  "props": {
3445
3446
  "$schema": "http://json-schema.org/draft-07/schema#",
3446
3447
  "type": "object",
@@ -3489,6 +3490,30 @@
3489
3490
  "additionalProperties": false
3490
3491
  }
3491
3492
  },
3493
+ "PageFrame": {
3494
+ "description": "A live swarm Page: the same body `/pages/<pageId>` shows, clickable. An HTML page runs in a sandboxed iframe (scripts, forms and popups, never top navigation); a JSON page renders inline. It checks the page every 3 s and reloads by itself when the page changes (a new version, a restore, a theme switch), with no viewer action; a reload resets scroll and any state inside the page. Bind `pageId` to a row or route param (`{ \"$state\": \"/queries/<name>/data/0/pageId\" }`). The viewer needs read access to the page: an authed page launches a page session for them, a password page asks for the password. `device: \"mobile\"` narrows the frame to 390 px, so the page's own media queries see a phone (a JSON page follows the dashboard viewport instead). 640 px tall by default; `height` sets it, `fill: true` grows inside a `fill`-aware parent. An empty `pageId` shows \"No page selected\".",
3495
+ "props": {
3496
+ "$schema": "http://json-schema.org/draft-07/schema#",
3497
+ "type": "object",
3498
+ "properties": {
3499
+ "pageId": {
3500
+ "type": "string"
3501
+ },
3502
+ "device": {
3503
+ "type": "string",
3504
+ "enum": ["desktop", "mobile"]
3505
+ },
3506
+ "height": {
3507
+ "type": "string"
3508
+ },
3509
+ "fill": {
3510
+ "type": "boolean"
3511
+ }
3512
+ },
3513
+ "required": ["pageId"],
3514
+ "additionalProperties": false
3515
+ }
3516
+ },
3492
3517
  "ElementRef": {
3493
3518
  "description": "Reference a reusable element from this app or an exported element from another app. Consumer children are inserted at the target's ElementSlot.",
3494
3519
  "slots": ["default"],
@@ -3705,7 +3730,7 @@
3705
3730
  }
3706
3731
  },
3707
3732
  "app.action": {
3708
- "description": "Invoke a named custom action from the app definition's `actions` map (script- or task-backed). Result lands in state at `/actions/<name>`.",
3733
+ "description": "Invoke a named custom action from the app definition's `actions` map (script- or task-backed). Result lands in state at `/actions/<name>`. `session: { key, scope? }` files a task-kind action's task under a SessionThread session for the viewer (see that param), so a Form chain like create row → `app.action` with `session: { key: { $chain: \"createdRowId\" } }` → `app.navigate` to the page whose SessionThread uses that id starts the chat in one click.",
3709
3734
  "params": {
3710
3735
  "$schema": "http://json-schema.org/draft-07/schema#",
3711
3736
  "type": "object",
@@ -3722,6 +3747,21 @@
3722
3747
  },
3723
3748
  "parentTaskId": {
3724
3749
  "type": "string"
3750
+ },
3751
+ "session": {
3752
+ "description": "Task-kind actions only — start or join the viewer's SessionThread session from any chain, e.g. a create form that sends the idea as the chat's first message. `key` is the SessionThread `sessionKey` to file the task under: a plain token (^[A-Za-z0-9_-]{1,128}$) or a binding such as { \"$chain\": \"createdRowId\" } (in a Form chain, the row an earlier create step just made). The server keys the task as task:app:<appId>:<key>:user:<viewer>, the exact key a SessionThread with that `sessionKey` reads, so the thread shows it as its first message. `scope` \"user\" (default); \"shared\" is rejected today. A session step defaults to `followUp: false`. Inside a SessionThread `onDispatch` the thread's own session replaces this param.",
3753
+ "type": "object",
3754
+ "properties": {
3755
+ "key": {
3756
+ "type": "string"
3757
+ },
3758
+ "scope": {
3759
+ "type": "string",
3760
+ "enum": ["user", "shared"]
3761
+ }
3762
+ },
3763
+ "required": ["key"],
3764
+ "additionalProperties": false
3725
3765
  }
3726
3766
  },
3727
3767
  "required": ["name"],
@@ -576,6 +576,22 @@ function actionParams(
576
576
  issue(appendPath(paramsPath, "name"), `unknown app action "${String(params.name)}"`),
577
577
  );
578
578
  }
579
+ // Same rules as `SessionThread.sessionKey` / `scope`: the key lands in a
580
+ // server-built context key; a bound key is checked at send time.
581
+ const session = params.session;
582
+ if (isPlainObject(session)) {
583
+ const sessionPath = appendPath(paramsPath, "session");
584
+ if (typeof session.key === "string" && !SESSION_KEY.test(session.key)) {
585
+ result.issues.push(
586
+ issue(appendPath(sessionPath, "key"), "session key must match ^[A-Za-z0-9_-]{1,128}$"),
587
+ );
588
+ }
589
+ if (session.scope === "shared") {
590
+ result.issues.push(
591
+ issue(appendPath(sessionPath, "scope"), 'scope "shared" is not supported yet'),
592
+ );
593
+ }
594
+ }
579
595
  } else if (step.action === "ui.toast") {
580
596
  // The Undo chain runs through the same handlers as any other chain, so
581
597
  // its steps get the same per-action checks (models, queries, actions).
@@ -1597,6 +1613,9 @@ function agentFsPropIssues(
1597
1613
  return issues;
1598
1614
  }
1599
1615
 
1616
+ /** `PageFrame.pageId` literal: a page id as the `/pages/:id` route takes it (no slugs). */
1617
+ const PAGE_FRAME_ID = /^[a-f0-9]{32}$/i;
1618
+
1600
1619
  function isAgentFsPath(value: string): boolean {
1601
1620
  return value.startsWith("/") && !value.split("/").includes("..");
1602
1621
  }
@@ -1830,6 +1849,14 @@ export function validatePage(
1830
1849
  if (type === "File" || type === "Files") {
1831
1850
  issues.push(...agentFsPropIssues(type, rawElement.props, elementPath));
1832
1851
  }
1852
+ if (
1853
+ type === "PageFrame" &&
1854
+ typeof rawElement.props.pageId === "string" &&
1855
+ rawElement.props.pageId !== "" &&
1856
+ !PAGE_FRAME_ID.test(rawElement.props.pageId)
1857
+ ) {
1858
+ issues.push(issue(`${elementPath}.props.pageId`, "must be a page id (32 hex characters)"));
1859
+ }
1833
1860
  if (type === "Form") issues.push(...formFileFieldIssues(rawElement.props, elementPath));
1834
1861
  if (type === "DateRange") issues.push(...dateRangePropIssues(rawElement.props, elementPath));
1835
1862
  if (type === "Table") {
@@ -12,6 +12,7 @@ import {
12
12
  ProviderNameSchema,
13
13
  type ReasoningEffort,
14
14
  ReasoningEffortSchema,
15
+ SUPERSEDED_WORKFLOW_TASK_REASON,
15
16
  } from "../../types";
16
17
  import {
17
18
  checkProfileForAgent,
@@ -236,12 +237,14 @@ export async function updateModelProfile(
236
237
  * later write than the supersede (HTTP supersede, heartbeat remediation), and
237
238
  * after a restart the heartbeat's orphan repair makes it, inside the same
238
239
  * window (`SUPERSEDED_RESUME_REPAIR_WINDOW_MS`). Binds one parameter: the
239
- * oldest `finishedAt` the repair still covers.
240
+ * oldest `finishedAt` the repair still covers. A workflow-step task superseded
241
+ * by a queued retry gets no resume, so it never holds its profile.
240
242
  */
241
243
  const TASK_HOLDS_PROFILE_SQL = `(
242
244
  t.status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
243
245
  OR (t.status = 'superseded'
244
246
  AND t.workflowRunStepId IS NULL
247
+ AND t.failureReason IS NOT '${SUPERSEDED_WORKFLOW_TASK_REASON}'
245
248
  AND (t.finishedAt IS NULL OR t.finishedAt > ?)
246
249
  AND NOT EXISTS (
247
250
  SELECT 1 FROM agent_tasks c WHERE c.parentTaskId = t.id AND c.taskType = 'resume')))`;
@@ -0,0 +1,219 @@
1
+ import { chatgptSubscriptionModelId } from "@desplega/model-catalog";
2
+ import {
3
+ type ProviderName,
4
+ type SessionCost,
5
+ type SessionCostModelBreakdown,
6
+ SessionCostModelBreakdownSchema,
7
+ type SessionCostSource,
8
+ } from "../../types";
9
+ import { getDbClient } from "./runtime";
10
+
11
+ /**
12
+ * Sessions recorded before migration 307 carry no credential of their own.
13
+ * Those legacy rows fall back to their task's credential, as usage read it
14
+ * before 307. Newer rows keep their own, null included. Needs `t` joined.
15
+ */
16
+ const LEGACY_CREDENTIAL_SQL =
17
+ "(sc.credentialKeyType IS NULL AND sc.createdAt < (SELECT applied_at FROM _migrations WHERE version = 307))";
18
+ export const CREDENTIAL_TYPE_SQL = `CASE WHEN ${LEGACY_CREDENTIAL_SQL} THEN t.credentialKeyType ELSE sc.credentialKeyType END`;
19
+ export const CREDENTIAL_SUFFIX_SQL = `CASE WHEN ${LEGACY_CREDENTIAL_SQL} THEN t.credentialKeySuffix ELSE sc.credentialKeySuffix END`;
20
+
21
+ export type SessionCostRow = {
22
+ id: string;
23
+ sessionId: string;
24
+ taskId: string | null;
25
+ agentId: string;
26
+ totalCostUsd: number;
27
+ inputTokens: number;
28
+ outputTokens: number;
29
+ credentialKeyType: string | null;
30
+ credentialKeySuffix: string | null;
31
+ harness: ProviderName | null;
32
+ cacheReadTokens: number | null;
33
+ cacheWriteTokens: number | null;
34
+ // Migration 063 additions:
35
+ reasoningOutputTokens: number;
36
+ thinkingTokens: number;
37
+ durationMs: number;
38
+ numTurns: number | null;
39
+ model: string;
40
+ isError: number;
41
+ costSource: string;
42
+ harnessCostUsd: number | null;
43
+ cacheWrite5mTokens: number | null;
44
+ cacheWrite1hTokens: number | null;
45
+ modelBreakdown: string | null;
46
+ createdAt: string;
47
+ };
48
+
49
+ export function rowToSessionCost(row: SessionCostRow): SessionCost {
50
+ let modelBreakdown: SessionCostModelBreakdown[] | null = null;
51
+ if (row.modelBreakdown) {
52
+ try {
53
+ const parsed = SessionCostModelBreakdownSchema.array().safeParse(
54
+ JSON.parse(row.modelBreakdown),
55
+ );
56
+ if (parsed.success) modelBreakdown = parsed.data;
57
+ } catch {
58
+ // Corrupt JSON (manual edits, partial writes) must not fail the listing.
59
+ }
60
+ }
61
+
62
+ return {
63
+ id: row.id,
64
+ sessionId: row.sessionId,
65
+ taskId: row.taskId ?? undefined,
66
+ agentId: row.agentId,
67
+ credentialKeyType: row.credentialKeyType,
68
+ credentialKeySuffix: row.credentialKeySuffix,
69
+ harness: row.harness,
70
+ totalCostUsd: row.totalCostUsd,
71
+ inputTokens: row.inputTokens,
72
+ outputTokens: row.outputTokens,
73
+ cacheReadTokens: row.cacheReadTokens,
74
+ cacheWriteTokens: row.cacheWriteTokens,
75
+ reasoningOutputTokens: row.reasoningOutputTokens ?? 0,
76
+ thinkingTokens: row.thinkingTokens ?? 0,
77
+ durationMs: row.durationMs,
78
+ numTurns: row.numTurns,
79
+ model: row.model,
80
+ isError: row.isError === 1,
81
+ costSource: (row.costSource as SessionCostSource) ?? "harness",
82
+ harnessCostUsd: row.harnessCostUsd,
83
+ cacheWrite5mTokens: row.cacheWrite5mTokens,
84
+ cacheWrite1hTokens: row.cacheWrite1hTokens,
85
+ modelBreakdown,
86
+ createdAt: row.createdAt,
87
+ };
88
+ }
89
+
90
+ export interface CreateSessionCostInput {
91
+ credentialKeyType?: string | null;
92
+ credentialKeySuffix?: string | null;
93
+ harness?: ProviderName | null;
94
+ id?: string;
95
+ sessionId: string;
96
+ taskId?: string;
97
+ agentId: string;
98
+ totalCostUsd: number;
99
+ inputTokens?: number;
100
+ outputTokens?: number;
101
+ cacheReadTokens?: number | null;
102
+ cacheWriteTokens?: number | null;
103
+ // Migration 063 additions, adapters that have these numbers should pass
104
+ // them; defaulting to 0 preserves the old write shape for callers that don't.
105
+ reasoningOutputTokens?: number;
106
+ thinkingTokens?: number;
107
+ durationMs: number;
108
+ // Nullable: some adapters (claude when num_turns is absent) can't honestly
109
+ // report a turn count; we prefer null over a faked 1.
110
+ numTurns: number | null;
111
+ model: string;
112
+ isError?: boolean;
113
+ /**
114
+ * Phase 6 (migration 063 added 'unpriced'): where `totalCostUsd` came from.
115
+ * - 'harness' , value reported by the harness as-is (default).
116
+ * - 'pricing-table' , value recomputed by the API from `pricing` rows.
117
+ * - 'unpriced' , recompute attempted but no matching pricing rows;
118
+ * `totalCostUsd` is whatever the worker submitted.
119
+ * - 'estimated' , fallback token counts priced at an assumed model
120
+ * (amp with a failed thread export).
121
+ */
122
+ costSource?: SessionCostSource;
123
+ harnessCostUsd?: number | null;
124
+ cacheWrite5mTokens?: number | null;
125
+ cacheWrite1hTokens?: number | null;
126
+ modelBreakdown?: SessionCostModelBreakdown[] | null;
127
+ }
128
+
129
+ export class SessionCostConflictError extends Error {}
130
+
131
+ /** Insert once. Existing session identity and attribution never change. */
132
+ export async function insertSessionCost(
133
+ input: CreateSessionCostInput,
134
+ ): Promise<{ cost: SessionCost; created: boolean }> {
135
+ return getDbClient().transaction(async (client) => {
136
+ const id = input.id ?? crypto.randomUUID();
137
+ // Taskless triggers register a synthetic ID that has no task row.
138
+ const active = await client.get<{ agentId: string; taskId: string | null }>(
139
+ `SELECT a.agentId, t.id AS taskId FROM active_sessions a
140
+ LEFT JOIN agent_tasks t ON t.id = a.taskId
141
+ WHERE a.runnerSessionId = ? OR a.id = ? LIMIT 1`,
142
+ [input.sessionId, input.sessionId],
143
+ );
144
+ if (active && (active.agentId !== input.agentId || active.taskId !== (input.taskId ?? null))) {
145
+ throw new SessionCostConflictError("Session cost identity conflicts with an active session.");
146
+ }
147
+ const existing = await client.get<SessionCostRow>(
148
+ "SELECT * FROM session_costs WHERE id = ? OR sessionId = ? ORDER BY CASE WHEN id = ? THEN 0 ELSE 1 END, createdAt, id LIMIT 1",
149
+ [id, input.sessionId, id],
150
+ );
151
+ if (existing) {
152
+ if (
153
+ existing.sessionId !== input.sessionId ||
154
+ existing.agentId !== input.agentId ||
155
+ existing.taskId !== (input.taskId ?? null)
156
+ ) {
157
+ throw new SessionCostConflictError(
158
+ "Session cost identity conflicts with an existing record.",
159
+ );
160
+ }
161
+ // Reposts return the original counters and attribution, including unknown values.
162
+ return { cost: rowToSessionCost(existing), created: false };
163
+ }
164
+ const costSource: SessionCostSource = input.costSource ?? "harness";
165
+ const reasoningOutputTokens = input.reasoningOutputTokens ?? 0;
166
+ const thinkingTokens = input.thinkingTokens ?? 0;
167
+ await client.run(
168
+ `INSERT INTO session_costs (
169
+ id, sessionId, taskId, agentId,
170
+ totalCostUsd, inputTokens, outputTokens,
171
+ cacheReadTokens, cacheWriteTokens,
172
+ reasoningOutputTokens, thinkingTokens,
173
+ durationMs, numTurns, model, isError,
174
+ costSource, harnessCostUsd, cacheWrite5mTokens, cacheWrite1hTokens,
175
+ modelBreakdown, credentialKeyType, credentialKeySuffix, harness, createdAt
176
+ )
177
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
178
+ ON CONFLICT(id) DO NOTHING`,
179
+ [
180
+ id,
181
+ input.sessionId,
182
+ input.taskId ?? null,
183
+ input.agentId,
184
+ input.totalCostUsd,
185
+ input.inputTokens ?? 0,
186
+ input.outputTokens ?? 0,
187
+ input.cacheReadTokens ?? null,
188
+ input.cacheWriteTokens ?? null,
189
+ reasoningOutputTokens,
190
+ thinkingTokens,
191
+ input.durationMs,
192
+ input.numTurns,
193
+ // Cost rows group by the underlying model, while task configuration and
194
+ // session logs retain the pi route used to select credentials.
195
+ chatgptSubscriptionModelId(input.model)?.toLowerCase() ?? input.model,
196
+ input.isError ? 1 : 0,
197
+ costSource,
198
+ input.harnessCostUsd ?? null,
199
+ input.cacheWrite5mTokens ?? null,
200
+ input.cacheWrite1hTokens ?? null,
201
+ input.modelBreakdown
202
+ ? JSON.stringify(
203
+ input.modelBreakdown.map((entry) => ({
204
+ ...entry,
205
+ model: chatgptSubscriptionModelId(entry.model)?.toLowerCase() ?? entry.model,
206
+ })),
207
+ )
208
+ : null,
209
+ input.credentialKeyType ?? null,
210
+ input.credentialKeySuffix ?? null,
211
+ input.harness ?? null,
212
+ ],
213
+ );
214
+
215
+ const row = await client.get<SessionCostRow>("SELECT * FROM session_costs WHERE id = ?", [id]);
216
+ if (!row) throw new Error("Session cost record is missing after insertion.");
217
+ return { cost: rowToSessionCost(row), created: true };
218
+ });
219
+ }
@@ -0,0 +1,36 @@
1
+ import { classifyClaudeThinking } from "../../utils/reasoning-events";
2
+ import type { DbExecutor } from "../db-client";
3
+
4
+ // Marks the pre-tool update among the thinking lines of `messageId` that sit
5
+ // directly before its tool_use line (classifyClaudeThinking). Reads rows from
6
+ // this transaction and from earlier POSTs alike.
7
+ export async function classifyClaudeUpdate(
8
+ tx: DbExecutor,
9
+ sessionId: string,
10
+ messageId: string,
11
+ toolLineNumber: number,
12
+ ): Promise<void> {
13
+ const since = new Date(Date.now() - 10 * 60_000).toISOString();
14
+ // INDEXED BY: with `sessionId = ?` the planner would pick the sessionId
15
+ // index and read every line of the session.
16
+ const rows = await tx.query<{ id: string; lineNumber: number; messageId: string | null }>(
17
+ `SELECT id, lineNumber, json_extract(content, '$.message.id') AS messageId
18
+ FROM session_logs INDEXED BY idx_session_logs_reasoning
19
+ WHERE reasoningChars IS NOT NULL AND createdAt >= ? AND cli = 'claude' AND sessionId = ?`,
20
+ [since, sessionId],
21
+ );
22
+ const byLine = new Map<number, string>();
23
+ for (const row of rows) if (row.messageId === messageId) byLine.set(row.lineNumber, row.id);
24
+ const runIds: string[] = [];
25
+ for (let n = toolLineNumber - 1; byLine.has(n); n--) runIds.unshift(byLine.get(n) as string);
26
+ const kinds = classifyClaudeThinking([
27
+ ...runIds.map(() => ({ type: "thinking" })),
28
+ { type: "tool_use" },
29
+ ]);
30
+ for (const [i, kind] of kinds.entries()) {
31
+ const id = runIds[i];
32
+ if (kind === "update" && id) {
33
+ await tx.run("UPDATE session_logs SET reasoningKind = 'update' WHERE id = ?", [id]);
34
+ }
35
+ }
36
+ }
@@ -21,6 +21,7 @@ import {
21
21
  parseModelTier,
22
22
  ReasoningEffortSchema,
23
23
  RoutingAffinitySchema,
24
+ SUPERSEDED_WORKFLOW_TASK_REASON,
24
25
  TaskSlackParticipantsSchema,
25
26
  TERMINAL_TASK_STATUSES,
26
27
  } from "../../../types";
@@ -657,8 +658,10 @@ export const SUPERSEDED_RESUME_REPAIR_WINDOW_MS = 24 * 60 * 60 * 1000;
657
658
  * Superseded tasks that never got a resume child. Both supersede paths
658
659
  * (heartbeat remediation and `POST /api/tasks/:id/supersede`) supersede
659
660
  * first and create the resume in a later, separate write, so a process
660
- * crash between the two leaves this state. Workflow steps are failed, not
661
- * superseded, and are excluded. `finishedBefore` keeps the sweep from racing
661
+ * crash between the two leaves this state. Workflow steps are excluded: a cut
662
+ * step is failed, and one whose retry was queued is superseded with its
663
+ * `failureReason` kept and its step id cleared, so it is matched on the reason.
664
+ * `finishedBefore` keeps the sweep from racing
662
665
  * an in-flight supersede; `finishedAfter` bounds how far back it repairs.
663
666
  */
664
667
  export async function getSupersededTasksWithoutResume(
@@ -669,13 +672,14 @@ export async function getSupersededTasksWithoutResume(
669
672
  `SELECT * FROM agent_tasks t
670
673
  WHERE t.status = 'superseded'
671
674
  AND t.workflowRunStepId IS NULL
675
+ AND t.failureReason IS NOT ?
672
676
  AND t.finishedAt < ?
673
677
  AND t.finishedAt > ?
674
678
  AND NOT EXISTS (
675
679
  SELECT 1 FROM agent_tasks c WHERE c.parentTaskId = t.id AND c.taskType = 'resume'
676
680
  )
677
681
  ORDER BY t.finishedAt ASC`,
678
- [finishedBefore, finishedAfter],
682
+ [SUPERSEDED_WORKFLOW_TASK_REASON, finishedBefore, finishedAfter],
679
683
  );
680
684
  return rows.map(rowToAgentTask);
681
685
  }
@@ -13,7 +13,7 @@ import type {
13
13
  RuntimePool,
14
14
  TaskAttachment,
15
15
  } from "../../../types";
16
- import { isTerminalTaskStatus } from "../../../types";
16
+ import { isTerminalTaskStatus, SUPERSEDED_WORKFLOW_TASK_REASON } from "../../../types";
17
17
  import { scrubSecrets } from "../../../utils/secret-scrubber";
18
18
  import { emitTaskStarted } from "../../task-lifecycle-events";
19
19
  import { publishWorkerNudge } from "../../worker-nudges";
@@ -1001,6 +1001,38 @@ export async function supersedeTask(
1001
1001
  return row ? rowToAgentTask(row) : null;
1002
1002
  }
1003
1003
 
1004
+ /**
1005
+ * Move a workflow-step task that a supersede cut failed (`failed` with
1006
+ * `SUPERSEDED_WORKFLOW_TASK_REASON`) to `superseded` once the engine has
1007
+ * queued a retry for its step, so it no longer counts as a real failure. The
1008
+ * engine still sees `failed` first: its retry path runs off `task.failed`.
1009
+ * Keeps `failureReason` and `finishedAt`; emits no `task.superseded` event
1010
+ * (there is no resume task, and the failure listeners already ran). No-op
1011
+ * unless the row is still exactly that failure. Returns whether it moved.
1012
+ */
1013
+ export async function markWorkflowStepTaskSuperseded(id: string): Promise<boolean> {
1014
+ const row = await getDbClient().get<AgentTaskRow>(
1015
+ `UPDATE agent_tasks
1016
+ SET status = 'superseded',
1017
+ lastUpdatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
1018
+ WHERE id = ? AND status = 'failed' AND failureReason = ?
1019
+ RETURNING *`,
1020
+ [id, SUPERSEDED_WORKFLOW_TASK_REASON],
1021
+ );
1022
+ if (!row) return false;
1023
+ try {
1024
+ await dependencies.createLogEntry({
1025
+ eventType: "task_superseded",
1026
+ taskId: id,
1027
+ agentId: row.agentId ?? undefined,
1028
+ oldValue: "failed",
1029
+ newValue: "superseded",
1030
+ metadata: { reason: SUPERSEDED_WORKFLOW_TASK_REASON, resumeTaskId: null },
1031
+ });
1032
+ } catch {}
1033
+ return true;
1034
+ }
1035
+
1004
1036
  /**
1005
1037
  * Settle the dependents of a superseded task. With a resume id, every
1006
1038
  * never-started dependent has the superseded id in `dependsOn` replaced by the