@bitkyc08/opencodex 2.96.0 → 2.98.0-preview.20261107
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/bin/ocx.mjs +215 -20
- package/gui/dist/assets/App-6TFtZsUF.css +1 -0
- package/gui/dist/assets/App-B8_sOxoz.js +59 -0
- package/gui/dist/assets/Tray-DpWEp6ee.js +1 -0
- package/gui/dist/assets/WantedSansVariable.split.0-Dwvb1WRx.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.1-1wKD2RxI.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.10-CAKA6LIP.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.11-k5H85R4b.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.12-BHboLsUv.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.13-9GV377ix.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.14-DovDXnrj.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.15-DTdykCig.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.16-CKz2ccgK.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.17-Z2RD_KRZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.18-BcKtfonJ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.19-DEQPOSZn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.2-DryboyuA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.20-Bia5JMls.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.21-Cr4jFw-E.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.22-DjjB69TZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.23-CvUzJskt.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.24-i_eMg5ox.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.25-2aKHwPX-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.26-B6wXoCEL.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.27-D4h1WfGM.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.28-kvRPCStd.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.29-DHAiwleD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.3-7H--eyZi.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.30-C66cfAY2.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.31-FDmtiNim.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.32-DouHt2Dd.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.33-B8HVvkJX.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.34-BtkRu1FN.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.35-DBylQbtk.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.36-Sg089Kgh.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.37-CYtvbriS.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.38-DKkSLf8Z.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.39-CecotKZD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.4-Bv8O3ZMb.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.40-DdCvkmOU.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.41-ESn674Hc.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.42-DL9V7NNV.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.43-yipO0cyk.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.44-6rTmLZhm.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.45-BJAj8lrm.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.46-BDTzMn2c.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.47-Bxd4wGgi.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.48-DxnFBLnH.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.49-DnVD0aOD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.5-B1wI2pp5.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.50-D9JlkZd6.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.51-D9Vw6Bu3.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.52-ClEJk4kn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.53-BSXU0vh-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.54-EcuxkR9v.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.55-CYiFhQX8.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.56--Gk9g8BK.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.57-DnkOPZcy.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.58-9MB8504z.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.59-ByxIsN72.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.6-Bmk0dRVw.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.60-Bxwx_aWQ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.61-DA2z5sm7.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.62-C5iJPJZn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.63-DAqrmaEc.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.64-BgXFsljb.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.65-DKiWujvu.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.66-8po4vUZ4.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.67-Cy5qyI9O.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.68-BKny7Fy3.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.69-B4VU4u_b.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.7-BuqwNpgA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.70-BCd4n346.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.71-CkQppaWn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.72-Db7vaoFs.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.73-DI80TYWl.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.74-tMCtDAHB.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.75-Ciw0D5WG.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.76-DoLjFgp-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.77-CpT2uvMy.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.78-CkcJ4iZ1.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.79-DsOUJjEM.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.8-DsjypPd6.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.80-C0VwHTte.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.81-DTelu57i.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.82-BiMndGN1.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.83-CVcC6eDG.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.84-DlhZVt_O.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.85-S8I2D3pA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.86-DozXXpH5.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.87-Dsn0Vuuo.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.88-iNwxxDCr.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.89-B63u_9CZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.9-Bi3IzpMI.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.90-ByeH1Pqf.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.91-UQLlagpm.woff2 +0 -0
- package/gui/dist/assets/brand-mark-VPhzz-WE.js +1 -0
- package/gui/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/gui/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/gui/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/gui/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/gui/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/gui/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/gui/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/gui/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/gui/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/gui/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/gui/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/gui/dist/assets/index-5REODpG3.css +2 -0
- package/gui/dist/assets/index-BWKBeK77.js +94 -0
- package/gui/dist/assets/segment-thumb-features-BQYzrze9.js +1 -0
- package/gui/dist/classic/assets/App-Bz65x1J6.js +58 -0
- package/gui/dist/{assets/Tray-BOPQyDbH.js → classic/assets/Tray-kk7mdO6I.js} +1 -1
- package/gui/dist/classic/assets/index-Dp2j8bSc.js +94 -0
- package/gui/dist/classic/assets/quota-summary-CvamtHjB.js +1 -0
- package/gui/dist/classic/index.html +47 -0
- package/gui/dist/favicon.png +0 -0
- package/gui/dist/favicon.svg +14 -0
- package/gui/dist/index.html +15 -2
- package/package.json +1 -1
- package/src/adapters/anthropic.ts +17 -8
- package/src/adapters/command-code.ts +15 -16
- package/src/adapters/cursor/transport-retry.ts +2 -2
- package/src/adapters/devin/cloud-direct/chat.ts +15 -6
- package/src/adapters/google.ts +7 -7
- package/src/adapters/kiro/adapter.ts +18 -3
- package/src/adapters/kiro/conversation.ts +8 -8
- package/src/adapters/kiro/payload.ts +45 -12
- package/src/adapters/kiro/stream.ts +230 -14
- package/src/adapters/kiro/structured-output-json.ts +191 -0
- package/src/adapters/kiro/structured-output-schema.ts +542 -0
- package/src/adapters/kiro/structured-output.ts +367 -0
- package/src/adapters/kiro-constants.ts +24 -1
- package/src/adapters/kiro-events.ts +31 -1
- package/src/adapters/kiro-retry.ts +3 -3
- package/src/adapters/kiro-tools.ts +14 -9
- package/src/adapters/kiro-wire.ts +9 -5
- package/src/adapters/ollama-native.ts +11 -1
- package/src/adapters/openai-chat/messages.ts +58 -5
- package/src/adapters/openai-chat/mistral-image-limit.ts +50 -0
- package/src/adapters/openai-chat/passthrough.ts +5 -3
- package/src/adapters/openai-chat/tool-schema.ts +83 -13
- package/src/adapters/openai-responses/empty-assistant.ts +15 -3
- package/src/adapters/openai-responses/opengateway-input.ts +18 -6
- package/src/adapters/openai-responses/passthrough.ts +5 -4
- package/src/adapters/openai-responses/reasoning.ts +9 -4
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/openai-responses/tool-output-recovery.ts +79 -0
- package/src/adapters/physical-send.ts +3 -3
- package/src/adapters/qoder/live-models.ts +115 -1
- package/src/adapters/zed-openai-stream.ts +2 -1
- package/src/bridge/errors.ts +11 -2
- package/src/bridge/response-json.ts +2 -1
- package/src/bridge/sse.ts +14 -6
- package/src/chat/failure-verdict.ts +21 -0
- package/src/chat/outbound.ts +139 -21
- package/src/claude/failure-verdict.ts +21 -0
- package/src/claude/inbound-content-options.ts +15 -2
- package/src/claude/inbound-model-options.ts +2 -1
- package/src/claude/inbound-records.ts +2 -0
- package/src/claude/inbound.ts +17 -11
- package/src/claude/outbound.ts +98 -22
- package/src/cli/capabilities-access-remote.ts +13 -0
- package/src/cli/capabilities-base.ts +26 -3
- package/src/cli/capabilities-command.ts +12 -3
- package/src/cli/capabilities-provider-models.ts +3 -3
- package/src/cli/capability-contracts.ts +2 -0
- package/src/cli/codex-launch-auth.ts +30 -1
- package/src/cli/codex-launcher.ts +12 -5
- package/src/cli/codex-shim-autorestore.ts +12 -4
- package/src/cli/config-command.ts +11 -2
- package/src/cli/connect.ts +17 -2
- package/src/cli/dispatch.ts +14 -177
- package/src/cli/doctor.ts +95 -7
- package/src/cli/help.ts +2 -2
- package/src/cli/index.ts +17 -8
- package/src/cli/link-apply-restart.ts +9 -2
- package/src/cli/link.ts +1 -1
- package/src/cli/models.ts +124 -38
- package/src/cli/registry.ts +12 -4
- package/src/cli/restart-failure.ts +17 -0
- package/src/cli/root.ts +8 -0
- package/src/cli/stop-approval.ts +2 -2
- package/src/cli/sync-command.ts +243 -0
- package/src/cli/sync-fanout-process.ts +92 -0
- package/src/cli/sync-fanout.ts +161 -0
- package/src/cli/sync-flags.ts +10 -0
- package/src/cli/sync-link-status.ts +39 -0
- package/src/cli/sync-update-guard.ts +18 -0
- package/src/cli/system-restart-client.ts +5 -0
- package/src/cli/uninstall-client-state.ts +12 -1
- package/src/cli/update-restart-child.ts +13 -3
- package/src/cli/update-restart-home.ts +6 -3
- package/src/cli/update-restart.ts +36 -19
- package/src/client/connect.ts +35 -15
- package/src/client/hub-client.ts +5 -0
- package/src/client/link-home.ts +3 -2
- package/src/client/link-management-relay.ts +39 -2
- package/src/client/link-readiness.ts +3 -1
- package/src/client/machine-api.ts +2 -1
- package/src/client/machine-listener.ts +10 -0
- package/src/client/orphan-token-recovery.ts +322 -0
- package/src/client/restore-ownership.ts +19 -1
- package/src/client/runtime-restart.ts +12 -4
- package/src/client/runtime.ts +40 -11
- package/src/client/stop-routing.ts +62 -0
- package/src/client/sync-runtime.ts +65 -0
- package/src/clients/config-export.ts +32 -3
- package/src/codex/auth-context.ts +49 -103
- package/src/codex/catalog/antigravity-discovery.ts +16 -5
- package/src/codex/catalog/provider-models.ts +18 -12
- package/src/codex/forward-transport-headers.ts +35 -6
- package/src/codex/inject/config-toml.ts +88 -0
- package/src/codex/inject/multi-agent-v2.ts +30 -4
- package/src/codex/inject/plan.ts +34 -7
- package/src/codex/inject-coordination.ts +11 -0
- package/src/codex/inject.ts +18 -7
- package/src/codex/lineage.ts +13 -7
- package/src/codex/native-profile-api.ts +27 -1
- package/src/codex/quota.ts +22 -6
- package/src/codex/request-owned-affinity-key.ts +11 -0
- package/src/codex/request-owned-affinity.ts +118 -0
- package/src/codex/request-owned-main-pin.ts +86 -0
- package/src/codex/role-capability.ts +52 -41
- package/src/codex/routing/active-account.ts +13 -5
- package/src/codex/routing/selection.ts +40 -1
- package/src/codex/routing/thread-affinity-store.ts +916 -0
- package/src/codex/routing/thread-affinity.ts +90 -12
- package/src/codex/shim-diagnostics.ts +7 -0
- package/src/codex/shim-legacy-record.ts +290 -0
- package/src/codex/shim-windows-refresh.ts +9 -2
- package/src/codex/shim-wrapper-write.ts +7 -0
- package/src/codex/shim.ts +80 -21
- package/src/codex/toml-source-lines.ts +72 -13
- package/src/combos/failover.ts +6 -109
- package/src/combos/request.ts +2 -2
- package/src/combos/resolve.ts +29 -11
- package/src/config/diagnostics.ts +9 -9
- package/src/config/load-degrade.ts +27 -27
- package/src/config/process-state.ts +5 -0
- package/src/config/provider-validation.ts +9 -2
- package/src/config/removed-opencode-free-backup.ts +6 -3
- package/src/config/schema/leaf-validators.ts +1 -0
- package/src/config/tracked-runtime-inspection.ts +3 -3
- package/src/generated/compatibility-version.json +595 -255
- package/src/images/loop.ts +4 -3
- package/src/lib/client-error-body.ts +215 -0
- package/src/lib/client-retry-after.ts +66 -0
- package/src/lib/config-ownership-removal.ts +422 -0
- package/src/lib/config-ownership.ts +650 -81
- package/src/lib/context-overflow-verdict.ts +113 -0
- package/src/lib/crash-guard.ts +4 -2
- package/src/lib/desktop-cli-handoff.d.mts +4 -5
- package/src/lib/desktop-cli-handoff.mjs +18 -17
- package/src/lib/empty-tool-catalog.ts +25 -3
- package/src/lib/error-destination.ts +47 -0
- package/src/lib/errors.ts +1 -0
- package/src/lib/failure-detail.ts +66 -0
- package/src/lib/local-management-capability.ts +3 -1
- package/src/lib/messages-error-body.ts +162 -0
- package/src/lib/messages-sse-error-presentation.ts +93 -0
- package/src/lib/model-identity.ts +44 -0
- package/src/lib/passive-read.ts +9 -4
- package/src/lib/private-sqlite-path.ts +124 -0
- package/src/lib/response-service-tier.ts +17 -0
- package/src/lib/retry-after.ts +3 -0
- package/src/lib/socks5-fetch.ts +21 -9
- package/src/lib/spend-ledger-owner.ts +43 -4
- package/src/lib/upstream-condition.ts +142 -0
- package/src/lib/upstream-retry.ts +95 -12
- package/src/lib/windows-owner-acl.ts +22 -9
- package/src/lib/winsw.ts +5 -5
- package/src/lib/workflow-budget.ts +3 -1
- package/src/link/remote-platform.ts +14 -0
- package/src/link/remote-windows.ts +51 -9
- package/src/link/ssh-argv.ts +63 -10
- package/src/oauth/generic-account-failover.ts +13 -11
- package/src/oauth/index.ts +42 -73
- package/src/oauth/oauth-errors.ts +67 -0
- package/src/oauth/store.ts +21 -11
- package/src/protocols/codecs/messages-ir.ts +15 -9
- package/src/protocols/codecs/ollama.ts +197 -0
- package/src/protocols/encoders/adapter-events.ts +30 -7
- package/src/protocols/encoders/chat.ts +18 -10
- package/src/protocols/encoders/messages.ts +72 -28
- package/src/protocols/trace.ts +18 -0
- package/src/providers/antigravity-models.ts +45 -12
- package/src/providers/fastwire.ts +3 -2
- package/src/providers/free-directory.ts +2 -2
- package/src/providers/quota/anthropic-usage-windows.ts +13 -3
- package/src/providers/quota/vendor-probes-key.ts +60 -24
- package/src/providers/reasoning-metadata.ts +2 -1
- package/src/providers/registry/entries-extended.ts +9 -0
- package/src/providers/request-pacing.ts +3 -2
- package/src/reasoning-effort.ts +7 -2
- package/src/remote/hub-usage.ts +3 -0
- package/src/responses/apply-patch-envelope.ts +45 -19
- package/src/responses/compaction-history-framing.ts +5 -1
- package/src/responses/freeform-wrapper-scan.ts +5 -3
- package/src/responses/progressive-freeform-input.ts +354 -45
- package/src/routing/fallback-policy.ts +3 -1
- package/src/server/admission-model-scope.ts +17 -6
- package/src/server/admitted-http-turn.ts +57 -0
- package/src/server/anthropic-rate-limit-headers.ts +75 -3
- package/src/server/auth-cors.ts +5 -0
- package/src/server/chat-completions.ts +45 -20
- package/src/server/chat-native-sse.ts +52 -7
- package/src/server/chat-native.ts +60 -35
- package/src/server/claude-bridge-pool-session.ts +59 -0
- package/src/server/claude-messages.ts +174 -84
- package/src/server/context-history.ts +5 -1
- package/src/server/gui-static.ts +4 -1
- package/src/server/hub-usage.ts +7 -2
- package/src/server/inbound-body-admission.ts +11 -4
- package/src/server/index/link-management.ts +8 -0
- package/src/server/index/ollama-routes.ts +91 -0
- package/src/server/index/serve-options.ts +44 -24
- package/src/server/index/startup-warnings.ts +5 -12
- package/src/server/index/websocket-handler.ts +5 -2
- package/src/server/index.ts +6 -36
- package/src/server/inference/client-encoder-delivery.ts +9 -3
- package/src/server/json-serialized-bytes.ts +44 -0
- package/src/server/management/agent-settings-routes.ts +24 -21
- package/src/server/management/codex-cli-update-routes.ts +2 -1
- package/src/server/management/logs-usage-routes.ts +89 -4
- package/src/server/management/provider-routes.ts +2 -22
- package/src/server/management/qoder-provider-probe.ts +105 -0
- package/src/server/management/route-registry.ts +4 -1
- package/src/server/management/usage-aggregate-cache.ts +15 -5
- package/src/server/management/usage-source-facets.ts +38 -0
- package/src/server/messages-native-scope.ts +2 -1
- package/src/server/messages-native-tool-guard.ts +12 -4
- package/src/server/messages-native.ts +123 -47
- package/src/server/messages-response-headers.ts +25 -11
- package/src/server/messages-shared.ts +99 -65
- package/src/server/messages-sse-error-filter.ts +199 -0
- package/src/server/native-final-log.ts +93 -0
- package/src/server/ollama-inbound.ts +349 -0
- package/src/server/ollama-native-paths.ts +21 -0
- package/src/server/ollama-route-policy.ts +73 -0
- package/src/server/relay.ts +22 -3
- package/src/server/request-decompress.ts +4 -2
- package/src/server/request-log-failure-attribution.ts +22 -0
- package/src/server/request-log-failure-detail.ts +80 -0
- package/src/server/request-log-terminal-status.ts +4 -2
- package/src/server/request-log.ts +91 -42
- package/src/server/response-log-body.ts +6 -1
- package/src/server/responses/account-change-state.ts +17 -6
- package/src/server/responses/adapter-continuation.ts +17 -6
- package/src/server/responses/adapter-delivery.ts +17 -10
- package/src/server/responses/adapter-dispatch.ts +32 -31
- package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
- package/src/server/responses/codex-auth-error.ts +24 -19
- package/src/server/responses/codex-ws-exchange.ts +11 -8
- package/src/server/responses/codex-ws-metadata.ts +94 -21
- package/src/server/responses/codex-ws-request.ts +3 -1
- package/src/server/responses/codex-ws-wire.ts +19 -3
- package/src/server/responses/compact.ts +57 -24
- package/src/server/responses/compaction-recovery.ts +4 -2
- package/src/server/responses/compaction-routing.ts +9 -4
- package/src/server/responses/core-auth.ts +32 -14
- package/src/server/responses/core-codex-account.ts +17 -6
- package/src/server/responses/core-combo-failure.ts +7 -1
- package/src/server/responses/core-combo-native.ts +2 -1
- package/src/server/responses/core-combo.ts +43 -27
- package/src/server/responses/core-errors.ts +24 -21
- package/src/server/responses/core-lifetime.ts +6 -3
- package/src/server/responses/core-normalize.ts +1 -0
- package/src/server/responses/core-options.ts +9 -0
- package/src/server/responses/core-pipeline.ts +4 -3
- package/src/server/responses/empty-completion-guard.ts +4 -1
- package/src/server/responses/fetch-helpers.ts +7 -1
- package/src/server/responses/input-admission.ts +28 -2
- package/src/server/responses/native-injection.ts +1 -1
- package/src/server/responses/native-response-json.ts +13 -4
- package/src/server/responses/native-response-output.ts +1 -2
- package/src/server/responses/non-replayable-error.ts +2 -1
- package/src/server/responses/pacing-overload.ts +3 -2
- package/src/server/responses/passthrough-delivery.ts +55 -14
- package/src/server/responses/passthrough-dispatch.ts +20 -18
- package/src/server/responses/passthrough-error.ts +9 -9
- package/src/server/responses/policy-fallback.ts +2 -1
- package/src/server/responses/request-prepare.ts +69 -48
- package/src/server/responses/request-transport.ts +36 -31
- package/src/server/responses/response-effects.ts +3 -2
- package/src/server/responses/run-turn-execution.ts +6 -6
- package/src/server/responses/sidecar-execution.ts +16 -12
- package/src/server/responses/spend-storage-error.ts +2 -1
- package/src/server/responses/terminal-guard.ts +30 -0
- package/src/server/responses/ws-upstream.ts +9 -0
- package/src/server/responses-custom-tool-repair.ts +14 -3
- package/src/server/responses-terminal-repair.ts +5 -2
- package/src/server/responses-undeclared-tool-guard.ts +39 -16
- package/src/server/restart-replacement.ts +3 -1
- package/src/server/safe-response-headers.ts +162 -13
- package/src/server/sse-payload-rewrite.ts +23 -11
- package/src/server/turn-state-handles.ts +164 -0
- package/src/server/workflow-refusal.ts +2 -1
- package/src/server/ws-bridge.ts +4 -0
- package/src/service/definition.ts +36 -4
- package/src/service/launchd.ts +89 -32
- package/src/service/logging.ts +34 -7
- package/src/service/ownership-mutation-lease.d.mts +11 -2
- package/src/service/ownership-mutation-lease.mjs +53 -11
- package/src/service/plist-xml.ts +59 -0
- package/src/service/state.ts +8 -0
- package/src/service/systemd-env.ts +2 -0
- package/src/service/systemd.ts +31 -7
- package/src/service/windows-taskxml.ts +16 -7
- package/src/service-manager-probe.ts +4 -10
- package/src/types/config.ts +2 -0
- package/src/types/provider.ts +2 -0
- package/src/types/request.ts +13 -1
- package/src/update/config-preflight.ts +48 -0
- package/src/update/index.ts +148 -26
- package/src/update/npm-install.d.mts +8 -0
- package/src/update/npm-install.mjs +20 -1
- package/src/update/orchestrated-admission.d.mts +4 -0
- package/src/update/orchestrated-admission.mjs +12 -0
- package/src/update/orchestrated-arguments.d.mts +12 -0
- package/src/update/orchestrated-arguments.mjs +64 -0
- package/src/update/orchestrated-child.d.mts +12 -0
- package/src/update/orchestrated-child.mjs +70 -0
- package/src/update/orchestrated-entry.ts +234 -0
- package/src/update/orchestrated-identity-probe-entry.ts +20 -0
- package/src/update/orchestrated-identity.ts +53 -0
- package/src/update/orchestrated-live-identity.ts +48 -0
- package/src/update/orchestrated-node-driver.mjs +99 -0
- package/src/update/orchestrated-outcome.d.mts +21 -0
- package/src/update/orchestrated-outcome.mjs +40 -0
- package/src/update/orchestrated-plan.ts +49 -0
- package/src/update/orchestrated-pnpm.d.mts +8 -0
- package/src/update/orchestrated-pnpm.mjs +33 -0
- package/src/update/orchestrated-session.d.mts +37 -0
- package/src/update/orchestrated-session.mjs +264 -0
- package/src/update/orchestrated-token.d.mts +10 -0
- package/src/update/orchestrated-token.mjs +21 -0
- package/src/update/orchestrated-token.ts +3 -0
- package/src/update/orchestrated-tree.d.mts +1 -0
- package/src/update/orchestrated-tree.mjs +14 -0
- package/src/update/pnpm-global-install.d.mts +6 -0
- package/src/update/pnpm-global-install.mjs +9 -2
- package/src/update/posix-install-supervisor-entry.mjs +6 -0
- package/src/update/posix-install-supervisor.d.mts +10 -0
- package/src/update/posix-install-supervisor.mjs +88 -0
- package/src/update/sync-update-mutex.d.mts +10 -0
- package/src/update/sync-update-mutex.mjs +164 -0
- package/src/update/sync-update-mutex.ts +1 -0
- package/src/update/test-home-guard.mjs +33 -0
- package/src/update/transactional-install.mjs +2 -2
- package/src/usage/client.ts +43 -0
- package/src/usage/error-detail.ts +225 -0
- package/src/usage/log.ts +64 -27
- package/src/usage/source-facets.ts +51 -0
- package/src/usage/source-filter.ts +65 -0
- package/src/usage/summary.ts +50 -8
- package/src/web-search/anthropic-executor.ts +105 -24
- package/src/web-search/executor.ts +5 -3
- package/src/web-search/loop.ts +33 -6
- package/src/web-search/progress-stream.ts +64 -5
- package/gui/dist/assets/App-bwugJRKn.js +0 -58
- package/gui/dist/assets/index-ebuVUtB7.js +0 -94
- package/gui/dist/assets/quota-summary-6HsrHQAy.js +0 -1
- /package/gui/dist/{assets → classic/assets}/App-B4j-Txmb.css +0 -0
- /package/gui/dist/{assets → classic/assets}/index-CHWwDo9L.css +0 -0
package/src/update/index.ts
CHANGED
|
@@ -5,11 +5,13 @@ import { manualUpdateFailureGuidance } from "./update-failure-guidance.mjs";
|
|
|
5
5
|
import { STOP_HISTORY_INCOMPLETE_EXIT_CODE } from "./stop-contract.mjs";
|
|
6
6
|
import { proxyIdentityAt } from "../server/proxy-liveness";
|
|
7
7
|
import { probeProxyLiveness } from "./proxy-liveness-probe.mjs";
|
|
8
|
+
import { verifyOrchestratedInstall } from "./orchestrated-tree.mjs";
|
|
8
9
|
import { decidePostStopUpdate } from "./stop-decision.mjs";
|
|
9
|
-
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
10
|
+
import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
|
|
10
11
|
import { fileURLToPath } from "node:url";
|
|
11
12
|
import { dirname, join, resolve } from "node:path";
|
|
12
|
-
import { getConfigDir, loadConfig } from "../config";
|
|
13
|
+
import { getConfigDir, getConfigPath, loadConfig } from "../config";
|
|
14
|
+
import { runConfigPreflight } from "./config-preflight";
|
|
13
15
|
import { readPid, readRuntimePort, getRuntimePortPath } from "../config/process-state";
|
|
14
16
|
import { pendingTeardownOutstanding } from "../config/pending-teardown";
|
|
15
17
|
import type { ServiceOwnership } from "../service/state";
|
|
@@ -43,6 +45,11 @@ import { withoutSiblingMarker } from "../codex/sibling-start";
|
|
|
43
45
|
import { packageVersion } from "../lib/package-version";
|
|
44
46
|
import { isStandaloneModuleUrl } from "../lib/standalone";
|
|
45
47
|
import { selfLaunchArgv } from "../lib/self-launch-argv";
|
|
48
|
+
import { createLegacyUpdateSession, createOrchestratedChildSession, decodeOrchestratedExpect } from "./orchestrated-session.mjs";
|
|
49
|
+
import { runPosixInstallerSync } from "./posix-install-supervisor.mjs";
|
|
50
|
+
import { runWindowsInstallerSync } from "./npm-install.mjs";
|
|
51
|
+
import { protectOrchestratedWorkerSignals } from "./orchestrated-child.mjs";
|
|
52
|
+
import type { OrchestratedChildArgs } from "./orchestrated-arguments.mjs";
|
|
46
53
|
import { PNPM_READ_CWD, withPnpmCommandCwd, pnpmReadEnvironment } from "./pnpm-read-policy.mjs";
|
|
47
54
|
import {
|
|
48
55
|
freshServingPid, hasRestartableServiceManager, readParentPid, readServiceManagerPid, restartServiceManagerJob,
|
|
@@ -109,6 +116,7 @@ function runPnpmCandidate(
|
|
|
109
116
|
args: readonly string[],
|
|
110
117
|
capture = false,
|
|
111
118
|
probeSpawn: typeof probeSpawnSync = probeSpawnSync,
|
|
119
|
+
probeEnv: NodeJS.ProcessEnv = process.env,
|
|
112
120
|
): { status: number | null; stdout?: string | null; stderr?: string | null } {
|
|
113
121
|
const invocation = pnpmInvocationForPath(commandPath, args);
|
|
114
122
|
if (!invocation) return { status: 1 };
|
|
@@ -118,7 +126,7 @@ function runPnpmCandidate(
|
|
|
118
126
|
timeout: 20_000,
|
|
119
127
|
windowsHide: true,
|
|
120
128
|
cwd: PNPM_READ_CWD,
|
|
121
|
-
env: pnpmReadEnvironment(unprivilegedOwnershipMutationEnvironment(
|
|
129
|
+
env: pnpmReadEnvironment(unprivilegedOwnershipMutationEnvironment(probeEnv)),
|
|
122
130
|
...invocation.options,
|
|
123
131
|
});
|
|
124
132
|
}
|
|
@@ -126,7 +134,7 @@ function runPnpmCandidate(
|
|
|
126
134
|
/** Resolve the exact pnpm executable/group/bin that own this package. */
|
|
127
135
|
export function resolveCurrentPnpmGlobalOwner(
|
|
128
136
|
invoked = process.argv[1],
|
|
129
|
-
deps: { commandPaths?: readonly string[]; spawn?: typeof probeSpawnSync } = {},
|
|
137
|
+
deps: { commandPaths?: readonly string[]; spawn?: typeof probeSpawnSync; env?: NodeJS.ProcessEnv } = {},
|
|
130
138
|
): PnpmGlobalOwnerResult {
|
|
131
139
|
const probeSpawn = deps.spawn ?? probeSpawnSync;
|
|
132
140
|
return resolvePnpmGlobalOwner({
|
|
@@ -134,7 +142,7 @@ export function resolveCurrentPnpmGlobalOwner(
|
|
|
134
142
|
packagePath: packageRoot(),
|
|
135
143
|
commandPaths: deps.commandPaths ?? resolvePnpmCommands(),
|
|
136
144
|
runningShimPath: runningPnpmShimPath(invoked),
|
|
137
|
-
runPnpm: (commandPath, args, capture) => runPnpmCandidate(commandPath, args, capture, probeSpawn),
|
|
145
|
+
runPnpm: (commandPath, args, capture) => runPnpmCandidate(commandPath, args, capture, probeSpawn, deps.env),
|
|
138
146
|
});
|
|
139
147
|
}
|
|
140
148
|
|
|
@@ -159,10 +167,30 @@ export function runOwnedPnpm(
|
|
|
159
167
|
stdio: "inherit" | "pipe" | "ignore" = capture ? "pipe" : "inherit",
|
|
160
168
|
probeSpawn: typeof probeSpawnSync = probeSpawnSync,
|
|
161
169
|
authorizeMutation: (kind: "package") => boolean = () => ["root", "bin", "list", "config", "view", "--version"].includes(args[0] ?? ""),
|
|
162
|
-
|
|
170
|
+
session?: Pick<ReturnType<typeof createOrchestratedChildSession>, "retainInstallerFence" | "noteUntrackedInstaller" | "confirmInstallerExit">,
|
|
171
|
+
markerPath = join(getConfigDir(), "update-orchestrated.json"),
|
|
172
|
+
): { status: number | null; stdout?: string | null; stderr?: string | null; processTreeExited?: boolean } {
|
|
163
173
|
const target = ownerPnpmTarget(owner, args);
|
|
164
174
|
if (!target) return { status: 1 };
|
|
165
|
-
|
|
175
|
+
const mutating = ["add", "install", "update", "remove", "uninstall"].includes(args[0] ?? "");
|
|
176
|
+
try { return withPnpmCommandCwd(args, cwd => {
|
|
177
|
+
if (mutating && !capture && session && authorizeMutation("package")) {
|
|
178
|
+
const env = pnpmReadEnvironment(unprivilegedOwnershipMutationEnvironment(target.env));
|
|
179
|
+
if (process.platform === "win32") {
|
|
180
|
+
session.noteUntrackedInstaller();
|
|
181
|
+
const result = runWindowsInstallerSync({ file: target.bin, args: target.args, options: target.options }, { cwd, env, authorizeMutation });
|
|
182
|
+
if (result.processTreeExited && Number.isInteger(result.status)) session.confirmInstallerExit();
|
|
183
|
+
else { session.retainInstallerFence(); return { ...result, processTreeExited: false }; }
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
const result = runPosixInstallerSync({ file: target.bin, args: target.args, markerPath, cwd, env, authorizeMutation });
|
|
187
|
+
if (!Number.isInteger(result.status) || result.signal || !result.groupExited || result.groupKilled !== false || result.processTreeExited === false) {
|
|
188
|
+
session.retainInstallerFence();
|
|
189
|
+
return { ...result, processTreeExited: false };
|
|
190
|
+
}
|
|
191
|
+
return { ...result, processTreeExited: true };
|
|
192
|
+
}
|
|
193
|
+
const result = authorizeMutation("package") ? guardedSpawnSync(authorizeMutation, "package", target.bin, target.args, {
|
|
166
194
|
stdio,
|
|
167
195
|
encoding: "utf8",
|
|
168
196
|
timeout: 180_000,
|
|
@@ -172,7 +200,10 @@ export function runOwnedPnpm(
|
|
|
172
200
|
cwd,
|
|
173
201
|
env: pnpmReadEnvironment(unprivilegedOwnershipMutationEnvironment(target.env)),
|
|
174
202
|
...target.options,
|
|
175
|
-
|
|
203
|
+
}, probeSpawn) : { status: 1, signal: null };
|
|
204
|
+
if (mutating && (!Number.isInteger(result.status) || result.signal)) session?.retainInstallerFence();
|
|
205
|
+
return result;
|
|
206
|
+
}); } catch (error) { if (mutating) session?.retainInstallerFence(); throw error; }
|
|
176
207
|
}
|
|
177
208
|
|
|
178
209
|
/** Re-read the owning group's active package and return its verified launcher. */
|
|
@@ -221,9 +252,9 @@ function npmSpawnTarget(args: readonly string[]): SpawnTarget | null {
|
|
|
221
252
|
return { bin: invocation.file, args: invocation.args, options: invocation.options };
|
|
222
253
|
}
|
|
223
254
|
|
|
224
|
-
function pnpmSpawnTarget(args: readonly string[], owner?: PnpmGlobalOwner): SpawnTarget | null {
|
|
255
|
+
function pnpmSpawnTarget(args: readonly string[], owner?: PnpmGlobalOwner, env?: NodeJS.ProcessEnv): SpawnTarget | null {
|
|
225
256
|
if (owner) {
|
|
226
|
-
const invocation = pnpmOwnerInvocation(owner, args);
|
|
257
|
+
const invocation = pnpmOwnerInvocation(owner, args, process.platform, env);
|
|
227
258
|
if (!invocation) return null;
|
|
228
259
|
return {
|
|
229
260
|
bin: invocation.file,
|
|
@@ -241,19 +272,20 @@ export function registrySpawnTarget(
|
|
|
241
272
|
installer: Installer,
|
|
242
273
|
args: readonly string[],
|
|
243
274
|
owner?: PnpmGlobalOwner,
|
|
275
|
+
env?: NodeJS.ProcessEnv,
|
|
244
276
|
): SpawnTarget | null {
|
|
245
277
|
if (installer === "standalone") return null;
|
|
246
278
|
// A pnpm command without an owner would silently fall back to the first PATH
|
|
247
279
|
// candidate. That is unsafe when multiple PNPM_HOME installations expose the
|
|
248
280
|
// same version, so registry queries use the same hard binding as mutation.
|
|
249
281
|
return installer === "pnpm"
|
|
250
|
-
? owner ? pnpmSpawnTarget(args, owner) : null
|
|
282
|
+
? owner ? pnpmSpawnTarget(args, owner, env) : null
|
|
251
283
|
: npmSpawnTarget(args);
|
|
252
284
|
}
|
|
253
285
|
|
|
254
|
-
function selectedPnpmOwner(owner?: PnpmGlobalOwner): PnpmGlobalOwner | undefined {
|
|
286
|
+
function selectedPnpmOwner(owner?: PnpmGlobalOwner, probeSpawn?: typeof probeSpawnSync, env?: NodeJS.ProcessEnv): PnpmGlobalOwner | undefined {
|
|
255
287
|
if (owner) return owner;
|
|
256
|
-
const result = resolveCurrentPnpmGlobalOwner();
|
|
288
|
+
const result = resolveCurrentPnpmGlobalOwner(undefined, { spawn: probeSpawn, env });
|
|
257
289
|
return result.ok ? result.owner : undefined;
|
|
258
290
|
}
|
|
259
291
|
|
|
@@ -299,10 +331,11 @@ export function latestVersion(
|
|
|
299
331
|
installer: Installer = detectInstall(),
|
|
300
332
|
owner?: PnpmGlobalOwner,
|
|
301
333
|
probeSpawn: typeof probeSpawnSync = probeSpawnSync,
|
|
334
|
+
probeEnv?: NodeJS.ProcessEnv,
|
|
302
335
|
): string | null {
|
|
303
|
-
const resolvedOwner = installer === "pnpm" ? selectedPnpmOwner(owner) : undefined;
|
|
336
|
+
const resolvedOwner = installer === "pnpm" ? selectedPnpmOwner(owner, probeSpawn, probeEnv) : undefined;
|
|
304
337
|
if (installer === "pnpm" && !resolvedOwner) return null;
|
|
305
|
-
const manager = registrySpawnTarget(installer, ["view", `${PKG}@${tag}`, "version"], resolvedOwner);
|
|
338
|
+
const manager = registrySpawnTarget(installer, ["view", `${PKG}@${tag}`, "version"], resolvedOwner, probeEnv);
|
|
306
339
|
if (!manager) return null;
|
|
307
340
|
const r = probeSpawn(manager.bin, manager.args, {
|
|
308
341
|
encoding: "utf8",
|
|
@@ -310,8 +343,8 @@ export function latestVersion(
|
|
|
310
343
|
windowsHide: true,
|
|
311
344
|
cwd: installer === "pnpm" ? PNPM_READ_CWD : undefined,
|
|
312
345
|
env: installer === "pnpm"
|
|
313
|
-
? pnpmReadEnvironment(unprivilegedOwnershipMutationEnvironment(manager.env ?? process.env))
|
|
314
|
-
: unprivilegedOwnershipMutationEnvironment(manager.env ?? process.env),
|
|
346
|
+
? pnpmReadEnvironment(unprivilegedOwnershipMutationEnvironment(manager.env ?? probeEnv ?? process.env))
|
|
347
|
+
: unprivilegedOwnershipMutationEnvironment(manager.env ?? probeEnv ?? process.env),
|
|
315
348
|
...manager.options,
|
|
316
349
|
});
|
|
317
350
|
return r.status === 0 && typeof r.stdout === "string" ? (r.stdout.trim() || null) : null;
|
|
@@ -417,9 +450,35 @@ async function resolvedRuntimeOwnership(): Promise<RuntimeOwnershipObservation>
|
|
|
417
450
|
* are updated in the Node bin launcher before Bun starts, so Windows does not replace the running
|
|
418
451
|
* Bun binary.
|
|
419
452
|
*/
|
|
420
|
-
export async function runUpdate(): Promise<void> {
|
|
453
|
+
export async function runUpdate(child?: Extract<OrchestratedChildArgs, { ok: true }>): Promise<void> {
|
|
454
|
+
let session: ReturnType<typeof createOrchestratedChildSession> | undefined;
|
|
455
|
+
if (child) {
|
|
456
|
+
try {
|
|
457
|
+
const expect = decodeOrchestratedExpect(child.expect);
|
|
458
|
+
session = createOrchestratedChildSession({ home: getConfigDir(), resultPath: child.resultPath, resultCapability: child.resultCapability, expect, notAfter: child.notAfter,
|
|
459
|
+
verifyIdentity: async () => (await import("./orchestrated-entry")).verifyOrchestratedChildIdentity(expect, child.version) });
|
|
460
|
+
if (!session.start().ok) { process.exitCode = 10; return; }
|
|
461
|
+
protectOrchestratedWorkerSignals();
|
|
462
|
+
} catch (error) {
|
|
463
|
+
console.error(`Orchestrated update preflight failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
464
|
+
process.exitCode = 1;
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
} else {
|
|
468
|
+
session = createLegacyUpdateSession({ home: getConfigDir() });
|
|
469
|
+
const started = session.start();
|
|
470
|
+
if (!started.ok) { console.error(`opencodex: ${started.error}`); process.exitCode = 1; return; }
|
|
471
|
+
process.once("exit", () => session?.finishPreflight());
|
|
472
|
+
}
|
|
473
|
+
try { await runUpdateWithSession(child, session); }
|
|
474
|
+
finally { session?.finishPreflight(); }
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
async function runUpdateWithSession(child: Extract<OrchestratedChildArgs, { ok: true }> | undefined,
|
|
478
|
+
session: ReturnType<typeof createOrchestratedChildSession> | undefined): Promise<void> {
|
|
421
479
|
const ownership = detectInstallOwnership();
|
|
422
480
|
const installer = ownership.installer;
|
|
481
|
+
if (child && installer !== "bun") { process.exitCode = 1; return; }
|
|
423
482
|
const current = currentVersion();
|
|
424
483
|
const tag = updateTag(current);
|
|
425
484
|
console.log(`opencodex v${current} (installed via ${installer}, tag ${tag})`);
|
|
@@ -454,9 +513,10 @@ export async function runUpdate(): Promise<void> {
|
|
|
454
513
|
process.exit(1);
|
|
455
514
|
}
|
|
456
515
|
const owner = ownerResult?.ok ? ownerResult.owner : undefined;
|
|
457
|
-
const latest = latestVersion(tag, installer, owner);
|
|
516
|
+
const latest = child?.version ?? latestVersion(tag, installer, owner);
|
|
458
517
|
if (latest && latest === current) {
|
|
459
518
|
console.log(`Already on the latest ${tag} version (v${latest}).`);
|
|
519
|
+
if (child) process.exitCode = 1;
|
|
460
520
|
return;
|
|
461
521
|
}
|
|
462
522
|
|
|
@@ -465,6 +525,7 @@ export async function runUpdate(): Promise<void> {
|
|
|
465
525
|
const integrity = checkUpdatePackageIntegrity(latest, probeSpawnSync, installer, owner);
|
|
466
526
|
if (integrity.ok === false) {
|
|
467
527
|
console.error(`⚠️ ${integrity.reason} — aborting the update before stopping the proxy.`);
|
|
528
|
+
if (child) { process.exitCode = 1; return; }
|
|
468
529
|
process.exit(1);
|
|
469
530
|
}
|
|
470
531
|
if (integrity.ok === "skipped") {
|
|
@@ -487,16 +548,33 @@ export async function runUpdate(): Promise<void> {
|
|
|
487
548
|
: updateSpawnTarget(bin, cmdArgs);
|
|
488
549
|
if (!target) {
|
|
489
550
|
console.error(`⚠️ Could not resolve ${bin} from a trusted absolute PATH entry; aborting before stopping the proxy.`);
|
|
551
|
+
if (child) { process.exitCode = 1; return; }
|
|
490
552
|
process.exit(1);
|
|
491
553
|
}
|
|
492
554
|
|
|
493
555
|
const { serviceStatePaths } = await import("../service");
|
|
494
|
-
|
|
556
|
+
let mutationStarted = false, completed = false, installerUncertain = false, installedRoot: string | undefined;
|
|
557
|
+
let updateExitCode: number | undefined;
|
|
558
|
+
try {
|
|
559
|
+
updateExitCode = await withUpdateOwnershipLease(serviceStatePaths(), async mutation => {
|
|
495
560
|
// Ownership inspection imports the service CLI, which reaches this update entry again.
|
|
496
561
|
// Load it only after entering the lease; the policy itself stays a dependency-free import.
|
|
497
562
|
const { inspectUpdateServiceHome } = await import("./service-home-authority");
|
|
498
563
|
const homePolicy = createUpdateServiceHomePolicy(inspectUpdateServiceHome, message => console.warn(message), process.argv.includes("--update-package-only"), parseUpdateWorkerHome(process.argv));
|
|
499
564
|
if (!homePolicy.authorizeMutation("package")) return 1;
|
|
565
|
+
const configPath = getConfigPath(), configPreflight = runConfigPreflight(configPath);
|
|
566
|
+
if (!configPreflight.ok) {
|
|
567
|
+
console.error(`⚠️ Configuration preflight failed for ${configPath}; aborting update before stopping services.`);
|
|
568
|
+
if (configPreflight.error) console.error(` ${configPreflight.error}`);
|
|
569
|
+
if (configPreflight.reason === "read_error") {
|
|
570
|
+
console.error(" Inspect the config path, permissions, and any symlink target; correct them or restore a readable regular config from a trusted backup, then retry.");
|
|
571
|
+
console.error(" 'ocx config validate' may report defaults if a symlink target is missing; it does not change the file.");
|
|
572
|
+
} else {
|
|
573
|
+
console.error(" Run 'ocx config validate' to diagnose the configuration; it does not change the file. Back up and correct the file, then retry.");
|
|
574
|
+
}
|
|
575
|
+
return 1;
|
|
576
|
+
}
|
|
577
|
+
|
|
500
578
|
// Remember whether a background service manages the proxy BEFORE stopping — `ocx stop`
|
|
501
579
|
// unloads it, so a successful update must repair/restart it afterwards.
|
|
502
580
|
let serviceWasInstalled = false;
|
|
@@ -519,6 +597,11 @@ export async function runUpdate(): Promise<void> {
|
|
|
519
597
|
console.error("⚠️ Update stopped before tray handoff, runtime stop, or package replacement because runtime authority does not permit it.");
|
|
520
598
|
return 1;
|
|
521
599
|
}
|
|
600
|
+
if (session) {
|
|
601
|
+
const admission = await session.enterMutation();
|
|
602
|
+
if (!admission.ok) return 10;
|
|
603
|
+
mutationStarted = true;
|
|
604
|
+
}
|
|
522
605
|
let trayWasInstalled = false;
|
|
523
606
|
let trayWasRunning = false;
|
|
524
607
|
if (!homePolicy.packageOnly && process.platform === "win32") {
|
|
@@ -869,6 +952,7 @@ export async function runUpdate(): Promise<void> {
|
|
|
869
952
|
// Every post-update action below receives the verified active launcher.
|
|
870
953
|
if (installer === "pnpm") {
|
|
871
954
|
let update: ReturnType<typeof runPnpmGlobalUpdate>;
|
|
955
|
+
installerUncertain = true;
|
|
872
956
|
try {
|
|
873
957
|
if (!homePolicy.authorizeMutation("package")) return 1;
|
|
874
958
|
update = runPnpmGlobalUpdate({
|
|
@@ -883,7 +967,7 @@ export async function runUpdate(): Promise<void> {
|
|
|
883
967
|
args,
|
|
884
968
|
capture,
|
|
885
969
|
capture ? "pipe" : installStdio,
|
|
886
|
-
probeSpawnSync, homePolicy.authorizeMutation,
|
|
970
|
+
probeSpawnSync, homePolicy.authorizeMutation, session,
|
|
887
971
|
) : { status: 1, stdout: "", stderr: "" },
|
|
888
972
|
log: line => console.log(line),
|
|
889
973
|
});
|
|
@@ -894,9 +978,12 @@ export async function runUpdate(): Promise<void> {
|
|
|
894
978
|
ok: false,
|
|
895
979
|
phase: "rollback",
|
|
896
980
|
rolledBack: false,
|
|
981
|
+
processTreeExited: false,
|
|
897
982
|
error: "pnpm update failed unexpectedly; active package could not be verified",
|
|
898
983
|
};
|
|
984
|
+
session?.retainInstallerFence();
|
|
899
985
|
}
|
|
986
|
+
installerUncertain = !update.ok && update.processTreeExited === false;
|
|
900
987
|
if (update.ok) {
|
|
901
988
|
postUpdateLauncher = join(update.path, "bin", "ocx.mjs");
|
|
902
989
|
postUpdateLauncherUsable = true;
|
|
@@ -909,14 +996,35 @@ export async function runUpdate(): Promise<void> {
|
|
|
909
996
|
}
|
|
910
997
|
} else {
|
|
911
998
|
if (!homePolicy.authorizeMutation("package")) return 1;
|
|
912
|
-
|
|
999
|
+
installerUncertain = true;
|
|
1000
|
+
if (session && process.platform === "win32") {
|
|
1001
|
+
session.noteUntrackedInstaller();
|
|
1002
|
+
const supervised = runWindowsInstallerSync({ file: target.bin, args: target.args, options: target.options }, {
|
|
1003
|
+
env: mutation.unprivilegedEnvironment(), authorizeMutation: homePolicy.authorizeMutation,
|
|
1004
|
+
});
|
|
1005
|
+
if (supervised.processTreeExited === true && Number.isInteger(supervised.status)) session.confirmInstallerExit();
|
|
1006
|
+
else session.retainInstallerFence();
|
|
1007
|
+
r = supervised;
|
|
1008
|
+
installerUncertain = supervised.processTreeExited !== true || !Number.isInteger(supervised.status);
|
|
1009
|
+
} else if (session) {
|
|
1010
|
+
try {
|
|
1011
|
+
const supervised = runPosixInstallerSync({ file: target.bin, args: target.args,
|
|
1012
|
+
markerPath: join(getConfigDir(), "update-orchestrated.json"),
|
|
1013
|
+
authorizeMutation: homePolicy.authorizeMutation, env: mutation.unprivilegedEnvironment() });
|
|
1014
|
+
installerUncertain = !Number.isInteger(supervised.status) || Boolean(supervised.signal) || !supervised.groupExited || supervised.groupKilled !== false || supervised.processTreeExited === false;
|
|
1015
|
+
if (installerUncertain) session.retainInstallerFence();
|
|
1016
|
+
r = supervised;
|
|
1017
|
+
} catch (error) { session.retainInstallerFence(); throw error; }
|
|
1018
|
+
} else r = guardedSpawnSync(homePolicy.authorizeMutation, "package", target.bin, target.args, {
|
|
913
1019
|
stdio: installStdio,
|
|
914
1020
|
encoding: installStdio === "pipe" ? "utf8" : undefined,
|
|
915
|
-
|
|
1021
|
+
// The parent watchdog reports overrun without killing an active transaction.
|
|
1022
|
+
timeout: child ? undefined : 180000,
|
|
916
1023
|
windowsHide: true,
|
|
917
1024
|
...target.options,
|
|
918
1025
|
env: mutation.unprivilegedEnvironment(),
|
|
919
1026
|
});
|
|
1027
|
+
if (!session) installerUncertain = r.status === null;
|
|
920
1028
|
}
|
|
921
1029
|
if (r && installStdio === "pipe") logSpawnOutput("", r);
|
|
922
1030
|
}
|
|
@@ -932,6 +1040,11 @@ export async function runUpdate(): Promise<void> {
|
|
|
932
1040
|
return 1;
|
|
933
1041
|
}
|
|
934
1042
|
if (!r) throw new Error("update replacement returned no result");
|
|
1043
|
+
if (installerUncertain) { console.error("Installer termination was not confirmed; update recovery is deferred."); return 1; }
|
|
1044
|
+
if (session && r.status === 0 && latest) {
|
|
1045
|
+
const root = realpathSync.native(packageRoot());
|
|
1046
|
+
if (verifyOrchestratedInstall(root, latest, "bun")) installedRoot = root;
|
|
1047
|
+
}
|
|
935
1048
|
const postInstallPlan = planUpdateRuntimeHandling({
|
|
936
1049
|
...(await resolvedRuntimeOwnership()),
|
|
937
1050
|
serviceInstalled: serviceWasInstalled,
|
|
@@ -1186,12 +1299,21 @@ export async function runUpdate(): Promise<void> {
|
|
|
1186
1299
|
return 1;
|
|
1187
1300
|
}
|
|
1188
1301
|
} catch (error) {
|
|
1189
|
-
await recoverStoppedRuntime("update failed unexpectedly");
|
|
1190
|
-
if (trayWasRunning) {
|
|
1302
|
+
if (!installerUncertain) await recoverStoppedRuntime("update failed unexpectedly");
|
|
1303
|
+
if (trayWasRunning && !installerUncertain) {
|
|
1191
1304
|
try { const { guardedStartWindowsTray } = await import("./guarded-tray-ops"); if (homePolicy.authorizeMutation("own-tray")) guardedStartWindowsTray(homePolicy.authorizeMutation); } catch { /* retain original failure */ }
|
|
1192
1305
|
}
|
|
1193
1306
|
throw error;
|
|
1194
1307
|
}
|
|
1195
1308
|
});
|
|
1196
|
-
|
|
1309
|
+
completed = true;
|
|
1310
|
+
} finally {
|
|
1311
|
+
if (session && mutationStarted) session.finish(installedRoot
|
|
1312
|
+
? { phase: "installed", activeRoot: installedRoot, ...(!completed || updateExitCode ? { recoveryFailed: true, error: "runtime-unhealthy" } : {}) }
|
|
1313
|
+
: { phase: "failed", error: installerUncertain ? "installer-timeout" : "update-failed", ...(installerUncertain ? { terminationConfirmed: false } : {}) });
|
|
1314
|
+
}
|
|
1315
|
+
if (updateExitCode) {
|
|
1316
|
+
if (child) process.exitCode = updateExitCode;
|
|
1317
|
+
else process.exit(updateExitCode);
|
|
1318
|
+
} else if (child && !mutationStarted) process.exitCode = 1;
|
|
1197
1319
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NpmInvocation } from "./npm-invocation.mjs";
|
|
2
|
+
|
|
3
|
+
export declare function runWindowsInstallerSync(invocation: NpmInvocation, options?: {
|
|
4
|
+
env?: NodeJS.ProcessEnv;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
authorizeMutation?: (kind: "package") => boolean;
|
|
8
|
+
}): { status: number | null; processTreeExited: boolean };
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
// Windows Node-launcher compatibility code. The install owns its entire process tree until
|
|
2
2
|
// exit is proved; a timeout signal alone never authorizes stage removal.
|
|
3
|
-
import { guardedSpawn, materializeMutationData } from "./mutation-guard.mjs";
|
|
3
|
+
import { guardedSpawn, guardedSpawnSync, materializeMutationData } from "./mutation-guard.mjs";
|
|
4
4
|
import { dirname, join, win32 } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
|
|
7
7
|
const JOIN_MS = 10000;
|
|
8
8
|
const failure = message => ({ status: null, processTreeExited: false, error: { code: "EINSTALLJOIN", message } });
|
|
9
9
|
|
|
10
|
+
/** Bridge synchronous pnpm transactions to the same Windows Job Object barrier. */
|
|
11
|
+
export function runWindowsInstallerSync(invocation, { env = process.env, cwd, timeoutMs = 180000, authorizeMutation = () => false } = {}) {
|
|
12
|
+
const moduleUrl = import.meta.url;
|
|
13
|
+
const script = `import {readFileSync} from 'node:fs';import {runNpmInstall} from ${JSON.stringify(moduleUrl)};const input=JSON.parse(readFileSync(0,'utf8'));console.log(JSON.stringify(await runNpmInstall(input.invocation,{timeoutMs:input.timeoutMs,authorizeMutation:()=>true})));`;
|
|
14
|
+
const result = guardedSpawnSync(authorizeMutation, "package", process.execPath, ["--input-type=module", "-e", script], {
|
|
15
|
+
input: JSON.stringify({ invocation, timeoutMs }), env, cwd, encoding: "utf8", windowsHide: true, stdio: ["pipe", "pipe", "inherit"],
|
|
16
|
+
});
|
|
17
|
+
try {
|
|
18
|
+
const value = JSON.parse(result.stdout);
|
|
19
|
+
if (result.status !== 0 || typeof value.processTreeExited !== "boolean") throw Error("invalid supervisor result");
|
|
20
|
+
return value;
|
|
21
|
+
} catch { return failure("Windows installer supervisor did not confirm process-tree exit"); }
|
|
22
|
+
}
|
|
23
|
+
|
|
10
24
|
function quoteWindowsArg(value) {
|
|
11
25
|
return '"' + value.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1") + '"';
|
|
12
26
|
}
|
|
@@ -16,6 +30,11 @@ export async function runNpmInstall(invocation, { env = process.env, timeoutMs =
|
|
|
16
30
|
env = materializeMutationData(env);
|
|
17
31
|
if (!invocation) return { status: 1, processTreeExited: true, error: { code: "ENOENT", message: "npm invocation unavailable" } };
|
|
18
32
|
if (process.platform === "win32") {
|
|
33
|
+
// The PowerShell helper assigns npm to a kill-on-close Job Object before it
|
|
34
|
+
// resumes the suspended process, then terminates the job on timeout and
|
|
35
|
+
// waits for the job to become empty. An unconfirmed join retains the stage.
|
|
36
|
+
// Windows acceptance still needs orchestrated npm and pnpm worker tests proving
|
|
37
|
+
// marker visibility across supervisor failure and Job Object termination.
|
|
19
38
|
// Resolve from the same absolute system directory as the hardened cmd hop.
|
|
20
39
|
// Never search PATH for PowerShell, and never interpolate the JSON as code.
|
|
21
40
|
const roots = new Set(Object.entries(env).filter(([key, value]) => key.toLowerCase() === "systemroot" && value !== undefined).map(([, value]) => value));
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { observeOrchestratedPlan } from "./orchestrated-entry";
|
|
2
|
+
import type { OrchestratedUpdateArgs } from "./orchestrated-arguments.mjs";
|
|
3
|
+
export declare function decideOrchestratedApply(plan: Awaited<ReturnType<typeof observeOrchestratedPlan>>, request: Extract<OrchestratedUpdateArgs, { ok: true }>, now: number):
|
|
4
|
+
| { kind: "proceed" } | { kind: "done"; exitCode: 0 | 10; result: { schema: "ocx.update.result/1"; applied: boolean; fromVersion: string; toVersion: string | null; installer: string; restarted: boolean; healthy: boolean; rolledBack: boolean; error?: string } };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Resolve decisions that require no mutation before starting an update worker. */
|
|
2
|
+
export function decideOrchestratedApply(plan, request, now) {
|
|
3
|
+
const result = { schema: "ocx.update.result/1", applied: false, fromVersion: plan.currentVersion,
|
|
4
|
+
toVersion: plan.targetVersion, installer: plan.installer, restarted: false, healthy: false, rolledBack: false };
|
|
5
|
+
const refuse = error => ({ kind: "done", exitCode: 10, result: { ...result, error } });
|
|
6
|
+
if (request.expectPlan && request.expectPlan !== plan.planToken) return refuse("plan-changed");
|
|
7
|
+
if (request.notAfter !== undefined && now > request.notAfter) return refuse("deadline-passed");
|
|
8
|
+
if (plan.updateInFlight) return refuse("update-in-flight");
|
|
9
|
+
if (plan.reason === "up-to-date") return { kind: "done", exitCode: 0, result };
|
|
10
|
+
if (!plan.canApply) return refuse(plan.reason ?? "plan-unavailable");
|
|
11
|
+
return { kind: "proceed" };
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type OrchestratedUpdateArgs = { ok: false } | {
|
|
2
|
+
ok: true;
|
|
3
|
+
mode: "plan" | "apply";
|
|
4
|
+
tag?: "latest" | "preview";
|
|
5
|
+
version?: string;
|
|
6
|
+
expectPlan?: string;
|
|
7
|
+
notAfter?: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function parseOrchestratedUpdateArgs(argv: readonly string[]): OrchestratedUpdateArgs;
|
|
10
|
+
export declare function isOrchestratedUpdateArgv(argv: readonly string[]): boolean;
|
|
11
|
+
export type OrchestratedChildArgs = { ok: false } | { ok: true; version: string; expect: string; resultPath: string; resultCapability: string; notAfter?: number };
|
|
12
|
+
export declare function parseOrchestratedChildArgs(argv: readonly string[], env: Record<string, string | undefined>): OrchestratedChildArgs;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const CORE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
|
|
2
|
+
|
|
3
|
+
export function isOrchestratedUpdateArgv(argv) {
|
|
4
|
+
return argv.some(arg => /^(--plan|--yes|--json|--expect-plan|--not-after|--orchestrated-expect|--orchestrated-result)(?:=|$)/.test(arg));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal child grammar is accepted only in the explicitly marked child process, with its result capability.
|
|
9
|
+
* The capability is taken out of env on every call, so no subprocess started afterwards inherits it.
|
|
10
|
+
*/
|
|
11
|
+
export function parseOrchestratedChildArgs(argv, env) {
|
|
12
|
+
const resultCapability = env.OCX_UPDATE_RESULT_CAPABILITY;
|
|
13
|
+
delete env.OCX_UPDATE_RESULT_CAPABILITY;
|
|
14
|
+
if (env.OCX_UPDATE_ORCHESTRATED_CHILD !== "1") return { ok: false };
|
|
15
|
+
if (typeof resultCapability !== "string" || !/^[A-Za-z0-9_-]{43}$/.test(resultCapability)) return { ok: false };
|
|
16
|
+
const values = new Map();
|
|
17
|
+
const allowed = new Set(["--version", "--orchestrated-expect", "--orchestrated-result", "--not-after"]);
|
|
18
|
+
for (let i = 0; i < argv.length; i++) {
|
|
19
|
+
const flag = argv[i], value = argv[++i];
|
|
20
|
+
if (!allowed.has(flag) || values.has(flag) || !value || value.startsWith("-")) return { ok: false };
|
|
21
|
+
values.set(flag, value);
|
|
22
|
+
}
|
|
23
|
+
const version = values.get("--version"), expect = values.get("--orchestrated-expect"), resultPath = values.get("--orchestrated-result"), deadline = values.get("--not-after");
|
|
24
|
+
if (!version || !strictSemver(version) || !expect || !resultPath || (deadline !== undefined
|
|
25
|
+
&& (!/^\d+$/.test(deadline) || !Number.isSafeInteger(Number(deadline)) || Number(deadline) <= 0))) return { ok: false };
|
|
26
|
+
return { ok: true, version, expect, resultPath, resultCapability, ...(deadline === undefined ? {} : { notAfter: Number(deadline) }) };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function strictSemver(value) {
|
|
30
|
+
if (value.length > 128) return false;
|
|
31
|
+
const match = CORE.exec(value);
|
|
32
|
+
return Boolean(match && (match[4] === undefined || match[4].split(".").every(part =>
|
|
33
|
+
part.length > 0 && /^[0-9A-Za-z-]+$/.test(part) && (!/^\d+$/.test(part) || /^(0|[1-9]\d*)$/.test(part)))));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Parse only the public orchestrated grammar; callers map an invalid result to exit 64. */
|
|
37
|
+
export function parseOrchestratedUpdateArgs(argv) {
|
|
38
|
+
const flags = new Map();
|
|
39
|
+
const switches = new Set(["--plan", "--yes", "--json"]);
|
|
40
|
+
const values = new Set(["--tag", "--version", "--expect-plan", "--not-after"]);
|
|
41
|
+
for (let i = 0; i < argv.length; i++) {
|
|
42
|
+
const arg = argv[i];
|
|
43
|
+
if (switches.has(arg)) {
|
|
44
|
+
if (flags.has(arg)) return { ok: false };
|
|
45
|
+
flags.set(arg, true);
|
|
46
|
+
} else if (values.has(arg)) {
|
|
47
|
+
if (flags.has(arg) || i + 1 >= argv.length || argv[i + 1].startsWith("-")) return { ok: false };
|
|
48
|
+
flags.set(arg, argv[++i]);
|
|
49
|
+
} else return { ok: false };
|
|
50
|
+
}
|
|
51
|
+
const plan = flags.has("--plan"), apply = flags.has("--yes");
|
|
52
|
+
if (plan === apply || !flags.has("--json")) return { ok: false };
|
|
53
|
+
if (flags.has("--tag") && flags.has("--version")) return { ok: false };
|
|
54
|
+
const tag = flags.get("--tag"), version = flags.get("--version");
|
|
55
|
+
if (tag !== undefined && tag !== "latest" && tag !== "preview") return { ok: false };
|
|
56
|
+
if (version !== undefined && !strictSemver(version)) return { ok: false };
|
|
57
|
+
const expectPlan = flags.get("--expect-plan"), deadline = flags.get("--not-after");
|
|
58
|
+
if (plan && (expectPlan !== undefined || deadline !== undefined)) return { ok: false };
|
|
59
|
+
if (expectPlan !== undefined && !/^[A-Za-z0-9_-]{16,128}$/.test(expectPlan)) return { ok: false };
|
|
60
|
+
if (deadline !== undefined && (!/^\d+$/.test(deadline) || !Number.isSafeInteger(Number(deadline)) || Number(deadline) <= 0)) return { ok: false };
|
|
61
|
+
return { ok: true, mode: plan ? "plan" : "apply", ...(tag === undefined ? {} : { tag }),
|
|
62
|
+
...(version === undefined ? {} : { version }), ...(expectPlan === undefined ? {} : { expectPlan }),
|
|
63
|
+
...(deadline === undefined ? {} : { notAfter: Number(deadline) }) };
|
|
64
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ChildProcess } from "node:child_process";
|
|
2
|
+
import type { EventEmitter } from "node:events";
|
|
3
|
+
|
|
4
|
+
export declare function protectOrchestratedWorkerSignals(): void;
|
|
5
|
+
|
|
6
|
+
export declare function waitForOrchestratedChild(child: ChildProcess, options?: {
|
|
7
|
+
signals?: EventEmitter;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
overrunMs?: number;
|
|
10
|
+
setTimer?: (callback: () => void, timeoutMs: number) => unknown;
|
|
11
|
+
clearTimer?: (timer: unknown) => void;
|
|
12
|
+
}): Promise<{ confirmed: boolean; code: number | null; signal: NodeJS.Signals | null; reason?: "overrun" }>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
2
|
+
|
|
3
|
+
/** Keep a worker alive until its synchronous installer and recovery finish. */
|
|
4
|
+
export function protectOrchestratedWorkerSignals() {
|
|
5
|
+
for (const signal of process.platform === "win32" ? SIGNALS.slice(0, 2) : SIGNALS) process.on(signal, () => {});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Forward catchable signals and require a close event within 60 seconds after interruption. */
|
|
9
|
+
export function waitForOrchestratedChild(child, options = {}) {
|
|
10
|
+
const signals = options.signals ?? process;
|
|
11
|
+
const startTimer = options.setTimer ?? setTimeout;
|
|
12
|
+
const stopTimer = options.clearTimer ?? clearTimeout;
|
|
13
|
+
const timeoutMs = options.timeoutMs ?? 60_000;
|
|
14
|
+
return new Promise(resolve => {
|
|
15
|
+
let timer;
|
|
16
|
+
let overrunTimer;
|
|
17
|
+
let settled = false;
|
|
18
|
+
const handlers = new Map();
|
|
19
|
+
const cleanupSignals = () => {
|
|
20
|
+
for (const [signal, handler] of handlers) signals.removeListener(signal, handler);
|
|
21
|
+
if (timer !== undefined) stopTimer(timer);
|
|
22
|
+
if (overrunTimer !== undefined) stopTimer(overrunTimer);
|
|
23
|
+
};
|
|
24
|
+
const onClose = (code, signal) => {
|
|
25
|
+
child.removeListener("error", onError);
|
|
26
|
+
if (settled) return;
|
|
27
|
+
settled = true;
|
|
28
|
+
cleanupSignals();
|
|
29
|
+
resolve({ confirmed: true, code, signal });
|
|
30
|
+
};
|
|
31
|
+
const armTimer = () => {
|
|
32
|
+
if (timer !== undefined) return;
|
|
33
|
+
timer = startTimer(() => {
|
|
34
|
+
if (settled) return;
|
|
35
|
+
settled = true;
|
|
36
|
+
cleanupSignals();
|
|
37
|
+
// Keep the child listeners until close: a late error must not become unhandled.
|
|
38
|
+
resolve({ confirmed: false, code: null, signal: null });
|
|
39
|
+
}, timeoutMs);
|
|
40
|
+
};
|
|
41
|
+
const onError = () => armTimer();
|
|
42
|
+
child.once("close", onClose);
|
|
43
|
+
child.on("error", onError);
|
|
44
|
+
for (const signal of SIGNALS) {
|
|
45
|
+
const handler = () => {
|
|
46
|
+
armTimer();
|
|
47
|
+
try { child.kill(signal); } catch { /* Wait for close or return uncertainty. */ }
|
|
48
|
+
};
|
|
49
|
+
handlers.set(signal, handler);
|
|
50
|
+
signals.on(signal, handler);
|
|
51
|
+
}
|
|
52
|
+
if (options.overrunMs !== undefined) {
|
|
53
|
+
let remaining = Math.max(0, options.overrunMs);
|
|
54
|
+
const schedule = () => {
|
|
55
|
+
const delay = Math.min(remaining, 2_147_483_647);
|
|
56
|
+
overrunTimer = startTimer(() => {
|
|
57
|
+
if (settled) return;
|
|
58
|
+
remaining -= delay;
|
|
59
|
+
if (remaining > 0) { schedule(); return; }
|
|
60
|
+
settled = true;
|
|
61
|
+
cleanupSignals();
|
|
62
|
+
// Do not signal a transaction in progress. The caller must detach its
|
|
63
|
+
// handles and leave the child's in-flight marker intact.
|
|
64
|
+
resolve({ confirmed: false, code: null, signal: null, reason: "overrun" });
|
|
65
|
+
}, delay);
|
|
66
|
+
};
|
|
67
|
+
schedule();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|