@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
@@ -3,15 +3,16 @@ import { scheduleRepo } from '../store/schedule-repo.js';
3
3
  import { normalizeScheduleSpec, parseDayOfWeek, parseDurationMs, ScheduleSpecError, SCHEDULE_TYPES, } from '../domain/scheduling/schedule-spec.js';
4
4
  import { addSchedule, pauseSchedule, resumeSchedule, updateSchedule } from '../domain/scheduling/schedule-ops.js';
5
5
  import { getScheduleHelp } from './cli-help.js';
6
+ import { resolveScheduleSelection } from '../domain/scheduling/schedule-selection.js';
6
7
  // `cortex schedule` shares schedule-ops with the daemon, which watches the file and re-arms changes.
7
8
  // Both writers hold the schedules.json lock across read-modify-write to preserve concurrent changes.
8
9
  const COMMANDS = ['list', 'get', 'add', 'edit', 'pause', 'resume', 'remove'];
9
10
  const VALUE_FLAGS = {
10
11
  '--type': 'type', '--interval': 'interval', '--time': 'time', '--day': 'day', '--delay': 'delay',
11
- '--message': 'message', '--project': 'project', '--profile': 'profile', '--pre-check': 'preCheck',
12
+ '--message': 'message', '--project': 'project', '--model': 'model', '--thinking': 'thinking', '--pre-check': 'preCheck',
12
13
  '--idempotency-key': 'idempotencyKey',
13
14
  };
14
- const SPEC_FLAGS = ['interval', 'time', 'day', 'delay', 'message', 'project', 'profile', 'preCheck'];
15
+ const SPEC_FLAGS = ['interval', 'time', 'day', 'delay', 'message', 'project', 'model', 'thinking', 'preCheck'];
15
16
  const COMMAND_FLAGS = {
16
17
  list: ['project'],
17
18
  get: [],
@@ -43,7 +44,7 @@ function readFlag(command, args, i, flags) {
43
44
  const valid = [...flagNames(COMMAND_FLAGS[command]), ...(command === 'remove' ? ['--dry-run'] : [])];
44
45
  throw new UsageError(`Unknown option for '${command}': '${args[i]}'.`, valid.length ? valid : ['(none)']);
45
46
  }
46
- if (args[i + 1] === undefined)
47
+ if (args[i + 1] === undefined || args[i + 1].startsWith('--'))
47
48
  throw new UsageError(`Missing value for ${args[i]}.`);
48
49
  flags[name] = args[i + 1];
49
50
  }
@@ -86,7 +87,8 @@ async function runAdd({ flags }, repo) {
86
87
  if (!flags.type)
87
88
  throw new UsageError('Missing --type.', [...SCHEDULE_TYPES]);
88
89
  const spec = normalizeScheduleSpec({
89
- type: flags.type, message: flags.message, projectId: flags.project, profile: flags.profile,
90
+ type: flags.type, message: flags.message, projectId: flags.project,
91
+ selection: resolveScheduleSelection(flags.model, flags.thinking),
90
92
  preCheck: flags.preCheck, interval: flags.interval, time: flags.time, dayOfWeek: flags.day, delay: flags.delay,
91
93
  });
92
94
  const allowed = TIMING_FLAGS[spec.type];
@@ -100,7 +102,6 @@ async function runAdd({ flags }, repo) {
100
102
  const EDIT_FIELDS = {
101
103
  message: (message) => ({ message }),
102
104
  project: (projectId) => ({ projectId }),
103
- profile: (profile) => ({ profile }),
104
105
  preCheck: (preCheck) => ({ preCheck }),
105
106
  interval: (value) => ({ intervalMs: parseDurationMs(value, 'interval') }),
106
107
  time: (time) => ({ time }),
@@ -108,7 +109,13 @@ const EDIT_FIELDS = {
108
109
  delay: (value) => ({ runAt: Date.now() + parseDurationMs(value, 'delay') }),
109
110
  };
110
111
  async function runEdit({ id, flags }, repo) {
111
- const patch = Object.assign({}, ...Object.entries(flags).map(([name, value]) => EDIT_FIELDS[name](value)));
112
+ const task = await repo.findTask(id);
113
+ found(task, id);
114
+ const { model, thinking, ...fields } = flags;
115
+ const patch = Object.assign({}, ...Object.entries(fields).map(([name, value]) => EDIT_FIELDS[name](value)));
116
+ const selection = resolveScheduleSelection(model, thinking, task?.selection);
117
+ if (selection)
118
+ patch.selection = selection;
112
119
  return { ok: true, schedule: found(await updateSchedule(repo, id, patch), id) };
113
120
  }
114
121
  async function runRemove({ id, dryRun }, repo) {
@@ -23,7 +23,7 @@ export interface ShutdownHandles {
23
23
  uiHttpServer?: {
24
24
  close(): Promise<void>;
25
25
  } | null;
26
- stopProfileWatcher?: (() => void) | null;
26
+ stopModelsWatcher?: (() => void) | null;
27
27
  stopBoardWatcher?: (() => void) | null;
28
28
  }
29
29
  export declare function shutdownSteps(h: ShutdownHandles): ShutdownStep[];
@@ -9,11 +9,14 @@ import { stopClientManager } from '../domain/remote/client-manager.js';
9
9
  import { stopMachineRegistryWatcher } from '../domain/remote/machine-registry.js';
10
10
  import { stopAllDevicePorts } from '../domain/remote/device-port.js';
11
11
  import { forgetDeviceBrowsers } from '../domain/remote/device-browser.js';
12
+ import { shutdownBrowserBroker } from '../domain/browser/broker.js';
12
13
  import { stopDiskMonitor } from '../domain/monitor/disk-monitor.js';
13
14
  import { stopEventLoopMonitor } from '../domain/monitor/event-loop-monitor.js';
14
15
  import { stopGateway } from '../domain/costs/gateway-manager.js';
15
16
  import { stopBrowser } from '../platform/browser/managed-browser.js';
16
17
  import { stopWaitpointSweep } from '../orchestration/waitpoint-sweep.js';
18
+ import { stopCacheKeepWarm } from '../orchestration/cache-keep-warm.js';
19
+ import { stopClaudeWindowWarmup } from '../orchestration/claude-window-warmup.js';
17
20
  const log = createLogger('shutdown');
18
21
  function serviceSteps(h) {
19
22
  return [
@@ -24,8 +27,10 @@ function serviceSteps(h) {
24
27
  { name: 'agent engines', run: () => engines.closeAll() },
25
28
  { name: 'client manager', run: stopClientManager },
26
29
  { name: 'machine watcher', run: stopMachineRegistryWatcher },
27
- { name: 'profile watcher', run: () => h.stopProfileWatcher?.() },
30
+ { name: 'models watcher', run: () => h.stopModelsWatcher?.() },
28
31
  { name: 'board watcher', run: () => h.stopBoardWatcher?.() },
32
+ // Leases first: their timers would otherwise fire against a browser that is already gone.
33
+ { name: 'browser leases', run: shutdownBrowserBroker },
29
34
  // A Chrome that outlives the daemon keeps the profile locked, so the next launch would attach to
30
35
  // an instance nothing is supervising.
31
36
  { name: 'browser', run: stopBrowser },
@@ -45,6 +50,8 @@ function drainSteps(h) {
45
50
  // its store's flush resolved, losing that write.
46
51
  { name: 'scheduler', run: () => h.scheduler.stop() },
47
52
  { name: 'waitpoint sweep', run: stopWaitpointSweep },
53
+ { name: 'cache keep-warm', run: stopCacheKeepWarm },
54
+ { name: 'claude window warm-up', run: stopClaudeWindowWarmup },
48
55
  // Pending WAL entries survive on disk for the next startup.
49
56
  { name: 'outbound drain loop', run: () => h.outboundQueue.stop() },
50
57
  // SIGTERM landing between `writeFile(tmp)` and `rename(tmp, target)` in atomic-write.ts leaves
@@ -11,6 +11,8 @@ import { isUpdateDevMode } from '../domain/system/server-update-check.js';
11
11
  import { createForwardRoutes } from '../platform/ui-http/port-forward.js';
12
12
  import { createDevicePortRoutes } from '../platform/ui-http/device-ports.js';
13
13
  import { createFileRoutes } from '../platform/ui-http/file-routes.js';
14
+ import { BROWSER_STREAM_PATH, createBrowserStream } from '../platform/ui-http/browser-stream.js';
15
+ import { insertText, isTakenOver, listBrowserSessions, setTakeover, streamPort, } from '../domain/browser/broker.js';
14
16
  import { getOnlineDevices, sendCommand } from '../domain/remote/client-manager.js';
15
17
  import { openDevicePort, closeDevicePort, listDevicePorts } from '../domain/remote/device-port.js';
16
18
  import { accessVerifierFromEnv } from '../platform/ui-http/access-jwt.js';
@@ -99,6 +101,10 @@ export function startUiHttpServer(opts) {
99
101
  : undefined;
100
102
  const verifySession = sessionStore ? (sid) => sessionStore.verify(sid) : undefined;
101
103
  const authorize = createAuthorizer({ getToken, verifySession, verifyAccessJwt });
104
+ // The agent's browser, live in the app: session list, takeover, typed text, and the stream itself.
105
+ const browserStream = createBrowserStream({
106
+ listSessions: listBrowserSessions, streamPort, setTakeover, isTakenOver, insertText,
107
+ });
102
108
  log.info(`Web UI enabled — starting tRPC HTTP+SSE on 127.0.0.1:${port}` +
103
109
  (spaDir ? ` (SPA: ${spaDir})` : ' (SPA: not built — non-tRPC paths 404)') +
104
110
  (initialCorsOrigins.length > 0 ? ` (CORS allow-list: ${initialCorsOrigins.join(', ')})` : '') +
@@ -152,7 +158,9 @@ export function startUiHttpServer(opts) {
152
158
  closeDevicePort,
153
159
  listDevicePorts,
154
160
  }),
161
+ ...browserStream.routes,
155
162
  },
163
+ upgradeRoutes: { [BROWSER_STREAM_PATH]: browserStream },
156
164
  portForward: env.CORTEX_PORT_FORWARD !== '0',
157
165
  });
158
166
  }
@@ -9,7 +9,7 @@ import { conversationHistory } from '../store/conversation-history-repo.js';
9
9
  import { pendingInjectionRepo } from '../store/pending-injection-repo.js';
10
10
  import { sessionStore } from '../store/session-registry-repo.js';
11
11
  import { waitpointRepo } from '../store/waitpoint-repo.js';
12
- import { applyChannelSelection, clearChannelAgentSelection, getActiveProfile, getChannelOverride, getSelectionDefault, resolveBackendForChannel, switchChannelAgent, switchChannelProfile, } from '../domain/agents/index.js';
12
+ import { applyChannelSelection, clearChannelAgentSelection, getModelMemory, getSelectionDefault, resolveBackendForChannel, switchChannelAgent, } from '../domain/agents/index.js';
13
13
  import { getSubagentChildStatuses } from '../domain/agents/subagent/registry.js';
14
14
  import { getCostSummary } from '../domain/costs/cost-tracker.js';
15
15
  import * as executionRegistry from '../domain/executions/registry.js';
@@ -29,10 +29,12 @@ import { cancelChannelRuns, cancelLiveExecution } from '../orchestration/routing
29
29
  import { deliverToSessionDetached } from '../orchestration/session-gateway.js';
30
30
  import { compactSessionContext } from '../orchestration/session-compact.js';
31
31
  import { rewindWebSession } from '../orchestration/session-rewind.js';
32
+ import { snapshotInlineMedia } from '../orchestration/inline-media.js';
32
33
  import { moveDraftAttachments } from './draft-attachments.js';
33
34
  export function buildUiService(w) {
34
35
  return createUiService({
35
36
  checkServerUpdate: () => w.serverUpdateCoordinator.check(),
37
+ resolveMedia: snapshotInlineMedia,
36
38
  projectStore,
37
39
  sessionStore,
38
40
  scheduler: w.scheduler,
@@ -95,26 +97,22 @@ function sessionRunDeps(adapter) {
95
97
  moveDraftAttachments,
96
98
  };
97
99
  }
98
- /** The profile / agent / model a session runs: the same domain rules the chat commands apply. */
100
+ /** The environment and engine a session runs: the shared domain rules. */
99
101
  function sessionSelectionDeps() {
100
102
  return {
101
- switchSessionProfile: (opts) => switchChannelProfile(opts),
102
103
  // A null name is the "follow the global default" row, which clears the channel's selection.
103
104
  switchSessionAgent: async ({ channel, name }) => {
104
105
  if (name === null) {
105
106
  await clearChannelAgentSelection(channel);
106
- return { ok: true, agentName: null, effectiveProfile: getActiveProfile(channel) ?? '', backendChanged: false };
107
+ return { ok: true, agentName: null };
107
108
  }
108
109
  const res = await switchChannelAgent({ channel, name });
109
110
  return res.ok === true
110
- ? { ok: true, agentName: res.agentName, effectiveProfile: res.effectiveProfile, backendChanged: res.backendChanged }
111
- : {
112
- ok: false, agentName: null, effectiveProfile: '', backendChanged: false,
113
- reason: res.reason, currentBackend: res.currentBackend, targetBackend: res.targetBackend,
114
- };
111
+ ? { ok: true, agentName: res.agentName }
112
+ : { ok: false, agentName: null, reason: res.reason };
115
113
  },
116
114
  applySessionSelection: (opts) => applyChannelSelection(opts),
117
- getChannelSelectionOverride: (channel) => getChannelOverride(channel),
115
+ getModelMemory: () => getModelMemory(),
118
116
  // What a draft composer starts on before any session exists.
119
117
  getSelectionDefault: () => getSelectionDefault(),
120
118
  };
@@ -9,7 +9,7 @@ export type CortexEvent = {
9
9
  ts: string;
10
10
  sessionId: string;
11
11
  channel: string;
12
- role: 'user' | 'assistant' | 'tool' | 'worker-progress';
12
+ role: 'user' | 'assistant' | 'thinking' | 'tool' | 'worker-progress';
13
13
  text: string;
14
14
  toolName?: string;
15
15
  toolInput?: string;
@@ -57,6 +57,7 @@ export type CortexEvent = {
57
57
  blockId: string;
58
58
  text: string;
59
59
  seq: number;
60
+ kind?: 'thinking';
60
61
  } | {
61
62
  type: 'session.status';
62
63
  ts: string;
@@ -219,7 +220,7 @@ export type CortexEvent = {
219
220
  } | {
220
221
  type: 'config.changed';
221
222
  ts: string;
222
- section: 'profiles' | 'preferences';
223
+ section: 'models' | 'preferences';
223
224
  } | {
224
225
  type: 'llm.active-count-delta';
225
226
  ts: string;
@@ -43,8 +43,8 @@ export declare class AgentRunner {
43
43
  */
44
44
  private _tryInjectReal;
45
45
  /**
46
- * Resolve what a turn needs but is not part of it — the files, the session record (found or
47
- * created) with its use lease, the browser the session opted into — and open the turn.
46
+ * Resolve what a turn needs but is not part of it — the files and the session record (found or
47
+ * created) with its use lease — and open the turn.
48
48
  */
49
49
  private _executeReal;
50
50
  }
@@ -5,7 +5,8 @@ import * as crypto from 'node:crypto';
5
5
  import { getSessionAsync, setSessionAsync } from '../domain/sessions/session.js';
6
6
  import { sessionStore, effectiveBackendSessionId } from '../store/session-registry-repo.js';
7
7
  import { conversationHistory } from '../store/conversation-history-repo.js';
8
- import { getActiveProfile, resolveBackendForChannel } from '../domain/agents/index.js';
8
+ import { resolveBackendForChannel } from '../domain/agents/index.js';
9
+ import { resolveRunSelection } from '../domain/runs/config-resolver.js';
9
10
  import { registerSessionRecord } from '../domain/sessions/session-lifecycle.js';
10
11
  import { createLogger } from '../core/log.js';
11
12
  import { isDebugMode } from '../core/debug-mode.js';
@@ -15,7 +16,7 @@ import { runRegistry } from '../core/run-registry.js';
15
16
  import { prepareConversationRequest } from './conversation-request.js';
16
17
  import { openTurn, buildInjectDeps } from './turn/turn.js';
17
18
  import { recordHistory } from './transcript-sink.js';
18
- import { acquireSessionUseLease, collectTurnFiles, withTurnBrowser, } from './turn/turn-prep.js';
19
+ import { acquireSessionUseLease, collectTurnFiles, } from './turn/turn-prep.js';
19
20
  import { downloadMessageFiles } from './routing/file-handler.js';
20
21
  import { acquireTurnMutationLock } from './turn-mutation-lock.js';
21
22
  import { isRebuildHeld, refuseTurnForRebuild } from '../domain/system/rebuild-hold.js';
@@ -115,7 +116,7 @@ export class AgentRunner {
115
116
  return tryInjectIntoLiveTurn(buildInjectDeps(sessionId, ctx.adapter), {
116
117
  channel: ctx.channel,
117
118
  sessionId,
118
- profileName: getActiveProfile(ctx.channel),
119
+ selection: resolveRunSelection({ channel: ctx.channel, session: await sessionStore.getById(sessionId) }),
119
120
  text: ctx.userMessage || '',
120
121
  senderId: ctx.message.senderId,
121
122
  ...(ctx.message.systemOrigin ? { systemOrigin: ctx.message.systemOrigin } : {}),
@@ -135,8 +136,8 @@ export class AgentRunner {
135
136
  }
136
137
  }
137
138
  /**
138
- * Resolve what a turn needs but is not part of it — the files, the session record (found or
139
- * created) with its use lease, the browser the session opted into — and open the turn.
139
+ * Resolve what a turn needs but is not part of it — the files and the session record (found or
140
+ * created) with its use lease — and open the turn.
140
141
  */
141
142
  async _executeReal(ctx, mutationRelease, loadPlatformFiles) {
142
143
  const { message, channel, adapter, threadAnchorId, userMessage, agentMessage } = ctx;
@@ -145,7 +146,7 @@ export class AgentRunner {
145
146
  const backend = resolveBackendForChannel(channel);
146
147
  const { lease, backendSessionId } = await bindTurnSession(ctx, backend);
147
148
  const session = lease.session;
148
- await withTurnBrowser({ backend, browser: session.browser ?? null }, (cdpEndpoint) => openTurn({
149
+ await openTurn({
149
150
  channel, adapter, threadAnchorId,
150
151
  session: {
151
152
  sessionId: session.sessionId, backendSessionId,
@@ -164,9 +165,9 @@ export class AgentRunner {
164
165
  prepareRequest: (turnIds) => prepareConversationRequest({
165
166
  ids: turnIds, channel, session, userMessage: agentMessage,
166
167
  files: turnFiles.files, failedFiles: turnFiles.failures,
167
- browserCdpEndpoint: cdpEndpoint, onPromptBuilt: debugPromptRecorder(session.sessionId, channel),
168
+ onPromptBuilt: debugPromptRecorder(session.sessionId, channel),
168
169
  }),
169
- }));
170
+ });
170
171
  }
171
172
  }
172
173
  /** In debug mode, the backend-ready prompt of each turn is kept in the session's history. */
@@ -194,7 +195,7 @@ async function bindTurnSession(ctx, backend) {
194
195
  await registerSessionRecord(sessionStore, {
195
196
  sessionId, channel: ctx.channel, backend,
196
197
  label: ctx.userMessage?.substring(0, 60) ?? null,
197
- profileName: getActiveProfile(ctx.channel),
198
+ selection: resolveRunSelection({ channel: ctx.channel }),
198
199
  projectId: (await ctx.adapter.resolveInboundProject(ctx.channel)) ?? 'general',
199
200
  });
200
201
  await setSessionAsync(ctx.channel, sessionId);
@@ -52,11 +52,23 @@ function subscribeTurns(deps) {
52
52
  tracked.get(event.sessionId)?.turns.push({ status: event.status, finalOutput: event.finalOutput });
53
53
  });
54
54
  }
55
+ function outputCap(value, frozen) {
56
+ if (value === undefined)
57
+ return undefined;
58
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0) {
59
+ throw new BenchmarkSessionError('benchmarkMaxOutputTokens must be a positive safe integer');
60
+ }
61
+ if (value !== frozen) {
62
+ throw new BenchmarkSessionError('benchmarkMaxOutputTokens differs from frozen max_output_tokens');
63
+ }
64
+ return value;
65
+ }
55
66
  async function start(data, deps) {
56
67
  const message = str(data.message);
57
68
  if (!message)
58
69
  throw new BenchmarkSessionError('message required');
59
70
  const context = parseProductionBenchmarkEvidenceContext(data.productionBenchmarkEvidenceContext);
71
+ const cap = outputCap(data.benchmarkMaxOutputTokens, context.model_execution.max_output_tokens);
60
72
  const run = `${context.trial_id}/${context.root_run_id}`;
61
73
  if (startingRuns.has(run) || sessionForRun(context.trial_id, context.root_run_id)) {
62
74
  throw new BenchmarkSessionError(`trial run ${run} already has a session`);
@@ -66,7 +78,7 @@ async function start(data, deps) {
66
78
  subscribeTurns(deps);
67
79
  const { sessionId, channel } = await deps.createSession(str(data.projectId) || 'general');
68
80
  // Bound before the delivery, so the first turn's runs already carry the context.
69
- bindSessionEvidenceContext(sessionId, context);
81
+ bindSessionEvidenceContext(sessionId, context, cap);
70
82
  const entry = { channel, delivering: true, deliveryError: null, turns: [] };
71
83
  tracked.set(sessionId, entry);
72
84
  void deps.deliver(channel, message).then(() => { entry.delivering = false; }, (error) => {
@@ -0,0 +1,11 @@
1
+ import { type BrowserBroker } from '../domain/browser/broker.js';
2
+ export interface BrowserWebhookReply {
3
+ success: boolean;
4
+ data?: unknown;
5
+ error?: string;
6
+ hint?: string;
7
+ code?: string;
8
+ }
9
+ type BrokerSlice = Pick<BrowserBroker, 'leaseBrowser' | 'noteBrowserCommand' | 'agentBrowserRuntime'>;
10
+ export declare function handleBrowserWebhook(data: Record<string, any>, broker?: BrokerSlice): Promise<BrowserWebhookReply>;
11
+ export {};
@@ -0,0 +1,28 @@
1
+ // `/webhook/browser`: the daemon side of `cortex-browser`. The CLI leases the session's browser
2
+ // here, then runs agent-browser itself so its output streams straight to the agent.
3
+ import { BrowserLeaseError, leaseBrowser, noteBrowserCommand, agentBrowserRuntime, } from '../domain/browser/broker.js';
4
+ const defaultBroker = { leaseBrowser, noteBrowserCommand, agentBrowserRuntime };
5
+ function str(value) {
6
+ return typeof value === 'string' ? value.trim() : '';
7
+ }
8
+ export async function handleBrowserWebhook(data, broker = defaultBroker) {
9
+ const sessionId = str(data.sessionId);
10
+ try {
11
+ if (data.action === 'lease') {
12
+ const lease = await broker.leaseBrowser({ sessionId, device: str(data.device) || null });
13
+ const { bin, env } = broker.agentBrowserRuntime();
14
+ return { success: true, data: { ...lease, bin, env } };
15
+ }
16
+ if (data.action === 'report') {
17
+ broker.noteBrowserCommand(sessionId);
18
+ return { success: true };
19
+ }
20
+ return { success: false, error: `unknown action: ${String(data.action)}`, hint: 'valid actions: lease, report' };
21
+ }
22
+ catch (e) {
23
+ if (e instanceof BrowserLeaseError) {
24
+ return { success: false, error: e.message, code: e.code, ...(e.hint ? { hint: e.hint } : {}) };
25
+ }
26
+ return { success: false, error: e.message };
27
+ }
28
+ }
@@ -0,0 +1,77 @@
1
+ import { type Session } from '../store/session-registry-repo.js';
2
+ import type { EngineSelection } from '../domain/agents/engine-selection.js';
3
+ import { type CacheRefreshLaunch, type CacheRefreshResult } from '../agent-adapter/claude/cache-refresh.js';
4
+ import { type WorkerView } from './team-state.js';
5
+ export declare const KEEP_WARM_SWEEP_MS: number;
6
+ /** Refresh once the cache is this old: ten minutes short of its one-hour lifetime. */
7
+ export declare const KEEP_WARM_REFRESH_AGE_MS: number;
8
+ /** Past this the cache is presumed expired (a restart lost the refresh record, or a sweep missed
9
+ * the window). The window is wider than the sweep interval, so every pass-through is caught once. */
10
+ export declare const KEEP_WARM_MAX_AGE_MS: number;
11
+ /** Below this a cold rewrite is cheap enough that keeping the cache is not worth a request. */
12
+ export declare const KEEP_WARM_MIN_CONTEXT_TOKENS = 100000;
13
+ export type KeepWarmSettings = {
14
+ hours: number;
15
+ subscriptionModes: readonly string[];
16
+ };
17
+ export interface KeepWarmTarget {
18
+ session: Session;
19
+ backendSessionId: string;
20
+ selection: EngineSelection;
21
+ }
22
+ export interface KeepWarmCostEntry {
23
+ project: string;
24
+ trigger: 'cache-refresh';
25
+ cost_usd: number;
26
+ backend: 'claude';
27
+ mode: string;
28
+ source: 'estimate';
29
+ input_tokens: number;
30
+ output_tokens: number;
31
+ prompt_tokens: number;
32
+ cache_read_tokens: number;
33
+ cache_creation_tokens: number;
34
+ provider: 'anthropic';
35
+ model: string;
36
+ session_id: string;
37
+ }
38
+ export interface KeepWarmDeps {
39
+ listSessions(): Promise<Session[]>;
40
+ settings(): KeepWarmSettings;
41
+ /** The selection the session's next turn would run under; throws when it cannot resume there. */
42
+ selection(session: Session): EngineSelection;
43
+ transcriptPath(backendSessionId: string): string;
44
+ lastActivity(transcriptPath: string): number | null;
45
+ lastTouch(transcriptPath: string, backendSessionId: string): number | null;
46
+ /** Something will still wake the session: an open waitpoint, a busy worker, a background run. */
47
+ hasWakeSource(session: Session): Promise<boolean>;
48
+ /** A turn is live or queued on the channel. A background hold alone is not busy. */
49
+ busy(channel: string): boolean;
50
+ runQueued<T>(channel: string, fn: () => Promise<T>): Promise<T>;
51
+ refresh(target: KeepWarmTarget): Promise<CacheRefreshResult>;
52
+ noteRefresh(backendSessionId: string, at: number): void;
53
+ recordCost(entry: KeepWarmCostEntry): Promise<void>;
54
+ now(): number;
55
+ }
56
+ /** The session's refresh target when it is due one now, else null. Cheapest checks first. */
57
+ export declare function dueTarget(session: Session, deps: KeepWarmDeps, settings: KeepWarmSettings): Promise<KeepWarmTarget | null>;
58
+ /** One pass, one session at a time. Returns how many sessions were refreshed. */
59
+ export declare function sweepCacheKeepWarm(deps?: KeepWarmDeps): Promise<number>;
60
+ export interface WakeSourceDeps {
61
+ backgroundRuns(sessionId: string): boolean;
62
+ openWaitpoints(sessionId: string, channel: string): Promise<number>;
63
+ isLead(session: Session): boolean;
64
+ team(leadSessionId: string): Promise<WorkerView[]>;
65
+ }
66
+ /** Whether something will still wake the session: a background `agent` run of its own, an open
67
+ * waitpoint it owns, or (as a lead) a worker that has not reported back. */
68
+ export declare function hasWakeSource(session: Session, deps?: WakeSourceDeps): Promise<boolean>;
69
+ /** The fork's launch, built from the request the session's next turn would run under: same agent,
70
+ * selection, policy and route, so its argv and env match that turn's. Its execution id is its own. */
71
+ export declare function keepWarmLaunch(target: KeepWarmTarget): CacheRefreshLaunch;
72
+ export declare const productionKeepWarmDeps: KeepWarmDeps;
73
+ /** Start the periodic keep-warm sweep. `cacheKeepWarmHours` is read on every pass, so turning it
74
+ * off or on takes effect without a restart. */
75
+ export declare function startCacheKeepWarm(): void;
76
+ /** Stop the loop before the stores flush: a pass records costs. */
77
+ export declare function stopCacheKeepWarm(): void;