@chroxy/server 0.11.0 → 0.11.11

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 (386) hide show
  1. package/CONFIG.md +206 -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 +958 -0
  12. package/src/activity-registry.js +110 -5
  13. package/src/agent-connections.js +304 -0
  14. package/src/agent-control/client.js +1645 -0
  15. package/src/agent-control/events.js +551 -0
  16. package/src/agent-control/local-connection.js +293 -0
  17. package/src/agent-control/mcp-server.js +547 -0
  18. package/src/anthropic-compatible-config.js +30 -4
  19. package/src/anthropic-compatible-session.js +15 -6
  20. package/src/anthropic-gemini-shim.js +444 -0
  21. package/src/anthropic-gemini-translate.js +1030 -0
  22. package/src/anthropic-openai-shim.js +0 -1
  23. package/src/archive-continuation.js +164 -0
  24. package/src/assistant-response.js +24 -0
  25. package/src/auth-probes.js +120 -13
  26. package/src/background-shell-tracker.js +27 -0
  27. package/src/base-session.js +1520 -36
  28. package/src/bearer-recheck.js +49 -0
  29. package/src/billing-budget.js +19 -0
  30. package/src/billing-class.js +40 -7
  31. package/src/binary-provenance-trust.js +11 -5
  32. package/src/bound-client-policy.js +291 -0
  33. package/src/built-in-tools/bash-exec.js +46 -7
  34. package/src/built-in-tools/file-ops.js +69 -5
  35. package/src/built-in-tools/tool-transforms.js +1113 -13
  36. package/src/byok-compose-state.js +6 -9
  37. package/src/byok-credentials.js +2 -3
  38. package/src/byok-mcp-client.js +92 -7
  39. package/src/byok-mcp-config.js +633 -122
  40. package/src/byok-mcp-fleet.js +49 -7
  41. package/src/byok-mcp-oauth-store.js +18 -16
  42. package/src/byok-mcp-trust.js +37 -23
  43. package/src/byok-session.js +707 -179
  44. package/src/byok-tool-executor.js +2742 -26
  45. package/src/byok-tools.js +9 -2
  46. package/src/channels/chroxy-channel-server.js +2 -3
  47. package/src/checkpoint-manager.js +64 -46
  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-setting-sources.js +74 -0
  53. package/src/claude-stream-parser.js +53 -3
  54. package/src/claude-tui/diagnostic-tail.js +83 -0
  55. package/src/claude-tui/form-driver.js +44 -7
  56. package/src/claude-tui/model-error.js +41 -0
  57. package/src/claude-tui/pty-driver.js +215 -88
  58. package/src/claude-tui/sanitize-question-payload.js +109 -0
  59. package/src/claude-tui/usage-limit.js +239 -0
  60. package/src/claude-tui-session.js +3563 -284
  61. package/src/claude-tui-tool-response.js +300 -0
  62. package/src/cli/agent-cmd.js +236 -0
  63. package/src/cli/agent-control-cmd.js +65 -0
  64. package/src/cli/config-cmd.js +4 -4
  65. package/src/cli/config-dir-cmd.js +234 -0
  66. package/src/cli/connection-state.js +54 -0
  67. package/src/cli/deploy-cmd.js +45 -10
  68. package/src/cli/doctor-cmd.js +7 -3
  69. package/src/cli/freshness-cmd.js +53 -0
  70. package/src/cli/init-cmd.js +15 -16
  71. package/src/cli/pages-cmd.js +6 -4
  72. package/src/cli/pair-code-cmd.js +7 -6
  73. package/src/cli/pair-discord-cmd.js +7 -6
  74. package/src/cli/providers-cmd.js +3 -3
  75. package/src/cli/schedule-cmd.js +91 -40
  76. package/src/cli/server-cmd.js +54 -1
  77. package/src/cli/service-cmd.js +33 -10
  78. package/src/cli/session-cmd.js +227 -74
  79. package/src/cli/shared.js +162 -11
  80. package/src/cli/shell-cmd.js +7 -4
  81. package/src/cli/status-cmd.js +19 -5
  82. package/src/cli/tokens-cmd.js +4 -5
  83. package/src/cli/tunnel-cmd.js +255 -24
  84. package/src/cli/worktree-gc-cmd.js +2 -2
  85. package/src/cli-session.js +1250 -126
  86. package/src/cli.js +8 -0
  87. package/src/codex-app-server-client.js +36 -3
  88. package/src/codex-app-server-session.js +1517 -81
  89. package/src/codex-bundled-client.js +66 -0
  90. package/src/codex-error-text.js +114 -0
  91. package/src/codex-model-catalog.js +548 -0
  92. package/src/codex-model-rejections.js +87 -0
  93. package/src/codex-native-resume.js +104 -0
  94. package/src/codex-protocol-capabilities.js +188 -0
  95. package/src/codex-session.js +450 -27
  96. package/src/config-dir-migration.js +449 -0
  97. package/src/config-dir.js +108 -0
  98. package/src/config.js +306 -26
  99. package/src/connection-authority.js +48 -0
  100. package/src/connection-info.js +78 -23
  101. package/src/connection-locality.js +60 -0
  102. package/src/container-liveness-monitor.js +189 -0
  103. package/src/continuation-metadata-worker.js +17 -0
  104. package/src/continuations.js +227 -0
  105. package/src/control-room/host-prune.js +5 -0
  106. package/src/control-room/integrations.js +7 -20
  107. package/src/control-room/skills-inventory.js +2 -2
  108. package/src/conversation-scanner.js +42 -39
  109. package/src/conversation-scope.js +59 -39
  110. package/src/conversation-search.js +28 -39
  111. package/src/credential-store.js +23 -19
  112. package/src/daemon-commit.js +92 -0
  113. package/src/daemon-idle-state.js +171 -0
  114. package/src/daemon-update-status.js +314 -0
  115. package/src/dashboard-build.js +70 -0
  116. package/src/declared-status.js +90 -0
  117. package/src/deepseek-credentials.js +2 -3
  118. package/src/dev-preview.js +170 -182
  119. package/src/device-preferences.js +2 -2
  120. package/src/diff-parser.js +87 -0
  121. package/src/discord-credentials.js +2 -3
  122. package/src/docker-byok-pool.js +3 -1
  123. package/src/docker-byok-session.js +678 -78
  124. package/src/docker-image-allowlist.js +23 -1
  125. package/src/docker-sdk-session.js +172 -3
  126. package/src/docker-session.js +294 -11
  127. package/src/doctor.js +781 -64
  128. package/src/durable-write.js +35 -0
  129. package/src/edited-input.js +264 -0
  130. package/src/environment-manager.js +175 -36
  131. package/src/environments/authority.js +101 -0
  132. package/src/environments/backends/container-claude-spawn.js +94 -0
  133. package/src/environments/backends/docker.js +31 -10
  134. package/src/environments/backends/k8s.js +49 -24
  135. package/src/environments/destroy-with-sessions.js +142 -0
  136. package/src/event-ingest.js +118 -13
  137. package/src/event-normalizer.js +186 -235
  138. package/src/folder-trust-wire.js +137 -0
  139. package/src/folder-trust-worker.js +17 -0
  140. package/src/folder-trust.js +1572 -0
  141. package/src/freshness/activity-meter.js +101 -0
  142. package/src/freshness/adapter.js +199 -0
  143. package/src/freshness/checks.js +239 -0
  144. package/src/freshness/config.js +98 -0
  145. package/src/freshness/core.js +185 -0
  146. package/src/freshness/derive.js +680 -0
  147. package/src/freshness/exchange.js +305 -0
  148. package/src/freshness/file-ledger.js +400 -0
  149. package/src/freshness/grade.js +81 -0
  150. package/src/freshness/hash.js +45 -0
  151. package/src/freshness/inbox.js +163 -0
  152. package/src/freshness/index.js +20 -0
  153. package/src/freshness/investigation.js +474 -0
  154. package/src/freshness/keys.js +177 -0
  155. package/src/freshness/ledger.js +122 -0
  156. package/src/freshness/outbox.js +131 -0
  157. package/src/freshness/policy.js +599 -0
  158. package/src/freshness/queue.js +843 -0
  159. package/src/freshness/read-errors.js +23 -0
  160. package/src/freshness/render.js +153 -0
  161. package/src/freshness/runtime.js +113 -0
  162. package/src/freshness/session-registry-adapter.js +161 -0
  163. package/src/freshness/state-file-adapter.js +167 -0
  164. package/src/freshness-runner/build-info.js +139 -0
  165. package/src/freshness-runner/cli.js +105 -0
  166. package/src/freshness-runner/run-tick.js +109 -0
  167. package/src/freshness-runner/stamp.js +57 -0
  168. package/src/freshness-sources/claude-transcript-adapter.js +211 -0
  169. package/src/freshness-sources/codex-transcript-adapter.js +33 -0
  170. package/src/freshness-sources/index.js +8 -0
  171. package/src/gemini-byok-session.js +292 -0
  172. package/src/gemini-credentials.js +67 -0
  173. package/src/gemini-key-safety.js +246 -0
  174. package/src/gemini-models.js +386 -0
  175. package/src/gemini-session.js +81 -5
  176. package/src/handler-utils.js +540 -80
  177. package/src/handlers/checkpoint-handlers.js +47 -4
  178. package/src/handlers/control-room-handlers.js +51 -11
  179. package/src/handlers/conversation-handlers.js +469 -56
  180. package/src/handlers/daemon-update-handlers.js +81 -0
  181. package/src/handlers/evaluator-handlers.js +14 -1
  182. package/src/handlers/feature-handlers.js +186 -69
  183. package/src/handlers/file-handlers.js +57 -13
  184. package/src/handlers/folder-trust-handlers.js +90 -0
  185. package/src/handlers/input-handlers.js +714 -48
  186. package/src/handlers/orchestration-handlers.js +3 -3
  187. package/src/handlers/principal-admin-handlers.js +229 -0
  188. package/src/handlers/principal-handlers.js +262 -0
  189. package/src/handlers/scheduler-handlers.js +92 -18
  190. package/src/handlers/session-handlers.js +551 -20
  191. package/src/handlers/session-pr-status-handlers.js +283 -0
  192. package/src/handlers/session-pr-threads-handlers.js +247 -0
  193. package/src/handlers/settings-handlers.js +372 -50
  194. package/src/handlers/skills-handlers.js +20 -4
  195. package/src/handlers/summarize-handlers.js +32 -1
  196. package/src/handlers/survey-throttle.js +380 -0
  197. package/src/health-proof.js +40 -0
  198. package/src/history-page.js +112 -0
  199. package/src/http-routes.js +127 -8
  200. package/src/ide/search.js +24 -6
  201. package/src/ide/symbols.js +20 -6
  202. package/src/input-context.js +117 -0
  203. package/src/instruction-policy-compiler.js +229 -0
  204. package/src/instruction-policy.js +250 -0
  205. package/src/jsonl-reader.js +378 -91
  206. package/src/jsonl-subprocess-session.js +96 -9
  207. package/src/keychain.js +1 -1
  208. package/src/logger.js +166 -30
  209. package/src/mailbox-route.js +113 -22
  210. package/src/message-wire.js +386 -0
  211. package/src/model-discovery.js +43 -3
  212. package/src/models.js +1276 -174
  213. package/src/notification-prefs.js +27 -4
  214. package/src/notifications/discord-billing-sink.js +22 -5
  215. package/src/notifications/discord-ci-sink.js +243 -0
  216. package/src/notifications/discord-webhook-client.js +71 -0
  217. package/src/notifications/discord-webhook-sink.js +64 -23
  218. package/src/notifications/expo-push-sink.js +85 -6
  219. package/src/notifications/ready-body.js +16 -5
  220. package/src/ollama-session.js +34 -2
  221. package/src/orchestration/build-manager.js +9 -2
  222. package/src/orchestration/git-ops.js +41 -7
  223. package/src/orchestration/orchestration-manager.js +112 -36
  224. package/src/orchestration/permission-gate.js +17 -2
  225. package/src/orchestration/run-model.js +2 -1
  226. package/src/orchestration/run-record.js +11 -0
  227. package/src/orchestration/turn-driver.js +185 -43
  228. package/src/orphan-reaper.js +470 -0
  229. package/src/outgoing-policy.js +189 -0
  230. package/src/pairing.js +92 -13
  231. package/src/path-hash-trust-ledger.js +642 -25
  232. package/src/permission-deadlines.js +82 -0
  233. package/src/permission-floor.js +1410 -43
  234. package/src/permission-hook.js +180 -69
  235. package/src/permission-manager.js +737 -89
  236. package/src/permission-mode-support.js +35 -0
  237. package/src/permission-resolved-by.js +89 -0
  238. package/src/permission-resolver.js +126 -8
  239. package/src/permission-scope.js +43 -0
  240. package/src/platform.js +315 -47
  241. package/src/preview-ingress.js +54 -0
  242. package/src/preview-target.js +213 -0
  243. package/src/principal-audit.js +189 -0
  244. package/src/principal-binding.js +25 -0
  245. package/src/principal-brakes.js +21 -0
  246. package/src/principal-effect.js +101 -0
  247. package/src/principal-journal.js +905 -0
  248. package/src/principal-kill-switch.js +183 -0
  249. package/src/principal-label.js +5 -0
  250. package/src/principal-pending-permissions.js +177 -0
  251. package/src/principal-policy.js +1094 -0
  252. package/src/principal-sessions-snapshot.js +208 -0
  253. package/src/principal-store.js +488 -0
  254. package/src/principal-subscriptions.js +283 -0
  255. package/src/prompt-evaluator.js +34 -4
  256. package/src/provider-customization.js +180 -0
  257. package/src/providers.js +209 -4
  258. package/src/push.js +30 -4
  259. package/src/question-route-map.js +130 -0
  260. package/src/redaction.js +531 -20
  261. package/src/roster-broadcast.js +186 -0
  262. package/src/scheduled-task-store.js +330 -26
  263. package/src/scheduler.js +368 -11
  264. package/src/sdk-session.js +2114 -188
  265. package/src/server-cli/preview-shutdown.js +22 -0
  266. package/src/server-cli/push-notification-handler.js +17 -3
  267. package/src/server-cli/server-orchestrator.js +28 -5
  268. package/src/server-cli-child.js +33 -18
  269. package/src/server-cli.js +553 -38
  270. package/src/server-identity.js +15 -11
  271. package/src/service.js +396 -25
  272. package/src/session-archive-limits.js +15 -0
  273. package/src/session-archive.js +1029 -0
  274. package/src/session-busy-state.js +72 -0
  275. package/src/session-ci-watcher.js +1099 -0
  276. package/src/session-context.js +7 -2
  277. package/src/session-manager.js +4062 -312
  278. package/src/session-message-history.js +841 -16
  279. package/src/session-name-allocator.js +685 -0
  280. package/src/session-pr-status.js +654 -0
  281. package/src/session-pr-threads.js +271 -0
  282. package/src/session-preset-trust.js +3 -3
  283. package/src/session-preset.js +10 -5
  284. package/src/session-state-persistence.js +94 -17
  285. package/src/session-timeout-manager.js +20 -0
  286. package/src/session-token-store.js +17 -8
  287. package/src/session-wake.js +240 -0
  288. package/src/shell-approval-info.js +2 -2
  289. package/src/shell-approval-store.js +3 -1
  290. package/src/skills-loader.js +7 -4
  291. package/src/skills-manager.js +2 -2
  292. package/src/skills-trust.js +95 -13
  293. package/src/skills-usage.js +2 -3
  294. package/src/snapshots-store.js +2 -3
  295. package/src/statusline.js +100 -29
  296. package/src/summarize-session.js +53 -4
  297. package/src/supervisor.js +22 -11
  298. package/src/sweep-stale-provider-dirs.js +95 -0
  299. package/src/thinking-level-wire.js +39 -0
  300. package/src/thinking-stream.js +179 -0
  301. package/src/tool-result.js +61 -0
  302. package/src/transcript-sources.js +109 -0
  303. package/src/transcript-tasks.js +372 -25
  304. package/src/trusted-file-read.js +302 -0
  305. package/src/tunnel/base.js +0 -8
  306. package/src/tunnel/cloudflare.js +34 -31
  307. package/src/tunnel/index.js +9 -0
  308. package/src/tunnel/preview.js +64 -0
  309. package/src/turn-outcome.js +140 -0
  310. package/src/usage-normalize.js +9 -5
  311. package/src/user-shell-session.js +59 -5
  312. package/src/utils/agent-sdk-version.js +107 -0
  313. package/src/utils/argv-safety.js +770 -0
  314. package/src/utils/auth-cause.js +60 -0
  315. package/src/utils/binary-package-manifest.js +639 -0
  316. package/src/utils/binary-version.js +224 -0
  317. package/src/utils/bounded-regex-worker.js +29 -0
  318. package/src/utils/bounded-regex.js +162 -0
  319. package/src/utils/claude-binary.js +43 -0
  320. package/src/utils/claude-config-dir.js +245 -0
  321. package/src/utils/claude-login-command.js +16 -0
  322. package/src/utils/claude-native-route.js +81 -0
  323. package/src/utils/componentwise-resolver.js +133 -37
  324. package/src/utils/deploy-control-files.js +87 -0
  325. package/src/utils/exec-failure-reason.js +21 -0
  326. package/src/utils/git-repo.js +42 -0
  327. package/src/utils/is-entry-point.js +137 -0
  328. package/src/utils/node-pty-probe.js +95 -0
  329. package/src/utils/node-pty-support.js +118 -0
  330. package/src/utils/opened-file-path.js +167 -0
  331. package/src/utils/path-containment.js +165 -0
  332. package/src/utils/permission-mode-sidecar.js +51 -0
  333. package/src/utils/pid-liveness.js +47 -0
  334. package/src/utils/preflight.js +360 -16
  335. package/src/utils/read-limiter.js +217 -0
  336. package/src/utils/regular-file.js +375 -0
  337. package/src/utils/safe-regex.js +113 -0
  338. package/src/utils/small-file.js +129 -0
  339. package/src/utils/spawn-env.js +189 -4
  340. package/src/utils/stale-session-dirs.js +182 -0
  341. package/src/utils/stat-identity.js +43 -0
  342. package/src/utils/verify-provenance.js +406 -13
  343. package/src/web-task-manager.js +297 -16
  344. package/src/worktree-gc.js +202 -6
  345. package/src/ws-auth.js +163 -31
  346. package/src/ws-broadcaster.js +49 -5
  347. package/src/ws-client-manager.js +24 -1
  348. package/src/ws-client-sender.js +7 -0
  349. package/src/ws-file-ops/browser.js +363 -58
  350. package/src/ws-file-ops/common.js +320 -14
  351. package/src/ws-file-ops/git.js +395 -42
  352. package/src/ws-file-ops/index.js +2 -0
  353. package/src/ws-file-ops/memory.js +137 -35
  354. package/src/ws-file-ops/open-nofollow.js +354 -0
  355. package/src/ws-file-ops/reader.js +571 -113
  356. package/src/ws-forwarding.js +349 -39
  357. package/src/ws-handler-context.js +88 -2
  358. package/src/ws-history.js +1010 -175
  359. package/src/ws-message-handlers.js +25 -1
  360. package/src/ws-permissions.js +307 -37
  361. package/src/ws-schemas.js +5 -0
  362. package/src/ws-server.js +885 -98
  363. package/sidecar/node_modules/.package-lock.json +0 -29
  364. package/sidecar/node_modules/ws/LICENSE +0 -20
  365. package/sidecar/node_modules/ws/README.md +0 -548
  366. package/sidecar/node_modules/ws/browser.js +0 -8
  367. package/sidecar/node_modules/ws/index.js +0 -22
  368. package/sidecar/node_modules/ws/lib/buffer-util.js +0 -131
  369. package/sidecar/node_modules/ws/lib/constants.js +0 -19
  370. package/sidecar/node_modules/ws/lib/event-target.js +0 -292
  371. package/sidecar/node_modules/ws/lib/extension.js +0 -203
  372. package/sidecar/node_modules/ws/lib/limiter.js +0 -55
  373. package/sidecar/node_modules/ws/lib/permessage-deflate.js +0 -528
  374. package/sidecar/node_modules/ws/lib/receiver.js +0 -706
  375. package/sidecar/node_modules/ws/lib/sender.js +0 -602
  376. package/sidecar/node_modules/ws/lib/stream.js +0 -161
  377. package/sidecar/node_modules/ws/lib/subprotocol.js +0 -62
  378. package/sidecar/node_modules/ws/lib/validation.js +0 -152
  379. package/sidecar/node_modules/ws/lib/websocket-server.js +0 -554
  380. package/sidecar/node_modules/ws/lib/websocket.js +0 -1393
  381. package/sidecar/node_modules/ws/package.json +0 -70
  382. package/sidecar/node_modules/ws/wrapper.mjs +0 -21
  383. package/src/dashboard-next/dist/assets/index-C2ipeGlq.js +0 -111
  384. package/src/dashboard-next/dist/assets/index-DM-_dISG.css +0 -1
  385. package/src/dashboard-next/dist/index.html +0 -13
  386. package/src/dashboard-next/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
@@ -1,9 +1,12 @@
1
+ import { assistantResponseText } from './assistant-response.js'
1
2
  import { JsonlSubprocessSession } from './jsonl-subprocess-session.js'
3
+ import { CODEX_EXEC_CUSTOMIZATION } from './provider-customization.js'
2
4
  import { buildBaseSessionOpts } from './base-session.js'
3
5
  import { homedir } from 'os'
4
6
  import { join } from 'path'
5
7
  import { resolveBinary } from './utils/resolve-binary.js'
6
8
  import { buildSpawnEnv } from './utils/spawn-env.js'
9
+ import { assertSafeArgvValue } from './utils/argv-safety.js'
7
10
  import {
8
11
  CONTEXT_WINDOW_HEADROOM,
9
12
  getRatchetCap,
@@ -12,6 +15,13 @@ import {
12
15
  import { nonNegInt } from './usage-normalize.js'
13
16
  import { BILLING_CLASSES } from './billing-class.js'
14
17
  import { hasCodexOAuthCreds } from './auth-probes.js'
18
+ import { getRegistryForProvider } from './models.js'
19
+ import {
20
+ getCodexCatalogRow,
21
+ getCodexCatalogRows,
22
+ hasCodexCatalog,
23
+ refreshCodexModels,
24
+ } from './codex-model-catalog.js'
15
25
  import {
16
26
  CODEX_SANDBOX_MODES as PROTOCOL_CODEX_SANDBOX_MODES,
17
27
  CODEX_DEFAULT_SANDBOX as PROTOCOL_CODEX_DEFAULT_SANDBOX,
@@ -153,6 +163,51 @@ export function resolveCodexSandbox(override) {
153
163
  return CODEX_DEFAULT_SANDBOX
154
164
  }
155
165
 
166
+ /**
167
+ * Serialize a string as a TOML **basic string** for a `codex exec -c key=<v>`
168
+ * override. Exported for unit testing.
169
+ *
170
+ * Why this exists (#7766): before #7727 the `model` id reaching
171
+ * `buildCodexArgs` was always one of six compiled-in literals, so raw
172
+ * interpolation into `model="${id}"` was safe by construction. Tri-state
173
+ * validation removed that construction — on the unrestricted branch the id is
174
+ * an arbitrary operator-supplied string — and argv-shape safety (one element,
175
+ * no shell) does NOT extend to the TOML grammar codex parses that element
176
+ * under. That is the "validated value handed on to something that parses it
177
+ * under a different grammar" entry in `docs/false-safety-guards.md`.
178
+ *
179
+ * JSON's string escaping is a SUBSET of TOML 1.0's basic-string escaping with
180
+ * exactly two known exceptions, both listed below: `JSON.stringify` escapes
181
+ * `"` and the backslash, emits the short forms `\\b \\f \\n \\r \\t` that TOML
182
+ * also defines, and `\\uXXXX` for every other control character — all of which
183
+ * TOML accepts. Everything else passes through unchanged, which is why an
184
+ * ordinary id still round-trips to the byte-identical `model="gpt-5-codex"`
185
+ * this produced before.
186
+ *
187
+ * Exception 1 — DEL (U+007F). The one character TOML forbids raw in a basic
188
+ * string but JSON leaves alone, so it is escaped afterwards by the `.replace`
189
+ * below.
190
+ *
191
+ * Exception 2 — a LONE SURROGATE, and it is NOT fixed here. ES2019
192
+ * well-formed `JSON.stringify` emits `\\udXXX` for an unpaired surrogate
193
+ * (`toTomlBasicString('a\\uD800b')` → `"a\\ud800b"`), but TOML's `\\uXXXX`
194
+ * must name a Unicode SCALAR value and a surrogate is not one, so that output
195
+ * is invalid TOML. Reachable post-#7727: on the unrestricted branch
196
+ * `handleSetModel` only trims and checks non-empty, so a client can send
197
+ * `{"model":"\\ud800"}`. The outcome is a CLOSED failure — codex's own TOML
198
+ * parser rejects the `-c` override and the turn errors out; the value is still
199
+ * one argv element, there is no shell, and no second `-c` appears, so nothing
200
+ * escapes into the grammar. It is deliberately NOT stripped or replaced: the
201
+ * contract these tests pin is escaped-not-sanitised, and silently rewriting an
202
+ * id would mangle a value the operator supplied rather than surface a bad one.
203
+ *
204
+ * @param {string} value
205
+ * @returns {string} a quoted, escaped TOML basic string
206
+ */
207
+ export function toTomlBasicString(value) {
208
+ return JSON.stringify(String(value)).replace(/\u007f/g, '\\u007F')
209
+ }
210
+
156
211
  /**
157
212
  * Build the argv passed to `codex exec`. Exported for unit testing.
158
213
  *
@@ -184,12 +239,38 @@ export function resolveCodexSandbox(override) {
184
239
  * interpolated into argv passed directly to `spawn()` — no shell, so shell
185
240
  * metacharacters can't escape.
186
241
  *
187
- * - `model` is interpolated into `-c model="${model}"` *without* re-validation
188
- * here. **Callers MUST pre-validate the model ID against
189
- * `CodexSession.getAllowedModels()` before calling.** The production gate is
190
- * `handleSetModel` in `handlers/settings-handlers.js`, which rejects any
191
- * value not in the per-provider allowlist before `session.setModel()`
192
- * writes to `this.model`.
242
+ * - `model` is serialized into `-c model=<toml basic string>` *without*
243
+ * re-validation here. **The caller-side gate is TRI-STATE since #7727 and is
244
+ * NOT an allowlist in general** — `CodexSession.getAllowedModels()` returns
245
+ * the binary's own catalog ids when it has one and `null` (unrestricted)
246
+ * when it does not, so pre-#7727 statements that this argument is always one
247
+ * of six compiled-in ids are no longer true. Read that as: on the
248
+ * unrestricted branch this receives an arbitrary non-empty string the
249
+ * operator asked for (`handleSetModel` still rejects a non-string /
250
+ * whitespace-only id, and `providers.allowAnyModel` could already produce
251
+ * exactly this before #7727).
252
+ *
253
+ * TWO independent things keep that safe, and the second is new in #7766
254
+ * because the first was being asked to do work it cannot do:
255
+ *
256
+ * 1. `spawn()` without a shell, so the value is ONE argv element: no shell
257
+ * metacharacter can escape into a second process, and no second `-c`
258
+ * override can be introduced. That bounds the blast radius to "whatever
259
+ * codex's own TOML parser makes of this one element".
260
+ * 2. `toTomlBasicString()` escapes the value, so it cannot escape the TOML
261
+ * string EITHER. This prose used to stop at (1) and claim that a quote
262
+ * merely produced "invalid TOML that Codex CLI rejects" — an unverified
263
+ * claim about a third-party parser's error handling, standing in for
264
+ * escaping we were not doing (`docs/false-safety-guards.md`: a guard
265
+ * whose comment describes a stronger check than its code performs). A
266
+ * `"` plus a newline is a plausible way to close the string and open a
267
+ * second key INSIDE the same argv element, and an argv-shape assertion
268
+ * says nothing about that. Escaping removes the question rather than
269
+ * answering it.
270
+ *
271
+ * `tests/codex-session.test.js` executes both halves against a hostile id —
272
+ * the argv shape, the escaping, and the absence of a `shell` option on the
273
+ * spawn path — so neither claim survives only in prose (#7646).
193
274
  *
194
275
  * - `threadId` (#3865) is **trusted because it comes from Codex CLI's own
195
276
  * `thread.started` JSONL stdout** — captured in `_processJsonlLine`, never
@@ -204,10 +285,12 @@ export function resolveCodexSandbox(override) {
204
285
  * alternate spawn path), preserve these invariants or add validation here.
205
286
  *
206
287
  * @param {string} text User prompt
207
- * @param {string|null} model Optional model ID. Caller must validate against
208
- * `CodexSession.getAllowedModels()`. If falsy,
209
- * no `-c model=` flag is appended — Codex CLI
210
- * uses its own default.
288
+ * @param {string|null} model Optional model ID. The caller-side gate is
289
+ * TRI-STATE since #7727, so this is NOT
290
+ * guaranteed to come from an allowlist — see the
291
+ * SECURITY INVARIANT above for what does hold. If
292
+ * falsy, no `-c model=` flag is appended — Codex
293
+ * CLI uses its own default.
211
294
  * @param {string|null} threadId Optional Codex thread_id captured from a
212
295
  * previous turn's `thread.started` event.
213
296
  * When set, switches to `exec resume <id>`
@@ -219,26 +302,80 @@ export function resolveCodexSandbox(override) {
219
302
  * @returns {string[]}
220
303
  */
221
304
  export function buildCodexArgs(text, model, threadId = null, sandboxOverride = undefined) {
222
- // INVARIANT: --sandbox must be passed to the parent `exec`, not to the
305
+ // INVARIANT 1: --sandbox must be passed to the parent `exec`, not to the
223
306
  // `resume` subcommand. `codex exec resume --sandbox ...` errors out with
224
307
  // `unexpected argument '--sandbox' found` (verified against codex-cli
225
- // 0.128.0) because --sandbox is only declared on the parent `exec` command.
226
- // Keep --sandbox BEFORE the `resume` subcommand on the resume path.
308
+ // 0.128.0, still true on 0.154.0) because --sandbox is only declared on the
309
+ // parent `exec` command. Keep --sandbox BEFORE the `resume` subcommand.
310
+ //
311
+ // INVARIANT 2 (#7342/#7291): `text` is TERMINATED, never bare. It is the raw
312
+ // client chat message, and it used to sit in a bare positional slot on both
313
+ // branches, where codex option-PARSED it. Measured on codex-cli 0.154.0:
314
+ //
315
+ // codex exec "- first bullet" --json …
316
+ // → error: unexpected argument '- ' found
317
+ // tip: to pass '- ' as a value, use '-- - ' (exit 2)
318
+ // codex exec --sandbox read-only resume <id> "--thread-source=x" --json …
319
+ // → consumed as an OPTION; the prompt slot falls empty and codex drops
320
+ // to "Reading prompt from stdin..." (exit 1)
321
+ //
322
+ // `resume` also declares --dangerously-bypass-approvals-and-sandbox, so the
323
+ // second shape was a sandbox-escape primitive and not merely a parse bug. A
324
+ // leading dash is LEGITIMATE input ("- first bullet"), so the fix is the `--`
325
+ // terminator (utils/argv-safety.js case 2), not rejection.
326
+ //
327
+ // Everything after `--` is POSITIONAL, which is why every flag — and the
328
+ // resume SESSION_ID, itself a positional — is emitted BEFORE it, and why
329
+ // `text` must stay the LAST element. Appending a flag after it would silently
330
+ // turn that flag into part of the prompt.
331
+ //
332
+ // #7868 — unlike `text`, `threadId` can never LEGITIMATELY start with `-`:
333
+ // it is chroxy's own identifier (a codex `thread_id`, or a client-supplied
334
+ // resume target already required to be a canonical UUID at the WS layer —
335
+ // see handlers/conversation-handlers.js's CONVERSATION_ID_RE), never free-
336
+ // form chat text. So the correct shape here is case 1 (reject), not a `--`
337
+ // terminator — which would not even help, since the SESSION_ID positional
338
+ // must stay BEFORE the separator (INVARIANT above). Before this, nothing in
339
+ // buildCodexArgs itself constrained threadId's shape: safety depended
340
+ // entirely on every external producer already happening to constrain it,
341
+ // which is the exact "someone remembers to sweep" pattern this issue's own
342
+ // lint exists to close. `resume` declares
343
+ // --dangerously-bypass-approvals-and-sandbox, so a producer that ever
344
+ // relaxed that external constraint would have reopened a sandbox-escape
345
+ // primitive, not just a parse nuisance.
346
+ if (threadId) assertSafeArgvValue(threadId, 'threadId')
227
347
  const sandbox = resolveCodexSandbox(sandboxOverride)
228
348
  const args = threadId
229
- ? ['exec', '--sandbox', sandbox, 'resume', threadId, text, '--json', '--skip-git-repo-check']
230
- : ['exec', text, '--json', '--skip-git-repo-check', '--sandbox', sandbox]
349
+ ? ['exec', '--sandbox', sandbox, 'resume', '--json', '--skip-git-repo-check']
350
+ : ['exec', '--json', '--skip-git-repo-check', '--sandbox', sandbox]
231
351
  if (model) {
232
- args.push('-c', `model="${model}"`)
352
+ // #7766 — SERIALIZED, not interpolated. See the SECURITY INVARIANT above.
353
+ args.push('-c', `model=${toTomlBasicString(model)}`)
233
354
  }
355
+ // Positionals, in order: [SESSION_ID] on the resume form, then the prompt
356
+ // behind the terminator.
357
+ if (threadId) args.push(threadId)
358
+ args.push('--', text)
234
359
  return args
235
360
  }
236
361
 
237
362
  // Per-provider model metadata — #2956.
238
- // Source of truth for `set_model` validation, fallback model list, and
239
- // per-model context window/label surfaced in the dashboard dropdown. Keep
240
- // this list small and explicit until Codex CLI grows a native
241
- // `supportedModels()` equivalent.
363
+ //
364
+ // #7726 DEMOTED this from "the roster" to a CATALOGUED label/window SEED. The
365
+ // binary answers `model/list` with its own roster (codex-model-catalog.js), and
366
+ // once that catalog is in hand it REPLACES this list in getFallbackModels() —
367
+ // a union would mean a retired model never dies. These six remain as the
368
+ // cold-boot seed (before any probe has resolved) and as the label/window
369
+ // lookup for an id the catalog does not carry; every row they produce is
370
+ // stamped `provenance: 'catalogued'` so a hand-maintained row is LABELLED as
371
+ // hand-maintained instead of masquerading as provider truth (the #7348 class).
372
+ //
373
+ // #7727 finished the demotion: this table is NO LONGER a validation roster at
374
+ // all. It is consumed by exactly two things — `CODEX_FALLBACK_MODELS` (the
375
+ // cold-boot picker) and `getModelMetadata`'s label/window LOOKUP for a still-
376
+ // known id. `getAllowedModels()` reads the catalog and nothing else; there is
377
+ // deliberately no `CODEX_ALLOWED_MODELS` constant here for a future edit to
378
+ // reach for.
242
379
  //
243
380
  // Context-window values come from the OpenAI model docs; `contextWindow` is
244
381
  // used both in the token-usage HUD and as the Codex-side override for the
@@ -263,18 +400,93 @@ const CODEX_MODEL_METADATA = Object.freeze({
263
400
  'o3': { label: 'o3', contextWindow: 200_000 },
264
401
  })
265
402
 
266
- const CODEX_ALLOWED_MODELS = Object.freeze(Object.keys(CODEX_MODEL_METADATA))
403
+ /**
404
+ * #7731 (GUARD-1) — the ids of `CODEX_MODEL_METADATA` that the shipped binary
405
+ * NO LONGER OFFERS, declared rather than inferred.
406
+ *
407
+ * The seed above is a hand-maintained list sitting beside a set that moves with
408
+ * OpenAI's releases, which is this repo's #1 recurring defect shape. #7726
409
+ * removed its authority (the binary's `model/list` is the roster) but left it
410
+ * free to ROT: a row nothing serves any more keeps its label/window lookup and
411
+ * keeps seeding the cold-boot picker, and nothing goes red.
412
+ *
413
+ * This roster is what the parity guard (`tests/model-catalog-parity.test.js`)
414
+ * measures the seed against: every seed id must be either present in the
415
+ * producer's own catalog or named HERE, and every id named here must still be
416
+ * in the seed. A retired model therefore has to be declared in a diff instead
417
+ * of lingering, and a stale declaration cannot outlive the row it describes.
418
+ *
419
+ * All six are listed today because none of them is in the roster codex-cli
420
+ * 0.154.0 serves (`gpt-6-astra, gpt-5.6-sol, gpt-5.6-terra, gpt-5.6-luna,
421
+ * gpt-5.5, gpt-5.3-codex-spark` — recorded on epic #7721, comment 5644101381,
422
+ * and restated at the top of `codex-model-catalog.js`). "Deprecated" here means
423
+ * exactly that and nothing more: not offered by the binary this repo has
424
+ * evidence for, kept as a label/window LOOKUP for a historical id. Nothing
425
+ * reads this set at runtime — it changes no roster, no validation and no wire
426
+ * field, so a row's presence here is a claim about the producer, never a
427
+ * behaviour change.
428
+ */
429
+ const CODEX_DEPRECATED_SEED_IDS = Object.freeze(new Set([
430
+ 'gpt-5-codex',
431
+ 'gpt-5',
432
+ 'gpt-4.1',
433
+ 'gpt-4o',
434
+ 'o1',
435
+ 'o3',
436
+ ]))
267
437
 
268
- const CODEX_FALLBACK_MODELS = Object.freeze(CODEX_ALLOWED_MODELS.map(id => {
438
+ // #7727 — `CODEX_ALLOWED_MODELS` is DELETED, not merely unreferenced. It was
439
+ // `Object.keys(CODEX_MODEL_METADATA)`, returned verbatim by
440
+ // `getAllowedModels()`, and it is the frozen-roster lockout this issue retires:
441
+ // every model the binary actually serves today (gpt-5.5, gpt-6-astra, …) was
442
+ // rejected by it, leaving `providers.allowAnyModel: ["codex"]` as the only way
443
+ // to run codex at all (#6378). Removing the NAME is the structural half of the
444
+ // fix — a later edit cannot `return` a constant that does not exist, and this
445
+ // file no longer holds a six-id array for one to reach for.
446
+ const CODEX_FALLBACK_MODELS = Object.freeze(Object.keys(CODEX_MODEL_METADATA).map(id => {
269
447
  const meta = CODEX_MODEL_METADATA[id]
270
448
  return Object.freeze({
271
449
  id,
272
450
  label: meta.label,
273
451
  fullId: id,
274
452
  contextWindow: meta.contextWindow,
453
+ // #7726 — hand-maintained, and says so on the wire.
454
+ provenance: 'catalogued',
275
455
  })
276
456
  }))
277
457
 
458
+ /**
459
+ * #7726 — one catalog row to the `{id,label,fullId,contextWindow,...}` entry
460
+ * shape both `getFallbackModels()` and `getModelMetadata()` hand the registry.
461
+ *
462
+ * `contextWindow` is the row's value or explicit `null` — never a fabricated
463
+ * number and never borrowed from a same-named static row. models.js preserves
464
+ * an explicit null instead of substituting DEFAULT_CONTEXT_WINDOW, so the
465
+ * dashboard omits the chip rather than showing an invented 200k (#5418/#5444).
466
+ *
467
+ * `reasoningLevels` / `defaultReasoningLevel` are OMITTED when the row has
468
+ * none, rather than emitted empty: `withModelMetadata` (models.js) skips
469
+ * undefined/null, so an absent key means "not recorded" on the wire, which is
470
+ * the contract #7723 established for these fields.
471
+ */
472
+ function catalogEntry(row) {
473
+ const entry = {
474
+ id: row.id,
475
+ label: typeof row.label === 'string' && row.label.length > 0 ? row.label : row.id,
476
+ fullId: row.id,
477
+ contextWindow: Number.isInteger(row.contextWindow) && row.contextWindow > 0 ? row.contextWindow : null,
478
+ description: typeof row.description === 'string' ? row.description : '',
479
+ provenance: typeof row.provenance === 'string' && row.provenance.length > 0 ? row.provenance : 'discovered',
480
+ }
481
+ if (Array.isArray(row.reasoningLevels) && row.reasoningLevels.length > 0) {
482
+ entry.reasoningLevels = row.reasoningLevels
483
+ }
484
+ if (typeof row.defaultReasoningLevel === 'string' && row.defaultReasoningLevel.length > 0) {
485
+ entry.defaultReasoningLevel = row.defaultReasoningLevel
486
+ }
487
+ return entry
488
+ }
489
+
278
490
  /**
279
491
  * Headroom multiplier for the learn-loop. Re-exported from the shared
280
492
  * `CONTEXT_WINDOW_HEADROOM` constant in `utils/context-window-learn.js`
@@ -317,6 +529,12 @@ export function _maybeRatchetContextWindow(session, modelId, inputTokens) {
317
529
  }
318
530
 
319
531
  export class CodexSession extends JsonlSubprocessSession {
532
+ static canonicalAssistantResponses = true
533
+
534
+ static get customizationDescriptor() {
535
+ return CODEX_EXEC_CUSTOMIZATION
536
+ }
537
+
320
538
  // ------------------------------------------------------------------
321
539
  // Static provider identity — required by JsonlSubprocessSession
322
540
  // ------------------------------------------------------------------
@@ -329,6 +547,12 @@ export class CodexSession extends JsonlSubprocessSession {
329
547
  // Re-resolve fresh on every access (NOT a frozen module-load const) so a
330
548
  // binary quarantined / moved / reinstalled after daemon start is spawned
331
549
  // from its CURRENT path — and matches what preflight verified (#6708).
550
+ //
551
+ // #8609 — CHROXY_CODEX_BIN (config `codexBinary`) names the client to
552
+ // launch. No PATH lookup: this exact path is what preflight/provenance
553
+ // verifies, so a bad path fails at preflight naming it. Read per access.
554
+ const override = typeof process.env.CHROXY_CODEX_BIN === 'string' ? process.env.CHROXY_CODEX_BIN.trim() : ''
555
+ if (override) return override
332
556
  return resolveBinary('codex', BINARY_CANDIDATES)
333
557
  }
334
558
 
@@ -379,12 +603,21 @@ export class CodexSession extends JsonlSubprocessSession {
379
603
  return {
380
604
  permissions: false,
381
605
  inProcessPermissions: false,
606
+ permissionFloor: false,
607
+ autoPermissionMode: false,
608
+ nativeSandbox: true,
382
609
  modelSwitch: true,
383
610
  permissionModeSwitch: false,
384
611
  planMode: false,
385
612
  resume: false,
386
613
  terminal: false,
387
614
  thinkingLevel: false,
615
+ // #7725: codex has its own reasoning-effort knob, but the Claude magic
616
+ // keywords mean nothing to it and the daemon never scans for them here.
617
+ // Kept SEPARATE from `thinkingLevel` precisely so #7730 can flip that one
618
+ // on without the client also promising keyword escalation.
619
+ thinkingKeywords: false,
620
+ thinkingLevelEffective: false, // #8700: no report of the applied level
388
621
  // #3932: declared explicitly so the capability matrix matches across
389
622
  // providers — claude-tui is the only one that sets this to false.
390
623
  streaming: true,
@@ -392,12 +625,60 @@ export class CodexSession extends JsonlSubprocessSession {
392
625
  }
393
626
 
394
627
  /**
395
- * Model IDs this provider accepts in `set_model`. Returns a plain array so
396
- * the settings handler can surface it to the client on rejection.
397
- * @returns {string[]}
628
+ * #7727 — TRI-STATE model validation, read by BOTH gates:
629
+ * `getProviderAllowedModels` (handlers/settings-handlers.js, the `set_model`
630
+ * path) and `_resolveCreateSessionPlan` (session-manager.js, the
631
+ * create-session path).
632
+ *
633
+ * - **catalog in hand** → its ids, and they are AUTHORITATIVE. The binary
634
+ * answered `model/list`; anything it did not name cannot be started, so
635
+ * rejecting is the provider's own truth rather than a chroxy opinion.
636
+ * - **no catalog** (never probed, probe failed, or the binary answered
637
+ * with ZERO rows) → `null`, i.e. UNRESTRICTED. Both gates map a
638
+ * non-array to "accept any non-empty id verbatim" — the ollama rule
639
+ * (#5418) — and the id is then validated by codex itself.
640
+ *
641
+ * Two returns are forbidden here, and each has its own red-proof in
642
+ * `tests/codex-model-validation.test.js`:
643
+ *
644
+ * - **the static seed.** "I could not ask" collapsing back into "these
645
+ * six" is precisely the lockout #7726/#7727 exist to remove, and it is
646
+ * the shape `anthropic-compatible-session.js:405-412` uses
647
+ * (`catalogIds -> entry.models -> null`) — correct THERE, because its
648
+ * middle rung is an operator-declared list, and wrong here, because
649
+ * ours is a hand-maintained seed that no longer matches any shipped
650
+ * binary. Deliberately NOT copied.
651
+ * - **an empty array.** It is the dangerous near-miss: `session-manager`
652
+ * skips it (`length > 0`) while `set_model` treats it as a DENY-ALL
653
+ * (`[]` is truthy, `[].includes(x)` is false) — so the same value means
654
+ * "unvalidated" at one gate and "nothing is allowed" at the other, and
655
+ * it reads as an authoritative allowlist to every future reader. A
656
+ * zero-row answer therefore takes the `null` branch, exactly like a
657
+ * failed probe: `hasCodexCatalog()` is false for BOTH, and
658
+ * `getCodexCatalogState()` is what tells them apart when that matters.
659
+ *
660
+ * The catalog is read DIRECTLY — not through `getFallbackModels()` and not
661
+ * through the models registry. The registry's roster is
662
+ * `discovered ∪ the statics captured at construction` (the #7761 deviation
663
+ * recorded on #7757: `createModelsRegistry` snapshots `getFallbackModels()`
664
+ * once, always before the first probe resolves, and `updateModels` merges
665
+ * the captured rows back), so validating against it would accept a stale
666
+ * hand-maintained id the binary does not serve. `tests/codex-model-
667
+ * validation.test.js` pins that divergence in both directions.
668
+ *
669
+ * `providers.allowAnyModel: ["codex"]` (#6378) is now a redundant
670
+ * workaround rather than the only way to run this provider — it still
671
+ * short-circuits both gates ahead of this method, and is deliberately kept.
672
+ *
673
+ * @returns {string[]|null} the catalog ids, or null = unrestricted.
398
674
  */
399
675
  static getAllowedModels() {
400
- return CODEX_ALLOWED_MODELS
676
+ // A fresh array per call: the catalog rows are frozen, but the ARRAY a
677
+ // caller receives must not be a handle onto module state (the
678
+ // deepseek/anthropic-compatible rule — a caller `.push()`ing into the
679
+ // allowlist must not widen it for everyone).
680
+ if (hasCodexCatalog()) return getCodexCatalogRows().map((row) => row.id)
681
+ return null
401
682
  }
402
683
 
403
684
  /**
@@ -409,9 +690,70 @@ export class CodexSession extends JsonlSubprocessSession {
409
690
  * @returns {ReadonlyArray<{id:string,label:string,fullId:string,contextWindow:number}>}
410
691
  */
411
692
  static getFallbackModels() {
693
+ // #7726 — REPLACE, not union, AT THIS FUNCTION. Once the binary has
694
+ // answered `model/list`, its roster is what this RETURNS; the six static
695
+ // rows do not ride along here, because a union means a model OpenAI
696
+ // retired never disappears. Pre-catalog (cold boot, probe not resolved,
697
+ // probe failed) the catalogued seed keeps the picker useful. `hasCatalog`
698
+ // is the sentinel-aware check: a catalog that was never fetched and one
699
+ // that came back empty are different facts, and neither of them may be
700
+ // reported as a roster.
701
+ //
702
+ // AND IT NOW ALSO HOLDS AT THE WIRE (#7761). It did not until that issue:
703
+ // the codex registry snapshots this function's result ONCE, at construction
704
+ // (`getRegistryForProvider` → `fallbackModels: getFallbackModels()`,
705
+ // models.js) — which always happens while the catalog is still UNSET, so
706
+ // the captured roster is always the six statics, and `updateModels` used to
707
+ // merge back every one the refresh omitted (the #3075 under-reporting
708
+ // union). Net `available_models` was `discovered ∪ {gpt-5-codex, gpt-5,
709
+ // gpt-4.1, gpt-4o, o1, o3}` in every process, PERMANENTLY — no path builds
710
+ // the registry after the catalog exists, so a restart reproduced it rather
711
+ // than clearing it, and `gpt-4.1`'s 1M window then minted a `gpt-4.1[1m]`
712
+ // chip that exists in no catalog (#7747). #7761 scoped BOTH rules to the
713
+ // Claude registry (identity check on the fallback roster), so a discovered
714
+ // codex roster now REPLACES at the wire as well. The registry-level test in
715
+ // codex-model-catalog.test.js pins that in BOTH directions — the discovered
716
+ // ids are present AND every static the refresh did not discover is absent —
717
+ // so a re-widening cannot land quietly. The captured roster is still stale
718
+ // by construction; it is simply no longer consulted once a refresh lands.
719
+ //
720
+ // The precise scope, because "REPLACES at the wire" on its own overstates
721
+ // it: the statics ARE still what `available_models` carries BEFORE any
722
+ // roster is learned — cold boot with no cache, probe unresolved, probe
723
+ // failed — which is the seed doing its job, not the union. What #7761/#7776
724
+ // removed is the seed riding back in ON TOP of a roster the binary reported,
725
+ // and that now holds at all three merge sites in models.js (`updateModels`,
726
+ // `loadCache`, `applyOverlay`'s cache-warmed branch). Stated at the
727
+ // observable rather than at the rule, because the two differ: the UNION no
728
+ // longer re-adds them, and rows a pre-fix build already PERSISTED are still
729
+ // served until the migration runs — `saveCache()` wrote `activeModels`, and
730
+ // the file is what boots. `loadCache`'s one-time schema-marker migration
731
+ // (models.js, `migrateLegacyStaticSeed`) is what takes them out of the file;
732
+ // absent that, they would be served indefinitely on an install whose probe
733
+ // never succeeds. Validation (`getAllowedModels`) is a separate roster and is
734
+ // untouched: #7727 is where the catalogue becomes authoritative there, so
735
+ // until it lands an id this function stopped OFFERING can still be ACCEPTED.
736
+ if (hasCodexCatalog()) {
737
+ return Object.freeze(getCodexCatalogRows().map((row) => Object.freeze(catalogEntry(row))))
738
+ }
412
739
  return CODEX_FALLBACK_MODELS
413
740
  }
414
741
 
742
+ /**
743
+ * #7731 — the ids of this provider's IN-REPO seed that the producer no longer
744
+ * offers (see `CODEX_DEPRECATED_SEED_IDS`). A fresh Set per call so a caller
745
+ * cannot widen the declaration for everyone; nothing in the runtime reads it.
746
+ *
747
+ * The parity guard treats "a provider with a catalog source AND an in-repo
748
+ * seed" as required to declare this — a provider that gains a catalog source
749
+ * and forgets it goes red rather than acquiring a seed nothing can retire.
750
+ *
751
+ * @returns {Set<string>}
752
+ */
753
+ static get deprecatedSeedModelIds() {
754
+ return new Set(CODEX_DEPRECATED_SEED_IDS)
755
+ }
756
+
415
757
  /**
416
758
  * Lookup metadata for a known Codex model. Returns null for unknown
417
759
  * ids so the registry can fall through to its generic heuristic
@@ -421,6 +763,17 @@ export class CodexSession extends JsonlSubprocessSession {
421
763
  * @returns {{id:string,label:string,fullId:string,contextWindow:number,description?:string}|null}
422
764
  */
423
765
  static getModelMetadata(modelId) {
766
+ if (typeof modelId !== 'string' || modelId.length === 0) return null
767
+ // #7726 — the discovered row wins: it carries the binary's own label, its
768
+ // reasoning levels, and a context window that came from the Codex CLI's
769
+ // cache or is honestly null.
770
+ const row = getCodexCatalogRow(modelId)
771
+ if (row) return catalogEntry(row)
772
+ // Not in the catalog (or no catalog yet): fall back to the catalogued seed
773
+ // for a LOOKUP only. This is not a membership decision — getFallbackModels
774
+ // above is the roster — so an id the seed still knows keeps its real label
775
+ // and window instead of falling through to the registry's generic 200k
776
+ // heuristic. An unknown id stays null, exactly as before.
424
777
  const meta = CODEX_MODEL_METADATA[modelId]
425
778
  if (!meta) return null
426
779
  return {
@@ -429,6 +782,69 @@ export class CodexSession extends JsonlSubprocessSession {
429
782
  fullId: modelId,
430
783
  contextWindow: meta.contextWindow,
431
784
  description: meta.description || '',
785
+ provenance: 'catalogued',
786
+ }
787
+ }
788
+
789
+ /**
790
+ * #7726 — refresh the codex model catalog from the app-server's own
791
+ * `model/list` and feed it into the codex models registry.
792
+ *
793
+ * This is the hook `scheduleProviderModelsRefresh` (ws-history.js) calls,
794
+ * fire-and-forget, whenever it sends `available_models` for this provider.
795
+ * Resolves to the refreshed list when the picker CHANGED, else null. Never
796
+ * throws and never blocks: every failure path resolves null and leaves the
797
+ * previous catalog untouched.
798
+ *
799
+ * With no `client` in `deps` this spawns a SHORT-LIVED app-server for the
800
+ * probe — the no-session/create-session path, which is exactly where the
801
+ * frozen roster used to reject the operator's configured model. A live
802
+ * session passes its own client instead (CodexAppServerSession.start).
803
+ *
804
+ * `deps` is the test seam (client / createClient / registry / now / ttlMs /
805
+ * timeoutMs / windows).
806
+ *
807
+ * `bin` and `env` are passed as THUNKS, not values (#7757 review).
808
+ * `resolvedBinary` re-runs a synchronous `execFileSync('which', …)` on every
809
+ * read by design (#6708) and `buildSpawnEnv` walks the environment; this
810
+ * method runs on the post-auth `available_models` path for the DEFAULT
811
+ * provider, so building them eagerly meant a blocking child process on every
812
+ * push — including the calls that carry a live client (never spawns) and the
813
+ * ones the TTL gate drops without probing. `probeCodexCatalog` calls the
814
+ * thunk on the one branch that actually spawns.
815
+ */
816
+ static refreshModels(deps = {}) {
817
+ try {
818
+ return refreshCodexModels({
819
+ ...deps,
820
+ registry: deps.registry || getRegistryForProvider('codex'),
821
+ // #8059 review (Suggestion 1 / S1) — a caller with NEITHER a live
822
+ // `client` NOR a verified `bin` thunk now gets REFUSED, not a silent
823
+ // unverified spawn off `this.resolvedBinary`. #8030 set this precedent
824
+ // for the one-shot summarizer/title calls (`defaultRunOneShot` throws
825
+ // when no verified `resolveExecutable` is supplied,
826
+ // summarize-session.js:207-210); this no-session probe has the exact
827
+ // same shape and the exact same risk, so it gets the same default.
828
+ // `bin` is only ever CALLED on the no-client spawn branch
829
+ // (`probeCodexCatalog`) — a `client`-carrying caller (the live
830
+ // session's own refresh) never reaches it, so this default is inert
831
+ // for that path. Today's only no-client caller (`ws-history.js`'s
832
+ // `scheduleProviderModelsRefresh`) always supplies `bin`, so this is
833
+ // a safety net for the NEXT no-client caller that forgets to, not a
834
+ // behaviour change for any caller that exists today.
835
+ bin: 'bin' in deps ? deps.bin : () => {
836
+ const err = new Error('CodexSession.refreshModels: no live client and no verified `bin` were supplied — refusing an unverified spawn (#8036/S1). Pass a `client`, or a `bin` built from a verified resolver (e.g. SessionManager.verifyOneShotExecutable).')
837
+ err.code = 'PROVIDER_BINARY_UNVERIFIED'
838
+ throw err
839
+ },
840
+ cwd: 'cwd' in deps ? deps.cwd : undefined,
841
+ env: 'env' in deps ? deps.env : () => buildSpawnEnv('codex'),
842
+ })
843
+ } catch {
844
+ // A refresh is advisory. A throw here (a registry build that blew up, a
845
+ // binary resolver that threw) must not become an unhandled rejection in
846
+ // the post-auth path.
847
+ return Promise.resolve(null)
432
848
  }
433
849
  }
434
850
 
@@ -443,6 +859,7 @@ export class CodexSession extends JsonlSubprocessSession {
443
859
  args: ['--version'],
444
860
  candidates: BINARY_CANDIDATES,
445
861
  installHint: 'install Codex CLI',
862
+ overrideEnv: 'CHROXY_CODEX_BIN', // #8609
446
863
  },
447
864
  credentials: {
448
865
  envVars: ['OPENAI_API_KEY'],
@@ -527,6 +944,9 @@ export class CodexSession extends JsonlSubprocessSession {
527
944
  super(buildBaseSessionOpts(opts, {
528
945
  provider: opts.provider || 'codex',
529
946
  model: opts.model || DEFAULT_MODEL,
947
+ // This adapter cannot intercept Auto. Do not inherit the subprocess
948
+ // layer's Auto default when the caller omitted a permission mode.
949
+ permissionMode: opts.permissionMode || 'approve',
530
950
  resumeSessionId: opts.resumeSessionId,
531
951
  }))
532
952
  // #6638: per-session sandbox override — honored on the exec path too, so a
@@ -588,7 +1008,9 @@ export class CodexSession extends JsonlSubprocessSession {
588
1008
  const item = event.item
589
1009
  if (!item) break
590
1010
 
591
- if (item.type === 'agent_message' && item.text) {
1011
+ if (item.type === 'agent_message') {
1012
+ this.emit('assistant_response', { responseId: item.id, text: assistantResponseText(item.text) })
1013
+ if (typeof item.text !== 'string' || !item.text) break
592
1014
  if (!ctx.didStreamStart) {
593
1015
  this.emit('stream_start', { messageId: ctx.messageId })
594
1016
  ctx.didStreamStart = true
@@ -646,6 +1068,7 @@ export class CodexSession extends JsonlSubprocessSession {
646
1068
  cost: null,
647
1069
  duration: null,
648
1070
  usage: this._mapUsage(usage),
1071
+ declarationEligible: !event.error,
649
1072
  sessionId: this.resumeSessionId,
650
1073
  })
651
1074
  break