@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
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { compareStrictSemver, parseStrictSemver } from "../lib/strict-semver";
|
|
2
|
+
import { ROUTE_OVERWRITE_MIN_CHILD_VERSION } from "./remote-windows";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Home-side classification of a pinned Child sync (moved from src/cli/sync-fanout.ts so the Link engine can use it
|
|
6
|
+
* without importing src/cli). Pure: imports only the strict semver parser.
|
|
7
|
+
*/
|
|
8
|
+
export const REMOTE_LINK_SYNC_MESSAGE = "Remote Link Home catalog synchronized.";
|
|
9
|
+
export const STALE_REMOTE_CATALOG_MESSAGE = "Home unavailable; retained and applied the last-known-good remote catalog (stale).";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* executable is present only when a restarting pinned sync reported that it selected ocx-child, which ignores the
|
|
13
|
+
* restart flags. Callers building ocx.sync.fanout/1 output must drop it.
|
|
14
|
+
*/
|
|
15
|
+
export type ChildVerdict = { state: "synced" | "skipped" | "failed"; reason: string | null; executable?: "ocx-child" };
|
|
16
|
+
const failure = (reason: string): ChildVerdict => ({ state: "failed", reason });
|
|
17
|
+
const skipped = (reason: string): ChildVerdict => ({ state: "skipped", reason });
|
|
18
|
+
const minimum = parseStrictSemver("2.93.0")!;
|
|
19
|
+
const SELECTED_KIND = "ocx-fanout:selected-kind:";
|
|
20
|
+
|
|
21
|
+
/** Operator guidance for a skipped pinned sync (moved from src/cli/sync-fanout.ts so the Link job runners can use it). */
|
|
22
|
+
export function childSkipHint(reason: string | null, alias: string): string {
|
|
23
|
+
if (reason === "child-ocx-lacks-expect-link") return `Update OpenCodex on ${alias} to >= 2.93.0 using the installer that owns its selected ocx. For Desktop on headless Windows, use Check for Updates in the signed-in Desktop tray.`;
|
|
24
|
+
if (reason === "child-ocx-lacks-overwrite") return `Update OpenCodex on ${alias} to >= ${ROUTE_OVERWRITE_MIN_CHILD_VERSION} to sync with --overwrite-conflict, or sync without it.`;
|
|
25
|
+
if (reason === "child-ephemeral-no-overwrite") return `${alias} runs the ephemeral ocx-child, which has no route intent to overwrite; sync without --overwrite-conflict.`;
|
|
26
|
+
if (reason === "child-updating") return "Wait for the Child update to finish, then retry sync.";
|
|
27
|
+
if (reason === "child-link-mismatch:pending_operation" || reason === "child-link-mismatch:disconnect_pending") return "Wait for the Child's link operation to finish, then check its link and retry sync.";
|
|
28
|
+
if (reason === "child-link-mismatch:disconnected" || reason === "child-link-mismatch:other_link") return "Please re-link this Child to this Home, then retry sync.";
|
|
29
|
+
if (reason?.startsWith("child-link-mismatch")) return "Check the Child's Remote Link connection and re-link it to this Home if needed, then retry sync.";
|
|
30
|
+
if (reason === "child-ocx-version-unknown") return "Check the Child's selected OpenCodex installation and version, then retry sync.";
|
|
31
|
+
if (reason === "child-platform-unsupported") return "Check the Child's platform and Remote Link setup before retrying sync.";
|
|
32
|
+
return "Check the Child's sync status and retry sync.";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function parseOcxVersion(output: string): string | null {
|
|
36
|
+
const version = output.trim().replace(/^opencodex /, "");
|
|
37
|
+
return parseStrictSemver(version) ? version : null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function classifyVersionProbe(output: string): "child-ocx-version-unknown" | "child-ocx-lacks-expect-link" | null {
|
|
41
|
+
const version = parseOcxVersion(output);
|
|
42
|
+
if (!version) return "child-ocx-version-unknown";
|
|
43
|
+
return compareStrictSemver(parseStrictSemver(version)!, minimum) < 0 ? "child-ocx-lacks-expect-link" : null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const mismatchReasons = new Set(["disconnected", "invalid_state", "disconnect_pending", "pending_operation", "hub_client", "link_client", "other_link", "other_key"]);
|
|
47
|
+
|
|
48
|
+
function validDocument(value: unknown): "synced" | "stale" | null {
|
|
49
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
50
|
+
const v = value as Record<string, unknown>;
|
|
51
|
+
const keysAre = (object: Record<string, unknown>, keys: readonly string[]): boolean => Object.keys(object).length === keys.length && keys.every(key => Object.hasOwn(object, key));
|
|
52
|
+
if (!keysAre(v, ["schema", "home", "fanout", "children"])) return null;
|
|
53
|
+
if (v.schema !== "ocx.sync.fanout/1" || !v.home || typeof v.home !== "object" || Array.isArray(v.home)
|
|
54
|
+
|| !v.fanout || typeof v.fanout !== "object" || Array.isArray(v.fanout) || !Array.isArray(v.children)) return null;
|
|
55
|
+
const home = v.home as Record<string, unknown>, fanout = v.fanout as Record<string, unknown>;
|
|
56
|
+
if (!keysAre(home, ["state", "exit"]) || !keysAre(fanout, ["state", "reason"])) return null;
|
|
57
|
+
if (home.exit !== 0 || (home.state !== "synced" && home.state !== "stale")) return null;
|
|
58
|
+
if (fanout.state !== "not-applicable" || fanout.reason !== null || v.children.length !== 0) return null;
|
|
59
|
+
return home.state;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* expectSelectedKind: only a restarting pinned sync asks its script to print ocx-fanout:selected-kind. Every other
|
|
64
|
+
* caller leaves it false, and then a selected-kind line in remote stderr is ignored exactly like any other noise.
|
|
65
|
+
*/
|
|
66
|
+
export function classifySyncResult(result: { code: number; stdout: string; stderr: string }, options: { expectSelectedKind?: boolean } = {}): ChildVerdict {
|
|
67
|
+
const { code, stdout, stderr } = result;
|
|
68
|
+
if (code === 255) return failure("ssh-failed");
|
|
69
|
+
if (code === 127) return failure("child-ocx-not-found");
|
|
70
|
+
if (code === 126) return failure("child-ocx-not-contained");
|
|
71
|
+
if (code === 125) return skipped("child-platform-unsupported");
|
|
72
|
+
const lines = stderr.split(/\r?\n/);
|
|
73
|
+
const last = stderr.trimEnd().split(/\r?\n/).at(-1);
|
|
74
|
+
if (code === 121) {
|
|
75
|
+
if (last === "ocx-fanout:child-ocx-lacks-overwrite" || last === "ocx-fanout:child-ephemeral-no-overwrite") return skipped(last.slice("ocx-fanout:".length));
|
|
76
|
+
if (last === "ocx-fanout:child-ocx-lacks-expect-link") return skipped("child-ocx-lacks-expect-link");
|
|
77
|
+
if (last === "ocx-fanout:child-ocx-version-unknown") return skipped("child-ocx-version-unknown");
|
|
78
|
+
return failure("child-sync-failed");
|
|
79
|
+
}
|
|
80
|
+
const markers = lines.map(line => /^ocx-fanout:selected:(.+)$/.exec(line)).filter(match => match !== null);
|
|
81
|
+
if (markers.length !== 1 || !parseStrictSemver(markers[0]![1]!)) return failure("child-output-invalid");
|
|
82
|
+
// Requested only: at most one selected-kind line, after the selection marker, naming ocx-child (the restart was ignored).
|
|
83
|
+
const selectedAt = lines.findIndex(line => line.startsWith("ocx-fanout:selected:"));
|
|
84
|
+
const kinds = options.expectSelectedKind !== true ? []
|
|
85
|
+
: lines.flatMap((line, index) => line.startsWith(SELECTED_KIND) ? [{ index, value: line.slice(SELECTED_KIND.length) }] : []);
|
|
86
|
+
if (kinds.length > 1 || (kinds.length === 1 && (kinds[0]!.value !== "ocx-child" || kinds[0]!.index < selectedAt))) return failure("child-output-invalid");
|
|
87
|
+
const kind = (verdict: ChildVerdict): ChildVerdict => kinds.length === 1 ? { ...verdict, executable: "ocx-child" } : verdict;
|
|
88
|
+
const outputLines = stdout.split(/\r?\n/);
|
|
89
|
+
const delimiters = outputLines.flatMap((line, index) => line === "ocx-fanout:stdout-begin" ? [index] : []);
|
|
90
|
+
if (delimiters.length !== 1) return failure("child-output-invalid");
|
|
91
|
+
if (code === 5) {
|
|
92
|
+
try {
|
|
93
|
+
const detail: unknown = JSON.parse(last ?? "");
|
|
94
|
+
if (detail && typeof detail === "object" && "phase" in detail && detail.phase === "child_link_mismatch"
|
|
95
|
+
&& "reason" in detail && typeof detail.reason === "string" && mismatchReasons.has(detail.reason)) return kind(skipped(`child-link-mismatch:${detail.reason}`));
|
|
96
|
+
} catch { /* The generic mismatch is the only safe fallback. */ }
|
|
97
|
+
return kind(skipped("child-link-mismatch"));
|
|
98
|
+
}
|
|
99
|
+
if (code === 7) return kind(skipped("child-updating"));
|
|
100
|
+
if (code !== 0) return kind(failure("child-sync-failed"));
|
|
101
|
+
const text = outputLines.slice(delimiters[0]! + 1).join("\n").trim();
|
|
102
|
+
if (text.startsWith("{")) {
|
|
103
|
+
try {
|
|
104
|
+
const state = validDocument(JSON.parse(text));
|
|
105
|
+
if (state === "synced") return kind({ state: "synced", reason: null });
|
|
106
|
+
if (state === "stale") return kind(failure("child-catalog-stale"));
|
|
107
|
+
} catch { /* Reject invalid or multiple JSON documents. */ }
|
|
108
|
+
return kind(failure("child-output-invalid"));
|
|
109
|
+
}
|
|
110
|
+
if (text.includes(STALE_REMOTE_CATALOG_MESSAGE)) return kind(failure("child-catalog-stale"));
|
|
111
|
+
if (text.includes(REMOTE_LINK_SYNC_MESSAGE)) return kind({ state: "synced", reason: null });
|
|
112
|
+
return kind(failure("child-output-invalid"));
|
|
113
|
+
}
|
|
114
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ChildRestart, ChildRestartOutcome } from "./child-ops-types";
|
|
2
|
+
import type { LinkRecord } from "./store";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* "Sync then guarded restart" (A2, 040 decision 7): the one implementation used by the Child operation runners
|
|
6
|
+
* (child-ops-runners.ts) and by ocx sync --restart-children (src/cli/sync-command.ts). Type-only imports, so the CLI
|
|
7
|
+
* pulls nothing else in. The caller supplies the pinned sync and the activity read.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Revision 6 F2 (030): a restarting sync that may have run but whose result is unknown. */
|
|
11
|
+
export const RESTART_RESULT_UNKNOWN = "restart-result-unknown";
|
|
12
|
+
|
|
13
|
+
type Verdict = { state: string; reason: string | null; executable?: "ocx-child" };
|
|
14
|
+
/** One pinned sync: its verdict and whether it certainly ran nothing on the Child (F2). */
|
|
15
|
+
export interface PinnedRun<S extends Verdict> { sync: S; notRun: boolean }
|
|
16
|
+
/** Why no restart went out. In process only; never serialized into a job or ocx.sync.fanout/1. */
|
|
17
|
+
export type RestartWithheld = "platform" | "ocx-child" | "sync-failed" | "activity-unknown" | "link-active" | "second-not-run";
|
|
18
|
+
|
|
19
|
+
export interface SyncThenRestart<S extends Verdict> {
|
|
20
|
+
/** The plain sync's verdict, or the restarting sync's when restartUnknown. */
|
|
21
|
+
sync: S;
|
|
22
|
+
restart?: { requested: "app-server" | "codex"; outcome: ChildRestartOutcome };
|
|
23
|
+
restartUnknown?: true;
|
|
24
|
+
withheld?: RestartWithheld;
|
|
25
|
+
/** The restarting sync's verdict whenever one ran. */
|
|
26
|
+
second?: S;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* F2: the gate refused before selecting an ocx (121, 125, 126, 127 without the selection marker), or the Child's sync
|
|
31
|
+
* declined (skipped). A dropped channel (255), a failure after selection or a timeout may have restarted Codex.
|
|
32
|
+
*/
|
|
33
|
+
export function pinnedSyncRanNothing(verdict: Verdict, result: { code: number; stderr: string }): boolean {
|
|
34
|
+
const selected = /^ocx-fanout:selected:/m.test(result.stderr);
|
|
35
|
+
return verdict.state === "skipped" || (verdict.state === "failed" && !selected && [121, 125, 126, 127].includes(result.code));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Revision 4 (4529521916): the catalog sync runs first without a restart; activity is read after it; the restart then
|
|
40
|
+
* goes out as a second pinned sync, which is close to a no-op sync. The gap between the activity read and the restart is
|
|
41
|
+
* one SSH round trip instead of a whole sync. It cannot be closed from the Home: the restart executes on the Child.
|
|
42
|
+
*/
|
|
43
|
+
export async function syncThenRestart<S extends Verdict>(input: {
|
|
44
|
+
requested: ChildRestart; platform: "posix" | "windows"; childKind: LinkRecord["childKind"];
|
|
45
|
+
runPinned: (restart: ChildRestart) => Promise<PinnedRun<S>>;
|
|
46
|
+
/** Read after the plain sync, immediately before the restart. null is unknown and counts as in flight (D5). */
|
|
47
|
+
readActivity: () => Promise<{ inFlight: number } | null>;
|
|
48
|
+
}): Promise<SyncThenRestart<S>> {
|
|
49
|
+
const { requested } = input;
|
|
50
|
+
const first = (await input.runPinned("none")).sync;
|
|
51
|
+
if (requested === "none") return { sync: first };
|
|
52
|
+
if (input.platform !== "posix") return { sync: first, restart: { requested, outcome: "unsupported" }, withheld: "platform" };
|
|
53
|
+
if (input.childKind === "ephemeral") return { sync: first, restart: { requested, outcome: "unsupported" }, withheld: "ocx-child" };
|
|
54
|
+
if (first.state !== "synced") return { sync: first, restart: { requested, outcome: "not-run" }, withheld: "sync-failed" };
|
|
55
|
+
const activity = await input.readActivity();
|
|
56
|
+
if (activity === null) return { sync: first, restart: { requested, outcome: "skipped" }, withheld: "activity-unknown" };
|
|
57
|
+
if (activity.inFlight > 0) return { sync: first, restart: { requested, outcome: "skipped" }, withheld: "link-active" };
|
|
58
|
+
const second = await input.runPinned(requested);
|
|
59
|
+
// 4529521993: a record without childKind can still select ocx-child, which ignores the flag (010 selected-kind marker).
|
|
60
|
+
if (second.sync.executable === "ocx-child") return { sync: first, restart: { requested, outcome: "unsupported" }, withheld: "ocx-child", second: second.sync };
|
|
61
|
+
if (second.sync.state === "synced") return { sync: first, restart: { requested, outcome: "requested" }, second: second.sync };
|
|
62
|
+
if (second.notRun) return { sync: first, restart: { requested, outcome: "not-run" }, withheld: "second-not-run", second: second.sync };
|
|
63
|
+
// F2: the restart was sent and its result is unknown; the caller reports the second sync beside it.
|
|
64
|
+
return { sync: second.sync, restart: { requested, outcome: "requested" }, restartUnknown: true, second: second.sync };
|
|
65
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { chmodSync, mkdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { atomicWriteFile, isMissingPathError } from "../config/atomic-write";
|
|
4
|
+
import { assertNotRealHomeUnderTest } from "../lib/test-home-guard";
|
|
5
|
+
import { hardenSecretDir } from "../lib/windows-secret-acl";
|
|
6
|
+
import { linkDir } from "./paths";
|
|
7
|
+
import { parseExplicitRoute, type ExplicitRoute } from "./explicit-route";
|
|
8
|
+
import { assertSshAlias } from "./ssh-argv";
|
|
9
|
+
import { MAX_LINK_ROUTES } from "./store";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Tombstones for ephemeral links whose Child was never cleaned (lane O5 of the disposable-machines
|
|
13
|
+
* design). A forced revoke skips the remote disconnect, so the link record and key go while the
|
|
14
|
+
* planted ocx-child may still hold that link's state and CODEX_HOME changes. The tombstone keeps
|
|
15
|
+
* what ocx link recover needs to reach that machine over the same pinned SSH trust, and stays until
|
|
16
|
+
* the Child's own receipt proves cleanup. It holds no key.
|
|
17
|
+
*/
|
|
18
|
+
export interface LinkTombstone {
|
|
19
|
+
linkId: string;
|
|
20
|
+
alias: string;
|
|
21
|
+
hostKeyFingerprint: string;
|
|
22
|
+
remotePlatform?: "posix" | "windows";
|
|
23
|
+
/** The link's route list when it had several; recover uses only alias, the pinned name. */
|
|
24
|
+
routes?: string[];
|
|
25
|
+
/** The link's explicit route (src/link/explicit-route.ts); recover reaches the machine over it. */
|
|
26
|
+
explicitRoute?: ExplicitRoute;
|
|
27
|
+
/** The link was exclusive: no other route may reach it. Required by explicitRoute. */
|
|
28
|
+
exclusive?: true;
|
|
29
|
+
revokedAt: string;
|
|
30
|
+
/** Random per revoke attempt, so a failed attempt's cleanup removes only the tombstone it wrote. */
|
|
31
|
+
attempt?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Fields a later Home adds go here, never at the top level: this Home keeps them verbatim when it
|
|
34
|
+
* rewrites the file and reads none of them, so a newer Home's tombstone never makes an older one
|
|
35
|
+
* refuse forced revokes. A change older Homes must not ignore bumps the store version instead.
|
|
36
|
+
*/
|
|
37
|
+
ext?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface LinkTombstoneStore {
|
|
41
|
+
version: 1;
|
|
42
|
+
tombstones: LinkTombstone[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class LinkTombstoneStoreError extends Error {
|
|
46
|
+
constructor(message: string) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.name = "LinkTombstoneStoreError";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** At most this many forced revokes wait for cleanup; a forced revoke beyond it is refused, never dropped. */
|
|
53
|
+
export const MAX_TOMBSTONES = 256;
|
|
54
|
+
const MAX_EXT_BYTES = 4096;
|
|
55
|
+
|
|
56
|
+
export class LinkTombstoneLimitError extends Error {
|
|
57
|
+
constructor() {
|
|
58
|
+
super(`at most ${MAX_TOMBSTONES} link tombstones can wait for cleanup`);
|
|
59
|
+
this.name = "LinkTombstoneLimitError";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const LINK_ID = /^lnk_[0-9a-f]{16}$/;
|
|
64
|
+
const ATTEMPT = /^[0-9a-f]{16}$/;
|
|
65
|
+
const FINGERPRINT = /^[A-Z0-9]+:[A-Za-z0-9+/=]{16,128}$/;
|
|
66
|
+
const KEYS = new Set(["linkId", "alias", "hostKeyFingerprint", "remotePlatform", "routes", "explicitRoute", "exclusive", "revokedAt", "attempt", "ext"]);
|
|
67
|
+
|
|
68
|
+
export function tombstonesPath(configDir?: string): string {
|
|
69
|
+
return join(linkDir(configDir), "tombstones.json");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isAlias(value: unknown): value is string {
|
|
73
|
+
if (typeof value !== "string") return false;
|
|
74
|
+
try { assertSshAlias(value); return true; } catch { return false; }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function parseTombstone(value: unknown, index: number): LinkTombstone {
|
|
78
|
+
const fail = (): never => { throw new LinkTombstoneStoreError(`tombstones[${index}] is invalid`); };
|
|
79
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) fail();
|
|
80
|
+
const raw = value as Record<string, unknown>;
|
|
81
|
+
if (Object.keys(raw).some(key => !KEYS.has(key))) fail();
|
|
82
|
+
if (typeof raw.linkId !== "string" || !LINK_ID.test(raw.linkId)) fail();
|
|
83
|
+
if (!isAlias(raw.alias)) fail();
|
|
84
|
+
if (typeof raw.hostKeyFingerprint !== "string" || !FINGERPRINT.test(raw.hostKeyFingerprint)) fail();
|
|
85
|
+
if (raw.remotePlatform !== undefined && raw.remotePlatform !== "posix" && raw.remotePlatform !== "windows") fail();
|
|
86
|
+
if (raw.routes !== undefined) {
|
|
87
|
+
const routes: unknown = raw.routes;
|
|
88
|
+
if (!Array.isArray(routes) || routes.length < 2 || routes.length > MAX_LINK_ROUTES
|
|
89
|
+
|| !routes.every(isAlias) || !routes.includes(raw.alias as string) || new Set(routes).size !== routes.length) fail();
|
|
90
|
+
}
|
|
91
|
+
if (typeof raw.revokedAt !== "string" || Number.isNaN(Date.parse(raw.revokedAt))) fail();
|
|
92
|
+
if (raw.attempt !== undefined && (typeof raw.attempt !== "string" || !ATTEMPT.test(raw.attempt))) fail();
|
|
93
|
+
if (raw.exclusive !== undefined && (raw.exclusive !== true || raw.routes !== undefined)) fail();
|
|
94
|
+
const explicitRoute = raw.explicitRoute === undefined ? undefined : parseExplicitRoute(raw.explicitRoute);
|
|
95
|
+
if (explicitRoute === null || (explicitRoute && raw.exclusive !== true)) fail();
|
|
96
|
+
const ext = raw.ext;
|
|
97
|
+
if (ext !== undefined && (!ext || typeof ext !== "object" || Array.isArray(ext) || Buffer.byteLength(JSON.stringify(ext), "utf8") > MAX_EXT_BYTES)) fail();
|
|
98
|
+
return {
|
|
99
|
+
linkId: raw.linkId as string,
|
|
100
|
+
alias: raw.alias as string,
|
|
101
|
+
hostKeyFingerprint: raw.hostKeyFingerprint as string,
|
|
102
|
+
...(raw.remotePlatform === undefined ? {} : { remotePlatform: raw.remotePlatform as "posix" | "windows" }),
|
|
103
|
+
...(raw.routes === undefined ? {} : { routes: [...raw.routes as string[]] }),
|
|
104
|
+
...(explicitRoute ? { explicitRoute } : {}),
|
|
105
|
+
...(raw.exclusive === true ? { exclusive: true as const } : {}),
|
|
106
|
+
revokedAt: raw.revokedAt as string,
|
|
107
|
+
...(raw.attempt === undefined ? {} : { attempt: raw.attempt as string }),
|
|
108
|
+
...(ext === undefined ? {} : { ext: JSON.parse(JSON.stringify(ext)) as Record<string, unknown> }),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function parseTombstones(text: string): LinkTombstoneStore {
|
|
113
|
+
let raw: unknown;
|
|
114
|
+
try { raw = JSON.parse(text); } catch { throw new LinkTombstoneStoreError("tombstones.json is not valid JSON"); }
|
|
115
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new LinkTombstoneStoreError("tombstones.json is not an object");
|
|
116
|
+
const body = raw as Record<string, unknown>;
|
|
117
|
+
if (Object.keys(body).some(key => key !== "version" && key !== "tombstones") || body.version !== 1 || !Array.isArray(body.tombstones)) {
|
|
118
|
+
throw new LinkTombstoneStoreError("tombstones.json has an invalid shape");
|
|
119
|
+
}
|
|
120
|
+
if (body.tombstones.length > MAX_TOMBSTONES) throw new LinkTombstoneStoreError("tombstones.json has too many entries");
|
|
121
|
+
const tombstones = body.tombstones.map(parseTombstone);
|
|
122
|
+
if (new Set(tombstones.map(t => t.linkId)).size !== tombstones.length) throw new LinkTombstoneStoreError("tombstones.json has duplicate link ids");
|
|
123
|
+
return { version: 1, tombstones };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A missing file is empty. A damaged file is an error: it is the only evidence that a Child still
|
|
128
|
+
* needs cleanup, so it is never read as empty and never overwritten.
|
|
129
|
+
*/
|
|
130
|
+
export function readTombstones(path: string = tombstonesPath()): LinkTombstoneStore {
|
|
131
|
+
let text: string;
|
|
132
|
+
try { text = readFileSync(path, "utf8"); } catch (error) {
|
|
133
|
+
if (isMissingPathError(error)) return { version: 1, tombstones: [] };
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
return parseTombstones(text);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function writeTombstones(path: string, store: LinkTombstoneStore): void {
|
|
140
|
+
const normalized = parseTombstones(JSON.stringify(store));
|
|
141
|
+
const dir = dirname(path);
|
|
142
|
+
assertNotRealHomeUnderTest(dirname(dir));
|
|
143
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
144
|
+
if (process.platform === "win32") hardenSecretDir(dir, { required: true });
|
|
145
|
+
else chmodSync(dir, 0o700);
|
|
146
|
+
atomicWriteFile(path, `${JSON.stringify(normalized, null, 2)}\n`);
|
|
147
|
+
if (process.platform !== "win32") chmodSync(path, 0o600);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Add the tombstone for tombstone.linkId, or keep the one already there: "kept" means another revoke attempt (a forced
|
|
152
|
+
* revoke still in flight in another runtime, or one that died) wrote it, so this attempt owns nothing it may drop.
|
|
153
|
+
* Replacing it would let a failed attempt drop the only tombstone of a revoke that then commits. Callers hold the
|
|
154
|
+
* config mutation lock.
|
|
155
|
+
*/
|
|
156
|
+
export function recordTombstone(tombstone: LinkTombstone, path: string = tombstonesPath()): "recorded" | "kept" {
|
|
157
|
+
const current = readTombstones(path);
|
|
158
|
+
if (current.tombstones.some(t => t.linkId === tombstone.linkId)) return "kept";
|
|
159
|
+
const others = current.tombstones.filter(t => t.linkId !== tombstone.linkId);
|
|
160
|
+
if (others.length >= MAX_TOMBSTONES) throw new LinkTombstoneLimitError();
|
|
161
|
+
writeTombstones(path, { version: 1, tombstones: [...others, tombstone] });
|
|
162
|
+
return "recorded";
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Remove the tombstone for linkId; true when one was removed. Callers hold the config mutation lock. */
|
|
166
|
+
export function removeTombstone(linkId: string, path: string = tombstonesPath()): boolean {
|
|
167
|
+
const current = readTombstones(path);
|
|
168
|
+
const next = current.tombstones.filter(t => t.linkId !== linkId);
|
|
169
|
+
if (next.length === current.tombstones.length) return false;
|
|
170
|
+
writeTombstones(path, { version: 1, tombstones: next });
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Remove exactly `written`, the tombstone this revoke attempt wrote (matched by its random attempt
|
|
176
|
+
* token), and only while its link still exists (the revoke did not commit). A tombstone another
|
|
177
|
+
* attempt wrote for the same link, even in the same millisecond, is left alone. Callers hold the
|
|
178
|
+
* config mutation lock.
|
|
179
|
+
*/
|
|
180
|
+
export function removeOwnTombstone(written: LinkTombstone, linkExists: boolean, path: string = tombstonesPath()): boolean {
|
|
181
|
+
if (!linkExists || written.attempt === undefined) return false;
|
|
182
|
+
const current = readTombstones(path);
|
|
183
|
+
const found = current.tombstones.find(t => t.linkId === written.linkId);
|
|
184
|
+
if (found?.attempt !== written.attempt) return false;
|
|
185
|
+
return removeTombstone(written.linkId, path);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export type ForgetTombstoneOutcome = "forgotten" | "not_found" | "link_present";
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* A tombstone names this alias (compared without case), so ocx link recover may run against that
|
|
192
|
+
* machine: enrollment and revoke of the alias then take the cross-process alias lock even on a Home
|
|
193
|
+
* without an operation journal. A damaged file answers true, failing toward the lock.
|
|
194
|
+
*/
|
|
195
|
+
export function tombstoneNamesAlias(alias: string, path: string = tombstonesPath()): boolean {
|
|
196
|
+
const wanted = alias.toLowerCase();
|
|
197
|
+
try { return readTombstones(path).tombstones.some(t => t.alias.toLowerCase() === wanted); } catch { return true; }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Drop a tombstone without contacting its machine (ocx link recover --forget, run by a person on the
|
|
202
|
+
* Home). Refused while the link exists, so a forced revoke that wrote its tombstone but has not yet
|
|
203
|
+
* removed the link cannot lose it. Callers hold the config mutation lock, which that revoke's link
|
|
204
|
+
* removal also takes.
|
|
205
|
+
*/
|
|
206
|
+
export function forgetTombstone(linkId: string, linkExists: boolean, path: string = tombstonesPath()): ForgetTombstoneOutcome {
|
|
207
|
+
if (linkExists) return "link_present";
|
|
208
|
+
return removeTombstone(linkId, path) ? "forgotten" : "not_found";
|
|
209
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bytes a Remote Link carried, per link, since this process started counting (#3023 measurement).
|
|
3
|
+
*
|
|
4
|
+
* The counters are plain integer additions on the JavaScript thread: no lock, no log line, no
|
|
5
|
+
* timer and no disk, and no request ever scans the book. A book holds at most `MAX_LINKS` links
|
|
6
|
+
* and never more. A new link takes the place of the link idle longest; when every tracked link has a
|
|
7
|
+
* request in flight there is no place, so that request is not measured and counts only in the
|
|
8
|
+
* book-level `untrackedRequests`. Telemetry never refuses or slows a request.
|
|
9
|
+
*
|
|
10
|
+
* Every time a link's counters start from zero (its first request, or its first after the book forgot
|
|
11
|
+
* it) it gets a new `generation` from one monotonic counter per book; a link the book does not hold
|
|
12
|
+
* reads zeros under the generation of the last forgetting. A process restart starts a new book, whose
|
|
13
|
+
* `epoch` is a fresh random value, so the generations of two process lifetimes never compare equal
|
|
14
|
+
* under it. A consumer subtracts two reads only when both their epoch and their generation match.
|
|
15
|
+
* `since` is the wall-clock time of that start, for people; it can repeat or go backward with the
|
|
16
|
+
* clock, so it is never the comparison key.
|
|
17
|
+
*
|
|
18
|
+
* Two books exist. A Child's link transport (`src/client/link-relay-transport.ts`) counts each
|
|
19
|
+
* request-body chunk or buffered body once its socket write completed and each response-body chunk
|
|
20
|
+
* as it is read off the socket, and ends a request only once both its response and its upload have
|
|
21
|
+
* settled; it is complete only when both finished. A write still pending when a request ends is not
|
|
22
|
+
* counted, even if part of it reached the Home, and that request counts as incomplete, so while
|
|
23
|
+
* `incomplete` > 0 `toHomeBytes` is a lower bound of what crossed, and otherwise every request that
|
|
24
|
+
* ended had its body counted in full. A write still in progress counts only once it completes, so a
|
|
25
|
+
* read taken mid-write lags (it can show `incomplete` 0 while the Home already holds a prefix) and a
|
|
26
|
+
* delta between two reads measures completed writes. A write completes once the operating system
|
|
27
|
+
* accepts it, and how much it accepts at once is the OS's choice: Linux and macOS accept what fits
|
|
28
|
+
* their send buffer, while Windows can take a whole large nonblocking send into its buffer (it took
|
|
29
|
+
* 48 MiB bodies at once on CI), so a body can count in full, and its upload as finished, as soon as
|
|
30
|
+
* it is written, even when the Home reads only part of it. A Home's hub-link listener (`src/server/index/link-relay-sessions.ts`) counts the
|
|
31
|
+
* response-body bytes it streams back and, for requests, each declared Content-Length (it cannot
|
|
32
|
+
* wrap Bun's native request without losing its identity); a request body without one is counted in
|
|
33
|
+
* `toHomeUncounted` instead. A link WebSocket is one request in either book, in the same units: message payload bytes
|
|
34
|
+
* each way (the Child once its socket write completed and per complete message from the Home; the Home per message
|
|
35
|
+
* received and per message Bun took for the socket). The Home counts it complete when any close frame ended it; the Child
|
|
36
|
+
* also counts its own overload, binary and protocol closes as incomplete. Neither counts HTTP headers, WebSocket framing or control
|
|
37
|
+
* frames, the relay-auth challenge, SSH or TCP framing, or what any relay between the machines adds.
|
|
38
|
+
*/
|
|
39
|
+
export const MAX_LINKS = 256;
|
|
40
|
+
|
|
41
|
+
export interface LinkTrafficCounters {
|
|
42
|
+
/** When this link's counters last started from zero (ISO). For people; compare on `generation`. */
|
|
43
|
+
since: string;
|
|
44
|
+
/** Random per book: a new value after every process restart. Compare two reads only when it matches. */
|
|
45
|
+
epoch: string;
|
|
46
|
+
/** Changes every time this link's counters start from zero within one epoch; compare two reads only when epoch and generation match. */
|
|
47
|
+
generation: number;
|
|
48
|
+
/** Relayed requests on this link, a link socket counting as one. */
|
|
49
|
+
requests: number;
|
|
50
|
+
/**
|
|
51
|
+
* Of those, requests that ended before their response body did (abort, cancel, error, refusal),
|
|
52
|
+
* and on a Child also requests whose request-body upload did not finish; a link socket counts when
|
|
53
|
+
* it ended without a close frame (and on a Child also after its own overload, binary or protocol close).
|
|
54
|
+
*/
|
|
55
|
+
incomplete: number;
|
|
56
|
+
/**
|
|
57
|
+
* Request-body bytes toward the Home, or a link socket's message payloads toward it. Child: bytes
|
|
58
|
+
* whose socket write completed, a lower bound while `incomplete` > 0. Home: the declared
|
|
59
|
+
* Content-Length of each relayed request, or the payload of each message a link socket received.
|
|
60
|
+
*/
|
|
61
|
+
toHomeBytes: number;
|
|
62
|
+
/** Response-body bytes from the Home, or a link socket's message payloads from it. */
|
|
63
|
+
fromHomeBytes: number;
|
|
64
|
+
/** How toHomeBytes was measured for relayed HTTP: socket writes completed (Child) or declared Content-Length (Home); a link socket's message payloads count the same on both. */
|
|
65
|
+
toHomeSource: "relayed" | "content-length";
|
|
66
|
+
/** Requests whose body bytes toHomeBytes could not include (a Home request without Content-Length). */
|
|
67
|
+
toHomeUncounted: number;
|
|
68
|
+
/** Book-level, the same on every row: requests on any link that were not measured because the book was full. */
|
|
69
|
+
untrackedRequests: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** One relayed request. Every method is cheap; `end` is idempotent and decides only `incomplete`. */
|
|
73
|
+
export interface LinkTrafficFlow {
|
|
74
|
+
toHome(bytes: number): void;
|
|
75
|
+
fromHome(bytes: number): void;
|
|
76
|
+
uncounted(): void;
|
|
77
|
+
/** complete = the response body reached its end (or there was none to read). */
|
|
78
|
+
end(complete: boolean): void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface LinkTrafficBook {
|
|
82
|
+
/** Start counting one request on `linkId`. */
|
|
83
|
+
begin(linkId: string): LinkTrafficFlow;
|
|
84
|
+
/** This link's counters; zeros for a link the book does not hold. */
|
|
85
|
+
snapshot(linkId: string): LinkTrafficCounters;
|
|
86
|
+
/** How many links the book holds now; never more than MAX_LINKS. */
|
|
87
|
+
linkCount(): number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface Entry {
|
|
91
|
+
since: string;
|
|
92
|
+
generation: number;
|
|
93
|
+
inFlight: number;
|
|
94
|
+
requests: number; incomplete: number; toHomeBytes: number; fromHomeBytes: number; toHomeUncounted: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function addable(bytes: number): number {
|
|
98
|
+
return Number.isSafeInteger(bytes) && bytes > 0 ? bytes : 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const UNMEASURED: LinkTrafficFlow = { toHome() {}, fromHome() {}, uncounted() {}, end() {} };
|
|
102
|
+
|
|
103
|
+
function randomEpoch(): string {
|
|
104
|
+
const bytes = crypto.getRandomValues(new Uint8Array(8));
|
|
105
|
+
return Array.from(bytes, byte => byte.toString(16).padStart(2, "0")).join("");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function createLinkTrafficBook(
|
|
109
|
+
toHomeSource: LinkTrafficCounters["toHomeSource"],
|
|
110
|
+
deps: { now?: () => number } = {},
|
|
111
|
+
): LinkTrafficBook {
|
|
112
|
+
const now = deps.now ?? Date.now;
|
|
113
|
+
const epoch = randomEpoch();
|
|
114
|
+
const started = new Date(now()).toISOString();
|
|
115
|
+
let sequence = 0;
|
|
116
|
+
let forgotten = { since: started, generation: 0 };
|
|
117
|
+
let untrackedRequests = 0;
|
|
118
|
+
const entries = new Map<string, Entry>();
|
|
119
|
+
// Links with no request in flight, least recently active first: the next to forget is always the
|
|
120
|
+
// first key, so making room is O(1) and never scans the book.
|
|
121
|
+
const idle = new Map<string, Entry>();
|
|
122
|
+
const room = (): boolean => {
|
|
123
|
+
if (entries.size < MAX_LINKS) return true;
|
|
124
|
+
const oldest = idle.keys().next();
|
|
125
|
+
if (oldest.done) return false;
|
|
126
|
+
entries.delete(oldest.value);
|
|
127
|
+
idle.delete(oldest.value);
|
|
128
|
+
forgotten = { since: new Date(now()).toISOString(), generation: ++sequence };
|
|
129
|
+
return true;
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
begin(linkId) {
|
|
133
|
+
let entry = entries.get(linkId);
|
|
134
|
+
if (!entry) {
|
|
135
|
+
if (!room()) { untrackedRequests += 1; return UNMEASURED; }
|
|
136
|
+
entry = { since: new Date(now()).toISOString(), generation: ++sequence, inFlight: 0,
|
|
137
|
+
requests: 0, incomplete: 0, toHomeBytes: 0, fromHomeBytes: 0, toHomeUncounted: 0 };
|
|
138
|
+
entries.set(linkId, entry);
|
|
139
|
+
}
|
|
140
|
+
const counted = entry;
|
|
141
|
+
counted.requests += 1;
|
|
142
|
+
counted.inFlight += 1;
|
|
143
|
+
idle.delete(linkId);
|
|
144
|
+
let ended = false;
|
|
145
|
+
return {
|
|
146
|
+
toHome(bytes) { counted.toHomeBytes += addable(bytes); },
|
|
147
|
+
fromHome(bytes) { counted.fromHomeBytes += addable(bytes); },
|
|
148
|
+
uncounted() { counted.toHomeUncounted += 1; },
|
|
149
|
+
end(complete) {
|
|
150
|
+
if (ended) return;
|
|
151
|
+
ended = true;
|
|
152
|
+
if (!complete) counted.incomplete += 1;
|
|
153
|
+
counted.inFlight -= 1;
|
|
154
|
+
if (counted.inFlight === 0) idle.set(linkId, counted);
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
snapshot(linkId) {
|
|
159
|
+
const entry = entries.get(linkId);
|
|
160
|
+
return {
|
|
161
|
+
since: entry?.since ?? forgotten.since,
|
|
162
|
+
epoch,
|
|
163
|
+
generation: entry?.generation ?? forgotten.generation,
|
|
164
|
+
requests: entry?.requests ?? 0,
|
|
165
|
+
incomplete: entry?.incomplete ?? 0,
|
|
166
|
+
toHomeBytes: entry?.toHomeBytes ?? 0,
|
|
167
|
+
fromHomeBytes: entry?.fromHomeBytes ?? 0,
|
|
168
|
+
toHomeSource,
|
|
169
|
+
toHomeUncounted: entry?.toHomeUncounted ?? 0,
|
|
170
|
+
untrackedRequests,
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
linkCount: () => entries.size,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The Child relay's book for this process. A Home's listener owns its own. */
|
|
178
|
+
export const childLinkTraffic: LinkTrafficBook = createLinkTrafficBook("relayed");
|
package/src/link/tunnel-state.ts
CHANGED
|
@@ -71,11 +71,17 @@ export const CLIENT_TUNNEL_RETRY_POLICY: TunnelRetryPolicy = {
|
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* The Home's `-R` supervisor
|
|
75
|
-
*
|
|
76
|
-
*
|
|
74
|
+
* The Home's `-R` supervisor retries a timed-out or refused-forward Child every minute, flat: a
|
|
75
|
+
* laptop Child that slept reconnects within about a minute of waking instead of waiting out a
|
|
76
|
+
* backoff of up to five minutes (#8470). A sleeping host never reaches sshd, so those retries add
|
|
77
|
+
* no authentication attempts. Auth keeps its five-minute start (the cap is
|
|
78
|
+
* `max(base, maxRetryDelayMs)`), so no more than 12 auth attempts reach the Child's sshd in an hour,
|
|
79
|
+
* and a changed host key is still never retried. The Child's own tunnel keeps the doubling policy.
|
|
77
80
|
*/
|
|
78
|
-
export const HOME_TUNNEL_RETRY_POLICY: TunnelRetryPolicy =
|
|
81
|
+
export const HOME_TUNNEL_RETRY_POLICY: TunnelRetryPolicy = {
|
|
82
|
+
retryFailedAfterMs: { timeout: 60_000, forward: 60_000, auth: 5 * 60_000 },
|
|
83
|
+
maxRetryDelayMs: 60_000,
|
|
84
|
+
};
|
|
79
85
|
|
|
80
86
|
export const IDLE: TunnelState = { kind: "idle" };
|
|
81
87
|
|