@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/hooks/permission-hook.sh
CHANGED
|
@@ -25,12 +25,52 @@
|
|
|
25
25
|
# args. Do NOT use $1/$2/etc for tool parameters — they are untrusted and could
|
|
26
26
|
# contain shell metacharacters that execute arbitrary commands.
|
|
27
27
|
|
|
28
|
+
# This script reads optional variables and runs commands that are expected to
|
|
29
|
+
# find nothing. A shell that inherits nounset, errexit or pipefail (bash takes
|
|
30
|
+
# them from an exported SHELLOPTS) would turn those into a failed hook, so they
|
|
31
|
+
# are switched off here whatever the environment says.
|
|
32
|
+
set +e +u
|
|
33
|
+
set +o pipefail 2>/dev/null
|
|
34
|
+
|
|
28
35
|
# If CHROXY_PORT is not set, this isn't a Chroxy session — exit silently
|
|
29
36
|
# so Claude Code uses its normal permission flow without showing a hook prompt.
|
|
30
37
|
if [ -z "$CHROXY_PORT" ]; then
|
|
31
38
|
exit 0
|
|
32
39
|
fi
|
|
33
40
|
|
|
41
|
+
# #8263: inside a chroxy-managed claude-tui child, only the copy THIS session's
|
|
42
|
+
# own --settings file registers may decide. That copy is invoked with
|
|
43
|
+
# `--session-settings` (SESSION_SETTINGS_HOOK_MARKER in claude-tui/pty-driver.js,
|
|
44
|
+
# written by writeHookSettings). The child also loads the user-level
|
|
45
|
+
# ~/.claude/settings.json, and a chroxy hook entry orphaned there by a claude-cli
|
|
46
|
+
# session that exited uncleanly (#3714) would run this same script a second time
|
|
47
|
+
# per tool call: two permission prompts, and the duplicate wins the
|
|
48
|
+
# AskUserQuestion sibling lock so the user's answer is refused. An UNMARKED
|
|
49
|
+
# invocation in a TUI child therefore exits here, silently: exit 0 with no
|
|
50
|
+
# output is "no decision" to Claude Code, which leaves the marked copy's
|
|
51
|
+
# allow/deny in force. No request is made to /permission or /permission-floor.
|
|
52
|
+
#
|
|
53
|
+
# This cannot weaken the floor: the marked copy runs the whole script below
|
|
54
|
+
# unchanged (floor probe included). Everything OUTSIDE a TUI child — claude-cli,
|
|
55
|
+
# whose legitimate registration IS the user-level file and whose env never sets
|
|
56
|
+
# CHROXY_TUI_CHILD, and plain Claude Code — is untouched. The failure direction
|
|
57
|
+
# is the old behavior: if CHROXY_TUI_CHILD is missing (a child spawned by an
|
|
58
|
+
# older daemon) the guard does not fire and both copies run as before.
|
|
59
|
+
#
|
|
60
|
+
# The only thing compared here is a fixed token against the script's own
|
|
61
|
+
# arguments; tool parameters still arrive only via stdin (see SECURITY below).
|
|
62
|
+
if [ "$CHROXY_TUI_CHILD" = "1" ]; then
|
|
63
|
+
SESSION_SETTINGS_COPY=0
|
|
64
|
+
for hook_arg in "$@"; do
|
|
65
|
+
if [ "$hook_arg" = "--session-settings" ]; then
|
|
66
|
+
SESSION_SETTINGS_COPY=1
|
|
67
|
+
fi
|
|
68
|
+
done
|
|
69
|
+
if [ "$SESSION_SETTINGS_COPY" != "1" ]; then
|
|
70
|
+
exit 0
|
|
71
|
+
fi
|
|
72
|
+
fi
|
|
73
|
+
|
|
34
74
|
PORT="$CHROXY_PORT"
|
|
35
75
|
TOKEN="$CHROXY_HOOK_SECRET"
|
|
36
76
|
# Where the daemon's HTTP endpoints live, from this process's point of view.
|
|
@@ -51,12 +91,13 @@ case "$HOOK_HOST" in
|
|
|
51
91
|
esac
|
|
52
92
|
# Permission mode resolution order:
|
|
53
93
|
# 1. CHROXY_PERMISSION_MODE_FILE — if set AND readable AND non-empty.
|
|
54
|
-
#
|
|
55
|
-
# is called mid-session, since
|
|
56
|
-
#
|
|
57
|
-
# 2. CHROXY_PERMISSION_MODE env var — the value at session-spawn time
|
|
58
|
-
#
|
|
59
|
-
# initial value for
|
|
94
|
+
# BOTH hook-routed providers write this sidecar when setPermissionMode()
|
|
95
|
+
# is called mid-session, since a running subprocess's env can't be mutated
|
|
96
|
+
# from outside: ClaudeTuiSession since #4013, CliSession since #7337.
|
|
97
|
+
# 2. CHROXY_PERMISSION_MODE env var — the value at session-spawn time, and
|
|
98
|
+
# the fallback whenever the sidecar is missing or unreadable. Also the
|
|
99
|
+
# initial value for both providers, and the ONLY channel inside a
|
|
100
|
+
# container (DockerSession cannot mount the host's sidecar path).
|
|
60
101
|
# 3. "approve" — default if nothing else is set.
|
|
61
102
|
PERM_MODE=""
|
|
62
103
|
if [ -n "$CHROXY_PERMISSION_MODE_FILE" ] && [ -r "$CHROXY_PERMISSION_MODE_FILE" ]; then
|
|
@@ -235,6 +276,30 @@ emit_unreachable_fallback() {
|
|
|
235
276
|
exit 0
|
|
236
277
|
}
|
|
237
278
|
|
|
279
|
+
# #7044: the daemon answered /permission with a non-200 (400 unparseable, 413
|
|
280
|
+
# oversize, 5xx fault, ...). No human saw this request, so say so honestly — and
|
|
281
|
+
# ALWAYS deny, whatever CHROXY_HOOK_UNREACHABLE_DECISION says. $1 is the status
|
|
282
|
+
# (three digits, or "unknown"), so the reason stays valid JSON.
|
|
283
|
+
emit_daemon_rejected_deny() {
|
|
284
|
+
printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"Chroxy could not process the permission request (HTTP %s). Failing closed (denied)."}}\n' "$1"
|
|
285
|
+
exit 0
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
# #8529: curl hit its own --max-time (exit 28) after it had begun uploading the
|
|
289
|
+
# request, and no complete response had arrived. The evidence is exactly that and
|
|
290
|
+
# no more: a positive uploaded-byte count means curl wrote bytes into the socket.
|
|
291
|
+
# It does not show that the whole request left, that the daemon read any of it,
|
|
292
|
+
# or that a prompt was shown. So the wording claims neither delivery nor
|
|
293
|
+
# non-delivery: it must not say the request never reached the phone (it may have
|
|
294
|
+
# been on screen the whole time), and it must not say it did. ALWAYS deny,
|
|
295
|
+
# whatever CHROXY_HOOK_UNREACHABLE_DECISION says: a wait that ran its full length
|
|
296
|
+
# after the request started is the no-answer case, which the daemon itself
|
|
297
|
+
# answers with a deny, and losing that reply must not turn it into an "ask".
|
|
298
|
+
emit_transport_timeout_deny() {
|
|
299
|
+
printf '%s\n' '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"Chroxy began sending the permission request, but did not receive a complete response before the wait expired. Failing closed (denied)."}}'
|
|
300
|
+
exit 0
|
|
301
|
+
}
|
|
302
|
+
|
|
238
303
|
# ---- Shared: route a permission request to the phone via HTTP ----
|
|
239
304
|
# Expects $REQUEST to contain the JSON body to POST.
|
|
240
305
|
# Outputs the appropriate hookSpecificOutput JSON and exits.
|
|
@@ -245,19 +310,90 @@ route_to_phone() {
|
|
|
245
310
|
# curl fail with E2BIG on a big write and the hook then reported the
|
|
246
311
|
# fail-closed deny instead of prompting. Identical bytes either way for a
|
|
247
312
|
# normal payload.
|
|
248
|
-
|
|
313
|
+
# #8529: --max-time is one layer of three, and the order is what matters:
|
|
314
|
+
# daemon no-answer timer (300 s) < this --max-time (310 s) < the `timeout`
|
|
315
|
+
# Claude Code is given for this hook (330 s).
|
|
316
|
+
# The daemon's timer answers a request nobody answered; this has to still be
|
|
317
|
+
# listening when it does. At 300 it was not: curl's clock starts before the
|
|
318
|
+
# daemon's, so curl gave up a few milliseconds before the reply was written.
|
|
319
|
+
# The 10 s between the first two is a margin, not a guarantee: a daemon whose
|
|
320
|
+
# timer fires more than that late still loses to this deadline, and the hook
|
|
321
|
+
# then reports the transport timeout below (a deny either way).
|
|
322
|
+
# The numbers live in src/permission-deadlines.js, and
|
|
323
|
+
# tests/permission-deadline-chain.test.js runs this script and fails if the
|
|
324
|
+
# value handed to curl here stops matching.
|
|
325
|
+
CURL_ARGS=(-s -X POST "http://${HOOK_HOST}:${PORT}/permission" -H "Content-Type: application/json" --data-binary @- --max-time 310)
|
|
249
326
|
if [ -n "$TOKEN" ]; then
|
|
250
327
|
CURL_ARGS+=(-H "Authorization: Bearer ${TOKEN}")
|
|
251
328
|
fi
|
|
252
329
|
|
|
253
|
-
|
|
330
|
+
# #7044: also capture the HTTP status. `-w` appends a trailer line after the
|
|
331
|
+
# body, "\n<code> <bytes uploaded>", so the last line is curl's own and
|
|
332
|
+
# everything before it is the body. Only a 200 can carry a decision a human
|
|
333
|
+
# made; the daemon also answers {"decision":"deny"} with a 400 (unparseable
|
|
334
|
+
# body), 413 (oversize body) and 5xx (daemon fault), none of which ever reached
|
|
335
|
+
# the phone. curl writes the trailer on a failed transfer too (code 000).
|
|
336
|
+
CURL_ARGS+=(-w $'\n%{http_code} %{size_upload}')
|
|
337
|
+
RESPONSE_AND_CODE=$(printf '%s' "$REQUEST" | curl "${CURL_ARGS[@]}")
|
|
254
338
|
EXIT_CODE=$?
|
|
339
|
+
CURL_TRAILER="${RESPONSE_AND_CODE##*$'\n'}"
|
|
255
340
|
|
|
256
341
|
if [ $EXIT_CODE -ne 0 ]; then
|
|
257
|
-
#
|
|
342
|
+
# #8529: curl's exit 28 is its own deadline. What it had seen by then decides
|
|
343
|
+
# the wording, and both outcomes selected here DENY. Both facts are read only
|
|
344
|
+
# from a well-formed trailer ("<3 digits> <digits>"); anything else (and a
|
|
345
|
+
# 200 with no byte uploaded) is not proof of either and falls through to the
|
|
346
|
+
# unreachable handling below, unchanged, opt-out included.
|
|
347
|
+
# - A final non-200 status had already arrived (the daemon sent 401/429/5xx
|
|
348
|
+
# headers and then stalled): that is the daemon's rejection, so keep the
|
|
349
|
+
# status visible, exactly as a completed non-200 reads (#7044).
|
|
350
|
+
# - Otherwise, if curl had BEGUN SENDING the request (uploaded-byte count
|
|
351
|
+
# above zero): a transport timeout, not an unreachable daemon. The count
|
|
352
|
+
# shows the upload started, not that it finished or was read. This
|
|
353
|
+
# includes a 200 whose body never completed. The body is not read on this
|
|
354
|
+
# path, so a partial body cannot allow.
|
|
355
|
+
if [ $EXIT_CODE -eq 28 ]; then
|
|
356
|
+
TIMEOUT_STATUS=""
|
|
357
|
+
BYTES_SENT=""
|
|
358
|
+
case "$CURL_TRAILER" in
|
|
359
|
+
[0-9][0-9][0-9]' '*)
|
|
360
|
+
TIMEOUT_STATUS="${CURL_TRAILER%% *}"
|
|
361
|
+
BYTES_SENT="${CURL_TRAILER#* }"
|
|
362
|
+
;;
|
|
363
|
+
esac
|
|
364
|
+
case "$BYTES_SENT" in
|
|
365
|
+
''|*[!0-9]*) TIMEOUT_STATUS=""; BYTES_SENT="" ;;
|
|
366
|
+
esac
|
|
367
|
+
case "$TIMEOUT_STATUS" in
|
|
368
|
+
200) ;;
|
|
369
|
+
[2-5][0-9][0-9]) emit_daemon_rejected_deny "$TIMEOUT_STATUS" ;;
|
|
370
|
+
esac
|
|
371
|
+
case "$BYTES_SENT" in
|
|
372
|
+
''|0*) ;;
|
|
373
|
+
*) emit_transport_timeout_deny ;;
|
|
374
|
+
esac
|
|
375
|
+
fi
|
|
376
|
+
# Could not connect (refused, unresolvable, or timed out with no byte
|
|
377
|
+
# uploaded): the request never reached the phone. KNOWN LIMIT: a connection
|
|
378
|
+
# that drops after the upload began (curl 52/56) also lands here and keeps
|
|
379
|
+
# this wording.
|
|
258
380
|
emit_unreachable_fallback "Chroxy could not reach the daemon to request your approval; the request never reached your phone. Failing closed (denied). Retry once Chroxy is reachable."
|
|
259
381
|
fi
|
|
260
382
|
|
|
383
|
+
HTTP_CODE="${CURL_TRAILER%% *}"
|
|
384
|
+
RESPONSE="${RESPONSE_AND_CODE%$'\n'*}"
|
|
385
|
+
# Anything that is not exactly 200 (including a missing/garbled status) is a
|
|
386
|
+
# daemon-side rejection. Always DENY — never the CHROXY_HOOK_UNREACHABLE_DECISION=ask
|
|
387
|
+
# opt-out, which exists for an unreachable daemon, not for one that answered no —
|
|
388
|
+
# and never look at the body: a non-200 must not be able to turn into an allow.
|
|
389
|
+
if [ "$HTTP_CODE" != "200" ]; then
|
|
390
|
+
case "$HTTP_CODE" in
|
|
391
|
+
[0-9][0-9][0-9]) ;;
|
|
392
|
+
*) HTTP_CODE="unknown" ;;
|
|
393
|
+
esac
|
|
394
|
+
emit_daemon_rejected_deny "$HTTP_CODE"
|
|
395
|
+
fi
|
|
396
|
+
|
|
261
397
|
DECISION=$(echo "$RESPONSE" | grep -o '"decision":"[^"]*"' | head -1 | cut -d'"' -f4)
|
|
262
398
|
|
|
263
399
|
case "$DECISION" in
|
|
@@ -267,9 +403,22 @@ route_to_phone() {
|
|
|
267
403
|
EOF
|
|
268
404
|
;;
|
|
269
405
|
deny)
|
|
270
|
-
|
|
406
|
+
# #8529: the daemon's own no-answer timer also answers 200 deny, and marks it
|
|
407
|
+
# "reason":"timeout". Nobody denied that request, so do not say the user did.
|
|
408
|
+
# The field only ever picks the WORDING of a deny: it is read here, inside
|
|
409
|
+
# the deny branch, and matched as the exact token. A daemon that predates
|
|
410
|
+
# the field sends no reason and keeps the wording below. It is extracted by
|
|
411
|
+
# the same token grep as DECISION above, not by a JSON parse.
|
|
412
|
+
DENY_REASON=$(echo "$RESPONSE" | grep -o '"reason":"[^"]*"' | head -1 | cut -d'"' -f4)
|
|
413
|
+
if [ "$DENY_REASON" = "timeout" ]; then
|
|
414
|
+
cat <<EOF
|
|
415
|
+
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"No one answered the Chroxy permission request before it timed out. Failing closed (denied)."}}
|
|
416
|
+
EOF
|
|
417
|
+
else
|
|
418
|
+
cat <<EOF
|
|
271
419
|
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"Denied by user via Chroxy mobile app"}}
|
|
272
420
|
EOF
|
|
421
|
+
fi
|
|
273
422
|
;;
|
|
274
423
|
*)
|
|
275
424
|
# Reached the daemon but got no recognizable decision — also unanswerable
|
|
@@ -309,6 +458,12 @@ EOF
|
|
|
309
458
|
# PROTECTED_PATH_INPUT_FIELDS entry, so extending the floor's field list without
|
|
310
459
|
# updating this line fails CI.
|
|
311
460
|
#
|
|
461
|
+
# #7978 — a Grep is floored on its `glob` too, and a Grep need not carry any path
|
|
462
|
+
# field (`{"pattern":"KEY","glob":".env"}` searches the cwd). So the arm also
|
|
463
|
+
# matches the tool NAME of every GLOB_SELECTOR_FLOOR_TOOLS member rather than a
|
|
464
|
+
# `"glob"` key: the name is present on every call of that tool, whatever fields
|
|
465
|
+
# it carries. The same test asserts every member is matched here.
|
|
466
|
+
#
|
|
312
467
|
# #7020 — the pre-filter's soundness argument ("naming no path field provably
|
|
313
468
|
# cannot be floored") holds only over a COMPLETE, escape-free payload. Two guards
|
|
314
469
|
# below narrow that premise before the negative filter is trusted; both resolve
|
|
@@ -347,7 +502,7 @@ EOF
|
|
|
347
502
|
# payload keeps the no-round-trip path.
|
|
348
503
|
floor_forces_prompt() {
|
|
349
504
|
case "$REQUEST" in
|
|
350
|
-
*'"file_path"'*|*'"path"'*|*'"notebook_path"'*|*'"changes"'*) ;;
|
|
505
|
+
*'"file_path"'*|*'"path"'*|*'"notebook_path"'*|*'"changes"'*|*'"Grep"'*|*'"Glob"'*) ;;
|
|
351
506
|
# (1) a \uXXXX escape may spell a path-naming key the byte scan cannot see.
|
|
352
507
|
# Kept explicit for readability though arm (2) now subsumes it (`u` is not in
|
|
353
508
|
# that arm's negated set), so a `\u` body probes either way.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chroxy/server",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.10",
|
|
4
4
|
"files": [
|
|
5
5
|
"src",
|
|
6
6
|
"hooks",
|
|
@@ -17,21 +17,22 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"start": "node src/cli.js start",
|
|
19
19
|
"dev": "node --watch src/cli.js start",
|
|
20
|
-
"test": "node
|
|
20
|
+
"test": "node ../../scripts/lib/assert-test-count.mjs c8 node --import ./tests/_setup.mjs --experimental-test-module-mocks --test './tests/**/*.test.js'",
|
|
21
21
|
"test:raw": "c8 node --import ./tests/_setup.mjs --experimental-test-module-mocks --test './tests/**/*.test.js'",
|
|
22
|
-
"test:coverage": "c8 --reporter=text --reporter=html node --import ./tests/_setup.mjs --experimental-test-module-mocks --test './tests/**/*.test.js'",
|
|
22
|
+
"test:coverage": "c8 --reporter=text --reporter=html --reporter=lcov --reporter=json-summary node --import ./tests/_setup.mjs --experimental-test-module-mocks --test './tests/**/*.test.js'",
|
|
23
23
|
"test:integration": "node --import ./tests/_setup.mjs --test ./tests/*.integration.test.js",
|
|
24
|
-
"test:integration:k8s": "RUN_K8S_INTEGRATION=1 node --import ./tests/_setup.mjs --test-timeout=840000 --test ./tests/integration/k8s-sidecar-roundtrip.test.js",
|
|
25
|
-
"lint": "eslint src/",
|
|
24
|
+
"test:integration:k8s": "RUN_K8S_INTEGRATION=1 node ../../scripts/lib/assert-test-count.mjs --min 4 --min-passed 4 node --import ./tests/_setup.mjs --test-timeout=840000 --test ./tests/integration/k8s-sidecar-roundtrip.test.js",
|
|
25
|
+
"lint": "eslint src/ tests/ scripts/",
|
|
26
26
|
"postinstall": "node scripts/fix-node-pty-helper.js"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
+
"@agentclientprotocol/sdk": "1.4.0",
|
|
29
30
|
"@anthropic-ai/claude-agent-sdk": "^0.2.0",
|
|
30
|
-
"@anthropic-ai/sdk": "^0.
|
|
31
|
-
"@chroxy/protocol": "^0.11.
|
|
32
|
-
"@chroxy/store-core": "^0.11.
|
|
31
|
+
"@anthropic-ai/sdk": "^0.91.1",
|
|
32
|
+
"@chroxy/protocol": "^0.11.10",
|
|
33
|
+
"@chroxy/store-core": "^0.11.10",
|
|
33
34
|
"@kubernetes/client-node": "^1.4.0",
|
|
34
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
35
|
+
"@modelcontextprotocol/sdk": "^1.32.0",
|
|
35
36
|
"@xterm/addon-fit": "^0.10.0",
|
|
36
37
|
"@xterm/xterm": "^5.5.0",
|
|
37
38
|
"bonjour-service": "^1.3.0",
|
|
@@ -42,8 +43,8 @@
|
|
|
42
43
|
"qrcode": "^1.5.3",
|
|
43
44
|
"tweetnacl": "^1.0.3",
|
|
44
45
|
"tweetnacl-util": "^0.15.1",
|
|
45
|
-
"ws": "^8.
|
|
46
|
-
"zod": "^4.
|
|
46
|
+
"ws": "^8.21.3",
|
|
47
|
+
"zod": "^4.6.6"
|
|
47
48
|
},
|
|
48
49
|
"engines": {
|
|
49
50
|
"node": ">=22"
|
|
@@ -55,8 +56,11 @@
|
|
|
55
56
|
},
|
|
56
57
|
"license": "MIT",
|
|
57
58
|
"devDependencies": {
|
|
59
|
+
"acorn": "8.16.0",
|
|
58
60
|
"c8": "^11.0.0",
|
|
59
61
|
"eslint": "^9.39.3",
|
|
60
|
-
"
|
|
62
|
+
"js-yaml": "^4.1.1",
|
|
63
|
+
"playwright": "^1.58.2",
|
|
64
|
+
"typescript": "^5.9.3"
|
|
61
65
|
}
|
|
62
66
|
}
|
package/sidecar/Dockerfile
CHANGED
|
@@ -7,7 +7,7 @@ LABEL org.opencontainers.image.source=https://github.com/blamechris/chroxy
|
|
|
7
7
|
# docker build --build-arg CLAUDE_CODE_VERSION=x.y.z .
|
|
8
8
|
# Bump this ARG when upgrading claude-code; keep it in sync with the version
|
|
9
9
|
# used by the rest of the server package.
|
|
10
|
-
ARG CLAUDE_CODE_VERSION=2.1.
|
|
10
|
+
ARG CLAUDE_CODE_VERSION=2.1.280
|
|
11
11
|
|
|
12
12
|
# Install claude-code globally so the sidecar can spawn it when K8sBackend
|
|
13
13
|
# sends a spawn frame. This is the only external npm dependency the image
|
package/sidecar/PROTOCOL.md
CHANGED
|
@@ -510,6 +510,14 @@ new one. If all sessions are active, the globally oldest session is evicted:
|
|
|
510
510
|
the agent sends `{ type: 'session_lost', sessionId, reason: 'evicted_by_cap' }`
|
|
511
511
|
to the live consumer before closing the WS with code `1001`.
|
|
512
512
|
|
|
513
|
+
Two sessions can share a `lastActiveAt` — it comes from a clock, and Windows'
|
|
514
|
+
timer granularity is around 15.6ms — so the order is `(lastActiveAt,
|
|
515
|
+
createdSeq)`, where `createdSeq` is a counter the agent increments per session.
|
|
516
|
+
**An equal-timestamp tie is therefore broken by creation order, oldest first.**
|
|
517
|
+
Before #7690 the tie was settled by `Map` iteration order, which gives the same
|
|
518
|
+
answer but as a side effect of the container rather than as a stated rule — so
|
|
519
|
+
nothing documented it and no test could fail on it.
|
|
520
|
+
|
|
513
521
|
`K8sBackend` maps `session_lost` to `exit(-2)` regardless of reason, so the
|
|
514
522
|
caller can distinguish a cap eviction (session-loss semantics) from a
|
|
515
523
|
pre-session connection failure (which maps to `exit(-1)`).
|
|
@@ -650,7 +658,7 @@ EOF and the grace would just be wasted shutdown latency.
|
|
|
650
658
|
## claude-code Version Pinning
|
|
651
659
|
|
|
652
660
|
The `Dockerfile` installs `@anthropic-ai/claude-code` at a fixed version via
|
|
653
|
-
the `CLAUDE_CODE_VERSION` build ARG (default: `2.1.
|
|
661
|
+
the `CLAUDE_CODE_VERSION` build ARG (default: `2.1.280`).
|
|
654
662
|
|
|
655
663
|
**Override at build time:**
|
|
656
664
|
```sh
|
package/sidecar/agent.js
CHANGED
|
@@ -13,9 +13,9 @@ import { createServer } from 'node:http'
|
|
|
13
13
|
import { createInterface } from 'node:readline'
|
|
14
14
|
import { spawn as nodeSpawn } from 'node:child_process'
|
|
15
15
|
import { timingSafeEqual, randomUUID } from 'node:crypto'
|
|
16
|
-
import { readFileSync } from 'node:fs'
|
|
16
|
+
import { readFileSync, realpathSync } from 'node:fs'
|
|
17
17
|
import { fileURLToPath } from 'node:url'
|
|
18
|
-
import { dirname, join } from 'node:path'
|
|
18
|
+
import { basename, dirname, join, resolve } from 'node:path'
|
|
19
19
|
import { Transform } from 'node:stream'
|
|
20
20
|
import { WebSocketServer } from 'ws'
|
|
21
21
|
|
|
@@ -129,6 +129,8 @@ const AGENT_TOKEN = process.env.CHROXY_AGENT_TOKEN ?? null
|
|
|
129
129
|
// environment. The child is the user-facing CLI; agent-internal credentials
|
|
130
130
|
// have no business being readable from inside it.
|
|
131
131
|
const AGENT_SECRET_ENV_KEYS = ['CHROXY_AGENT_TOKEN']
|
|
132
|
+
// Env names a spawn frame may ask the agent to remove from the child's env (`unsetEnv`).
|
|
133
|
+
const UNSETTABLE_ENV_KEYS = new Set(['CLAUDE_CONFIG_DIR'])
|
|
132
134
|
|
|
133
135
|
// Constant-time token comparison — adapted from token-compare.js in the main server.
|
|
134
136
|
function safeTokenCompare(a, b) {
|
|
@@ -232,6 +234,12 @@ export class PodAgent {
|
|
|
232
234
|
* @param {number} [opts.stdinDrainTimeoutMs] Override wedged-child drain timeout in ms (tests).
|
|
233
235
|
* @param {Function} [opts.setTimeoutFn] Override setTimeout for deterministic timer tests.
|
|
234
236
|
* @param {Function} [opts.clearTimeoutFn] Override clearTimeout for deterministic timer tests.
|
|
237
|
+
* @param {Function} [opts.nowFn] Override Date.now for deterministic ACTIVITY tests (#7690).
|
|
238
|
+
* `lastActiveAt` decides which session the size cap evicts,
|
|
239
|
+
* and it is REWRITTEN on every emitted frame — so a test that
|
|
240
|
+
* pins it can have the pin overwritten by a frame that lands
|
|
241
|
+
* a moment later. Injecting the clock is what makes that
|
|
242
|
+
* ordering a property of the test rather than of the machine.
|
|
235
243
|
*/
|
|
236
244
|
constructor({ spawnFn = nodeSpawn, token = AGENT_TOKEN, killGraceMs = KILL_GRACE_MS,
|
|
237
245
|
stdinCloseGraceMs = DEFAULT_STDIN_CLOSE_GRACE_MS,
|
|
@@ -241,7 +249,8 @@ export class PodAgent {
|
|
|
241
249
|
maxSessions = DEFAULT_MAX_SESSIONS,
|
|
242
250
|
stdinDrainTimeoutMs = DEFAULT_STDIN_DRAIN_TIMEOUT_MS,
|
|
243
251
|
setTimeoutFn = setTimeout,
|
|
244
|
-
clearTimeoutFn = clearTimeout
|
|
252
|
+
clearTimeoutFn = clearTimeout,
|
|
253
|
+
nowFn = Date.now } = {}) {
|
|
245
254
|
this._spawnFn = spawnFn
|
|
246
255
|
this._token = token
|
|
247
256
|
this._killGraceMs = killGraceMs
|
|
@@ -268,6 +277,12 @@ export class PodAgent {
|
|
|
268
277
|
: FALLBACK_STDIN_DRAIN_TIMEOUT_MS
|
|
269
278
|
this._setTimeoutFn = setTimeoutFn
|
|
270
279
|
this._clearTimeoutFn = clearTimeoutFn
|
|
280
|
+
this._nowFn = nowFn
|
|
281
|
+
// Monotonic creation counter, used ONLY to break `lastActiveAt` ties in
|
|
282
|
+
// `_enforceSessionCap`. Insertion order already decided them, but only as a
|
|
283
|
+
// side effect of Map iteration — an implicit rule nothing stated and no test
|
|
284
|
+
// could fail on (#7690).
|
|
285
|
+
this._sessionSeq = 0
|
|
271
286
|
|
|
272
287
|
// Fail-secure warning. Emitted from the constructor (not module-load) so
|
|
273
288
|
// tests and embedders that pass an explicit `token` don't see a misleading
|
|
@@ -630,11 +645,21 @@ export class PodAgent {
|
|
|
630
645
|
_enforceSessionCap() {
|
|
631
646
|
if (this._sessions.size < this._maxSessions) return
|
|
632
647
|
|
|
648
|
+
// Strictly older, or the same age and created FIRST. The tie-break is
|
|
649
|
+
// explicit since #7690: `lastActiveAt` comes from a clock, two sessions can
|
|
650
|
+
// share a millisecond (Windows' timer granularity is ~15.6ms), and with a
|
|
651
|
+
// bare `<` the winner was then decided by Map iteration order. That gave the
|
|
652
|
+
// right answer — insertion order IS creation order — but as a side effect
|
|
653
|
+
// nothing stated and no test could fail on. `createdSeq` makes the ordering
|
|
654
|
+
// total, so it is a property of the data rather than of the container.
|
|
655
|
+
const isOlder = (a, b) => a.lastActiveAt < b.lastActiveAt ||
|
|
656
|
+
(a.lastActiveAt === b.lastActiveAt && a.createdSeq < b.createdSeq)
|
|
657
|
+
|
|
633
658
|
// Prefer evicting idle sessions (no activeWs) over live ones.
|
|
634
659
|
let evictTarget = null
|
|
635
660
|
for (const session of this._sessions.values()) {
|
|
636
661
|
if (session.activeWs !== null) continue
|
|
637
|
-
if (evictTarget === null || session
|
|
662
|
+
if (evictTarget === null || isOlder(session, evictTarget)) {
|
|
638
663
|
evictTarget = session
|
|
639
664
|
}
|
|
640
665
|
}
|
|
@@ -642,7 +667,7 @@ export class PodAgent {
|
|
|
642
667
|
// Fall back to evicting the globally oldest session if all are active.
|
|
643
668
|
if (evictTarget === null) {
|
|
644
669
|
for (const session of this._sessions.values()) {
|
|
645
|
-
if (evictTarget === null || session
|
|
670
|
+
if (evictTarget === null || isOlder(session, evictTarget)) {
|
|
646
671
|
evictTarget = session
|
|
647
672
|
}
|
|
648
673
|
}
|
|
@@ -772,7 +797,7 @@ export class PodAgent {
|
|
|
772
797
|
// ---------------------------------------------------------------------------
|
|
773
798
|
|
|
774
799
|
_handleSpawn(ws, msg) {
|
|
775
|
-
const { cmd, args = [], env = {}, cwd, stdin: stdinMode = 'pipe' } = msg
|
|
800
|
+
const { cmd, args = [], env = {}, unsetEnv, cwd, stdin: stdinMode = 'pipe' } = msg
|
|
776
801
|
|
|
777
802
|
if (!cmd) {
|
|
778
803
|
this._send(ws, { type: 'error', message: 'spawn: cmd is required' })
|
|
@@ -815,6 +840,14 @@ export class PodAgent {
|
|
|
815
840
|
stdio: [resolvedStdin, 'pipe', 'pipe'],
|
|
816
841
|
env: { ...sanitizedAgentEnv, ...env },
|
|
817
842
|
}
|
|
843
|
+
// Variables the spawner asks to have removed from the merged env (the agent's
|
|
844
|
+
// own env, e.g. one defined by the image or pod, would otherwise survive).
|
|
845
|
+
// Only an allowlisted name is honoured.
|
|
846
|
+
if (Array.isArray(unsetEnv)) {
|
|
847
|
+
for (const key of unsetEnv) {
|
|
848
|
+
if (UNSETTABLE_ENV_KEYS.has(key)) delete spawnOpts.env[key]
|
|
849
|
+
}
|
|
850
|
+
}
|
|
818
851
|
if (cwd) spawnOpts.cwd = cwd
|
|
819
852
|
|
|
820
853
|
let child
|
|
@@ -839,7 +872,17 @@ export class PodAgent {
|
|
|
839
872
|
activeWs: ws,
|
|
840
873
|
seq: 0,
|
|
841
874
|
buffer: [],
|
|
842
|
-
|
|
875
|
+
// INERT TODAY, and kept deliberately. A stderr frame is emitted
|
|
876
|
+
// immediately after spawn, and `_emitSessionFrame` re-stamps
|
|
877
|
+
// `lastActiveAt`, so this initial value is overwritten before anything
|
|
878
|
+
// can read it — measured by tracing every write on a real spawn, and the
|
|
879
|
+
// reason a mutant that swaps this one call for `Date.now()` survives the
|
|
880
|
+
// suite while the other two do not (#7690 review). It stays on `_nowFn`
|
|
881
|
+
// because a field initialised from a different clock than it is updated
|
|
882
|
+
// from is a trap for the first path that creates a session without
|
|
883
|
+
// emitting, not because a test can currently tell.
|
|
884
|
+
lastActiveAt: this._nowFn(),
|
|
885
|
+
createdSeq: ++this._sessionSeq,
|
|
843
886
|
idleTimer: null,
|
|
844
887
|
// Cooperative backpressure flag for child.stdin.write() (#3396).
|
|
845
888
|
// True while a 'drain' listener is armed and the WS is paused.
|
|
@@ -1166,7 +1209,7 @@ export class PodAgent {
|
|
|
1166
1209
|
|
|
1167
1210
|
// Attach this WS to the session and refresh activity timestamp.
|
|
1168
1211
|
session.activeWs = ws
|
|
1169
|
-
session.lastActiveAt =
|
|
1212
|
+
session.lastActiveAt = this._nowFn()
|
|
1170
1213
|
ws._sessionId = sessionId
|
|
1171
1214
|
|
|
1172
1215
|
// Replay any buffered frames the client hasn't seen yet (seq > lastSeq).
|
|
@@ -1204,7 +1247,7 @@ export class PodAgent {
|
|
|
1204
1247
|
*/
|
|
1205
1248
|
_emitSessionFrame(session, frame, cb) {
|
|
1206
1249
|
session.seq += 1
|
|
1207
|
-
session.lastActiveAt =
|
|
1250
|
+
session.lastActiveAt = this._nowFn()
|
|
1208
1251
|
const seqFrame = { ...frame, seq: session.seq }
|
|
1209
1252
|
|
|
1210
1253
|
// Ring buffer: drop oldest entry when at capacity.
|
|
@@ -1274,7 +1317,56 @@ export class PodAgent {
|
|
|
1274
1317
|
// Entrypoint — only runs when executed directly, not when imported in tests.
|
|
1275
1318
|
// ---------------------------------------------------------------------------
|
|
1276
1319
|
|
|
1277
|
-
|
|
1320
|
+
// Realpath both sides. Node's ESM loader resolves symlinks in
|
|
1321
|
+
// `import.meta.url` while argv[1] is whatever the caller typed, so a raw
|
|
1322
|
+
// comparison also breaks on any relative invocation (`node ./agent.js`).
|
|
1323
|
+
// This is a standalone in-pod bundle with its own package.json, so it cannot
|
|
1324
|
+
// import packages/server/src/utils/is-entry-point.js — duplicated on purpose
|
|
1325
|
+
// (#7213). The body below runs the same code as that file and as
|
|
1326
|
+
// scripts/lib/is-entry-point.mjs — inlined as an IIFE, so it reads
|
|
1327
|
+
// `import.meta.url` directly rather than taking it as a parameter. The drift
|
|
1328
|
+
// gate in scripts/__tests__/is-entry-point.test.mjs compares all three with
|
|
1329
|
+
// comments stripped and fails if they diverge; change one, change all (#7222).
|
|
1330
|
+
const invokedDirectly = (() => {
|
|
1331
|
+
if (!process.argv[1]) return false
|
|
1332
|
+
// The plain comparison runs first and is conclusive on its own: identical
|
|
1333
|
+
// paths mean this IS the entry point, decided without touching the
|
|
1334
|
+
// filesystem. Consulting realpath first and reading a failure as false lets
|
|
1335
|
+
// an EACCES on a parent directory (or a script unlinked after launch) turn a
|
|
1336
|
+
// direct run into a silent exit-0 no-op — the exact class this guard exists
|
|
1337
|
+
// to remove (#7217 review). Realpath is only needed when the paths differ,
|
|
1338
|
+
// where a symlink is the sole thing that can still make them one file.
|
|
1339
|
+
const self = fileURLToPath(import.meta.url)
|
|
1340
|
+
const invoked = resolve(process.argv[1])
|
|
1341
|
+
if (self === invoked) return true
|
|
1342
|
+
const failures = []
|
|
1343
|
+
const real = (p) => {
|
|
1344
|
+
try {
|
|
1345
|
+
return realpathSync(p)
|
|
1346
|
+
} catch (err) {
|
|
1347
|
+
failures.push({ path: p, code: err.code || err.message })
|
|
1348
|
+
return null
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
const realSelf = real(self)
|
|
1352
|
+
const realInvoked = real(invoked)
|
|
1353
|
+
if (realSelf !== null && realInvoked !== null) return realSelf === realInvoked
|
|
1354
|
+
|
|
1355
|
+
// Undecidable, but not silent (#7226): in a pod, an agent that starts and
|
|
1356
|
+
// does nothing is indistinguishable from one that is merely idle, so the
|
|
1357
|
+
// reason has to reach the container log. See the twin in
|
|
1358
|
+
// packages/server/src/utils/is-entry-point.js for why this warns on ANY
|
|
1359
|
+
// realpath failure rather than carving out ENOENT.
|
|
1360
|
+
const why = failures.map(({ path, code }) => `${path}: ${code}`).join('; ')
|
|
1361
|
+
console.warn(
|
|
1362
|
+
`[is-entry-point] ${basename(self)}: cannot determine whether this module was run ` +
|
|
1363
|
+
`directly — realpath failed (${why}). Assuming it was imported, so its command-line ` +
|
|
1364
|
+
'behaviour did NOT run. If you invoked it directly, it did nothing.',
|
|
1365
|
+
)
|
|
1366
|
+
return false
|
|
1367
|
+
})()
|
|
1368
|
+
|
|
1369
|
+
if (invokedDirectly) {
|
|
1278
1370
|
const agent = new PodAgent()
|
|
1279
1371
|
agent.listen(PORT).catch((err) => {
|
|
1280
1372
|
console.error('[chroxy-pod-agent] Failed to start:', err)
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"node_modules/ws": {
|
|
22
|
-
"version": "8.
|
|
23
|
-
"resolved": "https://registry.npmjs.org/ws/-/ws-8.
|
|
24
|
-
"integrity": "sha512-
|
|
22
|
+
"version": "8.21.3",
|
|
23
|
+
"resolved": "https://registry.npmjs.org/ws/-/ws-8.21.3.tgz",
|
|
24
|
+
"integrity": "sha512-201TZ/kPWxoPr/OKWjquZR1SWKXcvxdH+e1xrx89b3YbmzLMFCLfnaG1HFIgWzJOEWZ7MvpK++odZufgYR50Rw==",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"engines": {
|
|
27
27
|
"node": ">=10.0.0"
|