@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
|
@@ -1,161 +1,111 @@
|
|
|
1
|
+
import { AsyncMutex } from '../../core/async-mutex.js';
|
|
1
2
|
import { readGatewayYaml } from '../../core/gateway-generator.js';
|
|
3
|
+
import { effectiveBackendSessionId, sessionStore } from '../../store/session-registry-repo.js';
|
|
2
4
|
import { GATEWAY_CONFIG_PATH } from '../pi-providers/gateway-route-store.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The routes gateway.yaml declares for one endpoint, or an empty list when the file cannot be read.
|
|
13
|
-
*
|
|
14
|
-
* A route that the gateway does not declare answers 404 at turn time, which reads as the agent
|
|
15
|
-
* dying, so this one IS checked — but only when the file could actually be read. Injected so the
|
|
16
|
-
* rule stays testable on a host with no gateway.yaml.
|
|
17
|
-
*/
|
|
18
|
-
function declaredModes(endpoint, read = () => readGatewayYaml(GATEWAY_CONFIG_PATH)) {
|
|
19
|
-
const parsed = read();
|
|
20
|
-
const modes = parsed?.endpoints?.[endpoint];
|
|
21
|
-
return modes ? Object.keys(modes) : [];
|
|
5
|
+
import { getChannelSelection, getModelMemory, rememberModelSelection, setChannelSelection, setSelectionDefault, } from './config.js';
|
|
6
|
+
import { isValidThinkingLevel, modelKey, THINKING_LEVELS_BY_BACKEND, } from './engine-selection.js';
|
|
7
|
+
import { firstModelRoute, getDefaultSelection, getDefaultSelectionForBackend } from './models.js';
|
|
8
|
+
export function decideBackendSwitch(opts) {
|
|
9
|
+
const backendChanged = opts.currentBackend !== opts.targetBackend;
|
|
10
|
+
if (opts.hasHistory && backendChanged)
|
|
11
|
+
return { allowed: false, reason: 'cross-backend-live-session' };
|
|
12
|
+
return { allowed: true, backendChanged };
|
|
22
13
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function targetBackend(request) {
|
|
26
|
-
if (!request.profileName)
|
|
27
|
-
return resolveBackendForChannel(request.channel);
|
|
28
|
-
try {
|
|
29
|
-
return resolveProfileConfig(request.profileName).backend;
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
14
|
+
export function readChannelSelection(channel) {
|
|
15
|
+
return getChannelSelection(channel) ?? getDefaultSelection();
|
|
34
16
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return { ...readChannelSelection(channel), ok: false, backendChanged: false, reason };
|
|
17
|
+
function refuse(current, reason, allowed) {
|
|
18
|
+
return { ...current, ok: false, backendChanged: false, reason, ...(allowed ? { allowed } : {}) };
|
|
38
19
|
}
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const
|
|
20
|
+
/** A complete identity needs no favorite. */
|
|
21
|
+
function targetRef(request, current) {
|
|
22
|
+
const backend = request.backend ?? current.backend;
|
|
23
|
+
const changingBackend = backend !== current.backend;
|
|
24
|
+
const base = changingBackend ? getDefaultSelectionForBackend(backend) : current;
|
|
25
|
+
const model = request.model !== undefined ? request.model : base?.model;
|
|
26
|
+
const provider = request.provider !== undefined ? request.provider : (backend === 'claude' ? null : base?.provider);
|
|
27
|
+
if (model === undefined)
|
|
28
|
+
return null;
|
|
29
|
+
return { backend, provider: provider ?? null, model };
|
|
30
|
+
}
|
|
31
|
+
function mergeSelection(request, current, ref) {
|
|
32
|
+
const changed = modelKey(ref) !== modelKey(current);
|
|
33
|
+
const memory = getModelMemory()[modelKey(ref)];
|
|
34
|
+
const settings = changed ? (memory ?? { thinking: null, mode: firstModelRoute(ref, request.readGateway) }) : current;
|
|
43
35
|
return {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
provider: profile.provider,
|
|
48
|
-
thinking: profile.thinking,
|
|
49
|
-
mode: profile.mode,
|
|
50
|
-
override: config.override,
|
|
36
|
+
...ref,
|
|
37
|
+
thinking: request.thinking !== undefined ? request.thinking : settings.thinking,
|
|
38
|
+
mode: request.mode !== undefined ? request.mode : settings.mode,
|
|
51
39
|
};
|
|
52
40
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* else the channel's), BEFORE anything is written — a request that fails must leave the channel
|
|
59
|
-
* exactly as it was, not half-switched.
|
|
60
|
-
* 2. An explicit `profileName` switches first, under the shared cross-backend rule
|
|
61
|
-
* (`switchChannelProfile`). Choosing a profile means "run this profile", so its existing
|
|
62
|
-
* overrides are dropped — anything the same call still wants is re-applied in step 4.
|
|
63
|
-
* 3. A PI provider the channel's profile does not use is looked up among the profiles: if the home
|
|
64
|
-
* has one for that provider, the channel moves there instead of carrying a provider override,
|
|
65
|
-
* so the route, env and fallback chain stay the ones the user configured for that provider.
|
|
66
|
-
* 4. The remaining fields are patched onto the channel's override.
|
|
67
|
-
*/
|
|
68
|
-
export async function applyChannelSelection(request) {
|
|
69
|
-
const { channel } = request;
|
|
70
|
-
let backendChanged = false;
|
|
71
|
-
// Validate against the backend the request is HEADED for, before anything is written: a request
|
|
72
|
-
// that names both a profile and a level the new backend rejects must fail whole, not leave the
|
|
73
|
-
// channel switched.
|
|
74
|
-
const target = targetBackend(request);
|
|
75
|
-
if (!target)
|
|
76
|
-
return refuse(channel, 'unknown-profile');
|
|
77
|
-
if (request.thinking && !isValidThinkingLevel(target, request.thinking)) {
|
|
78
|
-
return { ...refuse(channel, 'invalid-thinking'), allowed: THINKING_LEVELS_BY_BACKEND[target] };
|
|
79
|
-
}
|
|
80
|
-
if (request.provider && (target !== 'pi' || !PROVIDER_NAME_RE.test(request.provider))) {
|
|
81
|
-
return refuse(channel, 'provider-not-supported');
|
|
82
|
-
}
|
|
83
|
-
if (request.mode) {
|
|
84
|
-
// The endpoint the route must belong to: the provider this same request selects, else the one
|
|
85
|
-
// the channel's profile already leaves through.
|
|
86
|
-
const endpoint = target === 'claude'
|
|
87
|
-
? CLAUDE_ENDPOINT
|
|
88
|
-
: request.provider ?? readChannelSelection(channel).provider ?? '';
|
|
89
|
-
const modes = declaredModes(endpoint, request.readGateway);
|
|
90
|
-
// No declared routes means gateway.yaml could not be read — the run falls back to a direct
|
|
91
|
-
// connection anyway, so a route cannot be checked and is not refused.
|
|
92
|
-
if (modes.length > 0 && !modes.includes(request.mode)) {
|
|
93
|
-
return { ...refuse(channel, 'invalid-mode'), allowed: modes };
|
|
94
|
-
}
|
|
41
|
+
function targetSelection(request, current) {
|
|
42
|
+
// A backend pick selects its complete default, not just its model identity.
|
|
43
|
+
if (request.backend !== undefined && request.model === undefined && request.provider === undefined) {
|
|
44
|
+
const defaults = getDefaultSelectionForBackend(request.backend);
|
|
45
|
+
return defaults ? mergeSelection(request, defaults, defaults) : null;
|
|
95
46
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
// only in force because an override carries it still needs that override. Reading the
|
|
114
|
-
// effective value here would clear it on the next pick from the same provider and quietly
|
|
115
|
-
// send the turn back to the profile's endpoint — the wrong gateway, with the wrong protocol.
|
|
116
|
-
const base = resolveRunConfig({ channel }).profile;
|
|
117
|
-
if (request.provider === base.provider) {
|
|
118
|
-
// The profile already routes there; there is nothing left for an override to say.
|
|
119
|
-
patch.provider = null;
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
// The route belongs to the endpoint being left behind; `effectiveProfile` re-derives it for
|
|
123
|
-
// the new provider, so carrying the old one would only be a stale 404 waiting to happen.
|
|
124
|
-
if (request.mode === undefined)
|
|
125
|
-
patch.mode = null;
|
|
126
|
-
const sibling = !request.profileName ? findProfileForProvider('pi', request.provider) : null;
|
|
127
|
-
if (sibling) {
|
|
128
|
-
const switched = await switchChannelProfile({ channel, name: sibling.name });
|
|
129
|
-
// Same backend as the channel's current one, so the rule cannot refuse — but if it ever
|
|
130
|
-
// did, the provider override below is still a correct (if less configured) answer.
|
|
131
|
-
if (switched.ok) {
|
|
132
|
-
backendChanged = backendChanged || switched.backendChanged;
|
|
133
|
-
clearChannelOverride(channel);
|
|
134
|
-
patch.provider = null;
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
patch.provider = request.provider;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
patch.provider = request.provider;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
else if (request.provider === null) {
|
|
146
|
-
patch.provider = null;
|
|
147
|
-
}
|
|
148
|
-
setChannelOverride(channel, patch);
|
|
149
|
-
const selection = readChannelSelection(channel);
|
|
150
|
-
// What the next brand-new conversation starts on. A pick made in the app is a statement about how
|
|
151
|
-
// the user wants to work, not about this one session, so it outlives the session that made it —
|
|
152
|
-
// and it always carries the profile it was made on, so the seed is a complete engine rather than
|
|
153
|
-
// a set of overrides with no base to hang on.
|
|
154
|
-
//
|
|
155
|
-
// Only direct (`web:`) channels seed it. A platform channel's profile is chosen for that channel;
|
|
156
|
-
// an `!thinking` in Slack has no business deciding what the desktop composer opens on.
|
|
157
|
-
if (channel.startsWith('web:') && request.seedDefault !== false) {
|
|
158
|
-
setSelectionDefault({ profileName: selection.profileName, ...(selection.override ?? {}) });
|
|
47
|
+
const ref = targetRef(request, current);
|
|
48
|
+
return ref ? mergeSelection(request, current, ref) : null;
|
|
49
|
+
}
|
|
50
|
+
const SAFE_NAME = /^[a-zA-Z0-9_-]+$/;
|
|
51
|
+
function invalidIdentity(selection) {
|
|
52
|
+
if (typeof selection.model !== 'string' || !selection.model.trim())
|
|
53
|
+
return 'invalid-model';
|
|
54
|
+
const validProvider = selection.backend === 'claude' ? selection.provider === null
|
|
55
|
+
: selection.backend === 'pi' && typeof selection.provider === 'string' && SAFE_NAME.test(selection.provider);
|
|
56
|
+
return validProvider ? null : 'provider-not-supported';
|
|
57
|
+
}
|
|
58
|
+
function validateTarget(request, current, target) {
|
|
59
|
+
const identityFailure = invalidIdentity(target);
|
|
60
|
+
if (identityFailure)
|
|
61
|
+
return refuse(current, identityFailure);
|
|
62
|
+
if (target.thinking !== null && !isValidThinkingLevel(target.backend, target.thinking)) {
|
|
63
|
+
return refuse(current, 'invalid-thinking', THINKING_LEVELS_BY_BACKEND[target.backend]);
|
|
159
64
|
}
|
|
160
|
-
return
|
|
65
|
+
return validateRoute(request, current, target);
|
|
66
|
+
}
|
|
67
|
+
function validateRoute(request, current, target) {
|
|
68
|
+
const gateway = (request.readGateway ?? (() => readGatewayYaml(GATEWAY_CONFIG_PATH)))();
|
|
69
|
+
const endpoint = target.backend === 'claude' ? 'anthropic' : target.provider;
|
|
70
|
+
const modes = Object.keys(gateway?.endpoints?.[endpoint] ?? {});
|
|
71
|
+
const validName = typeof target.mode === 'string' && SAFE_NAME.test(target.mode);
|
|
72
|
+
if (!validName || (gateway && !modes.includes(target.mode)))
|
|
73
|
+
return refuse(current, 'invalid-mode', modes);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
/** Serialize read/validate/write so simultaneous patches cannot overwrite a newer selection. */
|
|
77
|
+
const selectionWrites = new AsyncMutex();
|
|
78
|
+
export function applyChannelSelection(request) {
|
|
79
|
+
return selectionWrites.run(() => applySelection(request));
|
|
80
|
+
}
|
|
81
|
+
async function applySelection(request) {
|
|
82
|
+
const sessionId = await sessionStore.getBoundSessionId(request.channel);
|
|
83
|
+
const session = sessionId ? await sessionStore.getById(sessionId) : null;
|
|
84
|
+
const current = session?.selection ?? readChannelSelection(request.channel);
|
|
85
|
+
const target = targetSelection(request, current);
|
|
86
|
+
if (!target)
|
|
87
|
+
return refuse(current, 'no-model-for-backend');
|
|
88
|
+
const invalid = validateTarget(request, current, target);
|
|
89
|
+
if (invalid)
|
|
90
|
+
return invalid;
|
|
91
|
+
return persistSelection(request, current, target, session);
|
|
92
|
+
}
|
|
93
|
+
async function persistSelection(request, current, target, session) {
|
|
94
|
+
// Attach/resume clears channel turns, but the backend conversation still exists.
|
|
95
|
+
const hasHistory = !!(session && effectiveBackendSessionId(session))
|
|
96
|
+
|| (await sessionStore.getTurns(request.channel)).length > 0;
|
|
97
|
+
const currentBackend = session?.backend ?? current.backend;
|
|
98
|
+
const decision = decideBackendSwitch({ currentBackend, targetBackend: target.backend, hasHistory });
|
|
99
|
+
if (!decision.allowed)
|
|
100
|
+
return {
|
|
101
|
+
...refuse(current, 'cross-backend-live-session'), currentBackend, targetBackend: target.backend,
|
|
102
|
+
};
|
|
103
|
+
// Session selection wins at run time: never acknowledge a pick if its journal write failed.
|
|
104
|
+
if (session)
|
|
105
|
+
await sessionStore.updateSession(session.sessionId, { backend: target.backend, selection: target });
|
|
106
|
+
setChannelSelection(request.channel, target);
|
|
107
|
+
rememberModelSelection(target);
|
|
108
|
+
if (request.channel.startsWith('web:') && request.seedDefault !== false)
|
|
109
|
+
setSelectionDefault(target);
|
|
110
|
+
return { ...target, ok: true, backendChanged: decision.backendChanged };
|
|
161
111
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Backend } from '../../core/types/agent-types.js';
|
|
2
|
+
import { type EngineSelection, type ModelRef, type ModelsFile } from './engine-selection.js';
|
|
3
|
+
export declare function validateModelsFile(value: unknown): asserts value is ModelsFile;
|
|
4
|
+
export declare function loadModelsFile(): ModelsFile;
|
|
5
|
+
export declare function getDefaultSelection(): EngineSelection;
|
|
6
|
+
export declare function listFavorites(): ModelRef[];
|
|
7
|
+
export declare function getDefaultSelectionForBackend(backend: Backend): EngineSelection | null;
|
|
8
|
+
export declare function selectionForModel(ref: ModelRef): EngineSelection;
|
|
9
|
+
/** PI's generated route is its provider. Claude uses gateway declaration order. */
|
|
10
|
+
export declare function firstModelRoute(ref: ModelRef, readGateway?: () => import("../../core/gateway-generator.js").ParsedGateway): string;
|
|
11
|
+
/** Synchronous: use warm catalog entries, never start a provider scan to parse a command. */
|
|
12
|
+
export declare function resolveModelRef(ref: string, backend?: Backend): ModelRef;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { readGatewayYaml } from '../../core/gateway-generator.js';
|
|
2
|
+
import { modelsRepo } from '../../store/models-repo.js';
|
|
3
|
+
import { piProviderDiscovery } from '../../agent-adapter/pi/discovery.js';
|
|
4
|
+
import { GATEWAY_CONFIG_PATH } from '../pi-providers/gateway-route-store.js';
|
|
5
|
+
import { getModelMemory } from './config.js';
|
|
6
|
+
import { copySelection, modelKey, validateEngineSelection, validateModelRef, } from './engine-selection.js';
|
|
7
|
+
let validated = null;
|
|
8
|
+
export function validateModelsFile(value) {
|
|
9
|
+
const data = value;
|
|
10
|
+
validateEngineSelection(data?.default);
|
|
11
|
+
if (!Array.isArray(data.favorites))
|
|
12
|
+
throw new Error('favorites must be an array');
|
|
13
|
+
const seen = new Set();
|
|
14
|
+
for (const ref of data.favorites) {
|
|
15
|
+
validateModelRef(ref);
|
|
16
|
+
const key = modelKey(ref);
|
|
17
|
+
if (seen.has(key))
|
|
18
|
+
throw new Error(`Duplicate favorite: ${ref.model}`);
|
|
19
|
+
seen.add(key);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function loadModelsFile() {
|
|
23
|
+
try {
|
|
24
|
+
const data = modelsRepo.readSync();
|
|
25
|
+
if (data !== validated) {
|
|
26
|
+
validateModelsFile(data);
|
|
27
|
+
validated = data;
|
|
28
|
+
}
|
|
29
|
+
return { default: copySelection(data.default), favorites: data.favorites.map(copyRef) };
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new Error(`Failed to load models.json: ${error.message}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function copyRef({ backend, provider, model }) {
|
|
36
|
+
return { backend, provider, model };
|
|
37
|
+
}
|
|
38
|
+
export function getDefaultSelection() { return loadModelsFile().default; }
|
|
39
|
+
export function listFavorites() { return loadModelsFile().favorites; }
|
|
40
|
+
export function getDefaultSelectionForBackend(backend) {
|
|
41
|
+
let file;
|
|
42
|
+
try {
|
|
43
|
+
file = loadModelsFile();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if (file.default.backend === backend)
|
|
49
|
+
return file.default;
|
|
50
|
+
const favorite = file.favorites.find((ref) => ref.backend === backend);
|
|
51
|
+
return favorite ? selectionForModel(favorite) : null;
|
|
52
|
+
}
|
|
53
|
+
export function selectionForModel(ref) {
|
|
54
|
+
validateModelRef(ref);
|
|
55
|
+
const memory = getModelMemory()[modelKey(ref)];
|
|
56
|
+
return { ...copyRef(ref), ...(memory ?? { thinking: null, mode: firstModelRoute(ref) }) };
|
|
57
|
+
}
|
|
58
|
+
/** PI's generated route is its provider. Claude uses gateway declaration order. */
|
|
59
|
+
export function firstModelRoute(ref, readGateway = () => readGatewayYaml(GATEWAY_CONFIG_PATH)) {
|
|
60
|
+
if (ref.backend === 'pi')
|
|
61
|
+
return ref.provider;
|
|
62
|
+
const modes = readGateway()?.endpoints?.anthropic;
|
|
63
|
+
return Object.keys(modes ?? {})[0] ?? 'plan';
|
|
64
|
+
}
|
|
65
|
+
function explicitRef(ref) {
|
|
66
|
+
const slash = ref.indexOf('/');
|
|
67
|
+
if (slash < 0)
|
|
68
|
+
return null;
|
|
69
|
+
const result = { backend: 'pi', provider: ref.slice(0, slash), model: ref.slice(slash + 1) };
|
|
70
|
+
validateModelRef(result);
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
function resolvePiRef(model, file) {
|
|
74
|
+
const candidates = [file.default, ...file.favorites,
|
|
75
|
+
...piProviderDiscovery.peekModels().map((pair) => ({ ...pair, backend: 'pi' }))];
|
|
76
|
+
const match = candidates.find((ref) => ref.backend === 'pi' && ref.model === model);
|
|
77
|
+
if (match)
|
|
78
|
+
return copyRef(match);
|
|
79
|
+
if (file.default.backend === 'pi')
|
|
80
|
+
return { backend: 'pi', provider: file.default.provider, model };
|
|
81
|
+
throw new Error(`Unknown PI model '${model}': specify provider/model or favorite a model first`);
|
|
82
|
+
}
|
|
83
|
+
/** Synchronous: use warm catalog entries, never start a provider scan to parse a command. */
|
|
84
|
+
export function resolveModelRef(ref, backend) {
|
|
85
|
+
const model = ref.trim();
|
|
86
|
+
if (!model)
|
|
87
|
+
throw new Error('Model must be a non-empty string');
|
|
88
|
+
const explicit = explicitRef(model);
|
|
89
|
+
if (explicit)
|
|
90
|
+
return explicit;
|
|
91
|
+
const file = loadModelsFile();
|
|
92
|
+
const target = backend ?? file.default.backend;
|
|
93
|
+
return target === 'claude' ? { backend: 'claude', provider: null, model } : resolvePiRef(model, file);
|
|
94
|
+
}
|
|
@@ -70,6 +70,8 @@ export declare function trackSubagentChildren(runId: string, blockId: (index: nu
|
|
|
70
70
|
* Native CLI tasks have their own lifecycle tracker and are not represented here. */
|
|
71
71
|
export declare function getSubagentChildStatuses(sessionId: string): ReadonlyMap<string, 'running' | SubagentEndStatus>;
|
|
72
72
|
export declare function getSubagentRun(id: string): SubagentRunView | null;
|
|
73
|
+
/** Whether the session owns a background run still going, whose result will wake it. */
|
|
74
|
+
export declare function hasRunningBackgroundRuns(sessionId: string): boolean;
|
|
73
75
|
export interface SubagentRunOutcome {
|
|
74
76
|
view: SubagentRunView;
|
|
75
77
|
/** Present only once the run has completed successfully. */
|
|
@@ -133,6 +133,14 @@ export function getSubagentRun(id) {
|
|
|
133
133
|
const record = runs.get(id);
|
|
134
134
|
return record ? viewOf(record) : null;
|
|
135
135
|
}
|
|
136
|
+
/** Whether the session owns a background run still going, whose result will wake it. */
|
|
137
|
+
export function hasRunningBackgroundRuns(sessionId) {
|
|
138
|
+
for (const record of runs.values()) {
|
|
139
|
+
if (record.sessionId === sessionId && record.background && record.status === 'running')
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
136
144
|
/**
|
|
137
145
|
* Wait up to `sliceMs` for a run to settle, then answer with whatever state it is in.
|
|
138
146
|
*
|
|
@@ -2,10 +2,10 @@ import type { Backend } from '../../../agent-adapter/types.js';
|
|
|
2
2
|
import type { SubagentNotice } from '../../../core/agents/subagent/types.js';
|
|
3
3
|
import { type ModelSpec } from '../../../core/agents/subagent/model-spec.js';
|
|
4
4
|
import { type AgentRole } from '../../../core/agents/roles.js';
|
|
5
|
-
import {
|
|
5
|
+
import type { EngineSelection } from '../engine-selection.js';
|
|
6
6
|
import type { RunObserver, RunRequest } from '../../runs/request.js';
|
|
7
7
|
import type { SubagentResult, SubagentTask } from '../../../core/agents/subagent/types.js';
|
|
8
|
-
/**
|
|
8
|
+
/** The delegating turn's materialized engine context. */
|
|
9
9
|
export interface SubagentParentContext {
|
|
10
10
|
backend: Backend;
|
|
11
11
|
/** The parent run's resolved gateway route. A same-backend Claude child reuses it verbatim. */
|
|
@@ -44,12 +44,12 @@ export declare function runSubagent(request: SubagentRunRequest): Promise<Subage
|
|
|
44
44
|
* The child model comes from the task or role, then the parent's own model when that parent is
|
|
45
45
|
* Claude, and finally the configured Claude-backend default. The route follows the Claude parent
|
|
46
46
|
* when there is one; a cross-backend child uses that Claude default instead of the PI channel's
|
|
47
|
-
* mode. The
|
|
47
|
+
* mode. The child remains a one-shot run.
|
|
48
48
|
*/
|
|
49
|
-
declare function claudeChildConfig(request: SubagentRunRequest, spec: ModelSpec):
|
|
49
|
+
declare function claudeChildConfig(request: SubagentRunRequest, spec: ModelSpec): EngineSelection;
|
|
50
50
|
/** The request a Claude child runs under. A frozen one-shot role: no session to resume, no
|
|
51
51
|
* hooks, no ambient rules, no transcript log, and a leaf tool surface. */
|
|
52
|
-
declare function claudeChildRequest(request: SubagentRunRequest, config:
|
|
52
|
+
declare function claudeChildRequest(request: SubagentRunRequest, config: EngineSelection): RunRequest;
|
|
53
53
|
/** Live attribution: the child's own run events, re-stamped with the parent's block key. */
|
|
54
54
|
declare function claudeNoticeObserver(request: SubagentRunRequest): RunObserver;
|
|
55
55
|
/** Internals exposed for tests only. */
|
|
@@ -7,7 +7,7 @@ import { noticesFor } from '../../../agent-adapter/pi/child-events.js';
|
|
|
7
7
|
import { getPiEngineAdapter } from '../../runs/adapters.js';
|
|
8
8
|
import { GATEWAY_URL } from '../../costs/gateway-manager.js';
|
|
9
9
|
import { buildPiGatewaySubPath } from '../../runs/engine-spec.js';
|
|
10
|
-
import {
|
|
10
|
+
import { getDefaultSelectionForBackend } from '../models.js';
|
|
11
11
|
import { startRun } from '../../runs/service.js';
|
|
12
12
|
import { engines } from '../../runs/engines.js';
|
|
13
13
|
import { fromRole } from '../../runs/spec-loader.js';
|
|
@@ -40,7 +40,7 @@ export async function runSubagent(request) {
|
|
|
40
40
|
/**
|
|
41
41
|
* Route resolution for a `pi` child, in order: the role's own `mode:`, then the parent's route when
|
|
42
42
|
* the parent is a PI run on this same provider, and finally the provider's own name — which is the
|
|
43
|
-
* convention
|
|
43
|
+
* PI convention (`provider: deepseek` pairs with `mode: deepseek`).
|
|
44
44
|
*/
|
|
45
45
|
function resolvePiMode(request, provider) {
|
|
46
46
|
if (request.role.mode)
|
|
@@ -109,26 +109,24 @@ function piForwarder(request) {
|
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
// ─── claude child ─────────────────────────────────────────────────
|
|
112
|
-
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
return resolveProfileConfig(name);
|
|
112
|
+
/** A cross-backend child must use a Claude route, never the PI parent's route. */
|
|
113
|
+
function claudeDefaultSelection() {
|
|
114
|
+
const selection = getDefaultSelectionForBackend('claude');
|
|
115
|
+
if (!selection)
|
|
116
|
+
throw new Error('A claude subagent needs a Claude default or favorite; favorite a Claude model first.');
|
|
117
|
+
return selection;
|
|
120
118
|
}
|
|
121
119
|
/**
|
|
122
120
|
* The child model comes from the task or role, then the parent's own model when that parent is
|
|
123
121
|
* Claude, and finally the configured Claude-backend default. The route follows the Claude parent
|
|
124
122
|
* when there is one; a cross-backend child uses that Claude default instead of the PI channel's
|
|
125
|
-
* mode. The
|
|
123
|
+
* mode. The child remains a one-shot run.
|
|
126
124
|
*/
|
|
127
125
|
function claudeChildConfig(request, spec) {
|
|
128
126
|
const sameBackend = request.parent.backend === 'claude';
|
|
129
127
|
let fallback = null;
|
|
130
|
-
const claudeDefault = () => fallback ??=
|
|
131
|
-
const inheritedMode = sameBackend && request.parent.mode
|
|
128
|
+
const claudeDefault = () => fallback ??= claudeDefaultSelection();
|
|
129
|
+
const inheritedMode = sameBackend && request.parent.mode != null
|
|
132
130
|
? request.parent.mode
|
|
133
131
|
: claudeDefault().mode;
|
|
134
132
|
return {
|
|
@@ -136,29 +134,9 @@ function claudeChildConfig(request, spec) {
|
|
|
136
134
|
backend: 'claude',
|
|
137
135
|
mode: inheritedMode,
|
|
138
136
|
provider: null,
|
|
139
|
-
extraEnv: {},
|
|
140
|
-
extraOption: {},
|
|
141
137
|
thinking: spec.thinking ?? null,
|
|
142
138
|
};
|
|
143
139
|
}
|
|
144
|
-
/** Wrap the child's resolved config as the run's profile: the run layer plans its attempt chain
|
|
145
|
-
* from `request.profile`, so a synthesized single-attempt profile is how a role/task model reaches
|
|
146
|
-
* the spawn without any named profile being consulted. */
|
|
147
|
-
function claudeChildProfile(config) {
|
|
148
|
-
return {
|
|
149
|
-
// Unnamed on purpose: no profile was consulted for the child, so none is attested to it.
|
|
150
|
-
name: '',
|
|
151
|
-
model: config.model,
|
|
152
|
-
backend: config.backend,
|
|
153
|
-
mode: config.mode,
|
|
154
|
-
provider: config.provider ?? null,
|
|
155
|
-
extraEnv: config.extraEnv ?? {},
|
|
156
|
-
extraOption: config.extraOption ?? {},
|
|
157
|
-
thinking: config.thinking ?? null,
|
|
158
|
-
maxOutputTokens: config.maxOutputTokens ?? null,
|
|
159
|
-
fallback: [],
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
140
|
/**
|
|
163
141
|
* A child's own pool slot, never the parent's. Keying a child on the parent's channel put it on
|
|
164
142
|
* the slot the parent's interactive session already occupies (`engineKey === channel` there too),
|
|
@@ -182,7 +160,7 @@ function claudeChildRequest(request, config) {
|
|
|
182
160
|
backendSessionId: null,
|
|
183
161
|
engineKey: childEngineKey(request, runId),
|
|
184
162
|
},
|
|
185
|
-
|
|
163
|
+
selection: config,
|
|
186
164
|
// The child runs where the caller asked (the parent's workspace), not where the server lives.
|
|
187
165
|
cwd: request.cwd,
|
|
188
166
|
spec: fromRole(request.role, 'claude', { mcpAllowlist: mcpToolAllowlist ?? null }),
|
|
@@ -208,7 +186,6 @@ function claudeChildRequest(request, config) {
|
|
|
208
186
|
loadRules: false, // loadCortexRules: false
|
|
209
187
|
mcpComposition: 'direct',
|
|
210
188
|
mcpToolAllowlist,
|
|
211
|
-
browserCdpEndpoint: null,
|
|
212
189
|
captureTranscripts: false, // captureTranscriptLogs: false
|
|
213
190
|
},
|
|
214
191
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Backend } from '../../agent-adapter/types.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { ModelRef } from '../agents/engine-selection.js';
|
|
3
3
|
import { type ClaudeAuthStatus } from './cc-auth-cli.js';
|
|
4
4
|
import { type LoadPiRuntimeOptions, type PiRuntimeLoadResult } from './pi-runtime.js';
|
|
5
5
|
export type AuthType = 'oauth' | 'api_key';
|
|
@@ -38,7 +38,7 @@ export interface AuthStatusSnapshot {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
export declare function preferredAuthType(snapshot: AuthStatusSnapshot, backend: 'claude' | 'pi', provider: string): AuthType | null;
|
|
41
|
-
interface
|
|
41
|
+
interface SelectionReference {
|
|
42
42
|
backend: Backend;
|
|
43
43
|
provider: string | null;
|
|
44
44
|
}
|
|
@@ -55,8 +55,8 @@ export interface GetAuthStatusOptions {
|
|
|
55
55
|
};
|
|
56
56
|
getClaudeMode?: () => string;
|
|
57
57
|
getActiveBackend?: () => Backend;
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
listFavorites?: () => ModelRef[];
|
|
59
|
+
getDefaultSelection?: () => SelectionReference | null;
|
|
60
60
|
readClaudeAuthStatus?: () => Promise<ClaudeAuthStatus>;
|
|
61
61
|
}
|
|
62
62
|
export declare function getAuthStatus(options?: GetAuthStatusOptions): Promise<AuthStatusSnapshot>;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
import { readClaudeStore } from '../../core/claude-credentials.js';
|
|
4
4
|
import { piUserAuthPath } from '../../core/pi-sdk.js';
|
|
5
5
|
import { resolveConfiguredDefaultRun } from '../runs/config-resolver.js';
|
|
6
|
-
import {
|
|
6
|
+
import { modelsRepo } from '../../store/models-repo.js';
|
|
7
7
|
import { getSavedApiEnv as readSavedApiEnv } from './anthropic-env.js';
|
|
8
|
-
import {
|
|
8
|
+
import { listFavorites as readFavorites } from '../agents/models.js';
|
|
9
9
|
import { readClaudeAuthStatus as readInstalledClaudeAuthStatus, } from './cc-auth-cli.js';
|
|
10
10
|
import { loadPiRuntime as loadInstalledPiRuntime, } from './pi-runtime.js';
|
|
11
11
|
export function preferredAuthType(snapshot, backend, provider) {
|
|
@@ -207,54 +207,43 @@ function buildPiAccount(runtime, readStored, provider, authPath, nowMs, inUse) {
|
|
|
207
207
|
return unknownPiAccount(provider, status.source ?? null, inUse);
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
function
|
|
211
|
-
|
|
212
|
-
if (backend === 'claude')
|
|
210
|
+
function addModelReference(usage, entry) {
|
|
211
|
+
if (entry.backend === 'claude')
|
|
213
212
|
usage.claude = true;
|
|
214
|
-
if (backend === 'pi' && entry.provider)
|
|
213
|
+
if (entry.backend === 'pi' && entry.provider)
|
|
215
214
|
usage.pi.add(entry.provider);
|
|
216
215
|
}
|
|
217
|
-
function
|
|
218
|
-
|
|
219
|
-
addProfileReference(usage, profile);
|
|
220
|
-
for (const fallback of profile.fallback ?? [])
|
|
221
|
-
addProfileReference(usage, fallback, primaryBackend);
|
|
222
|
-
}
|
|
223
|
-
function defaultActiveProfileConfig() {
|
|
224
|
-
const profile = resolveProfileConfig(getActiveProfile());
|
|
225
|
-
return { backend: profile.backend, provider: profile.provider };
|
|
216
|
+
function configuredDefault() {
|
|
217
|
+
return modelsRepo.readIfPresent()?.default ? resolveConfiguredDefaultRun() : null;
|
|
226
218
|
}
|
|
227
|
-
/** The backend and Claude mode a channel with no selection of its own will run (D5): the default
|
|
228
|
-
* profile's, replacing the retired daemon-wide `backend` / `claudeMode` fields. */
|
|
229
219
|
function defaultRunBackend() {
|
|
230
|
-
return
|
|
220
|
+
return configuredDefault()?.backend ?? null;
|
|
231
221
|
}
|
|
232
222
|
function defaultClaudeMode() {
|
|
233
|
-
return
|
|
223
|
+
return configuredDefault()?.mode ?? 'plan';
|
|
234
224
|
}
|
|
235
225
|
function collectInUse(options) {
|
|
236
226
|
const usage = { claude: false, pi: new Set() };
|
|
237
227
|
try {
|
|
238
|
-
for (const
|
|
239
|
-
|
|
228
|
+
for (const model of (options.listFavorites ?? readFavorites)())
|
|
229
|
+
addModelReference(usage, model);
|
|
240
230
|
}
|
|
241
231
|
catch {
|
|
242
|
-
// A broken
|
|
232
|
+
// A broken models file must not hide credential state.
|
|
243
233
|
}
|
|
244
|
-
//
|
|
245
|
-
// default profile runs, which is what an unconfigured channel will pick up.
|
|
234
|
+
// Include the configured default even if it is not favorited.
|
|
246
235
|
const backend = (options.getActiveBackend ?? defaultRunBackend)();
|
|
247
236
|
if (backend === 'claude')
|
|
248
237
|
usage.claude = true;
|
|
249
238
|
if (backend !== 'pi')
|
|
250
239
|
return usage;
|
|
251
240
|
try {
|
|
252
|
-
const active = (options.
|
|
253
|
-
if (active
|
|
254
|
-
usage
|
|
241
|
+
const active = (options.getDefaultSelection ?? configuredDefault)();
|
|
242
|
+
if (active)
|
|
243
|
+
addModelReference(usage, active);
|
|
255
244
|
}
|
|
256
245
|
catch {
|
|
257
|
-
//
|
|
246
|
+
// Default selection resolution is advisory for inUse only.
|
|
258
247
|
}
|
|
259
248
|
return usage;
|
|
260
249
|
}
|