@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
@@ -1,26 +1,30 @@
1
1
  import {
2
2
  getValidCodexOAuth,
3
3
  persistCodexOAuth
4
- } from "./cli-ygwm91nt.js";
4
+ } from "./cli-yy6dew39.js";
5
+ import {
6
+ oauthErrorHtml,
7
+ oauthSuccessHtml
8
+ } from "./cli-2x0e561b.js";
5
9
  import {
6
10
  GITHUB_COPILOT_MODELS,
7
11
  builtinModels,
8
12
  normalizeRadiusGatewayUrl,
9
13
  registerBundledOAuthFlowLoaders
10
- } from "./cli-10nhj6xq.js";
11
- import {
12
- oauthErrorHtml,
13
- oauthSuccessHtml
14
- } from "./cli-rykfmgwg.js";
14
+ } from "./cli-nt8hecg9.js";
15
15
  import {
16
16
  getEnvApiKey
17
17
  } from "./cli-trc24wk2.js";
18
+ import {
19
+ InMemoryCredentialStore
20
+ } from "./cli-ykk5jaax.js";
18
21
  import {
19
22
  getProviderEnvValue
20
23
  } from "./cli-btbzvq95.js";
21
24
  import {
22
- InMemoryCredentialStore
23
- } from "./cli-ykk5jaax.js";
25
+ init_src,
26
+ isFirstPartyAnthropicUrl
27
+ } from "./cli-f9w1semm.js";
24
28
  import {
25
29
  __require
26
30
  } from "./cli-bc05qbss.js";
@@ -33,8 +37,15 @@ var DEFAULT_MODEL = {
33
37
  "openai-codex": "openai-codex/gpt-6-luna",
34
38
  "claude-cli": "haiku"
35
39
  };
36
- function resolveModelString(kind) {
37
- return process.env.MEMORY_RATER_MODEL ?? DEFAULT_MODEL[kind];
40
+ var MEMORY_RATER_DEFAULT_MODEL = {
41
+ openrouter: "openrouter/deepseek/deepseek-v4.1-flash",
42
+ anthropic: "anthropic/claude-haiku-4-5",
43
+ openai: "openai/gpt-6-luna",
44
+ "openai-codex": "openai-codex/gpt-6-luna",
45
+ "claude-cli": "haiku"
46
+ };
47
+ function resolveRaterModelString(kind) {
48
+ return process.env.MEMORY_RATER_MODEL ?? MEMORY_RATER_DEFAULT_MODEL[kind];
38
49
  }
39
50
  function parseModelStr(modelStr) {
40
51
  const idx = modelStr.indexOf("/");
@@ -43,6 +54,9 @@ function parseModelStr(modelStr) {
43
54
  return [modelStr.slice(0, idx), modelStr.slice(idx + 1)];
44
55
  }
45
56
 
57
+ // src/utils/internal-ai/credentials.ts
58
+ init_src();
59
+
46
60
  // node_modules/@earendil-works/pi-ai/dist/auth/oauth/callback-server.js
47
61
  import { createServer } from "node:http";
48
62
  function sendPage(response, status, html) {
@@ -202,6 +216,9 @@ var CALLBACK_HOST = getProviderEnvValue("PI_OAUTH_CALLBACK_HOST") || "127.0.0.1"
202
216
  var CALLBACK_PORT = 53692;
203
217
  var CALLBACK_PATH = "/callback";
204
218
  var REDIRECT_URI = `http://localhost:${CALLBACK_PORT}${CALLBACK_PATH}`;
219
+ var COPY_CODE_REDIRECT_URI = "https://platform.claude.com/oauth/code/callback";
220
+ var ANTHROPIC_BROWSER_LOGIN_METHOD = "browser";
221
+ var ANTHROPIC_COPY_CODE_LOGIN_METHOD = "copy_code";
205
222
  var SCOPES = "org:create_api_key user:profile user:inference user:sessions:claude_code user:mcp_servers user:file_upload";
206
223
  function parseAuthorizationInput(input) {
207
224
  const value = input.trim();
@@ -340,6 +357,37 @@ async function loginAnthropic(interaction) {
340
357
  callback?.close();
341
358
  }
342
359
  }
360
+ async function loginAnthropicCopyCode(interaction) {
361
+ const { verifier, challenge } = await generatePKCE();
362
+ const authParams = new URLSearchParams({
363
+ code: "true",
364
+ client_id: CLIENT_ID,
365
+ response_type: "code",
366
+ redirect_uri: COPY_CODE_REDIRECT_URI,
367
+ scope: SCOPES,
368
+ code_challenge: challenge,
369
+ code_challenge_method: "S256",
370
+ state: verifier
371
+ });
372
+ interaction.notify({
373
+ type: "auth_url",
374
+ url: `${AUTHORIZE_URL}?${authParams.toString()}`,
375
+ instructions: "Complete login in your browser, then copy the code Anthropic shows and paste it here."
376
+ });
377
+ const input = await interaction.prompt({
378
+ type: "manual_code",
379
+ message: "Paste the code Anthropic shows after you sign in:",
380
+ placeholder: "code#state",
381
+ signal: interaction.signal
382
+ });
383
+ const parsed = parseAuthorizationInput(input);
384
+ if (parsed.state && parsed.state !== verifier)
385
+ throw new Error("OAuth state mismatch");
386
+ if (!parsed.code)
387
+ throw new Error("Missing authorization code");
388
+ interaction.notify({ type: "progress", message: "Exchanging authorization code for tokens..." });
389
+ return await exchangeAuthorizationCode(parsed.code, parsed.state ?? verifier, verifier, COPY_CODE_REDIRECT_URI, interaction.signal);
390
+ }
343
391
  async function refreshAnthropicToken(refreshToken, signal) {
344
392
  let responseBody;
345
393
  try {
@@ -367,7 +415,23 @@ async function refreshAnthropicToken(refreshToken, signal) {
367
415
  var anthropicOAuth = {
368
416
  name: "Anthropic (Claude Pro/Max)",
369
417
  isSubscription: true,
370
- login: loginAnthropic,
418
+ async login(interaction) {
419
+ const method = await interaction.prompt({
420
+ type: "select",
421
+ message: "Select Anthropic login method:",
422
+ options: [
423
+ { id: ANTHROPIC_BROWSER_LOGIN_METHOD, label: "Browser login (default)" },
424
+ { id: ANTHROPIC_COPY_CODE_LOGIN_METHOD, label: "Copy code login (headless)" }
425
+ ]
426
+ });
427
+ if (method === ANTHROPIC_COPY_CODE_LOGIN_METHOD) {
428
+ return loginAnthropicCopyCode(interaction);
429
+ }
430
+ if (method !== ANTHROPIC_BROWSER_LOGIN_METHOD) {
431
+ throw new Error(`Unknown Anthropic login method: ${method}`);
432
+ }
433
+ return loginAnthropic(interaction);
434
+ },
371
435
  refresh: (credential, signal) => refreshAnthropicToken(credential.refresh, signal),
372
436
  async toAuth(credential) {
373
437
  return { apiKey: credential.access };
@@ -1359,15 +1423,11 @@ async function loginOpenAIChatGPT(interaction, options) {
1359
1423
  const { verifier, challenge } = await generatePKCE();
1360
1424
  const state = randomValue();
1361
1425
  const nonce = randomValue();
1362
- let callback;
1363
- try {
1364
- callback = await startCallbackServer(state);
1365
- } catch (error) {
1366
- interaction.notify({
1367
- type: "info",
1368
- message: `Could not listen on ${REDIRECT_URI2}; paste the final redirect URL to continue. ${error instanceof Error ? error.message : String(error)}`
1369
- });
1370
- }
1426
+ const callback = await startCallbackServer(state).catch((error) => {
1427
+ if (!(error instanceof Error && ("code" in error) && error.code === "EADDRINUSE"))
1428
+ throw error;
1429
+ throw new Error(`Port ${CALLBACK_PORT2} is in use, probably by an unfinished login in another pi session or by the Codex CLI. Cancel that login and try again.`);
1430
+ });
1371
1431
  const authorizationUrl = new URL(AUTHORIZE_URL2);
1372
1432
  authorizationUrl.search = new URLSearchParams({
1373
1433
  client_id: DYNAMIC_CLIENT_ID,
@@ -1395,7 +1455,7 @@ async function loginOpenAIChatGPT(interaction, options) {
1395
1455
  signal: AbortSignal.any([manualAbort.signal, interaction.signal])
1396
1456
  }).then((input) => authorizationResultFromManualInput(input, state));
1397
1457
  try {
1398
- const result = await (callback ? Promise.race([callback.result, manualCode]) : manualCode);
1458
+ const result = await Promise.race([callback.result, manualCode]);
1399
1459
  interaction.notify({ type: "progress", message: "Exchanging authorization code for tokens..." });
1400
1460
  return await exchangeAuthorizationCode2(result.code, verifier, result.clientId, interaction.signal);
1401
1461
  } catch (error) {
@@ -1404,8 +1464,8 @@ async function loginOpenAIChatGPT(interaction, options) {
1404
1464
  throw error;
1405
1465
  } finally {
1406
1466
  manualAbort.abort();
1407
- callback?.server.close();
1408
- callback?.server.closeAllConnections();
1467
+ callback.server.close();
1468
+ callback.server.closeAllConnections();
1409
1469
  }
1410
1470
  }
1411
1471
  var openaiChatGPTOAuth = {
@@ -2329,15 +2389,17 @@ async function resolveCredential(opts = {}) {
2329
2389
  return {
2330
2390
  kind: "openrouter",
2331
2391
  apiKey: openrouterKey,
2332
- modelDefault: resolveModelString("openrouter")
2392
+ modelDefault: resolveRaterModelString("openrouter")
2333
2393
  };
2334
2394
  }
2335
- const anthropicKey = env.ANTHROPIC_API_KEY ?? getEnvKey("anthropic");
2395
+ const anthropicBaseUrl = env.ANTHROPIC_BASE_URL?.trim();
2396
+ const anthropicKeyIsForGateway = Boolean(anthropicBaseUrl) && !isFirstPartyAnthropicUrl(anthropicBaseUrl ?? "");
2397
+ const anthropicKey = anthropicKeyIsForGateway ? undefined : env.ANTHROPIC_API_KEY ?? getEnvKey("anthropic");
2336
2398
  if (anthropicKey) {
2337
2399
  return {
2338
2400
  kind: "anthropic",
2339
2401
  apiKey: anthropicKey,
2340
- modelDefault: resolveModelString("anthropic")
2402
+ modelDefault: resolveRaterModelString("anthropic")
2341
2403
  };
2342
2404
  }
2343
2405
  const openaiKey = env.OPENAI_API_KEY ?? getEnvKey("openai");
@@ -2345,7 +2407,7 @@ async function resolveCredential(opts = {}) {
2345
2407
  return {
2346
2408
  kind: "openai",
2347
2409
  apiKey: openaiKey,
2348
- modelDefault: resolveModelString("openai")
2410
+ modelDefault: resolveRaterModelString("openai")
2349
2411
  };
2350
2412
  }
2351
2413
  if (opts.apiUrl && opts.apiKey) {
@@ -2377,7 +2439,7 @@ async function resolveCredential(opts = {}) {
2377
2439
  return {
2378
2440
  kind: "openai-codex",
2379
2441
  apiKey: oauthResult.apiKey,
2380
- modelDefault: resolveModelString("openai-codex")
2442
+ modelDefault: resolveRaterModelString("openai-codex")
2381
2443
  };
2382
2444
  }
2383
2445
  }
@@ -2388,7 +2450,7 @@ async function resolveCredential(opts = {}) {
2388
2450
  if (env.AGENT_SWARM_CLAUDE_OAUTH_TOKEN || env.CLAUDE_CODE_OAUTH_TOKEN) {
2389
2451
  return {
2390
2452
  kind: "claude-cli",
2391
- modelDefault: resolveModelString("claude-cli")
2453
+ modelDefault: resolveRaterModelString("claude-cli")
2392
2454
  };
2393
2455
  }
2394
2456
  return null;
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  contentSha256,
3
3
  init_profile_sync
4
- } from "./cli-25fcq4b4.js";
4
+ } from "./cli-cebmgwsc.js";
5
5
  import {
6
6
  getDb,
7
7
  getDbClient,
8
8
  init_db,
9
9
  isSqliteVecAvailable
10
- } from "./cli-qydf22qq.js";
10
+ } from "./cli-jf7wmv1r.js";
11
11
  import {
12
12
  __esm,
13
13
  __export,
@@ -8024,7 +8024,7 @@ function isGraphExpansionEnabled() {
8024
8024
  const val = process.env.MEMORY_GRAPH_EXPANSION?.trim().toLowerCase();
8025
8025
  return val !== "0" && val !== "false";
8026
8026
  }
8027
- var TTL_DEFAULTS, DEFAULT_RECENCY_DECAY_HALF_LIFE, SOURCE_QUALITY_MULTIPLIER, ACCESS_BOOST_RECENCY_WINDOW_HOURS, CANDIDATE_SET_MULTIPLIER, EMBEDDING_DIMENSIONS, DEFAULT_EMBEDDING_MODEL = "openai/text-embedding-3-small", PROTECTED_SOURCES;
8027
+ var TTL_DEFAULTS, DEFAULT_RECENCY_DECAY_HALF_LIFE, SOURCE_QUALITY_MULTIPLIER, PATH_WEIGHT, DECISIONS_ROOT = "/longterm/decisions", SUPERSEDED_DECISION_WEIGHT = 0.3, ACCESS_BOOST_RECENCY_WINDOW_HOURS, CANDIDATE_SET_MULTIPLIER, EMBEDDING_DIMENSIONS, DEFAULT_EMBEDDING_MODEL = "openai/text-embedding-3-small", PROTECTED_SOURCES;
8028
8028
  var init_constants = __esm(() => {
8029
8029
  TTL_DEFAULTS = {
8030
8030
  task_completion: 7,
@@ -8044,6 +8044,13 @@ var init_constants = __esm(() => {
8044
8044
  task_completion: 0.7,
8045
8045
  session_summary: 0.5
8046
8046
  };
8047
+ PATH_WEIGHT = {
8048
+ "/longterm/company-story": 1.4,
8049
+ "/longterm/entities": 1.3,
8050
+ "/longterm/facts": 1.2,
8051
+ "/longterm/decisions": 1.1,
8052
+ "/longterm/timeline": 0.8
8053
+ };
8047
8054
  ACCESS_BOOST_RECENCY_WINDOW_HOURS = numEnv("MEMORY_ACCESS_RECENCY_HOURS", 48);
8048
8055
  CANDIDATE_SET_MULTIPLIER = numEnv("MEMORY_CANDIDATE_MULTIPLIER", 3);
8049
8056
  EMBEDDING_DIMENSIONS = numEnv("EMBEDDING_DIMENSIONS", 512);
@@ -8185,9 +8192,61 @@ function deserializeEmbedding(buffer) {
8185
8192
  }
8186
8193
  var init_embedding = () => {};
8187
8194
 
8195
+ // src/be/memory/key-paths.ts
8196
+ function isKeyUnderRoot(key, root) {
8197
+ return key === root || key.startsWith(`${root}/`);
8198
+ }
8199
+ function isLongtermKey(key) {
8200
+ return !!key && isKeyUnderRoot(key, LONGTERM_ROOT);
8201
+ }
8202
+ function longtermKeyError(key) {
8203
+ if (!isLongtermKey(key))
8204
+ return null;
8205
+ const [root, entityType] = key.split("/").slice(2);
8206
+ if (!LONGTERM_ROOTS.some((allowed) => allowed === root)) {
8207
+ 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>.`;
8208
+ }
8209
+ if (root === "entities" && !LONGTERM_ENTITY_TYPES.some((allowed) => allowed === entityType)) {
8210
+ 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>.`;
8211
+ }
8212
+ return null;
8213
+ }
8214
+ function tierSource(source, key) {
8215
+ return isLongtermKey(key) ? "manual" : source;
8216
+ }
8217
+ function isConsolidatedKey(key) {
8218
+ return CONSOLIDATED_KEY_ROOTS.some((root) => isKeyUnderRoot(key, root));
8219
+ }
8220
+ function consolidatedKeyMessage(key) {
8221
+ 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.`;
8222
+ }
8223
+ function resolveStoreKey(key, name) {
8224
+ if (key)
8225
+ return key;
8226
+ return name?.startsWith(`${LONGTERM_ROOT}/`) ? name : null;
8227
+ }
8228
+ var LONGTERM_ROOT = "/longterm", MEMORY_KEY_PATTERN, MEMORY_KEY_PATTERN_MESSAGE = "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 '/'.", MEMORY_KEY_MAX_LENGTH = 200, LONGTERM_ROOTS, LONGTERM_ENTITY_TYPES, CONSOLIDATED_KEY_ROOTS;
8229
+ var init_key_paths = __esm(() => {
8230
+ MEMORY_KEY_PATTERN = /^\/[a-z0-9-]+(\/[a-z0-9._-]+)*$/;
8231
+ LONGTERM_ROOTS = [
8232
+ "company-story",
8233
+ "entities",
8234
+ "facts",
8235
+ "decisions",
8236
+ "workstreams",
8237
+ "timeline"
8238
+ ];
8239
+ LONGTERM_ENTITY_TYPES = ["people", "customers"];
8240
+ CONSOLIDATED_KEY_ROOTS = [
8241
+ `${LONGTERM_ROOT}/company-story`,
8242
+ `${LONGTERM_ROOT}/entities`,
8243
+ `${LONGTERM_ROOT}/timeline`
8244
+ ];
8245
+ });
8246
+
8188
8247
  // src/be/memory/reranker.ts
8189
- function recencyDecay(createdAt, now, source) {
8190
- const halfLife = recencyDecayHalfLifeDays(source);
8248
+ function recencyDecay(createdAt, now, source, key) {
8249
+ const halfLife = recencyDecayHalfLifeDays(source && tierSource(source, key));
8191
8250
  if (!Number.isFinite(halfLife))
8192
8251
  return 1;
8193
8252
  const ageDays = (now.getTime() - new Date(createdAt).getTime()) / MS_PER_DAY;
@@ -8203,8 +8262,23 @@ function accessBoost(accessedAt, accessCount, now) {
8203
8262
  const boost = 1 + Math.min(accessCount / 10, accessBoostMaxMultiplier() - 1) * recencyFactor;
8204
8263
  return boost;
8205
8264
  }
8206
- function sourceQuality(source) {
8207
- return SOURCE_QUALITY_MULTIPLIER[source] ?? 1;
8265
+ function sourceQuality(source, key) {
8266
+ return SOURCE_QUALITY_MULTIPLIER[tierSource(source, key)] ?? 1;
8267
+ }
8268
+ function pathWeight(key, tags = []) {
8269
+ if (!key)
8270
+ return 1;
8271
+ let root;
8272
+ for (const candidate of Object.keys(PATH_WEIGHT)) {
8273
+ if (isKeyUnderRoot(key, candidate) && (!root || candidate.length > root.length)) {
8274
+ root = candidate;
8275
+ }
8276
+ }
8277
+ if (!root)
8278
+ return 1;
8279
+ if (root === DECISIONS_ROOT && tags.includes("superseded"))
8280
+ return SUPERSEDED_DECISION_WEIGHT;
8281
+ return PATH_WEIGHT[root] ?? 1;
8208
8282
  }
8209
8283
  function readDemotionFloor() {
8210
8284
  const raw = process.env.MEMORY_DEMOTION_FLOOR;
@@ -8219,8 +8293,8 @@ function usefulness(alpha, beta) {
8219
8293
  return Math.max(readDemotionFloor(), Math.min(2, 2 * mean));
8220
8294
  }
8221
8295
  function computeScore(candidate, now) {
8222
- const decay = candidate.recencyDecayApplied ? 1 : recencyDecay(candidate.createdAt, now, candidate.source);
8223
- return candidate.similarity * decay * accessBoost(candidate.accessedAt, candidate.accessCount, now) * sourceQuality(candidate.source) * usefulness(candidate.alpha, candidate.beta);
8296
+ const decay = candidate.recencyDecayApplied ? 1 : recencyDecay(candidate.createdAt, now, candidate.source, candidate.key);
8297
+ return candidate.similarity * decay * accessBoost(candidate.accessedAt, candidate.accessCount, now) * sourceQuality(candidate.source, candidate.key) * pathWeight(candidate.key, candidate.tags) * usefulness(candidate.alpha, candidate.beta);
8224
8298
  }
8225
8299
  function rerank(candidates, options) {
8226
8300
  const { limit: limit2, now = new Date } = options;
@@ -8258,6 +8332,7 @@ function rerank(candidates, options) {
8258
8332
  var MS_PER_DAY, MS_PER_HOUR;
8259
8333
  var init_reranker = __esm(() => {
8260
8334
  init_constants();
8335
+ init_key_paths();
8261
8336
  MS_PER_DAY = 1000 * 60 * 60 * 24;
8262
8337
  MS_PER_HOUR = 1000 * 60 * 60;
8263
8338
  });
@@ -8342,8 +8417,8 @@ function applyEditMode(mode, currentContent, fields) {
8342
8417
  }
8343
8418
  return currentContent.slice(0, first) + fields.newString + currentContent.slice(first + fields.oldString.length);
8344
8419
  }
8345
- function computeExpiresAt(source) {
8346
- const ttlDays = TTL_DEFAULTS[source];
8420
+ function computeExpiresAt(source, key) {
8421
+ const ttlDays = TTL_DEFAULTS[tierSource(source, key)];
8347
8422
  if (ttlDays == null)
8348
8423
  return null;
8349
8424
  return new Date(Date.now() + ttlDays * 86400000).toISOString();
@@ -8533,8 +8608,8 @@ class SqliteMemoryStore {
8533
8608
  async store(input) {
8534
8609
  const id = crypto.randomUUID();
8535
8610
  const now = new Date().toISOString();
8536
- const expiresAt = computeExpiresAt(input.source);
8537
8611
  const key = input.key ?? `${input.scope}/${input.source}/${id}`;
8612
+ const expiresAt = computeExpiresAt(input.source, key);
8538
8613
  const contentHash = contentSha256(input.content);
8539
8614
  const version = 1;
8540
8615
  const row = await getDbClient().transaction(async (tx) => {
@@ -8610,7 +8685,14 @@ class SqliteMemoryStore {
8610
8685
  return rowToAgentMemory(row);
8611
8686
  }
8612
8687
  async search(embedding, agentId, options = {}) {
8613
- const { scope = "all", limit: limit2 = 10, source, isLead = false, includeExpired = false } = options;
8688
+ const {
8689
+ scope = "all",
8690
+ limit: limit2 = 10,
8691
+ source,
8692
+ isLead = false,
8693
+ includeExpired = false,
8694
+ keyPrefix
8695
+ } = options;
8614
8696
  const health = this.getHealth();
8615
8697
  if (isHybridSearchEnabled() && options.queryText && this.ftsInitialized && await this.getFtsTableSchema() && health.retrievalMode === "vec" && embedding.length === EMBEDDING_DIMENSIONS) {
8616
8698
  console.log(`[memory-search] retrieval_path=hybrid scope=${scope} limit=${limit2} vec_rows=${health.counts.memoryVec} searchable=${health.counts.searchable}`);
@@ -8619,7 +8701,8 @@ class SqliteMemoryStore {
8619
8701
  limit: limit2,
8620
8702
  source,
8621
8703
  isLead,
8622
- includeExpired
8704
+ includeExpired,
8705
+ keyPrefix
8623
8706
  });
8624
8707
  }
8625
8708
  if (health.retrievalMode === "vec" && embedding.length === EMBEDDING_DIMENSIONS) {
@@ -8629,7 +8712,8 @@ class SqliteMemoryStore {
8629
8712
  limit: limit2,
8630
8713
  source,
8631
8714
  isLead,
8632
- includeExpired
8715
+ includeExpired,
8716
+ keyPrefix
8633
8717
  });
8634
8718
  }
8635
8719
  if (options.queryText && this.ftsInitialized && await this.getFtsTableSchema()) {
@@ -8639,7 +8723,8 @@ class SqliteMemoryStore {
8639
8723
  limit: limit2,
8640
8724
  source,
8641
8725
  isLead,
8642
- includeExpired
8726
+ includeExpired,
8727
+ keyPrefix
8643
8728
  });
8644
8729
  }
8645
8730
  console.log(`[memory-search] retrieval_path=fallback scope=${scope} limit=${limit2} reason=${embedding.length !== EMBEDDING_DIMENSIONS ? "query_dimension_mismatch" : health.reasons.join("|") || "vec_unavailable"}`);
@@ -8648,7 +8733,8 @@ class SqliteMemoryStore {
8648
8733
  limit: limit2,
8649
8734
  source,
8650
8735
  isLead,
8651
- includeExpired
8736
+ includeExpired,
8737
+ keyPrefix
8652
8738
  });
8653
8739
  }
8654
8740
  async searchHybrid(queryEmbedding, queryText, agentId, options) {
@@ -8707,10 +8793,11 @@ class SqliteMemoryStore {
8707
8793
  const match = this.buildFtsMatch(queryText);
8708
8794
  if (!match)
8709
8795
  return [];
8710
- const { scope, limit: limit2, source, isLead, includeExpired } = options;
8796
+ const { scope, limit: limit2, source, isLead, includeExpired, keyPrefix } = options;
8711
8797
  const conditions = ["memory_fts MATCH ?"];
8712
8798
  const params = [match];
8713
8799
  this.addScopeConditions(conditions, params, agentId, scope, isLead, "m");
8800
+ this.addKeyPrefixCondition(conditions, params, keyPrefix, "m");
8714
8801
  if (source) {
8715
8802
  conditions.push("m.source = ?");
8716
8803
  params.push(source);
@@ -8730,7 +8817,7 @@ class SqliteMemoryStore {
8730
8817
  return rows.map((row, index) => {
8731
8818
  const rawSimilarity = 1 / (index + 1);
8732
8819
  return {
8733
- ...rowToCandidate(row, rawSimilarity * recencyDecay(row.createdAt, now, row.source)),
8820
+ ...rowToCandidate(row, rawSimilarity * recencyDecay(row.createdAt, now, row.source, row.key)),
8734
8821
  rawSimilarity,
8735
8822
  retrievalSource: "fts",
8736
8823
  recencyDecayApplied: true
@@ -8748,12 +8835,13 @@ class SqliteMemoryStore {
8748
8835
  return terms.map((term) => `"${term.replaceAll('"', '""')}"`).join(" OR ");
8749
8836
  }
8750
8837
  async searchWithVec(queryEmbedding, agentId, options) {
8751
- const { scope, limit: limit2, source, isLead, includeExpired } = options;
8838
+ const { scope, limit: limit2, source, isLead, includeExpired, keyPrefix } = options;
8752
8839
  const embeddingBuffer = serializeEmbedding(queryEmbedding);
8753
8840
  const knnLimit = Math.min(Math.max(limit2, this.getVecCount()), 4096);
8754
8841
  const conditions = ["v.embedding MATCH ?"];
8755
8842
  const params = [embeddingBuffer];
8756
8843
  this.addScopeConditions(conditions, params, agentId, scope, isLead, "m");
8844
+ this.addKeyPrefixCondition(conditions, params, keyPrefix, "m");
8757
8845
  if (source) {
8758
8846
  conditions.push("m.source = ?");
8759
8847
  params.push(source);
@@ -8779,10 +8867,11 @@ class SqliteMemoryStore {
8779
8867
  return candidates;
8780
8868
  }
8781
8869
  async searchBruteForce(queryEmbedding, agentId, options) {
8782
- const { scope, limit: limit2, source, isLead, includeExpired } = options;
8870
+ const { scope, limit: limit2, source, isLead, includeExpired, keyPrefix } = options;
8783
8871
  const conditions = ["embedding IS NOT NULL"];
8784
8872
  const params = [];
8785
8873
  this.addScopeConditions(conditions, params, agentId, scope, isLead);
8874
+ this.addKeyPrefixCondition(conditions, params, keyPrefix);
8786
8875
  if (source) {
8787
8876
  conditions.push("source = ?");
8788
8877
  params.push(source);
@@ -8827,11 +8916,19 @@ class SqliteMemoryStore {
8827
8916
  }
8828
8917
  }
8829
8918
  }
8919
+ addKeyPrefixCondition(conditions, params, keyPrefix, tableAlias = "") {
8920
+ if (!keyPrefix)
8921
+ return;
8922
+ const key = tableAlias ? `${tableAlias}.key` : "key";
8923
+ conditions.push(`substr(${key}, 1, length(?)) = ?`);
8924
+ params.push(keyPrefix, keyPrefix);
8925
+ }
8830
8926
  buildListWhereClause(agentId, options) {
8831
- const { scope = "all", isLead = false, ownerAgentId, source, sourcePath } = options;
8927
+ const { scope = "all", isLead = false, ownerAgentId, source, sourcePath, keyPrefix } = options;
8832
8928
  const conditions = [];
8833
8929
  const params = [];
8834
8930
  this.addScopeConditions(conditions, params, agentId, scope, isLead);
8931
+ this.addKeyPrefixCondition(conditions, params, keyPrefix);
8835
8932
  if (ownerAgentId) {
8836
8933
  conditions.push("agentId = ?");
8837
8934
  params.push(ownerAgentId);
@@ -8862,8 +8959,8 @@ class SqliteMemoryStore {
8862
8959
  const row = await getDbClient().get(`SELECT COUNT(*) AS count FROM agent_memory ${whereClause}`, params);
8863
8960
  return row?.count ?? 0;
8864
8961
  }
8865
- isSourceProtected(source) {
8866
- return PROTECTED_SOURCES.has(source);
8962
+ isSourceProtected(source, key) {
8963
+ return PROTECTED_SOURCES.has(tierSource(source, key));
8867
8964
  }
8868
8965
  async edit(input) {
8869
8966
  if (!input.id && !(input.key && input.scope)) {
@@ -8876,19 +8973,22 @@ class SqliteMemoryStore {
8876
8973
  LIMIT 1`, [input.key, input.scope, input.agentId ?? null]);
8877
8974
  if (!row)
8878
8975
  throw new Error("memory not found");
8879
- if ((row.totalChunks ?? 1) !== 1)
8976
+ const moveOnly = input.newKey !== undefined && input.content === undefined && input.oldString === undefined && input.newString === undefined;
8977
+ if (!moveOnly && (row.totalChunks ?? 1) !== 1)
8880
8978
  throw new Error("memory edit only supports single-chunk rows");
8881
8979
  if (input.expectedVersion && input.expectedVersion !== (row.version ?? 1)) {
8882
8980
  throw new Error("memory version conflict");
8883
8981
  }
8884
8982
  const previousVersion = row.version ?? 1;
8885
- const nextContent = applyEditMode(input.mode, row.content, {
8983
+ const moving = input.newKey !== undefined && input.newKey !== row.key;
8984
+ const nextContent = moveOnly ? row.content : applyEditMode(input.mode, row.content, {
8886
8985
  content: input.content,
8887
8986
  oldString: input.oldString,
8888
8987
  newString: input.newString
8889
8988
  });
8890
8989
  const nextHash = contentSha256(nextContent);
8891
- if (nextHash === row.contentHash) {
8990
+ const contentChanged = !moveOnly && nextHash !== row.contentHash;
8991
+ if (!contentChanged && !moving) {
8892
8992
  return {
8893
8993
  result: {
8894
8994
  memory: rowToAgentMemory(row),
@@ -8900,25 +9000,61 @@ class SqliteMemoryStore {
8900
9000
  ftsContent: null
8901
9001
  };
8902
9002
  }
8903
- const nextVersion = previousVersion + 1;
9003
+ let targets = [row];
9004
+ if (moving) {
9005
+ const owner = row.agentId ?? null;
9006
+ if (row.key) {
9007
+ targets = await tx.query(`SELECT * FROM agent_memory
9008
+ WHERE key = ? AND scope = ? AND coalesce(agentId, '') = coalesce(?, '')
9009
+ ORDER BY chunkIndex ASC`, [row.key, row.scope, owner]);
9010
+ }
9011
+ if (targets.length !== (row.totalChunks ?? 1) || targets.some((target, index) => target.chunkIndex !== index)) {
9012
+ throw new Error("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");
9013
+ }
9014
+ const taken = await tx.get(`SELECT id FROM agent_memory
9015
+ WHERE key = ? AND scope = ? AND coalesce(agentId, '') = coalesce(?, '')
9016
+ LIMIT 1`, [input.newKey, row.scope, owner]);
9017
+ if (taken)
9018
+ throw new Error(`key "${input.newKey}" is already used in this scope`);
9019
+ }
9020
+ const clearExpiry = moving && isLongtermKey(input.newKey);
8904
9021
  const now = new Date().toISOString();
8905
- await tx.run(`INSERT INTO agent_memory_version (id, memory_id, version, content, contentHash, intent, operation, changedByAgentId, createdAt, updatedAt, created_by, updated_by)
8906
- VALUES (?, ?, ?, ?, ?, ?, 'edit', ?, ?, ?, ?, ?)`, [
8907
- crypto.randomUUID(),
8908
- row.id,
8909
- nextVersion,
8910
- nextContent,
8911
- nextHash,
8912
- input.intent,
8913
- input.changedByAgentId ?? null,
8914
- now,
8915
- now,
8916
- input.changedByAgentId ?? null,
8917
- input.changedByAgentId ?? null
8918
- ]);
8919
- await tx.run(`UPDATE agent_memory
8920
- SET content = ?, contentHash = ?, version = ?, updatedAt = ?
8921
- WHERE id = ?`, [nextContent, nextHash, nextVersion, now, row.id]);
9022
+ const versionIntent = moving ? `${input.intent} [key ${row.key ?? "(none)"} -> ${input.newKey}]` : input.intent;
9023
+ let nextVersion = previousVersion + 1;
9024
+ for (const target of targets) {
9025
+ const addressed = target.id === row.id;
9026
+ const targetContent = addressed ? nextContent : target.content;
9027
+ const targetHash = addressed ? nextHash : target.contentHash ?? contentSha256(target.content);
9028
+ const targetVersion = (target.version ?? 1) + 1;
9029
+ if (addressed)
9030
+ nextVersion = targetVersion;
9031
+ await tx.run(`INSERT INTO agent_memory_version (id, memory_id, version, content, contentHash, intent, operation, changedByAgentId, createdAt, updatedAt, created_by, updated_by)
9032
+ VALUES (?, ?, ?, ?, ?, ?, 'edit', ?, ?, ?, ?, ?)`, [
9033
+ crypto.randomUUID(),
9034
+ target.id,
9035
+ targetVersion,
9036
+ targetContent,
9037
+ targetHash,
9038
+ versionIntent,
9039
+ input.changedByAgentId ?? null,
9040
+ now,
9041
+ now,
9042
+ input.changedByAgentId ?? null,
9043
+ input.changedByAgentId ?? null
9044
+ ]);
9045
+ await tx.run(`UPDATE agent_memory
9046
+ SET content = ?, contentHash = ?, version = ?, updatedAt = ?, key = ?,
9047
+ expiresAt = CASE WHEN ? = 1 THEN NULL ELSE expiresAt END
9048
+ WHERE id = ?`, [
9049
+ targetContent,
9050
+ targetHash,
9051
+ targetVersion,
9052
+ now,
9053
+ moving ? input.newKey : target.key,
9054
+ clearExpiry ? 1 : 0,
9055
+ target.id
9056
+ ]);
9057
+ }
8922
9058
  return {
8923
9059
  result: {
8924
9060
  memory: rowToAgentMemory({
@@ -8926,14 +9062,16 @@ class SqliteMemoryStore {
8926
9062
  content: nextContent,
8927
9063
  contentHash: nextHash,
8928
9064
  version: nextVersion,
8929
- updatedAt: now
9065
+ updatedAt: now,
9066
+ key: moving ? input.newKey : row.key,
9067
+ expiresAt: clearExpiry ? null : row.expiresAt
8930
9068
  }),
8931
9069
  changed: true,
8932
9070
  previousVersion,
8933
9071
  version: nextVersion,
8934
9072
  contentHash: nextHash
8935
9073
  },
8936
- ftsContent: nextContent
9074
+ ftsContent: contentChanged ? nextContent : null
8937
9075
  };
8938
9076
  });
8939
9077
  if (ftsContent !== null) {
@@ -8944,12 +9082,13 @@ class SqliteMemoryStore {
8944
9082
  async listForCuration(agentId) {
8945
9083
  const db = getDbClient();
8946
9084
  const protectedList = [...PROTECTED_SOURCES].map((s) => `'${s}'`).join(",");
9085
+ const notLongterm = `coalesce(key, '') != '${LONGTERM_ROOT}' AND substr(coalesce(key, ''), 1, ${LONGTERM_ROOT.length + 1}) != '${LONGTERM_ROOT}/'`;
8947
9086
  if (agentId) {
8948
9087
  return db.query(`SELECT id, source, name, createdAt FROM agent_memory
8949
- WHERE agentId = ? AND source NOT IN (${protectedList})`, [agentId]);
9088
+ WHERE agentId = ? AND source NOT IN (${protectedList}) AND ${notLongterm}`, [agentId]);
8950
9089
  }
8951
9090
  return db.query(`SELECT id, source, name, createdAt FROM agent_memory
8952
- WHERE source NOT IN (${protectedList})`);
9091
+ WHERE source NOT IN (${protectedList}) AND ${notLongterm}`);
8953
9092
  }
8954
9093
  async listForReembedding(options) {
8955
9094
  const db = getDbClient();
@@ -9105,6 +9244,7 @@ var init_sqlite_store = __esm(() => {
9105
9244
  init_embedding();
9106
9245
  init_profile_sync();
9107
9246
  init_constants();
9247
+ init_key_paths();
9108
9248
  init_reranker();
9109
9249
  VECTOR_BYTES = EMBEDDING_DIMENSIONS * Float32Array.BYTES_PER_ELEMENT;
9110
9250
  });
@@ -9130,4 +9270,4 @@ function getMemoryStore() {
9130
9270
  return memoryStore;
9131
9271
  }
9132
9272
 
9133
- export { cosineSimilarity, serializeEmbedding, deserializeEmbedding, init_embedding, OpenAI, init_openai, CANDIDATE_SET_MULTIPLIER, isGraphExpansionEnabled, EMBEDDING_DIMENSIONS, init_constants, computeScore, rerank, init_reranker, rowToCandidate, init_sqlite_store, getEmbeddingProvider, resetEmbeddingProvider, getMemoryStore };
9273
+ export { cosineSimilarity, serializeEmbedding, deserializeEmbedding, init_embedding, OpenAI, init_openai, CANDIDATE_SET_MULTIPLIER, isGraphExpansionEnabled, EMBEDDING_DIMENSIONS, init_constants, LONGTERM_ROOT, MEMORY_KEY_PATTERN, MEMORY_KEY_PATTERN_MESSAGE, MEMORY_KEY_MAX_LENGTH, isLongtermKey, longtermKeyError, isConsolidatedKey, consolidatedKeyMessage, resolveStoreKey, init_key_paths, computeScore, rerank, init_reranker, rowToCandidate, init_sqlite_store, getEmbeddingProvider, resetEmbeddingProvider, getMemoryStore };