@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
@@ -80,12 +80,12 @@ export function normalizeScheduleSpec(input) {
80
80
  ...timing,
81
81
  message: normalizeMessage(input.message),
82
82
  projectId: input.projectId?.trim() || 'general',
83
- profile: input.profile?.trim() || null,
83
+ selection: input.selection ? { ...input.selection } : undefined,
84
84
  ...(preCheck ? { preCheck } : {}),
85
85
  };
86
86
  }
87
87
  const BUILTIN_JOB_DISPATCH_TYPES = new Set(['memory-index-regen']);
88
- const COMMON_PATCH_FIELDS = ['message', 'projectId', 'profile', 'dispatchType', 'preCheck'];
88
+ const COMMON_PATCH_FIELDS = ['message', 'projectId', 'selection', 'dispatchType', 'preCheck'];
89
89
  export const TIMING_PATCH_FIELDS = {
90
90
  interval: ['intervalMs'],
91
91
  daily: ['time'],
@@ -157,10 +157,10 @@ export function retimeTask(task, now = Date.now()) {
157
157
  return;
158
158
  task.nextRun = task.isPaused ? null : now + nextFireDelayMs(task, now);
159
159
  }
160
- /** The persisted record for a new schedule. `profile` is already resolved by the caller. */
161
- export function buildScheduleTask(spec, id, now, profile) {
162
- const { message, projectId, preCheck, profile: _profile, ...timing } = spec;
163
- const base = { id, message, projectId, profile, preCheck, createdAt: now };
160
+ /** The persisted record for a new schedule. The caller has materialized its selection. */
161
+ export function buildScheduleTask(spec, id, now, selection) {
162
+ const { message, projectId, preCheck, selection: _selection, ...timing } = spec;
163
+ const base = { id, message, projectId, selection: { ...selection }, preCheck, createdAt: now };
164
164
  if (timing.type === 'once')
165
165
  return { ...base, type: 'once', runAt: now + timing.delayMs };
166
166
  const task = { ...base, ...timing, lastRun: null, nextRun: null };
@@ -1,12 +1,13 @@
1
1
  import { FSWatcher } from 'fs';
2
2
  import { ScheduleRepo, type ScheduleTask } from '../../store/schedule-repo.js';
3
3
  import { type ScheduleSpec, type SchedulePatch } from './schedule-spec.js';
4
+ import type { EngineSelection } from '../agents/engine-selection.js';
4
5
  export type { ScheduleTask } from '../../store/schedule-repo.js';
5
6
  interface RunnerParams {
6
7
  message: string;
7
8
  projectId: string;
8
9
  scheduleTaskId: string;
9
- profileName: string;
10
+ selection: EngineSelection;
10
11
  }
11
12
  interface ProgrammaticHandlerParams {
12
13
  channel: string;
@@ -69,5 +70,6 @@ declare class Scheduler {
69
70
  /** Run the task's preCheck shell gate. A failing check records the skip and returns false. */
70
71
  _passesPreCheck(task: ScheduleTask): Promise<boolean>;
71
72
  _runTask(task: ScheduleTask): Promise<void>;
73
+ _dispatchTask(task: ScheduleTask): Promise<void>;
72
74
  }
73
75
  export { Scheduler };
@@ -1,4 +1,5 @@
1
1
  import { watch } from 'fs';
2
+ import { countFeature, recordScheduleCreated } from '../telemetry/usage.js';
2
3
  import { runShell } from '../../core/exec-async.js';
3
4
  import { t } from '../../core/i18n.js';
4
5
  import { Icons } from '../../core/icons.js';
@@ -7,14 +8,15 @@ import { createLogger } from '../../core/log.js';
7
8
  import { emitCortexEvent } from '../../core/hook-bus.js';
8
9
  import { ScheduleRepo, scheduleRepo, SCHEDULES_FILE } from '../../store/schedule-repo.js';
9
10
  import { nextFireDelayMs } from './schedule-spec.js';
10
- import { addSchedule, pauseSchedule, resolveTaskProfile, resumeSchedule, updateSchedule } from './schedule-ops.js';
11
+ import { addSchedule, pauseSchedule, resumeSchedule, updateSchedule } from './schedule-ops.js';
12
+ import { getDefaultSelection } from '../agents/models.js';
11
13
  const log = createLogger('scheduler');
12
14
  // Hash the task fields that affect when and how it fires (not run timestamps)
13
15
  function taskConfigHash(task) {
14
16
  const keys = { interval: 'intervalMs', daily: 'time', once: 'runAt', weekly: 'dayOfWeek' };
15
17
  const key = keys[task.type];
16
18
  const extra = task.type === 'weekly' ? `${task.dayOfWeek}:${task.time}` : (String(task[key] || ''));
17
- return `${task.type}:${extra}:${task.message}:${task.projectId}:${task.profile || ''}:${task.dispatchType || ''}:${task.preCheck || ''}:${task.isPaused ? 'paused' : ''}`;
19
+ return `${task.type}:${extra}:${task.message}:${task.projectId}:${JSON.stringify(task.selection ?? null)}:${task.dispatchType || ''}:${task.preCheck || ''}:${task.isPaused ? 'paused' : ''}`;
18
20
  }
19
21
  // The daemon's live view of schedules.json. `cortex schedule` writes the file
20
22
  // directly through schedule-ops; the file watcher re-reads it
@@ -135,6 +137,8 @@ class Scheduler {
135
137
  this._scheduleTask(task);
136
138
  }
137
139
  this._reportReload(added, removed.length, updated);
140
+ // Tasks another process (the CLI) wrote; ones this scheduler added are already armed.
141
+ recordScheduleCreated(added);
138
142
  }
139
143
  _reportReload(added, removed, updated) {
140
144
  if (!added && !removed && !updated)
@@ -145,6 +149,7 @@ class Scheduler {
145
149
  async add(spec) {
146
150
  const { task } = await addSchedule(this._repo, spec);
147
151
  this._scheduleTask(task);
152
+ recordScheduleCreated();
148
153
  return task;
149
154
  }
150
155
  // Remove a task by id. Returns true if found and removed.
@@ -268,35 +273,40 @@ class Scheduler {
268
273
  }
269
274
  // Internal: invoke the runner for a task
270
275
  async _runTask(task) {
271
- const profileName = resolveTaskProfile(task.profile);
272
- const resolvedChannel = task.projectId;
273
- log.info(`Firing task ${task.id} (${task.type}, dispatch=${task.dispatchType || 'llm'}, profile=${profileName}, project=${task.projectId}): "${task.message}"`);
274
- void emitCortexEvent('cortex:schedule.fired', {
275
- scheduleId: task.id,
276
- name: task.message,
277
- project: task.projectId,
278
- }).catch(() => { });
276
+ log.info(`Firing task ${task.id} (${task.type}, dispatch=${task.dispatchType || 'llm'}, model=${task.selection?.model || 'default'}, project=${task.projectId}): "${task.message}"`);
279
277
  try {
280
- if (task.dispatchType) {
281
- const handler = this.programmaticHandlers[task.dispatchType];
282
- if (!handler) {
283
- log.warn(`Skipping task ${task.id}: unregistered dispatch type "${task.dispatchType}"`);
284
- return;
285
- }
286
- await handler({ channel: resolvedChannel, scheduleTaskId: task.id });
287
- }
288
- else {
289
- await this.runner({
290
- message: `[Scheduled Task] ${task.message}`,
291
- projectId: task.projectId,
292
- scheduleTaskId: task.id,
293
- profileName,
294
- });
295
- }
278
+ await this._dispatchTask(task);
296
279
  }
297
280
  catch (e) {
298
281
  log.error(`Task ${task.id} runner error:`, e.message);
299
282
  }
300
283
  }
284
+ async _dispatchTask(task) {
285
+ if (!task.dispatchType) {
286
+ emitScheduleFired(task);
287
+ await this.runner({
288
+ message: `[Scheduled Task] ${task.message}`,
289
+ projectId: task.projectId,
290
+ scheduleTaskId: task.id,
291
+ selection: task.selection ?? getDefaultSelection(),
292
+ });
293
+ return;
294
+ }
295
+ const handler = this.programmaticHandlers[task.dispatchType];
296
+ if (!handler) {
297
+ log.warn(`Skipping task ${task.id}: unregistered dispatch type "${task.dispatchType}"`);
298
+ return;
299
+ }
300
+ emitScheduleFired(task);
301
+ await handler({ channel: task.projectId, scheduleTaskId: task.id });
302
+ }
303
+ }
304
+ function emitScheduleFired(task) {
305
+ countFeature('schedule_fired');
306
+ void emitCortexEvent('cortex:schedule.fired', {
307
+ scheduleId: task.id,
308
+ name: task.id,
309
+ project: task.projectId,
310
+ }).catch(() => { });
301
311
  }
302
312
  export { Scheduler };
@@ -1,4 +1,5 @@
1
1
  import type { PlatformAdapter, OutputStream } from '../../platform/index.js';
2
+ import type { EngineSelection } from '../agents/engine-selection.js';
2
3
  import { startRun } from '../runs/service.js';
3
4
  import type { RunRequest } from '../runs/request.js';
4
5
  declare const SESSION_EVENTS: {
@@ -16,7 +17,7 @@ export interface SessionHookContext {
16
17
  /** The backend's own id for the session's conversation (its transcript), when it has one. */
17
18
  backendSessionId?: string | null;
18
19
  executionId?: string | null;
19
- profile?: string | null;
20
+ selection?: EngineSelection | null;
20
21
  }
21
22
  /** Caller-supplied formatters — keep wording per-hook so existing UX text doesn't change.
22
23
  * All formatters return short single-line strings; runSessionHook appends them via OutputStream,
@@ -40,7 +41,7 @@ export interface SessionHookInject {
40
41
  /** The backend conversation it resumes. Differs from `sessionId` once the backend has assigned
41
42
  * its own id (Slack, Feishu, the Web after a first turn) or a rewind has moved it. */
42
43
  backendSessionId: string;
43
- profileName: string | null;
44
+ selection: EngineSelection | null;
44
45
  /** Session-pool key for the injected turn.
45
46
  * - onNew: an ISOLATED key (onNewInjectSessionKey(channel)) so resuming the old session for
46
47
  * the pre-close turn never collides with the channel's live pool slot — see the race below.
@@ -102,7 +103,7 @@ export interface OnMessageEndArgs {
102
103
  /** The backend conversation the turn ran on; a follow-up turn resumes it. */
103
104
  backendSessionId: string | null;
104
105
  executionId: string;
105
- profile?: string | null;
106
+ selection?: EngineSelection | null;
106
107
  /** The finished turn's request; see {@link SessionHookInject.follows}. */
107
108
  request?: RunRequest | null;
108
109
  /** OutputStream to extend — pass the assistant turn's stream so the hook lines
@@ -115,7 +116,7 @@ export declare function runMessageEndSessionHook(args: OnMessageEndArgs): Promis
115
116
  /** Run the onMessageEnd hook for a turn that just finished. The hook's lines extend the assistant
116
117
  * turn's OutputStream, so hook output (status / preview / error) and any injected agent turn share
117
118
  * one continuous thread with the reply we just finished — no top-level leak, no detached stream.
118
- * The profile comes from the turn's conversation record, never from a global. */
119
+ * The selection comes from the turn's conversation record, never from a global. */
119
120
  export declare function runMessageEndForTurn(args: {
120
121
  channel: string;
121
122
  /** The Cortex session id (the registry key), not the backend's. */
@@ -2,8 +2,7 @@ import { randomUUID } from 'node:crypto';
2
2
  import { emitCortexEvent } from '../../core/hook-bus.js';
3
3
  import { createLogger } from '../../core/log.js';
4
4
  import { Icons } from '../../core/icons.js';
5
- import { resolveBackendForChannel } from '../agents/index.js';
6
- import { resolveProfileConfig } from '../agents/profile-manager.js';
5
+ import { resolveRunSelection } from '../runs/config-resolver.js';
7
6
  import { startRun } from '../runs/service.js';
8
7
  import { continuationRunRequest } from '../runs/builders.js';
9
8
  import { engines } from '../runs/engines.js';
@@ -42,20 +41,6 @@ export function isOnMessageEndHookConfigured() {
42
41
  export function onNewInjectSessionKey(channel) {
43
42
  return `${channel}::onnew-hook`;
44
43
  }
45
- /** Synthetic profile for an unknown/missing configured name: keeps the requested name so the
46
- * run still rejects it, while its backend mirrors the channel's live session. */
47
- function hookInjectionProfile(profileName, channel) {
48
- try {
49
- return resolveProfileConfig(profileName);
50
- }
51
- catch {
52
- return {
53
- name: profileName ?? '', model: '', backend: resolveBackendForChannel(channel), mode: null,
54
- provider: null, extraEnv: {}, extraOption: {}, thinking: null,
55
- maxOutputTokens: null, fallback: [],
56
- };
57
- }
58
- }
59
44
  const defaultInjectDeps = {
60
45
  startRun,
61
46
  closeInjectedSession: async (channel, sessionKey) => {
@@ -67,7 +52,7 @@ const defaultInjectDeps = {
67
52
  }
68
53
  },
69
54
  };
70
- /** The next turn on the engine `after` ran on: same session, agent, profile, policy and route —
55
+ /** The next turn on the engine `after` ran on: same session, agent, selection, policy and route —
71
56
  * the route keeps `after`'s trigger, since the gateway URL names it and the process was spawned on
72
57
  * it; the follow-up's own trigger is what its execution and cost are recorded under. */
73
58
  function followUpRequest(after, next) {
@@ -105,7 +90,7 @@ export async function runHookInjection(output, spec, stream, deps = defaultInjec
105
90
  // session id.
106
91
  engineKey: inject.sessionKey,
107
92
  },
108
- profile: hookInjectionProfile(inject.profileName, spec.ctx.channel),
93
+ selection: resolveRunSelection({ selection: inject.selection, channel: spec.ctx.channel }),
109
94
  prompt: output,
110
95
  channel: spec.ctx.channel,
111
96
  project: 'general',
@@ -151,7 +136,8 @@ function buildHookPayload(name, ctx) {
151
136
  sessionId: ctx.sessionId,
152
137
  backendSessionId: ctx.backendSessionId ?? null,
153
138
  executionId: ctx.executionId ?? null,
154
- profile: ctx.profile ?? null,
139
+ backend: ctx.selection?.backend ?? null,
140
+ model: ctx.selection?.model ?? null,
155
141
  trigger: name === 'onNew' ? 'new' : 'messageEnd',
156
142
  timestampIso: new Date().toISOString(),
157
143
  };
@@ -252,29 +238,25 @@ export async function resolveOnNewThreadAnchor(channel, threadAnchorId) {
252
238
  }
253
239
  return null;
254
240
  }
255
- /** What a session hook reads about its session, from the registry, keyed by the Cortex session id.
256
- * The registry is the SINGLE source of truth for the profile (B.T2): the per-session record is
257
- * right for every kind of session, where the old channel-level ledger fallback could name another
258
- * session on the same channel and resume with the wrong profile (wrong gateway mode → Anthropic
259
- * 400 on thinking blocks). */
241
+ /** Read the engine choice from the session record, never another session's channel state. */
260
242
  async function sessionHookTarget(sessionId) {
261
243
  const record = await sessionStore.getById(sessionId);
262
244
  return {
263
- profile: record?.profileName ?? null,
245
+ selection: record?.selection ?? null,
264
246
  backendSessionId: record ? effectiveBackendSessionId(record) : null,
265
247
  };
266
248
  }
267
249
  function onNewHookSpec(channel, sessionId, target) {
268
- const { profile, backendSessionId } = target;
250
+ const { selection, backendSessionId } = target;
269
251
  return {
270
252
  name: 'onNew',
271
- ctx: { channel, sessionId, profile, backendSessionId },
253
+ ctx: { channel, sessionId, selection, backendSessionId },
272
254
  format: ONNEW_FORMAT,
273
255
  // A session with no backend conversation yet has nothing for a pre-close turn to continue.
274
256
  inject: backendSessionId ? {
275
257
  sessionId,
276
258
  backendSessionId,
277
- profileName: profile,
259
+ selection,
278
260
  sessionKey: onNewInjectSessionKey(channel),
279
261
  trigger: 'hook:onNew',
280
262
  } : null,
@@ -319,13 +301,13 @@ export async function runMessageEndSessionHook(args) {
319
301
  sessionId: args.sessionId,
320
302
  backendSessionId: args.backendSessionId,
321
303
  executionId: args.executionId,
322
- profile: args.profile ?? null,
304
+ selection: args.selection ?? null,
323
305
  },
324
306
  format: ONMESSAGEEND_FORMAT,
325
307
  inject: args.backendSessionId ? {
326
308
  sessionId: args.sessionId,
327
309
  backendSessionId: args.backendSessionId,
328
- profileName: args.profile ?? null,
310
+ selection: args.selection ?? null,
329
311
  // onMessageEnd continues the live conversation — keep it on the channel pool slot.
330
312
  sessionKey: args.channel,
331
313
  trigger: 'hook:onMessageEnd',
@@ -337,7 +319,7 @@ export async function runMessageEndSessionHook(args) {
337
319
  /** Run the onMessageEnd hook for a turn that just finished. The hook's lines extend the assistant
338
320
  * turn's OutputStream, so hook output (status / preview / error) and any injected agent turn share
339
321
  * one continuous thread with the reply we just finished — no top-level leak, no detached stream.
340
- * The profile comes from the turn's conversation record, never from a global. */
322
+ * The selection comes from the turn's conversation record, never from a global. */
341
323
  export async function runMessageEndForTurn(args) {
342
324
  if (!isOnMessageEndHookConfigured() || !args.sessionId)
343
325
  return;
@@ -346,7 +328,7 @@ export async function runMessageEndForTurn(args) {
346
328
  return;
347
329
  }
348
330
  try {
349
- // Profile comes from the session registry (the single source of truth), keyed by the turn's
331
+ // Selection comes from the session registry (the single source of truth), keyed by the turn's
350
332
  // sessionId — never from the channel-level ledger, which could name a different session.
351
333
  const target = await sessionHookTarget(args.sessionId);
352
334
  await runMessageEndSessionHook({
@@ -354,7 +336,7 @@ export async function runMessageEndForTurn(args) {
354
336
  sessionId: args.sessionId,
355
337
  backendSessionId: args.backendSessionId ?? target.backendSessionId,
356
338
  executionId: args.executionId ?? '',
357
- profile: target.profile,
339
+ selection: target.selection,
358
340
  stream: args.stream,
359
341
  request: args.request,
360
342
  });
@@ -1,5 +1,5 @@
1
+ import type { EngineSelection } from '../agents/engine-selection.js';
1
2
  import type { SessionOrigin } from '../../store/session-registry-repo.js';
2
- import type { SessionBrowserOption } from '../../store/session-registry-journal.js';
3
3
  export interface SessionRegistryWriter {
4
4
  registerSession(opts: {
5
5
  sessionId: string;
@@ -9,9 +9,8 @@ export interface SessionRegistryWriter {
9
9
  origin?: SessionOrigin;
10
10
  projectId: string;
11
11
  label?: string | null;
12
- profileName?: string | null;
12
+ selection?: EngineSelection | null;
13
13
  agentName?: string | null;
14
- browser?: SessionBrowserOption | null;
15
14
  boardId?: string | null;
16
15
  teamLeadId?: string | null;
17
16
  workerName?: string | null;
@@ -25,99 +24,68 @@ export interface RegisterSessionRecordOpts {
25
24
  backend: string;
26
25
  projectId: string;
27
26
  label?: string | null;
28
- profileName?: string | null;
29
- /** The agent template the session runs as; null/absent means it follows the channel's selection
30
- * and, beneath that, the global default. */
27
+ selection?: EngineSelection | null;
28
+ /** The agent template; absent means the channel/global default. */
31
29
  agentName?: string | null;
32
- /** Opt-in browser access for this session; null/absent means no browser tools at all. */
33
- browser?: SessionBrowserOption | null;
34
- /** The board a new session starts bound to (a worker inherits its lead's). */
35
30
  boardId?: string | null;
36
- /** Team mode: the owning lead's sessionId, this worker's name and its brief. Absent for ordinary
37
- * sessions. */
38
31
  teamLeadId?: string | null;
39
32
  workerName?: string | null;
40
33
  workerBrief?: string | null;
41
- /** The schedule whose fire opened this session. Present, the session is that schedule's run
42
- * (kind and origin 'scheduled') until a reply adopts it as an ordinary direct session. */
34
+ /** Provenance retained when the user adopts a scheduled session. */
43
35
  scheduleId?: string | null;
44
36
  }
45
- /** Register a session by its stable ID. */
37
+ /** Register a session by its stable ID, freezing the engine choice for future resumes. */
46
38
  export declare function registerSessionRecord(store: SessionRegistryWriter, opts: RegisterSessionRecordOpts): Promise<void>;
47
39
  export interface CreateDirectSessionDeps {
48
40
  sessionStore: SessionRegistryWriter;
49
- /** Bind the channel to the new session in the registry (so a later send resumes it). */
50
41
  setChannelSession(channel: string, sessionId: string): Promise<void>;
51
- /** Initialize the conversation ledger for the new channel/session. */
52
42
  initConversation(channel: string, opts: {
53
43
  sessionId: string;
54
44
  backend: string;
45
+ selection: EngineSelection;
55
46
  }): Promise<void>;
56
- /** Resolve the backend the send path will use for the channel (agent-runner reads the same). */
57
47
  resolveBackend(channel: string): string;
58
48
  }
59
- /** Create a fresh, live session for a web/UI conversation: mint a sessionId, derive its own
60
- * `web:<sessionId>` conduit channel, register by ID, bind the channel→session mapping
61
- * and conversation ledger. Returns the sessionId + channel. The session is
62
- * user-initiated (origin='direct') unless `scheduleId` names the schedule whose fire opened it.
63
- *
64
- * When `profileName` is provided, the backend is resolved directly from the profile config (not
65
- * from the channel's profile state) so the session is bound to the correct backend even before any
66
- * channel profile is set. The channel profile is then set so subsequent sends resolve correctly.
67
- *
68
- * Because the channel is bound with the same backend the send path resolves, a subsequent send
69
- * resumes THIS session rather than spawning a new one. */
70
- export declare function createDirectSession(deps: CreateDirectSessionDeps, opts: {
49
+ interface CreateDirectSessionOpts {
71
50
  projectId: string;
72
51
  sessionId?: string;
73
- profileName?: string | null;
74
52
  agentName?: string | null;
75
- selection?: {
76
- model?: string;
77
- provider?: string;
78
- thinking?: string;
79
- mode?: string;
80
- } | null;
81
- browser?: SessionBrowserOption | null;
53
+ selection?: EngineSelection | null;
54
+ seedDefault?: boolean;
82
55
  boardId?: string | null;
83
56
  teamLeadId?: string | null;
84
57
  workerName?: string | null;
85
58
  workerBrief?: string | null;
86
59
  label?: string | null;
87
60
  scheduleId?: string | null;
88
- }): Promise<{
61
+ }
62
+ /** Mint a session and bind its conduit, registry and ledger to one materialized engine choice. */
63
+ export declare function createDirectSession(deps: CreateDirectSessionDeps, opts: CreateDirectSessionOpts): Promise<{
89
64
  sessionId: string;
90
65
  channel: string;
91
66
  }>;
92
67
  export interface AttachExistingSessionOpts {
93
68
  sessionId: string;
94
69
  backend: string;
95
- profileName?: string | null;
70
+ selection?: EngineSelection | null;
96
71
  }
97
- /** Attach a channel to an existing session: restore its profile (if any), bind the channel to it in
98
- * the registry, and switch the conversation ledger. Mirrors the !resume switch sequence. */
72
+ /** Resume restores the record verbatim, not the last choice of the channel it replaces. */
99
73
  export declare function attachExistingSession(channel: string, opts: AttachExistingSessionOpts): Promise<void>;
100
74
  export interface AdoptScheduledSessionStore {
101
75
  getById(sessionId: string): Promise<{
102
76
  channel: string;
103
77
  backend: string;
104
78
  origin: SessionOrigin;
105
- profileName: string | null;
79
+ selection: EngineSelection | null;
106
80
  } | null>;
107
- /** Re-point the registry record: channel → the adopted channel, kind → local, origin → direct. */
108
81
  convertToDirect(sessionId: string, opts: {
109
82
  channel: string;
110
83
  }): Promise<unknown | null>;
111
84
  }
112
- /** Convert a scheduled run's session into a normal direct web session (replying adopts the run).
113
- * A run opened on its own `web:<sessionId>` conduit is already bound there and only needs its record
114
- * re-pointed; an older run that lived on the shared project channel first gets that conduit attached
115
- * — the same switch sequence as !resume, so a later send resumes the run's transcript. `scheduleId`
116
- * is intentionally KEPT on the record (provenance for the trigger card / schedule grouping).
117
- * Idempotent: a non-scheduled record just returns its current channel; an unknown id returns null. */
85
+ /** Re-home older shared-channel scheduled runs; preserve provenance and engine selection. */
118
86
  export declare function adoptScheduledSession(store: AdoptScheduledSessionStore, sessionId: string): Promise<{
119
87
  channel: string;
120
88
  } | null>;
121
- /** Clear a channel's session state: unbind the channel in the registry, clean session
122
- * backups, and clear the conversation ledger. Mirrors the store-level half of !new. */
89
+ /** Clear the channel's binding, backups and conversation ledger. */
123
90
  export declare function resetChannelSession(channel: string): Promise<void>;
91
+ export {};
@@ -1,120 +1,61 @@
1
1
  import * as crypto from 'node:crypto';
2
2
  import { setSessionAsync, deleteSessionAsync } from './session.js';
3
3
  import { conversationLedger } from '../../store/conversation-ledger-repo.js';
4
- import { applyChannelSelection, setActiveProfile, setDefaultAgent, setSelectionDefaultAgent, } from '../agents/index.js';
5
- import { resolveProfileConfig } from '../agents/profile-manager.js';
4
+ import { applyChannelSelection } from '../agents/model-selection.js';
5
+ import { setChannelSelection, setDefaultAgent, setSelectionDefaultAgent } from '../agents/config.js';
6
+ import { resolveRunSelection } from '../runs/config-resolver.js';
6
7
  import * as sessionBackup from './session-backup.js';
7
- /** Register a session by its stable ID. */
8
+ /** Register a session by its stable ID, freezing the engine choice for future resumes. */
8
9
  export async function registerSessionRecord(store, opts) {
9
- // Every caller path but a schedule's fire (inbound direct message, TUI and web fresh sessions,
10
- // team workers) is user-initiated.
11
10
  const scheduled = !!opts.scheduleId;
11
+ const selection = resolveRunSelection({ channel: opts.channel, selection: opts.selection });
12
12
  await store.registerSession({
13
- sessionId: opts.sessionId,
14
- channel: opts.channel,
15
- backend: opts.backend,
16
- kind: scheduled ? 'scheduled' : 'local',
17
- origin: scheduled ? 'scheduled' : 'direct',
18
- projectId: opts.projectId,
19
- label: opts.label ?? null,
20
- profileName: opts.profileName ?? null,
21
- agentName: opts.agentName ?? null,
22
- browser: opts.browser ?? null,
23
- boardId: opts.boardId ?? null,
13
+ sessionId: opts.sessionId, channel: opts.channel, backend: selection.backend,
14
+ kind: scheduled ? 'scheduled' : 'local', origin: scheduled ? 'scheduled' : 'direct',
15
+ projectId: opts.projectId, label: opts.label ?? null, selection,
16
+ agentName: opts.agentName ?? null, boardId: opts.boardId ?? null,
24
17
  ...(opts.teamLeadId
25
18
  ? { teamLeadId: opts.teamLeadId, workerName: opts.workerName ?? null, workerBrief: opts.workerBrief ?? null }
26
19
  : {}),
27
20
  ...(scheduled ? { scheduleId: opts.scheduleId } : {}),
28
21
  });
29
22
  }
30
- /** Create a fresh, live session for a web/UI conversation: mint a sessionId, derive its own
31
- * `web:<sessionId>` conduit channel, register by ID, bind the channel→session mapping
32
- * and conversation ledger. Returns the sessionId + channel. The session is
33
- * user-initiated (origin='direct') unless `scheduleId` names the schedule whose fire opened it.
34
- *
35
- * When `profileName` is provided, the backend is resolved directly from the profile config (not
36
- * from the channel's profile state) so the session is bound to the correct backend even before any
37
- * channel profile is set. The channel profile is then set so subsequent sends resolve correctly.
38
- *
39
- * Because the channel is bound with the same backend the send path resolves, a subsequent send
40
- * resumes THIS session rather than spawning a new one. */
41
- export async function createDirectSession(deps, opts) {
42
- const sessionId = opts.sessionId ?? crypto.randomUUID();
43
- const channel = `web:${sessionId}`;
44
- let backend;
45
- if (opts.profileName) {
46
- backend = resolveProfileConfig(opts.profileName).backend;
47
- setActiveProfile(opts.profileName, channel);
48
- }
49
- else {
50
- backend = deps.resolveBackend(channel);
51
- }
52
- // The draft composer's choice, carried onto the new channel before the first turn is routed —
53
- // through the SAME rule the picker writes with, not a direct state write. A draft has no history
54
- // to protect, but it can still name a level the backend does not take or a provider on a claude
55
- // profile: without the rule those land unchecked and the first turn dies at the CLI. The channel
56
- // is minted here, so the cross-backend guard has nothing to refuse.
57
- //
58
- // An EMPTY selection is a statement too — "run this profile as declared" — and it has to reach
59
- // the rule, because the rule is also what re-seeds `selectionDefault` (what the NEXT new
60
- // conversation opens on). Skipping it left a draft that had just been cleared back to its profile
61
- // re-opening the next one on the model it had dropped, however many times it was taken back.
62
- // `null`/`undefined` is the other thing entirely: a caller with no composer behind it
63
- // (sessions.create, an issue's session) states nothing and must not move the seed.
64
- if (opts.selection) {
65
- await applyChannelSelection({
66
- channel,
67
- model: opts.selection.model ?? null,
68
- provider: opts.selection.provider ?? null,
69
- thinking: opts.selection.thinking ?? null,
70
- mode: opts.selection.mode ?? null,
71
- });
72
- }
73
- // The environment the session opens in, written to the channel BEFORE the first turn is routed
74
- // (the run path resolves the agent per turn from the session record, then this map). No switch
75
- // rule is needed: a channel minted here has no history, so the cross-backend guard the rule
76
- // exists for has nothing to refuse.
23
+ /** A draft's explicit selection goes through the picker rule before the channel is bound. */
24
+ async function initializeSelection(channel, opts) {
25
+ const selection = resolveRunSelection({ channel, selection: opts.selection });
26
+ const seedDefault = opts.seedDefault ?? !!opts.selection;
27
+ const applied = await applyChannelSelection({ channel, ...selection, seedDefault });
28
+ if (!applied.ok)
29
+ throw new Error(applied.reason ?? 'Invalid engine selection');
77
30
  if (opts.agentName)
78
31
  setDefaultAgent(opts.agentName, channel);
79
- // Seeded on the same condition as the selection above: `selection` present is what marks a
80
- // composer behind this call, and a composer that named no agent stated the default.
81
- if (opts.selection)
32
+ if (seedDefault)
82
33
  setSelectionDefaultAgent(opts.agentName ?? null);
34
+ return selection;
35
+ }
36
+ /** Mint a session and bind its conduit, registry and ledger to one materialized engine choice. */
37
+ export async function createDirectSession(deps, opts) {
38
+ const sessionId = opts.sessionId ?? crypto.randomUUID();
39
+ const channel = `web:${sessionId}`;
40
+ const selection = await initializeSelection(channel, opts);
83
41
  await registerSessionRecord(deps.sessionStore, {
84
- sessionId,
85
- channel,
86
- backend,
87
- projectId: opts.projectId,
88
- label: opts.label ?? null,
89
- profileName: opts.profileName ?? null,
90
- agentName: opts.agentName ?? null,
91
- browser: opts.browser ?? null,
92
- boardId: opts.boardId ?? null,
93
- teamLeadId: opts.teamLeadId ?? null,
94
- workerName: opts.workerName ?? null,
95
- workerBrief: opts.workerBrief ?? null,
96
- scheduleId: opts.scheduleId ?? null,
42
+ ...opts, sessionId, channel, backend: selection.backend, selection,
97
43
  });
98
44
  await deps.setChannelSession(channel, sessionId);
99
- await deps.initConversation(channel, { sessionId, backend });
45
+ await deps.initConversation(channel, { sessionId, backend: selection.backend, selection });
100
46
  return { sessionId, channel };
101
47
  }
102
- /** Attach a channel to an existing session: restore its profile (if any), bind the channel to it in
103
- * the registry, and switch the conversation ledger. Mirrors the !resume switch sequence. */
48
+ /** Resume restores the record verbatim, not the last choice of the channel it replaces. */
104
49
  export async function attachExistingSession(channel, opts) {
105
- if (opts.profileName)
106
- setActiveProfile(opts.profileName, channel);
50
+ const selection = resolveRunSelection({ channel, selection: opts.selection });
51
+ // This restores another session rather than switching the engine of the current session.
52
+ setChannelSelection(channel, selection);
107
53
  await setSessionAsync(channel, opts.sessionId);
108
54
  await conversationLedger.switchSession(channel, {
109
- sessionId: opts.sessionId, backend: opts.backend, profileName: opts.profileName,
55
+ sessionId: opts.sessionId, backend: selection.backend, selection,
110
56
  });
111
57
  }
112
- /** Convert a scheduled run's session into a normal direct web session (replying adopts the run).
113
- * A run opened on its own `web:<sessionId>` conduit is already bound there and only needs its record
114
- * re-pointed; an older run that lived on the shared project channel first gets that conduit attached
115
- * — the same switch sequence as !resume, so a later send resumes the run's transcript. `scheduleId`
116
- * is intentionally KEPT on the record (provenance for the trigger card / schedule grouping).
117
- * Idempotent: a non-scheduled record just returns its current channel; an unknown id returns null. */
58
+ /** Re-home older shared-channel scheduled runs; preserve provenance and engine selection. */
118
59
  export async function adoptScheduledSession(store, sessionId) {
119
60
  const record = await store.getById(sessionId);
120
61
  if (!record)
@@ -122,23 +63,20 @@ export async function adoptScheduledSession(store, sessionId) {
122
63
  if (record.origin !== 'scheduled')
123
64
  return { channel: record.channel };
124
65
  const channel = `web:${sessionId}`;
125
- // Re-attaching the conduit it already runs on would switch the ledger under a turn that may be live.
126
66
  if (record.channel !== channel) {
127
67
  await attachExistingSession(channel, {
128
- sessionId, backend: record.backend, profileName: record.profileName,
68
+ sessionId, backend: record.backend, selection: record.selection,
129
69
  });
130
70
  }
131
71
  await store.convertToDirect(sessionId, { channel });
132
72
  return { channel };
133
73
  }
134
- /** Clear a channel's session state: unbind the channel in the registry, clean session
135
- * backups, and clear the conversation ledger. Mirrors the store-level half of !new. */
74
+ /** Clear the channel's binding, backups and conversation ledger. */
136
75
  export async function resetChannelSession(channel) {
137
76
  const conv = await conversationLedger.getConversation(channel);
138
77
  if (conv) {
139
78
  sessionBackup.cleanupAllBackups(conv.sessionId);
140
79
  await conversationLedger.clearConversation(channel);
141
80
  }
142
- // One channel, one binding: `deleteSessionAsync` unbinds the channel in the registry.
143
81
  await deleteSessionAsync(channel).catch(() => { });
144
82
  }