@bitkyc08/opencodex 2.97.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 (290) hide show
  1. package/bin/ocx.mjs +1 -1
  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-CEw0y0jR.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/google.ts +7 -7
  123. package/src/adapters/kiro/adapter.ts +18 -3
  124. package/src/adapters/kiro/conversation.ts +8 -8
  125. package/src/adapters/kiro/payload.ts +45 -12
  126. package/src/adapters/kiro/stream.ts +169 -12
  127. package/src/adapters/kiro/structured-output-json.ts +191 -0
  128. package/src/adapters/kiro/structured-output-schema.ts +542 -0
  129. package/src/adapters/kiro/structured-output.ts +367 -0
  130. package/src/adapters/kiro-constants.ts +9 -0
  131. package/src/adapters/kiro-tools.ts +14 -9
  132. package/src/adapters/kiro-wire.ts +9 -5
  133. package/src/adapters/openai-chat/messages.ts +58 -5
  134. package/src/adapters/openai-chat/mistral-image-limit.ts +50 -0
  135. package/src/adapters/openai-chat/passthrough.ts +5 -3
  136. package/src/adapters/openai-chat/tool-schema.ts +83 -13
  137. package/src/adapters/openai-responses/opengateway-input.ts +18 -6
  138. package/src/adapters/openai-responses/tool-output-recovery.ts +79 -0
  139. package/src/adapters/qoder/live-models.ts +115 -1
  140. package/src/claude/failure-verdict.ts +21 -0
  141. package/src/claude/inbound-content-options.ts +15 -2
  142. package/src/claude/inbound-model-options.ts +2 -1
  143. package/src/claude/inbound-records.ts +2 -0
  144. package/src/claude/inbound.ts +17 -11
  145. package/src/claude/outbound.ts +52 -23
  146. package/src/cli/capabilities-access-remote.ts +13 -0
  147. package/src/cli/capabilities-base.ts +1 -0
  148. package/src/cli/capabilities-provider-models.ts +3 -3
  149. package/src/cli/codex-shim-autorestore.ts +7 -0
  150. package/src/cli/config-command.ts +11 -2
  151. package/src/cli/connect.ts +17 -2
  152. package/src/cli/dispatch.ts +3 -1
  153. package/src/cli/doctor.ts +95 -7
  154. package/src/cli/index.ts +12 -7
  155. package/src/cli/link-apply-restart.ts +9 -2
  156. package/src/cli/models.ts +124 -38
  157. package/src/cli/registry.ts +1 -1
  158. package/src/cli/restart-failure.ts +17 -0
  159. package/src/cli/stop-approval.ts +2 -2
  160. package/src/cli/sync-command.ts +1 -1
  161. package/src/cli/sync-fanout.ts +15 -4
  162. package/src/cli/system-restart-client.ts +5 -0
  163. package/src/cli/uninstall-client-state.ts +12 -1
  164. package/src/cli/update-restart-child.ts +13 -3
  165. package/src/cli/update-restart-home.ts +6 -3
  166. package/src/cli/update-restart.ts +36 -19
  167. package/src/client/connect.ts +4 -1
  168. package/src/client/hub-client.ts +5 -0
  169. package/src/client/link-management-relay.ts +39 -2
  170. package/src/client/link-readiness.ts +3 -1
  171. package/src/client/machine-api.ts +2 -1
  172. package/src/client/machine-listener.ts +7 -0
  173. package/src/client/orphan-token-recovery.ts +322 -0
  174. package/src/codex/catalog/provider-models.ts +12 -4
  175. package/src/codex/native-profile-api.ts +27 -1
  176. package/src/codex/shim-diagnostics.ts +7 -0
  177. package/src/codex/shim-legacy-record.ts +290 -0
  178. package/src/codex/shim-windows-refresh.ts +9 -2
  179. package/src/codex/shim-wrapper-write.ts +7 -0
  180. package/src/codex/shim.ts +80 -21
  181. package/src/config/diagnostics.ts +9 -9
  182. package/src/config/load-degrade.ts +27 -27
  183. package/src/config/provider-validation.ts +9 -2
  184. package/src/config/removed-opencode-free-backup.ts +6 -3
  185. package/src/config/tracked-runtime-inspection.ts +3 -3
  186. package/src/generated/compatibility-version.json +219 -147
  187. package/src/images/loop.ts +2 -2
  188. package/src/lib/client-error-body.ts +37 -6
  189. package/src/lib/config-ownership-removal.ts +422 -0
  190. package/src/lib/config-ownership.ts +646 -81
  191. package/src/lib/context-overflow-verdict.ts +3 -3
  192. package/src/lib/crash-guard.ts +4 -2
  193. package/src/lib/desktop-cli-handoff.d.mts +3 -4
  194. package/src/lib/desktop-cli-handoff.mjs +7 -16
  195. package/src/lib/errors.ts +1 -0
  196. package/src/lib/local-management-capability.ts +3 -1
  197. package/src/lib/messages-error-body.ts +162 -0
  198. package/src/lib/messages-sse-error-presentation.ts +93 -0
  199. package/src/lib/passive-read.ts +9 -4
  200. package/src/lib/socks5-fetch.ts +21 -9
  201. package/src/lib/upstream-retry.ts +81 -1
  202. package/src/lib/windows-owner-acl.ts +9 -3
  203. package/src/lib/winsw.ts +5 -5
  204. package/src/lib/workflow-budget.ts +3 -1
  205. package/src/oauth/index.ts +7 -0
  206. package/src/oauth/store.ts +20 -10
  207. package/src/protocols/codecs/messages-ir.ts +15 -9
  208. package/src/protocols/encoders/adapter-events.ts +26 -7
  209. package/src/protocols/encoders/messages.ts +72 -28
  210. package/src/providers/antigravity-models.ts +45 -12
  211. package/src/providers/free-directory.ts +2 -2
  212. package/src/providers/reasoning-metadata.ts +2 -1
  213. package/src/providers/registry/entries-extended.ts +9 -0
  214. package/src/reasoning-effort.ts +7 -2
  215. package/src/remote/hub-usage.ts +3 -0
  216. package/src/server/admission-model-scope.ts +1 -1
  217. package/src/server/admitted-http-turn.ts +2 -1
  218. package/src/server/anthropic-rate-limit-headers.ts +75 -3
  219. package/src/server/claude-messages.ts +130 -67
  220. package/src/server/gui-static.ts +4 -1
  221. package/src/server/hub-usage.ts +7 -2
  222. package/src/server/index/link-management.ts +8 -0
  223. package/src/server/index/ollama-routes.ts +2 -0
  224. package/src/server/index/serve-options.ts +23 -20
  225. package/src/server/index/startup-warnings.ts +5 -12
  226. package/src/server/index/websocket-handler.ts +1 -0
  227. package/src/server/inference/client-encoder-delivery.ts +5 -1
  228. package/src/server/management/logs-usage-routes.ts +89 -4
  229. package/src/server/management/provider-routes.ts +2 -22
  230. package/src/server/management/qoder-provider-probe.ts +105 -0
  231. package/src/server/management/route-registry.ts +3 -0
  232. package/src/server/management/usage-aggregate-cache.ts +15 -5
  233. package/src/server/management/usage-source-facets.ts +38 -0
  234. package/src/server/messages-native-tool-guard.ts +11 -3
  235. package/src/server/messages-native.ts +111 -40
  236. package/src/server/messages-response-headers.ts +25 -11
  237. package/src/server/messages-shared.ts +94 -64
  238. package/src/server/messages-sse-error-filter.ts +199 -0
  239. package/src/server/request-log.ts +12 -0
  240. package/src/server/responses/adapter-continuation.ts +11 -5
  241. package/src/server/responses/adapter-delivery.ts +14 -8
  242. package/src/server/responses/adapter-dispatch.ts +8 -8
  243. package/src/server/responses/anthropic-thinking-recovery.ts +2 -2
  244. package/src/server/responses/codex-auth-error.ts +8 -4
  245. package/src/server/responses/codex-ws-wire.ts +19 -3
  246. package/src/server/responses/compact.ts +4 -1
  247. package/src/server/responses/core-auth.ts +1 -1
  248. package/src/server/responses/core-combo-failure.ts +2 -0
  249. package/src/server/responses/core-combo.ts +2 -0
  250. package/src/server/responses/core-errors.ts +5 -4
  251. package/src/server/responses/core-options.ts +2 -0
  252. package/src/server/responses/empty-completion-guard.ts +4 -1
  253. package/src/server/responses/pacing-overload.ts +1 -1
  254. package/src/server/responses/passthrough-dispatch.ts +5 -5
  255. package/src/server/responses/request-prepare.ts +3 -1
  256. package/src/server/responses/request-transport.ts +9 -8
  257. package/src/server/responses/response-effects.ts +3 -2
  258. package/src/server/responses/terminal-guard.ts +30 -0
  259. package/src/server/restart-replacement.ts +3 -1
  260. package/src/server/sse-payload-rewrite.ts +23 -11
  261. package/src/server/workflow-refusal.ts +1 -1
  262. package/src/server/ws-bridge.ts +4 -0
  263. package/src/service/definition.ts +36 -4
  264. package/src/service/launchd.ts +89 -32
  265. package/src/service/logging.ts +34 -7
  266. package/src/service/plist-xml.ts +59 -0
  267. package/src/service/state.ts +8 -0
  268. package/src/service/systemd-env.ts +2 -0
  269. package/src/service/systemd.ts +31 -7
  270. package/src/service/windows-taskxml.ts +16 -7
  271. package/src/service-manager-probe.ts +4 -10
  272. package/src/types/provider.ts +2 -0
  273. package/src/types/request.ts +13 -1
  274. package/src/update/config-preflight.ts +48 -0
  275. package/src/update/index.ts +15 -1
  276. package/src/usage/client.ts +43 -0
  277. package/src/usage/error-detail.ts +1 -1
  278. package/src/usage/log.ts +4 -0
  279. package/src/usage/source-facets.ts +51 -0
  280. package/src/usage/source-filter.ts +65 -0
  281. package/src/usage/summary.ts +50 -8
  282. package/src/web-search/anthropic-executor.ts +105 -24
  283. package/src/web-search/executor.ts +5 -3
  284. package/src/web-search/loop.ts +2 -1
  285. package/src/web-search/progress-stream.ts +64 -5
  286. package/gui/dist/assets/App-DuNhggE1.js +0 -58
  287. package/gui/dist/assets/index-CynE_Rue.js +0 -94
  288. package/gui/dist/assets/quota-summary-VHFSlUuM.js +0 -1
  289. /package/gui/dist/{assets → classic/assets}/App-B4j-Txmb.css +0 -0
  290. /package/gui/dist/{assets → classic/assets}/index-CHWwDo9L.css +0 -0
@@ -11,19 +11,21 @@
11
11
  import type { HomeCodexSettingsRecord } from "../client/link-home";
12
12
  import { findLiveProxy, probeHostname, type LiveProxy } from "../server/proxy-liveness";
13
13
  import type { ProxyRestartStartOutcome } from "./tray-proxy";
14
+ import type { RestartSupervisor } from "./restart-failure";
14
15
 
15
16
  export type ApplyRestartOutcome =
16
17
  | { kind: "current" }
17
18
  | { kind: "not-running" }
18
19
  | { kind: "connection-changed" }
19
20
  | { kind: "restarted" }
21
+ | { kind: "deferred-supervisor"; supervisor: RestartSupervisor }
20
22
  | { kind: "failed" };
21
23
 
22
24
  export interface ApplyRestartDeps {
23
25
  findLive?: () => Promise<LiveProxy | null>;
24
26
  /** Epoch ms the live client runtime reports as its start, or null when it reports none. */
25
27
  readStartedAt?: (live: LiveProxy) => Promise<number | null>;
26
- restart: (startWhenStopped: (recoveringLiveRestart: boolean) => Promise<ProxyRestartStartOutcome>) => Promise<boolean>;
28
+ restart: (startWhenStopped: (recoveringLiveRestart: boolean) => Promise<ProxyRestartStartOutcome>, onSupervised: (supervisor: RestartSupervisor) => void) => Promise<boolean>;
27
29
  recoveryStart: (recoveringLiveRestart: boolean) => Promise<ProxyRestartStartOutcome>;
28
30
  /** Still the connection this sync applied for (rechecked right before the restart). */
29
31
  connectionUnchanged: () => boolean;
@@ -54,9 +56,11 @@ export async function restartRuntimeAfterApply(record: HomeCodexSettingsRecord,
54
56
  const startedAt = await (deps.readStartedAt ?? (target => readClientRuntimeStartedAt(target)))(live);
55
57
  if (startedAt !== null && Number.isFinite(appliedAt) && startedAt >= appliedAt) return { kind: "current" };
56
58
  if (!deps.connectionUnchanged()) return { kind: "connection-changed" };
59
+ let supervisor: RestartSupervisor | undefined;
57
60
  const ok = await deps.restart(async recovering => recovering
58
61
  ? deps.recoveryStart(true)
59
- : { status: "skipped" });
62
+ : { status: "skipped" }, value => { supervisor = value; });
63
+ if (!ok && supervisor) return { kind: "deferred-supervisor", supervisor };
60
64
  return ok ? { kind: "restarted" } : { kind: "failed" };
61
65
  }
62
66
 
@@ -67,6 +71,9 @@ export function applyRestartMessage(outcome: ApplyRestartOutcome): string {
67
71
  case "not-running": return "No client runtime is running; the applied settings take effect when it starts.";
68
72
  case "connection-changed": return "The connection changed during sync; the client runtime was not restarted. Run 'ocx sync' again.";
69
73
  case "restarted": return "Client runtime restarted after applying the Home's settings.";
74
+ case "deferred-supervisor": return outcome.supervisor === "desktop"
75
+ ? "Client runtime restart deferred; the settings take effect when OpenCodex Desktop restarts it. Use Quit in the OpenCodex tray menu, then reopen OpenCodex."
76
+ : "Client runtime restart deferred; the settings take effect when the background service restarts it. Run `ocx service restart`.";
70
77
  case "failed": return "The client runtime restart did not complete; the previous runtime keeps serving. If a background service or the desktop app owns it, restart it there; otherwise retry with 'ocx restart' or 'ocx sync'.";
71
78
  }
72
79
  }
package/src/cli/models.ts CHANGED
@@ -6,7 +6,7 @@ import { resolveMatchedPrice, type MatchedPrice } from "../usage/cost";
6
6
  import { randomUUID } from "node:crypto";
7
7
  import { createInterface } from "node:readline/promises";
8
8
  import { syncModelsToCodex } from "../codex/sync";
9
- import { configuredContextWindow } from "../codex/catalog/provider-fetch";
9
+ import { applyRegistryCapabilitySeedFill, configuredContextWindow } from "../codex/catalog/provider-fetch";
10
10
  import { hasOwnProvider, isValidProviderName, loadConfig, saveConfig } from "../config";
11
11
  import { readCliConfigForMutation } from "./config-mutation";
12
12
  import {
@@ -16,6 +16,20 @@ import {
16
16
  import { encodedModelIdCollides, resolveSlugSelection, routedSlug } from "../providers/slug-codec";
17
17
  import { isModelsRuntimeSubcommand } from "./models-runtime-subcommands";
18
18
  import { knownModelIdsForProvider } from "../router";
19
+ import { azureVendorModelMetadata, enrichProviderFromRegistry, registryInputModalitiesForDestination } from "../providers/derive";
20
+ import { getProviderRegistryEntry } from "../providers/registry";
21
+ import { providerMatchesRegistryTransportWithStaticGuards } from "../providers/static-model-discovery";
22
+ import { resolveModelPolicy } from "../providers/resolved-model-policy";
23
+ import { customRowInputModalities } from "../vision/eligibility";
24
+ import { applyProviderContextCap, providerContextCap, resolveUnknownRoutedContextWindow } from "../providers/context-cap";
25
+ import { isCanonicalOpenAiForwardProvider, OPENAI_CODEX_PROVIDER_ID } from "../providers/openai-tiers";
26
+ import { reasoningCapabilitiesFromConfig } from "../providers/reasoning-capabilities";
27
+ import { dropLearnedUnsupportedReasoningEfforts, providerUsesReasoningMetadata } from "../providers/reasoning-metadata";
28
+ import { isKeychainReference } from "../providers/api-key-resolve";
29
+ import { hasNativeOpenAiCapabilityMetadata, nativeContextLimits, nativeDefaultReasoningEffort, nativeInputModalities, nativeOpenAiContextWindow, nativeReasoningEfforts } from "../codex/catalog/metadata";
30
+ import { canInferVendorContext, vendorContextInference } from "../codex/catalog/vendor-context";
31
+ import { terminalSafeText } from "./runtime-api";
32
+ import { runPassiveRead } from "../lib/passive-read";
19
33
  import { findLiveProxy } from "../server/proxy-liveness";
20
34
  import { modelInList, type OcxConfig, type OcxCustomModel } from "../types";
21
35
  import type { RuntimeApiDeps } from "./runtime-api";
@@ -28,6 +42,13 @@ const REMOVE_USAGE = "Usage: ocx models remove <customId|provider/modelId> [--ye
28
42
  const LIST_CUSTOM_USAGE = "Usage: ocx models list-custom [--json]";
29
43
  const ALLOWED_MODALITIES = new Set(["text", "image", "audio"]);
30
44
 
45
+ function printJson(value: unknown): void {
46
+ const encoded = JSON.stringify(value, null, 2);
47
+ if (encoded === undefined) throw new TypeError("Cannot serialize model output");
48
+ console.log(encoded.replace(/[\u007f-\u009f\u2028\u2029]/g, character =>
49
+ `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`));
50
+ }
51
+
31
52
  import { parseReasoningArgs } from "./models-custom-input";
32
53
  import { redactSecretArgs } from "./secret-args";
33
54
  export { parseReasoningArgs } from "./models-custom-input";
@@ -56,35 +77,91 @@ function collectModels(config: OcxConfig, providerFilter?: string): ModelEntry[]
56
77
  for (const [provName, prov] of Object.entries(providers)) {
57
78
  if (!prov) continue;
58
79
  const seen = new Set<string>();
59
- const inputModalities = prov.modelInputModalities ?? {};
80
+ // Model listing is read-only: derive effective registry policy on a private copy.
81
+ const effective = structuredClone(prov);
82
+ const registryMatches = providerMatchesRegistryTransportWithStaticGuards(provName, prov);
83
+ if (registryMatches) applyRegistryCapabilitySeedFill(provName, effective);
84
+ enrichProviderFromRegistry(provName, effective);
85
+ if (registryMatches) {
86
+ const policy = resolveModelPolicy({
87
+ providerName: provName, modelId: effective.defaultModel ?? "__catalog_capture__", provider: effective,
88
+ registryEntry: getProviderRegistryEntry(provName), transportMatchedRegistry: true,
89
+ ...(effective.authMode ? { effectiveAuth: { authMode: effective.authMode } } : {}),
90
+ }).provider;
91
+ Object.assign(effective, policy);
92
+ }
93
+ effective.inputModalities ??= registryInputModalitiesForDestination(provName, prov);
94
+ const routerKnown = new Set(knownModelIdsForProvider(provName, prov));
60
95
 
61
96
  /** Append one model with resolved metadata, ignoring duplicates within this provider. */
62
97
  const addModel = (model: string, isDefault: boolean) => {
63
98
  if (seen.has(model)) return;
64
99
  seen.add(model);
65
100
 
66
- // Resolve exactly as the runtime does, or this command reports capabilities the
67
- // proxy will not honour: `isModelTextOnly` matches noVisionModels with modelInList
68
- // and reads modelInputModalities with modelRecordValue, so a `gpt-oss` entry covers
69
- // `gpt-oss:120b`. A bare lookup reported that model as unclassified on every field.
70
- // noVisionModels is checked first because `isModelTextOnly` returns true on that
71
- // match before it ever reads modelInputModalities: a `gpt-oss` noVision entry beats
72
- // an exact `gpt-oss:120b` entry that lists "image", and the proxy rejects the image.
73
- const noVision = modelInList(prov.noVisionModels, model);
74
- const modalities = noVision ? ["text"] : (modelRecordValue(inputModalities, model) ?? null);
101
+ const custom = config.customModels?.find(row => row.provider === provName && row.modelId === model);
102
+ const nativeMetadata = custom && hasNativeOpenAiCapabilityMetadata(model);
103
+ const canonicalProvider = provName === OPENAI_CODEX_PROVIDER_ID && prov.authMode === undefined
104
+ ? { ...prov, authMode: "forward" as const } : prov;
105
+ const canonicalNativeCustom = nativeMetadata && provName === OPENAI_CODEX_PROVIDER_ID
106
+ && isCanonicalOpenAiForwardProvider(canonicalProvider);
107
+ const canInfer = canInferVendorContext(provName, effective);
108
+ const modelListEmpty = (effective.models?.length ?? 0) === 0;
109
+ const seededDefault = effective.defaultModel === model && modelListEmpty
110
+ && (effective.liveModels === false || (effective.adapter === "google" && effective.googleMode === "vertex"));
111
+ const hintEligible = !custom || canInfer || routerKnown.has(model) || (effective.models ?? []).includes(model)
112
+ || (effective.retainModels ?? []).includes(model) || seededDefault;
113
+ const azureMetadata = hintEligible ? azureVendorModelMetadata(effective.baseUrl, model, getConfigDir()) : undefined;
114
+ const capability = Object.hasOwn(effective.modelCapabilities ?? {}, model)
115
+ ? effective.modelCapabilities?.[model]?.inputModalities : undefined;
116
+ const customModalities = customRowInputModalities(config, provName, model);
117
+ const modalities = capability ?? customModalities ?? (modelInList(effective.noVisionModels, model)
118
+ ? ["text"] : modelRecordValue(effective.modelInputModalities, model) ?? effective.inputModalities
119
+ ?? azureMetadata?.input ?? (canonicalNativeCustom ? nativeInputModalities(model) : null));
75
120
  // Same reason, for the ladder: `configuredReasoningEfforts` is what the catalog
76
121
  // (`provider-fetch`) and the effort cap (`effort-policy`) resolve through, and it
77
122
  // does three things this expression did not — it returns [] for a noReasoningModels
78
123
  // match, drops levels Codex does not declare, and re-adds tiers the wire map proves
79
124
  // the model emits. Restating two of its five lines here reported a ladder the proxy
80
125
  // strips, and unsanitized junk as a supported level.
81
- const efforts = configuredReasoningEfforts(prov, model) ?? null;
126
+ const declaredEfforts = custom?.reasoningEfforts ?? modelRecordValue(effective.modelReasoningEfforts, model) ?? effective.reasoningEfforts;
127
+ // A passive CLI cannot resolve an OS-keychain reference to select account-scoped refusals.
128
+ // Report unknown rather than opening the keychain or claiming an unverifiable ladder.
129
+ const unobservedCredential = providerUsesReasoningMetadata(effective) && isKeychainReference(effective.apiKey);
130
+ let efforts = reasoningCapabilitiesFromConfig(effective, model).supportsReasoningEffort === false || declaredEfforts?.length === 0
131
+ ? [] : unobservedCredential ? null : custom?.reasoningEfforts ?? configuredReasoningEfforts(effective, model, { refreshMetadata: false })
132
+ ?? (canonicalNativeCustom ? nativeReasoningEfforts(model) : null);
133
+ if (nativeMetadata && efforts && efforts.length > 0) {
134
+ const allowed = nativeReasoningEfforts(model);
135
+ if (allowed.length > 0) {
136
+ const declared = new Set(efforts);
137
+ const surviving = [...new Set(allowed)].filter(effort => declared.has(effort));
138
+ const defaultEffort = nativeDefaultReasoningEffort(model);
139
+ efforts = surviving.length > 0 ? surviving : [defaultEffort && allowed.includes(defaultEffort) ? defaultEffort : allowed[0]!];
140
+ }
141
+ }
142
+ if (efforts) efforts = dropLearnedUnsupportedReasoningEfforts(effective, model, efforts);
143
+ const nativeCustomContext = canonicalNativeCustom
144
+ ? nativeOpenAiContextWindow(model, {
145
+ ...nativeContextLimits(config),
146
+ ...(custom.contextWindow ? { modelWindows: { ...nativeContextLimits(config).modelWindows, [model]: custom.contextWindow } } : {}),
147
+ }) : undefined;
148
+ const cap = providerContextCap(config, provName);
149
+ const explicitContext = nativeCustomContext ?? custom?.contextWindow;
150
+ const configuredContext = hintEligible ? configuredContextWindow(effective, model) : undefined;
151
+ const azureWindow = explicitContext === undefined && configuredContext === undefined
152
+ ? azureMetadata?.contextWindow : undefined;
153
+ const azureContext = Number.isSafeInteger(azureWindow) && azureWindow! > 0 ? azureWindow : undefined;
154
+ const inferredContext = explicitContext === undefined && configuredContext === undefined && azureContext === undefined && canInfer
155
+ ? vendorContextInference(model)?.contextWindow : undefined;
156
+ const fallbackContext = hintEligible && cap !== undefined ? resolveUnknownRoutedContextWindow(cap) : undefined;
157
+ const contextWindow = explicitContext
158
+ ?? applyProviderContextCap(configuredContext ?? azureContext ?? inferredContext ?? fallbackContext, cap);
82
159
 
83
160
  entries.push({
84
161
  provider: provName,
85
162
  model,
86
163
  isDefault,
87
- contextWindow: configuredContextWindow(prov, model) ?? null,
164
+ contextWindow: contextWindow ?? null,
88
165
  inputModalities: modalities,
89
166
  reasoningEfforts: efforts,
90
167
  price: resolveMatchedPrice(provName, model),
@@ -94,9 +171,17 @@ function collectModels(config: OcxConfig, providerFilter?: string): ModelEntry[]
94
171
  // defaultModel first
95
172
  if (prov.defaultModel) addModel(prov.defaultModel, true);
96
173
 
97
- // models array
98
- if (prov.models) {
99
- for (const m of prov.models) addModel(m, m === prov.defaultModel);
174
+ // Keep the CLI list current when this config predates a provider's registry seed.
175
+ // knownModelIdsForProvider is the router's own derivation: config models first, then
176
+ // registry seeds, hint-map keys, and live-discovered cache ids (registry-derived
177
+ // sources only enter when the router's registry transport guard matches), then customModels.
178
+ // Some legacy key presets retain registry ownership even after a destination change. Because hint-map keys
179
+ // are included, wire-only ids a provider's collapsed picker hides still appear here;
180
+ // that is router parity. A model the user pruned from `models` reappears if the
181
+ // registry still seeds it -- the list is a union, not the user's curation. The
182
+ // user's saved models remain first and are never discarded.
183
+ for (const m of [...(prov.models ?? []), ...knownModelIdsForProvider(provName, prov, config)]) {
184
+ addModel(m, m === prov.defaultModel);
100
185
  }
101
186
  }
102
187
 
@@ -119,8 +204,8 @@ function consumeFlagValue(args: string[], flag: string): string | undefined {
119
204
  }
120
205
 
121
206
  function fail(message: string, usage?: string): never {
122
- console.error(`Error: ${message}`);
123
- if (usage) console.error(usage);
207
+ console.error(`Error: ${terminalSafeText(message)}`);
208
+ if (usage) console.error(terminalSafeText(usage));
124
209
  process.exit(1);
125
210
  }
126
211
 
@@ -150,13 +235,13 @@ function printCustomMutation(action: "added" | "removed", model: OcxCustomModel,
150
235
  const complete = sync.configApplied === true && sync.ok;
151
236
  if (sync.status !== "not-attempted" && (!sync.ok || sync.status === "refused")) process.exitCode = 1;
152
237
  if (wantsJson) {
153
- console.log(JSON.stringify({ action,
238
+ printJson({ action,
154
239
  model: action === "added" ? model : { id: model.id, provider: model.provider, modelId: model.modelId },
155
- needsSync: !complete, sync }, null, 2));
240
+ needsSync: !complete, sync });
156
241
  return;
157
242
  }
158
- if (sync.warning) console.log(`Warning: ${sync.warning}`);
159
- console.log(`${action === "added" ? "Added" : "Removed"} custom model ${routedSlug(model.provider, model.modelId)}${action === "added" ? ` (${model.id})` : ""}.`);
243
+ if (sync.warning) console.log(`Warning: ${terminalSafeText(sync.warning)}`);
244
+ console.log(`${action === "added" ? "Added" : "Removed"} custom model ${terminalSafeText(routedSlug(model.provider, model.modelId))}${action === "added" ? ` (${terminalSafeText(model.id)})` : ""}.`);
160
245
  if (sync.status === "skipped") console.log("Custom model saved; client sync was skipped by the integration policy.");
161
246
  else if (!complete && sync.status !== "not-attempted") console.log("Custom model saved; client/catalog sync remains incomplete. Inspect the target before retrying.");
162
247
  }
@@ -241,7 +326,7 @@ async function confirmCustomRemoval(model: OcxCustomModel): Promise<boolean> {
241
326
  }
242
327
  const rl = createInterface({ input: process.stdin, output: process.stdout });
243
328
  try {
244
- const answer = (await rl.question(`Remove custom model ${routedSlug(model.provider, model.modelId)}? [y/N] `)).trim().toLowerCase();
329
+ const answer = (await rl.question(`Remove custom model ${terminalSafeText(routedSlug(model.provider, model.modelId))}? [y/N] `)).trim().toLowerCase();
245
330
  return answer === "y" || answer === "yes";
246
331
  } finally {
247
332
  rl.close();
@@ -331,11 +416,11 @@ function customModelCells(model: OcxCustomModel): string[] {
331
416
  }
332
417
 
333
418
  function printCustomModelGroup(provider: string, models: OcxCustomModel[]): void {
334
- const rows = models.map(customModelCells);
419
+ const rows = models.map(model => customModelCells(model).map(terminalSafeText));
335
420
  const headers = ["ID", "MODEL", "DISPLAY NAME", "CONTEXT", "MODALITIES", "EFFORTS", "DEFAULT EFFORT"];
336
421
  const widths = headers.map((header, column) => Math.max(header.length, ...rows.map(row => row[column].length)));
337
422
  const line = (cells: string[]) => cells.map((cell, column) => cell.padEnd(widths[column])).join(" ");
338
- console.log(`${provider}:`);
423
+ console.log(`${terminalSafeText(provider)}:`);
339
424
  console.log(` ${line(headers)}`);
340
425
  for (const row of rows) console.log(` ${line(row)}`);
341
426
  console.log();
@@ -347,7 +432,7 @@ function handleCustomList(args: string[]): void {
347
432
  rejectUnexpectedArgs(rest, LIST_CUSTOM_USAGE);
348
433
  const models = loadConfig().customModels ?? [];
349
434
  if (wantsJson) {
350
- console.log(JSON.stringify(models, null, 2));
435
+ printJson(models);
351
436
  return;
352
437
  }
353
438
  if (models.length === 0) {
@@ -372,9 +457,9 @@ function handleConfiguredModels(args: string[]): void {
372
457
  const shown = redactSecretArgs(restArgs);
373
458
  const unknown = shown.filter(a => a.startsWith("-"));
374
459
  if (unknown.length > 0) {
375
- console.error(`Unknown flag(s): ${unknown.join(", ")}`);
460
+ console.error(`Unknown flag(s): ${terminalSafeText(unknown.join(", "))}`);
376
461
  } else {
377
- console.error(`Unexpected argument(s): ${shown.join(", ")}`);
462
+ console.error(`Unexpected argument(s): ${terminalSafeText(shown.join(", "))}`);
378
463
  }
379
464
  console.error("Usage: ocx models [--provider <name>] [--json]");
380
465
  process.exit(1);
@@ -383,23 +468,24 @@ function handleConfiguredModels(args: string[]): void {
383
468
  const config = loadConfig();
384
469
 
385
470
  if (providerFilter && !hasOwnProvider(config.providers, providerFilter)) {
386
- console.error(`Provider "${providerFilter}" is not configured. See: ocx provider list`);
471
+ console.error(`Provider "${terminalSafeText(providerFilter)}" is not configured. See: ocx provider list`);
387
472
  process.exit(1);
388
473
  }
389
474
 
390
475
  const models = collectModels(config, providerFilter ?? undefined);
476
+ const note = "Local saved and router-known IDs include registry seeds, custom models and this process's discovery cache. Reasoning may be unknown for keychain credentials. Use ocx models live for the running catalog.";
391
477
 
392
478
  if (wantsJson) {
393
- console.log(JSON.stringify({
479
+ printJson({
394
480
  models,
395
- note: "Static config models only. Providers with liveModels=true may have additional models at runtime.",
396
- }, null, 2));
481
+ note,
482
+ });
397
483
  return;
398
484
  }
399
485
 
400
486
  if (models.length === 0) {
401
487
  console.log("No models found in configured providers.");
402
- if (!providerFilter) console.log("Providers may discover models dynamically at runtime (liveModels).");
488
+ console.log(`Note: ${note}`);
403
489
  return;
404
490
  }
405
491
 
@@ -413,19 +499,19 @@ function handleConfiguredModels(args: string[]): void {
413
499
 
414
500
  for (const [provName, provModels] of byProvider) {
415
501
  const isDefaultProv = provName === config.defaultProvider ? " (default provider)" : "";
416
- console.log(`${provName}${isDefaultProv}:`);
502
+ console.log(`${terminalSafeText(provName)}${isDefaultProv}:`);
417
503
  for (const m of provModels) {
418
504
  const marker = m.isDefault ? " *" : "";
419
505
  const ctx = m.contextWindow ? ` (${Math.round(m.contextWindow / 1000)}k)` : "";
420
506
  const rates = m.price?.cost4;
421
507
  const pricing = rates ? ` ~$${rates.input}/$${rates.output} input/output per 1M tokens` : " price unknown";
422
- console.log(` ${m.model}${marker}${ctx}${pricing}`);
508
+ console.log(` ${terminalSafeText(m.model)}${marker}${ctx}${pricing}`);
423
509
  }
424
510
  console.log();
425
511
  }
426
512
 
427
513
  console.log("* = default model for provider");
428
- console.log("Note: providers with liveModels may have additional models at runtime.");
514
+ console.log(`Note: ${note}`);
429
515
  }
430
516
 
431
517
  export async function handleModels(args: string[], deps: ModelsCommandDeps = {}): Promise<void> {
@@ -451,7 +537,7 @@ export async function handleModels(args: string[], deps: ModelsCommandDeps = {})
451
537
  return;
452
538
  }
453
539
  if (subcommand === "list-custom") {
454
- handleCustomList(rest);
540
+ await runPassiveRead(async () => { handleCustomList(rest); }, { onDiagnostic: message => console.error(message) });
455
541
  return;
456
542
  }
457
543
  if (isModelsRuntimeSubcommand(subcommand)) {
@@ -460,5 +546,5 @@ export async function handleModels(args: string[], deps: ModelsCommandDeps = {})
460
546
  if (code !== null) process.exitCode = code;
461
547
  return;
462
548
  }
463
- handleConfiguredModels(subcommand === "list" ? rest : args);
549
+ await runPassiveRead(async () => { handleConfiguredModels(subcommand === "list" ? rest : args); }, { onDiagnostic: message => console.error(message) });
464
550
  }
@@ -379,7 +379,7 @@ export const CLI_COMMANDS: CliCommandEntry[] = [
379
379
  usage: "ocx models <list|live|add|edit|remove|enable|disable|provider|selected|preset|context|shadow> ...",
380
380
  summary: "List models and manage custom (manually registered) models.",
381
381
  details: [
382
- "List available models from static config with no subcommand (liveModels may add more at runtime).",
382
+ "List available models: saved and router-known IDs include custom models and the process-local cache; models live reads the running proxy catalog.",
383
383
  "add/remove support --live for the selected proxy; live or JSON removal requires --yes.",
384
384
  "Local add/remove JSON reports saved state and opportunistic sync; no proxy keeps the save successful/pending.",
385
385
  "display-name <provider/raw-model> --set <label> or --clear changes an exact upstream model label.",
@@ -1,5 +1,22 @@
1
1
  import type { ProxyRestartResult } from "./tray-proxy";
2
2
 
3
+ export type RestartSupervisor = "desktop" | "service";
4
+
5
+ /** Only the bound client's explicit refusal establishes a supervisor for sync. */
6
+ export function supervisedRestartRefusal(result: ProxyRestartResult): RestartSupervisor | null {
7
+ if (result.ok || result.phase !== "request" || !(result.error instanceof Error)) return null;
8
+ if (result.error.message === "restart_supervised_desktop") return "desktop";
9
+ if (result.error.message === "restart_supervised_service") return "service";
10
+ return null;
11
+ }
12
+
13
+ export function deferSupervisedRestart(result: ProxyRestartResult, notify: (supervisor: RestartSupervisor) => void): boolean {
14
+ const supervisor = supervisedRestartRefusal(result);
15
+ if (!supervisor) return false;
16
+ notify(supervisor);
17
+ return true;
18
+ }
19
+
3
20
  export const INCOMPLETE_INSTALL_RECOVERY = "If the installer already exited or failed, run `ocx status`, stop any running proxy through its owner (`ocx stop`, or its service or desktop app), then reinstall with the same package manager and start it again (see https://opencodex.me/troubleshooting/update-failed/).";
4
21
 
5
22
  export function reportRestartFailure(result: Extract<ProxyRestartResult, { ok: false }>): void {
@@ -27,7 +27,7 @@ export interface GuardedStopSnapshot {
27
27
  * inspection probe -- it carries no path, command line, stderr, or token.
28
28
  */
29
29
  export type TrackedRuntimeCheck =
30
- | { pid: number; port: number; hostname: string }
30
+ | { pid: number; port: number; hostname: string | undefined }
31
31
  | { untracked: string }
32
32
  | null;
33
33
 
@@ -145,7 +145,7 @@ export async function runApprovedStop(
145
145
  return approvalChanged(`the tracked runtime record could not be verified (${target.untracked})`);
146
146
  }
147
147
  if (target.pid !== expected.pid || target.port !== expected.port
148
- || target.hostname !== expected.hostname) {
148
+ || (target.hostname === undefined ? expected.hostname !== "127.0.0.1" : target.hostname !== expected.hostname)) {
149
149
  return approvalChanged("the tracked runtime record changed");
150
150
  }
151
151
  if (manager.kind === "unknown") {
@@ -86,7 +86,7 @@ export async function runSyncCommand(deps: CliDispatchDeps): Promise<number> {
86
86
  const { sameClientConnectionOwner } = await import("../client/state");
87
87
  const applied = result.connection;
88
88
  const outcome = await restartRuntimeAfterApply(result.appliedRecord, {
89
- restart: startWhenStopped => deps.handleProxyRestart(startWhenStopped),
89
+ restart: (startWhenStopped, onSupervised) => deps.handleProxyRestart(startWhenStopped, onSupervised),
90
90
  recoveryStart: recovering => deps.handleRestartStartWhenStopped(recovering),
91
91
  connectionUnchanged: () => {
92
92
  const current = readClientConnectionState();
@@ -82,9 +82,20 @@ export function classifySyncResult(result: { code: number; stdout: string; stder
82
82
  }
83
83
 
84
84
  export type HomeResult = { state: "synced" | "stale" | "skipped" | "failed"; exit: number };
85
- export type ChildResult = { linkId: string; alias: string; state: "synced" | "skipped" | "failed" | "timed-out"; reason: string | null; exit: number | null };
85
+ export type ChildResult = { linkId: string; alias: string; state: "synced" | "skipped" | "failed" | "timed-out"; reason: string | null; exit: number | null; hint?: string };
86
86
  export type FanoutDocument = { schema: "ocx.sync.fanout/1"; home: HomeResult; fanout: { state: "ran" | "disabled" | "not-applicable" | "failed"; reason: string | null }; children: ChildResult[] };
87
87
 
88
+ function childSkipHint(reason: string | null, alias: string): string {
89
+ if (reason === "child-ocx-lacks-expect-link") return `Update OpenCodex on ${alias} to >= 2.93.0 using the installer that owns its selected ocx. For Desktop on headless Windows, use Check for Updates in the signed-in Desktop tray.`;
90
+ if (reason === "child-updating") return "Wait for the Child update to finish, then retry sync.";
91
+ if (reason === "child-link-mismatch:pending_operation" || reason === "child-link-mismatch:disconnect_pending") return "Wait for the Child's link operation to finish, then check its link and retry sync.";
92
+ if (reason === "child-link-mismatch:disconnected" || reason === "child-link-mismatch:other_link") return "Please re-link this Child to this Home, then retry sync.";
93
+ if (reason?.startsWith("child-link-mismatch")) return "Check the Child's Remote Link connection and re-link it to this Home if needed, then retry sync.";
94
+ if (reason === "child-ocx-version-unknown") return "Check the Child's selected OpenCodex installation and version, then retry sync.";
95
+ if (reason === "child-platform-unsupported") return "Check the Child's platform and Remote Link setup before retrying sync.";
96
+ return "Check the Child's sync status and retry sync.";
97
+ }
98
+
88
99
  export async function runHomeFanout(deps: {
89
100
  home: HomeResult; catalogCurrent: boolean; localOnly?: boolean; applicable?: boolean;
90
101
  readStore: () => LinkStore; readLinkStatus: () => Promise<LinkStatusDto>;
@@ -130,7 +141,7 @@ export async function runHomeFanout(deps: {
130
141
  timer = setTimeout(() => resolve({ state: "timed-out", reason: "termination-unconfirmed", exit: null }), budget + (deps.terminationGraceMs ?? 3000));
131
142
  }),
132
143
  ]);
133
- result.children[index] = { linkId: link.id, alias: link.alias, ...child };
144
+ result.children[index] = { linkId: link.id, alias: link.alias, ...child, ...(child.state === "skipped" ? { hint: childSkipHint(child.reason, link.alias) } : {}) };
134
145
  } catch { result.children[index] = classify(link, "failed", "internal-error"); }
135
146
  finally { if (timer !== undefined) clearTimeout(timer); }
136
147
  }
@@ -141,10 +152,10 @@ export async function runHomeFanout(deps: {
141
152
 
142
153
  export function fanoutExitCode(document: FanoutDocument): number {
143
154
  if (document.home.exit !== 0) return document.home.exit;
144
- return document.fanout.state === "failed" || document.children.some(child => child.state === "failed" || child.state === "timed-out") ? SYNC_FANOUT_PARTIAL_EXIT : 0;
155
+ return document.fanout.state === "failed" || document.children.some(child => child.state === "failed" || child.state === "timed-out" || (child.state === "skipped" && child.hint !== undefined)) ? SYNC_FANOUT_PARTIAL_EXIT : 0;
145
156
  }
146
157
 
147
158
  export function renderFanoutJson(document: FanoutDocument): string { return JSON.stringify(document); }
148
159
  export function renderFanoutHuman(document: FanoutDocument): string[] {
149
- return document.children.map(child => `${child.alias} (${child.linkId}): ${child.state}${child.reason ? ` (${child.reason})` : ""}`);
160
+ return document.children.map(child => `${child.alias} (${child.linkId}): ${child.state}${child.reason ? ` (${child.reason})` : ""}${child.hint ? ` — ${child.hint}` : ""}`);
150
161
  }
@@ -164,6 +164,11 @@ export async function requestBoundSystemRestart(
164
164
  if (!sameRestartTarget(target, observed)) return rejected("restart_target_changed");
165
165
  if (skew.relation === "cli-newer") {
166
166
  if (!updateHome) return rejected("update_restart_home_unverified");
167
+ try {
168
+ if (JSON.stringify((deps.readUpdateHome ?? readUpdateRestartHome)()) !== JSON.stringify(updateHome)) {
169
+ return rejected("update_restart_home_changed");
170
+ }
171
+ } catch { return rejected("update_restart_home_changed"); }
167
172
  const current = readRuntime(target.pid);
168
173
  if (!current || current.pid !== runtime.pid || current.port !== runtime.port
169
174
  || current.hostname !== runtime.hostname || current.attestationSecret !== runtime.attestationSecret) {
@@ -3,7 +3,7 @@ import { disconnectClient } from "../client/connect";
3
3
  import { readClientConnectionState, sameClientConnectionOwner } from "../client/state";
4
4
  import { assertClientLifecycleHeld, withClientLifecycle } from "../client/lifecycle-lock";
5
5
  import { inspectRemoteDesktopCleanup, readDesktopDisconnectReceipt } from "../claude/desktop-remote-store";
6
- import { removeOwnedConfigState, type ConfigRemovalResult } from "../lib/config-ownership";
6
+ import { beginConfigOwnershipTeardown, removeOwnedConfigState, type ConfigRemovalResult } from "../lib/config-ownership";
7
7
  import { windowsSecretAclReapPendingAtOrBelow } from "../lib/windows-secret-acl";
8
8
  import { supportsDesktopPicker } from "../claude/desktop-picker-platform";
9
9
  import { sharedTeardownAuthorized, type UninstallObservation } from "./uninstall-plan";
@@ -63,6 +63,17 @@ export async function removeOwnedConfigAfterDesktopCleanup(
63
63
  if (!sharedTeardownAuthorized(observed)) {
64
64
  throw new Error("Client cleanup refused: service or proxy teardown is not proven.");
65
65
  }
66
+ // A rerun after an interrupted uninstall finds the tombstone; this process's own cleanup steps
67
+ // (picker, disconnect, integrations) still register state, which the remover below then removes.
68
+ const endTeardown = beginConfigOwnershipTeardown();
69
+ try {
70
+ return await removeOwnedConfigInTeardown(deps);
71
+ } finally {
72
+ endTeardown();
73
+ }
74
+ }
75
+
76
+ async function removeOwnedConfigInTeardown(deps: UninstallClientStateDeps): Promise<ConfigRemovalResult> {
66
77
  const state = deps.readConnection();
67
78
  if (state.kind !== "connected" && state.kind !== "disconnected") {
68
79
  throw new Error("Client cleanup refused: connection state is invalid or mismatched.");
@@ -1,4 +1,5 @@
1
1
  import { existsSync } from "node:fs";
2
+ import { isIP } from "node:net";
2
3
  import { getRuntimePortPath, readRuntimePort } from "../config/process-state";
3
4
  import { packageVersion } from "../lib/package-version";
4
5
  import { parseStrictSemver } from "../lib/strict-semver";
@@ -10,12 +11,21 @@ export const UPDATE_RESTART_CHILD_ENV = "OCX_UPDATE_RESTART_CHILD";
10
11
  export interface UpdateRestartChildMarker { home: UpdateRestartHome; version: string; port: number; hostname: string; deadlineAt: number }
11
12
  export interface UpdateRestartChildGuard { check(port?: number, hostname?: string): void; complete(): void }
12
13
 
13
- function parseMarker(raw: string): UpdateRestartChildMarker {
14
+ function safeBindHost(host: string): boolean {
15
+ if (!host || host.length > 255 || host !== host.trim()) return false;
16
+ if (host.startsWith("[") || host.endsWith("]")) {
17
+ return host.startsWith("[") && host.endsWith("]") && isIP(host.slice(1, -1)) === 6;
18
+ }
19
+ return isIP(host) !== 0 || /^(?:\*|0|(0+\.){3}0+)\.?$/.test(host);
20
+ }
21
+
22
+ export function parseUpdateRestartMarker(raw: string): UpdateRestartChildMarker {
14
23
  if (raw.length > 8192) throw new Error("update_restart_child_marker_invalid");
15
24
  const value = JSON.parse(raw) as UpdateRestartChildMarker;
16
25
  if (!value || !Number.isSafeInteger(value.deadlineAt) || !Number.isInteger(value.port)
17
- || typeof value.hostname !== "string" || value.port < 1 || value.port > 65535 || typeof value.version !== "string"
26
+ || typeof value.hostname !== "string" || !safeBindHost(value.hostname) || value.port < 1 || value.port > 65535 || typeof value.version !== "string"
18
27
  || value.version === "0.0.0" || !parseStrictSemver(value.version) || !value.home
28
+ || !(value.home.diagnosedHostname === null || (typeof value.home.diagnosedHostname === "string" && safeBindHost(value.home.diagnosedHostname)))
19
29
  || !Number.isSafeInteger(value.home.revision) || value.home.serviceRecord?.schema !== 1
20
30
  || typeof value.home.serviceRecord.digest !== "string" || !/^[a-f0-9]{64}$/.test(value.home.serviceRecord.digest)) throw new Error("update_restart_child_marker_invalid");
21
31
  for (const directory of [value.home.config, value.home.codex]) {
@@ -49,7 +59,7 @@ export function admitUpdateRestartChild(argv: string[], io: UpdateRestartChildIo
49
59
  if (raw === undefined) return undefined;
50
60
  delete env[UPDATE_RESTART_CHILD_ENV];
51
61
  delete env[OWNERSHIP_MUTATION_LEASE_TOKEN_ENV];
52
- const marker = parseMarker(raw);
62
+ const marker = parseUpdateRestartMarker(raw);
53
63
  if (argv.length !== 3 || argv[0] !== "start" || argv[1] !== "--port" || argv[2] !== String(marker.port)) {
54
64
  throw new Error("update_restart_child_command_changed");
55
65
  }
@@ -18,6 +18,7 @@ export interface UpdateRestartHome {
18
18
  codex: UpdateRestartDirectory;
19
19
  revision: number;
20
20
  serviceRecord: UpdateRestartServiceRecord;
21
+ diagnosedHostname: string | null;
21
22
  }
22
23
 
23
24
  export type UpdateRestartDirectoryStat = Pick<BigIntStats, "dev" | "ino" | "isDirectory">;
@@ -44,7 +45,9 @@ export function readUpdateRestartHome(deps: UpdateRestartHomeDeps = {}): UpdateR
44
45
  throw new Error("update_restart_owner_unverified");
45
46
  }
46
47
  const stat = deps.statDirectory ?? (path => statSync(path, { bigint: true }));
47
- return { config: physicalDirectory(getConfigDir(), stat), codex: physicalDirectory(currentCodexHome(), stat), revision: owner.revision, serviceRecord };
48
+ const diagnostics = readConfigDiagnostics({ passive: true });
49
+ if (diagnostics.error) throw new Error("update_restart_configuration_unverified");
50
+ return { config: physicalDirectory(getConfigDir(), stat), codex: physicalDirectory(currentCodexHome(), stat), revision: owner.revision, serviceRecord, diagnosedHostname: diagnostics.config.hostname ?? null };
48
51
  }
49
52
 
50
53
  export function assertUpdateRestartHome(expected: UpdateRestartHome, deadlineAt = Date.now() + 2000, deps: UpdateRestartHomeDeps = {}): void {
@@ -62,7 +65,7 @@ export function assertUpdateRestartHome(expected: UpdateRestartHome, deadlineAt
62
65
 
63
66
  /** Read-only eligibility shared by parent pre-stop and child admission. */
64
67
  export function assertUpdateRestartConfiguration(hostname: string): void {
65
- const diagnostics = readConfigDiagnostics();
68
+ const diagnostics = readConfigDiagnostics({ passive: true });
66
69
  if (readClientConnectionState().kind !== "disconnected" || diagnostics.error
67
- || (diagnostics.config.hostname ?? "") !== hostname) throw new Error("update_restart_configuration_changed");
70
+ || (diagnostics.config.hostname === undefined ? hostname !== "127.0.0.1" : diagnostics.config.hostname !== hostname)) throw new Error("update_restart_configuration_changed");
68
71
  }