@mycadet/assistant 0.12.9 → 0.12.10

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 (651) hide show
  1. package/Dockerfile +0 -8
  2. package/eslint-rules/__tests__/cli-no-daemon-internals.test.ts +1 -1
  3. package/openapi.yaml +62 -910
  4. package/package.json +3 -7
  5. package/scripts/build-test-fixtures.ts +1 -1
  6. package/scripts/generate-openapi.ts +22 -6
  7. package/scripts/postinstall.ts +4 -10
  8. package/scripts/run-tests.ts +0 -21
  9. package/src/__tests__/adaptive-thinking-repair.test.ts +19 -57
  10. package/src/__tests__/agent-loop.test.ts +0 -76
  11. package/src/__tests__/anthropic-provider.test.ts +6 -6
  12. package/src/__tests__/assert-not-live-db.ts +1 -1
  13. package/src/__tests__/assistant-id-boundary-guard.test.ts +3 -3
  14. package/src/__tests__/attachments-store-heic-normalize.test.ts +1 -1
  15. package/src/__tests__/attachments-store.test.ts +1 -1
  16. package/src/__tests__/audit-log-rotation.test.ts +1 -1
  17. package/src/__tests__/btw-routes.test.ts +1 -1
  18. package/src/__tests__/byok-default-profile-ensure.test.ts +21 -27
  19. package/src/__tests__/call-conversation-messages.test.ts +0 -5
  20. package/src/__tests__/call-recovery.test.ts +2 -7
  21. package/src/__tests__/call-routes-http.test.ts +0 -12
  22. package/src/__tests__/call-store.test.ts +2 -7
  23. package/src/__tests__/catalog-files.test.ts +7 -5
  24. package/src/__tests__/checker.test.ts +1 -1
  25. package/src/__tests__/cli-memory-v2-reembed-skills.test.ts +4 -4
  26. package/src/__tests__/cloud-client-verify-credential.test.ts +0 -4
  27. package/src/__tests__/cloud-credential-catalog-cli.test.ts +14 -14
  28. package/src/__tests__/cloud-profile-guard.test.ts +48 -401
  29. package/src/__tests__/compaction-events.test.ts +2 -2
  30. package/src/__tests__/config-loader-backfill.test.ts +74 -163
  31. package/src/__tests__/config-loader-cloud-defaults.test.ts +11 -11
  32. package/src/__tests__/config-loader-corrupt.test.ts +10 -10
  33. package/src/__tests__/config-loader-quarantine-notice.test.ts +7 -7
  34. package/src/__tests__/config-loader-validation-reset-notice.test.ts +11 -11
  35. package/src/__tests__/config-schema.test.ts +26 -27
  36. package/src/__tests__/config-set-route.test.ts +2 -6
  37. package/src/__tests__/conversation-agent-loop-inference-profile.test.ts +28 -300
  38. package/src/__tests__/conversation-agent-loop-overflow.test.ts +39 -246
  39. package/src/__tests__/conversation-agent-loop.test.ts +2 -58
  40. package/src/__tests__/conversation-clear-safety.test.ts +0 -30
  41. package/src/__tests__/conversation-inference-profile-route.test.ts +1 -1
  42. package/src/__tests__/conversation-queue.test.ts +1 -1
  43. package/src/__tests__/conversation-runtime-assembly.test.ts +1 -1
  44. package/src/__tests__/conversation-skill-tools.test.ts +4 -444
  45. package/src/__tests__/conversation-slash-commands.test.ts +1 -1
  46. package/src/__tests__/conversation-store.test.ts +1 -84
  47. package/src/__tests__/conversation-surface-state.test.ts +0 -16
  48. package/src/__tests__/credential-health-service.test.ts +14 -1
  49. package/src/__tests__/credential-record-retire.test.ts +1 -1
  50. package/src/__tests__/credential-record-write-through.test.ts +1 -1
  51. package/src/__tests__/credential-security-invariants.test.ts +0 -145
  52. package/src/__tests__/custom-profile-ensure.test.ts +1 -1
  53. package/src/__tests__/default-profile-catalog-fallback.test.ts +5 -15
  54. package/src/__tests__/deterministic-verification-control-plane.test.ts +0 -2
  55. package/src/__tests__/dictation-profile-store.test.ts +6 -6
  56. package/src/__tests__/disk-usage.test.ts +28 -164
  57. package/src/__tests__/docker-signing-key-bootstrap.test.ts +1 -1
  58. package/src/__tests__/embedding-cloud-proxy-selection.test.ts +1 -1
  59. package/src/__tests__/emit-event-signal.test.ts +1 -1
  60. package/src/__tests__/gateway-client-cloud-outbound.test.ts +3 -3
  61. package/src/__tests__/gateway-only-enforcement.test.ts +1 -1
  62. package/src/__tests__/guardian-dispatch.test.ts +0 -13
  63. package/src/__tests__/helpers/seed-app.ts +1 -1
  64. package/src/__tests__/host-cu-routes-targeted.test.ts +1 -1
  65. package/src/__tests__/host-shell-tool.test.ts +1 -1
  66. package/src/__tests__/identity-routes.test.ts +1 -1
  67. package/src/__tests__/inference-profile-session-handler.test.ts +1 -1
  68. package/src/__tests__/inference-profile-session-ipc.test.ts +1 -1
  69. package/src/__tests__/injector-chain.test.ts +1 -1
  70. package/src/__tests__/injector-config-quarantine-notice.test.ts +1 -1
  71. package/src/__tests__/injector-config-validation-reset-notice.test.ts +1 -1
  72. package/src/__tests__/injector-pkb-v2-silenced.test.ts +1 -1
  73. package/src/__tests__/{platform.test.ts → layout.test.ts} +1 -1
  74. package/src/__tests__/list-all-apps.test.ts +1 -1
  75. package/src/__tests__/live-workspace-guard.test.ts +2 -2
  76. package/src/__tests__/llm-resolver-override-or-default.test.ts +5 -6
  77. package/src/__tests__/llm-resolver.test.ts +7 -7
  78. package/src/__tests__/llm-schema-fallback-profile.test.ts +9 -10
  79. package/src/__tests__/llm-usage-store.test.ts +0 -495
  80. package/src/__tests__/log-export-routes.test.ts +1 -1
  81. package/src/__tests__/mcp-config-secret-boundary.test.ts +12 -53
  82. package/src/__tests__/mcp-list-plugin-servers.test.ts +1 -1
  83. package/src/__tests__/memory-config-file-parity.test.ts +1 -1
  84. package/src/__tests__/memory-v2-static-injector.test.ts +1 -1
  85. package/src/__tests__/messages-read-boundary-guard.test.ts +0 -2
  86. package/src/__tests__/notification-guardian-path.test.ts +0 -7
  87. package/src/__tests__/onboarding-persona-write.test.ts +1 -1
  88. package/src/__tests__/openai-provider.test.ts +8 -8
  89. package/src/__tests__/path-policy.test.ts +1 -1
  90. package/src/__tests__/persona-resolver.test.ts +1 -1
  91. package/src/__tests__/plugin-app-serve-routes.test.ts +1 -1
  92. package/src/__tests__/plugin-effective-enabled-set.test.ts +1 -1
  93. package/src/__tests__/plugin-import-boundary-guard.test.ts +4 -6
  94. package/src/__tests__/plugin-import-boundary-reverse-guard.test.ts +0 -3
  95. package/src/__tests__/provider-cloud-proxy-integration.test.ts +1 -5
  96. package/src/__tests__/provider-connections-backfill.test.ts +10 -10
  97. package/src/__tests__/prune-old-conversations-job.test.ts +6 -31
  98. package/src/__tests__/resolve-app.test.ts +1 -1
  99. package/src/__tests__/run-due-schedules.test.ts +1 -1
  100. package/src/__tests__/scaffold-managed-skill-tool.test.ts +0 -53
  101. package/src/__tests__/schedule-routes.test.ts +1 -1
  102. package/src/__tests__/schedule-store.test.ts +1 -1
  103. package/src/__tests__/secret-routes-cloud-proxy.test.ts +1 -1
  104. package/src/__tests__/skill-load-plugin-scope.test.ts +1 -1
  105. package/src/__tests__/surface-completion-compaction-boundary.test.ts +1 -1
  106. package/src/__tests__/tool-approval-handler.test.ts +1 -1
  107. package/src/__tests__/tool-audit.test.ts +5 -235
  108. package/src/__tests__/tool-executor-lifecycle-events.test.ts +54 -114
  109. package/src/__tests__/tools-get-route.test.ts +1 -1
  110. package/src/__tests__/turn-outcome-read.test.ts +1 -1
  111. package/src/__tests__/twilio-routes.test.ts +0 -1
  112. package/src/__tests__/usage-attribution.test.ts +0 -31
  113. package/src/__tests__/verification-control-plane-policy.test.ts +3 -10
  114. package/src/__tests__/visible-app-context.test.ts +1 -1
  115. package/src/__tests__/voice-ingress-preflight.test.ts +1 -1
  116. package/src/__tests__/workspace-git-service.test.ts +1 -1
  117. package/src/__tests__/workspace-greetings.test.ts +1 -1
  118. package/src/acp/__tests__/helpers/acp-config-stub.ts +1 -1
  119. package/src/activation/progress-store.ts +1 -1
  120. package/src/activation/turn-hooks.ts +1 -1
  121. package/src/agent/loop.ts +0 -51
  122. package/src/apps/app-store.ts +1 -1
  123. package/src/avatar/__tests__/avatar-store.test.ts +2 -172
  124. package/src/avatar/accent-backfill.ts +1 -1
  125. package/src/avatar/avatar-manifest.ts +1 -1
  126. package/src/avatar/avatar-store.ts +10 -69
  127. package/src/avatar/ensure-raster.ts +1 -1
  128. package/src/avatar/identity-avatar.ts +1 -1
  129. package/src/avatar/sync-avatar.ts +1 -1
  130. package/src/avatar/traits-png-sync.ts +1 -1
  131. package/src/bundler/compiler-tools.ts +1 -1
  132. package/src/bundler/package-resolver.ts +1 -1
  133. package/src/calls/__tests__/call-controller.test.ts +25 -27
  134. package/src/calls/active-call-lease.ts +1 -1
  135. package/src/calls/call-controller.ts +3 -3
  136. package/src/calls/call-domain.ts +4 -8
  137. package/src/calls/call-store.ts +2 -76
  138. package/src/calls/resolve-call-tts-provider.ts +3 -3
  139. package/src/calls/twilio-config.ts +3 -3
  140. package/src/calls/twilio-rest.ts +2 -2
  141. package/src/calls/voice-ingress-preflight.ts +2 -2
  142. package/src/cli/bundled-modules.ts +0 -2
  143. package/src/cli/commands/__tests__/apps.test.ts +1 -1
  144. package/src/cli/commands/__tests__/plugins.test.ts +9 -66
  145. package/src/cli/commands/__tests__/ps.test.ts +67 -0
  146. package/src/cli/commands/auth.help.ts +2 -2
  147. package/src/cli/commands/avatar.ts +1 -1
  148. package/src/cli/commands/changelog.ts +1 -1
  149. package/src/cli/commands/cloud/__tests__/subscription.test.ts +2 -2
  150. package/src/cli/commands/cloud/index.help.ts +1 -1
  151. package/src/cli/commands/cloud/index.ts +2 -2
  152. package/src/cli/commands/db/refresh.ts +1 -1
  153. package/src/cli/commands/db/repair-step-conversation-backfill.ts +1 -1
  154. package/src/cli/commands/db/repair.ts +1 -1
  155. package/src/cli/commands/db/status.ts +1 -1
  156. package/src/cli/commands/inference-profiles.ts +1 -12
  157. package/src/cli/commands/memory/__tests__/memory-v3.test.ts +1 -116
  158. package/src/cli/commands/memory/index.help.ts +1 -43
  159. package/src/cli/commands/memory/memory-v3.ts +0 -64
  160. package/src/cli/commands/plugins.ts +54 -205
  161. package/src/cli/commands/ps.ts +5 -2
  162. package/src/cli/commands/status.ts +1 -1
  163. package/src/cli/index.help.ts +0 -2
  164. package/src/cli/lib/__tests__/inspect-plugin.test.ts +36 -66
  165. package/src/cli/lib/__tests__/install-from-cloud.test.ts +1 -1
  166. package/src/cli/lib/__tests__/install-from-github.test.ts +41 -117
  167. package/src/cli/lib/__tests__/plugin-catalog-cache.test.ts +2 -185
  168. package/src/cli/lib/__tests__/plugin-catalog-resolve.test.ts +36 -66
  169. package/src/cli/lib/__tests__/plugin-catalog-visibility.test.ts +4 -6
  170. package/src/cli/lib/__tests__/plugin-details.test.ts +113 -96
  171. package/src/cli/lib/__tests__/search-plugins.test.ts +9 -16
  172. package/src/cli/lib/__tests__/uninstall-plugin.test.ts +1 -1
  173. package/src/cli/lib/__tests__/upgrade-plugin.test.ts +38 -15
  174. package/src/cli/lib/diff-plugin.ts +1 -1
  175. package/src/cli/lib/inspect-plugin.ts +13 -97
  176. package/src/cli/lib/install-from-cloud.ts +1 -1
  177. package/src/cli/lib/install-from-github.ts +75 -154
  178. package/src/cli/lib/install-plugin-dependencies.ts +1 -1
  179. package/src/cli/lib/list-installed-plugins.ts +1 -1
  180. package/src/cli/lib/open-browser.ts +1 -1
  181. package/src/cli/lib/plugin-catalog-cache.ts +8 -51
  182. package/src/cli/lib/plugin-catalog-resolve.ts +3 -22
  183. package/src/cli/lib/plugin-details.ts +5 -27
  184. package/src/cli/lib/plugin-marketplace.ts +18 -266
  185. package/src/cli/lib/search-plugins.ts +23 -43
  186. package/src/cli/lib/toggle-plugin.ts +1 -1
  187. package/src/cli/lib/uninstall-plugin.ts +1 -1
  188. package/src/cli/lib/upgrade-plugin.ts +3 -49
  189. package/src/cli/program.ts +1 -3
  190. package/src/cli.ts +1 -1
  191. package/src/cloud/client.ts +0 -6
  192. package/src/cloud/consent-cache.test.ts +22 -201
  193. package/src/cloud/consent-cache.ts +16 -111
  194. package/src/cloud/sync-identity.ts +1 -1
  195. package/src/config/__tests__/chat-settings.test.ts +1 -1
  196. package/src/config/__tests__/cloud-identity.test.ts +15 -2
  197. package/src/config/__tests__/default-plugin-skill-discovery.test.ts +1 -1
  198. package/src/config/__tests__/default-profile-catalog.test.ts +12 -51
  199. package/src/config/__tests__/deployment-context-defaults.test.ts +13 -13
  200. package/src/config/__tests__/loader-callsite-strip-fallback.test.ts +4 -4
  201. package/src/config/__tests__/loader-last-known-good.test.ts +9 -9
  202. package/src/config/__tests__/loader-sparse-array-cleanup.test.ts +7 -7
  203. package/src/config/__tests__/plugin-resident-skill-discovery.test.ts +1 -1
  204. package/src/config/__tests__/profile-materialization.test.ts +2 -4
  205. package/src/config/__tests__/sync-gated-profiles.test.ts +1 -106
  206. package/src/config/acp-agent-write.ts +1 -1
  207. package/src/config/bundled-skills/settings/tools/open-system-settings.test.ts +1 -1
  208. package/src/config/bundled-skills/settings/tools/open-system-settings.ts +1 -1
  209. package/src/config/call-site-defaults.ts +0 -6
  210. package/src/config/cloud-identity.ts +12 -5
  211. package/src/config/composer-preferences.ts +1 -1
  212. package/src/config/default-profile-catalog.ts +8 -75
  213. package/src/config/default-profile-names.ts +2 -25
  214. package/src/config/env-registry.ts +1 -14
  215. package/src/config/env.ts +8 -6
  216. package/src/config/llm-resolver.ts +1 -2
  217. package/src/config/loader.ts +13 -17
  218. package/src/config/profile-materialization.ts +1 -1
  219. package/src/config/schema.ts +1 -7
  220. package/src/config/schemas/call-site-catalog.ts +0 -7
  221. package/src/config/schemas/llm.ts +22 -27
  222. package/src/config/seed-inference-profiles.ts +16 -17
  223. package/src/config/skills.ts +2 -2
  224. package/src/config/sync-gated-profiles.ts +6 -24
  225. package/src/credential-health/credential-health-service.ts +10 -3
  226. package/src/daemon/approval-generators.ts +3 -3
  227. package/src/daemon/config-watcher.ts +2 -2
  228. package/src/daemon/conversation-agent-loop-handlers.ts +0 -18
  229. package/src/daemon/conversation-agent-loop.ts +6 -97
  230. package/src/daemon/conversation-process.ts +1 -1
  231. package/src/daemon/conversation-skill-tools.ts +4 -72
  232. package/src/daemon/conversation-store.ts +1 -1
  233. package/src/daemon/conversation-surface-state.ts +0 -33
  234. package/src/daemon/conversation-surfaces.ts +1 -86
  235. package/src/daemon/conversation-tool-setup.test.ts +1 -1
  236. package/src/daemon/conversation-tool-setup.ts +0 -23
  237. package/src/daemon/conversation.ts +3 -5
  238. package/src/daemon/daemon-control.ts +3 -3
  239. package/src/daemon/dictation-profile-store.ts +3 -3
  240. package/src/daemon/event-loop-watchdog.test.ts +2 -198
  241. package/src/daemon/event-loop-watchdog.ts +0 -185
  242. package/src/daemon/external-plugins-bootstrap.ts +1 -1
  243. package/src/daemon/first-greeting.ts +1 -1
  244. package/src/daemon/handlers/skills.ts +1 -1
  245. package/src/daemon/host-app-control-proxy.ts +1 -1
  246. package/src/daemon/host-cu-proxy.ts +2 -2
  247. package/src/daemon/identity-helpers.ts +1 -1
  248. package/src/daemon/lifecycle.ts +11 -15
  249. package/src/daemon/main.ts +1 -1
  250. package/src/daemon/now-scratchpad.ts +1 -1
  251. package/src/daemon/process-message.ts +4 -4
  252. package/src/daemon/profiler-run-store.ts +2 -2
  253. package/src/daemon/providers-setup.ts +2 -2
  254. package/src/daemon/shutdown-handlers.ts +0 -10
  255. package/src/daemon/sqlite-corruption-watchdog.test.ts +2 -142
  256. package/src/daemon/sqlite-corruption-watchdog.ts +17 -81
  257. package/src/daemon/tool-side-effects.ts +1 -1
  258. package/src/desktop/desktop-session-manager.ts +1 -1
  259. package/src/desktop/desktop-wallpaper-renderer.ts +1 -1
  260. package/src/heartbeat/heartbeat-service.ts +1 -1
  261. package/src/home/feed-writer.ts +1 -1
  262. package/src/home/home-greeting-cache.ts +1 -1
  263. package/src/home/relationship-state-writer.ts +2 -2
  264. package/src/hooks/__tests__/hook-live-reload.test.ts +1 -1
  265. package/src/hooks/hook-loader.ts +2 -2
  266. package/src/inbound/__tests__/oauth-callback-url.test.ts +2 -2
  267. package/src/inbound/oauth-callback-url.ts +3 -3
  268. package/src/ipc/__tests__/attachment-ipc.test.ts +1 -1
  269. package/src/ipc/socket-path.ts +1 -1
  270. package/src/live-voice/__tests__/live-voice-archive.test.ts +1 -1
  271. package/src/live-voice/__tests__/live-voice-vad.test.ts +1 -1
  272. package/src/live-voice/live-voice-session.ts +3 -66
  273. package/src/mcp/__tests__/effective-config.test.ts +1 -1
  274. package/src/mcp/__tests__/mcp-oauth-client-registration.test.ts +2 -2
  275. package/src/mcp/__tests__/mcp-oauth-provider.test.ts +2 -3
  276. package/src/mcp/__tests__/reload-signal-emission.test.ts +1 -1
  277. package/src/mcp/__tests__/reload-signal.test.ts +1 -1
  278. package/src/mcp/__tests__/workspace-mcp-config.test.ts +19 -21
  279. package/src/mcp/reload-signal.ts +1 -1
  280. package/src/mcp/workspace-mcp-config.ts +1 -23
  281. package/src/messaging/draft-store.ts +1 -1
  282. package/src/monitoring/__tests__/active-conversations.test.ts +1 -1
  283. package/src/monitoring/__tests__/page-cache.test.ts +1 -1
  284. package/src/monitoring/__tests__/stall-capture.test.ts +1 -1
  285. package/src/monitoring/__tests__/workspace-git-heartbeat.test.ts +1 -1
  286. package/src/monitoring/active-conversations.ts +1 -1
  287. package/src/monitoring/control.ts +1 -1
  288. package/src/monitoring/daemon-boot-time.ts +1 -1
  289. package/src/monitoring/daemon-heartbeat.ts +1 -1
  290. package/src/monitoring/page-cache.ts +1 -1
  291. package/src/monitoring/plugin-auto-update.ts +1 -7
  292. package/src/monitoring/plugin-source-watch.ts +1 -1
  293. package/src/monitoring/recovery/db.ts +1 -1
  294. package/src/monitoring/recovery/inflight-content.ts +1 -1
  295. package/src/monitoring/resource-sampler.ts +3 -14
  296. package/src/monitoring/stall-capture.ts +1 -1
  297. package/src/monitoring/worker.ts +9 -76
  298. package/src/monitoring/workspace-git-heartbeat.ts +1 -1
  299. package/src/oauth/connect-orchestrator.ts +4 -4
  300. package/src/permissions/checker.ts +1 -1
  301. package/src/permissions/workspace-policy.ts +1 -1
  302. package/src/persistence/__tests__/main-db-readonly-probe.ts +27 -52
  303. package/src/persistence/__tests__/message-content-file.test.ts +1 -1
  304. package/src/persistence/__tests__/slow-sync-log.test.ts +0 -2
  305. package/src/persistence/attachments-store.ts +1 -1
  306. package/src/persistence/conversation-crud.ts +1 -38
  307. package/src/persistence/conversation-directories.ts +1 -1
  308. package/src/persistence/conversation-types.ts +0 -8
  309. package/src/persistence/db-async-query.ts +1 -1
  310. package/src/persistence/db-connection.ts +11 -1
  311. package/src/persistence/db-init.ts +1 -1
  312. package/src/persistence/db-maintenance.ts +1 -1
  313. package/src/persistence/embeddings/__tests__/embedding-local-lifecycle.test.ts +1 -1
  314. package/src/persistence/embeddings/embedding-local.ts +4 -4
  315. package/src/persistence/embeddings/embedding-runtime-manager.ts +1 -1
  316. package/src/persistence/embeddings/qdrant-client.ts +1 -1
  317. package/src/persistence/embeddings/qdrant-manager.ts +1 -1
  318. package/src/persistence/job-handlers/__tests__/message-lexical-backfill.test.ts +1 -1
  319. package/src/persistence/job-handlers/__tests__/message-lexical-enqueue.test.ts +1 -1
  320. package/src/persistence/job-handlers/cleanup.ts +8 -17
  321. package/src/persistence/llm-usage-store.ts +2 -229
  322. package/src/persistence/message-content-file.ts +1 -1
  323. package/src/persistence/migrations/209-strip-thinking-from-consolidated.ts +1 -1
  324. package/src/persistence/migrations/222-strip-placeholder-sentinels-from-messages.ts +1 -1
  325. package/src/persistence/migrations/296-rewrite-balanced-economy-profile-pins.test.ts +1 -1
  326. package/src/persistence/migrations/306-rewrite-frontier-profile-pins.test.ts +1 -1
  327. package/src/persistence/migrations/329-move-onboarding-events-to-telemetry-db.test.ts +13 -0
  328. package/src/persistence/migrations/330-move-auth-fallback-events-to-telemetry-db.test.ts +13 -0
  329. package/src/persistence/migrations/331-move-lifecycle-events-to-telemetry-db.test.ts +13 -0
  330. package/src/persistence/migrations/332-move-skill-loaded-events-to-telemetry-db.test.ts +13 -0
  331. package/src/persistence/migrations/333-create-telemetry-events-table.test.ts +7 -4
  332. package/src/persistence/migrations/334-backfill-telemetry-events-outbox.test.ts +13 -0
  333. package/src/persistence/migrations/387-drop-telemetry-tables.ts +51 -0
  334. package/src/persistence/migrations/__tests__/327-create-flush-checkpoints.test.ts +9 -1
  335. package/src/persistence/migrations/__tests__/387-drop-telemetry-tables.test.ts +79 -0
  336. package/src/persistence/migrations/helpers/relocation.ts +1 -1
  337. package/src/persistence/migrations/run-migrations.ts +1 -1
  338. package/src/persistence/migrations/validate-migration-state.ts +1 -1
  339. package/src/persistence/raw-query.ts +1 -29
  340. package/src/persistence/slow-sync-log.ts +0 -23
  341. package/src/persistence/steps.ts +2 -0
  342. package/src/{telemetry → persistence}/tool-audit.ts +6 -121
  343. package/src/plugin-api/index.ts +1 -1
  344. package/src/plugin-api/plugin-name-env.ts +1 -1
  345. package/src/plugins/__tests__/installed-plugin-dirs.test.ts +1 -1
  346. package/src/plugins/collect-source-versions.ts +1 -1
  347. package/src/plugins/defaults/channel/package.json +1 -1
  348. package/src/plugins/defaults/cloud-hosted/package.json +1 -1
  349. package/src/plugins/defaults/compaction/package.json +1 -1
  350. package/src/plugins/defaults/documents/package.json +1 -1
  351. package/src/plugins/defaults/empty-response/package.json +1 -1
  352. package/src/plugins/defaults/exploration-drift/package.json +1 -1
  353. package/src/plugins/defaults/image-fallback/package.json +1 -1
  354. package/src/plugins/defaults/image-recovery/package.json +1 -1
  355. package/src/plugins/defaults/max-tokens-continue/package.json +1 -1
  356. package/src/plugins/defaults/memory/__tests__/db-async-query.test.ts +1 -1
  357. package/src/plugins/defaults/memory/__tests__/db-maintenance.test.ts +1 -1
  358. package/src/plugins/defaults/memory/__tests__/memory-retrospective-job.test.ts +0 -82
  359. package/src/plugins/defaults/memory/__tests__/memory-retrospective-skill-card.test.ts +0 -41
  360. package/src/plugins/defaults/memory/__tests__/memory-tier-boundary-guard.test.ts +0 -2
  361. package/src/plugins/defaults/memory/memory-retrospective-job.ts +3 -52
  362. package/src/plugins/defaults/memory/memory-retrospective-skill-card.ts +0 -18
  363. package/src/plugins/defaults/memory/package.json +1 -1
  364. package/src/plugins/defaults/memory/paths.ts +4 -4
  365. package/src/plugins/defaults/memory/src/__tests__/memory-worker-routes.test.ts +1 -1
  366. package/src/plugins/defaults/memory/src/memory-v2-routes.ts +5 -5
  367. package/src/plugins/defaults/memory/src/memory-v3-routes.ts +0 -207
  368. package/src/plugins/defaults/memory/src/memory-worker-routes.ts +1 -1
  369. package/src/plugins/defaults/memory/startup.ts +1 -22
  370. package/src/plugins/defaults/memory/v3/__tests__/orchestrate.test.ts +2 -253
  371. package/src/plugins/defaults/memory/v3/orchestrate.ts +5 -129
  372. package/src/plugins/defaults/memory/worker-control.ts +1 -1
  373. package/src/plugins/defaults/memory/worker.ts +2 -2
  374. package/src/plugins/defaults/session/package.json +1 -1
  375. package/src/plugins/defaults/surface-completion-nudge/package.json +1 -1
  376. package/src/plugins/defaults/task-progress/package.json +1 -1
  377. package/src/plugins/defaults/task-progress-nudge/package.json +1 -1
  378. package/src/plugins/defaults/title-generate/package.json +1 -1
  379. package/src/plugins/defaults/tool-error/package.json +1 -1
  380. package/src/plugins/defaults/tool-result-truncate/package.json +1 -1
  381. package/src/plugins/defaults/turn-context/package.json +1 -1
  382. package/src/plugins/defaults/workspace/injectors.ts +1 -1
  383. package/src/plugins/defaults/workspace/package.json +1 -1
  384. package/src/plugins/disabled-state.ts +1 -1
  385. package/src/plugins/ensure-plugin-api-shim.ts +1 -1
  386. package/src/plugins/ensure-shared-dep-links.ts +1 -1
  387. package/src/plugins/installed-plugin-dirs.ts +1 -1
  388. package/src/plugins/mcp-servers.ts +7 -9
  389. package/src/plugins/mtime-cache.ts +2 -2
  390. package/src/plugins/source-versions.ts +1 -1
  391. package/src/prompts/bootstrap-cleanup.ts +1 -1
  392. package/src/prompts/persona-resolver.ts +1 -1
  393. package/src/prompts/sections.ts +2 -2
  394. package/src/prompts/system-prompt.ts +10 -42
  395. package/src/prompts/templates/BOOTSTRAP-ACTIVATION-RAIL.md +0 -37
  396. package/src/providers/__tests__/cadet-connection-routing.test.ts +2 -2
  397. package/src/providers/cadet/client.ts +1 -1
  398. package/src/providers/inference/__tests__/base-url-route-validation.test.ts +1 -1
  399. package/src/providers/inference/adapter-factory.ts +1 -1
  400. package/src/providers/inference/backfill.ts +3 -10
  401. package/src/providers/inference/profile-probe.ts +1 -1
  402. package/src/providers/retry.ts +0 -2
  403. package/src/providers/types.ts +0 -7
  404. package/src/providers/usage-tracking.ts +1 -1
  405. package/src/routes/__tests__/route-host.test.ts +1 -1
  406. package/src/routes/control.ts +1 -1
  407. package/src/routes/route-host-client.ts +1 -1
  408. package/src/routes/worker.ts +2 -2
  409. package/src/runtime/agent-wake.ts +1 -1
  410. package/src/runtime/assistant-stream-state.ts +1 -1
  411. package/src/runtime/auth/token-service.ts +1 -1
  412. package/src/runtime/background-job-runner.ts +1 -1
  413. package/src/runtime/middleware/twilio-validation.ts +2 -2
  414. package/src/runtime/routes/__tests__/app-pin-routes.test.ts +1 -1
  415. package/src/runtime/routes/__tests__/apps-refresh-route.test.ts +1 -1
  416. package/src/runtime/routes/__tests__/avatar-state-routes.test.ts +3 -33
  417. package/src/runtime/routes/__tests__/cloud-credits-routes.test.ts +5 -4
  418. package/src/runtime/routes/__tests__/cloud-invoice-routes.test.ts +4 -3
  419. package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +59 -287
  420. package/src/runtime/routes/__tests__/default-plugin-routes.test.ts +1 -1
  421. package/src/runtime/routes/__tests__/deprecated-route-context.test.ts +15 -62
  422. package/src/runtime/routes/__tests__/inference-profiles-routes.test.ts +105 -12
  423. package/src/runtime/routes/__tests__/ingress-status-routes.test.ts +1 -1
  424. package/src/runtime/routes/__tests__/monitoring-routes.test.ts +1 -1
  425. package/src/runtime/routes/__tests__/plugins-routes.test.ts +47 -211
  426. package/src/runtime/routes/__tests__/route-host-worker-routes.test.ts +1 -1
  427. package/src/runtime/routes/__tests__/schedule-routes-disarm-reason.test.ts +1 -1
  428. package/src/runtime/routes/__tests__/schedule-worker-routes.test.ts +1 -1
  429. package/src/runtime/routes/__tests__/user-route-dispatcher-host.test.ts +1 -1
  430. package/src/runtime/routes/__tests__/user-route-dispatcher.test.ts +1 -1
  431. package/src/runtime/routes/__tests__/user-routes-cli.test.ts +1 -1
  432. package/src/runtime/routes/__tests__/user-routes-notices.test.ts +1 -1
  433. package/src/runtime/routes/__tests__/user-routes-request.test.ts +1 -1
  434. package/src/runtime/routes/app-management-routes.ts +1 -1
  435. package/src/runtime/routes/attachment-routes.ts +1 -1
  436. package/src/runtime/routes/audit-routes.ts +1 -1
  437. package/src/runtime/routes/avatar-routes.ts +3 -10
  438. package/src/runtime/routes/cloud-routes.ts +3 -3
  439. package/src/runtime/routes/content-source-routes.ts +1 -1
  440. package/src/runtime/routes/conversation-query-routes.ts +60 -621
  441. package/src/runtime/routes/conversation-routes.ts +1 -38
  442. package/src/runtime/routes/debug-routes.ts +1 -1
  443. package/src/runtime/routes/deprecated-route-context.ts +5 -61
  444. package/src/runtime/routes/heartbeat-routes.ts +1 -1
  445. package/src/runtime/routes/identity-routes.ts +1 -1
  446. package/src/runtime/routes/index.ts +0 -6
  447. package/src/runtime/routes/inference-profile-session-handler.ts +3 -3
  448. package/src/runtime/routes/inference-profiles-routes.ts +48 -21
  449. package/src/runtime/routes/inference-provider-connection-routes.ts +0 -1
  450. package/src/runtime/routes/llm-call-sites-routes.ts +3 -3
  451. package/src/runtime/routes/log-export/__tests__/installed-inventory.test.ts +1 -1
  452. package/src/runtime/routes/log-export/__tests__/workspace-allowlist-error-contract.test.ts +1 -1
  453. package/src/runtime/routes/log-export/__tests__/workspace-allowlist.test.ts +1 -1
  454. package/src/runtime/routes/log-export/workspace-allowlist.ts +1 -1
  455. package/src/runtime/routes/log-export-routes.ts +17 -15
  456. package/src/runtime/routes/migration-rollback-routes.ts +1 -1
  457. package/src/runtime/routes/migration-routes.ts +2 -3
  458. package/src/runtime/routes/monitoring-routes.ts +2 -2
  459. package/src/runtime/routes/oauth-providers.ts +5 -5
  460. package/src/runtime/routes/plugins-routes.ts +38 -163
  461. package/src/runtime/routes/profiler-routes.ts +1 -1
  462. package/src/runtime/routes/route-host-worker-routes.ts +1 -1
  463. package/src/runtime/routes/sanity-routes.ts +1 -1
  464. package/src/runtime/routes/schedule-routes.ts +1 -1
  465. package/src/runtime/routes/schedule-worker-routes.ts +1 -1
  466. package/src/runtime/routes/settings-routes.ts +1 -1
  467. package/src/runtime/routes/sounds-config-routes.ts +1 -1
  468. package/src/runtime/routes/surface-conversation-resolver.ts +1 -7
  469. package/src/runtime/routes/user-route-dispatcher.ts +1 -3
  470. package/src/runtime/routes/user-route-import.ts +1 -1
  471. package/src/runtime/routes/user-route-resolution.ts +1 -1
  472. package/src/runtime/routes/user-routes-cli.ts +1 -1
  473. package/src/runtime/routes/workspace-commit-routes.ts +1 -1
  474. package/src/runtime/routes/workspace-greetings.ts +1 -1
  475. package/src/runtime/routes/workspace-routes.ts +1 -1
  476. package/src/runtime/routes/workspace-utils.ts +1 -1
  477. package/src/runtime/sync/resource-sync-events.ts +1 -1
  478. package/src/schedule/__tests__/plugin-schedule-declarations.test.ts +1 -1
  479. package/src/schedule/__tests__/plugin-schedule-reconciler.test.ts +1 -1
  480. package/src/schedule/plugin-schedule-availability.ts +1 -1
  481. package/src/schedule/plugin-schedule-declarations.ts +1 -1
  482. package/src/schedule/run-script.ts +1 -1
  483. package/src/schedule/scheduler.ts +1 -11
  484. package/src/schedule/worker-control.ts +1 -1
  485. package/src/schedule/worker.ts +3 -3
  486. package/src/security/oauth2.ts +2 -2
  487. package/src/security/secret-allowlist.ts +1 -1
  488. package/src/signals/cancel.ts +1 -1
  489. package/src/signals/conversation-undo.ts +1 -1
  490. package/src/signals/emit-event.ts +1 -1
  491. package/src/signals/event-stream.ts +1 -1
  492. package/src/signals/user-message.ts +1 -1
  493. package/src/skills/catalog-install.ts +2 -1
  494. package/src/skills/clawhub.ts +1 -1
  495. package/src/skills/cloud-store.ts +1 -1
  496. package/src/skills/path-classifier.ts +1 -1
  497. package/src/skills/skill-history.ts +1 -1
  498. package/src/skills/skillssh-registry.ts +1 -1
  499. package/src/skills/uninstall.ts +1 -1
  500. package/src/skills/workspace-skill-md-signature.ts +1 -1
  501. package/src/subagent/manager.ts +1 -1
  502. package/src/theme/workspace-theme.ts +1 -1
  503. package/src/tools/browser/auth-cache.ts +1 -1
  504. package/src/tools/browser/browser-manager.ts +1 -1
  505. package/src/tools/browser/runtime-check.ts +1 -1
  506. package/src/tools/executor.ts +4 -4
  507. package/src/tools/filesystem/write.ts +1 -1
  508. package/src/tools/permission-checker.ts +2 -51
  509. package/src/tools/run-standalone.ts +1 -1
  510. package/src/tools/skills/format-input-schema.ts +1 -1
  511. package/src/tools/skills/load.ts +1 -1
  512. package/src/tools/skills/scaffold-cloud.ts +0 -32
  513. package/src/tools/terminal/safe-env.ts +1 -2
  514. package/src/tools/terminal/sanitized-bash.ts +1 -1
  515. package/src/tools/terminal/shell.ts +1 -1
  516. package/src/tools/tool-approval-handler.ts +4 -1
  517. package/src/tools/workflows/manage-workflows.ts +2 -2
  518. package/src/tools/workflows/run-workflow.test.ts +1 -1
  519. package/src/tools/workspace-tools/loader.ts +1 -1
  520. package/src/tts/synthesis-stream.ts +2 -2
  521. package/src/usage/attribution.ts +1 -11
  522. package/src/util/browser.ts +1 -1
  523. package/src/util/bun-runtime.ts +2 -1
  524. package/src/util/device-id.ts +1 -1
  525. package/src/util/disk-usage.ts +4 -139
  526. package/src/util/layout.ts +3 -3
  527. package/src/util/logger.ts +1 -1
  528. package/src/util/logs-db-path.ts +1 -1
  529. package/src/util/memory-db-path.ts +1 -1
  530. package/src/util/{platform.ts → os.ts} +5 -30
  531. package/src/util/process-tree.ts +19 -0
  532. package/src/util/sqlite3-runtime.ts +1 -1
  533. package/src/util/telemetry-db-path.ts +1 -1
  534. package/src/watcher/__tests__/engine.test.ts +0 -23
  535. package/src/watcher/engine.ts +0 -7
  536. package/src/windows-compiled-cli.ts +0 -4
  537. package/src/windows-compiled-worker-entry.ts +0 -6
  538. package/src/workflows/leaf-runner.test.ts +1 -1
  539. package/src/workflows/leaf-runner.ts +1 -1
  540. package/src/workflows/library.ts +1 -1
  541. package/src/workspace/adaptive-thinking-repair.ts +5 -24
  542. package/src/workspace/byok-default-profile-ensure.ts +24 -26
  543. package/src/workspace/custom-profile-ensure.ts +2 -2
  544. package/src/workspace/git-service.ts +1 -1
  545. package/src/workspace/hatched-date.ts +1 -1
  546. package/src/workspace/migrations/038-unify-llm-callsite-configs.ts +2 -2
  547. package/src/workspace/migrations/040-seed-latency-callsite-defaults.ts +1 -1
  548. package/src/workspace/migrations/050-seed-main-agent-opus-callsite.ts +1 -1
  549. package/src/workspace/migrations/077-seed-memory-router-callsite.ts +1 -1
  550. package/src/workspace/migrations/registry.ts +0 -4
  551. package/src/workspace/turn-commit.ts +1 -1
  552. package/docs/activation-funnel-telemetry.md +0 -324
  553. package/scripts/bundled-plugin-packages.ts +0 -154
  554. package/scripts/generate-bundled-plugin-packages.ts +0 -29
  555. package/src/__tests__/activation-early-marking.test.ts +0 -114
  556. package/src/__tests__/auth-fallback-events-store.test.ts +0 -99
  557. package/src/__tests__/config-get-vision-flag.test.ts +0 -139
  558. package/src/__tests__/conversation-surfaces-activation-emit.test.ts +0 -400
  559. package/src/__tests__/internal-telemetry-routes.test.ts +0 -213
  560. package/src/__tests__/telemetry-routes.test.ts +0 -182
  561. package/src/__tests__/turn-events-store.test.ts +0 -376
  562. package/src/__tests__/ui-channel-variants.test.ts +0 -53
  563. package/src/avatar/__tests__/avatar-changed-telemetry.test.ts +0 -217
  564. package/src/avatar/avatar-changed-telemetry.ts +0 -128
  565. package/src/calls/__tests__/call-funnel-telemetry.test.ts +0 -204
  566. package/src/cli/commands/telemetry.help.ts +0 -27
  567. package/src/cli/commands/telemetry.ts +0 -83
  568. package/src/cli/lib/__tests__/local-plugin-upgrade.test.ts +0 -251
  569. package/src/cli/lib/__tests__/plugin-catalog-local.test.ts +0 -113
  570. package/src/cli/lib/__tests__/plugin-marketplace.test.ts +0 -384
  571. package/src/cli/lib/__tests__/plugin-pin-history.test.ts +0 -164
  572. package/src/cli/lib/__tests__/plugins-install-offline.test.ts +0 -228
  573. package/src/cli/lib/bundled-marketplace.json +0 -1575
  574. package/src/cli/lib/bundled-plugin-packages.json +0 -827
  575. package/src/cli/lib/bundled-plugin-packages.ts +0 -87
  576. package/src/cli/lib/plugin-catalog-local.ts +0 -94
  577. package/src/cli/lib/plugin-pin-history.ts +0 -276
  578. package/src/cloud/feature-gate.ts +0 -8
  579. package/src/config/__tests__/cloud-rehydration.test.ts +0 -180
  580. package/src/config/cloud-rehydration.ts +0 -35
  581. package/src/daemon/__tests__/auto-profile-router.test.ts +0 -380
  582. package/src/daemon/auto-profile-router.ts +0 -428
  583. package/src/live-voice/__tests__/live-voice-session-telemetry.test.ts +0 -391
  584. package/src/monitoring/__tests__/db-integrity-sample.test.ts +0 -113
  585. package/src/monitoring/__tests__/oom-kill-reporter.test.ts +0 -374
  586. package/src/monitoring/db-integrity-check.ts +0 -163
  587. package/src/monitoring/db-integrity-sample.ts +0 -176
  588. package/src/monitoring/oom-kill-reporter.ts +0 -469
  589. package/src/onboarding/__tests__/onboarding-events-store.test.ts +0 -158
  590. package/src/onboarding/onboarding-events-store.ts +0 -296
  591. package/src/persistence/__tests__/raw-query-telemetry.test.ts +0 -76
  592. package/src/persistence/lifecycle-events-store.test.ts +0 -134
  593. package/src/persistence/lifecycle-events-store.ts +0 -110
  594. package/src/plugins/defaults/memory/__tests__/activation-session-store.test.ts +0 -76
  595. package/src/plugins/defaults/memory/activation-session-store.ts +0 -50
  596. package/src/plugins/defaults/memory/src/__tests__/memory-v3-gate-stats.test.ts +0 -281
  597. package/src/runtime/routes/auto-profile-routes.ts +0 -83
  598. package/src/runtime/routes/internal-telemetry-routes.ts +0 -142
  599. package/src/runtime/routes/telemetry-routes.ts +0 -274
  600. package/src/security/auth-fallback-events-store.ts +0 -57
  601. package/src/telemetry/__tests__/activation-funnel.test.ts +0 -95
  602. package/src/telemetry/__tests__/config-setting-events-store.test.ts +0 -63
  603. package/src/telemetry/__tests__/config-setting-snapshot.test.ts +0 -143
  604. package/src/telemetry/__tests__/flush-checkpoints.test.ts +0 -56
  605. package/src/telemetry/__tests__/live-voice-funnel.test.ts +0 -174
  606. package/src/telemetry/__tests__/outbox-test-harness.ts +0 -85
  607. package/src/telemetry/__tests__/phone-call-funnel.test.ts +0 -72
  608. package/src/telemetry/__tests__/telemetry-event-fixtures.ts +0 -282
  609. package/src/telemetry/__tests__/watchdog-events-store.test.ts +0 -71
  610. package/src/telemetry/activation-funnel.ts +0 -172
  611. package/src/telemetry/config-setting-events-store.ts +0 -40
  612. package/src/telemetry/config-setting-snapshot.ts +0 -170
  613. package/src/telemetry/flush-checkpoints.ts +0 -70
  614. package/src/telemetry/live-voice-funnel.ts +0 -185
  615. package/src/telemetry/memory-corpus-size.test.ts +0 -120
  616. package/src/telemetry/memory-corpus-size.ts +0 -184
  617. package/src/telemetry/memory-tier-reporter.test.ts +0 -195
  618. package/src/telemetry/memory-tier-reporter.ts +0 -130
  619. package/src/telemetry/phone-call-funnel.ts +0 -144
  620. package/src/telemetry/skill-loaded-events-store.test.ts +0 -93
  621. package/src/telemetry/skill-loaded-events-store.ts +0 -39
  622. package/src/telemetry/telemetry-event-sources.test.ts +0 -223
  623. package/src/telemetry/telemetry-event-sources.ts +0 -597
  624. package/src/telemetry/telemetry-events-outbox.test.ts +0 -375
  625. package/src/telemetry/telemetry-events-outbox.ts +0 -237
  626. package/src/telemetry/telemetry-main-db.ts +0 -48
  627. package/src/telemetry/telemetry-wire-source.json +0 -4
  628. package/src/telemetry/telemetry-wire-validation.test.ts +0 -157
  629. package/src/telemetry/telemetry-wire-validation.ts +0 -162
  630. package/src/telemetry/telemetry-wire.generated.ts +0 -483
  631. package/src/telemetry/tool-executed-events-store.test.ts +0 -210
  632. package/src/telemetry/tool-executed-events-store.ts +0 -102
  633. package/src/telemetry/trace-collection-policy.test.ts +0 -28
  634. package/src/telemetry/trace-collection-policy.ts +0 -30
  635. package/src/telemetry/turn-events-store.ts +0 -216
  636. package/src/telemetry/turn-trace-store.test.ts +0 -884
  637. package/src/telemetry/turn-trace-store.ts +0 -399
  638. package/src/telemetry/types.test.ts +0 -38
  639. package/src/telemetry/types.ts +0 -780
  640. package/src/telemetry/usage-telemetry-reporter.test.ts +0 -3445
  641. package/src/telemetry/usage-telemetry-reporter.ts +0 -566
  642. package/src/telemetry/watchdog-direct-emit.test.ts +0 -112
  643. package/src/telemetry/watchdog-direct-emit.ts +0 -104
  644. package/src/telemetry/watchdog-events-store.ts +0 -31
  645. package/src/tools/ui-surface/channel-variants.ts +0 -52
  646. package/src/watcher/__tests__/telemetry.test.ts +0 -178
  647. package/src/watcher/telemetry.ts +0 -93
  648. package/src/workspace/migrations/097-enable-adaptive-thinking-managed-profiles.ts +0 -165
  649. package/src/workspace/migrations/104-recheck-adaptive-thinking-model-implied-anthropic.ts +0 -151
  650. /package/src/{telemetry → persistence}/tool-usage-store.ts +0 -0
  651. /package/src/{telemetry → persistence}/turn-outcome.ts +0 -0
@@ -1,780 +0,0 @@
1
- import type { LLMCallSite } from "../config/schemas/llm.js";
2
- import type { UsageAttributionProfileSource } from "../usage/types.js";
3
- import type * as wire from "./telemetry-wire.generated.js";
4
- import { telemetryEventSchema } from "./telemetry-wire.generated.js";
5
- import type { TurnOutcome } from "./turn-outcome.js";
6
-
7
- /** Base fields present on every telemetry event. */
8
- export interface TelemetryEventBase {
9
- type: string;
10
- daemon_event_id: string;
11
- recorded_at: number;
12
- /**
13
- * Version of the assistant binary at the moment THIS event was
14
- * RECORDED (not when the batch was uploaded). Distinct from the
15
- * envelope's `assistant_version` field, which still ships for
16
- * back-compat with platforms that haven't deployed the per-event
17
- * handling.
18
- *
19
- * The cloud's `TelemetryIngestView` prefers per-event over
20
- * envelope: when a per-event value is present (including explicit
21
- * `null`) it wins. When the field is omitted on the event entirely
22
- * (old assistant), the envelope value is the back-compat fallback.
23
- *
24
- * Daemon-side, this field is always non-null. The outbox-backed
25
- * event types store the full wire payload at record time, so their
26
- * `APP_VERSION` stamp is genuinely record-time; `llm_usage` carries
27
- * a record-time column (legacy rows from before migration 267 fall
28
- * back to the flushing binary's `APP_VERSION`); `turn` and
29
- * `tool_executed` derive from tables without a version column and
30
- * stamp the flushing binary's `APP_VERSION`. Stamping `APP_VERSION`
31
- * instead of emitting explicit `null` preserves envelope-equivalent
32
- * behavior under the per-event-wins contract. The type allows
33
- * `null` for parity with the cloud contract; in practice the
34
- * daemon never sends it.
35
- */
36
- assistant_version: string | null;
37
- }
38
-
39
- /**
40
- * Base for telemetry events that occur in the context of a model call.
41
- * Standardizes model attribution across event types — field names/shapes
42
- * mirror the existing llm_usage event so downstream consumers (dbt, admin
43
- * charts) can join/group consistently.
44
- *
45
- * `provider`/`model` are nullable on the wire because rows persisted before
46
- * the attribution columns existed, and rows whose attribution resolution
47
- * failed, must still ship; the cloud serializer accepts null.
48
- */
49
- export interface ModelTelemetryEventBase extends TelemetryEventBase {
50
- /** Provider serving the call, e.g. "anthropic", "fireworks". */
51
- provider: string | null;
52
- /** Model id active for the call, e.g. "claude-fable-5". */
53
- model: string | null;
54
- /** Inference profile slug. Null when no profile applied. */
55
- inference_profile: string | null;
56
- /** How the profile was attributed (same enum as llm_usage). */
57
- inference_profile_source: UsageAttributionProfileSource | null;
58
- }
59
-
60
- /**
61
- * Applies the daemon's record-time guarantee to a wire-derived event type.
62
- *
63
- * The wire contract marks `assistant_version` optional for back-compat with
64
- * old daemons; under the cloud's per-event-wins contract a present
65
- * per-event value (including explicit `null`) beats the envelope fallback.
66
- * This daemon always stamps the field at record time (see
67
- * {@link TelemetryEventBase.assistant_version} for the full contract), so
68
- * wire-derived event types are re-typed with the field required.
69
- */
70
- type Daemonize<T> = T & { assistant_version: string | null };
71
-
72
- /**
73
- * LLM usage event — one per persisted usage row. The main agent loop
74
- * persists a single row per turn with token totals summed across every
75
- * provider API call in the loop (`llm_call_count` carries the call count);
76
- * auxiliary call sites persist one row per call.
77
- */
78
- export interface LlmUsageTelemetryEvent extends TelemetryEventBase {
79
- type: "llm_usage";
80
- /**
81
- * Parent conversation id. Null for LLM calls not tied to a conversation
82
- * (memory consolidation, background embedding work, etc.).
83
- */
84
- conversation_id: string | null;
85
- /**
86
- * Type of the parent conversation (`"standard"` / `"background"` /
87
- * `"scheduled"`). Null when `conversation_id` is null. Daemons predating
88
- * this field send no value; downstream consumers treat missing/null as
89
- * `"standard"` to preserve back-compat during rollout.
90
- */
91
- conversation_type: string | null;
92
- /**
93
- * 1-indexed position of the user turn this LLM call belongs to within
94
- * the parent conversation, counting only real user turns (tool-result
95
- * rows persisted with role="user" are excluded — same filter as the
96
- * `turn` event stream). Computed as the count of user messages with
97
- * `created_at <= this_event.created_at`. Null when the LLM call isn't
98
- * tied to a conversation, or when no user turn has occurred yet.
99
- */
100
- turn_index: number | null;
101
- /**
102
- * Id of the conversation that spawned this event's conversation —
103
- * `parent_conversation_id` stamped at subagent spawn, falling back to
104
- * `fork_parent_conversation_id` for retrospective forks. Null when the
105
- * conversation was not spawned by another conversation or the LLM call
106
- * has no conversation.
107
- */
108
- parent_conversation_id: string | null;
109
- /**
110
- * 1-indexed parent-conversation user turn this event's conversation
111
- * branched from: the turn in flight at child creation for subagent
112
- * spawns, the fork boundary message's turn for retrospective forks
113
- * (same real-user-turn filter as `turn_index`). Null when there is no
114
- * parent conversation.
115
- */
116
- parent_turn_index: number | null;
117
- /**
118
- * Role the subagent that owns this event's conversation was spawned with
119
- * (`researcher`, `builder`, `advisor`; a spawn that named no role records
120
- * the default, `builder`). An open string set: older rows carry role names
121
- * nothing emits any more.
122
- * The advisor is a ROLE, not an `LLMCallSiteEnum` value, so this is the only
123
- * thing that tells an advisor consult apart from a regular subagent, since both
124
- * emit under `llm_call_site = "subagentSpawn"`. Null when the LLM call did
125
- * not run inside a subagent conversation.
126
- */
127
- subagent_role: string | null;
128
- /**
129
- * How that subagent was spawned, one of the modes described on
130
- * `SubagentSpawnMode` in `subagent/types.ts`, carried here as an open string
131
- * set. Orthogonal to `subagent_role`: the role selects the child's
132
- * capabilities, the spawn mode selects its context inheritance and lifecycle
133
- * (a fork's inherited transcript dominates its input tokens regardless of
134
- * role). Null under the same condition as `subagent_role`.
135
- */
136
- subagent_spawn_mode: string | null;
137
- provider: string;
138
- model: string;
139
- input_tokens: number;
140
- output_tokens: number;
141
- cache_creation_input_tokens: number | null;
142
- cache_read_input_tokens: number | null;
143
- /**
144
- * Number of provider API calls aggregated into this event. The main
145
- * agent loop persists one usage row per turn with token totals summed
146
- * across every call in the loop, so this is how downstream consumers
147
- * recover per-call averages (effective tokens ÷ calls). Auxiliary call
148
- * sites record exactly 1. Null for rows persisted before daemon
149
- * migration `200-usage-llm-call-count`; consumers treat null as 1.
150
- */
151
- llm_call_count: number | null;
152
- /**
153
- * The provider's untouched `usage` block. Anthropic surfaces a TTL
154
- * breakdown under `cache_creation.ephemeral_{5m,1h}_input_tokens`;
155
- * OpenAI surfaces cached-read counts under
156
- * `prompt_tokens_details.cached_tokens` (and reasoning tokens under
157
- * `completion_tokens_details`). Both shapes are forwarded verbatim so
158
- * downstream consumers (admin charts, dbt models) can extract any
159
- * provider-specific detail without requiring a schema change here.
160
- * Null when the provider did not return a usage payload, and for
161
- * daemons that predate `260-llm-usage-add-raw-usage`.
162
- */
163
- raw_usage: Record<string, unknown> | null;
164
- actor: string;
165
- llm_call_site: LLMCallSite | null;
166
- inference_profile: string | null;
167
- inference_profile_source: UsageAttributionProfileSource | null;
168
- /** Computed estimated cost in USD for this LLM call. Null when pricing data is unavailable. */
169
- cost: number | null;
170
- }
171
-
172
- /**
173
- * Optional client metadata bag carried on `TurnTelemetryEvent.client`.
174
- * Sourced from `messages.metadata.client`. Today only `os` is populated —
175
- * stamped by `persistQueuedMessageBody` from the request body's `clientOs`
176
- * field; the remaining fields are declared for clients that send them.
177
- * Extensible without a schema change — lives entirely in the JSON metadata
178
- * column.
179
- */
180
- export interface TurnTelemetryClientInfo {
181
- /** Browser family for `web`/`chrome-extension` interfaces: `"chrome"|"safari"|"firefox"|"edge"`. */
182
- browser_family?: string;
183
- /** Major browser version only (`"124"`, not the full UA string). */
184
- browser_version?: string;
185
- /**
186
- * OS surface reported by the client at message time
187
- * ("web" | "ios" | "macos" | "windows" | "android"). Browser, mobile, and
188
- * desktop apps all run the same renderer and report `interface_id: "web"`.
189
- * This field is the only per-platform attribution in turn telemetry.
190
- */
191
- os?: string;
192
- /**
193
- * Version of the surface app/client (`"0.8.2"` for the macOS app,
194
- * web client SHA, etc.) — distinct from `assistant_version` on the
195
- * batch envelope, which identifies the daemon. A user can be on an
196
- * older surface than the daemon (or vice versa, on web).
197
- */
198
- interface_version?: string;
199
- }
200
-
201
- /**
202
- * One message in a turn trace. `role` is the stored `messages.role`
203
- * (`"user"` / `"assistant"` / `"system"`); tool-result rows persisted with
204
- * role `"user"` keep that role here so the transcript is faithful to what was
205
- * sent to the model. `content` is the parsed `messages.content` — either the
206
- * modern `ContentBlock[]` (text / tool_use / tool_result / thinking / image /
207
- * file blocks) or a legacy plain string. Stored verbatim by the cloud as an
208
- * opaque JSON column, so the shape is self-describing rather than normalized.
209
- */
210
- export interface TurnTraceMessage {
211
- /** `messages.id` — stable per-row id. */
212
- id: string;
213
- /** Stored role of the message row. */
214
- role: string;
215
- /** Epoch-ms `messages.created_at`. */
216
- created_at: number;
217
- /**
218
- * Parsed `messages.content`. `unknown` because it is forwarded verbatim:
219
- * modern rows are `ContentBlock[]`, legacy rows are a plain string.
220
- */
221
- content: unknown;
222
- /**
223
- * Model that served this row — the provider's `response.model`, carried on
224
- * the agent loop's `message_complete` event and persisted with the row
225
- * (`messages.metadata.model`); matches the turn's `llm_usage.model` and
226
- * reflects per-call reroutes by a `pre-model-call` hook. Null on rows with
227
- * no model call: user rows, tool-result rows, synthetic assistant rows
228
- * (provider-error / yield notices), and historical rows persisted before the
229
- * daemon began stamping the model.
230
- */
231
- model: string | null;
232
- }
233
-
234
- /**
235
- * One tool invocation in a turn trace, projected from the `tool_invocations`
236
- * audit table for the turn window. Carries the full tool call + result so the
237
- * platform sees the same transcript the assistant did. Both `input` and
238
- * `result` are captured verbatim (full-fidelity) — no field-level redaction is
239
- * applied. The protections for this PII are the owner consent gate, the
240
- * PII-segregated `pii_turn_raw` table, and its 30-day TTL.
241
- */
242
- export interface TurnTraceToolCall {
243
- /** `tool_invocations.id`. */
244
- id: string;
245
- tool_name: string;
246
- /** Verbatim tool input — parsed JSON when it parses, else the raw string. */
247
- input: unknown;
248
- /** Stored tool result string (verbatim). */
249
- result: string;
250
- /** Audit decision (`"allow"` / `"error"` / …). */
251
- decision: string;
252
- duration_ms: number;
253
- created_at: number;
254
- }
255
-
256
- /**
257
- * Full transcript of a single turn — the user message, assistant response
258
- * message(s), and the tool calls + results that occurred between this user
259
- * turn and the next real user turn. Attached to the turn telemetry event's
260
- * `trace` field ONLY when trace collection is enabled — the owner's
261
- * `share_diagnostics` consent at an eligible accepted version.
262
- * The cloud stores this verbatim as an opaque JSON column, so the daemon
263
- * owns the shape.
264
- *
265
- * Each turn's trace is its natural window. A turn whose window holds no
266
- * assistant response (a coalesced-batch head, or a turn that failed/cancelled
267
- * before responding) traces user-only — faithful, since its window genuinely
268
- * has no response. A coalesced batch's shared response lives on the batch's
269
- * final turn's window, where the daemon already attributes it.
270
- */
271
- /** Tool definition included in the trace — name, description, and full input
272
- * schema so the trace shows exactly what the model had available. */
273
- export interface TurnTraceToolDefinition {
274
- name: string;
275
- description: string;
276
- /** JSON schema describing the tool's input arguments. */
277
- input_schema: Record<string, unknown>;
278
- }
279
-
280
- export interface TurnTrace {
281
- /** Shape version so the cloud/dbt can evolve parsing without ambiguity. */
282
- schema_version: 3;
283
- /**
284
- * Ordered message rows for the turn (the user message first, then assistant
285
- * responses and any tool-result rows), oldest-first by `(created_at, id)`.
286
- * Model attribution is per message — each assistant row carries the model
287
- * that served it on `TurnTraceMessage.model`.
288
- */
289
- messages: TurnTraceMessage[];
290
- /**
291
- * Tool invocations that occurred during the turn window, oldest-first. May
292
- * be empty for turns with no tool use. Projected from `tool_invocations`,
293
- * which complements the inline tool_use/tool_result blocks in `messages`.
294
- */
295
- tool_calls: TurnTraceToolCall[];
296
- /**
297
- * The system prompt sent to the provider for this turn. Read from the live
298
- * conversation's cached prompt at trace assembly time. Null when the
299
- * conversation has been evicted from memory by the time the trace is
300
- * assembled (e.g. after a daemon restart).
301
- */
302
- system_prompt: string | null;
303
- /**
304
- * Tool definitions available to the model for this turn — name,
305
- * description, and full input schema, matching what the provider received.
306
- * Read from the live conversation's last resolved tool set. Empty when the
307
- * conversation has been evicted.
308
- */
309
- tool_definitions: TurnTraceToolDefinition[];
310
- }
311
-
312
- /** Turn event — one per user message. */
313
- export interface TurnTelemetryEvent extends TelemetryEventBase {
314
- type: "turn";
315
- /**
316
- * Parent conversation id. Lets analytics group turns by conversation
317
- * (e.g. avg turns per conversation, time-to-first-completion).
318
- */
319
- conversation_id: string;
320
- /**
321
- * Type of the parent conversation. Lets analytics distinguish
322
- * user-initiated turns (`"standard"`) from system-generated prompts
323
- * in `"background"` / `"scheduled"` conversations. Daemons predating
324
- * this field send no value; downstream consumers should treat a
325
- * missing value as `"standard"` to preserve DAU during rollout.
326
- */
327
- conversation_type: string;
328
- /**
329
- * 1-indexed position of this user turn within the parent conversation,
330
- * counting only real user turns (tool-result rows persisted with
331
- * role="user" are excluded — same filter as the turn-event eligibility
332
- * predicate). The first user turn in a conversation is `1`.
333
- */
334
- turn_index: number;
335
- /**
336
- * Canonical `InterfaceId` enum value identifying the UI surface the
337
- * user was interacting from when this turn was created (`"macos"`,
338
- * `"ios"`, `"cli"`, `"web"`, `"chrome-extension"`, `"slack"`,
339
- * `"telegram"`, `"whatsapp"`, `"email"`, `"phone"`). Sourced from the
340
- * `userMessageInterface` field already stamped on `messages.metadata`
341
- * by every `persistUserMessage` path that flows through
342
- * `TurnChannelContext`.
343
- *
344
- * Null when the metadata didn't carry the field — historical rows or
345
- * system-initiated turns with no inbound client context. Downstream
346
- * consumers should treat null as `"unknown"`.
347
- */
348
- interface_id: string | null;
349
- /**
350
- * Canonical `ChannelId` enum value identifying the messaging fabric the
351
- * user message arrived on (`"cadet"` for in-app from macos/ios/web/
352
- * cli/chrome-extension; `"slack"`/`"telegram"`/`"whatsapp"`/`"email"`/
353
- * `"phone"` for channel-based interfaces). The 7th `ChannelId` value
354
- * (`"platform"`) is APNs-push outbound-only and should never appear
355
- * here.
356
- */
357
- channel_id: string | null;
358
- /**
359
- * Optional client-side metadata bag. Null when no client headers were
360
- * attached to the request that created the user message (most
361
- * channel-inbound paths today, and any path the new HTTP header
362
- * middleware hasn't been wired to yet).
363
- */
364
- client: TurnTelemetryClientInfo | null;
365
- /**
366
- * Explicit abnormal turn outcome, stamped by the daemon at turn end:
367
- *
368
- * - `"batched"` — the user message was coalesced into a later turn's
369
- * shared response (`drainBatch`); its own window holds no assistant
370
- * message by design. `batched_into` identifies the turn that replied.
371
- * - `"failed"` — the agent loop terminated in a non-cancellation error.
372
- * Includes turns whose only assistant output is the synthetic
373
- * provider-error message, so failure analytics don't need to
374
- * text-match error copy.
375
- * - `"cancelled"` — the user cancelled the turn (stop / barge-in).
376
- *
377
- * Omitted when the turn replied normally, when the daemon predates
378
- * outcome stamping, or when the process died mid-turn before a stamp
379
- * could land — so `absent + no assistant message in trace` isolates the
380
- * genuinely anomalous (crashed/unknown) turns.
381
- */
382
- outcome?: TurnOutcome;
383
- /**
384
- * For `outcome: "batched"` turns: the `daemon_event_id` of the
385
- * batch-final turn whose window carries the shared response. Omitted
386
- * otherwise.
387
- */
388
- batched_into?: string;
389
- /**
390
- * For `outcome: "failed"` turns: the stable classified error code
391
- * (`classifyConversationError(...).code`, a `ConversationErrorCode`
392
- * value like `"PROVIDER_RATE_LIMIT"` or `"MANAGED_USAGE_LIMIT"`). Never
393
- * free-form error text. Omitted otherwise or when the failure had no
394
- * classification.
395
- */
396
- failure_code?: string;
397
- /**
398
- * Whether this turn was auto-sent on the user's behalf rather than typed by
399
- * them: onboarding research prompts, the personality rewrite message,
400
- * research corrections, kickoff greetings, the legacy pre-chat bootstrap,
401
- * and `[User action on ...]` surface synthetics.
402
- *
403
- * Tri-state and the states are NOT interchangeable:
404
- * `true` - auto-sent
405
- * `false` - a genuine typed user message
406
- * omitted - UNKNOWN (a row persisted before the marker existed)
407
- *
408
- * This is the consent-independent replacement for classifying turns by
409
- * text-matching their content in `pii_turn_raw` traces. That classifier can
410
- * only see owners who cleared the diagnostics gate, while activation cohorts
411
- * need only `share_analytics`, so it silently counted scripted turns as real
412
- * messages for everyone else (ANT-10). Unlike `trace` below, this field
413
- * carries nothing about the turn's CONTENT, only how it was originated,
414
- * so it rides the ordinary analytics gate and reaches every owner.
415
- *
416
- * Downstream excludes `true` and lets omitted fall back to the legacy
417
- * classifier; an explicit `false` is TRUSTED. Never synthesize a `false` for
418
- * a turn whose origin is genuinely unknown.
419
- */
420
- scripted?: boolean;
421
- /**
422
- * Full per-turn transcript (user message + assistant responses + tool
423
- * calls/results). Present ONLY when trace collection is enabled — the daemon
424
- * composes the gate itself from the owner's cached `share_diagnostics`
425
- * consent AND the accepted consent version being at or past the disclosing
426
- * version. Fail-closed: when either is off (or unknown) no trace
427
- * is attached. The cloud dual-writes consented traces into a separate PII
428
- * table and keeps the trace-free turn row; downstream consumers that don't
429
- * read traces ignore this field. Null / absent when the gate is off or the
430
- * serialized trace exceeded the size cap.
431
- */
432
- trace?: TurnTrace | null;
433
- }
434
-
435
- /**
436
- * Tool-executed event — one per tool invocation. Carries NO tool
437
- * args/inputs or result contents (customer PII per ToS) — payload sizes
438
- * and metadata only; no raw error messages. Identity/attribution come
439
- * from the upload envelope per the per-event-wins contract. Not to be
440
- * confused with the since-reverted `tool_execution` permission-audit
441
- * event, which no longer exists on the wire.
442
- */
443
- export interface ToolExecutedTelemetryEvent extends ModelTelemetryEventBase {
444
- type: "tool_executed";
445
- tool_name: string;
446
- /**
447
- * `"errored"` means the invocation failed at the execution layer — a
448
- * thrown error / infra failure (audit decision `"error"`). A tool that
449
- * runs to completion but returns an `isError` result payload still
450
- * counts as `"fulfilled"`: it executed.
451
- */
452
- status: "fulfilled" | "errored";
453
- duration_ms: number;
454
- /** Serialized tool-argument size in bytes. Null when unknown. */
455
- arg_bytes: number | null;
456
- /** Serialized tool-result size in bytes. Null when unknown. */
457
- result_bytes: number | null;
458
- conversation_id: string | null;
459
- }
460
-
461
- /**
462
- * Skill-loaded event — one per skill load. Emitted only for
463
- * Cadet-produced skills (bundled, or managed with cadet origin).
464
- * Metadata only — no skill output or conversation content.
465
- */
466
- export interface SkillLoadedTelemetryEvent extends ModelTelemetryEventBase {
467
- type: "skill_loaded";
468
- skill_name: string;
469
- /**
470
- * ISO 8601 timestamp — the catalog's `updatedAt`, effectively the
471
- * skill version. Null when the catalog carries no timestamp.
472
- */
473
- skill_updated_at: string | null;
474
- conversation_id: string | null;
475
- }
476
-
477
- /**
478
- * Watchdog health event — one per watchdog check firing. The daemon's
479
- * watchdog observes liveness/health signals (event-loop block, stream-idle
480
- * stalls, restarts, ...) and emits one event per check firing.
481
- *
482
- * Deliberately minimal and forward-compatible, mirroring the cloud
483
- * `WatchdogTelemetryEventSerializer`:
484
- *
485
- * - `check_name` — which watchdog check fired. Open string set (not a
486
- * closed enum) so the daemon can introduce a new check without a
487
- * coordinated serializer release; it is the primary group-by dimension
488
- * downstream. The infrastructure admin chart filters this to
489
- * `event_loop_blocked`.
490
- * - `value` — the single measured magnitude for the check (block ms, idle
491
- * ms, ...). Nullable: not every check carries a scalar. The cloud
492
- * coerces ints to float, so the daemon need not distinguish.
493
- * - `detail` — open JSON bag for any extra fields the daemon attaches
494
- * (reason codes, secondary numbers, a human message) without a
495
- * platform-coordinated schema change. Null when the daemon attaches
496
- * nothing. Bounded server-side (4096 bytes serialized); an oversize bag
497
- * rejects only the single event, never the batch.
498
- *
499
- * Metadata only — no conversation content. Dedupe downstream on
500
- * `daemon_event_id` (the daemon retries a batch on transient POST failure).
501
- */
502
- export interface WatchdogTelemetryEvent extends TelemetryEventBase {
503
- type: "watchdog";
504
- check_name: string;
505
- value: number | null;
506
- detail: Record<string, unknown> | null;
507
- }
508
-
509
- /** One inferred fact from the onboarding research-onboarding web-search turn. */
510
- export interface OnboardingResearchClaim {
511
- claim: string;
512
- confidence: "confident" | "maybe" | "guessing";
513
- sources: string[];
514
- }
515
-
516
- /** One clickable follow-up offer from the research-onboarding turn. */
517
- export interface OnboardingResearchSuggestion {
518
- suggestion: string;
519
- prompt: string;
520
- }
521
-
522
- /**
523
- * Onboarding-research event — one per "research me" web-search turn's
524
- * settled result during onboarding. Client-orchestrated: the web client
525
- * knows exactly when the turn completes and what it produced (claims,
526
- * suggestions, plugin picks), and reports it once via
527
- * `POST /v1/telemetry/ingest` (as a client-reportable type) — the daemon
528
- * never detects this turn on its own.
529
- *
530
- * Carries both the raw claim/suggestion text (+ source URLs) and structural
531
- * counts by confidence tier, so downstream consumers can aggregate cheaply
532
- * without parsing the arrays.
533
- */
534
- export interface OnboardingResearchTelemetryEvent extends TelemetryEventBase {
535
- type: "onboarding_research";
536
- conversation_id: string | null;
537
- status: "done" | "error";
538
- /**
539
- * The onboarding-form values the turn was run ON (its INPUT), as distinct
540
- * from the inferred `claims` below (its OUTPUT). Excludes the user's name by
541
- * design. Optional — an older web client omits them.
542
- */
543
- self_reported_occupation?: string;
544
- self_reported_hobbies?: string[];
545
- self_reported_timezone?: string;
546
- claims: OnboardingResearchClaim[];
547
- claim_count: number;
548
- claims_confident: number;
549
- claims_maybe: number;
550
- claims_guessing: number;
551
- suggestions: OnboardingResearchSuggestion[];
552
- suggestion_count: number;
553
- /** The model's raw top-level `plugins` picks, before the deterministic-floor merge. */
554
- plugins: string[];
555
- /** The final resolved install set (deterministic floor ∪ model picks, catalog-filtered). */
556
- installed_plugins: string[];
557
- }
558
-
559
- /**
560
- * Wire-derived event types with the daemon's record-time
561
- * `assistant_version` guarantee applied. New event types added to the wire
562
- * contract flow through here with zero hand edits.
563
- */
564
- type WireDaemonized = {
565
- [K in keyof wire.WireEventMap]: Daemonize<wire.WireEventMap[K]>;
566
- };
567
-
568
- /** Events where the daemon's type is intentionally narrower than the wire. */
569
- type Overrides = {
570
- llm_usage: LlmUsageTelemetryEvent;
571
- turn: TurnTelemetryEvent;
572
- tool_executed: ToolExecutedTelemetryEvent;
573
- skill_loaded: SkillLoadedTelemetryEvent;
574
- watchdog: WatchdogTelemetryEvent;
575
- onboarding_research: OnboardingResearchTelemetryEvent;
576
- };
577
-
578
- /**
579
- * Daemon-only event types not (yet) in the cloud wire contract — i.e. types
580
- * the daemon emits but `POST /v1/telemetry/ingest/` would silently skip because
581
- * they have no serializer in the cloud's `TELEMETRY_EVENT_SERIALIZERS`.
582
- *
583
- * Currently EMPTY: every emitted type is in the wire contract. When the daemon
584
- * needs to emit a type before the cloud accepts it, add it here (keyed by
585
- * its wire `type`). Once the cloud adds the serializer and the wire sync
586
- * lands, the key must leave `Extensions` — into `Overrides` if the daemon type
587
- * stays narrower than the wire, or plain wire flow-through otherwise. The
588
- * `_extensionsDontCollide` guard below turns red until that move is made.
589
- */
590
- type Extensions = Record<never, never>;
591
-
592
- type EventMap = Omit<WireDaemonized, keyof Overrides> & Overrides & Extensions;
593
-
594
- /** Discriminated union of all telemetry event types. */
595
- export type TelemetryEvent = EventMap[keyof EventMap];
596
-
597
- /**
598
- * Lifecycle event — app_open, hatch, etc. 1:1 with the wire contract:
599
- * `telemetry-wire.generated.ts` (from the cloud's
600
- * `LifecycleTelemetryEventSerializer`) is the source of truth.
601
- */
602
- export type LifecycleTelemetryEvent = EventMap["lifecycle"];
603
-
604
- /**
605
- * Onboarding event — pre-chat selections, Google connect status, and
606
- * activation-funnel steps. 1:1 with the wire contract
607
- * (`OnboardingTelemetryEventSerializer`); the cloud accepts either the
608
- * legacy `screen` shape or the complete funnel step field set — see the wire
609
- * schema's superRefine.
610
- */
611
- export type OnboardingTelemetryEvent = EventMap["onboarding"];
612
-
613
- /**
614
- * Auth-fallback event — aggregated count of requests served via the legacy
615
- * loopback auth fallback, one event per (guard, path, failure_kind) per
616
- * flush window (`count` is a per-window delta, not a running total). 1:1
617
- * with the wire contract (`AuthFallbackTelemetryEventSerializer`).
618
- */
619
- export type AuthFallbackTelemetryEvent = EventMap["auth_fallback"];
620
-
621
- /**
622
- * Config-setting event — a tracked config key's effective value rendered as
623
- * a string; emitters record an explicit allowlist of non-sensitive settings,
624
- * never free-form config content. 1:1 with the wire contract
625
- * (`ConfigSettingTelemetryEventSerializer`).
626
- */
627
- export type ConfigSettingTelemetryEvent = EventMap["config_setting"];
628
-
629
- /**
630
- * Avatar-changed event: one per avatar mutation that changed the avatar. 1:1
631
- * with the wire contract (`AvatarChangedTelemetryEventSerializer`).
632
- */
633
- export type AvatarChangedTelemetryEvent = EventMap["avatar_changed"];
634
-
635
- // ---- Compile-time drift guards ----
636
- // Each `Overrides` entry is pinned to its wire type in BOTH directions, so a
637
- // wire sync PR that moves the cloud contract turns red here instead of
638
- // drifting silently:
639
- //
640
- // - `_*Narrows` — the daemon type stays assignable to the wire type, i.e.
641
- // every daemon field's value is acceptable to the wire. Catches wire-side
642
- // tightening (narrowed unions, newly required fields) and daemon-side
643
- // loosening.
644
- // - `_*KeysExist` — every key the daemon emits still exists on the wire
645
- // type. Structural subtyping treats a daemon field the wire dropped as a
646
- // harmless extra property, so `_*Narrows` alone stays green when the
647
- // platform REMOVES or RENAMES a field; this key-set check is what catches
648
- // those.
649
- //
650
- // Flow-through (non-override) events need no guards: they use the generated
651
- // wire types directly, so their construction sites get excess-property /
652
- // missing-field errors the moment the contract moves.
653
- type AssertNarrows<_Narrow extends Wide, Wide> = true;
654
- type AssertNoWireCollision<_Keys extends never> = true;
655
-
656
- // `raw_usage` is excluded: the server treats it as an opaque JSONField, so
657
- // the daemon's `Record<string, unknown>` (not structurally assignable to the
658
- // wire's recursive `JsonValue`) is wire-safe — any JSON-serializable shape
659
- // ships fine.
660
- type _llmUsageNarrows = AssertNarrows<
661
- Omit<LlmUsageTelemetryEvent, "raw_usage">,
662
- Omit<wire.LlmUsageTelemetryEvent, "raw_usage">
663
- >;
664
- // `trace` and `client` are excluded: the server treats both as opaque JSON
665
- // (JSONField/DictField), so the daemon's richer `TurnTrace`
666
- // (`content: unknown`) and `TurnTelemetryClientInfo` shapes are wire-safe
667
- // even though they are not assignable to `JsonValue`. Runtime bounds are
668
- // enforced by the wire schema's superRefines, not by these types.
669
- type _turnNarrows = AssertNarrows<
670
- Omit<TurnTelemetryEvent, "trace" | "client">,
671
- Omit<wire.TurnTelemetryEvent, "trace" | "client">
672
- >;
673
- type _toolExecutedNarrows = AssertNarrows<
674
- ToolExecutedTelemetryEvent,
675
- wire.ToolExecutedTelemetryEvent
676
- >;
677
- type _skillLoadedNarrows = AssertNarrows<
678
- SkillLoadedTelemetryEvent,
679
- wire.SkillLoadedTelemetryEvent
680
- >;
681
- // `detail` is excluded: the server treats it as an opaque JSONField, so the
682
- // daemon's `Record<string, unknown>` bag is wire-safe; the serialized-size
683
- // bound is enforced by the wire schema's superRefine.
684
- type _watchdogNarrows = AssertNarrows<
685
- Omit<WatchdogTelemetryEvent, "detail">,
686
- Omit<wire.WatchdogTelemetryEvent, "detail">
687
- >;
688
- // Reverse (key-existence) direction. Unlike the `_*Narrows` guards, the
689
- // opaque-JSON fields are NOT excluded here: opacity is about a field's
690
- // SHAPE (the daemon's richer types aren't assignable to `JsonValue`), but
691
- // key PRESENCE is part of the typed contract — the generated wire types
692
- // declare `raw_usage`/`trace`/`client`/`detail`, and a cloud sync that
693
- // removed or renamed one of them would otherwise leave every guard green
694
- // while the daemon kept emitting a field the server discards.
695
- type _llmUsageKeysExist = AssertNarrows<
696
- keyof LlmUsageTelemetryEvent,
697
- keyof wire.LlmUsageTelemetryEvent
698
- >;
699
- type _turnKeysExist = AssertNarrows<
700
- keyof TurnTelemetryEvent,
701
- keyof wire.TurnTelemetryEvent
702
- >;
703
- type _toolExecutedKeysExist = AssertNarrows<
704
- keyof ToolExecutedTelemetryEvent,
705
- keyof wire.ToolExecutedTelemetryEvent
706
- >;
707
- type _skillLoadedKeysExist = AssertNarrows<
708
- keyof SkillLoadedTelemetryEvent,
709
- keyof wire.SkillLoadedTelemetryEvent
710
- >;
711
- type _watchdogKeysExist = AssertNarrows<
712
- keyof WatchdogTelemetryEvent,
713
- keyof wire.WatchdogTelemetryEvent
714
- >;
715
- // `claims` and `suggestions` are excluded from the narrows: the server types
716
- // both as opaque JSON arrays (`z.array(jsonValueSchema)`), so the daemon's
717
- // structured `OnboardingResearchClaim[]` / `OnboardingResearchSuggestion[]`
718
- // shapes are wire-safe even though they aren't assignable to `JsonValue[]`.
719
- // Runtime size bounds are enforced by the wire schema's superRefine.
720
- type _onboardingResearchNarrows = AssertNarrows<
721
- Omit<OnboardingResearchTelemetryEvent, "claims" | "suggestions">,
722
- Omit<wire.OnboardingResearchTelemetryEvent, "claims" | "suggestions">
723
- >;
724
- type _onboardingResearchKeysExist = AssertNarrows<
725
- keyof OnboardingResearchTelemetryEvent,
726
- keyof wire.OnboardingResearchTelemetryEvent
727
- >;
728
- // An `Extensions` key that also exists in the wire map would silently
729
- // shadow the generated type; this stays `never` only while the key sets
730
- // are disjoint.
731
- type _extensionsDontCollide = AssertNoWireCollision<
732
- keyof Extensions & keyof wire.WireEventMap
733
- >;
734
-
735
- /**
736
- * Event names backed by the `telemetry_events` outbox. Each name doubles as
737
- * the wire `type` discriminant and the flush-group key, so names must never
738
- * change once shipped. The watermark-flushed types (`llm_usage`, `turn`,
739
- * `tool_executed`) live on their own tables and are deliberately excluded.
740
- */
741
- /**
742
- * Types NOT on the generic `telemetry_events` outbox — the high-volume events
743
- * flushed from their own SQLite tables by a watermark source
744
- * (`telemetry-event-sources.ts`). This is the ONLY hand-maintained partition
745
- * fact; every other wire event type is outbox-backed by default. Add a name
746
- * here only when a new type gets its own dedicated table.
747
- */
748
- export const WATERMARK_TELEMETRY_EVENT_NAMES = [
749
- "llm_usage",
750
- "turn",
751
- "tool_executed",
752
- ] as const;
753
-
754
- export type WatermarkTelemetryEventName =
755
- (typeof WATERMARK_TELEMETRY_EVENT_NAMES)[number];
756
-
757
- /**
758
- * Event names backed by the `telemetry_events` outbox: every wire event type
759
- * that is not watermark-flushed. Derived from the generated wire contract, so a
760
- * new event type added on the cloud side flows onto the outbox — and gets a
761
- * flush source (`telemetry-event-sources.ts`) and a fully-typed
762
- * `recordTelemetryEvent` call — with NO edit here. Each name doubles as the
763
- * wire `type` discriminant and the flush-group key.
764
- */
765
- export type OutboxTelemetryEventName = Exclude<
766
- keyof wire.WireEventMap,
767
- WatermarkTelemetryEventName
768
- >;
769
-
770
- export const OUTBOX_TELEMETRY_EVENT_NAMES: readonly OutboxTelemetryEventName[] =
771
- telemetryEventSchema.options
772
- .map((option) => option.shape.type.value)
773
- .filter(
774
- (name): name is OutboxTelemetryEventName =>
775
- !(WATERMARK_TELEMETRY_EVENT_NAMES as readonly string[]).includes(name),
776
- );
777
-
778
- /** Wire event type for one outbox event name. */
779
- export type OutboxTelemetryEventOf<N extends OutboxTelemetryEventName> =
780
- Extract<TelemetryEvent, { type: N }>;