@desplega.ai/agent-swarm 1.157.0 → 1.158.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 (256) hide show
  1. package/dist/{acp-adapter-qhqrk4q0.js → acp-adapter-xaq4n6pc.js} +1 -1
  2. package/dist/{actions-9rrg0zxm.js → actions-p9hz5yat.js} +15 -15
  3. package/dist/{app-enysy1zd.js → app-g26wdcz6.js} +4 -4
  4. package/dist/{artifact-td4q4dch.js → artifact-3v5t9jtg.js} +1 -1
  5. package/dist/{assistant-zegamy48.js → assistant-wydfqkb3.js} +16 -16
  6. package/dist/{boot-reembed-r6shx5qx.js → boot-reembed-g5ckg9yb.js} +6 -6
  7. package/dist/{boot-reembed-zfxb937k.js → boot-reembed-se8zmdcp.js} +5 -5
  8. package/dist/{boot-scrub-logs-k5y0se6r.js → boot-scrub-logs-wfxqan61.js} +3 -3
  9. package/dist/{seed-pricing-vqxa06qf.js → boot-seeds-s3q01xj3.js} +10 -10
  10. package/dist/{claude-adapter-5yc7hxwv.js → claude-adapter-tv2x4f36.js} +7 -7
  11. package/dist/{claude-managed-adapter-ea2aga6w.js → claude-managed-adapter-41b2s7fd.js} +2 -2
  12. package/dist/{claude-sdk-session-j4ywn3xf.js → claude-sdk-session-t442qz6f.js} +8 -8
  13. package/dist/{cli-e781c6f9.js → cli-0xjkj1j7.js} +1 -0
  14. package/dist/{cli-58rgvkt4.js → cli-1hkrch3k.js} +2 -2
  15. package/dist/{cli-yscm6cv8.js → cli-20cj37vt.js} +1866 -9
  16. package/dist/{cli-h0wdadsx.js → cli-4198qc9v.js} +7 -3
  17. package/dist/{cli-awwphhcs.js → cli-47m6dkd3.js} +362 -126
  18. package/dist/{cli-wb2zvbfg.js → cli-53sz8gkz.js} +1 -1
  19. package/dist/{cli-005pze6s.js → cli-5d10vd2m.js} +1 -1
  20. package/dist/{cli-v53rbqp3.js → cli-65hjmev5.js} +57 -17
  21. package/dist/{cli-scwq51gn.js → cli-68w09sjw.js} +7 -1
  22. package/dist/{cli-s98skd5r.js → cli-7gtvvpbh.js} +4 -4
  23. package/dist/{cli-y3nxwx0t.js → cli-7s3syk22.js} +18 -11
  24. package/dist/{cli-74h6f2bp.js → cli-8qmme6vd.js} +2 -2
  25. package/dist/{cli-wsed24mk.js → cli-987hg0aa.js} +2 -2
  26. package/dist/{cli-9n76jszt.js → cli-9httdpyq.js} +1 -1
  27. package/dist/{cli-f3va018d.js → cli-aky8tctm.js} +26 -93
  28. package/dist/{cli-sgyqyyxe.js → cli-c07r9a2m.js} +2 -1
  29. package/dist/{cli-c41wjx0r.js → cli-fgqxwrpv.js} +291 -12
  30. package/dist/{cli-01vfmq8c.js → cli-ftfvggzx.js} +607 -164
  31. package/dist/{cli-ytxs7mn1.js → cli-g8djp6qe.js} +17 -0
  32. package/dist/{cli-avkd6mqv.js → cli-h967nb6r.js} +551 -0
  33. package/dist/{cli-r9ee9c4w.js → cli-j55n64b6.js} +23 -22
  34. package/dist/{cli-9p33cz9h.js → cli-j57qkrpq.js} +86 -28
  35. package/dist/{cli-tjmghmm5.js → cli-q67y4wzm.js} +6 -3
  36. package/dist/{cli-n6zq3kbd.js → cli-rj19hc34.js} +1 -1
  37. package/dist/{cli-jytrw2na.js → cli-rjehvrts.js} +4 -4
  38. package/dist/{cli-tpv97m71.js → cli-rqz8qbw7.js} +245 -75
  39. package/dist/{cli-p37sg0a9.js → cli-s8eet254.js} +1 -1
  40. package/dist/cli-t1ze64h3.js +811 -0
  41. package/dist/{cli-6jjzxv3b.js → cli-ws6rqycm.js} +3 -2
  42. package/dist/{cli-xf5b7y1f.js → cli-wscdvcqz.js} +13 -5
  43. package/dist/{cli-5j7bm4tb.js → cli-x24pshtq.js} +5 -5
  44. package/dist/{cli-nbp6m6gp.js → cli-xberxa1r.js} +51 -26
  45. package/dist/{cli-vx9p3qdt.js → cli-xhaeg2nc.js} +1 -1
  46. package/dist/cli.js +29 -15
  47. package/dist/{codex-adapter-gns3s6c3.js → codex-adapter-cnm8wk11.js} +5 -5
  48. package/dist/{codex-session-runner-gqnxys5w.js → codex-session-runner-gfg547zj.js} +5 -5
  49. package/dist/{commands-hxy2y2sp.js → commands-e3bn0p75.js} +3 -3
  50. package/dist/{db-w8ghhsgf.js → db-03v9kzr2.js} +17 -3
  51. package/dist/{dispatcher-cp1rknjz.js → dispatcher-nrmg8yht.js} +14 -14
  52. package/dist/{dsh-adapter-1dwg97zv.js → dsh-adapter-k03nfqa6.js} +2 -2
  53. package/dist/{handlers-egfhr351.js → handlers-aqcedbyb.js} +17 -17
  54. package/dist/{hook-x4kftwzt.js → hook-7vkskkre.js} +19 -11
  55. package/dist/{hook-fbxjqfjz.js → hook-ybvmrmhq.js} +4 -4
  56. package/dist/{http-c7jfx990.js → http-2eqa8t24.js} +432 -195
  57. package/dist/{index-4k9hct21.js → index-1yks3qcr.js} +14 -14
  58. package/dist/{index-jtvpgb8f.js → index-a3vn96n8.js} +30 -27
  59. package/dist/{index-dc2ek6bw.js → index-c6zsv1bd.js} +5 -5
  60. package/dist/{index-yy07ef2s.js → index-chgdkq36.js} +14 -14
  61. package/dist/{index-r6bty6tb.js → index-x71bvq0p.js} +15 -15
  62. package/dist/{keepalive-f7ekefyc.js → keepalive-vtkf5n99.js} +5 -5
  63. package/dist/{lead-h053syts.js → lead-h3sp357x.js} +26 -26
  64. package/dist/{maintenance-a3w6zs54.js → maintenance-jzeqtk3q.js} +6 -6
  65. package/dist/{oauth-refresh-sweep-vra1dhkd.js → oauth-refresh-sweep-qp3dzmdp.js} +4 -4
  66. package/dist/{onboard-mfgzeqxs.js → onboard-tmsp0qbz.js} +278 -81
  67. package/dist/{opencode-adapter-z64xjzec.js → opencode-adapter-x6x2da1z.js} +3 -3
  68. package/dist/{otel-impl-2ez6xk57.js → otel-impl-9mz73q65.js} +416 -301
  69. package/dist/{pi-mono-adapter-2b7mw16r.js → pi-mono-adapter-m6dvv0dz.js} +2 -2
  70. package/dist/{pricing-refresh-6sw65tck.js → pricing-refresh-v1cbr9te.js} +5 -5
  71. package/dist/{rbac-roles-nm6924sy.js → rbac-roles-c9wqz83x.js} +4 -4
  72. package/dist/{render-v2-f026j6c4.js → render-v2-gryrh9h8.js} +4 -4
  73. package/dist/{setup-w606fr1q.js → setup-q9720bt6.js} +2 -2
  74. package/dist/{virtual-modules-8qheft18.js → virtual-modules-3htpgn8x.js} +1 -1
  75. package/dist/{work-objects-ezmggdne.js → work-objects-b76x7deb.js} +17 -17
  76. package/dist/{worker-1mbyv29k.js → worker-6vrxbv41.js} +26 -26
  77. package/openapi.json +1626 -629
  78. package/package.json +2 -1
  79. package/src/apps/catalog.generated.json +229 -0
  80. package/src/apps/page-validator.ts +71 -16
  81. package/src/apps/row-store.ts +66 -11
  82. package/src/apps/sync.ts +59 -17
  83. package/src/artifact-sdk/browser-sdk.ts +436 -2
  84. package/src/be/approval-sweeps.ts +109 -0
  85. package/src/be/boot-seeds.ts +40 -0
  86. package/src/be/chunking.ts +1 -1
  87. package/src/be/db/agents.ts +20 -0
  88. package/src/be/db/approvals.ts +78 -0
  89. package/src/be/db/tasks/read.ts +197 -39
  90. package/src/be/db/tasks/write.ts +41 -9
  91. package/src/be/db-client.ts +107 -48
  92. package/src/be/db.ts +219 -76
  93. package/src/be/events.ts +33 -1
  94. package/src/be/memory/graph-expansion.ts +10 -3
  95. package/src/be/memory/providers/sqlite-store.ts +55 -13
  96. package/src/be/memory/raters/retrieval.ts +5 -2
  97. package/src/be/memory/reranker.ts +26 -2
  98. package/src/be/memory/types.ts +2 -0
  99. package/src/be/migrations/166_approval_request_auto_cancellation.sql +9 -0
  100. package/src/be/migrations/171_memory_retrieval_relevance.sql +8 -0
  101. package/src/be/migrations/175_workflow_runs_list_index.sql +11 -0
  102. package/src/be/migrations/177_events_event_agent_created_index.sql +11 -0
  103. package/src/be/models-catalog.ts +2 -0
  104. package/src/be/modelsdev-cache.json +1857 -0
  105. package/src/be/modelsdev-cache.ts +14 -1
  106. package/src/be/pricing-normalize.ts +2 -0
  107. package/src/be/scripts/typecheck.ts +1 -0
  108. package/src/be/seed-pricing.ts +3 -1
  109. package/src/be/seed-skills/bundled-files.generated.json +1 -1
  110. package/src/be/steering.ts +53 -3
  111. package/src/be/swarm-config-guard.ts +3 -0
  112. package/src/be/task-citations.ts +29 -0
  113. package/src/cli.tsx +14 -1
  114. package/src/commands/onboard/compose-generator.ts +8 -3
  115. package/src/commands/onboard/container-engine.ts +220 -0
  116. package/src/commands/onboard/manifest.ts +1 -0
  117. package/src/commands/onboard/steps/health-check.tsx +4 -1
  118. package/src/commands/onboard/steps/prereq-check.tsx +50 -54
  119. package/src/commands/onboard/steps/start.tsx +31 -16
  120. package/src/commands/onboard/types.ts +7 -2
  121. package/src/commands/onboard.tsx +39 -4
  122. package/src/commands/profile-sync.ts +79 -26
  123. package/src/commands/runner.ts +8 -1
  124. package/src/extensions/catalog.generated.json +17 -0
  125. package/src/extensions/contract-types.generated.ts +1 -1
  126. package/src/heartbeat/heartbeat.ts +263 -103
  127. package/src/hooks/hook.ts +21 -12
  128. package/src/http/agents.ts +35 -0
  129. package/src/http/approval-requests.ts +136 -64
  130. package/src/http/apps.ts +14 -3
  131. package/src/http/config.ts +15 -1
  132. package/src/http/events.ts +62 -2
  133. package/src/http/index.ts +6 -4
  134. package/src/http/memory.ts +21 -7
  135. package/src/http/schedules.ts +1 -1
  136. package/src/http/session-data.ts +9 -4
  137. package/src/http/sessions.ts +25 -18
  138. package/src/http/stats.ts +19 -7
  139. package/src/http/status.ts +11 -1
  140. package/src/http/tasks.ts +40 -8
  141. package/src/http/webhooks.ts +67 -46
  142. package/src/http/workflows.ts +15 -20
  143. package/src/linear/outbound.ts +37 -15
  144. package/src/otel-impl.ts +151 -1
  145. package/src/otel.ts +14 -3
  146. package/src/prompts/memories.ts +19 -2
  147. package/src/providers/claude-managed-models.ts +8 -0
  148. package/src/providers/modelsdev-reasoning.json +551 -0
  149. package/src/rbac/legacy-policy.ts +16 -0
  150. package/src/rbac/permissions.ts +4 -0
  151. package/src/scheduler/schedule-task.ts +3 -0
  152. package/src/scripts-runtime/sdk-allowlist.ts +1 -0
  153. package/src/scripts-runtime/swarm-sdk.ts +9 -0
  154. package/src/scripts-runtime/types/stdlib.d.ts +1 -0
  155. package/src/scripts-runtime/types/swarm-extension.d.ts +1 -0
  156. package/src/scripts-runtime/types/swarm-sdk.d.ts +1 -0
  157. package/src/server.ts +12 -7
  158. package/src/slack/app.ts +35 -4
  159. package/src/slack/connection-state.ts +17 -0
  160. package/src/tasks/context-key.ts +1 -0
  161. package/src/tasks/worker-follow-up.ts +6 -2
  162. package/src/tests/agent-task-activity.test.ts +74 -0
  163. package/src/tests/agents-list-model-display.test.ts +6 -1
  164. package/src/tests/approval-auto-cancellation-migration.test.ts +104 -0
  165. package/src/tests/approval-requests.test.ts +395 -0
  166. package/src/tests/approval-sweeps-config.test.ts +47 -0
  167. package/src/tests/approval-sweeps.test.ts +508 -0
  168. package/src/tests/apps-kibo-blocks.test.ts +77 -0
  169. package/src/tests/apps-spike.test.ts +56 -1
  170. package/src/tests/apps-sync-engine.test.ts +20 -9
  171. package/src/tests/boot-seeds.test.ts +170 -0
  172. package/src/tests/cancel-approval-request-tool.test.ts +115 -0
  173. package/src/tests/claude-managed-adapter.test.ts +6 -0
  174. package/src/tests/config-key-filter.test.ts +80 -0
  175. package/src/tests/context-window.test.ts +1 -0
  176. package/src/tests/db-client-busy-retry.test.ts +96 -0
  177. package/src/tests/db-client.test.ts +60 -1
  178. package/src/tests/db-task-read-contract.test.ts +10 -0
  179. package/src/tests/db-task-write-contract.test.ts +9 -0
  180. package/src/tests/docs-index-footprint.test.js +3 -3
  181. package/src/tests/events-http.test.ts +103 -0
  182. package/src/tests/extensions-catalog.test.ts +22 -17
  183. package/src/tests/extensions-pre-task.test.ts +107 -0
  184. package/src/tests/fixtures/kibo-blocks-definition.json.txt +105 -0
  185. package/src/tests/follow-up-config-inheritance.test.ts +260 -0
  186. package/src/tests/heartbeat-orphan-resume.test.ts +84 -0
  187. package/src/tests/heartbeat-reboot-live.test.ts +95 -0
  188. package/src/tests/heartbeat-stall-cas.test.ts +80 -0
  189. package/src/tests/heartbeat.test.ts +99 -3
  190. package/src/tests/hook-mcp-config.test.ts +29 -0
  191. package/src/tests/http-api-integration.test.ts +16 -2
  192. package/src/tests/kv-storage.test.ts +62 -0
  193. package/src/tests/linear-outbound-sync.test.ts +120 -5
  194. package/src/tests/list-endpoint-slimming.test.ts +91 -0
  195. package/src/tests/memory-graph-organic-route.test.ts +155 -0
  196. package/src/tests/memory-http-recall-gating.test.ts +14 -4
  197. package/src/tests/memory-hybrid.test.ts +161 -1
  198. package/src/tests/memory-prompt-recall-crowdout.test.ts +297 -0
  199. package/src/tests/memory.test.ts +22 -0
  200. package/src/tests/onboard-container-engine.test.ts +240 -0
  201. package/src/tests/otel-event-loop-and-logs.test.ts +99 -0
  202. package/src/tests/pricing-routes.test.ts +14 -0
  203. package/src/tests/profile-sync-warning.test.ts +8 -4
  204. package/src/tests/promote-draft-task-route.test.ts +19 -0
  205. package/src/tests/provider-registration.test.ts +296 -42
  206. package/src/tests/rbac-engine.test.ts +30 -0
  207. package/src/tests/reasoning-effort.test.ts +8 -0
  208. package/src/tests/script-connections.test.ts +7 -0
  209. package/src/tests/sdk-allowlist.test.ts +39 -0
  210. package/src/tests/session-costs-model-key-normalize.test.ts +1 -0
  211. package/src/tests/sessions-detail-batch.test.ts +250 -0
  212. package/src/tests/sessions.test.ts +118 -0
  213. package/src/tests/slack-config.test.ts +22 -0
  214. package/src/tests/sonnet-5-5-registry.test.ts +44 -0
  215. package/src/tests/status.test.ts +36 -1
  216. package/src/tests/swarm-diff.test.ts +316 -10
  217. package/src/tests/task-completion-idempotency.test.ts +2 -1
  218. package/src/tests/tasks-requested-by-filter.test.ts +3 -1
  219. package/src/tests/tool-annotations.test.ts +1 -1
  220. package/src/tests/ui-list-slim-projections.test.ts +158 -0
  221. package/src/tests/webhooks-task-blocked.test.ts +127 -0
  222. package/src/tests/workflow-approval-recovery.test.ts +203 -0
  223. package/src/tests/workflow-hitl-routing.test.ts +22 -1
  224. package/src/tests/workflow-hitl-slack-card.test.ts +52 -0
  225. package/src/tests/workflow-http-v2.test.ts +99 -8
  226. package/src/tests/workflow-retry-validation.test.ts +56 -0
  227. package/src/tests/workflow-tla-races.test.ts +389 -0
  228. package/src/tests/workflow-validation-port-routing.test.ts +113 -1
  229. package/src/tools/cancel-approval-request.ts +57 -0
  230. package/src/tools/memory-search.ts +1 -0
  231. package/src/tools/request-human-input.ts +4 -2
  232. package/src/tools/send-task.ts +4 -0
  233. package/src/tools/templates.ts +19 -0
  234. package/src/tools/tool-config.ts +2 -1
  235. package/src/tools/workflows/list-workflow-runs.ts +1 -0
  236. package/src/types.ts +38 -0
  237. package/src/utils/context-window.ts +1 -0
  238. package/src/workflows/approval-cancel.ts +152 -0
  239. package/src/workflows/approval-notifications.ts +84 -0
  240. package/src/workflows/checkpoint.ts +10 -5
  241. package/src/workflows/definition.ts +21 -0
  242. package/src/workflows/engine.ts +152 -21
  243. package/src/workflows/executors/human-in-the-loop.ts +1 -1
  244. package/src/workflows/recovery.ts +100 -45
  245. package/src/workflows/resume.ts +49 -18
  246. package/src/workflows/retry-poller.ts +71 -21
  247. package/templates/extensions/README.md +1 -0
  248. package/templates/extensions/github-sender-allowlist/README.md +18 -0
  249. package/templates/extensions/github-sender-allowlist/hooks.ts +55 -0
  250. package/templates/extensions/github-sender-allowlist/manifest.json +8 -0
  251. package/templates/skills/apps/content.md +20 -1
  252. package/templates/skills/code-quality/content.md +26 -1
  253. package/templates/skills/pages/content.md +16 -4
  254. package/templates/skills/pages/files/examples/multiplayer-board.html +3 -12
  255. package/dist/cli-2daksqps.js +0 -378
  256. package/dist/rbac-roles-3gxmnb20.js +0 -37
@@ -117,6 +117,20 @@ export function computeRrfScore(rank: number, decayFactor: number, k = 60): numb
117
117
  return (1 / (k + rank + 1)) * decayFactor;
118
118
  }
119
119
 
120
+ /**
121
+ * Hybrid score on the vec arm's [0,1] cosine scale.
122
+ *
123
+ * Raw RRF tops out at 2/(k+1) ≈ 0.033 and is rank-based, so the best row of
124
+ * an unrelated query scores the same as an exact hit. The cosine is the
125
+ * absolute relevance signal; RRF, normalised to (0,1] by its two-arm maximum,
126
+ * scales it by keyword/semantic agreement: rank 1 in both arms keeps the full
127
+ * cosine, rank 1 in one arm keeps 75%, and no factor drops below 50%.
128
+ */
129
+ export function fusedSimilarity(cosine: number, rrfScore: number, k = 60): number {
130
+ const agreement = Math.min(1, (rrfScore * (k + 1)) / 2);
131
+ return cosine * (0.5 + 0.5 * agreement);
132
+ }
133
+
120
134
  /**
121
135
  * Compute the next content for a memory edit. Returns the new content string.
122
136
  * Throws if validation fails (missing fields, oldString not found, ambiguous match).
@@ -563,38 +577,66 @@ export class SqliteMemoryStore implements MemoryStore {
563
577
  ...options,
564
578
  limit: overfetchLimit,
565
579
  });
566
- if (ftsCandidates.length === 0) return vectorCandidates.slice(0, options.limit);
567
580
 
568
581
  const byId = new Map<string, MemoryCandidate>();
569
- const scores = new Map<string, number>();
582
+ const rrf = new Map<string, number>();
583
+ const cosines = new Map<string, number>();
570
584
  const sources = new Map<string, Set<MemoryRetrievalSource>>();
571
- const now = new Date();
572
585
  const add = (candidate: MemoryCandidate, rank: number) => {
573
586
  byId.set(candidate.id, byId.get(candidate.id) ?? candidate);
574
587
  const retrievalSource = candidate.retrievalSource === "fts" ? "fts" : "vec";
575
588
  const candidateSources = sources.get(candidate.id) ?? new Set<MemoryRetrievalSource>();
576
589
  candidateSources.add(retrievalSource);
577
590
  sources.set(candidate.id, candidateSources);
578
-
579
- const decay = recencyDecay(candidate.createdAt, now, candidate.source);
580
- scores.set(candidate.id, (scores.get(candidate.id) ?? 0) + computeRrfScore(rank, decay));
591
+ if (retrievalSource === "vec") cosines.set(candidate.id, candidate.similarity);
592
+ rrf.set(candidate.id, (rrf.get(candidate.id) ?? 0) + computeRrfScore(rank, 1.0));
581
593
  };
582
594
 
583
595
  vectorCandidates.forEach(add);
584
596
  ftsCandidates.forEach(add);
597
+ await this.fillCosines(queryEmbedding, [...byId.keys()], cosines);
585
598
 
599
+ // Fused score on the same [0,1] scale as the vec arm's cosine, so graph
600
+ // neighbours (derived from it) and the injection threshold compare
601
+ // like with like. Recency decay is left to rerank(), as on the vec path.
586
602
  return [...byId.values()]
587
- .map((candidate) => ({
588
- ...candidate,
589
- rawSimilarity: candidate.rawSimilarity ?? candidate.similarity,
590
- similarity: scores.get(candidate.id) ?? candidate.similarity,
591
- retrievalSource: retrievalSourceFor(sources.get(candidate.id) ?? new Set()),
592
- recencyDecayApplied: true,
593
- }))
603
+ .map((candidate) => {
604
+ const similarity = fusedSimilarity(
605
+ cosines.get(candidate.id) ?? 0,
606
+ rrf.get(candidate.id) ?? 0,
607
+ );
608
+ return {
609
+ ...candidate,
610
+ rawSimilarity: similarity,
611
+ similarity,
612
+ retrievalSource: retrievalSourceFor(sources.get(candidate.id) ?? new Set()),
613
+ recencyDecayApplied: false,
614
+ };
615
+ })
594
616
  .sort((a, b) => b.similarity - a.similarity)
595
617
  .slice(0, options.limit);
596
618
  }
597
619
 
620
+ /** Cosine to the query for FTS-only candidates, read from the stored embedding. */
621
+ private async fillCosines(
622
+ queryEmbedding: Float32Array,
623
+ ids: string[],
624
+ cosines: Map<string, number>,
625
+ ): Promise<void> {
626
+ const missing = ids.filter((id) => !cosines.has(id));
627
+ if (missing.length === 0) return;
628
+ const rows = await getDbClient().query<{ id: string; embedding: Buffer | null }>(
629
+ `SELECT id, embedding FROM agent_memory WHERE id IN (${missing.map(() => "?").join(",")})`,
630
+ missing,
631
+ );
632
+ for (const row of rows) {
633
+ if (!row.embedding) continue;
634
+ const embedding = deserializeEmbedding(row.embedding);
635
+ if (embedding.length !== queryEmbedding.length) continue;
636
+ cosines.set(row.id, Math.max(0, cosineSimilarity(queryEmbedding, embedding)));
637
+ }
638
+ }
639
+
598
640
  private async searchFts(
599
641
  queryText: string,
600
642
  agentId: string,
@@ -24,6 +24,8 @@ import type { AgentMemory } from "@/types";
24
24
  export type RetrievalRecord = {
25
25
  memoryId: string;
26
26
  similarity: number;
27
+ /** Pre-boost [0,1] match score (`rawSimilarity`); the injection gate's input. */
28
+ relevance?: number;
27
29
  retrievalSource?: MemoryRetrievalSource;
28
30
  };
29
31
 
@@ -82,8 +84,8 @@ export async function recordRetrievals(
82
84
  if (!taskId || results.length === 0) return;
83
85
 
84
86
  const insertSql = `INSERT INTO memory_retrieval
85
- (id, taskId, agentId, sessionId, memoryId, similarity, retrievedAt, contextKey, intent, eventType, retrievalId, rank, retrievalSource)
86
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
87
+ (id, taskId, agentId, sessionId, memoryId, similarity, retrievedAt, contextKey, intent, eventType, retrievalId, rank, retrievalSource, relevance)
88
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
87
89
  const now = new Date().toISOString();
88
90
  const retrievalId = crypto.randomUUID();
89
91
  const contextKey = extras?.contextKey ?? null;
@@ -106,6 +108,7 @@ export async function recordRetrievals(
106
108
  retrievalId,
107
109
  rank,
108
110
  r.retrievalSource ?? null,
111
+ r.relevance ?? null,
109
112
  ]);
110
113
  }
111
114
  });
@@ -89,13 +89,37 @@ export function computeScore(candidate: MemoryCandidate, now: Date): number {
89
89
  * Rerank candidates by combining similarity with recency, source quality,
90
90
  * and access signals. Returns the top `limit` candidates sorted by composite
91
91
  * score. Preserves raw similarity in `rawSimilarity` and sets `compositeScore`.
92
+ *
93
+ * A graph candidate's composite is capped at its parent's: the neighbour
94
+ * carries its own access/source/usefulness boosts, and without the cap a few
95
+ * boosted neighbours can push the direct hit that surfaced them out of the
96
+ * result set. Ties go to the higher `rawSimilarity`, so the parent sorts first.
92
97
  */
93
98
  export function rerank(candidates: MemoryCandidate[], options: RerankOptions): MemoryCandidate[] {
94
99
  const { limit, now = new Date() } = options;
95
100
 
101
+ const uncapped = new Map<string, number>();
102
+ for (const candidate of candidates) uncapped.set(candidate.id, computeScore(candidate, now));
103
+ const byId = new Map(candidates.map((c) => [c.id, c]));
104
+ const capped = new Map<string, number>();
105
+ // Walks the parent chain (a parent can itself be a graph entry that replaced
106
+ // an organic duplicate); `seen` guards against a link cycle.
107
+ const cappedScore = (candidate: MemoryCandidate, seen: Set<string>): number => {
108
+ const cached = capped.get(candidate.id);
109
+ if (cached !== undefined) return cached;
110
+ let score = uncapped.get(candidate.id)!;
111
+ const parent = candidate.graphParentId ? byId.get(candidate.graphParentId) : undefined;
112
+ if (parent && !seen.has(parent.id)) {
113
+ seen.add(candidate.id);
114
+ score = Math.min(score, cappedScore(parent, seen));
115
+ }
116
+ capped.set(candidate.id, score);
117
+ return score;
118
+ };
119
+
96
120
  const scored = candidates.map((candidate) => {
97
121
  const rawSimilarity = candidate.rawSimilarity ?? candidate.similarity;
98
- const compositeScore = computeScore(candidate, now);
122
+ const compositeScore = cappedScore(candidate, new Set());
99
123
  return {
100
124
  ...candidate,
101
125
  rawSimilarity,
@@ -104,6 +128,6 @@ export function rerank(candidates: MemoryCandidate[], options: RerankOptions): M
104
128
  };
105
129
  });
106
130
 
107
- scored.sort((a, b) => b.similarity - a.similarity);
131
+ scored.sort((a, b) => b.similarity - a.similarity || b.rawSimilarity - a.rawSimilarity);
108
132
  return scored.slice(0, limit);
109
133
  }
@@ -72,6 +72,8 @@ export interface MemoryCandidate extends AgentMemory {
72
72
  compositeScore?: number;
73
73
  /** Search arm that surfaced the candidate. Memory `source` remains manual/file_index/etc. */
74
74
  retrievalSource?: MemoryRetrievalSource;
75
+ /** Graph candidates only: the candidate whose link surfaced this one. rerank() never ranks it above that parent. */
76
+ graphParentId?: string;
75
77
  /** True when `similarity` already includes source-aware recency decay. */
76
78
  recencyDecayApplied?: boolean;
77
79
  accessCount: number;
@@ -0,0 +1,9 @@
1
+ -- Approval request auto-cancellation. The heartbeat sweep cancels pending
2
+ -- requests with no expiresAt whose createdAt is older than
3
+ -- APPROVAL_REQUEST_AUTO_CANCELLATION_DAYS. Requests with an expiresAt use
4
+ -- the existing partial index on expiresAt and become 'timeout' instead.
5
+ -- The status 'cancelled' and the resolutionReason column exist since
6
+ -- migration 140. This migration adds the index for the auto-cancel predicate.
7
+ CREATE INDEX IF NOT EXISTS idx_approval_requests_pending_created
8
+ ON approval_requests(createdAt)
9
+ WHERE status = 'pending' AND expiresAt IS NULL;
@@ -0,0 +1,8 @@
1
+ -- Record the pre-boost relevance each memory_retrieval row was gated on.
2
+ --
3
+ -- `similarity` stays the reranker's composite score (it includes recency,
4
+ -- access, source-quality and usefulness multipliers, so it is not bounded).
5
+ -- `relevance` is the [0,1] match score the pre-task injection threshold
6
+ -- compares against. Existing rows stay NULL.
7
+
8
+ ALTER TABLE memory_retrieval ADD COLUMN relevance REAL;
@@ -0,0 +1,11 @@
1
+ -- GET /api/workflows/{id}/runs and the list-workflow-runs tool list one
2
+ -- workflow's runs newest first, optionally for one status, and count them for
3
+ -- page metadata. idx_workflow_runs_workflowId finds the rows but leaves SQLite
4
+ -- to sort every run of the workflow first (7k rows for the largest one), and
5
+ -- idx_workflow_runs_status makes a status-filtered page or count walk that
6
+ -- status across every workflow. These two return a page already in order and
7
+ -- count from the index alone.
8
+ CREATE INDEX IF NOT EXISTS idx_workflow_runs_workflow_started
9
+ ON workflow_runs(workflowId, startedAt DESC, id DESC);
10
+ CREATE INDEX IF NOT EXISTS idx_workflow_runs_workflow_status_started
11
+ ON workflow_runs(workflowId, status, startedAt DESC, id DESC);
@@ -0,0 +1,11 @@
1
+ -- Profile-sync banner (fetchProfileSyncRejectionBanner, src/commands/profile-sync.ts).
2
+ --
3
+ -- Every worker session start or resume looks up the latest
4
+ -- system.profile_sync_rejected / system.profile_sync_reconciled event per
5
+ -- identity field for its own agent: `event IN (...) AND agentId = ?`, newest
6
+ -- first. With only single-column indexes SQLite picked one of idx_events_event
7
+ -- or idx_events_agentId and scanned every candidate row, synchronously on the
8
+ -- API's event loop. This index seeks straight to the agent's rows for each
9
+ -- event name, already in createdAt order.
10
+ CREATE INDEX IF NOT EXISTS idx_events_event_agent_created
11
+ ON events(event, agentId, createdAt DESC);
@@ -36,6 +36,8 @@ export type CatalogProviderId = (typeof CATALOG_PROVIDER_IDS)[number];
36
36
  export const PINNED_MODELSDEV_ENTRIES = [
37
37
  // Official launch metadata; retain until models.dev catches up. Verified 2026-09-22.
38
38
  "anthropic/claude-opus-5-5",
39
+ // Official launch metadata; retain until models.dev catches up. Verified 2026-09-28.
40
+ "anthropic/claude-sonnet-5-5",
39
41
  "anthropic/claude-mythos-5",
40
42
  "anthropic/claude-sonnet-5",
41
43
  "amazon-bedrock/anthropic.claude-sonnet-5",