@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,363 @@
1
+ import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from "bun:test";
2
+ import { unlink } from "node:fs/promises";
3
+ import { z } from "zod";
4
+ import * as db from "../be/db";
5
+ import {
6
+ cancelTask,
7
+ closeDb,
8
+ completeTask,
9
+ createWorkflow,
10
+ failTask,
11
+ getTaskById,
12
+ getTaskByWorkflowRunStepId,
13
+ getWorkflowRun,
14
+ getWorkflowRunStepsByRunId,
15
+ initDb,
16
+ } from "../be/db";
17
+ import type { AgentTask, WorkflowDefinition, WorkflowRunStep } from "../types";
18
+ import { startWorkflowExecution } from "../workflows/engine";
19
+ import { workflowEventBus } from "../workflows/event-bus";
20
+ import { AgentTaskExecutor } from "../workflows/executors/agent-task";
21
+ import {
22
+ BaseExecutor,
23
+ type ExecutorDependencies,
24
+ type ExecutorResult,
25
+ } from "../workflows/executors/base";
26
+ import { ExecutorRegistry } from "../workflows/executors/registry";
27
+ import { recoverIncompleteRuns } from "../workflows/recovery";
28
+ import { setupWorkflowResumeListener } from "../workflows/resume";
29
+ import { startRetryPoller, stopRetryPoller } from "../workflows/retry-poller";
30
+ import { interpolate } from "../workflows/template";
31
+
32
+ const TEST_DB_PATH = "./test-workflow-agent-task-retry.sqlite";
33
+
34
+ class NotifyStubExecutor extends BaseExecutor<
35
+ typeof NotifyStubExecutor.schema,
36
+ typeof NotifyStubExecutor.outSchema
37
+ > {
38
+ static readonly schema = z.object({ channel: z.string(), template: z.string() });
39
+ static readonly outSchema = z.object({ sent: z.boolean() });
40
+
41
+ readonly type = "notify";
42
+ readonly mode = "instant" as const;
43
+ readonly configSchema = NotifyStubExecutor.schema;
44
+ readonly outputSchema = NotifyStubExecutor.outSchema;
45
+
46
+ protected async execute(): Promise<ExecutorResult<z.infer<typeof NotifyStubExecutor.outSchema>>> {
47
+ return { status: "success", output: { sent: true } };
48
+ }
49
+ }
50
+
51
+ const deps: ExecutorDependencies = {
52
+ db: db as typeof import("../be/db"),
53
+ eventBus: workflowEventBus,
54
+ interpolate: (template, ctx) => interpolate(template, ctx).result,
55
+ };
56
+
57
+ let registry: ExecutorRegistry;
58
+ let teardownResumeListener: (() => void) | undefined;
59
+
60
+ beforeAll(() => {
61
+ initDb(TEST_DB_PATH);
62
+ registry = new ExecutorRegistry();
63
+ registry.register(new NotifyStubExecutor(deps));
64
+ registry.register(new AgentTaskExecutor(deps));
65
+ teardownResumeListener = setupWorkflowResumeListener(workflowEventBus, registry);
66
+ });
67
+
68
+ afterEach(() => {
69
+ stopRetryPoller();
70
+ });
71
+
72
+ afterAll(async () => {
73
+ // Detach from the process-wide singleton bus (see setupWorkflowResumeListener).
74
+ teardownResumeListener?.();
75
+ stopRetryPoller();
76
+ closeDb();
77
+ await unlink(TEST_DB_PATH).catch(() => {});
78
+ await unlink(`${TEST_DB_PATH}-wal`).catch(() => {});
79
+ await unlink(`${TEST_DB_PATH}-shm`).catch(() => {});
80
+ });
81
+
82
+ let counter = 0;
83
+
84
+ /** synthesize (agent-task) → done (notify); `retry` lands on the node itself. */
85
+ async function startRun(opts: {
86
+ retry?: WorkflowDefinition["nodes"][number]["retry"];
87
+ onNodeFailure?: "fail" | "continue";
88
+ }): Promise<string> {
89
+ counter++;
90
+ const workflow = await createWorkflow({
91
+ name: `agent-task-retry-${counter}-${Date.now()}`,
92
+ definition: {
93
+ ...(opts.onNodeFailure ? { onNodeFailure: opts.onNodeFailure } : {}),
94
+ nodes: [
95
+ {
96
+ id: "synthesize",
97
+ type: "agent-task",
98
+ config: { template: "Synthesize" },
99
+ ...(opts.retry ? { retry: opts.retry } : {}),
100
+ next: "done",
101
+ },
102
+ { id: "done", type: "notify", config: { channel: "swarm", template: "done" } },
103
+ ],
104
+ },
105
+ });
106
+ const runId = await startWorkflowExecution(workflow, {}, registry);
107
+ expect((await getWorkflowRun(runId))!.status).toBe("waiting");
108
+ return runId;
109
+ }
110
+
111
+ async function synthesizeStep(runId: string): Promise<WorkflowRunStep> {
112
+ const steps = await getWorkflowRunStepsByRunId(runId);
113
+ return steps.find((s) => s.nodeId === "synthesize")!;
114
+ }
115
+
116
+ async function waitFor<T>(
117
+ probe: () => Promise<T | null | undefined | false>,
118
+ label: string,
119
+ timeoutMs = 3000,
120
+ ): Promise<T> {
121
+ const deadline = Date.now() + timeoutMs;
122
+ while (Date.now() < deadline) {
123
+ const value = await probe();
124
+ if (value) return value;
125
+ await new Promise((r) => setTimeout(r, 10));
126
+ }
127
+ throw new Error(`Timed out waiting for ${label}`);
128
+ }
129
+
130
+ /** Wait until a task other than `previous` is bound to the step. */
131
+ async function waitForRedrive(stepId: string, previous: AgentTask): Promise<AgentTask> {
132
+ return waitFor(async () => {
133
+ const bound = await getTaskByWorkflowRunStepId(stepId);
134
+ return bound && bound.id !== previous.id ? bound : null;
135
+ }, "redriven task");
136
+ }
137
+
138
+ const RETRY_ONCE = { maxRetries: 1, strategy: "static" as const, baseDelayMs: 0, maxDelayMs: 0 };
139
+
140
+ describe("agent-task node.retry on task failure", () => {
141
+ test("a superseded task with retry {maxRetries:1} is redriven once and the run continues", async () => {
142
+ const runId = await startRun({ retry: RETRY_ONCE });
143
+ const step = await synthesizeStep(runId);
144
+ const first = (await getTaskByWorkflowRunStepId(step.id))!;
145
+
146
+ await failTask(first.id, "superseded_workflow_task");
147
+
148
+ // Queued for the poller: step failed with nextRetryAt, run not failed,
149
+ // failed task detached so the executor creates a fresh one.
150
+ const queued = await waitFor(async () => {
151
+ const s = await synthesizeStep(runId);
152
+ return s.status === "failed" && s.nextRetryAt != null ? s : null;
153
+ }, "step queued for retry");
154
+ expect(queued.retryCount).toBe(1);
155
+ expect(queued.error).toBe("superseded_workflow_task");
156
+ expect((await getWorkflowRun(runId))!.status).toBe("waiting");
157
+ expect((await getTaskById(first.id))!.workflowRunStepId).toBeFalsy();
158
+
159
+ startRetryPoller(registry, 10);
160
+ const second = await waitForRedrive(step.id, first);
161
+ expect(second.status).not.toBe("failed");
162
+ const waiting = await waitFor(async () => {
163
+ const s = await synthesizeStep(runId);
164
+ return s.status === "waiting" ? s : null;
165
+ }, "step waiting on redriven task");
166
+ expect(waiting.id).toBe(step.id);
167
+ stopRetryPoller();
168
+
169
+ await completeTask(second.id, "synthesis done");
170
+ const run = await waitFor(async () => {
171
+ const r = await getWorkflowRun(runId);
172
+ return r?.status === "completed" ? r : null;
173
+ }, "run completed");
174
+ expect(run.status).toBe("completed");
175
+ const steps = await getWorkflowRunStepsByRunId(runId);
176
+ expect(steps.filter((s) => s.nodeId === "synthesize")).toHaveLength(1);
177
+ expect(steps.find((s) => s.nodeId === "done")?.status).toBe("completed");
178
+ });
179
+
180
+ test("a second failure exhausts retries and falls through to onNodeFailure", async () => {
181
+ const runId = await startRun({ retry: RETRY_ONCE, onNodeFailure: "continue" });
182
+ const step = await synthesizeStep(runId);
183
+ const first = (await getTaskByWorkflowRunStepId(step.id))!;
184
+
185
+ await failTask(first.id, "superseded_workflow_task");
186
+ startRetryPoller(registry, 10);
187
+ const second = await waitForRedrive(step.id, first);
188
+ await waitFor(async () => {
189
+ const s = await synthesizeStep(runId);
190
+ return s.status === "waiting" ? s : null;
191
+ }, "step waiting on redriven task");
192
+ stopRetryPoller();
193
+
194
+ // A late duplicate event for the FIRST task must not consume the retry
195
+ // budget or touch the step now bound to the second task.
196
+ workflowEventBus.emit("task.failed", {
197
+ taskId: first.id,
198
+ failureReason: "duplicate",
199
+ workflowRunId: runId,
200
+ workflowRunStepId: step.id,
201
+ });
202
+ await new Promise((r) => setTimeout(r, 20));
203
+ expect((await synthesizeStep(runId)).status).toBe("waiting");
204
+
205
+ await failTask(second.id, "superseded_workflow_task");
206
+ const run = await waitFor(async () => {
207
+ const r = await getWorkflowRun(runId);
208
+ return r?.status === "completed" ? r : null;
209
+ }, "run completed via onNodeFailure:continue");
210
+ expect(run.status).toBe("completed");
211
+ const finalStep = await synthesizeStep(runId);
212
+ expect(finalStep.status).toBe("completed");
213
+ expect(finalStep.retryCount).toBe(1);
214
+ expect(finalStep.nextRetryAt).toBeFalsy();
215
+ expect(JSON.stringify(finalStep.output)).toContain("[FAILED:");
216
+ // No third task was ever created.
217
+ expect((await getTaskByWorkflowRunStepId(step.id))!.id).toBe(second.id);
218
+ });
219
+
220
+ test("a node without retry fails the run exactly as before", async () => {
221
+ const runId = await startRun({});
222
+ const step = await synthesizeStep(runId);
223
+ const first = (await getTaskByWorkflowRunStepId(step.id))!;
224
+
225
+ await failTask(first.id, "superseded_workflow_task");
226
+
227
+ const run = await waitFor(async () => {
228
+ const r = await getWorkflowRun(runId);
229
+ return r?.status === "failed" ? r : null;
230
+ }, "run failed");
231
+ expect(run.error).toContain("superseded_workflow_task");
232
+ const failedStep = await synthesizeStep(runId);
233
+ expect(failedStep.status).toBe("failed");
234
+ expect(failedStep.retryCount).toBe(0);
235
+ expect(failedStep.nextRetryAt).toBeFalsy();
236
+ expect((await getTaskByWorkflowRunStepId(step.id))!.id).toBe(first.id);
237
+ });
238
+
239
+ test("a cancelled task never retries, even with retry set", async () => {
240
+ const runId = await startRun({ retry: RETRY_ONCE });
241
+ const step = await synthesizeStep(runId);
242
+ const first = (await getTaskByWorkflowRunStepId(step.id))!;
243
+
244
+ await cancelTask(first.id, "operator cancel");
245
+
246
+ const run = await waitFor(async () => {
247
+ const r = await getWorkflowRun(runId);
248
+ return r?.status === "failed" ? r : null;
249
+ }, "run failed");
250
+ expect(run.error).toContain("cancelled");
251
+ const failedStep = await synthesizeStep(runId);
252
+ expect(failedStep.retryCount).toBe(0);
253
+ expect(failedStep.nextRetryAt).toBeFalsy();
254
+ expect((await getTaskByWorkflowRunStepId(step.id))!.id).toBe(first.id);
255
+ });
256
+
257
+ test("the recovery sweep applies the same retry when it sees the failed task first", async () => {
258
+ const runId = await startRun({ retry: RETRY_ONCE });
259
+ const step = await synthesizeStep(runId);
260
+ const first = (await getTaskByWorkflowRunStepId(step.id))!;
261
+
262
+ // Detach the live listener so only the heartbeat sweep sees the failure.
263
+ teardownResumeListener?.();
264
+ try {
265
+ await failTask(first.id, "superseded_workflow_task");
266
+ await new Promise((r) => setTimeout(r, 20));
267
+ await recoverIncompleteRuns(registry);
268
+ } finally {
269
+ teardownResumeListener = setupWorkflowResumeListener(workflowEventBus, registry);
270
+ }
271
+
272
+ const queued = await synthesizeStep(runId);
273
+ expect(queued.status).toBe("failed");
274
+ expect(queued.nextRetryAt).toBeTruthy();
275
+ expect(queued.retryCount).toBe(1);
276
+ expect((await getWorkflowRun(runId))!.status).toBe("waiting");
277
+
278
+ startRetryPoller(registry, 10);
279
+ const second = await waitForRedrive(step.id, first);
280
+ expect(second.id).not.toBe(first.id);
281
+ });
282
+ });
283
+
284
+ describe("recovery sweep holding a stale failed-task snapshot", () => {
285
+ /**
286
+ * Recovery snapshots task A as failed, then pauses. Meanwhile the live
287
+ * task.failed handler queues A's retry and the poller binds task B to the
288
+ * same step, back in `waiting`. When recovery resumes on its stale A row it
289
+ * must leave the step bound to B alone.
290
+ */
291
+ async function raceStaleRecovery(maxRetries: number) {
292
+ const runId = await startRun({ retry: { ...RETRY_ONCE, maxRetries } });
293
+ const step = await synthesizeStep(runId);
294
+ const first = (await getTaskByWorkflowRunStepId(step.id))!;
295
+
296
+ let releaseSnapshot!: () => void;
297
+ const snapshotHeld = new Promise<void>((r) => {
298
+ releaseSnapshot = r;
299
+ });
300
+ let snapshotTaken!: () => void;
301
+ const snapshotReady = new Promise<void>((r) => {
302
+ snapshotTaken = r;
303
+ });
304
+ const realGetStuck = db.getStuckWorkflowRuns;
305
+ const spy = spyOn(db, "getStuckWorkflowRuns").mockImplementation(async () => {
306
+ const rows = await realGetStuck();
307
+ snapshotTaken();
308
+ await snapshotHeld;
309
+ return rows;
310
+ });
311
+
312
+ let recovery: Promise<unknown> | undefined;
313
+ try {
314
+ // Fail A with the listener detached so the sweep's snapshot sees it.
315
+ teardownResumeListener?.();
316
+ try {
317
+ await failTask(first.id, "superseded_workflow_task");
318
+ recovery = recoverIncompleteRuns(registry);
319
+ await snapshotReady;
320
+ } finally {
321
+ teardownResumeListener = setupWorkflowResumeListener(workflowEventBus, registry);
322
+ }
323
+
324
+ // The live event for A arrives late: retry queued, B dispatched.
325
+ workflowEventBus.emit("task.failed", {
326
+ taskId: first.id,
327
+ failureReason: "superseded_workflow_task",
328
+ workflowRunId: runId,
329
+ workflowRunStepId: step.id,
330
+ });
331
+ startRetryPoller(registry, 10);
332
+ const second = await waitForRedrive(step.id, first);
333
+ await waitFor(async () => {
334
+ const s = await synthesizeStep(runId);
335
+ return s.status === "waiting" ? s : null;
336
+ }, "step waiting on redriven task");
337
+ stopRetryPoller();
338
+
339
+ releaseSnapshot();
340
+ await recovery;
341
+ recovery = undefined;
342
+
343
+ const after = await synthesizeStep(runId);
344
+ expect(after.status).toBe("waiting");
345
+ expect(after.retryCount).toBe(1);
346
+ expect(after.nextRetryAt).toBeFalsy();
347
+ expect((await getWorkflowRun(runId))!.status).toBe("waiting");
348
+ expect((await getTaskByWorkflowRunStepId(step.id))!.id).toBe(second.id);
349
+ } finally {
350
+ releaseSnapshot();
351
+ await recovery;
352
+ spy.mockRestore();
353
+ }
354
+ }
355
+
356
+ test("with retries left, the stale snapshot does not consume another retry", async () => {
357
+ await raceStaleRecovery(3);
358
+ });
359
+
360
+ test("with retries exhausted, the stale snapshot does not route onNodeFailure", async () => {
361
+ await raceStaleRecovery(1);
362
+ });
363
+ });
@@ -44,7 +44,7 @@ describe("workflow definition telemetry", () => {
44
44
  await removeTestDb();
45
45
  });
46
46
 
47
- test("emits workflow.created with definition size and known source", async () => {
47
+ test("emits workflow.created with definition size and known interface (via)", async () => {
48
48
  const workflow = await createWorkflow(
49
49
  {
50
50
  name: "created telemetry",
@@ -65,7 +65,7 @@ describe("workflow definition telemetry", () => {
65
65
  props: {
66
66
  workflowId: workflow.id,
67
67
  nodeCount: 2,
68
- source: "api",
68
+ via: "api",
69
69
  },
70
70
  },
71
71
  ]);
@@ -91,13 +91,13 @@ describe("workflow definition telemetry", () => {
91
91
  event: "deleted",
92
92
  props: {
93
93
  workflowId: workflow.id,
94
- source: "mcp",
94
+ via: "mcp",
95
95
  },
96
96
  },
97
97
  ]);
98
98
  });
99
99
 
100
- test("omits source for direct internal workflow mutations", async () => {
100
+ test("omits via for direct internal workflow mutations", async () => {
101
101
  const workflow = await createWorkflow({
102
102
  name: "internal telemetry",
103
103
  definition: { nodes: [] },
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, test } from "bun:test";
2
+ import { DEFAULT_MODEL } from "../utils/internal-ai/models";
2
3
  import { resolveWorkflowLlmConfig } from "../workflows/executors/workflow-llm";
3
4
 
4
5
  describe("resolveWorkflowLlmConfig", () => {
@@ -41,6 +42,19 @@ describe("resolveWorkflowLlmConfig", () => {
41
42
  }
42
43
  });
43
44
 
45
+ test("still follows DEFAULT_MODEL, which the pinned rater default no longer tracks", async () => {
46
+ const before = DEFAULT_MODEL.openrouter;
47
+ try {
48
+ DEFAULT_MODEL.openrouter = "openrouter/some/bumped-model";
49
+ const config = await resolveWorkflowLlmConfig(undefined, {
50
+ OPENROUTER_API_KEY: "sk-or-test",
51
+ });
52
+ expect(config.model).toBe("some/bumped-model");
53
+ } finally {
54
+ DEFAULT_MODEL.openrouter = before;
55
+ }
56
+ });
57
+
44
58
  test("preserves an explicit provider-compatible model", async () => {
45
59
  const config = await resolveWorkflowLlmConfig("openai/gpt-5.4", {
46
60
  OPENAI_API_KEY: "example-sk-openai-test",
@@ -64,6 +64,7 @@ export const registerContextDiffTool = (server: McpServer) => {
64
64
  fromVersion: z.number().optional(),
65
65
  toVersion: z.number().optional(),
66
66
  diff: z.string().optional(),
67
+ predecessorPruned: z.boolean().optional(),
67
68
  changeSource: z.string().optional(),
68
69
  createdAt: z.string().optional(),
69
70
  }),
@@ -119,6 +120,25 @@ export const registerContextDiffTool = (server: McpServer) => {
119
120
  compareVersion = await getContextVersion(version.previousVersionId);
120
121
  }
121
122
 
123
+ // Retention (CONTEXT_VERSIONS_KEEP_LATEST) deletes old versions, and the
124
+ // FK sets the survivor's previousVersionId to NULL. Diffing against ""
125
+ // here would present the whole file as newly written, so say what
126
+ // happened instead.
127
+ if (!compareToVersionId && !compareVersion && version.version > 1) {
128
+ const message = `No predecessor for ${version.field} v${version.version}: v${version.version - 1} was removed by context version retention. Pass compareToVersionId with a surviving version from context-history.`;
129
+ return toolOk(message, {
130
+ details: message,
131
+ data: {
132
+ yourAgentId: requestInfo.agentId,
133
+ field: version.field,
134
+ toVersion: version.version,
135
+ predecessorPruned: true,
136
+ changeSource: version.changeSource,
137
+ createdAt: version.createdAt,
138
+ },
139
+ });
140
+ }
141
+
122
142
  const oldContent = compareVersion?.content ?? "";
123
143
  const diff = await computeDiff(oldContent, version.content);
124
144
 
@@ -1,6 +1,7 @@
1
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import * as z from "zod";
3
3
  import { createToolRegistrar, toolOk } from "@/tools/utils";
4
+ import { checkExtensionInstallSource, ExtensionManifestSchema } from "@/types";
4
5
  import {
5
6
  coerceExtensionSummary,
6
7
  extensionToolOutputSchema,
@@ -8,7 +9,29 @@ import {
8
9
  } from "./extension-common";
9
10
 
10
11
  export const EXTENSION_INSTALL_DESCRIPTION =
11
- "Install a predefined extension by name. Only extensions in the catalog (extension-catalog, GET /api/extensions/catalog) can be installed; inline bundles are rejected. Install creates the extension, its ext:<name> agent and every asset it declares (scripts, and disabled schedules). Any authenticated agent may install; the installing agent is recorded as createdByAgentId. Workers may install subsequent versions only for their own extensions; those versions remain inactive. A new extension remains disabled until a lead, operator, or dashboard user enables it with extension-enable.";
12
+ "Install an extension from the catalog by `template` name (extension-catalog, GET /api/extensions/catalog), or from an inline bundle: `manifest` plus a `files` map keyed by bundle path. `template` and `manifest`/`files` are mutually exclusive. Inline bundles are accepted only when the deployment sets EXTENSION_ALLOW_INLINE_INSTALL=true, and only from lead, operator and dashboard-user callers. Workers are denied (403) and stay catalog-only; with the flag off the call fails with inline_install_disabled. Before writing an inline bundle, fetch the hook contract: GET /api/extensions/type-defs returns swarm-extension.d.ts. Install creates the extension, its ext:<name> agent and every asset it declares (scripts, and disabled schedules, workflows and skills). Any authenticated agent may install from the catalog; the installing agent is recorded as createdByAgentId. Workers may install subsequent versions only for their own extensions; those versions remain inactive. A new extension remains disabled until a lead, operator, or dashboard user enables it with extension-enable.";
13
+
14
+ const extensionInstallInputSchema = z
15
+ .object({
16
+ template: z
17
+ .string()
18
+ .min(1)
19
+ .optional()
20
+ .describe(
21
+ "Name of a predefined extension from extension-catalog. Mutually exclusive with manifest and files.",
22
+ ),
23
+ manifest: ExtensionManifestSchema.optional().describe(
24
+ "Inline bundle manifest. Requires files. Needs EXTENSION_ALLOW_INLINE_INSTALL and a lead, operator, or dashboard-user caller.",
25
+ ),
26
+ files: z
27
+ .record(z.string(), z.string())
28
+ .optional()
29
+ .describe("Inline bundle files keyed by relative path. Requires manifest."),
30
+ priority: z.number().int().optional().describe("Handler priority. Lower values run first."),
31
+ config: z.record(z.string(), z.unknown()).optional().describe("Extension configuration."),
32
+ })
33
+ .strict()
34
+ .superRefine(checkExtensionInstallSource);
12
35
 
13
36
  function extensionInstallResult(data: unknown, fallbackName: string) {
14
37
  const body = data as {
@@ -38,20 +61,7 @@ export const registerExtensionInstallTool = (server: McpServer) => {
38
61
  title: "Extension Install",
39
62
  description: EXTENSION_INSTALL_DESCRIPTION,
40
63
  annotations: { openWorldHint: false },
41
- inputSchema: z
42
- .object({
43
- template: z
44
- .string()
45
- .min(1)
46
- .describe("Name of a predefined extension from extension-catalog."),
47
- priority: z
48
- .number()
49
- .int()
50
- .optional()
51
- .describe("Handler priority. Lower values run first."),
52
- config: z.record(z.string(), z.unknown()).optional().describe("Extension configuration."),
53
- })
54
- .strict(),
64
+ inputSchema: extensionInstallInputSchema,
55
65
  outputSchema: extensionToolOutputSchema,
56
66
  },
57
67
  async (args, requestInfo) =>
@@ -60,7 +70,8 @@ export const registerExtensionInstallTool = (server: McpServer) => {
60
70
  path: "/api/extensions/install",
61
71
  body: args,
62
72
  requestInfo,
63
- success: (data) => extensionInstallResult(data, args.template),
73
+ success: (data) =>
74
+ extensionInstallResult(data, args.template ?? args.manifest?.name ?? "extension"),
64
75
  }),
65
76
  );
66
77
  };
@@ -2,6 +2,12 @@ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import * as z from "zod";
3
3
  import { getAgentById } from "@/be/db";
4
4
  import { getEmbeddingProvider, getMemoryStore } from "@/be/memory";
5
+ import { assertKeyWritable, MemoryKeyError } from "@/be/memory/key-guard";
6
+ import {
7
+ MEMORY_KEY_MAX_LENGTH,
8
+ MEMORY_KEY_PATTERN,
9
+ MEMORY_KEY_PATTERN_MESSAGE,
10
+ } from "@/be/memory/key-paths";
5
11
  import { refreshLinks } from "@/be/memory/link-resolver";
6
12
  import { can } from "@/rbac";
7
13
  import { createToolRegistrar, swarmToolOutputSchema, toolErr, toolOk } from "@/tools/utils";
@@ -38,7 +44,7 @@ export const registerMemoryEditTool = (server: McpServer) => {
38
44
  {
39
45
  title: "Edit a memory",
40
46
  description:
41
- "Edit a single memory in place while preserving its ID, usefulness posterior, and audit history. Two modes: 'replace' overwrites the entire content (requires `content`); 'exact' performs a surgical find-and-replace of `oldString` with `newString` within the existing content (fails if `oldString` is missing or ambiguous). Use 'replace' for full rewrites, 'exact' for targeted edits. Agents can edit their own memories; lead agents can edit any scope.",
47
+ "Edit a single memory in place while preserving its ID, usefulness posterior, and audit history. Two modes: 'replace' overwrites the entire content (requires `content`); 'exact' performs a surgical find-and-replace of `oldString` with `newString` within the existing content (fails if `oldString` is missing or ambiguous). Use 'replace' for full rewrites, 'exact' for targeted edits. Pass `newKey` alone to move the memory to another logical path (every chunk, same ID, posterior, access counts and author). A move into /longterm also clears the expiry. Agents can edit their own memories; lead agents can edit any scope.",
42
48
  annotations: { destructiveHint: true },
43
49
 
44
50
  inputSchema: z.object({
@@ -71,6 +77,14 @@ export const registerMemoryEditTool = (server: McpServer) => {
71
77
  ),
72
78
  intent: z.string().min(1).describe("Why you are editing this memory."),
73
79
  expectedVersion: z.number().int().min(1).optional(),
80
+ newKey: z
81
+ .string()
82
+ .max(MEMORY_KEY_MAX_LENGTH)
83
+ .regex(MEMORY_KEY_PATTERN, MEMORY_KEY_PATTERN_MESSAGE)
84
+ .optional()
85
+ .describe(
86
+ "Move the memory to this logical path, for example '/longterm/facts/swarm-runtime/slug'. Alone it is a pure move: omit content/oldString/newString. Fails when the key is already used in this scope by the same owner. Moving into /longterm marks the memory as curated on every chunk: it stops expiring and is protected from cleanup, and moving it out later does not bring the expiry back. A key under /longterm must start with /longterm/company-story, /longterm/entities/people, /longterm/entities/customers, /longterm/facts, /longterm/decisions, /longterm/workstreams or /longterm/timeline. Paths under /longterm/company-story, /longterm/entities and /longterm/timeline are lead-only.",
87
+ ),
74
88
  }),
75
89
  outputSchema: swarmToolOutputSchema({
76
90
  yourAgentId: z.string().optional(),
@@ -81,7 +95,18 @@ export const registerMemoryEditTool = (server: McpServer) => {
81
95
  }),
82
96
  },
83
97
  async (
84
- { memoryId, key, scope, mode, content, oldString, newString, intent, expectedVersion },
98
+ {
99
+ memoryId,
100
+ key,
101
+ scope,
102
+ mode,
103
+ content,
104
+ oldString,
105
+ newString,
106
+ intent,
107
+ expectedVersion,
108
+ newKey,
109
+ },
85
110
  requestInfo,
86
111
  _meta,
87
112
  ) => {
@@ -96,6 +121,18 @@ export const registerMemoryEditTool = (server: McpServer) => {
96
121
  }
97
122
 
98
123
  try {
124
+ if (newKey) {
125
+ const agent = await getAgentById(requestInfo.agentId);
126
+ assertKeyWritable(newKey, "key", {
127
+ principal: {
128
+ kind: "agent",
129
+ agentId: requestInfo.agentId,
130
+ isLead: agent?.isLead ?? false,
131
+ },
132
+ source: "mcp",
133
+ });
134
+ }
135
+
99
136
  const store = getMemoryStore();
100
137
  // Key+scope edits already constrain the owner in store.edit(). IDs do not.
101
138
  // Keep this boundary gate out of the internal indexer/store write path.
@@ -138,9 +175,13 @@ export const registerMemoryEditTool = (server: McpServer) => {
138
175
  intent,
139
176
  expectedVersion,
140
177
  changedByAgentId: requestInfo.agentId,
178
+ newKey,
141
179
  });
142
180
 
143
- if (result.changed) {
181
+ // A pure move leaves the content, so the embedding and links stay valid.
182
+ const contentEdited =
183
+ content !== undefined || oldString !== undefined || newString !== undefined;
184
+ if (result.changed && (newKey === undefined || contentEdited)) {
144
185
  const provider = getEmbeddingProvider();
145
186
  const embedding = await provider.embed(result.memory.content);
146
187
  if (embedding) await store.updateEmbedding(result.memory.id, embedding, provider.name);
@@ -174,6 +215,9 @@ export const registerMemoryEditTool = (server: McpServer) => {
174
215
  },
175
216
  );
176
217
  } catch (err) {
218
+ if (err instanceof MemoryKeyError) {
219
+ return toolErr(err.message, { data: { yourAgentId: requestInfo.agentId } });
220
+ }
177
221
  return toolErr(`Memory edit failed: ${(err as Error).message}`, {
178
222
  data: { yourAgentId: requestInfo.agentId },
179
223
  });
@@ -4,6 +4,7 @@ import { getAgentById } from "@/be/db";
4
4
  import { getEmbeddingProvider, getMemoryStore } from "@/be/memory";
5
5
  import { CANDIDATE_SET_MULTIPLIER } from "@/be/memory/constants";
6
6
  import { expandCandidatesWithGraph } from "@/be/memory/graph-expansion";
7
+ import { MEMORY_KEY_MAX_LENGTH } from "@/be/memory/key-paths";
7
8
  import {
8
9
  dedupeMemoryDocumentIds,
9
10
  recordMemoryAccesses,
@@ -96,10 +97,18 @@ export const registerMemorySearchTool = (server: McpServer) => {
96
97
  ),
97
98
  limit: z.number().int().min(1).max(50).default(10).describe("Max results to return."),
98
99
  source: AgentMemorySourceSchema.optional().describe("Filter by memory source type."),
100
+ keyPrefix: z
101
+ .string()
102
+ .min(1)
103
+ .max(MEMORY_KEY_MAX_LENGTH)
104
+ .optional()
105
+ .describe(
106
+ "Only return memories whose key starts with this text, for example '/longterm/facts/' or '/longterm/entities/people/'. Matched literally, case-sensitive. Include the trailing '/' to stay inside one folder.",
107
+ ),
99
108
  }),
100
109
  outputSchema: memorySearchOutputSchema,
101
110
  },
102
- async ({ query, intent, scope, limit, source }, requestInfo, _meta) => {
111
+ async ({ query, intent, scope, limit, source, keyPrefix }, requestInfo, _meta) => {
103
112
  if (!requestInfo.agentId) {
104
113
  return toolErr("Agent ID required. Are you registered in the swarm?");
105
114
  }
@@ -122,6 +131,7 @@ export const registerMemorySearchTool = (server: McpServer) => {
122
131
  source,
123
132
  isLead,
124
133
  queryText: query,
134
+ keyPrefix,
125
135
  },
126
136
  );
127
137
  // Default-on 1-hop memory_link neighbor expansion (disable with
@@ -129,6 +139,7 @@ export const registerMemorySearchTool = (server: McpServer) => {
129
139
  const expanded = await expandCandidatesWithGraph(candidates, requestInfo.agentId, {
130
140
  scope: scope as "agent" | "swarm" | "all",
131
141
  source,
142
+ keyPrefix,
132
143
  isLead,
133
144
  });
134
145
  if (expanded.length > 0) {
@@ -196,6 +207,7 @@ export const registerMemorySearchTool = (server: McpServer) => {
196
207
  limit,
197
208
  isLead,
198
209
  source,
210
+ keyPrefix,
199
211
  });
200
212
 
201
213
  const consumedIds = dedupeMemoryDocumentIds(recent);