@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,164 +1,38 @@
1
- import { profileRepo } from '../../store/profile-repo.js';
2
- import { getActiveProfile, getChannelOverride } from '../agents/config.js';
1
+ import { modelsRepo } from '../../store/models-repo.js';
2
+ import { getChannelSelection } from '../agents/config.js';
3
+ import { getDefaultSelection } from '../agents/models.js';
3
4
  import { resolveModeEnv } from './mode-env.js';
4
- import { getDefaultProfileName, resolveModeForProvider, resolveProfileConfig, } from '../agents/profile-manager.js';
5
- /** Startup and login exist before a first profile. Only a missing file is unconfigured. */
6
- export function resolveConfiguredDefaultRun() {
7
- if (!profileRepo.readIfPresent())
8
- return null;
9
- // Validate existing configuration even when the active selection could use a synthetic fallback.
10
- getDefaultProfileName();
11
- return resolveRunConfig();
12
- }
13
- const FALLBACK_BACKEND = 'claude';
14
- const FALLBACK_MODE = 'plan';
15
- /**
16
- * The profile name for a run, by D5's priority: explicit override → the session's recorded
17
- * profile → the channel's profile → the global active profile → profiles.defaultProfile.
18
- *
19
- * `getActiveProfile(channel)` already folds the middle two together (and resolves init's
20
- * `'__active__'` placeholder), so only the ends are added here.
21
- */
22
- export function resolveProfileName(query = {}) {
23
- return query.override
24
- || query.session?.profileName
25
- || getActiveProfile(query.channel ?? undefined)
26
- || getDefaultProfileName();
27
- }
28
- /** A profile shaped like the requested one but carrying no configuration: it keeps the name so the
29
- * run still rejects it, and borrows a backend/mode so the execution record is not a lie. Replaces
30
- * three byte-identical copies that each hard-coded the retired global backend. */
31
- function syntheticProfile(profileName, backend, mode) {
32
- return {
33
- name: profileName,
34
- model: '',
35
- backend,
36
- mode,
37
- provider: null,
38
- extraEnv: {},
39
- extraOption: {},
40
- thinking: null,
41
- maxOutputTokens: null,
42
- fallback: [],
43
- };
44
- }
45
- /**
46
- * What an unknown profile name borrows: the profile the channel would have used had the caller not
47
- * named one. Before D5 this was the stored global backend; with backend living on the profile, the
48
- * channel's own chain is the nearest honest answer, and it agrees with the old one whenever the
49
- * global backend matched the channel's profile — which is the only case where it was ever right.
50
- */
51
- function borrowedIdentity(query) {
52
- const name = resolveProfileName({ channel: query.channel, session: query.session });
53
- try {
54
- const profile = resolveProfileConfig(name);
55
- return { backend: profile.backend, mode: profile.mode };
56
- }
57
- catch {
58
- return { backend: FALLBACK_BACKEND, mode: FALLBACK_MODE };
5
+ /** Explicit request > recorded session > channel > configured default. No overlays. */
6
+ export function resolveRunSelection(query = {}) {
7
+ const selection = query.selection ?? query.session?.selection
8
+ ?? getChannelSelection(query.channel ?? undefined) ?? getDefaultSelection();
9
+ const session = query.session;
10
+ // Legacy records resume by sessionId; an explicit null is a history-free session.
11
+ const resumeId = session?.backendSessionId === undefined ? session?.sessionId : session.backendSessionId;
12
+ if (resumeId && session?.backend && selection.backend !== session.backend) {
13
+ throw new Error(`Cannot resume ${session.backend} session on ${selection.backend} backend`);
59
14
  }
15
+ return selection;
60
16
  }
61
- /**
62
- * Resolve everything a run needs to know about its configuration, in one place.
63
- *
64
- * Backend, model, provider, mode, thinking and the fallback chain come from the profile and only
65
- * from the profile (D5). The single exception is the channel's `!model` override, returned
66
- * separately rather than folded in so a caller can tell "the profile says X" from "this channel
67
- * was told to use Y" — the run applies it, the display distinguishes them.
68
- */
69
- export function resolveRunConfig(query = {}) {
70
- const profileName = resolveProfileName(query);
71
- const override = getChannelOverride(query.channel);
72
- const modelOverride = override?.model ?? null;
73
- try {
74
- return {
75
- profileName, profile: resolveProfileConfig(profileName), override, modelOverride, resolved: true,
76
- };
77
- }
78
- catch {
79
- const { backend, mode } = borrowedIdentity(query);
80
- return {
81
- profileName,
82
- profile: syntheticProfile(profileName, backend, mode),
83
- override,
84
- modelOverride,
85
- resolved: false,
86
- };
87
- }
17
+ /** Startup and login can precede configuration; malformed configuration still throws. */
18
+ export function resolveConfiguredDefaultRun() {
19
+ if (!modelsRepo.readIfPresent()?.default)
20
+ return null;
21
+ return getDefaultSelection();
88
22
  }
89
- /**
90
- * The Anthropic route (base URL + credentials) one attempt runs under. Per attempt, because a
91
- * fallback may be a different mode entirely, and per run because the project/trigger it carries
92
- * select the gateway's account: resolving this never writes a daemon global (K-053), the value
93
- * reaches exactly the one child env it was resolved for.
94
- */
95
- export function resolveRunRoute(attempt, context = {}) {
23
+ /** Resolve the route per run, never by changing the daemon's environment. */
24
+ export function resolveRunRoute(selection, context = {}) {
96
25
  const metadata = {};
97
26
  if (context.project)
98
27
  metadata.project = context.project;
99
28
  if (context.trigger)
100
29
  metadata.trigger = context.trigger;
101
- return resolveModeEnv(attempt.mode || 'api', Object.keys(metadata).length > 0 ? metadata : undefined);
30
+ return resolveModeEnv(selection.mode || 'api', Object.keys(metadata).length ? metadata : undefined);
102
31
  }
103
- /** The route one attempt of `request` runs under — the run's own choice, and what a command on the
104
- * same engine has to ask for to be handed that engine. */
105
- export function requestRoute(request, attempt) {
32
+ export function requestRoute(request, selection) {
106
33
  const { project, trigger, routeTrigger } = request.context;
107
- return resolveRunRoute(attempt, { project, trigger: routeTrigger ?? trigger });
34
+ return resolveRunRoute(selection, { project, trigger: routeTrigger ?? trigger });
108
35
  }
109
- /** The backend a channel's next run will use. Replaces `getActiveBackend()` on the run path. */
110
36
  export function resolveRunBackend(query = {}) {
111
- return resolveRunConfig(query).profile.backend;
112
- }
113
- /** The extraOption flag that would out-rank an explicitly chosen thinking level, per backend.
114
- * Both adapters let extraOption win (claude appends it after `--effort`, PI reads
115
- * `extraOption['--thinking']` in preference to the spec), so a profile carrying one would make the
116
- * user's choice silently do nothing. */
117
- const THINKING_FLAG_BY_BACKEND = { claude: '--effort', pi: '--thinking' };
118
- /**
119
- * The profile a run actually executes: the resolved profile with the channel's selection
120
- * (model / provider / thinking) applied to its primary attempt.
121
- *
122
- * What each field does:
123
- * - `model` — replaces the primary model (this is `!model`, unchanged).
124
- * - `mode` — which gateway route of the SAME endpoint bills the turn (anthropic `plan` vs `api`).
125
- * - `provider` — PI only. It selects both the request protocol and the gateway endpoint, so the
126
- * route is re-derived with it (overriding any `mode` above), and the profile's `maxOutputTokens`
127
- * is dropped: that cap was stated for the profile's own model and says nothing about the one now
128
- * selected.
129
- * - `thinking` — replaces the level AND removes the profile's own thinking flag from extraOption,
130
- * which both adapters would otherwise let win over the selection.
131
- *
132
- * The fallback chain is deliberately untouched. It is the profile's stated recovery path for when
133
- * the primary model is unavailable, not a second model choice the user made — overriding it too
134
- * would mean a selection on a rate-limited channel silently disabled the profile's own escape.
135
- */
136
- export function effectiveProfile(config) {
137
- const override = config.override;
138
- if (!override || Object.keys(override).length === 0)
139
- return config.profile;
140
- const profile = { ...config.profile };
141
- if (override.model)
142
- profile.model = override.model;
143
- // The route is chosen WITHIN the profile's endpoint (same credentials, same provider), so it is
144
- // applied before the provider branch below — which re-derives the route when the endpoint itself
145
- // moves and therefore has the last word.
146
- if (override.mode)
147
- profile.mode = override.mode;
148
- // A claude profile has no provider to select — the write path rejects one, and a stale value
149
- // from an older state file is ignored here rather than re-labelling the run's rate-limit identity.
150
- if (profile.backend === 'pi' && override.provider && override.provider !== config.profile.provider) {
151
- profile.provider = override.provider;
152
- profile.mode = resolveModeForProvider(profile.backend, override.provider);
153
- profile.maxOutputTokens = null;
154
- }
155
- if (override.thinking) {
156
- profile.thinking = override.thinking;
157
- const flag = THINKING_FLAG_BY_BACKEND[profile.backend];
158
- if (flag && flag in profile.extraOption) {
159
- profile.extraOption = { ...profile.extraOption };
160
- delete profile.extraOption[flag];
161
- }
162
- }
163
- return profile;
37
+ return resolveRunSelection(query).backend;
164
38
  }
@@ -1,6 +1,6 @@
1
1
  import type { EngineSpec } from '../../agent-adapter/types.js';
2
2
  import type { ModeEnv } from './mode-env.js';
3
- import type { RunAttemptConfig } from '../agents/profile-manager.js';
3
+ import type { EngineSelection } from '../agents/engine-selection.js';
4
4
  import type { RunRequest } from './request.js';
5
5
  /** Session scope and current policy evaluated at spawn time, after agent assignment. */
6
6
  export interface PluginScope {
@@ -22,19 +22,19 @@ export declare function filterScopedPlugins(dirs: string[] | undefined, scope: P
22
22
  * convention `/m/<mode>/<endpoint>`. The `mode` selects the gateway route (gateway.yaml owns the
23
23
  * upstream + keys); the `provider` is both the PI `--provider` and the gateway endpoint segment.
24
24
  *
25
- * `provider` is required for pi profiles (validated at load time — no default, no fallback). Returns
26
- * undefined when `mode` is absent — the PI adapter then falls back to the default `/<provider>` path
27
- * (direct per-provider routing, no `/m/` mode indirection).
28
- *
29
- * Keeping this derivation in code (not in the profile) means profiles only carry the logical
30
- * `mode` name; no gateway path string leaks into profiles.json.
25
+ * The selection carries a logical mode, not a gateway URL. An absent mode uses direct routing.
31
26
  */
32
27
  export declare function buildPiGatewaySubPath(mode: string | null, provider: string): string | undefined;
28
+ /** Environment comes only from the resolved route, not user configuration. */
29
+ export declare function routeEnvFields(route: ModeEnv | undefined): {
30
+ sets?: Record<string, string>;
31
+ unsets?: string[];
32
+ };
33
33
  /**
34
34
  * Group the resolved inputs into the backend-neutral {@link EngineSpec}.
35
35
  * Pure re-grouping: every value, condition and defaulting rule is the original flat builder's.
36
36
  */
37
- export declare function buildEngineSpec(request: RunRequest, attempt: RunAttemptConfig, opts?: {
37
+ export declare function buildEngineSpec(request: RunRequest, attempt: EngineSelection, opts?: {
38
38
  route?: ModeEnv;
39
39
  executionId?: string | null;
40
40
  }): EngineSpec;
@@ -35,12 +35,7 @@ export function filterScopedPlugins(dirs, scope) {
35
35
  * convention `/m/<mode>/<endpoint>`. The `mode` selects the gateway route (gateway.yaml owns the
36
36
  * upstream + keys); the `provider` is both the PI `--provider` and the gateway endpoint segment.
37
37
  *
38
- * `provider` is required for pi profiles (validated at load time — no default, no fallback). Returns
39
- * undefined when `mode` is absent — the PI adapter then falls back to the default `/<provider>` path
40
- * (direct per-provider routing, no `/m/` mode indirection).
41
- *
42
- * Keeping this derivation in code (not in the profile) means profiles only carry the logical
43
- * `mode` name; no gateway path string leaks into profiles.json.
38
+ * The selection carries a logical mode, not a gateway URL. An absent mode uses direct routing.
44
39
  */
45
40
  export function buildPiGatewaySubPath(mode, provider) {
46
41
  if (!mode)
@@ -48,20 +43,14 @@ export function buildPiGatewaySubPath(mode, provider) {
48
43
  return `/m/${mode}/${provider}`;
49
44
  }
50
45
  // --- Spec helpers ---
51
- function spawnContext(request, executionId) {
46
+ function spawnContext(request, attempt, executionId) {
52
47
  return {
53
- // `|| null`, not `?? null`: a synthesized profile (a subagent child, a fixture) carries an
54
- // empty name because it was never looked up by name, and the child env must stay as it was
55
- // before the run model — CORTEX_PROFILE absent, not set to an invented profile name.
56
- profile: request.profile.name || null,
48
+ selection: { ...attempt },
57
49
  project: request.context.project ?? null,
58
50
  trackSessionId: request.session.sessionId ?? request.session.backendSessionId ?? null,
59
51
  executionId: executionId ?? null,
60
52
  };
61
53
  }
62
- function hasSpawnContext(context) {
63
- return Object.values(context).some(Boolean);
64
- }
65
54
  /** A spec's tool surface is either a canonical list or Claude's raw `--tools` string. */
66
55
  function canonicalToolList(request) {
67
56
  return Array.isArray(request.spec.tools) ? request.spec.tools : undefined;
@@ -77,7 +66,6 @@ function spawnPolicy(request) {
77
66
  allowlist: request.policy.mcpToolAllowlist === undefined
78
67
  ? undefined : canonicalizeMcpToolAllowlist(request.policy.mcpToolAllowlist),
79
68
  configPaths: request.isolation?.mcpConfigPaths,
80
- browserCdpEndpoint: request.policy.browserCdpEndpoint ?? undefined,
81
69
  },
82
70
  flags: {
83
71
  // The request states what the run WANTS; the spec states what the engine is TOLD. `hooks`
@@ -129,20 +117,17 @@ function routeEnvSets(route) {
129
117
  }
130
118
  return sets;
131
119
  }
132
- /** A route fully decides the base URL, so an absent one means "delete": otherwise this spawn
133
- * inherits whatever mode configured the daemon last. A key the profile set explicitly is never
134
- * deleted — profile configuration outranks the mode's delete intent. */
135
- function routeEnvDeletes(route, extraEnv) {
120
+ /** An absent route base URL must not inherit a previous daemon route. */
121
+ function routeEnvDeletes(route) {
136
122
  const deletes = ROUTE_CREDENTIAL_KEYS.filter(key => route[key] === null);
137
123
  if (!route.ANTHROPIC_BASE_URL)
138
124
  deletes.push('ANTHROPIC_BASE_URL');
139
- return deletes.filter(key => !extraEnv || !(key in extraEnv));
125
+ return deletes;
140
126
  }
141
- /** Per-spawn env: the route's sets first, then the profile's extraEnv (last-wins), then the
142
- * route's deletes. An absent route states no routing opinion and touches neither channel. */
143
- function routeEnvFields(route, extraEnv) {
144
- const sets = { ...(route ? routeEnvSets(route) : {}), ...extraEnv };
145
- const unsets = route ? routeEnvDeletes(route, extraEnv) : [];
127
+ /** Environment comes only from the resolved route, not user configuration. */
128
+ export function routeEnvFields(route) {
129
+ const sets = route ? routeEnvSets(route) : {};
130
+ const unsets = route ? routeEnvDeletes(route) : [];
146
131
  return {
147
132
  sets: Object.keys(sets).length > 0 ? sets : undefined,
148
133
  unsets: unsets.length > 0 ? unsets : undefined,
@@ -166,13 +151,13 @@ function backendField(request, attempt) {
166
151
  export function buildEngineSpec(request, attempt, opts = {}) {
167
152
  const { route, executionId = null } = opts;
168
153
  const mcpComposition = resolveMcpComposition(request.policy.mcpComposition);
169
- const context = spawnContext(request, executionId);
154
+ const context = spawnContext(request, attempt, executionId);
170
155
  const appendSystemPrompt = composeSystemPrompt(request.spec, {
171
156
  rules: globalRuleBodies(request.policy.loadRules !== false),
172
157
  });
173
158
  const plugins = pluginFields(request, attempt, mcpComposition);
174
159
  const policy = spawnPolicy(request);
175
- const routeEnv = routeEnvFields(route, attempt.extraEnv);
160
+ const routeEnv = routeEnvFields(route);
176
161
  const provider = attempt.backend === 'pi' ? attempt.provider || undefined : undefined;
177
162
  return {
178
163
  engineKey: request.session.engineKey || request.context.channel || 'default',
@@ -185,7 +170,8 @@ export function buildEngineSpec(request, attempt, opts = {}) {
185
170
  id: attempt.model,
186
171
  provider,
187
172
  thinking: attempt.thinking || undefined,
188
- maxOutputTokens: attempt.backend === 'pi' ? attempt.maxOutputTokens ?? undefined : undefined,
173
+ benchmarkMaxOutputTokens: attempt.backend === 'pi' && request.benchmark?.evidenceContext
174
+ ? request.benchmarkMaxOutputTokens : undefined,
189
175
  },
190
176
  prompt: {
191
177
  system: typeof request.spec.systemPrompt === 'string' ? request.spec.systemPrompt : undefined,
@@ -210,7 +196,7 @@ export function buildEngineSpec(request, attempt, opts = {}) {
210
196
  sets: routeEnv.sets,
211
197
  unsets: routeEnv.unsets,
212
198
  pinned: request.isolation?.pinnedEnv,
213
- context: hasSpawnContext(context) ? context : undefined,
199
+ context,
214
200
  },
215
201
  route: {
216
202
  anthropicBaseUrl: route?.ANTHROPIC_BASE_URL,
@@ -223,8 +209,6 @@ export function buildEngineSpec(request, attempt, opts = {}) {
223
209
  callbackSource: request.context.callbackSource ?? undefined,
224
210
  scheduleTaskId: request.context.scheduleTaskId ?? undefined,
225
211
  },
226
- extraOption: attempt.extraOption && Object.keys(attempt.extraOption).length > 0
227
- ? attempt.extraOption : undefined,
228
212
  backend: backendField(request, attempt),
229
213
  process: policy.process,
230
214
  };
@@ -1,2 +1,2 @@
1
- export type { AttemptLabel, RunEvent, RunPhase } from '../../agent-adapter/run-events.js';
1
+ export type { RunEvent, RunPhase } from '../../agent-adapter/run-events.js';
2
2
  export { toRunEvent } from '../../agent-adapter/run-events.js';
@@ -1,43 +1,11 @@
1
- import type { ResolvedProfileConfig, RunAttemptConfig } from '../agents/profile-manager.js';
1
+ import type { EngineSelection } from '../agents/engine-selection.js';
2
2
  import { configIsRateLimited, resolveRateLimitProvider } from '../agents/provider-run-lifecycle.js';
3
3
  export { configIsRateLimited, rateLimitedResult, resolveRateLimitProvider } from '../agents/provider-run-lifecycle.js';
4
4
  export { isRetryableError, isRetryableResult } from './retryable-errors.js';
5
- /**
6
- * The attempts a run may make, in order: the profile itself, then its declared fallbacks.
7
- *
8
- * The head is the profile's own engine selection with `name`/`fallback` dropped — a profile IS its
9
- * first attempt, which is why `ResolvedProfileConfig` extends {@link RunAttemptConfig}. Building
10
- * the list here (rather than at each caller) is what makes "attempt index" a meaningful number.
11
- */
12
- export declare function planAttempts(profile: ResolvedProfileConfig): RunAttemptConfig[];
13
- /** How an attempt is named in logs and in the fallback notice the user reads. Takes only the two
14
- * fields it prints so a caller holding a partial config can still label it. */
15
- export declare function attemptLabel(attempt: Pick<RunAttemptConfig, 'model' | 'mode'>): string;
16
- /**
17
- * True when every attempt in the profile's chain is currently rate-limited, so a job runner can
18
- * decline to claim work instead of spawning a backend that will only come back 429.
19
- * Cheap-exits on the global throttle flag: with nothing throttled there is nothing to check.
20
- */
21
- export declare function allConfigsRateLimited(profileName: string | null): boolean;
22
- /**
23
- * Whether this attempt should be skipped without spawning. A user-initiated run always spawns:
24
- * the person is waiting, and a stale throttle entry must not silently swallow their turn.
25
- */
26
- export declare function shouldSkipAttempt(attempt: Parameters<typeof configIsRateLimited>[0], opts: {
5
+ /** A person waiting on a run bypasses cached throttle state. */
6
+ export declare function shouldSkipAttempt(selection: Parameters<typeof configIsRateLimited>[0], opts: {
27
7
  isUserInitiated?: boolean;
28
8
  }): boolean;
29
- /** The provider an attempt's rate-limit windows and cost rows are attributed to. */
30
- export declare function attemptProvider(attempt: Parameters<typeof resolveRateLimitProvider>[0]): string;
31
- /** The credential an attempt ran on: Claude's `api` mode uses the API key and its other modes the
32
- * subscription. A PI provider's credential type is not visible from the attempt. */
33
- export declare function attemptAuthType(attempt: Pick<RunAttemptConfig, 'backend' | 'mode'>): 'oauth' | 'api_key' | null;
34
- /**
35
- * The same attribution, but honest about not knowing: null when the attempt carries no engine
36
- * selection at all.
37
- *
38
- * An unknown profile name deliberately resolves to a synthetic config with an empty model
39
- * (`config-resolver.syntheticProfile`) so the execution record can be opened with a truthful
40
- * backend and the run itself rejects the name. Attributing that attempt's failure to a provider
41
- * would open an outage window against a provider that was never called.
42
- */
43
- export declare function attemptProviderOrNull(attempt: RunAttemptConfig): string | null;
9
+ export declare function attemptProvider(selection: Parameters<typeof resolveRateLimitProvider>[0]): string;
10
+ export declare function attemptAuthType(selection: Pick<EngineSelection, 'backend' | 'mode'>): 'oauth' | 'api_key' | null;
11
+ export declare function attemptProviderOrNull(selection: EngineSelection): string | null;
@@ -1,80 +1,18 @@
1
- //
2
- // A run is not one call to a backend: a profile may name fallbacks, and each attempt can be
3
- // skipped before it spawns (its provider/mode is already rate-limited) or retired after it
4
- // returns (rate-limited result, transient error). This module owns that sequence and nothing
5
- // else — no events, no notices, no process. `AgentRun` walks the plan; `notices.ts` narrates it.
6
- import { isThrottled } from '../costs/rate-limit-throttle.js';
7
- import { resolveProfileConfig } from '../agents/profile-manager.js';
8
1
  import { configIsRateLimited, resolveRateLimitProvider } from '../agents/provider-run-lifecycle.js';
9
2
  export { configIsRateLimited, rateLimitedResult, resolveRateLimitProvider } from '../agents/provider-run-lifecycle.js';
10
3
  export { isRetryableError, isRetryableResult } from './retryable-errors.js';
11
- /**
12
- * The attempts a run may make, in order: the profile itself, then its declared fallbacks.
13
- *
14
- * The head is the profile's own engine selection with `name`/`fallback` dropped — a profile IS its
15
- * first attempt, which is why `ResolvedProfileConfig` extends {@link RunAttemptConfig}. Building
16
- * the list here (rather than at each caller) is what makes "attempt index" a meaningful number.
17
- */
18
- export function planAttempts(profile) {
19
- const head = {
20
- model: profile.model,
21
- backend: profile.backend,
22
- mode: profile.mode,
23
- provider: profile.provider,
24
- extraEnv: profile.extraEnv,
25
- extraOption: profile.extraOption,
26
- thinking: profile.thinking,
27
- maxOutputTokens: profile.maxOutputTokens,
28
- };
29
- return [head, ...(profile.fallback ?? [])];
4
+ /** A person waiting on a run bypasses cached throttle state. */
5
+ export function shouldSkipAttempt(selection, opts) {
6
+ return configIsRateLimited(selection) && !opts.isUserInitiated;
30
7
  }
31
- /** How an attempt is named in logs and in the fallback notice the user reads. Takes only the two
32
- * fields it prints so a caller holding a partial config can still label it. */
33
- export function attemptLabel(attempt) {
34
- return `${attempt.model}/${attempt.mode || 'default'}`;
8
+ export function attemptProvider(selection) {
9
+ return resolveRateLimitProvider(selection);
35
10
  }
36
- /**
37
- * True when every attempt in the profile's chain is currently rate-limited, so a job runner can
38
- * decline to claim work instead of spawning a backend that will only come back 429.
39
- * Cheap-exits on the global throttle flag: with nothing throttled there is nothing to check.
40
- */
41
- export function allConfigsRateLimited(profileName) {
42
- if (!isThrottled())
43
- return false;
44
- try {
45
- return planAttempts(resolveProfileConfig(profileName)).every(configIsRateLimited);
46
- }
47
- catch {
48
- return false;
49
- }
50
- }
51
- /**
52
- * Whether this attempt should be skipped without spawning. A user-initiated run always spawns:
53
- * the person is waiting, and a stale throttle entry must not silently swallow their turn.
54
- */
55
- export function shouldSkipAttempt(attempt, opts) {
56
- return configIsRateLimited(attempt) && !opts.isUserInitiated;
57
- }
58
- /** The provider an attempt's rate-limit windows and cost rows are attributed to. */
59
- export function attemptProvider(attempt) {
60
- return resolveRateLimitProvider(attempt);
61
- }
62
- /** The credential an attempt ran on: Claude's `api` mode uses the API key and its other modes the
63
- * subscription. A PI provider's credential type is not visible from the attempt. */
64
- export function attemptAuthType(attempt) {
65
- if (attempt.backend !== 'claude')
11
+ export function attemptAuthType(selection) {
12
+ if (selection.backend !== 'claude')
66
13
  return null;
67
- return attempt.mode === 'api' ? 'api_key' : 'oauth';
14
+ return selection.mode === 'api' ? 'api_key' : 'oauth';
68
15
  }
69
- /**
70
- * The same attribution, but honest about not knowing: null when the attempt carries no engine
71
- * selection at all.
72
- *
73
- * An unknown profile name deliberately resolves to a synthetic config with an empty model
74
- * (`config-resolver.syntheticProfile`) so the execution record can be opened with a truthful
75
- * backend and the run itself rejects the name. Attributing that attempt's failure to a provider
76
- * would open an outage window against a provider that was never called.
77
- */
78
- export function attemptProviderOrNull(attempt) {
79
- return attempt.model ? resolveRateLimitProvider(attempt) : null;
16
+ export function attemptProviderOrNull(selection) {
17
+ return selection.model ? resolveRateLimitProvider(selection) : null;
80
18
  }
@@ -1,7 +1,5 @@
1
1
  import type { AgentResult, ChatNoticeLevel, NoticeAction } from '../../core/types/agent-types.js';
2
2
  import type { ToolUseSubagent } from '../../agent-adapter/normalize/event-types.js';
3
- import type { RunAttemptConfig } from '../agents/profile-manager.js';
4
- import { type FallbackReason } from './retryable-errors.js';
5
3
  /** `API Error:` prose is the backend reporting its own failure, not the agent talking. */
6
4
  export declare function assistantNoticeLevel(text: string): ChatNoticeLevel | undefined;
7
5
  /** A backend's own error text is already user-facing; anything else gets the generic wrapper. */
@@ -19,8 +17,7 @@ export interface NoticeContext {
19
17
  export type NoticeEmit = (text: string, blockId?: string, level?: ChatNoticeLevel, action?: NoticeAction, subagent?: ToolUseSubagent) => void;
20
18
  /**
21
19
  * Tracks error notices within one attempt so terminal handling is durable but not noisy: an
22
- * attempt that already showed an error card does not get a second one, and a fallback opens a
23
- * fresh dedupe window so the new provider's failure is not hidden by the old provider's notice.
20
+ * attempt that already showed an error card does not get a second one.
24
21
  */
25
22
  export declare class AttemptNoticeTracker {
26
23
  private readonly ctx;
@@ -42,13 +39,6 @@ export declare class AttemptNoticeTracker {
42
39
  settleSuccess(): void;
43
40
  private emitTerminal;
44
41
  private emitAutoResume;
45
- /** This attempt is over and another one follows: its held card is now terminal for that
46
- * provider, and the next attempt starts with a clean dedupe window. */
47
- transitionToFallback(current: Pick<RunAttemptConfig, 'model' | 'mode'>, next: Pick<RunAttemptConfig, 'model' | 'mode'>, reason: FallbackReason): void;
48
42
  emitTerminalError(error: unknown): void;
49
- /** A failure the chain chose not to retry is told as is: its message already carries the
50
- * provider's own error and says why nothing was retried, so neither a held card nor an earlier
51
- * error line (which say less) stands in for it, and a rate limit in it is not auto-resumed. */
52
- private emitNotRetried;
53
43
  emitTerminalRateLimit(result: AgentResult): void;
54
44
  }
@@ -2,7 +2,7 @@
2
2
  // Two jobs, both about narration rather than execution:
3
3
  //
4
4
  // 1. Classify assistant prose the backend emits (`API Error:` → an error notice).
5
- // 2. Synthesize lines the backend never sends: "falling back to X", "context compacted",
5
+ // 2. Synthesize lines the backend never sends: "context compacted",
6
6
  // "rate-limited, will auto-resume".
7
7
  //
8
8
  // The subtle part is a HELD rate-limit card. A backend surfaces a 429 as an assistant message
@@ -10,9 +10,8 @@
10
10
  // pause the resume registry already owns (show the auto-resume warning instead). So this sits in
11
11
  // the event path and can swallow a line, not beside it as a passive observer.
12
12
  import { t } from '../../core/i18n.js';
13
- import { isApiRateLimitError, isNotRetriedFailure } from './retryable-errors.js';
13
+ import { isApiRateLimitError } from './retryable-errors.js';
14
14
  import { isProviderRateLimited } from '../costs/rate-limit-throttle.js';
15
- import { attemptLabel } from './fallback.js';
16
15
  /** `API Error:` prose is the backend reporting its own failure, not the agent talking. */
17
16
  export function assistantNoticeLevel(text) {
18
17
  return text.startsWith('API Error:') ? 'error' : undefined;
@@ -23,8 +22,7 @@ export function terminalErrorText(message) {
23
22
  }
24
23
  /**
25
24
  * Tracks error notices within one attempt so terminal handling is durable but not noisy: an
26
- * attempt that already showed an error card does not get a second one, and a fallback opens a
27
- * fresh dedupe window so the new provider's failure is not hidden by the old provider's notice.
25
+ * attempt that already showed an error card does not get a second one.
28
26
  */
29
27
  export class AttemptNoticeTracker {
30
28
  ctx;
@@ -86,17 +84,6 @@ export class AttemptNoticeTracker {
86
84
  }
87
85
  return true;
88
86
  }
89
- /** This attempt is over and another one follows: its held card is now terminal for that
90
- * provider, and the next attempt starts with a clean dedupe window. */
91
- transitionToFallback(current, next, reason) {
92
- this.flushHeldError();
93
- if (this.synthesize) {
94
- const key = reason === 'rate-limited'
95
- ? 'notify.attemptFallback.rateLimited' : 'notify.attemptFallback.transportError';
96
- this.observe(t(key, { from: attemptLabel(current), to: attemptLabel(next) }), undefined, 'warning');
97
- }
98
- this.attemptHasErrorNotice = false;
99
- }
100
87
  emitTerminalError(error) {
101
88
  const value = error;
102
89
  if (value?.cancelled)
@@ -104,26 +91,12 @@ export class AttemptNoticeTracker {
104
91
  const message = typeof value?.message === 'string' && value.message.length > 0
105
92
  ? value.message
106
93
  : String(error);
107
- if (isNotRetriedFailure(error)) {
108
- this.emitNotRetried(message);
109
- return;
110
- }
111
94
  const resumableDirectError = this.ctx.trigger !== 'edit-retry'
112
95
  && isApiRateLimitError(message)
113
96
  && this.emitAutoResume(value?.rateLimitProvider);
114
97
  if (!resumableDirectError)
115
98
  this.emitTerminal(message);
116
99
  }
117
- /** A failure the chain chose not to retry is told as is: its message already carries the
118
- * provider's own error and says why nothing was retried, so neither a held card nor an earlier
119
- * error line (which say less) stands in for it, and a rate limit in it is not auto-resumed. */
120
- emitNotRetried(message) {
121
- this.heldError = null;
122
- if (!this.synthesize || !this.emit)
123
- return;
124
- this.attemptHasErrorNotice = true;
125
- this.emit(terminalErrorText(message), undefined, 'error');
126
- }
127
100
  emitTerminalRateLimit(result) {
128
101
  if (this.emitAutoResume(result.rateLimitProvider))
129
102
  return;
@@ -1,7 +1,7 @@
1
1
  import type { AgentProcessSpawner, McpComposition, UserMessage } from '../../agent-adapter/types.js';
2
2
  import type { AgentResult } from '../../core/types/agent-types.js';
3
3
  import type { ProductionBenchmarkEvidenceContext } from '../benchmark/benchmark-types.js';
4
- import type { ResolvedProfileConfig } from '../agents/profile-manager.js';
4
+ import type { EngineSelection } from '../agents/engine-selection.js';
5
5
  import type { RunEvent } from './events.js';
6
6
  import type { AgentSpec } from './spec-loader.js';
7
7
  /** Re-exported so `@domain/runs/request.js` stays the one import for the request contract; the
@@ -21,7 +21,9 @@ export interface RunRequest {
21
21
  /** Pool key: session id, `thr:<id>:<slot>` or `<sessionId>::hook`. */
22
22
  engineKey: string;
23
23
  };
24
- profile: ResolvedProfileConfig;
24
+ selection: EngineSelection;
25
+ /** Benchmark-only output cap; ignored unless benchmark evidence is present and backend is PI. */
26
+ benchmarkMaxOutputTokens?: number;
25
27
  spec: AgentSpec;
26
28
  /** Working directory the engine runs in. Omitted (undefined) means the server's own cwd, which
27
29
  * is what every surface except a subagent child wants. Mirrors `EngineSpec.cwd` (plan §3.3). */
@@ -65,7 +67,6 @@ export interface RunRequest {
65
67
  settingSources?: string[];
66
68
  mcpComposition: McpComposition;
67
69
  mcpToolAllowlist?: string[];
68
- browserCdpEndpoint?: string | null;
69
70
  captureTranscripts: boolean;
70
71
  };
71
72
  /** Present only on a production benchmark session's runs: the trial facts each attempt is
@@ -3,16 +3,3 @@ export declare function isRetryableResult(result: {
3
3
  rateLimited?: boolean;
4
4
  } | null): boolean;
5
5
  export declare function isRetryableError(error: Error | null | undefined): boolean;
6
- /** Why a retryable outcome moves the chain on to a fallback. */
7
- export type FallbackReason = 'rate-limited' | 'transport-error';
8
- /** A retryable thrown failure is either the provider refusing on quota or the request failing on
9
- * its way (connection reset, 5xx, timeout). Only call this on an `isRetryableError` failure. */
10
- export declare function fallbackReasonOf(error: Error): FallbackReason;
11
- /**
12
- * A retryable failure the chain deliberately did not retry: the attempt had already started a tool
13
- * call, and re-running the turn on a fallback would run that tool again. It ends the turn as a
14
- * plain failure — no fallback, and no automatic resume either, which is what a rate-limit message
15
- * would otherwise get. The message itself says what happened and asks the user to send again.
16
- */
17
- export declare function notRetriedFailure(message: string): Error;
18
- export declare function isNotRetriedFailure(error: unknown): boolean;