@bitkyc08/opencodex 2.93.0 → 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-BXu4zE8H.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-CizjBqyk.js +0 -58
  433. package/gui/dist/assets/Tray-DamiMqcX.js +0 -1
  434. package/gui/dist/assets/index-DQsht3vH.js +0 -94
  435. package/gui/dist/assets/index-DRe8Hhfz.css +0 -1
@@ -0,0 +1,83 @@
1
+ import { lstatSync } from "node:fs";
2
+ import { dirname, join, relative, sep } from "node:path";
3
+
4
+ /**
5
+ * Launch and restore execute code from a discovered bundle, so the bundle must be
6
+ * OpenAI-signed and pass ownership/permission checks along its filesystem path. Bundle
7
+ * identifier alone (what discovery checks) is plain text in Info.plist that anyone can copy.
8
+ */
9
+ export const OPENAI_TEAM_ID = "2DC432GLL2";
10
+
11
+ export interface BundleTrustDeps {
12
+ readonly uid: number;
13
+ readonly adminGroupId?: number;
14
+ stat(path: string): { uid: number; gid?: number; mode: number; isFile: boolean; isDirectory: boolean; isSymbolicLink: boolean } | null;
15
+ codesign(args: readonly string[]): { status: number | null; output: string };
16
+ }
17
+
18
+ export interface AsyncBundleTrustDeps extends Omit<BundleTrustDeps, "codesign"> {
19
+ codesign(args: readonly string[], signal?: AbortSignal): Promise<{ status: number | null; output: string }>;
20
+ }
21
+
22
+ export function bundleTrustStat(path: string): ReturnType<BundleTrustDeps["stat"]> {
23
+ try {
24
+ const s = lstatSync(path);
25
+ return { uid: s.uid, gid: s.gid, mode: s.mode, isFile: s.isFile(), isDirectory: s.isDirectory(), isSymbolicLink: s.isSymbolicLink() };
26
+ } catch { return null; }
27
+ }
28
+
29
+ type FilesystemTrustDeps = Omit<BundleTrustDeps, "codesign">;
30
+
31
+ function ownedSafely(deps: FilesystemTrustDeps, path: string, kind: "file" | "directory"): string | null {
32
+ const s = deps.stat(path);
33
+ if (!s) return "is missing";
34
+ if (s.isSymbolicLink) return "is a symbolic link";
35
+ if (kind === "file" ? !s.isFile : !s.isDirectory) return `is not a ${kind}`;
36
+ if (s.uid !== 0 && s.uid !== deps.uid) return "is owned by another user";
37
+ if ((s.mode & 0o022) !== 0) return "is writable by group or others";
38
+ return null;
39
+ }
40
+
41
+ /** Protect the bundle's directory entry all the way to the filesystem root. */
42
+ function untrustedAncestorReason(bundleRoot: string, deps: FilesystemTrustDeps): string | null {
43
+ for (let dir = dirname(bundleRoot); ; dir = dirname(dir)) {
44
+ const s = deps.stat(dir);
45
+ if (!s || !s.isDirectory || s.isSymbolicLink) return `${dir} is not a regular ancestor directory`;
46
+ if (s.uid !== 0 && s.uid !== deps.uid) return `${dir} is owned by another user`;
47
+ // A trusted sticky parent protects the already-checked child from replacement.
48
+ // Root-owned admin-group install containers are privileged OS-controlled paths;
49
+ // resolve that group from the local directory service rather than assuming a GID.
50
+ const sticky = (s.mode & 0o1000) !== 0;
51
+ const privileged = s.uid === 0 && (s.mode & 0o002) === 0
52
+ && deps.adminGroupId !== undefined && s.gid === deps.adminGroupId;
53
+ if ((s.mode & 0o022) !== 0 && !sticky && !privileged) return `${dir} is writable by group or others`;
54
+ if (dirname(dir) === dir) return null;
55
+ }
56
+ }
57
+
58
+ /** Shared filesystem policy; the callers separately verify both code signatures. */
59
+ export function untrustedBundleFilesystemReason(
60
+ bundleRoot: string,
61
+ binary: string | undefined = undefined,
62
+ deps: FilesystemTrustDeps,
63
+ ): string | null {
64
+ const label = binary === undefined ? "app executable" : "app-server binary";
65
+ binary ??= join(bundleRoot, "Contents", "MacOS", "ChatGPT");
66
+ const inside = relative(join(bundleRoot, "Contents"), binary);
67
+ if (!inside || inside.startsWith("..") || inside.startsWith(sep)) return `the ${label} is outside the bundle`;
68
+ const fileProblem = ownedSafely(deps, binary, "file");
69
+ if (fileProblem) return `the ${label} ${fileProblem}`;
70
+ for (let dir = dirname(binary); ; dir = dirname(dir)) {
71
+ const dirProblem = ownedSafely(deps, dir, "directory");
72
+ if (dirProblem) return `${dir} ${dirProblem}`;
73
+ if (dir === bundleRoot || dirname(dir) === dir) break;
74
+ }
75
+ const ancestorProblem = untrustedAncestorReason(bundleRoot, deps);
76
+ if (ancestorProblem) return ancestorProblem;
77
+ return null;
78
+ }
79
+
80
+ export function bundleSignatureDetailsReason(target: string, details: { status: number | null; output: string }): string | null {
81
+ return details.status !== 0 || !new RegExp(`^TeamIdentifier=${OPENAI_TEAM_ID}$`, "m").test(details.output)
82
+ ? `${target} is not signed by OpenAI (team ${OPENAI_TEAM_ID})` : null;
83
+ }
@@ -1,23 +1,15 @@
1
1
  import { spawnSync } from "node:child_process";
2
- import { lstatSync } from "node:fs";
3
- import { dirname, join, relative, sep } from "node:path";
2
+ import { join } from "node:path";
3
+ import { bundleSignatureDetailsReason, bundleTrustStat, untrustedBundleFilesystemReason, type BundleTrustDeps } from "./bundle-trust-policy";
4
4
 
5
- /**
6
- * Launch and restore execute code from a discovered bundle, so the bundle must be
7
- * OpenAI-signed and pass ownership/permission checks along its filesystem path. Bundle
8
- * identifier alone (what discovery checks) is plain text in Info.plist that anyone can copy.
9
- */
10
- export const OPENAI_TEAM_ID = "2DC432GLL2";
5
+ export { OPENAI_TEAM_ID, bundleSignatureDetailsReason, bundleTrustStat, untrustedBundleFilesystemReason } from "./bundle-trust-policy";
6
+ export type { BundleTrustDeps } from "./bundle-trust-policy";
11
7
 
12
8
  const CODESIGN = "/usr/bin/codesign";
13
9
  const CODESIGN_TIMEOUT_MS = 30_000;
14
10
 
15
- export interface BundleTrustDeps {
16
- readonly uid: number;
17
- readonly adminGroupId?: number;
18
- stat(path: string): { uid: number; gid?: number; mode: number; isFile: boolean; isDirectory: boolean; isSymbolicLink: boolean } | null;
19
- codesign(args: readonly string[]): { status: number | null; output: string };
20
- }
11
+ export { defaultAsyncBundleTrustDeps, untrustedChatgptBundleReasonAsync } from "./bundle-trust-async";
12
+ export type { AsyncBundleTrustDeps, TrustCommandSpawn } from "./bundle-trust-async";
21
13
 
22
14
  export function defaultBundleTrustDeps(): BundleTrustDeps {
23
15
  const admin = spawnSync("/usr/bin/dscl", [".", "-read", "/Groups/admin", "PrimaryGroupID"], {
@@ -27,14 +19,7 @@ export function defaultBundleTrustDeps(): BundleTrustDeps {
27
19
  return {
28
20
  adminGroupId: adminId === undefined ? undefined : Number(adminId),
29
21
  uid: typeof process.getuid === "function" ? process.getuid() : -1,
30
- stat(path) {
31
- try {
32
- const s = lstatSync(path);
33
- return { uid: s.uid, gid: s.gid, mode: s.mode, isFile: s.isFile(), isDirectory: s.isDirectory(), isSymbolicLink: s.isSymbolicLink() };
34
- } catch {
35
- return null;
36
- }
37
- },
22
+ stat: bundleTrustStat,
38
23
  codesign(args) {
39
24
  const result = spawnSync(CODESIGN, [...args], { encoding: "utf8", timeout: CODESIGN_TIMEOUT_MS });
40
25
  return { status: result.status, output: `${result.stdout ?? ""}${result.stderr ?? ""}` };
@@ -42,66 +27,24 @@ export function defaultBundleTrustDeps(): BundleTrustDeps {
42
27
  };
43
28
  }
44
29
 
45
- function ownedSafely(deps: BundleTrustDeps, path: string, kind: "file" | "directory"): string | null {
46
- const s = deps.stat(path);
47
- if (!s) return "is missing";
48
- if (s.isSymbolicLink) return "is a symbolic link";
49
- if (kind === "file" ? !s.isFile : !s.isDirectory) return `is not a ${kind}`;
50
- if (s.uid !== 0 && s.uid !== deps.uid) return "is owned by another user";
51
- if ((s.mode & 0o022) !== 0) return "is writable by group or others";
52
- return null;
53
- }
54
-
55
- /** Protect the bundle's directory entry all the way to the filesystem root. */
56
- function untrustedAncestorReason(bundleRoot: string, deps: BundleTrustDeps): string | null {
57
- for (let dir = dirname(bundleRoot); ; dir = dirname(dir)) {
58
- const s = deps.stat(dir);
59
- if (!s || !s.isDirectory || s.isSymbolicLink) return `${dir} is not a regular ancestor directory`;
60
- if (s.uid !== 0 && s.uid !== deps.uid) return `${dir} is owned by another user`;
61
- // A trusted sticky parent protects the already-checked child from replacement.
62
- // Root-owned admin-group install containers are privileged OS-controlled paths;
63
- // resolve that group from the local directory service rather than assuming a GID.
64
- const sticky = (s.mode & 0o1000) !== 0;
65
- const privileged = s.uid === 0 && (s.mode & 0o002) === 0
66
- && deps.adminGroupId !== undefined && s.gid === deps.adminGroupId;
67
- if ((s.mode & 0o022) !== 0 && !sticky && !privileged) return `${dir} is writable by group or others`;
68
- if (dirname(dir) === dir) return null;
69
- }
70
- }
71
-
72
30
  /**
73
- * Null when the bundle root and the selected executable may be run by this user.
74
- * Restore omits the app-server binary and validates the app shell instead, so a missing
75
- * app-server does not prevent returning to a normal launch. Otherwise returns a short reason.
76
- * Every directory from the binary up to the bundle root, and the
77
- * binary itself, must be owned by root or this user and not group/other-writable, and both the
78
- * bundle and the binary must pass strict code-signature verification under OpenAI's team ID.
79
- * Ancestors above the bundle are also checked for POSIX directory-entry replacement rights.
31
+ * Null when the bundle root and selected executable pass filesystem and OpenAI signature checks.
32
+ * Restore omits the app-server binary and validates the app shell instead. Directories and the
33
+ * binary must be owned by root or this user, non-symlink, and not group/other-writable;
34
+ * ancestors also pass POSIX directory-entry replacement checks through the filesystem root.
80
35
  */
81
36
  export function untrustedChatgptBundleReason(
82
37
  bundleRoot: string,
83
38
  binary: string | undefined = undefined,
84
39
  deps: BundleTrustDeps = defaultBundleTrustDeps(),
85
40
  ): string | null {
86
- const label = binary === undefined ? "app executable" : "app-server binary";
41
+ const filesystemProblem = untrustedBundleFilesystemReason(bundleRoot, binary, deps);
42
+ if (filesystemProblem) return filesystemProblem;
87
43
  binary ??= join(bundleRoot, "Contents", "MacOS", "ChatGPT");
88
- const inside = relative(bundleRoot, binary);
89
- if (!inside || inside.startsWith("..") || inside.startsWith(sep)) return `the ${label} is outside the bundle`;
90
- const fileProblem = ownedSafely(deps, binary, "file");
91
- if (fileProblem) return `the ${label} ${fileProblem}`;
92
- for (let dir = dirname(binary); ; dir = dirname(dir)) {
93
- const dirProblem = ownedSafely(deps, dir, "directory");
94
- if (dirProblem) return `${dir} ${dirProblem}`;
95
- if (dir === bundleRoot || dirname(dir) === dir) break;
96
- }
97
- const ancestorProblem = untrustedAncestorReason(bundleRoot, deps);
98
- if (ancestorProblem) return ancestorProblem;
99
44
  for (const target of [bundleRoot, binary]) {
100
45
  if (deps.codesign(["--verify", "--strict", target]).status !== 0) return `${target} failed code-signature verification`;
101
- const details = deps.codesign(["-dv", "--verbose=2", target]);
102
- if (details.status !== 0 || !new RegExp(`^TeamIdentifier=${OPENAI_TEAM_ID}$`, "m").test(details.output)) {
103
- return `${target} is not signed by OpenAI (team ${OPENAI_TEAM_ID})`;
104
- }
46
+ const detailsProblem = bundleSignatureDetailsReason(target, deps.codesign(["-dv", "--verbose=2", target]));
47
+ if (detailsProblem) return detailsProblem;
105
48
  }
106
49
  return null;
107
50
  }
@@ -242,6 +242,19 @@ export async function withFirstPartySecretsSettled<T>(configDir: string, prepare
242
242
  }
243
243
  }
244
244
 
245
+ /**
246
+ * Run a captured first-party rollback once overlapping ACL work settles. A settle timeout
247
+ * leaves the rollback unrun and reports it as incomplete, so callers keep their existing
248
+ * "rollback did not complete" response instead of escaping into a generic error path.
249
+ */
250
+ export async function rollbackDesktopFirstPartySettled(configDir: string, rollback: () => boolean): Promise<boolean> {
251
+ try { return await withConfigDirHardeningSettled(configDir, rollback); }
252
+ catch (error) {
253
+ if (!(error instanceof WindowsSecretAclSettleTimeoutError)) throw error;
254
+ return false;
255
+ }
256
+ }
257
+
245
258
  /**
246
259
  * Write the first-party env into Claude Code's settings. Creates the local CA first so the
247
260
  * path we point `NODE_EXTRA_CA_CERTS` at exists before Claude Code ever reads it.
@@ -284,7 +297,8 @@ export function removeDesktopFirstParty(
284
297
  * Remove Desktop's first-party env once ACL work overlapping the Claude settings home settles.
285
298
  * A `CLAUDE_CONFIG_DIR` nested in the opencodex home shares the config-root hardening flight, so
286
299
  * the credential-bearing settings rewrite gets the same admission as other intercept secrets.
287
- * The config is read inside the same synchronous turn. A settle timeout refuses without writing.
300
+ * The config is read inside the same synchronous turn. Admission, authority-read and removal
301
+ * exceptions return the existing unreadable refusal so a committed gateway remains explicit.
288
302
  */
289
303
  export async function removeDesktopFirstPartySettled(
290
304
  readConfig: () => Pick<OcxConfig, "claudeCode" | "runtimeRole">,
@@ -293,8 +307,5 @@ export async function removeDesktopFirstPartySettled(
293
307
  ): Promise<ReturnType<typeof removeDesktopFirstParty>> {
294
308
  const dir = options.claudeConfigDir ?? claudeConfigDir();
295
309
  try { return await withConfigDirHardeningSettled(dir, () => remove(readConfig(), options)); }
296
- catch (error) {
297
- if (!(error instanceof WindowsSecretAclSettleTimeoutError)) throw error;
298
- return { ok: false, reason: "unreadable", path: join(dir, "settings.json") };
299
- }
310
+ catch { return { ok: false, reason: "unreadable", path: join(dir, "settings.json") }; }
300
311
  }
@@ -29,10 +29,14 @@ export function persistCommittedDesktopGateway(
29
29
  const appliedAt = new Date().toISOString();
30
30
  try {
31
31
  const outcome = mutatePersistedConfig(current => {
32
+ if (JSON.stringify(current.claudeCode?.desktopProfile) !== JSON.stringify(profile)) {
33
+ return { changed: false, value: null };
34
+ }
32
35
  recordCommittedDesktopGateway(current, profile, fingerprint, appliedAt);
33
36
  return { changed: true, value: structuredClone(current.claudeCode) };
34
37
  });
35
38
  if (outcome.status === "unavailable") return { ok: false, reason: outcome.reason };
39
+ if (outcome.value === null) return { ok: false, reason: "conflict" };
36
40
  adoptPersistedClaudeCode(snapshot, outcome.value);
37
41
  // The mode/profile pair IS the committed transaction, not mergeable state.
38
42
  // Without an armed baseline the three-way adopt cannot prove the live leaves
@@ -0,0 +1,93 @@
1
+ import { isRec, type Rec } from "./inbound-records";
2
+
3
+ /** Provider-qualified routes, optionally ending in one prefix wildcard; never a global wildcard. */
4
+ export function isAppendOnlyToolLoadingModels(value: unknown): value is string[] {
5
+ return Array.isArray(value) && value.length <= 128 && value.every(entry =>
6
+ typeof entry === "string" && entry.length <= 512 && /^[^\s/*]+\/[^\s*]+\*?$/.test(entry));
7
+ }
8
+
9
+ export function appendOnlyToolLoadingMatches(value: unknown, model: string): boolean {
10
+ return isAppendOnlyToolLoadingModels(value) && value.some(pattern =>
11
+ pattern.endsWith("*") ? model.startsWith(pattern.slice(0, -1)) : model === pattern);
12
+ }
13
+
14
+ /** Replay client discovery in place, using only definitions still declared by this request. */
15
+ export function appendLoadedToolDefinitions(body: Rec, raw: Rec): Rec {
16
+ if (!Array.isArray(body.tools) || !Array.isArray(body.input) || !Array.isArray(raw.tools)
17
+ || !Array.isArray(raw.messages)) return body;
18
+
19
+ const declared = new Map<string, Rec>();
20
+ const deferred = new Set<string>();
21
+ for (const tool of body.tools) {
22
+ if (!isRec(tool) || tool.type !== "function" || typeof tool.name !== "string") continue;
23
+ if (declared.has(tool.name)) return body;
24
+ declared.set(tool.name, tool);
25
+ }
26
+ for (const tool of raw.tools) {
27
+ if (isRec(tool) && tool.defer_loading === true && typeof tool.name === "string") deferred.add(tool.name);
28
+ }
29
+
30
+ const calls = new Map<string, string>();
31
+ const used = new Set<string>();
32
+ const loadAt = new Map<string, string>();
33
+ for (const message of raw.messages) {
34
+ if (!isRec(message) || !Array.isArray(message.content)) continue;
35
+ for (const block of message.content) {
36
+ if (!isRec(block)) continue;
37
+ if (message.role === "assistant" && block.type === "tool_use"
38
+ && typeof block.id === "string" && typeof block.name === "string") {
39
+ if (calls.has(block.id)) return body;
40
+ calls.set(block.id, block.name);
41
+ used.add(block.name);
42
+ }
43
+ if (message.role !== "user" || block.type !== "tool_result" || block.is_error === true
44
+ || typeof block.tool_use_id !== "string" || calls.get(block.tool_use_id) !== "ToolSearch"
45
+ || !Array.isArray(block.content)) continue;
46
+ for (const reference of block.content) {
47
+ if (!isRec(reference) || reference.type !== "tool_reference" || typeof reference.tool_name !== "string") continue;
48
+ const name = reference.tool_name;
49
+ if (declared.has(name) && deferred.has(name) && !used.has(name) && !loadAt.has(name)) {
50
+ loadAt.set(name, block.tool_use_id);
51
+ }
52
+ }
53
+ }
54
+ }
55
+ // Discovery must remain callable; this optimization does not create a search capability.
56
+ if (!declared.has("ToolSearch") || deferred.has("ToolSearch")) return body;
57
+
58
+ // An ambiguous translated result cannot carry a definition safely.
59
+ const outputCounts = new Map<string, number>();
60
+ for (const item of body.input) {
61
+ if (isRec(item) && item.type === "function_call_output" && typeof item.call_id === "string") {
62
+ outputCounts.set(item.call_id, (outputCounts.get(item.call_id) ?? 0) + 1);
63
+ }
64
+ }
65
+ for (const id of loadAt.values()) if (outputCounts.get(id) !== 1) return body;
66
+
67
+ const hidden = new Set([...deferred].filter(name => declared.has(name) && (!used.has(name) || loadAt.has(name))));
68
+ // Explicit forced-tool intent takes precedence over waiting for discovery.
69
+ const choice = raw.tool_choice;
70
+ if (isRec(choice) && choice.type === "tool" && typeof choice.name === "string" && !loadAt.has(choice.name)) {
71
+ hidden.delete(choice.name);
72
+ }
73
+ if (hidden.size === 0) return body;
74
+
75
+ const additions = new Map<string, Rec[]>();
76
+ for (const [name, id] of loadAt) {
77
+ const tools = additions.get(id) ?? [];
78
+ tools.push(declared.get(name)!);
79
+ additions.set(id, tools);
80
+ }
81
+ const input: unknown[] = [];
82
+ for (const item of body.input) {
83
+ input.push(item);
84
+ if (!isRec(item) || item.type !== "function_call_output" || typeof item.call_id !== "string") continue;
85
+ const tools = additions.get(item.call_id);
86
+ if (tools) input.push({ type: "additional_tools", role: "developer", tools });
87
+ }
88
+ return {
89
+ ...body,
90
+ tools: body.tools.filter(tool => !isRec(tool) || typeof tool.name !== "string" || !hidden.has(tool.name)),
91
+ input,
92
+ };
93
+ }
@@ -34,6 +34,8 @@ export interface PickerListenerOptions {
34
34
  maxEncodedBytes?: number;
35
35
  /** Test seam: concurrent upstream requests; production uses PICKER_MAX_ACTIVE_UPSTREAMS. */
36
36
  maxActiveUpstreams?: number;
37
+ /** Test seam: no-progress time before an upstream response; never an upload lifetime cap. */
38
+ uploadIdleMs?: number;
37
39
  /**
38
40
  * Test seam: arms the drop of a connection whose backend ended, after PICKER_ABANDONED_INPUT_LINGER_MS;
39
41
  * returns a cancel function. Production uses a timer.
@@ -54,6 +56,8 @@ export const PICKER_MAX_HEADER_BYTES = 64 * 1024;
54
56
  export const PICKER_MAX_ACTIVE_UPSTREAMS = 256;
55
57
  /** Advertised per HTTP/2 connection; Chromium queues further requests rather than failing them. */
56
58
  export const PICKER_MAX_CONCURRENT_STREAMS = 100;
59
+ /** Pre-response body inactivity budget; native runtime limits remain independent. */
60
+ export const PICKER_UPLOAD_IDLE_MS = 60_000;
57
61
  /** A connection that has not sent a complete ClientHello by then is dropped. */
58
62
  const CLIENT_HELLO_TIMEOUT_MS = 10_000;
59
63
  /**
@@ -217,7 +221,11 @@ export async function startPickerListener(options: PickerListenerOptions): Promi
217
221
  // Discard further input and flush a graceful FIN without waiting for body completion.
218
222
  req.resume();
219
223
  req.socket.end();
220
- } else req.destroy();
224
+ } else {
225
+ // Bun can synthesize an empty 200 when only its request readable is destroyed.
226
+ // An unfinished upload without a reply must abort the transport instead.
227
+ req.socket.destroy();
228
+ }
221
229
  }
222
230
  };
223
231
  // An HTTP/1.1 reply sent while the upload is unfinished advertises Connection: close. Bun 1.4.3
@@ -358,9 +366,27 @@ export async function startPickerListener(options: PickerListenerOptions): Promi
358
366
  if (h2) (req as Http2ServerRequest).stream.once("close", onClientClose);
359
367
  if (uploading) {
360
368
  let uploadFinished = false;
369
+ let idleTimer: ReturnType<typeof setTimeout> | undefined;
370
+ const clearIdle = () => { if (idleTimer !== undefined) clearTimeout(idleTimer); idleTimer = undefined; };
371
+ const armIdle = () => {
372
+ clearIdle();
373
+ if (uploadFinished || upstreamResponded || req.isPaused()) return;
374
+ idleTimer = setTimeout(() => {
375
+ clientGone = true;
376
+ options.log?.("picker upload idle timeout");
377
+ stopUnfinishedUpload();
378
+ }, options.uploadIdleMs ?? PICKER_UPLOAD_IDLE_MS);
379
+ idleTimer.unref?.();
380
+ };
381
+ const noteProgress = (chunk: Buffer) => { if (chunk.length > 0) armIdle(); };
361
382
  const finishUpload = () => {
362
383
  if (uploadFinished) return;
363
384
  uploadFinished = true;
385
+ clearIdle();
386
+ req.off("data", noteProgress);
387
+ req.off("pause", clearIdle);
388
+ req.off("resume", armIdle);
389
+ upReq.off("response", clearIdle);
364
390
  req.off("end", finishUpload);
365
391
  req.off("close", finishUpload);
366
392
  upReq.off("close", onUpstreamClose);
@@ -382,12 +408,18 @@ export async function startPickerListener(options: PickerListenerOptions): Promi
382
408
  const onUpstreamClose = () => {
383
409
  if (!upstreamResponded && !res.writableEnded) stopUnfinishedUpload();
384
410
  };
411
+ // Piping pauses the readable under upstream backpressure; that is not client idleness.
412
+ req.on("data", noteProgress);
413
+ req.on("pause", clearIdle);
414
+ req.on("resume", armIdle);
415
+ upReq.once("response", clearIdle);
385
416
  req.once("end", finishUpload);
386
417
  req.once("close", finishUpload);
387
418
  upReq.once("close", onUpstreamClose);
388
419
  responseWritable.once("finish", onResponseFinish);
389
420
  res.once("close", stopUnfinishedUpload);
390
421
  if (h2) (req as Http2ServerRequest).stream.once("close", finishUpload);
422
+ armIdle();
391
423
  }
392
424
  req.pipe(upReq);
393
425
  };
@@ -21,6 +21,8 @@ import { cursorFastIdFor } from "../adapters/cursor/catalog";
21
21
  import { desktop3pAlias } from "./desktop-3p";
22
22
  import { AUTO_CONTEXT_OFF, shouldMarkOneMillion, UNPAIRED_AUTO_CONTEXT, type AutoContextMode } from "./context-windows";
23
23
  import { isAnthropicClaudeRoute } from "./long-context";
24
+ import { configuredModelDisplayName } from "../codex/catalog/model-hints";
25
+ import type { OcxConfig } from "../types";
24
26
 
25
27
  const MODEL_INFO_CREATED_AT = "2026-01-01T00:00:00Z";
26
28
  const ANTHROPIC_EFFORT_RUNGS = new Set(["low", "medium", "high", "xhigh", "max"]);
@@ -124,6 +126,19 @@ function modelInfo(
124
126
  };
125
127
  }
126
128
 
129
+ /**
130
+ * Routed-row label resolver for `buildAnthropicModelInfos`: the provider's exact
131
+ * `modelDisplayNames` entry, nothing else. `CatalogModel.displayName` is not used because it
132
+ * also carries Codex-only names (a model alias as `<provider>/<alias>`, catalog metadata), and a
133
+ * row without an operator label must keep its `<model id> (<provider>)` label.
134
+ */
135
+ export function configuredRoutedDisplayName(config: Pick<OcxConfig, "providers">): (model: CatalogModel) => string | undefined {
136
+ return model => {
137
+ const provider = config.providers[model.provider];
138
+ return provider ? configuredModelDisplayName(provider, model.id) : undefined;
139
+ };
140
+ }
141
+
127
142
  /**
128
143
  * Which id family the discovery list carries (devlog 050): Claude Code (CLI)
129
144
  * gets readable `ocx-claude-*` ids; Claude Desktop keeps its profile's
@@ -145,6 +160,9 @@ export function buildAnthropicModelInfos(
145
160
  // default install publishes nothing. The predicate answers ELIGIBILITY, not enablement.
146
161
  fastRows?: (model: CatalogModel | { provider: string; id: string }) => boolean,
147
162
  ordering?: { modelPickerOrder?: readonly string[]; featured?: readonly string[] },
163
+ // Operator label for a routed row (`providers.<p>.modelDisplayNames`); undefined keeps the
164
+ // raw-id label. Native rows never consult it, so a configured name cannot rename a native.
165
+ routedDisplayName?: (model: CatalogModel) => string | undefined,
148
166
  ): AnthropicModelInfo[] {
149
167
  const out: AnthropicModelInfo[] = [];
150
168
  const seen = new Set<string>();
@@ -214,13 +232,15 @@ export function buildAnthropicModelInfos(
214
232
  // A real model always wins its own id, whatever the iteration order.
215
233
  if (realDiscoveryIds.has(id) || seen.has(id)) return;
216
234
  seen.add(id);
217
- out.push({
235
+ const fast = {
218
236
  ...base,
219
237
  id,
220
238
  display_name: `${base.display_name} · Fast`,
221
239
  // Fast picks a different tier/variant, so the picker line says so like the name does.
222
240
  ...(base.description === undefined ? {} : { description: `${base.description} · Fast` }),
223
- });
241
+ };
242
+ out.push(fast);
243
+ return fast;
224
244
  };
225
245
  for (const slug of nativeSlugs) {
226
246
  const id = idStyle === "readable" ? claudeCodeNativeAlias(slug) : aliasForRoute("native", slug);
@@ -236,7 +256,10 @@ export function buildAnthropicModelInfos(
236
256
  push1mVariant(info, nativeWindow, nativeMaxInput);
237
257
  // Natives too, not only routed rows: gpt-5.6-sol is the flagship Fast model, and
238
258
  // omitting it would leave this surface without the model the feature exists for.
239
- if (fastRows?.({ provider: "native", id: slug }) === true) pushFastVariant(info);
259
+ if (fastRows?.({ provider: "native", id: slug }) === true) {
260
+ const fast = pushFastVariant(info);
261
+ if (fast) push1mVariant(fast, nativeWindow, nativeMaxInput);
262
+ }
240
263
  }
241
264
  const nativeEnd = out.length;
242
265
  const routedGroups = new Map<CatalogModel, AnthropicModelInfo[]>();
@@ -265,7 +288,9 @@ export function buildAnthropicModelInfos(
265
288
  : m.maxInputTokens)
266
289
  : undefined;
267
290
  const description = idStyle === "readable" ? `Routed by OpenCodex to ${m.provider}/${listedModelId}` : undefined;
268
- const info = modelInfo(id, `${listedModelId} (${m.provider})`, ladder, imageInput, routedMaxInput ?? m.contextWindow, description, m);
291
+ // The label is keyed by the raw id, so a fastMode-rewritten Cursor row keeps its listed id.
292
+ const label = (fastModelId === undefined ? routedDisplayName?.(m) : undefined) ?? listedModelId;
293
+ const info = modelInfo(id, `${label} (${m.provider})`, ladder, imageInput, routedMaxInput ?? m.contextWindow, description, m);
269
294
  out.push(info);
270
295
  // Anthropic passthrough guard (audit 021 #3): never auto-widen canonical claude
271
296
  // routes — only a genuine >=1M window earns the variant row there.
@@ -1190,28 +1190,48 @@ export async function collectAnthropicMessage(
1190
1190
  }
1191
1191
  };
1192
1192
 
1193
- try {
1194
- for (;;) {
1195
- const { done, value } = await reader.read();
1196
- if (done) break;
1197
- buffer = replaceRetained(buffer, buffer + decoder.decode(value, { stream: true }), "live_transient");
1198
- let sep: number;
1199
- while ((sep = buffer.indexOf("\n\n")) !== -1) {
1193
+ const drainFrames = () => {
1194
+ let sep: number;
1195
+ while ((sep = buffer.indexOf("\n\n")) !== -1) {
1200
1196
  const rawFrame = buffer.slice(0, sep);
1201
1197
  buffer = replaceRetained(buffer, buffer.slice(sep + 2), "live_transient");
1198
+ // Event name and data as SSE dispatches them: the last event field, untrimmed, and the
1199
+ // data fields joined by newlines.
1202
1200
  let eventName = "";
1203
- let dataLine = "";
1201
+ const dataLines: string[] = [];
1204
1202
  for (const line of rawFrame.split("\n")) {
1205
1203
  const eventValue = sseFieldValue(line, "event");
1206
- if (eventValue !== null) { eventName = eventValue.trim(); continue; }
1204
+ if (eventValue !== null) { eventName = eventValue; continue; }
1207
1205
  const dataValue = sseFieldValue(line, "data");
1208
- if (dataValue !== null) dataLine += dataValue;
1206
+ if (dataValue !== null) dataLines.push(dataValue);
1209
1207
  }
1210
- if (!eventName || !dataLine) continue;
1208
+ const dataLine = dataLines.join("\n");
1209
+ if (!dataLine) continue;
1211
1210
  let data: unknown;
1212
1211
  try { data = JSON.parse(dataLine); } catch { continue; }
1213
- if (isRec(data)) handle(eventName, data);
1214
- }
1212
+ if (!isRec(data)) continue;
1213
+ // A data-only frame is named by its payload type, the same rule the stream tap applies.
1214
+ const name = eventName || (typeof data.type === "string" ? data.type : "");
1215
+ if (name) handle(name, data);
1216
+ }
1217
+ };
1218
+
1219
+ try {
1220
+ for (;;) {
1221
+ const { done, value } = await reader.read();
1222
+ if (done) break;
1223
+ // Frame on LF only after normalizing CRLF/CR line endings, holding a trailing CR until the
1224
+ // next chunk shows whether its LF follows, so a CRLF stream folds like an LF one.
1225
+ const incoming = buffer + decoder.decode(value, { stream: true });
1226
+ const heldCr = incoming.endsWith("\r");
1227
+ const normalized = (heldCr ? incoming.slice(0, -1) : incoming).replace(/\r\n?/g, "\n") + (heldCr ? "\r" : "");
1228
+ buffer = replaceRetained(buffer, normalized, "live_transient");
1229
+ drainFrames();
1230
+ }
1231
+ // At EOF a held CR is a line ending: it can complete the final frame.
1232
+ if (buffer.endsWith("\r")) {
1233
+ buffer = replaceRetained(buffer, buffer.slice(0, -1) + "\n", "live_transient");
1234
+ drainFrames();
1215
1235
  }
1216
1236
  } finally {
1217
1237
  reader.releaseLock();
@@ -1,6 +1,7 @@
1
1
  import { isAbsolute } from "node:path";
2
2
  import { redactSecretArgs } from "./secret-args";
3
3
  import { codexExecInvocation } from "../codex/exec-invocation";
4
+ import { validatedCodexExecInvocationAsync, type CodexExecBoundaryAsyncDeps } from "../codex/exec-boundary";
4
5
  import { resolveAndPersistCodexRuntime, type ResolveCodexRuntimeDeps } from "../codex/runtime";
5
6
  import type { ResolveDeps, SpawnInvocation } from "../lib/win-exec";
6
7
  import {
@@ -46,6 +47,41 @@ export type NativeMainCodexLoginInvocationDeps =
46
47
  & ResolveDeps
47
48
  & Pick<ResolveCodexRuntimeDeps, "existsSync" | "execFileSync" | "configDir" | "readFileSync">;
48
49
 
50
+ export type NativeMainCodexLoginValidatedDeps =
51
+ & NativeMainCodexLoginInvocationDeps
52
+ & CodexExecBoundaryAsyncDeps;
53
+
54
+ /**
55
+ * Resolve+persist the runtime selection, then let the exec boundary produce the
56
+ * invocation that is spawned. Validating the raw command matters: re-wrapping
57
+ * the already-prepared invocation would launch cmd.exe as if it were Codex and
58
+ * drop windowsVerbatimArguments.
59
+ */
60
+ export async function nativeMainCodexLoginValidatedInvocation(
61
+ platform: NodeJS.Platform = process.platform,
62
+ deps: NativeMainCodexLoginValidatedDeps = {},
63
+ ): Promise<SpawnInvocation> {
64
+ const env = deps.env ?? process.env;
65
+ const command = resolveAndPersistCodexRuntime({
66
+ env,
67
+ platform,
68
+ existsSync: deps.existsSync,
69
+ execFileSync: deps.execFileSync,
70
+ configDir: deps.configDir,
71
+ readFileSync: deps.readFileSync,
72
+ discoverAlternatives: false,
73
+ }).runtime.command || "codex";
74
+ return validatedCodexExecInvocationAsync(command, ["login"], {
75
+ env,
76
+ platform,
77
+ exists: deps.exists,
78
+ executable: deps.executable,
79
+ realpath: deps.realpath,
80
+ macBundleTrustReasonAsync: deps.macBundleTrustReasonAsync,
81
+ signal: deps.signal,
82
+ });
83
+ }
84
+
49
85
  function flag(args: string[], name: string): boolean {
50
86
  const index = args.indexOf(name);
51
87
  if (index < 0) return false;
@@ -92,14 +128,16 @@ export function nativeMainCodexLoginInvocation(
92
128
  return codexExecInvocation(command, ["login"], platform, deps);
93
129
  }
94
130
 
95
- function spawnOfficialCodexLogin(codexHome: string): NativeMainLoginChild {
96
- const invocation = nativeMainCodexLoginInvocation();
97
- const child = Bun.spawn([invocation.file, ...invocation.args], {
131
+ async function spawnOfficialCodexLogin(codexHome: string): Promise<NativeMainLoginChild> {
132
+ // The boundary validates the raw resolved command and returns the invocation
133
+ // to spawn; the prepared-invocation builder above stays trust-free on purpose.
134
+ const validated = await nativeMainCodexLoginValidatedInvocation();
135
+ const child = Bun.spawn([validated.file, ...validated.args], {
98
136
  env: { ...process.env, CODEX_HOME: codexHome },
99
137
  stdin: "inherit",
100
138
  stdout: "inherit",
101
139
  stderr: "inherit",
102
- ...(invocation.options.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}),
140
+ ...(validated.options.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}),
103
141
  });
104
142
  return child;
105
143
  }
@@ -323,7 +361,7 @@ export async function cmdNativeMainAccount(args: string[], deps: AccountDeps): P
323
361
  ? deps.spawnCodexLoginImpl(stagingHome)
324
362
  : deps.runCodexLoginImpl
325
363
  ? { exited: deps.runCodexLoginImpl(stagingHome), kill: () => {} }
326
- : spawnOfficialCodexLogin(stagingHome);
364
+ : await spawnOfficialCodexLogin(stagingHome);
327
365
  const heartbeatAbort = new AbortController();
328
366
  const heartbeat = maintainStageLease(
329
367
  deps,