@bitkyc08/opencodex 2.93.0-preview.20261027 → 2.94.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (435) hide show
  1. package/README.md +27 -8
  2. package/bin/ocx.mjs +215 -63
  3. package/gui/dist/assets/App-DmvwlhQq.js +58 -0
  4. package/gui/dist/assets/Tray-CZatQdoF.js +1 -0
  5. package/gui/dist/assets/index-3EPO_KbX.js +94 -0
  6. package/gui/dist/assets/index-CHWwDo9L.css +1 -0
  7. package/gui/dist/assets/{quota-summary-DxToX1rV.js → quota-summary-BHvWg9mi.js} +1 -1
  8. package/gui/dist/index.html +2 -2
  9. package/gui/dist/provider-icons/t3code.svg +4 -0
  10. package/package.json +7 -4
  11. package/src/adapters/anthropic/account-metadata.ts +34 -3
  12. package/src/adapters/anthropic/beta-allowlist.ts +5 -5
  13. package/src/adapters/anthropic/passthrough.ts +5 -2
  14. package/src/adapters/anthropic.ts +17 -4
  15. package/src/adapters/antigravity-refusal.ts +29 -0
  16. package/src/adapters/base.ts +11 -1
  17. package/src/adapters/client-fingerprint.ts +43 -9
  18. package/src/adapters/coding-agent/protocol.ts +19 -9
  19. package/src/adapters/command-code.ts +4 -5
  20. package/src/adapters/cursor/catalog.ts +5 -3
  21. package/src/adapters/cursor/claude-id.ts +30 -19
  22. package/src/adapters/cursor/cursor-errors.ts +5 -2
  23. package/src/adapters/cursor/h2-pool.ts +9 -7
  24. package/src/adapters/cursor/http1-bidi.ts +1 -0
  25. package/src/adapters/cursor/live-models.ts +4 -2
  26. package/src/adapters/cursor.ts +4 -1
  27. package/src/adapters/devin/cloud-direct/chat.ts +18 -2
  28. package/src/adapters/google-antigravity-replay.ts +13 -2
  29. package/src/adapters/google-antigravity-wire.ts +8 -3
  30. package/src/adapters/google-errors.ts +33 -0
  31. package/src/adapters/google-http.ts +41 -16
  32. package/src/adapters/google-wire-compiler.ts +4 -0
  33. package/src/adapters/google.ts +21 -10
  34. package/src/adapters/kiro/adapter.ts +3 -0
  35. package/src/adapters/kiro/stream.ts +18 -13
  36. package/src/adapters/openai-chat/completed-tool-blocks.ts +65 -0
  37. package/src/adapters/openai-chat/messages.ts +22 -10
  38. package/src/adapters/openai-chat/required-tool-result.ts +3 -3
  39. package/src/adapters/openai-chat/serialized-tool-call-content.ts +5 -0
  40. package/src/adapters/openai-chat/wire.ts +9 -0
  41. package/src/adapters/openai-chat.ts +18 -17
  42. package/src/adapters/openai-responses/image-gen.ts +15 -1
  43. package/src/adapters/openai-responses/passthrough.ts +11 -34
  44. package/src/adapters/openai-responses/transport.ts +20 -2
  45. package/src/adapters/openai-responses/usage.ts +34 -0
  46. package/src/adapters/qoder/adapter.ts +9 -15
  47. package/src/adapters/qoder/image-input.ts +52 -0
  48. package/src/adapters/unique-tool-call-ids.ts +2 -2
  49. package/src/adapters/zed-additional-tools.ts +51 -0
  50. package/src/adapters/zed-diagnostic-usage.ts +22 -0
  51. package/src/adapters/zed-json-tokens.ts +166 -0
  52. package/src/adapters/zed-openai-stream.ts +723 -0
  53. package/src/adapters/zed-tool-arguments.ts +79 -0
  54. package/src/adapters/zed.ts +53 -3
  55. package/src/advisor/consult.ts +22 -0
  56. package/src/advisor/runtime.ts +3 -0
  57. package/src/bridge/errors.ts +22 -1
  58. package/src/bridge/response-json.ts +4 -1
  59. package/src/bridge/sse.ts +21 -12
  60. package/src/chat/inbound.ts +13 -2
  61. package/src/chatgpt/app-server-shim/bundle-trust-async.ts +111 -0
  62. package/src/chatgpt/app-server-shim/bundle-trust-policy.ts +83 -0
  63. package/src/chatgpt/app-server-shim/bundle-trust.ts +15 -72
  64. package/src/claude/desktop-first-party.ts +16 -5
  65. package/src/claude/desktop-gateway-state.ts +4 -0
  66. package/src/claude/inbound-tool-loading.ts +93 -0
  67. package/src/claude/intercept/picker-listener.ts +33 -1
  68. package/src/claude/model-info.ts +29 -4
  69. package/src/claude/outbound.ts +33 -13
  70. package/src/cli/account-main.ts +43 -5
  71. package/src/cli/capabilities-base.ts +22 -5
  72. package/src/cli/capabilities-integrations.ts +4 -4
  73. package/src/cli/claude-desktop.ts +139 -98
  74. package/src/cli/codex-cli-update.ts +102 -48
  75. package/src/cli/codex-launch-auth.ts +93 -0
  76. package/src/cli/codex-launch-command.ts +32 -0
  77. package/src/cli/codex-launch-diagnostics.ts +37 -0
  78. package/src/cli/codex-launch-ownership.ts +307 -0
  79. package/src/cli/codex-launch-policy.ts +84 -0
  80. package/src/cli/codex-launcher.ts +310 -0
  81. package/src/cli/codex-shim-autorestore.ts +2 -0
  82. package/src/cli/config-command.ts +9 -4
  83. package/src/cli/config-mutation.ts +13 -0
  84. package/src/cli/dispatch.ts +13 -7
  85. package/src/cli/effort.ts +19 -14
  86. package/src/cli/ensure-desired-integrations.ts +21 -14
  87. package/src/cli/ensure-desktop-cold-start.ts +41 -10
  88. package/src/cli/export-command.ts +8 -4
  89. package/src/cli/help.ts +3 -1
  90. package/src/cli/index.ts +58 -64
  91. package/src/cli/integration-input.ts +12 -0
  92. package/src/cli/integration-plan-dto.ts +2 -0
  93. package/src/cli/integration-preview.ts +6 -3
  94. package/src/cli/integrations.ts +2 -1
  95. package/src/cli/link-cleanup.ts +8 -23
  96. package/src/cli/link-enrollment.ts +1 -4
  97. package/src/cli/link.ts +1 -1
  98. package/src/cli/loopback-family.ts +2 -31
  99. package/src/cli/models.ts +62 -49
  100. package/src/cli/provider.ts +146 -139
  101. package/src/cli/registry.ts +34 -3
  102. package/src/cli/root.ts +2 -0
  103. package/src/cli/start-owner-fence.ts +22 -3
  104. package/src/cli/status-link.ts +28 -0
  105. package/src/cli/status.ts +15 -0
  106. package/src/cli/stop-restore-guard.ts +48 -0
  107. package/src/cli/stop-restore.ts +117 -36
  108. package/src/cli/system-command.ts +2 -0
  109. package/src/cli/v2.ts +17 -4
  110. package/src/client/lifecycle-lock.ts +1 -1
  111. package/src/client/link-connection.ts +19 -0
  112. package/src/client/link-relay-transport.ts +25 -3
  113. package/src/client/link-tunnel.ts +10 -0
  114. package/src/client/machine-listener.ts +7 -1
  115. package/src/client/restore-ownership.ts +45 -0
  116. package/src/client/runtime.ts +13 -1
  117. package/src/client/state.ts +1 -1
  118. package/src/clients/client-ids.ts +7 -0
  119. package/src/clients/client-path.ts +13 -5
  120. package/src/clients/config-export/agent-clients.ts +3 -6
  121. package/src/clients/config-export/alias-selectors.ts +85 -0
  122. package/src/clients/config-export/contracts.ts +6 -25
  123. package/src/clients/config-export/dsh.ts +8 -1
  124. package/src/clients/config-export/model-metadata.ts +19 -0
  125. package/src/clients/config-export/model-names.ts +31 -0
  126. package/src/clients/config-export/qoder.ts +3 -11
  127. package/src/clients/config-export/t3code.ts +141 -0
  128. package/src/clients/config-export.ts +51 -15
  129. package/src/clients/gentle-shell-path.ts +3 -3
  130. package/src/codex/account-lifecycle.ts +27 -13
  131. package/src/codex/account-store.ts +32 -6
  132. package/src/codex/app-server-processes.ts +84 -1
  133. package/src/codex/auth-api/main-account-probe.ts +50 -11
  134. package/src/codex/auth-api/pool-mode-gate.ts +16 -8
  135. package/src/codex/auth-context.ts +45 -4
  136. package/src/codex/catalog/antigravity-discovery.ts +59 -0
  137. package/src/codex/catalog/build-entries.ts +12 -13
  138. package/src/codex/catalog/bundled.ts +59 -9
  139. package/src/codex/catalog/derive-entry.ts +2 -0
  140. package/src/codex/catalog/gather-capture.ts +3 -0
  141. package/src/codex/catalog/metadata.ts +6 -5
  142. package/src/codex/catalog/model-hints.ts +36 -4
  143. package/src/codex/catalog/native-priority.ts +63 -0
  144. package/src/codex/catalog/provider-models.ts +20 -4
  145. package/src/codex/catalog/retained-sync.ts +1 -1
  146. package/src/codex/chatgpt-refresh-failure.ts +2 -2
  147. package/src/codex/cli-install-provenance.ts +57 -29
  148. package/src/codex/cli-installation-identity.ts +1 -1
  149. package/src/codex/cli-installation-limits.ts +7 -0
  150. package/src/codex/cli-update-apply.ts +391 -0
  151. package/src/codex/cli-update-artifacts.ts +257 -0
  152. package/src/codex/cli-update-files.ts +100 -0
  153. package/src/codex/cli-update-inspection-context.ts +49 -0
  154. package/src/codex/cli-update-job-execution.ts +77 -0
  155. package/src/codex/cli-update-job-store-windows.ts +1010 -0
  156. package/src/codex/cli-update-job-worker.ts +393 -0
  157. package/src/codex/cli-update-job.ts +369 -0
  158. package/src/codex/cli-update-lease.ts +71 -0
  159. package/src/codex/cli-update-paths.ts +76 -0
  160. package/src/codex/cli-update-plan.ts +180 -47
  161. package/src/codex/cli-update-recovery.ts +236 -0
  162. package/src/codex/cli-update-selection-gate.ts +235 -0
  163. package/src/codex/cli-update-windows-apply.ts +308 -0
  164. package/src/codex/cli-update-windows-layout.ts +110 -0
  165. package/src/codex/cli-update-windows-observation.ts +91 -0
  166. package/src/codex/cli-update-windows-paths.ts +26 -0
  167. package/src/codex/cli-update-worker-recovery.ts +32 -0
  168. package/src/codex/cli-update-worker.ts +185 -0
  169. package/src/codex/cli-windows-plan-provenance.ts +250 -0
  170. package/src/codex/desktop-app-restart.ts +22 -3
  171. package/src/codex/exec-boundary.ts +208 -0
  172. package/src/codex/forward-transport-headers.ts +80 -0
  173. package/src/codex/history-job.ts +7 -0
  174. package/src/codex/history-provider.ts +5 -2
  175. package/src/codex/history-worker.ts +20 -1
  176. package/src/codex/inject/restore.ts +57 -25
  177. package/src/codex/internal/history-writer.ts +2 -1
  178. package/src/codex/mac-app-bundle.ts +52 -0
  179. package/src/codex/main-account.ts +161 -23
  180. package/src/codex/native-main-auth-temp.ts +3 -2
  181. package/src/codex/native-main-refresh-mode.ts +18 -3
  182. package/src/codex/native-profile-manager.ts +8 -6
  183. package/src/codex/native-profile-store.ts +9 -0
  184. package/src/codex/ocx-compaction-history.ts +3 -2
  185. package/src/codex/prompt-text-probe.ts +211 -69
  186. package/src/codex/quota.ts +9 -0
  187. package/src/codex/role-model-history.ts +253 -0
  188. package/src/codex/runtime.ts +120 -71
  189. package/src/codex/shim-overlay.ts +22 -3
  190. package/src/codex/shim-templates.ts +5 -2
  191. package/src/codex/shim-wrapper-write.ts +136 -0
  192. package/src/codex/shim.ts +24 -125
  193. package/src/codex/windows-cli-child-native.ts +119 -0
  194. package/src/codex/windows-cli-child-pipe.ts +87 -0
  195. package/src/codex/windows-cli-child.ts +260 -0
  196. package/src/codex/windows-cli-recovery-guardian.ts +89 -0
  197. package/src/codex/windows-cli-recovery.ts +39 -0
  198. package/src/codex/windows-installation-files.ts +52 -6
  199. package/src/codex/windows-npm-execution.ts +25 -0
  200. package/src/combos/failover.ts +84 -5
  201. package/src/combos/index.ts +1 -0
  202. package/src/combos/resolve.ts +60 -22
  203. package/src/config/atomic-write.ts +75 -22
  204. package/src/config/diagnostics.ts +18 -10
  205. package/src/config/live-reconcile.ts +11 -3
  206. package/src/config/owner-registry.ts +5 -4
  207. package/src/config/persist-unlocked.ts +34 -8
  208. package/src/config/persisted-mutation.ts +7 -0
  209. package/src/config/process-state.ts +9 -5
  210. package/src/config/removed-opencode-free-backup.ts +99 -0
  211. package/src/config/removed-opencode-free.ts +4 -8
  212. package/src/config/salvage.ts +1 -0
  213. package/src/config/schema/config-schema.ts +16 -1
  214. package/src/config/schema/leaf-validators.ts +15 -0
  215. package/src/config.ts +4 -4
  216. package/src/generated/compatibility-version.json +743 -315
  217. package/src/grok/inject.ts +2 -1
  218. package/src/grok/sync.ts +5 -2
  219. package/src/images/loop.ts +14 -5
  220. package/src/integrations/catalog-refresh.ts +1 -1
  221. package/src/integrations/hermes-refresh.ts +28 -0
  222. package/src/integrations/model-name-guard.ts +31 -0
  223. package/src/integrations/mutation-plan.ts +17 -4
  224. package/src/integrations/ownership.ts +3 -0
  225. package/src/integrations/registry.ts +10 -1
  226. package/src/integrations/state.ts +6 -0
  227. package/src/integrations/writer.ts +64 -59
  228. package/src/lib/abort.ts +8 -4
  229. package/src/lib/bounded-body.ts +7 -1
  230. package/src/lib/config-ownership.ts +4 -0
  231. package/src/lib/errors.ts +2 -0
  232. package/src/lib/eventstream-decoder.ts +3 -2
  233. package/src/lib/http-response-semantics.ts +9 -6
  234. package/src/lib/inbound-body-policy.ts +11 -0
  235. package/src/lib/jsonc.ts +7 -2
  236. package/src/lib/local-management-capability.ts +3 -1
  237. package/src/lib/local-upstream.ts +22 -26
  238. package/src/lib/loopback-family.ts +31 -0
  239. package/src/lib/plain-data.ts +7 -5
  240. package/src/lib/process-control.ts +30 -5
  241. package/src/lib/shadow-call.ts +55 -1
  242. package/src/lib/tool-argument-integers.ts +99 -7
  243. package/src/lib/upstream-retry.ts +6 -1
  244. package/src/lib/windows-elevation.ts +34 -11
  245. package/src/lib/windows-owner-acl.ts +272 -32
  246. package/src/lib/windows-secret-acl.ts +310 -44
  247. package/src/lib/windows-service-wrappers.ts +10 -7
  248. package/src/lib/winsw.ts +8 -4
  249. package/src/link/relay-auth.ts +38 -1
  250. package/src/link/remote-platform.ts +11 -23
  251. package/src/link/remote-probe.ts +3 -1
  252. package/src/link/remote-windows.ts +150 -0
  253. package/src/link/ssh-argv.ts +13 -5
  254. package/src/link/store.ts +4 -1
  255. package/src/link/supervisor.ts +9 -0
  256. package/src/local-credentials/generation.ts +238 -0
  257. package/src/local-credentials/inventory.ts +281 -0
  258. package/src/local-credentials/observation-lease.ts +83 -0
  259. package/src/local-credentials/publication-fence.ts +81 -0
  260. package/src/local-credentials/references.ts +36 -0
  261. package/src/local-credentials/runtime-observation.ts +28 -0
  262. package/src/oauth/account-auto-pause-policy.ts +11 -0
  263. package/src/oauth/anthropic-account-refusal.ts +1 -0
  264. package/src/oauth/anthropic-rate-limit-policy.ts +26 -2
  265. package/src/oauth/anthropic-routing.ts +34 -44
  266. package/src/oauth/anthropic-session-affinity-store.ts +177 -0
  267. package/src/oauth/chatgpt.ts +11 -9
  268. package/src/oauth/cursor.ts +8 -2
  269. package/src/oauth/generic-account-failover.ts +33 -2
  270. package/src/oauth/generic-session-affinity.ts +7 -0
  271. package/src/oauth/google-antigravity.ts +29 -5
  272. package/src/oauth/index.ts +1 -0
  273. package/src/oauth/store.ts +32 -4
  274. package/src/protocols/encoders/adapter-events.ts +7 -4
  275. package/src/protocols/encoders/messages.ts +1 -1
  276. package/src/providers/antigravity-account-roster.ts +73 -7
  277. package/src/providers/antigravity-models.ts +8 -4
  278. package/src/providers/api-key-resolve.ts +16 -3
  279. package/src/providers/claude-cli-identity.ts +2 -0
  280. package/src/providers/codex-capacity.ts +3 -2
  281. package/src/providers/free-directory.ts +10 -2
  282. package/src/providers/key-store.ts +7 -2
  283. package/src/providers/provider-id-rewrite.ts +3 -0
  284. package/src/providers/quota/antigravity.ts +6 -4
  285. package/src/providers/quota/vendor-probes-oauth.ts +0 -1
  286. package/src/providers/stale-model-roster-migration.ts +3 -0
  287. package/src/quota-pool/assemble.ts +51 -21
  288. package/src/quota-pool/pooled.ts +162 -0
  289. package/src/remote-control/workspace-codex-runtime.ts +63 -20
  290. package/src/responses/apply-patch-envelope.ts +35 -0
  291. package/src/responses/compaction-history-framing.ts +15 -4
  292. package/src/responses/turn-membership.ts +111 -0
  293. package/src/server/advisor-admission-scope.ts +43 -0
  294. package/src/server/audio-upstream.ts +10 -2
  295. package/src/server/auth-cors.ts +23 -0
  296. package/src/server/bind-host.ts +5 -0
  297. package/src/server/chat-completions.ts +17 -2
  298. package/src/server/chat-native.ts +16 -11
  299. package/src/server/claude-messages.ts +9 -1
  300. package/src/server/codex-model-list.ts +46 -0
  301. package/src/server/gui-session.ts +5 -2
  302. package/src/server/inbound-body-admission.ts +21 -13
  303. package/src/server/inbound-body-budget.ts +128 -0
  304. package/src/server/index/link-listener.ts +3 -1
  305. package/src/server/index/link-relay-sessions.ts +9 -2
  306. package/src/server/index/optional-listeners.ts +1 -0
  307. package/src/server/index/serve-options.ts +9 -43
  308. package/src/server/index/websocket-handler.ts +7 -0
  309. package/src/server/index.ts +6 -5
  310. package/src/server/inference/client-encoder-delivery.ts +3 -1
  311. package/src/server/lifecycle.ts +8 -1
  312. package/src/server/management/advisor-routes.ts +26 -9
  313. package/src/server/management/agent-settings-routes.ts +424 -543
  314. package/src/server/management/anthropic-reset-grant-routes.ts +2 -1
  315. package/src/server/management/claude-code-settings-patch.ts +211 -0
  316. package/src/server/management/claude-desktop-config-writers.ts +78 -0
  317. package/src/server/management/codex-agent-role-routes.ts +79 -2
  318. package/src/server/management/codex-cli-update-routes.ts +55 -0
  319. package/src/server/management/codex-prompt-routes.ts +2 -1
  320. package/src/server/management/config-routes.ts +444 -380
  321. package/src/server/management/consent-session.ts +6 -0
  322. package/src/server/management/desktop-compatibility-authorization.ts +12 -0
  323. package/src/server/management/desktop-compatibility-routes.ts +3 -2
  324. package/src/server/management/desktop-compatibility-runtime-routes.ts +2 -1
  325. package/src/server/management/desktop-compatibility-settings-routes.ts +2 -1
  326. package/src/server/management/integration-routes.ts +45 -5
  327. package/src/server/management/link-enrollment.ts +21 -32
  328. package/src/server/management/link-route-state.ts +1 -0
  329. package/src/server/management/link-routes.ts +4 -1
  330. package/src/server/management/model-routes.ts +22 -6
  331. package/src/server/management/model-rows.ts +3 -1
  332. package/src/server/management/native-integration-routes.ts +90 -38
  333. package/src/server/management/oauth-account-routes.ts +8 -7
  334. package/src/server/management/route-registry.ts +8 -3
  335. package/src/server/management/session-routes.ts +20 -2
  336. package/src/server/management/shadow-call-validation.ts +43 -2
  337. package/src/server/management/sidebar-routes.ts +2 -1
  338. package/src/server/management/system-restart.ts +47 -7
  339. package/src/server/management-api.ts +61 -51
  340. package/src/server/management-auth.ts +11 -3
  341. package/src/server/messages-native.ts +21 -7
  342. package/src/server/messages-shared.ts +110 -18
  343. package/src/server/persistent-gui-session.ts +155 -0
  344. package/src/server/port-reclaim.ts +29 -5
  345. package/src/server/proxy-liveness.ts +110 -33
  346. package/src/server/request-decompress.ts +5 -1
  347. package/src/server/responses/account-change-state.ts +14 -2
  348. package/src/server/responses/adapter-continuation.ts +5 -4
  349. package/src/server/responses/adapter-delivery.ts +20 -5
  350. package/src/server/responses/adapter-dispatch.ts +39 -45
  351. package/src/server/responses/advisor-plan-slot.ts +3 -0
  352. package/src/server/responses/advisor-slot.ts +4 -2
  353. package/src/server/responses/antigravity-model-denial-recovery.ts +70 -0
  354. package/src/server/responses/antigravity-validation-refusal.ts +6 -0
  355. package/src/server/responses/combo-required-tool-contract.ts +2 -1
  356. package/src/server/responses/combo-required-tool-fulfillments.ts +58 -0
  357. package/src/server/responses/combo-required-tool-stream.ts +119 -0
  358. package/src/server/responses/combo-stream-preflight.ts +47 -7
  359. package/src/server/responses/compact.ts +14 -7
  360. package/src/server/responses/compaction-recovery.ts +2 -1
  361. package/src/server/responses/core-auth.ts +2 -1
  362. package/src/server/responses/core-codex-account.ts +1 -0
  363. package/src/server/responses/core-combo-failure.ts +11 -6
  364. package/src/server/responses/core-combo-native.ts +6 -5
  365. package/src/server/responses/core-combo.ts +93 -20
  366. package/src/server/responses/core-options.ts +7 -0
  367. package/src/server/responses/fetch-helpers.ts +5 -1
  368. package/src/server/responses/jev-model-invoke.ts +8 -3
  369. package/src/server/responses/memory-models.ts +3 -2
  370. package/src/server/responses/passthrough-delivery.ts +36 -8
  371. package/src/server/responses/passthrough-dispatch.ts +12 -12
  372. package/src/server/responses/request-prepare.ts +10 -1
  373. package/src/server/responses/request-transport.ts +41 -6
  374. package/src/server/responses/run-turn-execution.ts +11 -3
  375. package/src/server/responses/sidecar-execution.ts +5 -0
  376. package/src/server/responses/turn-membership.ts +30 -0
  377. package/src/server/responses-custom-tool-repair.ts +86 -11
  378. package/src/server/responses-image-gen-repair.ts +1 -1
  379. package/src/server/restart-parent-ownership.ts +49 -0
  380. package/src/server/stop-teardown.ts +46 -9
  381. package/src/server/windows-tcp-drop.ts +4 -2
  382. package/src/service/desktop-recovery-process.ts +341 -0
  383. package/src/service/desktop-recovery.ts +172 -0
  384. package/src/service/windows-ops.ts +6 -3
  385. package/src/service/windows-scheduler.ts +29 -6
  386. package/src/stall-timeout.ts +47 -0
  387. package/src/tray/windows.ts +6 -4
  388. package/src/types/config.ts +61 -10
  389. package/src/types/request.ts +1 -1
  390. package/src/types.ts +1 -0
  391. package/src/update/async-check.ts +4 -3
  392. package/src/update/bind-probe.ts +2 -2
  393. package/src/update/codex-cli-update-launch-policy.mjs +9 -0
  394. package/src/update/guarded-port-reclaim.ts +14 -0
  395. package/src/update/guarded-runtime-ops.ts +58 -0
  396. package/src/update/guarded-tray-ops.ts +9 -0
  397. package/src/update/index.ts +196 -58
  398. package/src/update/job-pinned-start.ts +53 -0
  399. package/src/update/job-supervised-restart.ts +23 -6
  400. package/src/update/job-update-home.ts +62 -0
  401. package/src/update/job-update-tray.ts +29 -0
  402. package/src/update/job-windows-restart.ts +39 -0
  403. package/src/update/job.ts +179 -193
  404. package/src/update/mutation-guard.d.mts +30 -0
  405. package/src/update/mutation-guard.mjs +103 -0
  406. package/src/update/notify.ts +2 -2
  407. package/src/update/npm-cache-preflight.mjs +4 -4
  408. package/src/update/npm-install.mjs +5 -3
  409. package/src/update/pnpm-read-policy.mjs +3 -2
  410. package/src/update/proxy-liveness-probe.mjs +2 -2
  411. package/src/update/service-home-authority.ts +35 -0
  412. package/src/update/service-home-package-only-protocol.json +1 -0
  413. package/src/update/service-home-policy.d.mts +25 -0
  414. package/src/update/service-home-policy.mjs +112 -0
  415. package/src/update/service-home-probe-entry.ts +9 -0
  416. package/src/update/service-home-probe.d.mts +15 -0
  417. package/src/update/service-home-probe.mjs +79 -0
  418. package/src/update/service-home-protocol.json +1 -0
  419. package/src/update/supervised-recovery.d.mts +2 -2
  420. package/src/update/supervised-recovery.mjs +14 -7
  421. package/src/update/transactional-install.d.mts +3 -1
  422. package/src/update/transactional-install.mjs +29 -19
  423. package/src/update/update-failure-guidance.mjs +1 -1
  424. package/src/update/worker-launch.ts +3 -3
  425. package/src/vision/anthropic-describe.ts +2 -1
  426. package/src/web-search/anthropic-executor.ts +2 -1
  427. package/src/web-search/anthropic-history.ts +1 -0
  428. package/src/web-search/format-result.ts +3 -2
  429. package/src/web-search/header-deadline.ts +3 -2
  430. package/src/web-search/loop.ts +10 -4
  431. package/src/web-search/parse.ts +191 -38
  432. package/gui/dist/assets/App-CJZoq-uF.js +0 -58
  433. package/gui/dist/assets/Tray-BWQPcgZn.js +0 -1
  434. package/gui/dist/assets/index-DRe8Hhfz.css +0 -1
  435. package/gui/dist/assets/index-Xfct8owH.js +0 -94
@@ -0,0 +1,310 @@
1
+ /**
2
+ * `ocx codex [codex args...]` — launch Codex wired to the local proxy's routing,
3
+ * passing through untouched when Codex routing is disabled or foreign.
4
+ *
5
+ * Mirrors `ocx claude` (src/cli/claude.ts) and `ocx opencode` (src/cli/opencode.ts):
6
+ * ensures the proxy is running, then execs the client with stdio inherited. The wiring
7
+ * channel differs again — Codex routing is config-owned (the injected `openai_base_url`
8
+ * and model catalog in `~/.codex/config.toml`), so a launch never rewrites a config
9
+ * file. What the launcher owns instead is the two add-ons `plain codex` lacks:
10
+ *
11
+ * - launch-time autostart: the same detached `ocx start` + health poll that
12
+ * `ocx ensure` gives service- and shim-less setups, attempted before every routed launch;
13
+ * - an honest route verdict before exec: native and foreign-gateway configs are
14
+ * announced (and NOT ensured) instead of silently benefiting or fighting them,
15
+ * reusing the routing classification the shim and doctor share
16
+ * (src/codex/inject/routing-classify.ts).
17
+ *
18
+ * The admission token is re-exported from `~/.opencodex/service-api-token` when the
19
+ * environment does not carry it — the same injection the generated Codex autostart
20
+ * shim performs (src/codex/shim-templates.ts), whose argv fast-path grammar
21
+ * (--help/-h, --version/-V, internal subcommands, global options with values) is
22
+ * mirrored here so both `codex` entry points behave identically for the same argv.
23
+ */
24
+ import { spawn } from "node:child_process";
25
+ import { loadConfig } from "../config";
26
+ import { getCodexRoutingKind, type CodexRoutingKind } from "../codex/inject";
27
+ import { inspectCodexShimBackingForCommand } from "../codex/shim";
28
+ import { CODEX_GLOBAL_OPTIONS_WITH_VALUE, CODEX_INTERNAL_COMMANDS, CODEX_SHIM_ENSURE_FAILED_DIAGNOSTIC } from "../codex/shim-templates";
29
+ import { withoutSiblingMarker } from "../codex/sibling-start";
30
+ import { withProcessRuntimeProvenance } from "../lib/bun-runtime";
31
+ import { tokenCollidesWithAdmin } from "../lib/admin-secrets";
32
+ import { selfLaunchArgv } from "../lib/self-launch-argv";
33
+ import { loadServiceTokenFromFile, serviceApiTokenFilePath } from "../lib/service-secrets";
34
+ import { commandInvocation } from "../lib/win-exec";
35
+ import { findExecutableOnPath } from "../remote-control/workspace-executable";
36
+ import { findLiveProxy, type LiveProxy } from "../server/proxy-liveness";
37
+ import { codexCredentialDestinationIsTrusted, resolveCodexLaunchHome } from "./codex-launch-auth";
38
+ import { codexCommandCanBypass, CODEX_UNVERIFIED_SHIM } from "./codex-launch-command";
39
+ import { codexTokenArgsAreSafe, codexTokenEnvironmentIsSafe } from "./codex-launch-policy";
40
+ import { codexTokenWithheldDiagnostic, type CodexTokenRefusal, type CodexTokenRefusalReporter } from "./codex-launch-diagnostics";
41
+
42
+ export interface CodexLaunchEnv {
43
+ [key: string]: string | undefined;
44
+ }
45
+
46
+ type FastPathReason = "help" | "version" | "internal";
47
+
48
+ /**
49
+ * Mirrors the generated shim wrapper's argv grammar (src/codex/shim-templates.ts):
50
+ * an invocation whose first positional operand is a Codex-internal subcommand, or
51
+ * which only asks for help/version, never needs the proxy. The shell scanners
52
+ * inline these sets — the exported constants here are the single source they are
53
+ * read from — while the option-value rules (`--model x`, `-c k=v`, ...) stay in
54
+ * this scanner in sync with the same templates.
55
+ */
56
+ export function codexFastPathReason(args: readonly string[]): FastPathReason | null {
57
+ let skipNext = false;
58
+ for (const arg of args) {
59
+ if (skipNext) { skipNext = false; continue; }
60
+ if (arg === "--") return null; // the shim's `break`: rest is operands, ensure runs
61
+ const options = CODEX_GLOBAL_OPTIONS_WITH_VALUE;
62
+ if (options.includes(arg)) { skipNext = true; continue; }
63
+ if (arg === "--help" || arg === "-h") return "help";
64
+ if (arg === "--version" || arg === "-V") return "version";
65
+ if (arg.startsWith("-")) continue;
66
+ const value = arg;
67
+ return (CODEX_INTERNAL_COMMANDS.includes(value)) ? "internal" : null;
68
+ }
69
+ return null;
70
+ }
71
+
72
+ export const CODEX_ROUTING_NATIVE_NOTICE =
73
+ "ℹ️ Codex does not route through OpenCodex (no injected routing in ~/.codex/config.toml). Launching `codex` unchanged. Run `ocx ensure` to start the proxy and sync Codex config.";
74
+
75
+ export const CODEX_ROUTING_UNKNOWN_NOTICE =
76
+ "⚠️ Codex routing could not be verified. Ensuring the proxy is up, but the launch may not be redirected; run `ocx doctor` before relying on it.";
77
+
78
+ export const CODEX_ROUTING_CUSTOM_LOCAL_NOTICE =
79
+ "⚠️ Codex routes through a user-owned local gateway. OpenCodex does not own that route; launching `codex` unchanged. Run `ocx doctor` to verify that gateway.";
80
+
81
+ export const CODEX_ROUTING_CUSTOM_REMOTE_NOTICE =
82
+ "⚠️ Codex routes through a remote gateway. OpenCodex does not own that route; launching `codex` unchanged.";
83
+
84
+ export type CodexLaunchPlan =
85
+ | { kind: "routed" }
86
+ | { kind: "passthrough"; notice?: string; ensureProxy: boolean };
87
+
88
+ /**
89
+ * Pure launch decision from the shared routing classification:
90
+ *
91
+ * - `opencodex-local` → ensure + exec (the config this launcher exists for);
92
+ * - `native` / `custom-*` → exec unchanged, no proxy side effects;
93
+ * - `unknown` (unreadable/ambiguous config) → name it out loud and still attempt
94
+ * the ensure, because a routed session that starts without its proxy hits the
95
+ * configured URL's dead port and every request fails.
96
+ */
97
+ export function codexLaunchPlan(routingKind: CodexRoutingKind): CodexLaunchPlan {
98
+ switch (routingKind) {
99
+ case "opencodex-local":
100
+ return { kind: "routed" };
101
+ case "native":
102
+ return { kind: "passthrough", ensureProxy: false, notice: CODEX_ROUTING_NATIVE_NOTICE };
103
+ case "custom-local":
104
+ return { kind: "passthrough", ensureProxy: false, notice: CODEX_ROUTING_CUSTOM_LOCAL_NOTICE };
105
+ case "custom-remote":
106
+ return { kind: "passthrough", ensureProxy: false, notice: CODEX_ROUTING_CUSTOM_REMOTE_NOTICE };
107
+ case "unknown":
108
+ return { kind: "passthrough", ensureProxy: true, notice: CODEX_ROUTING_UNKNOWN_NOTICE };
109
+ }
110
+ }
111
+
112
+ /** Env the detached `ocx start` child inherits (service-owned admission ladder). */
113
+ export function codexProxyStartEnv(base: CodexLaunchEnv = process.env): CodexLaunchEnv {
114
+ const stripped = withoutSiblingMarker(base) as CodexLaunchEnv;
115
+ const withTokenFile = stripped.OPENCODEX_API_AUTH_TOKEN?.trim()
116
+ ? stripped
117
+ : { ...stripped, OCX_API_TOKEN_FILE: serviceApiTokenFilePath() };
118
+ return { ...withTokenFile, OCX_SERVICE: "1" } as CodexLaunchEnv;
119
+ }
120
+
121
+ export type CodexProxyEnsureDeps = {
122
+ findLiveProxy?: typeof findLiveProxy;
123
+ };
124
+
125
+ /**
126
+ * Mirrors ensureProxyForClaude (src/cli/claude.ts) — the same borrowed liveness
127
+ * retry budget (#764), detached `ocx start` on the configured port, 8 s health
128
+ * poll — so all `ocx`-launched clients share one autostart contract.
129
+ */
130
+ export async function ensureProxyForCodex(deps: CodexProxyEnsureDeps = {}): Promise<LiveProxy | null> {
131
+ const probe = deps.findLiveProxy ?? findLiveProxy;
132
+ const live = await probe({ attempts: 3 });
133
+ if (live) return live;
134
+ const cfgPort = loadConfig().port;
135
+ const pinPort = typeof cfgPort === "number" && cfgPort > 0 ? cfgPort : 10100;
136
+ const child = spawn(process.execPath, selfLaunchArgv(["start", "--port", String(pinPort)]), {
137
+ detached: true,
138
+ stdio: "ignore",
139
+ windowsHide: true,
140
+ // An ordinary owner: a stray sibling marker would otherwise mark it before any probe.
141
+ env: withProcessRuntimeProvenance(codexProxyStartEnv(process.env) as NodeJS.ProcessEnv),
142
+ });
143
+ // Without a listener an 'error' (bad argv[1], EMFILE, AV denial) throws synchronously
144
+ // and kills this process; the health poll below already reports the failure properly.
145
+ child.on("error", () => { /* handled by the deadline loop returning null */ });
146
+ child.unref();
147
+ const deadline = Date.now() + 8_000;
148
+ while (Date.now() < deadline) {
149
+ const started = await probe();
150
+ if (started) return started;
151
+ await new Promise(resolve => setTimeout(resolve, 250));
152
+ }
153
+ return null;
154
+ }
155
+
156
+ export type CodexLaunchEnvDeps = {
157
+ routingKind?: CodexRoutingKind;
158
+ args?: readonly string[];
159
+ /** Test seam; production reads the hardened service token file. */
160
+ serviceToken?: (base: CodexLaunchEnv) => string | null;
161
+ credentialDestination?: (home: string, report?: CodexTokenRefusalReporter) => boolean;
162
+ };
163
+
164
+ /** Read the client admission credential from this installation's service-token file. */
165
+ const defaultServiceToken = (base: CodexLaunchEnv): string | null =>
166
+ loadServiceTokenFromFile({ ...base, OCX_API_TOKEN_FILE: serviceApiTokenFilePath() });
167
+
168
+ /**
169
+ * Launch env for a routed exec. The one injection is the shim's own: a missing
170
+ * OPENCODEX_API_AUTH_TOKEN is re-exported from the hardened service token file, so
171
+ * `ocx codex` from a shell without the system-env snapshot authenticates to the
172
+ * loopback proxy like a shimmed launch does. Fresh credentials require explicit
173
+ * argv/env/config allowlists, an exclusive managed provider and protected home/system
174
+ * configuration namespaces. User exports always win.
175
+ */
176
+ export function buildCodexLaunchEnv(
177
+ base: CodexLaunchEnv = process.env,
178
+ deps: CodexLaunchEnvDeps = {},
179
+ ): CodexLaunchEnv {
180
+ const env = { ...base };
181
+ if (deps.routingKind !== undefined && deps.routingKind !== "opencodex-local") return env;
182
+ if (!env.OPENCODEX_API_AUTH_TOKEN?.trim()) {
183
+ const withhold = (reason: CodexTokenRefusal): CodexLaunchEnv => {
184
+ console.error(codexTokenWithheldDiagnostic(reason));
185
+ return env;
186
+ };
187
+ if (!codexTokenArgsAreSafe(deps.args ?? [])) return withhold("args");
188
+ if (!codexTokenEnvironmentIsSafe(env)) return withhold("environment");
189
+ // NO_PROXY parsing and precedence vary across native HTTP/WebSocket transports.
190
+ // Without proving bypass, preserve the user's transport but never load a secret.
191
+ const home = resolveCodexLaunchHome(env);
192
+ if (!home) return withhold("home");
193
+ let refusal: CodexTokenRefusal = "destination";
194
+ const report: CodexTokenRefusalReporter = reason => { refusal = reason; };
195
+ const trusted = deps.credentialDestination
196
+ ? deps.credentialDestination(home, report)
197
+ : codexCredentialDestinationIsTrusted(home, undefined, report);
198
+ if (!trusted) return withhold(refusal);
199
+ const token = (deps.serviceToken ?? defaultServiceToken)(env);
200
+ if (!token) return withhold("credential");
201
+ if (tokenCollidesWithAdmin(token, env)) return withhold("collision");
202
+ // Reqwest's default transport can discover OS proxies even without proxy
203
+ // env. Bind both bypass spellings to the allowed loopback hosts, preserving
204
+ // existing entries and removing conflicting case aliases before handoff.
205
+ const bypass = ["127.0.0.1", "::1"];
206
+ for (const key of Object.keys(env)) if (/^no_proxy$/i.test(key)) {
207
+ if (env[key]) bypass.push(env[key]!);
208
+ delete env[key];
209
+ }
210
+ env.NO_PROXY = env.no_proxy = bypass.join(",");
211
+ env.CODEX_HOME = home;
212
+ env.OPENCODEX_API_AUTH_TOKEN = token;
213
+ }
214
+ return env;
215
+ }
216
+
217
+ const CODEX_INSTALL_HINT = "❌ `codex` CLI not found. Install it first: npm install -g @openai/codex";
218
+ class CodexNotFoundError extends Error {}
219
+
220
+ /**
221
+ * cmd.exe reports command-not-found as exit 9009 (the win32 launcher routes `.cmd`
222
+ * shims through cmd.exe, so ENOENT never fires there). Signal exits are not hints.
223
+ * Same contract as claudeNotFoundHint (devlog 260715_cross_platform_audit/020).
224
+ */
225
+ export function codexNotFoundHint(
226
+ code: number | null,
227
+ signal: NodeJS.Signals | null,
228
+ platform: NodeJS.Platform = process.platform,
229
+ ): string | null {
230
+ return platform === "win32" && code === 9009 && !signal ? CODEX_INSTALL_HINT : null;
231
+ }
232
+
233
+ export type CodexLaunchCommandDeps = {
234
+ findOnPath?: (name: string) => string | null;
235
+ inspectShim?: typeof inspectCodexShimBackingForCommand;
236
+ verifyBypass?: typeof codexCommandCanBypass;
237
+ };
238
+
239
+ export type CodexLaunchCommand = { command: string; env: CodexLaunchEnv };
240
+
241
+ /**
242
+ * The launcher has already made the ensure decision, so the generated autostart shim
243
+ * must not make it again: on a passthrough plan it would start the proxy and load the
244
+ * admission token anyway. When `codex` resolves to a recorded shim wrapper, exec its
245
+ * backing Codex directly. Unknown state requires a separate bypass-content check;
246
+ * obsolete or unverifiable Windows wrappers fail closed before starting any child.
247
+ */
248
+ export function resolveCodexLaunchCommand(
249
+ env: CodexLaunchEnv,
250
+ deps: CodexLaunchCommandDeps = {},
251
+ ): CodexLaunchCommand {
252
+ try {
253
+ const selected = (deps.findOnPath ?? findExecutableOnPath)("codex");
254
+ if (!selected) throw new CodexNotFoundError(CODEX_INSTALL_HINT);
255
+ let shim: ReturnType<typeof inspectCodexShimBackingForCommand>;
256
+ try { shim = (deps.inspectShim ?? inspectCodexShimBackingForCommand)(selected); }
257
+ catch { shim = { status: "unknown", reason: "binding_unavailable" }; }
258
+ if (shim.status === "matched" && shim.selectedRole === "wrapper") return { command: shim.backingPath, env };
259
+ if (shim.status !== "unknown") return { command: selected, env };
260
+ if (!(deps.verifyBypass ?? codexCommandCanBypass)(selected, env)) throw new Error(CODEX_UNVERIFIED_SHIM);
261
+ return { command: selected, env: { ...env, OCX_SHIM_BYPASS: "1" } };
262
+ } catch (error) {
263
+ if (error instanceof CodexNotFoundError) throw error;
264
+ throw new Error(CODEX_UNVERIFIED_SHIM);
265
+ }
266
+ }
267
+
268
+ /** Launch the selected Codex command with inherited IO and preserve its exit status. */
269
+ function spawnCodex(args: readonly string[], env: CodexLaunchEnv): Promise<number> {
270
+ return new Promise<number>(resolve => {
271
+ let launch: CodexLaunchCommand;
272
+ try { launch = resolveCodexLaunchCommand(env); }
273
+ catch (error) { console.error(error instanceof CodexNotFoundError ? CODEX_INSTALL_HINT : CODEX_UNVERIFIED_SHIM); resolve(1); return; }
274
+ const inv = commandInvocation(launch.command, args);
275
+ const child = spawn(inv.file, inv.args, { stdio: "inherit", env: launch.env as NodeJS.ProcessEnv, ...inv.options });
276
+ child.on("error", (err: NodeJS.ErrnoException) => {
277
+ if (err.code === "ENOENT") {
278
+ console.error(CODEX_INSTALL_HINT);
279
+ } else {
280
+ console.error(`❌ Failed to launch codex: ${err.message}`);
281
+ }
282
+ resolve(1);
283
+ });
284
+ child.on("exit", (code, signal) => {
285
+ const hint = codexNotFoundHint(code, signal);
286
+ if (hint) console.error(hint);
287
+ resolve(signal ? 1 : code ?? 0);
288
+ });
289
+ });
290
+ }
291
+
292
+ /** Apply the argument/routing plan, then hand the original arguments to Codex. */
293
+ export async function cmdCodex(args: string[]): Promise<number> {
294
+ if (codexFastPathReason(args) !== null) return spawnCodex(args, { ...process.env });
295
+ const routingKind = getCodexRoutingKind();
296
+ const plan = codexLaunchPlan(routingKind);
297
+ const notice = plan.kind === "passthrough" ? plan.notice : undefined;
298
+ if (notice) console.error(notice);
299
+ const needsProxy = plan.kind === "routed"
300
+ || (plan.kind === "passthrough" && plan.ensureProxy);
301
+ if (!needsProxy) return spawnCodex(args, { ...process.env });
302
+ const live = await ensureProxyForCodex();
303
+ if (!live) {
304
+ // A failed ensure warns and continues, subject to executable verification.
305
+ // The already-injected config decides
306
+ // what the session does next; `ocx doctor` names the autostart failure.
307
+ console.error(CODEX_SHIM_ENSURE_FAILED_DIAGNOSTIC);
308
+ }
309
+ return spawnCodex(args, buildCodexLaunchEnv(process.env, { routingKind, args }));
310
+ }
@@ -19,6 +19,8 @@ const DEFAULT_DEPS: CodexShimAutoRestoreCliDeps = {
19
19
  export function skipsCodexShimAutoRestore(command: string | undefined, args: string[]): boolean {
20
20
  if (command === "uninstall" || command === "remove") return true;
21
21
  if (command === "status" || command === "doctor") return true;
22
+ // The launcher owns shim handoff after classifying routing, including native fast paths.
23
+ if (command === "codex") return true;
22
24
  // `lab` is read-only inspection; it must not trigger shim side effects.
23
25
  if (command === "lab") return true;
24
26
  // Local messaging owns its helpers; even malformed usage must not repair/start anything.
@@ -1,6 +1,8 @@
1
1
  import { readFileSync, writeFileSync } from "node:fs";
2
2
  import { clearCodexAccountPin } from "../codex/account-priority";
3
3
  import { getConfigPath, mutatePersistedConfig, readConfigDiagnostics, sanitizeModelCostsForDisplay, saveConfig, validateConfigCandidate } from "../config";
4
+ import { getConfigDir, withConfigDirHardeningSettled } from "../config/paths";
5
+ import { readCliConfigForMutation } from "./config-mutation";
4
6
  import { VISION_REASONING_EFFORTS, isVisionReasoningEffort } from "../reasoning-effort";
5
7
  import type { OcxConfig } from "../types";
6
8
  import { normalizeVisionReasoningForModel } from "../vision/reasoning";
@@ -260,7 +262,7 @@ export async function handleConfigCommand(argv: string[]): Promise<number> {
260
262
  // `mutatePersistedConfig` reruns this callback against the latest validated disk
261
263
  // state, so the operation is applied to what is actually there at commit time.
262
264
  let savedValue: unknown = null;
263
- const outcome = mutatePersistedConfig(fresh => {
265
+ const outcome = await withConfigDirHardeningSettled(getConfigDir(), () => mutatePersistedConfig(fresh => {
264
266
  // Snapshot BEFORE mutating: comparing after the write compares a value with
265
267
  // itself and would report every no-op as a change, bumping the generation.
266
268
  const before = JSON.stringify(fresh);
@@ -285,9 +287,9 @@ export async function handleConfigCommand(argv: string[]): Promise<number> {
285
287
  }
286
288
  Object.assign(fresh, config);
287
289
  return { changed: JSON.stringify(fresh) !== before, value: undefined };
288
- });
290
+ }));
289
291
  if (outcome.status === "unavailable") {
290
- throw new Error(outcome.reason === "conflict"
292
+ throw new CliUsageError(outcome.reason === "conflict"
291
293
  ? "config changed while applying this update; retry"
292
294
  : `config is ${outcome.reason}`);
293
295
  }
@@ -327,7 +329,10 @@ export async function handleConfigCommand(argv: string[]): Promise<number> {
327
329
  if (!path) throw new CliUsageError("import path is required", USAGE);
328
330
  if (!yes) throw new CliUsageError("import requires --yes", USAGE);
329
331
  rejectArgs(args, USAGE);
330
- saveConfig(validate(loadInput(path)));
332
+ await withConfigDirHardeningSettled(getConfigDir(), () => {
333
+ readCliConfigForMutation();
334
+ saveConfig(validate(loadInput(path)));
335
+ });
331
336
  printData({ ok: true, source: path }, wantsJson, [`Imported config from ${path}. Restart or run ocx sync if needed.`]);
332
337
  return;
333
338
  }
@@ -0,0 +1,13 @@
1
+ import { readConfigDiagnostics } from "../config/diagnostics";
2
+ import type { OcxConfig } from "../types";
3
+ import { CliUsageError } from "./runtime-api";
4
+
5
+ /** Inside admission unless this is a passive preliminary selection read. */
6
+ export function readCliConfigForMutation(options: { passive?: boolean } = {}): OcxConfig {
7
+ const diagnostics = readConfigDiagnostics(options);
8
+ if (diagnostics.source === "fallback" || diagnostics.error) {
9
+ throw new CliUsageError("config.json is invalid or unreadable; run ocx config validate and repair it before retrying. Nothing was saved.");
10
+ }
11
+ // Fresh installs retain the full-config commands' existing default initialization.
12
+ return diagnostics.config;
13
+ }
@@ -10,6 +10,7 @@ import type { ProxyRestartStartOutcome } from "./tray-proxy";
10
10
  * never needs to import the entry module back (no cycle).
11
11
  */
12
12
  import { CLI_COMMANDS } from "./registry";
13
+ import { runCliAction } from "./runtime-api";
13
14
  import { uninstallArgsError, type CliHead } from "./root";
14
15
  import type { ReadyArgs } from "./ready";
15
16
  import type { LivenessIo, LiveProxy } from "../server/proxy-liveness";
@@ -82,9 +83,10 @@ export function selectDefaultGuiUrl(
82
83
  const ingress = config.runtimeRole === "hub" ? config.hub?.managementIngress : undefined;
83
84
  if (ingress?.enabled) return `http://127.0.0.1:${ingress.port}`;
84
85
 
86
+ // Keep literal loopback addresses: standalone pairing admits the configured
87
+ // origin, so replacing 127.0.0.1 with localhost strands its browser flow.
85
88
  const guiHost = probeHostname(live?.hostname ?? config.hostname);
86
- const hostname = guiHost === "127.0.0.1" ? "localhost" : guiHost;
87
- return `http://${hostname}:${live?.port ?? config.port ?? 10100}`;
89
+ return `http://${guiHost}:${live?.port ?? config.port ?? 10100}`;
88
90
  }
89
91
 
90
92
  const commandRunners: Record<string, CommandRunner> = {
@@ -546,7 +548,7 @@ const commandRunners: Record<string, CommandRunner> = {
546
548
  },
547
549
  config,
548
550
  port: live.port,
549
- }, ["mcode", "pi", "raycast", "omo", "cline", "commandcode", "droid", "opencode", "kilo", "qoder", "qoder-cn", "workbuddy", "workbuddy-ai"]));
551
+ }, ["mcode", "pi", "raycast", "omo", "cline", "commandcode", "droid", "opencode", "kilo", "qoder", "qoder-cn", "workbuddy", "workbuddy-ai", "hermes", "t3code"]));
550
552
  } catch (error) {
551
553
  console.warn(`Client integrations were not refreshed: ${error instanceof Error ? error.message : String(error)}`);
552
554
  }
@@ -869,12 +871,12 @@ const commandRunners: Record<string, CommandRunner> = {
869
871
  // Reset first, like the service runner below: reading process.exitCode only
870
872
  // reports THIS command's outcome if nothing earlier in the process set it.
871
873
  process.exitCode = 0;
872
- await handleProviderCommand(deps.args.slice(1));
874
+ const code = await runCliAction(() => handleProviderCommand(deps.args.slice(1)));
873
875
  // handleProviderCommand reports failure through process.exitCode, which it sets
874
876
  // from handleProviderRuntimeCommand. Returning a literal 0 here made index.ts
875
877
  // call process.exit(0) and erase it, so `ocx provider quota` against a stopped
876
878
  // proxy printed an error and still exited 0 (#2697).
877
- return Number(process.exitCode ?? 0);
879
+ return code || Number(process.exitCode ?? 0);
878
880
  },
879
881
  account: async deps => {
880
882
  const { cmdAccount } = await import("./account");
@@ -883,10 +885,10 @@ const commandRunners: Record<string, CommandRunner> = {
883
885
  models: async deps => {
884
886
  const { handleModels } = await import("./models");
885
887
  process.exitCode = 0;
886
- await handleModels(deps.args.slice(1));
888
+ const code = await runCliAction(() => handleModels(deps.args.slice(1)));
887
889
  // Same as the provider runner above: handleModels sets process.exitCode from
888
890
  // handleModelsRuntimeCommand, and a literal 0 discarded it (#2697).
889
- return Number(process.exitCode ?? 0);
891
+ return code || Number(process.exitCode ?? 0);
890
892
  },
891
893
  alias: async deps => {
892
894
  const { handleAliasCommand } = await import("./alias");
@@ -1038,6 +1040,10 @@ const commandRunners: Record<string, CommandRunner> = {
1038
1040
  }
1039
1041
  return await cmdClaude(deps.args.slice(1));
1040
1042
  },
1043
+ codex: async deps => {
1044
+ const { cmdCodex } = await import("./codex-launcher");
1045
+ return await cmdCodex(deps.args.slice(1));
1046
+ },
1041
1047
  opencode: async deps => {
1042
1048
  const { cmdOpencode } = await import("./opencode");
1043
1049
  return await cmdOpencode(deps.args.slice(1));
package/src/cli/effort.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { loadConfig, saveConfig } from "../config";
2
+ import { readCliConfigForMutation } from "./config-mutation";
3
+ import { getConfigDir, withConfigDirHardeningSettled } from "../config/paths";
2
4
  import {
3
5
  CODEX_REASONING_LEVELS,
4
6
  configuredReasoningEfforts,
@@ -232,20 +234,23 @@ async function setEffort(
232
234
  }
233
235
 
234
236
  // Offline persistence path: only reached when no live proxy was found before mutation
235
- const config = loadConfig();
236
- if (validatedMain !== undefined) {
237
- if (validatedMain === null) delete config.effortCap;
238
- else config.effortCap = validatedMain;
239
- }
240
- if (validatedSubagent !== undefined) {
241
- if (validatedSubagent === null) delete config.subagentEffortCap;
242
- else config.subagentEffortCap = validatedSubagent;
243
- }
244
- if (validatedInjection !== undefined) {
245
- if (validatedInjection === null) delete config.injectionEffort;
246
- else config.injectionEffort = validatedInjection;
247
- }
248
- saveConfig(config);
237
+ const config = await withConfigDirHardeningSettled(getConfigDir(), () => {
238
+ const config = readCliConfigForMutation();
239
+ if (validatedMain !== undefined) {
240
+ if (validatedMain === null) delete config.effortCap;
241
+ else config.effortCap = validatedMain;
242
+ }
243
+ if (validatedSubagent !== undefined) {
244
+ if (validatedSubagent === null) delete config.subagentEffortCap;
245
+ else config.subagentEffortCap = validatedSubagent;
246
+ }
247
+ if (validatedInjection !== undefined) {
248
+ if (validatedInjection === null) delete config.injectionEffort;
249
+ else config.injectionEffort = validatedInjection;
250
+ }
251
+ saveConfig(config);
252
+ return config;
253
+ });
249
254
 
250
255
  const result = {
251
256
  ok: true,
@@ -1,3 +1,4 @@
1
+ import { getConfigDir as configRoot, withConfigDirHardeningSettled as settleConfigRoot } from "../config/paths";
1
2
  /**
2
3
  * Align Grok and Claude Desktop files with the durable switches during `ocx ensure`.
3
4
  *
@@ -9,6 +10,7 @@
9
10
  * each external-file mutation, and use that current config for sync inputs.
10
11
  */
11
12
  import { loadConfig } from "../config";
13
+ import { readConfigForAdmittedMutation } from "../config/persisted-mutation";
12
14
  import { cliFirstPartyDesired, firstPartyDesired, reconcileClaudeFirstPartySettings } from "../claude/first-party-settings";
13
15
  import { getConfigDir } from "../config/paths";
14
16
  import { claudeInterceptEnabled } from "../claude/intercept/runtime";
@@ -46,7 +48,7 @@ export interface EnsureDesiredIntegrationsDeps {
46
48
  syncGrokConfig: (
47
49
  port: number,
48
50
  config: OcxConfig,
49
- opts?: { hostname?: string },
51
+ opts?: { hostname?: string; probeHostname?: string },
50
52
  ) => Promise<GrokInjectResult>;
51
53
  removeDesktop3pStandardPivot: typeof removeDesktop3pStandardPivot;
52
54
  removeDesktopFirstParty?: typeof removeDesktopFirstParty;
@@ -65,7 +67,7 @@ export interface EnsureDesiredIntegrationsDeps {
65
67
  async function defaultSyncGrokConfig(
66
68
  port: number,
67
69
  config: OcxConfig,
68
- opts: { hostname?: string } = {},
70
+ opts: { hostname?: string; probeHostname?: string } = {},
69
71
  ): Promise<GrokInjectResult> {
70
72
  const { syncGrokConfig } = await import("../grok/sync");
71
73
  return syncGrokConfig(port, config, opts);
@@ -98,7 +100,7 @@ function io(deps: EnsureDesiredIntegrationsDeps): {
98
100
  */
99
101
  export async function ensureGrokFenceMatchesDesired(
100
102
  port: number,
101
- opts: { hostname?: string } = {},
103
+ opts: { hostname?: string; probeHostname?: string } = {},
102
104
  deps: EnsureDesiredIntegrationsDeps = productionDeps,
103
105
  ): Promise<void> {
104
106
  const config = deps.loadConfig();
@@ -130,7 +132,8 @@ export async function ensureGrokFenceMatchesDesired(
130
132
  const g = await deps.syncGrokConfig(
131
133
  port,
132
134
  config,
133
- hostname !== undefined ? { hostname } : {},
135
+ { ...(hostname !== undefined ? { hostname } : {}),
136
+ ...(opts.probeHostname !== undefined ? { probeHostname: opts.probeHostname } : {}) },
134
137
  );
135
138
  if (g.changed) log(" + Grok Build config updated (~/.grok/config.toml)");
136
139
  else if (!g.ok) error(`⚠️ ${g.message}`);
@@ -151,13 +154,16 @@ export async function ensureClaudeDesktopMatchesDesired(
151
154
  deps: EnsureDesiredIntegrationsDeps = productionDeps,
152
155
  ): Promise<void> {
153
156
  const config = deps.loadConfig();
157
+ const readCurrent = () => deps.loadConfig === loadConfig ? readConfigForAdmittedMutation() : deps.loadConfig();
154
158
  const { log, error } = io(deps);
155
159
  if (cliFirstPartyDesired(config)) {
156
160
  const seen = (deps.inspectDesktopFirstParty ?? inspectDesktopFirstParty)(config);
157
161
  if (seen.settings.kind === "absent" || seen.stale || !claudeInterceptEnabled(config)) {
158
- const result = await withFirstPartySecretsSettled(getConfigDir(), () =>
159
- (deps.reconcileClaudeFirstPartySettings ?? reconcileClaudeFirstPartySettings)(config,
160
- firstPartyDesired(config, (deps.observeClaudeDesktopMode ?? observeClaudeDesktopMode)(config))));
162
+ const result = await withFirstPartySecretsSettled(getConfigDir(), () => {
163
+ const current = readCurrent();
164
+ return (deps.reconcileClaudeFirstPartySettings ?? reconcileClaudeFirstPartySettings)(current,
165
+ firstPartyDesired(current, (deps.observeClaudeDesktopMode ?? observeClaudeDesktopMode)(current)));
166
+ });
161
167
  if (result.ok && result.changed) log(` + Claude CLI first-party env refreshed (${result.path})`);
162
168
  else if (!result.ok) error(`⚠️ Claude CLI first-party env refresh skipped: ${result.reason}.`);
163
169
  }
@@ -175,7 +181,7 @@ export async function ensureClaudeDesktopMatchesDesired(
175
181
  }
176
182
  const seen = (deps.inspectDesktopFirstParty ?? inspectDesktopFirstParty)(config);
177
183
  if (!seen.stale) return;
178
- const applied = await withFirstPartySecretsSettled(getConfigDir(), () => (deps.applyDesktopFirstParty ?? applyDesktopFirstParty)(config));
184
+ const applied = await withFirstPartySecretsSettled(getConfigDir(), () => (deps.applyDesktopFirstParty ?? applyDesktopFirstParty)(readCurrent()));
179
185
  if (applied.ok && applied.changed) log(` + Claude Desktop first-party env refreshed (${applied.path})`);
180
186
  else if (!applied.ok) error(`⚠️ Claude Desktop first-party env refresh skipped: ${applied.reason}.`);
181
187
  return;
@@ -207,9 +213,9 @@ export async function ensureClaudeDesktopMatchesDesired(
207
213
  error(`⚠️ Claude Desktop first-party env cleanup failed: ${detail}.`);
208
214
  }
209
215
  try {
210
- const removed = deps.removeDesktop3pStandardPivot({
211
- appliedFingerprint: config.claudeCode?.desktopProfile?.appliedFingerprint ?? null,
212
- });
216
+ const removed = await settleConfigRoot(configRoot(), () => deps.removeDesktop3pStandardPivot({
217
+ appliedFingerprint: readCurrent().claudeCode?.desktopProfile?.appliedFingerprint ?? null,
218
+ }));
213
219
  if (removed.ok && removed.changed) {
214
220
  log(" ↩️ Claude Desktop integration residue removed.");
215
221
  } else if (!removed.ok) {
@@ -222,12 +228,12 @@ export async function ensureClaudeDesktopMatchesDesired(
222
228
  }
223
229
 
224
230
  export type EnsureDesiredIntegrationsBranch =
225
- | { kind: "live"; hostname?: string }
231
+ | { kind: "live"; hostname?: string; probeHostname?: string }
226
232
  | { kind: "spawned" };
227
233
 
228
234
  /**
229
235
  * Reconcile the two external integration files after either ensure race window.
230
- * Only the live proxy's observed bind host crosses this boundary; persisted
236
+ * The live proxy's bind scope and responding address cross this boundary; persisted
231
237
  * config is deliberately loaded inside each mutation helper.
232
238
  */
233
239
  export async function reconcileEnsureDesiredIntegrations(
@@ -238,7 +244,8 @@ export async function reconcileEnsureDesiredIntegrations(
238
244
  const liveHost = branch.kind === "live" ? branch.hostname : undefined;
239
245
  await ensureGrokFenceMatchesDesired(
240
246
  port,
241
- liveHost ? { hostname: liveHost } : {},
247
+ { ...(liveHost ? { hostname: liveHost } : {}),
248
+ ...(branch.kind === "live" && branch.probeHostname !== undefined ? { probeHostname: branch.probeHostname } : {}) },
242
249
  deps,
243
250
  );
244
251
  await ensureClaudeDesktopMatchesDesired(deps);