@desplega.ai/agent-swarm 2.13.4 → 2.14.0

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 (526) hide show
  1. package/dist/acp-adapter-99n6z9ky.js +17 -0
  2. package/dist/{acp-targets-zrk9k0n7.js → acp-targets-23exz4z4.js} +10 -10
  3. package/dist/{actions-acqqj9jn.js → actions-zcr25x27.js} +61 -40
  4. package/dist/{agent-fs-provision-zmaykqnd.js → agent-fs-provision-7fa9e12e.js} +4 -4
  5. package/dist/{amp-adapter-a7ts8tmw.js → amp-adapter-s7ytmv6b.js} +3 -3
  6. package/dist/{anthropic-messages-88b7s3n9.js → anthropic-messages-vdd1zmha.js} +10 -10
  7. package/dist/{app-tmwa442h.js → app-5d3sz1hy.js} +7 -7
  8. package/dist/{approval-notifications-6psaaaye.js → approval-notifications-7qgkzkzx.js} +8 -8
  9. package/dist/{assistant-564v6emv.js → assistant-p2yvhc3j.js} +37 -32
  10. package/dist/{boot-args-schema-n099e0f2.js → boot-args-schema-ry6cb0p7.js} +1 -1
  11. package/dist/{boot-reembed-epvg4fp9.js → boot-reembed-2hkm3vz2.js} +1 -1
  12. package/dist/{boot-reembed-chx66qfk.js → boot-reembed-c9643ms3.js} +1 -1
  13. package/dist/{boot-scrub-sweep-dhkfp0a7.js → boot-scrub-sweep-3ycxr51t.js} +2 -2
  14. package/dist/{boot-seeds-m74fc07r.js → boot-seeds-2hzvvzg0.js} +4 -4
  15. package/dist/{boxd-451q55ys.js → boxd-9py3x0jb.js} +2 -2
  16. package/dist/{claude-adapter-hw63yj3j.js → claude-adapter-dnkww93e.js} +9 -9
  17. package/dist/{claude-managed-adapter-z5s7fx6p.js → claude-managed-adapter-yk0cr5x6.js} +4 -4
  18. package/dist/{claude-managed-setup-wee1762m.js → claude-managed-setup-4byxpp47.js} +5 -5
  19. package/dist/{claude-sdk-session-cktyqkpk.js → claude-sdk-session-4wf3dbvs.js} +13163 -12195
  20. package/dist/{cli-5rxsb3wq.js → cli-096aftq6.js} +12 -7
  21. package/dist/{cli-5rgm8p39.js → cli-0e914dp9.js} +3 -3
  22. package/dist/{cli-bzcwwebm.js → cli-0h6m6z5g.js} +1 -1
  23. package/dist/{cli-cah298e5.js → cli-0k7ppk9k.js} +231 -124
  24. package/dist/{cli-ja450998.js → cli-1nfabrt4.js} +8 -8
  25. package/dist/{cli-jzerrzgc.js → cli-2414h5r9.js} +8 -8
  26. package/dist/{cli-b768ek79.js → cli-24wervhz.js} +38 -0
  27. package/dist/{cli-93n305hm.js → cli-2ayk9gn8.js} +2 -2
  28. package/dist/{cli-kr0jpw9c.js → cli-2ckwgs7q.js} +1 -1
  29. package/dist/{cli-d5pc8ep0.js → cli-2savn6mm.js} +11 -100
  30. package/dist/{cli-jbrc98qb.js → cli-2zjxake1.js} +4 -4
  31. package/dist/{cli-4q2c8rxw.js → cli-37p61fcg.js} +15 -9
  32. package/dist/{cli-2vp0z049.js → cli-39t9d248.js} +1 -1
  33. package/dist/{cli-sa02jsqt.js → cli-3mhdmcd4.js} +1 -1
  34. package/dist/{cli-x2cem5vy.js → cli-3wsabyt0.js} +2 -2
  35. package/dist/{cli-dqgnbnxs.js → cli-466jjrwe.js} +16 -2
  36. package/dist/{cli-zhwjdhjr.js → cli-6ajyhxh7.js} +2 -2
  37. package/dist/{cli-3bxrrh53.js → cli-6yy4fepf.js} +4 -4
  38. package/dist/{cli-hhtbandk.js → cli-73rmgm45.js} +2 -2
  39. package/dist/{cli-8b4rpnwj.js → cli-7ca8hczj.js} +1 -1
  40. package/dist/{cli-0h8skzss.js → cli-7g5qj2ca.js} +4 -3
  41. package/dist/{cli-m1sns1da.js → cli-7w1fs01q.js} +2 -2
  42. package/dist/{cli-xwsm6xkr.js → cli-84wxwt3z.js} +1 -1
  43. package/dist/{cli-qzz6tz8s.js → cli-84xn7bgz.js} +1 -1
  44. package/dist/{cli-49aq3cyn.js → cli-879txsac.js} +5 -5
  45. package/dist/{cli-bv4vvnmg.js → cli-8vbxjzk0.js} +3 -3
  46. package/dist/{cli-7by7vp6m.js → cli-91amj3md.js} +3 -3
  47. package/dist/{cli-60dwk8tx.js → cli-930zbczq.js} +3 -3
  48. package/dist/{cli-7g3fg4gf.js → cli-9fwznq4p.js} +10 -10
  49. package/dist/{cli-4pbwg7sn.js → cli-9j1t3kf6.js} +2 -2
  50. package/dist/{cli-tzw1jr2t.js → cli-9j47sgzy.js} +2 -2
  51. package/dist/{cli-0fgvnb0x.js → cli-ad00h1st.js} +7 -7
  52. package/dist/{cli-kj84fqxz.js → cli-adzmmcvf.js} +19 -7
  53. package/dist/{cli-3tzmh38q.js → cli-ayxxkk3p.js} +68 -25
  54. package/dist/{cli-4vynxtrb.js → cli-bqfx72e6.js} +10 -3
  55. package/dist/{cli-8cas2xvp.js → cli-cbg0j1yt.js} +2716 -2643
  56. package/dist/{cli-fw67mnyc.js → cli-cg1q8ymp.js} +1 -1
  57. package/dist/{cli-he5nxaa8.js → cli-dw9rtjm3.js} +1 -1
  58. package/dist/{cli-jg5txpm6.js → cli-dy754erz.js} +83 -1
  59. package/dist/{cli-tsc3pdfd.js → cli-edxfzgah.js} +4 -4
  60. package/dist/{cli-hyqksecw.js → cli-ejnhs815.js} +15 -15
  61. package/dist/{cli-k0nebh10.js → cli-enavhq6r.js} +1 -1
  62. package/dist/{cli-ea7nz50q.js → cli-f2rwt43y.js} +14 -14
  63. package/dist/{cli-zjdhrzm0.js → cli-f9g96z28.js} +8 -8
  64. package/dist/{cli-rmgvwcmy.js → cli-fww016hh.js} +534 -70
  65. package/dist/{cli-rv3y60bt.js → cli-g6a696c0.js} +4 -4
  66. package/dist/{cli-z1vam71h.js → cli-gc6b94tj.js} +2 -2
  67. package/dist/{cli-p436yrzp.js → cli-gcyws2bp.js} +2 -2
  68. package/dist/{cli-srktrbby.js → cli-hzhv7yac.js} +1 -1
  69. package/dist/{cli-0p76my9q.js → cli-jcnc5ret.js} +44 -32
  70. package/dist/{cli-tr19nyn9.js → cli-jgq9xptq.js} +7 -7
  71. package/dist/{cli-pz1dp12c.js → cli-jwnac23b.js} +1 -1
  72. package/dist/{cli-904wk98s.js → cli-kc7vd07m.js} +917 -350
  73. package/dist/{cli-t0jmkcah.js → cli-kg63yp1r.js} +14 -14
  74. package/dist/{cli-ts5yv7dn.js → cli-krk8y8c7.js} +835 -157
  75. package/dist/{cli-jyhbvdga.js → cli-m0ea8ggd.js} +8 -10
  76. package/dist/{cli-944w9wb4.js → cli-md4tn21h.js} +20 -15
  77. package/dist/{cli-zexwhj3f.js → cli-mv8ft7b0.js} +10 -9
  78. package/dist/{cli-phdzn699.js → cli-mw1tmn3x.js} +217 -27
  79. package/dist/{cli-5ashycw3.js → cli-njvpngc6.js} +3 -3
  80. package/dist/{cli-9ah37a8a.js → cli-phe2vcw5.js} +10 -7
  81. package/dist/{cli-eds5xnsz.js → cli-phmy14hb.js} +2 -2
  82. package/dist/{cli-n1kjs58m.js → cli-pq0kv31y.js} +5 -5
  83. package/dist/{cli-pz1nq5xm.js → cli-q457ga28.js} +6 -6
  84. package/dist/{cli-s33bzmk0.js → cli-q5n3deaf.js} +1 -1
  85. package/dist/{cli-4fpa0zns.js → cli-qkbevqer.js} +3 -3
  86. package/dist/{cli-29h5239w.js → cli-qrwjk4xy.js} +5 -5
  87. package/dist/{cli-kezzteka.js → cli-r04ve9xw.js} +1 -1
  88. package/dist/{cli-3xqad83h.js → cli-r495stwd.js} +2 -2
  89. package/dist/{cli-1kvcsd2f.js → cli-r9d2tya0.js} +71 -3
  90. package/dist/{cli-ybte1fqc.js → cli-rp1n2xpd.js} +1 -1
  91. package/dist/{cli-fkpnx3vf.js → cli-rs1rzwp4.js} +3 -2
  92. package/dist/{cli-h9d3sdnc.js → cli-rzbsh6bw.js} +1 -1
  93. package/dist/{cli-94gx6ze9.js → cli-s4pccby1.js} +1 -1
  94. package/dist/{cli-cq4am6vg.js → cli-shyhb4t5.js} +10 -10
  95. package/dist/{cli-gtj12v95.js → cli-srq69pn1.js} +1 -1
  96. package/dist/{cli-azj9t1f9.js → cli-tc165vrb.js} +48 -5
  97. package/dist/{cli-gse7bp3z.js → cli-v4z5v3jd.js} +300 -81
  98. package/dist/{cli-p3knvk62.js → cli-vxmmttmt.js} +132 -53
  99. package/dist/{cli-404am6f3.js → cli-w4bvtxet.js} +7 -7
  100. package/dist/{cli-gkv0r2hq.js → cli-wd7b5hgc.js} +71 -9
  101. package/dist/{cli-akm6y2a8.js → cli-wvbaq052.js} +1 -1
  102. package/dist/{cli-ywy8yz6t.js → cli-wvgg7r4j.js} +2 -2
  103. package/dist/{cli-ka48vpev.js → cli-wym6rxgt.js} +165 -6
  104. package/dist/{cli-nc4pbwmp.js → cli-yd7e590v.js} +12 -12
  105. package/dist/{cli-3zrwrnz7.js → cli-yjb3cddd.js} +1 -1
  106. package/dist/{cli-7gbff32z.js → cli-z8t4485r.js} +2 -2
  107. package/dist/{cli-hdhpdrka.js → cli-ze1ndjs4.js} +4 -6
  108. package/dist/{cli-50wa8k4h.js → cli-zy9bb22b.js} +1 -2
  109. package/dist/cli.js +28 -28
  110. package/dist/{codex-adapter-2fs2c0n6.js → codex-adapter-eq61radw.js} +8 -8
  111. package/dist/{codex-hook-jxjv6dy5.js → codex-hook-8nmepvz6.js} +3 -3
  112. package/dist/{codex-login-ktfg1cxk.js → codex-login-vbd9707w.js} +1 -1
  113. package/dist/{codex-session-runner-r55tmx4c.js → codex-session-runner-rfx355h4.js} +9 -9
  114. package/dist/{commands-0mxdy9x8.js → commands-d1z0sx62.js} +3 -3
  115. package/dist/{controller-g3vkfhr4.js → controller-9hz6d8x3.js} +4 -4
  116. package/dist/{controllers-connect-4wdmncqt.js → controllers-connect-tz07d2xr.js} +24 -25
  117. package/dist/core-dynsv289.js +41 -0
  118. package/dist/{cursor-adapter-t9qb96q2.js → cursor-adapter-ef22ze3j.js} +2 -2
  119. package/dist/{db-487vvyv9.js → db-gd81d68c.js} +3 -3
  120. package/dist/{db-76p7w3gr.js → db-vrckks6q.js} +4 -2
  121. package/dist/{devin-adapter-3bp6rape.js → devin-adapter-kdt6a2bh.js} +1 -1
  122. package/dist/{dispatcher-64rp6w67.js → dispatcher-76as8w2t.js} +21 -22
  123. package/dist/{docker-a59g3ebm.js → docker-51ta7jsh.js} +2 -2
  124. package/dist/dsh-adapter-ypfvcdyz.js +11 -0
  125. package/dist/{e2b-dc8f6ctq.js → e2b-05kn3kpq.js} +16 -5
  126. package/dist/{e2b-3ykbe805.js → e2b-dm9r8hpy.js} +3 -3
  127. package/dist/{easter-egg-3d-jrrwyf55.js → easter-egg-3d-sg21j15g.js} +1 -1
  128. package/dist/{embedding-space-001hhhpk.js → embedding-space-zsdw37bb.js} +13 -23
  129. package/dist/{embeddings-esj19cnw.js → embeddings-p4e3e1m6.js} +1 -1
  130. package/dist/{event-bus-7gbsr0g4.js → event-bus-tvf2grf4.js} +1 -1
  131. package/dist/{execute-301hkxqg.js → execute-nztd0af0.js} +1 -1
  132. package/dist/{external-channel-w10e2j05.js → external-channel-717yzn4d.js} +2 -2
  133. package/dist/fx-adapter-9k0hptnz.js +20 -0
  134. package/dist/grok-adapter-skdj2pce.js +20 -0
  135. package/dist/handlers-5btjqkz6.js +39 -0
  136. package/dist/{heartbeat-tbrj7vhq.js → heartbeat-vfb1gy84.js} +24 -25
  137. package/dist/{hook-tx917rqw.js → hook-ctz0xmp3.js} +11 -11
  138. package/dist/{hook-3am1sq68.js → hook-eh52p7yd.js} +6 -6
  139. package/dist/{http-3rmemtqy.js → http-zregegrx.js} +902 -198
  140. package/dist/{index-s7xtvc0f.js → index-5kx15d19.js} +1 -1
  141. package/dist/index-7w8p6em0.js +41 -0
  142. package/dist/index-evay0xyk.js +17 -0
  143. package/dist/{index-2jw11t8s.js → index-fdym6ryb.js} +25 -26
  144. package/dist/{index-3j803vnb.js → index-mtnbhe12.js} +20533 -19786
  145. package/dist/index-vz4semsx.js +38 -0
  146. package/dist/{index-gfnq66t1.js → index-x9qf8dg7.js} +294 -29
  147. package/dist/index-y3s0xp2v.js +43 -0
  148. package/dist/{k8s-36gfn847.js → k8s-ejkk0aw7.js} +2 -2
  149. package/dist/{keepalive-9px3t7qj.js → keepalive-zdqay870.js} +4 -5
  150. package/dist/lead-6cscw8a5.js +82 -0
  151. package/dist/{maintenance-vwqjwst6.js → maintenance-t5ndg11m.js} +1 -1
  152. package/dist/{node-2wfcey7d.js → node-0as4n1ef.js} +3 -3
  153. package/dist/{node-zd6shky9.js → node-dhxbt01p.js} +3 -3
  154. package/dist/{node-z67yjre7.js → node-jkdd5w7m.js} +290 -70
  155. package/dist/{node-hjn5n1yp.js → node-t0ct2zpw.js} +3 -5
  156. package/dist/{oauth-refresh-sweep-yqry3wn4.js → oauth-refresh-sweep-y9zyd7t6.js} +3 -4
  157. package/dist/{object-webhooks-8s1wtths.js → object-webhooks-mkca91s0.js} +7 -7
  158. package/dist/{onboard-hb8czx0p.js → onboard-ss995244.js} +11 -9
  159. package/dist/{opencode-adapter-djd6m6dk.js → opencode-adapter-mwpz0278.js} +8 -8
  160. package/dist/{otel-impl-2ymwyczz.js → otel-impl-6n6vva3x.js} +2 -2
  161. package/dist/{pending-nxavtvx7.js → pending-2sxh1t6j.js} +22 -23
  162. package/dist/{pi-mono-adapter-d2cpmcy4.js → pi-mono-adapter-sfb7zy43.js} +13 -13
  163. package/dist/{pricing-refresh-1yz8jkqv.js → pricing-refresh-h79bg4cf.js} +2 -2
  164. package/dist/{rbac-roles-7s6m31xw.js → rbac-roles-ckq0czp4.js} +2 -2
  165. package/dist/{rbac-roles-dbpx0x9v.js → rbac-roles-jg2e260w.js} +3 -3
  166. package/dist/{render-v2-7y20rjrn.js → render-v2-ymbshmn0.js} +7 -7
  167. package/dist/{resume-wz546x47.js → resume-jdhnt4jk.js} +10 -10
  168. package/dist/{runtime-cb5bd9tz.js → runtime-y28jhhnf.js} +1 -1
  169. package/dist/{session-access-4vcft8kq.js → session-access-k4ta5hvp.js} +5 -5
  170. package/dist/{session-source-backfill-57b50tpw.js → session-source-backfill-528j4s8j.js} +3 -3
  171. package/dist/{setup-e1tevjyj.js → setup-d6pj82fr.js} +15 -6
  172. package/dist/thread-buffer-9w6x5zec.js +40 -0
  173. package/dist/{tree-visibility-07wf1nct.js → tree-visibility-kjxv3nxk.js} +2 -2
  174. package/dist/{user-merge-jobs-n20qpv6s.js → user-merge-jobs-rabbncf6.js} +3 -3
  175. package/dist/{virtual-modules-6fxmn1yv.js → virtual-modules-22k51txd.js} +3 -3
  176. package/dist/{work-objects-eg7y48pe.js → work-objects-xtjbar3r.js} +26 -30
  177. package/dist/{worker-follow-up-jnvnnf2b.js → worker-follow-up-fg48vk6d.js} +21 -22
  178. package/dist/worker-g4aj93dt.js +82 -0
  179. package/dist/{x-d27jj7z7.js → x-vfsqypht.js} +2 -2
  180. package/openapi.json +633 -25
  181. package/package.json +10 -10
  182. package/src/apps/definition.ts +76 -24
  183. package/src/apps/row-store.ts +67 -0
  184. package/src/apps/script-types.ts +131 -21
  185. package/src/apps/store.ts +4 -1
  186. package/src/apps/sync.ts +20 -5
  187. package/src/azure-devops/boards-sync.ts +1 -1
  188. package/src/be/db/script-runs.ts +33 -0
  189. package/src/be/db/slack-card-groups.ts +147 -0
  190. package/src/be/db/slack-trees.ts +38 -1
  191. package/src/be/db/task-idempotency.ts +63 -0
  192. package/src/be/db/tasks/read.ts +27 -1
  193. package/src/be/db/tasks/write.ts +51 -14
  194. package/src/be/db/users/avatar.ts +12 -0
  195. package/src/be/db/workflow-idempotency.ts +6 -1
  196. package/src/be/db/workflows/read.ts +79 -0
  197. package/src/be/db.ts +129 -152
  198. package/src/be/improvements.ts +24 -2
  199. package/src/be/mcp-proxy.ts +45 -11
  200. package/src/be/memory/embedding-space.ts +10 -20
  201. package/src/be/memory/index.ts +35 -0
  202. package/src/be/memory/providers/openai-embedding.ts +10 -0
  203. package/src/be/migrations/344_user_avatar.sql +4 -0
  204. package/src/be/migrations/345_task_status_kind.sql +6 -0
  205. package/src/be/migrations/348_task_deferred_until.sql +4 -0
  206. package/src/be/migrations/354_durable_objects.sql +9 -0
  207. package/src/be/migrations/356_slack_outcome_card_groups.sql +14 -0
  208. package/src/be/migrations/357_task_idempotency_keys.sql +27 -0
  209. package/src/be/migrations/362_favorites_app.sql +36 -0
  210. package/src/be/primitives/object-embed.ts +2 -2
  211. package/src/be/primitives/objects.ts +2 -2
  212. package/src/be/repo-checked-update.ts +58 -5
  213. package/src/be/requester-timezone.ts +10 -0
  214. package/src/be/runtime-pools/supervisor.ts +1 -0
  215. package/src/be/script-connections.ts +5 -1
  216. package/src/be/script-credential-broker.ts +29 -2
  217. package/src/be/scripts/durable.ts +204 -0
  218. package/src/be/scripts/extract-schema.ts +29 -4
  219. package/src/be/scripts/run-credential.ts +1 -8
  220. package/src/be/scripts/typecheck.ts +33 -8
  221. package/src/be/seed-scripts/catalog/memory-eval.ts +11 -2
  222. package/src/be/seed-scripts/catalog/tool-usage.ts +27 -8
  223. package/src/be/swarm-config-guard.ts +91 -7
  224. package/src/be/users.ts +33 -12
  225. package/src/bitbucket/handlers.ts +1 -1
  226. package/src/comb/review-batch.ts +16 -5
  227. package/src/commands/context-preamble.ts +237 -0
  228. package/src/commands/credential-outcome-report.ts +96 -0
  229. package/src/commands/e2b.ts +14 -0
  230. package/src/commands/entrypoint-mcp-config.ts +231 -0
  231. package/src/commands/onboard/agent-fs-version.ts +1 -1
  232. package/src/commands/onboard/compose-generator.ts +2 -1
  233. package/src/commands/onboard/env-generator.ts +16 -7
  234. package/src/commands/runner.ts +72 -10
  235. package/src/commands/setup.tsx +17 -3
  236. package/src/event-waits/github.ts +39 -6
  237. package/src/event-waits/index.ts +4 -2
  238. package/src/event-waits/types.ts +10 -3
  239. package/src/extensions/contract-types.generated.ts +1 -1
  240. package/src/github/app.ts +177 -13
  241. package/src/github/handlers.ts +7 -2
  242. package/src/github/pull-request-state.ts +100 -11
  243. package/src/gitlab/handlers.ts +2 -2
  244. package/src/heartbeat/heartbeat.ts +6 -1
  245. package/src/hooks/hook.ts +8 -2
  246. package/src/hooks/native-tool-hooks.ts +4 -2
  247. package/src/http/api-keys.ts +26 -0
  248. package/src/http/apps.ts +82 -42
  249. package/src/http/asset-key-write.ts +45 -0
  250. package/src/http/assets.ts +4 -3
  251. package/src/http/comb.ts +21 -5
  252. package/src/http/config.ts +8 -4
  253. package/src/http/github-token.ts +27 -6
  254. package/src/http/heartbeat.ts +5 -0
  255. package/src/http/index.ts +12 -6
  256. package/src/http/kv.ts +7 -5
  257. package/src/http/mcp-oauth.ts +16 -0
  258. package/src/http/mcp-servers.ts +43 -3
  259. package/src/http/memory.ts +28 -1
  260. package/src/http/metrics.ts +11 -4
  261. package/src/http/onboarding.ts +12 -1
  262. package/src/http/pages.ts +4 -10
  263. package/src/http/repos.ts +27 -11
  264. package/src/http/request-principal.ts +27 -1
  265. package/src/http/schedules.ts +42 -14
  266. package/src/http/script-connection-proxy.ts +3 -1
  267. package/src/http/script-runs.ts +21 -10
  268. package/src/http/scripts.ts +177 -26
  269. package/src/http/session-cost-recompute.ts +9 -4
  270. package/src/http/sessions.ts +7 -2
  271. package/src/http/skills.ts +70 -0
  272. package/src/http/status.ts +2 -0
  273. package/src/http/tasks.ts +115 -19
  274. package/src/http/trackers/jira.ts +18 -3
  275. package/src/http/trackers/linear.ts +3 -0
  276. package/src/http/users.ts +5 -0
  277. package/src/http/webhooks.ts +19 -1
  278. package/src/http/workflows.ts +5 -10
  279. package/src/integrations/chat-sdk/commands.ts +3 -1
  280. package/src/jira/sync.ts +1 -1
  281. package/src/kv-limits.ts +2 -0
  282. package/src/kv-reserved-namespaces.ts +25 -2
  283. package/src/linear/sync.ts +5 -3
  284. package/src/prompts/session-templates.ts +50 -0
  285. package/src/prompts/session-turns.ts +30 -0
  286. package/src/providers/acp-targets.ts +2 -2
  287. package/src/providers/amp-adapter.ts +1 -1
  288. package/src/providers/claude-adapter.ts +5 -0
  289. package/src/providers/claude-managed-adapter.ts +14 -0
  290. package/src/providers/claude-sdk-session.ts +19 -1
  291. package/src/providers/cursor-adapter.ts +1 -1
  292. package/src/providers/dsh-adapter.ts +1 -1
  293. package/src/providers/opencode-adapter.ts +3 -5
  294. package/src/providers/runtime-dependencies.ts +11 -8
  295. package/src/rbac/legacy-policy.ts +7 -0
  296. package/src/rbac/permissions.ts +27 -0
  297. package/src/scheduler/deferred-task-waits.ts +74 -13
  298. package/src/scheduler/scheduler.ts +36 -18
  299. package/src/script-workflows/executor.ts +37 -8
  300. package/src/script-workflows/supervisor.ts +14 -0
  301. package/src/scripts-runtime/ctx.ts +5 -1
  302. package/src/scripts-runtime/durable-object-base.ts +19 -0
  303. package/src/scripts-runtime/eval-harness.ts +46 -1
  304. package/src/scripts-runtime/executors/native.ts +13 -1
  305. package/src/scripts-runtime/executors/quickjs-bundle.ts +20 -1
  306. package/src/scripts-runtime/executors/quickjs-prelude.ts +40 -1
  307. package/src/scripts-runtime/executors/quickjs-runner.ts +26 -3
  308. package/src/scripts-runtime/executors/quickjs-worker.ts +2 -1
  309. package/src/scripts-runtime/executors/types.ts +26 -0
  310. package/src/scripts-runtime/extract-signature.ts +96 -1
  311. package/src/scripts-runtime/loader.ts +11 -5
  312. package/src/scripts-runtime/mcp-client.ts +1 -1
  313. package/src/scripts-runtime/sdk-allowlist.ts +1 -0
  314. package/src/scripts-runtime/swarm-config.ts +7 -0
  315. package/src/scripts-runtime/swarm-sdk.ts +12 -2
  316. package/src/scripts-runtime/types/stdlib.d.ts +27 -1
  317. package/src/scripts-runtime/types/swarm-extension.d.ts +20 -2
  318. package/src/scripts-runtime/types/swarm-sdk.d.ts +27 -1
  319. package/src/slack/actions.ts +25 -1
  320. package/src/slack/assistant.ts +8 -0
  321. package/src/slack/blocks.ts +35 -0
  322. package/src/slack/channel-activity.ts +7 -0
  323. package/src/slack/enrich.ts +46 -54
  324. package/src/slack/files.ts +173 -23
  325. package/src/slack/handlers.test.ts +17 -19
  326. package/src/slack/handlers.ts +15 -14
  327. package/src/slack/render-v2.ts +403 -17
  328. package/src/slack/responses.ts +61 -5
  329. package/src/slack/session-mirror.ts +10 -5
  330. package/src/slack/task-output.ts +25 -14
  331. package/src/slack/templates.ts +9 -0
  332. package/src/slack/thread-participants.ts +64 -24
  333. package/src/slack/watcher.ts +4 -4
  334. package/src/slack/work-objects.ts +1 -1
  335. package/src/stdio.ts +5 -0
  336. package/src/tests/agents-list-model-display.test.ts +4 -0
  337. package/src/tests/api-drain-worker-e2e.test.ts +0 -2
  338. package/src/tests/approval-auto-cancellation-migration.test.ts +8 -19
  339. package/src/tests/approval-card-resolution.test.ts +2 -17
  340. package/src/tests/approval-requests-notifications.test.ts +41 -27
  341. package/src/tests/approval-requests.test.ts +137 -369
  342. package/src/tests/apps-script-types.test.ts +63 -16
  343. package/src/tests/apps-sort-order.test.ts +87 -0
  344. package/src/tests/apps-sync-engine.test.ts +5 -3
  345. package/src/tests/apps-table-filters-migration.test.ts +44 -25
  346. package/src/tests/bedrock-model-groups.test.ts +4 -0
  347. package/src/tests/bitbucket-handlers.test.ts +2 -0
  348. package/src/tests/channel-activity.test.ts +9 -0
  349. package/src/tests/chat-sdk-commands.test.ts +1 -0
  350. package/src/tests/chatgpt-subscription-model-groups.test.ts +4 -0
  351. package/src/tests/claude-adapter.test.ts +35 -0
  352. package/src/tests/claude-hook-output.test.ts +2 -0
  353. package/src/tests/claude-managed-adapter.test.ts +15 -3
  354. package/src/tests/claude-sdk-stderr.test.ts +28 -0
  355. package/src/tests/codex-adapter.test.ts +3 -92
  356. package/src/tests/codex-gpt6-release.test.ts +4 -9
  357. package/src/tests/codex-oauth-credential-info.test.ts +35 -18
  358. package/src/tests/codex-oauth.test.ts +0 -6
  359. package/src/tests/codex-pool.test.ts +5 -214
  360. package/src/tests/codex-rate-limit-parse.test.ts +0 -7
  361. package/src/tests/codex-swarm-events.test.ts +11 -54
  362. package/src/tests/comb-review-batch.test.ts +17 -4
  363. package/src/tests/comb-status.test.ts +1 -0
  364. package/src/tests/db-client-busy-retry.test.ts +49 -16
  365. package/src/tests/db-client.test.ts +11 -5
  366. package/src/tests/db-task-read-contract.test.ts +1 -0
  367. package/src/tests/db-task-write-contract.test.ts +2 -2
  368. package/src/tests/defer-task.test.ts +24 -1
  369. package/src/tests/dsh-adapter.test.ts +1 -1
  370. package/src/tests/e2b-dispatch.test.ts +13 -1
  371. package/src/tests/e2e-shards.test.ts +9 -9
  372. package/src/tests/enabled-tools.test.ts +0 -2
  373. package/src/tests/entrypoint-mcp-config.test.ts +642 -0
  374. package/src/tests/fixtures/base-prompt-baseline.json +6 -6
  375. package/src/tests/fixtures/onboard/content.env.txt +2 -2
  376. package/src/tests/fixtures/onboard/dev.env.txt +2 -2
  377. package/src/tests/fixtures/onboard/full-all.env.txt +2 -2
  378. package/src/tests/fixtures/onboard/full.env.txt +2 -2
  379. package/src/tests/fixtures/onboard/research.env.txt +2 -2
  380. package/src/tests/fixtures/onboard/solo.env.txt +2 -2
  381. package/src/tests/fixtures/runner-missing-dependency.ts +2 -1
  382. package/src/tests/fx-adapter.test.ts +4 -5
  383. package/src/tests/github-app-worker-auth-helper.test.ts +147 -1
  384. package/src/tests/gitlab-handlers.test.ts +2 -0
  385. package/src/tests/heartbeat-jev-gate.test.ts +9 -241
  386. package/src/tests/heartbeat-reroute-decision.test.ts +2 -0
  387. package/src/tests/heartbeat-supersede-resume.test.ts +2 -0
  388. package/src/tests/heartbeat.test.ts +1 -0
  389. package/src/tests/hook-mcp-config-precedence.test.ts +59 -0
  390. package/src/tests/hook-ping-me-order.test.ts +1 -0
  391. package/src/tests/hook-runtime-close.test.ts +1 -0
  392. package/src/tests/improvements-payload.test.ts +2 -2
  393. package/src/tests/key-usage-selection.test.ts +302 -0
  394. package/src/tests/memory-e2e.test.ts +34 -103
  395. package/src/tests/memory-key-paths.test.ts +5 -0
  396. package/src/tests/memory-rater-llm.test.ts +33 -149
  397. package/src/tests/memory-store.test.ts +24 -125
  398. package/src/tests/memory.test.ts +31 -100
  399. package/src/tests/merge-gate-detect-changes.test.ts +108 -2
  400. package/src/tests/model-groups-live-catalog.test.ts +4 -0
  401. package/src/tests/oauth-credential-bindings.test.ts +8 -3
  402. package/src/tests/oauth-refresh-failure.test.ts +15 -3
  403. package/src/tests/onboard-env.test.ts +1 -1
  404. package/src/tests/openai-compatible-providers.test.ts +5 -0
  405. package/src/tests/openapi-route-headers.test.ts +2 -1
  406. package/src/tests/opus-5-5-registry.test.ts +4 -0
  407. package/src/tests/otel-service-name.test.ts +0 -9
  408. package/src/tests/otel-session-cost-metrics.test.ts +1 -38
  409. package/src/tests/pool-session-logs.test.ts +8 -42
  410. package/src/tests/pre-push-affected-tests.test.ts +106 -0
  411. package/src/tests/prompt-template-session.test.ts +3 -0
  412. package/src/tests/provider-runtime-dependencies.test.ts +26 -15
  413. package/src/tests/routing-affinity-inventory.test.ts +11 -0
  414. package/src/tests/runner-api-drain.test.ts +2 -17
  415. package/src/tests/runner-context-preamble.test.ts +202 -0
  416. package/src/tests/runner-repo-clone-args.test.ts +116 -0
  417. package/src/tests/runner-terminal-window-report.test.ts +132 -0
  418. package/src/tests/runtime-supervisor-failures.test.ts +1 -0
  419. package/src/tests/sandboxed-process.test.ts +26 -21
  420. package/src/tests/schedule-http-triage-tools.test.ts +12 -9
  421. package/src/tests/scheduled-tasks.test.ts +14 -51
  422. package/src/tests/scheduler-occurrence.test.ts +60 -9
  423. package/src/tests/script-connections-mcp.test.ts +6 -3
  424. package/src/tests/script-connections.test.ts +4 -0
  425. package/src/tests/script-executor-conformance.test.ts +4 -48
  426. package/src/tests/script-executor-quickjs-pool.test.ts +9 -7
  427. package/src/tests/script-native-startup.test.ts +21 -25
  428. package/src/tests/scripts-namespaces.test.ts +3 -1
  429. package/src/tests/secret-rules.test.ts +4 -2
  430. package/src/tests/secret-scrubber.test.ts +8 -2
  431. package/src/tests/session-cost-recompute-unit.test.ts +39 -0
  432. package/src/tests/session-costs-recompute-all-providers.test.ts +6 -3
  433. package/src/tests/session-logs.test.ts +1 -260
  434. package/src/tests/session-route-posture.test.ts +7 -1
  435. package/src/tests/slack-file-tools-attachments.test.ts +14 -9
  436. package/src/tests/slack-identity-resolution.test.ts +10 -3
  437. package/src/tests/slack-inline-output.test.ts +10 -8
  438. package/src/tests/slack-render-v2.test.ts +14 -152
  439. package/src/tests/slack-steering.test.ts +8 -2
  440. package/src/tests/slack-thread-participants.test.ts +11 -1
  441. package/src/tests/sonnet-5-5-registry.test.ts +4 -0
  442. package/src/tests/swarm-config-encryption.test.ts +5 -8
  443. package/src/tests/task-cascade-fail.test.ts +1 -0
  444. package/src/tests/task-supersede-resume.test.ts +1 -0
  445. package/src/tests/test-proc.ts +5 -2
  446. package/src/tests/ui-spec-script-actions-config.test.ts +7 -3
  447. package/src/tests/window-stream-reporter.test.ts +122 -0
  448. package/src/tests/workflow-agent-task-retry.test.ts +1 -3
  449. package/src/tests/workflow-cascade-cancel.test.ts +1 -0
  450. package/src/tests/workflow-retry-v2.test.ts +34 -43
  451. package/src/tests/workflow-retry-validation.test.ts +8 -48
  452. package/src/tests/workflow-triggers-v2.test.ts +35 -11
  453. package/src/tests/worktree-reaper.test.ts +2 -2
  454. package/src/tools/app-patch.ts +6 -2
  455. package/src/tools/app-upsert.ts +8 -4
  456. package/src/tools/cancel-task.ts +2 -2
  457. package/src/tools/defer-task.ts +24 -79
  458. package/src/tools/get-task-details.ts +8 -4
  459. package/src/tools/get-tasks.ts +13 -2
  460. package/src/tools/kv/kv-get.ts +2 -0
  461. package/src/tools/kv/kv-list.ts +11 -5
  462. package/src/tools/kv/kv-set.ts +1 -3
  463. package/src/tools/manage-user.ts +9 -0
  464. package/src/tools/repos/update-repo.ts +37 -19
  465. package/src/tools/schedules/run-schedule-now.ts +21 -1
  466. package/src/tools/script-apis.ts +9 -4
  467. package/src/tools/script-common.ts +2 -2
  468. package/src/tools/script-run.ts +8 -0
  469. package/src/tools/script-upsert.ts +1 -1
  470. package/src/tools/slack-download-file.ts +15 -12
  471. package/src/tools/slack-post.ts +7 -1
  472. package/src/tools/slack-read.ts +3 -1
  473. package/src/tools/slack-reply.ts +16 -0
  474. package/src/tools/slack-start-thread.ts +8 -1
  475. package/src/tools/slack-upload-file.ts +99 -96
  476. package/src/tools/store-progress.ts +5 -3
  477. package/src/tools/swarm-config/set-config.ts +3 -1
  478. package/src/tools/swarm-x.ts +0 -2
  479. package/src/tools/utils.ts +3 -0
  480. package/src/types.ts +101 -2
  481. package/src/utils/constants.ts +32 -0
  482. package/src/utils/credentials.ts +42 -5
  483. package/src/utils/deferral-time.ts +61 -0
  484. package/src/utils/error-tracker.ts +6 -0
  485. package/src/utils/key-usage.ts +114 -0
  486. package/src/utils/request-auth-context.ts +15 -16
  487. package/src/utils/sandboxed-process.ts +1 -0
  488. package/src/utils/secret-scrubber.ts +1 -1
  489. package/src/workflows/engine.ts +6 -11
  490. package/src/workflows/executors/swarm-script.ts +0 -2
  491. package/src/workflows/foreach-driver.ts +6 -12
  492. package/src/workflows/input.ts +24 -1
  493. package/src/workflows/node-timeout.ts +18 -0
  494. package/src/workflows/resume.ts +5 -2
  495. package/src/workflows/retry-poller.ts +2 -1
  496. package/src/workflows/triggers.ts +21 -11
  497. package/src/x/composio.ts +10 -1
  498. package/templates/skills/apps/SKILL.md +6 -2
  499. package/templates/skills/apps/content.md +6 -2
  500. package/templates/skills/boards-and-sheets/content.md +4 -2
  501. package/templates/skills/code-quality/content.md +4 -4
  502. package/templates/skills/pages/content.md +7 -0
  503. package/templates/skills/scheduled-task-resilience/SKILL.md +2 -0
  504. package/templates/skills/scheduled-task-resilience/content.md +2 -0
  505. package/templates/skills/swarm-docs/content.md +8 -0
  506. package/templates/skills/swarm-scripts/SKILL.md +45 -0
  507. package/templates/skills/swarm-scripts/content.md +45 -0
  508. package/dist/acp-adapter-mr4temec.js +0 -17
  509. package/dist/cli-1vmhnncj.js +0 -173
  510. package/dist/cli-kj0hyr43.js +0 -51
  511. package/dist/cli-ysv0k1we.js +0 -459
  512. package/dist/core-gsvj5f3z.js +0 -42
  513. package/dist/dsh-adapter-8abzqk5c.js +0 -9
  514. package/dist/fx-adapter-4sjrbdne.js +0 -20
  515. package/dist/grok-adapter-3a0ezfee.js +0 -20
  516. package/dist/handlers-ef3k11hb.js +0 -41
  517. package/dist/index-aetfyx6p.js +0 -13
  518. package/dist/index-e6bq0exk.js +0 -42
  519. package/dist/index-hf2k1vge.js +0 -39
  520. package/dist/index-taxmejj3.js +0 -44
  521. package/dist/lead-5vt6f174.js +0 -83
  522. package/dist/thread-buffer-686pa1p1.js +0 -42
  523. package/dist/worker-4vp616ms.js +0 -83
  524. package/src/tests/apps-table-selection-migration.test.ts +0 -95
  525. package/src/tests/extensions-example-heartbeat-remediate.test.ts +0 -69
  526. package/src/tests/extensions-example-rewrite-and-suppress.test.ts +0 -70
package/src/be/users.ts CHANGED
@@ -22,6 +22,7 @@
22
22
  import { createHash, randomUUID } from "node:crypto";
23
23
  import { scheduleOrgDomainRecompute } from "../telemetry-identity";
24
24
  import type { User } from "../types";
25
+ import type { ScriptRunProvenance } from "../utils/request-auth-context";
25
26
  import { registerVolatileSecret, unregisterVolatileSecret } from "../utils/secret-scrubber";
26
27
  import { closeSessionTokenConnections } from "../utils/session-token-connections";
27
28
  import { randomChars } from "../utils/short-id";
@@ -412,6 +413,14 @@ export async function findOrCreateUserByEmail(
412
413
  return { user: created, created: true };
413
414
  }
414
415
 
416
+ /** A profile lookup can finish after a manual edit. Test the stored value in the write. */
417
+ export async function fillMissingUserTimezone(id: string, timezone: string): Promise<void> {
418
+ await getDbClient().run(
419
+ "UPDATE users SET timezone = ?, lastUpdatedAt = ? WHERE id = ? AND (timezone IS NULL OR timezone = '')",
420
+ [timezone, new Date().toISOString(), id],
421
+ );
422
+ }
423
+
415
424
  // ---------------------------------------------------------------------------
416
425
  // Identity link/unlink
417
426
  // ---------------------------------------------------------------------------
@@ -746,7 +755,7 @@ export async function mintRuntimeToken(
746
755
  export async function mintScriptRunToken(
747
756
  agentId: string,
748
757
  ttlMs: number,
749
- provenance: { sourceStepId?: string; sourceScriptRunId?: string } = {},
758
+ provenance: ScriptRunProvenance = {},
750
759
  ): Promise<{ tokenId: string; plaintext: string }> {
751
760
  const token = await insertSessionToken(
752
761
  agentId,
@@ -761,10 +770,21 @@ export async function mintScriptRunToken(
761
770
  );
762
771
  // Recorded before the plaintext leaves this function, so no request can
763
772
  // present the token without its provenance.
764
- if (provenance.sourceStepId || provenance.sourceScriptRunId) {
773
+ if (
774
+ provenance.sourceStepId ||
775
+ provenance.sourceScriptRunId ||
776
+ provenance.objectChain !== undefined ||
777
+ provenance.depth !== undefined
778
+ ) {
765
779
  await getDbClient().run(
766
- "UPDATE session_tokens SET sourceStepId = ?, sourceScriptRunId = ? WHERE id = ?",
767
- [provenance.sourceStepId ?? null, provenance.sourceScriptRunId ?? null, token.tokenId],
780
+ "UPDATE session_tokens SET sourceStepId = ?, sourceScriptRunId = ?, objectChain = ?, depth = ? WHERE id = ?",
781
+ [
782
+ provenance.sourceStepId ?? null,
783
+ provenance.sourceScriptRunId ?? null,
784
+ provenance.objectChain === undefined ? null : JSON.stringify(provenance.objectChain),
785
+ provenance.depth ?? 0,
786
+ token.tokenId,
787
+ ],
768
788
  );
769
789
  }
770
790
  return token;
@@ -1046,7 +1066,7 @@ export async function resolveSessionToken(
1046
1066
  options: { touch?: boolean } = {},
1047
1067
  ): Promise<
1048
1068
  | { kind: "controller"; controllerId: string; tokenId: string; expiresAt: string }
1049
- | {
1069
+ | ({
1050
1070
  kind: "agent";
1051
1071
  tokenId: string;
1052
1072
  tokenKind: SessionTokenKind;
@@ -1054,9 +1074,7 @@ export async function resolveSessionToken(
1054
1074
  taskId: string | null;
1055
1075
  runtimeId: string | null;
1056
1076
  expiresAt: string;
1057
- sourceStepId?: string | null;
1058
- sourceScriptRunId?: string | null;
1059
- }
1077
+ } & ScriptRunProvenance)
1060
1078
  | null
1061
1079
  > {
1062
1080
  if (!plaintext.startsWith(SESSION_TOKEN_PREFIX)) return null;
@@ -1074,9 +1092,11 @@ export async function resolveSessionToken(
1074
1092
  revokedAt: string | null;
1075
1093
  sourceStepId: string | null;
1076
1094
  sourceScriptRunId: string | null;
1095
+ objectChain: string | null;
1096
+ depth: number;
1077
1097
  }>(
1078
1098
  `SELECT s.id, s.agentId, s.taskId, s.runtimeId, s.controllerId, s.expiresAt, s.revokedAt,
1079
- s.sourceStepId, s.sourceScriptRunId, c.placement FROM session_tokens s LEFT JOIN runtime_controllers c ON c.id = s.controllerId
1099
+ s.sourceStepId, s.sourceScriptRunId, s.objectChain, s.depth, c.placement FROM session_tokens s LEFT JOIN runtime_controllers c ON c.id = s.controllerId
1080
1100
  WHERE s.tokenHash = ?`,
1081
1101
  [hash],
1082
1102
  );
@@ -1113,9 +1133,10 @@ export async function resolveSessionToken(
1113
1133
  taskId: row.taskId,
1114
1134
  runtimeId: row.runtimeId,
1115
1135
  expiresAt: row.expiresAt,
1116
- ...(row.sourceStepId || row.sourceScriptRunId
1117
- ? { sourceStepId: row.sourceStepId, sourceScriptRunId: row.sourceScriptRunId }
1118
- : {}),
1136
+ ...(row.sourceStepId ? { sourceStepId: row.sourceStepId } : {}),
1137
+ ...(row.sourceScriptRunId ? { sourceScriptRunId: row.sourceScriptRunId } : {}),
1138
+ ...(row.objectChain !== null ? { objectChain: JSON.parse(row.objectChain) as string[] } : {}),
1139
+ depth: row.depth,
1119
1140
  };
1120
1141
  }
1121
1142
 
@@ -430,7 +430,7 @@ export async function handlePullRequestClosed(
430
430
  const reason = outcome === "merged" ? "PR was merged" : "PR was declined";
431
431
  for (const task of await findActiveTasksByVcs(repository.full_name, pr.id, "bitbucket")) {
432
432
  console.log(`[Bitbucket] Cancelling task ${task.id} — ${reason}`);
433
- await failTask(task.id, reason);
433
+ await failTask(task.id, reason, { statusKind: "external" });
434
434
  }
435
435
  return { created: false };
436
436
  }
@@ -61,6 +61,7 @@ export interface RepairedComment {
61
61
  }
62
62
 
63
63
  export interface ReviewBatchInput {
64
+ parent?: { id: string; agentId?: string | null; agentCaller: boolean };
64
65
  orgId: string;
65
66
  driveId: string;
66
67
  commentIds: string[];
@@ -200,14 +201,18 @@ export async function sendReviewBatch(
200
201
  ...repairs.map((repair) => alreadySent(repair.id, repair.taskId)),
201
202
  ]);
202
203
  }
203
- const lead = await getLeadAgent();
204
+ const parent = input.parent;
205
+ const lead = parent?.agentId ? null : await getLeadAgent();
204
206
  leadState = !lead ? "none" : lead.status === "offline" ? "offline" : "online";
205
207
  const task = await createTask(
206
208
  text,
207
209
  {
208
- agentId: lead?.id ?? "",
209
- routingReason: lead ? "skill" : undefined,
210
- routingSource: lead ? "engine_default" : undefined,
210
+ agentId: parent?.agentId || lead?.id || "",
211
+ parentTaskId: parent?.id,
212
+ inheritParentOutputSchema: parent?.agentCaller,
213
+ routingAffinity: parent && !parent.agentCaller ? { capabilities: [] } : undefined,
214
+ routingReason: parent?.agentId ? "continuity" : lead ? "skill" : undefined,
215
+ routingSource: parent?.agentId || lead ? "engine_default" : undefined,
211
216
  source: "comb",
212
217
  taskType: "comb-review",
213
218
  tags: ["comb"],
@@ -254,7 +259,13 @@ export async function sendReviewBatch(
254
259
  }
255
260
  return taskId === null
256
261
  ? { taskId, sent: wonIds, skipped, repaired }
257
- : { taskId, sent: wonIds, skipped, repaired, lead: leadState };
262
+ : {
263
+ taskId,
264
+ sent: wonIds,
265
+ skipped,
266
+ repaired,
267
+ lead: input.parent?.agentId ? undefined : leadState,
268
+ };
258
269
  }
259
270
 
260
271
  /** `items.map(fn)` with at most `limit` calls in flight. Results keep the input order. */
@@ -11,6 +11,7 @@
11
11
  * resumes (see swarm memory sigterm-143-resumed-session-context-saturation-2026-05-13).
12
12
  */
13
13
 
14
+ import { renderSessionTurnsPreamble } from "../prompts/session-turns";
14
15
  import type { TaskAttachment } from "../types";
15
16
  import { scrubSecrets } from "../utils/secret-scrubber";
16
17
  import { isSteeringEnabled } from "../utils/steering-enabled";
@@ -68,6 +69,9 @@ export interface TaskContextForPreamble {
68
69
  status?: string;
69
70
  taskType?: string;
70
71
  parentTaskId?: string;
72
+ agentId?: string;
73
+ /** Set by `GET /api/tasks/{id}`: the assignee is a lead agent. */
74
+ isLeadTask?: boolean;
71
75
  attachments?: Array<{
72
76
  kind: string;
73
77
  name: string;
@@ -102,6 +106,8 @@ export async function fetchTaskContextForPreamble(
102
106
  status: data.status,
103
107
  taskType: data.taskType,
104
108
  parentTaskId: data.parentTaskId,
109
+ agentId: data.agentId,
110
+ isLeadTask: data.isLeadTask,
105
111
  attachments: data.attachments,
106
112
  };
107
113
  } catch {
@@ -215,6 +221,237 @@ export async function buildContextPreamble(
215
221
  return preamble;
216
222
  }
217
223
 
224
+ // ─── Sessions Follow-up Preamble ──────────────────────────────────────────────
225
+
226
+ /** Most recent Lead turns the Sessions follow-up preamble shows (the "last N"). */
227
+ export const SESSION_TURNS_MAX_TURNS = 6;
228
+ /**
229
+ * Token budget for the Sessions follow-up preamble: 3× the regular preamble,
230
+ * since it carries the session's original ask plus up to six turns.
231
+ * shortcut: a constant, not an env var; add one (with the configuration
232
+ * catalog entry) if operators need to tune it.
233
+ */
234
+ export const SESSION_TURNS_MAX_TOKENS = 6000;
235
+ export const SESSION_TURNS_MAX_CHARS = SESSION_TURNS_MAX_TOKENS * 4;
236
+ /** Ancestors walked one by one to find the last Lead turns (delegated and review tasks sit between them). */
237
+ export const SESSION_TURNS_MAX_HOPS = 30;
238
+ /** Lineage reads made to reach the session root past that walk; each read climbs 50 ancestors. */
239
+ const SESSION_ROOT_MAX_READS = 10;
240
+ /** Skipped turn ids the elision marker names before it only counts the rest. */
241
+ const SESSION_ELIDED_MAX_IDS = 8;
242
+ /** Chars kept of each turn's ask (~400 tokens). */
243
+ const SESSION_TURN_ASK_CHARS = 1600;
244
+ /** Chars kept of each turn's answer (~1000 tokens); the newest turn keeps twice this. */
245
+ const SESSION_TURN_ANSWER_CHARS = 4000;
246
+ const SESSION_TURN_MAX_ARTIFACTS = 5;
247
+ /** Room the template's own text takes, kept out of the turns' share of the budget. */
248
+ const SESSION_TURNS_FRAME_CHARS = 1600;
249
+
250
+ function clip(text: string, max: number, taskId: string): string {
251
+ return text.length > max
252
+ ? `${text.slice(0, max)} [cut; full text via \`get-task-details\` taskId \`${taskId}\`]`
253
+ : text;
254
+ }
255
+
256
+ function formatSessionTurn(turn: TaskContextForPreamble, heading: string, newest: boolean): string {
257
+ const lines = [
258
+ `### ${heading} (task \`${turn.id}\`, ${turn.status ?? "unknown"})`,
259
+ `**Asked:** ${clip(scrubSecrets(turn.task.trim()), SESSION_TURN_ASK_CHARS, turn.id)}`,
260
+ ];
261
+ const answer = (turn.output || turn.progress)?.trim();
262
+ const answerCap = newest ? SESSION_TURN_ANSWER_CHARS * 2 : SESSION_TURN_ANSWER_CHARS;
263
+ const answerLabel = turn.isLeadTask === false ? "Answer" : "You answered";
264
+ lines.push(
265
+ answer
266
+ ? `**${answerLabel}:** ${clip(scrubSecrets(answer), answerCap, turn.id)}`
267
+ : `**${answerLabel}:** (nothing recorded)`,
268
+ );
269
+ const atts = turn.attachments?.filter((a) => a.name && (a.url || a.path || a.pageId)) ?? [];
270
+ for (const att of atts.slice(0, SESSION_TURN_MAX_ARTIFACTS)) {
271
+ lines.push(` - Artifact **${att.name}**: \`${formatAttachmentPointer(att)}\``);
272
+ }
273
+ return lines.join("\n");
274
+ }
275
+
276
+ interface LineageRow {
277
+ id: string;
278
+ agentId?: string | null;
279
+ parentTaskId?: string | null;
280
+ }
281
+
282
+ /**
283
+ * The ancestors of `fromId`, newest first, up to the session root, read with
284
+ * `GET /api/tasks/{id}/lineage` (the API climbs 50 ancestors per read, so a
285
+ * long chain costs a few reads, not one per task). Null when a read fails.
286
+ */
287
+ async function fetchAncestorsToRoot(
288
+ apiUrl: string,
289
+ apiKey: string,
290
+ fromId: string,
291
+ ): Promise<LineageRow[] | null> {
292
+ const headers: Record<string, string> = {};
293
+ if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
294
+ const ancestors: LineageRow[] = [];
295
+ let id = fromId;
296
+ for (let read = 0; read < SESSION_ROOT_MAX_READS; read++) {
297
+ let data: { rootTaskId?: string; tasks?: LineageRow[] };
298
+ try {
299
+ const response = await fetch(`${apiUrl}/api/tasks/${id}/lineage?maxNodes=1&maxDepth=1`, {
300
+ headers,
301
+ });
302
+ if (!response.ok) return null;
303
+ data = (await response.json()) as typeof data;
304
+ } catch {
305
+ return null;
306
+ }
307
+ const byId = new Map((data.tasks ?? []).map((row) => [row.id, row]));
308
+ let row = byId.get(id);
309
+ while (row?.parentTaskId && byId.has(row.parentTaskId)) {
310
+ row = byId.get(row.parentTaskId);
311
+ if (row) ancestors.push(row);
312
+ }
313
+ // No parent left (the root), a deleted parent, or no progress: stop.
314
+ if (!row?.parentTaskId || row.id === id || data.rootTaskId === id) return ancestors;
315
+ id = row.id;
316
+ }
317
+ return ancestors;
318
+ }
319
+
320
+ function formatElisionMarker(elidedNewestFirst: string[], rootId: string | undefined): string {
321
+ if (elidedNewestFirst.length === 0) return "";
322
+ const named = elidedNewestFirst.slice(0, SESSION_ELIDED_MAX_IDS).map((id) => `\`${id}\``);
323
+ const more = elidedNewestFirst.length - named.length;
324
+ const turns = elidedNewestFirst.length === 1 ? "turn" : "turns";
325
+ return `### … ${elidedNewestFirst.length} earlier ${turns} skipped\n${rootId ? `Between the original ask (task \`${rootId}\`) and the turns below.` : "Before the turns below."} Skipped turn tasks, newest first: ${named.join(", ")}${more > 0 ? `, and ${more} more` : ""}.`;
326
+ }
327
+
328
+ /**
329
+ * Build the Lead's preamble for a Sessions follow-up as a sandwich:
330
+ *
331
+ * 1. The session's original ask: the lineage root, whatever its type, found
332
+ * past the turn walk through the lineage endpoint. Never dropped.
333
+ * 2. An elision marker counting and naming the Lead turns skipped between
334
+ * the root and the turns shown.
335
+ * 3. The last SESSION_TURNS_MAX_TURNS Lead turns, oldest first, each with
336
+ * its ask and answer. Delegated worker tasks are not turns: the Lead's
337
+ * review of them is a turn of its own.
338
+ *
339
+ * The root is shown once: when it is also one of the last turns, it moves to
340
+ * the top block. To fit SESSION_TURNS_MAX_TOKENS, the oldest of the last
341
+ * turns drop first (into the elision marker); the root and the newest turn
342
+ * always stay, clipped per field.
343
+ *
344
+ * Returns null when the path holds no Lead turn or the template is switched
345
+ * off; the caller then falls back to `buildContextPreamble`.
346
+ */
347
+ export async function buildSessionTurnsPreamble(
348
+ apiUrl: string,
349
+ apiKey: string,
350
+ parentTaskId: string,
351
+ ): Promise<string | null> {
352
+ const path: TaskContextForPreamble[] = [];
353
+ const turnsNewestFirst: TaskContextForPreamble[] = [];
354
+ const seen = new Set<string>();
355
+ let currentId: string | undefined = parentTaskId;
356
+ while (
357
+ currentId &&
358
+ !seen.has(currentId) &&
359
+ path.length < SESSION_TURNS_MAX_HOPS &&
360
+ turnsNewestFirst.length < SESSION_TURNS_MAX_TURNS
361
+ ) {
362
+ seen.add(currentId);
363
+ const ctx = await fetchTaskContextForPreamble(apiUrl, apiKey, currentId);
364
+ if (!ctx) break;
365
+ path.push(ctx);
366
+ if (ctx.isLeadTask) turnsNewestFirst.push(ctx);
367
+ currentId = ctx.parentTaskId;
368
+ }
369
+ if (turnsNewestFirst.length === 0) return null;
370
+
371
+ // The rest of the chain, from the oldest walked task up to the session root.
372
+ const top = path[path.length - 1]!;
373
+ const rest = top.parentTaskId ? ((await fetchAncestorsToRoot(apiUrl, apiKey, top.id)) ?? []) : [];
374
+ const rootRow = rest[rest.length - 1];
375
+ let root: TaskContextForPreamble | null = top.parentTaskId ? null : top;
376
+ if (rootRow) {
377
+ root = seen.has(rootRow.id)
378
+ ? (path.find((t) => t.id === rootRow.id) ?? null)
379
+ : await fetchTaskContextForPreamble(apiUrl, apiKey, rootRow.id);
380
+ }
381
+
382
+ // Lead turns past the walk. Lineage rows carry no isLeadTask, so a task
383
+ // assigned to an agent that owns a walked Lead turn counts as one.
384
+ const leadAgents = new Set(turnsNewestFirst.map((t) => t.agentId).filter(Boolean));
385
+ const elided = rest
386
+ .filter((row) => row.id !== root?.id && row.agentId && leadAgents.has(row.agentId))
387
+ .map((row) => row.id);
388
+
389
+ // The root is shown once, on top, unless it is the newest (only) turn.
390
+ const newest = turnsNewestFirst[0]!;
391
+ const rootOnTop = root && root.id !== newest.id ? root : null;
392
+ const candidates = turnsNewestFirst.filter((t) => t.id !== rootOnTop?.id);
393
+ const rootBlock = rootOnTop
394
+ ? `${formatSessionTurn(rootOnTop, "Original ask (session root)", false)}\n\n`
395
+ : "";
396
+
397
+ // Newest first, so the budget keeps the turns the message most likely means.
398
+ const budget = SESSION_TURNS_MAX_CHARS - SESSION_TURNS_FRAME_CHARS - rootBlock.length;
399
+ const kept: TaskContextForPreamble[] = [];
400
+ let used = 0;
401
+ for (const turn of candidates) {
402
+ const block = formatSessionTurn(turn, "Turn", kept.length === 0);
403
+ if (kept.length > 0 && used + block.length > budget) break;
404
+ kept.push(turn);
405
+ used += block.length;
406
+ }
407
+ // Turns the budget dropped are newer than the ones past the walk.
408
+ const elidedNewestFirst = [...candidates.slice(kept.length).map((t) => t.id), ...elided];
409
+ const elision = formatElisionMarker(elidedNewestFirst, rootOnTop?.id);
410
+
411
+ // Number oldest first now that the kept set is known.
412
+ const turns = kept
413
+ .map((turn, i) => {
414
+ const label = turn.id === root?.id ? "session root" : null;
415
+ const heading = `Turn ${kept.length - i}${label ? `, ${label}` : ""}`;
416
+ return formatSessionTurn(turn, heading, i === 0);
417
+ })
418
+ .reverse()
419
+ .join("\n\n");
420
+
421
+ const parent = path[0];
422
+ const replyTarget =
423
+ parent && !parent.isLeadTask
424
+ ? `The new message was sent on task \`${parent.id}\`, a task of another agent: ${parent.task
425
+ .slice(0, 300)
426
+ .replace(/\n/g, " ")}\n\n`
427
+ : "";
428
+
429
+ const rendered = await renderSessionTurnsPreamble({
430
+ turn_count: kept.length,
431
+ turns: `${turns}\n`,
432
+ reply_target: replyTarget,
433
+ root: rootBlock,
434
+ elided: elision ? `${elision}\n\n` : "",
435
+ });
436
+ if (!rendered) return null;
437
+ const preamble = rendered.endsWith("\n") ? rendered : `${rendered}\n`;
438
+ return preamble.length > SESSION_TURNS_MAX_CHARS
439
+ ? `${preamble.slice(0, SESSION_TURNS_MAX_CHARS)}\n\n[context preamble truncated to ${SESSION_TURNS_MAX_TOKENS}-token budget]\n\n---\n`
440
+ : preamble;
441
+ }
442
+
443
+ /** The Lead's Sessions follow-up preamble, else the regular one-parent preamble. */
444
+ export async function buildSessionFollowUpPreamble(
445
+ apiUrl: string,
446
+ apiKey: string,
447
+ parentTaskId: string,
448
+ ): Promise<string | null> {
449
+ return (
450
+ (await buildSessionTurnsPreamble(apiUrl, apiKey, parentTaskId)) ??
451
+ buildContextPreamble(apiUrl, apiKey, parentTaskId)
452
+ );
453
+ }
454
+
218
455
  // ─── Resume Preamble ───────────────────────────────────────────────────────────
219
456
 
220
457
  interface SessionLogForPreamble {
@@ -103,6 +103,102 @@ export async function reportKeyRateLimitWindows(
103
103
  }
104
104
  }
105
105
 
106
+ /** Server terminal statuses whose finished session still reports its window telemetry. */
107
+ const TELEMETRY_TERMINAL_STATUSES = new Set(["completed", "failed"]);
108
+
109
+ /**
110
+ * Reports the window snapshot of a session whose task the server already
111
+ * holds as `completed` or `failed` (the agent finished the task before its
112
+ * session ended). The server result stands, so no outcome and no `finish`:
113
+ * only the provider usage the session observed. Fire-and-forget; returns the
114
+ * settled report so a test can await it. Never throws.
115
+ */
116
+ export function reportTerminalSessionWindows(input: {
117
+ apiUrl: string;
118
+ apiKey: string;
119
+ credentialInfo?: { keyType: string; keySuffix: string; keyIndex: number };
120
+ serverTerminalStatus: string;
121
+ rateLimitWindows?: RateLimitWindowTelemetry;
122
+ }): Promise<void> {
123
+ const { credentialInfo, rateLimitWindows } = input;
124
+ if (
125
+ !credentialInfo ||
126
+ !TELEMETRY_TERMINAL_STATUSES.has(input.serverTerminalStatus) ||
127
+ !rateLimitWindows ||
128
+ Object.keys(rateLimitWindows).length === 0
129
+ ) {
130
+ return Promise.resolve();
131
+ }
132
+ return reportKeyRateLimitWindows(
133
+ input.apiUrl,
134
+ input.apiKey,
135
+ credentialInfo.keyType,
136
+ credentialInfo.keySuffix,
137
+ credentialInfo.keyIndex,
138
+ rateLimitWindows,
139
+ ).catch((err) => {
140
+ console.warn(
141
+ `[credential] Failed to report rate-limit windows: ${err instanceof Error ? err.message : String(err)}`,
142
+ );
143
+ });
144
+ }
145
+
146
+ /**
147
+ * Throttles mid-session window reports. A snapshot goes out when it carries a
148
+ * window the last report did not, when any window's utilization moved by
149
+ * `minDeltaPoints` percentage points or more, or when `minIntervalMs` passed.
150
+ * `post` is fire-and-forget: a rejection is logged, never thrown, and a
151
+ * failed report does not count as sent.
152
+ */
153
+ export function createWindowStreamReporter(opts: {
154
+ post: (windows: RateLimitWindowTelemetry) => Promise<void>;
155
+ minDeltaPoints?: number;
156
+ minIntervalMs?: number;
157
+ now?: () => number;
158
+ }): (windows: RateLimitWindowTelemetry) => void {
159
+ const minDelta = (opts.minDeltaPoints ?? 5) / 100;
160
+ const minIntervalMs = opts.minIntervalMs ?? 60_000;
161
+ const now = opts.now ?? Date.now;
162
+ let lastSentAt: number | undefined;
163
+ let lastSent: Record<string, number | undefined> = {};
164
+
165
+ const due = (windows: RateLimitWindowTelemetry, at: number): boolean => {
166
+ if (lastSentAt === undefined || at - lastSentAt >= minIntervalMs) return true;
167
+ return Object.entries(windows).some(([key, window]) => {
168
+ if (!(key in lastSent)) return true;
169
+ const before = lastSent[key];
170
+ const after = window.utilization;
171
+ if (before === undefined || after === undefined) return before !== after;
172
+ return Math.abs(after - before) >= minDelta - 1e-9;
173
+ });
174
+ };
175
+
176
+ return (windows) => {
177
+ if (Object.keys(windows).length === 0) return;
178
+ const at = now();
179
+ if (!due(windows, at)) return;
180
+ const previous = { sentAt: lastSentAt, sent: lastSent };
181
+ lastSentAt = at;
182
+ lastSent = Object.fromEntries(Object.entries(windows).map(([k, w]) => [k, w.utilization]));
183
+ let report: Promise<void>;
184
+ try {
185
+ report = opts.post(windows);
186
+ } catch (err) {
187
+ report = Promise.reject(err);
188
+ }
189
+ report.catch((err) => {
190
+ // Retry on the next event rather than wait out the interval.
191
+ if (lastSentAt === at) {
192
+ lastSentAt = previous.sentAt;
193
+ lastSent = previous.sent;
194
+ }
195
+ console.warn(
196
+ `[credential] Failed to stream rate-limit windows: ${err instanceof Error ? err.message : String(err)}`,
197
+ );
198
+ });
199
+ };
200
+ }
201
+
106
202
  export interface CredentialOutcomeInput {
107
203
  apiUrl: string;
108
204
  apiKey: string;
@@ -110,6 +110,14 @@ export type LaunchSpec = {
110
110
 
111
111
  /** The byte-identical specs for the legacy `start-api` / `start-worker` paths. */
112
112
  const API_SPEC: LaunchSpec = { swarmRole: "api", envScope: "api", metadataSwarmRole: "api" };
113
+
114
+ const API_ONLY_RUNTIME_KEYS = [
115
+ "SECRETS_ENCRYPTION_KEY",
116
+ "SECRETS_ENCRYPTION_KEY_FILE",
117
+ "API_AGENT_FS_API_KEY",
118
+ "SLACK_SIGNING_SECRET",
119
+ "TRANSCRIPTION_API_KEY",
120
+ ] as const;
113
121
  const WORKER_SPEC: LaunchSpec = {
114
122
  swarmRole: "worker",
115
123
  envScope: "worker",
@@ -472,6 +480,12 @@ export async function loadRuntimeEnv(
472
480
 
473
481
  delete runtime.E2B_API_KEY;
474
482
  delete runtime.E2B_ACCESS_TOKEN;
483
+ if (role !== "api") {
484
+ // Only the API reads these: the config master key and the API-only config
485
+ // keys (API_ONLY_CONFIG_KEYS in src/be/swarm-config-guard.ts). Drop them
486
+ // after every env layer so a lead or worker sandbox never receives them.
487
+ for (const key of API_ONLY_RUNTIME_KEYS) delete runtime[key];
488
+ }
475
489
  return runtime;
476
490
  }
477
491