@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
@@ -121,14 +121,20 @@ try {
121
121
  `;
122
122
  const ENCODED_ACL_SCRIPT = Buffer.from(ACL_SCRIPT, "utf16le").toString("base64");
123
123
 
124
+ /** Above this many paths the script reads them from stdin, keeping one process for a whole tree. */
125
+ const ACL_ENV_PATH_LIMIT = 16;
126
+
124
127
  function defaultWindowsOwnerAclRunner(entries: readonly WindowsPrivateEntry[], timeoutMs: number): WindowsOwnerAclResult {
125
- const env: Record<string, string | undefined> = { ...process.env, OCX_ACL_COUNT: String(entries.length), OCX_ACL_STDIN: "0" };
126
- for (let i = 0; i < entries.length; i++) env[`OCX_ACL_PATH_${i}`] = entries[i]!.path;
128
+ const viaStdin = entries.length > ACL_ENV_PATH_LIMIT;
129
+ const env: Record<string, string | undefined> = { ...process.env, OCX_ACL_COUNT: String(entries.length), OCX_ACL_STDIN: viaStdin ? "1" : "0" };
130
+ if (!viaStdin) for (let i = 0; i < entries.length; i++) env[`OCX_ACL_PATH_${i}`] = entries[i]!.path;
131
+ // Base64 lines are data, as in the async runner; no path text becomes PowerShell source.
132
+ const input = viaStdin ? Buffer.from(entries.map(entry => Buffer.from(entry.path, "utf8").toString("base64")).join("\n") + "\n") : undefined;
127
133
  const result = Bun.spawnSync([
128
134
  resolveTrustedWindowsPowerShellExe(), "-NoLogo", "-NoProfile", "-NonInteractive",
129
135
  "-ExecutionPolicy", "Bypass", "-EncodedCommand", ENCODED_ACL_SCRIPT,
130
136
  ], {
131
- env, stdin: "ignore", stdout: "pipe", stderr: "ignore",
137
+ env, stdin: input ?? "ignore", stdout: "pipe", stderr: "ignore",
132
138
  timeout: timeoutMs, windowsHide: true,
133
139
  });
134
140
  return { success: result.success, timedOut: result.exitedDueToTimeout ?? false, stdout: result.stdout ?? new Uint8Array() };
package/src/lib/winsw.ts CHANGED
@@ -16,9 +16,9 @@
16
16
  import { createHash } from "node:crypto";
17
17
  import { execFileSync } from "node:child_process";
18
18
  import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
19
- import { homedir } from "node:os";
20
19
  import { join, resolve, win32 } from "node:path";
21
20
  import { expandUserPath, getConfigDir, loadConfig } from "../config";
21
+ import { resolveCodexHomeDir } from "../codex/home";
22
22
  import { recordOwnedConfigPath } from "./config-ownership";
23
23
  import { BUN_RUNTIME_PATH_ENV, BUN_RUNTIME_SOURCE_ENV, durableBunRuntime, type DurableBunRuntime } from "./bun-runtime";
24
24
  import type { BunRuntimeSource } from "./bun-runtime";
@@ -59,9 +59,9 @@ function xmlEscape(value: string): string {
59
59
  .replace(/'/g, "&apos;");
60
60
  }
61
61
 
62
- function currentCodexHomeAbsolute(): string {
63
- const raw = process.env.CODEX_HOME?.trim();
64
- return raw ? resolve(expandUserPath(raw)) : join(homedir(), ".codex");
62
+ function currentCodexHomeAbsolute(env: NodeJS.ProcessEnv = process.env): string {
63
+ const raw = env.CODEX_HOME?.trim();
64
+ return raw ? windowsServicePathAbsolute(raw) : resolveCodexHomeDir({ env });
65
65
  }
66
66
 
67
67
  function windowsServicePathAbsolute(raw: string): string {
@@ -109,7 +109,7 @@ export function buildWinswXml(entry: WinswEntry, env: NodeJS.ProcessEnv = proces
109
109
  ` <env name="${BUN_RUNTIME_PATH_ENV}" value="${xmlEscape(entry.bun)}"/>`,
110
110
  ` <env name="OCX_API_TOKEN_FILE" value="${xmlEscape(serviceApiTokenFilePath())}"/>`,
111
111
  ` <env name="PATH" value="${xmlEscape(filterTransientServicePath(env.PATH ?? "", ";", "win32"))}"/>`,
112
- env.CODEX_HOME?.trim() ? ` <env name="CODEX_HOME" value="${xmlEscape(currentCodexHomeAbsolute())}"/>` : null,
112
+ ` <env name="CODEX_HOME" value="${xmlEscape(currentCodexHomeAbsolute(env))}"/>`,
113
113
  env.CODEX_SQLITE_HOME?.trim() ? ` <env name="CODEX_SQLITE_HOME" value="${xmlEscape(windowsServicePathAbsolute(env.CODEX_SQLITE_HOME.trim()))}"/>` : null,
114
114
  ` <env name="OPENCODEX_HOME" value="${xmlEscape(getConfigDir())}"/>`,
115
115
  aclTimeout ? ` <env name="OPENCODEX_ACL_TIMEOUT_MS" value="${xmlEscape(aclTimeout)}"/>` : null,
@@ -245,7 +245,9 @@ export function workflowDenialSummary(
245
245
  // because the alternative is an operator who can see that something refused and has
246
246
  // no way to find out what. Without one -- a caller that knows only the reason -- the
247
247
  // original sentence is kept unchanged.
248
- message: spend
248
+ message: spend && Object.hasOwn(SPEND_SCOPE_LABEL, spend.scope)
249
+ && Number.isSafeInteger(spend.limit) && spend.limit >= 0
250
+ && (spend.projected === undefined || (Number.isSafeInteger(spend.projected) && spend.projected >= 0))
249
251
  ? "This proxy refused the request locally: the configured " + SPEND_SCOPE_LABEL[spend.scope]
250
252
  + " token ceiling of " + formatTokenCount(spend.limit) + " is spent"
251
253
  + (spend.projected !== undefined
@@ -453,6 +453,13 @@ export function listOAuthProviders(): string[] {
453
453
  import { OAuthAccountUnusableError, OAuthLoginSupersededError, OAuthAccountPausedError, OAuthLoginRequiredError, OAuthProviderNamespaceCollisionError, OAuthProviderPublicationError, OAuthReauthIdentityMismatchError, OAuthReauthIdentityUnverifiedError, UnsupportedOAuthProviderError } from "./oauth-errors";
454
454
  export { OAuthAccountPausedError, OAuthLoginRequiredError, OAuthProviderNamespaceCollisionError, OAuthProviderPublicationError, OAuthReauthIdentityMismatchError, OAuthReauthIdentityUnverifiedError, UnsupportedOAuthProviderError } from "./oauth-errors";
455
455
  /** Project arbitrary OAuth failures onto the small, stable public error vocabulary. */
456
+ export function publicOAuthErrorPresentation(error: unknown): import("../lib/client-error-body").ProxyErrorPresentation | undefined {
457
+ if (error instanceof OAuthLoginRequiredError) return "oauth_login";
458
+ if (error instanceof AntigravityProjectDiscoveryError) return "discovery";
459
+ if (error instanceof MuseLoginError && error.kind === "validation-http" && error.status !== undefined) return "muse_http";
460
+ return undefined;
461
+ }
462
+
456
463
  export function publicOAuthAuthenticationErrorMessage(error: unknown): string {
457
464
  if (error instanceof AntigravityProjectDiscoveryError) return error.publicMessage;
458
465
  if (error instanceof MuseLoginError) return museLoginErrorMessage(error.kind, error.status);
@@ -34,7 +34,7 @@ import { join } from "node:path";
34
34
  import { getConfigDir, atomicWriteFile, backupInvalidConfig, hardenConfigDir, hardenExistingSecret, withConfigMutationLockSync, loadConfig } from "../config";
35
35
  import { atomicWriteFileNoFollowUnclaimed } from "../config/atomic-write";
36
36
  import { assertNotRealHomeUnderTest } from "../lib/test-home-guard";
37
- import { recordOwnedConfigPath } from "../lib/config-ownership";
37
+ import { recordOwnedConfigPath, registerOwnedConfigPath, type OwnedPathRegistration } from "../lib/config-ownership";
38
38
  import { statTimeMs } from "../lib/file-identity";
39
39
  import { MAX_PENDING_OAUTH_MUTATIONS } from "../lib/translator-budget";
40
40
  import { publishAccountSelection, publishOAuthAccountPauseChange, publishOAuthAccountRoutingPolicyChange } from "../lib/account-selection-events";
@@ -467,18 +467,28 @@ function backupLegacyOnce(): void {
467
467
  // Any existing entry, including a dangling symlink existsSync would call absent, is left
468
468
  // alone, and the copy is exclusive, so credentials are never written through a link.
469
469
  if (!existsSync(path) || directoryEntryExists(backup)) return;
470
+ // Register before creating, so no credential copy ever exists without its manifest entry. The
471
+ // entry is checked absent above and the copy below is exclusive, so nothing existing is adopted.
472
+ let registration: OwnedPathRegistration;
473
+ try {
474
+ registration = registerOwnedConfigPath(getConfigDir(), backup);
475
+ } catch {
476
+ // Uninstall in progress, or a busy ownership lock: defer the migration. The legacy store stays
477
+ // as it is and the next mutation backs it up again.
478
+ throw new Error("OAuth store migration deferred: its recovery backup could not be registered for uninstall; retry shortly.");
479
+ }
480
+ if (registration === "full") {
481
+ // An owned home whose manifest is full: a copy made now would survive uninstall with the legacy
482
+ // credentials in it. Migrate without the downgrade copy instead of blocking credential writes.
483
+ console.warn("[oauth] Recovery backup skipped: the uninstall ownership manifest is full.");
484
+ return;
485
+ }
470
486
  try {
471
487
  publishCredentialSync(() => copyFileSync(path, backup, fsConstants.COPYFILE_EXCL));
472
488
  try { chmodSync(backup, 0o600); } catch { /* best-effort */ }
473
- try {
474
- // Register only the copy we just created. An unowned home still needs downgrade recovery.
475
- if (!recordOwnedConfigPath(getConfigDir(), backup)) {
476
- console.warn("[oauth] Recovery backup created, but uninstall ownership registration failed.");
477
- }
478
- } catch {
479
- console.warn("[oauth] Recovery backup created, but uninstall ownership registration failed.");
480
- }
481
- } catch { /* best-effort */ }
489
+ } catch { return; /* best-effort */ }
490
+ // An unowned home still needs downgrade recovery; it has no manifest to record the copy in.
491
+ if (registration === "unowned") console.warn("[oauth] Recovery backup created, but uninstall ownership registration failed.");
482
492
  }
483
493
 
484
494
  /**
@@ -1,3 +1,5 @@
1
+ import { messagesRolePresentation } from "../../lib/messages-error-body";
2
+ import { CLAUDE_CONTEXT_OVERFLOW_MESSAGE, markProxyError } from "../../lib/client-error-body";
1
3
  /**
2
4
  * Anthropic Messages -> IR, directly (the Antigravity direct lane).
3
5
  *
@@ -169,10 +171,10 @@ export function messagesConversationToIr(
169
171
  budget: TranslatorBudget,
170
172
  modelId: string,
171
173
  ): MessagesIrConversation {
172
- if (!isRec(raw)) throw new AnthropicRequestError("request body must be a JSON object");
173
- if (typeof raw.model !== "string" || raw.model.length === 0) throw new AnthropicRequestError("model is required");
174
+ if (!isRec(raw)) throw markProxyError(new AnthropicRequestError("request body must be a JSON object"));
175
+ if (typeof raw.model !== "string" || raw.model.length === 0) throw markProxyError(new AnthropicRequestError("model is required"));
174
176
  if (!Array.isArray(raw.messages) || raw.messages.length === 0) {
175
- throw new AnthropicRequestError("messages must be a non-empty array");
177
+ throw markProxyError(new AnthropicRequestError("messages must be a non-empty array"));
176
178
  }
177
179
  const requestedModel = raw.model;
178
180
  const now = Date.now();
@@ -332,7 +334,7 @@ export function messagesConversationToIr(
332
334
  case "tool_result": {
333
335
  flush();
334
336
  if (typeof block.tool_use_id !== "string" || block.tool_use_id.length === 0) {
335
- throw new AnthropicRequestError("tool_result requires tool_use_id");
337
+ throw markProxyError(new AnthropicRequestError("tool_result requires tool_use_id"));
336
338
  }
337
339
  pushToolResult(
338
340
  block.tool_use_id,
@@ -376,7 +378,7 @@ export function messagesConversationToIr(
376
378
  case "tool_use":
377
379
  flush();
378
380
  if (typeof block.id !== "string" || block.id.length === 0 || typeof block.name !== "string" || block.name.length === 0) {
379
- throw new AnthropicRequestError("tool_use requires id and name");
381
+ throw markProxyError(new AnthropicRequestError("tool_use requires id and name"));
380
382
  }
381
383
  pushToolCall(block.id, block.name, block.input);
382
384
  break;
@@ -386,9 +388,9 @@ export function messagesConversationToIr(
386
388
  const signature = typeof block.signature === "string" ? block.signature : "";
387
389
  if (signature.startsWith(OCX_REASONING_PREFIX)) {
388
390
  const owned = decodeReasoningEnvelope(signature, budget);
389
- if (!owned) throw new AnthropicRequestError(MALFORMED_REASONING_SIGNATURE);
391
+ if (!owned) throw markProxyError(new AnthropicRequestError(MALFORMED_REASONING_SIGNATURE));
390
392
  if (Object.hasOwn(owned, "sig")) {
391
- throw new AnthropicRequestError("OpenCodex reasoning continuity cannot be replayed as an Anthropic signature");
393
+ throw markProxyError(new AnthropicRequestError("OpenCodex reasoning continuity cannot be replayed as an Anthropic signature"));
392
394
  }
393
395
  if (owned.nat) {
394
396
  // The provider's own blob goes back only to the model that minted it.
@@ -429,13 +431,17 @@ export function messagesConversationToIr(
429
431
  };
430
432
 
431
433
  for (const message of raw.messages) {
432
- if (!isRec(message)) throw new AnthropicRequestError("each message must be an object");
434
+ if (!isRec(message)) throw markProxyError(new AnthropicRequestError("each message must be an object"));
433
435
  if (message.role === "user") userContent(message.content);
434
436
  else if (message.role === "assistant") assistantContent(message.content);
435
437
  else if (message.role === "system") {
436
438
  const text = systemMessageText(message.content);
437
439
  if (text.length > 0) pushDeveloper(text);
438
- } else throw new AnthropicRequestError(`unsupported message role: ${String(message.role)}`);
440
+ } else {
441
+ const role = messagesRolePresentation(message.role);
442
+ if (role.coercionFailed) throw markProxyError(new TypeError("unsupported message role: unsupported"));
443
+ throw markProxyError(new AnthropicRequestError(role.overflow ? CLAUDE_CONTEXT_OVERFLOW_MESSAGE : "unsupported message role: unsupported"));
444
+ }
439
445
  }
440
446
 
441
447
  const system = anthropicSystemLayout(raw.system, cc);
@@ -89,14 +89,25 @@ export interface EncodedTerminal {
89
89
  durable: boolean;
90
90
  }
91
91
 
92
+ const encoderTransportFailures = new WeakSet<object>();
93
+ const originalErrorEvidence = new WeakMap<object, { status?: number; type?: string; code?: string; message: string }>();
94
+ /** Original adapter fields for a client writer; terminal classification stays independent. */
95
+ export function encoderOriginalErrorEvidence(terminal: EncodedTerminal) {
96
+ return originalErrorEvidence.get(terminal);
97
+ }
98
+
99
+ export function isEncoderTransportFailure(terminal: EncodedTerminal): boolean {
100
+ return encoderTransportFailures.has(terminal);
101
+ }
102
+
92
103
  /** Frame output owned by the driver: budget reservation, delivery release and relay counts. */
93
104
  export interface ClientFrameSink {
94
105
  readonly budget: TranslatorBudget;
95
- emit(text: string, observation?: RelayedEventObservation): void;
106
+ emit(text: string, observation?: RelayedEventObservation, onAdmitted?: () => void, admissionText?: string): void;
96
107
  /** Admit every frame before exposing any of them. */
97
108
  emitBatch(frames: { text: string; observation?: RelayedEventObservation }[]): void;
98
109
  /** A fixed, bounded frame that must reach the client even when the budget is exhausted. */
99
- emitBounded(text: string): void;
110
+ emitBounded(text: string, onAdmitted?: () => void): void;
100
111
  /** A transport keepalive; it counts as neither wire activity nor a relayed event. */
101
112
  emitKeepalive(text: string): void;
102
113
  desiredSize(): number;
@@ -203,10 +214,11 @@ export function encodeAdapterEventStream(
203
214
  const relayed = (observation?: RelayedEventObservation) => {
204
215
  try { hooks.onRelayed?.(observation ?? {}); } catch { /* counters never break the stream */ }
205
216
  };
206
- const enqueueCharged = (text: string, observation?: RelayedEventObservation, activity = true): void => {
217
+ const enqueueCharged = (text: string, observation?: RelayedEventObservation, activity = true, onAdmitted?: () => void, admissionText: string = text): void => {
207
218
  if (closed) return;
208
219
  const frame = textEncoder.encode(text);
209
- const reservation = budget.reserveTransient(frame.byteLength, { kind: "live_transient" });
220
+ const admittedBytes = admissionText === text ? frame.byteLength : Buffer.byteLength(admissionText);
221
+ const reservation = budget.reserveTransient(admittedBytes, { kind: "live_transient" });
210
222
  try {
211
223
  controller.enqueue(frame);
212
224
  } catch {
@@ -215,16 +227,17 @@ export function encodeAdapterEventStream(
215
227
  return;
216
228
  }
217
229
  reservation.commitRetained();
218
- queuedFrameBytes.push(frame.byteLength);
230
+ queuedFrameBytes.push(admittedBytes);
219
231
  emittedFrames++;
220
232
  if (activity) wireActivity = true;
221
233
  // A keepalive is transport liveness, not a relayed event: the bridge enqueues its heartbeat
222
234
  // outside the relay counter, and the converters' keepalives never reach it either.
223
235
  if (activity) relayed(observation);
236
+ onAdmitted?.();
224
237
  };
225
238
  const sink: ClientFrameSink = {
226
239
  budget,
227
- emit: (text, observation) => enqueueCharged(text, observation),
240
+ emit: (text, observation, onAdmitted, admissionText) => enqueueCharged(text, observation, true, onAdmitted, admissionText),
228
241
  emitBatch: frames => {
229
242
  if (closed) return;
230
243
  const staged: { frame: Uint8Array; reservation: ReturnType<TranslatorBudget["reserveTransient"]>; observation?: RelayedEventObservation }[] = [];
@@ -253,12 +266,13 @@ export function encodeAdapterEventStream(
253
266
  }
254
267
  wireActivity = true;
255
268
  },
256
- emitBounded: text => {
269
+ emitBounded: (text, onAdmitted) => {
257
270
  if (closed) return;
258
271
  try {
259
272
  controller.enqueue(textEncoder.encode(text));
260
273
  emittedFrames++;
261
274
  relayed({ terminal: true });
275
+ onAdmitted?.();
262
276
  } catch {
263
277
  closed = true;
264
278
  }
@@ -546,10 +560,13 @@ export function encodeAdapterEventStream(
546
560
  stepping = true;
547
561
  gated = false;
548
562
  const emittedAtStart = emittedFrames;
563
+ let readingUpstream = false;
549
564
  try {
550
565
  while (!terminated && !closed && emittedFrames === emittedAtStart) {
551
566
  iteratorStarted = true;
567
+ readingUpstream = true;
552
568
  const next = await it.next();
569
+ readingUpstream = false;
553
570
  // A cancel during the await must not process or charge a late event.
554
571
  if (closed || clientCancelled) {
555
572
  gated = true;
@@ -794,6 +811,7 @@ export function encodeAdapterEventStream(
794
811
  reportUsage: event.usage !== undefined,
795
812
  durable: true,
796
813
  };
814
+ originalErrorEvidence.set(terminal, { status: event.status, type: event.errorType, code: event.code, message: event.message });
797
815
  break;
798
816
  }
799
817
  default:
@@ -823,6 +841,7 @@ export function encodeAdapterEventStream(
823
841
  reportUsage: false,
824
842
  durable: false,
825
843
  };
844
+ if (readingUpstream) encoderTransportFailures.add(terminal);
826
845
  try {
827
846
  if (!await deliverTerminalGuarded(terminal)) return;
828
847
  } catch { /* a failing hook on the failure path must not throw into the pull */ }
@@ -1,3 +1,7 @@
1
+ import type { UpstreamConditionEvidence } from "../../lib/upstream-condition";
2
+ import { ownedAnthropicErrorPayload, ownedAnthropicErrorResponse, messagesOverflowPresentation, messagesRelayedOverflowPresentation } from "../../lib/messages-error-body";
3
+ import { proxyMessagePresentation, markProxyError, isProxyError, hasProxyErrorMessage } from "../../lib/client-error-body";
4
+ import { admitMessagesFailure, type MessagesFailureVerdictSink } from "../../claude/failure-verdict";
1
5
  /**
2
6
  * AdapterEvent -> Anthropic Messages, without the internal Responses SSE (PF-09).
3
7
  *
@@ -21,13 +25,15 @@ import { encodeReasoningEnvelope } from "../../responses/reasoning-envelope";
21
25
  import { responsesUsage, webSearchAction } from "../../bridge/internal";
22
26
  import {
23
27
  anthropicErrorBody,
24
- anthropicErrorResponse,
28
+ anthropicErrorType,
29
+ isThroughputLimitText,
25
30
  anthropicFailedStatus,
26
31
  anthropicIncompleteOutcome,
27
32
  anthropicUsage,
28
33
  boundedReasoningIdentity,
29
34
  collectAnthropicMessage,
30
35
  isClaudeWebSearchToolName,
36
+ isContextOverflowError,
31
37
  messageSnapshot,
32
38
  sanitizeWebSearchInput,
33
39
  sseFrame,
@@ -35,6 +41,8 @@ import {
35
41
  } from "../../claude/outbound";
36
42
  import {
37
43
  encodeAdapterEventStream,
44
+ isEncoderTransportFailure,
45
+ encoderOriginalErrorEvidence,
38
46
  type AdapterEventEncodeOptions,
39
47
  type ClientFrameSink,
40
48
  type ClientWireWriter,
@@ -51,6 +59,8 @@ export interface AnthropicMessageEncodeOptions extends AdapterEventEncodeOptions
51
59
  model: string;
52
60
  /** This proxy's prompt estimate for `message_start` when no usage arrived first (#4857). */
53
61
  inputTokenFloor?: number;
62
+ failureVerdictSink?: MessagesFailureVerdictSink;
63
+ proxyErrorContext?: object;
54
64
  }
55
65
 
56
66
  interface OpenBlock {
@@ -84,6 +94,7 @@ function createAnthropicMessageWriter(
84
94
  sink: ClientFrameSink,
85
95
  model: string,
86
96
  inputTokenFloor: number | undefined,
97
+ options: AnthropicMessageEncodeOptions,
87
98
  ): ClientWireWriter {
88
99
  const budget = sink.budget;
89
100
  let started = false;
@@ -184,22 +195,30 @@ function createAnthropicMessageWriter(
184
195
  terminalDelivered = true;
185
196
  };
186
197
  // Transient upstream statuses become overloaded_error so Anthropic SDK clients back off.
187
- const fail = (status: number, message: string, upstreamDerived = false, code?: string) => {
198
+ const fail = (status: number, message: string, upstreamDerived = false, code?: string, local = false, contract?: "stream_incomplete" | "transport_failed", evidence?: UpstreamConditionEvidence) => {
188
199
  if (terminated && (code !== "translation_buffer_limit" || terminalDelivered)) return;
189
200
  terminated = true;
201
+ const type = code === "translation_buffer_limit" ? "request_too_large"
202
+ : upstreamDerived && isTransientUpstreamStatus(status) ? "overloaded_error" : anthropicErrorType(status);
203
+ const legacy = anthropicErrorBody(status, message, type, code);
204
+ const payload = ownedAnthropicErrorPayload({ status, type, code, evidence: evidence ?? { status, message }, contract,
205
+ overflow: messagesOverflowPresentation((legacy.error as Rec).message),
206
+ condition: code === "context_length_exceeded" && isThroughputLimitText(message) ? "rate_limited" : undefined,
207
+ ...(local ? { localError: markProxyError({ message }, proxyMessagePresentation(options.proxyErrorContext, message, { type: evidence?.type, code: evidence?.code ?? code })) } : {}),
208
+ });
209
+ const admitted = () => admitMessagesFailure(options.failureVerdictSink, payload, legacy);
190
210
  if (code === "translation_buffer_limit") {
191
211
  releaseThinkingBuffer(open);
192
212
  if (open?.callId) budget.closeCall(open.callId);
193
213
  open = null;
194
214
  terminalDelivered = true;
195
215
  // No normal close frames are valid after overflow: one bounded typed terminal.
196
- sink.emitBounded(sseFrame("error", anthropicErrorBody(413, message, "request_too_large", "translation_buffer_limit")));
216
+ sink.emitBounded(sseFrame("error", payload), admitted);
197
217
  return;
198
218
  }
199
- const type = upstreamDerived && isTransientUpstreamStatus(status) ? "overloaded_error" : undefined;
200
219
  // An initial failure is an error stream, not a partial message: no message_start first.
201
220
  if (started) closeOpenBlock();
202
- emit("error", anthropicErrorBody(status, message, type, code), { terminal: true });
221
+ sink.emit(sseFrame("error", payload), { terminal: true }, admitted, sseFrame("error", legacy));
203
222
  terminalDelivered = true;
204
223
  };
205
224
 
@@ -370,7 +389,7 @@ function createAnthropicMessageWriter(
370
389
  terminal(terminal) {
371
390
  if (terminal.status === "completed") {
372
391
  if (terminal.endTurn === false && !sawToolUse) {
373
- fail(529, "upstream turn ended without a final answer", true);
392
+ fail(529, "upstream turn ended without a final answer", true, undefined, true);
374
393
  return;
375
394
  }
376
395
  finish(sawToolUse ? "tool_use" : "end_turn", responsesUsage(terminal.usage));
@@ -379,21 +398,27 @@ function createAnthropicMessageWriter(
379
398
  if (terminal.status === "incomplete") {
380
399
  const outcome = anthropicIncompleteOutcome(terminal.incomplete?.reason, terminal.incomplete?.message);
381
400
  if ("stopReason" in outcome) finish(outcome.stopReason, terminal.usageOnWire ? responsesUsage(terminal.usage) : null);
382
- else fail(529, outcome.failMessage, true);
401
+ else fail(529, outcome.failMessage, true, undefined, isProxyError(terminal), "stream_incomplete");
383
402
  return;
384
403
  }
385
404
  const error = (terminal.error ?? {}) as unknown as Rec;
386
405
  if (error.code === "translation_buffer_limit") {
387
- fail(413, "upstream translation buffer exceeded the safe limit", false, "translation_buffer_limit");
406
+ fail(413, "upstream translation buffer exceeded the safe limit", false, "translation_buffer_limit", true);
388
407
  return;
389
408
  }
390
409
  const message = typeof error.message === "string" ? error.message : "upstream request failed";
391
410
  const deterministic = error.code === UNDECLARED_TOOL_CALL_ERROR_CODE;
392
- fail(anthropicFailedStatus(error, message), message, !deterministic,
393
- deterministic || error.code === "context_length_exceeded" ? error.code as string : undefined);
411
+ const transportFailure = isEncoderTransportFailure(terminal);
412
+ const classified = transportFailure ? { ...error, code: "upstream_stream_error", status: 502 } : error;
413
+ const overflow = isContextOverflowError(classified, message);
414
+ const original = encoderOriginalErrorEvidence(terminal);
415
+ fail(anthropicFailedStatus(classified, message), message, !deterministic,
416
+ deterministic ? error.code as string : overflow ? "context_length_exceeded" : undefined,
417
+ hasProxyErrorMessage(options.proxyErrorContext, message, { type: typeof error.type === "string" ? error.type : undefined, code: typeof error.code === "string" ? error.code : undefined }), transportFailure ? "transport_failed" : undefined,
418
+ { ...(original ?? { message, type: typeof error.type === "string" ? error.type : undefined, code: typeof error.code === "string" ? error.code : undefined }), status: original?.status ?? anthropicFailedStatus(classified, message) });
394
419
  },
395
420
  overflow() {
396
- fail(413, "upstream translation buffer exceeded the safe limit", false, "translation_buffer_limit");
421
+ fail(413, "upstream translation buffer exceeded the safe limit", false, "translation_buffer_limit", true);
397
422
  },
398
423
  dispose() {
399
424
  releaseThinkingBuffer(open);
@@ -409,7 +434,7 @@ export function encodeAnthropicMessageSse(
409
434
  ): ReadableStream<Uint8Array> {
410
435
  return encodeAdapterEventStream(
411
436
  events,
412
- sink => createAnthropicMessageWriter(sink, options.model, options.inputTokenFloor),
437
+ sink => createAnthropicMessageWriter(sink, options.model, options.inputTokenFloor, options),
413
438
  { ...options, get localUpstream() { return options.localUpstream; }, keepaliveMs: MESSAGES_KEEPALIVE_MS },
414
439
  );
415
440
  }
@@ -423,32 +448,49 @@ export async function collectAnthropicMessageResponse(
423
448
  stream: ReadableStream<Uint8Array>,
424
449
  model: string,
425
450
  translatorBudget: TranslatorBudget,
451
+ failureVerdictSink?: MessagesFailureVerdictSink,
426
452
  ): Promise<Response> {
427
453
  let message: Rec;
454
+ const collectorVerdictSink: MessagesFailureVerdictSink = failureVerdictSink ?? {};
428
455
  try {
429
- message = await collectAnthropicMessage(stream, model, translatorBudget);
456
+ message = await collectAnthropicMessage(stream, model, translatorBudget, collectorVerdictSink);
430
457
  } catch (error) {
431
458
  if (isTranslatorBudgetExceededError(error)) {
432
- return anthropicErrorResponse(413, error.message, "request_too_large", error.code);
459
+ const legacy = anthropicErrorBody(413, error.message, "request_too_large", "translation_buffer_limit");
460
+ return ownedAnthropicErrorResponse({ status: 413, type: "request_too_large", code: "translation_buffer_limit",
461
+ evidence: { status: 413, message: error.message }, overflow: messagesRelayedOverflowPresentation("", legacy) }, legacy);
433
462
  }
434
- return anthropicErrorResponse(502, error instanceof Error ? error.message : String(error), "api_error");
463
+ const message = error instanceof Error ? error.message : String(error);
464
+ const legacy = anthropicErrorBody(502, message, "api_error");
465
+ return ownedAnthropicErrorResponse({ status: 502, type: "api_error", evidence: { status: 502, message },
466
+ contract: "transport_failed", overflow: messagesRelayedOverflowPresentation("", legacy) }, legacy);
435
467
  }
436
- const isError = message.type === "error";
437
- const translatedError = isError && typeof message.error === "object"
438
- ? (message as { error: { code?: unknown; message?: unknown } }).error
468
+ const legacy = collectorVerdictSink.collected ?? message;
469
+ const isError = legacy.type === "error";
470
+ const translatedError = isError && typeof legacy.error === "object"
471
+ ? (legacy as { error: { code?: unknown; message?: unknown } }).error
439
472
  : undefined;
440
473
  if (translatedError?.code === "translation_buffer_limit") {
441
- return anthropicErrorResponse(
442
- 413,
443
- typeof translatedError.message === "string"
444
- ? translatedError.message
445
- : "upstream translation buffer exceeded the safe limit",
446
- "request_too_large",
447
- "translation_buffer_limit",
448
- );
474
+ const originalMessage = typeof translatedError.message === "string" ? translatedError.message : "upstream translation buffer exceeded the safe limit";
475
+ const legacy = anthropicErrorBody(413, originalMessage, "request_too_large", "translation_buffer_limit");
476
+ return ownedAnthropicErrorResponse({ status: 413, type: "request_too_large", code: "translation_buffer_limit",
477
+ evidence: { status: 413, message: originalMessage }, overflow: messagesRelayedOverflowPresentation("", legacy) }, legacy);
478
+ }
479
+ const baselineOverflow = isError && translatedError?.code === "context_length_exceeded";
480
+ const status = isError ? (baselineOverflow ? 400 : 502) : 200;
481
+ if (collectorVerdictSink.collectedErrorEvent && !collectorVerdictSink.collectedProjection) {
482
+ const error = (message.error ?? {}) as Rec;
483
+ const originalMessage = typeof error.message === "string" ? error.message : "";
484
+ const throughput = isThroughputLimitText(originalMessage);
485
+ message = ownedAnthropicErrorPayload({ status, type: typeof error.type === "string" ? error.type : undefined,
486
+ code: typeof error.code === "string" ? error.code : undefined,
487
+ evidence: { status, message: originalMessage },
488
+ overflow: messagesRelayedOverflowPresentation(JSON.stringify(message), message),
489
+ ...(error.code === "context_length_exceeded" && throughput ? { condition: "rate_limited" as const } : {}),
490
+ });
449
491
  }
450
492
  return new Response(JSON.stringify(message), {
451
- status: isError ? (translatedError?.code === "context_length_exceeded" ? 400 : 502) : 200,
493
+ status,
452
494
  headers: { "Content-Type": "application/json" },
453
495
  });
454
496
  }
@@ -458,9 +500,11 @@ export function foldAnthropicMessage(
458
500
  events: AsyncIterable<AdapterEvent>,
459
501
  options: AnthropicMessageEncodeOptions,
460
502
  ): Promise<Response> {
503
+ const failureVerdictSink: MessagesFailureVerdictSink = options.failureVerdictSink ?? {};
461
504
  return collectAnthropicMessageResponse(
462
- encodeAnthropicMessageSse(events, options),
505
+ encodeAnthropicMessageSse(events, { ...options, failureVerdictSink }),
463
506
  options.model,
464
507
  options.translatorBudget,
508
+ failureVerdictSink,
465
509
  );
466
510
  }
@@ -236,13 +236,41 @@ const ANTIGRAVITY_EFFORT_WIRE_MAP: Record<string, Record<string, string>> = {
236
236
  * Sending `thinkingLevel` beside such a suffix states the effort twice, and CCA does not reject
237
237
  * the contradiction — a `-low` wire id paired with `HIGH` returns 200, so the tier that actually
238
238
  * ran becomes unknowable from the response. Membership also makes static resolution
239
- * byte-identical to the discovery path, which never emits a thinking level.
239
+ * byte-identical to discovery, except when an opted-in Argon summary needs its matching level.
240
240
  *
241
241
  * `gemini-3.1-pro` is deliberately absent: its `high` rung is `gemini-pro-agent`, which carries
242
242
  * no tier suffix, so there the level is the only thing naming the effort.
243
243
  */
244
244
  const ANTIGRAVITY_SUFFIX_TIER_MODELS = new Set([GEMINI_ARGON, "gemini-3.8-flash", CLAUDE_OPUS_55, CLAUDE_SONNET_55]);
245
245
 
246
+ /**
247
+ * Suffix-tier models that withhold `thought: true` text unless the request ALSO names its tier
248
+ * in `thinkingConfig.thinkingLevel`.
249
+ *
250
+ * Measured against live CCA (2026-10-27): `gemini-4-argon-high` with
251
+ * `{includeThoughts: true}` alone answers 200 with `thoughtsTokenCount` in the thousands and
252
+ * zero thought parts — the whole plan arrives as ordinary visible text. Sending
253
+ * `{thinkingLevel: "high", includeThoughts: true}` on the same wire id returns the thought
254
+ * parts. `gemini-3.8-flash-high` does not behave this way: its include-only request still
255
+ * returns thoughts, so it stays out of this set and keeps the one-field shape.
256
+ */
257
+ const ANTIGRAVITY_THOUGHT_LEVEL_REQUIRED_SUFFIX_MODELS = new Set([GEMINI_ARGON]);
258
+
259
+ function suffixThoughtLevel(wireModelId: string, includeThoughts: boolean | undefined): string | undefined {
260
+ if (!includeThoughts) return undefined;
261
+ for (const base of ANTIGRAVITY_THOUGHT_LEVEL_REQUIRED_SUFFIX_MODELS) {
262
+ for (const tier of ANTIGRAVITY_DISCOVERY_EFFORTS) {
263
+ if (wireModelId === `${base}-${tier}`) return tier;
264
+ }
265
+ }
266
+ return undefined;
267
+ }
268
+
269
+ function suffixThoughtWire(wireModelId: string, includeThoughts: boolean | undefined): { wireModelId: string; thinkingLevel?: string } {
270
+ const thinkingLevel = suffixThoughtLevel(wireModelId, includeThoughts);
271
+ return { wireModelId, ...(thinkingLevel ? { thinkingLevel } : {}) };
272
+ }
273
+
246
274
  function completeDiscoveredEffortWireModelIds(
247
275
  pickerId: string,
248
276
  available: ReadonlyMap<string, Record<string, unknown>>,
@@ -719,8 +747,8 @@ export function resolveAntigravityWireModelId(modelId: string, baseUrl?: string)
719
747
 
720
748
  /**
721
749
  * Whether the given model ID is a suffix wire ID or compat alias that already encodes
722
- * an effort level. For these IDs, the caller must NOT send thinkingConfig — the suffix
723
- * IS the effort, and sending both creates a contradictory request.
750
+ * an effort level. The suffix names the effort; an opted-in Argon summary additionally
751
+ * repeats that same level in thinkingConfig.
724
752
  */
725
753
  export function isAntigravitySuffixModelId(modelId: string): boolean {
726
754
  return !ANTIGRAVITY_KNOWN_PICKER_MODELS.includes(modelId);
@@ -735,9 +763,9 @@ export function retiredAntigravityFlashTier(modelId: string): string | undefined
735
763
  * Resolve a picker-visible base model + optional reasoning effort to the CCA wire model ID.
736
764
  *
737
765
  * Precedence (evaluated in order):
738
- * 1. Suffix wire ID or compat alias → resolve via `resolveAntigravityWireModelId`, no thinkingConfig.
766
+ * 1. Suffix wire ID or compat alias → resolve via `resolveAntigravityWireModelId`.
739
767
  * 2. Mapped Gemini base with effort → return mapped wire ID + thinkingLevel.
740
- * 3. Mapped Gemini base without effort → return default-effort wire ID, no thinkingConfig.
768
+ * 3. Mapped Gemini base without effort → return default-effort wire ID.
741
769
  * 4. Claude Opus with effort → return identity + thinkingLevel (no suffix variants exist).
742
770
  * 5. All other IDs → return `resolveAntigravityWireModelId(modelId)`, no thinkingConfig.
743
771
  */
@@ -745,9 +773,12 @@ export function resolveAntigravityEffortWireModel(
745
773
  modelId: string,
746
774
  effort?: string,
747
775
  baseUrl?: string,
776
+ options?: { includeThoughts?: boolean },
748
777
  ): { wireModelId: string; thinkingLevel?: string } {
749
778
  const discoveredEffortWireModelId = discoveredAntigravityEffortWireModelId(modelId, effort, baseUrl);
750
- if (discoveredEffortWireModelId) return { wireModelId: discoveredEffortWireModelId };
779
+ if (discoveredEffortWireModelId) {
780
+ return suffixThoughtWire(discoveredEffortWireModelId, options?.includeThoughts);
781
+ }
751
782
 
752
783
  // A collapsed picker row reports ONE representative wire id (whichever tier CCA
753
784
  // listed first), so live discovery cannot describe a ladder — it can only name a
@@ -763,11 +794,12 @@ export function resolveAntigravityEffortWireModel(
763
794
  : discoveredAntigravityWireModelId(modelId, baseUrl);
764
795
  if (discoveredWireModelId && (discoveredWireModelId !== modelId || isAntigravitySuffixModelId(modelId))) {
765
796
  const defaultLevel = ANTIGRAVITY_THINKING_LEVEL_MODELS[modelId];
797
+ const suffixLevel = suffixThoughtLevel(discoveredWireModelId, options?.includeThoughts);
766
798
  return {
767
799
  wireModelId: discoveredWireModelId,
768
800
  ...(defaultLevel
769
801
  ? { thinkingLevel: effort ? resolveAntigravityThinkingLevel(effort) ?? defaultLevel : defaultLevel }
770
- : {}),
802
+ : suffixLevel ? { thinkingLevel: suffixLevel } : {}),
771
803
  };
772
804
  }
773
805
 
@@ -786,7 +818,8 @@ export function resolveAntigravityEffortWireModel(
786
818
 
787
819
  // Rule 1: suffix/compat alias — suffix IS the effort.
788
820
  if (isAntigravitySuffixModelId(modelId)) {
789
- return { wireModelId: resolveAntigravityWireModelId(modelId, baseUrl) };
821
+ const wireModelId = resolveAntigravityWireModelId(modelId, baseUrl);
822
+ return suffixThoughtWire(wireModelId, options?.includeThoughts);
790
823
  }
791
824
 
792
825
  // Rule 1b: single-wire-id Gemini model whose tiers ride on thinkingLevel. Without
@@ -809,13 +842,13 @@ export function resolveAntigravityEffortWireModel(
809
842
  const requested = suffixTiered && effort
810
843
  ? resolveAntigravityThinkingLevel(effort) ?? effort
811
844
  : effort;
812
- if (requested && requested in effortMap) {
845
+ if (requested && Object.hasOwn(effortMap, requested)) {
813
846
  const wireModelId = effortMap[requested]!;
814
- // The suffix already names the tier; see ANTIGRAVITY_SUFFIX_TIER_MODELS.
815
- return suffixTiered ? { wireModelId } : { wireModelId, thinkingLevel: requested };
847
+ return suffixTiered ? suffixThoughtWire(wireModelId, options?.includeThoughts)
848
+ : { wireModelId, thinkingLevel: requested };
816
849
  }
817
850
  const defaultEffort = ANTIGRAVITY_DEFAULT_EFFORT[modelId]!;
818
- return { wireModelId: effortMap[defaultEffort]! };
851
+ return suffixThoughtWire(effortMap[defaultEffort]!, options?.includeThoughts);
819
852
  }
820
853
 
821
854
  // Rule 4: Claude models — effort via thinkingConfig only (no suffix variants).