@desplega.ai/agent-swarm 2.7.8 → 2.7.10

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 (380) hide show
  1. package/dist/acp-adapter-srfhs1s9.js +16 -0
  2. package/dist/{actions-4m1ct4nh.js → actions-b8aqhrsg.js} +20 -19
  3. package/dist/{amp-adapter-txqh7eqj.js → amp-adapter-4c165vgn.js} +3 -3
  4. package/dist/{anthropic-messages-xey2skwx.js → anthropic-messages-jkva0zps.js} +68 -78
  5. package/dist/app-m9khefrh.js +20 -0
  6. package/dist/{assistant-gd08kr9e.js → assistant-rh4v3ntz.js} +22 -21
  7. package/dist/{azure-openai-responses-26t7j9ra.js → azure-openai-responses-wgtqkbr3.js} +5 -10
  8. package/dist/{boot-args-schema-tjrkpbvm.js → boot-args-schema-hwkc8bzv.js} +1 -1
  9. package/dist/{boot-reembed-21hbck22.js → boot-reembed-5y6yw9sj.js} +1 -1
  10. package/dist/{boot-reembed-mdxd3wgp.js → boot-reembed-fdyk55h4.js} +1 -1
  11. package/dist/{boot-scrub-sweep-qy0zr9t2.js → boot-scrub-sweep-r5r8kqsn.js} +4 -4
  12. package/dist/{boot-seeds-n46eaxdv.js → boot-seeds-8f9zt5cm.js} +5 -4
  13. package/dist/{boxd-nv507va8.js → boxd-qbkxy6ap.js} +1 -1
  14. package/dist/{claude-adapter-j37w2eds.js → claude-adapter-s5df247c.js} +8 -8
  15. package/dist/{claude-managed-adapter-8jvcma9a.js → claude-managed-adapter-h74d06yz.js} +4 -4
  16. package/dist/{claude-managed-setup-rzkjmgc1.js → claude-managed-setup-9gsmwzyx.js} +4 -4
  17. package/dist/{claude-sdk-session-4k7w73t0.js → claude-sdk-session-dq1j4nz9.js} +7901 -7718
  18. package/dist/{cli-s4ss5g59.js → cli-0m7rtm11.js} +5 -5
  19. package/dist/{cli-fzachfnf.js → cli-16phend6.js} +5 -5
  20. package/dist/{cli-yqefz277.js → cli-18qt3few.js} +1 -1
  21. package/dist/{cli-snpj5zbj.js → cli-1z4qggfe.js} +9 -36
  22. package/dist/{cli-s0qnd4wv.js → cli-28fq781p.js} +1 -1
  23. package/dist/{cli-1p89xny0.js → cli-2r0jcc3k.js} +1 -1
  24. package/dist/{cli-66ww7fer.js → cli-2tsfpc70.js} +1 -1
  25. package/dist/{cli-rvtm68yy.js → cli-2xv18ywz.js} +2 -2
  26. package/dist/{cli-kyr67fgx.js → cli-36wdfzgn.js} +18608 -9089
  27. package/dist/{cli-t60ajbbp.js → cli-38yww4e9.js} +20 -20
  28. package/dist/{cli-5xaqj21p.js → cli-3kd08rej.js} +1 -1
  29. package/dist/{cli-ae7mrdf9.js → cli-3vjhs18n.js} +4 -6
  30. package/dist/{cli-ssnjfg5p.js → cli-3xcwp3z8.js} +8 -10
  31. package/dist/{cli-rjknb2ae.js → cli-3xddv0rk.js} +6 -6
  32. package/dist/{cli-az48n0nr.js → cli-4caa1x7d.js} +67 -64
  33. package/dist/cli-4vwxp550.js +9321 -0
  34. package/dist/{cli-pz4rk021.js → cli-54vrpgm0.js} +1 -1
  35. package/dist/{cli-gvx71kqv.js → cli-55bkx8hh.js} +3 -3
  36. package/dist/{cli-r9jqcehk.js → cli-5mpy301f.js} +38 -2
  37. package/dist/{cli-bb0mmdk8.js → cli-5wfz00be.js} +35 -12
  38. package/dist/{cli-btfsp3mv.js → cli-5xcb8gxq.js} +9 -11
  39. package/dist/{cli-4t50yq3j.js → cli-6m6b4bep.js} +29 -12
  40. package/dist/cli-6pzk82fd.js +778 -0
  41. package/dist/{cli-8sdejs1f.js → cli-7wz05bx3.js} +797 -255
  42. package/dist/{cli-mkk9rnzz.js → cli-8bpgbr8k.js} +54 -7
  43. package/dist/{cli-fyhr5h4s.js → cli-8ewkreqd.js} +17 -13
  44. package/dist/{cli-p3vsj0d3.js → cli-an1knn2k.js} +15 -10
  45. package/dist/{cli-0ykgn1h5.js → cli-bxz823sz.js} +2 -2
  46. package/dist/{cli-jdv6ypxs.js → cli-bzvs88tv.js} +2 -2
  47. package/dist/{cli-bshb7jas.js → cli-cr14kftt.js} +3 -3
  48. package/dist/{cli-njwac61j.js → cli-cyn9v8zr.js} +12 -2
  49. package/dist/{cli-a22h291q.js → cli-d6521kb5.js} +1 -1
  50. package/dist/{cli-1b7btd38.js → cli-d84byzn8.js} +869 -5
  51. package/dist/{cli-84rj785g.js → cli-eb2azq8n.js} +9 -9
  52. package/dist/{cli-1cxrbkk6.js → cli-ed6yqpf1.js} +7 -9
  53. package/dist/{cli-wx3rhnm0.js → cli-eddnyg3t.js} +1 -1
  54. package/dist/{cli-ga786dzg.js → cli-eqk5p56g.js} +18 -17
  55. package/dist/{cli-mthwvjre.js → cli-f2zenhja.js} +1 -1
  56. package/dist/{cli-ferkkrg9.js → cli-fjggej24.js} +2 -2
  57. package/dist/{cli-g7s47cc5.js → cli-fsgttth8.js} +123 -102
  58. package/dist/{cli-269q28a1.js → cli-g1px1g2e.js} +27 -6
  59. package/dist/{cli-sq4n7af4.js → cli-h49ejvmc.js} +4 -6
  60. package/dist/{cli-5j0m12ns.js → cli-hfkwwy1h.js} +51 -15
  61. package/dist/{cli-agfm16v9.js → cli-hg42n3hx.js} +12 -12
  62. package/dist/{cli-yndmfxb3.js → cli-hxpyc9sn.js} +3 -3
  63. package/dist/{cli-w4xnbm46.js → cli-j7d73g1y.js} +414 -145
  64. package/dist/{cli-gazw7kpa.js → cli-jg24scat.js} +8 -10
  65. package/dist/{cli-5ja3b75e.js → cli-jrp1dt73.js} +1 -1
  66. package/dist/{cli-98rw5dt5.js → cli-jrzkw01m.js} +2 -2
  67. package/dist/{cli-583frbyr.js → cli-kchjb7qy.js} +1 -1
  68. package/dist/{cli-xr8908my.js → cli-kx4c8j05.js} +32 -17
  69. package/dist/{cli-fmjd0t1y.js → cli-m0cy2vyf.js} +2 -2
  70. package/dist/{cli-c0kqky8y.js → cli-m5akxq8q.js} +1 -1
  71. package/dist/{cli-ycscb2ar.js → cli-m88rpzkh.js} +2 -2
  72. package/dist/{cli-ppjxh6ah.js → cli-mp9aa8g5.js} +10 -12
  73. package/dist/{cli-xq9r2wtt.js → cli-mr97t7cc.js} +679 -247
  74. package/dist/{cli-z75yxkjh.js → cli-n07eecjs.js} +3 -3
  75. package/dist/{cli-7cx2m6t2.js → cli-n515ex5z.js} +16 -16
  76. package/dist/{cli-fy6x31ps.js → cli-n5yexkdg.js} +1 -0
  77. package/dist/{cli-bbw9wj9m.js → cli-n9abj89w.js} +17 -16
  78. package/dist/{cli-ypff1qwp.js → cli-n9ftpys4.js} +7 -7
  79. package/dist/{cli-32m9eda8.js → cli-nj3x45rw.js} +111 -109
  80. package/dist/{cli-6vcp76qk.js → cli-p74md7t8.js} +42 -23
  81. package/dist/{cli-rjcbm574.js → cli-pr0eze3x.js} +2 -2
  82. package/dist/{cli-dq8x79v8.js → cli-pyrxt9gw.js} +198 -3
  83. package/dist/{cli-m0hmeqma.js → cli-q581b386.js} +5 -5
  84. package/dist/{cli-8rpcng8j.js → cli-rjyghzg4.js} +8 -10
  85. package/dist/cli-rkc97c6a.js +39 -0
  86. package/dist/{cli-msg9m2ny.js → cli-rt0ag4x1.js} +9 -11
  87. package/dist/{cli-qd57hhhh.js → cli-rvhdmjvt.js} +6 -10
  88. package/dist/{cli-318r69gq.js → cli-t73cas91.js} +440 -9
  89. package/dist/{cli-q4ebh7h7.js → cli-td33w98c.js} +6 -6
  90. package/dist/{cli-zkky4t5g.js → cli-tmft5dz2.js} +2 -2
  91. package/dist/{cli-q26b9wre.js → cli-tph5wt3y.js} +4 -4
  92. package/dist/{cli-3e4snnzf.js → cli-ttbqe3q4.js} +1 -1
  93. package/dist/{cli-wemma3jd.js → cli-v2fwbnsk.js} +7 -7
  94. package/dist/cli-w3bk0dgv.js +5266 -0
  95. package/dist/{cli-8h0ayw8c.js → cli-x9exydey.js} +6 -6
  96. package/dist/{cli-85gzce7b.js → cli-xbtq4d6s.js} +287 -75
  97. package/dist/{cli-eyg1pa00.js → cli-xd5ebp64.js} +7 -7
  98. package/dist/{cli-g83s9ewh.js → cli-xfjrc279.js} +1 -1
  99. package/dist/{cli-7axf41jq.js → cli-xncjscpm.js} +40 -42
  100. package/dist/{cli-9m8hdawy.js → cli-xvymtmv4.js} +4 -4
  101. package/dist/{cli-81p9jd57.js → cli-yab6sh8p.js} +9 -3
  102. package/dist/{cli-srye3vdt.js → cli-ybjdc978.js} +1 -1
  103. package/dist/{cli-z1srzaf6.js → cli-yz7v0sh4.js} +70 -5
  104. package/dist/{cli-nbsf8yvn.js → cli-z9cs5m0w.js} +9 -9
  105. package/dist/{cli-k5671be5.js → cli-zcfpsfzf.js} +5 -5
  106. package/dist/{cli-vf078p3e.js → cli-zfqg6fzn.js} +1 -1
  107. package/dist/{cli-tpksw2nr.js → cli-zjphdj1a.js} +461 -108
  108. package/dist/cli.js +32 -52
  109. package/dist/{cloudflare-workers-ai-system-one-ef2a980q.js → cloudflare-workers-ai-system-one-9y1zx3pt.js} +2 -2
  110. package/dist/{codex-adapter-88z6psm4.js → codex-adapter-yr60sme6.js} +7 -7
  111. package/dist/{codex-login-74wa4hmq.js → codex-login-bcda78ge.js} +2 -2
  112. package/dist/{codex-session-runner-zwbcwzvx.js → codex-session-runner-pch8x584.js} +8 -8
  113. package/dist/{commands-7amxs716.js → commands-phjfbkv0.js} +3 -3
  114. package/dist/{controller-5rkkc37m.js → controller-jkx994pz.js} +4 -4
  115. package/dist/{controllers-connect-m7d4vxxb.js → controllers-connect-c4448kwa.js} +25 -24
  116. package/dist/{cursor-adapter-x1q18693.js → cursor-adapter-ndebqnm8.js} +2 -2
  117. package/dist/{db-athc68zt.js → db-ef32tbfc.js} +6 -2
  118. package/dist/{db-h2fsfve3.js → db-ez6egt6v.js} +3 -3
  119. package/dist/{devin-adapter-r9phbnc9.js → devin-adapter-z46ep5ph.js} +1 -1
  120. package/dist/{dispatcher-b1yz2bnn.js → dispatcher-g3tt9hs9.js} +19 -18
  121. package/dist/{docker-c1a3gqmf.js → docker-866qpzt9.js} +2 -2
  122. package/dist/{dsh-adapter-e33bkxq9.js → dsh-adapter-tcyn3099.js} +2 -2
  123. package/dist/{e2b-fr12yccx.js → e2b-jkwfhbcv.js} +2 -2
  124. package/dist/{e2b-x6ywzak3.js → e2b-s16txnpx.js} +2 -3
  125. package/dist/{easter-egg-3d-pv5qnzc8.js → easter-egg-3d-e36hk5td.js} +1 -1
  126. package/dist/{embedding-space-b4txbwrk.js → embedding-space-4kyh5qqj.js} +6 -6
  127. package/dist/{embeddings-m6zn6tad.js → embeddings-6a8v4a6t.js} +1 -1
  128. package/dist/{event-bus-g0ka3pbw.js → event-bus-e66gh7cc.js} +1 -1
  129. package/dist/{execute-68nwny8m.js → execute-3cbg0twf.js} +1 -1
  130. package/dist/{external-channel-gkckmhzh.js → external-channel-se646snz.js} +2 -2
  131. package/dist/fx-adapter-yw795hqq.js +19 -0
  132. package/dist/{google-generative-ai-v94hr7h0.js → google-generative-ai-h7s3e9kk.js} +7 -12
  133. package/dist/{google-vertex-g7vr6cf8.js → google-vertex-fhxaafzw.js} +7 -12
  134. package/dist/grok-adapter-ttmcss2j.js +19 -0
  135. package/dist/handlers-17wha3ze.js +33 -0
  136. package/dist/heartbeat-gwewgdms.js +42 -0
  137. package/dist/{hook-q5fv0jy2.js → hook-g3nhexsy.js} +16 -11
  138. package/dist/{hook-w0q2wcrv.js → hook-hq93y5ej.js} +5 -5
  139. package/dist/{http-bxat8dg3.js → http-5a9p4h6y.js} +808 -285
  140. package/dist/{index-pxn30mse.js → index-0eny15vj.js} +8 -8
  141. package/dist/{index-6cxzwfen.js → index-0rvk3vd4.js} +71 -71
  142. package/dist/{index-fvzke5kx.js → index-1qw6f2dc.js} +10 -10
  143. package/dist/{index-cqhqpgrv.js → index-3c5pxbge.js} +1 -1
  144. package/dist/{index-k7fj52d3.js → index-6haqt3v5.js} +12302 -11048
  145. package/dist/index-8arwq8mw.js +34 -0
  146. package/dist/{index-h7f61sy9.js → index-e5pfbsys.js} +3 -3
  147. package/dist/{index-bxrexmfy.js → index-hgn3c961.js} +14 -13
  148. package/dist/{index-h39zbx67.js → index-m5gx1xd6.js} +68 -68
  149. package/dist/{index-5fx3b3kw.js → index-rvccek1w.js} +9 -9
  150. package/dist/{index-fm0czesf.js → index-s72rqgsx.js} +1 -1
  151. package/dist/index-tpw054az.js +38 -0
  152. package/dist/{index-514d9pf6.js → index-w7em4ktq.js} +8 -8
  153. package/dist/index-waq75j2j.js +31 -0
  154. package/dist/{keepalive-qnt21cv0.js → keepalive-1j4n4dmk.js} +4 -4
  155. package/dist/lead-re73kdgc.js +72 -0
  156. package/dist/{llama-cpp-classify-s5c47rwh.js → llama-cpp-classify-nfgswa1m.js} +2 -2
  157. package/dist/{maintenance-btdr68y4.js → maintenance-dmghacy5.js} +1 -1
  158. package/dist/{mistral-conversations-3gjpdb4b.js → mistral-conversations-a45tx39a.js} +29 -51
  159. package/dist/{oauth-refresh-sweep-vczabeh4.js → oauth-refresh-sweep-yy06c03c.js} +3 -3
  160. package/dist/{onboard-k33ezyq8.js → onboard-52f9t5dm.js} +68 -16
  161. package/dist/{openai-codex-responses-8pbxq9h5.js → openai-codex-responses-k9gapdze.js} +7 -11
  162. package/dist/{openai-completions-rm00s912.js → openai-completions-xd579js7.js} +50 -58
  163. package/dist/{openai-decisions-8v957r2r.js → openai-decisions-q3hh60wr.js} +2 -2
  164. package/dist/{openai-responses-agxpf96k.js → openai-responses-4d5dx3c7.js} +5 -10
  165. package/dist/{opencode-adapter-3dst2ka7.js → opencode-adapter-krnh9jkn.js} +6 -6
  166. package/dist/{openrouter-images-3ecegv0d.js → openrouter-images-xr9gme9x.js} +4 -3
  167. package/dist/{otel-impl-13am7a65.js → otel-impl-xjqz6wjj.js} +2 -2
  168. package/dist/{pi-messages-pchtw4he.js → pi-messages-hjbv8v10.js} +28 -12
  169. package/dist/{pi-mono-adapter-c53de1gd.js → pi-mono-adapter-dbxyp0qv.js} +23 -26
  170. package/dist/{pricing-refresh-9fcbnq3f.js → pricing-refresh-ctdr74pd.js} +3 -3
  171. package/dist/{rbac-roles-66j5h4y5.js → rbac-roles-ehv8s10n.js} +12 -3
  172. package/dist/{rbac-roles-gw0p9h3j.js → rbac-roles-q0gr8eyj.js} +16 -2
  173. package/dist/{render-v2-fg8bmdn4.js → render-v2-5b6chvcq.js} +9 -4
  174. package/dist/{resume-1c8kr3nh.js → resume-5a5d2845.js} +7 -7
  175. package/dist/{runtime-tzf9j7tc.js → runtime-khxszyfp.js} +1 -1
  176. package/dist/{session-access-d0atq10j.js → session-access-gj0bjhqg.js} +4 -4
  177. package/dist/{session-source-backfill-0vscqmsa.js → session-source-backfill-2sy0krfk.js} +3 -3
  178. package/dist/{setup-tvfa7rwe.js → setup-7ssfakk1.js} +1 -1
  179. package/dist/{typesafe-system-one-0bmqcxfg.js → typesafe-system-one-f2en2knd.js} +2 -2
  180. package/dist/virtual-modules-pjj0knwf.js +362 -0
  181. package/dist/{work-objects-ks71xqeb.js → work-objects-bf3syvhq.js} +22 -21
  182. package/dist/{worker-follow-up-bfx0h9hg.js → worker-follow-up-38xevga6.js} +19 -18
  183. package/dist/worker-r8mz7a65.js +72 -0
  184. package/dist/{x-vmmye1kb.js → x-2fyrt5pp.js} +2 -2
  185. package/openapi.json +1169 -257
  186. package/package.json +9 -11
  187. package/src/apps/catalog.generated.json +354 -82
  188. package/src/apps/page-validator.ts +134 -2
  189. package/src/assets/key.ts +77 -4
  190. package/src/be/connector-codes.ts +21 -6
  191. package/src/be/db/session-labels.ts +57 -0
  192. package/src/be/db/session-tree.ts +51 -7
  193. package/src/be/db/slack-trees.ts +146 -0
  194. package/src/be/db/tasks/read.ts +124 -7
  195. package/src/be/db-client.ts +8 -2
  196. package/src/be/db.ts +99 -86
  197. package/src/be/event-loop-lag.ts +146 -0
  198. package/src/be/improvements.ts +416 -0
  199. package/src/be/mcp-overflow-sweep.ts +2 -1
  200. package/src/be/memory/providers/sqlite-store.ts +39 -8
  201. package/src/be/migrations/274_improvements.sql +27 -0
  202. package/src/be/migrations/275_task_dispatched_by.sql +8 -0
  203. package/src/be/migrations/278_slack_render_v2_reconcile.sql +108 -0
  204. package/src/be/rbac-roles.ts +123 -1
  205. package/src/be/swarm-config-guard.ts +3 -0
  206. package/src/be/users.ts +58 -1
  207. package/src/cli.tsx +5 -25
  208. package/src/commands/codex-login.ts +1 -1
  209. package/src/commands/context-preamble.ts +258 -0
  210. package/src/commands/e2b.ts +0 -1
  211. package/src/commands/onboard/agent-fs-version.ts +1 -1
  212. package/src/commands/onboard/compose-generator.ts +0 -1
  213. package/src/commands/onboard/dashboard-url.ts +31 -0
  214. package/src/commands/onboard/steps/generate.tsx +17 -1
  215. package/src/commands/onboard/steps/post-dashboard.tsx +9 -3
  216. package/src/commands/onboard.tsx +19 -6
  217. package/src/commands/runner.ts +117 -96
  218. package/src/extensions/catalog.generated.json +3 -3
  219. package/src/extensions/contract-types.generated.ts +1 -1
  220. package/src/heartbeat/heartbeat.ts +5 -4
  221. package/src/hooks/hook.ts +13 -5
  222. package/src/http/all-routes.ts +1 -0
  223. package/src/http/approval-requests.ts +2 -44
  224. package/src/http/auth.ts +5 -4
  225. package/src/http/codex-oauth-accounts.ts +31 -23
  226. package/src/http/codex-oauth-device.ts +1 -1
  227. package/src/http/codex-oauth-keep-warm.ts +1 -1
  228. package/src/http/core.ts +9 -3
  229. package/src/http/improvements.ts +317 -0
  230. package/src/http/index.ts +12 -6
  231. package/src/http/memory.ts +9 -4
  232. package/src/http/operator-actor.ts +2 -1
  233. package/src/http/person-responder.ts +66 -0
  234. package/src/http/sessions.ts +65 -10
  235. package/src/http/tasks.ts +1 -1
  236. package/src/http/user-roles.ts +11 -2
  237. package/src/http/users.ts +194 -104
  238. package/src/http/utils.ts +18 -0
  239. package/src/http/webhooks.ts +48 -0
  240. package/src/integrations/chat-sdk/commands.ts +167 -31
  241. package/src/integrations/chat-sdk/inbound.ts +10 -8
  242. package/src/integrations/chat-sdk/message-text.ts +117 -0
  243. package/src/providers/acp-targets.ts +1 -1
  244. package/src/providers/amp-adapter.ts +1 -1
  245. package/src/providers/codex-adapter.ts +8 -1
  246. package/src/providers/codex-models.ts +4 -3
  247. package/src/providers/codex-oauth/auth-json.ts +14 -18
  248. package/src/providers/codex-oauth/storage.ts +2 -2
  249. package/src/providers/cursor-adapter.ts +1 -1
  250. package/src/providers/dsh-adapter.ts +1 -1
  251. package/src/rbac/legacy-policy.ts +2 -0
  252. package/src/rbac/permissions.ts +10 -0
  253. package/src/scheduler/scheduler.ts +4 -1
  254. package/src/scripts-runtime/executors/quickjs-runner.ts +2 -0
  255. package/src/scripts-runtime/executors/quickjs-structured-clone.ts +180 -0
  256. package/src/scripts-runtime/quickjs-compat.ts +0 -1
  257. package/src/scripts-runtime/types/swarm-extension.d.ts +2 -0
  258. package/src/server.ts +2 -0
  259. package/src/slack/ack.ts +20 -14
  260. package/src/slack/app.ts +332 -10
  261. package/src/slack/handlers.ts +9 -2
  262. package/src/slack/index.ts +7 -1
  263. package/src/slack/lifecycle-lock.ts +29 -0
  264. package/src/slack/render-v2.ts +466 -229
  265. package/src/slack/socket-fence.ts +64 -0
  266. package/src/slack/watcher.ts +42 -8
  267. package/src/tests/api-drain-worker-e2e.test.ts +69 -2
  268. package/src/tests/apps-catalog-drift.test.ts +35 -0
  269. package/src/tests/apps-catalog-table.test.ts +203 -0
  270. package/src/tests/apps-element-assembly.test.ts +28 -0
  271. package/src/tests/apps-schema-form.test.ts +151 -0
  272. package/src/tests/apps-smart-links.test.ts +151 -0
  273. package/src/tests/apps-table-filters-migration.test.ts +96 -0
  274. package/src/tests/apps-table-selection-migration.test.ts +95 -0
  275. package/src/tests/chat-sdk-commands.test.ts +359 -2
  276. package/src/tests/chat-sdk-inbound.test.ts +20 -0
  277. package/src/tests/chat-sdk-slack.test.ts +189 -1
  278. package/src/tests/chatgpt-subscription-session-bench.test.ts +2 -2
  279. package/src/tests/claude-worker-parity.test.ts +2 -2
  280. package/src/tests/codex-adapter.test.ts +30 -0
  281. package/src/tests/codex-login.test.ts +2 -2
  282. package/src/tests/codex-oauth-accounts.test.ts +48 -12
  283. package/src/tests/codex-oauth-credential-info.test.ts +77 -1
  284. package/src/tests/codex-oauth-device.test.ts +1 -1
  285. package/src/tests/codex-oauth-keep-warm.test.ts +2 -2
  286. package/src/tests/codex-oauth.test.ts +25 -4
  287. package/src/tests/codex-pool.test.ts +2 -2
  288. package/src/tests/db-client-busy-retry.test.ts +69 -18
  289. package/src/tests/db-client.test.ts +26 -1
  290. package/src/tests/db-task-read-contract.test.ts +4 -0
  291. package/src/tests/db-task-write-contract.test.ts +2 -0
  292. package/src/tests/deploy-one-box.test.ts +39 -1
  293. package/src/tests/docs-index-footprint.test.js +3 -3
  294. package/src/tests/dsh-adapter.test.ts +1 -1
  295. package/src/tests/event-loop-lag.test.ts +184 -0
  296. package/src/tests/extensions-example-comms-adherence-gate.test.ts +115 -0
  297. package/src/tests/fixtures/onboard/content.compose.yml.txt +0 -4
  298. package/src/tests/fixtures/onboard/dev.compose.yml.txt +0 -3
  299. package/src/tests/fixtures/onboard/full-all.compose.yml.txt +0 -11
  300. package/src/tests/fixtures/onboard/full.compose.yml.txt +0 -11
  301. package/src/tests/fixtures/onboard/research.compose.yml.txt +0 -3
  302. package/src/tests/fixtures/onboard/solo.compose.yml.txt +0 -1
  303. package/src/tests/fixtures/prs-app-definition.json.txt +784 -0
  304. package/src/tests/fixtures/prs-filters-migration.patch.json.txt +318 -0
  305. package/src/tests/fixtures/prs-selection-migration.patch.json.txt +373 -0
  306. package/src/tests/fixtures/runner-identity-refresh.ts +3 -0
  307. package/src/tests/fixtures/runner-legacy-resume-prompt.ts +3 -0
  308. package/src/tests/fixtures/runner-task-start-reads.ts +140 -0
  309. package/src/tests/github-webhook-early-ack.test.ts +144 -0
  310. package/src/tests/hook-ping-me-order.test.ts +85 -0
  311. package/src/tests/http-api-integration.test.ts +2 -0
  312. package/src/tests/http-log-scrubbing.test.ts +68 -2
  313. package/src/tests/improvements-payload.test.ts +200 -0
  314. package/src/tests/improvements-route.test.ts +419 -0
  315. package/src/tests/install-sh-setup-url.test.ts +190 -0
  316. package/src/tests/kv-storage.test.ts +92 -1
  317. package/src/tests/memory-key-paths.test.ts +57 -0
  318. package/src/tests/memory-retrieval-purge.test.ts +19 -0
  319. package/src/tests/onboard-dashboard-output.test.ts +109 -0
  320. package/src/tests/onboard-dashboard-url.test.ts +83 -0
  321. package/src/tests/operator-granted-credentials.test.ts +561 -0
  322. package/src/tests/operator-granted-role-wire.test.ts +222 -0
  323. package/src/tests/quickjs-compat.test.ts +1 -1
  324. package/src/tests/rbac-engine.test.ts +2 -0
  325. package/src/tests/runner-context-preamble.test.ts +552 -0
  326. package/src/tests/runner-context-usage.test.ts +0 -1
  327. package/src/tests/runner-legacy-options.test.ts +55 -0
  328. package/src/tests/runner-slot-reconcile.test.ts +38 -0
  329. package/src/tests/runner-task-start-reads.test.ts +58 -0
  330. package/src/tests/script-connections.test.ts +3 -0
  331. package/src/tests/script-executor-conformance.test.ts +188 -0
  332. package/src/tests/send-task-dispatched-by.test.ts +129 -0
  333. package/src/tests/session-dispatched-tasks.test.ts +115 -0
  334. package/src/tests/session-sharing.test.ts +198 -9
  335. package/src/tests/sessions-tree.test.ts +133 -2
  336. package/src/tests/slack-app-icon.test.ts +4 -0
  337. package/src/tests/slack-dm-implicit-mention.test.ts +236 -0
  338. package/src/tests/slack-file-tools-attachments.test.ts +96 -3
  339. package/src/tests/slack-reaction-config.test.ts +39 -0
  340. package/src/tests/slack-read-boundaries.test.ts +4 -3
  341. package/src/tests/slack-render-v2-query-plans.test.ts +262 -3
  342. package/src/tests/slack-render-v2-reconcile.test.ts +201 -0
  343. package/src/tests/slack-render-v2.test.ts +47 -0
  344. package/src/tests/slack-socket-watchdog.test.ts +748 -0
  345. package/src/tests/submit-improvement-tool.test.ts +82 -0
  346. package/src/tests/tool-annotations.test.ts +1 -1
  347. package/src/tests/vcs-identity-inheritance.test.ts +85 -0
  348. package/src/tools/manage-user.ts +88 -58
  349. package/src/tools/send-task.ts +3 -0
  350. package/src/tools/slack-read.ts +61 -33
  351. package/src/tools/submit-improvement.ts +68 -0
  352. package/src/tools/tool-config.ts +3 -0
  353. package/src/tools/utils.ts +16 -7
  354. package/src/types.ts +5 -0
  355. package/src/utils/request-auth-context.ts +6 -1
  356. package/templates/extensions/comms-adherence-gate/README.md +25 -0
  357. package/templates/extensions/comms-adherence-gate/hooks.ts +100 -11
  358. package/templates/extensions/comms-adherence-gate/manifest.json +1 -1
  359. package/templates/skills/apps/SKILL.md +29 -11
  360. package/templates/skills/apps/content.md +29 -11
  361. package/templates/skills/swarm-scripts/SKILL.md +1 -1
  362. package/templates/skills/swarm-scripts/content.md +1 -1
  363. package/templates/skills/work-on-task/SKILL.md +1 -1
  364. package/templates/skills/work-on-task/content.md +1 -1
  365. package/dist/acp-adapter-vg5hqkvj.js +0 -16
  366. package/dist/app-e00m45gn.js +0 -17
  367. package/dist/cli-5c4hjzne.js +0 -873
  368. package/dist/cli-ae0dnfee.js +0 -20222
  369. package/dist/cli-nn3ysbqk.js +0 -428
  370. package/dist/cli-pc5znp64.js +0 -364
  371. package/dist/fx-adapter-m5jbgd5q.js +0 -19
  372. package/dist/grok-adapter-csvv7sac.js +0 -19
  373. package/dist/handlers-8x5gfbzx.js +0 -32
  374. package/dist/heartbeat-6c2y3267.js +0 -41
  375. package/dist/index-hpfte8jd.js +0 -33
  376. package/dist/index-ncf7yb5s.js +0 -30
  377. package/dist/index-vte6dyeh.js +0 -37
  378. package/dist/lead-4bvftzm6.js +0 -71
  379. package/dist/virtual-modules-efxcp740.js +0 -59
  380. package/dist/worker-e7v2bvm9.js +0 -71
@@ -87,6 +87,7 @@ export type AgentTaskRow = {
87
87
  mentionChannelId: string | null;
88
88
  dir: string | null;
89
89
  parentTaskId: string | null;
90
+ dispatchedByTaskId?: string | null;
90
91
  claudeSessionId: string | null;
91
92
  model: string | null;
92
93
  modelTier: string | null;
@@ -343,6 +344,7 @@ export function rowToAgentTask(row: AgentTaskRow): AgentTask {
343
344
  mentionChannelId: row.mentionChannelId ?? undefined,
344
345
  dir: row.dir ?? undefined,
345
346
  parentTaskId: row.parentTaskId ?? undefined,
347
+ dispatchedByTaskId: row.dispatchedByTaskId ?? undefined,
346
348
  claudeSessionId: row.claudeSessionId ?? undefined,
347
349
  model: row.model ?? undefined,
348
350
  modelTier: parseModelTier(row.modelTier) ?? undefined,
@@ -715,6 +717,26 @@ export async function getTasksByAgentId(
715
717
  return rows.map(rowToAgentTask);
716
718
  }
717
719
 
720
+ /**
721
+ * Tasks that one of `taskIds` dispatched (send-task) and that are not in
722
+ * `taskIds`. A continuation keeps parentTaskId on an earlier task, so the
723
+ * task that sent it does not reach it by the parentTaskId walk.
724
+ */
725
+ export async function getTasksDispatchedFrom(taskIds: string[]): Promise<AgentTask[]> {
726
+ if (taskIds.length === 0) return [];
727
+ const ids = JSON.stringify(taskIds);
728
+ const rows = await getDbClient().query<AgentTaskRow>(
729
+ `SELECT t.*,
730
+ (SELECT SUM(totalCostUsd) FROM session_costs WHERE session_costs.taskId = t.id) AS totalCostUsd
731
+ FROM agent_tasks t
732
+ WHERE t.dispatchedByTaskId IN (SELECT value FROM json_each(?))
733
+ AND t.id NOT IN (SELECT value FROM json_each(?))
734
+ ORDER BY t.createdAt, t.rowid`,
735
+ [ids, ids],
736
+ );
737
+ return rows.map(rowToAgentTask);
738
+ }
739
+
718
740
  /**
719
741
  * Get the most recently updated in-progress task for an agent.
720
742
  * Used as a fallback when X-Source-Task-Id header is missing (e.g. lead agent HITL requests).
@@ -1585,13 +1607,50 @@ export async function getInProgressSlackTasks(): Promise<AgentTask[]> {
1585
1607
  return rows.map(rowToAgentTask);
1586
1608
  }
1587
1609
 
1588
- export async function getSlackTasksMissingTree(): Promise<AgentTask[]> {
1610
+ /** How far back the missing-tree sweep looks for Slack tasks without a tree. */
1611
+ const SLACK_MISSING_TREE_WINDOW_MS = 24 * 60 * 60 * 1000;
1612
+
1613
+ /**
1614
+ * Slack tasks (created since render-v2 activation) whose thread has no tree
1615
+ * row yet.
1616
+ *
1617
+ * The full sweep reads only tasks updated in the last 24 h. The bound is on
1618
+ * lastUpdatedAt, not createdAt: a task that waits in backlog/unassigned for
1619
+ * days gets a fresh lastUpdatedAt when it leaves that status, so it re-enters
1620
+ * the window exactly when it starts to need a tree. idx_agent_tasks_slack_last_updated
1621
+ * makes the bound a range seek and also serves the ORDER BY. INDEXED BY:
1622
+ * without ANALYZE statistics the planner otherwise picks a wider index.
1623
+ *
1624
+ * `thread` scopes the query to one thread (event-driven render). It seeks the
1625
+ * thread through idx_agent_tasks_slack_thread_cover and has no time window,
1626
+ * so an old task in that thread is never skipped.
1627
+ */
1628
+ export async function getSlackTasksMissingTree(
1629
+ options: { now?: Date; thread?: { channelId: string; threadTs: string } } = {},
1630
+ ): Promise<AgentTask[]> {
1631
+ const thread = options.thread;
1632
+ const since = new Date(
1633
+ (options.now ?? new Date()).getTime() - SLACK_MISSING_TREE_WINDOW_MS,
1634
+ ).toISOString();
1635
+ const scope = thread
1636
+ ? {
1637
+ index: "idx_agent_tasks_slack_thread_cover",
1638
+ sql: "AND task.slackChannelId = ? AND task.slackThreadTs = ?",
1639
+ params: [thread.channelId, thread.threadTs],
1640
+ }
1641
+ : {
1642
+ index: "idx_agent_tasks_slack_last_updated",
1643
+ sql: "AND task.lastUpdatedAt >= ?",
1644
+ params: [since],
1645
+ };
1589
1646
  const rows = await getDbClient().query<AgentTaskRow>(
1590
- `SELECT task.* FROM agent_tasks task
1591
- JOIN slack_render_v2_state state ON state.id = 1
1592
- WHERE task.source = 'slack'
1647
+ `SELECT task.* FROM slack_render_v2_state state
1648
+ CROSS JOIN agent_tasks task INDEXED BY ${scope.index}
1649
+ WHERE state.id = 1
1650
+ AND task.source = 'slack'
1593
1651
  AND task.slackChannelId IS NOT NULL
1594
1652
  AND task.slackThreadTs IS NOT NULL
1653
+ ${scope.sql}
1595
1654
  AND task.createdAt >= state.activated_at
1596
1655
  AND task.status NOT IN ('backlog', 'unassigned', 'superseded')
1597
1656
  AND NOT EXISTS (
@@ -1609,6 +1668,7 @@ export async function getSlackTasksMissingTree(): Promise<AgentTask[]> {
1609
1668
  )
1610
1669
  ORDER BY task.lastUpdatedAt DESC
1611
1670
  LIMIT 200`,
1671
+ scope.params,
1612
1672
  );
1613
1673
  return rows.map(rowToAgentTask);
1614
1674
  }
@@ -1718,14 +1778,28 @@ export async function findExistingLinearTrackerContextWork(
1718
1778
  return null;
1719
1779
  }
1720
1780
 
1721
- export async function getLatestTaskByContextKey(contextKey: string): Promise<AgentTask | null> {
1781
+ /**
1782
+ * Latest task on a contextKey. `requestedByUserId` keeps only that user's
1783
+ * tasks; `notRequestedByUserId` keeps only tasks of anyone else, including
1784
+ * tasks with no requester.
1785
+ */
1786
+ export async function getLatestTaskByContextKey(
1787
+ contextKey: string,
1788
+ options: { requestedByUserId?: string; notRequestedByUserId?: string } = {},
1789
+ ): Promise<AgentTask | null> {
1722
1790
  if (!contextKey) return null;
1723
1791
  const row = await getDbClient().get<AgentTaskRow>(
1724
1792
  `SELECT * FROM agent_tasks
1725
1793
  WHERE contextKey = ?
1794
+ ${options.requestedByUserId !== undefined ? "AND requestedByUserId = ?" : ""}
1795
+ ${options.notRequestedByUserId !== undefined ? "AND requestedByUserId IS NOT ?" : ""}
1726
1796
  ORDER BY createdAt DESC
1727
1797
  LIMIT 1`,
1728
- [contextKey],
1798
+ [
1799
+ contextKey,
1800
+ ...(options.requestedByUserId !== undefined ? [options.requestedByUserId] : []),
1801
+ ...(options.notRequestedByUserId !== undefined ? [options.notRequestedByUserId] : []),
1802
+ ],
1729
1803
  );
1730
1804
  return row ? rowToAgentTask(row) : null;
1731
1805
  }
@@ -1867,19 +1941,62 @@ export async function getAgentWorkingOnContextKey(
1867
1941
  return null;
1868
1942
  }
1869
1943
 
1944
+ /**
1945
+ * Latest task whose contextKey starts with `prefix` (a half-open key range, so
1946
+ * the contextKey index serves it). The Chat SDK keys a Slack or Discord task by
1947
+ * `<channel>:<thread>`, while a slash command only knows the channel: the
1948
+ * prefix finds the tasks of every thread in it. `activeOnly` narrows to
1949
+ * `in_progress` and `pending`; `source` narrows as in the exact-key twins;
1950
+ * `requestedByUserId` keeps only that user's tasks.
1951
+ */
1952
+ export async function getLatestTaskByContextKeyPrefix(
1953
+ prefix: string,
1954
+ options: { activeOnly?: boolean; source?: string; requestedByUserId?: string } = {},
1955
+ ): Promise<AgentTask | null> {
1956
+ if (!prefix) return null;
1957
+ const upper = prefix.slice(0, -1) + String.fromCharCode(prefix.charCodeAt(prefix.length - 1) + 1);
1958
+ const source = options.source ?? null;
1959
+ const row = await getDbClient().get<AgentTaskRow>(
1960
+ `SELECT * FROM agent_tasks
1961
+ WHERE contextKey >= ? AND contextKey < ?
1962
+ AND ${contextKeySourceSql()}
1963
+ ${options.activeOnly ? "AND status IN ('in_progress', 'pending')" : ""}
1964
+ ${options.requestedByUserId !== undefined ? "AND requestedByUserId = ?" : ""}
1965
+ ORDER BY createdAt DESC, rowid DESC
1966
+ LIMIT 1`,
1967
+ [
1968
+ prefix,
1969
+ upper,
1970
+ source,
1971
+ source,
1972
+ source,
1973
+ ...(options.requestedByUserId !== undefined ? [options.requestedByUserId] : []),
1974
+ ],
1975
+ );
1976
+ return row ? rowToAgentTask(row) : null;
1977
+ }
1978
+
1870
1979
  /** Latest `in_progress` or `pending` task on a contextKey (dependency chaining). */
1871
1980
  export async function getLatestActiveTaskByContextKey(
1872
1981
  contextKey: string,
1873
1982
  source?: string,
1983
+ requestedByUserId?: string,
1874
1984
  ): Promise<AgentTask | null> {
1875
1985
  const row = await getDbClient().get<AgentTaskRow>(
1876
1986
  `SELECT * FROM agent_tasks
1877
1987
  WHERE contextKey = ?
1878
1988
  AND ${contextKeySourceSql()}
1879
1989
  AND status IN ('in_progress', 'pending')
1990
+ ${requestedByUserId !== undefined ? "AND requestedByUserId = ?" : ""}
1880
1991
  ORDER BY createdAt DESC, rowid DESC
1881
1992
  LIMIT 1`,
1882
- [contextKey, source ?? null, source ?? null, source ?? null],
1993
+ [
1994
+ contextKey,
1995
+ source ?? null,
1996
+ source ?? null,
1997
+ source ?? null,
1998
+ ...(requestedByUserId !== undefined ? [requestedByUserId] : []),
1999
+ ],
1883
2000
  );
1884
2001
 
1885
2002
  return row ? rowToAgentTask(row) : null;
@@ -1,6 +1,7 @@
1
1
  import type { Database } from "bun:sqlite";
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
  import { scrubSecrets } from "../utils/secret-scrubber";
4
+ import { currentLoopPath, recordStatement } from "./event-loop-lag";
4
5
 
5
6
  /**
6
7
  * Async database seam.
@@ -216,14 +217,19 @@ const SLOW_STATEMENT_SQL_MAX_CHARS = 200;
216
217
 
217
218
  /** Params are never logged: they can carry secrets and user content. */
218
219
  function warnIfSlowStatement(sql: string, durationMs: number): void {
220
+ recordStatement(sql, durationMs);
219
221
  if (durationMs < SLOW_STATEMENT_WARN_MS) return;
220
- const flat = sql.replace(/\s+/g, " ").trim();
222
+ // Scrub the complete SQL before truncation, so a secret that straddles the
223
+ // cut cannot leave a partial token, then scrub the complete line at egress.
224
+ const flat = scrubSecrets(sql.replace(/\s+/g, " ").trim());
221
225
  const shown =
222
226
  flat.length > SLOW_STATEMENT_SQL_MAX_CHARS
223
227
  ? `${flat.slice(0, SLOW_STATEMENT_SQL_MAX_CHARS)}…`
224
228
  : flat;
225
229
  console.warn(
226
- `[db-client] slow sync statement blocked the event loop for ${Math.round(durationMs)}ms: ${scrubSecrets(shown)}`,
230
+ scrubSecrets(
231
+ `[db-client] slow sync statement blocked the event loop for ${Math.round(durationMs)}ms path=${currentLoopPath()}: ${shown}`,
232
+ ),
227
233
  );
228
234
  }
229
235
 
package/src/be/db.ts CHANGED
@@ -217,6 +217,7 @@ import {
217
217
  threadRootsSql,
218
218
  } from "./db/session-tree";
219
219
  import { searchSkillRowsRanked } from "./db/skill-search";
220
+ import { SLACK_TREE_NEEDS_RENDER_SQL } from "./db/slack-trees";
220
221
  import { classifyTaskHumanFree, reclassifyTaskHumanFree } from "./db/tasks/human-free";
221
222
  import {
222
223
  type AgentTaskRow,
@@ -367,6 +368,7 @@ export {
367
368
  getLatestLeadTaskInThread,
368
369
  getLatestScriptRunStepTaskByContextKey,
369
370
  getLatestTaskByContextKey,
371
+ getLatestTaskByContextKeyPrefix,
370
372
  getMostRecentTaskInThread,
371
373
  getPendingChatRelayTasks,
372
374
  getPendingSlackRelayTasks,
@@ -380,6 +382,7 @@ export {
380
382
  getTasksByAgentId,
381
383
  getTasksByStatus,
382
384
  getTasksCount,
385
+ getTasksDispatchedFrom,
383
386
  giveUpStaleChatRelays,
384
387
  hasNonTerminalRerouteDecisionChild,
385
388
  hasNonTerminalResumeChild,
@@ -595,6 +598,8 @@ export interface SlackMessageRecord {
595
598
  deliveryAbandonedAt?: string;
596
599
  /** Last Slack verdict for the card, "<code>: <messages>", 500 chars max. */
597
600
  deliveryLastError?: string;
601
+ /** Tree rows only: set once the thread has no render work left. */
602
+ closedAt?: string;
598
603
  createdAt: string;
599
604
  updatedAt: string;
600
605
  }
@@ -627,6 +632,7 @@ type SlackMessageRow = {
627
632
  delivery_attempts: number;
628
633
  delivery_abandoned_at: string | null;
629
634
  delivery_last_error: string | null;
635
+ closed_at: string | null;
630
636
  created_at: string;
631
637
  updated_at: string;
632
638
  };
@@ -649,6 +655,7 @@ function rowToSlackMessage(row: SlackMessageRow): SlackMessageRecord {
649
655
  deliveryAttempts: row.delivery_attempts,
650
656
  deliveryAbandonedAt: row.delivery_abandoned_at ?? undefined,
651
657
  deliveryLastError: row.delivery_last_error ?? undefined,
658
+ closedAt: row.closed_at ?? undefined,
652
659
  createdAt: row.created_at,
653
660
  updatedAt: row.updated_at,
654
661
  };
@@ -871,15 +878,20 @@ export async function getSlackOutcomeMessage(taskId: string): Promise<SlackMessa
871
878
  *
872
879
  * CROSS JOIN and `+wake.taskType` pin the join order to the small chain. Without
873
880
  * them the planner drives the outer join from every terminal task (~1s at 150k tasks).
881
+ * The anchor drives from the partial index idx_agent_tasks_deferred (tasks
882
+ * that ever deferred), not from every outcome card: `deferral_resolved_at IS
883
+ * NULL` stays true forever on cards of tasks that never deferred.
884
+ * `+child.taskType` does the same for the NOT EXISTS: without it the planner
885
+ * walks every deferred-type task through idx_agent_tasks_list_filter per row.
874
886
  */
875
887
  export async function getResolvableDeferralOutcomes(
876
888
  limit = 50,
877
889
  ): Promise<{ card: SlackMessageRecord; deferredTaskId: string; wakeTaskId: string }[]> {
878
890
  const rows = await getDbClient().query<SlackMessageRow & { wake_task_id: string }>(
879
891
  `WITH RECURSIVE chain(card_id, task_id) AS (
880
- SELECT card.id, deferred.id FROM slack_messages card
881
- JOIN agent_tasks deferred ON deferred.id = card.task_id
882
- WHERE card.kind = 'outcome' AND deferred.deferredAt IS NOT NULL
892
+ SELECT card.id, deferred.id FROM agent_tasks deferred
893
+ CROSS JOIN slack_messages card ON card.task_id = deferred.id AND card.kind = 'outcome'
894
+ WHERE deferred.deferredAt IS NOT NULL
883
895
  AND card.deferral_resolved_at IS NULL AND card.finalized_at IS NOT NULL
884
896
  AND card.ts NOT LIKE 'pending:%'
885
897
  UNION
@@ -897,7 +909,7 @@ export async function getResolvableDeferralOutcomes(
897
909
  AND card.ts NOT LIKE 'pending:%'
898
910
  AND NOT EXISTS (
899
911
  SELECT 1 FROM agent_tasks child
900
- WHERE child.parentTaskId = wake.id AND child.taskType = 'deferred'
912
+ WHERE child.parentTaskId = wake.id AND +child.taskType = 'deferred'
901
913
  )
902
914
  AND (wake.deferredAt IS NULL OR wake.finishedAt > card.updated_at)
903
915
  AND wake.status IN ('completed', 'failed', 'cancelled', 'skipped')
@@ -967,57 +979,26 @@ export async function abandonSlackOutcomeDelivery(
967
979
  return row ? rowToSlackMessage(row) : null;
968
980
  }
969
981
 
970
- export async function getSlackTreeMessages(): Promise<SlackMessageRecord[]> {
982
+ /**
983
+ * Trees with pending render work. Reads only open trees (closed_at IS NULL,
984
+ * idx_slack_messages_open_trees): a settled thread is closed after its render
985
+ * pass and reopened by migration 278's triggers on any task or outcome write
986
+ * in the thread. `thread` scopes the sweep to one thread (event-driven render).
987
+ */
988
+ export async function getSlackTreeMessages(
989
+ options: { thread?: { channelId: string; threadTs: string } } = {},
990
+ ): Promise<SlackMessageRecord[]> {
991
+ const thread = options.thread;
971
992
  const rows = await getDbClient().query<SlackMessageRow>(
972
993
  `SELECT tree.*
973
994
  FROM slack_messages tree
974
995
  JOIN slack_render_v2_state state ON state.id = 1
975
996
  WHERE tree.kind = 'tree'
976
- AND (
977
- (tree.ts LIKE 'pending:%' AND tree.created_at >= state.activated_at)
978
- OR EXISTS (
979
- SELECT 1 FROM agent_tasks task
980
- WHERE task.slackChannelId = tree.channel_id
981
- AND task.slackThreadTs = tree.thread_ts
982
- AND task.source = 'slack'
983
- AND task.createdAt >= state.activated_at
984
- AND task.status IN ('completed', 'failed', 'cancelled')
985
- AND NOT EXISTS (
986
- SELECT 1 FROM slack_messages outcome
987
- WHERE outcome.kind = 'outcome'
988
- AND outcome.task_id = task.id
989
- AND (outcome.finalized_at IS NOT NULL OR outcome.delivery_abandoned_at IS NOT NULL)
990
- )
991
- )
992
- OR
993
- EXISTS (
994
- SELECT 1 FROM agent_tasks task
995
- WHERE task.slackChannelId = tree.channel_id
996
- AND task.slackThreadTs = tree.thread_ts
997
- AND task.createdAt >= state.activated_at
998
- AND task.status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
999
- )
1000
- OR EXISTS (
1001
- SELECT 1 FROM agent_tasks task
1002
- WHERE task.slackChannelId = tree.channel_id
1003
- AND task.slackThreadTs = tree.thread_ts
1004
- AND task.createdAt >= state.activated_at
1005
- AND task.lastUpdatedAt > tree.updated_at
1006
- )
1007
- OR EXISTS (
1008
- SELECT 1 FROM slack_messages outcome
1009
- JOIN agent_tasks task ON task.id = outcome.task_id
1010
- WHERE outcome.kind = 'outcome'
1011
- AND outcome.channel_id = tree.channel_id
1012
- AND outcome.thread_ts = tree.thread_ts
1013
- AND task.createdAt >= state.activated_at
1014
- AND (
1015
- (outcome.finalized_at IS NULL AND outcome.delivery_abandoned_at IS NULL)
1016
- OR outcome.updated_at > tree.updated_at
1017
- )
1018
- )
1019
- )
997
+ AND tree.closed_at IS NULL
998
+ ${thread ? "AND tree.channel_id = ? AND tree.thread_ts = ?" : ""}
999
+ AND ${SLACK_TREE_NEEDS_RENDER_SQL}
1020
1000
  ORDER BY tree.created_at ASC`,
1001
+ thread ? [thread.channelId, thread.threadTs] : [],
1021
1002
  );
1022
1003
  return rows.map(rowToSlackMessage);
1023
1004
  }
@@ -2620,32 +2601,44 @@ export async function createTaskExtended(
2620
2601
  // Webhook handlers locate active work via `findTaskByVcs(repo, number, provider)`,
2621
2602
  // so a resume / follow-up child MUST carry the full VCS identity or
2622
2603
  // subsequent review/update events get dropped.
2623
- if (parent.vcsProvider && !options.vcsProvider) {
2624
- options.vcsProvider = parent.vcsProvider;
2625
- }
2626
- if (parent.vcsRepo && !options.vcsRepo) {
2627
- options.vcsRepo = parent.vcsRepo;
2628
- }
2629
- if (parent.vcsNumber != null && options.vcsNumber == null) {
2630
- options.vcsNumber = parent.vcsNumber;
2631
- }
2632
- if (parent.vcsEventType && !options.vcsEventType) {
2633
- options.vcsEventType = parent.vcsEventType;
2634
- }
2635
- if (parent.vcsCommentId != null && options.vcsCommentId == null) {
2636
- options.vcsCommentId = parent.vcsCommentId;
2637
- }
2638
- if (parent.vcsAuthor && !options.vcsAuthor) {
2639
- options.vcsAuthor = parent.vcsAuthor;
2640
- }
2641
- if (parent.vcsUrl && !options.vcsUrl) {
2642
- options.vcsUrl = parent.vcsUrl;
2643
- }
2644
- if (parent.vcsInstallationId != null && options.vcsInstallationId == null) {
2645
- options.vcsInstallationId = parent.vcsInstallationId;
2646
- }
2647
- if (parent.vcsNodeId && !options.vcsNodeId) {
2648
- options.vcsNodeId = parent.vcsNodeId;
2604
+ //
2605
+ // Inherited as an atomic unit, like Slack context above: a child that
2606
+ // names its own vcsRepo different from the parent's (e.g. `send-task
2607
+ // vcsRepo=...`) inherits NONE of the parent's vcs* fields. Otherwise it
2608
+ // would pair its repo with the parent's number/URL, so PR reconciliation
2609
+ // attaches the parent's PR as the child's deliverable and
2610
+ // `findTaskByVcs` matches an unrelated PR with the same number.
2611
+ const inheritParentVcs =
2612
+ !options.vcsRepo ||
2613
+ (!!parent.vcsRepo && options.vcsRepo.toLowerCase() === parent.vcsRepo.toLowerCase());
2614
+ if (inheritParentVcs) {
2615
+ if (parent.vcsProvider && !options.vcsProvider) {
2616
+ options.vcsProvider = parent.vcsProvider;
2617
+ }
2618
+ if (parent.vcsRepo && !options.vcsRepo) {
2619
+ options.vcsRepo = parent.vcsRepo;
2620
+ }
2621
+ if (parent.vcsNumber != null && options.vcsNumber == null) {
2622
+ options.vcsNumber = parent.vcsNumber;
2623
+ }
2624
+ if (parent.vcsEventType && !options.vcsEventType) {
2625
+ options.vcsEventType = parent.vcsEventType;
2626
+ }
2627
+ if (parent.vcsCommentId != null && options.vcsCommentId == null) {
2628
+ options.vcsCommentId = parent.vcsCommentId;
2629
+ }
2630
+ if (parent.vcsAuthor && !options.vcsAuthor) {
2631
+ options.vcsAuthor = parent.vcsAuthor;
2632
+ }
2633
+ if (parent.vcsUrl && !options.vcsUrl) {
2634
+ options.vcsUrl = parent.vcsUrl;
2635
+ }
2636
+ if (parent.vcsInstallationId != null && options.vcsInstallationId == null) {
2637
+ options.vcsInstallationId = parent.vcsInstallationId;
2638
+ }
2639
+ if (parent.vcsNodeId && !options.vcsNodeId) {
2640
+ options.vcsNodeId = parent.vcsNodeId;
2641
+ }
2649
2642
  }
2650
2643
 
2651
2644
  // Execution context (per-task overrides)
@@ -2962,9 +2955,9 @@ export async function createTaskExtended(
2962
2955
  vcsProvider, vcsRepo, vcsEventType, vcsNumber, vcsCommentId, vcsAuthor, vcsUrl,
2963
2956
  vcsInstallationId, vcsNodeId,
2964
2957
  agentmailInboxId, agentmailMessageId, agentmailThreadId,
2965
- mentionMessageId, mentionChannelId, dir, parentTaskId, model, modelTier, effort, profile, scheduleId,
2958
+ mentionMessageId, mentionChannelId, dir, parentTaskId, dispatchedByTaskId, model, modelTier, effort, profile, scheduleId,
2966
2959
  workflowRunId, workflowRunStepId, outputSchema, followUpConfig, requestedByUserId, requestedByUserIdInherited, contextKey, routingAffinity, swarmVersion, createdAt, lastUpdatedAt, created_by, updated_by, isHumanFree
2967
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *`,
2960
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *`,
2968
2961
  [
2969
2962
  id,
2970
2963
  insertKey,
@@ -3003,6 +2996,7 @@ export async function createTaskExtended(
3003
2996
  options?.mentionChannelId ?? null,
3004
2997
  options?.dir ?? null,
3005
2998
  options?.parentTaskId ?? null,
2999
+ options?.dispatchedByTaskId ?? null,
3006
3000
  options?.model ?? null,
3007
3001
  options?.modelTier ?? null,
3008
3002
  options?.effort ?? null,
@@ -13893,16 +13887,35 @@ export async function sweepExpiredKv(namespace: string, now = Date.now()): Promi
13893
13887
  /** Delete expired entries across a namespace family (`prefix` and
13894
13888
  * `prefix:*`). Used by per-agent internal stores whose inactive owners may
13895
13889
  * never return to trigger a namespace-local sweep. */
13896
- export async function sweepExpiredKvPrefix(prefix: string, now = Date.now()): Promise<number> {
13890
+ export async function sweepExpiredKvPrefix(
13891
+ prefix: string,
13892
+ now = Date.now(),
13893
+ /** Rows per DELETE, capped at 50 for multi-MB values. Yields between batches. */
13894
+ batchSize = 50,
13895
+ ): Promise<number> {
13896
+ batchSize = Math.max(1, Math.min(batchSize, 50));
13897
13897
  const escaped = prefix.replace(/[\\%_]/g, "\\$&");
13898
- const result = await getDbClient().run(
13899
- `DELETE FROM kv_entries
13900
- WHERE (namespace = ? OR namespace LIKE ? ESCAPE '\\')
13901
- AND expires_at IS NOT NULL
13902
- AND expires_at <= ?`,
13903
- [prefix, `${escaped}:%`, now],
13904
- );
13905
- return result.changes;
13898
+ // Batched, with a macrotask yield between batches: one DELETE of every
13899
+ // expired multi-MB overflow row blocked the event loop for seconds and
13900
+ // starved the Slack socket ping. `now` is fixed for the whole sweep, so the
13901
+ // batches delete the same row set as one statement. kv_entries is WITHOUT
13902
+ // ROWID, so a batch selects the (namespace, key) primary key.
13903
+ let removed = 0;
13904
+ for (;;) {
13905
+ const result = await getDbClient().run(
13906
+ `DELETE FROM kv_entries
13907
+ WHERE (namespace, key) IN (
13908
+ SELECT namespace, key FROM kv_entries
13909
+ WHERE (namespace = ? OR namespace LIKE ? ESCAPE '\\')
13910
+ AND expires_at IS NOT NULL
13911
+ AND expires_at <= ?
13912
+ LIMIT ?)`,
13913
+ [prefix, `${escaped}:%`, now, batchSize],
13914
+ );
13915
+ removed += result.changes;
13916
+ if (result.changes < batchSize) return removed;
13917
+ await new Promise<void>((resolve) => setImmediate(resolve));
13918
+ }
13906
13919
  }
13907
13920
 
13908
13921
  /**
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Event-loop stall attribution.
3
+ *
4
+ * Synchronous SQLite runs on the main thread, and a chain of awaited DB calls
5
+ * resolves in the microtask queue, so the whole chain is one macrotask. A
6
+ * stall over 5 s makes the Slack Socket Mode client miss its pong. The OTel
7
+ * `nodejs.eventloop.delay.max` histogram shows that a stall happened, but not
8
+ * when or which code path ran it.
9
+ *
10
+ * This module adds:
11
+ * - a breadcrumb: `withLoopPath(path, fn)` names the entry point (HTTP route,
12
+ * MCP tool, timer) on an AsyncLocalStorage that follows `await`;
13
+ * - a bounded ring of the DB statements run since the last probe tick, fed by
14
+ * the DB client (`recordStatement`);
15
+ * - a `setTimeout` lag probe. A stall of N ms delays its tick by about N ms.
16
+ * The first tick after the stall sees exactly the statements of the stalled
17
+ * macrotask and logs one `[event-loop] stall` line.
18
+ */
19
+ import { AsyncLocalStorage } from "node:async_hooks";
20
+ import { scrubSecrets } from "../utils/secret-scrubber";
21
+
22
+ const pathContext = new AsyncLocalStorage<string>();
23
+
24
+ /** Run `fn` with `path` as the entry point of everything it starts. */
25
+ export function withLoopPath<T>(path: string, fn: () => T): T {
26
+ return pathContext.run(path, fn);
27
+ }
28
+
29
+ /** Wrap `fn` so each call runs with `path` as its entry point. */
30
+ export function bindLoopPath<A extends unknown[], R>(
31
+ path: string,
32
+ fn: (...args: A) => R,
33
+ ): (...args: A) => R {
34
+ return (...args) => pathContext.run(path, fn, ...args);
35
+ }
36
+
37
+ /** Entry point of the code that runs now, or `unknown`. */
38
+ export function currentLoopPath(): string {
39
+ return pathContext.getStore() ?? "unknown";
40
+ }
41
+
42
+ type RecordedStatement = { path: string; sql: string; ms: number };
43
+
44
+ /** Statements shorter than this cannot make a stall worth a log line. */
45
+ const STATEMENT_RECORD_MIN_MS = 10;
46
+ const STATEMENT_RING_MAX = 256;
47
+ const ring: RecordedStatement[] = [];
48
+
49
+ /**
50
+ * Called by the DB client for each driver call. Stores a reference to the SQL
51
+ * string only; the label is built only when a stall line is logged.
52
+ */
53
+ export function recordStatement(sql: string, ms: number): void {
54
+ if (ms < STATEMENT_RECORD_MIN_MS) return;
55
+ if (ring.length === STATEMENT_RING_MAX) ring.shift();
56
+ ring.push({ path: currentLoopPath(), sql, ms });
57
+ }
58
+
59
+ const PROBE_MS = 100;
60
+ const DEFAULT_STALL_WARN_MS = 1000;
61
+ const TOP_STATEMENTS = 3;
62
+ const LABEL_MAX_CHARS = 60;
63
+
64
+ /** Read per tick, so a config reload applies without a restart. */
65
+ function stallWarnMs(): number {
66
+ const raw = Number(process.env.EVENT_LOOP_STALL_WARN_MS);
67
+ return Number.isFinite(raw) && raw > 0 ? raw : DEFAULT_STALL_WARN_MS;
68
+ }
69
+
70
+ /**
71
+ * Scrub the complete SQL before truncation: a secret that straddles the cut
72
+ * would otherwise leave a partial token that no pattern matches.
73
+ */
74
+ function statementLabel(sql: string): string {
75
+ return scrubSecrets(sql.replace(/\s+/g, " ").trim()).slice(0, LABEL_MAX_CHARS);
76
+ }
77
+
78
+ /**
79
+ * Build the stall line from the statements recorded during the stall.
80
+ * Params are never logged: they can carry secrets and user content.
81
+ */
82
+ export function formatStallLine(lagMs: number, statements: readonly RecordedStatement[]): string {
83
+ let dbMs = 0;
84
+ const perPath = new Map<string, number>();
85
+ for (const s of statements) {
86
+ dbMs += s.ms;
87
+ perPath.set(s.path, (perPath.get(s.path) ?? 0) + 1);
88
+ }
89
+ const top = [...statements].sort((a, b) => b.ms - a.ms).slice(0, TOP_STATEMENTS);
90
+ const path = top[0]?.path ?? "unknown";
91
+ const parts = [
92
+ `[event-loop] stall ${Math.round(lagMs)}ms`,
93
+ `path=${path}`,
94
+ `statements=${statements.length}`,
95
+ `db_ms=${Math.round(dbMs)}`,
96
+ ];
97
+ if (top.length > 0) {
98
+ parts.push(`top=${top.map((s) => `${Math.round(s.ms)}ms:${statementLabel(s.sql)}`).join("|")}`);
99
+ parts.push(
100
+ `paths=${[...perPath]
101
+ .sort((a, b) => b[1] - a[1])
102
+ .map(([p, n]) => `${p}:${n}`)
103
+ .join(",")}`,
104
+ );
105
+ }
106
+ // Paths are labels from code, but scrub the complete line at egress anyway.
107
+ return scrubSecrets(parts.join(" "));
108
+ }
109
+
110
+ let stopProbe: (() => void) | null = null;
111
+
112
+ /**
113
+ * Start the lag probe. A `setTimeout` chain, not `setInterval`: missed
114
+ * intervals coalesce and lose the lag value. Returns a stop function.
115
+ */
116
+ export function startEventLoopLagProbe(probeMs = PROBE_MS): () => void {
117
+ if (stopProbe) return stopProbe;
118
+ let timer: ReturnType<typeof setTimeout>;
119
+ let expected = performance.now() + probeMs;
120
+ const schedule = () => {
121
+ timer = setTimeout(tick, probeMs);
122
+ timer.unref?.();
123
+ };
124
+ const tick = () => {
125
+ const now = performance.now();
126
+ const lag = now - expected;
127
+ if (lag >= stallWarnMs()) console.warn(formatStallLine(lag, ring));
128
+ ring.length = 0;
129
+ expected = now + probeMs;
130
+ schedule();
131
+ };
132
+ // The probe owns no entry point: its own ticks must not inherit the caller's.
133
+ pathContext.exit(schedule);
134
+ const stop = () => {
135
+ clearTimeout(timer);
136
+ ring.length = 0;
137
+ if (stopProbe === stop) stopProbe = null;
138
+ };
139
+ stopProbe = stop;
140
+ return stop;
141
+ }
142
+
143
+ /** Stop the probe started by `startEventLoopLagProbe`, if any. */
144
+ export function stopEventLoopLagProbe(): void {
145
+ stopProbe?.();
146
+ }