@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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Per-device app tokens. A desktop or mobile app that pairs with a code gets its own token, sent as
|
|
2
|
+
// `x-cortex-token` exactly like the shared client token, so the app needs no other change. Each one
|
|
3
|
+
// can be revoked alone; the shared client token stays with cortex-client devices.
|
|
4
|
+
//
|
|
5
|
+
// Only a SHA-256 of each token is stored. The server is the only writer, so the file is read once.
|
|
6
|
+
import * as crypto from 'crypto';
|
|
7
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import { timingSafeEqualStr } from '../../core/auth.js';
|
|
10
|
+
import { createLogger } from '../../core/log.js';
|
|
11
|
+
const log = createLogger('ui-http');
|
|
12
|
+
/** Last-use times move on every request; disk sees them at most this often per device. */
|
|
13
|
+
export const DEVICE_SEEN_PERSIST_MS = 10 * 60 * 1000;
|
|
14
|
+
const NAME_MAX = 60;
|
|
15
|
+
const NAME_FALLBACK = 'App';
|
|
16
|
+
function hashToken(token) {
|
|
17
|
+
return crypto.createHash('sha256').update(token).digest('hex');
|
|
18
|
+
}
|
|
19
|
+
function cleanName(name) {
|
|
20
|
+
const trimmed = name.trim().slice(0, NAME_MAX);
|
|
21
|
+
return trimmed || NAME_FALLBACK;
|
|
22
|
+
}
|
|
23
|
+
function isStoredDevice(value) {
|
|
24
|
+
const d = value;
|
|
25
|
+
return typeof d?.id === 'string' && typeof d.name === 'string' && typeof d.tokenHash === 'string'
|
|
26
|
+
&& typeof d.createdAt === 'number' && typeof d.lastSeenAt === 'number';
|
|
27
|
+
}
|
|
28
|
+
function load(file) {
|
|
29
|
+
if (!file)
|
|
30
|
+
return [];
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
33
|
+
return Array.isArray(parsed?.devices) ? parsed.devices.filter(isStoredDevice) : [];
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return []; // absent or corrupt → no paired devices; the apps pair again
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function publicView(d) {
|
|
40
|
+
return { id: d.id, name: d.name, createdAt: d.createdAt, lastSeenAt: d.lastSeenAt };
|
|
41
|
+
}
|
|
42
|
+
export function createUiDeviceStore(opts = {}) {
|
|
43
|
+
const now = opts.now ?? (() => Date.now());
|
|
44
|
+
const devices = load(opts.file);
|
|
45
|
+
/** lastSeenAt as last written, per device id. */
|
|
46
|
+
const persistedSeen = new Map(devices.map((d) => [d.id, d.lastSeenAt]));
|
|
47
|
+
const persist = () => {
|
|
48
|
+
if (!opts.file)
|
|
49
|
+
return;
|
|
50
|
+
try {
|
|
51
|
+
mkdirSync(path.dirname(opts.file), { recursive: true });
|
|
52
|
+
const tmp = `${opts.file}.tmp`;
|
|
53
|
+
writeFileSync(tmp, JSON.stringify({ devices }), { mode: 0o600 });
|
|
54
|
+
renameSync(tmp, opts.file);
|
|
55
|
+
for (const d of devices)
|
|
56
|
+
persistedSeen.set(d.id, d.lastSeenAt);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
log.warn(`could not persist paired devices: ${e.message}`);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
// Constant-time walk over every hash, as the session store does: the set is a handful of apps.
|
|
63
|
+
const find = (token) => {
|
|
64
|
+
const hash = hashToken(token);
|
|
65
|
+
let hit;
|
|
66
|
+
for (const d of devices)
|
|
67
|
+
if (timingSafeEqualStr(d.tokenHash, hash))
|
|
68
|
+
hit = d;
|
|
69
|
+
return hit;
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
issue(name) {
|
|
73
|
+
const t = now();
|
|
74
|
+
const token = crypto.randomBytes(32).toString('hex');
|
|
75
|
+
const device = {
|
|
76
|
+
id: crypto.randomBytes(6).toString('hex'), name: cleanName(name),
|
|
77
|
+
createdAt: t, lastSeenAt: t, tokenHash: hashToken(token),
|
|
78
|
+
};
|
|
79
|
+
devices.push(device);
|
|
80
|
+
persist();
|
|
81
|
+
return { device: publicView(device), token };
|
|
82
|
+
},
|
|
83
|
+
match(token) {
|
|
84
|
+
if (!token)
|
|
85
|
+
return undefined;
|
|
86
|
+
const device = find(token);
|
|
87
|
+
if (!device)
|
|
88
|
+
return undefined;
|
|
89
|
+
device.lastSeenAt = now();
|
|
90
|
+
if (device.lastSeenAt - (persistedSeen.get(device.id) ?? 0) >= DEVICE_SEEN_PERSIST_MS)
|
|
91
|
+
persist();
|
|
92
|
+
return publicView(device);
|
|
93
|
+
},
|
|
94
|
+
list() {
|
|
95
|
+
return devices.map(publicView);
|
|
96
|
+
},
|
|
97
|
+
revoke(id) {
|
|
98
|
+
const index = devices.findIndex((d) => d.id === id);
|
|
99
|
+
if (index < 0)
|
|
100
|
+
return false;
|
|
101
|
+
devices.splice(index, 1);
|
|
102
|
+
persistedSeen.delete(id);
|
|
103
|
+
persist();
|
|
104
|
+
return true;
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as http from 'http';
|
|
2
|
+
import type { Duplex } from 'stream';
|
|
2
3
|
import type { AnyRouter } from '@trpc/server';
|
|
3
4
|
import type { AccessJwtVerifier } from './access-jwt.js';
|
|
4
5
|
export interface UiHttpServerOptions {
|
|
@@ -6,6 +7,8 @@ export interface UiHttpServerOptions {
|
|
|
6
7
|
router: AnyRouter;
|
|
7
8
|
/** Accessor for the bearer token the server accepts (wiring passes getClientToken). */
|
|
8
9
|
getToken: () => string;
|
|
10
|
+
/** Paired apps' own tokens, accepted wherever the client token is (including the port forward). */
|
|
11
|
+
matchDeviceToken?: DeviceTokenMatcher;
|
|
9
12
|
/** TCP port to listen on (0 = ephemeral, useful in tests). */
|
|
10
13
|
port: number;
|
|
11
14
|
/** Host to bind. Defaults to 127.0.0.1 (loopback only — exposure is via a tunnel). */
|
|
@@ -27,9 +30,9 @@ export interface UiHttpServerOptions {
|
|
|
27
30
|
*/
|
|
28
31
|
customRoutes?: Record<string, CustomRouteHandler>;
|
|
29
32
|
/**
|
|
30
|
-
* Custom-route paths served WITHOUT the auth gate. Only the login and session-probe
|
|
31
|
-
* here: a browser that holds no credential yet must be able to reach them,
|
|
32
|
-
* nothing more than a boolean or a 401.
|
|
33
|
+
* Custom-route paths served WITHOUT the auth gate. Only the login, app-pairing and session-probe
|
|
34
|
+
* routes belong here: a browser or app that holds no credential yet must be able to reach them,
|
|
35
|
+
* and each answers with nothing more than a boolean, a credential for a valid secret, or a 401.
|
|
33
36
|
*/
|
|
34
37
|
publicRoutes?: string[];
|
|
35
38
|
/**
|
|
@@ -38,11 +41,24 @@ export interface UiHttpServerOptions {
|
|
|
38
41
|
* predicate the gate uses, instead of a second copy that could drift.
|
|
39
42
|
*/
|
|
40
43
|
authorize: Authorizer;
|
|
44
|
+
/** Per-request tRPC context built from the incoming request; defaults to `{}`. */
|
|
45
|
+
createContext?: (req: http.IncomingMessage) => object;
|
|
41
46
|
/**
|
|
42
47
|
* Mount the TCP-over-WebSocket port forward on `/forward` (desktop shell → a loopback service on
|
|
43
48
|
* this host). Defaults to on; `CORTEX_PORT_FORWARD=0` at the call site turns it off.
|
|
44
49
|
*/
|
|
45
50
|
portForward?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* WebSocket endpoints beyond the port forward, by exact path. Each authenticates its own handshake
|
|
53
|
+
* (a page cannot set `x-cortex-token` on one); the server only applies the Origin check first, the
|
|
54
|
+
* same one every state-changing request gets, and closes each route on shutdown.
|
|
55
|
+
*/
|
|
56
|
+
upgradeRoutes?: Record<string, UpgradeRoute>;
|
|
57
|
+
}
|
|
58
|
+
/** A WebSocket endpoint mounted on the server's `upgrade` event. */
|
|
59
|
+
export interface UpgradeRoute {
|
|
60
|
+
handleUpgrade: (req: http.IncomingMessage, socket: Duplex, head: Buffer) => void;
|
|
61
|
+
close: () => void;
|
|
46
62
|
}
|
|
47
63
|
/** Handler for a custom API route mounted on the HTTP server. Receives the raw request
|
|
48
64
|
* and response after the auth gate passes; responsible for the full lifecycle
|
|
@@ -52,6 +68,8 @@ export interface UiHttpServer {
|
|
|
52
68
|
server: http.Server;
|
|
53
69
|
close: () => Promise<void>;
|
|
54
70
|
}
|
|
71
|
+
/** Whether a presented `x-cortex-token` belongs to a paired app (ui-devices.ts). */
|
|
72
|
+
export type DeviceTokenMatcher = (token: string | undefined) => boolean;
|
|
55
73
|
/** Decides whether one request may pass the gate. Async only because the JWT leg is. */
|
|
56
74
|
export type Authorizer = (req: http.IncomingMessage) => Promise<boolean>;
|
|
57
75
|
/**
|
|
@@ -64,6 +82,7 @@ export type Authorizer = (req: http.IncomingMessage) => Promise<boolean>;
|
|
|
64
82
|
*/
|
|
65
83
|
export declare function createAuthorizer(opts: {
|
|
66
84
|
getToken: () => string;
|
|
85
|
+
matchDeviceToken?: DeviceTokenMatcher;
|
|
67
86
|
verifySession?: (sid: string | undefined) => boolean;
|
|
68
87
|
verifyAccessJwt?: AccessJwtVerifier;
|
|
69
88
|
}): Authorizer;
|
|
@@ -17,7 +17,8 @@ const CORS_ALLOW_METHODS = 'GET, POST, OPTIONS';
|
|
|
17
17
|
// `x-session-id` / `x-file-name` are the custom headers the file-upload route reads; the app's
|
|
18
18
|
// upload is cross-origin (webview `cortexui://localhost` → server), so its CORS preflight fails
|
|
19
19
|
// unless these are allow-listed alongside the auth token and content-type.
|
|
20
|
-
|
|
20
|
+
// `x-cortex-client` names the app (desktop / android / browser) on every tRPC call.
|
|
21
|
+
const CORS_ALLOW_HEADERS = `${AUTH_HEADER}, content-type, x-session-id, x-file-name, x-cortex-client`;
|
|
21
22
|
const CORS_MAX_AGE = '86400'; // 24 h preflight cache
|
|
22
23
|
/**
|
|
23
24
|
* Largest tRPC request body. The big legitimate payloads are a pasted message (`sessions.send`,
|
|
@@ -27,11 +28,14 @@ const CORS_MAX_AGE = '86400'; // 24 h preflight cache
|
|
|
27
28
|
const TRPC_MAX_BODY_BYTES = 16 * 1024 * 1024;
|
|
28
29
|
/** Methods that never change state. Everything else is checked against the request's Origin. */
|
|
29
30
|
const SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
|
|
30
|
-
/**
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Bearer gate: the shared client token (constant-time compare) or, when a matcher is wired, a
|
|
33
|
+
* paired app's own token.
|
|
34
|
+
*/
|
|
35
|
+
function isAuthorized(req, getToken, matchDeviceToken) {
|
|
32
36
|
const provided = req.headers[AUTH_HEADER];
|
|
33
37
|
const headerVal = Array.isArray(provided) ? provided[0] : provided;
|
|
34
|
-
return timingSafeEqualStr(getToken(), headerVal);
|
|
38
|
+
return timingSafeEqualStr(getToken(), headerVal) || matchDeviceToken?.(headerVal) === true;
|
|
35
39
|
}
|
|
36
40
|
/**
|
|
37
41
|
* Cloudflare Access path: verify the `Cf-Access-Jwt-Assertion` JWT the edge injects. Returns false
|
|
@@ -57,7 +61,7 @@ async function isAccessAuthorized(req, verifyAccessJwt) {
|
|
|
57
61
|
*/
|
|
58
62
|
export function createAuthorizer(opts) {
|
|
59
63
|
return async (req) => {
|
|
60
|
-
if (isAuthorized(req, opts.getToken))
|
|
64
|
+
if (isAuthorized(req, opts.getToken, opts.matchDeviceToken))
|
|
61
65
|
return true;
|
|
62
66
|
if (opts.verifySession?.(sessionIdFrom(req)))
|
|
63
67
|
return true;
|
|
@@ -174,7 +178,7 @@ export function createUiHttpServer(opts) {
|
|
|
174
178
|
const server = createHTTPServer({
|
|
175
179
|
router: opts.router,
|
|
176
180
|
basePath: TRPC_BASE_PATH,
|
|
177
|
-
createContext: () => ({}
|
|
181
|
+
createContext: ({ req }) => opts.createContext?.(req) ?? {},
|
|
178
182
|
maxBodySize: TRPC_MAX_BODY_BYTES,
|
|
179
183
|
// Runs BEFORE the tRPC handler. tRPC paths are auth-gated here; everything else is the SPA stub.
|
|
180
184
|
middleware: async (req, res, next) => {
|
|
@@ -258,20 +262,35 @@ export function createUiHttpServer(opts) {
|
|
|
258
262
|
// `authorize(req)` here instead of `isAuthorized` would silently hand every logged-in page a raw
|
|
259
263
|
// socket to any loopback service on this host. See plan/embedded-browser.md §10.
|
|
260
264
|
const forward = opts.portForward === false ? null : createPortForward();
|
|
261
|
-
|
|
265
|
+
const upgradeRoutes = opts.upgradeRoutes ?? {};
|
|
266
|
+
if (forward || Object.keys(upgradeRoutes).length > 0) {
|
|
262
267
|
server.on('upgrade', (req, socket, head) => {
|
|
263
268
|
const pathname = (req.url ?? '').split('?')[0];
|
|
264
|
-
if (pathname
|
|
269
|
+
if (forward && pathname === FORWARD_PATH) {
|
|
270
|
+
if (!isAuthorized(req, opts.getToken, opts.matchDeviceToken)) {
|
|
271
|
+
log.warn(`forward auth rejected: ${req.url}`);
|
|
272
|
+
socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
|
|
273
|
+
socket.destroy();
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
forward.handleUpgrade(req, socket, head);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const route = Object.hasOwn(upgradeRoutes, pathname) ? upgradeRoutes[pathname] : undefined;
|
|
280
|
+
if (!route) {
|
|
265
281
|
socket.destroy();
|
|
266
282
|
return;
|
|
267
283
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
284
|
+
// A handshake carries cookies like any request, so a foreign page is refused before the route
|
|
285
|
+
// ever sees it.
|
|
286
|
+
const allowList = typeof opts.corsOrigins === 'function' ? opts.corsOrigins() : opts.corsOrigins;
|
|
287
|
+
if (!isTrustedOrigin(req, allowList)) {
|
|
288
|
+
log.warn(`ui-http cross-origin upgrade refused: ${pathname} from ${firstHeader(req.headers.origin)}`);
|
|
289
|
+
socket.write('HTTP/1.1 403 Forbidden\r\n\r\n');
|
|
271
290
|
socket.destroy();
|
|
272
291
|
return;
|
|
273
292
|
}
|
|
274
|
-
|
|
293
|
+
route.handleUpgrade(req, socket, head);
|
|
275
294
|
});
|
|
276
295
|
}
|
|
277
296
|
server.listen(opts.port, host, () => {
|
|
@@ -281,6 +300,8 @@ export function createUiHttpServer(opts) {
|
|
|
281
300
|
});
|
|
282
301
|
const close = () => new Promise((resolve) => {
|
|
283
302
|
forward?.close();
|
|
303
|
+
for (const route of Object.values(upgradeRoutes))
|
|
304
|
+
route.close();
|
|
284
305
|
// Force-close keep-alive + live SSE sockets, else server.close() would hang on them.
|
|
285
306
|
server.closeAllConnections?.();
|
|
286
307
|
server.close(() => resolve());
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Outstanding codes, under the store dir — shared by the server and `cortex ui pair`. */
|
|
2
|
+
export declare const PAIRING_FILE_NAME = "ui-pairing.json";
|
|
3
|
+
/** How long a code stays redeemable. */
|
|
4
|
+
export declare const PAIRING_CODE_TTL_MS: number;
|
|
5
|
+
/**
|
|
6
|
+
* Wrong guesses tolerated before every outstanding code is voided. With 40 bits per code this caps
|
|
7
|
+
* an online guesser's odds at roughly 20 in 10^12 per minted code.
|
|
8
|
+
*/
|
|
9
|
+
export declare const PAIRING_MAX_FAILURES = 20;
|
|
10
|
+
export interface PairingCode {
|
|
11
|
+
/** Display form, `XXXX-XXXX`. */
|
|
12
|
+
code: string;
|
|
13
|
+
expiresAt: number;
|
|
14
|
+
}
|
|
15
|
+
export interface PairingStore {
|
|
16
|
+
create(): PairingCode;
|
|
17
|
+
/** Consume a live code. True at most once per code; every miss counts toward the failure cap. */
|
|
18
|
+
redeem(input: string): boolean;
|
|
19
|
+
}
|
|
20
|
+
/** Canonical form of a typed code, or null when the input cannot be a pairing code at all. */
|
|
21
|
+
export declare function normalizePairingCode(input: string): string | null;
|
|
22
|
+
export declare function createPairingStore(opts: {
|
|
23
|
+
file: string;
|
|
24
|
+
now?: () => number;
|
|
25
|
+
}): PairingStore;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// One-time pairing codes: the short credential a new app or browser types instead of the 64-char
|
|
2
|
+
// client token. A signed-in UI (or `cortex ui pair` on the server) mints a code; redeeming it once
|
|
3
|
+
// hands the newcomer its own device token (apps) or a session cookie (browsers).
|
|
4
|
+
//
|
|
5
|
+
// Codes live in a file rather than in memory because the CLI that mints one runs in a different
|
|
6
|
+
// process from the server that redeems it. Every operation re-reads the file for the same reason.
|
|
7
|
+
import * as crypto from 'crypto';
|
|
8
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import { createLogger } from '../../core/log.js';
|
|
11
|
+
const log = createLogger('ui-http');
|
|
12
|
+
/** Outstanding codes, under the store dir — shared by the server and `cortex ui pair`. */
|
|
13
|
+
export const PAIRING_FILE_NAME = 'ui-pairing.json';
|
|
14
|
+
/** How long a code stays redeemable. */
|
|
15
|
+
export const PAIRING_CODE_TTL_MS = 10 * 60 * 1000;
|
|
16
|
+
/**
|
|
17
|
+
* Wrong guesses tolerated before every outstanding code is voided. With 40 bits per code this caps
|
|
18
|
+
* an online guesser's odds at roughly 20 in 10^12 per minted code.
|
|
19
|
+
*/
|
|
20
|
+
export const PAIRING_MAX_FAILURES = 20;
|
|
21
|
+
/** Crockford base32: no I, L, O or U, so a code read aloud or off a phone screen survives. */
|
|
22
|
+
const ALPHABET = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
|
23
|
+
const CODE_LENGTH = 8;
|
|
24
|
+
/** Look-alikes a person may type for a digit. */
|
|
25
|
+
const LOOKALIKES = { O: '0', I: '1', L: '1' };
|
|
26
|
+
/** Canonical form of a typed code, or null when the input cannot be a pairing code at all. */
|
|
27
|
+
export function normalizePairingCode(input) {
|
|
28
|
+
const raw = input.toUpperCase().replace(/[\s-]/g, '');
|
|
29
|
+
if (raw.length !== CODE_LENGTH)
|
|
30
|
+
return null;
|
|
31
|
+
const mapped = [...raw].map((ch) => LOOKALIKES[ch] ?? ch).join('');
|
|
32
|
+
return [...mapped].every((ch) => ALPHABET.includes(ch)) ? mapped : null;
|
|
33
|
+
}
|
|
34
|
+
function formatCode(raw) {
|
|
35
|
+
return `${raw.slice(0, 4)}-${raw.slice(4)}`;
|
|
36
|
+
}
|
|
37
|
+
function randomCode() {
|
|
38
|
+
const bytes = crypto.randomBytes(CODE_LENGTH);
|
|
39
|
+
return [...bytes].map((b) => ALPHABET[b % ALPHABET.length]).join('');
|
|
40
|
+
}
|
|
41
|
+
function readState(file, now) {
|
|
42
|
+
let parsed = null;
|
|
43
|
+
try {
|
|
44
|
+
parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// absent or corrupt → no codes
|
|
48
|
+
}
|
|
49
|
+
const codes = {};
|
|
50
|
+
for (const [code, exp] of Object.entries(parsed?.codes ?? {})) {
|
|
51
|
+
if (typeof exp === 'number' && exp > now)
|
|
52
|
+
codes[code] = exp;
|
|
53
|
+
}
|
|
54
|
+
return { codes, failures: typeof parsed?.failures === 'number' ? parsed.failures : 0 };
|
|
55
|
+
}
|
|
56
|
+
function writeState(file, state) {
|
|
57
|
+
try {
|
|
58
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
59
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
60
|
+
writeFileSync(tmp, JSON.stringify(state), { mode: 0o600 });
|
|
61
|
+
renameSync(tmp, file);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
log.warn(`could not persist pairing codes: ${e.message}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function createPairingStore(opts) {
|
|
68
|
+
const now = opts.now ?? (() => Date.now());
|
|
69
|
+
const { file } = opts;
|
|
70
|
+
return {
|
|
71
|
+
create() {
|
|
72
|
+
const t = now();
|
|
73
|
+
const state = readState(file, t);
|
|
74
|
+
const raw = randomCode();
|
|
75
|
+
state.codes[raw] = t + PAIRING_CODE_TTL_MS;
|
|
76
|
+
state.failures = 0;
|
|
77
|
+
writeState(file, state);
|
|
78
|
+
return { code: formatCode(raw), expiresAt: state.codes[raw] };
|
|
79
|
+
},
|
|
80
|
+
redeem(input) {
|
|
81
|
+
const state = readState(file, now());
|
|
82
|
+
const raw = normalizePairingCode(input);
|
|
83
|
+
if (raw && raw in state.codes) {
|
|
84
|
+
delete state.codes[raw];
|
|
85
|
+
writeState(file, state);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
state.failures += 1;
|
|
89
|
+
if (state.failures >= PAIRING_MAX_FAILURES) {
|
|
90
|
+
log.warn('too many wrong pairing codes — voiding every outstanding code');
|
|
91
|
+
state.codes = {};
|
|
92
|
+
state.failures = 0;
|
|
93
|
+
}
|
|
94
|
+
writeState(file, state);
|
|
95
|
+
return false;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -229,6 +229,12 @@ function pushWorkerProgress(state, ev) {
|
|
|
229
229
|
type: 'worker-progress', text: ev.text ?? '', worker: ev.worker, ts: ev.ts, turnIndex: turnFor(state),
|
|
230
230
|
});
|
|
231
231
|
}
|
|
232
|
+
function pushThinking(state, ev) {
|
|
233
|
+
pushEvent(state, {
|
|
234
|
+
type: 'thinking', text: ev.text ?? '', ts: ev.ts, turnIndex: turnFor(state),
|
|
235
|
+
...(ev.blockId ? { blockId: ev.blockId } : {}),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
232
238
|
function mergeResolvedInteraction(prior, ev) {
|
|
233
239
|
prior.status = ev.status;
|
|
234
240
|
if (ev.result !== undefined)
|
|
@@ -292,6 +298,8 @@ function consumeParsedEvent(state, ev, chars) {
|
|
|
292
298
|
return pushUser(state, ev);
|
|
293
299
|
if (ev.type === 'assistant')
|
|
294
300
|
return pushAssistant(state, ev);
|
|
301
|
+
if (ev.type === 'thinking')
|
|
302
|
+
return pushThinking(state, ev);
|
|
295
303
|
if (ev.type === 'tool')
|
|
296
304
|
return pushTool(state, ev, chars);
|
|
297
305
|
if (ev.type === 'worker-progress')
|
|
@@ -8,7 +8,7 @@ import type { BoardActionRef } from '../core/board-action.js';
|
|
|
8
8
|
export declare const CONVERSATION_HISTORY_DIR: string;
|
|
9
9
|
/** `worker-progress`: a team worker's interim final reply, recorded in its LEAD's history for
|
|
10
10
|
* display. It is not a user turn (no turn boundary) and never reaches the lead model. */
|
|
11
|
-
export type HistoryEventType = 'user' | 'assistant' | 'tool' | 'interaction' | 'worker-progress';
|
|
11
|
+
export type HistoryEventType = 'user' | 'assistant' | 'thinking' | 'tool' | 'interaction' | 'worker-progress';
|
|
12
12
|
/** Terminal state of one native subagent, as the backend's own task lifecycle reports it. */
|
|
13
13
|
export type SubagentEndStatus = 'completed' | 'failed' | 'killed';
|
|
14
14
|
export interface HistoryDebugDetails {
|
|
@@ -73,6 +73,7 @@ export interface HistoryEvent {
|
|
|
73
73
|
type: HistoryEventType;
|
|
74
74
|
/** user / assistant message text (omitted for tool events). */
|
|
75
75
|
text?: string;
|
|
76
|
+
blockId?: string;
|
|
76
77
|
/** User events only: this turn was authored by Cortex (resume signal, task/thread callback,
|
|
77
78
|
* subtask question, backgrounded agent result), not typed by a human. Absent = human, which is
|
|
78
79
|
* what every row written before this field existed reads as. */
|
|
@@ -150,6 +151,7 @@ export interface RawEvent {
|
|
|
150
151
|
/** edit-marker lines only. */
|
|
151
152
|
originalTs?: string;
|
|
152
153
|
text?: string;
|
|
154
|
+
blockId?: string;
|
|
153
155
|
/** user lines only: Cortex authored this turn rather than a human (see HistoryEvent). */
|
|
154
156
|
systemOrigin?: SystemTurnOrigin;
|
|
155
157
|
noticeLevel?: ChatNoticeLevel;
|
|
@@ -312,6 +314,11 @@ export declare class ConversationHistoryRepo {
|
|
|
312
314
|
subagent?: SubagentRowRef;
|
|
313
315
|
subagentSpawns?: SubagentSpawnRef[];
|
|
314
316
|
}): Promise<void>;
|
|
317
|
+
appendThinking(sessionId: string, opts: {
|
|
318
|
+
text: string;
|
|
319
|
+
blockId?: string;
|
|
320
|
+
ts?: string;
|
|
321
|
+
}): Promise<void>;
|
|
315
322
|
appendDecisionAction(sessionId: string, opts: {
|
|
316
323
|
decisionId: string;
|
|
317
324
|
action: DecisionActionKind;
|
|
@@ -324,6 +324,11 @@ export class ConversationHistoryRepo {
|
|
|
324
324
|
...subagentRowFields(opts.subagent),
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
|
+
appendThinking(sessionId, opts) {
|
|
328
|
+
return this.append(sessionId, {
|
|
329
|
+
type: 'thinking', text: opts.text, blockId: opts.blockId, ts: opts.ts ?? nowIso(),
|
|
330
|
+
});
|
|
331
|
+
}
|
|
327
332
|
appendDecisionAction(sessionId, opts) {
|
|
328
333
|
return this.append(sessionId, {
|
|
329
334
|
type: 'decision-action', decisionId: opts.decisionId, action: opts.action,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type SessionRegistryRepo } from './session-registry-repo.js';
|
|
2
|
+
import type { EngineSelection } from '../domain/agents/engine-selection.js';
|
|
2
3
|
import type { TurnRecord, TurnStatus } from './session-registry-journal.js';
|
|
3
4
|
export type { TurnStatus };
|
|
4
5
|
/** The ledger's turn IS the registry's turn record — one definition, no drift. */
|
|
@@ -6,9 +7,8 @@ export type LedgerTurn = TurnRecord;
|
|
|
6
7
|
export interface ChannelConversation {
|
|
7
8
|
sessionId: string | null;
|
|
8
9
|
backend: string;
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
profileName: string | null;
|
|
10
|
+
/** Materialized engine choice retained across resume and hook turns. */
|
|
11
|
+
selection: EngineSelection | null;
|
|
12
12
|
turns: LedgerTurn[];
|
|
13
13
|
updatedAt: string;
|
|
14
14
|
}
|
|
@@ -25,7 +25,7 @@ export declare class ConversationLedgerRepo {
|
|
|
25
25
|
initConversation(channel: string, opts: {
|
|
26
26
|
sessionId: string | null;
|
|
27
27
|
backend: string;
|
|
28
|
-
|
|
28
|
+
selection?: EngineSelection | null;
|
|
29
29
|
}): Promise<ChannelConversation>;
|
|
30
30
|
updateSessionId(channel: string, sessionId: string): Promise<void>;
|
|
31
31
|
beginTurn(channel: string, opts: {
|
|
@@ -50,7 +50,7 @@ export declare class ConversationLedgerRepo {
|
|
|
50
50
|
switchSession(channel: string, opts: {
|
|
51
51
|
sessionId: string;
|
|
52
52
|
backend: string;
|
|
53
|
-
|
|
53
|
+
selection?: EngineSelection | null;
|
|
54
54
|
}): Promise<void>;
|
|
55
55
|
/**
|
|
56
56
|
* Atomic init-if-missing + beginTurn. Captures the turn index under one lock
|
|
@@ -60,7 +60,7 @@ export declare class ConversationLedgerRepo {
|
|
|
60
60
|
initAndBeginTurn(channel: string, opts: {
|
|
61
61
|
sessionId: string | null;
|
|
62
62
|
backend: string;
|
|
63
|
-
|
|
63
|
+
selection?: EngineSelection | null;
|
|
64
64
|
userMessageTs: string;
|
|
65
65
|
userMessageText: string;
|
|
66
66
|
statusMessageTs: string;
|
|
@@ -21,7 +21,7 @@ function toChannelConversation(header, turns) {
|
|
|
21
21
|
return {
|
|
22
22
|
sessionId: header.sessionId,
|
|
23
23
|
backend: header.backend,
|
|
24
|
-
|
|
24
|
+
selection: header.selection,
|
|
25
25
|
turns,
|
|
26
26
|
updatedAt: deriveUpdatedAt(header, turns),
|
|
27
27
|
};
|
|
@@ -56,7 +56,7 @@ export class ConversationLedgerRepo {
|
|
|
56
56
|
const header = {
|
|
57
57
|
sessionId: opts.sessionId,
|
|
58
58
|
backend: opts.backend,
|
|
59
|
-
|
|
59
|
+
selection: opts.selection ?? null,
|
|
60
60
|
updatedAt: now,
|
|
61
61
|
};
|
|
62
62
|
await this.registry.batch(async (ops) => {
|
|
@@ -161,7 +161,7 @@ export class ConversationLedgerRepo {
|
|
|
161
161
|
const header = {
|
|
162
162
|
sessionId: opts.sessionId,
|
|
163
163
|
backend: opts.backend,
|
|
164
|
-
|
|
164
|
+
selection: opts.selection ?? null,
|
|
165
165
|
updatedAt: nowIso(),
|
|
166
166
|
};
|
|
167
167
|
await this.registry.batch(async (ops) => {
|
|
@@ -180,7 +180,7 @@ export class ConversationLedgerRepo {
|
|
|
180
180
|
await ops.setConversation(channel, {
|
|
181
181
|
sessionId: opts.sessionId,
|
|
182
182
|
backend: opts.backend,
|
|
183
|
-
|
|
183
|
+
selection: opts.selection ?? null,
|
|
184
184
|
updatedAt: nowIso(),
|
|
185
185
|
});
|
|
186
186
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// $CORTEX_HOME/.gitignore lives at the home root, so a pattern with a slash is anchored there:
|
|
2
|
+
// the shipped `projects/*/…/index.md` rules never matched the memory indexes under context/.
|
|
3
|
+
const MEMORY_INDEX_IGNORES = [
|
|
4
|
+
'context/projects/*/experiments/index.md',
|
|
5
|
+
'context/projects/*/knowledge/index.md',
|
|
6
|
+
'context/projects/*/patterns/index.md',
|
|
7
|
+
];
|
|
8
|
+
/** Append whichever memory-index rules are absent; every existing line is kept as is. */
|
|
9
|
+
export function appendMemoryIndexIgnores(text) {
|
|
10
|
+
const present = new Set(text.split(/\r?\n/).map(line => line.trim()));
|
|
11
|
+
const missing = MEMORY_INDEX_IGNORES.filter(rule => !present.has(rule));
|
|
12
|
+
if (missing.length === 0)
|
|
13
|
+
return text;
|
|
14
|
+
const separator = text.length === 0 || text.endsWith('\n') ? '' : '\n';
|
|
15
|
+
return `${text}${separator}${missing.join('\n')}\n`;
|
|
16
|
+
}
|
|
@@ -13,7 +13,7 @@ export type HookRun = ({
|
|
|
13
13
|
timeout?: number;
|
|
14
14
|
};
|
|
15
15
|
export type HookFilterValue = string | number | boolean | null;
|
|
16
|
-
export type HookResultMode = '
|
|
16
|
+
export type HookResultMode = 'stdout-as-prompt' | 'none';
|
|
17
17
|
export interface HookEntry {
|
|
18
18
|
id: string;
|
|
19
19
|
event: HookEvent;
|
|
@@ -20,14 +20,15 @@ const AGENT_EVENTS = new Set([
|
|
|
20
20
|
'agent:turn-end',
|
|
21
21
|
]);
|
|
22
22
|
const CALVER_RE = /^\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?$/;
|
|
23
|
-
const RESULT_MODES = new Set(['
|
|
23
|
+
const RESULT_MODES = new Set(['stdout-as-prompt', 'none']);
|
|
24
|
+
const RETIRED_RESULT_MODE = 'hook-result';
|
|
24
25
|
export const RESULT_CAPABILITY_BY_EVENT = new Map([
|
|
25
|
-
['cortex:thread.start', 'hook-result'],
|
|
26
|
-
['cortex:thread.transition', 'hook-result'],
|
|
27
|
-
['cortex:thread.end', 'hook-result'],
|
|
28
26
|
['cortex:session.new', 'stdout-as-prompt'],
|
|
29
27
|
['cortex:session.messageEnd', 'stdout-as-prompt'],
|
|
30
28
|
]);
|
|
29
|
+
/** A configuration that was once valid but no longer does anything: skipped with a warning. */
|
|
30
|
+
class RetiredHookConfigError extends Error {
|
|
31
|
+
}
|
|
31
32
|
function asObject(value, field) {
|
|
32
33
|
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
33
34
|
throw new Error(`${field} must be an object`);
|
|
@@ -137,8 +138,11 @@ function validateBlocking(value) {
|
|
|
137
138
|
function validateResult(value, event) {
|
|
138
139
|
if (value === undefined)
|
|
139
140
|
return;
|
|
141
|
+
if (value === RETIRED_RESULT_MODE) {
|
|
142
|
+
throw new RetiredHookConfigError(`result mode "${RETIRED_RESULT_MODE}" is retired; remove the hook or its result field`);
|
|
143
|
+
}
|
|
140
144
|
if (typeof value !== 'string' || !RESULT_MODES.has(value)) {
|
|
141
|
-
throw new Error('result must be
|
|
145
|
+
throw new Error('result must be stdout-as-prompt or none');
|
|
142
146
|
}
|
|
143
147
|
if (value !== 'none' && RESULT_CAPABILITY_BY_EVENT.get(event) !== value) {
|
|
144
148
|
throw new Error(`result mode "${value}" is not permitted for event "${event}"`);
|
|
@@ -166,7 +170,8 @@ export function validateHookEntry(value) {
|
|
|
166
170
|
}
|
|
167
171
|
function reportInvalid(source, error) {
|
|
168
172
|
const message = error instanceof Error ? error.message : String(error);
|
|
169
|
-
console.
|
|
173
|
+
const report = error instanceof RetiredHookConfigError ? console.warn : console.error;
|
|
174
|
+
report(`[hook-registry] skipped ${source}: ${message}`);
|
|
170
175
|
}
|
|
171
176
|
function registryFiles(directory) {
|
|
172
177
|
if (!directory)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AsyncMutex } from '../core/async-mutex.js';
|
|
2
|
+
import type { ModelsFile } from '../domain/agents/engine-selection.js';
|
|
3
|
+
export declare const MODELS_FILE: string;
|
|
4
|
+
export declare const modelsWriteLock: AsyncMutex;
|
|
5
|
+
export declare function getModelsConfigRevision(): number;
|
|
6
|
+
export declare class ModelsRepo {
|
|
7
|
+
private readonly filePath;
|
|
8
|
+
private cache;
|
|
9
|
+
constructor(filePath?: string);
|
|
10
|
+
readSync(): ModelsFile;
|
|
11
|
+
readIfPresent(): ModelsFile | null;
|
|
12
|
+
invalidate(): void;
|
|
13
|
+
/** Parse before replacing the cache: a failed reload keeps the last usable snapshot. */
|
|
14
|
+
reload(): void;
|
|
15
|
+
}
|
|
16
|
+
export declare const modelsRepo: ModelsRepo;
|
|
17
|
+
export declare function setAdminNotifier(fn: (text: string) => void): void;
|
|
18
|
+
export declare function startModelsWatcher(repo?: ModelsRepo, filePath?: string, onReload?: () => void): () => void;
|