@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
package/src/link/remote-plant.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CHILD_TARGET_TRIPLES, type ChildTargetTriple } from "./child-binary-source";
|
|
2
|
-
import { MANAGED_PURGE_CHILD_MISSING_MARKER, windowsInspectRuntimeArgv, windowsManagedPurgeDisconnectArgv, windowsPlantChildArgv, windowsPurgePlantedChildArgv } from "./remote-windows";
|
|
2
|
+
import { MANAGED_PURGE_CHILD_MISSING_MARKER, windowsInspectRuntimeArgv, windowsManagedPurgeDisconnectArgv, windowsPlantChildArgv, windowsPurgePlantedChildArgv, windowsRecoverReceiptArgv } from "./remote-windows";
|
|
3
3
|
import { buildExecArgv, REMOTE_SERVED_RUNTIME, remoteServedRuntimeAttempt } from "./ssh-argv";
|
|
4
|
+
import type { ExplicitRoute } from "./explicit-route";
|
|
4
5
|
import { sshFailureHint, sshRunnerErrorHint, type SshRunner } from "./ssh-runner";
|
|
5
6
|
|
|
6
7
|
export type RemoteRuntimeKind = "full" | "ephemeral" | "missing";
|
|
@@ -115,11 +116,12 @@ export function parseRemoteRuntimeInspection(platform: "posix" | "windows", stdo
|
|
|
115
116
|
export async function inspectRemoteChildRuntime(
|
|
116
117
|
runner: Pick<SshRunner, "run">,
|
|
117
118
|
alias: string,
|
|
119
|
+
route: ExplicitRoute | null,
|
|
118
120
|
knownHostsFile: string,
|
|
119
121
|
platform: "posix" | "windows",
|
|
120
122
|
timeoutMs = 30_000,
|
|
121
123
|
): Promise<ParsedRemoteRuntimeInspection | null> {
|
|
122
|
-
const res = await runner.run(buildExecArgv({ alias, argv: remoteInspectRuntimeArgv(platform), knownHostsFile }), { timeoutMs });
|
|
124
|
+
const res = await runner.run(buildExecArgv({ alias, argv: remoteInspectRuntimeArgv(platform), knownHostsFile, route }), { timeoutMs });
|
|
123
125
|
if (res.code !== 0) return null;
|
|
124
126
|
return parseRemoteRuntimeInspection(platform, res.stdout);
|
|
125
127
|
}
|
|
@@ -204,7 +206,10 @@ export const POSIX_PURGE_PLANTED_SCRIPT = [
|
|
|
204
206
|
"}",
|
|
205
207
|
"if [ -f \"$dest\" ]; then",
|
|
206
208
|
" if [ -x \"$dest\" ]; then",
|
|
207
|
-
" \"$dest\" detach --purge
|
|
209
|
+
" out=$(\"$dest\" detach --purge --json) || exit $?",
|
|
210
|
+
// purged:false from the managed binary means it kept itself on purpose: a relay of another
|
|
211
|
+
// ocx-child home runs from it. Any other answer keeps the old belt-and-braces removal.
|
|
212
|
+
" case \"$out\" in *'\"purged\":false'*) printf 'ocx-child kept the planted binary: another ocx-child relay runs from it.\\n' >&2; exit 0;; esac",
|
|
208
213
|
" rm -f \"$dest\" 2>/dev/null || true",
|
|
209
214
|
" elif recovery_pending; then",
|
|
210
215
|
" exit 1",
|
|
@@ -235,13 +240,48 @@ export const POSIX_MANAGED_PURGE_DISCONNECT_SCRIPT = [
|
|
|
235
240
|
"done",
|
|
236
241
|
"dest=\"$HOME/.cache/opencodex/bin/ocx-child\"",
|
|
237
242
|
`if [ ! -f "$dest" ] || [ ! -x "$dest" ]; then printf '${MANAGED_PURGE_CHILD_MISSING_MARKER}\\n' >&2; exit 1; fi`,
|
|
238
|
-
|
|
243
|
+
// "$@" is empty for a revoke; ocx link recover passes --expect-link <link id>.
|
|
244
|
+
"exec \"$dest\" disconnect --purge --json \"$@\"",
|
|
239
245
|
].join("\n");
|
|
240
246
|
|
|
241
|
-
|
|
247
|
+
const LINK_ID = /^lnk_[0-9a-f]{16}$/;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* ocx link recover's proof after a lost answer: the link-bound receipt that ocx-child detach
|
|
251
|
+
* --expect-link writes to $OPENCODEX_HOME/link-receipts/<link id>.json once it restored the Child
|
|
252
|
+
* (native/ocx-child/src/cli.rs write_detach_receipt). Read-only; a missing, symlinked or unreadable
|
|
253
|
+
* receipt exits non-zero and proves nothing.
|
|
254
|
+
*/
|
|
255
|
+
export const POSIX_RECOVER_RECEIPT_SCRIPT = [
|
|
256
|
+
"case \"$(uname -s 2>/dev/null)\" in Windows*|MSYS*|MINGW*|CYGWIN*) exit 125;; esac",
|
|
257
|
+
// The receipt proves the restore; the purge is proven only by a binary confirmed absent. A test
|
|
258
|
+
// for a path reads false both when it is absent and when an ancestor cannot be searched, so each
|
|
259
|
+
// step is trusted only after its parent was shown to be a searchable directory. An existing but
|
|
260
|
+
// non-executable file, or any directory on the way that cannot be searched, proves nothing.
|
|
261
|
+
"prev=\"$HOME\"",
|
|
262
|
+
"for p in \"$HOME/.cache\" \"$HOME/.cache/opencodex\" \"$HOME/.cache/opencodex/bin\" \"$HOME/.cache/opencodex/bin/ocx-child\"; do",
|
|
263
|
+
" if [ ! -d \"$prev\" ] || [ ! -x \"$prev\" ]; then exit 4; fi",
|
|
264
|
+
" if [ ! -e \"$p\" ] && [ ! -L \"$p\" ]; then break; fi",
|
|
265
|
+
" if [ \"$p\" = \"$HOME/.cache/opencodex/bin/ocx-child\" ]; then exit 4; fi",
|
|
266
|
+
" prev=\"$p\"",
|
|
267
|
+
"done",
|
|
268
|
+
"f=\"${OPENCODEX_HOME:-$HOME/.opencodex}/link-receipts/$1.json\"",
|
|
269
|
+
"if [ -L \"$f\" ] || [ ! -f \"$f\" ] || [ ! -r \"$f\" ]; then exit 4; fi",
|
|
270
|
+
"cat -- \"$f\"",
|
|
271
|
+
].join("\n");
|
|
272
|
+
|
|
273
|
+
export function remoteRecoverReceiptArgv(platform: "posix" | "windows", linkId: string): string[] {
|
|
274
|
+
if (!LINK_ID.test(linkId)) throw new Error("invalid link id");
|
|
275
|
+
return platform === "windows" ? windowsRecoverReceiptArgv(linkId) : ["sh", "-c", POSIX_RECOVER_RECEIPT_SCRIPT, "ocx-recover-receipt", linkId];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** With expectLink, the Child restores only when its state and owner record both name that link. */
|
|
279
|
+
export function remoteManagedPurgeDisconnectArgv(platform: "posix" | "windows" = "posix", expectLink?: string): string[] {
|
|
280
|
+
if (expectLink !== undefined && !LINK_ID.test(expectLink)) throw new Error("invalid link id");
|
|
281
|
+
const extra = expectLink === undefined ? [] : ["--expect-link", expectLink];
|
|
242
282
|
return platform === "windows"
|
|
243
|
-
? windowsManagedPurgeDisconnectArgv()
|
|
244
|
-
: ["sh", "-c", POSIX_MANAGED_PURGE_DISCONNECT_SCRIPT, "ocx-managed-purge"];
|
|
283
|
+
? windowsManagedPurgeDisconnectArgv(expectLink)
|
|
284
|
+
: ["sh", "-c", POSIX_MANAGED_PURGE_DISCONNECT_SCRIPT, "ocx-managed-purge", ...extra];
|
|
245
285
|
}
|
|
246
286
|
|
|
247
287
|
/** The `purged` flag from `ocx-child disconnect --json`, or null when no such report was printed. */
|
|
@@ -257,9 +297,13 @@ export function parsePurgeDisconnectReport(stdout: string): boolean | null {
|
|
|
257
297
|
return null;
|
|
258
298
|
}
|
|
259
299
|
|
|
300
|
+
/** Printed by ocx-child on stderr when --purge kept the binary because another relay runs from it. */
|
|
301
|
+
export const PURGE_KEPT_IN_USE_MARKER = "ocx-purge-kept:binary_in_use";
|
|
302
|
+
|
|
260
303
|
export type PurgeDisconnectOutcome =
|
|
261
304
|
| { readonly ok: true }
|
|
262
|
-
|
|
305
|
+
/** notAttempted: the Child's disconnect never ran (inspection failed, a full install, or no planted binary to run). */
|
|
306
|
+
| { readonly ok: false; readonly status: number; readonly code: string; readonly message: string; readonly hint?: string; readonly notAttempted?: true };
|
|
263
307
|
|
|
264
308
|
/**
|
|
265
309
|
* Disconnect with --purge. A link enrolled before childKind existed is inspected first; only an
|
|
@@ -268,31 +312,87 @@ export type PurgeDisconnectOutcome =
|
|
|
268
312
|
export async function purgeDisconnectRemote(
|
|
269
313
|
runner: Pick<SshRunner, "run">,
|
|
270
314
|
alias: string,
|
|
315
|
+
route: ExplicitRoute | null,
|
|
271
316
|
knownHostsFile: string,
|
|
272
317
|
platform: "posix" | "windows",
|
|
273
318
|
childKind: "ephemeral" | "full" | undefined,
|
|
319
|
+
expectLink?: string,
|
|
320
|
+
/** Asked before the unbound retry for a binary older than --expect-link; false refuses it (nothing changed). */
|
|
321
|
+
unboundStillSafe: () => boolean = () => true,
|
|
274
322
|
): Promise<PurgeDisconnectOutcome> {
|
|
275
323
|
const failed = (message: string, hint?: string): PurgeDisconnectOutcome => ({ ok: false, status: 502, code: "remote_disconnect_failed", message, ...(hint ? { hint } : {}) });
|
|
324
|
+
const notAttempted = (message: string, hint?: string): PurgeDisconnectOutcome => ({ ok: false, status: 502, code: "remote_disconnect_failed", message, ...(hint ? { hint } : {}), notAttempted: true });
|
|
276
325
|
let kind = childKind;
|
|
277
326
|
if (kind === undefined) {
|
|
278
327
|
let inspected: ParsedRemoteRuntimeInspection | null;
|
|
279
|
-
try { inspected = await inspectRemoteChildRuntime(runner, alias, knownHostsFile, platform); } catch (error) { return
|
|
280
|
-
if (!inspected || inspected.runtimeKind === "missing") return
|
|
328
|
+
try { inspected = await inspectRemoteChildRuntime(runner, alias, route, knownHostsFile, platform); } catch (error) { return notAttempted("The Child runtime could not be inspected, so --purge was not attempted.", sshRunnerErrorHint(error) ?? "child_kind_unknown"); }
|
|
329
|
+
if (!inspected || inspected.runtimeKind === "missing") return notAttempted("The Child runtime could not be identified, so --purge was not attempted.", "child_kind_unknown");
|
|
281
330
|
kind = inspected.runtimeKind;
|
|
282
331
|
}
|
|
283
332
|
if (kind !== "ephemeral") {
|
|
284
|
-
return { ok: false, status: 409, code: "purge_unsupported", message: "This Child runs a full OpenCodex install; --purge removes only a planted ocx-child. Disconnect without --purge." };
|
|
333
|
+
return { ok: false, status: 409, code: "purge_unsupported", message: "This Child runs a full OpenCodex install; --purge removes only a planted ocx-child. Disconnect without --purge.", notAttempted: true };
|
|
285
334
|
}
|
|
335
|
+
const purgeArgv = (link?: string) => buildExecArgv({ alias, argv: remoteManagedPurgeDisconnectArgv(platform, link), knownHostsFile, route });
|
|
286
336
|
let result;
|
|
287
|
-
|
|
337
|
+
let bound = expectLink !== undefined;
|
|
338
|
+
try { result = await runner.run(purgeArgv(expectLink), { timeoutMs: 30_000 }); } catch (error) { return failed("The remote client could not be disconnected.", sshRunnerErrorHint(error)); }
|
|
339
|
+
// A planted binary older than --expect-link rejects it as a usage error (exit 2) before doing anything: run unbound.
|
|
340
|
+
if (bound && result.code === CHILD_USAGE_EXIT) {
|
|
341
|
+
// The route answers this hint with its own fixed message (BOUND_REFUSAL_MESSAGES in link-routes.ts), which covers a planted
|
|
342
|
+
// ocx-child too, so this text names only what happened.
|
|
343
|
+
if (!unboundStillSafe()) return notAttempted("The planted ocx-child predates --expect-link and another Home-initiated link of this Home may reach the same machine, so it was not purged.", "expect_link_unsupported");
|
|
344
|
+
bound = false;
|
|
345
|
+
try { result = await runner.run(purgeArgv(), { timeoutMs: 30_000 }); } catch (error) { return failed("The remote client could not be disconnected.", sshRunnerErrorHint(error)); }
|
|
346
|
+
}
|
|
347
|
+
// detach --expect-link refused without changing anything: another link owns this Child (5), or it keeps state it
|
|
348
|
+
// cannot restore (6). Only a refusal recognised as such; anything else below counts as a cleanup attempted.
|
|
349
|
+
const refusal = bound ? classifyBoundRefusal(result.code, result.stderr, expectLink!) : null;
|
|
350
|
+
if (refusal === "mismatch" || refusal === "residual") {
|
|
351
|
+
return notAttempted("The Child is not attached to this link, so it was not disconnected.", refusal === "mismatch" ? "child_link_mismatch" : "child_residual");
|
|
352
|
+
}
|
|
288
353
|
if (result.code !== 0) {
|
|
289
|
-
|
|
354
|
+
// The script prints the marker and exits before it runs the binary.
|
|
355
|
+
if (result.stderr.includes(MANAGED_PURGE_CHILD_MISSING_MARKER)) return notAttempted("No planted ocx-child was found in the managed directory, so nothing was purged.", "managed_child_missing");
|
|
290
356
|
return failed("The remote client could not be disconnected.", sshFailureHint(result.stderr));
|
|
291
357
|
}
|
|
292
|
-
if (parsePurgeDisconnectReport(result.stdout) !== true)
|
|
358
|
+
if (parsePurgeDisconnectReport(result.stdout) !== true) {
|
|
359
|
+
if (result.stderr.includes(PURGE_KEPT_IN_USE_MARKER)) return failed("The Child disconnected, but kept the planted ocx-child because another ocx-child relay runs from it; the link was kept.", "binary_in_use");
|
|
360
|
+
return failed("The Child disconnected but did not report removing the planted ocx-child binary.", "purge_incomplete");
|
|
361
|
+
}
|
|
293
362
|
return { ok: true };
|
|
294
363
|
}
|
|
295
364
|
|
|
365
|
+
/** Exit codes of a Child refusing a link-bound command (ocx-child detach, ocx disconnect --expect-link). */
|
|
366
|
+
export const CHILD_USAGE_EXIT = 2;
|
|
367
|
+
export const CHILD_EXPECT_CONFLICT_EXIT = 5;
|
|
368
|
+
export const CHILD_EXPECT_RESIDUAL_EXIT = 6;
|
|
369
|
+
|
|
370
|
+
/** Reasons full ocx gives for a link-bound refusal that changed nothing (ClientSyncMismatchReason without disconnect_pending). */
|
|
371
|
+
const NO_WRITE_MISMATCH_REASONS = new Set(["disconnected", "invalid_state", "pending_operation", "hub_client", "link_client", "other_link", "other_key", "client_initiated_link"]);
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* What a link-bound refusal (exit 5 or 6) proves, read from the last stderr line only and from a closed set:
|
|
375
|
+
* "mismatch" or "residual" changed nothing on the Child (full ocx's {"phase":"child_link_mismatch","reason"} with a
|
|
376
|
+
* no-write reason, or ocx-child's "detach --expect-link <this link> refused (conflict|residual)"); "pending" is an
|
|
377
|
+
* unfinished disconnect the Child could not bind to this link, so an earlier attempt may have cleaned part of it. Any
|
|
378
|
+
* other answer (an unknown reason, garbled or extra output) is null: the caller treats it as a cleanup attempted.
|
|
379
|
+
*/
|
|
380
|
+
export function classifyBoundRefusal(code: number, stderr: string, linkId: string): "mismatch" | "residual" | "pending" | null {
|
|
381
|
+
if (code !== CHILD_EXPECT_CONFLICT_EXIT && code !== CHILD_EXPECT_RESIDUAL_EXIT) return null;
|
|
382
|
+
const line = stderr.trim().split(/\r?\n/).at(-1) ?? "";
|
|
383
|
+
const childLine = (outcome: "conflict" | "residual") => line.startsWith("detach --expect-link " + linkId + " refused (" + outcome + "): ");
|
|
384
|
+
if (code === CHILD_EXPECT_RESIDUAL_EXIT) return childLine("residual") ? "residual" : null;
|
|
385
|
+
if (childLine("conflict")) return "mismatch";
|
|
386
|
+
if (!line.startsWith("{")) return null;
|
|
387
|
+
let parsed: unknown;
|
|
388
|
+
try { parsed = JSON.parse(line); } catch { return null; }
|
|
389
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
390
|
+
const { phase, reason } = parsed as { phase?: unknown; reason?: unknown };
|
|
391
|
+
if (phase !== "child_link_mismatch" || typeof reason !== "string") return null;
|
|
392
|
+
if (reason === "disconnect_pending") return "pending";
|
|
393
|
+
return NO_WRITE_MISMATCH_REASONS.has(reason) ? "mismatch" : null;
|
|
394
|
+
}
|
|
395
|
+
|
|
296
396
|
/** The distinct reason a plant failed on the Child, when the plant script reported one. */
|
|
297
397
|
export function classifyPlantFailure(stderr: string): "hash_tool_unavailable" | null {
|
|
298
398
|
return stderr.includes(PLANT_HASH_TOOL_UNAVAILABLE_MARKER) ? "hash_tool_unavailable" : null;
|
|
@@ -304,3 +404,41 @@ export function classifyChildAttachConflict(stderr: string): ChildAttachConflict
|
|
|
304
404
|
return null;
|
|
305
405
|
}
|
|
306
406
|
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* --require-ephemeral (structure/remote-link.md, "Operation journal"): every full ocx the gated argv could select,
|
|
410
|
+
* the served-runtime census, the Desktop and system paths and every PATH directory, each counted when it answers
|
|
411
|
+
* --version. Unlike runtime inspection it never stops at an ocx-child, so a Child holding both reports the full one.
|
|
412
|
+
* Prints ocx-census:full per runnable full ocx, then ocx-census:done.
|
|
413
|
+
*/
|
|
414
|
+
export const POSIX_FULL_INSTALL_CENSUS_SCRIPT = [
|
|
415
|
+
"export PATH=\"$PATH:$HOME/.bun/bin:$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin\"",
|
|
416
|
+
"case \"$(uname -s 2>/dev/null)\" in Windows*|MSYS*|MINGW*|CYGWIN*) exit 125;; esac",
|
|
417
|
+
"ocx_entry=",
|
|
418
|
+
"census_full() {",
|
|
419
|
+
" if [ -x \"$1\" ] && \"$1\" ${ocx_entry:+\"$ocx_entry\"} --version >/dev/null 2>&1; then printf '%s\\n' 'ocx-census:full'; fi",
|
|
420
|
+
"}",
|
|
421
|
+
REMOTE_SERVED_RUNTIME.trimEnd(),
|
|
422
|
+
remoteServedRuntimeAttempt("census_full \"$served_bin\""),
|
|
423
|
+
"for candidate in \"$HOME/.opencodex-desktop/bin/ocx\" \"/Applications/OpenCodex.app/Contents/MacOS/ocx\" \"/usr/bin/ocx\"; do",
|
|
424
|
+
" census_full \"$candidate\"",
|
|
425
|
+
"done",
|
|
426
|
+
"remaining=$PATH",
|
|
427
|
+
"while :; do",
|
|
428
|
+
" directory=${remaining%%:*}",
|
|
429
|
+
" census_full \"${directory:-.}/ocx\"",
|
|
430
|
+
" case \"$remaining\" in *:*) remaining=${remaining#*:};; *) break;; esac",
|
|
431
|
+
"done",
|
|
432
|
+
"printf '%s\\n' 'ocx-census:done'",
|
|
433
|
+
].join("\n");
|
|
434
|
+
|
|
435
|
+
export function remoteFullInstallCensusArgv(): string[] {
|
|
436
|
+
return ["sh", "-c", POSIX_FULL_INSTALL_CENSUS_SCRIPT, "ocx-census"];
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** present or none only after the closing marker; anything else is unknown (null) and refuses. */
|
|
440
|
+
export function parseFullInstallCensus(stdout: string): "present" | "none" | null {
|
|
441
|
+
const lines = stdout.split(/\r?\n/).map(line => line.trim());
|
|
442
|
+
if (!lines.includes("ocx-census:done")) return null;
|
|
443
|
+
return lines.includes("ocx-census:full") ? "present" : "none";
|
|
444
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Remote platform is discovered only through the link's pinned SSH host key. */
|
|
2
2
|
import { buildExecArgv, buildWindowsProbeArgv, REMOTE_COMMAND_NOT_FOUND, REMOTE_PLATFORM_UNSUPPORTED } from "./ssh-argv";
|
|
3
|
+
import type { ExplicitRoute } from "./explicit-route";
|
|
3
4
|
import type { SshRunner, SshRunResult } from "./ssh-runner";
|
|
4
5
|
|
|
5
6
|
export type RemotePlatform = "windows" | "posix" | "unknown";
|
|
@@ -41,37 +42,47 @@ export function mayBeWindowsShell(result: SshRunResult): boolean {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
/** Ask the host the fixed, locale-independent WINDOWS_OS_PROBE. Any failure answers false. */
|
|
44
|
-
export async function confirmWindowsShell(runner: SshRunner, alias: string, knownHostsFile: string, timeoutMs = 30_000): Promise<boolean> {
|
|
45
|
+
export async function confirmWindowsShell(runner: SshRunner, alias: string, route: ExplicitRoute | null, knownHostsFile: string, timeoutMs = 30_000): Promise<boolean> {
|
|
45
46
|
try {
|
|
46
|
-
const result = await runner.run(buildWindowsProbeArgv({ alias, knownHostsFile }), { timeoutMs });
|
|
47
|
+
const result = await runner.run(buildWindowsProbeArgv({ alias, knownHostsFile, route }), { timeoutMs });
|
|
47
48
|
return result.code === 0 && result.stdout.trim().split(/\r?\n/)[0]?.trim() === "Windows_NT";
|
|
48
49
|
} catch { return false; }
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/** classifyRemotePlatform, plus the locale-independent follow-up when the answer could be Windows. */
|
|
52
|
-
export async function detectRemotePlatform(runner: SshRunner, alias: string, knownHostsFile: string, result: SshRunResult): Promise<RemotePlatform> {
|
|
53
|
+
export async function detectRemotePlatform(runner: SshRunner, alias: string, route: ExplicitRoute | null, knownHostsFile: string, result: SshRunResult): Promise<RemotePlatform> {
|
|
53
54
|
const platform = classifyRemotePlatform(result);
|
|
54
55
|
if (platform !== "unknown" || !mayBeWindowsShell(result)) return platform;
|
|
55
|
-
return await confirmWindowsShell(runner, alias, knownHostsFile) ? "windows" : "unknown";
|
|
56
|
+
return await confirmWindowsShell(runner, alias, route, knownHostsFile) ? "windows" : "unknown";
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
/** Windows when the fixed %OS% probe answers Windows_NT, otherwise POSIX from uname; never a guess. */
|
|
59
|
-
export async function requireRemotePlatform(
|
|
60
|
-
|
|
60
|
+
export async function requireRemotePlatform(
|
|
61
|
+
runner: Pick<SshRunner, "run">,
|
|
62
|
+
alias: string,
|
|
63
|
+
/** The link's explicit route (src/link/explicit-route.ts), or null. */
|
|
64
|
+
route: ExplicitRoute | null,
|
|
65
|
+
knownHostsFile: string,
|
|
66
|
+
/** A route to the same machine (HostKeyAlias stays alias), a tighter deadline, and an abort. */
|
|
67
|
+
over: { destination?: string; timeoutMs?: number; signal?: AbortSignal } = {},
|
|
68
|
+
): Promise<"posix" | "windows"> {
|
|
69
|
+
const timeoutMs = over.timeoutMs ?? 10_000;
|
|
70
|
+
const runOptions = over.signal ? { timeoutMs, signal: over.signal } : { timeoutMs };
|
|
71
|
+
const windows = await runner.run(buildWindowsProbeArgv({ alias, knownHostsFile, destination: over.destination, route }), runOptions);
|
|
61
72
|
if (windows.code === 255) throw new Error("SSH platform discovery failed");
|
|
62
73
|
if (windows.code === 0 && windows.stdout.trim() === "Windows_NT") return "windows";
|
|
63
|
-
const result = await runner.run(buildExecArgv({ alias, knownHostsFile, argv: REMOTE_UNAME_ARGV }),
|
|
74
|
+
const result = await runner.run(buildExecArgv({ alias, knownHostsFile, destination: over.destination, argv: REMOTE_UNAME_ARGV, route }), runOptions);
|
|
64
75
|
const platform = classifyRemotePlatform(result);
|
|
65
76
|
if (platform === "unknown") throw new Error("Remote platform could not be determined");
|
|
66
77
|
return platform;
|
|
67
78
|
}
|
|
68
79
|
|
|
69
80
|
/** Fan-out ignores login-shell output and trusts only one framed uname line. */
|
|
70
|
-
export async function requireRemotePlatformFramed(runner: Pick<SshRunner, "run">, alias: string, knownHostsFile: string): Promise<"posix" | "windows"> {
|
|
71
|
-
const windows = await runner.run(buildWindowsProbeArgv({ alias, knownHostsFile }), { timeoutMs: 10_000 });
|
|
81
|
+
export async function requireRemotePlatformFramed(runner: Pick<SshRunner, "run">, alias: string, route: ExplicitRoute | null, knownHostsFile: string): Promise<"posix" | "windows"> {
|
|
82
|
+
const windows = await runner.run(buildWindowsProbeArgv({ alias, knownHostsFile, route }), { timeoutMs: 10_000 });
|
|
72
83
|
if (windows.code === SSH_TRANSPORT_FAILURE) throw new Error("SSH platform discovery failed");
|
|
73
84
|
if (windows.code === 0 && windows.stdout.split(/\r?\n/).some(line => line.trim() === "Windows_NT")) return "windows";
|
|
74
|
-
const result = await runner.run(buildExecArgv({ alias, knownHostsFile, argv: REMOTE_FRAMED_UNAME_ARGV }), { timeoutMs: 10_000 });
|
|
85
|
+
const result = await runner.run(buildExecArgv({ alias, knownHostsFile, argv: REMOTE_FRAMED_UNAME_ARGV, route }), { timeoutMs: 10_000 });
|
|
75
86
|
if (result.code === SSH_TRANSPORT_FAILURE) throw new Error("SSH platform discovery failed");
|
|
76
87
|
const frames = result.stdout.split(/\r?\n/).filter(line => line.startsWith("ocx-platform:"));
|
|
77
88
|
const name = frames.length === 1 ? frames[0]!.slice("ocx-platform:".length) : "";
|
package/src/link/remote-probe.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { windowsChildHttpArgv } from "./remote-windows";
|
|
2
|
+
import { isRouteProofId, LINK_ROUTE_PROOF_HEADER } from "./route-proof";
|
|
2
3
|
import { MEMORY_DRAIN_RESTART_MS, REPLACEMENT_READY_TIMEOUT_MS } from "../lib/system-restart-contract";
|
|
3
4
|
|
|
4
5
|
export const LINK_COMMAND_WORK_MS = 15_000;
|
|
@@ -16,11 +17,18 @@ export function linkRestartBudget(latencyMs = 0): number {
|
|
|
16
17
|
return MEMORY_DRAIN_RESTART_MS + REPLACEMENT_READY_TIMEOUT_MS + linkCommandBudget(latencyMs);
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Credential-free Child HTTP probe. Ignore curlrc/proxies; never follow a redirect. A route
|
|
22
|
+
* readiness proof (src/link/route-proof.ts) sends its id in one fixed header, catalog only.
|
|
23
|
+
*/
|
|
24
|
+
export function remoteChildHttpArgv(port: number, path: "healthz" | "v1/catalog", timeoutMs = LINK_RELAY_VERIFY_MS, platform: "posix" | "windows" = "posix", routeProofId?: string): string[] {
|
|
25
|
+
if (routeProofId !== undefined && (path !== "v1/catalog" || !isRouteProofId(routeProofId))) throw new Error("invalid route proof");
|
|
26
|
+
if (platform === "windows") return windowsChildHttpArgv(port, path, timeoutMs, routeProofId);
|
|
22
27
|
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("invalid Child port");
|
|
23
28
|
const seconds = Math.max(1, Math.ceil(Math.min(LINK_RELAY_VERIFY_MS, timeoutMs) / 1000));
|
|
29
|
+
if (routeProofId !== undefined) {
|
|
30
|
+
return ["sh", "-c", 'curl -q --noproxy "*" --silent --show-error --fail --connect-timeout 3 --max-time "$3" -H "' + LINK_ROUTE_PROOF_HEADER + ': $4" --write-out "\\n%{http_code}" "http://127.0.0.1:$1/$2"', "ocx-child-http", String(port), path, String(seconds), routeProofId];
|
|
31
|
+
}
|
|
24
32
|
return ["sh", "-c", 'curl -q --noproxy "*" --silent --show-error --fail --connect-timeout 3 --max-time "$3" --write-out "\\n%{http_code}" "http://127.0.0.1:$1/$2"', "ocx-child-http", String(port), path, String(seconds)];
|
|
25
33
|
}
|
|
26
34
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { RouteClientId } from "./route-intent";
|
|
2
|
+
export const ROUTE_OVERWRITE_MIN_CHILD_VERSION = "2.100.0";
|
|
1
3
|
import { Buffer } from "node:buffer";
|
|
2
4
|
import { deflateRawSync, inflateRawSync } from "node:zlib";
|
|
3
5
|
|
|
@@ -7,10 +9,18 @@ import { deflateRawSync, inflateRawSync } from "node:zlib";
|
|
|
7
9
|
*/
|
|
8
10
|
export const POWERSHELL_ENCODED_MAX = 8_000;
|
|
9
11
|
|
|
12
|
+
/** The encoded command would not fit cmd.exe's command line; callers that build gated commands rename it. */
|
|
13
|
+
export class PowerShellCommandTooLongError extends Error {
|
|
14
|
+
constructor(readonly encodedLength: number) {
|
|
15
|
+
super(`Remote PowerShell command exceeds the cmd.exe-compatible command-line budget (${encodedLength})`);
|
|
16
|
+
this.name = "PowerShellCommandTooLongError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
10
20
|
export function powershellArgv(script: string): string[] {
|
|
11
21
|
// Module preparation otherwise writes a CLIXML progress record to stderr, which Home would see.
|
|
12
22
|
const encoded = Buffer.from("$ProgressPreference='SilentlyContinue'\n" + script, "utf16le").toString("base64");
|
|
13
|
-
if (encoded.length > POWERSHELL_ENCODED_MAX) throw new
|
|
23
|
+
if (encoded.length > POWERSHELL_ENCODED_MAX) throw new PowerShellCommandTooLongError(encoded.length);
|
|
14
24
|
return ["powershell.exe", "-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand", encoded];
|
|
15
25
|
}
|
|
16
26
|
|
|
@@ -193,47 +203,113 @@ export function windowsPurgePlantedChildArgv(): string[] {
|
|
|
193
203
|
return packedPowerShellArgv(NATIVE_PROCESS + WINDOWS_MANAGED_BIN + String.raw`
|
|
194
204
|
$r=if($env:HOME){$env:HOME}elseif($env:USERPROFILE){$env:USERPROFILE}else{"."};$h=if($env:OPENCODEX_HOME){$env:OPENCODEX_HOME}else{"$r\.opencodex"};$cd="$h\child";$cx=if($env:CODEX_HOME){$env:CODEX_HOME}else{"$r\.codex"}
|
|
195
205
|
$rec=@(@("$cd\state.json","$cd\codex-journal.json","$cd\attach-rollback.json","$cx\.ocx-child-owner.json")|?{[IO.File]::Exists($_)-or[IO.Directory]::Exists($_)});$pend=$rec.Count -gt 0;if($pend){$m='ocx-child recovery record remains at '+$rec[0]+'; keeping the planted binary for detach.'}
|
|
196
|
-
try{$dir=Resolve-PlantDir;$dst="$dir\ocx-child.exe";if([IO.File]::Exists($dst)){if([OcxJob]::Ok($dst)){$rc=[OcxJob]::Run($dst,('"'+$dst+'" detach --purge'));if($rc -ne 0){exit $rc};
|
|
206
|
+
try{$dir=Resolve-PlantDir;$dst="$dir\ocx-child.exe";if([IO.File]::Exists($dst)){if([OcxJob]::Ok($dst)){$rc=[OcxJob]::Run($dst,('"'+$dst+'" detach --purge'));if($rc -ne 0){exit $rc};if([IO.File]::Exists($dst)){[Console]::Error.WriteLine('ocx-child kept the planted binary: another ocx-child relay runs from it.')}}elseif($pend){[Console]::Error.WriteLine($m);exit 1}else{try{[IO.File]::Delete($dst)}catch{$null=$_}}}elseif($pend){[Console]::Error.WriteLine($m);exit 1};Get-ChildItem -LiteralPath $dir -Filter '.ocx-child.purge.*.old' -Force -EA 0|%{try{[IO.File]::Delete($_.FullName)}catch{$null=$_}}}catch{exit 1};exit 0
|
|
197
207
|
`);
|
|
198
208
|
}
|
|
199
209
|
|
|
200
210
|
/** Printed on stderr when the managed plant directory holds no runnable ocx-child to purge. */
|
|
201
211
|
export const MANAGED_PURGE_CHILD_MISSING_MARKER = "ocx-purge-error:managed_child_missing";
|
|
202
212
|
|
|
213
|
+
/** Read-only: print the link-bound detach receipt; exit 4 when it is missing, a reparse point or unreadable. */
|
|
214
|
+
export function windowsRecoverReceiptArgv(linkId: string): string[] {
|
|
215
|
+
if (!/^lnk_[0-9a-f]{16}$/.test(linkId)) throw new Error("invalid link id");
|
|
216
|
+
// The id travels as data ($d.args[0]), never spliced into the script source.
|
|
217
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: [linkId] }) + String.raw`
|
|
218
|
+
$r=if($env:HOME){$env:HOME}elseif($env:USERPROFILE){$env:USERPROFILE}else{"."};$h=if($env:OPENCODEX_HOME){$env:OPENCODEX_HOME}else{"$r\.opencodex"};$f="$h\link-receipts\"+[string]$d.args[0]+".json"
|
|
219
|
+
$b=if($env:LOCALAPPDATA){"$env:LOCALAPPDATA\opencodex\bin\ocx-child.exe"}else{"$env:USERPROFILE\.cache\opencodex\bin\ocx-child.exe"}
|
|
220
|
+
$found=$true;try{$null=Get-Item -LiteralPath $b -Force -ErrorAction Stop}catch [System.Management.Automation.ItemNotFoundException]{$found=$false}catch{exit 4};if($found){exit 4}
|
|
221
|
+
try{if(-not[IO.File]::Exists($f)){exit 4};if(((Get-Item -LiteralPath $f -Force).Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0){exit 4};[Console]::Out.Write([IO.File]::ReadAllText($f))}catch{exit 4};exit 0
|
|
222
|
+
`);
|
|
223
|
+
}
|
|
224
|
+
|
|
203
225
|
/** Runs `disconnect --purge --json` through the planted %LOCALAPPDATA% binary, never a PATH candidate. */
|
|
204
|
-
|
|
205
|
-
|
|
226
|
+
/** expectLink (lnk_ and 16 hex digits) travels as data ($d.args[0]), never spliced into the script source. */
|
|
227
|
+
export function windowsManagedPurgeDisconnectArgv(expectLink?: string): string[] {
|
|
228
|
+
if (expectLink !== undefined && !/^lnk_[0-9a-f]{16}$/.test(expectLink)) throw new Error("invalid link id");
|
|
229
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: expectLink === undefined ? [] : [expectLink] }) + WINDOWS_MANAGED_BIN + String.raw`
|
|
206
230
|
try{$dir=Resolve-PlantDir}catch{[Console]::Error.WriteLine('Refusing a reparse point in the managed ocx-child directory.');exit 1}
|
|
207
231
|
$dst="$dir\ocx-child.exe";if(-not([IO.File]::Exists($dst)-and[OcxJob]::Ok($dst))){[Console]::Error.WriteLine('${MANAGED_PURGE_CHILD_MISSING_MARKER}');exit 1}
|
|
208
|
-
|
|
232
|
+
$x=@($d.args);$e=if($x.Count -gt 0){' --expect-link '+(Quote-Native ([string]$x[0]))}else{''}
|
|
233
|
+
try{$rc=[OcxJob]::Run($dst,('"'+$dst+'" disconnect --purge --json'+$e))}catch{exit 1}
|
|
209
234
|
Get-ChildItem -LiteralPath $dir -Filter '.ocx-child.purge.*.old' -Force -EA 0|%{try{[IO.File]::Delete($_.FullName)}catch{$null=$_}};exit $rc
|
|
210
235
|
`);
|
|
211
236
|
}
|
|
212
237
|
|
|
213
|
-
export
|
|
214
|
-
|
|
238
|
+
export interface WindowsGatedCommand {
|
|
239
|
+
versionParts: readonly [string, string, string];
|
|
240
|
+
lacksMarker: "child-ocx-lacks-expect-link" | "child-ocx-lacks-orchestrated-update" | "child-ocx-lacks-overwrite";
|
|
241
|
+
acceptEphemeral: boolean;
|
|
242
|
+
/** Prints ocx-fanout:child-now:<epoch-ms> from [DateTimeOffset]::Now (Unix milliseconds do not depend on the offset). */
|
|
243
|
+
reportClock: boolean;
|
|
244
|
+
args: readonly string[];
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The gated Windows command: select a candidate, refuse below the minimum, optionally refuse ocx-child, then run it
|
|
249
|
+
* contained. OCX_NO_DESKTOP_HANDOFF=1 makes a launcher answer --version and run the command itself. Windows never
|
|
250
|
+
* sends a restart, so the selected-kind report is not built here. Windows reads no served-runtime census, so the
|
|
251
|
+
* selected entry is always a binary: the script prints no entry marker and the Home infers "binary", which keeps the
|
|
252
|
+
* plan probe inside the command-line budget for long preview Home versions.
|
|
253
|
+
*/
|
|
254
|
+
export function windowsGatedOcxArgv(cmd: WindowsGatedCommand): string[] {
|
|
255
|
+
if (!cmd.versionParts.every(part => /^(0|[1-9][0-9]{0,3})$/.test(part))) throw new Error("invalid gate version");
|
|
256
|
+
if (!/^child-ocx-lacks-(expect-link|orchestrated-update|overwrite)$/.test(cmd.lacksMarker)) throw new Error("invalid gate marker");
|
|
257
|
+
const b = cmd.versionParts.map(part => "'" + part + "'").join(",");
|
|
258
|
+
// -match is case-insensitive; the pattern reads the file name the way [IO.Path]::GetFileName does (either separator).
|
|
259
|
+
const overwriteEphemeral = cmd.lacksMarker === "child-ocx-lacks-overwrite" ? String.raw`if(([IO.Path]::GetFileName($x)).ToLowerInvariant().StartsWith('ocx-child')){[Console]::Error.WriteLine('ocx-fanout:child-ephemeral-no-overwrite');exit 121};` : "";
|
|
260
|
+
const ephemeral = cmd.acceptEphemeral || overwriteEphemeral ? "" : String.raw`if($x -match '(^|[\\/])ocx-child[^\\/]*$'){[Console]::Error.WriteLine('ocx-fanout:child-ocx-ephemeral');exit 121};`;
|
|
261
|
+
const clock = cmd.reportClock ? String.raw`[Console]::Error.WriteLine('ocx-fanout:child-now:'+[DateTimeOffset]::Now.ToUnixTimeMilliseconds());` : "";
|
|
262
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: cmd.args }) + OCX_CANDIDATES + String.raw`$env:OCX_NO_DESKTOP_HANDOFF='1'
|
|
215
263
|
foreach($x in ($c|select -Unique)){
|
|
216
|
-
if(![IO.File]::Exists($x)){continue}
|
|
264
|
+
if(![IO.File]::Exists($x)){continue};` + overwriteEphemeral + String.raw`$v=[OcxJob]::V($x);if($null -eq $v){continue};$v=$v.Trim();if($v.StartsWith('opencodex ')){$v=$v.Substring(10)}
|
|
265
|
+
$m=[regex]::Match($v,'^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$')
|
|
266
|
+
$bad=(!$m.Success -or $v.Length -gt 128);if(!$bad -and $m.Groups[4].Success){foreach($p in $m.Groups[4].Value.Split('.')){if(!$p -or ($p -match '^\d+$' -and $p.Length -gt 1 -and $p[0] -eq '0')){$bad=$true}}}
|
|
267
|
+
if($bad){[Console]::Error.WriteLine('ocx-fanout:child-ocx-version-unknown');exit 121}
|
|
268
|
+
$a=@($m.Groups[1].Value,$m.Groups[2].Value,$m.Groups[3].Value);$b=@(` + b + String.raw`);$cmp=0
|
|
269
|
+
for($i=0;$i -lt 3;$i++){if($a[$i].Length -ne $b[$i].Length){$cmp=$a[$i].Length-$b[$i].Length;break};$cmp=[string]::CompareOrdinal($a[$i],$b[$i]);if($cmp -ne 0){break}}
|
|
270
|
+
if($cmp -lt 0 -or ($cmp -eq 0 -and $m.Groups[4].Success)){[Console]::Error.WriteLine('ocx-fanout:` + cmd.lacksMarker + String.raw`');exit 121}
|
|
271
|
+
` + ephemeral + String.raw`[Console]::Error.WriteLine('ocx-fanout:selected:'+$v);` + clock + String.raw`[Console]::Out.WriteLine('ocx-fanout:stdout-begin');Invoke-Native $x @($d.args)
|
|
272
|
+
};exit 127
|
|
273
|
+
`);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** The 2.93.0 sync gate; kept as a named entry because discovery tests import it. */
|
|
277
|
+
export function windowsPinnedSyncArgv(linkId: string): string[] {
|
|
278
|
+
return windowsGatedOcxArgv({ versionParts: ["2", "93", "0"], lacksMarker: "child-ocx-lacks-expect-link", acceptEphemeral: true,
|
|
279
|
+
reportClock: false, args: ["sync", "--expect-link", linkId, "--json"] });
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function windowsOverwriteSyncArgv(linkId: string, overwriteConflict = false, overwriteClient?: RouteClientId): string[] {
|
|
283
|
+
// Overwrite needs a Child that honours it: refuse ocx-child and older ocx before syncing.
|
|
284
|
+
const minimum = overwriteConflict ? ROUTE_OVERWRITE_MIN_CHILD_VERSION.split(".").map(part => `'${part}'`).join(",") : "'2','93','0'";
|
|
285
|
+
const lacks = overwriteConflict ? "ocx-fanout:child-ocx-lacks-overwrite" : "ocx-fanout:child-ocx-lacks-expect-link";
|
|
286
|
+
const ephemeral = overwriteConflict ? String.raw`if(([IO.Path]::GetFileName($x)).ToLowerInvariant().StartsWith('ocx-child')){[Console]::Error.WriteLine('ocx-fanout:child-ephemeral-no-overwrite');exit 121};` : "";
|
|
287
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: ["sync", "--expect-link", linkId, "--json", ...(overwriteConflict ? ["--overwrite-conflict"] : []), ...(overwriteClient ? ["--overwrite-client", overwriteClient] : [])] }) + OCX_CANDIDATES + String.raw`$env:OCX_NO_DESKTOP_HANDOFF=1
|
|
288
|
+
foreach($x in $c){
|
|
289
|
+
if(![IO.File]::Exists($x)){continue};` + ephemeral + String.raw`$v=[OcxJob]::V($x);if($null -eq $v){continue};$v=$v.Trim();if($v.StartsWith('opencodex ')){$v=$v.Substring(10)}
|
|
217
290
|
$m=[regex]::Match($v,'^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$')
|
|
218
291
|
$bad=(!$m.Success -or $v.Length -gt 128);if(!$bad -and $m.Groups[4].Success){foreach($p in $m.Groups[4].Value.Split('.')){if(!$p -or ($p -match '^\d+$' -and $p.Length -gt 1 -and $p[0] -eq '0')){$bad=$true}}}
|
|
219
292
|
if($bad){[Console]::Error.WriteLine('ocx-fanout:child-ocx-version-unknown');exit 121}
|
|
220
|
-
$a=@($m.Groups[1].Value,$m.Groups[2].Value,$m.Groups[3].Value);$b=@(
|
|
293
|
+
$a=@($m.Groups[1].Value,$m.Groups[2].Value,$m.Groups[3].Value);$b=@(` + minimum + String.raw`);$cmp=0
|
|
221
294
|
for($i=0;$i -lt 3;$i++){if($a[$i].Length -ne $b[$i].Length){$cmp=$a[$i].Length-$b[$i].Length;break};$cmp=[string]::CompareOrdinal($a[$i],$b[$i]);if($cmp -ne 0){break}}
|
|
222
|
-
if($cmp -lt 0 -or ($cmp -eq 0 -and $m.Groups[4].Success)){[Console]::Error.WriteLine('
|
|
295
|
+
if($cmp -lt 0 -or ($cmp -eq 0 -and $m.Groups[4].Success)){[Console]::Error.WriteLine('` + lacks + String.raw`');exit 121}
|
|
223
296
|
[Console]::Error.WriteLine('ocx-fanout:selected:'+$v);[Console]::Out.WriteLine('ocx-fanout:stdout-begin');Invoke-Native $x @($d.args)
|
|
224
297
|
};exit 127
|
|
225
298
|
`);
|
|
226
299
|
}
|
|
227
300
|
|
|
228
301
|
/** Credential-free loopback probe of the Child; no proxy, no redirect, bounded body and deadline. */
|
|
229
|
-
export function windowsChildHttpArgv(port: number, path: "healthz" | "v1/catalog", timeoutMs: number): string[] {
|
|
302
|
+
export function windowsChildHttpArgv(port: number, path: "healthz" | "v1/catalog", timeoutMs: number, routeProofId?: string): string[] {
|
|
230
303
|
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("invalid Child port");
|
|
231
304
|
if (path !== "healthz" && path !== "v1/catalog") throw new Error("invalid Child HTTP path");
|
|
232
305
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) throw new Error("invalid Child HTTP deadline");
|
|
306
|
+
// 32 lowercase hex characters only, so it is a plain literal inside the script.
|
|
307
|
+
if (routeProofId !== undefined && !/^[0-9a-f]{32}$/.test(routeProofId)) throw new Error("invalid route proof");
|
|
308
|
+
const proofHeader = routeProofId === undefined ? "" : `;$q.Headers.Add('x-opencodex-link-route-proof','${routeProofId}')`;
|
|
233
309
|
const budget = Math.max(1, Math.min(15_000, Math.ceil(timeoutMs)));
|
|
234
310
|
return powershellArgv(`$ErrorActionPreference='Stop';$r=$null
|
|
235
311
|
try{$w=[Diagnostics.Stopwatch]::StartNew()
|
|
236
|
-
$q=[Net.HttpWebRequest]::Create('http://127.0.0.1:${port}/${path}');$q.Proxy=$null;$q.AllowAutoRedirect=$false;$q.Timeout=${budget};$q.ReadWriteTimeout=${budget}
|
|
312
|
+
$q=[Net.HttpWebRequest]::Create('http://127.0.0.1:${port}/${path}');$q.Proxy=$null;$q.AllowAutoRedirect=$false;$q.Timeout=${budget};$q.ReadWriteTimeout=${budget}${proofHeader}
|
|
237
313
|
$r=$q.GetResponse();if([int]$r.StatusCode -ne 200){throw 'status'}
|
|
238
314
|
$t=$r.GetResponseStream();$o=New-Object IO.MemoryStream;$b=New-Object byte[] 8192
|
|
239
315
|
while($true){$left=${budget}-[int]$w.ElapsedMilliseconds;if($left -le 0){throw 'deadline'}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-body zstd for Remote Link requests from a Child to its Home (#3023).
|
|
3
|
+
*
|
|
4
|
+
* A Home that decodes zstd request bodies on the link's data routes advertises
|
|
5
|
+
* `LINK_REQUEST_ZSTD_FEATURE` in its peer features (`GET /readyz`) and, on every relay-auth answer,
|
|
6
|
+
* in `LINK_HOME_FEATURES_HEADER`. A Child compresses a body only for a Home whose last verified
|
|
7
|
+
* answer named the feature, and confirms it again on the connection that carries the body; an older
|
|
8
|
+
* Home never names it and gets identity bodies exactly as before. Each body is compressed on its
|
|
9
|
+
* own: no dictionary, no context shared across requests or links, and the link key travels in a
|
|
10
|
+
* header, outside the compressed bytes. The SSH tunnel itself is never compressed.
|
|
11
|
+
*/
|
|
12
|
+
import { parseFeatureList } from "./peer-report";
|
|
13
|
+
|
|
14
|
+
export const LINK_REQUEST_ZSTD_VERSION = "1";
|
|
15
|
+
export const LINK_REQUEST_ZSTD_FEATURE = `link-request-zstd/${LINK_REQUEST_ZSTD_VERSION}`;
|
|
16
|
+
/** The Home's served peer features, on its relay-auth answer. Not covered by the proof, and needs not be: see above. */
|
|
17
|
+
export const LINK_HOME_FEATURES_HEADER = "x-opencodex-link-home-features";
|
|
18
|
+
/** Bodies at or below this size are sent as they are. */
|
|
19
|
+
export const LINK_REQUEST_COMPRESSION_MIN_BYTES = 1024;
|
|
20
|
+
/** The most a Child buffers to compress one body; a larger declared body streams unchanged. */
|
|
21
|
+
export const LINK_REQUEST_COMPRESSION_MAX_BYTES = 16 * 1024 * 1024;
|
|
22
|
+
/** Routes whose Home handler decodes Content-Encoding through the shared JSON body reader. */
|
|
23
|
+
export const LINK_REQUEST_COMPRESSIBLE_PATHS: ReadonlySet<string> = new Set([
|
|
24
|
+
"/v1/responses", "/v1/responses/compact", "/v1/messages", "/v1/chat/completions",
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
/** Read the header the way a peer report is read; anything malformed is no list. */
|
|
28
|
+
export function parseLinkHomeFeatures(value: string | null): string[] | null {
|
|
29
|
+
return parseFeatureList(value);
|
|
30
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What to run on a Child that a failed enrollment may have left connected. Every step is bound to the attempt's link id
|
|
3
|
+
* (--expect-link), so it acts only while the Child's records name that link or nothing at all, and leaves a Child that
|
|
4
|
+
* another link, a hub or another Home owns: a plain disconnect or detach read long after the attempt could remove a link
|
|
5
|
+
* the machine joined since. A build older than the flag refuses it before it acts; then a full install falls back to a
|
|
6
|
+
* check of that link id, and a lightweight Child is left (its status cannot show an interrupted attach of another link,
|
|
7
|
+
* which a plain detach would restore and then remove). Without a valid id nothing can be bound, so the Child is left.
|
|
8
|
+
* One source for the live apply answer, the journal's replay and the CLI.
|
|
9
|
+
*/
|
|
10
|
+
export type ResidualChild = "plant" | "ephemeral" | "full" | "enrollment";
|
|
11
|
+
|
|
12
|
+
const LINK_ID = /^lnk_[0-9a-f]{16}$/;
|
|
13
|
+
|
|
14
|
+
export const RESIDUAL_NO_LINK = "This answer does not name the attempt's link id, so no step on the Child can be bound to it: leave the Child as it is.";
|
|
15
|
+
|
|
16
|
+
const OLDER_LIGHTWEIGHT = "An ocx-child older than that flag refuses it before it acts; then leave the Child as it is: its status cannot show an interrupted attach of another link, which a plain detach would restore and then remove.";
|
|
17
|
+
|
|
18
|
+
const olderFull = (id: string): string => "An OpenCodex older than that flag refuses it before it acts on the link; then run ocx disconnect and ocx restart only if ocx connect status --json shows " + id
|
|
19
|
+
+ ", right after that check (an enrollment that lands between the two commands would be removed), and otherwise leave the Child as it is.";
|
|
20
|
+
|
|
21
|
+
const bound = (id: string): string => "it acts only when the Child's records name this attempt's link (" + id + ") or nothing at all, and leaves a Child that another link, a hub or another Home owns.";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The lightweight agent's detach by the paths it can have: the managed copy (not necessarily on PATH) for the Child's platform,
|
|
25
|
+
* both Windows locations in Command Prompt, and a copy placed by hand through the path command -v (where.exe) prints.
|
|
26
|
+
*/
|
|
27
|
+
function lightweightDetach(id: string, platform: "posix" | "windows" | undefined): { first: string; rest: string; prompt: boolean } {
|
|
28
|
+
const posix = "~/.cache/opencodex/bin/ocx-child detach --expect-link " + id;
|
|
29
|
+
const windows = "\"%LOCALAPPDATA%\\opencodex\\bin\\ocx-child.exe\" detach --expect-link " + id;
|
|
30
|
+
const windowsFallback = "\"%USERPROFILE%\\.cache\\opencodex\\bin\\ocx-child.exe\" detach --expect-link " + id;
|
|
31
|
+
const placed = (lookup: string) => "for a copy placed by hand, the same detach --expect-link " + id + " through the path " + lookup + " prints";
|
|
32
|
+
if (platform === "windows") return { first: windows, rest: " (or " + windowsFallback + " where LOCALAPPDATA is not set; " + placed("where.exe ocx-child") + ")", prompt: true };
|
|
33
|
+
if (platform === "posix") return { first: posix, rest: " (" + placed("command -v ocx-child") + ")", prompt: false };
|
|
34
|
+
return { first: posix, rest: " (on Windows, in Command Prompt, " + windows + ", or " + windowsFallback + " where LOCALAPPDATA is not set; " + placed("command -v ocx-child, or where.exe ocx-child on Windows,") + ")", prompt: false };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function residualRecovery(kind: ResidualChild, linkId: string | undefined, platform?: "posix" | "windows"): string {
|
|
38
|
+
if (linkId === undefined || !LINK_ID.test(linkId)) return RESIDUAL_NO_LINK;
|
|
39
|
+
const id = linkId;
|
|
40
|
+
if (kind === "plant") {
|
|
41
|
+
// The Home planted this build itself, so it knows the flag. Both places the plant uses on Windows.
|
|
42
|
+
const posix = "~/.cache/opencodex/bin/ocx-child detach --purge --expect-link " + id;
|
|
43
|
+
const windows = "\"%LOCALAPPDATA%\\opencodex\\bin\\ocx-child.exe\" detach --purge --expect-link " + id;
|
|
44
|
+
const windowsFallback = "\"%USERPROFILE%\\.cache\\opencodex\\bin\\ocx-child.exe\" detach --purge --expect-link " + id;
|
|
45
|
+
if (platform === "windows") return "In Command Prompt on the Child, run " + windows + " (or " + windowsFallback + " where LOCALAPPDATA is not set) before retrying: " + bound(id);
|
|
46
|
+
if (platform === "posix") return "Run " + posix + " on the Child before retrying: " + bound(id);
|
|
47
|
+
return "Run " + posix + " on the Child before retrying (on Windows, in Command Prompt, " + windows + ", or " + windowsFallback + " where LOCALAPPDATA is not set): " + bound(id);
|
|
48
|
+
}
|
|
49
|
+
const light = lightweightDetach(id, platform);
|
|
50
|
+
if (kind === "ephemeral") return (light.prompt ? "In Command Prompt on the Child, run " + light.first + " before retrying" : "Run " + light.first + " on the Child before retrying") + light.rest + ": " + bound(id) + " " + OLDER_LIGHTWEIGHT;
|
|
51
|
+
if (kind === "full") return "Run ocx disconnect --expect-link " + id + " on the Child and, if it disconnected, ocx restart, before retrying: it disconnects only while the Child is connected to this attempt's link (" + id + "). " + olderFull(id);
|
|
52
|
+
return "Run ocx disconnect --expect-link " + id + " and, if it disconnected, ocx restart on a full install, or " + (light.prompt ? "in Command Prompt " : "") + light.first + " on a lightweight Child" + light.rest + ", before retrying: either acts only while the Child belongs to this attempt's link (" + id + "). "
|
|
53
|
+
+ "A build older than that flag refuses it before it acts; then leave a lightweight Child as it is, and on a full install run ocx disconnect and ocx restart only if ocx connect status --json shows " + id + ", right after that check, and otherwise leave it as it is.";
|
|
54
|
+
}
|