@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,103 @@
1
+ import type { AgentMemorySource } from "@/types";
2
+
3
+ /**
4
+ * Logical memory paths. A memory's `key` column may hold a path such as
5
+ * `/longterm/entities/people/taras` instead of the auto key
6
+ * `<scope>/manual/<id>`. The curated tree lives under `/longterm`; a memory
7
+ * with any other key (auto keys, file-index paths under `/workspace/...`) is
8
+ * inbox material. Paths start with `/` and a root segment, so they never
9
+ * collide with file-index keys or auto keys.
10
+ *
11
+ * The key is the tier, `source` stays provenance: a memory under `/longterm`
12
+ * gets the lifecycle of a `manual` memory whatever its `source` (see
13
+ * `tierSource`).
14
+ */
15
+
16
+ export const LONGTERM_ROOT = "/longterm";
17
+
18
+ /** Shape of a key written through `memory-store` or `memory-edit` `newKey`. */
19
+ export const MEMORY_KEY_PATTERN = /^\/[a-z0-9-]+(\/[a-z0-9._-]+)*$/;
20
+
21
+ export const MEMORY_KEY_PATTERN_MESSAGE =
22
+ "Key must be a path like /longterm/facts/swarm-runtime/slug: start with '/', a lowercase root segment, then segments of lowercase letters, digits, '.', '_' or '-', no trailing '/'.";
23
+
24
+ export const MEMORY_KEY_MAX_LENGTH = 200;
25
+
26
+ /** The only second segments a `/longterm` key may have. A closed list: an unknown root would store but never rank. */
27
+ export const LONGTERM_ROOTS = [
28
+ "company-story",
29
+ "entities",
30
+ "facts",
31
+ "decisions",
32
+ "workstreams",
33
+ "timeline",
34
+ ] as const;
35
+
36
+ /** The only third segments under `/longterm/entities`. Agent profiles and `get-repos` own agents and repos. */
37
+ export const LONGTERM_ENTITY_TYPES = ["people", "customers"] as const;
38
+
39
+ /** Roots only the lead may write: lane-maintained, consolidated paths. */
40
+ const CONSOLIDATED_KEY_ROOTS: readonly string[] = [
41
+ `${LONGTERM_ROOT}/company-story`,
42
+ `${LONGTERM_ROOT}/entities`,
43
+ `${LONGTERM_ROOT}/timeline`,
44
+ ];
45
+
46
+ /** True when `key` is `root` itself or sits beneath it (`/longterm/entities-x` is not under `/longterm/entities`). */
47
+ export function isKeyUnderRoot(key: string, root: string): boolean {
48
+ return key === root || key.startsWith(`${root}/`);
49
+ }
50
+
51
+ /** True when `key` is `/longterm` or sits beneath it: the curated tier. */
52
+ export function isLongtermKey(key: string | null | undefined): boolean {
53
+ return !!key && isKeyUnderRoot(key, LONGTERM_ROOT);
54
+ }
55
+
56
+ /**
57
+ * Why a `/longterm` key is refused, or null when it is allowed (or sits outside
58
+ * `/longterm`, where keys stay free-form). Only the first segments are checked;
59
+ * leaf slugs are the caller's, within MEMORY_KEY_PATTERN.
60
+ */
61
+ export function longtermKeyError(key: string): string | null {
62
+ if (!isLongtermKey(key)) return null;
63
+ const [root, entityType] = key.split("/").slice(2);
64
+ if (!LONGTERM_ROOTS.some((allowed) => allowed === root)) {
65
+ return `Key "${key}" is not allowed: the segment after ${LONGTERM_ROOT} must be one of ${LONGTERM_ROOTS.join(", ")}, as in ${LONGTERM_ROOT}/facts/<topic>/<slug>.`;
66
+ }
67
+ if (root === "entities" && !LONGTERM_ENTITY_TYPES.some((allowed) => allowed === entityType)) {
68
+ return `Key "${key}" is not allowed: the segment after ${LONGTERM_ROOT}/entities must be one of ${LONGTERM_ENTITY_TYPES.join(", ")}, as in ${LONGTERM_ROOT}/entities/people/<slug>.`;
69
+ }
70
+ return null;
71
+ }
72
+
73
+ /**
74
+ * The source whose lifecycle a memory follows: a memory under `/longterm` is
75
+ * `manual` (no TTL, no recency decay, quality 1.5, protected from cleanup),
76
+ * any other keeps its own. Provenance stays on `source`; the key is the tier.
77
+ */
78
+ export function tierSource(
79
+ source: AgentMemorySource,
80
+ key: string | null | undefined,
81
+ ): AgentMemorySource {
82
+ return isLongtermKey(key) ? "manual" : source;
83
+ }
84
+
85
+ /** True when `key` is under a root that needs the `memory.write.consolidated` permission. */
86
+ export function isConsolidatedKey(key: string): boolean {
87
+ return CONSOLIDATED_KEY_ROOTS.some((root) => isKeyUnderRoot(key, root));
88
+ }
89
+
90
+ /** Refusal text for a write to a lead-only path. The allow/deny decision is `can()`'s. */
91
+ export function consolidatedKeyMessage(key: string): string {
92
+ return `Key "${key}" is under a lead-only path (${CONSOLIDATED_KEY_ROOTS.join(", ")}). Write under ${LONGTERM_ROOT}/facts or leave the key off; the lead consolidates the rest.`;
93
+ }
94
+
95
+ /**
96
+ * The key a `memory-store` call writes: an explicit `key`, else the `name`
97
+ * when it is itself a `/longterm/` path, so an agent sets one field. Null when
98
+ * neither applies and the memory gets its auto key.
99
+ */
100
+ export function resolveStoreKey(key: string | undefined, name: string | undefined): string | null {
101
+ if (key) return key;
102
+ return name?.startsWith(`${LONGTERM_ROOT}/`) ? name : null;
103
+ }
@@ -6,6 +6,7 @@
6
6
  * Phase 1: capture layer only — no traversal tools, no reranker integration.
7
7
  */
8
8
  import { getDbClient } from "@/be/db";
9
+ import { getConfiguredAppUrls } from "@/utils/constants";
9
10
 
10
11
  export type LinkType =
11
12
  | "wikilink"
@@ -41,8 +42,8 @@ const WIKILINK_RE = /\[\[([^\]]+)\]\]/g;
41
42
  const PR_HASH_RE = /(?:^|[\s(])#(\d{1,5})(?=[\s,.)!?]|$)/gm;
42
43
  const PR_PREFIX_RE = /\bPR\s*#(\d{1,5})\b/gi;
43
44
  const GITHUB_PR_URL_RE = /https?:\/\/github\.com\/([\w.-]+)\/([\w.-]+)\/pull\/(\d+)/g;
44
- const AGENT_FS_PATH_RE =
45
- /(?:agent-fs|live\.agent-fs\.dev)\/file\/~\/([a-f0-9-]+)\/([a-f0-9-]+)\/([\w/.%-]+)/g;
45
+ const AGENT_FS_LIVE_HOSTS = String.raw`agent-fs|live\.agent-fs\.dev`;
46
+ const AGENT_FS_FILE_ROUTE = String.raw`\/file\/~\/([a-f0-9-]+)\/([a-f0-9-]+)\/([\w/.%-]+)`;
46
47
  const AGENT_UI_PAGE_RE = /(?:app\.[^/]+|localhost:\d+)\/pages\/([a-f0-9-]+)/g;
47
48
  const AGENT_UI_TASK_RE = /(?:app\.[^/]+|localhost:\d+)\/tasks\/([a-f0-9-]+)/g;
48
49
 
@@ -111,9 +112,34 @@ const prMatcher: Matcher = (content) => {
111
112
  return results;
112
113
  };
113
114
 
115
+ function escapeRegExp(value: string): string {
116
+ return value.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
117
+ }
118
+
119
+ /**
120
+ * agent-fs file links: the live UI, and the dashboard (Comb) at a configured
121
+ * `APP_URL` / `DASHBOARD_URL` or `localhost:<port>`. Both use the same
122
+ * `/file/~/<org>/<drive>/<path>` route and path encoding, so they resolve to
123
+ * the same target. Built per call: a config reload can change the app URLs.
124
+ * A host must start the host name (`evil-swarm.example.com` does not match
125
+ * `swarm.example.com`). Hosts are case-insensitive.
126
+ */
127
+ function agentFsPathRegex(): RegExp {
128
+ const appHosts = getConfiguredAppUrls().flatMap((value) => {
129
+ try {
130
+ const url = new URL(value);
131
+ return [escapeRegExp(`${url.host}${url.pathname.replace(/\/+$/, "")}`)];
132
+ } catch {
133
+ return [];
134
+ }
135
+ });
136
+ const hosts = [AGENT_FS_LIVE_HOSTS, ...appHosts, String.raw`localhost:\d+`].join("|");
137
+ return new RegExp(`(?<![\\w.-])(?:${hosts})${AGENT_FS_FILE_ROUTE}`, "gi");
138
+ }
139
+
114
140
  const agentFsMatcher: Matcher = (content) => {
115
141
  const results: MatcherResult[] = [];
116
- for (const match of content.matchAll(AGENT_FS_PATH_RE)) {
142
+ for (const match of content.matchAll(agentFsPathRegex())) {
117
143
  const orgId = match[1]!;
118
144
  const driveId = match[2]!;
119
145
  const path = match[3]!;
@@ -9,6 +9,7 @@ import {
9
9
  PROTECTED_SOURCES,
10
10
  TTL_DEFAULTS,
11
11
  } from "../constants";
12
+ import { isLongtermKey, LONGTERM_ROOT, tierSource } from "../key-paths";
12
13
  import { recencyDecay } from "../reranker";
13
14
  import type {
14
15
  MemoryCandidate,
@@ -173,8 +174,8 @@ export function applyEditMode(
173
174
  );
174
175
  }
175
176
 
176
- function computeExpiresAt(source: AgentMemorySource): string | null {
177
- const ttlDays = TTL_DEFAULTS[source];
177
+ function computeExpiresAt(source: AgentMemorySource, key: string | null): string | null {
178
+ const ttlDays = TTL_DEFAULTS[tierSource(source, key)];
178
179
  if (ttlDays == null) return null;
179
180
  return new Date(Date.now() + ttlDays * 86400000).toISOString();
180
181
  }
@@ -434,8 +435,8 @@ export class SqliteMemoryStore implements MemoryStore {
434
435
  async store(input: MemoryInput): Promise<AgentMemory> {
435
436
  const id = crypto.randomUUID();
436
437
  const now = new Date().toISOString();
437
- const expiresAt = computeExpiresAt(input.source);
438
438
  const key = input.key ?? `${input.scope}/${input.source}/${id}`;
439
+ const expiresAt = computeExpiresAt(input.source, key);
439
440
  const contentHash = contentSha256(input.content);
440
441
  const version = 1;
441
442
 
@@ -531,7 +532,14 @@ export class SqliteMemoryStore implements MemoryStore {
531
532
  agentId: string,
532
533
  options: MemorySearchOptions = {},
533
534
  ): Promise<MemoryCandidate[]> {
534
- const { scope = "all", limit = 10, source, isLead = false, includeExpired = false } = options;
535
+ const {
536
+ scope = "all",
537
+ limit = 10,
538
+ source,
539
+ isLead = false,
540
+ includeExpired = false,
541
+ keyPrefix,
542
+ } = options;
535
543
 
536
544
  const health = this.getHealth();
537
545
  if (
@@ -551,6 +559,7 @@ export class SqliteMemoryStore implements MemoryStore {
551
559
  source,
552
560
  isLead,
553
561
  includeExpired,
562
+ keyPrefix,
554
563
  });
555
564
  }
556
565
 
@@ -564,6 +573,7 @@ export class SqliteMemoryStore implements MemoryStore {
564
573
  source,
565
574
  isLead,
566
575
  includeExpired,
576
+ keyPrefix,
567
577
  });
568
578
  }
569
579
 
@@ -577,6 +587,7 @@ export class SqliteMemoryStore implements MemoryStore {
577
587
  source,
578
588
  isLead,
579
589
  includeExpired,
590
+ keyPrefix,
580
591
  });
581
592
  }
582
593
 
@@ -589,6 +600,7 @@ export class SqliteMemoryStore implements MemoryStore {
589
600
  source,
590
601
  isLead,
591
602
  includeExpired,
603
+ keyPrefix,
592
604
  });
593
605
  }
594
606
 
@@ -602,6 +614,7 @@ export class SqliteMemoryStore implements MemoryStore {
602
614
  source?: AgentMemorySource;
603
615
  isLead: boolean;
604
616
  includeExpired: boolean;
617
+ keyPrefix?: string;
605
618
  },
606
619
  ): Promise<MemoryCandidate[]> {
607
620
  const overfetchLimit = Math.min(Math.max(options.limit * 4, options.limit), 100);
@@ -682,16 +695,18 @@ export class SqliteMemoryStore implements MemoryStore {
682
695
  source?: AgentMemorySource;
683
696
  isLead: boolean;
684
697
  includeExpired: boolean;
698
+ keyPrefix?: string;
685
699
  },
686
700
  ): Promise<MemoryCandidate[]> {
687
701
  const match = this.buildFtsMatch(queryText);
688
702
  if (!match) return [];
689
703
 
690
- const { scope, limit, source, isLead, includeExpired } = options;
704
+ const { scope, limit, source, isLead, includeExpired, keyPrefix } = options;
691
705
  const conditions: string[] = ["memory_fts MATCH ?"];
692
706
  const params: (Buffer | string | number | null)[] = [match];
693
707
 
694
708
  this.addScopeConditions(conditions, params, agentId, scope, isLead, "m");
709
+ this.addKeyPrefixCondition(conditions, params, keyPrefix, "m");
695
710
 
696
711
  if (source) {
697
712
  conditions.push("m.source = ?");
@@ -721,7 +736,8 @@ export class SqliteMemoryStore implements MemoryStore {
721
736
  return {
722
737
  ...rowToCandidate(
723
738
  row,
724
- rawSimilarity * recencyDecay(row.createdAt, now, row.source as AgentMemorySource),
739
+ rawSimilarity *
740
+ recencyDecay(row.createdAt, now, row.source as AgentMemorySource, row.key),
725
741
  ),
726
742
  rawSimilarity,
727
743
  retrievalSource: "fts" as const,
@@ -756,9 +772,10 @@ export class SqliteMemoryStore implements MemoryStore {
756
772
  source?: AgentMemorySource;
757
773
  isLead: boolean;
758
774
  includeExpired: boolean;
775
+ keyPrefix?: string;
759
776
  },
760
777
  ): Promise<MemoryCandidate[]> {
761
- const { scope, limit, source, isLead, includeExpired } = options;
778
+ const { scope, limit, source, isLead, includeExpired, keyPrefix } = options;
762
779
 
763
780
  const embeddingBuffer = serializeEmbedding(queryEmbedding);
764
781
  // sqlite-vec hard ceiling is 4096 for knn queries
@@ -768,6 +785,7 @@ export class SqliteMemoryStore implements MemoryStore {
768
785
  const params: (Buffer | string | number | null)[] = [embeddingBuffer];
769
786
 
770
787
  this.addScopeConditions(conditions, params, agentId, scope, isLead, "m");
788
+ this.addKeyPrefixCondition(conditions, params, keyPrefix, "m");
771
789
 
772
790
  if (source) {
773
791
  conditions.push("m.source = ?");
@@ -810,14 +828,16 @@ export class SqliteMemoryStore implements MemoryStore {
810
828
  source?: AgentMemorySource;
811
829
  isLead: boolean;
812
830
  includeExpired: boolean;
831
+ keyPrefix?: string;
813
832
  },
814
833
  ): Promise<MemoryCandidate[]> {
815
- const { scope, limit, source, isLead, includeExpired } = options;
834
+ const { scope, limit, source, isLead, includeExpired, keyPrefix } = options;
816
835
 
817
836
  const conditions: string[] = ["embedding IS NOT NULL"];
818
837
  const params: (string | null)[] = [];
819
838
 
820
839
  this.addScopeConditions(conditions, params, agentId, scope, isLead);
840
+ this.addKeyPrefixCondition(conditions, params, keyPrefix);
821
841
 
822
842
  if (source) {
823
843
  conditions.push("source = ?");
@@ -877,15 +897,32 @@ export class SqliteMemoryStore implements MemoryStore {
877
897
  }
878
898
  }
879
899
 
900
+ /**
901
+ * Literal prefix match on `key`. substr/length instead of GLOB or LIKE so a
902
+ * prefix holding `*`, `?`, `[` or `%` is matched as text, not as a pattern.
903
+ */
904
+ private addKeyPrefixCondition(
905
+ conditions: string[],
906
+ params: (Buffer | string | number | null)[],
907
+ keyPrefix: string | undefined,
908
+ tableAlias = "",
909
+ ): void {
910
+ if (!keyPrefix) return;
911
+ const key = tableAlias ? `${tableAlias}.key` : "key";
912
+ conditions.push(`substr(${key}, 1, length(?)) = ?`);
913
+ params.push(keyPrefix, keyPrefix);
914
+ }
915
+
880
916
  private buildListWhereClause(
881
917
  agentId: string,
882
918
  options: MemoryListOptions,
883
919
  ): { whereClause: string; params: (Buffer | string | number | null)[] } {
884
- const { scope = "all", isLead = false, ownerAgentId, source, sourcePath } = options;
920
+ const { scope = "all", isLead = false, ownerAgentId, source, sourcePath, keyPrefix } = options;
885
921
  const conditions: string[] = [];
886
922
  const params: (Buffer | string | number | null)[] = [];
887
923
 
888
924
  this.addScopeConditions(conditions, params, agentId, scope, isLead);
925
+ this.addKeyPrefixCondition(conditions, params, keyPrefix);
889
926
 
890
927
  if (ownerAgentId) {
891
928
  conditions.push("agentId = ?");
@@ -932,8 +969,8 @@ export class SqliteMemoryStore implements MemoryStore {
932
969
  return row?.count ?? 0;
933
970
  }
934
971
 
935
- isSourceProtected(source: AgentMemorySource): boolean {
936
- return PROTECTED_SOURCES.has(source);
972
+ isSourceProtected(source: AgentMemorySource, key?: string | null): boolean {
973
+ return PROTECTED_SOURCES.has(tierSource(source, key));
937
974
  }
938
975
 
939
976
  async edit(input: MemoryEditInput): Promise<MemoryEditResult> {
@@ -957,21 +994,32 @@ export class SqliteMemoryStore implements MemoryStore {
957
994
  );
958
995
 
959
996
  if (!row) throw new Error("memory not found");
960
- if ((row.totalChunks ?? 1) !== 1)
997
+ // A pure move (newKey, no content fields) may span every chunk; any
998
+ // content edit still needs a single-chunk row.
999
+ const moveOnly =
1000
+ input.newKey !== undefined &&
1001
+ input.content === undefined &&
1002
+ input.oldString === undefined &&
1003
+ input.newString === undefined;
1004
+ if (!moveOnly && (row.totalChunks ?? 1) !== 1)
961
1005
  throw new Error("memory edit only supports single-chunk rows");
962
1006
  if (input.expectedVersion && input.expectedVersion !== (row.version ?? 1)) {
963
1007
  throw new Error("memory version conflict");
964
1008
  }
965
1009
 
966
1010
  const previousVersion = row.version ?? 1;
967
- const nextContent = applyEditMode(input.mode, row.content, {
968
- content: input.content,
969
- oldString: input.oldString,
970
- newString: input.newString,
971
- });
1011
+ const moving = input.newKey !== undefined && input.newKey !== row.key;
1012
+ const nextContent = moveOnly
1013
+ ? row.content
1014
+ : applyEditMode(input.mode, row.content, {
1015
+ content: input.content,
1016
+ oldString: input.oldString,
1017
+ newString: input.newString,
1018
+ });
972
1019
 
973
1020
  const nextHash = contentSha256(nextContent);
974
- if (nextHash === row.contentHash) {
1021
+ const contentChanged = !moveOnly && nextHash !== row.contentHash;
1022
+ if (!contentChanged && !moving) {
975
1023
  return {
976
1024
  result: {
977
1025
  memory: rowToAgentMemory(row),
@@ -984,31 +1032,86 @@ export class SqliteMemoryStore implements MemoryStore {
984
1032
  };
985
1033
  }
986
1034
 
987
- const nextVersion = previousVersion + 1;
1035
+ // Every chunk of the document shares one key, so the move covers all of
1036
+ // them. Legacy multi-chunk manual docs carry a distinct key per chunk and
1037
+ // cannot be located by key: refuse rather than split the document.
1038
+ let targets: AgentMemoryRow[] = [row];
1039
+ if (moving) {
1040
+ const owner = row.agentId ?? null;
1041
+ if (row.key) {
1042
+ targets = await tx.query<AgentMemoryRow>(
1043
+ `SELECT * FROM agent_memory
1044
+ WHERE key = ? AND scope = ? AND coalesce(agentId, '') = coalesce(?, '')
1045
+ ORDER BY chunkIndex ASC`,
1046
+ [row.key, row.scope, owner],
1047
+ );
1048
+ }
1049
+ if (
1050
+ targets.length !== (row.totalChunks ?? 1) ||
1051
+ targets.some((target, index) => target.chunkIndex !== index)
1052
+ ) {
1053
+ throw new Error(
1054
+ "memory move needs every chunk of the document under one key; this document's chunks do not share one, re-store it with a key",
1055
+ );
1056
+ }
1057
+ const taken = await tx.get<{ id: string }>(
1058
+ `SELECT id FROM agent_memory
1059
+ WHERE key = ? AND scope = ? AND coalesce(agentId, '') = coalesce(?, '')
1060
+ LIMIT 1`,
1061
+ [input.newKey!, row.scope, owner],
1062
+ );
1063
+ if (taken) throw new Error(`key "${input.newKey}" is already used in this scope`);
1064
+ }
1065
+
1066
+ // Moving into /longterm makes the memory curated, so it stops expiring.
1067
+ // Moving out restores nothing: the TTL it had is gone.
1068
+ const clearExpiry = moving && isLongtermKey(input.newKey);
988
1069
  const now = new Date().toISOString();
989
- await tx.run(
990
- `INSERT INTO agent_memory_version (id, memory_id, version, content, contentHash, intent, operation, changedByAgentId, createdAt, updatedAt, created_by, updated_by)
991
- VALUES (?, ?, ?, ?, ?, ?, 'edit', ?, ?, ?, ?, ?)`,
992
- [
993
- crypto.randomUUID(),
994
- row.id,
995
- nextVersion,
996
- nextContent,
997
- nextHash,
998
- input.intent,
999
- input.changedByAgentId ?? null,
1000
- now,
1001
- now,
1002
- input.changedByAgentId ?? null,
1003
- input.changedByAgentId ?? null,
1004
- ],
1005
- );
1006
- await tx.run(
1007
- `UPDATE agent_memory
1008
- SET content = ?, contentHash = ?, version = ?, updatedAt = ?
1009
- WHERE id = ?`,
1010
- [nextContent, nextHash, nextVersion, now, row.id],
1011
- );
1070
+ const versionIntent = moving
1071
+ ? `${input.intent} [key ${row.key ?? "(none)"} -> ${input.newKey}]`
1072
+ : input.intent;
1073
+ let nextVersion = previousVersion + 1;
1074
+ for (const target of targets) {
1075
+ const addressed = target.id === row.id;
1076
+ const targetContent = addressed ? nextContent : target.content;
1077
+ const targetHash = addressed
1078
+ ? nextHash
1079
+ : (target.contentHash ?? contentSha256(target.content));
1080
+ const targetVersion = (target.version ?? 1) + 1;
1081
+ if (addressed) nextVersion = targetVersion;
1082
+ await tx.run(
1083
+ `INSERT INTO agent_memory_version (id, memory_id, version, content, contentHash, intent, operation, changedByAgentId, createdAt, updatedAt, created_by, updated_by)
1084
+ VALUES (?, ?, ?, ?, ?, ?, 'edit', ?, ?, ?, ?, ?)`,
1085
+ [
1086
+ crypto.randomUUID(),
1087
+ target.id,
1088
+ targetVersion,
1089
+ targetContent,
1090
+ targetHash,
1091
+ versionIntent,
1092
+ input.changedByAgentId ?? null,
1093
+ now,
1094
+ now,
1095
+ input.changedByAgentId ?? null,
1096
+ input.changedByAgentId ?? null,
1097
+ ],
1098
+ );
1099
+ await tx.run(
1100
+ `UPDATE agent_memory
1101
+ SET content = ?, contentHash = ?, version = ?, updatedAt = ?, key = ?,
1102
+ expiresAt = CASE WHEN ? = 1 THEN NULL ELSE expiresAt END
1103
+ WHERE id = ?`,
1104
+ [
1105
+ targetContent,
1106
+ targetHash,
1107
+ targetVersion,
1108
+ now,
1109
+ moving ? input.newKey! : target.key,
1110
+ clearExpiry ? 1 : 0,
1111
+ target.id,
1112
+ ],
1113
+ );
1114
+ }
1012
1115
 
1013
1116
  return {
1014
1117
  result: {
@@ -1018,13 +1121,15 @@ export class SqliteMemoryStore implements MemoryStore {
1018
1121
  contentHash: nextHash,
1019
1122
  version: nextVersion,
1020
1123
  updatedAt: now,
1124
+ key: moving ? input.newKey! : row.key,
1125
+ expiresAt: clearExpiry ? null : row.expiresAt,
1021
1126
  }),
1022
1127
  changed: true,
1023
1128
  previousVersion,
1024
1129
  version: nextVersion,
1025
1130
  contentHash: nextHash,
1026
1131
  },
1027
- ftsContent: nextContent,
1132
+ ftsContent: contentChanged ? nextContent : null,
1028
1133
  };
1029
1134
  });
1030
1135
 
@@ -1040,16 +1145,18 @@ export class SqliteMemoryStore implements MemoryStore {
1040
1145
  ): Promise<{ id: string; source: string; name: string; createdAt: string }[]> {
1041
1146
  const db = getDbClient();
1042
1147
  const protectedList = [...PROTECTED_SOURCES].map((s) => `'${s}'`).join(",");
1148
+ // A /longterm key is protected whatever its source (see tierSource).
1149
+ const notLongterm = `coalesce(key, '') != '${LONGTERM_ROOT}' AND substr(coalesce(key, ''), 1, ${LONGTERM_ROOT.length + 1}) != '${LONGTERM_ROOT}/'`;
1043
1150
  if (agentId) {
1044
1151
  return db.query<{ id: string; source: string; name: string; createdAt: string }>(
1045
1152
  `SELECT id, source, name, createdAt FROM agent_memory
1046
- WHERE agentId = ? AND source NOT IN (${protectedList})`,
1153
+ WHERE agentId = ? AND source NOT IN (${protectedList}) AND ${notLongterm}`,
1047
1154
  [agentId],
1048
1155
  );
1049
1156
  }
1050
1157
  return db.query<{ id: string; source: string; name: string; createdAt: string }>(
1051
1158
  `SELECT id, source, name, createdAt FROM agent_memory
1052
- WHERE source NOT IN (${protectedList})`,
1159
+ WHERE source NOT IN (${protectedList}) AND ${notLongterm}`,
1053
1160
  );
1054
1161
  }
1055
1162
 
@@ -11,15 +11,21 @@
11
11
  * No `bun:sqlite` / `src/be/db` imports. Boundary script enforces this.
12
12
  */
13
13
  import { z } from "zod";
14
+ import { MEMORY_RATER_DEFAULT_MODEL } from "../../../utils/internal-ai/models";
14
15
  import { getOpenRouterBaseUrl } from "../../../utils/openrouter-base-url";
15
16
  import { type SummaryWithRatings, SummaryWithRatingsSchema } from "./llm";
16
17
 
17
18
  /**
18
- * Default model used when `MEMORY_RATER_MODEL` is unset. Gemini 3 Flash on
19
- * OpenRouter — the only Gemini 3 Flash variant published as of this PR (no
20
- * stable non-preview slug exists yet). CLAUDE.md project-wide default.
19
+ * Default model used when `MEMORY_RATER_MODEL` is unset: the OpenRouter slug of
20
+ * the pinned rater model. Derived from `MEMORY_RATER_DEFAULT_MODEL` so the
21
+ * rater default has one source of truth (this copy used to be a stale literal).
22
+ * The registry entry carries an `openrouter/` credential prefix that the chat
23
+ * completions API does not take.
21
24
  */
22
- export const DEFAULT_MEMORY_RATER_MODEL = "google/gemini-3-flash-preview";
25
+ export const DEFAULT_MEMORY_RATER_MODEL = MEMORY_RATER_DEFAULT_MODEL.openrouter.replace(
26
+ /^openrouter\//,
27
+ "",
28
+ );
23
29
 
24
30
  /**
25
31
  * `response_format.json_schema.name` sent to OpenRouter. Used by some
@@ -41,8 +41,12 @@ const RatingSchema = z.object({
41
41
  // Step-6 §6 — optional free-form external source ID. Q2 contract: ≤512
42
42
  // chars, no closed enum, no prefix parser. Sanitization (control-char
43
43
  // strip + NUL rejection) happens in `buildRatingsFromLlm` so a single
44
- // bad rating drops the field rather than failing the whole batch.
45
- referencesSource: z.string().min(1).max(REFERENCES_SOURCE_MAX_LENGTH).optional(),
44
+ // bad rating drops the field rather than failing the whole batch. No
45
+ // `.min(1)`: models emit `""` for "no source", and rejecting it here failed
46
+ // the whole summary and burned a retry. `buildRatingsFromLlm` treats an
47
+ // empty or whitespace-only value as no source. Keep `summaryToolSchema` in
48
+ // sync.
49
+ referencesSource: z.string().max(REFERENCES_SOURCE_MAX_LENGTH).optional(),
46
50
  });
47
51
 
48
52
  /**
@@ -156,20 +160,24 @@ export class LlmRater implements MemoryRater {
156
160
  * Mapping: `signal = 2 * score - 1` (0 → -1, 0.5 → 0, 1 → +1).
157
161
  * Weight = {@link LLM_RATER_WEIGHT} (0.8).
158
162
  * Source = `"llm"` (the HTTP rate endpoint enums `["llm", "explicit-self"]`).
163
+ * Model = the judge that produced the batch (from `summarizeSession`), stamped
164
+ * on every event so `memory_rating.model` records it; omitted when unknown.
159
165
  */
160
166
  export function buildRatingsFromLlm(
161
167
  ratings: LlmRating[],
162
168
  retrievals: { id: string }[],
169
+ model?: string,
163
170
  ): RatingEvent[] {
164
171
  const allowed = new Set(retrievals.map((r) => r.id));
165
172
  const events: RatingEvent[] = [];
166
173
  for (const r of ratings) {
167
174
  if (!allowed.has(r.id)) continue;
168
- // Step-6 §6 — sanitize before propagation. If the LLM emits a NUL byte
169
- // or an all-control-chars string, drop the edge but keep the rating
175
+ // Step-6 §6 — sanitize before propagation. If the LLM emits a NUL byte,
176
+ // an all-control-chars string, or an empty / whitespace-only string (its
177
+ // way of saying "no source"), drop the edge but keep the rating
170
178
  // (best-effort: the memory's own posterior still gets the signal).
171
179
  let cleanedReferencesSource: string | undefined;
172
- if (r.referencesSource !== undefined) {
180
+ if (r.referencesSource !== undefined && r.referencesSource.trim() !== "") {
173
181
  const cleaned = sanitizeReferencesSource(r.referencesSource);
174
182
  if (cleaned !== null) {
175
183
  cleanedReferencesSource = cleaned;
@@ -184,6 +192,7 @@ export function buildRatingsFromLlm(
184
192
  ...(cleanedReferencesSource !== undefined
185
193
  ? { referencesSource: cleanedReferencesSource }
186
194
  : {}),
195
+ ...(model ? { model } : {}),
187
196
  });
188
197
  }
189
198
  return events;
@@ -371,6 +380,7 @@ export async function postRatings(opts: {
371
380
  source: e.source,
372
381
  ...(e.reasoning !== undefined ? { reasoning: e.reasoning } : {}),
373
382
  ...(e.referencesSource !== undefined ? { referencesSource: e.referencesSource } : {}),
383
+ ...(e.model !== undefined ? { model: e.model } : {}),
374
384
  ...(opts.taskId ? { taskId: opts.taskId } : {}),
375
385
  }));
376
386
  try {
@@ -11,7 +11,8 @@ import { type RatingEvent, REFERENCES_SOURCE_MAX_LENGTH, sanitizeReferencesSourc
11
11
  * - alphaDelta = max(0, signal) * weight (rewards usefulness)
12
12
  * - betaDelta = max(0, -signal) * weight (rewards anti-usefulness)
13
13
  * - UPDATE agent_memory SET alpha = alpha + ?, beta = beta + ? WHERE id = ?
14
- * - INSERT INTO memory_rating (...) VALUES (...)
14
+ * - INSERT INTO memory_rating (...) VALUES (...) — `model` is recorded for
15
+ * `llm` events only; every other source stores NULL.
15
16
  * - When `referencesSource` is present (step-6 §3): UPSERT into
16
17
  * agent_memory_edge with the SAME (alphaDelta, betaDelta) so the edge's
17
18
  * own posterior tracks evidence the same way the memory's does.
@@ -96,8 +97,8 @@ export async function applyRating(
96
97
  "UPDATE agent_memory SET alpha = alpha + ?, beta = beta + ? WHERE id = ?";
97
98
  const CHECK_EXISTS_SQL = "SELECT id FROM agent_memory WHERE id = ?";
98
99
  const INSERT_RATING_SQL = `INSERT INTO memory_rating
99
- (id, memoryId, taskId, source, signal, weight, reasoning, createdAt, contextKey)
100
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`;
100
+ (id, memoryId, taskId, source, signal, weight, reasoning, createdAt, contextKey, model)
101
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
101
102
  // Step-6 §3 — UPSERT the edge with the SAME deltas as the memory row.
102
103
  // The `- 1.0` corrections in DO UPDATE undo the default-prior offset that
103
104
  // the INSERT arm baked into excluded.alpha/excluded.beta. Net effect: on
@@ -135,6 +136,8 @@ export async function applyRating(
135
136
  event.reasoning ?? null,
136
137
  new Date().toISOString(),
137
138
  ctx.contextKey ?? null,
139
+ // Provenance is only meaningful for a model-judged rating.
140
+ event.source === "llm" ? (event.model ?? null) : null,
138
141
  ]);
139
142
  } catch (err) {
140
143
  // Partial unique index on (taskId, memoryId) WHERE source='explicit-self'