@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
|
@@ -48,7 +48,7 @@ export interface EnsureDesiredIntegrationsDeps {
|
|
|
48
48
|
syncGrokConfig: (
|
|
49
49
|
port: number,
|
|
50
50
|
config: OcxConfig,
|
|
51
|
-
opts?: { hostname?: string; probeHostname?: string },
|
|
51
|
+
opts?: { hostname?: string; probeHostname?: string; admit?: () => boolean },
|
|
52
52
|
) => Promise<GrokInjectResult>;
|
|
53
53
|
removeDesktop3pStandardPivot: typeof removeDesktop3pStandardPivot;
|
|
54
54
|
removeDesktopFirstParty?: typeof removeDesktopFirstParty;
|
|
@@ -67,7 +67,7 @@ export interface EnsureDesiredIntegrationsDeps {
|
|
|
67
67
|
async function defaultSyncGrokConfig(
|
|
68
68
|
port: number,
|
|
69
69
|
config: OcxConfig,
|
|
70
|
-
opts: { hostname?: string; probeHostname?: string } = {},
|
|
70
|
+
opts: { hostname?: string; probeHostname?: string; admit?: () => boolean } = {},
|
|
71
71
|
): Promise<GrokInjectResult> {
|
|
72
72
|
const { syncGrokConfig } = await import("../grok/sync");
|
|
73
73
|
return syncGrokConfig(port, config, opts);
|
|
@@ -133,7 +133,8 @@ export async function ensureGrokFenceMatchesDesired(
|
|
|
133
133
|
port,
|
|
134
134
|
config,
|
|
135
135
|
{ ...(hostname !== undefined ? { hostname } : {}),
|
|
136
|
-
...(opts.probeHostname !== undefined ? { probeHostname: opts.probeHostname } : {})
|
|
136
|
+
...(opts.probeHostname !== undefined ? { probeHostname: opts.probeHostname } : {}),
|
|
137
|
+
admit: () => shouldSyncGrokOnStart(deps.loadConfig()) },
|
|
137
138
|
);
|
|
138
139
|
if (g.changed) log(" + Grok Build config updated (~/.grok/config.toml)");
|
|
139
140
|
else if (!g.ok) error(`⚠️ ${g.message}`);
|
package/src/cli/index.ts
CHANGED
|
@@ -69,6 +69,7 @@ import {
|
|
|
69
69
|
writePid,
|
|
70
70
|
writeRuntimePort,
|
|
71
71
|
} from "../config/process-state";
|
|
72
|
+
import { describeTrackedRuntimeTarget } from "../config/tracked-runtime-inspection";
|
|
72
73
|
import {
|
|
73
74
|
claimPendingTeardown,
|
|
74
75
|
isPendingTeardownAbandoned,
|
|
@@ -780,7 +781,10 @@ async function handleStart(options: { block?: boolean } = {}) {
|
|
|
780
781
|
// one restart, because the toggle removed the fence and start wrote it back.
|
|
781
782
|
if (shouldSyncGrokOnStart(config)) try {
|
|
782
783
|
const { syncGrokConfig } = await import("../grok/sync");
|
|
783
|
-
const r = await syncGrokConfig(port, config,
|
|
784
|
+
const r = await syncGrokConfig(port, config, {
|
|
785
|
+
...(config.hostname ? { hostname: config.hostname } : {}),
|
|
786
|
+
admit: () => !shuttingDown && !cleaned && shouldSyncGrokOnStart(loadConfig()),
|
|
787
|
+
});
|
|
784
788
|
if (r.changed) console.log(" + Grok Build config updated (~/.grok/config.toml)");
|
|
785
789
|
else if (!r.ok) console.error(`⚠️ ${r.message}`);
|
|
786
790
|
} catch (err) {
|
|
@@ -1020,13 +1024,7 @@ async function handleStop(approval?: StopApproval) {
|
|
|
1020
1024
|
try { return JSON.parse(lines[0]!) as ResolveJson; }
|
|
1021
1025
|
catch { return null; }
|
|
1022
1026
|
},
|
|
1023
|
-
|
|
1024
|
-
const pid = readPid();
|
|
1025
|
-
const runtime = pid === null ? null : readRuntimePort(pid);
|
|
1026
|
-
return pid && runtime?.port ? {
|
|
1027
|
-
pid, port: runtime.port, hostname: runtime.hostname ?? "",
|
|
1028
|
-
} : null;
|
|
1029
|
-
},
|
|
1027
|
+
describeTrackedRuntimeTarget,
|
|
1030
1028
|
() => inspectGuardedManagerTarget(approval.pid, approval.port),
|
|
1031
1029
|
snapshot => handleStopUnlocked(snapshot),
|
|
1032
1030
|
);
|
|
@@ -1679,8 +1677,8 @@ async function handleUninstall() {
|
|
|
1679
1677
|
});
|
|
1680
1678
|
|
|
1681
1679
|
try {
|
|
1682
|
-
const {
|
|
1683
|
-
const r =
|
|
1680
|
+
const { uninstallCodexShimAsync } = await import("../codex/shim");
|
|
1681
|
+
const r = await uninstallCodexShimAsync();
|
|
1684
1682
|
console.log(r.removed ? "✅ Codex autostart shim removed" : "- Codex autostart shim removed: not installed");
|
|
1685
1683
|
} catch (err) {
|
|
1686
1684
|
failures.push("Codex autostart shim removed");
|
package/src/cli/init.ts
CHANGED
|
@@ -257,9 +257,9 @@ export async function runInit(): Promise<void> {
|
|
|
257
257
|
prompt.throwIfCancelled();
|
|
258
258
|
if (shimAnswer.trim().toLowerCase() !== "n") {
|
|
259
259
|
try {
|
|
260
|
-
const {
|
|
260
|
+
const { installCodexShimAsync } = await import("../codex/shim");
|
|
261
261
|
prompt.throwIfCancelled();
|
|
262
|
-
const result =
|
|
262
|
+
const result = await installCodexShimAsync();
|
|
263
263
|
console.log(result.installed ? `✅ ${result.message}` : `⚠️ ${result.message}`);
|
|
264
264
|
} catch (err) {
|
|
265
265
|
if (err instanceof InitCancelledError) throw err;
|
|
@@ -16,15 +16,42 @@
|
|
|
16
16
|
* that same user, and a same-uid process could call `kill` directly. A token here would
|
|
17
17
|
* protect nothing and would imply a boundary that does not exist.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
import type { CodexExecBoundaryAsyncDeps } from "../codex/exec-boundary";
|
|
20
|
+
|
|
21
|
+
const USAGE = "Usage: ocx internal desktop-restart-handoff --plan <path> | chatgpt-app-server-filter [--self-test] | codex-exec-target [--bundle-root <path>] -- <path>";
|
|
20
22
|
|
|
21
23
|
function optionValue(args: readonly string[], name: string): string | undefined {
|
|
22
24
|
const index = args.indexOf(name);
|
|
23
25
|
return index >= 0 ? args[index + 1] : undefined;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Dispatch internal helpers with command-specific argument checks and exit codes.
|
|
30
|
+
* The executable-target helper writes one trusted path to stdout only after validation.
|
|
31
|
+
*/
|
|
32
|
+
export async function handleInternalCommand(args: readonly string[], execBoundary: CodexExecBoundaryAsyncDeps = {}): Promise<number> {
|
|
27
33
|
const sub = args[0];
|
|
34
|
+
if (sub === "codex-exec-target") {
|
|
35
|
+
const bundled = args[1] === "--bundle-root";
|
|
36
|
+
const root = bundled ? args[2] : undefined;
|
|
37
|
+
const separator = bundled ? 3 : 1;
|
|
38
|
+
const command = args[separator + 1];
|
|
39
|
+
if (args.length !== separator + 2 || args[separator] !== "--" || !command || /[\r\n\0]/.test(command)
|
|
40
|
+
|| (bundled && (!root || !root.startsWith("/") || /[\r\n\0]/.test(root)))) {
|
|
41
|
+
console.error(USAGE);
|
|
42
|
+
return 2;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const { assertCodexExecTargetTrustedAsync } = await import("../codex/exec-boundary");
|
|
46
|
+
const target = await assertCodexExecTargetTrustedAsync(command, bundled ? { ...execBoundary, expectedBundleRoot: root } : execBoundary);
|
|
47
|
+
if (!target || /[\r\n]/.test(target)) throw new Error("invalid executable path");
|
|
48
|
+
console.log(target);
|
|
49
|
+
return 0;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error(`OpenCodex refused the app-server executable: ${error instanceof Error ? error.message : "verification failed"}`);
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
28
55
|
if (sub === "chatgpt-app-server-filter") {
|
|
29
56
|
if (args.length > 2 || (args[1] !== undefined && args[1] !== "--self-test")) {
|
|
30
57
|
console.error(USAGE);
|
|
@@ -7,11 +7,12 @@ import { terminalSafeText } from "./runtime-api";
|
|
|
7
7
|
|
|
8
8
|
/** Run one local messaging operation after pure syntax validation, then release owned resources. */
|
|
9
9
|
export async function runMessageCommand(argv: readonly string[], env: NodeJS.ProcessEnv = process.env): Promise<number> {
|
|
10
|
+
if (argv[0] === "mcp") return (await import("./message-mcp-command")).runMessageMcpCommand(argv.slice(1));
|
|
10
11
|
const remote = parseRemoteMessageArgs(argv);
|
|
11
12
|
if (remote) return (await import("./message-remote-command")).runRemoteMessageCommand(remote, env);
|
|
12
13
|
const args = parseMessageArgs(argv);
|
|
13
14
|
if (!args) {
|
|
14
|
-
console.error("Usage: ocx message sessions [--host <peer>] [--json] | send (--thread <uuid> | --name <exact-name>) --stdin [--host <peer>] [--kind request|response|notification] [--in-reply-to <uuid>] [--json] | enable [--port <port>] | disable | status | hosts <probe|add|list|remove|abandon|allow-inbound|deny-inbound> | serve [--host <peer>]...");
|
|
15
|
+
console.error("Usage: ocx message sessions [--host <peer>] [--json] | send (--thread <uuid> | --name <exact-name>) --stdin [--host <peer>] [--kind request|response|notification] [--in-reply-to <uuid>] [--json] | mcp --codex <absolute-cli-path> --codex-home <absolute-existing-home> | enable [--port <port>] | disable | status | hosts <probe|add|list|remove|abandon|allow-inbound|deny-inbound> | serve [--host <peer>]...");
|
|
15
16
|
return 64;
|
|
16
17
|
}
|
|
17
18
|
const controller = new AbortController();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
import type { QueueMcpOptions } from "../messaging/mcp-queue-rpc";
|
|
3
|
+
|
|
4
|
+
/** Validate all syntax before importing the MCP host or resolving any executable/home. */
|
|
5
|
+
export function parseQueueMcpArgs(argv: readonly string[]): QueueMcpOptions | null {
|
|
6
|
+
if (argv.length !== 4) return null;
|
|
7
|
+
const values: Record<string, string> = {};
|
|
8
|
+
for (let i = 0; i < argv.length; i += 2) {
|
|
9
|
+
const flag = argv[i]!, value = argv[i + 1]!;
|
|
10
|
+
if (!["--codex", "--codex-home"].includes(flag) || values[flag] !== undefined
|
|
11
|
+
|| !value || !isAbsolute(value) || /[\x00-\x1f]/.test(value)) return null;
|
|
12
|
+
values[flag] = value;
|
|
13
|
+
}
|
|
14
|
+
return values["--codex"] && values["--codex-home"] ? { codex: values["--codex"], codexHome: values["--codex-home"] } : null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function runMessageMcpCommand(argv: readonly string[]): Promise<number> {
|
|
18
|
+
const options = parseQueueMcpArgs(argv);
|
|
19
|
+
if (!options) {
|
|
20
|
+
console.error("Usage: ocx message mcp --codex <absolute-cli-path> --codex-home <absolute-existing-home>");
|
|
21
|
+
return 64;
|
|
22
|
+
}
|
|
23
|
+
if (process.platform === "win32") {
|
|
24
|
+
console.error("Queue MCP currently supports macOS and Linux only.");
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
try { await (await import("../messaging/mcp-queue-server")).serveQueueMcp(options); return 0; }
|
|
28
|
+
catch { console.error("Queue MCP could not serve the stdio connection."); return 1; }
|
|
29
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { runCcSwitchProviderImport } from "../providers/cc-switch-import";
|
|
2
|
+
import { terminalSafeText } from "./runtime-api";
|
|
3
|
+
|
|
4
|
+
const USAGE = "Usage: ocx provider import-cc-switch [--source <cc-switch.db|config.json>] [--provider <id>]... [--apply | --restore] [--allow-private-network] [--json]";
|
|
5
|
+
|
|
6
|
+
export interface CcSwitchImportCommandDeps {
|
|
7
|
+
runImport?: typeof runCcSwitchProviderImport;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const SAFE_ERROR_CODES: Readonly<Record<string, string>> = {
|
|
11
|
+
"Stop the opencodex proxy before applying or restoring a CC-Switch provider import.": "proxy_running",
|
|
12
|
+
"Initialize a valid opencodex configuration before importing or restoring providers.": "config_unavailable",
|
|
13
|
+
"An active CC-Switch import journal already exists; run 'ocx provider import-cc-switch --restore' before applying another import.": "active_journal_exists",
|
|
14
|
+
"No CC-Switch provider import journal found to restore.": "journal_missing",
|
|
15
|
+
"Existing CC-Switch import journal is corrupt; inspect or restore before importing.": "journal_corrupt",
|
|
16
|
+
"Existing CC-Switch import journal is unreadable; inspect or restore before importing.": "journal_unreadable",
|
|
17
|
+
"CC-Switch source does not contain one or more requested --provider IDs.": "provider_not_found",
|
|
18
|
+
"CC-Switch SQLite source has uncheckpointed WAL changes (-wal is non-empty); close CC-Switch (or checkpoint the database) and retry.": "sqlite_wal_active",
|
|
19
|
+
"CC-Switch SQLite source has an unreadable WAL file (-wal); close CC-Switch (or checkpoint the database) and retry.": "sqlite_wal_active",
|
|
20
|
+
"CC-Switch SQLite source has an active rollback journal (-journal); close CC-Switch and retry.": "sqlite_journal_active",
|
|
21
|
+
"CC-Switch SQLite source has an unreadable rollback journal (-journal); close CC-Switch and retry.": "sqlite_journal_active",
|
|
22
|
+
"CC-Switch SQLite source has multiple hard links; import the original CC-Switch database path directly.": "sqlite_hardlink_refused",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function formatCandidateLine(p: { name: string; sourceId: string; appType: string; adapter: string; baseUrl: string; defaultModel?: string }): string {
|
|
26
|
+
const modelText = terminalSafeText(p.defaultModel ?? "none");
|
|
27
|
+
return ` id=${terminalSafeText(p.name)} (source=${terminalSafeText(p.sourceId)}, ${terminalSafeText(p.appType)} -> ${terminalSafeText(p.adapter)}) model=${modelText} url=${terminalSafeText(p.baseUrl)}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Local-only keyless provider import from CC-Switch SQLite or JSON. */
|
|
31
|
+
export async function cmdProviderCcSwitchImport(args: string[], deps: CcSwitchImportCommandDeps = {}): Promise<number> {
|
|
32
|
+
let sourcePath: string | undefined;
|
|
33
|
+
const selectedProviders: string[] = [];
|
|
34
|
+
let apply = false;
|
|
35
|
+
let restore = false;
|
|
36
|
+
let allowPrivateNetwork = false;
|
|
37
|
+
const wantsJson = args.includes("--json");
|
|
38
|
+
const seenBooleans = new Set<string>();
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < args.length; i++) {
|
|
41
|
+
const arg = args[i]!;
|
|
42
|
+
if (arg === "--source" || arg === "--provider") {
|
|
43
|
+
const val = args[++i];
|
|
44
|
+
if (!val || val.startsWith("-")) {
|
|
45
|
+
console.error(USAGE);
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
if (arg === "--source") {
|
|
49
|
+
if (sourcePath !== undefined) {
|
|
50
|
+
console.error(USAGE);
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
sourcePath = val;
|
|
54
|
+
} else {
|
|
55
|
+
selectedProviders.push(val);
|
|
56
|
+
}
|
|
57
|
+
} else if (arg === "--apply" || arg === "--restore" || arg === "--allow-private-network" || arg === "--json") {
|
|
58
|
+
if (seenBooleans.has(arg)) {
|
|
59
|
+
console.error(USAGE);
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
seenBooleans.add(arg);
|
|
63
|
+
if (arg === "--apply") apply = true;
|
|
64
|
+
else if (arg === "--restore") restore = true;
|
|
65
|
+
else if (arg === "--allow-private-network") allowPrivateNetwork = true;
|
|
66
|
+
} else {
|
|
67
|
+
console.error(USAGE);
|
|
68
|
+
return 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (apply && restore) {
|
|
73
|
+
console.error(USAGE);
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
if (restore) {
|
|
77
|
+
if (sourcePath !== undefined || selectedProviders.length > 0 || allowPrivateNetwork) {
|
|
78
|
+
console.error(USAGE);
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
} else if (!sourcePath) {
|
|
82
|
+
console.error(USAGE);
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const mode = restore ? "restore" : apply ? "apply" : "preview";
|
|
87
|
+
if (mode !== "preview") {
|
|
88
|
+
const refusal = (await import("./link-child")).linkChildProviderChangeRefusal("ocx provider import-cc-switch");
|
|
89
|
+
if (refusal) {
|
|
90
|
+
if (wantsJson) console.log(JSON.stringify({ error: "link_child_refused", message: refusal }));
|
|
91
|
+
else console.error(refusal);
|
|
92
|
+
return 1;
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
await (await import("./link-child")).printLinkChildLocalNotice("The CC-Switch provider import preview");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const run = deps.runImport ?? (await import("../providers/cc-switch-import")).runCcSwitchProviderImport;
|
|
100
|
+
let printedBeforeWrite = false;
|
|
101
|
+
const result = await run({
|
|
102
|
+
mode,
|
|
103
|
+
sourcePath,
|
|
104
|
+
selectedProviders,
|
|
105
|
+
allowPrivateNetwork,
|
|
106
|
+
...(apply
|
|
107
|
+
? {
|
|
108
|
+
onBeforeApplyWrite: providers => {
|
|
109
|
+
const emit = wantsJson ? console.error : console.log;
|
|
110
|
+
printedBeforeWrite = true;
|
|
111
|
+
emit("Importing keyless provider entries (projects allowlisted non-secret metadata only; secret fields are skipped at the byte level and never decoded, written, or logged — verify IDs, models, and URLs from a trusted CC-Switch source before adding credentials):");
|
|
112
|
+
for (const p of providers) {
|
|
113
|
+
emit(formatCandidateLine(p));
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
: {}),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (result.mode === "restore") {
|
|
121
|
+
if (wantsJson) {
|
|
122
|
+
console.log(JSON.stringify({
|
|
123
|
+
mode: result.mode,
|
|
124
|
+
restored: result.restored,
|
|
125
|
+
restoredNames: result.restoredNames,
|
|
126
|
+
alreadyAbsent: result.alreadyAbsent,
|
|
127
|
+
retainedEdited: result.retainedEdited,
|
|
128
|
+
retainedNames: result.retainedNames,
|
|
129
|
+
}));
|
|
130
|
+
} else {
|
|
131
|
+
console.log(`CC-Switch restore: ${result.restored} removed, ${result.alreadyAbsent} already absent, ${result.retainedEdited} retained (edited or referenced).`);
|
|
132
|
+
if (result.retainedNames.length > 0) {
|
|
133
|
+
console.log(`Retained providers: ${result.retainedNames.map(terminalSafeText).join(", ")}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (wantsJson) {
|
|
140
|
+
console.log(JSON.stringify({
|
|
141
|
+
mode: result.mode,
|
|
142
|
+
discovered: result.discovered,
|
|
143
|
+
eligible: result.eligible,
|
|
144
|
+
imported: result.imported,
|
|
145
|
+
conflicts: result.conflicts,
|
|
146
|
+
conflictNames: result.conflictNames,
|
|
147
|
+
invalid: result.invalid,
|
|
148
|
+
invalidReasons: result.invalidReasons,
|
|
149
|
+
providers: result.providers,
|
|
150
|
+
...(apply && result.imported > 0
|
|
151
|
+
? { trustNotice: "Verify imported baseUrl endpoints come from a trusted CC-Switch source before adding credentials." }
|
|
152
|
+
: {}),
|
|
153
|
+
}));
|
|
154
|
+
} else {
|
|
155
|
+
console.log(`CC-Switch (${result.mode}): ${result.discovered} discovered, ${result.eligible} eligible, ${result.imported} imported, ${result.conflicts} conflicts, ${result.invalid} invalid.`);
|
|
156
|
+
if (!printedBeforeWrite) {
|
|
157
|
+
if (apply && result.imported > 0) {
|
|
158
|
+
console.log("Importing keyless provider entries (projects allowlisted non-secret metadata only; secret fields are skipped at the byte level and never decoded, written, or logged — verify IDs, models, and URLs from a trusted CC-Switch source before adding credentials):");
|
|
159
|
+
}
|
|
160
|
+
for (const p of result.providers) {
|
|
161
|
+
console.log(formatCandidateLine(p));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (result.invalid > 0) {
|
|
165
|
+
const reasons = Object.entries(result.invalidReasons).map(([k, v]) => `${k}=${v}`).join(", ");
|
|
166
|
+
console.log(`Invalid reasons: ${reasons}`);
|
|
167
|
+
}
|
|
168
|
+
console.log(apply
|
|
169
|
+
? (result.imported > 0
|
|
170
|
+
? "Keyless provider entries saved. Only add credentials to endpoints you trust: start the proxy ('ocx start') and run 'ocx account add-key <provider>' (piped stdin) or 'ocx login <provider>', or undo while stopped with 'ocx provider import-cc-switch --restore'."
|
|
171
|
+
: "No eligible non-conflicting providers were imported; configuration and journal are unchanged.")
|
|
172
|
+
: "Preview only (projects allowlisted non-secret metadata only; secret fields are skipped at the byte level and never decoded, written, or logged). Verify IDs, models, and destination URLs from a trusted source and stop the proxy before repeating with --apply.");
|
|
173
|
+
}
|
|
174
|
+
return result.invalid > 0 && result.eligible === 0 ? 1 : 0;
|
|
175
|
+
} catch (err) {
|
|
176
|
+
const msg = err instanceof Error ? err.message : "";
|
|
177
|
+
const code = SAFE_ERROR_CODES[msg] ?? "cc_switch_import_failed";
|
|
178
|
+
const safeMsg = SAFE_ERROR_CODES[msg] || msg.startsWith("CC-Switch ")
|
|
179
|
+
? terminalSafeText(msg)
|
|
180
|
+
: "CC-Switch provider import failed. Verify the source file, destination config, and stopped proxy.";
|
|
181
|
+
if (wantsJson) console.log(JSON.stringify({ error: code, message: safeMsg }));
|
|
182
|
+
else console.error(safeMsg);
|
|
183
|
+
return 1;
|
|
184
|
+
}
|
|
185
|
+
}
|
package/src/cli/provider.ts
CHANGED
|
@@ -655,6 +655,11 @@ export async function handleProviderCommand(args: string[], deps: ProviderComman
|
|
|
655
655
|
process.exitCode = await handleProviderPacingCommand(subArgs, deps);
|
|
656
656
|
return;
|
|
657
657
|
}
|
|
658
|
+
if (sub === "import-cc-switch") {
|
|
659
|
+
const { cmdProviderCcSwitchImport } = await import("./provider-cc-switch-import");
|
|
660
|
+
process.exitCode = await cmdProviderCcSwitchImport(subArgs);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
658
663
|
|
|
659
664
|
// #6957: a link Child's local providers are inactive; changing them is refused like any other
|
|
660
665
|
// provider change, which belongs to the Home.
|
package/src/cli/registry.ts
CHANGED
|
@@ -18,7 +18,7 @@ export const CLI_COMMANDS: CliCommandEntry[] = [
|
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
name: "message",
|
|
21
|
-
usage: "ocx message <sessions|send|enable|disable|status|hosts|serve> [options]",
|
|
21
|
+
usage: "ocx message <sessions|send|mcp|enable|disable|status|hosts|serve> [options]",
|
|
22
22
|
summary: "Discover loaded Codex sessions and queue messages locally or through explicit SSH peers.",
|
|
23
23
|
details: ["Remote listeners/tunnels require explicit foreground serve; no daemon start. queued is submission, not processing; never replay an unknown send."],
|
|
24
24
|
},
|
|
@@ -310,6 +310,7 @@ export const CLI_COMMANDS: CliCommandEntry[] = [
|
|
|
310
310
|
" show <name> Show provider config details",
|
|
311
311
|
" set-default <name> Change the default provider",
|
|
312
312
|
" add/remove/set-default support --live; live removal also requires --yes.",
|
|
313
|
+
" import-cc-switch Preview, apply, or restore keyless CC-Switch provider entries",
|
|
313
314
|
" selected <name> Show or set the provider model allowlist",
|
|
314
315
|
" quota Show provider quota reports",
|
|
315
316
|
" resets Show recently detected quota resets",
|
package/src/cli/restart-scope.ts
CHANGED
|
@@ -104,9 +104,9 @@ export async function handleDesktopAppRestart(
|
|
|
104
104
|
log: Pick<Console, "log" | "error">,
|
|
105
105
|
io: DesktopAppRestartIo = {},
|
|
106
106
|
): Promise<DesktopAppRestartResult> {
|
|
107
|
-
const {
|
|
107
|
+
const { restartCodexDesktopAppAsync } = await import("../codex/desktop-app-restart");
|
|
108
108
|
const { startDesktopRestartHandoff } = await import("../codex/desktop-app/handoff");
|
|
109
|
-
const result =
|
|
109
|
+
const result = await restartCodexDesktopAppAsync({
|
|
110
110
|
...io,
|
|
111
111
|
// The CLI is the one caller whose exit is exactly the signal the helper waits for,
|
|
112
112
|
// so it is the one caller allowed to hand off. The management service is not (it
|
package/src/cli/root.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { parseReadyArgs, type ReadyArgs } from "./ready";
|
|
|
13
13
|
import { parseResolveArgs, type ResolveArgs } from "./resolve";
|
|
14
14
|
import { parseStopApproval } from "./stop-approval";
|
|
15
15
|
import { parseSyncExpectation, SYNC_EXPECTATION_USAGE_EXIT } from "./sync-expectation";
|
|
16
|
-
import {
|
|
16
|
+
import { maybeAutoRestoreCodexShimAsync } from "./codex-shim-autorestore";
|
|
17
17
|
import { findCommand } from "./registry";
|
|
18
18
|
import { printUnknownCommand } from "./help-recovery";
|
|
19
19
|
import { noteCredentialArgv, redactSecretArgs } from "./secret-args";
|
|
@@ -64,7 +64,7 @@ export function parseCliHead(argv: string[]): CliHead {
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
// P1: pre-parse `ocx ready` and reject invalid arguments with exit 64 BEFORE
|
|
67
|
-
//
|
|
67
|
+
// maybeAutoRestoreCodexShimAsync (or any discovery/probe/filesystem-capable global
|
|
68
68
|
// preflight) runs. `ready --help` / `help ready` already exited above, so this
|
|
69
69
|
// only sees ready args without a help flag. Valid args are stashed so the
|
|
70
70
|
// switch dispatch can call runReady without a second parse.
|
|
@@ -74,7 +74,7 @@ export function parseCliHead(argv: string[]): CliHead {
|
|
|
74
74
|
return { kind: "ready", command, args, readyArgs: parsed.args };
|
|
75
75
|
}
|
|
76
76
|
// Same ordering contract as `ready`: `ocx resolve` rejects any argument with exit
|
|
77
|
-
// 64 BEFORE
|
|
77
|
+
// 64 BEFORE maybeAutoRestoreCodexShimAsync (or any other preflight with side effects) runs.
|
|
78
78
|
if (command === "resolve") {
|
|
79
79
|
const parsed = parseResolveArgs(args.slice(1));
|
|
80
80
|
if (!parsed.ok) return { kind: "resolve", command, args, resolveArgs: undefined };
|
|
@@ -115,7 +115,7 @@ export async function runCli(argv: string[]): Promise<CliHead> {
|
|
|
115
115
|
console.error(" Default wait timeout is 45 seconds.");
|
|
116
116
|
process.exit(64);
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
await maybeAutoRestoreCodexShimAsync(head.command, head.args);
|
|
119
119
|
return head;
|
|
120
120
|
}
|
|
121
121
|
case "resolve": {
|
|
@@ -128,7 +128,7 @@ export async function runCli(argv: string[]): Promise<CliHead> {
|
|
|
128
128
|
console.error(" and the identity-checked liveness verdict.");
|
|
129
129
|
process.exit(64);
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
await maybeAutoRestoreCodexShimAsync(head.command, head.args);
|
|
132
132
|
return head;
|
|
133
133
|
}
|
|
134
134
|
case "command":
|
|
@@ -154,7 +154,7 @@ export async function runCli(argv: string[]): Promise<CliHead> {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
await maybeNoticeVersionSkew(head.command, head.args);
|
|
157
|
-
|
|
157
|
+
await maybeAutoRestoreCodexShimAsync(head.command, head.args);
|
|
158
158
|
return head;
|
|
159
159
|
}
|
|
160
160
|
}
|
package/src/cli/stop-approval.ts
CHANGED
|
@@ -20,6 +20,17 @@ export interface GuardedStopSnapshot {
|
|
|
20
20
|
manager: Exclude<GuardedManagerTarget, { kind: "unknown" }>;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* What the tracked-record check can report: the verified target, null when the
|
|
25
|
+
* caller cannot name a cause (the pre-diagnostics shape), or the fixed cause of
|
|
26
|
+
* the single check that failed. The cause is a fixed sentence fragment from the
|
|
27
|
+
* inspection probe -- it carries no path, command line, stderr, or token.
|
|
28
|
+
*/
|
|
29
|
+
export type TrackedRuntimeCheck =
|
|
30
|
+
| { pid: number; port: number; hostname: string }
|
|
31
|
+
| { untracked: string }
|
|
32
|
+
| null;
|
|
33
|
+
|
|
23
34
|
function sameGuardedManager(
|
|
24
35
|
expected: GuardedStopSnapshot["manager"],
|
|
25
36
|
current: GuardedManagerTarget,
|
|
@@ -117,7 +128,7 @@ export function managerStillActive(
|
|
|
117
128
|
export async function runApprovedStop(
|
|
118
129
|
expected: StopApproval,
|
|
119
130
|
read: () => Promise<ResolveJson | null>,
|
|
120
|
-
tracked: () =>
|
|
131
|
+
tracked: () => TrackedRuntimeCheck,
|
|
121
132
|
managerTarget: () => GuardedManagerTarget,
|
|
122
133
|
stop: (snapshot: GuardedStopSnapshot) => Promise<StopOutcome>,
|
|
123
134
|
): Promise<StopOutcome> {
|
|
@@ -130,6 +141,9 @@ export async function runApprovedStop(
|
|
|
130
141
|
const mismatch = stopApprovalMismatch(expected, now);
|
|
131
142
|
if (mismatch !== null) return approvalChanged(mismatch);
|
|
132
143
|
if (target === null) return approvalChanged("the tracked runtime record could not be verified");
|
|
144
|
+
if ("untracked" in target) {
|
|
145
|
+
return approvalChanged(`the tracked runtime record could not be verified (${target.untracked})`);
|
|
146
|
+
}
|
|
133
147
|
if (target.pid !== expected.pid || target.port !== expected.port
|
|
134
148
|
|| target.hostname !== expected.hostname) {
|
|
135
149
|
return approvalChanged("the tracked runtime record changed");
|
package/src/cli/v2.ts
CHANGED
|
@@ -21,6 +21,7 @@ import type { ResolveDeps, SpawnInvocation } from "../lib/win-exec";
|
|
|
21
21
|
import { validatedCodexExecInvocation } from "../codex/exec-boundary";
|
|
22
22
|
import { deleteConfigTopLevelKey, loadConfig, saveConfig } from "../config";
|
|
23
23
|
import { resolveAndPersistCodexRuntime, type ResolveCodexRuntimeDeps } from "../codex/runtime";
|
|
24
|
+
import { withCodexCliSelectionParentWriteAsync } from "../codex/cli-update-selection-gate";
|
|
24
25
|
|
|
25
26
|
export interface V2CliDeps {
|
|
26
27
|
execFile?: (file: string, args: string[], options?: SpawnInvocation["options"] & { env?: NodeJS.ProcessEnv }) => void;
|
|
@@ -79,6 +80,11 @@ export function codexFeaturesInvocation(
|
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
export async function codexFeaturesInvocationAsync(action: "enable" | "disable", feature = "multi_agent_v2",
|
|
84
|
+
platform: NodeJS.Platform = process.platform, deps: CodexFeaturesInvocationDeps = {}): Promise<SpawnInvocation> {
|
|
85
|
+
return withCodexCliSelectionParentWriteAsync(() => codexFeaturesInvocation(action, feature, platform, deps), { configDir: deps.configDir });
|
|
86
|
+
}
|
|
87
|
+
|
|
82
88
|
/**
|
|
83
89
|
* Run `codex features <action> <feature>` synchronously - the management API
|
|
84
90
|
* fallback when no deps toggle is injected. Shares the invocation builder and
|
|
@@ -195,45 +201,77 @@ export async function cmdV2(args: string[], deps: V2CliDeps = {}, findPort?: ()
|
|
|
195
201
|
return emit(true, []);
|
|
196
202
|
}
|
|
197
203
|
if (parsed.verb === "mode-hint") {
|
|
198
|
-
const result =
|
|
204
|
+
const result = parsed.value === null ? setMultiAgentModeHintText(null)
|
|
205
|
+
: await withCodexCliSelectionParentWriteAsync(() => setMultiAgentModeHintText(parsed.value));
|
|
199
206
|
if (!result.ok) return emit(false, ["Unable to write the native mode hint. Check Codex support and ownership, then read ocx v2 status."]);
|
|
200
207
|
changed = result.changed;
|
|
201
208
|
return emit(true, [result.changed ? "multi_agent_mode_hint_text saved — applies to new sessions." : "multi_agent_mode_hint_text already set — nothing to do."]);
|
|
202
209
|
}
|
|
203
210
|
if (parsed.verb === "threads") {
|
|
204
|
-
|
|
205
|
-
|
|
211
|
+
// Admission can wait on recovery ACL checks; the feature state is read once admitted, in
|
|
212
|
+
// the same synchronous turn as the transition, so a change made meanwhile is not undone.
|
|
213
|
+
let enabled = false;
|
|
214
|
+
const result = await withCodexCliSelectionParentWriteAsync(() => {
|
|
215
|
+
enabled = (deps.isEnabled ?? isMultiAgentV2Enabled)();
|
|
216
|
+
return transitionMultiAgentV2(enabled, (next, env, validate) => runCodexFeatures(next ? "enable" : "disable", deps, env, validate), { threadLimit: parsed.value });
|
|
217
|
+
});
|
|
206
218
|
if (!result.ok) return emit(false, ["Unable to update the native thread limit. Read ocx v2 status before retrying."]);
|
|
207
219
|
changed = result.changed;
|
|
208
220
|
return emit(true, [changed ? `max_threads = ${parsed.value} (${enabled ? "v2" : "v1"}) — applies to new sessions.` : `max_threads already ${parsed.value} — nothing to do.`]);
|
|
209
221
|
}
|
|
210
|
-
|
|
222
|
+
// Every awaited admission below re-reads, decides and saves the config inside its
|
|
223
|
+
// synchronous callback, so a setting changed while admission waited is neither
|
|
224
|
+
// overruled by a stale decision nor overwritten by a stale save.
|
|
225
|
+
let config = loadConfig();
|
|
211
226
|
let successLines: string[];
|
|
212
227
|
let unchangedKeep: boolean | undefined;
|
|
213
228
|
if (parsed.verb === "mode") {
|
|
214
|
-
|
|
229
|
+
const persistMode = (): boolean => {
|
|
230
|
+
const before = config.multiAgentMode ?? "default";
|
|
231
|
+
if (parsed.value === "default") deleteConfigTopLevelKey(config, "multiAgentMode");
|
|
232
|
+
else config.multiAgentMode = parsed.value;
|
|
233
|
+
saveConfig(config);
|
|
234
|
+
return before !== parsed.value;
|
|
235
|
+
};
|
|
215
236
|
if (parsed.value !== "default") {
|
|
216
|
-
|
|
217
|
-
const transition =
|
|
237
|
+
let modeChanged = false;
|
|
238
|
+
const transition = await withCodexCliSelectionParentWriteAsync(() => {
|
|
239
|
+
config = loadConfig();
|
|
240
|
+
const target = parsed.value === "v2" && config.keepNativeChatGptOnV1 !== true;
|
|
241
|
+
const result = transitionMultiAgentV2(target, (next, env, validate) => runCodexFeatures(next ? "enable" : "disable", deps, env, validate));
|
|
242
|
+
if (result.ok) modeChanged = persistMode();
|
|
243
|
+
return result;
|
|
244
|
+
});
|
|
218
245
|
if (!transition.ok) { changed = false; return emit(false, ["Native mode transition failed. Read ocx v2 status before retrying."]); }
|
|
219
|
-
changed
|
|
246
|
+
changed = modeChanged || transition.changed;
|
|
247
|
+
} else {
|
|
248
|
+
changed = persistMode();
|
|
220
249
|
}
|
|
221
|
-
if (parsed.value === "default") deleteConfigTopLevelKey(config, "multiAgentMode");
|
|
222
|
-
else config.multiAgentMode = parsed.value;
|
|
223
|
-
saveConfig(config);
|
|
224
250
|
successLines = [multiAgentModeLine(parsed.value, config.keepNativeChatGptOnV1 === true),
|
|
225
251
|
"Applies to NEW sessions; running sessions keep their pinned multi-agent version."];
|
|
226
252
|
} else if (parsed.verb === "keep-native-v1") {
|
|
227
|
-
|
|
228
|
-
|
|
253
|
+
const persistKeep = (): void => {
|
|
254
|
+
unchangedKeep = (config.keepNativeChatGptOnV1 === true) === parsed.value;
|
|
255
|
+
if (parsed.value) config.keepNativeChatGptOnV1 = true;
|
|
256
|
+
else deleteConfigTopLevelKey(config, "keepNativeChatGptOnV1");
|
|
257
|
+
saveConfig(config);
|
|
258
|
+
};
|
|
229
259
|
if (parsed.value && requiresGlobalV2Disabled(config.multiAgentMode, true)) {
|
|
230
|
-
const transition =
|
|
260
|
+
const transition = await withCodexCliSelectionParentWriteAsync(() => {
|
|
261
|
+
config = loadConfig();
|
|
262
|
+
// Revalidated once admitted: mode may have left v2 while admission waited.
|
|
263
|
+
const result = requiresGlobalV2Disabled(config.multiAgentMode, true)
|
|
264
|
+
? transitionMultiAgentV2(false, (next, env, validate) => runCodexFeatures(next ? "enable" : "disable", deps, env, validate))
|
|
265
|
+
: { ok: true as const, changed: false };
|
|
266
|
+
if (result.ok) persistKeep();
|
|
267
|
+
return result;
|
|
268
|
+
});
|
|
231
269
|
if (!transition.ok) { changed = false; return emit(false, ["Native hybrid-mode transition failed. Read ocx v2 status before retrying."]); }
|
|
232
|
-
changed
|
|
270
|
+
changed = !unchangedKeep || transition.changed;
|
|
271
|
+
} else {
|
|
272
|
+
persistKeep();
|
|
273
|
+
changed = !unchangedKeep;
|
|
233
274
|
}
|
|
234
|
-
if (parsed.value) config.keepNativeChatGptOnV1 = true;
|
|
235
|
-
else deleteConfigTopLevelKey(config, "keepNativeChatGptOnV1");
|
|
236
|
-
saveConfig(config);
|
|
237
275
|
successLines = [parsed.value
|
|
238
276
|
? "keep_native_chatgpt_on_v1: ON — ChatGPT-native rows stay v1 when mode is v2 (new sessions)."
|
|
239
277
|
: "keep_native_chatgpt_on_v1: OFF — ChatGPT-native rows follow v1/base/v2 (new sessions)."];
|
|
@@ -242,7 +280,19 @@ export async function cmdV2(args: string[], deps: V2CliDeps = {}, findPort?: ()
|
|
|
242
280
|
if (want && requiresGlobalV2Disabled(config.multiAgentMode, config.keepNativeChatGptOnV1 === true)) {
|
|
243
281
|
return emit(false, ["v2 on: incompatible with keep-native-v1 while mode is v2 — Codex's global multi_agent_v2 overrides the native v1 catalog pin. Run 'ocx v2 keep-native-v1 off' first."]);
|
|
244
282
|
}
|
|
245
|
-
|
|
283
|
+
let incompatible = false;
|
|
284
|
+
const transition = await withCodexCliSelectionParentWriteAsync(() => {
|
|
285
|
+
// Revalidated once admitted: keep-native-v1 or mode v2 may have been set meanwhile.
|
|
286
|
+
const current = loadConfig();
|
|
287
|
+
if (want && requiresGlobalV2Disabled(current.multiAgentMode, current.keepNativeChatGptOnV1 === true)) {
|
|
288
|
+
incompatible = true;
|
|
289
|
+
return { ok: true as const, changed: false };
|
|
290
|
+
}
|
|
291
|
+
return transitionMultiAgentV2(want, (next, env, validate) => runCodexFeatures(next ? "enable" : "disable", deps, env, validate));
|
|
292
|
+
});
|
|
293
|
+
if (incompatible) {
|
|
294
|
+
return emit(false, ["v2 on: incompatible with keep-native-v1 while mode is v2 — Codex's global multi_agent_v2 overrides the native v1 catalog pin. Run 'ocx v2 keep-native-v1 off' first."]);
|
|
295
|
+
}
|
|
246
296
|
if (!transition.ok) return emit(false, ["Native feature transition failed. Read ocx v2 status before retrying."]);
|
|
247
297
|
changed = transition.changed;
|
|
248
298
|
if (!changed) return emit(true, [`multi_agent_v2 already ${want ? "ON" : "OFF"} — nothing to do.`]);
|