@bitkyc08/opencodex 2.100.3 → 2.100.5-preview.20261118.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 (249) hide show
  1. package/AGENTS_INSTALL.md +23 -1
  2. package/bin/ocx.mjs +8 -1
  3. package/gui/dist/assets/{App-Dnb6VMsP.js → App-BiOGtxDS.js} +21 -20
  4. package/gui/dist/assets/{Tray-BV4ms9U9.js → Tray-BwsMejUO.js} +1 -1
  5. package/gui/dist/assets/brand-mark-BY1dgACL.js +1 -0
  6. package/gui/dist/assets/{index-DCdXsMyZ.js → index-CwHSKMdG.js} +46 -13
  7. package/gui/dist/assets/index-DJxM-imn.css +2 -0
  8. package/gui/dist/assets/{segment-thumb-features-DXSidY6D.js → segment-thumb-features-Bds9Hb_7.js} +1 -1
  9. package/gui/dist/classic/assets/{App-DA-scMPq.js → App-CGLOiqQL.js} +20 -19
  10. package/gui/dist/classic/assets/{Tray-BrHaVRAq.js → Tray-Da4r2O70.js} +1 -1
  11. package/gui/dist/classic/assets/{index-BqOaGLf5.js → index-CvoKXKL9.js} +46 -13
  12. package/gui/dist/classic/assets/quota-summary-DvqzfCmr.js +1 -0
  13. package/gui/dist/classic/index.html +1 -1
  14. package/gui/dist/index.html +2 -2
  15. package/native/ocx-child/src/cli.rs +5 -3
  16. package/native/ocx-child/src/codex_home.rs +1 -0
  17. package/native/ocx-child/src/link_ws.rs +24 -19
  18. package/native/ocx-child/src/link_ws_frame.rs +136 -50
  19. package/package.json +3 -3
  20. package/src/adapters/anthropic/per-message-effort.ts +296 -0
  21. package/src/adapters/anthropic-input-schema.ts +270 -0
  22. package/src/adapters/anthropic.ts +4 -63
  23. package/src/adapters/claude-cli/adapter.ts +1 -0
  24. package/src/adapters/command-code-tool-text.ts +9 -1
  25. package/src/adapters/command-code.ts +18 -2
  26. package/src/adapters/devin/cloud-direct/chat.ts +95 -14
  27. package/src/adapters/devin/live-models.ts +11 -1
  28. package/src/adapters/google-errors.ts +14 -2
  29. package/src/adapters/kiro/reasoning.ts +3 -0
  30. package/src/adapters/kiro-tools.ts +14 -9
  31. package/src/adapters/openai-responses/passthrough.ts +3 -1
  32. package/src/adapters/openai-responses/request-strips.ts +1 -0
  33. package/src/adapters/qoder/adapter.ts +9 -1
  34. package/src/adapters/tool-catalog-nudge.ts +1 -1
  35. package/src/adapters/zed.ts +4 -2
  36. package/src/claude/chat-tool-dispatch.ts +4 -1
  37. package/src/claude/desktop-remote-store.ts +60 -10
  38. package/src/cli/account-api.ts +4 -0
  39. package/src/cli/account-auth.ts +30 -2
  40. package/src/cli/account-extended.ts +33 -2
  41. package/src/cli/capabilities-access-remote.ts +3 -3
  42. package/src/cli/capabilities-accounts.ts +3 -3
  43. package/src/cli/capabilities-base.ts +11 -6
  44. package/src/cli/capabilities-observe-system.ts +2 -2
  45. package/src/cli/claude.ts +3 -3
  46. package/src/cli/disconnect-runtime.ts +16 -6
  47. package/src/cli/dispatch.ts +7 -1
  48. package/src/cli/index.ts +2 -2
  49. package/src/cli/link-apply-restart.ts +4 -2
  50. package/src/cli/link-routes.ts +4 -1
  51. package/src/cli/link.ts +5 -4
  52. package/src/cli/logout-command.ts +23 -4
  53. package/src/cli/preflight-exemptions.ts +3 -0
  54. package/src/cli/provider.ts +3 -2
  55. package/src/cli/registry.ts +5 -2
  56. package/src/cli/resolve.ts +23 -8
  57. package/src/cli/restart-failure.ts +11 -1
  58. package/src/cli/runtime-api.ts +4 -0
  59. package/src/cli/status.ts +4 -1
  60. package/src/cli/system-command.ts +1 -1
  61. package/src/cli/system-restart-client.ts +9 -3
  62. package/src/cli/system-settings-parity.ts +2 -1
  63. package/src/client/connect.ts +73 -11
  64. package/src/client/desktop-refusal.ts +38 -0
  65. package/src/client/lifecycle-lock.ts +29 -4
  66. package/src/client/runtime-restart.ts +27 -15
  67. package/src/client/runtime.ts +4 -2
  68. package/src/client/state.ts +14 -0
  69. package/src/clients/config-export.ts +12 -7
  70. package/src/codex/account-lifecycle.ts +3 -1
  71. package/src/codex/account-pause.ts +4 -0
  72. package/src/codex/account-runtime-state.ts +4 -0
  73. package/src/codex/auth-api/main-account-probe.ts +3 -1
  74. package/src/codex/auth-api/main-hard-lock-refusal-read.ts +172 -0
  75. package/src/codex/auth-context.ts +40 -2
  76. package/src/codex/catalog/build-entries.ts +10 -0
  77. package/src/codex/catalog/derive-entry.ts +7 -0
  78. package/src/codex/catalog/metadata.ts +8 -0
  79. package/src/codex/catalog/native-models.ts +16 -6
  80. package/src/codex/catalog/pinned-models.ts +1 -0
  81. package/src/codex/catalog/provider-models.ts +5 -5
  82. package/src/codex/catalog/reserve-warn.ts +7 -5
  83. package/src/codex/catalog/reserve.ts +4 -3
  84. package/src/codex/catalog/retained-sync.ts +2 -0
  85. package/src/codex/catalog/routed-defaults.ts +35 -0
  86. package/src/codex/catalog-auto-refresh.ts +13 -2
  87. package/src/codex/config-drift-heal.ts +40 -12
  88. package/src/codex/config-write-lock.ts +39 -1
  89. package/src/codex/convergence.ts +2 -0
  90. package/src/codex/data/roster-pinned-models.json +346 -1
  91. package/src/codex/inject/config-write-section.ts +39 -1
  92. package/src/codex/inject/plan.ts +10 -8
  93. package/src/codex/inject/remove.ts +21 -19
  94. package/src/codex/inject/restore.ts +5 -1
  95. package/src/codex/inject-coordination.ts +58 -7
  96. package/src/codex/inject.ts +10 -12
  97. package/src/codex/journal-config-restore.ts +42 -0
  98. package/src/codex/journal.ts +62 -8
  99. package/src/codex/loopback-target.ts +22 -8
  100. package/src/codex/main-account.ts +94 -30
  101. package/src/codex/native-main-auth-file.ts +14 -0
  102. package/src/codex/native-main-credentials.ts +276 -0
  103. package/src/codex/native-main-owner.ts +3 -0
  104. package/src/codex/native-main-refresh-mode.ts +14 -1
  105. package/src/codex/quota.ts +63 -14
  106. package/src/combos/failover.ts +195 -1
  107. package/src/combos/index.ts +5 -0
  108. package/src/combos/resolve.ts +115 -19
  109. package/src/config/diagnostics.ts +3 -0
  110. package/src/config/live-reconcile.ts +6 -3
  111. package/src/config/load-degrade.ts +2 -0
  112. package/src/config/persisted-mutation.ts +2 -2
  113. package/src/config/persisted-projections.ts +18 -0
  114. package/src/config/process-state.ts +4 -3
  115. package/src/config/reserve-capability.ts +96 -0
  116. package/src/config/schema/config-schema.ts +6 -0
  117. package/src/config/schema/leaf-validators.ts +2 -0
  118. package/src/config/schema/routed-catalog-defaults.ts +49 -0
  119. package/src/config/subagent-models.ts +20 -12
  120. package/src/config.ts +7 -7
  121. package/src/desktop-update/acquire.ts +202 -0
  122. package/src/desktop-update/cli.ts +168 -0
  123. package/src/desktop-update/drain.ts +40 -0
  124. package/src/desktop-update/headless.ts +285 -0
  125. package/src/desktop-update/image.ts +85 -0
  126. package/src/desktop-update/install.ts +53 -0
  127. package/src/desktop-update/msi.ts +72 -0
  128. package/src/desktop-update/release.ts +128 -0
  129. package/src/desktop-update/runtime.ts +155 -0
  130. package/src/desktop-update/staging.ts +118 -0
  131. package/src/desktop-update/trust.ts +45 -0
  132. package/src/generated/compatibility-version.json +327 -195
  133. package/src/generated/model-metadata.ts +3 -3
  134. package/src/images/fulfill-video.ts +3 -3
  135. package/src/images/loop.ts +6 -2
  136. package/src/images/plan.ts +147 -11
  137. package/src/images/types.ts +13 -4
  138. package/src/images/xai-video-client.ts +72 -10
  139. package/src/lib/client-error-body.ts +6 -0
  140. package/src/lib/developer-role-rejection.ts +15 -0
  141. package/src/lib/gcp-adc.ts +48 -4
  142. package/src/lib/offline-resend.ts +150 -0
  143. package/src/lib/paced-stream.ts +3 -3
  144. package/src/lib/provider-outbound.ts +17 -6
  145. package/src/lib/request-failure-model.ts +2 -0
  146. package/src/lib/response-body-inactivity.ts +23 -1
  147. package/src/lib/upstream-retry.ts +39 -6
  148. package/src/link/explicit-route.ts +4 -4
  149. package/src/link/remote-windows.ts +79 -31
  150. package/src/link/residual-recovery.ts +20 -8
  151. package/src/messaging/budget.ts +23 -5
  152. package/src/messaging/remote-ports.ts +22 -10
  153. package/src/messaging/rpc.ts +4 -4
  154. package/src/oauth/antigravity-risk.ts +126 -0
  155. package/src/oauth/credential-siblings.ts +32 -0
  156. package/src/oauth/generic-account-failover.ts +113 -30
  157. package/src/oauth/generic-session-affinity.ts +10 -3
  158. package/src/oauth/index.ts +22 -14
  159. package/src/oauth/login-cli.ts +35 -1
  160. package/src/oauth/pool-kernel.ts +3 -3
  161. package/src/oauth/store.ts +38 -7
  162. package/src/providers/anthropic-billing-refusal.ts +27 -3
  163. package/src/providers/anthropic-reset-grants.ts +4 -0
  164. package/src/providers/claude-cli-usage.ts +2 -0
  165. package/src/providers/codebuddy-models.ts +11 -0
  166. package/src/providers/google-vertex-model-discovery.ts +49 -15
  167. package/src/providers/kiro-models.ts +5 -0
  168. package/src/providers/model-rename-fields.ts +2 -0
  169. package/src/providers/quota/workbuddy.ts +6 -2
  170. package/src/providers/registry/entries-core.ts +9 -3
  171. package/src/providers/registry/entries-extended.ts +20 -9
  172. package/src/providers/registry/model-seeds.ts +4 -1
  173. package/src/providers/stale-context-window-migration.ts +2 -0
  174. package/src/providers/workbuddy-credit-balance.ts +125 -16
  175. package/src/responses/citation-markers.ts +26 -23
  176. package/src/responses/effort-history.ts +732 -0
  177. package/src/routing/history/integrity.ts +41 -4
  178. package/src/server/auth-cors.ts +13 -3
  179. package/src/server/codex-model-list.ts +2 -1
  180. package/src/server/direct-local-http.ts +26 -3
  181. package/src/server/index/link-listener.ts +20 -14
  182. package/src/server/index/serve-options.ts +1 -0
  183. package/src/server/index.ts +3 -2
  184. package/src/server/link-turn.ts +17 -5
  185. package/src/server/management/config-routes.ts +39 -3
  186. package/src/server/management/link-child-preflight.ts +1 -1
  187. package/src/server/management/link-enrollment.ts +3 -3
  188. package/src/server/management/link-route-edit.ts +20 -1
  189. package/src/server/management/link-route-request.ts +11 -5
  190. package/src/server/management/oauth-account-routes.ts +43 -13
  191. package/src/server/management/provider-credential-release.ts +44 -0
  192. package/src/server/management/provider-overwrite-carry.ts +3 -0
  193. package/src/server/management/provider-routes.ts +12 -12
  194. package/src/server/management/static-catalog-probe.ts +33 -0
  195. package/src/server/management/usage-aggregate-cache.ts +6 -3
  196. package/src/server/messages-native.ts +16 -2
  197. package/src/server/proxy-liveness.ts +54 -9
  198. package/src/server/relay.ts +6 -1
  199. package/src/server/request-log-conversation.ts +8 -4
  200. package/src/server/request-log-failure-detail.ts +26 -9
  201. package/src/server/request-log.ts +5 -1
  202. package/src/server/reserve-capability-startup.ts +32 -0
  203. package/src/server/responses/adapter-continuation.ts +59 -25
  204. package/src/server/responses/adapter-delivery.ts +2 -0
  205. package/src/server/responses/adapter-dispatch.ts +39 -18
  206. package/src/server/responses/antigravity-fault-rotation.ts +24 -0
  207. package/src/server/responses/antigravity-validation-refusal.ts +43 -6
  208. package/src/server/responses/codex-tool-catalog.ts +47 -10
  209. package/src/server/responses/combo-selection-keepalive.ts +254 -0
  210. package/src/server/responses/combo-session-recall.ts +26 -1
  211. package/src/server/responses/combo-stream-preflight.ts +35 -26
  212. package/src/server/responses/core-combo-failure.ts +6 -0
  213. package/src/server/responses/core-combo-native.ts +2 -1
  214. package/src/server/responses/core-combo.ts +67 -28
  215. package/src/server/responses/core-errors.ts +9 -6
  216. package/src/server/responses/core-options.ts +10 -0
  217. package/src/server/responses/core.ts +21 -0
  218. package/src/server/responses/estimated-usage.ts +115 -0
  219. package/src/server/responses/input-admission.ts +41 -3
  220. package/src/server/responses/jev-model-invoke.ts +7 -2
  221. package/src/server/responses/passthrough-completion.ts +6 -3
  222. package/src/server/responses/passthrough-delivery.ts +47 -8
  223. package/src/server/responses/passthrough-dispatch.ts +3 -0
  224. package/src/server/responses/request-prepare.ts +9 -5
  225. package/src/server/responses/request-send-budget.ts +1 -1
  226. package/src/server/responses/request-transport.ts +10 -2
  227. package/src/server/responses/sidecar-execution.ts +11 -4
  228. package/src/service/desktop-supervision.d.mts +2 -0
  229. package/src/service/desktop-supervision.mjs +5 -0
  230. package/src/service/windows-checked-stop-live.ts +28 -5
  231. package/src/stall-timeout.ts +11 -0
  232. package/src/types/config.ts +15 -92
  233. package/src/types/provider.ts +13 -0
  234. package/src/types/request.ts +23 -3
  235. package/src/types/routed-catalog-defaults.ts +17 -0
  236. package/src/types/routing-profile.ts +90 -0
  237. package/src/types.ts +1 -0
  238. package/src/update/index.ts +1 -1
  239. package/src/usage/expected-prices.ts +35 -0
  240. package/src/usage/ledger-scanner.ts +44 -10
  241. package/src/usage/log.ts +14 -4
  242. package/src/usage/telemetry-contract.ts +1 -0
  243. package/src/web-search/loop.ts +20 -2
  244. package/src/web-search/parse.ts +2 -12
  245. package/src/web-search/passthrough-bridge.ts +7 -0
  246. package/src/web-search/sources.ts +13 -0
  247. package/gui/dist/assets/brand-mark-XOLJbomA.js +0 -1
  248. package/gui/dist/assets/index-DQtCRNAw.css +0 -2
  249. package/gui/dist/classic/assets/quota-summary-Dy5_wfTT.js +0 -1
@@ -1,5 +1,5 @@
1
1
  import type { OcxConfig } from "../../types";
2
- import { isEffectiveCodexDesktopAuthless } from "../loopback-target";
2
+ import { isEffectiveCodexReserve } from "../loopback-target";
3
3
  import { NATIVE_RESERVE_MODEL } from "./native-models";
4
4
 
5
5
  /**
@@ -14,9 +14,9 @@ import { NATIVE_RESERVE_MODEL } from "./native-models";
14
14
  * inputs that produced the omission are still in scope.
15
15
  *
16
16
  * Deliberately scoped to an operator who asked for the feature. A default install has
17
- * `codexDesktopAuthless` unset, wants no Reserve row, and must not be told about one. An install
18
- * that stores the flag on a bind where it cannot take effect is a different silence, already
19
- * reported as `inertReason` by `describeCodexDesktopSwitches`, and is not repeated here.
17
+ * `codexReserveEnabled` off, wants no Reserve row, and must not be told about one. An install
18
+ * that enables Reserve on a bind where it cannot take effect is a different silence and is not
19
+ * repeated here.
20
20
  */
21
21
  export type ReserveCatalogSuppressionReason =
22
22
  | "no-canonical-openai-provider"
@@ -30,6 +30,8 @@ type ReserveSuppressionConfig = Pick<
30
30
  | "hostname"
31
31
  | "unauthenticatedLoopbackListener"
32
32
  | "codexDesktopAuthless"
33
+ | "codexReserveEnabled"
34
+ | "codexReserveMigration"
33
35
  | "codexAccountNamespaces"
34
36
  | "codexAccountPickerEnabled"
35
37
  >;
@@ -45,7 +47,7 @@ export function reserveCatalogSuppressionReason(
45
47
  config: ReserveSuppressionConfig,
46
48
  input: ReserveSuppressionInput,
47
49
  ): ReserveCatalogSuppressionReason | undefined {
48
- if (!isEffectiveCodexDesktopAuthless(config) || input.mainSelectors.length > 0) return undefined;
50
+ if (!isEffectiveCodexReserve(config) || input.mainSelectors.length > 0) return undefined;
49
51
  if (!input.includeAccountBoundNativeOpenAi) return "no-canonical-openai-provider";
50
52
  // Checked before the empty-map case: when an operator has explicitly turned the picker off,
51
53
  // naming the empty map would send them to hand-author selectors that the opt-in generates.
@@ -1,5 +1,5 @@
1
1
  import type { OcxConfig } from "../../types";
2
- import { isEffectiveCodexDesktopAuthless } from "../loopback-target";
2
+ import { isEffectiveCodexReserve } from "../loopback-target";
3
3
  import { CODEX_ACCOUNT_BOUND_CATALOG_KIND } from "./account-models";
4
4
  import { NATIVE_RESERVE_MODEL } from "./native-models";
5
5
  import type { RawEntry } from "./parsing";
@@ -17,12 +17,13 @@ export interface ReserveCatalogProjection {
17
17
 
18
18
  /** The caller supplies a validated actual observation and an already context-capped Luna pin. */
19
19
  export function createReserveCatalogProjection(
20
- config: Pick<OcxConfig, "runtimeRole" | "hostname" | "unauthenticatedLoopbackListener" | "codexDesktopAuthless">,
20
+ config: Pick<OcxConfig, "runtimeRole" | "hostname" | "unauthenticatedLoopbackListener" | "codexDesktopAuthless"
21
+ | "codexReserveEnabled" | "codexReserveMigration">,
21
22
  mainSelectors: readonly string[],
22
23
  observedSource: RawEntry | null,
23
24
  lunaSource: RawEntry | null,
24
25
  ): ReserveCatalogProjection | undefined {
25
- if (!isEffectiveCodexDesktopAuthless(config) || mainSelectors.length === 0) return undefined;
26
+ if (!isEffectiveCodexReserve(config) || mainSelectors.length === 0) return undefined;
26
27
  const original = observedSource ?? lunaSource;
27
28
  if (!original) return undefined;
28
29
  const source = structuredClone(original);
@@ -5,6 +5,7 @@ import { join } from "node:path";
5
5
  import { initializeConfigOwnership } from "../../lib/config-ownership";
6
6
  import { getConfigDir, loadConfig, ultraFastTierEnabled, websocketsEnabled, withConfigMutationLockSync } from "../../config";
7
7
  import { resolveMultiAgentMode } from "../../config/multi-agent-surface";
8
+ import { resolveRoutedCatalogDefaults } from "../../config/schema/routed-catalog-defaults";
8
9
  import { shouldSyncCodexOnStart } from "../desired-state";
9
10
  import { legacyCustomModelCatalogSlugs } from "../custom-model-catalog-migration";
10
11
  import { getCodexHome } from "../paths";
@@ -466,6 +467,7 @@ function writeRetainedCatalogSync({
466
467
  disabledNativeAccountSlugs: new Set(),
467
468
  multiAgentV2Enabled,
468
469
  openaiContextCap,
470
+ routedCatalogDefaults: resolveRoutedCatalogDefaults(config),
469
471
  });
470
472
  // Keep genuine native entries (gpt-*, codex-*) with their real per-model fields and append
471
473
  // routed providers as namespaced slugs. Cursor and other adopted providers can expose model ids
@@ -0,0 +1,35 @@
1
+ import type { RoutedCatalogDefaults } from "../../config/schema/routed-catalog-defaults";
2
+ import type { RawEntry } from "./parsing";
3
+
4
+ /**
5
+ * Project operator `routedCatalogDefaults` (#6872) onto a freshly derived routed row.
6
+ *
7
+ * `deriveEntry` calls this after the inherited template has been normalized for routing and
8
+ * before provider/model metadata is applied, which fixes the precedence: concrete provider/model
9
+ * declarations > these defaults > template values > strict-field fallbacks. The final
10
+ * `ensureStrictCatalogFields` pass still removes `default_verbosity` from a row whose
11
+ * `support_verbosity` ended up false, so a model without verbosity support never advertises an
12
+ * operator default. Verbosity support itself is never set here: it stays the provider's,
13
+ * model's or template's own declaration.
14
+ *
15
+ * Only the four allowlisted serialized fields are written. Values of any other type are ignored,
16
+ * so a caller that bypassed config validation cannot smuggle other row fields through here.
17
+ */
18
+ export function applyRoutedCatalogDefaults(
19
+ entry: RawEntry,
20
+ defaults: Readonly<RoutedCatalogDefaults> | undefined,
21
+ ): void {
22
+ if (!defaults) return;
23
+ if (typeof defaults.includeSkillsUsageInstructions === "boolean") {
24
+ entry.include_skills_usage_instructions = defaults.includeSkillsUsageInstructions;
25
+ }
26
+ if (typeof defaults.includeAppsUsageInstructions === "boolean") {
27
+ entry.include_apps_usage_instructions = defaults.includeAppsUsageInstructions;
28
+ }
29
+ if (typeof defaults.includePluginUsageInstructions === "boolean") {
30
+ entry.include_plugin_usage_instructions = defaults.includePluginUsageInstructions;
31
+ }
32
+ if (defaults.defaultVerbosity === "low" || defaults.defaultVerbosity === "medium" || defaults.defaultVerbosity === "high") {
33
+ entry.default_verbosity = defaults.defaultVerbosity;
34
+ }
35
+ }
@@ -47,6 +47,9 @@ let liveIntervalMs: number | null = null;
47
47
  * so a converge still in flight when the timer stops cannot publish into the next generation.
48
48
  */
49
49
  let generation = 0;
50
+ /** Keys the last drift heal found missing, and whether this process already warned about one. */
51
+ let lastHealMissingKeys: readonly string[] = [];
52
+ let healReported = false;
50
53
  /** setInterval does not skip a firing while the previous callback is still awaiting. */
51
54
  let inFlight = false;
52
55
 
@@ -134,7 +137,7 @@ export function selectDriftHealCatalogPath(
134
137
 
135
138
  /** Repair only the missing config roots; catalog convergence remains the later tick step. */
136
139
  async function healCodexConfigDrift(config: OcxConfig, entryGeneration: number): Promise<"none" | "healed" | "not-healed"> {
137
- const [{ codexConfigDrift }, { JOURNAL_PATH, journaledInjectedOpenaiBaseUrl, journaledInjectedRealtimeWsBaseUrl }, { shouldSyncCodexOnStart }, { injectCodexConfig }, { DEFAULT_CATALOG_PATH, resolveCodexConfigPath }, { loadConfig }, { inspectNativeCodexOwnership }] =
140
+ const [{ codexConfigDrift }, { JOURNAL_PATH, journaledInjectedCatalogPath, journaledInjectedOpenaiBaseUrl, journaledInjectedRealtimeWsBaseUrl, journaledInjectedRootValues }, { shouldSyncCodexOnStart }, { injectCodexConfig }, { DEFAULT_CATALOG_PATH, resolveCodexConfigPath }, { loadConfig }, { inspectNativeCodexOwnership }] =
138
141
  await Promise.all([
139
142
  import("./config-drift-heal"),
140
143
  import("./journal"),
@@ -151,9 +154,15 @@ async function healCodexConfigDrift(config: OcxConfig, entryGeneration: number):
151
154
  const journaled = {
152
155
  injectedOpenaiBaseUrl: journaledInjectedOpenaiBaseUrl({ readOnly: true }),
153
156
  injectedRealtimeWsBaseUrl: journaledInjectedRealtimeWsBaseUrl({ readOnly: true }),
157
+ injectedCatalogPath: journaledInjectedCatalogPath(),
158
+ injectedRootValues: {
159
+ openai_base_url: journaledInjectedRootValues("openai_base_url", { readOnly: true }),
160
+ experimental_realtime_ws_base_url: journaledInjectedRootValues("experimental_realtime_ws_base_url", { readOnly: true }),
161
+ },
154
162
  };
155
163
  const drift = codexConfigDrift(() => journaled);
156
164
  if (!drift.drifted) return "none";
165
+ lastHealMissingKeys = drift.missingKeys;
157
166
  const { readRuntimePort } = await import("../config/process-state");
158
167
  if (!current()) return "none";
159
168
  const runtime = readRuntimePort(process.pid);
@@ -243,7 +252,9 @@ async function tick(): Promise<void> {
243
252
  const heal = await healCodexConfigDrift(config, entryGeneration);
244
253
  if (entryGeneration !== generation) return;
245
254
  if (heal === "healed") {
246
- console.info("[catalog-auto-refresh] injected Codex config keys were rewritten externally; re-injected");
255
+ const { codexConfigHealNotice } = await import("./config-drift-heal");
256
+ console.info(codexConfigHealNotice(lastHealMissingKeys, !healReported));
257
+ healReported = true;
247
258
  } else if (heal === "not-healed") {
248
259
  console.info("[catalog-auto-refresh] injected Codex config keys were rewritten externally; not re-injected this tick");
249
260
  }
@@ -23,10 +23,7 @@
23
23
 
24
24
  import { existsSync, readFileSync } from "node:fs";
25
25
  import { CODEX_CONFIG_PATH } from "./paths";
26
- import {
27
- REALTIME_WS_BASE_URL_KEY,
28
- rootTomlString,
29
- } from "./injected-marker";
26
+ import { REALTIME_WS_BASE_URL_KEY } from "./injected-marker";
30
27
 
31
28
  export interface CodexConfigDrift {
32
29
  /**
@@ -48,8 +45,17 @@ export interface CodexConfigDrift {
48
45
  * `keptUserBaseUrl`, and re-journaled as null) own that case, so a heal triggered on a
49
46
  * missing key runs into them and stops on its own rather than stomping a user's routing.
50
47
  */
48
+ export interface JournaledCodexConfigKeys {
49
+ injectedOpenaiBaseUrl?: string | null;
50
+ injectedRealtimeWsBaseUrl?: string | null;
51
+ /** The catalog path the last injection wrote; its root key going missing is drift too. */
52
+ injectedCatalogPath?: string | null;
53
+ /** Every URL injections under this journal wrote per root key, so a write-back of an older one is drift. */
54
+ injectedRootValues?: Partial<Record<"openai_base_url" | typeof REALTIME_WS_BASE_URL_KEY, readonly string[]>>;
55
+ }
56
+
51
57
  export function codexConfigDrift(
52
- readJournal: () => { injectedOpenaiBaseUrl?: string | null; injectedRealtimeWsBaseUrl?: string | null } | null,
58
+ readJournal: () => JournaledCodexConfigKeys | null,
53
59
  configPath: string = CODEX_CONFIG_PATH,
54
60
  readFile: (path: string) => string = path => readFileSync(path, "utf-8"),
55
61
  fileExists: (path: string) => boolean = existsSync,
@@ -57,7 +63,8 @@ export function codexConfigDrift(
57
63
  const journal = readJournal();
58
64
  const journaledBaseUrl = journal?.injectedOpenaiBaseUrl;
59
65
  const journaledRealtimeWsUrl = journal?.injectedRealtimeWsBaseUrl;
60
- if (!journaledBaseUrl && !journaledRealtimeWsUrl) {
66
+ const journaledCatalogPath = journal?.injectedCatalogPath;
67
+ if (!journaledBaseUrl && !journaledRealtimeWsUrl && !journaledCatalogPath) {
61
68
  return { drifted: false, missingKeys: [] };
62
69
  }
63
70
  if (!fileExists(configPath)) {
@@ -69,12 +76,33 @@ export function codexConfigDrift(
69
76
  } catch {
70
77
  return { drifted: false, missingKeys: [] };
71
78
  }
79
+ // Presence comes from the parsed document, so a multiline assignment counts as present. A file
80
+ // that does not parse is present-unknown: nothing is reported missing and no heal is started.
81
+ let root: Record<string, unknown>;
82
+ try { root = Bun.TOML.parse(content.replace(/^\uFEFF/, "")) as Record<string, unknown>; }
83
+ catch { return { drifted: false, missingKeys: [] }; }
72
84
  const missingKeys: string[] = [];
73
- if (journaledBaseUrl && rootTomlString(content, "openai_base_url") === null) {
74
- missingKeys.push("openai_base_url");
75
- }
76
- if (journaledRealtimeWsUrl && rootTomlString(content, REALTIME_WS_BASE_URL_KEY) === null) {
77
- missingKeys.push(REALTIME_WS_BASE_URL_KEY);
78
- }
85
+ // Missing, or rewritten back to a value an EARLIER injection wrote (the Codex app restoring its
86
+ // own older copy). Another value is the user's and stays out of this check.
87
+ const drifted = (key: "openai_base_url" | typeof REALTIME_WS_BASE_URL_KEY, latest: string) => {
88
+ if (!Object.hasOwn(root, key)) return true;
89
+ const value = root[key];
90
+ return typeof value === "string" && value !== latest && (journal?.injectedRootValues?.[key] ?? []).includes(value);
91
+ };
92
+ if (journaledBaseUrl && drifted("openai_base_url", journaledBaseUrl)) missingKeys.push("openai_base_url");
93
+ if (journaledRealtimeWsUrl && drifted(REALTIME_WS_BASE_URL_KEY, journaledRealtimeWsUrl)) missingKeys.push(REALTIME_WS_BASE_URL_KEY);
94
+ if (journaledCatalogPath && !Object.hasOwn(root, "model_catalog_json")) missingKeys.push("model_catalog_json");
79
95
  return { drifted: missingKeys.length > 0, missingKeys };
80
96
  }
97
+
98
+ /**
99
+ * What to print after a heal. The first heal in a process says what happened and what was kept;
100
+ * later ones are one quiet line, so an app that keeps rewriting the file is explained once instead
101
+ * of on every tick.
102
+ */
103
+ export function codexConfigHealNotice(missingKeys: readonly string[], firstReport: boolean): string {
104
+ if (!firstReport) return "[catalog-auto-refresh] injected Codex config keys were rewritten externally; re-injected";
105
+ return "[catalog-auto-refresh] Codex rewrote config.toml without OpenCodex's " + missingKeys.join(", ")
106
+ + "; re-injected only those keys and other settings were kept. If this repeats, the Codex app is"
107
+ + " rewriting config.toml from its own copy; run 'ocx sync' once it settles.";
108
+ }
@@ -41,7 +41,7 @@
41
41
  */
42
42
  import { atomicWriteFileStreamed, type AtomicWriteHooks } from "../config/atomic-write";
43
43
  import { lstatSync, readFileSync, realpathSync, statSync, unlinkSync, writeFileSync } from "node:fs";
44
- import { randomUUID } from "node:crypto";
44
+ import { createHash, randomUUID } from "node:crypto";
45
45
  import { basename, dirname, join, resolve } from "node:path";
46
46
  import { release, stillHeld, tryAcquire, type AcquireResult, type LockHandle } from "./prompt-lock";
47
47
 
@@ -146,16 +146,52 @@ export function publishConfigWrite<T>(configPath: string, held: LockHandle, run:
146
146
  return run(canonical, {
147
147
  validateBeforeRename: () => { assertConfigWriteDestination(configPath, held); },
148
148
  afterRename: () => {
149
+ const payloadKnown = payloadDigestPending.delete(held);
149
150
  const recovery = recoveries.get(held);
150
151
  if (recovery?.canonical === canonical) recovery.identity = canonicalFileIdentity(canonical);
151
152
  const after = destination(configPath);
152
153
  if (!stillHeld(held) || after.canonical !== canonical) throw new Error("Codex configuration destination changed; recovery evidence was preserved.");
153
154
  destinations.set(held, after);
155
+ // A payload-aware publisher records the digest of what it wrote; this re-read only
156
+ // covers writers whose bytes this process never sees (a native child, the empty file).
157
+ // Known limit for a native child: the `codex` CLI renames its own file and exits, and this
158
+ // re-read runs after it exits, so a write by a non-OpenCodex process (the Codex app, an
159
+ // editor) landing between the child's rename and this line is recorded as OpenCodex's and a
160
+ // later compensation in the same section could revert it. The child cannot report its bytes.
161
+ if (!payloadKnown) publishedConfigDigests.set(held, fileDigest(canonical));
154
162
  const watched = targets.get(held);
155
163
  if (watched) for (const [path, expected] of watched) if (expected.canonical === canonical) watched.set(path, after);
156
164
  },
157
165
  });
158
166
  }
167
+ /** config.toml no longer holds the bytes a writer decided from; nothing was written. */
168
+ export class ConfigWriteContentChanged extends Error {
169
+ readonly retryable = true;
170
+ constructor() {
171
+ super("Codex config.toml changed while OpenCodex was writing it; nothing was overwritten. Retry the command.");
172
+ }
173
+ }
174
+ /**
175
+ * The digest of the config.toml bytes this lock section last published, `null` for a removal,
176
+ * `undefined` when it published none. Compensation reverts only a file still holding them.
177
+ */
178
+ const publishedConfigDigests = new WeakMap<LockHandle, string | null>();
179
+ const payloadDigestPending = new WeakSet<LockHandle>();
180
+ export function publishedConfigDigest(held: LockHandle): string | null | undefined {
181
+ return publishedConfigDigests.get(held);
182
+ }
183
+ /** Called by a publisher that knows its payload, before the rename's afterRename hook runs. */
184
+ export function recordPublishedConfigDigest(held: LockHandle, digest: string | null): void {
185
+ publishedConfigDigests.set(held, digest);
186
+ payloadDigestPending.add(held);
187
+ }
188
+ export function configDigest(bytes: string | null): string | null {
189
+ return bytes === null ? null : createHash("sha256").update(bytes).digest("hex");
190
+ }
191
+ function fileDigest(path: string): string | null {
192
+ try { return createHash("sha256").update(readFileSync(path)).digest("hex"); }
193
+ catch (error) { if ((error as NodeJS.ErrnoException).code === "ENOENT") return null; throw error; }
194
+ }
159
195
  /** Native children use the acquisition witness, never a fresh home resolution. */
160
196
  export class ConfigWriteDestinationChanged extends Error {
161
197
  readonly retryable = false;
@@ -212,6 +248,8 @@ export function withConfigWriteRecovery<T>(
212
248
  assertConfigWriteDestination(configPath, held);
213
249
  return value;
214
250
  } catch (error) {
251
+ // Refused before this scope published anything: there is nothing to recover.
252
+ if (error instanceof ConfigWriteContentChanged && recovery.identity === identity) throw error;
215
253
  let changed = error instanceof ConfigWriteDestinationChanged;
216
254
  try { assertConfigWriteDestination(configPath, held); } catch { changed = true; }
217
255
  try {
@@ -99,6 +99,7 @@ import {
99
99
  import { ACCOUNT_GATED_NATIVE_OPENAI_MODELS } from "./catalog/native-models";
100
100
  import { providerCodexAccountMode } from "../providers/registry";
101
101
  import { OPENAI_CODEX_PROVIDER_ID } from "../providers/openai-tiers";
102
+ import { resolveRoutedCatalogDefaults } from "../config/schema/routed-catalog-defaults";
102
103
  import { withCatalogWriteSerialization } from "./catalog-write-serialization";
103
104
  import {
104
105
  auditRefusedCatalogReplacement,
@@ -351,6 +352,7 @@ function prepareCatalog(
351
352
  disabledNativeAccountSlugs: new Set(),
352
353
  multiAgentV2Enabled,
353
354
  openaiContextCap,
355
+ routedCatalogDefaults: resolveRoutedCatalogDefaults(config),
354
356
  });
355
357
  const accountBoundEntries = accountSelectors.length === 0
356
358
  ? []