@bitkyc08/opencodex 2.94.0 → 2.95.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 (249) hide show
  1. package/gui/dist/assets/App-8yedBkhm.js +58 -0
  2. package/gui/dist/assets/App-B4j-Txmb.css +1 -0
  3. package/gui/dist/assets/{Tray-CZatQdoF.js → Tray-erSMzxPG.js} +1 -1
  4. package/gui/dist/assets/index-D7DCm5eQ.js +94 -0
  5. package/gui/dist/assets/quota-summary-BK4VuQNc.js +1 -0
  6. package/gui/dist/index.html +1 -1
  7. package/package.json +1 -1
  8. package/src/adapters/anthropic.ts +10 -3
  9. package/src/adapters/command-code-project-context.ts +3 -3
  10. package/src/adapters/kiro/adapter.ts +4 -1
  11. package/src/adapters/kiro/stream.ts +1 -0
  12. package/src/adapters/kiro-events.ts +1 -0
  13. package/src/adapters/openai-chat/messages.ts +20 -7
  14. package/src/adapters/openai-chat/passthrough.ts +4 -2
  15. package/src/adapters/openai-chat/single-system.ts +24 -0
  16. package/src/adapters/openai-responses/muse-tool-catalog.ts +87 -0
  17. package/src/adapters/openai-responses/passthrough.ts +42 -7
  18. package/src/adapters/openai-responses/prompt-cache.ts +3 -1
  19. package/src/adapters/openai-responses/request-strips.ts +23 -4
  20. package/src/adapters/openai-responses/tool-output-recovery.ts +21 -8
  21. package/src/adapters/openai-responses/tool-schema.ts +20 -8
  22. package/src/adapters/opencode-go-additional-tools.ts +39 -6
  23. package/src/adapters/routed-agent-messages.ts +3 -0
  24. package/src/adapters/xai-web-search.ts +6 -3
  25. package/src/adapters/zed-additional-tools.ts +7 -7
  26. package/src/adapters/zed.ts +1 -6
  27. package/src/advisor/consult.ts +22 -10
  28. package/src/advisor/runtime.ts +10 -4
  29. package/src/bridge/max-output-completion.ts +41 -0
  30. package/src/bridge/response-json.ts +9 -4
  31. package/src/bridge/sse.ts +13 -2
  32. package/src/chatgpt/app-server-shim/bundle-trust-policy.ts +5 -0
  33. package/src/chatgpt/app-server-shim/launcher.ts +40 -6
  34. package/src/claude/compatibility.ts +5 -1
  35. package/src/claude/desktop-3p.ts +27 -6
  36. package/src/claude/desktop-model-visibility.ts +141 -0
  37. package/src/claude/desktop-remote-store-io.ts +8 -8
  38. package/src/claude/inbound-content-options.ts +11 -1
  39. package/src/claude/intercept/proxy-auth.ts +16 -16
  40. package/src/cli/account-main.ts +3 -2
  41. package/src/cli/capabilities-provider-models.ts +7 -0
  42. package/src/cli/chatgpt-command.ts +1 -1
  43. package/src/cli/codex-launcher.ts +20 -8
  44. package/src/cli/codex-shim-autorestore.ts +19 -1
  45. package/src/cli/dispatch.ts +6 -6
  46. package/src/cli/doctor.ts +5 -5
  47. package/src/cli/index.ts +4 -9
  48. package/src/cli/init.ts +2 -2
  49. package/src/cli/internal-command.ts +29 -2
  50. package/src/cli/provider-cc-switch-import.ts +185 -0
  51. package/src/cli/provider.ts +5 -0
  52. package/src/cli/registry.ts +1 -0
  53. package/src/cli/restart-scope.ts +2 -2
  54. package/src/cli/root.ts +6 -6
  55. package/src/cli/stop-approval.ts +15 -1
  56. package/src/cli/v2.ts +69 -19
  57. package/src/client/machine-api.ts +2 -2
  58. package/src/clients/config-export.ts +14 -3
  59. package/src/codex/account-cooldown-response.ts +18 -0
  60. package/src/codex/app-server-restart-service.ts +2 -2
  61. package/src/codex/auth-api/login-flow.ts +2 -2
  62. package/src/codex/auth-api/pool-quota-probe.ts +2 -2
  63. package/src/codex/auth-context.ts +4 -4
  64. package/src/codex/catalog/bundled.ts +10 -3
  65. package/src/codex/catalog/metadata.ts +4 -5
  66. package/src/codex/catalog/native-omission.ts +28 -0
  67. package/src/codex/catalog/native-template.ts +58 -0
  68. package/src/codex/catalog/parsing.ts +3 -29
  69. package/src/codex/catalog/provider-models.ts +2 -1
  70. package/src/codex/catalog/retained-sync.ts +15 -5
  71. package/src/codex/catalog/write-audit.ts +18 -18
  72. package/src/codex/cli-install-provenance.ts +46 -45
  73. package/src/codex/cli-update-artifacts.ts +8 -6
  74. package/src/codex/cli-update-job-store-windows.ts +99 -27
  75. package/src/codex/cli-update-job-worker.ts +3 -11
  76. package/src/codex/cli-update-recovery.ts +54 -8
  77. package/src/codex/cli-update-selection-gate.ts +74 -4
  78. package/src/codex/cli-windows-plan-provenance.ts +37 -19
  79. package/src/codex/codex-home-owner.ts +9 -8
  80. package/src/codex/convergence.ts +13 -3
  81. package/src/codex/coordinator-doctor.ts +14 -8
  82. package/src/codex/desktop-app/handoff.ts +1 -1
  83. package/src/codex/desktop-app-restart.ts +11 -1
  84. package/src/codex/exec-boundary.ts +26 -5
  85. package/src/codex/history-provider.ts +11 -10
  86. package/src/codex/inject/bounded-config-reader.ts +14 -13
  87. package/src/codex/main-account.ts +6 -6
  88. package/src/codex/native-main-lock-file.ts +13 -12
  89. package/src/codex/native-residue.ts +18 -14
  90. package/src/codex/orca-auth-source.ts +8 -7
  91. package/src/codex/quota-types.ts +5 -0
  92. package/src/codex/quota.ts +49 -7
  93. package/src/codex/role-auto-assign.ts +50 -26
  94. package/src/codex/role-capability.ts +160 -0
  95. package/src/codex/role-sizing.ts +24 -6
  96. package/src/codex/routing/cooldown-math.ts +3 -2
  97. package/src/codex/runtime.ts +43 -3
  98. package/src/codex/shim-fingerprint.ts +11 -9
  99. package/src/codex/shim-inspect.ts +3 -2
  100. package/src/codex/shim-restore-lock.ts +11 -14
  101. package/src/codex/shim-state-file.ts +22 -14
  102. package/src/codex/shim-wrapper-write.ts +7 -6
  103. package/src/codex/shim.ts +25 -2
  104. package/src/codex/transition-state.ts +5 -4
  105. package/src/combos/failover.ts +43 -4
  106. package/src/config/atomic-write.ts +38 -7
  107. package/src/config/diagnostics.ts +3 -0
  108. package/src/config/initialize.ts +6 -6
  109. package/src/config/load-degrade.ts +2 -0
  110. package/src/config/process-state.ts +23 -5
  111. package/src/config/salvage.ts +1 -0
  112. package/src/config/schema/config-schema.ts +29 -1
  113. package/src/config/schema/leaf-validators.ts +7 -0
  114. package/src/config/schema/workflow-budget.ts +43 -0
  115. package/src/config/tracked-runtime-inspection.ts +188 -0
  116. package/src/generated/compatibility-version.json +313 -213
  117. package/src/integrations/aside-profile-context.ts +1 -1
  118. package/src/integrations/droid-settings.ts +4 -4
  119. package/src/integrations/hermes-profiles.ts +3 -3
  120. package/src/lib/bounded-file-read.ts +3 -9
  121. package/src/lib/bun-runtime-preflight.ts +9 -8
  122. package/src/lib/file-identity.ts +15 -0
  123. package/src/lib/local-chat-completion.ts +8 -6
  124. package/src/lib/local-destinations.ts +32 -3
  125. package/src/lib/redact-folding.ts +9 -0
  126. package/src/lib/spend-pool-alias-validation.ts +6 -6
  127. package/src/lib/state-store-registrations.ts +2 -0
  128. package/src/lib/test-home-guard.ts +37 -9
  129. package/src/lib/windows-secret-acl.ts +47 -29
  130. package/src/lib/workflow-budget-config.ts +39 -0
  131. package/src/local-credentials/generation.ts +6 -2
  132. package/src/local-credentials/inventory.ts +132 -8
  133. package/src/messaging/remote-forward-failure.ts +35 -0
  134. package/src/messaging/remote-ports.ts +27 -5
  135. package/src/messaging/remote-process.ts +30 -4
  136. package/src/messaging/remote-tunnels.ts +80 -15
  137. package/src/oauth/antigravity-discovery-diagnostics.ts +65 -0
  138. package/src/oauth/google-antigravity.ts +23 -10
  139. package/src/oauth/index.ts +2 -0
  140. package/src/oauth/kiro-device-login.ts +87 -30
  141. package/src/oauth/kiro-iam-identity-center.ts +107 -0
  142. package/src/oauth/store.ts +9 -7
  143. package/src/providers/account-quota-disk.ts +18 -4
  144. package/src/providers/cc-switch-import-bytes.ts +991 -0
  145. package/src/providers/cc-switch-import-source.ts +1083 -0
  146. package/src/providers/cc-switch-import.ts +942 -0
  147. package/src/providers/derive.ts +6 -0
  148. package/src/providers/model-discovery-diagnostic.ts +4 -0
  149. package/src/providers/model-discovery.ts +4 -4
  150. package/src/providers/model-rename-fields.ts +2 -0
  151. package/src/providers/model-rename-migration.ts +41 -6
  152. package/src/providers/quota/report-cache.ts +17 -4
  153. package/src/providers/quota.ts +2 -2
  154. package/src/providers/reasoning-metadata.ts +31 -15
  155. package/src/providers/registry/entries-core.ts +1 -1
  156. package/src/providers/registry/entries-extended.ts +1 -1
  157. package/src/providers/registry/model-ids.ts +1 -0
  158. package/src/providers/registry/model-seeds.ts +2 -1
  159. package/src/providers/registry/types.ts +3 -1
  160. package/src/providers/resolved-model-policy.ts +2 -2
  161. package/src/providers/routed-config.ts +2 -0
  162. package/src/providers/stale-model-roster-migration.ts +5 -1
  163. package/src/providers/xai-transport.ts +4 -4
  164. package/src/remote-control/workspace-codex-runtime.ts +2 -2
  165. package/src/remote-control/workspace-executor.ts +14 -13
  166. package/src/responses/custom-tool-compat.ts +2 -1
  167. package/src/responses/item-provenance.ts +79 -0
  168. package/src/responses/namespace-tool-compat.ts +21 -3
  169. package/src/router.ts +21 -2
  170. package/src/routing/analytics.ts +3 -5
  171. package/src/routing/fallback-policy.ts +7 -3
  172. package/src/routing/health.ts +5 -3
  173. package/src/routing/history/build-file.ts +6 -0
  174. package/src/routing/history/indexer.ts +158 -31
  175. package/src/routing/history/ingest.ts +1 -1
  176. package/src/routing/history/integrity.ts +208 -0
  177. package/src/routing/history/rebuild-job.ts +20 -6
  178. package/src/routing/history/rebuild-protocol.ts +2 -1
  179. package/src/routing/history/rebuild-worker.ts +18 -0
  180. package/src/routing/history/sqlite-errors.ts +9 -0
  181. package/src/server/admission-model-scope.ts +21 -4
  182. package/src/server/advisor-admission-scope.ts +29 -0
  183. package/src/server/auth-cors.ts +5 -2
  184. package/src/server/capture-admission-policy.ts +91 -0
  185. package/src/server/chat-completions.ts +33 -7
  186. package/src/server/claude-messages.ts +90 -2
  187. package/src/server/codex-model-list.ts +2 -1
  188. package/src/server/configured-credentials.ts +5 -0
  189. package/src/server/index/serve-options.ts +12 -2
  190. package/src/server/index/websocket-handler.ts +3 -0
  191. package/src/server/management/agent-settings-routes.ts +34 -9
  192. package/src/server/management/codex-agent-role-routes.ts +1 -0
  193. package/src/server/management/codex-role-auto-assign.ts +50 -6
  194. package/src/server/management/config-routes.ts +15 -4
  195. package/src/server/management/context.ts +3 -0
  196. package/src/server/management/native-integration-routes.ts +22 -0
  197. package/src/server/management/oauth-account-routes.ts +20 -4
  198. package/src/server/management/provider-overwrite-carry.ts +21 -0
  199. package/src/server/management/provider-routes.ts +3 -1
  200. package/src/server/management/route-registry.ts +2 -0
  201. package/src/server/management/shared.ts +17 -1
  202. package/src/server/management/workflow-budget-routes.ts +70 -3
  203. package/src/server/messages-native-eligibility.ts +6 -5
  204. package/src/server/messages-native-scope.ts +6 -1
  205. package/src/server/messages-shared.ts +57 -17
  206. package/src/server/persistent-gui-session.ts +4 -4
  207. package/src/server/request-log.ts +30 -2
  208. package/src/server/responses/adapter-delivery.ts +4 -0
  209. package/src/server/responses/advisor-plan-slot.ts +4 -0
  210. package/src/server/responses/advisor-slot.ts +73 -46
  211. package/src/server/responses/codex-auth-error.ts +5 -1
  212. package/src/server/responses/combo-required-tool-contract.ts +27 -0
  213. package/src/server/responses/compact.ts +4 -1
  214. package/src/server/responses/core-combo-failure.ts +2 -0
  215. package/src/server/responses/core-combo.ts +66 -5
  216. package/src/server/responses/core-lifetime.ts +4 -0
  217. package/src/server/responses/core-options.ts +9 -0
  218. package/src/server/responses/core.ts +2 -0
  219. package/src/server/responses/jev-model-invoke.ts +4 -2
  220. package/src/server/responses/passthrough-dispatch.ts +5 -4
  221. package/src/server/responses/policy-fallback.ts +2 -0
  222. package/src/server/responses/request-prepare.ts +4 -5
  223. package/src/server/responses/request-send-budget.ts +2 -1
  224. package/src/server/responses/request-sidecar-auth.ts +1 -0
  225. package/src/server/responses/request-transport.ts +2 -3
  226. package/src/server/responses/run-turn-execution.ts +4 -0
  227. package/src/server/responses/sidecar-execution.ts +21 -5
  228. package/src/server/responses-snapshot-repair.ts +18 -4
  229. package/src/server/responses-undeclared-tool-guard.ts +4 -0
  230. package/src/server/workflow-refusal.ts +2 -1
  231. package/src/service/state-lock.ts +12 -11
  232. package/src/service-manager-probe.ts +53 -8
  233. package/src/types/admission-policy.ts +13 -0
  234. package/src/types/config.ts +25 -0
  235. package/src/types/provider.ts +10 -0
  236. package/src/types/request.ts +7 -0
  237. package/src/types.ts +1 -0
  238. package/src/update/job.ts +20 -0
  239. package/src/update/worker-launch.ts +71 -1
  240. package/src/usage/log.ts +25 -4
  241. package/src/vision/index.ts +2 -0
  242. package/src/vision/plan.ts +4 -0
  243. package/src/vision/routed-describe.ts +38 -23
  244. package/src/web-search/loop.ts +104 -9
  245. package/src/web-search/parse.ts +10 -2
  246. package/gui/dist/assets/App-DMps4OLk.css +0 -1
  247. package/gui/dist/assets/App-DmvwlhQq.js +0 -58
  248. package/gui/dist/assets/index-3EPO_KbX.js +0 -94
  249. package/gui/dist/assets/quota-summary-BHvWg9mi.js +0 -1
@@ -1,5 +1,5 @@
1
1
  import { journalOwner } from "../codex/journal";
2
- import { diagnoseCodexShim, installCodexShim, uninstallCodexShim } from "../codex/shim";
2
+ import { diagnoseCodexShim, installCodexShimAsync, uninstallCodexShimAsync } from "../codex/shim";
3
3
  import { readManagementJsonBody } from "../server/management/body";
4
4
  import type { OcxClientConnectionConfig } from "../types";
5
5
  import { disconnectClient, syncConnectedClient } from "./connect";
@@ -130,7 +130,7 @@ export async function handleMachineApi(
130
130
  return Response.json({ error: "action must be install, repair, or uninstall" }, { status: 400 });
131
131
  }
132
132
  try {
133
- const result = input.action === "uninstall" ? uninstallCodexShim() : installCodexShim();
133
+ const result = input.action === "uninstall" ? await uninstallCodexShimAsync() : await installCodexShimAsync();
134
134
  return Response.json({ success: true, action: input.action, result, shim: diagnoseCodexShim() });
135
135
  } catch (error) {
136
136
  return Response.json({ success: false, error: error instanceof Error ? error.message : "shim action failed" }, { status: 409 });
@@ -906,6 +906,8 @@ interface PiExportOptions {
906
906
  * states it rather than leaving each user to hand-edit a block the next export rewrites.
907
907
  */
908
908
  foldDeveloperRole?: boolean;
909
+ /** Provider dialect; omitted writes `PI_API_DIALECT`. */
910
+ api?: "openai-completions" | "openai-responses";
909
911
  }
910
912
 
911
913
  export interface PiGeneratedConfig {
@@ -1085,7 +1087,7 @@ function buildPiClientConfig(ctx: ExportContext, options: PiExportOptions = {}):
1085
1087
  providers: {
1086
1088
  [OPENCODE_PROVIDER_ID]: {
1087
1089
  baseUrl: ctx.baseUrl,
1088
- api: PI_API_DIALECT,
1090
+ api: options.api ?? PI_API_DIALECT,
1089
1091
  apiKey: LOOPBACK_API_KEY_PLACEHOLDER,
1090
1092
  ...(Object.keys(compat).length > 0 ? { compat } : {}),
1091
1093
  models,
@@ -1391,12 +1393,21 @@ function buildAsideContribution(ctx: ExportContext): ManagedContribution {
1391
1393
  * are consistent; passing it on only one would make `ocx export --client omo`
1392
1394
  * emit a `compat` block while enable and refresh wrote a file without it, and
1393
1395
  * the two would drift apart at the first refresh.
1396
+ *
1397
+ * The same rule covers the opt-in `omoClientExport.api` dialect (#7431): both paths read it from
1398
+ * the live config, so a refresh keeps the Responses dialect instead of reverting it to Chat.
1394
1399
  */
1395
1400
  function buildOmoContribution(ctx: ExportContext): ManagedContribution {
1396
- const doc = buildPiClientConfig(ctx, PI_EXPORT_OPTIONS);
1401
+ const doc = buildPiClientConfig(ctx, omoExportOptions(ctx));
1397
1402
  return singleFragment("omo", ["providers", OPENCODE_PROVIDER_ID], doc.providers[OPENCODE_PROVIDER_ID]);
1398
1403
  }
1399
1404
 
1405
+ function omoExportOptions(ctx: ExportContext): PiExportOptions {
1406
+ return ctx.config?.omoClientExport?.api === "openai-responses"
1407
+ ? { ...PI_EXPORT_OPTIONS, api: "openai-responses" }
1408
+ : PI_EXPORT_OPTIONS;
1409
+ }
1410
+
1400
1411
  /** Cline's shared SDK store; command-local --config must be mirrored by the env override. */
1401
1412
  export function clineConfigPath(env: OpencodeLaunchEnv = process.env, home: string = homedir()): string {
1402
1413
  const explicit = env.CLINE_PROVIDER_SETTINGS_PATH?.trim();
@@ -1652,7 +1663,7 @@ export const EXPORT_CLIENTS: Record<ExportClientId, ExportClientSpec> = {
1652
1663
  destination: env => omoConfigPath(env),
1653
1664
  apiKeyEnv: "",
1654
1665
  exportHint: "omo reads a non-secret placeholder from models.json; loopback needs no key.",
1655
- build: ctx => buildPiClientConfig(ctx, PI_EXPORT_OPTIONS),
1666
+ build: ctx => buildPiClientConfig(ctx, omoExportOptions(ctx)),
1656
1667
  format: "json",
1657
1668
  summarize: summarizePi,
1658
1669
  buildContribution: buildOmoContribution,
@@ -0,0 +1,18 @@
1
+ // Local quota advice is not an upstream target-wide retry directive. Response identity keeps
2
+ // this distinction private to the process: headers, body copies and HTTP hops cannot mint it.
3
+ const accountCooldownResponses = new WeakSet<Response>();
4
+
5
+ /** Minted only by mapCodexAuthContextErrorToResponse for an ordinary CodexAccountCooldownError. */
6
+ export function markCodexAccountCooldownResponse(response: Response): Response {
7
+ accountCooldownResponses.add(response);
8
+ return response;
9
+ }
10
+
11
+ export function isCodexAccountCooldownResponse(response: Response): boolean {
12
+ return accountCooldownResponses.has(response);
13
+ }
14
+
15
+ /** Preserve provenance across the combo's bounded error-body reconstruction. */
16
+ export function carryCodexAccountCooldownResponse(from: Response, to: Response): void {
17
+ if (accountCooldownResponses.has(from)) accountCooldownResponses.add(to);
18
+ }
@@ -37,8 +37,8 @@ import { getServerListenPort } from "../server/lifecycle";
37
37
  import type { DesktopPickerState } from "./desktop-app/picker-freshness";
38
38
 
39
39
  async function defaultRestartDesktopApp(): Promise<CodexDesktopRestartSummary> {
40
- const { restartCodexDesktopApp } = await import("./desktop-app-restart");
41
- const outcome = restartCodexDesktopApp({ allowHandoff: false });
40
+ const { restartCodexDesktopAppAsync } = await import("./desktop-app-restart");
41
+ const outcome = await restartCodexDesktopAppAsync({ allowHandoff: false });
42
42
  return {
43
43
  attempted: outcome.attempted,
44
44
  stopped: outcome.stopped,
@@ -1,6 +1,6 @@
1
1
  import { withCodexAccountLogLabel } from "../account-label";
2
2
  import { getCodexAccountCredential, markCodexAccountValidated, readCodexAccountRecord, saveCodexAccountCredential, CodexCredentialRefreshLockTimeoutError, CodexCredentialRefreshBusyError, CodexCredentialRefreshStaleError } from "../account-store";
3
- import { clearAccountQuota, isCodexQuotaExhausted, isValidWhamHistoryObservation, parseUsageQuota, setAccountQuotaFromParsed } from "../quota";
3
+ import { clearAccountQuota, isCodexQuotaExhausted, parseUsageQuota, poolWhamPolicyObservation, setAccountQuotaFromParsed } from "../quota";
4
4
  import type { StoredAccountQuota, WhamUsageResponse } from "../quota";
5
5
  import { ConfigMutationLockError, withConfigMutationLockSync } from "../../config";
6
6
  import { appendDefaultCodexAccountNamespace, codexAccountPickerEnabled } from "../account-namespaces";
@@ -278,7 +278,7 @@ export async function handleCodexAuthLoginStart(req: Request, config: OcxConfig,
278
278
  email = data.email?.trim() || email;
279
279
  plan = nonEmptyPlan(data.plan_type) ?? plan;
280
280
  quota = parseUsageQuota(data);
281
- policyQuota = isValidWhamHistoryObservation(data) ? quota : null;
281
+ policyQuota = poolWhamPolicyObservation(data, quota);
282
282
  }
283
283
  } catch { /* wham fetch is non-blocking */ }
284
284
  // Reauth must refresh the same ChatGPT identity already bound to this pool slot.
@@ -3,7 +3,7 @@ import { fetchCodexUsage } from "../quota-query-backoff";
3
3
  import type { CodexUsageOwner } from "../quota-query-backoff";
4
4
  import { capturePoolQuotaWriter, getValidCodexToken, isCodexAccountGenerationLive, forceRefreshCodexPoolToken, markCodexAccountValidated, markCodexAccountValidationFailed, readCodexAccountRecord, isTerminalCodexPoolRefreshFailure, CodexCredentialGenerationConflictError, CodexCredentialRefreshLockTimeoutError, CodexCredentialRefreshBusyError, CodexCredentialRefreshStaleError, TokenRefreshError } from "../account-store";
5
5
  import type { PoolQuotaWriter } from "../quota-types";
6
- import { isValidWhamHistoryObservation, getAccountQuota, isCompleteCodexQuotaRecoverySnapshot, parseUsageQuota, setAccountQuotaFromParsed } from "../quota";
6
+ import { isValidWhamHistoryObservation, getAccountQuota, isCompleteCodexQuotaRecoverySnapshot, parseUsageQuota, poolWhamPolicyObservation, setAccountQuotaFromParsed } from "../quota";
7
7
  import type { StoredAccountQuota, WhamUsageResponse } from "../quota";
8
8
  import type { ManualResetRefreshLineage } from "../routing";
9
9
  import { clearAccountNeedsReauth, markAccountNeedsReauth } from "../account-runtime-state";
@@ -377,7 +377,7 @@ export async function commitPoolQuotaResponse(
377
377
  return { quota: null, needsReauth: false, credentialGeneration: generation };
378
378
  }
379
379
  const validPolicyObservation = isValidWhamHistoryObservation(data);
380
- setAccountQuotaFromParsed(accountId, quota, writerGeneration, undefined, validPolicyObservation ? quota : null,
380
+ setAccountQuotaFromParsed(accountId, quota, writerGeneration, undefined, poolWhamPolicyObservation(data, quota),
381
381
  ctx.poolWriter && validPolicyObservation ? { writer: ctx.poolWriter, observedAt, source: "wham", raw: quota } : undefined,
382
382
  true);
383
383
  return {
@@ -322,8 +322,7 @@ export type CodexAuthContext =
322
322
  transientProbe?: TransientProbeGrant;
323
323
  }
324
324
  | {
325
- // Main Codex account participating in rotation: token injected from ~/.codex/auth.json
326
- // (Option A). Distinct from "main" (request-owned passthrough or Direct mode).
325
+ // Main account rotating in the Pool (Option A), token from ~/.codex/auth.json; never request-owned "main".
327
326
  kind: "main-pool";
328
327
  accountId: string;
329
328
  writerGeneration: number;
@@ -336,14 +335,14 @@ export type CodexAuthContext =
336
335
  chatgptAccountId: string;
337
336
  /** Bypass Pool selection and suppress quota/transient failover for an exact selector. */
338
337
  fixedAccount?: boolean;
339
- /** See `pool.affinityKey`. */
340
- affinityKey?: string;
338
+ affinityKey?: string; // See `pool.affinityKey`.
341
339
  /** See `pool.probeLeaseId`. */
342
340
  probeLeaseId?: string;
343
341
  quotaScope?: CodexQuotaScope;
344
342
  probeQuotaScope?: CodexQuotaScope;
345
343
  /** See `pool.transientProbe`. */
346
344
  transientProbe?: TransientProbeGrant;
345
+ affinityDecision?: CodexAffinityDecision;
347
346
  };
348
347
 
349
348
  /** Probe lease carried by this context, when it holds one. */
@@ -1733,6 +1732,7 @@ async function resolveCodexAuthContextUnannotated(
1733
1732
  ...(quotaScope ? { quotaScope } : {}),
1734
1733
  ...(probeLeaseId ? { probeLeaseId } : {}),
1735
1734
  ...(probeQuotaScope ? { probeQuotaScope } : {}),
1735
+ ...(affinityDecision ? { affinityDecision } : {}),
1736
1736
  ...(transientProbe ? { transientProbe } : {}),
1737
1737
  };
1738
1738
  }
@@ -33,7 +33,8 @@ import upstreamModelsSnapshot from "../data/upstream-models.json";
33
33
  import { decodeOverlayState } from "../shim-state-file";
34
34
 
35
35
 
36
- import { activeCodexModelsCachePath, catalogBackupPathFor, findNativeTemplate, findSupportedNativeTemplate, isDefaultCatalogPath, legacyCatalogBackupPath, parseCatalogJson, readCatalog, readCatalogBackup, readCodexCatalogPath } from "./parsing";
36
+ import { activeCodexModelsCachePath, catalogBackupPathFor, ensureStrictCatalogFields, findNativeTemplate, findSupportedNativeTemplate, isDefaultCatalogPath, legacyCatalogBackupPath, parseCatalogJson, readCatalog, readCatalogBackup, readCodexCatalogPath } from "./parsing";
37
+ import { retainedNativeInheritanceTemplate } from "./native-template";
37
38
  import type { RawCatalog, RawEntry } from "./parsing";
38
39
  import { isSpawnableCodexCandidate } from "../exec-invocation";
39
40
  import { validatedCodexExecInvocation, validatedCodexExecInvocationAsync } from "../exec-boundary";
@@ -729,8 +730,14 @@ export function readCurrentCodexModelsCache(): RawCatalog | null {
729
730
  export function loadCatalogTemplate(): RawEntry | null {
730
731
  const catalogPath = readCodexCatalogPath();
731
732
  const bundled = bundledCodexCatalogSnapshot();
732
- const fromRows = (catalog: RawCatalog | null) => findSupportedNativeTemplate(catalog
733
- ? { ...catalog, models: (catalog.models ?? []).filter(isPlainObject) } : null);
733
+ const fromRows = (catalog: RawCatalog | null) => {
734
+ const template = findSupportedNativeTemplate(catalog
735
+ ? { ...catalog, models: (catalog.models ?? []).filter(isPlainObject) } : null);
736
+ // An emitted native has already passed strict normalization. Match that read surface,
737
+ // including property insertion order, when the native survives only as source evidence.
738
+ return template && template === retainedNativeInheritanceTemplate(catalog)
739
+ ? ensureStrictCatalogFields(structuredClone(template)) : template;
740
+ };
734
741
  // Template inheritance only. The validity gates in this file keep `findNativeTemplate`
735
742
  // so a catalog carrying only a newly launched native row stays valid (#2813).
736
743
  const native = fromRows(readCatalog(catalogPath))
@@ -118,15 +118,14 @@ export function configuredNativeAliasSlugs(
118
118
  }
119
119
 
120
120
  /**
121
- * Bare native rows that must be absent, rather than merely hidden, while Desktop native-alias
122
- * compatibility is active. Codex Desktop's remote allowlist can ignore `visibility: "hide"`;
123
- * omitting disabled native rows is therefore part of the explicit native-alias opt-in.
121
+ * Bare native rows omitted by native-alias compatibility or explicit native-omission opt-in.
122
+ * Codex Desktop's remote allowlist can ignore `visibility: "hide"`.
124
123
  */
125
124
  export function desktopAllowlistSuppressedNativeSlugs(
126
- config: Pick<OcxConfig, "combos" | "disabledModels">,
125
+ config: Pick<OcxConfig, "combos" | "disabledModels" | "omitDisabledNativeModels">,
127
126
  ): Set<string> {
128
127
  const suppressed = configuredNativeAliasSlugs(config);
129
- if (suppressed.size === 0) return suppressed;
128
+ if (suppressed.size === 0 && config.omitDisabledNativeModels !== true) return suppressed;
130
129
  const disabled = disabledNativeSlugs(config);
131
130
  for (const slug of NATIVE_OPENAI_MODELS) {
132
131
  if (disabled.has(slug)) suppressed.add(slug);
@@ -0,0 +1,28 @@
1
+ import type { OcxConfig } from "../../types";
2
+ import { trustedAccountBoundNativeCatalogSlug } from "./account-models";
3
+ import { CODEX_NATIVE_ALIAS_CATALOG_KIND } from "./kinds";
4
+ import { SUPPORTED_NATIVE_OPENAI_SLUGS } from "./native-models";
5
+ import { hasOcxRoutedAuthorship } from "./ownership";
6
+ import { hasOrdinaryNativeOpenAiRow } from "./control-plane";
7
+ import { isCodexControlPlaneModel } from "../control-plane-models";
8
+ import type { RawEntry } from "./parsing";
9
+
10
+ /** Final projection also covers exact selector disables and observed account-native ids. */
11
+ export function omitDisabledNativeCatalogEntries(
12
+ entries: RawEntry[],
13
+ config: Pick<OcxConfig, "omitDisabledNativeModels" | "disabledModels">,
14
+ ): RawEntry[] {
15
+ if (config.omitDisabledNativeModels !== true) return entries;
16
+ const disabled = new Set(config.disabledModels ?? []);
17
+ const visible = entries.filter(entry => {
18
+ if (entry.opencodex_catalog_kind === CODEX_NATIVE_ALIAS_CATALOG_KIND) return true;
19
+ const slug = typeof entry.slug === "string" ? entry.slug : "";
20
+ const accountNative = trustedAccountBoundNativeCatalogSlug(entry);
21
+ if (accountNative) return !disabled.has(slug) && !disabled.has(accountNative);
22
+ return !SUPPORTED_NATIVE_OPENAI_SLUGS.has(slug) || hasOcxRoutedAuthorship(entry) || !disabled.has(slug);
23
+ });
24
+ // Nothing omitted: the flag must not change the catalog, control-plane rows included.
25
+ if (visible.length === entries.length) return entries;
26
+ return hasOrdinaryNativeOpenAiRow(visible)
27
+ ? visible : visible.filter(entry => !isCodexControlPlaneModel(entry.slug));
28
+ }
@@ -0,0 +1,58 @@
1
+ import { COMBO_NAMESPACE } from "../../combos/identifiers";
2
+ import { isPlainObject } from "../../lib/plain-data";
3
+ import { CODEX_NATIVE_ALIAS_CATALOG_KIND } from "./kinds";
4
+ import { SUPPORTED_NATIVE_OPENAI_SLUGS } from "./native-models";
5
+ import { hasOcxRoutedAuthorship } from "./ownership";
6
+ import type { RawCatalog, RawEntry } from "./parsing";
7
+
8
+ /** Internal source evidence, outside the emitted model collection. */
9
+ export const NATIVE_INHERITANCE_TEMPLATE_FIELD = "opencodex_native_inheritance_template";
10
+
11
+ function isSupportedNativeTemplate(row: RawEntry): boolean {
12
+ return typeof row.slug === "string"
13
+ && SUPPORTED_NATIVE_OPENAI_SLUGS.has(row.slug)
14
+ && !row.slug.includes("/")
15
+ && "base_instructions" in row
16
+ && row.opencodex_catalog_kind !== CODEX_NATIVE_ALIAS_CATALOG_KIND
17
+ && row.owned_by !== COMBO_NAMESPACE
18
+ && !hasOcxRoutedAuthorship(row);
19
+ }
20
+
21
+ export function retainedNativeInheritanceTemplate(catalog: RawCatalog | null): RawEntry | null {
22
+ const retained = catalog?.[NATIVE_INHERITANCE_TEMPLATE_FIELD];
23
+ return isPlainObject(retained) && isSupportedNativeTemplate(retained) ? retained : null;
24
+ }
25
+
26
+ /**
27
+ * Inheritance is stricter than catalog validity: unknown bare rows must never lend native
28
+ * eligibility to routed rows (#2813). Retained source evidence uses exactly the same rule.
29
+ * Prefer it over emitted rows so omission of the first native cannot change the next build.
30
+ * No supported source still returns null, preserving the existing null-template behavior.
31
+ */
32
+ export function findSupportedNativeTemplate(catalog: RawCatalog | null): RawEntry | null {
33
+ return retainedNativeInheritanceTemplate(catalog)
34
+ ?? catalog?.models?.find(isSupportedNativeTemplate) ?? null;
35
+ }
36
+
37
+ /** Capture before any visibility, capability or ordering projection mutates emitted rows. */
38
+ export function captureNativeInheritanceTemplate(catalog: RawCatalog, enabled: boolean): RawEntry | null {
39
+ const template = findSupportedNativeTemplate(catalog);
40
+ if (enabled && template) catalog[NATIVE_INHERITANCE_TEMPLATE_FIELD] = structuredClone(template);
41
+ else delete catalog[NATIVE_INHERITANCE_TEMPLATE_FIELD];
42
+ return template;
43
+ }
44
+
45
+ /**
46
+ * Replace upgradeable source evidence with the writer's fully normalized native result.
47
+ * Non-upgraded source evidence stays pristine, preserving existing byte-idempotent builds.
48
+ * The writer passes its upgrade rule in: importing it from `metadata.ts` here would close a
49
+ * load-time cycle through `bundled.ts`, which reads this module's retained template.
50
+ */
51
+ export function advanceNativeInheritanceTemplate(
52
+ catalog: RawCatalog, entries: readonly RawEntry[], shouldUpgrade: (entry: RawEntry) => boolean,
53
+ ): void {
54
+ const retained = retainedNativeInheritanceTemplate(catalog);
55
+ if (!retained || !shouldUpgrade(retained)) return;
56
+ const upgraded = entries.find(row => row.slug === retained.slug && isSupportedNativeTemplate(row));
57
+ if (upgraded) catalog[NATIVE_INHERITANCE_TEMPLATE_FIELD] = structuredClone(upgraded);
58
+ }
@@ -1,4 +1,6 @@
1
1
  import type { VendorContextInference } from "./vendor-context";
2
+ import { retainedNativeInheritanceTemplate } from "./native-template";
3
+ export { findSupportedNativeTemplate } from "./native-template";
2
4
  import { isCodexControlPlaneModel } from "../control-plane-models";
3
5
  import { execFileSync } from "node:child_process";
4
6
  import { createHash } from "node:crypto";
@@ -307,35 +309,7 @@ export function findNativeTemplate(catalog: RawCatalog | null): RawEntry | null
307
309
  && m.opencodex_catalog_kind !== CODEX_NATIVE_ALIAS_CATALOG_KIND
308
310
  && m.owned_by !== COMBO_NAMESPACE
309
311
  && !hasOcxRoutedAuthorship(m),
310
- ) ?? null;
311
- }
312
-
313
- /**
314
- * Template selection, as opposed to catalog VALIDITY.
315
- *
316
- * `findNativeTemplate` answers "does this look like a real catalog?" and must stay
317
- * permissive: four call sites use it as a validity gate, and a catalog holding only a
318
- * newly launched native model has to keep passing or sync falls back to stale data.
319
- *
320
- * This answers a different question — "which row should every routed model inherit
321
- * from?" — and must be strict. `deriveEntry` deep-clones the chosen row, so an unknown
322
- * bare row carrying `base_instructions` would become the template for every routed
323
- * model and hand them its native eligibility metadata. #2813 is the report that made
324
- * that concrete: a Reserve-shaped row injected by the client is exactly such a row.
325
- *
326
- * Returning null is safe and expected; `deriveEntry` falls back to a conservative
327
- * synthetic template.
328
- */
329
- export function findSupportedNativeTemplate(catalog: RawCatalog | null): RawEntry | null {
330
- return catalog?.models?.find(
331
- m => typeof m.slug === "string"
332
- && SUPPORTED_NATIVE_OPENAI_SLUGS.has(m.slug)
333
- && !m.slug.includes("/")
334
- && "base_instructions" in m
335
- && m.opencodex_catalog_kind !== CODEX_NATIVE_ALIAS_CATALOG_KIND
336
- && m.owned_by !== COMBO_NAMESPACE
337
- && !hasOcxRoutedAuthorship(m),
338
- ) ?? null;
312
+ ) ?? retainedNativeInheritanceTemplate(catalog);
339
313
  }
340
314
 
341
315
  /** Does this row already carry an `ultrafast` tier the operator put there themselves? */
@@ -89,6 +89,7 @@ import {
89
89
  providerRedirectError,
90
90
  } from "../../lib/provider-outbound";
91
91
  import { redactSecretString } from "../../lib/redact";
92
+ import { invalidModelDiscoveryHint } from "../../providers/model-discovery-diagnostic";
92
93
  import {
93
94
  extractProviderModelItems,
94
95
  isRegistryModelDiscoveryUrl,
@@ -857,7 +858,7 @@ export async function fetchProviderModelsWithAuth(
857
858
  };
858
859
  if (shouldLog) {
859
860
  console.warn(
860
- `[opencodex] Provider model discovery for "${name}" ${diagnostic[extracted.reason]} [status=${res.status}, contentType=${contentType}, urlClass=${urlClass}, fallback=${fallback}].`,
861
+ `[opencodex] Provider model discovery for "${name}" ${diagnostic[extracted.reason]} [status=${res.status}, contentType=${contentType}, urlClass=${urlClass}, fallback=${fallback}]${extracted.reason === "invalid_shape" ? invalidModelDiscoveryHint("diagnostic" in extracted ? extracted.diagnostic : undefined) : "."}`,
861
862
  );
862
863
  }
863
864
  return observed(models, "degraded");
@@ -16,6 +16,8 @@ import { COMBO_NAMESPACE } from "../../combos";
16
16
  import { codexAccountNamespaceEntries, isMainCodexAccountTarget } from "../account-namespaces";
17
17
  import { MAIN_CODEX_ACCOUNT_ID } from "../main-account";
18
18
  import { applyNativeAccessPrograms } from "./access-programs";
19
+ import { advanceNativeInheritanceTemplate, captureNativeInheritanceTemplate } from "./native-template";
20
+ import { omitDisabledNativeCatalogEntries } from "./native-omission";
19
21
  import {
20
22
  availableAccountGatedNativeModels,
21
23
  codexModelEntitlementStateForAccount,
@@ -30,7 +32,6 @@ import {
30
32
  catalogBackupPathFor,
31
33
  catalogHasRoutedEntries,
32
34
  findNativeTemplate,
33
- findSupportedNativeTemplate,
34
35
  isDefaultCatalogPath,
35
36
  legacyCatalogBackupPath,
36
37
  readCatalog,
@@ -52,6 +53,7 @@ import {
52
53
  observedReserveCatalogSource,
53
54
  shouldIncludeAccountBoundNativeOpenAi,
54
55
  shouldIncludeNativeOpenAi,
56
+ shouldUpgradeToUpstreamEntry,
55
57
  upstreamNativeEntry,
56
58
  } from "./metadata";
57
59
  import { trustedAccountBoundNativeCatalogSlug } from "./account-models";
@@ -298,9 +300,6 @@ function writeRetainedCatalogSync({
298
300
  catalog,
299
301
  onDiskCatalog,
300
302
  );
301
- // Strict selector for template inheritance; the validity gate above keeps the broad one.
302
- const template = findSupportedNativeTemplate(catalog);
303
-
304
303
  try {
305
304
  // Once-only: preserve the PRISTINE pre-opencodex catalog as the native-priority baseline
306
305
  // (later syncs would otherwise overwrite it with featured-modified priorities).
@@ -321,6 +320,9 @@ function writeRetainedCatalogSync({
321
320
  }
322
321
  } catch { /* backup best-effort */ }
323
322
 
323
+ // Capture inheritance only after pristine backup preparation, before any row projection.
324
+ const template = captureNativeInheritanceTemplate(catalog, config.omitDisabledNativeModels === true);
325
+
324
326
  // Hide disabled models from Codex, then feature the chosen subagent models (native OR routed)
325
327
  // by giving them the lowest priority — see buildCatalogEntries for why priority, not array order.
326
328
  const enabledGo = filterCatalogVisibleModels(goModels, config);
@@ -370,6 +372,13 @@ function writeRetainedCatalogSync({
370
372
  ...desktopAllowlistSuppressedNativeSlugs(config),
371
373
  ...unavailableGatedNativeSlugs,
372
374
  ]);
375
+ // An omitted source still needs the same upgrade/normalization as a visible native.
376
+ // Keep independent combo-alias and entitlement suppression authoritative.
377
+ if (template && shouldUpgradeToUpstreamEntry(template)
378
+ && (!ACCOUNT_GATED_NATIVE_OPENAI_MODELS.has(String(template.slug)) || availableBareGatedNativeSlugs.has(String(template.slug)))
379
+ && !desktopAllowlistSuppressedNativeSlugs({ ...config, omitDisabledNativeModels: false }).has(String(template.slug))) {
380
+ suppressedBareNativeSlugs.delete(String(template.slug));
381
+ }
373
382
  const hasPhysicalComboProvider = Object.hasOwn(config.providers, COMBO_NAMESPACE);
374
383
  const includeNativeOpenAi = shouldIncludeNativeOpenAi(config);
375
384
  const includeAccountBoundNativeOpenAi = shouldIncludeAccountBoundNativeOpenAi(config);
@@ -549,9 +558,10 @@ function writeRetainedCatalogSync({
549
558
  applyNativeAccessPrograms(catalog.models, modelEntitlements, accountTargets);
550
559
  clampCatalogModelsToCodexSupport(catalog.models, { observedCatalog: bundledCodexCatalogSnapshot() });
551
560
  finalizeAutoReviewModelOverride(catalog.models, catalogModelsForMerge, config);
561
+ advanceNativeInheritanceTemplate(catalog, catalog.models, shouldUpgradeToUpstreamEntry);
552
562
  // Last mutation before serialization; see `enforceCatalogSlugUniqueness` for why the ordering
553
563
  // against the effort clamp is load-bearing rather than cosmetic.
554
- catalog.models = enforceCatalogSlugUniqueness(catalog.models, true);
564
+ catalog.models = enforceCatalogSlugUniqueness(omitDisabledNativeCatalogEntries(catalog.models, config), true);
555
565
 
556
566
  const added = goEntries.length + accountBoundEntries.length;
557
567
  const content = `${JSON.stringify(catalog, null, 2)}\n`;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  closeSync, constants, fstatSync, ftruncateSync, lstatSync, openSync, readSync, writeSync,
3
- type Stats,
3
+ type BigIntStats,
4
4
  } from "node:fs";
5
5
  import { join } from "node:path";
6
6
  import { redactUserPath } from "../../lib/redact";
@@ -40,15 +40,15 @@ function auditLine(event: CatalogWriteAuditEvent): Buffer {
40
40
  })}\n`);
41
41
  }
42
42
 
43
- function regularPrivateFile(stat: Stats): boolean {
43
+ function regularPrivateFile(stat: BigIntStats): boolean {
44
44
  // POSIX bits cannot prove NTFS privacy. Windows requires fresh-file ACL hardening.
45
- return !windowsSecretAclApplies() && stat.isFile() && stat.nlink === 1
46
- && stat.uid === process.getuid?.() && (stat.mode & 0o777) === 0o600;
45
+ return !windowsSecretAclApplies() && stat.isFile() && stat.nlink === 1n
46
+ && stat.uid === BigInt(process.getuid?.() ?? -1) && (stat.mode & 0o777n) === 0o600n;
47
47
  }
48
48
 
49
- function sameFile(left: Stats, right: Stats): boolean {
49
+ function sameFile(left: BigIntStats, right: BigIntStats): boolean {
50
50
  return left.dev === right.dev && left.ino === right.ino && left.size === right.size
51
- && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
51
+ && left.mtimeNs === right.mtimeNs && left.ctimeNs === right.ctimeNs;
52
52
  }
53
53
 
54
54
  /** Read at most the tail budget plus one byte to locate a complete first record. */
@@ -116,8 +116,8 @@ export function appendCatalogWriteAudit(
116
116
  if (line.length > CATALOG_AUDIT_MAX_EVENT_BYTES) return "skipped";
117
117
  const path = codexCatalogAuditPath(codexHome);
118
118
  const windows = windowsSecretAclApplies();
119
- let before: Stats | undefined;
120
- try { before = lstatSync(path); }
119
+ let before: BigIntStats | undefined;
120
+ try { before = lstatSync(path, { bigint: true }); }
121
121
  catch (error) {
122
122
  if ((error as NodeJS.ErrnoException).code !== "ENOENT" || !options.create) return "skipped";
123
123
  }
@@ -126,29 +126,29 @@ export function appendCatalogWriteAudit(
126
126
  const flags = constants.O_RDWR | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0)
127
127
  | (before ? (options.create ? 0 : constants.O_APPEND) : constants.O_CREAT | constants.O_EXCL);
128
128
  fd = openSync(path, flags, 0o600);
129
- let opened = fstatSync(fd);
129
+ let opened = fstatSync(fd, { bigint: true });
130
130
  if (windows) {
131
131
  // Existing files have already been refused: no read-only NTFS privacy verifier exists.
132
- if (!opened.isFile() || opened.nlink !== 1 || opened.size !== 0
133
- || !sameFile(opened, lstatSync(path))) return "skipped";
132
+ if (!opened.isFile() || opened.nlink !== 1n || opened.size !== 0n
133
+ || !sameFile(opened, lstatSync(path, { bigint: true }))) return "skipped";
134
134
  if (!hardenSecretPath(path, { required: true, deadlineMs: AUDIT_ACL_DEADLINE_MS }).ok) return "skipped";
135
- const hardened = fstatSync(fd);
135
+ const hardened = fstatSync(fd, { bigint: true });
136
136
  // ACL changes legitimately move ctime. Retain object identity, then take a fresh baseline.
137
- if (!hardened.isFile() || hardened.nlink !== 1 || hardened.size !== 0
137
+ if (!hardened.isFile() || hardened.nlink !== 1n || hardened.size !== 0n
138
138
  || opened.dev !== hardened.dev || opened.ino !== hardened.ino
139
- || !sameFile(hardened, lstatSync(path))) return "skipped";
139
+ || !sameFile(hardened, lstatSync(path, { bigint: true }))) return "skipped";
140
140
  opened = hardened;
141
141
  } else if (!regularPrivateFile(opened) || (before && !sameFile(before, opened))) return "skipped";
142
- if (!options.create && opened.size + line.length > CATALOG_AUDIT_MAX_BYTES) return "skipped";
143
- const tail = readTail(fd, opened.size);
142
+ if (!options.create && opened.size + BigInt(line.length) > CATALOG_AUDIT_MAX_BYTES) return "skipped";
143
+ const tail = readTail(fd, Number(opened.size));
144
144
  const parsed = completeRecords(tail);
145
- if (!sameFile(opened, fstatSync(fd)) || !sameFile(opened, lstatSync(path))) return "skipped";
145
+ if (!sameFile(opened, fstatSync(fd, { bigint: true })) || !sameFile(opened, lstatSync(path, { bigint: true }))) return "skipped";
146
146
  if (!options.create) {
147
147
  if (!parsed.clean || parsed.count + 1 > CATALOG_AUDIT_KEEP_RECORDS) return "skipped";
148
148
  writeAll(fd, line, null);
149
149
  } else if (opened.size <= CATALOG_AUDIT_MAX_BYTES - line.length
150
150
  && parsed.clean && parsed.count < CATALOG_AUDIT_KEEP_RECORDS) {
151
- writeAll(fd, line, opened.size);
151
+ writeAll(fd, line, Number(opened.size));
152
152
  } else {
153
153
  const retained: Buffer[] = [line];
154
154
  let bytes = line.length;