@vellumai/assistant 0.10.1 → 0.10.2-dev.202606241743.799fce7

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 (372) hide show
  1. package/docs/workspace-tools.md +42 -33
  2. package/eslint-rules/cli-no-daemon-internals.js +6 -0
  3. package/node_modules/@vellumai/gateway-client/src/__tests__/guardian-delivery-contract.test.ts +91 -0
  4. package/node_modules/@vellumai/gateway-client/src/__tests__/trust-verdict-contract.test.ts +31 -0
  5. package/node_modules/@vellumai/gateway-client/src/guardian-delivery-contract.ts +48 -0
  6. package/node_modules/@vellumai/gateway-client/src/index.ts +14 -0
  7. package/node_modules/@vellumai/gateway-client/src/trust-verdict-contract.ts +17 -0
  8. package/openapi.yaml +74 -1
  9. package/package.json +1 -1
  10. package/scripts/test.sh +36 -15
  11. package/src/__tests__/actor-token-service.test.ts +36 -14
  12. package/src/__tests__/agent-loop-override-profile.test.ts +1 -0
  13. package/src/__tests__/agent-wake-disk-pressure-callsite.test.ts +2 -0
  14. package/src/__tests__/agent-wake-override-profile.test.ts +2 -0
  15. package/src/__tests__/annotate-activity-metadata.test.ts +2 -0
  16. package/src/__tests__/annotate-risk-options.test.ts +2 -0
  17. package/src/__tests__/approval-cascade.test.ts +2 -0
  18. package/src/__tests__/background-workers-disk-pressure.test.ts +2 -0
  19. package/src/__tests__/btw-routes.test.ts +2 -0
  20. package/src/__tests__/build-persisted-content.test.ts +2 -0
  21. package/src/__tests__/call-controller.test.ts +19 -0
  22. package/src/__tests__/channel-guardian.test.ts +94 -58
  23. package/src/__tests__/channel-reply-delivery.test.ts +2 -0
  24. package/src/__tests__/compaction-events.test.ts +2 -0
  25. package/src/__tests__/compaction.benchmark.test.ts +2 -0
  26. package/src/__tests__/compactor-call-site-logging.test.ts +2 -0
  27. package/src/__tests__/compactor-low-watermark-cut.test.ts +2 -0
  28. package/src/__tests__/compactor-preserved-tail-count.test.ts +2 -0
  29. package/src/__tests__/compactor-summary-call-truncation.test.ts +2 -0
  30. package/src/__tests__/compactor-web-search-strip.test.ts +2 -0
  31. package/src/__tests__/computer-use-tools.test.ts +13 -0
  32. package/src/__tests__/config-loader-backfill.test.ts +5 -1
  33. package/src/__tests__/config-schema.test.ts +1 -0
  34. package/src/__tests__/confirmation-request-guardian-bridge.test.ts +31 -29
  35. package/src/__tests__/contacts-relay-reads.test.ts +13 -15
  36. package/src/__tests__/conversation-abort-tool-results.test.ts +2 -0
  37. package/src/__tests__/conversation-agent-loop-disk-pressure.test.ts +2 -0
  38. package/src/__tests__/conversation-agent-loop-inference-profile.test.ts +2 -0
  39. package/src/__tests__/conversation-agent-loop-overflow.test.ts +2 -0
  40. package/src/__tests__/conversation-agent-loop.test.ts +7 -0
  41. package/src/__tests__/conversation-analysis-routes.test.ts +2 -0
  42. package/src/__tests__/conversation-app-control-lifecycle.test.ts +2 -0
  43. package/src/__tests__/conversation-confirmation-signals.test.ts +2 -0
  44. package/src/__tests__/conversation-history-web-search.test.ts +2 -0
  45. package/src/__tests__/conversation-load-history-repair.test.ts +2 -0
  46. package/src/__tests__/conversation-load-history-stripped.test.ts +2 -0
  47. package/src/__tests__/conversation-pairing.test.ts +2 -0
  48. package/src/__tests__/conversation-process-app-control-preactivation.test.ts +2 -0
  49. package/src/__tests__/conversation-process-callsite.test.ts +2 -0
  50. package/src/__tests__/conversation-provider-retry-repair.test.ts +2 -0
  51. package/src/__tests__/conversation-queue.test.ts +91 -0
  52. package/src/__tests__/conversation-routes-guardian-reply.test.ts +14 -0
  53. package/src/__tests__/conversation-routes-slash-commands.test.ts +14 -0
  54. package/src/__tests__/conversation-slash-queue.test.ts +2 -0
  55. package/src/__tests__/conversation-slash-unknown.test.ts +2 -0
  56. package/src/__tests__/conversation-speed-override.test.ts +2 -0
  57. package/src/__tests__/conversation-surfaces-action-delivery.test.ts +65 -0
  58. package/src/__tests__/conversation-title-service.test.ts +2 -0
  59. package/src/__tests__/conversation-tool-setup-attribution.test.ts +47 -0
  60. package/src/__tests__/conversation-usage.test.ts +2 -0
  61. package/src/__tests__/conversation-workspace-cache-state.test.ts +2 -0
  62. package/src/__tests__/conversation-workspace-injection.test.ts +2 -0
  63. package/src/__tests__/conversation-workspace-tool-tracking.test.ts +2 -0
  64. package/src/__tests__/credential-security-invariants.test.ts +0 -1
  65. package/src/__tests__/db-migration-rollback.test.ts +205 -171
  66. package/src/__tests__/db-test-helpers.ts +5 -4
  67. package/src/__tests__/deterministic-verification-control-plane.test.ts +4 -2
  68. package/src/__tests__/disk-pressure-guard.test.ts +41 -0
  69. package/src/__tests__/dm-persistence.test.ts +2 -0
  70. package/src/__tests__/emit-signal-routing-intent.test.ts +10 -5
  71. package/src/__tests__/events-dev-bypass-actor.test.ts +7 -1
  72. package/src/__tests__/filing-service.test.ts +2 -0
  73. package/src/__tests__/guardian-binding-drift-heal.test.ts +75 -10
  74. package/src/__tests__/guardian-dispatch.test.ts +95 -1
  75. package/src/__tests__/guardian-outbound-http.test.ts +13 -0
  76. package/src/__tests__/heartbeat-disk-pressure.test.ts +2 -0
  77. package/src/__tests__/heartbeat-service.test.ts +2 -0
  78. package/src/__tests__/helpers/channel-test-adapter.ts +1 -7
  79. package/src/__tests__/host-app-control-routes.test.ts +24 -30
  80. package/src/__tests__/host-bash-routes.test.ts +31 -41
  81. package/src/__tests__/host-browser-routes.test.ts +26 -32
  82. package/src/__tests__/host-cu-proxy.test.ts +299 -0
  83. package/src/__tests__/host-cu-routes-targeted.test.ts +25 -33
  84. package/src/__tests__/host-file-routes-targeted.test.ts +40 -52
  85. package/src/__tests__/host-transfer-routes-targeted.test.ts +31 -43
  86. package/src/__tests__/http-user-message-parity.test.ts +167 -8
  87. package/src/__tests__/inbound-slack-persistence.test.ts +2 -0
  88. package/src/__tests__/invite-redemption-service.test.ts +43 -0
  89. package/src/__tests__/llm-context-normalization.test.ts +105 -0
  90. package/src/__tests__/llm-usage-store.test.ts +25 -0
  91. package/src/__tests__/media-stream-server-integration.test.ts +127 -0
  92. package/src/__tests__/memory-retrieval-hook.test.ts +2 -0
  93. package/src/__tests__/messaging-send-tool.test.ts +2 -0
  94. package/src/__tests__/migration-import-from-url.test.ts +2 -2
  95. package/src/__tests__/mtime-cache.test.ts +146 -5
  96. package/src/__tests__/native-web-search.test.ts +2 -0
  97. package/src/__tests__/non-member-access-request.test.ts +189 -17
  98. package/src/__tests__/notification-broadcaster.test.ts +4 -0
  99. package/src/__tests__/notification-decision-recipient-context.test.ts +33 -32
  100. package/src/__tests__/notification-deep-link.test.ts +6 -0
  101. package/src/__tests__/notification-guardian-path.test.ts +19 -0
  102. package/src/__tests__/outbound-slack-persistence.test.ts +2 -0
  103. package/src/__tests__/pending-interactions-resolved-event.test.ts +7 -4
  104. package/src/__tests__/persistence-secret-redaction.test.ts +2 -0
  105. package/src/__tests__/plugin-bootstrap.test.ts +3 -73
  106. package/src/__tests__/plugin-route-contribution.test.ts +4 -17
  107. package/src/__tests__/plugin-tool-contribution.test.ts +3 -18
  108. package/src/__tests__/plugin-types.test.ts +0 -2
  109. package/src/__tests__/process-message-background-slack.test.ts +2 -0
  110. package/src/__tests__/process-message-display-content.test.ts +2 -0
  111. package/src/__tests__/provider-usage-tracking.test.ts +39 -0
  112. package/src/__tests__/regenerate-fire-and-forget-trace.test.ts +2 -0
  113. package/src/__tests__/registry.test.ts +3 -0
  114. package/src/__tests__/relay-server.test.ts +694 -25
  115. package/src/__tests__/runtime-attachment-metadata.test.ts +0 -1
  116. package/src/__tests__/secret-ingress-http.test.ts +14 -0
  117. package/src/__tests__/send-endpoint-busy.test.ts +30 -8
  118. package/src/__tests__/skills.test.ts +44 -0
  119. package/src/__tests__/slack-inbound-verification.test.ts +47 -2
  120. package/src/__tests__/sse-actor-principal-guardian-source.test.ts +102 -0
  121. package/src/__tests__/steer-on-enqueue-question.test.ts +181 -0
  122. package/src/__tests__/stt-hints.test.ts +44 -13
  123. package/src/__tests__/subagent-detail.test.ts +27 -0
  124. package/src/__tests__/subagent-disposal.test.ts +65 -0
  125. package/src/__tests__/subagent-notify-parent.test.ts +2 -0
  126. package/src/__tests__/subagent-spawn-tool-fork.test.ts +2 -0
  127. package/src/__tests__/subagent-tools.test.ts +2 -0
  128. package/src/__tests__/suggestion-routes.test.ts +2 -0
  129. package/src/__tests__/title-generate-hook.test.ts +2 -0
  130. package/src/__tests__/tool-executor-lifecycle-events.test.ts +2 -0
  131. package/src/__tests__/tool-executor.test.ts +16 -11
  132. package/src/__tests__/tool-preview-lifecycle.test.ts +2 -0
  133. package/src/__tests__/tool-result-metadata-plumbing.test.ts +2 -0
  134. package/src/__tests__/tool-start-timestamp.test.ts +2 -0
  135. package/src/__tests__/trusted-contact-inline-approval-integration.test.ts +10 -10
  136. package/src/__tests__/twilio-routes.test.ts +96 -0
  137. package/src/__tests__/verification-control-plane-policy.test.ts +2 -0
  138. package/src/__tests__/web-search-backend-failure.test.ts +2 -0
  139. package/src/__tests__/workspace-migration-remove-hooks.test.ts +14 -35
  140. package/src/__tests__/workspace-tool-loader.test.ts +195 -2
  141. package/src/agent/loop-exclusive-tool.test.ts +150 -0
  142. package/src/agent/loop.ts +56 -0
  143. package/src/api/constants/sse-replay.ts +41 -0
  144. package/src/api/index.ts +6 -0
  145. package/src/api/responses/llm-request-log-entry.ts +25 -0
  146. package/src/api/responses/subagent-detail.ts +17 -0
  147. package/src/calls/__tests__/relay-setup-router.test.ts +262 -4
  148. package/src/calls/call-domain.ts +3 -3
  149. package/src/calls/guardian-dispatch.ts +10 -8
  150. package/src/calls/inbound-trust-reader.ts +17 -1
  151. package/src/calls/media-stream-server.ts +21 -0
  152. package/src/calls/relay-server.ts +167 -50
  153. package/src/calls/relay-setup-router.ts +37 -7
  154. package/src/calls/relay-verification.ts +4 -4
  155. package/src/calls/stt-hints.ts +9 -12
  156. package/src/calls/twilio-routes.ts +14 -4
  157. package/src/cli/commands/__tests__/cache.test.ts +8 -1
  158. package/src/cli/commands/cache.ts +194 -181
  159. package/src/cli/commands/db/__tests__/repair.test.ts +6 -5
  160. package/src/cli/commands/db/status.ts +37 -1
  161. package/src/cli/commands/mcp.ts +252 -218
  162. package/src/cli/commands/memory/__tests__/worker.test.ts +302 -0
  163. package/src/cli/commands/memory/index.ts +2 -0
  164. package/src/cli/commands/memory/worker.ts +175 -0
  165. package/src/cli/commands/plugins.ts +75 -3
  166. package/src/cli/lib/__tests__/install-from-github.test.ts +102 -0
  167. package/src/cli/lib/__tests__/list-installed-plugins.test.ts +160 -1
  168. package/src/cli/lib/list-installed-plugins.ts +179 -1
  169. package/src/config/__tests__/loader-callsite-strip-fallback.test.ts +143 -0
  170. package/src/config/bundled-skills/computer-use/TOOLS.json +6 -1
  171. package/src/config/bundled-skills/contacts/tools/contact-merge.ts +27 -17
  172. package/src/config/bundled-skills/contacts/tools/contact-search.ts +13 -3
  173. package/src/config/feature-flag-registry.json +0 -8
  174. package/src/config/loader.ts +36 -5
  175. package/src/config/schemas/__tests__/memory-v3.test.ts +1 -0
  176. package/src/config/schemas/memory-lifecycle.ts +12 -0
  177. package/src/config/schemas/memory-v3.ts +7 -0
  178. package/src/config/schemas/memory.ts +4 -0
  179. package/src/config/schemas/timeouts.ts +8 -0
  180. package/src/config/seed-inference-profiles.ts +14 -5
  181. package/src/config/skills.ts +27 -5
  182. package/src/contacts/__tests__/guardian-delivery-reader.test.ts +312 -0
  183. package/src/contacts/contacts-write.ts +3 -0
  184. package/src/contacts/guardian-delivery-reader.ts +223 -0
  185. package/src/daemon/conversation-agent-loop.ts +9 -0
  186. package/src/daemon/conversation-process.ts +39 -17
  187. package/src/daemon/conversation-surfaces.ts +93 -36
  188. package/src/daemon/conversation-tool-setup.ts +49 -16
  189. package/src/daemon/conversation.ts +21 -2
  190. package/src/daemon/disk-pressure-guard.ts +12 -2
  191. package/src/daemon/event-loop-watchdog.ts +28 -1
  192. package/src/daemon/external-plugins-bootstrap.ts +4 -34
  193. package/src/daemon/handlers/__tests__/config-a2a-redeem.test.ts +25 -0
  194. package/src/daemon/handlers/__tests__/config-channels.test.ts +225 -0
  195. package/src/daemon/handlers/config-a2a.ts +6 -14
  196. package/src/daemon/handlers/config-channels.ts +78 -22
  197. package/src/daemon/handlers/conversations.ts +77 -0
  198. package/src/daemon/host-cu-proxy.ts +102 -11
  199. package/src/daemon/lifecycle.ts +4 -0
  200. package/src/daemon/memory-v2-startup.test.ts +72 -0
  201. package/src/daemon/memory-v2-startup.ts +87 -19
  202. package/src/daemon/server.ts +0 -4
  203. package/src/daemon/shutdown-handlers.ts +20 -0
  204. package/src/daemon/tool-setup-types.ts +9 -0
  205. package/src/hooks/hook-loader.ts +341 -0
  206. package/src/ipc/__tests__/clients-list-ipc.test.ts +1 -1
  207. package/src/ipc/assistant-server.ts +2 -2
  208. package/src/memory/__tests__/301-create-watchdog-events.test.ts +110 -0
  209. package/src/memory/__tests__/memory-retrospective-job.test.ts +8 -0
  210. package/src/memory/__tests__/prompt-override.test.ts +192 -0
  211. package/src/memory/__tests__/watchdog-events-store.test.ts +161 -0
  212. package/src/memory/conversation-crud.ts +38 -0
  213. package/src/memory/db-connection.ts +22 -3
  214. package/src/memory/db-init.ts +36 -502
  215. package/src/memory/db-singleton.ts +6 -4
  216. package/src/memory/jobs-worker.ts +58 -0
  217. package/src/memory/llm-usage-store.ts +48 -20
  218. package/src/memory/memory-retrospective-job.ts +9 -8
  219. package/src/memory/migrations/014-backfill-inbox-thread-state.ts +13 -3
  220. package/src/memory/migrations/136-drop-assistant-id-columns.ts +52 -27
  221. package/src/memory/migrations/209-strip-thinking-from-consolidated.ts +130 -56
  222. package/src/memory/migrations/300-add-processing-started-at.ts +30 -0
  223. package/src/memory/migrations/301-create-watchdog-events.ts +45 -0
  224. package/src/memory/migrations/__tests__/014-backfill-inbox-thread-state.test.ts +108 -0
  225. package/src/memory/migrations/__tests__/136-drop-assistant-id-columns.test.ts +82 -0
  226. package/src/memory/migrations/__tests__/209-strip-thinking-from-consolidated.test.ts +224 -0
  227. package/src/memory/migrations/__tests__/run-migrations.test.ts +2 -2
  228. package/src/memory/migrations/run-migrations.ts +90 -6
  229. package/src/memory/migrations/schema-introspection.ts +14 -0
  230. package/src/memory/migrations/validate-migration-state.ts +101 -66
  231. package/src/memory/prompt-override.ts +129 -0
  232. package/src/memory/schema/conversations.ts +9 -0
  233. package/src/memory/schema/infrastructure.ts +20 -0
  234. package/src/memory/steps.ts +573 -0
  235. package/src/memory/v2/__tests__/cli-command-store.test.ts +25 -0
  236. package/src/memory/v2/__tests__/skill-store.test.ts +80 -0
  237. package/src/memory/v2/cli-command-store.ts +75 -38
  238. package/src/memory/v2/prompts/consolidation.ts +13 -82
  239. package/src/memory/v2/prompts/router.ts +21 -93
  240. package/src/memory/v2/skill-store.ts +68 -31
  241. package/src/memory/watchdog-events-store.ts +87 -0
  242. package/src/memory/worker-control.ts +118 -0
  243. package/src/memory/worker-process.ts +72 -0
  244. package/src/notifications/__tests__/broadcaster.test.ts +16 -8
  245. package/src/notifications/__tests__/connected-channels.test.ts +114 -0
  246. package/src/notifications/__tests__/decision-engine.test.ts +78 -9
  247. package/src/notifications/__tests__/destination-resolver.test.ts +256 -0
  248. package/src/notifications/broadcaster.ts +8 -1
  249. package/src/notifications/decision-engine.ts +15 -7
  250. package/src/notifications/destination-resolver.ts +68 -24
  251. package/src/notifications/emit-signal.ts +39 -14
  252. package/src/onboarding/checkin-event.test.ts +220 -0
  253. package/src/onboarding/checkin-event.ts +321 -0
  254. package/src/onboarding/schedule-checkin.ts +190 -0
  255. package/src/permissions/question-prompter.test.ts +1 -1
  256. package/src/permissions/question-prompter.ts +7 -4
  257. package/src/plugin-api/index.ts +6 -6
  258. package/src/plugin-api/types.ts +3 -5
  259. package/src/plugin-api/vision-support.test.ts +28 -4
  260. package/src/plugin-api/vision-support.ts +66 -31
  261. package/src/plugins/defaults/advisor/__tests__/consult.test.ts +161 -0
  262. package/src/plugins/defaults/advisor/__tests__/context-pack-gating.test.ts +106 -0
  263. package/src/plugins/defaults/advisor/__tests__/context-pack.test.ts +60 -0
  264. package/src/plugins/defaults/advisor/consult.ts +110 -6
  265. package/src/plugins/defaults/advisor/context-pack.ts +288 -0
  266. package/src/plugins/defaults/advisor/steering.ts +14 -2
  267. package/src/plugins/defaults/advisor/tools/advisor.ts +32 -5
  268. package/src/plugins/defaults/image-fallback/__tests__/image-fallback.test.ts +47 -7
  269. package/src/plugins/defaults/image-fallback/hooks/post-tool-use.ts +10 -11
  270. package/src/plugins/defaults/image-fallback/hooks/user-prompt-submit.ts +12 -20
  271. package/src/plugins/defaults/image-fallback/src/caption-blocks.ts +42 -11
  272. package/src/plugins/defaults/memory-v3-shadow/orchestrate.ts +11 -2
  273. package/src/plugins/defaults/memory-v3-shadow/pool-select.test.ts +146 -0
  274. package/src/plugins/defaults/memory-v3-shadow/pool-select.ts +29 -1
  275. package/src/plugins/defaults/memory-v3-shadow/shadow-plugin.ts +8 -1
  276. package/src/plugins/mtime-cache.ts +76 -291
  277. package/src/plugins/surface-import.ts +121 -0
  278. package/src/plugins/types.ts +0 -2
  279. package/src/providers/anthropic/client.ts +5 -0
  280. package/src/providers/call-site-routing.ts +4 -0
  281. package/src/providers/model-catalog.ts +16 -0
  282. package/src/providers/openai/responses-provider.ts +5 -0
  283. package/src/providers/openrouter/client.ts +5 -0
  284. package/src/providers/provider-send-message.ts +4 -0
  285. package/src/providers/ratelimit.ts +4 -0
  286. package/src/providers/retry.ts +4 -0
  287. package/src/providers/types.ts +9 -0
  288. package/src/providers/usage-tracking.ts +4 -0
  289. package/src/runtime/__tests__/channel-verification-service.test.ts +133 -0
  290. package/src/runtime/__tests__/guardian-vellum-migration.test.ts +181 -0
  291. package/src/runtime/__tests__/is-guardian-bound-for-channel.test.ts +66 -0
  292. package/src/runtime/__tests__/local-principal-trust.test.ts +164 -0
  293. package/src/runtime/__tests__/trust-verdict-consumer.test.ts +335 -3
  294. package/src/runtime/access-request-helper.ts +19 -39
  295. package/src/runtime/actor-trust-resolver.ts +2 -2
  296. package/src/runtime/anchored-guardian.test.ts +156 -0
  297. package/src/runtime/anchored-guardian.ts +135 -0
  298. package/src/runtime/assistant-event-hub.ts +1 -1
  299. package/src/runtime/assistant-stream-state.ts +9 -2
  300. package/src/runtime/auth/__tests__/require-bound-guardian.test.ts +99 -0
  301. package/src/runtime/auth/require-bound-guardian.ts +21 -11
  302. package/src/runtime/channel-verification-service.ts +56 -31
  303. package/src/runtime/confirmation-request-guardian-bridge.ts +3 -3
  304. package/src/runtime/guardian-vellum-migration.ts +66 -7
  305. package/src/runtime/invite-redemption-service.ts +50 -18
  306. package/src/runtime/local-actor-identity.ts +76 -11
  307. package/src/runtime/local-principal-trust.ts +52 -0
  308. package/src/runtime/pending-interactions.ts +11 -1
  309. package/src/runtime/routes/__tests__/channel-verification-revoke.test.ts +56 -5
  310. package/src/runtime/routes/__tests__/channel-verification-routes.test.ts +1 -1
  311. package/src/runtime/routes/__tests__/contact-routes.test.ts +212 -0
  312. package/src/runtime/routes/__tests__/global-search-routes.test.ts +93 -0
  313. package/src/runtime/routes/__tests__/surface-action-routes.test.ts +215 -1
  314. package/src/runtime/routes/browser-routes.ts +1 -1
  315. package/src/runtime/routes/channel-verification-routes.ts +3 -3
  316. package/src/runtime/routes/contact-routes.ts +8 -32
  317. package/src/runtime/routes/conversation-cli-routes.ts +4 -5
  318. package/src/runtime/routes/conversation-list-routes.ts +4 -7
  319. package/src/runtime/routes/conversation-routes.ts +74 -81
  320. package/src/runtime/routes/events-routes.ts +2 -2
  321. package/src/runtime/routes/global-search-routes.ts +3 -1
  322. package/src/runtime/routes/guardian-action-routes.ts +4 -5
  323. package/src/runtime/routes/host-app-control-routes.ts +5 -4
  324. package/src/runtime/routes/host-bash-routes.ts +5 -4
  325. package/src/runtime/routes/host-browser-routes.ts +9 -11
  326. package/src/runtime/routes/host-cu-routes.ts +5 -4
  327. package/src/runtime/routes/host-file-routes.ts +5 -4
  328. package/src/runtime/routes/host-transfer-routes.ts +6 -6
  329. package/src/runtime/routes/http-adapter.ts +1 -1
  330. package/src/runtime/routes/identity-routes.ts +3 -2
  331. package/src/runtime/routes/inbound-message-handler.ts +5 -5
  332. package/src/runtime/routes/inbound-stages/acl-enforcement.test.ts +97 -5
  333. package/src/runtime/routes/inbound-stages/acl-enforcement.ts +61 -49
  334. package/src/runtime/routes/inbound-stages/background-dispatch.ts +16 -4
  335. package/src/runtime/routes/inbound-stages/escalation-intercept.ts +7 -7
  336. package/src/runtime/routes/inbound-stages/guardian-activation-intercept.test.ts +21 -8
  337. package/src/runtime/routes/inbound-stages/guardian-activation-intercept.ts +14 -3
  338. package/src/runtime/routes/index.ts +2 -0
  339. package/src/runtime/routes/llm-context-normalization.ts +71 -0
  340. package/src/runtime/routes/mcp-auth-routes.ts +38 -15
  341. package/src/runtime/routes/migration-rollback-routes.ts +4 -3
  342. package/src/runtime/routes/migration-routes.ts +4 -1
  343. package/src/runtime/routes/onboarding-checkin-routes.ts +86 -0
  344. package/src/runtime/routes/subagents-routes.ts +5 -0
  345. package/src/runtime/routes/surface-action-routes.ts +51 -55
  346. package/src/runtime/services/__tests__/conversation-serializer.test.ts +1 -0
  347. package/src/runtime/services/conversation-serializer.ts +7 -9
  348. package/src/runtime/tool-grant-request-helper.ts +3 -3
  349. package/src/runtime/trust-verdict-consumer.ts +85 -9
  350. package/src/runtime/verification-outbound-actions.ts +18 -18
  351. package/src/signals/user-message.ts +16 -0
  352. package/src/subagent/manager.ts +9 -0
  353. package/src/telemetry/types.ts +34 -1
  354. package/src/telemetry/usage-telemetry-reporter.test.ts +3 -2
  355. package/src/telemetry/usage-telemetry-reporter.ts +87 -3
  356. package/src/tools/ask-question/ask-question-tool.test.ts +29 -0
  357. package/src/tools/ask-question/ask-question-tool.ts +13 -0
  358. package/src/tools/computer-use/definitions.ts +8 -2
  359. package/src/tools/executor.ts +4 -4
  360. package/src/tools/registry.ts +18 -0
  361. package/src/tools/tool-approval-handler.ts +1 -1
  362. package/src/tools/tool-defaults.ts +9 -2
  363. package/src/tools/types.ts +17 -2
  364. package/src/tools/workspace-tools/loader.ts +348 -244
  365. package/src/util/platform.ts +5 -0
  366. package/src/util/telemetry-db-path.ts +24 -0
  367. package/src/workspace/migrations/017-seed-persona-dirs.ts +3 -34
  368. package/src/workspace/migrations/019-scope-journal-to-guardian.ts +3 -24
  369. package/src/workspace/migrations/048-remove-workspace-hooks.ts +14 -66
  370. package/src/__tests__/workspace-tools-watcher-flag.test.ts +0 -70
  371. package/src/daemon/workspace-tools-watcher.ts +0 -328
  372. package/src/memory/migrations/registry.ts +0 -573
@@ -8,15 +8,16 @@
8
8
 
9
9
  import { randomInt } from "node:crypto";
10
10
 
11
- import type { AdmissionPolicy } from "@vellumai/gateway-client";
11
+ import type { AdmissionPolicy, TrustVerdict } from "@vellumai/gateway-client";
12
12
  import type { ServerWebSocket } from "bun";
13
13
 
14
14
  import {
15
- findGuardianForChannel,
16
- listGuardianChannels,
17
- } from "../contacts/contact-store.js";
15
+ getGuardianDelivery,
16
+ voiceGuardianDisplayName,
17
+ } from "../contacts/guardian-delivery-reader.js";
18
18
  import { getAssistantName } from "../daemon/identity-helpers.js";
19
19
  import type { ServerMessage } from "../daemon/message-protocol.js";
20
+ import type { TrustContext } from "../daemon/trust-context.js";
20
21
  import { getCanonicalGuardianRequest } from "../memory/canonical-guardian-store.js";
21
22
  import { addMessage } from "../memory/conversation-crud.js";
22
23
  import { revokeScopedApprovalGrantsForContext } from "../memory/scoped-approval-grants.js";
@@ -26,6 +27,11 @@ import {
26
27
  resolveActorTrust,
27
28
  toTrustContext,
28
29
  } from "../runtime/actor-trust-resolver.js";
30
+ import {
31
+ trustContextFromVerdict,
32
+ verdictHasMemberIdentity,
33
+ verdictMemberUnresolvable,
34
+ } from "../runtime/trust-verdict-consumer.js";
29
35
  import {
30
36
  composeVerificationVoice,
31
37
  GUARDIAN_VERIFY_TEMPLATE_KEYS,
@@ -50,6 +56,10 @@ import {
50
56
  import { ConversationRelayTransport } from "./call-transport.js";
51
57
  import { getChannelAdmissionPolicy } from "./channel-admission-reader.js";
52
58
  import { finalizeCall } from "./finalize-call.js";
59
+ import {
60
+ getInboundTrustVerdict,
61
+ getPhoneCallerVerdict,
62
+ } from "./inbound-trust-reader.js";
53
63
  import {
54
64
  classifyWaitUtterance,
55
65
  emitAccessRequestCallbackHandoff,
@@ -252,6 +262,10 @@ export class RelayConnection {
252
262
  private accessRequestWaitStartedAt: number = 0;
253
263
  private heartbeatSequence = 0;
254
264
 
265
+ // Guardian displayName primed from the gateway binding at setup, read
266
+ // synchronously by the heartbeat-driven wait-label path.
267
+ private primedGuardianDisplayName: string | undefined;
268
+
255
269
  // In-wait prompt handling state
256
270
  private lastInWaitReplyAt = 0;
257
271
  private static readonly IN_WAIT_REPLY_COOLDOWN_MS = 3000;
@@ -261,6 +275,12 @@ export class RelayConnection {
261
275
  private callbackOptIn = false;
262
276
  private callbackHandoffNotified = false;
263
277
 
278
+ // True while mid-call trust is being re-resolved (async). handlePrompt defers
279
+ // prompts to trustReResolvePending so a verified caller can't start a turn
280
+ // under the stale pre-verification trust context during the await window.
281
+ private trustReResolving = false;
282
+ private trustReResolvePending: RelayPromptMessage[] = [];
283
+
264
284
  constructor(ws: ServerWebSocket<RelayWebSocketData>, callSessionId: string) {
265
285
  this.ws = ws;
266
286
  this.callSessionId = callSessionId;
@@ -581,12 +601,21 @@ export class RelayConnection {
581
601
  const session = getCallSession(this.callSessionId);
582
602
  this.recordSetupBookkeeping(session, msg);
583
603
 
604
+ await this.primeGuardianDisplayName();
605
+
584
606
  // Resolve the phone channel's inbound admission floor. The reader fails
585
607
  // open to `null` by contract, so a transport hiccup admits the caller.
586
608
  const admissionPolicy = await getChannelAdmissionPolicy("phone");
587
609
 
610
+ // Verdict-first caller trust. routeSetup uses it when present and not
611
+ // resolutionFailed, else falls back to local resolution. The reader
612
+ // returns null on failure, so a gateway blip keeps the local path.
613
+ const isInbound = session?.initiatedFromConversationId == null;
614
+ const otherPartyNumber = isInbound ? msg.from : msg.to;
615
+ const verdict = await getPhoneCallerVerdict(otherPartyNumber);
616
+
588
617
  try {
589
- await this.routeSetupOutcome(msg, session, admissionPolicy);
618
+ await this.routeSetupOutcome(msg, session, admissionPolicy, verdict);
590
619
  } catch (err) {
591
620
  // Never leave the connection stranded in "setting_up": a setup that
592
621
  // throws before reaching a terminal outcome would otherwise drop every
@@ -615,6 +644,7 @@ export class RelayConnection {
615
644
  msg: RelaySetupMessage,
616
645
  session: ReturnType<typeof getCallSession>,
617
646
  admissionPolicy: AdmissionPolicy | null,
647
+ verdict: TrustVerdict | null,
618
648
  ): Promise<void> {
619
649
  const { outcome, resolved } = routeSetup({
620
650
  callSessionId: this.callSessionId,
@@ -623,6 +653,7 @@ export class RelayConnection {
623
653
  to: msg.to,
624
654
  customParameters: msg.customParameters,
625
655
  admissionPolicy,
656
+ verdict,
626
657
  });
627
658
 
628
659
  const initialTrustContext = toTrustContext(
@@ -871,6 +902,95 @@ export class RelayConnection {
871
902
  );
872
903
  }
873
904
 
905
+ /**
906
+ * Re-resolve caller trust after a mid-call verification/activation. Prefers
907
+ * the gateway verdict (authoritative right after the gateway updated the
908
+ * binding); falls back to local resolution on a missing/failed/unusable
909
+ * verdict so a blip never drops the call. Mirrors the setup path's
910
+ * verdict-first-with-fallback condition.
911
+ */
912
+ private async resolveMidCallTrustContext(
913
+ assistantId: string,
914
+ fromNumber: string,
915
+ ): Promise<TrustContext> {
916
+ const verdict = await getInboundTrustVerdict({
917
+ channelType: "phone",
918
+ actorExternalId: fromNumber,
919
+ });
920
+
921
+ // Only a MEMBERLESS unknown verdict is treated as a stale gateway view and
922
+ // falls back to local: the caller was just activated, and invite redemption
923
+ // writes the channel assistant-side, so the gateway may not see the member
924
+ // yet — local resolution has it. A MEMBERFUL unknown verdict (blocked/revoked
925
+ // member, carrying contactId/channelId) is honored so its deny ACL is
926
+ // enforced; falling back could lose the gateway's member status if local
927
+ // state is stale.
928
+ const memberlessUnknown =
929
+ verdict?.trustClass === "unknown" && !verdictHasMemberIdentity(verdict);
930
+ const usable =
931
+ verdict &&
932
+ !verdict.resolutionFailed &&
933
+ !verdictMemberUnresolvable(verdict) &&
934
+ !memberlessUnknown;
935
+
936
+ if (usable) {
937
+ return trustContextFromVerdict(verdict, {
938
+ sourceChannel: "phone",
939
+ conversationExternalId: fromNumber,
940
+ });
941
+ }
942
+
943
+ return toTrustContext(
944
+ resolveActorTrust({
945
+ assistantId,
946
+ sourceChannel: "phone",
947
+ conversationExternalId: fromNumber,
948
+ actorExternalId: fromNumber,
949
+ }),
950
+ fromNumber,
951
+ );
952
+ }
953
+
954
+ /**
955
+ * Re-resolve mid-call trust and install it on the controller, deferring any
956
+ * prompt that arrives during the async window. Guards the gap between
957
+ * connectionState flipping to "connected" and the upgraded context landing so
958
+ * a verified caller never starts a turn under the stale pre-verification
959
+ * trust. Clears the guard in a finally and flushes buffered prompts under the
960
+ * new context, so an IPC error can't wedge the call.
961
+ */
962
+ private async reResolveAndApplyTrustContext(
963
+ assistantId: string,
964
+ fromNumber: string,
965
+ ): Promise<void> {
966
+ if (!this.controller) return;
967
+ this.trustReResolving = true;
968
+ try {
969
+ const context = await this.resolveMidCallTrustContext(
970
+ assistantId,
971
+ fromNumber,
972
+ );
973
+ this.controller.setTrustContext(context);
974
+ } finally {
975
+ this.trustReResolving = false;
976
+ this.flushDeferredPrompts();
977
+ }
978
+ }
979
+
980
+ /**
981
+ * Replay prompts buffered while trust was re-resolving. Runs after the
982
+ * upgraded context is installed so deferred utterances are answered under the
983
+ * correct trust.
984
+ */
985
+ private flushDeferredPrompts(): void {
986
+ if (this.trustReResolvePending.length === 0) return;
987
+ const pending = this.trustReResolvePending;
988
+ this.trustReResolvePending = [];
989
+ for (const msg of pending) {
990
+ void this.handlePrompt(msg);
991
+ }
992
+ }
993
+
874
994
  /**
875
995
  * Shared post-activation handoff for all trusted-contact success paths
876
996
  * (access-request approval, invite redemption, verification code).
@@ -878,7 +998,7 @@ export class RelayConnection {
878
998
  * transition copy, and marks the next utterance as opening-ack so the
879
999
  * LLM continues naturally.
880
1000
  */
881
- private continueCallAfterTrustedContactActivation(params: {
1001
+ private async continueCallAfterTrustedContactActivation(params: {
882
1002
  assistantId: string;
883
1003
  fromNumber: string;
884
1004
  activationReason?:
@@ -893,26 +1013,25 @@ export class RelayConnection {
893
1013
  * address.
894
1014
  */
895
1015
  inviteeName?: string | null;
896
- }): void {
1016
+ }): Promise<void> {
897
1017
  const { assistantId, fromNumber } = params;
898
1018
 
899
1019
  // Contact activation is handled by the gateway — the assistant no
900
1020
  // longer writes contact/channel records on inbound voice calls.
901
1021
 
902
- const updatedTrust = resolveActorTrust({
903
- assistantId,
904
- sourceChannel: "phone",
905
- conversationExternalId: fromNumber,
906
- actorExternalId: fromNumber,
907
- });
1022
+ // Reach connected and clear wait/verification flags before re-resolving
1023
+ // trust, so a prompt buffered during re-resolution flushes onto the
1024
+ // real-turn path, not the verification/wait branches.
1025
+ this.connectionState = "connected";
1026
+ this.verificationSessionActive = false;
1027
+ this.inviteRedemptionActive = false;
1028
+ this.accessRequestWaitActive = false;
1029
+ updateCallSession(this.callSessionId, { status: "in_progress" });
908
1030
 
909
1031
  if (this.controller) {
910
- this.controller.setTrustContext(toTrustContext(updatedTrust, fromNumber));
1032
+ await this.reResolveAndApplyTrustContext(assistantId, fromNumber);
911
1033
  }
912
1034
 
913
- this.connectionState = "connected";
914
- updateCallSession(this.callSessionId, { status: "in_progress" });
915
-
916
1035
  const guardianLabel = this.resolveGuardianLabel();
917
1036
  let handoffText: string;
918
1037
 
@@ -1045,7 +1164,7 @@ export class RelayConnection {
1045
1164
  const assistantId = this.verificationAssistantId;
1046
1165
  const fromNumber = this.verificationFromNumber;
1047
1166
 
1048
- const result = attemptVerificationCode({
1167
+ const result = await attemptVerificationCode({
1049
1168
  verificationAssistantId: assistantId,
1050
1169
  verificationFromNumber: fromNumber,
1051
1170
  enteredCode,
@@ -1091,15 +1210,7 @@ export class RelayConnection {
1091
1210
 
1092
1211
  // Update trust context on the controller so the LLM knows this is the guardian
1093
1212
  if (this.controller) {
1094
- const verifiedActorTrust = resolveActorTrust({
1095
- assistantId,
1096
- sourceChannel: "phone",
1097
- conversationExternalId: fromNumber,
1098
- actorExternalId: fromNumber,
1099
- });
1100
- this.controller.setTrustContext(
1101
- toTrustContext(verifiedActorTrust, fromNumber),
1102
- );
1213
+ await this.reResolveAndApplyTrustContext(assistantId, fromNumber);
1103
1214
  }
1104
1215
 
1105
1216
  // Mark session as in-progress and transition to guardian conversation
@@ -1116,7 +1227,7 @@ export class RelayConnection {
1116
1227
  );
1117
1228
  }
1118
1229
  } else if (result.verificationType === "trusted_contact") {
1119
- this.continueCallAfterTrustedContactActivation({
1230
+ await this.continueCallAfterTrustedContactActivation({
1120
1231
  assistantId,
1121
1232
  fromNumber,
1122
1233
  activationReason: "trusted_contact_verified",
@@ -1125,15 +1236,7 @@ export class RelayConnection {
1125
1236
  // Inbound guardian verification: binding already handled above,
1126
1237
  // proceed to normal call flow.
1127
1238
  if (this.controller) {
1128
- const verifiedActorTrust = resolveActorTrust({
1129
- assistantId,
1130
- sourceChannel: "phone",
1131
- conversationExternalId: fromNumber,
1132
- actorExternalId: fromNumber,
1133
- });
1134
- this.controller.setTrustContext(
1135
- toTrustContext(verifiedActorTrust, fromNumber),
1136
- );
1239
+ await this.reResolveAndApplyTrustContext(assistantId, fromNumber);
1137
1240
  this.startNormalCallFlow(this.controller, true);
1138
1241
  }
1139
1242
  }
@@ -1296,7 +1399,7 @@ export class RelayConnection {
1296
1399
  * Creates a canonical access request, notifies the guardian, and
1297
1400
  * enters the bounded wait loop for the guardian decision.
1298
1401
  */
1299
- private handleNameCaptureResponse(callerName: string): void {
1402
+ private async handleNameCaptureResponse(callerName: string): Promise<void> {
1300
1403
  if (!this.accessRequestAssistantId || !this.accessRequestFromNumber) {
1301
1404
  return;
1302
1405
  }
@@ -1317,7 +1420,7 @@ export class RelayConnection {
1317
1420
  // Create canonical access request and notify the guardian, including
1318
1421
  // the caller's spoken name and voice channel metadata.
1319
1422
  try {
1320
- const accessResult = notifyGuardianOfAccessRequest({
1423
+ const accessResult = await notifyGuardianOfAccessRequest({
1321
1424
  canonicalAssistantId: this.accessRequestAssistantId,
1322
1425
  sourceChannel: "phone",
1323
1426
  conversationExternalId: this.accessRequestFromNumber,
@@ -1410,7 +1513,7 @@ export class RelayConnection {
1410
1513
  }
1411
1514
 
1412
1515
  if (request.status === "approved") {
1413
- this.handleAccessRequestApproved();
1516
+ void this.handleAccessRequestApproved();
1414
1517
  } else if (request.status === "denied") {
1415
1518
  void this.handleAccessRequestDenied();
1416
1519
  }
@@ -1462,7 +1565,7 @@ export class RelayConnection {
1462
1565
  * Handle an approved access request: activate the caller as a trusted
1463
1566
  * contact, update runtime context, and continue with normal call flow.
1464
1567
  */
1465
- private handleAccessRequestApproved(): void {
1568
+ private async handleAccessRequestApproved(): Promise<void> {
1466
1569
  this.clearAccessRequestWait();
1467
1570
 
1468
1571
  const assistantId = this.accessRequestAssistantId!;
@@ -1480,7 +1583,7 @@ export class RelayConnection {
1480
1583
  "Access request approved — caller activated and continuing call",
1481
1584
  );
1482
1585
 
1483
- this.continueCallAfterTrustedContactActivation({
1586
+ await this.continueCallAfterTrustedContactActivation({
1484
1587
  assistantId,
1485
1588
  fromNumber,
1486
1589
  activationReason: "access_approved",
@@ -1688,7 +1791,7 @@ export class RelayConnection {
1688
1791
  "Voice invite redemption succeeded",
1689
1792
  );
1690
1793
 
1691
- this.continueCallAfterTrustedContactActivation({
1794
+ await this.continueCallAfterTrustedContactActivation({
1692
1795
  assistantId: this.inviteRedemptionAssistantId,
1693
1796
  fromNumber: this.inviteRedemptionFromNumber,
1694
1797
  activationReason: "invite_redeemed",
@@ -1731,15 +1834,20 @@ export class RelayConnection {
1731
1834
  * Resolve a human-readable guardian label for voice wait copy.
1732
1835
  * Delegates to the shared resolveGuardianName() which checks the
1733
1836
  * guardian's per-user persona file (users/<slug>.md) first, then falls
1734
- * back to Contact.displayName, then DEFAULT_USER_REFERENCE.
1837
+ * back to the primed gateway-binding displayName, then
1838
+ * DEFAULT_USER_REFERENCE.
1735
1839
  */
1736
1840
  private resolveGuardianLabel(): string {
1737
- // Look up the guardian contact for a displayName fallback
1738
- const voiceGuardian = findGuardianForChannel("phone");
1739
- const guardianChannels = voiceGuardian ? null : listGuardianChannels();
1740
- const guardianContact = voiceGuardian?.contact ?? guardianChannels?.contact;
1841
+ return resolveGuardianName(this.primedGuardianDisplayName);
1842
+ }
1741
1843
 
1742
- return resolveGuardianName(guardianContact?.displayName);
1844
+ /**
1845
+ * Prime the guardian displayName from the gateway binding so the
1846
+ * synchronous wait-label path can read it without an IPC round-trip.
1847
+ */
1848
+ private async primeGuardianDisplayName(): Promise<void> {
1849
+ const list = await getGuardianDelivery();
1850
+ this.primedGuardianDisplayName = voiceGuardianDisplayName(list);
1743
1851
  }
1744
1852
 
1745
1853
  /**
@@ -1917,6 +2025,15 @@ export class RelayConnection {
1917
2025
  return;
1918
2026
  }
1919
2027
 
2028
+ // Defer (don't drop) prompts while trust is being re-resolved mid-call so a
2029
+ // verified caller's first utterance runs under the upgraded context, not the
2030
+ // stale pre-verification one. flushDeferredPrompts replays them in order
2031
+ // once the new context lands.
2032
+ if (this.trustReResolving) {
2033
+ this.trustReResolvePending.push(msg);
2034
+ return;
2035
+ }
2036
+
1920
2037
  // Prompts arriving before setup routing/ACL completes are dropped — never
1921
2038
  // persisted or emitted — so a not-yet-authorized caller's speech can't be
1922
2039
  // stored ahead of the admission floor / trust ACL decision.
@@ -1942,7 +2059,7 @@ export class RelayConnection {
1942
2059
  { callSessionId: this.callSessionId, callerName },
1943
2060
  "Name captured from unknown inbound caller",
1944
2061
  );
1945
- this.handleNameCaptureResponse(callerName);
2062
+ await this.handleNameCaptureResponse(callerName);
1946
2063
  return;
1947
2064
  }
1948
2065
 
@@ -6,7 +6,7 @@
6
6
  * next — without performing any side effects itself.
7
7
  */
8
8
 
9
- import type { AdmissionPolicy } from "@vellumai/gateway-client";
9
+ import type { AdmissionPolicy, TrustVerdict } from "@vellumai/gateway-client";
10
10
 
11
11
  import { getConfig } from "../config/loader.js";
12
12
  import { getContact } from "../contacts/contact-store.js";
@@ -21,6 +21,10 @@ import {
21
21
  type AdmissionPolicyResult,
22
22
  enforceAdmissionPolicy,
23
23
  } from "../runtime/routes/inbound-stages/admission-policy.js";
24
+ import {
25
+ actorTrustContextFromVerdict,
26
+ verdictMemberUnresolvable,
27
+ } from "../runtime/trust-verdict-consumer.js";
24
28
  import { getLogger } from "../util/logger.js";
25
29
  import type { CallSession } from "./types.js";
26
30
 
@@ -40,6 +44,12 @@ interface SetupContext {
40
44
  * preserving all pre-admission behavior.
41
45
  */
42
46
  admissionPolicy?: AdmissionPolicy | null;
47
+ /**
48
+ * Gateway-stamped caller trust verdict. When present and not
49
+ * `resolutionFailed`, the caller's trust is built from it; otherwise the
50
+ * router falls back to local resolution.
51
+ */
52
+ verdict?: TrustVerdict | null;
43
53
  }
44
54
 
45
55
  // ── Setup outcomes ───────────────────────────────────────────────────
@@ -112,12 +122,32 @@ export function routeSetup(ctx: SetupContext): {
112
122
  const isInbound = ctx.session?.initiatedFromConversationId == null;
113
123
  const otherPartyNumber = isInbound ? ctx.from : ctx.to;
114
124
 
115
- const actorTrust = resolveActorTrust({
116
- assistantId,
117
- sourceChannel: "phone",
118
- conversationExternalId: otherPartyNumber,
119
- actorExternalId: otherPartyNumber || undefined,
120
- });
125
+ // Verdict-first: build caller trust from the gateway verdict when present.
126
+ // Voice falls back to local resolution on a missing/failed verdict so a
127
+ // gateway blip does not drop a known guardian's call — the deliberate
128
+ // difference from the fail-closed text path.
129
+ //
130
+ // A verdict that claims a member (contactId/channelId) but whose ACL can't be
131
+ // reassembled (malformed/mixed-version status·policy) also falls back to local
132
+ // resolution, so voice never trusts a member it cannot ACL-check. A real
133
+ // stranger verdict (no member identity) still takes the verdict path —
134
+ // memberRecord null is correct there.
135
+ const usable =
136
+ ctx.verdict &&
137
+ !ctx.verdict.resolutionFailed &&
138
+ !verdictMemberUnresolvable(ctx.verdict);
139
+ const actorTrust = usable
140
+ ? actorTrustContextFromVerdict(ctx.verdict!, {
141
+ sourceChannel: "phone",
142
+ conversationExternalId: otherPartyNumber,
143
+ actorDisplayName: undefined,
144
+ })
145
+ : resolveActorTrust({
146
+ assistantId,
147
+ sourceChannel: "phone",
148
+ conversationExternalId: otherPartyNumber,
149
+ actorExternalId: otherPartyNumber || undefined,
150
+ });
121
151
 
122
152
  const resolved: SetupResolved = {
123
153
  assistantId,
@@ -112,9 +112,9 @@ type VerificationCallResult =
112
112
  * so the caller can apply side-effects (state mutations, TTS, session
113
113
  * updates) without this function needing access to the relay connection.
114
114
  */
115
- export function attemptVerificationCode(
115
+ export async function attemptVerificationCode(
116
116
  params: VerificationCallParams,
117
- ): VerificationCallResult {
117
+ ): Promise<VerificationCallResult> {
118
118
  const {
119
119
  verificationAssistantId,
120
120
  verificationFromNumber,
@@ -142,7 +142,7 @@ export function attemptVerificationCode(
142
142
  let canonicalPrincipal: string | undefined;
143
143
 
144
144
  if (result.verificationType === "guardian") {
145
- const existingBinding = getGuardianBinding(
145
+ const existingBinding = await getGuardianBinding(
146
146
  verificationAssistantId,
147
147
  "phone",
148
148
  );
@@ -155,7 +155,7 @@ export function attemptVerificationCode(
155
155
  };
156
156
  } else {
157
157
  // Resolve canonical principal from the vellum channel binding
158
- const vellumBinding = getGuardianBinding(
158
+ const vellumBinding = await getGuardianBinding(
159
159
  verificationAssistantId,
160
160
  "vellum",
161
161
  );
@@ -1,9 +1,8 @@
1
+ import { findContactByAddress, listContacts } from "../contacts/contact-store.js";
1
2
  import {
2
- findContactByAddress,
3
- findGuardianForChannel,
4
- listContacts,
5
- listGuardianChannels,
6
- } from "../contacts/contact-store.js";
3
+ getGuardianDelivery,
4
+ voiceGuardianDisplayName,
5
+ } from "../contacts/guardian-delivery-reader.js";
7
6
  import { getAssistantName } from "../daemon/identity-helpers.js";
8
7
  import { DEFAULT_USER_REFERENCE, resolveGuardianName } from "../prompts/user-reference.js";
9
8
  import { getLogger } from "../util/logger.js";
@@ -119,7 +118,7 @@ export function buildSttHints(input: SttHintsInput): string {
119
118
  * {@link buildSttHints}. All DB lookups are best-effort — errors are
120
119
  * logged but never propagate so hints can never fail a call.
121
120
  */
122
- export function resolveCallHints(
121
+ export async function resolveCallHints(
123
122
  session: {
124
123
  task: string | null;
125
124
  toNumber: string;
@@ -129,16 +128,14 @@ export function resolveCallHints(
129
128
  inviteGuardianName: string | null;
130
129
  } | null,
131
130
  staticHints: string[],
132
- ): string {
131
+ ): Promise<string> {
133
132
  const assistantName = getAssistantName();
134
133
 
135
- // Look up the guardian contact for a displayName fallback (mirrors relay-server pattern)
134
+ // Resolve the guardian displayName from the gateway binding for STT vocabulary.
136
135
  let guardianDisplayName: string | undefined;
137
136
  try {
138
- const voiceGuardian = findGuardianForChannel("phone");
139
- const guardianChannels = voiceGuardian ? null : listGuardianChannels();
140
- const guardianContact = voiceGuardian?.contact ?? guardianChannels?.contact;
141
- guardianDisplayName = guardianContact?.displayName;
137
+ const list = await getGuardianDelivery();
138
+ guardianDisplayName = voiceGuardianDisplayName(list);
142
139
  } catch (err) {
143
140
  logger.warn({ err }, "Failed to look up guardian contact for STT hints");
144
141
  }
@@ -55,6 +55,7 @@ import {
55
55
  updateCallSession,
56
56
  } from "./call-store.js";
57
57
  import { getChannelAdmissionPolicy } from "./channel-admission-reader.js";
58
+ import { getPhoneCallerVerdict } from "./inbound-trust-reader.js";
58
59
  import { routeSetup } from "./relay-setup-router.js";
59
60
  import { resolveCallHints } from "./stt-hints.js";
60
61
  import { resolveTelephonySttRouting } from "./telephony-stt-routing.js";
@@ -298,7 +299,7 @@ async function processVoiceWebhook(
298
299
  "Inbound voice webhook — creating/reusing session",
299
300
  );
300
301
 
301
- const { session } = createInboundVoiceSession({
302
+ const { session } = await createInboundVoiceSession({
302
303
  callSid,
303
304
  fromNumber: callerFrom,
304
305
  toNumber: callerTo,
@@ -484,12 +485,21 @@ async function buildVoiceWebhookTwiml(
484
485
  // admits the caller.
485
486
  const admissionPolicy = await getChannelAdmissionPolicy("phone");
486
487
 
488
+ // Verdict-first caller trust so this preflight matches handleSetup's ACL.
489
+ // routeSetup uses it when present and not resolutionFailed, else falls back
490
+ // to local resolution. The reader returns null on failure, keeping the
491
+ // local path on a gateway blip.
492
+ const isInbound = sessionContext?.direction !== "outbound";
493
+ const otherPartyNumber = isInbound ? from : to;
494
+ const verdict = await getPhoneCallerVerdict(otherPartyNumber);
495
+
487
496
  const { outcome } = routeSetup({
488
497
  callSessionId,
489
498
  session: session ?? null,
490
499
  from,
491
500
  to,
492
501
  admissionPolicy,
502
+ verdict,
493
503
  });
494
504
 
495
505
  // The media-stream transport supports normal_call and deny (which speaks
@@ -522,7 +532,7 @@ async function buildVoiceWebhookTwiml(
522
532
  /**
523
533
  * Build ConversationRelay TwiML for Twilio-native STT providers.
524
534
  */
525
- function buildConversationRelayTwiml(
535
+ async function buildConversationRelayTwiml(
526
536
  callSessionId: string,
527
537
  profile: ReturnType<typeof resolveVoiceQualityProfile>,
528
538
  sessionContext: {
@@ -535,8 +545,8 @@ function buildConversationRelayTwiml(
535
545
  } | null,
536
546
  verificationSessionId: string | null | undefined,
537
547
  sttAttrs: { transcriptionProvider: string; speechModel: string | undefined },
538
- ): string {
539
- const rawHints = resolveCallHints(sessionContext, profile.hints);
548
+ ): Promise<string> {
549
+ const rawHints = await resolveCallHints(sessionContext, profile.hints);
540
550
 
541
551
  const speechConfig: TwilioRelaySpeechConfig = {
542
552
  transcriptionProvider: sttAttrs.transcriptionProvider,
@@ -88,8 +88,15 @@ mock.module("../../../util/logger.js", () => ({
88
88
  }));
89
89
 
90
90
  mock.module("../../lib/cache-fs.js", () => ({
91
- readFileSync: (path: string, encoding?: BufferEncoding) => {
91
+ readFileSync: (path: string | number, encoding?: BufferEncoding) => {
92
+ // Stdin must be read via fd 0, not by reopening "/dev/stdin": a spawned
93
+ // subprocess whose stdin is a pipe (Bun.spawn stdin:"pipe") cannot reopen
94
+ // its read-end by path — open("/dev/stdin") fails ENXIO. Throwing here on
95
+ // the path makes any regression to path-based reading fail loudly.
92
96
  if (path === "/dev/stdin") {
97
+ throw new Error("ENXIO: no such device or address, open '/dev/stdin'");
98
+ }
99
+ if (path === 0) {
93
100
  if (mockStdinContent === null) {
94
101
  throw new Error("EAGAIN: resource temporarily unavailable");
95
102
  }