@bitkyc08/opencodex 2.96.0 → 2.98.0-preview.20261107

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 (465) hide show
  1. package/bin/ocx.mjs +215 -20
  2. package/gui/dist/assets/App-6TFtZsUF.css +1 -0
  3. package/gui/dist/assets/App-B8_sOxoz.js +59 -0
  4. package/gui/dist/assets/Tray-DpWEp6ee.js +1 -0
  5. package/gui/dist/assets/WantedSansVariable.split.0-Dwvb1WRx.woff2 +0 -0
  6. package/gui/dist/assets/WantedSansVariable.split.1-1wKD2RxI.woff2 +0 -0
  7. package/gui/dist/assets/WantedSansVariable.split.10-CAKA6LIP.woff2 +0 -0
  8. package/gui/dist/assets/WantedSansVariable.split.11-k5H85R4b.woff2 +0 -0
  9. package/gui/dist/assets/WantedSansVariable.split.12-BHboLsUv.woff2 +0 -0
  10. package/gui/dist/assets/WantedSansVariable.split.13-9GV377ix.woff2 +0 -0
  11. package/gui/dist/assets/WantedSansVariable.split.14-DovDXnrj.woff2 +0 -0
  12. package/gui/dist/assets/WantedSansVariable.split.15-DTdykCig.woff2 +0 -0
  13. package/gui/dist/assets/WantedSansVariable.split.16-CKz2ccgK.woff2 +0 -0
  14. package/gui/dist/assets/WantedSansVariable.split.17-Z2RD_KRZ.woff2 +0 -0
  15. package/gui/dist/assets/WantedSansVariable.split.18-BcKtfonJ.woff2 +0 -0
  16. package/gui/dist/assets/WantedSansVariable.split.19-DEQPOSZn.woff2 +0 -0
  17. package/gui/dist/assets/WantedSansVariable.split.2-DryboyuA.woff2 +0 -0
  18. package/gui/dist/assets/WantedSansVariable.split.20-Bia5JMls.woff2 +0 -0
  19. package/gui/dist/assets/WantedSansVariable.split.21-Cr4jFw-E.woff2 +0 -0
  20. package/gui/dist/assets/WantedSansVariable.split.22-DjjB69TZ.woff2 +0 -0
  21. package/gui/dist/assets/WantedSansVariable.split.23-CvUzJskt.woff2 +0 -0
  22. package/gui/dist/assets/WantedSansVariable.split.24-i_eMg5ox.woff2 +0 -0
  23. package/gui/dist/assets/WantedSansVariable.split.25-2aKHwPX-.woff2 +0 -0
  24. package/gui/dist/assets/WantedSansVariable.split.26-B6wXoCEL.woff2 +0 -0
  25. package/gui/dist/assets/WantedSansVariable.split.27-D4h1WfGM.woff2 +0 -0
  26. package/gui/dist/assets/WantedSansVariable.split.28-kvRPCStd.woff2 +0 -0
  27. package/gui/dist/assets/WantedSansVariable.split.29-DHAiwleD.woff2 +0 -0
  28. package/gui/dist/assets/WantedSansVariable.split.3-7H--eyZi.woff2 +0 -0
  29. package/gui/dist/assets/WantedSansVariable.split.30-C66cfAY2.woff2 +0 -0
  30. package/gui/dist/assets/WantedSansVariable.split.31-FDmtiNim.woff2 +0 -0
  31. package/gui/dist/assets/WantedSansVariable.split.32-DouHt2Dd.woff2 +0 -0
  32. package/gui/dist/assets/WantedSansVariable.split.33-B8HVvkJX.woff2 +0 -0
  33. package/gui/dist/assets/WantedSansVariable.split.34-BtkRu1FN.woff2 +0 -0
  34. package/gui/dist/assets/WantedSansVariable.split.35-DBylQbtk.woff2 +0 -0
  35. package/gui/dist/assets/WantedSansVariable.split.36-Sg089Kgh.woff2 +0 -0
  36. package/gui/dist/assets/WantedSansVariable.split.37-CYtvbriS.woff2 +0 -0
  37. package/gui/dist/assets/WantedSansVariable.split.38-DKkSLf8Z.woff2 +0 -0
  38. package/gui/dist/assets/WantedSansVariable.split.39-CecotKZD.woff2 +0 -0
  39. package/gui/dist/assets/WantedSansVariable.split.4-Bv8O3ZMb.woff2 +0 -0
  40. package/gui/dist/assets/WantedSansVariable.split.40-DdCvkmOU.woff2 +0 -0
  41. package/gui/dist/assets/WantedSansVariable.split.41-ESn674Hc.woff2 +0 -0
  42. package/gui/dist/assets/WantedSansVariable.split.42-DL9V7NNV.woff2 +0 -0
  43. package/gui/dist/assets/WantedSansVariable.split.43-yipO0cyk.woff2 +0 -0
  44. package/gui/dist/assets/WantedSansVariable.split.44-6rTmLZhm.woff2 +0 -0
  45. package/gui/dist/assets/WantedSansVariable.split.45-BJAj8lrm.woff2 +0 -0
  46. package/gui/dist/assets/WantedSansVariable.split.46-BDTzMn2c.woff2 +0 -0
  47. package/gui/dist/assets/WantedSansVariable.split.47-Bxd4wGgi.woff2 +0 -0
  48. package/gui/dist/assets/WantedSansVariable.split.48-DxnFBLnH.woff2 +0 -0
  49. package/gui/dist/assets/WantedSansVariable.split.49-DnVD0aOD.woff2 +0 -0
  50. package/gui/dist/assets/WantedSansVariable.split.5-B1wI2pp5.woff2 +0 -0
  51. package/gui/dist/assets/WantedSansVariable.split.50-D9JlkZd6.woff2 +0 -0
  52. package/gui/dist/assets/WantedSansVariable.split.51-D9Vw6Bu3.woff2 +0 -0
  53. package/gui/dist/assets/WantedSansVariable.split.52-ClEJk4kn.woff2 +0 -0
  54. package/gui/dist/assets/WantedSansVariable.split.53-BSXU0vh-.woff2 +0 -0
  55. package/gui/dist/assets/WantedSansVariable.split.54-EcuxkR9v.woff2 +0 -0
  56. package/gui/dist/assets/WantedSansVariable.split.55-CYiFhQX8.woff2 +0 -0
  57. package/gui/dist/assets/WantedSansVariable.split.56--Gk9g8BK.woff2 +0 -0
  58. package/gui/dist/assets/WantedSansVariable.split.57-DnkOPZcy.woff2 +0 -0
  59. package/gui/dist/assets/WantedSansVariable.split.58-9MB8504z.woff2 +0 -0
  60. package/gui/dist/assets/WantedSansVariable.split.59-ByxIsN72.woff2 +0 -0
  61. package/gui/dist/assets/WantedSansVariable.split.6-Bmk0dRVw.woff2 +0 -0
  62. package/gui/dist/assets/WantedSansVariable.split.60-Bxwx_aWQ.woff2 +0 -0
  63. package/gui/dist/assets/WantedSansVariable.split.61-DA2z5sm7.woff2 +0 -0
  64. package/gui/dist/assets/WantedSansVariable.split.62-C5iJPJZn.woff2 +0 -0
  65. package/gui/dist/assets/WantedSansVariable.split.63-DAqrmaEc.woff2 +0 -0
  66. package/gui/dist/assets/WantedSansVariable.split.64-BgXFsljb.woff2 +0 -0
  67. package/gui/dist/assets/WantedSansVariable.split.65-DKiWujvu.woff2 +0 -0
  68. package/gui/dist/assets/WantedSansVariable.split.66-8po4vUZ4.woff2 +0 -0
  69. package/gui/dist/assets/WantedSansVariable.split.67-Cy5qyI9O.woff2 +0 -0
  70. package/gui/dist/assets/WantedSansVariable.split.68-BKny7Fy3.woff2 +0 -0
  71. package/gui/dist/assets/WantedSansVariable.split.69-B4VU4u_b.woff2 +0 -0
  72. package/gui/dist/assets/WantedSansVariable.split.7-BuqwNpgA.woff2 +0 -0
  73. package/gui/dist/assets/WantedSansVariable.split.70-BCd4n346.woff2 +0 -0
  74. package/gui/dist/assets/WantedSansVariable.split.71-CkQppaWn.woff2 +0 -0
  75. package/gui/dist/assets/WantedSansVariable.split.72-Db7vaoFs.woff2 +0 -0
  76. package/gui/dist/assets/WantedSansVariable.split.73-DI80TYWl.woff2 +0 -0
  77. package/gui/dist/assets/WantedSansVariable.split.74-tMCtDAHB.woff2 +0 -0
  78. package/gui/dist/assets/WantedSansVariable.split.75-Ciw0D5WG.woff2 +0 -0
  79. package/gui/dist/assets/WantedSansVariable.split.76-DoLjFgp-.woff2 +0 -0
  80. package/gui/dist/assets/WantedSansVariable.split.77-CpT2uvMy.woff2 +0 -0
  81. package/gui/dist/assets/WantedSansVariable.split.78-CkcJ4iZ1.woff2 +0 -0
  82. package/gui/dist/assets/WantedSansVariable.split.79-DsOUJjEM.woff2 +0 -0
  83. package/gui/dist/assets/WantedSansVariable.split.8-DsjypPd6.woff2 +0 -0
  84. package/gui/dist/assets/WantedSansVariable.split.80-C0VwHTte.woff2 +0 -0
  85. package/gui/dist/assets/WantedSansVariable.split.81-DTelu57i.woff2 +0 -0
  86. package/gui/dist/assets/WantedSansVariable.split.82-BiMndGN1.woff2 +0 -0
  87. package/gui/dist/assets/WantedSansVariable.split.83-CVcC6eDG.woff2 +0 -0
  88. package/gui/dist/assets/WantedSansVariable.split.84-DlhZVt_O.woff2 +0 -0
  89. package/gui/dist/assets/WantedSansVariable.split.85-S8I2D3pA.woff2 +0 -0
  90. package/gui/dist/assets/WantedSansVariable.split.86-DozXXpH5.woff2 +0 -0
  91. package/gui/dist/assets/WantedSansVariable.split.87-Dsn0Vuuo.woff2 +0 -0
  92. package/gui/dist/assets/WantedSansVariable.split.88-iNwxxDCr.woff2 +0 -0
  93. package/gui/dist/assets/WantedSansVariable.split.89-B63u_9CZ.woff2 +0 -0
  94. package/gui/dist/assets/WantedSansVariable.split.9-Bi3IzpMI.woff2 +0 -0
  95. package/gui/dist/assets/WantedSansVariable.split.90-ByeH1Pqf.woff2 +0 -0
  96. package/gui/dist/assets/WantedSansVariable.split.91-UQLlagpm.woff2 +0 -0
  97. package/gui/dist/assets/brand-mark-VPhzz-WE.js +1 -0
  98. package/gui/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  99. package/gui/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  100. package/gui/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  101. package/gui/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  102. package/gui/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
  103. package/gui/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
  104. package/gui/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
  105. package/gui/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
  106. package/gui/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
  107. package/gui/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
  108. package/gui/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  109. package/gui/dist/assets/index-5REODpG3.css +2 -0
  110. package/gui/dist/assets/index-BWKBeK77.js +94 -0
  111. package/gui/dist/assets/segment-thumb-features-BQYzrze9.js +1 -0
  112. package/gui/dist/classic/assets/App-Bz65x1J6.js +58 -0
  113. package/gui/dist/{assets/Tray-BOPQyDbH.js → classic/assets/Tray-kk7mdO6I.js} +1 -1
  114. package/gui/dist/classic/assets/index-Dp2j8bSc.js +94 -0
  115. package/gui/dist/classic/assets/quota-summary-CvamtHjB.js +1 -0
  116. package/gui/dist/classic/index.html +47 -0
  117. package/gui/dist/favicon.png +0 -0
  118. package/gui/dist/favicon.svg +14 -0
  119. package/gui/dist/index.html +15 -2
  120. package/package.json +1 -1
  121. package/src/adapters/anthropic.ts +17 -8
  122. package/src/adapters/command-code.ts +15 -16
  123. package/src/adapters/cursor/transport-retry.ts +2 -2
  124. package/src/adapters/devin/cloud-direct/chat.ts +15 -6
  125. package/src/adapters/google.ts +7 -7
  126. package/src/adapters/kiro/adapter.ts +18 -3
  127. package/src/adapters/kiro/conversation.ts +8 -8
  128. package/src/adapters/kiro/payload.ts +45 -12
  129. package/src/adapters/kiro/stream.ts +230 -14
  130. package/src/adapters/kiro/structured-output-json.ts +191 -0
  131. package/src/adapters/kiro/structured-output-schema.ts +542 -0
  132. package/src/adapters/kiro/structured-output.ts +367 -0
  133. package/src/adapters/kiro-constants.ts +24 -1
  134. package/src/adapters/kiro-events.ts +31 -1
  135. package/src/adapters/kiro-retry.ts +3 -3
  136. package/src/adapters/kiro-tools.ts +14 -9
  137. package/src/adapters/kiro-wire.ts +9 -5
  138. package/src/adapters/ollama-native.ts +11 -1
  139. package/src/adapters/openai-chat/messages.ts +58 -5
  140. package/src/adapters/openai-chat/mistral-image-limit.ts +50 -0
  141. package/src/adapters/openai-chat/passthrough.ts +5 -3
  142. package/src/adapters/openai-chat/tool-schema.ts +83 -13
  143. package/src/adapters/openai-responses/empty-assistant.ts +15 -3
  144. package/src/adapters/openai-responses/opengateway-input.ts +18 -6
  145. package/src/adapters/openai-responses/passthrough.ts +5 -4
  146. package/src/adapters/openai-responses/reasoning.ts +9 -4
  147. package/src/adapters/openai-responses/request-strips.ts +1 -1
  148. package/src/adapters/openai-responses/tool-output-recovery.ts +79 -0
  149. package/src/adapters/physical-send.ts +3 -3
  150. package/src/adapters/qoder/live-models.ts +115 -1
  151. package/src/adapters/zed-openai-stream.ts +2 -1
  152. package/src/bridge/errors.ts +11 -2
  153. package/src/bridge/response-json.ts +2 -1
  154. package/src/bridge/sse.ts +14 -6
  155. package/src/chat/failure-verdict.ts +21 -0
  156. package/src/chat/outbound.ts +139 -21
  157. package/src/claude/failure-verdict.ts +21 -0
  158. package/src/claude/inbound-content-options.ts +15 -2
  159. package/src/claude/inbound-model-options.ts +2 -1
  160. package/src/claude/inbound-records.ts +2 -0
  161. package/src/claude/inbound.ts +17 -11
  162. package/src/claude/outbound.ts +98 -22
  163. package/src/cli/capabilities-access-remote.ts +13 -0
  164. package/src/cli/capabilities-base.ts +26 -3
  165. package/src/cli/capabilities-command.ts +12 -3
  166. package/src/cli/capabilities-provider-models.ts +3 -3
  167. package/src/cli/capability-contracts.ts +2 -0
  168. package/src/cli/codex-launch-auth.ts +30 -1
  169. package/src/cli/codex-launcher.ts +12 -5
  170. package/src/cli/codex-shim-autorestore.ts +12 -4
  171. package/src/cli/config-command.ts +11 -2
  172. package/src/cli/connect.ts +17 -2
  173. package/src/cli/dispatch.ts +14 -177
  174. package/src/cli/doctor.ts +95 -7
  175. package/src/cli/help.ts +2 -2
  176. package/src/cli/index.ts +17 -8
  177. package/src/cli/link-apply-restart.ts +9 -2
  178. package/src/cli/link.ts +1 -1
  179. package/src/cli/models.ts +124 -38
  180. package/src/cli/registry.ts +12 -4
  181. package/src/cli/restart-failure.ts +17 -0
  182. package/src/cli/root.ts +8 -0
  183. package/src/cli/stop-approval.ts +2 -2
  184. package/src/cli/sync-command.ts +243 -0
  185. package/src/cli/sync-fanout-process.ts +92 -0
  186. package/src/cli/sync-fanout.ts +161 -0
  187. package/src/cli/sync-flags.ts +10 -0
  188. package/src/cli/sync-link-status.ts +39 -0
  189. package/src/cli/sync-update-guard.ts +18 -0
  190. package/src/cli/system-restart-client.ts +5 -0
  191. package/src/cli/uninstall-client-state.ts +12 -1
  192. package/src/cli/update-restart-child.ts +13 -3
  193. package/src/cli/update-restart-home.ts +6 -3
  194. package/src/cli/update-restart.ts +36 -19
  195. package/src/client/connect.ts +35 -15
  196. package/src/client/hub-client.ts +5 -0
  197. package/src/client/link-home.ts +3 -2
  198. package/src/client/link-management-relay.ts +39 -2
  199. package/src/client/link-readiness.ts +3 -1
  200. package/src/client/machine-api.ts +2 -1
  201. package/src/client/machine-listener.ts +10 -0
  202. package/src/client/orphan-token-recovery.ts +322 -0
  203. package/src/client/restore-ownership.ts +19 -1
  204. package/src/client/runtime-restart.ts +12 -4
  205. package/src/client/runtime.ts +40 -11
  206. package/src/client/stop-routing.ts +62 -0
  207. package/src/client/sync-runtime.ts +65 -0
  208. package/src/clients/config-export.ts +32 -3
  209. package/src/codex/auth-context.ts +49 -103
  210. package/src/codex/catalog/antigravity-discovery.ts +16 -5
  211. package/src/codex/catalog/provider-models.ts +18 -12
  212. package/src/codex/forward-transport-headers.ts +35 -6
  213. package/src/codex/inject/config-toml.ts +88 -0
  214. package/src/codex/inject/multi-agent-v2.ts +30 -4
  215. package/src/codex/inject/plan.ts +34 -7
  216. package/src/codex/inject-coordination.ts +11 -0
  217. package/src/codex/inject.ts +18 -7
  218. package/src/codex/lineage.ts +13 -7
  219. package/src/codex/native-profile-api.ts +27 -1
  220. package/src/codex/quota.ts +22 -6
  221. package/src/codex/request-owned-affinity-key.ts +11 -0
  222. package/src/codex/request-owned-affinity.ts +118 -0
  223. package/src/codex/request-owned-main-pin.ts +86 -0
  224. package/src/codex/role-capability.ts +52 -41
  225. package/src/codex/routing/active-account.ts +13 -5
  226. package/src/codex/routing/selection.ts +40 -1
  227. package/src/codex/routing/thread-affinity-store.ts +916 -0
  228. package/src/codex/routing/thread-affinity.ts +90 -12
  229. package/src/codex/shim-diagnostics.ts +7 -0
  230. package/src/codex/shim-legacy-record.ts +290 -0
  231. package/src/codex/shim-windows-refresh.ts +9 -2
  232. package/src/codex/shim-wrapper-write.ts +7 -0
  233. package/src/codex/shim.ts +80 -21
  234. package/src/codex/toml-source-lines.ts +72 -13
  235. package/src/combos/failover.ts +6 -109
  236. package/src/combos/request.ts +2 -2
  237. package/src/combos/resolve.ts +29 -11
  238. package/src/config/diagnostics.ts +9 -9
  239. package/src/config/load-degrade.ts +27 -27
  240. package/src/config/process-state.ts +5 -0
  241. package/src/config/provider-validation.ts +9 -2
  242. package/src/config/removed-opencode-free-backup.ts +6 -3
  243. package/src/config/schema/leaf-validators.ts +1 -0
  244. package/src/config/tracked-runtime-inspection.ts +3 -3
  245. package/src/generated/compatibility-version.json +595 -255
  246. package/src/images/loop.ts +4 -3
  247. package/src/lib/client-error-body.ts +215 -0
  248. package/src/lib/client-retry-after.ts +66 -0
  249. package/src/lib/config-ownership-removal.ts +422 -0
  250. package/src/lib/config-ownership.ts +650 -81
  251. package/src/lib/context-overflow-verdict.ts +113 -0
  252. package/src/lib/crash-guard.ts +4 -2
  253. package/src/lib/desktop-cli-handoff.d.mts +4 -5
  254. package/src/lib/desktop-cli-handoff.mjs +18 -17
  255. package/src/lib/empty-tool-catalog.ts +25 -3
  256. package/src/lib/error-destination.ts +47 -0
  257. package/src/lib/errors.ts +1 -0
  258. package/src/lib/failure-detail.ts +66 -0
  259. package/src/lib/local-management-capability.ts +3 -1
  260. package/src/lib/messages-error-body.ts +162 -0
  261. package/src/lib/messages-sse-error-presentation.ts +93 -0
  262. package/src/lib/model-identity.ts +44 -0
  263. package/src/lib/passive-read.ts +9 -4
  264. package/src/lib/private-sqlite-path.ts +124 -0
  265. package/src/lib/response-service-tier.ts +17 -0
  266. package/src/lib/retry-after.ts +3 -0
  267. package/src/lib/socks5-fetch.ts +21 -9
  268. package/src/lib/spend-ledger-owner.ts +43 -4
  269. package/src/lib/upstream-condition.ts +142 -0
  270. package/src/lib/upstream-retry.ts +95 -12
  271. package/src/lib/windows-owner-acl.ts +22 -9
  272. package/src/lib/winsw.ts +5 -5
  273. package/src/lib/workflow-budget.ts +3 -1
  274. package/src/link/remote-platform.ts +14 -0
  275. package/src/link/remote-windows.ts +51 -9
  276. package/src/link/ssh-argv.ts +63 -10
  277. package/src/oauth/generic-account-failover.ts +13 -11
  278. package/src/oauth/index.ts +42 -73
  279. package/src/oauth/oauth-errors.ts +67 -0
  280. package/src/oauth/store.ts +21 -11
  281. package/src/protocols/codecs/messages-ir.ts +15 -9
  282. package/src/protocols/codecs/ollama.ts +197 -0
  283. package/src/protocols/encoders/adapter-events.ts +30 -7
  284. package/src/protocols/encoders/chat.ts +18 -10
  285. package/src/protocols/encoders/messages.ts +72 -28
  286. package/src/protocols/trace.ts +18 -0
  287. package/src/providers/antigravity-models.ts +45 -12
  288. package/src/providers/fastwire.ts +3 -2
  289. package/src/providers/free-directory.ts +2 -2
  290. package/src/providers/quota/anthropic-usage-windows.ts +13 -3
  291. package/src/providers/quota/vendor-probes-key.ts +60 -24
  292. package/src/providers/reasoning-metadata.ts +2 -1
  293. package/src/providers/registry/entries-extended.ts +9 -0
  294. package/src/providers/request-pacing.ts +3 -2
  295. package/src/reasoning-effort.ts +7 -2
  296. package/src/remote/hub-usage.ts +3 -0
  297. package/src/responses/apply-patch-envelope.ts +45 -19
  298. package/src/responses/compaction-history-framing.ts +5 -1
  299. package/src/responses/freeform-wrapper-scan.ts +5 -3
  300. package/src/responses/progressive-freeform-input.ts +354 -45
  301. package/src/routing/fallback-policy.ts +3 -1
  302. package/src/server/admission-model-scope.ts +17 -6
  303. package/src/server/admitted-http-turn.ts +57 -0
  304. package/src/server/anthropic-rate-limit-headers.ts +75 -3
  305. package/src/server/auth-cors.ts +5 -0
  306. package/src/server/chat-completions.ts +45 -20
  307. package/src/server/chat-native-sse.ts +52 -7
  308. package/src/server/chat-native.ts +60 -35
  309. package/src/server/claude-bridge-pool-session.ts +59 -0
  310. package/src/server/claude-messages.ts +174 -84
  311. package/src/server/context-history.ts +5 -1
  312. package/src/server/gui-static.ts +4 -1
  313. package/src/server/hub-usage.ts +7 -2
  314. package/src/server/inbound-body-admission.ts +11 -4
  315. package/src/server/index/link-management.ts +8 -0
  316. package/src/server/index/ollama-routes.ts +91 -0
  317. package/src/server/index/serve-options.ts +44 -24
  318. package/src/server/index/startup-warnings.ts +5 -12
  319. package/src/server/index/websocket-handler.ts +5 -2
  320. package/src/server/index.ts +6 -36
  321. package/src/server/inference/client-encoder-delivery.ts +9 -3
  322. package/src/server/json-serialized-bytes.ts +44 -0
  323. package/src/server/management/agent-settings-routes.ts +24 -21
  324. package/src/server/management/codex-cli-update-routes.ts +2 -1
  325. package/src/server/management/logs-usage-routes.ts +89 -4
  326. package/src/server/management/provider-routes.ts +2 -22
  327. package/src/server/management/qoder-provider-probe.ts +105 -0
  328. package/src/server/management/route-registry.ts +4 -1
  329. package/src/server/management/usage-aggregate-cache.ts +15 -5
  330. package/src/server/management/usage-source-facets.ts +38 -0
  331. package/src/server/messages-native-scope.ts +2 -1
  332. package/src/server/messages-native-tool-guard.ts +12 -4
  333. package/src/server/messages-native.ts +123 -47
  334. package/src/server/messages-response-headers.ts +25 -11
  335. package/src/server/messages-shared.ts +99 -65
  336. package/src/server/messages-sse-error-filter.ts +199 -0
  337. package/src/server/native-final-log.ts +93 -0
  338. package/src/server/ollama-inbound.ts +349 -0
  339. package/src/server/ollama-native-paths.ts +21 -0
  340. package/src/server/ollama-route-policy.ts +73 -0
  341. package/src/server/relay.ts +22 -3
  342. package/src/server/request-decompress.ts +4 -2
  343. package/src/server/request-log-failure-attribution.ts +22 -0
  344. package/src/server/request-log-failure-detail.ts +80 -0
  345. package/src/server/request-log-terminal-status.ts +4 -2
  346. package/src/server/request-log.ts +91 -42
  347. package/src/server/response-log-body.ts +6 -1
  348. package/src/server/responses/account-change-state.ts +17 -6
  349. package/src/server/responses/adapter-continuation.ts +17 -6
  350. package/src/server/responses/adapter-delivery.ts +17 -10
  351. package/src/server/responses/adapter-dispatch.ts +32 -31
  352. package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
  353. package/src/server/responses/codex-auth-error.ts +24 -19
  354. package/src/server/responses/codex-ws-exchange.ts +11 -8
  355. package/src/server/responses/codex-ws-metadata.ts +94 -21
  356. package/src/server/responses/codex-ws-request.ts +3 -1
  357. package/src/server/responses/codex-ws-wire.ts +19 -3
  358. package/src/server/responses/compact.ts +57 -24
  359. package/src/server/responses/compaction-recovery.ts +4 -2
  360. package/src/server/responses/compaction-routing.ts +9 -4
  361. package/src/server/responses/core-auth.ts +32 -14
  362. package/src/server/responses/core-codex-account.ts +17 -6
  363. package/src/server/responses/core-combo-failure.ts +7 -1
  364. package/src/server/responses/core-combo-native.ts +2 -1
  365. package/src/server/responses/core-combo.ts +43 -27
  366. package/src/server/responses/core-errors.ts +24 -21
  367. package/src/server/responses/core-lifetime.ts +6 -3
  368. package/src/server/responses/core-normalize.ts +1 -0
  369. package/src/server/responses/core-options.ts +9 -0
  370. package/src/server/responses/core-pipeline.ts +4 -3
  371. package/src/server/responses/empty-completion-guard.ts +4 -1
  372. package/src/server/responses/fetch-helpers.ts +7 -1
  373. package/src/server/responses/input-admission.ts +28 -2
  374. package/src/server/responses/native-injection.ts +1 -1
  375. package/src/server/responses/native-response-json.ts +13 -4
  376. package/src/server/responses/native-response-output.ts +1 -2
  377. package/src/server/responses/non-replayable-error.ts +2 -1
  378. package/src/server/responses/pacing-overload.ts +3 -2
  379. package/src/server/responses/passthrough-delivery.ts +55 -14
  380. package/src/server/responses/passthrough-dispatch.ts +20 -18
  381. package/src/server/responses/passthrough-error.ts +9 -9
  382. package/src/server/responses/policy-fallback.ts +2 -1
  383. package/src/server/responses/request-prepare.ts +69 -48
  384. package/src/server/responses/request-transport.ts +36 -31
  385. package/src/server/responses/response-effects.ts +3 -2
  386. package/src/server/responses/run-turn-execution.ts +6 -6
  387. package/src/server/responses/sidecar-execution.ts +16 -12
  388. package/src/server/responses/spend-storage-error.ts +2 -1
  389. package/src/server/responses/terminal-guard.ts +30 -0
  390. package/src/server/responses/ws-upstream.ts +9 -0
  391. package/src/server/responses-custom-tool-repair.ts +14 -3
  392. package/src/server/responses-terminal-repair.ts +5 -2
  393. package/src/server/responses-undeclared-tool-guard.ts +39 -16
  394. package/src/server/restart-replacement.ts +3 -1
  395. package/src/server/safe-response-headers.ts +162 -13
  396. package/src/server/sse-payload-rewrite.ts +23 -11
  397. package/src/server/turn-state-handles.ts +164 -0
  398. package/src/server/workflow-refusal.ts +2 -1
  399. package/src/server/ws-bridge.ts +4 -0
  400. package/src/service/definition.ts +36 -4
  401. package/src/service/launchd.ts +89 -32
  402. package/src/service/logging.ts +34 -7
  403. package/src/service/ownership-mutation-lease.d.mts +11 -2
  404. package/src/service/ownership-mutation-lease.mjs +53 -11
  405. package/src/service/plist-xml.ts +59 -0
  406. package/src/service/state.ts +8 -0
  407. package/src/service/systemd-env.ts +2 -0
  408. package/src/service/systemd.ts +31 -7
  409. package/src/service/windows-taskxml.ts +16 -7
  410. package/src/service-manager-probe.ts +4 -10
  411. package/src/types/config.ts +2 -0
  412. package/src/types/provider.ts +2 -0
  413. package/src/types/request.ts +13 -1
  414. package/src/update/config-preflight.ts +48 -0
  415. package/src/update/index.ts +148 -26
  416. package/src/update/npm-install.d.mts +8 -0
  417. package/src/update/npm-install.mjs +20 -1
  418. package/src/update/orchestrated-admission.d.mts +4 -0
  419. package/src/update/orchestrated-admission.mjs +12 -0
  420. package/src/update/orchestrated-arguments.d.mts +12 -0
  421. package/src/update/orchestrated-arguments.mjs +64 -0
  422. package/src/update/orchestrated-child.d.mts +12 -0
  423. package/src/update/orchestrated-child.mjs +70 -0
  424. package/src/update/orchestrated-entry.ts +234 -0
  425. package/src/update/orchestrated-identity-probe-entry.ts +20 -0
  426. package/src/update/orchestrated-identity.ts +53 -0
  427. package/src/update/orchestrated-live-identity.ts +48 -0
  428. package/src/update/orchestrated-node-driver.mjs +99 -0
  429. package/src/update/orchestrated-outcome.d.mts +21 -0
  430. package/src/update/orchestrated-outcome.mjs +40 -0
  431. package/src/update/orchestrated-plan.ts +49 -0
  432. package/src/update/orchestrated-pnpm.d.mts +8 -0
  433. package/src/update/orchestrated-pnpm.mjs +33 -0
  434. package/src/update/orchestrated-session.d.mts +37 -0
  435. package/src/update/orchestrated-session.mjs +264 -0
  436. package/src/update/orchestrated-token.d.mts +10 -0
  437. package/src/update/orchestrated-token.mjs +21 -0
  438. package/src/update/orchestrated-token.ts +3 -0
  439. package/src/update/orchestrated-tree.d.mts +1 -0
  440. package/src/update/orchestrated-tree.mjs +14 -0
  441. package/src/update/pnpm-global-install.d.mts +6 -0
  442. package/src/update/pnpm-global-install.mjs +9 -2
  443. package/src/update/posix-install-supervisor-entry.mjs +6 -0
  444. package/src/update/posix-install-supervisor.d.mts +10 -0
  445. package/src/update/posix-install-supervisor.mjs +88 -0
  446. package/src/update/sync-update-mutex.d.mts +10 -0
  447. package/src/update/sync-update-mutex.mjs +164 -0
  448. package/src/update/sync-update-mutex.ts +1 -0
  449. package/src/update/test-home-guard.mjs +33 -0
  450. package/src/update/transactional-install.mjs +2 -2
  451. package/src/usage/client.ts +43 -0
  452. package/src/usage/error-detail.ts +225 -0
  453. package/src/usage/log.ts +64 -27
  454. package/src/usage/source-facets.ts +51 -0
  455. package/src/usage/source-filter.ts +65 -0
  456. package/src/usage/summary.ts +50 -8
  457. package/src/web-search/anthropic-executor.ts +105 -24
  458. package/src/web-search/executor.ts +5 -3
  459. package/src/web-search/loop.ts +33 -6
  460. package/src/web-search/progress-stream.ts +64 -5
  461. package/gui/dist/assets/App-bwugJRKn.js +0 -58
  462. package/gui/dist/assets/index-ebuVUtB7.js +0 -94
  463. package/gui/dist/assets/quota-summary-6HsrHQAy.js +0 -1
  464. /package/gui/dist/{assets → classic/assets}/App-B4j-Txmb.css +0 -0
  465. /package/gui/dist/{assets → classic/assets}/index-CHWwDo9L.css +0 -0
@@ -6,10 +6,13 @@ import type { CodexThreadLineage } from "../lineage";
6
6
  import type { CodexQuotaScope } from "./health-store";
7
7
  import type { TransientProbeLease } from "../../routing/probe-lease";
8
8
  import { clearPoolRecoveryState } from "../../routing/probe-lease";
9
+ import { identityFence, adoptStoredThreadRows, adoptStoredIssuer, CODEX_UNKNOWN_CONVERSATION_STATE_ISSUER, registerCodexAffinityLiveState, recordThreadBind, recordThreadTouch, recordThreadDelete, recordThreadAccountDeleted, recordAccountPinsCleared, recordAllCleared, recordThreadsCleared, recordIssuerSet, recordIssuerTouch, recordIssuerDelete, recordIssuersCleared } from "./thread-affinity-store";
10
+ export { CODEX_UNKNOWN_CONVERSATION_STATE_ISSUER } from "./thread-affinity-store";
9
11
 
10
12
  export type ThreadAffinityEntry = {
11
13
  accountId: string;
12
14
  generation: number;
15
+ identityFence?: string;
13
16
  createdAt: number;
14
17
  lastUsedAt: number;
15
18
  // Last time the bound account's quota threshold was re-evaluated for this
@@ -86,7 +89,9 @@ export type CodexAffinityMove =
86
89
  /** There was no live binding; this request established one. */
87
90
  | "new_bind"
88
91
  /** The binding was released without a replacement on this request. */
89
- | "cleared";
92
+ | "cleared"
93
+ /** No binding was established for this selection. */
94
+ | "unbound";
90
95
 
91
96
  /**
92
97
  * Why. A move is the expensive event -- it discards the prompt-cache prefix warmed on the old
@@ -95,6 +100,10 @@ export type CodexAffinityMove =
95
100
  */
96
101
  export type CodexAffinityReason =
97
102
  | "healthy"
103
+ /** The request had no usable conversation key. */
104
+ | "no_conversation"
105
+ /** A caller-owned credential did not opt into affinity. */
106
+ | "request_owned"
98
107
  | "quota_headroom"
99
108
  | "quota_refusal"
100
109
  | "transient"
@@ -194,15 +203,32 @@ let threadAffinityEntryTotal = 0;
194
203
  * Which pool account minted the conversation's carried OpenAI state
195
204
  * (`previous_response_id`, encrypted reasoning, provider conversation/file ids).
196
205
  * Keyed by the same affinity key as {@link threadAccountMap}, bounded the same
197
- * way, and process-local — raw account ids never reach a log.
206
+ * way. Durable rows use a separate keyed digest; raw account ids never reach a log.
198
207
  */
199
208
  type ConversationStateIssuerEntry = {
200
209
  accountId: string;
201
210
  lastUsedAt: number;
211
+ fence?: string;
212
+ storedAccountId?: string;
213
+ storedFence?: string | null;
202
214
  };
203
215
  const conversationStateIssuerMap = new Map<string, ConversationStateIssuerEntry>();
204
216
 
205
- export function clearThreadAccountMap(): void {
217
+ export function registerThreadAffinityLiveState(): void {
218
+ registerCodexAffinityLiveState({
219
+ thread: (key, scope) => threadAccountMap.get(key)?.get(scope as ThreadAffinityScope),
220
+ issuer: key => {
221
+ const entry = conversationStateIssuerMap.get(key);
222
+ return entry && { accountId: entry.storedAccountId ?? entry.accountId, fence: entry.storedAccountId ? entry.storedFence ?? undefined : entry.fence, lastUsedAt: entry.lastUsedAt };
223
+ },
224
+ clearLive: () => { threadAccountMap.clear(); threadAffinityEntryTotal = 0; conversationStateIssuerMap.clear(); },
225
+ });
226
+ }
227
+ registerThreadAffinityLiveState();
228
+
229
+ export function clearThreadAccountMap(options: { preserveConversationStateIssuers?: boolean } = {}): void {
230
+ if (options.preserveConversationStateIssuers) recordThreadsCleared();
231
+ else recordAllCleared();
206
232
  threadAccountMap.clear();
207
233
  threadAffinityEntryTotal = 0;
208
234
  // A refresh cooldown is per-account runtime state learned alongside these bindings. Leaving it
@@ -213,10 +239,13 @@ export function clearThreadAccountMap(): void {
213
239
  // going away. A held account nobody may probe because of a lease issued against the previous
214
240
  // roster is a recovery that never starts.
215
241
  clearPoolRecoveryState();
216
- conversationStateIssuerMap.clear();
242
+ // A manual account switch clears routing affinity, not the issuer of carried state. The next
243
+ // account needs that record to scrub or refuse account-bound continuation.
244
+ if (!options.preserveConversationStateIssuers) conversationStateIssuerMap.clear();
217
245
  }
218
246
 
219
247
  export function clearConversationStateIssuerMap(): void {
248
+ recordIssuersCleared();
220
249
  conversationStateIssuerMap.clear();
221
250
  }
222
251
 
@@ -224,6 +253,7 @@ export function clearThreadAccountMapForAccount(
224
253
  accountId: string,
225
254
  reason: CodexAffinityReason = "unusable",
226
255
  ): void {
256
+ recordAccountPinsCleared(accountId);
227
257
  for (const [threadId, affinities] of threadAccountMap) {
228
258
  for (const [scope, entry] of affinities) {
229
259
  if (entry.accountId === accountId && affinities.delete(scope)) {
@@ -239,6 +269,7 @@ function pruneConversationStateIssuers(now: number): void {
239
269
  for (const [key, entry] of conversationStateIssuerMap) {
240
270
  if (now - entry.lastUsedAt > CODEX_THREAD_AFFINITY_IDLE_TTL_MS) {
241
271
  conversationStateIssuerMap.delete(key);
272
+ recordIssuerDelete(key);
242
273
  }
243
274
  }
244
275
  while (conversationStateIssuerMap.size > CODEX_THREAD_AFFINITY_MAX_ENTRIES) {
@@ -252,22 +283,30 @@ function pruneConversationStateIssuers(now: number): void {
252
283
  }
253
284
  if (!oldestKey) break;
254
285
  conversationStateIssuerMap.delete(oldestKey);
286
+ recordIssuerDelete(oldestKey);
255
287
  }
256
288
  }
257
289
 
258
290
  /**
259
291
  * Record the pool account that just issued carried conversation state for this
260
- * binding key. In-memory only; the id is never written to a request log.
292
+ * binding key. Persisted when an anchor is available; the id is never logged.
261
293
  */
262
294
  export function rememberConversationStateIssuer(
263
295
  bindingKey: string,
264
296
  accountId: string,
265
297
  now = Date.now(),
298
+ credential?: { generation: number; chatgptAccountId: string },
266
299
  ): void {
267
300
  if (!bindingKey.trim() || !accountId.trim()) return;
268
301
  if (!admissibleAffinityComponent(bindingKey) || !admissibleAffinityComponent(accountId)) return;
269
302
  pruneConversationStateIssuers(now);
270
- conversationStateIssuerMap.set(bindingKey, { accountId, lastUsedAt: now });
303
+ const record = accountId === MAIN_CODEX_ACCOUNT_ID ? undefined : readCodexAccountRecord(accountId);
304
+ const fence = record?.credential && record.deletedAt == null && credential
305
+ && record.generation === credential.generation && record.credential.chatgptAccountId === credential.chatgptAccountId
306
+ ? identityFence(record.quotaHistoryIdentity) : undefined;
307
+ if (accountId === MAIN_CODEX_ACCOUNT_ID) recordIssuerDelete(bindingKey);
308
+ else if (accountId !== CODEX_UNKNOWN_CONVERSATION_STATE_ISSUER) recordIssuerSet(bindingKey, accountId, fence ?? null, now);
309
+ conversationStateIssuerMap.set(bindingKey, { accountId, lastUsedAt: now, fence });
271
310
  pruneConversationStateIssuers(now);
272
311
  }
273
312
 
@@ -278,12 +317,25 @@ export function peekConversationStateIssuer(
278
317
  ): string | undefined {
279
318
  if (!bindingKey.trim() || !admissibleAffinityComponent(bindingKey)) return undefined;
280
319
  pruneConversationStateIssuers(now);
281
- const entry = conversationStateIssuerMap.get(bindingKey);
320
+ recordIssuerTouch(bindingKey);
321
+ let entry = conversationStateIssuerMap.get(bindingKey);
322
+ if (!entry) {
323
+ const stored = adoptStoredIssuer(bindingKey, now);
324
+ if (stored !== undefined) {
325
+ entry = { accountId: stored.issuer, lastUsedAt: now, storedAccountId: stored.storedAccountId, storedFence: stored.storedFence };
326
+ conversationStateIssuerMap.set(bindingKey, entry);
327
+ pruneConversationStateIssuers(now);
328
+ }
329
+ }
282
330
  if (!entry) return undefined;
283
331
  entry.lastUsedAt = now;
284
332
  return entry.accountId;
285
333
  }
286
334
 
335
+ export function peekConversationStateStoredIssuerAccount(bindingKey: string): string | undefined {
336
+ return conversationStateIssuerMap.get(bindingKey)?.storedAccountId;
337
+ }
338
+
287
339
  /**
288
340
  * Why a binding was released, held until that thread's next resolve can report it (#4546).
289
341
  *
@@ -294,7 +346,7 @@ export function peekConversationStateIssuer(
294
346
  const pendingReleaseReasons = new Map<string, CodexAffinityReason>();
295
347
  const MAX_PENDING_RELEASE_REASONS = 4096;
296
348
 
297
- function notePendingReleaseReason(threadId: string | null, reason: CodexAffinityReason): void {
349
+ export function notePendingReleaseReason(threadId: string | null, reason: CodexAffinityReason): void {
298
350
  if (threadId === null) return;
299
351
  if (!pendingReleaseReasons.has(threadId) && pendingReleaseReasons.size >= MAX_PENDING_RELEASE_REASONS) {
300
352
  const oldest = pendingReleaseReasons.keys().next();
@@ -341,9 +393,25 @@ function getThreadAffinityForScope(
341
393
  scope: ThreadAffinityScope,
342
394
  ): ThreadAffinityEntry | undefined {
343
395
  if (!admissibleAffinityComponent(threadId)) return undefined;
396
+ recordThreadTouch(threadId, scope);
397
+ if (!threadAccountMap.get(threadId)?.get(scope)) adoptThreadAffinities(threadId, Date.now(), scope);
344
398
  return threadAccountMap.get(threadId)?.get(scope);
345
399
  }
346
400
 
401
+ function adoptThreadAffinities(threadId: string, now: number, scopeName?: ThreadAffinityScope): void {
402
+ for (const row of adoptStoredThreadRows(threadId, now, scopeName)) {
403
+ const record = readCodexAccountRecord(row.accountId);
404
+ if (!record?.credential || record.deletedAt != null || identityFence(record.quotaHistoryIdentity) !== row.fence) continue;
405
+ const scope = row.scope as ThreadAffinityScope;
406
+ const affinities = threadAccountMap.get(threadId) ?? new Map<ThreadAffinityScope, ThreadAffinityEntry>();
407
+ if (affinities.has(scope)) continue;
408
+ affinities.set(scope, { accountId: row.accountId, generation: record.generation, identityFence: row.fence, createdAt: row.createdAt, lastUsedAt: row.lastUsedAt, lastReevalAt: now });
409
+ threadAccountMap.set(threadId, affinities);
410
+ threadAffinityEntryTotal += 1;
411
+ }
412
+ pruneLruThreadAffinities();
413
+ }
414
+
347
415
  export function getThreadAffinity(threadId: string, quotaScope?: CodexQuotaScope): ThreadAffinityEntry | undefined {
348
416
  return getThreadAffinityForScope(threadId, threadAffinityScope(quotaScope));
349
417
  }
@@ -359,6 +427,7 @@ export function getModelDetourAffinity(
359
427
 
360
428
  function deleteThreadAffinityForScope(threadId: string, scope: ThreadAffinityScope): void {
361
429
  if (!admissibleAffinityComponent(threadId)) return;
430
+ recordThreadDelete(threadId, scope);
362
431
  const affinities = threadAccountMap.get(threadId);
363
432
  if (!affinities) return;
364
433
  if (affinities.delete(scope)) {
@@ -383,10 +452,12 @@ export function deleteModelDetourAffinity(
383
452
  /** Remove only the matching failed account's affinities for one thread. */
384
453
  export function deleteThreadAffinitiesForAccount(threadId: string, accountId: string): void {
385
454
  if (!admissibleAffinityComponent(threadId) || !admissibleAffinityComponent(accountId)) return;
455
+ recordThreadAccountDeleted(threadId, accountId);
386
456
  const affinities = threadAccountMap.get(threadId);
387
457
  if (!affinities) return;
388
458
  for (const [scope, entry] of affinities) {
389
459
  if (entry.accountId === accountId && affinities.delete(scope)) {
460
+ recordThreadDelete(threadId, scope);
390
461
  threadAffinityEntryTotal = Math.max(0, threadAffinityEntryTotal - 1);
391
462
  }
392
463
  }
@@ -459,6 +530,7 @@ function pruneExpiredThreadAffinities(now: number): void {
459
530
  for (const [threadId, affinities] of threadAccountMap) {
460
531
  for (const [scope, entry] of affinities) {
461
532
  if (isThreadAffinityExpired(entry, now) && affinities.delete(scope)) {
533
+ recordThreadDelete(threadId, scope);
462
534
  threadAffinityEntryTotal = Math.max(0, threadAffinityEntryTotal - 1);
463
535
  }
464
536
  }
@@ -502,15 +574,21 @@ function bindThreadAffinityForScope(
502
574
  const record = accountId === MAIN_CODEX_ACCOUNT_ID ? undefined : readCodexAccountRecord(accountId);
503
575
  if (accountId !== MAIN_CODEX_ACCOUNT_ID && (!record?.credential || record.deletedAt != null)) return;
504
576
  pruneExpiredThreadAffinities(now);
577
+ recordThreadTouch(threadId, scope);
505
578
  const affinities = threadAccountMap.get(threadId) ?? new Map<ThreadAffinityScope, ThreadAffinityEntry>();
506
579
  const previous = affinities.get(scope);
507
- affinities.set(scope, {
580
+ const fence = identityFence(record?.quotaHistoryIdentity);
581
+ const entry: ThreadAffinityEntry = {
508
582
  accountId,
509
583
  generation: accountId === MAIN_CODEX_ACCOUNT_ID ? 0 : record!.generation,
584
+ identityFence: fence,
510
585
  createdAt: previous?.createdAt ?? now,
511
586
  lastUsedAt: now,
512
587
  lastReevalAt: now,
513
- });
588
+ };
589
+ if (fence) recordThreadBind(threadId, scope, { scope, accountId, fence, createdAt: entry.createdAt, lastUsedAt: now });
590
+ else recordThreadDelete(threadId, scope);
591
+ affinities.set(scope, entry);
514
592
  if (!previous) threadAffinityEntryTotal += 1;
515
593
  threadAccountMap.set(threadId, affinities);
516
594
  pruneLruThreadAffinities();
@@ -540,14 +618,14 @@ export function bindModelDetourAffinity(
540
618
  export function getThreadAffinityScopes(
541
619
  threadId: string,
542
620
  ): ReadonlyMap<ThreadAffinityScope, ThreadAffinityEntry> | undefined {
621
+ adoptThreadAffinities(threadId, Date.now());
543
622
  return threadAccountMap.get(threadId);
544
623
  }
545
624
 
546
625
  /**
547
626
  * Move one scope's binding from the pre-#4546 RAW parent key onto the key this thread uses now.
548
627
  *
549
- * Bindings and the key that derives them are process-local, so an ordinary restart already
550
- * discards every binding and there is nothing to migrate. The case this exists for is the
628
+ * Legacy raw-parent keys are process-local and are not persisted. The case this exists for is the
551
629
  * narrow one: a code swap under a live conversation, where the map still holds entries made by
552
630
  * the old rule. Rebinding those cold is precisely the defect the lineage work exists to prevent,
553
631
  * so the conversation keeps its account and the legacy entry is retired in the same step.
@@ -2,6 +2,7 @@ import { existsSync, lstatSync, readFileSync } from "node:fs";
2
2
  import { SHIM_MARKER, UNIX_SHIM_REVISION_MARKER, WINDOWS_SHIM_REVISION_MARKER } from "./shim-templates";
3
3
  import { readStateResult, stateFiles, statePath } from "./shim-state-file";
4
4
  import { overlayDiagnostic } from "./shim-overlay";
5
+ import { checkLegacyShimRecord, legacyShimManualRestoreMessage } from "./shim-legacy-record";
5
6
 
6
7
  export function isShim(path: string): boolean {
7
8
  try {
@@ -59,6 +60,12 @@ export function diagnoseCodexShim(): CodexShimDiagnostic {
59
60
  };
60
61
  }
61
62
  if (state.mode === "path-overlay") return overlayDiagnostic(state);
63
+ if (state.platform === "win32") {
64
+ const legacy = checkLegacyShimRecord(state);
65
+ if (!legacy.ok) {
66
+ return { installed: true, healthy: false, runnable: false, active: null, summary: legacyShimManualRestoreMessage(legacy.reason, statePath()) };
67
+ }
68
+ }
62
69
  const files = stateFiles(state);
63
70
  const healthy = files.length > 0 && files.every(file => file.preserveOnly
64
71
  ? existsSync(file.backupPath) && !existsSync(file.originalPath)
@@ -0,0 +1,290 @@
1
+ import { closeSync, linkSync, lstatSync, openSync, readSync, realpathSync, renameSync, unlinkSync } from "node:fs";
2
+ import { posix, sep, win32 } from "node:path";
3
+ import { SHIM_MARKER } from "./shim-templates";
4
+ import { fileErrorCode, type ShimFileState } from "./shim-state-file";
5
+
6
+ type PlatformPath = typeof win32;
7
+
8
+ /**
9
+ * Validation for the legacy Codex shim record (codex-shim.json without schema/mode), which
10
+ * Windows installs still write. Every path a restore acts on is derived from the layout
11
+ * OpenCodex itself writes: launchers with fixed names, a backup that is the
12
+ * `.opencodex-real` sibling of the original, and all of them in one directory. The checks are
13
+ * pure functions over an injected path flavor so every OS can test them.
14
+ */
15
+
16
+ /** Path flavor of the host filesystem; independent of a test-overridden process.platform. */
17
+ export function hostShimPathApi(): PlatformPath {
18
+ return sep === "\\" ? win32 : posix;
19
+ }
20
+
21
+ /** The backup name OpenCodex gives an original launcher: the suffix goes before the extension. */
22
+ export function legacyShimBackupPath(path: string, api: PlatformPath = hostShimPathApi()): string {
23
+ const ext = api.extname(path);
24
+ return ext ? `${path.slice(0, -ext.length)}.opencodex-real${ext}` : `${path}.opencodex-real`;
25
+ }
26
+
27
+ /** In-place wrappers: the launcher npm writes is replaced by the shim at the same path. */
28
+ const IN_PLACE_LAUNCHERS = new Set(["codex.cmd", "codex.ps1", "codex"]);
29
+ /** The earliest Windows installs wrote codex.cmd next to the original launcher. */
30
+ const SIDE_BY_SIDE_ORIGINAL = /^codex(\.(exe|com|bat|cmd|ps1))?$/i;
31
+ const MAX_LEGACY_ENTRIES = 3;
32
+ const BACKUP_MARKER_SCAN_BYTES = 16 * 1024;
33
+
34
+ export type LegacyShimRecordVerdict =
35
+ | { ok: true; files: ShimFileState[]; directory: string }
36
+ | { ok: false; reason: string };
37
+
38
+ function isRecord(value: unknown): value is Record<string, unknown> {
39
+ return !!value && typeof value === "object" && !Array.isArray(value);
40
+ }
41
+
42
+ function pathProblem(path: unknown, api: PlatformPath): string | null {
43
+ if (typeof path !== "string" || path.length === 0) return "a launcher path is missing";
44
+ if (/[\x00-\x1f\x7f]/.test(path)) return "a launcher path contains control characters";
45
+ if (api === win32) {
46
+ if (!/^[A-Za-z]:\\/.test(path)) return "a launcher path is not an absolute drive path";
47
+ if (path.indexOf(":", 2) !== -1 || /[<>"|?*/]/.test(path)) return "a launcher path contains reserved characters";
48
+ if (path.slice(3).split("\\").some(segment => segment.length === 0 || /[. ]$/.test(segment))) {
49
+ return "a launcher path is not normalized";
50
+ }
51
+ } else if (!path.startsWith("/")) {
52
+ return "a launcher path is not absolute";
53
+ }
54
+ if (api.normalize(path) !== path || path.endsWith(api.sep)) return "a launcher path is not normalized";
55
+ return null;
56
+ }
57
+
58
+ function nameKey(path: string, api: PlatformPath): string {
59
+ return api.basename(path).toLowerCase();
60
+ }
61
+
62
+ /** Lexical validation: shape, platform, and the exact layout an OpenCodex install writes. */
63
+ export function validateLegacyWindowsShimRecord(value: unknown, api: PlatformPath = hostShimPathApi()): LegacyShimRecordVerdict {
64
+ const fail = (reason: string): LegacyShimRecordVerdict => ({ ok: false, reason });
65
+ if (!isRecord(value)) return fail("the shim record is not an object");
66
+ if (value.schema !== undefined || value.mode !== undefined) return fail("the shim record is not a Windows install record");
67
+ if (value.platform !== "win32") return fail("the shim record was not written by a Windows install");
68
+ const entries: unknown = value.wrappers !== undefined ? value.wrappers : [value];
69
+ if (!Array.isArray(entries) || entries.length === 0 || entries.length > MAX_LEGACY_ENTRIES) {
70
+ return fail("the shim record lists an unexpected number of launchers");
71
+ }
72
+ const files: ShimFileState[] = [];
73
+ for (const entry of entries) {
74
+ if (!isRecord(entry)) return fail("a shim record entry is not an object");
75
+ for (const key of ["wrapperPath", "originalPath", "backupPath"] as const) {
76
+ const problem = pathProblem(entry[key], api);
77
+ if (problem) return fail(problem);
78
+ }
79
+ const file = { wrapperPath: entry.wrapperPath as string, originalPath: entry.originalPath as string, backupPath: entry.backupPath as string };
80
+ if (entry.realPath !== undefined && entry.realPath !== file.backupPath) return fail("a launcher points at an unexpected backing file");
81
+ if (entry.preserveOnly !== undefined && entry.preserveOnly !== false) return fail("a launcher entry has an unexpected mode");
82
+ const directory = api.dirname(file.wrapperPath);
83
+ if (api.dirname(file.originalPath) !== directory || api.dirname(file.backupPath) !== directory) {
84
+ return fail("the launcher, its original and its backup are not in one directory");
85
+ }
86
+ if (file.wrapperPath === file.originalPath) {
87
+ if (!IN_PLACE_LAUNCHERS.has(nameKey(file.wrapperPath, api))) return fail("a launcher has an unexpected name");
88
+ } else if (entries.length !== 1 || nameKey(file.wrapperPath, api) !== "codex.cmd"
89
+ || !SIDE_BY_SIDE_ORIGINAL.test(api.basename(file.originalPath)) || nameKey(file.originalPath, api) === "codex.cmd") {
90
+ return fail("a launcher has an unexpected name");
91
+ }
92
+ if (file.backupPath !== legacyShimBackupPath(file.originalPath, api)) return fail("a backup is not the expected sibling of its original");
93
+ files.push(file);
94
+ }
95
+ if (value.wrappers !== undefined) {
96
+ const first = files[0]!;
97
+ for (const key of ["wrapperPath", "originalPath", "backupPath"] as const) {
98
+ if (value[key] !== undefined && value[key] !== first[key]) return fail("the shim record summary disagrees with its launcher list");
99
+ }
100
+ }
101
+ const directory = api.dirname(files[0]!.wrapperPath);
102
+ // Exact spelling: Windows directories can be case-sensitive, so differently cased names may differ.
103
+ if (files.some(file => api.dirname(file.wrapperPath) !== directory)) {
104
+ return fail("the launchers are not in one directory");
105
+ }
106
+ if (new Set(files.map(file => nameKey(file.wrapperPath, api))).size !== files.length) return fail("a launcher is listed twice");
107
+ return { ok: true, files, directory };
108
+ }
109
+
110
+ export interface LegacyShimDiskDeps {
111
+ lstat?: (path: string) => { isFile(): boolean; isDirectory(): boolean; isSymbolicLink(): boolean; size: number | bigint; nlink?: number | bigint; dev?: number | bigint; ino?: number | bigint };
112
+ realpath?: (path: string) => string;
113
+ readPrefix?: (path: string, bytes: number) => string;
114
+ }
115
+
116
+ export type LegacyShimDirectoryVerdict =
117
+ /** `resolved` is null when the recorded directory no longer exists: nothing to act on. */
118
+ | { ok: true; resolved: string | null; identity: string | null }
119
+ | { ok: false; reason: string };
120
+
121
+ function defaultReadPrefix(path: string, bytes: number): string {
122
+ const fd = openSync(path, "r");
123
+ try {
124
+ const buffer = Buffer.alloc(bytes);
125
+ let total = 0;
126
+ while (total < bytes) {
127
+ const count = readSync(fd, buffer, total, bytes - total, total);
128
+ if (count === 0) break;
129
+ total += count;
130
+ }
131
+ return buffer.subarray(0, total).toString("utf8");
132
+ } finally {
133
+ closeSync(fd);
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Resolves the recorded directory once and requires the resolved chain to hold only real
139
+ * directories. A link in the recorded spelling (an nvm-windows or scoop prefix) is accepted:
140
+ * it can only select a directory the record could name directly, and callers act on the
141
+ * resolved directory.
142
+ */
143
+ const defaultLstat = (path: string) => lstatSync(path, { bigint: true });
144
+
145
+ export function resolveLegacyShimDirectory(recordedDirectory: string, api: PlatformPath = hostShimPathApi(), deps: LegacyShimDiskDeps = {}): LegacyShimDirectoryVerdict {
146
+ const lstat = deps.lstat ?? defaultLstat;
147
+ const realpath = deps.realpath ?? realpathSync.native;
148
+ let resolved: string;
149
+ try {
150
+ resolved = realpath(recordedDirectory);
151
+ } catch (error) {
152
+ const code = fileErrorCode(error);
153
+ if (code === "ENOENT" || code === "ENOTDIR") return { ok: true, resolved: null, identity: null };
154
+ return { ok: false, reason: "the launcher directory could not be resolved" };
155
+ }
156
+ if (!api.isAbsolute(resolved)) return { ok: false, reason: "the launcher directory could not be resolved" };
157
+ let identity: string | null = null;
158
+ try {
159
+ for (let current = resolved; ; current = api.dirname(current)) {
160
+ const entry = lstat(current);
161
+ if (entry.isSymbolicLink() || !entry.isDirectory()) return { ok: false, reason: "the launcher directory resolves through a link" };
162
+ // Device and inode: a directory replaced at the same path is a different directory.
163
+ if (current === resolved) identity = `${entry.dev}:${entry.ino}`;
164
+ if (api.dirname(current) === current) break;
165
+ }
166
+ } catch {
167
+ return { ok: false, reason: "the launcher directory could not be inspected" };
168
+ }
169
+ return { ok: true, resolved, identity };
170
+ }
171
+
172
+ type EntryShape = "absent" | "file" | "shared" | "other";
173
+
174
+ function entryShape(path: string, lstat: NonNullable<LegacyShimDiskDeps["lstat"]>): { shape: EntryShape; size: number } {
175
+ try {
176
+ const entry = lstat(path);
177
+ if (entry.isSymbolicLink() || !entry.isFile()) return { shape: "other", size: 0 };
178
+ if (Number(entry.nlink ?? 1) > 1) return { shape: "shared", size: Number(entry.size) };
179
+ return { shape: "file", size: Number(entry.size) };
180
+ } catch (error) {
181
+ if (fileErrorCode(error) === "ENOENT") return { shape: "absent", size: 0 };
182
+ return { shape: "other", size: 0 };
183
+ }
184
+ }
185
+
186
+ /** File shapes inside the resolved directory: launchers are regular files, a backup is a non-empty non-shim file. */
187
+ export function legacyShimFilesProblem(files: readonly ShimFileState[], resolvedDirectory: string, api: PlatformPath = hostShimPathApi(), deps: LegacyShimDiskDeps = {}): string | null {
188
+ const lstat = deps.lstat ?? defaultLstat;
189
+ const readPrefix = deps.readPrefix ?? defaultReadPrefix;
190
+ for (const file of files) {
191
+ for (const launcher of new Set([file.wrapperPath, file.originalPath])) {
192
+ const shape = entryShape(api.join(resolvedDirectory, api.basename(launcher)), lstat).shape;
193
+ if (shape === "other") return "a launcher is not a regular file";
194
+ if (shape === "shared") return "a launcher shares its file with another path";
195
+ }
196
+ const backupPath = api.join(resolvedDirectory, api.basename(file.backupPath));
197
+ const backup = entryShape(backupPath, lstat);
198
+ if (backup.shape === "absent") continue;
199
+ if (backup.shape !== "file" || backup.size === 0) return "a backup is not a non-empty regular file";
200
+ try {
201
+ if (readPrefix(backupPath, BACKUP_MARKER_SCAN_BYTES).includes(SHIM_MARKER)) return "a backup is itself a shim";
202
+ } catch {
203
+ return "a backup could not be read";
204
+ }
205
+ }
206
+ return null;
207
+ }
208
+
209
+ export type LegacyShimCheck =
210
+ | { ok: true; files: ShimFileState[]; recordedDirectory: string; resolvedDirectory: string | null; directoryIdentity: string | null }
211
+ | { ok: false; reason: string };
212
+
213
+ /** Lexical layout, resolved directory, and file shapes, in that order. */
214
+ export function checkLegacyShimRecord(value: unknown, api: PlatformPath = hostShimPathApi(), deps: LegacyShimDiskDeps = {}): LegacyShimCheck {
215
+ const record = validateLegacyWindowsShimRecord(value, api);
216
+ if (!record.ok) return record;
217
+ const directory = resolveLegacyShimDirectory(record.directory, api, deps);
218
+ if (!directory.ok) return directory;
219
+ if (directory.resolved !== null) {
220
+ const problem = legacyShimFilesProblem(record.files, directory.resolved, api, deps);
221
+ if (problem) return { ok: false, reason: problem };
222
+ }
223
+ return { ok: true, files: record.files, recordedDirectory: record.directory, resolvedDirectory: directory.resolved, directoryIdentity: directory.identity };
224
+ }
225
+
226
+ /** A launcher a fresh install backs up must be a non-empty file; an empty backup is refused by every later restore. */
227
+ export function legacyShimFreshLaunchersProblem(files: readonly ShimFileState[], resolvedDirectory: string | null, api: PlatformPath = hostShimPathApi(), deps: LegacyShimDiskDeps = {}): string | null {
228
+ if (resolvedDirectory === null) return "the launcher directory is missing";
229
+ const lstat = deps.lstat ?? defaultLstat;
230
+ for (const file of files) {
231
+ const original = entryShape(api.join(resolvedDirectory, api.basename(file.originalPath)), lstat);
232
+ if (original.shape !== "file" || original.size === 0) return "a launcher is empty or not a regular file";
233
+ }
234
+ return null;
235
+ }
236
+
237
+ /** True when the recorded directory still resolves to the same link-free directory, by path and identity. */
238
+ export function legacyShimDirectoryUnchanged(recordedDirectory: string, resolvedDirectory: string | null, identity: string | null, api: PlatformPath = hostShimPathApi(), deps: LegacyShimDiskDeps = {}): boolean {
239
+ const now = resolveLegacyShimDirectory(recordedDirectory, api, deps);
240
+ return now.ok && now.resolved === resolvedDirectory && now.identity === identity;
241
+ }
242
+
243
+ let mutationGuard: (() => void) | null = null;
244
+
245
+ /**
246
+ * Binds every later Windows shim mutation to a validated record until the returned release runs:
247
+ * each rename, link, unlink and write first checks that the recorded directory still resolves to
248
+ * the directory that was validated.
249
+ */
250
+ export function setLegacyShimMutationGuard(check: Extract<LegacyShimCheck, { ok: true }> | null): () => void {
251
+ const previous = mutationGuard;
252
+ mutationGuard = check && (() => {
253
+ if (!legacyShimDirectoryUnchanged(check.recordedDirectory, check.resolvedDirectory, check.directoryIdentity)) {
254
+ throw new Error("Codex shim launcher directory changed after validation; refusing to modify it");
255
+ }
256
+ });
257
+ return () => { mutationGuard = previous; };
258
+ }
259
+
260
+ /** Throws when a guarded Windows shim operation would act outside its validated directory. */
261
+ export function assertLegacyShimMutationAllowed(): void {
262
+ mutationGuard?.();
263
+ }
264
+
265
+ /*
266
+ * The Windows shim modules import these instead of the node:fs calls, so every rename, unlink and
267
+ * link they make checks the active guard immediately before it runs. Without a guard they are the
268
+ * plain calls.
269
+ */
270
+ export function guardedRenameSync(from: string, to: string): void {
271
+ assertLegacyShimMutationAllowed();
272
+ renameSync(from, to);
273
+ }
274
+
275
+ export function guardedUnlinkSync(path: string): void {
276
+ assertLegacyShimMutationAllowed();
277
+ unlinkSync(path);
278
+ }
279
+
280
+ export function guardedLinkSync(from: string, to: string): void {
281
+ assertLegacyShimMutationAllowed();
282
+ linkSync(from, to);
283
+ }
284
+
285
+ export function legacyShimManualRestoreMessage(reason: string, statePath: string, partial = false): string {
286
+ const changed = partial
287
+ ? "The remaining launcher files were left as they are."
288
+ : "No launcher file was renamed or deleted.";
289
+ return `Codex autostart shim needs manual restore: ${reason}. ${changed} If Codex no longer starts, rename the launcher backup that carries the ".opencodex-real" suffix back to its original name, then delete ${statePath} and rerun.`;
290
+ }
@@ -1,7 +1,13 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { closeSync, constants, existsSync, fstatSync, linkSync, lstatSync, openSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
2
+ import { closeSync, constants, existsSync, fstatSync, lstatSync, openSync, statSync, writeFileSync } from "node:fs";
3
3
  import { dirname, extname, join } from "node:path";
4
4
  import { sameFingerprintAfterRename, sameStableShimPathProbe, shimPathFingerprint, stableShimPathProbe, type StableShimPathProbe } from "./shim-fingerprint";
5
+ import {
6
+ assertLegacyShimMutationAllowed,
7
+ guardedLinkSync as linkSync,
8
+ guardedRenameSync as renameSync,
9
+ guardedUnlinkSync as unlinkSync,
10
+ } from "./shim-legacy-record";
5
11
 
6
12
  /**
7
13
  * Identity of a directory entry: device, inode and whether the entry is itself a symbolic link.
@@ -52,6 +58,7 @@ function release(held: HeldFile | null): void {
52
58
 
53
59
  /** Create `path` exclusively (never through an existing entry or link), write it, and keep it open. */
54
60
  function createExclusive(path: string, content: string): HeldFile {
61
+ assertLegacyShimMutationAllowed();
55
62
  const flags = constants.O_RDWR | constants.O_CREAT | constants.O_EXCL
56
63
  | (process.platform === "win32" ? 0 : constants.O_NOFOLLOW);
57
64
  const fd = openSync(path, flags, 0o644);
@@ -149,7 +156,7 @@ export function refreshObsoleteWindowsShim(
149
156
  let moved: HeldFile | null = null;
150
157
  let stage: HeldFile | null = null;
151
158
  const discard = (path: string, held: HeldFile | null): void => {
152
- if (held && entryIs(path, held.identity)) { try { unlinkSync(path); } catch { /* already gone */ } }
159
+ if (held && entryIs(path, held.identity)) { try { unlinkSync(path); } catch { /* already gone, or the directory moved */ } }
153
160
  };
154
161
  /**
155
162
  * Put the moved wrapper back only onto an empty path, and only while the aside is still it. If the
@@ -12,6 +12,7 @@ import { basename, dirname, join } from "node:path";
12
12
  import { durableBunRuntime, type BunRuntimeSource, type DurableBunRuntime } from "../lib/bun-runtime";
13
13
  import { sameFileIdentity, type FileIdentity } from "../lib/file-identity";
14
14
  import { serviceApiTokenFilePath } from "../lib/service-secrets";
15
+ import { assertLegacyShimMutationAllowed } from "./shim-legacy-record";
15
16
  import {
16
17
  buildUnixCodexShim,
17
18
  buildWindowsCodexShim,
@@ -58,6 +59,12 @@ export function windowsShimContent(wrapperPath: string, realCodexPath: string, r
58
59
  export function writeShim(wrapperPath: string, realCodexPath: string, runtime?: DurableBunRuntime): FileIdentity | undefined {
59
60
  const { bun, bunRuntimeSource, cli } = cliEntry(runtime);
60
61
  if (process.platform === "win32") {
62
+ assertLegacyShimMutationAllowed();
63
+ // Never write through a link or a file another path shares: the write would land outside this wrapper.
64
+ const existing = (() => { try { return lstatSync(wrapperPath, { bigint: true }); } catch { return null; } })();
65
+ if (existing && (existing.isSymbolicLink() || !existing.isFile() || existing.nlink > 1n)) {
66
+ throw new Error("Codex shim wrapper path is not a private regular file; refusing to write through it");
67
+ }
61
68
  writeFileSync(wrapperPath, windowsShimContent(wrapperPath, realCodexPath, runtime), "utf8");
62
69
  return undefined;
63
70
  } else {