@cortex-agent/server 2026.10.15 → 2026.10.21

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 (333) hide show
  1. package/README.md +76 -50
  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/plugins/cortex-board/skills/board/SKILL.md +30 -22
  7. package/defaults/plugins/cortex-system/plugin.json +2 -2
  8. package/defaults/plugins/cortex-system/skills/browser/SKILL.md +56 -0
  9. package/dist/agent-adapter/claude/adapter.d.ts +2 -5
  10. package/dist/agent-adapter/claude/adapter.js +6 -5
  11. package/dist/agent-adapter/claude/assistant-blocks.d.ts +5 -0
  12. package/dist/agent-adapter/claude/assistant-blocks.js +61 -0
  13. package/dist/agent-adapter/claude/cache-refresh.d.ts +58 -0
  14. package/dist/agent-adapter/claude/cache-refresh.js +145 -0
  15. package/dist/agent-adapter/claude/cache-touch.d.ts +12 -0
  16. package/dist/agent-adapter/claude/cache-touch.js +75 -0
  17. package/dist/agent-adapter/claude/event-parser.d.ts +8 -3
  18. package/dist/agent-adapter/claude/event-parser.js +33 -17
  19. package/dist/agent-adapter/claude/event-translator.d.ts +2 -0
  20. package/dist/agent-adapter/claude/event-translator.js +2 -0
  21. package/dist/agent-adapter/claude/session-options.d.ts +6 -13
  22. package/dist/agent-adapter/claude/session-options.js +2 -13
  23. package/dist/agent-adapter/claude/spawn-args.d.ts +4 -21
  24. package/dist/agent-adapter/claude/spawn-args.js +17 -24
  25. package/dist/agent-adapter/claude/transcript-clear.d.ts +42 -0
  26. package/dist/agent-adapter/claude/transcript-clear.js +217 -0
  27. package/dist/agent-adapter/claude/turn-machine.d.ts +3 -2
  28. package/dist/agent-adapter/claude/turn-machine.js +21 -68
  29. package/dist/agent-adapter/claude/window-warmup.d.ts +13 -0
  30. package/dist/agent-adapter/claude/window-warmup.js +38 -0
  31. package/dist/agent-adapter/continuation-phase.js +3 -0
  32. package/dist/agent-adapter/normalize/event-types.d.ts +8 -0
  33. package/dist/agent-adapter/pi/adapter.d.ts +0 -1
  34. package/dist/agent-adapter/pi/adapter.js +5 -13
  35. package/dist/agent-adapter/pi/event-parser.d.ts +1 -1
  36. package/dist/agent-adapter/pi/event-parser.js +43 -27
  37. package/dist/agent-adapter/pi/mcp-bridge.d.ts +1 -1
  38. package/dist/agent-adapter/pi/pi-session.d.ts +2 -0
  39. package/dist/agent-adapter/pi/pi-session.js +15 -0
  40. package/dist/agent-adapter/pi/providers-config.d.ts +2 -2
  41. package/dist/agent-adapter/pi/providers-config.js +1 -1
  42. package/dist/agent-adapter/pi/quota-sink.d.ts +3 -3
  43. package/dist/agent-adapter/pi/quota-sink.js +3 -3
  44. package/dist/agent-adapter/pi/runtime.js +6 -1
  45. package/dist/agent-adapter/pi/session-options.d.ts +9 -13
  46. package/dist/agent-adapter/pi/session-options.js +12 -25
  47. package/dist/agent-adapter/run-events.d.ts +11 -10
  48. package/dist/agent-adapter/run-events.js +2 -0
  49. package/dist/agent-adapter/types.d.ts +5 -4
  50. package/dist/client-bundle/manifest.json +2 -2
  51. package/dist/core/codex-quota.d.ts +1 -1
  52. package/dist/core/codex-quota.js +1 -1
  53. package/dist/core/gateway-generator.d.ts +9 -11
  54. package/dist/core/gateway-generator.js +31 -58
  55. package/dist/core/locales/en.d.ts +51 -77
  56. package/dist/core/locales/slices/commands.d.ts +26 -31
  57. package/dist/core/locales/slices/commands.js +54 -64
  58. package/dist/core/locales/slices/init.d.ts +8 -19
  59. package/dist/core/locales/slices/init.js +17 -53
  60. package/dist/core/locales/slices/interactions.d.ts +3 -3
  61. package/dist/core/locales/slices/interactions.js +6 -6
  62. package/dist/core/locales/slices/notices.d.ts +1 -3
  63. package/dist/core/locales/slices/notices.js +2 -6
  64. package/dist/core/locales/slices/scheduling.d.ts +9 -9
  65. package/dist/core/locales/slices/scheduling.js +18 -18
  66. package/dist/core/locales/slices/status.d.ts +0 -4
  67. package/dist/core/locales/slices/status.js +0 -8
  68. package/dist/core/locales/slices/tui.d.ts +0 -1
  69. package/dist/core/locales/slices/tui.js +0 -2
  70. package/dist/core/locales/slices/uimsg.d.ts +4 -7
  71. package/dist/core/locales/slices/uimsg.js +9 -15
  72. package/dist/core/models-generator.d.ts +29 -0
  73. package/dist/core/models-generator.js +82 -0
  74. package/dist/core/paths.d.ts +1 -1
  75. package/dist/core/paths.js +1 -1
  76. package/dist/core/settings-spec.d.ts +25 -0
  77. package/dist/core/settings-spec.js +34 -0
  78. package/dist/core/status-format.d.ts +3 -2
  79. package/dist/core/status-format.js +2 -2
  80. package/dist/core/types/environment-types.d.ts +0 -2
  81. package/dist/domain/agents/agent-state.d.ts +11 -56
  82. package/dist/domain/agents/agent-state.js +48 -115
  83. package/dist/domain/agents/agent-switch.d.ts +2 -24
  84. package/dist/domain/agents/agent-switch.js +9 -72
  85. package/dist/domain/agents/config.d.ts +11 -61
  86. package/dist/domain/agents/config.js +47 -154
  87. package/dist/domain/agents/engine-selection.d.ts +21 -0
  88. package/dist/domain/agents/engine-selection.js +37 -0
  89. package/dist/domain/agents/environments/registry.js +2 -1
  90. package/dist/domain/agents/environments/resolve.js +0 -1
  91. package/dist/domain/agents/environments/schema.d.ts +0 -1
  92. package/dist/domain/agents/environments/schema.js +0 -1
  93. package/dist/domain/agents/index.d.ts +2 -1
  94. package/dist/domain/agents/index.js +3 -7
  95. package/dist/domain/agents/model-selection.d.ts +18 -70
  96. package/dist/domain/agents/model-selection.js +100 -150
  97. package/dist/domain/agents/models.d.ts +12 -0
  98. package/dist/domain/agents/models.js +94 -0
  99. package/dist/domain/agents/subagent/registry.d.ts +2 -0
  100. package/dist/domain/agents/subagent/registry.js +8 -0
  101. package/dist/domain/agents/subagent/runner.d.ts +5 -5
  102. package/dist/domain/agents/subagent/runner.js +12 -35
  103. package/dist/domain/auth/auth-status.d.ts +4 -4
  104. package/dist/domain/auth/auth-status.js +17 -28
  105. package/dist/domain/auth/gateway-sync.d.ts +6 -26
  106. package/dist/domain/auth/gateway-sync.js +31 -75
  107. package/dist/domain/benchmark/identity.d.ts +3 -5
  108. package/dist/domain/benchmark/identity.js +0 -1
  109. package/dist/domain/benchmark/production-attempt-identity.d.ts +6 -5
  110. package/dist/domain/benchmark/production-attempt-identity.js +32 -35
  111. package/dist/domain/benchmark/session-evidence.d.ts +2 -1
  112. package/dist/domain/benchmark/session-evidence.js +8 -1
  113. package/dist/domain/browser/broker.d.ts +99 -0
  114. package/dist/domain/browser/broker.js +487 -0
  115. package/dist/domain/costs/claude-account.js +21 -0
  116. package/dist/domain/costs/rate-limit-throttle.js +3 -1
  117. package/dist/domain/costs/reset-account.d.ts +2 -0
  118. package/dist/domain/costs/usage-service.d.ts +1 -1
  119. package/dist/domain/costs/usage-service.js +20 -7
  120. package/dist/domain/mcp/tools/context.d.ts +5 -6
  121. package/dist/domain/mcp/tools/context.js +17 -3
  122. package/dist/domain/mcp/tools/subagent.js +1 -1
  123. package/dist/domain/mcp/tools/ui-file.js +1 -1
  124. package/dist/domain/pi-providers/custom-provider-model.d.ts +1 -1
  125. package/dist/domain/pi-providers/custom-provider-model.js +1 -1
  126. package/dist/domain/remote/device-browser.js +1 -1
  127. package/dist/domain/remote/device-chrome-commands.js +2 -0
  128. package/dist/domain/remote/device-port.js +2 -2
  129. package/dist/domain/runs/attempt.d.ts +3 -3
  130. package/dist/domain/runs/attempt.js +2 -3
  131. package/dist/domain/runs/builders.d.ts +4 -4
  132. package/dist/domain/runs/builders.js +4 -5
  133. package/dist/domain/runs/compact.d.ts +4 -17
  134. package/dist/domain/runs/compact.js +14 -56
  135. package/dist/domain/runs/config-resolver.d.ts +15 -83
  136. package/dist/domain/runs/config-resolver.js +24 -150
  137. package/dist/domain/runs/engine-spec.d.ts +8 -8
  138. package/dist/domain/runs/engine-spec.js +15 -31
  139. package/dist/domain/runs/events.d.ts +1 -1
  140. package/dist/domain/runs/fallback.d.ts +6 -38
  141. package/dist/domain/runs/fallback.js +10 -72
  142. package/dist/domain/runs/notices.d.ts +1 -11
  143. package/dist/domain/runs/notices.js +3 -30
  144. package/dist/domain/runs/request.d.ts +4 -3
  145. package/dist/domain/runs/retryable-errors.d.ts +0 -13
  146. package/dist/domain/runs/retryable-errors.js +0 -17
  147. package/dist/domain/runs/run.d.ts +12 -42
  148. package/dist/domain/runs/run.js +40 -147
  149. package/dist/domain/runs/service.d.ts +1 -1
  150. package/dist/domain/runs/service.js +8 -3
  151. package/dist/domain/runs/spec-loader.d.ts +1 -1
  152. package/dist/domain/runs/spend.d.ts +1 -1
  153. package/dist/domain/runs/spend.js +1 -1
  154. package/dist/domain/scheduling/jobs/scheduled-task.d.ts +3 -2
  155. package/dist/domain/scheduling/jobs/scheduled-task.js +25 -19
  156. package/dist/domain/scheduling/schedule-ops.d.ts +0 -1
  157. package/dist/domain/scheduling/schedule-ops.js +2 -5
  158. package/dist/domain/scheduling/schedule-selection.d.ts +3 -0
  159. package/dist/domain/scheduling/schedule-selection.js +16 -0
  160. package/dist/domain/scheduling/schedule-spec.d.ts +6 -5
  161. package/dist/domain/scheduling/schedule-spec.js +6 -6
  162. package/dist/domain/scheduling/scheduler.d.ts +3 -1
  163. package/dist/domain/scheduling/scheduler.js +22 -21
  164. package/dist/domain/sessions/session-hooks.d.ts +5 -4
  165. package/dist/domain/sessions/session-hooks.js +15 -33
  166. package/dist/domain/sessions/session-lifecycle.d.ts +19 -51
  167. package/dist/domain/sessions/session-lifecycle.js +34 -96
  168. package/dist/domain/system/doctor.d.ts +3 -3
  169. package/dist/domain/system/doctor.js +22 -26
  170. package/dist/domain/system/own-bin-path.d.ts +13 -0
  171. package/dist/domain/system/own-bin-path.js +36 -0
  172. package/dist/domain/system/terminal-cli/index.d.ts +58 -0
  173. package/dist/domain/system/terminal-cli/index.js +100 -0
  174. package/dist/domain/system/terminal-cli/posix-profiles.d.ts +23 -0
  175. package/dist/domain/system/terminal-cli/posix-profiles.js +74 -0
  176. package/dist/domain/system/terminal-cli/registrar.d.ts +12 -0
  177. package/dist/domain/system/terminal-cli/registrar.js +1 -0
  178. package/dist/domain/system/terminal-cli/shims.d.ts +27 -0
  179. package/dist/domain/system/terminal-cli/shims.js +108 -0
  180. package/dist/domain/system/terminal-cli/state.d.ts +7 -0
  181. package/dist/domain/system/terminal-cli/state.js +36 -0
  182. package/dist/domain/system/terminal-cli/windows-user-path.d.ts +13 -0
  183. package/dist/domain/system/terminal-cli/windows-user-path.js +67 -0
  184. package/dist/domain/tui-session/tui-session-service.js +1 -1
  185. package/dist/domain/tui-session/types.d.ts +2 -2
  186. package/dist/domain/ui-service/app-router.d.ts +49 -71
  187. package/dist/domain/ui-service/app-router.js +9 -13
  188. package/dist/domain/ui-service/assistant-snapshots.js +2 -0
  189. package/dist/domain/ui-service/contract.parity.d.ts +19 -0
  190. package/dist/domain/ui-service/contract.parity.js +1 -0
  191. package/dist/domain/ui-service/inline-media-types.d.ts +18 -0
  192. package/dist/domain/ui-service/inline-media-types.js +1 -0
  193. package/dist/domain/ui-service/input-schemas.d.ts +52 -115
  194. package/dist/domain/ui-service/input-schemas.js +38 -84
  195. package/dist/domain/ui-service/mutate/auth.d.ts +1 -1
  196. package/dist/domain/ui-service/mutate/auth.js +3 -2
  197. package/dist/domain/ui-service/mutate/config.d.ts +0 -8
  198. package/dist/domain/ui-service/mutate/config.js +0 -22
  199. package/dist/domain/ui-service/mutate/models.d.ts +13 -0
  200. package/dist/domain/ui-service/mutate/models.js +137 -0
  201. package/dist/domain/ui-service/mutate/resolve-media.d.ts +4 -0
  202. package/dist/domain/ui-service/mutate/resolve-media.js +17 -0
  203. package/dist/domain/ui-service/mutate/sessions.d.ts +2 -2
  204. package/dist/domain/ui-service/mutate/sessions.js +29 -126
  205. package/dist/domain/ui-service/query/config.js +22 -42
  206. package/dist/domain/ui-service/query/models.js +2 -2
  207. package/dist/domain/ui-service/query/schedules.js +1 -1
  208. package/dist/domain/ui-service/query/sessions.js +7 -13
  209. package/dist/domain/ui-service/types.d.ts +51 -177
  210. package/dist/domain/ui-service/ui-service.d.ts +23 -49
  211. package/dist/domain/ui-service/ui-service.js +8 -6
  212. package/dist/entry/app.js +42 -19
  213. package/dist/entry/browser-cli.d.ts +39 -0
  214. package/dist/entry/browser-cli.js +317 -0
  215. package/dist/entry/cli-help.d.ts +1 -0
  216. package/dist/entry/cli-help.js +37 -6
  217. package/dist/entry/cli.js +16 -14
  218. package/dist/entry/daemon.js +2 -0
  219. package/dist/entry/init-auth.js +1 -1
  220. package/dist/entry/init.d.ts +7 -8
  221. package/dist/entry/init.js +89 -249
  222. package/dist/entry/path-cli.d.ts +4 -0
  223. package/dist/entry/path-cli.js +65 -0
  224. package/dist/entry/schedule-cli.js +13 -6
  225. package/dist/entry/shutdown.d.ts +1 -1
  226. package/dist/entry/shutdown.js +8 -1
  227. package/dist/entry/start-ui-http.js +8 -0
  228. package/dist/entry/ui-service-wiring.js +8 -10
  229. package/dist/events/event-types.d.ts +3 -2
  230. package/dist/orchestration/agent-runner.d.ts +2 -2
  231. package/dist/orchestration/agent-runner.js +10 -9
  232. package/dist/orchestration/benchmark-session-webhook.js +13 -1
  233. package/dist/orchestration/browser-webhook.d.ts +11 -0
  234. package/dist/orchestration/browser-webhook.js +28 -0
  235. package/dist/orchestration/cache-keep-warm.d.ts +77 -0
  236. package/dist/orchestration/cache-keep-warm.js +213 -0
  237. package/dist/orchestration/claude-window-warmup.d.ts +40 -0
  238. package/dist/orchestration/claude-window-warmup.js +126 -0
  239. package/dist/orchestration/conversation-request.d.ts +6 -10
  240. package/dist/orchestration/conversation-request.js +5 -23
  241. package/dist/orchestration/delta-coalescer.d.ts +4 -2
  242. package/dist/orchestration/delta-coalescer.js +5 -5
  243. package/dist/orchestration/edit-retry.js +9 -11
  244. package/dist/orchestration/inline-media-eager.d.ts +13 -0
  245. package/dist/orchestration/inline-media-eager.js +58 -0
  246. package/dist/orchestration/inline-media.d.ts +22 -0
  247. package/dist/orchestration/inline-media.js +151 -0
  248. package/dist/orchestration/interactions/ask-user-resume.js +3 -7
  249. package/dist/orchestration/interactions/interaction-handlers.js +6 -6
  250. package/dist/orchestration/mid-turn-inject.d.ts +2 -1
  251. package/dist/orchestration/mid-turn-inject.js +1 -1
  252. package/dist/orchestration/pending-injection-recovery.d.ts +2 -1
  253. package/dist/orchestration/pending-injection-recovery.js +1 -1
  254. package/dist/orchestration/routing/commands/index.js +4 -4
  255. package/dist/orchestration/routing/commands/mode.d.ts +5 -44
  256. package/dist/orchestration/routing/commands/mode.js +98 -272
  257. package/dist/orchestration/routing/commands/schedule.js +29 -18
  258. package/dist/orchestration/routing/commands/session.js +9 -9
  259. package/dist/orchestration/routing/commands/status.js +1 -1
  260. package/dist/orchestration/routing/commands/usage-format.js +3 -0
  261. package/dist/orchestration/routing/webhook.js +4 -0
  262. package/dist/orchestration/session-compact.d.ts +0 -1
  263. package/dist/orchestration/session-compact.js +5 -7
  264. package/dist/orchestration/session-events.d.ts +2 -1
  265. package/dist/orchestration/session-events.js +1 -0
  266. package/dist/orchestration/status-helpers.d.ts +0 -4
  267. package/dist/orchestration/status-helpers.js +0 -18
  268. package/dist/orchestration/subagent-webhook.js +9 -34
  269. package/dist/orchestration/team-webhook.d.ts +8 -9
  270. package/dist/orchestration/team-webhook.js +16 -42
  271. package/dist/orchestration/transcript-sink.d.ts +6 -0
  272. package/dist/orchestration/transcript-sink.js +21 -2
  273. package/dist/orchestration/turn/terminal.js +7 -7
  274. package/dist/orchestration/turn/turn-prep.d.ts +0 -8
  275. package/dist/orchestration/turn/turn-prep.js +0 -51
  276. package/dist/orchestration/turn/turn-tracking.d.ts +2 -2
  277. package/dist/orchestration/turn/turn-tracking.js +8 -5
  278. package/dist/orchestration/turn/turn.d.ts +0 -2
  279. package/dist/orchestration/turn/turn.js +13 -15
  280. package/dist/platform/adapters/tui/ports.d.ts +1 -1
  281. package/dist/platform/adapters/tui/tui-transcript.js +2 -0
  282. package/dist/platform/browser/agent-browser.d.ts +50 -0
  283. package/dist/platform/browser/agent-browser.js +165 -0
  284. package/dist/platform/browser/managed-browser.d.ts +1 -11
  285. package/dist/platform/browser/managed-browser.js +4 -12
  286. package/dist/platform/ui-http/browser-stream.d.ts +110 -0
  287. package/dist/platform/ui-http/browser-stream.js +447 -0
  288. package/dist/platform/ui-http/ui-http-server.d.ts +12 -0
  289. package/dist/platform/ui-http/ui-http-server.js +23 -6
  290. package/dist/store/conversation-history-reader.js +8 -0
  291. package/dist/store/conversation-history-repo.d.ts +8 -1
  292. package/dist/store/conversation-history-repo.js +5 -0
  293. package/dist/store/conversation-ledger-repo.d.ts +6 -6
  294. package/dist/store/conversation-ledger-repo.js +4 -4
  295. package/dist/store/models-repo.d.ts +18 -0
  296. package/dist/store/models-repo.js +74 -0
  297. package/dist/store/pending-injection-repo.d.ts +2 -1
  298. package/dist/store/pending-injection-repo.js +3 -1
  299. package/dist/store/retire-profiles-migration.d.ts +28 -0
  300. package/dist/store/retire-profiles-migration.js +335 -0
  301. package/dist/store/schedule-repo.d.ts +2 -1
  302. package/dist/store/session-registry-import.js +3 -2
  303. package/dist/store/session-registry-journal.d.ts +10 -13
  304. package/dist/store/session-registry-journal.js +48 -25
  305. package/dist/store/session-registry-repo.d.ts +4 -4
  306. package/dist/store/session-registry-repo.js +4 -5
  307. package/dist/store/version-migrations.d.ts +2 -3
  308. package/dist/store/version-migrations.js +19 -3
  309. package/dist/tui/slash-commands.js +2 -2
  310. package/dist/tui/turn-status.js +1 -1
  311. package/package.json +6 -4
  312. package/web/dist/assets/board-math-css-CB4GJ6qO.js +2 -0
  313. package/web/dist/assets/index-CaSZPg_H.css +1 -0
  314. package/web/dist/assets/index-CzOR7Edh.js +522 -0
  315. package/web/dist/assets/{index-CndZZ1IQ.js → index-cIGFv27z.js} +1 -1
  316. package/web/dist/index.html +3 -2
  317. package/web/dist/theme.css +6 -0
  318. package/dist/agent-adapter/browser-mcp-server.d.ts +0 -13
  319. package/dist/agent-adapter/browser-mcp-server.js +0 -28
  320. package/dist/agent-adapter/claude/browser-mcp.d.ts +0 -9
  321. package/dist/agent-adapter/claude/browser-mcp.js +0 -10
  322. package/dist/core/profile-generator.d.ts +0 -79
  323. package/dist/core/profile-generator.js +0 -215
  324. package/dist/domain/agents/profile-manager.d.ts +0 -103
  325. package/dist/domain/agents/profile-manager.js +0 -286
  326. package/dist/domain/agents/profile-switch.d.ts +0 -49
  327. package/dist/domain/agents/profile-switch.js +0 -62
  328. package/dist/domain/ui-service/mutate/profiles.d.ts +0 -36
  329. package/dist/domain/ui-service/mutate/profiles.js +0 -151
  330. package/dist/store/profile-repo.d.ts +0 -20
  331. package/dist/store/profile-repo.js +0 -97
  332. package/web/dist/assets/index-B76ueW3q.js +0 -494
  333. package/web/dist/assets/index-C8O0yxg8.css +0 -1
@@ -1,161 +1,111 @@
1
+ import { AsyncMutex } from '../../core/async-mutex.js';
1
2
  import { readGatewayYaml } from '../../core/gateway-generator.js';
3
+ import { effectiveBackendSessionId, sessionStore } from '../../store/session-registry-repo.js';
2
4
  import { GATEWAY_CONFIG_PATH } from '../pi-providers/gateway-route-store.js';
3
- import { effectiveProfile, resolveRunConfig } from '../runs/config-resolver.js';
4
- import { clearChannelOverride, resolveBackendForChannel, setChannelOverride, setSelectionDefault, } from './config.js';
5
- import { findProfileForProvider, isValidThinkingLevel, resolveProfileConfig, THINKING_LEVELS_BY_BACKEND, } from './profile-manager.js';
6
- import { switchChannelProfile } from './profile-switch.js';
7
- const PROVIDER_NAME_RE = /^[a-zA-Z0-9_-]+$/;
8
- /** The gateway endpoint a profile's turns leave through: the provider for PI, the one Anthropic
9
- * endpoint for claude — the same rule `gateway-generator` writes the file with. */
10
- const CLAUDE_ENDPOINT = 'anthropic';
11
- /**
12
- * The routes gateway.yaml declares for one endpoint, or an empty list when the file cannot be read.
13
- *
14
- * A route that the gateway does not declare answers 404 at turn time, which reads as the agent
15
- * dying, so this one IS checked — but only when the file could actually be read. Injected so the
16
- * rule stays testable on a host with no gateway.yaml.
17
- */
18
- function declaredModes(endpoint, read = () => readGatewayYaml(GATEWAY_CONFIG_PATH)) {
19
- const parsed = read();
20
- const modes = parsed?.endpoints?.[endpoint];
21
- return modes ? Object.keys(modes) : [];
5
+ import { getChannelSelection, getModelMemory, rememberModelSelection, setChannelSelection, setSelectionDefault, } from './config.js';
6
+ import { isValidThinkingLevel, modelKey, THINKING_LEVELS_BY_BACKEND, } from './engine-selection.js';
7
+ import { firstModelRoute, getDefaultSelection, getDefaultSelectionForBackend } from './models.js';
8
+ export function decideBackendSwitch(opts) {
9
+ const backendChanged = opts.currentBackend !== opts.targetBackend;
10
+ if (opts.hasHistory && backendChanged)
11
+ return { allowed: false, reason: 'cross-backend-live-session' };
12
+ return { allowed: true, backendChanged };
22
13
  }
23
- /** The backend the request is validated against: the named profile's, or the channel's own when the
24
- * request keeps the profile it has. null means the named profile does not exist. */
25
- function targetBackend(request) {
26
- if (!request.profileName)
27
- return resolveBackendForChannel(request.channel);
28
- try {
29
- return resolveProfileConfig(request.profileName).backend;
30
- }
31
- catch {
32
- return null;
33
- }
14
+ export function readChannelSelection(channel) {
15
+ return getChannelSelection(channel) ?? getDefaultSelection();
34
16
  }
35
- /** A refusal: the reason, plus the selection the channel still has. */
36
- function refuse(channel, reason) {
37
- return { ...readChannelSelection(channel), ok: false, backendChanged: false, reason };
17
+ function refuse(current, reason, allowed) {
18
+ return { ...current, ok: false, backendChanged: false, reason, ...(allowed ? { allowed } : {}) };
38
19
  }
39
- /** The channel's current selection, with no change applied. */
40
- export function readChannelSelection(channel) {
41
- const config = resolveRunConfig({ channel });
42
- const profile = effectiveProfile(config);
20
+ /** A complete identity needs no favorite. */
21
+ function targetRef(request, current) {
22
+ const backend = request.backend ?? current.backend;
23
+ const changingBackend = backend !== current.backend;
24
+ const base = changingBackend ? getDefaultSelectionForBackend(backend) : current;
25
+ const model = request.model !== undefined ? request.model : base?.model;
26
+ const provider = request.provider !== undefined ? request.provider : (backend === 'claude' ? null : base?.provider);
27
+ if (model === undefined)
28
+ return null;
29
+ return { backend, provider: provider ?? null, model };
30
+ }
31
+ function mergeSelection(request, current, ref) {
32
+ const changed = modelKey(ref) !== modelKey(current);
33
+ const memory = getModelMemory()[modelKey(ref)];
34
+ const settings = changed ? (memory ?? { thinking: null, mode: firstModelRoute(ref, request.readGateway) }) : current;
43
35
  return {
44
- profileName: config.profileName,
45
- backend: profile.backend,
46
- model: profile.model,
47
- provider: profile.provider,
48
- thinking: profile.thinking,
49
- mode: profile.mode,
50
- override: config.override,
36
+ ...ref,
37
+ thinking: request.thinking !== undefined ? request.thinking : settings.thinking,
38
+ mode: request.mode !== undefined ? request.mode : settings.mode,
51
39
  };
52
40
  }
53
- /**
54
- * Apply a selection to a channel.
55
- *
56
- * Order of operations, and why:
57
- * 1. Everything is validated against the backend the request is HEADED for (the named profile's,
58
- * else the channel's), BEFORE anything is written — a request that fails must leave the channel
59
- * exactly as it was, not half-switched.
60
- * 2. An explicit `profileName` switches first, under the shared cross-backend rule
61
- * (`switchChannelProfile`). Choosing a profile means "run this profile", so its existing
62
- * overrides are dropped — anything the same call still wants is re-applied in step 4.
63
- * 3. A PI provider the channel's profile does not use is looked up among the profiles: if the home
64
- * has one for that provider, the channel moves there instead of carrying a provider override,
65
- * so the route, env and fallback chain stay the ones the user configured for that provider.
66
- * 4. The remaining fields are patched onto the channel's override.
67
- */
68
- export async function applyChannelSelection(request) {
69
- const { channel } = request;
70
- let backendChanged = false;
71
- // Validate against the backend the request is HEADED for, before anything is written: a request
72
- // that names both a profile and a level the new backend rejects must fail whole, not leave the
73
- // channel switched.
74
- const target = targetBackend(request);
75
- if (!target)
76
- return refuse(channel, 'unknown-profile');
77
- if (request.thinking && !isValidThinkingLevel(target, request.thinking)) {
78
- return { ...refuse(channel, 'invalid-thinking'), allowed: THINKING_LEVELS_BY_BACKEND[target] };
79
- }
80
- if (request.provider && (target !== 'pi' || !PROVIDER_NAME_RE.test(request.provider))) {
81
- return refuse(channel, 'provider-not-supported');
82
- }
83
- if (request.mode) {
84
- // The endpoint the route must belong to: the provider this same request selects, else the one
85
- // the channel's profile already leaves through.
86
- const endpoint = target === 'claude'
87
- ? CLAUDE_ENDPOINT
88
- : request.provider ?? readChannelSelection(channel).provider ?? '';
89
- const modes = declaredModes(endpoint, request.readGateway);
90
- // No declared routes means gateway.yaml could not be read — the run falls back to a direct
91
- // connection anyway, so a route cannot be checked and is not refused.
92
- if (modes.length > 0 && !modes.includes(request.mode)) {
93
- return { ...refuse(channel, 'invalid-mode'), allowed: modes };
94
- }
41
+ function targetSelection(request, current) {
42
+ // A backend pick selects its complete default, not just its model identity.
43
+ if (request.backend !== undefined && request.model === undefined && request.provider === undefined) {
44
+ const defaults = getDefaultSelectionForBackend(request.backend);
45
+ return defaults ? mergeSelection(request, defaults, defaults) : null;
95
46
  }
96
- if (request.profileName) {
97
- const switched = await switchChannelProfile({ channel, name: request.profileName });
98
- if (!switched.ok) {
99
- return switched.reason === 'unknown-profile'
100
- ? refuse(channel, 'unknown-profile')
101
- : {
102
- ...refuse(channel, 'cross-backend-live-session'),
103
- currentBackend: switched.currentBackend,
104
- targetBackend: switched.targetBackend,
105
- };
106
- }
107
- backendChanged = switched.backendChanged;
108
- clearChannelOverride(channel);
109
- }
110
- const patch = { model: request.model, thinking: request.thinking, mode: request.mode };
111
- if (request.provider) {
112
- // Compared against the PROFILE's own provider, never the effective one: a provider that is
113
- // only in force because an override carries it still needs that override. Reading the
114
- // effective value here would clear it on the next pick from the same provider and quietly
115
- // send the turn back to the profile's endpoint — the wrong gateway, with the wrong protocol.
116
- const base = resolveRunConfig({ channel }).profile;
117
- if (request.provider === base.provider) {
118
- // The profile already routes there; there is nothing left for an override to say.
119
- patch.provider = null;
120
- }
121
- else {
122
- // The route belongs to the endpoint being left behind; `effectiveProfile` re-derives it for
123
- // the new provider, so carrying the old one would only be a stale 404 waiting to happen.
124
- if (request.mode === undefined)
125
- patch.mode = null;
126
- const sibling = !request.profileName ? findProfileForProvider('pi', request.provider) : null;
127
- if (sibling) {
128
- const switched = await switchChannelProfile({ channel, name: sibling.name });
129
- // Same backend as the channel's current one, so the rule cannot refuse — but if it ever
130
- // did, the provider override below is still a correct (if less configured) answer.
131
- if (switched.ok) {
132
- backendChanged = backendChanged || switched.backendChanged;
133
- clearChannelOverride(channel);
134
- patch.provider = null;
135
- }
136
- else {
137
- patch.provider = request.provider;
138
- }
139
- }
140
- else {
141
- patch.provider = request.provider;
142
- }
143
- }
144
- }
145
- else if (request.provider === null) {
146
- patch.provider = null;
147
- }
148
- setChannelOverride(channel, patch);
149
- const selection = readChannelSelection(channel);
150
- // What the next brand-new conversation starts on. A pick made in the app is a statement about how
151
- // the user wants to work, not about this one session, so it outlives the session that made it —
152
- // and it always carries the profile it was made on, so the seed is a complete engine rather than
153
- // a set of overrides with no base to hang on.
154
- //
155
- // Only direct (`web:`) channels seed it. A platform channel's profile is chosen for that channel;
156
- // an `!thinking` in Slack has no business deciding what the desktop composer opens on.
157
- if (channel.startsWith('web:') && request.seedDefault !== false) {
158
- setSelectionDefault({ profileName: selection.profileName, ...(selection.override ?? {}) });
47
+ const ref = targetRef(request, current);
48
+ return ref ? mergeSelection(request, current, ref) : null;
49
+ }
50
+ const SAFE_NAME = /^[a-zA-Z0-9_-]+$/;
51
+ function invalidIdentity(selection) {
52
+ if (typeof selection.model !== 'string' || !selection.model.trim())
53
+ return 'invalid-model';
54
+ const validProvider = selection.backend === 'claude' ? selection.provider === null
55
+ : selection.backend === 'pi' && typeof selection.provider === 'string' && SAFE_NAME.test(selection.provider);
56
+ return validProvider ? null : 'provider-not-supported';
57
+ }
58
+ function validateTarget(request, current, target) {
59
+ const identityFailure = invalidIdentity(target);
60
+ if (identityFailure)
61
+ return refuse(current, identityFailure);
62
+ if (target.thinking !== null && !isValidThinkingLevel(target.backend, target.thinking)) {
63
+ return refuse(current, 'invalid-thinking', THINKING_LEVELS_BY_BACKEND[target.backend]);
159
64
  }
160
- return { ok: true, backendChanged, ...selection };
65
+ return validateRoute(request, current, target);
66
+ }
67
+ function validateRoute(request, current, target) {
68
+ const gateway = (request.readGateway ?? (() => readGatewayYaml(GATEWAY_CONFIG_PATH)))();
69
+ const endpoint = target.backend === 'claude' ? 'anthropic' : target.provider;
70
+ const modes = Object.keys(gateway?.endpoints?.[endpoint] ?? {});
71
+ const validName = typeof target.mode === 'string' && SAFE_NAME.test(target.mode);
72
+ if (!validName || (gateway && !modes.includes(target.mode)))
73
+ return refuse(current, 'invalid-mode', modes);
74
+ return null;
75
+ }
76
+ /** Serialize read/validate/write so simultaneous patches cannot overwrite a newer selection. */
77
+ const selectionWrites = new AsyncMutex();
78
+ export function applyChannelSelection(request) {
79
+ return selectionWrites.run(() => applySelection(request));
80
+ }
81
+ async function applySelection(request) {
82
+ const sessionId = await sessionStore.getBoundSessionId(request.channel);
83
+ const session = sessionId ? await sessionStore.getById(sessionId) : null;
84
+ const current = session?.selection ?? readChannelSelection(request.channel);
85
+ const target = targetSelection(request, current);
86
+ if (!target)
87
+ return refuse(current, 'no-model-for-backend');
88
+ const invalid = validateTarget(request, current, target);
89
+ if (invalid)
90
+ return invalid;
91
+ return persistSelection(request, current, target, session);
92
+ }
93
+ async function persistSelection(request, current, target, session) {
94
+ // Attach/resume clears channel turns, but the backend conversation still exists.
95
+ const hasHistory = !!(session && effectiveBackendSessionId(session))
96
+ || (await sessionStore.getTurns(request.channel)).length > 0;
97
+ const currentBackend = session?.backend ?? current.backend;
98
+ const decision = decideBackendSwitch({ currentBackend, targetBackend: target.backend, hasHistory });
99
+ if (!decision.allowed)
100
+ return {
101
+ ...refuse(current, 'cross-backend-live-session'), currentBackend, targetBackend: target.backend,
102
+ };
103
+ // Session selection wins at run time: never acknowledge a pick if its journal write failed.
104
+ if (session)
105
+ await sessionStore.updateSession(session.sessionId, { backend: target.backend, selection: target });
106
+ setChannelSelection(request.channel, target);
107
+ rememberModelSelection(target);
108
+ if (request.channel.startsWith('web:') && request.seedDefault !== false)
109
+ setSelectionDefault(target);
110
+ return { ...target, ok: true, backendChanged: decision.backendChanged };
161
111
  }
@@ -0,0 +1,12 @@
1
+ import type { Backend } from '../../core/types/agent-types.js';
2
+ import { type EngineSelection, type ModelRef, type ModelsFile } from './engine-selection.js';
3
+ export declare function validateModelsFile(value: unknown): asserts value is ModelsFile;
4
+ export declare function loadModelsFile(): ModelsFile;
5
+ export declare function getDefaultSelection(): EngineSelection;
6
+ export declare function listFavorites(): ModelRef[];
7
+ export declare function getDefaultSelectionForBackend(backend: Backend): EngineSelection | null;
8
+ export declare function selectionForModel(ref: ModelRef): EngineSelection;
9
+ /** PI's generated route is its provider. Claude uses gateway declaration order. */
10
+ export declare function firstModelRoute(ref: ModelRef, readGateway?: () => import("../../core/gateway-generator.js").ParsedGateway): string;
11
+ /** Synchronous: use warm catalog entries, never start a provider scan to parse a command. */
12
+ export declare function resolveModelRef(ref: string, backend?: Backend): ModelRef;
@@ -0,0 +1,94 @@
1
+ import { readGatewayYaml } from '../../core/gateway-generator.js';
2
+ import { modelsRepo } from '../../store/models-repo.js';
3
+ import { piProviderDiscovery } from '../../agent-adapter/pi/discovery.js';
4
+ import { GATEWAY_CONFIG_PATH } from '../pi-providers/gateway-route-store.js';
5
+ import { getModelMemory } from './config.js';
6
+ import { copySelection, modelKey, validateEngineSelection, validateModelRef, } from './engine-selection.js';
7
+ let validated = null;
8
+ export function validateModelsFile(value) {
9
+ const data = value;
10
+ validateEngineSelection(data?.default);
11
+ if (!Array.isArray(data.favorites))
12
+ throw new Error('favorites must be an array');
13
+ const seen = new Set();
14
+ for (const ref of data.favorites) {
15
+ validateModelRef(ref);
16
+ const key = modelKey(ref);
17
+ if (seen.has(key))
18
+ throw new Error(`Duplicate favorite: ${ref.model}`);
19
+ seen.add(key);
20
+ }
21
+ }
22
+ export function loadModelsFile() {
23
+ try {
24
+ const data = modelsRepo.readSync();
25
+ if (data !== validated) {
26
+ validateModelsFile(data);
27
+ validated = data;
28
+ }
29
+ return { default: copySelection(data.default), favorites: data.favorites.map(copyRef) };
30
+ }
31
+ catch (error) {
32
+ throw new Error(`Failed to load models.json: ${error.message}`);
33
+ }
34
+ }
35
+ function copyRef({ backend, provider, model }) {
36
+ return { backend, provider, model };
37
+ }
38
+ export function getDefaultSelection() { return loadModelsFile().default; }
39
+ export function listFavorites() { return loadModelsFile().favorites; }
40
+ export function getDefaultSelectionForBackend(backend) {
41
+ let file;
42
+ try {
43
+ file = loadModelsFile();
44
+ }
45
+ catch {
46
+ return null;
47
+ }
48
+ if (file.default.backend === backend)
49
+ return file.default;
50
+ const favorite = file.favorites.find((ref) => ref.backend === backend);
51
+ return favorite ? selectionForModel(favorite) : null;
52
+ }
53
+ export function selectionForModel(ref) {
54
+ validateModelRef(ref);
55
+ const memory = getModelMemory()[modelKey(ref)];
56
+ return { ...copyRef(ref), ...(memory ?? { thinking: null, mode: firstModelRoute(ref) }) };
57
+ }
58
+ /** PI's generated route is its provider. Claude uses gateway declaration order. */
59
+ export function firstModelRoute(ref, readGateway = () => readGatewayYaml(GATEWAY_CONFIG_PATH)) {
60
+ if (ref.backend === 'pi')
61
+ return ref.provider;
62
+ const modes = readGateway()?.endpoints?.anthropic;
63
+ return Object.keys(modes ?? {})[0] ?? 'plan';
64
+ }
65
+ function explicitRef(ref) {
66
+ const slash = ref.indexOf('/');
67
+ if (slash < 0)
68
+ return null;
69
+ const result = { backend: 'pi', provider: ref.slice(0, slash), model: ref.slice(slash + 1) };
70
+ validateModelRef(result);
71
+ return result;
72
+ }
73
+ function resolvePiRef(model, file) {
74
+ const candidates = [file.default, ...file.favorites,
75
+ ...piProviderDiscovery.peekModels().map((pair) => ({ ...pair, backend: 'pi' }))];
76
+ const match = candidates.find((ref) => ref.backend === 'pi' && ref.model === model);
77
+ if (match)
78
+ return copyRef(match);
79
+ if (file.default.backend === 'pi')
80
+ return { backend: 'pi', provider: file.default.provider, model };
81
+ throw new Error(`Unknown PI model '${model}': specify provider/model or favorite a model first`);
82
+ }
83
+ /** Synchronous: use warm catalog entries, never start a provider scan to parse a command. */
84
+ export function resolveModelRef(ref, backend) {
85
+ const model = ref.trim();
86
+ if (!model)
87
+ throw new Error('Model must be a non-empty string');
88
+ const explicit = explicitRef(model);
89
+ if (explicit)
90
+ return explicit;
91
+ const file = loadModelsFile();
92
+ const target = backend ?? file.default.backend;
93
+ return target === 'claude' ? { backend: 'claude', provider: null, model } : resolvePiRef(model, file);
94
+ }
@@ -70,6 +70,8 @@ export declare function trackSubagentChildren(runId: string, blockId: (index: nu
70
70
  * Native CLI tasks have their own lifecycle tracker and are not represented here. */
71
71
  export declare function getSubagentChildStatuses(sessionId: string): ReadonlyMap<string, 'running' | SubagentEndStatus>;
72
72
  export declare function getSubagentRun(id: string): SubagentRunView | null;
73
+ /** Whether the session owns a background run still going, whose result will wake it. */
74
+ export declare function hasRunningBackgroundRuns(sessionId: string): boolean;
73
75
  export interface SubagentRunOutcome {
74
76
  view: SubagentRunView;
75
77
  /** Present only once the run has completed successfully. */
@@ -133,6 +133,14 @@ export function getSubagentRun(id) {
133
133
  const record = runs.get(id);
134
134
  return record ? viewOf(record) : null;
135
135
  }
136
+ /** Whether the session owns a background run still going, whose result will wake it. */
137
+ export function hasRunningBackgroundRuns(sessionId) {
138
+ for (const record of runs.values()) {
139
+ if (record.sessionId === sessionId && record.background && record.status === 'running')
140
+ return true;
141
+ }
142
+ return false;
143
+ }
136
144
  /**
137
145
  * Wait up to `sliceMs` for a run to settle, then answer with whatever state it is in.
138
146
  *
@@ -2,10 +2,10 @@ import type { Backend } from '../../../agent-adapter/types.js';
2
2
  import type { SubagentNotice } from '../../../core/agents/subagent/types.js';
3
3
  import { type ModelSpec } from '../../../core/agents/subagent/model-spec.js';
4
4
  import { type AgentRole } from '../../../core/agents/roles.js';
5
- import { type RunAttemptConfig } from '../profile-manager.js';
5
+ import type { EngineSelection } from '../engine-selection.js';
6
6
  import type { RunObserver, RunRequest } from '../../runs/request.js';
7
7
  import type { SubagentResult, SubagentTask } from '../../../core/agents/subagent/types.js';
8
- /** What the delegating turn already resolved. A child inherits routing from here — never a profile. */
8
+ /** The delegating turn's materialized engine context. */
9
9
  export interface SubagentParentContext {
10
10
  backend: Backend;
11
11
  /** The parent run's resolved gateway route. A same-backend Claude child reuses it verbatim. */
@@ -44,12 +44,12 @@ export declare function runSubagent(request: SubagentRunRequest): Promise<Subage
44
44
  * The child model comes from the task or role, then the parent's own model when that parent is
45
45
  * Claude, and finally the configured Claude-backend default. The route follows the Claude parent
46
46
  * when there is one; a cross-backend child uses that Claude default instead of the PI channel's
47
- * mode. The fallback profile supplies routing only — the child remains an unnamed one-shot run.
47
+ * mode. The child remains a one-shot run.
48
48
  */
49
- declare function claudeChildConfig(request: SubagentRunRequest, spec: ModelSpec): RunAttemptConfig;
49
+ declare function claudeChildConfig(request: SubagentRunRequest, spec: ModelSpec): EngineSelection;
50
50
  /** The request a Claude child runs under. A frozen one-shot role: no session to resume, no
51
51
  * hooks, no ambient rules, no transcript log, and a leaf tool surface. */
52
- declare function claudeChildRequest(request: SubagentRunRequest, config: RunAttemptConfig): RunRequest;
52
+ declare function claudeChildRequest(request: SubagentRunRequest, config: EngineSelection): RunRequest;
53
53
  /** Live attribution: the child's own run events, re-stamped with the parent's block key. */
54
54
  declare function claudeNoticeObserver(request: SubagentRunRequest): RunObserver;
55
55
  /** Internals exposed for tests only. */
@@ -7,7 +7,7 @@ import { noticesFor } from '../../../agent-adapter/pi/child-events.js';
7
7
  import { getPiEngineAdapter } from '../../runs/adapters.js';
8
8
  import { GATEWAY_URL } from '../../costs/gateway-manager.js';
9
9
  import { buildPiGatewaySubPath } from '../../runs/engine-spec.js';
10
- import { getDefaultProfileForBackend, resolveProfileConfig, } from '../profile-manager.js';
10
+ import { getDefaultSelectionForBackend } from '../models.js';
11
11
  import { startRun } from '../../runs/service.js';
12
12
  import { engines } from '../../runs/engines.js';
13
13
  import { fromRole } from '../../runs/spec-loader.js';
@@ -40,7 +40,7 @@ export async function runSubagent(request) {
40
40
  /**
41
41
  * Route resolution for a `pi` child, in order: the role's own `mode:`, then the parent's route when
42
42
  * the parent is a PI run on this same provider, and finally the provider's own name — which is the
43
- * convention `profiles.json` already follows (`provider: deepseek` pairs with `mode: deepseek`).
43
+ * PI convention (`provider: deepseek` pairs with `mode: deepseek`).
44
44
  */
45
45
  function resolvePiMode(request, provider) {
46
46
  if (request.role.mode)
@@ -109,26 +109,24 @@ function piForwarder(request) {
109
109
  };
110
110
  }
111
111
  // ─── claude child ─────────────────────────────────────────────────
112
- /** The fallback route for a Claude child must itself be a Claude profile. Using the caller's
113
- * channel default here can smuggle a PI gateway mode into a cross-backend Claude attempt. */
114
- function claudeFallbackProfile() {
115
- const name = getDefaultProfileForBackend('claude');
116
- if (!name) {
117
- throw new Error('A claude subagent needs a configured Claude profile for routing.');
118
- }
119
- return resolveProfileConfig(name);
112
+ /** A cross-backend child must use a Claude route, never the PI parent's route. */
113
+ function claudeDefaultSelection() {
114
+ const selection = getDefaultSelectionForBackend('claude');
115
+ if (!selection)
116
+ throw new Error('A claude subagent needs a Claude default or favorite; favorite a Claude model first.');
117
+ return selection;
120
118
  }
121
119
  /**
122
120
  * The child model comes from the task or role, then the parent's own model when that parent is
123
121
  * Claude, and finally the configured Claude-backend default. The route follows the Claude parent
124
122
  * when there is one; a cross-backend child uses that Claude default instead of the PI channel's
125
- * mode. The fallback profile supplies routing only — the child remains an unnamed one-shot run.
123
+ * mode. The child remains a one-shot run.
126
124
  */
127
125
  function claudeChildConfig(request, spec) {
128
126
  const sameBackend = request.parent.backend === 'claude';
129
127
  let fallback = null;
130
- const claudeDefault = () => fallback ??= claudeFallbackProfile();
131
- const inheritedMode = sameBackend && request.parent.mode !== undefined
128
+ const claudeDefault = () => fallback ??= claudeDefaultSelection();
129
+ const inheritedMode = sameBackend && request.parent.mode != null
132
130
  ? request.parent.mode
133
131
  : claudeDefault().mode;
134
132
  return {
@@ -136,29 +134,9 @@ function claudeChildConfig(request, spec) {
136
134
  backend: 'claude',
137
135
  mode: inheritedMode,
138
136
  provider: null,
139
- extraEnv: {},
140
- extraOption: {},
141
137
  thinking: spec.thinking ?? null,
142
138
  };
143
139
  }
144
- /** Wrap the child's resolved config as the run's profile: the run layer plans its attempt chain
145
- * from `request.profile`, so a synthesized single-attempt profile is how a role/task model reaches
146
- * the spawn without any named profile being consulted. */
147
- function claudeChildProfile(config) {
148
- return {
149
- // Unnamed on purpose: no profile was consulted for the child, so none is attested to it.
150
- name: '',
151
- model: config.model,
152
- backend: config.backend,
153
- mode: config.mode,
154
- provider: config.provider ?? null,
155
- extraEnv: config.extraEnv ?? {},
156
- extraOption: config.extraOption ?? {},
157
- thinking: config.thinking ?? null,
158
- maxOutputTokens: config.maxOutputTokens ?? null,
159
- fallback: [],
160
- };
161
- }
162
140
  /**
163
141
  * A child's own pool slot, never the parent's. Keying a child on the parent's channel put it on
164
142
  * the slot the parent's interactive session already occupies (`engineKey === channel` there too),
@@ -182,7 +160,7 @@ function claudeChildRequest(request, config) {
182
160
  backendSessionId: null,
183
161
  engineKey: childEngineKey(request, runId),
184
162
  },
185
- profile: claudeChildProfile(config),
163
+ selection: config,
186
164
  // The child runs where the caller asked (the parent's workspace), not where the server lives.
187
165
  cwd: request.cwd,
188
166
  spec: fromRole(request.role, 'claude', { mcpAllowlist: mcpToolAllowlist ?? null }),
@@ -208,7 +186,6 @@ function claudeChildRequest(request, config) {
208
186
  loadRules: false, // loadCortexRules: false
209
187
  mcpComposition: 'direct',
210
188
  mcpToolAllowlist,
211
- browserCdpEndpoint: null,
212
189
  captureTranscripts: false, // captureTranscriptLogs: false
213
190
  },
214
191
  };
@@ -1,5 +1,5 @@
1
1
  import type { Backend } from '../../agent-adapter/types.js';
2
- import { type ResolvedProfile } from '../agents/profile-manager.js';
2
+ import type { ModelRef } from '../agents/engine-selection.js';
3
3
  import { type ClaudeAuthStatus } from './cc-auth-cli.js';
4
4
  import { type LoadPiRuntimeOptions, type PiRuntimeLoadResult } from './pi-runtime.js';
5
5
  export type AuthType = 'oauth' | 'api_key';
@@ -38,7 +38,7 @@ export interface AuthStatusSnapshot {
38
38
  };
39
39
  }
40
40
  export declare function preferredAuthType(snapshot: AuthStatusSnapshot, backend: 'claude' | 'pi', provider: string): AuthType | null;
41
- interface ActiveProfileReference {
41
+ interface SelectionReference {
42
42
  backend: Backend;
43
43
  provider: string | null;
44
44
  }
@@ -55,8 +55,8 @@ export interface GetAuthStatusOptions {
55
55
  };
56
56
  getClaudeMode?: () => string;
57
57
  getActiveBackend?: () => Backend;
58
- listProfiles?: () => ResolvedProfile[];
59
- getActiveProfileConfig?: () => ActiveProfileReference;
58
+ listFavorites?: () => ModelRef[];
59
+ getDefaultSelection?: () => SelectionReference | null;
60
60
  readClaudeAuthStatus?: () => Promise<ClaudeAuthStatus>;
61
61
  }
62
62
  export declare function getAuthStatus(options?: GetAuthStatusOptions): Promise<AuthStatusSnapshot>;
@@ -3,9 +3,9 @@
3
3
  import { readClaudeStore } from '../../core/claude-credentials.js';
4
4
  import { piUserAuthPath } from '../../core/pi-sdk.js';
5
5
  import { resolveConfiguredDefaultRun } from '../runs/config-resolver.js';
6
- import { getActiveProfile } from '../agents/config.js';
6
+ import { modelsRepo } from '../../store/models-repo.js';
7
7
  import { getSavedApiEnv as readSavedApiEnv } from './anthropic-env.js';
8
- import { listProfiles as readProfiles, resolveProfileConfig, } from '../agents/profile-manager.js';
8
+ import { listFavorites as readFavorites } from '../agents/models.js';
9
9
  import { readClaudeAuthStatus as readInstalledClaudeAuthStatus, } from './cc-auth-cli.js';
10
10
  import { loadPiRuntime as loadInstalledPiRuntime, } from './pi-runtime.js';
11
11
  export function preferredAuthType(snapshot, backend, provider) {
@@ -207,54 +207,43 @@ function buildPiAccount(runtime, readStored, provider, authPath, nowMs, inUse) {
207
207
  return unknownPiAccount(provider, status.source ?? null, inUse);
208
208
  }
209
209
  }
210
- function addProfileReference(usage, entry, inherited = 'claude') {
211
- const backend = entry.backend ?? inherited;
212
- if (backend === 'claude')
210
+ function addModelReference(usage, entry) {
211
+ if (entry.backend === 'claude')
213
212
  usage.claude = true;
214
- if (backend === 'pi' && entry.provider)
213
+ if (entry.backend === 'pi' && entry.provider)
215
214
  usage.pi.add(entry.provider);
216
215
  }
217
- function addProfile(usage, profile) {
218
- const primaryBackend = profile.backend ?? 'claude';
219
- addProfileReference(usage, profile);
220
- for (const fallback of profile.fallback ?? [])
221
- addProfileReference(usage, fallback, primaryBackend);
222
- }
223
- function defaultActiveProfileConfig() {
224
- const profile = resolveProfileConfig(getActiveProfile());
225
- return { backend: profile.backend, provider: profile.provider };
216
+ function configuredDefault() {
217
+ return modelsRepo.readIfPresent()?.default ? resolveConfiguredDefaultRun() : null;
226
218
  }
227
- /** The backend and Claude mode a channel with no selection of its own will run (D5): the default
228
- * profile's, replacing the retired daemon-wide `backend` / `claudeMode` fields. */
229
219
  function defaultRunBackend() {
230
- return resolveConfiguredDefaultRun()?.profile.backend ?? null;
220
+ return configuredDefault()?.backend ?? null;
231
221
  }
232
222
  function defaultClaudeMode() {
233
- return resolveConfiguredDefaultRun()?.profile.mode ?? 'plan';
223
+ return configuredDefault()?.mode ?? 'plan';
234
224
  }
235
225
  function collectInUse(options) {
236
226
  const usage = { claude: false, pi: new Set() };
237
227
  try {
238
- for (const profile of (options.listProfiles ?? readProfiles)())
239
- addProfile(usage, profile);
228
+ for (const model of (options.listFavorites ?? readFavorites)())
229
+ addModelReference(usage, model);
240
230
  }
241
231
  catch {
242
- // A broken profile file must not hide credential state.
232
+ // A broken models file must not hide credential state.
243
233
  }
244
- // D5: there is no daemon-wide backend. What "in use" means for a credential is the backend the
245
- // default profile runs, which is what an unconfigured channel will pick up.
234
+ // Include the configured default even if it is not favorited.
246
235
  const backend = (options.getActiveBackend ?? defaultRunBackend)();
247
236
  if (backend === 'claude')
248
237
  usage.claude = true;
249
238
  if (backend !== 'pi')
250
239
  return usage;
251
240
  try {
252
- const active = (options.getActiveProfileConfig ?? defaultActiveProfileConfig)();
253
- if (active.backend === 'pi' && active.provider)
254
- usage.pi.add(active.provider);
241
+ const active = (options.getDefaultSelection ?? configuredDefault)();
242
+ if (active)
243
+ addModelReference(usage, active);
255
244
  }
256
245
  catch {
257
- // Active profile resolution is advisory for inUse only.
246
+ // Default selection resolution is advisory for inUse only.
258
247
  }
259
248
  return usage;
260
249
  }