@bitkyc08/opencodex 2.100.5 → 2.100.6
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 +2 -0
- package/gui/dist/assets/App-BI8LQ7Qk.css +1 -0
- package/gui/dist/assets/App-CsZ1Gr7S.js +60 -0
- package/gui/dist/assets/Tray-CVqm4S4W.js +1 -0
- package/gui/dist/assets/brand-mark-BebhnAtV.js +1 -0
- package/gui/dist/assets/index-BtwVlpeQ.css +2 -0
- package/gui/dist/assets/index-CEeMegqE.js +138 -0
- package/gui/dist/assets/{segment-thumb-features-Bquysdn5.js → segment-thumb-features-COdzmORE.js} +1 -1
- package/gui/dist/classic/assets/App-BJgUWNJ8.js +59 -0
- package/gui/dist/classic/assets/App-CoiVLRW3.css +1 -0
- package/gui/dist/classic/assets/Tray-BDlcOLDK.js +1 -0
- package/gui/dist/classic/assets/index-B9Jgli_W.js +138 -0
- package/gui/dist/classic/assets/usage-companion-chart-vbzDcND0.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/Cargo.lock +62 -0
- package/native/ocx-child/Cargo.toml +1 -0
- package/native/ocx-child/src/journal.rs +32 -10
- package/native/ocx-child/src/state.rs +2 -1
- package/native/ocx-child/src/toml_surgeon.rs +183 -72
- package/package.json +2 -2
- package/src/adapters/agy-acp/acp.ts +202 -0
- package/src/adapters/agy-acp/adapter.ts +554 -0
- package/src/adapters/agy-acp/binary.ts +79 -0
- package/src/adapters/agy-acp/options.ts +163 -0
- package/src/adapters/agy-acp/output-redaction.ts +270 -0
- package/src/adapters/agy-acp/policy.ts +105 -0
- package/src/adapters/agy-acp/process.ts +218 -0
- package/src/adapters/anthropic/account-metadata.ts +4 -1
- package/src/adapters/anthropic/advisor-tool.ts +43 -9
- package/src/adapters/anthropic/client-identity.ts +2 -0
- package/src/adapters/anthropic.ts +102 -14
- package/src/adapters/antigravity-refusal.ts +5 -1
- package/src/adapters/base.ts +25 -2
- package/src/adapters/claude-cli/adapter.ts +1 -0
- package/src/adapters/claude-cli/usage-admission.ts +12 -9
- package/src/adapters/codebuddy/adapter.ts +1 -0
- package/src/adapters/command-code.ts +2 -2
- package/src/adapters/cursor/http1-bidi.ts +7 -2
- package/src/adapters/cursor/live-transport.ts +2 -0
- package/src/adapters/cursor/request-builder.ts +4 -4
- package/src/adapters/cursor/tool-naming.ts +5 -5
- package/src/adapters/cursor/transport-retry.ts +14 -8
- package/src/adapters/cursor/transport.ts +2 -0
- package/src/adapters/cursor.ts +8 -2
- package/src/adapters/google-error-details.ts +105 -0
- package/src/adapters/google-errors.ts +183 -31
- package/src/adapters/google-http.ts +66 -22
- package/src/adapters/google-truncation.ts +48 -3
- package/src/adapters/google-vertex-endpoint.ts +12 -1
- package/src/adapters/google.ts +54 -26
- package/src/adapters/kiro/adapter.ts +39 -38
- package/src/adapters/kiro/stream.ts +59 -9
- package/src/adapters/kiro-retry.ts +5 -3
- package/src/adapters/m365-copilot/LICENSE +21 -0
- package/src/adapters/m365-copilot/fenced.ts +745 -0
- package/src/adapters/m365-copilot/images.ts +89 -0
- package/src/adapters/m365-copilot/tools.ts +284 -0
- package/src/adapters/m365-copilot/transport.ts +232 -0
- package/src/adapters/m365-copilot.ts +143 -0
- package/src/adapters/openai-chat/tool-schema.ts +2 -2
- package/src/adapters/openai-responses/passthrough.ts +1 -0
- package/src/adapters/openai-responses/reasoning.ts +23 -3
- package/src/adapters/physical-send.ts +11 -4
- package/src/adapters/qoder/adapter.ts +17 -3
- package/src/adapters/registry.ts +15 -1
- package/src/adapters/zed.ts +2 -1
- package/src/advisor/consult.ts +1 -0
- package/src/bridge/response-json.ts +6 -2
- package/src/bridge/sse.ts +21 -9
- package/src/chat/inbound.ts +11 -8
- package/src/chat/outbound.ts +28 -7
- package/src/claude/context-windows.ts +32 -8
- package/src/claude/desktop-3p.ts +18 -14
- package/src/claude/desktop-picker-platform.ts +1 -1
- package/src/claude/desktop-picker.ts +3 -3
- package/src/claude/inbound-content-options.ts +11 -1
- package/src/claude/intercept/picker-ca-cleanup.ts +17 -5
- package/src/claude/intercept/picker-ca.ts +162 -27
- package/src/claude/intercept/picker-trust-linux.ts +411 -0
- package/src/claude/intercept/picker-trust.ts +35 -3
- package/src/claude/intercept/runtime.ts +2 -2
- package/src/claude/subagent-force-status.ts +24 -5
- package/src/claude/subscription-reserve.ts +87 -0
- package/src/cli/account-api.ts +3 -0
- package/src/cli/account-auth.ts +65 -11
- package/src/cli/account-extended.ts +1 -1
- package/src/cli/account-next-actions.ts +4 -1
- package/src/cli/account-policy-dto.ts +1 -1
- package/src/cli/account-policy.ts +6 -3
- package/src/cli/account-probe.ts +66 -0
- package/src/cli/account.ts +8 -2
- package/src/cli/capabilities-accounts.ts +8 -1
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-base.ts +4 -4
- package/src/cli/capabilities-integrations.ts +44 -4
- package/src/cli/capabilities-provider-models.ts +6 -0
- package/src/cli/claude-context-settings.ts +60 -0
- package/src/cli/claude-desktop.ts +2 -2
- package/src/cli/claude.ts +15 -7
- package/src/cli/client-start-fence.ts +64 -1
- package/src/cli/combo-result.ts +1 -0
- package/src/cli/combo-stats.ts +1 -1
- package/src/cli/combo.ts +19 -2
- package/src/cli/config-command.ts +21 -8
- package/src/cli/connect.ts +16 -0
- package/src/cli/cross-home-owner.ts +65 -18
- package/src/cli/dispatch.ts +4 -0
- package/src/cli/gateway-client-command.ts +128 -0
- package/src/cli/index.ts +98 -97
- package/src/cli/init.ts +20 -4
- package/src/cli/integrations.ts +23 -3
- package/src/cli/launcher-context.ts +12 -1
- package/src/cli/link.ts +24 -5
- package/src/cli/models-runtime-subcommands.ts +1 -0
- package/src/cli/models-runtime.ts +32 -0
- package/src/cli/start-owner-fence.ts +5 -2
- package/src/cli/status.ts +3 -3
- package/src/cli/stop-client-process.ts +51 -0
- package/src/cli/stop-restore.ts +383 -36
- package/src/cli/sync-command.ts +2 -2
- package/src/cli/uninstall-client-state.ts +7 -0
- package/src/client/connect.ts +72 -13
- package/src/client/hub-client.ts +38 -0
- package/src/client/hub-relay.ts +61 -36
- package/src/client/hub-session.ts +106 -0
- package/src/client/lifecycle-lock.ts +6 -1
- package/src/client/link-relay.ts +2 -1
- package/src/client/machine-listener.ts +60 -1
- package/src/client/runtime-restart.ts +1 -0
- package/src/client/runtime.ts +104 -34
- package/src/client/state.ts +11 -0
- package/src/client/stop-darwin-process.ts +73 -0
- package/src/client/stop-file-routing.ts +49 -0
- package/src/client/stop-native-handoff.ts +108 -0
- package/src/client/stop-routing.ts +41 -7
- package/src/client/stop-teardown-owner.ts +173 -0
- package/src/client/sync-runtime.ts +23 -4
- package/src/clients/config-export/opencode-wire.ts +24 -0
- package/src/clients/config-export.ts +28 -19
- package/src/codex/auth-api/login-flow.ts +68 -33
- package/src/codex/auth-api/main-account-probe.ts +3 -3
- package/src/codex/auth-api/pool-quota-probe.ts +8 -7
- package/src/codex/auth-api/routes.ts +1 -1
- package/src/codex/catalog/aggregation.ts +22 -10
- package/src/codex/catalog/gather-capture.ts +11 -2
- package/src/codex/catalog/m365-copilot-models.ts +52 -0
- package/src/codex/catalog/provider-models.ts +126 -53
- package/src/codex/catalog/routed-gather.ts +26 -12
- package/src/codex/catalog-admission.ts +4 -6
- package/src/codex/catalog-auto-refresh.ts +4 -2
- package/src/codex/catalog-self-heal.ts +4 -2
- package/src/codex/control-plane-models.ts +6 -0
- package/src/codex/convergence.ts +10 -0
- package/src/codex/desktop-app/picker-freshness.ts +3 -14
- package/src/codex/desktop-app/types.ts +6 -0
- package/src/codex/desktop-app/windows-command-payload.ts +9 -0
- package/src/codex/desktop-app/windows.ts +20 -12
- package/src/codex/desktop-compatibility/installed-build.ts +61 -58
- package/src/codex/desktop-compatibility/runtime-ownership.ts +11 -5
- package/src/codex/desktop-compatibility/runtime.ts +51 -14
- package/src/codex/desktop-compatibility/windows-activation-source.ts +28 -13
- package/src/codex/desktop-compatibility/windows-package-command.ts +73 -33
- package/src/codex/desktop-compatibility/windows-package-launch.ts +41 -9
- package/src/codex/desktop-compatibility/windows-package-proof.ts +104 -0
- package/src/codex/inject/config-toml.ts +67 -73
- package/src/codex/inject/plan.ts +11 -10
- package/src/codex/inject/remove.ts +4 -1
- package/src/codex/inject.ts +1 -0
- package/src/codex/journal-config-restore.ts +31 -4
- package/src/codex/journal.ts +16 -4
- package/src/codex/model-cache.ts +98 -27
- package/src/codex/native-residue.ts +14 -13
- package/src/codex/paths.ts +65 -28
- package/src/codex/quota-observation-freshness.ts +4 -0
- package/src/codex/quota.ts +71 -8
- package/src/codex/routing/selection.ts +32 -8
- package/src/combos/capability-policy.ts +31 -0
- package/src/combos/failover.ts +82 -74
- package/src/combos/identifiers.ts +2 -2
- package/src/combos/index.ts +3 -0
- package/src/combos/jev-model-backend.ts +12 -4
- package/src/combos/jev-session-pin-config.ts +22 -9
- package/src/combos/jev.ts +15 -4
- package/src/combos/request-capability.ts +214 -0
- package/src/combos/request.ts +22 -15
- package/src/combos/resolve.ts +5 -2
- package/src/combos/suggestion-channel.ts +89 -0
- package/src/combos/types.ts +14 -1
- package/src/config/account-auto-pause-revisions.ts +33 -10
- package/src/config/atomic-write.ts +1 -1
- package/src/config/codex-ws-incremental-setting.ts +34 -0
- package/src/config/diagnostics.ts +47 -8
- package/src/config/live-topology.ts +4 -2
- package/src/config/load-degrade.ts +96 -2
- package/src/config/mutation-lock.ts +7 -3
- package/src/config/paths.ts +3 -0
- package/src/config/pending-teardown.ts +19 -3
- package/src/config/process-state.ts +30 -12
- package/src/config/provider-validation.ts +10 -0
- package/src/config/salvage.ts +2 -2
- package/src/config/schema/account-auto-pause.ts +15 -1
- package/src/config/schema/agy-acp-references.ts +257 -0
- package/src/config/schema/config-schema.ts +32 -0
- package/src/config/schema/leaf-validators.ts +42 -0
- package/src/config/schema/subscription-reserve.ts +33 -0
- package/src/config/windows-process-command-line.ts +27 -9
- package/src/config.ts +6 -0
- package/src/generated/compatibility-version.json +806 -402
- package/src/images/loop.ts +79 -39
- package/src/integrations/catalog-refresh.ts +19 -1
- package/src/integrations/gateway-clients/agy.ts +340 -0
- package/src/integrations/gateway-clients/antigravity.ts +224 -0
- package/src/integrations/gateway-clients/index.ts +89 -0
- package/src/integrations/gateway-clients/io.ts +278 -0
- package/src/integrations/gateway-clients/types.ts +80 -0
- package/src/integrations/route-intent-disconnect.ts +37 -21
- package/src/lib/app-owned-memory-stores.ts +9 -0
- package/src/lib/cloud-code-appeal-link.ts +30 -0
- package/src/lib/errors.ts +32 -0
- package/src/lib/executor-physical-send-receipt.ts +42 -0
- package/src/lib/failure-detail.ts +1 -0
- package/src/lib/gcp-adc.ts +5 -0
- package/src/lib/http-date.ts +91 -0
- package/src/lib/lab-passive-linker-registration.ts +2 -1
- package/src/lib/local-chat-completion.ts +13 -3
- package/src/lib/local-internal-call-capability.ts +1 -3
- package/src/lib/messages-error-body.ts +2 -1
- package/src/lib/outbound-credential-registry.ts +40 -4
- package/src/lib/pinned-http.ts +7 -2
- package/src/lib/process-control.ts +1 -0
- package/src/lib/provider-egress.ts +16 -0
- package/src/lib/provider-outbound.ts +3 -0
- package/src/lib/redact-folding.ts +12 -3
- package/src/lib/redact.ts +37 -19
- package/src/lib/request-execution-budget.ts +241 -32
- package/src/lib/request-peer-scope.ts +64 -0
- package/src/lib/response-send-readings.ts +41 -0
- package/src/lib/state-store-registrations.ts +5 -0
- package/src/lib/tool-envelope-echo-filter.ts +33 -5
- package/src/lib/upstream-condition.ts +10 -3
- package/src/lib/upstream-retry.ts +95 -20
- package/src/lib/windows-secret-acl.ts +24 -7
- package/src/link/child-activity.ts +60 -4
- package/src/link/codex-settings.ts +2 -1
- package/src/link/relay-auth.ts +1 -0
- package/src/link/route-rounds.ts +32 -9
- package/src/link/status-projection.ts +42 -5
- package/src/link/supervisor.ts +96 -11
- package/src/link/tunnel-history.ts +5 -0
- package/src/oauth/account-auto-pause-policy.ts +72 -19
- package/src/oauth/account-auto-pause.ts +40 -16
- package/src/oauth/anthropic-account-refusal.ts +7 -0
- package/src/oauth/anthropic-continuity.ts +70 -9
- package/src/oauth/anthropic-identity.ts +75 -11
- package/src/oauth/anthropic-login-slot.ts +258 -0
- package/src/oauth/anthropic-routing.ts +24 -9
- package/src/oauth/anthropic-send-ownership.ts +4 -3
- package/src/oauth/anthropic.ts +30 -11
- package/src/oauth/health.ts +7 -2
- package/src/oauth/index.ts +50 -48
- package/src/oauth/key-providers.ts +2 -0
- package/src/oauth/login-cli.ts +11 -0
- package/src/oauth/login-flow-state.ts +10 -4
- package/src/oauth/m365-copilot-browser.ts +222 -0
- package/src/oauth/m365-copilot-web-session.ts +25 -0
- package/src/oauth/m365-copilot.ts +57 -0
- package/src/oauth/model-discovery-auth.ts +5 -0
- package/src/oauth/plan.ts +44 -0
- package/src/oauth/pool-kernel.ts +22 -8
- package/src/oauth/pool-settings-capability.ts +14 -3
- package/src/oauth/reauth-precheck.ts +27 -0
- package/src/oauth/store-anthropic-instance.ts +3 -1
- package/src/oauth/store.ts +121 -23
- package/src/oauth/types.ts +27 -2
- package/src/protocols/codecs/chat-ir.ts +7 -4
- package/src/protocols/codecs/gemini-interactions.ts +770 -0
- package/src/protocols/codecs/gemini.ts +470 -0
- package/src/protocols/contract.ts +2 -0
- package/src/protocols/encoders/adapter-events.ts +5 -3
- package/src/protocols/encoders/chat.ts +23 -7
- package/src/protocols/settings.ts +3 -0
- package/src/providers/account-quota-disk.ts +26 -8
- package/src/providers/api-key-pause.ts +2 -2
- package/src/providers/api-key-response-ownership.ts +14 -4
- package/src/providers/claude-cli-usage-state.ts +1 -0
- package/src/providers/claude-cli-usage.ts +24 -7
- package/src/providers/default-aliases.ts +11 -5
- package/src/providers/derive.ts +5 -1
- package/src/providers/fastwire.ts +6 -5
- package/src/providers/free-directory.ts +2 -2
- package/src/providers/google-vertex-location.ts +2 -1
- package/src/providers/google-vertex-model-discovery.ts +22 -0
- package/src/providers/key-failover.ts +18 -23
- package/src/providers/m365-copilot-discovery-fetch.ts +17 -0
- package/src/providers/m365-copilot-discovery.ts +68 -0
- package/src/providers/m365-copilot-models.ts +32 -0
- package/src/providers/model-rename-fields.ts +6 -0
- package/src/providers/new-model-policy-runtime.ts +27 -6
- package/src/providers/openai-forward-destination.ts +19 -0
- package/src/providers/openai-tiers-destination.ts +3 -19
- package/src/providers/quota/account-cache.ts +183 -27
- package/src/providers/quota/anthropic-account-quota.ts +21 -17
- package/src/providers/quota/anthropic-cooldown-recovery.ts +57 -27
- package/src/providers/quota/anthropic-decision-windows.ts +7 -3
- package/src/providers/quota/anthropic-usage-windows.ts +34 -4
- package/src/providers/quota/antigravity-account-probe.ts +165 -0
- package/src/providers/quota/antigravity.ts +71 -3
- package/src/providers/quota/vendor-probes-oauth.ts +52 -28
- package/src/providers/quota-decision-publication.ts +1 -1
- package/src/providers/quota-decision-snapshot.ts +4 -1
- package/src/providers/quota-types.ts +2 -0
- package/src/providers/quota.ts +8 -7
- package/src/providers/registry/agy-acp-models.ts +3 -0
- package/src/providers/registry/entries-core.ts +9 -0
- package/src/providers/registry/entries-extended.ts +60 -0
- package/src/providers/registry/model-seeds.ts +51 -0
- package/src/providers/request-pacing.ts +37 -7
- package/src/providers/service-tier.ts +2 -0
- package/src/providers/xai-privacy-mode.ts +52 -0
- package/src/remote/hub-management-relay.ts +74 -0
- package/src/responses/id-limits.ts +2 -0
- package/src/responses/input-media.ts +15 -3
- package/src/responses/parser-tools.ts +74 -11
- package/src/responses/parser.ts +16 -14
- package/src/responses/provider-opaque-metadata.ts +10 -0
- package/src/responses/reasoning-envelope.ts +3 -0
- package/src/responses/schema.ts +2 -3
- package/src/responses/spill-store.ts +5 -3
- package/src/responses/state/connection-scope.ts +232 -0
- package/src/responses/state/entry-types.ts +47 -0
- package/src/responses/state/snapshot-codec.ts +75 -14
- package/src/responses/state/snapshot-select.ts +2 -0
- package/src/responses/state/spill-codec.ts +59 -0
- package/src/responses/state/spill-queue.ts +11 -2
- package/src/responses/state.ts +178 -159
- package/src/router.ts +2 -6
- package/src/routing/compatibility/behavior.ts +6 -2
- package/src/routing/compatibility/subject.ts +17 -12
- package/src/routing/machine-weighted-routing.ts +58 -0
- package/src/server/advisor-admission-scope.ts +15 -7
- package/src/server/auth-cors.ts +27 -0
- package/src/server/chat-completions.ts +37 -17
- package/src/server/chat-native-eligibility.ts +21 -0
- package/src/server/chat-native.ts +15 -6
- package/src/server/claude-messages.ts +54 -6
- package/src/server/credential-recovery-attempt.ts +32 -0
- package/src/server/effort-policy.ts +6 -3
- package/src/server/gemini-inbound.ts +267 -0
- package/src/server/gemini-interactions-inbound.ts +229 -0
- package/src/server/gemini-interactions-store.ts +129 -0
- package/src/server/gemini-native-catalog.ts +64 -0
- package/src/server/gemini-native-log.ts +33 -0
- package/src/server/gemini-native-paths.ts +88 -0
- package/src/server/gemini-native-wire.ts +201 -0
- package/src/server/gemini-native.ts +218 -0
- package/src/server/grok-upstream-envelope-echo.ts +8 -2
- package/src/server/hub-relay-auth.ts +87 -0
- package/src/server/hub-usage-windows.ts +135 -0
- package/src/server/hub-usage.ts +16 -3
- package/src/server/inbound-body-admission.ts +2 -1
- package/src/server/index/anthropic-model-listing.ts +75 -0
- package/src/server/index/gemini-routes.ts +147 -0
- package/src/server/index/link-management.ts +3 -22
- package/src/server/index/link-relay-sessions.ts +71 -13
- package/src/server/index/link-websocket.ts +2 -0
- package/src/server/index/passive-management-read.ts +55 -0
- package/src/server/index/serve-options.ts +93 -107
- package/src/server/index/websocket-handler.ts +15 -2
- package/src/server/index.ts +10 -0
- package/src/server/inference/client-encoder-delivery.ts +2 -1
- package/src/server/inference/context.ts +33 -6
- package/src/server/management/agent-settings-routes.ts +33 -16
- package/src/server/management/claude-code-settings-patch.ts +6 -0
- package/src/server/management/combo-routes.ts +21 -1
- package/src/server/management/combo-suggestion-routes.ts +212 -0
- package/src/server/management/config-routes.ts +12 -4
- package/src/server/management/context.ts +2 -0
- package/src/server/management/gateway-client-routes.ts +62 -0
- package/src/server/management/integration-routes.ts +5 -0
- package/src/server/management/link-routes.ts +5 -1
- package/src/server/management/m365-copilot-provider-probe.ts +23 -0
- package/src/server/management/model-routes.ts +32 -2
- package/src/server/management/model-rows.ts +36 -3
- package/src/server/management/oauth-account-routes.ts +68 -15
- package/src/server/management/protocol-settings-patch.ts +1 -0
- package/src/server/management/provider-omitted-fields.ts +25 -0
- package/src/server/management/provider-overwrite-carry.ts +33 -8
- package/src/server/management/provider-routes.ts +10 -16
- package/src/server/management/request-history-routes.ts +2 -2
- package/src/server/management/route-registry.ts +10 -0
- package/src/server/management/shared.ts +118 -30
- package/src/server/management/sibling-guard.ts +2 -1
- package/src/server/management/system-routes.ts +6 -0
- package/src/server/management-auth.ts +8 -1
- package/src/server/messages-native-scope.ts +19 -0
- package/src/server/messages-native.ts +156 -59
- package/src/server/messages-shared.ts +6 -0
- package/src/server/models-capabilities.ts +24 -0
- package/src/server/native-chat-bridge.ts +259 -0
- package/src/server/ollama-inbound.ts +36 -184
- package/src/server/passive-route-linker.ts +3 -1
- package/src/server/port-reclaim.ts +48 -4
- package/src/server/proxy-liveness.ts +79 -22
- package/src/server/relay.ts +16 -9
- package/src/server/request-log-account-rotation.ts +2 -1
- package/src/server/request-log-attempt-recovery.ts +24 -2
- package/src/server/request-log-attempt-usage.ts +5 -4
- package/src/server/request-log-committed-terminal.ts +87 -0
- package/src/server/request-log-failure-attribution.ts +3 -3
- package/src/server/request-log-failure-detail.ts +34 -0
- package/src/server/request-log-key-failure.ts +27 -0
- package/src/server/request-log-terminal-status.ts +25 -12
- package/src/server/request-log.ts +59 -63
- package/src/server/responses/adapter-continuation.ts +77 -44
- package/src/server/responses/adapter-delivery.ts +47 -22
- package/src/server/responses/adapter-dispatch.ts +150 -149
- package/src/server/responses/advisor-retention.ts +12 -4
- package/src/server/responses/advisor-slot.ts +97 -2
- package/src/server/responses/agent-task-recovery.ts +44 -11
- package/src/server/responses/agy-acp-preflight.ts +41 -0
- package/src/server/responses/anthropic-image-context.ts +44 -0
- package/src/server/responses/antigravity-validation-refusal.ts +25 -1
- package/src/server/responses/buffered-sse-json.ts +18 -1
- package/src/server/responses/codex-ws-correlation.ts +5 -2
- package/src/server/responses/codex-ws-exchange.ts +91 -8
- package/src/server/responses/codex-ws-incremental.ts +136 -0
- package/src/server/responses/codex-ws-pool.ts +22 -8
- package/src/server/responses/codex-ws-request.ts +5 -0
- package/src/server/responses/codex-ws-send-accounting.ts +8 -0
- package/src/server/responses/codex-ws-session.ts +14 -0
- package/src/server/responses/codex-ws-wire.ts +44 -22
- package/src/server/responses/combo-admission-snapshot.ts +93 -0
- package/src/server/responses/combo-required-tool-stream.ts +16 -4
- package/src/server/responses/combo-selection-keepalive.ts +5 -0
- package/src/server/responses/combo-stream-preflight.ts +182 -73
- package/src/server/responses/compact-response-body.ts +27 -0
- package/src/server/responses/compact.ts +174 -121
- package/src/server/responses/compaction-recovery.ts +7 -0
- package/src/server/responses/core-codex-account.ts +88 -62
- package/src/server/responses/core-combo-failure.ts +15 -0
- package/src/server/responses/core-combo-native.ts +12 -1
- package/src/server/responses/core-combo.ts +340 -94
- package/src/server/responses/core-normalize.ts +19 -12
- package/src/server/responses/core-opaque-recovery.ts +15 -4
- package/src/server/responses/core-options.ts +50 -5
- package/src/server/responses/core-pipeline.ts +11 -0
- package/src/server/responses/core.ts +7 -1
- package/src/server/responses/empty-completion-guard.ts +21 -7
- package/src/server/responses/estimated-usage.ts +2 -1
- package/src/server/responses/fetch-helpers.ts +95 -19
- package/src/server/responses/history-slim.ts +204 -0
- package/src/server/responses/hosted-advisor-spend.ts +49 -0
- package/src/server/responses/image-context-recovery.ts +199 -0
- package/src/server/responses/input-admission.ts +36 -11
- package/src/server/responses/jev-model-invoke.ts +23 -16
- package/src/server/responses/non-replayable-error.ts +12 -2
- package/src/server/responses/passthrough-build-error.ts +5 -3
- package/src/server/responses/passthrough-delivery.ts +74 -33
- package/src/server/responses/passthrough-dispatch.ts +170 -197
- package/src/server/responses/policy-fallback.ts +7 -2
- package/src/server/responses/policy-request-scope.ts +36 -2
- package/src/server/responses/replay-owner.ts +20 -0
- package/src/server/responses/request-prepare.ts +97 -16
- package/src/server/responses/request-send-budget.ts +97 -25
- package/src/server/responses/request-sidecar-auth.ts +138 -65
- package/src/server/responses/request-spend-target.ts +13 -1
- package/src/server/responses/request-spend.ts +228 -47
- package/src/server/responses/request-transport.ts +395 -70
- package/src/server/responses/run-turn-execution.ts +40 -9
- package/src/server/responses/sidecar-execution.ts +214 -67
- package/src/server/responses/sidecar-send-budget.ts +9 -9
- package/src/server/responses/terminal-guard.ts +35 -9
- package/src/server/responses/ws-upstream.ts +27 -6
- package/src/server/responses-phase-inference.ts +32 -9
- package/src/server/responses-terminal-repair.ts +14 -35
- package/src/server/system-env.ts +8 -5
- package/src/server/ws-bridge.ts +23 -17
- package/src/service/health-sentinel-linux.ts +16 -7
- package/src/service/systemd.ts +11 -2
- package/src/service/windows-checked-stop-live.ts +60 -55
- package/src/service/windows-checked-stop.ts +29 -11
- package/src/service/windows-guarded-manager.ts +14 -26
- package/src/service/windows-process-evidence.ts +82 -74
- package/src/service/windows-process-native.ts +69 -20
- package/src/service/windows-service-stop.ts +14 -12
- package/src/service/windows-stop-binding.ts +14 -5
- package/src/service/windows-stop-confirm.ts +1 -1
- package/src/service/windows-task-instance-stop.ts +98 -0
- package/src/service/windows-taskxml.ts +30 -7
- package/src/sidecar/anthropic-binding.ts +1 -1
- package/src/stall-timeout.ts +30 -0
- package/src/telemetry/aggregate.ts +6 -3
- package/src/types/account-auto-pause.ts +19 -1
- package/src/types/accounts.ts +21 -0
- package/src/types/anthropic-account-pool.ts +1 -1
- package/src/types/combo-capability-policy.ts +19 -0
- package/src/types/config.ts +22 -2
- package/src/types/provider.ts +42 -8
- package/src/types/request.ts +15 -0
- package/src/types/tools.ts +22 -5
- package/src/types/wire.ts +1 -0
- package/src/types.ts +4 -0
- package/src/update/check-types.ts +2 -0
- package/src/update/job.ts +8 -3
- package/src/update/managed-release.ts +6 -0
- package/src/update/orchestrated-entry.ts +13 -4
- package/src/update/refresh-scheduler.ts +17 -7
- package/src/usage/attempt-delivery.ts +6 -0
- package/src/usage/cache-provenance.ts +71 -0
- package/src/usage/cost.ts +216 -27
- package/src/usage/credit-billing.ts +88 -0
- package/src/usage/jev-stats.ts +13 -9
- package/src/usage/log.ts +5 -33
- package/src/usage/summary.ts +8 -43
- package/src/usage/user-cost-overlays.ts +13 -1
- package/src/vision/index.ts +8 -3
- package/src/vision/plan.ts +28 -14
- package/src/vision/routed-describe.ts +24 -36
- package/src/web-search/header-deadline.ts +14 -3
- package/src/web-search/index.ts +6 -4
- package/src/web-search/loop.ts +240 -78
- package/src/web-search/progress-stream.ts +29 -2
- package/src/web-search/run-turn-loop.ts +5 -1
- package/gui/dist/assets/App-BGP8I0V4.css +0 -1
- package/gui/dist/assets/App-BRExzhwL.js +0 -60
- package/gui/dist/assets/Tray-DHCWAn8V.js +0 -1
- package/gui/dist/assets/brand-mark-C70PuQ3j.js +0 -1
- package/gui/dist/assets/index-DJxM-imn.css +0 -2
- package/gui/dist/assets/index-Dy1jIGty.js +0 -138
- package/gui/dist/classic/assets/App-B4j-Txmb.css +0 -1
- package/gui/dist/classic/assets/App-CaC-E6Vl.js +0 -59
- package/gui/dist/classic/assets/Tray-BG253fiL.js +0 -1
- package/gui/dist/classic/assets/index-CR_AThOp.js +0 -138
- package/gui/dist/classic/assets/quota-summary-B7KQPpEC.js +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isAllowedRequestOrigin } from "../server/auth-cors";
|
|
1
2
|
import { recordLinkDiagnostic } from "../link/diagnostics";
|
|
2
3
|
import type { Server } from "bun";
|
|
3
4
|
import { loadConfig } from "../config";
|
|
@@ -18,6 +19,8 @@ import { isLinkConnection, readClientConnectionState } from "./state";
|
|
|
18
19
|
import { handleMachineApi, type HubReachability, type MachineApiDeps } from "./machine-api";
|
|
19
20
|
import { MACHINE_GUI_ORIGIN_HEADER, requireMachineAuth } from "./machine-auth";
|
|
20
21
|
import { HUB_RELAY_REQUEST_BODY_MAX_BYTES, relayHubManagementRequest } from "./hub-relay";
|
|
22
|
+
import { currentHubRelayAdmission } from "./hub-session";
|
|
23
|
+
import { hubRelayBootstrapAllowed, hubRelayLogoutAllowed, hubRelayReadAllowed, hubRelayRequestTarget } from "../remote/hub-management-relay";
|
|
21
24
|
import { createLinkKeySource, handleLinkIngress, type LinkIngress, type LinkKeySourceDeps } from "./link-ingress";
|
|
22
25
|
import type { LinkTunnelGate } from "./link-relay";
|
|
23
26
|
import { createLinkWebsocketRelay, type LinkWebsocketRelayDeps } from "./link-websocket";
|
|
@@ -49,6 +52,11 @@ import { clientRestartRollbackAction } from "./runtime-restart";
|
|
|
49
52
|
import { isLinkConnectionGeneration } from "../link/relay-auth";
|
|
50
53
|
|
|
51
54
|
const VERSION = packageVersion("0.0.0");
|
|
55
|
+
/** Machine, Link, and stop paths are reserved for the local runtime. */
|
|
56
|
+
function clientLocalApiPath(pathname: string): boolean {
|
|
57
|
+
return pathname === "/api/machine" || pathname.startsWith("/api/machine/")
|
|
58
|
+
|| pathname === "/api/stop" || pathname === "/api/link/status" || pathname === LINK_DIAGNOSTICS_ROUTE;
|
|
59
|
+
}
|
|
52
60
|
const GUI_SPA_PATHS = new Set([
|
|
53
61
|
"/dashboard", "/startup", "/providers", "/models", "/subagents",
|
|
54
62
|
"/logs", "/usage", "/storage", "/codex-set", "/integrations",
|
|
@@ -91,6 +99,8 @@ export interface MachineListenerDeps {
|
|
|
91
99
|
attestationSecret: string;
|
|
92
100
|
/** ISO start time of this runtime's process. */
|
|
93
101
|
startedAt: string;
|
|
102
|
+
/** The owning runtime preserves explicit Link stop fences across restart rollback. */
|
|
103
|
+
linkStopFence?: true;
|
|
94
104
|
request: () => Promise<ClientRestartAdmission>;
|
|
95
105
|
};
|
|
96
106
|
serve?: (options: Parameters<typeof Bun.serve>[0]) => Server<unknown>;
|
|
@@ -105,6 +115,13 @@ function machinePolicyConfig(config: OcxConfig): OcxConfig {
|
|
|
105
115
|
return { ...config, hostname: "127.0.0.1" };
|
|
106
116
|
}
|
|
107
117
|
|
|
118
|
+
/** Bare management candidates enter the Hub client's authentication and route policy. */
|
|
119
|
+
function relayedManagementPath(url: URL, linkMode: boolean): boolean {
|
|
120
|
+
if (linkMode) return false;
|
|
121
|
+
if (url.pathname.startsWith("/api/machine/hub-relay/")) return false;
|
|
122
|
+
return url.pathname.startsWith("/api/") && !clientLocalApiPath(url.pathname);
|
|
123
|
+
}
|
|
124
|
+
|
|
108
125
|
export function machineRouteAllowed(url: URL, req: Request, relayEnabled: boolean, linkMode = false): boolean {
|
|
109
126
|
if (req.headers.get("upgrade")) return false;
|
|
110
127
|
if (linkMode && linkRouteAllowed(url, req)) return true;
|
|
@@ -117,6 +134,8 @@ export function machineRouteAllowed(url: URL, req: Request, relayEnabled: boolea
|
|
|
117
134
|
if (linkMode && (req.method === "GET" || req.method === "HEAD") && (path === "/api/link/status" || path === LINK_DIAGNOSTICS_ROUTE)) return true;
|
|
118
135
|
if (req.method === "POST" && (path === "/api/machine/sync" || path === "/api/machine/shim" || path === "/api/machine/disconnect")) return true;
|
|
119
136
|
if (relayEnabled && path.startsWith("/api/machine/hub-relay/")) return true;
|
|
137
|
+
// CLI reads go through this listener even when the browser uses the direct Hub transport.
|
|
138
|
+
if (relayedManagementPath(url, linkMode)) return true;
|
|
120
139
|
// Known machine endpoints are admitted for every method so an unsupported
|
|
121
140
|
// method reaches the authenticated method restriction (403) instead of a
|
|
122
141
|
// bare 404 that hides the endpoint entirely.
|
|
@@ -207,6 +226,7 @@ export function startMachineListener(
|
|
|
207
226
|
const response = Response.json({
|
|
208
227
|
service: "opencodex", version: VERSION, role: "client", uptime: process.uptime(), pid: process.pid, port: server.port,
|
|
209
228
|
...(restart ? { startedAt: restart.startedAt, restartCapability: SYSTEM_RESTART_CAPABILITY_VERSION, restartBudgetMs: CLIENT_RESTART_BUDGET_MS } : {}),
|
|
229
|
+
...(restart?.linkStopFence ? { linkStopFence: true } : {}),
|
|
210
230
|
});
|
|
211
231
|
const challenge = restart ? req.headers.get(LOCAL_ATTESTATION_CHALLENGE_HEADER) : null;
|
|
212
232
|
const proof = challenge && server.port
|
|
@@ -237,6 +257,10 @@ export function startMachineListener(
|
|
|
237
257
|
const linkBody = isLinkConnectionGeneration(connectionGeneration) ? { state: "available", connectionGeneration } : { state: "available" };
|
|
238
258
|
return Response.json({ ...identity, status: "ready", ...facts, ...(link ? { link: linkBody } : {}) });
|
|
239
259
|
}
|
|
260
|
+
if ((relayedManagementPath(url, linkMode) || (relayEnabled && url.pathname.startsWith("/api/machine/hub-relay/")))
|
|
261
|
+
&& !isAllowedRequestOrigin(req, config)) {
|
|
262
|
+
return Response.json({ error: "origin_rejected" }, { status: 403 });
|
|
263
|
+
}
|
|
240
264
|
if (url.pathname.startsWith("/api/machine/hub-relay/")) {
|
|
241
265
|
if (!relayEnabled) return json404(req);
|
|
242
266
|
const prefix = "/api/machine/hub-relay";
|
|
@@ -262,7 +286,16 @@ export function startMachineListener(
|
|
|
262
286
|
}
|
|
263
287
|
const authError = requireMachineAuth(req, managementAuth, config);
|
|
264
288
|
if (authError) return authError;
|
|
265
|
-
const
|
|
289
|
+
const callerCredential = req.headers.get("x-opencodex-api-key");
|
|
290
|
+
if (managementPrincipal(req, managementAuth, config)
|
|
291
|
+
|| (!callerCredential && url.pathname !== `${prefix}/opencodex-session`)) {
|
|
292
|
+
return Response.json({ error: "caller hub credential required" }, { status: 401 });
|
|
293
|
+
}
|
|
294
|
+
const raw = hubRelayRequestTarget(req);
|
|
295
|
+
if (!raw.startsWith(prefix + "/")) return json404(req);
|
|
296
|
+
const suffix = raw.slice(prefix.length);
|
|
297
|
+
if (!hubRelayReadAllowed(req.method, suffix) && !hubRelayBootstrapAllowed(req.method, suffix)
|
|
298
|
+
&& !hubRelayLogoutAllowed(req.method, suffix)) return json404(req);
|
|
266
299
|
const response = await relayHubManagementRequest(req, suffix, {
|
|
267
300
|
managementUrl: connection.managementUrl,
|
|
268
301
|
browserOrigin: req.headers.get(MACHINE_GUI_ORIGIN_HEADER) ?? req.headers.get("Origin") ?? "",
|
|
@@ -272,6 +305,32 @@ export function startMachineListener(
|
|
|
272
305
|
else hubReachability = "online";
|
|
273
306
|
return response;
|
|
274
307
|
}
|
|
308
|
+
// A loopback bootstrap grants the machine GUI session. Only the local admin token
|
|
309
|
+
// grants access to the persisted Hub relay credential.
|
|
310
|
+
if (relayedManagementPath(url, linkMode)) {
|
|
311
|
+
const localPrincipal = managementPrincipal(req, managementAuth, config);
|
|
312
|
+
const localAdmin = localPrincipal === "admin-token";
|
|
313
|
+
if (!localAdmin) {
|
|
314
|
+
const authError = requireMachineAuth(req, managementAuth, config);
|
|
315
|
+
if (authError) return authError;
|
|
316
|
+
if (localPrincipal || !req.headers.get("x-opencodex-api-key")) {
|
|
317
|
+
return Response.json({ error: "caller hub credential required" }, { status: 401 });
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const suffix = hubRelayRequestTarget(req);
|
|
321
|
+
if (!hubRelayReadAllowed(req.method, suffix)) return json404(req);
|
|
322
|
+
const readCredential = localAdmin
|
|
323
|
+
? (method: string, target: string) => currentHubRelayAdmission(connection, method, target)
|
|
324
|
+
: undefined;
|
|
325
|
+
const response = await relayHubManagementRequest(req, suffix, {
|
|
326
|
+
managementUrl: connection.managementUrl,
|
|
327
|
+
browserOrigin: req.headers.get(MACHINE_GUI_ORIGIN_HEADER) ?? req.headers.get("Origin") ?? "",
|
|
328
|
+
}, { fetchImpl: deps.fetchImpl, readCredential });
|
|
329
|
+
if (response.status === 401) hubReachability = "unauthorized";
|
|
330
|
+
else if (response.status >= 500) hubReachability = "offline";
|
|
331
|
+
else hubReachability = "online";
|
|
332
|
+
return response;
|
|
333
|
+
}
|
|
275
334
|
if (url.pathname.startsWith("/api/machine/") || (linkMode && (url.pathname === "/api/link/status" || url.pathname === LINK_DIAGNOSTICS_ROUTE))) {
|
|
276
335
|
const authError = requireManagementAuth(req, managementAuth, config);
|
|
277
336
|
if (authError) return authError;
|
|
@@ -161,6 +161,7 @@ export function createClientRestartController(io: ClientRestartIo): ClientRestar
|
|
|
161
161
|
// The recheck is the last step before the recycle, after the (asynchronous) supervisor lookup.
|
|
162
162
|
flight = sleep(200).then(async () => {
|
|
163
163
|
const supervisor = await io.supervisor();
|
|
164
|
+
if (io.stopping?.()) return;
|
|
164
165
|
if (restartRefusedByOwner(supervisor)) { warn("[client] restart: this runtime's owner could not be proven to relaunch it; it keeps serving"); return; }
|
|
165
166
|
if (changed()) await recycle(supervisor);
|
|
166
167
|
}).finally(() => { flight = null; });
|
package/src/client/runtime.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { readDesktopDisconnectReceipt } from "../claude/desktop-remote-store";
|
|
2
3
|
import { flushLinkDiagnostics, recordLinkDiagnostic } from "../link/diagnostics";
|
|
3
4
|
import { existsSync } from "node:fs";
|
|
4
5
|
import type { Server } from "bun";
|
|
5
6
|
import { siblingRuntimeField, withSiblingMarker } from "../codex/sibling-start";
|
|
6
7
|
import { issueSiblingHandoff } from "../codex/sibling-handoff";
|
|
7
|
-
import { loadConfig } from "../config";
|
|
8
|
-
import { removePid, removeRuntimePort, writePid, writeRuntimePort, type RuntimePortState } from "../config/process-state";
|
|
8
|
+
import { loadConfig, withConfigMutationLockSync } from "../config";
|
|
9
|
+
import { readRuntimePort, removePid, removeRuntimePort, writePid, writeRuntimePort, type ClientStopOwner, type RuntimePortState } from "../config/process-state";
|
|
9
10
|
import { currentServingCommand } from "../config/serving-runtimes";
|
|
10
11
|
import { installCrashGuards } from "../lib/crash-guard";
|
|
11
12
|
import { observeLocalCredentials } from "../local-credentials/runtime-observation";
|
|
@@ -29,11 +30,14 @@ import { clientInitiatedLinkReadiness, createHomeInitiatedLinkReadiness } from "
|
|
|
29
30
|
import { createClientLinkSupervisor, type ClientLinkSupervisor } from "./link-tunnel";
|
|
30
31
|
import { clientLinkStatePath, isChildInitiatedLink, recordChildInitiatedLink } from "./link-state";
|
|
31
32
|
import { startMachineListener, type MachineListenerDeps } from "./machine-listener";
|
|
32
|
-
import {
|
|
33
|
+
import { startHubRelayLeaseRefresh } from "./hub-relay";
|
|
34
|
+
import { currentHubRelayAdmission } from "./hub-session";
|
|
35
|
+
import { isLinkConnection, linkStopConnectionOwner, pendingClientConnectMayOwnToken, readClientConnectionState, readClientConnectionStateWithEvidence, sameClientConnectionOwner } from "./state";
|
|
33
36
|
import { withClientLifecycleSync } from "./lifecycle-lock";
|
|
34
37
|
import { clientConnectionEnded, clientRestartRollbackAction, clientRestartSupervisor, createClientRestartController, LEGACY_FLAG_RESTART_OWNER, restartOwnerEvidence, type ClientRestartController, type RecordedRestartOwner, type RestartOwner } from "./runtime-restart";
|
|
35
38
|
import { createLinkParityReporter, type LinkParityReporter } from "./link-parity-reporter";
|
|
36
|
-
import {
|
|
39
|
+
import { restoreLinkClientRoutingBeforeExit } from "./stop-routing";
|
|
40
|
+
import { observeClientStopOwner } from "./stop-teardown-owner";
|
|
37
41
|
import { SUPERVISOR_MARKER_ENVS } from "../lib/supervisor-markers";
|
|
38
42
|
import { markClientRuntimeStopping, markClientRuntimeStoppingWithRetry } from "./sync-runtime";
|
|
39
43
|
import { startRouteIntentTick, type RouteIntentTick } from "../integrations/route-intent-tick";
|
|
@@ -45,6 +49,7 @@ let activeSupervisor: ClientLinkSupervisor | null = null;
|
|
|
45
49
|
let activeReporter: LinkParityReporter | null = null;
|
|
46
50
|
let activeRouteWatch: RouteIntentRuntimeWatch | null = null;
|
|
47
51
|
let activeRouteSync: RouteIntentTick | null = null;
|
|
52
|
+
let activeHubRelayRefresh: { stop(): void } | null = null;
|
|
48
53
|
// The local-credential observer lives exactly while this process serves (status attestation).
|
|
49
54
|
// Every path that stops serving stops it, including a recycle back to standalone.
|
|
50
55
|
let activeCredentialObservation: { stop(): void } | null = null;
|
|
@@ -52,6 +57,9 @@ let recycleScheduled = false;
|
|
|
52
57
|
let recycleTimer: ReturnType<typeof setTimeout> | undefined;
|
|
53
58
|
let recycleFlight: Promise<void> | null = null;
|
|
54
59
|
let clientStopping = false;
|
|
60
|
+
let explicitClientStopRequested: boolean | undefined;
|
|
61
|
+
let explicitClientStopOwner: ClientStopOwner | undefined;
|
|
62
|
+
let standaloneRecycleAllowed = () => !clientStopping;
|
|
55
63
|
|
|
56
64
|
/**
|
|
57
65
|
* When this runtime's process started (OCX-6, P5): what `/healthz` reports as `startedAt` and the
|
|
@@ -114,7 +122,10 @@ export function clientRuntimeRecord(
|
|
|
114
122
|
): RuntimePortState {
|
|
115
123
|
let command: string[] | undefined;
|
|
116
124
|
try { command = currentServingCommand(); } catch { /* no reliable relaunch identity; update admission fails closed */ }
|
|
117
|
-
return { pid, port, hostname: "127.0.0.1", attestationSecret, ...(command ? { command } : {}), ...siblingRuntimeField(),
|
|
125
|
+
return { pid, port, hostname: "127.0.0.1", attestationSecret, ...(command ? { command } : {}), ...siblingRuntimeField(),
|
|
126
|
+
...(clientStopping ? { clientStopping: true as const } : {}),
|
|
127
|
+
...(explicitClientStopRequested !== undefined ? { clientStopRequested: explicitClientStopRequested } : {}),
|
|
128
|
+
...(explicitClientStopOwner ? { clientStopOwner: explicitClientStopOwner } : {}), ...(owner ? { restartOwner: owner } : {}) };
|
|
118
129
|
}
|
|
119
130
|
|
|
120
131
|
/** Evaluated once: the launch environment and parent of this process do not change. */
|
|
@@ -155,11 +166,11 @@ export function standaloneRecycleEnv(
|
|
|
155
166
|
}
|
|
156
167
|
|
|
157
168
|
export function scheduleStandaloneRecycle(disconnectedTokenFingerprint: string): void {
|
|
158
|
-
if (recycleScheduled ||
|
|
169
|
+
if (recycleScheduled || !standaloneRecycleAllowed()) return;
|
|
159
170
|
recycleScheduled = true;
|
|
160
171
|
recycleTimer = setTimeout(() => {
|
|
161
172
|
recycleTimer = undefined;
|
|
162
|
-
if (
|
|
173
|
+
if (!standaloneRecycleAllowed()) { recycleScheduled = false; return; }
|
|
163
174
|
recycleFlight = recycleStandalone(disconnectedTokenFingerprint).finally(() => { recycleFlight = null; });
|
|
164
175
|
void recycleFlight.catch(error => { if (!clientStopping) throw error; });
|
|
165
176
|
}, 50);
|
|
@@ -193,6 +204,7 @@ export async function recycleStandalone(
|
|
|
193
204
|
? withSiblingMarker(standaloneRecycleEnv(process.env, disconnectedTokenFingerprint), issueSiblingHandoff)
|
|
194
205
|
: null;
|
|
195
206
|
activeCredentialObservation?.stop(); activeCredentialObservation = null;
|
|
207
|
+
activeHubRelayRefresh?.stop(); activeHubRelayRefresh = null;
|
|
196
208
|
activeReporter?.stop(); activeReporter = null;
|
|
197
209
|
activeRouteWatch?.stop(); activeRouteWatch = null;
|
|
198
210
|
activeRouteSync?.stop(); activeRouteSync = null;
|
|
@@ -337,6 +349,7 @@ export async function startClientRuntime(
|
|
|
337
349
|
if (state.kind !== "connected") throw new Error(`client runtime refused: client state is ${state.kind}`);
|
|
338
350
|
const config = loadConfig();
|
|
339
351
|
const linkMode = isLinkConnection(state.value);
|
|
352
|
+
const clientLinkOwner = linkMode ? linkStopConnectionOwner(state.value) : null;
|
|
340
353
|
if (linkMode && (!Number.isInteger(config.port) || config.port < 1 || config.port > 65535)) {
|
|
341
354
|
throw new Error("link mode requires a valid local config port");
|
|
342
355
|
}
|
|
@@ -360,8 +373,17 @@ export async function startClientRuntime(
|
|
|
360
373
|
// restart rolls back (OCX-6); the stopped supervisor cannot be started twice, so each call builds one.
|
|
361
374
|
// The port this process actually serves on; a rollback binds exactly this one again.
|
|
362
375
|
let servedPort = preferred;
|
|
363
|
-
|
|
364
|
-
|
|
376
|
+
const observeExplicitStop = (): boolean => {
|
|
377
|
+
const current = readRuntimePort(process.pid);
|
|
378
|
+
if (current?.port === servedPort && current.attestationSecret === attestationSecret && current.clientStopRequested !== undefined) {
|
|
379
|
+
explicitClientStopRequested = current.clientStopRequested;
|
|
380
|
+
explicitClientStopOwner = current.clientStopOwner;
|
|
381
|
+
clientStopping = true;
|
|
382
|
+
}
|
|
383
|
+
return explicitClientStopRequested === true
|
|
384
|
+
&& (!explicitClientStopOwner || observeClientStopOwner(explicitClientStopOwner) !== "confirmed-stale");
|
|
385
|
+
};
|
|
386
|
+
// An unpublishable rollback closes the new listener before the caller considers a recycle.
|
|
365
387
|
const serve = async (rollback?: { port: number; portWaitMs: number }): Promise<boolean> => {
|
|
366
388
|
const supervisor = supervised
|
|
367
389
|
? createClientLinkSupervisor({
|
|
@@ -385,24 +407,33 @@ export async function startClientRuntime(
|
|
|
385
407
|
preferred: rollback?.port ?? preferred,
|
|
386
408
|
explicitPort: rollback !== undefined || options.port !== undefined,
|
|
387
409
|
configuredPort: config.port,
|
|
388
|
-
restart: { attestationSecret, startedAt: CLIENT_RUNTIME_STARTED_AT, request: () => restartController.request() },
|
|
410
|
+
restart: { attestationSecret, startedAt: CLIENT_RUNTIME_STARTED_AT, ...(linkMode ? { linkStopFence: true as const } : {}), request: () => restartController.request() },
|
|
389
411
|
...(linkMode ? { linkStatus: () => activeSupervisor?.status() ?? { kind: "stopped" as const }, linkKeySource: linkKey } : {}),
|
|
390
412
|
...(supervisor ? { linkTunnel: supervisor } : homeInitiated ? { linkTunnel: HOME_INITIATED_LINK_TUNNEL } : {}),
|
|
391
413
|
...(linkReadiness ? { linkReadiness } : {}),
|
|
392
414
|
...(supervisor ? { linkConnectionGeneration: () => supervisor.connectionGeneration() }
|
|
393
415
|
: homeInitiated && link ? { linkConnectionGeneration: () => verifiedHomeConnection(link.linkId) } : {}),
|
|
394
416
|
}, rollback === undefined ? io : { ...io, portWaitMs: rollback.portWaitMs });
|
|
395
|
-
const
|
|
417
|
+
const publishRecord = (): void => {
|
|
418
|
+
// A parent stop can arrive after restart admission. Never clear its fence on rollback;
|
|
419
|
+
// a fresh process has another attestation identity and cannot inherit this request.
|
|
420
|
+
if (rollback) observeExplicitStop();
|
|
421
|
+
writePid(process.pid);
|
|
422
|
+
// A new generation refuses commits from syncs admitted before the failed restart.
|
|
423
|
+
writeRuntimePort({ ...clientRuntimeRecord(process.pid, boundPort, attestationSecret), servingGeneration: randomUUID(),
|
|
424
|
+
clientLinkOwner });
|
|
425
|
+
};
|
|
426
|
+
const activate = (): void => {
|
|
396
427
|
activeServer = server;
|
|
397
428
|
activePort = boundPort;
|
|
398
429
|
servedPort = boundPort;
|
|
399
430
|
activeSupervisor = supervisor;
|
|
400
431
|
supervisor?.start();
|
|
401
432
|
activeCredentialObservation ??= observeLocalCredentials();
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
433
|
+
if (!linkMode) {
|
|
434
|
+
activeHubRelayRefresh ??= startHubRelayLeaseRefresh(state.value.managementUrl,
|
|
435
|
+
(method, target) => currentHubRelayAdmission(state.value, method, target));
|
|
436
|
+
}
|
|
406
437
|
if (linkMode && state.value.link && linkKey) {
|
|
407
438
|
activeReporter = createLinkParityReporter({ connection: state.value, linkKey, runtimeStartedAt: CLIENT_RUNTIME_STARTED_AT });
|
|
408
439
|
activeReporter.start();
|
|
@@ -412,23 +443,23 @@ export async function startClientRuntime(
|
|
|
412
443
|
}
|
|
413
444
|
};
|
|
414
445
|
if (!rollback) {
|
|
415
|
-
|
|
446
|
+
publishRecord();
|
|
447
|
+
activate();
|
|
416
448
|
return true;
|
|
417
449
|
}
|
|
418
|
-
//
|
|
419
|
-
//
|
|
420
|
-
|
|
450
|
+
// Admission and publication are synchronous after bind. A busy lock must close the
|
|
451
|
+
// rebound listener before yielding. Link takes C to preserve an explicit stop fence.
|
|
452
|
+
const publishIfOwned = () => {
|
|
453
|
+
if (clientRestartRollbackAction(state.value, readClientConnectionState()) === "recycle") return false;
|
|
454
|
+
publishRecord();
|
|
455
|
+
return true;
|
|
456
|
+
};
|
|
421
457
|
let published = false;
|
|
422
458
|
try {
|
|
423
|
-
published = withClientLifecycleSync(() =>
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
});
|
|
428
|
-
} catch {
|
|
429
|
-
published = false;
|
|
430
|
-
}
|
|
431
|
-
if (!published) {
|
|
459
|
+
published = withClientLifecycleSync(() => linkMode ? withConfigMutationLockSync(publishIfOwned) : publishIfOwned());
|
|
460
|
+
} catch { /* failed admission */ }
|
|
461
|
+
if (published) activate();
|
|
462
|
+
else {
|
|
432
463
|
try { await server.stop(true); } catch { /* never published */ }
|
|
433
464
|
}
|
|
434
465
|
return published;
|
|
@@ -438,6 +469,7 @@ export async function startClientRuntime(
|
|
|
438
469
|
const stopServing = async (drainMs: number): Promise<void> => {
|
|
439
470
|
activeCredentialObservation?.stop();
|
|
440
471
|
activeCredentialObservation = null;
|
|
472
|
+
activeHubRelayRefresh?.stop(); activeHubRelayRefresh = null;
|
|
441
473
|
activeReporter?.stop();
|
|
442
474
|
activeReporter = null;
|
|
443
475
|
activeRouteWatch?.stop(); activeRouteWatch = null;
|
|
@@ -464,8 +496,25 @@ export async function startClientRuntime(
|
|
|
464
496
|
};
|
|
465
497
|
|
|
466
498
|
let shuttingDown = false;
|
|
499
|
+
standaloneRecycleAllowed = () => {
|
|
500
|
+
try {
|
|
501
|
+
if (shuttingDown || observeExplicitStop()) return false;
|
|
502
|
+
if (!clientStopping) return true;
|
|
503
|
+
// A retained sync fence is not an active exit. Only a completed disconnect of this exact
|
|
504
|
+
// served owner permits recovery; partial cleanup, a new connect or uncertain state cannot.
|
|
505
|
+
return withConfigMutationLockSync(() => {
|
|
506
|
+
if (observeExplicitStop()) return false;
|
|
507
|
+
const receipt = readDesktopDisconnectReceipt();
|
|
508
|
+
return ownerProven() && !pendingClientConnectMayOwnToken()
|
|
509
|
+
&& readClientConnectionStateWithEvidence().kind === "disconnected"
|
|
510
|
+
&& receipt.kind === "valid" && receipt.value.phase === "complete"
|
|
511
|
+
&& sameClientConnectionOwner(receipt.value.owner, state.value)
|
|
512
|
+
&& receipt.value.tokenFingerprint === state.value.tokenFingerprint;
|
|
513
|
+
});
|
|
514
|
+
} catch { return false; }
|
|
515
|
+
};
|
|
467
516
|
const restartController: ClientRestartController = createClientRestartController({
|
|
468
|
-
stopping: () =>
|
|
517
|
+
stopping: () => !standaloneRecycleAllowed(),
|
|
469
518
|
supervisor: io.restartSupervisor ?? clientRestartSupervisor,
|
|
470
519
|
connectionChanged: () => clientConnectionEnded(state.value, readClientConnectionStateWithEvidence()),
|
|
471
520
|
ownerProven,
|
|
@@ -478,7 +527,12 @@ export async function startClientRuntime(
|
|
|
478
527
|
// later commit stand down under C; the replacement's record, or the fresh generation a rollback
|
|
479
528
|
// publishes, keeps those syncs refused and admits new ones. A mark that cannot be written
|
|
480
529
|
// abandons the restart before anything stops.
|
|
481
|
-
fence: async () => !linkMode || await markClientRuntimeStoppingWithRetry({ pid: process.pid, port: servedPort, attestationSecret }
|
|
530
|
+
fence: async () => !linkMode || await markClientRuntimeStoppingWithRetry({ pid: process.pid, port: servedPort, attestationSecret }, {
|
|
531
|
+
mark: () => withConfigMutationLockSync(() => {
|
|
532
|
+
if (observeExplicitStop()) throw new Error("client_stop_requested");
|
|
533
|
+
markClientRuntimeStopping({ pid: process.pid, port: servedPort, attestationSecret });
|
|
534
|
+
}),
|
|
535
|
+
}),
|
|
482
536
|
stop: stopServing,
|
|
483
537
|
spawnReplacement: async deadlineAt => {
|
|
484
538
|
const { replacementStartEnvironment } = await import("../server/management/system-restart");
|
|
@@ -489,15 +543,18 @@ export async function startClientRuntime(
|
|
|
489
543
|
);
|
|
490
544
|
},
|
|
491
545
|
resume: async () => {
|
|
546
|
+
const recycleAfterRollback = () => {
|
|
547
|
+
if (standaloneRecycleAllowed()) return recycleStandalone(state.value.tokenFingerprint);
|
|
548
|
+
};
|
|
492
549
|
// The connection may have changed while the replacement was starting (`ocx disconnect`, a
|
|
493
550
|
// new connect). Serving the old one again would be a stale runtime nothing recycles; hand
|
|
494
551
|
// off to the recycle, which starts whatever the durable state now calls for.
|
|
495
552
|
if (clientRestartRollbackAction(state.value, readClientConnectionState()) === "recycle") {
|
|
496
|
-
await
|
|
553
|
+
await recycleAfterRollback();
|
|
497
554
|
return;
|
|
498
555
|
}
|
|
499
556
|
if (!(await serve({ port: servedPort, portWaitMs: CLIENT_RESTART_REBIND_WAIT_MS }))) {
|
|
500
|
-
await
|
|
557
|
+
await recycleAfterRollback();
|
|
501
558
|
}
|
|
502
559
|
},
|
|
503
560
|
exitProcess: async code => {
|
|
@@ -515,7 +572,11 @@ export async function startClientRuntime(
|
|
|
515
572
|
if (shuttingDown) return;
|
|
516
573
|
shuttingDown = true;
|
|
517
574
|
clientStopping = true;
|
|
518
|
-
if (recycleTimer) {
|
|
575
|
+
if (recycleTimer) {
|
|
576
|
+
clearTimeout(recycleTimer);
|
|
577
|
+
recycleTimer = undefined;
|
|
578
|
+
recycleScheduled = false;
|
|
579
|
+
}
|
|
519
580
|
const fenceSync = () => {
|
|
520
581
|
if (!linkMode) return true;
|
|
521
582
|
try { markClientRuntimeStopping({ pid: process.pid, port: servedPort, attestationSecret }); return true; }
|
|
@@ -531,6 +592,7 @@ export async function startClientRuntime(
|
|
|
531
592
|
syncFenced = !linkMode || await markClientRuntimeStoppingWithRetry({ pid: process.pid, port: servedPort, attestationSecret });
|
|
532
593
|
activeCredentialObservation?.stop();
|
|
533
594
|
activeCredentialObservation = null;
|
|
595
|
+
activeHubRelayRefresh?.stop(); activeHubRelayRefresh = null;
|
|
534
596
|
activeReporter?.stop();
|
|
535
597
|
activeReporter = null;
|
|
536
598
|
activeRouteWatch?.stop(); activeRouteWatch = null;
|
|
@@ -541,8 +603,16 @@ export async function startClientRuntime(
|
|
|
541
603
|
console.warn(`[client] link supervisor stop failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
542
604
|
}
|
|
543
605
|
activeSupervisor = null;
|
|
544
|
-
const restored = linkMode ?
|
|
606
|
+
const restored = linkMode ? await restoreLinkClientRoutingBeforeExit(state.value, {
|
|
607
|
+
syncFenced, runtime: { pid: process.pid, port: servedPort, attestationSecret },
|
|
608
|
+
}) : null;
|
|
545
609
|
if (restored && !restored.success) console.error(`[client] ${restored.message}`);
|
|
610
|
+
if (restored?.retainListener) {
|
|
611
|
+
// Keep the stopping record and socket. Another signal can retry after the operator
|
|
612
|
+
// repairs the retained file/ownership evidence; no background sync can reapply it.
|
|
613
|
+
shuttingDown = false;
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
546
616
|
try {
|
|
547
617
|
activeServer?.stop(true);
|
|
548
618
|
} catch (error) {
|
package/src/client/state.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { lstatSync, readFileSync, unlinkSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
3
4
|
import {
|
|
4
5
|
getConfigDir,
|
|
5
6
|
getConfigPath,
|
|
@@ -31,6 +32,16 @@ export function isLinkConnection(c: OcxClientConnectionConfig | undefined): bool
|
|
|
31
32
|
return c?.transport === "link";
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
/** The serving Link's ownership, independent of selection and catalog sync observations. */
|
|
36
|
+
export function linkStopConnectionOwner(connection: OcxClientConnectionConfig): string | undefined {
|
|
37
|
+
if (connection.transport !== "link" || !connection.link) return;
|
|
38
|
+
return createHash("sha256").update(JSON.stringify([
|
|
39
|
+
connection.serverUrl, connection.managementUrl, connection.managementTransport,
|
|
40
|
+
connection.apiKeyId, connection.connectedAt, connection.tokenFingerprint,
|
|
41
|
+
connection.link.linkId, connection.link.tunnelPort,
|
|
42
|
+
])).digest("hex");
|
|
43
|
+
}
|
|
44
|
+
|
|
34
45
|
const pendingConnectPath = (): string => join(getConfigDir(), "client-connect-pending");
|
|
35
46
|
|
|
36
47
|
/** Validate pending ownership; an optional fingerprint restricts it to that exact key. */
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { dlopen, ptr } from "bun:ffi";
|
|
2
|
+
|
|
3
|
+
const MAX_ARGV_BYTES = 64 * 1024;
|
|
4
|
+
|
|
5
|
+
/** Read argc, skip the executable path and padding, and keep the environment separate. */
|
|
6
|
+
function parseProcessArgs(bytes: Buffer): { argv: string[]; environment: Buffer } | undefined {
|
|
7
|
+
if (bytes.length < 5) return;
|
|
8
|
+
const argc = bytes.readInt32LE(0);
|
|
9
|
+
if (argc < 1 || argc > 4096) return;
|
|
10
|
+
let start = bytes.indexOf(0, 4);
|
|
11
|
+
if (start < 5) return;
|
|
12
|
+
while (bytes[start] === 0) start++;
|
|
13
|
+
const argv: string[] = [];
|
|
14
|
+
const decode = new TextDecoder("utf-8", { fatal: true });
|
|
15
|
+
for (let index = 0; index < argc; index++) {
|
|
16
|
+
const end = bytes.indexOf(0, start);
|
|
17
|
+
if (end < start || end >= MAX_ARGV_BYTES) return;
|
|
18
|
+
argv.push(decode.decode(bytes.subarray(start, end)));
|
|
19
|
+
start = end + 1;
|
|
20
|
+
}
|
|
21
|
+
return { argv, environment: bytes.subarray(start) };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function readDarwinStopProcessArgs(pid: number): ReturnType<typeof parseProcessArgs> {
|
|
25
|
+
const lib = dlopen("/usr/lib/libSystem.B.dylib", {
|
|
26
|
+
sysctl: { args: ["ptr", "u32", "ptr", "ptr", "ptr", "u64"], returns: "i32" },
|
|
27
|
+
});
|
|
28
|
+
try {
|
|
29
|
+
const mib = new Int32Array([1, 49, pid]); // CTL_KERN, KERN_PROCARGS2, PID
|
|
30
|
+
// The kernel returns argv with its environment. Bound the native read.
|
|
31
|
+
const bytes = Buffer.alloc(1024 * 1024);
|
|
32
|
+
const size = new BigUint64Array([BigInt(bytes.length)]);
|
|
33
|
+
if (lib.symbols.sysctl(ptr(mib), mib.length, ptr(bytes), ptr(size), null, 0n) !== 0
|
|
34
|
+
|| size[0]! > BigInt(bytes.length)) return;
|
|
35
|
+
return parseProcessArgs(bytes.subarray(0, Number(size[0])));
|
|
36
|
+
} finally { lib.close(); }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function readDarwinStopArgv(pid: number): string[] | undefined {
|
|
40
|
+
return readDarwinStopProcessArgs(pid)?.argv;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function readDarwinStopEnvironment(pid: number): Buffer | undefined {
|
|
44
|
+
return readDarwinStopProcessArgs(pid)?.environment;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function readDarwinProcessInfo(pid: number, flavor: number, size: number): Buffer | undefined {
|
|
48
|
+
const lib = dlopen("/usr/lib/libproc.dylib", {
|
|
49
|
+
proc_pidinfo: { args: ["i32", "i32", "u64", "ptr", "i32"], returns: "i32" },
|
|
50
|
+
});
|
|
51
|
+
try {
|
|
52
|
+
const info = Buffer.alloc(size);
|
|
53
|
+
if (lib.symbols.proc_pidinfo(pid, flavor, 0n, ptr(info), size) === size) return info;
|
|
54
|
+
} finally { lib.close(); }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** PROC_PIDTBSDINFO supplies both the effective UID and microsecond process creation time. */
|
|
58
|
+
export function readDarwinStopStart(pid: number): string | undefined {
|
|
59
|
+
// struct proc_bsdinfo from sys/proc_info.h, shared by arm64 and x86_64.
|
|
60
|
+
const info = readDarwinProcessInfo(pid, 3, 136);
|
|
61
|
+
if (!info || info.readUInt32LE(12) !== pid || info.readUInt32LE(20) !== process.geteuid?.()) return;
|
|
62
|
+
const seconds = info.readBigUInt64LE(120);
|
|
63
|
+
const micros = info.readBigUInt64LE(128);
|
|
64
|
+
if (seconds > 0n && micros < 1_000_000n) return `darwin:${seconds}:${micros}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function readDarwinStopCwd(pid: number): string | undefined {
|
|
68
|
+
// PROC_PIDVNODEPATHINFO, struct proc_vnodepathinfo.pvi_cdir.vip_path[MAXPATHLEN].
|
|
69
|
+
const info = readDarwinProcessInfo(pid, 9, 2352);
|
|
70
|
+
const path = info?.subarray(152, 152 + 1024);
|
|
71
|
+
const end = path?.indexOf(0) ?? -1;
|
|
72
|
+
if (path && end > 0) return new TextDecoder("utf-8", { fatal: true }).decode(path.subarray(0, end));
|
|
73
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Stop only the file routes this Link created; connection and recovery records remain. */
|
|
2
|
+
import { loadConfig } from "../config";
|
|
3
|
+
import { getConfigDir, withConfigDirHardeningSettled } from "../config/paths";
|
|
4
|
+
import { cleanupConnectedFileRouteIntent, readConnectedFileRouteIntentForCleanup } from "../integrations/route-intent-disconnect";
|
|
5
|
+
import { readRouteIntentReceiptStrict } from "../integrations/route-intent-state";
|
|
6
|
+
import { readServiceApiTokenState } from "../lib/service-secrets";
|
|
7
|
+
import type { OcxClientConnectionConfig } from "../types";
|
|
8
|
+
import { clearHomeRouteIntentRecord } from "./link-home";
|
|
9
|
+
import { withClientLifecycleSync, type ClientLifecycleLockDeps } from "./lifecycle-lock";
|
|
10
|
+
import { stopRestoreWriteGuard } from "./restore-ownership";
|
|
11
|
+
|
|
12
|
+
export async function restoreLinkFileRouting(
|
|
13
|
+
connection: OcxClientConnectionConfig,
|
|
14
|
+
options: { beforeWrite?: () => void; lifecycleLockDeps?: ClientLifecycleLockDeps } = {},
|
|
15
|
+
): Promise<boolean> {
|
|
16
|
+
if (connection.transport !== "link" || !connection.link) return false;
|
|
17
|
+
const expected = structuredClone(connection);
|
|
18
|
+
const ownership = stopRestoreWriteGuard(expected);
|
|
19
|
+
const port = loadConfig().port;
|
|
20
|
+
const boundary = () => {
|
|
21
|
+
options.beforeWrite?.();
|
|
22
|
+
if (loadConfig().port !== port) throw new Error("client_route_port_changed");
|
|
23
|
+
};
|
|
24
|
+
// A fenced Link with no owned file route needs no credential or lifecycle mutation. Keep the
|
|
25
|
+
// strict disk proof (including missing-receipt residue) and recheck the owner after its awaits.
|
|
26
|
+
if (!await readConnectedFileRouteIntentForCleanup(expected)) {
|
|
27
|
+
ownership.run(boundary);
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const guard = () => ownership.run(() => {
|
|
31
|
+
boundary();
|
|
32
|
+
const token = readServiceApiTokenState();
|
|
33
|
+
if (token.kind !== "present" || token.fingerprint !== expected.tokenFingerprint) throw new Error("client_token_changed");
|
|
34
|
+
});
|
|
35
|
+
return withConfigDirHardeningSettled(getConfigDir(), async () => {
|
|
36
|
+
withClientLifecycleSync(() => {
|
|
37
|
+
guard();
|
|
38
|
+
const receipt = readRouteIntentReceiptStrict();
|
|
39
|
+
if (receipt?.linkId !== undefined) {
|
|
40
|
+
if (receipt.linkId !== expected.link!.linkId) throw new Error("client_route_owner_changed");
|
|
41
|
+
// A partial stop must not leave the Home's previous successful apply proof current.
|
|
42
|
+
clearHomeRouteIntentRecord();
|
|
43
|
+
}
|
|
44
|
+
}, options.lifecycleLockDeps);
|
|
45
|
+
const restored = await cleanupConnectedFileRouteIntent(expected, guard, options.lifecycleLockDeps);
|
|
46
|
+
guard();
|
|
47
|
+
return restored;
|
|
48
|
+
});
|
|
49
|
+
}
|