@bitkyc08/opencodex 2.100.5 → 2.100.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/ocx.mjs +2 -0
- package/gui/dist/assets/App-BI8LQ7Qk.css +1 -0
- package/gui/dist/assets/App-CsZ1Gr7S.js +60 -0
- package/gui/dist/assets/Tray-CVqm4S4W.js +1 -0
- package/gui/dist/assets/brand-mark-BebhnAtV.js +1 -0
- package/gui/dist/assets/index-BtwVlpeQ.css +2 -0
- package/gui/dist/assets/index-CEeMegqE.js +138 -0
- package/gui/dist/assets/{segment-thumb-features-Bquysdn5.js → segment-thumb-features-COdzmORE.js} +1 -1
- package/gui/dist/classic/assets/App-BJgUWNJ8.js +59 -0
- package/gui/dist/classic/assets/App-CoiVLRW3.css +1 -0
- package/gui/dist/classic/assets/Tray-BDlcOLDK.js +1 -0
- package/gui/dist/classic/assets/index-B9Jgli_W.js +138 -0
- package/gui/dist/classic/assets/usage-companion-chart-vbzDcND0.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/Cargo.lock +62 -0
- package/native/ocx-child/Cargo.toml +1 -0
- package/native/ocx-child/src/journal.rs +32 -10
- package/native/ocx-child/src/state.rs +2 -1
- package/native/ocx-child/src/toml_surgeon.rs +183 -72
- package/package.json +2 -2
- package/src/adapters/agy-acp/acp.ts +202 -0
- package/src/adapters/agy-acp/adapter.ts +554 -0
- package/src/adapters/agy-acp/binary.ts +79 -0
- package/src/adapters/agy-acp/options.ts +163 -0
- package/src/adapters/agy-acp/output-redaction.ts +270 -0
- package/src/adapters/agy-acp/policy.ts +105 -0
- package/src/adapters/agy-acp/process.ts +218 -0
- package/src/adapters/anthropic/account-metadata.ts +4 -1
- package/src/adapters/anthropic/advisor-tool.ts +43 -9
- package/src/adapters/anthropic/client-identity.ts +2 -0
- package/src/adapters/anthropic.ts +102 -14
- package/src/adapters/antigravity-refusal.ts +5 -1
- package/src/adapters/base.ts +25 -2
- package/src/adapters/claude-cli/adapter.ts +1 -0
- package/src/adapters/claude-cli/usage-admission.ts +12 -9
- package/src/adapters/codebuddy/adapter.ts +1 -0
- package/src/adapters/command-code.ts +2 -2
- package/src/adapters/cursor/http1-bidi.ts +7 -2
- package/src/adapters/cursor/live-transport.ts +2 -0
- package/src/adapters/cursor/request-builder.ts +4 -4
- package/src/adapters/cursor/tool-naming.ts +5 -5
- package/src/adapters/cursor/transport-retry.ts +14 -8
- package/src/adapters/cursor/transport.ts +2 -0
- package/src/adapters/cursor.ts +8 -2
- package/src/adapters/google-error-details.ts +105 -0
- package/src/adapters/google-errors.ts +183 -31
- package/src/adapters/google-http.ts +66 -22
- package/src/adapters/google-truncation.ts +48 -3
- package/src/adapters/google-vertex-endpoint.ts +12 -1
- package/src/adapters/google.ts +54 -26
- package/src/adapters/kiro/adapter.ts +39 -38
- package/src/adapters/kiro/stream.ts +59 -9
- package/src/adapters/kiro-retry.ts +5 -3
- package/src/adapters/m365-copilot/LICENSE +21 -0
- package/src/adapters/m365-copilot/fenced.ts +745 -0
- package/src/adapters/m365-copilot/images.ts +89 -0
- package/src/adapters/m365-copilot/tools.ts +284 -0
- package/src/adapters/m365-copilot/transport.ts +232 -0
- package/src/adapters/m365-copilot.ts +143 -0
- package/src/adapters/openai-chat/tool-schema.ts +2 -2
- package/src/adapters/openai-responses/passthrough.ts +1 -0
- package/src/adapters/openai-responses/reasoning.ts +23 -3
- package/src/adapters/physical-send.ts +11 -4
- package/src/adapters/qoder/adapter.ts +17 -3
- package/src/adapters/registry.ts +15 -1
- package/src/adapters/zed.ts +2 -1
- package/src/advisor/consult.ts +1 -0
- package/src/bridge/response-json.ts +6 -2
- package/src/bridge/sse.ts +21 -9
- package/src/chat/inbound.ts +11 -8
- package/src/chat/outbound.ts +28 -7
- package/src/claude/context-windows.ts +32 -8
- package/src/claude/desktop-3p.ts +18 -14
- package/src/claude/desktop-picker-platform.ts +1 -1
- package/src/claude/desktop-picker.ts +3 -3
- package/src/claude/inbound-content-options.ts +11 -1
- package/src/claude/intercept/picker-ca-cleanup.ts +17 -5
- package/src/claude/intercept/picker-ca.ts +162 -27
- package/src/claude/intercept/picker-trust-linux.ts +411 -0
- package/src/claude/intercept/picker-trust.ts +35 -3
- package/src/claude/intercept/runtime.ts +2 -2
- package/src/claude/subagent-force-status.ts +24 -5
- package/src/claude/subscription-reserve.ts +87 -0
- package/src/cli/account-api.ts +3 -0
- package/src/cli/account-auth.ts +65 -11
- package/src/cli/account-extended.ts +1 -1
- package/src/cli/account-next-actions.ts +4 -1
- package/src/cli/account-policy-dto.ts +1 -1
- package/src/cli/account-policy.ts +6 -3
- package/src/cli/account-probe.ts +66 -0
- package/src/cli/account.ts +8 -2
- package/src/cli/capabilities-accounts.ts +8 -1
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-base.ts +4 -4
- package/src/cli/capabilities-integrations.ts +44 -4
- package/src/cli/capabilities-provider-models.ts +6 -0
- package/src/cli/claude-context-settings.ts +60 -0
- package/src/cli/claude-desktop.ts +2 -2
- package/src/cli/claude.ts +15 -7
- package/src/cli/client-start-fence.ts +64 -1
- package/src/cli/combo-result.ts +1 -0
- package/src/cli/combo-stats.ts +1 -1
- package/src/cli/combo.ts +19 -2
- package/src/cli/config-command.ts +21 -8
- package/src/cli/connect.ts +16 -0
- package/src/cli/cross-home-owner.ts +65 -18
- package/src/cli/dispatch.ts +4 -0
- package/src/cli/gateway-client-command.ts +128 -0
- package/src/cli/index.ts +98 -97
- package/src/cli/init.ts +20 -4
- package/src/cli/integrations.ts +23 -3
- package/src/cli/launcher-context.ts +12 -1
- package/src/cli/link.ts +24 -5
- package/src/cli/models-runtime-subcommands.ts +1 -0
- package/src/cli/models-runtime.ts +32 -0
- package/src/cli/start-owner-fence.ts +5 -2
- package/src/cli/status.ts +3 -3
- package/src/cli/stop-client-process.ts +51 -0
- package/src/cli/stop-restore.ts +383 -36
- package/src/cli/sync-command.ts +2 -2
- package/src/cli/uninstall-client-state.ts +7 -0
- package/src/client/connect.ts +72 -13
- package/src/client/hub-client.ts +38 -0
- package/src/client/hub-relay.ts +61 -36
- package/src/client/hub-session.ts +106 -0
- package/src/client/lifecycle-lock.ts +6 -1
- package/src/client/link-relay.ts +2 -1
- package/src/client/machine-listener.ts +60 -1
- package/src/client/runtime-restart.ts +1 -0
- package/src/client/runtime.ts +104 -34
- package/src/client/state.ts +11 -0
- package/src/client/stop-darwin-process.ts +73 -0
- package/src/client/stop-file-routing.ts +49 -0
- package/src/client/stop-native-handoff.ts +108 -0
- package/src/client/stop-routing.ts +41 -7
- package/src/client/stop-teardown-owner.ts +173 -0
- package/src/client/sync-runtime.ts +23 -4
- package/src/clients/config-export/opencode-wire.ts +24 -0
- package/src/clients/config-export.ts +28 -19
- package/src/codex/auth-api/login-flow.ts +68 -33
- package/src/codex/auth-api/main-account-probe.ts +3 -3
- package/src/codex/auth-api/pool-quota-probe.ts +8 -7
- package/src/codex/auth-api/routes.ts +1 -1
- package/src/codex/catalog/aggregation.ts +22 -10
- package/src/codex/catalog/gather-capture.ts +11 -2
- package/src/codex/catalog/m365-copilot-models.ts +52 -0
- package/src/codex/catalog/provider-models.ts +126 -53
- package/src/codex/catalog/routed-gather.ts +26 -12
- package/src/codex/catalog-admission.ts +4 -6
- package/src/codex/catalog-auto-refresh.ts +4 -2
- package/src/codex/catalog-self-heal.ts +4 -2
- package/src/codex/control-plane-models.ts +6 -0
- package/src/codex/convergence.ts +10 -0
- package/src/codex/desktop-app/picker-freshness.ts +3 -14
- package/src/codex/desktop-app/types.ts +6 -0
- package/src/codex/desktop-app/windows-command-payload.ts +9 -0
- package/src/codex/desktop-app/windows.ts +20 -12
- package/src/codex/desktop-compatibility/installed-build.ts +61 -58
- package/src/codex/desktop-compatibility/runtime-ownership.ts +11 -5
- package/src/codex/desktop-compatibility/runtime.ts +51 -14
- package/src/codex/desktop-compatibility/windows-activation-source.ts +28 -13
- package/src/codex/desktop-compatibility/windows-package-command.ts +73 -33
- package/src/codex/desktop-compatibility/windows-package-launch.ts +41 -9
- package/src/codex/desktop-compatibility/windows-package-proof.ts +104 -0
- package/src/codex/inject/config-toml.ts +67 -73
- package/src/codex/inject/plan.ts +11 -10
- package/src/codex/inject/remove.ts +4 -1
- package/src/codex/inject.ts +1 -0
- package/src/codex/journal-config-restore.ts +31 -4
- package/src/codex/journal.ts +16 -4
- package/src/codex/model-cache.ts +98 -27
- package/src/codex/native-residue.ts +14 -13
- package/src/codex/paths.ts +65 -28
- package/src/codex/quota-observation-freshness.ts +4 -0
- package/src/codex/quota.ts +71 -8
- package/src/codex/routing/selection.ts +32 -8
- package/src/combos/capability-policy.ts +31 -0
- package/src/combos/failover.ts +82 -74
- package/src/combos/identifiers.ts +2 -2
- package/src/combos/index.ts +3 -0
- package/src/combos/jev-model-backend.ts +12 -4
- package/src/combos/jev-session-pin-config.ts +22 -9
- package/src/combos/jev.ts +15 -4
- package/src/combos/request-capability.ts +214 -0
- package/src/combos/request.ts +22 -15
- package/src/combos/resolve.ts +5 -2
- package/src/combos/suggestion-channel.ts +89 -0
- package/src/combos/types.ts +14 -1
- package/src/config/account-auto-pause-revisions.ts +33 -10
- package/src/config/atomic-write.ts +1 -1
- package/src/config/codex-ws-incremental-setting.ts +34 -0
- package/src/config/diagnostics.ts +47 -8
- package/src/config/live-topology.ts +4 -2
- package/src/config/load-degrade.ts +96 -2
- package/src/config/mutation-lock.ts +7 -3
- package/src/config/paths.ts +3 -0
- package/src/config/pending-teardown.ts +19 -3
- package/src/config/process-state.ts +30 -12
- package/src/config/provider-validation.ts +10 -0
- package/src/config/salvage.ts +2 -2
- package/src/config/schema/account-auto-pause.ts +15 -1
- package/src/config/schema/agy-acp-references.ts +257 -0
- package/src/config/schema/config-schema.ts +32 -0
- package/src/config/schema/leaf-validators.ts +42 -0
- package/src/config/schema/subscription-reserve.ts +33 -0
- package/src/config/windows-process-command-line.ts +27 -9
- package/src/config.ts +6 -0
- package/src/generated/compatibility-version.json +806 -402
- package/src/images/loop.ts +79 -39
- package/src/integrations/catalog-refresh.ts +19 -1
- package/src/integrations/gateway-clients/agy.ts +340 -0
- package/src/integrations/gateway-clients/antigravity.ts +224 -0
- package/src/integrations/gateway-clients/index.ts +89 -0
- package/src/integrations/gateway-clients/io.ts +278 -0
- package/src/integrations/gateway-clients/types.ts +80 -0
- package/src/integrations/route-intent-disconnect.ts +37 -21
- package/src/lib/app-owned-memory-stores.ts +9 -0
- package/src/lib/cloud-code-appeal-link.ts +30 -0
- package/src/lib/errors.ts +32 -0
- package/src/lib/executor-physical-send-receipt.ts +42 -0
- package/src/lib/failure-detail.ts +1 -0
- package/src/lib/gcp-adc.ts +5 -0
- package/src/lib/http-date.ts +91 -0
- package/src/lib/lab-passive-linker-registration.ts +2 -1
- package/src/lib/local-chat-completion.ts +13 -3
- package/src/lib/local-internal-call-capability.ts +1 -3
- package/src/lib/messages-error-body.ts +2 -1
- package/src/lib/outbound-credential-registry.ts +40 -4
- package/src/lib/pinned-http.ts +7 -2
- package/src/lib/process-control.ts +1 -0
- package/src/lib/provider-egress.ts +16 -0
- package/src/lib/provider-outbound.ts +3 -0
- package/src/lib/redact-folding.ts +12 -3
- package/src/lib/redact.ts +37 -19
- package/src/lib/request-execution-budget.ts +241 -32
- package/src/lib/request-peer-scope.ts +64 -0
- package/src/lib/response-send-readings.ts +41 -0
- package/src/lib/state-store-registrations.ts +5 -0
- package/src/lib/tool-envelope-echo-filter.ts +33 -5
- package/src/lib/upstream-condition.ts +10 -3
- package/src/lib/upstream-retry.ts +95 -20
- package/src/lib/windows-secret-acl.ts +24 -7
- package/src/link/child-activity.ts +60 -4
- package/src/link/codex-settings.ts +2 -1
- package/src/link/relay-auth.ts +1 -0
- package/src/link/route-rounds.ts +32 -9
- package/src/link/status-projection.ts +42 -5
- package/src/link/supervisor.ts +96 -11
- package/src/link/tunnel-history.ts +5 -0
- package/src/oauth/account-auto-pause-policy.ts +72 -19
- package/src/oauth/account-auto-pause.ts +40 -16
- package/src/oauth/anthropic-account-refusal.ts +7 -0
- package/src/oauth/anthropic-continuity.ts +70 -9
- package/src/oauth/anthropic-identity.ts +75 -11
- package/src/oauth/anthropic-login-slot.ts +258 -0
- package/src/oauth/anthropic-routing.ts +24 -9
- package/src/oauth/anthropic-send-ownership.ts +4 -3
- package/src/oauth/anthropic.ts +30 -11
- package/src/oauth/health.ts +7 -2
- package/src/oauth/index.ts +50 -48
- package/src/oauth/key-providers.ts +2 -0
- package/src/oauth/login-cli.ts +11 -0
- package/src/oauth/login-flow-state.ts +10 -4
- package/src/oauth/m365-copilot-browser.ts +222 -0
- package/src/oauth/m365-copilot-web-session.ts +25 -0
- package/src/oauth/m365-copilot.ts +57 -0
- package/src/oauth/model-discovery-auth.ts +5 -0
- package/src/oauth/plan.ts +44 -0
- package/src/oauth/pool-kernel.ts +22 -8
- package/src/oauth/pool-settings-capability.ts +14 -3
- package/src/oauth/reauth-precheck.ts +27 -0
- package/src/oauth/store-anthropic-instance.ts +3 -1
- package/src/oauth/store.ts +121 -23
- package/src/oauth/types.ts +27 -2
- package/src/protocols/codecs/chat-ir.ts +7 -4
- package/src/protocols/codecs/gemini-interactions.ts +770 -0
- package/src/protocols/codecs/gemini.ts +470 -0
- package/src/protocols/contract.ts +2 -0
- package/src/protocols/encoders/adapter-events.ts +5 -3
- package/src/protocols/encoders/chat.ts +23 -7
- package/src/protocols/settings.ts +3 -0
- package/src/providers/account-quota-disk.ts +26 -8
- package/src/providers/api-key-pause.ts +2 -2
- package/src/providers/api-key-response-ownership.ts +14 -4
- package/src/providers/claude-cli-usage-state.ts +1 -0
- package/src/providers/claude-cli-usage.ts +24 -7
- package/src/providers/default-aliases.ts +11 -5
- package/src/providers/derive.ts +5 -1
- package/src/providers/fastwire.ts +6 -5
- package/src/providers/free-directory.ts +2 -2
- package/src/providers/google-vertex-location.ts +2 -1
- package/src/providers/google-vertex-model-discovery.ts +22 -0
- package/src/providers/key-failover.ts +18 -23
- package/src/providers/m365-copilot-discovery-fetch.ts +17 -0
- package/src/providers/m365-copilot-discovery.ts +68 -0
- package/src/providers/m365-copilot-models.ts +32 -0
- package/src/providers/model-rename-fields.ts +6 -0
- package/src/providers/new-model-policy-runtime.ts +27 -6
- package/src/providers/openai-forward-destination.ts +19 -0
- package/src/providers/openai-tiers-destination.ts +3 -19
- package/src/providers/quota/account-cache.ts +183 -27
- package/src/providers/quota/anthropic-account-quota.ts +21 -17
- package/src/providers/quota/anthropic-cooldown-recovery.ts +57 -27
- package/src/providers/quota/anthropic-decision-windows.ts +7 -3
- package/src/providers/quota/anthropic-usage-windows.ts +34 -4
- package/src/providers/quota/antigravity-account-probe.ts +165 -0
- package/src/providers/quota/antigravity.ts +71 -3
- package/src/providers/quota/vendor-probes-oauth.ts +52 -28
- package/src/providers/quota-decision-publication.ts +1 -1
- package/src/providers/quota-decision-snapshot.ts +4 -1
- package/src/providers/quota-types.ts +2 -0
- package/src/providers/quota.ts +8 -7
- package/src/providers/registry/agy-acp-models.ts +3 -0
- package/src/providers/registry/entries-core.ts +9 -0
- package/src/providers/registry/entries-extended.ts +60 -0
- package/src/providers/registry/model-seeds.ts +51 -0
- package/src/providers/request-pacing.ts +37 -7
- package/src/providers/service-tier.ts +2 -0
- package/src/providers/xai-privacy-mode.ts +52 -0
- package/src/remote/hub-management-relay.ts +74 -0
- package/src/responses/id-limits.ts +2 -0
- package/src/responses/input-media.ts +15 -3
- package/src/responses/parser-tools.ts +74 -11
- package/src/responses/parser.ts +16 -14
- package/src/responses/provider-opaque-metadata.ts +10 -0
- package/src/responses/reasoning-envelope.ts +3 -0
- package/src/responses/schema.ts +2 -3
- package/src/responses/spill-store.ts +5 -3
- package/src/responses/state/connection-scope.ts +232 -0
- package/src/responses/state/entry-types.ts +47 -0
- package/src/responses/state/snapshot-codec.ts +75 -14
- package/src/responses/state/snapshot-select.ts +2 -0
- package/src/responses/state/spill-codec.ts +59 -0
- package/src/responses/state/spill-queue.ts +11 -2
- package/src/responses/state.ts +178 -159
- package/src/router.ts +2 -6
- package/src/routing/compatibility/behavior.ts +6 -2
- package/src/routing/compatibility/subject.ts +17 -12
- package/src/routing/machine-weighted-routing.ts +58 -0
- package/src/server/advisor-admission-scope.ts +15 -7
- package/src/server/auth-cors.ts +27 -0
- package/src/server/chat-completions.ts +37 -17
- package/src/server/chat-native-eligibility.ts +21 -0
- package/src/server/chat-native.ts +15 -6
- package/src/server/claude-messages.ts +54 -6
- package/src/server/credential-recovery-attempt.ts +32 -0
- package/src/server/effort-policy.ts +6 -3
- package/src/server/gemini-inbound.ts +267 -0
- package/src/server/gemini-interactions-inbound.ts +229 -0
- package/src/server/gemini-interactions-store.ts +129 -0
- package/src/server/gemini-native-catalog.ts +64 -0
- package/src/server/gemini-native-log.ts +33 -0
- package/src/server/gemini-native-paths.ts +88 -0
- package/src/server/gemini-native-wire.ts +201 -0
- package/src/server/gemini-native.ts +218 -0
- package/src/server/grok-upstream-envelope-echo.ts +8 -2
- package/src/server/hub-relay-auth.ts +87 -0
- package/src/server/hub-usage-windows.ts +135 -0
- package/src/server/hub-usage.ts +16 -3
- package/src/server/inbound-body-admission.ts +2 -1
- package/src/server/index/anthropic-model-listing.ts +75 -0
- package/src/server/index/gemini-routes.ts +147 -0
- package/src/server/index/link-management.ts +3 -22
- package/src/server/index/link-relay-sessions.ts +71 -13
- package/src/server/index/link-websocket.ts +2 -0
- package/src/server/index/passive-management-read.ts +55 -0
- package/src/server/index/serve-options.ts +93 -107
- package/src/server/index/websocket-handler.ts +15 -2
- package/src/server/index.ts +10 -0
- package/src/server/inference/client-encoder-delivery.ts +2 -1
- package/src/server/inference/context.ts +33 -6
- package/src/server/management/agent-settings-routes.ts +33 -16
- package/src/server/management/claude-code-settings-patch.ts +6 -0
- package/src/server/management/combo-routes.ts +21 -1
- package/src/server/management/combo-suggestion-routes.ts +212 -0
- package/src/server/management/config-routes.ts +12 -4
- package/src/server/management/context.ts +2 -0
- package/src/server/management/gateway-client-routes.ts +62 -0
- package/src/server/management/integration-routes.ts +5 -0
- package/src/server/management/link-routes.ts +5 -1
- package/src/server/management/m365-copilot-provider-probe.ts +23 -0
- package/src/server/management/model-routes.ts +32 -2
- package/src/server/management/model-rows.ts +36 -3
- package/src/server/management/oauth-account-routes.ts +68 -15
- package/src/server/management/protocol-settings-patch.ts +1 -0
- package/src/server/management/provider-omitted-fields.ts +25 -0
- package/src/server/management/provider-overwrite-carry.ts +33 -8
- package/src/server/management/provider-routes.ts +10 -16
- package/src/server/management/request-history-routes.ts +2 -2
- package/src/server/management/route-registry.ts +10 -0
- package/src/server/management/shared.ts +118 -30
- package/src/server/management/sibling-guard.ts +2 -1
- package/src/server/management/system-routes.ts +6 -0
- package/src/server/management-auth.ts +8 -1
- package/src/server/messages-native-scope.ts +19 -0
- package/src/server/messages-native.ts +156 -59
- package/src/server/messages-shared.ts +6 -0
- package/src/server/models-capabilities.ts +24 -0
- package/src/server/native-chat-bridge.ts +259 -0
- package/src/server/ollama-inbound.ts +36 -184
- package/src/server/passive-route-linker.ts +3 -1
- package/src/server/port-reclaim.ts +48 -4
- package/src/server/proxy-liveness.ts +79 -22
- package/src/server/relay.ts +16 -9
- package/src/server/request-log-account-rotation.ts +2 -1
- package/src/server/request-log-attempt-recovery.ts +24 -2
- package/src/server/request-log-attempt-usage.ts +5 -4
- package/src/server/request-log-committed-terminal.ts +87 -0
- package/src/server/request-log-failure-attribution.ts +3 -3
- package/src/server/request-log-failure-detail.ts +34 -0
- package/src/server/request-log-key-failure.ts +27 -0
- package/src/server/request-log-terminal-status.ts +25 -12
- package/src/server/request-log.ts +59 -63
- package/src/server/responses/adapter-continuation.ts +77 -44
- package/src/server/responses/adapter-delivery.ts +47 -22
- package/src/server/responses/adapter-dispatch.ts +150 -149
- package/src/server/responses/advisor-retention.ts +12 -4
- package/src/server/responses/advisor-slot.ts +97 -2
- package/src/server/responses/agent-task-recovery.ts +44 -11
- package/src/server/responses/agy-acp-preflight.ts +41 -0
- package/src/server/responses/anthropic-image-context.ts +44 -0
- package/src/server/responses/antigravity-validation-refusal.ts +25 -1
- package/src/server/responses/buffered-sse-json.ts +18 -1
- package/src/server/responses/codex-ws-correlation.ts +5 -2
- package/src/server/responses/codex-ws-exchange.ts +91 -8
- package/src/server/responses/codex-ws-incremental.ts +136 -0
- package/src/server/responses/codex-ws-pool.ts +22 -8
- package/src/server/responses/codex-ws-request.ts +5 -0
- package/src/server/responses/codex-ws-send-accounting.ts +8 -0
- package/src/server/responses/codex-ws-session.ts +14 -0
- package/src/server/responses/codex-ws-wire.ts +44 -22
- package/src/server/responses/combo-admission-snapshot.ts +93 -0
- package/src/server/responses/combo-required-tool-stream.ts +16 -4
- package/src/server/responses/combo-selection-keepalive.ts +5 -0
- package/src/server/responses/combo-stream-preflight.ts +182 -73
- package/src/server/responses/compact-response-body.ts +27 -0
- package/src/server/responses/compact.ts +174 -121
- package/src/server/responses/compaction-recovery.ts +7 -0
- package/src/server/responses/core-codex-account.ts +88 -62
- package/src/server/responses/core-combo-failure.ts +15 -0
- package/src/server/responses/core-combo-native.ts +12 -1
- package/src/server/responses/core-combo.ts +340 -94
- package/src/server/responses/core-normalize.ts +19 -12
- package/src/server/responses/core-opaque-recovery.ts +15 -4
- package/src/server/responses/core-options.ts +50 -5
- package/src/server/responses/core-pipeline.ts +11 -0
- package/src/server/responses/core.ts +7 -1
- package/src/server/responses/empty-completion-guard.ts +21 -7
- package/src/server/responses/estimated-usage.ts +2 -1
- package/src/server/responses/fetch-helpers.ts +95 -19
- package/src/server/responses/history-slim.ts +204 -0
- package/src/server/responses/hosted-advisor-spend.ts +49 -0
- package/src/server/responses/image-context-recovery.ts +199 -0
- package/src/server/responses/input-admission.ts +36 -11
- package/src/server/responses/jev-model-invoke.ts +23 -16
- package/src/server/responses/non-replayable-error.ts +12 -2
- package/src/server/responses/passthrough-build-error.ts +5 -3
- package/src/server/responses/passthrough-delivery.ts +74 -33
- package/src/server/responses/passthrough-dispatch.ts +170 -197
- package/src/server/responses/policy-fallback.ts +7 -2
- package/src/server/responses/policy-request-scope.ts +36 -2
- package/src/server/responses/replay-owner.ts +20 -0
- package/src/server/responses/request-prepare.ts +97 -16
- package/src/server/responses/request-send-budget.ts +97 -25
- package/src/server/responses/request-sidecar-auth.ts +138 -65
- package/src/server/responses/request-spend-target.ts +13 -1
- package/src/server/responses/request-spend.ts +228 -47
- package/src/server/responses/request-transport.ts +395 -70
- package/src/server/responses/run-turn-execution.ts +40 -9
- package/src/server/responses/sidecar-execution.ts +214 -67
- package/src/server/responses/sidecar-send-budget.ts +9 -9
- package/src/server/responses/terminal-guard.ts +35 -9
- package/src/server/responses/ws-upstream.ts +27 -6
- package/src/server/responses-phase-inference.ts +32 -9
- package/src/server/responses-terminal-repair.ts +14 -35
- package/src/server/system-env.ts +8 -5
- package/src/server/ws-bridge.ts +23 -17
- package/src/service/health-sentinel-linux.ts +16 -7
- package/src/service/systemd.ts +11 -2
- package/src/service/windows-checked-stop-live.ts +60 -55
- package/src/service/windows-checked-stop.ts +29 -11
- package/src/service/windows-guarded-manager.ts +14 -26
- package/src/service/windows-process-evidence.ts +82 -74
- package/src/service/windows-process-native.ts +69 -20
- package/src/service/windows-service-stop.ts +14 -12
- package/src/service/windows-stop-binding.ts +14 -5
- package/src/service/windows-stop-confirm.ts +1 -1
- package/src/service/windows-task-instance-stop.ts +98 -0
- package/src/service/windows-taskxml.ts +30 -7
- package/src/sidecar/anthropic-binding.ts +1 -1
- package/src/stall-timeout.ts +30 -0
- package/src/telemetry/aggregate.ts +6 -3
- package/src/types/account-auto-pause.ts +19 -1
- package/src/types/accounts.ts +21 -0
- package/src/types/anthropic-account-pool.ts +1 -1
- package/src/types/combo-capability-policy.ts +19 -0
- package/src/types/config.ts +22 -2
- package/src/types/provider.ts +42 -8
- package/src/types/request.ts +15 -0
- package/src/types/tools.ts +22 -5
- package/src/types/wire.ts +1 -0
- package/src/types.ts +4 -0
- package/src/update/check-types.ts +2 -0
- package/src/update/job.ts +8 -3
- package/src/update/managed-release.ts +6 -0
- package/src/update/orchestrated-entry.ts +13 -4
- package/src/update/refresh-scheduler.ts +17 -7
- package/src/usage/attempt-delivery.ts +6 -0
- package/src/usage/cache-provenance.ts +71 -0
- package/src/usage/cost.ts +216 -27
- package/src/usage/credit-billing.ts +88 -0
- package/src/usage/jev-stats.ts +13 -9
- package/src/usage/log.ts +5 -33
- package/src/usage/summary.ts +8 -43
- package/src/usage/user-cost-overlays.ts +13 -1
- package/src/vision/index.ts +8 -3
- package/src/vision/plan.ts +28 -14
- package/src/vision/routed-describe.ts +24 -36
- package/src/web-search/header-deadline.ts +14 -3
- package/src/web-search/index.ts +6 -4
- package/src/web-search/loop.ts +240 -78
- package/src/web-search/progress-stream.ts +29 -2
- package/src/web-search/run-turn-loop.ts +5 -1
- package/gui/dist/assets/App-BGP8I0V4.css +0 -1
- package/gui/dist/assets/App-BRExzhwL.js +0 -60
- package/gui/dist/assets/Tray-DHCWAn8V.js +0 -1
- package/gui/dist/assets/brand-mark-C70PuQ3j.js +0 -1
- package/gui/dist/assets/index-DJxM-imn.css +0 -2
- package/gui/dist/assets/index-Dy1jIGty.js +0 -138
- package/gui/dist/classic/assets/App-B4j-Txmb.css +0 -1
- package/gui/dist/classic/assets/App-CaC-E6Vl.js +0 -59
- package/gui/dist/classic/assets/Tray-BG253fiL.js +0 -1
- package/gui/dist/classic/assets/index-CR_AThOp.js +0 -138
- package/gui/dist/classic/assets/quota-summary-B7KQPpEC.js +0 -1
package/src/chat/outbound.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
UNDECLARED_TOOL_CALL_ERROR_CODE,
|
|
28
28
|
} from "../lib/errors";
|
|
29
29
|
import { redactSecretString } from "../lib/redact";
|
|
30
|
+
import { normalizedClientExtraContent } from "../responses/provider-opaque-metadata";
|
|
30
31
|
import { truncationReasonFor } from "../responses/truncated-stop-reason";
|
|
31
32
|
import { createSseBlockBuffer, sseDataPayload } from "../server/sse-payload-rewrite";
|
|
32
33
|
import { reasoningDetailEntriesForItem } from "./reasoning-details";
|
|
@@ -297,7 +298,11 @@ function refusalTranslationError(): ChatCompletionsStreamError {
|
|
|
297
298
|
export function responsesSseToChatCompletionsSse(
|
|
298
299
|
upstream: ReadableStream<Uint8Array>,
|
|
299
300
|
model: string,
|
|
300
|
-
opts: {
|
|
301
|
+
opts: {
|
|
302
|
+
translatorBudget: TranslatorBudget; failureVerdictSink?: FailureVerdictSink; proxyErrorContext?: object;
|
|
303
|
+
/** The client set `stream_options.include_usage`: a failed terminal's usage precedes its error frame. */
|
|
304
|
+
includeUsage?: boolean;
|
|
305
|
+
},
|
|
301
306
|
): ReadableStream<Uint8Array> {
|
|
302
307
|
const translatorBudget = opts.translatorBudget;
|
|
303
308
|
const encoder = new TextEncoder();
|
|
@@ -559,7 +564,7 @@ export function responsesSseToChatCompletionsSse(
|
|
|
559
564
|
// non-empty streamed arguments; genuinely empty calls have no buffered content.
|
|
560
565
|
return candidate.length > 0 || streamed.length === 0 ? candidate : streamed;
|
|
561
566
|
};
|
|
562
|
-
const emitToolCall = (toolIndex: number, callId: string, name: string, args: string) => {
|
|
567
|
+
const emitToolCall = (toolIndex: number, callId: string, name: string, args: string, extra?: unknown) => {
|
|
563
568
|
if (!callId || emittedToolIndexes.has(toolIndex)) return;
|
|
564
569
|
emittedToolIndexes.add(toolIndex);
|
|
565
570
|
ensureRole();
|
|
@@ -572,6 +577,8 @@ export function responsesSseToChatCompletionsSse(
|
|
|
572
577
|
id: callId,
|
|
573
578
|
type: "function",
|
|
574
579
|
function: { name, arguments: args },
|
|
580
|
+
// Provider-opaque state (a Gemini thought signature) for the client to echo back.
|
|
581
|
+
...(normalizedClientExtraContent(extra) ?? {}),
|
|
575
582
|
}],
|
|
576
583
|
},
|
|
577
584
|
finish_reason: null,
|
|
@@ -626,8 +633,17 @@ export function responsesSseToChatCompletionsSse(
|
|
|
626
633
|
terminated = true;
|
|
627
634
|
releaseRefusals();
|
|
628
635
|
};
|
|
629
|
-
const fail = (message: string, details?: ChatCompletionsStreamFailure) => {
|
|
636
|
+
const fail = (message: string, details?: ChatCompletionsStreamFailure, usage?: unknown) => {
|
|
630
637
|
if (terminated) return;
|
|
638
|
+
// A failed turn ends in an {error} frame, never the finish chunk that carries usage, so an
|
|
639
|
+
// include_usage client gets the failed terminal's usage on its own chunk first.
|
|
640
|
+
if (opts.includeUsage && isRec(usage)) {
|
|
641
|
+
try {
|
|
642
|
+
const frame = chunkBase(id, model, created);
|
|
643
|
+
frame.usage = chatCompletionsUsage(usage);
|
|
644
|
+
emit(frame);
|
|
645
|
+
} catch { /* the error frame below still ends the stream */ }
|
|
646
|
+
}
|
|
631
647
|
terminated = true;
|
|
632
648
|
failed = true;
|
|
633
649
|
releaseRefusals();
|
|
@@ -784,7 +800,7 @@ export function responsesSseToChatCompletionsSse(
|
|
|
784
800
|
// done event was omitted, and replace-style clients still get a complete object.
|
|
785
801
|
const args = resolveFinalArguments(item.arguments, streamedArgs);
|
|
786
802
|
replaceToolArguments(toolIndex, args);
|
|
787
|
-
emitToolCall(toolIndex, callId, finalName, args);
|
|
803
|
+
emitToolCall(toolIndex, callId, finalName, args, item.extra_content);
|
|
788
804
|
}
|
|
789
805
|
break;
|
|
790
806
|
}
|
|
@@ -807,14 +823,15 @@ export function responsesSseToChatCompletionsSse(
|
|
|
807
823
|
// failures, not early finishes: emit an error frame and close WITHOUT
|
|
808
824
|
// [DONE] instead of a success-looking stop/tool_calls + [DONE].
|
|
809
825
|
fail(outcome.originalFailMessage, { contract: "stream_incomplete",
|
|
810
|
-
proxyAuthored: hasProxyIncomplete(opts.proxyErrorContext ?? upstream, details.reason, details.message) });
|
|
826
|
+
proxyAuthored: hasProxyIncomplete(opts.proxyErrorContext ?? upstream, details.reason, details.message) }, response.usage);
|
|
811
827
|
}
|
|
812
828
|
break;
|
|
813
829
|
}
|
|
814
830
|
case "response.failed": {
|
|
815
831
|
const response = isRec(data.response) ? data.response : {};
|
|
816
832
|
const failure = chatCompletionsFailedResponse(isRec(response.error) ? response.error : {});
|
|
817
|
-
fail(failure.message, { ...failure.details, proxyAuthored: hasProxyErrorMessage(opts.proxyErrorContext, failure.message, failure.details) }
|
|
833
|
+
fail(failure.message, { ...failure.details, proxyAuthored: hasProxyErrorMessage(opts.proxyErrorContext, failure.message, failure.details) },
|
|
834
|
+
response.usage);
|
|
818
835
|
break;
|
|
819
836
|
}
|
|
820
837
|
default:
|
|
@@ -975,6 +992,7 @@ export function responsesJsonToChatCompletion(json: unknown, model: string, tran
|
|
|
975
992
|
name: typeof raw.name === "string" ? raw.name : "",
|
|
976
993
|
arguments: typeof raw.arguments === "string" ? raw.arguments : "{}",
|
|
977
994
|
},
|
|
995
|
+
...(normalizedClientExtraContent(raw.extra_content) ?? {}),
|
|
978
996
|
};
|
|
979
997
|
// A complete buffered call still obeys the same per-call cap as live deltas.
|
|
980
998
|
// Reserve before serializing, then transfer ownership to the complete call.
|
|
@@ -1129,7 +1147,7 @@ export async function collectChatCompletion(
|
|
|
1129
1147
|
let reasoning = "";
|
|
1130
1148
|
const reasoningDetails: Rec[] = [];
|
|
1131
1149
|
const retainedBytes = { content: 0, refusal: 0, reasoning: 0, reasoningDetails: 0 };
|
|
1132
|
-
const toolCalls = new Map<number, { id: string; name: string; arguments: string; argumentBytes: number }>();
|
|
1150
|
+
const toolCalls = new Map<number, { id: string; name: string; arguments: string; argumentBytes: number; extra?: Rec }>();
|
|
1133
1151
|
// Per-call budget scopes (2 MiB/call enforced by the budget): the map key is the
|
|
1134
1152
|
// wire index, which is stable across deltas and present before the call id.
|
|
1135
1153
|
const callScope = (index: number) => `chat_collect_${index}`;
|
|
@@ -1228,6 +1246,8 @@ export async function collectChatCompletion(
|
|
|
1228
1246
|
translatorBudget.openCall(callScope(index));
|
|
1229
1247
|
}
|
|
1230
1248
|
if (typeof tc.id === "string") current.id = tc.id;
|
|
1249
|
+
const extra = normalizedClientExtraContent(tc.extra_content);
|
|
1250
|
+
if (extra) current.extra = extra;
|
|
1231
1251
|
const fn = isRec(tc.function) ? tc.function : {};
|
|
1232
1252
|
// Done-frame final arguments are authoritative last-write-wins snapshots.
|
|
1233
1253
|
if (typeof fn.name === "string" && fn.name.length > 0) current.name = fn.name;
|
|
@@ -1298,6 +1318,7 @@ export async function collectChatCompletion(
|
|
|
1298
1318
|
id: tc.id || `call_${uuid().slice(0, 16)}`,
|
|
1299
1319
|
type: "function",
|
|
1300
1320
|
function: { name: tc.name, arguments: tc.arguments },
|
|
1321
|
+
...(tc.extra ?? {}),
|
|
1301
1322
|
};
|
|
1302
1323
|
const copyBytes = Buffer.byteLength(JSON.stringify(copy));
|
|
1303
1324
|
translatorBudget.chargeRetained(copyBytes, { kind: "retained_collectors" });
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { aliasForNative, aliasForRoute, currentClaudeAliasSpelling, legacyAliasForNative, legacyAliasForRoute, resolveAlias } from "./alias";
|
|
14
14
|
import { desktop3pAlias } from "./desktop-3p";
|
|
15
15
|
import { nativeOpenAiContextWindow, type CatalogModel, type NativeContextLimitsInput } from "../codex/catalog";
|
|
16
|
+
import { compareStrictSemver, parseStrictSemver } from "../lib/strict-semver";
|
|
16
17
|
import { ANTHROPIC_MODEL_CONTEXT_WINDOWS } from "../providers/registry/model-seeds";
|
|
17
18
|
import type { OcxClaudeCodeConfig } from "../types";
|
|
18
19
|
import { AUTO_COMPACT_WINDOW_DEFAULT, AUTO_CONTEXT_FLOOR, ONE_MILLION } from "./long-context";
|
|
@@ -20,13 +21,14 @@ import { AUTO_COMPACT_WINDOW_DEFAULT, AUTO_CONTEXT_FLOOR, ONE_MILLION } from "./
|
|
|
20
21
|
export { AUTO_COMPACT_WINDOW_DEFAULT, AUTO_CONTEXT_FLOOR } from "./long-context";
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* with this id when the map marks it (#5755). A marked alias cannot stand in: Claude Code sends
|
|
27
|
-
* `sonnet[1m]` upstream unresolved. Haiku has no entry; its 200k window never marks.
|
|
24
|
+
* Behind a gateway Claude Code accounts an unmarked id at 200k, so unset tier slots use
|
|
25
|
+
* concrete model ids when the map marks them (#5755). Claude Code sends a marked alias
|
|
26
|
+
* such as `sonnet[1m]` upstream unresolved. Haiku has no automatic fill.
|
|
28
27
|
*/
|
|
29
|
-
const CLAUDE_CODE_NATIVE_TIERS = { opus: "claude-opus-5-5", sonnet: "claude-sonnet-5-5"
|
|
28
|
+
const CLAUDE_CODE_NATIVE_TIERS = { opus: "claude-opus-5-5", sonnet: "claude-sonnet-5-5" } as const;
|
|
29
|
+
const FABLE_52_MODEL = "claude-fable-5-2";
|
|
30
|
+
// Anthropic rejects Fable 5.2 with a Claude Code identity below this floor.
|
|
31
|
+
const FABLE_52_MIN_CLAUDE_CODE = parseStrictSemver("2.1.290")!;
|
|
30
32
|
|
|
31
33
|
/** Binary-verified accepted range for CLAUDE_CODE_AUTO_COMPACT_WINDOW (2.1.207: pSo=1e5, yDs=1e6). */
|
|
32
34
|
export const AUTO_COMPACT_WINDOW_MIN = 100_000;
|
|
@@ -243,6 +245,24 @@ export interface ClaudeTierModels {
|
|
|
243
245
|
fable?: string;
|
|
244
246
|
}
|
|
245
247
|
|
|
248
|
+
type ModelEnvConfig = AutoContextConfigSlice & {
|
|
249
|
+
model?: string;
|
|
250
|
+
smallFastModel?: string;
|
|
251
|
+
tierModels?: ClaudeTierModels;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
/** Only probe if the installed CLI can affect the automatic Fable selection. */
|
|
255
|
+
export async function probeClaudeCodeVersionForTierFill(
|
|
256
|
+
claudeCode: ModelEnvConfig | undefined,
|
|
257
|
+
windows: Record<string, number>,
|
|
258
|
+
): Promise<string | null> {
|
|
259
|
+
if (claudeCode?.tierModels?.fable !== undefined || claudeCode?.contextAccounting === "200k" || !windows[FABLE_52_MODEL]) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
const { probeInstalledClaudeCodeVersion } = await import("./subagent-force-status");
|
|
263
|
+
return probeInstalledClaudeCodeVersion();
|
|
264
|
+
}
|
|
265
|
+
|
|
246
266
|
/**
|
|
247
267
|
* The exact env map Claude Code consumes for model slots (audit R4#4):
|
|
248
268
|
* ANTHROPIC_MODEL + the four tier defaults + the legacy small-fast alias.
|
|
@@ -250,9 +270,10 @@ export interface ClaudeTierModels {
|
|
|
250
270
|
* value injected into BOTH haiku variables.
|
|
251
271
|
*/
|
|
252
272
|
export function effectiveModelEnv(
|
|
253
|
-
claudeCode:
|
|
273
|
+
claudeCode: ModelEnvConfig | undefined,
|
|
254
274
|
windows: Record<string, number>,
|
|
255
275
|
autoOverride?: AutoContextMode,
|
|
276
|
+
claudeCodeVersion?: string | null,
|
|
256
277
|
): Record<string, string> {
|
|
257
278
|
const out: Record<string, string> = {};
|
|
258
279
|
const auto = autoOverride ?? resolveAutoContext(claudeCode);
|
|
@@ -270,7 +291,10 @@ export function effectiveModelEnv(
|
|
|
270
291
|
set("ANTHROPIC_MODEL", claudeCode?.model);
|
|
271
292
|
set("ANTHROPIC_DEFAULT_OPUS_MODEL", tier(claudeCode?.tierModels?.opus, CLAUDE_CODE_NATIVE_TIERS.opus));
|
|
272
293
|
set("ANTHROPIC_DEFAULT_SONNET_MODEL", tier(claudeCode?.tierModels?.sonnet, CLAUDE_CODE_NATIVE_TIERS.sonnet));
|
|
273
|
-
|
|
294
|
+
const installed = parseStrictSemver(claudeCodeVersion);
|
|
295
|
+
const fable = installed && compareStrictSemver(installed, FABLE_52_MIN_CLAUDE_CODE) >= 0
|
|
296
|
+
? FABLE_52_MODEL : "claude-fable-5-1";
|
|
297
|
+
set("ANTHROPIC_DEFAULT_FABLE_MODEL", tier(claudeCode?.tierModels?.fable, fable));
|
|
274
298
|
const effectiveHaiku = claudeCode?.tierModels?.haiku ?? claudeCode?.smallFastModel;
|
|
275
299
|
set("ANTHROPIC_DEFAULT_HAIKU_MODEL", effectiveHaiku);
|
|
276
300
|
set("ANTHROPIC_SMALL_FAST_MODEL", effectiveHaiku);
|
package/src/claude/desktop-3p.ts
CHANGED
|
@@ -171,8 +171,9 @@ function collectDesktop3pModels(
|
|
|
171
171
|
routedModels: Array<Desktop3pRoutedModel>,
|
|
172
172
|
profile?: OcxClaudeDesktopProfile,
|
|
173
173
|
nativeContextCap?: NativeContextLimitsInput,
|
|
174
|
-
)
|
|
174
|
+
) {
|
|
175
175
|
const registry = new Map<string, string>();
|
|
176
|
+
const aliasesByRoute = new Map<string, string>();
|
|
176
177
|
const models: Desktop3pModelEntry[] = [];
|
|
177
178
|
// routes[i] is the route models[i] serves; visibility filters by route, never by alias.
|
|
178
179
|
const routes: string[] = [];
|
|
@@ -198,7 +199,6 @@ function collectDesktop3pModels(
|
|
|
198
199
|
} satisfies DesktopProfileModel));
|
|
199
200
|
const reconciled = reconcileDesktopProfile(profile, profileModels);
|
|
200
201
|
const rendered = renderDesktopProfile(reconciled, profileModels);
|
|
201
|
-
const aliasesByRoute = new Map<string, string>();
|
|
202
202
|
for (const model of rendered) {
|
|
203
203
|
const realAnthropic = model.route.startsWith("anthropic/claude-");
|
|
204
204
|
if (!realAnthropic && realAnthropicIds.has(model.name)) {
|
|
@@ -251,11 +251,9 @@ function collectDesktop3pModels(
|
|
|
251
251
|
registry.set(legacy, model.route);
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
|
-
|
|
255
|
-
return { models, routes, registry, realAnthropicIds };
|
|
254
|
+
return { models, routes, registry, aliasesByRoute, realAnthropicIds };
|
|
256
255
|
}
|
|
257
256
|
|
|
258
|
-
const aliasesByRoute = new Map<string, string>();
|
|
259
257
|
const emittedNames = new Set<string>();
|
|
260
258
|
for (const { provider, id, contextWindow } of candidates) {
|
|
261
259
|
const route = `${provider}/${id}`;
|
|
@@ -310,8 +308,13 @@ function collectDesktop3pModels(
|
|
|
310
308
|
}
|
|
311
309
|
|
|
312
310
|
if (models[0]) models[0].isFamilyDefault = true;
|
|
311
|
+
return { models, routes, registry, aliasesByRoute, realAnthropicIds };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function installDesktop3pRegistry({ registry, aliasesByRoute, realAnthropicIds }: ReturnType<typeof collectDesktop3pModels>): void {
|
|
315
|
+
desktop3pRegistry = registry;
|
|
313
316
|
desktop3pAliasesByRoute = aliasesByRoute;
|
|
314
|
-
|
|
317
|
+
desktop3pRealAnthropicIds = realAnthropicIds;
|
|
315
318
|
}
|
|
316
319
|
|
|
317
320
|
/** Build and install the registry used to decode Desktop aliases. */
|
|
@@ -321,10 +324,9 @@ export function buildDesktop3pRegistry(
|
|
|
321
324
|
profile?: OcxClaudeDesktopProfile,
|
|
322
325
|
nativeContextCap?: NativeContextLimitsInput,
|
|
323
326
|
): Map<string, string> {
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
return registry;
|
|
327
|
+
const collected = collectDesktop3pModels(nativeSlugs, routedModels, profile, nativeContextCap);
|
|
328
|
+
installDesktop3pRegistry(collected);
|
|
329
|
+
return collected.registry;
|
|
328
330
|
}
|
|
329
331
|
|
|
330
332
|
/** Generate Claude Desktop 3P model entries from the proxy's available models. */
|
|
@@ -348,9 +350,9 @@ export function generateDesktop3pModels(
|
|
|
348
350
|
nativeContextCap?: NativeContextLimitsInput,
|
|
349
351
|
options: Desktop3pModelOptions = {},
|
|
350
352
|
): Desktop3pModelEntry[] {
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
|
|
353
|
+
const collected = collectDesktop3pModels(nativeSlugs, routedModels, profile, nativeContextCap);
|
|
354
|
+
installDesktop3pRegistry(collected);
|
|
355
|
+
const { models: all, routes } = collected;
|
|
354
356
|
let models = filterDesktopModelsByVisibility(all, routes, options.visibility);
|
|
355
357
|
if (models.length === 0 && all.length > 0) {
|
|
356
358
|
// An empty static list leaves Desktop with no usable picker. The dashboard refuses to save
|
|
@@ -408,7 +410,9 @@ export function activeDesktop3pAlias(provider: string, modelId: string): string
|
|
|
408
410
|
|
|
409
411
|
/** Discovery cannot offer a skipped alias or one owned by a different route. */
|
|
410
412
|
export function resolvableDesktop3pAlias(provider: string, modelId: string): string | undefined {
|
|
411
|
-
if (provider === "anthropic" && modelId.startsWith("claude-"))
|
|
413
|
+
if (provider === "anthropic" && modelId.startsWith("claude-")) {
|
|
414
|
+
return desktop3pRealAnthropicIds.has(modelId) ? modelId : undefined;
|
|
415
|
+
}
|
|
412
416
|
const alias = activeDesktop3pAlias(provider, modelId);
|
|
413
417
|
return resolveDesktop3pAlias(alias) === `${provider}/${modelId}` ? alias : undefined;
|
|
414
418
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** Platforms with a Desktop egress profile and an OS trust adapter for the picker. */
|
|
2
2
|
export function supportsDesktopPicker(platform: NodeJS.Platform = process.platform): boolean {
|
|
3
|
-
return platform === "darwin" || platform === "win32";
|
|
3
|
+
return platform === "darwin" || platform === "win32" || platform === "linux";
|
|
4
4
|
}
|
|
@@ -184,7 +184,7 @@ export function createDesktopPickerController(deps: DesktopPickerControllerDeps)
|
|
|
184
184
|
if (!supportsDesktopPicker(platform) || !existsSync(caPath)) return true;
|
|
185
185
|
try {
|
|
186
186
|
const sha1 = pickerCaFingerprints(readFileSync(caPath, "utf8")).sha1;
|
|
187
|
-
return (await untrustPickerCa(caPath, sha1, deps.security, platform)).ok;
|
|
187
|
+
return (await untrustPickerCa(caPath, sha1, deps.security, platform, undefined, { configDir: deps.configDir })).ok;
|
|
188
188
|
} catch { return false; }
|
|
189
189
|
}
|
|
190
190
|
|
|
@@ -248,7 +248,7 @@ export function createDesktopPickerController(deps: DesktopPickerControllerDeps)
|
|
|
248
248
|
let trust = await inspectPickerTrust(pickerLeafCertPath(deps.configDir), caSha1, deps.security, platform);
|
|
249
249
|
observedTrust = trust;
|
|
250
250
|
if (trust !== "trusted" && options.context === "server" && options.allowTrustPrompt !== false) {
|
|
251
|
-
const added = await trustPickerCa(caPath, deps.security, platform, { pem: ca.certPem });
|
|
251
|
+
const added = await trustPickerCa(caPath, deps.security, platform, { pem: ca.certPem, configDir: deps.configDir });
|
|
252
252
|
trustedByAttempt = added.ok;
|
|
253
253
|
trust = await inspectPickerTrust(pickerLeafCertPath(deps.configDir), caSha1, deps.security, platform);
|
|
254
254
|
observedTrust = trust;
|
|
@@ -349,7 +349,7 @@ export async function removeDesktopPickerArtifacts(options: { configDir?: string
|
|
|
349
349
|
if (supportsDesktopPicker(platform) && existsSync(caPath)) {
|
|
350
350
|
try {
|
|
351
351
|
const sha1 = pickerCaFingerprints(readFileSync(caPath, "utf8")).sha1;
|
|
352
|
-
if (!(await untrustPickerCa(caPath, sha1, options.security, platform)).ok) residual.push("trust");
|
|
352
|
+
if (!(await untrustPickerCa(caPath, sha1, options.security, platform, undefined, { configDir })).ok) residual.push("trust");
|
|
353
353
|
} catch { residual.push("trust"); }
|
|
354
354
|
}
|
|
355
355
|
return residual.length ? { ok: false, residual } : { ok: true };
|
|
@@ -112,6 +112,16 @@ export function declaredAnthropicServerTools(raw: unknown): Rec[] | undefined {
|
|
|
112
112
|
return tools.length > 0 ? tools : undefined;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
export type HostedAdvisorSelection = "selected" | "ambiguous";
|
|
116
|
+
|
|
117
|
+
/** Read the named choice against the original catalog before Messages lowers it to a function. */
|
|
118
|
+
export function hostedAdvisorSelection(raw: unknown): HostedAdvisorSelection | undefined {
|
|
119
|
+
if (!isRec(raw) || !isRec(raw.tool_choice) || !Array.isArray(raw.tools)
|
|
120
|
+
|| raw.tool_choice.type !== "tool" || raw.tool_choice.name !== ADVISOR_SERVER_TOOL_NAME) return undefined;
|
|
121
|
+
const matching = raw.tools.filter((tool): tool is Rec => isRec(tool) && tool.name === ADVISOR_SERVER_TOOL_NAME);
|
|
122
|
+
if (matching.some(tool => isAdvisorServerToolType(tool.type))) return matching.length === 1 ? "selected" : "ambiguous";
|
|
123
|
+
}
|
|
124
|
+
|
|
115
125
|
/**
|
|
116
126
|
* A declared tool the translated body drops and no out-of-body lane carries (bash_*, text_editor_*, ...).
|
|
117
127
|
* The Advisor rides the out-of-body lane and is optional: a destination without it simply runs the
|
|
@@ -215,7 +225,7 @@ export function toolChoiceToResponses(choice: unknown, body: Rec): void {
|
|
|
215
225
|
}
|
|
216
226
|
// Anthropic represents hosted WebSearch as a named tool choice, while
|
|
217
227
|
// Responses requires the choice type to match the hosted declaration.
|
|
218
|
-
//
|
|
228
|
+
// Keep the hosted selector for request authorization even when an adapter lowers it to auto.
|
|
219
229
|
if (isClaudeWebSearchToolName(choice.name)
|
|
220
230
|
&& (!Array.isArray(body.tools) || !body.tools.some(tool => isRec(tool) && tool.type === "web_search"))) {
|
|
221
231
|
throw markProxyError(new AnthropicRequestError("Restricted web search cannot be forced on a translated route without an available search declaration"));
|
|
@@ -4,6 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import { withConfigDirHardeningSettled } from "../../config/paths";
|
|
5
5
|
import {
|
|
6
6
|
acknowledgePendingPickerCaUntrust,
|
|
7
|
+
bindPendingPickerCaLinuxStore,
|
|
7
8
|
pendingPickerCaHasLivePublishedOwner,
|
|
8
9
|
readPendingPickerCaUntrust,
|
|
9
10
|
} from "./picker-ca";
|
|
@@ -13,20 +14,31 @@ import { untrustPickerCa, type SecurityRunner } from "./picker-trust";
|
|
|
13
14
|
export async function drainPendingPickerCaUntrust(
|
|
14
15
|
configDir: string,
|
|
15
16
|
security?: SecurityRunner,
|
|
16
|
-
platform
|
|
17
|
+
platform: NodeJS.Platform = process.platform,
|
|
18
|
+
linuxHome?: string,
|
|
17
19
|
): Promise<boolean> {
|
|
18
|
-
const pending = readPendingPickerCaUntrust(configDir);
|
|
20
|
+
const pending = readPendingPickerCaUntrust(configDir, platform);
|
|
19
21
|
if (!pending) return true;
|
|
20
|
-
if (
|
|
22
|
+
if (pending.linuxStore && platform !== "linux") return false;
|
|
23
|
+
if (await withConfigDirHardeningSettled(configDir, () => pendingPickerCaHasLivePublishedOwner(configDir, pending, platform))) return false;
|
|
21
24
|
|
|
22
25
|
const privateDir = mkdtempSync(join(tmpdir(), "ocx-picker-untrust-"));
|
|
23
26
|
try {
|
|
24
27
|
const publicCopy = join(privateDir, "ca.pem");
|
|
25
28
|
writeFileSync(publicCopy, pending.certPem, { mode: 0o600 });
|
|
26
|
-
|
|
29
|
+
let pendingToAcknowledge = pending;
|
|
30
|
+
const result = await untrustPickerCa(publicCopy, pending.sha1, security, platform, linuxHome,
|
|
31
|
+
{ store: pending.linuxStore, bindStore: store => {
|
|
32
|
+
pendingToAcknowledge = bindPendingPickerCaLinuxStore(configDir, pending, store);
|
|
33
|
+
} });
|
|
34
|
+
if (result.reason === "original_store_unknown") {
|
|
35
|
+
console.warn("Claude Desktop picker CA cleanup is still pending: the original NSS database is unknown. "
|
|
36
|
+
+ "Retry with the XDG_DATA_HOME used when the certificate was installed.");
|
|
37
|
+
}
|
|
27
38
|
if (!result.ok) return false;
|
|
28
39
|
// OS untrust yielded: a new parent flight may have started since the owner inspection.
|
|
29
|
-
return await withConfigDirHardeningSettled(configDir, () =>
|
|
40
|
+
return await withConfigDirHardeningSettled(configDir, () =>
|
|
41
|
+
acknowledgePendingPickerCaUntrust(configDir, pendingToAcknowledge, result, platform));
|
|
30
42
|
} finally {
|
|
31
43
|
rmSync(privateDir, { recursive: true, force: true });
|
|
32
44
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { createHash, randomUUID, X509Certificate } from "node:crypto";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
chmodSync, closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, readFileSync,
|
|
4
|
+
readSync, renameSync, rmSync, statSync, writeFileSync, type BigIntStats,
|
|
5
|
+
} from "node:fs";
|
|
6
|
+
import { dirname, isAbsolute, join, posix } from "node:path";
|
|
4
7
|
import { canonicalPickerConfigDir, ensurePersistentPickerCa } from "./picker-ca-persistence";
|
|
5
8
|
import type { PickerCaStore } from "./picker-ca-store";
|
|
6
|
-
import { withClientLifecycleSync } from "../../client/lifecycle-lock";
|
|
9
|
+
import { withClientLifecycle, withClientLifecycleSync } from "../../client/lifecycle-lock";
|
|
10
|
+
import { sameFileIdentity } from "../../lib/file-identity";
|
|
7
11
|
import {
|
|
8
12
|
ALL_IP_ADDRESS_BASES,
|
|
9
13
|
createCertificateAuthority,
|
|
@@ -18,7 +22,8 @@ export const PICKER_CA_COMMON_NAME = "opencodex Claude Desktop Picker CA";
|
|
|
18
22
|
export const PICKER_STATE_DIR = "claude-picker";
|
|
19
23
|
|
|
20
24
|
export interface PickerCa extends LocalInterceptCa { fingerprint: string }
|
|
21
|
-
export interface
|
|
25
|
+
export interface LinuxPickerTrustStore { dir: string; directoryId: string; certDbId: string }
|
|
26
|
+
export interface PendingPickerCaUntrust { certPem: string; sha1: string; sha256: string; linuxStore?: LinuxPickerTrustStore }
|
|
22
27
|
|
|
23
28
|
const processAuthorities = new Map<string, PickerCa>();
|
|
24
29
|
const MAX_PENDING_CA_BYTES = 64 * 1024;
|
|
@@ -30,6 +35,20 @@ export function pickerLeafCertPath(configDir: string): string { return join(pick
|
|
|
30
35
|
export function pickerCaOwnerPath(configDir: string): string { return join(pickerStateDir(configDir), "ca-owner.json"); }
|
|
31
36
|
export function pickerCaPendingUntrustPath(configDir: string): string { return join(pickerStateDir(configDir), "pending-untrust.json"); }
|
|
32
37
|
function pickerCaLockPath(configDir: string): string { return join(pickerStateDir(configDir), "ca.lock.sqlite"); }
|
|
38
|
+
function linuxTrustStorePath(configDir: string): string { return join(pickerStateDir(configDir), "linux-trust-store.json"); }
|
|
39
|
+
|
|
40
|
+
function isLinuxPickerTrustStore(value: unknown): value is LinuxPickerTrustStore {
|
|
41
|
+
if (!value || typeof value !== "object" || Object.keys(value).sort().join(",") !== "certDbId,dir,directoryId") return false;
|
|
42
|
+
const store = value as Partial<LinuxPickerTrustStore>;
|
|
43
|
+
const validIdentity = (id: unknown) => typeof id === "string" && /^\d+:[1-9]\d*$/.test(id);
|
|
44
|
+
return typeof store.dir === "string" && (isAbsolute(store.dir) || posix.isAbsolute(store.dir))
|
|
45
|
+
&& !store.dir.includes("\0") && !store.dir.split(/[/\\]/).includes("..")
|
|
46
|
+
&& validIdentity(store.directoryId) && validIdentity(store.certDbId);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function sameLinuxPickerTrustStore(a?: LinuxPickerTrustStore, b?: LinuxPickerTrustStore): boolean {
|
|
50
|
+
return a?.dir === b?.dir && a?.directoryId === b?.directoryId && a?.certDbId === b?.certDbId;
|
|
51
|
+
}
|
|
33
52
|
|
|
34
53
|
export function pickerCaFingerprints(certPem: string): { sha1: string; sha256: string } {
|
|
35
54
|
const der = new X509Certificate(certPem).raw;
|
|
@@ -292,28 +311,80 @@ function publicCertificate(pem: string): PendingPickerCaUntrust | null {
|
|
|
292
311
|
}
|
|
293
312
|
}
|
|
294
313
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const path = pickerCaPendingUntrustPath(configDir);
|
|
298
|
-
let stat;
|
|
299
|
-
try { stat = lstatSync(path); }
|
|
314
|
+
function trustStateStat(path: string): BigIntStats | null {
|
|
315
|
+
try { return lstatSync(path, { bigint: true }); }
|
|
300
316
|
catch (error) {
|
|
301
|
-
if (
|
|
317
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return null;
|
|
302
318
|
throw error;
|
|
303
319
|
}
|
|
304
|
-
|
|
305
|
-
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function readPublicTrustStateBytes(path: string, checkLinuxOwner: boolean): Buffer | null {
|
|
323
|
+
const uid = checkLinuxOwner ? process.getuid?.() : undefined;
|
|
324
|
+
const directory = dirname(path);
|
|
325
|
+
const ownerControlled = (stat: BigIntStats) => uid === undefined || (stat.uid === BigInt(uid) && (stat.mode & 0o022n) === 0n);
|
|
326
|
+
const safeFile = (stat: BigIntStats) => stat.isFile() && stat.nlink === 1n
|
|
327
|
+
&& stat.size <= BigInt(MAX_PENDING_CA_BYTES) && ownerControlled(stat);
|
|
328
|
+
const sameEntry = (a: BigIntStats, b: BigIntStats) => a.ino !== 0n && sameFileIdentity(a, b) && a.ctimeNs === b.ctimeNs;
|
|
329
|
+
const unsafe = () => new Error("picker_ca_pending_untrust_unsafe");
|
|
330
|
+
|
|
331
|
+
// NSS bindings carry cleanup authority. Validate their containing directory even
|
|
332
|
+
// when the journal is absent, then verify the path and open descriptor agree.
|
|
333
|
+
const parent = uid === undefined ? null : trustStateStat(directory);
|
|
334
|
+
if (uid !== undefined && !parent) return null;
|
|
335
|
+
if (parent && (!parent.isDirectory() || !ownerControlled(parent))) throw unsafe();
|
|
336
|
+
const entry = trustStateStat(path);
|
|
337
|
+
if (!entry) return null;
|
|
338
|
+
if (!safeFile(entry)) throw unsafe();
|
|
339
|
+
|
|
340
|
+
let fd: number;
|
|
341
|
+
try {
|
|
342
|
+
fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
343
|
+
} catch {
|
|
344
|
+
throw unsafe();
|
|
345
|
+
}
|
|
346
|
+
try {
|
|
347
|
+
const opened = fstatSync(fd, { bigint: true });
|
|
348
|
+
if (!sameEntry(entry, opened) || !safeFile(opened)) throw unsafe();
|
|
349
|
+
const bytes = Buffer.alloc(MAX_PENDING_CA_BYTES + 1);
|
|
350
|
+
let used = 0;
|
|
351
|
+
while (used < bytes.length) {
|
|
352
|
+
const count = readSync(fd, bytes, used, bytes.length - used, null);
|
|
353
|
+
if (count === 0) break;
|
|
354
|
+
used += count;
|
|
355
|
+
}
|
|
356
|
+
const after = trustStateStat(path);
|
|
357
|
+
if (used > MAX_PENDING_CA_BYTES || !after || !sameEntry(opened, after) || !safeFile(after)) throw unsafe();
|
|
358
|
+
if (parent) {
|
|
359
|
+
const current = trustStateStat(directory);
|
|
360
|
+
if (!current?.isDirectory() || !sameEntry(parent, current) || !ownerControlled(current)) throw unsafe();
|
|
361
|
+
}
|
|
362
|
+
return bytes.subarray(0, used);
|
|
363
|
+
} finally {
|
|
364
|
+
closeSync(fd);
|
|
306
365
|
}
|
|
307
|
-
|
|
308
|
-
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function readPublicTrustState(path: string, checkLinuxOwner: boolean): object | null {
|
|
369
|
+
const bytes = readPublicTrustStateBytes(path, checkLinuxOwner);
|
|
370
|
+
if (bytes === null) return null;
|
|
309
371
|
let value: unknown;
|
|
310
|
-
try { value = JSON.parse(
|
|
372
|
+
try { value = JSON.parse(bytes.toString("utf8")); }
|
|
311
373
|
catch { throw new Error("picker_ca_pending_untrust_invalid"); }
|
|
312
374
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
313
375
|
throw new Error("picker_ca_pending_untrust_invalid");
|
|
314
376
|
}
|
|
377
|
+
return value;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** The pending record is public-only, but malformed or unsafe state must never be discarded. */
|
|
381
|
+
export function readPendingPickerCaUntrust(configDir: string, platform = process.platform): PendingPickerCaUntrust | null {
|
|
382
|
+
const value = readPublicTrustState(pickerCaPendingUntrustPath(configDir), platform === "linux");
|
|
383
|
+
if (value === null) return null;
|
|
315
384
|
const pending = value as Partial<PendingPickerCaUntrust>;
|
|
316
|
-
|
|
385
|
+
const keys = pending.linuxStore === undefined ? "certPem,sha1,sha256" : "certPem,linuxStore,sha1,sha256";
|
|
386
|
+
if (Object.keys(pending).sort().join(",") !== keys
|
|
387
|
+
|| (pending.linuxStore !== undefined && !isLinuxPickerTrustStore(pending.linuxStore))
|
|
317
388
|
|| typeof pending.certPem !== "string" || typeof pending.sha1 !== "string" || typeof pending.sha256 !== "string") {
|
|
318
389
|
throw new Error("picker_ca_pending_untrust_invalid");
|
|
319
390
|
}
|
|
@@ -322,14 +393,13 @@ export function readPendingPickerCaUntrust(configDir: string): PendingPickerCaUn
|
|
|
322
393
|
|| pending.sha1 !== publicOnly.sha1 || pending.sha256 !== publicOnly.sha256) {
|
|
323
394
|
throw new Error("picker_ca_pending_untrust_invalid");
|
|
324
395
|
}
|
|
325
|
-
return publicOnly;
|
|
396
|
+
return pending.linuxStore ? { ...publicOnly, linuxStore: pending.linuxStore } : publicOnly;
|
|
326
397
|
}
|
|
327
398
|
|
|
328
|
-
function
|
|
329
|
-
const path = pickerCaPendingUntrustPath(configDir);
|
|
399
|
+
function writePrivateTrustState(path: string, value: object): void {
|
|
330
400
|
const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
331
401
|
try {
|
|
332
|
-
writeFileSync(temporary, JSON.stringify(
|
|
402
|
+
writeFileSync(temporary, JSON.stringify(value) + "\n", { flag: "wx", mode: 0o600 });
|
|
333
403
|
try { chmodSync(temporary, 0o600); } catch { /* best-effort on platforms without POSIX modes */ }
|
|
334
404
|
renameSync(temporary, path);
|
|
335
405
|
} finally {
|
|
@@ -337,6 +407,21 @@ function writePendingPickerCaUntrust(configDir: string, pending: PendingPickerCa
|
|
|
337
407
|
}
|
|
338
408
|
}
|
|
339
409
|
|
|
410
|
+
function readLinuxTrustStore(configDir: string, sha256: string): LinuxPickerTrustStore | undefined {
|
|
411
|
+
const value = readPublicTrustState(linuxTrustStorePath(configDir), true);
|
|
412
|
+
if (value === null) return undefined;
|
|
413
|
+
const record = value as { sha256?: string; store?: LinuxPickerTrustStore };
|
|
414
|
+
if (Object.keys(record).sort().join(",") !== "sha256,store"
|
|
415
|
+
|| typeof record.sha256 !== "string" || !/^[0-9A-F]{64}$/.test(record.sha256)
|
|
416
|
+
|| !isLinuxPickerTrustStore(record.store)) throw new Error("picker_ca_linux_store_invalid");
|
|
417
|
+
return record.sha256 === sha256 ? record.store : undefined;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function writePendingPickerCaUntrust(configDir: string, pending: PendingPickerCaUntrust): void {
|
|
421
|
+
const linuxStore = readLinuxTrustStore(configDir, pending.sha256);
|
|
422
|
+
writePrivateTrustState(pickerCaPendingUntrustPath(configDir), { ...pending, linuxStore });
|
|
423
|
+
}
|
|
424
|
+
|
|
340
425
|
/**
|
|
341
426
|
* A lock failure is separate from a successful void callback. Once the callback entered, an
|
|
342
427
|
* exception (including lock release failure) propagates: its effects may be partial.
|
|
@@ -371,12 +456,63 @@ function publishedPickerCa(configDir: string): string | null {
|
|
|
371
456
|
}
|
|
372
457
|
}
|
|
373
458
|
|
|
459
|
+
/** Serialize Linux trust changes with rotation. Record the exact store before certutil can mutate it. */
|
|
460
|
+
export async function withPublishedPickerCaLinuxTrust<T>(
|
|
461
|
+
configDir: string,
|
|
462
|
+
certPem: string,
|
|
463
|
+
work: (store: LinuxPickerTrustStore | undefined, save: (store: LinuxPickerTrustStore) => void, clear: () => void) => Promise<T>,
|
|
464
|
+
): Promise<T> {
|
|
465
|
+
configDir = canonicalPickerConfigDir(configDir);
|
|
466
|
+
const sha256 = pickerCaFingerprints(certPem).sha256;
|
|
467
|
+
const path = linuxTrustStorePath(configDir);
|
|
468
|
+
return withClientLifecycle(async () => {
|
|
469
|
+
if (publishedPickerCa(configDir) !== certPem) throw new Error("picker_ca_trust_state_changed");
|
|
470
|
+
const current = readLinuxTrustStore(configDir, sha256);
|
|
471
|
+
return work(current, store => {
|
|
472
|
+
if (readPendingPickerCaUntrust(configDir, "linux")) throw new Error("picker_ca_pending_untrust");
|
|
473
|
+
if (current && !sameLinuxPickerTrustStore(current, store)) throw new Error("picker_ca_linux_store_changed");
|
|
474
|
+
if (!current) writePrivateTrustState(path, { sha256, store });
|
|
475
|
+
}, () => {
|
|
476
|
+
if (current) rmSync(path);
|
|
477
|
+
});
|
|
478
|
+
}, { lockPath: pickerCaLockPath(configDir) });
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function samePendingUntrust(current: PendingPickerCaUntrust | null, pending: PendingPickerCaUntrust): boolean {
|
|
482
|
+
return current?.certPem === pending.certPem && current.sha1 === pending.sha1
|
|
483
|
+
&& current.sha256 === pending.sha256 && sameLinuxPickerTrustStore(current.linuxStore, pending.linuxStore);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** Record the verified NSS store before mutating it, conditional on the journal we read. */
|
|
487
|
+
export function bindPendingPickerCaLinuxStore(
|
|
488
|
+
configDir: string,
|
|
489
|
+
pending: PendingPickerCaUntrust,
|
|
490
|
+
store: LinuxPickerTrustStore,
|
|
491
|
+
): PendingPickerCaUntrust {
|
|
492
|
+
if (pending.linuxStore || !isLinuxPickerTrustStore(store)) throw new Error("picker_ca_linux_store_invalid");
|
|
493
|
+
const checkPending = () => {
|
|
494
|
+
if (!samePendingUntrust(readPendingPickerCaUntrust(configDir, "linux"), pending)) {
|
|
495
|
+
throw new Error("picker_ca_pending_untrust_changed");
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
// The lock setup hardens the state directory. Validate ownership and mode before it runs.
|
|
499
|
+
checkPending();
|
|
500
|
+
return lockedPickerCa(configDir, () => {
|
|
501
|
+
checkPending();
|
|
502
|
+
const bound = { ...pending, linuxStore: store };
|
|
503
|
+
writePrivateTrustState(pickerCaPendingUntrustPath(configDir), bound);
|
|
504
|
+
return bound;
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
|
|
374
508
|
/** A pending CA may still be serving when journal publication preceded a failed PEM replacement. */
|
|
375
|
-
export function pendingPickerCaHasLivePublishedOwner(
|
|
509
|
+
export function pendingPickerCaHasLivePublishedOwner(
|
|
510
|
+
configDir: string,
|
|
511
|
+
pending: PendingPickerCaUntrust,
|
|
512
|
+
platform = process.platform,
|
|
513
|
+
): boolean {
|
|
376
514
|
return lockedPickerCa(configDir, () => {
|
|
377
|
-
|
|
378
|
-
if (!current || current.sha1 !== pending.sha1
|
|
379
|
-
|| current.sha256 !== pending.sha256 || current.certPem !== pending.certPem) {
|
|
515
|
+
if (!samePendingUntrust(readPendingPickerCaUntrust(configDir, platform), pending)) {
|
|
380
516
|
throw new Error("picker_ca_pending_untrust_changed");
|
|
381
517
|
}
|
|
382
518
|
const published = publishedPickerCa(configDir);
|
|
@@ -390,12 +526,11 @@ export function acknowledgePendingPickerCaUntrust(
|
|
|
390
526
|
configDir: string,
|
|
391
527
|
pending: PendingPickerCaUntrust,
|
|
392
528
|
confirmedUntrust: { ok: boolean },
|
|
529
|
+
platform = process.platform,
|
|
393
530
|
): boolean {
|
|
394
531
|
if (confirmedUntrust?.ok !== true) return false;
|
|
395
532
|
return lockedPickerCa(configDir, () => {
|
|
396
|
-
|
|
397
|
-
if (!current || current.certPem !== pending.certPem
|
|
398
|
-
|| current.sha1 !== pending.sha1 || current.sha256 !== pending.sha256) return false;
|
|
533
|
+
if (!samePendingUntrust(readPendingPickerCaUntrust(configDir, platform), pending)) return false;
|
|
399
534
|
rmSync(pickerCaPendingUntrustPath(configDir));
|
|
400
535
|
return true;
|
|
401
536
|
});
|