@bitkyc08/opencodex 2.94.0 → 2.96.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/gui/dist/assets/App-B4j-Txmb.css +1 -0
- package/gui/dist/assets/App-bwugJRKn.js +58 -0
- package/gui/dist/assets/{Tray-CZatQdoF.js → Tray-BOPQyDbH.js} +1 -1
- package/gui/dist/assets/index-ebuVUtB7.js +94 -0
- package/gui/dist/assets/quota-summary-6HsrHQAy.js +1 -0
- package/gui/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/adapters/anthropic.ts +10 -3
- package/src/adapters/command-code-project-context.ts +3 -3
- package/src/adapters/kiro/adapter.ts +4 -1
- package/src/adapters/kiro/stream.ts +1 -0
- package/src/adapters/kiro-events.ts +1 -0
- package/src/adapters/ollama-native.ts +10 -6
- package/src/adapters/openai-chat/messages.ts +20 -7
- package/src/adapters/openai-chat/passthrough.ts +4 -2
- package/src/adapters/openai-chat/single-system.ts +24 -0
- package/src/adapters/openai-responses/canonical-forward.ts +50 -13
- package/src/adapters/openai-responses/muse-tool-catalog.ts +87 -0
- package/src/adapters/openai-responses/passthrough.ts +45 -11
- package/src/adapters/openai-responses/prompt-cache.ts +3 -1
- package/src/adapters/openai-responses/request-strips.ts +23 -4
- package/src/adapters/openai-responses/tool-output-recovery.ts +21 -8
- package/src/adapters/openai-responses/tool-schema.ts +20 -8
- package/src/adapters/openai-responses/transport.ts +17 -26
- package/src/adapters/opencode-go-additional-tools.ts +39 -6
- package/src/adapters/qoder/adapter.ts +1 -1
- package/src/adapters/qoder/image-input.ts +5 -2
- package/src/adapters/routed-agent-messages.ts +3 -0
- package/src/adapters/xai-web-search.ts +6 -3
- package/src/adapters/zed-additional-tools.ts +7 -7
- package/src/adapters/zed.ts +1 -6
- package/src/advisor/consult.ts +22 -10
- package/src/advisor/runtime.ts +10 -4
- package/src/bridge/max-output-completion.ts +41 -0
- package/src/bridge/response-json.ts +9 -4
- package/src/bridge/sse.ts +13 -2
- package/src/chatgpt/app-server-shim/bundle-trust-policy.ts +5 -0
- package/src/chatgpt/app-server-shim/launcher.ts +40 -6
- package/src/claude/compatibility.ts +5 -1
- package/src/claude/desktop-3p.ts +27 -6
- package/src/claude/desktop-model-visibility.ts +141 -0
- package/src/claude/desktop-remote-store-io.ts +8 -8
- package/src/claude/inbound-content-options.ts +11 -1
- package/src/claude/intercept/proxy-auth.ts +16 -16
- package/src/cli/account-main.ts +3 -2
- package/src/cli/agent.ts +44 -15
- package/src/cli/capabilities-agents-routing.ts +9 -0
- package/src/cli/capabilities-provider-models.ts +7 -0
- package/src/cli/chatgpt-command.ts +1 -1
- package/src/cli/codex-launcher.ts +20 -8
- package/src/cli/codex-shim-autorestore.ts +19 -1
- package/src/cli/dispatch.ts +6 -6
- package/src/cli/doctor.ts +5 -5
- package/src/cli/ensure-desired-integrations.ts +4 -3
- package/src/cli/index.ts +8 -10
- package/src/cli/init.ts +2 -2
- package/src/cli/internal-command.ts +29 -2
- package/src/cli/message-command.ts +2 -1
- package/src/cli/message-mcp-command.ts +29 -0
- package/src/cli/provider-cc-switch-import.ts +185 -0
- package/src/cli/provider.ts +5 -0
- package/src/cli/registry.ts +2 -1
- package/src/cli/restart-scope.ts +2 -2
- package/src/cli/root.ts +6 -6
- package/src/cli/stop-approval.ts +15 -1
- package/src/cli/v2.ts +69 -19
- package/src/client/machine-api.ts +2 -2
- package/src/clients/config-export.ts +14 -3
- package/src/codex/account-cooldown-response.ts +18 -0
- package/src/codex/account-store.ts +1 -0
- package/src/codex/app-server-restart-service.ts +2 -2
- package/src/codex/auth-api/login-flow.ts +2 -2
- package/src/codex/auth-api/pool-quota-probe.ts +2 -2
- package/src/codex/auth-context-provider.ts +15 -0
- package/src/codex/auth-context.ts +14 -23
- package/src/codex/catalog/bundled.ts +10 -3
- package/src/codex/catalog/metadata.ts +4 -5
- package/src/codex/catalog/native-omission.ts +28 -0
- package/src/codex/catalog/native-template.ts +58 -0
- package/src/codex/catalog/parsing.ts +3 -29
- package/src/codex/catalog/provider-models.ts +2 -1
- package/src/codex/catalog/retained-sync.ts +15 -5
- package/src/codex/catalog/write-audit.ts +18 -18
- package/src/codex/cli-install-provenance.ts +46 -45
- package/src/codex/cli-update-artifacts.ts +8 -6
- package/src/codex/cli-update-job-store-windows.ts +99 -27
- package/src/codex/cli-update-job-worker.ts +3 -11
- package/src/codex/cli-update-recovery.ts +54 -8
- package/src/codex/cli-update-selection-gate.ts +74 -4
- package/src/codex/cli-windows-plan-provenance.ts +37 -19
- package/src/codex/codex-home-owner.ts +9 -8
- package/src/codex/convergence.ts +13 -3
- package/src/codex/coordinator-doctor.ts +14 -8
- package/src/codex/desktop-app/handoff.ts +1 -1
- package/src/codex/desktop-app-restart.ts +11 -1
- package/src/codex/exec-boundary.ts +26 -5
- package/src/codex/forward-transport-headers.ts +33 -33
- package/src/codex/history-provider.ts +11 -10
- package/src/codex/inject/bounded-config-reader.ts +14 -13
- package/src/codex/installation-id.ts +72 -0
- package/src/codex/main-account.ts +6 -6
- package/src/codex/native-main-lock-file.ts +13 -12
- package/src/codex/native-residue.ts +18 -14
- package/src/codex/orca-auth-source.ts +8 -7
- package/src/codex/quota-types.ts +5 -0
- package/src/codex/quota.ts +49 -7
- package/src/codex/role-auto-assign.ts +50 -26
- package/src/codex/role-capability.ts +160 -0
- package/src/codex/role-sizing.ts +24 -6
- package/src/codex/routing/cooldown-math.ts +3 -2
- package/src/codex/runtime.ts +43 -3
- package/src/codex/shim-fingerprint.ts +11 -9
- package/src/codex/shim-inspect.ts +3 -2
- package/src/codex/shim-restore-lock.ts +11 -14
- package/src/codex/shim-state-file.ts +22 -14
- package/src/codex/shim-wrapper-write.ts +7 -6
- package/src/codex/shim.ts +25 -2
- package/src/codex/transition-state.ts +5 -4
- package/src/combos/failover.ts +43 -4
- package/src/config/atomic-write.ts +38 -7
- package/src/config/diagnostics.ts +3 -0
- package/src/config/initialize.ts +6 -6
- package/src/config/load-degrade.ts +2 -0
- package/src/config/process-state.ts +23 -5
- package/src/config/salvage.ts +1 -0
- package/src/config/schema/config-schema.ts +29 -1
- package/src/config/schema/leaf-validators.ts +7 -0
- package/src/config/schema/workflow-budget.ts +43 -0
- package/src/config/tracked-runtime-inspection.ts +188 -0
- package/src/generated/compatibility-version.json +380 -244
- package/src/grok/sync.ts +10 -1
- package/src/integrations/aside-profile-context.ts +1 -1
- package/src/integrations/droid-settings.ts +4 -4
- package/src/integrations/hermes-profiles.ts +3 -3
- package/src/lib/bounded-file-read.ts +3 -9
- package/src/lib/bun-runtime-preflight.ts +9 -8
- package/src/lib/file-identity.ts +15 -0
- package/src/lib/local-chat-completion.ts +8 -6
- package/src/lib/local-destinations.ts +32 -3
- package/src/lib/redact-folding.ts +9 -0
- package/src/lib/spend-pool-alias-validation.ts +6 -6
- package/src/lib/state-store-registrations.ts +2 -0
- package/src/lib/test-home-guard.ts +37 -9
- package/src/lib/windows-secret-acl.ts +49 -31
- package/src/lib/workflow-budget-config.ts +39 -0
- package/src/local-credentials/generation.ts +6 -2
- package/src/local-credentials/inventory.ts +132 -8
- package/src/messaging/mcp-queue-rpc.ts +102 -0
- package/src/messaging/mcp-queue-server.ts +42 -0
- package/src/messaging/mcp-queue-tools.ts +39 -0
- package/src/messaging/remote-forward-failure.ts +35 -0
- package/src/messaging/remote-ports.ts +27 -5
- package/src/messaging/remote-process.ts +30 -4
- package/src/messaging/remote-tunnels.ts +80 -15
- package/src/oauth/anthropic-identity.ts +2 -6
- package/src/oauth/antigravity-discovery-diagnostics.ts +65 -0
- package/src/oauth/google-antigravity.ts +23 -10
- package/src/oauth/index.ts +7 -0
- package/src/oauth/kiro-device-login.ts +87 -30
- package/src/oauth/kiro-iam-identity-center.ts +107 -0
- package/src/oauth/store.ts +9 -7
- package/src/providers/account-quota-disk.ts +18 -4
- package/src/providers/anthropic-subscription.ts +25 -0
- package/src/providers/cc-switch-import-bytes.ts +991 -0
- package/src/providers/cc-switch-import-source.ts +1083 -0
- package/src/providers/cc-switch-import.ts +942 -0
- package/src/providers/claude-cli-usage.ts +15 -67
- package/src/providers/derive.ts +6 -0
- package/src/providers/model-discovery-diagnostic.ts +4 -0
- package/src/providers/model-discovery.ts +4 -4
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/model-rename-migration.ts +41 -6
- package/src/providers/quota/anthropic-decision-windows.ts +5 -19
- package/src/providers/quota/anthropic-usage-windows.ts +55 -0
- package/src/providers/quota/report-cache.ts +17 -4
- package/src/providers/quota.ts +2 -2
- package/src/providers/reasoning-metadata.ts +31 -15
- package/src/providers/registry/entries-core.ts +1 -1
- package/src/providers/registry/entries-extended.ts +1 -1
- package/src/providers/registry/model-ids.ts +1 -0
- package/src/providers/registry/model-seeds.ts +2 -1
- package/src/providers/registry/types.ts +3 -1
- package/src/providers/resolved-model-policy.ts +2 -2
- package/src/providers/routed-config.ts +2 -0
- package/src/providers/stale-model-roster-migration.ts +5 -1
- package/src/providers/xai-transport.ts +4 -4
- package/src/remote-control/workspace-codex-runtime.ts +2 -2
- package/src/remote-control/workspace-executor.ts +14 -13
- package/src/responses/custom-tool-compat.ts +2 -1
- package/src/responses/item-provenance.ts +79 -0
- package/src/responses/namespace-tool-compat.ts +21 -3
- package/src/responses/parser-tools.ts +1 -0
- package/src/responses/schema.ts +5 -2
- package/src/router.ts +21 -2
- package/src/routing/analytics.ts +3 -5
- package/src/routing/fallback-policy.ts +7 -3
- package/src/routing/health.ts +5 -3
- package/src/routing/history/build-file.ts +6 -0
- package/src/routing/history/indexer.ts +158 -31
- package/src/routing/history/ingest.ts +1 -1
- package/src/routing/history/integrity.ts +208 -0
- package/src/routing/history/rebuild-job.ts +20 -6
- package/src/routing/history/rebuild-protocol.ts +2 -1
- package/src/routing/history/rebuild-worker.ts +18 -0
- package/src/routing/history/sqlite-errors.ts +9 -0
- package/src/server/admission-model-scope.ts +21 -4
- package/src/server/advisor-admission-scope.ts +29 -0
- package/src/server/audio-dictation.ts +3 -0
- package/src/server/audio-live.ts +8 -2
- package/src/server/audio-upstream.ts +2 -0
- package/src/server/auth-cors.ts +5 -2
- package/src/server/capture-admission-policy.ts +91 -0
- package/src/server/chat-completions.ts +33 -7
- package/src/server/claude-messages.ts +93 -2
- package/src/server/codex-model-list.ts +2 -1
- package/src/server/configured-credentials.ts +5 -0
- package/src/server/context-history.ts +9 -6
- package/src/server/images.ts +14 -5
- package/src/server/index/live-sideband.ts +16 -2
- package/src/server/index/serve-options.ts +13 -2
- package/src/server/index/websocket-handler.ts +4 -1
- package/src/server/live.ts +30 -5
- package/src/server/management/agent-settings-routes.ts +34 -9
- package/src/server/management/codex-agent-role-routes.ts +1 -0
- package/src/server/management/codex-role-auto-assign.ts +50 -6
- package/src/server/management/config-routes.ts +15 -4
- package/src/server/management/context.ts +3 -0
- package/src/server/management/native-integration-routes.ts +22 -0
- package/src/server/management/oauth-account-routes.ts +20 -4
- package/src/server/management/provider-overwrite-carry.ts +21 -0
- package/src/server/management/provider-routes.ts +3 -1
- package/src/server/management/route-registry.ts +2 -0
- package/src/server/management/shared.ts +17 -1
- package/src/server/management/workflow-budget-routes.ts +70 -3
- package/src/server/messages-native-eligibility.ts +6 -5
- package/src/server/messages-native-scope.ts +6 -1
- package/src/server/messages-shared.ts +57 -17
- package/src/server/persistent-gui-session.ts +4 -4
- package/src/server/request-log.ts +30 -2
- package/src/server/responses/adapter-delivery.ts +4 -0
- package/src/server/responses/adapter-dispatch.ts +5 -0
- package/src/server/responses/advisor-plan-slot.ts +4 -0
- package/src/server/responses/advisor-slot.ts +73 -46
- package/src/server/responses/codex-auth-error.ts +9 -1
- package/src/server/responses/combo-required-tool-contract.ts +39 -0
- package/src/server/responses/compact.ts +41 -20
- package/src/server/responses/core-codex-account.ts +17 -6
- package/src/server/responses/core-combo-failure.ts +2 -0
- package/src/server/responses/core-combo.ts +70 -5
- package/src/server/responses/core-lifetime.ts +4 -0
- package/src/server/responses/core-normalize.ts +7 -1
- package/src/server/responses/core-options.ts +9 -0
- package/src/server/responses/core.ts +2 -0
- package/src/server/responses/jev-model-invoke.ts +4 -2
- package/src/server/responses/passthrough-build-error.ts +36 -0
- package/src/server/responses/passthrough-dispatch.ts +10 -24
- package/src/server/responses/policy-fallback.ts +2 -0
- package/src/server/responses/request-prepare.ts +4 -5
- package/src/server/responses/request-send-budget.ts +2 -1
- package/src/server/responses/request-sidecar-auth.ts +4 -1
- package/src/server/responses/request-transport.ts +2 -3
- package/src/server/responses/run-turn-execution.ts +4 -0
- package/src/server/responses/sidecar-execution.ts +21 -5
- package/src/server/responses-snapshot-repair.ts +18 -4
- package/src/server/responses-undeclared-tool-guard.ts +4 -0
- package/src/server/search.ts +13 -4
- package/src/server/workflow-refusal.ts +2 -1
- package/src/server/ws-bridge.ts +5 -2
- package/src/service/state-lock.ts +12 -11
- package/src/service-manager-probe.ts +53 -8
- package/src/types/admission-policy.ts +13 -0
- package/src/types/config.ts +25 -0
- package/src/types/provider.ts +10 -0
- package/src/types/request.ts +7 -0
- package/src/types.ts +1 -0
- package/src/update/job.ts +20 -0
- package/src/update/worker-launch.ts +71 -1
- package/src/usage/log.ts +25 -4
- package/src/vision/describe.ts +4 -7
- package/src/vision/index.ts +2 -0
- package/src/vision/plan.ts +4 -0
- package/src/vision/routed-describe.ts +38 -23
- package/src/web-search/executor.ts +4 -7
- package/src/web-search/loop.ts +104 -9
- package/src/web-search/parse.ts +10 -2
- package/gui/dist/assets/App-DMps4OLk.css +0 -1
- package/gui/dist/assets/App-DmvwlhQq.js +0 -58
- package/gui/dist/assets/index-3EPO_KbX.js +0 -94
- package/gui/dist/assets/quota-summary-BHvWg9mi.js +0 -1
|
@@ -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,
|
package/src/cli/agent.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CliUsageError,
|
|
3
|
+
RuntimeApiError,
|
|
3
4
|
csv,
|
|
4
5
|
desktopSwitchApplyReason,
|
|
5
6
|
printData,
|
|
@@ -345,27 +346,48 @@ async function suggestRoles(args: string[], wantsJson: boolean, deps: RuntimeApi
|
|
|
345
346
|
);
|
|
346
347
|
const proposals = result.proposals ?? [];
|
|
347
348
|
const applied: Array<{ role: string; model: string; effort?: string }> = [];
|
|
348
|
-
const skipped
|
|
349
|
+
const skipped = apply ? proposals.filter(p => p.status === "proposed" && p.proposedModel && proposalAlreadySet(p)).map(p => p.role) : [];
|
|
350
|
+
const changes = proposals.filter((p): p is CodexRoleProposal & { proposedModel: string } =>
|
|
351
|
+
p.status === "proposed" && !!p.proposedModel && !proposalAlreadySet(p));
|
|
352
|
+
const { ROLE_HISTORY_LIMIT } = await import("../codex/role-model-history");
|
|
349
353
|
const omoJsoncNotWritten: Array<{ role: string; status: string }> = [];
|
|
354
|
+
let batch: string | undefined;
|
|
355
|
+
let failure: { cause: unknown; unconfirmedRole: string; unattemptedRoles: string[] } | undefined;
|
|
350
356
|
if (apply) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
357
|
+
// Splitting into several batches would hide earlier changes from the bounded Restore list.
|
|
358
|
+
if (changes.length > ROLE_HISTORY_LIMIT) {
|
|
359
|
+
const message = `${changes.length} changed proposals exceed the ${ROLE_HISTORY_LIMIT}-role batch limit. No role files were written. Preview without --apply and use 'ocx agent roles set' for individual changes.`;
|
|
360
|
+
printData({ ...result, applied, skipped, omoJsoncNotWritten, complete: false,
|
|
361
|
+
refusal: { code: "too_many_role_changes", limit: ROLE_HISTORY_LIMIT, count: changes.length },
|
|
362
|
+
unattemptedRoles: changes.map(p => p.role) }, wantsJson, [message]);
|
|
363
|
+
throw new RuntimeApiError(message, 409, null);
|
|
364
|
+
}
|
|
365
|
+
for (const [index, proposal] of changes.entries()) {
|
|
366
|
+
const body = {
|
|
367
|
+
model: proposal.proposedModel,
|
|
368
|
+
...(proposal.proposedEffort ? { effort: proposal.proposedEffort } : {}),
|
|
369
|
+
...(batch ? { batch } : {}),
|
|
370
|
+
};
|
|
371
|
+
let written: { batch?: string; omoJsonc?: { status?: string } } | null;
|
|
372
|
+
try {
|
|
373
|
+
written = await runtimeRequest<typeof written>(
|
|
374
|
+
`/api/codex-agent-roles/${encodeURIComponent(proposal.role)}`,
|
|
375
|
+
{ method: "PUT", body: JSON.stringify(body) },
|
|
376
|
+
deps,
|
|
377
|
+
);
|
|
378
|
+
} catch (cause) {
|
|
379
|
+
// A lost response can follow a persisted write: report uncertainty and do not replay it.
|
|
380
|
+
failure = { cause, unconfirmedRole: proposal.role, unattemptedRoles: changes.slice(index + 1).map(p => p.role) };
|
|
381
|
+
break;
|
|
356
382
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
`/api/codex-agent-roles/${encodeURIComponent(proposal.role)}`,
|
|
360
|
-
{ method: "PUT", body: JSON.stringify(body) },
|
|
361
|
-
deps,
|
|
362
|
-
);
|
|
363
|
-
applied.push({ role: proposal.role, ...body });
|
|
383
|
+
batch = written?.batch ?? batch;
|
|
384
|
+
applied.push({ role: proposal.role, model: body.model, ...(proposal.proposedEffort ? { effort: proposal.proposedEffort } : {}) });
|
|
364
385
|
const omoStatus = written?.omoJsonc?.status;
|
|
365
386
|
if (omoStatus && OMO_JSONC_NOT_WRITTEN.has(omoStatus)) omoJsoncNotWritten.push({ role: proposal.role, status: omoStatus });
|
|
366
387
|
}
|
|
367
388
|
}
|
|
368
|
-
printData(apply ? { ...result, applied, skipped, omoJsoncNotWritten } :
|
|
389
|
+
printData(apply ? { ...result, applied, skipped, omoJsoncNotWritten, ...(batch ? { batch } : {}),
|
|
390
|
+
...(failure ? { complete: false, unconfirmedRole: failure.unconfirmedRole, unattemptedRoles: failure.unattemptedRoles } : {}) } : result, wantsJson, [
|
|
369
391
|
`Sized with ${result.sizingModel ?? "unknown"}.`,
|
|
370
392
|
...proposals.map(p => p.status === "unsized"
|
|
371
393
|
? `${p.role}: not sized (${p.reason ?? "unknown"})`
|
|
@@ -374,9 +396,16 @@ async function suggestRoles(args: string[], wantsJson: boolean, deps: RuntimeApi
|
|
|
374
396
|
: `${p.role}: ${p.model ?? "(no pin)"} -> ${p.proposedModel}${p.proposedEffort ? ` (${p.proposedEffort})` : ""} [${p.tier}/${p.effortIntent}] ${p.rationale ?? ""}`),
|
|
375
397
|
apply
|
|
376
398
|
? `Applied ${applied.length} of ${proposals.length} roles.${skipped.length > 0 ? ` Skipped ${skipped.length} already set: ${skipped.join(", ")}.` : ""}`
|
|
377
|
-
:
|
|
399
|
+
: `Nothing was written; --apply accepts up to ${ROLE_HISTORY_LIMIT} changed roles in one batch. Use 'ocx agent roles set' for individual changes.`,
|
|
378
400
|
...omoJsoncNotWritten.map(entry => `${entry.role}: omo.jsonc not written (${entry.status}); the role TOML was updated.`),
|
|
401
|
+
...(batch ? [`Recorded history batch: ${batch}. Restore uses the retained changes in the dashboard's Change history.`] : []),
|
|
402
|
+
...(failure ? [
|
|
403
|
+
`Confirmed writes: ${applied.map(p => p.role).join(", ") || "none"}.`,
|
|
404
|
+
`Write not confirmed for ${failure.unconfirmedRole}; it may have been saved. Not attempted: ${failure.unattemptedRoles.join(", ") || "none"}.`,
|
|
405
|
+
"Earlier writes remain applied. Inspect 'ocx agent roles --json' before retrying.",
|
|
406
|
+
] : []),
|
|
379
407
|
]);
|
|
408
|
+
if (failure) throw failure.cause;
|
|
380
409
|
}
|
|
381
410
|
|
|
382
411
|
async function roles(argv: string[], deps: RuntimeApiDeps): Promise<void> {
|
|
@@ -26,6 +26,15 @@ export const AGENT_ROUTING_CAPABILITIES: readonly Capability[] = [
|
|
|
26
26
|
"queued means submitted, not processed. unknown must not be replayed; no automatic retry, daemon start or thread resume.",
|
|
27
27
|
"Exit 0: queued; 1: not sent; 3: unknown; 64: invalid usage. No Claude transport, native lifecycle mutation or skill installation."],
|
|
28
28
|
},
|
|
29
|
+
{
|
|
30
|
+
command: ["message", "mcp"], usage: "ocx message mcp --codex <absolute-cli-path> --codex-home <absolute-existing-home>",
|
|
31
|
+
summary: "Serve opt-in MCP tools for stored Codex metadata and queued text delivery over stdio.",
|
|
32
|
+
routes: [], mutates: true, json: "none",
|
|
33
|
+
flags: [{ name: "--codex", value: "string", required: true, summary: "Explicit local Codex CLI executable." },
|
|
34
|
+
{ name: "--codex-home", value: "string", required: true, summary: "Explicit existing Codex home; no creation or login." }],
|
|
35
|
+
details: ["macOS/Linux only. No proxy/control socket required. Starts bounded stdio helpers only when a tool is called; existing sessions/send behavior stays unchanged.",
|
|
36
|
+
"Stored threads are not verified live sessions. queued is not processing; unknown is never replayed. No daemon start, thread resume, steer, automatic replies or registration."],
|
|
37
|
+
},
|
|
29
38
|
{
|
|
30
39
|
command: ["advisor"],
|
|
31
40
|
summary: "Inspect and configure the advisor sidecar (expert consultation for routed workers).",
|
|
@@ -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);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { autoRestoreCodexShim } from "../codex/shim";
|
|
1
|
+
import { autoRestoreCodexShim, autoRestoreCodexShimAsync } from "../codex/shim";
|
|
2
2
|
import { codexShimAutoRestoreEnabled, readConfigDiagnostics } from "../config";
|
|
3
3
|
|
|
4
4
|
export interface CodexShimAutoRestoreCliDeps {
|
|
@@ -21,6 +21,8 @@ export function skipsCodexShimAutoRestore(command: string | undefined, args: str
|
|
|
21
21
|
if (command === "status" || command === "doctor") return true;
|
|
22
22
|
// The launcher owns shim handoff after classifying routing, including native fast paths.
|
|
23
23
|
if (command === "codex") return true;
|
|
24
|
+
// Exec admission only observes the selected target; it must never repair a shim first.
|
|
25
|
+
if (command === "internal" && args[1] === "codex-exec-target") return true;
|
|
24
26
|
// `lab` is read-only inspection; it must not trigger shim side effects.
|
|
25
27
|
if (command === "lab") return true;
|
|
26
28
|
// Local messaging owns its helpers; even malformed usage must not repair/start anything.
|
|
@@ -75,3 +77,19 @@ export function runCodexShimAutoRestore(deps: CodexShimAutoRestoreCliDeps = DEFA
|
|
|
75
77
|
);
|
|
76
78
|
}
|
|
77
79
|
}
|
|
80
|
+
|
|
81
|
+
export async function maybeAutoRestoreCodexShimAsync(command: string | undefined, args: string[]): Promise<void> {
|
|
82
|
+
if (!skipsCodexShimAutoRestore(command, args)) await runCodexShimAutoRestoreAsync();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function runCodexShimAutoRestoreAsync(): Promise<void> {
|
|
86
|
+
try {
|
|
87
|
+
const result = await autoRestoreCodexShimAsync({
|
|
88
|
+
enabled: () => codexShimAutoRestoreEnabled(DEFAULT_DEPS.readConfig().config, DEFAULT_DEPS.env),
|
|
89
|
+
});
|
|
90
|
+
if (result.status === "restored") DEFAULT_DEPS.warn(`⚠️ ${result.message} (automatic repair after Codex update)`);
|
|
91
|
+
else if ((result.status === "deferred" || result.status === "ineligible") && result.message) DEFAULT_DEPS.warn(`⚠️ ${result.message}`);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
DEFAULT_DEPS.warn(`⚠️ Codex shim auto-restore failed; continuing without it: ${error instanceof Error ? error.message : String(error)}. Run 'ocx codex-shim install' after the Codex update finishes.`);
|
|
94
|
+
}
|
|
95
|
+
}
|
package/src/cli/dispatch.ts
CHANGED
|
@@ -435,8 +435,8 @@ const commandRunners: Record<string, CommandRunner> = {
|
|
|
435
435
|
if (expectation) {
|
|
436
436
|
// The root preflight skipped the shim repair for a pinned sync; the identity held, so
|
|
437
437
|
// run it now, as an unpinned sync would have.
|
|
438
|
-
const {
|
|
439
|
-
|
|
438
|
+
const { runCodexShimAutoRestoreAsync } = await import("./codex-shim-autorestore");
|
|
439
|
+
await runCodexShimAutoRestoreAsync();
|
|
440
440
|
}
|
|
441
441
|
// The connection the sync ran under, read inside its lock; the read above may be stale.
|
|
442
442
|
const link = result.connection.transport === "link";
|
|
@@ -731,10 +731,10 @@ const commandRunners: Record<string, CommandRunner> = {
|
|
|
731
731
|
return Number(process.exitCode ?? 0);
|
|
732
732
|
},
|
|
733
733
|
"codex-shim": async deps => {
|
|
734
|
-
const { codexShimStatus, diagnoseCodexShim,
|
|
734
|
+
const { codexShimStatus, diagnoseCodexShim, installCodexShimAsync, uninstallCodexShimAsync } = await import("../codex/shim");
|
|
735
735
|
switch (deps.args[1]) {
|
|
736
736
|
case "install": {
|
|
737
|
-
const r =
|
|
737
|
+
const r = await installCodexShimAsync();
|
|
738
738
|
const { healthy, runnable, active, summary } = diagnoseCodexShim();
|
|
739
739
|
const success = !r.refused && (runnable ?? healthy);
|
|
740
740
|
const { collectCodexShimReadinessWarnings } = await import("./codex-shim-readiness");
|
|
@@ -764,7 +764,7 @@ const commandRunners: Record<string, CommandRunner> = {
|
|
|
764
764
|
}
|
|
765
765
|
case "uninstall":
|
|
766
766
|
case "remove": {
|
|
767
|
-
const r =
|
|
767
|
+
const r = await uninstallCodexShimAsync();
|
|
768
768
|
console.log(r.removed ? `✅ ${r.message}` : `⚠️ ${r.message}`);
|
|
769
769
|
break;
|
|
770
770
|
}
|
|
@@ -858,7 +858,7 @@ const commandRunners: Record<string, CommandRunner> = {
|
|
|
858
858
|
},
|
|
859
859
|
ready: async deps => {
|
|
860
860
|
// Fail-closed impossible-state guard: readyArgs is populated by the
|
|
861
|
-
// preparse block in src/cli/root.ts before
|
|
861
|
+
// preparse block in src/cli/root.ts before maybeAutoRestoreCodexShimAsync, so
|
|
862
862
|
// reaching here without it means dispatch diverged. Refuse with code 64
|
|
863
863
|
// and perform NO I/O (no discovery/probe). process.exit is `never`,
|
|
864
864
|
// narrowing below.
|
package/src/cli/doctor.ts
CHANGED
|
@@ -70,8 +70,8 @@ import {
|
|
|
70
70
|
effortClampAppliesToRuntime,
|
|
71
71
|
liveRemovedEfforts,
|
|
72
72
|
loadLastEffortClamp,
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
persistCodexRuntimeAsync,
|
|
74
|
+
resolveAndPersistCodexRuntimeAsync,
|
|
75
75
|
resolveCodexRuntime,
|
|
76
76
|
} from "../codex/runtime";
|
|
77
77
|
import { CODEX_REAUTH_ACTION, collectOAuthHealthEntriesForCli, MASKED_ACCOUNT_FALLBACK, type OAuthHealthEntry } from "../oauth/health";
|
|
@@ -1266,8 +1266,8 @@ export async function runDoctor(args: string[] = []): Promise<void> {
|
|
|
1266
1266
|
const resolved = resolveCodexRuntime();
|
|
1267
1267
|
if (!resolved.newerAvailable) {
|
|
1268
1268
|
console.log("No newer Codex runtime found; keeping current selection.");
|
|
1269
|
-
const current =
|
|
1270
|
-
console.log(`Selected: ${displayCodexRuntimePath(current
|
|
1269
|
+
const current = await resolveAndPersistCodexRuntimeAsync();
|
|
1270
|
+
console.log(`Selected: ${displayCodexRuntimePath(current?.runtime.command ?? "codex")} (${current?.runtime.version ?? "unknown"})`);
|
|
1271
1271
|
return;
|
|
1272
1272
|
}
|
|
1273
1273
|
if (resolved.runtime.source === "environment") {
|
|
@@ -1276,7 +1276,7 @@ export async function runDoctor(args: string[] = []): Promise<void> {
|
|
|
1276
1276
|
console.log("Then run ocx sync.");
|
|
1277
1277
|
return;
|
|
1278
1278
|
}
|
|
1279
|
-
|
|
1279
|
+
await persistCodexRuntimeAsync({
|
|
1280
1280
|
command: resolved.newerAvailable.command,
|
|
1281
1281
|
version: resolved.newerAvailable.version,
|
|
1282
1282
|
source: "configured",
|