@vellumai/assistant 0.11.9 → 0.11.10-dev.202609091114.7b6342c

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 (433) hide show
  1. package/ARCHITECTURE.md +2 -2
  2. package/Dockerfile +6 -12
  3. package/docs/architecture/memory.md +17 -9
  4. package/docs/guardian-request-flow.md +7 -4
  5. package/docs/runbook-trusted-contacts.md +13 -2
  6. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/package.json +3 -1
  7. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/plan-credit.test.ts +51 -0
  8. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/secret-detection.test.ts +2 -0
  9. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/desktop-presence.ts +11 -0
  10. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
  11. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/plan-credit.ts +66 -0
  12. package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/secret-detection.ts +7 -0
  13. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/package.json +3 -1
  14. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/plan-credit.test.ts +51 -0
  15. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/secret-detection.test.ts +2 -0
  16. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/desktop-presence.ts +11 -0
  17. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
  18. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/plan-credit.ts +66 -0
  19. package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/secret-detection.ts +7 -0
  20. package/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +72 -0
  21. package/node_modules/@vellumai/service-contracts/package.json +3 -1
  22. package/node_modules/@vellumai/service-contracts/src/__tests__/plan-credit.test.ts +51 -0
  23. package/node_modules/@vellumai/service-contracts/src/__tests__/secret-detection.test.ts +2 -0
  24. package/node_modules/@vellumai/service-contracts/src/desktop-presence.ts +11 -0
  25. package/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
  26. package/node_modules/@vellumai/service-contracts/src/plan-credit.ts +66 -0
  27. package/node_modules/@vellumai/service-contracts/src/secret-detection.ts +7 -0
  28. package/openapi.yaml +729 -63
  29. package/package.json +1 -1
  30. package/src/__tests__/agent-loop-mutable-latest-user-message.test.ts +19 -21
  31. package/src/__tests__/assistant-event-hub-machine-name.test.ts +40 -0
  32. package/src/__tests__/assistant-event-hub.test.ts +45 -0
  33. package/src/__tests__/cli-memory-v2-reembed-skills.test.ts +0 -1
  34. package/src/__tests__/compactor-assistant-tail-preview.test.ts +111 -0
  35. package/src/__tests__/compactor-tail-resolution.test.ts +116 -0
  36. package/src/__tests__/computer-use-native-history.test.ts +30 -0
  37. package/src/__tests__/computer-use-window-schema.test.ts +24 -0
  38. package/src/__tests__/config-get-vision-flag.test.ts +36 -0
  39. package/src/__tests__/config-loader-validation-reset-notice.test.ts +47 -15
  40. package/src/__tests__/context-search-conversations-source.test.ts +27 -5
  41. package/src/__tests__/conversation-agent-loop-overflow.test.ts +189 -195
  42. package/src/__tests__/conversation-agent-loop.test.ts +690 -50
  43. package/src/__tests__/conversation-fork-crud.test.ts +132 -45
  44. package/src/__tests__/conversation-fork-retrospective.test.ts +9 -7
  45. package/src/__tests__/conversation-lifecycle.test.ts +684 -10
  46. package/src/__tests__/conversation-pairing.test.ts +10 -9
  47. package/src/__tests__/conversation-runtime-assembly.test.ts +288 -1
  48. package/src/__tests__/conversation-surfaces-history-restored-completion.test.ts +21 -4
  49. package/src/__tests__/conversation-surfaces-point-at-budget.test.ts +150 -0
  50. package/src/__tests__/conversation-surfaces-point-at-capability.test.ts +161 -0
  51. package/src/__tests__/copy-composer-tc-templates.test.ts +2 -2
  52. package/src/__tests__/credential-security-invariants.test.ts +1 -0
  53. package/src/__tests__/delivered-post-record.test.ts +107 -0
  54. package/src/__tests__/guardian-action-service-scope.test.ts +53 -0
  55. package/src/__tests__/guardian-question-mode.test.ts +88 -138
  56. package/src/__tests__/headless-browser-mode.test.ts +63 -13
  57. package/src/__tests__/heartbeat-disk-pressure.test.ts +2 -0
  58. package/src/__tests__/heartbeat-service.test.ts +118 -27
  59. package/src/__tests__/host-cu-proxy.test.ts +159 -1
  60. package/src/__tests__/host-proxy-interface.test.ts +15 -0
  61. package/src/__tests__/host-proxy-preactivation.test.ts +61 -0
  62. package/src/__tests__/injector-chain.test.ts +3 -3
  63. package/src/__tests__/injector-registry-order-guard.test.ts +1 -1
  64. package/src/__tests__/injector-v3-suppression.test.ts +587 -45
  65. package/src/__tests__/llm-schema.test.ts +70 -2
  66. package/src/__tests__/logger.test.ts +33 -32
  67. package/src/__tests__/mcp-config-secret-boundary.test.ts +2 -0
  68. package/src/__tests__/memory-config-file-parity.test.ts +18 -0
  69. package/src/__tests__/memory-retrieval-hook.test.ts +53 -3
  70. package/src/__tests__/messages-read-boundary-guard.test.ts +0 -1
  71. package/src/__tests__/messaging-send-tool.test.ts +251 -128
  72. package/src/__tests__/messaging-shared.test.ts +19 -0
  73. package/src/__tests__/notification-decision-fallback.test.ts +98 -76
  74. package/src/__tests__/notification-decision-strategy.test.ts +10 -38
  75. package/src/__tests__/notification-events-source-context-probe.test.ts +211 -0
  76. package/src/__tests__/openai-responses-prompt-cache.test.ts +7 -2
  77. package/src/__tests__/openai-responses-provider.test.ts +42 -0
  78. package/src/__tests__/outlook-messaging-provider.test.ts +9 -0
  79. package/src/__tests__/platform-callback-registration.test.ts +162 -3
  80. package/src/__tests__/plugin-api-webhook-url.test.ts +66 -4
  81. package/src/__tests__/plugin-import-boundary-guard.test.ts +1 -0
  82. package/src/__tests__/pricing.test.ts +29 -0
  83. package/src/__tests__/prompt-cache-cross-turn-stability.test.ts +63 -3
  84. package/src/__tests__/scheduler-result-notification.test.ts +209 -0
  85. package/src/__tests__/strip-memory-injections.test.ts +75 -27
  86. package/src/__tests__/tool-approval-seed-content-blocks.test.ts +4 -13
  87. package/src/acp/auto-install.test.ts +35 -1
  88. package/src/acp/resolve-agent.test.ts +3 -3
  89. package/src/agent/loop.ts +116 -45
  90. package/src/api/constants/personality-sliders.test.ts +21 -0
  91. package/src/api/constants/personality-sliders.ts +64 -0
  92. package/src/api/events/contact-record-request.ts +16 -4
  93. package/src/api/events/contact-request.ts +10 -1
  94. package/src/api/index.ts +12 -0
  95. package/src/api/responses/memory-v3-selection-log.ts +64 -13
  96. package/src/api/surfaces.ts +6 -5
  97. package/src/background-wake/next-wake.test.ts +13 -0
  98. package/src/background-wake/next-wake.ts +4 -2
  99. package/src/calls/__tests__/voice-session-bridge.test.ts +166 -0
  100. package/src/calls/__tests__/voice-turn-sight-hold.test.ts +301 -0
  101. package/src/calls/voice-session-bridge.ts +162 -1
  102. package/src/calls/voice-triage-escalate.ts +1 -1
  103. package/src/channels/types.ts +14 -0
  104. package/src/cli/__tests__/catalog-search-help.test.ts +1 -0
  105. package/src/cli/__tests__/contacts-address-prompt-cli.test.ts +701 -0
  106. package/src/cli/__tests__/contacts-record-prompt-cli.test.ts +276 -15
  107. package/src/cli/__tests__/roadmap-cli.test.ts +313 -0
  108. package/src/cli/__tests__/run-assistant-command.ts +59 -20
  109. package/src/cli/commands/__tests__/conversations-slack.test.ts +12 -0
  110. package/src/cli/commands/__tests__/plugins-search.test.ts +81 -0
  111. package/src/cli/commands/config.help.ts +3 -1
  112. package/src/cli/commands/contacts.help.ts +179 -12
  113. package/src/cli/commands/contacts.ts +442 -47
  114. package/src/cli/commands/memory/worker.ts +1 -1
  115. package/src/cli/commands/platform/__tests__/credits-format.test.ts +152 -0
  116. package/src/cli/commands/platform/__tests__/credits.test.ts +20 -0
  117. package/src/cli/commands/platform/credits-format.ts +108 -0
  118. package/src/cli/commands/platform/index.help.ts +33 -11
  119. package/src/cli/commands/platform/index.ts +7 -18
  120. package/src/cli/commands/plugins.help.ts +4 -1
  121. package/src/cli/commands/plugins.ts +2 -1
  122. package/src/cli/commands/roadmap.help.ts +171 -0
  123. package/src/cli/commands/roadmap.ts +358 -0
  124. package/src/cli/index.help.ts +2 -0
  125. package/src/cli/lib/__tests__/cli-output.test.ts +5 -0
  126. package/src/cli/lib/cli-output.ts +6 -6
  127. package/src/cli/program.ts +2 -0
  128. package/src/config/__tests__/webhook-routing.test.ts +42 -0
  129. package/src/config/acp-defaults.test.ts +3 -3
  130. package/src/config/acp-defaults.ts +5 -5
  131. package/src/config/bundled-skills/acp/SKILL.md +8 -11
  132. package/src/config/bundled-skills/computer-use/SKILL.md +21 -0
  133. package/src/config/bundled-skills/computer-use/TOOLS.json +6 -0
  134. package/src/config/bundled-skills/contacts/SKILL.md +61 -11
  135. package/src/config/bundled-skills/messaging/SKILL.md +2 -0
  136. package/src/config/bundled-skills/messaging/TOOLS.json +4 -4
  137. package/src/config/bundled-skills/messaging/tools/messaging-send.ts +160 -36
  138. package/src/config/bundled-skills/messaging/tools/shared.ts +6 -0
  139. package/src/config/bundled-skills/schedule/SKILL.md +10 -2
  140. package/src/config/bundled-skills/screen-annotation/SKILL.md +80 -0
  141. package/src/config/bundled-skills/screen-annotation/TOOLS.json +73 -0
  142. package/src/config/bundled-skills/screen-annotation/tools/screen-annotation.test.ts +74 -0
  143. package/src/config/bundled-skills/screen-annotation/tools/screen-clear-marks.ts +33 -0
  144. package/src/config/bundled-skills/screen-annotation/tools/screen-point-at.ts +25 -0
  145. package/src/config/env-registry.ts +2 -0
  146. package/src/config/feature-flag-registry.json +39 -7
  147. package/src/config/input-modalities.test.ts +71 -0
  148. package/src/config/input-modalities.ts +95 -0
  149. package/src/config/loader.ts +2 -0
  150. package/src/config/schemas/__tests__/memory-v3.test.ts +58 -15
  151. package/src/config/schemas/heartbeat.ts +3 -3
  152. package/src/config/schemas/llm.ts +47 -10
  153. package/src/config/schemas/memory-storage.test.ts +39 -0
  154. package/src/config/schemas/memory-storage.ts +21 -0
  155. package/src/config/schemas/memory-v3.ts +73 -46
  156. package/src/config/schemas/services.ts +18 -0
  157. package/src/config/webhook-routing.ts +12 -2
  158. package/src/context/compactor.ts +12 -13
  159. package/src/context/strip-injections.ts +29 -25
  160. package/src/context/token-estimator.ts +2 -2
  161. package/src/daemon/__tests__/embedding-reconcile.test.ts +77 -0
  162. package/src/daemon/__tests__/lifecycle-embedding-reconcile.test.ts +3 -0
  163. package/src/daemon/__tests__/turn-actor.test.ts +68 -0
  164. package/src/daemon/conversation-agent-loop-handlers.ts +152 -22
  165. package/src/daemon/conversation-agent-loop.ts +19 -3
  166. package/src/daemon/conversation-messaging.ts +3 -2
  167. package/src/daemon/conversation-runtime-assembly.ts +191 -69
  168. package/src/daemon/conversation-surfaces.ts +32 -62
  169. package/src/daemon/conversation.ts +153 -46
  170. package/src/daemon/embedding-reconcile.ts +64 -1
  171. package/src/daemon/handlers/config-embeddings.ts +31 -0
  172. package/src/daemon/host-cu-proxy.ts +66 -50
  173. package/src/daemon/host-cu-target.ts +139 -0
  174. package/src/daemon/host-proxy-preactivation.ts +29 -1
  175. package/src/daemon/mcp-reload-service.ts +6 -0
  176. package/src/daemon/providers-setup.ts +5 -26
  177. package/src/daemon/trust-context.ts +1 -1
  178. package/src/daemon/turn-actor.ts +46 -0
  179. package/src/heartbeat/heartbeat-service.ts +72 -13
  180. package/src/inbound/platform-callback-registration.ts +77 -11
  181. package/src/inbound/pod-webhook-claim.ts +35 -0
  182. package/src/inbound/velay-webhooks-gate.ts +20 -0
  183. package/src/ipc/gateway-client.ts +91 -0
  184. package/src/live-voice/__tests__/live-voice-photo.test.ts +174 -0
  185. package/src/live-voice/__tests__/live-voice-session-guardian.test.ts +127 -0
  186. package/src/live-voice/__tests__/live-voice-session-telemetry.test.ts +42 -2
  187. package/src/live-voice/__tests__/live-voice-sight-frame.test.ts +81 -0
  188. package/src/live-voice/__tests__/protocol.test.ts +67 -0
  189. package/src/live-voice/live-voice-connection.ts +14 -1
  190. package/src/live-voice/live-voice-photo.ts +109 -4
  191. package/src/live-voice/live-voice-session-manager.ts +10 -1
  192. package/src/live-voice/live-voice-session.ts +196 -31
  193. package/src/live-voice/protocol.ts +134 -1
  194. package/src/mcp/__tests__/reload-signal-emission.test.ts +54 -0
  195. package/src/mcp/__tests__/reload-signal.test.ts +57 -0
  196. package/src/mcp/__tests__/startup.test.ts +150 -0
  197. package/src/mcp/reload-signal.ts +50 -0
  198. package/src/mcp/startup.ts +101 -0
  199. package/src/messaging/providers/outlook/adapter.ts +2 -13
  200. package/src/messaging/providers/outlook/client.ts +13 -1
  201. package/src/messaging/providers/outlook/types.ts +3 -0
  202. package/src/messaging/providers/telegram-bot/adapter.ts +9 -2
  203. package/src/messaging/providers/telegram-bot/client.ts +8 -2
  204. package/src/messaging/providers/whatsapp/adapter.ts +9 -2
  205. package/src/messaging/providers/whatsapp/client.ts +8 -2
  206. package/src/notifications/AGENTS.md +5 -0
  207. package/src/notifications/README.md +21 -7
  208. package/src/notifications/__tests__/assistant-reply-producer.test.ts +3 -10
  209. package/src/notifications/__tests__/background-failure-signal.test.ts +96 -0
  210. package/src/notifications/__tests__/broadcaster.test.ts +171 -7
  211. package/src/notifications/__tests__/decision-engine.test.ts +79 -6
  212. package/src/notifications/__tests__/edit-notification.test.ts +59 -0
  213. package/src/notifications/__tests__/resolve-visible-in-source.test.ts +96 -0
  214. package/src/notifications/__tests__/schedule-result-producer.test.ts +397 -0
  215. package/src/notifications/access-request-copy.ts +5 -5
  216. package/src/notifications/approval-card-data.ts +29 -13
  217. package/src/notifications/assistant-reply-producer.ts +0 -4
  218. package/src/notifications/background-failure-signal.ts +13 -1
  219. package/src/notifications/broadcaster.ts +65 -2
  220. package/src/notifications/conversation-pairing.ts +263 -155
  221. package/src/notifications/copy-composer.ts +38 -22
  222. package/src/notifications/decision-engine.ts +89 -61
  223. package/src/notifications/delivered-post-record.ts +81 -0
  224. package/src/notifications/deliveries-store.ts +8 -1
  225. package/src/notifications/edit-notification.ts +16 -0
  226. package/src/notifications/events-store.ts +68 -2
  227. package/src/notifications/guardian-question-mode.ts +24 -232
  228. package/src/notifications/home-feed-side-effect.ts +1 -0
  229. package/src/notifications/notification-utils.ts +13 -5
  230. package/src/notifications/resolve-visible-in-source.ts +56 -0
  231. package/src/notifications/schedule-result-producer.ts +275 -0
  232. package/src/notifications/signal.ts +5 -0
  233. package/src/oauth/__tests__/seed-providers-managed.test.ts +82 -0
  234. package/src/oauth/seed-providers.ts +201 -3
  235. package/src/onboarding/onboarding-events-store.ts +14 -8
  236. package/src/persistence/conversation-crud.ts +68 -19
  237. package/src/persistence/embeddings/embedding-backend.test.ts +162 -0
  238. package/src/persistence/embeddings/embedding-backend.ts +148 -11
  239. package/src/persistence/embeddings/embedding-gemini.test.ts +328 -9
  240. package/src/persistence/embeddings/embedding-gemini.ts +211 -27
  241. package/src/persistence/embeddings/embedding-openai.test.ts +113 -0
  242. package/src/persistence/embeddings/embedding-openai.ts +55 -4
  243. package/src/persistence/embeddings/embedding-types.test.ts +24 -0
  244. package/src/persistence/embeddings/embedding-types.ts +25 -1
  245. package/src/persistence/job-utils.ts +6 -2
  246. package/src/persistence/message-metadata.ts +20 -0
  247. package/src/persistence/migrations/283-memory-v3-selections-message-id-and-sections.ts +2 -1
  248. package/src/persistence/migrations/376-notification-deliveries-canonical-message-id.ts +37 -0
  249. package/src/persistence/schema/memory-injection.ts +31 -9
  250. package/src/persistence/schema/notifications.ts +8 -0
  251. package/src/persistence/steps.ts +2 -0
  252. package/src/plugin-api/index.ts +2 -1
  253. package/src/plugin-api/vision-support.test.ts +81 -0
  254. package/src/plugin-api/vision-support.ts +57 -10
  255. package/src/plugin-api/webhook-url.ts +18 -4
  256. package/src/plugins/AGENTS.md +1 -1
  257. package/src/plugins/defaults/channel/injectors.ts +3 -1
  258. package/src/plugins/defaults/injector-order.ts +2 -2
  259. package/src/plugins/defaults/memory/AGENTS.md +263 -30
  260. package/src/plugins/defaults/memory/__tests__/conversation-memory-orphan-sweep.test.ts +4 -0
  261. package/src/plugins/defaults/memory/__tests__/conversation-memory-purge.test.ts +6 -0
  262. package/src/plugins/defaults/memory/__tests__/db-memory-attach.test.ts +9 -3
  263. package/src/plugins/defaults/memory/__tests__/memory-log-stores-degraded.test.ts +3 -7
  264. package/src/plugins/defaults/memory/__tests__/relocated-memory-test-rows.ts +18 -0
  265. package/src/plugins/defaults/memory/context-search/sources/conversations.ts +16 -2
  266. package/src/plugins/defaults/memory/conversation-memory-purge.ts +2 -0
  267. package/src/plugins/defaults/memory/fork-conversation-memory.ts +13 -13
  268. package/src/plugins/defaults/memory/graph/__tests__/conversation-graph-memory-v2-routing.test.ts +19 -12
  269. package/src/plugins/defaults/memory/graph/conversation-graph-memory.ts +17 -15
  270. package/src/plugins/defaults/memory/graph-topology/build-memory-graph.ts +1 -1
  271. package/src/plugins/defaults/memory/hooks/__tests__/post-compact.test.ts +121 -0
  272. package/src/plugins/defaults/memory/hooks/init.ts +10 -0
  273. package/src/plugins/defaults/memory/hooks/injection-metadata.ts +100 -0
  274. package/src/plugins/defaults/memory/hooks/post-compact.ts +19 -7
  275. package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +11 -83
  276. package/src/plugins/defaults/memory/injectors.ts +4 -4
  277. package/src/plugins/defaults/memory/job-handlers.ts +4 -1
  278. package/src/plugins/defaults/memory/jobs/__tests__/embed-concept-page.test.ts +1 -0
  279. package/src/plugins/defaults/memory/jobs/embed-concept-page.ts +11 -3
  280. package/src/plugins/defaults/memory/memory-db.ts +4 -0
  281. package/src/plugins/defaults/memory/memory-marker.ts +28 -17
  282. package/src/plugins/defaults/memory/src/__tests__/memory-v2-simulate-route.test.ts +0 -1
  283. package/src/plugins/defaults/memory/src/__tests__/memory-worker-routes.test.ts +20 -0
  284. package/src/plugins/defaults/memory/src/memory-item-routes.test.ts +0 -1
  285. package/src/plugins/defaults/memory/src/memory-worker-routes.ts +3 -1
  286. package/src/plugins/defaults/memory/substrate/__tests__/cli-command-store.test.ts +1 -1
  287. package/src/plugins/defaults/memory/substrate/__tests__/consolidation-job.test.ts +66 -0
  288. package/src/plugins/defaults/memory/substrate/__tests__/injected-block-slugs.test.ts +345 -0
  289. package/src/plugins/defaults/memory/substrate/__tests__/page-index.test.ts +0 -1
  290. package/src/plugins/defaults/memory/substrate/__tests__/prompts-consolidation.test.ts +170 -1
  291. package/src/plugins/defaults/memory/substrate/__tests__/reembed-job.test.ts +1 -0
  292. package/src/plugins/defaults/memory/substrate/capability-slugs.ts +53 -0
  293. package/src/plugins/defaults/memory/substrate/cli-command-store.ts +4 -18
  294. package/src/plugins/defaults/memory/substrate/consolidation-job.ts +40 -1
  295. package/src/plugins/defaults/memory/substrate/ingest.ts +11 -9
  296. package/src/plugins/defaults/memory/substrate/injected-block-slugs.ts +426 -42
  297. package/src/plugins/defaults/memory/substrate/page-index.ts +5 -4
  298. package/src/plugins/defaults/memory/substrate/prompts/consolidation.ts +127 -14
  299. package/src/plugins/defaults/memory/substrate/skill-store.ts +1 -18
  300. package/src/plugins/defaults/memory/v2/__tests__/backfill-jobs.test.ts +1 -0
  301. package/src/plugins/defaults/memory/v2/__tests__/injection.test.ts +2 -8
  302. package/src/plugins/defaults/memory/v2/__tests__/router.test.ts +0 -1
  303. package/src/plugins/defaults/memory/v2/injection.ts +4 -4
  304. package/src/plugins/defaults/memory/v3/__tests__/capabilities.test.ts +16 -0
  305. package/src/plugins/defaults/memory/v3/__tests__/carry-integration.test.ts +1004 -319
  306. package/src/plugins/defaults/memory/v3/__tests__/dense.test.ts +227 -4
  307. package/src/plugins/defaults/memory/v3/__tests__/injection.test.ts +836 -263
  308. package/src/plugins/defaults/memory/v3/__tests__/live-integration.test.ts +65 -38
  309. package/src/plugins/defaults/memory/v3/__tests__/maintain-job.test.ts +354 -3
  310. package/src/plugins/defaults/memory/v3/__tests__/orchestrate.test.ts +688 -104
  311. package/src/plugins/defaults/memory/v3/__tests__/overlong-sections.test.ts +109 -0
  312. package/src/plugins/defaults/memory/v3/__tests__/page-content.test.ts +144 -0
  313. package/src/plugins/defaults/memory/v3/__tests__/plugin-schema.test.ts +534 -0
  314. package/src/plugins/defaults/memory/v3/__tests__/pool-log-store.test.ts +449 -0
  315. package/src/plugins/defaults/memory/v3/__tests__/pool-select.test.ts +265 -27
  316. package/src/plugins/defaults/memory/v3/__tests__/render-injection.test.ts +34 -117
  317. package/src/plugins/defaults/memory/v3/__tests__/section-dense-store.test.ts +491 -4
  318. package/src/plugins/defaults/memory/v3/__tests__/section-needle.test.ts +124 -1
  319. package/src/plugins/defaults/memory/v3/__tests__/sections.test.ts +264 -4
  320. package/src/plugins/defaults/memory/v3/__tests__/selection-log-store.test.ts +560 -22
  321. package/src/plugins/defaults/memory/v3/__tests__/shadow-integration.test.ts +40 -33
  322. package/src/plugins/defaults/memory/v3/__tests__/shadow-plugin.test.ts +718 -63
  323. package/src/plugins/defaults/memory/v3/__tests__/types.test.ts +83 -2
  324. package/src/plugins/defaults/memory/v3/candidate-match.ts +1 -1
  325. package/src/plugins/defaults/memory/v3/capabilities.ts +90 -14
  326. package/src/plugins/defaults/memory/v3/card.test.ts +15 -16
  327. package/src/plugins/defaults/memory/v3/card.ts +16 -15
  328. package/src/plugins/defaults/memory/v3/dense.ts +10 -0
  329. package/src/plugins/defaults/memory/v3/ever-injected-store.test.ts +643 -140
  330. package/src/plugins/defaults/memory/v3/ever-injected-store.ts +462 -212
  331. package/src/plugins/defaults/memory/v3/hot-set.test.ts +2 -2
  332. package/src/plugins/defaults/memory/v3/injector.ts +366 -278
  333. package/src/plugins/defaults/memory/v3/learned-edges.test.ts +2 -2
  334. package/src/plugins/defaults/memory/v3/maintain-job.ts +299 -73
  335. package/src/plugins/defaults/memory/v3/orchestrate.ts +327 -214
  336. package/src/plugins/defaults/memory/v3/overlong-sections.ts +83 -0
  337. package/src/plugins/defaults/memory/v3/page-content.ts +72 -92
  338. package/src/plugins/defaults/memory/v3/plugin-schema.ts +346 -0
  339. package/src/plugins/defaults/memory/v3/pool-log-store.ts +291 -0
  340. package/src/plugins/defaults/memory/v3/pool-select.test.ts +2 -2
  341. package/src/plugins/defaults/memory/v3/pool-select.ts +160 -60
  342. package/src/plugins/defaults/memory/v3/prune.test.ts +1042 -329
  343. package/src/plugins/defaults/memory/v3/prune.ts +433 -270
  344. package/src/plugins/defaults/memory/v3/rare-term-lane.test.ts +269 -0
  345. package/src/plugins/defaults/memory/v3/rare-term-lane.ts +141 -0
  346. package/src/plugins/defaults/memory/v3/render-injection.ts +43 -82
  347. package/src/plugins/defaults/memory/v3/section-dense-store.ts +316 -28
  348. package/src/plugins/defaults/memory/v3/section-needle.ts +145 -11
  349. package/src/plugins/defaults/memory/v3/sections.ts +103 -16
  350. package/src/plugins/defaults/memory/v3/selection-log-store.ts +243 -78
  351. package/src/plugins/defaults/memory/v3/shadow-plugin.ts +189 -68
  352. package/src/plugins/defaults/memory/v3/tuning-profile.ts +6 -0
  353. package/src/plugins/defaults/memory/v3/types.ts +169 -23
  354. package/src/plugins/defaults/memory/v3-eval/__tests__/eval-packets.test.ts +21 -4
  355. package/src/plugins/defaults/memory/v3-eval/eval-packets.ts +77 -26
  356. package/src/plugins/types.ts +14 -0
  357. package/src/providers/__tests__/connection-model-compat.test.ts +1 -0
  358. package/src/providers/__tests__/provider-secret-catalog.test.ts +4 -0
  359. package/src/providers/__tests__/xml-tool-call-salvage.test.ts +172 -0
  360. package/src/providers/inline-audio-support.test.ts +34 -0
  361. package/src/providers/inline-audio-support.ts +27 -0
  362. package/src/providers/model-catalog.ts +102 -0
  363. package/src/providers/openai/__tests__/chat-completions-extra-body.test.ts +51 -0
  364. package/src/providers/openai/__tests__/chat-completions-provider-xml-salvage.test.ts +291 -0
  365. package/src/providers/openai/chat-completions-provider.ts +114 -14
  366. package/src/providers/openai/codex-models.ts +1 -0
  367. package/src/providers/openai/responses-provider.ts +65 -15
  368. package/src/providers/opencode/client.test.ts +24 -0
  369. package/src/providers/opencode/client.ts +6 -1
  370. package/src/providers/provider-secret-catalog.ts +11 -1
  371. package/src/providers/retry.ts +6 -0
  372. package/src/providers/vellum/client.ts +14 -1
  373. package/src/providers/vellum/personality-directions.test.ts +163 -0
  374. package/src/providers/vellum/personality-directions.ts +120 -0
  375. package/src/providers/xml-tool-call-salvage.ts +212 -0
  376. package/src/runtime/AGENTS.md +7 -2
  377. package/src/runtime/__tests__/background-job-runner.test.ts +115 -0
  378. package/src/runtime/__tests__/guardian-form-registry.test.ts +0 -32
  379. package/src/runtime/__tests__/host-observe.test.ts +44 -0
  380. package/src/runtime/assistant-event-hub.ts +14 -9
  381. package/src/runtime/auth/__tests__/guard-tests.test.ts +1 -4
  382. package/src/runtime/auth/__tests__/route-policy.test.ts +65 -0
  383. package/src/runtime/auth/same-actor.ts +4 -3
  384. package/src/runtime/background-job-runner.ts +10 -0
  385. package/src/runtime/channel-reply-delivery.ts +1 -162
  386. package/src/runtime/guardian-action-service.ts +20 -1
  387. package/src/runtime/host-observe.ts +56 -6
  388. package/src/runtime/http-server.ts +35 -0
  389. package/src/runtime/outbound-post-reconciliation.ts +183 -0
  390. package/src/runtime/routes/__tests__/contact-address-prompt-route.test.ts +231 -0
  391. package/src/runtime/routes/__tests__/contact-record-prompt-route.test.ts +59 -3
  392. package/src/runtime/routes/__tests__/guardian-form-routes.test.ts +85 -0
  393. package/src/runtime/routes/__tests__/heartbeat-routes.test.ts +24 -0
  394. package/src/runtime/routes/__tests__/platform-credits-routes.test.ts +239 -0
  395. package/src/runtime/routes/__tests__/roadmap-routes.test.ts +469 -0
  396. package/src/runtime/routes/__tests__/watch-routes.test.ts +70 -1
  397. package/src/runtime/routes/__tests__/webhook-routes.test.ts +83 -0
  398. package/src/runtime/routes/contact-prompt-routes.ts +177 -28
  399. package/src/runtime/routes/conversation-query-routes.ts +53 -11
  400. package/src/runtime/routes/events-routes.ts +13 -3
  401. package/src/runtime/routes/guardian-action-routes.ts +7 -0
  402. package/src/runtime/routes/guardian-form-routes.ts +6 -4
  403. package/src/runtime/routes/heartbeat-routes.ts +41 -53
  404. package/src/runtime/routes/index.ts +2 -2
  405. package/src/runtime/routes/integrations/a2a.ts +12 -3
  406. package/src/runtime/routes/integrations/vercel.ts +13 -3
  407. package/src/runtime/routes/platform-routes.ts +175 -23
  408. package/src/runtime/routes/roadmap-routes.ts +744 -0
  409. package/src/runtime/routes/watch-routes.ts +50 -0
  410. package/src/runtime/routes/webhook-routes.ts +24 -2
  411. package/src/runtime/web-presence.ts +13 -9
  412. package/src/schedule/__tests__/schedule-timezone.test.ts +21 -3
  413. package/src/schedule/__tests__/worker-mcp-tools.test.ts +88 -0
  414. package/src/schedule/schedule-timezone.ts +25 -0
  415. package/src/schedule/scheduler.ts +19 -0
  416. package/src/schedule/worker.ts +119 -2
  417. package/src/telemetry/__tests__/live-voice-funnel.test.ts +32 -0
  418. package/src/telemetry/live-voice-funnel.ts +33 -0
  419. package/src/tools/acp/list-agents.test.ts +1 -1
  420. package/src/tools/browser/__tests__/browser-status.test.ts +3 -0
  421. package/src/tools/browser/browser-execution.ts +117 -53
  422. package/src/tools/browser/browser-status-constants.ts +6 -6
  423. package/src/tools/capability-offer.test.ts +87 -0
  424. package/src/tools/capability-offer.ts +93 -0
  425. package/src/tools/computer-use/definitions.ts +6 -0
  426. package/src/tools/computer-use/skill-proxy-bridge.ts +10 -0
  427. package/src/tools/terminal/safe-env.ts +2 -0
  428. package/src/watch/__tests__/watch-retro.test.ts +11 -10
  429. package/src/watch/__tests__/watch-session-manager.test.ts +75 -1
  430. package/src/watch/watch-retro.ts +10 -9
  431. package/src/watch/watch-session-manager.ts +17 -0
  432. package/src/runtime/routes/__tests__/sight-frame-routes.test.ts +0 -487
  433. package/src/runtime/routes/sight-frame-routes.ts +0 -136
@@ -43,11 +43,11 @@ let nextTurn = 0;
43
43
  /** Insert one selector call: every slug shares the same (conv, created_at). */
44
44
  function seedCall(slugs: string[], createdAt = NOW, conv = "conv-1"): void {
45
45
  const stmt = sqlite.query(
46
- `INSERT INTO memory_v3_selections (conversation_id, turn, slug, source, pinned, created_at) VALUES (?, ?, ?, ?, ?, ?)`,
46
+ `INSERT INTO memory_v3_selections (conversation_id, turn, slug, source, created_at) VALUES (?, ?, ?, ?, ?)`,
47
47
  );
48
48
  const turn = nextTurn++;
49
49
  for (const slug of slugs) {
50
- stmt.run(conv, turn, slug, "needle", 0, createdAt);
50
+ stmt.run(conv, turn, slug, "needle", createdAt);
51
51
  }
52
52
  }
53
53
 
@@ -4,31 +4,51 @@
4
4
  * A flag-gated, best-effort self-maintenance pass over the v3 section dense
5
5
  * store and the in-memory lanes. It runs six independent stages, in order:
6
6
  *
7
- * 1. **Section re-embed** — diff the page index by `modifiedAt` against the
7
+ * 1. **Section re-embed**: diff the page index by `modifiedAt` against the
8
8
  * last successful pass (the high-water mark below), and for every page that
9
9
  * is new or edited since then, re-chunk it into sections
10
10
  * (`buildSectionIndex`) and refresh its dense points
11
11
  * (`deleteSectionsForArticle` + `upsertSections`). This keeps the
12
12
  * section-grain Qdrant collection in sync with on-disk page edits so the
13
- * dense lane retrieves against current content. The high-water mark is
14
- * advanced only after the pass completes with zero page failures (and is
15
- * captured before any potential mtime bumps) so a page is not re-embedded
16
- * forever, yet a page whose embed failed (and whose sections were therefore
17
- * left deleted) stays above the mark and is retried next pass.
18
- * 2. **Capability reconcile** — embed capability rows (synthetic skill/CLI
13
+ * dense lane retrieves against current content. When the chunker version
14
+ * check (`ensureSectionChunkerVersion`) reports a rebuild pending, the
15
+ * pass also re-embeds every capability row the store already holds (the
16
+ * delta never names one), so every stored point carries the current
17
+ * chunk boundaries before the commit releases the dense-read hold. The
18
+ * high-water mark is advanced only after the pass completes with zero
19
+ * failures (and is captured before any potential mtime bumps) so a page
20
+ * is not re-embedded forever, yet a page whose embed failed (and whose
21
+ * sections were therefore left deleted) stays above the mark and is
22
+ * retried next pass. On a version rebuild the commit also waits for
23
+ * every stored capability row: one whose body renders empty in this
24
+ * process (its capability cache unseeded, or the capability gone)
25
+ * keeps its points, so the commit is settled only after the
26
+ * deleted-page prune (stage 3) has had its chance to remove it, and a
27
+ * row still standing holds the commit, and the rebuild marker. The job
28
+ * runs in the memory worker, whose skill and CLI caches are never
29
+ * seeded, so there every stored capability row renders empty and the
30
+ * prune, whose page index lists no capability row, removes them all: a
31
+ * version rebuild in the worker commits over a store with no
32
+ * capability points, which `backfillAllSections` (run in the daemon,
33
+ * caches seeded) restores.
34
+ * 2. **Capability reconcile**: embed capability rows (synthetic skill/CLI
19
35
  * slugs) present in the page index but missing from the section store. The
20
36
  * re-embed delta above EXCLUDES capability rows (they have `modifiedAt` 0,
21
- * no mtime to diff), so the only other embedder is the one-time
22
- * `backfillAllSections`. Without this stage a skill enabled AFTER that
23
- * backfill (e.g. a flag-gated skill flipped on at runtime) lands in the
24
- * index but never reaches the dense lane. See {@link reconcileCapabilityRows}.
37
+ * no mtime to diff), so their only other embedders are the one-time
38
+ * `backfillAllSections` and the version-triggered rebuild. Without this
39
+ * stage a skill enabled AFTER that backfill (e.g. a flag-gated skill
40
+ * flipped on at runtime) lands in the index but never reaches the dense
41
+ * lane. See {@link reconcileCapabilityRows}.
25
42
  * 3. **Deleted-page prune** — diff the dense store's stored articles
26
43
  * (`listSectionArticles`) against the live page-index slugs and
27
44
  * `deleteSectionsForArticle` for any article that is no longer in the
28
45
  * index. A deleted page's slug never reaches the re-embed delta selector
29
46
  * (it only names live pages), so without this its section points would
30
47
  * linger in Qdrant and the dense lane could still surface the deleted page.
31
- * Synthetic capability rows are in the page index, so they are never pruned.
48
+ * A capability row the page index lists is never pruned; one it does not
49
+ * list (the capability gone, or this process's capability caches
50
+ * unseeded, which lists none) is pruned like a deleted page, and that
51
+ * removal also settles the version-rebuild commit stage 1 deferred.
32
52
  * 4. **Core-set validation** — load the maintainer-curated core set
33
53
  * (`memory/core-pages.md`) and report entries whose page no longer exists
34
54
  * in the page index (dangling slugs) via the log + outcome. The file is
@@ -65,10 +85,7 @@ import {
65
85
 
66
86
  import { isMemoryV3Live } from "../../../../config/memory-v3-gate.js";
67
87
  import type { AssistantConfig } from "../../../../config/types.js";
68
- import {
69
- getMemoryCheckpoint,
70
- setMemoryCheckpoint,
71
- } from "../../../../persistence/checkpoints.js";
88
+ import { getMemoryCheckpoint } from "../../../../persistence/checkpoints.js";
72
89
  import { EmbeddingBackendUnavailableError } from "../../../../persistence/embeddings/embedding-backend.js";
73
90
  import { EmbeddingBillingBlockError } from "../../../../persistence/embeddings/embedding-billing-breaker.js";
74
91
  import type { MemoryJob } from "../../../../persistence/jobs-store.js";
@@ -76,17 +93,20 @@ import { executeDeleteManagedSkill } from "../../../../tools/skills/delete-manag
76
93
  import { embedWithBackend } from "../embeddings.js";
77
94
  import { getLogger } from "../logging.js";
78
95
  import { getWorkspaceDir } from "../paths.js";
96
+ import { skillSlugFor } from "../substrate/capability-slugs.js";
79
97
  import { getPageIndex } from "../substrate/page-index.js";
80
98
  import { readPage } from "../substrate/page-store.js";
81
- import { skillSlugFor } from "../substrate/skill-store.js";
82
99
  import { capabilityOrDiskBody, isCapabilitySlug } from "./capabilities.js";
83
100
  import { loadCoreSet as realLoadCoreSet } from "./core-set.js";
84
101
  import {
102
+ commitSectionEmbedHighWater,
85
103
  deleteSectionsForArticle as realDeleteSectionsForArticle,
104
+ ensureSectionChunkerVersion as realEnsureSectionChunkerVersion,
86
105
  ensureSectionCollection as realEnsureSectionCollection,
87
106
  listSectionArticles as realListSectionArticles,
88
107
  MAINTAIN_EMBED_HIGH_WATER_KEY,
89
108
  upsertSections as realUpsertSections,
109
+ warmSectionEmbeddings as realWarmSectionEmbeddings,
90
110
  } from "./section-dense-store.js";
91
111
  import { buildSectionIndex as realBuildSectionIndex } from "./sections.js";
92
112
  import { invalidateLanes as realInvalidateLanes } from "./shadow-plugin.js";
@@ -142,12 +162,31 @@ export interface MaintainJobDeps {
142
162
  deleteSectionsForArticle: typeof realDeleteSectionsForArticle;
143
163
  /** Embed + upsert an article's current sections into the dense store. */
144
164
  upsertSections: typeof realUpsertSections;
165
+ /**
166
+ * Warm the embedding cache for many pages' sections in one batched backend
167
+ * call before the per-page upserts, which then serve from the cache.
168
+ */
169
+ warmSectionEmbeddings: typeof realWarmSectionEmbeddings;
145
170
  /**
146
171
  * Persist the high-water mark after a re-embed pass with zero failures. The
147
172
  * value is captured before the pass's writes (see the key docstring); the
148
- * caller skips this when any page failed so failed pages retry next pass.
173
+ * caller skips this when any page failed so failed pages retry next pass,
174
+ * and a version rebuild defers it past the deleted-page prune while a
175
+ * stored capability row it could not rebuild remains. The real commit
176
+ * (`commitSectionEmbedHighWater`) also releases the dense read hold a
177
+ * forced chunker rebuild put in place.
149
178
  */
150
179
  commitEmbedHighWater: (highWaterMs: number) => void;
180
+ /**
181
+ * Force a full re-embed when the section chunker version on record differs
182
+ * from the current one (see `ensureSectionChunkerVersion`). Runs after the
183
+ * collection is ensured and before deltas are selected, so the cleared
184
+ * high-water is what the selector reads. Resolves to whether a chunker
185
+ * rebuild is pending (forced by this call, or left by an earlier one that
186
+ * no clean pass has committed since), which is the pass's cue to re-embed
187
+ * the capability rows the store holds before committing.
188
+ */
189
+ ensureChunkerVersion: () => Promise<boolean>;
151
190
  /**
152
191
  * Every distinct `article` slug that currently has section points in the
153
192
  * dense store. The prune stage diffs this against the live page-index slugs
@@ -211,11 +250,27 @@ export interface BackfillJobDeps {
211
250
  deleteSectionsForArticle: typeof realDeleteSectionsForArticle;
212
251
  /** Embed + upsert an article's current sections into the dense store. */
213
252
  upsertSections: typeof realUpsertSections;
253
+ /**
254
+ * Warm the embedding cache for many pages' sections in one batched backend
255
+ * call before the per-page upserts, which then serve from the cache.
256
+ */
257
+ warmSectionEmbeddings: typeof realWarmSectionEmbeddings;
214
258
  /**
215
259
  * Persist the high-water mark after the backfill completes with zero
216
260
  * failures. Skipped when any page failed so failed pages retry next pass.
261
+ * The real commit (`commitSectionEmbedHighWater`) also releases the dense
262
+ * read hold a forced chunker rebuild put in place.
217
263
  */
218
264
  commitEmbedHighWater: (highWaterMs: number) => void;
265
+ /**
266
+ * Record the current section chunker version, forcing the maintain job's
267
+ * rebuild path when the one on record differs (see
268
+ * `ensureSectionChunkerVersion`). Runs after the collection is ensured and
269
+ * before the first write, so the version is on record before this pass
270
+ * commits. The backfill embeds every page and capability row regardless, so
271
+ * the pending-rebuild result is not consulted.
272
+ */
273
+ ensureChunkerVersion: () => Promise<boolean>;
219
274
  /** Epoch-ms stamped as the new high-water mark; injectable for tests. */
220
275
  nowMs: () => number;
221
276
  /** Active assistant config (for the dense-store/embedding calls). */
@@ -243,10 +298,22 @@ export interface BackfillOutcome {
243
298
  export interface MaintainOutcome {
244
299
  /** True when both v3 flags were off and the job no-opped. */
245
300
  disabled: boolean;
246
- /** Pages whose sections were re-chunked + re-embedded this pass. */
301
+ /**
302
+ * Articles whose sections were re-chunked + re-embedded this pass: the
303
+ * changed pages plus, on a version-triggered rebuild, the capability rows
304
+ * the store already held.
305
+ */
247
306
  reembedded: number;
248
- /** Pages whose re-embed threw (and was contained). */
307
+ /** Re-embeds that threw (and were contained). */
249
308
  reembedFailures: number;
309
+ /**
310
+ * Stored capability rows (skills/CLI) a version-triggered rebuild left with
311
+ * the previous chunker's points at the end of this pass: their body
312
+ * rendered empty here (this process's capability caches do not resolve
313
+ * them) and the deleted-page prune did not remove them. The embed
314
+ * checkpoint and the dense-read hold wait while any remain.
315
+ */
316
+ unrebuiltCapabilityRows: Slug[];
250
317
  /**
251
318
  * Capability rows (skills/CLI) present in the index but missing from the
252
319
  * section store that were embedded this pass — how a skill enabled after the
@@ -333,10 +400,6 @@ async function selectChangedPagesFromWorkspace(
333
400
  return computeChangedPages(index.entries, readEmbedHighWater());
334
401
  }
335
402
 
336
- function commitEmbedHighWater(highWaterMs: number): void {
337
- setMemoryCheckpoint(MAINTAIN_EMBED_HIGH_WATER_KEY, String(highWaterMs));
338
- }
339
-
340
403
  /** Read a page's frontmatter-stripped body; missing/failed reads degrade to "". */
341
404
  async function readPageBodyFromWorkspace(
342
405
  workspaceDir: string,
@@ -385,7 +448,9 @@ function defaultDeps(config: AssistantConfig): MaintainJobDeps {
385
448
  backfillPageBodyFromWorkspace(workspaceDir, slug),
386
449
  deleteSectionsForArticle: realDeleteSectionsForArticle,
387
450
  upsertSections: realUpsertSections,
388
- commitEmbedHighWater,
451
+ warmSectionEmbeddings: realWarmSectionEmbeddings,
452
+ commitEmbedHighWater: commitSectionEmbedHighWater,
453
+ ensureChunkerVersion: realEnsureSectionChunkerVersion,
389
454
  listSectionArticles: () => realListSectionArticles(config),
390
455
  listIndexedSlugs: () => selectAllPagesFromWorkspace(workspaceDir),
391
456
  loadCoreSet: () => realLoadCoreSet(workspaceDir),
@@ -419,7 +484,9 @@ function defaultBackfillDeps(config: AssistantConfig): BackfillJobDeps {
419
484
  readPageBody: (slug) => backfillPageBodyFromWorkspace(workspaceDir, slug),
420
485
  deleteSectionsForArticle: realDeleteSectionsForArticle,
421
486
  upsertSections: realUpsertSections,
422
- commitEmbedHighWater,
487
+ warmSectionEmbeddings: realWarmSectionEmbeddings,
488
+ commitEmbedHighWater: commitSectionEmbedHighWater,
489
+ ensureChunkerVersion: realEnsureSectionChunkerVersion,
423
490
  nowMs: () => Date.now(),
424
491
  config,
425
492
  embedProbe: async () => {
@@ -440,6 +507,7 @@ async function reembedChangedPages(
440
507
  ): Promise<{ reembedded: number; reembedFailures: number }> {
441
508
  let reembedded = 0;
442
509
  let reembedFailures = 0;
510
+ await warmEmbeddingCacheForPages(slugs, deps);
443
511
  for (const slug of slugs) {
444
512
  try {
445
513
  const index = await deps.buildSectionIndex([slug], deps.readPageBody);
@@ -457,58 +525,128 @@ async function reembedChangedPages(
457
525
  return { reembedded, reembedFailures };
458
526
  }
459
527
 
528
+ /**
529
+ * Warm the embedding cache for every section of `slugs` in batched backend
530
+ * calls before the per-page loop, which otherwise pays one backend call per
531
+ * page. Only worth a call for two or more pages. Best-effort: a failure here
532
+ * is logged, and the per-page loop then embeds each page independently, with
533
+ * each page's failure contained to that page.
534
+ */
535
+ async function warmEmbeddingCacheForPages(
536
+ slugs: Slug[],
537
+ deps: Pick<
538
+ MaintainJobDeps,
539
+ "buildSectionIndex" | "readPageBody" | "warmSectionEmbeddings" | "config"
540
+ >,
541
+ ): Promise<void> {
542
+ if (slugs.length < 2) {
543
+ return;
544
+ }
545
+ try {
546
+ const index = await deps.buildSectionIndex(slugs, deps.readPageBody);
547
+ await deps.warmSectionEmbeddings(deps.config, index.sections);
548
+ } catch (err) {
549
+ log.warn(
550
+ {
551
+ pages: slugs.length,
552
+ err: err instanceof Error ? err.message : String(err),
553
+ },
554
+ "memory-v3 maintain: embedding cache warm-up failed; each page embeds on its own (non-fatal)",
555
+ );
556
+ }
557
+ }
558
+
460
559
  /**
461
560
  * Embed capability rows (synthetic skill/CLI slugs) present in the page index
462
561
  * but missing from the section dense store. The incremental re-embed selector
463
- * ({@link computeChangedPages}) excludes capability rows — they have no on-disk
464
- * mtime to delta against — so the ONLY other embedder is the one-time
465
- * {@link backfillAllSections}. Without this, a skill enabled AFTER that backfill
466
- * (e.g. a flag-gated skill flipped on at runtime) lands in the page index but
467
- * never reaches the dense lane. This stage makes the periodic maintain pass
468
- * self-heal: diff the live capability slugs against the stored section articles
469
- * and embed the missing ones.
470
- *
471
- * Each row is independent: a single build/upsert throw is logged and counted in
472
- * `reconcileFailures` without aborting the rest. A capability row whose body
473
- * resolves empty (its store has not seeded yet) is skipped WITHOUT deleting any
474
- * points — never replace good points with a blank — and is retried next pass.
562
+ * ({@link computeChangedPages}) excludes capability rows (they have no on-disk
563
+ * mtime to delta against), so their only other embedders are the one-time
564
+ * {@link backfillAllSections} and the version-triggered rebuild in
565
+ * {@link maintainJob}'s first stage. Without this, a skill enabled AFTER that
566
+ * backfill (e.g. a flag-gated skill flipped on at runtime) lands in the page
567
+ * index but never reaches the dense lane. This stage makes the periodic
568
+ * maintain pass self-heal: diff the live capability slugs against the stored
569
+ * section articles and embed the missing ones. Per-row containment and the
570
+ * cold-row skip live in {@link refreshCapabilityRows}.
475
571
  */
476
572
  async function reconcileCapabilityRows(
477
573
  deps: MaintainJobDeps,
478
574
  ): Promise<{ capabilitiesReconciled: number; reconcileFailures: number }> {
575
+ const missing = await missingCapabilityRows(deps);
576
+ const { embedded, failed } = await refreshCapabilityRows(missing, deps);
577
+ return { capabilitiesReconciled: embedded, reconcileFailures: failed };
578
+ }
579
+
580
+ /**
581
+ * The capability slugs (synthetic skill/CLI rows) the page index lists that
582
+ * the section dense store holds no points for: what
583
+ * {@link reconcileCapabilityRows} embeds.
584
+ */
585
+ async function missingCapabilityRows(deps: MaintainJobDeps): Promise<Slug[]> {
479
586
  const [indexedSlugs, storedArticles] = await Promise.all([
480
587
  deps.listIndexedSlugs(),
481
588
  deps.listSectionArticles(),
482
589
  ]);
483
590
  const stored = new Set(storedArticles);
484
- const missing = indexedSlugs.filter(
591
+ return indexedSlugs.filter(
485
592
  (slug) => isCapabilitySlug(slug) && !stored.has(slug),
486
593
  );
594
+ }
595
+
596
+ /**
597
+ * The capability rows the section dense store currently holds points for:
598
+ * what a version-triggered rebuild re-embeds, since the change-delta selector
599
+ * never names a capability row and the stored points would otherwise keep
600
+ * the previous chunker's boundaries. Read from the store rather than the page
601
+ * index: an index built while this process's capability caches are unseeded
602
+ * lists no capability row, and a stored row it omits still carries the old
603
+ * points.
604
+ */
605
+ async function storedCapabilityRows(deps: MaintainJobDeps): Promise<Slug[]> {
606
+ return (await deps.listSectionArticles()).filter(isCapabilitySlug);
607
+ }
487
608
 
488
- let capabilitiesReconciled = 0;
489
- let reconcileFailures = 0;
490
- for (const slug of missing) {
609
+ /**
610
+ * Re-chunk + re-embed capability rows from their rendered capability bodies
611
+ * (`readCapabilityBody`). Each row is independent: a single build/delete/upsert
612
+ * throw is logged and counted in `failed` without aborting the rest. A row
613
+ * whose body resolves empty is listed in `cold` and skipped WITHOUT deleting
614
+ * any points (never replace good points with a blank): a capability store that
615
+ * has not seeded yet renders every row empty, and a slug the index lists but
616
+ * no store resolves renders empty on every pass. What a cold row means is the
617
+ * caller's: the reconcile stage retries it on a later pass, and a version
618
+ * rebuild holds its commit on it (see {@link maintainJob}).
619
+ */
620
+ async function refreshCapabilityRows(
621
+ slugs: Slug[],
622
+ deps: MaintainJobDeps,
623
+ ): Promise<{ embedded: number; failed: number; cold: Slug[] }> {
624
+ let embedded = 0;
625
+ let failed = 0;
626
+ const cold: Slug[] = [];
627
+ for (const slug of slugs) {
491
628
  try {
492
629
  const body = await deps.readCapabilityBody(slug);
493
630
  if (body.trim().length === 0) {
631
+ cold.push(slug);
494
632
  continue;
495
- } // store cold — retry next pass
633
+ }
496
634
  const index = await deps.buildSectionIndex(
497
635
  [slug],
498
636
  deps.readCapabilityBody,
499
637
  );
500
638
  await deps.deleteSectionsForArticle(deps.config, slug);
501
639
  await deps.upsertSections(deps.config, index.sections);
502
- capabilitiesReconciled += 1;
640
+ embedded += 1;
503
641
  } catch (err) {
504
- reconcileFailures += 1;
642
+ failed += 1;
505
643
  log.warn(
506
644
  { slug, err: err instanceof Error ? err.message : String(err) },
507
- "memory-v3 maintain: capability reconcile embed failed (non-fatal)",
645
+ "memory-v3 maintain: capability row embed failed (non-fatal)",
508
646
  );
509
647
  }
510
648
  }
511
- return { capabilitiesReconciled, reconcileFailures };
649
+ return { embedded, failed, cold };
512
650
  }
513
651
 
514
652
  /**
@@ -521,12 +659,15 @@ async function reconcileCapabilityRows(
521
659
  * diffing against the live slug set.
522
660
  *
523
661
  * Each deletion is independent: a single `deleteSectionsForArticle` throw is
524
- * logged and counted in `pruneFailures` without aborting the rest. Synthetic
525
- * capability rows are in the page index, so they are never pruned.
662
+ * logged and counted in `pruneFailures` without aborting the rest. A
663
+ * capability row the page index lists is never pruned; one it does not list
664
+ * is pruned like any deleted page, and the pruned articles are returned so a
665
+ * version rebuild's deferred commit can settle on them (see
666
+ * {@link maintainJob}).
526
667
  */
527
668
  async function pruneDeletedPages(
528
669
  deps: MaintainJobDeps,
529
- ): Promise<{ pruned: number; pruneFailures: number }> {
670
+ ): Promise<{ prunedArticles: string[]; pruneFailures: number }> {
530
671
  const [storedArticles, indexedSlugs] = await Promise.all([
531
672
  deps.listSectionArticles(),
532
673
  deps.listIndexedSlugs(),
@@ -534,12 +675,12 @@ async function pruneDeletedPages(
534
675
  const live = new Set(indexedSlugs);
535
676
  const deleted = storedArticles.filter((article) => !live.has(article));
536
677
 
537
- let pruned = 0;
678
+ const prunedArticles: string[] = [];
538
679
  let pruneFailures = 0;
539
680
  for (const article of deleted) {
540
681
  try {
541
682
  await deps.deleteSectionsForArticle(deps.config, article);
542
- pruned += 1;
683
+ prunedArticles.push(article);
543
684
  } catch (err) {
544
685
  pruneFailures += 1;
545
686
  log.warn(
@@ -548,7 +689,7 @@ async function pruneDeletedPages(
548
689
  );
549
690
  }
550
691
  }
551
- return { pruned, pruneFailures };
692
+ return { prunedArticles, pruneFailures };
552
693
  }
553
694
 
554
695
  /**
@@ -698,6 +839,9 @@ export async function backfillAllSections(
698
839
 
699
840
  const slugs = await deps.selectAllPages();
700
841
  await deps.ensureSectionCollection(deps.config);
842
+ // The backfill re-embeds every page regardless; recording the chunker
843
+ // version here keeps the maintain job from forcing a second full pass.
844
+ await deps.ensureChunkerVersion();
701
845
 
702
846
  // Pre-flight: smoke-test the embedding backend BEFORE any delete. Each article
703
847
  // is processed delete-then-upsert, so starting a full backfill against a down
@@ -751,6 +895,13 @@ export async function backfillAllSections(
751
895
  };
752
896
 
753
897
  const coldCapabilities: Slug[] = [];
898
+ // Real pages warm the embedding cache in one batched call first; capability
899
+ // rows stay on the per-page path below, whose cold-row guard must see each
900
+ // body before anything of it is embedded.
901
+ await warmEmbeddingCacheForPages(
902
+ slugs.filter((slug) => !isCapabilitySlug(slug)),
903
+ deps,
904
+ );
754
905
  for (const slug of slugs) {
755
906
  if ((await embedOne(slug)) === "cold") {
756
907
  coldCapabilities.push(slug);
@@ -814,6 +965,7 @@ export async function maintainJob(
814
965
  disabled: false,
815
966
  reembedded: 0,
816
967
  reembedFailures: 0,
968
+ unrebuiltCapabilityRows: [],
817
969
  capabilitiesReconciled: 0,
818
970
  reconcileFailures: 0,
819
971
  pruned: 0,
@@ -835,6 +987,12 @@ export async function maintainJob(
835
987
  // Stage 1: re-chunk + re-embed pages changed since the last pass. Capture the
836
988
  // high-water mark BEFORE the pass so an embed write that bumps a page's mtime
837
989
  // does not re-trigger it next pass; advance it only when every page succeeded.
990
+ //
991
+ // The commit a version rebuild still owes after this stage: set when the
992
+ // pass had no embed failure but left stored capability rows it could not
993
+ // rebuild, and settled after the deleted-page prune (stage 3), the stage
994
+ // that removes such a row when the page index no longer lists it.
995
+ let deferredCommit: { highWaterMs: number; unrebuilt: Slug[] } | null = null;
838
996
  try {
839
997
  const startedAtMs = Date.now();
840
998
  // Establish the collection BEFORE selecting deltas. If it is absent or
@@ -845,6 +1003,10 @@ export async function maintainJob(
845
1003
  // cleared mark visible to `selectChangedPages`, turning this pass into the
846
1004
  // full-corpus re-embed the recreate requires.
847
1005
  await deps.ensureSectionCollection(deps.config);
1006
+ // A chunker version change clears the high-water the same way, and for
1007
+ // the same reason: the stored points no longer line up with the index.
1008
+ // The pending marker it leaves names this pass a version rebuild.
1009
+ const rebuildPending = await deps.ensureChunkerVersion();
848
1010
  const changed = await deps.selectChangedPages();
849
1011
  const { reembedded, reembedFailures } = await reembedChangedPages(
850
1012
  changed,
@@ -852,20 +1014,51 @@ export async function maintainJob(
852
1014
  );
853
1015
  outcome.reembedded = reembedded;
854
1016
  outcome.reembedFailures = reembedFailures;
855
- // Only advance the high-water mark when nothing failed. A failed page is
856
- // processed as delete-then-upsert, so a transient embed/Qdrant error leaves
857
- // its sections deleted; if we advanced past its mtime, `computeChangedPages`
858
- // would never re-select it (mtime <= high-water) and it would stay missing.
859
- // Holding the checkpoint keeps every failed page above the mark so it
860
- // retries next pass — the handful of already-succeeded pages re-embedding
861
- // again is idempotent and cheap.
862
- if (reembedFailures === 0) {
863
- deps.commitEmbedHighWater(startedAtMs);
864
- } else {
1017
+ // A version rebuild must also refresh the capability rows the store
1018
+ // already holds: the delta selector never names them (modifiedAt 0) and
1019
+ // the reconcile stage below embeds only rows missing from the store, so
1020
+ // without this their points would keep the previous chunker's boundaries
1021
+ // past the commit that releases the dense-read hold. A cold row (its body
1022
+ // renders empty here: this process's capability caches are unseeded, or
1023
+ // the capability is gone) keeps its points, and those points keep the
1024
+ // old boundaries, so it holds the commit until it is rebuilt or removed.
1025
+ let unrebuilt: Slug[] = [];
1026
+ if (rebuildPending) {
1027
+ const { embedded, failed, cold } = await refreshCapabilityRows(
1028
+ await storedCapabilityRows(deps),
1029
+ deps,
1030
+ );
1031
+ outcome.reembedded += embedded;
1032
+ outcome.reembedFailures += failed;
1033
+ unrebuilt = cold;
1034
+ }
1035
+ // Only advance the high-water mark when nothing failed. A failed article
1036
+ // is processed as delete-then-upsert, so a transient embed/Qdrant error
1037
+ // leaves its sections deleted; if we advanced past a page's mtime,
1038
+ // `computeChangedPages` would never re-select it (mtime <= high-water) and
1039
+ // it would stay missing, and a commit would release the dense-read hold
1040
+ // over a capability row whose points are gone. Holding the checkpoint
1041
+ // keeps every failed article in the next pass so it retries; the handful
1042
+ // of already-succeeded articles re-embedding again is idempotent and cheap.
1043
+ // A commit over a cold capability row would likewise release the hold
1044
+ // over points whose ordinals can name the wrong section, so with cold
1045
+ // rows and no failure the commit is deferred until the deleted-page
1046
+ // prune has run: a row the page index no longer lists leaves the store
1047
+ // there, and a row still standing afterwards holds the commit, and the
1048
+ // rebuild marker (in the memory worker, where the job runs, every
1049
+ // capability row is cold and the prune removes them all).
1050
+ if (outcome.reembedFailures > 0) {
865
1051
  log.info(
866
- { reembedded, reembedFailures },
867
- "memory-v3 maintain: embed checkpoint held (page failures) — failed pages retry next pass",
1052
+ {
1053
+ reembedded: outcome.reembedded,
1054
+ reembedFailures: outcome.reembedFailures,
1055
+ },
1056
+ "memory-v3 maintain: embed checkpoint held (embed failures); failed articles retry next pass",
868
1057
  );
1058
+ } else if (unrebuilt.length === 0) {
1059
+ deps.commitEmbedHighWater(startedAtMs);
1060
+ } else {
1061
+ deferredCommit = { highWaterMs: startedAtMs, unrebuilt };
869
1062
  }
870
1063
  } catch (err) {
871
1064
  outcome.failures.push("reembed");
@@ -877,10 +1070,10 @@ export async function maintainJob(
877
1070
 
878
1071
  // Stage 2: embed capability rows (skills/CLI) present in the index but missing
879
1072
  // from the section store. They have modifiedAt 0, so computeChangedPages never
880
- // selects them; the one-time backfill is otherwise their only embedder, so a
881
- // skill enabled after that backfill stays invisible to the dense lane until
882
- // this self-heals it. Contained: a failure is logged + recorded without
883
- // aborting later stages.
1073
+ // selects them; the one-time backfill and the version rebuild above are
1074
+ // otherwise their only embedders, so a skill enabled after that backfill
1075
+ // stays invisible to the dense lane until this self-heals it. Contained: a
1076
+ // failure is logged + recorded without aborting later stages.
884
1077
  try {
885
1078
  const { capabilitiesReconciled, reconcileFailures } =
886
1079
  await reconcileCapabilityRows(deps);
@@ -897,12 +1090,20 @@ export async function maintainJob(
897
1090
  // Stage 3: prune section points for pages deleted from the index. A deleted
898
1091
  // page's slug never appears in `selectChangedPages` (the delta selector only
899
1092
  // names live pages), so its lingering points are cleared by diffing the dense
900
- // store's stored articles against the live page-index slugs. Contained: a
901
- // failure is logged + recorded in `failures` without aborting invalidation.
1093
+ // store's stored articles against the live page-index slugs. The articles
1094
+ // it removes also settle the commit a version rebuild deferred (below).
1095
+ // Contained: a failure is logged + recorded in `failures` without aborting
1096
+ // invalidation.
902
1097
  try {
903
- const { pruned, pruneFailures } = await pruneDeletedPages(deps);
904
- outcome.pruned = pruned;
1098
+ const { prunedArticles, pruneFailures } = await pruneDeletedPages(deps);
1099
+ outcome.pruned = prunedArticles.length;
905
1100
  outcome.pruneFailures = pruneFailures;
1101
+ if (deferredCommit) {
1102
+ const pruned = new Set(prunedArticles);
1103
+ deferredCommit.unrebuilt = deferredCommit.unrebuilt.filter(
1104
+ (slug) => !pruned.has(slug),
1105
+ );
1106
+ }
906
1107
  } catch (err) {
907
1108
  outcome.failures.push("prune");
908
1109
  log.warn(
@@ -911,6 +1112,30 @@ export async function maintainJob(
911
1112
  );
912
1113
  }
913
1114
 
1115
+ // Settle the commit stage 1 deferred: a cold capability row the prune
1116
+ // removed carries no stale points any more, so with none left the pass
1117
+ // commits as a clean rebuild; otherwise the checkpoint and the rebuild
1118
+ // marker stay put and the remaining rows are surfaced in the outcome.
1119
+ if (deferredCommit) {
1120
+ try {
1121
+ if (deferredCommit.unrebuilt.length === 0) {
1122
+ deps.commitEmbedHighWater(deferredCommit.highWaterMs);
1123
+ } else {
1124
+ outcome.unrebuiltCapabilityRows = deferredCommit.unrebuilt;
1125
+ log.info(
1126
+ { unrebuiltCapabilityRows: deferredCommit.unrebuilt },
1127
+ "memory-v3 maintain: embed checkpoint held (stored capability rows this process cannot rebuild keep the previous chunker's points); the next pass retries",
1128
+ );
1129
+ }
1130
+ } catch (err) {
1131
+ outcome.failures.push("reembed");
1132
+ log.warn(
1133
+ { err: err instanceof Error ? err.message : String(err) },
1134
+ "memory-v3 maintain: deferred embed commit failed (non-fatal)",
1135
+ );
1136
+ }
1137
+ }
1138
+
914
1139
  // Stage 4: validate the maintainer-curated core set. Diff `core-pages.md`
915
1140
  // entries against the live page-index slugs and REPORT dangling entries
916
1141
  // (pages that were renamed or deleted) through the log + outcome — the file
@@ -976,6 +1201,7 @@ export async function maintainJob(
976
1201
  {
977
1202
  reembedded: outcome.reembedded,
978
1203
  reembedFailures: outcome.reembedFailures,
1204
+ unrebuiltCapabilityRows: outcome.unrebuiltCapabilityRows,
979
1205
  capabilitiesReconciled: outcome.capabilitiesReconciled,
980
1206
  reconcileFailures: outcome.reconcileFailures,
981
1207
  pruned: outcome.pruned,