@bitkyc08/opencodex 2.97.0 → 2.98.0
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 +1 -1
- package/gui/dist/assets/App-6TFtZsUF.css +1 -0
- package/gui/dist/assets/App-FQ0OtiMJ.js +59 -0
- package/gui/dist/assets/Tray-D2d5wqLq.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-A03mw_9y.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-BjTIN4to.js +94 -0
- package/gui/dist/assets/segment-thumb-features-Bf6vpwf8.js +1 -0
- package/gui/dist/classic/assets/App-C9Eg3nUo.js +58 -0
- package/gui/dist/{assets/Tray-CEw0y0jR.js → classic/assets/Tray-B8P8cokE.js} +1 -1
- package/gui/dist/classic/assets/index-DFAFnven.js +94 -0
- package/gui/dist/classic/assets/quota-summary-C-4HP4_5.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/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 +169 -12
- 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 +9 -0
- package/src/adapters/kiro-tools.ts +14 -9
- package/src/adapters/kiro-wire.ts +9 -5
- 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/opengateway-input.ts +18 -6
- package/src/adapters/openai-responses/tool-output-recovery.ts +79 -0
- package/src/adapters/qoder/live-models.ts +115 -1
- 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 +52 -23
- package/src/cli/capabilities-access-remote.ts +13 -0
- package/src/cli/capabilities-base.ts +1 -0
- package/src/cli/capabilities-provider-models.ts +3 -3
- package/src/cli/codex-shim-autorestore.ts +7 -0
- package/src/cli/config-command.ts +11 -2
- package/src/cli/connect.ts +17 -2
- package/src/cli/dispatch.ts +3 -1
- package/src/cli/doctor.ts +95 -7
- package/src/cli/index.ts +12 -7
- package/src/cli/link-apply-restart.ts +9 -2
- package/src/cli/models.ts +124 -38
- package/src/cli/registry.ts +1 -1
- package/src/cli/restart-failure.ts +17 -0
- package/src/cli/stop-approval.ts +2 -2
- package/src/cli/sync-command.ts +1 -1
- package/src/cli/sync-fanout.ts +15 -4
- 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 +4 -1
- package/src/client/hub-client.ts +5 -0
- 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 +7 -0
- package/src/client/orphan-token-recovery.ts +322 -0
- package/src/codex/catalog/provider-models.ts +12 -4
- package/src/codex/native-profile-api.ts +27 -1
- 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/config/diagnostics.ts +9 -9
- package/src/config/load-degrade.ts +27 -27
- package/src/config/provider-validation.ts +9 -2
- package/src/config/removed-opencode-free-backup.ts +6 -3
- package/src/config/tracked-runtime-inspection.ts +3 -3
- package/src/generated/compatibility-version.json +219 -147
- package/src/images/loop.ts +2 -2
- package/src/lib/client-error-body.ts +37 -6
- package/src/lib/config-ownership-removal.ts +422 -0
- package/src/lib/config-ownership.ts +646 -81
- package/src/lib/context-overflow-verdict.ts +3 -3
- package/src/lib/crash-guard.ts +4 -2
- package/src/lib/desktop-cli-handoff.d.mts +3 -4
- package/src/lib/desktop-cli-handoff.mjs +7 -16
- package/src/lib/errors.ts +1 -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/passive-read.ts +9 -4
- package/src/lib/socks5-fetch.ts +21 -9
- package/src/lib/upstream-retry.ts +81 -1
- package/src/lib/windows-owner-acl.ts +9 -3
- package/src/lib/winsw.ts +5 -5
- package/src/lib/workflow-budget.ts +3 -1
- package/src/oauth/index.ts +7 -0
- package/src/oauth/store.ts +20 -10
- package/src/protocols/codecs/messages-ir.ts +15 -9
- package/src/protocols/encoders/adapter-events.ts +26 -7
- package/src/protocols/encoders/messages.ts +72 -28
- package/src/providers/antigravity-models.ts +45 -12
- package/src/providers/free-directory.ts +2 -2
- package/src/providers/reasoning-metadata.ts +2 -1
- package/src/providers/registry/entries-extended.ts +9 -0
- package/src/reasoning-effort.ts +7 -2
- package/src/remote/hub-usage.ts +3 -0
- package/src/server/admission-model-scope.ts +1 -1
- package/src/server/admitted-http-turn.ts +2 -1
- package/src/server/anthropic-rate-limit-headers.ts +75 -3
- package/src/server/claude-messages.ts +130 -67
- package/src/server/gui-static.ts +4 -1
- package/src/server/hub-usage.ts +7 -2
- package/src/server/index/link-management.ts +8 -0
- package/src/server/index/ollama-routes.ts +2 -0
- package/src/server/index/serve-options.ts +23 -20
- package/src/server/index/startup-warnings.ts +5 -12
- package/src/server/index/websocket-handler.ts +1 -0
- package/src/server/inference/client-encoder-delivery.ts +5 -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 +3 -0
- 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-tool-guard.ts +11 -3
- package/src/server/messages-native.ts +111 -40
- package/src/server/messages-response-headers.ts +25 -11
- package/src/server/messages-shared.ts +94 -64
- package/src/server/messages-sse-error-filter.ts +199 -0
- package/src/server/request-log.ts +12 -0
- package/src/server/responses/adapter-continuation.ts +11 -5
- package/src/server/responses/adapter-delivery.ts +14 -8
- package/src/server/responses/adapter-dispatch.ts +8 -8
- package/src/server/responses/anthropic-thinking-recovery.ts +2 -2
- package/src/server/responses/codex-auth-error.ts +8 -4
- package/src/server/responses/codex-ws-wire.ts +19 -3
- package/src/server/responses/compact.ts +4 -1
- package/src/server/responses/core-auth.ts +1 -1
- package/src/server/responses/core-combo-failure.ts +2 -0
- package/src/server/responses/core-combo.ts +2 -0
- package/src/server/responses/core-errors.ts +5 -4
- package/src/server/responses/core-options.ts +2 -0
- package/src/server/responses/empty-completion-guard.ts +4 -1
- package/src/server/responses/pacing-overload.ts +1 -1
- package/src/server/responses/passthrough-dispatch.ts +5 -5
- package/src/server/responses/request-prepare.ts +3 -1
- package/src/server/responses/request-transport.ts +9 -8
- package/src/server/responses/response-effects.ts +3 -2
- package/src/server/responses/terminal-guard.ts +30 -0
- package/src/server/restart-replacement.ts +3 -1
- package/src/server/sse-payload-rewrite.ts +23 -11
- package/src/server/workflow-refusal.ts +1 -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/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/provider.ts +2 -0
- package/src/types/request.ts +13 -1
- package/src/update/config-preflight.ts +48 -0
- package/src/update/index.ts +15 -1
- package/src/usage/client.ts +43 -0
- package/src/usage/error-detail.ts +1 -1
- package/src/usage/log.ts +4 -0
- 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 +2 -1
- package/src/web-search/progress-stream.ts +64 -5
- package/gui/dist/assets/App-DuNhggE1.js +0 -58
- package/gui/dist/assets/index-CynE_Rue.js +0 -94
- package/gui/dist/assets/quota-summary-VHFSlUuM.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
|
@@ -63,7 +63,7 @@ import { CODEX_GPT5_IDENTITY_LINE } from "../../adapters/identity";
|
|
|
63
63
|
import { filterCursorConfiguredModelsByLiveDiscovery } from "../../adapters/cursor/discovery";
|
|
64
64
|
import { fetchCursorUsableModels } from "../../adapters/cursor/live-models";
|
|
65
65
|
import { cursorLiveRosterScope, recordLiveCursorClaudeModels, recordLiveCursorMaxModeModels } from "../../adapters/cursor/catalog";
|
|
66
|
-
import {
|
|
66
|
+
import { discoverQoderModels, markQoderDiscoveryCommitted, qoderDiscoveryJoinable, uncommittedQoderDiscovery } from "../../adapters/qoder/live-models";
|
|
67
67
|
import { resolveQoderProfile } from "../../adapters/qoder/profiles";
|
|
68
68
|
import { CODEBUDDY_PROFILES, type CodeBuddyProfile } from "../../adapters/codebuddy/profiles";
|
|
69
69
|
import { fetchCodeBuddyModels } from "../../adapters/codebuddy/live-models";
|
|
@@ -451,19 +451,26 @@ export async function fetchProviderModelsWithAuth(
|
|
|
451
451
|
// fingerprint so an account switch cannot observe another account's roster, even if a caller
|
|
452
452
|
// bypasses the normal config mutation path that clears provider caches.
|
|
453
453
|
const authorityIdentity = createHash("sha256").update(apiKey).digest("hex");
|
|
454
|
-
const
|
|
454
|
+
const discoveryScope = `${name}\0${cacheGeneration}`;
|
|
455
|
+
// A finished run no gather has stored yet (the dashboard test stopped waiting for it) outranks
|
|
456
|
+
// a fresh cached roster; the cached roster stays as the fallback until this one is stored (#8115).
|
|
457
|
+
const unstored = uncommittedQoderDiscovery(profile, apiKey, discoveryScope);
|
|
458
|
+
const fresh = unstored ? null : getFreshCached(name, ttlMs, Date.now(), authorityIdentity);
|
|
455
459
|
if (fresh) {
|
|
456
460
|
return observed(withConfiguredRetention(
|
|
457
461
|
applyConfigHintsToCachedModels(name, prov, fresh, contextCap, metadataModelIdCaseFold, captured.effectiveAlias, metadataConfigDir, false),
|
|
458
462
|
), "authoritative");
|
|
459
463
|
}
|
|
460
464
|
const scopedStale = getStaleCached(name, authorityIdentity);
|
|
461
|
-
|
|
465
|
+
// A run another caller started (the dashboard test) is joined even inside the failure
|
|
466
|
+
// cooldown: its late success is what the catalog re-sync after it is waiting for.
|
|
467
|
+
if (!unstored && isModelsFetchCoolingDown(name) && scopedStale && !qoderDiscoveryJoinable(profile, apiKey, discoveryScope)) {
|
|
462
468
|
return observed(withConfiguredRetention(
|
|
463
469
|
applyConfigHintsToCachedModels(name, prov, scopedStale, contextCap, metadataModelIdCaseFold, captured.effectiveAlias, metadataConfigDir, false),
|
|
464
470
|
), "degraded");
|
|
465
471
|
}
|
|
466
|
-
|
|
472
|
+
// Background discovery: waits for the full CLI bound, shared with any concurrent caller.
|
|
473
|
+
const live = unstored ?? await discoverQoderModels(profile, apiKey, discoveryScope);
|
|
467
474
|
if (live.ok) {
|
|
468
475
|
const discovered = live.models.map(id => ({
|
|
469
476
|
id,
|
|
@@ -474,6 +481,7 @@ export async function fetchProviderModelsWithAuth(
|
|
|
474
481
|
if (!setCached(name, forCache, Date.now(), cacheGeneration, authorityIdentity)) {
|
|
475
482
|
return observed(withConfiguredRetention(configured), "degraded");
|
|
476
483
|
}
|
|
484
|
+
markQoderDiscoveryCommitted(profile, apiKey, discoveryScope);
|
|
477
485
|
markProviderDiscoveryOk(name, live.models.length);
|
|
478
486
|
return observed(withConfiguredRetention(forCache, { warnDrops: true }), "authoritative");
|
|
479
487
|
}
|
|
@@ -74,6 +74,13 @@ async function withMainRequestDrain<T>(deps: NativeProfileApiDeps, operation: ()
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
function admissionFields(): { admissionStatus: "ready" | "blocked"; admissionBlockReason?: string } {
|
|
78
|
+
const gate = nativeMainStartupGateSnapshot();
|
|
79
|
+
return gate.status === "blocked"
|
|
80
|
+
? { admissionStatus: gate.status, admissionBlockReason: gate.reason }
|
|
81
|
+
: { admissionStatus: gate.status };
|
|
82
|
+
}
|
|
83
|
+
|
|
77
84
|
async function withRecoveryGateTransition<T>(
|
|
78
85
|
manager: NativeProfileManager,
|
|
79
86
|
deps: NativeProfileApiDeps,
|
|
@@ -141,13 +148,32 @@ export async function handleNativeProfileAPI(
|
|
|
141
148
|
deps: NativeProfileApiDeps = {},
|
|
142
149
|
): Promise<Response | null> {
|
|
143
150
|
if (!url.pathname.startsWith("/api/native-main-profiles")) return null;
|
|
151
|
+
// Admission is read from this process's startup gate only. It constructs no manager and runs
|
|
152
|
+
// no doctor sweep, so the single-use local read capability `ocx doctor` holds can reach it
|
|
153
|
+
// without reaching staging cleanup, profile ids or filesystem paths.
|
|
154
|
+
if (url.pathname === "/api/native-main-profiles/admission" && req.method === "GET") {
|
|
155
|
+
return jsonResponse(admissionFields(), 200, req, config);
|
|
156
|
+
}
|
|
144
157
|
try {
|
|
145
158
|
const manager = deps.manager ?? new NativeProfileManager();
|
|
146
159
|
if (url.pathname === "/api/native-main-profiles" && req.method === "GET") {
|
|
147
160
|
return jsonResponse(await manager.list(), 200, req, config);
|
|
148
161
|
}
|
|
149
162
|
if (url.pathname === "/api/native-main-profiles/doctor" && req.method === "GET") {
|
|
150
|
-
|
|
163
|
+
try {
|
|
164
|
+
const doc = await withNativeMainApiOperation(manager, () => manager.doctor(), { mode: "shared" });
|
|
165
|
+
return jsonResponse({ ...doc, ...admissionFields() }, 200, req, config);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
if (!(error instanceof NativeProfileError)) throw error;
|
|
168
|
+
return jsonResponse({
|
|
169
|
+
error: error.message,
|
|
170
|
+
code: error.code,
|
|
171
|
+
retryable: error.retryable,
|
|
172
|
+
...(error.cleanupRequired === true ? { cleanupRequired: true } : {}),
|
|
173
|
+
...(typeof error.plaintextMayRemain === "boolean" ? { plaintextMayRemain: error.plaintextMayRemain } : {}),
|
|
174
|
+
...admissionFields(),
|
|
175
|
+
}, error.status, req, config);
|
|
176
|
+
}
|
|
151
177
|
}
|
|
152
178
|
if (url.pathname === "/api/native-main-profiles/register" && req.method === "POST") {
|
|
153
179
|
const input = await body(req);
|
|
@@ -2,6 +2,7 @@ import { existsSync, lstatSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { SHIM_MARKER, UNIX_SHIM_REVISION_MARKER, WINDOWS_SHIM_REVISION_MARKER } from "./shim-templates";
|
|
3
3
|
import { readStateResult, stateFiles, statePath } from "./shim-state-file";
|
|
4
4
|
import { overlayDiagnostic } from "./shim-overlay";
|
|
5
|
+
import { checkLegacyShimRecord, legacyShimManualRestoreMessage } from "./shim-legacy-record";
|
|
5
6
|
|
|
6
7
|
export function isShim(path: string): boolean {
|
|
7
8
|
try {
|
|
@@ -59,6 +60,12 @@ export function diagnoseCodexShim(): CodexShimDiagnostic {
|
|
|
59
60
|
};
|
|
60
61
|
}
|
|
61
62
|
if (state.mode === "path-overlay") return overlayDiagnostic(state);
|
|
63
|
+
if (state.platform === "win32") {
|
|
64
|
+
const legacy = checkLegacyShimRecord(state);
|
|
65
|
+
if (!legacy.ok) {
|
|
66
|
+
return { installed: true, healthy: false, runnable: false, active: null, summary: legacyShimManualRestoreMessage(legacy.reason, statePath()) };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
62
69
|
const files = stateFiles(state);
|
|
63
70
|
const healthy = files.length > 0 && files.every(file => file.preserveOnly
|
|
64
71
|
? existsSync(file.backupPath) && !existsSync(file.originalPath)
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { closeSync, linkSync, lstatSync, openSync, readSync, realpathSync, renameSync, unlinkSync } from "node:fs";
|
|
2
|
+
import { posix, sep, win32 } from "node:path";
|
|
3
|
+
import { SHIM_MARKER } from "./shim-templates";
|
|
4
|
+
import { fileErrorCode, type ShimFileState } from "./shim-state-file";
|
|
5
|
+
|
|
6
|
+
type PlatformPath = typeof win32;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Validation for the legacy Codex shim record (codex-shim.json without schema/mode), which
|
|
10
|
+
* Windows installs still write. Every path a restore acts on is derived from the layout
|
|
11
|
+
* OpenCodex itself writes: launchers with fixed names, a backup that is the
|
|
12
|
+
* `.opencodex-real` sibling of the original, and all of them in one directory. The checks are
|
|
13
|
+
* pure functions over an injected path flavor so every OS can test them.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Path flavor of the host filesystem; independent of a test-overridden process.platform. */
|
|
17
|
+
export function hostShimPathApi(): PlatformPath {
|
|
18
|
+
return sep === "\\" ? win32 : posix;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The backup name OpenCodex gives an original launcher: the suffix goes before the extension. */
|
|
22
|
+
export function legacyShimBackupPath(path: string, api: PlatformPath = hostShimPathApi()): string {
|
|
23
|
+
const ext = api.extname(path);
|
|
24
|
+
return ext ? `${path.slice(0, -ext.length)}.opencodex-real${ext}` : `${path}.opencodex-real`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** In-place wrappers: the launcher npm writes is replaced by the shim at the same path. */
|
|
28
|
+
const IN_PLACE_LAUNCHERS = new Set(["codex.cmd", "codex.ps1", "codex"]);
|
|
29
|
+
/** The earliest Windows installs wrote codex.cmd next to the original launcher. */
|
|
30
|
+
const SIDE_BY_SIDE_ORIGINAL = /^codex(\.(exe|com|bat|cmd|ps1))?$/i;
|
|
31
|
+
const MAX_LEGACY_ENTRIES = 3;
|
|
32
|
+
const BACKUP_MARKER_SCAN_BYTES = 16 * 1024;
|
|
33
|
+
|
|
34
|
+
export type LegacyShimRecordVerdict =
|
|
35
|
+
| { ok: true; files: ShimFileState[]; directory: string }
|
|
36
|
+
| { ok: false; reason: string };
|
|
37
|
+
|
|
38
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
39
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function pathProblem(path: unknown, api: PlatformPath): string | null {
|
|
43
|
+
if (typeof path !== "string" || path.length === 0) return "a launcher path is missing";
|
|
44
|
+
if (/[\x00-\x1f\x7f]/.test(path)) return "a launcher path contains control characters";
|
|
45
|
+
if (api === win32) {
|
|
46
|
+
if (!/^[A-Za-z]:\\/.test(path)) return "a launcher path is not an absolute drive path";
|
|
47
|
+
if (path.indexOf(":", 2) !== -1 || /[<>"|?*/]/.test(path)) return "a launcher path contains reserved characters";
|
|
48
|
+
if (path.slice(3).split("\\").some(segment => segment.length === 0 || /[. ]$/.test(segment))) {
|
|
49
|
+
return "a launcher path is not normalized";
|
|
50
|
+
}
|
|
51
|
+
} else if (!path.startsWith("/")) {
|
|
52
|
+
return "a launcher path is not absolute";
|
|
53
|
+
}
|
|
54
|
+
if (api.normalize(path) !== path || path.endsWith(api.sep)) return "a launcher path is not normalized";
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function nameKey(path: string, api: PlatformPath): string {
|
|
59
|
+
return api.basename(path).toLowerCase();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Lexical validation: shape, platform, and the exact layout an OpenCodex install writes. */
|
|
63
|
+
export function validateLegacyWindowsShimRecord(value: unknown, api: PlatformPath = hostShimPathApi()): LegacyShimRecordVerdict {
|
|
64
|
+
const fail = (reason: string): LegacyShimRecordVerdict => ({ ok: false, reason });
|
|
65
|
+
if (!isRecord(value)) return fail("the shim record is not an object");
|
|
66
|
+
if (value.schema !== undefined || value.mode !== undefined) return fail("the shim record is not a Windows install record");
|
|
67
|
+
if (value.platform !== "win32") return fail("the shim record was not written by a Windows install");
|
|
68
|
+
const entries: unknown = value.wrappers !== undefined ? value.wrappers : [value];
|
|
69
|
+
if (!Array.isArray(entries) || entries.length === 0 || entries.length > MAX_LEGACY_ENTRIES) {
|
|
70
|
+
return fail("the shim record lists an unexpected number of launchers");
|
|
71
|
+
}
|
|
72
|
+
const files: ShimFileState[] = [];
|
|
73
|
+
for (const entry of entries) {
|
|
74
|
+
if (!isRecord(entry)) return fail("a shim record entry is not an object");
|
|
75
|
+
for (const key of ["wrapperPath", "originalPath", "backupPath"] as const) {
|
|
76
|
+
const problem = pathProblem(entry[key], api);
|
|
77
|
+
if (problem) return fail(problem);
|
|
78
|
+
}
|
|
79
|
+
const file = { wrapperPath: entry.wrapperPath as string, originalPath: entry.originalPath as string, backupPath: entry.backupPath as string };
|
|
80
|
+
if (entry.realPath !== undefined && entry.realPath !== file.backupPath) return fail("a launcher points at an unexpected backing file");
|
|
81
|
+
if (entry.preserveOnly !== undefined && entry.preserveOnly !== false) return fail("a launcher entry has an unexpected mode");
|
|
82
|
+
const directory = api.dirname(file.wrapperPath);
|
|
83
|
+
if (api.dirname(file.originalPath) !== directory || api.dirname(file.backupPath) !== directory) {
|
|
84
|
+
return fail("the launcher, its original and its backup are not in one directory");
|
|
85
|
+
}
|
|
86
|
+
if (file.wrapperPath === file.originalPath) {
|
|
87
|
+
if (!IN_PLACE_LAUNCHERS.has(nameKey(file.wrapperPath, api))) return fail("a launcher has an unexpected name");
|
|
88
|
+
} else if (entries.length !== 1 || nameKey(file.wrapperPath, api) !== "codex.cmd"
|
|
89
|
+
|| !SIDE_BY_SIDE_ORIGINAL.test(api.basename(file.originalPath)) || nameKey(file.originalPath, api) === "codex.cmd") {
|
|
90
|
+
return fail("a launcher has an unexpected name");
|
|
91
|
+
}
|
|
92
|
+
if (file.backupPath !== legacyShimBackupPath(file.originalPath, api)) return fail("a backup is not the expected sibling of its original");
|
|
93
|
+
files.push(file);
|
|
94
|
+
}
|
|
95
|
+
if (value.wrappers !== undefined) {
|
|
96
|
+
const first = files[0]!;
|
|
97
|
+
for (const key of ["wrapperPath", "originalPath", "backupPath"] as const) {
|
|
98
|
+
if (value[key] !== undefined && value[key] !== first[key]) return fail("the shim record summary disagrees with its launcher list");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const directory = api.dirname(files[0]!.wrapperPath);
|
|
102
|
+
// Exact spelling: Windows directories can be case-sensitive, so differently cased names may differ.
|
|
103
|
+
if (files.some(file => api.dirname(file.wrapperPath) !== directory)) {
|
|
104
|
+
return fail("the launchers are not in one directory");
|
|
105
|
+
}
|
|
106
|
+
if (new Set(files.map(file => nameKey(file.wrapperPath, api))).size !== files.length) return fail("a launcher is listed twice");
|
|
107
|
+
return { ok: true, files, directory };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface LegacyShimDiskDeps {
|
|
111
|
+
lstat?: (path: string) => { isFile(): boolean; isDirectory(): boolean; isSymbolicLink(): boolean; size: number | bigint; nlink?: number | bigint; dev?: number | bigint; ino?: number | bigint };
|
|
112
|
+
realpath?: (path: string) => string;
|
|
113
|
+
readPrefix?: (path: string, bytes: number) => string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type LegacyShimDirectoryVerdict =
|
|
117
|
+
/** `resolved` is null when the recorded directory no longer exists: nothing to act on. */
|
|
118
|
+
| { ok: true; resolved: string | null; identity: string | null }
|
|
119
|
+
| { ok: false; reason: string };
|
|
120
|
+
|
|
121
|
+
function defaultReadPrefix(path: string, bytes: number): string {
|
|
122
|
+
const fd = openSync(path, "r");
|
|
123
|
+
try {
|
|
124
|
+
const buffer = Buffer.alloc(bytes);
|
|
125
|
+
let total = 0;
|
|
126
|
+
while (total < bytes) {
|
|
127
|
+
const count = readSync(fd, buffer, total, bytes - total, total);
|
|
128
|
+
if (count === 0) break;
|
|
129
|
+
total += count;
|
|
130
|
+
}
|
|
131
|
+
return buffer.subarray(0, total).toString("utf8");
|
|
132
|
+
} finally {
|
|
133
|
+
closeSync(fd);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Resolves the recorded directory once and requires the resolved chain to hold only real
|
|
139
|
+
* directories. A link in the recorded spelling (an nvm-windows or scoop prefix) is accepted:
|
|
140
|
+
* it can only select a directory the record could name directly, and callers act on the
|
|
141
|
+
* resolved directory.
|
|
142
|
+
*/
|
|
143
|
+
const defaultLstat = (path: string) => lstatSync(path, { bigint: true });
|
|
144
|
+
|
|
145
|
+
export function resolveLegacyShimDirectory(recordedDirectory: string, api: PlatformPath = hostShimPathApi(), deps: LegacyShimDiskDeps = {}): LegacyShimDirectoryVerdict {
|
|
146
|
+
const lstat = deps.lstat ?? defaultLstat;
|
|
147
|
+
const realpath = deps.realpath ?? realpathSync.native;
|
|
148
|
+
let resolved: string;
|
|
149
|
+
try {
|
|
150
|
+
resolved = realpath(recordedDirectory);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
const code = fileErrorCode(error);
|
|
153
|
+
if (code === "ENOENT" || code === "ENOTDIR") return { ok: true, resolved: null, identity: null };
|
|
154
|
+
return { ok: false, reason: "the launcher directory could not be resolved" };
|
|
155
|
+
}
|
|
156
|
+
if (!api.isAbsolute(resolved)) return { ok: false, reason: "the launcher directory could not be resolved" };
|
|
157
|
+
let identity: string | null = null;
|
|
158
|
+
try {
|
|
159
|
+
for (let current = resolved; ; current = api.dirname(current)) {
|
|
160
|
+
const entry = lstat(current);
|
|
161
|
+
if (entry.isSymbolicLink() || !entry.isDirectory()) return { ok: false, reason: "the launcher directory resolves through a link" };
|
|
162
|
+
// Device and inode: a directory replaced at the same path is a different directory.
|
|
163
|
+
if (current === resolved) identity = `${entry.dev}:${entry.ino}`;
|
|
164
|
+
if (api.dirname(current) === current) break;
|
|
165
|
+
}
|
|
166
|
+
} catch {
|
|
167
|
+
return { ok: false, reason: "the launcher directory could not be inspected" };
|
|
168
|
+
}
|
|
169
|
+
return { ok: true, resolved, identity };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
type EntryShape = "absent" | "file" | "shared" | "other";
|
|
173
|
+
|
|
174
|
+
function entryShape(path: string, lstat: NonNullable<LegacyShimDiskDeps["lstat"]>): { shape: EntryShape; size: number } {
|
|
175
|
+
try {
|
|
176
|
+
const entry = lstat(path);
|
|
177
|
+
if (entry.isSymbolicLink() || !entry.isFile()) return { shape: "other", size: 0 };
|
|
178
|
+
if (Number(entry.nlink ?? 1) > 1) return { shape: "shared", size: Number(entry.size) };
|
|
179
|
+
return { shape: "file", size: Number(entry.size) };
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (fileErrorCode(error) === "ENOENT") return { shape: "absent", size: 0 };
|
|
182
|
+
return { shape: "other", size: 0 };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** File shapes inside the resolved directory: launchers are regular files, a backup is a non-empty non-shim file. */
|
|
187
|
+
export function legacyShimFilesProblem(files: readonly ShimFileState[], resolvedDirectory: string, api: PlatformPath = hostShimPathApi(), deps: LegacyShimDiskDeps = {}): string | null {
|
|
188
|
+
const lstat = deps.lstat ?? defaultLstat;
|
|
189
|
+
const readPrefix = deps.readPrefix ?? defaultReadPrefix;
|
|
190
|
+
for (const file of files) {
|
|
191
|
+
for (const launcher of new Set([file.wrapperPath, file.originalPath])) {
|
|
192
|
+
const shape = entryShape(api.join(resolvedDirectory, api.basename(launcher)), lstat).shape;
|
|
193
|
+
if (shape === "other") return "a launcher is not a regular file";
|
|
194
|
+
if (shape === "shared") return "a launcher shares its file with another path";
|
|
195
|
+
}
|
|
196
|
+
const backupPath = api.join(resolvedDirectory, api.basename(file.backupPath));
|
|
197
|
+
const backup = entryShape(backupPath, lstat);
|
|
198
|
+
if (backup.shape === "absent") continue;
|
|
199
|
+
if (backup.shape !== "file" || backup.size === 0) return "a backup is not a non-empty regular file";
|
|
200
|
+
try {
|
|
201
|
+
if (readPrefix(backupPath, BACKUP_MARKER_SCAN_BYTES).includes(SHIM_MARKER)) return "a backup is itself a shim";
|
|
202
|
+
} catch {
|
|
203
|
+
return "a backup could not be read";
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export type LegacyShimCheck =
|
|
210
|
+
| { ok: true; files: ShimFileState[]; recordedDirectory: string; resolvedDirectory: string | null; directoryIdentity: string | null }
|
|
211
|
+
| { ok: false; reason: string };
|
|
212
|
+
|
|
213
|
+
/** Lexical layout, resolved directory, and file shapes, in that order. */
|
|
214
|
+
export function checkLegacyShimRecord(value: unknown, api: PlatformPath = hostShimPathApi(), deps: LegacyShimDiskDeps = {}): LegacyShimCheck {
|
|
215
|
+
const record = validateLegacyWindowsShimRecord(value, api);
|
|
216
|
+
if (!record.ok) return record;
|
|
217
|
+
const directory = resolveLegacyShimDirectory(record.directory, api, deps);
|
|
218
|
+
if (!directory.ok) return directory;
|
|
219
|
+
if (directory.resolved !== null) {
|
|
220
|
+
const problem = legacyShimFilesProblem(record.files, directory.resolved, api, deps);
|
|
221
|
+
if (problem) return { ok: false, reason: problem };
|
|
222
|
+
}
|
|
223
|
+
return { ok: true, files: record.files, recordedDirectory: record.directory, resolvedDirectory: directory.resolved, directoryIdentity: directory.identity };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** A launcher a fresh install backs up must be a non-empty file; an empty backup is refused by every later restore. */
|
|
227
|
+
export function legacyShimFreshLaunchersProblem(files: readonly ShimFileState[], resolvedDirectory: string | null, api: PlatformPath = hostShimPathApi(), deps: LegacyShimDiskDeps = {}): string | null {
|
|
228
|
+
if (resolvedDirectory === null) return "the launcher directory is missing";
|
|
229
|
+
const lstat = deps.lstat ?? defaultLstat;
|
|
230
|
+
for (const file of files) {
|
|
231
|
+
const original = entryShape(api.join(resolvedDirectory, api.basename(file.originalPath)), lstat);
|
|
232
|
+
if (original.shape !== "file" || original.size === 0) return "a launcher is empty or not a regular file";
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** True when the recorded directory still resolves to the same link-free directory, by path and identity. */
|
|
238
|
+
export function legacyShimDirectoryUnchanged(recordedDirectory: string, resolvedDirectory: string | null, identity: string | null, api: PlatformPath = hostShimPathApi(), deps: LegacyShimDiskDeps = {}): boolean {
|
|
239
|
+
const now = resolveLegacyShimDirectory(recordedDirectory, api, deps);
|
|
240
|
+
return now.ok && now.resolved === resolvedDirectory && now.identity === identity;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
let mutationGuard: (() => void) | null = null;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Binds every later Windows shim mutation to a validated record until the returned release runs:
|
|
247
|
+
* each rename, link, unlink and write first checks that the recorded directory still resolves to
|
|
248
|
+
* the directory that was validated.
|
|
249
|
+
*/
|
|
250
|
+
export function setLegacyShimMutationGuard(check: Extract<LegacyShimCheck, { ok: true }> | null): () => void {
|
|
251
|
+
const previous = mutationGuard;
|
|
252
|
+
mutationGuard = check && (() => {
|
|
253
|
+
if (!legacyShimDirectoryUnchanged(check.recordedDirectory, check.resolvedDirectory, check.directoryIdentity)) {
|
|
254
|
+
throw new Error("Codex shim launcher directory changed after validation; refusing to modify it");
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
return () => { mutationGuard = previous; };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Throws when a guarded Windows shim operation would act outside its validated directory. */
|
|
261
|
+
export function assertLegacyShimMutationAllowed(): void {
|
|
262
|
+
mutationGuard?.();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/*
|
|
266
|
+
* The Windows shim modules import these instead of the node:fs calls, so every rename, unlink and
|
|
267
|
+
* link they make checks the active guard immediately before it runs. Without a guard they are the
|
|
268
|
+
* plain calls.
|
|
269
|
+
*/
|
|
270
|
+
export function guardedRenameSync(from: string, to: string): void {
|
|
271
|
+
assertLegacyShimMutationAllowed();
|
|
272
|
+
renameSync(from, to);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function guardedUnlinkSync(path: string): void {
|
|
276
|
+
assertLegacyShimMutationAllowed();
|
|
277
|
+
unlinkSync(path);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function guardedLinkSync(from: string, to: string): void {
|
|
281
|
+
assertLegacyShimMutationAllowed();
|
|
282
|
+
linkSync(from, to);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function legacyShimManualRestoreMessage(reason: string, statePath: string, partial = false): string {
|
|
286
|
+
const changed = partial
|
|
287
|
+
? "The remaining launcher files were left as they are."
|
|
288
|
+
: "No launcher file was renamed or deleted.";
|
|
289
|
+
return `Codex autostart shim needs manual restore: ${reason}. ${changed} If Codex no longer starts, rename the launcher backup that carries the ".opencodex-real" suffix back to its original name, then delete ${statePath} and rerun.`;
|
|
290
|
+
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { closeSync, constants, existsSync, fstatSync,
|
|
2
|
+
import { closeSync, constants, existsSync, fstatSync, lstatSync, openSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, extname, join } from "node:path";
|
|
4
4
|
import { sameFingerprintAfterRename, sameStableShimPathProbe, shimPathFingerprint, stableShimPathProbe, type StableShimPathProbe } from "./shim-fingerprint";
|
|
5
|
+
import {
|
|
6
|
+
assertLegacyShimMutationAllowed,
|
|
7
|
+
guardedLinkSync as linkSync,
|
|
8
|
+
guardedRenameSync as renameSync,
|
|
9
|
+
guardedUnlinkSync as unlinkSync,
|
|
10
|
+
} from "./shim-legacy-record";
|
|
5
11
|
|
|
6
12
|
/**
|
|
7
13
|
* Identity of a directory entry: device, inode and whether the entry is itself a symbolic link.
|
|
@@ -52,6 +58,7 @@ function release(held: HeldFile | null): void {
|
|
|
52
58
|
|
|
53
59
|
/** Create `path` exclusively (never through an existing entry or link), write it, and keep it open. */
|
|
54
60
|
function createExclusive(path: string, content: string): HeldFile {
|
|
61
|
+
assertLegacyShimMutationAllowed();
|
|
55
62
|
const flags = constants.O_RDWR | constants.O_CREAT | constants.O_EXCL
|
|
56
63
|
| (process.platform === "win32" ? 0 : constants.O_NOFOLLOW);
|
|
57
64
|
const fd = openSync(path, flags, 0o644);
|
|
@@ -149,7 +156,7 @@ export function refreshObsoleteWindowsShim(
|
|
|
149
156
|
let moved: HeldFile | null = null;
|
|
150
157
|
let stage: HeldFile | null = null;
|
|
151
158
|
const discard = (path: string, held: HeldFile | null): void => {
|
|
152
|
-
if (held && entryIs(path, held.identity)) { try { unlinkSync(path); } catch { /* already gone */ } }
|
|
159
|
+
if (held && entryIs(path, held.identity)) { try { unlinkSync(path); } catch { /* already gone, or the directory moved */ } }
|
|
153
160
|
};
|
|
154
161
|
/**
|
|
155
162
|
* Put the moved wrapper back only onto an empty path, and only while the aside is still it. If the
|
|
@@ -12,6 +12,7 @@ import { basename, dirname, join } from "node:path";
|
|
|
12
12
|
import { durableBunRuntime, type BunRuntimeSource, type DurableBunRuntime } from "../lib/bun-runtime";
|
|
13
13
|
import { sameFileIdentity, type FileIdentity } from "../lib/file-identity";
|
|
14
14
|
import { serviceApiTokenFilePath } from "../lib/service-secrets";
|
|
15
|
+
import { assertLegacyShimMutationAllowed } from "./shim-legacy-record";
|
|
15
16
|
import {
|
|
16
17
|
buildUnixCodexShim,
|
|
17
18
|
buildWindowsCodexShim,
|
|
@@ -58,6 +59,12 @@ export function windowsShimContent(wrapperPath: string, realCodexPath: string, r
|
|
|
58
59
|
export function writeShim(wrapperPath: string, realCodexPath: string, runtime?: DurableBunRuntime): FileIdentity | undefined {
|
|
59
60
|
const { bun, bunRuntimeSource, cli } = cliEntry(runtime);
|
|
60
61
|
if (process.platform === "win32") {
|
|
62
|
+
assertLegacyShimMutationAllowed();
|
|
63
|
+
// Never write through a link or a file another path shares: the write would land outside this wrapper.
|
|
64
|
+
const existing = (() => { try { return lstatSync(wrapperPath, { bigint: true }); } catch { return null; } })();
|
|
65
|
+
if (existing && (existing.isSymbolicLink() || !existing.isFile() || existing.nlink > 1n)) {
|
|
66
|
+
throw new Error("Codex shim wrapper path is not a private regular file; refusing to write through it");
|
|
67
|
+
}
|
|
61
68
|
writeFileSync(wrapperPath, windowsShimContent(wrapperPath, realCodexPath, runtime), "utf8");
|
|
62
69
|
return undefined;
|
|
63
70
|
} else {
|
package/src/codex/shim.ts
CHANGED
|
@@ -4,11 +4,9 @@ import {
|
|
|
4
4
|
existsSync,
|
|
5
5
|
lstatSync,
|
|
6
6
|
readFileSync,
|
|
7
|
-
renameSync,
|
|
8
|
-
unlinkSync,
|
|
9
7
|
writeFileSync,
|
|
10
8
|
} from "node:fs";
|
|
11
|
-
import { delimiter,
|
|
9
|
+
import { delimiter, join, posix, win32 } from "node:path";
|
|
12
10
|
import { durableBunRuntime, type DurableBunRuntime } from "../lib/bun-runtime";
|
|
13
11
|
import type { FileIdentity } from "../lib/file-identity";
|
|
14
12
|
import { assertSelectedRuntimeWritable, RuntimePreflightError, type RuntimePreflightDeps } from "../lib/bun-runtime-preflight";
|
|
@@ -33,7 +31,6 @@ import {
|
|
|
33
31
|
} from "./shim-fingerprint";
|
|
34
32
|
import {
|
|
35
33
|
fileErrorCode,
|
|
36
|
-
readState,
|
|
37
34
|
readStateResult,
|
|
38
35
|
stateFiles,
|
|
39
36
|
statePath,
|
|
@@ -58,6 +55,18 @@ import {
|
|
|
58
55
|
type CodexPathScanDeps,
|
|
59
56
|
} from "./shim-path-resolution";
|
|
60
57
|
import { ownedWrapperFingerprint, windowsShimContent, wrapperInodeIsOurs, writeShim } from "./shim-wrapper-write";
|
|
58
|
+
import {
|
|
59
|
+
checkLegacyShimRecord,
|
|
60
|
+
hostShimPathApi,
|
|
61
|
+
guardedRenameSync as renameSync,
|
|
62
|
+
guardedUnlinkSync as unlinkSync,
|
|
63
|
+
legacyShimBackupPath,
|
|
64
|
+
legacyShimDirectoryUnchanged,
|
|
65
|
+
legacyShimFilesProblem,
|
|
66
|
+
legacyShimFreshLaunchersProblem,
|
|
67
|
+
legacyShimManualRestoreMessage,
|
|
68
|
+
setLegacyShimMutationGuard,
|
|
69
|
+
} from "./shim-legacy-record";
|
|
61
70
|
|
|
62
71
|
export { buildUnixCodexShim, buildWindowsCodexShim, buildWindowsPowerShellCodexShim } from "./shim-templates";
|
|
63
72
|
export { isVersionManagerOwnedCodexPath } from "./shim-fingerprint";
|
|
@@ -207,8 +216,7 @@ function findWindowsCodexTargets(): ShimFileState[] | null {
|
|
|
207
216
|
}
|
|
208
217
|
|
|
209
218
|
function backupPathFor(path: string): string {
|
|
210
|
-
|
|
211
|
-
return ext ? `${path.slice(0, -ext.length)}.opencodex-real${ext}` : `${path}.opencodex-real`;
|
|
219
|
+
return legacyShimBackupPath(path);
|
|
212
220
|
}
|
|
213
221
|
|
|
214
222
|
/**
|
|
@@ -770,8 +778,19 @@ function refreshObsoleteUnixShims(files: readonly ShimFileState[], runtime?: Dur
|
|
|
770
778
|
};
|
|
771
779
|
}
|
|
772
780
|
|
|
773
|
-
|
|
774
|
-
|
|
781
|
+
type InstallResult = { installed: boolean; message: string; refused?: boolean };
|
|
782
|
+
|
|
783
|
+
function installCodexShimInternal(options: InstallCodexShimInternalOptions): InstallResult {
|
|
784
|
+
const read = readStateResult();
|
|
785
|
+
// A record that is present but unreadable is not "no record": a fresh install would overwrite it.
|
|
786
|
+
if (read.present && !read.state) return { installed: false, refused: true, message: legacyShimManualRestoreMessage(read.warning ? "the shim record is unsafe to read" : "the shim record is unreadable", statePath()) };
|
|
787
|
+
const legacy = read.state ? checkLegacyShimRecord(read.state) : null;
|
|
788
|
+
if (legacy && !legacy.ok) return { installed: false, refused: true, message: legacyShimManualRestoreMessage(legacy.reason, statePath()) };
|
|
789
|
+
const release = setLegacyShimMutationGuard(legacy);
|
|
790
|
+
try { return installCodexShimFromState(options, read.state); } finally { release(); }
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
function installCodexShimFromState(options: InstallCodexShimInternalOptions, existing: ShimState | null): InstallResult {
|
|
775
794
|
const filesBefore = existing ? stateFiles(existing) : [];
|
|
776
795
|
if (filesBefore.length > 0 && filesBefore.every(file => {
|
|
777
796
|
if (file.preserveOnly) return existsSync(file.backupPath) && !existsSync(file.originalPath);
|
|
@@ -864,6 +883,11 @@ function installCodexShimInternal(options: InstallCodexShimInternalOptions): { i
|
|
|
864
883
|
return originalPath ? [{ wrapperPath: originalPath, originalPath, backupPath: backupPathFor(originalPath) }] : null;
|
|
865
884
|
})();
|
|
866
885
|
if (!targets) return { installed: false, message: lastShimDiscoveryError ?? "Could not find a codex executable on PATH." };
|
|
886
|
+
// The writer obeys the rules every later restore checks, so it never records a layout it would refuse.
|
|
887
|
+
const fresh = checkLegacyShimRecord(primaryState(targets));
|
|
888
|
+
const freshProblem = fresh.ok ? legacyShimFreshLaunchersProblem(fresh.files, fresh.resolvedDirectory) : fresh.reason;
|
|
889
|
+
if (!fresh.ok || freshProblem) return { installed: false, refused: true, message: `Refusing to install the Codex autostart shim: ${freshProblem}.` };
|
|
890
|
+
setLegacyShimMutationGuard(fresh); // released with the caller's guard
|
|
867
891
|
|
|
868
892
|
for (const target of targets) {
|
|
869
893
|
if (existsSync(target.backupPath)) return { installed: false, message: `Refusing to overwrite existing backup: ${target.backupPath}` };
|
|
@@ -1032,6 +1056,8 @@ function autoRestoreWindowsCodexShim(options: RuntimePreflightDeps & {
|
|
|
1032
1056
|
return { status: stateRead.present ? "ineligible" : "not-installed" };
|
|
1033
1057
|
}
|
|
1034
1058
|
if (state.platform !== process.platform) return { status: "ineligible" };
|
|
1059
|
+
const legacy = checkLegacyShimRecord(state);
|
|
1060
|
+
if (!legacy.ok) return { status: "ineligible", message: legacyShimManualRestoreMessage(legacy.reason, statePath()) };
|
|
1035
1061
|
|
|
1036
1062
|
const files = stateFiles(state);
|
|
1037
1063
|
const replacementProbes = new Map<string, StableShimPathProbe>();
|
|
@@ -1104,9 +1130,15 @@ function autoRestoreWindowsCodexShim(options: RuntimePreflightDeps & {
|
|
|
1104
1130
|
|| !sameStableShimPathProbe(firstProbe, secondProbe)) return { status: "deferred" };
|
|
1105
1131
|
}
|
|
1106
1132
|
if (state.platform === "win32") {
|
|
1133
|
+
// Recheck after the lock and the stability sleep, immediately before the wrappers are rewritten.
|
|
1134
|
+
const recheck = checkLegacyShimRecord(state);
|
|
1135
|
+
if (!recheck.ok) return { status: "ineligible", message: legacyShimManualRestoreMessage(recheck.reason, statePath()) };
|
|
1107
1136
|
const realFor = (path: string) => { const file = files.find(entry => entry.wrapperPath === path)!; return file.realPath ?? file.backupPath; };
|
|
1108
|
-
|
|
1109
|
-
|
|
1137
|
+
const release = setLegacyShimMutationGuard(recheck);
|
|
1138
|
+
try {
|
|
1139
|
+
return refreshAdmittedWindowsShims(obsoleteShimProbes, currentShimProbes, path => windowsShimContent(path, realFor(path), runtime))
|
|
1140
|
+
? { status: "restored", message: `Upgraded Codex autostart shim at ${[...obsoleteShimProbes.keys()].join(", ")}.` } : { status: "deferred" };
|
|
1141
|
+
} finally { release(); }
|
|
1110
1142
|
}
|
|
1111
1143
|
const result = refreshObsoleteUnixShims(files);
|
|
1112
1144
|
return result.installed
|
|
@@ -1130,13 +1162,13 @@ function autoRestoreWindowsCodexShim(options: RuntimePreflightDeps & {
|
|
|
1130
1162
|
});
|
|
1131
1163
|
return result.installed
|
|
1132
1164
|
? { status: "restored", message: result.message }
|
|
1133
|
-
: { status: "deferred" };
|
|
1165
|
+
: result.refused ? { status: "ineligible", message: result.message } : { status: "deferred" };
|
|
1134
1166
|
} finally {
|
|
1135
1167
|
lock.release();
|
|
1136
1168
|
}
|
|
1137
1169
|
}
|
|
1138
1170
|
|
|
1139
|
-
export function uninstallCodexShim(): { removed: boolean; message: string } {
|
|
1171
|
+
export function uninstallCodexShim(): { removed: boolean; message: string; refused?: boolean } {
|
|
1140
1172
|
if (process.platform !== "win32") return uninstallUnixCodexShim();
|
|
1141
1173
|
const gate = beginCodexCliSelectionParentWrite();
|
|
1142
1174
|
if (!gate.entered) return { removed: false, message: "codex_cli_selection_busy" };
|
|
@@ -1144,16 +1176,43 @@ export function uninstallCodexShim(): { removed: boolean; message: string } {
|
|
|
1144
1176
|
finally { gate.exit(); }
|
|
1145
1177
|
}
|
|
1146
1178
|
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1179
|
+
let legacyUninstallStepHookForTests: ((step: "unlink" | "rename", index: number) => void) | null = null;
|
|
1180
|
+
/** @internal Runs before each uninstall mutation, after validation; lets tests change the filesystem there. */
|
|
1181
|
+
export function setLegacyShimUninstallStepHookForTests(hook: typeof legacyUninstallStepHookForTests): void {
|
|
1182
|
+
legacyUninstallStepHookForTests = hook;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
function uninstallWindowsCodexShim(): { removed: boolean; message: string; refused?: boolean } {
|
|
1186
|
+
const read = readStateResult();
|
|
1187
|
+
const refused = (reason: string, partial = false) => ({ removed: false, refused: true, message: legacyShimManualRestoreMessage(reason, statePath(), partial) });
|
|
1188
|
+
if (!read.state) return read.present ? refused(read.warning ? "the shim record is unsafe to read" : "the shim record is unreadable") : { removed: false, message: "Codex autostart shim is not installed." };
|
|
1189
|
+
if (read.state.mode !== undefined || read.state.platform !== "win32") {
|
|
1190
|
+
// Another platform's record (a config directory shared with WSL) names no Windows launcher.
|
|
1191
|
+
if (existsSync(statePath())) unlinkSync(statePath());
|
|
1192
|
+
return { removed: true, message: "Codex autostart shim record from another platform removed; no launcher file was changed." };
|
|
1154
1193
|
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1194
|
+
const checked = checkLegacyShimRecord(read.state);
|
|
1195
|
+
if (!checked.ok) return refused(checked.reason);
|
|
1196
|
+
const { files, recordedDirectory, resolvedDirectory, directoryIdentity } = checked;
|
|
1197
|
+
if (resolvedDirectory !== null) {
|
|
1198
|
+
const api = hostShimPathApi();
|
|
1199
|
+
const at = (path: string) => api.join(resolvedDirectory, api.basename(path));
|
|
1200
|
+
// Act only inside the directory that was validated, and only while it still resolves there.
|
|
1201
|
+
const stillValid = () => legacyShimDirectoryUnchanged(recordedDirectory, resolvedDirectory, directoryIdentity)
|
|
1202
|
+
&& legacyShimFilesProblem(files, resolvedDirectory) === null;
|
|
1203
|
+
let step = 0;
|
|
1204
|
+
for (const [index, file] of files.entries()) {
|
|
1205
|
+
legacyUninstallStepHookForTests?.("unlink", index);
|
|
1206
|
+
if (!stillValid()) return refused("the launcher directory changed during removal", step > 0);
|
|
1207
|
+
const wrapper = at(file.wrapperPath);
|
|
1208
|
+
if (existsSync(wrapper) && isShim(wrapper)) { unlinkSync(wrapper); step++; }
|
|
1209
|
+
}
|
|
1210
|
+
for (const [index, file] of files.entries()) {
|
|
1211
|
+
legacyUninstallStepHookForTests?.("rename", index);
|
|
1212
|
+
if (!stillValid()) return refused("the launcher directory changed during removal", step > 0);
|
|
1213
|
+
const backup = at(file.backupPath), original = at(file.originalPath);
|
|
1214
|
+
if (existsSync(backup) && !existsSync(original)) { renameSync(backup, original); step++; }
|
|
1215
|
+
}
|
|
1157
1216
|
}
|
|
1158
1217
|
if (existsSync(statePath())) unlinkSync(statePath());
|
|
1159
1218
|
return { removed: true, message: `Codex autostart shim removed. Restored ${files.map(f => f.originalPath).join(", ")}.` };
|