@desplega.ai/agent-swarm 1.160.0 → 1.162.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 (398) hide show
  1. package/README.md +4 -3
  2. package/dist/{acp-adapter-2mjwcsfh.js → acp-adapter-74m73ae9.js} +163 -49
  3. package/dist/{actions-e43rxskr.js → actions-4sr14gnt.js} +42 -38
  4. package/dist/{anthropic-messages-5qx80j9k.js → anthropic-messages-8xxrzky9.js} +22 -26
  5. package/dist/{app-mc7xfagn.js → app-pt68fbwp.js} +17 -14
  6. package/dist/{artifact-3v5t9jtg.js → artifact-fey7dvj9.js} +3 -2
  7. package/dist/{assistant-sedkzv3b.js → assistant-cv3jytks.js} +43 -39
  8. package/dist/{azure-openai-responses-nfb21z9a.js → azure-openai-responses-f5cqsyj8.js} +15 -10
  9. package/dist/{boot-reembed-m3656j2n.js → boot-reembed-4ht4gqth.js} +17 -14
  10. package/dist/{boot-reembed-cqz9swn5.js → boot-reembed-nxpcvpj9.js} +16 -13
  11. package/dist/{boot-scrub-logs-xbxf5d7w.js → boot-scrub-logs-k93kyw8k.js} +13 -10
  12. package/dist/boot-seeds-1skcrs0e.js +32 -0
  13. package/dist/{claude-adapter-dc6289mc.js → claude-adapter-r5g0tzge.js} +39 -30
  14. package/dist/{claude-managed-adapter-naaw51me.js → claude-managed-adapter-yxkfxg8j.js} +6 -5
  15. package/dist/{claude-managed-setup-eacvchx0.js → claude-managed-setup-pkyrgshb.js} +27 -27
  16. package/dist/{claude-sdk-session-bqp2xvym.js → claude-sdk-session-jxyxnrwd.js} +8041 -7910
  17. package/dist/{cli-4derpgyk.js → cli-2hhfhfq5.js} +6 -1
  18. package/dist/{cli-rykfmgwg.js → cli-2x0e561b.js} +1 -1
  19. package/dist/{cli-tzx2ke1v.js → cli-2zy95vhm.js} +137 -64
  20. package/dist/{cli-0x01kwrd.js → cli-4cwxn7gp.js} +47 -186
  21. package/dist/{cli-xjcywfsf.js → cli-4dcpaefp.js} +12 -11
  22. package/dist/{cli-v7fn5gms.js → cli-4x0csdjq.js} +164 -76
  23. package/dist/{cli-12tszpk9.js → cli-5bcd7sfy.js} +91 -29
  24. package/dist/{cli-jz4w45qt.js → cli-5k6k8ta3.js} +190 -50
  25. package/dist/{cli-tpq83z89.js → cli-5xhpb3kv.js} +20 -19
  26. package/dist/{cli-r1mxd1xh.js → cli-7af8yhav.js} +6 -179
  27. package/dist/{cli-jajnsm8q.js → cli-7tre70zp.js} +18160 -31345
  28. package/dist/{cli-447dt1h3.js → cli-8ev9xqnx.js} +218 -25
  29. package/dist/cli-bsky8g7w.js +449 -0
  30. package/dist/{cli-0z2v4nhw.js → cli-cat6h73s.js} +1 -1
  31. package/dist/{cli-25fcq4b4.js → cli-cebmgwsc.js} +15 -11
  32. package/dist/{cli-shkxm1vn.js → cli-cvatsam7.js} +189 -13
  33. package/dist/{cli-2658f6at.js → cli-cvk6yzw5.js} +6 -8
  34. package/dist/cli-dbmwby6a.js +9 -0
  35. package/dist/{cli-ptr8h7kp.js → cli-eg0b3p0k.js} +5 -218
  36. package/dist/cli-f9w1semm.js +413 -0
  37. package/dist/{cli-523679eh.js → cli-g739zqzt.js} +6 -5
  38. package/dist/{cli-dv6cdjs2.js → cli-gd4favx9.js} +28 -7
  39. package/dist/{cli-c8a36vcc.js → cli-gpqpmns7.js} +2 -2
  40. package/dist/{cli-5nbmpy8w.js → cli-hb5c2x5y.js} +1 -1
  41. package/dist/{cli-741yb0xx.js → cli-hmsw1gpy.js} +55 -169
  42. package/dist/{cli-qydf22qq.js → cli-jf7wmv1r.js} +2562 -735
  43. package/dist/{cli-mfe5btp9.js → cli-jxs2ygaw.js} +317 -121
  44. package/dist/{cli-kmcpfwn2.js → cli-jyy6pm2f.js} +19 -3
  45. package/dist/cli-kdkwd3yr.js +615 -0
  46. package/dist/{cli-6cs6wzxt.js → cli-kh04eqwe.js} +2 -2
  47. package/dist/{cli-9hsgwz4w.js → cli-kp42yek0.js} +1309 -391
  48. package/dist/cli-ma3zvh39.js +10404 -0
  49. package/dist/{cli-ybgv4kw2.js → cli-mbssg1xv.js} +9 -2
  50. package/dist/{cli-jsp14b6c.js → cli-mzfth0bp.js} +38 -1
  51. package/dist/{cli-r2ap2czm.js → cli-nexqx4ve.js} +6 -0
  52. package/dist/{cli-f8gy6r2r.js → cli-nq7yqw7b.js} +19 -8
  53. package/dist/{cli-10nhj6xq.js → cli-nt8hecg9.js} +34 -33
  54. package/dist/cli-p0r8sxj5.js +303 -0
  55. package/dist/{cli-58e8yr0d.js → cli-pkd6s2wy.js} +4 -2
  56. package/dist/{cli-a8dvhzrt.js → cli-q24re23n.js} +7 -5
  57. package/dist/cli-qjjvzwzd.js +222 -0
  58. package/dist/cli-qrgt5bqf.js +189 -0
  59. package/dist/{cli-et8m9xsv.js → cli-rfjw9jw2.js} +22 -10
  60. package/dist/{cli-7e398j1h.js → cli-rj0gqwwp.js} +3 -3
  61. package/dist/{cli-btfv8y88.js → cli-rnyzn44p.js} +2 -2
  62. package/dist/{cli-d5czme6m.js → cli-s3hwpt9v.js} +4754 -4945
  63. package/dist/{cli-0jwe9034.js → cli-sptrj5f5.js} +3 -3
  64. package/dist/{cli-0q3avq3s.js → cli-sqvfa090.js} +19 -11
  65. package/dist/{cli-azhgzetg.js → cli-swfmp1fx.js} +27 -27
  66. package/dist/{cli-jyk0ynw2.js → cli-t845n9xk.js} +23 -10
  67. package/dist/{cli-zpep9q5e.js → cli-tcen9p5w.js} +20 -15
  68. package/dist/{cli-74h9hscv.js → cli-tre4bdgq.js} +1 -1
  69. package/dist/{cli-pm1rst0h.js → cli-twrh04ap.js} +30 -15
  70. package/dist/{cli-phsaj4xq.js → cli-v0pvvhfq.js} +1 -1
  71. package/dist/{cli-ydmcgve1.js → cli-vc9bp061.js} +5 -5
  72. package/dist/{cli-g2whhdrf.js → cli-vxe6qa4h.js} +1 -1
  73. package/dist/{cli-vctdqs5h.js → cli-vy3ed88x.js} +15 -2
  74. package/dist/{cli-br0qdrnp.js → cli-vyqs9ya8.js} +18 -18
  75. package/dist/{cli-cpvsaqsw.js → cli-w0bwte75.js} +8 -5
  76. package/dist/cli-wbvnn6tk.js +861 -0
  77. package/dist/{cli-r94z9p1z.js → cli-wgbezhw2.js} +3 -0
  78. package/dist/{cli-evvtk35y.js → cli-wjgs5wxe.js} +7 -7
  79. package/dist/cli-wxkkd0e0.js +33 -0
  80. package/dist/{cli-0wgxmwf6.js → cli-xk79303e.js} +20 -7
  81. package/dist/{cli-ktmyrtpn.js → cli-xqpk3rp7.js} +33 -10
  82. package/dist/{cli-ygwm91nt.js → cli-yy6dew39.js} +1 -1
  83. package/dist/cli-zp38xvtm.js +9487 -0
  84. package/dist/{cli-tfky2838.js → cli-zvhd3f64.js} +4 -4
  85. package/dist/{cli-jayjpjmb.js → cli-zxqx25nz.js} +66 -23
  86. package/dist/cli.js +40 -32
  87. package/dist/{cloudflare-workers-ai-system-one-k6fbxw9d.js → cloudflare-workers-ai-system-one-k8ddqjkq.js} +8 -6
  88. package/dist/{codex-adapter-nmxcatww.js → codex-adapter-esvmnhn7.js} +24 -23
  89. package/dist/{codex-hook-20me6byw.js → codex-hook-m73jmqgx.js} +19 -3
  90. package/dist/{codex-login-w6fz4xbz.js → codex-login-cf7mzsgg.js} +2 -2
  91. package/dist/{codex-session-runner-90aa80ev.js → codex-session-runner-ban9excr.js} +24 -23
  92. package/dist/{commands-8wcq1kn7.js → commands-75413p2n.js} +13 -10
  93. package/dist/{db-j40kc4se.js → db-7f5pecwg.js} +17 -10
  94. package/dist/{dispatcher-4zqy768d.js → dispatcher-fh9at8nz.js} +41 -37
  95. package/dist/dsh-adapter-wpze65d4.js +24 -0
  96. package/dist/{e2b-ez07znam.js → e2b-gjgdjp91.js} +12 -9
  97. package/dist/easter-egg-3d-3w5c2n4c.js +1057 -0
  98. package/dist/{execute-6e7qeyk4.js → execute-f50wg9nh.js} +203 -49
  99. package/dist/{google-generative-ai-k6n5nbpp.js → google-generative-ai-jxxpnegy.js} +2 -2
  100. package/dist/{google-vertex-44xxtcvp.js → google-vertex-x7q1angm.js} +5 -5
  101. package/dist/{handlers-kjdce1w5.js → handlers-w13787bb.js} +44 -40
  102. package/dist/{hook-r2t4bqfg.js → hook-46g1jrvx.js} +34 -20
  103. package/dist/{hook-czx13n12.js → hook-4tpts2ry.js} +25 -21
  104. package/dist/{http-3bbb19be.js → http-19pzbfrt.js} +1440 -283
  105. package/dist/{index-668me3f0.js → index-8fd4dm4h.js} +42 -38
  106. package/dist/{index-fg0dsp6c.js → index-dqmp15bq.js} +41 -37
  107. package/dist/{index-kkv84jq9.js → index-qb4q1y3e.js} +41 -37
  108. package/dist/index-s75wc4wd.js +33 -0
  109. package/dist/{index-zg7vp46x.js → index-scptvdxg.js} +64 -38
  110. package/dist/{keepalive-yra8dy57.js → keepalive-xa5ts9cd.js} +15 -12
  111. package/dist/{lead-va0pad2c.js → lead-qp4xkvjq.js} +59 -54
  112. package/dist/{maintenance-hqewtmyg.js → maintenance-rm5885hm.js} +17 -14
  113. package/dist/{mistral-conversations-pc3ntnxt.js → mistral-conversations-rw7fbt22.js} +4 -4
  114. package/dist/{node-a5e00qhp.js → node-8zkdq42h.js} +834 -833
  115. package/dist/node-f0ykebbv.js +2107 -0
  116. package/dist/node-wyamey5r.js +19 -0
  117. package/dist/{oauth-refresh-sweep-7rdt1m9n.js → oauth-refresh-sweep-1csdfebf.js} +14 -11
  118. package/dist/{onboard-j6ms6d0x.js → onboard-r6b78cs4.js} +10 -10
  119. package/dist/{openai-codex-responses-bbancrr0.js → openai-codex-responses-efvrgrq3.js} +4 -4
  120. package/dist/{openai-completions-jpaj5g2b.js → openai-completions-bbbrrz4z.js} +12 -8
  121. package/dist/{openai-responses-200k1wx4.js → openai-responses-9jjyrcm1.js} +15 -10
  122. package/dist/{opencode-adapter-89rabkw2.js → opencode-adapter-kb3g6pkf.js} +12 -9
  123. package/dist/{otel-impl-a792rjz0.js → otel-impl-0y9knpky.js} +6 -6
  124. package/dist/{pi-mono-adapter-g7qzvr3v.js → pi-mono-adapter-z6s1bme2.js} +128 -37
  125. package/dist/{pricing-refresh-wx0tp7cb.js → pricing-refresh-mth26tgp.js} +15 -12
  126. package/dist/{rbac-roles-8tzawacv.js → rbac-roles-kwntb23q.js} +17 -12
  127. package/dist/rbac-roles-vpk4ebm8.js +45 -0
  128. package/dist/{registry-v5wytg0s.js → registry-km6t1jd2.js} +1 -1
  129. package/dist/{render-v2-mm7zswb8.js → render-v2-hcm7h00y.js} +17 -14
  130. package/dist/{runtime-zyssgse0.js → runtime-vfjsfsc5.js} +5 -4
  131. package/dist/{setup-8y70ys6t.js → setup-hbyzd65h.js} +2 -2
  132. package/dist/{virtual-modules-6nmk7h3n.js → virtual-modules-9bv7ry91.js} +9 -7
  133. package/dist/{work-objects-fg6xkb0n.js → work-objects-m09sxnhe.js} +44 -40
  134. package/dist/{worker-wmwhxsph.js → worker-0h35rvk4.js} +59 -54
  135. package/dist/{x-n3e0v3xa.js → x-f1gt1pz3.js} +2 -2
  136. package/openapi.json +699 -26
  137. package/package.json +19 -11
  138. package/src/azure-devops/api.ts +121 -0
  139. package/src/azure-devops/auth.ts +78 -0
  140. package/src/azure-devops/handlers.ts +413 -0
  141. package/src/azure-devops/index.ts +27 -0
  142. package/src/azure-devops/templates.ts +108 -0
  143. package/src/azure-devops/types.ts +90 -0
  144. package/src/be/api-drain.ts +184 -0
  145. package/src/be/db/tasks/read.ts +32 -7
  146. package/src/be/db/tasks/write.ts +21 -4
  147. package/src/be/db-client.ts +11 -2
  148. package/src/be/db-retention.ts +95 -32
  149. package/src/be/db.ts +44 -19
  150. package/src/be/memory/constants.ts +16 -0
  151. package/src/be/memory/graph-expansion.ts +8 -1
  152. package/src/be/memory/index-content.ts +20 -1
  153. package/src/be/memory/key-guard.ts +93 -0
  154. package/src/be/memory/key-paths.ts +103 -0
  155. package/src/be/memory/link-resolver.ts +29 -3
  156. package/src/be/memory/providers/sqlite-store.ts +152 -45
  157. package/src/be/memory/raters/llm-summarizer.ts +10 -4
  158. package/src/be/memory/raters/llm.ts +15 -5
  159. package/src/be/memory/raters/store.ts +6 -3
  160. package/src/be/memory/raters/types.ts +11 -0
  161. package/src/be/memory/reranker.ts +38 -7
  162. package/src/be/memory/types.ts +12 -1
  163. package/src/be/migrations/190_memory_rating_model.sql +7 -0
  164. package/src/be/migrations/191_context_versions_previous_index.sql +8 -0
  165. package/src/be/migrations/192_favorites_agent_fs_path.sql +36 -0
  166. package/src/be/onboarding.ts +7 -1
  167. package/src/be/pricing-normalize.ts +4 -2
  168. package/src/be/scripts/typecheck.ts +4 -3
  169. package/src/be/seed-pricing.ts +16 -0
  170. package/src/be/seed-prompt-templates.ts +1 -0
  171. package/src/be/swarm-config-guard.ts +46 -17
  172. package/src/be/task-citations.ts +11 -5
  173. package/src/be/users.ts +3 -0
  174. package/src/cli.tsx +3 -2
  175. package/src/comb/agent-fs.ts +39 -0
  176. package/src/comb/config.ts +37 -0
  177. package/src/comb/markers.ts +37 -0
  178. package/src/comb/review-batch.ts +486 -0
  179. package/src/comb/templates.ts +88 -0
  180. package/src/commands/claude-managed-setup.ts +33 -31
  181. package/src/commands/context-preamble.ts +4 -1
  182. package/src/commands/hook.ts +2 -1
  183. package/src/commands/provider-credentials.ts +28 -15
  184. package/src/commands/runner.ts +458 -110
  185. package/src/commands/templates.ts +10 -0
  186. package/src/e2b/env.ts +2 -0
  187. package/src/extensions/catalog.generated.json +17 -0
  188. package/src/extensions/contract-types.generated.ts +1 -1
  189. package/src/fs/agent-fs-provider.ts +106 -2
  190. package/src/github/handlers.ts +10 -74
  191. package/src/github/reactions.ts +119 -138
  192. package/src/github/task-reactions.ts +34 -11
  193. package/src/heartbeat/heartbeat.ts +4 -0
  194. package/src/hooks/codex-hook.ts +25 -1
  195. package/src/hooks/hook.ts +14 -1
  196. package/src/hooks/pr-body-guard.ts +983 -0
  197. package/src/http/agents.ts +1 -1
  198. package/src/http/all-routes.ts +1 -0
  199. package/src/http/assets.ts +5 -17
  200. package/src/http/comb.ts +131 -0
  201. package/src/http/core.ts +14 -1
  202. package/src/http/extensions.ts +51 -27
  203. package/src/http/fs.ts +9 -17
  204. package/src/http/index.ts +27 -9
  205. package/src/http/mcp-user.ts +8 -13
  206. package/src/http/mcp.ts +19 -12
  207. package/src/http/memory.ts +80 -14
  208. package/src/http/onboarding.ts +21 -2
  209. package/src/http/poll.ts +30 -3
  210. package/src/http/realtime.ts +62 -0
  211. package/src/http/request-principal.ts +22 -0
  212. package/src/http/session-data.ts +6 -4
  213. package/src/http/stats.ts +1 -0
  214. package/src/http/status.ts +34 -2
  215. package/src/http/tasks.ts +17 -3
  216. package/src/http/users.ts +1 -1
  217. package/src/http/webhooks.ts +120 -2
  218. package/src/kv-reserved-namespaces.ts +10 -5
  219. package/src/providers/claude-adapter.ts +84 -16
  220. package/src/providers/claude-managed-adapter.ts +29 -2
  221. package/src/providers/codex-adapter.ts +1 -1
  222. package/src/providers/codex-skill-resolver.ts +6 -0
  223. package/src/providers/dsh-adapter.ts +204 -7
  224. package/src/providers/opencode-adapter.ts +24 -3
  225. package/src/providers/pi-mono-adapter.ts +154 -5
  226. package/src/providers/pi-mono-extension.ts +1 -1
  227. package/src/providers/pricing-sources.md +5 -1
  228. package/src/providers/reasoning-effort.ts +10 -2
  229. package/src/providers/types.ts +1 -1
  230. package/src/rbac/legacy-policy.ts +3 -0
  231. package/src/rbac/permissions.ts +14 -0
  232. package/src/realtime/auth.ts +63 -1
  233. package/src/realtime/tickets.ts +52 -0
  234. package/src/realtime/transport.ts +51 -22
  235. package/src/scripts-runtime/types/stdlib.d.ts +13 -5
  236. package/src/scripts-runtime/types/swarm-extension.d.ts +7 -3
  237. package/src/scripts-runtime/types/swarm-sdk.d.ts +13 -5
  238. package/src/tasks/context-key.ts +38 -1
  239. package/src/telemetry-context.ts +175 -0
  240. package/src/telemetry-contract/EVENTS.md +81 -0
  241. package/src/telemetry-contract/SOURCE.json +9 -0
  242. package/src/telemetry-contract/catalog.json +1335 -0
  243. package/src/telemetry-contract/index.ts +60 -0
  244. package/src/telemetry-contract/types.gen.ts +1971 -0
  245. package/src/telemetry-identity.ts +129 -0
  246. package/src/telemetry-snapshot.ts +211 -0
  247. package/src/telemetry-trigger.ts +125 -0
  248. package/src/telemetry-types.typetest.ts +40 -0
  249. package/src/telemetry.ts +271 -67
  250. package/src/tests/api-drain-e2e.test.ts +249 -0
  251. package/src/tests/api-drain-worker-e2e.test.ts +216 -0
  252. package/src/tests/api-drain.test.ts +351 -0
  253. package/src/tests/azure-devops-auth.test.ts +100 -0
  254. package/src/tests/azure-devops-handlers.test.ts +324 -0
  255. package/src/tests/azure-devops-webhook-malformed.test.ts +96 -0
  256. package/src/tests/claude-default-route.test.ts +260 -0
  257. package/src/tests/claude-managed-adapter.test.ts +47 -0
  258. package/src/tests/claude-managed-setup.test.ts +48 -0
  259. package/src/tests/claude-prompt-body-once.test.ts +117 -0
  260. package/src/tests/claude-routes-e2e.test.ts +316 -0
  261. package/src/tests/comb-config-guard.test.ts +38 -0
  262. package/src/tests/comb-links.test.ts +162 -0
  263. package/src/tests/comb-markers.test.ts +68 -0
  264. package/src/tests/comb-review-batch.test.ts +770 -0
  265. package/src/tests/comb-status.test.ts +152 -0
  266. package/src/tests/context-versions-retention.test.ts +314 -0
  267. package/src/tests/core-auth.test.ts +7 -0
  268. package/src/tests/db-retention.test.ts +14 -14
  269. package/src/tests/db-task-read-contract.test.ts +3 -0
  270. package/src/tests/db-task-write-contract.test.ts +3 -0
  271. package/src/tests/docs-index-footprint.test.js +3 -3
  272. package/src/tests/dsh-adapter.test.ts +134 -2
  273. package/src/tests/dsh-usage.test.ts +153 -0
  274. package/src/tests/extensions-catalog.test.ts +1 -0
  275. package/src/tests/extensions-example-deploy-awareness.test.ts +301 -0
  276. package/src/tests/extensions-http.test.ts +137 -10
  277. package/src/tests/extensions-mcp-tools.test.ts +28 -0
  278. package/src/tests/favorites-agent-fs-path.test.ts +226 -0
  279. package/src/tests/fetch-resolved-env.test.ts +24 -0
  280. package/src/tests/fixtures/azure-devops/pull-request-commented.json +129 -0
  281. package/src/tests/fixtures/azure-devops/pull-request-created.json +88 -0
  282. package/src/tests/fixtures/fake-claude-routes.ts +229 -0
  283. package/src/tests/github-handlers-reactions.test.ts +486 -0
  284. package/src/tests/github-reactions.test.ts +280 -0
  285. package/src/tests/harness-cli-version.test.ts +62 -0
  286. package/src/tests/http-api-integration.test.ts +21 -0
  287. package/src/tests/http-task-write-ownership.test.ts +24 -1
  288. package/src/tests/internal-ai/complete-structured.test.ts +94 -0
  289. package/src/tests/internal-ai/credentials.test.ts +22 -0
  290. package/src/tests/internal-ai/models.test.ts +36 -2
  291. package/src/tests/internal-ai/schema-parity.test.ts +25 -1
  292. package/src/tests/internal-ai/summarize-session.test.ts +23 -7
  293. package/src/tests/mcp-user-route.test.ts +133 -0
  294. package/src/tests/memory-key-paths.test.ts +1055 -0
  295. package/src/tests/memory-link-resolver.test.ts +34 -0
  296. package/src/tests/memory-rate-endpoint.test.ts +66 -0
  297. package/src/tests/memory-rater-llm-summarizer.test.ts +2 -1
  298. package/src/tests/memory-rater-llm.test.ts +73 -0
  299. package/src/tests/memory-rater-store.test.ts +31 -0
  300. package/src/tests/memory-reranker.test.ts +40 -0
  301. package/src/tests/onboarding.test.ts +108 -0
  302. package/src/tests/opencode-adapter.test.ts +57 -0
  303. package/src/tests/opencode-plugin.test.ts +4 -0
  304. package/src/tests/pi-codemode.test.ts +82 -4
  305. package/src/tests/pi-mono-adapter.test.ts +265 -2
  306. package/src/tests/pr-body-leaks.test.ts +789 -0
  307. package/src/tests/preload.ts +14 -0
  308. package/src/tests/provider-registration.test.ts +0 -2
  309. package/src/tests/providers/pi-cost.test.ts +190 -4
  310. package/src/tests/rbac-engine.test.ts +25 -1
  311. package/src/tests/realtime-room-auth.test.ts +104 -1
  312. package/src/tests/realtime-tickets.test.ts +74 -0
  313. package/src/tests/realtime-transport.test.ts +131 -4
  314. package/src/tests/runner-api-drain.test.ts +301 -0
  315. package/src/tests/runner-fallback-output.test.ts +61 -0
  316. package/src/tests/runner-fenced-json-output.test.ts +178 -0
  317. package/src/tests/runner-slot-reconcile.test.ts +199 -0
  318. package/src/tests/script-connections.test.ts +6 -0
  319. package/src/tests/send-task-requested-by.test.ts +133 -15
  320. package/src/tests/session-costs-recompute-all-providers.test.ts +23 -0
  321. package/src/tests/task-lifecycle-telemetry.test.ts +8 -3
  322. package/src/tests/task-reactions.test.ts +29 -6
  323. package/src/tests/telemetry-context.test.ts +314 -0
  324. package/src/tests/telemetry-init.test.ts +51 -19
  325. package/src/tests/telemetry-snapshot.test.ts +229 -0
  326. package/src/tests/telemetry-trigger.test.ts +200 -0
  327. package/src/tests/template-registry-helpers.ts +1 -0
  328. package/src/tests/vcs-azure-devops.test.ts +73 -0
  329. package/src/tests/webhooks-task-blocked.test.ts +23 -0
  330. package/src/tests/workflow-agent-task-retry.test.ts +363 -0
  331. package/src/tests/workflow-definition-telemetry.test.ts +4 -4
  332. package/src/tests/workflow-llm.test.ts +14 -0
  333. package/src/tools/context-diff.ts +20 -0
  334. package/src/tools/extension-install.ts +27 -16
  335. package/src/tools/memory-edit.ts +47 -3
  336. package/src/tools/memory-search.ts +13 -1
  337. package/src/tools/memory-store.ts +55 -3
  338. package/src/tools/poll-task.ts +20 -1
  339. package/src/tools/send-task.ts +9 -1
  340. package/src/tools/task-action.ts +11 -0
  341. package/src/types.ts +45 -8
  342. package/src/utils/api-drain.ts +24 -0
  343. package/src/utils/constants.ts +57 -16
  344. package/src/utils/credentials.test.ts +31 -1
  345. package/src/utils/credentials.ts +20 -9
  346. package/src/utils/dsh-usage.ts +53 -0
  347. package/src/utils/harness-cli-version.ts +6 -4
  348. package/src/utils/internal-ai/complete-structured.ts +26 -3
  349. package/src/utils/internal-ai/credentials.ts +23 -9
  350. package/src/utils/internal-ai/index.ts +8 -1
  351. package/src/utils/internal-ai/models.ts +34 -8
  352. package/src/utils/internal-ai/summarize-session.ts +22 -8
  353. package/src/utils/pr-body-leaks.ts +172 -0
  354. package/src/utils/secret-scrubber.ts +8 -0
  355. package/src/utils/task-attachment-links.ts +14 -8
  356. package/src/vcs/azure-devops.ts +80 -0
  357. package/src/vcs/index.ts +5 -1
  358. package/src/vcs/types.ts +2 -2
  359. package/src/workflows/recovery.ts +26 -1
  360. package/src/workflows/resume.ts +31 -4
  361. package/src/workflows/task-step-routing.ts +75 -2
  362. package/templates/community/open-prompt-showreel/PLAYBOOK.md +336 -0
  363. package/templates/community/open-prompt-showreel/README.md +33 -0
  364. package/templates/community/open-prompt-showreel/example/tla-races/facts.ts +145 -0
  365. package/templates/community/open-prompt-showreel/example/tla-races/facts.v3.json +140 -0
  366. package/templates/community/open-prompt-showreel/example/tla-races/music.mist-city.json +8 -0
  367. package/templates/community/open-prompt-showreel/example/tla-races/reel.html +805 -0
  368. package/templates/community/open-prompt-showreel/example/tla-races/smoke.sh +48 -0
  369. package/templates/community/open-prompt-showreel/lead-prompt.md +89 -0
  370. package/templates/community/open-prompt-showreel/setup.sh +167 -0
  371. package/templates/community/open-prompt-showreel/skills/motion-design-replication/SKILL.md +85 -0
  372. package/templates/community/open-prompt-showreel/skills/motion-design-video-analysis/SKILL.md +115 -0
  373. package/templates/community/open-prompt-showreel/skills/open-prompt-showreel/SKILL.md +147 -0
  374. package/templates/community/open-prompt-showreel/skills/video-generation/SKILL.md +195 -0
  375. package/templates/community/open-prompt-showreel/tools/fetch-music.sh +65 -0
  376. package/templates/community/open-prompt-showreel/tools/music-analyze.py +69 -0
  377. package/templates/community/open-prompt-showreel/tools/music-current.sh +34 -0
  378. package/templates/community/open-prompt-showreel/tools/music-cut.sh +36 -0
  379. package/templates/community/open-prompt-showreel/tools/music-refine.py +39 -0
  380. package/templates/community/open-prompt-showreel/tools/render.mjs +157 -0
  381. package/templates/community/open-prompt-showreel/tools/sheet.sh +44 -0
  382. package/templates/community/open-prompt-showreel/tools/web-compress.sh +17 -0
  383. package/templates/community/open-prompt-showreel/tools/x-reencode.sh +21 -0
  384. package/templates/extensions/README.md +1 -0
  385. package/templates/extensions/deploy-awareness/README.md +28 -0
  386. package/templates/extensions/deploy-awareness/hooks.ts +152 -0
  387. package/templates/extensions/deploy-awareness/manifest.json +8 -0
  388. package/templates/skills/memory/config.json +2 -2
  389. package/templates/skills/memory/content.md +59 -5
  390. package/templates/skills/swarm-extensions/config.json +1 -1
  391. package/templates/skills/swarm-extensions/content.md +28 -5
  392. package/tsconfig.json +3 -0
  393. package/dist/boot-seeds-gsetbs5y.js +0 -28
  394. package/dist/cli-j490egb5.js +0 -5632
  395. package/dist/cli-tjf4cn8z.js +0 -9119
  396. package/dist/cli-tmqt7dpj.js +0 -572
  397. package/dist/dsh-adapter-mpnzgztj.js +0 -19
  398. package/dist/index-7aj368tw.js +0 -30
@@ -0,0 +1,27 @@
1
+ // Azure DevOps Integration
2
+ export {
3
+ likeAzureDevOpsComment,
4
+ postAzureDevOpsPullRequestComment,
5
+ resetAzureDevOpsBotIdCache,
6
+ resolveAzureDevOpsBotId,
7
+ } from "./api";
8
+ export {
9
+ AZURE_DEVOPS_BOT_NAME,
10
+ getAzureDevOpsOrgUrl,
11
+ getAzureDevOpsToken,
12
+ initAzureDevOps,
13
+ isAzureDevOpsEnabled,
14
+ resetAzureDevOps,
15
+ verifyAzureDevOpsWebhook,
16
+ } from "./auth";
17
+ export {
18
+ commentedPayloadOf,
19
+ createdPullRequestOf,
20
+ handlePullRequestCommented,
21
+ handlePullRequestCreated,
22
+ } from "./handlers";
23
+ export type {
24
+ AzureDevOpsWebhookEvent,
25
+ PullRequestCommentedEvent,
26
+ PullRequestCreatedEvent,
27
+ } from "./types";
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Azure DevOps event prompt template definitions.
3
+ *
4
+ * Each template is registered at module load time via registerTemplate().
5
+ * Handlers import this module for the side-effect of registration.
6
+ *
7
+ * Template text uses {{variable}} syntax. The resolver interpolates variables
8
+ * and expands {{@template[id]}} references before returning the final text.
9
+ */
10
+
11
+ import { registerTemplate } from "../prompts/registry";
12
+
13
+ // ============================================================================
14
+ // Common building blocks (Azure DevOps-specific)
15
+ // ============================================================================
16
+
17
+ registerTemplate({
18
+ eventType: "common.delegation_instruction.azure_devops",
19
+ header: "",
20
+ defaultBody:
21
+ "\n\n**Delegation instruction:** As the lead agent, analyze this and decide whether to handle it yourself or delegate to a worker agent. Use `send-task` to delegate with clear instructions.",
22
+ variables: [],
23
+ category: "common",
24
+ });
25
+
26
+ // `az repos` has no comment command, so replies go through `az devops invoke`.
27
+ registerTemplate({
28
+ eventType: "common.command_suggestions.azure_devops_pr",
29
+ header: "",
30
+ defaultBody:
31
+ 'Workers have the `az` CLI with the azure-devops extension, authenticated with the swarm PAT. Inspect the PR with `az repos pr show --id {{pr_id}}`. To reply on the PR, write `{"comments":[{"content":"<reply>"}],"status":1}` to a JSON file and run `az devops invoke --area git --resource pullRequestThreads --route-parameters project={{project}} repositoryId={{repository}} pullRequestId={{pr_id}} --http-method POST --in-file <file> --api-version 7.1`.',
32
+ variables: [
33
+ { name: "pr_id", description: "Pull request ID" },
34
+ { name: "project", description: "Azure DevOps project name" },
35
+ { name: "repository", description: "Azure Repos repository name" },
36
+ ],
37
+ category: "common",
38
+ });
39
+
40
+ const SHARED_VARIABLES = [
41
+ { name: "pr_id", description: "Pull request ID" },
42
+ { name: "pr_title", description: "Pull request title" },
43
+ {
44
+ name: "repo",
45
+ description: "Repository clone URL (https://dev.azure.com/<org>/<project>/_git/<repo>)",
46
+ },
47
+ { name: "project", description: "Azure DevOps project name" },
48
+ { name: "repository", description: "Azure Repos repository name" },
49
+ { name: "pr_url", description: "Pull request web URL" },
50
+ ];
51
+
52
+ // ============================================================================
53
+ // Pull request events
54
+ // ============================================================================
55
+
56
+ registerTemplate({
57
+ eventType: "azure-devops.pull_request.opened",
58
+ header: "[Azure DevOps PR #{{pr_id}}] {{pr_title}}",
59
+ defaultBody: `Repo: {{repo}}
60
+ Author: {{username}}
61
+ Branch: {{source_branch}} → {{target_branch}}
62
+ URL: {{pr_url}}
63
+
64
+ {{context_section}}{{@template[common.command_suggestions.azure_devops_pr]}}{{@template[common.delegation_instruction.azure_devops]}}`,
65
+ variables: [
66
+ ...SHARED_VARIABLES,
67
+ {
68
+ name: "username",
69
+ description:
70
+ "Author identity — resolved canonical name (e.g. 'Luis (azure-devops:luis@example.com)') or the UNKNOWN sentinel",
71
+ },
72
+ { name: "source_branch", description: "Source branch name" },
73
+ { name: "target_branch", description: "Target branch name" },
74
+ { name: "context_section", description: "Context section with description or empty string" },
75
+ ],
76
+ category: "event",
77
+ });
78
+
79
+ // ============================================================================
80
+ // Pull request comment events
81
+ // ============================================================================
82
+
83
+ registerTemplate({
84
+ eventType: "azure-devops.comment.mentioned",
85
+ header: "[Azure DevOps Comment on PR #{{pr_id}}] {{username}} mentioned bot",
86
+ defaultBody: `Repo: {{repo}}
87
+ PR: {{pr_title}}
88
+ URL: {{pr_url}}
89
+
90
+ Comment:
91
+ {{context}}{{existing_task_note}}
92
+
93
+ {{@template[common.command_suggestions.azure_devops_pr]}}{{@template[common.delegation_instruction.azure_devops]}}`,
94
+ variables: [
95
+ ...SHARED_VARIABLES,
96
+ {
97
+ name: "username",
98
+ description:
99
+ "Comment author identity — resolved canonical name (e.g. 'Luis (azure-devops:luis@example.com)') or the UNKNOWN sentinel",
100
+ },
101
+ { name: "context", description: "Extracted mention context from comment" },
102
+ {
103
+ name: "existing_task_note",
104
+ description: "Note about existing active task, or empty string",
105
+ },
106
+ ],
107
+ category: "event",
108
+ });
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Azure DevOps service-hook payload types.
3
+ *
4
+ * Based on https://learn.microsoft.com/azure/devops/service-hooks/events
5
+ * (resource version 1.0 for pull requests, 2.0 for pull request comments).
6
+ * Only the fields we actually use are typed.
7
+ */
8
+
9
+ export interface AzureDevOpsIdentityRef {
10
+ id: string; // identity GUID; a picker @mention stores it as `@<GUID>`
11
+ displayName: string;
12
+ uniqueName?: string; // usually the sign-in email
13
+ url?: string;
14
+ imageUrl?: string;
15
+ }
16
+
17
+ export interface AzureDevOpsProjectRef {
18
+ id: string;
19
+ name: string;
20
+ url?: string;
21
+ }
22
+
23
+ export interface AzureDevOpsRepository {
24
+ id: string;
25
+ name: string;
26
+ url: string; // REST URL of the repository
27
+ project: AzureDevOpsProjectRef;
28
+ defaultBranch?: string;
29
+ remoteUrl: string; // clone URL, may carry a `user@` prefix
30
+ }
31
+
32
+ export interface AzureDevOpsPullRequest {
33
+ repository: AzureDevOpsRepository;
34
+ pullRequestId: number;
35
+ status: string; // "active" | "abandoned" | "completed"
36
+ createdBy: AzureDevOpsIdentityRef;
37
+ title: string;
38
+ description?: string | null;
39
+ sourceRefName: string; // e.g. "refs/heads/feature"
40
+ targetRefName: string;
41
+ url: string; // REST URL of the pull request
42
+ _links?: { web?: { href: string } };
43
+ }
44
+
45
+ export interface AzureDevOpsComment {
46
+ id: number;
47
+ parentCommentId: number;
48
+ author: AzureDevOpsIdentityRef;
49
+ content: string;
50
+ publishedDate: string;
51
+ lastContentUpdatedDate?: string;
52
+ commentType: string; // "text" | "system" | "codeChange"
53
+ _links?: {
54
+ self?: { href: string };
55
+ threads?: { href: string };
56
+ };
57
+ }
58
+
59
+ interface ResourceContainer {
60
+ id: string;
61
+ baseUrl?: string; // e.g. "https://dev.azure.com/fabrikam/"
62
+ }
63
+
64
+ interface ServiceHookEvent<TType extends string, TResource> {
65
+ id: string;
66
+ eventType: TType;
67
+ publisherId: string;
68
+ resource: TResource;
69
+ resourceVersion?: string;
70
+ resourceContainers?: {
71
+ collection?: ResourceContainer;
72
+ account?: ResourceContainer;
73
+ project?: ResourceContainer;
74
+ };
75
+ createdDate?: string;
76
+ }
77
+
78
+ /** `git.pullrequest.created` */
79
+ export type PullRequestCreatedEvent = ServiceHookEvent<
80
+ "git.pullrequest.created",
81
+ AzureDevOpsPullRequest
82
+ >;
83
+
84
+ /** `ms.vss-code.git-pullrequest-comment-event` */
85
+ export type PullRequestCommentedEvent = ServiceHookEvent<
86
+ "ms.vss-code.git-pullrequest-comment-event",
87
+ { comment: AzureDevOpsComment; pullRequest: AzureDevOpsPullRequest }
88
+ >;
89
+
90
+ export type AzureDevOpsWebhookEvent = PullRequestCreatedEvent | PullRequestCommentedEvent;
@@ -0,0 +1,184 @@
1
+ /**
2
+ * API drain: what the API does between SIGTERM and closing its HTTP server.
3
+ *
4
+ * On a deploy the orchestrator stops the API and the workers together, and the
5
+ * workers' own SIGTERM handoff (`POST /api/tasks/:id/supersede`) lands after the
6
+ * API is gone, so every in-flight task falls through to the heartbeat sweep.
7
+ * Draining flips that order: the API keeps serving, dispatches no new work,
8
+ * marks every response with `X-Swarm-Draining: 1` (see `src/utils/api-drain.ts`),
9
+ * and waits, bounded, until the tasks it saw in flight have been handed off.
10
+ *
11
+ * The state is process-local. A new API process starts not draining.
12
+ */
13
+
14
+ import { API_DRAIN_MAX_MS_LIMIT } from "../utils/api-drain";
15
+ import { scrubSecrets } from "../utils/secret-scrubber";
16
+ import { getDbClient } from "./db";
17
+
18
+ /**
19
+ * Default cap on the wait for worker handoffs: `0`, the drain is off. It is
20
+ * opt-in because it makes every live worker supersede its in-flight tasks on
21
+ * any API SIGTERM, including an API-only restart where those tasks would
22
+ * otherwise keep running. A deploy that stops the API and the workers together
23
+ * sets `API_DRAIN_MAX_MS` (e.g. `30000`) to turn it on.
24
+ */
25
+ export const DEFAULT_API_DRAIN_MAX_MS = 0;
26
+ const DRAIN_CHECK_INTERVAL_MS = 500;
27
+ /**
28
+ * A worker pings every few seconds. One silent for longer than this is not
29
+ * expected to hand anything off; the heartbeat sweep owns its tasks.
30
+ */
31
+ const LIVE_WORKER_WINDOW_MS = 30_000;
32
+
33
+ let drainStartedAt: number | null = null;
34
+
35
+ export function isApiDraining(): boolean {
36
+ return drainStartedAt !== null;
37
+ }
38
+
39
+ /** Enter the draining state. Returns false when already draining. */
40
+ export function beginApiDrain(now: number = Date.now()): boolean {
41
+ if (drainStartedAt !== null) return false;
42
+ drainStartedAt = now;
43
+ return true;
44
+ }
45
+
46
+ /** Test seam: the state is module-level, so tests reset it between cases. */
47
+ export function resetApiDrainForTesting(): void {
48
+ drainStartedAt = null;
49
+ }
50
+
51
+ /**
52
+ * `API_DRAIN_MAX_MS`, capped at `API_DRAIN_MAX_MS_LIMIT`. Unset, empty, or
53
+ * invalid means `DEFAULT_API_DRAIN_MAX_MS` (`0`, the drain is off).
54
+ */
55
+ export function resolveApiDrainMaxMs(
56
+ env: Record<string, string | undefined> = process.env,
57
+ ): number {
58
+ const raw = env.API_DRAIN_MAX_MS;
59
+ if (raw === undefined || raw.trim() === "") return DEFAULT_API_DRAIN_MAX_MS;
60
+ const parsed = Number(raw);
61
+ if (!Number.isFinite(parsed) || parsed < 0) return DEFAULT_API_DRAIN_MAX_MS;
62
+ return Math.min(Math.floor(parsed), API_DRAIN_MAX_MS_LIMIT);
63
+ }
64
+
65
+ /** `in_progress` tasks held by an agent that pinged recently, i.e. one that can still hand off. */
66
+ export async function listLiveInFlightTaskIds(now: number = Date.now()): Promise<string[]> {
67
+ const cutoff = new Date(now - LIVE_WORKER_WINDOW_MS).toISOString();
68
+ const rows = await getDbClient().query<{ id: string }>(
69
+ `SELECT t.id AS id
70
+ FROM agent_tasks t
71
+ JOIN agents a ON a.id = t.agentId
72
+ WHERE t.status = 'in_progress' AND a.status != 'offline' AND a.lastUpdatedAt >= ?`,
73
+ [cutoff],
74
+ );
75
+ return rows.map((row) => row.id);
76
+ }
77
+
78
+ /** How many of `taskIds` are still `in_progress`. */
79
+ export async function countStillInProgress(taskIds: string[]): Promise<number> {
80
+ if (taskIds.length === 0) return 0;
81
+ const row = await getDbClient().get<{ n: number }>(
82
+ `SELECT count(*) AS n FROM agent_tasks
83
+ WHERE status = 'in_progress' AND id IN (SELECT value FROM json_each(?))`,
84
+ [JSON.stringify(taskIds)],
85
+ );
86
+ return row?.n ?? 0;
87
+ }
88
+
89
+ export interface ApiDrainDeps {
90
+ env?: Record<string, string | undefined>;
91
+ now?: () => number;
92
+ sleep?: (ms: number) => Promise<void>;
93
+ listInFlight?: () => Promise<string[]>;
94
+ countRemaining?: (taskIds: string[]) => Promise<number>;
95
+ log?: (message: string) => void;
96
+ }
97
+
98
+ export interface ApiDrainOutcome {
99
+ /** False when the cap is `0` (the default): the API did not enter the draining state. */
100
+ enabled: boolean;
101
+ /** Live in-flight tasks seen when the drain began. */
102
+ inFlight: number;
103
+ /** Of those, still `in_progress` when the wait ended. */
104
+ remaining: number;
105
+ waitedMs: number;
106
+ timedOut: boolean;
107
+ }
108
+
109
+ /**
110
+ * Enter the draining state, then wait until the live in-flight tasks are handed
111
+ * off or the cap passes. Never throws: a failed read ends the wait, because a
112
+ * shutdown that cannot finish is worse than one that skips the drain.
113
+ */
114
+ export async function drainApi(deps: ApiDrainDeps = {}): Promise<ApiDrainOutcome> {
115
+ const now = deps.now ?? Date.now;
116
+ const sleep = deps.sleep ?? ((ms: number) => Bun.sleep(ms));
117
+ const log = deps.log ?? ((message: string) => console.log(message));
118
+ const listInFlight = deps.listInFlight ?? (() => listLiveInFlightTaskIds(now()));
119
+ const countRemaining = deps.countRemaining ?? countStillInProgress;
120
+ const maxMs = resolveApiDrainMaxMs(deps.env);
121
+ const startedAt = now();
122
+
123
+ if (maxMs === 0) {
124
+ log("[drain] off (API_DRAIN_MAX_MS is 0 or unset): closing without waiting for handoffs");
125
+ return { enabled: false, inFlight: 0, remaining: 0, waitedMs: 0, timedOut: false };
126
+ }
127
+
128
+ beginApiDrain(startedAt);
129
+
130
+ let taskIds: string[];
131
+ try {
132
+ taskIds = await listInFlight();
133
+ } catch (err) {
134
+ log(`[drain] could not read in-flight tasks, closing without waiting: ${describe(err)}`);
135
+ return {
136
+ enabled: true,
137
+ inFlight: 0,
138
+ remaining: 0,
139
+ waitedMs: now() - startedAt,
140
+ timedOut: false,
141
+ };
142
+ }
143
+
144
+ if (taskIds.length === 0) {
145
+ log("[drain] draining: no in-flight tasks on live workers");
146
+ return {
147
+ enabled: true,
148
+ inFlight: 0,
149
+ remaining: 0,
150
+ waitedMs: now() - startedAt,
151
+ timedOut: false,
152
+ };
153
+ }
154
+
155
+ log(
156
+ `[drain] draining: waiting up to ${maxMs}ms for ${taskIds.length} in-flight task(s) to be handed off`,
157
+ );
158
+
159
+ const deadline = startedAt + maxMs;
160
+ let remaining = taskIds.length;
161
+ while (true) {
162
+ try {
163
+ remaining = await countRemaining(taskIds);
164
+ } catch (err) {
165
+ log(`[drain] could not re-read in-flight tasks, closing now: ${describe(err)}`);
166
+ break;
167
+ }
168
+ if (remaining === 0 || now() >= deadline) break;
169
+ await sleep(Math.min(DRAIN_CHECK_INTERVAL_MS, Math.max(0, deadline - now())));
170
+ }
171
+
172
+ const waitedMs = now() - startedAt;
173
+ const timedOut = remaining > 0;
174
+ log(
175
+ timedOut
176
+ ? `[drain] timed out after ${waitedMs}ms with ${remaining} of ${taskIds.length} task(s) still in_progress`
177
+ : `[drain] all ${taskIds.length} in-flight task(s) handed off after ${waitedMs}ms`,
178
+ );
179
+ return { enabled: true, inFlight: taskIds.length, remaining, waitedMs, timedOut };
180
+ }
181
+
182
+ function describe(err: unknown): string {
183
+ return scrubSecrets(err instanceof Error ? err.message : String(err));
184
+ }
@@ -288,7 +288,7 @@ export function rowToAgentTask(row: AgentTaskRow): AgentTask {
288
288
  slackReplySent: !!row.slackReplySent,
289
289
  slackProgressMessageTs: row.slackProgressMessageTs ?? undefined,
290
290
  slackTreeRootMessageTs: row.slackTreeRootMessageTs ?? undefined,
291
- vcsProvider: (row.vcsProvider as "github" | "gitlab" | null) ?? undefined,
291
+ vcsProvider: (row.vcsProvider as "github" | "gitlab" | "azure-devops" | null) ?? undefined,
292
292
  vcsRepo: row.vcsRepo ?? undefined,
293
293
  vcsEventType: row.vcsEventType ?? undefined,
294
294
  vcsNumber: row.vcsNumber ?? undefined,
@@ -1161,7 +1161,9 @@ export type ExistingTrackerContextWork = {
1161
1161
 
1162
1162
  const LINEAR_TRACKER_CONTEXT_KEY_PREFIX = "task:trackers:linear:";
1163
1163
 
1164
- function isLinearTrackerContextKey(contextKey: string | null | undefined): contextKey is string {
1164
+ export function isLinearTrackerContextKey(
1165
+ contextKey: string | null | undefined,
1166
+ ): contextKey is string {
1165
1167
  return !!contextKey && contextKey.startsWith(LINEAR_TRACKER_CONTEXT_KEY_PREFIX);
1166
1168
  }
1167
1169
 
@@ -1170,28 +1172,51 @@ function isLinearTrackerContextKey(contextKey: string | null | undefined): conte
1170
1172
  *
1171
1173
  * Active means any non-terminal task. A completed task with persisted VCS PR/MR
1172
1174
  * metadata is also treated as existing work because the task can be complete
1173
- * while the PR is still awaiting review/merge.
1175
+ * while the PR is still awaiting review/merge. Delegation excludes the tracker
1176
+ * root and all its descendants from both lookups.
1174
1177
  */
1175
1178
  export async function findExistingLinearTrackerContextWork(
1176
1179
  contextKey: string | null | undefined,
1180
+ delegatingParentTaskId?: string,
1177
1181
  ): Promise<ExistingTrackerContextWork | null> {
1178
1182
  if (!isLinearTrackerContextKey(contextKey)) return null;
1179
1183
 
1184
+ const lineageCte = `WITH RECURSIVE
1185
+ ancestors(id, parentTaskId) AS (
1186
+ SELECT id, parentTaskId FROM agent_tasks WHERE id = ? AND contextKey = ?
1187
+ UNION
1188
+ SELECT parent.id, parent.parentTaskId FROM agent_tasks parent
1189
+ JOIN ancestors child ON parent.id = child.parentTaskId
1190
+ WHERE parent.contextKey = ?
1191
+ ),
1192
+ lineage(id) AS (
1193
+ SELECT id FROM ancestors
1194
+ WHERE parentTaskId IS NULL OR parentTaskId NOT IN (SELECT id FROM ancestors)
1195
+ UNION
1196
+ SELECT child.id FROM agent_tasks child
1197
+ JOIN lineage parent ON child.parentTaskId = parent.id
1198
+ )`;
1199
+ const lineageParams = [delegatingParentTaskId ?? null, contextKey, contextKey];
1200
+
1180
1201
  const activeRow = await getDbClient().get<AgentTaskRow>(
1181
- `SELECT * FROM agent_tasks
1202
+ `${lineageCte}
1203
+ SELECT * FROM agent_tasks
1182
1204
  WHERE contextKey = ?
1205
+ AND id NOT IN (SELECT id FROM lineage)
1183
1206
  AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded')
1184
1207
  ORDER BY lastUpdatedAt DESC
1185
1208
  LIMIT 1`,
1186
- [contextKey],
1209
+ [...lineageParams, contextKey],
1187
1210
  );
1188
1211
  if (activeRow) {
1189
1212
  return { task: rowToAgentTask(activeRow), reason: "active_task" };
1190
1213
  }
1191
1214
 
1192
1215
  const linkedPrRow = await getDbClient().get<AgentTaskRow>(
1193
- `SELECT * FROM agent_tasks
1216
+ `${lineageCte}
1217
+ SELECT * FROM agent_tasks
1194
1218
  WHERE contextKey = ?
1219
+ AND id NOT IN (SELECT id FROM lineage)
1195
1220
  AND status = 'completed'
1196
1221
  AND vcsProvider IS NOT NULL
1197
1222
  AND vcsRepo IS NOT NULL
@@ -1199,7 +1224,7 @@ export async function findExistingLinearTrackerContextWork(
1199
1224
  AND vcsUrl IS NOT NULL
1200
1225
  ORDER BY lastUpdatedAt DESC
1201
1226
  LIMIT 1`,
1202
- [contextKey],
1227
+ [...lineageParams, contextKey],
1203
1228
  );
1204
1229
  if (linkedPrRow) {
1205
1230
  return { task: rowToAgentTask(linkedPrRow), reason: "linked_open_pr" };
@@ -1,6 +1,6 @@
1
1
  import pkg from "../../../../package.json";
2
2
  import { defaultAssetKey } from "../../../assets/key";
3
- import type { telemetry } from "../../../telemetry";
3
+ import type { TaskTelemetryEvent, TaskTelemetryInput } from "../../../telemetry-trigger";
4
4
  import type {
5
5
  Agent,
6
6
  AgentLog,
@@ -42,10 +42,11 @@ type TaskWriteDependencies = {
42
42
  agentId: string | null,
43
43
  sourceTexts: Array<string | null | undefined>,
44
44
  ) => Promise<TaskAttachment[]>;
45
- emitTaskLifecycleTelemetryAfterCommit: (
46
- event: string,
47
- props: Parameters<typeof telemetry.taskEvent>[1],
45
+ emitTaskLifecycleTelemetryAfterCommit: <S extends TaskTelemetryEvent>(
46
+ event: S,
47
+ props: TaskTelemetryInput<S>,
48
48
  verify?: (task: AgentTask | null) => boolean,
49
+ actorUserId?: string | null,
49
50
  ) => void;
50
51
  taskContextForTelemetry: (task: AgentTask) => {
51
52
  provider?: ProviderName;
@@ -317,6 +318,22 @@ export async function updateTaskClaudeSessionId(
317
318
  return row ? rowToAgentTask(row) : null;
318
319
  }
319
320
 
321
+ /**
322
+ * Records the harness that ran (or tried to run) a task when no session ever
323
+ * reported it. `provider` is otherwise written only by the session-init path,
324
+ * so a task whose harness failed to spawn kept `provider` NULL and looked like
325
+ * a task that never started. Never overwrites a provider already recorded.
326
+ */
327
+ export async function recordTaskProviderIfUnset(
328
+ taskId: string,
329
+ provider: ProviderName,
330
+ ): Promise<void> {
331
+ await getDbClient().run("UPDATE agent_tasks SET provider = ? WHERE id = ? AND provider IS NULL", [
332
+ provider,
333
+ taskId,
334
+ ]);
335
+ }
336
+
320
337
  /**
321
338
  * Sets or clears a task's display title (session rename). Trims the input and
322
339
  * normalizes an empty string to NULL (clear). Deliberately does NOT touch
@@ -68,6 +68,9 @@ export interface DbClient extends DbExecutor {
68
68
  * really did occupy the driver and block the event loop, up to
69
69
  * `attemptSpinMs` per BUSY attempt. It excludes all lock waiting and all
70
70
  * backoff sleeping.
71
+ *
72
+ * `changes` counts only the rows the statement itself changed. Unlike
73
+ * `run`, it excludes rows touched by foreign-key actions.
71
74
  */
72
75
  runTimed(sql: string, params?: DbParam[]): Promise<{ changes: number; executionMs: number }>;
73
76
  /**
@@ -278,8 +281,14 @@ class BunSqliteClient implements DbClient {
278
281
  const result = await this.execute(
279
282
  sql,
280
283
  (db) => {
281
- const run = db.query(sql).run(...params);
282
- return { changes: run.changes };
284
+ db.query(sql).run(...params);
285
+ // bun:sqlite's `run().changes` also counts rows touched by foreign-key
286
+ // actions (an ON DELETE SET NULL child update counts as a change), so
287
+ // a DELETE on a self-referencing table reports up to twice the rows it
288
+ // removed. SQLite's changes() counts only the statement's own rows.
289
+ // Same connection, still inside the lock: nothing can run in between.
290
+ const own = db.query("SELECT changes() AS n").get() as { n: number } | null;
291
+ return { changes: own?.n ?? 0 };
283
292
  },
284
293
  (ms) => {
285
294
  executionMs += ms;