@bitkyc08/opencodex 2.94.0 → 2.95.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/gui/dist/assets/App-8yedBkhm.js +58 -0
- package/gui/dist/assets/App-B4j-Txmb.css +1 -0
- package/gui/dist/assets/{Tray-CZatQdoF.js → Tray-erSMzxPG.js} +1 -1
- package/gui/dist/assets/index-D7DCm5eQ.js +94 -0
- package/gui/dist/assets/quota-summary-BK4VuQNc.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/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/muse-tool-catalog.ts +87 -0
- package/src/adapters/openai-responses/passthrough.ts +42 -7
- 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/opencode-go-additional-tools.ts +39 -6
- 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/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/index.ts +4 -9
- package/src/cli/init.ts +2 -2
- package/src/cli/internal-command.ts +29 -2
- package/src/cli/provider-cc-switch-import.ts +185 -0
- package/src/cli/provider.ts +5 -0
- package/src/cli/registry.ts +1 -0
- 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/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.ts +4 -4
- 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/history-provider.ts +11 -10
- package/src/codex/inject/bounded-config-reader.ts +14 -13
- 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 +313 -213
- 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 +47 -29
- 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/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/antigravity-discovery-diagnostics.ts +65 -0
- package/src/oauth/google-antigravity.ts +23 -10
- package/src/oauth/index.ts +2 -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/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/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/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/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/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 +90 -2
- package/src/server/codex-model-list.ts +2 -1
- package/src/server/configured-credentials.ts +5 -0
- package/src/server/index/serve-options.ts +12 -2
- package/src/server/index/websocket-handler.ts +3 -0
- 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/advisor-plan-slot.ts +4 -0
- package/src/server/responses/advisor-slot.ts +73 -46
- package/src/server/responses/codex-auth-error.ts +5 -1
- package/src/server/responses/combo-required-tool-contract.ts +27 -0
- package/src/server/responses/compact.ts +4 -1
- package/src/server/responses/core-combo-failure.ts +2 -0
- package/src/server/responses/core-combo.ts +66 -5
- package/src/server/responses/core-lifetime.ts +4 -0
- 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-dispatch.ts +5 -4
- 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 +1 -0
- 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/workflow-refusal.ts +2 -1
- 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/index.ts +2 -0
- package/src/vision/plan.ts +4 -0
- package/src/vision/routed-describe.ts +38 -23
- 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
|
@@ -30,8 +30,10 @@
|
|
|
30
30
|
* stays the documented residual it always was.
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
import { codexCliUpdateRecoveryBlocksAdmission } from "./cli-update-recovery";
|
|
33
|
+
import { codexCliUpdateRecoveryBlocksAdmission, codexCliUpdateRecoveryBlocksAdmissionAsync } from "./cli-update-recovery";
|
|
34
34
|
import type { CodexCliUpdateNativeChildIdentity, CodexCliUpdateNativeRecoveryProof } from "./cli-update-recovery";
|
|
35
|
+
import { getConfigDir } from "../config/paths";
|
|
36
|
+
import { resolve } from "node:path";
|
|
35
37
|
|
|
36
38
|
export const CODEX_CLI_UPDATE_FENCE_PREPARING = 0;
|
|
37
39
|
export const CODEX_CLI_UPDATE_FENCE_CANCELLED = 1;
|
|
@@ -53,6 +55,10 @@ export class CodexCliSelectionMutationBusyError extends Error {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
let selectionGate: SharedArrayBuffer | null = null;
|
|
58
|
+
let asyncParentOwner: { buffer: SharedArrayBuffer; owner: number } | null = null;
|
|
59
|
+
// This scope exists only during one synchronous commit turn. It is never kept
|
|
60
|
+
// across an await, so unrelated parent requests cannot borrow its admission.
|
|
61
|
+
let parentCommitScope: { buffer: SharedArrayBuffer; owner: number; configDir: string } | null = null;
|
|
56
62
|
|
|
57
63
|
/** One process-wide holder and monotonic generation counter shared across realms. */
|
|
58
64
|
export function codexCliUpdateSelectionGate(): SharedArrayBuffer {
|
|
@@ -60,9 +66,19 @@ export function codexCliUpdateSelectionGate(): SharedArrayBuffer {
|
|
|
60
66
|
return selectionGate;
|
|
61
67
|
}
|
|
62
68
|
|
|
69
|
+
/** Diagnostic classification does not grant or release gate ownership. */
|
|
70
|
+
export function codexCliSelectionGateState(): "free" | "parent_write" | "worker_commit" | "unrecognized" {
|
|
71
|
+
const buffer = codexCliUpdateSelectionGate(), owner = Atomics.load(new Int32Array(buffer), 0);
|
|
72
|
+
if (owner === CODEX_CLI_UPDATE_GATE_FREE) return "free";
|
|
73
|
+
if (owner === CODEX_CLI_UPDATE_GATE_PARENT_WRITE
|
|
74
|
+
|| (asyncParentOwner?.buffer === buffer && asyncParentOwner.owner === owner)) return "parent_write";
|
|
75
|
+
return owner >= CODEX_CLI_UPDATE_GATE_WORKER_COMMIT ? "worker_commit" : "unrecognized";
|
|
76
|
+
}
|
|
77
|
+
|
|
63
78
|
/** Test seam: drop the cell so each case starts from FREE on a fresh buffer. */
|
|
64
79
|
export function resetCodexCliSelectionGatesForTests(): void {
|
|
65
80
|
selectionGate = null;
|
|
81
|
+
asyncParentOwner = null;
|
|
66
82
|
}
|
|
67
83
|
|
|
68
84
|
/** Per-job fence: decision, current child pgid (0 = unpublished), terminal proof. */
|
|
@@ -112,8 +128,13 @@ export interface CodexCliSelectionParentWrite {
|
|
|
112
128
|
* paths. entered === false means a commit window (or another writer) is in
|
|
113
129
|
* flight and the caller must surface busy immediately, never wait.
|
|
114
130
|
*/
|
|
115
|
-
export function beginCodexCliSelectionParentWrite(): CodexCliSelectionParentWrite {
|
|
116
|
-
if (
|
|
131
|
+
export function beginCodexCliSelectionParentWrite(configDir = getConfigDir()): CodexCliSelectionParentWrite {
|
|
132
|
+
if (parentCommitScope) {
|
|
133
|
+
const entered = resolve(configDir) === parentCommitScope.configDir
|
|
134
|
+
&& Atomics.load(new Int32Array(parentCommitScope.buffer), 0) === parentCommitScope.owner;
|
|
135
|
+
return Object.freeze({ entered, exit() {} });
|
|
136
|
+
}
|
|
137
|
+
if (codexCliUpdateRecoveryBlocksAdmission(configDir)) return Object.freeze({ entered: false, exit() {} });
|
|
117
138
|
const view = new Int32Array(codexCliUpdateSelectionGate());
|
|
118
139
|
if (Atomics.compareExchange(view, 0, CODEX_CLI_UPDATE_GATE_FREE, CODEX_CLI_UPDATE_GATE_PARENT_WRITE)
|
|
119
140
|
!== CODEX_CLI_UPDATE_GATE_FREE) {
|
|
@@ -125,11 +146,60 @@ export function beginCodexCliSelectionParentWrite(): CodexCliSelectionParentWrit
|
|
|
125
146
|
exit() {
|
|
126
147
|
if (!held) return;
|
|
127
148
|
held = false;
|
|
128
|
-
Atomics.
|
|
149
|
+
Atomics.compareExchange(view, 0, CODEX_CLI_UPDATE_GATE_PARENT_WRITE, CODEX_CLI_UPDATE_GATE_FREE);
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
type SynchronousParentCommit<T> = () => T & (T extends PromiseLike<unknown> ? never : unknown);
|
|
155
|
+
export interface CodexCliSelectionAsyncParentWrite extends CodexCliSelectionParentWrite {
|
|
156
|
+
/** Run existing synchronous writers under this exact fresh admission. Never await inside. */
|
|
157
|
+
commit<T>(run: SynchronousParentCommit<T>): T;
|
|
158
|
+
}
|
|
159
|
+
interface ParentAdmissionOptions {
|
|
160
|
+
configDir?: string;
|
|
161
|
+
signal?: AbortSignal;
|
|
162
|
+
/** Test seam; production always uses the fresh async recovery protocol. */
|
|
163
|
+
recoveryBlocksAdmission?: (configDir?: string) => Promise<boolean>;
|
|
164
|
+
}
|
|
165
|
+
/** Reserve before inspection, keep the generation across awaits, and release only that owner. */
|
|
166
|
+
export async function beginCodexCliSelectionParentWriteAsync(options: ParentAdmissionOptions = {}): Promise<CodexCliSelectionAsyncParentWrite> {
|
|
167
|
+
const refused = Object.freeze({ entered: false, exit() {}, commit<T>(_run: SynchronousParentCommit<T>): T { throw new CodexCliSelectionMutationBusyError(); } });
|
|
168
|
+
if (options.signal?.aborted) return refused;
|
|
169
|
+
const configDir = resolve(options.configDir ?? getConfigDir());
|
|
170
|
+
const buffer = codexCliUpdateSelectionGate(), view = new Int32Array(buffer);
|
|
171
|
+
const owner = allocateCodexCliUpdateGateOwner(buffer);
|
|
172
|
+
if (Atomics.compareExchange(view, 0, CODEX_CLI_UPDATE_GATE_FREE, owner) !== CODEX_CLI_UPDATE_GATE_FREE) return refused;
|
|
173
|
+
const parent = { buffer, owner };
|
|
174
|
+
asyncParentOwner = parent;
|
|
175
|
+
let held = true;
|
|
176
|
+
const exit = () => {
|
|
177
|
+
if (!held) return;
|
|
178
|
+
held = false;
|
|
179
|
+
releaseCodexCliUpdateGateOwner(buffer, owner);
|
|
180
|
+
if (asyncParentOwner === parent) asyncParentOwner = null;
|
|
181
|
+
};
|
|
182
|
+
try {
|
|
183
|
+
if (await (options.recoveryBlocksAdmission ?? codexCliUpdateRecoveryBlocksAdmissionAsync)(configDir)
|
|
184
|
+
|| options.signal?.aborted || Atomics.load(view, 0) !== owner) { exit(); return refused; }
|
|
185
|
+
} catch { exit(); return refused; }
|
|
186
|
+
return Object.freeze({ entered: true, exit,
|
|
187
|
+
commit<T>(run: SynchronousParentCommit<T>): T {
|
|
188
|
+
if (!held || options.signal?.aborted || Atomics.load(view, 0) !== owner) throw new CodexCliSelectionMutationBusyError();
|
|
189
|
+
const previous = parentCommitScope;
|
|
190
|
+
parentCommitScope = { buffer, owner, configDir };
|
|
191
|
+
try { return run(); } finally { parentCommitScope = previous; }
|
|
129
192
|
},
|
|
130
193
|
});
|
|
131
194
|
}
|
|
132
195
|
|
|
196
|
+
/** The callback is synchronous: config critical sections retain their original no-await contract. */
|
|
197
|
+
export async function withCodexCliSelectionParentWriteAsync<T>(run: SynchronousParentCommit<T>, options: ParentAdmissionOptions = {}): Promise<T> {
|
|
198
|
+
const admission = await beginCodexCliSelectionParentWriteAsync(options);
|
|
199
|
+
if (!admission.entered) throw new CodexCliSelectionMutationBusyError();
|
|
200
|
+
try { return admission.commit<T>(run); } finally { admission.exit(); }
|
|
201
|
+
}
|
|
202
|
+
|
|
133
203
|
/**
|
|
134
204
|
* The worker's installation window. tryEnter covers the uncontended same-turn
|
|
135
205
|
* case; waitEnter is the bounded retry for a held parent write. commit() is
|
|
@@ -12,7 +12,8 @@ import { inspectWindowsInstallationFiles as inspectFiles, type WindowsInstallati
|
|
|
12
12
|
const inspectWindowsInstallationFiles: typeof inspectFiles = (requests, finalize) =>
|
|
13
13
|
inspectFiles(requests.map(request => ({ ...request, requireCanonicalPath: true })), finalize);
|
|
14
14
|
|
|
15
|
-
async function withCanonicalExclusionRoots<R>(roots: readonly string[], run: () => Promise<R
|
|
15
|
+
async function withCanonicalExclusionRoots<R>(roots: readonly string[], run: () => Promise<R>,
|
|
16
|
+
onRefusal?: (reason: Extract<WindowsInstallationFilesResult, { kind: "refused" }>["reason"]) => void): Promise<R | null> {
|
|
16
17
|
if (!roots.length) return run();
|
|
17
18
|
let result: R | null = null;
|
|
18
19
|
// Keep every exclusion open across the observation/query; validate each batch
|
|
@@ -20,8 +21,9 @@ async function withCanonicalExclusionRoots<R>(roots: readonly string[], run: ()
|
|
|
20
21
|
const observed = await inspectWindowsInstallationFiles(roots.slice(0, 12).map(path => ({
|
|
21
22
|
path: win32.normalize(path), maxBytes: 0, metadataOnly: true, directory: true,
|
|
22
23
|
})), async () => {
|
|
23
|
-
result = await withCanonicalExclusionRoots(roots.slice(12), run); return result !== null;
|
|
24
|
+
result = await withCanonicalExclusionRoots(roots.slice(12), run, onRefusal); return result !== null;
|
|
24
25
|
});
|
|
26
|
+
if (observed.kind === "refused") onRefusal?.(observed.reason);
|
|
25
27
|
return observed.kind === "observed" ? result : null;
|
|
26
28
|
}
|
|
27
29
|
|
|
@@ -34,6 +36,16 @@ interface WindowsPlanEvidence { readonly node: string; readonly npmCli: string;
|
|
|
34
36
|
readonly nodeEvidence: string; readonly npmEvidence: string; readonly exclusionRoots: readonly string[] }
|
|
35
37
|
const evidence = new WeakMap<CodexCliInstallReport, WindowsPlanEvidence>();
|
|
36
38
|
const toolchainDigests = new WeakMap<CodexCliInstallReport, string>();
|
|
39
|
+
type WindowsPlanRefusalGate = "selection" | "exclusion-roots" | "local-node" | "derivation"
|
|
40
|
+
| "launcher-arch" | "excluded-layout" | "initial-observation" | "initial-content"
|
|
41
|
+
| "backing-selection" | "final-observation" | "shim-content" | "manifest-identity"
|
|
42
|
+
| "node-identity" | "backing-content" | "exception";
|
|
43
|
+
type WindowsPlanRefusalReason = Extract<WindowsInstallationFilesResult, { kind: "refused" }>["reason"]
|
|
44
|
+
| Extract<Awaited<ReturnType<typeof deriveCodexCliInstallationInput>>, { kind: "unavailable" }>["reason"];
|
|
45
|
+
interface WindowsPlanRefusal { readonly gate: WindowsPlanRefusalGate; readonly reason?: WindowsPlanRefusalReason }
|
|
46
|
+
const refusals = new WeakMap<CodexCliInstallReport, WindowsPlanRefusal>();
|
|
47
|
+
/** Test diagnostics only: fixed codes, never paths, exception messages or public report fields. */
|
|
48
|
+
export const windowsCodexCliPlanRefusalForTests = (report: CodexCliInstallReport): WindowsPlanRefusal | null => refusals.get(report) ?? null;
|
|
37
49
|
export const windowsCodexCliToolchainDigest = (report: CodexCliInstallReport): string | undefined => toolchainDigests.get(report);
|
|
38
50
|
export const windowsCodexCliPlanEvidence = (report: CodexCliInstallReport): WindowsPlanEvidence | null => evidence.get(report) ?? null;
|
|
39
51
|
const hash = (value: string): string => createHash("sha256").update(value).digest("hex");
|
|
@@ -129,20 +141,25 @@ export async function inspectWindowsCodexCliPlanInstall(
|
|
|
129
141
|
deps: CodexCliInstallProvenanceDeps, fallback: CodexCliInstallReport, excluded: (path: string) => boolean,
|
|
130
142
|
exclusionRoots: readonly string[] = [],
|
|
131
143
|
): Promise<CodexCliInstallReport> {
|
|
144
|
+
const refuse = (gate: WindowsPlanRefusalGate, reason?: WindowsPlanRefusalReason): CodexCliInstallReport => {
|
|
145
|
+
refusals.set(fallback, Object.freeze(reason === undefined ? { gate } : { gate, reason }));
|
|
146
|
+
return fallback;
|
|
147
|
+
};
|
|
132
148
|
const env = deps.env ?? {};
|
|
133
149
|
const candidate = env.CODEX_CLI_PATH?.trim();
|
|
134
150
|
if (!deps.selectionAttested || !candidate || !/^[a-z]:[\\/]/i.test(candidate)
|
|
135
151
|
|| win32.basename(candidate) !== "codex.cmd"
|
|
136
|
-
|| (deps.selectedCommand != null && deps.selectedCommand !== candidate)) return
|
|
152
|
+
|| (deps.selectedCommand != null && deps.selectedCommand !== candidate)) return refuse("selection");
|
|
137
153
|
if (exclusionRoots.length) {
|
|
138
154
|
const roots = Object.freeze([...exclusionRoots]);
|
|
155
|
+
let reason: WindowsPlanRefusalReason | undefined;
|
|
139
156
|
const report = await withCanonicalExclusionRoots(roots,
|
|
140
|
-
() => inspectWindowsCodexCliPlanInstall(deps, fallback, excluded));
|
|
157
|
+
() => inspectWindowsCodexCliPlanInstall(deps, fallback, excluded), value => { reason ??= value; });
|
|
141
158
|
if (report) {
|
|
142
159
|
const toolchain = evidence.get(report);
|
|
143
160
|
if (toolchain) evidence.set(report, Object.freeze({ ...toolchain, exclusionRoots: roots }));
|
|
144
161
|
}
|
|
145
|
-
return report ??
|
|
162
|
+
return report ?? refuse("exclusion-roots", reason);
|
|
146
163
|
}
|
|
147
164
|
// The bounded content read is opt-in: a bare ownership check holds the same
|
|
148
165
|
// reparse-refusing handles; only bounded ownership/header reads remain.
|
|
@@ -150,14 +167,14 @@ export async function inspectWindowsCodexCliPlanInstall(
|
|
|
150
167
|
const prefix = win32.dirname(candidate);
|
|
151
168
|
const localNodePath = win32.join(prefix, "node.exe");
|
|
152
169
|
const localNode = await inspectWindowsInstallationFiles([{ path: localNodePath, maxBytes: 0, metadataOnly: true }]);
|
|
153
|
-
if (localNode.kind === "refused" && localNode.reason !== "not-found") return
|
|
170
|
+
if (localNode.kind === "refused" && localNode.reason !== "not-found") return refuse("local-node", localNode.reason);
|
|
154
171
|
const selectedPath = env.PATH;
|
|
155
172
|
const selectedPathExt = env.PATHEXT;
|
|
156
173
|
const derivation = await deriveCodexCliInstallationInput({
|
|
157
174
|
codexCliPath: candidate, path: selectedPath ?? null, pathExt: selectedPathExt ?? null,
|
|
158
175
|
}, { platform: "win32" });
|
|
159
176
|
if (derivation.kind !== "derived" || derivation.input.candidate !== candidate
|
|
160
|
-
|| derivation.input.npmPrefix !== prefix) return
|
|
177
|
+
|| derivation.input.npmPrefix !== prefix) return refuse("derivation", derivation.kind === "unavailable" ? derivation.reason : undefined);
|
|
161
178
|
const node = derivation.input.node;
|
|
162
179
|
const npmCli = derivation.input.npmCli;
|
|
163
180
|
const npmRoot = win32.dirname(win32.dirname(npmCli));
|
|
@@ -166,13 +183,13 @@ export async function inspectWindowsCodexCliPlanInstall(
|
|
|
166
183
|
// separate toolchain is bound as the updater's metadata vehicle only. Without the
|
|
167
184
|
// launcher arch the toolchain's arch cannot be tied to the selection at all, so a
|
|
168
185
|
// separate toolchain stays refused rather than claim an unanchored backing lane.
|
|
169
|
-
if (pathNode && !deps.arch) return
|
|
186
|
+
if (pathNode && !deps.arch) return refuse("launcher-arch");
|
|
170
187
|
const root = win32.join(prefix, "node_modules", "@openai", "codex");
|
|
171
188
|
const manifest = win32.join(root, "package.json");
|
|
172
189
|
const npmManifest = win32.join(npmRoot, "package.json");
|
|
173
190
|
const bin = win32.join(root, "bin", "codex.js");
|
|
174
191
|
const paths = [candidate, node, npmCli, root];
|
|
175
|
-
if (prefix === win32.parse(prefix).root || paths.some(excluded)) return
|
|
192
|
+
if (prefix === win32.parse(prefix).root || paths.some(excluded)) return refuse("excluded-layout");
|
|
176
193
|
// Only already handle-observed files can pass the real resolver's existence
|
|
177
194
|
// predicate. The explicit override wins before saved-state/shim/PATH candidates.
|
|
178
195
|
const selected = () => selectedWindowsOverride(candidate, env, deps.configDir);
|
|
@@ -181,30 +198,31 @@ export async function inspectWindowsCodexCliPlanInstall(
|
|
|
181
198
|
{ path: manifest, maxBytes: 256 * 1024 }, { path: npmManifest, maxBytes: 256 * 1024 },
|
|
182
199
|
{ path: node, maxBytes: 4096, prefixOnly: true },
|
|
183
200
|
]);
|
|
184
|
-
if (first.kind !== "observed") return
|
|
201
|
+
if (first.kind !== "observed") return refuse("initial-observation", first.reason);
|
|
185
202
|
const initial = new Map(first.files.map(file => [file.path, file]));
|
|
186
203
|
const main = json(initial.get(manifest)!); const npm = json(initial.get(npmManifest)!);
|
|
187
204
|
const arch = peArch(initial.get(node)!.bytes);
|
|
188
205
|
if (!main || main.name !== "@openai/codex" || typeof main.version !== "string" || !parseStrictSemver(main.version)
|
|
189
206
|
|| entry(main, "codex") !== "bin/codex.js" || !npm || npm.name !== "npm"
|
|
190
207
|
|| typeof npm.version !== "string" || !parseStrictSemver(npm.version) || entry(npm, "npm") !== "bin/npm-cli.js"
|
|
191
|
-
|| !arch || (deps.arch && deps.arch !== arch)) return
|
|
208
|
+
|| !arch || (deps.arch && deps.arch !== arch)) return refuse("initial-content");
|
|
192
209
|
const pkg = `@openai/codex-win32-${arch}`;
|
|
193
210
|
const triple = arch === "x64" ? "x86_64-pc-windows-msvc" : "aarch64-pc-windows-msvc";
|
|
194
211
|
// Node's nearest-first package lookup, bounded to this independent prefix.
|
|
195
212
|
const lanes = [win32.join(root, "bin", "node_modules"), win32.join(root, "node_modules"),
|
|
196
213
|
win32.join(prefix, "node_modules", "@openai", "node_modules"), win32.join(prefix, "node_modules")];
|
|
214
|
+
let backingRefusal: WindowsPlanRefusalReason | undefined;
|
|
197
215
|
const backingSelection = async (): Promise<string | null> => {
|
|
198
216
|
for (const lane of lanes) {
|
|
199
217
|
const path = win32.join(lane, pkg, "package.json");
|
|
200
218
|
const probe = await inspectWindowsInstallationFiles([{ path, maxBytes: 0, metadataOnly: true }]);
|
|
201
219
|
if (probe.kind === "observed") return path;
|
|
202
|
-
if (probe.reason !== "not-found") return null;
|
|
220
|
+
if (probe.reason !== "not-found") { backingRefusal = probe.reason; return null; }
|
|
203
221
|
}
|
|
204
222
|
return null; // No global module lookup or vendor fallback adoption.
|
|
205
223
|
};
|
|
206
224
|
const backingManifest = await backingSelection();
|
|
207
|
-
if (!backingManifest) return
|
|
225
|
+
if (!backingManifest) return refuse("backing-selection", backingRefusal ?? "not-found");
|
|
208
226
|
const native = win32.join(win32.dirname(backingManifest), "vendor", triple, "bin", "codex.exe");
|
|
209
227
|
// Ownership requires the manifests, shim and backing manifest bytes plus the
|
|
210
228
|
// bounded Node header read above; entrypoint, npm CLI, Node and native
|
|
@@ -225,14 +243,14 @@ export async function inspectWindowsCodexCliPlanInstall(
|
|
|
225
243
|
.then(current => current.kind === "derived" && current.input.candidate === candidate
|
|
226
244
|
&& current.input.npmPrefix === prefix && current.input.node === node && current.input.npmCli === npmCli)
|
|
227
245
|
&& await backingSelection() === backingManifest);
|
|
228
|
-
if (final.kind !== "observed") return
|
|
246
|
+
if (final.kind !== "observed") return refuse("final-observation", backingRefusal ?? final.reason);
|
|
229
247
|
const files = new Map(final.files.map(file => [file.path, file]));
|
|
230
|
-
if (!npmCodexCommandShim(files.get(candidate)!.bytes)) return
|
|
231
|
-
for (const path of [manifest, npmManifest]) if (id(initial.get(path)!) !== id(files.get(path)!)) return
|
|
232
|
-
if (JSON.stringify(initial.get(node)!.identity) !== JSON.stringify(files.get(node)!.identity)) return
|
|
248
|
+
if (!npmCodexCommandShim(files.get(candidate)!.bytes)) return refuse("shim-content");
|
|
249
|
+
for (const path of [manifest, npmManifest]) if (id(initial.get(path)!) !== id(files.get(path)!)) return refuse("manifest-identity");
|
|
250
|
+
if (JSON.stringify(initial.get(node)!.identity) !== JSON.stringify(files.get(node)!.identity)) return refuse("node-identity");
|
|
233
251
|
const backing = json(files.get(backingManifest)!);
|
|
234
252
|
if (!backing || "exports" in backing || ![pkg, "@openai/codex"].includes(String(backing.name))
|
|
235
|
-
|| ![main.version, `${main.version}-win32-${arch}`].includes(String(backing.version))) return
|
|
253
|
+
|| ![main.version, `${main.version}-win32-${arch}`].includes(String(backing.version))) return refuse("backing-content");
|
|
236
254
|
const content = observe ? hash(JSON.stringify(["windows-npm-read-only-plan-v3", arch, prefix, candidate, node, npmCli,
|
|
237
255
|
...final.files.map(file => [file.path, file.identity, file.digest])])) : null;
|
|
238
256
|
const report: CodexCliInstallReport = Object.freeze({ ...fallback, managed: true, selectionAttested: true,
|
|
@@ -246,5 +264,5 @@ export async function inspectWindowsCodexCliPlanInstall(
|
|
|
246
264
|
envPath: selectedPath, envPathExt: selectedPathExt,
|
|
247
265
|
backingRoot: win32.dirname(backingManifest), nodeEvidence: id(files.get(node)!), npmEvidence: id(files.get(npmCli)!), exclusionRoots: Object.freeze([]) }));
|
|
248
266
|
return report;
|
|
249
|
-
} catch { return
|
|
267
|
+
} catch { return refuse("exception"); }
|
|
250
268
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, realpathSync, statSync } from "node:fs";
|
|
2
2
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
3
3
|
import { getConfigDir } from "../config/paths";
|
|
4
|
+
import { sameFileIdentity } from "../lib/file-identity";
|
|
4
5
|
import { samePathIdentity } from "./user-identity";
|
|
5
6
|
|
|
6
7
|
export const CODEX_HOME_JOURNAL_FILE = "opencodex-journal.json";
|
|
@@ -55,21 +56,21 @@ function validJournal(value: unknown): value is Record<string, unknown> {
|
|
|
55
56
|
export function readCodexHomeJournal(journalPath: string): CodexHomeJournalInspection {
|
|
56
57
|
let fd: number | undefined;
|
|
57
58
|
try {
|
|
58
|
-
const before = lstatSync(journalPath);
|
|
59
|
-
if (!before.isFile() || before.isSymbolicLink() || before.size > MAX_JOURNAL_BYTES) return { kind: "unknown" };
|
|
59
|
+
const before = lstatSync(journalPath, { bigint: true });
|
|
60
|
+
if (!before.isFile() || before.isSymbolicLink() || before.size > BigInt(MAX_JOURNAL_BYTES)) return { kind: "unknown" };
|
|
60
61
|
fd = openSync(journalPath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
61
|
-
const opened = fstatSync(fd);
|
|
62
|
-
if (!opened.isFile() || opened.size > MAX_JOURNAL_BYTES || before
|
|
63
|
-
const bytes = Buffer.alloc(opened.size + 1);
|
|
62
|
+
const opened = fstatSync(fd, { bigint: true });
|
|
63
|
+
if (!opened.isFile() || opened.size > BigInt(MAX_JOURNAL_BYTES) || !sameFileIdentity(before, opened)) return { kind: "unknown" };
|
|
64
|
+
const bytes = Buffer.alloc(Number(opened.size) + 1);
|
|
64
65
|
let length = 0;
|
|
65
66
|
while (length < bytes.length) {
|
|
66
67
|
const count = readSync(fd, bytes, length, bytes.length - length, null);
|
|
67
68
|
if (!count) break;
|
|
68
69
|
length += count;
|
|
69
70
|
}
|
|
70
|
-
const after = lstatSync(journalPath);
|
|
71
|
-
if (length !== opened.size || !after.isFile() || after
|
|
72
|
-
|| after.size !== opened.size || after.
|
|
71
|
+
const after = lstatSync(journalPath, { bigint: true });
|
|
72
|
+
if (BigInt(length) !== opened.size || !after.isFile() || !sameFileIdentity(after, opened)
|
|
73
|
+
|| after.size !== opened.size || after.mtimeNs !== opened.mtimeNs || after.ctimeNs !== opened.ctimeNs) return { kind: "unknown" };
|
|
73
74
|
const journal: unknown = JSON.parse(bytes.subarray(0, length).toString("utf8"));
|
|
74
75
|
return validJournal(journal) ? { kind: "read", journal } : { kind: "unknown" };
|
|
75
76
|
} catch (error) {
|
package/src/codex/convergence.ts
CHANGED
|
@@ -37,7 +37,6 @@ import {
|
|
|
37
37
|
import {
|
|
38
38
|
catalogBackupPathFor,
|
|
39
39
|
catalogHasRoutedEntries,
|
|
40
|
-
findSupportedNativeTemplate,
|
|
41
40
|
legacyCatalogBackupPath,
|
|
42
41
|
nativeMultiAgentDefaults,
|
|
43
42
|
parseCatalogJson,
|
|
@@ -64,6 +63,7 @@ import {
|
|
|
64
63
|
nativeContextLimits,
|
|
65
64
|
shouldIncludeAccountBoundNativeOpenAi,
|
|
66
65
|
shouldIncludeNativeOpenAi,
|
|
66
|
+
shouldUpgradeToUpstreamEntry,
|
|
67
67
|
} from "./catalog/metadata";
|
|
68
68
|
import {
|
|
69
69
|
trustedAccountBoundNativeCatalogSlug,
|
|
@@ -78,6 +78,8 @@ import { codexRuntimeStatePath, peekCodexRuntimeProcessCache } from "./runtime";
|
|
|
78
78
|
import { codexAccountNamespaceEntries, isMainCodexAccountTarget } from "./account-namespaces";
|
|
79
79
|
import { MAIN_CODEX_ACCOUNT_ID } from "./main-account";
|
|
80
80
|
import { applyNativeAccessPrograms } from "./catalog/access-programs";
|
|
81
|
+
import { advanceNativeInheritanceTemplate, captureNativeInheritanceTemplate } from "./catalog/native-template";
|
|
82
|
+
import { omitDisabledNativeCatalogEntries } from "./catalog/native-omission";
|
|
81
83
|
import {
|
|
82
84
|
availableAccountGatedNativeModels,
|
|
83
85
|
codexModelEntitlementStateForAccount,
|
|
@@ -269,7 +271,7 @@ function prepareCatalog(
|
|
|
269
271
|
): RawCatalog {
|
|
270
272
|
const catalog = JSON.parse(JSON.stringify(source.catalog)) as RawCatalog;
|
|
271
273
|
// Strict selector: an unknown bare row must never become the routed template (#2813).
|
|
272
|
-
const template =
|
|
274
|
+
const template = captureNativeInheritanceTemplate(catalog, config.omitDisabledNativeModels === true);
|
|
273
275
|
const enabled = filterCatalogVisibleModels(routedModels, config);
|
|
274
276
|
const featured = config.subagentModels ?? [];
|
|
275
277
|
const ordered = orderForSubagents(enabled, featured);
|
|
@@ -296,6 +298,13 @@ function prepareCatalog(
|
|
|
296
298
|
...desktopAllowlistSuppressedNativeSlugs(config),
|
|
297
299
|
...[...ACCOUNT_GATED_NATIVE_OPENAI_MODELS].filter(slug => !availableBareGatedNativeSlugs.has(slug)),
|
|
298
300
|
]);
|
|
301
|
+
// An omitted source still needs the same upgrade/normalization as a visible native.
|
|
302
|
+
// Keep independent combo-alias and entitlement suppression authoritative.
|
|
303
|
+
if (template && shouldUpgradeToUpstreamEntry(template)
|
|
304
|
+
&& (!ACCOUNT_GATED_NATIVE_OPENAI_MODELS.has(String(template.slug)) || availableBareGatedNativeSlugs.has(String(template.slug)))
|
|
305
|
+
&& !desktopAllowlistSuppressedNativeSlugs({ ...config, omitDisabledNativeModels: false }).has(String(template.slug))) {
|
|
306
|
+
suppressedBareNativeSlugs.delete(String(template.slug));
|
|
307
|
+
}
|
|
299
308
|
const hasPhysicalComboProvider = Object.hasOwn(config.providers, COMBO_NAMESPACE);
|
|
300
309
|
const enabledProviders = Object.entries(config.providers).filter(([, provider]) => provider.disabled !== true);
|
|
301
310
|
const includeNativeOpenAi = shouldIncludeNativeOpenAi(config);
|
|
@@ -416,12 +425,13 @@ function prepareCatalog(
|
|
|
416
425
|
: null,
|
|
417
426
|
);
|
|
418
427
|
finalizeAutoReviewModelOverride(mergedModels, catalogModels, config);
|
|
428
|
+
advanceNativeInheritanceTemplate(catalog, mergedModels, shouldUpgradeToUpstreamEntry);
|
|
419
429
|
// The second writer of this file. A dashboard model toggle, a combo edit, or a Codex account
|
|
420
430
|
// login reaches `convergeCodexCatalog` and commits through `fixedCommit`, never through
|
|
421
431
|
// `writeRetainedCatalogSync`, so the #4730 uniqueness guard has to stand here too or the same
|
|
422
432
|
// `source-invalid` rejection returns by a different route. Silent because this merge runs under
|
|
423
433
|
// `warningPolicy: "suppress"`.
|
|
424
|
-
catalog.models = enforceCatalogSlugUniqueness(mergedModels, false);
|
|
434
|
+
catalog.models = enforceCatalogSlugUniqueness(omitDisabledNativeCatalogEntries(mergedModels, config), false);
|
|
425
435
|
return catalog;
|
|
426
436
|
}
|
|
427
437
|
|
|
@@ -12,11 +12,13 @@ import {
|
|
|
12
12
|
realpathSync,
|
|
13
13
|
renameSync,
|
|
14
14
|
type Stats,
|
|
15
|
+
type BigIntStats,
|
|
15
16
|
} from "node:fs";
|
|
16
17
|
import { join } from "node:path";
|
|
17
18
|
import { pathToFileURL } from "node:url";
|
|
18
19
|
|
|
19
20
|
import { Database, constants as sqliteConstants } from "bun:sqlite";
|
|
21
|
+
import { sameFileIdentity, type FileIdentity as NodeIdentity } from "../lib/file-identity";
|
|
20
22
|
|
|
21
23
|
import { resolveCodexHomeDir } from "./home";
|
|
22
24
|
import {
|
|
@@ -33,7 +35,11 @@ import {
|
|
|
33
35
|
const IMMUTABLE_READONLY_FLAGS =
|
|
34
36
|
sqliteConstants.SQLITE_OPEN_READONLY | sqliteConstants.SQLITE_OPEN_URI;
|
|
35
37
|
|
|
36
|
-
export type FileIdentity = Pick<Stats, "
|
|
38
|
+
export type FileIdentity = NodeIdentity & Pick<Stats, "size" | "mtimeMs" | "ctimeMs">;
|
|
39
|
+
|
|
40
|
+
function milliseconds(ns: bigint): number {
|
|
41
|
+
return Number(ns / 1_000_000_000n) * 1000 + Number(ns % 1_000_000_000n) / 1e6;
|
|
42
|
+
}
|
|
37
43
|
|
|
38
44
|
export interface CodexCoordinatorDiagnosticEvidence {
|
|
39
45
|
sizeBytes: number;
|
|
@@ -66,15 +72,14 @@ function errorCode(error: unknown): string {
|
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
function sameIdentity(left: FileIdentity, right: FileIdentity): boolean {
|
|
69
|
-
return left
|
|
70
|
-
&& left.ino === right.ino
|
|
75
|
+
return sameFileIdentity(left, right)
|
|
71
76
|
&& left.size === right.size
|
|
72
77
|
&& left.mtimeMs === right.mtimeMs
|
|
73
78
|
&& left.ctimeMs === right.ctimeMs;
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
function sameNodeAndSize(left: FileIdentity, right: FileIdentity): boolean {
|
|
77
|
-
return left
|
|
82
|
+
return sameFileIdentity(left, right) && left.size === right.size;
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
function coordinatorPathWithoutCreation(): { kind: "absent"; path: string | null } | { kind: "path"; path: string } {
|
|
@@ -113,9 +118,9 @@ function inspectTarget(
|
|
|
113
118
|
path: string,
|
|
114
119
|
options: { allowSqliteSidecars?: boolean } = {},
|
|
115
120
|
): { kind: "absent" } | { kind: "file"; identity: FileIdentity } | { kind: "unsafe"; reason: string } {
|
|
116
|
-
let entry:
|
|
121
|
+
let entry: BigIntStats;
|
|
117
122
|
try {
|
|
118
|
-
entry = lstatSync(path);
|
|
123
|
+
entry = lstatSync(path, { bigint: true });
|
|
119
124
|
} catch (cause) {
|
|
120
125
|
if (errorCode(cause) === "ENOENT") return { kind: "absent" };
|
|
121
126
|
return { kind: "unsafe", reason: "the coordinator file cannot be inspected" };
|
|
@@ -132,7 +137,7 @@ function inspectTarget(
|
|
|
132
137
|
}
|
|
133
138
|
if (process.platform !== "win32") {
|
|
134
139
|
const uid = process.getuid?.();
|
|
135
|
-
if (uid === undefined || entry.uid !== uid || (entry.mode & 0o777) !== 0o600) {
|
|
140
|
+
if (uid === undefined || Number(entry.uid) !== uid || (Number(entry.mode) & 0o777) !== 0o600) {
|
|
136
141
|
return { kind: "unsafe", reason: "the coordinator file has unsafe ownership or permissions" };
|
|
137
142
|
}
|
|
138
143
|
}
|
|
@@ -143,7 +148,8 @@ function inspectTarget(
|
|
|
143
148
|
}
|
|
144
149
|
}
|
|
145
150
|
}
|
|
146
|
-
return { kind: "file", identity: entry
|
|
151
|
+
return { kind: "file", identity: { dev: entry.dev, ino: entry.ino, size: Number(entry.size),
|
|
152
|
+
mtimeMs: milliseconds(entry.mtimeNs), ctimeMs: milliseconds(entry.ctimeNs) } };
|
|
147
153
|
}
|
|
148
154
|
|
|
149
155
|
function classifyOpenedDatabase(
|
|
@@ -284,7 +284,7 @@ export async function runDesktopRestartHandoff(
|
|
|
284
284
|
try {
|
|
285
285
|
const restart = io.restart
|
|
286
286
|
? io.restart(false)
|
|
287
|
-
: (await import("../desktop-app-restart")).
|
|
287
|
+
: await (await import("../desktop-app-restart")).restartCodexDesktopAppAsync({
|
|
288
288
|
allowHandoff: false,
|
|
289
289
|
lock: io.lock,
|
|
290
290
|
});
|
|
@@ -41,7 +41,7 @@ import { darwinDesktopAppAdapter, darwinDefaultExec } from "./desktop-app/darwin
|
|
|
41
41
|
import { linuxDesktopAppAdapter, linuxDefaultExec } from "./desktop-app/linux";
|
|
42
42
|
import { windowsDesktopAppAdapter, windowsDefaultExec } from "./desktop-app/windows";
|
|
43
43
|
import { isTestHomeGuardArmed } from "../lib/test-home-guard";
|
|
44
|
-
import { beginCodexCliSelectionParentWrite } from "./cli-update-selection-gate";
|
|
44
|
+
import { beginCodexCliSelectionParentWrite, withCodexCliSelectionParentWriteAsync, CodexCliSelectionMutationBusyError } from "./cli-update-selection-gate";
|
|
45
45
|
|
|
46
46
|
export type { DesktopAppExecOptions } from "./desktop-app/types";
|
|
47
47
|
|
|
@@ -388,3 +388,13 @@ export function restartCodexDesktopApp(io: DesktopAppRestartIo = {}): DesktopApp
|
|
|
388
388
|
if (lockHeld && !handedOff) releaseDesktopRestartLock(io.lock);
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
|
+
|
|
392
|
+
export async function restartCodexDesktopAppAsync(io: DesktopAppRestartIo = {}): Promise<DesktopAppRestartResult> {
|
|
393
|
+
try { return await withCodexCliSelectionParentWriteAsync(() => restartCodexDesktopApp(io)); }
|
|
394
|
+
catch (error) {
|
|
395
|
+
if (error instanceof CodexCliSelectionMutationBusyError) return {
|
|
396
|
+
attempted: false, stopped: [], surviving: [], relaunch: "skipped", reason: "selection_mutation_busy",
|
|
397
|
+
};
|
|
398
|
+
throw error;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
@@ -20,8 +20,9 @@ import {
|
|
|
20
20
|
* known-Codex-bundle classifier, and — when the lexical or canonical path sits
|
|
21
21
|
* inside a ChatGPT.app or Codex.app bundle at any location — checked by the shared
|
|
22
22
|
* signature/ownership policy before the same canonical target is returned for
|
|
23
|
-
* execution.
|
|
24
|
-
*
|
|
23
|
+
* execution. CLI handoffs additionally classify any enclosing lexical or canonical .app,
|
|
24
|
+
* independent of bundle name or identifier. Other callers retain the known-app
|
|
25
|
+
* policy; non-bundle executables pass through to the shared launcher unchanged.
|
|
25
26
|
*
|
|
26
27
|
* The check is one-shot per invocation and deliberately not memoized:
|
|
27
28
|
* directory-service group membership, signature state, and directory-entry
|
|
@@ -53,6 +54,10 @@ export interface CodexExecBoundaryDeps {
|
|
|
53
54
|
executable?: (path: string) => boolean;
|
|
54
55
|
/** Canonicalizer; returns null when the path cannot be resolved. */
|
|
55
56
|
realpath?: (path: string) => string | null;
|
|
57
|
+
/** CLI handoffs verify any enclosing app, without trusting mutable bundle identity metadata. */
|
|
58
|
+
verifyAnyAppBundle?: boolean;
|
|
59
|
+
/** Discovered Desktop bundle identity, retained by its generated launcher across respawns. */
|
|
60
|
+
expectedBundleRoot?: string;
|
|
56
61
|
macBundleTrustReason?: (bundleRoot: string, binary: string) => string | null;
|
|
57
62
|
}
|
|
58
63
|
|
|
@@ -113,22 +118,36 @@ function resolveDarwinExecPath(command: string, deps: CodexExecBoundaryDeps): {
|
|
|
113
118
|
|
|
114
119
|
/**
|
|
115
120
|
* Canonical (bundleRoot, binary) pair when the resolved path classifies into a
|
|
116
|
-
* known Codex desktop bundle, else null. The pair is always consistent:
|
|
121
|
+
* known Codex desktop bundle (or any enclosing app for CLI handoffs), else null. The pair is always consistent:
|
|
117
122
|
* both halves are canonicalized together so a symlinked HOME or a PATH alias
|
|
118
123
|
* cannot split the containment check, and a bundle member that cannot be
|
|
119
124
|
* canonicalized refuses rather than escaping the known-bundle classification.
|
|
120
125
|
*/
|
|
121
126
|
function darwinBundleTarget(resolved: string, deps: CodexExecBoundaryDeps): { bundle: string; binary: string } | null {
|
|
122
127
|
const realpath = deps.realpath ?? realpathOrNull;
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
if (deps.expectedBundleRoot !== undefined && !posix.isAbsolute(deps.expectedBundleRoot)) {
|
|
129
|
+
throw new CodexExecTrustError("the recorded app bundle must be an absolute path");
|
|
130
|
+
}
|
|
125
131
|
const binary = realpath(resolved);
|
|
132
|
+
const enclosingApp = (path: string) => /^(.*?\/[^/]*\.app)(?:\/|$)/i.exec(path)?.[1];
|
|
133
|
+
const lexicalBundle = deps.verifyAnyAppBundle && deps.expectedBundleRoot === undefined ? enclosingApp(resolved) : undefined;
|
|
134
|
+
// Verify the outer canonical app for nested layouts, but retain lexical containment.
|
|
135
|
+
const enclosing = deps.verifyAnyAppBundle && binary !== null ? enclosingApp(binary) : undefined;
|
|
136
|
+
const bundle = deps.expectedBundleRoot ?? enclosing ?? lexicalBundle ?? macCodexAppBundleFor(resolved, { env: deps.env, platform: deps.platform, realpath });
|
|
137
|
+
if (!bundle) return null;
|
|
126
138
|
if (binary === null) throw new CodexExecTrustError("cannot canonicalize the app-bundle exec target");
|
|
127
139
|
const canonicalBundle = realpath(bundle);
|
|
128
140
|
if (canonicalBundle === null) throw new CodexExecTrustError("cannot canonicalize the app bundle");
|
|
129
141
|
if (!binary.startsWith(canonicalBundle + "/Contents/")) {
|
|
130
142
|
throw new CodexExecTrustError("the app-bundle exec target is outside bundle Contents");
|
|
131
143
|
}
|
|
144
|
+
if (lexicalBundle && lexicalBundle !== bundle) {
|
|
145
|
+
const canonicalLexicalBundle = realpath(lexicalBundle);
|
|
146
|
+
if (canonicalLexicalBundle === null) throw new CodexExecTrustError("cannot canonicalize the app bundle");
|
|
147
|
+
if (!binary.startsWith(canonicalLexicalBundle + "/Contents/")) {
|
|
148
|
+
throw new CodexExecTrustError("the app-bundle exec target is outside bundle Contents");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
132
151
|
return { bundle: canonicalBundle, binary };
|
|
133
152
|
}
|
|
134
153
|
|
|
@@ -144,6 +163,7 @@ export function validatedCodexExecTarget(
|
|
|
144
163
|
deps: CodexExecBoundaryDeps = {},
|
|
145
164
|
): ValidatedCodexExecTarget {
|
|
146
165
|
if ((deps.platform ?? process.platform) !== "darwin") {
|
|
166
|
+
if (deps.expectedBundleRoot !== undefined) throw new CodexExecTrustError("recorded app bundles require macOS verification");
|
|
147
167
|
return { invocation: codexExecInvocation(command, args, deps.platform ?? process.platform, { env: deps.env, exists: deps.exists }), macAppBundle: false };
|
|
148
168
|
}
|
|
149
169
|
const resolved = resolveDarwinExecPath(command, deps);
|
|
@@ -164,6 +184,7 @@ export async function validatedCodexExecTargetAsync(
|
|
|
164
184
|
): Promise<ValidatedCodexExecTarget> {
|
|
165
185
|
deps.signal?.throwIfAborted();
|
|
166
186
|
if ((deps.platform ?? process.platform) !== "darwin") {
|
|
187
|
+
if (deps.expectedBundleRoot !== undefined) throw new CodexExecTrustError("recorded app bundles require macOS verification");
|
|
167
188
|
return { invocation: codexExecInvocation(command, args, deps.platform ?? process.platform, { env: deps.env, exists: deps.exists }), macAppBundle: false };
|
|
168
189
|
}
|
|
169
190
|
const resolved = resolveDarwinExecPath(command, deps);
|
|
@@ -7,6 +7,7 @@ import { Database } from "bun:sqlite";
|
|
|
7
7
|
import { resolveCodexStateDbPath } from "./paths";
|
|
8
8
|
import { openCodexStateForPreflight } from "./history-state-open";
|
|
9
9
|
import { atomicWriteFile, getConfigDir } from "../config";
|
|
10
|
+
import { sameFileIdentity, statTimeMs, type FileIdentity } from "../lib/file-identity";
|
|
10
11
|
import {
|
|
11
12
|
CODEX_HISTORY_RESUMABLE_SOURCES,
|
|
12
13
|
codexHistoryBackupId,
|
|
@@ -268,15 +269,15 @@ function readFirstLineProviderValue(path: string, expectedId: string): string |
|
|
|
268
269
|
|
|
269
270
|
function patchFirstLineProviderInPlace(
|
|
270
271
|
path: string, expectedId: string, provider: string,
|
|
271
|
-
expectedIdentity:
|
|
272
|
+
expectedIdentity: FileIdentity,
|
|
272
273
|
): FirstLineProviderResult {
|
|
273
274
|
historyAppendHooks?.beforeFirstLineOpen?.(path);
|
|
274
275
|
const fd = openSync(path, "r+");
|
|
275
276
|
try {
|
|
276
277
|
const assertIdentity = (): void => {
|
|
277
278
|
assertHistoryDescriptorIdentity(path, fd);
|
|
278
|
-
const held = fstatSync(fd);
|
|
279
|
-
if (held
|
|
279
|
+
const held = fstatSync(fd, { bigint: true });
|
|
280
|
+
if (!sameFileIdentity(held, expectedIdentity)) {
|
|
280
281
|
throw new CodexHistoryIntegrityError("history_rollout_identity_changed");
|
|
281
282
|
}
|
|
282
283
|
};
|
|
@@ -360,10 +361,10 @@ function assertLegacyHistoryRecord(line: string): void {
|
|
|
360
361
|
}
|
|
361
362
|
|
|
362
363
|
function assertHistoryDescriptorIdentity(path: string, fd: number): void {
|
|
363
|
-
const held = fstatSync(fd);
|
|
364
|
-
let current:
|
|
365
|
-
try { current = lstatSync(path); } catch { throw new CodexHistoryIntegrityError("history_rollout_identity_changed"); }
|
|
366
|
-
if (!current.isFile() || current.isSymbolicLink() || current
|
|
364
|
+
const held = fstatSync(fd, { bigint: true });
|
|
365
|
+
let current: import("node:fs").BigIntStats;
|
|
366
|
+
try { current = lstatSync(path, { bigint: true }); } catch { throw new CodexHistoryIntegrityError("history_rollout_identity_changed"); }
|
|
367
|
+
if (!current.isFile() || current.isSymbolicLink() || !sameFileIdentity(current, held)) {
|
|
367
368
|
throw new CodexHistoryIntegrityError("history_rollout_identity_changed");
|
|
368
369
|
}
|
|
369
370
|
}
|
|
@@ -693,8 +694,8 @@ function inspectBackupForNoop(path: string, stateDbPath: string): StrictBackupIn
|
|
|
693
694
|
|
|
694
695
|
function historyFileIdentity(path: string): string | null {
|
|
695
696
|
try {
|
|
696
|
-
const stat = statSync(path);
|
|
697
|
-
return [stat.dev, stat.ino, stat.size, stat.
|
|
697
|
+
const stat = statSync(path, { bigint: true });
|
|
698
|
+
return [stat.dev, stat.ino, Number(stat.size), statTimeMs(stat.mtimeNs), statTimeMs(stat.ctimeNs)].join(":");
|
|
698
699
|
} catch {
|
|
699
700
|
return null;
|
|
700
701
|
}
|
|
@@ -1132,7 +1133,7 @@ function updateSessionMeta(
|
|
|
1132
1133
|
} = {},
|
|
1133
1134
|
): SessionMetaUpdateResult {
|
|
1134
1135
|
if (!path || !existsSync(path)) return { changed: false, durableProvider: false };
|
|
1135
|
-
const validatedIdentity = lstatSync(path);
|
|
1136
|
+
const validatedIdentity = lstatSync(path, { bigint: true });
|
|
1136
1137
|
if (options.expectedFileIdentity !== undefined
|
|
1137
1138
|
&& historyFileIdentity(path) !== options.expectedFileIdentity) {
|
|
1138
1139
|
return { changed: false, durableProvider: false, conflict: true };
|