@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,58 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'node:stream';
|
|
2
|
+
import type { EngineSpec } from '../types.js';
|
|
3
|
+
export declare const CACHE_REFRESH_PROMPT = "[Cortex cache refresh] Reply with exactly: ok";
|
|
4
|
+
export declare const CACHE_REFRESH_TIMEOUT_MS = 90000;
|
|
5
|
+
export interface CacheRefreshLaunch {
|
|
6
|
+
command: string;
|
|
7
|
+
args: string[];
|
|
8
|
+
env: NodeJS.ProcessEnv;
|
|
9
|
+
cwd: string;
|
|
10
|
+
sessionId: string;
|
|
11
|
+
transcriptPath: string;
|
|
12
|
+
}
|
|
13
|
+
export interface CacheRefreshUsage {
|
|
14
|
+
inputTokens: number;
|
|
15
|
+
outputTokens: number;
|
|
16
|
+
cacheReadTokens: number;
|
|
17
|
+
cacheWriteTokens: number;
|
|
18
|
+
}
|
|
19
|
+
export interface CacheRefreshResult {
|
|
20
|
+
usage: CacheRefreshUsage;
|
|
21
|
+
model: string | null;
|
|
22
|
+
/** This one request: the fork's total minus the history total it restored. */
|
|
23
|
+
costUsd: number;
|
|
24
|
+
durationMs: number;
|
|
25
|
+
}
|
|
26
|
+
/** The slice of a child process the refresh drives; `child_process.spawn` returns one. */
|
|
27
|
+
export interface CacheRefreshChild {
|
|
28
|
+
stdin: Writable | null;
|
|
29
|
+
stdout: Readable | null;
|
|
30
|
+
stderr: Readable | null;
|
|
31
|
+
exitCode: number | null;
|
|
32
|
+
signalCode: NodeJS.Signals | null;
|
|
33
|
+
kill(signal?: NodeJS.Signals): boolean;
|
|
34
|
+
on(event: 'error', listener: (error: Error) => void): this;
|
|
35
|
+
on(event: 'close', listener: (code: number | null) => void): this;
|
|
36
|
+
}
|
|
37
|
+
export type CacheRefreshSpawn = (command: string, args: string[], options: {
|
|
38
|
+
cwd: string;
|
|
39
|
+
env: NodeJS.ProcessEnv;
|
|
40
|
+
}) => CacheRefreshChild;
|
|
41
|
+
export interface CacheRefreshDeps {
|
|
42
|
+
spawn?: CacheRefreshSpawn;
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
now?: () => number;
|
|
45
|
+
}
|
|
46
|
+
/** The launch's session identity (`--session-id X` or `--resume X`) turned into a one-turn fork of
|
|
47
|
+
* X that persists nothing. Throws when the argv does not name X. */
|
|
48
|
+
export declare function forkRefreshArgs(args: readonly string[], sessionId: string): string[];
|
|
49
|
+
/**
|
|
50
|
+
* The fork's command line: the launch the session's next turn would spawn, resumed, without
|
|
51
|
+
* hooks. Hooks run Cortex scripts against the session's identity and add nothing to the cached
|
|
52
|
+
* prefix, which is the system prompt, the tools and the transcript.
|
|
53
|
+
*/
|
|
54
|
+
export declare function cacheRefreshLaunch(spec: EngineSpec): CacheRefreshLaunch;
|
|
55
|
+
/** A resumed fork's `total_cost_usd` carries the session's restored history; this is the rest. */
|
|
56
|
+
export declare function refreshCost(totalCostUsd: unknown, restoredUsd: number): number;
|
|
57
|
+
/** Run one refresh fork to its result. */
|
|
58
|
+
export declare function runCacheRefresh(launch: CacheRefreshLaunch, deps?: CacheRefreshDeps): Promise<CacheRefreshResult>;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createInterface } from 'node:readline';
|
|
3
|
+
import { claudeProcessLaunch, launchFromSpec } from './session-options.js';
|
|
4
|
+
import { computeTranscriptPath, readRestoredSessionCost } from './transcript-path.js';
|
|
5
|
+
// A keep-warm refresh: one request on a fork of an idle session, so the session's one-hour prompt
|
|
6
|
+
// cache is read (which restarts its clock) without the session's own transcript changing. The fork
|
|
7
|
+
// resumes the transcript, sends one short message, persists nothing, and is gone after its result.
|
|
8
|
+
export const CACHE_REFRESH_PROMPT = '[Cortex cache refresh] Reply with exactly: ok';
|
|
9
|
+
export const CACHE_REFRESH_TIMEOUT_MS = 90_000;
|
|
10
|
+
/** How long a fork may take to exit once its stdin closes, before it is killed. */
|
|
11
|
+
const EXIT_GRACE_MS = 10_000;
|
|
12
|
+
const FORK_FLAGS = ['--fork-session', '--no-session-persistence', '--max-turns', '1'];
|
|
13
|
+
/** The launch's session identity (`--session-id X` or `--resume X`) turned into a one-turn fork of
|
|
14
|
+
* X that persists nothing. Throws when the argv does not name X. */
|
|
15
|
+
export function forkRefreshArgs(args, sessionId) {
|
|
16
|
+
const at = args.findIndex((arg, i) => (arg === '--session-id' || arg === '--resume') && args[i + 1] === sessionId);
|
|
17
|
+
if (at === -1)
|
|
18
|
+
throw new Error(`launch does not name session ${sessionId}`);
|
|
19
|
+
return [...args.slice(0, at), '--resume', sessionId, ...FORK_FLAGS, ...args.slice(at + 2)];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The fork's command line: the launch the session's next turn would spawn, resumed, without
|
|
23
|
+
* hooks. Hooks run Cortex scripts against the session's identity and add nothing to the cached
|
|
24
|
+
* prefix, which is the system prompt, the tools and the transcript.
|
|
25
|
+
*/
|
|
26
|
+
export function cacheRefreshLaunch(spec) {
|
|
27
|
+
const sessionId = spec.resume.backendSessionId;
|
|
28
|
+
if (!sessionId)
|
|
29
|
+
throw new Error('cache refresh needs a backend session to resume');
|
|
30
|
+
const launch = launchFromSpec(spec);
|
|
31
|
+
const options = { ...launch.options, disableHooks: true };
|
|
32
|
+
const { args, env } = claudeProcessLaunch({
|
|
33
|
+
channel: launch.channel, sessionId, needsResume: true, options,
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
command: options.cliPath ?? 'claude',
|
|
37
|
+
args: forkRefreshArgs(args, sessionId),
|
|
38
|
+
env,
|
|
39
|
+
cwd: options.cwd,
|
|
40
|
+
sessionId,
|
|
41
|
+
transcriptPath: computeTranscriptPath(options.cwd, sessionId),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** A resumed fork's `total_cost_usd` carries the session's restored history; this is the rest. */
|
|
45
|
+
export function refreshCost(totalCostUsd, restoredUsd) {
|
|
46
|
+
if (typeof totalCostUsd !== 'number' || !Number.isFinite(totalCostUsd))
|
|
47
|
+
return 0;
|
|
48
|
+
return Math.max(0, totalCostUsd - restoredUsd);
|
|
49
|
+
}
|
|
50
|
+
function tokens(value) {
|
|
51
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : 0;
|
|
52
|
+
}
|
|
53
|
+
function usageOf(usage) {
|
|
54
|
+
return {
|
|
55
|
+
inputTokens: tokens(usage?.input_tokens),
|
|
56
|
+
outputTokens: tokens(usage?.output_tokens),
|
|
57
|
+
cacheReadTokens: tokens(usage?.cache_read_input_tokens),
|
|
58
|
+
cacheWriteTokens: tokens(usage?.cache_creation_input_tokens),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function parseRecord(line) {
|
|
62
|
+
try {
|
|
63
|
+
const record = JSON.parse(line);
|
|
64
|
+
return record && typeof record === 'object' ? record : null;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Once the result is in, close stdin so the CLI exits; kill it if it lingers. */
|
|
71
|
+
function release(child) {
|
|
72
|
+
child.stdin?.end();
|
|
73
|
+
const timer = setTimeout(() => {
|
|
74
|
+
if (child.exitCode === null && child.signalCode === null)
|
|
75
|
+
child.kill('SIGKILL');
|
|
76
|
+
}, EXIT_GRACE_MS);
|
|
77
|
+
timer.unref?.();
|
|
78
|
+
child.on('close', () => clearTimeout(timer));
|
|
79
|
+
}
|
|
80
|
+
/** The fork's `result` record and the model that answered, or a rejection on timeout, a spawn
|
|
81
|
+
* error, or an exit before the result. A timeout kills the fork. */
|
|
82
|
+
function readForkResult(child, timeoutMs) {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
let model = null;
|
|
85
|
+
let stderr = '';
|
|
86
|
+
let done = false;
|
|
87
|
+
const finish = (error, result) => {
|
|
88
|
+
if (done)
|
|
89
|
+
return;
|
|
90
|
+
done = true;
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
if (error)
|
|
93
|
+
reject(error);
|
|
94
|
+
else
|
|
95
|
+
resolve({ result: result, model });
|
|
96
|
+
};
|
|
97
|
+
const timer = setTimeout(() => {
|
|
98
|
+
child.kill();
|
|
99
|
+
finish(new Error(`no result within ${timeoutMs}ms`));
|
|
100
|
+
}, timeoutMs);
|
|
101
|
+
createInterface({ input: child.stdout }).on('line', (line) => {
|
|
102
|
+
const record = parseRecord(line);
|
|
103
|
+
if (record?.type === 'assistant')
|
|
104
|
+
model ??= record.message?.model ?? null;
|
|
105
|
+
if (record?.type === 'result')
|
|
106
|
+
finish(null, record);
|
|
107
|
+
});
|
|
108
|
+
child.stderr?.on('data', (data) => { stderr = (stderr + String(data)).slice(-500); });
|
|
109
|
+
child.on('error', (error) => finish(error));
|
|
110
|
+
child.on('close', (code) => finish(new Error(`exited ${code} before a result: ${stderr.trim()}`)));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function checkResult(result) {
|
|
114
|
+
// `--max-turns 1` ends a reply that reached for a tool as an error, but its request still ran.
|
|
115
|
+
if (result.is_error !== true || result.subtype === 'error_max_turns')
|
|
116
|
+
return;
|
|
117
|
+
throw new Error(`refresh failed: ${String(result.result ?? result.subtype).slice(0, 300)}`);
|
|
118
|
+
}
|
|
119
|
+
function writePrompt(child) {
|
|
120
|
+
// A fork that dies at once fails the write with EPIPE; its exit already rejects the refresh.
|
|
121
|
+
child.stdin.on('error', () => { });
|
|
122
|
+
const message = { type: 'user', message: { role: 'user', content: CACHE_REFRESH_PROMPT } };
|
|
123
|
+
child.stdin.write(JSON.stringify(message) + '\n');
|
|
124
|
+
}
|
|
125
|
+
/** Run one refresh fork to its result. */
|
|
126
|
+
export async function runCacheRefresh(launch, deps = {}) {
|
|
127
|
+
const now = deps.now ?? Date.now;
|
|
128
|
+
const restoredUsd = readRestoredSessionCost(launch.transcriptPath, launch.sessionId);
|
|
129
|
+
const started = now();
|
|
130
|
+
const child = (deps.spawn ?? defaultSpawn)(launch.command, launch.args, { cwd: launch.cwd, env: launch.env });
|
|
131
|
+
const output = readForkResult(child, deps.timeoutMs ?? CACHE_REFRESH_TIMEOUT_MS);
|
|
132
|
+
writePrompt(child);
|
|
133
|
+
const { result, model } = await output;
|
|
134
|
+
release(child);
|
|
135
|
+
checkResult(result);
|
|
136
|
+
return {
|
|
137
|
+
usage: usageOf(result.usage),
|
|
138
|
+
model,
|
|
139
|
+
costUsd: refreshCost(result.total_cost_usd, restoredUsd),
|
|
140
|
+
durationMs: now() - started,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function defaultSpawn(command, args, options) {
|
|
144
|
+
return spawn(command, args, { ...options, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
145
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function noteCacheRefresh(backendSessionId: string, at?: number): void;
|
|
2
|
+
/**
|
|
3
|
+
* When the session last talked to the model: the newest timestamped record in its transcript.
|
|
4
|
+
* Not the file's mtime — the CLI appends untimestamped `last-prompt`/`cost-state` entries when its
|
|
5
|
+
* process exits, which for an idle-closed session is an hour after the last request. Falls back to
|
|
6
|
+
* the mtime when the tail holds no timestamped record. Null when the transcript is missing.
|
|
7
|
+
*/
|
|
8
|
+
export declare function lastModelActivity(transcriptPath: string): number | null;
|
|
9
|
+
/** When the session's prompt cache was last read or written: its last model activity or a later
|
|
10
|
+
* keep-warm refresh. Null when neither is known. */
|
|
11
|
+
export declare function lastCacheTouch(transcriptPath: string, backendSessionId: string): number | null;
|
|
12
|
+
export declare function resetCacheTouches(): void;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { closeSync, fstatSync, openSync, readSync } from 'node:fs';
|
|
2
|
+
const TAIL_BYTES = 512 * 1024;
|
|
3
|
+
// A keep-warm refresh reads the cached prefix through a fork that never writes the transcript, so
|
|
4
|
+
// the transcript alone says the cache went cold earlier than it did. In memory only: a restart
|
|
5
|
+
// loses it, and the worst case is one cold-resume clearing that a warm cache did not need.
|
|
6
|
+
const refreshedAt = new Map();
|
|
7
|
+
export function noteCacheRefresh(backendSessionId, at = Date.now()) {
|
|
8
|
+
refreshedAt.set(backendSessionId, at);
|
|
9
|
+
}
|
|
10
|
+
function lastTimestampIn(text) {
|
|
11
|
+
const lines = text.split('\n');
|
|
12
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
13
|
+
const line = lines[i];
|
|
14
|
+
if (!line.includes('"timestamp"'))
|
|
15
|
+
continue;
|
|
16
|
+
try {
|
|
17
|
+
const record = JSON.parse(line);
|
|
18
|
+
if (typeof record.timestamp !== 'string')
|
|
19
|
+
continue;
|
|
20
|
+
// The CLI writes these itself (interrupts, local errors) without calling the model.
|
|
21
|
+
if (record.message?.model === '<synthetic>')
|
|
22
|
+
continue;
|
|
23
|
+
const at = Date.parse(record.timestamp);
|
|
24
|
+
if (Number.isFinite(at))
|
|
25
|
+
return at;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* When the session last talked to the model: the newest timestamped record in its transcript.
|
|
35
|
+
* Not the file's mtime — the CLI appends untimestamped `last-prompt`/`cost-state` entries when its
|
|
36
|
+
* process exits, which for an idle-closed session is an hour after the last request. Falls back to
|
|
37
|
+
* the mtime when the tail holds no timestamped record. Null when the transcript is missing.
|
|
38
|
+
*/
|
|
39
|
+
export function lastModelActivity(transcriptPath) {
|
|
40
|
+
let fd;
|
|
41
|
+
try {
|
|
42
|
+
fd = openSync(transcriptPath, 'r');
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const stat = fstatSync(fd);
|
|
49
|
+
const start = Math.max(0, stat.size - TAIL_BYTES);
|
|
50
|
+
const buf = Buffer.alloc(stat.size - start);
|
|
51
|
+
readSync(fd, buf, 0, buf.length, start);
|
|
52
|
+
let text = buf.toString('utf8');
|
|
53
|
+
if (start > 0)
|
|
54
|
+
text = text.slice(text.indexOf('\n') + 1);
|
|
55
|
+
return lastTimestampIn(text) ?? stat.mtimeMs;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
closeSync(fd);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** When the session's prompt cache was last read or written: its last model activity or a later
|
|
65
|
+
* keep-warm refresh. Null when neither is known. */
|
|
66
|
+
export function lastCacheTouch(transcriptPath, backendSessionId) {
|
|
67
|
+
const activity = lastModelActivity(transcriptPath);
|
|
68
|
+
const refreshed = refreshedAt.get(backendSessionId) ?? null;
|
|
69
|
+
if (activity === null)
|
|
70
|
+
return refreshed;
|
|
71
|
+
return refreshed === null ? activity : Math.max(activity, refreshed);
|
|
72
|
+
}
|
|
73
|
+
export function resetCacheTouches() {
|
|
74
|
+
refreshedAt.clear();
|
|
75
|
+
}
|
|
@@ -14,13 +14,17 @@ export interface StreamDeltaState {
|
|
|
14
14
|
model: string | null;
|
|
15
15
|
/** blockId of the text block currently open, awaiting its complete `assistant` event. */
|
|
16
16
|
textBlockId: string | null;
|
|
17
|
+
/** Independent cursor for complete thinking summaries. */
|
|
18
|
+
thinkingBlockId: string | null;
|
|
17
19
|
}
|
|
18
20
|
export declare function createStreamDeltaState(): StreamDeltaState;
|
|
19
|
-
|
|
20
|
-
export declare function parseStreamEvent(data: any, state: StreamDeltaState): {
|
|
21
|
+
export type StreamDelta = {
|
|
21
22
|
text: string;
|
|
22
23
|
blockId: string;
|
|
23
|
-
|
|
24
|
+
kind?: 'thinking';
|
|
25
|
+
};
|
|
26
|
+
/** Translate a partial stdout event while advancing only its own block cursor. */
|
|
27
|
+
export declare function parseStreamEvent(data: any, state: StreamDeltaState): StreamDelta | null;
|
|
24
28
|
/**
|
|
25
29
|
* Consume the blockId of the streamed text block that the complete `assistant` event now being
|
|
26
30
|
* handled belongs to. Returns null when nothing streamed (kill switch, older CLI, thinking-only
|
|
@@ -30,6 +34,7 @@ export declare function parseStreamEvent(data: any, state: StreamDeltaState): {
|
|
|
30
34
|
* can never re-adopt a stale id.
|
|
31
35
|
*/
|
|
32
36
|
export declare function takeTextBlockId(state: StreamDeltaState): string | null;
|
|
37
|
+
export declare function takeThinkingBlockId(state: StreamDeltaState): string | null;
|
|
33
38
|
export declare function formatAssistantEvent(data: any): string | null;
|
|
34
39
|
export declare function formatUserEvent(data: any): string | null;
|
|
35
40
|
export declare function formatResultEvent(data: any): string;
|
|
@@ -15,23 +15,43 @@ export function parseModelFallbackEvent(raw) {
|
|
|
15
15
|
return { type: 'model_fallback', originalModel, fallbackModel };
|
|
16
16
|
}
|
|
17
17
|
export function createStreamDeltaState() {
|
|
18
|
-
return { messageId: null, model: null, textBlockId: null };
|
|
18
|
+
return { messageId: null, model: null, textBlockId: null, thinkingBlockId: null };
|
|
19
19
|
}
|
|
20
20
|
function observeMessageStart(event, state) {
|
|
21
21
|
state.messageId = typeof event.message?.id === 'string' ? event.message.id : null;
|
|
22
22
|
state.model = typeof event.message?.model === 'string' ? event.message.model : null;
|
|
23
23
|
state.textBlockId = null;
|
|
24
|
+
state.thinkingBlockId = null;
|
|
24
25
|
}
|
|
25
26
|
function observeBlockStart(event, state) {
|
|
26
|
-
if (event.
|
|
27
|
-
return;
|
|
28
|
-
if (typeof event.index !== 'number')
|
|
27
|
+
if (!state.messageId || typeof event.index !== 'number')
|
|
29
28
|
return;
|
|
30
|
-
|
|
29
|
+
const blockId = `${state.messageId}:${event.index}`;
|
|
30
|
+
if (event.content_block?.type === 'text')
|
|
31
|
+
state.textBlockId = blockId;
|
|
32
|
+
if (event.content_block?.type === 'thinking')
|
|
33
|
+
state.thinkingBlockId = blockId;
|
|
31
34
|
}
|
|
32
|
-
|
|
35
|
+
function parseBlockDelta(event, state) {
|
|
36
|
+
const kind = event.delta?.type;
|
|
37
|
+
if (kind !== 'text_delta' && kind !== 'thinking_delta')
|
|
38
|
+
return null;
|
|
39
|
+
const text = kind === 'thinking_delta' ? event.delta.thinking : event.delta.text;
|
|
40
|
+
if (typeof text !== 'string' || text.length === 0)
|
|
41
|
+
return null;
|
|
42
|
+
if (!state.messageId || typeof event.index !== 'number')
|
|
43
|
+
return null;
|
|
44
|
+
const blockId = `${state.messageId}:${event.index}`;
|
|
45
|
+
if (kind === 'thinking_delta') {
|
|
46
|
+
state.thinkingBlockId = blockId;
|
|
47
|
+
return { kind: 'thinking', text, blockId };
|
|
48
|
+
}
|
|
49
|
+
state.textBlockId = blockId;
|
|
50
|
+
return { text, blockId };
|
|
51
|
+
}
|
|
52
|
+
/** Translate a partial stdout event while advancing only its own block cursor. */
|
|
33
53
|
export function parseStreamEvent(data, state) {
|
|
34
|
-
if (!data || data.type !== 'stream_event')
|
|
54
|
+
if (!data || data.type !== 'stream_event' || data.parent_tool_use_id)
|
|
35
55
|
return null;
|
|
36
56
|
const event = data.event;
|
|
37
57
|
if (!event || typeof event.type !== 'string')
|
|
@@ -44,16 +64,7 @@ export function parseStreamEvent(data, state) {
|
|
|
44
64
|
observeBlockStart(event, state);
|
|
45
65
|
return null;
|
|
46
66
|
}
|
|
47
|
-
|
|
48
|
-
return null;
|
|
49
|
-
const text = event.delta.text;
|
|
50
|
-
if (typeof text !== 'string' || text.length === 0)
|
|
51
|
-
return null;
|
|
52
|
-
if (!state.messageId || typeof event.index !== 'number')
|
|
53
|
-
return null;
|
|
54
|
-
const blockId = `${state.messageId}:${event.index}`;
|
|
55
|
-
state.textBlockId = blockId;
|
|
56
|
-
return { text, blockId };
|
|
67
|
+
return event.type === 'content_block_delta' ? parseBlockDelta(event, state) : null;
|
|
57
68
|
}
|
|
58
69
|
/**
|
|
59
70
|
* Consume the blockId of the streamed text block that the complete `assistant` event now being
|
|
@@ -68,6 +79,11 @@ export function takeTextBlockId(state) {
|
|
|
68
79
|
state.textBlockId = null;
|
|
69
80
|
return id;
|
|
70
81
|
}
|
|
82
|
+
export function takeThinkingBlockId(state) {
|
|
83
|
+
const id = state.thinkingBlockId;
|
|
84
|
+
state.thinkingBlockId = null;
|
|
85
|
+
return id;
|
|
86
|
+
}
|
|
71
87
|
export function formatAssistantEvent(data) {
|
|
72
88
|
const parts = [];
|
|
73
89
|
for (const block of (data.message?.content || [])) {
|
|
@@ -22,6 +22,8 @@ export interface ClaudeTurnCallbacks {
|
|
|
22
22
|
onProgress?: ((progress: any) => void) | null;
|
|
23
23
|
onAssistantMessage?: ((text: string, blockId?: string, model?: string | null, subagent?: ToolUseSubagent) => void) | null;
|
|
24
24
|
onAssistantDelta?: ((text: string, blockId: string) => void) | null;
|
|
25
|
+
onAssistantThinking?: ((text: string, blockId?: string) => void) | null;
|
|
26
|
+
onAssistantThinkingDelta?: ((text: string, blockId: string) => void) | null;
|
|
25
27
|
onToolUse?: ((name: string, input: any, toolUseId: string, subagent?: ToolUseSubagent) => void) | null;
|
|
26
28
|
onToolResult?: ((toolUseId: string, content: string, isError: boolean, subagent?: ToolUseSubagent, images?: ToolResultImage[]) => void) | null;
|
|
27
29
|
onCompact?: ((info: {
|
|
@@ -28,6 +28,8 @@ export function claudeTurnCallbacks(push) {
|
|
|
28
28
|
// Token-level preview of the block above. Same FIFO stream, so every delta is delivered
|
|
29
29
|
// before the complete message that supersedes it.
|
|
30
30
|
onAssistantDelta: (text, blockId) => push({ type: 'assistant_delta', text, blockId }),
|
|
31
|
+
onAssistantThinking: (text, blockId) => push({ type: 'assistant_thinking', text, ...(blockId ? { blockId } : {}) }),
|
|
32
|
+
onAssistantThinkingDelta: (text, blockId) => push({ type: 'assistant_thinking_delta', text, blockId }),
|
|
31
33
|
onToolUse: (name, input, toolUseId, subagent) => {
|
|
32
34
|
push({ type: 'tool_use', toolUseId, name, input, ...(subagent ? { subagent } : {}) });
|
|
33
35
|
// Derived semantic event alongside the raw call (cf. plan_written /
|
|
@@ -78,11 +78,22 @@ function writePrivateAtomic(filePath, text) {
|
|
|
78
78
|
fs.renameSync(tmp, filePath);
|
|
79
79
|
fs.chmodSync(filePath, 0o600);
|
|
80
80
|
}
|
|
81
|
+
/** Reuse refreshes the mtime: the plugin-runtime sweep removes only files untouched for a week. */
|
|
82
|
+
function markLive(filePath) {
|
|
83
|
+
try {
|
|
84
|
+
const now = new Date();
|
|
85
|
+
fs.utimesSync(filePath, now, now);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// A failed touch only makes the file eligible for a sweep; the next spawn writes it again.
|
|
89
|
+
}
|
|
90
|
+
}
|
|
81
91
|
function privateContentFile(directory, text, label) {
|
|
82
92
|
ensurePrivateDirectory(directory, label);
|
|
83
93
|
const filePath = path.join(directory, `${sha256(text)}.json`);
|
|
84
94
|
if (fs.existsSync(filePath)) {
|
|
85
95
|
validateExistingFile(filePath, text);
|
|
96
|
+
markLive(filePath);
|
|
86
97
|
return filePath;
|
|
87
98
|
}
|
|
88
99
|
try {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { AgentProcessSpawner, EngineSpec, McpComposition } from '../types.js';
|
|
2
|
-
import { type CortexAgentContext } from './spawn-args.js';
|
|
1
|
+
import type { AgentProcessSpawner, CortexContextEnv, EngineSpec, McpComposition } from '../types.js';
|
|
3
2
|
/** What a Claude session runs with: one EngineSpec, translated once. Every (re)spawn of the
|
|
4
3
|
* session's process reads this same object, and the pool identity is computed from it. */
|
|
5
4
|
export interface ClaudeSessionOptions {
|
|
@@ -16,8 +15,8 @@ export interface ClaudeSessionOptions {
|
|
|
16
15
|
tools?: string | null;
|
|
17
16
|
pluginDirs?: string[] | null;
|
|
18
17
|
anthropicBaseUrl?: string;
|
|
19
|
-
|
|
20
|
-
/** Keys deleted from the child env after
|
|
18
|
+
routeEnv?: Record<string, string>;
|
|
19
|
+
/** Keys deleted from the child env after route environment is applied (EngineSpec.env.unsets). */
|
|
21
20
|
unsetEnv?: string[];
|
|
22
21
|
/** Resolved spawn cwd; also where the transcript lives. */
|
|
23
22
|
cwd: string;
|
|
@@ -26,10 +25,6 @@ export interface ClaudeSessionOptions {
|
|
|
26
25
|
mcpToolAllowlist?: string[];
|
|
27
26
|
supplementalMcpConfigPath?: string | null;
|
|
28
27
|
supplementalMcpConfigIdentity?: string | null;
|
|
29
|
-
/** Playwright MCP config for a browser-enabled session. Kept separate from the supplemental
|
|
30
|
-
* (plugin) config because a session can legitimately have both. */
|
|
31
|
-
browserMcpConfigPath?: string | null;
|
|
32
|
-
browserMcpConfigIdentity?: string | null;
|
|
33
28
|
pluginCapabilityFingerprint?: string | null;
|
|
34
29
|
disableHooks?: boolean;
|
|
35
30
|
/** Drop the CLI's whole skill layer; see {@link ClaudeSpawnOptions.disableSkills}. */
|
|
@@ -43,13 +38,11 @@ export interface ClaudeSessionOptions {
|
|
|
43
38
|
cliPath?: string;
|
|
44
39
|
/** Exact allowlisted child environment for an isolated process. */
|
|
45
40
|
pinnedEnv?: NodeJS.ProcessEnv;
|
|
46
|
-
/**
|
|
47
|
-
extraOption?: Record<string, string>;
|
|
48
|
-
/** Thinking level from the profile's `thinking` field → `--effort <level>`. Absent → no flag. */
|
|
41
|
+
/** Selected thinking level → `--effort <level>`. Absent → no flag. */
|
|
49
42
|
thinking?: string | null;
|
|
50
|
-
/** Cortex execution
|
|
43
|
+
/** Cortex execution identity and engine selection surfaced to the MCP server child as env vars.
|
|
51
44
|
* Captured at spawn time; later turns on the same session reuse the original snapshot. */
|
|
52
|
-
context?:
|
|
45
|
+
context?: CortexContextEnv;
|
|
53
46
|
}
|
|
54
47
|
/** One launch of a session's process: which transcript, whether it resumes, and the options. */
|
|
55
48
|
export interface ClaudeLaunchInput {
|
|
@@ -5,7 +5,6 @@ import { encodeMcpBundles, MCP_BUNDLES_ENV } from '../../core/mcp-bundles.js';
|
|
|
5
5
|
import { resolveMcpComposition } from '../types.js';
|
|
6
6
|
import { buildClaudeEnv, buildSpawnArgs, resolveClaudeMcpBundles, } from './spawn-args.js';
|
|
7
7
|
import { writeClaudeSupplementalMcpConfig } from './mcp-config.js';
|
|
8
|
-
import { writeBrowserMcpConfig } from './browser-mcp.js';
|
|
9
8
|
/** The prompt and model half of the CLI options. An empty string reads as unset. */
|
|
10
9
|
function promptSpawnOptions(options) {
|
|
11
10
|
return {
|
|
@@ -16,7 +15,6 @@ function promptSpawnOptions(options) {
|
|
|
16
15
|
claudeAgent: options.claudeAgent || null,
|
|
17
16
|
pluginDirs: options.pluginDirs || null,
|
|
18
17
|
outputStyle: options.outputStyle || null,
|
|
19
|
-
extraOption: options.extraOption,
|
|
20
18
|
thinking: options.thinking ?? null,
|
|
21
19
|
};
|
|
22
20
|
}
|
|
@@ -27,7 +25,6 @@ function surfaceSpawnOptions(options) {
|
|
|
27
25
|
mcpConfigPaths: options.mcpConfigPaths,
|
|
28
26
|
mcpToolAllowlist: options.mcpToolAllowlist,
|
|
29
27
|
supplementalMcpConfigPath: options.supplementalMcpConfigPath ?? null,
|
|
30
|
-
browserMcpConfigPath: options.browserMcpConfigPath ?? null,
|
|
31
28
|
disableHooks: options.disableHooks === true,
|
|
32
29
|
disableSkills: options.disableSkills === true,
|
|
33
30
|
settingSources: options.settingSources,
|
|
@@ -59,7 +56,7 @@ function claudeSpawnOptions(launch) {
|
|
|
59
56
|
export function claudeProcessLaunch(launch) {
|
|
60
57
|
const spawnOptions = claudeSpawnOptions(launch);
|
|
61
58
|
const { options } = launch;
|
|
62
|
-
const env = buildClaudeEnv(launch.channel, launch.sessionId, options.callbackSource || null, options.scheduleTaskId || null, options.anthropicBaseUrl, options.
|
|
59
|
+
const env = buildClaudeEnv(launch.channel, launch.sessionId, options.callbackSource || null, options.scheduleTaskId || null, options.anthropicBaseUrl, options.routeEnv, options.context, options.pinnedEnv, options.unsetEnv);
|
|
63
60
|
env[MCP_BUNDLES_ENV] = encodeMcpBundles(resolveClaudeMcpBundles(spawnOptions));
|
|
64
61
|
return { args: buildSpawnArgs(spawnOptions), env };
|
|
65
62
|
}
|
|
@@ -108,14 +105,9 @@ function sessionPresentationOptions(spec) {
|
|
|
108
105
|
}
|
|
109
106
|
function sessionRuntimeOptions(spec, composition) {
|
|
110
107
|
const supplemental = supplementalMcpConfig(spec, composition);
|
|
111
|
-
// Browser tools ride on the direct composition only: an agent configured with composition
|
|
112
|
-
// `none` gets no Cortex MCP servers, the browser included.
|
|
113
|
-
const browser = spec.mcp.browserCdpEndpoint && composition === 'direct'
|
|
114
|
-
? writeBrowserMcpConfig(spec.mcp.browserCdpEndpoint)
|
|
115
|
-
: null;
|
|
116
108
|
return {
|
|
117
109
|
anthropicBaseUrl: spec.route.anthropicBaseUrl,
|
|
118
|
-
|
|
110
|
+
routeEnv: spec.env.sets,
|
|
119
111
|
unsetEnv: spec.env.unsets,
|
|
120
112
|
cwd: resolveSpawnCwd(spec.cwd),
|
|
121
113
|
mcpComposition: composition,
|
|
@@ -123,8 +115,6 @@ function sessionRuntimeOptions(spec, composition) {
|
|
|
123
115
|
mcpToolAllowlist: spec.mcp.allowlist,
|
|
124
116
|
supplementalMcpConfigPath: supplemental?.path ?? null,
|
|
125
117
|
supplementalMcpConfigIdentity: supplemental?.identity ?? null,
|
|
126
|
-
browserMcpConfigPath: browser?.path ?? null,
|
|
127
|
-
browserMcpConfigIdentity: browser?.identity ?? null,
|
|
128
118
|
pluginCapabilityFingerprint: spec.plugins.fingerprint ?? null,
|
|
129
119
|
disableHooks: spec.flags.disableHooks,
|
|
130
120
|
disableSkills: spec.flags.disableSkills,
|
|
@@ -134,7 +124,6 @@ function sessionRuntimeOptions(spec, composition) {
|
|
|
134
124
|
processSpawner: spec.process.spawner,
|
|
135
125
|
cliPath: spec.process.cliPath,
|
|
136
126
|
pinnedEnv: spec.env.pinned,
|
|
137
|
-
extraOption: spec.extraOption,
|
|
138
127
|
context: spec.env.context,
|
|
139
128
|
};
|
|
140
129
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { McpBundleName } from '../../core/mcp-bundles.js';
|
|
2
|
-
import type { McpComposition } from '../types.js';
|
|
2
|
+
import type { CortexContextEnv, McpComposition } from '../types.js';
|
|
3
3
|
export interface ClaudeSpawnOptions {
|
|
4
4
|
tools: string | null;
|
|
5
5
|
systemPrompt?: string | null;
|
|
@@ -35,14 +35,9 @@ export interface ClaudeSpawnOptions {
|
|
|
35
35
|
loadFeishuMcp?: boolean;
|
|
36
36
|
/** Select Web tools in the bundled server for Web-originated direct sessions. */
|
|
37
37
|
loadWebMcp?: boolean;
|
|
38
|
-
/**
|
|
39
|
-
* browser tools, which is the default and the reason this is opt-in at all. */
|
|
40
|
-
browserMcpConfigPath?: string | null;
|
|
41
|
-
/** Thinking level from the profile's `thinking` field → `--effort <level>`
|
|
38
|
+
/** Selected thinking level → `--effort <level>`
|
|
42
39
|
* (low/medium/high/xhigh/max). Absent → no flag. */
|
|
43
40
|
thinking?: string | null;
|
|
44
|
-
/** Extra CLI options from profile (e.g. {"--thinking": "xhigh"}). */
|
|
45
|
-
extraOption?: Record<string, string> | null;
|
|
46
41
|
/** True for conversation turns (not subagents or the onNew pre-close turn). Such
|
|
47
42
|
* sessions additionally get the cortex-interaction-bridge MCP tools
|
|
48
43
|
* (cortex_plan_enter/exit, cortex_ask_user) because the native EnterPlanMode/ExitPlanMode/
|
|
@@ -57,23 +52,11 @@ export interface ClaudeSpawnOptions {
|
|
|
57
52
|
export declare function isStreamDeltasEnabled(): boolean;
|
|
58
53
|
export declare function resolveClaudeMcpBundles(options: ClaudeSpawnOptions): McpBundleName[];
|
|
59
54
|
export declare function buildSpawnArgs(options: ClaudeSpawnOptions): string[];
|
|
60
|
-
/** Cortex agent execution context — surfaces as CORTEX_* env vars so MCP tools
|
|
61
|
-
* such as cortex_context can discover the current session/profile/etc.
|
|
62
|
-
* Optional fields are omitted from env when undefined, so child processes see no key
|
|
63
|
-
* rather than an empty string. */
|
|
64
|
-
export interface CortexAgentContext {
|
|
65
|
-
profile?: string | null;
|
|
66
|
-
project?: string | null;
|
|
67
|
-
/** Stable Cortex tracking id (decoupled from the backend session id) → CORTEX_SESSION_ID. */
|
|
68
|
-
trackSessionId?: string | null;
|
|
69
|
-
/** Cortex execution record id, surfaced as CORTEX_EXECUTION_ID to subprocess env. */
|
|
70
|
-
executionId?: string | null;
|
|
71
|
-
}
|
|
72
55
|
/** The three per-spawn channels that decide where a child sends its requests and with which
|
|
73
56
|
* credential: the dedicated base-URL field, the env overrides, and the env deletions. */
|
|
74
57
|
export interface ClaudeRouteInputs {
|
|
75
58
|
anthropicBaseUrl?: string;
|
|
76
|
-
|
|
59
|
+
routeEnv?: Record<string, string>;
|
|
77
60
|
unsetEnv?: string[];
|
|
78
61
|
}
|
|
79
62
|
/** Identity of the route this spawn would take: the endpoint verbatim (not a secret, and worth
|
|
@@ -84,4 +67,4 @@ export declare function claudeRouteIdentity(route: ClaudeRouteInputs): string;
|
|
|
84
67
|
/** The provider/model catalogs the MCP sidecar offers subagents, read from the daemon's caches.
|
|
85
68
|
* Shared by Claude spawns and the injected PI session snapshot getter. */
|
|
86
69
|
export declare function subagentModelEnv(): Record<string, string>;
|
|
87
|
-
export declare function buildClaudeEnv(channel: string, sessionId: string, callbackSource?: string | null, scheduleTaskId?: string | null, anthropicBaseUrl?: string,
|
|
70
|
+
export declare function buildClaudeEnv(channel: string, sessionId: string, callbackSource?: string | null, scheduleTaskId?: string | null, anthropicBaseUrl?: string, routeEnv?: Record<string, string>, context?: CortexContextEnv, pinnedEnv?: NodeJS.ProcessEnv, unsetEnv?: string[]): NodeJS.ProcessEnv;
|