@bitkyc08/opencodex 2.92.0 → 2.93.0

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 (258) hide show
  1. package/bin/ocx.mjs +10 -5
  2. package/gui/dist/assets/{App-sUf_8afJ.js → App-CizjBqyk.js} +18 -18
  3. package/gui/dist/assets/{Tray-BSsxznDm.js → Tray-DamiMqcX.js} +1 -1
  4. package/gui/dist/assets/{index-BlFE_VB_.js → index-DQsht3vH.js} +12 -12
  5. package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
  6. package/gui/dist/assets/{quota-summary-BRlbXgw0.js → quota-summary-BXu4zE8H.js} +1 -1
  7. package/gui/dist/index.html +2 -2
  8. package/package.json +5 -5
  9. package/src/adapters/anthropic.ts +28 -5
  10. package/src/adapters/coding-agent/batch-dispatcher.ts +122 -0
  11. package/src/adapters/coding-agent/profile.ts +54 -16
  12. package/src/adapters/coding-agent/turn.ts +30 -2
  13. package/src/adapters/command-code.ts +114 -7
  14. package/src/adapters/cursor/native-exec-fs.ts +11 -9
  15. package/src/adapters/devin/live-models.ts +4 -0
  16. package/src/adapters/google-wire-compiler.ts +1 -2
  17. package/src/adapters/kiro/reasoning.ts +2 -0
  18. package/src/adapters/kiro-refusal.ts +6 -1
  19. package/src/adapters/kiro-wire.ts +1 -1
  20. package/src/adapters/openai-chat/messages.ts +8 -2
  21. package/src/adapters/openai-chat/passthrough.ts +35 -14
  22. package/src/adapters/openai-chat/reasoning-replay.ts +27 -16
  23. package/src/adapters/openai-chat/reasoning-wire.ts +117 -8
  24. package/src/adapters/openai-chat/required-tool-result.ts +64 -0
  25. package/src/adapters/openai-chat.ts +7 -8
  26. package/src/adapters/openai-responses/passthrough.ts +7 -4
  27. package/src/adapters/openai-responses/reasoning.ts +13 -0
  28. package/src/adapters/openai-responses/request-strips.ts +1 -1
  29. package/src/adapters/qoder/adapter.ts +129 -8
  30. package/src/adapters/qoder/scaffold-guard.ts +5 -0
  31. package/src/adapters/reasoning-controls.ts +16 -0
  32. package/src/adapters/tool-call-id.ts +1 -3
  33. package/src/bridge/errors.ts +27 -0
  34. package/src/bridge.ts +1 -1
  35. package/src/chat/inbound.ts +4 -1
  36. package/src/chat/outbound.ts +9 -2
  37. package/src/chat/reasoning-details.ts +28 -5
  38. package/src/claude/desktop-first-party.ts +54 -4
  39. package/src/claude/desktop-picker.ts +11 -8
  40. package/src/claude/first-party-settings.ts +3 -1
  41. package/src/claude/inbound.ts +2 -1
  42. package/src/claude/intercept/local-ca.ts +2 -1
  43. package/src/claude/intercept/picker-ca-cleanup.ts +4 -2
  44. package/src/claude/intercept/picker-ca-startup.ts +3 -1
  45. package/src/claude/intercept/picker-models.ts +6 -3
  46. package/src/claude/intercept/picker-runtime.ts +3 -2
  47. package/src/claude/intercept/runtime.ts +6 -3
  48. package/src/claude/model-info.ts +31 -8
  49. package/src/cli/account-api.ts +11 -0
  50. package/src/cli/capabilities-agents-routing.ts +2 -2
  51. package/src/cli/capabilities-base.ts +7 -1
  52. package/src/cli/capabilities-observe-system.ts +10 -0
  53. package/src/cli/claude-desktop.ts +9 -8
  54. package/src/cli/claude.ts +3 -2
  55. package/src/cli/codex-shim-autorestore.ts +9 -0
  56. package/src/cli/combo-result.ts +7 -0
  57. package/src/cli/combo.ts +18 -0
  58. package/src/cli/cross-home-owner.ts +13 -1
  59. package/src/cli/dispatch.ts +25 -6
  60. package/src/cli/ensure-desired-integrations.ts +8 -6
  61. package/src/cli/export-command.ts +4 -1
  62. package/src/cli/help.ts +2 -1
  63. package/src/cli/index.ts +45 -45
  64. package/src/cli/integration-plan-dto.ts +4 -0
  65. package/src/cli/opencode.ts +20 -9
  66. package/src/cli/registry.ts +6 -4
  67. package/src/cli/root.ts +9 -0
  68. package/src/cli/status.ts +59 -1
  69. package/src/cli/stop-restore.ts +113 -0
  70. package/src/cli/sync-expectation.ts +60 -0
  71. package/src/cli/uninstall-integrations.ts +41 -7
  72. package/src/client/connect.ts +40 -3
  73. package/src/client/link-home.ts +10 -1
  74. package/src/client/machine-api.ts +3 -1
  75. package/src/client/sync-expectation.ts +118 -0
  76. package/src/clients/config-export/agent-clients.ts +96 -0
  77. package/src/clients/config-export/contracts.ts +25 -7
  78. package/src/clients/config-export/qoder.ts +38 -23
  79. package/src/clients/config-export/reasoning-metadata.ts +55 -8
  80. package/src/clients/config-export.ts +12 -0
  81. package/src/clients/lazycodex.ts +7 -2
  82. package/src/clients/reasoning-controls.ts +49 -0
  83. package/src/codex/auth-api/account-identity.ts +14 -0
  84. package/src/codex/auth-api/account-list.ts +29 -2
  85. package/src/codex/auth-api/http.ts +13 -0
  86. package/src/codex/auth-api/main-account-probe.ts +2 -2
  87. package/src/codex/auth-api/pool-mode-gate.ts +16 -3
  88. package/src/codex/auth-api/pool-quota-probe.ts +15 -0
  89. package/src/codex/auth-context.ts +15 -12
  90. package/src/codex/catalog/build-entries.ts +22 -0
  91. package/src/codex/catalog/configured-tiers.ts +70 -0
  92. package/src/codex/catalog/effort.ts +44 -10
  93. package/src/codex/catalog/gather-capture.ts +1 -0
  94. package/src/codex/catalog/heal-observation.ts +155 -13
  95. package/src/codex/catalog/metadata.ts +6 -0
  96. package/src/codex/catalog/model-hints.ts +60 -11
  97. package/src/codex/catalog/model-visibility.ts +3 -2
  98. package/src/codex/catalog/native-models.ts +18 -3
  99. package/src/codex/catalog/parsing.ts +10 -8
  100. package/src/codex/catalog/pinned-models.ts +2 -1
  101. package/src/codex/catalog/provider-models.ts +4 -5
  102. package/src/codex/catalog/retained-sync.ts +2 -1
  103. package/src/codex/catalog/routed-gather.ts +19 -20
  104. package/src/codex/catalog/write-audit.ts +3 -2
  105. package/src/codex/catalog-self-heal.ts +43 -23
  106. package/src/codex/collision-identity.ts +30 -5
  107. package/src/codex/convergence.ts +4 -3
  108. package/src/codex/data/roster-pinned-models.json +177 -1
  109. package/src/codex/desired-state.ts +6 -1
  110. package/src/codex/desktop-compatibility/installed-build.ts +88 -12
  111. package/src/codex/desktop-compatibility/runtime.ts +29 -5
  112. package/src/codex/desktop-compatibility/usage-controller.ts +2 -0
  113. package/src/codex/desktop-compatibility/windows-certificate-trust.ts +46 -12
  114. package/src/codex/inject/config-toml.ts +0 -18
  115. package/src/codex/inject/plan.ts +18 -3
  116. package/src/codex/inject/remove.ts +6 -2
  117. package/src/codex/inject.ts +1 -1
  118. package/src/codex/journal.ts +61 -1
  119. package/src/codex/model-entitlements.ts +1 -1
  120. package/src/codex/native-main-owner.ts +27 -1
  121. package/src/codex/native-profile-store.ts +2 -1
  122. package/src/codex/pool-credit-policy.ts +35 -1
  123. package/src/codex/quota-types.ts +3 -0
  124. package/src/codex/quota.ts +24 -4
  125. package/src/codex/role-auto-assign.ts +6 -2
  126. package/src/codex/subagent-defaults.ts +49 -4
  127. package/src/combos/failover.ts +17 -2
  128. package/src/combos/jev-decision-contract.ts +22 -1
  129. package/src/combos/jev-service-exchange.ts +3 -1
  130. package/src/combos/jev.ts +95 -9
  131. package/src/combos/resolve.ts +45 -1
  132. package/src/combos/types.ts +24 -0
  133. package/src/config/load-degrade.ts +5 -0
  134. package/src/config/paths.ts +19 -3
  135. package/src/config/pending-teardown.ts +22 -1
  136. package/src/config/provider-validation.ts +15 -4
  137. package/src/config/removed-opencode-free.ts +11 -0
  138. package/src/config/schema/leaf-validators.ts +5 -0
  139. package/src/generated/compatibility-version.json +314 -230
  140. package/src/generated/model-metadata.ts +5 -5
  141. package/src/images/loop.ts +16 -2
  142. package/src/integrations/catalog-refresh.ts +1 -1
  143. package/src/integrations/hermes-profiles.ts +251 -0
  144. package/src/integrations/merge.ts +8 -0
  145. package/src/integrations/mutation-plan.ts +19 -4
  146. package/src/integrations/registry.ts +5 -0
  147. package/src/integrations/state.ts +36 -1
  148. package/src/integrations/writer.ts +18 -4
  149. package/src/lib/bun-path-runtime.mjs +2 -1
  150. package/src/lib/errors.ts +62 -0
  151. package/src/lib/eventstream-decoder.ts +81 -37
  152. package/src/lib/opaque-proxy-tunnel.ts +32 -8
  153. package/src/lib/pinned-http.ts +35 -2
  154. package/src/lib/process-control.ts +13 -1
  155. package/src/lib/socks5-fetch.ts +59 -64
  156. package/src/lib/socks5-upload-waiter.ts +50 -0
  157. package/src/lib/sse-decoder.ts +7 -2
  158. package/src/lib/state-store-sweeper.ts +40 -14
  159. package/src/lib/windows-native-principal-worker.ts +14 -0
  160. package/src/lib/windows-native-principal.ts +188 -0
  161. package/src/lib/windows-secret-acl.ts +39 -3
  162. package/src/lib/windows-user-principal.ts +62 -18
  163. package/src/link/ssh-config.ts +35 -3
  164. package/src/providers/account-quota-disk.ts +12 -4
  165. package/src/providers/codebuddy-models.ts +6 -0
  166. package/src/providers/codex-capacity.ts +3 -1
  167. package/src/providers/derive.ts +28 -0
  168. package/src/providers/kiro-models.ts +3 -0
  169. package/src/providers/mimo-thinking.ts +12 -0
  170. package/src/providers/model-rename-fields.ts +1 -0
  171. package/src/providers/model-rename-migration.ts +10 -0
  172. package/src/providers/openai-sidecar-credit.ts +2 -2
  173. package/src/providers/reasoning-capabilities.ts +76 -0
  174. package/src/providers/registry/entries-core.ts +14 -12
  175. package/src/providers/registry/entries-extended.ts +63 -20
  176. package/src/providers/registry/model-ids.ts +2 -0
  177. package/src/providers/registry/model-seeds.ts +93 -28
  178. package/src/providers/registry/types.ts +10 -1
  179. package/src/providers/resolved-model-policy.ts +26 -6
  180. package/src/providers/routed-config.ts +9 -1
  181. package/src/providers/stale-model-roster-migration.ts +44 -7
  182. package/src/remote-control/workspace-pi-runtime.ts +11 -6
  183. package/src/responses/compaction-summary.ts +45 -0
  184. package/src/responses/muse-tool-name-alias.ts +1 -2
  185. package/src/responses/parser.ts +3 -2
  186. package/src/responses/schema.ts +1 -0
  187. package/src/responses/thought-signature-replay.ts +10 -2
  188. package/src/routing/capability.ts +8 -2
  189. package/src/routing/history/ingest.ts +28 -3
  190. package/src/server/auth-cors.ts +3 -2
  191. package/src/server/chat-completions.ts +7 -0
  192. package/src/server/chat-native-eligibility.ts +7 -0
  193. package/src/server/chat-native-reasoning.ts +14 -4
  194. package/src/server/direct-local-http.ts +5 -2
  195. package/src/server/effort-policy.ts +5 -1
  196. package/src/server/index/live-sideband.ts +18 -15
  197. package/src/server/index/serve-options.ts +5 -4
  198. package/src/server/management/agent-settings-routes.ts +27 -15
  199. package/src/server/management/combo-routes.ts +4 -0
  200. package/src/server/management/config-routes.ts +2 -2
  201. package/src/server/management/decision-discovery.ts +12 -2
  202. package/src/server/management/hermes-profile-routes.ts +156 -0
  203. package/src/server/management/integration-routes.ts +85 -24
  204. package/src/server/management/model-routes.ts +2 -2
  205. package/src/server/management/model-row-export-metadata.ts +25 -6
  206. package/src/server/management/model-rows.ts +15 -20
  207. package/src/server/management/native-integration-routes.ts +11 -8
  208. package/src/server/management/route-registry.ts +4 -0
  209. package/src/server/management-api.ts +5 -0
  210. package/src/server/models-capabilities.ts +21 -3
  211. package/src/server/responses/adapter-delivery.ts +11 -1
  212. package/src/server/responses/adapter-dispatch.ts +2 -2
  213. package/src/server/responses/codex-ws-exchange.ts +39 -9
  214. package/src/server/responses/codex-ws-session.ts +38 -4
  215. package/src/server/responses/codex-ws-wire.ts +6 -1
  216. package/src/server/responses/combo-required-tool-contract.ts +103 -0
  217. package/src/server/responses/combo-stream-preflight.ts +8 -1
  218. package/src/server/responses/compact.ts +4 -3
  219. package/src/server/responses/context-overflow.ts +8 -1
  220. package/src/server/responses/core-combo-failure.ts +10 -0
  221. package/src/server/responses/core-combo.ts +23 -15
  222. package/src/server/responses/core-lifetime.ts +3 -0
  223. package/src/server/responses/core-normalize.ts +11 -1
  224. package/src/server/responses/core-options.ts +2 -0
  225. package/src/server/responses/main-hard-lock-routing.ts +60 -44
  226. package/src/server/responses/passthrough-delivery.ts +40 -2
  227. package/src/server/responses/policy-fallback.ts +6 -1
  228. package/src/server/responses/request-compression.ts +12 -7
  229. package/src/server/responses/request-prepare.ts +22 -2
  230. package/src/server/responses/request-sidecar-auth.ts +2 -0
  231. package/src/server/responses/response-effects.ts +22 -10
  232. package/src/server/responses/sidecar-execution.ts +11 -3
  233. package/src/server/stop-teardown.ts +36 -1
  234. package/src/server/ws-bridge.ts +1 -1
  235. package/src/service/desktop-supervision.d.mts +7 -4
  236. package/src/service/desktop-supervision.mjs +90 -13
  237. package/src/service/ownership-mutation-lease.mjs +21 -7
  238. package/src/types/config.ts +8 -2
  239. package/src/types/provider.ts +20 -6
  240. package/src/types/request.ts +10 -0
  241. package/src/types.ts +1 -0
  242. package/src/update/bind-probe.ts +29 -0
  243. package/src/update/job.ts +10 -29
  244. package/src/update/npm-install-job.ps1 +173 -0
  245. package/src/update/npm-install.mjs +70 -0
  246. package/src/update/stop-contract.d.mts +1 -0
  247. package/src/update/stop-contract.mjs +14 -0
  248. package/src/update/stop-decision.d.mts +1 -1
  249. package/src/update/stop-decision.mjs +13 -3
  250. package/src/update/teardown-handover.ts +166 -0
  251. package/src/update/transactional-install.d.mts +14 -3
  252. package/src/update/transactional-install.mjs +33 -7
  253. package/src/usage/expected-prices.ts +64 -31
  254. package/src/usage/timeline.ts +19 -9
  255. package/src/vision/eligibility.ts +15 -5
  256. package/src/vision/plan.ts +2 -2
  257. package/src/web-search/loop.ts +16 -2
  258. package/gui/dist/assets/index-DPeB9HpV.css +0 -1
@@ -1,7 +1,7 @@
1
1
  import { canInferVendorContext } from "./vendor-context";
2
2
  import { effectiveProviderAlias, effectiveProviderAliasDecision } from "../../providers/default-aliases";
3
3
  import { initialModelSelectionPending } from "../../providers/initial-model-selection";
4
- import { supportsConfiguredUltraFast } from "./configured-tiers";
4
+ import { supportsConfiguredFlex, supportsConfiguredUltraFast } from "./configured-tiers";
5
5
  import { execFileSync } from "node:child_process";
6
6
  import { createHash, createHmac, randomBytes } from "node:crypto";
7
7
  import { copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync } from "node:fs";
@@ -102,7 +102,7 @@ import type {
102
102
  CatalogTrustedOpenAiApiPolicySnapshot,
103
103
  } from "../convergence-types";
104
104
  import type { CatalogGatherProviderAuthOutcome, CatalogGatherProviderModelOutcome, GatherFlightCapture, ModelsAuthResolverFactory } from "./gather-capture";
105
- import { applyProviderConfigHints, configuredAutoCompactTokenLimit, configuredMaxInputTokens, configuredModelDisplayName, configuredReasoningSummarySupport, modelInputModalities, routedMaxOutputTokens, withVisionSidecarInput } from "./model-hints";
105
+ import { applyProviderConfigHints, configuredAutoCompactTokenLimit, configuredMaxInputTokens, configuredModelDisplayName, configuredReasoningSummarySupport, copyReasoningHintSource, modelInputModalities, routedMaxOutputTokens, withVisionSidecarInput } from "./model-hints";
106
106
  import { resolveComboCatalogMember } from "./combo-member";
107
107
  import { captureGatherFlight, captureTrustedOpenAiApiPolicy, gatherFlightKey, keyedGatherBytesIdentity, withCanonicalOpenAiForwardAuthDefault } from "./gather-capture";
108
108
  import { fetchProviderModelsWithAuth, observedModelsAuthResolver, refreshingModelsAuthResolver } from "./provider-models";
@@ -364,6 +364,7 @@ async function gatherRoutedModelsUncached(
364
364
  const supported = serviceTierSupportFromPolicy(policy);
365
365
  if (supported !== undefined) model.supportsServiceTier = supported;
366
366
  model.supportsUltraFastTier = supportsConfiguredUltraFast(policy);
367
+ model.supportsFlexTier = supportsConfiguredFlex(policy);
367
368
  if (supported === true && policy.fastTierDescription !== undefined) model.fastTierDescription = policy.fastTierDescription;
368
369
  }
369
370
  }
@@ -661,6 +662,7 @@ async function gatherRoutedModelsUncached(
661
662
  ...(cm.defaultReasoningEffort ? { defaultReasoningEffort: cm.defaultReasoningEffort } : {}),
662
663
  ...(typeof supportsServiceTier === "boolean" ? { supportsServiceTier } : {}),
663
664
  supportsUltraFastTier: supportsConfiguredUltraFast(fastPolicy),
665
+ supportsFlexTier: supportsConfiguredFlex(fastPolicy),
664
666
  ...(supportsServiceTier === true && fastPolicy?.fastTierDescription !== undefined
665
667
  ? { fastTierDescription: fastPolicy.fastTierDescription }
666
668
  : {}),
@@ -818,8 +820,8 @@ async function gatherRoutedModelsUncached(
818
820
  ? config.combos?.[model.id]?.targets ?? []
819
821
  : [{ provider: model.provider }];
820
822
  const inactive = quotaInactiveReason(config, targets);
821
- const named = displayName && !model.displayName ? { ...model, displayName } : model;
822
- return inactive ? { ...named, quotaInactiveReason: inactive } : named;
823
+ const named = displayName && !model.displayName ? copyReasoningHintSource(model, { ...model, displayName }) : model;
824
+ return inactive ? copyReasoningHintSource(named, { ...named, quotaInactiveReason: inactive }) : named;
823
825
  }),
824
826
  comboOmissions: localOmissions,
825
827
  providerAuthOutcomes: localProviderAuthOutcomes,
@@ -966,7 +968,7 @@ export function augmentRoutedModelsWithMetadata(
966
968
  : undefined;
967
969
  const liveWindow = typeof existing.contextWindow === "number" && existing.contextWindow > 0;
968
970
  if (liveWindow || publishedWindow === undefined) continue;
969
- const seeded: CatalogModel = { ...existing, contextWindow: publishedWindow };
971
+ const seeded = copyReasoningHintSource(existing, { ...existing, contextWindow: publishedWindow });
970
972
  out[existingIndex] = providers?.[provider]
971
973
  ? applyProviderConfigHints(
972
974
  provider,
@@ -990,21 +992,18 @@ export function augmentRoutedModelsWithMetadata(
990
992
  ...(typeof meta.maxTokens === "number" && meta.maxTokens > 0 ? { maxOutputTokens: meta.maxTokens } : {}),
991
993
  ...(Array.isArray(meta.input) && meta.input.length > 0 ? { inputModalities: [...meta.input] } : {}),
992
994
  };
993
- out.push({
994
- ...model,
995
- ...(providers?.[provider]
996
- ? applyProviderConfigHints(
997
- provider,
998
- providers[provider],
999
- model,
1000
- contextCap,
1001
- metadataModelIdCaseFoldByProvider?.get(provider),
1002
- undefined,
1003
- metadataConfigDirByProvider?.get(provider),
1004
- includeVisionSidecar,
1005
- )
1006
- : {}),
1007
- });
995
+ out.push(providers?.[provider]
996
+ ? applyProviderConfigHints(
997
+ provider,
998
+ providers[provider],
999
+ model,
1000
+ contextCap,
1001
+ metadataModelIdCaseFoldByProvider?.get(provider),
1002
+ undefined,
1003
+ metadataConfigDirByProvider?.get(provider),
1004
+ includeVisionSidecar,
1005
+ )
1006
+ : model);
1008
1007
  }
1009
1008
  }
1010
1009
  return out;
@@ -68,6 +68,8 @@ function readTail(fd: number, size: number): Buffer {
68
68
  }
69
69
 
70
70
  function completeRecords(bytes: Buffer): { records: Buffer[]; count: number; clean: boolean } {
71
+ // Keep a BOM in the decoded text so JSON.parse still rejects BOM-prefixed rows.
72
+ const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
71
73
  const records: Buffer[] = [];
72
74
  let start = 0;
73
75
  let clean = true;
@@ -75,8 +77,7 @@ function completeRecords(bytes: Buffer): { records: Buffer[]; count: number; cle
75
77
  for (let end = bytes.indexOf(10); end !== -1; end = bytes.indexOf(10, start)) {
76
78
  const line = bytes.subarray(start, end);
77
79
  try {
78
- const text = line.toString("utf8");
79
- if (!line.equals(Buffer.from(text))) throw new Error("invalid UTF-8");
80
+ const text = decoder.decode(line);
80
81
  JSON.parse(text);
81
82
  records[count % CATALOG_AUDIT_KEEP_RECORDS] = bytes.subarray(start, end + 1);
82
83
  count++;
@@ -3,7 +3,7 @@ import { readRuntimePort } from "../config/process-state";
3
3
  import { readClientConnectionState } from "../client/state";
4
4
  import { getActiveTurnCount, isDraining, isRecyclingForExit, isShutdownDraining } from "../server/lifecycle";
5
5
  import type { OcxConfig } from "../types";
6
- import { observeCatalogHealFile, sameCatalogHealPath, selectCatalogHealPath, type CatalogObservation } from "./catalog/heal-observation";
6
+ import { compareCatalogHealPaths, observeCatalogHealFile, retainCatalogHealPath, selectCatalogHealPath, type CatalogObservation } from "./catalog/heal-observation";
7
7
  import { subscribeCatalogPublication } from "./catalog/publication-observer";
8
8
  import { configEnablesRoutedNamespace, ocxRoutedNamespaceCounts } from "./catalog/routed-removal";
9
9
  import { inspectCodexHomeOwner } from "./codex-home-owner";
@@ -51,6 +51,7 @@ export interface CatalogSelfHealDeps {
51
51
  now?: () => number;
52
52
  catalogPath?: () => string | null;
53
53
  observe?: (path: string, readContent: boolean) => CatalogObservation | null;
54
+ retainPath?: typeof retainCatalogHealPath;
54
55
  converge?: (config: OcxConfig, lifecycle: CatalogHealLifecycle) => Promise<CatalogHealOutcome>;
55
56
  subscribe?: typeof subscribeCatalogPublication;
56
57
  gates?: Partial<CatalogSelfHealGates>;
@@ -135,14 +136,19 @@ export function startCodexCatalogSelfHeal(options: { port?: number; deps?: Catal
135
136
  const attempts: number[] = [];
136
137
  const heals: number[] = [];
137
138
 
138
- const read = (path: string): NamespaceObservation | null => {
139
+ const read = (path: string, fresh = false): NamespaceObservation | null => {
139
140
  const quick = observe(path, false);
140
141
  if (quick === null) return null;
141
- if (observed !== null && sameCatalogHealPath(observed.path, path) && observed.signature === quick.signature) return observed;
142
+ if (!fresh && observed !== null) {
143
+ const relation = compareCatalogHealPaths(observed.path, path);
144
+ if (relation === "unknown") return null;
145
+ if (relation === "same" && observed.signature === quick.signature) return observed;
146
+ }
142
147
  const seen = observe(path, true);
143
148
  if (seen === null) return null;
144
- observed = { path, signature: seen.signature, namespaces: seen.catalog ? new Set(ocxRoutedNamespaceCounts(seen.catalog).keys()) : null };
145
- return observed;
149
+ const result = { path, signature: seen.signature, namespaces: seen.catalog ? new Set(ocxRoutedNamespaceCounts(seen.catalog).keys()) : null };
150
+ if (!fresh) observed = result;
151
+ return result;
146
152
  };
147
153
  const accept = (path: string): void => {
148
154
  const seen = read(path);
@@ -154,18 +160,23 @@ export function startCodexCatalogSelfHeal(options: { port?: number; deps?: Catal
154
160
  pendingRetry = null;
155
161
  recheckAt = 0;
156
162
  };
157
- const updateTarget = (path: string | null): void => {
163
+ const updateTarget = (path: string | null): boolean => {
158
164
  // Unavailable selection is not evidence of a different target or lost authority.
159
- if (path === null) return;
160
- if (target !== null && sameCatalogHealPath(target, path)) return;
165
+ if (path === null) return false;
166
+ if (target !== null) {
167
+ const relation = compareCatalogHealPaths(target, path);
168
+ if (relation === "unknown") return false;
169
+ if (relation === "same") return true;
170
+ }
161
171
  clear();
162
172
  target = path;
173
+ return true;
163
174
  };
164
175
  const beforeCommit = (path: string, entryGeneration: number): boolean => {
165
176
  try {
166
177
  const selected = catalogPath();
167
178
  return !stopped && !released && generation === entryGeneration
168
- && selected !== null && sameCatalogHealPath(selected, path) && evaluateCatalogSelfHealGates(gates).open;
179
+ && selected !== null && compareCatalogHealPaths(selected, path) === "same" && evaluateCatalogSelfHealGates(gates).open;
169
180
  } catch { return false; }
170
181
  };
171
182
  const capRetryAt = (now: number): number => {
@@ -182,8 +193,7 @@ export function startCodexCatalogSelfHeal(options: { port?: number; deps?: Catal
182
193
  running = true;
183
194
  try {
184
195
  const path = catalogPath();
185
- updateTarget(path);
186
- if (path === null) return;
196
+ if (!updateTarget(path) || path === null) return;
187
197
  // Pending cache/funnel failure is independent of catalog stat or apparent repaired rows.
188
198
  if (pendingRetry) {
189
199
  const config = gates.loadConfig();
@@ -226,7 +236,7 @@ export function startCodexCatalogSelfHeal(options: { port?: number; deps?: Catal
226
236
  })).committed; }
227
237
  catch { /* Failed attempts retain pending retry and consume the attempt budget. */ }
228
238
  const selected = catalogPath();
229
- if (stopped || released || generation !== entryGeneration || selected === null || !sameCatalogHealPath(selected, path)) return;
239
+ if (stopped || released || generation !== entryGeneration || selected === null || compareCatalogHealPaths(selected, path) !== "same") return;
230
240
  last = { at: new Date().toISOString(), lostNamespaces: lostEnabled.length, committed };
231
241
  if (committed) {
232
242
  heals.push(clock());
@@ -241,33 +251,43 @@ export function startCodexCatalogSelfHeal(options: { port?: number; deps?: Catal
241
251
 
242
252
  const unsubscribe = (deps.subscribe ?? subscribeCatalogPublication)(event => {
243
253
  if (stopped) return;
254
+ const release = event.kind === "native-released" || event.intent === "restore";
255
+ // Bind publication evidence before comparisons can observe a retargeted alias.
256
+ const stillPublished = !release && event.path !== null ? (deps.retainPath ?? retainCatalogHealPath)(event.path) : null;
244
257
  // Native restoration can remove the journal before notification. Fence the known
245
258
  // target (and target-less releases) without resolving possibly unavailable evidence.
246
- const release = event.kind === "native-released" || event.intent === "restore";
247
- if (release && (event.path === null || (target !== null && sameCatalogHealPath(event.path, target)))) {
259
+ const known = event.path !== null && target !== null ? compareCatalogHealPaths(event.path, target) : "different";
260
+ if (release && (event.path === null || known !== "different")) {
248
261
  clear();
249
262
  released = true;
250
263
  return;
251
264
  }
252
265
  const path = catalogPath();
253
- if (event.path !== null && (target === null || !sameCatalogHealPath(event.path, target))
254
- && (path === null || !sameCatalogHealPath(event.path, path))) return;
266
+ const selected = event.path !== null && path !== null ? compareCatalogHealPaths(event.path, path) : "different";
267
+ if (event.path !== null && known === "different" && selected === "different") return;
255
268
  if (release) {
256
269
  clear();
257
270
  released = true; // Only a later accepted owner publication can re-arm this lifecycle.
258
271
  return;
259
272
  }
260
- if (running) return; // Catalog-success/cache-failure must not accept a baseline.
273
+ if (running) {
274
+ if (known === "unknown" || selected === "unknown") clear();
275
+ return; // Catalog-success/cache-failure must not accept a baseline.
276
+ }
261
277
  // A committed owner publication supplies a read-only baseline even while heal writes are gated.
262
- if (event.path === null || path === null || !sameCatalogHealPath(event.path, path)) return;
263
- updateTarget(path);
278
+ if (event.path === null || path === null || selected !== "same" || stillPublished === null) return;
279
+ // Read independently of obsolete evidence, but retire it only after current selection proof.
280
+ const seen = read(event.path, true);
281
+ const current = catalogPath();
282
+ if (seen?.namespaces == null || current === null
283
+ || compareCatalogHealPaths(event.path, current) !== "same" || !stillPublished(seen.signature)) return;
284
+ clear();
285
+ target = current;
286
+ baseline = observed = seen;
264
287
  released = false;
265
- pendingRetry = null;
266
- recheckAt = 0;
267
- accept(event.path);
268
288
  });
269
289
  // Capture immediately after startup sync, before a foreign write can become the first tick.
270
- try { updateTarget(catalogPath()); if (target !== null) accept(target); }
290
+ try { const path = catalogPath(); if (updateTarget(path) && target !== null) accept(target); }
271
291
  catch { /* Unavailable observation can be retried by the scheduled tick. */ }
272
292
  const schedule = (): void => {
273
293
  if (stopped) return;
@@ -1,12 +1,14 @@
1
- import { extractAccountIdClaims, extractEmail } from "../oauth/chatgpt";
1
+ import { decodeJwtPayload, extractAccountIdClaims, extractEmail } from "../oauth/chatgpt";
2
2
  import type { CodexAccount, OcxConfig } from "../types";
3
3
  import { getCodexAccountCredential } from "./account-store";
4
4
  import type { CodexTokens } from "./auth-collision";
5
5
  import { captureMainAccountIdentityGeneration, isMainAccountIdentityGenerationLive } from "./main-account-cache";
6
6
  import { codexPlanKey, extractChatgptPlanType } from "./plan";
7
+ import { nativeUserIdClaims } from "./reserve-availability";
7
8
 
8
9
  export interface CodexCollisionIdentity {
9
10
  accountId: string;
11
+ userId?: string;
10
12
  email?: string | null;
11
13
  plan?: unknown;
12
14
  }
@@ -34,19 +36,42 @@ function homeScope(): string {
34
36
 
35
37
  let observed: { identity: CodexCollisionIdentity; homeScope: string; generation: number } | undefined;
36
38
 
39
+ function suppressObservedUserId(): void {
40
+ if (!observed || observed.homeScope !== homeScope()
41
+ || !isMainAccountIdentityGenerationLive(observed.generation)) return;
42
+ observed = { ...observed, identity: { ...observed.identity, userId: undefined } };
43
+ }
44
+
37
45
  /** Only existing owned lifecycle observations may publish; never call with a request bearer. */
38
46
  export function observeMainCodexCollisionIdentity(tokens?: CodexTokens): void {
39
47
  if (!tokens) { observed = undefined; return; }
40
48
  if (typeof tokens.access_token !== "string" || typeof tokens.account_id !== "string"
41
- || (tokens.id_token !== undefined && typeof tokens.id_token !== "string")) return;
49
+ || (tokens.id_token !== undefined && typeof tokens.id_token !== "string")) {
50
+ suppressObservedUserId();
51
+ return;
52
+ }
42
53
  const claims = [extractAccountIdClaims(tokens.id_token), extractAccountIdClaims(tokens.access_token)];
43
- if (claims.some(claim => claim.conflict)) return;
54
+ if (claims.some(claim => claim.conflict)) { suppressObservedUserId(); return; }
44
55
  const accountId = tokens.account_id || claims.find(claim => claim.accountId)?.accountId;
45
- if (!accountId || claims.some(claim => claim.accountId && claim.accountId !== accountId)) return;
56
+ if (!accountId || claims.some(claim => claim.accountId && claim.accountId !== accountId)) {
57
+ suppressObservedUserId();
58
+ return;
59
+ }
46
60
  const emails = new Set([extractEmail(tokens.id_token), extractEmail(undefined, tokens.access_token)]
47
61
  .flatMap(email => normalizedEmail(email) ? [normalizedEmail(email)!] : []));
48
- if (emails.size > 1) return;
62
+ if (emails.size > 1) { suppressObservedUserId(); return; }
63
+ const idPayload: unknown = tokens.id_token === undefined ? undefined : decodeJwtPayload(tokens.id_token);
64
+ const idTokenMalformed = tokens.id_token !== undefined
65
+ && (idPayload === null || typeof idPayload !== "object" || Array.isArray(idPayload));
66
+ const users = [tokens.id_token ? nativeUserIdClaims(tokens.id_token) : undefined, nativeUserIdClaims(tokens.access_token)];
67
+ const userIds = new Set(users.flatMap(user => user?.userId ? [user.userId] : []));
68
+ // A join key needs one token claiming both the account and the user, as a Pool access token does;
69
+ // auth.json account_id alone, or claims split across a mixed token set, prove no pairing.
70
+ const bound = claims.some((claim, index) => claim.accountId === accountId && users[index]?.userId);
71
+ const userId = !idTokenMalformed && !users.some(user => user?.conflict) && bound && userIds.size === 1
72
+ ? [...userIds][0] : undefined;
49
73
  observed = { identity: { accountId, email: [...emails][0],
74
+ ...(userId ? { userId } : {}),
50
75
  plan: extractChatgptPlanType(tokens.id_token, tokens.access_token) },
51
76
  homeScope: homeScope(), generation: captureMainAccountIdentityGeneration() };
52
77
  }
@@ -1,7 +1,7 @@
1
1
  import { projectAntigravitySelectedModels } from "../providers/antigravity-effort-families";
2
- import { configuredUltraFastSlugs } from "./catalog/configured-tiers";
2
+ import { configuredUltraFastSlugs, retainedFlexPolicyBySlug } from "./catalog/configured-tiers";
3
3
  import { join } from "node:path";
4
- import { sameCatalogHealPath } from "./catalog/heal-observation";
4
+ import { compareCatalogHealPaths } from "./catalog/heal-observation";
5
5
 
6
6
  import { getConfigDir, saveConfigPreservingClaudeCode, ultraFastTierEnabled, websocketsEnabled, withExpectedConfigGenerationSync } from "../config";
7
7
  import { reconcileSuccessfulModelDiscoveries } from "../providers/new-model-policy";
@@ -373,6 +373,7 @@ function prepareCatalog(
373
373
  const mergedModels = mergeCatalogEntriesFromObservedState({
374
374
  ultraFastTier: ultraFastTierEnabled(config),
375
375
  configuredUltraFastSlugs: configuredUltraFastSlugs(ordered),
376
+ retainedFlexPolicyBySlug: retainedFlexPolicyBySlug(config.providers ?? {}, catalogModels, ordered),
376
377
  modelPickerOrder,
377
378
  accountSelectors,
378
379
  catalogModels,
@@ -674,7 +675,7 @@ export async function commitCodexCatalogCandidate(
674
675
  const guarded = withExpectedConfigGenerationSync(state.generation, () => {
675
676
  const invalid = revalidateCandidate(state);
676
677
  if (invalid) return invalid;
677
- if (lifecycle.expectedCatalogPath !== undefined && !sameCatalogHealPath(state.catalog.path, lifecycle.expectedCatalogPath)) {
678
+ if (lifecycle.expectedCatalogPath !== undefined && compareCatalogHealPaths(state.catalog.path, lifecycle.expectedCatalogPath) !== "same") {
678
679
  return { kind: "stale", reason: "target-identity" } as const;
679
680
  }
680
681
  if (lifecycle.beforeCommit && lifecycle.beforeCommit() !== true) return { kind: "stale", reason: "process-local" } as const;