@bitkyc08/opencodex 2.93.0 → 2.94.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/README.md +27 -8
- package/bin/ocx.mjs +215 -63
- package/gui/dist/assets/App-DmvwlhQq.js +58 -0
- package/gui/dist/assets/Tray-CZatQdoF.js +1 -0
- package/gui/dist/assets/index-3EPO_KbX.js +94 -0
- package/gui/dist/assets/index-CHWwDo9L.css +1 -0
- package/gui/dist/assets/{quota-summary-BXu4zE8H.js → quota-summary-BHvWg9mi.js} +1 -1
- package/gui/dist/index.html +2 -2
- package/gui/dist/provider-icons/t3code.svg +4 -0
- package/package.json +7 -4
- package/src/adapters/anthropic/account-metadata.ts +34 -3
- package/src/adapters/anthropic/beta-allowlist.ts +5 -5
- package/src/adapters/anthropic/passthrough.ts +5 -2
- package/src/adapters/anthropic.ts +17 -4
- package/src/adapters/antigravity-refusal.ts +29 -0
- package/src/adapters/base.ts +11 -1
- package/src/adapters/client-fingerprint.ts +43 -9
- package/src/adapters/coding-agent/protocol.ts +19 -9
- package/src/adapters/command-code.ts +4 -5
- package/src/adapters/cursor/catalog.ts +5 -3
- package/src/adapters/cursor/claude-id.ts +30 -19
- package/src/adapters/cursor/cursor-errors.ts +5 -2
- package/src/adapters/cursor/h2-pool.ts +9 -7
- package/src/adapters/cursor/http1-bidi.ts +1 -0
- package/src/adapters/cursor/live-models.ts +4 -2
- package/src/adapters/cursor.ts +4 -1
- package/src/adapters/devin/cloud-direct/chat.ts +18 -2
- package/src/adapters/google-antigravity-replay.ts +13 -2
- package/src/adapters/google-antigravity-wire.ts +8 -3
- package/src/adapters/google-errors.ts +33 -0
- package/src/adapters/google-http.ts +41 -16
- package/src/adapters/google-wire-compiler.ts +4 -0
- package/src/adapters/google.ts +21 -10
- package/src/adapters/kiro/adapter.ts +3 -0
- package/src/adapters/kiro/stream.ts +18 -13
- package/src/adapters/openai-chat/completed-tool-blocks.ts +65 -0
- package/src/adapters/openai-chat/messages.ts +22 -10
- package/src/adapters/openai-chat/required-tool-result.ts +3 -3
- package/src/adapters/openai-chat/serialized-tool-call-content.ts +5 -0
- package/src/adapters/openai-chat/wire.ts +9 -0
- package/src/adapters/openai-chat.ts +18 -17
- package/src/adapters/openai-responses/image-gen.ts +15 -1
- package/src/adapters/openai-responses/passthrough.ts +11 -34
- package/src/adapters/openai-responses/transport.ts +20 -2
- package/src/adapters/openai-responses/usage.ts +34 -0
- package/src/adapters/qoder/adapter.ts +9 -15
- package/src/adapters/qoder/image-input.ts +52 -0
- package/src/adapters/unique-tool-call-ids.ts +2 -2
- package/src/adapters/zed-additional-tools.ts +51 -0
- package/src/adapters/zed-diagnostic-usage.ts +22 -0
- package/src/adapters/zed-json-tokens.ts +166 -0
- package/src/adapters/zed-openai-stream.ts +723 -0
- package/src/adapters/zed-tool-arguments.ts +79 -0
- package/src/adapters/zed.ts +53 -3
- package/src/advisor/consult.ts +22 -0
- package/src/advisor/runtime.ts +3 -0
- package/src/bridge/errors.ts +22 -1
- package/src/bridge/response-json.ts +4 -1
- package/src/bridge/sse.ts +21 -12
- package/src/chat/inbound.ts +13 -2
- package/src/chatgpt/app-server-shim/bundle-trust-async.ts +111 -0
- package/src/chatgpt/app-server-shim/bundle-trust-policy.ts +83 -0
- package/src/chatgpt/app-server-shim/bundle-trust.ts +15 -72
- package/src/claude/desktop-first-party.ts +16 -5
- package/src/claude/desktop-gateway-state.ts +4 -0
- package/src/claude/inbound-tool-loading.ts +93 -0
- package/src/claude/intercept/picker-listener.ts +33 -1
- package/src/claude/model-info.ts +29 -4
- package/src/claude/outbound.ts +33 -13
- package/src/cli/account-main.ts +43 -5
- package/src/cli/capabilities-base.ts +22 -5
- package/src/cli/capabilities-integrations.ts +4 -4
- package/src/cli/claude-desktop.ts +139 -98
- package/src/cli/codex-cli-update.ts +102 -48
- package/src/cli/codex-launch-auth.ts +93 -0
- package/src/cli/codex-launch-command.ts +32 -0
- package/src/cli/codex-launch-diagnostics.ts +37 -0
- package/src/cli/codex-launch-ownership.ts +307 -0
- package/src/cli/codex-launch-policy.ts +84 -0
- package/src/cli/codex-launcher.ts +310 -0
- package/src/cli/codex-shim-autorestore.ts +2 -0
- package/src/cli/config-command.ts +9 -4
- package/src/cli/config-mutation.ts +13 -0
- package/src/cli/dispatch.ts +13 -7
- package/src/cli/effort.ts +19 -14
- package/src/cli/ensure-desired-integrations.ts +21 -14
- package/src/cli/ensure-desktop-cold-start.ts +41 -10
- package/src/cli/export-command.ts +8 -4
- package/src/cli/help.ts +3 -1
- package/src/cli/index.ts +58 -64
- package/src/cli/integration-input.ts +12 -0
- package/src/cli/integration-plan-dto.ts +2 -0
- package/src/cli/integration-preview.ts +6 -3
- package/src/cli/integrations.ts +2 -1
- package/src/cli/link-cleanup.ts +8 -23
- package/src/cli/link-enrollment.ts +1 -4
- package/src/cli/link.ts +1 -1
- package/src/cli/loopback-family.ts +2 -31
- package/src/cli/models.ts +62 -49
- package/src/cli/provider.ts +146 -139
- package/src/cli/registry.ts +34 -3
- package/src/cli/root.ts +2 -0
- package/src/cli/start-owner-fence.ts +22 -3
- package/src/cli/status-link.ts +28 -0
- package/src/cli/status.ts +15 -0
- package/src/cli/stop-restore-guard.ts +48 -0
- package/src/cli/stop-restore.ts +117 -36
- package/src/cli/system-command.ts +2 -0
- package/src/cli/v2.ts +17 -4
- package/src/client/lifecycle-lock.ts +1 -1
- package/src/client/link-connection.ts +19 -0
- package/src/client/link-relay-transport.ts +25 -3
- package/src/client/link-tunnel.ts +10 -0
- package/src/client/machine-listener.ts +7 -1
- package/src/client/restore-ownership.ts +45 -0
- package/src/client/runtime.ts +13 -1
- package/src/client/state.ts +1 -1
- package/src/clients/client-ids.ts +7 -0
- package/src/clients/client-path.ts +13 -5
- package/src/clients/config-export/agent-clients.ts +3 -6
- package/src/clients/config-export/alias-selectors.ts +85 -0
- package/src/clients/config-export/contracts.ts +6 -25
- package/src/clients/config-export/dsh.ts +8 -1
- package/src/clients/config-export/model-metadata.ts +19 -0
- package/src/clients/config-export/model-names.ts +31 -0
- package/src/clients/config-export/qoder.ts +3 -11
- package/src/clients/config-export/t3code.ts +141 -0
- package/src/clients/config-export.ts +51 -15
- package/src/clients/gentle-shell-path.ts +3 -3
- package/src/codex/account-lifecycle.ts +27 -13
- package/src/codex/account-store.ts +32 -6
- package/src/codex/app-server-processes.ts +84 -1
- package/src/codex/auth-api/main-account-probe.ts +50 -11
- package/src/codex/auth-api/pool-mode-gate.ts +16 -8
- package/src/codex/auth-context.ts +45 -4
- package/src/codex/catalog/antigravity-discovery.ts +59 -0
- package/src/codex/catalog/build-entries.ts +12 -13
- package/src/codex/catalog/bundled.ts +59 -9
- package/src/codex/catalog/derive-entry.ts +2 -0
- package/src/codex/catalog/gather-capture.ts +3 -0
- package/src/codex/catalog/metadata.ts +6 -5
- package/src/codex/catalog/model-hints.ts +36 -4
- package/src/codex/catalog/native-priority.ts +63 -0
- package/src/codex/catalog/provider-models.ts +20 -4
- package/src/codex/catalog/retained-sync.ts +1 -1
- package/src/codex/chatgpt-refresh-failure.ts +2 -2
- package/src/codex/cli-install-provenance.ts +57 -29
- package/src/codex/cli-installation-identity.ts +1 -1
- package/src/codex/cli-installation-limits.ts +7 -0
- package/src/codex/cli-update-apply.ts +391 -0
- package/src/codex/cli-update-artifacts.ts +257 -0
- package/src/codex/cli-update-files.ts +100 -0
- package/src/codex/cli-update-inspection-context.ts +49 -0
- package/src/codex/cli-update-job-execution.ts +77 -0
- package/src/codex/cli-update-job-store-windows.ts +1010 -0
- package/src/codex/cli-update-job-worker.ts +393 -0
- package/src/codex/cli-update-job.ts +369 -0
- package/src/codex/cli-update-lease.ts +71 -0
- package/src/codex/cli-update-paths.ts +76 -0
- package/src/codex/cli-update-plan.ts +180 -47
- package/src/codex/cli-update-recovery.ts +236 -0
- package/src/codex/cli-update-selection-gate.ts +235 -0
- package/src/codex/cli-update-windows-apply.ts +308 -0
- package/src/codex/cli-update-windows-layout.ts +110 -0
- package/src/codex/cli-update-windows-observation.ts +91 -0
- package/src/codex/cli-update-windows-paths.ts +26 -0
- package/src/codex/cli-update-worker-recovery.ts +32 -0
- package/src/codex/cli-update-worker.ts +185 -0
- package/src/codex/cli-windows-plan-provenance.ts +250 -0
- package/src/codex/desktop-app-restart.ts +22 -3
- package/src/codex/exec-boundary.ts +208 -0
- package/src/codex/forward-transport-headers.ts +80 -0
- package/src/codex/history-job.ts +7 -0
- package/src/codex/history-provider.ts +5 -2
- package/src/codex/history-worker.ts +20 -1
- package/src/codex/inject/restore.ts +57 -25
- package/src/codex/internal/history-writer.ts +2 -1
- package/src/codex/mac-app-bundle.ts +52 -0
- package/src/codex/main-account.ts +161 -23
- package/src/codex/native-main-auth-temp.ts +3 -2
- package/src/codex/native-main-refresh-mode.ts +18 -3
- package/src/codex/native-profile-manager.ts +8 -6
- package/src/codex/native-profile-store.ts +9 -0
- package/src/codex/ocx-compaction-history.ts +3 -2
- package/src/codex/prompt-text-probe.ts +211 -69
- package/src/codex/quota.ts +9 -0
- package/src/codex/role-model-history.ts +253 -0
- package/src/codex/runtime.ts +120 -71
- package/src/codex/shim-overlay.ts +22 -3
- package/src/codex/shim-templates.ts +5 -2
- package/src/codex/shim-wrapper-write.ts +136 -0
- package/src/codex/shim.ts +24 -125
- package/src/codex/windows-cli-child-native.ts +119 -0
- package/src/codex/windows-cli-child-pipe.ts +87 -0
- package/src/codex/windows-cli-child.ts +260 -0
- package/src/codex/windows-cli-recovery-guardian.ts +89 -0
- package/src/codex/windows-cli-recovery.ts +39 -0
- package/src/codex/windows-installation-files.ts +52 -6
- package/src/codex/windows-npm-execution.ts +25 -0
- package/src/combos/failover.ts +84 -5
- package/src/combos/index.ts +1 -0
- package/src/combos/resolve.ts +60 -22
- package/src/config/atomic-write.ts +75 -22
- package/src/config/diagnostics.ts +18 -10
- package/src/config/live-reconcile.ts +11 -3
- package/src/config/owner-registry.ts +5 -4
- package/src/config/persist-unlocked.ts +34 -8
- package/src/config/persisted-mutation.ts +7 -0
- package/src/config/process-state.ts +9 -5
- package/src/config/removed-opencode-free-backup.ts +99 -0
- package/src/config/removed-opencode-free.ts +4 -8
- package/src/config/salvage.ts +1 -0
- package/src/config/schema/config-schema.ts +16 -1
- package/src/config/schema/leaf-validators.ts +15 -0
- package/src/config.ts +4 -4
- package/src/generated/compatibility-version.json +743 -315
- package/src/grok/inject.ts +2 -1
- package/src/grok/sync.ts +5 -2
- package/src/images/loop.ts +14 -5
- package/src/integrations/catalog-refresh.ts +1 -1
- package/src/integrations/hermes-refresh.ts +28 -0
- package/src/integrations/model-name-guard.ts +31 -0
- package/src/integrations/mutation-plan.ts +17 -4
- package/src/integrations/ownership.ts +3 -0
- package/src/integrations/registry.ts +10 -1
- package/src/integrations/state.ts +6 -0
- package/src/integrations/writer.ts +64 -59
- package/src/lib/abort.ts +8 -4
- package/src/lib/bounded-body.ts +7 -1
- package/src/lib/config-ownership.ts +4 -0
- package/src/lib/errors.ts +2 -0
- package/src/lib/eventstream-decoder.ts +3 -2
- package/src/lib/http-response-semantics.ts +9 -6
- package/src/lib/inbound-body-policy.ts +11 -0
- package/src/lib/jsonc.ts +7 -2
- package/src/lib/local-management-capability.ts +3 -1
- package/src/lib/local-upstream.ts +22 -26
- package/src/lib/loopback-family.ts +31 -0
- package/src/lib/plain-data.ts +7 -5
- package/src/lib/process-control.ts +30 -5
- package/src/lib/shadow-call.ts +55 -1
- package/src/lib/tool-argument-integers.ts +99 -7
- package/src/lib/upstream-retry.ts +6 -1
- package/src/lib/windows-elevation.ts +34 -11
- package/src/lib/windows-owner-acl.ts +272 -32
- package/src/lib/windows-secret-acl.ts +310 -44
- package/src/lib/windows-service-wrappers.ts +10 -7
- package/src/lib/winsw.ts +8 -4
- package/src/link/relay-auth.ts +38 -1
- package/src/link/remote-platform.ts +11 -23
- package/src/link/remote-probe.ts +3 -1
- package/src/link/remote-windows.ts +150 -0
- package/src/link/ssh-argv.ts +13 -5
- package/src/link/store.ts +4 -1
- package/src/link/supervisor.ts +9 -0
- package/src/local-credentials/generation.ts +238 -0
- package/src/local-credentials/inventory.ts +281 -0
- package/src/local-credentials/observation-lease.ts +83 -0
- package/src/local-credentials/publication-fence.ts +81 -0
- package/src/local-credentials/references.ts +36 -0
- package/src/local-credentials/runtime-observation.ts +28 -0
- package/src/oauth/account-auto-pause-policy.ts +11 -0
- package/src/oauth/anthropic-account-refusal.ts +1 -0
- package/src/oauth/anthropic-rate-limit-policy.ts +26 -2
- package/src/oauth/anthropic-routing.ts +34 -44
- package/src/oauth/anthropic-session-affinity-store.ts +177 -0
- package/src/oauth/chatgpt.ts +11 -9
- package/src/oauth/cursor.ts +8 -2
- package/src/oauth/generic-account-failover.ts +33 -2
- package/src/oauth/generic-session-affinity.ts +7 -0
- package/src/oauth/google-antigravity.ts +29 -5
- package/src/oauth/index.ts +1 -0
- package/src/oauth/store.ts +32 -4
- package/src/protocols/encoders/adapter-events.ts +7 -4
- package/src/protocols/encoders/messages.ts +1 -1
- package/src/providers/antigravity-account-roster.ts +73 -7
- package/src/providers/antigravity-models.ts +8 -4
- package/src/providers/api-key-resolve.ts +16 -3
- package/src/providers/claude-cli-identity.ts +2 -0
- package/src/providers/codex-capacity.ts +3 -2
- package/src/providers/free-directory.ts +10 -2
- package/src/providers/key-store.ts +7 -2
- package/src/providers/provider-id-rewrite.ts +3 -0
- package/src/providers/quota/antigravity.ts +6 -4
- package/src/providers/quota/vendor-probes-oauth.ts +0 -1
- package/src/providers/stale-model-roster-migration.ts +3 -0
- package/src/quota-pool/assemble.ts +51 -21
- package/src/quota-pool/pooled.ts +162 -0
- package/src/remote-control/workspace-codex-runtime.ts +63 -20
- package/src/responses/apply-patch-envelope.ts +35 -0
- package/src/responses/compaction-history-framing.ts +15 -4
- package/src/responses/turn-membership.ts +111 -0
- package/src/server/advisor-admission-scope.ts +43 -0
- package/src/server/audio-upstream.ts +10 -2
- package/src/server/auth-cors.ts +23 -0
- package/src/server/bind-host.ts +5 -0
- package/src/server/chat-completions.ts +17 -2
- package/src/server/chat-native.ts +16 -11
- package/src/server/claude-messages.ts +9 -1
- package/src/server/codex-model-list.ts +46 -0
- package/src/server/gui-session.ts +5 -2
- package/src/server/inbound-body-admission.ts +21 -13
- package/src/server/inbound-body-budget.ts +128 -0
- package/src/server/index/link-listener.ts +3 -1
- package/src/server/index/link-relay-sessions.ts +9 -2
- package/src/server/index/optional-listeners.ts +1 -0
- package/src/server/index/serve-options.ts +9 -43
- package/src/server/index/websocket-handler.ts +7 -0
- package/src/server/index.ts +6 -5
- package/src/server/inference/client-encoder-delivery.ts +3 -1
- package/src/server/lifecycle.ts +8 -1
- package/src/server/management/advisor-routes.ts +26 -9
- package/src/server/management/agent-settings-routes.ts +424 -543
- package/src/server/management/anthropic-reset-grant-routes.ts +2 -1
- package/src/server/management/claude-code-settings-patch.ts +211 -0
- package/src/server/management/claude-desktop-config-writers.ts +78 -0
- package/src/server/management/codex-agent-role-routes.ts +79 -2
- package/src/server/management/codex-cli-update-routes.ts +55 -0
- package/src/server/management/codex-prompt-routes.ts +2 -1
- package/src/server/management/config-routes.ts +444 -380
- package/src/server/management/consent-session.ts +6 -0
- package/src/server/management/desktop-compatibility-authorization.ts +12 -0
- package/src/server/management/desktop-compatibility-routes.ts +3 -2
- package/src/server/management/desktop-compatibility-runtime-routes.ts +2 -1
- package/src/server/management/desktop-compatibility-settings-routes.ts +2 -1
- package/src/server/management/integration-routes.ts +45 -5
- package/src/server/management/link-enrollment.ts +21 -32
- package/src/server/management/link-route-state.ts +1 -0
- package/src/server/management/link-routes.ts +4 -1
- package/src/server/management/model-routes.ts +22 -6
- package/src/server/management/model-rows.ts +3 -1
- package/src/server/management/native-integration-routes.ts +90 -38
- package/src/server/management/oauth-account-routes.ts +8 -7
- package/src/server/management/route-registry.ts +8 -3
- package/src/server/management/session-routes.ts +20 -2
- package/src/server/management/shadow-call-validation.ts +43 -2
- package/src/server/management/sidebar-routes.ts +2 -1
- package/src/server/management/system-restart.ts +47 -7
- package/src/server/management-api.ts +61 -51
- package/src/server/management-auth.ts +11 -3
- package/src/server/messages-native.ts +21 -7
- package/src/server/messages-shared.ts +110 -18
- package/src/server/persistent-gui-session.ts +155 -0
- package/src/server/port-reclaim.ts +29 -5
- package/src/server/proxy-liveness.ts +110 -33
- package/src/server/request-decompress.ts +5 -1
- package/src/server/responses/account-change-state.ts +14 -2
- package/src/server/responses/adapter-continuation.ts +5 -4
- package/src/server/responses/adapter-delivery.ts +20 -5
- package/src/server/responses/adapter-dispatch.ts +39 -45
- package/src/server/responses/advisor-plan-slot.ts +3 -0
- package/src/server/responses/advisor-slot.ts +4 -2
- package/src/server/responses/antigravity-model-denial-recovery.ts +70 -0
- package/src/server/responses/antigravity-validation-refusal.ts +6 -0
- package/src/server/responses/combo-required-tool-contract.ts +2 -1
- package/src/server/responses/combo-required-tool-fulfillments.ts +58 -0
- package/src/server/responses/combo-required-tool-stream.ts +119 -0
- package/src/server/responses/combo-stream-preflight.ts +47 -7
- package/src/server/responses/compact.ts +14 -7
- package/src/server/responses/compaction-recovery.ts +2 -1
- package/src/server/responses/core-auth.ts +2 -1
- package/src/server/responses/core-codex-account.ts +1 -0
- package/src/server/responses/core-combo-failure.ts +11 -6
- package/src/server/responses/core-combo-native.ts +6 -5
- package/src/server/responses/core-combo.ts +93 -20
- package/src/server/responses/core-options.ts +7 -0
- package/src/server/responses/fetch-helpers.ts +5 -1
- package/src/server/responses/jev-model-invoke.ts +8 -3
- package/src/server/responses/memory-models.ts +3 -2
- package/src/server/responses/passthrough-delivery.ts +36 -8
- package/src/server/responses/passthrough-dispatch.ts +12 -12
- package/src/server/responses/request-prepare.ts +10 -1
- package/src/server/responses/request-transport.ts +41 -6
- package/src/server/responses/run-turn-execution.ts +11 -3
- package/src/server/responses/sidecar-execution.ts +5 -0
- package/src/server/responses/turn-membership.ts +30 -0
- package/src/server/responses-custom-tool-repair.ts +86 -11
- package/src/server/responses-image-gen-repair.ts +1 -1
- package/src/server/restart-parent-ownership.ts +49 -0
- package/src/server/stop-teardown.ts +46 -9
- package/src/server/windows-tcp-drop.ts +4 -2
- package/src/service/desktop-recovery-process.ts +341 -0
- package/src/service/desktop-recovery.ts +172 -0
- package/src/service/windows-ops.ts +6 -3
- package/src/service/windows-scheduler.ts +29 -6
- package/src/stall-timeout.ts +47 -0
- package/src/tray/windows.ts +6 -4
- package/src/types/config.ts +61 -10
- package/src/types/request.ts +1 -1
- package/src/types.ts +1 -0
- package/src/update/async-check.ts +4 -3
- package/src/update/bind-probe.ts +2 -2
- package/src/update/codex-cli-update-launch-policy.mjs +9 -0
- package/src/update/guarded-port-reclaim.ts +14 -0
- package/src/update/guarded-runtime-ops.ts +58 -0
- package/src/update/guarded-tray-ops.ts +9 -0
- package/src/update/index.ts +196 -58
- package/src/update/job-pinned-start.ts +53 -0
- package/src/update/job-supervised-restart.ts +23 -6
- package/src/update/job-update-home.ts +62 -0
- package/src/update/job-update-tray.ts +29 -0
- package/src/update/job-windows-restart.ts +39 -0
- package/src/update/job.ts +179 -193
- package/src/update/mutation-guard.d.mts +30 -0
- package/src/update/mutation-guard.mjs +103 -0
- package/src/update/notify.ts +2 -2
- package/src/update/npm-cache-preflight.mjs +4 -4
- package/src/update/npm-install.mjs +5 -3
- package/src/update/pnpm-read-policy.mjs +3 -2
- package/src/update/proxy-liveness-probe.mjs +2 -2
- package/src/update/service-home-authority.ts +35 -0
- package/src/update/service-home-package-only-protocol.json +1 -0
- package/src/update/service-home-policy.d.mts +25 -0
- package/src/update/service-home-policy.mjs +112 -0
- package/src/update/service-home-probe-entry.ts +9 -0
- package/src/update/service-home-probe.d.mts +15 -0
- package/src/update/service-home-probe.mjs +79 -0
- package/src/update/service-home-protocol.json +1 -0
- package/src/update/supervised-recovery.d.mts +2 -2
- package/src/update/supervised-recovery.mjs +14 -7
- package/src/update/transactional-install.d.mts +3 -1
- package/src/update/transactional-install.mjs +29 -19
- package/src/update/update-failure-guidance.mjs +1 -1
- package/src/update/worker-launch.ts +3 -3
- package/src/vision/anthropic-describe.ts +2 -1
- package/src/web-search/anthropic-executor.ts +2 -1
- package/src/web-search/anthropic-history.ts +1 -0
- package/src/web-search/format-result.ts +3 -2
- package/src/web-search/header-deadline.ts +3 -2
- package/src/web-search/loop.ts +10 -4
- package/src/web-search/parse.ts +191 -38
- package/gui/dist/assets/App-CizjBqyk.js +0 -58
- package/gui/dist/assets/Tray-DamiMqcX.js +0 -1
- package/gui/dist/assets/index-DQsht3vH.js +0 -94
- package/gui/dist/assets/index-DRe8Hhfz.css +0 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { lstatSync, readdirSync } from "node:fs";
|
|
2
|
+
import { win32 } from "node:path";
|
|
3
|
+
import { inspectWindowsInstallationFiles } from "./windows-installation-files";
|
|
4
|
+
import { verifyWindowsEntriesAclAsync, type WindowsAclEntry } from "../lib/windows-owner-acl";
|
|
5
|
+
import { MAX_CODEX_MEMBER_BYTES, MAX_CODEX_UNPACKED_BYTES } from "./cli-update-artifacts";
|
|
6
|
+
import { windowsArchivePathValidator } from "./cli-update-windows-paths";
|
|
7
|
+
import type { WindowsCodexExpectedFile } from "./cli-update-windows-layout";
|
|
8
|
+
|
|
9
|
+
export interface WindowsInstallSnapshot {
|
|
10
|
+
readonly files: readonly (WindowsCodexExpectedFile & { readonly identity: string })[];
|
|
11
|
+
readonly directories: readonly string[];
|
|
12
|
+
readonly absent: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
const roots = ["codex", "codex.cmd", "codex.ps1", "node_modules/@openai/codex",
|
|
15
|
+
"node_modules/@openai/codex-win32-x64", "node_modules/.package-lock.json"];
|
|
16
|
+
const key = (path: string) => path.replaceAll("\\", "/");
|
|
17
|
+
export const windowsCodexOwnedPath = (relative: string): boolean => roots.slice(0, -1).some(root =>
|
|
18
|
+
relative === root || relative.startsWith(root + "/"));
|
|
19
|
+
|
|
20
|
+
/** Bound the existing shared prefix, never follow links outside it. Only our separately
|
|
21
|
+
* pinned mutex is excluded. Unrelated packages and shims are preservation obligations,
|
|
22
|
+
* not installer targets. Oversized or unsupported namespaces refuse before npm starts.
|
|
23
|
+
*/
|
|
24
|
+
function inventory(prefix: string) {
|
|
25
|
+
const paths: string[] = [], directories: string[] = [], acl: WindowsAclEntry[] = [];
|
|
26
|
+
const validate = windowsArchivePathValidator();
|
|
27
|
+
let entries = 0, total = 0n;
|
|
28
|
+
const walk = (relative: string) => {
|
|
29
|
+
if (++entries > 4096) throw new Error("installation_readback_limit");
|
|
30
|
+
const path = win32.join(prefix, relative), st = lstatSync(path, { bigint: true });
|
|
31
|
+
if (st.isSymbolicLink() || (!st.isDirectory() && !st.isFile()) || (!st.isDirectory() && st.nlink !== 1n)) {
|
|
32
|
+
throw new Error("installation_path_unverified");
|
|
33
|
+
}
|
|
34
|
+
validate(relative, st.isDirectory());
|
|
35
|
+
// Descriptor readers need extended-length targets; inventory/native identity
|
|
36
|
+
// paths retain their canonical DOS spelling.
|
|
37
|
+
acl.push({ path: win32.toNamespacedPath(path), directory: st.isDirectory(), policy: "write-private" });
|
|
38
|
+
if (st.isDirectory()) {
|
|
39
|
+
directories.push(`${relative}:${st.dev}:${st.ino}`);
|
|
40
|
+
for (const name of readdirSync(path).sort()) walk(`${relative}/${name}`);
|
|
41
|
+
} else {
|
|
42
|
+
total += st.size;
|
|
43
|
+
if (st.size > BigInt(MAX_CODEX_MEMBER_BYTES) || total > BigInt(MAX_CODEX_UNPACKED_BYTES)) throw new Error("installation_readback_limit");
|
|
44
|
+
paths.push(relative);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
for (const relative of readdirSync(prefix).sort()) if (relative !== ".ocx-codex-cli-apply.lock") walk(relative);
|
|
48
|
+
const absent = roots.filter(root => !paths.includes(root) && !directories.some(dir => dir.startsWith(root + ":")));
|
|
49
|
+
return { paths, directories, acl, absent };
|
|
50
|
+
}
|
|
51
|
+
export function windowsInstallNamespaceSupported(prefix: string): boolean {
|
|
52
|
+
try { inventory(prefix); return true; } catch { return false; }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Full bounded observation of both old/new package lanes, three shims and npm hidden lock.
|
|
56
|
+
* Includes absence and empty directories. A positive match cannot be made by reading only
|
|
57
|
+
* expected filenames. No POSIX executable-bit guesses substitute for Windows identity/ACL.
|
|
58
|
+
*/
|
|
59
|
+
export async function observeWindowsInstall(prefix: string): Promise<WindowsInstallSnapshot> {
|
|
60
|
+
const { paths, directories, absent, acl } = inventory(prefix);
|
|
61
|
+
// Existing ancestors are guarded by the authority; each observed child must also
|
|
62
|
+
// refuse writes from principals outside that same trust boundary.
|
|
63
|
+
for (let i = 0; i < acl.length; i += 32) {
|
|
64
|
+
if (!await verifyWindowsEntriesAclAsync(acl.slice(i, i + 32), 5000)) throw new Error("installation_acl_unverified");
|
|
65
|
+
}
|
|
66
|
+
const files: (WindowsCodexExpectedFile & { identity: string })[] = [];
|
|
67
|
+
for (let i = 0; i < paths.length; i += 12) {
|
|
68
|
+
const batch = paths.slice(i, i + 12);
|
|
69
|
+
const observed = await inspectWindowsInstallationFiles(batch.map(relative => ({
|
|
70
|
+
path: win32.join(prefix, relative), maxBytes: lstatSync(win32.join(prefix, relative)).size, hashOnly: true, installationDigest: true,
|
|
71
|
+
})));
|
|
72
|
+
if (observed.kind !== "observed") throw new Error("installation_file_unverified");
|
|
73
|
+
for (const file of observed.files) files.push({ relativePath: key(win32.relative(prefix, file.path)),
|
|
74
|
+
size: file.identity.size, digest: file.digest, identity: JSON.stringify(file.identity) });
|
|
75
|
+
}
|
|
76
|
+
// Detect namespace changes while the bounded observations yielded.
|
|
77
|
+
const again = inventory(prefix);
|
|
78
|
+
if (JSON.stringify([...again.directories, ...again.paths].sort()) !== JSON.stringify([...directories, ...paths].sort())
|
|
79
|
+
|| JSON.stringify(absent) !== JSON.stringify(again.absent)) throw new Error("installation_changed");
|
|
80
|
+
return { files: files.sort((a, b) => a.relativePath.localeCompare(b.relativePath)), directories: directories.sort(), absent: absent.sort() };
|
|
81
|
+
}
|
|
82
|
+
export const sameWindowsInstall = (left: WindowsInstallSnapshot, right: WindowsInstallSnapshot): boolean =>
|
|
83
|
+
JSON.stringify(left) === JSON.stringify(right);
|
|
84
|
+
/** npm metadata and every bounded unrelated entry must retain bytes and identity. */
|
|
85
|
+
export function sameWindowsPreservedEntries(left: WindowsInstallSnapshot, right: WindowsInstallSnapshot): boolean {
|
|
86
|
+
const preserved = (snapshot: WindowsInstallSnapshot) => ({
|
|
87
|
+
files: snapshot.files.filter(file => !windowsCodexOwnedPath(file.relativePath)),
|
|
88
|
+
directories: snapshot.directories.filter(dir => !windowsCodexOwnedPath(dir.split(":")[0]!)),
|
|
89
|
+
});
|
|
90
|
+
return JSON.stringify(preserved(left)) === JSON.stringify(preserved(right));
|
|
91
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Archive names only, never filesystem resolution or installation authority. */
|
|
2
|
+
export const WINDOWS_CODEX_NATIVE_MEMBER = "vendor/x86_64-pc-windows-msvc/bin/codex.exe";
|
|
3
|
+
export const WINDOWS_CODEX_HEADER_BYTES = 4096;
|
|
4
|
+
|
|
5
|
+
/** ASCII is the supported archive namespace. Refuse unknown Windows case folding. */
|
|
6
|
+
export function windowsArchivePathValidator(): (name: string, directory: boolean) => void {
|
|
7
|
+
const seen = new Map<string, { spelling: string; directory: boolean; explicit: boolean }>();
|
|
8
|
+
return (name, directory) => {
|
|
9
|
+
const relative = directory && name.endsWith("/") ? name.slice(0, -1) : name;
|
|
10
|
+
const parts = relative.split("/");
|
|
11
|
+
if (relative.length > 8192 || parts.length > 64 || parts.some(part => !part || part === "." || part === ".."
|
|
12
|
+
|| /[^\x20-\x7e]|[<>:"\\|?*]/.test(part) || /[. ]$/.test(part)
|
|
13
|
+
|| /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)|^(?:conin\$|conout\$)$/i.test(part))) {
|
|
14
|
+
throw new Error("artifact_windows_path_unverified");
|
|
15
|
+
}
|
|
16
|
+
for (let i = 0; i < parts.length; i++) {
|
|
17
|
+
const spelling = parts.slice(0, i + 1).join("/"), key = spelling.toLowerCase();
|
|
18
|
+
const isDirectory = directory || i < parts.length - 1, explicit = i === parts.length - 1;
|
|
19
|
+
const prior = seen.get(key);
|
|
20
|
+
if (prior && (prior.spelling !== spelling || prior.directory !== isDirectory || prior.explicit && explicit)) {
|
|
21
|
+
throw new Error("artifact_windows_path_collision");
|
|
22
|
+
}
|
|
23
|
+
seen.set(key, { spelling, directory: isDirectory, explicit: explicit || !!prior?.explicit });
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { codexCliUpdateGroupGone, closedWindowsCodexCliUpdateChildGone, finishClosedCodexCliUpdateRecovery } from "./cli-update-recovery";
|
|
2
|
+
import { CODEX_CLI_UPDATE_FENCE_COMMITTED, CODEX_CLI_UPDATE_FENCE_RECOVERING,
|
|
3
|
+
CODEX_CLI_UPDATE_FENCE_CANCELLED, cancelCodexCliUpdateFence, releaseCodexCliUpdateGateOwner } from "./cli-update-selection-gate";
|
|
4
|
+
|
|
5
|
+
/** Close is authority only before commit. After commit require exact group absence. */
|
|
6
|
+
export function recoverClosedCodexCliUpdateWorker(gate: SharedArrayBuffer, fence: SharedArrayBuffer, owner: number,
|
|
7
|
+
token: string, configDir?: string): void {
|
|
8
|
+
const view = new Int32Array(fence);
|
|
9
|
+
// Bun close can precede full thread exit. Prevent a late commit before
|
|
10
|
+
// treating PREPARING as proof that no installer can ever start.
|
|
11
|
+
cancelCodexCliUpdateFence(fence);
|
|
12
|
+
if (Atomics.load(new Int32Array(gate), 0) !== owner) return;
|
|
13
|
+
Atomics.compareExchange(view, 0, CODEX_CLI_UPDATE_FENCE_COMMITTED, CODEX_CLI_UPDATE_FENCE_RECOVERING);
|
|
14
|
+
const recover = () => {
|
|
15
|
+
if (Atomics.load(new Int32Array(gate), 0) !== owner) return true;
|
|
16
|
+
if (Atomics.load(view, 0) === CODEX_CLI_UPDATE_FENCE_CANCELLED
|
|
17
|
+
|| Atomics.load(view, 2) === 1 || codexCliUpdateGroupGone(Atomics.load(view, 1))
|
|
18
|
+
|| (process.platform === "win32" && Atomics.load(view, 1) > 0
|
|
19
|
+
&& closedWindowsCodexCliUpdateChildGone(token, configDir, Atomics.load(view, 1)))) {
|
|
20
|
+
try { finishClosedCodexCliUpdateRecovery(token, configDir); }
|
|
21
|
+
catch { return false; }
|
|
22
|
+
releaseCodexCliUpdateGateOwner(gate, owner);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
};
|
|
27
|
+
if (recover()) return;
|
|
28
|
+
const timer = setInterval(() => {
|
|
29
|
+
if (Atomics.load(new Int32Array(gate), 0) !== owner || recover()) clearInterval(timer);
|
|
30
|
+
}, 250);
|
|
31
|
+
timer.unref();
|
|
32
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker-thread entry for one Codex CLI update plan or apply job.
|
|
3
|
+
*
|
|
4
|
+
* The parent owns admission and the durable job ledger; this realm owns the
|
|
5
|
+
* heavy inspection, hashing, staging and installer lifetime. The mutation
|
|
6
|
+
* evidence WeakMap is per-realm, which is exactly why the whole plan/apply
|
|
7
|
+
* must run here rather than only its hashing: report objects and their
|
|
8
|
+
* internal evidence cannot cross the realm boundary together.
|
|
9
|
+
*
|
|
10
|
+
* The message carries the allowlisted launcher snapshot (never the parent's
|
|
11
|
+
* trusted context) plus two shared-memory cells: the process-wide selection
|
|
12
|
+
* GATE the worker holds for its short final window, and the per-job FENCE
|
|
13
|
+
* whose PREPARING -> CANCELLED / PREPARING -> COMMITTED compare-exchanges
|
|
14
|
+
* decide cancel-vs-spawn atomically. A "cancel" message aborts the real
|
|
15
|
+
* AbortSignal handed to apply's fetchArtifact path — the asynchronous half
|
|
16
|
+
* of cancellation; the fence remains the synchronous-section half, and a
|
|
17
|
+
* cancel that loses the commit CAS is never posted. Any other second
|
|
18
|
+
* message is ignored: one worker runs exactly one job and then closes, so
|
|
19
|
+
* a late duplicate or a stale generation cannot attach new work to a dying
|
|
20
|
+
* realm.
|
|
21
|
+
*/
|
|
22
|
+
import { createCodexCliUpdatePlan, type CodexCliUpdateChannel, type CodexCliUpdatePlan } from "./cli-update-plan";
|
|
23
|
+
import { applyCodexCliUpdate, type CodexCliApplyResult } from "./cli-update-apply";
|
|
24
|
+
import {
|
|
25
|
+
codexCliUpdateInspectionDepsFromSnapshot,
|
|
26
|
+
type CodexCliUpdateInspectionSnapshot,
|
|
27
|
+
} from "./cli-update-inspection-context";
|
|
28
|
+
import { codexCliUpdateIsCancelled, createWorkerCommitWindow } from "./cli-update-selection-gate";
|
|
29
|
+
import { recoverWindowsCodexCliInstallations } from "./cli-update-windows-apply";
|
|
30
|
+
import { WindowsCliToolchainCleanupError } from "./cli-update-job-store-windows";
|
|
31
|
+
import { createCodexCliUpdateRecovery } from "./cli-update-recovery";
|
|
32
|
+
|
|
33
|
+
export interface CodexCliUpdateWorkerRunMessage {
|
|
34
|
+
readonly type: "run";
|
|
35
|
+
readonly requestId: string;
|
|
36
|
+
readonly jobId: string;
|
|
37
|
+
readonly operation: "plan" | "apply";
|
|
38
|
+
readonly planId?: string;
|
|
39
|
+
readonly channel?: CodexCliUpdateChannel;
|
|
40
|
+
/** Frozen allowlisted launcher snapshot; never supplemented from ambient env. */
|
|
41
|
+
readonly snapshot: CodexCliUpdateInspectionSnapshot;
|
|
42
|
+
/** Process-wide selection gate cell (see cli-update-selection-gate). */
|
|
43
|
+
readonly gate: SharedArrayBuffer;
|
|
44
|
+
/** Per-job cancel/commit fence cell. */
|
|
45
|
+
readonly fence: SharedArrayBuffer;
|
|
46
|
+
readonly owner?: number;
|
|
47
|
+
/** Env snapshot: a Worker may not observe parent mutations on every platform. */
|
|
48
|
+
readonly env?: { readonly CODEX_HOME?: string; readonly OPENCODEX_HOME?: string };
|
|
49
|
+
}
|
|
50
|
+
/** Same generation/recovery binding for each production worker execution. */
|
|
51
|
+
export function createCodexCliWorkerCommitWindow(message: Pick<CodexCliUpdateWorkerRunMessage,
|
|
52
|
+
"gate" | "fence" | "owner" | "requestId">) {
|
|
53
|
+
return createWorkerCommitWindow({ gate: message.gate, fence: message.fence, owner: message.owner,
|
|
54
|
+
recovery: createCodexCliUpdateRecovery(message.requestId) });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Async half of cancellation; the fence CAS is the synchronous half. */
|
|
58
|
+
export interface CodexCliUpdateWorkerCancelMessage {
|
|
59
|
+
readonly type: "cancel";
|
|
60
|
+
readonly requestId?: string;
|
|
61
|
+
readonly jobId?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type CodexCliUpdateWorkerReply =
|
|
65
|
+
| { readonly type: "done"; readonly requestId: string; readonly jobId: string;
|
|
66
|
+
readonly operation: "plan"; readonly plan: CodexCliUpdatePlan }
|
|
67
|
+
| { readonly type: "done"; readonly requestId: string; readonly jobId: string;
|
|
68
|
+
readonly operation: "apply"; readonly result: CodexCliApplyResult }
|
|
69
|
+
| { readonly type: "error"; readonly requestId: string; readonly jobId: string;
|
|
70
|
+
readonly message: string };
|
|
71
|
+
|
|
72
|
+
function isSharedBuffer(value: unknown): value is SharedArrayBuffer {
|
|
73
|
+
return typeof SharedArrayBuffer !== "undefined"
|
|
74
|
+
&& value instanceof SharedArrayBuffer
|
|
75
|
+
&& value.byteLength >= Int32Array.BYTES_PER_ELEMENT;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isRunMessage(data: unknown): data is CodexCliUpdateWorkerRunMessage {
|
|
79
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) return false;
|
|
80
|
+
const o = data as Record<string, unknown>;
|
|
81
|
+
return o.type === "run"
|
|
82
|
+
&& typeof o.requestId === "string"
|
|
83
|
+
&& typeof o.jobId === "string"
|
|
84
|
+
&& (o.operation === "plan" || o.operation === "apply")
|
|
85
|
+
&& (o.planId === undefined || typeof o.planId === "string")
|
|
86
|
+
&& (o.channel === undefined || o.channel === "latest")
|
|
87
|
+
&& (o.snapshot === null || (typeof o.snapshot === "object" && !Array.isArray(o.snapshot)))
|
|
88
|
+
&& isSharedBuffer(o.gate)
|
|
89
|
+
&& o.gate.byteLength >= Int32Array.BYTES_PER_ELEMENT * 2
|
|
90
|
+
&& isSharedBuffer(o.fence) && o.fence.byteLength >= Int32Array.BYTES_PER_ELEMENT * 3
|
|
91
|
+
&& (o.owner === undefined || (Number.isSafeInteger(o.owner) && (o.owner as number) >= 2));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
declare const self: Worker;
|
|
95
|
+
|
|
96
|
+
// One real AbortSignal per realm for apply's fetchArtifact path; aborting it
|
|
97
|
+
// is idempotent, so a cancel that arrives before the run still refuses the
|
|
98
|
+
// apply at its first checkpoint via signal.aborted.
|
|
99
|
+
const applyAbort = new AbortController();
|
|
100
|
+
let ran = false;
|
|
101
|
+
let runIdentity: { requestId: string; jobId: string } | undefined;
|
|
102
|
+
// A raw Win32 handle is not a Bun event-loop reference. Keep the run-once
|
|
103
|
+
// handler AND exact resource roots until their terminal cleanup releases them.
|
|
104
|
+
export function createCodexCliWorkerLifetime(detach: () => void) {
|
|
105
|
+
let executionFinished = false;
|
|
106
|
+
let detached = false;
|
|
107
|
+
const retainedExecutions = new Set<object>();
|
|
108
|
+
const maybeDetach = () => {
|
|
109
|
+
if (executionFinished && !detached && retainedExecutions.size === 0) { detached = true; detach(); }
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
retain(owner: object): { release(): void } {
|
|
113
|
+
const token = { owner };
|
|
114
|
+
retainedExecutions.add(token);
|
|
115
|
+
return { release() { if (retainedExecutions.delete(token)) maybeDetach(); } };
|
|
116
|
+
},
|
|
117
|
+
finish() { executionFinished = true; maybeDetach(); },
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const lifetime = createCodexCliWorkerLifetime(() => { self.onmessage = null; });
|
|
121
|
+
|
|
122
|
+
// Guarded so the module can be imported directly by tests without a Worker host.
|
|
123
|
+
if (typeof Bun !== "undefined" && Bun.isMainThread === false
|
|
124
|
+
&& typeof self !== "undefined" && typeof self.postMessage === "function") {
|
|
125
|
+
self.onmessage = async (event: MessageEvent<unknown>) => {
|
|
126
|
+
const data = event.data;
|
|
127
|
+
if (data && typeof data === "object" && !Array.isArray(data)
|
|
128
|
+
&& (data as { type?: unknown }).type === "recover"
|
|
129
|
+
&& runIdentity && (data as { requestId?: unknown }).requestId === runIdentity.requestId
|
|
130
|
+
&& (data as { jobId?: unknown }).jobId === runIdentity.jobId) {
|
|
131
|
+
await recoverWindowsCodexCliInstallations();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (data && typeof data === "object" && !Array.isArray(data)
|
|
135
|
+
&& (data as CodexCliUpdateWorkerCancelMessage).type === "cancel") {
|
|
136
|
+
applyAbort.abort();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (ran || !isRunMessage(data)) return;
|
|
140
|
+
ran = true;
|
|
141
|
+
const message = data;
|
|
142
|
+
runIdentity = { requestId: message.requestId, jobId: message.jobId };
|
|
143
|
+
try {
|
|
144
|
+
// Home overrides apply before anything resolves a home-derived path in
|
|
145
|
+
// this realm; they are transport for the job, never snapshot fields.
|
|
146
|
+
if (message.env?.CODEX_HOME) process.env.CODEX_HOME = message.env.CODEX_HOME;
|
|
147
|
+
if (message.env?.OPENCODEX_HOME) process.env.OPENCODEX_HOME = message.env.OPENCODEX_HOME;
|
|
148
|
+
const inspectionDeps = codexCliUpdateInspectionDepsFromSnapshot(message.snapshot);
|
|
149
|
+
if (message.operation === "plan") {
|
|
150
|
+
const plan = await createCodexCliUpdatePlan({
|
|
151
|
+
channel: message.channel ?? "latest",
|
|
152
|
+
inspectionDeps,
|
|
153
|
+
});
|
|
154
|
+
self.postMessage({
|
|
155
|
+
type: "done", requestId: message.requestId, jobId: message.jobId,
|
|
156
|
+
operation: "plan", plan,
|
|
157
|
+
} satisfies CodexCliUpdateWorkerReply);
|
|
158
|
+
} else {
|
|
159
|
+
if (typeof message.planId !== "string") throw new Error("cli_update_worker_missing_plan_id");
|
|
160
|
+
const result = await applyCodexCliUpdate(message.planId, {
|
|
161
|
+
inspectionDeps,
|
|
162
|
+
signal: applyAbort.signal,
|
|
163
|
+
isCancelled: codexCliUpdateIsCancelled(message.fence),
|
|
164
|
+
commitWindow: createCodexCliWorkerCommitWindow(message),
|
|
165
|
+
retainExecution: owner => lifetime.retain(owner),
|
|
166
|
+
});
|
|
167
|
+
self.postMessage({
|
|
168
|
+
type: "done", requestId: message.requestId, jobId: message.jobId,
|
|
169
|
+
operation: "apply", result,
|
|
170
|
+
} satisfies CodexCliUpdateWorkerReply);
|
|
171
|
+
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (error instanceof WindowsCliToolchainCleanupError) lifetime.retain(error.acquisition);
|
|
174
|
+
self.postMessage({
|
|
175
|
+
type: "error", requestId: message.requestId, jobId: message.jobId,
|
|
176
|
+
message: error instanceof Error ? error.message : "cli_update_worker_failed",
|
|
177
|
+
} satisfies CodexCliUpdateWorkerReply);
|
|
178
|
+
} finally {
|
|
179
|
+
// Bun 1.4.4 has no self.close(). Drop the handler only when native owners
|
|
180
|
+
// have released every token; referenced child/I/O work must also drain.
|
|
181
|
+
// The parent's close event is not proof that every OS descendant exited.
|
|
182
|
+
lifetime.finish();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { win32 } from "node:path";
|
|
3
|
+
import { parseStrictSemver } from "../lib/strict-semver";
|
|
4
|
+
import { npmCodexCommandShim } from "./cli-installation-identity";
|
|
5
|
+
import { MAX_NATIVE_BACKING_BYTES } from "./cli-installation-limits";
|
|
6
|
+
import { deriveCodexCliInstallationInput } from "./cli-installation-targets";
|
|
7
|
+
import type { CodexCliInstallProvenanceDeps, CodexCliInstallReport } from "./cli-install-provenance";
|
|
8
|
+
import { resolveCodexRuntime } from "./runtime";
|
|
9
|
+
import { inspectWindowsInstallationFiles as inspectFiles, type WindowsInstallationFilesResult } from "./windows-installation-files";
|
|
10
|
+
|
|
11
|
+
// Every plan observation refuses alternate names, including aliases of ancestors.
|
|
12
|
+
const inspectWindowsInstallationFiles: typeof inspectFiles = (requests, finalize) =>
|
|
13
|
+
inspectFiles(requests.map(request => ({ ...request, requireCanonicalPath: true })), finalize);
|
|
14
|
+
|
|
15
|
+
async function withCanonicalExclusionRoots<R>(roots: readonly string[], run: () => Promise<R>): Promise<R | null> {
|
|
16
|
+
if (!roots.length) return run();
|
|
17
|
+
let result: R | null = null;
|
|
18
|
+
// Keep every exclusion open across the observation/query; validate each batch
|
|
19
|
+
// under the native reader's existing request ceiling without dropping a root.
|
|
20
|
+
const observed = await inspectWindowsInstallationFiles(roots.slice(0, 12).map(path => ({
|
|
21
|
+
path: win32.normalize(path), maxBytes: 0, metadataOnly: true, directory: true,
|
|
22
|
+
})), async () => {
|
|
23
|
+
result = await withCanonicalExclusionRoots(roots.slice(12), run); return result !== null;
|
|
24
|
+
});
|
|
25
|
+
return observed.kind === "observed" ? result : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
import { openWindowsCliToolchainAuthority, WindowsCliToolchainCleanupError } from "./cli-update-job-store-windows";
|
|
29
|
+
|
|
30
|
+
/** Private plan evidence. Explicit `attest` observations never enter this map. */
|
|
31
|
+
interface WindowsPlanEvidence { readonly node: string; readonly npmCli: string; readonly arch: "x64" | "arm64";
|
|
32
|
+
readonly prefix: string; readonly launcher: string; readonly backingRoot: string;
|
|
33
|
+
readonly envPath: string | undefined; readonly envPathExt: string | undefined;
|
|
34
|
+
readonly nodeEvidence: string; readonly npmEvidence: string; readonly exclusionRoots: readonly string[] }
|
|
35
|
+
const evidence = new WeakMap<CodexCliInstallReport, WindowsPlanEvidence>();
|
|
36
|
+
const toolchainDigests = new WeakMap<CodexCliInstallReport, string>();
|
|
37
|
+
export const windowsCodexCliToolchainDigest = (report: CodexCliInstallReport): string | undefined => toolchainDigests.get(report);
|
|
38
|
+
export const windowsCodexCliPlanEvidence = (report: CodexCliInstallReport): WindowsPlanEvidence | null => evidence.get(report) ?? null;
|
|
39
|
+
const hash = (value: string): string => createHash("sha256").update(value).digest("hex");
|
|
40
|
+
type File = Extract<WindowsInstallationFilesResult, { kind: "observed" }>["files"][number];
|
|
41
|
+
const id = (file: File): string => JSON.stringify([file.path, file.identity, file.digest]);
|
|
42
|
+
const sameWindowsPath = (left: string, right: string): boolean => win32.resolve(left).toLowerCase() === win32.resolve(right).toLowerCase();
|
|
43
|
+
function selectedWindowsOverride(candidate: string, env: NodeJS.ProcessEnv, configDir?: string): boolean {
|
|
44
|
+
return env.CODEX_CLI_PATH?.trim() === candidate && resolveCodexRuntime({ platform: "win32", env, configDir,
|
|
45
|
+
probeVersion: false, discoverAlternatives: false, existsSync: path => path === candidate,
|
|
46
|
+
readFileSync: () => { throw new Error("state not required for explicit override"); },
|
|
47
|
+
readdirSync: () => [], statSync: () => { throw new Error("discovery disabled"); },
|
|
48
|
+
}).runtime.command === candidate;
|
|
49
|
+
}
|
|
50
|
+
/** Synchronous selection fence after the last awaited authority check, before native start. */
|
|
51
|
+
export function windowsCodexCliSelectionMatches(report: CodexCliInstallReport, deps: CodexCliInstallProvenanceDeps): boolean {
|
|
52
|
+
const captured = evidence.get(report), env = deps.env;
|
|
53
|
+
return !!captured && !!env && deps.selectionAttested === true && env.PATH === captured.envPath
|
|
54
|
+
&& env.PATHEXT === captured.envPathExt && selectedWindowsOverride(captured.launcher, env, deps.configDir);
|
|
55
|
+
}
|
|
56
|
+
/** Metadata queries execute only while the observed Node/npm and ancestors deny replacement. */
|
|
57
|
+
export async function withWindowsCodexCliPlanToolchain<R>(report: CodexCliInstallReport,
|
|
58
|
+
run: () => R): Promise<Awaited<R> | null> {
|
|
59
|
+
const toolchain = evidence.get(report);
|
|
60
|
+
if (!toolchain) return null;
|
|
61
|
+
return withCanonicalExclusionRoots(toolchain.exclusionRoots, async () => {
|
|
62
|
+
let authority;
|
|
63
|
+
try { authority = await openWindowsCliToolchainAuthority(toolchain.node, win32.dirname(win32.dirname(toolchain.npmCli)), true); }
|
|
64
|
+
catch (error) { if (error instanceof WindowsCliToolchainCleanupError) throw error; return null; }
|
|
65
|
+
let result: Awaited<R> | null = null;
|
|
66
|
+
try { const observed = await inspectWindowsInstallationFiles([
|
|
67
|
+
{ path: toolchain.node, maxBytes: 128 * 1024 * 1024, hashOnly: true },
|
|
68
|
+
{ path: toolchain.npmCli, maxBytes: 256 * 1024 },
|
|
69
|
+
], async files => {
|
|
70
|
+
if (id(files[0]!) !== toolchain.nodeEvidence || id(files[1]!) !== toolchain.npmEvidence) return false;
|
|
71
|
+
toolchainDigests.set(report, authority.digest);
|
|
72
|
+
result = await run(); return true;
|
|
73
|
+
});
|
|
74
|
+
return observed.kind === "observed" ? result : null;
|
|
75
|
+
} finally { if (!await authority.release()) throw new Error("toolchain_release_unverified"); }
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Transfer a held toolchain observation to a transaction, including unknown child lifetimes. */
|
|
80
|
+
export async function holdWindowsCodexCliPlanToolchain(report: CodexCliInstallReport) {
|
|
81
|
+
const toolchain = evidence.get(report);
|
|
82
|
+
if (!toolchain) return null;
|
|
83
|
+
let authority;
|
|
84
|
+
try { authority = await openWindowsCliToolchainAuthority(toolchain.node, win32.dirname(win32.dirname(toolchain.npmCli)), true); }
|
|
85
|
+
catch (error) { if (error instanceof WindowsCliToolchainCleanupError) throw error; return null; }
|
|
86
|
+
const admitted = Promise.withResolvers<boolean>();
|
|
87
|
+
const release = Promise.withResolvers<void>();
|
|
88
|
+
const observing = withCanonicalExclusionRoots(toolchain.exclusionRoots, () => inspectWindowsInstallationFiles([
|
|
89
|
+
{ path: toolchain.node, maxBytes: 128 * 1024 * 1024, hashOnly: true },
|
|
90
|
+
{ path: toolchain.npmCli, maxBytes: 256 * 1024 },
|
|
91
|
+
], async files => {
|
|
92
|
+
if (id(files[0]!) !== toolchain.nodeEvidence || id(files[1]!) !== toolchain.npmEvidence) return false;
|
|
93
|
+
admitted.resolve(true);
|
|
94
|
+
await release.promise;
|
|
95
|
+
return true;
|
|
96
|
+
}));
|
|
97
|
+
void observing.then(() => admitted.resolve(false), () => admitted.resolve(false));
|
|
98
|
+
if (!await admitted.promise) { await authority.release(); return null; }
|
|
99
|
+
return { async release() { release.resolve(); const observed = await observing;
|
|
100
|
+
return await authority.release() && observed?.kind === "observed"; } };
|
|
101
|
+
}
|
|
102
|
+
const json = (file: File): Record<string, unknown> | null => {
|
|
103
|
+
try { const item = JSON.parse(Buffer.from(file.bytes).toString("utf8"));
|
|
104
|
+
return item && typeof item === "object" && !Array.isArray(item) ? item : null;
|
|
105
|
+
} catch { return null; }
|
|
106
|
+
};
|
|
107
|
+
const entry = (item: Record<string, unknown>, name: string): unknown => typeof item.bin === "string" ? item.bin
|
|
108
|
+
: item.bin && typeof item.bin === "object" ? (item.bin as Record<string, unknown>)[name] : null;
|
|
109
|
+
function peArch(bytes: Uint8Array): "x64" | "arm64" | null {
|
|
110
|
+
const b = Buffer.from(bytes);
|
|
111
|
+
if (b.length < 64 || b.toString("ascii", 0, 2) !== "MZ") return null;
|
|
112
|
+
const offset = b.readUInt32LE(60);
|
|
113
|
+
if (offset > b.length - 6 || b.toString("ascii", offset, offset + 4) !== "PE\0\0") return null;
|
|
114
|
+
return b.readUInt16LE(offset + 4) === 0x8664 ? "x64" : b.readUInt16LE(offset + 4) === 0xaa64 ? "arm64" : null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Read-only supported subset: a proof-captured absolute standard npm cmd-shim
|
|
119
|
+
* override, its global-prefix package, a held-bound Node/npm toolchain, and the
|
|
120
|
+
* in-prefix optional backing. When the prefix has no node.exe, the toolchain is
|
|
121
|
+
* the npm pair the captured PATH resolves — the updater's own metadata vehicle,
|
|
122
|
+
* never a claim about which interpreter a later codex.cmd invocation resolves:
|
|
123
|
+
* the shim's bare `node` falls through to the ambient invocation working
|
|
124
|
+
* directory, which no launcher snapshot can prove. A separate toolchain
|
|
125
|
+
* therefore also requires the launcher arch anchor, keeping the backing lane
|
|
126
|
+
* tied to the selection instead of to an arbitrary PATH hit.
|
|
127
|
+
*/
|
|
128
|
+
export async function inspectWindowsCodexCliPlanInstall(
|
|
129
|
+
deps: CodexCliInstallProvenanceDeps, fallback: CodexCliInstallReport, excluded: (path: string) => boolean,
|
|
130
|
+
exclusionRoots: readonly string[] = [],
|
|
131
|
+
): Promise<CodexCliInstallReport> {
|
|
132
|
+
const env = deps.env ?? {};
|
|
133
|
+
const candidate = env.CODEX_CLI_PATH?.trim();
|
|
134
|
+
if (!deps.selectionAttested || !candidate || !/^[a-z]:[\\/]/i.test(candidate)
|
|
135
|
+
|| win32.basename(candidate) !== "codex.cmd"
|
|
136
|
+
|| (deps.selectedCommand != null && deps.selectedCommand !== candidate)) return fallback;
|
|
137
|
+
if (exclusionRoots.length) {
|
|
138
|
+
const roots = Object.freeze([...exclusionRoots]);
|
|
139
|
+
const report = await withCanonicalExclusionRoots(roots,
|
|
140
|
+
() => inspectWindowsCodexCliPlanInstall(deps, fallback, excluded));
|
|
141
|
+
if (report) {
|
|
142
|
+
const toolchain = evidence.get(report);
|
|
143
|
+
if (toolchain) evidence.set(report, Object.freeze({ ...toolchain, exclusionRoots: roots }));
|
|
144
|
+
}
|
|
145
|
+
return report ?? fallback;
|
|
146
|
+
}
|
|
147
|
+
// The bounded content read is opt-in: a bare ownership check holds the same
|
|
148
|
+
// reparse-refusing handles; only bounded ownership/header reads remain.
|
|
149
|
+
const observe = deps.observeInstallContent === true;
|
|
150
|
+
const prefix = win32.dirname(candidate);
|
|
151
|
+
const localNodePath = win32.join(prefix, "node.exe");
|
|
152
|
+
const localNode = await inspectWindowsInstallationFiles([{ path: localNodePath, maxBytes: 0, metadataOnly: true }]);
|
|
153
|
+
if (localNode.kind === "refused" && localNode.reason !== "not-found") return fallback;
|
|
154
|
+
const selectedPath = env.PATH;
|
|
155
|
+
const selectedPathExt = env.PATHEXT;
|
|
156
|
+
const derivation = await deriveCodexCliInstallationInput({
|
|
157
|
+
codexCliPath: candidate, path: selectedPath ?? null, pathExt: selectedPathExt ?? null,
|
|
158
|
+
}, { platform: "win32" });
|
|
159
|
+
if (derivation.kind !== "derived" || derivation.input.candidate !== candidate
|
|
160
|
+
|| derivation.input.npmPrefix !== prefix) return fallback;
|
|
161
|
+
const node = derivation.input.node;
|
|
162
|
+
const npmCli = derivation.input.npmCli;
|
|
163
|
+
const npmRoot = win32.dirname(win32.dirname(npmCli));
|
|
164
|
+
const pathNode = !sameWindowsPath(node, localNodePath);
|
|
165
|
+
// A prefix-local node.exe is provably the shim's own interpreter; a PATH-resolved
|
|
166
|
+
// separate toolchain is bound as the updater's metadata vehicle only. Without the
|
|
167
|
+
// launcher arch the toolchain's arch cannot be tied to the selection at all, so a
|
|
168
|
+
// separate toolchain stays refused rather than claim an unanchored backing lane.
|
|
169
|
+
if (pathNode && !deps.arch) return fallback;
|
|
170
|
+
const root = win32.join(prefix, "node_modules", "@openai", "codex");
|
|
171
|
+
const manifest = win32.join(root, "package.json");
|
|
172
|
+
const npmManifest = win32.join(npmRoot, "package.json");
|
|
173
|
+
const bin = win32.join(root, "bin", "codex.js");
|
|
174
|
+
const paths = [candidate, node, npmCli, root];
|
|
175
|
+
if (prefix === win32.parse(prefix).root || paths.some(excluded)) return fallback;
|
|
176
|
+
// Only already handle-observed files can pass the real resolver's existence
|
|
177
|
+
// predicate. The explicit override wins before saved-state/shim/PATH candidates.
|
|
178
|
+
const selected = () => selectedWindowsOverride(candidate, env, deps.configDir);
|
|
179
|
+
try {
|
|
180
|
+
const first = await inspectWindowsInstallationFiles([
|
|
181
|
+
{ path: manifest, maxBytes: 256 * 1024 }, { path: npmManifest, maxBytes: 256 * 1024 },
|
|
182
|
+
{ path: node, maxBytes: 4096, prefixOnly: true },
|
|
183
|
+
]);
|
|
184
|
+
if (first.kind !== "observed") return fallback;
|
|
185
|
+
const initial = new Map(first.files.map(file => [file.path, file]));
|
|
186
|
+
const main = json(initial.get(manifest)!); const npm = json(initial.get(npmManifest)!);
|
|
187
|
+
const arch = peArch(initial.get(node)!.bytes);
|
|
188
|
+
if (!main || main.name !== "@openai/codex" || typeof main.version !== "string" || !parseStrictSemver(main.version)
|
|
189
|
+
|| entry(main, "codex") !== "bin/codex.js" || !npm || npm.name !== "npm"
|
|
190
|
+
|| typeof npm.version !== "string" || !parseStrictSemver(npm.version) || entry(npm, "npm") !== "bin/npm-cli.js"
|
|
191
|
+
|| !arch || (deps.arch && deps.arch !== arch)) return fallback;
|
|
192
|
+
const pkg = `@openai/codex-win32-${arch}`;
|
|
193
|
+
const triple = arch === "x64" ? "x86_64-pc-windows-msvc" : "aarch64-pc-windows-msvc";
|
|
194
|
+
// Node's nearest-first package lookup, bounded to this independent prefix.
|
|
195
|
+
const lanes = [win32.join(root, "bin", "node_modules"), win32.join(root, "node_modules"),
|
|
196
|
+
win32.join(prefix, "node_modules", "@openai", "node_modules"), win32.join(prefix, "node_modules")];
|
|
197
|
+
const backingSelection = async (): Promise<string | null> => {
|
|
198
|
+
for (const lane of lanes) {
|
|
199
|
+
const path = win32.join(lane, pkg, "package.json");
|
|
200
|
+
const probe = await inspectWindowsInstallationFiles([{ path, maxBytes: 0, metadataOnly: true }]);
|
|
201
|
+
if (probe.kind === "observed") return path;
|
|
202
|
+
if (probe.reason !== "not-found") return null;
|
|
203
|
+
}
|
|
204
|
+
return null; // No global module lookup or vendor fallback adoption.
|
|
205
|
+
};
|
|
206
|
+
const backingManifest = await backingSelection();
|
|
207
|
+
if (!backingManifest) return fallback;
|
|
208
|
+
const native = win32.join(win32.dirname(backingManifest), "vendor", triple, "bin", "codex.exe");
|
|
209
|
+
// Ownership requires the manifests, shim and backing manifest bytes plus the
|
|
210
|
+
// bounded Node header read above; entrypoint, npm CLI, Node and native
|
|
211
|
+
// contents only feed the opt-in digest, so they stay metadata-held without it.
|
|
212
|
+
const owned = (path: string) => ({ path, maxBytes: 256 * 1024 });
|
|
213
|
+
const bound = (path: string) => observe ? { path, maxBytes: 256 * 1024 } : { path, maxBytes: 0, metadataOnly: true };
|
|
214
|
+
const requests = [owned(manifest), owned(npmManifest), owned(candidate), bound(bin), bound(npmCli), owned(backingManifest)];
|
|
215
|
+
const final = await inspectWindowsInstallationFiles([...requests,
|
|
216
|
+
observe
|
|
217
|
+
? { path: node, maxBytes: 128 * 1024 * 1024, hashOnly: true }
|
|
218
|
+
: { path: node, maxBytes: 0, metadataOnly: true },
|
|
219
|
+
observe
|
|
220
|
+
? { path: native, maxBytes: MAX_NATIVE_BACKING_BYTES, hashOnly: true }
|
|
221
|
+
: { path: native, maxBytes: 0, metadataOnly: true },
|
|
222
|
+
], async () => selected() && env.PATH === selectedPath && env.PATHEXT === selectedPathExt
|
|
223
|
+
&& await deriveCodexCliInstallationInput({ codexCliPath: candidate,
|
|
224
|
+
path: selectedPath ?? null, pathExt: selectedPathExt ?? null }, { platform: "win32" })
|
|
225
|
+
.then(current => current.kind === "derived" && current.input.candidate === candidate
|
|
226
|
+
&& current.input.npmPrefix === prefix && current.input.node === node && current.input.npmCli === npmCli)
|
|
227
|
+
&& await backingSelection() === backingManifest);
|
|
228
|
+
if (final.kind !== "observed") return fallback;
|
|
229
|
+
const files = new Map(final.files.map(file => [file.path, file]));
|
|
230
|
+
if (!npmCodexCommandShim(files.get(candidate)!.bytes)) return fallback;
|
|
231
|
+
for (const path of [manifest, npmManifest]) if (id(initial.get(path)!) !== id(files.get(path)!)) return fallback;
|
|
232
|
+
if (JSON.stringify(initial.get(node)!.identity) !== JSON.stringify(files.get(node)!.identity)) return fallback;
|
|
233
|
+
const backing = json(files.get(backingManifest)!);
|
|
234
|
+
if (!backing || "exports" in backing || ![pkg, "@openai/codex"].includes(String(backing.name))
|
|
235
|
+
|| ![main.version, `${main.version}-win32-${arch}`].includes(String(backing.version))) return fallback;
|
|
236
|
+
const content = observe ? hash(JSON.stringify(["windows-npm-read-only-plan-v3", arch, prefix, candidate, node, npmCli,
|
|
237
|
+
...final.files.map(file => [file.path, file.identity, file.digest])])) : null;
|
|
238
|
+
const report: CodexCliInstallReport = Object.freeze({ ...fallback, managed: true, selectionAttested: true,
|
|
239
|
+
provenance: "npm-global", reason: "managed_npm_global", packageVersion: main.version,
|
|
240
|
+
versionEvidence: Object.freeze({ kind: "package-manifest" }), installDigest: hash(prefix),
|
|
241
|
+
installContentDigest: content, shim: Object.freeze({ status: "not-tracked", backingKind: null }),
|
|
242
|
+
evidence: Object.freeze(["package_manifest", "package_manifest_digest",
|
|
243
|
+
...(content ? ["install_content_digest" as const] : []), "global_npm_layout"] as const),
|
|
244
|
+
});
|
|
245
|
+
evidence.set(report, Object.freeze({ node, npmCli, arch, prefix, launcher: candidate,
|
|
246
|
+
envPath: selectedPath, envPathExt: selectedPathExt,
|
|
247
|
+
backingRoot: win32.dirname(backingManifest), nodeEvidence: id(files.get(node)!), npmEvidence: id(files.get(npmCli)!), exclusionRoots: Object.freeze([]) }));
|
|
248
|
+
return report;
|
|
249
|
+
} catch { return fallback; }
|
|
250
|
+
}
|
|
@@ -41,6 +41,7 @@ import { darwinDesktopAppAdapter, darwinDefaultExec } from "./desktop-app/darwin
|
|
|
41
41
|
import { linuxDesktopAppAdapter, linuxDefaultExec } from "./desktop-app/linux";
|
|
42
42
|
import { windowsDesktopAppAdapter, windowsDefaultExec } from "./desktop-app/windows";
|
|
43
43
|
import { isTestHomeGuardArmed } from "../lib/test-home-guard";
|
|
44
|
+
import { beginCodexCliSelectionParentWrite } from "./cli-update-selection-gate";
|
|
44
45
|
|
|
45
46
|
export type { DesktopAppExecOptions } from "./desktop-app/types";
|
|
46
47
|
|
|
@@ -90,6 +91,7 @@ export type DesktopAppRestartReason =
|
|
|
90
91
|
| "restart_in_flight"
|
|
91
92
|
| "handoff_started"
|
|
92
93
|
| "relaunch_context_failed"
|
|
94
|
+
| "selection_mutation_busy"
|
|
93
95
|
| "targets_survived"
|
|
94
96
|
| "relaunch_failed";
|
|
95
97
|
|
|
@@ -248,11 +250,27 @@ export function restartCodexDesktopApp(io: DesktopAppRestartIo = {}): DesktopApp
|
|
|
248
250
|
// first quits and relaunches, the second sees the freshly started shell as a target
|
|
249
251
|
// and kills it. Own-pid reentrancy means the wp5 helper runs this same step and
|
|
250
252
|
// finds the lock its caller made out to it.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
+
// A cli-update worker holds this gate from its final process scan through
|
|
254
|
+
// installer termination and readback, so no new shell may appear inside. The
|
|
255
|
+
// admission check runs BEFORE the restart lock and every mutation this
|
|
256
|
+
// function performs: a busy refusal must leave the app, the lock and any
|
|
257
|
+
// handoff all untouched. Held through relaunch or a failed attempt's
|
|
258
|
+
// cleanup; a handoff helper's own delayed descendants stay the documented
|
|
259
|
+
// pre-existing residual.
|
|
260
|
+
const selectionWrite = beginCodexCliSelectionParentWrite();
|
|
261
|
+
if (!selectionWrite.entered) return skipped("selection_mutation_busy");
|
|
253
262
|
|
|
254
263
|
let handedOff = false;
|
|
264
|
+
// The lock attempt sits inside the protected scope too: a throw from the
|
|
265
|
+
// lock's own mkdir/write before the try would otherwise leak this
|
|
266
|
+
// process-wide gate for the rest of the process. lockHeld distinguishes
|
|
267
|
+
// "acquisition threw/refused" from "lock taken" so a failed attempt never
|
|
268
|
+
// releases a lock this call does not hold.
|
|
269
|
+
let lockHeld = false;
|
|
255
270
|
try {
|
|
271
|
+
const acquisition = acquireDesktopRestartLock(io.lock);
|
|
272
|
+
if (!acquisition.acquired) return skipped("restart_in_flight");
|
|
273
|
+
lockHeld = true;
|
|
256
274
|
const install = adapter.discover(exec);
|
|
257
275
|
if (!install) return skipped("package_discovery_failed");
|
|
258
276
|
|
|
@@ -366,6 +384,7 @@ export function restartCodexDesktopApp(io: DesktopAppRestartIo = {}): DesktopApp
|
|
|
366
384
|
} finally {
|
|
367
385
|
// On the handoff path ownership was transferred to the helper, so releasing here
|
|
368
386
|
// would drop a lock that is still protecting a restart about to happen.
|
|
369
|
-
|
|
387
|
+
selectionWrite.exit();
|
|
388
|
+
if (lockHeld && !handedOff) releaseDesktopRestartLock(io.lock);
|
|
370
389
|
}
|
|
371
390
|
}
|