@cortex-agent/server 2026.10.15 → 2026.10.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -50
- package/defaults/board/board.css +140 -62
- package/defaults/board/scaffold.html +36 -13
- package/defaults/config/environments/creative.json +0 -1
- package/defaults/config/environments/main.json +1 -2
- package/defaults/plugins/cortex-board/skills/board/SKILL.md +30 -22
- package/defaults/plugins/cortex-system/plugin.json +2 -2
- package/defaults/plugins/cortex-system/skills/browser/SKILL.md +56 -0
- package/dist/agent-adapter/claude/adapter.d.ts +2 -5
- package/dist/agent-adapter/claude/adapter.js +6 -5
- package/dist/agent-adapter/claude/assistant-blocks.d.ts +5 -0
- package/dist/agent-adapter/claude/assistant-blocks.js +61 -0
- package/dist/agent-adapter/claude/cache-refresh.d.ts +58 -0
- package/dist/agent-adapter/claude/cache-refresh.js +145 -0
- package/dist/agent-adapter/claude/cache-touch.d.ts +12 -0
- package/dist/agent-adapter/claude/cache-touch.js +75 -0
- package/dist/agent-adapter/claude/event-parser.d.ts +8 -3
- package/dist/agent-adapter/claude/event-parser.js +33 -17
- package/dist/agent-adapter/claude/event-translator.d.ts +2 -0
- package/dist/agent-adapter/claude/event-translator.js +2 -0
- package/dist/agent-adapter/claude/session-options.d.ts +6 -13
- package/dist/agent-adapter/claude/session-options.js +2 -13
- package/dist/agent-adapter/claude/spawn-args.d.ts +4 -21
- package/dist/agent-adapter/claude/spawn-args.js +17 -24
- package/dist/agent-adapter/claude/transcript-clear.d.ts +42 -0
- package/dist/agent-adapter/claude/transcript-clear.js +217 -0
- package/dist/agent-adapter/claude/turn-machine.d.ts +3 -2
- package/dist/agent-adapter/claude/turn-machine.js +21 -68
- package/dist/agent-adapter/claude/window-warmup.d.ts +13 -0
- package/dist/agent-adapter/claude/window-warmup.js +38 -0
- package/dist/agent-adapter/continuation-phase.js +3 -0
- package/dist/agent-adapter/normalize/event-types.d.ts +8 -0
- package/dist/agent-adapter/pi/adapter.d.ts +0 -1
- package/dist/agent-adapter/pi/adapter.js +5 -13
- package/dist/agent-adapter/pi/event-parser.d.ts +1 -1
- package/dist/agent-adapter/pi/event-parser.js +43 -27
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +1 -1
- package/dist/agent-adapter/pi/pi-session.d.ts +2 -0
- package/dist/agent-adapter/pi/pi-session.js +15 -0
- package/dist/agent-adapter/pi/providers-config.d.ts +2 -2
- package/dist/agent-adapter/pi/providers-config.js +1 -1
- package/dist/agent-adapter/pi/quota-sink.d.ts +3 -3
- package/dist/agent-adapter/pi/quota-sink.js +3 -3
- package/dist/agent-adapter/pi/runtime.js +6 -1
- package/dist/agent-adapter/pi/session-options.d.ts +9 -13
- package/dist/agent-adapter/pi/session-options.js +12 -25
- package/dist/agent-adapter/run-events.d.ts +11 -10
- package/dist/agent-adapter/run-events.js +2 -0
- package/dist/agent-adapter/types.d.ts +5 -4
- package/dist/client-bundle/manifest.json +2 -2
- package/dist/core/codex-quota.d.ts +1 -1
- package/dist/core/codex-quota.js +1 -1
- package/dist/core/gateway-generator.d.ts +9 -11
- package/dist/core/gateway-generator.js +31 -58
- package/dist/core/locales/en.d.ts +51 -77
- package/dist/core/locales/slices/commands.d.ts +26 -31
- package/dist/core/locales/slices/commands.js +54 -64
- package/dist/core/locales/slices/init.d.ts +8 -19
- package/dist/core/locales/slices/init.js +17 -53
- package/dist/core/locales/slices/interactions.d.ts +3 -3
- package/dist/core/locales/slices/interactions.js +6 -6
- package/dist/core/locales/slices/notices.d.ts +1 -3
- package/dist/core/locales/slices/notices.js +2 -6
- package/dist/core/locales/slices/scheduling.d.ts +9 -9
- package/dist/core/locales/slices/scheduling.js +18 -18
- package/dist/core/locales/slices/status.d.ts +0 -4
- package/dist/core/locales/slices/status.js +0 -8
- package/dist/core/locales/slices/tui.d.ts +0 -1
- package/dist/core/locales/slices/tui.js +0 -2
- package/dist/core/locales/slices/uimsg.d.ts +4 -7
- package/dist/core/locales/slices/uimsg.js +9 -15
- package/dist/core/models-generator.d.ts +29 -0
- package/dist/core/models-generator.js +82 -0
- package/dist/core/paths.d.ts +1 -1
- package/dist/core/paths.js +1 -1
- package/dist/core/settings-spec.d.ts +25 -0
- package/dist/core/settings-spec.js +34 -0
- package/dist/core/status-format.d.ts +3 -2
- package/dist/core/status-format.js +2 -2
- package/dist/core/types/environment-types.d.ts +0 -2
- package/dist/domain/agents/agent-state.d.ts +11 -56
- package/dist/domain/agents/agent-state.js +48 -115
- package/dist/domain/agents/agent-switch.d.ts +2 -24
- package/dist/domain/agents/agent-switch.js +9 -72
- package/dist/domain/agents/config.d.ts +11 -61
- package/dist/domain/agents/config.js +47 -154
- package/dist/domain/agents/engine-selection.d.ts +21 -0
- package/dist/domain/agents/engine-selection.js +37 -0
- package/dist/domain/agents/environments/registry.js +2 -1
- package/dist/domain/agents/environments/resolve.js +0 -1
- package/dist/domain/agents/environments/schema.d.ts +0 -1
- package/dist/domain/agents/environments/schema.js +0 -1
- package/dist/domain/agents/index.d.ts +2 -1
- package/dist/domain/agents/index.js +3 -7
- package/dist/domain/agents/model-selection.d.ts +18 -70
- package/dist/domain/agents/model-selection.js +100 -150
- package/dist/domain/agents/models.d.ts +12 -0
- package/dist/domain/agents/models.js +94 -0
- package/dist/domain/agents/subagent/registry.d.ts +2 -0
- package/dist/domain/agents/subagent/registry.js +8 -0
- package/dist/domain/agents/subagent/runner.d.ts +5 -5
- package/dist/domain/agents/subagent/runner.js +12 -35
- package/dist/domain/auth/auth-status.d.ts +4 -4
- package/dist/domain/auth/auth-status.js +17 -28
- package/dist/domain/auth/gateway-sync.d.ts +6 -26
- package/dist/domain/auth/gateway-sync.js +31 -75
- package/dist/domain/benchmark/identity.d.ts +3 -5
- package/dist/domain/benchmark/identity.js +0 -1
- package/dist/domain/benchmark/production-attempt-identity.d.ts +6 -5
- package/dist/domain/benchmark/production-attempt-identity.js +32 -35
- package/dist/domain/benchmark/session-evidence.d.ts +2 -1
- package/dist/domain/benchmark/session-evidence.js +8 -1
- package/dist/domain/browser/broker.d.ts +99 -0
- package/dist/domain/browser/broker.js +487 -0
- package/dist/domain/costs/claude-account.js +21 -0
- package/dist/domain/costs/rate-limit-throttle.js +3 -1
- package/dist/domain/costs/reset-account.d.ts +2 -0
- package/dist/domain/costs/usage-service.d.ts +1 -1
- package/dist/domain/costs/usage-service.js +20 -7
- package/dist/domain/mcp/tools/context.d.ts +5 -6
- package/dist/domain/mcp/tools/context.js +17 -3
- package/dist/domain/mcp/tools/subagent.js +1 -1
- package/dist/domain/mcp/tools/ui-file.js +1 -1
- package/dist/domain/pi-providers/custom-provider-model.d.ts +1 -1
- package/dist/domain/pi-providers/custom-provider-model.js +1 -1
- package/dist/domain/remote/device-browser.js +1 -1
- package/dist/domain/remote/device-chrome-commands.js +2 -0
- package/dist/domain/remote/device-port.js +2 -2
- package/dist/domain/runs/attempt.d.ts +3 -3
- package/dist/domain/runs/attempt.js +2 -3
- package/dist/domain/runs/builders.d.ts +4 -4
- package/dist/domain/runs/builders.js +4 -5
- package/dist/domain/runs/compact.d.ts +4 -17
- package/dist/domain/runs/compact.js +14 -56
- package/dist/domain/runs/config-resolver.d.ts +15 -83
- package/dist/domain/runs/config-resolver.js +24 -150
- package/dist/domain/runs/engine-spec.d.ts +8 -8
- package/dist/domain/runs/engine-spec.js +15 -31
- package/dist/domain/runs/events.d.ts +1 -1
- package/dist/domain/runs/fallback.d.ts +6 -38
- package/dist/domain/runs/fallback.js +10 -72
- package/dist/domain/runs/notices.d.ts +1 -11
- package/dist/domain/runs/notices.js +3 -30
- package/dist/domain/runs/request.d.ts +4 -3
- package/dist/domain/runs/retryable-errors.d.ts +0 -13
- package/dist/domain/runs/retryable-errors.js +0 -17
- package/dist/domain/runs/run.d.ts +12 -42
- package/dist/domain/runs/run.js +40 -147
- package/dist/domain/runs/service.d.ts +1 -1
- package/dist/domain/runs/service.js +8 -3
- package/dist/domain/runs/spec-loader.d.ts +1 -1
- package/dist/domain/runs/spend.d.ts +1 -1
- package/dist/domain/runs/spend.js +1 -1
- package/dist/domain/scheduling/jobs/scheduled-task.d.ts +3 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +25 -19
- package/dist/domain/scheduling/schedule-ops.d.ts +0 -1
- package/dist/domain/scheduling/schedule-ops.js +2 -5
- package/dist/domain/scheduling/schedule-selection.d.ts +3 -0
- package/dist/domain/scheduling/schedule-selection.js +16 -0
- package/dist/domain/scheduling/schedule-spec.d.ts +6 -5
- package/dist/domain/scheduling/schedule-spec.js +6 -6
- package/dist/domain/scheduling/scheduler.d.ts +3 -1
- package/dist/domain/scheduling/scheduler.js +22 -21
- package/dist/domain/sessions/session-hooks.d.ts +5 -4
- package/dist/domain/sessions/session-hooks.js +15 -33
- package/dist/domain/sessions/session-lifecycle.d.ts +19 -51
- package/dist/domain/sessions/session-lifecycle.js +34 -96
- package/dist/domain/system/doctor.d.ts +3 -3
- package/dist/domain/system/doctor.js +22 -26
- package/dist/domain/system/own-bin-path.d.ts +13 -0
- package/dist/domain/system/own-bin-path.js +36 -0
- package/dist/domain/system/terminal-cli/index.d.ts +58 -0
- package/dist/domain/system/terminal-cli/index.js +100 -0
- package/dist/domain/system/terminal-cli/posix-profiles.d.ts +23 -0
- package/dist/domain/system/terminal-cli/posix-profiles.js +74 -0
- package/dist/domain/system/terminal-cli/registrar.d.ts +12 -0
- package/dist/domain/system/terminal-cli/registrar.js +1 -0
- package/dist/domain/system/terminal-cli/shims.d.ts +27 -0
- package/dist/domain/system/terminal-cli/shims.js +108 -0
- package/dist/domain/system/terminal-cli/state.d.ts +7 -0
- package/dist/domain/system/terminal-cli/state.js +36 -0
- package/dist/domain/system/terminal-cli/windows-user-path.d.ts +13 -0
- package/dist/domain/system/terminal-cli/windows-user-path.js +67 -0
- package/dist/domain/tui-session/tui-session-service.js +1 -1
- package/dist/domain/tui-session/types.d.ts +2 -2
- package/dist/domain/ui-service/app-router.d.ts +49 -71
- package/dist/domain/ui-service/app-router.js +9 -13
- package/dist/domain/ui-service/assistant-snapshots.js +2 -0
- package/dist/domain/ui-service/contract.parity.d.ts +19 -0
- package/dist/domain/ui-service/contract.parity.js +1 -0
- package/dist/domain/ui-service/inline-media-types.d.ts +18 -0
- package/dist/domain/ui-service/inline-media-types.js +1 -0
- package/dist/domain/ui-service/input-schemas.d.ts +52 -115
- package/dist/domain/ui-service/input-schemas.js +38 -84
- package/dist/domain/ui-service/mutate/auth.d.ts +1 -1
- package/dist/domain/ui-service/mutate/auth.js +3 -2
- package/dist/domain/ui-service/mutate/config.d.ts +0 -8
- package/dist/domain/ui-service/mutate/config.js +0 -22
- package/dist/domain/ui-service/mutate/models.d.ts +13 -0
- package/dist/domain/ui-service/mutate/models.js +137 -0
- package/dist/domain/ui-service/mutate/resolve-media.d.ts +4 -0
- package/dist/domain/ui-service/mutate/resolve-media.js +17 -0
- package/dist/domain/ui-service/mutate/sessions.d.ts +2 -2
- package/dist/domain/ui-service/mutate/sessions.js +29 -126
- package/dist/domain/ui-service/query/config.js +22 -42
- package/dist/domain/ui-service/query/models.js +2 -2
- package/dist/domain/ui-service/query/schedules.js +1 -1
- package/dist/domain/ui-service/query/sessions.js +7 -13
- package/dist/domain/ui-service/types.d.ts +51 -177
- package/dist/domain/ui-service/ui-service.d.ts +23 -49
- package/dist/domain/ui-service/ui-service.js +8 -6
- package/dist/entry/app.js +42 -19
- package/dist/entry/browser-cli.d.ts +39 -0
- package/dist/entry/browser-cli.js +317 -0
- package/dist/entry/cli-help.d.ts +1 -0
- package/dist/entry/cli-help.js +37 -6
- package/dist/entry/cli.js +16 -14
- package/dist/entry/daemon.js +2 -0
- package/dist/entry/init-auth.js +1 -1
- package/dist/entry/init.d.ts +7 -8
- package/dist/entry/init.js +89 -249
- package/dist/entry/path-cli.d.ts +4 -0
- package/dist/entry/path-cli.js +65 -0
- package/dist/entry/schedule-cli.js +13 -6
- package/dist/entry/shutdown.d.ts +1 -1
- package/dist/entry/shutdown.js +8 -1
- package/dist/entry/start-ui-http.js +8 -0
- package/dist/entry/ui-service-wiring.js +8 -10
- package/dist/events/event-types.d.ts +3 -2
- package/dist/orchestration/agent-runner.d.ts +2 -2
- package/dist/orchestration/agent-runner.js +10 -9
- package/dist/orchestration/benchmark-session-webhook.js +13 -1
- package/dist/orchestration/browser-webhook.d.ts +11 -0
- package/dist/orchestration/browser-webhook.js +28 -0
- package/dist/orchestration/cache-keep-warm.d.ts +77 -0
- package/dist/orchestration/cache-keep-warm.js +213 -0
- package/dist/orchestration/claude-window-warmup.d.ts +40 -0
- package/dist/orchestration/claude-window-warmup.js +126 -0
- package/dist/orchestration/conversation-request.d.ts +6 -10
- package/dist/orchestration/conversation-request.js +5 -23
- package/dist/orchestration/delta-coalescer.d.ts +4 -2
- package/dist/orchestration/delta-coalescer.js +5 -5
- package/dist/orchestration/edit-retry.js +9 -11
- package/dist/orchestration/inline-media-eager.d.ts +13 -0
- package/dist/orchestration/inline-media-eager.js +58 -0
- package/dist/orchestration/inline-media.d.ts +22 -0
- package/dist/orchestration/inline-media.js +151 -0
- package/dist/orchestration/interactions/ask-user-resume.js +3 -7
- package/dist/orchestration/interactions/interaction-handlers.js +6 -6
- package/dist/orchestration/mid-turn-inject.d.ts +2 -1
- package/dist/orchestration/mid-turn-inject.js +1 -1
- package/dist/orchestration/pending-injection-recovery.d.ts +2 -1
- package/dist/orchestration/pending-injection-recovery.js +1 -1
- package/dist/orchestration/routing/commands/index.js +4 -4
- package/dist/orchestration/routing/commands/mode.d.ts +5 -44
- package/dist/orchestration/routing/commands/mode.js +98 -272
- package/dist/orchestration/routing/commands/schedule.js +29 -18
- package/dist/orchestration/routing/commands/session.js +9 -9
- package/dist/orchestration/routing/commands/status.js +1 -1
- package/dist/orchestration/routing/commands/usage-format.js +3 -0
- package/dist/orchestration/routing/webhook.js +4 -0
- package/dist/orchestration/session-compact.d.ts +0 -1
- package/dist/orchestration/session-compact.js +5 -7
- package/dist/orchestration/session-events.d.ts +2 -1
- package/dist/orchestration/session-events.js +1 -0
- package/dist/orchestration/status-helpers.d.ts +0 -4
- package/dist/orchestration/status-helpers.js +0 -18
- package/dist/orchestration/subagent-webhook.js +9 -34
- package/dist/orchestration/team-webhook.d.ts +8 -9
- package/dist/orchestration/team-webhook.js +16 -42
- package/dist/orchestration/transcript-sink.d.ts +6 -0
- package/dist/orchestration/transcript-sink.js +21 -2
- package/dist/orchestration/turn/terminal.js +7 -7
- package/dist/orchestration/turn/turn-prep.d.ts +0 -8
- package/dist/orchestration/turn/turn-prep.js +0 -51
- package/dist/orchestration/turn/turn-tracking.d.ts +2 -2
- package/dist/orchestration/turn/turn-tracking.js +8 -5
- package/dist/orchestration/turn/turn.d.ts +0 -2
- package/dist/orchestration/turn/turn.js +13 -15
- package/dist/platform/adapters/tui/ports.d.ts +1 -1
- package/dist/platform/adapters/tui/tui-transcript.js +2 -0
- package/dist/platform/browser/agent-browser.d.ts +50 -0
- package/dist/platform/browser/agent-browser.js +165 -0
- package/dist/platform/browser/managed-browser.d.ts +1 -11
- package/dist/platform/browser/managed-browser.js +4 -12
- package/dist/platform/ui-http/browser-stream.d.ts +110 -0
- package/dist/platform/ui-http/browser-stream.js +447 -0
- package/dist/platform/ui-http/ui-http-server.d.ts +12 -0
- package/dist/platform/ui-http/ui-http-server.js +23 -6
- package/dist/store/conversation-history-reader.js +8 -0
- package/dist/store/conversation-history-repo.d.ts +8 -1
- package/dist/store/conversation-history-repo.js +5 -0
- package/dist/store/conversation-ledger-repo.d.ts +6 -6
- package/dist/store/conversation-ledger-repo.js +4 -4
- package/dist/store/models-repo.d.ts +18 -0
- package/dist/store/models-repo.js +74 -0
- package/dist/store/pending-injection-repo.d.ts +2 -1
- package/dist/store/pending-injection-repo.js +3 -1
- package/dist/store/retire-profiles-migration.d.ts +28 -0
- package/dist/store/retire-profiles-migration.js +335 -0
- package/dist/store/schedule-repo.d.ts +2 -1
- package/dist/store/session-registry-import.js +3 -2
- package/dist/store/session-registry-journal.d.ts +10 -13
- package/dist/store/session-registry-journal.js +48 -25
- package/dist/store/session-registry-repo.d.ts +4 -4
- package/dist/store/session-registry-repo.js +4 -5
- package/dist/store/version-migrations.d.ts +2 -3
- package/dist/store/version-migrations.js +19 -3
- package/dist/tui/slash-commands.js +2 -2
- package/dist/tui/turn-status.js +1 -1
- package/package.json +6 -4
- package/web/dist/assets/board-math-css-CB4GJ6qO.js +2 -0
- package/web/dist/assets/index-CaSZPg_H.css +1 -0
- package/web/dist/assets/index-CzOR7Edh.js +522 -0
- package/web/dist/assets/{index-CndZZ1IQ.js → index-cIGFv27z.js} +1 -1
- package/web/dist/index.html +3 -2
- package/web/dist/theme.css +6 -0
- package/dist/agent-adapter/browser-mcp-server.d.ts +0 -13
- package/dist/agent-adapter/browser-mcp-server.js +0 -28
- package/dist/agent-adapter/claude/browser-mcp.d.ts +0 -9
- package/dist/agent-adapter/claude/browser-mcp.js +0 -10
- package/dist/core/profile-generator.d.ts +0 -79
- package/dist/core/profile-generator.js +0 -215
- package/dist/domain/agents/profile-manager.d.ts +0 -103
- package/dist/domain/agents/profile-manager.js +0 -286
- package/dist/domain/agents/profile-switch.d.ts +0 -49
- package/dist/domain/agents/profile-switch.js +0 -62
- package/dist/domain/ui-service/mutate/profiles.d.ts +0 -36
- package/dist/domain/ui-service/mutate/profiles.js +0 -151
- package/dist/store/profile-repo.d.ts +0 -20
- package/dist/store/profile-repo.js +0 -97
- package/web/dist/assets/index-B76ueW3q.js +0 -494
- package/web/dist/assets/index-C8O0yxg8.css +0 -1
package/dist/entry/app.js
CHANGED
|
@@ -21,6 +21,8 @@ import { registerCommands } from '../orchestration/routing/commands/index.js';
|
|
|
21
21
|
import { buildAuthRequiredLoginAction } from '../orchestration/routing/commands/login-notice.js';
|
|
22
22
|
import { usageResetNoticeActions } from '../orchestration/routing/commands/usage-reset.js';
|
|
23
23
|
import { recoverWaitpoints, startWaitpointSweep } from '../orchestration/waitpoint-sweep.js';
|
|
24
|
+
import { startCacheKeepWarm } from '../orchestration/cache-keep-warm.js';
|
|
25
|
+
import { startClaudeWindowWarmup } from '../orchestration/claude-window-warmup.js';
|
|
24
26
|
import { projectStore } from '../domain/projects/index.js';
|
|
25
27
|
import { sendStartupDmIfConfigured } from './startup-notify.js';
|
|
26
28
|
import { installSigtermShutdown } from './shutdown.js';
|
|
@@ -71,10 +73,11 @@ import { initResumeRegistry, getResumeCount, pendingDirectTrackSessionIds } from
|
|
|
71
73
|
import { dispatchPendingResumes, registerResumeWakeOnAgentSettle, } from '../orchestration/resume-dispatcher.js';
|
|
72
74
|
import { providerStateRepo } from '../store/provider-state-repo.js';
|
|
73
75
|
import { runMigrations, migrateAistatusConfigLocation } from '../store/version-migrations.js';
|
|
76
|
+
import { reloadAgentState } from '../domain/agents/config.js';
|
|
74
77
|
import { loadHookRegistry } from '../store/hook-registry.js';
|
|
75
78
|
import { emitCortexEvent, initHookBus } from '../core/hook-bus.js';
|
|
76
79
|
import { CORTEX_VERSION } from '../core/version.js';
|
|
77
|
-
import {
|
|
80
|
+
import { getModelsConfigRevision, MODELS_FILE, modelsRepo, startModelsWatcher, setAdminNotifier as setModelsNotifier } from '../store/models-repo.js';
|
|
78
81
|
import { startBoardWatcher } from '../domain/boards/board-watcher.js';
|
|
79
82
|
import { sessionStore } from '../store/session-registry-repo.js';
|
|
80
83
|
import { retentionCandidateRepo } from '../store/retention-candidate-repo.js';
|
|
@@ -106,9 +109,12 @@ import { registerAuthWatch } from '../domain/auth/auth-watch.js';
|
|
|
106
109
|
import { onLoginSuccess } from '../domain/auth/login-flow.js';
|
|
107
110
|
import { syncGatewayFromBackends } from '../domain/auth/gateway-sync.js';
|
|
108
111
|
import { createSessionRetentionController } from '../orchestration/session-retention-controller.js';
|
|
112
|
+
import { ensureOwnBinsOnPath } from '../domain/system/own-bin-path.js';
|
|
113
|
+
import { defaultTerminalCliContext, syncTerminalCli } from '../domain/system/terminal-cli/index.js';
|
|
109
114
|
// Static imports are evaluated before this line, so this is how long module loading took.
|
|
110
115
|
const importsMs = Math.round(performance.now());
|
|
111
116
|
loadRuntimeDotenv(path.join(CONFIG_DIR, '.env'));
|
|
117
|
+
ensureOwnBinsOnPath();
|
|
112
118
|
await migrateEnvToSettings();
|
|
113
119
|
// Ensure the WebSocket + webhook bearer tokens exist before either server starts. Generates
|
|
114
120
|
// and persists them to .env on first run (fail-closed auth — see core/auth.ts). Must run after
|
|
@@ -163,6 +169,19 @@ async function runRetentionSweep(retentionDays, signal) {
|
|
|
163
169
|
const attachmentsPruned = result.stopped ? 0 : await pruneInboundAttachments(retentionDays);
|
|
164
170
|
log.info(`Retention sweep${result.stopped ? ' stopped early' : ''}: registry=${result.registryCommitted} history=${result.historyOrphanDeleted} pi=${result.piOrphanDeleted} capture=${result.claudeCaptureDeleted} toolImages=${result.toolImagesDeleted} attachments=${attachmentsPruned} errors=${result.errors.length} in ${Date.now() - startedAt}ms`);
|
|
165
171
|
}
|
|
172
|
+
/** Deferred past startup: the first Windows install calls PowerShell synchronously. */
|
|
173
|
+
function syncTerminalCommand() {
|
|
174
|
+
setTimeout(() => {
|
|
175
|
+
try {
|
|
176
|
+
const result = syncTerminalCli(defaultTerminalCliContext(DATA_DIR));
|
|
177
|
+
if (result.files.length)
|
|
178
|
+
log.info(`Terminal command ${result.action}: ${result.files.join(', ')}`);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
log.warn(`Terminal command setup failed; retrying at next start: ${error.message}`);
|
|
182
|
+
}
|
|
183
|
+
}, 0);
|
|
184
|
+
}
|
|
166
185
|
const retentionController = createSessionRetentionController({
|
|
167
186
|
getRetentionDays: () => getSettings().sessionRetentionDays,
|
|
168
187
|
onSettingsChange,
|
|
@@ -183,18 +202,17 @@ function initConfiguredHooks() {
|
|
|
183
202
|
const cortexCount = enabled.filter((entry) => entry.event.startsWith('cortex:')).length;
|
|
184
203
|
log.info(`Startup: mounted ${enabled.length} hooks (${ccCount} cc / ${cortexCount} cortex)`);
|
|
185
204
|
}
|
|
186
|
-
/** Preload the PI SDK at boot when
|
|
205
|
+
/** Preload the PI SDK at boot when the default or any favorite uses it, so the first PI session of this
|
|
187
206
|
* process does not wait out its multi-second module import. */
|
|
188
207
|
function prewarmPiBackend() {
|
|
189
208
|
try {
|
|
190
|
-
const
|
|
191
|
-
const usesPi =
|
|
192
|
-
|| profile.fallback?.some((entry) => entry.backend === 'pi'));
|
|
209
|
+
const models = modelsRepo.readIfPresent();
|
|
210
|
+
const usesPi = models?.default?.backend === 'pi' || models?.favorites?.some(ref => ref.backend === 'pi');
|
|
193
211
|
if (usesPi)
|
|
194
212
|
prewarmPiSdk();
|
|
195
213
|
}
|
|
196
214
|
catch (error) {
|
|
197
|
-
log.warn(`Startup: PI preload skipped (
|
|
215
|
+
log.warn(`Startup: PI preload skipped (models unreadable): ${error.message}`);
|
|
198
216
|
}
|
|
199
217
|
}
|
|
200
218
|
// --- Singleton lock ---
|
|
@@ -220,6 +238,7 @@ process.on('exit', () => releaseSingletonLock(APP_PID_FILE));
|
|
|
220
238
|
// Cross-file migrations must finish before adapters, ports, and background services
|
|
221
239
|
// become externally visible. Provider-state extraction runs before schedule cleanup.
|
|
222
240
|
await runMigrations();
|
|
241
|
+
reloadAgentState();
|
|
223
242
|
await migrateBuiltinJobSchedules();
|
|
224
243
|
// Before any Claude spawn: a fresh Cortex Claude config dir takes its model/effort/context
|
|
225
244
|
// settings over from the terminal's once, so the first sessions behave as they did before.
|
|
@@ -262,8 +281,8 @@ createEventLogger(bus);
|
|
|
262
281
|
initAuthEvents(bus);
|
|
263
282
|
// A login only becomes useful once the models it unlocks are routable, and that mapping is derived
|
|
264
283
|
// by scanning local backend state. Re-derive it whenever a login lands, so a user who authenticates
|
|
265
|
-
// from the workbench gets
|
|
266
|
-
// Merge-aware and non-throwing (see gateway-sync.ts) —
|
|
284
|
+
// from the workbench gets usable models without dropping to a terminal for `cortex setup-gateway`.
|
|
285
|
+
// Merge-aware and non-throwing (see gateway-sync.ts) — the existing default is never overwritten.
|
|
267
286
|
onLoginSuccess((event) => {
|
|
268
287
|
void syncGatewayFromBackends({ backends: [event.backend] }).then((result) => {
|
|
269
288
|
if (!result.configured && result.reason !== 'no-endpoints') {
|
|
@@ -319,7 +338,7 @@ if (tuiGateway) {
|
|
|
319
338
|
const notifyAdmin = (text) => {
|
|
320
339
|
void emitSystemNotice(adapter, { text });
|
|
321
340
|
};
|
|
322
|
-
|
|
341
|
+
setModelsNotifier(notifyAdmin);
|
|
323
342
|
setMachineNotifier(notifyAdmin);
|
|
324
343
|
setMachineReloadListener(() => {
|
|
325
344
|
void releaseUnregisteredDevices().catch((e) => log.error(`Releasing removed machines failed: ${e.message}`));
|
|
@@ -391,7 +410,7 @@ registerInteractionHandlers(adapter);
|
|
|
391
410
|
// --- Register message handler ---
|
|
392
411
|
registerMessageHandler(adapter, { dispatchCommand, handleMessageEdit });
|
|
393
412
|
// --- Graceful shutdown ---
|
|
394
|
-
// Boot fills in the platform connections, the Web UI host and the
|
|
413
|
+
// Boot fills in the platform connections, the Web UI host and the models watcher as it starts them.
|
|
395
414
|
const shutdownHandles = {
|
|
396
415
|
bus, outboundQueue: oq, scheduler, retention: retentionController,
|
|
397
416
|
};
|
|
@@ -466,11 +485,11 @@ installSigtermShutdown(shutdownHandles);
|
|
|
466
485
|
startEnvironmentWatcher();
|
|
467
486
|
initializeProductionAttemptIdentity({
|
|
468
487
|
configurationRevision: () => ({
|
|
469
|
-
|
|
488
|
+
models: getModelsConfigRevision(), environments: getEnvironmentRevision(),
|
|
470
489
|
}),
|
|
471
490
|
});
|
|
472
|
-
shutdownHandles.
|
|
473
|
-
bus.publish({ type: 'config.changed', section: '
|
|
491
|
+
shutdownHandles.stopModelsWatcher = startModelsWatcher(modelsRepo, MODELS_FILE, () => {
|
|
492
|
+
bus.publish({ type: 'config.changed', section: 'models' });
|
|
474
493
|
});
|
|
475
494
|
// Open boards refresh live: their directories and the user stylesheet are watched.
|
|
476
495
|
shutdownHandles.stopBoardWatcher = startBoardWatcher(bus);
|
|
@@ -543,6 +562,10 @@ installSigtermShutdown(shutdownHandles);
|
|
|
543
562
|
// S13: register hook-bridge event subscribers (bodies extracted to orch/routing/hook-bridge-subscribers.ts)
|
|
544
563
|
registerHookBridgeSubscribers(bus, adapter, planApprovals);
|
|
545
564
|
installTeamDelivery(bus);
|
|
565
|
+
// Claude prompt caches of idle sessions that still expect a wake, read before their hour runs out.
|
|
566
|
+
startCacheKeepWarm();
|
|
567
|
+
// Claude's five-hour window, reopened after it closes while Claude sits idle (when enabled).
|
|
568
|
+
startClaudeWindowWarmup();
|
|
546
569
|
// Worker reports a restart kept from their leads: delivered now that sessions and the adapter are up.
|
|
547
570
|
void flushTeamOutbox()
|
|
548
571
|
.then((n) => { if (n > 0)
|
|
@@ -560,12 +583,12 @@ installSigtermShutdown(shutdownHandles);
|
|
|
560
583
|
version: CORTEX_VERSION,
|
|
561
584
|
pid: process.pid,
|
|
562
585
|
}).catch(() => { });
|
|
563
|
-
//
|
|
564
|
-
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
? `profile: ${bootConfig.profileName} · backend: ${bootConfig.profile.backend}`
|
|
586
|
+
// Show the selection an unconfigured channel will use.
|
|
587
|
+
const bootConfig = modelsRepo.readIfPresent()?.default ? resolveConfiguredDefaultRun() : null;
|
|
588
|
+
const selectionSummary = bootConfig
|
|
589
|
+
? `model: ${bootConfig.model} · backend: ${bootConfig.backend}`
|
|
568
590
|
: 'provider setup required';
|
|
569
|
-
log.info(`Cortex agent is running (${adapter.name}) — ${
|
|
591
|
+
log.info(`Cortex agent is running (${adapter.name}) — ${selectionSummary}`
|
|
570
592
|
+ ` · boot ${Math.round(performance.now())}ms (imports ${importsMs}ms)`);
|
|
593
|
+
syncTerminalCommand();
|
|
571
594
|
})();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface ParsedBrowserArgs {
|
|
2
|
+
help: boolean;
|
|
3
|
+
device: string | null;
|
|
4
|
+
args: string[];
|
|
5
|
+
command: string | null;
|
|
6
|
+
}
|
|
7
|
+
export declare class BrowserUsageError extends Error {
|
|
8
|
+
}
|
|
9
|
+
export declare function parseBrowserArgs(argv: string[]): ParsedBrowserArgs;
|
|
10
|
+
/** Does this command run without a browser (help, version, bundled skills)? */
|
|
11
|
+
export declare function isLocalCommand(parsed: ParsedBrowserArgs): boolean;
|
|
12
|
+
/** Make the file arguments of file-writing commands absolute against the caller's directory. */
|
|
13
|
+
export declare function absolutizePaths(args: string[], cwd: string): string[];
|
|
14
|
+
export interface LeaseData {
|
|
15
|
+
device: string;
|
|
16
|
+
cdpEndpoint: string;
|
|
17
|
+
abSession: string;
|
|
18
|
+
bin: string;
|
|
19
|
+
env: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
export interface BrowserCliOptions {
|
|
22
|
+
env?: NodeJS.ProcessEnv;
|
|
23
|
+
cwd?: string;
|
|
24
|
+
post?: (url: string, body: unknown, headers: Record<string, string>) => Promise<{
|
|
25
|
+
status: number;
|
|
26
|
+
body: any;
|
|
27
|
+
}>;
|
|
28
|
+
/** Run agent-browser with stdout passed through (discarded when `quiet`); resolves its exit code
|
|
29
|
+
* and captured stderr. */
|
|
30
|
+
exec?: (bin: string, args: string[], env: Record<string, string>, cwd: string, quiet?: boolean) => Promise<{
|
|
31
|
+
code: number;
|
|
32
|
+
stderr: string;
|
|
33
|
+
}>;
|
|
34
|
+
writeErr?: (text: string) => void;
|
|
35
|
+
/** Delay before telling the caller the browser is still starting. */
|
|
36
|
+
slowNoticeMs?: number;
|
|
37
|
+
}
|
|
38
|
+
export declare function runBrowserCli(argv: string[], options?: BrowserCliOptions): Promise<number>;
|
|
39
|
+
export declare function main(argv?: string[]): Promise<void>;
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { formatError, formatHelp } from '../core/cli-utils.js';
|
|
5
|
+
import { AUTH_HEADER } from '../core/auth.js';
|
|
6
|
+
import { isMainModule } from '../core/utils.js';
|
|
7
|
+
import { agentBrowserArgs, agentBrowserBaseEnv, agentBrowserCallEnv, isTabGone, resolveAgentBrowserBin, AgentBrowserMissingError, } from '../platform/browser/agent-browser.js';
|
|
8
|
+
/**
|
|
9
|
+
* `cortex-browser`: agent-browser, attached to the Chrome Cortex manages for this session.
|
|
10
|
+
*
|
|
11
|
+
* Each call leases the session's browser from the daemon (starting Chrome if needed), then runs
|
|
12
|
+
* agent-browser here so its output streams straight back. Every failure is an error with a reason;
|
|
13
|
+
* nothing quietly falls back to a different browser.
|
|
14
|
+
*/
|
|
15
|
+
const HELP = {
|
|
16
|
+
name: 'cortex-browser',
|
|
17
|
+
description: [
|
|
18
|
+
"Drive a real browser from any Cortex session: agent-browser, attached to the session's own tab",
|
|
19
|
+
"in the Chrome Cortex manages on the server or on one of your devices.",
|
|
20
|
+
'',
|
|
21
|
+
'Every argument except --device is passed to agent-browser. Full command guide:',
|
|
22
|
+
' cortex-browser skills get core',
|
|
23
|
+
].join('\n'),
|
|
24
|
+
usage: 'cortex-browser [--device <name>] <agent-browser command> [args...]',
|
|
25
|
+
options: [
|
|
26
|
+
{ flag: '--device <name>', description: "Whose Chrome: 'server' or a connected device. Sticks for the session", default: "the session's last device, else server" },
|
|
27
|
+
{ flag: '--help, -h', description: 'Show this help (agent-browser <command> --help for one command)' },
|
|
28
|
+
],
|
|
29
|
+
examples: [
|
|
30
|
+
{ description: 'Open a page and list what can be clicked', command: 'cortex-browser open http://127.0.0.1:5173 && cortex-browser snapshot -i' },
|
|
31
|
+
{ description: 'Click a ref from the snapshot, then capture the result', command: 'cortex-browser click @e2 && cortex-browser screenshot ./after-click.png' },
|
|
32
|
+
{ description: "Use the Chrome on the user's machine (its localhost, its logins)", command: 'cortex-browser --device my-pc open https://example.com' },
|
|
33
|
+
{ description: 'Read the version-matched command reference', command: 'cortex-browser skills get core --full' },
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
/** Flags that would point agent-browser at a different browser, daemon or tab than the lease. */
|
|
37
|
+
const RESERVED_FLAGS = new Set([
|
|
38
|
+
'--cdp', '--session', '--no-pin-tab', '--auto-connect', '--provider', '-p', '--namespace', '--engine',
|
|
39
|
+
'--executable-path',
|
|
40
|
+
]);
|
|
41
|
+
/** Commands that need no browser and so no lease. */
|
|
42
|
+
const LOCAL_COMMANDS = new Set(['skills', 'help']);
|
|
43
|
+
/** Commands that would change the shared setup underneath every session. */
|
|
44
|
+
const BLOCKED_COMMANDS = {
|
|
45
|
+
connect: 'cortex-browser already connects each call to the session browser',
|
|
46
|
+
install: 'Chrome is managed by Cortex; agent-browser does not install its own',
|
|
47
|
+
upgrade: 'agent-browser is pinned to the version Cortex ships with',
|
|
48
|
+
dashboard: "watch the browser in the Cortex app's Agent browser tab instead",
|
|
49
|
+
mcp: 'call cortex-browser commands directly',
|
|
50
|
+
};
|
|
51
|
+
/** Global agent-browser flags that take a value, so the value is not mistaken for the command. */
|
|
52
|
+
const VALUE_FLAGS = new Set([
|
|
53
|
+
'--session', '--namespace', '--executable-path', '--extension', '--init-script', '--enable', '--args',
|
|
54
|
+
'--user-agent', '--proxy', '--proxy-bypass', '--ca-cert', '--hide-scrollbars', '--provider', '-p',
|
|
55
|
+
'--screenshot-dir', '--screenshot-quality', '--screenshot-format', '--input-mode', '--cdp',
|
|
56
|
+
'--color-scheme', '--download-path', '--max-output', '--allowed-domains', '--action-policy',
|
|
57
|
+
'--confirm-actions', '--idle-timeout', '--engine', '--model', '--config', '--profile',
|
|
58
|
+
'--restore-save', '--restore-check-url', '--restore-check-text', '--restore-check-fn', '--session-name',
|
|
59
|
+
'--state', '--headers', '--threshold', '--baseline', '-d', '--depth', '-s', '--selector',
|
|
60
|
+
]);
|
|
61
|
+
/** Flags whose value is a directory or file wherever they appear. */
|
|
62
|
+
const PATH_FLAGS = new Set(['--screenshot-dir', '--download-path', '--baseline']);
|
|
63
|
+
/**
|
|
64
|
+
* Commands that write or read local files, and how many leading positionals are not files
|
|
65
|
+
* (`download <selector> <path>`). The daemon resolves a relative path against ITS working
|
|
66
|
+
* directory, not the caller's, so these are made absolute before they leave this process.
|
|
67
|
+
*/
|
|
68
|
+
const FILE_COMMANDS = {
|
|
69
|
+
screenshot: 0, pdf: 0, download: 1, upload: 1, record: 0, trace: 0, profiler: 0, network: 0, har: 0,
|
|
70
|
+
state: 0, diff: 0,
|
|
71
|
+
};
|
|
72
|
+
const FILE_EXTENSIONS = /\.(png|jpe?g|webp|gif|pdf|webm|mp4|json|har|zip|txt|html?|csv|xml|md|log|cpuprofile)$/i;
|
|
73
|
+
export class BrowserUsageError extends Error {
|
|
74
|
+
}
|
|
75
|
+
/** The first token that is neither a flag nor a flag's value, with its index. */
|
|
76
|
+
function findCommand(args) {
|
|
77
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
78
|
+
const token = args[i];
|
|
79
|
+
if (token.startsWith('-')) {
|
|
80
|
+
if (VALUE_FLAGS.has(token))
|
|
81
|
+
i += 1;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
return { command: token, index: i };
|
|
85
|
+
}
|
|
86
|
+
return { command: null, index: -1 };
|
|
87
|
+
}
|
|
88
|
+
export function parseBrowserArgs(argv) {
|
|
89
|
+
let device = null;
|
|
90
|
+
const args = [];
|
|
91
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
92
|
+
const token = argv[i];
|
|
93
|
+
if (token === '--device' || token.startsWith('--device=')) {
|
|
94
|
+
const value = token === '--device' ? argv[i + 1] : token.slice('--device='.length);
|
|
95
|
+
if (!value || value.startsWith('-')) {
|
|
96
|
+
throw new BrowserUsageError(formatError('--device requires a device name', {
|
|
97
|
+
hint: "use 'server' for this machine, or a connected device name (cortex-browser --device my-pc open …)",
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
device = value;
|
|
101
|
+
if (token === '--device')
|
|
102
|
+
i += 1;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const flag = token.split('=')[0];
|
|
106
|
+
if (RESERVED_FLAGS.has(flag)) {
|
|
107
|
+
throw new BrowserUsageError(formatError(`${flag} is set by cortex-browser and cannot be passed`, {
|
|
108
|
+
hint: 'cortex-browser attaches every call to this session\'s own tab; use --device to pick whose Chrome',
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
if (token === '--pin-tab')
|
|
112
|
+
continue; // always on
|
|
113
|
+
args.push(token);
|
|
114
|
+
}
|
|
115
|
+
const { command } = findCommand(args);
|
|
116
|
+
// No command at all (`cortex-browser`, `cortex-browser --device x`) shows this help rather than
|
|
117
|
+
// leasing a browser just to print agent-browser's.
|
|
118
|
+
const help = command === null && !args.some((a) => a === '--version' || a === '-V');
|
|
119
|
+
if (command && Object.hasOwn(BLOCKED_COMMANDS, command)) {
|
|
120
|
+
throw new BrowserUsageError(formatError(`'${command}' is not available through cortex-browser`, {
|
|
121
|
+
hint: BLOCKED_COMMANDS[command],
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
if (command === 'close' && args.includes('--all')) {
|
|
125
|
+
throw new BrowserUsageError(formatError("'close --all' would disconnect every other session's browser", {
|
|
126
|
+
hint: "use 'cortex-browser close' to close only this session's connection",
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
return { help, device, args, command };
|
|
130
|
+
}
|
|
131
|
+
/** Does this command run without a browser (help, version, bundled skills)? */
|
|
132
|
+
export function isLocalCommand(parsed) {
|
|
133
|
+
if (parsed.command && LOCAL_COMMANDS.has(parsed.command))
|
|
134
|
+
return true;
|
|
135
|
+
if (parsed.args.some((a) => a === '--help' || a === '-h'))
|
|
136
|
+
return true;
|
|
137
|
+
return parsed.command === null && parsed.args.some((a) => a === '--version' || a === '-V');
|
|
138
|
+
}
|
|
139
|
+
function looksLikePath(token) {
|
|
140
|
+
if (!token || token.startsWith('-') || token.startsWith('@') || token.includes('://'))
|
|
141
|
+
return false;
|
|
142
|
+
if (/[*?{}[\]]/.test(token))
|
|
143
|
+
return false; // a URL pattern (`network route "*.png"`), not a file
|
|
144
|
+
if (path.isAbsolute(token))
|
|
145
|
+
return false;
|
|
146
|
+
return token.startsWith('./') || token.startsWith('../') || FILE_EXTENSIONS.test(token);
|
|
147
|
+
}
|
|
148
|
+
/** Make the file arguments of file-writing commands absolute against the caller's directory. */
|
|
149
|
+
export function absolutizePaths(args, cwd) {
|
|
150
|
+
const out = [...args];
|
|
151
|
+
for (let i = 0; i < out.length - 1; i += 1) {
|
|
152
|
+
if (PATH_FLAGS.has(out[i]) && !path.isAbsolute(out[i + 1]) && !out[i + 1].startsWith('-')) {
|
|
153
|
+
out[i + 1] = path.resolve(cwd, out[i + 1]);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const { command, index } = findCommand(out);
|
|
157
|
+
if (!command || !Object.hasOwn(FILE_COMMANDS, command))
|
|
158
|
+
return out;
|
|
159
|
+
let skip = FILE_COMMANDS[command];
|
|
160
|
+
for (let i = index + 1; i < out.length; i += 1) {
|
|
161
|
+
const token = out[i];
|
|
162
|
+
if (token.startsWith('-')) {
|
|
163
|
+
if (VALUE_FLAGS.has(token))
|
|
164
|
+
i += 1;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (skip > 0) {
|
|
168
|
+
skip -= 1;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (looksLikePath(token))
|
|
172
|
+
out[i] = path.resolve(cwd, token);
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
async function httpPost(url, body, headers) {
|
|
177
|
+
const response = await fetch(url, {
|
|
178
|
+
method: 'POST',
|
|
179
|
+
headers: { 'content-type': 'application/json', ...headers },
|
|
180
|
+
body: JSON.stringify(body),
|
|
181
|
+
// A device's first Chrome launch can take the device's own 90s budget plus the round trip.
|
|
182
|
+
signal: AbortSignal.timeout(180_000),
|
|
183
|
+
});
|
|
184
|
+
const text = await response.text();
|
|
185
|
+
let parsed = text;
|
|
186
|
+
try {
|
|
187
|
+
parsed = JSON.parse(text);
|
|
188
|
+
}
|
|
189
|
+
catch { /* non-JSON bodies surface as text */ }
|
|
190
|
+
return { status: response.status, body: parsed };
|
|
191
|
+
}
|
|
192
|
+
/** stdout passes straight through; stderr is held so a recoverable tab_gone can be retried
|
|
193
|
+
* without showing the agent an error that was already handled. */
|
|
194
|
+
function spawnExec(bin, args, env, cwd, quiet = false) {
|
|
195
|
+
return new Promise((resolve) => {
|
|
196
|
+
let stderr = '';
|
|
197
|
+
const child = spawn(bin, args, { env, cwd, stdio: [quiet ? 'ignore' : 'inherit', quiet ? 'ignore' : 'inherit', 'pipe'] });
|
|
198
|
+
child.stderr?.on('data', (chunk) => { stderr += String(chunk); });
|
|
199
|
+
child.on('error', (e) => resolve({ code: 127, stderr: `${stderr}cortex-browser: cannot run ${bin}: ${e.message}\n` }));
|
|
200
|
+
child.on('close', (code, signal) => resolve({ code: code ?? (signal ? 128 : 1), stderr }));
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
class BrowserCliError extends Error {
|
|
204
|
+
exitCode;
|
|
205
|
+
constructor(message, exitCode = 1) {
|
|
206
|
+
super(message);
|
|
207
|
+
this.exitCode = exitCode;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async function lease(options, env, sessionId, device) {
|
|
211
|
+
const port = env.WEBHOOK_PORT || '3001';
|
|
212
|
+
const url = `http://127.0.0.1:${port}/webhook/browser`;
|
|
213
|
+
const notice = setTimeout(() => {
|
|
214
|
+
options.writeErr(`cortex-browser: starting the browser${device ? ` on ${device}` : ''}…\n`);
|
|
215
|
+
}, options.slowNoticeMs);
|
|
216
|
+
let response;
|
|
217
|
+
try {
|
|
218
|
+
response = await options.post(url, { action: 'lease', sessionId, device }, { [AUTH_HEADER]: env.CORTEX_WEBHOOK_TOKEN || '' });
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
throw new BrowserCliError(formatError(`cannot reach the Cortex daemon at 127.0.0.1:${port}: ${error.message}`, {
|
|
222
|
+
hint: 'cortex-browser works inside Cortex sessions while the Cortex server is running',
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
finally {
|
|
226
|
+
clearTimeout(notice);
|
|
227
|
+
}
|
|
228
|
+
if (response.status === 401) {
|
|
229
|
+
throw new BrowserCliError(formatError('the Cortex daemon rejected this call (bad or missing CORTEX_WEBHOOK_TOKEN)', {
|
|
230
|
+
hint: 'run cortex-browser from a Cortex session, which sets the token',
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
if (response.status === 404) {
|
|
234
|
+
throw new BrowserCliError(formatError('this Cortex server has no browser endpoint yet', {
|
|
235
|
+
hint: 'the server needs a restart onto the version that ships cortex-browser',
|
|
236
|
+
}));
|
|
237
|
+
}
|
|
238
|
+
const body = response.body;
|
|
239
|
+
if (response.status !== 200 || !body?.success) {
|
|
240
|
+
const detail = typeof body === 'object' && body ? body.error : String(body ?? '');
|
|
241
|
+
throw new BrowserCliError(formatError(`browser unavailable: ${detail || `HTTP ${response.status}`}`, { hint: body?.hint }));
|
|
242
|
+
}
|
|
243
|
+
return body.data;
|
|
244
|
+
}
|
|
245
|
+
export async function runBrowserCli(argv, options = {}) {
|
|
246
|
+
const env = options.env ?? process.env;
|
|
247
|
+
const cwd = options.cwd ?? process.cwd();
|
|
248
|
+
const writeErr = options.writeErr ?? ((text) => { process.stderr.write(text); });
|
|
249
|
+
const exec = options.exec ?? spawnExec;
|
|
250
|
+
const post = options.post ?? httpPost;
|
|
251
|
+
let parsed;
|
|
252
|
+
try {
|
|
253
|
+
parsed = parseBrowserArgs(argv);
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
if (error instanceof BrowserUsageError) {
|
|
257
|
+
writeErr(`${error.message}\n`);
|
|
258
|
+
return 2;
|
|
259
|
+
}
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
if (parsed.help) {
|
|
263
|
+
process.stdout.write(`${formatHelp(HELP)}\n`);
|
|
264
|
+
return 0;
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
if (isLocalCommand(parsed)) {
|
|
268
|
+
const bin = resolveAgentBrowserBin(env);
|
|
269
|
+
const run = await exec(bin, parsed.args, agentBrowserBaseEnv(env), cwd);
|
|
270
|
+
if (run.stderr)
|
|
271
|
+
writeErr(run.stderr);
|
|
272
|
+
return run.code;
|
|
273
|
+
}
|
|
274
|
+
const sessionId = env.CORTEX_SESSION_ID || env.CORTEX_EXECUTION_ID || '';
|
|
275
|
+
if (!sessionId) {
|
|
276
|
+
writeErr(`${formatError('no Cortex session (CORTEX_SESSION_ID is unset)', {
|
|
277
|
+
hint: 'cortex-browser leases a browser per Cortex session; run it from a session\'s shell',
|
|
278
|
+
})}\n`);
|
|
279
|
+
return 2;
|
|
280
|
+
}
|
|
281
|
+
const data = await lease({ post, writeErr, slowNoticeMs: options.slowNoticeMs ?? 2_000 }, env, sessionId, parsed.device);
|
|
282
|
+
const callEnv = agentBrowserCallEnv(data.env, env);
|
|
283
|
+
const args = absolutizePaths(parsed.args, cwd);
|
|
284
|
+
let run = await exec(data.bin, agentBrowserArgs(data.cdpEndpoint, data.abSession, args), callEnv, cwd);
|
|
285
|
+
if (run.code !== 0 && isTabGone(run.stderr)) {
|
|
286
|
+
// The tab this session was bound to is gone (Chrome was restarted, or someone closed it).
|
|
287
|
+
// The command never ran, so binding a fresh tab and running it once more is safe.
|
|
288
|
+
const rebound = await exec(data.bin, agentBrowserArgs(data.cdpEndpoint, data.abSession, ['tab', 'new']), callEnv, cwd, true);
|
|
289
|
+
if (rebound.code === 0) {
|
|
290
|
+
writeErr('cortex-browser: this session\'s previous tab is gone (closed after 10 idle minutes, or the browser restarted); continuing in a new blank tab\n');
|
|
291
|
+
run = await exec(data.bin, agentBrowserArgs(data.cdpEndpoint, data.abSession, args), callEnv, cwd);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (run.stderr)
|
|
295
|
+
writeErr(run.stderr);
|
|
296
|
+
await post(`http://127.0.0.1:${env.WEBHOOK_PORT || '3001'}/webhook/browser`, { action: 'report', sessionId }, { [AUTH_HEADER]: env.CORTEX_WEBHOOK_TOKEN || '' }).catch(() => undefined);
|
|
297
|
+
return run.code;
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
if (error instanceof BrowserCliError) {
|
|
301
|
+
writeErr(`${error.message}\n`);
|
|
302
|
+
return error.exitCode;
|
|
303
|
+
}
|
|
304
|
+
if (error instanceof AgentBrowserMissingError) {
|
|
305
|
+
writeErr(`${formatError(error.message, { hint: error.hint })}\n`);
|
|
306
|
+
return 1;
|
|
307
|
+
}
|
|
308
|
+
writeErr(`cortex-browser: ${error.message}\n`);
|
|
309
|
+
return 1;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
313
|
+
process.exitCode = await runBrowserCli(argv);
|
|
314
|
+
}
|
|
315
|
+
if (isMainModule(import.meta.url)) {
|
|
316
|
+
void main();
|
|
317
|
+
}
|
package/dist/entry/cli-help.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare function getInitHelp(): string;
|
|
|
2
2
|
export declare function getSetupGatewayHelp(): string;
|
|
3
3
|
export declare function getTuiHelp(): string;
|
|
4
4
|
export declare function getUiHelp(): string;
|
|
5
|
+
export declare function getPathHelp(): string;
|
|
5
6
|
export declare function getClientHelp(): string;
|
|
6
7
|
export declare function getMemoryHelp(): string;
|
|
7
8
|
export declare function getScheduleHelp(): string;
|
package/dist/entry/cli-help.js
CHANGED
|
@@ -20,17 +20,17 @@ export function getInitHelp() {
|
|
|
20
20
|
}
|
|
21
21
|
export function getSetupGatewayHelp() {
|
|
22
22
|
return [
|
|
23
|
-
'Auto-detect Claude Code / PI configurations and generate gateway.yaml +
|
|
23
|
+
'Auto-detect Claude Code / PI configurations and generate gateway.yaml + models.json',
|
|
24
24
|
'',
|
|
25
25
|
'Usage: cortex setup-gateway [--dry-run] [--output-dir <path>]',
|
|
26
26
|
'',
|
|
27
27
|
'Discovers backend endpoints from local Claude Code and PI configs, then',
|
|
28
|
-
'writes ~/.aistatus/gateway.yaml (with backup) and $CORTEX_HOME/config/
|
|
28
|
+
'writes ~/.aistatus/gateway.yaml (with backup) and $CORTEX_HOME/config/models.json.',
|
|
29
29
|
'Without flags, this command writes files in place.',
|
|
30
30
|
'',
|
|
31
31
|
'Options:',
|
|
32
32
|
' --dry-run Print the generated gateway.yaml to stdout without writing anything',
|
|
33
|
-
' --output-dir <path> Write gateway.yaml and
|
|
33
|
+
' --output-dir <path> Write gateway.yaml and models.json under <path> instead of the defaults',
|
|
34
34
|
' --help, -h Show this help',
|
|
35
35
|
].join('\n');
|
|
36
36
|
}
|
|
@@ -71,6 +71,34 @@ export function getUiHelp() {
|
|
|
71
71
|
],
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
+
export function getPathHelp() {
|
|
75
|
+
return formatHelp({
|
|
76
|
+
name: 'cortex path',
|
|
77
|
+
description: 'Make this install\'s commands (cortex, cortex-signal, …) available in new terminals',
|
|
78
|
+
usage: 'cortex path <install|remove|status> [--home <path>] [--dry-run] [--json]',
|
|
79
|
+
commands: [
|
|
80
|
+
{
|
|
81
|
+
name: 'install',
|
|
82
|
+
description: 'Write launchers that use this install\'s Node into <home>/runtime/bin and put that '
|
|
83
|
+
+ 'directory on PATH (shell profiles on Linux/macOS, the user Path on Windows)',
|
|
84
|
+
},
|
|
85
|
+
{ name: 'remove', description: 'Delete the launchers and undo the PATH change' },
|
|
86
|
+
{ name: 'status', description: 'Show whether the launchers exist, are current, and are on PATH' },
|
|
87
|
+
],
|
|
88
|
+
options: [
|
|
89
|
+
{ flag: '--home <path>', description: 'CORTEX_HOME the launchers belong to', default: '$CORTEX_HOME or ~/.cortex' },
|
|
90
|
+
{ flag: '--dry-run', description: 'Report what install or remove would change and change nothing' },
|
|
91
|
+
{ flag: '--json', description: 'Print the result as JSON' },
|
|
92
|
+
{ flag: '--help, -h', description: 'Show this help' },
|
|
93
|
+
],
|
|
94
|
+
examples: [
|
|
95
|
+
{ description: 'Add cortex to new terminals', command: 'cortex path install' },
|
|
96
|
+
{ description: 'Preview the change', command: 'cortex path install --dry-run --json' },
|
|
97
|
+
{ description: 'Check the current state', command: 'cortex path status' },
|
|
98
|
+
{ description: 'Undo it', command: 'cortex path remove' },
|
|
99
|
+
],
|
|
100
|
+
});
|
|
101
|
+
}
|
|
74
102
|
export function getClientHelp() {
|
|
75
103
|
return formatHelp({
|
|
76
104
|
name: 'cortex client',
|
|
@@ -130,7 +158,7 @@ export function getScheduleHelp() {
|
|
|
130
158
|
{ name: 'list', description: 'List schedules (--project to filter)' },
|
|
131
159
|
{ name: 'get <id>', description: 'Show one schedule' },
|
|
132
160
|
{ name: 'add --type <type>', description: 'Create a schedule' },
|
|
133
|
-
{ name: 'edit <id>', description: 'Change message, project,
|
|
161
|
+
{ name: 'edit <id>', description: 'Change message, project, model, thinking, pre-check or timing (the type is fixed)' },
|
|
134
162
|
{ name: 'pause <id>', description: 'Pause a recurring schedule' },
|
|
135
163
|
{ name: 'resume <id>', description: 'Resume a paused schedule' },
|
|
136
164
|
{ name: 'remove <id>', description: 'Delete a schedule (--dry-run to preview)' },
|
|
@@ -143,7 +171,8 @@ export function getScheduleHelp() {
|
|
|
143
171
|
{ flag: '--delay <duration>', description: 'once: fire this long from now, e.g. 90m, 2h' },
|
|
144
172
|
{ flag: '--message <text|->', description: 'Prompt for the fired session; "-" reads stdin' },
|
|
145
173
|
{ flag: '--project <id>', description: 'Project the fired session belongs to', default: 'general' },
|
|
146
|
-
{ flag: '--
|
|
174
|
+
{ flag: '--model [provider/]model', description: 'Model to run', default: 'the default model' },
|
|
175
|
+
{ flag: '--thinking <level>', description: 'Thinking level for the selected model' },
|
|
147
176
|
{ flag: '--pre-check <cmd>', description: 'Shell gate run before each fire; non-zero exit skips it' },
|
|
148
177
|
{ flag: '--idempotency-key <key>', description: 'add: return the schedule already created with this key' },
|
|
149
178
|
{ flag: '--dry-run', description: 'remove: show what would be removed' },
|
|
@@ -177,9 +206,10 @@ function getCliCommands() {
|
|
|
177
206
|
{ name: 'doctor', description: 'Health-check the install (runtime, login, platform, gateway); --fix to repair' },
|
|
178
207
|
{ name: 'auth status', description: t('cmd.auth.cli.statusDescription') },
|
|
179
208
|
{ name: 'feishu', description: 'Manage Feishu user-identity login (login / status / logout)' },
|
|
180
|
-
{ name: 'setup-gateway', description: 'Auto-detect Claude/PI configs and generate gateway.yaml +
|
|
209
|
+
{ name: 'setup-gateway', description: 'Auto-detect Claude/PI configs and generate gateway.yaml + models.json' },
|
|
181
210
|
{ name: 'ui enable', description: 'Enable the local Web UI endpoint the desktop app connects to' },
|
|
182
211
|
{ name: 'client remove', description: 'Unregister a remote machine and uninstall its cortex-client' },
|
|
212
|
+
{ name: 'path install', description: 'Make cortex available in new terminals (remove / status to undo or check)' },
|
|
183
213
|
{ name: 'schedule', description: 'List, add, edit, pause, resume and remove scheduled tasks' },
|
|
184
214
|
{ name: 'memory', description: 'Rebuild project memory indexes; report knowledge lifecycle findings' },
|
|
185
215
|
{ name: 'tui', description: 'Start the Terminal UI (TUI) client for local interaction' },
|
|
@@ -197,6 +227,7 @@ function getCliExamples() {
|
|
|
197
227
|
{ description: 'Re-generate gateway config', command: 'cortex setup-gateway' },
|
|
198
228
|
{ description: 'Enable the local Web UI endpoint', command: 'cortex ui enable' },
|
|
199
229
|
{ description: 'Remove a remote machine and its client', command: 'cortex client remove --device trainer' },
|
|
230
|
+
{ description: 'Add cortex to new terminals', command: 'cortex path install' },
|
|
200
231
|
{ description: 'List scheduled tasks', command: 'cortex schedule list' },
|
|
201
232
|
{ description: 'Rebuild every project memory index', command: 'cortex memory regen' },
|
|
202
233
|
{ description: 'Start the server', command: 'cortex start' },
|