@bitkyc08/opencodex 2.93.0 → 2.95.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-8yedBkhm.js +58 -0
- package/gui/dist/assets/App-B4j-Txmb.css +1 -0
- package/gui/dist/assets/Tray-erSMzxPG.js +1 -0
- package/gui/dist/assets/index-CHWwDo9L.css +1 -0
- package/gui/dist/assets/index-D7DCm5eQ.js +94 -0
- package/gui/dist/assets/quota-summary-BK4VuQNc.js +1 -0
- 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 +27 -7
- 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-project-context.ts +3 -3
- 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 +7 -1
- package/src/adapters/kiro/stream.ts +19 -13
- package/src/adapters/kiro-events.ts +1 -0
- package/src/adapters/openai-chat/completed-tool-blocks.ts +65 -0
- package/src/adapters/openai-chat/messages.ts +42 -17
- package/src/adapters/openai-chat/passthrough.ts +4 -2
- 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/single-system.ts +24 -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/muse-tool-catalog.ts +87 -0
- package/src/adapters/openai-responses/passthrough.ts +53 -41
- package/src/adapters/openai-responses/prompt-cache.ts +3 -1
- package/src/adapters/openai-responses/request-strips.ts +23 -4
- package/src/adapters/openai-responses/tool-output-recovery.ts +21 -8
- package/src/adapters/openai-responses/tool-schema.ts +20 -8
- package/src/adapters/openai-responses/transport.ts +20 -2
- package/src/adapters/openai-responses/usage.ts +34 -0
- package/src/adapters/opencode-go-additional-tools.ts +39 -6
- package/src/adapters/qoder/adapter.ts +9 -15
- package/src/adapters/qoder/image-input.ts +52 -0
- package/src/adapters/routed-agent-messages.ts +3 -0
- package/src/adapters/unique-tool-call-ids.ts +2 -2
- package/src/adapters/xai-web-search.ts +6 -3
- 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 +48 -3
- package/src/advisor/consult.ts +39 -5
- package/src/advisor/runtime.ts +12 -3
- package/src/bridge/errors.ts +22 -1
- package/src/bridge/max-output-completion.ts +41 -0
- package/src/bridge/response-json.ts +13 -5
- package/src/bridge/sse.ts +34 -14
- 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 +88 -0
- package/src/chatgpt/app-server-shim/bundle-trust.ts +15 -72
- package/src/chatgpt/app-server-shim/launcher.ts +40 -6
- package/src/claude/compatibility.ts +5 -1
- package/src/claude/desktop-3p.ts +27 -6
- package/src/claude/desktop-first-party.ts +16 -5
- package/src/claude/desktop-gateway-state.ts +4 -0
- package/src/claude/desktop-model-visibility.ts +141 -0
- package/src/claude/desktop-remote-store-io.ts +8 -8
- package/src/claude/inbound-content-options.ts +11 -1
- package/src/claude/inbound-tool-loading.ts +93 -0
- package/src/claude/intercept/picker-listener.ts +33 -1
- package/src/claude/intercept/proxy-auth.ts +16 -16
- package/src/claude/model-info.ts +29 -4
- package/src/claude/outbound.ts +33 -13
- package/src/cli/account-main.ts +44 -5
- package/src/cli/capabilities-base.ts +22 -5
- package/src/cli/capabilities-integrations.ts +4 -4
- package/src/cli/capabilities-provider-models.ts +7 -0
- package/src/cli/chatgpt-command.ts +1 -1
- 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 +322 -0
- package/src/cli/codex-shim-autorestore.ts +21 -1
- package/src/cli/config-command.ts +9 -4
- package/src/cli/config-mutation.ts +13 -0
- package/src/cli/dispatch.ts +19 -13
- package/src/cli/doctor.ts +5 -5
- 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 +62 -73
- package/src/cli/init.ts +2 -2
- 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/internal-command.ts +29 -2
- 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-cc-switch-import.ts +185 -0
- package/src/cli/provider.ts +151 -139
- package/src/cli/registry.ts +35 -3
- package/src/cli/restart-scope.ts +2 -2
- package/src/cli/root.ts +8 -6
- 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-approval.ts +15 -1
- 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 +86 -23
- 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-api.ts +2 -2
- 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 +65 -18
- package/src/clients/gentle-shell-path.ts +3 -3
- package/src/codex/account-cooldown-response.ts +18 -0
- 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/app-server-restart-service.ts +2 -2
- package/src/codex/auth-api/login-flow.ts +2 -2
- 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-api/pool-quota-probe.ts +2 -2
- package/src/codex/auth-context.ts +49 -8
- package/src/codex/catalog/antigravity-discovery.ts +59 -0
- package/src/codex/catalog/build-entries.ts +12 -13
- package/src/codex/catalog/bundled.ts +67 -10
- package/src/codex/catalog/derive-entry.ts +2 -0
- package/src/codex/catalog/gather-capture.ts +3 -0
- package/src/codex/catalog/metadata.ts +10 -10
- package/src/codex/catalog/model-hints.ts +36 -4
- package/src/codex/catalog/native-omission.ts +28 -0
- package/src/codex/catalog/native-priority.ts +63 -0
- package/src/codex/catalog/native-template.ts +58 -0
- package/src/codex/catalog/parsing.ts +3 -29
- package/src/codex/catalog/provider-models.ts +22 -5
- package/src/codex/catalog/retained-sync.ts +16 -6
- package/src/codex/catalog/write-audit.ts +18 -18
- package/src/codex/chatgpt-refresh-failure.ts +2 -2
- package/src/codex/cli-install-provenance.ts +103 -74
- 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 +259 -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 +1082 -0
- package/src/codex/cli-update-job-worker.ts +385 -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 +282 -0
- package/src/codex/cli-update-selection-gate.ts +305 -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 +268 -0
- package/src/codex/codex-home-owner.ts +9 -8
- package/src/codex/convergence.ts +13 -3
- package/src/codex/coordinator-doctor.ts +14 -8
- package/src/codex/desktop-app/handoff.ts +1 -1
- package/src/codex/desktop-app-restart.ts +32 -3
- package/src/codex/exec-boundary.ts +229 -0
- package/src/codex/forward-transport-headers.ts +80 -0
- package/src/codex/history-job.ts +7 -0
- package/src/codex/history-provider.ts +16 -12
- package/src/codex/history-worker.ts +20 -1
- package/src/codex/inject/bounded-config-reader.ts +14 -13
- 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 +167 -29
- package/src/codex/native-main-auth-temp.ts +3 -2
- package/src/codex/native-main-lock-file.ts +13 -12
- 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/native-residue.ts +18 -14
- package/src/codex/ocx-compaction-history.ts +3 -2
- package/src/codex/orca-auth-source.ts +8 -7
- package/src/codex/prompt-text-probe.ts +211 -69
- package/src/codex/quota-types.ts +5 -0
- package/src/codex/quota.ts +58 -7
- package/src/codex/role-auto-assign.ts +50 -26
- package/src/codex/role-capability.ts +160 -0
- package/src/codex/role-model-history.ts +253 -0
- package/src/codex/role-sizing.ts +24 -6
- package/src/codex/routing/cooldown-math.ts +3 -2
- package/src/codex/runtime.ts +161 -72
- package/src/codex/shim-fingerprint.ts +11 -9
- package/src/codex/shim-inspect.ts +3 -2
- package/src/codex/shim-overlay.ts +22 -3
- package/src/codex/shim-restore-lock.ts +11 -14
- package/src/codex/shim-state-file.ts +22 -14
- package/src/codex/shim-templates.ts +5 -2
- package/src/codex/shim-wrapper-write.ts +137 -0
- package/src/codex/shim.ts +48 -126
- package/src/codex/transition-state.ts +5 -4
- 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 +127 -9
- package/src/combos/index.ts +1 -0
- package/src/combos/resolve.ts +60 -22
- package/src/config/atomic-write.ts +113 -29
- package/src/config/diagnostics.ts +21 -10
- package/src/config/initialize.ts +6 -6
- package/src/config/live-reconcile.ts +11 -3
- package/src/config/load-degrade.ts +2 -0
- 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 +32 -10
- package/src/config/removed-opencode-free-backup.ts +99 -0
- package/src/config/removed-opencode-free.ts +4 -8
- package/src/config/salvage.ts +2 -0
- package/src/config/schema/config-schema.ts +44 -1
- package/src/config/schema/leaf-validators.ts +22 -0
- package/src/config/schema/workflow-budget.ts +43 -0
- package/src/config/tracked-runtime-inspection.ts +188 -0
- package/src/config.ts +4 -4
- package/src/generated/compatibility-version.json +962 -434
- package/src/grok/inject.ts +2 -1
- package/src/grok/sync.ts +5 -2
- package/src/images/loop.ts +14 -5
- package/src/integrations/aside-profile-context.ts +1 -1
- package/src/integrations/catalog-refresh.ts +1 -1
- package/src/integrations/droid-settings.ts +4 -4
- package/src/integrations/hermes-profiles.ts +3 -3
- 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/bounded-file-read.ts +3 -9
- package/src/lib/bun-runtime-preflight.ts +9 -8
- 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/file-identity.ts +15 -0
- 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-chat-completion.ts +8 -6
- package/src/lib/local-destinations.ts +32 -3
- 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/redact-folding.ts +9 -0
- package/src/lib/shadow-call.ts +55 -1
- package/src/lib/spend-pool-alias-validation.ts +6 -6
- package/src/lib/state-store-registrations.ts +2 -0
- package/src/lib/test-home-guard.ts +37 -9
- 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 +328 -44
- package/src/lib/windows-service-wrappers.ts +10 -7
- package/src/lib/winsw.ts +8 -4
- package/src/lib/workflow-budget-config.ts +39 -0
- 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 +242 -0
- package/src/local-credentials/inventory.ts +405 -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/messaging/remote-forward-failure.ts +35 -0
- package/src/messaging/remote-ports.ts +27 -5
- package/src/messaging/remote-process.ts +30 -4
- package/src/messaging/remote-tunnels.ts +80 -15
- 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/antigravity-discovery-diagnostics.ts +65 -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 +49 -12
- package/src/oauth/index.ts +3 -0
- package/src/oauth/kiro-device-login.ts +87 -30
- package/src/oauth/kiro-iam-identity-center.ts +107 -0
- package/src/oauth/store.ts +41 -11
- package/src/protocols/encoders/adapter-events.ts +7 -4
- package/src/protocols/encoders/messages.ts +1 -1
- package/src/providers/account-quota-disk.ts +18 -4
- 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/cc-switch-import-bytes.ts +991 -0
- package/src/providers/cc-switch-import-source.ts +1083 -0
- package/src/providers/cc-switch-import.ts +942 -0
- package/src/providers/claude-cli-identity.ts +2 -0
- package/src/providers/codex-capacity.ts +3 -2
- package/src/providers/derive.ts +6 -0
- package/src/providers/free-directory.ts +10 -2
- package/src/providers/key-store.ts +7 -2
- package/src/providers/model-discovery-diagnostic.ts +4 -0
- package/src/providers/model-discovery.ts +4 -4
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/model-rename-migration.ts +41 -6
- package/src/providers/provider-id-rewrite.ts +3 -0
- package/src/providers/quota/antigravity.ts +6 -4
- package/src/providers/quota/report-cache.ts +17 -4
- package/src/providers/quota/vendor-probes-oauth.ts +0 -1
- package/src/providers/quota.ts +2 -2
- package/src/providers/reasoning-metadata.ts +31 -15
- package/src/providers/registry/entries-core.ts +1 -1
- package/src/providers/registry/entries-extended.ts +1 -1
- package/src/providers/registry/model-ids.ts +1 -0
- package/src/providers/registry/model-seeds.ts +2 -1
- package/src/providers/registry/types.ts +3 -1
- package/src/providers/resolved-model-policy.ts +2 -2
- package/src/providers/routed-config.ts +2 -0
- package/src/providers/stale-model-roster-migration.ts +8 -1
- package/src/providers/xai-transport.ts +4 -4
- 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/remote-control/workspace-executor.ts +14 -13
- package/src/responses/apply-patch-envelope.ts +35 -0
- package/src/responses/compaction-history-framing.ts +15 -4
- package/src/responses/custom-tool-compat.ts +2 -1
- package/src/responses/item-provenance.ts +79 -0
- package/src/responses/namespace-tool-compat.ts +21 -3
- package/src/responses/turn-membership.ts +111 -0
- package/src/router.ts +21 -2
- package/src/routing/analytics.ts +3 -5
- package/src/routing/fallback-policy.ts +7 -3
- package/src/routing/health.ts +5 -3
- package/src/routing/history/build-file.ts +6 -0
- package/src/routing/history/indexer.ts +158 -31
- package/src/routing/history/ingest.ts +1 -1
- package/src/routing/history/integrity.ts +208 -0
- package/src/routing/history/rebuild-job.ts +20 -6
- package/src/routing/history/rebuild-protocol.ts +2 -1
- package/src/routing/history/rebuild-worker.ts +18 -0
- package/src/routing/history/sqlite-errors.ts +9 -0
- package/src/server/admission-model-scope.ts +21 -4
- package/src/server/advisor-admission-scope.ts +72 -0
- package/src/server/audio-upstream.ts +10 -2
- package/src/server/auth-cors.ts +28 -2
- package/src/server/bind-host.ts +5 -0
- package/src/server/capture-admission-policy.ts +91 -0
- package/src/server/chat-completions.ts +47 -6
- package/src/server/chat-native.ts +16 -11
- package/src/server/claude-messages.ts +99 -3
- package/src/server/codex-model-list.ts +47 -0
- package/src/server/configured-credentials.ts +5 -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 +21 -45
- package/src/server/index/websocket-handler.ts +10 -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 +455 -549
- 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 +80 -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/codex-role-auto-assign.ts +50 -6
- package/src/server/management/config-routes.ts +459 -384
- package/src/server/management/consent-session.ts +6 -0
- package/src/server/management/context.ts +3 -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 +112 -38
- package/src/server/management/oauth-account-routes.ts +28 -11
- package/src/server/management/provider-overwrite-carry.ts +21 -0
- package/src/server/management/provider-routes.ts +3 -1
- package/src/server/management/route-registry.ts +10 -3
- package/src/server/management/session-routes.ts +20 -2
- package/src/server/management/shadow-call-validation.ts +43 -2
- package/src/server/management/shared.ts +17 -1
- package/src/server/management/sidebar-routes.ts +2 -1
- package/src/server/management/system-restart.ts +47 -7
- package/src/server/management/workflow-budget-routes.ts +70 -3
- package/src/server/management-api.ts +61 -51
- package/src/server/management-auth.ts +11 -3
- package/src/server/messages-native-eligibility.ts +6 -5
- package/src/server/messages-native-scope.ts +6 -1
- package/src/server/messages-native.ts +21 -7
- package/src/server/messages-shared.ts +161 -29
- 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/request-log.ts +30 -2
- 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 +24 -5
- package/src/server/responses/adapter-dispatch.ts +39 -45
- package/src/server/responses/advisor-plan-slot.ts +7 -0
- package/src/server/responses/advisor-slot.ts +77 -48
- 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/codex-auth-error.ts +5 -1
- package/src/server/responses/combo-required-tool-contract.ts +29 -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 +18 -8
- 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 +13 -6
- package/src/server/responses/core-combo-native.ts +6 -5
- package/src/server/responses/core-combo.ts +159 -25
- package/src/server/responses/core-lifetime.ts +4 -0
- package/src/server/responses/core-options.ts +16 -0
- package/src/server/responses/core.ts +2 -0
- package/src/server/responses/fetch-helpers.ts +5 -1
- package/src/server/responses/jev-model-invoke.ts +10 -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 +17 -16
- package/src/server/responses/policy-fallback.ts +2 -0
- package/src/server/responses/request-prepare.ts +14 -6
- package/src/server/responses/request-send-budget.ts +2 -1
- package/src/server/responses/request-sidecar-auth.ts +1 -0
- package/src/server/responses/request-transport.ts +43 -9
- package/src/server/responses/run-turn-execution.ts +15 -3
- package/src/server/responses/sidecar-execution.ts +26 -5
- 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/responses-snapshot-repair.ts +18 -4
- package/src/server/responses-undeclared-tool-guard.ts +4 -0
- 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/server/workflow-refusal.ts +2 -1
- package/src/service/desktop-recovery-process.ts +341 -0
- package/src/service/desktop-recovery.ts +172 -0
- package/src/service/state-lock.ts +12 -11
- package/src/service/windows-ops.ts +6 -3
- package/src/service/windows-scheduler.ts +29 -6
- package/src/service-manager-probe.ts +53 -8
- package/src/stall-timeout.ts +47 -0
- package/src/tray/windows.ts +6 -4
- package/src/types/admission-policy.ts +13 -0
- package/src/types/config.ts +86 -10
- package/src/types/provider.ts +10 -0
- package/src/types/request.ts +8 -1
- package/src/types.ts +2 -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 +199 -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 +74 -4
- package/src/usage/log.ts +25 -4
- package/src/vision/anthropic-describe.ts +2 -1
- package/src/vision/index.ts +2 -0
- package/src/vision/plan.ts +4 -0
- package/src/vision/routed-describe.ts +38 -23
- 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 +113 -12
- package/src/web-search/parse.ts +201 -40
- package/gui/dist/assets/App-CizjBqyk.js +0 -58
- package/gui/dist/assets/App-DMps4OLk.css +0 -1
- 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
- package/gui/dist/assets/quota-summary-BXu4zE8H.js +0 -1
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import { watch, lstatSync, readdirSync, type FSWatcher } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve, parse } from "node:path";
|
|
3
|
+
import { getConfigDir } from "../config/paths";
|
|
4
|
+
import { readUnderCredentialPublicationFence } from "./publication-fence";
|
|
5
|
+
import { getCodexHome } from "../codex/paths";
|
|
6
|
+
import { readBounded, nativeProfileHomeId, countLocalNativeProfileSlots } from "../codex/native-profile-store";
|
|
7
|
+
import { countLocalOAuthCredentialSlots } from "../oauth/store";
|
|
8
|
+
import { inspectLocalCodexCredentialSlots } from "../codex/account-store";
|
|
9
|
+
import {
|
|
10
|
+
claimCredentialObservation, generationToken, observationAlive, readCredentialGeneration,
|
|
11
|
+
registerCredentialObserver, updateCredentialObservation,
|
|
12
|
+
} from "./generation";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This installation's stored provider credentials, counted passively: OAuth accounts (with the
|
|
16
|
+
* pre-multiauth backup), provider API-key slots including disabled and private references, Codex
|
|
17
|
+
* pool records, native Codex auth and inactive native profiles. Link, management and incoming API
|
|
18
|
+
* keys are not provider credentials and never count. Any unreadable or unfamiliar source throws,
|
|
19
|
+
* so a caller omits the attestation instead of reporting zero.
|
|
20
|
+
*/
|
|
21
|
+
export type LocalCredentialSnapshot = { count: number; generation: string };
|
|
22
|
+
const RECONCILE_RETRIES = 20;
|
|
23
|
+
const RECONCILE_RETRY_MS = 100;
|
|
24
|
+
const FENCED_READ_ATTEMPTS = 40;
|
|
25
|
+
const FENCED_READ_RETRY_MS = 50;
|
|
26
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
27
|
+
const MAX_BYTES = 4 * 1024 * 1024;
|
|
28
|
+
function object(value: unknown): Record<string, unknown> {
|
|
29
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid credential object");
|
|
30
|
+
return value as Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
function missing(error: unknown): boolean { return (error as NodeJS.ErrnoException)?.code === "ENOENT"; }
|
|
33
|
+
function exists(path: string): boolean {
|
|
34
|
+
try { lstatSync(path); return true; } catch (error) { if (missing(error)) return false; throw error; }
|
|
35
|
+
}
|
|
36
|
+
function assertParents(path: string): void {
|
|
37
|
+
for (let p = dirname(path); ; p = dirname(p)) {
|
|
38
|
+
try { const s = lstatSync(p); if (!s.isDirectory() || s.isSymbolicLink()) throw new Error("Unsafe credential parent"); }
|
|
39
|
+
catch (error) { if (!missing(error)) throw error; }
|
|
40
|
+
if (p === parse(p).root) break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Watch classification for one parent directory, per basenames seen there. */
|
|
44
|
+
export type WatchEntry = {
|
|
45
|
+
/**
|
|
46
|
+
* Basenames that are coverage targets themselves: a file whose bytes are scanned or a
|
|
47
|
+
* directory whose whole listing is checked. Every event on these is coverage-relevant
|
|
48
|
+
* -- an in-place content change reconciles exactly like a rename, even when the scan
|
|
49
|
+
* vector ends up identical, because the advance is what proves the observation ran.
|
|
50
|
+
*/
|
|
51
|
+
names: Set<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Basenames watched only as ancestors of a deeper target, paired with the identity
|
|
54
|
+
* recorded at install. A "rename" always reconciles: a replacement is the signal these
|
|
55
|
+
* entries exist to catch. A "change" reconciles too unless the entry re-identifies as
|
|
56
|
+
* the same real directory -- on Windows a directory entry reports "change" whenever a
|
|
57
|
+
* child is added or removed, so this observer's own local-credentials.json save would
|
|
58
|
+
* otherwise re-arm the same reconcile forever. null means the ancestor could not be
|
|
59
|
+
* identified at install, and an unverifiable ancestor reconciles on any event.
|
|
60
|
+
*/
|
|
61
|
+
ancestors: Map<string, { dev: bigint; ino: bigint } | null>;
|
|
62
|
+
/**
|
|
63
|
+
* Identity of each target name at install (watchEntryIdentity). An unmatched 8.3 short
|
|
64
|
+
* name is resolved against these: it reconciles when a target here changed or when the
|
|
65
|
+
* alias is a target. Absent means the entry is treated as unresolvable and reconciles.
|
|
66
|
+
*/
|
|
67
|
+
targetIdentities?: Map<string, string>;
|
|
68
|
+
};
|
|
69
|
+
const CREDENTIAL_TMP_NAME = /^(auth|config|codex-accounts)\.json\.ocx\./i;
|
|
70
|
+
/**
|
|
71
|
+
* Watcher names are compared the way a case-insensitive volume resolves them. Windows and
|
|
72
|
+
* default macOS volumes report a notification under the spelling the writer used, so a
|
|
73
|
+
* credential created as AUTH.JSON reaches the watcher under that name while the scan reads
|
|
74
|
+
* it as auth.json. Folding can only add reconciles on a case-sensitive volume, never drop one.
|
|
75
|
+
*/
|
|
76
|
+
function foldWatchName(name: string): string {
|
|
77
|
+
return name.toLowerCase().replace(/[. ]+$/, "");
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* An 8.3 short name (AUTH~1.JSO, OPENC~1) cannot be mapped back to its long name by
|
|
81
|
+
* spelling; it is resolved by identity instead (see shortNameAction).
|
|
82
|
+
*/
|
|
83
|
+
const SHORT_NAME_ALIAS = /~\d/;
|
|
84
|
+
/** "<dev>:<ino>", "absent", or "unreadable" for one entry of a watched parent. */
|
|
85
|
+
export function watchEntryIdentity(parent: string, child: string): string {
|
|
86
|
+
try {
|
|
87
|
+
const stat = lstatSync(join(parent, child), { bigint: true });
|
|
88
|
+
return `${stat.dev}:${stat.ino}`;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
return (error as NodeJS.ErrnoException).code === "ENOENT" ? "absent" : "unreadable";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Windows may report either name of an entry that has both, and a removed entry's short
|
|
95
|
+
* name can no longer be looked up. Such an event is coverage-relevant when a target or
|
|
96
|
+
* ancestor in this parent no longer has its install identity, or when the alias resolves to
|
|
97
|
+
* a target; a change that resolves to a tracked ancestor is that ancestor's tick. Anything
|
|
98
|
+
* else -- this observer's own metadata save under a short spelling -- changed no target.
|
|
99
|
+
*/
|
|
100
|
+
function shortNameAction(parent: string, entry: WatchEntry, event: string, name: string): WatchEventAction {
|
|
101
|
+
const recorded = entry.targetIdentities;
|
|
102
|
+
if (!recorded) return "reconcile";
|
|
103
|
+
const resolved = watchEntryIdentity(parent, name);
|
|
104
|
+
if (resolved === "unreadable") return "reconcile";
|
|
105
|
+
for (const [target, identity] of recorded) {
|
|
106
|
+
const now = watchEntryIdentity(parent, target);
|
|
107
|
+
if (now === "unreadable" || now !== identity) return "reconcile";
|
|
108
|
+
if (resolved !== "absent" && resolved === now) return "reconcile";
|
|
109
|
+
}
|
|
110
|
+
let aliasOfAncestor = false;
|
|
111
|
+
for (const [ancestorName, identity] of entry.ancestors) {
|
|
112
|
+
const now = ancestorIdentity(parent, ancestorName);
|
|
113
|
+
if (identity === null || now === null || now.dev !== identity.dev || now.ino !== identity.ino) return "reconcile";
|
|
114
|
+
if (resolved === `${identity.dev}:${identity.ino}`) aliasOfAncestor = true;
|
|
115
|
+
}
|
|
116
|
+
return aliasOfAncestor && event !== "change" ? "reconcile" : "ignore";
|
|
117
|
+
}
|
|
118
|
+
function foldedLookup<T>(keys: Iterable<T>, key: (item: T) => string, folded: string): T | undefined {
|
|
119
|
+
for (const item of keys) if (foldWatchName(key(item)) === folded) return item;
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
function ancestorIdentity(parent: string, child: string): { dev: bigint; ino: bigint } | null {
|
|
123
|
+
try {
|
|
124
|
+
const stat = lstatSync(join(parent, child), { bigint: true });
|
|
125
|
+
return stat.isDirectory() && !stat.isSymbolicLink() ? { dev: stat.dev, ino: stat.ino } : null;
|
|
126
|
+
} catch { return null; }
|
|
127
|
+
}
|
|
128
|
+
type WatchEventAction = "fail" | "reconcile" | "ignore";
|
|
129
|
+
/**
|
|
130
|
+
* The single (parent, event, name) decision behind the observation watchers, exported so
|
|
131
|
+
* tests can pin every branch without timing-dependent filesystem notifications.
|
|
132
|
+
*/
|
|
133
|
+
export function credentialWatchEventAction(
|
|
134
|
+
parent: string, entry: WatchEntry, event: string, name: string | null,
|
|
135
|
+
): WatchEventAction {
|
|
136
|
+
if (name === null) return "fail";
|
|
137
|
+
const folded = foldWatchName(name);
|
|
138
|
+
if (foldedLookup(entry.names, n => n, folded) !== undefined) return "reconcile";
|
|
139
|
+
const match = foldedLookup(entry.ancestors.entries(), ([n]) => n, folded);
|
|
140
|
+
// A known ancestor whose real name merely looks like write residue or a short name
|
|
141
|
+
// (C:\config.json.ocx.home, C:\ocx~1) goes through the identity check below.
|
|
142
|
+
if (match === undefined) {
|
|
143
|
+
if (CREDENTIAL_TMP_NAME.test(name)) return "reconcile";
|
|
144
|
+
return SHORT_NAME_ALIAS.test(name) ? shortNameAction(parent, entry, event, name) : "ignore";
|
|
145
|
+
}
|
|
146
|
+
const ancestor = match[1];
|
|
147
|
+
// Renames (create/delete/move, including a same-identity rename) are structural and
|
|
148
|
+
// always reconcile; only "change" may be child-list noise from a same-identity dir.
|
|
149
|
+
if (event !== "change" || ancestor === null) return "reconcile";
|
|
150
|
+
try {
|
|
151
|
+
const stat = lstatSync(join(parent, name), { bigint: true });
|
|
152
|
+
if (stat.isDirectory() && !stat.isSymbolicLink() && stat.dev === ancestor.dev && stat.ino === ancestor.ino) {
|
|
153
|
+
return "ignore";
|
|
154
|
+
}
|
|
155
|
+
} catch { /* an ancestor that cannot be re-identified cannot prove the tick is noise */ }
|
|
156
|
+
return "reconcile";
|
|
157
|
+
}
|
|
158
|
+
export function scanLocalCredentials(accounts: readonly string[] = []): { count: number; vector: string; targets: string[] } {
|
|
159
|
+
const home = getConfigDir();
|
|
160
|
+
const codex = getCodexHome();
|
|
161
|
+
const vector: string[] = [];
|
|
162
|
+
const targets = new Set<string>();
|
|
163
|
+
function bytes(path: string, limit = MAX_BYTES): Buffer | null {
|
|
164
|
+
path = resolve(path);
|
|
165
|
+
targets.add(path);
|
|
166
|
+
assertParents(path);
|
|
167
|
+
try {
|
|
168
|
+
const before = lstatSync(path, { bigint: true });
|
|
169
|
+
if (!before.isFile() || before.isSymbolicLink()) throw new Error("Unsafe credential file");
|
|
170
|
+
const raw = readBounded(path, limit);
|
|
171
|
+
const after = lstatSync(path, { bigint: true });
|
|
172
|
+
const identity = (s: typeof before) => `${s.dev}:${s.ino}:${s.size}:${s.mtimeNs}:${s.ctimeNs}`;
|
|
173
|
+
if (identity(before) !== identity(after)) throw new Error("Credential changed while reading");
|
|
174
|
+
vector.push(`${path}:${identity(after)}`);
|
|
175
|
+
return raw;
|
|
176
|
+
} catch (error) {
|
|
177
|
+
if (!missing(error)) throw error;
|
|
178
|
+
vector.push(`${path}:absent`);
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function json(path: string): Record<string, unknown> | null {
|
|
183
|
+
const raw = bytes(path);
|
|
184
|
+
return raw === null ? null : object(JSON.parse(decoder.decode(raw)));
|
|
185
|
+
}
|
|
186
|
+
function emptyDirectory(path: string, child?: string): void {
|
|
187
|
+
targets.add(path);
|
|
188
|
+
assertParents(path);
|
|
189
|
+
if (!exists(path)) { vector.push(`${path}:absent`); return; }
|
|
190
|
+
const s = lstatSync(path, { bigint: true });
|
|
191
|
+
if (!s.isDirectory() || s.isSymbolicLink()) throw new Error("Unsafe credential directory");
|
|
192
|
+
const names = readdirSync(path);
|
|
193
|
+
vector.push(`${path}:${s.dev}:${s.ino}:${JSON.stringify(names.sort())}`);
|
|
194
|
+
if (child !== undefined) {
|
|
195
|
+
if (names.some(name => name !== child)) throw new Error("Unknown staging home");
|
|
196
|
+
emptyDirectory(join(path, child));
|
|
197
|
+
} else if (names.length) throw new Error("Pending credential directory");
|
|
198
|
+
}
|
|
199
|
+
for (const [root, prefixes] of [
|
|
200
|
+
[home, ["auth.json.ocx.", "codex-accounts.json.ocx.", "config.json.ocx."]],
|
|
201
|
+
[codex, ["auth.json.ocx."]],
|
|
202
|
+
] as const) {
|
|
203
|
+
targets.add(join(root, "auth.json"));
|
|
204
|
+
if (exists(root) && readdirSync(root).some(name => prefixes.some(prefix => name.startsWith(prefix)))) {
|
|
205
|
+
throw new Error("Retained credential write residue");
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
let count = countLocalOAuthCredentialSlots(json(join(home, "auth.json")))
|
|
209
|
+
+ countLocalOAuthCredentialSlots(json(join(home, "auth.json.pre-multiauth")));
|
|
210
|
+
const configuredAccounts = new Set<string>();
|
|
211
|
+
const config = json(join(home, "config.json"));
|
|
212
|
+
if (config !== null) {
|
|
213
|
+
const providers = object(config.providers ?? {});
|
|
214
|
+
for (const row of Object.values(providers)) {
|
|
215
|
+
const provider = object(row);
|
|
216
|
+
const pool = provider.apiKeyPool ?? [];
|
|
217
|
+
if (!Array.isArray(pool)) throw new Error("Invalid provider pool");
|
|
218
|
+
const keys: string[] = [];
|
|
219
|
+
const ids = new Set<string>();
|
|
220
|
+
for (const value of pool) {
|
|
221
|
+
const entry = object(value);
|
|
222
|
+
if (typeof entry.id !== "string" || ids.has(entry.id) || typeof entry.key !== "string" || !entry.key) {
|
|
223
|
+
throw new Error("Invalid provider key slot");
|
|
224
|
+
}
|
|
225
|
+
ids.add(entry.id);
|
|
226
|
+
keys.push(entry.key);
|
|
227
|
+
}
|
|
228
|
+
if (provider.apiKey !== undefined) {
|
|
229
|
+
if (typeof provider.apiKey !== "string") throw new Error("Invalid provider key");
|
|
230
|
+
if (provider.apiKey && !keys.includes(provider.apiKey)) keys.push(provider.apiKey);
|
|
231
|
+
}
|
|
232
|
+
count += keys.length;
|
|
233
|
+
for (const key of keys) {
|
|
234
|
+
for (const prefix of ["keychain:", "gcp-sa:"]) if (key.startsWith(prefix)) {
|
|
235
|
+
const account = key.slice(prefix.length);
|
|
236
|
+
if (!account.trim()) throw new Error("Invalid private key reference");
|
|
237
|
+
configuredAccounts.add(account);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
count += accounts.filter(a => !configuredAccounts.has(a)).length;
|
|
243
|
+
const pool = inspectLocalCodexCredentialSlots(json(join(home, "codex-accounts.json")));
|
|
244
|
+
count += pool.count;
|
|
245
|
+
for (const path of pool.sourcePaths) if (json(path) === null) throw new Error("Missing source-backed credential");
|
|
246
|
+
|
|
247
|
+
const tomlBytes = bytes(join(codex, "config.toml"), 1024 * 1024);
|
|
248
|
+
const toml = tomlBytes === null ? {} : object(Bun.TOML.parse(decoder.decode(tomlBytes)));
|
|
249
|
+
if (toml.cli_auth_credentials_store !== undefined && toml.cli_auth_credentials_store !== "file") {
|
|
250
|
+
throw new Error("Native credential store is not file-backed");
|
|
251
|
+
}
|
|
252
|
+
for (const profile of Object.values(object(toml.profiles ?? {}))) {
|
|
253
|
+
const mode = object(profile).cli_auth_credentials_store;
|
|
254
|
+
if (mode !== undefined && mode !== "file") throw new Error("Profile credential store is not file-backed");
|
|
255
|
+
}
|
|
256
|
+
const auth = json(join(codex, "auth.json"));
|
|
257
|
+
let main = 0;
|
|
258
|
+
if (auth !== null) {
|
|
259
|
+
if (typeof auth.OPENAI_API_KEY === "string" && auth.OPENAI_API_KEY) main = 1;
|
|
260
|
+
if (auth.tokens !== undefined && auth.tokens !== null) {
|
|
261
|
+
const tokens = object(auth.tokens);
|
|
262
|
+
if (![tokens.access_token, tokens.refresh_token, tokens.id_token].some(v => typeof v === "string" && v)) {
|
|
263
|
+
throw new Error("Invalid native token envelope");
|
|
264
|
+
}
|
|
265
|
+
main = 1;
|
|
266
|
+
}
|
|
267
|
+
if (!main) throw new Error("Unsupported native auth envelope");
|
|
268
|
+
}
|
|
269
|
+
const shared = join(codex, ".opencodex-native-main-profiles");
|
|
270
|
+
const homeId = nativeProfileHomeId(codex);
|
|
271
|
+
emptyDirectory(join(home, "native-main-profiles"));
|
|
272
|
+
emptyDirectory(join(home, "native-main-profile-staging"), homeId);
|
|
273
|
+
for (const suffix of ["journal", "recovery-block"]) {
|
|
274
|
+
if (bytes(join(shared, `${homeId}.${suffix}.json`)) !== null) throw new Error("Pending native profile transaction");
|
|
275
|
+
}
|
|
276
|
+
const stages = json(join(shared, `${homeId}.stages.json`));
|
|
277
|
+
if (stages !== null && (stages.version !== 1 || stages.homeId !== homeId
|
|
278
|
+
|| !Number.isSafeInteger(stages.revision) || Number(stages.revision) < 0
|
|
279
|
+
|| !Array.isArray(stages.stages) || stages.stages.length !== 0)) throw new Error("Pending native stage registry");
|
|
280
|
+
const vault = json(join(shared, `${homeId}.vault.json`));
|
|
281
|
+
const profiles = countLocalNativeProfileSlots(vault, homeId);
|
|
282
|
+
if (profiles.active && !main) throw new Error("Active native profile has no readable auth");
|
|
283
|
+
count += main + profiles.inactive;
|
|
284
|
+
// The whole listing is verified below, so the directory itself is a coverage target:
|
|
285
|
+
// an unknown create/delete must reach a watcher even when the child's own name is not.
|
|
286
|
+
targets.add(shared);
|
|
287
|
+
assertParents(shared);
|
|
288
|
+
if (exists(shared)) {
|
|
289
|
+
if (!lstatSync(shared).isDirectory() || lstatSync(shared).isSymbolicLink()) throw new Error("Unsafe native vault");
|
|
290
|
+
const expected = new Set([`${homeId}.vault.json`, `${homeId}.stages.json`]);
|
|
291
|
+
if (readdirSync(shared).some(name => !expected.has(name))) throw new Error("Unknown native profile metadata");
|
|
292
|
+
}
|
|
293
|
+
if (!Number.isSafeInteger(count) || count < 0) throw new Error("Invalid credential count");
|
|
294
|
+
return { count, vector: JSON.stringify(vector.sort()), targets: [...targets].sort() };
|
|
295
|
+
}
|
|
296
|
+
function snapshotOnce(home: string): LocalCredentialSnapshot | undefined {
|
|
297
|
+
try {
|
|
298
|
+
const before = readCredentialGeneration(home);
|
|
299
|
+
if (!before?.coverage || before.pending.length || !observationAlive(before, home)) return undefined;
|
|
300
|
+
const snapshot = scanLocalCredentials(before.keyAccounts);
|
|
301
|
+
const after = readCredentialGeneration(home);
|
|
302
|
+
if (!after?.coverage || after.pending.length || !observationAlive(after, home)
|
|
303
|
+
|| generationToken(before) !== generationToken(after)
|
|
304
|
+
|| before.coverage.owner !== after.coverage.owner
|
|
305
|
+
|| before.coverage.vector !== snapshot.vector || after.coverage.vector !== snapshot.vector) return undefined;
|
|
306
|
+
return { count: snapshot.count, generation: generationToken(after) };
|
|
307
|
+
} catch { return undefined; }
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* The attestation for "ocx status --json". Each attempt holds the publication fence shared across
|
|
312
|
+
* both generation reads and the scan, so no instrumented write can land in between; while a
|
|
313
|
+
* publication holds it, retry briefly, then omit rather than attest a snapshot that could race.
|
|
314
|
+
*/
|
|
315
|
+
export async function collectLocalCredentials(): Promise<LocalCredentialSnapshot | undefined> {
|
|
316
|
+
const home = getConfigDir();
|
|
317
|
+
for (let attempt = 0; attempt < FENCED_READ_ATTEMPTS; attempt += 1) {
|
|
318
|
+
const read = readUnderCredentialPublicationFence(home, () => snapshotOnce(home));
|
|
319
|
+
if (read.kind === "read") return read.value;
|
|
320
|
+
if (read.kind === "unavailable") return undefined;
|
|
321
|
+
await new Promise(resolve => setTimeout(resolve, FENCED_READ_RETRY_MS));
|
|
322
|
+
}
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
export function startLocalCredentialObservation(): { stop(): void; reconcile(): void } {
|
|
326
|
+
const home = getConfigDir();
|
|
327
|
+
let watchers: FSWatcher[] = [];
|
|
328
|
+
let owner: string | undefined;
|
|
329
|
+
let releaseLease = () => {};
|
|
330
|
+
let failed = false;
|
|
331
|
+
let unregister = () => {};
|
|
332
|
+
const fail = () => {
|
|
333
|
+
if (failed) return;
|
|
334
|
+
failed = true;
|
|
335
|
+
if (retry) clearTimeout(retry);
|
|
336
|
+
unregister();
|
|
337
|
+
releaseLease();
|
|
338
|
+
for (const watcher of watchers) watcher.close();
|
|
339
|
+
if (owner) {
|
|
340
|
+
try { updateCredentialObservation(home, owner, null); }
|
|
341
|
+
catch { /* The kernel lease is already closed; a busy metadata writer cannot keep evidence alive. */ }
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
const install = (targets: string[]) => {
|
|
345
|
+
const watched = new Map<string, WatchEntry>();
|
|
346
|
+
for (const target of targets) {
|
|
347
|
+
let leaf = true;
|
|
348
|
+
for (let path = target; dirname(path) !== path; path = dirname(path)) {
|
|
349
|
+
const parent = dirname(path);
|
|
350
|
+
if (!exists(parent)) continue;
|
|
351
|
+
assertParents(path);
|
|
352
|
+
const entry = watched.get(parent) ?? { names: new Set<string>(), ancestors: new Map(), targetIdentities: new Map<string, string>() };
|
|
353
|
+
const child = path.slice(parent.length + (parent.endsWith("/") || parent.endsWith("\\") ? 0 : 1));
|
|
354
|
+
if (leaf) { entry.names.add(child); entry.targetIdentities?.set(child, watchEntryIdentity(parent, child)); }
|
|
355
|
+
else if (!entry.ancestors.has(child)) entry.ancestors.set(child, ancestorIdentity(parent, child));
|
|
356
|
+
watched.set(parent, entry);
|
|
357
|
+
leaf = false;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const next: FSWatcher[] = [];
|
|
361
|
+
try {
|
|
362
|
+
for (const [parent, entry] of watched) {
|
|
363
|
+
const watcher = watch(parent, { persistent: false }, (event, name) => {
|
|
364
|
+
const action = credentialWatchEventAction(parent, entry, event, name === null ? null : String(name));
|
|
365
|
+
if (action === "fail") fail();
|
|
366
|
+
else if (action === "reconcile") reconcile();
|
|
367
|
+
});
|
|
368
|
+
watcher.on("error", fail);
|
|
369
|
+
next.push(watcher);
|
|
370
|
+
}
|
|
371
|
+
} catch (error) { for (const watcher of next) watcher.close(); throw error; }
|
|
372
|
+
const previous = watchers;
|
|
373
|
+
watchers = next;
|
|
374
|
+
for (const watcher of previous) watcher.close();
|
|
375
|
+
};
|
|
376
|
+
const observe = (keys: readonly string[]) => {
|
|
377
|
+
const before = scanLocalCredentials(keys);
|
|
378
|
+
install(before.targets);
|
|
379
|
+
const after = scanLocalCredentials(keys);
|
|
380
|
+
if (before.vector !== after.vector || JSON.stringify(before.targets) !== JSON.stringify(after.targets)) {
|
|
381
|
+
throw new Error("Credential coverage changed during observer installation");
|
|
382
|
+
}
|
|
383
|
+
if (failed) throw new Error("Credential observation lost");
|
|
384
|
+
return after.vector;
|
|
385
|
+
};
|
|
386
|
+
let retries = 0;
|
|
387
|
+
let retry: ReturnType<typeof setTimeout> | undefined;
|
|
388
|
+
const reconcile = () => {
|
|
389
|
+
if (failed || !owner) return;
|
|
390
|
+
try { updateCredentialObservation(home, owner, observe); retries = 0; }
|
|
391
|
+
catch {
|
|
392
|
+
// A peer holding the config lock only delays this; the stale vector withholds attestation meanwhile.
|
|
393
|
+
if (++retries > RECONCILE_RETRIES) { fail(); return; }
|
|
394
|
+
retry ??= setTimeout(() => { retry = undefined; reconcile(); }, RECONCILE_RETRY_MS);
|
|
395
|
+
(retry as { unref?: () => void }).unref?.();
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
try {
|
|
399
|
+
const claim = claimCredentialObservation(home, observe);
|
|
400
|
+
owner = claim.owner;
|
|
401
|
+
releaseLease = claim.close;
|
|
402
|
+
unregister = registerCredentialObserver(home, reconcile);
|
|
403
|
+
return { stop: fail, reconcile };
|
|
404
|
+
} catch (error) { fail(); throw error; }
|
|
405
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Database } from "bun:sqlite";
|
|
2
|
+
import { chmodSync, lstatSync, mkdirSync, readdirSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { hardenSecretDir, windowsSecretAclApplies } from "../lib/windows-secret-acl";
|
|
5
|
+
import { assertNotRealHomeUnderTest } from "../lib/test-home-guard";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A per-observer SQLite file held in an exclusive transaction for the observer's lifetime. It is
|
|
9
|
+
* an OS lock that process death releases, so status can tell a live observer from surviving
|
|
10
|
+
* metadata without trusting a PID. Status opens it read-only and only an exact SQLITE_BUSY on the
|
|
11
|
+
* same file identity counts as alive.
|
|
12
|
+
*/
|
|
13
|
+
const UUID = /^[0-9a-f-]{36}$/;
|
|
14
|
+
function pathFor(home: string, owner: string): string {
|
|
15
|
+
if (!UUID.test(owner)) throw new Error("Invalid credential observer owner");
|
|
16
|
+
return join(home, "local-credential-observers", `${owner}.sqlite`);
|
|
17
|
+
}
|
|
18
|
+
function safeDirectory(path: string): void {
|
|
19
|
+
const stat = lstatSync(path);
|
|
20
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error("Unsafe credential observer directory");
|
|
21
|
+
}
|
|
22
|
+
export function acquireCredentialObservationLease(home: string, owner: string): { close(): void } {
|
|
23
|
+
assertNotRealHomeUnderTest(home);
|
|
24
|
+
safeDirectory(home);
|
|
25
|
+
const dir = join(home, "local-credential-observers");
|
|
26
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
27
|
+
safeDirectory(dir);
|
|
28
|
+
if (windowsSecretAclApplies()) hardenSecretDir(dir, { required: true });
|
|
29
|
+
else chmodSync(dir, 0o700);
|
|
30
|
+
const path = pathFor(home, owner);
|
|
31
|
+
try { lstatSync(path); throw new Error("Credential observer lease already exists"); }
|
|
32
|
+
catch (error) { if ((error as NodeJS.ErrnoException)?.code !== "ENOENT") throw error; }
|
|
33
|
+
const db = new Database(path, { create: true });
|
|
34
|
+
let held = false;
|
|
35
|
+
try {
|
|
36
|
+
if (process.platform !== "win32") chmodSync(path, 0o600);
|
|
37
|
+
db.exec("PRAGMA busy_timeout=0; PRAGMA journal_mode=DELETE; CREATE TABLE liveness (id INTEGER PRIMARY KEY)");
|
|
38
|
+
// No writes after BEGIN: process death releases the lock without a hot rollback journal.
|
|
39
|
+
db.exec("BEGIN EXCLUSIVE");
|
|
40
|
+
held = true;
|
|
41
|
+
return { close() {
|
|
42
|
+
if (!held) return;
|
|
43
|
+
held = false;
|
|
44
|
+
try { db.exec("ROLLBACK"); }
|
|
45
|
+
finally {
|
|
46
|
+
db.close();
|
|
47
|
+
try { unlinkSync(path); } catch { /* An unlocked residue never proves observer liveness. */ }
|
|
48
|
+
}
|
|
49
|
+
} };
|
|
50
|
+
} catch (error) { db.close(); throw error; }
|
|
51
|
+
}
|
|
52
|
+
export function credentialObservationLeaseAlive(home: string, owner: string): boolean {
|
|
53
|
+
let db: Database | undefined;
|
|
54
|
+
try {
|
|
55
|
+
safeDirectory(home);
|
|
56
|
+
safeDirectory(join(home, "local-credential-observers"));
|
|
57
|
+
const path = pathFor(home, owner);
|
|
58
|
+
const before = lstatSync(path, { bigint: true });
|
|
59
|
+
if (!before.isFile() || before.isSymbolicLink() || before.size > 1024n * 1024n) return false;
|
|
60
|
+
try {
|
|
61
|
+
db = new Database(path, { readonly: true });
|
|
62
|
+
db.exec("PRAGMA busy_timeout=0");
|
|
63
|
+
db.query("SELECT id FROM liveness LIMIT 1").get();
|
|
64
|
+
return false;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
const after = lstatSync(path, { bigint: true });
|
|
67
|
+
return (error as { code?: string })?.code === "SQLITE_BUSY"
|
|
68
|
+
&& before.dev === after.dev && before.ino === after.ino && after.isFile() && !after.isSymbolicLink();
|
|
69
|
+
}
|
|
70
|
+
} catch { return false; }
|
|
71
|
+
finally { db?.close(); }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Removes the leases of observers that died without closing them; callers hold the config lock. */
|
|
75
|
+
export function sweepDeadCredentialObservationLeases(home: string, keep: string): void {
|
|
76
|
+
let names: string[];
|
|
77
|
+
try { names = readdirSync(join(home, "local-credential-observers")); } catch { return; }
|
|
78
|
+
for (const name of names) {
|
|
79
|
+
const owner = name.endsWith(".sqlite") ? name.slice(0, -".sqlite".length) : "";
|
|
80
|
+
if (!UUID.test(owner) || owner === keep || credentialObservationLeaseAlive(home, owner)) continue;
|
|
81
|
+
try { unlinkSync(pathFor(home, owner)); } catch { /* a lease that cannot be removed proves nothing either */ }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Database } from "bun:sqlite";
|
|
2
|
+
import { chmodSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { recordOwnedConfigPath } from "../lib/config-ownership";
|
|
5
|
+
import { assertNotRealHomeUnderTest } from "../lib/test-home-guard";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The credential-publication fence: the OS lock of one small SQLite file, separate from the config
|
|
9
|
+
* mutation lock. Instrumented credential writers hold it EXCLUSIVE across their ticket, the
|
|
10
|
+
* credential write and the ticket's close; `ocx status` holds it SHARED across its generation
|
|
11
|
+
* reads and source scan, so a snapshot can never interleave with a publication. Nothing is written
|
|
12
|
+
* inside the transaction, so process death releases the lock without a hot journal. Holding is
|
|
13
|
+
* reentrant per process and per home, which also covers an async publication that awaits inside it.
|
|
14
|
+
*/
|
|
15
|
+
export const CREDENTIAL_FENCE_FILENAME = "local-credential-publication.sqlite";
|
|
16
|
+
/** How long a writer waits for readers and other writers; a reader never waits inside SQLite. */
|
|
17
|
+
export const CREDENTIAL_FENCE_WRITER_WAIT_MS = 10_000;
|
|
18
|
+
|
|
19
|
+
const held = new Map<string, { db: Database; holders: number }>();
|
|
20
|
+
|
|
21
|
+
function acquire(home: string, waitMs: number): () => void {
|
|
22
|
+
const current = held.get(home);
|
|
23
|
+
if (current) current.holders += 1;
|
|
24
|
+
else {
|
|
25
|
+
assertNotRealHomeUnderTest(home);
|
|
26
|
+
const path = join(home, CREDENTIAL_FENCE_FILENAME);
|
|
27
|
+
recordOwnedConfigPath(home, path);
|
|
28
|
+
const db = new Database(path, { create: true });
|
|
29
|
+
try {
|
|
30
|
+
if (process.platform !== "win32") chmodSync(path, 0o600);
|
|
31
|
+
db.exec(`PRAGMA busy_timeout=${Math.max(0, Math.floor(waitMs))}; PRAGMA journal_mode=DELETE; CREATE TABLE IF NOT EXISTS fence (id INTEGER PRIMARY KEY)`);
|
|
32
|
+
db.exec("BEGIN EXCLUSIVE");
|
|
33
|
+
} catch (error) { db.close(); throw error; }
|
|
34
|
+
held.set(home, { db, holders: 1 });
|
|
35
|
+
}
|
|
36
|
+
let released = false;
|
|
37
|
+
return () => {
|
|
38
|
+
if (released) return;
|
|
39
|
+
released = true;
|
|
40
|
+
const entry = held.get(home);
|
|
41
|
+
if (!entry || --entry.holders > 0) return;
|
|
42
|
+
held.delete(home);
|
|
43
|
+
try { entry.db.exec("ROLLBACK"); } catch { /* close below releases the lock */ }
|
|
44
|
+
entry.db.close();
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function withCredentialPublicationFence<T>(home: string, fn: () => T, waitMs = CREDENTIAL_FENCE_WRITER_WAIT_MS): T {
|
|
49
|
+
const release = acquire(home, waitMs);
|
|
50
|
+
try { return fn(); } finally { release(); }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function withCredentialPublicationFenceAsync<T>(home: string, fn: () => Promise<T>): Promise<T> {
|
|
54
|
+
const release = acquire(home, CREDENTIAL_FENCE_WRITER_WAIT_MS);
|
|
55
|
+
try { return await fn(); } finally { release(); }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type FencedRead<T> = { kind: "read"; value: T } | { kind: "busy" } | { kind: "unavailable" };
|
|
59
|
+
|
|
60
|
+
/** One consistent read with no publication in flight; never creates the fence or waits. */
|
|
61
|
+
export function readUnderCredentialPublicationFence<T>(home: string, fn: () => T): FencedRead<T> {
|
|
62
|
+
if (held.has(home)) return { kind: "busy" };
|
|
63
|
+
let db: Database;
|
|
64
|
+
try { db = new Database(join(home, CREDENTIAL_FENCE_FILENAME), { readonly: true }); }
|
|
65
|
+
catch { return { kind: "unavailable" }; }
|
|
66
|
+
let open = false;
|
|
67
|
+
try {
|
|
68
|
+
db.exec("PRAGMA busy_timeout=0");
|
|
69
|
+
db.exec("BEGIN");
|
|
70
|
+
open = true;
|
|
71
|
+
try { db.query("SELECT count(*) FROM sqlite_master").get(); }
|
|
72
|
+
catch (error) {
|
|
73
|
+
return String((error as { code?: unknown })?.code ?? "").startsWith("SQLITE_BUSY") ? { kind: "busy" } : { kind: "unavailable" };
|
|
74
|
+
}
|
|
75
|
+
return { kind: "read", value: fn() };
|
|
76
|
+
} catch { return { kind: "unavailable" }; }
|
|
77
|
+
finally {
|
|
78
|
+
if (open) { try { db.exec("COMMIT"); } catch { /* close below releases the shared lock */ } }
|
|
79
|
+
db.close();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { readBoundedRegularFileSync } from "../lib/bounded-file-read";
|
|
3
|
+
|
|
4
|
+
const OS_STORE_PREFIXES = ["keychain:", "gcp-sa:"] as const;
|
|
5
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The OS credential-store accounts a config document references: `keychain:<account>` API keys and
|
|
9
|
+
* `gcp-sa:<account>` service-account JSON, as the active key or a pool entry. These accounts are
|
|
10
|
+
* registered in local-credentials.json before a reference can leave the config, so a secret whose
|
|
11
|
+
* deletion fails or never happens keeps counting after its config slot is gone.
|
|
12
|
+
*/
|
|
13
|
+
export function osStoreAccounts(config: unknown): string[] {
|
|
14
|
+
const accounts = new Set<string>();
|
|
15
|
+
const providers = config && typeof config === "object" ? (config as { providers?: unknown }).providers : undefined;
|
|
16
|
+
if (!providers || typeof providers !== "object") return [];
|
|
17
|
+
for (const row of Object.values(providers)) {
|
|
18
|
+
if (!row || typeof row !== "object") continue;
|
|
19
|
+
const provider = row as { apiKey?: unknown; apiKeyPool?: unknown };
|
|
20
|
+
const pool = Array.isArray(provider.apiKeyPool) ? provider.apiKeyPool : [];
|
|
21
|
+
for (const key of [provider.apiKey, ...pool.map(entry => entry && typeof entry === "object" ? (entry as { key?: unknown }).key : undefined)]) {
|
|
22
|
+
if (typeof key !== "string") continue;
|
|
23
|
+
for (const prefix of OS_STORE_PREFIXES) {
|
|
24
|
+
const account = key.startsWith(prefix) ? key.slice(prefix.length) : "";
|
|
25
|
+
if (account.trim() && account.length <= 1024) accounts.add(account);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return [...accounts];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The references in this home's config.json; an absent or unreadable file names none. */
|
|
33
|
+
export function configuredOsStoreAccounts(home: string): string[] {
|
|
34
|
+
try { return osStoreAccounts(JSON.parse(decoder.decode(readBoundedRegularFileSync(join(home, "config.json"), 4 * 1024 * 1024)))); }
|
|
35
|
+
catch { return []; }
|
|
36
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { startLocalCredentialObservation } from "./inventory";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The one way a runtime owns the local-credential observer. `ocx status` attests only while the
|
|
5
|
+
* runtime holding the observer's OS lease lives, so each runtime stops it before it stops serving:
|
|
6
|
+
* a replacement process can then claim its own. A failure leaves the attestation omitted.
|
|
7
|
+
*/
|
|
8
|
+
export function observeLocalCredentials(): { stop(): void } {
|
|
9
|
+
try { return startLocalCredentialObservation(); }
|
|
10
|
+
catch { return { stop() {} }; }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Starts the observer before a server, and stops it with that server or its failed start. */
|
|
14
|
+
export function withLocalCredentialObservation<S extends { stop(closeActiveConnections?: boolean): Promise<void> }>(start: () => S): S {
|
|
15
|
+
const observation = observeLocalCredentials();
|
|
16
|
+
let server: S;
|
|
17
|
+
try { server = start(); }
|
|
18
|
+
catch (error) { observation.stop(); throw error; }
|
|
19
|
+
const stop = server.stop.bind(server);
|
|
20
|
+
Object.defineProperty(server, "stop", {
|
|
21
|
+
configurable: true,
|
|
22
|
+
value: async (closeActiveConnections?: boolean): Promise<void> => {
|
|
23
|
+
observation.stop();
|
|
24
|
+
await stop(closeActiveConnections);
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return server;
|
|
28
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Match fixed SSH bind-failure tokens without retaining any diagnostic bytes. */
|
|
2
|
+
export function remoteForwardFailure(argv: readonly string[], onReady: () => void) {
|
|
3
|
+
const direction = argv.includes("-L") ? "L" : "R";
|
|
4
|
+
const index = argv.indexOf(`-${direction}`), port = argv[index + 1]?.split(":")[1];
|
|
5
|
+
const enabled = index >= 0 && argv.includes("ExitOnForwardFailure=yes") && /^\d+$/.test(port ?? "");
|
|
6
|
+
const failures = !enabled ? []
|
|
7
|
+
: direction === "L" ? ["Could not request local forwarding."]
|
|
8
|
+
: [`remote port forwarding failed for listen port ${port}\r`, `remote port forwarding failed for listen port ${port}\n`];
|
|
9
|
+
const target = argv[index + 1]?.split(":").slice(2).join(":");
|
|
10
|
+
// OpenSSH emits the local-listening announcement BEFORE bind(), so it is not a success receipt.
|
|
11
|
+
const success = direction === "L" ? "debug1: Entering interactive session."
|
|
12
|
+
: `debug1: remote forward success for: listen 127.0.0.1:${port}, connect ${target}`;
|
|
13
|
+
const successes = !enabled ? [] : [`${success}\r`, `${success}\n`];
|
|
14
|
+
const matches = [...failures, ...successes].map((token, index) => {
|
|
15
|
+
const bytes = new TextEncoder().encode(token), prefixes = new Uint32Array(bytes.length);
|
|
16
|
+
for (let i = 1, length = 0; i < bytes.length; i++) {
|
|
17
|
+
while (length && bytes[i] !== bytes[length]) length = prefixes[length - 1]!;
|
|
18
|
+
if (bytes[i] === bytes[length]) length++;
|
|
19
|
+
prefixes[i] = length;
|
|
20
|
+
}
|
|
21
|
+
return { bytes, prefixes, length: 0, success: index >= failures.length };
|
|
22
|
+
});
|
|
23
|
+
let failed = false, ready = false;
|
|
24
|
+
return { enabled, get failed() { return failed; }, get ready() { return ready; }, write(chunk: Uint8Array) {
|
|
25
|
+
if (!enabled || failed || ready) return;
|
|
26
|
+
for (const byte of chunk) for (const match of matches) {
|
|
27
|
+
while (match.length && byte !== match.bytes[match.length]) match.length = match.prefixes[match.length - 1]!;
|
|
28
|
+
if (byte === match.bytes[match.length]) match.length++;
|
|
29
|
+
if (match.length === match.bytes.length) {
|
|
30
|
+
if (match.success) { ready = true; onReady(); } else failed = true;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} };
|
|
35
|
+
}
|