@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.
Files changed (326) hide show
  1. package/CONFIG.md +602 -19
  2. package/README.md +2 -2
  3. package/hooks/claude-native-route-check.mjs +17 -0
  4. package/hooks/permission-hook.sh +416 -11
  5. package/package.json +20 -23
  6. package/sidecar/Dockerfile +1 -1
  7. package/sidecar/PROTOCOL.md +9 -1
  8. package/sidecar/agent.js +102 -10
  9. package/sidecar/package-lock.json +3 -3
  10. package/src/acp-config.js +206 -0
  11. package/src/acp-session.js +954 -0
  12. package/src/activity-registry.js +110 -5
  13. package/src/agent-connections.js +293 -0
  14. package/src/agent-control/client.js +1616 -0
  15. package/src/agent-control/events.js +547 -0
  16. package/src/agent-control/local-connection.js +275 -0
  17. package/src/agent-control/mcp-server.js +545 -0
  18. package/src/anthropic-compatible-config.js +29 -4
  19. package/src/anthropic-compatible-session.js +15 -6
  20. package/src/anthropic-openai-shim.js +0 -1
  21. package/src/archive-continuation.js +164 -0
  22. package/src/assistant-response.js +24 -0
  23. package/src/auth-probes.js +120 -13
  24. package/src/background-shell-tracker.js +27 -0
  25. package/src/base-session.js +1353 -41
  26. package/src/bearer-recheck.js +49 -0
  27. package/src/billing-budget.js +24 -1
  28. package/src/billing-class.js +40 -7
  29. package/src/binary-provenance-trust.js +101 -0
  30. package/src/bound-client-policy.js +279 -0
  31. package/src/built-in-tools/bash-exec.js +46 -7
  32. package/src/built-in-tools/file-ops.js +74 -9
  33. package/src/built-in-tools/tool-transforms.js +1113 -13
  34. package/src/byok-compose-state.js +6 -9
  35. package/src/byok-credentials.js +2 -3
  36. package/src/byok-mcp-client.js +1153 -20
  37. package/src/byok-mcp-config.js +1712 -8
  38. package/src/byok-mcp-fleet.js +416 -29
  39. package/src/byok-mcp-oauth-store.js +329 -0
  40. package/src/byok-mcp-oauth.js +635 -0
  41. package/src/byok-mcp-trust.js +257 -40
  42. package/src/byok-session.js +1400 -149
  43. package/src/byok-tool-executor.js +2681 -38
  44. package/src/byok-tools.js +9 -2
  45. package/src/channels/chroxy-channel-server.js +2 -3
  46. package/src/checkpoint-manager.js +96 -51
  47. package/src/chroxy-host-metadata.js +122 -0
  48. package/src/claude-channel-session.js +16 -10
  49. package/src/claude-model-catalog.js +131 -16
  50. package/src/claude-model-refresh.js +385 -0
  51. package/src/claude-model-request.js +103 -0
  52. package/src/claude-stream-parser.js +109 -3
  53. package/src/claude-tui/diagnostic-tail.js +83 -0
  54. package/src/claude-tui/form-driver.js +44 -7
  55. package/src/claude-tui/model-error.js +41 -0
  56. package/src/claude-tui/pty-driver.js +223 -60
  57. package/src/claude-tui/sanitize-question-payload.js +109 -0
  58. package/src/claude-tui/usage-limit.js +239 -0
  59. package/src/claude-tui-session.js +3611 -286
  60. package/src/claude-tui-tool-response.js +300 -0
  61. package/src/cli/agent-control-cmd.js +65 -0
  62. package/src/cli/config-cmd.js +6 -6
  63. package/src/cli/config-dir-cmd.js +234 -0
  64. package/src/cli/deploy-cmd.js +46 -11
  65. package/src/cli/doctor-cmd.js +7 -3
  66. package/src/cli/init-cmd.js +16 -17
  67. package/src/cli/providers-cmd.js +6 -6
  68. package/src/cli/schedule-cmd.js +804 -0
  69. package/src/cli/server-cmd.js +64 -2
  70. package/src/cli/service-cmd.js +70 -27
  71. package/src/cli/session-cmd.js +227 -74
  72. package/src/cli/shared.js +168 -14
  73. package/src/cli/tokens-cmd.js +212 -0
  74. package/src/cli/tunnel-cmd.js +256 -25
  75. package/src/cli/worktree-gc-cmd.js +2 -2
  76. package/src/cli-session.js +1117 -116
  77. package/src/cli.js +8 -0
  78. package/src/codex-app-server-client.js +36 -3
  79. package/src/codex-app-server-session.js +2108 -101
  80. package/src/codex-bundled-client.js +66 -0
  81. package/src/codex-model-catalog.js +548 -0
  82. package/src/codex-model-rejections.js +87 -0
  83. package/src/codex-native-resume.js +104 -0
  84. package/src/codex-protocol-capabilities.js +188 -0
  85. package/src/codex-session.js +571 -45
  86. package/src/config-dir-migration.js +444 -0
  87. package/src/config-dir.js +108 -0
  88. package/src/config.js +738 -52
  89. package/src/connection-authority.js +48 -0
  90. package/src/connection-info.js +5 -9
  91. package/src/connection-locality.js +60 -0
  92. package/src/container-liveness-monitor.js +189 -0
  93. package/src/continuation-metadata-worker.js +17 -0
  94. package/src/continuations.js +114 -0
  95. package/src/control-room/host-prune.js +5 -0
  96. package/src/control-room/integrations.js +23 -30
  97. package/src/control-room/skills-inventory.js +8 -3
  98. package/src/control-room/survey.js +32 -0
  99. package/src/conversation-scanner.js +40 -18
  100. package/src/conversation-scope.js +59 -39
  101. package/src/conversation-search.js +24 -22
  102. package/src/credential-store.js +279 -29
  103. package/src/daemon-commit.js +92 -0
  104. package/src/daemon-idle-state.js +171 -0
  105. package/src/daemon-update-status.js +314 -0
  106. package/src/dashboard-build.js +70 -0
  107. package/src/declared-status.js +90 -0
  108. package/src/deepseek-credentials.js +2 -3
  109. package/src/dev-preview.js +169 -182
  110. package/src/device-preferences.js +2 -2
  111. package/src/diagnostics.js +3 -0
  112. package/src/diff-parser.js +87 -0
  113. package/src/discord-credentials.js +2 -3
  114. package/src/docker-byok-pool.js +3 -1
  115. package/src/docker-byok-session.js +678 -78
  116. package/src/docker-image-allowlist.js +23 -1
  117. package/src/docker-sdk-session.js +188 -4
  118. package/src/docker-session.js +293 -10
  119. package/src/doctor.js +783 -66
  120. package/src/edited-input.js +264 -0
  121. package/src/environment-manager.js +175 -36
  122. package/src/environments/authority.js +95 -0
  123. package/src/environments/backends/container-claude-spawn.js +94 -0
  124. package/src/environments/backends/docker.js +39 -10
  125. package/src/environments/backends/k8s.js +58 -24
  126. package/src/environments/destroy-with-sessions.js +142 -0
  127. package/src/event-ingest.js +137 -14
  128. package/src/event-normalizer.js +363 -110
  129. package/src/external-session-registry.js +0 -0
  130. package/src/gemini-session.js +100 -7
  131. package/src/github-webhook.js +188 -4
  132. package/src/handler-utils.js +563 -62
  133. package/src/handlers/checkpoint-handlers.js +162 -20
  134. package/src/handlers/control-room-handlers.js +99 -29
  135. package/src/handlers/conversation-handlers.js +563 -25
  136. package/src/handlers/credential-handlers.js +43 -2
  137. package/src/handlers/daemon-update-handlers.js +81 -0
  138. package/src/handlers/evaluator-handlers.js +14 -1
  139. package/src/handlers/feature-handlers.js +186 -69
  140. package/src/handlers/file-handlers.js +101 -13
  141. package/src/handlers/github-webhook-handlers.js +204 -0
  142. package/src/handlers/input-handlers.js +689 -48
  143. package/src/handlers/orchestration-handlers.js +238 -0
  144. package/src/handlers/scheduler-handlers.js +584 -0
  145. package/src/handlers/session-handlers.js +546 -16
  146. package/src/handlers/session-pr-status-handlers.js +283 -0
  147. package/src/handlers/session-pr-threads-handlers.js +247 -0
  148. package/src/handlers/settings-handlers.js +822 -35
  149. package/src/handlers/skills-handlers.js +13 -4
  150. package/src/handlers/summarize-handlers.js +32 -1
  151. package/src/handlers/survey-throttle.js +380 -0
  152. package/src/handlers/token-handlers.js +11 -2
  153. package/src/health-proof.js +40 -0
  154. package/src/history-page.js +104 -0
  155. package/src/http-routes.js +286 -8
  156. package/src/ide/search.js +24 -6
  157. package/src/ide/symbols.js +20 -6
  158. package/src/input-context.js +117 -0
  159. package/src/instruction-policy-compiler.js +229 -0
  160. package/src/instruction-policy.js +250 -0
  161. package/src/jsonl-reader.js +309 -48
  162. package/src/jsonl-subprocess-session.js +122 -9
  163. package/src/keychain.js +160 -13
  164. package/src/logger.js +240 -31
  165. package/src/mailbox-route.js +11 -22
  166. package/src/message-wire.js +386 -0
  167. package/src/model-discovery.js +43 -3
  168. package/src/models.js +1276 -174
  169. package/src/notification-prefs.js +100 -10
  170. package/src/notifications/discord-billing-sink.js +22 -5
  171. package/src/notifications/discord-ci-sink.js +243 -0
  172. package/src/notifications/discord-webhook-client.js +71 -0
  173. package/src/notifications/discord-webhook-sink.js +82 -12
  174. package/src/notifications/expo-push-sink.js +85 -6
  175. package/src/notifications/ready-body.js +16 -5
  176. package/src/ollama-session.js +34 -2
  177. package/src/orchestration/build-manager.js +63 -0
  178. package/src/orchestration/decision-contract.js +245 -0
  179. package/src/orchestration/git-ops.js +381 -0
  180. package/src/orchestration/orchestration-manager.js +1342 -0
  181. package/src/orchestration/permission-gate.js +121 -0
  182. package/src/orchestration/role-prompts.js +136 -0
  183. package/src/orchestration/run-budget.js +81 -0
  184. package/src/orchestration/run-ledger.js +487 -0
  185. package/src/orchestration/run-model.js +206 -0
  186. package/src/orchestration/run-record.js +336 -0
  187. package/src/orchestration/run-report.js +194 -0
  188. package/src/orchestration/to-wire.js +201 -0
  189. package/src/orchestration/turn-driver.js +422 -0
  190. package/src/orphan-reaper.js +413 -0
  191. package/src/outgoing-policy.js +183 -0
  192. package/src/pairing.js +236 -12
  193. package/src/path-hash-trust-ledger.js +642 -25
  194. package/src/permission-audit.js +79 -3
  195. package/src/permission-deadlines.js +82 -0
  196. package/src/permission-floor.js +1770 -0
  197. package/src/permission-hook.js +180 -69
  198. package/src/permission-manager.js +1175 -94
  199. package/src/permission-mode-support.js +35 -0
  200. package/src/permission-resolver.js +174 -12
  201. package/src/permission-rule-store.js +411 -0
  202. package/src/permission-scope.js +43 -0
  203. package/src/platform.js +483 -23
  204. package/src/preview-ingress.js +54 -0
  205. package/src/preview-target.js +213 -0
  206. package/src/prompt-evaluator.js +34 -4
  207. package/src/provider-customization.js +180 -0
  208. package/src/providers.js +228 -6
  209. package/src/push.js +30 -4
  210. package/src/question-route-map.js +130 -0
  211. package/src/redaction.js +360 -8
  212. package/src/roster-broadcast.js +186 -0
  213. package/src/schedule-parser.js +311 -0
  214. package/src/scheduled-task-store.js +945 -0
  215. package/src/scheduler.js +1099 -0
  216. package/src/sdk-session.js +2374 -168
  217. package/src/server-cli/preview-shutdown.js +22 -0
  218. package/src/server-cli/push-notification-handler.js +11 -2
  219. package/src/server-cli/server-orchestrator.js +50 -4
  220. package/src/server-cli/tunnel-lifecycle-handler.js +3 -2
  221. package/src/server-cli-child.js +33 -18
  222. package/src/server-cli.js +760 -62
  223. package/src/server-identity.js +42 -14
  224. package/src/service.js +682 -53
  225. package/src/session-archive-limits.js +15 -0
  226. package/src/session-archive.js +1029 -0
  227. package/src/session-busy-state.js +72 -0
  228. package/src/session-ci-watcher.js +926 -0
  229. package/src/session-context.js +7 -2
  230. package/src/session-manager.js +3879 -308
  231. package/src/session-message-history.js +749 -37
  232. package/src/session-pr-status.js +654 -0
  233. package/src/session-pr-threads.js +271 -0
  234. package/src/session-preset-trust.js +3 -3
  235. package/src/session-preset.js +10 -5
  236. package/src/session-state-persistence.js +94 -17
  237. package/src/session-timeout-manager.js +20 -0
  238. package/src/session-title.js +168 -0
  239. package/src/session-token-store.js +70 -36
  240. package/src/session-wake.js +240 -0
  241. package/src/shell-approval-info.js +2 -2
  242. package/src/shell-approval-store.js +3 -1
  243. package/src/skills-loader.js +7 -4
  244. package/src/skills-manager.js +2 -2
  245. package/src/skills-trust.js +95 -13
  246. package/src/skills-usage.js +22 -5
  247. package/src/snapshots-store.js +2 -3
  248. package/src/statusline.js +596 -0
  249. package/src/subagent-counter.js +9 -1
  250. package/src/summarize-session.js +51 -4
  251. package/src/supervisor.js +99 -38
  252. package/src/sweep-stale-provider-dirs.js +95 -0
  253. package/src/thinking-level-wire.js +39 -0
  254. package/src/thinking-stream.js +179 -0
  255. package/src/token-manager.js +39 -9
  256. package/src/tool-result.js +61 -0
  257. package/src/transcript-sources.js +109 -0
  258. package/src/transcript-tasks.js +413 -31
  259. package/src/trusted-file-read.js +302 -0
  260. package/src/tunnel/base.js +0 -8
  261. package/src/tunnel/cloudflare.js +145 -35
  262. package/src/tunnel/index.js +13 -1
  263. package/src/tunnel/preview.js +64 -0
  264. package/src/tunnel-check.js +1 -1
  265. package/src/turn-outcome.js +137 -0
  266. package/src/turn-tracker.js +0 -0
  267. package/src/usage-normalize.js +122 -0
  268. package/src/user-shell-session.js +157 -37
  269. package/src/utils/agent-sdk-version.js +107 -0
  270. package/src/utils/argv-safety.js +741 -0
  271. package/src/utils/auth-cause.js +60 -0
  272. package/src/utils/binary-package-manifest.js +597 -0
  273. package/src/utils/binary-version.js +224 -0
  274. package/src/utils/bounded-regex-worker.js +25 -0
  275. package/src/utils/bounded-regex.js +153 -0
  276. package/src/utils/claude-binary.js +43 -0
  277. package/src/utils/claude-config-dir.js +245 -0
  278. package/src/utils/claude-login-command.js +16 -0
  279. package/src/utils/claude-native-route.js +81 -0
  280. package/src/utils/componentwise-resolver.js +301 -0
  281. package/src/utils/composite-key.js +45 -0
  282. package/src/utils/deploy-control-files.js +87 -0
  283. package/src/utils/exec-failure-reason.js +21 -0
  284. package/src/utils/git-repo.js +42 -0
  285. package/src/utils/is-entry-point.js +137 -0
  286. package/src/utils/iso-datetime.js +51 -0
  287. package/src/utils/node-pty-probe.js +95 -0
  288. package/src/utils/node-pty-support.js +118 -0
  289. package/src/utils/opened-file-path.js +167 -0
  290. package/src/utils/path-containment.js +165 -0
  291. package/src/utils/permission-mode-sidecar.js +51 -0
  292. package/src/utils/preflight.js +485 -29
  293. package/src/utils/read-limiter.js +217 -0
  294. package/src/utils/regular-file.js +375 -0
  295. package/src/utils/safe-regex.js +113 -0
  296. package/src/utils/small-file.js +129 -0
  297. package/src/utils/spawn-env.js +196 -5
  298. package/src/utils/stale-session-dirs.js +182 -0
  299. package/src/utils/stat-identity.js +43 -0
  300. package/src/utils/verify-binary.js +276 -0
  301. package/src/utils/verify-provenance.js +634 -0
  302. package/src/utils/wire-counters.js +48 -0
  303. package/src/web-task-manager.js +256 -16
  304. package/src/worktree-gc.js +11 -3
  305. package/src/ws-auth.js +69 -21
  306. package/src/ws-broadcaster.js +14 -2
  307. package/src/ws-client-manager.js +16 -1
  308. package/src/ws-client-sender.js +7 -0
  309. package/src/ws-file-ops/browser.js +370 -66
  310. package/src/ws-file-ops/common.js +384 -11
  311. package/src/ws-file-ops/git.js +615 -44
  312. package/src/ws-file-ops/index.js +7 -0
  313. package/src/ws-file-ops/memory.js +460 -0
  314. package/src/ws-file-ops/open-nofollow.js +354 -0
  315. package/src/ws-file-ops/reader.js +676 -94
  316. package/src/ws-forwarding.js +373 -55
  317. package/src/ws-handler-context.js +89 -2
  318. package/src/ws-history.js +1018 -177
  319. package/src/ws-message-handlers.js +23 -1
  320. package/src/ws-outbound-schemas.js +207 -0
  321. package/src/ws-permissions.js +589 -38
  322. package/src/ws-schemas.js +6 -0
  323. package/src/ws-server.js +936 -105
  324. package/src/dashboard-next/dist/assets/index-C2ipeGlq.js +0 -111
  325. package/src/dashboard-next/dist/assets/index-DM-_dISG.css +0 -1
  326. package/src/dashboard-next/dist/index.html +0 -13
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Node.js daemon that bridges your phone to Claude Code via WebSocket over Cloudflare tunnel.
4
4
 
5
- The server runs in **CLI headless mode**: it executes the Claude Agent SDK in-process by default, or shells out to `claude -p`, `gemini -p`, or `codex exec` for the other providers, and streams parsed events to clients. No tmux, no PTY.
5
+ The server runs in **CLI headless mode**: it executes the Claude Agent SDK in-process by default, or shells out to `claude -p`, `gemini --prompt=<text>`, or `codex exec` for the other providers, and streams parsed events to clients. No tmux, no PTY.
6
6
 
7
7
  ## Quick Start
8
8
 
@@ -31,7 +31,7 @@ The server will print a QR code. Scan it with the Chroxy app.
31
31
  | `chroxy start --cwd /path` | Set working directory |
32
32
  | `chroxy start --model opus` | Use a specific Claude model |
33
33
  | `chroxy start --allowed-tools tool1,tool2` | Restrict exposed tools |
34
- | `chroxy start --provider name` | Use a specific session provider (default: `claude-tui`) |
34
+ | `chroxy start --provider name` | Use a specific session provider (default: `claude-sdk`) |
35
35
  | `chroxy start --no-encrypt` | Disable end-to-end encryption |
36
36
  | `chroxy dev` | Development mode (supervisor + auto-restart) |
37
37
  | `chroxy deploy` | Validate and restart the running server |
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { writeFileSync } from 'fs'
4
+ import { observeClaudeNativeRoute } from '../src/utils/claude-native-route.js'
5
+
6
+ const markerPath = process.argv[2]
7
+ const nonce = process.argv[3]
8
+ if (!markerPath || !nonce) process.exit(2)
9
+
10
+ const observed = observeClaudeNativeRoute(process.env)
11
+ writeFileSync(markerPath, JSON.stringify({
12
+ version: 1,
13
+ nonce,
14
+ safe: observed.safe,
15
+ firstPartyEndpoint: observed.firstPartyEndpoint,
16
+ blockedKeys: observed.blockedKeys,
17
+ }), { mode: 0o600 })
@@ -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
  #
@@ -17,22 +25,79 @@
17
25
  # args. Do NOT use $1/$2/etc for tool parameters — they are untrusted and could
18
26
  # contain shell metacharacters that execute arbitrary commands.
19
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
+
20
35
  # If CHROXY_PORT is not set, this isn't a Chroxy session — exit silently
21
36
  # so Claude Code uses its normal permission flow without showing a hook prompt.
22
37
  if [ -z "$CHROXY_PORT" ]; then
23
38
  exit 0
24
39
  fi
25
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
+
26
74
  PORT="$CHROXY_PORT"
27
75
  TOKEN="$CHROXY_HOOK_SECRET"
76
+ # Where the daemon's HTTP endpoints live, from this process's point of view.
77
+ # `localhost` is right for a host-spawned session, but NOT from inside a
78
+ # container: DockerSession forwards CHROXY_HOST=host.docker.internal precisely so
79
+ # the callback can reach the host, and the hook has been ignoring it — meaning a
80
+ # containerized CliSession's /permission POST went to the container's own
81
+ # localhost and always failed (fail-closed deny). #7004 makes that reachability
82
+ # load-bearing for auto/acceptEdits too, so honour it: CHROXY_HOOK_HOST (dedicated)
83
+ # first, then CHROXY_HOST (what DockerSession already sets, and which on the host
84
+ # names the interface the daemon actually bound), else localhost.
85
+ HOOK_HOST="${CHROXY_HOOK_HOST:-$CHROXY_HOST}"
86
+ # Sanitize: a hostname/IPv4 literal only. Anything else — an empty value, an IPv6
87
+ # literal, a URL, or anything carrying shell/URL metacharacters — falls back to
88
+ # localhost rather than being interpolated into the curl target.
89
+ case "$HOOK_HOST" in
90
+ ''|*[!A-Za-z0-9.-]*|[!A-Za-z0-9]*) HOOK_HOST="localhost" ;;
91
+ esac
28
92
  # Permission mode resolution order:
29
93
  # 1. CHROXY_PERMISSION_MODE_FILE — if set AND readable AND non-empty.
30
- # ClaudeTuiSession writes this sidecar file when setPermissionMode()
31
- # is called mid-session, since env vars on a running PTY can't be
32
- # mutated from outside (#4013).
33
- # 2. CHROXY_PERMISSION_MODE env var — the value at session-spawn time.
34
- # Used by CliSession (which restarts on mode change) and as the
35
- # initial value for TUI sessions.
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).
36
101
  # 3. "approve" — default if nothing else is set.
37
102
  PERM_MODE=""
38
103
  if [ -n "$CHROXY_PERMISSION_MODE_FILE" ] && [ -r "$CHROXY_PERMISSION_MODE_FILE" ]; then
@@ -211,23 +276,124 @@ emit_unreachable_fallback() {
211
276
  exit 0
212
277
  }
213
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
+
214
303
  # ---- Shared: route a permission request to the phone via HTTP ----
215
304
  # Expects $REQUEST to contain the JSON body to POST.
216
305
  # Outputs the appropriate hookSpecificOutput JSON and exits.
217
306
  route_to_phone() {
218
- CURL_ARGS=(-s -X POST "http://localhost:${PORT}/permission" -H "Content-Type: application/json" -d "$REQUEST" --max-time 300)
307
+ # The payload goes over STDIN (`--data-binary @-`), not as an argv string. A
308
+ # tool input can be large — a `Write` carries its whole `content` — and Linux
309
+ # caps a SINGLE argv string at 128KB (MAX_ARG_STRLEN), so `-d "$REQUEST"` made
310
+ # curl fail with E2BIG on a big write and the hook then reported the
311
+ # fail-closed deny instead of prompting. Identical bytes either way for a
312
+ # normal payload.
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)
219
326
  if [ -n "$TOKEN" ]; then
220
327
  CURL_ARGS+=(-H "Authorization: Bearer ${TOKEN}")
221
328
  fi
222
329
 
223
- RESPONSE=$(curl "${CURL_ARGS[@]}")
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[@]}")
224
338
  EXIT_CODE=$?
339
+ CURL_TRAILER="${RESPONSE_AND_CODE##*$'\n'}"
225
340
 
226
341
  if [ $EXIT_CODE -ne 0 ]; then
227
- # Daemon unreachable / curl timeout — the request never reached the phone.
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.
228
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."
229
381
  fi
230
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
+
231
397
  DECISION=$(echo "$RESPONSE" | grep -o '"decision":"[^"]*"' | head -1 | cut -d'"' -f4)
232
398
 
233
399
  case "$DECISION" in
@@ -237,9 +403,22 @@ route_to_phone() {
237
403
  EOF
238
404
  ;;
239
405
  deny)
240
- cat <<EOF
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
241
419
  {"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"Denied by user via Chroxy mobile app"}}
242
420
  EOF
421
+ fi
243
422
  ;;
244
423
  *)
245
424
  # Reached the daemon but got no recognizable decision — also unanswerable
@@ -250,8 +429,229 @@ EOF
250
429
  exit 0
251
430
  }
252
431
 
253
- # Auto mode — allow everything without routing to the phone
432
+ # ---- Shared: does the protected-path / secret-read FLOOR cover this call? ----
433
+ # #7004. Returns 0 ("must prompt") when the daemon says the target is floored —
434
+ # and ALSO whenever the answer is anything other than an explicit `"floor":false`.
435
+ # So every failure mode (daemon unreachable, rate limited, unauthorized,
436
+ # unparseable body, 5xx) FAILS CLOSED into the normal prompt path instead of
437
+ # silently auto-allowing a `.env` / `id_rsa` / `.git` target.
438
+ #
439
+ # The floor is deliberately NOT reimplemented here. It is non-trivial path logic
440
+ # (lexical scan + an open(2)-faithful symlink component-walk, fail-closed on any
441
+ # resolution error) that lives in ONE place — packages/server/src/permission-floor.js
442
+ # — and is applied by the in-process providers through the very same function. A
443
+ # shell copy would be a second source of truth and would drift; this hook only
444
+ # asks the question. Expects $REQUEST to hold the PreToolUse payload.
445
+ #
446
+ # The `case` below is a FAST NEGATIVE PRE-FILTER, not a floor decision. The floor's
447
+ # verdict is a pure function of whether the tool input carries a path-NAMING field
448
+ # — PROTECTED_PATH_INPUT_FIELDS (file_path / path / notebook_path) or the codex
449
+ # `changes[]` array (see permission-floor.js `_matchesFloor`) — so a payload
450
+ # carrying NONE of them provably cannot be floored, and skipping the probe keeps a
451
+ # path-less tool (Bash / Task / WebFetch / WebSearch / AskUserQuestion / an MCP
452
+ # tool) on its exact pre-#7004 behavior: no round trip, no new daemon dependency,
453
+ # no added latency. It is a substring scan over the RAW payload, so it also matches
454
+ # nested keys and OVER-matches a literal `"path"` sitting in a value — over-probing
455
+ # is harmless (the daemon just answers floor:false); under-probing would not be,
456
+ # which is why the list must stay in sync. It IS kept in sync mechanically:
457
+ # tests/permission-hook-floor.test.js asserts this pattern covers every
458
+ # PROTECTED_PATH_INPUT_FIELDS entry, so extending the floor's field list without
459
+ # updating this line fails CI.
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
+ #
467
+ # #7020 — the pre-filter's soundness argument ("naming no path field provably
468
+ # cannot be floored") holds only over a COMPLETE, escape-free payload. Two guards
469
+ # below narrow that premise before the negative filter is trusted; both resolve
470
+ # toward the PROBE (fail closed), never toward the skip. Each guard states exactly
471
+ # what it PROVES — neither is a completeness proof, and #7043 tracks the residual:
472
+ # 1. LAST-BYTE SHAPE CHECK. A PreToolUse payload is always a JSON object, so a
473
+ # complete one ends in `}` once trailing whitespace is discarded. A body that
474
+ # does NOT is definitely unusable, and an unusable body proves nothing about
475
+ # path fields, so it leaves the auto-allow path immediately — no probe,
476
+ # because that way the guard holds even when the daemon is unreachable.
477
+ # (`route_to_phone` then POSTs it to /permission, which cannot parse it
478
+ # either and answers its 400 deny.) This catches the shapes that motivated
479
+ # the guard — an EMPTY body and a PREFIX truncation (`{"tool_name":"Read"` …)
480
+ # — and nothing more. It is a cheap heuristic, NOT a completeness check: a
481
+ # truncation that happens to land on a `}` (`…,"permission_suggestions":{}`)
482
+ # still looks complete here and still skips the probe. Tracked in #7043.
483
+ # Trailing whitespace is trimmed first: `REQUEST=$(cat -)` strips trailing
484
+ # NEWLINES only, so a `}\r\n`- or `} `-terminated payload would otherwise
485
+ # fail this check and route EVERY auto/acceptEdits call to a phone prompt —
486
+ # fail-closed, but it would destroy the lenient modes.
487
+ # 2. UNICODE ESCAPES. The pre-filter is a BYTE-level substring scan while the
488
+ # daemon does a JSON-SEMANTIC field lookup, so a path-naming key spelled with
489
+ # an escape parses to file_path server-side yet never matches the pattern
490
+ # below. A `u`-escape of the letter f (byte sequence backslash-u-0-0-6-6,
491
+ # followed by `ile_path`) is such a key. `\uXXXX` is the ONLY escape in the
492
+ # JSON grammar that can spell one of these keys — the rest
493
+ # (`\" \\ \/ \b \f \n \r \t`) yields none of `[a-z_]` — so probing whenever
494
+ # the raw body contains `\u` closes the VALID-ESCAPE key-spelling gap on the
495
+ # floor's own semantics rather than on an assumption about the producer's
496
+ # serializer. That is the whole of what it proves. An INVALID escape (`\U`,
497
+ # `\x`) is not covered: it does not match this arm, so the pre-filter takes
498
+ # `return 1` and the daemon is never asked — the byte-scan-vs-semantic-lookup
499
+ # divergence remains for bodies no JSON parser would accept. Also #7043
500
+ # (which lists the candidate fixes: probe on any backslash, or a real
501
+ # structural check). Over-probing here is harmless; a `\n` / `\"`-only
502
+ # payload keeps the no-round-trip path.
503
+ floor_forces_prompt() {
504
+ case "$REQUEST" in
505
+ *'"file_path"'*|*'"path"'*|*'"notebook_path"'*|*'"changes"'*|*'"Grep"'*|*'"Glob"'*) ;;
506
+ # (1) a \uXXXX escape may spell a path-naming key the byte scan cannot see.
507
+ # Kept explicit for readability though arm (2) now subsumes it (`u` is not in
508
+ # that arm's negated set), so a `\u` body probes either way.
509
+ *'\u'*) ;;
510
+ # (2) #7043: an INVALID escape can hide one too, and never reaches the
511
+ # daemon's fail-closed parse because this pre-filter short-circuits first.
512
+ # `\U0066ile_path` is the worked example: the `\u` arm above is
513
+ # case-SENSITIVE, so it missed. Rather than enumerate malformed escapes,
514
+ # match "a backslash NOT starting one of JSON's valid non-unicode escapes"
515
+ # (`" \ / b f n r t`). That covers `\U`, `\x` and every other invalid form,
516
+ # while deliberately KEEPING the `\n` / `\"` fast path the Bash tool relies
517
+ # on - those cannot spell a key, and #7035 pinned that they stay fast.
518
+ # NOT kept fast: an ESCAPED backslash followed by a non-set char (`\\U`,
519
+ # `\\d`, `\\.`) — so a Windows cwd (`C:\\Users\\...`) or a regex-carrying
520
+ # Grep/Bash payload now probes. Distinguishing those needs escape-state
521
+ # tracking, i.e. a parse; over-probing is the price of not doing one, and it
522
+ # errs safe.
523
+ *'\'[!\"\\/bfnrt]*) ;;
524
+ *)
525
+ # Fast-path candidate. ONLY here is a completeness proof load-bearing, so
526
+ # only here is it paid for - running it before the path-key arm scanned
527
+ # payloads that were going to probe anyway, and a 200KB Write blew the
528
+ # hook's timeout and got SIGKILLed (a dead hook, not a slow one).
529
+ #
530
+ # The pre-filter's justification is that a payload naming no path field
531
+ # PROVABLY cannot be floored. That proof needs all the bytes, and #7043
532
+ # showed a last-byte `}` test does not establish it: a truncation can land
533
+ # on `}` (`..."permission_suggestions":{}`), carry no key literal, and take
534
+ # the skip. Shape + brace balance instead.
535
+ #
536
+ # Whitespace is trimmed at BOTH ends. JSON.parse accepts leading
537
+ # whitespace and `cat -` preserves it, so anchoring the shape check on the
538
+ # raw first byte would send every call from a producer that emits a
539
+ # leading newline to a phone prompt - destroying the lenient modes for a
540
+ # formatting detail.
541
+ REQUEST_TRIMMED=${REQUEST%"${REQUEST##*[![:space:]]}"}
542
+ REQUEST_TRIMMED=${REQUEST_TRIMMED#"${REQUEST_TRIMMED%%[![:space:]]*}"}
543
+ case "$REQUEST_TRIMMED" in
544
+ '{'*'}') ;;
545
+ *) return 0 ;;
546
+ esac
547
+ # Brace balance, counted by `tr` rather than bash pattern substitution.
548
+ # That is not a style choice: `${VAR//[!\{]/}` is ~O(n^3) on bash 3.2,
549
+ # which is macOS's /bin/bash and this file's shebang. Measured there:
550
+ # 0.68s at 4KB, 28.7s at 16KB - so a mid-size path-less body (a Bash
551
+ # heredoc, a Task prompt) would stall or be killed outright, which is the
552
+ # very failure this guard is supposed to prevent. `tr -cd` is O(n) and
553
+ # reduces the body to just its braces (0.00s at 16KB); the two
554
+ # substitutions below then run on that tiny result. LC_ALL=C keeps it
555
+ # byte-oriented so a multibyte payload cannot change the count.
556
+ FLOOR_BRACES=$(printf '%s' "$REQUEST_TRIMMED" | LC_ALL=C tr -cd '{}')
557
+ FLOOR_OPEN=${FLOOR_BRACES//\}/}
558
+ FLOOR_CLOSE=${FLOOR_BRACES//\{/}
559
+ if [ ${#FLOOR_OPEN} -ne ${#FLOOR_CLOSE} ]; then
560
+ return 0
561
+ fi
562
+ # Counting braces inside strings too is an over-approximation in the SAFE
563
+ # direction: a miscount can only ever ADD a probe/prompt, never skip one.
564
+ # RESIDUAL, precisely: this is not a parse. A truncation whose literal
565
+ # brace counts happen to balance is still undetected; closing that needs a
566
+ # structural walk costing about what the probe it avoids costs (#7043).
567
+ # A COMPLETE, escape-clean payload naming no path field: the floor cannot apply.
568
+ return 1
569
+ ;;
570
+ esac
571
+ # Payload over STDIN, not argv — see route_to_phone's note on MAX_ARG_STRLEN.
572
+ # Here it matters doubly: an argv failure on a large `Write` would fail closed
573
+ # into a prompt for a file the floor never covered.
574
+ FLOOR_ARGS=(-s -X POST "http://${HOOK_HOST}:${PORT}/permission-floor" -H "Content-Type: application/json" --data-binary @- --max-time 10)
575
+ if [ -n "$TOKEN" ]; then
576
+ FLOOR_ARGS+=(-H "Authorization: Bearer ${TOKEN}")
577
+ fi
578
+ FLOOR_RESPONSE=$(printf '%s' "$REQUEST" | curl "${FLOOR_ARGS[@]}")
579
+ FLOOR_EXIT=$?
580
+ if [ $FLOOR_EXIT -ne 0 ]; then
581
+ return 0
582
+ fi
583
+ # ONLY an unambiguous, TOP-LEVEL `"floor":false` clears the short-circuit.
584
+ # Anything else — `true`, an error body, an empty response, or a body a real
585
+ # JSON parser cannot make sense of — keeps the prompt.
586
+ #
587
+ # #7017 — this is a real parse (via `node -e`), not a substring grep. A grep
588
+ # keyed on the FIRST `"floor"` occurrence anywhere in the body is foolable by
589
+ # a NESTED key (`{"nested":{"floor":false},"floor":true}`), an ARRAY-nested
590
+ # key (`{"a":[{"floor":false}],"floor":true}`), or a DUPLICATE top-level key
591
+ # (`{"floor":true,"floor":false}` — note `JSON.parse`'s own last-write-wins
592
+ # would silently clear this one too, so a raw occurrence count is checked
593
+ # BEFORE ever parsing, rather than trusting which duplicate `JSON.parse`
594
+ # keeps). `node` is a safe dependency here: this hook only ever runs inside a
595
+ # chroxy-spawned session (the CHROXY_PORT guard at the top of this file), and
596
+ # the daemon that spawned it IS a node process, so `node` is on PATH by
597
+ # construction — no new dependency is introduced.
598
+ #
599
+ # Clearance requires ALL of:
600
+ # 1. the literal substring `"floor"` appears EXACTLY ONCE in the raw body
601
+ # (this alone rules out nested / array-nested / duplicate-key, without
602
+ # needing to trust which value a parser would pick for a duplicate)
603
+ # 2. the body parses as JSON
604
+ # 3. the parsed value is a plain object (not an array, not a scalar)
605
+ # 4. its single top-level `floor` property is `=== false`
606
+ # A parse failure, a non-object top level, or `node` itself being
607
+ # unavailable all make the substitution empty, which fails the `= "false"`
608
+ # comparison below and prompts — fail-closed by construction, not by a
609
+ # special case.
610
+ FLOOR_VALUE=$(printf '%s' "$FLOOR_RESPONSE" | node -e '
611
+ let data = "";
612
+ process.stdin.on("data", (chunk) => { data += chunk; });
613
+ process.stdin.on("end", () => {
614
+ try {
615
+ const marker = "\"floor\"";
616
+ let count = 0;
617
+ let idx = 0;
618
+ while ((idx = data.indexOf(marker, idx)) !== -1) {
619
+ count++;
620
+ idx += marker.length;
621
+ }
622
+ if (count !== 1) {
623
+ process.stdout.write("true");
624
+ return;
625
+ }
626
+ const parsed = JSON.parse(data);
627
+ const cleared = parsed !== null &&
628
+ typeof parsed === "object" &&
629
+ !Array.isArray(parsed) &&
630
+ parsed.floor === false;
631
+ process.stdout.write(cleared ? "false" : "true");
632
+ } catch {
633
+ process.stdout.write("true");
634
+ }
635
+ });
636
+ ' 2>/dev/null)
637
+ if [ "$FLOOR_VALUE" = "false" ]; then
638
+ return 1
639
+ fi
640
+ return 0
641
+ }
642
+
643
+ # Auto mode — allow everything without routing to the phone, EXCEPT a target the
644
+ # protected-path / secret-read floor covers (#7004). #6794/#6803 gave that floor
645
+ # precedence over every lenient mode for the in-process providers, but this hook
646
+ # decides auto/acceptEdits itself and never reaches permission-manager.js — so
647
+ # claude-tui (the DEFAULT provider) and cli-session were auto-allowing `.env` /
648
+ # `id_rsa` reads and `.git`/`.claude` writes with no prompt. A floored target is
649
+ # never DENIED here; it is routed to the normal prompt, exactly as the in-process
650
+ # path falls through to one.
254
651
  if [ "$PERM_MODE" = "auto" ]; then
652
+ if floor_forces_prompt; then
653
+ route_to_phone
654
+ fi
255
655
  cat <<'EOF'
256
656
  {"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}
257
657
  EOF
@@ -263,6 +663,11 @@ if [ "$PERM_MODE" = "acceptEdits" ]; then
263
663
  # $REQUEST and $TOOL_NAME already populated at top of script (#4648).
264
664
  case "$TOOL_NAME" in
265
665
  Read|Write|Edit|NotebookEdit|Glob|Grep)
666
+ # #7004 — same floor precedence as auto above. Mirrors permission-manager.js,
667
+ # whose acceptEdits short-circuit is likewise gated on the floor.
668
+ if floor_forces_prompt; then
669
+ route_to_phone
670
+ fi
266
671
  cat <<'EOF'
267
672
  {"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}
268
673
  EOF
package/package.json CHANGED
@@ -1,44 +1,38 @@
1
1
  {
2
2
  "name": "@chroxy/server",
3
- "version": "0.10.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.10",
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
  },
23
17
  "scripts": {
24
18
  "start": "node src/cli.js start",
25
19
  "dev": "node --watch src/cli.js start",
26
- "test": "node ./scripts/assert-test-count.mjs c8 node --import ./tests/_setup.mjs --experimental-test-module-mocks --test './tests/**/*.test.js'",
20
+ "test": "node ../../scripts/lib/assert-test-count.mjs c8 node --import ./tests/_setup.mjs --experimental-test-module-mocks --test './tests/**/*.test.js'",
27
21
  "test:raw": "c8 node --import ./tests/_setup.mjs --experimental-test-module-mocks --test './tests/**/*.test.js'",
28
- "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'",
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",
31
- "lint": "eslint src/",
32
- "prepack": "node scripts/copy-dashboard-dist.mjs",
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/",
33
26
  "postinstall": "node scripts/fix-node-pty-helper.js"
34
27
  },
35
28
  "dependencies": {
29
+ "@agentclientprotocol/sdk": "1.4.0",
36
30
  "@anthropic-ai/claude-agent-sdk": "^0.2.0",
37
- "@anthropic-ai/sdk": "^0.81.0",
38
- "@chroxy/protocol": "0.10.0",
39
- "@chroxy/store-core": "0.10.0",
31
+ "@anthropic-ai/sdk": "^0.91.1",
32
+ "@chroxy/protocol": "^0.11.10",
33
+ "@chroxy/store-core": "^0.11.10",
40
34
  "@kubernetes/client-node": "^1.4.0",
41
- "@modelcontextprotocol/sdk": "^1.29.0",
35
+ "@modelcontextprotocol/sdk": "^1.32.0",
42
36
  "@xterm/addon-fit": "^0.10.0",
43
37
  "@xterm/xterm": "^5.5.0",
44
38
  "bonjour-service": "^1.3.0",
@@ -49,8 +43,8 @@
49
43
  "qrcode": "^1.5.3",
50
44
  "tweetnacl": "^1.0.3",
51
45
  "tweetnacl-util": "^0.15.1",
52
- "ws": "^8.16.0",
53
- "zod": "^4.3.6"
46
+ "ws": "^8.21.3",
47
+ "zod": "^4.6.6"
54
48
  },
55
49
  "engines": {
56
50
  "node": ">=22"
@@ -62,8 +56,11 @@
62
56
  },
63
57
  "license": "MIT",
64
58
  "devDependencies": {
59
+ "acorn": "8.16.0",
65
60
  "c8": "^11.0.0",
66
61
  "eslint": "^9.39.3",
67
- "playwright": "^1.58.2"
62
+ "js-yaml": "^4.1.1",
63
+ "playwright": "^1.58.2",
64
+ "typescript": "^5.9.3"
68
65
  }
69
66
  }
@@ -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.128
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
@@ -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.128`).
661
+ the `CLAUDE_CODE_VERSION` build ARG (default: `2.1.280`).
654
662
 
655
663
  **Override at build time:**
656
664
  ```sh