@cortex-agent/server 2026.10.15 → 2026.10.25

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 (469) hide show
  1. package/README.md +81 -51
  2. package/defaults/board/board.css +140 -62
  3. package/defaults/board/scaffold.html +36 -13
  4. package/defaults/config/environments/creative.json +0 -1
  5. package/defaults/config/environments/main.json +1 -2
  6. package/defaults/context/projects/AGENTS.md +1 -1
  7. package/defaults/gitignore +3 -3
  8. package/defaults/hooks/new-session-hook.mjs +1 -1
  9. package/defaults/hooks/status-md-guard.mjs +6 -6
  10. package/defaults/plugins/cortex-board/skills/board/SKILL.md +30 -22
  11. package/defaults/plugins/cortex-system/plugin.json +2 -2
  12. package/defaults/plugins/cortex-system/skills/browser/SKILL.md +56 -0
  13. package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +16 -9
  14. package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +2 -2
  15. package/defaults/rules/agents-md.md +1 -1
  16. package/defaults/rules/issues-md.md +1 -1
  17. package/defaults/rules/meta-conventions.md +3 -3
  18. package/defaults/rules/mission-md.md +1 -1
  19. package/defaults/rules/status-md.md +1 -1
  20. package/dist/agent-adapter/claude/adapter.d.ts +2 -5
  21. package/dist/agent-adapter/claude/adapter.js +6 -5
  22. package/dist/agent-adapter/claude/assistant-blocks.d.ts +5 -0
  23. package/dist/agent-adapter/claude/assistant-blocks.js +61 -0
  24. package/dist/agent-adapter/claude/bg-task-tracker.d.ts +3 -1
  25. package/dist/agent-adapter/claude/bg-task-tracker.js +6 -2
  26. package/dist/agent-adapter/claude/cache-refresh.d.ts +58 -0
  27. package/dist/agent-adapter/claude/cache-refresh.js +145 -0
  28. package/dist/agent-adapter/claude/cache-touch.d.ts +12 -0
  29. package/dist/agent-adapter/claude/cache-touch.js +75 -0
  30. package/dist/agent-adapter/claude/event-parser.d.ts +8 -3
  31. package/dist/agent-adapter/claude/event-parser.js +33 -17
  32. package/dist/agent-adapter/claude/event-translator.d.ts +2 -0
  33. package/dist/agent-adapter/claude/event-translator.js +2 -0
  34. package/dist/agent-adapter/claude/mcp-config.js +11 -0
  35. package/dist/agent-adapter/claude/session-options.d.ts +6 -13
  36. package/dist/agent-adapter/claude/session-options.js +2 -13
  37. package/dist/agent-adapter/claude/spawn-args.d.ts +4 -21
  38. package/dist/agent-adapter/claude/spawn-args.js +17 -24
  39. package/dist/agent-adapter/claude/transcript-clear.d.ts +42 -0
  40. package/dist/agent-adapter/claude/transcript-clear.js +217 -0
  41. package/dist/agent-adapter/claude/turn-machine.d.ts +5 -3
  42. package/dist/agent-adapter/claude/turn-machine.js +29 -73
  43. package/dist/agent-adapter/claude/window-warmup.d.ts +13 -0
  44. package/dist/agent-adapter/claude/window-warmup.js +38 -0
  45. package/dist/agent-adapter/continuation-phase.d.ts +6 -3
  46. package/dist/agent-adapter/continuation-phase.js +11 -3
  47. package/dist/agent-adapter/normalize/event-types.d.ts +8 -0
  48. package/dist/agent-adapter/pi/adapter.d.ts +0 -1
  49. package/dist/agent-adapter/pi/adapter.js +5 -13
  50. package/dist/agent-adapter/pi/event-parser.d.ts +1 -1
  51. package/dist/agent-adapter/pi/event-parser.js +43 -27
  52. package/dist/agent-adapter/pi/mcp-bridge.d.ts +1 -1
  53. package/dist/agent-adapter/pi/pi-session.d.ts +2 -0
  54. package/dist/agent-adapter/pi/pi-session.js +15 -0
  55. package/dist/agent-adapter/pi/providers-config.d.ts +2 -2
  56. package/dist/agent-adapter/pi/providers-config.js +1 -1
  57. package/dist/agent-adapter/pi/quota-sink.d.ts +3 -3
  58. package/dist/agent-adapter/pi/quota-sink.js +3 -3
  59. package/dist/agent-adapter/pi/runtime.js +6 -1
  60. package/dist/agent-adapter/pi/session-options.d.ts +9 -13
  61. package/dist/agent-adapter/pi/session-options.js +12 -25
  62. package/dist/agent-adapter/run-events.d.ts +15 -10
  63. package/dist/agent-adapter/run-events.js +2 -0
  64. package/dist/agent-adapter/types.d.ts +14 -6
  65. package/dist/build-info.json +1 -0
  66. package/dist/client-bundle/client.mjs +10 -5
  67. package/dist/client-bundle/manifest.json +3 -3
  68. package/dist/core/claude-credentials.d.ts +6 -0
  69. package/dist/core/claude-credentials.js +11 -0
  70. package/dist/core/codex-quota.d.ts +1 -1
  71. package/dist/core/codex-quota.js +1 -1
  72. package/dist/core/gateway-generator.d.ts +26 -11
  73. package/dist/core/gateway-generator.js +73 -62
  74. package/dist/core/hook-bus.d.ts +1 -1
  75. package/dist/core/hook-bus.js +1 -8
  76. package/dist/core/locales/en.d.ts +52 -77
  77. package/dist/core/locales/slices/commands.d.ts +26 -31
  78. package/dist/core/locales/slices/commands.js +54 -64
  79. package/dist/core/locales/slices/init.d.ts +9 -19
  80. package/dist/core/locales/slices/init.js +19 -53
  81. package/dist/core/locales/slices/interactions.d.ts +3 -3
  82. package/dist/core/locales/slices/interactions.js +6 -6
  83. package/dist/core/locales/slices/notices.d.ts +1 -3
  84. package/dist/core/locales/slices/notices.js +2 -6
  85. package/dist/core/locales/slices/scheduling.d.ts +9 -9
  86. package/dist/core/locales/slices/scheduling.js +18 -18
  87. package/dist/core/locales/slices/status.d.ts +0 -4
  88. package/dist/core/locales/slices/status.js +0 -8
  89. package/dist/core/locales/slices/tui.d.ts +0 -1
  90. package/dist/core/locales/slices/tui.js +0 -2
  91. package/dist/core/locales/slices/uimsg.d.ts +4 -7
  92. package/dist/core/locales/slices/uimsg.js +9 -15
  93. package/dist/core/log.d.ts +3 -0
  94. package/dist/core/log.js +18 -1
  95. package/dist/core/models-generator.d.ts +29 -0
  96. package/dist/core/models-generator.js +82 -0
  97. package/dist/core/paths.d.ts +1 -1
  98. package/dist/core/paths.js +1 -1
  99. package/dist/core/settings-spec.d.ts +30 -0
  100. package/dist/core/settings-spec.js +38 -0
  101. package/dist/core/status-format.d.ts +3 -2
  102. package/dist/core/status-format.js +2 -2
  103. package/dist/core/types/agent-types.d.ts +3 -1
  104. package/dist/core/types/environment-types.d.ts +1 -8
  105. package/dist/domain/agents/agent-state.d.ts +11 -56
  106. package/dist/domain/agents/agent-state.js +48 -115
  107. package/dist/domain/agents/agent-switch.d.ts +2 -24
  108. package/dist/domain/agents/agent-switch.js +9 -72
  109. package/dist/domain/agents/config.d.ts +11 -61
  110. package/dist/domain/agents/config.js +47 -154
  111. package/dist/domain/agents/engine-selection.d.ts +21 -0
  112. package/dist/domain/agents/engine-selection.js +37 -0
  113. package/dist/domain/agents/environments/registry.js +4 -2
  114. package/dist/domain/agents/environments/resolve.js +0 -1
  115. package/dist/domain/agents/environments/schema.d.ts +3 -3
  116. package/dist/domain/agents/environments/schema.js +4 -4
  117. package/dist/domain/agents/index.d.ts +2 -1
  118. package/dist/domain/agents/index.js +3 -7
  119. package/dist/domain/agents/model-selection.d.ts +18 -70
  120. package/dist/domain/agents/model-selection.js +100 -150
  121. package/dist/domain/agents/models.d.ts +12 -0
  122. package/dist/domain/agents/models.js +94 -0
  123. package/dist/domain/agents/subagent/registry.d.ts +2 -0
  124. package/dist/domain/agents/subagent/registry.js +8 -0
  125. package/dist/domain/agents/subagent/runner.d.ts +5 -5
  126. package/dist/domain/agents/subagent/runner.js +12 -35
  127. package/dist/domain/auth/auth-status.d.ts +4 -4
  128. package/dist/domain/auth/auth-status.js +17 -28
  129. package/dist/domain/auth/auth-watch.js +48 -18
  130. package/dist/domain/auth/gateway-sync.d.ts +6 -26
  131. package/dist/domain/auth/gateway-sync.js +31 -75
  132. package/dist/domain/benchmark/identity.d.ts +3 -5
  133. package/dist/domain/benchmark/identity.js +0 -1
  134. package/dist/domain/benchmark/production-attempt-identity.d.ts +6 -5
  135. package/dist/domain/benchmark/production-attempt-identity.js +32 -35
  136. package/dist/domain/benchmark/session-evidence.d.ts +2 -1
  137. package/dist/domain/benchmark/session-evidence.js +8 -1
  138. package/dist/domain/browser/broker.d.ts +99 -0
  139. package/dist/domain/browser/broker.js +487 -0
  140. package/dist/domain/costs/claude-account.js +21 -0
  141. package/dist/domain/costs/rate-limit-throttle.js +3 -1
  142. package/dist/domain/costs/reset-account.d.ts +2 -0
  143. package/dist/domain/costs/usage-service.d.ts +1 -1
  144. package/dist/domain/costs/usage-service.js +20 -7
  145. package/dist/domain/mcp/tools/context.d.ts +5 -7
  146. package/dist/domain/mcp/tools/context.js +17 -4
  147. package/dist/domain/mcp/tools/subagent.js +1 -1
  148. package/dist/domain/mcp/tools/ui-file.js +1 -1
  149. package/dist/domain/monitor/event-loop-monitor.d.ts +2 -0
  150. package/dist/domain/monitor/event-loop-monitor.js +5 -1
  151. package/dist/domain/pi-providers/custom-provider-model.d.ts +1 -1
  152. package/dist/domain/pi-providers/custom-provider-model.js +1 -1
  153. package/dist/domain/plugins/authoring.d.ts +8 -1
  154. package/dist/domain/plugins/authoring.js +24 -9
  155. package/dist/domain/plugins/runtime-gc.d.ts +7 -0
  156. package/dist/domain/plugins/runtime-gc.js +52 -19
  157. package/dist/domain/plugins/runtime.js +2 -1
  158. package/dist/domain/remote/client-bootstrap.js +1 -1
  159. package/dist/domain/remote/client-manager.js +6 -1
  160. package/dist/domain/remote/device-browser.js +1 -1
  161. package/dist/domain/remote/device-chrome-commands.js +2 -0
  162. package/dist/domain/remote/device-port.js +2 -2
  163. package/dist/domain/runs/attempt.d.ts +3 -3
  164. package/dist/domain/runs/attempt.js +2 -3
  165. package/dist/domain/runs/builders.d.ts +4 -4
  166. package/dist/domain/runs/builders.js +4 -5
  167. package/dist/domain/runs/compact.d.ts +4 -17
  168. package/dist/domain/runs/compact.js +14 -56
  169. package/dist/domain/runs/config-resolver.d.ts +15 -83
  170. package/dist/domain/runs/config-resolver.js +24 -150
  171. package/dist/domain/runs/engine-spec.d.ts +8 -8
  172. package/dist/domain/runs/engine-spec.js +15 -31
  173. package/dist/domain/runs/events.d.ts +1 -1
  174. package/dist/domain/runs/fallback.d.ts +6 -38
  175. package/dist/domain/runs/fallback.js +10 -72
  176. package/dist/domain/runs/notices.d.ts +1 -11
  177. package/dist/domain/runs/notices.js +3 -30
  178. package/dist/domain/runs/request.d.ts +4 -3
  179. package/dist/domain/runs/retryable-errors.d.ts +0 -13
  180. package/dist/domain/runs/retryable-errors.js +3 -18
  181. package/dist/domain/runs/run.d.ts +12 -42
  182. package/dist/domain/runs/run.js +40 -147
  183. package/dist/domain/runs/service.d.ts +0 -9
  184. package/dist/domain/runs/service.js +33 -14
  185. package/dist/domain/runs/spec-loader.d.ts +1 -1
  186. package/dist/domain/runs/spend.d.ts +1 -1
  187. package/dist/domain/runs/spend.js +1 -1
  188. package/dist/domain/scheduling/builtin-job-controller.d.ts +3 -1
  189. package/dist/domain/scheduling/builtin-job-controller.js +5 -2
  190. package/dist/domain/scheduling/builtin-jobs.js +7 -0
  191. package/dist/domain/scheduling/jobs/scheduled-task.d.ts +3 -2
  192. package/dist/domain/scheduling/jobs/scheduled-task.js +25 -19
  193. package/dist/domain/scheduling/schedule-ops.d.ts +0 -1
  194. package/dist/domain/scheduling/schedule-ops.js +2 -5
  195. package/dist/domain/scheduling/schedule-selection.d.ts +3 -0
  196. package/dist/domain/scheduling/schedule-selection.js +16 -0
  197. package/dist/domain/scheduling/schedule-spec.d.ts +6 -5
  198. package/dist/domain/scheduling/schedule-spec.js +6 -6
  199. package/dist/domain/scheduling/scheduler.d.ts +3 -1
  200. package/dist/domain/scheduling/scheduler.js +36 -26
  201. package/dist/domain/sessions/session-hooks.d.ts +5 -4
  202. package/dist/domain/sessions/session-hooks.js +15 -33
  203. package/dist/domain/sessions/session-lifecycle.d.ts +19 -51
  204. package/dist/domain/sessions/session-lifecycle.js +34 -96
  205. package/dist/domain/system/doctor.d.ts +3 -3
  206. package/dist/domain/system/doctor.js +22 -26
  207. package/dist/domain/system/own-bin-path.d.ts +13 -0
  208. package/dist/domain/system/own-bin-path.js +36 -0
  209. package/dist/domain/system/server-update-check.js +2 -1
  210. package/dist/domain/system/terminal-cli/index.d.ts +58 -0
  211. package/dist/domain/system/terminal-cli/index.js +100 -0
  212. package/dist/domain/system/terminal-cli/posix-profiles.d.ts +23 -0
  213. package/dist/domain/system/terminal-cli/posix-profiles.js +74 -0
  214. package/dist/domain/system/terminal-cli/registrar.d.ts +12 -0
  215. package/dist/domain/system/terminal-cli/registrar.js +1 -0
  216. package/dist/domain/system/terminal-cli/shims.d.ts +27 -0
  217. package/dist/domain/system/terminal-cli/shims.js +108 -0
  218. package/dist/domain/system/terminal-cli/state.d.ts +7 -0
  219. package/dist/domain/system/terminal-cli/state.js +36 -0
  220. package/dist/domain/system/terminal-cli/windows-user-path.d.ts +13 -0
  221. package/dist/domain/system/terminal-cli/windows-user-path.js +67 -0
  222. package/dist/domain/telemetry/bus-collector.d.ts +3 -0
  223. package/dist/domain/telemetry/bus-collector.js +22 -0
  224. package/dist/domain/telemetry/child-exit.d.ts +11 -0
  225. package/dist/domain/telemetry/child-exit.js +36 -0
  226. package/dist/domain/telemetry/client-kind.d.ts +4 -0
  227. package/dist/domain/telemetry/client-kind.js +7 -0
  228. package/dist/domain/telemetry/crash-limits.d.ts +15 -0
  229. package/dist/domain/telemetry/crash-limits.js +50 -0
  230. package/dist/domain/telemetry/crash.d.ts +25 -0
  231. package/dist/domain/telemetry/crash.js +70 -0
  232. package/dist/domain/telemetry/daily-upload.d.ts +5 -0
  233. package/dist/domain/telemetry/daily-upload.js +20 -0
  234. package/dist/domain/telemetry/daily.d.ts +5 -0
  235. package/dist/domain/telemetry/daily.js +104 -0
  236. package/dist/domain/telemetry/endpoint.d.ts +7 -0
  237. package/dist/domain/telemetry/endpoint.js +40 -0
  238. package/dist/domain/telemetry/envelope.d.ts +6 -0
  239. package/dist/domain/telemetry/envelope.js +35 -0
  240. package/dist/domain/telemetry/error-digest.d.ts +7 -0
  241. package/dist/domain/telemetry/error-digest.js +43 -0
  242. package/dist/domain/telemetry/funnel.d.ts +6 -0
  243. package/dist/domain/telemetry/funnel.js +22 -0
  244. package/dist/domain/telemetry/gate.d.ts +19 -0
  245. package/dist/domain/telemetry/gate.js +67 -0
  246. package/dist/domain/telemetry/heartbeat.d.ts +17 -0
  247. package/dist/domain/telemetry/heartbeat.js +49 -0
  248. package/dist/domain/telemetry/info.d.ts +9 -0
  249. package/dist/domain/telemetry/info.js +12 -0
  250. package/dist/domain/telemetry/init-answer.d.ts +12 -0
  251. package/dist/domain/telemetry/init-answer.js +42 -0
  252. package/dist/domain/telemetry/install-id.d.ts +5 -0
  253. package/dist/domain/telemetry/install-id.js +42 -0
  254. package/dist/domain/telemetry/normalize.d.ts +33 -0
  255. package/dist/domain/telemetry/normalize.js +88 -0
  256. package/dist/domain/telemetry/outbox.d.ts +18 -0
  257. package/dist/domain/telemetry/outbox.js +93 -0
  258. package/dist/domain/telemetry/panic-group.d.ts +4 -0
  259. package/dist/domain/telemetry/panic-group.js +51 -0
  260. package/dist/domain/telemetry/paths.d.ts +7 -0
  261. package/dist/domain/telemetry/paths.js +11 -0
  262. package/dist/domain/telemetry/redact.d.ts +18 -0
  263. package/dist/domain/telemetry/redact.js +109 -0
  264. package/dist/domain/telemetry/rollup-types.d.ts +81 -0
  265. package/dist/domain/telemetry/rollup-types.js +31 -0
  266. package/dist/domain/telemetry/rollup.d.ts +16 -0
  267. package/dist/domain/telemetry/rollup.js +102 -0
  268. package/dist/domain/telemetry/schema.d.ts +931 -0
  269. package/dist/domain/telemetry/schema.js +275 -0
  270. package/dist/domain/telemetry/service.d.ts +34 -0
  271. package/dist/domain/telemetry/service.js +146 -0
  272. package/dist/domain/telemetry/state.d.ts +17 -0
  273. package/dist/domain/telemetry/state.js +29 -0
  274. package/dist/domain/telemetry/turns.d.ts +17 -0
  275. package/dist/domain/telemetry/turns.js +176 -0
  276. package/dist/domain/telemetry/upgrade.d.ts +14 -0
  277. package/dist/domain/telemetry/upgrade.js +87 -0
  278. package/dist/domain/telemetry/uploader.d.ts +21 -0
  279. package/dist/domain/telemetry/uploader.js +82 -0
  280. package/dist/domain/telemetry/usage.d.ts +25 -0
  281. package/dist/domain/telemetry/usage.js +153 -0
  282. package/dist/domain/telemetry/web-report.d.ts +8 -0
  283. package/dist/domain/telemetry/web-report.js +15 -0
  284. package/dist/domain/tui-session/tui-session-service.js +1 -1
  285. package/dist/domain/tui-session/types.d.ts +2 -2
  286. package/dist/domain/ui-service/app-router.d.ts +117 -95
  287. package/dist/domain/ui-service/app-router.js +17 -14
  288. package/dist/domain/ui-service/assistant-snapshots.js +2 -0
  289. package/dist/domain/ui-service/contract.parity.d.ts +19 -0
  290. package/dist/domain/ui-service/contract.parity.js +1 -0
  291. package/dist/domain/ui-service/inline-media-types.d.ts +18 -0
  292. package/dist/domain/ui-service/inline-media-types.js +1 -0
  293. package/dist/domain/ui-service/input-schemas.d.ts +120 -119
  294. package/dist/domain/ui-service/input-schemas.js +47 -85
  295. package/dist/domain/ui-service/mutate/approvals.d.ts +3 -2
  296. package/dist/domain/ui-service/mutate/approvals.js +3 -2
  297. package/dist/domain/ui-service/mutate/auth.d.ts +1 -1
  298. package/dist/domain/ui-service/mutate/auth.js +3 -2
  299. package/dist/domain/ui-service/mutate/config.d.ts +0 -8
  300. package/dist/domain/ui-service/mutate/config.js +0 -22
  301. package/dist/domain/ui-service/mutate/models.d.ts +13 -0
  302. package/dist/domain/ui-service/mutate/models.js +137 -0
  303. package/dist/domain/ui-service/mutate/plugin-packages.js +1 -1
  304. package/dist/domain/ui-service/mutate/resolve-media.d.ts +4 -0
  305. package/dist/domain/ui-service/mutate/resolve-media.js +17 -0
  306. package/dist/domain/ui-service/mutate/sessions.d.ts +2 -2
  307. package/dist/domain/ui-service/mutate/sessions.js +29 -126
  308. package/dist/domain/ui-service/mutate/telemetry.d.ts +5 -0
  309. package/dist/domain/ui-service/mutate/telemetry.js +6 -0
  310. package/dist/domain/ui-service/query/approvals.js +4 -3
  311. package/dist/domain/ui-service/query/config.js +22 -42
  312. package/dist/domain/ui-service/query/machine-probe.d.ts +1 -1
  313. package/dist/domain/ui-service/query/machine-probe.js +3 -2
  314. package/dist/domain/ui-service/query/models.d.ts +3 -0
  315. package/dist/domain/ui-service/query/models.js +49 -32
  316. package/dist/domain/ui-service/query/plugin-source.js +4 -3
  317. package/dist/domain/ui-service/query/schedules.js +1 -1
  318. package/dist/domain/ui-service/query/sessions.js +8 -13
  319. package/dist/domain/ui-service/query/telemetry.d.ts +3 -0
  320. package/dist/domain/ui-service/query/telemetry.js +4 -0
  321. package/dist/domain/ui-service/trpc.d.ts +8 -3
  322. package/dist/domain/ui-service/trpc.js +1 -1
  323. package/dist/domain/ui-service/types.d.ts +71 -179
  324. package/dist/domain/ui-service/ui-service.d.ts +56 -53
  325. package/dist/domain/ui-service/ui-service.js +27 -24
  326. package/dist/entry/app.js +62 -21
  327. package/dist/entry/browser-cli.d.ts +39 -0
  328. package/dist/entry/browser-cli.js +317 -0
  329. package/dist/entry/cli-help.d.ts +1 -0
  330. package/dist/entry/cli-help.js +64 -20
  331. package/dist/entry/cli.js +16 -14
  332. package/dist/entry/daemon.d.ts +1 -1
  333. package/dist/entry/daemon.js +88 -72
  334. package/dist/entry/init-auth.js +1 -1
  335. package/dist/entry/init.d.ts +10 -8
  336. package/dist/entry/init.js +138 -276
  337. package/dist/entry/path-cli.d.ts +4 -0
  338. package/dist/entry/path-cli.js +65 -0
  339. package/dist/entry/schedule-cli.js +13 -6
  340. package/dist/entry/shutdown.d.ts +1 -1
  341. package/dist/entry/shutdown.js +11 -1
  342. package/dist/entry/signal-cli.js +8 -11
  343. package/dist/entry/start-ui-http.js +48 -18
  344. package/dist/entry/telemetry-wiring.d.ts +12 -0
  345. package/dist/entry/telemetry-wiring.js +56 -0
  346. package/dist/entry/ui-cli.d.ts +0 -11
  347. package/dist/entry/ui-cli.js +42 -33
  348. package/dist/entry/ui-service-wiring.js +8 -10
  349. package/dist/events/event-types.d.ts +4 -6
  350. package/dist/orchestration/agent-runner.d.ts +2 -2
  351. package/dist/orchestration/agent-runner.js +10 -9
  352. package/dist/orchestration/benchmark-session-webhook.js +13 -1
  353. package/dist/orchestration/browser-webhook.d.ts +11 -0
  354. package/dist/orchestration/browser-webhook.js +28 -0
  355. package/dist/orchestration/cache-keep-warm.d.ts +77 -0
  356. package/dist/orchestration/cache-keep-warm.js +213 -0
  357. package/dist/orchestration/claude-window-warmup.d.ts +40 -0
  358. package/dist/orchestration/claude-window-warmup.js +126 -0
  359. package/dist/orchestration/conversation-request.d.ts +6 -10
  360. package/dist/orchestration/conversation-request.js +5 -23
  361. package/dist/orchestration/delta-coalescer.d.ts +4 -2
  362. package/dist/orchestration/delta-coalescer.js +5 -5
  363. package/dist/orchestration/edit-retry.js +9 -11
  364. package/dist/orchestration/inline-media-eager.d.ts +13 -0
  365. package/dist/orchestration/inline-media-eager.js +58 -0
  366. package/dist/orchestration/inline-media.d.ts +22 -0
  367. package/dist/orchestration/inline-media.js +151 -0
  368. package/dist/orchestration/interactions/ask-user-resume.js +3 -7
  369. package/dist/orchestration/interactions/interaction-handlers.js +6 -6
  370. package/dist/orchestration/mid-turn-inject.d.ts +2 -1
  371. package/dist/orchestration/mid-turn-inject.js +1 -1
  372. package/dist/orchestration/pending-injection-recovery.d.ts +2 -1
  373. package/dist/orchestration/pending-injection-recovery.js +1 -1
  374. package/dist/orchestration/routing/commands/index.js +4 -4
  375. package/dist/orchestration/routing/commands/mode.d.ts +5 -44
  376. package/dist/orchestration/routing/commands/mode.js +98 -272
  377. package/dist/orchestration/routing/commands/schedule.js +29 -18
  378. package/dist/orchestration/routing/commands/session.js +9 -9
  379. package/dist/orchestration/routing/commands/status.js +1 -1
  380. package/dist/orchestration/routing/commands/usage-format.js +3 -0
  381. package/dist/orchestration/routing/message-router.js +2 -0
  382. package/dist/orchestration/routing/webhook.js +6 -0
  383. package/dist/orchestration/session-compact.d.ts +0 -1
  384. package/dist/orchestration/session-compact.js +5 -7
  385. package/dist/orchestration/session-events.d.ts +2 -1
  386. package/dist/orchestration/session-events.js +1 -0
  387. package/dist/orchestration/status-helpers.d.ts +0 -4
  388. package/dist/orchestration/status-helpers.js +0 -18
  389. package/dist/orchestration/subagent-webhook.js +9 -34
  390. package/dist/orchestration/team-webhook.d.ts +8 -9
  391. package/dist/orchestration/team-webhook.js +16 -42
  392. package/dist/orchestration/transcript-sink.d.ts +12 -0
  393. package/dist/orchestration/transcript-sink.js +38 -2
  394. package/dist/orchestration/turn/terminal.js +7 -7
  395. package/dist/orchestration/turn/turn-prep.d.ts +0 -8
  396. package/dist/orchestration/turn/turn-prep.js +0 -51
  397. package/dist/orchestration/turn/turn-tracking.d.ts +2 -2
  398. package/dist/orchestration/turn/turn-tracking.js +8 -5
  399. package/dist/orchestration/turn/turn.d.ts +0 -2
  400. package/dist/orchestration/turn/turn.js +13 -15
  401. package/dist/orchestration/waitpoint-ingress.js +3 -0
  402. package/dist/platform/adapters/tui/ports.d.ts +1 -1
  403. package/dist/platform/adapters/tui/tui-transcript.js +2 -0
  404. package/dist/platform/browser/agent-browser.d.ts +50 -0
  405. package/dist/platform/browser/agent-browser.js +165 -0
  406. package/dist/platform/browser/managed-browser.d.ts +1 -11
  407. package/dist/platform/browser/managed-browser.js +4 -12
  408. package/dist/platform/ui-http/browser-stream.d.ts +110 -0
  409. package/dist/platform/ui-http/browser-stream.js +447 -0
  410. package/dist/platform/ui-http/ui-auth-routes.d.ts +2 -0
  411. package/dist/platform/ui-http/ui-auth-routes.js +9 -2
  412. package/dist/platform/ui-http/ui-device-routes.d.ts +13 -0
  413. package/dist/platform/ui-http/ui-device-routes.js +81 -0
  414. package/dist/platform/ui-http/ui-devices.d.ts +24 -0
  415. package/dist/platform/ui-http/ui-devices.js +107 -0
  416. package/dist/platform/ui-http/ui-http-server.d.ts +22 -3
  417. package/dist/platform/ui-http/ui-http-server.js +33 -12
  418. package/dist/platform/ui-http/ui-pairing.d.ts +25 -0
  419. package/dist/platform/ui-http/ui-pairing.js +98 -0
  420. package/dist/store/conversation-history-reader.js +8 -0
  421. package/dist/store/conversation-history-repo.d.ts +8 -1
  422. package/dist/store/conversation-history-repo.js +5 -0
  423. package/dist/store/conversation-ledger-repo.d.ts +6 -6
  424. package/dist/store/conversation-ledger-repo.js +4 -4
  425. package/dist/store/gitignore-migration.d.ts +2 -0
  426. package/dist/store/gitignore-migration.js +16 -0
  427. package/dist/store/hook-registry.d.ts +1 -1
  428. package/dist/store/hook-registry.js +11 -6
  429. package/dist/store/models-repo.d.ts +18 -0
  430. package/dist/store/models-repo.js +74 -0
  431. package/dist/store/pending-injection-repo.d.ts +2 -1
  432. package/dist/store/pending-injection-repo.js +3 -1
  433. package/dist/store/retire-profiles-migration.d.ts +28 -0
  434. package/dist/store/retire-profiles-migration.js +335 -0
  435. package/dist/store/schedule-repo.d.ts +2 -1
  436. package/dist/store/session-registry-import.js +3 -2
  437. package/dist/store/session-registry-journal.d.ts +10 -13
  438. package/dist/store/session-registry-journal.js +51 -25
  439. package/dist/store/session-registry-repo.d.ts +4 -4
  440. package/dist/store/session-registry-repo.js +4 -5
  441. package/dist/store/version-migrations.d.ts +7 -3
  442. package/dist/store/version-migrations.js +133 -80
  443. package/dist/tui/components/Dashboard.js +4 -3
  444. package/dist/tui/hooks/useDashboardData.js +1 -1
  445. package/dist/tui/slash-commands.js +2 -2
  446. package/dist/tui/turn-status.js +1 -1
  447. package/package.json +6 -4
  448. package/web/dist/assets/board-math-css-spk7yR6n.js +2 -0
  449. package/web/dist/assets/index-BQ69u-92.css +1 -0
  450. package/web/dist/assets/{index-CndZZ1IQ.js → index-CKNLatCd.js} +1 -1
  451. package/web/dist/assets/index-CkzWfC98.js +525 -0
  452. package/web/dist/index.html +3 -2
  453. package/web/dist/theme.css +6 -0
  454. package/dist/agent-adapter/browser-mcp-server.d.ts +0 -13
  455. package/dist/agent-adapter/browser-mcp-server.js +0 -28
  456. package/dist/agent-adapter/claude/browser-mcp.d.ts +0 -9
  457. package/dist/agent-adapter/claude/browser-mcp.js +0 -10
  458. package/dist/core/profile-generator.d.ts +0 -79
  459. package/dist/core/profile-generator.js +0 -215
  460. package/dist/domain/agents/profile-manager.d.ts +0 -103
  461. package/dist/domain/agents/profile-manager.js +0 -286
  462. package/dist/domain/agents/profile-switch.d.ts +0 -49
  463. package/dist/domain/agents/profile-switch.js +0 -62
  464. package/dist/domain/ui-service/mutate/profiles.d.ts +0 -36
  465. package/dist/domain/ui-service/mutate/profiles.js +0 -151
  466. package/dist/store/profile-repo.d.ts +0 -20
  467. package/dist/store/profile-repo.js +0 -97
  468. package/web/dist/assets/index-B76ueW3q.js +0 -494
  469. package/web/dist/assets/index-C8O0yxg8.css +0 -1
@@ -0,0 +1,19 @@
1
+ export declare const TELEMETRY_INACTIVE_REASONS: readonly ['setting', 'env', 'do-not-track', 'sealed', 'no-endpoint', 'dev'];
2
+ export type TelemetryInactiveReason = (typeof TELEMETRY_INACTIVE_REASONS)[number];
3
+ export interface TelemetryGateInput {
4
+ settingEnabled: boolean;
5
+ env: NodeJS.ProcessEnv;
6
+ /** Running from a source checkout (`CORTEX_REPO`, or a tree that still has `src/`). */
7
+ devCheckout: boolean;
8
+ endpoint: string | null;
9
+ }
10
+ export interface TelemetryGate {
11
+ active: boolean;
12
+ reason: TelemetryInactiveReason | null;
13
+ channel: 'release' | 'dev';
14
+ endpoint: string | null;
15
+ }
16
+ /** Pure decision; `telemetryGate()` feeds it the live inputs. */
17
+ export declare function evaluateTelemetryGate(input: TelemetryGateInput): TelemetryGate;
18
+ export declare function telemetryGate(env?: NodeJS.ProcessEnv): TelemetryGate;
19
+ export declare function isTelemetryActive(): boolean;
@@ -0,0 +1,67 @@
1
+ import { existsSync, statSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { INSTALL_ROOT } from '../../core/paths.js';
4
+ import { getSettings } from '../../core/settings.js';
5
+ import { resolveTelemetryEndpoint } from './endpoint.js';
6
+ export const TELEMETRY_INACTIVE_REASONS = [
7
+ 'setting', 'env', 'do-not-track', 'sealed', 'no-endpoint', 'dev',
8
+ ];
9
+ function truthyFlag(raw) {
10
+ if (raw === undefined)
11
+ return false;
12
+ const value = raw.trim().toLowerCase();
13
+ return value !== '' && value !== '0' && value !== 'false' && value !== 'no' && value !== 'off';
14
+ }
15
+ /** Hard switches that win over the saved setting, in the order they are reported. */
16
+ function forcedOffReason(env) {
17
+ if (env.CORTEX_TELEMETRY?.trim() === '0')
18
+ return 'env';
19
+ if (truthyFlag(env.DO_NOT_TRACK))
20
+ return 'do-not-track';
21
+ if (env.CORTEX_CONFIG_IMMUTABLE === '1')
22
+ return 'sealed';
23
+ return null;
24
+ }
25
+ /** Pure decision; `telemetryGate()` feeds it the live inputs. */
26
+ export function evaluateTelemetryGate(input) {
27
+ const explicitOn = input.env.CORTEX_TELEMETRY?.trim() === '1';
28
+ const channel = input.devCheckout ? 'dev' : 'release';
29
+ const off = (reason) => ({ active: false, reason, channel, endpoint: input.endpoint });
30
+ const forced = forcedOffReason(input.env);
31
+ if (forced)
32
+ return off(forced);
33
+ if (!input.settingEnabled)
34
+ return off('setting');
35
+ if (input.devCheckout && !explicitOn)
36
+ return off('dev');
37
+ if (!input.endpoint)
38
+ return off('no-endpoint');
39
+ return { active: true, reason: null, channel, endpoint: input.endpoint };
40
+ }
41
+ let cachedDevCheckout;
42
+ /** `CORTEX_REPO` names an existing directory: the same test as the update checker's dev mode. */
43
+ function repoCheckoutConfigured() {
44
+ const repo = process.env.CORTEX_REPO;
45
+ try {
46
+ return !!repo && statSync(repo).isDirectory();
47
+ }
48
+ catch {
49
+ return false;
50
+ }
51
+ }
52
+ /** Fixed for the life of the process; checked once (the gate runs on hot paths). */
53
+ function isDevCheckout() {
54
+ cachedDevCheckout ??= existsSync(path.join(INSTALL_ROOT, 'src', 'entry')) || repoCheckoutConfigured();
55
+ return cachedDevCheckout;
56
+ }
57
+ export function telemetryGate(env = process.env) {
58
+ return evaluateTelemetryGate({
59
+ settingEnabled: getSettings().telemetryEnabled,
60
+ env,
61
+ devCheckout: isDevCheckout(),
62
+ endpoint: resolveTelemetryEndpoint(env),
63
+ });
64
+ }
65
+ export function isTelemetryActive() {
66
+ return telemetryGate().active;
67
+ }
@@ -0,0 +1,17 @@
1
+ import type { AuthStatusSnapshot } from '../auth/auth-status.js';
2
+ import { type NameCatalog } from './normalize.js';
3
+ import type { HeartbeatEvent } from './schema.js';
4
+ /** The settings a heartbeat reports, by name; all booleans the user can see in Settings. */
5
+ export declare const HEARTBEAT_SETTINGS: readonly ['teamEnabled', 'serverAutoUpdate', 'serverUpdateDisable', 'autoResume', 'bgContinuation', 'streamDeltas', 'clientHotReloadEnabled', 'storeArchiveEnabled', 'providerUsageCollectionEnabled', 'claudeWindowWarmupEnabled', 'feishuSkillsInWeb', 'memoryIndexRegenEnabled'];
6
+ export interface HeartbeatSources {
7
+ authStatus: () => Promise<AuthStatusSnapshot | null>;
8
+ projects: () => number;
9
+ onlineDevices: () => Array<{
10
+ platform: string;
11
+ }>;
12
+ activeSessions24h: () => Promise<number>;
13
+ uptimeS: () => number;
14
+ settings: () => Record<string, unknown>;
15
+ catalog: () => Promise<NameCatalog>;
16
+ }
17
+ export declare function buildHeartbeat(sources: HeartbeatSources, now?: Date): Promise<HeartbeatEvent>;
@@ -0,0 +1,49 @@
1
+ import { normalizeProviderList, toIdent } from './normalize.js';
2
+ /** The settings a heartbeat reports, by name; all booleans the user can see in Settings. */
3
+ export const HEARTBEAT_SETTINGS = [
4
+ 'teamEnabled', 'serverAutoUpdate', 'serverUpdateDisable', 'autoResume', 'bgContinuation',
5
+ 'streamDeltas', 'clientHotReloadEnabled', 'storeArchiveEnabled', 'providerUsageCollectionEnabled',
6
+ 'claudeWindowWarmupEnabled', 'feishuSkillsInWeb', 'memoryIndexRegenEnabled',
7
+ ];
8
+ function usable(account) {
9
+ return account.state === 'logged-in' || account.state === 'expiring';
10
+ }
11
+ function claudeBilling(accounts) {
12
+ const claude = accounts.find((account) => account.backend === 'claude' && usable(account));
13
+ if (!claude)
14
+ return 'none';
15
+ return claude.authType === 'api_key' ? 'api' : 'plan';
16
+ }
17
+ function platformCounts(devices) {
18
+ const counts = {};
19
+ for (const { platform } of devices) {
20
+ const key = ['linux', 'darwin', 'win32'].includes(platform)
21
+ ? platform : 'other';
22
+ counts[key] = (counts[key] ?? 0) + 1;
23
+ }
24
+ return counts;
25
+ }
26
+ function pickSettings(settings) {
27
+ return Object.fromEntries(HEARTBEAT_SETTINGS
28
+ .filter((key) => typeof settings[key] === 'boolean')
29
+ .map((key) => [toIdent(key), settings[key]]));
30
+ }
31
+ export async function buildHeartbeat(sources, now = new Date()) {
32
+ const snapshot = await sources.authStatus().catch(() => null);
33
+ const accounts = snapshot?.accounts.filter(usable) ?? [];
34
+ const devices = sources.onlineDevices();
35
+ const piNames = accounts.filter((account) => account.backend === 'pi').map((account) => account.provider);
36
+ return {
37
+ type: 'heartbeat',
38
+ at: now.toISOString(),
39
+ backends: [...new Set(accounts.map((account) => account.backend))],
40
+ claudeBilling: claudeBilling(accounts),
41
+ piProviders: normalizeProviderList(piNames, await sources.catalog()).slice(0, 60),
42
+ projects: sources.projects(),
43
+ onlineClients: devices.length,
44
+ clientPlatforms: platformCounts(devices),
45
+ activeSessions24h: await sources.activeSessions24h().catch(() => 0),
46
+ uptimeH: Math.round((sources.uptimeS() / 3600) * 100) / 100,
47
+ settings: pickSettings(sources.settings()),
48
+ };
49
+ }
@@ -0,0 +1,9 @@
1
+ import { type TelemetryInactiveReason } from './gate.js';
2
+ /** What the Privacy settings section shows (`telemetry.info`). */
3
+ export interface TelemetryInfo {
4
+ settingEnabled: boolean;
5
+ active: boolean;
6
+ inactiveReason: TelemetryInactiveReason | null;
7
+ installId: string;
8
+ }
9
+ export declare function telemetryInfo(): TelemetryInfo;
@@ -0,0 +1,12 @@
1
+ import { getSettings } from '../../core/settings.js';
2
+ import { telemetryGate } from './gate.js';
3
+ import { getInstallId } from './install-id.js';
4
+ export function telemetryInfo() {
5
+ const gate = telemetryGate();
6
+ return {
7
+ settingEnabled: getSettings().telemetryEnabled,
8
+ active: gate.active,
9
+ inactiveReason: gate.reason,
10
+ installId: getInstallId(),
11
+ };
12
+ }
@@ -0,0 +1,12 @@
1
+ import { type InitTelemetryAnswer } from './schema.js';
2
+ /** The `telemetry` field of `cortex init --answers`, or undefined when absent or malformed. */
3
+ export declare function parseInitTelemetryAnswer(value: unknown): InitTelemetryAnswer | undefined;
4
+ /**
5
+ * Persist the init choice into the new home: `telemetryEnabled` in settings.json, and the
6
+ * caller's install id (the desktop shell's, so its setup events and the server's join up) unless
7
+ * this home already has one.
8
+ */
9
+ export declare function applyInitTelemetry(answer: InitTelemetryAnswer, dirs: {
10
+ configDir: string;
11
+ storeDir: string;
12
+ }): void;
@@ -0,0 +1,42 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { adoptInstallId, isInstallId } from './install-id.js';
4
+ import { InitTelemetryAnswerSchema } from './schema.js';
5
+ /** The `telemetry` field of `cortex init --answers`, or undefined when absent or malformed. */
6
+ export function parseInitTelemetryAnswer(value) {
7
+ if (value === undefined)
8
+ return undefined;
9
+ const parsed = InitTelemetryAnswerSchema.safeParse(value);
10
+ return parsed.success ? parsed.data : undefined;
11
+ }
12
+ function readSettingsObject(file) {
13
+ if (!existsSync(file))
14
+ return {};
15
+ const parsed = JSON.parse(readFileSync(file, 'utf8'));
16
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
17
+ throw new Error(`${file} must contain a JSON object`);
18
+ }
19
+ return parsed;
20
+ }
21
+ /**
22
+ * Persist the init choice into the new home: `telemetryEnabled` in settings.json, and the
23
+ * caller's install id (the desktop shell's, so its setup events and the server's join up) unless
24
+ * this home already has one.
25
+ */
26
+ export function applyInitTelemetry(answer, dirs) {
27
+ const settingsFile = path.join(dirs.configDir, 'settings.json');
28
+ const settings = readSettingsObject(settingsFile);
29
+ mkdirSync(dirs.configDir, { recursive: true });
30
+ writeFileSync(settingsFile, `${JSON.stringify({ ...settings, telemetryEnabled: answer.enabled }, null, 2)}\n`, 'utf8');
31
+ const idFile = path.join(dirs.storeDir, 'telemetry', 'install-id');
32
+ if (answer.installId && !hasInstallId(idFile))
33
+ adoptInstallId(answer.installId, idFile);
34
+ }
35
+ function hasInstallId(file) {
36
+ try {
37
+ return isInstallId(readFileSync(file, 'utf8').trim());
38
+ }
39
+ catch {
40
+ return false;
41
+ }
42
+ }
@@ -0,0 +1,5 @@
1
+ export declare function isInstallId(value: unknown): value is string;
2
+ /** The random per-install id, created on first use. Carries no machine or user information. */
3
+ export declare function getInstallId(file?: string): string;
4
+ /** Take over an id generated elsewhere (the desktop shell hands its own to `cortex init`). */
5
+ export declare function adoptInstallId(id: string, file?: string): void;
@@ -0,0 +1,42 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { INSTALL_ID_FILE } from './paths.js';
5
+ const cache = new Map();
6
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
7
+ export function isInstallId(value) {
8
+ return typeof value === 'string' && UUID_RE.test(value);
9
+ }
10
+ function readInstallId(file) {
11
+ try {
12
+ const value = readFileSync(file, 'utf8').trim();
13
+ return isInstallId(value) ? value.toLowerCase() : null;
14
+ }
15
+ catch {
16
+ return null;
17
+ }
18
+ }
19
+ function writeInstallId(file, id) {
20
+ mkdirSync(path.dirname(file), { recursive: true });
21
+ writeFileSync(file, `${id}\n`, { encoding: 'utf8', mode: 0o600 });
22
+ }
23
+ /** The random per-install id, created on first use. Carries no machine or user information. */
24
+ export function getInstallId(file = INSTALL_ID_FILE) {
25
+ const onDisk = readInstallId(file);
26
+ const id = onDisk ?? cache.get(file) ?? randomUUID();
27
+ if (!onDisk) {
28
+ try {
29
+ writeInstallId(file, id);
30
+ }
31
+ catch { /* unwritable home: the id lives for this process */ }
32
+ }
33
+ cache.set(file, id);
34
+ return id;
35
+ }
36
+ /** Take over an id generated elsewhere (the desktop shell hands its own to `cortex init`). */
37
+ export function adoptInstallId(id, file = INSTALL_ID_FILE) {
38
+ if (!isInstallId(id))
39
+ throw new Error('install id must be a UUID');
40
+ writeInstallId(file, id.toLowerCase());
41
+ cache.set(file, id.toLowerCase());
42
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Public names an upload may carry: the PI SDK's bundled static catalog plus Cortex's own Claude
3
+ * list. Anything else a user configured (custom providers, local or dynamically listed models,
4
+ * third-party MCP tools) is replaced by a placeholder.
5
+ */
6
+ export interface NameCatalog {
7
+ piProviders: ReadonlySet<string>;
8
+ /** `provider/model` pairs from the static catalog. */
9
+ piModels: ReadonlySet<string>;
10
+ /** Every model id in the static catalog, any provider (gateway-routed Claude Code). */
11
+ modelIds: ReadonlySet<string>;
12
+ /** User-defined PI providers (models.json) → their API kind. */
13
+ customProviders: ReadonlyMap<string, string>;
14
+ }
15
+ /** A public name made to fit the wire identifier shape. */
16
+ export declare function toIdent(name: string): string;
17
+ export declare function normalizeTool(name: string): string;
18
+ export interface NormalizedProvider {
19
+ provider: string;
20
+ customApi: string | null;
21
+ }
22
+ export declare function normalizeProvider(backend: 'claude' | 'pi', provider: string, catalog: NameCatalog): NormalizedProvider;
23
+ export declare function normalizeModel(backend: 'claude' | 'pi', provider: string, model: string, catalog: NameCatalog): string;
24
+ /** Heartbeat provider list: built-ins as-is, user-defined ones as `custom`, deduplicated. */
25
+ export declare function normalizeProviderList(providers: string[], catalog: NameCatalog): string[];
26
+ interface CatalogModel {
27
+ provider: string;
28
+ id: string;
29
+ }
30
+ export declare function buildNameCatalog(models: CatalogModel[], customProviders: Map<string, string>): NameCatalog;
31
+ /** Built once per UTC day, at the first upload that needs it; never on a turn's hot path. */
32
+ export declare function loadNameCatalog(day: string, modelsPath?: string): Promise<NameCatalog>;
33
+ export {};
@@ -0,0 +1,88 @@
1
+ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { ANTHROPIC_MODELS } from '../../core/anthropic-models.js';
5
+ import { loadPiSdk } from '../../core/pi-sdk.js';
6
+ import { readCustomProviderEntries, USER_PI_MODELS_PATH } from '../pi-providers/models-json-store.js';
7
+ import { TELEMETRY_CUSTOM, TELEMETRY_MCP_OTHER, TELEMETRY_OTHER } from './schema.js';
8
+ /** Built-in tool names of Claude Code and PI (plus the tools Cortex registers on PI). */
9
+ const BUILTIN_TOOLS = new Set([
10
+ 'Bash', 'Read', 'Write', 'Edit', 'MultiEdit', 'Grep', 'Glob', 'LS', 'WebFetch', 'WebSearch',
11
+ 'AskUserQuestion', 'EnterPlanMode', 'ExitPlanMode', 'TodoWrite', 'Skill', 'Agent', 'Task',
12
+ 'TaskOutput', 'TaskStop', 'NotebookEdit', 'NotebookRead', 'BashOutput', 'KillShell', 'KillBash',
13
+ 'SlashCommand', 'ToolSearch', 'ListMcpResourcesTool', 'ReadMcpResourceTool',
14
+ 'bash', 'read', 'write', 'edit', 'grep', 'glob', 'find', 'ls', 'powershell', 'web_fetch',
15
+ 'web_search', 'todo_write', 'skill', 'agent', 'agent_stop',
16
+ ]);
17
+ const NOT_IDENT_CHARS = /[^A-Za-z0-9._:/@[\]-]/g;
18
+ /** A public name made to fit the wire identifier shape. */
19
+ export function toIdent(name) {
20
+ return name.replace(NOT_IDENT_CHARS, '_').slice(0, 80) || TELEMETRY_OTHER;
21
+ }
22
+ export function normalizeTool(name) {
23
+ if (BUILTIN_TOOLS.has(name))
24
+ return name;
25
+ if (name.startsWith('mcp__cortex-'))
26
+ return toIdent(name);
27
+ return name.startsWith('mcp__') ? TELEMETRY_MCP_OTHER : TELEMETRY_OTHER;
28
+ }
29
+ export function normalizeProvider(backend, provider, catalog) {
30
+ if (backend === 'claude')
31
+ return { provider: 'anthropic', customApi: null };
32
+ if (catalog.customProviders.has(provider)) {
33
+ return { provider: TELEMETRY_CUSTOM, customApi: toIdent(catalog.customProviders.get(provider)) };
34
+ }
35
+ return { provider: catalog.piProviders.has(provider) ? provider : TELEMETRY_OTHER, customApi: null };
36
+ }
37
+ export function normalizeModel(backend, provider, model, catalog) {
38
+ if (backend === 'claude') {
39
+ const known = ANTHROPIC_MODELS.includes(model) || catalog.modelIds.has(model.replace(/\[1m\]$/, ''));
40
+ return known ? toIdent(model) : TELEMETRY_OTHER;
41
+ }
42
+ if (catalog.customProviders.has(provider))
43
+ return TELEMETRY_CUSTOM;
44
+ return catalog.piModels.has(`${provider}/${model}`) ? toIdent(model) : TELEMETRY_OTHER;
45
+ }
46
+ /** Heartbeat provider list: built-ins as-is, user-defined ones as `custom`, deduplicated. */
47
+ export function normalizeProviderList(providers, catalog) {
48
+ return [...new Set(providers.map((name) => normalizeProvider('pi', name, catalog).provider))];
49
+ }
50
+ function customProviderApis(modelsPath) {
51
+ const entries = readCustomProviderEntries(modelsPath);
52
+ return new Map(Object.entries(entries).map(([name, entry]) => [name, String(entry.api)]));
53
+ }
54
+ /** Read the SDK's bundled catalog without the user's auth, models.json or network. */
55
+ async function loadStaticModels() {
56
+ const dir = mkdtempSync(path.join(os.tmpdir(), 'cortex-telemetry-catalog-'));
57
+ try {
58
+ const authPath = path.join(dir, 'auth.json');
59
+ writeFileSync(authPath, '');
60
+ const sdk = await loadPiSdk();
61
+ const runtime = await sdk.ModelRuntime.create({
62
+ authPath, modelsPath: path.join(dir, 'absent', 'models.json'), allowModelNetwork: false,
63
+ });
64
+ return runtime.getAllModels().map((model) => ({ provider: String(model.provider), id: String(model.id) }));
65
+ }
66
+ finally {
67
+ rmSync(dir, { recursive: true, force: true });
68
+ }
69
+ }
70
+ export function buildNameCatalog(models, customProviders) {
71
+ return {
72
+ piProviders: new Set(models.map((model) => model.provider)),
73
+ piModels: new Set(models.map((model) => `${model.provider}/${model.id}`)),
74
+ modelIds: new Set(models.map((model) => model.id)),
75
+ customProviders,
76
+ };
77
+ }
78
+ let cached = null;
79
+ /** Built once per UTC day, at the first upload that needs it; never on a turn's hot path. */
80
+ export function loadNameCatalog(day, modelsPath = USER_PI_MODELS_PATH) {
81
+ if (cached?.day === day)
82
+ return cached.catalog;
83
+ const catalog = loadStaticModels()
84
+ .catch(() => [])
85
+ .then((models) => buildNameCatalog(models, customProviderApis(modelsPath)));
86
+ cached = { day, catalog };
87
+ return catalog;
88
+ }
@@ -0,0 +1,18 @@
1
+ import { type TelemetryEvent } from './schema.js';
2
+ /** The outbox never grows past this; the oldest lines go first. */
3
+ export declare const OUTBOX_MAX_BYTES: number;
4
+ /** Keep the newest lines that fit in `budget` bytes. */
5
+ export declare function newestWithin(lines: string[], budget: number): string[];
6
+ /**
7
+ * Append one event synchronously, so a process about to die still leaves it on disk. Invalid
8
+ * events are refused. Never throws.
9
+ */
10
+ export declare function appendToOutbox(event: TelemetryEvent, file?: string, maxBytes?: number): boolean;
11
+ /**
12
+ * Everything waiting to be sent, oldest first. New appends go to a fresh outbox file meanwhile
13
+ * (another process may append while an upload runs); `settleOutbox` writes back what is left.
14
+ */
15
+ export declare function takeOutbox(file?: string): TelemetryEvent[];
16
+ /** Record what an upload attempt could not deliver; an empty list clears the pending file. */
17
+ export declare function settleOutbox(unsent: TelemetryEvent[], file?: string): void;
18
+ export declare function wipeOutbox(file?: string): void;
@@ -0,0 +1,93 @@
1
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync, } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { OUTBOX_FILE } from './paths.js';
4
+ import { TelemetryEventSchema } from './schema.js';
5
+ /** The outbox never grows past this; the oldest lines go first. */
6
+ export const OUTBOX_MAX_BYTES = 2 * 1024 * 1024;
7
+ const TRIM_TARGET_BYTES = Math.floor(OUTBOX_MAX_BYTES * 0.75);
8
+ function sendingFile(file) {
9
+ return `${file.slice(0, -'.jsonl'.length)}.sending.jsonl`;
10
+ }
11
+ function readLines(file) {
12
+ try {
13
+ return readFileSync(file, 'utf8').split('\n').filter((line) => line.trim() !== '');
14
+ }
15
+ catch {
16
+ return [];
17
+ }
18
+ }
19
+ /** Keep the newest lines that fit in `budget` bytes. */
20
+ export function newestWithin(lines, budget) {
21
+ let used = 0;
22
+ let start = lines.length;
23
+ while (start > 0 && used + Buffer.byteLength(lines[start - 1]) + 1 <= budget) {
24
+ start -= 1;
25
+ used += Buffer.byteLength(lines[start]) + 1;
26
+ }
27
+ return lines.slice(start);
28
+ }
29
+ function writeLines(file, lines) {
30
+ if (lines.length === 0)
31
+ return void rmSync(file, { force: true });
32
+ writeFileSync(file, `${lines.join('\n')}\n`, 'utf8');
33
+ }
34
+ function enforceCap(file, maxBytes) {
35
+ if (statSync(file).size <= maxBytes)
36
+ return;
37
+ writeLines(file, newestWithin(readLines(file), Math.floor(maxBytes * 0.75)));
38
+ }
39
+ /**
40
+ * Append one event synchronously, so a process about to die still leaves it on disk. Invalid
41
+ * events are refused. Never throws.
42
+ */
43
+ export function appendToOutbox(event, file = OUTBOX_FILE, maxBytes = OUTBOX_MAX_BYTES) {
44
+ const parsed = TelemetryEventSchema.safeParse(event);
45
+ if (!parsed.success)
46
+ return false;
47
+ try {
48
+ mkdirSync(path.dirname(file), { recursive: true });
49
+ appendFileSync(file, `${JSON.stringify(parsed.data)}\n`, 'utf8');
50
+ enforceCap(file, maxBytes);
51
+ return true;
52
+ }
53
+ catch {
54
+ return false;
55
+ }
56
+ }
57
+ /**
58
+ * Everything waiting to be sent, oldest first. New appends go to a fresh outbox file meanwhile
59
+ * (another process may append while an upload runs); `settleOutbox` writes back what is left.
60
+ */
61
+ export function takeOutbox(file = OUTBOX_FILE) {
62
+ const sending = sendingFile(file);
63
+ if (existsSync(file)) {
64
+ const moved = `${file}.${process.pid}.tmp`;
65
+ try {
66
+ renameSync(file, moved);
67
+ writeLines(sending, newestWithin([...readLines(sending), ...readLines(moved)], TRIM_TARGET_BYTES));
68
+ rmSync(moved, { force: true });
69
+ }
70
+ catch { /* leave both files for the next attempt */ }
71
+ }
72
+ return readLines(sending).flatMap((line) => parseEvent(line));
73
+ }
74
+ function parseEvent(line) {
75
+ try {
76
+ const parsed = TelemetryEventSchema.safeParse(JSON.parse(line));
77
+ return parsed.success ? [parsed.data] : [];
78
+ }
79
+ catch {
80
+ return [];
81
+ }
82
+ }
83
+ /** Record what an upload attempt could not deliver; an empty list clears the pending file. */
84
+ export function settleOutbox(unsent, file = OUTBOX_FILE) {
85
+ try {
86
+ writeLines(sendingFile(file), unsent.map((event) => JSON.stringify(event)));
87
+ }
88
+ catch { /* retried next time */ }
89
+ }
90
+ export function wipeOutbox(file = OUTBOX_FILE) {
91
+ rmSync(file, { force: true });
92
+ rmSync(sendingFile(file), { force: true });
93
+ }
@@ -0,0 +1,4 @@
1
+ /** The reportable form of a panic location's file, or null when none can be derived safely. */
2
+ export declare function panicFile(raw: string): string | null;
3
+ /** `panic@<file>:<line>` from the panic message, else from the backtrace, else `panic@unknown`. */
4
+ export declare function panicGroupKey(message: string, stack: string): string;
@@ -0,0 +1,51 @@
1
+ // Group keys for native shell panics. The shell's panic hook formats its message as
2
+ // `<text> at <file>:<line>:<col>`; the file is relative for the shell's own crate (`src/setup.rs`) and
3
+ // absolute for dependencies and the standard library. Only the source-relative part is kept, so a
4
+ // key never carries a home directory, user name or checkout location.
5
+ const MESSAGE_LOCATION_RE = / at (\S+):(\d+):\d+\s*$/;
6
+ const FRAME_LOCATION_RE = /^\s*at (\S+):(\d+):\d+\s*$/;
7
+ const SAFE_SEGMENT_RE = /^[A-Za-z0-9._-]+$/;
8
+ /** A published crate directory in the cargo registry (`tauri-2.1.0`). */
9
+ const CRATE_DIR_RE = /^[A-Za-z0-9_-]+-\d+\.\d+\.\d+[A-Za-z0-9.+-]*$/;
10
+ /** A standard library crate under the toolchain's `library/` directory. */
11
+ const STD_CRATE_RE = /^(?:core|std|alloc|proc_macro|test)$/;
12
+ const MAX_FILE_LENGTH = 120;
13
+ function isRelative(file) {
14
+ return !/^(?:[A-Za-z]:\/|\/|~)/.test(file);
15
+ }
16
+ function safePath(file) {
17
+ const segments = file.split('/');
18
+ const safe = segments.every((segment) => SAFE_SEGMENT_RE.test(segment) && segment !== '..');
19
+ return safe && file.length <= MAX_FILE_LENGTH ? file : null;
20
+ }
21
+ /** `src/...` of an absolute path, prefixed with the crate directory when that is public. */
22
+ function sourceRelative(file) {
23
+ const at = file.lastIndexOf('/src/');
24
+ if (at < 0)
25
+ return null;
26
+ const parent = file.slice(0, at).split('/').pop() ?? '';
27
+ const publicCrate = CRATE_DIR_RE.test(parent) || (file.includes('/library/') && STD_CRATE_RE.test(parent));
28
+ return publicCrate ? `${parent}/${file.slice(at + 1)}` : file.slice(at + 1);
29
+ }
30
+ /** The reportable form of a panic location's file, or null when none can be derived safely. */
31
+ export function panicFile(raw) {
32
+ const file = raw.replace(/\\/g, '/').replace(/^\.\//, '');
33
+ return safePath(isRelative(file) ? file : sourceRelative(file) ?? '');
34
+ }
35
+ function locationKey(match) {
36
+ const file = match ? panicFile(match[1]) : null;
37
+ return file ? `panic@${file}:${match[2]}` : null;
38
+ }
39
+ /** First backtrace frame in the shell's own crate (a relative path); library frames come first. */
40
+ function ownFrameKey(stack) {
41
+ for (const line of stack.split('\n')) {
42
+ const match = FRAME_LOCATION_RE.exec(line);
43
+ if (match && isRelative(match[1].replace(/\\/g, '/')))
44
+ return locationKey(match);
45
+ }
46
+ return null;
47
+ }
48
+ /** `panic@<file>:<line>` from the panic message, else from the backtrace, else `panic@unknown`. */
49
+ export function panicGroupKey(message, stack) {
50
+ return locationKey(MESSAGE_LOCATION_RE.exec(message)) ?? ownFrameKey(stack) ?? 'panic@unknown';
51
+ }
@@ -0,0 +1,7 @@
1
+ /** Everything telemetry keeps on disk lives here; nothing outside it is written. */
2
+ export declare const TELEMETRY_DIR: string;
3
+ export declare const INSTALL_ID_FILE: string;
4
+ export declare const OUTBOX_FILE: string;
5
+ export declare const STATE_FILE: string;
6
+ export declare const ROLLUP_PREFIX = "rollup-";
7
+ export declare function rollupFile(day: string, dir?: string): string;
@@ -0,0 +1,11 @@
1
+ import path from 'node:path';
2
+ import { STORE_DIR } from '../../core/paths.js';
3
+ /** Everything telemetry keeps on disk lives here; nothing outside it is written. */
4
+ export const TELEMETRY_DIR = path.join(STORE_DIR, 'telemetry');
5
+ export const INSTALL_ID_FILE = path.join(TELEMETRY_DIR, 'install-id');
6
+ export const OUTBOX_FILE = path.join(TELEMETRY_DIR, 'outbox.jsonl');
7
+ export const STATE_FILE = path.join(TELEMETRY_DIR, 'state.json');
8
+ export const ROLLUP_PREFIX = 'rollup-';
9
+ export function rollupFile(day, dir = TELEMETRY_DIR) {
10
+ return path.join(dir, `${ROLLUP_PREFIX}${day}.json`);
11
+ }
@@ -0,0 +1,18 @@
1
+ /** What redaction must recognize on this machine. Injected in tests. */
2
+ export interface RedactionContext {
3
+ installRoot: string;
4
+ homeDir: string;
5
+ username: string;
6
+ hostname: string;
7
+ }
8
+ export declare const MAX_MESSAGE_CHARS = 300;
9
+ export declare const MAX_STACK_FRAMES = 30;
10
+ export declare const MAX_STACK_CHARS = 8000;
11
+ export declare function defaultRedactionContext(): RedactionContext;
12
+ /** Apply every rule. Order matters: Cortex's own paths become relative before any path is cut. */
13
+ export declare function redactText(text: string, ctx?: RedactionContext): string;
14
+ export declare function redactMessage(text: string, ctx?: RedactionContext): string;
15
+ /** Redacted stack: the header line plus at most 30 frames, within the size cap. */
16
+ export declare function redactStack(stack: string, ctx?: RedactionContext): string;
17
+ /** Grouping key: error name + the first frame in Cortex's own code (function and file). */
18
+ export declare function groupKeyOf(errorName: string, redactedStack: string): string;