@bitkyc08/opencodex 2.100.3 → 2.100.5-preview.20261118.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS_INSTALL.md +23 -1
- package/bin/ocx.mjs +8 -1
- package/gui/dist/assets/{App-Dnb6VMsP.js → App-BiOGtxDS.js} +21 -20
- package/gui/dist/assets/{Tray-BV4ms9U9.js → Tray-BwsMejUO.js} +1 -1
- package/gui/dist/assets/brand-mark-BY1dgACL.js +1 -0
- package/gui/dist/assets/{index-DCdXsMyZ.js → index-CwHSKMdG.js} +46 -13
- package/gui/dist/assets/index-DJxM-imn.css +2 -0
- package/gui/dist/assets/{segment-thumb-features-DXSidY6D.js → segment-thumb-features-Bds9Hb_7.js} +1 -1
- package/gui/dist/classic/assets/{App-DA-scMPq.js → App-CGLOiqQL.js} +20 -19
- package/gui/dist/classic/assets/{Tray-BrHaVRAq.js → Tray-Da4r2O70.js} +1 -1
- package/gui/dist/classic/assets/{index-BqOaGLf5.js → index-CvoKXKL9.js} +46 -13
- package/gui/dist/classic/assets/quota-summary-DvqzfCmr.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/src/cli.rs +5 -3
- package/native/ocx-child/src/codex_home.rs +1 -0
- package/native/ocx-child/src/link_ws.rs +24 -19
- package/native/ocx-child/src/link_ws_frame.rs +136 -50
- package/package.json +3 -3
- package/src/adapters/anthropic/per-message-effort.ts +296 -0
- package/src/adapters/anthropic-input-schema.ts +270 -0
- package/src/adapters/anthropic.ts +4 -63
- package/src/adapters/claude-cli/adapter.ts +1 -0
- package/src/adapters/command-code-tool-text.ts +9 -1
- package/src/adapters/command-code.ts +18 -2
- package/src/adapters/devin/cloud-direct/chat.ts +95 -14
- package/src/adapters/devin/live-models.ts +11 -1
- package/src/adapters/google-errors.ts +14 -2
- package/src/adapters/kiro/reasoning.ts +3 -0
- package/src/adapters/kiro-tools.ts +14 -9
- package/src/adapters/openai-responses/passthrough.ts +3 -1
- package/src/adapters/openai-responses/request-strips.ts +1 -0
- package/src/adapters/qoder/adapter.ts +9 -1
- package/src/adapters/tool-catalog-nudge.ts +1 -1
- package/src/adapters/zed.ts +4 -2
- package/src/claude/chat-tool-dispatch.ts +4 -1
- package/src/claude/desktop-remote-store.ts +60 -10
- package/src/cli/account-api.ts +4 -0
- package/src/cli/account-auth.ts +30 -2
- package/src/cli/account-extended.ts +33 -2
- package/src/cli/capabilities-access-remote.ts +3 -3
- package/src/cli/capabilities-accounts.ts +3 -3
- package/src/cli/capabilities-base.ts +11 -6
- package/src/cli/capabilities-observe-system.ts +2 -2
- package/src/cli/claude.ts +3 -3
- package/src/cli/disconnect-runtime.ts +16 -6
- package/src/cli/dispatch.ts +7 -1
- package/src/cli/index.ts +2 -2
- package/src/cli/link-apply-restart.ts +4 -2
- package/src/cli/link-routes.ts +4 -1
- package/src/cli/link.ts +5 -4
- package/src/cli/logout-command.ts +23 -4
- package/src/cli/preflight-exemptions.ts +3 -0
- package/src/cli/provider.ts +3 -2
- package/src/cli/registry.ts +5 -2
- package/src/cli/resolve.ts +23 -8
- package/src/cli/restart-failure.ts +11 -1
- package/src/cli/runtime-api.ts +4 -0
- package/src/cli/status.ts +4 -1
- package/src/cli/system-command.ts +1 -1
- package/src/cli/system-restart-client.ts +9 -3
- package/src/cli/system-settings-parity.ts +2 -1
- package/src/client/connect.ts +73 -11
- package/src/client/desktop-refusal.ts +38 -0
- package/src/client/lifecycle-lock.ts +29 -4
- package/src/client/runtime-restart.ts +27 -15
- package/src/client/runtime.ts +4 -2
- package/src/client/state.ts +14 -0
- package/src/clients/config-export.ts +12 -7
- package/src/codex/account-lifecycle.ts +3 -1
- package/src/codex/account-pause.ts +4 -0
- package/src/codex/account-runtime-state.ts +4 -0
- package/src/codex/auth-api/main-account-probe.ts +3 -1
- package/src/codex/auth-api/main-hard-lock-refusal-read.ts +172 -0
- package/src/codex/auth-context.ts +40 -2
- package/src/codex/catalog/build-entries.ts +10 -0
- package/src/codex/catalog/derive-entry.ts +7 -0
- package/src/codex/catalog/metadata.ts +8 -0
- package/src/codex/catalog/native-models.ts +16 -6
- package/src/codex/catalog/pinned-models.ts +1 -0
- package/src/codex/catalog/provider-models.ts +5 -5
- package/src/codex/catalog/reserve-warn.ts +7 -5
- package/src/codex/catalog/reserve.ts +4 -3
- package/src/codex/catalog/retained-sync.ts +2 -0
- package/src/codex/catalog/routed-defaults.ts +35 -0
- package/src/codex/catalog-auto-refresh.ts +13 -2
- package/src/codex/config-drift-heal.ts +40 -12
- package/src/codex/config-write-lock.ts +39 -1
- package/src/codex/convergence.ts +2 -0
- package/src/codex/data/roster-pinned-models.json +346 -1
- package/src/codex/inject/config-write-section.ts +39 -1
- package/src/codex/inject/plan.ts +10 -8
- package/src/codex/inject/remove.ts +21 -19
- package/src/codex/inject/restore.ts +5 -1
- package/src/codex/inject-coordination.ts +58 -7
- package/src/codex/inject.ts +10 -12
- package/src/codex/journal-config-restore.ts +42 -0
- package/src/codex/journal.ts +62 -8
- package/src/codex/loopback-target.ts +22 -8
- package/src/codex/main-account.ts +94 -30
- package/src/codex/native-main-auth-file.ts +14 -0
- package/src/codex/native-main-credentials.ts +276 -0
- package/src/codex/native-main-owner.ts +3 -0
- package/src/codex/native-main-refresh-mode.ts +14 -1
- package/src/codex/quota.ts +63 -14
- package/src/combos/failover.ts +195 -1
- package/src/combos/index.ts +5 -0
- package/src/combos/resolve.ts +115 -19
- package/src/config/diagnostics.ts +3 -0
- package/src/config/live-reconcile.ts +6 -3
- package/src/config/load-degrade.ts +2 -0
- package/src/config/persisted-mutation.ts +2 -2
- package/src/config/persisted-projections.ts +18 -0
- package/src/config/process-state.ts +4 -3
- package/src/config/reserve-capability.ts +96 -0
- package/src/config/schema/config-schema.ts +6 -0
- package/src/config/schema/leaf-validators.ts +2 -0
- package/src/config/schema/routed-catalog-defaults.ts +49 -0
- package/src/config/subagent-models.ts +20 -12
- package/src/config.ts +7 -7
- package/src/desktop-update/acquire.ts +202 -0
- package/src/desktop-update/cli.ts +168 -0
- package/src/desktop-update/drain.ts +40 -0
- package/src/desktop-update/headless.ts +285 -0
- package/src/desktop-update/image.ts +85 -0
- package/src/desktop-update/install.ts +53 -0
- package/src/desktop-update/msi.ts +72 -0
- package/src/desktop-update/release.ts +128 -0
- package/src/desktop-update/runtime.ts +155 -0
- package/src/desktop-update/staging.ts +118 -0
- package/src/desktop-update/trust.ts +45 -0
- package/src/generated/compatibility-version.json +327 -195
- package/src/generated/model-metadata.ts +3 -3
- package/src/images/fulfill-video.ts +3 -3
- package/src/images/loop.ts +6 -2
- package/src/images/plan.ts +147 -11
- package/src/images/types.ts +13 -4
- package/src/images/xai-video-client.ts +72 -10
- package/src/lib/client-error-body.ts +6 -0
- package/src/lib/developer-role-rejection.ts +15 -0
- package/src/lib/gcp-adc.ts +48 -4
- package/src/lib/offline-resend.ts +150 -0
- package/src/lib/paced-stream.ts +3 -3
- package/src/lib/provider-outbound.ts +17 -6
- package/src/lib/request-failure-model.ts +2 -0
- package/src/lib/response-body-inactivity.ts +23 -1
- package/src/lib/upstream-retry.ts +39 -6
- package/src/link/explicit-route.ts +4 -4
- package/src/link/remote-windows.ts +79 -31
- package/src/link/residual-recovery.ts +20 -8
- package/src/messaging/budget.ts +23 -5
- package/src/messaging/remote-ports.ts +22 -10
- package/src/messaging/rpc.ts +4 -4
- package/src/oauth/antigravity-risk.ts +126 -0
- package/src/oauth/credential-siblings.ts +32 -0
- package/src/oauth/generic-account-failover.ts +113 -30
- package/src/oauth/generic-session-affinity.ts +10 -3
- package/src/oauth/index.ts +22 -14
- package/src/oauth/login-cli.ts +35 -1
- package/src/oauth/pool-kernel.ts +3 -3
- package/src/oauth/store.ts +38 -7
- package/src/providers/anthropic-billing-refusal.ts +27 -3
- package/src/providers/anthropic-reset-grants.ts +4 -0
- package/src/providers/claude-cli-usage.ts +2 -0
- package/src/providers/codebuddy-models.ts +11 -0
- package/src/providers/google-vertex-model-discovery.ts +49 -15
- package/src/providers/kiro-models.ts +5 -0
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/quota/workbuddy.ts +6 -2
- package/src/providers/registry/entries-core.ts +9 -3
- package/src/providers/registry/entries-extended.ts +20 -9
- package/src/providers/registry/model-seeds.ts +4 -1
- package/src/providers/stale-context-window-migration.ts +2 -0
- package/src/providers/workbuddy-credit-balance.ts +125 -16
- package/src/responses/citation-markers.ts +26 -23
- package/src/responses/effort-history.ts +732 -0
- package/src/routing/history/integrity.ts +41 -4
- package/src/server/auth-cors.ts +13 -3
- package/src/server/codex-model-list.ts +2 -1
- package/src/server/direct-local-http.ts +26 -3
- package/src/server/index/link-listener.ts +20 -14
- package/src/server/index/serve-options.ts +1 -0
- package/src/server/index.ts +3 -2
- package/src/server/link-turn.ts +17 -5
- package/src/server/management/config-routes.ts +39 -3
- package/src/server/management/link-child-preflight.ts +1 -1
- package/src/server/management/link-enrollment.ts +3 -3
- package/src/server/management/link-route-edit.ts +20 -1
- package/src/server/management/link-route-request.ts +11 -5
- package/src/server/management/oauth-account-routes.ts +43 -13
- package/src/server/management/provider-credential-release.ts +44 -0
- package/src/server/management/provider-overwrite-carry.ts +3 -0
- package/src/server/management/provider-routes.ts +12 -12
- package/src/server/management/static-catalog-probe.ts +33 -0
- package/src/server/management/usage-aggregate-cache.ts +6 -3
- package/src/server/messages-native.ts +16 -2
- package/src/server/proxy-liveness.ts +54 -9
- package/src/server/relay.ts +6 -1
- package/src/server/request-log-conversation.ts +8 -4
- package/src/server/request-log-failure-detail.ts +26 -9
- package/src/server/request-log.ts +5 -1
- package/src/server/reserve-capability-startup.ts +32 -0
- package/src/server/responses/adapter-continuation.ts +59 -25
- package/src/server/responses/adapter-delivery.ts +2 -0
- package/src/server/responses/adapter-dispatch.ts +39 -18
- package/src/server/responses/antigravity-fault-rotation.ts +24 -0
- package/src/server/responses/antigravity-validation-refusal.ts +43 -6
- package/src/server/responses/codex-tool-catalog.ts +47 -10
- package/src/server/responses/combo-selection-keepalive.ts +254 -0
- package/src/server/responses/combo-session-recall.ts +26 -1
- package/src/server/responses/combo-stream-preflight.ts +35 -26
- package/src/server/responses/core-combo-failure.ts +6 -0
- package/src/server/responses/core-combo-native.ts +2 -1
- package/src/server/responses/core-combo.ts +67 -28
- package/src/server/responses/core-errors.ts +9 -6
- package/src/server/responses/core-options.ts +10 -0
- package/src/server/responses/core.ts +21 -0
- package/src/server/responses/estimated-usage.ts +115 -0
- package/src/server/responses/input-admission.ts +41 -3
- package/src/server/responses/jev-model-invoke.ts +7 -2
- package/src/server/responses/passthrough-completion.ts +6 -3
- package/src/server/responses/passthrough-delivery.ts +47 -8
- package/src/server/responses/passthrough-dispatch.ts +3 -0
- package/src/server/responses/request-prepare.ts +9 -5
- package/src/server/responses/request-send-budget.ts +1 -1
- package/src/server/responses/request-transport.ts +10 -2
- package/src/server/responses/sidecar-execution.ts +11 -4
- package/src/service/desktop-supervision.d.mts +2 -0
- package/src/service/desktop-supervision.mjs +5 -0
- package/src/service/windows-checked-stop-live.ts +28 -5
- package/src/stall-timeout.ts +11 -0
- package/src/types/config.ts +15 -92
- package/src/types/provider.ts +13 -0
- package/src/types/request.ts +23 -3
- package/src/types/routed-catalog-defaults.ts +17 -0
- package/src/types/routing-profile.ts +90 -0
- package/src/types.ts +1 -0
- package/src/update/index.ts +1 -1
- package/src/usage/expected-prices.ts +35 -0
- package/src/usage/ledger-scanner.ts +44 -10
- package/src/usage/log.ts +14 -4
- package/src/usage/telemetry-contract.ts +1 -0
- package/src/web-search/loop.ts +20 -2
- package/src/web-search/parse.ts +2 -12
- package/src/web-search/passthrough-bridge.ts +7 -0
- package/src/web-search/sources.ts +13 -0
- package/gui/dist/assets/brand-mark-XOLJbomA.js +0 -1
- package/gui/dist/assets/index-DQtCRNAw.css +0 -2
- package/gui/dist/classic/assets/quota-summary-Dy5_wfTT.js +0 -1
|
@@ -5,6 +5,7 @@ import { join } from "node:path";
|
|
|
5
5
|
import { compactionRecoveryConfigError } from "./schema/compaction-recovery";
|
|
6
6
|
import { nativeReasoningRetentionConfigError } from "./schema/native-reasoning-retention";
|
|
7
7
|
import { workflowBudgetConfigError } from "./schema/workflow-budget";
|
|
8
|
+
import { routedCatalogDefaultsConfigError } from "./schema/routed-catalog-defaults";
|
|
8
9
|
import { desktopCompatibilityConfigError } from "./schema/desktop-compatibility";
|
|
9
10
|
import { blockedModelRedirectsError } from "./schema/blocked-model-redirects";
|
|
10
11
|
import { mainAccountHardLockFallbackError } from "./schema/main-account-hard-lock-fallback";
|
|
@@ -141,6 +142,7 @@ export function warnDegradedCompactionRouting(rawParsed: unknown, validated: Ocx
|
|
|
141
142
|
export function warnDegradedTopLevelOptIns(rawParsed: unknown, validated: OcxConfig): void {
|
|
142
143
|
if (nativeReasoningRetentionConfigError(rawParsed)) console.warn("⚠️ invalid nativeReasoningRetention disabled; model and account switch allowances remain off");
|
|
143
144
|
if (workflowBudgetConfigError(rawParsed)) console.warn("⚠️ invalid workflowBudget ignored; the built-in workflow ceilings stay in force");
|
|
145
|
+
if (routedCatalogDefaultsConfigError(rawParsed)) console.warn("⚠️ invalid routedCatalogDefaults ignored; routed catalog rows keep their derived values");
|
|
144
146
|
setCodexWsReuseAcrossTurns(validated.codexWsReuseAcrossTurns === true);
|
|
145
147
|
const retentionWarning = degradedReasoningRetentionWarning(rawParsed, validated);
|
|
146
148
|
if (retentionWarning) console.warn(retentionWarning);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OcxConfig } from "../types";
|
|
2
|
-
import {
|
|
2
|
+
import { projectPersistedConfigMigrations } from "./persisted-projections";
|
|
3
3
|
import { readConfigFileSnapshot, type ConfigFileSnapshot } from "./diagnostics";
|
|
4
4
|
import { bumpGenerationForCooperatingConfigWrite, withConfigMutationLockSync } from "./mutation-lock";
|
|
5
5
|
import { persistConfigUnlocked } from "./persist-unlocked";
|
|
@@ -89,7 +89,7 @@ export function mutatePersistedConfig<T>(
|
|
|
89
89
|
continue;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
const projected =
|
|
92
|
+
const projected = projectPersistedConfigMigrations(
|
|
93
93
|
commitBase.diagnostics.config,
|
|
94
94
|
projectConfigRebaseProvenance(confirmedConfig),
|
|
95
95
|
);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OcxConfig } from "../types";
|
|
2
|
+
import { adoptCustomModelCatalogMigration, projectCustomModelCatalogMigration } from "../codex/custom-model-catalog-migration";
|
|
3
|
+
import { adoptReserveCapabilityMigration, projectReserveCapabilityMigration } from "./reserve-capability";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Every one-time migration a whole-config write must carry, projected against the same pre-write
|
|
7
|
+
* document. Writers call this once instead of each migration separately, so a new migration cannot
|
|
8
|
+
* be wired into some write paths and silently missed by others.
|
|
9
|
+
*/
|
|
10
|
+
export function projectPersistedConfigMigrations(persisted: unknown, candidate: OcxConfig): OcxConfig {
|
|
11
|
+
return projectReserveCapabilityMigration(persisted, projectCustomModelCatalogMigration(persisted, candidate));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Copy the migration state a successful projected write established onto the live object. */
|
|
15
|
+
export function adoptPersistedConfigMigrations(target: OcxConfig, projected: OcxConfig): void {
|
|
16
|
+
adoptCustomModelCatalogMigration(target, projected);
|
|
17
|
+
adoptReserveCapabilityMigration(target, projected);
|
|
18
|
+
}
|
|
@@ -166,9 +166,10 @@ export type RuntimePortState = {
|
|
|
166
166
|
servingGeneration?: string;
|
|
167
167
|
/**
|
|
168
168
|
* The owner a client runtime classified from positive evidence (src/client/runtime-restart.ts
|
|
169
|
-
*
|
|
170
|
-
* runtimes older than this field; `ocx disconnect` restarts only a runtime whose
|
|
171
|
-
*
|
|
169
|
+
* recordedRestartOwner: desktop, service-manager or none), or legacy-flag for a bare OCX_SERVICE=1
|
|
170
|
+
* (#8545). Absent for runtimes older than this field; `ocx disconnect` restarts only a runtime whose
|
|
171
|
+
* record states a proven owner, and gives the re-register advice for legacy-flag. Any string is
|
|
172
|
+
* accepted here so a later value never invalidates the record.
|
|
172
173
|
*/
|
|
173
174
|
restartOwner?: string;
|
|
174
175
|
/**
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { OcxConfig } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Luna Reserve's own capability switch (#4961).
|
|
5
|
+
*
|
|
6
|
+
* Reserve used to ride `codexDesktopAuthless`, a flag documented as controlling whether the Codex app
|
|
7
|
+
* asks for a sign-in. It is now `codexReserveEnabled`, seeded once from that flag and independent of
|
|
8
|
+
* it afterwards. `codexReserveMigration` records that the seed happened.
|
|
9
|
+
*
|
|
10
|
+
* Until a document carries the marker, Reserve reads the legacy flag, which is exactly the value the
|
|
11
|
+
* migration persists. Startup records the seed for every unmarked file once, so after the first start
|
|
12
|
+
* on this version a hand edit of authless cannot move Reserve. Writers record it only when it matters:
|
|
13
|
+
* when a write changes authless (the seed then comes from the persisted pre-write document, so the
|
|
14
|
+
* change cannot move Reserve), when Reserve is set explicitly, or when a new document is created with
|
|
15
|
+
* authless on (new documents start disabled). Other writes leave an unmarked document byte-for-byte
|
|
16
|
+
* alone. Once the marker exists, an absent `codexReserveEnabled` means off, so deleting the field
|
|
17
|
+
* cannot bring the inheritance back.
|
|
18
|
+
*
|
|
19
|
+
* Enabling the capability never manufactures permission: every Reserve request still needs the
|
|
20
|
+
* upstream, credential-bound Reserve allowance, a non-client role and a loopback admission.
|
|
21
|
+
*/
|
|
22
|
+
export const RESERVE_CAPABILITY_MIGRATION_VERSION = 1;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The two Reserve fields. A live save always rebases them against disk, even when the live config and
|
|
26
|
+
* its baseline both omit them: after the marker an absent value reads as off, so skipping a value only
|
|
27
|
+
* another process wrote would silently turn Reserve off. Explicit live edits still win the merge.
|
|
28
|
+
*/
|
|
29
|
+
export const RESERVE_CAPABILITY_KEYS: readonly string[] = ["codexReserveEnabled", "codexReserveMigration"];
|
|
30
|
+
|
|
31
|
+
type ReserveCapabilityFields = Pick<OcxConfig, "codexReserveEnabled" | "codexReserveMigration" | "codexDesktopAuthless">;
|
|
32
|
+
|
|
33
|
+
function configRecord(value: unknown): Record<string, unknown> | undefined {
|
|
34
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function isMigratedMarker(value: unknown): value is number {
|
|
38
|
+
return typeof value === "number" && Number.isInteger(value) && value >= RESERVE_CAPABILITY_MIGRATION_VERSION;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function isReserveCapabilityMigrated(config: unknown): boolean {
|
|
42
|
+
return isMigratedMarker(configRecord(config)?.codexReserveMigration);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Whether the operator enabled Luna Reserve. Runtime role and listener admission are checked separately. */
|
|
46
|
+
export function isCodexReserveEnabled(config: Partial<ReserveCapabilityFields> | undefined): boolean {
|
|
47
|
+
if (!config) return false;
|
|
48
|
+
if (typeof config.codexReserveEnabled === "boolean") return config.codexReserveEnabled;
|
|
49
|
+
if (isMigratedMarker(config.codexReserveMigration)) return false;
|
|
50
|
+
return config.codexDesktopAuthless === true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Seed this document from its own legacy flag, in place. Returns whether anything changed. */
|
|
54
|
+
export function migrateReserveCapability(config: OcxConfig): boolean {
|
|
55
|
+
if (isMigratedMarker(config.codexReserveMigration)) return false;
|
|
56
|
+
if (typeof config.codexReserveEnabled !== "boolean") config.codexReserveEnabled = config.codexDesktopAuthless === true;
|
|
57
|
+
config.codexReserveMigration = RESERVE_CAPABILITY_MIGRATION_VERSION;
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Carry the migration onto a whole-config write. `persisted` is the document on disk before the
|
|
63
|
+
* write (undefined when none exists yet) and is the only authority for the legacy seed; a candidate
|
|
64
|
+
* without the marker is a snapshot taken before migration and never decides the seed itself.
|
|
65
|
+
*/
|
|
66
|
+
export function projectReserveCapabilityMigration(persisted: unknown, candidate: OcxConfig): OcxConfig {
|
|
67
|
+
if (isMigratedMarker(candidate.codexReserveMigration)) return candidate;
|
|
68
|
+
const prior = configRecord(persisted);
|
|
69
|
+
if (prior && isMigratedMarker(prior.codexReserveMigration)) {
|
|
70
|
+
const projected = { ...candidate };
|
|
71
|
+
if (typeof projected.codexReserveEnabled !== "boolean") {
|
|
72
|
+
if (typeof prior.codexReserveEnabled === "boolean") projected.codexReserveEnabled = prior.codexReserveEnabled;
|
|
73
|
+
else delete projected.codexReserveEnabled;
|
|
74
|
+
}
|
|
75
|
+
// Same key order as the seed below, so carrying an unchanged state rewrites identical bytes.
|
|
76
|
+
projected.codexReserveMigration = prior.codexReserveMigration;
|
|
77
|
+
return projected;
|
|
78
|
+
}
|
|
79
|
+
const explicit = typeof candidate.codexReserveEnabled === "boolean";
|
|
80
|
+
// A new document has no earlier authless value to carry: it starts disabled.
|
|
81
|
+
const legacy = prior ? prior.codexDesktopAuthless === true : false;
|
|
82
|
+
// Nothing to record while authless keeps its persisted value: the reading is unchanged.
|
|
83
|
+
if (!explicit && (candidate.codexDesktopAuthless === true) === legacy) return candidate;
|
|
84
|
+
const projected = { ...candidate };
|
|
85
|
+
if (!explicit) projected.codexReserveEnabled = legacy;
|
|
86
|
+
projected.codexReserveMigration = RESERVE_CAPABILITY_MIGRATION_VERSION;
|
|
87
|
+
return projected;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** After the projected write succeeds, the live object holds what was written. */
|
|
91
|
+
export function adoptReserveCapabilityMigration(target: OcxConfig, projected: OcxConfig): void {
|
|
92
|
+
if (projected.codexReserveMigration === undefined) delete target.codexReserveMigration;
|
|
93
|
+
else target.codexReserveMigration = projected.codexReserveMigration;
|
|
94
|
+
if (projected.codexReserveEnabled === undefined) delete target.codexReserveEnabled;
|
|
95
|
+
else target.codexReserveEnabled = projected.codexReserveEnabled;
|
|
96
|
+
}
|
|
@@ -8,6 +8,7 @@ import { anthropicAccountPoolSchema } from "./anthropic-account-pool";
|
|
|
8
8
|
import { compactionRecoverySchema } from "./compaction-recovery";
|
|
9
9
|
import { nativeReasoningRetentionSchema } from "./native-reasoning-retention";
|
|
10
10
|
import { workflowBudgetSchema } from "./workflow-budget";
|
|
11
|
+
import { routedCatalogDefaultsSchema } from "./routed-catalog-defaults";
|
|
11
12
|
import { desktopCompatibilitySchema } from "./desktop-compatibility";
|
|
12
13
|
import { blockedModelRedirectsSchema } from "./blocked-model-redirects";
|
|
13
14
|
import { mainAccountHardLockFallbackSchema } from "./main-account-hard-lock-fallback";
|
|
@@ -234,6 +235,8 @@ export const configSchema = z.object({
|
|
|
234
235
|
nativeReasoningRetention: nativeReasoningRetentionSchema.optional().catch(undefined),
|
|
235
236
|
// A bad hand edit falls back to the built-in ceilings; it never turns the guard off.
|
|
236
237
|
workflowBudget: workflowBudgetSchema.optional().catch(undefined),
|
|
238
|
+
// A bad hand edit drops the whole block, so routed rows keep today's derivation (#6872).
|
|
239
|
+
routedCatalogDefaults: routedCatalogDefaultsSchema.optional().catch(undefined),
|
|
237
240
|
desktopCompatibility: desktopCompatibilitySchema.optional().catch(undefined),
|
|
238
241
|
// A hand-edited malformed phase disables only that phase instead of rejecting
|
|
239
242
|
// providers/apiKeys, matching the load-time degradation notice; the management write
|
|
@@ -344,6 +347,9 @@ export const configSchema = z.object({
|
|
|
344
347
|
}).strict().optional().catch(undefined)),
|
|
345
348
|
codexShimAutoRestore: z.boolean().optional(),
|
|
346
349
|
codexDesktopAuthless: z.boolean().optional().catch(undefined),
|
|
350
|
+
codexReserveEnabled: z.boolean().optional().catch(undefined),
|
|
351
|
+
// A malformed marker degrades to unmigrated, which reseeds from the persisted authless flag.
|
|
352
|
+
codexReserveMigration: z.number().int().positive().optional().catch(undefined),
|
|
347
353
|
codexClientCompaction: z.boolean().optional().catch(undefined),
|
|
348
354
|
// Presentation-only label for the injected provider. A malformed value degrades to undefined
|
|
349
355
|
// and the default label is emitted, rather than failing the parse or writing a config Codex
|
|
@@ -458,8 +458,10 @@ export const providerConfigSchema = z.object({
|
|
|
458
458
|
}).strict().optional(),
|
|
459
459
|
responsesSnapshotRepair: z.boolean().optional(),
|
|
460
460
|
messagePhaseInference: z.boolean().optional(),
|
|
461
|
+
estimateMissingUsage: z.boolean().optional(),
|
|
461
462
|
hideRawReasoning: z.boolean().optional(),
|
|
462
463
|
forwardAdvisorTool: z.boolean().optional(),
|
|
464
|
+
perMessageEffort: z.boolean().optional(),
|
|
463
465
|
// Invalid blocks degrade to "absent" rather than failing the whole config load: an unusable
|
|
464
466
|
// bridge block must never send an operator through invalid-config recovery for an opt-in
|
|
465
467
|
// feature that is off by default. The management write boundary still rejects it loudly.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as z from "zod/v4";
|
|
2
|
+
import type { OcxConfig } from "../../types";
|
|
3
|
+
import type { OcxRoutedCatalogDefaultsConfig } from "../../types/routed-catalog-defaults";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Operator defaults for routed Codex catalog rows (#6872), stored as top-level
|
|
7
|
+
* `routedCatalogDefaults` in config.json.
|
|
8
|
+
*
|
|
9
|
+
* The allowlist is the owner's decision: the three `include_*_usage_instructions` prompt-block
|
|
10
|
+
* flags plus `default_verbosity`. Nothing else is accepted, because the
|
|
11
|
+
* neighbouring row fields (tool mode, search, truncation, auto review, identity) carry execution or
|
|
12
|
+
* protocol contracts that an operator default must not be able to undo. Every field is optional;
|
|
13
|
+
* an omitted field keeps today's derivation, and explicit `false` stays `false`.
|
|
14
|
+
*/
|
|
15
|
+
export const ROUTED_CATALOG_VERBOSITIES = ["low", "medium", "high"] as const;
|
|
16
|
+
|
|
17
|
+
export const routedCatalogDefaultsSchema = z.object({
|
|
18
|
+
includeSkillsUsageInstructions: z.boolean().optional(),
|
|
19
|
+
includeAppsUsageInstructions: z.boolean().optional(),
|
|
20
|
+
includePluginUsageInstructions: z.boolean().optional(),
|
|
21
|
+
defaultVerbosity: z.enum(ROUTED_CATALOG_VERBOSITIES).optional(),
|
|
22
|
+
}).strict() satisfies z.ZodType<OcxRoutedCatalogDefaultsConfig>;
|
|
23
|
+
|
|
24
|
+
export type RoutedCatalogDefaults = OcxRoutedCatalogDefaultsConfig;
|
|
25
|
+
|
|
26
|
+
export const ROUTED_CATALOG_DEFAULTS_SHAPE_HINT = "accepts only optional boolean includeSkillsUsageInstructions,"
|
|
27
|
+
+ " includeAppsUsageInstructions and includePluginUsageInstructions, and an optional"
|
|
28
|
+
+ " defaultVerbosity of \"low\", \"medium\" or \"high\"";
|
|
29
|
+
|
|
30
|
+
/** Write-boundary check; also drives the load-time and diagnostics warnings for a degraded block. */
|
|
31
|
+
export function routedCatalogDefaultsConfigError(value: unknown): string | null {
|
|
32
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
33
|
+
const block = (value as Record<string, unknown>).routedCatalogDefaults;
|
|
34
|
+
return block === undefined || routedCatalogDefaultsSchema.safeParse(block).success
|
|
35
|
+
? null : "schema_invalid: routedCatalogDefaults: " + ROUTED_CATALOG_DEFAULTS_SHAPE_HINT;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Capture the defaults once per catalog build. Catalog derivation receives this frozen snapshot as
|
|
40
|
+
* an input instead of reading mutable config while it derives rows. A malformed synthetic value
|
|
41
|
+
* resolves the same way as a degraded disk block, and an empty block is the same as no block.
|
|
42
|
+
*/
|
|
43
|
+
export function resolveRoutedCatalogDefaults(
|
|
44
|
+
config: Pick<OcxConfig, "routedCatalogDefaults">,
|
|
45
|
+
): Readonly<RoutedCatalogDefaults> | undefined {
|
|
46
|
+
const parsed = routedCatalogDefaultsSchema.safeParse(config.routedCatalogDefaults);
|
|
47
|
+
if (!parsed.success || Object.keys(parsed.data).length === 0) return undefined;
|
|
48
|
+
return Object.freeze({ ...parsed.data });
|
|
49
|
+
}
|
|
@@ -4,15 +4,17 @@ import {
|
|
|
4
4
|
NATIVE_GPT6_LUNA_MODEL,
|
|
5
5
|
NATIVE_GPT6_SOL_MODEL,
|
|
6
6
|
NATIVE_GPT61_SOL_MODEL,
|
|
7
|
+
NATIVE_GPT62_ASTRA_MODEL,
|
|
8
|
+
NATIVE_GPT62_SOL_MODEL,
|
|
7
9
|
} from "../codex/catalog/native-models";
|
|
8
10
|
|
|
9
|
-
export const SUBAGENT_MODELS_VERSION =
|
|
11
|
+
export const SUBAGENT_MODELS_VERSION = 4;
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
* Native featured defaults: Astra,
|
|
13
|
-
* five picker-visible rows.
|
|
14
|
+
* Native featured defaults: GPT-6.2 Astra, GPT-6.2 Sol and GPT-6 Luna. Codex advertises at most
|
|
15
|
+
* five picker-visible rows.
|
|
14
16
|
*/
|
|
15
|
-
export const DEFAULT_SUBAGENT_MODELS = [
|
|
17
|
+
export const DEFAULT_SUBAGENT_MODELS = [NATIVE_GPT62_ASTRA_MODEL, NATIVE_GPT62_SOL_MODEL, NATIVE_GPT6_LUNA_MODEL];
|
|
16
18
|
|
|
17
19
|
/** Bare native families the version-2 upgrade removes from a roster. */
|
|
18
20
|
const RETIRED_ROSTER_FAMILY = /^gpt-5\.[56](?:-|$)/;
|
|
@@ -45,13 +47,16 @@ function upgradeRetiredRosterRows(models: readonly string[]): string[] {
|
|
|
45
47
|
* moves; a routed or account-qualified id keeps its exact spelling. GPT-6 Sol stays a supported
|
|
46
48
|
* model, so a user who adds it back afterwards keeps it.
|
|
47
49
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
const ROSTER_V3_SUCCESSORS = new Map([[NATIVE_GPT6_SOL_MODEL, NATIVE_GPT61_SOL_MODEL]]);
|
|
51
|
+
|
|
52
|
+
// V4 replaces the prior bare defaults. Qualified targets and earlier user re-selections keep their ids.
|
|
53
|
+
const ROSTER_V4_SUCCESSORS = new Map([
|
|
54
|
+
[NATIVE_GPT6_ASTRA_MODEL, NATIVE_GPT62_ASTRA_MODEL],
|
|
55
|
+
[NATIVE_GPT61_SOL_MODEL, NATIVE_GPT62_SOL_MODEL],
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
function upgradeRosterRows(models: readonly string[], successors: ReadonlyMap<string, string>): string[] {
|
|
59
|
+
return [...new Set(models.map(model => successors.get(model) ?? model))];
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
/** One-time upgrades; later user edits (including removing Astra) remain authoritative. */
|
|
@@ -71,7 +76,10 @@ export function migrateSubagentModels(config: OcxConfig): boolean {
|
|
|
71
76
|
if (version < 2 && config.subagentModels !== undefined) {
|
|
72
77
|
config.subagentModels = upgradeRetiredRosterRows(config.subagentModels);
|
|
73
78
|
}
|
|
74
|
-
if (config.subagentModels !== undefined)
|
|
79
|
+
if (config.subagentModels !== undefined) {
|
|
80
|
+
if (version < 3) config.subagentModels = upgradeRosterRows(config.subagentModels, ROSTER_V3_SUCCESSORS);
|
|
81
|
+
config.subagentModels = upgradeRosterRows(config.subagentModels, ROSTER_V4_SUCCESSORS);
|
|
82
|
+
}
|
|
75
83
|
config.subagentModelsVersion = SUBAGENT_MODELS_VERSION;
|
|
76
84
|
return true;
|
|
77
85
|
}
|
package/src/config.ts
CHANGED
|
@@ -6,9 +6,9 @@ import { configReasoningPinsConfigError } from "./config/provider-validation";
|
|
|
6
6
|
import { recordOwnedConfigPath } from "./lib/config-ownership";
|
|
7
7
|
import { assertNotRealHomeUnderTest } from "./lib/test-home-guard";
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from "./
|
|
9
|
+
adoptPersistedConfigMigrations,
|
|
10
|
+
projectPersistedConfigMigrations,
|
|
11
|
+
} from "./config/persisted-projections";
|
|
12
12
|
import { refreshConfigDerivedRegistries } from "./config/derived-registries";
|
|
13
13
|
import {
|
|
14
14
|
clearPendingConfigDeletions,
|
|
@@ -355,7 +355,7 @@ export function initializePersistedConfigIfMissing(
|
|
|
355
355
|
const persisted = withConfigMutationLockSync((): OcxConfig | "exists" | "invalid" => {
|
|
356
356
|
const current = observeInitialConfigState();
|
|
357
357
|
if (current !== "missing") return current;
|
|
358
|
-
const projected =
|
|
358
|
+
const projected = projectPersistedConfigMigrations(undefined, projectConfigRebaseProvenance(config));
|
|
359
359
|
normalizeAccountAutoPauseRevisions(undefined, projected);
|
|
360
360
|
// Creating config.json never introduces a telemetry decision: one made before the file existed
|
|
361
361
|
// is held in telemetry-state.json, where another process may have replaced it (see
|
|
@@ -372,7 +372,7 @@ export function initializePersistedConfigIfMissing(
|
|
|
372
372
|
return projected;
|
|
373
373
|
});
|
|
374
374
|
if (typeof persisted === "string") return persisted;
|
|
375
|
-
|
|
375
|
+
adoptPersistedConfigMigrations(config, persisted);
|
|
376
376
|
if (telemetry?.carried) adoptPersistedTelemetry(config, telemetry.value);
|
|
377
377
|
if (persisted.configRebaseProvenance === undefined) delete config.configRebaseProvenance;
|
|
378
378
|
else config.configRebaseProvenance = structuredClone(persisted.configRebaseProvenance);
|
|
@@ -393,14 +393,14 @@ export function saveConfig(config: OcxConfig): void {
|
|
|
393
393
|
assertNotRealHomeUnderTest(getConfigDir());
|
|
394
394
|
withConfigMutationLockSync(() => {
|
|
395
395
|
const onDisk = readRawConfigJson();
|
|
396
|
-
const withProvenance =
|
|
396
|
+
const withProvenance = projectPersistedConfigMigrations(
|
|
397
397
|
onDisk,
|
|
398
398
|
projectConfigRebaseProvenance(config),
|
|
399
399
|
);
|
|
400
400
|
// Telemetry consent is owned by the file, as in the live save (see carryPersistedTelemetry).
|
|
401
401
|
const telemetry = carryPersistedTelemetry(withProvenance, onDisk);
|
|
402
402
|
if (persistConfigUnlocked(withProvenance)) bumpGenerationForCooperatingConfigWrite();
|
|
403
|
-
|
|
403
|
+
adoptPersistedConfigMigrations(config, withProvenance);
|
|
404
404
|
if (telemetry.carried) adoptPersistedTelemetry(config, telemetry.value);
|
|
405
405
|
if (withProvenance.configRebaseProvenance === undefined) delete config.configRebaseProvenance;
|
|
406
406
|
else config.configRebaseProvenance = structuredClone(withProvenance.configRebaseProvenance);
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded HTTPS acquisition for the headless Desktop updater (#8246).
|
|
3
|
+
*
|
|
4
|
+
* The contract is the acquisition rule in devlog/_plan/261107_auto_update_parity/030_desktop_engine.md:
|
|
5
|
+
* HTTPS only, the exact lidge-jun/opencodex release source, at most three redirects to the
|
|
6
|
+
* listed GitHub asset hosts, no userinfo or non-default port, no credentials, a size cap counted
|
|
7
|
+
* before each chunk is kept, and connect, idle-read and total deadlines. A Content-Length header
|
|
8
|
+
* is advisory: it can refuse early but never raises the bound. The transport and the timers are
|
|
9
|
+
* injected so tests drive every hop and deadline without a network or a sleep; a loopback mock is
|
|
10
|
+
* reachable only through that injected transport, never through a production setting.
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
DESKTOP_ACQUIRE_LIMITS,
|
|
14
|
+
DESKTOP_REDIRECT_HOSTS,
|
|
15
|
+
DESKTOP_RELEASE_PATH_PREFIX,
|
|
16
|
+
} from "./trust";
|
|
17
|
+
|
|
18
|
+
export type DesktopAcquireErrorCode =
|
|
19
|
+
| "url_refused"
|
|
20
|
+
| "redirect_refused"
|
|
21
|
+
| "too_many_redirects"
|
|
22
|
+
| "http_status"
|
|
23
|
+
| "connect_timeout"
|
|
24
|
+
| "idle_timeout"
|
|
25
|
+
| "total_timeout"
|
|
26
|
+
| "oversize"
|
|
27
|
+
| "truncated"
|
|
28
|
+
| "transport";
|
|
29
|
+
|
|
30
|
+
export class DesktopAcquireError extends Error {
|
|
31
|
+
constructor(readonly code: DesktopAcquireErrorCode, readonly retryable: boolean, message: string) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "DesktopAcquireError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface AcquireResponse {
|
|
38
|
+
status: number;
|
|
39
|
+
headers: { get(name: string): string | null };
|
|
40
|
+
body: AsyncIterable<Uint8Array> | null;
|
|
41
|
+
/** Release the connection of a response that is not read to the end. */
|
|
42
|
+
cancel?: () => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface AcquireTransport {
|
|
46
|
+
request(url: string, signal: AbortSignal): Promise<AcquireResponse>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface AcquireTimers {
|
|
50
|
+
/** Run `fire` once after `ms`; the returned function cancels it. */
|
|
51
|
+
schedule(ms: number, fire: () => void): () => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface AcquireLimits {
|
|
55
|
+
maxBytes: number;
|
|
56
|
+
maxRedirects?: number;
|
|
57
|
+
connectMs?: number;
|
|
58
|
+
idleReadMs?: number;
|
|
59
|
+
totalMs?: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Admit one hop. The first request must name the exact release source on github.com; a redirect
|
|
66
|
+
* may move to a listed asset host, and a redirect back to github.com stays inside the same
|
|
67
|
+
* repository's releases.
|
|
68
|
+
*/
|
|
69
|
+
export function admitAcquireUrl(raw: string, initial: boolean): URL {
|
|
70
|
+
let url: URL;
|
|
71
|
+
try { url = new URL(raw); } catch { throw new DesktopAcquireError(initial ? "url_refused" : "redirect_refused", false, "not an absolute URL"); }
|
|
72
|
+
const code = initial ? "url_refused" : "redirect_refused";
|
|
73
|
+
if (url.protocol !== "https:") throw new DesktopAcquireError(code, false, `${url.protocol} is not https`);
|
|
74
|
+
if (url.username || url.password) throw new DesktopAcquireError(code, false, "a URL with credentials is refused");
|
|
75
|
+
if (url.port !== "") throw new DesktopAcquireError(code, false, "a non-default port is refused");
|
|
76
|
+
const host = url.hostname.toLowerCase();
|
|
77
|
+
if (initial || host === "github.com") {
|
|
78
|
+
if (host !== "github.com" || !url.pathname.startsWith(DESKTOP_RELEASE_PATH_PREFIX)) {
|
|
79
|
+
throw new DesktopAcquireError(code, false, `${host}${url.pathname} is not the OpenCodex release source`);
|
|
80
|
+
}
|
|
81
|
+
} else if (!DESKTOP_REDIRECT_HOSTS.includes(host)) {
|
|
82
|
+
throw new DesktopAcquireError(code, false, `${host} is not a listed GitHub release-asset host`);
|
|
83
|
+
}
|
|
84
|
+
return url;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Fetch one resource under the acquisition contract and return its exact bytes. */
|
|
88
|
+
export async function acquireBounded(
|
|
89
|
+
url: string,
|
|
90
|
+
limits: AcquireLimits,
|
|
91
|
+
deps: { transport: AcquireTransport; timers: AcquireTimers },
|
|
92
|
+
): Promise<Uint8Array> {
|
|
93
|
+
const maxRedirects = limits.maxRedirects ?? DESKTOP_ACQUIRE_LIMITS.maxRedirects;
|
|
94
|
+
const connectMs = limits.connectMs ?? DESKTOP_ACQUIRE_LIMITS.connectMs;
|
|
95
|
+
const idleReadMs = limits.idleReadMs ?? DESKTOP_ACQUIRE_LIMITS.idleReadMs;
|
|
96
|
+
const totalMs = limits.totalMs ?? DESKTOP_ACQUIRE_LIMITS.totalMs;
|
|
97
|
+
const controller = new AbortController();
|
|
98
|
+
let failure: DesktopAcquireError | null = null;
|
|
99
|
+
let rejectFailure: (error: DesktopAcquireError) => void = () => {};
|
|
100
|
+
const failed = new Promise<never>((_, reject) => { rejectFailure = reject; });
|
|
101
|
+
failed.catch(() => {});
|
|
102
|
+
const fail = (code: DesktopAcquireErrorCode, message: string) => {
|
|
103
|
+
if (failure) return;
|
|
104
|
+
failure = new DesktopAcquireError(code, true, message);
|
|
105
|
+
controller.abort(failure);
|
|
106
|
+
rejectFailure(failure);
|
|
107
|
+
};
|
|
108
|
+
const raced = async <T>(work: Promise<T>): Promise<T> => {
|
|
109
|
+
try { return await Promise.race([work, failed]); }
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (failure) throw failure;
|
|
112
|
+
if (error instanceof DesktopAcquireError) throw error;
|
|
113
|
+
throw new DesktopAcquireError("transport", true, "the download connection failed");
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const cancelTotal = deps.timers.schedule(totalMs, () => fail("total_timeout", `no complete response within ${totalMs} ms`));
|
|
117
|
+
try {
|
|
118
|
+
let current = url;
|
|
119
|
+
let redirects = 0;
|
|
120
|
+
for (;;) {
|
|
121
|
+
const target = admitAcquireUrl(current, redirects === 0);
|
|
122
|
+
const cancelConnect = deps.timers.schedule(connectMs, () => fail("connect_timeout", `no response within ${connectMs} ms`));
|
|
123
|
+
let response: AcquireResponse;
|
|
124
|
+
try { response = await raced(deps.transport.request(target.href, controller.signal)); }
|
|
125
|
+
finally { cancelConnect(); }
|
|
126
|
+
if (REDIRECT_STATUSES.has(response.status)) {
|
|
127
|
+
response.cancel?.();
|
|
128
|
+
const location = response.headers.get("location");
|
|
129
|
+
if (!location) throw new DesktopAcquireError("redirect_refused", false, "a redirect named no location");
|
|
130
|
+
if (++redirects > maxRedirects) throw new DesktopAcquireError("too_many_redirects", false, `more than ${maxRedirects} redirects`);
|
|
131
|
+
current = new URL(location, target).href;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (response.status !== 200) {
|
|
135
|
+
response.cancel?.();
|
|
136
|
+
const retryable = response.status === 429 || response.status >= 500;
|
|
137
|
+
throw new DesktopAcquireError("http_status", retryable, `the release source answered HTTP ${response.status}`);
|
|
138
|
+
}
|
|
139
|
+
// A transfer encoding changes what Content-Length counts, so only an identity body binds it.
|
|
140
|
+
const declaredRaw = response.headers.get("content-encoding") ? null : response.headers.get("content-length");
|
|
141
|
+
const declared = declaredRaw !== null && /^\d{1,15}$/.test(declaredRaw) ? Number(declaredRaw) : null;
|
|
142
|
+
if (declared !== null && declared > limits.maxBytes) {
|
|
143
|
+
response.cancel?.();
|
|
144
|
+
throw new DesktopAcquireError("oversize", false, `the response declares ${declared} bytes, over the ${limits.maxBytes}-byte cap`);
|
|
145
|
+
}
|
|
146
|
+
if (!response.body) throw new DesktopAcquireError("truncated", true, "the response had no body");
|
|
147
|
+
const iterator = response.body[Symbol.asyncIterator]();
|
|
148
|
+
const chunks: Uint8Array[] = [];
|
|
149
|
+
let total = 0;
|
|
150
|
+
for (;;) {
|
|
151
|
+
const cancelIdle = deps.timers.schedule(idleReadMs, () => fail("idle_timeout", `no data for ${idleReadMs} ms`));
|
|
152
|
+
let step: IteratorResult<Uint8Array>;
|
|
153
|
+
try { step = await raced(iterator.next()); }
|
|
154
|
+
finally { cancelIdle(); }
|
|
155
|
+
if (step.done) break;
|
|
156
|
+
const chunk = step.value;
|
|
157
|
+
// Count before keeping: an oversized chunk is never retained.
|
|
158
|
+
if (total + chunk.byteLength > limits.maxBytes) {
|
|
159
|
+
try { await iterator.return?.(); } catch { /* the cap already decided */ }
|
|
160
|
+
throw new DesktopAcquireError("oversize", false, `the response exceeded the ${limits.maxBytes}-byte cap`);
|
|
161
|
+
}
|
|
162
|
+
chunks.push(chunk);
|
|
163
|
+
total += chunk.byteLength;
|
|
164
|
+
}
|
|
165
|
+
if (declared !== null && declared !== total) {
|
|
166
|
+
throw new DesktopAcquireError("truncated", true, `received ${total} of ${declared} declared bytes`);
|
|
167
|
+
}
|
|
168
|
+
const bytes = new Uint8Array(total);
|
|
169
|
+
let offset = 0;
|
|
170
|
+
for (const chunk of chunks) { bytes.set(chunk, offset); offset += chunk.byteLength; }
|
|
171
|
+
return bytes;
|
|
172
|
+
}
|
|
173
|
+
} finally {
|
|
174
|
+
cancelTotal();
|
|
175
|
+
if (!controller.signal.aborted) controller.abort();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Production transport: manual redirects so every hop is admitted here, and no credentials. */
|
|
180
|
+
export const fetchAcquireTransport: AcquireTransport = {
|
|
181
|
+
async request(url, signal) {
|
|
182
|
+
const response = await fetch(url, {
|
|
183
|
+
redirect: "manual",
|
|
184
|
+
signal,
|
|
185
|
+
credentials: "omit",
|
|
186
|
+
headers: { "user-agent": "opencodex-desktop-updater", accept: "application/octet-stream, application/json" },
|
|
187
|
+
});
|
|
188
|
+
return {
|
|
189
|
+
status: response.status,
|
|
190
|
+
headers: response.headers,
|
|
191
|
+
body: response.body as unknown as AsyncIterable<Uint8Array> | null,
|
|
192
|
+
cancel: () => { response.body?.cancel().catch(() => {}); },
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export const realAcquireTimers: AcquireTimers = {
|
|
198
|
+
schedule(ms, fire) {
|
|
199
|
+
const timer = setTimeout(fire, ms);
|
|
200
|
+
return () => clearTimeout(timer);
|
|
201
|
+
},
|
|
202
|
+
};
|