@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/entry/init.js
CHANGED
|
@@ -11,11 +11,13 @@ export { isGitInstalled, ensureGitInstalled, getGitInstallHint } from './init-gi
|
|
|
11
11
|
import { onboardInitAuth } from './init-auth.js';
|
|
12
12
|
import * as clack from '@clack/prompts';
|
|
13
13
|
import { buildCoreConfig, buildEmptyConfig, buildFullConfig, buildInteractionConfig, } from '../core/config-generator.js';
|
|
14
|
-
import { discoverEndpoints, writeMergedGatewayYaml,
|
|
15
|
-
import {
|
|
14
|
+
import { discoverEndpoints, writeMergedGatewayYaml, validateModelsAgainstGateway } from '../core/gateway-generator.js';
|
|
15
|
+
import { readExistingModels, writeModelsJson, listChoices, recommendedChoice } from '../core/models-generator.js';
|
|
16
16
|
import { ENVIRONMENTS_DIRNAME, mergeDefaultEnvironments } from '../domain/agents/environments/index.js';
|
|
17
17
|
import { createLogger } from '../core/log.js';
|
|
18
|
-
import { INSTALL_ROOT, DEFAULTS_DIR } from '../core/paths.js';
|
|
18
|
+
import { INSTALL_ROOT, DEFAULTS_DIR, DATA_DIR } from '../core/paths.js';
|
|
19
|
+
import { applyInitTelemetry, parseInitTelemetryAnswer } from '../domain/telemetry/init-answer.js';
|
|
20
|
+
import { recordFunnelStep } from '../domain/telemetry/funnel.js';
|
|
19
21
|
import { writeUsageSharing } from '../domain/costs/aistatus-config.js';
|
|
20
22
|
import { t, setLocale, normalizeLocale, detectSystemLocale } from '../core/i18n.js';
|
|
21
23
|
import { CLIENT_TOKEN_ENV } from '../core/auth.js';
|
|
@@ -119,11 +121,11 @@ export function parseInitAnswersJson(raw) {
|
|
|
119
121
|
slackConfig: input.slackConfig,
|
|
120
122
|
feishuConfig: input.feishuConfig,
|
|
121
123
|
gatewayUsage,
|
|
124
|
+
telemetry: parseInitTelemetryAnswer(input.telemetry),
|
|
122
125
|
installService: input.installService === true,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
? input.extraProfiles.map(parseChoiceValue).filter((c) => !!c)
|
|
126
|
+
defaultChoice: parseChoiceValue(input.defaultChoice),
|
|
127
|
+
favorites: Array.isArray(input.favorites)
|
|
128
|
+
? input.favorites.map(parseChoiceValue).filter((c) => !!c)
|
|
127
129
|
: undefined,
|
|
128
130
|
localUi: parseLocalUi(input.localUi),
|
|
129
131
|
localClient: parseLocalClientAnswer(input.localClient),
|
|
@@ -145,8 +147,8 @@ function parseChoiceLine(raw) {
|
|
|
145
147
|
model: trimmed.substring(colonIdx + 1).trim(),
|
|
146
148
|
};
|
|
147
149
|
}
|
|
148
|
-
/** Parse comma-separated "mode:model"
|
|
149
|
-
function
|
|
150
|
+
/** Parse comma-separated "mode:model" favorites. Returns undefined for empty. */
|
|
151
|
+
function parseFavoritesLine(raw) {
|
|
150
152
|
if (!raw)
|
|
151
153
|
return undefined;
|
|
152
154
|
const trimmed = raw.trim();
|
|
@@ -209,7 +211,6 @@ export function generateDotEnvContent(answers) {
|
|
|
209
211
|
/** Generate default agent-state.json content (compact JSON, single line). */
|
|
210
212
|
export function generateDefaultModeJson() {
|
|
211
213
|
return JSON.stringify({
|
|
212
|
-
activeProfile: '__active__',
|
|
213
214
|
defaultAgent: 'main',
|
|
214
215
|
});
|
|
215
216
|
}
|
|
@@ -845,6 +846,7 @@ async function collectAnswersInteractive(paths) {
|
|
|
845
846
|
handleCancel(email);
|
|
846
847
|
gatewayUsage = { enabled: true, name: name, org: org, email: email };
|
|
847
848
|
}
|
|
849
|
+
const telemetry = await askTelemetry();
|
|
848
850
|
// Step 5: Service registration
|
|
849
851
|
const wantService = await clack.confirm({
|
|
850
852
|
message: t('init.serviceRegister.prompt'),
|
|
@@ -860,9 +862,15 @@ async function collectAnswersInteractive(paths) {
|
|
|
860
862
|
slackConfig,
|
|
861
863
|
feishuConfig,
|
|
862
864
|
gatewayUsage,
|
|
865
|
+
telemetry,
|
|
863
866
|
installService: wantService,
|
|
864
867
|
};
|
|
865
868
|
}
|
|
869
|
+
async function askTelemetry() {
|
|
870
|
+
const enabled = await clack.confirm({ message: t('init.telemetry.prompt'), initialValue: true });
|
|
871
|
+
handleCancel(enabled);
|
|
872
|
+
return { enabled: enabled };
|
|
873
|
+
}
|
|
866
874
|
// ─── Non-interactive prompts (piped stdin) ───────────────────────
|
|
867
875
|
async function collectAnswersNonInteractive() {
|
|
868
876
|
const lines = [];
|
|
@@ -870,73 +878,48 @@ async function collectAnswersNonInteractive() {
|
|
|
870
878
|
for await (const line of rl) {
|
|
871
879
|
lines.push(line);
|
|
872
880
|
}
|
|
873
|
-
// Line format:
|
|
874
|
-
// backends, platform, gatewayEnabled, name, org, email, installService
|
|
875
|
-
// [+ platform-specific token blocks, concatenated in fixed order: slack first, then feishu]
|
|
876
|
-
// `platform` is a comma-separated list (e.g. "slack,feishu"); single values are back-compat.
|
|
877
|
-
const [backendsRaw, platformRaw, gatewayEnabledRaw, name, org, email, installServiceRaw] = lines;
|
|
878
|
-
const backends = (backendsRaw || 'pi')
|
|
879
|
-
.split(',')
|
|
880
|
-
.map(s => s.trim())
|
|
881
|
-
.filter((s) => s === 'claude' || s === 'pi');
|
|
882
|
-
// Parse the platform list, keeping valid values in order and de-duplicating.
|
|
883
|
-
const platforms = [];
|
|
884
|
-
const seenPlatforms = new Set();
|
|
885
|
-
for (const raw of (platformRaw || '').split(',')) {
|
|
886
|
-
const p = raw.trim().toLowerCase();
|
|
887
|
-
if ((p === 'slack' || p === 'feishu') && !seenPlatforms.has(p)) {
|
|
888
|
-
seenPlatforms.add(p);
|
|
889
|
-
platforms.push(p);
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
const gatewayChoice = gatewayEnabledRaw?.trim().toLowerCase();
|
|
893
881
|
log.info('Cortex Initialization (non-interactive)');
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
882
|
+
return parseInitAnswersLines(lines);
|
|
883
|
+
}
|
|
884
|
+
function stdinPlatforms(raw = '') {
|
|
885
|
+
const values = raw.split(',').map(value => value.trim().toLowerCase());
|
|
886
|
+
return [...new Set(values.filter((value) => value === 'slack' || value === 'feishu'))];
|
|
887
|
+
}
|
|
888
|
+
/** Token blocks always use Slack then Feishu order, regardless of platform display order. */
|
|
889
|
+
function stdinPlatformTokens(lines, platforms) {
|
|
899
890
|
let slackConfig;
|
|
900
891
|
let feishuConfig;
|
|
901
892
|
let cursor = 7;
|
|
902
893
|
if (platforms.includes('slack') && lines.length >= cursor + 3) {
|
|
903
|
-
slackConfig = {
|
|
904
|
-
signingSecret: lines[cursor] || '',
|
|
905
|
-
appToken: lines[cursor + 1] || '',
|
|
906
|
-
botToken: lines[cursor + 2] || '',
|
|
907
|
-
};
|
|
894
|
+
slackConfig = { signingSecret: lines[cursor] || '', appToken: lines[cursor + 1] || '', botToken: lines[cursor + 2] || '' };
|
|
908
895
|
cursor += 3;
|
|
909
896
|
}
|
|
910
897
|
if (platforms.includes('feishu') && lines.length >= cursor + 3) {
|
|
911
|
-
const
|
|
912
|
-
feishuConfig = {
|
|
913
|
-
|
|
914
|
-
appSecret: lines[cursor + 1] || '',
|
|
915
|
-
domain: (domainVal === 'feishu' || domainVal === 'lark')
|
|
916
|
-
? domainVal
|
|
917
|
-
: undefined,
|
|
918
|
-
};
|
|
898
|
+
const domain = (lines[cursor + 2] || '').trim().toLowerCase();
|
|
899
|
+
feishuConfig = { appId: lines[cursor] || '', appSecret: lines[cursor + 1] || '',
|
|
900
|
+
domain: domain === 'feishu' || domain === 'lark' ? domain : undefined };
|
|
919
901
|
cursor += 3;
|
|
920
902
|
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
903
|
+
return { slackConfig, feishuConfig, cursor };
|
|
904
|
+
}
|
|
905
|
+
/** Seven setup lines, platform token blocks, then defaultChoice and comma-separated favorites. */
|
|
906
|
+
export function parseInitAnswersLines(lines) {
|
|
907
|
+
const [backendsRaw, platformRaw, gatewayEnabledRaw, name, org, email, installServiceRaw] = lines;
|
|
908
|
+
const backends = (backendsRaw || 'pi').split(',').map(s => s.trim())
|
|
909
|
+
.filter((s) => s === 'claude' || s === 'pi');
|
|
910
|
+
const platforms = stdinPlatforms(platformRaw);
|
|
911
|
+
const { slackConfig, feishuConfig, cursor } = stdinPlatformTokens(lines, platforms);
|
|
912
|
+
const gatewayChoice = gatewayEnabledRaw?.trim().toLowerCase();
|
|
925
913
|
return {
|
|
926
914
|
lang: process.env.CORTEX_LANG ? normalizeLocale(process.env.CORTEX_LANG) : detectSystemLocale(),
|
|
927
915
|
backends: backends.length > 0 ? backends : ['claude'],
|
|
928
|
-
machineName: os.hostname(),
|
|
929
|
-
gpuCount: detectGpuCount(),
|
|
930
|
-
platforms,
|
|
931
|
-
slackConfig,
|
|
932
|
-
feishuConfig,
|
|
916
|
+
machineName: os.hostname(), gpuCount: detectGpuCount(), platforms, slackConfig, feishuConfig,
|
|
933
917
|
gatewayUsage: gatewayChoice === 'y'
|
|
934
918
|
? { enabled: true, name: name || '', org: org || '', email: email || '' }
|
|
935
919
|
: gatewayChoice === 'n' ? { enabled: false } : undefined,
|
|
936
920
|
installService: installServiceRaw?.toLowerCase() === 'y',
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
extraProfiles,
|
|
921
|
+
defaultChoice: parseChoiceLine(lines[cursor]),
|
|
922
|
+
favorites: parseFavoritesLine(lines[cursor + 1]),
|
|
940
923
|
};
|
|
941
924
|
}
|
|
942
925
|
// ─── Directory creation ─────────────────────────────────────────
|
|
@@ -1112,190 +1095,75 @@ export function writeDotEnv(paths, answers, force) {
|
|
|
1112
1095
|
}
|
|
1113
1096
|
writeFileSync(envPath, content);
|
|
1114
1097
|
}
|
|
1115
|
-
// ─── Gateway &
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
const data = JSON.parse(readFileSync(profilesPath, 'utf-8'));
|
|
1123
|
-
return !!(data?.profiles?.plan || data?.profiles?.execute);
|
|
1124
|
-
}
|
|
1125
|
-
catch {
|
|
1126
|
-
return false;
|
|
1127
|
-
}
|
|
1098
|
+
// ─── Gateway & model auto-setup ──────────────────────────────
|
|
1099
|
+
async function confirmDefaultOverwrite(configDir) {
|
|
1100
|
+
if (!readExistingModels(configDir)?.default)
|
|
1101
|
+
return true;
|
|
1102
|
+
const confirm = await clack.confirm({ message: t('init.gatewaySetup.overwritePrompt'), initialValue: false });
|
|
1103
|
+
handleCancel(confirm);
|
|
1104
|
+
return confirm;
|
|
1128
1105
|
}
|
|
1129
|
-
/**
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
* Returns `overwrite: false` if the user declined to overwrite an existing profile — in that
|
|
1134
|
-
* case all *Choice / *Fallback fields are undefined.
|
|
1135
|
-
*/
|
|
1136
|
-
async function pickPlanExecuteInteractive(endpoints, configDir) {
|
|
1137
|
-
// If existing profiles.json has plan/execute, ask before overwriting
|
|
1138
|
-
if (detectExistingPlanOrExecute(configDir)) {
|
|
1139
|
-
const confirm = await clack.confirm({
|
|
1140
|
-
message: t('init.gatewaySetup.overwritePrompt'),
|
|
1141
|
-
initialValue: false,
|
|
1142
|
-
});
|
|
1143
|
-
handleCancel(confirm);
|
|
1144
|
-
if (!confirm) {
|
|
1145
|
-
return { overwrite: false };
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1106
|
+
/** Pick a recommended default and favorites. The default is included even if untoggled. */
|
|
1107
|
+
async function pickModelsInteractive(endpoints, configDir) {
|
|
1108
|
+
if (!await confirmDefaultOverwrite(configDir))
|
|
1109
|
+
return { overwrite: false };
|
|
1148
1110
|
const choices = listChoices(endpoints);
|
|
1149
|
-
if (choices.length
|
|
1111
|
+
if (!choices.length)
|
|
1150
1112
|
return { overwrite: true };
|
|
1151
|
-
const
|
|
1152
|
-
const
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
const options = choices.map(c => ({
|
|
1157
|
-
value: formatValue(c),
|
|
1158
|
-
label: `${c.mode} / ${c.model}`,
|
|
1159
|
-
}));
|
|
1160
|
-
// Pre-select the same model a non-interactive setup would pick.
|
|
1161
|
-
const firstChoiceValue = formatValue(recommendedChoice(endpoints) ?? choices[0]);
|
|
1162
|
-
const planSel = await clack.select({
|
|
1163
|
-
message: t('init.gatewaySetup.planPrompt'),
|
|
1164
|
-
options,
|
|
1165
|
-
initialValue: firstChoiceValue,
|
|
1113
|
+
const format = (choice) => `${choice.mode}:${choice.model}`;
|
|
1114
|
+
const options = choices.map(choice => ({ value: format(choice), label: `${choice.mode} / ${choice.model}` }));
|
|
1115
|
+
const selected = await clack.select({
|
|
1116
|
+
message: t('init.gatewaySetup.defaultPrompt'), options,
|
|
1117
|
+
initialValue: format(recommendedChoice(endpoints) ?? choices[0]),
|
|
1166
1118
|
});
|
|
1167
|
-
handleCancel(
|
|
1168
|
-
const
|
|
1169
|
-
message: t('init.gatewaySetup.
|
|
1170
|
-
|
|
1171
|
-
initialValue: firstChoiceValue,
|
|
1119
|
+
handleCancel(selected);
|
|
1120
|
+
const favorites = await clack.multiselect({
|
|
1121
|
+
message: t('init.gatewaySetup.favoritesPrompt'), options,
|
|
1122
|
+
required: false, initialValues: [selected],
|
|
1172
1123
|
});
|
|
1173
|
-
handleCancel(
|
|
1174
|
-
const
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
const
|
|
1181
|
-
|
|
1182
|
-
if (
|
|
1183
|
-
const
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
required: false,
|
|
1187
|
-
initialValues: [],
|
|
1188
|
-
});
|
|
1189
|
-
handleCancel(sel);
|
|
1190
|
-
const arr = sel;
|
|
1191
|
-
if (arr.length > 0)
|
|
1192
|
-
planFallback = arr.map(parseValue);
|
|
1193
|
-
}
|
|
1194
|
-
let executeFallback;
|
|
1195
|
-
if (execFallbackOptions.length > 0) {
|
|
1196
|
-
const sel = await clack.multiselect({
|
|
1197
|
-
message: t('init.gatewaySetup.executeFallbackPrompt'),
|
|
1198
|
-
options: execFallbackOptions,
|
|
1199
|
-
required: false,
|
|
1200
|
-
initialValues: [],
|
|
1201
|
-
});
|
|
1202
|
-
handleCancel(sel);
|
|
1203
|
-
const arr = sel;
|
|
1204
|
-
if (arr.length > 0)
|
|
1205
|
-
executeFallback = arr.map(parseValue);
|
|
1206
|
-
}
|
|
1207
|
-
// ── Extra profiles: additional models to register as standalone named profiles ──
|
|
1208
|
-
let extraProfiles;
|
|
1209
|
-
if (options.length > 0) {
|
|
1210
|
-
const sel = await clack.multiselect({
|
|
1211
|
-
message: t('init.gatewaySetup.extraProfilesPrompt'),
|
|
1212
|
-
options,
|
|
1213
|
-
required: false,
|
|
1214
|
-
initialValues: [],
|
|
1215
|
-
});
|
|
1216
|
-
handleCancel(sel);
|
|
1217
|
-
const arr = sel;
|
|
1218
|
-
if (arr.length > 0)
|
|
1219
|
-
extraProfiles = arr.map(parseValue);
|
|
1124
|
+
handleCancel(favorites);
|
|
1125
|
+
const values = new Set([selected, ...favorites]);
|
|
1126
|
+
return { defaultChoice: parseChoiceLine(selected), favorites: [...values].map(v => parseChoiceLine(v)), overwrite: true };
|
|
1127
|
+
}
|
|
1128
|
+
function writeDiscoveredGateway(endpoints, configDir) {
|
|
1129
|
+
const summary = endpoints.map(ep => ` ${ep.mode}/${ep.endpoint}: ${ep.models.slice(0, 3).join(', ')}${ep.models.length > 3 ? ', ...' : ''} (${ep.keys.length > 0 ? 'with key' : 'passthrough'})`).join('\n');
|
|
1130
|
+
clack.log.success(t('init.gatewaySetup.discovered', { count: endpoints.length, summary }));
|
|
1131
|
+
const { path: gatewayPath, result } = writeMergedGatewayYaml(endpoints, configDir);
|
|
1132
|
+
clack.log.success(t('init.gatewaySetup.gatewayWritten', { path: gatewayPath }));
|
|
1133
|
+
if (result.droppedFromDiscovery.length > 0) {
|
|
1134
|
+
const list = result.droppedFromDiscovery.map(p => `${p.mode}/${p.endpoint}`).join(', ');
|
|
1135
|
+
clack.log.warn(t('init.gatewaySetup.preservedModes', { count: result.droppedFromDiscovery.length, list }));
|
|
1136
|
+
clack.log.info(t('init.gatewaySetup.preservedModesHint'));
|
|
1220
1137
|
}
|
|
1221
|
-
return
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1138
|
+
return result.endpoints;
|
|
1139
|
+
}
|
|
1140
|
+
function reportModelsSetup(configDir, endpoints) {
|
|
1141
|
+
const models = readExistingModels(configDir);
|
|
1142
|
+
clack.log.info(t('init.gatewaySetup.generatedModels', {
|
|
1143
|
+
names: models.favorites.map(ref => ref.model).join(', '), default: models.default.model,
|
|
1144
|
+
}));
|
|
1145
|
+
const issues = validateModelsAgainstGateway(endpoints, configDir);
|
|
1146
|
+
if (!issues.length)
|
|
1147
|
+
return;
|
|
1148
|
+
const lines = issues.map(i => ` - ${i.model}: ${i.reason}`).join('\n');
|
|
1149
|
+
clack.log.warn(t('init.gatewaySetup.modelIssues', { count: issues.length, lines }));
|
|
1150
|
+
clack.log.info(t('init.gatewaySetup.modelIssuesHint'));
|
|
1229
1151
|
}
|
|
1230
1152
|
/** Returns false when no backend is logged in yet, so nothing could be generated. */
|
|
1231
1153
|
async function runGatewaySetup(backends, paths, gatewayConfigDir, answers, interactive = false) {
|
|
1232
|
-
// Discover endpoints from Claude/PI local configs — filtered by user-selected backends
|
|
1233
1154
|
const endpoints = await discoverEndpoints(backends);
|
|
1234
|
-
if (endpoints.length
|
|
1155
|
+
if (!endpoints.some(endpoint => endpoint.models.length > 0)) {
|
|
1235
1156
|
clack.log.warn(t('init.gatewaySetup.noBackends'));
|
|
1236
1157
|
clack.log.info(t('init.gatewaySetup.rerunHint'));
|
|
1237
1158
|
return false;
|
|
1238
1159
|
}
|
|
1239
|
-
|
|
1240
|
-
const
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
const { path: gatewayPath, result: mergeResult } = writeMergedGatewayYaml(endpoints, gatewayConfigDir);
|
|
1247
|
-
clack.log.success(t('init.gatewaySetup.gatewayWritten', { path: gatewayPath }));
|
|
1248
|
-
if (mergeResult.droppedFromDiscovery.length > 0) {
|
|
1249
|
-
const list = mergeResult.droppedFromDiscovery.map(p => `${p.mode}/${p.endpoint}`).join(', ');
|
|
1250
|
-
clack.log.warn(t('init.gatewaySetup.preservedModes', { count: mergeResult.droppedFromDiscovery.length, list }));
|
|
1251
|
-
clack.log.info(t('init.gatewaySetup.preservedModesHint'));
|
|
1252
|
-
}
|
|
1253
|
-
// Resolve plan/execute choices + fallback chains + extra profiles + overwrite intent.
|
|
1254
|
-
let planChoice = answers?.planChoice;
|
|
1255
|
-
let executeChoice = answers?.executeChoice;
|
|
1256
|
-
let planFallback;
|
|
1257
|
-
let executeFallback;
|
|
1258
|
-
let extraProfiles = answers?.extraProfiles;
|
|
1259
|
-
let overwrite;
|
|
1260
|
-
if (interactive) {
|
|
1261
|
-
// Interactive: prompt for selection (with overwrite confirmation if needed)
|
|
1262
|
-
const picked = await pickPlanExecuteInteractive(endpoints, paths.CONFIG_DIR);
|
|
1263
|
-
planChoice = picked.planChoice ?? planChoice;
|
|
1264
|
-
executeChoice = picked.executeChoice ?? executeChoice;
|
|
1265
|
-
planFallback = picked.planFallback;
|
|
1266
|
-
executeFallback = picked.executeFallback;
|
|
1267
|
-
extraProfiles = picked.extraProfiles ?? extraProfiles;
|
|
1268
|
-
overwrite = picked.overwrite;
|
|
1269
|
-
}
|
|
1270
|
-
else {
|
|
1271
|
-
// Non-interactive: stdin already provided choices (or empty → lex-first default).
|
|
1272
|
-
// Fallback chains are not configurable via stdin in this iteration — extend the stdin
|
|
1273
|
-
// protocol if scripted installs need fallback.
|
|
1274
|
-
overwrite = !!(answers?.planChoice || answers?.executeChoice || answers?.extraProfiles);
|
|
1275
|
-
}
|
|
1276
|
-
// Generate profiles.json
|
|
1277
|
-
const profilesPath = writeProfilesJson(endpoints, {
|
|
1278
|
-
outputDir: paths.CONFIG_DIR,
|
|
1279
|
-
planChoice,
|
|
1280
|
-
executeChoice,
|
|
1281
|
-
planFallback,
|
|
1282
|
-
executeFallback,
|
|
1283
|
-
extraProfiles,
|
|
1284
|
-
overwrite,
|
|
1285
|
-
});
|
|
1286
|
-
clack.log.success(t('init.gatewaySetup.profilesWritten', { path: profilesPath }));
|
|
1287
|
-
// Show profile summary (reflects what was actually generated, not what was merged)
|
|
1288
|
-
const profiles = generateProfiles(endpoints, { planChoice, executeChoice, planFallback, executeFallback, extraProfiles });
|
|
1289
|
-
const profileNames = Object.keys(profiles.profiles).join(', ');
|
|
1290
|
-
clack.log.info(t('init.gatewaySetup.generatedProfiles', { names: profileNames, default: profiles.defaultProfile }));
|
|
1291
|
-
// Validate profile ↔ gateway mode coupling. A profile referencing a non-existent gateway mode is
|
|
1292
|
-
// exactly what produces a silent `400 Unknown mode: <x>` at runtime. Non-fatal — warn only.
|
|
1293
|
-
const issues = validateProfilesAgainstGateway(mergeResult.endpoints, paths.CONFIG_DIR);
|
|
1294
|
-
if (issues.length > 0) {
|
|
1295
|
-
const lines = issues.map(i => ` - ${i.profile}: ${i.reason}`).join('\n');
|
|
1296
|
-
clack.log.warn(t('init.gatewaySetup.profileIssues', { count: issues.length, lines }));
|
|
1297
|
-
clack.log.info(t('init.gatewaySetup.profileIssuesHint'));
|
|
1298
|
-
}
|
|
1160
|
+
const mergedEndpoints = writeDiscoveredGateway(endpoints, gatewayConfigDir);
|
|
1161
|
+
const options = interactive
|
|
1162
|
+
? await pickModelsInteractive(endpoints, paths.CONFIG_DIR)
|
|
1163
|
+
: { ...answers, overwrite: !!answers?.defaultChoice };
|
|
1164
|
+
const modelsPath = writeModelsJson(endpoints, { ...options, outputDir: paths.CONFIG_DIR });
|
|
1165
|
+
clack.log.success(t('init.gatewaySetup.modelsWritten', { path: modelsPath }));
|
|
1166
|
+
reportModelsSetup(paths.CONFIG_DIR, mergedEndpoints);
|
|
1299
1167
|
return true;
|
|
1300
1168
|
}
|
|
1301
1169
|
/**
|
|
@@ -1327,6 +1195,38 @@ export async function runInit(options = {}) {
|
|
|
1327
1195
|
emitter?.restore();
|
|
1328
1196
|
}
|
|
1329
1197
|
}
|
|
1198
|
+
function applySharingChoices(paths, answers, options) {
|
|
1199
|
+
if (answers.gatewayUsage)
|
|
1200
|
+
writeUsageSharing(answers.gatewayUsage, options.gatewayConfigDir);
|
|
1201
|
+
if (answers.telemetry) {
|
|
1202
|
+
applyInitTelemetry(answers.telemetry, { configDir: paths.CONFIG_DIR, storeDir: paths.STORE_DIR });
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
async function detectAuthAndGateway(paths, answers, options, interactive, emitter) {
|
|
1206
|
+
const emit = (event) => emitter?.emit(event);
|
|
1207
|
+
const authBackends = await onboardInitAuth(interactive, event => {
|
|
1208
|
+
emit(event);
|
|
1209
|
+
if (!emitter && !interactive)
|
|
1210
|
+
process.stdout.write(`${JSON.stringify(event)}\n`);
|
|
1211
|
+
});
|
|
1212
|
+
if (interactive) {
|
|
1213
|
+
const configured = authBackends.length > 0
|
|
1214
|
+
&& await runGatewaySetup(authBackends, paths, options.gatewayConfigDir, answers, true);
|
|
1215
|
+
emit({ step: 'gateway', state: configured ? 'ok' : 'skip' });
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
// Non-interactive: auto-detect silently, passing caller-supplied choices. A machine with no
|
|
1219
|
+
// backend logged in yet yields no endpoints — expected on a fresh desktop install, where the
|
|
1220
|
+
// user logs in from the workbench afterwards and the server syncs models from that login.
|
|
1221
|
+
try {
|
|
1222
|
+
const configured = await runGatewaySetup(answers.backends, paths, options.gatewayConfigDir, answers);
|
|
1223
|
+
emit({ step: 'gateway', state: configured ? 'ok' : 'skip', reason: configured ? undefined : 'no-backend-login' });
|
|
1224
|
+
}
|
|
1225
|
+
catch (e) {
|
|
1226
|
+
log.warn(`Gateway setup failed (non-interactive): ${e.message}`);
|
|
1227
|
+
emit({ step: 'gateway', state: 'skip', reason: e.message });
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1330
1230
|
export function writeInitConfigs(paths, answers, force) {
|
|
1331
1231
|
// Opt-in retries never replace credentials, registry, or user configuration (even with --force).
|
|
1332
1232
|
const overwrite = answers.localClient?.enabled ? false : force;
|
|
@@ -1356,10 +1256,8 @@ async function runInitSteps(paths, force, options, emitter) {
|
|
|
1356
1256
|
// 4. Explicit client intent is durable before config writes; prepare never starts a process.
|
|
1357
1257
|
await withInitLocalClient(paths, answers, () => writeInitConfigs(paths, answers, force), emit);
|
|
1358
1258
|
emit({ step: 'config', state: 'ok' });
|
|
1359
|
-
// 5. Gateway usage — omitted scripted answers preserve the existing
|
|
1360
|
-
|
|
1361
|
-
writeUsageSharing(answers.gatewayUsage, options.gatewayConfigDir);
|
|
1362
|
-
}
|
|
1259
|
+
// 5. Gateway usage and telemetry — omitted scripted answers preserve the existing choices.
|
|
1260
|
+
applySharingChoices(paths, answers, options);
|
|
1363
1261
|
// 5b. Local Web UI endpoint — opt-in, driven by the desktop setup wizard. Must run after the
|
|
1364
1262
|
// .env exists so the generated client token is the one the native app is handed back.
|
|
1365
1263
|
let localUi = null;
|
|
@@ -1374,49 +1272,13 @@ async function runInitSteps(paths, force, options, emitter) {
|
|
|
1374
1272
|
emit({ step: 'service', state: 'ok' });
|
|
1375
1273
|
}
|
|
1376
1274
|
// 7. Detect credentials automatically. Login/install is only offered here.
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
if (!emitter && !interactive)
|
|
1380
|
-
process.stdout.write(`${JSON.stringify(event)}\n`);
|
|
1381
|
-
});
|
|
1382
|
-
if (interactive) {
|
|
1383
|
-
const configured = authBackends.length > 0
|
|
1384
|
-
&& await runGatewaySetup(authBackends, paths, options.gatewayConfigDir, answers, true);
|
|
1385
|
-
emit({ step: 'gateway', state: configured ? 'ok' : 'skip' });
|
|
1386
|
-
}
|
|
1387
|
-
else {
|
|
1388
|
-
// Non-interactive: auto-detect silently, passing caller-supplied choices. A machine with no
|
|
1389
|
-
// backend logged in yet yields no endpoints — expected on a fresh desktop install, where the
|
|
1390
|
-
// user logs in from the workbench afterwards and the server syncs profiles from that login.
|
|
1391
|
-
try {
|
|
1392
|
-
const configured = await runGatewaySetup(answers.backends, paths, options.gatewayConfigDir, answers);
|
|
1393
|
-
emit({ step: 'gateway', state: configured ? 'ok' : 'skip', reason: configured ? undefined : 'no-backend-login' });
|
|
1394
|
-
}
|
|
1395
|
-
catch (e) {
|
|
1396
|
-
log.warn(`Gateway setup failed (non-interactive): ${e.message}`);
|
|
1397
|
-
emit({ step: 'gateway', state: 'skip', reason: e.message });
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
// 8. Patch the stored activeProfile to match profiles.json defaultProfile
|
|
1401
|
-
try {
|
|
1402
|
-
const profilesJsonPath = path.join(paths.CONFIG_DIR, 'profiles.json');
|
|
1403
|
-
const statePath = path.join(paths.STORE_DIR, 'agent-state.json');
|
|
1404
|
-
const modeJsonPath = existsSync(statePath) ? statePath : path.join(paths.STORE_DIR, 'mode.json');
|
|
1405
|
-
if (existsSync(profilesJsonPath) && existsSync(modeJsonPath)) {
|
|
1406
|
-
const profilesData = JSON.parse(readFileSync(profilesJsonPath, 'utf8'));
|
|
1407
|
-
const modeData = JSON.parse(readFileSync(modeJsonPath, 'utf8'));
|
|
1408
|
-
if (modeData.activeProfile === '__active__' && profilesData.defaultProfile) {
|
|
1409
|
-
modeData.activeProfile = profilesData.defaultProfile;
|
|
1410
|
-
writeFileSync(modeJsonPath, JSON.stringify(modeData));
|
|
1411
|
-
log.info(`${path.basename(modeJsonPath)} activeProfile set to "${profilesData.defaultProfile}"`);
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
catch (e) {
|
|
1416
|
-
log.warn(`Failed to update the stored activeProfile: ${e.message}`);
|
|
1417
|
-
}
|
|
1418
|
-
// 9. Done
|
|
1275
|
+
await detectAuthAndGateway(paths, answers, options, !!interactive, emitter);
|
|
1276
|
+
// 8. Done
|
|
1419
1277
|
clack.outro(t('init.outro', { dataDir: paths.DATA_DIR }));
|
|
1278
|
+
// The funnel step goes to this process's own home only, and never against a fresh opt-out.
|
|
1279
|
+
if (answers.telemetry?.enabled !== false && path.resolve(paths.DATA_DIR) === path.resolve(DATA_DIR)) {
|
|
1280
|
+
recordFunnelStep('server_init_completed');
|
|
1281
|
+
}
|
|
1420
1282
|
emit({
|
|
1421
1283
|
step: 'result',
|
|
1422
1284
|
state: 'ok',
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type CliResult } from '../core/cli-utils.js';
|
|
2
|
+
import { defaultTerminalCliContext } from '../domain/system/terminal-cli/index.js';
|
|
3
|
+
/** `cortex path install|remove|status` — make this install's commands reachable from terminals. */
|
|
4
|
+
export declare function runPathCli(args: string[], makeContext?: typeof defaultTerminalCliContext): CliResult;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { formatError } from '../core/cli-utils.js';
|
|
2
|
+
import { getResolvedPaths } from './init.js';
|
|
3
|
+
import { getPathHelp } from './cli-help.js';
|
|
4
|
+
import { defaultTerminalCliContext, installTerminalCli, removeTerminalCli, terminalCliStatus, } from '../domain/system/terminal-cli/index.js';
|
|
5
|
+
const SUBCOMMANDS = ['install', 'remove', 'status'];
|
|
6
|
+
function optionValue(args, flag) {
|
|
7
|
+
const index = args.indexOf(flag);
|
|
8
|
+
return index !== -1 && args[index + 1] ? args[index + 1] : undefined;
|
|
9
|
+
}
|
|
10
|
+
const fail = (message) => ({
|
|
11
|
+
exitCode: 1, stdout: '', stderr: formatError(message, { validValues: SUBCOMMANDS, hint: 'cortex path --help' }),
|
|
12
|
+
});
|
|
13
|
+
function targetsLine(report, key, label) {
|
|
14
|
+
const hits = report.path_targets.filter((t) => t[key]).map((t) => t.target);
|
|
15
|
+
return `${label}: ${hits.length ? hits.join(', ') : 'none'}`;
|
|
16
|
+
}
|
|
17
|
+
function installText(report) {
|
|
18
|
+
const lines = [
|
|
19
|
+
`${report.dry_run ? 'Would install' : 'Installed'} terminal commands in ${report.dir}`,
|
|
20
|
+
targetsLine(report, 'changed', report.dry_run ? 'PATH would change in' : 'PATH updated in'),
|
|
21
|
+
'Open a new terminal to use `cortex`.',
|
|
22
|
+
];
|
|
23
|
+
if (report.shadowed.length)
|
|
24
|
+
lines.push(`New terminals will use this install instead of: ${report.shadowed.join(', ')}`);
|
|
25
|
+
if (process.env.SHELL?.endsWith('fish'))
|
|
26
|
+
lines.push(`fish is not configured automatically; run: fish_add_path ${report.dir}`);
|
|
27
|
+
return lines;
|
|
28
|
+
}
|
|
29
|
+
function removeText(report) {
|
|
30
|
+
return [
|
|
31
|
+
`${report.dry_run ? 'Would remove' : 'Removed'} ${report.removed.length} command file(s) from ${report.dir}`,
|
|
32
|
+
targetsLine(report, 'changed', report.dry_run ? 'PATH would change in' : 'PATH restored in'),
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
function statusText(report) {
|
|
36
|
+
return [
|
|
37
|
+
`Terminal commands: ${report.installed ? 'installed' : 'not installed'} (${report.dir})`,
|
|
38
|
+
...(report.stale.length ? [`Out of date: ${report.stale.join(', ')} — rerun cortex path install`] : []),
|
|
39
|
+
targetsLine(report, 'registered', 'On PATH via'),
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
const ACTIONS = {
|
|
43
|
+
install: (ctx, dryRun) => { const report = installTerminalCli(ctx, dryRun); return { report, text: installText(report) }; },
|
|
44
|
+
remove: (ctx, dryRun) => { const report = removeTerminalCli(ctx, dryRun); return { report, text: removeText(report) }; },
|
|
45
|
+
status: (ctx) => { const report = terminalCliStatus(ctx); return { report, text: statusText(report) }; },
|
|
46
|
+
};
|
|
47
|
+
/** `cortex path install|remove|status` — make this install's commands reachable from terminals. */
|
|
48
|
+
export function runPathCli(args, makeContext = defaultTerminalCliContext) {
|
|
49
|
+
if (args.includes('--help') || args.includes('-h'))
|
|
50
|
+
return { exitCode: 0, stdout: getPathHelp(), stderr: '' };
|
|
51
|
+
if (args.length === 0)
|
|
52
|
+
return fail("Missing subcommand for 'path'.");
|
|
53
|
+
const action = ACTIONS[args[0]];
|
|
54
|
+
if (!action)
|
|
55
|
+
return fail(`Unknown subcommand: '${args[0]}'.`);
|
|
56
|
+
try {
|
|
57
|
+
const ctx = makeContext(getResolvedPaths(optionValue(args, '--home')).DATA_DIR);
|
|
58
|
+
const { report, text } = action(ctx, args.includes('--dry-run'));
|
|
59
|
+
const stdout = args.includes('--json') ? `${JSON.stringify(report, null, 2)}\n` : `${text.join('\n')}\n`;
|
|
60
|
+
return { exitCode: 0, stdout, stderr: '' };
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
return { exitCode: 1, stdout: '', stderr: `cortex path ${args[0]} failed: ${error?.message ?? String(error)}\n` };
|
|
64
|
+
}
|
|
65
|
+
}
|