@chroxy/server 0.10.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 +602 -19
- package/README.md +2 -2
- package/hooks/claude-native-route-check.mjs +17 -0
- package/hooks/permission-hook.sh +416 -11
- package/package.json +20 -23
- 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 +1353 -41
- package/src/bearer-recheck.js +49 -0
- package/src/billing-budget.js +24 -1
- package/src/billing-class.js +40 -7
- package/src/binary-provenance-trust.js +101 -0
- 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 +74 -9
- 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 +1153 -20
- package/src/byok-mcp-config.js +1712 -8
- package/src/byok-mcp-fleet.js +416 -29
- package/src/byok-mcp-oauth-store.js +329 -0
- package/src/byok-mcp-oauth.js +635 -0
- package/src/byok-mcp-trust.js +257 -40
- package/src/byok-session.js +1400 -149
- package/src/byok-tool-executor.js +2681 -38
- package/src/byok-tools.js +9 -2
- package/src/channels/chroxy-channel-server.js +2 -3
- package/src/checkpoint-manager.js +96 -51
- package/src/chroxy-host-metadata.js +122 -0
- 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 +109 -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 +223 -60
- 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 +3611 -286
- package/src/claude-tui-tool-response.js +300 -0
- package/src/cli/agent-control-cmd.js +65 -0
- package/src/cli/config-cmd.js +6 -6
- package/src/cli/config-dir-cmd.js +234 -0
- package/src/cli/deploy-cmd.js +46 -11
- package/src/cli/doctor-cmd.js +7 -3
- package/src/cli/init-cmd.js +16 -17
- package/src/cli/providers-cmd.js +6 -6
- package/src/cli/schedule-cmd.js +804 -0
- package/src/cli/server-cmd.js +64 -2
- package/src/cli/service-cmd.js +70 -27
- package/src/cli/session-cmd.js +227 -74
- package/src/cli/shared.js +168 -14
- package/src/cli/tokens-cmd.js +212 -0
- package/src/cli/tunnel-cmd.js +256 -25
- package/src/cli/worktree-gc-cmd.js +2 -2
- package/src/cli-session.js +1117 -116
- package/src/cli.js +8 -0
- package/src/codex-app-server-client.js +36 -3
- package/src/codex-app-server-session.js +2108 -101
- 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 +571 -45
- package/src/config-dir-migration.js +444 -0
- package/src/config-dir.js +108 -0
- package/src/config.js +738 -52
- 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 +23 -30
- package/src/control-room/skills-inventory.js +8 -3
- package/src/control-room/survey.js +32 -0
- 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 +279 -29
- 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/diagnostics.js +3 -0
- 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 +188 -4
- package/src/docker-session.js +293 -10
- package/src/doctor.js +783 -66
- 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 +39 -10
- package/src/environments/backends/k8s.js +58 -24
- package/src/environments/destroy-with-sessions.js +142 -0
- package/src/event-ingest.js +137 -14
- package/src/event-normalizer.js +363 -110
- package/src/external-session-registry.js +0 -0
- package/src/gemini-session.js +100 -7
- package/src/github-webhook.js +188 -4
- package/src/handler-utils.js +563 -62
- package/src/handlers/checkpoint-handlers.js +162 -20
- package/src/handlers/control-room-handlers.js +99 -29
- package/src/handlers/conversation-handlers.js +563 -25
- package/src/handlers/credential-handlers.js +43 -2
- 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 +101 -13
- package/src/handlers/github-webhook-handlers.js +204 -0
- package/src/handlers/input-handlers.js +689 -48
- package/src/handlers/orchestration-handlers.js +238 -0
- package/src/handlers/scheduler-handlers.js +584 -0
- package/src/handlers/session-handlers.js +546 -16
- 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 +822 -35
- 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/handlers/token-handlers.js +11 -2
- package/src/health-proof.js +40 -0
- package/src/history-page.js +104 -0
- package/src/http-routes.js +286 -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 +309 -48
- package/src/jsonl-subprocess-session.js +122 -9
- package/src/keychain.js +160 -13
- package/src/logger.js +240 -31
- 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 +100 -10
- 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 +82 -12
- 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 +63 -0
- package/src/orchestration/decision-contract.js +245 -0
- package/src/orchestration/git-ops.js +381 -0
- package/src/orchestration/orchestration-manager.js +1342 -0
- package/src/orchestration/permission-gate.js +121 -0
- package/src/orchestration/role-prompts.js +136 -0
- package/src/orchestration/run-budget.js +81 -0
- package/src/orchestration/run-ledger.js +487 -0
- package/src/orchestration/run-model.js +206 -0
- package/src/orchestration/run-record.js +336 -0
- package/src/orchestration/run-report.js +194 -0
- package/src/orchestration/to-wire.js +201 -0
- package/src/orchestration/turn-driver.js +422 -0
- package/src/orphan-reaper.js +413 -0
- package/src/outgoing-policy.js +183 -0
- package/src/pairing.js +236 -12
- package/src/path-hash-trust-ledger.js +642 -25
- package/src/permission-audit.js +79 -3
- package/src/permission-deadlines.js +82 -0
- package/src/permission-floor.js +1770 -0
- package/src/permission-hook.js +180 -69
- package/src/permission-manager.js +1175 -94
- package/src/permission-mode-support.js +35 -0
- package/src/permission-resolver.js +174 -12
- package/src/permission-rule-store.js +411 -0
- package/src/permission-scope.js +43 -0
- package/src/platform.js +483 -23
- 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 +228 -6
- 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/schedule-parser.js +311 -0
- package/src/scheduled-task-store.js +945 -0
- package/src/scheduler.js +1099 -0
- package/src/sdk-session.js +2374 -168
- 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 +50 -4
- package/src/server-cli/tunnel-lifecycle-handler.js +3 -2
- package/src/server-cli-child.js +33 -18
- package/src/server-cli.js +760 -62
- package/src/server-identity.js +42 -14
- package/src/service.js +682 -53
- 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 +3879 -308
- package/src/session-message-history.js +749 -37
- 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-title.js +168 -0
- package/src/session-token-store.js +70 -36
- 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 +22 -5
- package/src/snapshots-store.js +2 -3
- package/src/statusline.js +596 -0
- package/src/subagent-counter.js +9 -1
- package/src/summarize-session.js +51 -4
- package/src/supervisor.js +99 -38
- 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/token-manager.js +39 -9
- package/src/tool-result.js +61 -0
- package/src/transcript-sources.js +109 -0
- package/src/transcript-tasks.js +413 -31
- package/src/trusted-file-read.js +302 -0
- package/src/tunnel/base.js +0 -8
- package/src/tunnel/cloudflare.js +145 -35
- package/src/tunnel/index.js +13 -1
- package/src/tunnel/preview.js +64 -0
- package/src/tunnel-check.js +1 -1
- package/src/turn-outcome.js +137 -0
- package/src/turn-tracker.js +0 -0
- package/src/usage-normalize.js +122 -0
- package/src/user-shell-session.js +157 -37
- 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 +301 -0
- package/src/utils/composite-key.js +45 -0
- 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/iso-datetime.js +51 -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 +485 -29
- 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 +196 -5
- package/src/utils/stale-session-dirs.js +182 -0
- package/src/utils/stat-identity.js +43 -0
- package/src/utils/verify-binary.js +276 -0
- package/src/utils/verify-provenance.js +634 -0
- package/src/utils/wire-counters.js +48 -0
- package/src/web-task-manager.js +256 -16
- package/src/worktree-gc.js +11 -3
- 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 +370 -66
- package/src/ws-file-ops/common.js +384 -11
- package/src/ws-file-ops/git.js +615 -44
- package/src/ws-file-ops/index.js +7 -0
- package/src/ws-file-ops/memory.js +460 -0
- package/src/ws-file-ops/open-nofollow.js +354 -0
- package/src/ws-file-ops/reader.js +676 -94
- package/src/ws-forwarding.js +373 -55
- package/src/ws-handler-context.js +89 -2
- package/src/ws-history.js +1018 -177
- package/src/ws-message-handlers.js +23 -1
- package/src/ws-outbound-schemas.js +207 -0
- package/src/ws-permissions.js +589 -38
- package/src/ws-schemas.js +6 -0
- package/src/ws-server.js +936 -105
- 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/redaction.js
CHANGED
|
@@ -20,9 +20,101 @@ const SENSITIVE_PATTERNS = [
|
|
|
20
20
|
// Bearer tokens in headers
|
|
21
21
|
/Bearer\s+[A-Za-z0-9_\-./+=]{8,}/gi,
|
|
22
22
|
// API tokens (base64url, UUID, hex) after common key names
|
|
23
|
-
|
|
23
|
+
// The key may be QUOTED (a JSON property: `{"token":"…"}`, or the same JSON inside
|
|
24
|
+
// a string, where each quote is escaped), and so may the value (#6630, #8416). A
|
|
25
|
+
// quoted value is redacted up to its closing quote, whatever it holds; it is bounded
|
|
26
|
+
// (1024 characters, no line break) so the scan stays linear in the input. A value with
|
|
27
|
+
// no closing quote falls through to the unquoted form, which needs 8 token characters.
|
|
28
|
+
/(?:token|password|secret|apiKey|api_key|authorization|credential|private_key)(?:\\?["'])?\s*[:=]\s*(?:"(?:[^"\\\r\n]|\\.){1,1024}"|'(?:[^'\\\r\n]|\\.){1,1024}'|\\"(?:[^\\\r\n]|\\(?!")){1,1024}\\"|(?:\\?["'])?[A-Za-z0-9_\-./+=]{8,}(?:\\?["'])?)/gi,
|
|
24
29
|
]
|
|
25
30
|
|
|
31
|
+
// JWT shape: `eyJ` + base64url, a dot, base64url, a dot, base64url, each segment at
|
|
32
|
+
// least 8 characters, the `eyJ` starting on a word boundary. This is matched by a scan
|
|
33
|
+
// rather than by one regex (`\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}`),
|
|
34
|
+
// so that the time taken is linear in the length of the text: the segments are maximal
|
|
35
|
+
// runs (the class holds no `.`), a candidate's outcome depends only on the runs that
|
|
36
|
+
// follow it, and the scan reads each run a bounded number of times, skipping the other
|
|
37
|
+
// candidates that share a failed candidate's first run. It reports exactly the spans
|
|
38
|
+
// the regex does (tests/redaction-bounded-time.test.js compares the two).
|
|
39
|
+
const JWT_SEGMENT_MIN = 8
|
|
40
|
+
|
|
41
|
+
function isWordChar(c) {
|
|
42
|
+
return (c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c === 95
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The end of the base64url run starting at `i` ([A-Za-z0-9_-]).
|
|
46
|
+
function tokenRunEnd(s, i) {
|
|
47
|
+
while (i < s.length) {
|
|
48
|
+
const c = s.charCodeAt(i)
|
|
49
|
+
if (!isWordChar(c) && c !== 45) break
|
|
50
|
+
i++
|
|
51
|
+
}
|
|
52
|
+
return i
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* First JWT span at or after `from`, as `[start, end]` (end exclusive), or null.
|
|
57
|
+
* @param {string} s
|
|
58
|
+
* @param {number} from
|
|
59
|
+
* @returns {[number, number]|null}
|
|
60
|
+
*/
|
|
61
|
+
function findJwtSpan(s, from) {
|
|
62
|
+
let p = s.indexOf('eyJ', from)
|
|
63
|
+
while (p !== -1) {
|
|
64
|
+
if (p === 0 || !isWordChar(s.charCodeAt(p - 1))) {
|
|
65
|
+
const e1 = tokenRunEnd(s, p + 3)
|
|
66
|
+
if (e1 - (p + 3) >= JWT_SEGMENT_MIN && s.charCodeAt(e1) === 46) {
|
|
67
|
+
const e2 = tokenRunEnd(s, e1 + 1)
|
|
68
|
+
if (e2 - (e1 + 1) >= JWT_SEGMENT_MIN && s.charCodeAt(e2) === 46) {
|
|
69
|
+
const e3 = tokenRunEnd(s, e2 + 1)
|
|
70
|
+
if (e3 - (e2 + 1) >= JWT_SEGMENT_MIN) return [p, e3]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Every later `eyJ` inside this first run sees the same runs after it.
|
|
74
|
+
p = s.indexOf('eyJ', Math.max(p + 1, e1))
|
|
75
|
+
} else {
|
|
76
|
+
p = s.indexOf('eyJ', p + 1)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return null
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The JWT matcher, shaped like a global RegExp for the two ways the patterns are
|
|
84
|
+
* used: `string.replace(pattern, '[REDACTED]')` (the replacement is literal text)
|
|
85
|
+
* and the `lastIndex` / `exec` loop in the logger's escape-aware pass.
|
|
86
|
+
*/
|
|
87
|
+
const JWT_PATTERN = {
|
|
88
|
+
global: true,
|
|
89
|
+
lastIndex: 0,
|
|
90
|
+
exec(s) {
|
|
91
|
+
s = String(s)
|
|
92
|
+
const span = findJwtSpan(s, this.lastIndex)
|
|
93
|
+
if (!span) {
|
|
94
|
+
this.lastIndex = 0
|
|
95
|
+
return null
|
|
96
|
+
}
|
|
97
|
+
this.lastIndex = span[1]
|
|
98
|
+
const match = [s.slice(span[0], span[1])]
|
|
99
|
+
match.index = span[0]
|
|
100
|
+
match.input = s
|
|
101
|
+
return match
|
|
102
|
+
},
|
|
103
|
+
test(s) {
|
|
104
|
+
return findJwtSpan(String(s), 0) !== null
|
|
105
|
+
},
|
|
106
|
+
[Symbol.replace](s, replacement) {
|
|
107
|
+
s = String(s)
|
|
108
|
+
let out = ''
|
|
109
|
+
let last = 0
|
|
110
|
+
for (let span = findJwtSpan(s, 0); span; span = findJwtSpan(s, last)) {
|
|
111
|
+
out += s.slice(last, span[0]) + replacement
|
|
112
|
+
last = span[1]
|
|
113
|
+
}
|
|
114
|
+
return last === 0 ? s : out + s.slice(last)
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
|
|
26
118
|
// Provider API key patterns (#2961). These run separately so we can emit a
|
|
27
119
|
// bare "[REDACTED]" regardless of any surrounding key/value syntax — the raw
|
|
28
120
|
// key often appears mid-sentence in stderr (e.g., "invalid api key sk-...").
|
|
@@ -45,7 +137,8 @@ const API_KEY_PATTERNS = [
|
|
|
45
137
|
// marker). header.payload.signature, each base64url; the header always starts
|
|
46
138
|
// `eyJ` (base64 of `{"`), which makes this specific enough to avoid matching
|
|
47
139
|
// ordinary dotted tokens. Length floors keep it off short `a.b.c` strings.
|
|
48
|
-
|
|
140
|
+
// Matched by a linear scan rather than a regex: see JWT_PATTERN above.
|
|
141
|
+
JWT_PATTERN,
|
|
49
142
|
// #5413: Discord webhook URLs. The token segment after the numeric webhook
|
|
50
143
|
// id grants post/edit/delete on the channel, so the URL is a credential.
|
|
51
144
|
// Covers discordapp.com (legacy), ptb/canary builds, and optional /vN/ API
|
|
@@ -126,9 +219,13 @@ const MAX_SANITIZE_DEPTH = 8
|
|
|
126
219
|
*/
|
|
127
220
|
function redactDeep(value, depth, seen, maxChars = MAX_INPUT_CHARS) {
|
|
128
221
|
if (typeof value === 'string') {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
222
|
+
// Redact the whole string, then cut the redacted result (`clipRedacted`).
|
|
223
|
+
const { text: redacted, clipped } = redactWhole(value)
|
|
224
|
+
return clipped || redacted.length > maxChars
|
|
225
|
+
// The cap is taken from the text before the unsafe tail, so a value longer than
|
|
226
|
+
// the cap by more than the margin keeps exactly maxChars (and a whole input
|
|
227
|
+
// that is still over the cap is summarized, as it always was).
|
|
228
|
+
? clipRedacted(redacted, maxChars + REDACT_SCAN_MARGIN, '... [truncated]')
|
|
132
229
|
: redacted
|
|
133
230
|
}
|
|
134
231
|
if (!value || typeof value !== 'object') return value
|
|
@@ -189,9 +286,30 @@ function sanitizeToolInput(input, { maxChars = MAX_INPUT_CHARS } = {}) {
|
|
|
189
286
|
// Final size check on the whole object
|
|
190
287
|
const serialized = JSON.stringify(result)
|
|
191
288
|
if (serialized.length > maxChars) {
|
|
192
|
-
return { _truncated: true, summary: serialized.slice(0, maxChars) + '... [truncated]' }
|
|
289
|
+
return markSanitized({ _truncated: true, summary: serialized.slice(0, maxChars) + '... [truncated]' })
|
|
193
290
|
}
|
|
194
|
-
return result
|
|
291
|
+
return markSanitized(result)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* #8503: the objects `sanitizeToolInput` itself returned, by identity. A consumer
|
|
296
|
+
* that keeps a tool input (the permission journal) can then tell the value that was
|
|
297
|
+
* ALREADY broadcast, which it must keep exactly, from a raw one, which it must
|
|
298
|
+
* sanitize first. The answer cannot come from the value's content: a `_truncated`
|
|
299
|
+
* key, a `summary`, any shape at all is something an agent can write into its own
|
|
300
|
+
* tool input, so a content test would let agent-authored data pass for the
|
|
301
|
+
* sanitizer's output (or have the sanitizer's own output re-shaped as if it were
|
|
302
|
+
* the agent's). A WeakSet holds no content, is not serialized, and is not reachable
|
|
303
|
+
* from a tool input.
|
|
304
|
+
*/
|
|
305
|
+
const SANITIZED_INPUTS = new WeakSet()
|
|
306
|
+
function markSanitized(value) {
|
|
307
|
+
SANITIZED_INPUTS.add(value)
|
|
308
|
+
return value
|
|
309
|
+
}
|
|
310
|
+
/** @param {unknown} value @returns {boolean} true only for an object `sanitizeToolInput` returned (this process, not a copy of it) */
|
|
311
|
+
function isSanitizedToolInput(value) {
|
|
312
|
+
return !!value && typeof value === 'object' && SANITIZED_INPUTS.has(value)
|
|
195
313
|
}
|
|
196
314
|
|
|
197
315
|
/**
|
|
@@ -203,4 +321,238 @@ function sanitizeToolInput(input, { maxChars = MAX_INPUT_CHARS } = {}) {
|
|
|
203
321
|
*/
|
|
204
322
|
const PULL_MAX_INPUT_CHARS = 512 * 1024 // 512K chars
|
|
205
323
|
|
|
206
|
-
|
|
324
|
+
/**
|
|
325
|
+
* How many characters of redacted text the callers that keep a field for display
|
|
326
|
+
* or for a record keep: an OUTPUT budget, applied after the whole text is redacted.
|
|
327
|
+
*/
|
|
328
|
+
export const REDACT_KEEP_MAX = 8192
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* The most text the pattern redactor is ever handed in one call, in characters. It
|
|
332
|
+
* is an admission ceiling for pathological sizes, far above any text a caller shows
|
|
333
|
+
* or keeps: matching is linear, so text up to the ceiling is redacted WHOLE and the
|
|
334
|
+
* caller cuts the redacted result afterwards, which cannot expose a secret.
|
|
335
|
+
*/
|
|
336
|
+
export const REDACT_ADMISSION_MAX = 4 * 1024 * 1024
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* The part of `text` the patterns are handed when no more than `scanMax` characters
|
|
340
|
+
* may be scanned. Text within the bound is returned whole. Longer text is cut at the
|
|
341
|
+
* last whitespace inside the bound, and a run with no whitespace to stop at is
|
|
342
|
+
* discarded, never half-kept, so the cut does not leave the front of a token that the
|
|
343
|
+
* patterns can no longer recognise. This is the only lossy step in redaction, and it
|
|
344
|
+
* applies only past the admission ceiling.
|
|
345
|
+
*
|
|
346
|
+
* @param {string} text
|
|
347
|
+
* @param {number} scanMax
|
|
348
|
+
* @returns {{ text: string, clipped: boolean }}
|
|
349
|
+
*/
|
|
350
|
+
export function scanWindow(text, scanMax) {
|
|
351
|
+
if (text.length <= scanMax) return { text, clipped: false }
|
|
352
|
+
const head = text.slice(0, scanMax)
|
|
353
|
+
const cut = Math.max(head.lastIndexOf(' '), head.lastIndexOf('\n'), head.lastIndexOf('\t'), head.lastIndexOf('\r'))
|
|
354
|
+
return { text: cut > 0 ? head.slice(0, cut) : '', clipped: true }
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* How much of the end of a clipped, redacted result is not kept. A pattern fragment
|
|
359
|
+
* that straddled a cut (the front of a key, an unterminated quoted value) is at most
|
|
360
|
+
* this far from the end of the kept text: the quoted-value bound is 1024 characters
|
|
361
|
+
* and every other pattern needs far less, and replacements before the fragment only
|
|
362
|
+
* shorten the text ahead of it.
|
|
363
|
+
*/
|
|
364
|
+
export const REDACT_SCAN_MARGIN = 2048
|
|
365
|
+
|
|
366
|
+
/** `text` without the last {@link REDACT_SCAN_MARGIN} characters. */
|
|
367
|
+
export function withoutUnsafeTail(text) {
|
|
368
|
+
return text.slice(0, Math.max(0, text.length - REDACT_SCAN_MARGIN))
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* The one rule for every cut of redacted text. Keep at most `max` characters of
|
|
373
|
+
* `redacted`, drop the last {@link REDACT_SCAN_MARGIN} of those, and append `marker`.
|
|
374
|
+
* Callers use it whenever the result is clipped, whether by length or because the
|
|
375
|
+
* tail of the raw text was discarded at the ceiling; unclipped text is returned as it
|
|
376
|
+
* is, without calling this.
|
|
377
|
+
*
|
|
378
|
+
* @param {string} redacted
|
|
379
|
+
* @param {number} max
|
|
380
|
+
* @param {string} [marker]
|
|
381
|
+
* @returns {string}
|
|
382
|
+
*/
|
|
383
|
+
export function clipRedacted(redacted, max, marker = '') {
|
|
384
|
+
return withoutUnsafeTail(redacted.slice(0, Math.max(0, max))) + marker
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Redact the whole of `text`, up to the admission ceiling. `clipped` says the text
|
|
389
|
+
* was longer than the ceiling and its tail was discarded (see {@link scanWindow});
|
|
390
|
+
* the redacted text can then end in a fragment of a match that the discarded tail
|
|
391
|
+
* would have completed, and the caller cuts it with {@link clipRedacted}.
|
|
392
|
+
*
|
|
393
|
+
* @param {unknown} text
|
|
394
|
+
* @param {number} [ceiling]
|
|
395
|
+
* @returns {{ text: string, clipped: boolean }}
|
|
396
|
+
*/
|
|
397
|
+
export function redactWhole(text, ceiling = REDACT_ADMISSION_MAX) {
|
|
398
|
+
const s = typeof text === 'string' ? text : String(text ?? '')
|
|
399
|
+
const window = scanWindow(s, ceiling)
|
|
400
|
+
return { text: redactValue(window.text), clipped: window.clipped }
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Redact the whole of `text` (up to the admission ceiling) and return it, for
|
|
405
|
+
* callers that cut the result themselves. Only text past the ceiling loses its tail
|
|
406
|
+
* first, and then the end of what remains is dropped as well
|
|
407
|
+
* ({@link withoutUnsafeTail}): a fragment of a match the discarded text would have
|
|
408
|
+
* completed is not kept. `max`, when given, is an OUTPUT budget: the redacted result
|
|
409
|
+
* is sliced to it, which keeps the readable prefix and cannot expose a matched secret.
|
|
410
|
+
*
|
|
411
|
+
* @param {unknown} text
|
|
412
|
+
* @param {number} [max]
|
|
413
|
+
* @returns {string}
|
|
414
|
+
*/
|
|
415
|
+
export function redactBounded(text, max) {
|
|
416
|
+
const { text: redacted, clipped } = redactWhole(text)
|
|
417
|
+
const kept = clipped ? withoutUnsafeTail(redacted) : redacted
|
|
418
|
+
return max === undefined ? kept : kept.slice(0, max)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* How much of a permission prompt's identifying field the permission transcript
|
|
423
|
+
* keeps. Applied where the field is produced (so the copy held with a pending
|
|
424
|
+
* prompt is bounded too), and again by the history layer as it records.
|
|
425
|
+
*/
|
|
426
|
+
export const RECORD_DESCRIPTION_MAX = 500
|
|
427
|
+
|
|
428
|
+
/** How much of a serialized input a description shows when no field names the call. */
|
|
429
|
+
const SERIALIZED_DESCRIPTION_MAX = 200
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* The identifying field of a tool input that a permission prompt is described
|
|
433
|
+
* by: the one precedence every producer shares.
|
|
434
|
+
*
|
|
435
|
+
* @param {unknown} rawInput
|
|
436
|
+
* @returns {unknown} the field's value, or undefined when the input has none
|
|
437
|
+
*/
|
|
438
|
+
function namedField(rawInput) {
|
|
439
|
+
if (!rawInput || typeof rawInput !== 'object' || Array.isArray(rawInput)) return undefined
|
|
440
|
+
return rawInput.description || rawInput.command || rawInput.file_path || rawInput.pattern || rawInput.query || undefined
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* The identifying field of a RAW tool input that a permission prompt is
|
|
445
|
+
* described by, redacted and clipped to `RECORD_DESCRIPTION_MAX`; `undefined`
|
|
446
|
+
* when the input has none. Read from the raw input on purpose: the broadcast
|
|
447
|
+
* copy of a large input is replaced by a truncation wrapper that no longer has
|
|
448
|
+
* the field. Redacted before it is clipped, never after.
|
|
449
|
+
*
|
|
450
|
+
* @param {unknown} rawInput
|
|
451
|
+
* @returns {string|undefined}
|
|
452
|
+
*/
|
|
453
|
+
export function describeByNamedField(rawInput) {
|
|
454
|
+
const named = namedField(rawInput)
|
|
455
|
+
return named ? redactBounded(String(named)).slice(0, RECORD_DESCRIPTION_MAX) : undefined
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Bounds on the walk `describeToolInput` makes. Only 200 characters of its
|
|
459
|
+
// result are ever shown, so it needs only the first few entries of an input.
|
|
460
|
+
const DESCRIBE_MAX_ENTRIES = 64
|
|
461
|
+
const OMITTED_TEXT = '[omitted]'
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* A redacted, bounded copy of a tool input for DESCRIBING it (never for
|
|
465
|
+
* broadcast: `sanitizeToolInput` owns that). Every property name and every
|
|
466
|
+
* string value is redacted as the RAW string, before it is JSON-escaped (an
|
|
467
|
+
* escaped `\n` hides a credential from patterns that expect a word boundary) and
|
|
468
|
+
* before it is shortened (a clip can leave a prefix no pattern recognises). A
|
|
469
|
+
* string is redacted whole by `redactBounded` before it is shortened.
|
|
470
|
+
*
|
|
471
|
+
* @param {*} value
|
|
472
|
+
* @param {number} depth
|
|
473
|
+
* @param {WeakSet} seen
|
|
474
|
+
* @param {{ left: number }} budget entries still to be read, shared across the walk
|
|
475
|
+
* @returns {*}
|
|
476
|
+
*/
|
|
477
|
+
function redactedForDescription(value, depth, seen, budget) {
|
|
478
|
+
if (typeof value === 'string') {
|
|
479
|
+
const text = redactBounded(value)
|
|
480
|
+
return value && !text ? OMITTED_TEXT : text.slice(0, SERIALIZED_DESCRIPTION_MAX)
|
|
481
|
+
}
|
|
482
|
+
if (value === null || typeof value === 'number' || typeof value === 'boolean') return value
|
|
483
|
+
if (typeof value !== 'object') return String(value)
|
|
484
|
+
if (depth >= MAX_SANITIZE_DEPTH) return '[REDACTED:depth]'
|
|
485
|
+
if (seen.has(value)) return '[REDACTED:cycle]'
|
|
486
|
+
seen.add(value)
|
|
487
|
+
let out
|
|
488
|
+
if (Array.isArray(value)) {
|
|
489
|
+
out = []
|
|
490
|
+
for (const item of value) {
|
|
491
|
+
if (budget.left <= 0) break
|
|
492
|
+
budget.left -= 1
|
|
493
|
+
out.push(redactedForDescription(item, depth + 1, seen, budget))
|
|
494
|
+
}
|
|
495
|
+
} else {
|
|
496
|
+
out = Object.create(null)
|
|
497
|
+
for (const [key, child] of Object.entries(value)) {
|
|
498
|
+
if (budget.left <= 0) break
|
|
499
|
+
budget.left -= 1
|
|
500
|
+
const name = redactedForDescription(key, depth + 1, seen, budget)
|
|
501
|
+
out[name] = SENSITIVE_KEY_NAMES.has(key.toLowerCase())
|
|
502
|
+
? '[REDACTED]'
|
|
503
|
+
: redactedForDescription(child, depth + 1, seen, budget)
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
seen.delete(value)
|
|
507
|
+
return out
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* The human-readable `description` of a permission prompt, derived from its
|
|
512
|
+
* tool input. The ONE place a producer (in-process sdk/byok/codex, hook-routed
|
|
513
|
+
* claude-tui/claude-cli) builds it, so what a description may carry is decided
|
|
514
|
+
* once.
|
|
515
|
+
*
|
|
516
|
+
* - An input with an identifying field (command, file_path, ...) is described by
|
|
517
|
+
* that field, redacted whole, then clipped.
|
|
518
|
+
* - Anything else is described by a structurally redacted copy of the input
|
|
519
|
+
* (`redactedForDescription`), serialized: a value under a sensitive key reads
|
|
520
|
+
* `[REDACTED]` exactly as it does in the prompt's `input`, and secrets in
|
|
521
|
+
* property names are redacted too. The raw input is never serialized, and the
|
|
522
|
+
* sanitizer's size-clipped summary is never used: this walk reads the input
|
|
523
|
+
* itself, redacting each string whole before it is shortened.
|
|
524
|
+
*
|
|
525
|
+
* The serialization is scanned once more (defence in depth), then clipped to the
|
|
526
|
+
* length a client shows.
|
|
527
|
+
*
|
|
528
|
+
* @param {unknown} rawInput
|
|
529
|
+
* @param {string} [emptyFallback] returned when the input has nothing to describe
|
|
530
|
+
* @returns {string}
|
|
531
|
+
*/
|
|
532
|
+
export function describeToolInput(rawInput, emptyFallback = '') {
|
|
533
|
+
const named = namedField(rawInput)
|
|
534
|
+
if (named) {
|
|
535
|
+
const text = redactBounded(String(named), REDACT_KEEP_MAX)
|
|
536
|
+
if (text) return text
|
|
537
|
+
}
|
|
538
|
+
if (rawInput && typeof rawInput === 'object' && Object.keys(rawInput).length > 0) {
|
|
539
|
+
const walked = redactedForDescription(rawInput, 0, new WeakSet(), { left: DESCRIBE_MAX_ENTRIES })
|
|
540
|
+
return redactValue(JSON.stringify(walked)).slice(0, SERIALIZED_DESCRIPTION_MAX)
|
|
541
|
+
}
|
|
542
|
+
return emptyFallback
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* A prompt description composed by a producer from its own fields (not derived
|
|
547
|
+
* from a tool input): redacted whole, then clipped to the length
|
|
548
|
+
* a client shows. The MCP trust prompt uses it, so every description follows one
|
|
549
|
+
* policy.
|
|
550
|
+
*
|
|
551
|
+
* @param {unknown} text
|
|
552
|
+
* @returns {string}
|
|
553
|
+
*/
|
|
554
|
+
export function describeComposedText(text) {
|
|
555
|
+
return redactBounded(text).slice(0, SERIALIZED_DESCRIPTION_MAX)
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
export { SENSITIVE_PATTERNS, API_KEY_PATTERNS, JWT_PATTERN, SENSITIVE_KEY_NAMES, sanitizeToolInput, isSanitizedToolInput, PULL_MAX_INPUT_CHARS, MAX_INPUT_CHARS }
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { getRegisteredProviderNames } from './providers.js'
|
|
2
|
+
import { isClaudeProvider, usesDefaultModelsRegistry, resolveRosterProvider } from './models.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* #7722 — the provider a client is currently looking at, or null when it has no
|
|
6
|
+
* active session. Null is NOT an error signal: it is the "no session yet" case,
|
|
7
|
+
* which `overlayBroadcastReachesProvider` routes to the default roster exactly
|
|
8
|
+
* as the pre-#7722 broadcast did.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately fail-OPEN toward that default: a session lookup that throws (or a
|
|
11
|
+
* SessionManager torn down mid-reload) yields null, so the client still receives
|
|
12
|
+
* the Claude roster it would have received before this change rather than
|
|
13
|
+
* silently receiving nothing.
|
|
14
|
+
*
|
|
15
|
+
* @param {{ activeSessionId?: string|null }} client
|
|
16
|
+
* @param {{ getSession?: (id: string) => ({ provider?: string|null }|undefined) }} sessionManager
|
|
17
|
+
* @returns {string|null}
|
|
18
|
+
*/
|
|
19
|
+
export function clientActiveProvider(client, sessionManager) {
|
|
20
|
+
try {
|
|
21
|
+
const sessionId = client?.activeSessionId
|
|
22
|
+
if (!sessionId) return null
|
|
23
|
+
return sessionManager?.getSession?.(sessionId)?.provider || null
|
|
24
|
+
} catch {
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* #7722 — the recipient rule for ONE `available_models` roster broadcast: does
|
|
31
|
+
* a client whose ACTIVE session runs `activeProvider` receive this message?
|
|
32
|
+
*
|
|
33
|
+
* The rule:
|
|
34
|
+
* - the DEFAULT (Claude) roster reaches every client whose active provider
|
|
35
|
+
* shares the default registry — Claude-family, an unknown/unregistered
|
|
36
|
+
* name, and no active session at all.
|
|
37
|
+
* - every other tag names a PER-PROVIDER registry, and those are keyed by
|
|
38
|
+
* name (`providerRegistryCache`), so only that exact provider matches.
|
|
39
|
+
*
|
|
40
|
+
* `usesDefaultModelsRegistry` is imported rather than re-derived: it is the same
|
|
41
|
+
* predicate `reloadModelsOverlay` uses to decide which rosters are worth
|
|
42
|
+
* reporting, and a second copy here would be free to disagree about the
|
|
43
|
+
* unknown-name and docker-* edges that motivate it.
|
|
44
|
+
*
|
|
45
|
+
* A throw resolves to the default roster (fail-open) — see `clientActiveProvider`'s
|
|
46
|
+
* docstring for why: `WsBroadcaster._broadcast`'s filter SKIPS a client whose
|
|
47
|
+
* filter threw, which would deliver *nothing* to a client that received the
|
|
48
|
+
* `claude-sdk` roster before #7722.
|
|
49
|
+
*
|
|
50
|
+
* @param {{ provider?: string|null }} message one roster broadcast (this
|
|
51
|
+
* module's `message` shape, or one entry from `buildOverlayReloadBroadcasts`)
|
|
52
|
+
* @param {string|null|undefined} activeProvider the client's active session provider
|
|
53
|
+
* @param {boolean} [tagIsDefault] precomputed `usesDefaultModelsRegistry(message.provider)`.
|
|
54
|
+
* Omit it and the same value is derived here — callers that route many clients
|
|
55
|
+
* through one message pass it so the tag is resolved once.
|
|
56
|
+
* @returns {boolean}
|
|
57
|
+
*/
|
|
58
|
+
export function overlayBroadcastReachesProvider(message, activeProvider, tagIsDefault) {
|
|
59
|
+
const tag = message?.provider ?? null
|
|
60
|
+
const isDefaultTag = tagIsDefault === undefined ? usesDefaultModelsRegistry(tag) : tagIsDefault
|
|
61
|
+
if (!isDefaultTag) return activeProvider === tag
|
|
62
|
+
try {
|
|
63
|
+
return usesDefaultModelsRegistry(activeProvider)
|
|
64
|
+
} catch {
|
|
65
|
+
// Fail OPEN toward the default roster — see the paragraph above.
|
|
66
|
+
return true
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* #7895 — the single per-recipient tagging routine for an `available_models`
|
|
72
|
+
* roster broadcast.
|
|
73
|
+
*
|
|
74
|
+
* #7756's `createOverlayReloadBroadcaster` (server-cli.js) first solved this
|
|
75
|
+
* for the models-overlay hot-reload path: `claude-sdk`, `claude-cli`,
|
|
76
|
+
* `claude-tui` and `claude-byok` all share ONE registry, so
|
|
77
|
+
* `overlayBroadcastReachesProvider` correctly decides all four should receive
|
|
78
|
+
* a default-registry roster — but the client keys each roster by the EXACT tag
|
|
79
|
+
* it arrived under (`modelsByProvider`, store-core/src/models-by-provider.ts),
|
|
80
|
+
* so a single literal tag never refreshes the other three clients' OWN bucket
|
|
81
|
+
* even though routing already decided they should receive something. #7895
|
|
82
|
+
* found two MORE `available_models` send sites with the identical hardcoded-tag
|
|
83
|
+
* shape (`ws-forwarding.js`'s `models_updated` forward and its legacy
|
|
84
|
+
* single-session path) — this function is the ONE place all of them now
|
|
85
|
+
* resolve a recipient's tag, instead of a third hand-rolled copy of the same
|
|
86
|
+
* per-recipient loop.
|
|
87
|
+
*
|
|
88
|
+
* Given ONE roster message (whatever its `provider` tag), sends it to every
|
|
89
|
+
* relevant client:
|
|
90
|
+
* - a NON-default tag (a real per-provider registry, e.g. `codex`) reaches
|
|
91
|
+
* only the exact-match clients, tag unchanged — `overlayBroadcastReachesProvider`
|
|
92
|
+
* already decided that's correct and no re-tagging is needed.
|
|
93
|
+
* - the DEFAULT (Claude-family) tag is instead RE-SENT once per known
|
|
94
|
+
* Claude-family provider name, each copy re-tagged with that name and
|
|
95
|
+
* filtered to the clients `resolveRosterProvider` resolves to it — so a
|
|
96
|
+
* reload/refresh and a reconnect agree on what a session's roster is
|
|
97
|
+
* called. A residual broadcast (tagged with the message's own literal)
|
|
98
|
+
* covers whatever does not resolve to a known tag — an unregistered/custom
|
|
99
|
+
* provider name, or one whose own registry build throws — preserving
|
|
100
|
+
* fail-open delivery for that edge case.
|
|
101
|
+
*
|
|
102
|
+
* The concrete known-tag set is derived from the provider REGISTRY
|
|
103
|
+
* (`getRegisteredProviderNames` + `isClaudeProvider`, #5858's single source of
|
|
104
|
+
* truth), never a hand-maintained name literal — the exact defect class #5855
|
|
105
|
+
* fixed for `isClaudeProvider` itself.
|
|
106
|
+
*
|
|
107
|
+
* @param {object} deps
|
|
108
|
+
* @param {(msg: object, filter?: (client: object) => boolean) => void} deps.broadcast
|
|
109
|
+
* the caller's broadcast primitive — `wsServer._broadcast` /
|
|
110
|
+
* `ctx.broadcast`, both already `(msg, filter) => void`.
|
|
111
|
+
* @param {object} deps.sessionManager
|
|
112
|
+
* @param {string|null} [deps.defaultProvider] - this daemon's resolved default
|
|
113
|
+
* (`resolveDaemonDefaultProvider(config)`, `./providers.js`) — the same value
|
|
114
|
+
* `ws-history.js` feeds `resolveRosterProvider` via
|
|
115
|
+
* `billingCanary.defaultProvider`. Omitted, `resolveRosterProvider` falls
|
|
116
|
+
* back to `DEFAULT_PROVIDER` itself.
|
|
117
|
+
* @param {{ type: string, models: Array, defaultModel?: string|null, provider?: string|null }} deps.message
|
|
118
|
+
* @returns {void}
|
|
119
|
+
*/
|
|
120
|
+
export function broadcastRosterPerRecipient({ broadcast, sessionManager, defaultProvider = null, message }) {
|
|
121
|
+
const tagIsDefault = usesDefaultModelsRegistry(message?.provider ?? null)
|
|
122
|
+
|
|
123
|
+
if (!tagIsDefault) {
|
|
124
|
+
// Per-provider (non-default) roster: the tag already names the exact
|
|
125
|
+
// registry it came from, so the recipient's own provider must match it
|
|
126
|
+
// exactly. No re-tagging needed: a codex roster is never right for anyone
|
|
127
|
+
// but a codex session.
|
|
128
|
+
broadcast(message, (client) => overlayBroadcastReachesProvider(
|
|
129
|
+
message,
|
|
130
|
+
clientActiveProvider(client, sessionManager),
|
|
131
|
+
tagIsDefault,
|
|
132
|
+
))
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// The concrete Claude-family names this daemon currently has registered
|
|
137
|
+
// (built-ins + docker-* once registerDockerProvider() has run + any
|
|
138
|
+
// config-driven endpoint), INCLUDING claude-byok — same registry as
|
|
139
|
+
// claude-sdk/cli/tui. Read fresh on every call rather than cached, so a
|
|
140
|
+
// provider registered after this module was first imported (docker-*,
|
|
141
|
+
// hot-registered endpoints) is still covered.
|
|
142
|
+
const knownTags = new Set(
|
|
143
|
+
getRegisteredProviderNames().filter((name) => isClaudeProvider(name)),
|
|
144
|
+
)
|
|
145
|
+
// The tag a client with no active session — or a session reporting no
|
|
146
|
+
// provider — is served. Same resolution `ws-history.js` uses on connect, so
|
|
147
|
+
// an idle client's bucket key matches whichever of the two sent last.
|
|
148
|
+
//
|
|
149
|
+
// Only added when it NAMES the default registry — i.e. when this daemon's
|
|
150
|
+
// own configured default is itself Claude-family (the ordinary case:
|
|
151
|
+
// DEFAULT_PROVIDER is 'claude-sdk') or an unregistered/custom name (which
|
|
152
|
+
// `getRegistryForProvider` also falls back to the default registry for).
|
|
153
|
+
// A daemon explicitly defaulted to a REAL non-Claude provider (`--provider
|
|
154
|
+
// codex`) resolves this to `'codex'` — a REGISTERED tag with its OWN
|
|
155
|
+
// registry and its own real recipients. Adding it unconditionally used to
|
|
156
|
+
// re-tag THIS Claude roster as `'codex'` and hand it to every codex-active
|
|
157
|
+
// (and idle) client on that daemon: a Claude model list filed under the
|
|
158
|
+
// exact bucket key a codex session reads, with `set_model` live on tap —
|
|
159
|
+
// the precise cross-provider leak #7728 exists to prevent, reintroduced by
|
|
160
|
+
// this fallback tag. An idle client on such a daemon has no business
|
|
161
|
+
// receiving a Claude roster at all (ws-history.js's connect path would tag
|
|
162
|
+
// ITS roster 'codex' too, from the codex registry, never Claude) — it falls
|
|
163
|
+
// through to the residual broadcast below instead, tagged with the
|
|
164
|
+
// message's own literal, which no codex session's bucket key matches.
|
|
165
|
+
const idleTag = resolveRosterProvider(null, defaultProvider)
|
|
166
|
+
if (usesDefaultModelsRegistry(idleTag)) {
|
|
167
|
+
knownTags.add(idleTag)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (const tag of knownTags) {
|
|
171
|
+
broadcast({ ...message, provider: tag }, (client) => resolveRosterProvider(
|
|
172
|
+
clientActiveProvider(client, sessionManager),
|
|
173
|
+
defaultProvider,
|
|
174
|
+
) === tag)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Residual fallback — see the docstring above. `claude-byok` IS in
|
|
178
|
+
// `knownTags`, so it is excluded from the residual by the same generic
|
|
179
|
+
// `knownTags.has(...)` check every other known Claude-family provider is —
|
|
180
|
+
// no separate byok guard needed or wanted.
|
|
181
|
+
broadcast(message, (client) => {
|
|
182
|
+
const activeProvider = clientActiveProvider(client, sessionManager)
|
|
183
|
+
if (knownTags.has(resolveRosterProvider(activeProvider, defaultProvider))) return false
|
|
184
|
+
return overlayBroadcastReachesProvider(message, activeProvider, tagIsDefault)
|
|
185
|
+
})
|
|
186
|
+
}
|