@bitkyc08/opencodex 2.96.0 → 2.97.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/bin/ocx.mjs +214 -19
- package/gui/dist/assets/{App-bwugJRKn.js → App-DuNhggE1.js} +15 -15
- package/gui/dist/assets/{Tray-BOPQyDbH.js → Tray-CEw0y0jR.js} +1 -1
- package/gui/dist/assets/index-CynE_Rue.js +94 -0
- package/gui/dist/assets/{quota-summary-6HsrHQAy.js → quota-summary-VHFSlUuM.js} +1 -1
- package/gui/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/adapters/command-code.ts +15 -16
- package/src/adapters/cursor/transport-retry.ts +2 -2
- package/src/adapters/devin/cloud-direct/chat.ts +15 -6
- package/src/adapters/kiro/stream.ts +63 -4
- package/src/adapters/kiro-constants.ts +15 -1
- package/src/adapters/kiro-events.ts +31 -1
- package/src/adapters/kiro-retry.ts +3 -3
- package/src/adapters/ollama-native.ts +11 -1
- package/src/adapters/openai-responses/empty-assistant.ts +15 -3
- package/src/adapters/openai-responses/passthrough.ts +5 -4
- package/src/adapters/openai-responses/reasoning.ts +9 -4
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/physical-send.ts +3 -3
- package/src/adapters/zed-openai-stream.ts +2 -1
- package/src/bridge/errors.ts +11 -2
- package/src/bridge/response-json.ts +2 -1
- package/src/bridge/sse.ts +14 -6
- package/src/chat/failure-verdict.ts +21 -0
- package/src/chat/outbound.ts +139 -21
- package/src/claude/outbound.ts +49 -2
- package/src/cli/capabilities-base.ts +25 -3
- package/src/cli/capabilities-command.ts +12 -3
- package/src/cli/capability-contracts.ts +2 -0
- package/src/cli/codex-launch-auth.ts +30 -1
- package/src/cli/codex-launcher.ts +12 -5
- package/src/cli/codex-shim-autorestore.ts +5 -4
- package/src/cli/dispatch.ts +11 -176
- package/src/cli/help.ts +2 -2
- package/src/cli/index.ts +5 -1
- package/src/cli/link.ts +1 -1
- package/src/cli/registry.ts +11 -3
- package/src/cli/root.ts +8 -0
- package/src/cli/sync-command.ts +243 -0
- package/src/cli/sync-fanout-process.ts +92 -0
- package/src/cli/sync-fanout.ts +150 -0
- package/src/cli/sync-flags.ts +10 -0
- package/src/cli/sync-link-status.ts +39 -0
- package/src/cli/sync-update-guard.ts +18 -0
- package/src/client/connect.ts +31 -14
- package/src/client/link-home.ts +3 -2
- package/src/client/machine-listener.ts +3 -0
- package/src/client/restore-ownership.ts +19 -1
- package/src/client/runtime-restart.ts +12 -4
- package/src/client/runtime.ts +40 -11
- package/src/client/stop-routing.ts +62 -0
- package/src/client/sync-runtime.ts +65 -0
- package/src/clients/config-export.ts +32 -3
- package/src/codex/auth-context.ts +49 -103
- package/src/codex/catalog/antigravity-discovery.ts +16 -5
- package/src/codex/catalog/provider-models.ts +6 -8
- package/src/codex/forward-transport-headers.ts +35 -6
- package/src/codex/inject/config-toml.ts +88 -0
- package/src/codex/inject/multi-agent-v2.ts +30 -4
- package/src/codex/inject/plan.ts +34 -7
- package/src/codex/inject-coordination.ts +11 -0
- package/src/codex/inject.ts +18 -7
- package/src/codex/lineage.ts +13 -7
- package/src/codex/quota.ts +22 -6
- package/src/codex/request-owned-affinity-key.ts +11 -0
- package/src/codex/request-owned-affinity.ts +118 -0
- package/src/codex/request-owned-main-pin.ts +86 -0
- package/src/codex/role-capability.ts +52 -41
- package/src/codex/routing/active-account.ts +13 -5
- package/src/codex/routing/selection.ts +40 -1
- package/src/codex/routing/thread-affinity-store.ts +916 -0
- package/src/codex/routing/thread-affinity.ts +90 -12
- package/src/codex/toml-source-lines.ts +72 -13
- package/src/combos/failover.ts +6 -109
- package/src/combos/request.ts +2 -2
- package/src/combos/resolve.ts +29 -11
- package/src/config/process-state.ts +5 -0
- package/src/config/schema/leaf-validators.ts +1 -0
- package/src/generated/compatibility-version.json +433 -165
- package/src/images/loop.ts +2 -1
- package/src/lib/client-error-body.ts +184 -0
- package/src/lib/client-retry-after.ts +66 -0
- package/src/lib/config-ownership.ts +4 -0
- package/src/lib/context-overflow-verdict.ts +113 -0
- package/src/lib/desktop-cli-handoff.d.mts +1 -1
- package/src/lib/desktop-cli-handoff.mjs +11 -1
- package/src/lib/empty-tool-catalog.ts +25 -3
- package/src/lib/error-destination.ts +47 -0
- package/src/lib/failure-detail.ts +66 -0
- package/src/lib/model-identity.ts +44 -0
- package/src/lib/private-sqlite-path.ts +124 -0
- package/src/lib/response-service-tier.ts +17 -0
- package/src/lib/retry-after.ts +3 -0
- package/src/lib/spend-ledger-owner.ts +43 -4
- package/src/lib/upstream-condition.ts +142 -0
- package/src/lib/upstream-retry.ts +14 -11
- package/src/lib/windows-owner-acl.ts +13 -6
- package/src/link/remote-platform.ts +14 -0
- package/src/link/remote-windows.ts +51 -9
- package/src/link/ssh-argv.ts +63 -10
- package/src/oauth/generic-account-failover.ts +13 -11
- package/src/oauth/index.ts +36 -74
- package/src/oauth/oauth-errors.ts +67 -0
- package/src/oauth/store.ts +1 -1
- package/src/protocols/codecs/ollama.ts +197 -0
- package/src/protocols/encoders/adapter-events.ts +4 -0
- package/src/protocols/encoders/chat.ts +18 -10
- package/src/protocols/trace.ts +18 -0
- package/src/providers/fastwire.ts +3 -2
- package/src/providers/quota/anthropic-usage-windows.ts +13 -3
- package/src/providers/quota/vendor-probes-key.ts +60 -24
- package/src/providers/request-pacing.ts +3 -2
- package/src/responses/apply-patch-envelope.ts +45 -19
- package/src/responses/compaction-history-framing.ts +5 -1
- package/src/responses/freeform-wrapper-scan.ts +5 -3
- package/src/responses/progressive-freeform-input.ts +354 -45
- package/src/routing/fallback-policy.ts +3 -1
- package/src/server/admission-model-scope.ts +17 -6
- package/src/server/admitted-http-turn.ts +56 -0
- package/src/server/auth-cors.ts +5 -0
- package/src/server/chat-completions.ts +45 -20
- package/src/server/chat-native-sse.ts +52 -7
- package/src/server/chat-native.ts +60 -35
- package/src/server/claude-bridge-pool-session.ts +59 -0
- package/src/server/claude-messages.ts +51 -24
- package/src/server/context-history.ts +5 -1
- package/src/server/inbound-body-admission.ts +11 -4
- package/src/server/index/ollama-routes.ts +89 -0
- package/src/server/index/serve-options.ts +21 -4
- package/src/server/index/websocket-handler.ts +4 -2
- package/src/server/index.ts +6 -36
- package/src/server/inference/client-encoder-delivery.ts +4 -2
- package/src/server/json-serialized-bytes.ts +44 -0
- package/src/server/management/agent-settings-routes.ts +24 -21
- package/src/server/management/codex-cli-update-routes.ts +2 -1
- package/src/server/management/route-registry.ts +1 -1
- package/src/server/messages-native-scope.ts +2 -1
- package/src/server/messages-native-tool-guard.ts +1 -1
- package/src/server/messages-native.ts +12 -7
- package/src/server/messages-shared.ts +6 -2
- package/src/server/native-final-log.ts +93 -0
- package/src/server/ollama-inbound.ts +349 -0
- package/src/server/ollama-native-paths.ts +21 -0
- package/src/server/ollama-route-policy.ts +73 -0
- package/src/server/relay.ts +22 -3
- package/src/server/request-decompress.ts +4 -2
- package/src/server/request-log-failure-attribution.ts +22 -0
- package/src/server/request-log-failure-detail.ts +80 -0
- package/src/server/request-log-terminal-status.ts +4 -2
- package/src/server/request-log.ts +79 -42
- package/src/server/response-log-body.ts +6 -1
- package/src/server/responses/account-change-state.ts +17 -6
- package/src/server/responses/adapter-continuation.ts +9 -4
- package/src/server/responses/adapter-delivery.ts +5 -4
- package/src/server/responses/adapter-dispatch.ts +31 -30
- package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
- package/src/server/responses/codex-auth-error.ts +19 -18
- package/src/server/responses/codex-ws-exchange.ts +11 -8
- package/src/server/responses/codex-ws-metadata.ts +94 -21
- package/src/server/responses/codex-ws-request.ts +3 -1
- package/src/server/responses/compact.ts +53 -23
- package/src/server/responses/compaction-recovery.ts +4 -2
- package/src/server/responses/compaction-routing.ts +9 -4
- package/src/server/responses/core-auth.ts +32 -14
- package/src/server/responses/core-codex-account.ts +17 -6
- package/src/server/responses/core-combo-failure.ts +5 -1
- package/src/server/responses/core-combo-native.ts +2 -1
- package/src/server/responses/core-combo.ts +41 -27
- package/src/server/responses/core-errors.ts +22 -20
- package/src/server/responses/core-lifetime.ts +6 -3
- package/src/server/responses/core-normalize.ts +1 -0
- package/src/server/responses/core-options.ts +7 -0
- package/src/server/responses/core-pipeline.ts +4 -3
- package/src/server/responses/fetch-helpers.ts +7 -1
- package/src/server/responses/input-admission.ts +28 -2
- package/src/server/responses/native-injection.ts +1 -1
- package/src/server/responses/native-response-json.ts +13 -4
- package/src/server/responses/native-response-output.ts +1 -2
- package/src/server/responses/non-replayable-error.ts +2 -1
- package/src/server/responses/pacing-overload.ts +3 -2
- package/src/server/responses/passthrough-delivery.ts +55 -14
- package/src/server/responses/passthrough-dispatch.ts +19 -17
- package/src/server/responses/passthrough-error.ts +9 -9
- package/src/server/responses/policy-fallback.ts +2 -1
- package/src/server/responses/request-prepare.ts +67 -48
- package/src/server/responses/request-transport.ts +35 -31
- package/src/server/responses/run-turn-execution.ts +6 -6
- package/src/server/responses/sidecar-execution.ts +16 -12
- package/src/server/responses/spend-storage-error.ts +2 -1
- package/src/server/responses/ws-upstream.ts +9 -0
- package/src/server/responses-custom-tool-repair.ts +14 -3
- package/src/server/responses-terminal-repair.ts +5 -2
- package/src/server/responses-undeclared-tool-guard.ts +39 -16
- package/src/server/safe-response-headers.ts +162 -13
- package/src/server/turn-state-handles.ts +164 -0
- package/src/server/workflow-refusal.ts +2 -1
- package/src/service/ownership-mutation-lease.d.mts +11 -2
- package/src/service/ownership-mutation-lease.mjs +53 -11
- package/src/types/config.ts +2 -0
- package/src/update/index.ts +133 -25
- package/src/update/npm-install.d.mts +8 -0
- package/src/update/npm-install.mjs +20 -1
- package/src/update/orchestrated-admission.d.mts +4 -0
- package/src/update/orchestrated-admission.mjs +12 -0
- package/src/update/orchestrated-arguments.d.mts +12 -0
- package/src/update/orchestrated-arguments.mjs +64 -0
- package/src/update/orchestrated-child.d.mts +12 -0
- package/src/update/orchestrated-child.mjs +70 -0
- package/src/update/orchestrated-entry.ts +234 -0
- package/src/update/orchestrated-identity-probe-entry.ts +20 -0
- package/src/update/orchestrated-identity.ts +53 -0
- package/src/update/orchestrated-live-identity.ts +48 -0
- package/src/update/orchestrated-node-driver.mjs +99 -0
- package/src/update/orchestrated-outcome.d.mts +21 -0
- package/src/update/orchestrated-outcome.mjs +40 -0
- package/src/update/orchestrated-plan.ts +49 -0
- package/src/update/orchestrated-pnpm.d.mts +8 -0
- package/src/update/orchestrated-pnpm.mjs +33 -0
- package/src/update/orchestrated-session.d.mts +37 -0
- package/src/update/orchestrated-session.mjs +264 -0
- package/src/update/orchestrated-token.d.mts +10 -0
- package/src/update/orchestrated-token.mjs +21 -0
- package/src/update/orchestrated-token.ts +3 -0
- package/src/update/orchestrated-tree.d.mts +1 -0
- package/src/update/orchestrated-tree.mjs +14 -0
- package/src/update/pnpm-global-install.d.mts +6 -0
- package/src/update/pnpm-global-install.mjs +9 -2
- package/src/update/posix-install-supervisor-entry.mjs +6 -0
- package/src/update/posix-install-supervisor.d.mts +10 -0
- package/src/update/posix-install-supervisor.mjs +88 -0
- package/src/update/sync-update-mutex.d.mts +10 -0
- package/src/update/sync-update-mutex.mjs +164 -0
- package/src/update/sync-update-mutex.ts +1 -0
- package/src/update/test-home-guard.mjs +33 -0
- package/src/update/transactional-install.mjs +2 -2
- package/src/usage/error-detail.ts +225 -0
- package/src/usage/log.ts +60 -27
- package/src/web-search/loop.ts +31 -5
- package/gui/dist/assets/index-ebuVUtB7.js +0 -94
|
@@ -215,12 +215,30 @@ export const CAPABILITIES: readonly Capability[] = [
|
|
|
215
215
|
"A rotation left pending by a crash is resumed here — startup and status stop rather than guess which key generation is live.",
|
|
216
216
|
],
|
|
217
217
|
},
|
|
218
|
+
{
|
|
219
|
+
command: ["update"],
|
|
220
|
+
summary: "Plan or apply an OpenCodex update.",
|
|
221
|
+
routes: [],
|
|
222
|
+
flags: [
|
|
223
|
+
{ name: "--plan", value: "boolean", summary: "Preview an orchestrated update with --json." },
|
|
224
|
+
{ name: "--yes", value: "boolean", summary: "Apply an orchestrated update with --json." },
|
|
225
|
+
{ name: "--json", value: "boolean", summary: "Emit a versioned plan or result." },
|
|
226
|
+
{ name: "--tag", value: "string", summary: "Select latest or preview for the legacy update or plan." },
|
|
227
|
+
{ name: "--version", value: "string", summary: "Select an exact version for a plan or apply." },
|
|
228
|
+
{ name: "--expect-plan", value: "string", summary: "Require the apply plan to match this planToken." },
|
|
229
|
+
{ name: "--not-after", value: "string", summary: "Refuse mutation after this Unix millisecond deadline." },
|
|
230
|
+
],
|
|
231
|
+
mutates: true,
|
|
232
|
+
json: "envelope",
|
|
233
|
+
details: ["Orchestrated exit codes: 0 verified or up-to-date; 10 refused; 11 previous version verified; 12 uncertain; 64 usage."],
|
|
234
|
+
},
|
|
218
235
|
{
|
|
219
236
|
command: ["capabilities"],
|
|
220
237
|
summary: "List the declared CLI capabilities and the management routes they drive.",
|
|
221
238
|
routes: [],
|
|
222
239
|
flags: [
|
|
223
240
|
{ name: "--json", value: "boolean", summary: "Emit the full capability table as JSON." },
|
|
241
|
+
{ name: "--contracts", value: "boolean", summary: "List supported versioned contracts." },
|
|
224
242
|
{ name: "--mutating-only", value: "boolean", summary: "Restrict output to capabilities that mutate state." },
|
|
225
243
|
{ name: "--route", value: "string", summary: "Show which capabilities drive a management route." },
|
|
226
244
|
],
|
|
@@ -618,7 +636,7 @@ export const CAPABILITIES: readonly Capability[] = [
|
|
|
618
636
|
routes: [],
|
|
619
637
|
flags: [{ name: "--plan-id", value: "string", summary: "Required 32-hex id from the current plan." }, { name: "--yes", value: "boolean", summary: "Required confirmation." }, { name: "--request-id", value: "string", summary: "Optional stable retry key." }, { name: "--json", value: "boolean", summary: "Emit the public job status." }],
|
|
620
638
|
mutates: true, json: "envelope",
|
|
621
|
-
details: ["Local counterpart of POST /api/codex/cli-update/apply: invokes the same durable job owner with --yes confirmation; HTTP admission separately requires a trusted loopback
|
|
639
|
+
details: ["Local counterpart of POST /api/codex/cli-update/apply: invokes the same durable job owner with --yes confirmation; HTTP admission separately requires a current paired dashboard session on trusted loopback ingress, matching origin, CSRF and confirmed: true.", "Standalone HTTP pairing requires the configured literal 127.0.0.1 or ::1 origin; localhost aliases, wildcard binds and connected-client roles use the local CLI --yes path instead.", "Admission is stored under the protected current-user config root before the installer can run.", "Exit 0 requires an applied job; refused, not_applied, ambiguous and pending duplicate jobs exit 1, including with --json.", "Only POSIX npm-global managed installs are currently supported; Windows, shims and other managers remain refused."],
|
|
622
640
|
usage: "ocx system codex-cli-update apply --plan-id <32-hex> --yes [--request-id <key>] [--json]",
|
|
623
641
|
},
|
|
624
642
|
{
|
|
@@ -752,6 +770,8 @@ export const CAPABILITIES: readonly Capability[] = [
|
|
|
752
770
|
summary: "Synchronize client catalogs, including Aside profiles through the running server's mutation owner.",
|
|
753
771
|
routes: [{ method: "POST", path: "/api/client-integrations/aside/sync" }],
|
|
754
772
|
flags: [
|
|
773
|
+
{ name: "--local-only", value: "boolean", summary: "Do not fan out the Home sync to linked Children." },
|
|
774
|
+
{ name: "--json", value: "boolean", summary: "Emit the sync fan-out result as JSON." },
|
|
755
775
|
{ name: "--restart-codex", value: "boolean", summary: "Restart the Codex app-servers and fully quit and relaunch the Codex desktop app after a catalog, cache, or changed configuration write, on macOS, Linux and Windows." },
|
|
756
776
|
{ name: "--restart-app-server-only", value: "boolean", summary: "Restart only the Codex app-servers and leave the desktop app running; wins over --restart-codex when both are given." },
|
|
757
777
|
{ name: "--restart-desktop-app", value: "boolean", summary: "Deprecated alias of --restart-codex." },
|
|
@@ -759,12 +779,14 @@ export const CAPABILITIES: readonly Capability[] = [
|
|
|
759
779
|
{ name: "--expect-hub-key", value: "string", summary: "Sync only when this machine is a hub client connected with this API key id; otherwise exit 5 with nothing changed." },
|
|
760
780
|
],
|
|
761
781
|
mutates: true,
|
|
762
|
-
json: "
|
|
782
|
+
json: "payload",
|
|
763
783
|
details: [
|
|
764
784
|
"The Aside refresh uses the live server; other catalog synchronization also performs local work.",
|
|
785
|
+
"An update in flight or an unavailable update/sync mutex refuses without changes: update-in-flight, exit 7. Another sync reports sync-in-progress, exit 1.",
|
|
786
|
+
"A current Home catalog fans out to linked Children. Fan-out never requests a Codex app or app-server restart on a Child; use GOAT or ocx sync --restart-codex there. Applying changed Home settings may restart the Child's own OpenCodex client runtime.",
|
|
765
787
|
"--expect-link/--expect-hub-key are checked under the lock that selects the sync path. A mismatch writes nothing, never falls back to local providers, exits 5, and ends stderr with {\"phase\":\"child_link_mismatch\"|\"hub_client_mismatch\",\"reason\":...}; reasons are disconnected, invalid_state, disconnect_pending, pending_operation, hub_client, link_client, other_link and other_key. Usage errors exit 2.",
|
|
766
788
|
],
|
|
767
|
-
usage: "ocx sync [--expect-link <linkId> | --expect-hub-key <apiKeyId>] [--restart-codex] [--restart-app-server-only]",
|
|
789
|
+
usage: "ocx sync [--expect-link <linkId> | --expect-hub-key <apiKeyId>] [--local-only] [--json] [--restart-codex] [--restart-app-server-only]",
|
|
768
790
|
},
|
|
769
791
|
{
|
|
770
792
|
command: ["agent","subagents","force"],
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
type Capability,
|
|
14
14
|
} from "./capabilities";
|
|
15
15
|
import { takeFlag } from "./runtime-api";
|
|
16
|
+
import { CAPABILITY_CONTRACTS } from "./capability-contracts";
|
|
16
17
|
|
|
17
18
|
function takeValueFlag(args: string[], flag: string): string | undefined {
|
|
18
19
|
// Order-independent by construction: scan for the flag anywhere in argv rather than
|
|
@@ -49,14 +50,21 @@ function renderHuman(caps: readonly Capability[], includeHead: boolean): void {
|
|
|
49
50
|
export async function runCapabilities(argv: string[]): Promise<number> {
|
|
50
51
|
const args = [...argv];
|
|
51
52
|
const json = takeFlag(args, "--json");
|
|
53
|
+
const contracts = takeFlag(args, "--contracts");
|
|
52
54
|
const mutatingOnly = takeFlag(args, "--mutating-only");
|
|
53
55
|
const route = takeValueFlag(args, "--route");
|
|
54
56
|
|
|
55
|
-
if (args.length > 0 || (route !== undefined && route.trim().length === 0)) {
|
|
56
|
-
console.error("Usage: ocx capabilities [--json] [--mutating-only] [--route <path>]");
|
|
57
|
+
if (args.length > 0 || (route !== undefined && route.trim().length === 0) || (contracts && (mutatingOnly || route !== undefined))) {
|
|
58
|
+
console.error("Usage: ocx capabilities [--json] [--contracts] [--mutating-only] [--route <path>]");
|
|
57
59
|
return 64;
|
|
58
60
|
}
|
|
59
61
|
|
|
62
|
+
if (contracts) {
|
|
63
|
+
if (json) console.log(JSON.stringify({ schemaVersion: 1, contracts: CAPABILITY_CONTRACTS }));
|
|
64
|
+
else for (const contract of CAPABILITY_CONTRACTS) console.log(contract);
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
60
68
|
let selected: readonly Capability[] = route === undefined ? CAPABILITIES : capabilitiesForRoute(route);
|
|
61
69
|
if (mutatingOnly) selected = selected.filter(cap => cap.mutates);
|
|
62
70
|
|
|
@@ -64,7 +72,7 @@ export async function runCapabilities(argv: string[]): Promise<number> {
|
|
|
64
72
|
// An unmatched route is a real answer, not an error: the route may be exempt or may
|
|
65
73
|
// not exist. Say which, rather than exiting 0 with silence.
|
|
66
74
|
if (json) {
|
|
67
|
-
console.log(JSON.stringify({ schemaVersion: 1, route, capabilities: [] }, null, 2));
|
|
75
|
+
console.log(JSON.stringify({ schemaVersion: 1, contracts: CAPABILITY_CONTRACTS, route, capabilities: [] }, null, 2));
|
|
68
76
|
} else {
|
|
69
77
|
console.error(`No CLI capability drives ${route}.`);
|
|
70
78
|
}
|
|
@@ -74,6 +82,7 @@ export async function runCapabilities(argv: string[]): Promise<number> {
|
|
|
74
82
|
if (json) {
|
|
75
83
|
console.log(JSON.stringify({
|
|
76
84
|
schemaVersion: 1,
|
|
85
|
+
contracts: CAPABILITY_CONTRACTS,
|
|
77
86
|
...(route === undefined ? {} : { route }),
|
|
78
87
|
capabilities: selected.map(cap => ({
|
|
79
88
|
command: cap.command,
|
|
@@ -7,10 +7,34 @@ import { readBoundedCodexConfig } from "../codex/inject/bounded-config-reader";
|
|
|
7
7
|
import { buildProviderTableBlockForTarget } from "../codex/inject/config-toml";
|
|
8
8
|
import { standaloneCodexRoutingTarget, validateCodexRoutingTarget } from "../codex/inject/routing-target";
|
|
9
9
|
import { readClientConnectionState } from "../client/state";
|
|
10
|
+
import { normalizeBindHostname } from "../server/bind-host";
|
|
11
|
+
import { probeHostname, proveLiveProxyOwnedByHome, type LiveProxy } from "../server/proxy-liveness";
|
|
10
12
|
import { codexHasOtherTokenConsumers, codexTokenConfigShapeIsSafe } from "./codex-launch-policy";
|
|
11
13
|
import { codexLaunchHomeIsOwned, codexLaunchProjectAliasIsOwned, codexLaunchSystemNamespaceIsSafe } from "./codex-launch-ownership";
|
|
12
14
|
import type { CodexTokenRefusal, CodexTokenRefusalReporter } from "./codex-launch-diagnostics";
|
|
13
15
|
|
|
16
|
+
export type CodexRuntimeAttestation = Readonly<{ origin: string }>;
|
|
17
|
+
|
|
18
|
+
/** Retain the exact dial endpoint that answered the ownership challenge, not just its verdict. */
|
|
19
|
+
export async function attestCodexRuntime(
|
|
20
|
+
live: LiveProxy,
|
|
21
|
+
prove: typeof proveLiveProxyOwnedByHome = proveLiveProxyOwnedByHome,
|
|
22
|
+
): Promise<CodexRuntimeAttestation | null> {
|
|
23
|
+
// Probe the address the listener actually binds: a configured localhost binds 127.0.0.1,
|
|
24
|
+
// which is also what the standalone Codex target dials.
|
|
25
|
+
const snapshot = Object.freeze({ ...live, probeHostname: normalizeBindHostname(live.probeHostname ?? live.hostname) });
|
|
26
|
+
try {
|
|
27
|
+
const origin = new URL(`http://${probeHostname(snapshot.probeHostname)}:${snapshot.port}`).origin;
|
|
28
|
+
return await prove(snapshot) === "proven" ? Object.freeze({ origin }) : null;
|
|
29
|
+
} catch { return null; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** IPv4 and IPv6 listeners are distinct recipients, even when their ports are equal. */
|
|
33
|
+
export function codexRuntimeAttestationMatchesTarget(baseUrl: string, proof: CodexRuntimeAttestation | null | undefined): boolean {
|
|
34
|
+
try { return proof !== null && proof !== undefined && new URL(baseUrl).origin === proof.origin; }
|
|
35
|
+
catch { return false; }
|
|
36
|
+
}
|
|
37
|
+
|
|
14
38
|
/** Resolve once; the credential verifier and child must use this exact directory. */
|
|
15
39
|
export function resolveCodexLaunchHome(env: Record<string, string | undefined>): string | null {
|
|
16
40
|
try {
|
|
@@ -28,7 +52,7 @@ export function resolveCodexLaunchHome(env: Record<string, string | undefined>):
|
|
|
28
52
|
}
|
|
29
53
|
|
|
30
54
|
/** Config classification is a startup hint; credentials need an independently bound destination. */
|
|
31
|
-
export function codexCredentialDestinationIsTrusted(home: string, systemNamespaceDirectory?: string, report?: CodexTokenRefusalReporter): boolean {
|
|
55
|
+
export function codexCredentialDestinationIsTrusted(home: string, systemNamespaceDirectory?: string, report?: CodexTokenRefusalReporter, runtimeAttestation?: CodexRuntimeAttestation | null): boolean {
|
|
32
56
|
const refuse = (reason: CodexTokenRefusal): false => { report?.(reason); return false; };
|
|
33
57
|
try {
|
|
34
58
|
if (!codexLaunchHomeIsOwned(home)) return refuse("ownership");
|
|
@@ -43,15 +67,20 @@ export function codexCredentialDestinationIsTrusted(home: string, systemNamespac
|
|
|
43
67
|
if (diagnostics.error || diagnostics.source === "fallback") return refuse("installationConfig");
|
|
44
68
|
const cfg = diagnostics.config;
|
|
45
69
|
let target = standaloneCodexRoutingTarget(cfg.port, cfg);
|
|
70
|
+
// A direct client's proof comes from its own machine listener, never from the hub it
|
|
71
|
+
// dials, so only a standalone destination can be compared with the proven origin.
|
|
72
|
+
let destinationIsProvenListener = true;
|
|
46
73
|
if (cfg.runtimeRole === "client") {
|
|
47
74
|
// Direct clients bind to persisted connection state; link clients use an authless relay.
|
|
48
75
|
const connection = readClientConnectionState();
|
|
49
76
|
if (connection.kind !== "connected" || connection.value.transport === "link") return refuse("connection");
|
|
50
77
|
target = validateCodexRoutingTarget({ baseUrl: `${connection.value.serverUrl}/v1`, requiresAdmissionToken: true, tokenEnv: "OPENCODEX_API_AUTH_TOKEN" });
|
|
78
|
+
destinationIsProvenListener = false;
|
|
51
79
|
}
|
|
52
80
|
const url = new URL(target.baseUrl);
|
|
53
81
|
if (!target.requiresAdmissionToken) return refuse("admission");
|
|
54
82
|
if (url.protocol !== "http:" || !["127.0.0.1", "[::1]"].includes(url.hostname)) return refuse("loopback");
|
|
83
|
+
if (destinationIsProvenListener && !codexRuntimeAttestationMatchesTarget(target.baseUrl, runtimeAttestation)) return refuse("destination");
|
|
55
84
|
const content = readBoundedCodexConfig(join(home, "config.toml"));
|
|
56
85
|
if (content === null) return refuse("configRead");
|
|
57
86
|
const config = Bun.TOML.parse(content) as Record<string, unknown>;
|
|
@@ -34,7 +34,7 @@ import { selfLaunchArgv } from "../lib/self-launch-argv";
|
|
|
34
34
|
import { loadServiceTokenFromFile, serviceApiTokenFilePath } from "../lib/service-secrets";
|
|
35
35
|
import { findExecutableOnPath } from "../remote-control/workspace-executable";
|
|
36
36
|
import { findLiveProxy, type LiveProxy } from "../server/proxy-liveness";
|
|
37
|
-
import { codexCredentialDestinationIsTrusted, resolveCodexLaunchHome } from "./codex-launch-auth";
|
|
37
|
+
import { attestCodexRuntime, codexCredentialDestinationIsTrusted, resolveCodexLaunchHome, type CodexRuntimeAttestation } from "./codex-launch-auth";
|
|
38
38
|
import { codexCommandCanBypass, CODEX_UNVERIFIED_SHIM } from "./codex-launch-command";
|
|
39
39
|
import { codexTokenArgsAreSafe, codexTokenEnvironmentIsSafe } from "./codex-launch-policy";
|
|
40
40
|
import { codexTokenWithheldDiagnostic, type CodexTokenRefusal, type CodexTokenRefusalReporter } from "./codex-launch-diagnostics";
|
|
@@ -158,7 +158,9 @@ export type CodexLaunchEnvDeps = {
|
|
|
158
158
|
args?: readonly string[];
|
|
159
159
|
/** Test seam; production reads the hardened service token file. */
|
|
160
160
|
serviceToken?: (base: CodexLaunchEnv) => string | null;
|
|
161
|
-
credentialDestination?: (home: string, report?: CodexTokenRefusalReporter) => boolean;
|
|
161
|
+
credentialDestination?: (home: string, report?: CodexTokenRefusalReporter, runtimeAttestation?: CodexRuntimeAttestation | null) => boolean;
|
|
162
|
+
/** Exact origin that proved this home's runtime-record secret. */
|
|
163
|
+
runtimeAttestation?: CodexRuntimeAttestation | null;
|
|
162
164
|
};
|
|
163
165
|
|
|
164
166
|
/** Read the client admission credential from this installation's service-token file. */
|
|
@@ -186,6 +188,7 @@ export function buildCodexLaunchEnv(
|
|
|
186
188
|
};
|
|
187
189
|
if (!codexTokenArgsAreSafe(deps.args ?? [])) return withhold("args");
|
|
188
190
|
if (!codexTokenEnvironmentIsSafe(env)) return withhold("environment");
|
|
191
|
+
if (!deps.runtimeAttestation) return withhold("destination");
|
|
189
192
|
// NO_PROXY parsing and precedence vary across native HTTP/WebSocket transports.
|
|
190
193
|
// Without proving bypass, preserve the user's transport but never load a secret.
|
|
191
194
|
const home = resolveCodexLaunchHome(env);
|
|
@@ -193,8 +196,8 @@ export function buildCodexLaunchEnv(
|
|
|
193
196
|
let refusal: CodexTokenRefusal = "destination";
|
|
194
197
|
const report: CodexTokenRefusalReporter = reason => { refusal = reason; };
|
|
195
198
|
const trusted = deps.credentialDestination
|
|
196
|
-
? deps.credentialDestination(home, report)
|
|
197
|
-
: codexCredentialDestinationIsTrusted(home, undefined, report);
|
|
199
|
+
? deps.credentialDestination(home, report, deps.runtimeAttestation)
|
|
200
|
+
: codexCredentialDestinationIsTrusted(home, undefined, report, deps.runtimeAttestation);
|
|
198
201
|
if (!trusted) return withhold(refusal);
|
|
199
202
|
const token = (deps.serviceToken ?? defaultServiceToken)(env);
|
|
200
203
|
if (!token) return withhold("credential");
|
|
@@ -318,5 +321,9 @@ export async function cmdCodex(args: string[]): Promise<number> {
|
|
|
318
321
|
// what the session does next; `ocx doctor` names the autostart failure.
|
|
319
322
|
console.error(CODEX_SHIM_ENSURE_FAILED_DIAGNOSTIC);
|
|
320
323
|
}
|
|
321
|
-
|
|
324
|
+
// A public health marker proves liveness, not ownership of the listener. Never read the
|
|
325
|
+
// persisted service token until the exact runtime-record endpoint answers a fresh challenge.
|
|
326
|
+
const runtimeAttestation = plan.kind === "routed" && live !== null
|
|
327
|
+
? await attestCodexRuntime(live) : null;
|
|
328
|
+
return spawnCodex(args, buildCodexLaunchEnv(process.env, { routingKind, args, runtimeAttestation }));
|
|
322
329
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { autoRestoreCodexShim, autoRestoreCodexShimAsync } from "../codex/shim";
|
|
2
2
|
import { codexShimAutoRestoreEnabled, readConfigDiagnostics } from "../config";
|
|
3
|
+
import { isOrchestratedUpdateArgv } from "../update/orchestrated-arguments.mjs";
|
|
3
4
|
|
|
4
5
|
export interface CodexShimAutoRestoreCliDeps {
|
|
5
6
|
env: NodeJS.ProcessEnv;
|
|
@@ -18,6 +19,10 @@ const DEFAULT_DEPS: CodexShimAutoRestoreCliDeps = {
|
|
|
18
19
|
/** Identify command namespaces whose execution must not trigger automatic shim repair. */
|
|
19
20
|
export function skipsCodexShimAutoRestore(command: string | undefined, args: string[]): boolean {
|
|
20
21
|
if (command === "uninstall" || command === "remove") return true;
|
|
22
|
+
// Contract discovery and orchestrated update must validate before any repair.
|
|
23
|
+
if (command === "capabilities") return true;
|
|
24
|
+
if (command === "update" && isOrchestratedUpdateArgv(args)) return true;
|
|
25
|
+
if (command === "sync") return true;
|
|
21
26
|
if (command === "status" || command === "doctor") return true;
|
|
22
27
|
// The launcher owns shim handoff after classifying routing, including native fast paths.
|
|
23
28
|
if (command === "codex") return true;
|
|
@@ -38,10 +43,6 @@ export function skipsCodexShimAutoRestore(command: string | undefined, args: str
|
|
|
38
43
|
// The desktop's approval-bound stop must validate its snapshot before any unrelated
|
|
39
44
|
// CLI repair changes the installation it was approved against.
|
|
40
45
|
if (command === "stop" && args.some(arg => arg.startsWith("--expect-"))) return true;
|
|
41
|
-
// A pinned sync (#7694) must change nothing when its expected Home or hub key does not hold,
|
|
42
|
-
// so the root preflight may not repair the shim first; the sync runner repairs it only after
|
|
43
|
-
// the locked identity check passed (runCodexShimAutoRestore in src/cli/dispatch.ts).
|
|
44
|
-
if (command === "sync" && args.some(arg => /^--expect-(link|hub-key)(=|$)/.test(arg))) return true;
|
|
45
46
|
// The entire updater-inspection namespace is zero-effect, including malformed
|
|
46
47
|
// or future actions. A later `apply` implementation must own its preflight.
|
|
47
48
|
if (command === "system" && args[1] === "codex-cli-update") return true;
|
package/src/cli/dispatch.ts
CHANGED
|
@@ -15,7 +15,6 @@ import { uninstallArgsError, type CliHead } from "./root";
|
|
|
15
15
|
import type { ReadyArgs } from "./ready";
|
|
16
16
|
import type { LivenessIo, LiveProxy } from "../server/proxy-liveness";
|
|
17
17
|
import type { OcxConfig } from "../types";
|
|
18
|
-
import type { OwnedIntegrationRefreshOutcome } from "../integrations/owned-refresh";
|
|
19
18
|
import { hasHelpFlag, printSubcommandUsage, printUsage } from "./help";
|
|
20
19
|
import { printUnknownCommand } from "./help-recovery";
|
|
21
20
|
import {
|
|
@@ -30,9 +29,9 @@ import { syncModelsToCodex } from "../codex/sync";
|
|
|
30
29
|
import { collectOrcaCodexHomeDiagnostic } from "../codex/home";
|
|
31
30
|
import { restoreNativeCodexAsync, type CodexNativeRestoreResult } from "../codex/inject";
|
|
32
31
|
import { stripGrokConfig } from "../grok/inject";
|
|
33
|
-
import { handleRestartScopeAfterWrite, readRestartScope
|
|
32
|
+
import { handleRestartScopeAfterWrite, readRestartScope } from "./restart-scope";
|
|
34
33
|
import { normalizeUpdateChannel, runGuiUpdateWorker } from "../update/job";
|
|
35
|
-
import { isJsonOption, takeFlag
|
|
34
|
+
import { isJsonOption, takeFlag } from "./runtime-api";
|
|
36
35
|
import { printStopSummary, type StopOutcome } from "./stop-report";
|
|
37
36
|
import { parseStopApproval, type StopApproval } from "./stop-approval";
|
|
38
37
|
import type { ResolveArgs } from "./resolve";
|
|
@@ -404,171 +403,7 @@ const commandRunners: Record<string, CommandRunner> = {
|
|
|
404
403
|
const { handleLogoutCommand } = await import("./logout-command");
|
|
405
404
|
return handleLogoutCommand(deps.args.slice(1), { findLiveProxy: deps.findLiveProxy });
|
|
406
405
|
},
|
|
407
|
-
sync: async deps =>
|
|
408
|
-
const syncArgs = deps.args.slice(1);
|
|
409
|
-
// #7694: parse the expected identity before anything else reads or writes state.
|
|
410
|
-
const { parseSyncExpectation, reportSyncExpectationMismatch, SYNC_EXPECTATION_USAGE_EXIT } = await import("./sync-expectation");
|
|
411
|
-
const parsedExpectation = parseSyncExpectation(syncArgs);
|
|
412
|
-
if (!parsedExpectation.ok) {
|
|
413
|
-
console.error(parsedExpectation.message);
|
|
414
|
-
return SYNC_EXPECTATION_USAGE_EXIT;
|
|
415
|
-
}
|
|
416
|
-
const expectation = parsedExpectation.expectation;
|
|
417
|
-
const restartScope = readRestartScope(syncArgs, console);
|
|
418
|
-
// The wire field keeps APP-SERVER-ONLY meaning and is deliberately not widened. A
|
|
419
|
-
// remote hub must not end a local user's conversations because a field name acquired
|
|
420
|
-
// a wider meaning underneath it; the maintainer decision widened a local CLI flag and
|
|
421
|
-
// said nothing about remote callers. syncConnectedClient ignores it either way.
|
|
422
|
-
const restartCodex = restartScope.appServers;
|
|
423
|
-
const { readClientConnectionState } = await import("../client/state");
|
|
424
|
-
const clientState = readClientConnectionState();
|
|
425
|
-
// With an expectation the unlocked read decides nothing: the connected sync re-reads under its
|
|
426
|
-
// lock and refuses there, so a state that changes in between can never reach the local path.
|
|
427
|
-
if (!expectation && (clientState.kind === "invalid" || clientState.kind === "mismatched")) {
|
|
428
|
-
console.error(`Client state is ${clientState.kind}: ${clientState.reason}`);
|
|
429
|
-
return 1;
|
|
430
|
-
}
|
|
431
|
-
if (expectation || clientState.kind === "connected") {
|
|
432
|
-
try {
|
|
433
|
-
const { syncConnectedClient } = await import("../client/connect");
|
|
434
|
-
const result = await syncConnectedClient(expectation ? { restartCodex, expect: expectation } : { restartCodex });
|
|
435
|
-
if (expectation) {
|
|
436
|
-
// The root preflight skipped the shim repair for a pinned sync; the identity held, so
|
|
437
|
-
// run it now, as an unpinned sync would have.
|
|
438
|
-
const { runCodexShimAutoRestoreAsync } = await import("./codex-shim-autorestore");
|
|
439
|
-
await runCodexShimAutoRestoreAsync();
|
|
440
|
-
}
|
|
441
|
-
// The connection the sync ran under, read inside its lock; the read above may be stale.
|
|
442
|
-
const link = result.connection.transport === "link";
|
|
443
|
-
console.log(result.stale
|
|
444
|
-
? `${link ? "Home" : "Hub"} unavailable; retained and applied the last-known-good remote catalog (stale).`
|
|
445
|
-
: link ? "Remote Link Home catalog synchronized." : "Remote hub catalog synchronized.");
|
|
446
|
-
if (result.homeSettings) {
|
|
447
|
-
const { describeHomeCodexSettings } = await import("../link/codex-settings");
|
|
448
|
-
const settings = result.homeSettings;
|
|
449
|
-
if (settings.source === "local") {
|
|
450
|
-
console.log(`Codex settings: kept this machine's local values (${terminalSafeText(settings.reason)}).`);
|
|
451
|
-
} else {
|
|
452
|
-
console.log(settings.source === "home"
|
|
453
|
-
? `Codex settings applied from Home ${terminalSafeText(settings.document.home.name)}:`
|
|
454
|
-
: `Codex settings applied from the last recorded Home read (${terminalSafeText(settings.reason)}):`);
|
|
455
|
-
for (const line of describeHomeCodexSettings(settings.document.settings)) console.log(` ${terminalSafeText(line)}`);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
await handleConnectedSyncCatalogWrite(result, restartScope);
|
|
459
|
-
if (result.applyRecordFailed) {
|
|
460
|
-
console.error("The Home's Codex settings were applied, but the apply record could not be written; the client runtime was not restarted. Run 'ocx sync' again.");
|
|
461
|
-
process.exitCode = 1;
|
|
462
|
-
}
|
|
463
|
-
// OCX-6: a link Child's runtime must have started after the apply it serves under.
|
|
464
|
-
if (link && result.appliedRecord) {
|
|
465
|
-
const { applyRestartMessage, restartRuntimeAfterApply } = await import("./link-apply-restart");
|
|
466
|
-
const { sameClientConnectionOwner } = await import("../client/state");
|
|
467
|
-
const applied = result.connection;
|
|
468
|
-
const outcome = await restartRuntimeAfterApply(result.appliedRecord, {
|
|
469
|
-
restart: startWhenStopped => deps.handleProxyRestart(startWhenStopped),
|
|
470
|
-
recoveryStart: recovering => deps.handleRestartStartWhenStopped(recovering),
|
|
471
|
-
connectionUnchanged: () => {
|
|
472
|
-
const current = readClientConnectionState();
|
|
473
|
-
return current.kind === "connected" && sameClientConnectionOwner(current.value, applied)
|
|
474
|
-
&& current.value.link?.linkId === applied.link?.linkId;
|
|
475
|
-
},
|
|
476
|
-
});
|
|
477
|
-
const message = applyRestartMessage(outcome);
|
|
478
|
-
if (outcome.kind === "failed" || outcome.kind === "connection-changed") {
|
|
479
|
-
console.error(message);
|
|
480
|
-
process.exitCode = 1;
|
|
481
|
-
} else {
|
|
482
|
-
console.log(message);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
// `process.exitCode` rather than a literal 0, for the same reason every other
|
|
486
|
-
// runner does it (tests/cli/cli-transport-honesty.test.ts): the catalog-write helper
|
|
487
|
-
// drives app-server restarts, and one of those recording a failure must not be
|
|
488
|
-
// erased by the value this runner returns. It reads 0 on the ordinary path. Node
|
|
489
|
-
// types it as `number | string`; only a numeric code means anything here.
|
|
490
|
-
return typeof process.exitCode === "number" ? process.exitCode : 0;
|
|
491
|
-
} catch (error) {
|
|
492
|
-
const { ClientSyncExpectationError } = await import("../client/sync-expectation");
|
|
493
|
-
if (error instanceof ClientSyncExpectationError) return reportSyncExpectationMismatch(error, console);
|
|
494
|
-
// The refresh path reaches the same hub catalog `ocx connect` validates, so a rejected
|
|
495
|
-
// reasoning level arrives here as hub-supplied text. Rendering it through the shared
|
|
496
|
-
// terminal boundary is what keeps the routine refresh from forging output; the domain
|
|
497
|
-
// error itself is left alone for callers that inspect it.
|
|
498
|
-
console.error(`Connected sync failed without local fallback: ${terminalSafeError(error).message}`);
|
|
499
|
-
return 1;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
const live = await deps.findLiveProxy();
|
|
503
|
-
const synced = await syncModelsToCodex(
|
|
504
|
-
live?.port,
|
|
505
|
-
undefined,
|
|
506
|
-
undefined,
|
|
507
|
-
undefined,
|
|
508
|
-
{ catalogEvenWhenNotInjected: true },
|
|
509
|
-
);
|
|
510
|
-
let code = 0;
|
|
511
|
-
if (synced.status === "skipped") {
|
|
512
|
-
console.log(synced.skippedReason === "hub-gated"
|
|
513
|
-
? `${HUB_GATED_SKIP_MESSAGE} sync skipped and no Codex files changed.`
|
|
514
|
-
: "Codex integration is OFF; sync skipped and no Codex files changed.");
|
|
515
|
-
} else if (synced.status === "catalog-only") {
|
|
516
|
-
// Explicit sync with the integration OFF still refreshes the catalog/cache
|
|
517
|
-
// for side profiles that consume the proxy without injection.
|
|
518
|
-
console.log(synced.message ?? "Codex integration is OFF; catalog refreshed, Codex config untouched.");
|
|
519
|
-
if (!synced.ok) code = 1;
|
|
520
|
-
} else if (!synced.ok) {
|
|
521
|
-
code = 1;
|
|
522
|
-
console.error("Codex sync did not complete. Fix the reported Codex config issue and retry.");
|
|
523
|
-
}
|
|
524
|
-
// Catalog/model-cache writes retain their warning/restart handling. This is
|
|
525
|
-
// deliberately not an `else`: refreshCodexModelCatalog runs before injectCodexConfig,
|
|
526
|
-
// so a sync can fail (`ok: false`) after the catalog was already rewritten — which is
|
|
527
|
-
// exactly when a long-lived app-server is holding the stale list.
|
|
528
|
-
// A configuration-only change also needs a reload, but only when explicitly
|
|
529
|
-
// requested. A successful no-op or refused write is never restart authority.
|
|
530
|
-
const requestedConfigRestart = (restartScope.appServers || restartScope.desktopApp)
|
|
531
|
-
&& synced.ok && synced.configChanged === true;
|
|
532
|
-
if (synced.catalogWritten || synced.cacheSynced || requestedConfigRestart) {
|
|
533
|
-
await handleRestartScopeAfterWrite(restartScope, console);
|
|
534
|
-
}
|
|
535
|
-
// `ocx sync` is a direct CLI path; it does not call the management
|
|
536
|
-
// `/api/sync` route. Refresh already-connected file integrations here too,
|
|
537
|
-
// after Codex has published the catalog that supplies its capabilities.
|
|
538
|
-
if (synced.status !== "refused") {
|
|
539
|
-
const results: OwnedIntegrationRefreshOutcome[] = [];
|
|
540
|
-
if (live) {
|
|
541
|
-
try {
|
|
542
|
-
const config = deps.loadConfig();
|
|
543
|
-
const { refreshOwnedCatalogIntegrations } = await import("../integrations/catalog-refresh");
|
|
544
|
-
results.push(...await refreshOwnedCatalogIntegrations({
|
|
545
|
-
models: async () => {
|
|
546
|
-
const { loadExportModels } = await import("../server/management/model-rows");
|
|
547
|
-
return loadExportModels(config);
|
|
548
|
-
},
|
|
549
|
-
config,
|
|
550
|
-
port: live.port,
|
|
551
|
-
}, ["mcode", "pi", "raycast", "omo", "cline", "commandcode", "droid", "opencode", "kilo", "qoder", "qoder-cn", "workbuddy", "workbuddy-ai", "hermes", "t3code"]));
|
|
552
|
-
} catch (error) {
|
|
553
|
-
console.warn(`Client integrations were not refreshed: ${error instanceof Error ? error.message : String(error)}`);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
// Even without a live proxy, report why Aside could not sync. Its server
|
|
557
|
-
// owner is never bypassed, and another client's failure cannot hide it.
|
|
558
|
-
try {
|
|
559
|
-
const { refreshAsideProfilesThroughServer } = await import("./aside-profiles");
|
|
560
|
-
results.push(...await refreshAsideProfilesThroughServer({ findLiveProxy: async () => live }));
|
|
561
|
-
} catch (error) {
|
|
562
|
-
console.warn(`Aside profiles were not refreshed: ${error instanceof Error ? error.message : String(error)}`);
|
|
563
|
-
}
|
|
564
|
-
for (const result of results) {
|
|
565
|
-
const label = result.profileId === undefined ? result.client : `${result.client}:${result.profileId}`;
|
|
566
|
-
if (result.changed) console.log(`${label} integration refreshed from the current catalog.`);
|
|
567
|
-
else if (result.reason) console.warn(`${label} integration was not refreshed: ${result.reason}${result.residual ? " Recovery did not finish." : ""}${result.snapshotPath ? ` Backup: ${result.snapshotPath}` : ""}`);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
return code;
|
|
571
|
-
},
|
|
406
|
+
sync: async deps => (await import("./sync-update-guard")).withSyncUpdateGuard(async () => (await import("./sync-command")).runSyncCommand(deps), deps.args),
|
|
572
407
|
v2: async deps => {
|
|
573
408
|
const { cmdV2 } = await import("./v2");
|
|
574
409
|
return await cmdV2(deps.args.slice(1), { runtimeApi: { findLiveProxy: deps.findLiveProxy } }, async () => (await deps.findLiveProxy())?.port);
|
|
@@ -775,6 +610,14 @@ const commandRunners: Record<string, CommandRunner> = {
|
|
|
775
610
|
return 0;
|
|
776
611
|
},
|
|
777
612
|
update: async deps => {
|
|
613
|
+
const { isOrchestratedUpdateArgv, parseOrchestratedChildArgs } = await import("../update/orchestrated-arguments.mjs");
|
|
614
|
+
if (process.env.OCX_UPDATE_ORCHESTRATED_CHILD === "1" && deps.args.slice(1).some(arg => /^--orchestrated-(expect|result)(?:=|$)/.test(arg))) {
|
|
615
|
+
const child = parseOrchestratedChildArgs(deps.args.slice(1), process.env);
|
|
616
|
+
if (!child.ok) return 64;
|
|
617
|
+
await (await import("../update")).runUpdate(child);
|
|
618
|
+
return Number(process.exitCode ?? 0);
|
|
619
|
+
}
|
|
620
|
+
if (isOrchestratedUpdateArgv(deps.args.slice(1))) return (await import("../update/orchestrated-entry")).runOrchestratedUpdate(deps.args.slice(1));
|
|
778
621
|
// `ocx update --help` must print usage and exit WITHOUT side effects — running the
|
|
779
622
|
// real self-update stops the proxy and drops in-flight routed streams (issue #168).
|
|
780
623
|
if (hasHelpFlag(deps.args.slice(1))) {
|
|
@@ -1254,14 +1097,6 @@ export async function dispatchCommand(head: CliHead, deps: CliDispatchDeps): Pro
|
|
|
1254
1097
|
return await runner(deps);
|
|
1255
1098
|
}
|
|
1256
1099
|
|
|
1257
|
-
async function handleConnectedSyncCatalogWrite(
|
|
1258
|
-
result: { catalogWritten: boolean; cacheSynced: boolean },
|
|
1259
|
-
scope: RestartScope,
|
|
1260
|
-
): Promise<void> {
|
|
1261
|
-
if (!result.catalogWritten && !result.cacheSynced) return;
|
|
1262
|
-
await handleRestartScopeAfterWrite(scope, console);
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
1100
|
async function reconcileClientJournalBeforeLifecycle(
|
|
1266
1101
|
state: ClientConnectionState,
|
|
1267
1102
|
): Promise<void> {
|
package/src/cli/help.ts
CHANGED
|
@@ -49,7 +49,7 @@ Usage:
|
|
|
49
49
|
ocx connect <url> Connect this machine to a remote OpenCodex hub (credential via stdin)
|
|
50
50
|
ocx remote-workspace <sub> Pair/run an OCX-only remote execution computer
|
|
51
51
|
ocx disconnect Restore local state and clear the hub connection
|
|
52
|
-
ocx sync [--restart-codex]
|
|
52
|
+
ocx sync [--local-only] [--json] [--restart-codex] Sync models and linked Children
|
|
53
53
|
--expect-link <id> | --expect-hub-key <id>: only from that Home/hub key (exit 5 otherwise)
|
|
54
54
|
ocx sync-cache [--restart-codex]
|
|
55
55
|
Refresh Codex's model cache from the active catalog
|
|
@@ -72,7 +72,7 @@ Usage:
|
|
|
72
72
|
ocx restart Stop and restart the proxy
|
|
73
73
|
ocx v2 <sub> multi_agent_v2 surface (status|on|off|mode|keep-native-v1|threads|mode-hint)
|
|
74
74
|
ocx health [--json] Check proxy health (exit 0=healthy, 1=not)
|
|
75
|
-
ocx capabilities [--json]
|
|
75
|
+
ocx capabilities [--json] [--contracts] List capabilities and contracts
|
|
76
76
|
ocx ready [--json] [--wait [--timeout <s>]] Check post-sync readiness (exit 0 only when ready)
|
|
77
77
|
ocx resolve [--json] Config home, effective port, and liveness (JSON for shells)
|
|
78
78
|
ocx provider <sub> Providers, connectivity, quota, and selected models
|
package/src/cli/index.ts
CHANGED
|
@@ -210,6 +210,7 @@ async function refreshOwnedRaycastCatalog(
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
if (process.argv[2] === "__update-orchestrated-identity") process.exit(await (await import("../update/orchestrated-identity-probe-entry")).runIdentityProbe(process.argv.slice(2)));
|
|
213
214
|
if (process.argv[2] === "start" && process.env.OCX_SERVICE) startServiceLogging(join(getConfigDir(), "service.log"));
|
|
214
215
|
const updateRestartChild = admitUpdateRestartChild(process.argv.slice(2));
|
|
215
216
|
initializeNodeLauncherContext();
|
|
@@ -606,6 +607,7 @@ async function handleStart(options: { block?: boolean } = {}) {
|
|
|
606
607
|
port: bound.port,
|
|
607
608
|
hostname: bound.config.hostname,
|
|
608
609
|
attestationSecret: bound.localAttestationSecret,
|
|
610
|
+
command: currentServingCommand(),
|
|
609
611
|
...siblingRuntimeField(),
|
|
610
612
|
}); updateRestartChild?.complete(); },
|
|
611
613
|
stopBound: bound => bound.server.stop(true),
|
|
@@ -1137,7 +1139,9 @@ async function handleStopUnlocked(snapshot?: GuardedStopSnapshot) {
|
|
|
1137
1139
|
.filter(read => isPendingTeardownAbandoned(read, teardownOwnerStillRunning));
|
|
1138
1140
|
let teardownNonce: string | undefined;
|
|
1139
1141
|
// #7423: an update that restarts the proxy asks this stop to leave Codex routing for the replacement.
|
|
1140
|
-
|
|
1142
|
+
// Client start never discharges a standalone update-handover receipt or reapplies routing.
|
|
1143
|
+
const handoverRequested = updateTeardownHandoverRequested(process.env, () => shouldSyncCodexOnStart(loadConfig()))
|
|
1144
|
+
&& !stoppingSibling && readClientConnectionState().kind !== "connected";
|
|
1141
1145
|
let deferralHonoredByProxy = false;
|
|
1142
1146
|
const claimTeardown = (endpoint: { hostname: string; port: number }, endpointSource: "exact" | "guessed") => {
|
|
1143
1147
|
if (teardownNonce || stoppingSibling) return;
|
package/src/cli/link.ts
CHANGED
|
@@ -134,7 +134,7 @@ function validatePeer(value: unknown, index: number): LinkPeerStatus {
|
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
function validateStatus(value: unknown): LinkStatusPayload {
|
|
137
|
+
export function validateStatus(value: unknown): LinkStatusPayload {
|
|
138
138
|
if (!isRecord(value)) throw new Error("invalid link API response: status object");
|
|
139
139
|
assertKeys(value, ["role", "listener", "links", "child"], ["local"], "status");
|
|
140
140
|
if (value.role !== "standalone" && value.role !== "home" && value.role !== "child") {
|
package/src/cli/registry.ts
CHANGED
|
@@ -183,10 +183,13 @@ export const CLI_COMMANDS: CliCommandEntry[] = [
|
|
|
183
183
|
},
|
|
184
184
|
{
|
|
185
185
|
name: "sync",
|
|
186
|
-
usage: "ocx sync [--expect-link <linkId> | --expect-hub-key <apiKeyId>] [--restart-codex] [--restart-app-server-only]",
|
|
186
|
+
usage: "ocx sync [--expect-link <linkId> | --expect-hub-key <apiKeyId>] [--local-only] [--json] [--restart-codex] [--restart-app-server-only]",
|
|
187
187
|
summary: "Fetch provider models and inject them into Codex config.",
|
|
188
188
|
details: [
|
|
189
|
+
"A current Home catalog fans out to linked Children; --local-only disables fan-out and --json emits the result. Partial fan-out exits 6.",
|
|
190
|
+
"Fan-out never requests a Codex app or app-server restart on a Child; use GOAT or ocx sync --restart-codex on the Child. The Child's pinned sync may restart its OpenCodex client runtime after applying changed Home settings.",
|
|
189
191
|
"After writing the catalog, warns if long-lived Codex app-server processes are still running.",
|
|
192
|
+
"An update in flight or an unavailable update/sync mutex refuses without changes: update-in-flight, exit 7. Another sync reports sync-in-progress, exit 1.",
|
|
190
193
|
"--restart-codex restarts the app-servers AND fully quits and relaunches the Codex desktop app on macOS, Linux and Windows, after catalog/cache writes or a committed configuration change. It ends live conversations.",
|
|
191
194
|
"--restart-app-server-only keeps the narrow behaviour: SIGTERM to matching app-server / code-mode-host processes, desktop app left running. It wins over --restart-codex when both are given.",
|
|
192
195
|
"--restart-desktop-app is a deprecated alias of --restart-codex and prints a notice.",
|
|
@@ -290,8 +293,12 @@ export const CLI_COMMANDS: CliCommandEntry[] = [
|
|
|
290
293
|
},
|
|
291
294
|
{
|
|
292
295
|
name: "update",
|
|
293
|
-
usage: "ocx update [--tag latest|preview]",
|
|
296
|
+
usage: "ocx update [--tag latest|preview] | --plan --json [--tag latest|preview | --version <version>] | --yes --json [--tag latest|preview | --version <version>] [--expect-plan <token>] [--not-after <unix-ms>]",
|
|
294
297
|
summary: "Update opencodex. Preview installs stay on the preview tag unless overridden.",
|
|
298
|
+
details: [
|
|
299
|
+
"--plan --json previews an orchestrated update; --yes --json applies it. --expect-plan binds apply to the returned planToken; --not-after sets a Unix millisecond mutation deadline.",
|
|
300
|
+
"Orchestrated exit codes: 0 verified or up-to-date; 10 refused; 11 failed with previous version verified; 12 unverified or still running; 64 invalid usage.",
|
|
301
|
+
],
|
|
295
302
|
},
|
|
296
303
|
{
|
|
297
304
|
name: "provider",
|
|
@@ -731,10 +738,11 @@ export const CLI_COMMANDS: CliCommandEntry[] = [
|
|
|
731
738
|
},
|
|
732
739
|
{
|
|
733
740
|
name: "capabilities",
|
|
734
|
-
usage: "ocx capabilities [--json] [--mutating-only] [--route <path>]",
|
|
741
|
+
usage: "ocx capabilities [--json] [--contracts] [--mutating-only] [--route <path>]",
|
|
735
742
|
summary: "List the declared CLI capabilities and the management routes they drive.",
|
|
736
743
|
details: [
|
|
737
744
|
"The machine-readable surface index: start here when driving ocx programmatically instead of parsing help text.",
|
|
745
|
+
"--contracts lists supported versioned contracts; it cannot be combined with --route or --mutating-only.",
|
|
738
746
|
"--route <path> answers the inverse question: which commands drive this management route.",
|
|
739
747
|
],
|
|
740
748
|
},
|
package/src/cli/root.ts
CHANGED
|
@@ -13,11 +13,13 @@ 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 { parseSyncFanoutFlags } from "./sync-flags";
|
|
16
17
|
import { maybeAutoRestoreCodexShimAsync } from "./codex-shim-autorestore";
|
|
17
18
|
import { findCommand } from "./registry";
|
|
18
19
|
import { printUnknownCommand } from "./help-recovery";
|
|
19
20
|
import { noteCredentialArgv, redactSecretArgs } from "./secret-args";
|
|
20
21
|
import { maybeNoticeVersionSkew } from "./version-skew-notice";
|
|
22
|
+
import { isOrchestratedUpdateArgv } from "../update/orchestrated-arguments.mjs";
|
|
21
23
|
|
|
22
24
|
export interface CliHead {
|
|
23
25
|
kind: "version" | "help" | "ready" | "resolve" | "command";
|
|
@@ -40,6 +42,7 @@ export function parseCliHead(argv: string[]): CliHead {
|
|
|
40
42
|
const args = argv;
|
|
41
43
|
// Codex owns its forwarded grammar; wrapper documentation is `ocx help codex`.
|
|
42
44
|
if (command === "codex") return { kind: "command", command, args };
|
|
45
|
+
if (command === "update" && isOrchestratedUpdateArgv(args.slice(1))) return { kind: "command", command, args };
|
|
43
46
|
if (command === "--version" || command === "-v" || command === "version") {
|
|
44
47
|
return { kind: "version", command, args };
|
|
45
48
|
}
|
|
@@ -147,6 +150,11 @@ export async function runCli(argv: string[]): Promise<CliHead> {
|
|
|
147
150
|
}
|
|
148
151
|
// #7694: a malformed pinned sync is refused before any preflight reads or repairs anything.
|
|
149
152
|
if (head.command === "sync") {
|
|
153
|
+
const flags = parseSyncFanoutFlags(head.args.slice(1));
|
|
154
|
+
if (!flags.ok) {
|
|
155
|
+
console.error(flags.message);
|
|
156
|
+
process.exit(SYNC_EXPECTATION_USAGE_EXIT);
|
|
157
|
+
}
|
|
150
158
|
const pinned = parseSyncExpectation(head.args.slice(1));
|
|
151
159
|
if (!pinned.ok) {
|
|
152
160
|
console.error(pinned.message);
|