@desplega.ai/agent-swarm 2.9.1 → 2.10.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 (315) hide show
  1. package/dist/acp-adapter-bht22g3k.js +16 -0
  2. package/dist/{acp-targets-ny75x1qy.js → acp-targets-arrwv4f0.js} +6 -6
  3. package/dist/{actions-b9qgrmeq.js → actions-y0d2n1c2.js} +49 -28
  4. package/dist/{agent-fs-provision-b5dhdsbd.js → agent-fs-provision-tpj7sktd.js} +4 -4
  5. package/dist/{amp-adapter-vtax2c9s.js → amp-adapter-vmmnmw8d.js} +1 -1
  6. package/dist/{anthropic-messages-r5xf5hqw.js → anthropic-messages-zdca3gv1.js} +13 -13
  7. package/dist/{app-g2z15hax.js → app-wb7w45dq.js} +3 -3
  8. package/dist/{approval-notifications-yt13wp8r.js → approval-notifications-7mqr6vbd.js} +5 -5
  9. package/dist/{assistant-2cgfxsgk.js → assistant-gf60454p.js} +19 -19
  10. package/dist/{boot-args-schema-3gwy0f60.js → boot-args-schema-qxmd59sr.js} +1 -1
  11. package/dist/{boot-reembed-mywmyp4s.js → boot-reembed-5tmeskj2.js} +1 -1
  12. package/dist/{boot-reembed-92g7s5zp.js → boot-reembed-wb44vc3s.js} +1 -1
  13. package/dist/boot-scrub-sweep-25bxhnw4.js +9 -0
  14. package/dist/{boot-seeds-ce7rvgq1.js → boot-seeds-nj9za0vk.js} +4 -4
  15. package/dist/{claude-adapter-3m4q7735.js → claude-adapter-d3krpdyb.js} +5 -5
  16. package/dist/{claude-managed-setup-c217draw.js → claude-managed-setup-7y4pwd81.js} +1 -1
  17. package/dist/{claude-sdk-session-7fbqm51z.js → claude-sdk-session-d138zy0e.js} +5 -5
  18. package/dist/{cli-tvc4jag9.js → cli-01k6wpr9.js} +3 -3
  19. package/dist/{cli-2xs8tsf7.js → cli-124ntmf0.js} +42 -36
  20. package/dist/{cli-jm0hvmz2.js → cli-2rnd5j3t.js} +1 -1
  21. package/dist/{cli-32djehja.js → cli-2spnz7ye.js} +8 -8
  22. package/dist/{cli-2dq9yv8p.js → cli-2v2zdm0a.js} +1 -1
  23. package/dist/{cli-fkef327x.js → cli-3caf7pmg.js} +2 -2
  24. package/dist/{cli-mw620q3n.js → cli-3et6fmfe.js} +1 -1
  25. package/dist/{cli-h9yqfzx9.js → cli-3f8zbtqa.js} +3 -3
  26. package/dist/{cli-mhapr559.js → cli-43evxwj4.js} +1 -1
  27. package/dist/{cli-pyjn0qhk.js → cli-539h29es.js} +138 -21
  28. package/dist/{cli-bnqncekd.js → cli-5qhfv9rw.js} +2 -2
  29. package/dist/{cli-p4kckx1z.js → cli-6037prsx.js} +6 -6
  30. package/dist/{cli-zr6qy15y.js → cli-6cwr32fe.js} +17 -17
  31. package/dist/{cli-1jykg0py.js → cli-7r162fxe.js} +22 -15
  32. package/dist/{cli-sn650d7x.js → cli-8st34zhr.js} +20 -10
  33. package/dist/{cli-rq5rpv6k.js → cli-91pkxres.js} +1 -1
  34. package/dist/{cli-m7zvgt57.js → cli-9fjr27ez.js} +10 -10
  35. package/dist/{cli-f8x9drqr.js → cli-aw83sr40.js} +19 -5
  36. package/dist/{cli-jkw6ptfw.js → cli-cc93xzes.js} +5 -5
  37. package/dist/{cli-gfy38pvt.js → cli-fcfbct2j.js} +5 -5
  38. package/dist/{cli-nafvvsp8.js → cli-fq2rr3jb.js} +5 -5
  39. package/dist/{boot-scrub-sweep-7dkdzqxx.js → cli-had1p04a.js} +8 -9
  40. package/dist/{cli-bg63qmsx.js → cli-j6te8keb.js} +4 -4
  41. package/dist/{cli-br0924pw.js → cli-jrbq4djp.js} +1 -1
  42. package/dist/{cli-kxx4k2jw.js → cli-k3q2va86.js} +2 -2
  43. package/dist/{cli-jaw5v1sy.js → cli-k5yewqgd.js} +3 -3
  44. package/dist/cli-kbtzfrxj.js +404 -0
  45. package/dist/{cli-td9tb872.js → cli-m9cvf7vs.js} +7 -7
  46. package/dist/{cli-f3jyzq4g.js → cli-md50mj0r.js} +2 -2
  47. package/dist/{cli-xag7btpe.js → cli-mk7c5ac4.js} +1 -1
  48. package/dist/cli-mys27d03.js +321 -0
  49. package/dist/{cli-nbt14he0.js → cli-nstkanmx.js} +5 -5
  50. package/dist/{cli-wn13hhdt.js → cli-nv4xsvmk.js} +4 -4
  51. package/dist/{cli-vyff45ve.js → cli-p0c3vtch.js} +2 -2
  52. package/dist/{cli-2czxfnvj.js → cli-p0n7b5rz.js} +662 -93
  53. package/dist/{cli-j7svy295.js → cli-q5srsxq2.js} +12 -12
  54. package/dist/{cli-vt89089n.js → cli-qrta34nb.js} +4 -4
  55. package/dist/{cli-ysvspf5e.js → cli-qx4f057j.js} +2 -2
  56. package/dist/{cli-zh0e5x7p.js → cli-s1khw52h.js} +11 -11
  57. package/dist/{cli-mkwkwq81.js → cli-s1zqk1aj.js} +18 -11
  58. package/dist/{cli-f9gz2vyj.js → cli-sb4426be.js} +7 -7
  59. package/dist/{cli-dgs10ttj.js → cli-th1dkc2v.js} +1 -1
  60. package/dist/{cli-3j873zxq.js → cli-tr27kwyg.js} +2 -2
  61. package/dist/{cli-6945ywhr.js → cli-tvgqesec.js} +6 -4
  62. package/dist/{cli-fjggej24.js → cli-v46zsvqk.js} +1 -1
  63. package/dist/{cli-67mwzr35.js → cli-v8z0yga9.js} +4 -4
  64. package/dist/{cli-pb2ay3sh.js → cli-vfqvrd82.js} +5 -5
  65. package/dist/{cli-fh97xn30.js → cli-vq2eg24x.js} +2 -2
  66. package/dist/{cli-v57d7fmm.js → cli-vsw91x06.js} +23 -22
  67. package/dist/{cli-2yjj3e31.js → cli-w1q68d8x.js} +9 -7
  68. package/dist/{cli-y2ewxhth.js → cli-wafmk3fn.js} +10 -10
  69. package/dist/{cli-ctx0b85j.js → cli-wwp1bd3n.js} +257 -101
  70. package/dist/{cli-bkjdknnp.js → cli-y4ccxtz5.js} +37 -5
  71. package/dist/{cli-w4n323t3.js → cli-y8p78ekx.js} +7 -7
  72. package/dist/{cli-8zh9nrew.js → cli-z0m452jr.js} +1 -1
  73. package/dist/{cli-mjw0yf82.js → cli-zeh2mhkg.js} +1 -1
  74. package/dist/{cli-jwampxxq.js → cli-zk7v5s89.js} +2 -2
  75. package/dist/cli.js +16 -16
  76. package/dist/{cloudflare-workers-ai-system-one-9y1zx3pt.js → cloudflare-workers-ai-system-one-4aysy6rh.js} +2 -2
  77. package/dist/{codex-adapter-n656pvb8.js → codex-adapter-exfdbj73.js} +4 -4
  78. package/dist/{codex-session-runner-p0fbv5y9.js → codex-session-runner-xhznc4g3.js} +4 -4
  79. package/dist/{commands-gwea8z5p.js → commands-d8g349v4.js} +3 -3
  80. package/dist/{controller-t67c3grh.js → controller-mwgdmb8y.js} +3 -3
  81. package/dist/{controllers-connect-ks155r0h.js → controllers-connect-5v7qx04j.js} +19 -19
  82. package/dist/core-sxy4epp2.js +38 -0
  83. package/dist/{cursor-adapter-ygwrtmkv.js → cursor-adapter-p2q5h35d.js} +1 -1
  84. package/dist/{db-rb2xqdb1.js → db-qpganbeb.js} +3 -3
  85. package/dist/{db-kpmx06s9.js → db-wcw0b2j8.js} +2 -2
  86. package/dist/{dispatcher-31sm0ej2.js → dispatcher-8d8s49yz.js} +17 -17
  87. package/dist/{dsh-adapter-qyxh0w31.js → dsh-adapter-me0twn13.js} +1 -1
  88. package/dist/{easter-egg-3d-00wjscn6.js → easter-egg-3d-wv7w5ty6.js} +1 -1
  89. package/dist/{embedding-space-qhw4g68n.js → embedding-space-e48xchqa.js} +6 -6
  90. package/dist/{embeddings-zdv9ke6x.js → embeddings-tgq2afbq.js} +1 -1
  91. package/dist/{execute-zna8wwr7.js → execute-8rhwrk7f.js} +1 -1
  92. package/dist/{external-channel-1ac6t56s.js → external-channel-8bt3j2pm.js} +2 -2
  93. package/dist/{fx-adapter-sk7n0fzc.js → fx-adapter-adtdb3jb.js} +8 -8
  94. package/dist/{grok-adapter-sjbcm5ew.js → grok-adapter-accnn9km.js} +8 -8
  95. package/dist/handlers-1x77561e.js +35 -0
  96. package/dist/{heartbeat-2f6z4kdx.js → heartbeat-x0056ra5.js} +20 -20
  97. package/dist/{hook-w1skzaqc.js → hook-a7vmn2st.js} +4 -4
  98. package/dist/{hook-8y0gvtp1.js → hook-mrd2ayxv.js} +5 -5
  99. package/dist/{http-wghxvpef.js → http-ym9c5svp.js} +676 -273
  100. package/dist/{index-s71ez27v.js → index-01ns1pkw.js} +1 -1
  101. package/dist/index-48qzcqzj.js +35 -0
  102. package/dist/{index-9zkchs9t.js → index-ny60jcat.js} +186 -14
  103. package/dist/{index-rv89fvzf.js → index-p46tvwtx.js} +21 -21
  104. package/dist/index-rkvaambe.js +36 -0
  105. package/dist/{index-8zn8nxn5.js → index-x6azjwm8.js} +1 -1
  106. package/dist/{index-25pvya7q.js → index-xj1mq27m.js} +17 -17
  107. package/dist/k8s-m56sw868.js +217 -0
  108. package/dist/{keepalive-sh02349h.js → keepalive-7yxg8z4c.js} +3 -3
  109. package/dist/lead-enzn86bz.js +74 -0
  110. package/dist/{maintenance-yj0dcjja.js → maintenance-6tefxmk1.js} +1 -1
  111. package/dist/{oauth-refresh-sweep-d9xedk66.js → oauth-refresh-sweep-70cavc3a.js} +2 -2
  112. package/dist/{onboard-dpgjn03r.js → onboard-fja65z08.js} +5 -5
  113. package/dist/{openai-decisions-q3hh60wr.js → openai-decisions-ytp6w6xh.js} +1 -1
  114. package/dist/{opencode-adapter-2d31cpjc.js → opencode-adapter-hakkm7yh.js} +5 -5
  115. package/dist/{otel-impl-1skarpfq.js → otel-impl-7zhnt6gj.js} +1 -1
  116. package/dist/{pending-bfmxtx0g.js → pending-h01yzpx4.js} +18 -18
  117. package/dist/{pi-mono-adapter-gvppnasy.js → pi-mono-adapter-f52hz743.js} +6 -6
  118. package/dist/{pricing-refresh-c6b325mk.js → pricing-refresh-fzxvk2zf.js} +2 -2
  119. package/dist/{rbac-roles-h80qbdbs.js → rbac-roles-9v6vhgbs.js} +3 -3
  120. package/dist/{rbac-roles-zfcx68tx.js → rbac-roles-hfgh8sba.js} +2 -2
  121. package/dist/{render-v2-nx20t3rb.js → render-v2-1rgspxzf.js} +3 -3
  122. package/dist/{resume-5ep8agan.js → resume-tqy61x24.js} +7 -7
  123. package/dist/{runtime-r3pj4mce.js → runtime-exkxyx5f.js} +1 -1
  124. package/dist/{session-access-n7p3m15b.js → session-access-3act7vt4.js} +4 -4
  125. package/dist/{session-source-backfill-v8mt0zwn.js → session-source-backfill-82qe7fqq.js} +2 -2
  126. package/dist/{setup-z1psaqhe.js → setup-ry1vfdef.js} +1 -1
  127. package/dist/thread-buffer-3x93yexa.js +38 -0
  128. package/dist/{typesafe-system-one-f2en2knd.js → typesafe-system-one-vcfj2ak8.js} +2 -2
  129. package/dist/user-merge-jobs-bx6bf7db.js +22 -0
  130. package/dist/{virtual-modules-rrbjdpxn.js → virtual-modules-s0rjzcqq.js} +3 -3
  131. package/dist/{work-objects-4aghh73z.js → work-objects-z2e5tv03.js} +20 -20
  132. package/dist/{worker-follow-up-166zmex1.js → worker-follow-up-y3xeg89w.js} +17 -17
  133. package/dist/worker-zfcv2wbf.js +74 -0
  134. package/openapi.json +1630 -388
  135. package/package.json +3 -3
  136. package/src/be/boot-seeds.ts +7 -1
  137. package/src/be/db/model-groups.ts +238 -0
  138. package/src/be/db/model-profiles.ts +26 -8
  139. package/src/be/db/session-costs.ts +8 -2
  140. package/src/be/db/tasks/read.ts +3 -2
  141. package/src/be/db/tasks/write.ts +2 -1
  142. package/src/be/db/user-references.ts +75 -0
  143. package/src/be/db/users/references.ts +185 -0
  144. package/src/be/db-client.ts +70 -19
  145. package/src/be/db.ts +32 -57
  146. package/src/be/key-window-usage.ts +1 -0
  147. package/src/be/memory/demotion-evidence.ts +34 -0
  148. package/src/be/memory/reranker.ts +34 -12
  149. package/src/be/memory/review-recall-filter.ts +83 -0
  150. package/src/be/memory/search-candidates.ts +19 -6
  151. package/src/be/memory/types.ts +11 -0
  152. package/src/be/migrations/312_task_ui_action_runs_repeatable.sql +6 -0
  153. package/src/be/migrations/314_model_groups.sql +85 -0
  154. package/src/be/migrations/318_superseded_workflow_cut_backfill.sql +22 -0
  155. package/src/be/migrations/319_user_fk_indexes.sql +153 -0
  156. package/src/be/migrations/320_session_costs_kind.sql +4 -0
  157. package/src/be/migrations/321_user_merge_jobs.sql +52 -0
  158. package/src/be/pricing-normalize.ts +2 -0
  159. package/src/be/rbac-roles.ts +6 -4
  160. package/src/be/runtime-pools/db.ts +20 -5
  161. package/src/be/runtime-pools/supervisor.ts +15 -1
  162. package/src/be/scripts/db.ts +11 -0
  163. package/src/be/scripts/typecheck.ts +2 -0
  164. package/src/be/seed-model-groups.ts +86 -0
  165. package/src/be/seed-model-profiles.ts +20 -13
  166. package/src/be/seed-scripts/catalog/dreaming-gather.ts +165 -1
  167. package/src/be/swarm-config-guard.ts +34 -0
  168. package/src/be/task-ui-spec.ts +102 -1
  169. package/src/be/user-merge-jobs.ts +564 -0
  170. package/src/be/users.ts +41 -23
  171. package/src/commands/onboard/agent-fs-version.ts +1 -1
  172. package/src/commands/onboard/compose-generator.ts +1 -1
  173. package/src/commands/onboard/env-generator.ts +1 -1
  174. package/src/commands/provider-credentials.ts +1 -1
  175. package/src/extensions/contract-types.generated.ts +1 -1
  176. package/src/extensions/contract.ts +15 -0
  177. package/src/extensions/dispatcher.ts +14 -4
  178. package/src/github/handlers.ts +57 -0
  179. package/src/github/types.ts +4 -0
  180. package/src/http/all-routes.ts +2 -0
  181. package/src/http/approval-requests.ts +5 -1
  182. package/src/http/auth.ts +3 -1
  183. package/src/http/config.ts +34 -1
  184. package/src/http/index.ts +13 -0
  185. package/src/http/memory.ts +19 -6
  186. package/src/http/model-groups.ts +277 -0
  187. package/src/http/model-profiles.ts +30 -13
  188. package/src/http/tasks.ts +41 -6
  189. package/src/http/tool-hooks.ts +140 -0
  190. package/src/http/users.ts +142 -19
  191. package/src/http/workflows.ts +19 -1
  192. package/src/integrations/chat-sdk/inbound.ts +8 -2
  193. package/src/integrations/chat-sdk/limits.ts +8 -3
  194. package/src/providers/acp-targets.ts +2 -2
  195. package/src/providers/amp-adapter.ts +1 -1
  196. package/src/providers/pricing-sources.md +9 -0
  197. package/src/rbac/legacy-policy.ts +1 -0
  198. package/src/rbac/permissions.ts +5 -0
  199. package/src/runtime-providers/index.ts +7 -5
  200. package/src/runtime-providers/k8s.ts +250 -0
  201. package/src/scripts-runtime/types/stdlib.d.ts +2 -0
  202. package/src/scripts-runtime/types/swarm-extension.d.ts +16 -1
  203. package/src/scripts-runtime/types/swarm-sdk.d.ts +2 -0
  204. package/src/slack/actions.ts +33 -10
  205. package/src/slack/blocks.ts +23 -2
  206. package/src/slack/render-v2.ts +47 -0
  207. package/src/tests/acp-adapter.test.ts +26 -0
  208. package/src/tests/chat-sdk-relay.test.ts +21 -1
  209. package/src/tests/check-pr-body.test.ts +43 -0
  210. package/src/tests/credential-check.test.ts +14 -6
  211. package/src/tests/db-client.test.ts +146 -0
  212. package/src/tests/deploy-guard.test.ts +7 -7
  213. package/src/tests/deploy-select.test.ts +83 -0
  214. package/src/tests/dreaming-gather-corrections.test.ts +467 -0
  215. package/src/tests/event-loop-lag.test.ts +9 -7
  216. package/src/tests/fixtures/extensions/native-tool-recorder/hooks.ts +26 -0
  217. package/src/tests/fixtures/extensions/native-tool-recorder/manifest.json +10 -0
  218. package/src/tests/fixtures/onboard/content.compose.yml.txt +1 -1
  219. package/src/tests/fixtures/onboard/content.env.txt +1 -1
  220. package/src/tests/fixtures/onboard/dev.compose.yml.txt +1 -1
  221. package/src/tests/fixtures/onboard/dev.env.txt +1 -1
  222. package/src/tests/fixtures/onboard/full-all.compose.yml.txt +1 -1
  223. package/src/tests/fixtures/onboard/full-all.env.txt +1 -1
  224. package/src/tests/fixtures/onboard/full.compose.yml.txt +1 -1
  225. package/src/tests/fixtures/onboard/full.env.txt +1 -1
  226. package/src/tests/fixtures/onboard/research.compose.yml.txt +1 -1
  227. package/src/tests/fixtures/onboard/research.env.txt +1 -1
  228. package/src/tests/fixtures/onboard/solo.compose.yml.txt +1 -1
  229. package/src/tests/fixtures/onboard/solo.env.txt +1 -1
  230. package/src/tests/github-event-filter.test.ts +8 -0
  231. package/src/tests/github-handlers-inline-comments.test.ts +2 -0
  232. package/src/tests/github-handlers-reactions.test.ts +4 -0
  233. package/src/tests/github-handlers.test.ts +3 -0
  234. package/src/tests/github-sender-trust.test.ts +223 -0
  235. package/src/tests/http-users.test.ts +142 -41
  236. package/src/tests/k8s-pool-smoke.test.ts +190 -0
  237. package/src/tests/key-window-usage.test.ts +15 -0
  238. package/src/tests/memory-rater-store.test.ts +35 -1
  239. package/src/tests/memory-reranker.test.ts +39 -4
  240. package/src/tests/memory-review-recall-filter.test.ts +205 -0
  241. package/src/tests/migration-318-superseded-workflow-cut-backfill.test.ts +74 -0
  242. package/src/tests/model-groups-api.test.ts +415 -0
  243. package/src/tests/model-profiles-api.test.ts +1 -0
  244. package/src/tests/operator-granted-credentials.test.ts +7 -2
  245. package/src/tests/operator-granted-role-wire.test.ts +2 -1
  246. package/src/tests/rbac-engine.test.ts +1 -0
  247. package/src/tests/runtime-k8s-pools.test.ts +142 -0
  248. package/src/tests/runtime-pools-db.test.ts +42 -2
  249. package/src/tests/runtime-pools-http.test.ts +47 -2
  250. package/src/tests/runtime-provider-registration.test.ts +5 -14
  251. package/src/tests/runtime-providers-k8s.test.ts +303 -0
  252. package/src/tests/script-connections.test.ts +13 -1
  253. package/src/tests/short-id.test.ts +23 -0
  254. package/src/tests/slack-blocks.test.ts +69 -0
  255. package/src/tests/slack-render-v2.test.ts +54 -0
  256. package/src/tests/spec-base-url.test.ts +13 -1
  257. package/src/tests/system-one-decide-session-cost.test.ts +196 -0
  258. package/src/tests/task-ui-action-route.test.ts +59 -1
  259. package/src/tests/task-ui-script-actions.test.ts +517 -0
  260. package/src/tests/tool-hooks-http.test.ts +187 -0
  261. package/src/tests/ui-spec-script-actions-config.test.ts +196 -0
  262. package/src/tests/user-delete-perf.test.ts +321 -0
  263. package/src/tests/user-merge-jobs.test.ts +680 -0
  264. package/src/tests/vcs-provider.test.ts +25 -5
  265. package/src/tests/vendored-openapi.test.ts +13 -1
  266. package/src/tests/workflow-agent-task-retry.test.ts +62 -0
  267. package/src/tests/workflow-foreach-supersede-retry.test.ts +10 -0
  268. package/src/tests/workflow-http-v2.test.ts +27 -0
  269. package/src/tests/workflow-replay.test.ts +10 -1
  270. package/src/tests/workflow-triggers-v2.test.ts +128 -0
  271. package/src/tests/workflow-wait-event.test.ts +109 -1
  272. package/src/tools/memory-search.ts +14 -3
  273. package/src/tools/store-progress.ts +26 -26
  274. package/src/tools/swarm-config/delete-config.ts +12 -1
  275. package/src/tools/swarm-config/set-config.ts +8 -0
  276. package/src/tools/system-one-decide.ts +113 -3
  277. package/src/tools/utils.ts +4 -1
  278. package/src/tools/workflows/create-workflow.ts +2 -0
  279. package/src/tools/workflows/update-workflow.ts +3 -1
  280. package/src/types.ts +86 -2
  281. package/src/ui-spec/actions.ts +30 -4
  282. package/src/ui-spec/schema.ts +38 -0
  283. package/src/ui-spec/script-actions.ts +340 -0
  284. package/src/ui-spec/script-allowlist.ts +48 -0
  285. package/src/utils/short-id.ts +20 -14
  286. package/src/utils/task-ui-spec.ts +16 -4
  287. package/src/vcs/index.ts +12 -2
  288. package/src/workflows/executors/system-one-decision.ts +2 -2
  289. package/src/workflows/resume.ts +3 -2
  290. package/src/workflows/task-step-routing.ts +30 -10
  291. package/src/workflows/triggers.ts +35 -3
  292. package/templates/extensions/manifest.schema.json +13 -0
  293. package/templates/skills/swarm-docs/content.md +2 -0
  294. package/templates/skills/ui-spec/content.md +7 -1
  295. package/templates/workflows/dreaming/content.md +1 -1
  296. package/dist/acp-adapter-g909b5hw.js +0 -16
  297. package/dist/cli-b91nz213.js +0 -93
  298. package/dist/handlers-yzy0c87x.js +0 -35
  299. package/dist/index-2t4859r5.js +0 -35
  300. package/dist/index-cxca2t8y.js +0 -36
  301. package/dist/lead-gk4h5eg7.js +0 -74
  302. package/dist/thread-buffer-a1re2r9r.js +0 -38
  303. package/dist/worker-3dyyb8ev.js +0 -74
  304. package/dist/{azure-openai-responses-590s1eea.js → azure-openai-responses-b3y7fz36.js} +8 -8
  305. package/dist/{cli-m7c2380k.js → cli-3aaeb78m.js} +4 -4
  306. package/dist/{cli-g0vv9dg4.js → cli-8y43jx2r.js} +8 -8
  307. package/dist/{cli-m0cy2vyf.js → cli-k6nejceb.js} +4 -4
  308. package/dist/{google-generative-ai-maq6c9bf.js → google-generative-ai-bh0djqjp.js} +4 -4
  309. package/dist/{google-vertex-2jgsw2nb.js → google-vertex-prjbw8dj.js} +8 -8
  310. package/dist/{mistral-conversations-0c30em7t.js → mistral-conversations-tm2vd4gc.js} +8 -8
  311. package/dist/{node-dqm4xgxw.js → node-2wfcey7d.js} +0 -0
  312. package/dist/{openai-codex-responses-bkcd8pjj.js → openai-codex-responses-sxjv60xx.js} +4 -4
  313. package/dist/{openai-completions-f3n69rep.js → openai-completions-0c7qnhsx.js} +20 -20
  314. package/dist/{openai-responses-gbh0wfqe.js → openai-responses-a7h29chp.js} +15 -15
  315. package/dist/{pi-messages-zebyt7gb.js → pi-messages-2j0fpqwq.js} +5 -5
@@ -0,0 +1,190 @@
1
+ import { expect, test } from "bun:test";
2
+ import { chmod, mkdir, rmdir } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { CHILD_PROCESS_TEST_BUDGET_MS, runChild } from "./test-proc";
5
+
6
+ const script = join(import.meta.dir, "../../scripts/k8s-pool-smoke.ts");
7
+
8
+ test(
9
+ "Kubernetes smoke help needs no credentials or cluster",
10
+ async () => {
11
+ const result = await runChild(["bun", script, "--help"], {
12
+ env: { ...process.env, AGENT_SWARM_API_KEY: "", API_KEY: "" },
13
+ });
14
+ expect(result.exitCode).toBe(0);
15
+ expect(result.stdout).toContain("--namespace");
16
+ },
17
+ CHILD_PROCESS_TEST_BUDGET_MS,
18
+ );
19
+
20
+ for (const mode of [
21
+ "success",
22
+ "pod-failure",
23
+ "api-failure",
24
+ "cleanup-failure",
25
+ "pod-and-cleanup-failure",
26
+ ] as const) {
27
+ test(
28
+ `Kubernetes smoke cleans only its test resources: ${mode}`,
29
+ async () => {
30
+ const dir = `/tmp/k8s-review-smoke-${crypto.randomUUID()}`;
31
+ await mkdir(dir, { mode: 0o700 });
32
+ const stateFile = join(dir, "state.json");
33
+ const kubectl = join(dir, "kubectl");
34
+ const ids = {
35
+ controller: crypto.randomUUID(),
36
+ pool: crypto.randomUUID(),
37
+ agent: crypto.randomUUID(),
38
+ runtime: crypto.randomUUID(),
39
+ };
40
+ const operatorKey = crypto.randomUUID();
41
+ const workerKey = `aseph_${crypto.randomUUID()}`;
42
+ const cleanupFails = mode.includes("cleanup-failure");
43
+ const podFails = mode === "pod-failure" || mode === "pod-and-cleanup-failure";
44
+ let disabled = false;
45
+ const deletes: string[] = [];
46
+ const pod = {
47
+ metadata: {
48
+ name: `swarm-rt-${ids.runtime}`,
49
+ uid: crypto.randomUUID(),
50
+ labels: { "swarm.agent-id": ids.agent, "swarm.pool-id": ids.pool },
51
+ },
52
+ spec: {
53
+ automountServiceAccountToken: false,
54
+ restartPolicy: "Never",
55
+ containers: [
56
+ {
57
+ name: "worker",
58
+ resources: { limits: { cpu: "1", memory: podFails ? "64Mi" : "2Gi" } },
59
+ env: [{ name: "AGENT_SWARM_API_KEY", value: workerKey }],
60
+ },
61
+ ],
62
+ },
63
+ };
64
+ await Bun.write(stateFile, JSON.stringify({ ids, pod, disabled }));
65
+ await Bun.write(
66
+ kubectl,
67
+ `#!/usr/bin/env bun
68
+ const state = await Bun.file(process.env.K8S_SMOKE_STATE_FILE).json();
69
+ const args = Bun.argv.slice(2);
70
+ if (args.includes('delete') || !args.includes('get')) process.exit(2);
71
+ const selector = args[args.indexOf('-l') + 1];
72
+ const owned = selector === 'swarm.runtime-id=' + state.ids.runtime || selector === 'swarm.pool-id=' + state.ids.pool;
73
+ console.log(JSON.stringify({items: owned && !state.disabled ? [state.pod] : []}));
74
+ `,
75
+ );
76
+ await chmod(kubectl, 0o700);
77
+ const server = Bun.serve({
78
+ hostname: "127.0.0.1",
79
+ port: 0,
80
+ async fetch(req) {
81
+ expect(req.headers.get("authorization")).toBe(`Bearer ${operatorKey}`);
82
+ const path = new URL(req.url).pathname;
83
+ if (path === "/status")
84
+ return Response.json({ runtime_pools: { enabled: true, supervisor: "running" } });
85
+ if (path === "/api/runtime-controllers" && req.method === "POST") {
86
+ const body = await req.json();
87
+ expect(body).toMatchObject({
88
+ kind: "k8s",
89
+ placement: "builtin",
90
+ config: { K8S_NAMESPACE: "workers", WORKER_API_URL: "http://api.example.test" },
91
+ });
92
+ expect(JSON.stringify(body)).not.toContain(operatorKey);
93
+ return Response.json({ controller: { id: ids.controller, secretConfigKeys: [] } });
94
+ }
95
+ if (path === "/api/runtime-pools" && req.method === "POST")
96
+ return Response.json({ pool: { id: ids.pool } });
97
+ if (path === `/api/runtime-pools/${ids.pool}/agents`)
98
+ return Response.json({ agent: { id: ids.agent } });
99
+ if (path === `/api/runtime-pools/${ids.pool}/runtimes`) {
100
+ if (disabled && cleanupFails)
101
+ return Response.json({ message: workerKey }, { status: 503 });
102
+ if (!disabled && mode === "api-failure")
103
+ return Response.json({ message: workerKey }, { status: 403 });
104
+ return Response.json({
105
+ runtimes: [
106
+ {
107
+ id: ids.runtime,
108
+ status: disabled ? "offline" : "active",
109
+ externalHandle: {
110
+ kind: "k8s",
111
+ controllerId: ids.controller,
112
+ externalId: pod.metadata.name,
113
+ meta: { "k8s.uid": pod.metadata.uid },
114
+ },
115
+ },
116
+ ],
117
+ });
118
+ }
119
+ if (path === `/api/runtime-pools/${ids.pool}` && req.method === "PATCH") {
120
+ expect(await req.json()).toEqual({ enabled: false });
121
+ disabled = true;
122
+ await Bun.write(stateFile, JSON.stringify({ ids, pod, disabled }));
123
+ if (cleanupFails) return Response.json({ message: workerKey }, { status: 500 });
124
+ return Response.json({});
125
+ }
126
+ if (req.method === "DELETE") {
127
+ deletes.push(path);
128
+ if (cleanupFails) return Response.json({ message: workerKey }, { status: 500 });
129
+ return Response.json({});
130
+ }
131
+ return Response.json({}, { status: 404 });
132
+ },
133
+ });
134
+ try {
135
+ const result = await runChild(
136
+ [
137
+ "bun",
138
+ script,
139
+ "--api",
140
+ server.url.origin,
141
+ "--worker-api",
142
+ "http://api.example.test",
143
+ "--namespace",
144
+ "workers",
145
+ "--context",
146
+ "test-context",
147
+ ],
148
+ {
149
+ env: {
150
+ ...process.env,
151
+ PATH: `${dir}:${process.env.PATH}`,
152
+ AGENT_SWARM_API_KEY: operatorKey,
153
+ K8S_SMOKE_STATE_FILE: stateFile,
154
+ },
155
+ },
156
+ );
157
+ expect(result.exitCode).toBe(mode === "success" ? 0 : 1);
158
+ expect(disabled).toBe(true);
159
+ expect(deletes).toEqual([
160
+ `/api/runtime-pools/${ids.pool}`,
161
+ `/api/runtime-controllers/${ids.controller}`,
162
+ ]);
163
+ if (cleanupFails) {
164
+ expect(result.stdout).not.toContain("PASS: drained pool");
165
+ expect(result.stderr).toContain(`PATCH /api/runtime-pools/${ids.pool} failed (500)`);
166
+ expect(result.stderr).toContain(
167
+ `GET /api/runtime-pools/${ids.pool}/runtimes failed (503)`,
168
+ );
169
+ expect(result.stderr).toContain(
170
+ `DELETE /api/runtime-pools/${ids.pool}?force=true failed (500)`,
171
+ );
172
+ expect(result.stderr).toContain(
173
+ `DELETE /api/runtime-controllers/${ids.controller} failed (500)`,
174
+ );
175
+ } else {
176
+ expect(result.stdout).toContain("deleted pods, pool, and controller");
177
+ }
178
+ if (podFails) expect(result.stderr).toContain("Worker resource limits differ.");
179
+ expect(result.stdout + result.stderr).not.toContain(operatorKey);
180
+ expect(result.stdout + result.stderr).not.toContain(workerKey);
181
+ } finally {
182
+ await server.stop(true);
183
+ await Bun.file(kubectl).delete();
184
+ await Bun.file(stateFile).delete();
185
+ await rmdir(dir);
186
+ }
187
+ },
188
+ CHILD_PROCESS_TEST_BUDGET_MS,
189
+ );
190
+ }
@@ -361,6 +361,21 @@ test("does not assign historical unknown credentials to one key or guess unknown
361
361
  });
362
362
  });
363
363
 
364
+ test("a SystemOne decision row is not an unattributed provider session", async () => {
365
+ await quota();
366
+ await cost();
367
+ // SystemOne rows never carry a credential; they bill no provider key window.
368
+ await cost({
369
+ kind: "system-one",
370
+ harness: null,
371
+ model: "cloudflare/clef",
372
+ credentialKeyType: null,
373
+ credentialKeySuffix: null,
374
+ });
375
+ const windows = (await read("?keyType=CODEX_OAUTH&keySuffix=key-a")).windows;
376
+ expect(windows[0]!.usage).toMatchObject({ sessions: 1, swarmUnattributedSessions: 0 });
377
+ });
378
+
364
379
  test("filters retain separate populations while callers share the same visible cache", async () => {
365
380
  await quota();
366
381
  await quota("key-b");
@@ -1,7 +1,8 @@
1
1
  import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
2
2
  import { unlink } from "node:fs/promises";
3
3
  import { closeDb, createAgent, getDbClient, initDb } from "../be/db";
4
- import { SqliteMemoryStore } from "../be/memory/providers/sqlite-store";
4
+ import { attachDemotionEvidence } from "../be/memory/demotion-evidence";
5
+ import { rowToCandidate, SqliteMemoryStore } from "../be/memory/providers/sqlite-store";
5
6
  import { applyRating, ExplicitSelfDuplicateError } from "../be/memory/raters/store";
6
7
  import type { RatingEvent } from "../be/memory/raters/types";
7
8
 
@@ -269,4 +270,37 @@ describe("applyRating", () => {
269
270
  expect(row!.weight).toBe(0.4);
270
271
  expect(row!.reasoning).toBe("because reasons");
271
272
  });
273
+
274
+ test("attachDemotionEvidence sums explicit-self and LLM mass for net-negative rows only", async () => {
275
+ const wrong = await makeMemory("wrong");
276
+ const liked = await makeMemory("liked");
277
+ await applyRating(
278
+ [
279
+ { memoryId: wrong.id, signal: -1, weight: 1, source: "explicit-self" },
280
+ { memoryId: wrong.id, signal: -0.5, weight: 0.8, source: "llm" },
281
+ { memoryId: wrong.id, signal: 0.5, weight: 0.8, source: "llm" },
282
+ { memoryId: wrong.id, signal: -1, weight: 0.25, source: "implicit-citation" },
283
+ { memoryId: liked.id, signal: 1, weight: 1, source: "llm" },
284
+ ],
285
+ { taskId },
286
+ );
287
+ const load = async (id: string) =>
288
+ rowToCandidate(
289
+ (await getDbClient().get<Parameters<typeof rowToCandidate>[0]>(
290
+ "SELECT * FROM agent_memory WHERE id = ?",
291
+ [id],
292
+ ))!,
293
+ 0.9,
294
+ );
295
+ const [w, l] = await attachDemotionEvidence([await load(wrong.id), await load(liked.id)]);
296
+ expect(w!.demotionEvidence).toEqual({
297
+ selfAlpha: 0,
298
+ selfBeta: 1,
299
+ llmAlpha: 0.4,
300
+ llmBeta: 0.4,
301
+ llmCount: 2,
302
+ });
303
+ // alpha > beta: never demotable, so never looked up.
304
+ expect(l!.demotionEvidence).toBeUndefined();
305
+ });
272
306
  });
@@ -339,10 +339,37 @@ describe("usefulness", () => {
339
339
  expect(usefulness(10, 1)).toBeCloseTo(1.8181818, 5);
340
340
  });
341
341
 
342
- test("Beta(1,10) → 1.0 (floored at default MEMORY_DEMOTION_FLOOR=1.0)", () => {
342
+ test("Beta(1,10) with no rating evidence → 1.0 (off-topic votes never demote)", () => {
343
343
  expect(usefulness(1, 10)).toBe(1.0);
344
344
  });
345
345
 
346
+ const noEvidence = { selfAlpha: 0, selfBeta: 0, llmAlpha: 0, llmBeta: 0, llmCount: 0 };
347
+
348
+ test("explicit-self net-negative demotes to the 0.5 default floor", () => {
349
+ expect(usefulness(1, 10, { ...noEvidence, selfBeta: 1 })).toBe(0.5);
350
+ // Above the floor the pooled score is kept: 2 * 3/5 = 1.2 is not demoted,
351
+ // 2 * 2/5 = 0.8 is.
352
+ expect(usefulness(2, 3, { ...noEvidence, selfBeta: 1 })).toBeCloseTo(0.8, 10);
353
+ });
354
+
355
+ test("explicit-self net-positive vetoes LLM-driven demotion", () => {
356
+ expect(usefulness(1, 10, { ...noEvidence, selfAlpha: 1, llmBeta: 20, llmCount: 30 })).toBe(1.0);
357
+ });
358
+
359
+ test("LLM-only negatives demote only with enough ratings and a mean below 0.25", () => {
360
+ const strong = { ...noEvidence, llmBeta: 8, llmAlpha: 0, llmCount: 10 };
361
+ expect(usefulness(1, 10, strong)).toBe(0.5);
362
+ // 9 ratings: not enough evidence.
363
+ expect(usefulness(1, 10, { ...strong, llmCount: 9 })).toBe(1.0);
364
+ // LLM mean (1+2)/(2+2+8) = 0.25: not clearly negative.
365
+ expect(usefulness(1, 10, { ...strong, llmAlpha: 2 })).toBe(1.0);
366
+ });
367
+
368
+ test("a positive pooled posterior is never demoted, whatever the evidence", () => {
369
+ expect(usefulness(10, 1, { ...noEvidence, selfBeta: 5 })).toBeCloseTo((2 * 10) / 11, 10);
370
+ expect(usefulness(1, 1, { ...noEvidence, selfBeta: 5 })).toBe(1.0);
371
+ });
372
+
346
373
  test("Beta(50,1) → 2 * 50/51 ≈ 1.961 (approaches ceiling, never above 2.0)", () => {
347
374
  expect(usefulness(50, 1)).toBeCloseTo((2 * 50) / 51, 10);
348
375
  expect(usefulness(50, 1)).toBeLessThan(2.0);
@@ -352,9 +379,17 @@ describe("usefulness", () => {
352
379
  expect(usefulness(10, 0)).toBe(2.0);
353
380
  });
354
381
 
355
- test("MEMORY_DEMOTION_FLOOR=0.5 lowers the floor and enables demotion", () => {
356
- process.env.MEMORY_DEMOTION_FLOOR = "0.5";
357
- expect(usefulness(1, 10)).toBe(0.5);
382
+ test("MEMORY_DEMOTION_FLOOR=1.0 restores no demotion", () => {
383
+ process.env.MEMORY_DEMOTION_FLOOR = "1.0";
384
+ expect(usefulness(1, 10, { ...noEvidence, selfBeta: 1 })).toBe(1.0);
385
+ expect(usefulness(10, 1)).toBeCloseTo((2 * 10) / 11, 10);
386
+ });
387
+
388
+ test("MEMORY_DEMOTION_FLOOR overrides the default floor", () => {
389
+ process.env.MEMORY_DEMOTION_FLOOR = "0.2";
390
+ expect(usefulness(1, 10, { ...noEvidence, selfBeta: 1 })).toBe(0.2);
391
+ process.env.MEMORY_DEMOTION_FLOOR = "not-a-number";
392
+ expect(usefulness(1, 10, { ...noEvidence, selfBeta: 1 })).toBe(0.5);
358
393
  });
359
394
  });
360
395
 
@@ -0,0 +1,205 @@
1
+ import { afterAll, beforeAll, describe, expect, mock, test } from "bun:test";
2
+ import { randomUUID } from "node:crypto";
3
+ import { unlink } from "node:fs/promises";
4
+ import type { IncomingMessage, ServerResponse } from "node:http";
5
+ import { Readable } from "node:stream";
6
+ import { closeDb, createAgent, getDbClient, initDb } from "../be/db";
7
+ import * as realMemoryModule from "../be/memory";
8
+ import type { MemoryCandidate, MemorySearchOptions, MemoryStore } from "../be/memory/types";
9
+ import type { AgentMemory } from "../types";
10
+
11
+ const realMemoryExports = {
12
+ getEmbeddingProvider: realMemoryModule.getEmbeddingProvider,
13
+ getMemoryStore: realMemoryModule.getMemoryStore,
14
+ };
15
+
16
+ const TEST_DB_PATH = "./test-memory-review-recall-filter.sqlite";
17
+ const agentId = randomUUID();
18
+
19
+ const id = {
20
+ reviewRecaller: randomUUID(), // taskType review
21
+ batchRecaller: randomUUID(), // pr-review-demo tag
22
+ plainRecaller: randomUUID(),
23
+ reviewSource: randomUUID(), // taskType review
24
+ rereviewSource: randomUUID(), // re-review tag
25
+ batchSource: randomUUID(), // pr-review-demo tag
26
+ plainSource: randomUUID(), // taskType bug
27
+ };
28
+
29
+ function memory(
30
+ name: string,
31
+ source: AgentMemory["source"],
32
+ sourceTaskId: string | null,
33
+ ): AgentMemory {
34
+ return {
35
+ id: randomUUID(),
36
+ agentId,
37
+ key: null,
38
+ name,
39
+ content: `${name} content`,
40
+ scope: "agent",
41
+ source,
42
+ summary: null,
43
+ sourcePath: null,
44
+ sourceTaskId,
45
+ chunkIndex: 0,
46
+ totalChunks: 1,
47
+ tags: [],
48
+ contextKey: null,
49
+ createdAt: "2026-11-01T00:00:00.000Z",
50
+ updatedAt: "2026-11-01T00:00:00.000Z",
51
+ accessedAt: "2026-11-01T00:00:00.000Z",
52
+ };
53
+ }
54
+
55
+ // Highest similarity first: three review-sourced completions crowd the top.
56
+ const reviewCompletions = [
57
+ memory("review-a", "task_completion", id.reviewSource),
58
+ memory("review-b", "task_completion", id.rereviewSource),
59
+ memory("review-c", "task_completion", id.batchSource),
60
+ ];
61
+ const plainCompletion = memory("plain-completion", "task_completion", id.plainSource);
62
+ const manualNote = memory("manual-note", "manual", null);
63
+ const orphanCompletion = memory("orphan-completion", "task_completion", randomUUID());
64
+ const ranked = [...reviewCompletions, plainCompletion, manualNote, orphanCompletion];
65
+
66
+ function asCandidate(m: AgentMemory, similarity: number): MemoryCandidate {
67
+ return {
68
+ ...m,
69
+ similarity,
70
+ rawSimilarity: similarity,
71
+ accessCount: 0,
72
+ expiresAt: null,
73
+ embeddingModel: "test",
74
+ alpha: 1,
75
+ beta: 1,
76
+ };
77
+ }
78
+
79
+ // Honors `limit` like the real store: the top-`limit` rows by similarity.
80
+ const fakeStore = {
81
+ search: async (_e: Float32Array, _a: string, options: MemorySearchOptions) =>
82
+ ranked.slice(0, options.limit ?? 10).map((m, i) => asCandidate(m, 0.95 - i * 0.01)),
83
+ list: async () => ranked,
84
+ } as unknown as MemoryStore;
85
+
86
+ mock.module("../be/memory", () => ({
87
+ getEmbeddingProvider: () => ({
88
+ name: "test",
89
+ dimensions: 3,
90
+ embed: async () => new Float32Array([1, 0, 0]),
91
+ embedBatch: async (texts: string[]) => texts.map(() => new Float32Array([1, 0, 0])),
92
+ }),
93
+ getMemoryStore: () => fakeStore,
94
+ }));
95
+
96
+ const { handleMemory } = await import("../http/memory");
97
+ const { searchMemoryCandidates } = await import("../be/memory/search-candidates");
98
+ const { dropReviewTaskCompletions, isReviewTaskId } = await import(
99
+ "../be/memory/review-recall-filter"
100
+ );
101
+
102
+ async function insertTask(taskId: string, taskType: string | null, tags: string[]): Promise<void> {
103
+ const now = new Date().toISOString();
104
+ await getDbClient().run(
105
+ `INSERT INTO agent_tasks (id, agentId, task, status, source, taskType, tags, createdAt, lastUpdatedAt)
106
+ VALUES (?, ?, 'task', 'completed', 'mcp', ?, ?, ?, ?)`,
107
+ [taskId, agentId, taskType, JSON.stringify(tags), now, now],
108
+ );
109
+ }
110
+
111
+ async function recall(recallerTaskId: string, limit = 5): Promise<string[]> {
112
+ const req = Readable.from([
113
+ Buffer.from(
114
+ JSON.stringify({ query: "prompt recall", intent: "pre-task memory recall", limit }),
115
+ ),
116
+ ]) as IncomingMessage;
117
+ req.method = "POST";
118
+ req.url = "/api/memory/search";
119
+ req.headers = { "x-memory-consumption": "prompt", "x-source-task-id": recallerTaskId };
120
+ let body: { results: { name: string }[] } = { results: [] };
121
+ const res = {
122
+ writeHead() {
123
+ return this;
124
+ },
125
+ end(chunk?: unknown) {
126
+ body = JSON.parse(chunk as string);
127
+ return this;
128
+ },
129
+ } as unknown as ServerResponse;
130
+ expect(await handleMemory(req, res, ["api", "memory", "search"], agentId)).toBe(true);
131
+ return body.results.map((r) => r.name);
132
+ }
133
+
134
+ beforeAll(async () => {
135
+ for (const suffix of ["", "-wal", "-shm"]) {
136
+ try {
137
+ await unlink(TEST_DB_PATH + suffix);
138
+ } catch {}
139
+ }
140
+ initDb(TEST_DB_PATH);
141
+ await createAgent({ id: agentId, name: "Review Recall Agent", isLead: false, status: "idle" });
142
+ await insertTask(id.reviewRecaller, "review", []);
143
+ await insertTask(id.batchRecaller, null, ["pr-review-demo"]);
144
+ await insertTask(id.plainRecaller, "bug", []);
145
+ await insertTask(id.reviewSource, "review", []);
146
+ await insertTask(id.rereviewSource, null, ["pr-fix-loop", "re-review"]);
147
+ await insertTask(id.batchSource, null, ["pr-review-demo"]);
148
+ await insertTask(id.plainSource, "bug", ["pr-fix-loop"]);
149
+ });
150
+
151
+ afterAll(async () => {
152
+ mock.module("../be/memory", () => realMemoryExports);
153
+ closeDb();
154
+ for (const suffix of ["", "-wal", "-shm"]) {
155
+ try {
156
+ await unlink(TEST_DB_PATH + suffix);
157
+ } catch {}
158
+ }
159
+ });
160
+
161
+ describe("review tasks do not recall review task_completion memories", () => {
162
+ test("recaller classification uses task fields", async () => {
163
+ expect(await isReviewTaskId(id.reviewRecaller)).toBe(true);
164
+ expect(await isReviewTaskId(id.batchRecaller)).toBe(true);
165
+ expect(await isReviewTaskId(id.plainRecaller)).toBe(false);
166
+ expect(await isReviewTaskId(randomUUID())).toBe(false);
167
+ expect(await isReviewTaskId(undefined)).toBe(false);
168
+ });
169
+
170
+ test("pre-task recall for a review task drops review-sourced completions, keeps the rest", async () => {
171
+ for (const recaller of [id.reviewRecaller, id.batchRecaller]) {
172
+ const names = await recall(recaller);
173
+ expect([...names].sort()).toEqual(["manual-note", "orphan-completion", "plain-completion"]);
174
+ }
175
+ });
176
+
177
+ test("dropped rows free their slots for the next-ranked memories", async () => {
178
+ // limit 1 -> 3 candidate rows, all review-sourced: the filter must widen the fetch.
179
+ const names = await recall(id.reviewRecaller, 1);
180
+ expect(names).toHaveLength(1);
181
+ expect(["manual-note", "orphan-completion", "plain-completion"]).toContain(names[0]);
182
+ });
183
+
184
+ test("a non-review task still recalls review-sourced completions", async () => {
185
+ const names = await recall(id.plainRecaller);
186
+ expect(names).toEqual(expect.arrayContaining(["review-a", "review-b", "review-c"]));
187
+ });
188
+
189
+ test("searchMemoryCandidates only filters when asked", async () => {
190
+ const embedding = new Float32Array([1, 0, 0]);
191
+ const off = await searchMemoryCandidates(fakeStore, embedding, agentId, { limit: 3 });
192
+ expect(off.map((c) => c.name)).toEqual(["review-a", "review-b", "review-c"]);
193
+ const on = await searchMemoryCandidates(fakeStore, embedding, agentId, {
194
+ limit: 3,
195
+ excludeReviewTaskCompletions: true,
196
+ });
197
+ expect(on.map((c) => c.name)).toEqual(["plain-completion", "manual-note", "orphan-completion"]);
198
+ });
199
+
200
+ test("dropReviewTaskCompletions leaves non-task_completion sources alone", async () => {
201
+ const reviewManual = memory("manual-with-review-task", "manual", id.reviewSource);
202
+ const kept = await dropReviewTaskCompletions([reviewManual, ...reviewCompletions]);
203
+ expect(kept.map((m) => m.name)).toEqual(["manual-with-review-task"]);
204
+ });
205
+ });
@@ -0,0 +1,74 @@
1
+ import { Database } from "bun:sqlite";
2
+ import { expect, test } from "bun:test";
3
+
4
+ const MIGRATION = "src/be/migrations/318_superseded_workflow_cut_backfill.sql";
5
+ const CUT = "superseded_workflow_task";
6
+
7
+ test("migration 318 moves cuts the workflow carried on without to superseded, once", async () => {
8
+ const db = new Database(":memory:");
9
+ try {
10
+ db.exec(`
11
+ CREATE TABLE workflow_run_steps (id TEXT PRIMARY KEY, status TEXT NOT NULL);
12
+ CREATE TABLE agent_tasks (
13
+ id TEXT PRIMARY KEY,
14
+ status TEXT NOT NULL,
15
+ failureReason TEXT,
16
+ workflowRunId TEXT,
17
+ workflowRunStepId TEXT,
18
+ lastUpdatedAt TEXT
19
+ );
20
+ INSERT INTO workflow_run_steps VALUES
21
+ ('s-completed', 'completed'), ('s-failed', 'failed'), ('s-waiting', 'waiting');
22
+ `);
23
+ const insert = db.prepare(
24
+ "INSERT INTO agent_tasks VALUES (?, ?, ?, ?, ?, '2026-01-01T00:00:00.000Z')",
25
+ );
26
+ const rows: [string, string, string | null, string | null, string | null][] = [
27
+ ["retried", "failed", CUT, "run", null],
28
+ ["absorbed", "failed", CUT, "run", "s-completed"],
29
+ ["step-failed", "failed", CUT, "run", "s-failed"],
30
+ ["step-waiting", "failed", CUT, "run", "s-waiting"],
31
+ ["run-deleted", "failed", CUT, null, null],
32
+ ["real-failure", "failed", "agent crashed", "run", "s-completed"],
33
+ ["already", "superseded", CUT, "run", null],
34
+ ];
35
+ for (const row of rows) insert.run(...row);
36
+
37
+ const sql = await Bun.file(MIGRATION).text();
38
+ db.exec(sql);
39
+
40
+ const status = () =>
41
+ Object.fromEntries(
42
+ db
43
+ .query<{ id: string; status: string }, []>("SELECT id, status FROM agent_tasks")
44
+ .all()
45
+ .map((r) => [r.id, r.status]),
46
+ );
47
+ expect(status()).toEqual({
48
+ retried: "superseded",
49
+ absorbed: "superseded",
50
+ "step-failed": "failed",
51
+ "step-waiting": "failed",
52
+ "run-deleted": "failed",
53
+ "real-failure": "failed",
54
+ already: "superseded",
55
+ });
56
+ const kept = db
57
+ .query<{ failureReason: string }, []>(
58
+ "SELECT failureReason FROM agent_tasks WHERE id IN ('retried', 'absorbed')",
59
+ )
60
+ .all();
61
+ expect(kept.every((r) => r.failureReason === CUT)).toBe(true);
62
+ const untouched = db
63
+ .query<{ lastUpdatedAt: string }, []>(
64
+ "SELECT lastUpdatedAt FROM agent_tasks WHERE id = 'already'",
65
+ )
66
+ .get();
67
+ expect(untouched?.lastUpdatedAt).toBe("2026-01-01T00:00:00.000Z");
68
+
69
+ // Idempotent: a second run matches nothing.
70
+ expect(db.run(sql).changes).toBe(0);
71
+ } finally {
72
+ db.close();
73
+ }
74
+ });