@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.
- package/README.md +76 -50
- package/defaults/board/board.css +140 -62
- package/defaults/board/scaffold.html +36 -13
- package/defaults/config/environments/creative.json +0 -1
- package/defaults/config/environments/main.json +1 -2
- package/defaults/plugins/cortex-board/skills/board/SKILL.md +30 -22
- package/defaults/plugins/cortex-system/plugin.json +2 -2
- package/defaults/plugins/cortex-system/skills/browser/SKILL.md +56 -0
- package/dist/agent-adapter/claude/adapter.d.ts +2 -5
- package/dist/agent-adapter/claude/adapter.js +6 -5
- package/dist/agent-adapter/claude/assistant-blocks.d.ts +5 -0
- package/dist/agent-adapter/claude/assistant-blocks.js +61 -0
- package/dist/agent-adapter/claude/cache-refresh.d.ts +58 -0
- package/dist/agent-adapter/claude/cache-refresh.js +145 -0
- package/dist/agent-adapter/claude/cache-touch.d.ts +12 -0
- package/dist/agent-adapter/claude/cache-touch.js +75 -0
- package/dist/agent-adapter/claude/event-parser.d.ts +8 -3
- package/dist/agent-adapter/claude/event-parser.js +33 -17
- package/dist/agent-adapter/claude/event-translator.d.ts +2 -0
- package/dist/agent-adapter/claude/event-translator.js +2 -0
- package/dist/agent-adapter/claude/session-options.d.ts +6 -13
- package/dist/agent-adapter/claude/session-options.js +2 -13
- package/dist/agent-adapter/claude/spawn-args.d.ts +4 -21
- package/dist/agent-adapter/claude/spawn-args.js +17 -24
- package/dist/agent-adapter/claude/transcript-clear.d.ts +42 -0
- package/dist/agent-adapter/claude/transcript-clear.js +217 -0
- package/dist/agent-adapter/claude/turn-machine.d.ts +3 -2
- package/dist/agent-adapter/claude/turn-machine.js +21 -68
- package/dist/agent-adapter/claude/window-warmup.d.ts +13 -0
- package/dist/agent-adapter/claude/window-warmup.js +38 -0
- package/dist/agent-adapter/continuation-phase.js +3 -0
- package/dist/agent-adapter/normalize/event-types.d.ts +8 -0
- package/dist/agent-adapter/pi/adapter.d.ts +0 -1
- package/dist/agent-adapter/pi/adapter.js +5 -13
- package/dist/agent-adapter/pi/event-parser.d.ts +1 -1
- package/dist/agent-adapter/pi/event-parser.js +43 -27
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +1 -1
- package/dist/agent-adapter/pi/pi-session.d.ts +2 -0
- package/dist/agent-adapter/pi/pi-session.js +15 -0
- package/dist/agent-adapter/pi/providers-config.d.ts +2 -2
- package/dist/agent-adapter/pi/providers-config.js +1 -1
- package/dist/agent-adapter/pi/quota-sink.d.ts +3 -3
- package/dist/agent-adapter/pi/quota-sink.js +3 -3
- package/dist/agent-adapter/pi/runtime.js +6 -1
- package/dist/agent-adapter/pi/session-options.d.ts +9 -13
- package/dist/agent-adapter/pi/session-options.js +12 -25
- package/dist/agent-adapter/run-events.d.ts +11 -10
- package/dist/agent-adapter/run-events.js +2 -0
- package/dist/agent-adapter/types.d.ts +5 -4
- package/dist/client-bundle/manifest.json +2 -2
- package/dist/core/codex-quota.d.ts +1 -1
- package/dist/core/codex-quota.js +1 -1
- package/dist/core/gateway-generator.d.ts +9 -11
- package/dist/core/gateway-generator.js +31 -58
- package/dist/core/locales/en.d.ts +51 -77
- package/dist/core/locales/slices/commands.d.ts +26 -31
- package/dist/core/locales/slices/commands.js +54 -64
- package/dist/core/locales/slices/init.d.ts +8 -19
- package/dist/core/locales/slices/init.js +17 -53
- package/dist/core/locales/slices/interactions.d.ts +3 -3
- package/dist/core/locales/slices/interactions.js +6 -6
- package/dist/core/locales/slices/notices.d.ts +1 -3
- package/dist/core/locales/slices/notices.js +2 -6
- package/dist/core/locales/slices/scheduling.d.ts +9 -9
- package/dist/core/locales/slices/scheduling.js +18 -18
- package/dist/core/locales/slices/status.d.ts +0 -4
- package/dist/core/locales/slices/status.js +0 -8
- package/dist/core/locales/slices/tui.d.ts +0 -1
- package/dist/core/locales/slices/tui.js +0 -2
- package/dist/core/locales/slices/uimsg.d.ts +4 -7
- package/dist/core/locales/slices/uimsg.js +9 -15
- package/dist/core/models-generator.d.ts +29 -0
- package/dist/core/models-generator.js +82 -0
- package/dist/core/paths.d.ts +1 -1
- package/dist/core/paths.js +1 -1
- package/dist/core/settings-spec.d.ts +25 -0
- package/dist/core/settings-spec.js +34 -0
- package/dist/core/status-format.d.ts +3 -2
- package/dist/core/status-format.js +2 -2
- package/dist/core/types/environment-types.d.ts +0 -2
- package/dist/domain/agents/agent-state.d.ts +11 -56
- package/dist/domain/agents/agent-state.js +48 -115
- package/dist/domain/agents/agent-switch.d.ts +2 -24
- package/dist/domain/agents/agent-switch.js +9 -72
- package/dist/domain/agents/config.d.ts +11 -61
- package/dist/domain/agents/config.js +47 -154
- package/dist/domain/agents/engine-selection.d.ts +21 -0
- package/dist/domain/agents/engine-selection.js +37 -0
- package/dist/domain/agents/environments/registry.js +2 -1
- package/dist/domain/agents/environments/resolve.js +0 -1
- package/dist/domain/agents/environments/schema.d.ts +0 -1
- package/dist/domain/agents/environments/schema.js +0 -1
- package/dist/domain/agents/index.d.ts +2 -1
- package/dist/domain/agents/index.js +3 -7
- package/dist/domain/agents/model-selection.d.ts +18 -70
- package/dist/domain/agents/model-selection.js +100 -150
- package/dist/domain/agents/models.d.ts +12 -0
- package/dist/domain/agents/models.js +94 -0
- package/dist/domain/agents/subagent/registry.d.ts +2 -0
- package/dist/domain/agents/subagent/registry.js +8 -0
- package/dist/domain/agents/subagent/runner.d.ts +5 -5
- package/dist/domain/agents/subagent/runner.js +12 -35
- package/dist/domain/auth/auth-status.d.ts +4 -4
- package/dist/domain/auth/auth-status.js +17 -28
- package/dist/domain/auth/gateway-sync.d.ts +6 -26
- package/dist/domain/auth/gateway-sync.js +31 -75
- package/dist/domain/benchmark/identity.d.ts +3 -5
- package/dist/domain/benchmark/identity.js +0 -1
- package/dist/domain/benchmark/production-attempt-identity.d.ts +6 -5
- package/dist/domain/benchmark/production-attempt-identity.js +32 -35
- package/dist/domain/benchmark/session-evidence.d.ts +2 -1
- package/dist/domain/benchmark/session-evidence.js +8 -1
- package/dist/domain/browser/broker.d.ts +99 -0
- package/dist/domain/browser/broker.js +487 -0
- package/dist/domain/costs/claude-account.js +21 -0
- package/dist/domain/costs/rate-limit-throttle.js +3 -1
- package/dist/domain/costs/reset-account.d.ts +2 -0
- package/dist/domain/costs/usage-service.d.ts +1 -1
- package/dist/domain/costs/usage-service.js +20 -7
- package/dist/domain/mcp/tools/context.d.ts +5 -6
- package/dist/domain/mcp/tools/context.js +17 -3
- package/dist/domain/mcp/tools/subagent.js +1 -1
- package/dist/domain/mcp/tools/ui-file.js +1 -1
- package/dist/domain/pi-providers/custom-provider-model.d.ts +1 -1
- package/dist/domain/pi-providers/custom-provider-model.js +1 -1
- package/dist/domain/remote/device-browser.js +1 -1
- package/dist/domain/remote/device-chrome-commands.js +2 -0
- package/dist/domain/remote/device-port.js +2 -2
- package/dist/domain/runs/attempt.d.ts +3 -3
- package/dist/domain/runs/attempt.js +2 -3
- package/dist/domain/runs/builders.d.ts +4 -4
- package/dist/domain/runs/builders.js +4 -5
- package/dist/domain/runs/compact.d.ts +4 -17
- package/dist/domain/runs/compact.js +14 -56
- package/dist/domain/runs/config-resolver.d.ts +15 -83
- package/dist/domain/runs/config-resolver.js +24 -150
- package/dist/domain/runs/engine-spec.d.ts +8 -8
- package/dist/domain/runs/engine-spec.js +15 -31
- package/dist/domain/runs/events.d.ts +1 -1
- package/dist/domain/runs/fallback.d.ts +6 -38
- package/dist/domain/runs/fallback.js +10 -72
- package/dist/domain/runs/notices.d.ts +1 -11
- package/dist/domain/runs/notices.js +3 -30
- package/dist/domain/runs/request.d.ts +4 -3
- package/dist/domain/runs/retryable-errors.d.ts +0 -13
- package/dist/domain/runs/retryable-errors.js +0 -17
- package/dist/domain/runs/run.d.ts +12 -42
- package/dist/domain/runs/run.js +40 -147
- package/dist/domain/runs/service.d.ts +1 -1
- package/dist/domain/runs/service.js +8 -3
- package/dist/domain/runs/spec-loader.d.ts +1 -1
- package/dist/domain/runs/spend.d.ts +1 -1
- package/dist/domain/runs/spend.js +1 -1
- package/dist/domain/scheduling/jobs/scheduled-task.d.ts +3 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +25 -19
- package/dist/domain/scheduling/schedule-ops.d.ts +0 -1
- package/dist/domain/scheduling/schedule-ops.js +2 -5
- package/dist/domain/scheduling/schedule-selection.d.ts +3 -0
- package/dist/domain/scheduling/schedule-selection.js +16 -0
- package/dist/domain/scheduling/schedule-spec.d.ts +6 -5
- package/dist/domain/scheduling/schedule-spec.js +6 -6
- package/dist/domain/scheduling/scheduler.d.ts +3 -1
- package/dist/domain/scheduling/scheduler.js +22 -21
- package/dist/domain/sessions/session-hooks.d.ts +5 -4
- package/dist/domain/sessions/session-hooks.js +15 -33
- package/dist/domain/sessions/session-lifecycle.d.ts +19 -51
- package/dist/domain/sessions/session-lifecycle.js +34 -96
- package/dist/domain/system/doctor.d.ts +3 -3
- package/dist/domain/system/doctor.js +22 -26
- package/dist/domain/system/own-bin-path.d.ts +13 -0
- package/dist/domain/system/own-bin-path.js +36 -0
- package/dist/domain/system/terminal-cli/index.d.ts +58 -0
- package/dist/domain/system/terminal-cli/index.js +100 -0
- package/dist/domain/system/terminal-cli/posix-profiles.d.ts +23 -0
- package/dist/domain/system/terminal-cli/posix-profiles.js +74 -0
- package/dist/domain/system/terminal-cli/registrar.d.ts +12 -0
- package/dist/domain/system/terminal-cli/registrar.js +1 -0
- package/dist/domain/system/terminal-cli/shims.d.ts +27 -0
- package/dist/domain/system/terminal-cli/shims.js +108 -0
- package/dist/domain/system/terminal-cli/state.d.ts +7 -0
- package/dist/domain/system/terminal-cli/state.js +36 -0
- package/dist/domain/system/terminal-cli/windows-user-path.d.ts +13 -0
- package/dist/domain/system/terminal-cli/windows-user-path.js +67 -0
- package/dist/domain/tui-session/tui-session-service.js +1 -1
- package/dist/domain/tui-session/types.d.ts +2 -2
- package/dist/domain/ui-service/app-router.d.ts +49 -71
- package/dist/domain/ui-service/app-router.js +9 -13
- package/dist/domain/ui-service/assistant-snapshots.js +2 -0
- package/dist/domain/ui-service/contract.parity.d.ts +19 -0
- package/dist/domain/ui-service/contract.parity.js +1 -0
- package/dist/domain/ui-service/inline-media-types.d.ts +18 -0
- package/dist/domain/ui-service/inline-media-types.js +1 -0
- package/dist/domain/ui-service/input-schemas.d.ts +52 -115
- package/dist/domain/ui-service/input-schemas.js +38 -84
- package/dist/domain/ui-service/mutate/auth.d.ts +1 -1
- package/dist/domain/ui-service/mutate/auth.js +3 -2
- package/dist/domain/ui-service/mutate/config.d.ts +0 -8
- package/dist/domain/ui-service/mutate/config.js +0 -22
- package/dist/domain/ui-service/mutate/models.d.ts +13 -0
- package/dist/domain/ui-service/mutate/models.js +137 -0
- package/dist/domain/ui-service/mutate/resolve-media.d.ts +4 -0
- package/dist/domain/ui-service/mutate/resolve-media.js +17 -0
- package/dist/domain/ui-service/mutate/sessions.d.ts +2 -2
- package/dist/domain/ui-service/mutate/sessions.js +29 -126
- package/dist/domain/ui-service/query/config.js +22 -42
- package/dist/domain/ui-service/query/models.js +2 -2
- package/dist/domain/ui-service/query/schedules.js +1 -1
- package/dist/domain/ui-service/query/sessions.js +7 -13
- package/dist/domain/ui-service/types.d.ts +51 -177
- package/dist/domain/ui-service/ui-service.d.ts +23 -49
- package/dist/domain/ui-service/ui-service.js +8 -6
- package/dist/entry/app.js +42 -19
- package/dist/entry/browser-cli.d.ts +39 -0
- package/dist/entry/browser-cli.js +317 -0
- package/dist/entry/cli-help.d.ts +1 -0
- package/dist/entry/cli-help.js +37 -6
- package/dist/entry/cli.js +16 -14
- package/dist/entry/daemon.js +2 -0
- package/dist/entry/init-auth.js +1 -1
- package/dist/entry/init.d.ts +7 -8
- package/dist/entry/init.js +89 -249
- package/dist/entry/path-cli.d.ts +4 -0
- package/dist/entry/path-cli.js +65 -0
- package/dist/entry/schedule-cli.js +13 -6
- package/dist/entry/shutdown.d.ts +1 -1
- package/dist/entry/shutdown.js +8 -1
- package/dist/entry/start-ui-http.js +8 -0
- package/dist/entry/ui-service-wiring.js +8 -10
- package/dist/events/event-types.d.ts +3 -2
- package/dist/orchestration/agent-runner.d.ts +2 -2
- package/dist/orchestration/agent-runner.js +10 -9
- package/dist/orchestration/benchmark-session-webhook.js +13 -1
- package/dist/orchestration/browser-webhook.d.ts +11 -0
- package/dist/orchestration/browser-webhook.js +28 -0
- package/dist/orchestration/cache-keep-warm.d.ts +77 -0
- package/dist/orchestration/cache-keep-warm.js +213 -0
- package/dist/orchestration/claude-window-warmup.d.ts +40 -0
- package/dist/orchestration/claude-window-warmup.js +126 -0
- package/dist/orchestration/conversation-request.d.ts +6 -10
- package/dist/orchestration/conversation-request.js +5 -23
- package/dist/orchestration/delta-coalescer.d.ts +4 -2
- package/dist/orchestration/delta-coalescer.js +5 -5
- package/dist/orchestration/edit-retry.js +9 -11
- package/dist/orchestration/inline-media-eager.d.ts +13 -0
- package/dist/orchestration/inline-media-eager.js +58 -0
- package/dist/orchestration/inline-media.d.ts +22 -0
- package/dist/orchestration/inline-media.js +151 -0
- package/dist/orchestration/interactions/ask-user-resume.js +3 -7
- package/dist/orchestration/interactions/interaction-handlers.js +6 -6
- package/dist/orchestration/mid-turn-inject.d.ts +2 -1
- package/dist/orchestration/mid-turn-inject.js +1 -1
- package/dist/orchestration/pending-injection-recovery.d.ts +2 -1
- package/dist/orchestration/pending-injection-recovery.js +1 -1
- package/dist/orchestration/routing/commands/index.js +4 -4
- package/dist/orchestration/routing/commands/mode.d.ts +5 -44
- package/dist/orchestration/routing/commands/mode.js +98 -272
- package/dist/orchestration/routing/commands/schedule.js +29 -18
- package/dist/orchestration/routing/commands/session.js +9 -9
- package/dist/orchestration/routing/commands/status.js +1 -1
- package/dist/orchestration/routing/commands/usage-format.js +3 -0
- package/dist/orchestration/routing/webhook.js +4 -0
- package/dist/orchestration/session-compact.d.ts +0 -1
- package/dist/orchestration/session-compact.js +5 -7
- package/dist/orchestration/session-events.d.ts +2 -1
- package/dist/orchestration/session-events.js +1 -0
- package/dist/orchestration/status-helpers.d.ts +0 -4
- package/dist/orchestration/status-helpers.js +0 -18
- package/dist/orchestration/subagent-webhook.js +9 -34
- package/dist/orchestration/team-webhook.d.ts +8 -9
- package/dist/orchestration/team-webhook.js +16 -42
- package/dist/orchestration/transcript-sink.d.ts +6 -0
- package/dist/orchestration/transcript-sink.js +21 -2
- package/dist/orchestration/turn/terminal.js +7 -7
- package/dist/orchestration/turn/turn-prep.d.ts +0 -8
- package/dist/orchestration/turn/turn-prep.js +0 -51
- package/dist/orchestration/turn/turn-tracking.d.ts +2 -2
- package/dist/orchestration/turn/turn-tracking.js +8 -5
- package/dist/orchestration/turn/turn.d.ts +0 -2
- package/dist/orchestration/turn/turn.js +13 -15
- package/dist/platform/adapters/tui/ports.d.ts +1 -1
- package/dist/platform/adapters/tui/tui-transcript.js +2 -0
- package/dist/platform/browser/agent-browser.d.ts +50 -0
- package/dist/platform/browser/agent-browser.js +165 -0
- package/dist/platform/browser/managed-browser.d.ts +1 -11
- package/dist/platform/browser/managed-browser.js +4 -12
- package/dist/platform/ui-http/browser-stream.d.ts +110 -0
- package/dist/platform/ui-http/browser-stream.js +447 -0
- package/dist/platform/ui-http/ui-http-server.d.ts +12 -0
- package/dist/platform/ui-http/ui-http-server.js +23 -6
- package/dist/store/conversation-history-reader.js +8 -0
- package/dist/store/conversation-history-repo.d.ts +8 -1
- package/dist/store/conversation-history-repo.js +5 -0
- package/dist/store/conversation-ledger-repo.d.ts +6 -6
- package/dist/store/conversation-ledger-repo.js +4 -4
- package/dist/store/models-repo.d.ts +18 -0
- package/dist/store/models-repo.js +74 -0
- package/dist/store/pending-injection-repo.d.ts +2 -1
- package/dist/store/pending-injection-repo.js +3 -1
- package/dist/store/retire-profiles-migration.d.ts +28 -0
- package/dist/store/retire-profiles-migration.js +335 -0
- package/dist/store/schedule-repo.d.ts +2 -1
- package/dist/store/session-registry-import.js +3 -2
- package/dist/store/session-registry-journal.d.ts +10 -13
- package/dist/store/session-registry-journal.js +48 -25
- package/dist/store/session-registry-repo.d.ts +4 -4
- package/dist/store/session-registry-repo.js +4 -5
- package/dist/store/version-migrations.d.ts +2 -3
- package/dist/store/version-migrations.js +19 -3
- package/dist/tui/slash-commands.js +2 -2
- package/dist/tui/turn-status.js +1 -1
- package/package.json +6 -4
- package/web/dist/assets/board-math-css-CB4GJ6qO.js +2 -0
- package/web/dist/assets/index-CaSZPg_H.css +1 -0
- package/web/dist/assets/index-CzOR7Edh.js +522 -0
- package/web/dist/assets/{index-CndZZ1IQ.js → index-cIGFv27z.js} +1 -1
- package/web/dist/index.html +3 -2
- package/web/dist/theme.css +6 -0
- package/dist/agent-adapter/browser-mcp-server.d.ts +0 -13
- package/dist/agent-adapter/browser-mcp-server.js +0 -28
- package/dist/agent-adapter/claude/browser-mcp.d.ts +0 -9
- package/dist/agent-adapter/claude/browser-mcp.js +0 -10
- package/dist/core/profile-generator.d.ts +0 -79
- package/dist/core/profile-generator.js +0 -215
- package/dist/domain/agents/profile-manager.d.ts +0 -103
- package/dist/domain/agents/profile-manager.js +0 -286
- package/dist/domain/agents/profile-switch.d.ts +0 -49
- package/dist/domain/agents/profile-switch.js +0 -62
- package/dist/domain/ui-service/mutate/profiles.d.ts +0 -36
- package/dist/domain/ui-service/mutate/profiles.js +0 -151
- package/dist/store/profile-repo.d.ts +0 -20
- package/dist/store/profile-repo.js +0 -97
- package/web/dist/assets/index-B76ueW3q.js +0 -494
- 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', '--
|
|
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', '
|
|
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,
|
|
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
|
|
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) {
|
package/dist/entry/shutdown.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface ShutdownHandles {
|
|
|
23
23
|
uiHttpServer?: {
|
|
24
24
|
close(): Promise<void>;
|
|
25
25
|
} | null;
|
|
26
|
-
|
|
26
|
+
stopModelsWatcher?: (() => void) | null;
|
|
27
27
|
stopBoardWatcher?: (() => void) | null;
|
|
28
28
|
}
|
|
29
29
|
export declare function shutdownSteps(h: ShutdownHandles): ShutdownStep[];
|
package/dist/entry/shutdown.js
CHANGED
|
@@ -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: '
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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: '
|
|
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
|
|
47
|
-
* created) with its use lease
|
|
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 {
|
|
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,
|
|
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
|
-
|
|
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
|
|
139
|
-
* created) with its use lease
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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;
|