@cortex-agent/server 2026.10.15 → 2026.10.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -51
- 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/context/projects/AGENTS.md +1 -1
- package/defaults/gitignore +3 -3
- package/defaults/hooks/new-session-hook.mjs +1 -1
- package/defaults/hooks/status-md-guard.mjs +6 -6
- 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/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +16 -9
- package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +2 -2
- package/defaults/rules/agents-md.md +1 -1
- package/defaults/rules/issues-md.md +1 -1
- package/defaults/rules/meta-conventions.md +3 -3
- package/defaults/rules/mission-md.md +1 -1
- package/defaults/rules/status-md.md +1 -1
- 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/bg-task-tracker.d.ts +3 -1
- package/dist/agent-adapter/claude/bg-task-tracker.js +6 -2
- 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/mcp-config.js +11 -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 +5 -3
- package/dist/agent-adapter/claude/turn-machine.js +29 -73
- 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.d.ts +6 -3
- package/dist/agent-adapter/continuation-phase.js +11 -3
- 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 +15 -10
- package/dist/agent-adapter/run-events.js +2 -0
- package/dist/agent-adapter/types.d.ts +14 -6
- package/dist/build-info.json +1 -0
- package/dist/client-bundle/client.mjs +10 -5
- package/dist/client-bundle/manifest.json +3 -3
- package/dist/core/claude-credentials.d.ts +6 -0
- package/dist/core/claude-credentials.js +11 -0
- package/dist/core/codex-quota.d.ts +1 -1
- package/dist/core/codex-quota.js +1 -1
- package/dist/core/gateway-generator.d.ts +26 -11
- package/dist/core/gateway-generator.js +73 -62
- package/dist/core/hook-bus.d.ts +1 -1
- package/dist/core/hook-bus.js +1 -8
- package/dist/core/locales/en.d.ts +52 -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 +9 -19
- package/dist/core/locales/slices/init.js +19 -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/log.d.ts +3 -0
- package/dist/core/log.js +18 -1
- 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 +30 -0
- package/dist/core/settings-spec.js +38 -0
- package/dist/core/status-format.d.ts +3 -2
- package/dist/core/status-format.js +2 -2
- package/dist/core/types/agent-types.d.ts +3 -1
- package/dist/core/types/environment-types.d.ts +1 -8
- 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 +4 -2
- package/dist/domain/agents/environments/resolve.js +0 -1
- package/dist/domain/agents/environments/schema.d.ts +3 -3
- package/dist/domain/agents/environments/schema.js +4 -4
- 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/auth-watch.js +48 -18
- 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 -7
- package/dist/domain/mcp/tools/context.js +17 -4
- package/dist/domain/mcp/tools/subagent.js +1 -1
- package/dist/domain/mcp/tools/ui-file.js +1 -1
- package/dist/domain/monitor/event-loop-monitor.d.ts +2 -0
- package/dist/domain/monitor/event-loop-monitor.js +5 -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/plugins/authoring.d.ts +8 -1
- package/dist/domain/plugins/authoring.js +24 -9
- package/dist/domain/plugins/runtime-gc.d.ts +7 -0
- package/dist/domain/plugins/runtime-gc.js +52 -19
- package/dist/domain/plugins/runtime.js +2 -1
- package/dist/domain/remote/client-bootstrap.js +1 -1
- package/dist/domain/remote/client-manager.js +6 -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 +3 -18
- package/dist/domain/runs/run.d.ts +12 -42
- package/dist/domain/runs/run.js +40 -147
- package/dist/domain/runs/service.d.ts +0 -9
- package/dist/domain/runs/service.js +33 -14
- 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/builtin-job-controller.d.ts +3 -1
- package/dist/domain/scheduling/builtin-job-controller.js +5 -2
- package/dist/domain/scheduling/builtin-jobs.js +7 -0
- 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 +36 -26
- 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/server-update-check.js +2 -1
- 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/telemetry/bus-collector.d.ts +3 -0
- package/dist/domain/telemetry/bus-collector.js +22 -0
- package/dist/domain/telemetry/child-exit.d.ts +11 -0
- package/dist/domain/telemetry/child-exit.js +36 -0
- package/dist/domain/telemetry/client-kind.d.ts +4 -0
- package/dist/domain/telemetry/client-kind.js +7 -0
- package/dist/domain/telemetry/crash-limits.d.ts +15 -0
- package/dist/domain/telemetry/crash-limits.js +50 -0
- package/dist/domain/telemetry/crash.d.ts +25 -0
- package/dist/domain/telemetry/crash.js +70 -0
- package/dist/domain/telemetry/daily-upload.d.ts +5 -0
- package/dist/domain/telemetry/daily-upload.js +20 -0
- package/dist/domain/telemetry/daily.d.ts +5 -0
- package/dist/domain/telemetry/daily.js +104 -0
- package/dist/domain/telemetry/endpoint.d.ts +7 -0
- package/dist/domain/telemetry/endpoint.js +40 -0
- package/dist/domain/telemetry/envelope.d.ts +6 -0
- package/dist/domain/telemetry/envelope.js +35 -0
- package/dist/domain/telemetry/error-digest.d.ts +7 -0
- package/dist/domain/telemetry/error-digest.js +43 -0
- package/dist/domain/telemetry/funnel.d.ts +6 -0
- package/dist/domain/telemetry/funnel.js +22 -0
- package/dist/domain/telemetry/gate.d.ts +19 -0
- package/dist/domain/telemetry/gate.js +67 -0
- package/dist/domain/telemetry/heartbeat.d.ts +17 -0
- package/dist/domain/telemetry/heartbeat.js +49 -0
- package/dist/domain/telemetry/info.d.ts +9 -0
- package/dist/domain/telemetry/info.js +12 -0
- package/dist/domain/telemetry/init-answer.d.ts +12 -0
- package/dist/domain/telemetry/init-answer.js +42 -0
- package/dist/domain/telemetry/install-id.d.ts +5 -0
- package/dist/domain/telemetry/install-id.js +42 -0
- package/dist/domain/telemetry/normalize.d.ts +33 -0
- package/dist/domain/telemetry/normalize.js +88 -0
- package/dist/domain/telemetry/outbox.d.ts +18 -0
- package/dist/domain/telemetry/outbox.js +93 -0
- package/dist/domain/telemetry/panic-group.d.ts +4 -0
- package/dist/domain/telemetry/panic-group.js +51 -0
- package/dist/domain/telemetry/paths.d.ts +7 -0
- package/dist/domain/telemetry/paths.js +11 -0
- package/dist/domain/telemetry/redact.d.ts +18 -0
- package/dist/domain/telemetry/redact.js +109 -0
- package/dist/domain/telemetry/rollup-types.d.ts +81 -0
- package/dist/domain/telemetry/rollup-types.js +31 -0
- package/dist/domain/telemetry/rollup.d.ts +16 -0
- package/dist/domain/telemetry/rollup.js +102 -0
- package/dist/domain/telemetry/schema.d.ts +931 -0
- package/dist/domain/telemetry/schema.js +275 -0
- package/dist/domain/telemetry/service.d.ts +34 -0
- package/dist/domain/telemetry/service.js +146 -0
- package/dist/domain/telemetry/state.d.ts +17 -0
- package/dist/domain/telemetry/state.js +29 -0
- package/dist/domain/telemetry/turns.d.ts +17 -0
- package/dist/domain/telemetry/turns.js +176 -0
- package/dist/domain/telemetry/upgrade.d.ts +14 -0
- package/dist/domain/telemetry/upgrade.js +87 -0
- package/dist/domain/telemetry/uploader.d.ts +21 -0
- package/dist/domain/telemetry/uploader.js +82 -0
- package/dist/domain/telemetry/usage.d.ts +25 -0
- package/dist/domain/telemetry/usage.js +153 -0
- package/dist/domain/telemetry/web-report.d.ts +8 -0
- package/dist/domain/telemetry/web-report.js +15 -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 +117 -95
- package/dist/domain/ui-service/app-router.js +17 -14
- 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 +120 -119
- package/dist/domain/ui-service/input-schemas.js +47 -85
- package/dist/domain/ui-service/mutate/approvals.d.ts +3 -2
- package/dist/domain/ui-service/mutate/approvals.js +3 -2
- 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/plugin-packages.js +1 -1
- 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/mutate/telemetry.d.ts +5 -0
- package/dist/domain/ui-service/mutate/telemetry.js +6 -0
- package/dist/domain/ui-service/query/approvals.js +4 -3
- package/dist/domain/ui-service/query/config.js +22 -42
- package/dist/domain/ui-service/query/machine-probe.d.ts +1 -1
- package/dist/domain/ui-service/query/machine-probe.js +3 -2
- package/dist/domain/ui-service/query/models.d.ts +3 -0
- package/dist/domain/ui-service/query/models.js +49 -32
- package/dist/domain/ui-service/query/plugin-source.js +4 -3
- package/dist/domain/ui-service/query/schedules.js +1 -1
- package/dist/domain/ui-service/query/sessions.js +8 -13
- package/dist/domain/ui-service/query/telemetry.d.ts +3 -0
- package/dist/domain/ui-service/query/telemetry.js +4 -0
- package/dist/domain/ui-service/trpc.d.ts +8 -3
- package/dist/domain/ui-service/trpc.js +1 -1
- package/dist/domain/ui-service/types.d.ts +71 -179
- package/dist/domain/ui-service/ui-service.d.ts +56 -53
- package/dist/domain/ui-service/ui-service.js +27 -24
- package/dist/entry/app.js +62 -21
- 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 +64 -20
- package/dist/entry/cli.js +16 -14
- package/dist/entry/daemon.d.ts +1 -1
- package/dist/entry/daemon.js +88 -72
- package/dist/entry/init-auth.js +1 -1
- package/dist/entry/init.d.ts +10 -8
- package/dist/entry/init.js +138 -276
- 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 +11 -1
- package/dist/entry/signal-cli.js +8 -11
- package/dist/entry/start-ui-http.js +48 -18
- package/dist/entry/telemetry-wiring.d.ts +12 -0
- package/dist/entry/telemetry-wiring.js +56 -0
- package/dist/entry/ui-cli.d.ts +0 -11
- package/dist/entry/ui-cli.js +42 -33
- package/dist/entry/ui-service-wiring.js +8 -10
- package/dist/events/event-types.d.ts +4 -6
- 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/message-router.js +2 -0
- package/dist/orchestration/routing/webhook.js +6 -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 +12 -0
- package/dist/orchestration/transcript-sink.js +38 -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/orchestration/waitpoint-ingress.js +3 -0
- 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-auth-routes.d.ts +2 -0
- package/dist/platform/ui-http/ui-auth-routes.js +9 -2
- package/dist/platform/ui-http/ui-device-routes.d.ts +13 -0
- package/dist/platform/ui-http/ui-device-routes.js +81 -0
- package/dist/platform/ui-http/ui-devices.d.ts +24 -0
- package/dist/platform/ui-http/ui-devices.js +107 -0
- package/dist/platform/ui-http/ui-http-server.d.ts +22 -3
- package/dist/platform/ui-http/ui-http-server.js +33 -12
- package/dist/platform/ui-http/ui-pairing.d.ts +25 -0
- package/dist/platform/ui-http/ui-pairing.js +98 -0
- 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/gitignore-migration.d.ts +2 -0
- package/dist/store/gitignore-migration.js +16 -0
- package/dist/store/hook-registry.d.ts +1 -1
- package/dist/store/hook-registry.js +11 -6
- 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 +51 -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 +7 -3
- package/dist/store/version-migrations.js +133 -80
- package/dist/tui/components/Dashboard.js +4 -3
- package/dist/tui/hooks/useDashboardData.js +1 -1
- 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-spk7yR6n.js +2 -0
- package/web/dist/assets/index-BQ69u-92.css +1 -0
- package/web/dist/assets/{index-CndZZ1IQ.js → index-CKNLatCd.js} +1 -1
- package/web/dist/assets/index-CkzWfC98.js +525 -0
- 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
package/dist/domain/runs/run.js
CHANGED
|
@@ -4,10 +4,10 @@ import { mergeContinuation } from '../../agent-adapter/continuation-phase.js';
|
|
|
4
4
|
import { CAPABILITIES_BY_BACKEND, Capability } from '../../agent-adapter/capabilities.js';
|
|
5
5
|
import { getSettings } from '../../core/settings.js';
|
|
6
6
|
import { t } from '../../core/i18n.js';
|
|
7
|
-
import {
|
|
8
|
-
import { NO_SPEND,
|
|
7
|
+
import { isRetryableError } from './retryable-errors.js';
|
|
8
|
+
import { NO_SPEND, countSpend, spendOfResult } from './spend.js';
|
|
9
9
|
import { publishAuthRecovered, publishAuthRequired, classifyAuthError } from '../auth/auth-events.js';
|
|
10
|
-
import { attemptAuthType, attemptProvider, attemptProviderOrNull, rateLimitedResult, shouldSkipAttempt,
|
|
10
|
+
import { attemptAuthType, attemptProvider, attemptProviderOrNull, rateLimitedResult, shouldSkipAttempt, } from './fallback.js';
|
|
11
11
|
import { requestRoute } from './config-resolver.js';
|
|
12
12
|
import { AttemptNoticeTracker, assistantNoticeLevel } from './notices.js';
|
|
13
13
|
import { startAttempt } from './attempt.js';
|
|
@@ -17,12 +17,6 @@ const PLUGIN_WARNINGS_SHOWN = 3;
|
|
|
17
17
|
function asError(error) {
|
|
18
18
|
return error instanceof Error ? error : new Error(String(error));
|
|
19
19
|
}
|
|
20
|
-
/** The error a turn ends with when a retryable failure hit after it had started a tool call. It
|
|
21
|
-
* keeps the original message — auth classification and provider attribution read it. */
|
|
22
|
-
function notRetriedAfterTools(reason, message) {
|
|
23
|
-
const key = reason === 'rate-limited' ? 'status.rateLimitedMidTurn' : 'status.notRetriedAfterTools';
|
|
24
|
-
return notRetriedFailure(t(key, { message }));
|
|
25
|
-
}
|
|
26
20
|
function cancellationError(reason) {
|
|
27
21
|
return Object.assign(new Error(`Run cancelled (${reason})`), { cancelled: true });
|
|
28
22
|
}
|
|
@@ -45,9 +39,6 @@ export class AgentRunImpl {
|
|
|
45
39
|
/** Continuation results seen so far. The live tally and a run that ends before its attempt
|
|
46
40
|
* settles (Stop, failure) read them; a settled attempt reports its own merged result. */
|
|
47
41
|
continuations = [];
|
|
48
|
-
/** What each attempt the chain moved past had spent. Each entry keeps counting until the run
|
|
49
|
-
* ends: a retired attempt's late cost rows still reach the ledger, so they count here too. */
|
|
50
|
-
retiredSpend = [];
|
|
51
42
|
/** What the running attempt has streamed so far: a run that ends with no result still cost it. */
|
|
52
43
|
liveSpend = null;
|
|
53
44
|
observers;
|
|
@@ -56,9 +47,7 @@ export class AgentRunImpl {
|
|
|
56
47
|
startedAt;
|
|
57
48
|
settleDeferred = deferred();
|
|
58
49
|
resultDeferred = deferred();
|
|
59
|
-
/**
|
|
60
|
-
plan;
|
|
61
|
-
/** Narrates the chain. It sits IN the event path because it can swallow a line. */
|
|
50
|
+
/** Narrates the attempt. It sits in the event path because it can swallow a line. */
|
|
62
51
|
notices;
|
|
63
52
|
/** Mirrors the old dispatcher's `active`: once the foreground turn is over, the run stops
|
|
64
53
|
* synthesizing notices about itself — the background phase is not a new turn to announce. */
|
|
@@ -73,8 +62,7 @@ export class AgentRunImpl {
|
|
|
73
62
|
this.request = args.request;
|
|
74
63
|
this.executionId = args.executionId;
|
|
75
64
|
this.id = args.request.runId;
|
|
76
|
-
this.
|
|
77
|
-
this.attemptValue = { index: 0, config: this.plan[0] };
|
|
65
|
+
this.attemptValue = { index: 0, config: args.request.selection };
|
|
78
66
|
this.notices = new AttemptNoticeTracker({
|
|
79
67
|
channel: args.request.context.channel,
|
|
80
68
|
isUserInitiated: args.request.context.isUserInitiated,
|
|
@@ -110,7 +98,7 @@ export class AgentRunImpl {
|
|
|
110
98
|
/** True while the running attempt is on the session's own backend, i.e. while its backend id
|
|
111
99
|
* may become the session's resume target (see `backendSessionId`). */
|
|
112
100
|
get onSessionBackend() {
|
|
113
|
-
return this.attemptValue.config.backend === this.request.
|
|
101
|
+
return this.attemptValue.config.backend === this.request.selection.backend;
|
|
114
102
|
}
|
|
115
103
|
/** Adopt `id` as the resume target, unless the running attempt is on another backend. */
|
|
116
104
|
adoptBackendSessionId(id) {
|
|
@@ -124,146 +112,52 @@ export class AgentRunImpl {
|
|
|
124
112
|
if (this.started)
|
|
125
113
|
return;
|
|
126
114
|
this.started = true;
|
|
127
|
-
void this.
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
async walkChain() {
|
|
138
|
-
let reason = 'rate-limited';
|
|
139
|
-
for (let index = 0; index < this.plan.length; index++) {
|
|
140
|
-
if (this.terminal)
|
|
141
|
-
return;
|
|
142
|
-
const attempt = this.plan[index];
|
|
143
|
-
const isLast = index === this.plan.length - 1;
|
|
144
|
-
if (index > 0)
|
|
145
|
-
this.advanceAttempt(index, attempt, reason);
|
|
146
|
-
if (shouldSkipAttempt(attempt, { isUserInitiated: this.request.context.isUserInitiated })) {
|
|
147
|
-
const blocked = rateLimitedResult(attempt.mode || 'api', attemptProvider(attempt));
|
|
148
|
-
if (isLast) {
|
|
149
|
-
this.notices.emitTerminalRateLimit(blocked);
|
|
150
|
-
this.settleBlocked(blocked);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
log.info(`${attemptLabel(attempt)} rate-limited, skipping to fallback[${index}]`);
|
|
154
|
-
reason = 'rate-limited';
|
|
155
|
-
this.notices.transitionToFallback(attempt, this.plan[index + 1], reason);
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
const outcome = await this.runAttempt(attempt, index, isLast);
|
|
159
|
-
if (outcome === 'settled')
|
|
160
|
-
return;
|
|
161
|
-
reason = outcome;
|
|
162
|
-
this.notices.transitionToFallback(attempt, this.plan[index + 1], reason);
|
|
115
|
+
void this.runOnce();
|
|
116
|
+
}
|
|
117
|
+
/** One selection, at most one spawn. Background work never waits for a throttled provider. */
|
|
118
|
+
async runOnce() {
|
|
119
|
+
const attempt = this.request.selection;
|
|
120
|
+
if (shouldSkipAttempt(attempt, this.request.context)) {
|
|
121
|
+
const blocked = rateLimitedResult(attempt.mode, attemptProvider(attempt));
|
|
122
|
+
this.notices.emitTerminalRateLimit(blocked);
|
|
123
|
+
this.settleBlocked(blocked);
|
|
124
|
+
return;
|
|
163
125
|
}
|
|
164
|
-
// Unreachable: the last attempt always settles or throws. Guard rather than hang.
|
|
165
|
-
if (!this.terminal)
|
|
166
|
-
this.finishForegroundError(new Error('All fallback configs exhausted without result'));
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* One attempt. Returns 'settled' when the run is over, or why the chain should advance.
|
|
170
|
-
*
|
|
171
|
-
* A fallback re-runs the whole turn in a fresh backend conversation. That is only safe before
|
|
172
|
-
* the turn started any tool call — a rate limit or a transport failure alike; after one, the
|
|
173
|
-
* re-run would repeat its side effects, so the turn ends with an error that says why it was not
|
|
174
|
-
* retried. The last attempt has nothing to fall back to and settles as it always did.
|
|
175
|
-
*/
|
|
176
|
-
async runAttempt(attempt, index, isLast) {
|
|
177
|
-
// A retry starts a fresh backend conversation: the previous attempt's resume target belongs to
|
|
178
|
-
// a provider that just failed us.
|
|
179
|
-
const request = index === 0
|
|
180
|
-
? this.request
|
|
181
|
-
: { ...this.request, session: { ...this.request.session, backendSessionId: null } };
|
|
182
|
-
// Once the chain moves on, whatever this attempt still streams (a hold-mode background phase,
|
|
183
|
-
// the close of its engine) belongs to no one: observers follow the attempt that replaced it.
|
|
184
|
-
let abandoned = false;
|
|
185
|
-
let toolStarted = false;
|
|
186
|
-
const spend = { ...NO_SPEND };
|
|
187
|
-
this.liveSpend = spend;
|
|
188
|
-
const retire = (reason) => {
|
|
189
|
-
abandoned = true;
|
|
190
|
-
this.retiredSpend.push(spend);
|
|
191
|
-
this.liveSpend = null;
|
|
192
|
-
return reason;
|
|
193
|
-
};
|
|
194
126
|
let current;
|
|
195
127
|
try {
|
|
196
|
-
current =
|
|
197
|
-
request, attempt, executionId: this.executionId,
|
|
198
|
-
route: this.routeFor(attempt),
|
|
199
|
-
onEvent: (event) => {
|
|
200
|
-
countSpend(spend, event);
|
|
201
|
-
if (abandoned)
|
|
202
|
-
return;
|
|
203
|
-
if (event.type === 'tool_use')
|
|
204
|
-
toolStarted = true;
|
|
205
|
-
this.onRunEvent(event);
|
|
206
|
-
},
|
|
207
|
-
});
|
|
128
|
+
current = this.openAttempt(attempt);
|
|
208
129
|
}
|
|
209
130
|
catch (error) {
|
|
210
131
|
this.onForegroundError(error);
|
|
211
|
-
return
|
|
132
|
+
return;
|
|
212
133
|
}
|
|
213
|
-
this.current = current;
|
|
214
|
-
this.registerAttempt(current);
|
|
215
|
-
this.announcePluginWarnings(current.spec);
|
|
216
134
|
try {
|
|
217
|
-
|
|
218
|
-
if (!isRetryableResult(result) || isLast) {
|
|
219
|
-
this.settleAttemptResult(current, result);
|
|
220
|
-
return 'settled';
|
|
221
|
-
}
|
|
222
|
-
// The attempt ends here with a result of its own: its turn count is the last word.
|
|
223
|
-
const resultTurns = spendOfResult(result).numTurns;
|
|
224
|
-
if (resultTurns !== null)
|
|
225
|
-
spend.numTurns = Math.max(spend.numTurns ?? 0, resultTurns);
|
|
226
|
-
if (toolStarted) {
|
|
227
|
-
log.info(`${attemptLabel(attempt)} rate limited after a tool ran; not retrying on fallback[${index}]`);
|
|
228
|
-
const detail = result.rateLimitMessage || t('status.rateLimitedExhausted');
|
|
229
|
-
this.onAttemptError(current, attempt, notRetriedAfterTools('rate-limited', detail));
|
|
230
|
-
return 'settled';
|
|
231
|
-
}
|
|
232
|
-
log.info(`${attemptLabel(attempt)} rate limited, trying fallback[${index}]`);
|
|
233
|
-
return retire('rate-limited');
|
|
135
|
+
this.settleAttemptResult(current, await current.foreground);
|
|
234
136
|
}
|
|
235
137
|
catch (error) {
|
|
236
|
-
|
|
237
|
-
if (this.cancelRequested || !isRetryableError(failure) || isLast) {
|
|
238
|
-
this.onAttemptError(current, attempt, error);
|
|
239
|
-
return 'settled';
|
|
240
|
-
}
|
|
241
|
-
const reason = fallbackReasonOf(failure);
|
|
242
|
-
if (toolStarted) {
|
|
243
|
-
log.info(`${attemptLabel(attempt)} ${reason} after a tool ran; not retrying on fallback[${index}]`);
|
|
244
|
-
this.onAttemptError(current, attempt, notRetriedAfterTools(reason, failure.message));
|
|
245
|
-
return 'settled';
|
|
246
|
-
}
|
|
247
|
-
log.info(`${attemptLabel(attempt)} retryable error (${reason}), trying fallback[${index}]`);
|
|
248
|
-
return retire(reason);
|
|
138
|
+
this.onAttemptError(current, attempt, error);
|
|
249
139
|
}
|
|
250
140
|
}
|
|
251
|
-
|
|
252
|
-
|
|
141
|
+
openAttempt(attempt) {
|
|
142
|
+
const spend = { ...NO_SPEND };
|
|
143
|
+
this.liveSpend = spend;
|
|
144
|
+
const current = startAttempt({
|
|
145
|
+
request: this.request, attempt, executionId: this.executionId,
|
|
146
|
+
route: this.routeFor(attempt),
|
|
147
|
+
onEvent: (event) => {
|
|
148
|
+
countSpend(spend, event);
|
|
149
|
+
this.onRunEvent(event);
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
this.current = current;
|
|
153
|
+
this.registerAttempt(current);
|
|
154
|
+
this.announcePluginWarnings(current.spec);
|
|
155
|
+
return current;
|
|
156
|
+
}
|
|
157
|
+
/** The route (base URL + credentials) this run uses. */
|
|
253
158
|
routeFor(attempt) {
|
|
254
159
|
return requestRoute(this.request, attempt);
|
|
255
160
|
}
|
|
256
|
-
/** The chain moved on. Report it on the stream; the surface renders the notice. */
|
|
257
|
-
advanceAttempt(index, next, reason) {
|
|
258
|
-
const previous = this.attemptValue.config;
|
|
259
|
-
this.attemptValue = { index, config: next };
|
|
260
|
-
this.absorb({
|
|
261
|
-
type: 'run_fallback',
|
|
262
|
-
from: attemptLabel(previous),
|
|
263
|
-
to: attemptLabel(next),
|
|
264
|
-
reason,
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
161
|
/** Every attempt that reached a backend settles here: provider attribution and the auth
|
|
268
162
|
* lifecycle apply to the WHOLE attempt, background phase included, which is why they are done
|
|
269
163
|
* on the settled value rather than wrapped around the foreground promise. */
|
|
@@ -291,8 +185,7 @@ export class AgentRunImpl {
|
|
|
291
185
|
void current.settled.catch(() => undefined);
|
|
292
186
|
this.onForegroundError(failure);
|
|
293
187
|
}
|
|
294
|
-
/** Stamp the
|
|
295
|
-
* selection (an unknown profile name) names no provider: see `attemptProviderOrNull`. */
|
|
188
|
+
/** Stamp the selected provider onto a result that did not name one. */
|
|
296
189
|
attribute(result) {
|
|
297
190
|
const provider = attemptProviderOrNull(this.attemptValue.config);
|
|
298
191
|
if (!provider || result.rateLimitProvider)
|
|
@@ -444,7 +337,7 @@ export class AgentRunImpl {
|
|
|
444
337
|
}
|
|
445
338
|
break;
|
|
446
339
|
case 'model_fallback':
|
|
447
|
-
// The
|
|
340
|
+
// The backend itself swapped models — report its native event.
|
|
448
341
|
if (this.noticesActive) {
|
|
449
342
|
this.notices.observe(t('notify.agentFallback', {
|
|
450
343
|
from: event.originalModel, to: event.fallbackModel,
|
|
@@ -637,7 +530,7 @@ export class AgentRunImpl {
|
|
|
637
530
|
* what it streamed. */
|
|
638
531
|
runSpend(result) {
|
|
639
532
|
const last = result ? spendOfResult(result) : this.liveSpend ?? NO_SPEND;
|
|
640
|
-
return
|
|
533
|
+
return last;
|
|
641
534
|
}
|
|
642
535
|
// ── observer fan-out ───────────────────────────────────────────────────
|
|
643
536
|
fanOut(event) {
|
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
import { type AgentRun } from './run.js';
|
|
2
2
|
import type { RunObserver, RunRequest } from './request.js';
|
|
3
|
-
/**
|
|
4
|
-
* Start one agent run: open its execution record, register it for cancellation, and return the
|
|
5
|
-
* `AgentRun` that owns the rest of the lifecycle. This is the single entry point every surface is
|
|
6
|
-
* meant to call.
|
|
7
|
-
*
|
|
8
|
-
* The run walks its own attempt chain over pooled engine sessions and feeds every signal through
|
|
9
|
-
* one `RunEvent` stream. `teardownExecution` and the registry removal happen exactly once, from
|
|
10
|
-
* the run's terminal handler.
|
|
11
|
-
*/
|
|
12
3
|
export declare function startRun(request: RunRequest, observers: RunObserver[]): AgentRun;
|
|
@@ -1,42 +1,61 @@
|
|
|
1
1
|
import { runRegistry } from '../../core/run-registry.js';
|
|
2
|
+
import { sessionBenchmarkMaxOutputTokens } from '../benchmark/session-evidence.js';
|
|
2
3
|
import * as executionRegistry from '../executions/registry.js';
|
|
3
4
|
import { AgentRunImpl } from './run.js';
|
|
5
|
+
import { createRunTelemetry } from '../telemetry/turns.js';
|
|
4
6
|
/**
|
|
5
7
|
* Start one agent run: open its execution record, register it for cancellation, and return the
|
|
6
8
|
* `AgentRun` that owns the rest of the lifecycle. This is the single entry point every surface is
|
|
7
9
|
* meant to call.
|
|
8
10
|
*
|
|
9
|
-
* The run
|
|
11
|
+
* The run opens one attempt on its pooled engine session and feeds every signal through
|
|
10
12
|
* one `RunEvent` stream. `teardownExecution` and the registry removal happen exactly once, from
|
|
11
13
|
* the run's terminal handler.
|
|
12
14
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
function withBenchmarkCap(request) {
|
|
16
|
+
if (!request.benchmark?.evidenceContext || !request.session.sessionId)
|
|
17
|
+
return request;
|
|
18
|
+
return { ...request, benchmarkMaxOutputTokens: request.benchmarkMaxOutputTokens
|
|
19
|
+
?? sessionBenchmarkMaxOutputTokens(request.session.sessionId) };
|
|
20
|
+
}
|
|
21
|
+
function openExecution(request) {
|
|
22
|
+
return executionRegistry.startLocalExecution({
|
|
16
23
|
kind: request.context.executionKind,
|
|
17
24
|
channel: request.context.channel,
|
|
18
25
|
project: request.context.project,
|
|
19
26
|
trigger: request.context.trigger,
|
|
20
|
-
backend: request.
|
|
21
|
-
billingMode: request.
|
|
27
|
+
backend: request.selection.backend,
|
|
28
|
+
billingMode: request.selection.mode || 'api',
|
|
22
29
|
sessionId: request.session.sessionId,
|
|
23
30
|
ownerSessionId: request.context.ownerSessionId ?? null,
|
|
24
31
|
label: request.prompt.text.substring(0, 60),
|
|
25
32
|
scheduleTaskId: request.context.scheduleTaskId || null,
|
|
26
33
|
});
|
|
34
|
+
}
|
|
35
|
+
function closeExecution(executionId, info) {
|
|
36
|
+
const { status, result, spend, error, durationS } = info;
|
|
37
|
+
executionRegistry.teardownExecution({
|
|
38
|
+
executionId, status, result, spend,
|
|
39
|
+
error: error ? { message: error.message } : null,
|
|
40
|
+
durationS,
|
|
41
|
+
});
|
|
42
|
+
runRegistry.remove(executionId);
|
|
43
|
+
}
|
|
44
|
+
export function startRun(request, observers) {
|
|
45
|
+
request = withBenchmarkCap(request);
|
|
46
|
+
const startedAt = Date.now();
|
|
47
|
+
const execution = openExecution(request);
|
|
48
|
+
// Anonymous product telemetry: one more observer, and the terminal facts (no-op when off).
|
|
49
|
+
const telemetry = createRunTelemetry(request);
|
|
27
50
|
const run = new AgentRunImpl({
|
|
28
51
|
request,
|
|
29
|
-
observers,
|
|
52
|
+
observers: [...observers, telemetry.observer],
|
|
30
53
|
executionId: execution.id,
|
|
31
54
|
registry: runRegistry,
|
|
32
55
|
startedAt,
|
|
33
|
-
onTerminal: (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
error: error ? { message: error.message } : null,
|
|
37
|
-
durationS,
|
|
38
|
-
});
|
|
39
|
-
runRegistry.remove(execution.id);
|
|
56
|
+
onTerminal: (info) => {
|
|
57
|
+
closeExecution(execution.id, info);
|
|
58
|
+
telemetry.finish(info);
|
|
40
59
|
},
|
|
41
60
|
});
|
|
42
61
|
run.start();
|
|
@@ -17,7 +17,7 @@ import type { McpComposition } from '../../agent-adapter/types.js';
|
|
|
17
17
|
*/
|
|
18
18
|
export type ToolSurface = string[] | string | null;
|
|
19
19
|
/**
|
|
20
|
-
* What an agent *is*, independent of which
|
|
20
|
+
* What an agent *is*, independent of which model/route runs it. Every field is resolved: no
|
|
21
21
|
* file refs, no `__active__`, no template placeholders left to expand.
|
|
22
22
|
*/
|
|
23
23
|
export interface AgentSpec {
|
|
@@ -11,6 +11,6 @@ export declare function spendOfResult(result: RunResult): RunSpend;
|
|
|
11
11
|
/**
|
|
12
12
|
* Fold one event of an attempt's stream into what that attempt has spent: every cost row (the
|
|
13
13
|
* same rows the ledger records) and its latest turn count. This is how an attempt that ends with
|
|
14
|
-
* no result of its own —
|
|
14
|
+
* no result of its own — failed or stopped — still accounts for its spend.
|
|
15
15
|
*/
|
|
16
16
|
export declare function countSpend(spend: RunSpend, event: RunEvent): void;
|
|
@@ -17,7 +17,7 @@ export function spendOfResult(result) {
|
|
|
17
17
|
/**
|
|
18
18
|
* Fold one event of an attempt's stream into what that attempt has spent: every cost row (the
|
|
19
19
|
* same rows the ledger records) and its latest turn count. This is how an attempt that ends with
|
|
20
|
-
* no result of its own —
|
|
20
|
+
* no result of its own — failed or stopped — still accounts for its spend.
|
|
21
21
|
*/
|
|
22
22
|
export function countSpend(spend, event) {
|
|
23
23
|
if (event.type === 'cost_record') {
|
|
@@ -2,7 +2,9 @@ export type BuiltinJobMode = 'serial' | 'detached';
|
|
|
2
2
|
export interface BuiltinJobDefinition {
|
|
3
3
|
name: string;
|
|
4
4
|
enabledKey: string;
|
|
5
|
-
|
|
5
|
+
/** Setting that holds the interval; `fixedIntervalMs` instead for a job with no such setting. */
|
|
6
|
+
intervalKey?: string;
|
|
7
|
+
fixedIntervalMs?: number;
|
|
6
8
|
mode: BuiltinJobMode;
|
|
7
9
|
run: () => void | Promise<void>;
|
|
8
10
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
function jobInterval(job, settings) {
|
|
2
|
+
return job.fixedIntervalMs ?? settings[job.intervalKey ?? ''];
|
|
3
|
+
}
|
|
1
4
|
function clearJobTimer(state) {
|
|
2
5
|
if (!state.timer)
|
|
3
6
|
return;
|
|
@@ -39,7 +42,7 @@ class JobController {
|
|
|
39
42
|
const state = this.states.get(job.name);
|
|
40
43
|
const wasEnabled = state.enabled;
|
|
41
44
|
const nextEnabled = settings[job.enabledKey] === true;
|
|
42
|
-
const nextInterval = settings
|
|
45
|
+
const nextInterval = jobInterval(job, settings);
|
|
43
46
|
const intervalChanged = nextInterval !== state.intervalMs;
|
|
44
47
|
state.enabled = nextEnabled;
|
|
45
48
|
state.intervalMs = nextInterval;
|
|
@@ -63,7 +66,7 @@ class JobController {
|
|
|
63
66
|
const settings = this.options.getSettings();
|
|
64
67
|
if (!this.started || settings[job.enabledKey] !== true)
|
|
65
68
|
return;
|
|
66
|
-
state.intervalMs = settings
|
|
69
|
+
state.intervalMs = jobInterval(job, settings);
|
|
67
70
|
if (job.mode === 'serial')
|
|
68
71
|
this.runSerial(job);
|
|
69
72
|
else
|
|
@@ -3,6 +3,7 @@ import { getSettings, onSettingsChange } from '../../core/settings.js';
|
|
|
3
3
|
import { usageService } from '../costs/usage-service.js';
|
|
4
4
|
import { createBuiltinJobController } from './builtin-job-controller.js';
|
|
5
5
|
import { regenAll } from '../memory/index-regen.js';
|
|
6
|
+
import { telemetryTick } from '../telemetry/service.js';
|
|
6
7
|
const log = createLogger('builtin-jobs');
|
|
7
8
|
let controller = null;
|
|
8
9
|
function buildJobs() {
|
|
@@ -17,6 +18,12 @@ function buildJobs() {
|
|
|
17
18
|
intervalKey: 'memoryIndexRegenIntervalMs', mode: 'serial',
|
|
18
19
|
run: async () => { regenAll(); },
|
|
19
20
|
},
|
|
21
|
+
{
|
|
22
|
+
// Persists the day's telemetry aggregates and uploads what is due (heartbeat, finished
|
|
23
|
+
// days, retries). The tick itself checks the full gate (env, sealed home, endpoint).
|
|
24
|
+
name: 'telemetry', enabledKey: 'telemetryEnabled', fixedIntervalMs: 5 * 60 * 1000, mode: 'serial',
|
|
25
|
+
run: telemetryTick,
|
|
26
|
+
},
|
|
20
27
|
];
|
|
21
28
|
}
|
|
22
29
|
export function startBuiltinJobs() {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { applyChannelSelection } from '../../agents/index.js';
|
|
2
|
+
import type { EngineSelection } from '../../agents/engine-selection.js';
|
|
2
3
|
import { createDirectSession } from '../../sessions/session-lifecycle.js';
|
|
3
4
|
export interface RunScheduledTaskInput {
|
|
4
5
|
message: string;
|
|
5
6
|
projectId: string;
|
|
6
7
|
scheduleTaskId: string;
|
|
7
|
-
|
|
8
|
+
selection: EngineSelection;
|
|
8
9
|
}
|
|
9
10
|
/** Collaborators the run is opened with. Production uses the real stores; tests inject their own. */
|
|
10
11
|
export interface ScheduledRunDeps {
|
|
@@ -20,4 +21,4 @@ export declare function runScheduledTask(input: RunScheduledTaskInput, deps?: Sc
|
|
|
20
21
|
* the schedule's run — and delivers the schedule's prompt as its first turn. Everything after that
|
|
21
22
|
* (the run itself, a rate-limit pause and its resume, a reply adopting the run) is the session's.
|
|
22
23
|
*/
|
|
23
|
-
export declare function fireScheduledTask(
|
|
24
|
+
export declare function fireScheduledTask(input: RunScheduledTaskInput, deps?: ScheduledRunDeps): Promise<void>;
|
|
@@ -5,12 +5,11 @@ import * as executionRegistry from '../../executions/registry.js';
|
|
|
5
5
|
import { sessionStore } from '../../../store/session-registry-repo.js';
|
|
6
6
|
import { conversationLedger } from '../../../store/conversation-ledger-repo.js';
|
|
7
7
|
import { applyChannelSelection, resolveBackendForChannel } from '../../agents/index.js';
|
|
8
|
-
import { getDefaultProfileName } from '../../agents/profile-manager.js';
|
|
9
8
|
import { projectStore } from '../../projects/index.js';
|
|
10
9
|
import { createDirectSession } from '../../sessions/session-lifecycle.js';
|
|
11
10
|
import { setSessionAsync } from '../../sessions/session.js';
|
|
12
11
|
import { isValidDispatchPrompt, hasRunningExecutionForSchedule } from '../run-guards.js';
|
|
13
|
-
import {
|
|
12
|
+
import { configIsRateLimited } from '../../agents/provider-run-lifecycle.js';
|
|
14
13
|
import { t } from '../../../core/i18n.js';
|
|
15
14
|
import { publishSystemNotice } from '../../system/system-notice.js';
|
|
16
15
|
const log = createLogger('scheduled-task');
|
|
@@ -47,22 +46,19 @@ export function runScheduledTask(input, deps = defaultDeps) {
|
|
|
47
46
|
* the schedule's run — and delivers the schedule's prompt as its first turn. Everything after that
|
|
48
47
|
* (the run itself, a rate-limit pause and its resume, a reply adopting the run) is the session's.
|
|
49
48
|
*/
|
|
50
|
-
export async function fireScheduledTask(
|
|
49
|
+
export async function fireScheduledTask(input, deps = defaultDeps) {
|
|
50
|
+
const { projectId, scheduleTaskId } = input;
|
|
51
51
|
const schedKey = `sched:${scheduleTaskId || projectId}`;
|
|
52
52
|
if (!passScheduledGuards(schedKey, scheduleTaskId))
|
|
53
53
|
return;
|
|
54
|
-
if (!
|
|
55
|
-
log.warn(`Guard dropped null/empty prompt for schedule ${scheduleTaskId} (project=${projectId}, profile=${profileName}): "${message?.substring(0, 60) || String(message)}"`);
|
|
54
|
+
if (!(await canOpenScheduledRun(input)))
|
|
56
55
|
return;
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
log.info(`Skipping schedule ${scheduleTaskId} — all configs rate-limited for profile ${profileName}`);
|
|
60
|
-
await notifySkippedSchedule(projectId, t('notice.schedule.rateLimited', { id: scheduleTaskId, message }));
|
|
56
|
+
// Re-check after the async guard: another fire may already have reserved this schedule.
|
|
57
|
+
if (!passScheduledGuards(schedKey, scheduleTaskId))
|
|
61
58
|
return;
|
|
62
|
-
}
|
|
63
59
|
scheduledTaskActive.add(schedKey);
|
|
64
60
|
try {
|
|
65
|
-
await openScheduledRun(
|
|
61
|
+
await openScheduledRun(input, deps);
|
|
66
62
|
}
|
|
67
63
|
catch (error) {
|
|
68
64
|
// Nothing ran, so the notice is the only trace this fire leaves.
|
|
@@ -73,23 +69,33 @@ export async function fireScheduledTask({ message, projectId, scheduleTaskId, pr
|
|
|
73
69
|
scheduledTaskActive.delete(schedKey);
|
|
74
70
|
}
|
|
75
71
|
}
|
|
76
|
-
async function
|
|
72
|
+
async function canOpenScheduledRun({ message, projectId, scheduleTaskId, selection }) {
|
|
73
|
+
if (!isValidDispatchPrompt(message)) {
|
|
74
|
+
log.warn(`Guard dropped null/empty prompt for schedule ${scheduleTaskId} (project=${projectId}, model=${selection.model}): "${message?.substring(0, 60) || String(message)}"`);
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (!configIsRateLimited(selection))
|
|
78
|
+
return true;
|
|
79
|
+
log.info(`Skipping schedule ${scheduleTaskId} — selection ${selection.backend}/${selection.model} is rate-limited`);
|
|
80
|
+
await notifySkippedSchedule(projectId, t('notice.schedule.rateLimited', { id: scheduleTaskId, message }));
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
async function openScheduledRun({ message, projectId, scheduleTaskId, selection }, deps) {
|
|
77
84
|
const deliver = requireJobCtx('deliverScheduledTurn');
|
|
78
85
|
const sessionId = deps.newSessionId();
|
|
79
86
|
const channel = `web:${sessionId}`;
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
const applied = await deps.applySelection({
|
|
83
|
-
channel, profileName: profileName || getDefaultProfileName(), seedDefault: false,
|
|
84
|
-
});
|
|
87
|
+
// Apply the complete stored selection before creating the session, without changing the seed
|
|
88
|
+
// for the user's next conversation.
|
|
89
|
+
const applied = await deps.applySelection({ channel, ...selection, seedDefault: false });
|
|
85
90
|
if (!applied.ok)
|
|
86
|
-
throw new Error(`cannot run on
|
|
91
|
+
throw new Error(`cannot run on model "${selection.model}": ${applied.reason}`);
|
|
87
92
|
const created = await deps.createSession({
|
|
88
93
|
projectId: projectStore.exists(projectId)
|
|
89
94
|
? projectId
|
|
90
95
|
: projectStore.resolveFromMessage(message)?.id ?? 'general',
|
|
91
96
|
sessionId,
|
|
92
|
-
|
|
97
|
+
selection,
|
|
98
|
+
seedDefault: false,
|
|
93
99
|
scheduleId: scheduleTaskId || null,
|
|
94
100
|
label: message.substring(0, 60) || null,
|
|
95
101
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ScheduleRepo, ScheduleTask } from '../../store/schedule-repo.js';
|
|
2
2
|
import { type ScheduleSpec, type SchedulePatch } from './schedule-spec.js';
|
|
3
3
|
type Repo = Pick<ScheduleRepo, 'mutate' | 'updateTask'>;
|
|
4
|
-
export declare function resolveTaskProfile(profile: string | null | undefined): string;
|
|
5
4
|
/** Persist a new schedule. With an idempotency key, a schedule already created under that key is
|
|
6
5
|
* returned instead of adding a second one. */
|
|
7
6
|
export declare function addSchedule(repo: Repo, spec: ScheduleSpec, opts?: {
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { randomBytes } from 'crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { getDefaultSelection } from '../agents/models.js';
|
|
3
3
|
import { buildScheduleTask, normalizeSchedulePatch, retimeTask, } from './schedule-spec.js';
|
|
4
|
-
export function resolveTaskProfile(profile) {
|
|
5
|
-
return profile || getDefaultProfileName();
|
|
6
|
-
}
|
|
7
4
|
/** Persist a new schedule. With an idempotency key, a schedule already created under that key is
|
|
8
5
|
* returned instead of adding a second one. */
|
|
9
6
|
export async function addSchedule(repo, spec, opts = {}) {
|
|
10
|
-
const task = buildScheduleTask(spec, randomBytes(4).toString('hex'), Date.now(),
|
|
7
|
+
const task = buildScheduleTask(spec, randomBytes(4).toString('hex'), Date.now(), spec.selection ?? getDefaultSelection());
|
|
11
8
|
const key = opts.idempotencyKey;
|
|
12
9
|
if (key)
|
|
13
10
|
task.idempotencyKey = key;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type EngineSelection } from '../agents/engine-selection.js';
|
|
2
|
+
/** CLI/chat model flags resolve once, at creation or edit, never again when the task fires. */
|
|
3
|
+
export declare function resolveScheduleSelection(model?: string, thinking?: string, current?: EngineSelection): EngineSelection | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getDefaultSelection, resolveModelRef, selectionForModel } from '../agents/models.js';
|
|
2
|
+
import { isValidThinkingLevel, THINKING_LEVELS_BY_BACKEND } from '../agents/engine-selection.js';
|
|
3
|
+
import { ScheduleSpecError } from './schedule-spec.js';
|
|
4
|
+
/** CLI/chat model flags resolve once, at creation or edit, never again when the task fires. */
|
|
5
|
+
export function resolveScheduleSelection(model, thinking, current) {
|
|
6
|
+
if (model === undefined && thinking === undefined)
|
|
7
|
+
return undefined;
|
|
8
|
+
const selection = model === undefined ? current ?? getDefaultSelection() : selectionForModel(resolveModelRef(model));
|
|
9
|
+
if (thinking === undefined)
|
|
10
|
+
return { ...selection };
|
|
11
|
+
if (!isValidThinkingLevel(selection.backend, thinking)) {
|
|
12
|
+
const levels = THINKING_LEVELS_BY_BACKEND[selection.backend].join(', ');
|
|
13
|
+
throw new ScheduleSpecError('thinking', `Invalid thinking '${thinking}' for ${selection.backend}. Valid values: ${levels}`, thinking);
|
|
14
|
+
}
|
|
15
|
+
return { ...selection, thinking };
|
|
16
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EngineSelection } from '../agents/engine-selection.js';
|
|
1
2
|
import type { ScheduleTask } from '../../store/schedule-repo.js';
|
|
2
3
|
export declare const SCHEDULE_TYPES: readonly ['interval', 'daily', 'weekly', 'once'];
|
|
3
4
|
export type ScheduleType = typeof SCHEDULE_TYPES[number];
|
|
@@ -21,7 +22,7 @@ export type ScheduleTiming = {
|
|
|
21
22
|
export type ScheduleSpec = ScheduleTiming & {
|
|
22
23
|
message: string;
|
|
23
24
|
projectId: string;
|
|
24
|
-
|
|
25
|
+
selection?: EngineSelection;
|
|
25
26
|
preCheck?: string;
|
|
26
27
|
};
|
|
27
28
|
/** Schedule fields as an entry point parsed them from its own syntax. Durations are a unit string
|
|
@@ -30,7 +31,7 @@ export interface ScheduleSpecInput {
|
|
|
30
31
|
type: string | undefined;
|
|
31
32
|
message: string | null | undefined;
|
|
32
33
|
projectId?: string | null;
|
|
33
|
-
|
|
34
|
+
selection?: EngineSelection | null;
|
|
34
35
|
preCheck?: string | null;
|
|
35
36
|
interval?: string | number;
|
|
36
37
|
time?: string;
|
|
@@ -41,7 +42,7 @@ export interface ScheduleSpecInput {
|
|
|
41
42
|
export interface SchedulePatch {
|
|
42
43
|
message?: string;
|
|
43
44
|
projectId?: string;
|
|
44
|
-
|
|
45
|
+
selection?: EngineSelection;
|
|
45
46
|
preCheck?: string;
|
|
46
47
|
dispatchType?: string;
|
|
47
48
|
intervalMs?: number;
|
|
@@ -74,5 +75,5 @@ export declare function nextFireDelayMs(task: Pick<ScheduleTask, 'type' | 'inter
|
|
|
74
75
|
/** Recompute nextRun after a recurring task's timing or pause state changed. A once task keeps
|
|
75
76
|
* its runAt. */
|
|
76
77
|
export declare function retimeTask(task: ScheduleTask, now?: number): void;
|
|
77
|
-
/** The persisted record for a new schedule.
|
|
78
|
-
export declare function buildScheduleTask(spec: ScheduleSpec, id: string, now: number,
|
|
78
|
+
/** The persisted record for a new schedule. The caller has materialized its selection. */
|
|
79
|
+
export declare function buildScheduleTask(spec: ScheduleSpec, id: string, now: number, selection: EngineSelection): ScheduleTask;
|