@chroxy/server 0.11.0 → 0.11.10
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/CONFIG.md +204 -18
- package/README.md +2 -2
- package/hooks/claude-native-route-check.mjs +17 -0
- package/hooks/permission-hook.sh +166 -11
- package/package.json +16 -12
- package/sidecar/Dockerfile +1 -1
- package/sidecar/PROTOCOL.md +9 -1
- package/sidecar/agent.js +102 -10
- package/sidecar/package-lock.json +3 -3
- package/src/acp-config.js +206 -0
- package/src/acp-session.js +954 -0
- package/src/activity-registry.js +110 -5
- package/src/agent-connections.js +293 -0
- package/src/agent-control/client.js +1616 -0
- package/src/agent-control/events.js +547 -0
- package/src/agent-control/local-connection.js +275 -0
- package/src/agent-control/mcp-server.js +545 -0
- package/src/anthropic-compatible-config.js +29 -4
- package/src/anthropic-compatible-session.js +15 -6
- package/src/anthropic-openai-shim.js +0 -1
- package/src/archive-continuation.js +164 -0
- package/src/assistant-response.js +24 -0
- package/src/auth-probes.js +120 -13
- package/src/background-shell-tracker.js +27 -0
- package/src/base-session.js +1203 -36
- package/src/bearer-recheck.js +49 -0
- package/src/billing-budget.js +19 -0
- package/src/billing-class.js +40 -7
- package/src/binary-provenance-trust.js +11 -5
- package/src/bound-client-policy.js +279 -0
- package/src/built-in-tools/bash-exec.js +46 -7
- package/src/built-in-tools/file-ops.js +69 -5
- package/src/built-in-tools/tool-transforms.js +1113 -13
- package/src/byok-compose-state.js +6 -9
- package/src/byok-credentials.js +2 -3
- package/src/byok-mcp-client.js +92 -7
- package/src/byok-mcp-config.js +628 -121
- package/src/byok-mcp-fleet.js +49 -7
- package/src/byok-mcp-oauth-store.js +18 -16
- package/src/byok-mcp-trust.js +3 -3
- package/src/byok-session.js +650 -175
- package/src/byok-tool-executor.js +2662 -26
- package/src/byok-tools.js +9 -2
- package/src/channels/chroxy-channel-server.js +2 -3
- package/src/checkpoint-manager.js +64 -46
- package/src/claude-channel-session.js +16 -10
- package/src/claude-model-catalog.js +131 -16
- package/src/claude-model-refresh.js +385 -0
- package/src/claude-model-request.js +103 -0
- package/src/claude-stream-parser.js +53 -3
- package/src/claude-tui/diagnostic-tail.js +83 -0
- package/src/claude-tui/form-driver.js +44 -7
- package/src/claude-tui/model-error.js +41 -0
- package/src/claude-tui/pty-driver.js +211 -88
- package/src/claude-tui/sanitize-question-payload.js +109 -0
- package/src/claude-tui/usage-limit.js +239 -0
- package/src/claude-tui-session.js +3513 -287
- package/src/claude-tui-tool-response.js +300 -0
- package/src/cli/agent-control-cmd.js +65 -0
- package/src/cli/config-cmd.js +4 -4
- package/src/cli/config-dir-cmd.js +234 -0
- package/src/cli/deploy-cmd.js +45 -10
- package/src/cli/doctor-cmd.js +7 -3
- package/src/cli/init-cmd.js +15 -16
- package/src/cli/providers-cmd.js +3 -3
- package/src/cli/schedule-cmd.js +68 -39
- package/src/cli/server-cmd.js +48 -1
- package/src/cli/service-cmd.js +33 -10
- package/src/cli/session-cmd.js +227 -74
- package/src/cli/shared.js +162 -11
- package/src/cli/tokens-cmd.js +4 -5
- package/src/cli/tunnel-cmd.js +255 -24
- package/src/cli/worktree-gc-cmd.js +2 -2
- package/src/cli-session.js +1066 -121
- package/src/cli.js +4 -0
- package/src/codex-app-server-client.js +36 -3
- package/src/codex-app-server-session.js +1454 -79
- package/src/codex-bundled-client.js +66 -0
- package/src/codex-model-catalog.js +548 -0
- package/src/codex-model-rejections.js +87 -0
- package/src/codex-native-resume.js +104 -0
- package/src/codex-protocol-capabilities.js +188 -0
- package/src/codex-session.js +450 -27
- package/src/config-dir-migration.js +444 -0
- package/src/config-dir.js +108 -0
- package/src/config.js +286 -26
- package/src/connection-authority.js +48 -0
- package/src/connection-info.js +5 -9
- package/src/connection-locality.js +60 -0
- package/src/container-liveness-monitor.js +189 -0
- package/src/continuation-metadata-worker.js +17 -0
- package/src/continuations.js +114 -0
- package/src/control-room/host-prune.js +5 -0
- package/src/control-room/integrations.js +7 -20
- package/src/control-room/skills-inventory.js +2 -2
- package/src/conversation-scanner.js +40 -18
- package/src/conversation-scope.js +59 -39
- package/src/conversation-search.js +24 -22
- package/src/credential-store.js +23 -19
- package/src/daemon-commit.js +92 -0
- package/src/daemon-idle-state.js +171 -0
- package/src/daemon-update-status.js +314 -0
- package/src/dashboard-build.js +70 -0
- package/src/declared-status.js +90 -0
- package/src/deepseek-credentials.js +2 -3
- package/src/dev-preview.js +169 -182
- package/src/device-preferences.js +2 -2
- package/src/diff-parser.js +87 -0
- package/src/discord-credentials.js +2 -3
- package/src/docker-byok-pool.js +3 -1
- package/src/docker-byok-session.js +678 -78
- package/src/docker-image-allowlist.js +23 -1
- package/src/docker-sdk-session.js +172 -3
- package/src/docker-session.js +284 -10
- package/src/doctor.js +767 -61
- package/src/edited-input.js +264 -0
- package/src/environment-manager.js +175 -36
- package/src/environments/authority.js +95 -0
- package/src/environments/backends/container-claude-spawn.js +94 -0
- package/src/environments/backends/docker.js +31 -10
- package/src/environments/backends/k8s.js +49 -24
- package/src/environments/destroy-with-sessions.js +142 -0
- package/src/event-ingest.js +118 -13
- package/src/event-normalizer.js +151 -233
- package/src/gemini-session.js +81 -5
- package/src/handler-utils.js +535 -68
- package/src/handlers/checkpoint-handlers.js +39 -4
- package/src/handlers/control-room-handlers.js +51 -11
- package/src/handlers/conversation-handlers.js +469 -56
- package/src/handlers/daemon-update-handlers.js +81 -0
- package/src/handlers/evaluator-handlers.js +14 -1
- package/src/handlers/feature-handlers.js +186 -69
- package/src/handlers/file-handlers.js +57 -13
- package/src/handlers/input-handlers.js +685 -48
- package/src/handlers/orchestration-handlers.js +3 -3
- package/src/handlers/scheduler-handlers.js +88 -14
- package/src/handlers/session-handlers.js +542 -20
- package/src/handlers/session-pr-status-handlers.js +283 -0
- package/src/handlers/session-pr-threads-handlers.js +247 -0
- package/src/handlers/settings-handlers.js +330 -42
- package/src/handlers/skills-handlers.js +13 -4
- package/src/handlers/summarize-handlers.js +32 -1
- package/src/handlers/survey-throttle.js +380 -0
- package/src/health-proof.js +40 -0
- package/src/history-page.js +104 -0
- package/src/http-routes.js +127 -8
- package/src/ide/search.js +24 -6
- package/src/ide/symbols.js +20 -6
- package/src/input-context.js +117 -0
- package/src/instruction-policy-compiler.js +229 -0
- package/src/instruction-policy.js +250 -0
- package/src/jsonl-reader.js +289 -82
- package/src/jsonl-subprocess-session.js +92 -8
- package/src/keychain.js +1 -1
- package/src/logger.js +63 -17
- package/src/mailbox-route.js +11 -22
- package/src/message-wire.js +386 -0
- package/src/model-discovery.js +43 -3
- package/src/models.js +1276 -174
- package/src/notification-prefs.js +12 -4
- package/src/notifications/discord-billing-sink.js +22 -5
- package/src/notifications/discord-ci-sink.js +243 -0
- package/src/notifications/discord-webhook-client.js +71 -0
- package/src/notifications/discord-webhook-sink.js +64 -23
- package/src/notifications/expo-push-sink.js +85 -6
- package/src/notifications/ready-body.js +16 -5
- package/src/ollama-session.js +34 -2
- package/src/orchestration/build-manager.js +9 -2
- package/src/orchestration/git-ops.js +41 -7
- package/src/orchestration/orchestration-manager.js +80 -33
- package/src/orchestration/permission-gate.js +13 -1
- package/src/orchestration/run-model.js +2 -1
- package/src/orchestration/turn-driver.js +44 -20
- package/src/orphan-reaper.js +413 -0
- package/src/outgoing-policy.js +183 -0
- package/src/pairing.js +92 -13
- package/src/path-hash-trust-ledger.js +642 -25
- package/src/permission-deadlines.js +82 -0
- package/src/permission-floor.js +1357 -42
- package/src/permission-hook.js +180 -69
- package/src/permission-manager.js +712 -83
- package/src/permission-mode-support.js +35 -0
- package/src/permission-resolver.js +122 -8
- package/src/permission-scope.js +43 -0
- package/src/platform.js +159 -43
- package/src/preview-ingress.js +54 -0
- package/src/preview-target.js +213 -0
- package/src/prompt-evaluator.js +34 -4
- package/src/provider-customization.js +180 -0
- package/src/providers.js +207 -4
- package/src/push.js +30 -4
- package/src/question-route-map.js +130 -0
- package/src/redaction.js +360 -8
- package/src/roster-broadcast.js +186 -0
- package/src/scheduled-task-store.js +318 -26
- package/src/scheduler.js +73 -3
- package/src/sdk-session.js +2060 -187
- package/src/server-cli/preview-shutdown.js +22 -0
- package/src/server-cli/push-notification-handler.js +11 -2
- package/src/server-cli/server-orchestrator.js +28 -5
- package/src/server-cli-child.js +33 -18
- package/src/server-cli.js +524 -38
- package/src/server-identity.js +15 -11
- package/src/service.js +396 -25
- package/src/session-archive-limits.js +15 -0
- package/src/session-archive.js +1029 -0
- package/src/session-busy-state.js +72 -0
- package/src/session-ci-watcher.js +926 -0
- package/src/session-context.js +7 -2
- package/src/session-manager.js +3491 -312
- package/src/session-message-history.js +722 -16
- package/src/session-pr-status.js +654 -0
- package/src/session-pr-threads.js +271 -0
- package/src/session-preset-trust.js +3 -3
- package/src/session-preset.js +10 -5
- package/src/session-state-persistence.js +94 -17
- package/src/session-timeout-manager.js +20 -0
- package/src/session-token-store.js +17 -8
- package/src/session-wake.js +240 -0
- package/src/shell-approval-info.js +2 -2
- package/src/shell-approval-store.js +3 -1
- package/src/skills-loader.js +7 -4
- package/src/skills-manager.js +2 -2
- package/src/skills-trust.js +95 -13
- package/src/skills-usage.js +2 -3
- package/src/snapshots-store.js +2 -3
- package/src/statusline.js +23 -11
- package/src/summarize-session.js +51 -4
- package/src/supervisor.js +22 -11
- package/src/sweep-stale-provider-dirs.js +95 -0
- package/src/thinking-level-wire.js +39 -0
- package/src/thinking-stream.js +179 -0
- package/src/tool-result.js +61 -0
- package/src/transcript-sources.js +109 -0
- package/src/transcript-tasks.js +372 -25
- package/src/trusted-file-read.js +302 -0
- package/src/tunnel/base.js +0 -8
- package/src/tunnel/cloudflare.js +34 -31
- package/src/tunnel/index.js +9 -0
- package/src/tunnel/preview.js +64 -0
- package/src/turn-outcome.js +137 -0
- package/src/usage-normalize.js +9 -5
- package/src/user-shell-session.js +59 -5
- package/src/utils/agent-sdk-version.js +107 -0
- package/src/utils/argv-safety.js +741 -0
- package/src/utils/auth-cause.js +60 -0
- package/src/utils/binary-package-manifest.js +597 -0
- package/src/utils/binary-version.js +224 -0
- package/src/utils/bounded-regex-worker.js +25 -0
- package/src/utils/bounded-regex.js +153 -0
- package/src/utils/claude-binary.js +43 -0
- package/src/utils/claude-config-dir.js +245 -0
- package/src/utils/claude-login-command.js +16 -0
- package/src/utils/claude-native-route.js +81 -0
- package/src/utils/componentwise-resolver.js +133 -37
- package/src/utils/deploy-control-files.js +87 -0
- package/src/utils/exec-failure-reason.js +21 -0
- package/src/utils/git-repo.js +42 -0
- package/src/utils/is-entry-point.js +137 -0
- package/src/utils/node-pty-probe.js +95 -0
- package/src/utils/node-pty-support.js +118 -0
- package/src/utils/opened-file-path.js +167 -0
- package/src/utils/path-containment.js +165 -0
- package/src/utils/permission-mode-sidecar.js +51 -0
- package/src/utils/preflight.js +360 -16
- package/src/utils/read-limiter.js +217 -0
- package/src/utils/regular-file.js +375 -0
- package/src/utils/safe-regex.js +113 -0
- package/src/utils/small-file.js +129 -0
- package/src/utils/spawn-env.js +189 -4
- package/src/utils/stale-session-dirs.js +182 -0
- package/src/utils/stat-identity.js +43 -0
- package/src/utils/verify-provenance.js +406 -13
- package/src/web-task-manager.js +256 -16
- package/src/worktree-gc.js +7 -2
- package/src/ws-auth.js +69 -21
- package/src/ws-broadcaster.js +14 -2
- package/src/ws-client-manager.js +16 -1
- package/src/ws-client-sender.js +7 -0
- package/src/ws-file-ops/browser.js +331 -58
- package/src/ws-file-ops/common.js +320 -14
- package/src/ws-file-ops/git.js +395 -42
- package/src/ws-file-ops/index.js +2 -0
- package/src/ws-file-ops/memory.js +137 -35
- package/src/ws-file-ops/open-nofollow.js +354 -0
- package/src/ws-file-ops/reader.js +571 -113
- package/src/ws-forwarding.js +329 -39
- package/src/ws-handler-context.js +70 -2
- package/src/ws-history.js +940 -172
- package/src/ws-message-handlers.js +17 -1
- package/src/ws-permissions.js +307 -37
- package/src/ws-schemas.js +5 -0
- package/src/ws-server.js +643 -96
- package/sidecar/node_modules/.package-lock.json +0 -29
- package/sidecar/node_modules/ws/LICENSE +0 -20
- package/sidecar/node_modules/ws/README.md +0 -548
- package/sidecar/node_modules/ws/browser.js +0 -8
- package/sidecar/node_modules/ws/index.js +0 -22
- package/sidecar/node_modules/ws/lib/buffer-util.js +0 -131
- package/sidecar/node_modules/ws/lib/constants.js +0 -19
- package/sidecar/node_modules/ws/lib/event-target.js +0 -292
- package/sidecar/node_modules/ws/lib/extension.js +0 -203
- package/sidecar/node_modules/ws/lib/limiter.js +0 -55
- package/sidecar/node_modules/ws/lib/permessage-deflate.js +0 -528
- package/sidecar/node_modules/ws/lib/receiver.js +0 -706
- package/sidecar/node_modules/ws/lib/sender.js +0 -602
- package/sidecar/node_modules/ws/lib/stream.js +0 -161
- package/sidecar/node_modules/ws/lib/subprotocol.js +0 -62
- package/sidecar/node_modules/ws/lib/validation.js +0 -152
- package/sidecar/node_modules/ws/lib/websocket-server.js +0 -554
- package/sidecar/node_modules/ws/lib/websocket.js +0 -1393
- package/sidecar/node_modules/ws/package.json +0 -70
- package/sidecar/node_modules/ws/wrapper.mjs +0 -21
- package/src/dashboard-next/dist/assets/index-C2ipeGlq.js +0 -111
- package/src/dashboard-next/dist/assets/index-DM-_dISG.css +0 -1
- package/src/dashboard-next/dist/index.html +0 -13
- package/src/dashboard-next/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
package/src/server-cli.js
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
SessionManager,
|
|
3
|
+
ProviderBinaryNotFoundError,
|
|
4
|
+
ProviderBinaryQuarantinedError,
|
|
5
|
+
ProviderBinaryProvenanceError,
|
|
6
|
+
ProviderBinaryUnsupportedError,
|
|
7
|
+
ProviderBinaryVersionError,
|
|
8
|
+
ProviderCredentialMissingError,
|
|
9
|
+
} from './session-manager.js'
|
|
2
10
|
import { DEFAULT_RESULT_TIMEOUT_MS, DEFAULT_HARD_TIMEOUT_MS, DEFAULT_STREAM_STALL_TIMEOUT_MS } from './base-session.js'
|
|
3
11
|
import { DEFAULT_TOOL_CALL_TIMEOUT_MS } from './byok-mcp-client.js'
|
|
4
12
|
import { formatIdleDuration } from './session-timeout-manager.js'
|
|
5
13
|
import { isOperatorTimeoutInRange } from './duration.js'
|
|
6
14
|
import { WsServer } from './ws-server.js'
|
|
7
15
|
import { BillingCanaryMonitor } from './billing-canary-monitor.js'
|
|
16
|
+
import { buildSessionCiWatcher } from './session-ci-watcher.js'
|
|
17
|
+
import { DaemonUpdateStatus } from './daemon-update-status.js'
|
|
18
|
+
import { computeDaemonIdleState } from './daemon-idle-state.js'
|
|
8
19
|
import { resolvePublicIp } from './get-public-ip.js'
|
|
9
20
|
import { createTunnel, parseTunnelArg } from './tunnel/index.js'
|
|
10
21
|
// #5368 slice (c): QUICK_TUNNEL_DNS_SETTLE_MS + TUNNEL_STATUS_MIN_PROTOCOL_VERSION
|
|
@@ -14,6 +25,8 @@ import { waitForTunnel } from './tunnel-check.js'
|
|
|
14
25
|
import { PushManager, settlePush } from './push.js'
|
|
15
26
|
import { ensureIngestSecret } from './event-ingest.js'
|
|
16
27
|
import { getChroxyHostEnv } from './chroxy-host-metadata.js'
|
|
28
|
+
import { boundedRegex } from './utils/bounded-regex.js'
|
|
29
|
+
import { probeNodePtyAvailable } from './utils/node-pty-probe.js'
|
|
17
30
|
import { PushNotificationHandler } from './server-cli/push-notification-handler.js'
|
|
18
31
|
import { StartupDisplay } from './server-cli/startup-display.js'
|
|
19
32
|
import { TunnelLifecycleHandler } from './server-cli/tunnel-lifecycle-handler.js'
|
|
@@ -23,6 +36,9 @@ import { readFileSync, existsSync } from 'fs'
|
|
|
23
36
|
import { fileURLToPath } from 'url'
|
|
24
37
|
import { dirname, join, relative, sep } from 'path'
|
|
25
38
|
import { createLogger, setJsonMode, initFileLogging, setConsoleQuiet } from './logger.js'
|
|
39
|
+
import { configDir, configPath } from './config-dir.js'
|
|
40
|
+
import { defaultCwdAdvisory } from './handler-utils.js'
|
|
41
|
+
import { detectStrandedState, missingTokenAdvice, startupStrandedWarning } from './config-dir-migration.js'
|
|
26
42
|
|
|
27
43
|
const log = createLogger('cli')
|
|
28
44
|
// #5368 slice (b): QRCode + writeConnectionInfo moved to startup-display.js with
|
|
@@ -36,23 +52,27 @@ import { resolveBindHost, isLoopbackHost, formatHostForUrl, maybeWarnNonLoopback
|
|
|
36
52
|
import { writeFileRestricted } from './platform.js'
|
|
37
53
|
import { getToken, setToken, migrateToken, isKeychainAvailable } from './keychain.js'
|
|
38
54
|
import { maybeEncryptCredentialsAtRest } from './credential-store.js'
|
|
39
|
-
import { registerDockerProvider, resolveProviderLabel, DEFAULT_PROVIDER } from './providers.js'
|
|
55
|
+
import { registerDockerProvider, resolveProviderLabel, DEFAULT_PROVIDER, resolveDaemonDefaultProvider } from './providers.js'
|
|
40
56
|
import { registerAnthropicCompatibleProviders } from './anthropic-compatible-session.js'
|
|
41
57
|
import { registerOpenAiCompatibleProviders } from './openai-compatible-session.js'
|
|
58
|
+
import { registerAcpProviders } from './acp-session.js'
|
|
42
59
|
import { getSharedPool, isPoolEnabled } from './docker-byok-pool.js'
|
|
43
60
|
import { getSharedPoolStats } from './docker-byok-pool-stats.js'
|
|
44
|
-
import { getRegistryForProvider, watchModelsOverlay } from './models.js'
|
|
61
|
+
import { getRegistryForProvider, watchModelsOverlay, setInUseModelsProvider } from './models.js'
|
|
62
|
+
import { clientActiveProvider, overlayBroadcastReachesProvider, broadcastRosterPerRecipient } from './roster-broadcast.js'
|
|
45
63
|
// Imported from a dedicated constants module rather than environment-manager.js
|
|
46
64
|
// so we don't eagerly pull in DockerBackend when environments are disabled —
|
|
47
65
|
// environment-manager.js itself remains behind the dynamic import below
|
|
48
66
|
// (`if (config?.environments?.enabled)`).
|
|
49
67
|
import { UNREACHABLE_STATUSES } from './environment-statuses.js'
|
|
50
|
-
import { resolveSkipPermissions, buildEnvironmentBackend, isUserShellEnabled, getAllowAnyModelProviders, isSemanticTitlesEnabled, resolveSemanticTitleModel, resolveSemanticTitleTimeoutMs, resolveBinaryProvenanceMode, isBinarySignatureGateEnabled } from './config.js'
|
|
68
|
+
import { resolveSkipPermissions, buildEnvironmentBackend, isUserShellEnabled, getAllowAnyModelProviders, isSemanticTitlesEnabled, resolveSemanticTitleModel, resolveSemanticTitleTimeoutMs, resolveBinaryProvenanceMode, isBinarySignatureGateEnabled, applyCodexBinaryConfig } from './config.js'
|
|
69
|
+
import { sweepStaleProviderDirs } from './sweep-stale-provider-dirs.js'
|
|
51
70
|
import { buildOrchestrationManager } from './orchestration/build-manager.js'
|
|
52
71
|
import { buildSchedulerEngine } from './scheduler.js'
|
|
53
72
|
import { parseDuration } from './duration.js'
|
|
54
73
|
import { createSessionTokenStore } from './session-token-store.js'
|
|
55
74
|
import { StatusLineManager } from './statusline.js'
|
|
75
|
+
import { warnIfClaudeConfigDirUnusable } from './utils/claude-config-dir.js'
|
|
56
76
|
|
|
57
77
|
const __filename = fileURLToPath(import.meta.url)
|
|
58
78
|
const __dirname = dirname(__filename)
|
|
@@ -233,6 +253,155 @@ export function buildServerBanner({ version, provider }) {
|
|
|
233
253
|
return `Chroxy Server v${version} (${modeStr})`
|
|
234
254
|
}
|
|
235
255
|
|
|
256
|
+
/**
|
|
257
|
+
* #7722 — build the `available_models` broadcasts for one models-overlay
|
|
258
|
+
* hot-reload (`watchModelsOverlay`'s `onReload`).
|
|
259
|
+
*
|
|
260
|
+
* The reload re-folds the default (Claude) registry AND every per-provider
|
|
261
|
+
* registry the overlay touches (#6377), so it produces ONE roster per affected
|
|
262
|
+
* registry — not one. Broadcasting only the Claude roster (and labelling it
|
|
263
|
+
* `claude-sdk`, as this did before) had two failures on a live codex session: a
|
|
264
|
+
* `provider: "codex"` overlay row never reached the codex client at all, and —
|
|
265
|
+
* on the pre-#7728 clients this was written against — the claude-sdk tag flipped
|
|
266
|
+
* the dashboard's `modelsMatchProvider` false, which HID the model picker until
|
|
267
|
+
* the client reconnected. That second failure is gone: `modelsMatchProvider` was
|
|
268
|
+
* deleted with the single `availableModels` slot, and a client now keys each
|
|
269
|
+
* roster by its sender. The FIRST one is still live and is what this function
|
|
270
|
+
* exists for — a roster that is never sent cannot be read from any slot.
|
|
271
|
+
*
|
|
272
|
+
* The wire shape is unchanged — each entry is the same provider-tagged
|
|
273
|
+
* `available_models` message every other sender emits.
|
|
274
|
+
*
|
|
275
|
+
* This builds the SET; it does not decide recipients.
|
|
276
|
+
* `overlayBroadcastReachesProvider` below is the recipient rule, and
|
|
277
|
+
* `createOverlayReloadBroadcaster` is what applies it. Until #7728 that routing
|
|
278
|
+
* was load-bearing for CORRECTNESS: every client kept ONE `availableModels`
|
|
279
|
+
* slot, replaced unconditionally on every message, so sending the whole set to
|
|
280
|
+
* everyone was last-write-wins and a Claude client on a daemon that also has a
|
|
281
|
+
* codex row ended up tagged `codex` and lost the very picker this issue is
|
|
282
|
+
* about. Clients now key each roster by the provider that sent it
|
|
283
|
+
* (`mergeModelsByProvider`, store-core/src/models-by-provider.ts), so the
|
|
284
|
+
* routing is defence in depth and bandwidth rather than the only thing standing
|
|
285
|
+
* between a codex session and a Claude roster.
|
|
286
|
+
*
|
|
287
|
+
* Exported so tests can assert the broadcast set without executing
|
|
288
|
+
* `startCliServer()` end-to-end.
|
|
289
|
+
*
|
|
290
|
+
* @param {{ models?: object[], defaultModelId?: string|null, providers?: {provider: string, models: object[], defaultModelId: string|null}[] }} reload
|
|
291
|
+
* @returns {{ type: 'available_models', models: object[], defaultModel: string|null, provider: string }[]}
|
|
292
|
+
*/
|
|
293
|
+
export function buildOverlayReloadBroadcasts({ models, defaultModelId, providers } = {}) {
|
|
294
|
+
const out = [{
|
|
295
|
+
type: 'available_models',
|
|
296
|
+
models: models || [],
|
|
297
|
+
defaultModel: defaultModelId ?? null,
|
|
298
|
+
provider: 'claude-sdk',
|
|
299
|
+
}]
|
|
300
|
+
for (const entry of providers || []) {
|
|
301
|
+
if (!entry || typeof entry.provider !== 'string' || entry.provider.length === 0) continue
|
|
302
|
+
out.push({
|
|
303
|
+
type: 'available_models',
|
|
304
|
+
models: entry.models || [],
|
|
305
|
+
defaultModel: entry.defaultModelId ?? null,
|
|
306
|
+
provider: entry.provider,
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
return out
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// #7895 — `overlayBroadcastReachesProvider` and `clientActiveProvider` moved to
|
|
313
|
+
// `./roster-broadcast.js` so `ws-forwarding.js`'s two `available_models` send
|
|
314
|
+
// sites can share them (and the per-recipient tagging loop below) instead of a
|
|
315
|
+
// third hand-rolled copy. Re-exported here so every existing importer of this
|
|
316
|
+
// module — notably `models-overlay-reload-broadcast.test.js` — is unaffected.
|
|
317
|
+
export { overlayBroadcastReachesProvider, clientActiveProvider }
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* #7722 — build the `watchModelsOverlay({ onReload })` callback: turn one reload
|
|
321
|
+
* into its broadcast set and send each entry ONLY to the clients that registry
|
|
322
|
+
* is the roster for (`overlayBroadcastReachesProvider`).
|
|
323
|
+
*
|
|
324
|
+
* #7756 — the DEFAULT (Claude) entry additionally gets RE-TAGGED per recipient
|
|
325
|
+
* instead of sent verbatim. `claude-sdk`, `claude-cli` and `claude-tui` share
|
|
326
|
+
* this one registry, so `overlayBroadcastReachesProvider` correctly decides all
|
|
327
|
+
* three should receive it — but since #7728 the client keys each roster by the
|
|
328
|
+
* EXACT tag it arrived under (`modelsByProvider`,
|
|
329
|
+
* store-core/src/models-by-provider.ts), so a single `claude-sdk` literal
|
|
330
|
+
* never refreshes a `claude-cli`/`claude-tui` client's OWN bucket even though
|
|
331
|
+
* routing already decided it should. Each recipient is instead served the same roster
|
|
332
|
+
* tagged with the name `resolveRosterProvider` would give IT on a fresh
|
|
333
|
+
* connect (`ws-history.js`'s own resolution), so a reload and a reconnect agree
|
|
334
|
+
* on what a session's roster is called — no reconnect-vs-reload skew.
|
|
335
|
+
*
|
|
336
|
+
* The concrete tag set is derived from the provider REGISTRY
|
|
337
|
+
* (`getRegisteredProviderNames` + `isClaudeProvider`, #5858's single source of
|
|
338
|
+
* truth), never a hand-maintained name literal — the exact defect class #5855
|
|
339
|
+
* fixed for `isClaudeProvider` itself. That includes `claude-byok`
|
|
340
|
+
* (`static claudeFamily = true`, byok-session.js) — see the paragraph below
|
|
341
|
+
* for why an earlier revision of this fix excluded it and why that was wrong.
|
|
342
|
+
*
|
|
343
|
+
* A residual broadcast (still tagged with the reload's own literal) covers
|
|
344
|
+
* whatever does not resolve to a known tag — an unregistered/custom provider
|
|
345
|
+
* name, or one whose own registry build throws — preserving the pre-#7756
|
|
346
|
+
* fail-open delivery for that edge case (`overlayBroadcastReachesProvider`'s
|
|
347
|
+
* own try/catch) rather than silently dropping it. That roster was already
|
|
348
|
+
* "delivered and discarded" for such a client before this fix (its own bucket
|
|
349
|
+
* key never matched `claude-sdk` either), so nothing regresses; #7756 is about
|
|
350
|
+
* the KNOWN Claude-family names landing in the wrong bucket, not this edge
|
|
351
|
+
* case.
|
|
352
|
+
*
|
|
353
|
+
* `claude-byok` MUST be in `knownTags`, not the residual: `ws-history.js`'s
|
|
354
|
+
* post-auth connect path (`resolveRosterProvider(entry.provider, ...)` at
|
|
355
|
+
* `ws-history.js:928`) tags a byok client's roster `'claude-byok'` exactly,
|
|
356
|
+
* same registry as claude-sdk/cli/tui. A prior revision of this fix instead
|
|
357
|
+
* excluded `claude-byok` from `knownTags` and explicitly skipped it in the
|
|
358
|
+
* residual, reasoning that connect never refreshed a byok client's own
|
|
359
|
+
* bucket either — but that reasoning rested on a stale reading of #7756
|
|
360
|
+
* (`static claudeFamily = false`) that does not match this class. Excluding
|
|
361
|
+
* it here reproduces the EXACT #7756 bug for a fourth provider: the roster is
|
|
362
|
+
* delivered (via the residual, tagged with the reload's own literal) and
|
|
363
|
+
* discarded, because a byok client's bucket key is `'claude-byok'`, not
|
|
364
|
+
* whatever the residual's literal happens to be. Folding it into the same
|
|
365
|
+
* per-tag treatment as claude-cli/claude-tui is what keeps a reload and a
|
|
366
|
+
* reconnect agreeing on a byok session's roster tag, exactly as they do for
|
|
367
|
+
* the other three.
|
|
368
|
+
*
|
|
369
|
+
* A factory rather than an inline closure so the wiring is a single named
|
|
370
|
+
* reference at the call site AND the behaviour is directly executable in a test
|
|
371
|
+
* — the previous inline closure lived inside `startCliServer()`, which no test
|
|
372
|
+
* can run, so the only available check was a source grep over its body.
|
|
373
|
+
*
|
|
374
|
+
* #7895 — the per-message tagging loop itself (the `tagIsDefault` branch, the
|
|
375
|
+
* known-tags set, the residual fallback) now lives in
|
|
376
|
+
* `broadcastRosterPerRecipient` (`./roster-broadcast.js`), shared with
|
|
377
|
+
* `ws-forwarding.js`'s two `available_models` send sites. This function keeps
|
|
378
|
+
* only what's specific to the overlay-reload wiring: the per-message reload
|
|
379
|
+
* log line and adapting `wsServer._broadcast` to the shared `(msg, filter)`
|
|
380
|
+
* broadcast shape.
|
|
381
|
+
*
|
|
382
|
+
* @param {{ wsServer: { _broadcast: Function }, sessionManager: object, logger?: object, defaultProvider?: string|null }} deps
|
|
383
|
+
* `defaultProvider` is this daemon's resolved default (`config.provider ||
|
|
384
|
+
* DEFAULT_PROVIDER`) — the same value `ws-history.js` feeds
|
|
385
|
+
* `resolveRosterProvider` from `billingCanary.defaultProvider`. Omitted (as
|
|
386
|
+
* every existing caller/test does), `resolveRosterProvider` falls back to
|
|
387
|
+
* `DEFAULT_PROVIDER` itself, which is a true statement only when the daemon
|
|
388
|
+
* was not started with an explicit `--provider` override.
|
|
389
|
+
* @returns {(reload: object) => void}
|
|
390
|
+
*/
|
|
391
|
+
export function createOverlayReloadBroadcaster({ wsServer, sessionManager, logger = log, defaultProvider = null }) {
|
|
392
|
+
return (reload) => {
|
|
393
|
+
for (const message of buildOverlayReloadBroadcasts(reload)) {
|
|
394
|
+
logger.info(`Models overlay reloaded (${message.provider}): ${message.models.map((m) => m.id).join(', ')}`)
|
|
395
|
+
broadcastRosterPerRecipient({
|
|
396
|
+
broadcast: (msg, filter) => wsServer._broadcast(msg, filter),
|
|
397
|
+
sessionManager,
|
|
398
|
+
defaultProvider,
|
|
399
|
+
message,
|
|
400
|
+
})
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
236
405
|
/**
|
|
237
406
|
* Run `environmentManager.reconnect()` and log a startup summary (#3464).
|
|
238
407
|
*
|
|
@@ -406,6 +575,99 @@ export function resolveStartupTimeouts(config = {}, log = { warn: () => {} }) {
|
|
|
406
575
|
}
|
|
407
576
|
}
|
|
408
577
|
|
|
578
|
+
/**
|
|
579
|
+
* Resolve runtime-skill policy once for both SessionManager construction and
|
|
580
|
+
* startup diagnostics (#7834). Keeping the effective values beside their
|
|
581
|
+
* diagnostic source prevents startup from reporting a policy that was not
|
|
582
|
+
* actually forwarded to provider sessions.
|
|
583
|
+
*
|
|
584
|
+
* Omitted values preserve the documented permissive/no-trust defaults.
|
|
585
|
+
* An explicitly malformed allowlist throws before SessionManager construction:
|
|
586
|
+
* `null` is the loader's permissive sentinel, so falling back to it would fail
|
|
587
|
+
* open on the supervised child's independent config re-read. Unknown trust
|
|
588
|
+
* modes remain disabled and are called out as rejected in diagnostics.
|
|
589
|
+
*
|
|
590
|
+
* @param {object} config merged daemon config
|
|
591
|
+
* @returns {{
|
|
592
|
+
* sessionManagerOptions: {
|
|
593
|
+
* maxSkillBytes: number|null,
|
|
594
|
+
* maxTotalSkillBytes: number|null,
|
|
595
|
+
* providerSkillAllowlist: object|null,
|
|
596
|
+
* trustMismatchMode: 'warn'|'block'|null,
|
|
597
|
+
* },
|
|
598
|
+
* diagnostics: {
|
|
599
|
+
* allowlist: { effective: 'configured'|'disabled', source: 'config'|'default'|'rejected config', providerCount: number },
|
|
600
|
+
* trust: { effective: 'warn'|'block'|'disabled', source: 'config'|'default'|'rejected config' },
|
|
601
|
+
* },
|
|
602
|
+
* }}
|
|
603
|
+
*/
|
|
604
|
+
export function resolveStartupSkillPolicy(config = {}) {
|
|
605
|
+
const hasAllowlist = Object.prototype.hasOwnProperty.call(config, 'providerSkillAllowlist')
|
|
606
|
+
const allowlist = config.providerSkillAllowlist
|
|
607
|
+
const allowlistIsValid = allowlist !== null
|
|
608
|
+
&& typeof allowlist === 'object'
|
|
609
|
+
&& !Array.isArray(allowlist)
|
|
610
|
+
if (hasAllowlist && !allowlistIsValid) {
|
|
611
|
+
const error = new TypeError('Runtime skills: allowlist=rejected (source: config; expected object)')
|
|
612
|
+
error.code = 'INVALID_PROVIDER_SKILL_ALLOWLIST'
|
|
613
|
+
throw error
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const hasTrustMode = Object.prototype.hasOwnProperty.call(config, 'trustMismatchMode')
|
|
617
|
+
const trustMode = config.trustMismatchMode
|
|
618
|
+
const trustModeIsValid = trustMode === 'warn' || trustMode === 'block'
|
|
619
|
+
|
|
620
|
+
return {
|
|
621
|
+
sessionManagerOptions: {
|
|
622
|
+
// Keep byte budgets in this builder too: all runtime-skill startup
|
|
623
|
+
// options now cross the daemon boundary through one production seam.
|
|
624
|
+
maxSkillBytes: Number.isFinite(config.maxSkillBytes) ? config.maxSkillBytes : null,
|
|
625
|
+
maxTotalSkillBytes: Number.isFinite(config.maxTotalSkillBytes) ? config.maxTotalSkillBytes : null,
|
|
626
|
+
providerSkillAllowlist: allowlistIsValid ? allowlist : null,
|
|
627
|
+
trustMismatchMode: trustModeIsValid ? trustMode : null,
|
|
628
|
+
},
|
|
629
|
+
diagnostics: {
|
|
630
|
+
allowlist: {
|
|
631
|
+
effective: allowlistIsValid ? 'configured' : 'disabled',
|
|
632
|
+
source: allowlistIsValid ? 'config' : 'default',
|
|
633
|
+
providerCount: allowlistIsValid ? Object.keys(allowlist).length : 0,
|
|
634
|
+
},
|
|
635
|
+
trust: {
|
|
636
|
+
effective: trustModeIsValid ? trustMode : 'disabled',
|
|
637
|
+
source: trustModeIsValid ? 'config' : (hasTrustMode ? 'rejected config' : 'default'),
|
|
638
|
+
},
|
|
639
|
+
},
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/** Format the content-free operator diagnostic for resolved skill policy. */
|
|
644
|
+
export function formatStartupSkillPolicyDiagnostic(diagnostics) {
|
|
645
|
+
const allowlist = diagnostics?.allowlist || { effective: 'disabled', source: 'default', providerCount: 0 }
|
|
646
|
+
const trust = diagnostics?.trust || { effective: 'disabled', source: 'default' }
|
|
647
|
+
const providers = allowlist.effective === 'configured'
|
|
648
|
+
? `, providers: ${allowlist.providerCount}`
|
|
649
|
+
: ''
|
|
650
|
+
return `Runtime skills: allowlist=${allowlist.effective} (source: ${allowlist.source}${providers}); trust=${trust.effective} (source: ${trust.source})`
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Construct the daemon SessionManager with its resolved runtime-skill policy.
|
|
655
|
+
* Tests use this same production factory so removing the final constructor
|
|
656
|
+
* forwarding cannot leave a resolver-only test green (#7834).
|
|
657
|
+
*
|
|
658
|
+
* @param {object} config merged daemon config
|
|
659
|
+
* @param {object} sessionManagerOptions remaining daemon constructor options
|
|
660
|
+
* @returns {{ sessionManager: SessionManager, startupSkillPolicy: object }}
|
|
661
|
+
*/
|
|
662
|
+
export function createDaemonSessionManager(config, sessionManagerOptions) {
|
|
663
|
+
const startupSkillPolicy = resolveStartupSkillPolicy(config)
|
|
664
|
+
const sessionManager = new SessionManager({
|
|
665
|
+
...sessionManagerOptions,
|
|
666
|
+
...startupSkillPolicy.sessionManagerOptions,
|
|
667
|
+
})
|
|
668
|
+
return { sessionManager, startupSkillPolicy }
|
|
669
|
+
}
|
|
670
|
+
|
|
409
671
|
export function initFileLoggingFromConfig(config = {}) {
|
|
410
672
|
if (process.env.CHROXY_NO_FILE_LOGGING === '1') {
|
|
411
673
|
return { enabled: false, level: 'info', logDir: null }
|
|
@@ -506,11 +768,12 @@ export async function emergencyCleanup({
|
|
|
506
768
|
// String(err?.message || err) so a non-Error throw (e.g. a Symbol) can't make
|
|
507
769
|
// the log-formatting itself throw and break this best-effort teardown chain.
|
|
508
770
|
try { if (tunnel) await tunnel.stop() } catch (err) { logger?.warn?.(`emergencyCleanup: tunnel.stop failed: ${String(err?.message || err)}`) }
|
|
509
|
-
try { wsServer?.close() } catch (err) { logger?.warn?.(`emergencyCleanup: wsServer.close failed: ${String(err?.message || err)}`) }
|
|
771
|
+
try { await wsServer?.close() } catch (err) { logger?.warn?.(`emergencyCleanup: wsServer.close failed: ${String(err?.message || err)}`) }
|
|
510
772
|
try { mdnsService?.stop?.() } catch {}
|
|
511
773
|
try { bonjourInstance?.destroy?.() } catch {}
|
|
512
774
|
try { tokenManager?.destroy() } catch {}
|
|
513
775
|
try { pairingManager?.destroy() } catch {}
|
|
776
|
+
try { boundedRegex.close() } catch {}
|
|
514
777
|
try { sessionManager?.destroyAll() } catch (err) { logger?.warn?.(`emergencyCleanup: destroyAll failed: ${String(err?.message || err)}`) }
|
|
515
778
|
}
|
|
516
779
|
|
|
@@ -534,6 +797,7 @@ export function emergencyCleanupSync({ kind, tunnel, wsServer, sessionManager, l
|
|
|
534
797
|
try { sessionManager?.serializeState() } catch (serializeErr) {
|
|
535
798
|
logger?.warn?.(`Failed to serialize state during ${kind}: ${String(serializeErr?.stack || serializeErr)}`)
|
|
536
799
|
}
|
|
800
|
+
try { boundedRegex.close() } catch {}
|
|
537
801
|
try { sessionManager?.destroyAll() } catch {}
|
|
538
802
|
try { wsServer?.close() } catch {}
|
|
539
803
|
// NO await — see the invariant above.
|
|
@@ -541,7 +805,75 @@ export function emergencyCleanupSync({ kind, tunnel, wsServer, sessionManager, l
|
|
|
541
805
|
try { removeConnectionInfo() } catch {}
|
|
542
806
|
}
|
|
543
807
|
|
|
808
|
+
// #8029: the set of typed errors `runProviderPreflight` (via
|
|
809
|
+
// SessionManager#createSession) throws for a provider that isn't usable —
|
|
810
|
+
// binary missing/quarantined/unsupported/wrong-provenance/wrong-version, or
|
|
811
|
+
// missing credentials. Kept as an explicit instanceof list (not a
|
|
812
|
+
// duck-typed `err.code` check) and exposed through `isProviderPreflightError`
|
|
813
|
+
// below, so a test can prove the startup
|
|
814
|
+
// default-session guard below only swallows THIS class of failure and lets
|
|
815
|
+
// anything else — a bug, an out-of-memory error, a corrupted state file —
|
|
816
|
+
// still crash loudly instead of being silently absorbed by a broadened net.
|
|
817
|
+
const PROVIDER_PREFLIGHT_ERROR_CLASSES = [
|
|
818
|
+
ProviderBinaryNotFoundError,
|
|
819
|
+
ProviderBinaryQuarantinedError,
|
|
820
|
+
ProviderBinaryProvenanceError,
|
|
821
|
+
ProviderBinaryUnsupportedError,
|
|
822
|
+
ProviderBinaryVersionError,
|
|
823
|
+
ProviderCredentialMissingError,
|
|
824
|
+
]
|
|
825
|
+
|
|
826
|
+
export function isProviderPreflightError(err) {
|
|
827
|
+
return PROVIDER_PREFLIGHT_ERROR_CLASSES.some((ErrorClass) => err instanceof ErrorClass)
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Create the startup default session, or return the already-restored one.
|
|
832
|
+
* Extracted (like `createDaemonSessionManager` above) so the #8029 preflight
|
|
833
|
+
* guard is unit-testable without driving the rest of `startCliServer`'s
|
|
834
|
+
* WS-server/tunnel/push-manager setup.
|
|
835
|
+
*
|
|
836
|
+
* `createSession` runs `runProviderPreflight` for the configured default
|
|
837
|
+
* provider, which throws a typed error (binary missing/quarantined/
|
|
838
|
+
* unsupported/wrong-provenance/wrong-version, or missing credentials) when
|
|
839
|
+
* the provider isn't usable. Without `--skip-checks`, `chroxy start`'s
|
|
840
|
+
* doctor pass (server-cmd.js) catches the same class of failure first and
|
|
841
|
+
* refuses with a readable one-line message before any server state exists.
|
|
842
|
+
* `--skip-checks` reaches this point instead. `restoreState()` (called just
|
|
843
|
+
* before this) already keeps the daemon running when a RESTORED session fails
|
|
844
|
+
* to come back (it catches any restore failure, broader than this guard), so
|
|
845
|
+
* one broken provider does not take the whole process down. This does the
|
|
846
|
+
* same, more narrowly, for the startup default session: log the same readable message and
|
|
847
|
+
* keep starting with no default session, rather than letting an uncaught
|
|
848
|
+
* exception kill a daemon that (a) may serve other, working providers per
|
|
849
|
+
* session and (b) is often the only way to reach this machine remotely to
|
|
850
|
+
* fix the credential/binary problem in the first place.
|
|
851
|
+
*
|
|
852
|
+
* The returned `defaultSessionId` may be `null` — `ws-server.js` already
|
|
853
|
+
* coalesces that (`this.defaultSessionId = defaultSessionId || null`) and
|
|
854
|
+
* every client (dashboard's WelcomeScreen, the app's "No active sessions"
|
|
855
|
+
* states) already renders a clean zero-session state.
|
|
856
|
+
*
|
|
857
|
+
* Anything NOT one of the typed preflight errors is an unexpected failure
|
|
858
|
+
* and must still surface (uncaught), same as before this guard existed.
|
|
859
|
+
*
|
|
860
|
+
* @param {{ sessionManager: SessionManager, defaultSessionId: string|null, logger?: { warn: Function } }} args
|
|
861
|
+
* @returns {string|null}
|
|
862
|
+
*/
|
|
863
|
+
export function createDefaultSessionIfNeeded({ sessionManager, defaultSessionId, logger = log }) {
|
|
864
|
+
if (defaultSessionId) return defaultSessionId
|
|
865
|
+
try {
|
|
866
|
+
return sessionManager.createSession({ name: 'Default' })
|
|
867
|
+
} catch (err) {
|
|
868
|
+
if (!isProviderPreflightError(err)) throw err
|
|
869
|
+
logger.warn(`✗ default session [${err.code}]: ${err.message}`)
|
|
870
|
+
logger.warn('Starting with no default session — fix the provider (see the message above) and create a session from the app or dashboard, or restart once resolved.')
|
|
871
|
+
return null
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
544
875
|
export async function startCliServer(config) {
|
|
876
|
+
applyCodexBinaryConfig(config)
|
|
545
877
|
// Enable JSON log format if configured
|
|
546
878
|
if (config.logFormat === 'json') {
|
|
547
879
|
setJsonMode(true)
|
|
@@ -549,6 +881,9 @@ export async function startCliServer(config) {
|
|
|
549
881
|
|
|
550
882
|
const fileLogging = initFileLoggingFromConfig(config)
|
|
551
883
|
|
|
884
|
+
// #8270: say so once at startup when the claude data-dir override is unusable.
|
|
885
|
+
warnIfClaudeConfigDirUnusable()
|
|
886
|
+
|
|
552
887
|
// #7162: under a service manager (CHROXY_DAEMON=1) the console streams are
|
|
553
888
|
// captured to files nothing rotates (launchd StandardOutPath et al); the
|
|
554
889
|
// logger's console mirror is how the stdout capture reached 32MB in a
|
|
@@ -570,6 +905,40 @@ export async function startCliServer(config) {
|
|
|
570
905
|
// $CHROXY_HOST_VERSION / _GIT_SHA / _CHANNEL to confirm the exact running build.
|
|
571
906
|
Object.assign(process.env, getChroxyHostEnv())
|
|
572
907
|
|
|
908
|
+
// #8151 (C3) — probe once, before the WS server can accept any real
|
|
909
|
+
// connection, so the very first `list_providers` / `auth_bootstrap` a
|
|
910
|
+
// client sees already reflects reality (claude-tui greyed out when
|
|
911
|
+
// node-pty can't load here, e.g. the official Docker image). Cheap either
|
|
912
|
+
// way (a failed resolution is a fast ENOENT-class failure) and cached for
|
|
913
|
+
// the rest of the process by node-pty-probe.js.
|
|
914
|
+
await probeNodePtyAvailable()
|
|
915
|
+
|
|
916
|
+
// #7240 — state stranded at ~/.chroxy by a CHROXY_CONFIG_DIR relocation.
|
|
917
|
+
//
|
|
918
|
+
// This runs HERE, near the top of startCliServer, and the placement is the
|
|
919
|
+
// point. #7052 logs the resolved root, but that line sits ~500 lines further
|
|
920
|
+
// down — past the `No API token configured` exit below. In the sharpest
|
|
921
|
+
// failure (stranded config.json on a keychain-less host) the daemon exits
|
|
922
|
+
// before it ever says which root it opened, so the operator sees a token
|
|
923
|
+
// error with no hint that a relocation caused it. Warning first is what makes
|
|
924
|
+
// the diagnosis reachable.
|
|
925
|
+
//
|
|
926
|
+
// Detection only — the copy is opt-in via `chroxy config-dir migrate`.
|
|
927
|
+
// Best-effort, like maybeEncryptCredentialsAtRest: never blocks boot.
|
|
928
|
+
//
|
|
929
|
+
// #7244 — an operator running a deliberate second root can acknowledge the
|
|
930
|
+
// CURRENT set with `chroxy config-dir ack`. Only the warning is filtered:
|
|
931
|
+
// `strandedState` stays the raw detection, so the missing-token exit below
|
|
932
|
+
// still names an unmoved config.json even when it was acknowledged. An entry
|
|
933
|
+
// that appears after the acknowledgement is not in the snapshot and warns.
|
|
934
|
+
let strandedState = null
|
|
935
|
+
try {
|
|
936
|
+
strandedState = detectStrandedState()
|
|
937
|
+
for (const line of startupStrandedWarning(strandedState)) log.warn(line)
|
|
938
|
+
} catch (err) {
|
|
939
|
+
log.warn(`Stranded config-dir state check failed: ${err.message}`)
|
|
940
|
+
}
|
|
941
|
+
|
|
573
942
|
const PORT = config.port || parseInt(process.env.PORT || '8765', 10)
|
|
574
943
|
const NO_AUTH = !!config.noAuth
|
|
575
944
|
|
|
@@ -578,7 +947,7 @@ export async function startCliServer(config) {
|
|
|
578
947
|
|
|
579
948
|
// Migrate plaintext token to keychain and remove from config file
|
|
580
949
|
if (!NO_AUTH && config.apiToken && isKeychainAvailable()) {
|
|
581
|
-
const configFile =
|
|
950
|
+
const configFile = configPath('config.json')
|
|
582
951
|
const { migrated } = migrateToken(config)
|
|
583
952
|
// Remove plaintext token from config file (whether newly migrated or already in keychain)
|
|
584
953
|
const keychainToken = getToken()
|
|
@@ -601,7 +970,12 @@ export async function startCliServer(config) {
|
|
|
601
970
|
}
|
|
602
971
|
|
|
603
972
|
if (!NO_AUTH && !API_TOKEN) {
|
|
604
|
-
|
|
973
|
+
// #7240 — when config.json is sitting at ~/.chroxy and the daemon is reading
|
|
974
|
+
// a relocated root, `chroxy init` is the WRONG advice: it mints a brand new
|
|
975
|
+
// token and forces every paired device to re-pair. Name the real cause.
|
|
976
|
+
// The wording lives in missingTokenAdvice so a test can pin it; an
|
|
977
|
+
// acknowledgement (#7244) does not change it.
|
|
978
|
+
for (const line of missingTokenAdvice(strandedState)) console.error(line) // intentional user-facing output
|
|
605
979
|
process.exit(1)
|
|
606
980
|
}
|
|
607
981
|
|
|
@@ -614,7 +988,12 @@ export async function startCliServer(config) {
|
|
|
614
988
|
log.warn(`Credentials at-rest encryption check failed: ${err.message}`)
|
|
615
989
|
}
|
|
616
990
|
|
|
617
|
-
|
|
991
|
+
// #8189: pass the daemon's actually-resolved default through the shared
|
|
992
|
+
// helper rather than the raw `config.provider` field — `buildServerBanner`
|
|
993
|
+
// itself still floors to DEFAULT_PROVIDER internally (its own unit tests
|
|
994
|
+
// call it directly with no provider at all), so this is belt-and-suspenders
|
|
995
|
+
// against the two ever drifting apart, not a behavior change today.
|
|
996
|
+
const banner = buildServerBanner({ version: SERVER_VERSION, provider: resolveDaemonDefaultProvider(config) })
|
|
618
997
|
const pad = Math.max(0, 38 - banner.length)
|
|
619
998
|
const left = Math.floor(pad / 2)
|
|
620
999
|
const right = pad - left
|
|
@@ -654,8 +1033,13 @@ export async function startCliServer(config) {
|
|
|
654
1033
|
// talks chat-completions via the Anthropic↔OpenAI shim. Registered right
|
|
655
1034
|
// after the Anthropic-compatible block (collision-checked against it).
|
|
656
1035
|
registerOpenAiCompatibleProviders(config)
|
|
1036
|
+
// #7319: register config-driven ACP (Agent Client Protocol) agents from
|
|
1037
|
+
// `providers.acp` — one registered provider per configured agent, spawned
|
|
1038
|
+
// over stdio. Permissions ship denied-by-default (#7320 wires the real
|
|
1039
|
+
// bridge). Collision-checked against every provider registered above.
|
|
1040
|
+
registerAcpProviders(config)
|
|
657
1041
|
|
|
658
|
-
const providerType = config
|
|
1042
|
+
const providerType = resolveDaemonDefaultProvider(config)
|
|
659
1043
|
|
|
660
1044
|
// Warm the models registry from disk cache so the picker is populated before
|
|
661
1045
|
// any SDK session fires supportedModels(). Routed through the ACTIVE provider's
|
|
@@ -753,14 +1137,40 @@ export async function startCliServer(config) {
|
|
|
753
1137
|
// a single warning here at boot (not three on each tunable).
|
|
754
1138
|
const startupTimeouts = resolveStartupTimeouts(config, log)
|
|
755
1139
|
|
|
1140
|
+
// #7601: wire the proactive container-liveness poll's inspect seam. A dedicated
|
|
1141
|
+
// DockerBackend (a stateless docker-CLI wrapper — same shape server-cli already
|
|
1142
|
+
// constructs for the compose sweep above) inspects each live containerized
|
|
1143
|
+
// session's container; `inspectContainerLiveness` classifies a rejection so a
|
|
1144
|
+
// Docker-daemon outage can't false-surface a vanish across every session at
|
|
1145
|
+
// once. Safe to wire unconditionally: the poll is a no-op when no containerized
|
|
1146
|
+
// session exists, and docker-cli/docker-sdk sessions can be created even with
|
|
1147
|
+
// the container-environments feature off.
|
|
1148
|
+
const { DockerBackend: LivenessDockerBackend } = await import('./environments/backends/docker.js')
|
|
1149
|
+
const { inspectContainerLiveness } = await import('./docker-session.js')
|
|
1150
|
+
const livenessBackend = new LivenessDockerBackend()
|
|
1151
|
+
const containerInspect = (containerId) =>
|
|
1152
|
+
inspectContainerLiveness((cid) => livenessBackend.getEnvironmentStatus(cid), containerId)
|
|
1153
|
+
|
|
756
1154
|
// 1. Create session manager
|
|
757
|
-
|
|
1155
|
+
// (#8967 — registered right after construction below, so a live Claude model
|
|
1156
|
+
// refresh keeps a row a running session is still on instead of dropping it.)
|
|
1157
|
+
const { sessionManager, startupSkillPolicy } = createDaemonSessionManager(config, {
|
|
758
1158
|
maxSessions: config.maxSessions || 5,
|
|
759
1159
|
port: PORT,
|
|
760
1160
|
apiToken: API_TOKEN,
|
|
761
1161
|
defaultCwd: config.cwd || (isWithinHome(process.cwd()) ? process.cwd() : homedir()),
|
|
762
1162
|
defaultModel: config.model || null,
|
|
763
1163
|
defaultPermissionMode: 'approve',
|
|
1164
|
+
// #7552: so a session created with an `environmentId` is TAGGED onto that
|
|
1165
|
+
// environment for its lifetime (and untagged on teardown). Null when
|
|
1166
|
+
// container environments are off — the block above only constructs one when
|
|
1167
|
+
// the feature is enabled — and every use inside SessionManager is
|
|
1168
|
+
// optional-chained. Ordering matters and already holds: the manager is
|
|
1169
|
+
// constructed AND `reconnect()`ed (which clears every stale session tag from
|
|
1170
|
+
// the previous process) above, before this line runs.
|
|
1171
|
+
environmentManager,
|
|
1172
|
+
// #7601: the proactive container-liveness poll inspect seam (see above).
|
|
1173
|
+
containerInspect,
|
|
764
1174
|
// #5859 (audit P1-7): reclaim orphaned chroxy session worktrees at boot when
|
|
765
1175
|
// the operator opted into worktree auto-reaping. Clean-tree-guarded.
|
|
766
1176
|
sweepOrphanWorktrees: config.worktreeGc?.autoReap === true,
|
|
@@ -787,6 +1197,7 @@ export async function startCliServer(config) {
|
|
|
787
1197
|
binaryProvenanceMode: resolveBinaryProvenanceMode(config),
|
|
788
1198
|
binarySignatureGate: isBinarySignatureGateEnabled(config),
|
|
789
1199
|
providerType,
|
|
1200
|
+
agentConnections: config.agentConnections || [],
|
|
790
1201
|
maxToolInput: config.maxToolInput || null,
|
|
791
1202
|
transforms: config.transforms || [],
|
|
792
1203
|
sessionTimeout: config.sessionTimeout || null,
|
|
@@ -794,6 +1205,9 @@ export async function startCliServer(config) {
|
|
|
794
1205
|
costBudget: config.costBudget || null,
|
|
795
1206
|
// #5665: monthly programmatic-credit budget meter config.
|
|
796
1207
|
billing: config.billing || null,
|
|
1208
|
+
// Session archive retention (`sessionArchive` config block); the archive
|
|
1209
|
+
// directory itself sits next to the session-state file.
|
|
1210
|
+
sessionArchive: config.sessionArchive || null,
|
|
797
1211
|
maxMessages: config.maxMessages || config.maxHistory || null,
|
|
798
1212
|
// #6764: opt-in semantic session titles. Off unless the operator set
|
|
799
1213
|
// features.semanticTitles:true (or CHROXY_SEMANTIC_TITLES=1). The title model
|
|
@@ -836,10 +1250,10 @@ export async function startCliServer(config) {
|
|
|
836
1250
|
// over-24h operator value falls back to null here so byok-mcp-client
|
|
837
1251
|
// applies its default (and the operator gets a warn log).
|
|
838
1252
|
mcpToolCallTimeoutMs: startupTimeouts.mcpToolCallTimeoutMs,
|
|
839
|
-
// Skills size budgets (#3202). null = use loader defaults (32KB / 256KB).
|
|
840
|
-
maxSkillBytes: Number.isFinite(config.maxSkillBytes) ? config.maxSkillBytes : null,
|
|
841
|
-
maxTotalSkillBytes: Number.isFinite(config.maxTotalSkillBytes) ? config.maxTotalSkillBytes : null,
|
|
842
1253
|
})
|
|
1254
|
+
// #8303: a blank New Session cwd inherits this without the explicit-cwd check.
|
|
1255
|
+
const defaultCwdWarning = defaultCwdAdvisory(sessionManager.defaultCwd, config)
|
|
1256
|
+
if (defaultCwdWarning) log.warn(defaultCwdWarning)
|
|
843
1257
|
|
|
844
1258
|
// #3749 / #3899: surface the effective inactivity timeouts at startup so
|
|
845
1259
|
// operators can verify their config overrides took effect.
|
|
@@ -852,6 +1266,9 @@ export async function startCliServer(config) {
|
|
|
852
1266
|
? 'disabled'
|
|
853
1267
|
: `${formatIdleDuration(effectiveStreamStallTimeoutMs)} (${effectiveStreamStallTimeoutMs}ms)`
|
|
854
1268
|
log.info(`Inactivity soft-warning: ${formatIdleDuration(effectiveResultTimeoutMs)} (${effectiveResultTimeoutMs}ms); hard-cap: ${formatIdleDuration(effectiveHardTimeoutMs)} (${effectiveHardTimeoutMs}ms); stream-stall: ${stallLabel}`)
|
|
1269
|
+
log.info(formatStartupSkillPolicyDiagnostic(startupSkillPolicy.diagnostics))
|
|
1270
|
+
|
|
1271
|
+
setInUseModelsProvider(() => sessionManager.listSessions().map((s) => s.model).filter(Boolean))
|
|
855
1272
|
|
|
856
1273
|
// 2. Try restoring session state from a previous instance
|
|
857
1274
|
let defaultSessionId
|
|
@@ -861,9 +1278,7 @@ export async function startCliServer(config) {
|
|
|
861
1278
|
}
|
|
862
1279
|
|
|
863
1280
|
// 3. Create default session if no restore
|
|
864
|
-
|
|
865
|
-
defaultSessionId = sessionManager.createSession({ name: 'Default' })
|
|
866
|
-
}
|
|
1281
|
+
defaultSessionId = createDefaultSessionIfNeeded({ sessionManager, defaultSessionId, logger: log })
|
|
867
1282
|
|
|
868
1283
|
let wsServer
|
|
869
1284
|
|
|
@@ -951,10 +1366,10 @@ export async function startCliServer(config) {
|
|
|
951
1366
|
|
|
952
1367
|
// 3. Create push notification manager, token manager, and WebSocket server
|
|
953
1368
|
const pushManager = new PushManager({
|
|
954
|
-
storagePath:
|
|
1369
|
+
storagePath: configPath('push-tokens.json'),
|
|
955
1370
|
// #4541: notification preferences persistence. Co-located in
|
|
956
1371
|
// ~/.chroxy alongside push-tokens.json so cleanup is one step.
|
|
957
|
-
prefsPath:
|
|
1372
|
+
prefsPath: configPath('notification-prefs.json'),
|
|
958
1373
|
// #5413 Phase 2: Discord status-embed sink. Off by default — only
|
|
959
1374
|
// active when a webhook URL resolves from CHROXY_DISCORD_WEBHOOK_URL
|
|
960
1375
|
// or ~/.chroxy/credentials.json (0600). Non-secret knobs (bot name,
|
|
@@ -963,10 +1378,10 @@ export async function startCliServer(config) {
|
|
|
963
1378
|
// (message ids, current state) persists alongside the other
|
|
964
1379
|
// notification state in ~/.chroxy.
|
|
965
1380
|
discord: {
|
|
966
|
-
statePath:
|
|
1381
|
+
statePath: configPath('discord-webhook-state.json'),
|
|
967
1382
|
// #5828: the billing-alert sink keeps its own state file, separate from
|
|
968
1383
|
// the per-project status store above.
|
|
969
|
-
billingStatePath:
|
|
1384
|
+
billingStatePath: configPath('discord-billing-state.json'),
|
|
970
1385
|
...(config.notifications?.discord || {}),
|
|
971
1386
|
},
|
|
972
1387
|
})
|
|
@@ -990,7 +1405,7 @@ export async function startCliServer(config) {
|
|
|
990
1405
|
})
|
|
991
1406
|
pushNotificationHandler.start()
|
|
992
1407
|
|
|
993
|
-
const configFile =
|
|
1408
|
+
const configFile = configPath('config.json')
|
|
994
1409
|
const tokenManager = NO_AUTH ? null : new TokenManager({
|
|
995
1410
|
token: API_TOKEN,
|
|
996
1411
|
tokenExpiry: config.tokenExpiry || null,
|
|
@@ -1090,7 +1505,13 @@ export async function startCliServer(config) {
|
|
|
1090
1505
|
)
|
|
1091
1506
|
// #6598 — persist paired tokens across restarts (encrypted at rest). Honour a
|
|
1092
1507
|
// CHROXY_CONFIG_DIR override so it sits next to config.json / credentials.json.
|
|
1093
|
-
const chroxyDir =
|
|
1508
|
+
const chroxyDir = configDir()
|
|
1509
|
+
// #7052 — state the resolved root once at startup. Every persistent path the
|
|
1510
|
+
// daemon touches now hangs off it, so when an operator relocates the dir and
|
|
1511
|
+
// finds empty trust stores or a missing token, this line is the one thing
|
|
1512
|
+
// that tells them WHICH root the daemon actually opened. Logged
|
|
1513
|
+
// unconditionally: knowing it is `~/.chroxy` is exactly as useful.
|
|
1514
|
+
log.info(`Config/state root: ${chroxyDir}${process.env.CHROXY_CONFIG_DIR ? ' (from CHROXY_CONFIG_DIR)' : ''}`)
|
|
1094
1515
|
const pairingManager = NO_AUTH ? null : new PairingManager({
|
|
1095
1516
|
ttlMs: 60_000,
|
|
1096
1517
|
autoRefresh: true,
|
|
@@ -1109,6 +1530,38 @@ export async function startCliServer(config) {
|
|
|
1109
1530
|
// no timers and spawns nothing.
|
|
1110
1531
|
const schedulerEngine = buildSchedulerEngine({ sessionManager, config, logger: log })
|
|
1111
1532
|
|
|
1533
|
+
// #7424 (step 3 of #7344): watch the PR each session opened and announce a CI
|
|
1534
|
+
// run the moment it SETTLES, to both audiences — a `ci_complete` push for the
|
|
1535
|
+
// user's phone, and one typed line into the session's own prompt so the agent
|
|
1536
|
+
// learns it without spending a turn (and a full cached-context re-read)
|
|
1537
|
+
// polling `gh pr checks`.
|
|
1538
|
+
//
|
|
1539
|
+
// ON by default; `sessionCi.watch: false` returns null here. Everything
|
|
1540
|
+
// decidable lives in buildSessionCiWatcher so it is unit-tested rather than
|
|
1541
|
+
// source-grepped.
|
|
1542
|
+
//
|
|
1543
|
+
// Built BEFORE the WsServer (#7427) because the ws handler ctx carries it: the
|
|
1544
|
+
// dashboard's on-demand `session_pr_status_request` survey hands its snapshot
|
|
1545
|
+
// to `observe()`, which ARMS the watch without waiting on the sweep's
|
|
1546
|
+
// five-minute discovery pass.
|
|
1547
|
+
const sessionCiWatcher = buildSessionCiWatcher({ config, sessionManager, pushManager, logger: log })
|
|
1548
|
+
sessionCiWatcher?.start()
|
|
1549
|
+
|
|
1550
|
+
// #8331: the daily-daemon "update ready" banner. Watches the files the idle-only
|
|
1551
|
+
// auto-deploy script leaves in the config dir and answers the dashboard's
|
|
1552
|
+
// Restart now / Postpone. The idle verdict is the SAME function
|
|
1553
|
+
// GET /api/daemon/idle answers from, so the confirm dialog and the script's own
|
|
1554
|
+
// gate cannot disagree. Harmless on a daemon with no deploy script: with no
|
|
1555
|
+
// files there is nothing to report and nothing to act on.
|
|
1556
|
+
const daemonUpdate = new DaemonUpdateStatus({
|
|
1557
|
+
dir: chroxyDir,
|
|
1558
|
+
getIdleState: () => computeDaemonIdleState({
|
|
1559
|
+
sessionManager,
|
|
1560
|
+
getHookPendingPermissionCount: () => wsServer.getHookPendingPermissionCount(),
|
|
1561
|
+
}),
|
|
1562
|
+
})
|
|
1563
|
+
daemonUpdate.start()
|
|
1564
|
+
|
|
1112
1565
|
wsServer = new WsServer({
|
|
1113
1566
|
port: PORT,
|
|
1114
1567
|
apiToken: API_TOKEN,
|
|
@@ -1117,6 +1570,11 @@ export async function startCliServer(config) {
|
|
|
1117
1570
|
// #6871: nullable — null whenever the scheduled-execution gate is closed (the
|
|
1118
1571
|
// default). The scheduled-tasks handlers report that as "not armed".
|
|
1119
1572
|
schedulerEngine,
|
|
1573
|
+
// #7427: nullable — null when `sessionCi.watch` is off. Handed to handlers
|
|
1574
|
+
// only; server-cli owns its start() above and ServerOrchestrator its stop().
|
|
1575
|
+
sessionCiWatcher,
|
|
1576
|
+
// #8331: closed by wsServer.close().
|
|
1577
|
+
daemonUpdate,
|
|
1120
1578
|
defaultSessionId,
|
|
1121
1579
|
authRequired: !NO_AUTH,
|
|
1122
1580
|
pushManager,
|
|
@@ -1167,13 +1625,24 @@ export async function startCliServer(config) {
|
|
|
1167
1625
|
// #5932: hot-reload the ~/.chroxy/models.json overlay on edit — surfacing a
|
|
1168
1626
|
// new model id (or a label/contextWindow/pricing override) is "a config entry,
|
|
1169
1627
|
// not a code change", so it must not require a daemon restart. On a successful
|
|
1170
|
-
// reload, re-broadcast `available_models` for
|
|
1171
|
-
//
|
|
1628
|
+
// reload, re-broadcast `available_models` for every registry the overlay
|
|
1629
|
+
// CHANGED — the default (Claude) one plus each provider-tagged slice (#7722)
|
|
1630
|
+
// — routed so each client only ever receives the roster for the provider its
|
|
1631
|
+
// active session runs on, RE-TAGGED per recipient for the default registry
|
|
1632
|
+
// (#7756) so a claude-cli/claude-tui/claude-byok client's own bucket
|
|
1633
|
+
// refreshes too. A malformed save is ignored (last-good kept).
|
|
1634
|
+
//
|
|
1635
|
+
// #7756: `defaultProvider` mirrors `billingCanaryMonitor`'s own
|
|
1636
|
+
// `getDefaultProvider` below (`resolveDaemonDefaultProvider(config)`) — the
|
|
1637
|
+
// same resolution `ws-history.js` feeds `resolveRosterProvider` via
|
|
1638
|
+
// `billingCanary.defaultProvider` — so a no-session client's roster is
|
|
1639
|
+
// tagged identically whether it arrives on connect or on a reload.
|
|
1172
1640
|
const modelsOverlayWatcher = watchModelsOverlay({
|
|
1173
|
-
onReload: ({
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1641
|
+
onReload: createOverlayReloadBroadcaster({
|
|
1642
|
+
wsServer,
|
|
1643
|
+
sessionManager,
|
|
1644
|
+
defaultProvider: resolveDaemonDefaultProvider(config),
|
|
1645
|
+
}),
|
|
1177
1646
|
})
|
|
1178
1647
|
|
|
1179
1648
|
// #5821 (live wiring): the billing canary. Recomputes the daemon's billing
|
|
@@ -1193,8 +1662,8 @@ export async function startCliServer(config) {
|
|
|
1193
1662
|
const egressCheckEnabled = config.billing?.egressCheck === true
|
|
1194
1663
|
const billingCanaryMonitor = new BillingCanaryMonitor({
|
|
1195
1664
|
getSessions: () => sessionManager.listSessions(),
|
|
1196
|
-
getDefaultProvider: () => config
|
|
1197
|
-
getApiKeyAuth: () => (config
|
|
1665
|
+
getDefaultProvider: () => resolveDaemonDefaultProvider(config),
|
|
1666
|
+
getApiKeyAuth: () => resolveDaemonDefaultProvider(config) === 'claude-sdk' && Boolean(process.env.ANTHROPIC_API_KEY),
|
|
1198
1667
|
broadcast: (msg) => { try { wsServer?.broadcast(msg) } catch { /* best-effort */ } },
|
|
1199
1668
|
logger: log,
|
|
1200
1669
|
resolveEgressIp: egressCheckEnabled ? () => resolvePublicIp() : undefined,
|
|
@@ -1245,6 +1714,10 @@ export async function startCliServer(config) {
|
|
|
1245
1714
|
// Wire session timeout to WsServer viewer checks
|
|
1246
1715
|
sessionManager.setActiveViewersFn((sid) => wsServer.hasActiveViewersForSession(sid))
|
|
1247
1716
|
sessionManager.startSessionTimeouts()
|
|
1717
|
+
// #7601: begin the proactive container-liveness poll (no-op when no
|
|
1718
|
+
// containerInspect seam was wired). Surfaces CONTAINER_VANISHED on an idle
|
|
1719
|
+
// containerized session whose container was stopped/removed externally.
|
|
1720
|
+
sessionManager.startContainerLiveness()
|
|
1248
1721
|
|
|
1249
1722
|
// Advertise via mDNS/Bonjour for local network discovery. Suppressed on a
|
|
1250
1723
|
// loopback bind and when auth is off — see maybeAdvertiseMdns (#5280).
|
|
@@ -1384,14 +1857,25 @@ export async function startCliServer(config) {
|
|
|
1384
1857
|
.catch((err) => log.warn(`worktree auto-reaper failed: ${(err && err.message) || err}`))
|
|
1385
1858
|
}
|
|
1386
1859
|
|
|
1387
|
-
// #
|
|
1388
|
-
//
|
|
1389
|
-
//
|
|
1390
|
-
//
|
|
1391
|
-
//
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1860
|
+
// #7606: orphaned-child reaper — sends SIGKILL to processes a dead session
|
|
1861
|
+
// left behind, reparented to pid 1 inside chroxy's own worktree root (ppid 1
|
|
1862
|
+
// + this uid + cwd under the root + older than minAgeMs). Default ON; the
|
|
1863
|
+
// sweep is a no-op on Windows. Same lazy-import / getter-at-shutdown shape
|
|
1864
|
+
// as the worktree reaper above.
|
|
1865
|
+
let orphanReapTimer = null
|
|
1866
|
+
if (config.orphanReap?.enabled !== false) {
|
|
1867
|
+
import('./orphan-reaper.js')
|
|
1868
|
+
.then(({ startPeriodicOrphanReap }) => { orphanReapTimer = startPeriodicOrphanReap(config, log) })
|
|
1869
|
+
.catch((err) => log.warn(`orphan-reaper failed: ${(err && err.message) || err}`))
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
// #7374 — every provider's stale per-session dirs (claude-tui, claude-cli,
|
|
1873
|
+
// codex app-server, docker-byok — #8047). The body lives in its own module
|
|
1874
|
+
// so the sweep is covered by tests that RUN it; this block used to be
|
|
1875
|
+
// inline and was pinned only by a source grep, which stayed green with the
|
|
1876
|
+
// whole thing behind a false condition. Fire-and-forget: the function never
|
|
1877
|
+
// rejects, and a sweep must never affect startup.
|
|
1878
|
+
sweepStaleProviderDirs(log)
|
|
1395
1879
|
|
|
1396
1880
|
console.log('\nPress Ctrl+C to stop.\n')
|
|
1397
1881
|
|
|
@@ -1418,10 +1902,12 @@ export async function startCliServer(config) {
|
|
|
1418
1902
|
pairingManager,
|
|
1419
1903
|
pushManager,
|
|
1420
1904
|
billingCanaryMonitor,
|
|
1905
|
+
sessionCiWatcher,
|
|
1421
1906
|
orchestrationManager,
|
|
1422
1907
|
schedulerEngine,
|
|
1423
1908
|
modelsOverlayWatcher,
|
|
1424
1909
|
getWorktreeReapTimer: () => worktreeReapTimer,
|
|
1910
|
+
getOrphanReapTimer: () => orphanReapTimer,
|
|
1425
1911
|
emergencyCleanupSync,
|
|
1426
1912
|
removeConnectionInfo,
|
|
1427
1913
|
isPoolEnabled,
|