@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
|
@@ -3,6 +3,8 @@ import { randomBytes } from "node:crypto";
|
|
|
3
3
|
import { join, posix } from "node:path";
|
|
4
4
|
import { getConfigDir } from "../../config/paths";
|
|
5
5
|
import { selfLaunchArgv } from "../../lib/self-launch-argv";
|
|
6
|
+
import { defaultBundleTrustDeps } from "./bundle-trust";
|
|
7
|
+
import { untrustedLauncherFilesystemReason, type BundleTrustDeps } from "./bundle-trust-policy";
|
|
6
8
|
|
|
7
9
|
export const CHATGPT_APP_CODEX_BINARY = "/Applications/ChatGPT.app/Contents/Resources/codex-cli/CodexCLI.app/Contents/MacOS/codex";
|
|
8
10
|
|
|
@@ -47,24 +49,41 @@ function shellQuote(value: string): string {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/**
|
|
50
|
-
* A failed
|
|
52
|
+
* A failed filter self-test runs the verified binary with untouched stdout.
|
|
53
|
+
* Executable verification is required on every invocation, including passthrough and respawns.
|
|
51
54
|
* A filter that passes the self-test and then dies mid-session closes the pipe.
|
|
52
55
|
* Expected (not yet validated against the bundled app-server): the server gets SIGPIPE or a
|
|
53
56
|
* write error and Desktop respawns it through the same launcher.
|
|
54
57
|
*/
|
|
55
|
-
export function buildChatgptShimLauncher(
|
|
58
|
+
export function buildChatgptShimLauncher(
|
|
59
|
+
argv: readonly string[],
|
|
60
|
+
real = CHATGPT_APP_CODEX_BINARY,
|
|
61
|
+
validator: readonly string[] = [process.execPath, ...selfLaunchArgv(["internal", "codex-exec-target"])],
|
|
62
|
+
bundleRoot = /^(.*?\.app)\/Contents\//i.exec(real)?.[1],
|
|
63
|
+
): string {
|
|
56
64
|
return `#!/bin/bash
|
|
57
65
|
# opencodex (experimental): ChatGPT app-server stdout passes through the quota-gate filter.
|
|
58
66
|
REAL=${shellQuote(real)}
|
|
59
|
-
FILTER=(${argv.map(shellQuote).join(" ")})
|
|
67
|
+
${bundleRoot === undefined ? "" : `BUNDLE_ROOT=${shellQuote(bundleRoot)}\n`}FILTER=(${argv.map(shellQuote).join(" ")})
|
|
68
|
+
VALIDATE=(${validator.map(shellQuote).join(" ")})
|
|
60
69
|
if [ ! -x "$REAL" ]; then
|
|
61
70
|
echo "opencodex (experimental): the bundled app-server is no longer at $REAL; run 'ocx chatgpt launch' again or 'ocx chatgpt restore'." >&2
|
|
62
71
|
exit 127
|
|
63
72
|
fi
|
|
73
|
+
validate_real() {
|
|
74
|
+
local target
|
|
75
|
+
if [ ! -x "\${VALIDATE[0]}" ] || ! target=$("\${VALIDATE[@]}" ${bundleRoot === undefined ? "" : '--bundle-root "$BUNDLE_ROOT" '}-- "$REAL") || [ -z "$target" ]; then
|
|
76
|
+
echo "opencodex: app-server execution verification failed; run 'ocx chatgpt launch' again or 'ocx chatgpt restore'." >&2
|
|
77
|
+
return 126
|
|
78
|
+
fi
|
|
79
|
+
REAL="$target"
|
|
80
|
+
}
|
|
64
81
|
if [ "$(uname -s)" = "Darwin" ] && [ -x "\${FILTER[0]}" ] \\
|
|
65
82
|
&& "\${FILTER[@]}" --self-test >/dev/null 2>&1; then
|
|
83
|
+
validate_real || exit 126
|
|
66
84
|
exec "$REAL" "$@" > >(exec "\${FILTER[@]}")
|
|
67
85
|
fi
|
|
86
|
+
validate_real || exit 126
|
|
68
87
|
exec "$REAL" "$@"
|
|
69
88
|
`;
|
|
70
89
|
}
|
|
@@ -74,17 +93,32 @@ exec "$REAL" "$@"
|
|
|
74
93
|
* launcher, so an existing symbolic link is replaced rather than followed and a respawn during
|
|
75
94
|
* the write never runs a half-written script.
|
|
76
95
|
*/
|
|
77
|
-
export function writeChatgptShimLauncher(
|
|
96
|
+
export function writeChatgptShimLauncher(
|
|
97
|
+
configDir = getConfigDir(), real = CHATGPT_APP_CODEX_BINARY,
|
|
98
|
+
bundleRoot = /^(.*?\.app)\/Contents\//i.exec(real)?.[1],
|
|
99
|
+
filesystem: Pick<BundleTrustDeps, "uid" | "stat" | "adminGroupId"> | undefined = process.platform === "darwin" ? defaultBundleTrustDeps() : undefined,
|
|
100
|
+
): string {
|
|
101
|
+
if (!bundleRoot || !posix.isAbsolute(bundleRoot) || !real.startsWith(bundleRoot + "/Contents/")) {
|
|
102
|
+
throw new Error("the app-server launcher requires its discovered bundle root");
|
|
103
|
+
}
|
|
78
104
|
mkdirSync(configDir, { recursive: true });
|
|
79
105
|
const path = chatgptShimLauncherPath(configDir);
|
|
80
106
|
const argv = [process.execPath, ...selfLaunchArgv(["internal", "chatgpt-app-server-filter"])];
|
|
81
107
|
const temp = `${path}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`;
|
|
108
|
+
let created = false;
|
|
109
|
+
const assertFilesystem = (file: string, existing: boolean) => {
|
|
110
|
+
const reason = filesystem && untrustedLauncherFilesystemReason(file, filesystem, existing);
|
|
111
|
+
if (reason) throw new Error(`unsafe app-server launcher: ${reason}`);
|
|
112
|
+
};
|
|
82
113
|
try {
|
|
83
|
-
|
|
114
|
+
assertFilesystem(temp, false);
|
|
115
|
+
writeFileSync(temp, buildChatgptShimLauncher(argv, real, undefined, bundleRoot), { mode: 0o755, flag: "wx" });
|
|
116
|
+
created = true;
|
|
84
117
|
chmodSync(temp, 0o755);
|
|
118
|
+
assertFilesystem(temp, true);
|
|
85
119
|
renameSync(temp, path);
|
|
86
120
|
} catch (error) {
|
|
87
|
-
try { unlinkSync(temp); } catch { /* the
|
|
121
|
+
if (created) { try { unlinkSync(temp); } catch { /* preserve the publication error */ } }
|
|
88
122
|
throw error;
|
|
89
123
|
}
|
|
90
124
|
return path;
|
|
@@ -100,7 +100,11 @@ function detectFeatures(body: unknown, anthropicBeta?: string): Set<ClaudeFeatur
|
|
|
100
100
|
if (Object.hasOwn(tool, "cache_control")) codes.add("cache_control");
|
|
101
101
|
if (Object.hasOwn(tool, "input_examples")) codes.add("input_examples");
|
|
102
102
|
if (tool.strict === true) codes.add("strict_tools");
|
|
103
|
-
|
|
103
|
+
// Valid function definitions lower to eager tools when the destination lacks deferral.
|
|
104
|
+
// Top-level deferral and declarations without a callable definition remain unsupported.
|
|
105
|
+
const eagerFunction = typeof tool.name === "string" && tool.name.length > 0 && isRec(tool.input_schema)
|
|
106
|
+
&& (tool.type === undefined || tool.type === "function" || tool.type === "custom");
|
|
107
|
+
if (tool.defer === true || (tool.defer_loading === true && !eagerFunction)) codes.add("deferred_tools");
|
|
104
108
|
if (nonDirectCaller(tool.allowed_callers)) codes.add("caller_mode");
|
|
105
109
|
const type = tool.type;
|
|
106
110
|
// Ordinary client function names do not convey hosted execution semantics.
|
package/src/claude/desktop-3p.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
import { nativeOpenAiContextWindow, type NativeContextLimitsInput } from "../codex/catalog";
|
|
28
28
|
import { localAdmissionToken, localInferenceDestination } from "../lib/local-destinations";
|
|
29
29
|
import { assertDesktop3pModelsValid } from "./desktop-3p-guard";
|
|
30
|
+
import { filterDesktopModelsByVisibility, readDesktopModelVisibility, type DesktopModelVisibility } from "./desktop-model-visibility";
|
|
30
31
|
import { claudeSurfaceSupportsOneMillion, ONE_MILLION } from "./long-context";
|
|
31
32
|
|
|
32
33
|
export interface Desktop3pModelEntry {
|
|
@@ -170,9 +171,11 @@ function collectDesktop3pModels(
|
|
|
170
171
|
routedModels: Array<Desktop3pRoutedModel>,
|
|
171
172
|
profile?: OcxClaudeDesktopProfile,
|
|
172
173
|
nativeContextCap?: NativeContextLimitsInput,
|
|
173
|
-
): { models: Desktop3pModelEntry[]; registry: Map<string, string>; realAnthropicIds: Set<string> } {
|
|
174
|
+
): { models: Desktop3pModelEntry[]; routes: string[]; registry: Map<string, string>; realAnthropicIds: Set<string> } {
|
|
174
175
|
const registry = new Map<string, string>();
|
|
175
176
|
const models: Desktop3pModelEntry[] = [];
|
|
177
|
+
// routes[i] is the route models[i] serves; visibility filters by route, never by alias.
|
|
178
|
+
const routes: string[] = [];
|
|
176
179
|
const candidates: Desktop3pRoutedModel[] = [
|
|
177
180
|
// Native candidates carry their real context window from the same accessor the
|
|
178
181
|
// Desktop DTO uses, so a native 1M/372k model resolves identically in the written
|
|
@@ -224,6 +227,7 @@ function collectDesktop3pModels(
|
|
|
224
227
|
...(model.isFamilyDefault ? { isFamilyDefault: true } : {}),
|
|
225
228
|
...(model.supports1m ? { supports1m: true, prefer1m: true } : {}),
|
|
226
229
|
});
|
|
230
|
+
routes.push(model.route);
|
|
227
231
|
}
|
|
228
232
|
// Previous profile IDs and both hash generations are compatibility-only and can
|
|
229
233
|
// collide. Bind them in stable route order so changing a family default or
|
|
@@ -248,7 +252,7 @@ function collectDesktop3pModels(
|
|
|
248
252
|
}
|
|
249
253
|
}
|
|
250
254
|
desktop3pAliasesByRoute = aliasesByRoute;
|
|
251
|
-
return { models, registry, realAnthropicIds };
|
|
255
|
+
return { models, routes, registry, realAnthropicIds };
|
|
252
256
|
}
|
|
253
257
|
|
|
254
258
|
const aliasesByRoute = new Map<string, string>();
|
|
@@ -272,6 +276,7 @@ function collectDesktop3pModels(
|
|
|
272
276
|
...(supports1m.supports1m ? { prefer1m: true as const } : {}),
|
|
273
277
|
});
|
|
274
278
|
emittedNames.add(alias);
|
|
279
|
+
routes.push(route);
|
|
275
280
|
aliasesByRoute.set(route, alias);
|
|
276
281
|
continue;
|
|
277
282
|
}
|
|
@@ -300,12 +305,13 @@ function collectDesktop3pModels(
|
|
|
300
305
|
...supports1m,
|
|
301
306
|
...(supports1m.supports1m ? { prefer1m: true as const } : {}),
|
|
302
307
|
});
|
|
308
|
+
routes.push(route);
|
|
303
309
|
aliasesByRoute.set(route, alias);
|
|
304
310
|
}
|
|
305
311
|
|
|
306
312
|
if (models[0]) models[0].isFamilyDefault = true;
|
|
307
313
|
desktop3pAliasesByRoute = aliasesByRoute;
|
|
308
|
-
return { models, registry, realAnthropicIds };
|
|
314
|
+
return { models, routes, registry, realAnthropicIds };
|
|
309
315
|
}
|
|
310
316
|
|
|
311
317
|
/** Build and install the registry used to decode Desktop aliases. */
|
|
@@ -328,6 +334,11 @@ export interface Desktop3pModelOptions {
|
|
|
328
334
|
* (`supports1m`) but no longer defaults to it (`prefer1m` dropped).
|
|
329
335
|
*/
|
|
330
336
|
preferOneMillion?: boolean;
|
|
337
|
+
/**
|
|
338
|
+
* Rows Desktop lists (#7702). Filters only the emitted list: the decode registry keeps every
|
|
339
|
+
* route so a running session holding a just-hidden alias still routes.
|
|
340
|
+
*/
|
|
341
|
+
visibility?: DesktopModelVisibility;
|
|
331
342
|
}
|
|
332
343
|
|
|
333
344
|
export function generateDesktop3pModels(
|
|
@@ -337,15 +348,25 @@ export function generateDesktop3pModels(
|
|
|
337
348
|
nativeContextCap?: NativeContextLimitsInput,
|
|
338
349
|
options: Desktop3pModelOptions = {},
|
|
339
350
|
): Desktop3pModelEntry[] {
|
|
340
|
-
const { models, registry, realAnthropicIds } = collectDesktop3pModels(nativeSlugs, routedModels, profile, nativeContextCap);
|
|
351
|
+
const { models: all, routes, registry, realAnthropicIds } = collectDesktop3pModels(nativeSlugs, routedModels, profile, nativeContextCap);
|
|
341
352
|
desktop3pRegistry = registry;
|
|
342
353
|
desktop3pRealAnthropicIds = realAnthropicIds;
|
|
354
|
+
let models = filterDesktopModelsByVisibility(all, routes, options.visibility);
|
|
355
|
+
if (models.length === 0 && all.length > 0) {
|
|
356
|
+
// An empty static list leaves Desktop with no usable picker. The dashboard refuses to save
|
|
357
|
+
// such a selection; this covers selections whose every model has since disappeared.
|
|
358
|
+
console.warn("[opencodex] Claude Desktop model visibility hides every available model; listing all models instead");
|
|
359
|
+
models = all;
|
|
360
|
+
}
|
|
343
361
|
return options.preferOneMillion === false ? models.map(({ prefer1m: _prefer1m, ...model }) => model) : models;
|
|
344
362
|
}
|
|
345
363
|
|
|
346
364
|
/** The Desktop model options a config asks for (one place, so writer and export agree). */
|
|
347
|
-
export function desktop3pModelOptions(
|
|
348
|
-
|
|
365
|
+
export function desktop3pModelOptions(
|
|
366
|
+
claudeCode: { contextAccounting?: string; desktopModelVisibility?: unknown } | undefined,
|
|
367
|
+
): Desktop3pModelOptions {
|
|
368
|
+
const visibility = readDesktopModelVisibility(claudeCode);
|
|
369
|
+
return { preferOneMillion: claudeCode?.contextAccounting !== "200k", ...(visibility ? { visibility } : {}) };
|
|
349
370
|
}
|
|
350
371
|
|
|
351
372
|
/** Resolve an alias using the most recently generated Desktop model registry. */
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Desktop model visibility (#7702): which rows the Desktop 3P `inferenceModels`
|
|
3
|
+
* list carries, persisted as `claudeCode.desktopModelVisibility`.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately separate from the Desktop profile (tier/family mapping and defaults) and
|
|
6
|
+
* from provider-wide `disabledModels`: hiding a row here changes only what Claude Desktop
|
|
7
|
+
* lists. The alias decode registry keeps every route, so a running Desktop session that
|
|
8
|
+
* still sends a just-hidden alias keeps routing instead of failing mid-conversation.
|
|
9
|
+
*
|
|
10
|
+
* - unset: every available model is listed (the pre-#7702 behaviour).
|
|
11
|
+
* - `exclude`: every model except `routes`; newly discovered models are listed.
|
|
12
|
+
* - `include`: only `routes`; newly discovered models stay hidden until selected.
|
|
13
|
+
*
|
|
14
|
+
* Discovery-only mode emits no static list, so visibility does not apply there.
|
|
15
|
+
*/
|
|
16
|
+
import type { OcxClaudeDesktopModelVisibility } from "../types";
|
|
17
|
+
import { readDesktopLibraryText } from "./desktop-3p-library";
|
|
18
|
+
|
|
19
|
+
export type DesktopModelVisibility = OcxClaudeDesktopModelVisibility;
|
|
20
|
+
|
|
21
|
+
export const DESKTOP_VISIBILITY_MODES = ["include", "exclude"] as const;
|
|
22
|
+
/** Bounded so a hand-edited config cannot grow the per-write set without limit. */
|
|
23
|
+
export const MAX_DESKTOP_VISIBILITY_ROUTES = 5000;
|
|
24
|
+
|
|
25
|
+
export class DesktopModelVisibilityError extends Error {
|
|
26
|
+
constructor(message: string, readonly path = "desktopModelVisibility") {
|
|
27
|
+
super(`${path}: ${message}`);
|
|
28
|
+
this.name = "DesktopModelVisibilityError";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
33
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function parseDesktopModelVisibility(value: unknown): DesktopModelVisibility {
|
|
37
|
+
if (!isPlainObject(value)) throw new DesktopModelVisibilityError("must be an object");
|
|
38
|
+
for (const key of Object.keys(value)) {
|
|
39
|
+
if (key !== "mode" && key !== "routes") throw new DesktopModelVisibilityError(`unknown field "${key}"`);
|
|
40
|
+
}
|
|
41
|
+
if (value.mode !== "include" && value.mode !== "exclude") {
|
|
42
|
+
throw new DesktopModelVisibilityError("must be \"include\" or \"exclude\"", "desktopModelVisibility.mode");
|
|
43
|
+
}
|
|
44
|
+
if (!Array.isArray(value.routes)) throw new DesktopModelVisibilityError("must be an array", "desktopModelVisibility.routes");
|
|
45
|
+
if (value.routes.length > MAX_DESKTOP_VISIBILITY_ROUTES) {
|
|
46
|
+
throw new DesktopModelVisibilityError(`must list at most ${MAX_DESKTOP_VISIBILITY_ROUTES} routes`, "desktopModelVisibility.routes");
|
|
47
|
+
}
|
|
48
|
+
const routes = new Set<string>();
|
|
49
|
+
for (const route of value.routes) {
|
|
50
|
+
if (typeof route !== "string" || !route.includes("/") || /\s/.test(route) || route.startsWith("/") || route.endsWith("/")) {
|
|
51
|
+
throw new DesktopModelVisibilityError("routes must be provider/model strings", "desktopModelVisibility.routes");
|
|
52
|
+
}
|
|
53
|
+
routes.add(route);
|
|
54
|
+
}
|
|
55
|
+
return { mode: value.mode, routes: [...routes].sort() };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Whether Desktop lists this route under the given visibility (unset lists everything). */
|
|
59
|
+
export function desktopRouteVisible(visibility: DesktopModelVisibility | undefined, route: string): boolean {
|
|
60
|
+
if (!visibility) return true;
|
|
61
|
+
const listed = visibility.routes.includes(route);
|
|
62
|
+
return visibility.mode === "include" ? listed : !listed;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Same desired list, compared order-insensitively (routes are stored sorted). */
|
|
66
|
+
export function sameDesktopModelVisibility(
|
|
67
|
+
left: DesktopModelVisibility | undefined,
|
|
68
|
+
right: DesktopModelVisibility | undefined,
|
|
69
|
+
): boolean {
|
|
70
|
+
if (!left || !right) return !left && !right;
|
|
71
|
+
return left.mode === right.mode && left.routes.join("\n") === right.routes.join("\n");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface FamilyRow {
|
|
75
|
+
anthropicFamilyTier: string;
|
|
76
|
+
isFamilyDefault?: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Drop hidden rows from a generated Desktop list (`routes[i]` is the route of `models[i]`).
|
|
81
|
+
*
|
|
82
|
+
* A hidden family default hands its role to the first remaining member of that family, and
|
|
83
|
+
* the defaults are moved to the front so the written list keeps the shape
|
|
84
|
+
* `renderDesktopProfile` produces: defaults first, in family order, then everything else.
|
|
85
|
+
*/
|
|
86
|
+
export function filterDesktopModelsByVisibility<T extends FamilyRow>(
|
|
87
|
+
models: readonly T[],
|
|
88
|
+
routes: readonly string[],
|
|
89
|
+
visibility: DesktopModelVisibility | undefined,
|
|
90
|
+
): T[] {
|
|
91
|
+
if (!visibility) return [...models];
|
|
92
|
+
const kept = models.filter((_, index) => desktopRouteVisible(visibility, routes[index] ?? ""));
|
|
93
|
+
if (kept.length === models.length) return kept;
|
|
94
|
+
const families: string[] = [];
|
|
95
|
+
for (const model of models) if (!families.includes(model.anthropicFamilyTier)) families.push(model.anthropicFamilyTier);
|
|
96
|
+
const defaults: T[] = [];
|
|
97
|
+
for (const family of families) {
|
|
98
|
+
const members = kept.filter(model => model.anthropicFamilyTier === family);
|
|
99
|
+
const chosen = members.find(model => model.isFamilyDefault) ?? members[0];
|
|
100
|
+
if (chosen) defaults.push(chosen);
|
|
101
|
+
}
|
|
102
|
+
const defaultSet = new Set(defaults);
|
|
103
|
+
return [
|
|
104
|
+
...defaults.map(model => ({ ...model, isFamilyDefault: true })),
|
|
105
|
+
...kept.filter(model => !defaultSet.has(model)).map(({ isFamilyDefault: _drop, ...model }) => model as T),
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The persisted selection, or undefined when unset or unreadable (unreadable lists everything). */
|
|
110
|
+
export function readDesktopModelVisibility(claudeCode: { desktopModelVisibility?: unknown } | undefined): DesktopModelVisibility | undefined {
|
|
111
|
+
if (claudeCode?.desktopModelVisibility === undefined) return undefined;
|
|
112
|
+
try {
|
|
113
|
+
return parseDesktopModelVisibility(claudeCode.desktopModelVisibility);
|
|
114
|
+
} catch {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface AppliedDesktopModel {
|
|
120
|
+
name: string;
|
|
121
|
+
label: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The `inferenceModels` rows of the profile Desktop has selected, for the dashboard's
|
|
126
|
+
* applied count and added/removed preview. `null` when there is no static list to read
|
|
127
|
+
* (no profile, discovery-only, or unreadable): unknown, not empty. Names and labels only.
|
|
128
|
+
*/
|
|
129
|
+
export function readAppliedDesktopModels(selectedProfilePath: string | null): AppliedDesktopModel[] | null {
|
|
130
|
+
if (!selectedProfilePath) return null;
|
|
131
|
+
try {
|
|
132
|
+
const parsed = JSON.parse(readDesktopLibraryText(selectedProfilePath)) as { inferenceModels?: unknown };
|
|
133
|
+
if (!Array.isArray(parsed.inferenceModels)) return null;
|
|
134
|
+
return parsed.inferenceModels.flatMap(row => {
|
|
135
|
+
if (!isPlainObject(row) || typeof row.name !== "string") return [];
|
|
136
|
+
return [{ name: row.name, label: typeof row.labelOverride === "string" ? row.labelOverride : row.name }];
|
|
137
|
+
});
|
|
138
|
+
} catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { chmodSync, lstatSync, mkdirSync, realpathSync, unlinkSync } from "node:fs";
|
|
1
|
+
import { chmodSync, lstatSync, mkdirSync, realpathSync, unlinkSync, type BigIntStats } from "node:fs";
|
|
2
2
|
import { basename, dirname, join, resolve } from "node:path";
|
|
3
3
|
import { atomicWriteFile, getConfigDir } from "../config";
|
|
4
4
|
import { hardenSecretDir } from "../lib/windows-secret-acl";
|
|
@@ -8,7 +8,7 @@ import { DesktopStoreError, digest } from "./desktop-remote-store-state";
|
|
|
8
8
|
export const MAX_DESKTOP_METADATA_ENTRIES = 256;
|
|
9
9
|
|
|
10
10
|
export interface JsonFile { value: Record<string, unknown>; hash: string; identity: string }
|
|
11
|
-
const identity = (s:
|
|
11
|
+
const identity = (s: BigIntStats): string => `${s.dev}:${s.ino}:${s.size}:${s.mtimeNs}`;
|
|
12
12
|
function missing(error: unknown): boolean { return (error as NodeJS.ErrnoException)?.code === "ENOENT"; }
|
|
13
13
|
export function canonicalDirectory(path: string): string {
|
|
14
14
|
const absolute = resolve(path);
|
|
@@ -33,20 +33,20 @@ export class StoreIO {
|
|
|
33
33
|
private bytes = 0;
|
|
34
34
|
private readonly seenSizes = new Map<string, number>();
|
|
35
35
|
read(path: string, maxBytes = 1024 * 1024, privateFile = false): JsonFile | null {
|
|
36
|
-
let stat:
|
|
37
|
-
try { stat = lstatSync(path); }
|
|
36
|
+
let stat: BigIntStats;
|
|
37
|
+
try { stat = lstatSync(path, { bigint: true }); }
|
|
38
38
|
catch (error) { if (missing(error)) return null; throw new DesktopStoreError("unsafe"); }
|
|
39
39
|
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > maxBytes
|
|
40
|
-
|| (privateFile && process.platform !== "win32" && (stat.mode &
|
|
40
|
+
|| (privateFile && process.platform !== "win32" && (stat.mode & 0o077n) !== 0n)) throw new DesktopStoreError("unsafe");
|
|
41
41
|
const counted = this.seenSizes.get(path) ?? 0;
|
|
42
|
-
this.bytes += Math.max(0, stat.size - counted);
|
|
43
|
-
this.seenSizes.set(path, Math.max(counted, stat.size));
|
|
42
|
+
this.bytes += Math.max(0, Number(stat.size) - counted);
|
|
43
|
+
this.seenSizes.set(path, Math.max(counted, Number(stat.size)));
|
|
44
44
|
if (this.bytes > 8 * 1024 * 1024) throw new DesktopStoreError("unsafe");
|
|
45
45
|
try {
|
|
46
46
|
// The shared verified regular-file read keeps a swapped FIFO from parking this
|
|
47
47
|
// open before the post-read identity recheck below can run.
|
|
48
48
|
const bytes = readDesktopLibraryBytes(path, Math.min(maxBytes, MAX_DESKTOP_PROFILE_FILE_BYTES));
|
|
49
|
-
if (bytes.byteLength > maxBytes || identity(lstatSync(path)) !== identity(stat)) throw new DesktopStoreError("conflict");
|
|
49
|
+
if (bytes.byteLength > maxBytes || identity(lstatSync(path, { bigint: true })) !== identity(stat)) throw new DesktopStoreError("conflict");
|
|
50
50
|
const value: unknown = JSON.parse(bytes.toString("utf8"));
|
|
51
51
|
if (!isRecord(value)) throw new DesktopStoreError("unsafe");
|
|
52
52
|
return { value, hash: digest(bytes.toString("utf8")), identity: identity(stat) };
|
|
@@ -42,12 +42,18 @@ export function systemToInstructions(system: unknown): string | undefined {
|
|
|
42
42
|
|
|
43
43
|
export function toolsToResponses(tools: unknown): Rec[] | undefined {
|
|
44
44
|
if (!Array.isArray(tools) || tools.length === 0) return undefined;
|
|
45
|
+
// The shared hosted-search lane cannot enforce these constraints on every destination or
|
|
46
|
+
// sidecar backend. Omit search rather than broaden it; a duplicate declaration cannot opt out.
|
|
47
|
+
// Typed originals still travel separately to an Anthropic destination.
|
|
48
|
+
const restrictedSearch = tools.some(raw => isRec(raw) && typeof raw.type === "string"
|
|
49
|
+
&& raw.type.startsWith("web_search")
|
|
50
|
+
&& ["allowed_domains", "blocked_domains", "user_location"].some(key => Object.hasOwn(raw, key)));
|
|
45
51
|
const out: Rec[] = [];
|
|
46
52
|
for (const raw of tools) {
|
|
47
53
|
if (!isRec(raw)) continue;
|
|
48
54
|
const type = typeof raw.type === "string" ? raw.type : "";
|
|
49
55
|
if (type.startsWith("web_search")) {
|
|
50
|
-
out.push({ type: "web_search" }); // hosted sidecar path
|
|
56
|
+
if (!restrictedSearch) out.push({ type: "web_search" }); // hosted sidecar path
|
|
51
57
|
continue;
|
|
52
58
|
}
|
|
53
59
|
if (typeof raw.name === "string" && raw.name.length > 0 && isRec(raw.input_schema)) {
|
|
@@ -167,6 +173,10 @@ export function toolChoiceToResponses(choice: unknown, body: Rec): void {
|
|
|
167
173
|
// Anthropic represents hosted WebSearch as a named tool choice, while
|
|
168
174
|
// Responses requires the choice type to match the hosted declaration.
|
|
169
175
|
// Preserve forced-tool intent rather than weakening it to `auto`.
|
|
176
|
+
if (isClaudeWebSearchToolName(choice.name)
|
|
177
|
+
&& (!Array.isArray(body.tools) || !body.tools.some(tool => isRec(tool) && tool.type === "web_search"))) {
|
|
178
|
+
throw new AnthropicRequestError("Restricted web search cannot be forced on a translated route without an available search declaration");
|
|
179
|
+
}
|
|
170
180
|
body.tool_choice = isClaudeWebSearchToolName(choice.name)
|
|
171
181
|
? { type: "web_search" }
|
|
172
182
|
: { type: "function", name: choice.name };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import {
|
|
3
3
|
closeSync, constants, fchmodSync, fstatSync, linkSync, lstatSync, mkdirSync,
|
|
4
|
-
openSync, readSync, unlinkSync, writeFileSync, type
|
|
4
|
+
openSync, readSync, unlinkSync, writeFileSync, type BigIntStats,
|
|
5
5
|
} from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { forgetEphemeralSecretPath, hardenSecretDir, hardenSecretPath } from "../../lib/windows-secret-acl";
|
|
@@ -20,15 +20,15 @@ function invalidCredential(): Error {
|
|
|
20
20
|
return new Error("Claude intercept credential is not a safe, valid owner-controlled file");
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function assertOwnedNode(stat:
|
|
23
|
+
function assertOwnedNode(stat: BigIntStats, directory = false): void {
|
|
24
24
|
if (stat.isSymbolicLink() || !(directory ? stat.isDirectory() : stat.isFile())) throw invalidCredential();
|
|
25
|
-
if (process.platform !== "win32" && typeof process.geteuid === "function" && stat.uid !== process.geteuid()) {
|
|
25
|
+
if (process.platform !== "win32" && typeof process.geteuid === "function" && stat.uid !== BigInt(process.geteuid())) {
|
|
26
26
|
throw invalidCredential();
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function assertSameNode(path: string, expected:
|
|
31
|
-
const current = lstatSync(path);
|
|
30
|
+
function assertSameNode(path: string, expected: BigIntStats, directory = false): void {
|
|
31
|
+
const current = lstatSync(path, { bigint: true });
|
|
32
32
|
assertOwnedNode(current, directory);
|
|
33
33
|
if (current.dev !== expected.dev || current.ino !== expected.ino) throw invalidCredential();
|
|
34
34
|
}
|
|
@@ -36,17 +36,17 @@ function assertSameNode(path: string, expected: Stats, directory = false): void
|
|
|
36
36
|
/** Read only through the validated descriptor, with a fixed maximum allocation and no links. */
|
|
37
37
|
function readPinnedToken(configDir: string, harden: boolean): string {
|
|
38
38
|
const dir = join(configDir, "claude-intercept");
|
|
39
|
-
const directory = lstatSync(dir);
|
|
39
|
+
const directory = lstatSync(dir, { bigint: true });
|
|
40
40
|
assertOwnedNode(directory, true);
|
|
41
|
-
if (process.platform !== "win32" && (directory.mode &
|
|
41
|
+
if (process.platform !== "win32" && (directory.mode & 0o077n) !== 0n) throw invalidCredential();
|
|
42
42
|
const path = claudeInterceptProxyTokenPath(configDir);
|
|
43
|
-
const entry = lstatSync(path);
|
|
43
|
+
const entry = lstatSync(path, { bigint: true });
|
|
44
44
|
assertOwnedNode(entry);
|
|
45
45
|
if (entry.size < TOKEN_LENGTH || entry.size > TOKEN_MAX_BYTES) throw invalidCredential();
|
|
46
46
|
// NONBLOCK prevents a raced-in FIFO from blocking before fstat can reject it.
|
|
47
47
|
const fd = openSync(path, constants.O_RDONLY | NOFOLLOW | NONBLOCK);
|
|
48
48
|
try {
|
|
49
|
-
const opened = fstatSync(fd);
|
|
49
|
+
const opened = fstatSync(fd, { bigint: true });
|
|
50
50
|
assertOwnedNode(opened);
|
|
51
51
|
if (opened.dev !== entry.dev || opened.ino !== entry.ino
|
|
52
52
|
|| opened.size < TOKEN_LENGTH || opened.size > TOKEN_MAX_BYTES) throw invalidCredential();
|
|
@@ -62,8 +62,8 @@ function readPinnedToken(configDir: string, harden: boolean): string {
|
|
|
62
62
|
const ending = contents.slice(TOKEN_LENGTH);
|
|
63
63
|
if (token.length !== TOKEN_LENGTH || !/^[A-Za-z0-9_-]+$/.test(token)
|
|
64
64
|
|| !["", "\n", "\r\n"].includes(ending)) throw invalidCredential();
|
|
65
|
-
const afterRead = fstatSync(fd);
|
|
66
|
-
if (length !== afterRead.size || afterRead.
|
|
65
|
+
const afterRead = fstatSync(fd, { bigint: true });
|
|
66
|
+
if (BigInt(length) !== afterRead.size || afterRead.mtimeNs !== opened.mtimeNs) throw invalidCredential();
|
|
67
67
|
assertSameNode(path, opened);
|
|
68
68
|
assertSameNode(dir, directory, true);
|
|
69
69
|
if (harden) {
|
|
@@ -71,7 +71,7 @@ function readPinnedToken(configDir: string, harden: boolean): string {
|
|
|
71
71
|
else fchmodSync(fd, 0o600); // Never chmod a followed/replaced pathname.
|
|
72
72
|
assertSameNode(path, opened);
|
|
73
73
|
assertSameNode(dir, directory, true);
|
|
74
|
-
} else if (process.platform !== "win32" && (afterRead.mode &
|
|
74
|
+
} else if (process.platform !== "win32" && (afterRead.mode & 0o077n) !== 0n) {
|
|
75
75
|
throw invalidCredential();
|
|
76
76
|
}
|
|
77
77
|
return token;
|
|
@@ -89,7 +89,7 @@ export function readClaudeInterceptProxyToken(configDir: string): string | null
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
function ensurePrivateDirectory(configDir: string):
|
|
92
|
+
function ensurePrivateDirectory(configDir: string): BigIntStats {
|
|
93
93
|
const dir = join(configDir, "claude-intercept");
|
|
94
94
|
mkdirSync(configDir, { recursive: true, mode: 0o700 });
|
|
95
95
|
try {
|
|
@@ -97,14 +97,14 @@ function ensurePrivateDirectory(configDir: string): Stats {
|
|
|
97
97
|
} catch (error) {
|
|
98
98
|
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
99
99
|
}
|
|
100
|
-
const entry = lstatSync(dir);
|
|
100
|
+
const entry = lstatSync(dir, { bigint: true });
|
|
101
101
|
assertOwnedNode(entry, true);
|
|
102
102
|
if (process.platform === "win32") {
|
|
103
103
|
hardenSecretDir(dir, { required: true });
|
|
104
104
|
} else {
|
|
105
105
|
const fd = openSync(dir, constants.O_RDONLY | (constants.O_DIRECTORY ?? 0) | NOFOLLOW);
|
|
106
106
|
try {
|
|
107
|
-
const opened = fstatSync(fd);
|
|
107
|
+
const opened = fstatSync(fd, { bigint: true });
|
|
108
108
|
assertOwnedNode(opened, true);
|
|
109
109
|
if (entry.dev !== opened.dev || entry.ino !== opened.ino) throw invalidCredential();
|
|
110
110
|
fchmodSync(fd, 0o700);
|
|
@@ -130,7 +130,7 @@ export function ensureClaudeInterceptProxyToken(configDir: string): string {
|
|
|
130
130
|
const token = randomBytes(32).toString("base64url");
|
|
131
131
|
const temp = join(dir, `.${TOKEN_FILE}.${process.pid}.${randomBytes(8).toString("hex")}.tmp`);
|
|
132
132
|
const fd = openSync(temp, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | NOFOLLOW, 0o600);
|
|
133
|
-
const created = fstatSync(fd);
|
|
133
|
+
const created = fstatSync(fd, { bigint: true });
|
|
134
134
|
try {
|
|
135
135
|
writeFileSync(fd, `${token}\n`, { encoding: "utf8" });
|
|
136
136
|
if (process.platform !== "win32") fchmodSync(fd, 0o600);
|
package/src/cli/account-main.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { redactSecretArgs } from "./secret-args";
|
|
|
3
3
|
import { codexExecInvocation } from "../codex/exec-invocation";
|
|
4
4
|
import { validatedCodexExecInvocationAsync, type CodexExecBoundaryAsyncDeps } from "../codex/exec-boundary";
|
|
5
5
|
import { resolveAndPersistCodexRuntime, type ResolveCodexRuntimeDeps } from "../codex/runtime";
|
|
6
|
+
import { withCodexCliSelectionParentWriteAsync } from "../codex/cli-update-selection-gate";
|
|
6
7
|
import type { ResolveDeps, SpawnInvocation } from "../lib/win-exec";
|
|
7
8
|
import {
|
|
8
9
|
apiError,
|
|
@@ -62,7 +63,7 @@ export async function nativeMainCodexLoginValidatedInvocation(
|
|
|
62
63
|
deps: NativeMainCodexLoginValidatedDeps = {},
|
|
63
64
|
): Promise<SpawnInvocation> {
|
|
64
65
|
const env = deps.env ?? process.env;
|
|
65
|
-
const command = resolveAndPersistCodexRuntime({
|
|
66
|
+
const command = (await withCodexCliSelectionParentWriteAsync(() => resolveAndPersistCodexRuntime({
|
|
66
67
|
env,
|
|
67
68
|
platform,
|
|
68
69
|
existsSync: deps.existsSync,
|
|
@@ -70,7 +71,7 @@ export async function nativeMainCodexLoginValidatedInvocation(
|
|
|
70
71
|
configDir: deps.configDir,
|
|
71
72
|
readFileSync: deps.readFileSync,
|
|
72
73
|
discoverAlternatives: false,
|
|
73
|
-
}).runtime.command || "codex";
|
|
74
|
+
}), { configDir: deps.configDir, signal: deps.signal })).runtime.command || "codex";
|
|
74
75
|
return validatedCodexExecInvocationAsync(command, ["login"], {
|
|
75
76
|
env,
|
|
76
77
|
platform,
|
|
@@ -79,6 +79,13 @@ export const PROVIDER_MODEL_CAPABILITIES: readonly Capability[] = [
|
|
|
79
79
|
flags: [{ name: "--set", value: "string", summary: "Replace with comma-separated upstream IDs." }, { name: "--clear", value: "boolean", summary: "Clear the allowlist to show all; exclusive with --set." }, { name: "--json", value: "boolean", summary: "Emit the selected view or receipt." }],
|
|
80
80
|
details: ["Without a mutation flag this reads only. --clear sends models:[], not a model named -.", "Read JSON is the CLI projection {provider, selected: string[], available: string[]}, not the API's provider-keyed maps; missing entries become empty arrays. --set/--clear JSON returns the server's write receipt unchanged."],
|
|
81
81
|
},
|
|
82
|
+
{
|
|
83
|
+
command: ["provider", "import-cc-switch"], summary: "Preview, apply, or restore keyless CC-Switch provider entries locally.",
|
|
84
|
+
usage: "ocx provider import-cc-switch [--source <cc-switch.db|config.json>] [--provider <id>]... [--apply | --restore] [--allow-private-network] [--json]",
|
|
85
|
+
routes: [], mutates: true, json: "payload",
|
|
86
|
+
flags: [{ name: "--source", value: "string", summary: "CC-Switch SQLite database or legacy JSON file; required for preview and apply." }, { name: "--provider", value: "string", summary: "Repeatable source ID or target provider name filter." }, { name: "--apply", value: "boolean", summary: "Write eligible keyless provider entries and record a rollback journal; requires a stopped proxy." }, { name: "--restore", value: "boolean", summary: "Remove unedited keyless providers recorded by the active import journal; requires a stopped proxy." }, { name: "--allow-private-network", value: "boolean", summary: "Permit loopback or private-network provider base URLs." }, { name: "--json", value: "boolean", summary: "Emit the preview, apply, or restore report as JSON." }],
|
|
87
|
+
details: ["Projects values only from an explicit allowlist of non-secret metadata fields (provider IDs, app types, base URLs, wire dialects, and default models); source and embedded-config bytes are read transiently while secret fields, free-text names, and TOML comments are skipped at the byte level and never decoded into strings, written, or logged, and transient byte buffers are zeroed in finally.", "Only import from a trusted local CC-Switch source: apply prints every imported ID, model, and destination URL before writing, refuses SQLite hard links (nlink > 1) and non-empty -wal/-journal sidecars until CC-Switch is closed, and opens sources read-only with O_NOFOLLOW|O_NONBLOCK descriptor checks; restore inspects auth.json read-only at the byte level and retains any provider that was edited, selected as defaultProvider, or referenced by routing, combos, fallback policy, OAuth accounts, or API keys."],
|
|
88
|
+
},
|
|
82
89
|
{
|
|
83
90
|
command: ["models", "list"], summary: "List static configured models locally.",
|
|
84
91
|
usage: "ocx models list [--provider <name>] [--json]", routes: [], mutates: false, json: "envelope",
|
|
@@ -164,7 +164,7 @@ CODEX_CLI_PATH launcher: ${app.shim === null ? "unknown" : app.shim ? "yes" : "n
|
|
|
164
164
|
console.error("ChatGPT process inspection failed; no launcher was changed and no app was opened. Retry after resolving inspection.");
|
|
165
165
|
return 1;
|
|
166
166
|
}
|
|
167
|
-
if (binary) writeChatgptShimLauncher(undefined, binary);
|
|
167
|
+
if (binary) writeChatgptShimLauncher(undefined, binary, install.root);
|
|
168
168
|
if (!(await quitApp(install, launcher))) {
|
|
169
169
|
console.error("ChatGPT exit could not be confirmed; no new app was opened. Check the running app and retry.");
|
|
170
170
|
return 1;
|
|
@@ -25,13 +25,13 @@ import { spawn } from "node:child_process";
|
|
|
25
25
|
import { loadConfig } from "../config";
|
|
26
26
|
import { getCodexRoutingKind, type CodexRoutingKind } from "../codex/inject";
|
|
27
27
|
import { inspectCodexShimBackingForCommand } from "../codex/shim";
|
|
28
|
+
import { validatedCodexExecInvocationAsync, type CodexExecBoundaryAsyncDeps } from "../codex/exec-boundary";
|
|
28
29
|
import { CODEX_GLOBAL_OPTIONS_WITH_VALUE, CODEX_INTERNAL_COMMANDS, CODEX_SHIM_ENSURE_FAILED_DIAGNOSTIC } from "../codex/shim-templates";
|
|
29
30
|
import { withoutSiblingMarker } from "../codex/sibling-start";
|
|
30
31
|
import { withProcessRuntimeProvenance } from "../lib/bun-runtime";
|
|
31
32
|
import { tokenCollidesWithAdmin } from "../lib/admin-secrets";
|
|
32
33
|
import { selfLaunchArgv } from "../lib/self-launch-argv";
|
|
33
34
|
import { loadServiceTokenFromFile, serviceApiTokenFilePath } from "../lib/service-secrets";
|
|
34
|
-
import { commandInvocation } from "../lib/win-exec";
|
|
35
35
|
import { findExecutableOnPath } from "../remote-control/workspace-executable";
|
|
36
36
|
import { findLiveProxy, type LiveProxy } from "../server/proxy-liveness";
|
|
37
37
|
import { codexCredentialDestinationIsTrusted, resolveCodexLaunchHome } from "./codex-launch-auth";
|
|
@@ -265,14 +265,26 @@ export function resolveCodexLaunchCommand(
|
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
export interface CodexSpawnDeps extends CodexLaunchCommandDeps {
|
|
269
|
+
execBoundary?: CodexExecBoundaryAsyncDeps;
|
|
270
|
+
spawn?: typeof spawn;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Validate the final backing command immediately before each launch, including fast paths. */
|
|
274
|
+
export async function spawnCodex(args: readonly string[], env: CodexLaunchEnv, deps: CodexSpawnDeps = {}): Promise<number> {
|
|
275
|
+
let launch: CodexLaunchCommand, inv: Awaited<ReturnType<typeof validatedCodexExecInvocationAsync>>;
|
|
276
|
+
try {
|
|
277
|
+
launch = resolveCodexLaunchCommand(env, deps);
|
|
278
|
+
inv = await validatedCodexExecInvocationAsync(launch.command, args, { ...deps.execBoundary, verifyAnyAppBundle: true, env: launch.env as NodeJS.ProcessEnv });
|
|
279
|
+
} catch (error) {
|
|
280
|
+
// A selected executable that vanished before verification is the same missing CLI
|
|
281
|
+
// the spawn-time ENOENT branch below reports, not a trust refusal.
|
|
282
|
+
const missing = error instanceof CodexNotFoundError || (error as NodeJS.ErrnoException | null)?.code === "ENOENT";
|
|
283
|
+
console.error(missing ? CODEX_INSTALL_HINT : `❌ Cannot launch codex: ${error instanceof Error ? error.message : "executable verification failed"}`);
|
|
284
|
+
return 1;
|
|
285
|
+
}
|
|
270
286
|
return new Promise<number>(resolve => {
|
|
271
|
-
|
|
272
|
-
try { launch = resolveCodexLaunchCommand(env); }
|
|
273
|
-
catch (error) { console.error(error instanceof CodexNotFoundError ? CODEX_INSTALL_HINT : CODEX_UNVERIFIED_SHIM); resolve(1); return; }
|
|
274
|
-
const inv = commandInvocation(launch.command, args);
|
|
275
|
-
const child = spawn(inv.file, inv.args, { stdio: "inherit", env: launch.env as NodeJS.ProcessEnv, ...inv.options });
|
|
287
|
+
const child = (deps.spawn ?? spawn)(inv.file, inv.args, { stdio: "inherit", env: launch.env as NodeJS.ProcessEnv, ...inv.options });
|
|
276
288
|
child.on("error", (err: NodeJS.ErrnoException) => {
|
|
277
289
|
if (err.code === "ENOENT") {
|
|
278
290
|
console.error(CODEX_INSTALL_HINT);
|