@bitkyc08/opencodex 2.99.0 → 2.100.1

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 (276) hide show
  1. package/AGENTS_INSTALL.md +19 -1
  2. package/README.md +37 -33
  3. package/SPONSORS.md +5 -1
  4. package/bin/ocx.mjs +1 -1
  5. package/gui/dist/assets/{App-C1hGwaN1.css → App-COo8Yopd.css} +1 -1
  6. package/gui/dist/assets/App-g3Cm2xhZ.js +59 -0
  7. package/gui/dist/assets/Tray-BMDkAiXy.js +1 -0
  8. package/gui/dist/assets/brand-mark-nr3ziR-T.js +1 -0
  9. package/gui/dist/assets/index-Bziu8gTy.css +2 -0
  10. package/gui/dist/assets/index-OYzhQUNP.js +94 -0
  11. package/gui/dist/assets/{segment-thumb-features-fYEMxBaW.js → segment-thumb-features-DKCVUUTi.js} +1 -1
  12. package/gui/dist/classic/assets/App-CgPBKUP-.js +58 -0
  13. package/gui/dist/classic/assets/{Tray-BqZueZOx.js → Tray-BedmOsE7.js} +1 -1
  14. package/gui/dist/classic/assets/index-BR-HhNrp.js +94 -0
  15. package/gui/dist/classic/assets/quota-summary-CXKhvSmQ.js +1 -0
  16. package/gui/dist/classic/index.html +1 -1
  17. package/gui/dist/index.html +2 -2
  18. package/native/ocx-child/Cargo.lock +215 -0
  19. package/native/ocx-child/Cargo.toml +31 -0
  20. package/native/ocx-child/src/cli.rs +1901 -0
  21. package/native/ocx-child/src/codex_home.rs +429 -0
  22. package/native/ocx-child/src/codex_settings.rs +231 -0
  23. package/native/ocx-child/src/daemon.rs +363 -0
  24. package/native/ocx-child/src/http_wire.rs +619 -0
  25. package/native/ocx-child/src/journal.rs +977 -0
  26. package/native/ocx-child/src/lib.rs +22 -0
  27. package/native/ocx-child/src/main.rs +9 -0
  28. package/native/ocx-child/src/parity.rs +102 -0
  29. package/native/ocx-child/src/platform.rs +1487 -0
  30. package/native/ocx-child/src/relay.rs +1288 -0
  31. package/native/ocx-child/src/relay_auth.rs +166 -0
  32. package/native/ocx-child/src/routes.rs +236 -0
  33. package/native/ocx-child/src/state.rs +190 -0
  34. package/native/ocx-child/src/test_hooks.rs +58 -0
  35. package/native/ocx-child/src/toml_surgeon.rs +1156 -0
  36. package/package.json +8 -2
  37. package/src/adapters/anthropic-image-normalize.ts +1 -1
  38. package/src/adapters/anthropic.ts +28 -2
  39. package/src/adapters/claude-cli/adapter.ts +5 -25
  40. package/src/adapters/claude-cli/instruction-images.ts +31 -0
  41. package/src/adapters/claude-cli/stable-replay.ts +42 -14
  42. package/src/adapters/claude-cli/usage-admission.ts +53 -64
  43. package/src/adapters/client-fingerprint.ts +1 -1
  44. package/src/adapters/coding-agent/protocol.ts +1 -1
  45. package/src/adapters/devin/live-models.ts +3 -0
  46. package/src/adapters/google-http.ts +3 -0
  47. package/src/adapters/google-vertex-key-project.ts +10 -2
  48. package/src/adapters/google.ts +40 -8
  49. package/src/adapters/kiro/usage.ts +3 -13
  50. package/src/adapters/openai-chat/mistral-image-limit.ts +28 -15
  51. package/src/adapters/openai-chat-images.ts +100 -0
  52. package/src/adapters/openai-chat.ts +6 -9
  53. package/src/adapters/openai-responses/passthrough.ts +5 -2
  54. package/src/adapters/openai-responses/request-strips.ts +32 -0
  55. package/src/adapters/openai-responses/tool-schema.ts +9 -4
  56. package/src/chat/inbound.ts +1 -1
  57. package/src/claude/auth-detect.ts +26 -8
  58. package/src/claude/inbound-content-options.ts +18 -3
  59. package/src/claude/inbound.ts +5 -2
  60. package/src/cli/bundled-bun-diagnostic.ts +91 -0
  61. package/src/cli/capabilities-agents-routing.ts +2 -2
  62. package/src/cli/capabilities-observe-system.ts +60 -0
  63. package/src/cli/combo-input.ts +6 -0
  64. package/src/cli/combo-result.ts +1 -1
  65. package/src/cli/combo.ts +4 -0
  66. package/src/cli/config-command.ts +16 -2
  67. package/src/cli/connect.ts +12 -10
  68. package/src/cli/dispatch.ts +4 -0
  69. package/src/cli/doctor.ts +11 -0
  70. package/src/cli/help.ts +1 -0
  71. package/src/cli/init.ts +4 -0
  72. package/src/cli/link-enrollment.ts +152 -25
  73. package/src/cli/link-local-control.ts +49 -0
  74. package/src/cli/link.ts +37 -10
  75. package/src/cli/provider-lifecycle-runtime.ts +4 -2
  76. package/src/cli/registry.ts +13 -0
  77. package/src/cli/star-prompt.ts +2 -0
  78. package/src/cli/status.ts +1 -1
  79. package/src/cli/telemetry-profile.ts +206 -0
  80. package/src/cli/telemetry.ts +260 -0
  81. package/src/client/hub-relay.ts +26 -0
  82. package/src/client/machine-api.ts +3 -0
  83. package/src/clients/config-export/t3code.ts +44 -5
  84. package/src/clients/omo-role-models.ts +1 -1
  85. package/src/codex/catalog/bundled.ts +44 -2
  86. package/src/codex/runtime.ts +12 -0
  87. package/src/codex/shim-restore-lock.ts +67 -30
  88. package/src/combos/types.ts +21 -1
  89. package/src/config/atomic-write.ts +24 -1
  90. package/src/config/diagnostics.ts +15 -0
  91. package/src/config/live-reconcile.ts +17 -0
  92. package/src/config/load-degrade.ts +16 -0
  93. package/src/config/provider-validation.ts +29 -0
  94. package/src/config/schema/config-schema.ts +24 -0
  95. package/src/config/schema/leaf-validators.ts +17 -0
  96. package/src/config/telemetry-carry.ts +30 -0
  97. package/src/config.ts +13 -1
  98. package/src/generated/compatibility-version.json +422 -170
  99. package/src/generated/model-metadata.ts +3 -3
  100. package/src/integrations/aside-profiles.ts +7 -1
  101. package/src/integrations/owned-refresh.ts +9 -2
  102. package/src/lab/artifacts/secure-fs.ts +12 -11
  103. package/src/lab/fabric/scratch.ts +11 -9
  104. package/src/lab/public/community.ts +2 -3
  105. package/src/lab/public/file-safety.ts +18 -20
  106. package/src/lab/public/mutation-lock.ts +109 -337
  107. package/src/lab/public/private-file.ts +4 -3
  108. package/src/lib/bun-runtime-preflight.ts +1 -1
  109. package/src/lib/codex-catalog-read-only.ts +122 -0
  110. package/src/lib/config-ownership.ts +56 -18
  111. package/src/lib/errors.ts +11 -0
  112. package/src/lib/gcp-adc.ts +167 -48
  113. package/src/lib/jsonc.ts +4 -2
  114. package/src/lib/local-control-socket.ts +88 -0
  115. package/src/lib/privacy.ts +15 -0
  116. package/src/lib/provider-client-headers.ts +3 -0
  117. package/src/lib/token-estimate.ts +13 -2
  118. package/src/link/child-binary-source.ts +228 -0
  119. package/src/link/ephemeral-child.ts +45 -0
  120. package/src/link/remote-plant.ts +306 -0
  121. package/src/link/remote-windows.ts +59 -5
  122. package/src/link/ssh-argv.ts +71 -8
  123. package/src/link/status-projection.ts +2 -0
  124. package/src/link/store.ts +5 -1
  125. package/src/oauth/anthropic-model-quota.ts +12 -0
  126. package/src/oauth/anthropic-routing.ts +11 -4
  127. package/src/oauth/claude-keychain-read.ts +165 -0
  128. package/src/oauth/kiro-iam-identity-center.ts +4 -1
  129. package/src/oauth/local-token-detect.ts +14 -17
  130. package/src/protocols/envelope.ts +20 -2
  131. package/src/providers/api-key-selection.ts +8 -2
  132. package/src/providers/claude-cli-identity.ts +9 -3
  133. package/src/providers/claude-cli-usage-state.ts +93 -0
  134. package/src/providers/claude-cli-usage.ts +3 -2
  135. package/src/providers/github-copilot-auto.ts +25 -5
  136. package/src/providers/meta-muse-plan-refusal.ts +94 -0
  137. package/src/providers/model-rename-fields.ts +3 -0
  138. package/src/providers/quota/anthropic-family-headers.ts +8 -1
  139. package/src/providers/quota/anthropic-usage-windows.ts +49 -2
  140. package/src/providers/quota/vendor-probes-key.ts +23 -4
  141. package/src/providers/quota/vendor-probes-oauth.ts +59 -0
  142. package/src/providers/quota/workbuddy.ts +2 -2
  143. package/src/providers/quota-types.ts +7 -0
  144. package/src/providers/quota.ts +25 -18
  145. package/src/providers/registry/entries-core.ts +7 -4
  146. package/src/providers/registry/entries-extended.ts +42 -8
  147. package/src/providers/registry/model-ids.ts +1 -0
  148. package/src/providers/registry/model-seeds.ts +10 -2
  149. package/src/providers/registry/types.ts +6 -0
  150. package/src/providers/resolved-model-policy.ts +4 -0
  151. package/src/providers/routed-config.ts +30 -3
  152. package/src/providers/stale-no-vision-seed-migration.ts +7 -0
  153. package/src/providers/vertex-environment-authority.ts +50 -0
  154. package/src/providers/workbuddy-credit-balance.ts +38 -6
  155. package/src/quota-pool/assemble.ts +14 -6
  156. package/src/responses/retained-compaction.ts +31 -5
  157. package/src/router.ts +1 -0
  158. package/src/server/adapter-resolve.ts +11 -6
  159. package/src/server/audio-dictation.ts +21 -7
  160. package/src/server/auth-cors.ts +19 -0
  161. package/src/server/background-lifecycle.ts +71 -0
  162. package/src/server/chat-completions.ts +2 -0
  163. package/src/server/claude-messages.ts +30 -3
  164. package/src/server/index/live-sideband.ts +15 -1
  165. package/src/server/index/local-control-listener.ts +515 -0
  166. package/src/server/index/optional-listeners.ts +21 -1
  167. package/src/server/index/serve-options.ts +4 -3
  168. package/src/server/index/websocket-handler.ts +2 -0
  169. package/src/server/index.ts +3 -0
  170. package/src/server/management/combo-routes.ts +6 -1
  171. package/src/server/management/context.ts +1 -0
  172. package/src/server/management/link-child-preflight.ts +74 -0
  173. package/src/server/management/link-enrollment.ts +190 -25
  174. package/src/server/management/link-route-state.ts +6 -1
  175. package/src/server/management/link-routes.ts +27 -9
  176. package/src/server/management/model-rows.ts +4 -0
  177. package/src/server/management/oauth-account-routes.ts +9 -4
  178. package/src/server/management/provider-overwrite-carry.ts +9 -2
  179. package/src/server/management/provider-routes.ts +14 -0
  180. package/src/server/management/provider-thinking-display-patch.ts +54 -0
  181. package/src/server/management/route-registry.ts +7 -0
  182. package/src/server/management/session-routes.ts +4 -1
  183. package/src/server/management/telemetry-routes.ts +37 -0
  184. package/src/server/management/usage-aggregate-cache.ts +290 -67
  185. package/src/server/management-api.ts +11 -2
  186. package/src/server/messages-native-preflight.ts +166 -0
  187. package/src/server/messages-native.ts +143 -43
  188. package/src/server/messages-shared.ts +14 -0
  189. package/src/server/proxy-liveness.ts +99 -6
  190. package/src/server/request-log-conversation.ts +18 -2
  191. package/src/server/request-log.ts +7 -2
  192. package/src/server/responses/adapter-continuation.ts +1 -0
  193. package/src/server/responses/adapter-dispatch.ts +11 -28
  194. package/src/server/responses/adapter-failure-message.ts +68 -0
  195. package/src/server/responses/combo-stream-preflight.ts +14 -2
  196. package/src/server/responses/compact.ts +13 -1
  197. package/src/server/responses/core-auth.ts +26 -5
  198. package/src/server/responses/core-codex-account.ts +8 -1
  199. package/src/server/responses/core-combo-failure.ts +6 -1
  200. package/src/server/responses/core-combo-native.ts +150 -37
  201. package/src/server/responses/core-combo.ts +15 -9
  202. package/src/server/responses/core-normalize.ts +1 -0
  203. package/src/server/responses/core-options.ts +7 -1
  204. package/src/server/responses/core-pipeline.ts +21 -1
  205. package/src/server/responses/fetch-helpers.ts +5 -0
  206. package/src/server/responses/opengateway-completion-guard.ts +7 -3
  207. package/src/server/responses/passthrough-delivery.ts +8 -1
  208. package/src/server/responses/passthrough-error.ts +22 -0
  209. package/src/server/responses/request-prepare.ts +7 -1
  210. package/src/server/responses/request-transport.ts +28 -5
  211. package/src/server/responses/run-turn-execution.ts +13 -0
  212. package/src/server/sse-frame-buffer.ts +5 -0
  213. package/src/server/ws-bridge.ts +10 -0
  214. package/src/service/launchd.ts +78 -4
  215. package/src/telemetry/aggregate.ts +348 -0
  216. package/src/telemetry/consent.ts +128 -0
  217. package/src/telemetry/contract.ts +403 -0
  218. package/src/telemetry/disclosure.ts +19 -0
  219. package/src/telemetry/install-id.ts +226 -0
  220. package/src/telemetry/payload.ts +129 -0
  221. package/src/telemetry/profile/client.ts +150 -0
  222. package/src/telemetry/profile/contract.ts +288 -0
  223. package/src/telemetry/profile/disclosure.ts +14 -0
  224. package/src/telemetry/profile/paths.ts +13 -0
  225. package/src/telemetry/profile/routes.ts +99 -0
  226. package/src/telemetry/profile/service.ts +234 -0
  227. package/src/telemetry/profile/state.ts +189 -0
  228. package/src/telemetry/profile/sync.ts +276 -0
  229. package/src/telemetry/routes.ts +183 -0
  230. package/src/telemetry/scheduler.ts +386 -0
  231. package/src/telemetry/sender.ts +97 -0
  232. package/src/telemetry/state.ts +334 -0
  233. package/src/types/combo-jev-effort-mode.ts +11 -0
  234. package/src/types/config.ts +3 -0
  235. package/src/types/provider.ts +11 -1
  236. package/src/types/request.ts +2 -0
  237. package/src/types/telemetry.ts +15 -0
  238. package/src/types/wire.ts +10 -0
  239. package/src/types.ts +5 -0
  240. package/src/update/index.ts +7 -1
  241. package/src/update/minisign.d.mts +17 -0
  242. package/src/update/minisign.mjs +88 -0
  243. package/src/update/signed-supply.d.mts +59 -0
  244. package/src/update/signed-supply.mjs +289 -0
  245. package/src/update/trust-root.json +38 -0
  246. package/src/update/update-bounded-json.d.mts +4 -0
  247. package/src/update/update-bounded-json.mjs +113 -0
  248. package/src/update/update-bytes.d.mts +2 -0
  249. package/src/update/update-bytes.mjs +23 -0
  250. package/src/update/update-candidate-id.d.mts +2 -0
  251. package/src/update/update-candidate-id.mjs +23 -0
  252. package/src/update/update-checkpoint-codec.d.mts +33 -0
  253. package/src/update/update-checkpoint-codec.mjs +217 -0
  254. package/src/update/update-contracts.d.mts +24 -0
  255. package/src/update/update-contracts.mjs +207 -0
  256. package/src/update/update-signature-threshold.d.mts +12 -0
  257. package/src/update/update-signature-threshold.mjs +47 -0
  258. package/src/update/update-signed-version.d.mts +5 -0
  259. package/src/update/update-signed-version.mjs +25 -0
  260. package/src/update/update-trust-anchor.d.mts +2 -0
  261. package/src/update/update-trust-anchor.mjs +2 -0
  262. package/src/usage/cache-diagnostic.ts +195 -50
  263. package/src/usage/expected-prices.ts +20 -2
  264. package/src/usage/filter-index.ts +1469 -0
  265. package/src/usage/ledger-scanner.ts +245 -4
  266. package/src/usage/source-filter.ts +10 -2
  267. package/src/usage/summary.ts +16 -0
  268. package/src/web-search/parse.ts +265 -38
  269. package/gui/dist/assets/App-BepstgEN.js +0 -59
  270. package/gui/dist/assets/Tray-BinxbEZo.js +0 -1
  271. package/gui/dist/assets/brand-mark-wzPe3R-J.js +0 -1
  272. package/gui/dist/assets/index-C-9X2yaI.js +0 -94
  273. package/gui/dist/assets/index-bnUWypyz.css +0 -2
  274. package/gui/dist/classic/assets/App-DX88_GCW.js +0 -58
  275. package/gui/dist/classic/assets/index-fSP71pLB.js +0 -94
  276. package/gui/dist/classic/assets/quota-summary-y2fl0WBv.js +0 -1
@@ -38,6 +38,7 @@ import { retainedNativeInheritanceTemplate } from "./native-template";
38
38
  import type { RawCatalog, RawEntry } from "./parsing";
39
39
  import { isSpawnableCodexCandidate } from "../exec-invocation";
40
40
  import { validatedCodexExecInvocation, validatedCodexExecInvocationAsync } from "../exec-boundary";
41
+ import { macCodexAppCommands } from "../mac-app-bundle";
41
42
  import { isPlainObject } from "../../lib/plain-data";
42
43
  import {
43
44
  parsePersistedCodexRuntime,
@@ -47,10 +48,12 @@ import {
47
48
  codexRuntimeSelectionIdentity,
48
49
  codexRuntimeStateEpoch,
49
50
  execCodexFileAsync,
51
+ codexRuntimeIsUnresolved,
50
52
  } from "../runtime";
51
53
  import type {
52
54
  DeepReadonly,
53
55
  EffortClampDiagnostic,
56
+ ResolveCodexRuntimeResult,
54
57
  ResolvedCodexRuntime,
55
58
  } from "../runtime";
56
59
  import type {
@@ -188,6 +191,12 @@ export interface BundledCatalogDeps {
188
191
  /** Already-observed source for server clamping; null never triggers a probe. */
189
192
  observedCatalog?: ReadonlyRawCatalog | null;
190
193
  commandCandidates?: () => string[];
194
+ /**
195
+ * The resolver selection `commandCandidates` came from, when the caller resolved first. Only an
196
+ * unresolved selection lets the macOS probe add the ChatGPT.app CLI (#8360); without it, injected
197
+ * candidates are probed as given.
198
+ */
199
+ selectedRuntime?: Pick<ResolvedCodexRuntime, "source" | "version">;
191
200
  execFileSync?: ExecFile;
192
201
  execFile?: (...args: Parameters<ExecFile>) => Promise<string>;
193
202
  onEffortClamp?: (diagnostic: EffortClampDiagnostic) => void;
@@ -332,6 +341,39 @@ function bundledRuntimeDeps(deps: BundledCatalogDeps) {
332
341
  };
333
342
  }
334
343
 
344
+ /**
345
+ * Candidates for the bundled-catalog probe.
346
+ *
347
+ * When discovery finds no Codex CLI it answers with the bare `codex` sentinel, so the probe
348
+ * asks a command that does not exist while a real CLI sits inside ChatGPT.app. Discovery only
349
+ * offers that app candidate after classifying the bundle's XML `Info.plist` identity, so a
350
+ * bundle it cannot classify (a binary plist, or an identity assertion that moved with an app
351
+ * update) left `ocx connect status` reporting `unverified` on a macOS Child whose only Codex
352
+ * was the bundled CLI (#8360).
353
+ *
354
+ * The known app locations are therefore added after a bare sentinel. This list grants no
355
+ * trust: every execution still passes the app-bundle signature and ownership gate in
356
+ * `exec-boundary.ts`, so an unverifiable bundle yields `null` rather than an invented ladder.
357
+ * Windows needs no entry here because its Codex App install root under LOCALAPPDATA is already
358
+ * enumerated by `installedCodexCandidates` in `runtime.ts`.
359
+ */
360
+ function bundledCatalogCandidates(
361
+ deps: BundledCatalogDeps,
362
+ resolved: ResolveCodexRuntimeResult | null,
363
+ ): string[] {
364
+ const candidates = deps.commandCandidates?.() ?? [resolved!.runtime.command];
365
+ // An explicit empty list asks for no probe at all.
366
+ if (candidates.length === 0) return candidates;
367
+ if ((deps.platform ?? process.platform) !== "darwin") return candidates;
368
+ // Decide from the resolver's own result, not from the command's shape: a bare command that ran
369
+ // (a PATH fallback or a bare CODEX_CLI_PATH) is the operator's runtime, and borrowing the app's
370
+ // catalog for it would report a ladder that runtime may reject.
371
+ const selection = resolved?.runtime ?? deps.selectedRuntime;
372
+ if (!selection || !codexRuntimeIsUnresolved(selection)) return candidates;
373
+ const exists = deps.existsSync ?? existsSync;
374
+ return [...candidates, ...macCodexAppCommands(deps).filter(command => exists(command))];
375
+ }
376
+
335
377
  function* bundledCatalogSteps(
336
378
  candidates: string[],
337
379
  cacheKey: string | null,
@@ -390,7 +432,7 @@ export function loadBundledCodexCatalog(deps: BundledCatalogDeps = {}): Readonly
390
432
  const useCache = !deps.commandCandidates && !deps.execFileSync && !deps.execFile && !deps.configDir && !deps.env;
391
433
  const resolved = deps.commandCandidates ? null : resolveAndPersistCodexRuntime(bundledRuntimeDeps(deps));
392
434
  const inputs = codexRuntimeSelectionIdentity(bundledRuntimeDeps(deps));
393
- const steps = bundledCatalogSteps(deps.commandCandidates?.() ?? [resolved!.runtime.command],
435
+ const steps = bundledCatalogSteps(bundledCatalogCandidates(deps, resolved),
394
436
  useCache ? bundledRuntimeKey(resolved!.runtime) : null,
395
437
  () => inputs === codexRuntimeSelectionIdentity(bundledRuntimeDeps(deps)));
396
438
  let step = steps.next();
@@ -449,7 +491,7 @@ export function loadBundledCodexCatalogAsync(
449
491
  const runtimeEpoch = codexRuntimeStateEpoch();
450
492
  const current = () => active() && runtimeEpoch === codexRuntimeStateEpoch()
451
493
  && flight.inputs === codexRuntimeSelectionIdentity(runtimeDeps);
452
- const steps = bundledCatalogSteps(deps.commandCandidates?.() ?? [resolved!.runtime.command],
494
+ const steps = bundledCatalogSteps(bundledCatalogCandidates(deps, resolved),
453
495
  useCache ? bundledRuntimeKey(resolved!.runtime) : null, current, false);
454
496
  let step = steps.next();
455
497
  while (!step.done) {
@@ -55,6 +55,18 @@ export interface EffortClampDiagnostic {
55
55
  readonly affectedModels: readonly string[];
56
56
  }
57
57
 
58
+ /**
59
+ * True for the selection the resolver returns when no candidate ran: the bare `codex` fallback
60
+ * with no version. A probed candidate always carries the version it parsed, so a bare command
61
+ * that actually ran (a bare CODEX_CLI_PATH or shim, or the bare fallback itself) is not this
62
+ * sentinel. Deferred resolution (`probeVersion: false`) gives every candidate a null version and
63
+ * so cannot be told apart here; the bundled-catalog probe, `ocx connect` and `ocx status` all
64
+ * resolve with probing.
65
+ */
66
+ export function codexRuntimeIsUnresolved(runtime: Pick<ResolvedCodexRuntime, "source" | "version">): boolean {
67
+ return runtime.source === "fallback" && runtime.version === null;
68
+ }
69
+
58
70
  export interface ResolveCodexRuntimeResult {
59
71
  readonly runtime: ResolvedCodexRuntime;
60
72
  readonly failures: readonly RuntimeProbeFailure[];
@@ -32,70 +32,107 @@ interface ShimRestoreLockRecord {
32
32
  createdAt: number;
33
33
  }
34
34
 
35
- interface ShimRestoreLockSnapshot {
35
+ interface ShimRestoreLockOwner {
36
36
  record: ShimRestoreLockRecord;
37
37
  ownerPath: string;
38
- lockIdentity: FileIdentity;
39
38
  fingerprint: ShimPathFingerprint;
40
39
  }
41
40
 
41
+ interface ShimRestoreLockSnapshot {
42
+ lockIdentity: FileIdentity;
43
+ /** Sorted by owner filename so two snapshots compare entry by entry. */
44
+ owners: ShimRestoreLockOwner[];
45
+ }
46
+
42
47
  function restoreLockPath(): string {
43
48
  return join(getConfigDir(), "codex-shim.autorestore.lock");
44
49
  }
45
50
 
51
+ function readShimRestoreLockOwner(path: string, entry: string): ShimRestoreLockOwner | null {
52
+ if (!entry.endsWith(".json")) return null;
53
+ const ownerPath = join(path, entry);
54
+ const probe = stableShimPathProbe(ownerPath);
55
+ if (!probe || probe.fingerprint.kind !== "file" || probe.fingerprint.size > 4096) return null;
56
+ try {
57
+ const value = JSON.parse(probe.prefix) as Partial<ShimRestoreLockRecord>;
58
+ if (value.version !== 1 || typeof value.token !== "string" || value.token.length === 0
59
+ || typeof value.pid !== "number" || !Number.isSafeInteger(value.pid) || value.pid <= 0
60
+ || typeof value.createdAt !== "number" || !Number.isFinite(value.createdAt)) return null;
61
+ if (entry !== `${value.token}.json`) return null;
62
+ return { record: value as ShimRestoreLockRecord, ownerPath, fingerprint: probe.fingerprint };
63
+ } catch {
64
+ return null;
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Every entry must be a valid token-named owner record; one unaccounted entry (foreign file,
70
+ * unparsable or empty record, mismatched name) makes the whole lock unreadable. A normal lock
71
+ * holds one owner. Two or more are not produced by the current acquire path, but have been
72
+ * observed in the field (#8317) and must stay recoverable rather than block repair forever.
73
+ */
46
74
  function readShimRestoreLockSnapshot(path: string): ShimRestoreLockSnapshot | null {
47
75
  let lockIdentity: BigIntStats;
48
76
  let entries: string[];
49
77
  try {
50
78
  lockIdentity = lstatSync(path, { bigint: true });
51
79
  if (!lockIdentity.isDirectory()) return null;
52
- entries = readdirSync(path);
80
+ entries = readdirSync(path).sort();
53
81
  } catch {
54
82
  return null;
55
83
  }
56
- if (entries.length !== 1 || !entries[0].endsWith(".json")) return null;
57
- const ownerPath = join(path, entries[0]);
58
- const probe = stableShimPathProbe(ownerPath);
59
- if (!probe || probe.fingerprint.kind !== "file" || probe.fingerprint.size > 4096) return null;
84
+ if (entries.length === 0) return null;
85
+ const owners: ShimRestoreLockOwner[] = [];
86
+ for (const entry of entries) {
87
+ const owner = readShimRestoreLockOwner(path, entry);
88
+ if (!owner) return null;
89
+ owners.push(owner);
90
+ }
60
91
  try {
61
- const value = JSON.parse(probe.prefix) as Partial<ShimRestoreLockRecord>;
62
- if (value.version !== 1 || typeof value.token !== "string" || value.token.length === 0
63
- || typeof value.pid !== "number" || !Number.isSafeInteger(value.pid) || value.pid <= 0
64
- || typeof value.createdAt !== "number" || !Number.isFinite(value.createdAt)) return null;
65
- if (entries[0] !== `${value.token}.json`) return null;
66
92
  const currentLockIdentity = lstatSync(path, { bigint: true });
67
93
  if (!currentLockIdentity.isDirectory() || !sameFileIdentity(lockIdentity, currentLockIdentity)) return null;
68
- return {
69
- record: value as ShimRestoreLockRecord,
70
- ownerPath,
71
- lockIdentity,
72
- fingerprint: probe.fingerprint,
73
- };
74
94
  } catch {
75
95
  return null;
76
96
  }
97
+ return { lockIdentity, owners };
98
+ }
99
+
100
+ /** Release only ever removes a lock it solely owns; an ambiguous set is left to stale recovery. */
101
+ function soleShimRestoreLockOwner(path: string): ShimRestoreLockOwner | null {
102
+ const snapshot = readShimRestoreLockSnapshot(path);
103
+ return snapshot?.owners.length === 1 ? snapshot.owners[0] : null;
77
104
  }
78
105
 
79
106
  function sameShimRestoreLock(left: ShimRestoreLockSnapshot, right: ShimRestoreLockSnapshot): boolean {
80
- return left.record.token === right.record.token
81
- && sameFileIdentity(left.lockIdentity, right.lockIdentity)
82
- && sameFingerprint(left.fingerprint, right.fingerprint);
107
+ return sameFileIdentity(left.lockIdentity, right.lockIdentity)
108
+ && left.owners.length === right.owners.length
109
+ && left.owners.every((owner, index) => owner.record.token === right.owners[index].record.token
110
+ && sameFingerprint(owner.fingerprint, right.owners[index].fingerprint));
83
111
  }
84
112
 
113
+ /**
114
+ * Reclaim requires every owner record to be past the stale window and to name a dead PID.
115
+ * Any live, fresh or unaccounted entry keeps the lock: age alone never evicts a live holder,
116
+ * and an entry this code cannot attribute might belong to an owner it cannot judge.
117
+ */
85
118
  function reclaimStaleRestoreLock(path: string, beforeDelete?: () => void): boolean {
86
119
  const observed = readShimRestoreLockSnapshot(path);
87
120
  if (!observed) return false;
88
- const createdAt = Math.max(observed.record.createdAt, observed.fingerprint.mtimeMs);
89
- if (Date.now() - createdAt <= CODEX_SHIM_RESTORE_LOCK_STALE_MS) return false;
90
- if (isProcessAlive(observed.record.pid)) return false;
121
+ const now = Date.now();
122
+ for (const owner of observed.owners) {
123
+ const createdAt = Math.max(owner.record.createdAt, owner.fingerprint.mtimeMs);
124
+ if (now - createdAt <= CODEX_SHIM_RESTORE_LOCK_STALE_MS) return false;
125
+ if (isProcessAlive(owner.record.pid)) return false;
126
+ }
91
127
  const current = readShimRestoreLockSnapshot(path);
92
128
  if (!current || !sameShimRestoreLock(observed, current)) return false;
93
129
  beforeDelete?.();
94
130
  try {
95
- // The token is part of the owner filename. Even if the lock directory is
96
- // replaced after the comparison, this unlink cannot target a successor's
97
- // differently named owner record.
98
- unlinkSync(observed.ownerPath);
131
+ // The token is part of each owner filename. Even if the lock directory is
132
+ // replaced after the comparison, these unlinks cannot target a successor's
133
+ // differently named owner record. A failure part-way leaves a smaller set
134
+ // of the same dead owners, which the next attempt reclaims.
135
+ for (const owner of observed.owners) unlinkSync(owner.ownerPath);
99
136
  rmdirSync(path);
100
137
  return true;
101
138
  } catch {
@@ -132,7 +169,7 @@ function tryAcquireShimRestoreLock(beforeStaleDelete?: () => void): ShimRestoreL
132
169
  released = true;
133
170
  try { closeSync(fd!); } catch { /* stale recovery handles an uncertain lock */ }
134
171
  try {
135
- const current = readShimRestoreLockSnapshot(path);
172
+ const current = soleShimRestoreLockOwner(path);
136
173
  if (identity && current && current.record.token === record.token
137
174
  && sameFileIdentity(identity, current.fingerprint.identity)) {
138
175
  unlinkSync(ownerPath);
@@ -145,7 +182,7 @@ function tryAcquireShimRestoreLock(beforeStaleDelete?: () => void): ShimRestoreL
145
182
  if (fd !== null) {
146
183
  try { closeSync(fd); } catch { /* best-effort close before ownership cleanup */ }
147
184
  try {
148
- const current = readShimRestoreLockSnapshot(path);
185
+ const current = soleShimRestoreLockOwner(path);
149
186
  if (identity && current && current.record.token === record.token
150
187
  && sameFileIdentity(identity, current.fingerprint.identity)) {
151
188
  unlinkSync(ownerPath);
@@ -7,7 +7,7 @@ import {
7
7
  } from "./jev-session-pin-config";
8
8
  import { isCodexReasoningEffort, isDeclaredReasoningEffort } from "../reasoning-effort";
9
9
  import { SUPPORTED_NATIVE_OPENAI_SLUGS } from "../codex/catalog/native-models";
10
- import type { OcxComboConfig, OcxComboCooldownWaitPolicy, OcxComboDefaultEffort, OcxComboDefaultEffortMode, OcxComboReasoningEffortMode, OcxComboStrategy, OcxComboTarget, OcxProviderConfig } from "../types";
10
+ import type { OcxComboConfig, OcxComboCooldownWaitPolicy, OcxComboDefaultEffort, OcxComboDefaultEffortMode, OcxComboJevEffortMode, OcxComboReasoningEffortMode, OcxComboStrategy, OcxComboTarget, OcxProviderConfig } from "../types";
11
11
  import { COMBO_NAMESPACE, isValidComboId, resolveComboId, targetKey } from "./identifiers";
12
12
  import {
13
13
  CANONICAL_JEV_DECISION_PROVIDER,
@@ -69,6 +69,15 @@ export interface NormalizedComboConfig {
69
69
  defaultEffortMode: OcxComboDefaultEffortMode;
70
70
  /** Picker-ladder derivation policy; `strict` preserves the legacy intersection rule. */
71
71
  reasoningEffortMode: OcxComboReasoningEffortMode;
72
+ /**
73
+ * Who owns the wire effort on a JEV combo.
74
+ *
75
+ * `decide` (default) applies the decision's effort and lets it override the caller.
76
+ * `client` keeps the decision's target choice but leaves effort to the caller and the
77
+ * target ladder, so a provider that must hold one tier to keep its prompt cache warm
78
+ * (for example one whose effort swaps the upstream model id) is never re-tiered.
79
+ */
80
+ jevEffortMode: OcxComboJevEffortMode;
72
81
  /** Disable image input; `auto` preserves the intersection derived from all targets. */
73
82
  imageInput: "auto" | "disabled";
74
83
  /** Trimmed public alias, or null when the combo keeps the default `combo/<id>` slug. */
@@ -272,6 +281,16 @@ export function comboConfigIssues(
272
281
  message: "defaultEffort is required when defaultEffortMode is force",
273
282
  });
274
283
  }
284
+ if (body.jevEffortMode !== undefined
285
+ && body.jevEffortMode !== "decide"
286
+ && body.jevEffortMode !== "client") {
287
+ issues.push({
288
+ path: ["jevEffortMode"],
289
+ message: 'jevEffortMode must be "decide" or "client"',
290
+ });
291
+ } else if (body.jevEffortMode === "client" && body.strategy !== "jev") {
292
+ issues.push({ path: ["jevEffortMode"], message: 'jevEffortMode "client" is only valid with strategy "jev"' });
293
+ }
275
294
  if (body.imageInput !== undefined && body.imageInput !== "auto" && body.imageInput !== "disabled") {
276
295
  issues.push({ path: ["imageInput"], message: 'imageInput must be "auto" or "disabled"' });
277
296
  }
@@ -564,6 +583,7 @@ export function normalizeComboConfig(raw: OcxComboConfig): NormalizedComboConfig
564
583
  defaultEffort,
565
584
  defaultEffortMode: raw.defaultEffortMode === "force" && defaultEffort !== null ? "force" : "fallback",
566
585
  reasoningEffortMode: raw.reasoningEffortMode === "adaptive" ? "adaptive" : "strict",
586
+ jevEffortMode: raw.jevEffortMode === "client" ? "client" : "decide",
567
587
  imageInput: raw.imageInput === "disabled" ? "disabled" : "auto",
568
588
  alias: alias || null,
569
589
  nativeAlias: raw.nativeAlias === true,
@@ -29,6 +29,11 @@ import {
29
29
  renameAtomicFile,
30
30
  renameAtomicFileAsync,
31
31
  } from "../lib/windows-atomic-replace";
32
+ import {
33
+ catalogReadOnlyRepairFor,
34
+ publishWithReadOnlyRepair,
35
+ setCatalogReadOnlyRepairForTests as setCatalogReadOnlyRepairOverride,
36
+ } from "../lib/codex-catalog-read-only";
32
37
  import { getConfigDir } from "./paths";
33
38
 
34
39
  let atomicSequence = 0;
@@ -103,6 +108,16 @@ export interface AtomicWriteHooks {
103
108
  afterRename?: (targetPath: string) => void;
104
109
  }
105
110
 
111
+ /**
112
+ * Test seam for the read-only catalog repair (#8358). `null` disables it, `undefined`
113
+ * restores the production rule (win32 and the OpenCodex catalog artifact only).
114
+ */
115
+ export function setCatalogReadOnlyRepairForTests(
116
+ repair: Parameters<typeof setCatalogReadOnlyRepairOverride>[0],
117
+ ): void {
118
+ setCatalogReadOnlyRepairOverride(repair);
119
+ }
120
+
106
121
  export class AtomicWriteResidualTempError extends Error {
107
122
  constructor(readonly tempPath: string, readonly hardened = true, options?: ErrorOptions) {
108
123
  super(`Atomic config write left a ${hardened ? "hardened " : ""}zero-byte temporary file`, options);
@@ -377,7 +392,13 @@ function atomicWriteFileToTarget(
377
392
  publicationAttempted = true;
378
393
  linkSync(tmp, target);
379
394
  assertIdentity(target);
380
- } else effective.rename(tmp, target);
395
+ } else {
396
+ // The Codex catalog owner repairs its own read-only artifact (#8358); every
397
+ // other destination, and every other platform, keeps the plain rename.
398
+ const repair = catalogReadOnlyRepairFor(target);
399
+ if (repair) publishWithReadOnlyRepair(() => effective.rename(tmp, target), target, repair);
400
+ else effective.rename(tmp, target);
401
+ }
381
402
  hooks.afterRename?.(target);
382
403
  if (exclusive) { assertIdentity(tmp); effective.unlink(tmp); }
383
404
  // The rename is only as durable as the directory entry recording it. Fsyncing the temp's
@@ -529,6 +550,8 @@ export async function atomicWriteFileAsync(
529
550
  }
530
551
  try { chmodSync(tempPath, 0o600); } catch { /* platform may ignore chmod */ }
531
552
  },
553
+ // The read-only catalog repair (#8358) is wired only into the sync writer; no async
554
+ // caller writes the Codex catalog today. Route one through publishWithReadOnlyRepair too.
532
555
  rename: renameAtomicFileAsync,
533
556
  truncate: target => truncateSync(target, 0),
534
557
  unlink: unlinkSync,
@@ -49,6 +49,7 @@ import {
49
49
  malformedQuotaResetNotifyWarning,
50
50
  malformedCatalogAutoRefreshWarning,
51
51
  malformedCodexPoolWarning,
52
+ malformedTelemetryWarning,
52
53
  malformedSpendWarning,
53
54
  rawConfigRecord,
54
55
  malformedNativeSubagentFields,
@@ -81,6 +82,7 @@ import {
81
82
  compactionRoutingSchema,
82
83
  reasoningRetentionSchema,
83
84
  skillsConfigSchema,
85
+ telemetryConfigSchema,
84
86
  memoryModelsSchema,
85
87
  } from "./schema/leaf-validators";
86
88
 
@@ -175,6 +177,8 @@ function validFileConfigDiagnostics(config: OcxConfig, rawParsed: unknown): Conf
175
177
  if (catalogRefreshWarning) warnings.push(catalogRefreshWarning);
176
178
  const codexPoolWarning = malformedCodexPoolWarning(rawParsed);
177
179
  if (codexPoolWarning) warnings.push(codexPoolWarning);
180
+ const telemetryWarning = malformedTelemetryWarning(rawParsed);
181
+ if (telemetryWarning) warnings.push(telemetryWarning);
178
182
  const spendWarning = malformedSpendWarning(rawParsed);
179
183
  if (spendWarning) warnings.push(spendWarning);
180
184
  const retentionWarning = degradedReasoningRetentionWarning(rawParsed, normalized);
@@ -709,6 +713,16 @@ function skillsConfigError(value: unknown): string | null {
709
713
  return "schema_invalid: skills" + (field ? "." + field : "") + ": " + (issue?.message ?? "invalid configuration");
710
714
  }
711
715
 
716
+ export function telemetryConfigError(value: unknown): string | null {
717
+ const raw = rawConfigRecord(value);
718
+ if (!raw || !Object.hasOwn(raw, "telemetry") || raw.telemetry === undefined) return null;
719
+ const result = telemetryConfigSchema.safeParse(raw.telemetry);
720
+ if (result.success) return null;
721
+ const issue = result.error.issues[0];
722
+ const field = issue?.path.join(".");
723
+ return "schema_invalid: telemetry" + (field ? "." + field : "") + ": " + (issue?.message ?? "invalid configuration");
724
+ }
725
+
712
726
  export function validateConfigCandidate(value: unknown): { ok: true; config: OcxConfig } | { ok: false; error: string } {
713
727
  const chatgptDesktop = rawConfigRecord(value)?.chatgptDesktop;
714
728
  if (chatgptDesktop !== undefined && !chatgptDesktopSchema.safeParse(chatgptDesktop).success) {
@@ -773,6 +787,7 @@ export function validateConfigCandidate(value: unknown): { ok: true; config: Ocx
773
787
  ?? managementIngressConfigError(value)
774
788
  ?? metricsExportConfigError(value)
775
789
  ?? serviceHealthRecoveryConfigError(value)
790
+ ?? telemetryConfigError(value)
776
791
  ?? skillsConfigError(value);
777
792
  if (boundaryError) return { ok: false, error: boundaryError };
778
793
  const result = configSchema.safeParse(value);
@@ -1,6 +1,7 @@
1
1
  import { observeAccountAutoPauseRevisions, snapshotAutoPauseFingerprints } from "./account-auto-pause-revisions";
2
2
  import type { OcxConfig, OcxProviderConfig, ProviderCostOverlay } from "../types";
3
3
  import { configReasoningPinsConfigError } from "./provider-validation";
4
+ import { carryPersistedTelemetry } from "./telemetry-carry";
4
5
  import { adoptCustomModelCatalogMigration, projectCustomModelCatalogMigration } from "../codex/custom-model-catalog-migration";
5
6
  import { refreshPreservedProviderOwner } from "../usage/user-cost-overlays";
6
7
  import { refreshConfigDerivedRegistries } from "./derived-registries";
@@ -118,6 +119,19 @@ export function adoptPersistedAdvisor(config: OcxConfig, persisted: OcxConfig["a
118
119
  clearConfigTopLevelDeletionIntent(config, ["advisor"]);
119
120
  if (baseline) clearConfigTopLevelDeletionIntent(baseline, ["advisor"]);
120
121
  }
122
+
123
+ /** Adopt the committed telemetry consent subtree without advancing unrelated pending live intent. */
124
+ export function adoptPersistedTelemetry(config: OcxConfig, persisted: OcxConfig["telemetry"]): void {
125
+ if (persisted === undefined) delete config.telemetry;
126
+ else config.telemetry = structuredClone(persisted);
127
+ const baseline = liveConfigBaseline.get(config);
128
+ if (baseline) {
129
+ if (persisted === undefined) delete baseline.telemetry;
130
+ else baseline.telemetry = structuredClone(persisted);
131
+ }
132
+ clearConfigTopLevelDeletionIntent(config, ["telemetry"]);
133
+ if (baseline) clearConfigTopLevelDeletionIntent(baseline, ["telemetry"]);
134
+ }
121
135
  /**
122
136
  * The live config retains the address of the socket Bun actually opened, while
123
137
  * this map retains the operator's desired address for the next process start.
@@ -623,6 +637,9 @@ export function saveConfigPreservingClaudeCode(config: OcxConfig): void {
623
637
  );
624
638
  if (provenanceProjection.configRebaseProvenance === undefined) delete projectedConfig.configRebaseProvenance;
625
639
  else projectedConfig.configRebaseProvenance = provenanceProjection.configRebaseProvenance;
640
+ // Telemetry consent is owned by the file (see carryPersistedTelemetry).
641
+ const telemetry = carryPersistedTelemetry(projectedConfig, onDisk as Record<string, unknown> | undefined);
642
+ if (telemetry.carried) adoptPersistedTelemetry(config, telemetry.value);
626
643
  const persistedBinding = (bindingBaseline || diskDeletedKeys.has("hostname")) && onDisk
627
644
  ? readPersistedServerBinding(onDisk, bindingBaseline ?? { port: config.port, hostname: config.hostname })
628
645
  : bindingBaseline;
@@ -52,6 +52,7 @@ import {
52
52
  transientRetryOn5xxPolicySchema,
53
53
  runtimeRoleSchema,
54
54
  spendSchema,
55
+ telemetryConfigSchema,
55
56
  chatgptDesktopConfigIssue,
56
57
  } from "./schema/leaf-validators";
57
58
  import { hasWarnedInheritedFastWireConflict, markWarnedInheritedFastWireConflict } from "./warn-memo";
@@ -152,6 +153,7 @@ export function warnDegradedTopLevelOptIns(rawParsed: unknown, validated: OcxCon
152
153
  warnDegradedStreamMode(rawParsed, validated);
153
154
  warnDegradedCompactionRouting(rawParsed, validated);
154
155
  warnDegradedMemoryModels(rawParsed, validated);
156
+ warnDegradedTelemetry(rawParsed);
155
157
  // The schema replaces a malformed policy with { allProfiles: false }, which silently turns every Aside profile off (#6757).
156
158
  const asidePolicy = rawParsed && typeof rawParsed === "object" ? (rawParsed as Record<string, unknown>).asideProfileSync : undefined;
157
159
  if (asidePolicy !== undefined && !asideProfileSyncSchema.safeParse(asidePolicy).success) {
@@ -850,6 +852,20 @@ export function malformedCodexPoolWarning(rawParsed: unknown): string | null {
850
852
  return `codexPool${field ? `.${field}` : ""} ignored: invalid Codex pool selection policy`;
851
853
  }
852
854
 
855
+ export function malformedTelemetryWarning(rawParsed: unknown): string | null {
856
+ const raw = rawConfigRecord(rawParsed);
857
+ if (!raw || !Object.hasOwn(raw, "telemetry") || raw.telemetry === undefined) return null;
858
+ const result = telemetryConfigSchema.safeParse(raw.telemetry);
859
+ if (result.success) return null;
860
+ const field = result.error.issues[0]?.path.join(".");
861
+ return `telemetry${field ? `.${field}` : ""} ignored: invalid telemetry consent configuration`;
862
+ }
863
+
864
+ export function warnDegradedTelemetry(rawParsed: unknown): void {
865
+ const warning = malformedTelemetryWarning(rawParsed);
866
+ if (warning) console.warn(`⚠️ config.json ${warning}. Other settings were preserved.`);
867
+ }
868
+
853
869
  /**
854
870
  * Warn once per load that the section was dropped.
855
871
  *
@@ -13,6 +13,7 @@ import {
13
13
  isWirePinnedModel,
14
14
  MODEL_ADAPTER_OVERRIDE_ALLOWED,
15
15
  REASONING_SUMMARY_DELIVERY_VALUES,
16
+ THINKING_DISPLAY_VALUES,
16
17
  UPSTREAM_HTTP_VERSION_VALUES,
17
18
  type OcxProviderConfig,
18
19
  type ModelCapabilities,
@@ -29,6 +30,7 @@ const SENSITIVE_PROVIDER_HEADERS = new Set([
29
30
  "x-amz-security-token",
30
31
  ]);
31
32
  const REASONING_SUMMARY_DELIVERY_SET = new Set<string>(REASONING_SUMMARY_DELIVERY_VALUES);
33
+ const THINKING_DISPLAY_SET = new Set<string>(THINKING_DISPLAY_VALUES);
32
34
  const DISPLAY_NAME_CONTROL_CHARS = /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/;
33
35
  const MAX_MODEL_DISPLAY_NAME_LENGTH = 128;
34
36
 
@@ -385,6 +387,33 @@ export function reasoningSummaryDeliveryRecordConfigError(
385
387
  return null;
386
388
  }
387
389
 
390
+ /** Validate `thinkingDisplay`: one closed vocabulary shared by config and management writes. */
391
+ export function thinkingDisplayConfigError(value: unknown, field = "thinkingDisplay"): string | null {
392
+ if (value === undefined) return null;
393
+ if (typeof value !== "string" || !THINKING_DISPLAY_SET.has(value)) {
394
+ return `${field} must be one of: ${THINKING_DISPLAY_VALUES.join(", ")}`;
395
+ }
396
+ return null;
397
+ }
398
+
399
+ /** Validate `modelThinkingDisplay`: a plain map of model id to the same closed vocabulary. */
400
+ export function modelThinkingDisplayConfigError(value: unknown, field = "modelThinkingDisplay"): string | null {
401
+ if (value === undefined) return null;
402
+ if (!value || typeof value !== "object" || Array.isArray(value)) return `${field} must be a plain object`;
403
+ const prototype = Object.getPrototypeOf(value);
404
+ if (prototype !== Object.prototype && prototype !== null) return `${field} must be a plain object with own properties`;
405
+ for (const [key, entry] of Object.entries(value)) {
406
+ const safeKey = JSON.stringify(redactSecretString(key));
407
+ if (!key.trim()) return `${field} keys must be nonblank model ids`;
408
+ if (["__proto__", "prototype", "constructor"].includes(key)) {
409
+ return `${field} keys must not be reserved object keys`;
410
+ }
411
+ const entryError = thinkingDisplayConfigError(entry, `${field}.${safeKey}`);
412
+ if (entryError) return entryError;
413
+ }
414
+ return null;
415
+ }
416
+
388
417
  /** Validate a provider's per-model wire override map against runtime routing rules. */
389
418
  export function modelAdapterRecordConfigError(
390
419
  value: unknown,
@@ -29,6 +29,7 @@ import {
29
29
  spendSchema,
30
30
  chatgptDesktopSchema,
31
31
  skillsConfigSchema,
32
+ telemetryConfigSchema,
32
33
  configuredCodexPoolAccountIds,
33
34
  apiKeyEntrySchema,
34
35
  asideProfileSyncSchema,
@@ -60,6 +61,8 @@ import {
60
61
  providerHeadersConfigError,
61
62
  providerForwardClientHeadersConfigError,
62
63
  reasoningSummaryDeliveryRecordConfigError,
64
+ thinkingDisplayConfigError,
65
+ modelThinkingDisplayConfigError,
63
66
  credentialPinnedProviderConfigError,
64
67
  } from "../provider-validation";
65
68
  import {
@@ -120,6 +123,7 @@ export const configSchema = z.object({
120
123
  skills: skillsConfigSchema.optional().catch(undefined),
121
124
  // Malformed hand edits disable this opt-in exporter. Live writes reject them in diagnostics.ts.
122
125
  metricsExport: z.object({ enabled: z.boolean().optional() }).strict().optional().catch(undefined),
126
+ telemetry: telemetryConfigSchema.optional().catch(undefined),
123
127
  // Same contract as metricsExport: a malformed hand edit leaves recovery off; live writes reject it.
124
128
  serviceHealthRecovery: z.object({ enabled: z.boolean().optional() }).strict().optional().catch(undefined),
125
129
  // Kept raw on purpose: `.catch(undefined)` would turn a mistyped `enabled` into "inherit",
@@ -767,6 +771,26 @@ export const configSchema = z.object({
767
771
  message: reasoningSummaryDeliveryError,
768
772
  });
769
773
  }
774
+ const thinkingDisplayError = thinkingDisplayConfigError(
775
+ (provider as { thinkingDisplay?: unknown }).thinkingDisplay,
776
+ );
777
+ if (thinkingDisplayError) {
778
+ ctx.addIssue({
779
+ code: "custom",
780
+ path: ["providers", redactSecretString(name), "thinkingDisplay"],
781
+ message: thinkingDisplayError,
782
+ });
783
+ }
784
+ const modelThinkingDisplayError = modelThinkingDisplayConfigError(
785
+ (provider as { modelThinkingDisplay?: unknown }).modelThinkingDisplay,
786
+ );
787
+ if (modelThinkingDisplayError) {
788
+ ctx.addIssue({
789
+ code: "custom",
790
+ path: ["providers", redactSecretString(name), "modelThinkingDisplay"],
791
+ message: modelThinkingDisplayError,
792
+ });
793
+ }
770
794
  const minMaxOutputError = positiveIntegerConfigError(
771
795
  (provider as { minMaxOutputTokens?: unknown }).minMaxOutputTokens,
772
796
  "minMaxOutputTokens",
@@ -29,6 +29,7 @@ import {
29
29
  MODEL_ADAPTER_OVERRIDE_ALLOWED,
30
30
  pinnedWireAdapter,
31
31
  PROVIDER_WEB_SEARCH_BRIDGE_BACKENDS,
32
+ THINKING_DISPLAY_VALUES,
32
33
  UPSTREAM_HTTP_VERSION_VALUES,
33
34
  type OcxProviderConfig,
34
35
  type OcxConfig,
@@ -360,12 +361,17 @@ export const providerConfigSchema = z.object({
360
361
  inferContextWindow: z.boolean().optional(),
361
362
  modelSupportsServiceTier: z.record(z.string().min(1), z.boolean()).optional(),
362
363
  modelSuppressSyntheticMax: z.record(z.string().min(1), z.boolean()).optional(),
364
+ // Validated against a closed vocabulary here as well as at the write boundaries, so a
365
+ // hand-edited typo cannot load silently and leave the operator with the built-in display (#8363).
366
+ thinkingDisplay: z.enum(THINKING_DISPLAY_VALUES).optional(),
367
+ modelThinkingDisplay: z.record(z.string().min(1), z.enum(THINKING_DISPLAY_VALUES)).optional(),
363
368
  promoteAdditionalTools: z.boolean().optional(),
364
369
  preserveResponsesReasoningContent: z.boolean().optional(),
365
370
  preserveResponsesInputItemIds: z.boolean().optional(),
366
371
  preserveResponsesMessageMetadata: z.boolean().optional(),
367
372
  projectResponsesLiteHostedSearchHistory: z.boolean().optional(),
368
373
  dropResponsesReasoningItems: z.boolean().optional(),
374
+ arkKimiResponsesModels: z.array(z.string().min(1)).optional(),
369
375
  modelReasoningEffortsAuthoritative: z.boolean().optional(),
370
376
  decodesNativeCompactionBlobs: z.boolean().optional(),
371
377
  supportsNativeCompactionTrigger: z.boolean().optional(),
@@ -1189,3 +1195,14 @@ export const spendSchema = z.object({
1189
1195
  export const skillsConfigSchema = z.object({
1190
1196
  catalog_refresh: z.enum(["per_session", "per_turn"]).optional(),
1191
1197
  }).strict();
1198
+
1199
+ /**
1200
+ * Anonymous telemetry consent state.
1201
+ *
1202
+ * No endpoint is accepted here: the collector URL is a constant in src/telemetry/sender.ts.
1203
+ */
1204
+ export const telemetryConfigSchema = z.object({
1205
+ decision: z.enum(["accepted", "declined"]).optional(),
1206
+ decidedAt: clientTimestampSchema.optional(),
1207
+ noticeShownAt: clientTimestampSchema.optional(),
1208
+ }).strict();