@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
@@ -0,0 +1,243 @@
1
+ import type { CliDispatchDeps } from "./dispatch";
2
+ import type { OwnedIntegrationRefreshOutcome } from "../integrations/owned-refresh";
3
+ import { syncModelsToCodex } from "../codex/sync";
4
+ import { HUB_GATED_SKIP_MESSAGE } from "../codex/desired-state";
5
+ import { handleRestartScopeAfterWrite, readRestartScope, type RestartScope } from "./restart-scope";
6
+ import { terminalSafeError, terminalSafeText } from "./runtime-api";
7
+ import { parseSyncFanoutFlags } from "./sync-flags";
8
+ import { projectLocalSyncResult } from "./local-sync-result";
9
+ import { readLinkStore } from "../link/store";
10
+ import { linkKnownHostsPath, linkStorePath } from "../link/paths";
11
+ import { buildExecArgv, remotePinnedSyncArgv } from "../link/ssh-argv";
12
+ import { requireRemotePlatformFramed } from "../link/remote-platform";
13
+ import { FanoutProcessError, fanoutSshRunner, runFanoutProcess } from "./sync-fanout-process";
14
+ import { readHomeLinkStatus } from "./sync-link-status";
15
+ import { classifySyncResult, fanoutExitCode, renderFanoutHuman, renderFanoutJson, runHomeFanout, REMOTE_LINK_SYNC_MESSAGE, STALE_REMOTE_CATALOG_MESSAGE, type HomeResult } from "./sync-fanout";
16
+
17
+ export async function runSyncCommand(deps: CliDispatchDeps): Promise<number> {
18
+ const flags = parseSyncFanoutFlags(deps.args.slice(1));
19
+ if (!flags.ok) { console.error(flags.message); return 2; }
20
+ const originalLog = console.log;
21
+ if (flags.json) console.log = (...args: unknown[]) => console.error(...args);
22
+ let applicable = false, catalogCurrent = false;
23
+ let state: HomeResult["state"] = "failed";
24
+ const runHome = async (): Promise<number> => {
25
+ const syncArgs = deps.args.slice(1);
26
+ // #7694: parse the expected identity before anything else reads or writes state.
27
+ const { parseSyncExpectation, reportSyncExpectationMismatch, SYNC_EXPECTATION_USAGE_EXIT } = await import("./sync-expectation");
28
+ const parsedExpectation = parseSyncExpectation(syncArgs);
29
+ if (!parsedExpectation.ok) {
30
+ console.error(parsedExpectation.message);
31
+ return SYNC_EXPECTATION_USAGE_EXIT;
32
+ }
33
+ const expectation = parsedExpectation.expectation;
34
+ // The root preflight skips shim repair for every sync so the update/sync mutex is held first.
35
+ if (!expectation) await (await import("./codex-shim-autorestore")).runCodexShimAutoRestoreAsync();
36
+ const restartScope = readRestartScope(syncArgs, console);
37
+ // The wire field keeps APP-SERVER-ONLY meaning and is deliberately not widened. A
38
+ // remote hub must not end a local user's conversations because a field name acquired
39
+ // a wider meaning underneath it; the maintainer decision widened a local CLI flag and
40
+ // said nothing about remote callers. syncConnectedClient ignores it either way.
41
+ const restartCodex = restartScope.appServers;
42
+ const { readClientConnectionState } = await import("../client/state");
43
+ const clientState = readClientConnectionState();
44
+ // With an expectation the unlocked read decides nothing: the connected sync re-reads under its
45
+ // lock and refuses there, so a state that changes in between can never reach the local path.
46
+ if (!expectation && (clientState.kind === "invalid" || clientState.kind === "mismatched")) {
47
+ console.error(`Client state is ${clientState.kind}: ${clientState.reason}`);
48
+ return 1;
49
+ }
50
+ if (expectation || clientState.kind === "connected") {
51
+ try {
52
+ const { syncConnectedClient } = await import("../client/connect");
53
+ const result = await syncConnectedClient(expectation ? { restartCodex, expect: expectation } : { restartCodex });
54
+ if (expectation) {
55
+ // The root preflight skipped the shim repair for a pinned sync; the identity held, so
56
+ // run it now, as an unpinned sync would have.
57
+ const { runCodexShimAutoRestoreAsync } = await import("./codex-shim-autorestore");
58
+ await runCodexShimAutoRestoreAsync();
59
+ }
60
+ // The connection the sync ran under, read inside its lock; the read above may be stale.
61
+ const link = result.connection.transport === "link";
62
+ state = result.stale ? "stale" : "synced";
63
+ console.log(result.stale
64
+ ? link ? STALE_REMOTE_CATALOG_MESSAGE : "Hub unavailable; retained and applied the last-known-good remote catalog (stale)."
65
+ : link ? REMOTE_LINK_SYNC_MESSAGE : "Remote hub catalog synchronized.");
66
+ if (result.homeSettings) {
67
+ const { describeHomeCodexSettings } = await import("../link/codex-settings");
68
+ const settings = result.homeSettings;
69
+ if (settings.source === "local") {
70
+ console.log(`Codex settings: kept this machine's local values (${terminalSafeText(settings.reason)}).`);
71
+ } else {
72
+ console.log(settings.source === "home"
73
+ ? `Codex settings applied from Home ${terminalSafeText(settings.document.home.name)}:`
74
+ : `Codex settings applied from the last recorded Home read (${terminalSafeText(settings.reason)}):`);
75
+ for (const line of describeHomeCodexSettings(settings.document.settings)) console.log(` ${terminalSafeText(line)}`);
76
+ }
77
+ }
78
+ await handleConnectedSyncCatalogWrite(result, restartScope);
79
+ if (result.applyRecordFailed) {
80
+ console.error("The Home's Codex settings were applied, but the apply record could not be written; the client runtime was not restarted. Run 'ocx sync' again.");
81
+ process.exitCode = 1;
82
+ }
83
+ // OCX-6: a link Child's runtime must have started after the apply it serves under.
84
+ if (link && result.appliedRecord) {
85
+ const { applyRestartMessage, restartRuntimeAfterApply } = await import("./link-apply-restart");
86
+ const { sameClientConnectionOwner } = await import("../client/state");
87
+ const applied = result.connection;
88
+ const outcome = await restartRuntimeAfterApply(result.appliedRecord, {
89
+ restart: (startWhenStopped, onSupervised) => deps.handleProxyRestart(startWhenStopped, onSupervised),
90
+ recoveryStart: recovering => deps.handleRestartStartWhenStopped(recovering),
91
+ connectionUnchanged: () => {
92
+ const current = readClientConnectionState();
93
+ return current.kind === "connected" && sameClientConnectionOwner(current.value, applied)
94
+ && current.value.link?.linkId === applied.link?.linkId;
95
+ },
96
+ });
97
+ const message = applyRestartMessage(outcome);
98
+ if (outcome.kind === "failed" || outcome.kind === "connection-changed") {
99
+ console.error(message);
100
+ process.exitCode = 1;
101
+ } else {
102
+ console.log(message);
103
+ }
104
+ }
105
+ // `process.exitCode` rather than a literal 0, for the same reason every other
106
+ // runner does it (tests/cli/cli-transport-honesty.test.ts): the catalog-write helper
107
+ // drives app-server restarts, and one of those recording a failure must not be
108
+ // erased by the value this runner returns. It reads 0 on the ordinary path. Node
109
+ // types it as `number | string`; only a numeric code means anything here.
110
+ return typeof process.exitCode === "number" ? process.exitCode : 0;
111
+ } catch (error) {
112
+ const { ClientSyncExpectationError } = await import("../client/sync-expectation");
113
+ if (error instanceof ClientSyncExpectationError) return reportSyncExpectationMismatch(error, console);
114
+ // The refresh path reaches the same hub catalog `ocx connect` validates, so a rejected
115
+ // reasoning level arrives here as hub-supplied text. Rendering it through the shared
116
+ // terminal boundary is what keeps the routine refresh from forging output; the domain
117
+ // error itself is left alone for callers that inspect it.
118
+ console.error(`Connected sync failed without local fallback: ${terminalSafeError(error).message}`);
119
+ return 1;
120
+ }
121
+ }
122
+ applicable = true;
123
+ const live = await deps.findLiveProxy();
124
+ const synced = await syncModelsToCodex(
125
+ live?.port,
126
+ undefined,
127
+ undefined,
128
+ undefined,
129
+ { catalogEvenWhenNotInjected: true },
130
+ );
131
+ let code = 0;
132
+ state = synced.status === "skipped" ? "skipped" : synced.ok ? "synced" : "failed";
133
+ catalogCurrent = (synced.status === "applied" || synced.status === "catalog-only")
134
+ && synced.refreshOutcome === "committed" && projectLocalSyncResult(synced).catalog?.converged === true;
135
+ if (synced.status === "skipped") {
136
+ console.log(synced.skippedReason === "hub-gated"
137
+ ? `${HUB_GATED_SKIP_MESSAGE} sync skipped and no Codex files changed.`
138
+ : "Codex integration is OFF; sync skipped and no Codex files changed.");
139
+ } else if (synced.status === "catalog-only") {
140
+ // Explicit sync with the integration OFF still refreshes the catalog/cache
141
+ // for side profiles that consume the proxy without injection.
142
+ console.log(synced.message ?? "Codex integration is OFF; catalog refreshed, Codex config untouched.");
143
+ if (!synced.ok) code = 1;
144
+ } else if (!synced.ok) {
145
+ code = 1;
146
+ console.error("Codex sync did not complete. Fix the reported Codex config issue and retry.");
147
+ }
148
+ // Catalog/model-cache writes retain their warning/restart handling. This is
149
+ // deliberately not an `else`: refreshCodexModelCatalog runs before injectCodexConfig,
150
+ // so a sync can fail (`ok: false`) after the catalog was already rewritten — which is
151
+ // exactly when a long-lived app-server is holding the stale list.
152
+ // A configuration-only change also needs a reload, but only when explicitly
153
+ // requested. A successful no-op or refused write is never restart authority.
154
+ const requestedConfigRestart = (restartScope.appServers || restartScope.desktopApp)
155
+ && synced.ok && synced.configChanged === true;
156
+ if (synced.catalogWritten || synced.cacheSynced || requestedConfigRestart) {
157
+ await handleRestartScopeAfterWrite(restartScope, console);
158
+ }
159
+ // `ocx sync` is a direct CLI path; it does not call the management
160
+ // `/api/sync` route. Refresh already-connected file integrations here too,
161
+ // after Codex has published the catalog that supplies its capabilities.
162
+ if (synced.status !== "refused") {
163
+ const results: OwnedIntegrationRefreshOutcome[] = [];
164
+ if (live) {
165
+ try {
166
+ const config = deps.loadConfig();
167
+ const { refreshOwnedCatalogIntegrations } = await import("../integrations/catalog-refresh");
168
+ results.push(...await refreshOwnedCatalogIntegrations({
169
+ models: async () => {
170
+ const { loadExportModels } = await import("../server/management/model-rows");
171
+ return loadExportModels(config);
172
+ },
173
+ config,
174
+ port: live.port,
175
+ }, ["mcode", "pi", "raycast", "omo", "cline", "commandcode", "droid", "opencode", "kilo", "qoder", "qoder-cn", "workbuddy", "workbuddy-ai", "hermes", "t3code"]));
176
+ } catch (error) {
177
+ console.warn(`Client integrations were not refreshed: ${error instanceof Error ? error.message : String(error)}`);
178
+ }
179
+ }
180
+ // Even without a live proxy, report why Aside could not sync. Its server
181
+ // owner is never bypassed, and another client's failure cannot hide it.
182
+ try {
183
+ const { refreshAsideProfilesThroughServer } = await import("./aside-profiles");
184
+ results.push(...await refreshAsideProfilesThroughServer({ findLiveProxy: async () => live }));
185
+ } catch (error) {
186
+ console.warn(`Aside profiles were not refreshed: ${error instanceof Error ? error.message : String(error)}`);
187
+ }
188
+ for (const result of results) {
189
+ const label = result.profileId === undefined ? result.client : `${result.client}:${result.profileId}`;
190
+ if (result.changed) console.log(`${label} integration refreshed from the current catalog.`);
191
+ else if (result.reason) console.warn(`${label} integration was not refreshed: ${result.reason}${result.residual ? " Recovery did not finish." : ""}${result.snapshotPath ? ` Backup: ${result.snapshotPath}` : ""}`);
192
+ }
193
+ }
194
+ return code || (typeof process.exitCode === "number" ? process.exitCode : 0);
195
+ };
196
+ let code: number;
197
+ try { code = await runHome(); }
198
+ catch (error) {
199
+ if (!flags.json) {
200
+ try { if (readLinkStore(linkStorePath()).links.length) console.error("Children were not synced because the Home sync failed."); } catch { /* Preserve the original error. */ }
201
+ throw error;
202
+ }
203
+ console.error(`Sync failed: ${terminalSafeError(error).message}`);
204
+ code = 1; state = "failed"; applicable = true;
205
+ } finally { console.log = originalLog; }
206
+ if (code !== 0) state = "failed";
207
+ const document = await runHomeFanout({
208
+ home: { state, exit: code }, catalogCurrent, localOnly: flags.localOnly, applicable,
209
+ readStore: () => readLinkStore(linkStorePath()), readLinkStatus: () => readHomeLinkStatus(),
210
+ runChild: async (link, deadline) => {
211
+ const runner = fanoutSshRunner(deadline);
212
+ let platform: "posix" | "windows";
213
+ try { platform = link.remotePlatform ?? await requireRemotePlatformFramed(runner, link.alias, linkKnownHostsPath()); }
214
+ catch (error) {
215
+ if (error instanceof FanoutProcessError && (error.reason === "deadline-exceeded" || error.reason === "termination-unconfirmed")) return { state: "timed-out", reason: error.reason, exit: null };
216
+ return { state: "failed", reason: "platform-probe-failed", exit: null };
217
+ }
218
+ try {
219
+ const result = await runFanoutProcess(buildExecArgv({ alias: link.alias, knownHostsFile: linkKnownHostsPath(), argv: remotePinnedSyncArgv(link.id, platform) }), { timeoutMs: Math.max(0, deadline - Date.now()) });
220
+ return { ...classifySyncResult(result), exit: result.code };
221
+ } catch (error) {
222
+ if (error instanceof FanoutProcessError) return { state: error.reason === "deadline-exceeded" || error.reason === "termination-unconfirmed" ? "timed-out" : "failed", reason: error.reason, exit: null };
223
+ throw error;
224
+ }
225
+ },
226
+ });
227
+ if (flags.json) originalLog(renderFanoutJson(document));
228
+ else {
229
+ for (const line of renderFanoutHuman(document)) originalLog(line);
230
+ if (document.fanout.state === "failed" && document.fanout.reason === "link-store-unreadable") {
231
+ console.error("Children were not synced: the Remote Link store could not be read.");
232
+ }
233
+ }
234
+ return fanoutExitCode(document);
235
+ }
236
+
237
+ async function handleConnectedSyncCatalogWrite(
238
+ result: { catalogWritten: boolean; cacheSynced: boolean },
239
+ scope: RestartScope,
240
+ ): Promise<void> {
241
+ if (!result.catalogWritten && !result.cacheSynced) return;
242
+ await handleRestartScopeAfterWrite(scope, console);
243
+ }
@@ -0,0 +1,92 @@
1
+ import { linkSshSpawnEnv, type SshRunResult, type SshRunner } from "../link/ssh-runner";
2
+
3
+ export type FanoutProcessFailure = "deadline-exceeded" | "termination-unconfirmed" | "ssh-spawn-failed" | "ssh-output";
4
+ export class FanoutProcessError extends Error {
5
+ constructor(readonly reason: FanoutProcessFailure, options?: ErrorOptions) {
6
+ super(reason, options);
7
+ this.name = "FanoutProcessError";
8
+ }
9
+ }
10
+
11
+ function delay(ms: number): Promise<void> { return new Promise(resolve => setTimeout(resolve, ms)); }
12
+
13
+ async function readBounded(stream: ReadableStream<Uint8Array>, cap: number, exited: Promise<number>): Promise<string> {
14
+ const reader = stream.getReader();
15
+ let ended = false;
16
+ let graceExpired = false;
17
+ let timer: ReturnType<typeof setTimeout> | undefined;
18
+ void exited.then(() => { if (!ended) timer = setTimeout(() => { graceExpired = true; void reader.cancel().catch(() => {}); }, 250); });
19
+ const chunks: Uint8Array[] = [];
20
+ let length = 0;
21
+ try {
22
+ while (true) {
23
+ const next = await reader.read();
24
+ if (next.done) {
25
+ if (graceExpired) throw new FanoutProcessError("ssh-output");
26
+ break;
27
+ }
28
+ length += next.value.length;
29
+ if (length > cap) throw new FanoutProcessError("ssh-output");
30
+ chunks.push(next.value);
31
+ }
32
+ const bytes = new Uint8Array(length);
33
+ let offset = 0;
34
+ for (const chunk of chunks) { bytes.set(chunk, offset); offset += chunk.length; }
35
+ try { return new TextDecoder("utf-8", { fatal: true }).decode(bytes); }
36
+ catch (cause) { throw new FanoutProcessError("ssh-output", { cause }); }
37
+ } finally {
38
+ ended = true;
39
+ if (timer !== undefined) clearTimeout(timer);
40
+ void reader.cancel().catch(() => {});
41
+ reader.releaseLock();
42
+ }
43
+ }
44
+
45
+ export async function runFanoutProcess(argv: readonly string[], options: {
46
+ timeoutMs: number; maxOutputBytes?: number; onSpawn?: (pid: number) => void;
47
+ }): Promise<SshRunResult> {
48
+ if (options.timeoutMs <= 0) throw new FanoutProcessError("deadline-exceeded");
49
+ const env = linkSshSpawnEnv();
50
+ let child: Bun.Subprocess<"ignore", "pipe", "pipe">;
51
+ try {
52
+ child = Bun.spawn([...argv], { stdin: "ignore", stdout: "pipe", stderr: "pipe", ...(env ? { env } : {}) });
53
+ } catch (cause) { throw new FanoutProcessError("ssh-spawn-failed", { cause }); }
54
+ options.onSpawn?.(child.pid);
55
+ let exited = false;
56
+ const exit = child.exited.then(code => { exited = true; return code; });
57
+ const stdout = readBounded(child.stdout, options.maxOutputBytes ?? 65536, exit);
58
+ const stderr = readBounded(child.stderr, options.maxOutputBytes ?? 65536, exit);
59
+ let timer: ReturnType<typeof setTimeout> | undefined;
60
+ const deadline = new Promise<never>((_, reject) => { timer = setTimeout(() => reject(new FanoutProcessError("deadline-exceeded")), Math.max(0, options.timeoutMs)); });
61
+ try {
62
+ const [code, out, err] = await Promise.race([Promise.all([exit, stdout, stderr]), deadline]);
63
+ return { code, stdout: out, stderr: err };
64
+ } catch (error) {
65
+ let signalError = false;
66
+ const signal = (name: NodeJS.Signals): void => {
67
+ if (exited) return;
68
+ try { child.kill(name); } catch (cause) {
69
+ if (cause && typeof cause === "object" && "code" in cause && cause.code === "ESRCH") { exited = true; return; }
70
+ signalError = true;
71
+ }
72
+ };
73
+ signal("SIGTERM");
74
+ if (!exited) await Promise.race([exit, delay(2000)]);
75
+ if (!exited) signal("SIGKILL");
76
+ if (!exited) await Promise.race([exit, delay(1000)]);
77
+ if (signalError || !exited) throw new FanoutProcessError("termination-unconfirmed", { cause: error });
78
+ if (error instanceof FanoutProcessError) throw error;
79
+ throw new FanoutProcessError("ssh-output", { cause: error });
80
+ } finally {
81
+ if (timer !== undefined) clearTimeout(timer);
82
+ void Promise.allSettled([exit, stdout, stderr]);
83
+ }
84
+ }
85
+
86
+ /** Platform discovery shares the worker deadline across its SSH calls. */
87
+ export function fanoutSshRunner(deadline: number): Pick<SshRunner, "run"> {
88
+ return { run: (argv, options = {}) => runFanoutProcess(argv, {
89
+ timeoutMs: Math.min(options.timeoutMs ?? 30_000, Math.max(0, deadline - Date.now())),
90
+ ...(options.maxOutputBytes === undefined ? {} : { maxOutputBytes: options.maxOutputBytes }),
91
+ }) };
92
+ }
@@ -0,0 +1,161 @@
1
+ import { compareStrictSemver, parseStrictSemver } from "../lib/strict-semver";
2
+ import type { LinkRecord, LinkStore } from "../link/store";
3
+ import type { LinkStatusDto } from "../link/status-projection";
4
+ import { LinkStatusError } from "./sync-link-status";
5
+
6
+ export const REMOTE_LINK_SYNC_MESSAGE = "Remote Link Home catalog synchronized.";
7
+ export const STALE_REMOTE_CATALOG_MESSAGE = "Home unavailable; retained and applied the last-known-good remote catalog (stale).";
8
+ export const SYNC_FANOUT_PARTIAL_EXIT = 6;
9
+
10
+ export type ChildVerdict = { state: "synced" | "skipped" | "failed"; reason: string | null };
11
+ const failure = (reason: string): ChildVerdict => ({ state: "failed", reason });
12
+ const skipped = (reason: string): ChildVerdict => ({ state: "skipped", reason });
13
+ const minimum = parseStrictSemver("2.93.0")!;
14
+
15
+ export function parseOcxVersion(output: string): string | null {
16
+ const version = output.trim().replace(/^opencodex /, "");
17
+ return parseStrictSemver(version) ? version : null;
18
+ }
19
+
20
+ export function classifyVersionProbe(output: string): "child-ocx-version-unknown" | "child-ocx-lacks-expect-link" | null {
21
+ const version = parseOcxVersion(output);
22
+ if (!version) return "child-ocx-version-unknown";
23
+ return compareStrictSemver(parseStrictSemver(version)!, minimum) < 0 ? "child-ocx-lacks-expect-link" : null;
24
+ }
25
+
26
+ const mismatchReasons = new Set(["disconnected", "invalid_state", "disconnect_pending", "pending_operation", "hub_client", "link_client", "other_link", "other_key"]);
27
+
28
+ function validDocument(value: unknown): "synced" | "stale" | null {
29
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
30
+ const v = value as Record<string, unknown>;
31
+ const keysAre = (object: Record<string, unknown>, keys: readonly string[]): boolean => Object.keys(object).length === keys.length && keys.every(key => Object.hasOwn(object, key));
32
+ if (!keysAre(v, ["schema", "home", "fanout", "children"])) return null;
33
+ if (v.schema !== "ocx.sync.fanout/1" || !v.home || typeof v.home !== "object" || Array.isArray(v.home)
34
+ || !v.fanout || typeof v.fanout !== "object" || Array.isArray(v.fanout) || !Array.isArray(v.children)) return null;
35
+ const home = v.home as Record<string, unknown>, fanout = v.fanout as Record<string, unknown>;
36
+ if (!keysAre(home, ["state", "exit"]) || !keysAre(fanout, ["state", "reason"])) return null;
37
+ if (home.exit !== 0 || (home.state !== "synced" && home.state !== "stale")) return null;
38
+ if (fanout.state !== "not-applicable" || fanout.reason !== null || v.children.length !== 0) return null;
39
+ return home.state;
40
+ }
41
+
42
+ export function classifySyncResult(result: { code: number; stdout: string; stderr: string }): ChildVerdict {
43
+ const { code, stdout, stderr } = result;
44
+ if (code === 255) return failure("ssh-failed");
45
+ if (code === 127) return failure("child-ocx-not-found");
46
+ if (code === 126) return failure("child-ocx-not-contained");
47
+ if (code === 125) return skipped("child-platform-unsupported");
48
+ const lines = stderr.split(/\r?\n/);
49
+ const last = stderr.trimEnd().split(/\r?\n/).at(-1);
50
+ if (code === 121) {
51
+ if (last === "ocx-fanout:child-ocx-lacks-expect-link") return skipped("child-ocx-lacks-expect-link");
52
+ if (last === "ocx-fanout:child-ocx-version-unknown") return skipped("child-ocx-version-unknown");
53
+ return failure("child-sync-failed");
54
+ }
55
+ const markers = lines.map(line => /^ocx-fanout:selected:(.+)$/.exec(line)).filter(match => match !== null);
56
+ if (markers.length !== 1 || !parseStrictSemver(markers[0]![1]!)) return failure("child-output-invalid");
57
+ const outputLines = stdout.split(/\r?\n/);
58
+ const delimiters = outputLines.flatMap((line, index) => line === "ocx-fanout:stdout-begin" ? [index] : []);
59
+ if (delimiters.length !== 1) return failure("child-output-invalid");
60
+ if (code === 5) {
61
+ try {
62
+ const detail: unknown = JSON.parse(last ?? "");
63
+ if (detail && typeof detail === "object" && "phase" in detail && detail.phase === "child_link_mismatch"
64
+ && "reason" in detail && typeof detail.reason === "string" && mismatchReasons.has(detail.reason)) return skipped(`child-link-mismatch:${detail.reason}`);
65
+ } catch { /* The generic mismatch is the only safe fallback. */ }
66
+ return skipped("child-link-mismatch");
67
+ }
68
+ if (code === 7) return skipped("child-updating");
69
+ if (code !== 0) return failure("child-sync-failed");
70
+ const text = outputLines.slice(delimiters[0]! + 1).join("\n").trim();
71
+ if (text.startsWith("{")) {
72
+ try {
73
+ const state = validDocument(JSON.parse(text));
74
+ if (state === "synced") return { state: "synced", reason: null };
75
+ if (state === "stale") return failure("child-catalog-stale");
76
+ } catch { /* Reject invalid or multiple JSON documents. */ }
77
+ return failure("child-output-invalid");
78
+ }
79
+ if (text.includes(STALE_REMOTE_CATALOG_MESSAGE)) return failure("child-catalog-stale");
80
+ if (text.includes(REMOTE_LINK_SYNC_MESSAGE)) return { state: "synced", reason: null };
81
+ return failure("child-output-invalid");
82
+ }
83
+
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; hint?: string };
86
+ export type FanoutDocument = { schema: "ocx.sync.fanout/1"; home: HomeResult; fanout: { state: "ran" | "disabled" | "not-applicable" | "failed"; reason: string | null }; children: ChildResult[] };
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
+
99
+ export async function runHomeFanout(deps: {
100
+ home: HomeResult; catalogCurrent: boolean; localOnly?: boolean; applicable?: boolean;
101
+ readStore: () => LinkStore; readLinkStatus: () => Promise<LinkStatusDto>;
102
+ runChild: (link: LinkRecord, deadline: number) => Promise<Omit<ChildResult, "linkId" | "alias">>;
103
+ now?: () => number; deadlineMs?: number; concurrency?: number; terminationGraceMs?: number;
104
+ }): Promise<FanoutDocument> {
105
+ const result: FanoutDocument = { schema: "ocx.sync.fanout/1", home: deps.home, fanout: { state: deps.localOnly ? "disabled" : "not-applicable", reason: null }, children: [] };
106
+ if (deps.localOnly || deps.applicable === false) return result;
107
+ let store: LinkStore;
108
+ try { store = deps.readStore(); } catch { result.fanout = { state: "failed", reason: "link-store-unreadable" }; return result; }
109
+ if (!store.links.length) return result;
110
+ result.fanout.state = "ran";
111
+ const classify = (link: LinkRecord, state: ChildResult["state"], reason: string | null, exit: number | null = null): ChildResult => ({ linkId: link.id, alias: link.alias, state, reason, exit });
112
+ result.children = store.links.map(link => classify(link, "skipped", link.direction === "client-initiated" ? "client-initiated-link" : "home-catalog-not-current"));
113
+ const skipReason = deps.home.state === "failed" || deps.home.exit !== 0 ? "home-sync-failed" : deps.home.state === "skipped" ? "home-sync-skipped" : !deps.catalogCurrent ? "home-catalog-not-current" : null;
114
+ if (skipReason) {
115
+ result.children = store.links.map(link => classify(link, "skipped", link.direction === "client-initiated" ? "client-initiated-link" : skipReason));
116
+ return result;
117
+ }
118
+ let status: LinkStatusDto;
119
+ try { status = await deps.readLinkStatus(); }
120
+ catch (error) {
121
+ const reason = error instanceof LinkStatusError ? error.reason : "home-link-status-unavailable";
122
+ result.children = store.links.map(link => link.direction === "client-initiated" ? classify(link, "skipped", "client-initiated-link") : classify(link, reason === "home-runtime-not-running" ? "skipped" : "failed", reason));
123
+ return result;
124
+ }
125
+ let cursor = 0;
126
+ const workers = Array.from({ length: Math.max(1, Math.min(Math.floor(deps.concurrency ?? 3), 3, store.links.length)) }, async () => {
127
+ for (;;) {
128
+ const index = cursor++;
129
+ const link = store.links[index];
130
+ if (!link) return;
131
+ if (link.direction === "client-initiated") continue;
132
+ const wire = status.links.find(row => row.id === link.id);
133
+ if (!wire) { result.children[index] = classify(link, "skipped", "link-not-in-runtime"); continue; }
134
+ if (wire.state !== "connected") { result.children[index] = classify(link, "skipped", `tunnel-${wire.state}`); continue; }
135
+ let timer: ReturnType<typeof setTimeout> | undefined;
136
+ try {
137
+ const budget = deps.deadlineMs ?? 180_000;
138
+ const child = await Promise.race([
139
+ deps.runChild(link, (deps.now ?? Date.now)() + budget),
140
+ new Promise<Omit<ChildResult, "linkId" | "alias">>(resolve => {
141
+ timer = setTimeout(() => resolve({ state: "timed-out", reason: "termination-unconfirmed", exit: null }), budget + (deps.terminationGraceMs ?? 3000));
142
+ }),
143
+ ]);
144
+ result.children[index] = { linkId: link.id, alias: link.alias, ...child, ...(child.state === "skipped" ? { hint: childSkipHint(child.reason, link.alias) } : {}) };
145
+ } catch { result.children[index] = classify(link, "failed", "internal-error"); }
146
+ finally { if (timer !== undefined) clearTimeout(timer); }
147
+ }
148
+ });
149
+ await Promise.all(workers);
150
+ return result;
151
+ }
152
+
153
+ export function fanoutExitCode(document: FanoutDocument): number {
154
+ if (document.home.exit !== 0) return document.home.exit;
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;
156
+ }
157
+
158
+ export function renderFanoutJson(document: FanoutDocument): string { return JSON.stringify(document); }
159
+ export function renderFanoutHuman(document: FanoutDocument): string[] {
160
+ return document.children.map(child => `${child.alias} (${child.linkId}): ${child.state}${child.reason ? ` (${child.reason})` : ""}${child.hint ? ` — ${child.hint}` : ""}`);
161
+ }
@@ -0,0 +1,10 @@
1
+ export type SyncFanoutFlags = { ok: true; localOnly: boolean; json: boolean } | { ok: false; message: string };
2
+
3
+ export function parseSyncFanoutFlags(args: readonly string[]): SyncFanoutFlags {
4
+ for (const flag of ["--local-only", "--json"]) {
5
+ if (args.filter(arg => arg === flag).length > 1 || args.some(arg => arg.startsWith(`${flag}=`))) {
6
+ return { ok: false, message: `ocx sync accepts ${flag} once without a value.` };
7
+ }
8
+ }
9
+ return { ok: true, localOnly: args.includes("--local-only"), json: args.includes("--json") };
10
+ }
@@ -0,0 +1,39 @@
1
+ import { runningProxyUpdateHeaders } from "../oauth/login-cli";
2
+ import { runtimeBaseUrl, RuntimeApiError } from "./runtime-api";
3
+ import { validateStatus, type LinkStatusPayload } from "./link";
4
+
5
+ export type LinkStatusFailure = "home-runtime-not-running" | "home-link-status-unauthorized" | "home-link-status-timeout" | "home-link-status-unavailable" | "home-link-status-invalid";
6
+ export class LinkStatusError extends Error {
7
+ constructor(readonly reason: LinkStatusFailure, options?: ErrorOptions) { super(reason, options); this.name = "LinkStatusError"; }
8
+ }
9
+
10
+ /** A single absolute deadline covers discovery, response headers and the response body. */
11
+ export async function readHomeLinkStatus(deadlineMs = 5000, deps: {
12
+ baseUrl?: () => Promise<string | null>; fetchImpl?: typeof fetch; headers?: () => Headers;
13
+ } = {}): Promise<LinkStatusPayload> {
14
+ const controller = new AbortController();
15
+ let timer: ReturnType<typeof setTimeout> | undefined;
16
+ const timeout = new Promise<never>((_, reject) => {
17
+ timer = setTimeout(() => { controller.abort(); reject(new LinkStatusError("home-link-status-timeout")); }, Math.max(0, deadlineMs));
18
+ });
19
+ const work = async (): Promise<LinkStatusPayload> => {
20
+ let base: string | null;
21
+ try { base = await (deps.baseUrl ?? (() => runtimeBaseUrl()))(); }
22
+ catch (cause) {
23
+ if (cause instanceof RuntimeApiError && cause.code === "proxy_not_running") throw new LinkStatusError("home-runtime-not-running", { cause });
24
+ throw new LinkStatusError("home-link-status-unavailable", { cause });
25
+ }
26
+ if (controller.signal.aborted) throw new LinkStatusError("home-link-status-timeout");
27
+ if (!base) throw new LinkStatusError("home-runtime-not-running");
28
+ let response: Response;
29
+ try { response = await (deps.fetchImpl ?? fetch)(`${base}/api/link/status`, { headers: (deps.headers ?? runningProxyUpdateHeaders)(), signal: controller.signal }); }
30
+ catch (cause) { throw new LinkStatusError("home-link-status-unavailable", { cause }); }
31
+ if (response.status === 401 || response.status === 403) throw new LinkStatusError("home-link-status-unauthorized");
32
+ if (!response.ok) throw new LinkStatusError("home-link-status-unavailable");
33
+ let text: string;
34
+ try { text = await response.text(); } catch (cause) { throw new LinkStatusError("home-link-status-unavailable", { cause }); }
35
+ try { return validateStatus(JSON.parse(text)); } catch (cause) { throw new LinkStatusError("home-link-status-invalid", { cause }); }
36
+ };
37
+ try { return await Promise.race([work(), timeout]); }
38
+ finally { if (timer !== undefined) clearTimeout(timer); controller.abort(); }
39
+ }
@@ -0,0 +1,18 @@
1
+ import { getConfigDir } from "../config/paths";
2
+ import { acquireSyncGuard, inspectUpdateMarker, inspectUpdateSyncMutex, parentHoldsSyncMutex, refuseSync } from "../update/sync-update-mutex";
3
+
4
+ /** Hold the home-scoped update/sync mutex until the complete sync operation settles. */
5
+ export async function withSyncUpdateGuard(run: () => Promise<number>, args: readonly string[] = []): Promise<number> {
6
+ const home = getConfigDir();
7
+ if (process.env.OCX_SYNC_MUTEX_HELD_BY) {
8
+ const deadline = Date.now() + 2_000;
9
+ while (!parentHoldsSyncMutex(home) && Date.now() < deadline) await new Promise(resolve => setTimeout(resolve, 20));
10
+ if (!parentHoldsSyncMutex(home)) return refuseSync(inspectUpdateSyncMutex(home) === "sync" ? "sync-in-progress" : "update-in-flight", args);
11
+ }
12
+ if (parentHoldsSyncMutex(home)) return inspectUpdateMarker(home) === "free" ? await run() : refuseSync("update-in-flight", args);
13
+ const lease = acquireSyncGuard(home, args);
14
+ if (lease.kind === "refused") return lease.exit;
15
+ try {
16
+ return await run();
17
+ } finally { lease.release(); }
18
+ }
@@ -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.");