@bitkyc08/opencodex 2.100.1 → 2.100.3
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/README.md +1 -1
- package/bin/ocx.mjs +32 -18
- package/gui/dist/assets/{App-COo8Yopd.css → App-BGP8I0V4.css} +1 -1
- package/gui/dist/assets/App-Dnb6VMsP.js +59 -0
- package/gui/dist/assets/Tray-BV4ms9U9.js +1 -0
- package/gui/dist/assets/{brand-mark-nr3ziR-T.js → brand-mark-XOLJbomA.js} +1 -1
- package/gui/dist/assets/index-DCdXsMyZ.js +105 -0
- package/gui/dist/assets/index-DQtCRNAw.css +2 -0
- package/gui/dist/assets/{segment-thumb-features-DKCVUUTi.js → segment-thumb-features-DXSidY6D.js} +1 -1
- package/gui/dist/classic/assets/App-DA-scMPq.js +58 -0
- package/gui/dist/classic/assets/{Tray-BedmOsE7.js → Tray-BrHaVRAq.js} +1 -1
- package/gui/dist/classic/assets/index-BqOaGLf5.js +105 -0
- package/gui/dist/classic/assets/quota-summary-Dy5_wfTT.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/Cargo.toml +9 -0
- package/native/ocx-child/src/cli.rs +402 -20
- package/native/ocx-child/src/codex_home.rs +98 -14
- package/native/ocx-child/src/daemon.rs +2 -1
- package/native/ocx-child/src/lib.rs +3 -0
- package/native/ocx-child/src/link_ws.rs +2598 -0
- package/native/ocx-child/src/link_ws_advert.rs +346 -0
- package/native/ocx-child/src/link_ws_frame.rs +749 -0
- package/native/ocx-child/src/parity.rs +5 -1
- package/native/ocx-child/src/platform.rs +152 -6
- package/native/ocx-child/src/relay.rs +150 -19
- package/package.json +3 -3
- package/src/adapters/anthropic/advisor-tool.ts +176 -0
- package/src/adapters/anthropic/beta-body-pairs.ts +6 -0
- package/src/adapters/anthropic/client-identity.ts +3 -1
- package/src/adapters/anthropic/passthrough.ts +9 -3
- package/src/adapters/anthropic.ts +31 -14
- package/src/adapters/client-fingerprint.ts +6 -4
- package/src/adapters/cursor/discovery.ts +17 -0
- package/src/adapters/cursor/native-exec-desktop.ts +2 -1
- package/src/adapters/cursor/native-exec-shell.ts +2 -1
- package/src/adapters/cursor/native-exec.ts +3 -2
- package/src/adapters/cursor/protobuf-request.ts +8 -8
- package/src/adapters/cursor/tool-guidance.ts +3 -3
- package/src/adapters/cursor/tool-wording.ts +10 -1
- package/src/adapters/cursor.ts +7 -6
- package/src/adapters/devin/cloud-direct/tool-schema.ts +20 -2
- package/src/adapters/google-antigravity-wire.ts +15 -6
- package/src/adapters/google-truncation.ts +4 -2
- package/src/adapters/google-wire-compiler.ts +2 -2
- package/src/adapters/google.ts +17 -4
- package/src/adapters/kiro/payload.ts +7 -4
- package/src/adapters/kiro/reasoning.ts +44 -1
- package/src/adapters/kiro/structured-output.ts +10 -8
- package/src/adapters/kiro-tools.ts +61 -15
- package/src/adapters/openai-chat/destination-policy.ts +16 -0
- package/src/adapters/openai-chat/reasoning-replay.ts +4 -1
- package/src/adapters/openai-chat/tool-schema.ts +9 -0
- package/src/adapters/openai-responses/tool-schema.ts +18 -4
- package/src/adapters/run-turn-queue.ts +139 -5
- package/src/adapters/upstream-http-error.ts +4 -2
- package/src/adapters/zed.ts +3 -0
- package/src/advisor/consult.ts +15 -4
- package/src/advisor/context.ts +12 -3
- package/src/advisor/runtime.ts +35 -5
- package/src/advisor/settings.ts +8 -0
- package/src/advisor/synthetic-tool.ts +21 -8
- package/src/bridge/response-json.ts +11 -2
- package/src/bridge/sse.ts +51 -9
- package/src/claude/auth-detect.ts +21 -33
- package/src/claude/chat-tool-dispatch.ts +233 -0
- package/src/claude/desktop-3p.ts +11 -5
- package/src/claude/desktop-gateway-state.ts +2 -0
- package/src/claude/desktop-remote-store-artifact.ts +14 -3
- package/src/claude/desktop-remote-store.ts +24 -4
- package/src/claude/inbound-content-options.ts +31 -16
- package/src/claude/inbound-tool-loading.ts +42 -17
- package/src/claude/outbound.ts +13 -3
- package/src/cli/account-api.ts +23 -1
- package/src/cli/account-auth.ts +54 -21
- package/src/cli/account-extended.ts +60 -6
- package/src/cli/account-key-quota.ts +56 -7
- package/src/cli/account.ts +5 -3
- package/src/cli/advisor.ts +7 -4
- package/src/cli/alias.ts +38 -1
- package/src/cli/capabilities-access-remote.ts +137 -2
- package/src/cli/capabilities-accounts.ts +3 -3
- package/src/cli/capabilities-agents-routing.ts +17 -10
- package/src/cli/capabilities-base.ts +43 -18
- package/src/cli/capabilities-integrations.ts +2 -2
- package/src/cli/capabilities-provider-models.ts +18 -2
- package/src/cli/capabilities-route-to.ts +43 -0
- package/src/cli/capabilities.ts +2 -0
- package/src/cli/capability-contracts.ts +1 -1
- package/src/cli/claude-desktop.ts +30 -11
- package/src/cli/claude.ts +36 -17
- package/src/cli/codex-launcher.ts +3 -1
- package/src/cli/codex-shim-autorestore.ts +5 -42
- package/src/cli/config-command.ts +38 -2
- package/src/cli/config-root-startup.ts +34 -0
- package/src/cli/connect.ts +124 -19
- package/src/cli/desktop-runtime-guidance.ts +1 -1
- package/src/cli/disconnect-runtime.ts +168 -0
- package/src/cli/dispatch.ts +54 -12
- package/src/cli/export-command.ts +1 -1
- package/src/cli/gui-pair-client.ts +29 -5
- package/src/cli/gui.ts +10 -5
- package/src/cli/help-catalog.ts +11 -0
- package/src/cli/help.ts +5 -4
- package/src/cli/hub.ts +18 -1
- package/src/cli/index.ts +83 -92
- package/src/cli/inspect.ts +11 -2
- package/src/cli/integrations.ts +26 -1
- package/src/cli/link-capture.ts +64 -0
- package/src/cli/link-child-ops.ts +314 -0
- package/src/cli/link-cleanup.ts +8 -5
- package/src/cli/link-diagnostics.ts +67 -0
- package/src/cli/link-enrollment.ts +158 -12
- package/src/cli/link-operations.ts +52 -0
- package/src/cli/link-recover.ts +152 -0
- package/src/cli/link-routes.ts +87 -0
- package/src/cli/link-status-child.ts +137 -0
- package/src/cli/link-status-traffic.ts +34 -0
- package/src/cli/link.ts +327 -37
- package/src/cli/message-command.ts +1 -1
- package/src/cli/message-mcp-command.ts +23 -10
- package/src/cli/models-runtime.ts +3 -3
- package/src/cli/opencode.ts +3 -1
- package/src/cli/pi-sync.ts +35 -0
- package/src/cli/preflight-exemptions.ts +46 -0
- package/src/cli/registry.ts +29 -12
- package/src/cli/restart-failure.ts +5 -2
- package/src/cli/root.ts +5 -1
- package/src/cli/route-to.ts +172 -0
- package/src/cli/runtime-api.ts +5 -8
- package/src/cli/status.ts +3 -1
- package/src/cli/stop-approval.ts +66 -19
- package/src/cli/stop-report.ts +23 -0
- package/src/cli/stop-windows-checked.ts +304 -0
- package/src/cli/sync-command.ts +70 -13
- package/src/cli/sync-fanout.ts +81 -99
- package/src/cli/sync-flags.ts +40 -3
- package/src/cli/sync-link-status.ts +18 -2
- package/src/cli/sync-update-guard.ts +7 -2
- package/src/cli/system-restart-client.ts +3 -2
- package/src/cli/uninstall-plan.ts +77 -5
- package/src/cli/uninstall-stop.ts +152 -0
- package/src/cli/v2-input.ts +10 -6
- package/src/cli/v2-local-output.ts +3 -2
- package/src/cli/v2-runtime.ts +10 -3
- package/src/cli/v2.ts +22 -7
- package/src/client/connect.ts +321 -34
- package/src/client/link-home-features.ts +27 -0
- package/src/client/link-home.ts +92 -4
- package/src/client/link-ingress.ts +21 -3
- package/src/client/link-join.ts +12 -2
- package/src/client/link-parity-reporter.ts +60 -6
- package/src/client/link-readiness.ts +16 -6
- package/src/client/link-relay-transport.ts +161 -36
- package/src/client/link-relay.ts +150 -6
- package/src/client/link-request-compression.ts +84 -0
- package/src/client/link-state.ts +11 -5
- package/src/client/link-status.ts +39 -1
- package/src/client/link-teardown.ts +1 -0
- package/src/client/link-tunnel-status.ts +76 -0
- package/src/client/link-tunnel.ts +56 -5
- package/src/client/link-websocket-limits.ts +89 -0
- package/src/client/link-websocket.ts +586 -0
- package/src/client/link-ws-advertisement.ts +100 -0
- package/src/client/link-ws-framer.ts +241 -0
- package/src/client/link-ws-transport.ts +177 -0
- package/src/client/machine-api.ts +13 -2
- package/src/client/machine-listener.ts +48 -7
- package/src/client/route-intent-apply.ts +293 -0
- package/src/client/route-intent-file-originals.ts +97 -0
- package/src/client/route-intent-native-originals.ts +201 -0
- package/src/client/route-intent-watch.ts +141 -0
- package/src/client/runtime-restart.ts +127 -5
- package/src/client/runtime.ts +61 -15
- package/src/client/state.ts +30 -0
- package/src/client/sync-expectation.ts +36 -2
- package/src/client/sync-runtime.ts +7 -0
- package/src/clients/config-export/alias-selectors.ts +63 -40
- package/src/clients/config-export/contracts.ts +2 -0
- package/src/clients/config-export/nested-selectors.ts +42 -0
- package/src/clients/config-export.ts +36 -4
- package/src/codex/account-resume-health.ts +41 -0
- package/src/codex/account-store.ts +12 -3
- package/src/codex/account-usability.ts +13 -0
- package/src/codex/auth-api/account-list.ts +29 -3
- package/src/codex/auth-api/login-flow.ts +6 -0
- package/src/codex/auth-api/routes.ts +35 -2
- package/src/codex/auth-collision.ts +23 -22
- package/src/codex/auth-context.ts +21 -6
- package/src/codex/catalog/gather-capture.ts +10 -2
- package/src/codex/catalog/parsing.ts +7 -3
- package/src/codex/catalog/provider-models.ts +67 -23
- package/src/codex/catalog/retained-sync.ts +2 -1
- package/src/codex/catalog/routed-gather.ts +1 -1
- package/src/codex/catalog-auto-refresh.ts +11 -0
- package/src/codex/cli-update-job.ts +35 -13
- package/src/codex/convergence-types.ts +2 -0
- package/src/codex/convergence.ts +2 -2
- package/src/codex/desktop-compatibility/native-identity.ts +4 -8
- package/src/codex/features.ts +2 -2
- package/src/codex/history-provider.ts +31 -0
- package/src/codex/inject/multi-agent-v2.ts +9 -3
- package/src/codex/inject/paginated-openai-compat.ts +54 -1
- package/src/codex/inject/plan.ts +20 -2
- package/src/codex/inject.ts +2 -0
- package/src/codex/journal-config-restore.ts +217 -0
- package/src/codex/journal.ts +75 -6
- package/src/codex/main-account.ts +23 -30
- package/src/codex/native-main-auth-file.ts +104 -0
- package/src/codex/native-profile-manager.ts +4 -3
- package/src/codex/native-profile-store.ts +3 -61
- package/src/codex/orca-import.ts +10 -1
- package/src/codex/quota-history.ts +13 -0
- package/src/codex/quota-window-conflict.ts +103 -0
- package/src/codex/quota.ts +134 -7
- package/src/codex/subagent-model-fallback.ts +3 -1
- package/src/codex/websocket-activity.ts +171 -16
- package/src/codex/websocket-registry.ts +11 -4
- package/src/combos/cooldown-store.ts +228 -0
- package/src/combos/failover.ts +760 -35
- package/src/config/dashboard-trusted-proxy.ts +83 -0
- package/src/config/diagnostics.ts +28 -0
- package/src/config/feature-flags.ts +9 -0
- package/src/config/live-reconcile.ts +10 -1
- package/src/config/load-degrade.ts +12 -1
- package/src/config/multi-agent-surface.ts +28 -5
- package/src/config/pending-teardown.ts +60 -3
- package/src/config/process-state.ts +175 -4
- package/src/config/provider-validation.ts +4 -4
- package/src/config/salvage.ts +1 -0
- package/src/config/schema/config-schema.ts +12 -3
- package/src/config/schema/leaf-validators.ts +43 -14
- package/src/config/windows-process-command-line.ts +107 -0
- package/src/generated/compatibility-version.json +1077 -429
- package/src/generated/model-metadata.ts +1 -1
- package/src/images/loop.ts +3 -0
- package/src/integrations/model-name-guard.ts +25 -0
- package/src/integrations/route-intent-catalog.ts +26 -0
- package/src/integrations/route-intent-connected.ts +262 -0
- package/src/integrations/route-intent-contract.ts +55 -0
- package/src/integrations/route-intent-disconnect.ts +109 -0
- package/src/integrations/route-intent-initial.ts +64 -0
- package/src/integrations/route-intent-state.ts +117 -0
- package/src/integrations/route-intent-tick.ts +65 -0
- package/src/integrations/route-intent.ts +212 -0
- package/src/integrations/writer.ts +44 -11
- package/src/lib/catalog-etag.ts +10 -0
- package/src/lib/client-error-body.ts +15 -0
- package/src/lib/client-retry-after.ts +29 -0
- package/src/lib/config-ownership.ts +13 -0
- package/src/lib/context-overflow-verdict.ts +266 -9
- package/src/lib/desktop-gui-origin.ts +28 -0
- package/src/lib/errors.ts +1 -1
- package/src/lib/failure-detail.ts +72 -3
- package/src/lib/gui-pair-capability.ts +2 -1
- package/src/lib/hard-refusal.ts +259 -0
- package/src/lib/messages-error-body.ts +4 -1
- package/src/lib/outbound-credential-registry.ts +362 -4
- package/src/lib/paced-stream.ts +34 -0
- package/src/lib/passive-key-fetch-proof.ts +30 -0
- package/src/lib/passive-read.ts +5 -0
- package/src/lib/process-control.ts +76 -12
- package/src/lib/redact.ts +84 -8
- package/src/lib/state-store-registrations.ts +11 -0
- package/src/lib/state-store-sweeper.ts +4 -0
- package/src/lib/supervisor-markers.ts +18 -0
- package/src/lib/terminal-safe-text.ts +58 -0
- package/src/lib/translator-budget.ts +3 -2
- package/src/lib/upstream-retry.ts +14 -4
- package/src/link/alias-lock.ts +119 -0
- package/src/link/child-activity.ts +83 -0
- package/src/link/child-binary-cache-fill.d.mts +50 -0
- package/src/link/child-binary-cache-fill.mjs +494 -0
- package/src/link/child-binary-cache-start.ts +73 -0
- package/src/link/child-binary-source.ts +12 -5
- package/src/link/child-catalog-freshness.ts +149 -0
- package/src/link/child-gated-ocx.ts +135 -0
- package/src/link/child-observations.ts +206 -0
- package/src/link/child-observe.ts +121 -0
- package/src/link/child-ops-engine.ts +230 -0
- package/src/link/child-ops-host.ts +138 -0
- package/src/link/child-ops-runners.ts +319 -0
- package/src/link/child-ops-scheduler.ts +207 -0
- package/src/link/child-ops-types.ts +89 -0
- package/src/link/child-parity.ts +23 -4
- package/src/link/child-policy.ts +93 -0
- package/src/link/child-update-contract.ts +174 -0
- package/src/link/codex-settings.ts +1 -1
- package/src/link/compatibility.ts +18 -1
- package/src/link/diagnostics-read.ts +163 -0
- package/src/link/diagnostics.ts +20 -7
- package/src/link/explicit-route.ts +209 -0
- package/src/link/link-recover.ts +113 -0
- package/src/link/management-routes.ts +3 -1
- package/src/link/operation-recovery-slot.ts +44 -0
- package/src/link/operations-journal.ts +408 -0
- package/src/link/paths.ts +5 -0
- package/src/link/peer-report.ts +1 -1
- package/src/link/relay-auth.ts +14 -0
- package/src/link/remote-plant.ts +152 -14
- package/src/link/remote-platform.ts +21 -10
- package/src/link/remote-probe.ts +11 -3
- package/src/link/remote-windows.ts +88 -12
- package/src/link/request-compression.ts +30 -0
- package/src/link/residual-recovery.ts +54 -0
- package/src/link/retirement.ts +128 -0
- package/src/link/route-intent-watch.ts +41 -0
- package/src/link/route-intent.ts +209 -0
- package/src/link/route-proof.ts +82 -0
- package/src/link/route-rounds.ts +579 -0
- package/src/link/route-select.ts +95 -0
- package/src/link/route-trust.ts +96 -0
- package/src/link/ssh-argv.ts +285 -43
- package/src/link/ssh-capture-redact.ts +253 -0
- package/src/link/ssh-capture.ts +497 -0
- package/src/link/ssh-runner.ts +141 -14
- package/src/link/status-projection.ts +160 -0
- package/src/link/store.ts +54 -1
- package/src/link/supervisor.ts +543 -55
- package/src/link/sync-fanout-classify.ts +114 -0
- package/src/link/sync-then-restart.ts +65 -0
- package/src/link/tombstones.ts +209 -0
- package/src/link/traffic.ts +178 -0
- package/src/link/tunnel-state.ts +10 -4
- package/src/link/ws-activity-holds.ts +474 -0
- package/src/local-credentials/publication-fence.ts +20 -1
- package/src/messaging/mcp-queue-rpc.ts +3 -2
- package/src/messaging/mcp-queue-server.ts +21 -1
- package/src/messaging/mcp-reply-tools.ts +24 -9
- package/src/messaging/mcp-reply-wait.ts +70 -0
- package/src/messaging/mcp-resume-tools.ts +25 -0
- package/src/messaging/remote-enrollment.ts +3 -3
- package/src/messaging/remote-tunnels.ts +2 -2
- package/src/messaging/resume-permissions.ts +27 -0
- package/src/messaging/rpc.ts +46 -2
- package/src/oauth/account-resume-health.ts +60 -0
- package/src/oauth/anthropic-continuity.ts +23 -7
- package/src/oauth/anthropic-routing.ts +5 -2
- package/src/oauth/anthropic.ts +22 -2
- package/src/oauth/claude-keychain-read.ts +78 -68
- package/src/oauth/index.ts +25 -6
- package/src/oauth/local-token-detect.ts +8 -29
- package/src/oauth/login-cli-errors.ts +5 -1
- package/src/oauth/login-cli.ts +33 -18
- package/src/oauth/login-flow-state.ts +26 -3
- package/src/oauth/meta-muse.ts +1 -1
- package/src/oauth/store.ts +51 -1
- package/src/oauth/xai.ts +248 -14
- package/src/protocols/contract.ts +4 -0
- package/src/protocols/encoders/messages.ts +1 -0
- package/src/providers/alias-template.ts +48 -0
- package/src/providers/anthropic-billing-ownership.ts +2 -0
- package/src/providers/anthropic-output-caps.ts +46 -0
- package/src/providers/anthropic-reset-grant-ledger.ts +9 -3
- package/src/providers/antigravity-effort-families.ts +11 -3
- package/src/providers/antigravity-models.ts +32 -9
- package/src/providers/antigravity-wire-snapshot.ts +3 -2
- package/src/providers/api-key-pause-state.ts +23 -0
- package/src/providers/api-key-pause.ts +71 -10
- package/src/providers/api-key-resolve.ts +49 -7
- package/src/providers/api-key-response-ownership.ts +2 -0
- package/src/providers/api-key-selection-capture.ts +3 -1
- package/src/providers/api-key-selection.ts +54 -11
- package/src/providers/api-keys.ts +24 -7
- package/src/providers/cache-affinity-identity.ts +73 -0
- package/src/providers/cache-affinity.ts +256 -0
- package/src/providers/claude-cli-usage-state.ts +11 -6
- package/src/providers/claude-cli-usage.ts +27 -9
- package/src/providers/codex-capacity.ts +11 -2
- package/src/providers/default-aliases.ts +98 -20
- package/src/providers/google-vertex-model-discovery.ts +510 -0
- package/src/providers/key-failover.ts +136 -14
- package/src/providers/key-store.ts +3 -3
- package/src/providers/kiro-models.ts +3 -5
- package/src/providers/label.ts +31 -5
- package/src/providers/mistral-transport.ts +17 -4
- package/src/providers/model-discovery-config.ts +31 -0
- package/src/providers/model-discovery-diagnostic.ts +34 -3
- package/src/providers/model-discovery.ts +43 -7
- package/src/providers/model-rename-fields.ts +5 -0
- package/src/providers/muse-key-quota.ts +14 -6
- package/src/providers/new-model-policy-runtime.ts +17 -4
- package/src/providers/new-model-policy.ts +30 -4
- package/src/providers/openai-sidecar.ts +15 -2
- package/src/providers/passive-key-observation.ts +252 -0
- package/src/providers/provider-id-rewrite.ts +3 -0
- package/src/providers/quota/account-cache.ts +53 -34
- package/src/providers/quota/anthropic-cooldown-recovery-worker.ts +121 -0
- package/src/providers/quota/anthropic-usage-windows.ts +19 -9
- package/src/providers/quota/passive-key-limits.ts +272 -0
- package/src/providers/quota/passive-wire-model.ts +126 -0
- package/src/providers/quota/report-cache.ts +112 -5
- package/src/providers/quota/vendor-probes-key.ts +73 -0
- package/src/providers/quota/vendor-probes-oauth.ts +57 -3
- package/src/providers/quota-key-accounts.ts +22 -10
- package/src/providers/quota-mistral-budget.ts +18 -0
- package/src/providers/quota-types.ts +43 -0
- package/src/providers/quota.ts +31 -32
- package/src/providers/reasoning-metadata.ts +1051 -12
- package/src/providers/registry/entries-core.ts +34 -16
- package/src/providers/registry/entries-extended.ts +32 -0
- package/src/providers/registry/model-seeds.ts +35 -0
- package/src/providers/resolved-model-policy.ts +7 -0
- package/src/providers/routed-config.ts +8 -3
- package/src/providers/xai-transport.ts +3 -0
- package/src/quota/reset-observer.ts +4 -2
- package/src/quota/reset-seen-store.ts +9 -0
- package/src/quota/window-mapping.ts +1 -0
- package/src/quota-pool/assemble.ts +4 -1
- package/src/remote/features.ts +17 -0
- package/src/responses/anthropic-progress.ts +10 -4
- package/src/responses/citation-markers.ts +231 -0
- package/src/responses/hosted-tool-policy.ts +56 -12
- package/src/responses/spill-store.ts +5 -1
- package/src/responses/state/replay-input.ts +50 -0
- package/src/responses/state/replay-owner.ts +24 -0
- package/src/responses/state/snapshot-codec.ts +9 -0
- package/src/responses/state/spill-queue.ts +1 -0
- package/src/responses/state.ts +42 -60
- package/src/router.ts +4 -2
- package/src/routing/home-route-capture.ts +123 -0
- package/src/routing/home-route-intent.ts +200 -0
- package/src/routing/route-intent-state.ts +178 -0
- package/src/routing/route-to-live-settings.ts +35 -0
- package/src/routing/route-to-local.ts +145 -0
- package/src/routing/route-to-status.ts +94 -0
- package/src/routing/route-to-sync-child.ts +32 -0
- package/src/server/adapter-resolve.ts +21 -1
- package/src/server/admitted-http-turn.ts +3 -0
- package/src/server/auth-cors.ts +109 -8
- package/src/server/bare-upstream-error.ts +220 -0
- package/src/server/catalog-download.ts +3 -5
- package/src/server/chat-native.ts +25 -7
- package/src/server/claude-messages.ts +8 -5
- package/src/server/codex-model-list.ts +2 -1
- package/src/server/configured-credentials.ts +37 -5
- package/src/server/gui-desktop-authorization.ts +36 -0
- package/src/server/gui-pair-delivery.ts +6 -3
- package/src/server/gui-session.ts +10 -1
- package/src/server/images.ts +41 -13
- package/src/server/inbound-body-admission.ts +17 -4
- package/src/server/index/link-listener.ts +203 -11
- package/src/server/index/link-management.ts +15 -1
- package/src/server/index/link-relay-sessions.ts +128 -8
- package/src/server/index/link-websocket-limits.ts +136 -0
- package/src/server/index/link-websocket.ts +692 -0
- package/src/server/index/optional-listeners.ts +115 -7
- package/src/server/index/route-intent-watch.ts +47 -0
- package/src/server/index/serve-contract.ts +86 -0
- package/src/server/index/serve-options.ts +35 -86
- package/src/server/index/startup-warnings.ts +8 -2
- package/src/server/index/websocket-handler.ts +26 -4
- package/src/server/index.ts +12 -2
- package/src/server/inference/client-encoder-delivery.ts +2 -0
- package/src/server/inspection-tee.ts +39 -2
- package/src/server/lifecycle.ts +2 -0
- package/src/server/link-turn.ts +137 -0
- package/src/server/management/advisor-routes.ts +10 -2
- package/src/server/management/agent-settings-routes.ts +50 -16
- package/src/server/management/anthropic-reset-grant-routes.ts +1 -1
- package/src/server/management/config-routes.ts +7 -1
- package/src/server/management/context.ts +9 -2
- package/src/server/management/desktop-authorization.ts +41 -0
- package/src/server/management/desktop-compatibility-routes.ts +9 -8
- package/src/server/management/desktop-compatibility-runtime-routes.ts +3 -2
- package/src/server/management/desktop-compatibility-settings-routes.ts +5 -3
- package/src/server/management/home-integration-decision.ts +89 -0
- package/src/server/management/integration-routes.ts +208 -81
- package/src/server/management/link-child-ops-routes.ts +218 -0
- package/src/server/management/link-child-preflight.ts +31 -0
- package/src/server/management/link-diagnostics-route.ts +29 -0
- package/src/server/management/link-enrollment.ts +199 -47
- package/src/server/management/link-operation.ts +609 -0
- package/src/server/management/link-recover-route.ts +103 -0
- package/src/server/management/link-route-edit.ts +173 -0
- package/src/server/management/link-route-request.ts +62 -0
- package/src/server/management/link-route-state.ts +92 -6
- package/src/server/management/link-routes.ts +563 -51
- package/src/server/management/link-traffic-status.ts +13 -0
- package/src/server/management/model-routes.ts +122 -36
- package/src/server/management/model-rows.ts +2 -1
- package/src/server/management/native-integration-routes.ts +176 -70
- package/src/server/management/oauth-account-routes.ts +69 -17
- package/src/server/management/protocol-routes.ts +7 -0
- package/src/server/management/provider-completion-test.ts +4 -4
- package/src/server/management/provider-overwrite-carry.ts +39 -3
- package/src/server/management/provider-routes.ts +80 -72
- package/src/server/management/provider-routing-quota.ts +45 -0
- package/src/server/management/route-registry.ts +25 -3
- package/src/server/management/route-to-routes.ts +257 -0
- package/src/server/management/system-restart.ts +4 -2
- package/src/server/management/usage-aggregate-cache.ts +101 -66
- package/src/server/management-api.ts +17 -3
- package/src/server/management-auth.ts +13 -1
- package/src/server/messages-native-preflight.ts +27 -4
- package/src/server/messages-native.ts +22 -5
- package/src/server/persistent-gui-session.ts +6 -3
- package/src/server/proxy-liveness.ts +33 -6
- package/src/server/relay-eager.ts +36 -12
- package/src/server/relay.ts +183 -116
- package/src/server/request-body-facts.ts +48 -0
- package/src/server/request-decompress.ts +65 -2
- package/src/server/request-log-account-rotation.ts +6 -0
- package/src/server/request-log-attempt-usage.ts +69 -0
- package/src/server/request-log-cache-affinity.ts +60 -0
- package/src/server/request-log-conversation.ts +45 -2
- package/src/server/request-log-failure-detail.ts +59 -1
- package/src/server/request-log-terminal-status.ts +210 -24
- package/src/server/request-log.ts +71 -79
- package/src/server/responses/adapter-continuation.ts +2 -1
- package/src/server/responses/adapter-delivery.ts +2 -0
- package/src/server/responses/adapter-dispatch.ts +40 -51
- package/src/server/responses/advisor-plan-slot.ts +33 -1
- package/src/server/responses/advisor-question.ts +21 -0
- package/src/server/responses/advisor-slot.ts +10 -3
- package/src/server/responses/bare-namespace-aliases.ts +18 -0
- package/src/server/responses/buffered-sse-json.ts +9 -3
- package/src/server/responses/code-mode-collab-surface.ts +11 -0
- package/src/server/responses/codex-tool-catalog.ts +156 -0
- package/src/server/responses/combo-required-tool-fulfillments.ts +4 -2
- package/src/server/responses/combo-stream-preflight.ts +701 -81
- package/src/server/responses/compact.ts +47 -12
- package/src/server/responses/context-overflow.ts +58 -2
- package/src/server/responses/core-codex-account.ts +17 -3
- package/src/server/responses/core-combo-failure.ts +37 -4
- package/src/server/responses/core-combo-native.ts +3 -1
- package/src/server/responses/core-combo.ts +62 -7
- package/src/server/responses/core-errors.ts +8 -3
- package/src/server/responses/core-lifetime.ts +3 -2
- package/src/server/responses/core-normalize.ts +3 -1
- package/src/server/responses/core-opaque-recovery.ts +45 -2
- package/src/server/responses/core-options.ts +18 -0
- package/src/server/responses/core.ts +2 -0
- package/src/server/responses/fetch-helpers.ts +15 -10
- package/src/server/responses/native-replay-guard.ts +57 -0
- package/src/server/responses/opengateway-completion-guard.ts +10 -4
- package/src/server/responses/outbound-request-body.ts +29 -0
- package/src/server/responses/passthrough-completion.ts +105 -8
- package/src/server/responses/passthrough-delivery.ts +31 -11
- package/src/server/responses/passthrough-dispatch.ts +99 -106
- package/src/server/responses/policy-fallback.ts +13 -1
- package/src/server/responses/request-prepare.ts +50 -6
- package/src/server/responses/request-transport.ts +53 -17
- package/src/server/responses/reset-replay.ts +104 -4
- package/src/server/responses/run-turn-execution.ts +58 -30
- package/src/server/responses/sidecar-execution.ts +14 -0
- package/src/server/responses/terminal-error-redaction.ts +222 -25
- package/src/server/responses/ws-upstream.ts +2 -2
- package/src/server/sse-payload-rewrite.ts +3 -2
- package/src/server/stop-service-route.ts +85 -0
- package/src/server/system-env-shell.ts +12 -1
- package/src/server/system-env.ts +5 -3
- package/src/server/windows-tcp-drop.ts +21 -4
- package/src/server/workflow-refusal.ts +8 -0
- package/src/server/ws-bridge.ts +191 -12
- package/src/service/cli-windows-stop.ts +189 -0
- package/src/service/cli.ts +41 -12
- package/src/service/disconnected-client-restart.ts +60 -0
- package/src/service/guarded-manager-target.ts +18 -1
- package/src/service/health.ts +99 -6
- package/src/service/launchd.ts +84 -31
- package/src/service/orchestration.ts +418 -91
- package/src/service/repair.ts +223 -6
- package/src/service/restart-proxy-stop.ts +79 -0
- package/src/service/service-child-ownership.ts +6 -2
- package/src/service/windows-checked-stop-live.ts +467 -0
- package/src/service/windows-checked-stop.ts +435 -0
- package/src/service/windows-command-line-token.ts +23 -0
- package/src/service/windows-guarded-manager.ts +77 -34
- package/src/service/windows-ops.ts +38 -56
- package/src/service/windows-process-evidence.ts +292 -0
- package/src/service/windows-process-native.ts +262 -0
- package/src/service/windows-service-stop.ts +321 -0
- package/src/service/windows-stop-binding.ts +187 -0
- package/src/service/windows-stop-budget.ts +123 -0
- package/src/service/windows-stop-confirm.ts +158 -0
- package/src/service/windows-stop-deadline.ts +56 -0
- package/src/service.ts +2 -2
- package/src/types/claude-tool-loading.ts +48 -0
- package/src/types/config.ts +47 -53
- package/src/types/link.ts +20 -0
- package/src/types/multi-agent.ts +13 -0
- package/src/types/provider.ts +68 -2
- package/src/types/request.ts +4 -0
- package/src/types.ts +4 -0
- package/src/update/guarded-runtime-ops.ts +5 -7
- package/src/update/index.ts +25 -10
- package/src/update/install-detection.mjs +3 -1
- package/src/update/job-pinned-start.ts +2 -0
- package/src/update/job-windows-restart.ts +19 -32
- package/src/update/job.ts +12 -5
- package/src/update/npm-install.d.mts +11 -0
- package/src/update/npm-install.mjs +44 -7
- package/src/update/orchestrated-entry.ts +1 -1
- package/src/update/orchestrated-node-driver.mjs +3 -2
- package/src/update/orchestrated-pnpm.d.mts +4 -0
- package/src/update/orchestrated-pnpm.mjs +50 -6
- package/src/update/orchestrated-session.d.mts +3 -1
- package/src/update/orchestrated-session.mjs +21 -6
- package/src/update/pnpm-global-install.d.mts +21 -3
- package/src/update/pnpm-global-install.mjs +322 -19
- package/src/update/pnpm-store-layout.mjs +46 -0
- package/src/update/sync-update-mutex.d.mts +3 -2
- package/src/update/sync-update-mutex.mjs +57 -8
- package/src/update/transactional-install.d.mts +3 -1
- package/src/update/transactional-install.mjs +545 -12
- package/src/update/windows-installer-marker.d.mts +1 -0
- package/src/update/windows-installer-marker.mjs +44 -0
- package/src/usage/expected-prices.ts +8 -0
- package/src/usage/filter-index.ts +326 -77
- package/src/usage/ledger-scanner.ts +15 -0
- package/src/usage/link-log-fields.ts +48 -0
- package/src/usage/log.ts +43 -2
- package/src/usage/request-body.ts +37 -0
- package/src/web-search/loop.ts +3 -0
- package/src/web-search/parse.ts +21 -2
- package/gui/dist/assets/App-g3Cm2xhZ.js +0 -59
- package/gui/dist/assets/Tray-BMDkAiXy.js +0 -1
- package/gui/dist/assets/index-Bziu8gTy.css +0 -2
- package/gui/dist/assets/index-OYzhQUNP.js +0 -94
- package/gui/dist/classic/assets/App-CgPBKUP-.js +0 -58
- package/gui/dist/classic/assets/index-BR-HhNrp.js +0 -94
- package/gui/dist/classic/assets/quota-summary-CXKhvSmQ.js +0 -1
- package/src/server/management/desktop-compatibility-authorization.ts +0 -12
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { createInterface } from "node:readline/promises";
|
|
2
2
|
import { plantUnavailableGuidance } from "../link/child-binary-source";
|
|
3
3
|
import { assertSshAlias } from "../link/ssh-argv";
|
|
4
|
+
import { checkExplicitRoute, IDENTITY_FILE_GUIDANCE, type ExplicitRoute } from "../link/explicit-route";
|
|
5
|
+
import { OPERATION_JOURNAL_MAX_RECENT_SETTLED, OPERATION_JOURNAL_MAX_UNSETTLED } from "../link/operations-journal";
|
|
6
|
+
import { residualRecovery, type ResidualChild } from "../link/residual-recovery";
|
|
4
7
|
import { CliUsageError, RuntimeApiError, runtimeBaseUrl, rejectArgs, takeFlag, takeJsonFlag, takeOption, printData } from "./runtime-api";
|
|
5
8
|
import type { LinkCliDeps } from "./link";
|
|
6
9
|
|
|
7
10
|
const FINGERPRINT = /^SHA256:[A-Za-z0-9+/]{16,88}={0,2}$/;
|
|
8
11
|
const SEMVER = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]{1,128})?$/;
|
|
9
|
-
const ENROLLMENT_DEADLINE_MS = 360_000;
|
|
12
|
+
export const ENROLLMENT_DEADLINE_MS = 360_000;
|
|
10
13
|
const PHASES: Record<string, string> = {
|
|
11
14
|
remote_port_failed: "remote port selection", remote_port_timeout: "remote port selection",
|
|
12
15
|
remote_plant_failed: "remote ocx-child planting", remote_plant_timeout: "remote ocx-child planting",
|
|
@@ -22,8 +25,58 @@ const PHASES: Record<string, string> = {
|
|
|
22
25
|
child_runtime_not_client: "Child runtime role verification",
|
|
23
26
|
remote_platform_unsupported: "remote platform verification", remote_ocx_missing: "remote OpenCodex discovery",
|
|
24
27
|
};
|
|
25
|
-
const
|
|
26
|
-
|
|
28
|
+
const HOME_CLEANUP: Record<string, string> = {
|
|
29
|
+
key_cleanup_failed: "Enrollment did not complete, and the Home could not revoke the link key it issued; revoke the leftover link key under API keys before retrying.",
|
|
30
|
+
link_cleanup_uncertain: "Enrollment did not complete, and the Home could not undo the attempt: whether the link is stored is unknown and its issued key could not be revoked. Run ocx link status, remove the link if it is listed (ocx link revoke), and revoke the leftover link key under API keys if it remains.",
|
|
31
|
+
};
|
|
32
|
+
const CHILD_MAY_BE_CONNECTED = "The Child may still be connected.";
|
|
33
|
+
/**
|
|
34
|
+
* The Child's step after a refused apply that may have left it connected, from the answer's closed words: a plant, the install
|
|
35
|
+
* the apply knew (residualInstall), a journalled enrollment whose install was not recorded, or, from a server that names neither,
|
|
36
|
+
* the kind this command probed. Bound to the attempt's link id the answer names (src/link/residual-recovery.ts): a step read long
|
|
37
|
+
* after the attempt never removes a link the machine joined since, and without an id the Child is left.
|
|
38
|
+
*/
|
|
39
|
+
function residualChildStep(body: Record<string, unknown>, ephemeralFlow: boolean): string {
|
|
40
|
+
const kind: ResidualChild = body.residualKind === "plant" ? "plant"
|
|
41
|
+
: body.residualInstall === "ephemeral" || body.residualInstall === "full" ? body.residualInstall
|
|
42
|
+
: body.residualKind === "enrollment" ? "enrollment" : ephemeralFlow ? "ephemeral" : "full";
|
|
43
|
+
const platform = body.remotePlatform === "posix" || body.remotePlatform === "windows" ? body.remotePlatform : undefined;
|
|
44
|
+
return residualRecovery(kind, typeof body.linkId === "string" ? body.linkId : undefined, platform);
|
|
45
|
+
}
|
|
46
|
+
const OPERATION_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
47
|
+
// Refusals of ocx link add --operation-id and --require-ephemeral (structure/remote-link.md, "Operation journal").
|
|
48
|
+
const OPERATION_REFUSALS: Record<string, string> = {
|
|
49
|
+
operation_mismatch: "This operation id was already used with other parameters; use a new operation id.",
|
|
50
|
+
link_operation_open: "An unfinished enrollment holds this alias; repeat it with its own operation id to settle it first.",
|
|
51
|
+
// The same 409 answers a concurrent probe, confirmation, route edit, enrollment or revoke of the alias.
|
|
52
|
+
link_operation_in_progress: "Another link operation for this alias is running; retry when it ends.",
|
|
53
|
+
// The census runs inside the apply before any plant, key or Child change; with --operation-id the apply still records its
|
|
54
|
+
// entry, and confirm-host already wrote the known_hosts pin, so these name only what the apply left alone.
|
|
55
|
+
full_install_present: "A full OpenCodex install is on the Child; --require-ephemeral refused it before the apply changed the Child, a key or a link.",
|
|
56
|
+
full_install_census_failed: "The Child could not be checked for a full OpenCodex install; the apply changed no key, link or Child file.",
|
|
57
|
+
require_ephemeral_unsupported: "--require-ephemeral is not supported for a Windows Child.",
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** " (operation <id>: <outcome>)" when the answer carries this operation's recorded outcome. */
|
|
61
|
+
function operationNote(error: unknown, operationId: string | undefined): string {
|
|
62
|
+
if (operationId === undefined || !(error instanceof RuntimeApiError) || !record(error.body)) return "";
|
|
63
|
+
return error.body.operationId === operationId && typeof error.body.outcome === "string" ? " (operation " + operationId + ": " + error.body.outcome + ")" : "";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The CLI's own text for 409 operation_journal_full, picked by the closed bound field (an older Home sends none). Never
|
|
68
|
+
* the server's message; the code and the bound ride along for scripts. The refusal comes before the entry is written; for
|
|
69
|
+
* an add, confirm-host already wrote the known_hosts pin, so only the apply changed nothing.
|
|
70
|
+
*/
|
|
71
|
+
export function journalFullGuidance(body: unknown, kind: "add" | "revoke"): string {
|
|
72
|
+
const bound = record(body) && (body.bound === "unsettled" || body.bound === "recent") ? body.bound : undefined;
|
|
73
|
+
const text = bound === "unsettled"
|
|
74
|
+
? "The link operation journal holds " + OPERATION_JOURNAL_MAX_UNSETTLED + " open or unresolved operations. Check the Child of each residual or unknown one, then run ocx link operations resolve --operation-id <id> --yes; repeat an open one with its operation id first. ocx link operations lists them."
|
|
75
|
+
: bound === "recent"
|
|
76
|
+
? "The link operation journal holds " + OPERATION_JOURNAL_MAX_RECENT_SETTLED + " operations that settled within the last 2 hours and three minutes; retry once the oldest of them is older than that."
|
|
77
|
+
: "The link operation journal is full; ocx link operations lists its entries.";
|
|
78
|
+
return text + (kind === "add" ? " The apply changed nothing." : " Nothing was changed.") + " (code operation_journal_full)" + (bound ? " (bound " + bound + ")" : "");
|
|
79
|
+
}
|
|
27
80
|
type LinkRequest = <T>(path: string, init: RequestInit, deps: LinkCliDeps) => Promise<T>;
|
|
28
81
|
|
|
29
82
|
interface ParsedProbeOffer {
|
|
@@ -108,6 +161,40 @@ function validateConfirmed(value: unknown, alias: string, fingerprint: string, a
|
|
|
108
161
|
}
|
|
109
162
|
}
|
|
110
163
|
|
|
164
|
+
/**
|
|
165
|
+
* --proxy-command, --ssh-user and --ssh-port name one explicit route and go together; they need
|
|
166
|
+
* --exclusive (structure/remote-link.md, "Explicit route"). --ssh-identity-file adds the route's key and needs the
|
|
167
|
+
* other three. The values are checked here and again on the Home, which refuses any form explicit-route.ts does not
|
|
168
|
+
* accept and, for the key, a file that is not a usable private key file.
|
|
169
|
+
*/
|
|
170
|
+
const ROUTE_FORM = {
|
|
171
|
+
proxy_command_form: "--proxy-command must be an absolute path followed by words of letters, digits and . _ / : @ + , = - separated by single spaces (no %, quotes or other shell characters)",
|
|
172
|
+
user_form: "--ssh-user must be a letter or _ followed by up to 31 letters, digits, ., _ or -",
|
|
173
|
+
port_form: "--ssh-port must be an integer from 1 to 65535",
|
|
174
|
+
identity_file_form: "--ssh-identity-file must be an absolute path of letters, digits and . _ + - / (no ~, %, $, spaces, quotes, empty, . or .. segments), at most 1024 characters",
|
|
175
|
+
} as const;
|
|
176
|
+
|
|
177
|
+
function takeRouteFlags(args: string[], usage: string): { explicitRoute?: ExplicitRoute; exclusive?: true } {
|
|
178
|
+
const proxyCommand = takeOption(args, "--proxy-command");
|
|
179
|
+
const user = takeOption(args, "--ssh-user");
|
|
180
|
+
const portText = takeOption(args, "--ssh-port");
|
|
181
|
+
// link.route/2: the route's key; it belongs to an explicit route and travels inside it.
|
|
182
|
+
const identityFile = takeOption(args, "--ssh-identity-file");
|
|
183
|
+
const exclusive = takeFlag(args, "--exclusive");
|
|
184
|
+
const given = [proxyCommand, user, portText].filter(value => value !== undefined).length;
|
|
185
|
+
if (identityFile !== undefined && given === 0) throw new CliUsageError("--ssh-identity-file needs an explicit route (--proxy-command, --ssh-user and --ssh-port)", usage);
|
|
186
|
+
if (given === 0) return exclusive ? { exclusive: true } : {};
|
|
187
|
+
if (given !== 3) throw new CliUsageError("--proxy-command, --ssh-user and --ssh-port go together", usage);
|
|
188
|
+
if (!exclusive) throw new CliUsageError("An explicit route requires --exclusive", usage);
|
|
189
|
+
const port = /^[0-9]{1,5}$/.test(portText!) ? Number(portText) : Number.NaN;
|
|
190
|
+
const checked = checkExplicitRoute({ proxyCommand, user, port, ...(identityFile !== undefined ? { identityFile } : {}) });
|
|
191
|
+
if (!checked.ok) {
|
|
192
|
+
const reason = checked.reason === "user_form" || checked.reason === "port_form" || checked.reason === "identity_file_form" ? checked.reason : "proxy_command_form";
|
|
193
|
+
throw new CliUsageError(ROUTE_FORM[reason], usage);
|
|
194
|
+
}
|
|
195
|
+
return { explicitRoute: checked.route, exclusive: true };
|
|
196
|
+
}
|
|
197
|
+
|
|
111
198
|
function formatSizeMb(bytes?: number): string {
|
|
112
199
|
if (!bytes || !Number.isFinite(bytes) || bytes <= 0) return "~0.9 MB";
|
|
113
200
|
return `~${Math.max(0.1, bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
@@ -117,6 +204,9 @@ export async function runLinkEnrollment(command: "probe" | "add", args: string[]
|
|
|
117
204
|
const wantsJson = takeJsonFlag(args);
|
|
118
205
|
const plantFlag = takeFlag(args, "--plant");
|
|
119
206
|
const expected = takeOption(args, "--expect-fingerprint");
|
|
207
|
+
const routeBody = takeRouteFlags(args, usage);
|
|
208
|
+
const operationId = takeOption(args, "--operation-id");
|
|
209
|
+
const requireEphemeral = takeFlag(args, "--require-ephemeral");
|
|
120
210
|
const alias = args.shift();
|
|
121
211
|
if (!alias) throw new CliUsageError(command + " requires an SSH alias", usage);
|
|
122
212
|
try { assertSshAlias(alias); } catch { throw new CliUsageError("Invalid SSH alias", usage); }
|
|
@@ -124,6 +214,11 @@ export async function runLinkEnrollment(command: "probe" | "add", args: string[]
|
|
|
124
214
|
if (command === "probe" && expected !== undefined) throw new CliUsageError("--expect-fingerprint is only for link add", usage);
|
|
125
215
|
if (command === "probe" && plantFlag) throw new CliUsageError("--plant is only for link add", usage);
|
|
126
216
|
if (expected !== undefined && !FINGERPRINT.test(expected)) throw new CliUsageError("Expected a SHA256 SSH fingerprint", usage);
|
|
217
|
+
if (command === "probe" && (operationId !== undefined || requireEphemeral)) throw new CliUsageError("--operation-id and --require-ephemeral are only for link add", usage);
|
|
218
|
+
if (operationId !== undefined && !OPERATION_ID.test(operationId)) throw new CliUsageError("--operation-id must be 1-128 letters, digits, '.', '_', ':' or '-', not starting with a punctuation mark", usage);
|
|
219
|
+
// A repeat replays without probing, so the fingerprint that names the operation must be given, not offered.
|
|
220
|
+
if (operationId !== undefined && expected === undefined) throw new CliUsageError("--operation-id requires --expect-fingerprint", usage);
|
|
221
|
+
const operationBody = { ...(operationId !== undefined ? { operationId } : {}), ...(requireEphemeral ? { requireEphemeral: true } : {}) };
|
|
127
222
|
const isTTY = Boolean((deps.stdinImpl ?? process.stdin).isTTY);
|
|
128
223
|
if (command === "add" && !expected && !isTTY) {
|
|
129
224
|
throw new CliUsageError("Non-interactive link add requires --expect-fingerprint", usage);
|
|
@@ -148,10 +243,39 @@ export async function runLinkEnrollment(command: "probe" | "add", args: string[]
|
|
|
148
243
|
rl ??= createInterface({ input: deps.stdinImpl ?? process.stdin, output: process.stderr });
|
|
149
244
|
return (await rl.question(promptText, { signal: controller.signal })).trim() === "yes";
|
|
150
245
|
};
|
|
246
|
+
const get = async <T>(path: string): Promise<T> => {
|
|
247
|
+
controller.signal.throwIfAborted();
|
|
248
|
+
const result = await request<T>(path, { method: "GET", redirect: "error", signal: controller.signal }, boundDeps);
|
|
249
|
+
controller.signal.throwIfAborted();
|
|
250
|
+
return result;
|
|
251
|
+
};
|
|
252
|
+
const applied = (result: unknown, planted: boolean): void => {
|
|
253
|
+
const keys = record(result) ? Object.keys(result).sort().join(",") : "";
|
|
254
|
+
const shaped = operationId === undefined ? keys === "linkId"
|
|
255
|
+
: (keys === "linkId,operationId,outcome" || (keys === "linkId,operationId,outcome,planted" && record(result) && result.planted === true))
|
|
256
|
+
&& record(result) && result.operationId === operationId && result.outcome === "committed";
|
|
257
|
+
// A replay never probed, so only the journalled answer can say the Child was planted.
|
|
258
|
+
planted = planted || (record(result) && result.planted === true);
|
|
259
|
+
if (!shaped || !record(result) || typeof result.linkId !== "string" || !/^lnk_[0-9a-f]{16}$/.test(result.linkId)) throw new Error("Invalid link apply response");
|
|
260
|
+
printData({ linkId: result.linkId, alias, state: "connected", childRole: "client", ...(planted ? { planted: true } : {}), ...(routeBody.exclusive ? { exclusive: true } : {}),
|
|
261
|
+
...(operationId !== undefined ? { operationId, outcome: "committed" } : {}) }, wantsJson, ["Connected " + alias + " as a Child (" + result.linkId + ")."]);
|
|
262
|
+
};
|
|
151
263
|
const work = async () => {
|
|
152
264
|
boundDeps = { ...deps, baseUrl: await runtimeBaseUrl(deps) };
|
|
153
265
|
controller.signal.throwIfAborted();
|
|
154
|
-
|
|
266
|
+
if (command === "add" && operationId !== undefined) {
|
|
267
|
+
// A recorded operation replays its outcome: no new probe or confirmation, which a gone host could not answer.
|
|
268
|
+
let recorded = false;
|
|
269
|
+
try { await get<unknown>("/api/link/operations/" + encodeURIComponent(operationId)); recorded = true; } catch (error) {
|
|
270
|
+
const code = error instanceof RuntimeApiError && record(error.body) && record(error.body.error) ? error.body.error.code : undefined;
|
|
271
|
+
if (!(error instanceof RuntimeApiError && error.status === 404 && code === "operation_not_found")) throw error;
|
|
272
|
+
}
|
|
273
|
+
if (recorded) {
|
|
274
|
+
applied(await post<unknown>("/api/link/apply", { alias, fingerprint: expected, ...routeBody, ...operationBody }), false);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const probeReq = command === "add" ? { alias, includeVersion: true, allowMissing: true, ...routeBody } : { alias, includeVersion: true, ...routeBody };
|
|
155
279
|
const probe = parseOffered(await post<unknown>("/api/link/probe", probeReq), command === "add");
|
|
156
280
|
if (probe.alias !== alias) throw new Error("Host probe alias did not match");
|
|
157
281
|
if (command === "probe") {
|
|
@@ -192,29 +316,51 @@ export async function runLinkEnrollment(command: "probe" | "add", args: string[]
|
|
|
192
316
|
if (!approved) throw new CliUsageError("Host fingerprint was not confirmed");
|
|
193
317
|
}
|
|
194
318
|
const sendAllowMissing = shouldPlant || probe.runtimeKind === "missing";
|
|
195
|
-
const confirm = await post<unknown>("/api/link/confirm-host", { alias, fingerprint: probe.fingerprint, ...(sendAllowMissing ? { allowMissing: true } : {}) });
|
|
319
|
+
const confirm = await post<unknown>("/api/link/confirm-host", { alias, fingerprint: probe.fingerprint, ...(sendAllowMissing ? { allowMissing: true } : {}), ...routeBody });
|
|
196
320
|
validateConfirmed(confirm, alias, probe.fingerprint, sendAllowMissing);
|
|
197
|
-
|
|
198
|
-
if (!record(result) || Object.keys(result).join(",") !== "linkId" || typeof result.linkId !== "string" || !/^lnk_[0-9a-f]{16}$/.test(result.linkId)) throw new Error("Invalid link apply response");
|
|
199
|
-
printData({ linkId: result.linkId, alias, state: "connected", childRole: "client", ...(shouldPlant ? { planted: true } : {}) }, wantsJson, ["Connected " + alias + " as a Child (" + result.linkId + ")."]);
|
|
321
|
+
applied(await post<unknown>("/api/link/apply", { alias, fingerprint: probe.fingerprint, ...(shouldPlant ? { plant: true } : {}), ...routeBody, ...operationBody }), shouldPlant);
|
|
200
322
|
};
|
|
201
323
|
try { await Promise.race([work(), expiry]); }
|
|
202
324
|
catch (error) {
|
|
325
|
+
const note = operationNote(error, operationId);
|
|
326
|
+
try {
|
|
203
327
|
if (error instanceof RuntimeApiError && record(error.body)) {
|
|
204
328
|
const code = record(error.body.error) ? error.body.error.code : undefined;
|
|
205
329
|
if (code === "remote_platform_unsupported" && error.body.residual !== true) throw new Error("The remote shell cannot run this Remote Link workflow. Update OpenCodex on Home and check PowerShell on the Child.");
|
|
206
|
-
|
|
330
|
+
// Both conflicts say no Child file changed, which holds only when nothing is left behind (a plant whose rollback failed is).
|
|
331
|
+
if (code === "child_port_busy" && error.body.residual !== true) throw new Error("The target port on the Child is already in use by another process; no Child files were modified.");
|
|
207
332
|
if (code === "child_preflight_output_limit") throw new Error("The Child's ocx config show --json output exceeded the Remote Link preflight limit; trim the Child's saved configuration and retry.");
|
|
208
|
-
if (code === "child_external_provider_conflict") throw new Error("The Child's ~/.codex/config.toml is already managed by another model provider or custom base URL; no Child files were modified.");
|
|
333
|
+
if (code === "child_external_provider_conflict" && error.body.residual !== true) throw new Error("The Child's ~/.codex/config.toml is already managed by another model provider or custom base URL; no Child files were modified.");
|
|
334
|
+
// A refused --ssh-identity-file: what to fix, from the closed hint (the same text the Home answers), never the path.
|
|
335
|
+
const keyHint = record(error.body.error) ? error.body.error.hint : undefined;
|
|
336
|
+
if (code === "invalid_identity_file" && typeof keyHint === "string" && Object.hasOwn(IDENTITY_FILE_GUIDANCE, keyHint)) {
|
|
337
|
+
throw new Error(IDENTITY_FILE_GUIDANCE[keyHint as keyof typeof IDENTITY_FILE_GUIDANCE] + " (code invalid_identity_file, hint " + keyHint + ")");
|
|
338
|
+
}
|
|
339
|
+
// Home-side cleanup that left a link key behind: fixed, locally written guidance (the server's
|
|
340
|
+
// prose is never echoed), plus the Child's own recovery step when it may still be connected.
|
|
341
|
+
const homeCleanup = typeof code === "string" && Object.hasOwn(HOME_CLEANUP, code) ? HOME_CLEANUP[code] : undefined;
|
|
342
|
+
if (homeCleanup) {
|
|
343
|
+
const childStep = error.body.residual === true ? " " + CHILD_MAY_BE_CONNECTED + " " + residualChildStep(error.body, ephemeralFlow) : "";
|
|
344
|
+
throw new Error(homeCleanup + childStep + " (code " + code + ")");
|
|
345
|
+
}
|
|
209
346
|
const phase = typeof code === "string" && Object.hasOwn(PHASES, code) ? PHASES[code] : undefined;
|
|
210
347
|
// The server's hint is the Child's own bounded, redacted reason (#8357); a phase name
|
|
211
348
|
// alone left every failure to SSH reproduction and source reading.
|
|
212
349
|
const hint = record(error.body.error) && typeof error.body.error.hint === "string" ? error.body.error.hint : "";
|
|
213
350
|
const message = phase ? "Remote Link failed during " + phase + (hint ? ": " + hint : "") : error.message;
|
|
214
|
-
|
|
215
|
-
|
|
351
|
+
// The machine-readable code rides along so a script can branch without parsing prose.
|
|
352
|
+
const codeSuffix = (phase || note) && typeof code === "string" ? " (code " + code + ")" : "";
|
|
353
|
+
if (phase || error.body.residual === true) throw new Error(message + (error.body.residual === true ? ". " + CHILD_MAY_BE_CONNECTED + " " + residualChildStep(error.body, ephemeralFlow) : "") + codeSuffix);
|
|
354
|
+
// Keeps the 409 (exit 5) a full journal always gave.
|
|
355
|
+
if (code === "operation_journal_full") throw new RuntimeApiError(journalFullGuidance(error.body, "add"), error.status, error.body);
|
|
356
|
+
if (typeof code === "string" && Object.hasOwn(OPERATION_REFUSALS, code)) throw new Error(OPERATION_REFUSALS[code] + " (code " + code + ")");
|
|
357
|
+
if (note && typeof code === "string") throw new Error(error.message + " (code " + code + ")");
|
|
216
358
|
}
|
|
217
359
|
throw error;
|
|
360
|
+
} catch (explained) {
|
|
361
|
+
if (note && explained instanceof Error) explained.message += note;
|
|
362
|
+
throw explained;
|
|
363
|
+
}
|
|
218
364
|
} finally {
|
|
219
365
|
if (timer) clearTimeout(timer);
|
|
220
366
|
controller.abort();
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ocx link operations: read the Home's link operation journal (structure/remote-link.md, "Operation journal") and
|
|
3
|
+
* resolve a residual or unknown entry once the Child is known clean or the loss is accepted, which starts its 30
|
|
4
|
+
* days of retention. GET /api/link/operations[/{id}] and POST /api/link/operations/{id}/resolve.
|
|
5
|
+
*/
|
|
6
|
+
import { CliUsageError, printData, rejectArgs, takeFlag, takeJsonFlag, takeOption } from "./runtime-api";
|
|
7
|
+
import type { LinkCliDeps } from "./link";
|
|
8
|
+
|
|
9
|
+
type LinkRequest = <T>(path: string, init: RequestInit, deps: LinkCliDeps) => Promise<T>;
|
|
10
|
+
|
|
11
|
+
export const LINK_OPERATIONS_USAGE = [
|
|
12
|
+
" ocx link operations [--operation-id <id>] [--json]",
|
|
13
|
+
" ocx link operations resolve --operation-id <id> --yes [--json]",
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const OPERATION_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
17
|
+
|
|
18
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
19
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function line(op: unknown): string {
|
|
23
|
+
if (!isRecord(op)) throw new Error("invalid link API response: operation");
|
|
24
|
+
const { operationId, kind, alias, state } = op;
|
|
25
|
+
if (typeof operationId !== "string" || typeof kind !== "string" || typeof alias !== "string" || typeof state !== "string") throw new Error("invalid link API response: operation");
|
|
26
|
+
return operationId + " " + kind + " " + alias + " " + state + (typeof op.resolvedAt === "string" ? " resolved " + op.resolvedAt : "");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function runLinkOperations(args: string[], deps: LinkCliDeps, request: LinkRequest, usage: string): Promise<void> {
|
|
30
|
+
const resolve = args[0] === "resolve" ? (args.shift(), true) : false;
|
|
31
|
+
const json = takeJsonFlag(args);
|
|
32
|
+
const operationId = takeOption(args, "--operation-id");
|
|
33
|
+
const confirmed = takeFlag(args, "--yes");
|
|
34
|
+
rejectArgs(args, usage);
|
|
35
|
+
if (operationId !== undefined && !OPERATION_ID.test(operationId)) throw new CliUsageError("--operation-id is not a valid operation id", usage);
|
|
36
|
+
if (resolve) {
|
|
37
|
+
if (operationId === undefined) throw new CliUsageError("operations resolve requires --operation-id", usage);
|
|
38
|
+
if (!confirmed) throw new CliUsageError("resolving accepts that the Child may keep what the operation left; pass --yes to confirm", usage);
|
|
39
|
+
const resolved = await request<unknown>("/api/link/operations/" + encodeURIComponent(operationId) + "/resolve", { method: "POST" }, deps);
|
|
40
|
+
printData(resolved, json, [line(resolved)]);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (confirmed) throw new CliUsageError("--yes is only for operations resolve", usage);
|
|
44
|
+
if (operationId !== undefined) {
|
|
45
|
+
const op = await request<unknown>("/api/link/operations/" + encodeURIComponent(operationId), {}, deps);
|
|
46
|
+
printData(op, json, [line(op)]);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const list = await request<unknown>("/api/link/operations", {}, deps);
|
|
50
|
+
if (!isRecord(list) || !Array.isArray(list.operations)) throw new Error("invalid link API response: operations");
|
|
51
|
+
printData(list, json, list.operations.length === 0 ? ["No link operations are recorded."] : list.operations.map(line));
|
|
52
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ocx link recover: clean an ephemeral Child that a forced revoke (a Home tombstone) or an
|
|
3
|
+
* interrupted enrollment (--operation-id, the link operation journal) left behind, through
|
|
4
|
+
* POST /api/link/recover (structure/remote-link.md, "Recover"). --list shows the tombstones still
|
|
5
|
+
* waiting; --forget drops one whose machine is gone for good. Forget has no management API: it runs
|
|
6
|
+
* here, on the Home, for a person only, under the config mutation lock that a forced revoke's link
|
|
7
|
+
* removal also takes, and is refused while the link still exists.
|
|
8
|
+
*/
|
|
9
|
+
import { withConfigMutationLockSync } from "../config/mutation-lock";
|
|
10
|
+
import { linkStorePath } from "../link/paths";
|
|
11
|
+
import { readLinkStore } from "../link/store";
|
|
12
|
+
import { forgetTombstone, tombstonesPath } from "../link/tombstones";
|
|
13
|
+
import { isAgentDriven } from "./agent-driven";
|
|
14
|
+
import { CliUsageError, printData, rejectArgs, RuntimeApiError, takeFlag, takeJsonFlag, takeOption } from "./runtime-api";
|
|
15
|
+
import type { LinkCliDeps } from "./link";
|
|
16
|
+
|
|
17
|
+
type LinkRequest = <T>(path: string, init: RequestInit, deps: LinkCliDeps) => Promise<T>;
|
|
18
|
+
|
|
19
|
+
export const LINK_RECOVER_USAGE = [
|
|
20
|
+
" ocx link recover (--link-id <id> | --operation-id <id>) [--json]",
|
|
21
|
+
" ocx link recover --list [--json]",
|
|
22
|
+
" ocx link recover --forget --link-id <id> --yes [--json]",
|
|
23
|
+
].join("\n");
|
|
24
|
+
|
|
25
|
+
const LINK_ID = /^lnk_[0-9a-f]{16}$/;
|
|
26
|
+
const OPERATION_ID = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/;
|
|
27
|
+
const ALIAS = /^[^\u0000-\u001f\u007f]{1,255}$/;
|
|
28
|
+
|
|
29
|
+
/** purged false: the Child restored its state, but kept the shared planted binary for another home's relay. */
|
|
30
|
+
interface RecoverReceipt { linkId: string; outcome: "clean"; purged: boolean }
|
|
31
|
+
interface WaitingTombstone { linkId: string; alias: string; revokedAt: string; remotePlatform?: "posix" | "windows" }
|
|
32
|
+
|
|
33
|
+
const invalid = (what: string): never => { throw new Error("invalid link API response: " + what); };
|
|
34
|
+
const isObject = (value: unknown): value is Record<string, unknown> => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* alias_linked's step: the machine may run that other link now (enrolled again under this alias while the tombstone waited),
|
|
38
|
+
* and no status check proves it does not (ocx-child's status reads only state.json, so an attach in progress can show no link
|
|
39
|
+
* or an earlier one; unreadable state shows none). So the other link is left; ending it is the operator's own decision.
|
|
40
|
+
*/
|
|
41
|
+
type RecoverTarget = { readonly linkId: string } | { readonly operationId: string };
|
|
42
|
+
/** The command that repeats this recover, and a person's way out when the machine is clean or gone, for its target. */
|
|
43
|
+
const again = (t: RecoverTarget): string => "linkId" in t ? "ocx link recover --link-id " + t.linkId : "ocx link recover --operation-id " + t.operationId;
|
|
44
|
+
const settleOperation = (operationId: string): string => "ocx link operations resolve --operation-id " + operationId + " --yes";
|
|
45
|
+
const aliasLinked = (t: RecoverTarget): string => "another Home-initiated link still uses this machine's alias, so the Child there may belong to that link. Do not run ocx-child detach on the machine. Leave that link: no status check on the machine can show it is stale, since an attach of it still in progress can show no link or an earlier one, and state that cannot be read shows none. " + ("linkId" in t ? "This tombstone" : "This operation") + " waits until that link is removed; then run " + again(t) + " again. Revoking that link (ocx link revoke --link-id <that link's id>, shown by ocx link status, after settling any open operation on it: ocx link operations) ends it and disconnects the machine if the machine runs it, so do that only if you mean to end that link. "
|
|
46
|
+
+ ("linkId" in t ? "A person on this Home can instead forget this tombstone (ocx link recover --forget --link-id " + t.linkId + " --yes) once the machine is confirmed clean or gone."
|
|
47
|
+
: "Once the machine is confirmed clean or gone, a person on this Home can instead resolve the operation (" + settleOperation(t.operationId) + ").");
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* child_recover_unsupported's step: the planted ocx-child cannot bind its detach to the link, and its status cannot show an
|
|
51
|
+
* interrupted attach of another link that a plain detach would restore and then remove, so the machine is left.
|
|
52
|
+
*/
|
|
53
|
+
const recoverUnsupported = (t: RecoverTarget): string => "the planted ocx-child predates detach --expect-link, so it cannot check which link it belongs to, and nothing was changed. Do not run its plain detach on the machine: its status cannot show an interrupted attach of another link, which a plain detach would restore and then remove. Leave the machine: recover cannot confirm its cleanup with this build. Once the machine is gone, or a person on that machine has checked and cleaned its ocx-child records by hand, a person on this Home can run "
|
|
54
|
+
+ ("linkId" in t ? "ocx link recover --forget --link-id " + t.linkId + " --yes." : settleOperation(t.operationId) + ".");
|
|
55
|
+
|
|
56
|
+
/** The CLI's own words for recover's refusals; any other code is shown as the code itself. */
|
|
57
|
+
const RECOVER_REFUSALS: Record<string, string> = {
|
|
58
|
+
link_present: "this link still exists; revoke it (ocx link revoke, with --purge for a lightweight Child) instead.",
|
|
59
|
+
link_retirement_pending: "this link's removal is unfinished; repeat ocx link revoke for it, then recover.",
|
|
60
|
+
tombstone_not_found: "no forced revoke of this link is waiting for cleanup (ocx link recover --list).",
|
|
61
|
+
host_key_changed: "the machine's pinned host key changed since the link was made; nothing was sent to it.",
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A refusal from POST /api/link/recover, named by its code: the CLI's own text for a known code, else the code with
|
|
66
|
+
* its hint when the hint is a plain word (a fixed hint or a record name). Only these closed or validated values reach
|
|
67
|
+
* the terminal, never the server's message; the status is kept, so the exit code is unchanged.
|
|
68
|
+
*/
|
|
69
|
+
function recoverRefusal(error: RuntimeApiError, target: RecoverTarget): RuntimeApiError {
|
|
70
|
+
const body = isObject(error.body) && isObject(error.body.error) ? error.body.error : null;
|
|
71
|
+
const code = typeof body?.code === "string" && /^[a-z_]{1,64}$/.test(body.code) ? body.code : null;
|
|
72
|
+
if (!code) return error;
|
|
73
|
+
const hint = typeof body?.hint === "string" && /^[a-z0-9_-]{1,64}$/.test(body.hint) ? body.hint : null;
|
|
74
|
+
// A command is printed so that it runs as printed: the link id or operation id this command validated. An --operation-id
|
|
75
|
+
// recover's target comes from the journal (--list shows only tombstones), so its way out resolves the operation.
|
|
76
|
+
const known = code === "alias_linked" ? aliasLinked(target)
|
|
77
|
+
: code === "child_recover_unsupported" ? recoverUnsupported(target)
|
|
78
|
+
: Object.hasOwn(RECOVER_REFUSALS, code) ? RECOVER_REFUSALS[code] : undefined;
|
|
79
|
+
const message = "Link recover refused (" + error.status + "): " + code + (hint ? " (" + hint + ")" : "") + (known ? ": " + known : "");
|
|
80
|
+
return new RuntimeApiError(message, error.status, error.body);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function validateReceipt(value: unknown, linkId: string | null): RecoverReceipt {
|
|
84
|
+
if (!isObject(value) || Object.keys(value).sort().join(",") !== "linkId,outcome,purged") return invalid("recover");
|
|
85
|
+
if (typeof value.linkId !== "string" || !LINK_ID.test(value.linkId) || (linkId !== null && value.linkId !== linkId)) invalid("recover");
|
|
86
|
+
if (value.outcome !== "clean" || typeof value.purged !== "boolean") invalid("recover");
|
|
87
|
+
return { linkId: value.linkId as string, outcome: "clean", purged: value.purged as boolean };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function validateList(value: unknown): WaitingTombstone[] {
|
|
91
|
+
if (!isObject(value) || Object.keys(value).join(",") !== "tombstones" || !Array.isArray(value.tombstones)) return invalid("recover list");
|
|
92
|
+
return value.tombstones.map(item => {
|
|
93
|
+
if (!isObject(item) || typeof item.linkId !== "string" || !LINK_ID.test(item.linkId) || typeof item.alias !== "string" || !ALIAS.test(item.alias)
|
|
94
|
+
|| typeof item.revokedAt !== "string" || Number.isNaN(Date.parse(item.revokedAt))
|
|
95
|
+
|| (item.remotePlatform !== undefined && item.remotePlatform !== "posix" && item.remotePlatform !== "windows")) return invalid("recover list");
|
|
96
|
+
return { linkId: item.linkId, alias: item.alias, revokedAt: item.revokedAt, ...(item.remotePlatform ? { remotePlatform: item.remotePlatform as "posix" | "windows" } : {}) };
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function runLinkRecover(args: string[], deps: LinkCliDeps, linkRequest: LinkRequest, usage: string): Promise<void> {
|
|
101
|
+
const wantsJson = takeJsonFlag(args);
|
|
102
|
+
const list = takeFlag(args, "--list");
|
|
103
|
+
const forget = takeFlag(args, "--forget");
|
|
104
|
+
const yes = takeFlag(args, "--yes");
|
|
105
|
+
const linkId = takeOption(args, "--link-id");
|
|
106
|
+
const operationId = takeOption(args, "--operation-id");
|
|
107
|
+
rejectArgs(args, usage);
|
|
108
|
+
if (list) {
|
|
109
|
+
if (forget || yes || linkId !== undefined || operationId !== undefined) throw new CliUsageError("recover --list takes no other option", usage);
|
|
110
|
+
const tombstones = validateList(await linkRequest<unknown>("/api/link/recover", { method: "GET", redirect: "error" }, deps));
|
|
111
|
+
printData({ tombstones }, wantsJson, tombstones.length === 0
|
|
112
|
+
? ["No forced revoke is waiting for cleanup."]
|
|
113
|
+
: tombstones.map(t => `${t.linkId} ${t.alias} revoked ${t.revokedAt}`));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (forget) {
|
|
117
|
+
if (linkId === undefined || !LINK_ID.test(linkId) || operationId !== undefined) throw new CliUsageError("recover --forget requires a valid --link-id", usage);
|
|
118
|
+
if (!yes) throw new CliUsageError("recover --forget drops the only record that this machine still needs cleanup; confirm with --yes", usage);
|
|
119
|
+
// Forgetting gives up on cleaning a machine: a person decides that, never an agent or a runner.
|
|
120
|
+
if ((deps.agentDriven ?? isAgentDriven)()) throw new CliUsageError("recover --forget must be run by a person at a terminal, not by an agent or a CI runner", usage);
|
|
121
|
+
const readStore = deps.readStore ?? (() => readLinkStore(linkStorePath()));
|
|
122
|
+
let outcome;
|
|
123
|
+
try {
|
|
124
|
+
outcome = withConfigMutationLockSync(() => forgetTombstone(linkId, readStore().links.some(link => link.id === linkId), tombstonesPath()));
|
|
125
|
+
} catch {
|
|
126
|
+
throw new Error("The link tombstone file could not be read or updated, or another change holds the configuration lock; it was left as it is. Try again.");
|
|
127
|
+
}
|
|
128
|
+
if (outcome === "link_present") throw new Error("This link still exists: revoke it first (ocx link revoke), then forget it if its machine is gone.");
|
|
129
|
+
if (outcome === "not_found") throw new Error("No forced revoke of this link is waiting for cleanup.");
|
|
130
|
+
printData({ linkId, outcome: "forgotten" }, wantsJson, [`Forgot ${linkId}: its machine will not be cleaned by ocx link recover.`]);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (yes) throw new CliUsageError("--yes applies only to recover --forget", usage);
|
|
134
|
+
if ((linkId === undefined) === (operationId === undefined)) throw new CliUsageError("recover needs exactly one of --link-id or --operation-id", usage);
|
|
135
|
+
if (linkId !== undefined && !LINK_ID.test(linkId)) throw new CliUsageError("recover requires a valid --link-id", usage);
|
|
136
|
+
if (operationId !== undefined && !OPERATION_ID.test(operationId)) throw new CliUsageError("recover requires a valid --operation-id", usage);
|
|
137
|
+
let response: unknown;
|
|
138
|
+
try {
|
|
139
|
+
response = await linkRequest<unknown>("/api/link/recover", {
|
|
140
|
+
method: "POST",
|
|
141
|
+
redirect: "error",
|
|
142
|
+
headers: { "content-type": "application/json" },
|
|
143
|
+
body: JSON.stringify(linkId !== undefined ? { linkId } : { operationId }),
|
|
144
|
+
}, deps);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
throw error instanceof RuntimeApiError ? recoverRefusal(error, linkId !== undefined ? { linkId } : { operationId: operationId! }) : error;
|
|
147
|
+
}
|
|
148
|
+
const receipt = validateReceipt(response, linkId ?? null);
|
|
149
|
+
printData(receipt, wantsJson, [receipt.purged
|
|
150
|
+
? `Recovered ${receipt.linkId}: the Child restored its pre-link state and removed the planted ocx-child.`
|
|
151
|
+
: `Recovered ${receipt.linkId}: the Child restored its pre-link state; the planted ocx-child stays because another OpenCodex home on that machine runs a relay from it.`]);
|
|
152
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ocx link routes: list, add, remove and reorder a Home-initiated link's SSH routes through the
|
|
3
|
+
* Home's management API (GET and POST /api/link/{id}/routes; structure/remote-link.md, "Routes").
|
|
4
|
+
* The Home proves a new route against the link's pinned key before storing it.
|
|
5
|
+
*/
|
|
6
|
+
import { isSshAlias } from "../link/ssh-argv";
|
|
7
|
+
import { CliUsageError, printData, rejectArgs, RuntimeApiError, takeIntegerOption, takeJsonFlag, takeOption } from "./runtime-api";
|
|
8
|
+
import type { LinkCliDeps } from "./link";
|
|
9
|
+
|
|
10
|
+
type LinkRequest = <T>(path: string, init: RequestInit, deps: LinkCliDeps) => Promise<T>;
|
|
11
|
+
|
|
12
|
+
export const LINK_ROUTES_USAGE = [
|
|
13
|
+
" ocx link routes --link-id <id> [--json]",
|
|
14
|
+
" ocx link routes add --link-id <id> --route <alias> [--position <n>] [--json]",
|
|
15
|
+
" ocx link routes remove --link-id <id> --route <alias> [--json]",
|
|
16
|
+
" ocx link routes order --link-id <id> --routes <alias,alias,...> [--json]",
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const LINK_ID = /^lnk_[0-9a-f]{16}$/;
|
|
20
|
+
// The class words an unproven route can carry (RouteOutcomeClass); anything else is not echoed.
|
|
21
|
+
const ROUTE_CAUSES = new Set(["transient", "readiness", "grant_unobserved", "forward", "auth", "hostkey"]);
|
|
22
|
+
|
|
23
|
+
export interface LinkRoutesDocument { linkId: string; pin: string; routes: string[]; exclusive?: true }
|
|
24
|
+
|
|
25
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
26
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function validateRoutesDocument(value: unknown, linkId: string): LinkRoutesDocument {
|
|
30
|
+
const fail = (): never => { throw new Error("invalid link API response: routes"); };
|
|
31
|
+
if (!isRecord(value)) return fail();
|
|
32
|
+
const keys = Object.keys(value).sort().join(",");
|
|
33
|
+
if (keys !== "linkId,pin,routes" && keys !== "exclusive,linkId,pin,routes") fail();
|
|
34
|
+
const { pin, routes } = value;
|
|
35
|
+
// An exclusive link (structure/remote-link.md, "Explicit route") lists exactly its pin.
|
|
36
|
+
if ("exclusive" in value && (value.exclusive !== true || !Array.isArray(routes) || routes.length !== 1)) fail();
|
|
37
|
+
if (value.linkId !== linkId || typeof pin !== "string" || !isSshAlias(pin) || !Array.isArray(routes) || routes.length < 1
|
|
38
|
+
|| !routes.every(route => typeof route === "string" && isSshAlias(route)) || new Set(routes).size !== routes.length
|
|
39
|
+
|| !routes.includes(pin)) fail();
|
|
40
|
+
return { linkId, pin: pin as string, routes: [...routes as string[]], ...(value.exclusive === true ? { exclusive: true as const } : {}) };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function route(value: string | undefined, flag: string, usage: string): string {
|
|
44
|
+
if (!value || !isSshAlias(value)) throw new CliUsageError(flag + " must be an SSH host alias", usage);
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function runLinkRoutes(args: string[], deps: LinkCliDeps, request: LinkRequest, usage: string): Promise<void> {
|
|
49
|
+
const verb = args[0] === "add" || args[0] === "remove" || args[0] === "order" ? args.shift() : undefined;
|
|
50
|
+
const json = takeJsonFlag(args);
|
|
51
|
+
const linkId = takeOption(args, "--link-id");
|
|
52
|
+
if (!linkId || !LINK_ID.test(linkId)) throw new CliUsageError("routes requires a valid --link-id", usage);
|
|
53
|
+
let body: Record<string, unknown> | undefined;
|
|
54
|
+
if (verb === "add") {
|
|
55
|
+
const position = takeIntegerOption(args, "--position", { min: 0, max: 7 });
|
|
56
|
+
body = { op: "add", route: route(takeOption(args, "--route"), "--route", usage), ...(position === undefined ? {} : { position }) };
|
|
57
|
+
} else if (verb === "remove") {
|
|
58
|
+
body = { op: "remove", route: route(takeOption(args, "--route"), "--route", usage) };
|
|
59
|
+
} else if (verb === "order") {
|
|
60
|
+
const list = takeOption(args, "--routes");
|
|
61
|
+
const routes = list === undefined ? [] : list.split(",");
|
|
62
|
+
if (routes.length < 1) throw new CliUsageError("order requires --routes alias,alias,...", usage);
|
|
63
|
+
body = { op: "order", routes: routes.map(value => route(value, "--routes", usage)) };
|
|
64
|
+
}
|
|
65
|
+
rejectArgs(args, usage);
|
|
66
|
+
const path = "/api/link/" + encodeURIComponent(linkId) + "/routes";
|
|
67
|
+
let response: unknown;
|
|
68
|
+
try {
|
|
69
|
+
response = body === undefined
|
|
70
|
+
? await request<unknown>(path, {}, deps)
|
|
71
|
+
: await request<unknown>(path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }, deps);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
// Name the fixed code and, for an unproven route, its class word; only known words are shown.
|
|
74
|
+
// The status keeps the exit code (4 on 404, 5 on 409, 1 otherwise).
|
|
75
|
+
if (error instanceof RuntimeApiError && isRecord(error.body) && isRecord(error.body.error) && typeof error.body.error.code === "string") {
|
|
76
|
+
const code = error.body.error.code;
|
|
77
|
+
const cause = error.body.error.cause;
|
|
78
|
+
const known = typeof cause === "string" && ROUTE_CAUSES.has(cause) ? " (" + cause + ")" : "";
|
|
79
|
+
const note = code === "routes_stored_reload_failed" ? "; the routes were stored (ocx link routes --link-id " + linkId + " reads them), restart the proxy to apply them" : "";
|
|
80
|
+
throw new RuntimeApiError("Link routes request refused (" + error.status + "): " + code + known + note, error.status, error.body);
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
const document = validateRoutesDocument(response, linkId);
|
|
85
|
+
printData(document, json, document.routes.map((name, index) => index + " " + name + (name === document.pin ? (document.exclusive ? " (pin, exclusive)" : " (pin)") : "")));
|
|
86
|
+
}
|
|
87
|
+
|