@bitkyc08/opencodex 2.100.2 → 2.100.4
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/AGENTS_INSTALL.md +23 -1
- package/README.md +1 -1
- package/bin/ocx.mjs +40 -19
- package/gui/dist/assets/{App-COo8Yopd.css → App-BGP8I0V4.css} +1 -1
- package/gui/dist/assets/App-DcpyI78f.js +60 -0
- package/gui/dist/assets/{Tray-BcaI-VCr.js → Tray-CzjPJprT.js} +1 -1
- package/gui/dist/assets/brand-mark-BTIi7e69.js +1 -0
- package/gui/dist/assets/index-DJxM-imn.css +2 -0
- package/gui/dist/assets/index-DVgU6S3y.js +138 -0
- package/gui/dist/assets/{segment-thumb-features-e9A_FogJ.js → segment-thumb-features-Bn6Y-g3R.js} +1 -1
- package/gui/dist/classic/assets/App-eYJAyNHM.js +59 -0
- package/gui/dist/classic/assets/{Tray-DT146AhS.js → Tray-xHMYxLkV.js} +1 -1
- package/gui/dist/classic/assets/index-DSaVRW4F.js +138 -0
- package/gui/dist/classic/assets/quota-summary-DyzHlkFl.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 +404 -20
- package/native/ocx-child/src/codex_home.rs +99 -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/per-message-effort.ts +296 -0
- package/src/adapters/anthropic.ts +34 -14
- package/src/adapters/claude-cli/adapter.ts +1 -0
- package/src/adapters/client-fingerprint.ts +3 -3
- 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/protobuf-request.ts +8 -8
- package/src/adapters/cursor.ts +7 -6
- package/src/adapters/devin/cloud-direct/chat.ts +71 -14
- package/src/adapters/google-antigravity-wire.ts +7 -5
- package/src/adapters/google-errors.ts +14 -2
- package/src/adapters/google-wire-compiler.ts +2 -2
- package/src/adapters/google.ts +9 -2
- 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/qoder/adapter.ts +9 -1
- package/src/adapters/zed.ts +7 -2
- 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 +43 -8
- package/src/claude/auth-detect.ts +21 -33
- 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 +82 -12
- package/src/claude/inbound-content-options.ts +31 -16
- package/src/claude/outbound.ts +13 -3
- package/src/cli/account-api.ts +21 -1
- package/src/cli/account-auth.ts +83 -22
- package/src/cli/account-extended.ts +33 -2
- package/src/cli/account-key-quota.ts +34 -5
- package/src/cli/account.ts +4 -2
- package/src/cli/advisor.ts +7 -4
- package/src/cli/alias.ts +38 -1
- package/src/cli/capabilities-access-remote.ts +128 -3
- package/src/cli/capabilities-accounts.ts +6 -6
- package/src/cli/capabilities-agents-routing.ts +17 -10
- package/src/cli/capabilities-base.ts +49 -19
- package/src/cli/capabilities-integrations.ts +2 -2
- package/src/cli/capabilities-observe-system.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 +17 -3
- package/src/cli/codex-launcher.ts +3 -1
- package/src/cli/codex-shim-autorestore.ts +5 -42
- package/src/cli/config-command.ts +14 -1
- package/src/cli/config-root-startup.ts +34 -0
- package/src/cli/connect.ts +88 -16
- package/src/cli/desktop-runtime-guidance.ts +1 -1
- package/src/cli/disconnect-runtime.ts +178 -0
- package/src/cli/dispatch.ts +61 -13
- package/src/cli/export-command.ts +1 -1
- package/src/cli/gui-pair-client.ts +6 -3
- package/src/cli/gui.ts +10 -5
- package/src/cli/help-catalog.ts +11 -0
- package/src/cli/help.ts +4 -3
- package/src/cli/index.ts +85 -94
- package/src/cli/inspect.ts +11 -2
- package/src/cli/integrations.ts +26 -1
- package/src/cli/link-apply-restart.ts +4 -2
- package/src/cli/link-capture.ts +64 -0
- package/src/cli/link-child-ops.ts +218 -40
- 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 +90 -0
- package/src/cli/link-status-child.ts +44 -1
- package/src/cli/link-status-traffic.ts +34 -0
- package/src/cli/link.ts +315 -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 +49 -0
- package/src/cli/registry.ts +33 -14
- package/src/cli/resolve.ts +23 -8
- package/src/cli/restart-failure.ts +15 -2
- package/src/cli/root.ts +5 -1
- package/src/cli/route-to.ts +172 -0
- package/src/cli/runtime-api.ts +9 -8
- package/src/cli/status.ts +7 -2
- 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 -15
- package/src/cli/sync-fanout.ts +74 -19
- 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-command.ts +1 -1
- package/src/cli/system-restart-client.ts +10 -3
- package/src/cli/system-settings-parity.ts +2 -1
- 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 +376 -35
- package/src/client/desktop-refusal.ts +38 -0
- package/src/client/lifecycle-lock.ts +29 -4
- 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-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.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 +141 -7
- package/src/client/runtime.ts +63 -15
- package/src/client/state.ts +44 -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 +22 -3
- package/src/codex/account-pause.ts +4 -0
- package/src/codex/account-runtime-state.ts +4 -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/main-account-probe.ts +3 -1
- package/src/codex/auth-api/main-hard-lock-refusal-read.ts +172 -0
- package/src/codex/auth-collision.ts +23 -22
- package/src/codex/auth-context.ts +61 -8
- package/src/codex/catalog/build-entries.ts +10 -0
- package/src/codex/catalog/derive-entry.ts +7 -0
- package/src/codex/catalog/gather-capture.ts +8 -2
- package/src/codex/catalog/parsing.ts +7 -3
- package/src/codex/catalog/provider-models.ts +54 -15
- package/src/codex/catalog/reserve-warn.ts +7 -5
- package/src/codex/catalog/reserve.ts +4 -3
- package/src/codex/catalog/retained-sync.ts +4 -1
- package/src/codex/catalog/routed-defaults.ts +35 -0
- 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.ts +4 -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/loopback-target.ts +22 -8
- package/src/codex/main-account.ts +109 -57
- package/src/codex/native-main-auth-file.ts +118 -0
- package/src/codex/native-main-credentials.ts +270 -0
- package/src/codex/native-main-owner.ts +3 -0
- package/src/codex/native-main-refresh-mode.ts +14 -1
- 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 +86 -15
- 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 +25 -5
- package/src/combos/failover.ts +342 -3
- package/src/combos/index.ts +5 -0
- package/src/combos/resolve.ts +115 -19
- package/src/config/dashboard-trusted-proxy.ts +83 -0
- package/src/config/diagnostics.ts +31 -0
- package/src/config/feature-flags.ts +9 -0
- package/src/config/live-reconcile.ts +16 -4
- package/src/config/load-degrade.ts +14 -1
- package/src/config/multi-agent-surface.ts +28 -5
- package/src/config/pending-teardown.ts +60 -3
- package/src/config/persisted-mutation.ts +2 -2
- package/src/config/persisted-projections.ts +18 -0
- package/src/config/process-state.ts +176 -4
- package/src/config/provider-validation.ts +4 -4
- package/src/config/reserve-capability.ts +96 -0
- package/src/config/schema/config-schema.ts +12 -0
- package/src/config/schema/leaf-validators.ts +11 -2
- package/src/config/schema/routed-catalog-defaults.ts +49 -0
- package/src/config/windows-process-command-line.ts +107 -0
- package/src/config.ts +7 -7
- package/src/desktop-update/acquire.ts +202 -0
- package/src/desktop-update/cli.ts +168 -0
- package/src/desktop-update/drain.ts +40 -0
- package/src/desktop-update/headless.ts +285 -0
- package/src/desktop-update/image.ts +85 -0
- package/src/desktop-update/install.ts +53 -0
- package/src/desktop-update/msi.ts +72 -0
- package/src/desktop-update/release.ts +128 -0
- package/src/desktop-update/runtime.ts +155 -0
- package/src/desktop-update/staging.ts +118 -0
- package/src/desktop-update/trust.ts +45 -0
- package/src/generated/compatibility-version.json +1114 -442
- package/src/generated/model-metadata.ts +1 -1
- package/src/images/fulfill-video.ts +3 -3
- package/src/images/loop.ts +9 -2
- package/src/images/plan.ts +147 -11
- package/src/images/types.ts +13 -4
- package/src/images/xai-video-client.ts +72 -10
- 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/client-retry-after.ts +29 -0
- package/src/lib/config-ownership.ts +13 -0
- package/src/lib/desktop-gui-origin.ts +28 -0
- package/src/lib/errors.ts +1 -1
- package/src/lib/gcp-adc.ts +48 -4
- package/src/lib/gui-pair-capability.ts +2 -1
- package/src/lib/messages-error-body.ts +4 -1
- package/src/lib/offline-resend.ts +150 -0
- 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/provider-outbound.ts +17 -6
- package/src/lib/redact.ts +84 -8
- package/src/lib/request-failure-model.ts +2 -0
- package/src/lib/response-body-inactivity.ts +23 -1
- 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 +52 -9
- package/src/link/alias-lock.ts +119 -0
- package/src/link/child-activity.ts +28 -2
- 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-gated-ocx.ts +29 -11
- package/src/link/child-observations.ts +2 -1
- package/src/link/child-observe.ts +2 -2
- package/src/link/child-ops-engine.ts +159 -91
- 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 +12 -3
- 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/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 +124 -36
- package/src/link/request-compression.ts +30 -0
- package/src/link/residual-recovery.ts +66 -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 +172 -24
- 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 +87 -0
- package/src/link/store.ts +54 -1
- package/src/link/supervisor.ts +543 -55
- package/src/link/sync-fanout-classify.ts +16 -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/ws-activity-holds.ts +474 -0
- package/src/local-credentials/publication-fence.ts +20 -1
- package/src/messaging/budget.ts +23 -5
- package/src/messaging/mcp-queue-rpc.ts +1 -1
- package/src/messaging/mcp-queue-server.ts +16 -1
- 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 +50 -6
- 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/antigravity-risk.ts +126 -0
- package/src/oauth/claude-keychain-read.ts +78 -68
- package/src/oauth/generic-account-failover.ts +89 -18
- package/src/oauth/generic-session-affinity.ts +10 -3
- package/src/oauth/index.ts +24 -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 +68 -19
- package/src/oauth/login-flow-state.ts +26 -3
- package/src/oauth/meta-muse.ts +1 -1
- package/src/oauth/pool-kernel.ts +3 -3
- package/src/oauth/store.ts +7 -0
- 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-billing-refusal.ts +27 -3
- 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.ts +3 -0
- 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.ts +51 -9
- package/src/providers/api-keys.ts +6 -2
- package/src/providers/cache-affinity-identity.ts +73 -0
- package/src/providers/cache-affinity.ts +256 -0
- package/src/providers/default-aliases.ts +98 -20
- package/src/providers/google-vertex-model-discovery.ts +515 -0
- package/src/providers/key-failover.ts +123 -8
- 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-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/passive-key-observation.ts +252 -0
- package/src/providers/quota/account-cache.ts +2 -1
- package/src/providers/quota/anthropic-cooldown-recovery-worker.ts +121 -0
- 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 +61 -2
- package/src/providers/quota/workbuddy.ts +6 -2
- package/src/providers/quota-key-accounts.ts +11 -6
- package/src/providers/quota-types.ts +18 -0
- package/src/providers/quota.ts +11 -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/workbuddy-credit-balance.ts +125 -16
- package/src/providers/xai-transport.ts +3 -0
- 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/effort-history.ts +732 -0
- 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 +2 -2
- package/src/routing/history/integrity.ts +41 -4
- 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 +111 -3
- package/src/server/bare-upstream-error.ts +220 -0
- package/src/server/chat-native.ts +14 -5
- package/src/server/claude-messages.ts +6 -4
- package/src/server/codex-model-list.ts +4 -2
- package/src/server/configured-credentials.ts +37 -5
- package/src/server/direct-local-http.ts +26 -3
- 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/inbound-body-admission.ts +17 -4
- package/src/server/index/link-listener.ts +196 -12
- package/src/server/index/link-management.ts +15 -1
- package/src/server/index/link-relay-sessions.ts +87 -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 +97 -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 +36 -86
- package/src/server/index/startup-warnings.ts +8 -2
- package/src/server/index/websocket-handler.ts +26 -4
- package/src/server/index.ts +15 -4
- 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 +149 -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 +39 -3
- 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 +145 -43
- 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 +192 -0
- package/src/server/management/link-route-request.ts +62 -0
- package/src/server/management/link-route-state.ts +83 -7
- package/src/server/management/link-routes.ts +553 -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 +58 -18
- 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 +14 -0
- package/src/server/management/provider-routes.ts +68 -65
- package/src/server/management/provider-routing-quota.ts +45 -0
- package/src/server/management/route-registry.ts +22 -3
- package/src/server/management/route-to-routes.ts +257 -0
- package/src/server/management/static-catalog-probe.ts +33 -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 +17 -5
- package/src/server/persistent-gui-session.ts +6 -3
- package/src/server/proxy-liveness.ts +87 -15
- package/src/server/relay-eager.ts +36 -12
- package/src/server/relay.ts +189 -117
- 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-terminal-status.ts +210 -24
- package/src/server/request-log.ts +76 -80
- package/src/server/reserve-capability-startup.ts +32 -0
- package/src/server/responses/adapter-continuation.ts +2 -1
- package/src/server/responses/adapter-delivery.ts +4 -0
- package/src/server/responses/adapter-dispatch.ts +36 -17
- 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/antigravity-fault-rotation.ts +24 -0
- package/src/server/responses/antigravity-validation-refusal.ts +43 -6
- 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-selection-keepalive.ts +254 -0
- package/src/server/responses/combo-stream-preflight.ts +557 -54
- package/src/server/responses/compact.ts +32 -8
- package/src/server/responses/core-codex-account.ts +17 -3
- package/src/server/responses/core-combo-failure.ts +8 -0
- package/src/server/responses/core-combo.ts +55 -12
- package/src/server/responses/core-errors.ts +13 -7
- package/src/server/responses/core-lifetime.ts +3 -2
- package/src/server/responses/core-normalize.ts +3 -1
- package/src/server/responses/core-options.ts +14 -0
- package/src/server/responses/core.ts +23 -0
- package/src/server/responses/estimated-usage.ts +115 -0
- package/src/server/responses/fetch-helpers.ts +15 -10
- package/src/server/responses/jev-model-invoke.ts +7 -2
- 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 +109 -9
- package/src/server/responses/passthrough-delivery.ts +77 -18
- package/src/server/responses/passthrough-dispatch.ts +77 -73
- package/src/server/responses/policy-fallback.ts +13 -1
- package/src/server/responses/request-prepare.ts +59 -11
- package/src/server/responses/request-transport.ts +10 -3
- package/src/server/responses/reset-replay.ts +46 -2
- package/src/server/responses/run-turn-execution.ts +2 -0
- package/src/server/responses/sidecar-execution.ts +19 -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/desktop-supervision.d.mts +2 -0
- package/src/service/desktop-supervision.mjs +5 -0
- 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/stall-timeout.ts +11 -0
- package/src/types/config.ts +57 -110
- package/src/types/link.ts +20 -0
- package/src/types/multi-agent.ts +13 -0
- package/src/types/provider.ts +60 -2
- package/src/types/request.ts +23 -0
- package/src/types/routed-catalog-defaults.ts +17 -0
- package/src/types/routing-profile.ts +90 -0
- package/src/types.ts +4 -0
- package/src/update/guarded-runtime-ops.ts +5 -7
- package/src/update/index.ts +26 -11
- 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 +57 -6
- package/src/usage/request-body.ts +37 -0
- package/src/usage/telemetry-contract.ts +1 -0
- package/src/web-search/loop.ts +3 -0
- package/src/web-search/passthrough-bridge.ts +7 -0
- package/gui/dist/assets/App-BpJOzw4F.js +0 -59
- package/gui/dist/assets/brand-mark-DU-0Vdkr.js +0 -1
- package/gui/dist/assets/index-Bbor_y80.js +0 -94
- package/gui/dist/assets/index-DJEkIDAi.css +0 -2
- package/gui/dist/classic/assets/App-BrIlUiLc.js +0 -58
- package/gui/dist/classic/assets/index-DyJHagvT.js +0 -94
- package/gui/dist/classic/assets/quota-summary-CakPe9Ni.js +0 -1
- package/src/server/management/desktop-compatibility-authorization.ts +0 -12
|
@@ -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
|
|
|
@@ -26,20 +28,44 @@ export function powershellArgv(script: string): string[] {
|
|
|
26
28
|
export const WINDOWS_CONTAINMENT_EXIT = 126;
|
|
27
29
|
|
|
28
30
|
const SCRIPT_PACKED_PREFIX = "$ocxPacked='";
|
|
31
|
+
/** First code point of the packed alphabet: 14 bits per character land in U+3400..U+73FF. */
|
|
32
|
+
const PACK_BASE = 0x3400;
|
|
33
|
+
|
|
29
34
|
/**
|
|
30
35
|
* The whole script travels deflated and is inflated on the Child before anything in it exists,
|
|
31
|
-
* including Fail.
|
|
36
|
+
* including Fail. The deflated bytes ride 14 bits per character in U+3400..U+73FF (#8359): every one
|
|
37
|
+
* is plain text inside a single-quoted PowerShell literal (no ASCII, no U+2018..U+201B smart quotes,
|
|
38
|
+
* no surrogates), and the denser alphabet leaves room under cmd.exe's command line for the
|
|
39
|
+
* served-runtime census in the gated scripts. The byte count rides along so padding bits never
|
|
40
|
+
* become a byte. A session that cannot inflate it (Constrained Language Mode blocks the stream
|
|
32
41
|
* types) must still exit 126, so only the inflate is guarded: Invoke-Expression stays outside the
|
|
33
42
|
* try, and the inflated script's own errors and exit status are never relabelled as containment.
|
|
34
43
|
*/
|
|
35
44
|
export function packedPowerShellArgv(script: string): string[] {
|
|
36
45
|
const bytes = deflateRawSync(Buffer.from(script, "utf8"), { level: 9 });
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
let packed = "", bits = 0, pending = 0;
|
|
47
|
+
for (const byte of bytes) {
|
|
48
|
+
pending = (pending << 8) | byte;
|
|
49
|
+
bits += 8;
|
|
50
|
+
while (bits >= 14) { bits -= 14; packed += String.fromCharCode(PACK_BASE + ((pending >> bits) & 0x3fff)); }
|
|
51
|
+
pending &= (1 << bits) - 1;
|
|
52
|
+
}
|
|
53
|
+
if (bits > 0) packed += String.fromCharCode(PACK_BASE + ((pending << (14 - bits)) & 0x3fff));
|
|
54
|
+
return powershellArgv(`${SCRIPT_PACKED_PREFIX}${packed}'\n` + String.raw`$ErrorActionPreference='Stop';try{$m=[IO.MemoryStream]::new();$a=0;$n=0;foreach($c in $ocxPacked.ToCharArray()){$a=($a -shl 14)-bor([int]$c-13312);$n+=14;while($n -ge 8){$n-=8;$m.WriteByte(($a -shr $n)-band 255)};$a=$a-band((1 -shl $n)-1)};$m.SetLength(` + bytes.length + String.raw`);$m.Position=0;$r=[IO.StreamReader]::new([IO.Compression.DeflateStream]::new($m,[IO.Compression.CompressionMode]::Decompress));$s=$r.ReadToEnd()}catch{try{[Console]::Error.WriteLine('Refusing to run ocx.exe outside a kill-on-close job.')}catch{$null=$_};exit ${WINDOWS_CONTAINMENT_EXIT}};Invoke-Expression $s`);
|
|
39
55
|
}
|
|
40
56
|
function unpackPowerShell(script: string): string {
|
|
41
57
|
const match = /\$ocxPacked='([^']+)'/.exec(script);
|
|
42
|
-
|
|
58
|
+
const length = /\$m\.SetLength\((\d+)\)/.exec(script);
|
|
59
|
+
if (!match || !length) return script;
|
|
60
|
+
const bytes: number[] = [];
|
|
61
|
+
let pending = 0, bits = 0;
|
|
62
|
+
for (const ch of match[1]!) {
|
|
63
|
+
pending = (pending << 14) | (ch.charCodeAt(0) - PACK_BASE);
|
|
64
|
+
bits += 14;
|
|
65
|
+
while (bits >= 8) { bits -= 8; bytes.push((pending >> bits) & 0xff); }
|
|
66
|
+
pending &= (1 << bits) - 1;
|
|
67
|
+
}
|
|
68
|
+
return inflateRawSync(Buffer.from(bytes.slice(0, Number(length[1])))).toString("utf8");
|
|
43
69
|
}
|
|
44
70
|
|
|
45
71
|
/**
|
|
@@ -52,13 +78,15 @@ function unpackPowerShell(script: string): string {
|
|
|
52
78
|
* host's. One finally block releases the attribute list, its value buffer and the thread, process
|
|
53
79
|
* and Job handles on every path, and terminates the child through its own handle if anything
|
|
54
80
|
* fails after creation. If Add-Type or any step fails, the host exits 126; there is no
|
|
55
|
-
* uncontained fallback.
|
|
81
|
+
* uncontained fallback. V is the bounded --version probe (ten seconds, at most 256 characters of
|
|
82
|
+
* stdout, exit 0) and Ok is V succeeding; both take an already CRT-quoted argument prefix, empty
|
|
83
|
+
* for a binary and the entry of a served [bun.exe, entry] pair (#8359). Layouts are x64:
|
|
56
84
|
* STARTUPINFOEXW is 112 bytes with the attribute list at byte 104, and LimitFlags sits at byte 16
|
|
57
85
|
* of the 144-byte JOBOBJECT_EXTENDED_LIMIT_INFORMATION. Warnings fail Add-Type in Windows
|
|
58
86
|
* PowerShell, so this source must compile without any.
|
|
59
87
|
*/
|
|
60
88
|
export const OCX_JOB_SOURCE = [
|
|
61
|
-
"using System;using System.Text;using System.Diagnostics;using System.Runtime.InteropServices;",
|
|
89
|
+
"using System;using System.Text;using System.Diagnostics;using System.Runtime.InteropServices;using System.Threading.Tasks;",
|
|
62
90
|
"public static class OcxJob{",
|
|
63
91
|
"[DllImport(\"kernel32\")]static extern IntPtr CreateJobObjectW(IntPtr a,IntPtr n);",
|
|
64
92
|
"[DllImport(\"kernel32\")]static extern bool SetInformationJobObject(IntPtr j,int c,byte[] i,int l);",
|
|
@@ -71,15 +99,12 @@ export const OCX_JOB_SOURCE = [
|
|
|
71
99
|
"[DllImport(\"kernel32\")]static extern bool TerminateProcess(IntPtr p,int c);",
|
|
72
100
|
"[DllImport(\"kernel32\")]static extern bool CloseHandle(IntPtr h);",
|
|
73
101
|
"static void F(bool k){if(!k)throw new Exception();}",
|
|
74
|
-
"public static bool Ok(string x){
|
|
75
|
-
"
|
|
76
|
-
"q.
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"var p=q;var read=System.Threading.Tasks.Task.Run(()=>{var b=new char[257];int n=0,k;while(n<257&&(k=p.StandardOutput.Read(b,n,257-n))>0)n+=k;return n>256?null:new string(b,0,n);});",
|
|
81
|
-
"System.Threading.Tasks.Task.Run(()=>{var b=new char[1024];while(p.StandardError.Read(b,0,b.Length)>0){} });",
|
|
82
|
-
"var clock=Stopwatch.StartNew();var done=System.Threading.Tasks.Task.Run(()=>p.WaitForExit());if(!read.Wait(10000)||read.Result==null||!done.Wait(Math.Max(0,10000-(int)clock.ElapsedMilliseconds))){q.Kill();q.WaitForExit();return null;}return q.ExitCode==0?read.Result:null;",
|
|
102
|
+
"public static bool Ok(string x,string a){return V(x,a)!=null;}",
|
|
103
|
+
"public static string V(string x,string a){Process q=null;try{",
|
|
104
|
+
"q=Process.Start(new ProcessStartInfo(x,a+\"--version\"){UseShellExecute=false,RedirectStandardInput=true,RedirectStandardOutput=true,RedirectStandardError=true});q.StandardInput.Close();",
|
|
105
|
+
"var p=q;var read=Task.Run(()=>{var b=new char[257];int n=0,k;while(n<257&&(k=p.StandardOutput.Read(b,n,257-n))>0)n+=k;return n>256?null:new string(b,0,n);});",
|
|
106
|
+
"Task.Run(()=>{var b=new char[1024];while(p.StandardError.Read(b,0,b.Length)>0){} });",
|
|
107
|
+
"var clock=Stopwatch.StartNew();var done=Task.Run(()=>p.WaitForExit());if(!read.Wait(10000)||read.Result==null||!done.Wait(Math.Max(0,10000-(int)clock.ElapsedMilliseconds))){q.Kill();q.WaitForExit();return null;}return q.ExitCode==0?read.Result:null;",
|
|
83
108
|
"}catch{try{if(q!=null&&!q.HasExited){q.Kill();q.WaitForExit();}}catch{return null;}return null;}finally{if(q!=null)q.Dispose();}}",
|
|
84
109
|
"public static int Run(string x,string c){",
|
|
85
110
|
"IntPtr z=IntPtr.Zero,j=z,l=z,v=z,h=z,t=z;bool listed=false,done=false;",
|
|
@@ -110,6 +135,11 @@ function Quote-Native([string]$v){'"'+[regex]::Replace([regex]::Replace($v,'(\\*
|
|
|
110
135
|
function Invoke-Native([string]$e,[string[]]$a){try{$c=[OcxJob]::Run($e,((@($e)+$a|%{Quote-Native $_}) -join ' '))}catch{Fail};exit $c}
|
|
111
136
|
`;
|
|
112
137
|
|
|
138
|
+
/** A script from this module with its packed payload inflated; any other text comes back unchanged. For tests. */
|
|
139
|
+
export function windowsInflatedScript(script: string): string {
|
|
140
|
+
return unpackPowerShell(script);
|
|
141
|
+
}
|
|
142
|
+
|
|
113
143
|
/** The packed helper a script carries, inflated; for tests that check the transport. */
|
|
114
144
|
export function windowsScriptHelperSource(script: string): string | undefined {
|
|
115
145
|
script = unpackPowerShell(script);
|
|
@@ -159,19 +189,39 @@ $f+=@((Get-Command ocx.exe -Type Application -EA 0).Source)
|
|
|
159
189
|
$k=@("$u\.local\bin\ocx-child.exe","$u\.cache\opencodex\bin\ocx-child.exe");if($env:LOCALAPPDATA){$k+="$env:LOCALAPPDATA\opencodex\bin\ocx-child.exe"};$k+=@((Get-Command ocx-child.exe -Type Application -EA 0).Source)
|
|
160
190
|
$r=if($env:HOME){$env:HOME}elseif($u){$u}else{"."};$h=if($env:OPENCODEX_HOME){$env:OPENCODEX_HOME}else{"$r\.opencodex"};$c=if([IO.File]::Exists("$h\child\state.json")){$k+$f}else{$f+$k}
|
|
161
191
|
`;
|
|
192
|
+
/**
|
|
193
|
+
* The install that last started serving this home (#8359), read from the first record's `command`
|
|
194
|
+
* in `serving-runtimes.json` (src/config/serving-runtimes.ts): `[ocx.exe]`, or `[bun.exe, cli\index.ts]`
|
|
195
|
+
* for an npm install. It moves ahead of every fixed candidate except ocx-child under a Child state,
|
|
196
|
+
* the POSIX order. Its variables ($sx, $sy) are names no other script fragment assigns: the gate loops
|
|
197
|
+
* reuse $a, $s and $p (#8359 review). `A` yields its entry as an argument prefix for the run and `P` the same prefix
|
|
198
|
+
* CRT-quoted for the helper's --version probe; any other candidate gets none. The pair runs only
|
|
199
|
+
* while its entry exists. A census over 64 KiB, a first record without a command, a relative or
|
|
200
|
+
* quoted path, a third element or any read error leaves the fixed order. The census sits where its
|
|
201
|
+
* writer's `getConfigDir()` puts it: a trimmed `OPENCODEX_HOME` (a leading ~ is the profile), else
|
|
202
|
+
* `%USERPROFILE%\.opencodex`, which is what `homedir()` answers on Windows; a Child state in that
|
|
203
|
+
* directory or the legacy `$h` one keeps ocx-child first. Discovery and runtime
|
|
204
|
+
* inspection, the pinned and overwrite syncs and the gated update plan all read it, so every Windows
|
|
205
|
+
* Remote Link command runs the same install the Child serves from.
|
|
206
|
+
*/
|
|
207
|
+
const SERVED_CANDIDATE = String.raw`$sx=$null;$sy=@();try{$o=([string]$env:OPENCODEX_HOME).Trim();if($o -match '^~([\\/]|$)'){$o=$u+$o.Substring(1)};$g=$(if($o){$o}else{"$u\.opencodex"});$j="$g\serving-runtimes.json";if((Get-Item -LiteralPath $j -Force -EA 1).Length -le 65536){$e=@(@(([IO.File]::ReadAllText($j)|ConvertFrom-Json).runtimes)[0].command);if($e.Count -in 1,2 -and !($e|?{$_ -isnot [string] -or $_ -match '["\x00-\x1f]' -or ![IO.Path]::IsPathRooted($_)})-and($e.Count -eq 1 -or [IO.File]::Exists($e[1]))){$sx=$e[0];$sy=@($e|select -Skip 1);$c=if([IO.File]::Exists("$g\child\state.json")-or[IO.File]::Exists("$h\child\state.json")){$k+$sx+$f}else{@($sx)+$f+$k}}}}catch{$null=$_}
|
|
208
|
+
function A($x){if($x -eq $sx){$sy}}
|
|
209
|
+
function P($x){(@(A $x)|%{(Quote-Native $_)+' '}) -join ''}
|
|
210
|
+
`;
|
|
211
|
+
|
|
162
212
|
export function windowsOcxArgv(args: readonly string[]): string[] {
|
|
163
213
|
const sweep = args.includes("--purge") ? String.raw`foreach($r in @($env:LOCALAPPDATA,$env:USERPROFILE)){if($r){foreach($s in @("$r\opencodex\bin","$r\.cache\opencodex\bin")){if([IO.Directory]::Exists($s)){Get-ChildItem -LiteralPath $s -Filter '.ocx-child.purge.*.old' -Force -EA 0|%{try{[IO.File]::Delete($_.FullName)}catch{$null=$_}}}}}};` : "";
|
|
164
|
-
const run = sweep ? `try{$c=[OcxJob]::Run($x,((@($x)+$d.args|%{Quote-Native $_}) -join ' '))}catch{Fail};${sweep}exit $c` : `Invoke-Native $x @($d.args)`;
|
|
165
|
-
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args }) + OCX_CANDIDATES + String.raw`
|
|
166
|
-
foreach($x in ($c|select -Unique)){if([IO.File]::Exists($x)-and[OcxJob]::Ok($x)){` + run + String.raw`}}
|
|
214
|
+
const run = sweep ? `try{$c=[OcxJob]::Run($x,((@($x)+@(A $x)+$d.args|%{Quote-Native $_}) -join ' '))}catch{Fail};${sweep}exit $c` : `Invoke-Native $x (@(A $x)+@($d.args))`;
|
|
215
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args }) + OCX_CANDIDATES + SERVED_CANDIDATE + String.raw`
|
|
216
|
+
foreach($x in ($c|select -Unique)){if([IO.File]::Exists($x)-and[OcxJob]::Ok($x,(P $x))){` + run + String.raw`}}
|
|
167
217
|
[Console]::Error.WriteLine('No runnable ocx.exe found; install the Windows standalone archive.');exit 127
|
|
168
218
|
`);
|
|
169
219
|
}
|
|
170
220
|
|
|
171
221
|
export function windowsInspectRuntimeArgv(): string[] {
|
|
172
|
-
return packedPowerShellArgv(NATIVE_PROCESS + OCX_CANDIDATES + String.raw`
|
|
222
|
+
return packedPowerShellArgv(NATIVE_PROCESS + OCX_CANDIDATES + SERVED_CANDIDATE + String.raw`
|
|
173
223
|
[Console]::Out.WriteLine('ocx-inspect:arch:'+[string]$env:PROCESSOR_ARCHITECTURE)
|
|
174
|
-
foreach($x in ($c|select -Unique)){if(![IO.File]::Exists($x)){continue};$v=[OcxJob]::V($x);if($null -ne $v){$k=if(([IO.Path]::GetFileName($x)).ToLowerInvariant().StartsWith('ocx-child')){'ephemeral'}else{'full'};[Console]::Out.WriteLine('ocx-inspect:kind:'+$k);[Console]::Out.WriteLine('ocx-inspect:version:'+$v.Trim());exit 0}}
|
|
224
|
+
foreach($x in ($c|select -Unique)){if(![IO.File]::Exists($x)){continue};$v=[OcxJob]::V($x,(P $x));if($null -ne $v){$k=if(([IO.Path]::GetFileName($x)).ToLowerInvariant().StartsWith('ocx-child')){'ephemeral'}else{'full'};[Console]::Out.WriteLine('ocx-inspect:kind:'+$k);[Console]::Out.WriteLine('ocx-inspect:version:'+$v.Trim());exit 0}}
|
|
175
225
|
[Console]::Out.WriteLine('ocx-inspect:kind:missing');exit 0
|
|
176
226
|
`);
|
|
177
227
|
}
|
|
@@ -201,26 +251,41 @@ export function windowsPurgePlantedChildArgv(): string[] {
|
|
|
201
251
|
return packedPowerShellArgv(NATIVE_PROCESS + WINDOWS_MANAGED_BIN + String.raw`
|
|
202
252
|
$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"}
|
|
203
253
|
$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.'}
|
|
204
|
-
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};
|
|
254
|
+
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
|
|
205
255
|
`);
|
|
206
256
|
}
|
|
207
257
|
|
|
208
258
|
/** Printed on stderr when the managed plant directory holds no runnable ocx-child to purge. */
|
|
209
259
|
export const MANAGED_PURGE_CHILD_MISSING_MARKER = "ocx-purge-error:managed_child_missing";
|
|
210
260
|
|
|
261
|
+
/** Read-only: print the link-bound detach receipt; exit 4 when it is missing, a reparse point or unreadable. */
|
|
262
|
+
export function windowsRecoverReceiptArgv(linkId: string): string[] {
|
|
263
|
+
if (!/^lnk_[0-9a-f]{16}$/.test(linkId)) throw new Error("invalid link id");
|
|
264
|
+
// The id travels as data ($d.args[0]), never spliced into the script source.
|
|
265
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: [linkId] }) + String.raw`
|
|
266
|
+
$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"
|
|
267
|
+
$b=if($env:LOCALAPPDATA){"$env:LOCALAPPDATA\opencodex\bin\ocx-child.exe"}else{"$env:USERPROFILE\.cache\opencodex\bin\ocx-child.exe"}
|
|
268
|
+
$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}
|
|
269
|
+
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
|
|
270
|
+
`);
|
|
271
|
+
}
|
|
272
|
+
|
|
211
273
|
/** Runs `disconnect --purge --json` through the planted %LOCALAPPDATA% binary, never a PATH candidate. */
|
|
212
|
-
|
|
213
|
-
|
|
274
|
+
/** expectLink (lnk_ and 16 hex digits) travels as data ($d.args[0]), never spliced into the script source. */
|
|
275
|
+
export function windowsManagedPurgeDisconnectArgv(expectLink?: string): string[] {
|
|
276
|
+
if (expectLink !== undefined && !/^lnk_[0-9a-f]{16}$/.test(expectLink)) throw new Error("invalid link id");
|
|
277
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: expectLink === undefined ? [] : [expectLink] }) + WINDOWS_MANAGED_BIN + String.raw`
|
|
214
278
|
try{$dir=Resolve-PlantDir}catch{[Console]::Error.WriteLine('Refusing a reparse point in the managed ocx-child directory.');exit 1}
|
|
215
|
-
$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}
|
|
216
|
-
|
|
279
|
+
$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}
|
|
280
|
+
$x=@($d.args);$e=if($x.Count -gt 0){' --expect-link '+(Quote-Native ([string]$x[0]))}else{''}
|
|
281
|
+
try{$rc=[OcxJob]::Run($dst,('"'+$dst+'" disconnect --purge --json'+$e))}catch{exit 1}
|
|
217
282
|
Get-ChildItem -LiteralPath $dir -Filter '.ocx-child.purge.*.old' -Force -EA 0|%{try{[IO.File]::Delete($_.FullName)}catch{$null=$_}};exit $rc
|
|
218
283
|
`);
|
|
219
284
|
}
|
|
220
285
|
|
|
221
286
|
export interface WindowsGatedCommand {
|
|
222
287
|
versionParts: readonly [string, string, string];
|
|
223
|
-
lacksMarker: "child-ocx-lacks-expect-link" | "child-ocx-lacks-orchestrated-update";
|
|
288
|
+
lacksMarker: "child-ocx-lacks-expect-link" | "child-ocx-lacks-orchestrated-update" | "child-ocx-lacks-overwrite";
|
|
224
289
|
acceptEphemeral: boolean;
|
|
225
290
|
/** Prints ocx-fanout:child-now:<epoch-ms> from [DateTimeOffset]::Now (Unix milliseconds do not depend on the offset). */
|
|
226
291
|
reportClock: boolean;
|
|
@@ -230,27 +295,28 @@ export interface WindowsGatedCommand {
|
|
|
230
295
|
/**
|
|
231
296
|
* The gated Windows command: select a candidate, refuse below the minimum, optionally refuse ocx-child, then run it
|
|
232
297
|
* contained. OCX_NO_DESKTOP_HANDOFF=1 makes a launcher answer --version and run the command itself. Windows never
|
|
233
|
-
* sends a restart, so the selected-kind report is not built here.
|
|
234
|
-
*
|
|
235
|
-
*
|
|
298
|
+
* sends a restart, so the selected-kind report is not built here. The served install comes first (#8359), and a served
|
|
299
|
+
* [bun.exe, entry] pair passes its entry as an argument prefix. The script still prints no entry marker and the Home
|
|
300
|
+
* infers "binary": Windows never applies an update, so nothing reads the pair/binary distinction there.
|
|
236
301
|
*/
|
|
237
302
|
export function windowsGatedOcxArgv(cmd: WindowsGatedCommand): string[] {
|
|
238
303
|
if (!cmd.versionParts.every(part => /^(0|[1-9][0-9]{0,3})$/.test(part))) throw new Error("invalid gate version");
|
|
239
|
-
if (!/^child-ocx-lacks-(expect-link|orchestrated-update)$/.test(cmd.lacksMarker)) throw new Error("invalid gate marker");
|
|
304
|
+
if (!/^child-ocx-lacks-(expect-link|orchestrated-update|overwrite)$/.test(cmd.lacksMarker)) throw new Error("invalid gate marker");
|
|
240
305
|
const b = cmd.versionParts.map(part => "'" + part + "'").join(",");
|
|
241
306
|
// -match is case-insensitive; the pattern reads the file name the way [IO.Path]::GetFileName does (either separator).
|
|
242
|
-
const
|
|
307
|
+
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};` : "";
|
|
308
|
+
const ephemeral = cmd.acceptEphemeral || overwriteEphemeral ? "" : String.raw`if($x -match '(^|[\\/])ocx-child[^\\/]*$'){[Console]::Error.WriteLine('ocx-fanout:child-ocx-ephemeral');exit 121};`;
|
|
243
309
|
const clock = cmd.reportClock ? String.raw`[Console]::Error.WriteLine('ocx-fanout:child-now:'+[DateTimeOffset]::Now.ToUnixTimeMilliseconds());` : "";
|
|
244
|
-
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: cmd.args }) + OCX_CANDIDATES + String.raw`$env:OCX_NO_DESKTOP_HANDOFF='1'
|
|
310
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: cmd.args }) + OCX_CANDIDATES + SERVED_CANDIDATE + String.raw`$env:OCX_NO_DESKTOP_HANDOFF='1'
|
|
245
311
|
foreach($x in ($c|select -Unique)){
|
|
246
|
-
if(![IO.File]::Exists($x)){continue}
|
|
312
|
+
if(![IO.File]::Exists($x)){continue};` + overwriteEphemeral + String.raw`$v=[OcxJob]::V($x,(P $x));if($null -eq $v){continue};$v=$v.Trim();if($v.StartsWith('opencodex ')){$v=$v.Substring(10)}
|
|
247
313
|
$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-]+)*))?$')
|
|
248
314
|
$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}}}
|
|
249
315
|
if($bad){[Console]::Error.WriteLine('ocx-fanout:child-ocx-version-unknown');exit 121}
|
|
250
316
|
$a=@($m.Groups[1].Value,$m.Groups[2].Value,$m.Groups[3].Value);$b=@(` + b + String.raw`);$cmp=0
|
|
251
317
|
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}}
|
|
252
318
|
if($cmp -lt 0 -or ($cmp -eq 0 -and $m.Groups[4].Success)){[Console]::Error.WriteLine('ocx-fanout:` + cmd.lacksMarker + String.raw`');exit 121}
|
|
253
|
-
` + 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)
|
|
319
|
+
` + ephemeral + String.raw`[Console]::Error.WriteLine('ocx-fanout:selected:'+$v);` + clock + String.raw`[Console]::Out.WriteLine('ocx-fanout:stdout-begin');Invoke-Native $x (@(A $x)+@($d.args))
|
|
254
320
|
};exit 127
|
|
255
321
|
`);
|
|
256
322
|
}
|
|
@@ -261,15 +327,37 @@ export function windowsPinnedSyncArgv(linkId: string): string[] {
|
|
|
261
327
|
reportClock: false, args: ["sync", "--expect-link", linkId, "--json"] });
|
|
262
328
|
}
|
|
263
329
|
|
|
330
|
+
export function windowsOverwriteSyncArgv(linkId: string, overwriteConflict = false, overwriteClient?: RouteClientId): string[] {
|
|
331
|
+
// Overwrite needs a Child that honours it: refuse ocx-child and older ocx before syncing.
|
|
332
|
+
const minimum = overwriteConflict ? ROUTE_OVERWRITE_MIN_CHILD_VERSION.split(".").map(part => `'${part}'`).join(",") : "'2','93','0'";
|
|
333
|
+
const lacks = overwriteConflict ? "ocx-fanout:child-ocx-lacks-overwrite" : "ocx-fanout:child-ocx-lacks-expect-link";
|
|
334
|
+
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};` : "";
|
|
335
|
+
return packedPowerShellArgv(NATIVE_PROCESS + dataLine({ args: ["sync", "--expect-link", linkId, "--json", ...(overwriteConflict ? ["--overwrite-conflict"] : []), ...(overwriteClient ? ["--overwrite-client", overwriteClient] : [])] }) + OCX_CANDIDATES + SERVED_CANDIDATE + String.raw`$env:OCX_NO_DESKTOP_HANDOFF=1
|
|
336
|
+
foreach($x in $c){
|
|
337
|
+
if(![IO.File]::Exists($x)){continue};` + ephemeral + String.raw`$v=[OcxJob]::V($x,(P $x));if($null -eq $v){continue};$v=$v.Trim();if($v.StartsWith('opencodex ')){$v=$v.Substring(10)}
|
|
338
|
+
$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-]+)*))?$')
|
|
339
|
+
$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}}}
|
|
340
|
+
if($bad){[Console]::Error.WriteLine('ocx-fanout:child-ocx-version-unknown');exit 121}
|
|
341
|
+
$a=@($m.Groups[1].Value,$m.Groups[2].Value,$m.Groups[3].Value);$b=@(` + minimum + String.raw`);$cmp=0
|
|
342
|
+
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}}
|
|
343
|
+
if($cmp -lt 0 -or ($cmp -eq 0 -and $m.Groups[4].Success)){[Console]::Error.WriteLine('` + lacks + String.raw`');exit 121}
|
|
344
|
+
[Console]::Error.WriteLine('ocx-fanout:selected:'+$v);[Console]::Out.WriteLine('ocx-fanout:stdout-begin');Invoke-Native $x (@(A $x)+@($d.args))
|
|
345
|
+
};exit 127
|
|
346
|
+
`);
|
|
347
|
+
}
|
|
348
|
+
|
|
264
349
|
/** Credential-free loopback probe of the Child; no proxy, no redirect, bounded body and deadline. */
|
|
265
|
-
export function windowsChildHttpArgv(port: number, path: "healthz" | "v1/catalog", timeoutMs: number): string[] {
|
|
350
|
+
export function windowsChildHttpArgv(port: number, path: "healthz" | "v1/catalog", timeoutMs: number, routeProofId?: string): string[] {
|
|
266
351
|
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("invalid Child port");
|
|
267
352
|
if (path !== "healthz" && path !== "v1/catalog") throw new Error("invalid Child HTTP path");
|
|
268
353
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) throw new Error("invalid Child HTTP deadline");
|
|
354
|
+
// 32 lowercase hex characters only, so it is a plain literal inside the script.
|
|
355
|
+
if (routeProofId !== undefined && !/^[0-9a-f]{32}$/.test(routeProofId)) throw new Error("invalid route proof");
|
|
356
|
+
const proofHeader = routeProofId === undefined ? "" : `;$q.Headers.Add('x-opencodex-link-route-proof','${routeProofId}')`;
|
|
269
357
|
const budget = Math.max(1, Math.min(15_000, Math.ceil(timeoutMs)));
|
|
270
358
|
return powershellArgv(`$ErrorActionPreference='Stop';$r=$null
|
|
271
359
|
try{$w=[Diagnostics.Stopwatch]::StartNew()
|
|
272
|
-
$q=[Net.HttpWebRequest]::Create('http://127.0.0.1:${port}/${path}');$q.Proxy=$null;$q.AllowAutoRedirect=$false;$q.Timeout=${budget};$q.ReadWriteTimeout=${budget}
|
|
360
|
+
$q=[Net.HttpWebRequest]::Create('http://127.0.0.1:${port}/${path}');$q.Proxy=$null;$q.AllowAutoRedirect=$false;$q.Timeout=${budget};$q.ReadWriteTimeout=${budget}${proofHeader}
|
|
273
361
|
$r=$q.GetResponse();if([int]$r.StatusCode -ne 200){throw 'status'}
|
|
274
362
|
$t=$r.GetResponseStream();$o=New-Object IO.MemoryStream;$b=New-Object byte[] 8192
|
|
275
363
|
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,66 @@
|
|
|
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
|
+
/**
|
|
22
|
+
* A purge path that is not found means no planted binary is there: an uncertain journalled plant can stop before it installs
|
|
23
|
+
* one, and a purge removes one only after every recovery record is gone. Either way no ocx-child of this attempt holds the
|
|
24
|
+
* Child, which the bare "not found" of the shell does not say.
|
|
25
|
+
*/
|
|
26
|
+
const PLANT_NOT_FOUND = " If the command is not found there, the binary is not installed (the plant stopped before installing it, or it was purged since), so no ocx-child of this attempt holds the Child: nothing is left to undo on it, and you can retry.";
|
|
27
|
+
|
|
28
|
+
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.";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The lightweight agent's detach by the paths it can have: the managed copy (not necessarily on PATH) for the Child's platform,
|
|
32
|
+
* both Windows locations in Command Prompt, and a copy placed by hand: first in ~/.local/bin (%USERPROFILE%\.local\bin on
|
|
33
|
+
* Windows), the place the Home's discovery tries before any other and which need not be on PATH, then through the path
|
|
34
|
+
* command -v (where.exe) prints.
|
|
35
|
+
*/
|
|
36
|
+
function lightweightDetach(id: string, platform: "posix" | "windows" | undefined): { first: string; rest: string; prompt: boolean } {
|
|
37
|
+
const posix = "~/.cache/opencodex/bin/ocx-child detach --expect-link " + id;
|
|
38
|
+
const windows = "\"%LOCALAPPDATA%\\opencodex\\bin\\ocx-child.exe\" detach --expect-link " + id;
|
|
39
|
+
const windowsFallback = "\"%USERPROFILE%\\.cache\\opencodex\\bin\\ocx-child.exe\" detach --expect-link " + id;
|
|
40
|
+
const placed = (where: string, lookup: string) => "for a copy placed by hand, the same detach --expect-link " + id + " through " + where
|
|
41
|
+
+ ", which need not be on PATH, or through the path " + lookup + " prints";
|
|
42
|
+
const posixPlaced = "~/.local/bin/ocx-child";
|
|
43
|
+
const windowsPlaced = "%USERPROFILE%\\.local\\bin\\ocx-child.exe";
|
|
44
|
+
if (platform === "windows") return { first: windows, rest: " (or " + windowsFallback + " where LOCALAPPDATA is not set; " + placed(windowsPlaced, "where.exe ocx-child") + ")", prompt: true };
|
|
45
|
+
if (platform === "posix") return { first: posix, rest: " (" + placed(posixPlaced, "command -v ocx-child") + ")", prompt: false };
|
|
46
|
+
return { first: posix, rest: " (on Windows, in Command Prompt, " + windows + ", or " + windowsFallback + " where LOCALAPPDATA is not set; " + placed(posixPlaced + " (" + windowsPlaced + " on Windows)", "command -v ocx-child, or where.exe ocx-child on Windows,") + ")", prompt: false };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function residualRecovery(kind: ResidualChild, linkId: string | undefined, platform?: "posix" | "windows"): string {
|
|
50
|
+
if (linkId === undefined || !LINK_ID.test(linkId)) return RESIDUAL_NO_LINK;
|
|
51
|
+
const id = linkId;
|
|
52
|
+
if (kind === "plant") {
|
|
53
|
+
// The Home planted this build itself, so it knows the flag. Both places the plant uses on Windows.
|
|
54
|
+
const posix = "~/.cache/opencodex/bin/ocx-child detach --purge --expect-link " + id;
|
|
55
|
+
const windows = "\"%LOCALAPPDATA%\\opencodex\\bin\\ocx-child.exe\" detach --purge --expect-link " + id;
|
|
56
|
+
const windowsFallback = "\"%USERPROFILE%\\.cache\\opencodex\\bin\\ocx-child.exe\" detach --purge --expect-link " + id;
|
|
57
|
+
if (platform === "windows") return "In Command Prompt on the Child, run " + windows + " (or " + windowsFallback + " where LOCALAPPDATA is not set) before retrying: " + bound(id) + PLANT_NOT_FOUND;
|
|
58
|
+
if (platform === "posix") return "Run " + posix + " on the Child before retrying: " + bound(id) + PLANT_NOT_FOUND;
|
|
59
|
+
return "Run " + posix + " on the Child before retrying (on Windows, in Command Prompt, " + windows + ", or " + windowsFallback + " where LOCALAPPDATA is not set): " + bound(id) + PLANT_NOT_FOUND;
|
|
60
|
+
}
|
|
61
|
+
const light = lightweightDetach(id, platform);
|
|
62
|
+
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;
|
|
63
|
+
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);
|
|
64
|
+
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 + "). "
|
|
65
|
+
+ "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.";
|
|
66
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { chmodSync, mkdirSync, readFileSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { atomicWriteFileNoFollow, isMissingPathError } from "../config/atomic-write";
|
|
5
|
+
import { withConfigMutationLockSync } from "../config/mutation-lock";
|
|
6
|
+
import { getConfigDir } from "../config/paths";
|
|
7
|
+
import { assertNotRealHomeUnderTest } from "../lib/test-home-guard";
|
|
8
|
+
import { hardenSecretDir } from "../lib/windows-secret-acl";
|
|
9
|
+
import { linkDir, linkStorePath } from "./paths";
|
|
10
|
+
import { isOperationId } from "./operations-journal";
|
|
11
|
+
import { parseLinkStore, readLinkStore, type LinkRecord, type LinkStore } from "./store";
|
|
12
|
+
|
|
13
|
+
/** How the removal that claimed the receipt cleaned up its Child before the commit: a retry must ask for the same. */
|
|
14
|
+
export type LinkRetirementMode = "force" | "disconnect" | "purge";
|
|
15
|
+
/**
|
|
16
|
+
* operationId names the journalled revoke that claimed the receipt: only that operation's replay resumes it (#8416),
|
|
17
|
+
* so a recorded revoke is never credited with, or skips its own cleanup through, another removal's receipt.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* formerOwner names the operation a plain --force took the receipt over from (disownLinkRetirement): that operation may
|
|
21
|
+
* take it back only while the force has provably committed nothing (#8416).
|
|
22
|
+
*/
|
|
23
|
+
export interface LinkRetirement { version: 1; link: LinkRecord; nonce: string; mode?: LinkRetirementMode; operationId?: string; formerOwner?: string }
|
|
24
|
+
export class LinkRetirementError extends Error {
|
|
25
|
+
constructor(message: string) { super(message); this.name = "LinkRetirementError"; }
|
|
26
|
+
}
|
|
27
|
+
const ID = /^lnk_[0-9a-f]{16}$/;
|
|
28
|
+
const NONCE = /^[0-9a-f]{64}$/;
|
|
29
|
+
|
|
30
|
+
function pathFor(id: string, configDir: string): string {
|
|
31
|
+
if (!ID.test(id)) throw new LinkRetirementError("invalid link id");
|
|
32
|
+
return join(linkDir(configDir), `retirement-${id}.json`);
|
|
33
|
+
}
|
|
34
|
+
function parse(text: string, id: string): LinkRetirement {
|
|
35
|
+
let raw: unknown;
|
|
36
|
+
try { raw = JSON.parse(text); } catch { throw new LinkRetirementError("invalid retirement JSON"); }
|
|
37
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new LinkRetirementError("invalid retirement record");
|
|
38
|
+
const value = raw as Record<string, unknown>;
|
|
39
|
+
const keys = Object.keys(value);
|
|
40
|
+
const allowed = new Set(["version", "link", "nonce", "mode", "operationId", "formerOwner"]);
|
|
41
|
+
if (keys.some(key => !allowed.has(key)) || !("link" in value) || value.version !== 1 || typeof value.nonce !== "string" || !NONCE.test(value.nonce)
|
|
42
|
+
|| (value.mode !== undefined && value.mode !== "force" && value.mode !== "disconnect" && value.mode !== "purge")
|
|
43
|
+
|| (value.operationId !== undefined && !isOperationId(value.operationId))
|
|
44
|
+
|| (value.formerOwner !== undefined && (!isOperationId(value.formerOwner) || value.operationId !== undefined))) {
|
|
45
|
+
throw new LinkRetirementError("invalid retirement record");
|
|
46
|
+
}
|
|
47
|
+
let link: LinkRecord;
|
|
48
|
+
try { link = parseLinkStore(JSON.stringify({ version: 1, listenerPort: null, links: [value.link] })).links[0]!; }
|
|
49
|
+
catch { throw new LinkRetirementError("invalid retirement link"); }
|
|
50
|
+
if (link.id !== id) throw new LinkRetirementError("retirement id mismatch");
|
|
51
|
+
return { version: 1, link, nonce: value.nonce, ...(value.mode === undefined ? {} : { mode: value.mode as LinkRetirementMode }),
|
|
52
|
+
...(value.operationId === undefined ? {} : { operationId: value.operationId as string }),
|
|
53
|
+
...(value.formerOwner === undefined ? {} : { formerOwner: value.formerOwner as string }) };
|
|
54
|
+
}
|
|
55
|
+
function sameLink(a: LinkRecord, b: LinkRecord): boolean {
|
|
56
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
57
|
+
}
|
|
58
|
+
/** Missing is distinct from malformed; malformed records always throw. */
|
|
59
|
+
export function readLinkRetirement(id: string, configDir: string = getConfigDir()): LinkRetirement | null {
|
|
60
|
+
const path = pathFor(id, configDir);
|
|
61
|
+
let text: string;
|
|
62
|
+
try { text = readFileSync(path, "utf8"); } catch (error) { if (isMissingPathError(error)) return null; throw error; }
|
|
63
|
+
return parse(text, id);
|
|
64
|
+
}
|
|
65
|
+
/** Claims only the still-current full link. A competing or damaged receipt is never replaced. */
|
|
66
|
+
export function claimLinkRetirement(link: LinkRecord, configDir: string = getConfigDir(), readStore?: () => LinkStore, mode?: LinkRetirementMode, operationId?: string): LinkRetirement {
|
|
67
|
+
const candidate = parse(JSON.stringify({ version: 1, link, nonce: randomBytes(32).toString("hex"), ...(mode ? { mode } : {}), ...(operationId ? { operationId } : {}) }), link.id);
|
|
68
|
+
assertNotRealHomeUnderTest(configDir);
|
|
69
|
+
return withConfigMutationLockSync(() => {
|
|
70
|
+
const path = pathFor(candidate.link.id, configDir);
|
|
71
|
+
if (readLinkRetirement(candidate.link.id, configDir)) throw new LinkRetirementError("retirement already claimed");
|
|
72
|
+
const store = readStore ? parseLinkStore(JSON.stringify(readStore())) : readLinkStore(linkStorePath(configDir));
|
|
73
|
+
const current = store.links.find(item => item.id === candidate.link.id);
|
|
74
|
+
if (!current || !sameLink(current, candidate.link)) throw new LinkRetirementError("link identity changed");
|
|
75
|
+
const dir = linkDir(configDir);
|
|
76
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
77
|
+
if (process.platform === "win32") hardenSecretDir(dir, { required: true });
|
|
78
|
+
else chmodSync(dir, 0o700);
|
|
79
|
+
atomicWriteFileNoFollow(path, `${JSON.stringify(candidate, null, 2)}\n`, undefined, {}, { exclusive: true });
|
|
80
|
+
return candidate;
|
|
81
|
+
}, configDir);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Take an owned receipt over for a plain --force (#8416): rewrite the exact receipt (same nonce, link and mode) without
|
|
85
|
+
* its operation id, under the config mutation lock, before the force changes anything. From then on the original
|
|
86
|
+
* operation no longer owns it, so a later replay of that operation cannot resume it and be credited with the force's
|
|
87
|
+
* removal. Returns the rewritten receipt, or null when the receipt changed.
|
|
88
|
+
*/
|
|
89
|
+
export function disownLinkRetirement(expected: LinkRetirement, configDir: string = getConfigDir()): LinkRetirement | null {
|
|
90
|
+
const owner = parse(JSON.stringify(expected), expected.link.id);
|
|
91
|
+
assertNotRealHomeUnderTest(configDir);
|
|
92
|
+
return withConfigMutationLockSync(() => {
|
|
93
|
+
const current = readLinkRetirement(owner.link.id, configDir);
|
|
94
|
+
if (!current || current.nonce !== owner.nonce || !sameLink(current.link, owner.link)) return null;
|
|
95
|
+
if (current.operationId === undefined) return current;
|
|
96
|
+
const { operationId: former, ...unowned } = current;
|
|
97
|
+
const next = parse(JSON.stringify({ ...unowned, formerOwner: former }), owner.link.id);
|
|
98
|
+
atomicWriteFileNoFollow(pathFor(owner.link.id, configDir), JSON.stringify(next, null, 2) + "\n");
|
|
99
|
+
return next;
|
|
100
|
+
}, configDir);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Undo disownLinkRetirement for a plain --force takeover that stopped before its removal began (#8416): give the exact
|
|
104
|
+
* receipt (same nonce and link, still without an owner) back to the operation that claimed it, under the config lock.
|
|
105
|
+
*/
|
|
106
|
+
export function reownLinkRetirement(expected: LinkRetirement, operationId: string, configDir: string = getConfigDir()): boolean {
|
|
107
|
+
const owner = parse(JSON.stringify(expected), expected.link.id);
|
|
108
|
+
assertNotRealHomeUnderTest(configDir);
|
|
109
|
+
return withConfigMutationLockSync(() => {
|
|
110
|
+
const current = readLinkRetirement(owner.link.id, configDir);
|
|
111
|
+
if (!current || current.nonce !== owner.nonce || !sameLink(current.link, owner.link) || current.operationId !== undefined) return false;
|
|
112
|
+
const { formerOwner: _former, ...rest } = current;
|
|
113
|
+
const next = parse(JSON.stringify({ ...rest, operationId }), owner.link.id);
|
|
114
|
+
atomicWriteFileNoFollow(pathFor(owner.link.id, configDir), JSON.stringify(next, null, 2) + "\n");
|
|
115
|
+
return true;
|
|
116
|
+
}, configDir);
|
|
117
|
+
}
|
|
118
|
+
/** Clear only the exact receipt previously read or claimed, under the config mutation lock. */
|
|
119
|
+
export function clearLinkRetirement(expected: LinkRetirement, configDir: string = getConfigDir(), safeToClear?: () => boolean): boolean {
|
|
120
|
+
const owner = parse(JSON.stringify(expected), expected.link.id);
|
|
121
|
+
assertNotRealHomeUnderTest(configDir);
|
|
122
|
+
return withConfigMutationLockSync(() => {
|
|
123
|
+
const current = readLinkRetirement(owner.link.id, configDir);
|
|
124
|
+
if (!current || current.nonce !== owner.nonce || !sameLink(current.link, owner.link) || (safeToClear && !safeToClear())) return false;
|
|
125
|
+
unlinkSync(pathFor(owner.link.id, configDir));
|
|
126
|
+
return true;
|
|
127
|
+
}, configDir);
|
|
128
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Ephemeral Home wakeups. The admitted link id, never a caller selector, owns each slot. */
|
|
2
|
+
export const ROUTE_INTENT_WATCH_HEADER = "x-ocx-route-intent-watch";
|
|
3
|
+
export const ROUTE_INTENT_AFTER_HEADER = "x-ocx-route-intent-after";
|
|
4
|
+
export const ROUTE_INTENT_WAKE_HEADER = "x-ocx-route-intent-wake";
|
|
5
|
+
export const ROUTE_INTENT_WATCH_TIMEOUT_MS = 30_000;
|
|
6
|
+
export const ROUTE_INTENT_WATCH_MAX_LINKS = 256;
|
|
7
|
+
export type RouteIntentWake = "notified" | "timeout" | "cancelled" | "busy";
|
|
8
|
+
|
|
9
|
+
export class RouteIntentWatch {
|
|
10
|
+
private readonly waiters = new Map<string, (reason: RouteIntentWake) => void>();
|
|
11
|
+
constructor(private readonly timeoutMs = ROUTE_INTENT_WATCH_TIMEOUT_MS, private readonly maxLinks = ROUTE_INTENT_WATCH_MAX_LINKS) {
|
|
12
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > ROUTE_INTENT_WATCH_TIMEOUT_MS
|
|
13
|
+
|| !Number.isInteger(maxLinks) || maxLinks < 1 || maxLinks > ROUTE_INTENT_WATCH_MAX_LINKS) throw new RangeError("invalid route intent watch bounds");
|
|
14
|
+
}
|
|
15
|
+
get size(): number { return this.waiters.size; }
|
|
16
|
+
wait(linkId: string, signal: AbortSignal): Promise<RouteIntentWake> {
|
|
17
|
+
if (signal.aborted) return Promise.resolve("cancelled");
|
|
18
|
+
if (this.waiters.has(linkId) || this.waiters.size >= this.maxLinks) return Promise.resolve("busy");
|
|
19
|
+
return new Promise(resolve => {
|
|
20
|
+
const finish = (reason: RouteIntentWake) => {
|
|
21
|
+
clearTimeout(timer);
|
|
22
|
+
signal.removeEventListener("abort", abort);
|
|
23
|
+
this.waiters.delete(linkId);
|
|
24
|
+
resolve(reason);
|
|
25
|
+
};
|
|
26
|
+
const abort = () => finish("cancelled");
|
|
27
|
+
const timer = setTimeout(() => finish("timeout"), this.timeoutMs);
|
|
28
|
+
timer.unref();
|
|
29
|
+
this.waiters.set(linkId, finish);
|
|
30
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
31
|
+
if (signal.aborted) abort();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** False means no active watcher accepted the request; it is never an apply acknowledgment. */
|
|
35
|
+
notify(linkId: string): boolean {
|
|
36
|
+
const wake = this.waiters.get(linkId);
|
|
37
|
+
wake?.("notified");
|
|
38
|
+
return wake !== undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export const homeRouteIntentWatch = new RouteIntentWatch();
|