@chroxy/server 0.10.0 → 0.11.0
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 +411 -14
- package/hooks/permission-hook.sh +253 -3
- package/package.json +8 -15
- package/sidecar/node_modules/.package-lock.json +29 -0
- package/sidecar/node_modules/ws/LICENSE +20 -0
- package/sidecar/node_modules/ws/README.md +548 -0
- package/sidecar/node_modules/ws/browser.js +8 -0
- package/sidecar/node_modules/ws/index.js +22 -0
- package/sidecar/node_modules/ws/lib/buffer-util.js +131 -0
- package/sidecar/node_modules/ws/lib/constants.js +19 -0
- package/sidecar/node_modules/ws/lib/event-target.js +292 -0
- package/sidecar/node_modules/ws/lib/extension.js +203 -0
- package/sidecar/node_modules/ws/lib/limiter.js +55 -0
- package/sidecar/node_modules/ws/lib/permessage-deflate.js +528 -0
- package/sidecar/node_modules/ws/lib/receiver.js +706 -0
- package/sidecar/node_modules/ws/lib/sender.js +602 -0
- package/sidecar/node_modules/ws/lib/stream.js +161 -0
- package/sidecar/node_modules/ws/lib/subprotocol.js +62 -0
- package/sidecar/node_modules/ws/lib/validation.js +152 -0
- package/sidecar/node_modules/ws/lib/websocket-server.js +554 -0
- package/sidecar/node_modules/ws/lib/websocket.js +1393 -0
- package/sidecar/node_modules/ws/package.json +70 -0
- package/sidecar/node_modules/ws/wrapper.mjs +21 -0
- package/src/base-session.js +151 -6
- package/src/billing-budget.js +5 -1
- package/src/binary-provenance-trust.js +95 -0
- package/src/built-in-tools/file-ops.js +5 -4
- package/src/byok-mcp-client.js +1061 -13
- package/src/byok-mcp-config.js +1201 -4
- package/src/byok-mcp-fleet.js +374 -29
- package/src/byok-mcp-oauth-store.js +327 -0
- package/src/byok-mcp-oauth.js +635 -0
- package/src/byok-mcp-trust.js +254 -37
- package/src/byok-session.js +789 -13
- package/src/byok-tool-executor.js +20 -13
- package/src/checkpoint-manager.js +33 -6
- package/src/chroxy-host-metadata.js +122 -0
- package/src/claude-stream-parser.js +56 -0
- package/src/claude-tui/pty-driver.js +54 -14
- package/src/claude-tui-session.js +106 -7
- package/src/cli/config-cmd.js +2 -2
- package/src/cli/deploy-cmd.js +1 -1
- package/src/cli/init-cmd.js +1 -1
- package/src/cli/providers-cmd.js +3 -3
- package/src/cli/schedule-cmd.js +775 -0
- package/src/cli/server-cmd.js +16 -1
- package/src/cli/service-cmd.js +39 -19
- package/src/cli/shared.js +7 -4
- package/src/cli/tokens-cmd.js +213 -0
- package/src/cli/tunnel-cmd.js +1 -1
- package/src/cli-session.js +66 -10
- package/src/cli.js +4 -0
- package/src/codex-app-server-session.js +671 -39
- package/src/codex-session.js +121 -18
- package/src/config.js +453 -27
- package/src/control-room/integrations.js +16 -10
- package/src/control-room/skills-inventory.js +6 -1
- package/src/control-room/survey.js +32 -0
- package/src/credential-store.js +256 -10
- package/src/dashboard-next/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/src/diagnostics.js +3 -0
- package/src/docker-sdk-session.js +16 -1
- package/src/docker-session.js +9 -0
- package/src/doctor.js +19 -8
- package/src/environments/backends/docker.js +8 -0
- package/src/environments/backends/k8s.js +9 -0
- package/src/event-ingest.js +19 -1
- package/src/event-normalizer.js +354 -19
- package/src/external-session-registry.js +0 -0
- package/src/gemini-session.js +19 -2
- package/src/github-webhook.js +188 -4
- package/src/handler-utils.js +42 -8
- package/src/handlers/checkpoint-handlers.js +126 -19
- package/src/handlers/control-room-handlers.js +48 -18
- package/src/handlers/conversation-handlers.js +127 -2
- package/src/handlers/credential-handlers.js +43 -2
- package/src/handlers/file-handlers.js +47 -3
- package/src/handlers/github-webhook-handlers.js +204 -0
- package/src/handlers/input-handlers.js +4 -0
- package/src/handlers/orchestration-handlers.js +238 -0
- package/src/handlers/scheduler-handlers.js +510 -0
- package/src/handlers/session-handlers.js +10 -2
- package/src/handlers/settings-handlers.js +510 -11
- package/src/handlers/token-handlers.js +11 -2
- package/src/http-routes.js +159 -0
- package/src/jsonl-reader.js +60 -6
- package/src/jsonl-subprocess-session.js +35 -6
- package/src/keychain.js +159 -12
- package/src/logger.js +182 -19
- package/src/notification-prefs.js +88 -6
- package/src/notifications/discord-webhook-sink.js +30 -1
- package/src/orchestration/build-manager.js +56 -0
- package/src/orchestration/decision-contract.js +245 -0
- package/src/orchestration/git-ops.js +347 -0
- package/src/orchestration/orchestration-manager.js +1295 -0
- package/src/orchestration/permission-gate.js +109 -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 +205 -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 +398 -0
- package/src/pairing.js +146 -1
- package/src/permission-audit.js +79 -3
- package/src/permission-floor.js +455 -0
- package/src/permission-manager.js +492 -40
- package/src/permission-resolver.js +55 -7
- package/src/permission-rule-store.js +411 -0
- package/src/platform.js +367 -23
- package/src/providers.js +21 -2
- package/src/schedule-parser.js +311 -0
- package/src/scheduled-task-store.js +653 -0
- package/src/scheduler.js +1029 -0
- package/src/sdk-session.js +338 -5
- package/src/server-cli/server-orchestrator.js +23 -0
- package/src/server-cli/tunnel-lifecycle-handler.js +3 -2
- package/src/server-cli.js +238 -26
- package/src/server-identity.js +28 -4
- package/src/service.js +291 -33
- package/src/session-manager.js +417 -25
- package/src/session-message-history.js +27 -21
- package/src/session-title.js +168 -0
- package/src/session-token-store.js +60 -35
- package/src/skills-usage.js +20 -2
- package/src/statusline.js +584 -0
- package/src/subagent-counter.js +9 -1
- package/src/supervisor.js +77 -27
- package/src/token-manager.js +39 -9
- package/src/transcript-tasks.js +41 -6
- package/src/tunnel/cloudflare.js +115 -8
- package/src/tunnel/index.js +4 -1
- package/src/tunnel-check.js +1 -1
- package/src/turn-tracker.js +0 -0
- package/src/usage-normalize.js +118 -0
- package/src/user-shell-session.js +98 -32
- package/src/utils/componentwise-resolver.js +205 -0
- package/src/utils/composite-key.js +45 -0
- package/src/utils/iso-datetime.js +51 -0
- package/src/utils/preflight.js +140 -28
- package/src/utils/spawn-env.js +8 -2
- package/src/utils/verify-binary.js +276 -0
- package/src/utils/verify-provenance.js +241 -0
- package/src/utils/wire-counters.js +48 -0
- package/src/worktree-gc.js +4 -1
- package/src/ws-file-ops/browser.js +42 -11
- package/src/ws-file-ops/common.js +68 -1
- package/src/ws-file-ops/git.js +221 -3
- package/src/ws-file-ops/index.js +5 -0
- package/src/ws-file-ops/memory.js +358 -0
- package/src/ws-file-ops/reader.js +124 -0
- package/src/ws-forwarding.js +44 -16
- package/src/ws-handler-context.js +19 -0
- package/src/ws-history.js +84 -11
- package/src/ws-message-handlers.js +6 -0
- package/src/ws-outbound-schemas.js +207 -0
- package/src/ws-permissions.js +285 -4
- package/src/ws-schemas.js +1 -0
- package/src/ws-server.js +301 -17
package/hooks/permission-hook.sh
CHANGED
|
@@ -9,6 +9,14 @@
|
|
|
9
9
|
# random secret specific to this session — never the primary API token.
|
|
10
10
|
# 4. Translates the response into Claude Code's hookSpecificOutput format
|
|
11
11
|
#
|
|
12
|
+
# In the lenient modes (auto / acceptEdits) it decides locally instead of routing
|
|
13
|
+
# to the phone — but FIRST asks POST /permission-floor whether the protected-path /
|
|
14
|
+
# secret-read floor covers the target (#7004). A floored target (.env, key material,
|
|
15
|
+
# a write into .git/.claude/.vscode) is routed to the normal prompt rather than
|
|
16
|
+
# auto-allowed, so the floor holds on this path exactly as it does in-process. The
|
|
17
|
+
# floor logic itself lives only in the daemon — see floor_forces_prompt below and
|
|
18
|
+
# docs/security/permission-floor.md.
|
|
19
|
+
#
|
|
12
20
|
# Non-Chroxy Claude sessions don't have CHROXY_PORT set, so the hook immediately
|
|
13
21
|
# falls through to Claude's normal permission prompt.
|
|
14
22
|
#
|
|
@@ -25,6 +33,22 @@ fi
|
|
|
25
33
|
|
|
26
34
|
PORT="$CHROXY_PORT"
|
|
27
35
|
TOKEN="$CHROXY_HOOK_SECRET"
|
|
36
|
+
# Where the daemon's HTTP endpoints live, from this process's point of view.
|
|
37
|
+
# `localhost` is right for a host-spawned session, but NOT from inside a
|
|
38
|
+
# container: DockerSession forwards CHROXY_HOST=host.docker.internal precisely so
|
|
39
|
+
# the callback can reach the host, and the hook has been ignoring it — meaning a
|
|
40
|
+
# containerized CliSession's /permission POST went to the container's own
|
|
41
|
+
# localhost and always failed (fail-closed deny). #7004 makes that reachability
|
|
42
|
+
# load-bearing for auto/acceptEdits too, so honour it: CHROXY_HOOK_HOST (dedicated)
|
|
43
|
+
# first, then CHROXY_HOST (what DockerSession already sets, and which on the host
|
|
44
|
+
# names the interface the daemon actually bound), else localhost.
|
|
45
|
+
HOOK_HOST="${CHROXY_HOOK_HOST:-$CHROXY_HOST}"
|
|
46
|
+
# Sanitize: a hostname/IPv4 literal only. Anything else — an empty value, an IPv6
|
|
47
|
+
# literal, a URL, or anything carrying shell/URL metacharacters — falls back to
|
|
48
|
+
# localhost rather than being interpolated into the curl target.
|
|
49
|
+
case "$HOOK_HOST" in
|
|
50
|
+
''|*[!A-Za-z0-9.-]*|[!A-Za-z0-9]*) HOOK_HOST="localhost" ;;
|
|
51
|
+
esac
|
|
28
52
|
# Permission mode resolution order:
|
|
29
53
|
# 1. CHROXY_PERMISSION_MODE_FILE — if set AND readable AND non-empty.
|
|
30
54
|
# ClaudeTuiSession writes this sidecar file when setPermissionMode()
|
|
@@ -215,12 +239,18 @@ emit_unreachable_fallback() {
|
|
|
215
239
|
# Expects $REQUEST to contain the JSON body to POST.
|
|
216
240
|
# Outputs the appropriate hookSpecificOutput JSON and exits.
|
|
217
241
|
route_to_phone() {
|
|
218
|
-
|
|
242
|
+
# The payload goes over STDIN (`--data-binary @-`), not as an argv string. A
|
|
243
|
+
# tool input can be large — a `Write` carries its whole `content` — and Linux
|
|
244
|
+
# caps a SINGLE argv string at 128KB (MAX_ARG_STRLEN), so `-d "$REQUEST"` made
|
|
245
|
+
# curl fail with E2BIG on a big write and the hook then reported the
|
|
246
|
+
# fail-closed deny instead of prompting. Identical bytes either way for a
|
|
247
|
+
# normal payload.
|
|
248
|
+
CURL_ARGS=(-s -X POST "http://${HOOK_HOST}:${PORT}/permission" -H "Content-Type: application/json" --data-binary @- --max-time 300)
|
|
219
249
|
if [ -n "$TOKEN" ]; then
|
|
220
250
|
CURL_ARGS+=(-H "Authorization: Bearer ${TOKEN}")
|
|
221
251
|
fi
|
|
222
252
|
|
|
223
|
-
RESPONSE=$(curl "${CURL_ARGS[@]}")
|
|
253
|
+
RESPONSE=$(printf '%s' "$REQUEST" | curl "${CURL_ARGS[@]}")
|
|
224
254
|
EXIT_CODE=$?
|
|
225
255
|
|
|
226
256
|
if [ $EXIT_CODE -ne 0 ]; then
|
|
@@ -250,8 +280,223 @@ EOF
|
|
|
250
280
|
exit 0
|
|
251
281
|
}
|
|
252
282
|
|
|
253
|
-
#
|
|
283
|
+
# ---- Shared: does the protected-path / secret-read FLOOR cover this call? ----
|
|
284
|
+
# #7004. Returns 0 ("must prompt") when the daemon says the target is floored —
|
|
285
|
+
# and ALSO whenever the answer is anything other than an explicit `"floor":false`.
|
|
286
|
+
# So every failure mode (daemon unreachable, rate limited, unauthorized,
|
|
287
|
+
# unparseable body, 5xx) FAILS CLOSED into the normal prompt path instead of
|
|
288
|
+
# silently auto-allowing a `.env` / `id_rsa` / `.git` target.
|
|
289
|
+
#
|
|
290
|
+
# The floor is deliberately NOT reimplemented here. It is non-trivial path logic
|
|
291
|
+
# (lexical scan + an open(2)-faithful symlink component-walk, fail-closed on any
|
|
292
|
+
# resolution error) that lives in ONE place — packages/server/src/permission-floor.js
|
|
293
|
+
# — and is applied by the in-process providers through the very same function. A
|
|
294
|
+
# shell copy would be a second source of truth and would drift; this hook only
|
|
295
|
+
# asks the question. Expects $REQUEST to hold the PreToolUse payload.
|
|
296
|
+
#
|
|
297
|
+
# The `case` below is a FAST NEGATIVE PRE-FILTER, not a floor decision. The floor's
|
|
298
|
+
# verdict is a pure function of whether the tool input carries a path-NAMING field
|
|
299
|
+
# — PROTECTED_PATH_INPUT_FIELDS (file_path / path / notebook_path) or the codex
|
|
300
|
+
# `changes[]` array (see permission-floor.js `_matchesFloor`) — so a payload
|
|
301
|
+
# carrying NONE of them provably cannot be floored, and skipping the probe keeps a
|
|
302
|
+
# path-less tool (Bash / Task / WebFetch / WebSearch / AskUserQuestion / an MCP
|
|
303
|
+
# tool) on its exact pre-#7004 behavior: no round trip, no new daemon dependency,
|
|
304
|
+
# no added latency. It is a substring scan over the RAW payload, so it also matches
|
|
305
|
+
# nested keys and OVER-matches a literal `"path"` sitting in a value — over-probing
|
|
306
|
+
# is harmless (the daemon just answers floor:false); under-probing would not be,
|
|
307
|
+
# which is why the list must stay in sync. It IS kept in sync mechanically:
|
|
308
|
+
# tests/permission-hook-floor.test.js asserts this pattern covers every
|
|
309
|
+
# PROTECTED_PATH_INPUT_FIELDS entry, so extending the floor's field list without
|
|
310
|
+
# updating this line fails CI.
|
|
311
|
+
#
|
|
312
|
+
# #7020 — the pre-filter's soundness argument ("naming no path field provably
|
|
313
|
+
# cannot be floored") holds only over a COMPLETE, escape-free payload. Two guards
|
|
314
|
+
# below narrow that premise before the negative filter is trusted; both resolve
|
|
315
|
+
# toward the PROBE (fail closed), never toward the skip. Each guard states exactly
|
|
316
|
+
# what it PROVES — neither is a completeness proof, and #7043 tracks the residual:
|
|
317
|
+
# 1. LAST-BYTE SHAPE CHECK. A PreToolUse payload is always a JSON object, so a
|
|
318
|
+
# complete one ends in `}` once trailing whitespace is discarded. A body that
|
|
319
|
+
# does NOT is definitely unusable, and an unusable body proves nothing about
|
|
320
|
+
# path fields, so it leaves the auto-allow path immediately — no probe,
|
|
321
|
+
# because that way the guard holds even when the daemon is unreachable.
|
|
322
|
+
# (`route_to_phone` then POSTs it to /permission, which cannot parse it
|
|
323
|
+
# either and answers its 400 deny.) This catches the shapes that motivated
|
|
324
|
+
# the guard — an EMPTY body and a PREFIX truncation (`{"tool_name":"Read"` …)
|
|
325
|
+
# — and nothing more. It is a cheap heuristic, NOT a completeness check: a
|
|
326
|
+
# truncation that happens to land on a `}` (`…,"permission_suggestions":{}`)
|
|
327
|
+
# still looks complete here and still skips the probe. Tracked in #7043.
|
|
328
|
+
# Trailing whitespace is trimmed first: `REQUEST=$(cat -)` strips trailing
|
|
329
|
+
# NEWLINES only, so a `}\r\n`- or `} `-terminated payload would otherwise
|
|
330
|
+
# fail this check and route EVERY auto/acceptEdits call to a phone prompt —
|
|
331
|
+
# fail-closed, but it would destroy the lenient modes.
|
|
332
|
+
# 2. UNICODE ESCAPES. The pre-filter is a BYTE-level substring scan while the
|
|
333
|
+
# daemon does a JSON-SEMANTIC field lookup, so a path-naming key spelled with
|
|
334
|
+
# an escape parses to file_path server-side yet never matches the pattern
|
|
335
|
+
# below. A `u`-escape of the letter f (byte sequence backslash-u-0-0-6-6,
|
|
336
|
+
# followed by `ile_path`) is such a key. `\uXXXX` is the ONLY escape in the
|
|
337
|
+
# JSON grammar that can spell one of these keys — the rest
|
|
338
|
+
# (`\" \\ \/ \b \f \n \r \t`) yields none of `[a-z_]` — so probing whenever
|
|
339
|
+
# the raw body contains `\u` closes the VALID-ESCAPE key-spelling gap on the
|
|
340
|
+
# floor's own semantics rather than on an assumption about the producer's
|
|
341
|
+
# serializer. That is the whole of what it proves. An INVALID escape (`\U`,
|
|
342
|
+
# `\x`) is not covered: it does not match this arm, so the pre-filter takes
|
|
343
|
+
# `return 1` and the daemon is never asked — the byte-scan-vs-semantic-lookup
|
|
344
|
+
# divergence remains for bodies no JSON parser would accept. Also #7043
|
|
345
|
+
# (which lists the candidate fixes: probe on any backslash, or a real
|
|
346
|
+
# structural check). Over-probing here is harmless; a `\n` / `\"`-only
|
|
347
|
+
# payload keeps the no-round-trip path.
|
|
348
|
+
floor_forces_prompt() {
|
|
349
|
+
case "$REQUEST" in
|
|
350
|
+
*'"file_path"'*|*'"path"'*|*'"notebook_path"'*|*'"changes"'*) ;;
|
|
351
|
+
# (1) a \uXXXX escape may spell a path-naming key the byte scan cannot see.
|
|
352
|
+
# Kept explicit for readability though arm (2) now subsumes it (`u` is not in
|
|
353
|
+
# that arm's negated set), so a `\u` body probes either way.
|
|
354
|
+
*'\u'*) ;;
|
|
355
|
+
# (2) #7043: an INVALID escape can hide one too, and never reaches the
|
|
356
|
+
# daemon's fail-closed parse because this pre-filter short-circuits first.
|
|
357
|
+
# `\U0066ile_path` is the worked example: the `\u` arm above is
|
|
358
|
+
# case-SENSITIVE, so it missed. Rather than enumerate malformed escapes,
|
|
359
|
+
# match "a backslash NOT starting one of JSON's valid non-unicode escapes"
|
|
360
|
+
# (`" \ / b f n r t`). That covers `\U`, `\x` and every other invalid form,
|
|
361
|
+
# while deliberately KEEPING the `\n` / `\"` fast path the Bash tool relies
|
|
362
|
+
# on - those cannot spell a key, and #7035 pinned that they stay fast.
|
|
363
|
+
# NOT kept fast: an ESCAPED backslash followed by a non-set char (`\\U`,
|
|
364
|
+
# `\\d`, `\\.`) — so a Windows cwd (`C:\\Users\\...`) or a regex-carrying
|
|
365
|
+
# Grep/Bash payload now probes. Distinguishing those needs escape-state
|
|
366
|
+
# tracking, i.e. a parse; over-probing is the price of not doing one, and it
|
|
367
|
+
# errs safe.
|
|
368
|
+
*'\'[!\"\\/bfnrt]*) ;;
|
|
369
|
+
*)
|
|
370
|
+
# Fast-path candidate. ONLY here is a completeness proof load-bearing, so
|
|
371
|
+
# only here is it paid for - running it before the path-key arm scanned
|
|
372
|
+
# payloads that were going to probe anyway, and a 200KB Write blew the
|
|
373
|
+
# hook's timeout and got SIGKILLed (a dead hook, not a slow one).
|
|
374
|
+
#
|
|
375
|
+
# The pre-filter's justification is that a payload naming no path field
|
|
376
|
+
# PROVABLY cannot be floored. That proof needs all the bytes, and #7043
|
|
377
|
+
# showed a last-byte `}` test does not establish it: a truncation can land
|
|
378
|
+
# on `}` (`..."permission_suggestions":{}`), carry no key literal, and take
|
|
379
|
+
# the skip. Shape + brace balance instead.
|
|
380
|
+
#
|
|
381
|
+
# Whitespace is trimmed at BOTH ends. JSON.parse accepts leading
|
|
382
|
+
# whitespace and `cat -` preserves it, so anchoring the shape check on the
|
|
383
|
+
# raw first byte would send every call from a producer that emits a
|
|
384
|
+
# leading newline to a phone prompt - destroying the lenient modes for a
|
|
385
|
+
# formatting detail.
|
|
386
|
+
REQUEST_TRIMMED=${REQUEST%"${REQUEST##*[![:space:]]}"}
|
|
387
|
+
REQUEST_TRIMMED=${REQUEST_TRIMMED#"${REQUEST_TRIMMED%%[![:space:]]*}"}
|
|
388
|
+
case "$REQUEST_TRIMMED" in
|
|
389
|
+
'{'*'}') ;;
|
|
390
|
+
*) return 0 ;;
|
|
391
|
+
esac
|
|
392
|
+
# Brace balance, counted by `tr` rather than bash pattern substitution.
|
|
393
|
+
# That is not a style choice: `${VAR//[!\{]/}` is ~O(n^3) on bash 3.2,
|
|
394
|
+
# which is macOS's /bin/bash and this file's shebang. Measured there:
|
|
395
|
+
# 0.68s at 4KB, 28.7s at 16KB - so a mid-size path-less body (a Bash
|
|
396
|
+
# heredoc, a Task prompt) would stall or be killed outright, which is the
|
|
397
|
+
# very failure this guard is supposed to prevent. `tr -cd` is O(n) and
|
|
398
|
+
# reduces the body to just its braces (0.00s at 16KB); the two
|
|
399
|
+
# substitutions below then run on that tiny result. LC_ALL=C keeps it
|
|
400
|
+
# byte-oriented so a multibyte payload cannot change the count.
|
|
401
|
+
FLOOR_BRACES=$(printf '%s' "$REQUEST_TRIMMED" | LC_ALL=C tr -cd '{}')
|
|
402
|
+
FLOOR_OPEN=${FLOOR_BRACES//\}/}
|
|
403
|
+
FLOOR_CLOSE=${FLOOR_BRACES//\{/}
|
|
404
|
+
if [ ${#FLOOR_OPEN} -ne ${#FLOOR_CLOSE} ]; then
|
|
405
|
+
return 0
|
|
406
|
+
fi
|
|
407
|
+
# Counting braces inside strings too is an over-approximation in the SAFE
|
|
408
|
+
# direction: a miscount can only ever ADD a probe/prompt, never skip one.
|
|
409
|
+
# RESIDUAL, precisely: this is not a parse. A truncation whose literal
|
|
410
|
+
# brace counts happen to balance is still undetected; closing that needs a
|
|
411
|
+
# structural walk costing about what the probe it avoids costs (#7043).
|
|
412
|
+
# A COMPLETE, escape-clean payload naming no path field: the floor cannot apply.
|
|
413
|
+
return 1
|
|
414
|
+
;;
|
|
415
|
+
esac
|
|
416
|
+
# Payload over STDIN, not argv — see route_to_phone's note on MAX_ARG_STRLEN.
|
|
417
|
+
# Here it matters doubly: an argv failure on a large `Write` would fail closed
|
|
418
|
+
# into a prompt for a file the floor never covered.
|
|
419
|
+
FLOOR_ARGS=(-s -X POST "http://${HOOK_HOST}:${PORT}/permission-floor" -H "Content-Type: application/json" --data-binary @- --max-time 10)
|
|
420
|
+
if [ -n "$TOKEN" ]; then
|
|
421
|
+
FLOOR_ARGS+=(-H "Authorization: Bearer ${TOKEN}")
|
|
422
|
+
fi
|
|
423
|
+
FLOOR_RESPONSE=$(printf '%s' "$REQUEST" | curl "${FLOOR_ARGS[@]}")
|
|
424
|
+
FLOOR_EXIT=$?
|
|
425
|
+
if [ $FLOOR_EXIT -ne 0 ]; then
|
|
426
|
+
return 0
|
|
427
|
+
fi
|
|
428
|
+
# ONLY an unambiguous, TOP-LEVEL `"floor":false` clears the short-circuit.
|
|
429
|
+
# Anything else — `true`, an error body, an empty response, or a body a real
|
|
430
|
+
# JSON parser cannot make sense of — keeps the prompt.
|
|
431
|
+
#
|
|
432
|
+
# #7017 — this is a real parse (via `node -e`), not a substring grep. A grep
|
|
433
|
+
# keyed on the FIRST `"floor"` occurrence anywhere in the body is foolable by
|
|
434
|
+
# a NESTED key (`{"nested":{"floor":false},"floor":true}`), an ARRAY-nested
|
|
435
|
+
# key (`{"a":[{"floor":false}],"floor":true}`), or a DUPLICATE top-level key
|
|
436
|
+
# (`{"floor":true,"floor":false}` — note `JSON.parse`'s own last-write-wins
|
|
437
|
+
# would silently clear this one too, so a raw occurrence count is checked
|
|
438
|
+
# BEFORE ever parsing, rather than trusting which duplicate `JSON.parse`
|
|
439
|
+
# keeps). `node` is a safe dependency here: this hook only ever runs inside a
|
|
440
|
+
# chroxy-spawned session (the CHROXY_PORT guard at the top of this file), and
|
|
441
|
+
# the daemon that spawned it IS a node process, so `node` is on PATH by
|
|
442
|
+
# construction — no new dependency is introduced.
|
|
443
|
+
#
|
|
444
|
+
# Clearance requires ALL of:
|
|
445
|
+
# 1. the literal substring `"floor"` appears EXACTLY ONCE in the raw body
|
|
446
|
+
# (this alone rules out nested / array-nested / duplicate-key, without
|
|
447
|
+
# needing to trust which value a parser would pick for a duplicate)
|
|
448
|
+
# 2. the body parses as JSON
|
|
449
|
+
# 3. the parsed value is a plain object (not an array, not a scalar)
|
|
450
|
+
# 4. its single top-level `floor` property is `=== false`
|
|
451
|
+
# A parse failure, a non-object top level, or `node` itself being
|
|
452
|
+
# unavailable all make the substitution empty, which fails the `= "false"`
|
|
453
|
+
# comparison below and prompts — fail-closed by construction, not by a
|
|
454
|
+
# special case.
|
|
455
|
+
FLOOR_VALUE=$(printf '%s' "$FLOOR_RESPONSE" | node -e '
|
|
456
|
+
let data = "";
|
|
457
|
+
process.stdin.on("data", (chunk) => { data += chunk; });
|
|
458
|
+
process.stdin.on("end", () => {
|
|
459
|
+
try {
|
|
460
|
+
const marker = "\"floor\"";
|
|
461
|
+
let count = 0;
|
|
462
|
+
let idx = 0;
|
|
463
|
+
while ((idx = data.indexOf(marker, idx)) !== -1) {
|
|
464
|
+
count++;
|
|
465
|
+
idx += marker.length;
|
|
466
|
+
}
|
|
467
|
+
if (count !== 1) {
|
|
468
|
+
process.stdout.write("true");
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
const parsed = JSON.parse(data);
|
|
472
|
+
const cleared = parsed !== null &&
|
|
473
|
+
typeof parsed === "object" &&
|
|
474
|
+
!Array.isArray(parsed) &&
|
|
475
|
+
parsed.floor === false;
|
|
476
|
+
process.stdout.write(cleared ? "false" : "true");
|
|
477
|
+
} catch {
|
|
478
|
+
process.stdout.write("true");
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
' 2>/dev/null)
|
|
482
|
+
if [ "$FLOOR_VALUE" = "false" ]; then
|
|
483
|
+
return 1
|
|
484
|
+
fi
|
|
485
|
+
return 0
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
# Auto mode — allow everything without routing to the phone, EXCEPT a target the
|
|
489
|
+
# protected-path / secret-read floor covers (#7004). #6794/#6803 gave that floor
|
|
490
|
+
# precedence over every lenient mode for the in-process providers, but this hook
|
|
491
|
+
# decides auto/acceptEdits itself and never reaches permission-manager.js — so
|
|
492
|
+
# claude-tui (the DEFAULT provider) and cli-session were auto-allowing `.env` /
|
|
493
|
+
# `id_rsa` reads and `.git`/`.claude` writes with no prompt. A floored target is
|
|
494
|
+
# never DENIED here; it is routed to the normal prompt, exactly as the in-process
|
|
495
|
+
# path falls through to one.
|
|
254
496
|
if [ "$PERM_MODE" = "auto" ]; then
|
|
497
|
+
if floor_forces_prompt; then
|
|
498
|
+
route_to_phone
|
|
499
|
+
fi
|
|
255
500
|
cat <<'EOF'
|
|
256
501
|
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}
|
|
257
502
|
EOF
|
|
@@ -263,6 +508,11 @@ if [ "$PERM_MODE" = "acceptEdits" ]; then
|
|
|
263
508
|
# $REQUEST and $TOOL_NAME already populated at top of script (#4648).
|
|
264
509
|
case "$TOOL_NAME" in
|
|
265
510
|
Read|Write|Edit|NotebookEdit|Glob|Grep)
|
|
511
|
+
# #7004 — same floor precedence as auto above. Mirrors permission-manager.js,
|
|
512
|
+
# whose acceptEdits short-circuit is likewise gated on the floor.
|
|
513
|
+
if floor_forces_prompt; then
|
|
514
|
+
route_to_phone
|
|
515
|
+
fi
|
|
266
516
|
cat <<'EOF'
|
|
267
517
|
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}
|
|
268
518
|
EOF
|
package/package.json
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chroxy/server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Chroxy server daemon and CLI",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "src/cli.js",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
3
|
+
"version": "0.11.0",
|
|
10
4
|
"files": [
|
|
11
5
|
"src",
|
|
12
|
-
"!src/dashboard-next/node_modules",
|
|
13
6
|
"hooks",
|
|
14
7
|
"sidecar",
|
|
15
|
-
"!sidecar/node_modules",
|
|
16
8
|
"scripts/fix-node-pty-helper.js",
|
|
17
|
-
"CONFIG.md"
|
|
18
|
-
"README.md"
|
|
9
|
+
"CONFIG.md"
|
|
19
10
|
],
|
|
11
|
+
"description": "Chroxy server daemon and CLI",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "src/cli.js",
|
|
20
14
|
"bin": {
|
|
21
15
|
"chroxy": "src/cli.js"
|
|
22
16
|
},
|
|
@@ -27,16 +21,15 @@
|
|
|
27
21
|
"test:raw": "c8 node --import ./tests/_setup.mjs --experimental-test-module-mocks --test './tests/**/*.test.js'",
|
|
28
22
|
"test:coverage": "c8 --reporter=text --reporter=html node --import ./tests/_setup.mjs --experimental-test-module-mocks --test './tests/**/*.test.js'",
|
|
29
23
|
"test:integration": "node --import ./tests/_setup.mjs --test ./tests/*.integration.test.js",
|
|
30
|
-
"test:integration:k8s": "RUN_K8S_INTEGRATION=1 node --import ./tests/_setup.mjs --test ./tests/integration/k8s-sidecar-roundtrip.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",
|
|
31
25
|
"lint": "eslint src/",
|
|
32
|
-
"prepack": "node scripts/copy-dashboard-dist.mjs",
|
|
33
26
|
"postinstall": "node scripts/fix-node-pty-helper.js"
|
|
34
27
|
},
|
|
35
28
|
"dependencies": {
|
|
36
29
|
"@anthropic-ai/claude-agent-sdk": "^0.2.0",
|
|
37
30
|
"@anthropic-ai/sdk": "^0.81.0",
|
|
38
|
-
"@chroxy/protocol": "0.
|
|
39
|
-
"@chroxy/store-core": "0.
|
|
31
|
+
"@chroxy/protocol": "^0.11.0",
|
|
32
|
+
"@chroxy/store-core": "^0.11.0",
|
|
40
33
|
"@kubernetes/client-node": "^1.4.0",
|
|
41
34
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
42
35
|
"@xterm/addon-fit": "^0.10.0",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "chroxy-pod-agent",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"node_modules/ws": {
|
|
8
|
+
"version": "8.20.0",
|
|
9
|
+
"resolved": "https://registry.npmjs.org/ws/-/ws-8.20.0.tgz",
|
|
10
|
+
"integrity": "sha512-sAt8BhgNbzCtgGbt2OxmpuryO63ZoDk/sqaB/znQm94T4fCEsy/yV+7CdC1kJhOU9lboAEU7R3kquuycDoibVA==",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=10.0.0"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"bufferutil": "^4.0.1",
|
|
17
|
+
"utf-8-validate": ">=5.0.2"
|
|
18
|
+
},
|
|
19
|
+
"peerDependenciesMeta": {
|
|
20
|
+
"bufferutil": {
|
|
21
|
+
"optional": true
|
|
22
|
+
},
|
|
23
|
+
"utf-8-validate": {
|
|
24
|
+
"optional": true
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2011 Einar Otto Stangvik <einaros@gmail.com>
|
|
2
|
+
Copyright (c) 2013 Arnout Kazemier and contributors
|
|
3
|
+
Copyright (c) 2016 Luigi Pinca and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|