@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.
Files changed (317) hide show
  1. package/CONFIG.md +204 -18
  2. package/README.md +2 -2
  3. package/hooks/claude-native-route-check.mjs +17 -0
  4. package/hooks/permission-hook.sh +166 -11
  5. package/package.json +16 -12
  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 +1203 -36
  26. package/src/bearer-recheck.js +49 -0
  27. package/src/billing-budget.js +19 -0
  28. package/src/billing-class.js +40 -7
  29. package/src/binary-provenance-trust.js +11 -5
  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 +69 -5
  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 +92 -7
  37. package/src/byok-mcp-config.js +628 -121
  38. package/src/byok-mcp-fleet.js +49 -7
  39. package/src/byok-mcp-oauth-store.js +18 -16
  40. package/src/byok-mcp-trust.js +3 -3
  41. package/src/byok-session.js +650 -175
  42. package/src/byok-tool-executor.js +2662 -26
  43. package/src/byok-tools.js +9 -2
  44. package/src/channels/chroxy-channel-server.js +2 -3
  45. package/src/checkpoint-manager.js +64 -46
  46. package/src/claude-channel-session.js +16 -10
  47. package/src/claude-model-catalog.js +131 -16
  48. package/src/claude-model-refresh.js +385 -0
  49. package/src/claude-model-request.js +103 -0
  50. package/src/claude-stream-parser.js +53 -3
  51. package/src/claude-tui/diagnostic-tail.js +83 -0
  52. package/src/claude-tui/form-driver.js +44 -7
  53. package/src/claude-tui/model-error.js +41 -0
  54. package/src/claude-tui/pty-driver.js +211 -88
  55. package/src/claude-tui/sanitize-question-payload.js +109 -0
  56. package/src/claude-tui/usage-limit.js +239 -0
  57. package/src/claude-tui-session.js +3513 -287
  58. package/src/claude-tui-tool-response.js +300 -0
  59. package/src/cli/agent-control-cmd.js +65 -0
  60. package/src/cli/config-cmd.js +4 -4
  61. package/src/cli/config-dir-cmd.js +234 -0
  62. package/src/cli/deploy-cmd.js +45 -10
  63. package/src/cli/doctor-cmd.js +7 -3
  64. package/src/cli/init-cmd.js +15 -16
  65. package/src/cli/providers-cmd.js +3 -3
  66. package/src/cli/schedule-cmd.js +68 -39
  67. package/src/cli/server-cmd.js +48 -1
  68. package/src/cli/service-cmd.js +33 -10
  69. package/src/cli/session-cmd.js +227 -74
  70. package/src/cli/shared.js +162 -11
  71. package/src/cli/tokens-cmd.js +4 -5
  72. package/src/cli/tunnel-cmd.js +255 -24
  73. package/src/cli/worktree-gc-cmd.js +2 -2
  74. package/src/cli-session.js +1066 -121
  75. package/src/cli.js +4 -0
  76. package/src/codex-app-server-client.js +36 -3
  77. package/src/codex-app-server-session.js +1454 -79
  78. package/src/codex-bundled-client.js +66 -0
  79. package/src/codex-model-catalog.js +548 -0
  80. package/src/codex-model-rejections.js +87 -0
  81. package/src/codex-native-resume.js +104 -0
  82. package/src/codex-protocol-capabilities.js +188 -0
  83. package/src/codex-session.js +450 -27
  84. package/src/config-dir-migration.js +444 -0
  85. package/src/config-dir.js +108 -0
  86. package/src/config.js +286 -26
  87. package/src/connection-authority.js +48 -0
  88. package/src/connection-info.js +5 -9
  89. package/src/connection-locality.js +60 -0
  90. package/src/container-liveness-monitor.js +189 -0
  91. package/src/continuation-metadata-worker.js +17 -0
  92. package/src/continuations.js +114 -0
  93. package/src/control-room/host-prune.js +5 -0
  94. package/src/control-room/integrations.js +7 -20
  95. package/src/control-room/skills-inventory.js +2 -2
  96. package/src/conversation-scanner.js +40 -18
  97. package/src/conversation-scope.js +59 -39
  98. package/src/conversation-search.js +24 -22
  99. package/src/credential-store.js +23 -19
  100. package/src/daemon-commit.js +92 -0
  101. package/src/daemon-idle-state.js +171 -0
  102. package/src/daemon-update-status.js +314 -0
  103. package/src/dashboard-build.js +70 -0
  104. package/src/declared-status.js +90 -0
  105. package/src/deepseek-credentials.js +2 -3
  106. package/src/dev-preview.js +169 -182
  107. package/src/device-preferences.js +2 -2
  108. package/src/diff-parser.js +87 -0
  109. package/src/discord-credentials.js +2 -3
  110. package/src/docker-byok-pool.js +3 -1
  111. package/src/docker-byok-session.js +678 -78
  112. package/src/docker-image-allowlist.js +23 -1
  113. package/src/docker-sdk-session.js +172 -3
  114. package/src/docker-session.js +284 -10
  115. package/src/doctor.js +767 -61
  116. package/src/edited-input.js +264 -0
  117. package/src/environment-manager.js +175 -36
  118. package/src/environments/authority.js +95 -0
  119. package/src/environments/backends/container-claude-spawn.js +94 -0
  120. package/src/environments/backends/docker.js +31 -10
  121. package/src/environments/backends/k8s.js +49 -24
  122. package/src/environments/destroy-with-sessions.js +142 -0
  123. package/src/event-ingest.js +118 -13
  124. package/src/event-normalizer.js +151 -233
  125. package/src/gemini-session.js +81 -5
  126. package/src/handler-utils.js +535 -68
  127. package/src/handlers/checkpoint-handlers.js +39 -4
  128. package/src/handlers/control-room-handlers.js +51 -11
  129. package/src/handlers/conversation-handlers.js +469 -56
  130. package/src/handlers/daemon-update-handlers.js +81 -0
  131. package/src/handlers/evaluator-handlers.js +14 -1
  132. package/src/handlers/feature-handlers.js +186 -69
  133. package/src/handlers/file-handlers.js +57 -13
  134. package/src/handlers/input-handlers.js +685 -48
  135. package/src/handlers/orchestration-handlers.js +3 -3
  136. package/src/handlers/scheduler-handlers.js +88 -14
  137. package/src/handlers/session-handlers.js +542 -20
  138. package/src/handlers/session-pr-status-handlers.js +283 -0
  139. package/src/handlers/session-pr-threads-handlers.js +247 -0
  140. package/src/handlers/settings-handlers.js +330 -42
  141. package/src/handlers/skills-handlers.js +13 -4
  142. package/src/handlers/summarize-handlers.js +32 -1
  143. package/src/handlers/survey-throttle.js +380 -0
  144. package/src/health-proof.js +40 -0
  145. package/src/history-page.js +104 -0
  146. package/src/http-routes.js +127 -8
  147. package/src/ide/search.js +24 -6
  148. package/src/ide/symbols.js +20 -6
  149. package/src/input-context.js +117 -0
  150. package/src/instruction-policy-compiler.js +229 -0
  151. package/src/instruction-policy.js +250 -0
  152. package/src/jsonl-reader.js +289 -82
  153. package/src/jsonl-subprocess-session.js +92 -8
  154. package/src/keychain.js +1 -1
  155. package/src/logger.js +63 -17
  156. package/src/mailbox-route.js +11 -22
  157. package/src/message-wire.js +386 -0
  158. package/src/model-discovery.js +43 -3
  159. package/src/models.js +1276 -174
  160. package/src/notification-prefs.js +12 -4
  161. package/src/notifications/discord-billing-sink.js +22 -5
  162. package/src/notifications/discord-ci-sink.js +243 -0
  163. package/src/notifications/discord-webhook-client.js +71 -0
  164. package/src/notifications/discord-webhook-sink.js +64 -23
  165. package/src/notifications/expo-push-sink.js +85 -6
  166. package/src/notifications/ready-body.js +16 -5
  167. package/src/ollama-session.js +34 -2
  168. package/src/orchestration/build-manager.js +9 -2
  169. package/src/orchestration/git-ops.js +41 -7
  170. package/src/orchestration/orchestration-manager.js +80 -33
  171. package/src/orchestration/permission-gate.js +13 -1
  172. package/src/orchestration/run-model.js +2 -1
  173. package/src/orchestration/turn-driver.js +44 -20
  174. package/src/orphan-reaper.js +413 -0
  175. package/src/outgoing-policy.js +183 -0
  176. package/src/pairing.js +92 -13
  177. package/src/path-hash-trust-ledger.js +642 -25
  178. package/src/permission-deadlines.js +82 -0
  179. package/src/permission-floor.js +1357 -42
  180. package/src/permission-hook.js +180 -69
  181. package/src/permission-manager.js +712 -83
  182. package/src/permission-mode-support.js +35 -0
  183. package/src/permission-resolver.js +122 -8
  184. package/src/permission-scope.js +43 -0
  185. package/src/platform.js +159 -43
  186. package/src/preview-ingress.js +54 -0
  187. package/src/preview-target.js +213 -0
  188. package/src/prompt-evaluator.js +34 -4
  189. package/src/provider-customization.js +180 -0
  190. package/src/providers.js +207 -4
  191. package/src/push.js +30 -4
  192. package/src/question-route-map.js +130 -0
  193. package/src/redaction.js +360 -8
  194. package/src/roster-broadcast.js +186 -0
  195. package/src/scheduled-task-store.js +318 -26
  196. package/src/scheduler.js +73 -3
  197. package/src/sdk-session.js +2060 -187
  198. package/src/server-cli/preview-shutdown.js +22 -0
  199. package/src/server-cli/push-notification-handler.js +11 -2
  200. package/src/server-cli/server-orchestrator.js +28 -5
  201. package/src/server-cli-child.js +33 -18
  202. package/src/server-cli.js +524 -38
  203. package/src/server-identity.js +15 -11
  204. package/src/service.js +396 -25
  205. package/src/session-archive-limits.js +15 -0
  206. package/src/session-archive.js +1029 -0
  207. package/src/session-busy-state.js +72 -0
  208. package/src/session-ci-watcher.js +926 -0
  209. package/src/session-context.js +7 -2
  210. package/src/session-manager.js +3491 -312
  211. package/src/session-message-history.js +722 -16
  212. package/src/session-pr-status.js +654 -0
  213. package/src/session-pr-threads.js +271 -0
  214. package/src/session-preset-trust.js +3 -3
  215. package/src/session-preset.js +10 -5
  216. package/src/session-state-persistence.js +94 -17
  217. package/src/session-timeout-manager.js +20 -0
  218. package/src/session-token-store.js +17 -8
  219. package/src/session-wake.js +240 -0
  220. package/src/shell-approval-info.js +2 -2
  221. package/src/shell-approval-store.js +3 -1
  222. package/src/skills-loader.js +7 -4
  223. package/src/skills-manager.js +2 -2
  224. package/src/skills-trust.js +95 -13
  225. package/src/skills-usage.js +2 -3
  226. package/src/snapshots-store.js +2 -3
  227. package/src/statusline.js +23 -11
  228. package/src/summarize-session.js +51 -4
  229. package/src/supervisor.js +22 -11
  230. package/src/sweep-stale-provider-dirs.js +95 -0
  231. package/src/thinking-level-wire.js +39 -0
  232. package/src/thinking-stream.js +179 -0
  233. package/src/tool-result.js +61 -0
  234. package/src/transcript-sources.js +109 -0
  235. package/src/transcript-tasks.js +372 -25
  236. package/src/trusted-file-read.js +302 -0
  237. package/src/tunnel/base.js +0 -8
  238. package/src/tunnel/cloudflare.js +34 -31
  239. package/src/tunnel/index.js +9 -0
  240. package/src/tunnel/preview.js +64 -0
  241. package/src/turn-outcome.js +137 -0
  242. package/src/usage-normalize.js +9 -5
  243. package/src/user-shell-session.js +59 -5
  244. package/src/utils/agent-sdk-version.js +107 -0
  245. package/src/utils/argv-safety.js +741 -0
  246. package/src/utils/auth-cause.js +60 -0
  247. package/src/utils/binary-package-manifest.js +597 -0
  248. package/src/utils/binary-version.js +224 -0
  249. package/src/utils/bounded-regex-worker.js +25 -0
  250. package/src/utils/bounded-regex.js +153 -0
  251. package/src/utils/claude-binary.js +43 -0
  252. package/src/utils/claude-config-dir.js +245 -0
  253. package/src/utils/claude-login-command.js +16 -0
  254. package/src/utils/claude-native-route.js +81 -0
  255. package/src/utils/componentwise-resolver.js +133 -37
  256. package/src/utils/deploy-control-files.js +87 -0
  257. package/src/utils/exec-failure-reason.js +21 -0
  258. package/src/utils/git-repo.js +42 -0
  259. package/src/utils/is-entry-point.js +137 -0
  260. package/src/utils/node-pty-probe.js +95 -0
  261. package/src/utils/node-pty-support.js +118 -0
  262. package/src/utils/opened-file-path.js +167 -0
  263. package/src/utils/path-containment.js +165 -0
  264. package/src/utils/permission-mode-sidecar.js +51 -0
  265. package/src/utils/preflight.js +360 -16
  266. package/src/utils/read-limiter.js +217 -0
  267. package/src/utils/regular-file.js +375 -0
  268. package/src/utils/safe-regex.js +113 -0
  269. package/src/utils/small-file.js +129 -0
  270. package/src/utils/spawn-env.js +189 -4
  271. package/src/utils/stale-session-dirs.js +182 -0
  272. package/src/utils/stat-identity.js +43 -0
  273. package/src/utils/verify-provenance.js +406 -13
  274. package/src/web-task-manager.js +256 -16
  275. package/src/worktree-gc.js +7 -2
  276. package/src/ws-auth.js +69 -21
  277. package/src/ws-broadcaster.js +14 -2
  278. package/src/ws-client-manager.js +16 -1
  279. package/src/ws-client-sender.js +7 -0
  280. package/src/ws-file-ops/browser.js +331 -58
  281. package/src/ws-file-ops/common.js +320 -14
  282. package/src/ws-file-ops/git.js +395 -42
  283. package/src/ws-file-ops/index.js +2 -0
  284. package/src/ws-file-ops/memory.js +137 -35
  285. package/src/ws-file-ops/open-nofollow.js +354 -0
  286. package/src/ws-file-ops/reader.js +571 -113
  287. package/src/ws-forwarding.js +329 -39
  288. package/src/ws-handler-context.js +70 -2
  289. package/src/ws-history.js +940 -172
  290. package/src/ws-message-handlers.js +17 -1
  291. package/src/ws-permissions.js +307 -37
  292. package/src/ws-schemas.js +5 -0
  293. package/src/ws-server.js +643 -96
  294. package/sidecar/node_modules/.package-lock.json +0 -29
  295. package/sidecar/node_modules/ws/LICENSE +0 -20
  296. package/sidecar/node_modules/ws/README.md +0 -548
  297. package/sidecar/node_modules/ws/browser.js +0 -8
  298. package/sidecar/node_modules/ws/index.js +0 -22
  299. package/sidecar/node_modules/ws/lib/buffer-util.js +0 -131
  300. package/sidecar/node_modules/ws/lib/constants.js +0 -19
  301. package/sidecar/node_modules/ws/lib/event-target.js +0 -292
  302. package/sidecar/node_modules/ws/lib/extension.js +0 -203
  303. package/sidecar/node_modules/ws/lib/limiter.js +0 -55
  304. package/sidecar/node_modules/ws/lib/permessage-deflate.js +0 -528
  305. package/sidecar/node_modules/ws/lib/receiver.js +0 -706
  306. package/sidecar/node_modules/ws/lib/sender.js +0 -602
  307. package/sidecar/node_modules/ws/lib/stream.js +0 -161
  308. package/sidecar/node_modules/ws/lib/subprotocol.js +0 -62
  309. package/sidecar/node_modules/ws/lib/validation.js +0 -152
  310. package/sidecar/node_modules/ws/lib/websocket-server.js +0 -554
  311. package/sidecar/node_modules/ws/lib/websocket.js +0 -1393
  312. package/sidecar/node_modules/ws/package.json +0 -70
  313. package/sidecar/node_modules/ws/wrapper.mjs +0 -21
  314. package/src/dashboard-next/dist/assets/index-C2ipeGlq.js +0 -111
  315. package/src/dashboard-next/dist/assets/index-DM-_dISG.css +0 -1
  316. package/src/dashboard-next/dist/index.html +0 -13
  317. package/src/dashboard-next/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
@@ -4,7 +4,18 @@
4
4
  * Handles: set_model, set_permission_mode, permission_response,
5
5
  * query_permission_audit, list_providers, set_permission_rules
6
6
  */
7
- import { ALLOWED_MODEL_IDS, toShortModelId, isClaudeProvider } from '../models.js'
7
+ import { isSafeRegexSource } from '../utils/safe-regex.js'
8
+ import { getErrorMessage } from '../utils/error-message.js'
9
+ import { authorizedFor } from '../connection-authority.js'
10
+ import { isWellFormedThinkingLevel, resolveThinkingLevels, LEGACY_DEFAULT_THINKING_LEVEL } from '@chroxy/protocol'
11
+ import { buildThinkingLevelChanged } from '../thinking-level-wire.js'
12
+ import {
13
+ ALLOWED_MODEL_IDS,
14
+ toShortModelId,
15
+ isClaudeProvider,
16
+ getRosterModelRow,
17
+ thinkingLevelLegacyFallbackApplies,
18
+ } from '../models.js'
8
19
  import {
9
20
  ALLOWED_PERMISSION_MODE_IDS,
10
21
  resolveSession,
@@ -15,9 +26,11 @@ import {
15
26
  buildSessionTokenMismatchPayload,
16
27
  isSessionViewer,
17
28
  } from '../handler-utils.js'
18
- import { listProviders, getProvider } from '../providers.js'
29
+ import { listProviders, getProvider, resolveDaemonDefaultProvider } from '../providers.js'
19
30
  import { isProviderModelUnrestricted } from '../config.js'
31
+ import { getProviderPermissionModeSupport } from '../permission-mode-support.js'
20
32
  import { createLogger, loggerForSession, sessionLogger } from '../logger.js'
33
+ import { isBoundClient } from '../environments/authority.js'
21
34
  // Credential + skills handlers were split into sibling modules (audit P2-4);
22
35
  // their maps are composed into settingsHandlers below.
23
36
  import { credentialHandlers } from './credential-handlers.js'
@@ -26,7 +39,7 @@ import {
26
39
  PER_SESSION_SETTINGS,
27
40
  buildPerSessionSettingHandler,
28
41
  } from '../per-session-settings.js'
29
- import { createPermissionResolver, resolveOriginSessionId } from '../permission-resolver.js'
42
+ import { createPermissionResolver, resolveOriginSessionId, buildLegacyResolvedBroadcast } from '../permission-resolver.js'
30
43
  import { sanitizeToolInput, PULL_MAX_INPUT_CHARS } from '../redaction.js'
31
44
  // #6605 — SINGLE source of truth for the rule-eligibility sets. These used to be
32
45
  // a duplicate hard-coded copy here, which silently drifted from
@@ -65,6 +78,19 @@ const PROVIDER_MODELS_UNRESTRICTED = Symbol('provider-models-unrestricted')
65
78
  * - `null` — no method / unknown provider / method threw: use the
66
79
  * global allowlist (conservative legacy behaviour).
67
80
  *
81
+ * A provider may move between the first two states at RUNTIME. `codex`
82
+ * (#7727) and the `anthropicCompatible` / `openaiCompatible` entries with
83
+ * live discovery return an array once their catalog is in hand and a
84
+ * non-array before that, so nothing here may cache the answer or assume a
85
+ * provider is permanently restricted.
86
+ *
87
+ * NOTE for anyone adding a provider: an EMPTY array is not "unrestricted"
88
+ * here. It is truthy, so it takes the allowlist branch below and
89
+ * `[].includes(model)` rejects every id — a total lockout, and one that
90
+ * `session-manager.js`'s copy of this gate does NOT reproduce (it guards on
91
+ * `length > 0` and skips validation instead). A provider with nothing to
92
+ * assert must return a NON-ARRAY, never `[]` (#7727).
93
+ *
68
94
  * @param {string|undefined} providerName - Session's registered provider name
69
95
  * @returns {string[]|typeof PROVIDER_MODELS_UNRESTRICTED|null}
70
96
  */
@@ -290,9 +316,25 @@ function handleSetPermissionMode(ws, client, msg, ctx) {
290
316
  sendSessionError(ws, ctx, 'This provider does not support plan mode')
291
317
  return
292
318
  }
293
- // Auto permission mode is the ultimate privilege escalation in
294
- // the chroxy handler dispatch — it disables all permission
295
- // checks, so every subsequent tool call auto-executes. The
319
+ // #7825 — reject unsupported adapter/mode combinations before the Auto
320
+ // config/confirmation flow. BaseSession repeats this guard for direct
321
+ // callers; this wire gate supplies a precise error instead of a generic
322
+ // post-setter no-op.
323
+ const modeSupport = getProviderPermissionModeSupport(entry.session.constructor, msg.mode)
324
+ if (!modeSupport.supported) {
325
+ sendError(
326
+ ws,
327
+ msg?.requestId,
328
+ 'CAPABILITY_NOT_SUPPORTED',
329
+ `The active provider '${entry.provider || 'unknown'}' cannot use '${msg.mode}' because its adapter cannot guarantee protected-path prompts reach Chroxy's permission floor.`,
330
+ undefined,
331
+ ctx,
332
+ )
333
+ return
334
+ }
335
+ // Auto permission mode is a broad privilege escalation in
336
+ // the chroxy handler dispatch — ordinary tool calls auto-execute while
337
+ // the protected-path floor still forces a real decision. The
296
338
  // 2026-04-11 audit (Adversary A5) flagged this as a step in
297
339
  // the kill chain: an authenticated attacker sends
298
340
  // `{mode:'auto', confirmed:true}` and trivially flips the
@@ -317,10 +359,10 @@ function handleSetPermissionMode(ws, client, msg, ctx) {
317
359
  // and should only be able to use existing permissions, not
318
360
  // escalate. Only the primary API token can flip to auto.
319
361
  if (msg.mode === 'auto') {
320
- if (client.boundSessionId) {
362
+ if (isBoundClient(client)) {
321
363
  // #4828: session-scoped to the bound session — that's the
322
364
  // session the rejection belongs to.
323
- loggerForSession('ws', client.boundSessionId).warn(`Client ${client.id} (bound to ${client.boundSessionId}) attempted to flip to auto permission mode — rejected`)
365
+ sessionLogger(client.boundSessionId, 'ws').warn(`Client ${client.id} (bound to ${client.boundSessionId}) attempted to flip to auto permission mode — rejected`)
324
366
  sendError(ws, msg?.requestId, 'AUTO_MODE_FORBIDDEN_BOUND_CLIENT',
325
367
  'Pairing-issued session tokens cannot enable auto permission mode. Use the primary API token from a device with physical access to this machine.',
326
368
  undefined, ctx)
@@ -346,9 +388,12 @@ function handleSetPermissionMode(ws, client, msg, ctx) {
346
388
  // keep the plain warning. The warning string is rendered verbatim by
347
389
  // the mobile app's confirm Alert (SettingsBar.tsx).
348
390
  const interruptsTurn = !!entry.session.constructor.capabilities?.interruptsTurnOnAutoSwitch
391
+ const enforcementCopy = modeSupport.enforcement === 'chroxy'
392
+ ? 'Protected paths and secret reads still require a Chroxy prompt.'
393
+ : 'Protected-path and secret-read enforcement is not reported by this provider.'
349
394
  const warning = interruptsTurn && entry.session._isBusy
350
- ? 'This session is mid-response. Switching to Auto will INTERRUPT the running turn and restart the session — the in-flight response will be dropped. Tools will then run without asking for permission.'
351
- : 'Auto mode bypasses all permission checks. Claude will execute tools without asking.'
395
+ ? `This session is mid-response. Switching to Auto will INTERRUPT the running turn and restart the session — the in-flight response will be dropped. Ordinary tools will then run without asking; ${enforcementCopy}`
396
+ : `Auto mode runs ordinary tools without asking. ${enforcementCopy}`
352
397
  ctx.transport.send(ws, {
353
398
  type: 'confirm_permission_mode',
354
399
  mode: 'auto',
@@ -405,6 +450,7 @@ function handleSetPermissionMode(ws, client, msg, ctx) {
405
450
  function handlePermissionResponse(ws, client, msg, ctx) {
406
451
  const { requestId, decision } = msg
407
452
  if (!requestId || !decision) return
453
+ if (ctx.services?.devPreview?.respondToConsent(client, msg)) return
408
454
 
409
455
  // #5373: the binding check + SDK-vs-legacy dispatch + audit are delegated to
410
456
  // the shared permission-resolver (also used by the HTTP handler in
@@ -438,9 +484,20 @@ function handlePermissionResponse(ws, client, msg, ctx) {
438
484
  // subscribed client can still respond. WS-ONLY by design: a primary HTTP caller
439
485
  // has full session authority (§3), so the HTTP path has no analog and must not
440
486
  // inherit this restriction.
441
- if (!client.boundSessionId && originSessionId) {
487
+ if (!isBoundClient(client) && originSessionId) {
442
488
  if (!isSessionViewer(client, originSessionId)) {
443
489
  sessionLogger(originSessionId).warn(`[permission-response-reject] unbound client ${client.id} attempted to respond to ${requestId} (originSessionId=${originSessionId}, activeSessionId=${client.activeSessionId ?? 'none'}, subscribed=false) — dropped`)
490
+ // #7858: answer with the SAME correlated negative a never-registered id gets
491
+ // (the caller's OWN active session, never the request's), so the caller sees
492
+ // an outcome instead of waiting out a timeout, and cannot tell "exists in a
493
+ // session I don't view" from "does not exist". The decision was NOT routed
494
+ // and the mapping is untouched.
495
+ ctx.transport.send(ws, {
496
+ type: 'permission_expired',
497
+ requestId,
498
+ ...(typeof client.activeSessionId === 'string' && client.activeSessionId.length > 0 ? { sessionId: client.activeSessionId } : {}),
499
+ message: 'This permission request has expired or was already handled',
500
+ })
444
501
  return
445
502
  }
446
503
  }
@@ -467,6 +524,10 @@ function handlePermissionResponse(ws, client, msg, ctx) {
467
524
  // server bounds + redacts it (permission-manager.js buildDenyMessage) and
468
525
  // feeds it back to the agent as the denial message instead of 'User denied'.
469
526
  reason: msg.reason,
527
+ // #8517: the "Allow for Session" label. The resolver keeps it only beside an
528
+ // `allow`; it grants nothing (the session rule is the client's separate
529
+ // set_permission_rules) and only names the allow in the broadcast and journal.
530
+ scope: msg.scope,
470
531
  })
471
532
 
472
533
  if (result.kind === 'binding_mismatch') {
@@ -484,7 +545,7 @@ function handlePermissionResponse(ws, client, msg, ctx) {
484
545
  )
485
546
  // #4828: session-scoped to the bound session — the reject belongs to the
486
547
  // OWNER of `boundSessionId`, not the mismatched mapped session.
487
- loggerForSession('ws', result.boundSessionId).warn(`[session-binding-reject] permission_response rejected ${JSON.stringify({
548
+ sessionLogger(result.boundSessionId, 'ws').warn(`[session-binding-reject] permission_response rejected ${JSON.stringify({
488
549
  requestId,
489
550
  decision,
490
551
  clientId: client.id,
@@ -511,6 +572,14 @@ function handlePermissionResponse(ws, client, msg, ctx) {
511
572
  return
512
573
  }
513
574
 
575
+ if (result.kind === 'edit_refused') {
576
+ // #8446: the resolver denied the request (fail closed: nothing was written) and
577
+ // the answering client is told why. The other clients learn of the denial from
578
+ // the unified pipeline's permission_resolved.
579
+ sendError(ws, requestId, 'PERMISSION_EDIT_REFUSED', result.message, undefined, ctx)
580
+ return
581
+ }
582
+
514
583
  if (result.kind === 'expired' || result.kind === 'not_found') {
515
584
  // #7096: OMIT sessionId when it is not a real id. `originSessionId` resolves to
516
585
  // `client.activeSessionId`, which defaults to null (ws-server.js), so the
@@ -529,23 +598,23 @@ function handlePermissionResponse(ws, client, msg, ctx) {
529
598
  // result.kind === 'resolved' — the resolver dispatched (sdk|legacy) + audited.
530
599
  // #3048: SDK-session broadcasts go through the unified pipeline
531
600
  // (PermissionManager → SdkSession → SessionManager → EventNormalizer →
532
- // broadcast). Legacy non-SDK sessions (no PermissionManager) keep an inline
533
- // broadcast for the unmapped case only — mirrors the prior `!originSessionId`.
534
- if (!result.sessionId) {
535
- // #6590: broadcast to ALL clients INCLUDING the resolver (no `c.id !==
536
- // client.id` exclusion). The resolving client needs its own
537
- // `permission_resolved` to prune `permissionInputs[requestId]` (#6559) —
538
- // append-only otherwise, so on this legacy path the entry used to linger
539
- // until disconnect. Echoing to the resolver is SAFE to re-apply: the
540
- // `permissionInputs` prune is a guarded copy-delete, the notification
541
- // read-stamp only touches not-yet-acked rows, and re-marking the
542
- // already-answered prompt is functionally inert (its label reads from
543
- // `resolvedPermissions`, and the pending-count only checks that `answered`
544
- // is truthy — only `answeredAt` is refreshed to the server-confirmed time).
545
- // This also matches the SDK path, which broadcasts session events to every
546
- // subscriber without excluding the origin client.
547
- ctx.transport.broadcast({ type: 'permission_resolved', requestId, decision })
548
- }
601
+ // broadcast). Only a legacy (non-SDK) dispatch keeps an inline broadcast, and
602
+ // whether the frame may NAME a session is decided by `result.mapped` (the
603
+ // request's own mapping), never by `result.sessionId`: for an UNMAPPED prompt
604
+ // the resolver fills `sessionId` from `client.activeSessionId` (dispatch
605
+ // fallback), so keying on it dropped the frame whenever the answering client had
606
+ // an active session (#8359). Mirrors POST /permission-response (ws-permissions.js).
607
+ // #7858: the legacy announcement is built once in permission-resolver.js and
608
+ // shared with POST /permission-response. Mapped (#7976): a hook-routed prompt
609
+ // (claude-tui / claude-cli / claude-channel) has NO PermissionManager, so
610
+ // nothing else announces its resolution — without this every other client keeps
611
+ // a stale card and agent-control reports `uncertain`. Unmapped (#6590): echoed to
612
+ // the resolver too, which needs it to prune `permissionInputs[requestId]`
613
+ // (#6559); re-applying it is inert. The resolver's own frame is therefore the
614
+ // success confirmation for BOTH, correlated by requestId + decision.
615
+ const effectiveDecision = result.decision ?? decision
616
+ const legacyBroadcast = buildLegacyResolvedBroadcast(result, requestId, effectiveDecision)
617
+ if (legacyBroadcast) ctx.transport.broadcast(legacyBroadcast.frame, legacyBroadcast.filter)
549
618
 
550
619
  // #6771 — an `allowAlways` that resolved on an in-process session just
551
620
  // persisted a durable project rule (permission-manager.js). Broadcast the
@@ -553,7 +622,14 @@ function handlePermissionResponse(ws, client, msg, ctx) {
553
622
  // etc.) reflects the new standing grant without a reconnect. The manager
554
623
  // updated its in-memory persistent set synchronously during respondToPermission,
555
624
  // so getPersistentPermissionRules() already includes it.
556
- if (decision === 'allowAlways' && result.sessionId) {
625
+ //
626
+ // #8398: gated on `via === 'sdk'`, as POST /permission-response is. A legacy
627
+ // dispatch (an unmapped HTTP-held prompt, or a hook-routed one) has no
628
+ // PermissionManager or rule store behind it, so an `allowAlways` there persists
629
+ // nothing and the rules did not change. For an UNMAPPED prompt `result.sessionId`
630
+ // is also only the answerer's dispatch fallback (#8359), so the frame would be a
631
+ // wasted refresh of an unrelated session's unchanged rules.
632
+ if (effectiveDecision === 'allowAlways' && result.via === 'sdk' && result.sessionId) {
557
633
  const rulesEntry = ctx.sessions.sessionManager?.getSession?.(result.sessionId)
558
634
  const rulesSession = rulesEntry?.session
559
635
  if (rulesSession && typeof rulesSession.getPersistentPermissionRules === 'function') {
@@ -574,8 +650,8 @@ function handleQueryPermissionAudit(ws, client, msg, ctx) {
574
650
  // omit sessionId entirely and pull the GLOBAL cross-session audit log. Bound
575
651
  // clients must name their own boundSessionId explicitly; the global query is
576
652
  // host-authority (unbound / primary token) only.
577
- if (client.boundSessionId && msg.sessionId !== client.boundSessionId) {
578
- loggerForSession('ws', client.boundSessionId).warn(`Client ${client.id} (bound to ${client.boundSessionId}) attempted to query permission audit for ${msg.sessionId || 'ALL sessions'} — rejected`)
653
+ if (isBoundClient(client) && msg.sessionId !== client.boundSessionId) {
654
+ sessionLogger(client.boundSessionId, 'ws').warn(`Client ${client.id} (bound to ${client.boundSessionId}) attempted to query permission audit for ${msg.sessionId || 'ALL sessions'} — rejected`)
579
655
  sendError(ws, msg?.requestId, 'PERMISSION_AUDIT_FORBIDDEN_BOUND_CLIENT',
580
656
  "Pairing-issued session tokens can only query their own session's permission audit.",
581
657
  undefined, ctx)
@@ -596,10 +672,142 @@ function handleQueryPermissionAudit(ws, client, msg, ctx) {
596
672
  }
597
673
 
598
674
  function handleListProviders(ws, client, msg, ctx) {
599
- ctx.transport.send(ws, { type: 'provider_list', providers: listProviders() })
675
+ ctx.transport.send(ws, {
676
+ type: 'provider_list',
677
+ providers: listProviders({ agentConnections: ctx.services?.config?.agentConnections }),
678
+ // #8151 (C3) — this daemon's own resolved default (CLI > env > config file
679
+ // > DEFAULT_PROVIDER), so a client can override its baked-in
680
+ // DEFAULT_PROVIDER fallback with what actually works here —
681
+ // e.g. the Docker image's ENV CHROXY_PROVIDER=claude-sdk.
682
+ defaultProvider: resolveDaemonDefaultProvider(ctx.services?.config),
683
+ })
684
+ }
685
+
686
+ /**
687
+ * #7730 — the AUTHORITATIVE per-model thinking-level gate.
688
+ *
689
+ * This replaces `VALID_THINKING_LEVELS`, a Set of the three Claude levels and
690
+ * one of six frozen copies of a vocabulary that was only ever true of the
691
+ * Claude family. Codex advertises `supportedReasoningEfforts` PER MODEL (the
692
+ * values differ per model and move with releases), so the question "is this a
693
+ * real level?" has no repo-wide answer — only "is this level offered by the
694
+ * model THIS session is running?", and this handler is the layer that can see
695
+ * both the session and its provider.
696
+ *
697
+ * #7784 — THE ROSTER AND THE PICKER NOW READ THE SAME ROW.
698
+ *
699
+ * The row comes from `getRosterModelRow(provider, modelId)`, which is the
700
+ * roster `available_models` carried to this client — `getRegistryForProvider`'s
701
+ * rows, matched on `fullId || id` exactly as the dashboard's picker matches
702
+ * them. It used to come from `ProviderClass.getModelMetadata(id)`, a SECOND
703
+ * source with its own refresh timing, and the two provably disagreed: after a
704
+ * codex `model/list` that answers with zero rows the catalog records the empty
705
+ * answer while nothing is broadcast for it, so the registry keeps serving the
706
+ * previously discovered rows — levels and all — while `getModelMetadata` for
707
+ * those same ids returns null. The picker offered the stale row's efforts and
708
+ * this gate refused every one of them.
709
+ *
710
+ * A row with no `reasoningLevels` at all — every Claude provider today — falls
711
+ * back to `LEGACY_THINKING_LEVELS`, so claude-sdk keeps accepting the Claude
712
+ * triple and mapping it to `maxThinkingTokens`. That fallback is the CLAUDE
713
+ * family's roster and nobody else's, so whether it applies is asked through
714
+ * `thinkingLevelLegacyFallbackApplies` — the same derivation `listProviders()`
715
+ * ships to clients as the `thinkingLevelLegacyFallback` capability, so the
716
+ * picker narrows with this gate instead of against it. On a provider where it
717
+ * does not apply the answer is an EMPTY roster (`source: 'none'`) and the caller
718
+ * refuses every level: handing a cannot-check the Claude three would let
719
+ * `default` (offered by NO codex model, and the picker's first option) ride out
720
+ * on `turn/start.effort` as if a model had advertised it — "could not check"
721
+ * reading as "nothing to check", cause #2 in docs/false-safety-guards.md. The
722
+ * reachability is not hypothetical: `CodexSession.getFallbackModels` seeds the
723
+ * registry from `CODEX_MODEL_METADATA`, whose six rows carry no
724
+ * `reasoningLevels` at all, and `_refreshModelCatalog()` is skipped permanently
725
+ * when the binary reports `supportsModelList === false`.
726
+ *
727
+ * `claudeFamily` prefers the registry class and falls back to the live
728
+ * session's own constructor, so a session whose `entry.provider` is missing or
729
+ * unregistered is still classified by the class that is actually running
730
+ * (`isClaudeProvider` treats a passed class's `static claudeFamily` as
731
+ * authoritative).
732
+ *
733
+ * EXPORTED for the parity guard (`tests/thinking-level-roster-parity.test.js`),
734
+ * which drives one roster row through this function and through the picker's
735
+ * own `thinkingLevelOptions` and compares the two sets in both directions.
736
+ *
737
+ * @returns {{levels: string[], defaultLevel: string, source: 'model'|'legacy'|'none', modelId: string|null, claudeFamily: boolean}}
738
+ */
739
+ export function resolveSessionThinkingLevels(entry) {
740
+ const session = entry?.session
741
+ // Same precedence as ws-history's `model_changed` replay and session-manager's
742
+ // session_info render: the operator's explicit override first, then the model
743
+ // the provider actually booted. Keeping the three in step is what stops the
744
+ // gate from validating against a model the session is not running.
745
+ const modelId = (typeof session?.model === 'string' && session.model.length > 0)
746
+ ? session.model
747
+ : ((typeof session?.bootedModel === 'string' && session.bootedModel.length > 0) ? session.bootedModel : null)
748
+
749
+ const providerName = (typeof entry?.provider === 'string' && entry.provider.length > 0) ? entry.provider : null
750
+
751
+ let ProviderClass = null
752
+ if (providerName) {
753
+ // TWO lookups, TWO try blocks, because they fail for different reasons and
754
+ // only one of them says anything about which FAMILY the session belongs to.
755
+ try {
756
+ ProviderClass = getProvider(providerName) || null
757
+ } catch (err) {
758
+ // The provider NAME did not resolve to a class. A cannot-check, and it is
759
+ // LOGGED rather than swallowed: without this line a deployment whose
760
+ // registry lookup is permanently broken is indistinguishable in every log
761
+ // from one that is working (docs/false-safety-guards.md #2).
762
+ log.warn(`Thinking-level provider lookup failed for provider '${providerName}': ${err?.message || err}`)
763
+ ProviderClass = null
764
+ }
765
+ }
766
+
767
+ // Preferred for BOTH questions below: the class the registry resolved, else
768
+ // the class actually running. `isClaudeProvider` treats a passed class as
769
+ // authoritative, so a session whose entry lost its provider string is still
770
+ // classified by what it is.
771
+ const resolvedClass = ProviderClass || entry?.session?.constructor || null
772
+
773
+ let row = null
774
+ try {
775
+ row = getRosterModelRow(providerName, modelId)
776
+ } catch (err) {
777
+ // The ROSTER is unavailable — and that is all. `ProviderClass` stays set on
778
+ // purpose: it really resolved, and isClaudeProvider treats a passed class as
779
+ // authoritative, so nulling it here would downgrade a Claude session to its
780
+ // live constructor and then to the name map because of a failure one call
781
+ // LATER. The roster falls back (row null); the FAMILY does not have to.
782
+ // Reachable because building a provider registry runs provider-class code
783
+ // (`getFallbackModels()`), which a throwing implementation turns into a
784
+ // cannot-check here.
785
+ log.warn(`Thinking-level roster lookup failed for provider '${providerName || 'none'}' model '${modelId}': ${err?.message || err}`)
786
+ row = null
787
+ }
788
+
789
+ // ONE question, asked once, through the derivation `listProviders()` also
790
+ // ships: "does the legacy triple stand in for a row that advertised nothing
791
+ // on this provider?" It is the Claude-family test, which is why the returned
792
+ // `claudeFamily` is the same value rather than a second call — two spellings
793
+ // of one fact are free to disagree, and this one is load-bearing on both
794
+ // sides of the wire.
795
+ const legacyFallback = thinkingLevelLegacyFallbackApplies(providerName, resolvedClass)
796
+ return {
797
+ ...resolveThinkingLevels(row, { legacyFallback }),
798
+ modelId,
799
+ claudeFamily: legacyFallback,
800
+ }
600
801
  }
601
802
 
602
- const VALID_THINKING_LEVELS = new Set(['default', 'high', 'max'])
803
+ /**
804
+ * A provider's setter may reject with anything: null, undefined or a bare
805
+ * string. `err.message` on the first two would throw INSIDE the catch block and
806
+ * the client would never get its THINKING_LEVEL_NOT_APPLIED (#7786 review).
807
+ */
808
+ function thrownMessage(err) {
809
+ return getErrorMessage(err, typeof err === 'string' && err.length > 0 ? err : 'unknown error')
810
+ }
603
811
 
604
812
  async function handleSetThinkingLevel(ws, client, msg, ctx) {
605
813
  // #5731 T9: every rejection path echoes the client's requestId with a single
@@ -612,8 +820,21 @@ async function handleSetThinkingLevel(ws, client, msg, ctx) {
612
820
  // dropdown stuck on a level the session never entered. requestId is optional
613
821
  // (older clients omit it); sendError tolerates null.
614
822
  const requestId = msg?.requestId
823
+ // #7786 — an explicit `level: null` is the wire spelling of "clear the
824
+ // override" (back to the provider/model default). Exactly null: an absent key,
825
+ // '' and whitespace stay malformed and are refused by the form check below, so
826
+ // a client that merely forgot the field cannot un-pin a level by accident.
827
+ const clearing = msg.level === null
615
828
  const level = typeof msg.level === 'string' ? msg.level.trim() : ''
616
- if (!VALID_THINKING_LEVELS.has(level)) {
829
+ // #7730 — two questions, asked separately and in this order.
830
+ //
831
+ // FORM first, because it needs no session: the level is about to become a
832
+ // JSON-RPC param on a subprocess, so charset and length are checked with the
833
+ // same predicate the wire schema uses (1-32 chars of [A-Za-z0-9_-] — this is
834
+ // what refuses `../../etc` and a 200-char string). This says nothing about
835
+ // which levels exist; a syntactic guard that also carried the roster is what
836
+ // the six-site problem was made of.
837
+ if (!clearing && !isWellFormedThinkingLevel(level)) {
617
838
  sendError(ws, requestId, 'THINKING_LEVEL_NOT_APPLIED', `Invalid thinking level: ${level}`, undefined, ctx)
618
839
  return
619
840
  }
@@ -630,11 +851,74 @@ async function handleSetThinkingLevel(ws, client, msg, ctx) {
630
851
  return
631
852
  }
632
853
 
854
+ // A CLEAR names no level, so there is nothing to check against a roster — and
855
+ // it must work when the roster is empty (a pre-catalog codex session refuses
856
+ // every SET, yet an override recorded earlier still has to be undoable).
857
+ // Everything after this point is about validating a level being SET.
858
+ if (clearing) {
859
+ const previousLevel = entry.session.thinkingLevel || LEGACY_DEFAULT_THINKING_LEVEL
860
+ try {
861
+ await entry.session.setThinkingLevel(null)
862
+ const described = typeof entry.session.describeThinkingLevel === 'function' ? entry.session.describeThinkingLevel() : null
863
+ ;sessionLogger(sessionId).info(`Thinking level cleared by ${client.id} on session ${sessionId}: ${previousLevel} → provider default${described ? ` (${described})` : ''}`)
864
+ ctx.transport.broadcastToSession(sessionId, buildThinkingLevelChanged(entry.session) ?? { type: 'thinking_level_changed', level: LEGACY_DEFAULT_THINKING_LEVEL })
865
+ } catch (err) {
866
+ sendError(ws, requestId, 'THINKING_LEVEL_NOT_APPLIED', `Failed to clear thinking level: ${thrownMessage(err)}`, undefined, ctx)
867
+ }
868
+ return
869
+ }
870
+
871
+ // MEMBERSHIP second, and only here — this is the first point that knows both
872
+ // the session and the model it is running, which is the only scope in which
873
+ // the question has an answer (see resolveSessionThinkingLevels above).
874
+ const offered = resolveSessionThinkingLevels(entry)
875
+ // NO ROSTER AT ALL is its own rejection, before membership, and it carries a
876
+ // different message: "this model has advertised nothing" is not "you picked
877
+ // the wrong level", and an empty `Supported levels:` list reads as a bug.
878
+ //
879
+ // `source: 'none'` is reached only when the row advertised nothing AND this
880
+ // provider has no legacy fallback (#7784) — the pre-catalog codex state. The
881
+ // Claude path never reaches it (the fallback applies, so source is 'legacy'
882
+ // with the triple), and a codex row that DID advertise levels has source
883
+ // 'model'. Since #7784 the picker resolves from the SAME fact, so it offers
884
+ // nothing here rather than offering three levels this branch refuses; the
885
+ // branch stays because a client can send any level it likes, and an older
886
+ // client still offers the triple.
887
+ if (offered.levels.length === 0) {
888
+ ;sessionLogger(sessionId).warn(`Rejected thinking level '${level}' on ${entry.provider || 'unknown-provider'} session ${sessionId} from ${client.id}: model ${offered.modelId || 'unknown'} has advertised no reasoning levels, and the legacy roster is Claude-only (source=${offered.source})`)
889
+ sendError(
890
+ ws,
891
+ requestId,
892
+ 'THINKING_LEVEL_NOT_APPLIED',
893
+ `Model '${offered.modelId || 'unknown'}' has not advertised its reasoning levels yet, so no level can be applied on ${entry.provider || 'this provider'}.`,
894
+ undefined,
895
+ ctx,
896
+ )
897
+ return
898
+ }
899
+ if (!offered.levels.includes(level)) {
900
+ ;sessionLogger(sessionId).warn(`Rejected thinking level '${level}' on ${entry.provider || 'unknown-provider'} session ${sessionId} from ${client.id}: model ${offered.modelId || 'unknown'} offers ${offered.levels.join(', ')} (${offered.source})`)
901
+ sendError(
902
+ ws,
903
+ requestId,
904
+ 'THINKING_LEVEL_NOT_APPLIED',
905
+ `Thinking level '${level}' is not offered by model '${offered.modelId || 'unknown'}'. Supported levels: ${offered.levels.join(', ')}`,
906
+ undefined,
907
+ ctx,
908
+ )
909
+ return
910
+ }
911
+
912
+ const previousLevel = entry.session.thinkingLevel || LEGACY_DEFAULT_THINKING_LEVEL
633
913
  try {
634
914
  await entry.session.setThinkingLevel(level)
635
- ctx.transport.broadcastToSession(sessionId, { type: 'thinking_level_changed', level })
915
+ // #8700: the line an operator checks before a send. A provider that can say
916
+ // what it will run (SdkSession) appends its model/requested/effective summary.
917
+ const described = typeof entry.session.describeThinkingLevel === 'function' ? entry.session.describeThinkingLevel() : null
918
+ ;sessionLogger(sessionId).info(`Thinking level change from ${client.id} on session ${sessionId}: ${previousLevel} → ${level}${described ? ` (${described})` : ''}`)
919
+ ctx.transport.broadcastToSession(sessionId, buildThinkingLevelChanged(entry.session) ?? { type: 'thinking_level_changed', level })
636
920
  } catch (err) {
637
- sendError(ws, requestId, 'THINKING_LEVEL_NOT_APPLIED', `Failed to set thinking level: ${err.message}`, undefined, ctx)
921
+ sendError(ws, requestId, 'THINKING_LEVEL_NOT_APPLIED', `Failed to set thinking level: ${thrownMessage(err)}`, undefined, ctx)
638
922
  }
639
923
  }
640
924
 
@@ -647,7 +931,7 @@ async function handleSetThinkingLevel(ws, client, msg, ctx) {
647
931
  * window from silently losing the change.
648
932
  *
649
933
  * Empty string and `null` both clear the override — at that point
650
- * `shouldSkipEvaluator` falls through to the server-wide
934
+ * `shouldSkipEvaluatorAsync` falls through to the server-wide
651
935
  * `config.promptEvaluatorSkipPattern` (#3187) and the default skip rules.
652
936
  *
653
937
  * Validation: BaseSession.setPromptEvaluatorSkipPattern returns false for
@@ -682,6 +966,10 @@ function handleSetPromptEvaluatorSkipPattern(ws, client, msg, ctx) {
682
966
  sendSessionError(ws, ctx, `Invalid pattern: ${err.message || 'malformed regex'}`)
683
967
  return
684
968
  }
969
+ if (!isSafeRegexSource(msg.value)) {
970
+ sendSessionError(ws, ctx, 'Pattern not accepted: over 200 characters, uses a backreference, or repeats a group that begins with an unbounded repeat (such as `(a+)+`)')
971
+ return
972
+ }
685
973
  }
686
974
 
687
975
  const changed = entry.session.setPromptEvaluatorSkipPattern(msg.value)
@@ -718,8 +1006,8 @@ function handleSetPermissionRules(ws, client, msg, ctx) {
718
1006
  // (share-a-session) client set them is exactly that escalation. The gate is
719
1007
  // host-authority = an UNBOUND client (no boundSessionId — the primary token,
720
1008
  // or an unbound linking-mode pairing token), mirroring rejectCredentialWriteIfBound.
721
- if (client.boundSessionId) {
722
- loggerForSession('ws', client.boundSessionId).warn(`Client ${client.id} (bound to ${client.boundSessionId}) attempted to set permission rules — rejected`)
1009
+ if (isBoundClient(client)) {
1010
+ sessionLogger(client.boundSessionId, 'ws').warn(`Client ${client.id} (bound to ${client.boundSessionId}) attempted to set permission rules — rejected`)
723
1011
  sendError(ws, msg?.requestId, 'PERMISSION_RULES_FORBIDDEN_BOUND_CLIENT',
724
1012
  'Pairing-issued session tokens cannot modify permission rules. Use the primary API token from a device with physical access to this machine.',
725
1013
  undefined, ctx)
@@ -1057,7 +1345,7 @@ function handleGetPermissionInput(ws, client, msg, ctx) {
1057
1345
 
1058
1346
  // Same authority gate as permission_response — a client may only read the
1059
1347
  // input for a permission it could itself answer.
1060
- if (client.boundSessionId) {
1348
+ if (isBoundClient(client)) {
1061
1349
  if (client.boundSessionId !== sessionId) return notFound('NOT_FOUND', 'No pending permission for that request.')
1062
1350
  } else if (!isSessionViewer(client, sessionId)) {
1063
1351
  return notFound('NOT_FOUND', 'No pending permission for that request.')
@@ -1185,7 +1473,7 @@ async function handleAddMcpServer(ws, client, msg, ctx) {
1185
1473
  }
1186
1474
 
1187
1475
  try {
1188
- const result = await entry.session.addMcpServer(name, msg.config, scope)
1476
+ const result = await entry.session.addMcpServer(name, msg.config, scope, { isAuthorized: authorizedFor(ctx, client) })
1189
1477
  if (!result || result.ok !== true) {
1190
1478
  // #7001: a denied spawn-trust prompt is a distinct outcome from a failure —
1191
1479
  // nothing was written, and the client should say "you declined" rather than
@@ -16,11 +16,12 @@ import {
16
16
  loadActiveSkillsLayered,
17
17
  findRepoSkillsDir,
18
18
  findSkillForRetrust,
19
- DEFAULT_SKILLS_DIR,
19
+ defaultSkillsDir,
20
20
  _isCommunityNamespace,
21
21
  } from '../skills-loader.js'
22
22
  import { realpathSync, readdirSync, statSync } from 'fs'
23
23
  import { loggerForSession } from '../logger.js'
24
+ import { isBoundClient } from '../environments/authority.js'
24
25
 
25
26
  // #3250: strict ISO-8601 datetime gate matching the shape z.string().datetime()
26
27
  // accepts. Used by handleListSkills to drop malformed timestamps from a
@@ -76,6 +77,14 @@ function rejectSkillTrustIfBound(ws, client, msg, ctx) {
76
77
  function handleListSkills(ws, client, msg, ctx) {
77
78
  const entry = resolveSession(ctx, msg, client)
78
79
 
80
+ // A session-scoped connection is shown its own session's skills or nothing:
81
+ // with no resolved session the listing below would fall back to the host's
82
+ // whole catalog.
83
+ if (isBoundClient(client) && !entry) {
84
+ ctx.transport.send(ws, { type: 'skills_list', skills: [] })
85
+ return
86
+ }
87
+
79
88
  // #3209: emit the full activation context so the dashboard can
80
89
  // render manual-skill toggles. For a bound session, run a fresh
81
90
  // layered scan with `includeInactive: true` against that session's
@@ -94,7 +103,7 @@ function handleListSkills(ws, client, msg, ctx) {
94
103
  // override per-session). Fall back to the defaults / cwd-walk only
95
104
  // when the session doesn't expose these — typically because no
96
105
  // session is bound (the no-session path scans the global tier).
97
- const sessionSkillsDir = entry?.session?._skillsDir || DEFAULT_SKILLS_DIR
106
+ const sessionSkillsDir = entry?.session?._skillsDir || defaultSkillsDir()
98
107
  const sessionRepoDir = entry?.session
99
108
  ? (entry.session._repoSkillsDir !== undefined
100
109
  ? entry.session._repoSkillsDir
@@ -358,7 +367,7 @@ function handleSkillTrustAccept(ws, client, msg, ctx) {
358
367
  resolvedBody = loaded.body
359
368
  } else {
360
369
  // Block-mode recovery path: scan the session's skill dirs directly.
361
- const sessionGlobalDir = entry?.session?._skillsDir || DEFAULT_SKILLS_DIR
370
+ const sessionGlobalDir = entry?.session?._skillsDir || defaultSkillsDir()
362
371
  const sessionRepoDir = entry?.session?._repoSkillsDir !== undefined
363
372
  ? entry.session._repoSkillsDir
364
373
  : (entry?.session?.cwd ? findRepoSkillsDir(entry.session.cwd) : null)
@@ -543,7 +552,7 @@ function handleSkillTrustGrant(ws, client, msg, ctx) {
543
552
 
544
553
  // Resolve the skill path. Community skills are absent from _getSkills()
545
554
  // while pending trust, so we scan the community dirs directly.
546
- const sessionGlobalDir = entry?.session?._skillsDir || DEFAULT_SKILLS_DIR
555
+ const sessionGlobalDir = entry?.session?._skillsDir || defaultSkillsDir()
547
556
  const sessionRepoDir = entry?.session?._repoSkillsDir !== undefined
548
557
  ? entry.session._repoSkillsDir
549
558
  : (entry?.session?.cwd ? findRepoSkillsDir(entry.session.cwd) : null)