@bitkyc08/opencodex 2.94.0 → 2.96.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.
- package/gui/dist/assets/App-B4j-Txmb.css +1 -0
- package/gui/dist/assets/App-bwugJRKn.js +58 -0
- package/gui/dist/assets/{Tray-CZatQdoF.js → Tray-BOPQyDbH.js} +1 -1
- package/gui/dist/assets/index-ebuVUtB7.js +94 -0
- package/gui/dist/assets/quota-summary-6HsrHQAy.js +1 -0
- package/gui/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/adapters/anthropic.ts +10 -3
- package/src/adapters/command-code-project-context.ts +3 -3
- package/src/adapters/kiro/adapter.ts +4 -1
- package/src/adapters/kiro/stream.ts +1 -0
- package/src/adapters/kiro-events.ts +1 -0
- package/src/adapters/ollama-native.ts +10 -6
- package/src/adapters/openai-chat/messages.ts +20 -7
- package/src/adapters/openai-chat/passthrough.ts +4 -2
- package/src/adapters/openai-chat/single-system.ts +24 -0
- package/src/adapters/openai-responses/canonical-forward.ts +50 -13
- package/src/adapters/openai-responses/muse-tool-catalog.ts +87 -0
- package/src/adapters/openai-responses/passthrough.ts +45 -11
- package/src/adapters/openai-responses/prompt-cache.ts +3 -1
- package/src/adapters/openai-responses/request-strips.ts +23 -4
- package/src/adapters/openai-responses/tool-output-recovery.ts +21 -8
- package/src/adapters/openai-responses/tool-schema.ts +20 -8
- package/src/adapters/openai-responses/transport.ts +17 -26
- package/src/adapters/opencode-go-additional-tools.ts +39 -6
- package/src/adapters/qoder/adapter.ts +1 -1
- package/src/adapters/qoder/image-input.ts +5 -2
- package/src/adapters/routed-agent-messages.ts +3 -0
- package/src/adapters/xai-web-search.ts +6 -3
- package/src/adapters/zed-additional-tools.ts +7 -7
- package/src/adapters/zed.ts +1 -6
- package/src/advisor/consult.ts +22 -10
- package/src/advisor/runtime.ts +10 -4
- package/src/bridge/max-output-completion.ts +41 -0
- package/src/bridge/response-json.ts +9 -4
- package/src/bridge/sse.ts +13 -2
- package/src/chatgpt/app-server-shim/bundle-trust-policy.ts +5 -0
- package/src/chatgpt/app-server-shim/launcher.ts +40 -6
- package/src/claude/compatibility.ts +5 -1
- package/src/claude/desktop-3p.ts +27 -6
- package/src/claude/desktop-model-visibility.ts +141 -0
- package/src/claude/desktop-remote-store-io.ts +8 -8
- package/src/claude/inbound-content-options.ts +11 -1
- package/src/claude/intercept/proxy-auth.ts +16 -16
- package/src/cli/account-main.ts +3 -2
- package/src/cli/agent.ts +44 -15
- package/src/cli/capabilities-agents-routing.ts +9 -0
- package/src/cli/capabilities-provider-models.ts +7 -0
- package/src/cli/chatgpt-command.ts +1 -1
- package/src/cli/codex-launcher.ts +20 -8
- package/src/cli/codex-shim-autorestore.ts +19 -1
- package/src/cli/dispatch.ts +6 -6
- package/src/cli/doctor.ts +5 -5
- package/src/cli/ensure-desired-integrations.ts +4 -3
- package/src/cli/index.ts +8 -10
- package/src/cli/init.ts +2 -2
- package/src/cli/internal-command.ts +29 -2
- package/src/cli/message-command.ts +2 -1
- package/src/cli/message-mcp-command.ts +29 -0
- package/src/cli/provider-cc-switch-import.ts +185 -0
- package/src/cli/provider.ts +5 -0
- package/src/cli/registry.ts +2 -1
- package/src/cli/restart-scope.ts +2 -2
- package/src/cli/root.ts +6 -6
- package/src/cli/stop-approval.ts +15 -1
- package/src/cli/v2.ts +69 -19
- package/src/client/machine-api.ts +2 -2
- package/src/clients/config-export.ts +14 -3
- package/src/codex/account-cooldown-response.ts +18 -0
- package/src/codex/account-store.ts +1 -0
- package/src/codex/app-server-restart-service.ts +2 -2
- package/src/codex/auth-api/login-flow.ts +2 -2
- package/src/codex/auth-api/pool-quota-probe.ts +2 -2
- package/src/codex/auth-context-provider.ts +15 -0
- package/src/codex/auth-context.ts +14 -23
- package/src/codex/catalog/bundled.ts +10 -3
- package/src/codex/catalog/metadata.ts +4 -5
- package/src/codex/catalog/native-omission.ts +28 -0
- package/src/codex/catalog/native-template.ts +58 -0
- package/src/codex/catalog/parsing.ts +3 -29
- package/src/codex/catalog/provider-models.ts +2 -1
- package/src/codex/catalog/retained-sync.ts +15 -5
- package/src/codex/catalog/write-audit.ts +18 -18
- package/src/codex/cli-install-provenance.ts +46 -45
- package/src/codex/cli-update-artifacts.ts +8 -6
- package/src/codex/cli-update-job-store-windows.ts +99 -27
- package/src/codex/cli-update-job-worker.ts +3 -11
- package/src/codex/cli-update-recovery.ts +54 -8
- package/src/codex/cli-update-selection-gate.ts +74 -4
- package/src/codex/cli-windows-plan-provenance.ts +37 -19
- package/src/codex/codex-home-owner.ts +9 -8
- package/src/codex/convergence.ts +13 -3
- package/src/codex/coordinator-doctor.ts +14 -8
- package/src/codex/desktop-app/handoff.ts +1 -1
- package/src/codex/desktop-app-restart.ts +11 -1
- package/src/codex/exec-boundary.ts +26 -5
- package/src/codex/forward-transport-headers.ts +33 -33
- package/src/codex/history-provider.ts +11 -10
- package/src/codex/inject/bounded-config-reader.ts +14 -13
- package/src/codex/installation-id.ts +72 -0
- package/src/codex/main-account.ts +6 -6
- package/src/codex/native-main-lock-file.ts +13 -12
- package/src/codex/native-residue.ts +18 -14
- package/src/codex/orca-auth-source.ts +8 -7
- package/src/codex/quota-types.ts +5 -0
- package/src/codex/quota.ts +49 -7
- package/src/codex/role-auto-assign.ts +50 -26
- package/src/codex/role-capability.ts +160 -0
- package/src/codex/role-sizing.ts +24 -6
- package/src/codex/routing/cooldown-math.ts +3 -2
- package/src/codex/runtime.ts +43 -3
- package/src/codex/shim-fingerprint.ts +11 -9
- package/src/codex/shim-inspect.ts +3 -2
- package/src/codex/shim-restore-lock.ts +11 -14
- package/src/codex/shim-state-file.ts +22 -14
- package/src/codex/shim-wrapper-write.ts +7 -6
- package/src/codex/shim.ts +25 -2
- package/src/codex/transition-state.ts +5 -4
- package/src/combos/failover.ts +43 -4
- package/src/config/atomic-write.ts +38 -7
- package/src/config/diagnostics.ts +3 -0
- package/src/config/initialize.ts +6 -6
- package/src/config/load-degrade.ts +2 -0
- package/src/config/process-state.ts +23 -5
- package/src/config/salvage.ts +1 -0
- package/src/config/schema/config-schema.ts +29 -1
- package/src/config/schema/leaf-validators.ts +7 -0
- package/src/config/schema/workflow-budget.ts +43 -0
- package/src/config/tracked-runtime-inspection.ts +188 -0
- package/src/generated/compatibility-version.json +380 -244
- package/src/grok/sync.ts +10 -1
- package/src/integrations/aside-profile-context.ts +1 -1
- package/src/integrations/droid-settings.ts +4 -4
- package/src/integrations/hermes-profiles.ts +3 -3
- package/src/lib/bounded-file-read.ts +3 -9
- package/src/lib/bun-runtime-preflight.ts +9 -8
- package/src/lib/file-identity.ts +15 -0
- package/src/lib/local-chat-completion.ts +8 -6
- package/src/lib/local-destinations.ts +32 -3
- package/src/lib/redact-folding.ts +9 -0
- package/src/lib/spend-pool-alias-validation.ts +6 -6
- package/src/lib/state-store-registrations.ts +2 -0
- package/src/lib/test-home-guard.ts +37 -9
- package/src/lib/windows-secret-acl.ts +49 -31
- package/src/lib/workflow-budget-config.ts +39 -0
- package/src/local-credentials/generation.ts +6 -2
- package/src/local-credentials/inventory.ts +132 -8
- package/src/messaging/mcp-queue-rpc.ts +102 -0
- package/src/messaging/mcp-queue-server.ts +42 -0
- package/src/messaging/mcp-queue-tools.ts +39 -0
- package/src/messaging/remote-forward-failure.ts +35 -0
- package/src/messaging/remote-ports.ts +27 -5
- package/src/messaging/remote-process.ts +30 -4
- package/src/messaging/remote-tunnels.ts +80 -15
- package/src/oauth/anthropic-identity.ts +2 -6
- package/src/oauth/antigravity-discovery-diagnostics.ts +65 -0
- package/src/oauth/google-antigravity.ts +23 -10
- package/src/oauth/index.ts +7 -0
- package/src/oauth/kiro-device-login.ts +87 -30
- package/src/oauth/kiro-iam-identity-center.ts +107 -0
- package/src/oauth/store.ts +9 -7
- package/src/providers/account-quota-disk.ts +18 -4
- package/src/providers/anthropic-subscription.ts +25 -0
- package/src/providers/cc-switch-import-bytes.ts +991 -0
- package/src/providers/cc-switch-import-source.ts +1083 -0
- package/src/providers/cc-switch-import.ts +942 -0
- package/src/providers/claude-cli-usage.ts +15 -67
- package/src/providers/derive.ts +6 -0
- package/src/providers/model-discovery-diagnostic.ts +4 -0
- package/src/providers/model-discovery.ts +4 -4
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/model-rename-migration.ts +41 -6
- package/src/providers/quota/anthropic-decision-windows.ts +5 -19
- package/src/providers/quota/anthropic-usage-windows.ts +55 -0
- package/src/providers/quota/report-cache.ts +17 -4
- package/src/providers/quota.ts +2 -2
- package/src/providers/reasoning-metadata.ts +31 -15
- package/src/providers/registry/entries-core.ts +1 -1
- package/src/providers/registry/entries-extended.ts +1 -1
- package/src/providers/registry/model-ids.ts +1 -0
- package/src/providers/registry/model-seeds.ts +2 -1
- package/src/providers/registry/types.ts +3 -1
- package/src/providers/resolved-model-policy.ts +2 -2
- package/src/providers/routed-config.ts +2 -0
- package/src/providers/stale-model-roster-migration.ts +5 -1
- package/src/providers/xai-transport.ts +4 -4
- package/src/remote-control/workspace-codex-runtime.ts +2 -2
- package/src/remote-control/workspace-executor.ts +14 -13
- package/src/responses/custom-tool-compat.ts +2 -1
- package/src/responses/item-provenance.ts +79 -0
- package/src/responses/namespace-tool-compat.ts +21 -3
- package/src/responses/parser-tools.ts +1 -0
- package/src/responses/schema.ts +5 -2
- package/src/router.ts +21 -2
- package/src/routing/analytics.ts +3 -5
- package/src/routing/fallback-policy.ts +7 -3
- package/src/routing/health.ts +5 -3
- package/src/routing/history/build-file.ts +6 -0
- package/src/routing/history/indexer.ts +158 -31
- package/src/routing/history/ingest.ts +1 -1
- package/src/routing/history/integrity.ts +208 -0
- package/src/routing/history/rebuild-job.ts +20 -6
- package/src/routing/history/rebuild-protocol.ts +2 -1
- package/src/routing/history/rebuild-worker.ts +18 -0
- package/src/routing/history/sqlite-errors.ts +9 -0
- package/src/server/admission-model-scope.ts +21 -4
- package/src/server/advisor-admission-scope.ts +29 -0
- package/src/server/audio-dictation.ts +3 -0
- package/src/server/audio-live.ts +8 -2
- package/src/server/audio-upstream.ts +2 -0
- package/src/server/auth-cors.ts +5 -2
- package/src/server/capture-admission-policy.ts +91 -0
- package/src/server/chat-completions.ts +33 -7
- package/src/server/claude-messages.ts +93 -2
- package/src/server/codex-model-list.ts +2 -1
- package/src/server/configured-credentials.ts +5 -0
- package/src/server/context-history.ts +9 -6
- package/src/server/images.ts +14 -5
- package/src/server/index/live-sideband.ts +16 -2
- package/src/server/index/serve-options.ts +13 -2
- package/src/server/index/websocket-handler.ts +4 -1
- package/src/server/live.ts +30 -5
- package/src/server/management/agent-settings-routes.ts +34 -9
- package/src/server/management/codex-agent-role-routes.ts +1 -0
- package/src/server/management/codex-role-auto-assign.ts +50 -6
- package/src/server/management/config-routes.ts +15 -4
- package/src/server/management/context.ts +3 -0
- package/src/server/management/native-integration-routes.ts +22 -0
- package/src/server/management/oauth-account-routes.ts +20 -4
- package/src/server/management/provider-overwrite-carry.ts +21 -0
- package/src/server/management/provider-routes.ts +3 -1
- package/src/server/management/route-registry.ts +2 -0
- package/src/server/management/shared.ts +17 -1
- package/src/server/management/workflow-budget-routes.ts +70 -3
- package/src/server/messages-native-eligibility.ts +6 -5
- package/src/server/messages-native-scope.ts +6 -1
- package/src/server/messages-shared.ts +57 -17
- package/src/server/persistent-gui-session.ts +4 -4
- package/src/server/request-log.ts +30 -2
- package/src/server/responses/adapter-delivery.ts +4 -0
- package/src/server/responses/adapter-dispatch.ts +5 -0
- package/src/server/responses/advisor-plan-slot.ts +4 -0
- package/src/server/responses/advisor-slot.ts +73 -46
- package/src/server/responses/codex-auth-error.ts +9 -1
- package/src/server/responses/combo-required-tool-contract.ts +39 -0
- package/src/server/responses/compact.ts +41 -20
- package/src/server/responses/core-codex-account.ts +17 -6
- package/src/server/responses/core-combo-failure.ts +2 -0
- package/src/server/responses/core-combo.ts +70 -5
- package/src/server/responses/core-lifetime.ts +4 -0
- package/src/server/responses/core-normalize.ts +7 -1
- package/src/server/responses/core-options.ts +9 -0
- package/src/server/responses/core.ts +2 -0
- package/src/server/responses/jev-model-invoke.ts +4 -2
- package/src/server/responses/passthrough-build-error.ts +36 -0
- package/src/server/responses/passthrough-dispatch.ts +10 -24
- package/src/server/responses/policy-fallback.ts +2 -0
- package/src/server/responses/request-prepare.ts +4 -5
- package/src/server/responses/request-send-budget.ts +2 -1
- package/src/server/responses/request-sidecar-auth.ts +4 -1
- package/src/server/responses/request-transport.ts +2 -3
- package/src/server/responses/run-turn-execution.ts +4 -0
- package/src/server/responses/sidecar-execution.ts +21 -5
- package/src/server/responses-snapshot-repair.ts +18 -4
- package/src/server/responses-undeclared-tool-guard.ts +4 -0
- package/src/server/search.ts +13 -4
- package/src/server/workflow-refusal.ts +2 -1
- package/src/server/ws-bridge.ts +5 -2
- package/src/service/state-lock.ts +12 -11
- package/src/service-manager-probe.ts +53 -8
- package/src/types/admission-policy.ts +13 -0
- package/src/types/config.ts +25 -0
- package/src/types/provider.ts +10 -0
- package/src/types/request.ts +7 -0
- package/src/types.ts +1 -0
- package/src/update/job.ts +20 -0
- package/src/update/worker-launch.ts +71 -1
- package/src/usage/log.ts +25 -4
- package/src/vision/describe.ts +4 -7
- package/src/vision/index.ts +2 -0
- package/src/vision/plan.ts +4 -0
- package/src/vision/routed-describe.ts +38 -23
- package/src/web-search/executor.ts +4 -7
- package/src/web-search/loop.ts +104 -9
- package/src/web-search/parse.ts +10 -2
- package/gui/dist/assets/App-DMps4OLk.css +0 -1
- package/gui/dist/assets/App-DmvwlhQq.js +0 -58
- package/gui/dist/assets/index-3EPO_KbX.js +0 -94
- package/gui/dist/assets/quota-summary-BHvWg9mi.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { journalOwner } from "../codex/journal";
|
|
2
|
-
import { diagnoseCodexShim,
|
|
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" ?
|
|
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,
|
|
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,
|
|
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
|
+
}
|
|
@@ -92,6 +92,7 @@ function isCredential(value: unknown): value is CodexAccountCredentials {
|
|
|
92
92
|
&& typeof value.refreshToken === "string"
|
|
93
93
|
&& typeof value.expiresAt === "number"
|
|
94
94
|
&& typeof value.chatgptAccountId === "string"
|
|
95
|
+
&& value.chatgptAccountId.trim().length > 0
|
|
95
96
|
&& (hasNoSource || hasCompleteSource);
|
|
96
97
|
}
|
|
97
98
|
|
|
@@ -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 {
|
|
41
|
-
const outcome =
|
|
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,
|
|
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 =
|
|
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,
|
|
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 {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { OcxProviderConfig } from "../types";
|
|
2
|
+
|
|
3
|
+
export type OcxRuntimeProviderConfig = OcxProviderConfig & {
|
|
4
|
+
_codexAccountOverride?: { accessToken: string; chatgptAccountId: string; kind?: "pool" | "main-pool" };
|
|
5
|
+
_codexAccountRequired?: boolean;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function stripCodexRuntimeProviderFields(provider: OcxProviderConfig): OcxProviderConfig {
|
|
9
|
+
const {
|
|
10
|
+
_codexAccountOverride: _override,
|
|
11
|
+
_codexAccountRequired: _required,
|
|
12
|
+
...safeProvider
|
|
13
|
+
} = provider as OcxRuntimeProviderConfig;
|
|
14
|
+
return safeProvider;
|
|
15
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { OcxRuntimeProviderConfig } from "./auth-context-provider";
|
|
2
|
+
export type { OcxRuntimeProviderConfig } from "./auth-context-provider";
|
|
3
|
+
export { stripCodexRuntimeProviderFields } from "./auth-context-provider";
|
|
1
4
|
import { bindPoolCreditPolicy, poolCreditHoldResetAt, poolContextCreditHoldResetAt, poolCreditRecoveryNeeded, poolContextCreditRecoveryNeeded, poolCreditRecoveryRetryAt } from "./pool-credit-policy";
|
|
2
5
|
import { hasSpendableCodexCredits } from "./quota-types";
|
|
3
6
|
import { nextQuotaQueryDelay } from "./quota-query-backoff";
|
|
@@ -322,8 +325,7 @@ export type CodexAuthContext =
|
|
|
322
325
|
transientProbe?: TransientProbeGrant;
|
|
323
326
|
}
|
|
324
327
|
| {
|
|
325
|
-
// Main
|
|
326
|
-
// (Option A). Distinct from "main" (request-owned passthrough or Direct mode).
|
|
328
|
+
// Main account rotating in the Pool (Option A), token from ~/.codex/auth.json; never request-owned "main".
|
|
327
329
|
kind: "main-pool";
|
|
328
330
|
accountId: string;
|
|
329
331
|
writerGeneration: number;
|
|
@@ -336,14 +338,14 @@ export type CodexAuthContext =
|
|
|
336
338
|
chatgptAccountId: string;
|
|
337
339
|
/** Bypass Pool selection and suppress quota/transient failover for an exact selector. */
|
|
338
340
|
fixedAccount?: boolean;
|
|
339
|
-
|
|
340
|
-
affinityKey?: string;
|
|
341
|
+
affinityKey?: string; // See `pool.affinityKey`.
|
|
341
342
|
/** See `pool.probeLeaseId`. */
|
|
342
343
|
probeLeaseId?: string;
|
|
343
344
|
quotaScope?: CodexQuotaScope;
|
|
344
345
|
probeQuotaScope?: CodexQuotaScope;
|
|
345
346
|
/** See `pool.transientProbe`. */
|
|
346
347
|
transientProbe?: TransientProbeGrant;
|
|
348
|
+
affinityDecision?: CodexAffinityDecision;
|
|
347
349
|
};
|
|
348
350
|
|
|
349
351
|
/** Probe lease carried by this context, when it holds one. */
|
|
@@ -379,11 +381,6 @@ export function releaseCodexAuthContextProbeLease(ctx: CodexAuthContext | undefi
|
|
|
379
381
|
else releaseCodexQuotaProbeLease(ctx.accountId!, leaseId);
|
|
380
382
|
}
|
|
381
383
|
|
|
382
|
-
export type OcxRuntimeProviderConfig = OcxProviderConfig & {
|
|
383
|
-
_codexAccountOverride?: { accessToken: string; chatgptAccountId: string };
|
|
384
|
-
_codexAccountRequired?: boolean;
|
|
385
|
-
};
|
|
386
|
-
|
|
387
384
|
export class CodexAuthContextError extends Error {
|
|
388
385
|
accountId: string;
|
|
389
386
|
|
|
@@ -1733,6 +1730,7 @@ async function resolveCodexAuthContextUnannotated(
|
|
|
1733
1730
|
...(quotaScope ? { quotaScope } : {}),
|
|
1734
1731
|
...(probeLeaseId ? { probeLeaseId } : {}),
|
|
1735
1732
|
...(probeQuotaScope ? { probeQuotaScope } : {}),
|
|
1733
|
+
...(affinityDecision ? { affinityDecision } : {}),
|
|
1736
1734
|
...(transientProbe ? { transientProbe } : {}),
|
|
1737
1735
|
};
|
|
1738
1736
|
}
|
|
@@ -1795,6 +1793,7 @@ export function applyCodexAuthContextToProvider(
|
|
|
1795
1793
|
_codexAccountOverride: {
|
|
1796
1794
|
accessToken: ctx.accessToken,
|
|
1797
1795
|
chatgptAccountId: ctx.chatgptAccountId,
|
|
1796
|
+
kind: ctx.kind,
|
|
1798
1797
|
},
|
|
1799
1798
|
_codexAccountRequired: true,
|
|
1800
1799
|
};
|
|
@@ -1840,14 +1839,15 @@ export function materializeCodexUpstreamAuth(
|
|
|
1840
1839
|
const selected = new Headers();
|
|
1841
1840
|
for (const name of FORWARD_HEADERS) {
|
|
1842
1841
|
const value = headers.get(name);
|
|
1843
|
-
if (value) selected.set(name, value);
|
|
1842
|
+
if (value || (value !== null && (name === "x-codex-installation-id" || name === "x-codex-turn-metadata"))) selected.set(name, value);
|
|
1844
1843
|
}
|
|
1845
1844
|
if (ctx.kind === "pool" || ctx.kind === "main-pool") {
|
|
1846
1845
|
assertCodexAccountValidationReady(ctx.accountId);
|
|
1847
1846
|
if (ctx.kind === "pool") assertPoolAccountCredits(ctx.accountId, poolContextCreditHoldResetAt(ctx, options.config), poolContextCreditRecoveryNeeded(ctx, options.config), ctx.quotaScope);
|
|
1848
1847
|
selected.set("authorization", `Bearer ${ctx.accessToken}`);
|
|
1849
1848
|
selected.set("chatgpt-account-id", ctx.chatgptAccountId);
|
|
1850
|
-
isolateCodexPoolAccountHeaders(selected, ctx.chatgptAccountId);
|
|
1849
|
+
if (ctx.kind === "pool") isolateCodexPoolAccountHeaders(selected, ctx.chatgptAccountId);
|
|
1850
|
+
else selected.delete("x-oai-attestation");
|
|
1851
1851
|
if (ctx.kind === "main-pool") {
|
|
1852
1852
|
ctx.mainQuotaWriter = observeSelectedMainCredential(ctx, ctx.mainQuotaWriter);
|
|
1853
1853
|
assertMainAccountPolicy(options.config);
|
|
@@ -1878,7 +1878,7 @@ export function materializeCodexUpstreamAuth(
|
|
|
1878
1878
|
selected.delete("chatgpt-account-id");
|
|
1879
1879
|
selected.set("authorization", `Bearer ${stored.accessToken}`);
|
|
1880
1880
|
if (stored.chatgptAccountId) selected.set("chatgpt-account-id", stored.chatgptAccountId);
|
|
1881
|
-
|
|
1881
|
+
selected.delete("x-oai-attestation");
|
|
1882
1882
|
observeSelectedMainCredential(stored, writer);
|
|
1883
1883
|
assertMainAccountPolicy(options.config);
|
|
1884
1884
|
assertMaterializedReserve(selected, ctx, options);
|
|
@@ -1949,7 +1949,7 @@ export async function materializeCodexUpstreamAuthAsync(
|
|
|
1949
1949
|
const selected = new Headers();
|
|
1950
1950
|
for (const name of FORWARD_HEADERS) {
|
|
1951
1951
|
const value = headers.get(name);
|
|
1952
|
-
if (value) selected.set(name, value);
|
|
1952
|
+
if (value || (value !== null && (name === "x-codex-installation-id" || name === "x-codex-turn-metadata"))) selected.set(name, value);
|
|
1953
1953
|
}
|
|
1954
1954
|
if (options.config !== undefined && isMainAccountHardLockEnabled(options.config)) {
|
|
1955
1955
|
reconcileMainCodexAccountRuntimeState();
|
|
@@ -1963,7 +1963,7 @@ export async function materializeCodexUpstreamAuthAsync(
|
|
|
1963
1963
|
selected.delete("chatgpt-account-id");
|
|
1964
1964
|
selected.set("authorization", `Bearer ${stored.accessToken}`);
|
|
1965
1965
|
if (stored.chatgptAccountId) selected.set("chatgpt-account-id", stored.chatgptAccountId);
|
|
1966
|
-
|
|
1966
|
+
selected.delete("x-oai-attestation");
|
|
1967
1967
|
observeSelectedMainCredential(stored, writer);
|
|
1968
1968
|
assertMainAccountPolicy(options.config);
|
|
1969
1969
|
// An opt-in enabled during token refresh must not turn a proof-less context into Reserve.
|
|
@@ -1988,12 +1988,3 @@ export function isCodexAuthContextUsable(ctx: CodexAuthContext, config: OcxConfi
|
|
|
1988
1988
|
if (ctx.kind === "main-pool") return isCodexAccountUsable(config, ctx.accountId);
|
|
1989
1989
|
return isCodexAccountUsable(config, ctx.accountId) && isCodexAccountGenerationLive(ctx.accountId, ctx.generation);
|
|
1990
1990
|
}
|
|
1991
|
-
|
|
1992
|
-
export function stripCodexRuntimeProviderFields(provider: OcxProviderConfig): OcxProviderConfig {
|
|
1993
|
-
const {
|
|
1994
|
-
_codexAccountOverride: _override,
|
|
1995
|
-
_codexAccountRequired: _required,
|
|
1996
|
-
...safeProvider
|
|
1997
|
-
} = provider as OcxRuntimeProviderConfig;
|
|
1998
|
-
return safeProvider;
|
|
1999
|
-
}
|
|
@@ -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) =>
|
|
733
|
-
|
|
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
|
|
122
|
-
*
|
|
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
|
-
) ??
|
|
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
|
|
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:
|
|
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 ===
|
|
46
|
-
&& stat.uid === process.getuid?.() && (stat.mode &
|
|
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:
|
|
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.
|
|
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:
|
|
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 !==
|
|
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 !==
|
|
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;
|