@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,13 @@
|
|
|
1
|
+
import { type PathRegistrar } from './registrar.js';
|
|
2
|
+
export declare const USER_PATH_TARGET = "HKCU\\Environment\\Path";
|
|
3
|
+
/** Prepend `dir` unless an equivalent entry exists; `null` means the value is absent. */
|
|
4
|
+
export declare function addUserPathEntry(raw: string | null, dir: string): string;
|
|
5
|
+
/** Drop `dir`, leaving every other byte of the value as it was. */
|
|
6
|
+
export declare function removeUserPathEntry(raw: string | null, dir: string): string | null;
|
|
7
|
+
/** Null when the user Path value does not exist. */
|
|
8
|
+
export declare function readUserPath(): string | null;
|
|
9
|
+
export declare function writeUserPath(value: string | null): void;
|
|
10
|
+
export declare function windowsRegistrar(io?: {
|
|
11
|
+
read: typeof readUserPath;
|
|
12
|
+
write: typeof writeUserPath;
|
|
13
|
+
}): PathRegistrar;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { spawnSync } from 'child_process';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { isChanged } from './registrar.js';
|
|
4
|
+
export const USER_PATH_TARGET = 'HKCU\\Environment\\Path';
|
|
5
|
+
const entryKey = (entry) => path.win32.normalize(entry.trim()).replace(/\\+$/, '').toLowerCase();
|
|
6
|
+
const matches = (entry, dir) => entry.trim() !== '' && entryKey(entry) === entryKey(dir);
|
|
7
|
+
/** Prepend `dir` unless an equivalent entry exists; `null` means the value is absent. */
|
|
8
|
+
export function addUserPathEntry(raw, dir) {
|
|
9
|
+
if (!raw)
|
|
10
|
+
return dir;
|
|
11
|
+
if (raw.split(';').some((entry) => matches(entry, dir)))
|
|
12
|
+
return raw;
|
|
13
|
+
return `${dir};${raw}`;
|
|
14
|
+
}
|
|
15
|
+
/** Drop `dir`, leaving every other byte of the value as it was. */
|
|
16
|
+
export function removeUserPathEntry(raw, dir) {
|
|
17
|
+
if (raw === null)
|
|
18
|
+
return null;
|
|
19
|
+
const entries = raw.split(';');
|
|
20
|
+
const kept = entries.filter((entry) => !matches(entry, dir));
|
|
21
|
+
return kept.length === entries.length ? raw : kept.join(';');
|
|
22
|
+
}
|
|
23
|
+
// Read and write the raw (unexpanded) value and keep its registry kind, so `%USERPROFILE%`-style
|
|
24
|
+
// entries survive; then broadcast WM_SETTINGCHANGE so new terminals pick the change up.
|
|
25
|
+
const READ_SCRIPT = `
|
|
26
|
+
[Console]::OutputEncoding = [Text.Encoding]::UTF8
|
|
27
|
+
$k = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment')
|
|
28
|
+
if ($k -and ($k.GetValueNames() -contains 'Path')) { [Console]::Out.Write('=' + $k.GetValue('Path', '', 'DoNotExpandEnvironmentNames')) }`;
|
|
29
|
+
const WRITE_SCRIPT = `
|
|
30
|
+
$k = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Environment')
|
|
31
|
+
$kind = [Microsoft.Win32.RegistryValueKind]::ExpandString
|
|
32
|
+
if ($k.GetValueNames() -contains 'Path') { $kind = $k.GetValueKind('Path') }
|
|
33
|
+
if ($env:CORTEX_USER_PATH) { $k.SetValue('Path', $env:CORTEX_USER_PATH, $kind) } else { $k.DeleteValue('Path', $false) }
|
|
34
|
+
Add-Type -Namespace CortexEnv -Name Native -MemberDefinition '[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr SendMessageTimeout(IntPtr h, uint m, UIntPtr w, string l, uint f, uint t, out UIntPtr r);'
|
|
35
|
+
$r = [UIntPtr]::Zero
|
|
36
|
+
[void][CortexEnv.Native]::SendMessageTimeout([IntPtr]0xffff, 0x1A, [UIntPtr]::Zero, 'Environment', 2, 5000, [ref]$r)`;
|
|
37
|
+
function powershell(script, extraEnv = {}) {
|
|
38
|
+
const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', script], {
|
|
39
|
+
encoding: 'utf8',
|
|
40
|
+
windowsHide: true,
|
|
41
|
+
env: { ...process.env, ...extraEnv },
|
|
42
|
+
});
|
|
43
|
+
if (result.status !== 0)
|
|
44
|
+
throw new Error(`powershell failed: ${(result.stderr || String(result.error ?? '')).trim()}`);
|
|
45
|
+
return result.stdout;
|
|
46
|
+
}
|
|
47
|
+
/** Null when the user Path value does not exist. */
|
|
48
|
+
export function readUserPath() {
|
|
49
|
+
const out = powershell(READ_SCRIPT);
|
|
50
|
+
return out.startsWith('=') ? out.slice(1) : null;
|
|
51
|
+
}
|
|
52
|
+
export function writeUserPath(value) {
|
|
53
|
+
powershell(WRITE_SCRIPT, { CORTEX_USER_PATH: value ?? '' });
|
|
54
|
+
}
|
|
55
|
+
export function windowsRegistrar(io = { read: readUserPath, write: writeUserPath }) {
|
|
56
|
+
return {
|
|
57
|
+
plan: (dir, mode) => {
|
|
58
|
+
const before = io.read();
|
|
59
|
+
const after = mode === 'add' ? addUserPathEntry(before, dir) : removeUserPathEntry(before, dir);
|
|
60
|
+
return [{ target: USER_PATH_TARGET, before, after }];
|
|
61
|
+
},
|
|
62
|
+
apply: (changes) => {
|
|
63
|
+
for (const change of changes.filter(isChanged))
|
|
64
|
+
io.write(change.after);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { countFeature, recordUiMutation } from './usage.js';
|
|
2
|
+
/** Fold the event bus's feature signals into the daily rollup. Returns the unsubscribe. */
|
|
3
|
+
export function subscribeTelemetryToBus(bus) {
|
|
4
|
+
const unsubscribers = [
|
|
5
|
+
bus.subscribe('ui.mutate-invoked', (event) => recordUiMutation(event.op, event.result?.ok === true, event.client)),
|
|
6
|
+
bus.subscribe('plan.submitted', (event) => { if (!event.dryRun)
|
|
7
|
+
countFeature('plan_submitted'); }),
|
|
8
|
+
bus.subscribe('ask-user.requested', (event) => { if (!event.dryRun)
|
|
9
|
+
countFeature('ask_user_asked'); }),
|
|
10
|
+
bus.subscribe('ask-user.answered', () => countFeature('ask_user_answered')),
|
|
11
|
+
bus.subscribe('session.interaction', (event) => {
|
|
12
|
+
if (event.kind !== 'plan-approval')
|
|
13
|
+
return;
|
|
14
|
+
if (event.status === 'approved')
|
|
15
|
+
countFeature('plan_approved');
|
|
16
|
+
if (event.status === 'rejected')
|
|
17
|
+
countFeature('plan_rejected');
|
|
18
|
+
}),
|
|
19
|
+
];
|
|
20
|
+
return () => { for (const subscription of unsubscribers)
|
|
21
|
+
subscription.unsubscribe(); };
|
|
22
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The daemon hands the next app process the facts of the previous one's unexpected exit. */
|
|
2
|
+
export declare const CHILD_EXIT_ENV = "CORTEX_CHILD_EXIT";
|
|
3
|
+
export interface ChildExitInfo {
|
|
4
|
+
code: number | null;
|
|
5
|
+
signal: string | null;
|
|
6
|
+
uptimeMs: number;
|
|
7
|
+
backoffMs: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function encodeChildExit(info: ChildExitInfo): string;
|
|
10
|
+
/** At boot: report the crash the daemon recovered from, if any. */
|
|
11
|
+
export declare function captureChildExitFromEnv(env?: NodeJS.ProcessEnv): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { captureCrash } from './crash.js';
|
|
2
|
+
/** The daemon hands the next app process the facts of the previous one's unexpected exit. */
|
|
3
|
+
export const CHILD_EXIT_ENV = 'CORTEX_CHILD_EXIT';
|
|
4
|
+
export function encodeChildExit(info) {
|
|
5
|
+
return JSON.stringify(info);
|
|
6
|
+
}
|
|
7
|
+
function decode(raw) {
|
|
8
|
+
if (!raw)
|
|
9
|
+
return null;
|
|
10
|
+
try {
|
|
11
|
+
const value = JSON.parse(raw);
|
|
12
|
+
if (typeof value.uptimeMs !== 'number' || typeof value.backoffMs !== 'number')
|
|
13
|
+
return null;
|
|
14
|
+
const code = Number.isInteger(value.code) ? value.code : null;
|
|
15
|
+
const signal = typeof value.signal === 'string' ? value.signal.slice(0, 20) : null;
|
|
16
|
+
return { code, signal, uptimeMs: Math.max(0, value.uptimeMs), backoffMs: Math.max(0, Math.round(value.backoffMs)) };
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** At boot: report the crash the daemon recovered from, if any. */
|
|
23
|
+
export function captureChildExitFromEnv(env = process.env) {
|
|
24
|
+
const info = decode(env[CHILD_EXIT_ENV]);
|
|
25
|
+
if (!info)
|
|
26
|
+
return;
|
|
27
|
+
captureCrash({
|
|
28
|
+
component: 'server',
|
|
29
|
+
kind: 'childExit',
|
|
30
|
+
errorName: 'ChildExit',
|
|
31
|
+
message: info.signal ? `signal ${info.signal}` : `exit code ${info.code ?? 'unknown'}`,
|
|
32
|
+
stack: '',
|
|
33
|
+
uptimeS: Math.round(info.uptimeMs / 1000),
|
|
34
|
+
exit: { code: info.code, signal: info.signal, backoffMs: info.backoffMs },
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CLIENT_KINDS } from './schema.js';
|
|
2
|
+
export type ClientKind = (typeof CLIENT_KINDS)[number];
|
|
3
|
+
/** The `x-cortex-client` request header, or null when absent or unrecognized. */
|
|
4
|
+
export declare function parseClientKind(header: string | string[] | undefined): ClientKind | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CLIENT_KINDS } from './schema.js';
|
|
2
|
+
/** The `x-cortex-client` request header, or null when absent or unrecognized. */
|
|
3
|
+
export function parseClientKind(header) {
|
|
4
|
+
const raw = Array.isArray(header) ? header[0] : header;
|
|
5
|
+
const value = raw?.trim().toLowerCase();
|
|
6
|
+
return CLIENT_KINDS.includes(value ?? '') ? value : null;
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const CRASH_GROUP_INTERVAL_MS: number;
|
|
2
|
+
export declare const CRASH_DAILY_LIMIT = 20;
|
|
3
|
+
export declare const CRASH_LIMITS_FILE: string;
|
|
4
|
+
export interface CrashAdmission {
|
|
5
|
+
send: boolean;
|
|
6
|
+
/** Same-group crashes held back since the last one sent (reported on this one). */
|
|
7
|
+
suppressed: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* One crash per group per hour, twenty per install per UTC day. Held-back crashes are only
|
|
11
|
+
* counted, and the count rides on the next crash of that group that goes out. Synchronous: the
|
|
12
|
+
* caller may be a process about to exit.
|
|
13
|
+
*/
|
|
14
|
+
export declare function admitCrash(groupKey: string, now?: number, file?: string): CrashAdmission;
|
|
15
|
+
export declare function wipeCrashLimits(file?: string): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { TELEMETRY_DIR } from './paths.js';
|
|
4
|
+
export const CRASH_GROUP_INTERVAL_MS = 60 * 60 * 1000;
|
|
5
|
+
export const CRASH_DAILY_LIMIT = 20;
|
|
6
|
+
export const CRASH_LIMITS_FILE = path.join(TELEMETRY_DIR, 'crash-limits.json');
|
|
7
|
+
function read(file, day) {
|
|
8
|
+
try {
|
|
9
|
+
const state = JSON.parse(readFileSync(file, 'utf8'));
|
|
10
|
+
if (state.day === day && state.groups && typeof state.sentToday === 'number')
|
|
11
|
+
return state;
|
|
12
|
+
return { day, sentToday: 0, groups: state.groups ?? {} };
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return { day, sentToday: 0, groups: {} };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function write(file, state, now) {
|
|
19
|
+
for (const [key, group] of Object.entries(state.groups)) {
|
|
20
|
+
if (now - group.lastSentAt > 24 * CRASH_GROUP_INTERVAL_MS && group.suppressed === 0)
|
|
21
|
+
delete state.groups[key];
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
25
|
+
writeFileSync(file, JSON.stringify(state), 'utf8');
|
|
26
|
+
}
|
|
27
|
+
catch { /* an unwritable home only loses the limiter */ }
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* One crash per group per hour, twenty per install per UTC day. Held-back crashes are only
|
|
31
|
+
* counted, and the count rides on the next crash of that group that goes out. Synchronous: the
|
|
32
|
+
* caller may be a process about to exit.
|
|
33
|
+
*/
|
|
34
|
+
export function admitCrash(groupKey, now = Date.now(), file = CRASH_LIMITS_FILE) {
|
|
35
|
+
const state = read(file, new Date(now).toISOString().slice(0, 10));
|
|
36
|
+
const group = state.groups[groupKey] ?? { lastSentAt: 0, suppressed: 0 };
|
|
37
|
+
const tooSoon = now - group.lastSentAt < CRASH_GROUP_INTERVAL_MS;
|
|
38
|
+
if (tooSoon || state.sentToday >= CRASH_DAILY_LIMIT) {
|
|
39
|
+
state.groups[groupKey] = { ...group, suppressed: group.suppressed + 1 };
|
|
40
|
+
write(file, state, now);
|
|
41
|
+
return { send: false, suppressed: group.suppressed + 1 };
|
|
42
|
+
}
|
|
43
|
+
state.groups[groupKey] = { lastSentAt: now, suppressed: 0 };
|
|
44
|
+
state.sentToday += 1;
|
|
45
|
+
write(file, state, now);
|
|
46
|
+
return { send: true, suppressed: group.suppressed };
|
|
47
|
+
}
|
|
48
|
+
export function wipeCrashLimits(file = CRASH_LIMITS_FILE) {
|
|
49
|
+
rmSync(file, { force: true });
|
|
50
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ClientKind } from './client-kind.js';
|
|
2
|
+
import type { CrashEvent } from './schema.js';
|
|
3
|
+
export interface CrashInput {
|
|
4
|
+
component: CrashEvent['component'];
|
|
5
|
+
kind: CrashEvent['kind'];
|
|
6
|
+
errorName: string;
|
|
7
|
+
message: string;
|
|
8
|
+
stack: string;
|
|
9
|
+
uptimeS?: number | null;
|
|
10
|
+
route?: string | null;
|
|
11
|
+
buildStamp?: string | null;
|
|
12
|
+
client?: ClientKind | null;
|
|
13
|
+
exit?: CrashEvent['exit'];
|
|
14
|
+
at?: Date;
|
|
15
|
+
}
|
|
16
|
+
/** Name, message and stack of whatever was thrown, before redaction. */
|
|
17
|
+
export declare function describeThrown(error: unknown): Pick<CrashInput, 'errorName' | 'message' | 'stack'>;
|
|
18
|
+
/** Redact and shape a crash; the group key comes from the redacted stack. */
|
|
19
|
+
export declare function buildCrashEvent(input: CrashInput, suppressed?: number): CrashEvent;
|
|
20
|
+
/**
|
|
21
|
+
* Record a crash: rate-limited, appended synchronously, uploaded within seconds when the
|
|
22
|
+
* service runs in this process. Never throws.
|
|
23
|
+
*/
|
|
24
|
+
export declare function captureCrash(input: CrashInput): void;
|
|
25
|
+
export declare function captureProcessCrash(component: 'server' | 'daemon', kind: 'uncaughtException' | 'unhandledRejection', error: unknown): void;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isTelemetryActive } from './gate.js';
|
|
2
|
+
import { admitCrash, wipeCrashLimits } from './crash-limits.js';
|
|
3
|
+
import { panicGroupKey } from './panic-group.js';
|
|
4
|
+
import { groupKeyOf, redactMessage, redactStack } from './redact.js';
|
|
5
|
+
import { recordTelemetryEvent, registerTelemetryHooks } from './service.js';
|
|
6
|
+
registerTelemetryHooks({ wipe: () => wipeCrashLimits() });
|
|
7
|
+
function errorNameOf(error) {
|
|
8
|
+
if (error instanceof Error)
|
|
9
|
+
return error.name || error.constructor?.name || 'Error';
|
|
10
|
+
return typeof error === 'object' && error !== null ? 'NonErrorObject' : `Non${typeof error}`;
|
|
11
|
+
}
|
|
12
|
+
/** Name, message and stack of whatever was thrown, before redaction. */
|
|
13
|
+
export function describeThrown(error) {
|
|
14
|
+
if (error instanceof Error) {
|
|
15
|
+
return { errorName: errorNameOf(error), message: error.message ?? '', stack: error.stack ?? '' };
|
|
16
|
+
}
|
|
17
|
+
return { errorName: errorNameOf(error), message: '', stack: '' };
|
|
18
|
+
}
|
|
19
|
+
/** Redact and shape a crash; the group key comes from the redacted stack. */
|
|
20
|
+
export function buildCrashEvent(input, suppressed = 0) {
|
|
21
|
+
const errorName = redactMessage(input.errorName).slice(0, 80) || 'Error';
|
|
22
|
+
const stack = redactStack(input.stack);
|
|
23
|
+
return {
|
|
24
|
+
type: 'crash',
|
|
25
|
+
at: (input.at ?? new Date()).toISOString(),
|
|
26
|
+
component: input.component,
|
|
27
|
+
kind: input.kind,
|
|
28
|
+
errorName,
|
|
29
|
+
message: redactMessage(input.message),
|
|
30
|
+
stack,
|
|
31
|
+
groupKey: groupKeyFor(input, errorName, stack),
|
|
32
|
+
uptimeS: input.uptimeS ?? null,
|
|
33
|
+
route: input.route?.slice(0, 80) ?? null,
|
|
34
|
+
buildStamp: input.buildStamp?.slice(0, 60) ?? null,
|
|
35
|
+
client: input.client ?? null,
|
|
36
|
+
exit: input.exit ?? null,
|
|
37
|
+
suppressed,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function childExitGroup(exit) {
|
|
41
|
+
return exit?.signal ? `ChildExit@${exit.signal}` : `ChildExit@code:${exit?.code ?? 'unknown'}`;
|
|
42
|
+
}
|
|
43
|
+
/** Child exits group by signal or code, native panics by their location (read from the unredacted
|
|
44
|
+
* report, then reduced to a source-relative file), everything else by its first own stack frame. */
|
|
45
|
+
function groupKeyFor(input, errorName, redactedStack) {
|
|
46
|
+
if (input.kind === 'childExit')
|
|
47
|
+
return childExitGroup(input.exit);
|
|
48
|
+
if (input.kind === 'panic')
|
|
49
|
+
return panicGroupKey(input.message, input.stack);
|
|
50
|
+
return groupKeyOf(errorName, redactedStack);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Record a crash: rate-limited, appended synchronously, uploaded within seconds when the
|
|
54
|
+
* service runs in this process. Never throws.
|
|
55
|
+
*/
|
|
56
|
+
export function captureCrash(input) {
|
|
57
|
+
try {
|
|
58
|
+
if (!isTelemetryActive())
|
|
59
|
+
return;
|
|
60
|
+
const draft = buildCrashEvent(input);
|
|
61
|
+
const admission = admitCrash(draft.groupKey);
|
|
62
|
+
if (!admission.send)
|
|
63
|
+
return;
|
|
64
|
+
recordTelemetryEvent({ ...draft, suppressed: admission.suppressed }, { urgent: true });
|
|
65
|
+
}
|
|
66
|
+
catch { /* crash reporting must never add a crash */ }
|
|
67
|
+
}
|
|
68
|
+
export function captureProcessCrash(component, kind, error) {
|
|
69
|
+
captureCrash({ component, kind, ...describeThrown(error), uptimeS: Math.round(process.uptime()) });
|
|
70
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { loadNameCatalog } from './normalize.js';
|
|
2
|
+
/** Queue every finished day as a `daily` event, then forget it locally. */
|
|
3
|
+
export declare function queueFinishedDays(now: number, loadCatalog?: typeof loadNameCatalog): Promise<void>;
|
|
4
|
+
/** Hook the rollup store into the service's persist / finalize / wipe moments. */
|
|
5
|
+
export declare function installDailyUpload(): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { toDailyEvent } from './daily.js';
|
|
2
|
+
import { loadNameCatalog } from './normalize.js';
|
|
3
|
+
import { dropRollupDay, finishedRollups, persistRollup, utcDay, wipeRollups } from './rollup.js';
|
|
4
|
+
import { recordTelemetryEvent, registerTelemetryHooks } from './service.js';
|
|
5
|
+
/** Queue every finished day as a `daily` event, then forget it locally. */
|
|
6
|
+
export async function queueFinishedDays(now, loadCatalog = loadNameCatalog) {
|
|
7
|
+
const days = finishedRollups(now);
|
|
8
|
+
if (days.length === 0)
|
|
9
|
+
return;
|
|
10
|
+
const catalog = await loadCatalog(utcDay(now));
|
|
11
|
+
for (const rollup of days) {
|
|
12
|
+
const event = toDailyEvent(rollup, catalog);
|
|
13
|
+
if (!event || recordTelemetryEvent(event))
|
|
14
|
+
dropRollupDay(rollup.day);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Hook the rollup store into the service's persist / finalize / wipe moments. */
|
|
18
|
+
export function installDailyUpload() {
|
|
19
|
+
registerTelemetryHooks({ persist: persistRollup, finalize: (now) => queueFinishedDays(now), wipe: wipeRollups });
|
|
20
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type NameCatalog } from './normalize.js';
|
|
2
|
+
import type { RawRollup } from './rollup-types.js';
|
|
3
|
+
import { type DailyEvent } from './schema.js';
|
|
4
|
+
/** One finished day as an upload, or null when it does not fit the wire schema. */
|
|
5
|
+
export declare function toDailyEvent(rollup: RawRollup, catalog: NameCatalog): DailyEvent | null;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { normalizeModel, normalizeProvider, normalizeTool, toIdent } from './normalize.js';
|
|
2
|
+
import { emptyTurnRow } from './rollup-types.js';
|
|
3
|
+
import { bucketIndex, DailyEventSchema, emptyHistogram, FEATURE_COUNTERS, MESSAGE_CHANNELS, } from './schema.js';
|
|
4
|
+
function addInto(target, source) {
|
|
5
|
+
source.forEach((value, index) => { target[index] = (target[index] ?? 0) + value; });
|
|
6
|
+
}
|
|
7
|
+
function sumRecord(target, source) {
|
|
8
|
+
for (const [key, value] of Object.entries(source))
|
|
9
|
+
target[key] = (target[key] ?? 0) + value;
|
|
10
|
+
}
|
|
11
|
+
function mergeTurnRow(target, row) {
|
|
12
|
+
sumRecord(target.outcomes, row.outcomes);
|
|
13
|
+
sumRecord(target.failures, row.failures);
|
|
14
|
+
sumRecord(target.compactions, row.compactions);
|
|
15
|
+
sumRecord(target.tokens, row.tokens);
|
|
16
|
+
target.retries += row.retries;
|
|
17
|
+
target.fallbacks += row.fallbacks;
|
|
18
|
+
addInto(target.ttftMs, row.ttftMs);
|
|
19
|
+
addInto(target.durationS, row.durationS);
|
|
20
|
+
addInto(target.contextPctAtEnd, row.contextPctAtEnd);
|
|
21
|
+
}
|
|
22
|
+
/** Normalize each row's provider/model, merging rows that collapse onto the same name. */
|
|
23
|
+
function turnRows(rollup, catalog) {
|
|
24
|
+
const merged = new Map();
|
|
25
|
+
for (const row of Object.values(rollup.turns)) {
|
|
26
|
+
const { provider, customApi } = normalizeProvider(row.backend, row.provider, catalog);
|
|
27
|
+
const model = normalizeModel(row.backend, row.provider, row.model, catalog);
|
|
28
|
+
const key = [row.backend, provider, model, row.billing, customApi].join('|');
|
|
29
|
+
if (!merged.has(key))
|
|
30
|
+
merged.set(key, { ...emptyTurnRow(row.backend, provider, model, row.billing), customApi });
|
|
31
|
+
mergeTurnRow(merged.get(key), row);
|
|
32
|
+
}
|
|
33
|
+
return [...merged.values()].sort((a, b) => total(b) - total(a)).slice(0, 100);
|
|
34
|
+
}
|
|
35
|
+
function total(row) {
|
|
36
|
+
return row.outcomes.completed + row.outcomes.failed + row.outcomes.cancelled + row.outcomes.rateLimited;
|
|
37
|
+
}
|
|
38
|
+
function tools(rollup) {
|
|
39
|
+
const merged = new Map();
|
|
40
|
+
for (const [name, counts] of Object.entries(rollup.tools)) {
|
|
41
|
+
const key = normalizeTool(name);
|
|
42
|
+
const entry = merged.get(key) ?? { calls: 0, errors: 0 };
|
|
43
|
+
merged.set(key, { calls: entry.calls + counts.calls, errors: entry.errors + counts.errors });
|
|
44
|
+
}
|
|
45
|
+
return [...merged].map(([name, counts]) => ({ name, ...counts }))
|
|
46
|
+
.sort((a, b) => b.calls - a.calls).slice(0, 200);
|
|
47
|
+
}
|
|
48
|
+
function pick(source, keys) {
|
|
49
|
+
return Object.fromEntries(keys.filter((key) => source[key] > 0).map((key) => [key, source[key]]));
|
|
50
|
+
}
|
|
51
|
+
function identRecord(source) {
|
|
52
|
+
const out = {};
|
|
53
|
+
for (const [key, value] of Object.entries(source))
|
|
54
|
+
out[toIdent(key)] = (out[toIdent(key)] ?? 0) + value;
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
function turnsPerSession(sessionTurns) {
|
|
58
|
+
const histogram = emptyHistogram('turnsPerSession');
|
|
59
|
+
for (const turns of Object.values(sessionTurns))
|
|
60
|
+
histogram[bucketIndex('turnsPerSession', turns)] += 1;
|
|
61
|
+
return histogram;
|
|
62
|
+
}
|
|
63
|
+
function median(values) {
|
|
64
|
+
if (values.length === 0)
|
|
65
|
+
return 0;
|
|
66
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
67
|
+
return sorted[Math.floor(sorted.length / 2)];
|
|
68
|
+
}
|
|
69
|
+
function perf(rollup) {
|
|
70
|
+
const loop = rollup.perf.eventLoopP99s;
|
|
71
|
+
return {
|
|
72
|
+
startups: rollup.perf.startups.slice(-10).map(identRecord),
|
|
73
|
+
eventLoop: { windows: loop.length, p99MedianMs: median(loop), p99MaxMs: loop.length ? Math.max(...loop) : 0 },
|
|
74
|
+
web: rollup.perf.web,
|
|
75
|
+
sseReconnects: rollup.perf.sseReconnects,
|
|
76
|
+
remoteClientDisconnects: rollup.perf.remoteClientDisconnects,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** One finished day as an upload, or null when it does not fit the wire schema. */
|
|
80
|
+
export function toDailyEvent(rollup, catalog) {
|
|
81
|
+
const event = {
|
|
82
|
+
type: 'daily',
|
|
83
|
+
day: rollup.day,
|
|
84
|
+
turns: turnRows(rollup, catalog),
|
|
85
|
+
features: pick(rollup.features, FEATURE_COUNTERS),
|
|
86
|
+
messagesByChannel: pick(rollup.messagesByChannel, MESSAGE_CHANNELS),
|
|
87
|
+
uiOps: identRecord(rollup.uiOps),
|
|
88
|
+
tools: tools(rollup),
|
|
89
|
+
agent: {
|
|
90
|
+
userInterrupts: rollup.agent.userInterrupts,
|
|
91
|
+
superseded: rollup.agent.superseded,
|
|
92
|
+
turnsPerSession: turnsPerSession(rollup.agent.sessionTurns),
|
|
93
|
+
workers: rollup.agent.workers,
|
|
94
|
+
subagents: rollup.agent.subagents,
|
|
95
|
+
},
|
|
96
|
+
perf: perf(rollup),
|
|
97
|
+
errors: {
|
|
98
|
+
byModule: identRecord(rollup.errors.byModule),
|
|
99
|
+
samples: rollup.errors.samples.slice(0, 5).map((sample) => ({ ...sample, module: toIdent(sample.module) })),
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
const parsed = DailyEventSchema.safeParse(event);
|
|
103
|
+
return parsed.success ? parsed.data : null;
|
|
104
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Release CI writes this next to the compiled server; source builds have none. */
|
|
2
|
+
export declare const BUILD_INFO_FILE: string;
|
|
3
|
+
/**
|
|
4
|
+
* Where batches go: `CORTEX_TELEMETRY_ENDPOINT` (tests, self-hosted sinks), else the endpoint
|
|
5
|
+
* the release build recorded. Null means nothing is ever sent.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveTelemetryEndpoint(env?: NodeJS.ProcessEnv, buildInfoFile?: string): string | null;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { INSTALL_ROOT } from '../../core/paths.js';
|
|
4
|
+
/** Release CI writes this next to the compiled server; source builds have none. */
|
|
5
|
+
export const BUILD_INFO_FILE = path.join(INSTALL_ROOT, 'dist', 'build-info.json');
|
|
6
|
+
let cachedBuildEndpoint;
|
|
7
|
+
function validEndpoint(raw) {
|
|
8
|
+
if (typeof raw !== 'string' || raw.trim() === '')
|
|
9
|
+
return null;
|
|
10
|
+
try {
|
|
11
|
+
const url = new URL(raw.trim());
|
|
12
|
+
return url.protocol === 'https:' || url.protocol === 'http:' ? url.toString() : null;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function readBuildEndpoint(file) {
|
|
19
|
+
try {
|
|
20
|
+
const info = JSON.parse(readFileSync(file, 'utf8'));
|
|
21
|
+
return validEndpoint(info.telemetryEndpoint);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Where batches go: `CORTEX_TELEMETRY_ENDPOINT` (tests, self-hosted sinks), else the endpoint
|
|
29
|
+
* the release build recorded. Null means nothing is ever sent.
|
|
30
|
+
*/
|
|
31
|
+
export function resolveTelemetryEndpoint(env = process.env, buildInfoFile = BUILD_INFO_FILE) {
|
|
32
|
+
const override = validEndpoint(env.CORTEX_TELEMETRY_ENDPOINT);
|
|
33
|
+
if (override)
|
|
34
|
+
return override;
|
|
35
|
+
if (buildInfoFile !== BUILD_INFO_FILE)
|
|
36
|
+
return readBuildEndpoint(buildInfoFile);
|
|
37
|
+
if (cachedBuildEndpoint === undefined)
|
|
38
|
+
cachedBuildEndpoint = readBuildEndpoint(buildInfoFile);
|
|
39
|
+
return cachedBuildEndpoint;
|
|
40
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type TelemetryEnvelope } from './schema.js';
|
|
2
|
+
type InstallForm = TelemetryEnvelope['installForm'];
|
|
3
|
+
/** The desktop service sets CORTEX_NPM_PREFIX; a global npm layout is the npm form. */
|
|
4
|
+
export declare function detectInstallForm(env?: NodeJS.ProcessEnv, installRoot?: string): InstallForm;
|
|
5
|
+
export declare function buildEnvelope(channel: TelemetryEnvelope['channel'], now?: Date): TelemetryEnvelope;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import { getLocale } from '../../core/i18n.js';
|
|
3
|
+
import { INSTALL_ROOT } from '../../core/paths.js';
|
|
4
|
+
import { npmPrefixFromInstallRoot } from '../../core/utils.js';
|
|
5
|
+
import { CORTEX_VERSION } from '../../core/version.js';
|
|
6
|
+
import { getInstallId } from './install-id.js';
|
|
7
|
+
import { TELEMETRY_SCHEMA_VERSION } from './schema.js';
|
|
8
|
+
const KNOWN_OS = ['linux', 'darwin', 'win32', 'android'];
|
|
9
|
+
/** The desktop service sets CORTEX_NPM_PREFIX; a global npm layout is the npm form. */
|
|
10
|
+
export function detectInstallForm(env = process.env, installRoot = INSTALL_ROOT) {
|
|
11
|
+
if (env.CORTEX_NPM_PREFIX?.trim())
|
|
12
|
+
return 'desktop';
|
|
13
|
+
return npmPrefixFromInstallRoot(installRoot, '@cortex-agent/server') ? 'npm' : 'other';
|
|
14
|
+
}
|
|
15
|
+
function osName(platform) {
|
|
16
|
+
return KNOWN_OS.includes(platform) ? platform : 'other';
|
|
17
|
+
}
|
|
18
|
+
function majorOf(release) {
|
|
19
|
+
return (release.split('.')[0] ?? '').slice(0, 20);
|
|
20
|
+
}
|
|
21
|
+
export function buildEnvelope(channel, now = new Date()) {
|
|
22
|
+
return {
|
|
23
|
+
schema: TELEMETRY_SCHEMA_VERSION,
|
|
24
|
+
installId: getInstallId(),
|
|
25
|
+
sentAt: now.toISOString(),
|
|
26
|
+
version: CORTEX_VERSION.slice(0, 40),
|
|
27
|
+
channel,
|
|
28
|
+
installForm: detectInstallForm(),
|
|
29
|
+
os: osName(process.platform),
|
|
30
|
+
osRelease: majorOf(os.release()),
|
|
31
|
+
arch: process.arch.slice(0, 20),
|
|
32
|
+
nodeMajor: Number.parseInt(process.versions.node, 10),
|
|
33
|
+
uiLang: getLocale(),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** A stable group for one `log.error` call: the error's own frame, else its message shape. */
|
|
2
|
+
export declare function describeLogError(module: string, args: unknown[]): {
|
|
3
|
+
groupKey: string;
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
/** The `log.error` sink: count per module, keep one redacted sample for up to five groups. */
|
|
7
|
+
export declare function recordErrorLog(module: string, args: unknown[]): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { groupKeyOf, redactMessage, redactStack } from './redact.js';
|
|
2
|
+
import { updateRollup } from './rollup.js';
|
|
3
|
+
const MAX_SAMPLES = 5;
|
|
4
|
+
function formatArg(arg) {
|
|
5
|
+
if (arg instanceof Error)
|
|
6
|
+
return `${arg.name}: ${arg.message}`;
|
|
7
|
+
if (typeof arg === 'string')
|
|
8
|
+
return arg;
|
|
9
|
+
try {
|
|
10
|
+
return JSON.stringify(arg) ?? String(arg);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return String(arg);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** A stable group for one `log.error` call: the error's own frame, else its message shape. */
|
|
17
|
+
export function describeLogError(module, args) {
|
|
18
|
+
const message = redactMessage(args.map(formatArg).join(' '));
|
|
19
|
+
const error = args.find((arg) => arg instanceof Error);
|
|
20
|
+
if (error?.stack) {
|
|
21
|
+
const key = groupKeyOf(error.name || 'Error', redactStack(error.stack));
|
|
22
|
+
if (!key.endsWith('@unknown'))
|
|
23
|
+
return { groupKey: `${module}:${key}`.slice(0, 200), message };
|
|
24
|
+
}
|
|
25
|
+
const shape = message.replace(/\d+/g, '#').slice(0, 120);
|
|
26
|
+
return { groupKey: `${module}:${shape}`.slice(0, 200), message };
|
|
27
|
+
}
|
|
28
|
+
function addSample(rollup, module, args) {
|
|
29
|
+
const { samples } = rollup.errors;
|
|
30
|
+
const { groupKey, message } = describeLogError(module, args);
|
|
31
|
+
const existing = samples.find((sample) => sample.groupKey === groupKey);
|
|
32
|
+
if (existing)
|
|
33
|
+
existing.count += 1;
|
|
34
|
+
else if (samples.length < MAX_SAMPLES)
|
|
35
|
+
samples.push({ module, groupKey, message, count: 1 });
|
|
36
|
+
}
|
|
37
|
+
/** The `log.error` sink: count per module, keep one redacted sample for up to five groups. */
|
|
38
|
+
export function recordErrorLog(module, args) {
|
|
39
|
+
updateRollup((rollup) => {
|
|
40
|
+
rollup.errors.byModule[module] = (rollup.errors.byModule[module] ?? 0) + 1;
|
|
41
|
+
addSample(rollup, module, args);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FunnelEvent } from './schema.js';
|
|
2
|
+
type ServerStep = Extract<FunnelEvent['step'], `server_${string}` | 'provider_authed' | `first_${string}`>;
|
|
3
|
+
/** Report an onboarding step the first time this install reaches it; later calls are no-ops. */
|
|
4
|
+
export declare function recordFunnelStep(step: ServerStep, detail?: string | null): void;
|
|
5
|
+
export declare function resetFunnelCacheForTests(): void;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { recordTelemetryEvent } from './service.js';
|
|
2
|
+
import { readTelemetryState, updateTelemetryState } from './state.js';
|
|
3
|
+
const sentThisProcess = new Set();
|
|
4
|
+
/** Report an onboarding step the first time this install reaches it; later calls are no-ops. */
|
|
5
|
+
export function recordFunnelStep(step, detail = null) {
|
|
6
|
+
if (sentThisProcess.has(step))
|
|
7
|
+
return;
|
|
8
|
+
if (readTelemetryState().funnelSent.includes(step)) {
|
|
9
|
+
sentThisProcess.add(step);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const recorded = recordTelemetryEvent({
|
|
13
|
+
type: 'funnel', at: new Date().toISOString(), source: 'server', step, detail,
|
|
14
|
+
});
|
|
15
|
+
if (!recorded)
|
|
16
|
+
return;
|
|
17
|
+
sentThisProcess.add(step);
|
|
18
|
+
updateTelemetryState((state) => ({ ...state, funnelSent: [...new Set([...state.funnelSent, step])] }));
|
|
19
|
+
}
|
|
20
|
+
export function resetFunnelCacheForTests() {
|
|
21
|
+
sentThisProcess.clear();
|
|
22
|
+
}
|