@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/config.js
CHANGED
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { readFileSync, existsSync, mkdirSync, copyFileSync, constants as fsConstants } from 'fs'
|
|
12
12
|
import { createHash } from 'crypto'
|
|
13
|
-
import {
|
|
14
|
-
import { homedir } from 'os'
|
|
13
|
+
import { dirname } from 'path'
|
|
15
14
|
import { writeFileRestricted } from './platform.js'
|
|
16
15
|
import { parseDuration } from './duration.js'
|
|
17
16
|
import { createLogger } from './logger.js'
|
|
@@ -19,10 +18,19 @@ import { createLogger } from './logger.js'
|
|
|
19
18
|
// deliberately a dependency-free module so importing it here never pulls
|
|
20
19
|
// the BYOK/SDK machinery into the config-load path.
|
|
21
20
|
import { validateProvidersConfigBlock } from './anthropic-compatible-config.js'
|
|
21
|
+
// #7319: pure validation helpers for `providers.acp` — same dependency-free
|
|
22
|
+
// rationale (no spawn/ACP-SDK machinery in the config-load path). Called
|
|
23
|
+
// directly here (not from validateProvidersConfigBlock) to avoid a circular
|
|
24
|
+
// import — acp-config.js already imports RESERVED_PROVIDER_IDS from
|
|
25
|
+
// anthropic-compatible-config.js.
|
|
26
|
+
import { validateAcpProviders } from './acp-config.js'
|
|
22
27
|
// #6764: default cheap model + timeout for the one-shot semantic-title call.
|
|
23
28
|
// Imported from the pure title module (no provider/SDK deps) so config load stays
|
|
24
29
|
// lightweight.
|
|
25
30
|
import { DEFAULT_SEMANTIC_TITLE_MODEL, DEFAULT_SEMANTIC_TITLE_TIMEOUT_MS } from './session-title.js'
|
|
31
|
+
import { configPath } from './config-dir.js'
|
|
32
|
+
import { SESSION_ARCHIVE_MAX_ENTRIES } from './session-archive-limits.js'
|
|
33
|
+
import { validateAgentConnections } from './agent-connections.js'
|
|
26
34
|
|
|
27
35
|
const log = createLogger('config')
|
|
28
36
|
|
|
@@ -82,6 +90,10 @@ const CONFIG_SCHEMA = {
|
|
|
82
90
|
// name an env var (`apiKeyEnv`) or a ~/.chroxy/credentials.json
|
|
83
91
|
// field (`credentialsKey`).
|
|
84
92
|
providers: 'array|object',
|
|
93
|
+
// Explicit host-scoped agent access routes. Entries contain only stable
|
|
94
|
+
// identifiers and credential references; raw credentials are rejected by
|
|
95
|
+
// the connection validator and remain in env/native/vendor stores.
|
|
96
|
+
agentConnections: 'array',
|
|
85
97
|
// #5547: optional override for the one-shot session summarizer (the sidebar
|
|
86
98
|
// "Summarize & start new session" action). `{ provider?: string, model?:
|
|
87
99
|
// string }` — when set, the summarizer uses this (typically cheaper) model
|
|
@@ -150,6 +162,10 @@ const CONFIG_SCHEMA = {
|
|
|
150
162
|
// runs with a GUI/launchd PATH that misses npm globals. Mirrored by the
|
|
151
163
|
// CHROXY_REPO_MEMORY_BIN env var.
|
|
152
164
|
controlRoomRepoMemoryBin: 'string',
|
|
165
|
+
// #8609: explicit path of the codex client the codex provider launches
|
|
166
|
+
// (instead of the first `codex` on PATH). Mirrored by CHROXY_CODEX_BIN, which
|
|
167
|
+
// is what CodexSession.resolvedBinary reads — see applyCodexBinaryConfig.
|
|
168
|
+
codexBinary: 'string',
|
|
153
169
|
maxSessions: 'number',
|
|
154
170
|
maxHistory: 'number',
|
|
155
171
|
maxMessages: 'number',
|
|
@@ -170,11 +186,39 @@ const CONFIG_SCHEMA = {
|
|
|
170
186
|
// discord-credentials.js. Documented in CONFIG.md +
|
|
171
187
|
// docs/guides/discord-notifications.md.
|
|
172
188
|
notifications: 'object',
|
|
173
|
-
// #5158: worktree garbage-collection. `{ autoReap
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
//
|
|
189
|
+
// #5158: worktree garbage-collection. `{ autoReap?: boolean, reapIntervalMs?:
|
|
190
|
+
// number, maxLockAgeMs?: number }` — when `autoReap` is true, the server
|
|
191
|
+
// reclaims orphaned, dead-pid-locked agent worktrees on startup and then
|
|
192
|
+
// every `reapIntervalMs` (clean trees only, never --force); `maxLockAgeMs` is
|
|
193
|
+
// the absolute-age fallback for the PID-liveness check (0 disables it).
|
|
194
|
+
// Defaults to off; the `chroxy worktree gc` CLI is always available for
|
|
195
|
+
// manual/dry-run use.
|
|
177
196
|
worktreeGc: 'object',
|
|
197
|
+
// #7606: orphaned-child reaper. `{ enabled?: boolean, sweepIntervalMs?:
|
|
198
|
+
// number, minAgeMs?: number }` — the daemon periodically SIGKILLs processes
|
|
199
|
+
// that are reparented to pid 1, owned by this uid, older than `minAgeMs`
|
|
200
|
+
// (default 10 min) and whose cwd is inside chroxy's own session-worktree
|
|
201
|
+
// root — work a dead session left behind. `enabled` defaults ON; sweeps
|
|
202
|
+
// every `sweepIntervalMs` (default 5 min). POSIX only.
|
|
203
|
+
orphanReap: 'object',
|
|
204
|
+
// Session archive: the chroxy-held history of a session that leaves the live
|
|
205
|
+
// set (closed, idle-timed-out, stale at boot, dismissed/expired failed
|
|
206
|
+
// restore) is kept as a compressed, read-only record so a Codex / Gemini /
|
|
207
|
+
// BYOK session's content is not lost. `{ enabled?: boolean, maxEntries?:
|
|
208
|
+
// number, maxAgeDays?: number, maxMegabytes?: number }` — defaults ON, 100
|
|
209
|
+
// entries, 30 days, 256 MiB; the oldest records are deleted first.
|
|
210
|
+
sessionArchive: 'object',
|
|
211
|
+
// #7424: the session CI-completion watcher. `{ watch?: boolean, wakeAgent?:
|
|
212
|
+
// boolean, intervalMs?: number, discoveryIntervalMs?: number,
|
|
213
|
+
// maxSurveysPerTick?: number }` (#7436 added the per-tick cap). `watch`
|
|
214
|
+
// defaults ON — the daemon periodically surveys each session's PR through the
|
|
215
|
+
// user's own `gh` and, when a run settles, notifies (`ci_complete`) and wakes
|
|
216
|
+
// the agent with one daemon-authored line: typed into a claude-tui prompt, or
|
|
217
|
+
// delivered as a user turn (queued when busy) to a provider that declares
|
|
218
|
+
// `capabilities.daemonTurnInput` — claude-sdk included (#8301). Set
|
|
219
|
+
// `watch: false` on a host that should make no background GitHub calls;
|
|
220
|
+
// `wakeAgent: false` keeps the notification but never wakes a session.
|
|
221
|
+
sessionCi: 'object',
|
|
178
222
|
sandbox: 'object',
|
|
179
223
|
// Optional allowlist of absolute directory paths that sessions may use
|
|
180
224
|
// as their working directory. When set (non-empty array), session
|
|
@@ -195,7 +239,8 @@ const CONFIG_SCHEMA = {
|
|
|
195
239
|
// #5985 (epic #5982): gate for the embedded user-shell terminal — a
|
|
196
240
|
// `user-shell` session spawns the operator's `$SHELL` (arbitrary code
|
|
197
241
|
// execution on the dev machine, reachable through the tunnel). Nested object
|
|
198
|
-
// `{ enabled
|
|
242
|
+
// `{ enabled?: boolean, requireApproval?: boolean }` (#6277 added the
|
|
243
|
+
// host-local approval gate). Defaults to undefined/false so fresh installs are
|
|
199
244
|
// secure-by-default: creating a `user-shell` session is rejected with
|
|
200
245
|
// USER_SHELL_DISABLED unless `userShell.enabled === true`. Enabling is a
|
|
201
246
|
// deliberate edit on the dev machine (physical-access proxy for confirmation),
|
|
@@ -213,7 +258,7 @@ const CONFIG_SCHEMA = {
|
|
|
213
258
|
// the 2026-04-11 audit Adversary A7 fix to close the "register any
|
|
214
259
|
// attacker-controlled image and run it" attack path.
|
|
215
260
|
allowedDockerImages: 'array',
|
|
216
|
-
// Per-session regex source string used by `
|
|
261
|
+
// Per-session regex source string used by `shouldSkipEvaluatorAsync` to extend
|
|
217
262
|
// the default continuation-pattern skip list. Wrapped in try/catch when
|
|
218
263
|
// compiled — malformed sources are logged and ignored, the default
|
|
219
264
|
// pattern still applies. Documented in CONFIG.md. Added in #3187.
|
|
@@ -506,17 +551,33 @@ function warnUnknownKeys(obj, knownSet, prefix, warnings, supportedKeys = knownS
|
|
|
506
551
|
// `workspace` sub-block (#4556); billing-budget.js + billing-canary (egressCheck
|
|
507
552
|
// / datacenterPrefixes via server-cli); worktree-reaper.js; rancher.js (the
|
|
508
553
|
// RancherBackend ctor) + resolveRancherToken (tokenEnv / tokenFile).
|
|
509
|
-
|
|
554
|
+
//
|
|
555
|
+
// #7449: these are EXPORTED solely so the doc gate
|
|
556
|
+
// (tests/config-supported-keys-docs.test.js) can compare CONFIG.md's rosters
|
|
557
|
+
// against the producer itself rather than a hand-copied expectation. Nothing
|
|
558
|
+
// in src/ imports them across module boundaries — but a re-parse of this file
|
|
559
|
+
// as text would be a second implementation of the roster, and that copy is
|
|
560
|
+
// what drifts.
|
|
561
|
+
export const K8S_SUPPORTED_KEYS = new Set([
|
|
510
562
|
'namespace', 'inCluster', 'kubeconfigPath', 'sidecarImage', 'imagePullPolicy',
|
|
511
563
|
'connectMode', 'namespaceQuota', 'namespaceLimitRange', 'workspace',
|
|
512
564
|
])
|
|
513
|
-
const BILLING_SUPPORTED_KEYS = new Set([
|
|
565
|
+
export const BILLING_SUPPORTED_KEYS = new Set([
|
|
514
566
|
'creditTier', 'monthlyCreditBudgetUsd', 'budgetWarningPercent', 'egressCheck', 'datacenterPrefixes',
|
|
515
567
|
])
|
|
516
|
-
const WORKTREE_GC_SUPPORTED_KEYS = new Set([
|
|
568
|
+
export const WORKTREE_GC_SUPPORTED_KEYS = new Set([
|
|
517
569
|
'autoReap', 'reapIntervalMs', 'maxLockAgeMs',
|
|
518
570
|
])
|
|
519
|
-
const
|
|
571
|
+
export const ORPHAN_REAP_SUPPORTED_KEYS = new Set([
|
|
572
|
+
'enabled', 'sweepIntervalMs', 'minAgeMs',
|
|
573
|
+
])
|
|
574
|
+
export const SESSION_ARCHIVE_SUPPORTED_KEYS = new Set([
|
|
575
|
+
'enabled', 'maxEntries', 'maxAgeDays', 'maxMegabytes',
|
|
576
|
+
])
|
|
577
|
+
export const SESSION_CI_SUPPORTED_KEYS = new Set([
|
|
578
|
+
'watch', 'wakeAgent', 'intervalMs', 'discoveryIntervalMs', 'maxSurveysPerTick',
|
|
579
|
+
])
|
|
580
|
+
export const RANCHER_SUPPORTED_KEYS = new Set([
|
|
520
581
|
'rancherUrl', 'clusterId', 'token', 'tokenEnv', 'tokenFile', 'caData', 'skipTLSVerify', 'defaultProjectId',
|
|
521
582
|
])
|
|
522
583
|
|
|
@@ -683,8 +744,8 @@ const MAX_DISCORD_COLOR = 16777215
|
|
|
683
744
|
// `{ ...config.notifications.discord }` spread into the sink) surfaces instead of
|
|
684
745
|
// silently no-op'ing / failing the sink closed. Keep in sync with the per-key
|
|
685
746
|
// validation below. The webhook URL is a SECRET (its own warning) — not a knob.
|
|
686
|
-
const DISCORD_SUPPORTED_KEYS = new Set([
|
|
687
|
-
'botName', 'billingAlerts', 'defaultColor', 'permissionColor', 'errorColor',
|
|
747
|
+
export const DISCORD_SUPPORTED_KEYS = new Set([
|
|
748
|
+
'botName', 'billingAlerts', 'ciAlerts', 'defaultColor', 'permissionColor', 'errorColor',
|
|
688
749
|
'colors', 'updateThrottleMs', 'heartbeatIntervalMs', 'pruneAfterMs',
|
|
689
750
|
// #5676 status-watchdog tunables — the sink reads these from the config spread
|
|
690
751
|
// (discord-webhook-sink.js: staleAfterMs/offlineAfterMs, default 10m/30m), so
|
|
@@ -768,7 +829,7 @@ function validateBillingBlock(billing, warnings) {
|
|
|
768
829
|
warnUnknownKeys(billing, BILLING_SUPPORTED_KEYS, 'billing', warnings)
|
|
769
830
|
}
|
|
770
831
|
|
|
771
|
-
const USER_SHELL_SUPPORTED_KEYS = new Set(['enabled', 'requireApproval'])
|
|
832
|
+
export const USER_SHELL_SUPPORTED_KEYS = new Set(['enabled', 'requireApproval'])
|
|
772
833
|
|
|
773
834
|
// #5985 (epic #5982): validate the `userShell` block. Only `enabled` (boolean)
|
|
774
835
|
// today; the security primitives (primary-token gate, audit, isolation) land in
|
|
@@ -800,6 +861,20 @@ function validateUserShellBlock(userShell, warnings) {
|
|
|
800
861
|
warnUnknownKeys(userShell, USER_SHELL_SUPPORTED_KEYS, 'userShell', warnings)
|
|
801
862
|
}
|
|
802
863
|
|
|
864
|
+
/**
|
|
865
|
+
* #8609: CodexSession.resolvedBinary is a static getter with no config handle,
|
|
866
|
+
* so the config-file `codexBinary` is published to CHROXY_CODEX_BIN once at
|
|
867
|
+
* startup. An env var already set wins (it is the same key merged by
|
|
868
|
+
* mergeConfig, so a file value only matters when the env is unset).
|
|
869
|
+
*/
|
|
870
|
+
// Needed beyond the env→config merge: that merge only reads the env, but the static
|
|
871
|
+
// resolvedBinary getter has no config handle, so a file value must be pushed to the env.
|
|
872
|
+
export function applyCodexBinaryConfig(config, env = process.env) {
|
|
873
|
+
const configured = typeof config?.codexBinary === 'string' ? config.codexBinary.trim() : ''
|
|
874
|
+
const current = typeof env.CHROXY_CODEX_BIN === 'string' ? env.CHROXY_CODEX_BIN.trim() : ''
|
|
875
|
+
if (configured && !current) env.CHROXY_CODEX_BIN = configured
|
|
876
|
+
}
|
|
877
|
+
|
|
803
878
|
// #5985: single source of truth for "may a user-shell session be created?".
|
|
804
879
|
// Fail-closed — anything other than an explicit `userShell.enabled === true` is
|
|
805
880
|
// disabled. Used by SessionManager.createSession (the authoritative gate).
|
|
@@ -940,9 +1015,14 @@ export function isUserShellApprovalRequired(config) {
|
|
|
940
1015
|
}
|
|
941
1016
|
|
|
942
1017
|
// #6378: which providers may serve a model id that is NOT in their static
|
|
943
|
-
// allowlist.
|
|
944
|
-
//
|
|
945
|
-
//
|
|
1018
|
+
// allowlist. A static-allowlist subprocess provider (currently gemini and
|
|
1019
|
+
// deepseek — NOT codex since #7727, whose allowlist is the installed binary's
|
|
1020
|
+
// own model/list answer) otherwise hard-rejects an unlisted-but-API-valid
|
|
1021
|
+
// model, forcing a code release just to add one the upstream API already
|
|
1022
|
+
// exposes. This flag is keyed on the provider NAME and checked before any class
|
|
1023
|
+
// lookup, so it stays generic: the set of providers it matters for grows with
|
|
1024
|
+
// every provider that ships a compiled-in list, and the parenthetical above is
|
|
1025
|
+
// an inventory of today, not a closed roster. Opting a provider in here
|
|
946
1026
|
// makes it behave like ollama (#5418 PROVIDER_MODELS_UNRESTRICTED): the id
|
|
947
1027
|
// passes through verbatim and the upstream API becomes the validator. Returns a
|
|
948
1028
|
// Set of provider-name strings; a missing/non-array value → empty Set (the
|
|
@@ -989,6 +1069,13 @@ function validateDiscordNotificationsBlock(discord, warnings) {
|
|
|
989
1069
|
warnings.push(`Invalid value for 'notifications.discord.billingAlerts': expected a boolean, got ${JSON.stringify(discord.billingAlerts)}`)
|
|
990
1070
|
}
|
|
991
1071
|
|
|
1072
|
+
// #7428: kill-switch for the Discord CI-completion sink. Default ON when a
|
|
1073
|
+
// webhook resolves; set false to keep ci_complete notices off Discord while
|
|
1074
|
+
// the status embed / billing alerts stay on.
|
|
1075
|
+
if (Object.prototype.hasOwnProperty.call(discord, 'ciAlerts') && typeof discord.ciAlerts !== 'boolean') {
|
|
1076
|
+
warnings.push(`Invalid value for 'notifications.discord.ciAlerts': expected a boolean, got ${JSON.stringify(discord.ciAlerts)}`)
|
|
1077
|
+
}
|
|
1078
|
+
|
|
992
1079
|
const isValidColor = (v) => Number.isInteger(v) && v >= 0 && v <= MAX_DISCORD_COLOR
|
|
993
1080
|
for (const key of ['defaultColor', 'permissionColor', 'errorColor']) {
|
|
994
1081
|
if (Object.prototype.hasOwnProperty.call(discord, key) && !isValidColor(discord[key])) {
|
|
@@ -1291,6 +1378,10 @@ export function validateConfig(config, verbose = false) {
|
|
|
1291
1378
|
}
|
|
1292
1379
|
}
|
|
1293
1380
|
|
|
1381
|
+
if (config.agentConnections !== undefined) {
|
|
1382
|
+
validateAgentConnections(config.agentConnections, warnings)
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1294
1385
|
// #4482: per-MCP-call timeout. 1s-10min. Unlike streamStallTimeoutMs,
|
|
1295
1386
|
// 0 isn't meaningful here — a 0-ms callTool timeout fires immediately
|
|
1296
1387
|
// and makes every MCP tool look broken — so any non-finite / non-
|
|
@@ -1430,6 +1521,85 @@ export function validateConfig(config, verbose = false) {
|
|
|
1430
1521
|
}
|
|
1431
1522
|
}
|
|
1432
1523
|
|
|
1524
|
+
// #7606: orphaned-child reaper block. `enabled` boolean; `sweepIntervalMs`
|
|
1525
|
+
// positive; `minAgeMs` non-negative. A bad value warns and the reaper falls
|
|
1526
|
+
// back to its built-in default for that knob (fail-safe: a typo can only
|
|
1527
|
+
// ever leave the defaults in place, never widen the predicate).
|
|
1528
|
+
if (config.orphanReap !== undefined) {
|
|
1529
|
+
if (typeof config.orphanReap !== 'object' || config.orphanReap === null || Array.isArray(config.orphanReap)) {
|
|
1530
|
+
warnings.push(`Invalid type for 'orphanReap': expected object, got ${Array.isArray(config.orphanReap) ? 'array' : typeof config.orphanReap}`)
|
|
1531
|
+
} else {
|
|
1532
|
+
if (
|
|
1533
|
+
Object.prototype.hasOwnProperty.call(config.orphanReap, 'enabled') &&
|
|
1534
|
+
typeof config.orphanReap.enabled !== 'boolean'
|
|
1535
|
+
) {
|
|
1536
|
+
warnings.push(`Invalid type for 'orphanReap.enabled': expected boolean, got ${typeof config.orphanReap.enabled}`)
|
|
1537
|
+
}
|
|
1538
|
+
if (Object.prototype.hasOwnProperty.call(config.orphanReap, 'sweepIntervalMs')) {
|
|
1539
|
+
const v = config.orphanReap.sweepIntervalMs
|
|
1540
|
+
if (typeof v !== 'number' || !Number.isFinite(v) || v <= 0) {
|
|
1541
|
+
warnings.push(`Invalid value for 'orphanReap.sweepIntervalMs': expected a positive number, got ${typeof v === 'number' ? v : typeof v}`)
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
if (Object.prototype.hasOwnProperty.call(config.orphanReap, 'minAgeMs')) {
|
|
1545
|
+
const v = config.orphanReap.minAgeMs
|
|
1546
|
+
if (typeof v !== 'number' || !Number.isFinite(v) || v < 0) {
|
|
1547
|
+
warnings.push(`Invalid value for 'orphanReap.minAgeMs': expected a non-negative number, got ${typeof v === 'number' ? v : typeof v}`)
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
warnUnknownKeys(config.orphanReap, ORPHAN_REAP_SUPPORTED_KEYS, 'orphanReap', warnings)
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
// Session archive block. `enabled` boolean; `maxEntries` a positive integer;
|
|
1555
|
+
// `maxAgeDays` / `maxMegabytes` positive numbers. A bad value warns and the
|
|
1556
|
+
// archive falls back to its built-in default for that knob (SessionArchive
|
|
1557
|
+
// re-validates, so a typo can never widen retention past the defaults).
|
|
1558
|
+
if (config.sessionArchive !== undefined) {
|
|
1559
|
+
if (typeof config.sessionArchive !== 'object' || config.sessionArchive === null || Array.isArray(config.sessionArchive)) {
|
|
1560
|
+
warnings.push(`Invalid type for 'sessionArchive': expected object, got ${Array.isArray(config.sessionArchive) ? 'array' : typeof config.sessionArchive}`)
|
|
1561
|
+
} else {
|
|
1562
|
+
for (const key of SESSION_ARCHIVE_POLICY_KEYS) {
|
|
1563
|
+
if (!Object.prototype.hasOwnProperty.call(config.sessionArchive, key)) continue
|
|
1564
|
+
const problem = sessionArchiveFieldProblem(key, config.sessionArchive[key])
|
|
1565
|
+
if (!problem) continue
|
|
1566
|
+
if (problem.kind === 'type') {
|
|
1567
|
+
warnings.push(`Invalid type for 'sessionArchive.${key}': ${problem.detail}`)
|
|
1568
|
+
} else if (problem.kind === 'above_max') {
|
|
1569
|
+
warnings.push(`Invalid value for 'sessionArchive.${key}': ${config.sessionArchive[key]} is above the maximum of ${SESSION_ARCHIVE_MAX_ENTRIES} and is clamped to it`)
|
|
1570
|
+
} else {
|
|
1571
|
+
warnings.push(`Invalid value for 'sessionArchive.${key}': ${problem.detail}`)
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
warnUnknownKeys(config.sessionArchive, SESSION_ARCHIVE_SUPPORTED_KEYS, 'sessionArchive', warnings)
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
// #7424: session CI-completion watcher. Every key is optional; an unset block
|
|
1579
|
+
// means "watch on, wake on, built-in intervals". The two intervals must be
|
|
1580
|
+
// positive finite numbers — a zero or negative sweep interval would spin the
|
|
1581
|
+
// event loop spawning `gh`, so a typo warns and the wiring layer falls back to
|
|
1582
|
+
// the module default rather than honouring it.
|
|
1583
|
+
if (config.sessionCi !== undefined) {
|
|
1584
|
+
if (typeof config.sessionCi !== 'object' || config.sessionCi === null || Array.isArray(config.sessionCi)) {
|
|
1585
|
+
warnings.push(`Invalid type for 'sessionCi': expected object, got ${Array.isArray(config.sessionCi) ? 'array' : typeof config.sessionCi}`)
|
|
1586
|
+
} else {
|
|
1587
|
+
for (const key of ['watch', 'wakeAgent']) {
|
|
1588
|
+
if (Object.prototype.hasOwnProperty.call(config.sessionCi, key) && typeof config.sessionCi[key] !== 'boolean') {
|
|
1589
|
+
warnings.push(`Invalid type for 'sessionCi.${key}': expected boolean, got ${typeof config.sessionCi[key]}`)
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
for (const key of ['intervalMs', 'discoveryIntervalMs', 'maxSurveysPerTick']) {
|
|
1593
|
+
if (!Object.prototype.hasOwnProperty.call(config.sessionCi, key)) continue
|
|
1594
|
+
const v = config.sessionCi[key]
|
|
1595
|
+
if (typeof v !== 'number' || !Number.isFinite(v) || v <= 0) {
|
|
1596
|
+
warnings.push(`Invalid value for 'sessionCi.${key}': expected a positive number, got ${typeof v === 'number' ? v : typeof v}`)
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
warnUnknownKeys(config.sessionCi, SESSION_CI_SUPPORTED_KEYS, 'sessionCi', warnings)
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1433
1603
|
// #5413: notifications block. Only `notifications.discord` is recognised
|
|
1434
1604
|
// today. All warnings here are "Invalid value" (not "Invalid type") so a
|
|
1435
1605
|
// typo in a cosmetic color can never become a fatal startup error via the
|
|
@@ -1474,6 +1644,16 @@ export function validateConfig(config, verbose = false) {
|
|
|
1474
1644
|
!Array.isArray(config.providers)
|
|
1475
1645
|
) {
|
|
1476
1646
|
validateProvidersConfigBlock(config.providers, warnings)
|
|
1647
|
+
// #7319 — `providers.acp` (config-driven ACP agents). Validated here
|
|
1648
|
+
// rather than inside validateProvidersConfigBlock to avoid a circular
|
|
1649
|
+
// import (see the import comment above); entry-level warnings use the
|
|
1650
|
+
// same "Invalid value" wording so a malformed entry can't escalate into
|
|
1651
|
+
// a fatal startup error — bad entries are dropped at registration
|
|
1652
|
+
// (acp-session.js) and valid siblings still register.
|
|
1653
|
+
if (Object.prototype.hasOwnProperty.call(config.providers, 'acp')) {
|
|
1654
|
+
const { warnings: acpWarnings } = validateAcpProviders(config.providers.acp)
|
|
1655
|
+
warnings.push(...acpWarnings)
|
|
1656
|
+
}
|
|
1477
1657
|
}
|
|
1478
1658
|
|
|
1479
1659
|
// Validate externalUrl format if provided
|
|
@@ -1580,6 +1760,19 @@ export function mergeConfig({ fileConfig = {}, cliOverrides = {}, defaults = {},
|
|
|
1580
1760
|
|
|
1581
1761
|
/**
|
|
1582
1762
|
* Convert config key to corresponding environment variable name.
|
|
1763
|
+
*
|
|
1764
|
+
* #8151 round-2 review (nit) — was exported (S6) for doctor.js's
|
|
1765
|
+
* `resolveProviders` to read the same env-var name this file uses for a
|
|
1766
|
+
* given config key, rather than a second hand-typed copy. Round-2 Critical
|
|
1767
|
+
* 2 removed that direct read entirely — `resolveProviders` now goes
|
|
1768
|
+
* through `mergeConfig`/`resolveDaemonDefaultProvider` instead, the actual
|
|
1769
|
+
* fix for the regression that export-for-direct-reads turned out to be
|
|
1770
|
+
* (CHROXY_PROVIDERS is `config.providers`'s env var, not a provider-name
|
|
1771
|
+
* list, and a direct per-key env read couldn't tell the difference). No
|
|
1772
|
+
* remaining caller outside this file reads `envKeyForConfig` itself
|
|
1773
|
+
* (confirmed: `grep -rl` finds none), so this reverts to module-private
|
|
1774
|
+
* rather than carry a stale-justification export.
|
|
1775
|
+
*
|
|
1583
1776
|
* @param {string} key - Config key
|
|
1584
1777
|
* @returns {string} Environment variable name
|
|
1585
1778
|
*/
|
|
@@ -1625,6 +1818,8 @@ function envKeyForConfig(key) {
|
|
|
1625
1818
|
controlRoomContainersIncludeStats: 'CHROXY_CONTAINERS_INCLUDE_STATS',
|
|
1626
1819
|
// #5499: explicit repo-memory binary path for the Integrations survey.
|
|
1627
1820
|
controlRoomRepoMemoryBin: 'CHROXY_REPO_MEMORY_BIN',
|
|
1821
|
+
// #8609: codex client to launch (read by CodexSession.resolvedBinary).
|
|
1822
|
+
codexBinary: 'CHROXY_CODEX_BIN',
|
|
1628
1823
|
logFormat: 'CHROXY_LOG_FORMAT',
|
|
1629
1824
|
sandbox: 'CHROXY_SANDBOX',
|
|
1630
1825
|
resultTimeoutMs: 'CHROXY_RESULT_TIMEOUT_MS',
|
|
@@ -1921,14 +2116,80 @@ export async function buildEnvironmentBackend(config, { _execFile, _loadBackends
|
|
|
1921
2116
|
return { backend, type }
|
|
1922
2117
|
}
|
|
1923
2118
|
|
|
1924
|
-
|
|
2119
|
+
/** The four `sessionArchive` retention knobs, in display order. */
|
|
2120
|
+
export const SESSION_ARCHIVE_POLICY_KEYS = ['enabled', 'maxEntries', 'maxAgeDays', 'maxMegabytes']
|
|
2121
|
+
|
|
2122
|
+
/**
|
|
2123
|
+
* The ONE rule for a single `sessionArchive` retention value, shared by the
|
|
2124
|
+
* config validator (which warns) and the dashboard setter (which rejects).
|
|
2125
|
+
* `enabled` is a boolean; `maxEntries` a positive integer no larger than
|
|
2126
|
+
* SESSION_ARCHIVE_MAX_ENTRIES; `maxAgeDays` / `maxMegabytes` positive finite
|
|
2127
|
+
* numbers.
|
|
2128
|
+
* @returns {null | { kind: 'type'|'value'|'above_max', detail: string }}
|
|
2129
|
+
*/
|
|
2130
|
+
export function sessionArchiveFieldProblem(key, v) {
|
|
2131
|
+
const got = typeof v === 'number' ? String(v) : typeof v
|
|
2132
|
+
if (key === 'enabled') {
|
|
2133
|
+
return typeof v === 'boolean' ? null : { kind: 'type', detail: `expected boolean, got ${typeof v}` }
|
|
2134
|
+
}
|
|
2135
|
+
if (key === 'maxEntries') {
|
|
2136
|
+
if (typeof v !== 'number' || !Number.isInteger(v) || v <= 0) {
|
|
2137
|
+
return { kind: 'value', detail: `expected a positive integer, got ${got}` }
|
|
2138
|
+
}
|
|
2139
|
+
if (v > SESSION_ARCHIVE_MAX_ENTRIES) {
|
|
2140
|
+
return { kind: 'above_max', detail: `${v} is above the maximum of ${SESSION_ARCHIVE_MAX_ENTRIES}` }
|
|
2141
|
+
}
|
|
2142
|
+
return null
|
|
2143
|
+
}
|
|
2144
|
+
if (key === 'maxAgeDays' || key === 'maxMegabytes') {
|
|
2145
|
+
return typeof v === 'number' && Number.isFinite(v) && v > 0 ? null : { kind: 'value', detail: `expected a positive number, got ${got}` }
|
|
2146
|
+
}
|
|
2147
|
+
return { kind: 'value', detail: 'unknown key' }
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
/**
|
|
2151
|
+
* Validate a whole retention policy (all four fields required, exactly as the
|
|
2152
|
+
* dashboard setter sends them). Unlike config loading, an over-max
|
|
2153
|
+
* `maxEntries` is REJECTED, not clamped.
|
|
2154
|
+
* @returns {{ field: string, message: string } | null} the first problem, or null
|
|
2155
|
+
*/
|
|
2156
|
+
export function validateSessionArchivePolicy(policy) {
|
|
2157
|
+
if (!policy || typeof policy !== 'object' || Array.isArray(policy)) {
|
|
2158
|
+
return { field: 'policy', message: 'expected a retention policy object' }
|
|
2159
|
+
}
|
|
2160
|
+
for (const key of SESSION_ARCHIVE_POLICY_KEYS) {
|
|
2161
|
+
const problem = sessionArchiveFieldProblem(key, policy[key])
|
|
2162
|
+
if (problem) return { field: key, message: `sessionArchive.${key}: ${problem.detail}` }
|
|
2163
|
+
}
|
|
2164
|
+
return null
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
/**
|
|
2168
|
+
* Persist the four session-archive retention knobs to a config file,
|
|
2169
|
+
* preserving every other field (including unknown keys inside `sessionArchive`).
|
|
2170
|
+
* Throws on an unreadable/malformed existing config (readConfigForMerge).
|
|
2171
|
+
* Does NOT validate; callers run validateSessionArchivePolicy first.
|
|
2172
|
+
*/
|
|
2173
|
+
export function writeSessionArchiveToConfig(policy, configPath = defaultConfigPath()) {
|
|
2174
|
+
const existing = readConfigForMerge(configPath)
|
|
2175
|
+
if (!existing.sessionArchive || typeof existing.sessionArchive !== 'object' || Array.isArray(existing.sessionArchive)) {
|
|
2176
|
+
existing.sessionArchive = {}
|
|
2177
|
+
}
|
|
2178
|
+
for (const key of SESSION_ARCHIVE_POLICY_KEYS) existing.sessionArchive[key] = policy[key]
|
|
2179
|
+
mkdirSync(dirname(configPath), { recursive: true })
|
|
2180
|
+
writeFileRestricted(configPath, JSON.stringify(existing, null, 2))
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
function defaultConfigPath() {
|
|
2184
|
+
return configPath('config.json')
|
|
2185
|
+
}
|
|
1925
2186
|
|
|
1926
2187
|
/**
|
|
1927
2188
|
* Read the repos array from a config file.
|
|
1928
2189
|
* @param {string} [configPath] - Path to config.json. Defaults to ~/.chroxy/config.json.
|
|
1929
2190
|
* @returns {Array<{ path: string, name?: string }>} Repos array, or [] if missing/invalid.
|
|
1930
2191
|
*/
|
|
1931
|
-
export function readReposFromConfig(configPath =
|
|
2192
|
+
export function readReposFromConfig(configPath = defaultConfigPath()) {
|
|
1932
2193
|
try {
|
|
1933
2194
|
if (!existsSync(configPath)) return []
|
|
1934
2195
|
const raw = JSON.parse(readFileSync(configPath, 'utf-8'))
|
|
@@ -2060,7 +2321,7 @@ function refuseMalformedConfig(configPath, reason, bytes) {
|
|
|
2060
2321
|
* @param {Array<{ path: string, name?: string }>} repos - Repos array to write.
|
|
2061
2322
|
* @param {string} [configPath] - Path to config.json. Defaults to ~/.chroxy/config.json.
|
|
2062
2323
|
*/
|
|
2063
|
-
export function writeReposToConfig(repos, configPath =
|
|
2324
|
+
export function writeReposToConfig(repos, configPath = defaultConfigPath()) {
|
|
2064
2325
|
const existing = readConfigForMerge(configPath)
|
|
2065
2326
|
existing.repos = repos
|
|
2066
2327
|
const dir = dirname(configPath)
|
|
@@ -2083,7 +2344,7 @@ export function writeReposToConfig(repos, configPath = DEFAULT_CONFIG_PATH) {
|
|
|
2083
2344
|
* @param {object|null} preset - The preset object ({ preamble?, seed?, enabled? }) or null to clear.
|
|
2084
2345
|
* @param {string} [configPath] - Path to config.json. Defaults to ~/.chroxy/config.json.
|
|
2085
2346
|
*/
|
|
2086
|
-
export function writeSessionPresetOverrideToConfig(repoPath, preset, configPath =
|
|
2347
|
+
export function writeSessionPresetOverrideToConfig(repoPath, preset, configPath = defaultConfigPath()) {
|
|
2087
2348
|
const existing = readConfigForMerge(configPath)
|
|
2088
2349
|
if (!Array.isArray(existing.repos)) existing.repos = []
|
|
2089
2350
|
|
|
@@ -2134,7 +2395,7 @@ export function writeSessionPresetOverrideToConfig(repoPath, preset, configPath
|
|
|
2134
2395
|
* @param {boolean} enabled - the new gate value.
|
|
2135
2396
|
* @param {string} [configPath] - Path to config.json. Defaults to ~/.chroxy/config.json.
|
|
2136
2397
|
*/
|
|
2137
|
-
export function writeSchedulerEnabledToConfig(enabled, configPath =
|
|
2398
|
+
export function writeSchedulerEnabledToConfig(enabled, configPath = defaultConfigPath()) {
|
|
2138
2399
|
const existing = readConfigForMerge(configPath)
|
|
2139
2400
|
// A non-object `features` is a single stray FIELD, not the whole config, so it
|
|
2140
2401
|
// is repaired in place rather than refused — the operator's other settings
|
|
@@ -2153,7 +2414,7 @@ export function writeSchedulerEnabledToConfig(enabled, configPath = DEFAULT_CONF
|
|
|
2153
2414
|
* @param {string} [configPath] - Path to config.json. Defaults to ~/.chroxy/config.json.
|
|
2154
2415
|
* @returns {string|undefined} The configured root, or undefined if missing/invalid.
|
|
2155
2416
|
*/
|
|
2156
|
-
export function readControlRoomRootFromConfig(configPath =
|
|
2417
|
+
export function readControlRoomRootFromConfig(configPath = defaultConfigPath()) {
|
|
2157
2418
|
try {
|
|
2158
2419
|
if (!existsSync(configPath)) return undefined
|
|
2159
2420
|
const raw = JSON.parse(readFileSync(configPath, 'utf-8'))
|
|
@@ -2173,11 +2434,10 @@ export function readControlRoomRootFromConfig(configPath = DEFAULT_CONFIG_PATH)
|
|
|
2173
2434
|
* @param {string} root - Absolute path to the discovery root.
|
|
2174
2435
|
* @param {string} [configPath] - Path to config.json. Defaults to ~/.chroxy/config.json.
|
|
2175
2436
|
*/
|
|
2176
|
-
export function writeControlRoomRootToConfig(root, configPath =
|
|
2437
|
+
export function writeControlRoomRootToConfig(root, configPath = defaultConfigPath()) {
|
|
2177
2438
|
const existing = readConfigForMerge(configPath)
|
|
2178
2439
|
existing.controlRoomRoot = root
|
|
2179
2440
|
const dir = dirname(configPath)
|
|
2180
2441
|
mkdirSync(dir, { recursive: true })
|
|
2181
2442
|
writeFileRestricted(configPath, JSON.stringify(existing, null, 2))
|
|
2182
2443
|
}
|
|
2183
|
-
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request authority for work that outlives the frame that asked for it.
|
|
3
|
+
*
|
|
4
|
+
* A handler (or a manager it calls) that waits — on a lock, a scan, a trust
|
|
5
|
+
* prompt, a subprocess — keeps the connection record it started with after the
|
|
6
|
+
* connection's credential has been revoked or has expired. `isAuthorized` is the
|
|
7
|
+
* ONE mechanism for carrying that authority into such deferred work: a
|
|
8
|
+
* zero-argument function, true while the requesting connection is still
|
|
9
|
+
* authenticated with a valid credential. Code that has waited calls
|
|
10
|
+
* `assertAuthorized(isAuthorized)` IMMEDIATELY before starting each mutation.
|
|
11
|
+
* Absent (internal callers, timers, tests) means "not tied to a connection".
|
|
12
|
+
*
|
|
13
|
+
* A function rather than an abort signal because expiry is time-based: a token
|
|
14
|
+
* can lapse between sweeps, with no event to abort on, and the check must see it.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export const AUTHORITY_REVOKED = 'CONNECTION_AUTHORITY_REVOKED'
|
|
18
|
+
|
|
19
|
+
export class AuthorityRevokedError extends Error {
|
|
20
|
+
constructor() {
|
|
21
|
+
super('The requesting connection is no longer authorized; the operation was not started')
|
|
22
|
+
this.name = 'AuthorityRevokedError'
|
|
23
|
+
this.code = AUTHORITY_REVOKED
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** True when `isAuthorized` is absent or reports the connection still authorized. */
|
|
28
|
+
export function stillAuthorized(isAuthorized) {
|
|
29
|
+
return typeof isAuthorized !== 'function' || isAuthorized() !== false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Throw AuthorityRevokedError unless the requesting connection is still authorized. */
|
|
33
|
+
export function assertAuthorized(isAuthorized) {
|
|
34
|
+
if (!stillAuthorized(isAuthorized)) throw new AuthorityRevokedError()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function isAuthorityRevoked(err) {
|
|
38
|
+
return err?.code === AUTHORITY_REVOKED
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The `isAuthorized` function for the connection behind `client`, built from the
|
|
43
|
+
* handler context. A hand-built context without the hook (tests) is never
|
|
44
|
+
* revoked; the production context always carries it (assertCtxShape).
|
|
45
|
+
*/
|
|
46
|
+
export function authorizedFor(ctx, client) {
|
|
47
|
+
return () => ctx?.transport?.isConnectionAuthorized?.(client) ?? true
|
|
48
|
+
}
|
package/src/connection-info.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import { homedir } from 'os'
|
|
2
1
|
import { join } from 'path'
|
|
3
2
|
import { existsSync, readFileSync, unlinkSync, mkdirSync } from 'fs'
|
|
4
3
|
import { writeFileRestricted } from './platform.js'
|
|
5
|
-
|
|
6
|
-
function getConfigDir() {
|
|
7
|
-
return process.env.CHROXY_CONFIG_DIR || join(homedir(), '.chroxy')
|
|
8
|
-
}
|
|
4
|
+
import { configDir, configPath } from './config-dir.js'
|
|
9
5
|
|
|
10
6
|
export function getConnectionInfoPath() {
|
|
11
|
-
return
|
|
7
|
+
return configPath('connection.json')
|
|
12
8
|
}
|
|
13
9
|
|
|
14
10
|
export function writeConnectionInfo(info) {
|
|
15
|
-
const
|
|
16
|
-
mkdirSync(
|
|
17
|
-
writeFileRestricted(join(
|
|
11
|
+
const dir = configDir()
|
|
12
|
+
mkdirSync(dir, { recursive: true })
|
|
13
|
+
writeFileRestricted(join(dir, 'connection.json'), JSON.stringify(info, null, 2))
|
|
18
14
|
}
|
|
19
15
|
|
|
20
16
|
export function readConnectionInfo() {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* this classification — it's a pure transport-efficiency hint.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
import { isIPv4 } from 'node:net'
|
|
24
25
|
import { isLoopbackHost } from './bind-host.js'
|
|
25
26
|
import { isPrivateOrSpecialIp } from './ssrf-guard.js'
|
|
26
27
|
|
|
@@ -53,3 +54,62 @@ export function isLocalOrLanPeer(req) {
|
|
|
53
54
|
if (isPrivateOrSpecialIp(socketIp)) return true
|
|
54
55
|
return false
|
|
55
56
|
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Strict loopback parse for AUTHORIZATION use. Not `isLoopbackHost`, which is a
|
|
60
|
+
* bind-host helper that accepts anything starting `::ffff:7f` — so
|
|
61
|
+
* `::ffff:7f00:1:2`, which is not an address at all, would pass. Accepts exactly:
|
|
62
|
+
* - a dotted IPv4 literal in 127.0.0.0/8,
|
|
63
|
+
* - `::1`,
|
|
64
|
+
* - an IPv4-mapped `::ffff:a.b.c.d` whose dotted part is in 127.0.0.0/8.
|
|
65
|
+
*/
|
|
66
|
+
function isStrictLoopbackAddress(ip) {
|
|
67
|
+
const addr = ip.toLowerCase()
|
|
68
|
+
if (isIPv4(addr)) return addr.split('.')[0] === '127'
|
|
69
|
+
if (addr === '::1') return true
|
|
70
|
+
const mapped = /^::ffff:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/.exec(addr)
|
|
71
|
+
return !!mapped && isIPv4(mapped[1]) && mapped[1].split('.')[0] === '127'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Any header a tunnel, CDN or reverse proxy leaves behind. Wider than
|
|
76
|
+
* `hasProxyHeaders` on purpose: Cloudflare can strip the visitor-IP headers
|
|
77
|
+
* (a managed transform), and then `cf-connecting-ip` is absent on a request
|
|
78
|
+
* that very much came through the tunnel. What survives is the rest of the
|
|
79
|
+
* family — `cf-ray`, `cf-visitor`, `cdn-loop`, `x-forwarded-proto`. Presence of
|
|
80
|
+
* the NAME is the test; the value is never trusted.
|
|
81
|
+
*/
|
|
82
|
+
function hasAnyProxyHint(headers) {
|
|
83
|
+
if (!headers) return false
|
|
84
|
+
for (const name of Object.keys(headers)) {
|
|
85
|
+
const n = name.toLowerCase()
|
|
86
|
+
if (n.startsWith('cf-') || n.startsWith('cdn-loop') || n.startsWith('forwarded') ||
|
|
87
|
+
n.startsWith('x-forwarded-') || n === 'x-real-ip') return true
|
|
88
|
+
}
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Is this request a loopback peer that carries no sign of a proxy? (#8324)
|
|
94
|
+
*
|
|
95
|
+
* It does NOT prove direct local origin. It rejects a request whose socket is
|
|
96
|
+
* not loopback, and any request carrying a proxy-family header (see
|
|
97
|
+
* `hasAnyProxyHint`); a proxy that strips EVERY such header, or a local process
|
|
98
|
+
* that forwards traffic for a remote party without adding one, passes it. So it
|
|
99
|
+
* is defence in depth for the local-only `/api/daemon/idle` probe, and the
|
|
100
|
+
* primary bearer token is the authority.
|
|
101
|
+
*
|
|
102
|
+
* Stricter than `isLocalOrLanPeer`, which is a transport-efficiency hint with
|
|
103
|
+
* no security property riding on it: the socket address is parsed strictly, and
|
|
104
|
+
* ANY proxy-family header disqualifies the request. cloudflared connects to the
|
|
105
|
+
* daemon from 127.0.0.1, so the socket address alone proves nothing.
|
|
106
|
+
*
|
|
107
|
+
* @param {object} req - Node IncomingMessage.
|
|
108
|
+
* @returns {boolean}
|
|
109
|
+
*/
|
|
110
|
+
export function isLoopbackPeer(req) {
|
|
111
|
+
const socketIp = req?.socket?.remoteAddress
|
|
112
|
+
if (typeof socketIp !== 'string' || socketIp.length === 0) return false
|
|
113
|
+
if (hasAnyProxyHint(req.headers)) return false
|
|
114
|
+
return isStrictLoopbackAddress(socketIp)
|
|
115
|
+
}
|