@code-yeongyu/senpi 2026.9.10 → 2026.9.11
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/CHANGELOG.md +83 -0
- package/dist/core/agent-session.d.ts +57 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +130 -20
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +2 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +49 -17
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/brand.d.ts +5 -0
- package/dist/core/brand.d.ts.map +1 -1
- package/dist/core/brand.js +13 -0
- package/dist/core/brand.js.map +1 -1
- package/dist/core/changelog-source.d.ts +8 -0
- package/dist/core/changelog-source.d.ts.map +1 -0
- package/dist/core/changelog-source.js +19 -0
- package/dist/core/changelog-source.js.map +1 -0
- package/dist/core/credential-accounts.d.ts +3 -0
- package/dist/core/credential-accounts.d.ts.map +1 -1
- package/dist/core/credential-accounts.js +20 -1
- package/dist/core/credential-accounts.js.map +1 -1
- package/dist/core/credential-pool/classify.d.ts.map +1 -1
- package/dist/core/credential-pool/classify.js +8 -0
- package/dist/core/credential-pool/classify.js.map +1 -1
- package/dist/core/extensions/builtin/account/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/account/index.js +7 -3
- package/dist/core/extensions/builtin/account/index.js.map +1 -1
- package/dist/core/extensions/builtin/account-display-name.d.ts +7 -0
- package/dist/core/extensions/builtin/account-display-name.d.ts.map +1 -0
- package/dist/core/extensions/builtin/account-display-name.js +40 -0
- package/dist/core/extensions/builtin/account-display-name.js.map +1 -0
- package/dist/core/extensions/builtin/ask-user/format.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ask-user/format.js +7 -2
- package/dist/core/extensions/builtin/ask-user/format.js.map +1 -1
- package/dist/core/extensions/builtin/ask-user/pending.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ask-user/pending.js +3 -0
- package/dist/core/extensions/builtin/ask-user/pending.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.js +21 -9
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-management.d.ts +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-management.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-management.js +11 -6
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-management.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/accounts.d.ts +9 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/accounts.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/accounts.js +10 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/accounts.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js +3 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js +19 -10
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/settings.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/settings.js +3 -9
- package/dist/core/extensions/builtin/claude-sdk-oauth/settings.js.map +1 -1
- package/dist/core/extensions/builtin/config-reload/routine-settings.d.ts.map +1 -1
- package/dist/core/extensions/builtin/config-reload/routine-settings.js +1 -0
- package/dist/core/extensions/builtin/config-reload/routine-settings.js.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.d.ts.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.js +5 -3
- package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.js.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/accounts.d.ts +1 -0
- package/dist/core/extensions/builtin/cursor-cli-oauth/accounts.d.ts.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/accounts.js.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/settings.d.ts.map +1 -1
- package/dist/core/extensions/builtin/cursor-cli-oauth/settings.js +3 -9
- package/dist/core/extensions/builtin/cursor-cli-oauth/settings.js.map +1 -1
- package/dist/core/extensions/builtin/goal/agent-end-continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/agent-end-continuation.js +13 -1
- package/dist/core/extensions/builtin/goal/agent-end-continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/prompt.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/prompt.js +11 -8
- package/dist/core/extensions/builtin/goal/prompt.js.map +1 -1
- package/dist/core/extensions/builtin/goal/terminal-provider-error.d.ts +1 -0
- package/dist/core/extensions/builtin/goal/terminal-provider-error.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/terminal-provider-error.js +28 -0
- package/dist/core/extensions/builtin/goal/terminal-provider-error.js.map +1 -1
- package/dist/core/extensions/builtin/goal/todo-gate.js +2 -2
- package/dist/core/extensions/builtin/goal/todo-gate.js.map +1 -1
- package/dist/core/extensions/builtin/goal/tool-registration.js +2 -2
- package/dist/core/extensions/builtin/goal/tool-registration.js.map +1 -1
- package/dist/core/extensions/builtin/gpt-account.d.ts.map +1 -1
- package/dist/core/extensions/builtin/gpt-account.js +19 -8
- package/dist/core/extensions/builtin/gpt-account.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/deepseek-v4-1-flash.d.ts +3 -0
- package/dist/core/extensions/builtin/prompt-preset/deepseek-v4-1-flash.d.ts.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/deepseek-v4-1-flash.js +19 -0
- package/dist/core/extensions/builtin/prompt-preset/deepseek-v4-1-flash.js.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts +6 -6
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js +26 -7
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.js +29 -0
- package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/settings.d.ts +1 -1
- package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/settings.js +1 -0
- package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
- package/dist/core/high-reasoning-warning.d.ts.map +1 -1
- package/dist/core/high-reasoning-warning.js +5 -1
- package/dist/core/high-reasoning-warning.js.map +1 -1
- package/dist/core/manual-continue.d.ts +14 -0
- package/dist/core/manual-continue.d.ts.map +1 -1
- package/dist/core/manual-continue.js +13 -0
- package/dist/core/manual-continue.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +2 -2
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/remote-catalog-merge.d.ts +16 -0
- package/dist/core/remote-catalog-merge.d.ts.map +1 -0
- package/dist/core/remote-catalog-merge.js +75 -0
- package/dist/core/remote-catalog-merge.js.map +1 -0
- package/dist/core/remote-catalog-provider.d.ts +3 -0
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +12 -40
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/session-entry-materializer.d.ts +12 -0
- package/dist/core/session-entry-materializer.d.ts.map +1 -0
- package/dist/core/session-entry-materializer.js +26 -0
- package/dist/core/session-entry-materializer.js.map +1 -0
- package/dist/core/session-manager.d.ts +36 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +38 -8
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +3 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +10 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/modes/app-server/daemon/process.d.ts +6 -1
- package/dist/modes/app-server/daemon/process.d.ts.map +1 -1
- package/dist/modes/app-server/daemon/process.js +23 -4
- package/dist/modes/app-server/daemon/process.js.map +1 -1
- package/dist/modes/app-server/protocol/account.d.ts +2 -0
- package/dist/modes/app-server/protocol/account.d.ts.map +1 -1
- package/dist/modes/app-server/protocol/account.js.map +1 -1
- package/dist/modes/interactive/components/ask-user-question-keys.d.ts +1 -1
- package/dist/modes/interactive/components/ask-user-question-keys.d.ts.map +1 -1
- package/dist/modes/interactive/components/ask-user-question-keys.js +65 -17
- package/dist/modes/interactive/components/ask-user-question-keys.js.map +1 -1
- package/dist/modes/interactive/components/ask-user-question-render.d.ts +2 -1
- package/dist/modes/interactive/components/ask-user-question-render.d.ts.map +1 -1
- package/dist/modes/interactive/components/ask-user-question-render.js +39 -9
- package/dist/modes/interactive/components/ask-user-question-render.js.map +1 -1
- package/dist/modes/interactive/components/ask-user-question-state.d.ts +14 -4
- package/dist/modes/interactive/components/ask-user-question-state.d.ts.map +1 -1
- package/dist/modes/interactive/components/ask-user-question-state.js +63 -6
- package/dist/modes/interactive/components/ask-user-question-state.js.map +1 -1
- package/dist/modes/interactive/components/ask-user-question.d.ts +2 -0
- package/dist/modes/interactive/components/ask-user-question.d.ts.map +1 -1
- package/dist/modes/interactive/components/ask-user-question.js +27 -14
- package/dist/modes/interactive/components/ask-user-question.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +51 -19
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +11 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +29 -9
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +7 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/help-content.d.ts.map +1 -1
- package/dist/modes/interactive/help-content.js +4 -0
- package/dist/modes/interactive/help-content.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +13 -4
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +44 -15
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/tips/catalog/input-tips.js +1 -1
- package/dist/modes/interactive/tips/catalog/input-tips.js.map +1 -1
- package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
- package/dist/modes/rpc/connection-handler.js +3 -1
- package/dist/modes/rpc/connection-handler.js.map +1 -1
- package/dist/modes/rpc/connection-question-bridge.js +1 -1
- package/dist/modes/rpc/connection-question-bridge.js.map +1 -1
- package/dist/modes/rpc/host-ensure.d.ts.map +1 -1
- package/dist/modes/rpc/host-ensure.js +33 -11
- package/dist/modes/rpc/host-ensure.js.map +1 -1
- package/dist/modes/rpc/host-lifecycle.d.ts +14 -0
- package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -1
- package/dist/modes/rpc/host-lifecycle.js +31 -5
- package/dist/modes/rpc/host-lifecycle.js.map +1 -1
- package/dist/modes/rpc/rpc-input-validation.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-input-validation.js +2 -0
- package/dist/modes/rpc/rpc-input-validation.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +2 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/changelog.d.ts +3 -1
- package/dist/utils/changelog.d.ts.map +1 -1
- package/dist/utils/changelog.js +89 -23
- package/dist/utils/changelog.js.map +1 -1
- package/dist/utils/paths.d.ts +5 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +14 -1
- package/dist/utils/paths.js.map +1 -1
- package/docs/app-server.md +6 -0
- package/docs/extensions.md +19 -3
- package/docs/rpc.md +10 -0
- package/docs/settings.md +2 -1
- package/docs/tui.md +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +28 -0
- package/node_modules/@code-yeongyu/senpi-codemode/README.md +5 -4
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/output/streaming-output-buffer.ts +58 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/output/streaming-output.ts +9 -64
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt-template.ts +1 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/discovery.d.ts +17 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/discovery.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/discovery.js +90 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/discovery.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/frames.d.ts +23 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/frames.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/frames.js +71 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/frames.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/gen/cascade_pb.d.ts +873 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/gen/cascade_pb.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/gen/cascade_pb.js +303 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/gen/cascade_pb.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/metadata.d.ts +12 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/metadata.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/metadata.js +35 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/metadata.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/paths.d.ts +23 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/paths.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/paths.js +23 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/paths.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/request.d.ts +24 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/request.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/request.js +116 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/request.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/stream-state.d.ts +20 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/stream-state.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/stream-state.js +153 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/stream-state.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/types.d.ts +12 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/types.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/types.js +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/types.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/wire.d.ts +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/wire.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/wire.js +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/wire.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.d.ts +14 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.js +162 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.lazy.d.ts +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.lazy.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.lazy.js +23 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.lazy.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-callback.d.ts +25 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-callback.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-callback.js +124 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-callback.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-token.d.ts +18 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-token.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-token.js +101 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-token.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin.d.ts +14 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin.js +111 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js +5 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-identity.d.ts +24 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-identity.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-identity.js +86 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-identity.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.d.ts +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts +51 -4
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js +196 -7
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts +8 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +10 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts +9 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/compat.js +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/compat.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +4 -4
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.d.ts +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.js +14 -5
- package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.js +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opengateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/venice.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/devin.d.ts +12 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/devin.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/devin.js +62 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/devin.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/devin.models.d.ts +10 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/devin.models.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/devin.models.js +28 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/devin.models.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +3 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/dollar-invocation-autocomplete.d.ts +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/dollar-invocation-autocomplete.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/dollar-invocation-autocomplete.js +55 -16
- package/node_modules/@earendil-works/pi-tui/dist/dollar-invocation-autocomplete.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +7 -7
|
@@ -66,6 +66,8 @@ export declare class AuthStorage implements CredentialStore {
|
|
|
66
66
|
static fromStorage(storage: AuthStorageBackend): AuthStorage;
|
|
67
67
|
static inMemory(data?: AuthStorageData): AuthStorage;
|
|
68
68
|
private parseStorageData;
|
|
69
|
+
/** Reports whether the parse had to heal poisoned pool slots, so a load can write the repair back once. */
|
|
70
|
+
private parseStorageContent;
|
|
69
71
|
private recordError;
|
|
70
72
|
private updateReadState;
|
|
71
73
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-storage.d.ts","sourceRoot":"","sources":["../../src/core/auth-storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,gBAAgB,EAGhB,oBAAoB,EAEpB,UAAU,EACV,cAAc,EACd,eAAe,EACf,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAEN,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"auth-storage.d.ts","sourceRoot":"","sources":["../../src/core/auth-storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,gBAAgB,EAGhB,oBAAoB,EAEpB,UAAU,EACV,cAAc,EACd,eAAe,EACf,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAEN,KAAK,cAAc,EAMnB,MAAM,uCAAuC,CAAC;AAoB/C,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAsBlD,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC;AACxC,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC;AAClD,MAAM,MAAM,UAAU,GAAG;IACxB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,aAAa,GAAG,UAAU,GAAG,iBAAiB,GAAG,qBAAqB,CAAC;IACvG,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAChC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,KAAK,UAAU,CAAC,CAAC,IAAI;IACpB,MAAM,EAAE,CAAC,CAAC;IACV,IAAI,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAmBF,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC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-ai";
|
|
6
|
-
import { appendLoginSlot, listSlots, removeSlot, upsertSlot, } from "@earendil-works/pi-ai/auth/pool/slots";
|
|
6
|
+
import { appendLoginSlot, listSlots, removeSlot, repairManagedSentinelSlots, upsertSlot, } from "@earendil-works/pi-ai/auth/pool/slots";
|
|
7
7
|
import { builtinProviders } from "@earendil-works/pi-ai/providers/all";
|
|
8
8
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
9
9
|
import { dirname, join } from "path";
|
|
10
10
|
import lockfile from "proper-lockfile";
|
|
11
11
|
import { getAgentDir } from "../config.js";
|
|
12
12
|
import { raceWithAbortSignal } from "../utils/abort.js";
|
|
13
|
-
import {
|
|
13
|
+
import { getFileContentRevision, normalizePath } from "../utils/paths.js";
|
|
14
14
|
import { stripBom } from "../utils/text.js";
|
|
15
15
|
import { CredentialStoreBusyError, FILE_STORAGE_LOCK_OPTIONS, FILE_STORAGE_LOCK_RETRY_BUDGET_MS, FILE_STORAGE_LOCK_RETRY_MAX_DELAY_MS, FILE_STORAGE_LOCK_RETRY_MIN_DELAY_MS, FILE_STORAGE_SYNC_LOCK_BUDGET_MS, isLockError, } from "./lockfile-policy.js";
|
|
16
16
|
import { isCommandConfigValue, resolveConfigValue } from "./resolve-config-value.js";
|
|
17
|
+
/**
|
|
18
|
+
* Heals pools poisoned by a shipped build that stored a provider-owned pool's
|
|
19
|
+
* flat sentinel as a generated `login-N` slot. Such a slot resolves to sentinel
|
|
20
|
+
* material, fails the provider's auth `check`, and hard-errors every request
|
|
21
|
+
* whose affinity picks it - deterministically, for the lifetime of the entry -
|
|
22
|
+
* so it is dropped the moment auth.json is read and the repair is written back
|
|
23
|
+
* once by the mutable store.
|
|
24
|
+
*/
|
|
25
|
+
function repairPoisonedPoolSlots(data) {
|
|
26
|
+
let repaired;
|
|
27
|
+
for (const [providerId, credential] of Object.entries(data)) {
|
|
28
|
+
if (typeof credential !== "object" || credential === null)
|
|
29
|
+
continue;
|
|
30
|
+
const healed = repairManagedSentinelSlots(providerId, credential);
|
|
31
|
+
if (!healed)
|
|
32
|
+
continue;
|
|
33
|
+
repaired ??= { ...data };
|
|
34
|
+
repaired[providerId] = healed;
|
|
35
|
+
}
|
|
36
|
+
return repaired ? { data: repaired, repaired: true } : { data, repaired: false };
|
|
37
|
+
}
|
|
17
38
|
// The mode applies only on creation so administrator-managed modes and ACLs remain intact.
|
|
18
39
|
const AUTH_FILE_WRITE_OPTIONS = { encoding: "utf-8", mode: 0o600 };
|
|
19
40
|
let sharedAuthFileReadState;
|
|
@@ -192,7 +213,7 @@ export class ReadOnlyAuthStorage {
|
|
|
192
213
|
}
|
|
193
214
|
throw new Error(`Invalid auth.json credential for provider "${providerId}"`);
|
|
194
215
|
}
|
|
195
|
-
this.data = parsed;
|
|
216
|
+
this.data = repairPoisonedPoolSlots(parsed).data;
|
|
196
217
|
return this.data;
|
|
197
218
|
}
|
|
198
219
|
async read(providerId, options) {
|
|
@@ -266,7 +287,7 @@ export class AuthStorage {
|
|
|
266
287
|
sharedAuthFileReadState = { authPath, readState: this.readState };
|
|
267
288
|
}
|
|
268
289
|
if (authPath) {
|
|
269
|
-
const revision =
|
|
290
|
+
const revision = getFileContentRevision(authPath);
|
|
270
291
|
if (revision !== undefined && revision === this.readState.revision)
|
|
271
292
|
return;
|
|
272
293
|
}
|
|
@@ -288,10 +309,14 @@ export class AuthStorage {
|
|
|
288
309
|
return AuthStorage.fromStorage(storage);
|
|
289
310
|
}
|
|
290
311
|
parseStorageData(content) {
|
|
312
|
+
return this.parseStorageContent(content).data;
|
|
313
|
+
}
|
|
314
|
+
/** Reports whether the parse had to heal poisoned pool slots, so a load can write the repair back once. */
|
|
315
|
+
parseStorageContent(content) {
|
|
291
316
|
if (!content) {
|
|
292
|
-
return {};
|
|
317
|
+
return { data: {}, repaired: false };
|
|
293
318
|
}
|
|
294
|
-
return JSON.parse(stripBom(content));
|
|
319
|
+
return repairPoisonedPoolSlots(JSON.parse(stripBom(content)));
|
|
295
320
|
}
|
|
296
321
|
recordError(error) {
|
|
297
322
|
this.errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
@@ -305,15 +330,20 @@ export class AuthStorage {
|
|
|
305
330
|
* Reload credentials from storage.
|
|
306
331
|
*/
|
|
307
332
|
reload() {
|
|
308
|
-
let
|
|
333
|
+
let data = {};
|
|
309
334
|
let revision;
|
|
310
335
|
try {
|
|
311
336
|
this.storage.withLock((current) => {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
337
|
+
const parsed = this.parseStorageContent(current);
|
|
338
|
+
data = parsed.data;
|
|
339
|
+
// A written repair invalidates the revision read before it; leaving it
|
|
340
|
+
// unset makes the next reader re-read instead of trusting a stale stamp.
|
|
341
|
+
revision = parsed.repaired || !this.authPath ? undefined : getFileContentRevision(this.authPath);
|
|
342
|
+
return parsed.repaired
|
|
343
|
+
? { result: undefined, next: JSON.stringify(parsed.data, null, 2) }
|
|
344
|
+
: { result: undefined };
|
|
315
345
|
});
|
|
316
|
-
this.updateReadState(
|
|
346
|
+
this.updateReadState(data, revision);
|
|
317
347
|
}
|
|
318
348
|
catch (error) {
|
|
319
349
|
// Preserve the last valid in-memory snapshot.
|
|
@@ -402,10 +432,12 @@ export class AuthStorage {
|
|
|
402
432
|
}
|
|
403
433
|
async reloadFromStorageAsync(options) {
|
|
404
434
|
return this.storage.withLockAsync(async (content) => {
|
|
405
|
-
const
|
|
406
|
-
const revision = this.authPath ?
|
|
407
|
-
this.updateReadState(
|
|
408
|
-
return
|
|
435
|
+
const parsed = this.parseStorageContent(content);
|
|
436
|
+
const revision = parsed.repaired || !this.authPath ? undefined : getFileContentRevision(this.authPath);
|
|
437
|
+
this.updateReadState(parsed.data, revision);
|
|
438
|
+
return parsed.repaired
|
|
439
|
+
? { result: parsed.data, next: JSON.stringify(parsed.data, null, 2) }
|
|
440
|
+
: { result: parsed.data };
|
|
409
441
|
}, options);
|
|
410
442
|
}
|
|
411
443
|
async readLatestData(options) {
|
|
@@ -420,7 +452,7 @@ export class AuthStorage {
|
|
|
420
452
|
return this.readState.data;
|
|
421
453
|
}
|
|
422
454
|
}
|
|
423
|
-
const revision =
|
|
455
|
+
const revision = getFileContentRevision(this.authPath);
|
|
424
456
|
if (revision !== undefined && revision === this.readState.revision)
|
|
425
457
|
return this.readState.data;
|
|
426
458
|
if (!this.readState.reload) {
|
|
@@ -481,7 +513,7 @@ export class AuthStorage {
|
|
|
481
513
|
const next = await fn(currentData[provider]);
|
|
482
514
|
if (next === undefined) {
|
|
483
515
|
latestData = currentData;
|
|
484
|
-
revision = this.authPath ?
|
|
516
|
+
revision = this.authPath ? getFileContentRevision(this.authPath) : undefined;
|
|
485
517
|
return { result: currentData[provider] };
|
|
486
518
|
}
|
|
487
519
|
const merged = { ...currentData, [provider]: next };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-storage.js","sourceRoot":"","sources":["../../src/core/auth-storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EACN,eAAe,EAEf,SAAS,EAET,UAAU,EACV,UAAU,GACV,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EACN,wBAAwB,EACxB,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,CAAC","sourcesContent":["/**\n * CredentialStore implementation backed by auth.json.\n * Provider auth orchestration belongs to ModelRuntime and pi-ai Models.\n */\n\nimport type {\n\tApiKeyCredential,\n\tAuthEvent,\n\tAuthInteraction,\n\tAuthOperationOptions,\n\tAuthPrompt,\n\tCredential,\n\tCredentialInfo,\n\tCredentialStore,\n\tOAuthAuth,\n\tOAuthCredential,\n\tOAuthLoginCallbacks,\n} from \"@earendil-works/pi-ai\";\nimport { findEnvKeys, getEnvApiKey } from \"@earendil-works/pi-ai\";\nimport {\n\tappendLoginSlot,\n\ttype CredentialSlot,\n\tlistSlots,\n\ttype PooledCredential,\n\tremoveSlot,\n\tupsertSlot,\n} from \"@earendil-works/pi-ai/auth/pool/slots\";\nimport { builtinProviders } from \"@earendil-works/pi-ai/providers/all\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport lockfile from \"proper-lockfile\";\nimport { getAgentDir } from \"../config.ts\";\nimport { raceWithAbortSignal } from \"../utils/abort.ts\";\nimport { getFileRevision, normalizePath } from \"../utils/paths.ts\";\nimport { stripBom } from \"../utils/text.ts\";\nimport {\n\tCredentialStoreBusyError,\n\tFILE_STORAGE_LOCK_OPTIONS,\n\tFILE_STORAGE_LOCK_RETRY_BUDGET_MS,\n\tFILE_STORAGE_LOCK_RETRY_MAX_DELAY_MS,\n\tFILE_STORAGE_LOCK_RETRY_MIN_DELAY_MS,\n\tFILE_STORAGE_SYNC_LOCK_BUDGET_MS,\n\tisLockError,\n} from \"./lockfile-policy.ts\";\nimport { isCommandConfigValue, resolveConfigValue } from \"./resolve-config-value.ts\";\n\ntype AuthStorageData = Record<string, Credential>;\n\nexport type AuthCredential = Credential;\nexport type { ApiKeyCredential, OAuthCredential };\nexport type AuthStatus = {\n\tconfigured: boolean;\n\tsource?: \"stored\" | \"runtime\" | \"environment\" | \"fallback\" | \"models_json_key\" | \"models_json_command\";\n\tlabel?: string;\n};\n\nexport interface GetApiKeyOptions {\n\tincludeFallback?: boolean;\n}\n\ntype LockResult<T> = {\n\tresult: T;\n\tnext?: string;\n};\n\n// The mode applies only on creation so administrator-managed modes and ACLs remain intact.\nconst AUTH_FILE_WRITE_OPTIONS = { encoding: \"utf-8\", mode: 0o600 } as const;\n\ntype AuthFileReload = {\n\tcontroller: AbortController;\n\tpromise: Promise<AuthStorageData>;\n\treaders: number;\n};\n\ntype AuthFileReadState = {\n\tdata: AuthStorageData;\n\trevision?: string;\n\treload?: AuthFileReload;\n};\n\nlet sharedAuthFileReadState: { authPath: string; readState: AuthFileReadState } | undefined;\n\nexport interface AuthStorageBackend {\n\twithLock<T>(fn: (current: string | undefined) => LockResult<T>): T;\n\twithLockAsync<T>(\n\t\tfn: (current: string | undefined) => Promise<LockResult<T>>,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<T>;\n}\n\nexport class FileAuthStorageBackend implements AuthStorageBackend {\n\tprivate authPath: string;\n\n\tconstructor(authPath: string = join(getAgentDir(), \"auth.json\")) {\n\t\tthis.authPath = normalizePath(authPath);\n\t}\n\n\tprivate ensureParentDir(): void {\n\t\tconst dir = dirname(this.authPath);\n\t\tif (!existsSync(dir)) {\n\t\t\tmkdirSync(dir, { recursive: true, mode: 0o700 });\n\t\t}\n\t}\n\n\tprivate ensureFileExists(): void {\n\t\tif (!existsSync(this.authPath)) {\n\t\t\twriteFileSync(this.authPath, \"{}\", AUTH_FILE_WRITE_OPTIONS);\n\t\t}\n\t}\n\n\tprivate acquireLockSyncWithRetry(path: string): () => void {\n\t\tconst startedAt = Date.now();\n\t\tlet attempt = 0;\n\t\twhile (true) {\n\t\t\ttry {\n\t\t\t\treturn lockfile.lockSync(path, { ...FILE_STORAGE_LOCK_OPTIONS, retries: 0 });\n\t\t\t} catch (error) {\n\t\t\t\tif (!isLockError(error)) throw error;\n\t\t\t\tconst waitedMs = Date.now() - startedAt;\n\t\t\t\tif (waitedMs >= FILE_STORAGE_SYNC_LOCK_BUDGET_MS) {\n\t\t\t\t\tthrow new CredentialStoreBusyError(path, waitedMs, error);\n\t\t\t\t}\n\t\t\t\tconst delayMs = Math.min(\n\t\t\t\t\tFILE_STORAGE_LOCK_RETRY_MIN_DELAY_MS * 2 ** attempt,\n\t\t\t\t\tFILE_STORAGE_LOCK_RETRY_MAX_DELAY_MS,\n\t\t\t\t\tFILE_STORAGE_SYNC_LOCK_BUDGET_MS - waitedMs,\n\t\t\t\t);\n\t\t\t\tattempt++;\n\t\t\t\tconst sleeper = new Int32Array(new SharedArrayBuffer(4));\n\t\t\t\tAtomics.wait(sleeper, 0, 0, delayMs);\n\t\t\t}\n\t\t}\n\t}\n\n\twithLock<T>(fn: (current: string | undefined) => LockResult<T>): T {\n\t\tthis.ensureParentDir();\n\t\tthis.ensureFileExists();\n\n\t\tlet release: (() => void) | undefined;\n\t\ttry {\n\t\t\trelease = this.acquireLockSyncWithRetry(this.authPath);\n\t\t\tconst current = existsSync(this.authPath) ? readFileSync(this.authPath, \"utf-8\") : undefined;\n\t\t\tconst { result, next } = fn(current);\n\t\t\tif (next !== undefined) {\n\t\t\t\twriteFileSync(this.authPath, next, AUTH_FILE_WRITE_OPTIONS);\n\t\t\t}\n\t\t\treturn result;\n\t\t} finally {\n\t\t\tif (release) {\n\t\t\t\trelease();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async acquireLockAsync(\n\t\tsignal: AbortSignal | undefined,\n\t\tonCompromised: (error: Error) => void,\n\t): Promise<() => Promise<void>> {\n\t\tsignal?.throwIfAborted();\n\t\tconst startedAt = Date.now();\n\t\tlet attempt = 0;\n\t\t// The retry loop stays here rather than delegating to proper-lockfile's own\n\t\t// `retries`, so an abort is observed between attempts instead of after the\n\t\t// whole budget, and `onCompromised` is rebound per attempt.\n\t\twhile (true) {\n\t\t\ttry {\n\t\t\t\tconst release = await lockfile.lock(this.authPath, {\n\t\t\t\t\t...FILE_STORAGE_LOCK_OPTIONS,\n\t\t\t\t\tretries: 0,\n\t\t\t\t\tonCompromised,\n\t\t\t\t});\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tawait release();\n\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t}\n\t\t\t\treturn release;\n\t\t\t} catch (error) {\n\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\tif (!isLockError(error)) throw error;\n\t\t\t\tconst waitedMs = Date.now() - startedAt;\n\t\t\t\tif (waitedMs >= FILE_STORAGE_LOCK_RETRY_BUDGET_MS) {\n\t\t\t\t\tthrow new CredentialStoreBusyError(this.authPath, waitedMs, error);\n\t\t\t\t}\n\t\t\t\tconst delayMs = Math.min(\n\t\t\t\t\tFILE_STORAGE_LOCK_RETRY_MIN_DELAY_MS * 2 ** attempt,\n\t\t\t\t\tFILE_STORAGE_LOCK_RETRY_MAX_DELAY_MS,\n\t\t\t\t\tFILE_STORAGE_LOCK_RETRY_BUDGET_MS - waitedMs,\n\t\t\t\t);\n\t\t\t\tattempt++;\n\t\t\t\tawait raceWithAbortSignal(new Promise<void>((resolve) => setTimeout(resolve, delayMs)), signal);\n\t\t\t}\n\t\t}\n\t}\n\n\tasync withLockAsync<T>(\n\t\tfn: (current: string | undefined) => Promise<LockResult<T>>,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<T> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tthis.ensureParentDir();\n\t\tthis.ensureFileExists();\n\n\t\tlet release: (() => Promise<void>) | undefined;\n\t\tlet lockCompromised = false;\n\t\tlet lockCompromisedError: Error | undefined;\n\t\tconst throwIfCompromised = () => {\n\t\t\tif (lockCompromised) {\n\t\t\t\tthrow lockCompromisedError ?? new Error(\"Auth storage lock was compromised\");\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\trelease = await this.acquireLockAsync(options?.signal, (error) => {\n\t\t\t\tlockCompromised = true;\n\t\t\t\tlockCompromisedError = error;\n\t\t\t});\n\n\t\t\tthrowIfCompromised();\n\t\t\toptions?.signal?.throwIfAborted();\n\t\t\tconst current = existsSync(this.authPath) ? readFileSync(this.authPath, \"utf-8\") : undefined;\n\t\t\tconst { result, next } = await fn(current);\n\t\t\tthrowIfCompromised();\n\t\t\toptions?.signal?.throwIfAborted();\n\t\t\tif (next !== undefined) {\n\t\t\t\twriteFileSync(this.authPath, next, AUTH_FILE_WRITE_OPTIONS);\n\t\t\t}\n\t\t\tthrowIfCompromised();\n\t\t\treturn result;\n\t\t} finally {\n\t\t\tif (release) {\n\t\t\t\ttry {\n\t\t\t\t\tawait release();\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore unlock errors when lock is compromised.\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class ReadOnlyAuthStorage implements CredentialStore {\n\tprivate readonly authPath: string;\n\tprivate data: AuthStorageData | undefined;\n\n\tconstructor(authPath: string = join(getAgentDir(), \"auth.json\")) {\n\t\tthis.authPath = normalizePath(authPath);\n\t}\n\n\tprivate load(): AuthStorageData {\n\t\tif (this.data) return this.data;\n\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(stripBom(readFileSync(this.authPath, \"utf-8\")));\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\t\tthis.data = {};\n\t\t\t\treturn this.data;\n\t\t\t}\n\t\t\tthrow new Error(`Failed to read auth.json: ${error instanceof Error ? error.message : String(error)}`);\n\t\t}\n\n\t\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\t\tthrow new Error(\"Invalid auth.json: expected an object\");\n\t\t}\n\t\tfor (const [providerId, credential] of Object.entries(parsed)) {\n\t\t\tif (typeof credential !== \"object\" || credential === null || Array.isArray(credential)) {\n\t\t\t\tthrow new Error(`Invalid auth.json credential for provider \"${providerId}\"`);\n\t\t\t}\n\t\t\tconst value = credential as Record<string, unknown>;\n\t\t\tif (value.type === \"api_key\") {\n\t\t\t\tconst validKey = value.key === undefined || typeof value.key === \"string\";\n\t\t\t\tconst validEnv =\n\t\t\t\t\tvalue.env === undefined ||\n\t\t\t\t\t(typeof value.env === \"object\" &&\n\t\t\t\t\t\tvalue.env !== null &&\n\t\t\t\t\t\t!Array.isArray(value.env) &&\n\t\t\t\t\t\tObject.values(value.env).every((entry) => typeof entry === \"string\"));\n\t\t\t\tif (validKey && validEnv) continue;\n\t\t\t} else if (\n\t\t\t\tvalue.type === \"oauth\" &&\n\t\t\t\ttypeof value.access === \"string\" &&\n\t\t\t\ttypeof value.refresh === \"string\" &&\n\t\t\t\ttypeof value.expires === \"number\" &&\n\t\t\t\tNumber.isFinite(value.expires)\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow new Error(`Invalid auth.json credential for provider \"${providerId}\"`);\n\t\t}\n\n\t\tthis.data = parsed as AuthStorageData;\n\t\treturn this.data;\n\t}\n\n\tasync read(providerId: string, options?: AuthOperationOptions): Promise<Credential | undefined> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst credential = this.load()[providerId];\n\t\toptions?.signal?.throwIfAborted();\n\t\tif (!credential) return undefined;\n\t\tif (credential.type !== \"api_key\" || !credential.key || isCommandConfigValue(credential.key)) {\n\t\t\treturn structuredClone(credential);\n\t\t}\n\t\treturn { ...credential, key: resolveConfigValue(credential.key, credential.env) };\n\t}\n\n\tasync list(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst credentials = Object.entries(this.load()).map(([providerId, credential]) => ({\n\t\t\tproviderId,\n\t\t\ttype: credential.type,\n\t\t}));\n\t\toptions?.signal?.throwIfAborted();\n\t\treturn credentials;\n\t}\n\n\tasync modify(\n\t\t_providerId: string,\n\t\t_fn: (current: Credential | undefined) => Promise<Credential | undefined>,\n\t\t_options?: AuthOperationOptions,\n\t): Promise<Credential | undefined> {\n\t\tthrow new Error(\"Read-only credential storage cannot modify auth.json\");\n\t}\n\n\tasync delete(_providerId: string, _options?: AuthOperationOptions): Promise<void> {\n\t\tthrow new Error(\"Read-only credential storage cannot modify auth.json\");\n\t}\n}\n\nexport class InMemoryAuthStorageBackend implements AuthStorageBackend {\n\tprivate value: string | undefined;\n\tprivate asyncChain: Promise<unknown> = Promise.resolve();\n\n\twithLock<T>(fn: (current: string | undefined) => LockResult<T>): T {\n\t\tconst { result, next } = fn(this.value);\n\t\tif (next !== undefined) {\n\t\t\tthis.value = next;\n\t\t}\n\t\treturn result;\n\t}\n\n\twithLockAsync<T>(\n\t\tfn: (current: string | undefined) => Promise<LockResult<T>>,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<T> {\n\t\tconst previous = this.asyncChain;\n\t\tconst operation = (async () => {\n\t\t\tawait previous.catch(() => {});\n\t\t\toptions?.signal?.throwIfAborted();\n\t\t\tconst { result, next } = await fn(this.value);\n\t\t\toptions?.signal?.throwIfAborted();\n\t\t\tif (next !== undefined) {\n\t\t\t\tthis.value = next;\n\t\t\t}\n\t\t\treturn result;\n\t\t})();\n\t\tthis.asyncChain = operation.catch(() => {});\n\t\treturn raceWithAbortSignal(operation, options?.signal);\n\t}\n}\n\n/**\n * Credential storage backed by a JSON file.\n */\nexport class AuthStorage implements CredentialStore {\n\tprivate data: AuthStorageData = {};\n\tprivate readonly runtimeOverrides = new Map<string, string>();\n\tprivate readonly extensionOAuthProviders = new Map<string, OAuthAuth>();\n\tprivate errors: Error[] = [];\n\tprivate storage: AuthStorageBackend;\n\tprivate authPath: string | undefined;\n\tprivate readState: AuthFileReadState;\n\n\tprivate constructor(storage: AuthStorageBackend, authPath?: string) {\n\t\tthis.storage = storage;\n\t\tthis.authPath = authPath;\n\t\tthis.readState =\n\t\t\tauthPath && sharedAuthFileReadState?.authPath === authPath ? sharedAuthFileReadState.readState : { data: {} };\n\t\tif (authPath && !sharedAuthFileReadState) {\n\t\t\tsharedAuthFileReadState = { authPath, readState: this.readState };\n\t\t}\n\t\tif (authPath) {\n\t\t\tconst revision = getFileRevision(authPath);\n\t\t\tif (revision !== undefined && revision === this.readState.revision) return;\n\t\t}\n\t\tthis.reload();\n\t}\n\n\tstatic create(authPath: string = join(getAgentDir(), \"auth.json\")): AuthStorage {\n\t\tconst normalizedAuthPath = normalizePath(authPath);\n\t\treturn new AuthStorage(new FileAuthStorageBackend(normalizedAuthPath), normalizedAuthPath);\n\t}\n\n\tgetStoragePath(): string | undefined {\n\t\treturn this.authPath;\n\t}\n\n\tstatic fromStorage(storage: AuthStorageBackend): AuthStorage {\n\t\treturn new AuthStorage(storage);\n\t}\n\n\tstatic inMemory(data: AuthStorageData = {}): AuthStorage {\n\t\tconst storage = new InMemoryAuthStorageBackend();\n\t\tstorage.withLock(() => ({ result: undefined, next: JSON.stringify(data, null, 2) }));\n\t\treturn AuthStorage.fromStorage(storage);\n\t}\n\n\tprivate parseStorageData(content: string | undefined): AuthStorageData {\n\t\tif (!content) {\n\t\t\treturn {};\n\t\t}\n\t\treturn JSON.parse(stripBom(content)) as AuthStorageData;\n\t}\n\n\tprivate recordError(error: unknown): void {\n\t\tthis.errors.push(error instanceof Error ? error : new Error(String(error)));\n\t}\n\n\tprivate updateReadState(data: AuthStorageData, revision?: string): void {\n\t\tthis.data = data;\n\t\tthis.readState.data = data;\n\t\tthis.readState.revision = revision;\n\t}\n\n\t/**\n\t * Reload credentials from storage.\n\t */\n\treload(): void {\n\t\tlet content: string | undefined;\n\t\tlet revision: string | undefined;\n\t\ttry {\n\t\t\tthis.storage.withLock((current) => {\n\t\t\t\tcontent = current;\n\t\t\t\trevision = this.authPath ? getFileRevision(this.authPath) : undefined;\n\t\t\t\treturn { result: undefined };\n\t\t\t});\n\t\t\tthis.updateReadState(this.parseStorageData(content), revision);\n\t\t} catch (error) {\n\t\t\t// Preserve the last valid in-memory snapshot.\n\t\t\tthis.recordError(error instanceof Error ? error : new Error(String(error)));\n\t\t}\n\t}\n\n\t/** Set a non-persistent API key used ahead of stored credentials. */\n\tsetRuntimeApiKey(provider: string, apiKey: string): void {\n\t\tthis.runtimeOverrides.set(provider, apiKey);\n\t}\n\n\tremoveRuntimeApiKey(provider: string): void {\n\t\tthis.runtimeOverrides.delete(provider);\n\t}\n\n\tget(provider: string): Credential | undefined {\n\t\treturn this.data[provider];\n\t}\n\n\tgetProviderEnv(provider: string): Record<string, string> | undefined {\n\t\tconst credential = this.data[provider];\n\t\treturn credential?.type === \"api_key\" && credential.env ? { ...credential.env } : undefined;\n\t}\n\n\tset(provider: string, credential: Credential): void {\n\t\tthis.storage.withLock((content) => {\n\t\t\tconst currentData = this.parseStorageData(content);\n\t\t\tconst next = appendLoginSlot(currentData[provider], credential);\n\t\t\tconst nextData = { ...currentData, [provider]: next };\n\t\t\tthis.data = nextData;\n\t\t\treturn { result: undefined, next: JSON.stringify(nextData, null, 2) };\n\t\t});\n\t}\n\n\tremove(provider: string): void {\n\t\tthis.storage.withLock((content) => {\n\t\t\tconst nextData = { ...this.parseStorageData(content) };\n\t\t\tdelete nextData[provider];\n\t\t\tthis.data = nextData;\n\t\t\treturn { result: undefined, next: JSON.stringify(nextData, null, 2) };\n\t\t});\n\t}\n\n\tlistSlots(provider: string): CredentialSlot[] {\n\t\treturn listSlots(this.data[provider] as PooledCredential | undefined);\n\t}\n\n\tsetSlot(provider: string, slot: CredentialSlot): void {\n\t\tthis.storage.withLock((content) => {\n\t\t\tconst currentData = this.parseStorageData(content);\n\t\t\tconst next = upsertSlot(currentData[provider] as PooledCredential | undefined, slot);\n\t\t\tconst nextData = { ...currentData, [provider]: next };\n\t\t\tthis.data = nextData;\n\t\t\treturn { result: undefined, next: JSON.stringify(nextData, null, 2) };\n\t\t});\n\t}\n\n\tremoveSlot(provider: string, name: string): void {\n\t\tthis.storage.withLock((content) => {\n\t\t\tconst currentData = this.parseStorageData(content);\n\t\t\tconst next = removeSlot(currentData[provider] as PooledCredential | undefined, name);\n\t\t\tconst nextData = { ...currentData };\n\t\t\tif (next === undefined) delete nextData[provider];\n\t\t\telse nextData[provider] = next;\n\t\t\tthis.data = nextData;\n\t\t\treturn { result: undefined, next: JSON.stringify(nextData, null, 2) };\n\t\t});\n\t}\n\n\thas(provider: string): boolean {\n\t\treturn provider in this.data;\n\t}\n\n\thasAuth(provider: string): boolean {\n\t\treturn this.runtimeOverrides.has(provider) || this.has(provider) || getEnvApiKey(provider) !== undefined;\n\t}\n\n\tgetAuthStatus(provider: string): AuthStatus {\n\t\tif (this.has(provider)) return { configured: true, source: \"stored\" };\n\t\tif (this.runtimeOverrides.has(provider)) return { configured: true, source: \"runtime\", label: \"--api-key\" };\n\t\tconst envName = findEnvKeys(provider)?.[0];\n\t\tif (envName && process.env[envName]) return { configured: true, source: \"environment\", label: envName };\n\t\treturn { configured: false };\n\t}\n\n\tgetAll(): AuthStorageData {\n\t\treturn { ...this.data };\n\t}\n\n\tdrainErrors(): Error[] {\n\t\tconst errors = this.errors;\n\t\tthis.errors = [];\n\t\treturn errors;\n\t}\n\n\tprivate async reloadFromStorageAsync(options?: AuthOperationOptions): Promise<AuthStorageData> {\n\t\treturn this.storage.withLockAsync(async (content) => {\n\t\t\tconst currentData = this.parseStorageData(content);\n\t\t\tconst revision = this.authPath ? getFileRevision(this.authPath) : undefined;\n\t\t\tthis.updateReadState(currentData, revision);\n\t\t\treturn { result: currentData };\n\t\t}, options);\n\t}\n\n\tprivate async readLatestData(options?: AuthOperationOptions): Promise<AuthStorageData> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tif (!this.authPath) {\n\t\t\ttry {\n\t\t\t\treturn await this.reloadFromStorageAsync(options);\n\t\t\t} catch (error) {\n\t\t\t\toptions?.signal?.throwIfAborted();\n\t\t\t\tthis.recordError(error);\n\t\t\t\treturn this.readState.data;\n\t\t\t}\n\t\t}\n\t\tconst revision = getFileRevision(this.authPath);\n\t\tif (revision !== undefined && revision === this.readState.revision) return this.readState.data;\n\t\tif (!this.readState.reload) {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst reload: AuthFileReload = {\n\t\t\t\tcontroller,\n\t\t\t\tpromise: this.reloadFromStorageAsync({ signal: controller.signal }),\n\t\t\t\treaders: 0,\n\t\t\t};\n\t\t\tthis.readState.reload = reload;\n\t\t\tvoid reload.promise.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (this.readState.reload === reload) this.readState.reload = undefined;\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tif (!controller.signal.aborted) this.recordError(error);\n\t\t\t\t\tif (this.readState.reload === reload) this.readState.reload = undefined;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tconst reload = this.readState.reload;\n\t\treload.readers++;\n\t\ttry {\n\t\t\ttry {\n\t\t\t\treturn await raceWithAbortSignal(reload.promise, options?.signal);\n\t\t\t} catch {\n\t\t\t\toptions?.signal?.throwIfAborted();\n\t\t\t\treturn this.readState.data;\n\t\t\t}\n\t\t} finally {\n\t\t\treload.readers--;\n\t\t\tif (reload.readers === 0 && this.readState.reload === reload) {\n\t\t\t\tthis.readState.reload = undefined;\n\t\t\t\treload.controller.abort();\n\t\t\t}\n\t\t}\n\t}\n\n\tasync read(provider: string, options?: AuthOperationOptions): Promise<Credential | undefined> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst runtimeKey = this.runtimeOverrides.get(provider);\n\t\tif (runtimeKey) return { type: \"api_key\", key: runtimeKey };\n\t\tconst credential = (await this.readLatestData(options))[provider];\n\t\toptions?.signal?.throwIfAborted();\n\t\tif (credential?.type !== \"api_key\") return credential;\n\t\tif (credential.key === undefined) return credential;\n\t\treturn { ...credential, key: resolveConfigValue(credential.key, credential.env) };\n\t}\n\n\tasync modify(\n\t\tprovider: string,\n\t\tfn: (current: Credential | undefined) => Promise<Credential | undefined>,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<Credential | undefined> {\n\t\tlet latestData = this.readState.data;\n\t\tlet revision: string | undefined;\n\t\tconst result = await this.storage.withLockAsync(async (content) => {\n\t\t\tconst currentData = this.parseStorageData(content);\n\t\t\tconst next = await fn(currentData[provider]);\n\t\t\tif (next === undefined) {\n\t\t\t\tlatestData = currentData;\n\t\t\t\trevision = this.authPath ? getFileRevision(this.authPath) : undefined;\n\t\t\t\treturn { result: currentData[provider] };\n\t\t\t}\n\n\t\t\tconst merged: AuthStorageData = { ...currentData, [provider]: next };\n\t\t\tlatestData = merged;\n\t\t\treturn { result: next, next: JSON.stringify(merged, null, 2) };\n\t\t}, options);\n\t\tthis.updateReadState(latestData, revision);\n\t\treturn result;\n\t}\n\n\tasync delete(provider: string, options?: AuthOperationOptions): Promise<void> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tthis.runtimeOverrides.delete(provider);\n\t\tlet latestData = this.readState.data;\n\t\tawait this.storage.withLockAsync(async (content) => {\n\t\t\tconst currentData = this.parseStorageData(content);\n\t\t\tdelete currentData[provider];\n\t\t\tlatestData = currentData;\n\t\t\treturn { result: undefined, next: JSON.stringify(currentData, null, 2) };\n\t\t}, options);\n\t\tthis.updateReadState(latestData);\n\t}\n\n\t/** List credential metadata without resolving configured key values. */\n\tasync list(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]> {\n\t\tconst entries = new Map(\n\t\t\tObject.entries(await this.readLatestData(options)).map(([providerId, credential]) => [\n\t\t\t\tproviderId,\n\t\t\t\t{ providerId, type: credential.type },\n\t\t\t]),\n\t\t);\n\t\toptions?.signal?.throwIfAborted();\n\t\tfor (const providerId of this.runtimeOverrides.keys()) {\n\t\t\tentries.set(providerId, { providerId, type: \"api_key\" });\n\t\t}\n\t\treturn [...entries.values()];\n\t}\n\n\tasync getApiKey(providerId: string, options: GetApiKeyOptions = {}): Promise<string | undefined> {\n\t\tconst runtimeKey = this.runtimeOverrides.get(providerId);\n\t\tif (runtimeKey) return runtimeKey;\n\t\tconst credential = await this.read(providerId);\n\t\tif (credential?.type === \"api_key\") return credential.key;\n\t\tif (credential?.type === \"oauth\") {\n\t\t\tconst oauth = builtinProviders().find((provider) => provider.id === providerId)?.auth.oauth;\n\t\t\tif (!oauth) return undefined;\n\t\t\tlet current = credential;\n\t\t\tif (Date.now() >= current.expires) {\n\t\t\t\tconst refreshed = await this.modify(providerId, async (stored) => {\n\t\t\t\t\tif (stored?.type !== \"oauth\") return stored;\n\t\t\t\t\treturn Date.now() < stored.expires ? stored : oauth.refresh(stored, new AbortController().signal);\n\t\t\t\t});\n\t\t\t\tif (refreshed?.type !== \"oauth\") return undefined;\n\t\t\t\tcurrent = refreshed;\n\t\t\t}\n\t\t\treturn (await oauth.toAuth(current)).apiKey;\n\t\t}\n\t\tif (options.includeFallback === false) return undefined;\n\t\treturn getEnvApiKey(providerId);\n\t}\n\n\tregisterOAuthProvider(providerId: string, oauth: OAuthAuth): void {\n\t\tthis.extensionOAuthProviders.set(providerId, oauth);\n\t}\n\n\tunregisterOAuthProvider(providerId: string): void {\n\t\tthis.extensionOAuthProviders.delete(providerId);\n\t}\n\n\tgetOAuthProviders(): Array<{ id: string; name: string }> {\n\t\tconst dynamic = [...this.extensionOAuthProviders.entries()].map(([id, oauth]) => ({\n\t\t\tid,\n\t\t\tname: oauth.name,\n\t\t}));\n\t\tconst builtin = builtinProviders().flatMap((provider) =>\n\t\t\tprovider.auth.oauth && !this.extensionOAuthProviders.has(provider.id)\n\t\t\t\t? [{ id: provider.id, name: provider.auth.oauth.name }]\n\t\t\t\t: [],\n\t\t);\n\t\treturn [...dynamic, ...builtin];\n\t}\n\n\tasync login(providerId: string, callbacks: OAuthLoginCallbacks): Promise<void> {\n\t\tconst oauth =\n\t\t\tthis.extensionOAuthProviders.get(providerId) ??\n\t\t\tbuiltinProviders().find((provider) => provider.id === providerId)?.auth.oauth;\n\t\tif (!oauth) throw new Error(`Unknown OAuth provider: ${providerId}`);\n\t\tconst signal = callbacks.signal ?? new AbortController().signal;\n\t\tconst interaction: AuthInteraction & { signal: AbortSignal } = {\n\t\t\tsignal,\n\t\t\tprompt: (prompt) => this.handleLegacyPrompt(prompt, callbacks),\n\t\t\tnotify: (event) => this.handleLegacyEvent(event, callbacks),\n\t\t};\n\t\tconst credential = await oauth.login(interaction);\n\t\tthis.set(providerId, credential);\n\t}\n\n\tlogout(provider: string): void {\n\t\tthis.removeRuntimeApiKey(provider);\n\t\tthis.remove(provider);\n\t}\n\n\tprivate handleLegacyPrompt(prompt: AuthPrompt, callbacks: OAuthLoginCallbacks): Promise<string> {\n\t\tswitch (prompt.type) {\n\t\t\tcase \"manual_code\":\n\t\t\t\treturn callbacks.onManualCodeInput?.() ?? callbacks.onPrompt(prompt);\n\t\t\tcase \"select\":\n\t\t\t\treturn callbacks.onSelect(prompt).then((value) => {\n\t\t\t\t\tif (value === undefined) throw new Error(\"Login cancelled\");\n\t\t\t\t\treturn value;\n\t\t\t\t});\n\t\t\tcase \"secret\":\n\t\t\tcase \"text\":\n\t\t\t\treturn callbacks.onPrompt(prompt);\n\t\t}\n\t}\n\n\tprivate handleLegacyEvent(event: AuthEvent, callbacks: OAuthLoginCallbacks): void {\n\t\tswitch (event.type) {\n\t\t\tcase \"auth_url\":\n\t\t\t\tcallbacks.onAuth(event);\n\t\t\t\tbreak;\n\t\t\tcase \"device_code\":\n\t\t\t\tcallbacks.onDeviceCode(event);\n\t\t\t\tbreak;\n\t\t\tcase \"info\":\n\t\t\t\tcallbacks.onProgress?.(event.message);\n\t\t\t\tbreak;\n\t\t\tcase \"progress\":\n\t\t\t\tcallbacks.onProgress?.(event.message);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n/**\n * One-off synchronous read of a stored credential from an auth.json file,\n * without instantiating a store or resolving configured key values.\n */\nexport function readStoredCredential(\n\tproviderId: string,\n\tauthPath: string = join(getAgentDir(), \"auth.json\"),\n): Credential | undefined {\n\ttry {\n\t\tconst data = JSON.parse(stripBom(readFileSync(normalizePath(authPath), \"utf-8\"))) as AuthStorageData;\n\t\treturn data[providerId];\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"auth-storage.js","sourceRoot":"","sources":["../../src/core/auth-storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAClE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CAAC,IAAI,EAAE,CAAC;YACpB,KAAK,UAAU;gBACd,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACxB,MAAM;YACP,KAAK,aAAa;gBACjB,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;gBAC9B,MAAM;YACP,KAAK,MAAM;gBACV,SAAS,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACtC,MAAM;YACP,KAAK,UAAU;gBACd,SAAS,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACtC,MAAM;QACR,CAAC;IACF,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CACnC,UAAkB,EAClB,QAAQ,GAAW,IAAI,CAAC,WAAW,EAAE,EAAE,WAAW,CAAC;IAEnD,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,CAAoB,CAAC;QACrG,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC","sourcesContent":["/**\n * CredentialStore implementation backed by auth.json.\n * Provider auth orchestration belongs to ModelRuntime and pi-ai Models.\n */\n\nimport type {\n\tApiKeyCredential,\n\tAuthEvent,\n\tAuthInteraction,\n\tAuthOperationOptions,\n\tAuthPrompt,\n\tCredential,\n\tCredentialInfo,\n\tCredentialStore,\n\tOAuthAuth,\n\tOAuthCredential,\n\tOAuthLoginCallbacks,\n} from \"@earendil-works/pi-ai\";\nimport { findEnvKeys, getEnvApiKey } from \"@earendil-works/pi-ai\";\nimport {\n\tappendLoginSlot,\n\ttype CredentialSlot,\n\tlistSlots,\n\ttype PooledCredential,\n\tremoveSlot,\n\trepairManagedSentinelSlots,\n\tupsertSlot,\n} from \"@earendil-works/pi-ai/auth/pool/slots\";\nimport { builtinProviders } from \"@earendil-works/pi-ai/providers/all\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport lockfile from \"proper-lockfile\";\nimport { getAgentDir } from \"../config.ts\";\nimport { raceWithAbortSignal } from \"../utils/abort.ts\";\nimport { getFileContentRevision, normalizePath } from \"../utils/paths.ts\";\nimport { stripBom } from \"../utils/text.ts\";\nimport {\n\tCredentialStoreBusyError,\n\tFILE_STORAGE_LOCK_OPTIONS,\n\tFILE_STORAGE_LOCK_RETRY_BUDGET_MS,\n\tFILE_STORAGE_LOCK_RETRY_MAX_DELAY_MS,\n\tFILE_STORAGE_LOCK_RETRY_MIN_DELAY_MS,\n\tFILE_STORAGE_SYNC_LOCK_BUDGET_MS,\n\tisLockError,\n} from \"./lockfile-policy.ts\";\nimport { isCommandConfigValue, resolveConfigValue } from \"./resolve-config-value.ts\";\n\ntype AuthStorageData = Record<string, Credential>;\n\n/**\n * Heals pools poisoned by a shipped build that stored a provider-owned pool's\n * flat sentinel as a generated `login-N` slot. Such a slot resolves to sentinel\n * material, fails the provider's auth `check`, and hard-errors every request\n * whose affinity picks it - deterministically, for the lifetime of the entry -\n * so it is dropped the moment auth.json is read and the repair is written back\n * once by the mutable store.\n */\nfunction repairPoisonedPoolSlots(data: AuthStorageData): { data: AuthStorageData; repaired: boolean } {\n\tlet repaired: AuthStorageData | undefined;\n\tfor (const [providerId, credential] of Object.entries(data)) {\n\t\tif (typeof credential !== \"object\" || credential === null) continue;\n\t\tconst healed = repairManagedSentinelSlots(providerId, credential);\n\t\tif (!healed) continue;\n\t\trepaired ??= { ...data };\n\t\trepaired[providerId] = healed;\n\t}\n\treturn repaired ? { data: repaired, repaired: true } : { data, repaired: false };\n}\n\nexport type AuthCredential = Credential;\nexport type { ApiKeyCredential, OAuthCredential };\nexport type AuthStatus = {\n\tconfigured: boolean;\n\tsource?: \"stored\" | \"runtime\" | \"environment\" | \"fallback\" | \"models_json_key\" | \"models_json_command\";\n\tlabel?: string;\n};\n\nexport interface GetApiKeyOptions {\n\tincludeFallback?: boolean;\n}\n\ntype LockResult<T> = {\n\tresult: T;\n\tnext?: string;\n};\n\n// The mode applies only on creation so administrator-managed modes and ACLs remain intact.\nconst AUTH_FILE_WRITE_OPTIONS = { encoding: \"utf-8\", mode: 0o600 } as const;\n\ntype AuthFileReload = {\n\tcontroller: AbortController;\n\tpromise: Promise<AuthStorageData>;\n\treaders: number;\n};\n\ntype AuthFileReadState = {\n\tdata: AuthStorageData;\n\trevision?: string;\n\treload?: AuthFileReload;\n};\n\nlet sharedAuthFileReadState: { authPath: string; readState: AuthFileReadState } | undefined;\n\nexport interface AuthStorageBackend {\n\twithLock<T>(fn: (current: string | undefined) => LockResult<T>): T;\n\twithLockAsync<T>(\n\t\tfn: (current: string | undefined) => Promise<LockResult<T>>,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<T>;\n}\n\nexport class FileAuthStorageBackend implements AuthStorageBackend {\n\tprivate authPath: string;\n\n\tconstructor(authPath: string = join(getAgentDir(), \"auth.json\")) {\n\t\tthis.authPath = normalizePath(authPath);\n\t}\n\n\tprivate ensureParentDir(): void {\n\t\tconst dir = dirname(this.authPath);\n\t\tif (!existsSync(dir)) {\n\t\t\tmkdirSync(dir, { recursive: true, mode: 0o700 });\n\t\t}\n\t}\n\n\tprivate ensureFileExists(): void {\n\t\tif (!existsSync(this.authPath)) {\n\t\t\twriteFileSync(this.authPath, \"{}\", AUTH_FILE_WRITE_OPTIONS);\n\t\t}\n\t}\n\n\tprivate acquireLockSyncWithRetry(path: string): () => void {\n\t\tconst startedAt = Date.now();\n\t\tlet attempt = 0;\n\t\twhile (true) {\n\t\t\ttry {\n\t\t\t\treturn lockfile.lockSync(path, { ...FILE_STORAGE_LOCK_OPTIONS, retries: 0 });\n\t\t\t} catch (error) {\n\t\t\t\tif (!isLockError(error)) throw error;\n\t\t\t\tconst waitedMs = Date.now() - startedAt;\n\t\t\t\tif (waitedMs >= FILE_STORAGE_SYNC_LOCK_BUDGET_MS) {\n\t\t\t\t\tthrow new CredentialStoreBusyError(path, waitedMs, error);\n\t\t\t\t}\n\t\t\t\tconst delayMs = Math.min(\n\t\t\t\t\tFILE_STORAGE_LOCK_RETRY_MIN_DELAY_MS * 2 ** attempt,\n\t\t\t\t\tFILE_STORAGE_LOCK_RETRY_MAX_DELAY_MS,\n\t\t\t\t\tFILE_STORAGE_SYNC_LOCK_BUDGET_MS - waitedMs,\n\t\t\t\t);\n\t\t\t\tattempt++;\n\t\t\t\tconst sleeper = new Int32Array(new SharedArrayBuffer(4));\n\t\t\t\tAtomics.wait(sleeper, 0, 0, delayMs);\n\t\t\t}\n\t\t}\n\t}\n\n\twithLock<T>(fn: (current: string | undefined) => LockResult<T>): T {\n\t\tthis.ensureParentDir();\n\t\tthis.ensureFileExists();\n\n\t\tlet release: (() => void) | undefined;\n\t\ttry {\n\t\t\trelease = this.acquireLockSyncWithRetry(this.authPath);\n\t\t\tconst current = existsSync(this.authPath) ? readFileSync(this.authPath, \"utf-8\") : undefined;\n\t\t\tconst { result, next } = fn(current);\n\t\t\tif (next !== undefined) {\n\t\t\t\twriteFileSync(this.authPath, next, AUTH_FILE_WRITE_OPTIONS);\n\t\t\t}\n\t\t\treturn result;\n\t\t} finally {\n\t\t\tif (release) {\n\t\t\t\trelease();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async acquireLockAsync(\n\t\tsignal: AbortSignal | undefined,\n\t\tonCompromised: (error: Error) => void,\n\t): Promise<() => Promise<void>> {\n\t\tsignal?.throwIfAborted();\n\t\tconst startedAt = Date.now();\n\t\tlet attempt = 0;\n\t\t// The retry loop stays here rather than delegating to proper-lockfile's own\n\t\t// `retries`, so an abort is observed between attempts instead of after the\n\t\t// whole budget, and `onCompromised` is rebound per attempt.\n\t\twhile (true) {\n\t\t\ttry {\n\t\t\t\tconst release = await lockfile.lock(this.authPath, {\n\t\t\t\t\t...FILE_STORAGE_LOCK_OPTIONS,\n\t\t\t\t\tretries: 0,\n\t\t\t\t\tonCompromised,\n\t\t\t\t});\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tawait release();\n\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t}\n\t\t\t\treturn release;\n\t\t\t} catch (error) {\n\t\t\t\tsignal?.throwIfAborted();\n\t\t\t\tif (!isLockError(error)) throw error;\n\t\t\t\tconst waitedMs = Date.now() - startedAt;\n\t\t\t\tif (waitedMs >= FILE_STORAGE_LOCK_RETRY_BUDGET_MS) {\n\t\t\t\t\tthrow new CredentialStoreBusyError(this.authPath, waitedMs, error);\n\t\t\t\t}\n\t\t\t\tconst delayMs = Math.min(\n\t\t\t\t\tFILE_STORAGE_LOCK_RETRY_MIN_DELAY_MS * 2 ** attempt,\n\t\t\t\t\tFILE_STORAGE_LOCK_RETRY_MAX_DELAY_MS,\n\t\t\t\t\tFILE_STORAGE_LOCK_RETRY_BUDGET_MS - waitedMs,\n\t\t\t\t);\n\t\t\t\tattempt++;\n\t\t\t\tawait raceWithAbortSignal(new Promise<void>((resolve) => setTimeout(resolve, delayMs)), signal);\n\t\t\t}\n\t\t}\n\t}\n\n\tasync withLockAsync<T>(\n\t\tfn: (current: string | undefined) => Promise<LockResult<T>>,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<T> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tthis.ensureParentDir();\n\t\tthis.ensureFileExists();\n\n\t\tlet release: (() => Promise<void>) | undefined;\n\t\tlet lockCompromised = false;\n\t\tlet lockCompromisedError: Error | undefined;\n\t\tconst throwIfCompromised = () => {\n\t\t\tif (lockCompromised) {\n\t\t\t\tthrow lockCompromisedError ?? new Error(\"Auth storage lock was compromised\");\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\trelease = await this.acquireLockAsync(options?.signal, (error) => {\n\t\t\t\tlockCompromised = true;\n\t\t\t\tlockCompromisedError = error;\n\t\t\t});\n\n\t\t\tthrowIfCompromised();\n\t\t\toptions?.signal?.throwIfAborted();\n\t\t\tconst current = existsSync(this.authPath) ? readFileSync(this.authPath, \"utf-8\") : undefined;\n\t\t\tconst { result, next } = await fn(current);\n\t\t\tthrowIfCompromised();\n\t\t\toptions?.signal?.throwIfAborted();\n\t\t\tif (next !== undefined) {\n\t\t\t\twriteFileSync(this.authPath, next, AUTH_FILE_WRITE_OPTIONS);\n\t\t\t}\n\t\t\tthrowIfCompromised();\n\t\t\treturn result;\n\t\t} finally {\n\t\t\tif (release) {\n\t\t\t\ttry {\n\t\t\t\t\tawait release();\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore unlock errors when lock is compromised.\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class ReadOnlyAuthStorage implements CredentialStore {\n\tprivate readonly authPath: string;\n\tprivate data: AuthStorageData | undefined;\n\n\tconstructor(authPath: string = join(getAgentDir(), \"auth.json\")) {\n\t\tthis.authPath = normalizePath(authPath);\n\t}\n\n\tprivate load(): AuthStorageData {\n\t\tif (this.data) return this.data;\n\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(stripBom(readFileSync(this.authPath, \"utf-8\")));\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\t\tthis.data = {};\n\t\t\t\treturn this.data;\n\t\t\t}\n\t\t\tthrow new Error(`Failed to read auth.json: ${error instanceof Error ? error.message : String(error)}`);\n\t\t}\n\n\t\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\t\tthrow new Error(\"Invalid auth.json: expected an object\");\n\t\t}\n\t\tfor (const [providerId, credential] of Object.entries(parsed)) {\n\t\t\tif (typeof credential !== \"object\" || credential === null || Array.isArray(credential)) {\n\t\t\t\tthrow new Error(`Invalid auth.json credential for provider \"${providerId}\"`);\n\t\t\t}\n\t\t\tconst value = credential as Record<string, unknown>;\n\t\t\tif (value.type === \"api_key\") {\n\t\t\t\tconst validKey = value.key === undefined || typeof value.key === \"string\";\n\t\t\t\tconst validEnv =\n\t\t\t\t\tvalue.env === undefined ||\n\t\t\t\t\t(typeof value.env === \"object\" &&\n\t\t\t\t\t\tvalue.env !== null &&\n\t\t\t\t\t\t!Array.isArray(value.env) &&\n\t\t\t\t\t\tObject.values(value.env).every((entry) => typeof entry === \"string\"));\n\t\t\t\tif (validKey && validEnv) continue;\n\t\t\t} else if (\n\t\t\t\tvalue.type === \"oauth\" &&\n\t\t\t\ttypeof value.access === \"string\" &&\n\t\t\t\ttypeof value.refresh === \"string\" &&\n\t\t\t\ttypeof value.expires === \"number\" &&\n\t\t\t\tNumber.isFinite(value.expires)\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow new Error(`Invalid auth.json credential for provider \"${providerId}\"`);\n\t\t}\n\n\t\tthis.data = repairPoisonedPoolSlots(parsed as AuthStorageData).data;\n\t\treturn this.data;\n\t}\n\n\tasync read(providerId: string, options?: AuthOperationOptions): Promise<Credential | undefined> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst credential = this.load()[providerId];\n\t\toptions?.signal?.throwIfAborted();\n\t\tif (!credential) return undefined;\n\t\tif (credential.type !== \"api_key\" || !credential.key || isCommandConfigValue(credential.key)) {\n\t\t\treturn structuredClone(credential);\n\t\t}\n\t\treturn { ...credential, key: resolveConfigValue(credential.key, credential.env) };\n\t}\n\n\tasync list(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst credentials = Object.entries(this.load()).map(([providerId, credential]) => ({\n\t\t\tproviderId,\n\t\t\ttype: credential.type,\n\t\t}));\n\t\toptions?.signal?.throwIfAborted();\n\t\treturn credentials;\n\t}\n\n\tasync modify(\n\t\t_providerId: string,\n\t\t_fn: (current: Credential | undefined) => Promise<Credential | undefined>,\n\t\t_options?: AuthOperationOptions,\n\t): Promise<Credential | undefined> {\n\t\tthrow new Error(\"Read-only credential storage cannot modify auth.json\");\n\t}\n\n\tasync delete(_providerId: string, _options?: AuthOperationOptions): Promise<void> {\n\t\tthrow new Error(\"Read-only credential storage cannot modify auth.json\");\n\t}\n}\n\nexport class InMemoryAuthStorageBackend implements AuthStorageBackend {\n\tprivate value: string | undefined;\n\tprivate asyncChain: Promise<unknown> = Promise.resolve();\n\n\twithLock<T>(fn: (current: string | undefined) => LockResult<T>): T {\n\t\tconst { result, next } = fn(this.value);\n\t\tif (next !== undefined) {\n\t\t\tthis.value = next;\n\t\t}\n\t\treturn result;\n\t}\n\n\twithLockAsync<T>(\n\t\tfn: (current: string | undefined) => Promise<LockResult<T>>,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<T> {\n\t\tconst previous = this.asyncChain;\n\t\tconst operation = (async () => {\n\t\t\tawait previous.catch(() => {});\n\t\t\toptions?.signal?.throwIfAborted();\n\t\t\tconst { result, next } = await fn(this.value);\n\t\t\toptions?.signal?.throwIfAborted();\n\t\t\tif (next !== undefined) {\n\t\t\t\tthis.value = next;\n\t\t\t}\n\t\t\treturn result;\n\t\t})();\n\t\tthis.asyncChain = operation.catch(() => {});\n\t\treturn raceWithAbortSignal(operation, options?.signal);\n\t}\n}\n\n/**\n * Credential storage backed by a JSON file.\n */\nexport class AuthStorage implements CredentialStore {\n\tprivate data: AuthStorageData = {};\n\tprivate readonly runtimeOverrides = new Map<string, string>();\n\tprivate readonly extensionOAuthProviders = new Map<string, OAuthAuth>();\n\tprivate errors: Error[] = [];\n\tprivate storage: AuthStorageBackend;\n\tprivate authPath: string | undefined;\n\tprivate readState: AuthFileReadState;\n\n\tprivate constructor(storage: AuthStorageBackend, authPath?: string) {\n\t\tthis.storage = storage;\n\t\tthis.authPath = authPath;\n\t\tthis.readState =\n\t\t\tauthPath && sharedAuthFileReadState?.authPath === authPath ? sharedAuthFileReadState.readState : { data: {} };\n\t\tif (authPath && !sharedAuthFileReadState) {\n\t\t\tsharedAuthFileReadState = { authPath, readState: this.readState };\n\t\t}\n\t\tif (authPath) {\n\t\t\tconst revision = getFileContentRevision(authPath);\n\t\t\tif (revision !== undefined && revision === this.readState.revision) return;\n\t\t}\n\t\tthis.reload();\n\t}\n\n\tstatic create(authPath: string = join(getAgentDir(), \"auth.json\")): AuthStorage {\n\t\tconst normalizedAuthPath = normalizePath(authPath);\n\t\treturn new AuthStorage(new FileAuthStorageBackend(normalizedAuthPath), normalizedAuthPath);\n\t}\n\n\tgetStoragePath(): string | undefined {\n\t\treturn this.authPath;\n\t}\n\n\tstatic fromStorage(storage: AuthStorageBackend): AuthStorage {\n\t\treturn new AuthStorage(storage);\n\t}\n\n\tstatic inMemory(data: AuthStorageData = {}): AuthStorage {\n\t\tconst storage = new InMemoryAuthStorageBackend();\n\t\tstorage.withLock(() => ({ result: undefined, next: JSON.stringify(data, null, 2) }));\n\t\treturn AuthStorage.fromStorage(storage);\n\t}\n\n\tprivate parseStorageData(content: string | undefined): AuthStorageData {\n\t\treturn this.parseStorageContent(content).data;\n\t}\n\n\t/** Reports whether the parse had to heal poisoned pool slots, so a load can write the repair back once. */\n\tprivate parseStorageContent(content: string | undefined): { data: AuthStorageData; repaired: boolean } {\n\t\tif (!content) {\n\t\t\treturn { data: {}, repaired: false };\n\t\t}\n\t\treturn repairPoisonedPoolSlots(JSON.parse(stripBom(content)) as AuthStorageData);\n\t}\n\n\tprivate recordError(error: unknown): void {\n\t\tthis.errors.push(error instanceof Error ? error : new Error(String(error)));\n\t}\n\n\tprivate updateReadState(data: AuthStorageData, revision?: string): void {\n\t\tthis.data = data;\n\t\tthis.readState.data = data;\n\t\tthis.readState.revision = revision;\n\t}\n\n\t/**\n\t * Reload credentials from storage.\n\t */\n\treload(): void {\n\t\tlet data: AuthStorageData = {};\n\t\tlet revision: string | undefined;\n\t\ttry {\n\t\t\tthis.storage.withLock((current) => {\n\t\t\t\tconst parsed = this.parseStorageContent(current);\n\t\t\t\tdata = parsed.data;\n\t\t\t\t// A written repair invalidates the revision read before it; leaving it\n\t\t\t\t// unset makes the next reader re-read instead of trusting a stale stamp.\n\t\t\t\trevision = parsed.repaired || !this.authPath ? undefined : getFileContentRevision(this.authPath);\n\t\t\t\treturn parsed.repaired\n\t\t\t\t\t? { result: undefined, next: JSON.stringify(parsed.data, null, 2) }\n\t\t\t\t\t: { result: undefined };\n\t\t\t});\n\t\t\tthis.updateReadState(data, revision);\n\t\t} catch (error) {\n\t\t\t// Preserve the last valid in-memory snapshot.\n\t\t\tthis.recordError(error instanceof Error ? error : new Error(String(error)));\n\t\t}\n\t}\n\n\t/** Set a non-persistent API key used ahead of stored credentials. */\n\tsetRuntimeApiKey(provider: string, apiKey: string): void {\n\t\tthis.runtimeOverrides.set(provider, apiKey);\n\t}\n\n\tremoveRuntimeApiKey(provider: string): void {\n\t\tthis.runtimeOverrides.delete(provider);\n\t}\n\n\tget(provider: string): Credential | undefined {\n\t\treturn this.data[provider];\n\t}\n\n\tgetProviderEnv(provider: string): Record<string, string> | undefined {\n\t\tconst credential = this.data[provider];\n\t\treturn credential?.type === \"api_key\" && credential.env ? { ...credential.env } : undefined;\n\t}\n\n\tset(provider: string, credential: Credential): void {\n\t\tthis.storage.withLock((content) => {\n\t\t\tconst currentData = this.parseStorageData(content);\n\t\t\tconst next = appendLoginSlot(currentData[provider], credential);\n\t\t\tconst nextData = { ...currentData, [provider]: next };\n\t\t\tthis.data = nextData;\n\t\t\treturn { result: undefined, next: JSON.stringify(nextData, null, 2) };\n\t\t});\n\t}\n\n\tremove(provider: string): void {\n\t\tthis.storage.withLock((content) => {\n\t\t\tconst nextData = { ...this.parseStorageData(content) };\n\t\t\tdelete nextData[provider];\n\t\t\tthis.data = nextData;\n\t\t\treturn { result: undefined, next: JSON.stringify(nextData, null, 2) };\n\t\t});\n\t}\n\n\tlistSlots(provider: string): CredentialSlot[] {\n\t\treturn listSlots(this.data[provider] as PooledCredential | undefined);\n\t}\n\n\tsetSlot(provider: string, slot: CredentialSlot): void {\n\t\tthis.storage.withLock((content) => {\n\t\t\tconst currentData = this.parseStorageData(content);\n\t\t\tconst next = upsertSlot(currentData[provider] as PooledCredential | undefined, slot);\n\t\t\tconst nextData = { ...currentData, [provider]: next };\n\t\t\tthis.data = nextData;\n\t\t\treturn { result: undefined, next: JSON.stringify(nextData, null, 2) };\n\t\t});\n\t}\n\n\tremoveSlot(provider: string, name: string): void {\n\t\tthis.storage.withLock((content) => {\n\t\t\tconst currentData = this.parseStorageData(content);\n\t\t\tconst next = removeSlot(currentData[provider] as PooledCredential | undefined, name);\n\t\t\tconst nextData = { ...currentData };\n\t\t\tif (next === undefined) delete nextData[provider];\n\t\t\telse nextData[provider] = next;\n\t\t\tthis.data = nextData;\n\t\t\treturn { result: undefined, next: JSON.stringify(nextData, null, 2) };\n\t\t});\n\t}\n\n\thas(provider: string): boolean {\n\t\treturn provider in this.data;\n\t}\n\n\thasAuth(provider: string): boolean {\n\t\treturn this.runtimeOverrides.has(provider) || this.has(provider) || getEnvApiKey(provider) !== undefined;\n\t}\n\n\tgetAuthStatus(provider: string): AuthStatus {\n\t\tif (this.has(provider)) return { configured: true, source: \"stored\" };\n\t\tif (this.runtimeOverrides.has(provider)) return { configured: true, source: \"runtime\", label: \"--api-key\" };\n\t\tconst envName = findEnvKeys(provider)?.[0];\n\t\tif (envName && process.env[envName]) return { configured: true, source: \"environment\", label: envName };\n\t\treturn { configured: false };\n\t}\n\n\tgetAll(): AuthStorageData {\n\t\treturn { ...this.data };\n\t}\n\n\tdrainErrors(): Error[] {\n\t\tconst errors = this.errors;\n\t\tthis.errors = [];\n\t\treturn errors;\n\t}\n\n\tprivate async reloadFromStorageAsync(options?: AuthOperationOptions): Promise<AuthStorageData> {\n\t\treturn this.storage.withLockAsync(async (content) => {\n\t\t\tconst parsed = this.parseStorageContent(content);\n\t\t\tconst revision = parsed.repaired || !this.authPath ? undefined : getFileContentRevision(this.authPath);\n\t\t\tthis.updateReadState(parsed.data, revision);\n\t\t\treturn parsed.repaired\n\t\t\t\t? { result: parsed.data, next: JSON.stringify(parsed.data, null, 2) }\n\t\t\t\t: { result: parsed.data };\n\t\t}, options);\n\t}\n\n\tprivate async readLatestData(options?: AuthOperationOptions): Promise<AuthStorageData> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tif (!this.authPath) {\n\t\t\ttry {\n\t\t\t\treturn await this.reloadFromStorageAsync(options);\n\t\t\t} catch (error) {\n\t\t\t\toptions?.signal?.throwIfAborted();\n\t\t\t\tthis.recordError(error);\n\t\t\t\treturn this.readState.data;\n\t\t\t}\n\t\t}\n\t\tconst revision = getFileContentRevision(this.authPath);\n\t\tif (revision !== undefined && revision === this.readState.revision) return this.readState.data;\n\t\tif (!this.readState.reload) {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst reload: AuthFileReload = {\n\t\t\t\tcontroller,\n\t\t\t\tpromise: this.reloadFromStorageAsync({ signal: controller.signal }),\n\t\t\t\treaders: 0,\n\t\t\t};\n\t\t\tthis.readState.reload = reload;\n\t\t\tvoid reload.promise.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (this.readState.reload === reload) this.readState.reload = undefined;\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tif (!controller.signal.aborted) this.recordError(error);\n\t\t\t\t\tif (this.readState.reload === reload) this.readState.reload = undefined;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tconst reload = this.readState.reload;\n\t\treload.readers++;\n\t\ttry {\n\t\t\ttry {\n\t\t\t\treturn await raceWithAbortSignal(reload.promise, options?.signal);\n\t\t\t} catch {\n\t\t\t\toptions?.signal?.throwIfAborted();\n\t\t\t\treturn this.readState.data;\n\t\t\t}\n\t\t} finally {\n\t\t\treload.readers--;\n\t\t\tif (reload.readers === 0 && this.readState.reload === reload) {\n\t\t\t\tthis.readState.reload = undefined;\n\t\t\t\treload.controller.abort();\n\t\t\t}\n\t\t}\n\t}\n\n\tasync read(provider: string, options?: AuthOperationOptions): Promise<Credential | undefined> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst runtimeKey = this.runtimeOverrides.get(provider);\n\t\tif (runtimeKey) return { type: \"api_key\", key: runtimeKey };\n\t\tconst credential = (await this.readLatestData(options))[provider];\n\t\toptions?.signal?.throwIfAborted();\n\t\tif (credential?.type !== \"api_key\") return credential;\n\t\tif (credential.key === undefined) return credential;\n\t\treturn { ...credential, key: resolveConfigValue(credential.key, credential.env) };\n\t}\n\n\tasync modify(\n\t\tprovider: string,\n\t\tfn: (current: Credential | undefined) => Promise<Credential | undefined>,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<Credential | undefined> {\n\t\tlet latestData = this.readState.data;\n\t\tlet revision: string | undefined;\n\t\tconst result = await this.storage.withLockAsync(async (content) => {\n\t\t\tconst currentData = this.parseStorageData(content);\n\t\t\tconst next = await fn(currentData[provider]);\n\t\t\tif (next === undefined) {\n\t\t\t\tlatestData = currentData;\n\t\t\t\trevision = this.authPath ? getFileContentRevision(this.authPath) : undefined;\n\t\t\t\treturn { result: currentData[provider] };\n\t\t\t}\n\n\t\t\tconst merged: AuthStorageData = { ...currentData, [provider]: next };\n\t\t\tlatestData = merged;\n\t\t\treturn { result: next, next: JSON.stringify(merged, null, 2) };\n\t\t}, options);\n\t\tthis.updateReadState(latestData, revision);\n\t\treturn result;\n\t}\n\n\tasync delete(provider: string, options?: AuthOperationOptions): Promise<void> {\n\t\toptions?.signal?.throwIfAborted();\n\t\tthis.runtimeOverrides.delete(provider);\n\t\tlet latestData = this.readState.data;\n\t\tawait this.storage.withLockAsync(async (content) => {\n\t\t\tconst currentData = this.parseStorageData(content);\n\t\t\tdelete currentData[provider];\n\t\t\tlatestData = currentData;\n\t\t\treturn { result: undefined, next: JSON.stringify(currentData, null, 2) };\n\t\t}, options);\n\t\tthis.updateReadState(latestData);\n\t}\n\n\t/** List credential metadata without resolving configured key values. */\n\tasync list(options?: AuthOperationOptions): Promise<readonly CredentialInfo[]> {\n\t\tconst entries = new Map(\n\t\t\tObject.entries(await this.readLatestData(options)).map(([providerId, credential]) => [\n\t\t\t\tproviderId,\n\t\t\t\t{ providerId, type: credential.type },\n\t\t\t]),\n\t\t);\n\t\toptions?.signal?.throwIfAborted();\n\t\tfor (const providerId of this.runtimeOverrides.keys()) {\n\t\t\tentries.set(providerId, { providerId, type: \"api_key\" });\n\t\t}\n\t\treturn [...entries.values()];\n\t}\n\n\tasync getApiKey(providerId: string, options: GetApiKeyOptions = {}): Promise<string | undefined> {\n\t\tconst runtimeKey = this.runtimeOverrides.get(providerId);\n\t\tif (runtimeKey) return runtimeKey;\n\t\tconst credential = await this.read(providerId);\n\t\tif (credential?.type === \"api_key\") return credential.key;\n\t\tif (credential?.type === \"oauth\") {\n\t\t\tconst oauth = builtinProviders().find((provider) => provider.id === providerId)?.auth.oauth;\n\t\t\tif (!oauth) return undefined;\n\t\t\tlet current = credential;\n\t\t\tif (Date.now() >= current.expires) {\n\t\t\t\tconst refreshed = await this.modify(providerId, async (stored) => {\n\t\t\t\t\tif (stored?.type !== \"oauth\") return stored;\n\t\t\t\t\treturn Date.now() < stored.expires ? stored : oauth.refresh(stored, new AbortController().signal);\n\t\t\t\t});\n\t\t\t\tif (refreshed?.type !== \"oauth\") return undefined;\n\t\t\t\tcurrent = refreshed;\n\t\t\t}\n\t\t\treturn (await oauth.toAuth(current)).apiKey;\n\t\t}\n\t\tif (options.includeFallback === false) return undefined;\n\t\treturn getEnvApiKey(providerId);\n\t}\n\n\tregisterOAuthProvider(providerId: string, oauth: OAuthAuth): void {\n\t\tthis.extensionOAuthProviders.set(providerId, oauth);\n\t}\n\n\tunregisterOAuthProvider(providerId: string): void {\n\t\tthis.extensionOAuthProviders.delete(providerId);\n\t}\n\n\tgetOAuthProviders(): Array<{ id: string; name: string }> {\n\t\tconst dynamic = [...this.extensionOAuthProviders.entries()].map(([id, oauth]) => ({\n\t\t\tid,\n\t\t\tname: oauth.name,\n\t\t}));\n\t\tconst builtin = builtinProviders().flatMap((provider) =>\n\t\t\tprovider.auth.oauth && !this.extensionOAuthProviders.has(provider.id)\n\t\t\t\t? [{ id: provider.id, name: provider.auth.oauth.name }]\n\t\t\t\t: [],\n\t\t);\n\t\treturn [...dynamic, ...builtin];\n\t}\n\n\tasync login(providerId: string, callbacks: OAuthLoginCallbacks): Promise<void> {\n\t\tconst oauth =\n\t\t\tthis.extensionOAuthProviders.get(providerId) ??\n\t\t\tbuiltinProviders().find((provider) => provider.id === providerId)?.auth.oauth;\n\t\tif (!oauth) throw new Error(`Unknown OAuth provider: ${providerId}`);\n\t\tconst signal = callbacks.signal ?? new AbortController().signal;\n\t\tconst interaction: AuthInteraction & { signal: AbortSignal } = {\n\t\t\tsignal,\n\t\t\tprompt: (prompt) => this.handleLegacyPrompt(prompt, callbacks),\n\t\t\tnotify: (event) => this.handleLegacyEvent(event, callbacks),\n\t\t};\n\t\tconst credential = await oauth.login(interaction);\n\t\tthis.set(providerId, credential);\n\t}\n\n\tlogout(provider: string): void {\n\t\tthis.removeRuntimeApiKey(provider);\n\t\tthis.remove(provider);\n\t}\n\n\tprivate handleLegacyPrompt(prompt: AuthPrompt, callbacks: OAuthLoginCallbacks): Promise<string> {\n\t\tswitch (prompt.type) {\n\t\t\tcase \"manual_code\":\n\t\t\t\treturn callbacks.onManualCodeInput?.() ?? callbacks.onPrompt(prompt);\n\t\t\tcase \"select\":\n\t\t\t\treturn callbacks.onSelect(prompt).then((value) => {\n\t\t\t\t\tif (value === undefined) throw new Error(\"Login cancelled\");\n\t\t\t\t\treturn value;\n\t\t\t\t});\n\t\t\tcase \"secret\":\n\t\t\tcase \"text\":\n\t\t\t\treturn callbacks.onPrompt(prompt);\n\t\t}\n\t}\n\n\tprivate handleLegacyEvent(event: AuthEvent, callbacks: OAuthLoginCallbacks): void {\n\t\tswitch (event.type) {\n\t\t\tcase \"auth_url\":\n\t\t\t\tcallbacks.onAuth(event);\n\t\t\t\tbreak;\n\t\t\tcase \"device_code\":\n\t\t\t\tcallbacks.onDeviceCode(event);\n\t\t\t\tbreak;\n\t\t\tcase \"info\":\n\t\t\t\tcallbacks.onProgress?.(event.message);\n\t\t\t\tbreak;\n\t\t\tcase \"progress\":\n\t\t\t\tcallbacks.onProgress?.(event.message);\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n/**\n * One-off synchronous read of a stored credential from an auth.json file,\n * without instantiating a store or resolving configured key values.\n */\nexport function readStoredCredential(\n\tproviderId: string,\n\tauthPath: string = join(getAgentDir(), \"auth.json\"),\n): Credential | undefined {\n\ttry {\n\t\tconst data = JSON.parse(stripBom(readFileSync(normalizePath(authPath), \"utf-8\"))) as AuthStorageData;\n\t\treturn data[providerId];\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n"]}
|
package/dist/core/brand.d.ts
CHANGED
|
@@ -25,6 +25,10 @@ export interface BrandUpdateChannel {
|
|
|
25
25
|
/** Release notes URL; `{version}` is replaced with the available version. */
|
|
26
26
|
readonly changelogUrl?: string;
|
|
27
27
|
}
|
|
28
|
+
export interface BrandChangelog {
|
|
29
|
+
readonly path: string;
|
|
30
|
+
readonly version?: string;
|
|
31
|
+
}
|
|
28
32
|
export interface BrandProfile {
|
|
29
33
|
/** Product name shown to users and to the model. */
|
|
30
34
|
readonly name: string;
|
|
@@ -44,6 +48,7 @@ export interface BrandProfile {
|
|
|
44
48
|
readonly originator?: string;
|
|
45
49
|
/** Update channel of the branded product; absent means the product manages updates itself. */
|
|
46
50
|
readonly update?: BrandUpdateChannel;
|
|
51
|
+
readonly changelog?: BrandChangelog;
|
|
47
52
|
}
|
|
48
53
|
/**
|
|
49
54
|
* Parses a brand profile. Returns undefined for absent, malformed, or nameless input; a
|
package/dist/core/brand.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../src/core/brand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,4DAA4D;AAC5D,eAAO,MAAM,aAAa,gBAAgB,CAAC;AAE3C;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAClC,sEAAsE;IACtE,QAAQ,CAAC,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AAC,MAAM,EAAE,MAAM,EAAE,OAAO,2BAAiB,GAAG,MAAM,EAAE,CAKhF;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,GAAG,SAAS,CAMjG"}
|
package/dist/core/brand.js
CHANGED
|
@@ -11,6 +11,17 @@
|
|
|
11
11
|
*/
|
|
12
12
|
/** Environment variable carrying the JSON brand profile. */
|
|
13
13
|
export const BRAND_ENV_VAR = "SENPI_BRAND";
|
|
14
|
+
function readChangelog(source) {
|
|
15
|
+
const value = source.changelog;
|
|
16
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
17
|
+
return undefined;
|
|
18
|
+
const changelog = value;
|
|
19
|
+
const path = readString(changelog, "path");
|
|
20
|
+
if (!path?.startsWith("/") || path.includes("\0"))
|
|
21
|
+
return undefined;
|
|
22
|
+
const version = readString(changelog, "version");
|
|
23
|
+
return { path, ...(version ? { version } : {}) };
|
|
24
|
+
}
|
|
14
25
|
function readUpdateChannel(source) {
|
|
15
26
|
const update = source.update;
|
|
16
27
|
if (typeof update !== "object" || update === null || Array.isArray(update))
|
|
@@ -70,6 +81,7 @@ export function parseBrandProfile(raw) {
|
|
|
70
81
|
process.stderr.write(`warning: ignoring ${BRAND_ENV_VAR} with an unsafe "configDir"\n`);
|
|
71
82
|
return undefined;
|
|
72
83
|
}
|
|
84
|
+
const changelog = readChangelog(source);
|
|
73
85
|
return {
|
|
74
86
|
name,
|
|
75
87
|
command: readString(source, "command"),
|
|
@@ -80,6 +92,7 @@ export function parseBrandProfile(raw) {
|
|
|
80
92
|
userAgent: readString(source, "userAgent") || name,
|
|
81
93
|
originator: readString(source, "originator"),
|
|
82
94
|
update: readUpdateChannel(source),
|
|
95
|
+
...(changelog ? { changelog } : {}),
|
|
83
96
|
};
|
|
84
97
|
}
|
|
85
98
|
/**
|
package/dist/core/brand.js.map
CHANGED
|
@@ -1 +1 @@
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AAC,MAAM,EAAoB,EAAE,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,CAC7E,CAAC;IACF,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC,CAAC;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAc,EAAE,GAAG,GAAsB,OAAO,CAAC,GAAG;IAC5E,KAAK,MAAM,IAAI,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1C,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;IACvC,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Brand profile resolution.\n *\n * A distribution that repackages this engine (for example the `omo-ai` package) injects a\n * single JSON environment variable describing how the product presents itself. The engine\n * parses it once at startup and then REMOVES it from the environment, so nested processes\n * spawned by tools inherit a clean environment and keep the engine's own identity.\n *\n * Absent or malformed input leaves every brand-derived value at its standalone default, so a\n * plain install behaves exactly as it did before this module existed.\n */\n\n/** Environment variable carrying the JSON brand profile. */\nexport const BRAND_ENV_VAR = \"SENPI_BRAND\";\n\n/**\n * Where a repackaging distribution publishes itself. Without this the engine keeps checking\n * its own package, which would advertise an update the branded product cannot install.\n */\nexport interface BrandUpdateChannel {\n\t/** Registry package that ships the branded product, e.g. `omo-ai`. */\n\treadonly packageName: string;\n\t/** Dist-tag the product publishes on, e.g. `beta`. */\n\treadonly distTag: string;\n\t/** Command shown to the user, e.g. `npm i -g omo-ai@beta`. */\n\treadonly command: string;\n\t/** Release notes URL; `{version}` is replaced with the available version. */\n\treadonly changelogUrl?: string;\n}\n\nexport interface BrandProfile {\n\t/** Product name shown to users and to the model. */\n\treadonly name: string;\n\t/** Executable name used in shell-command contexts when it differs from the display name. */\n\treadonly command?: string;\n\t/** Version shown in the header, terminal titles and `--version`. */\n\treadonly displayVersion?: string;\n\t/** Config directory name, e.g. `.omo`. */\n\treadonly configDir: string;\n\t/** When true the agent state lives directly under the config directory, with no `agent` segment. */\n\treadonly flatLayout: boolean;\n\t/** Prefix for the product's environment variables, e.g. `OMO`. */\n\treadonly envPrefix: string;\n\t/** Product token used in the outgoing user agent. */\n\treadonly userAgent: string;\n\t/** Product token used as the provider-side originator, when the distribution overrides it. */\n\treadonly originator?: string;\n\t/** Update channel of the branded product; absent means the product manages updates itself. */\n\treadonly update?: BrandUpdateChannel;\n}\n\nfunction readUpdateChannel(source: Record<string, unknown>): BrandUpdateChannel | undefined {\n\tconst update = source.update;\n\tif (typeof update !== \"object\" || update === null || Array.isArray(update)) return undefined;\n\n\tconst channel = update as Record<string, unknown>;\n\tconst packageName = readString(channel, \"packageName\");\n\tconst command = readString(channel, \"command\");\n\tif (!packageName || !command) return undefined;\n\n\treturn {\n\t\tpackageName,\n\t\tdistTag: readString(channel, \"distTag\") || \"latest\",\n\t\tcommand,\n\t\tchangelogUrl: readString(channel, \"changelogUrl\"),\n\t};\n}\n\n/**\n * A config directory names ONE entry inside the home directory. Anything carrying a separator or\n * a parent reference would move agent state - and the migration that copies into it - somewhere\n * the user never agreed to, so such a profile is rejected rather than sanitised.\n */\nfunction isSafeConfigDirName(value: string): boolean {\n\treturn value !== \".\" && value !== \"..\" && !/[\\\\/]/.test(value);\n}\n\nfunction readString(source: Record<string, unknown>, key: string): string | undefined {\n\tconst value = source[key];\n\treturn typeof value === \"string\" && value.trim() ? value.trim() : undefined;\n}\n\n/**\n * Parses a brand profile. Returns undefined for absent, malformed, or nameless input; a\n * malformed profile is reported once on stderr and never throws, because a broken brand\n * must not stop the agent from starting.\n */\nexport function parseBrandProfile(raw: string | undefined): BrandProfile | undefined {\n\tif (!raw?.trim()) return undefined;\n\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch {\n\t\tprocess.stderr.write(`warning: ignoring malformed ${BRAND_ENV_VAR} (expected JSON)\\n`);\n\t\treturn undefined;\n\t}\n\n\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\tprocess.stderr.write(`warning: ignoring malformed ${BRAND_ENV_VAR} (expected a JSON object)\\n`);\n\t\treturn undefined;\n\t}\n\n\tconst source = parsed as Record<string, unknown>;\n\tconst name = readString(source, \"name\");\n\tif (!name) {\n\t\tprocess.stderr.write(`warning: ignoring ${BRAND_ENV_VAR} without a \"name\"\\n`);\n\t\treturn undefined;\n\t}\n\n\tconst configDir = readString(source, \"configDir\") || `.${name}`;\n\tif (!isSafeConfigDirName(configDir)) {\n\t\tprocess.stderr.write(`warning: ignoring ${BRAND_ENV_VAR} with an unsafe \"configDir\"\\n`);\n\t\treturn undefined;\n\t}\n\n\treturn {\n\t\tname,\n\t\tcommand: readString(source, \"command\"),\n\t\tdisplayVersion: readString(source, \"displayVersion\"),\n\t\tconfigDir,\n\t\tflatLayout: source.flatLayout === true,\n\t\tenvPrefix: (readString(source, \"envPrefix\") || name).toUpperCase(),\n\t\tuserAgent: readString(source, \"userAgent\") || name,\n\t\toriginator: readString(source, \"originator\"),\n\t\tupdate: readUpdateChannel(source),\n\t};\n}\n\n/**\n * Parses the brand profile without touching the environment.\n *\n * The CLI entrypoint re-spawns the real agent as a child process and hands it `process.env`,\n * so the variable has to survive that hop. Scrubbing therefore happens explicitly in the\n * process that actually runs the agent - see `scrubBrandFromEnvironment`.\n */\nexport function consumeBrandProfile(env: NodeJS.ProcessEnv = process.env): BrandProfile | undefined {\n\treturn parseBrandProfile(env[BRAND_ENV_VAR]);\n}\n\n/**\n * Removes the brand variable so tools spawning the engine again inherit a clean environment\n * and keep the engine's own identity. Called once the profile has been resolved by the\n * process that runs the agent loop.\n */\nexport function scrubBrandFromEnvironment(env: NodeJS.ProcessEnv = process.env): void {\n\tdelete env[BRAND_ENV_VAR];\n}\n\n/**\n * Environment prefixes read after the brand's own prefix, so a machine configured before the\n * rebrand keeps working unchanged.\n */\nconst LEGACY_ENV_PREFIXES = [\"SENPI\", \"PI\"] as const;\n\nlet cachedProfile: BrandProfile | undefined;\nlet profileResolved = false;\n\n/**\n * The active brand profile, resolved (and scrubbed from the environment) on first use.\n */\nexport function brandProfile(): BrandProfile | undefined {\n\tif (!profileResolved) {\n\t\tcachedProfile = consumeBrandProfile();\n\t\tprofileResolved = true;\n\t}\n\treturn cachedProfile;\n}\n\n/** exported for tests only */\nexport function resetBrandProfileForTests(): void {\n\tcachedProfile = undefined;\n\tprofileResolved = false;\n}\n\n/** Environment variable names for one setting, most specific first. */\nexport function brandEnvNames(suffix: string, profile = brandProfile()): string[] {\n\tconst prefixes = [profile?.envPrefix, ...LEGACY_ENV_PREFIXES].filter(\n\t\t(prefix): prefix is string => typeof prefix === \"string\" && prefix.length > 0,\n\t);\n\treturn [...new Set(prefixes)].map((prefix) => `${prefix}_${suffix}`);\n}\n\n/**\n * Reads one setting across the brand's prefix and the legacy prefixes, returning the first\n * DEFINED value so that an explicitly empty value keeps its existing meaning.\n */\nexport function envValue(suffix: string, env: NodeJS.ProcessEnv = process.env): string | undefined {\n\tfor (const name of brandEnvNames(suffix)) {\n\t\tconst value = env[name];\n\t\tif (value !== undefined) return value;\n\t}\n\treturn undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"brand.js","sourceRoot":"","sources":["../../src/core/brand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;AA4C3C,SAAS,aAAa,CAAC,MAA+B;IACrD,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC;IAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAA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,CAAC;QACtB,aAAa,GAAG,mBAAmB,EAAE,CAAC;QACtC,eAAe,GAAG,IAAI,CAAC;IACxB,CAAC;IACD,OAAO,aAAa,CAAC;AACtB,CAAC;AAED,8BAA8B;AAC9B,MAAM,UAAU,yBAAyB;IACxC,aAAa,GAAG,SAAS,CAAC;IAC1B,eAAe,GAAG,KAAK,CAAC;AACzB,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,OAAO,GAAG,YAAY,EAAE;IACrE,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,mBAAmB,CAAC,CAAC,MAAM,CACnE,CAAC,MAAM,EAAoB,EAAE,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,CAC7E,CAAC;IACF,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC,CAAC;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAc,EAAE,GAAG,GAAsB,OAAO,CAAC,GAAG;IAC5E,KAAK,MAAM,IAAI,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1C,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;IACvC,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Brand profile resolution.\n *\n * A distribution that repackages this engine (for example the `omo-ai` package) injects a\n * single JSON environment variable describing how the product presents itself. The engine\n * parses it once at startup and then REMOVES it from the environment, so nested processes\n * spawned by tools inherit a clean environment and keep the engine's own identity.\n *\n * Absent or malformed input leaves every brand-derived value at its standalone default, so a\n * plain install behaves exactly as it did before this module existed.\n */\n\n/** Environment variable carrying the JSON brand profile. */\nexport const BRAND_ENV_VAR = \"SENPI_BRAND\";\n\n/**\n * Where a repackaging distribution publishes itself. Without this the engine keeps checking\n * its own package, which would advertise an update the branded product cannot install.\n */\nexport interface BrandUpdateChannel {\n\t/** Registry package that ships the branded product, e.g. `omo-ai`. */\n\treadonly packageName: string;\n\t/** Dist-tag the product publishes on, e.g. `beta`. */\n\treadonly distTag: string;\n\t/** Command shown to the user, e.g. `npm i -g omo-ai@beta`. */\n\treadonly command: string;\n\t/** Release notes URL; `{version}` is replaced with the available version. */\n\treadonly changelogUrl?: string;\n}\n\nexport interface BrandChangelog {\n\treadonly path: string;\n\treadonly version?: string;\n}\n\nexport interface BrandProfile {\n\t/** Product name shown to users and to the model. */\n\treadonly name: string;\n\t/** Executable name used in shell-command contexts when it differs from the display name. */\n\treadonly command?: string;\n\t/** Version shown in the header, terminal titles and `--version`. */\n\treadonly displayVersion?: string;\n\t/** Config directory name, e.g. `.omo`. */\n\treadonly configDir: string;\n\t/** When true the agent state lives directly under the config directory, with no `agent` segment. */\n\treadonly flatLayout: boolean;\n\t/** Prefix for the product's environment variables, e.g. `OMO`. */\n\treadonly envPrefix: string;\n\t/** Product token used in the outgoing user agent. */\n\treadonly userAgent: string;\n\t/** Product token used as the provider-side originator, when the distribution overrides it. */\n\treadonly originator?: string;\n\t/** Update channel of the branded product; absent means the product manages updates itself. */\n\treadonly update?: BrandUpdateChannel;\n\treadonly changelog?: BrandChangelog;\n}\n\nfunction readChangelog(source: Record<string, unknown>): BrandChangelog | undefined {\n\tconst value = source.changelog;\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return undefined;\n\tconst changelog = value as Record<string, unknown>;\n\tconst path = readString(changelog, \"path\");\n\tif (!path?.startsWith(\"/\") || path.includes(\"\\0\")) return undefined;\n\tconst version = readString(changelog, \"version\");\n\treturn { path, ...(version ? { version } : {}) };\n}\n\nfunction readUpdateChannel(source: Record<string, unknown>): BrandUpdateChannel | undefined {\n\tconst update = source.update;\n\tif (typeof update !== \"object\" || update === null || Array.isArray(update)) return undefined;\n\n\tconst channel = update as Record<string, unknown>;\n\tconst packageName = readString(channel, \"packageName\");\n\tconst command = readString(channel, \"command\");\n\tif (!packageName || !command) return undefined;\n\n\treturn {\n\t\tpackageName,\n\t\tdistTag: readString(channel, \"distTag\") || \"latest\",\n\t\tcommand,\n\t\tchangelogUrl: readString(channel, \"changelogUrl\"),\n\t};\n}\n\n/**\n * A config directory names ONE entry inside the home directory. Anything carrying a separator or\n * a parent reference would move agent state - and the migration that copies into it - somewhere\n * the user never agreed to, so such a profile is rejected rather than sanitised.\n */\nfunction isSafeConfigDirName(value: string): boolean {\n\treturn value !== \".\" && value !== \"..\" && !/[\\\\/]/.test(value);\n}\n\nfunction readString(source: Record<string, unknown>, key: string): string | undefined {\n\tconst value = source[key];\n\treturn typeof value === \"string\" && value.trim() ? value.trim() : undefined;\n}\n\n/**\n * Parses a brand profile. Returns undefined for absent, malformed, or nameless input; a\n * malformed profile is reported once on stderr and never throws, because a broken brand\n * must not stop the agent from starting.\n */\nexport function parseBrandProfile(raw: string | undefined): BrandProfile | undefined {\n\tif (!raw?.trim()) return undefined;\n\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch {\n\t\tprocess.stderr.write(`warning: ignoring malformed ${BRAND_ENV_VAR} (expected JSON)\\n`);\n\t\treturn undefined;\n\t}\n\n\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\tprocess.stderr.write(`warning: ignoring malformed ${BRAND_ENV_VAR} (expected a JSON object)\\n`);\n\t\treturn undefined;\n\t}\n\n\tconst source = parsed as Record<string, unknown>;\n\tconst name = readString(source, \"name\");\n\tif (!name) {\n\t\tprocess.stderr.write(`warning: ignoring ${BRAND_ENV_VAR} without a \"name\"\\n`);\n\t\treturn undefined;\n\t}\n\n\tconst configDir = readString(source, \"configDir\") || `.${name}`;\n\tif (!isSafeConfigDirName(configDir)) {\n\t\tprocess.stderr.write(`warning: ignoring ${BRAND_ENV_VAR} with an unsafe \"configDir\"\\n`);\n\t\treturn undefined;\n\t}\n\n\tconst changelog = readChangelog(source);\n\treturn {\n\t\tname,\n\t\tcommand: readString(source, \"command\"),\n\t\tdisplayVersion: readString(source, \"displayVersion\"),\n\t\tconfigDir,\n\t\tflatLayout: source.flatLayout === true,\n\t\tenvPrefix: (readString(source, \"envPrefix\") || name).toUpperCase(),\n\t\tuserAgent: readString(source, \"userAgent\") || name,\n\t\toriginator: readString(source, \"originator\"),\n\t\tupdate: readUpdateChannel(source),\n\t\t...(changelog ? { changelog } : {}),\n\t};\n}\n\n/**\n * Parses the brand profile without touching the environment.\n *\n * The CLI entrypoint re-spawns the real agent as a child process and hands it `process.env`,\n * so the variable has to survive that hop. Scrubbing therefore happens explicitly in the\n * process that actually runs the agent - see `scrubBrandFromEnvironment`.\n */\nexport function consumeBrandProfile(env: NodeJS.ProcessEnv = process.env): BrandProfile | undefined {\n\treturn parseBrandProfile(env[BRAND_ENV_VAR]);\n}\n\n/**\n * Removes the brand variable so tools spawning the engine again inherit a clean environment\n * and keep the engine's own identity. Called once the profile has been resolved by the\n * process that runs the agent loop.\n */\nexport function scrubBrandFromEnvironment(env: NodeJS.ProcessEnv = process.env): void {\n\tdelete env[BRAND_ENV_VAR];\n}\n\n/**\n * Environment prefixes read after the brand's own prefix, so a machine configured before the\n * rebrand keeps working unchanged.\n */\nconst LEGACY_ENV_PREFIXES = [\"SENPI\", \"PI\"] as const;\n\nlet cachedProfile: BrandProfile | undefined;\nlet profileResolved = false;\n\n/**\n * The active brand profile, resolved (and scrubbed from the environment) on first use.\n */\nexport function brandProfile(): BrandProfile | undefined {\n\tif (!profileResolved) {\n\t\tcachedProfile = consumeBrandProfile();\n\t\tprofileResolved = true;\n\t}\n\treturn cachedProfile;\n}\n\n/** exported for tests only */\nexport function resetBrandProfileForTests(): void {\n\tcachedProfile = undefined;\n\tprofileResolved = false;\n}\n\n/** Environment variable names for one setting, most specific first. */\nexport function brandEnvNames(suffix: string, profile = brandProfile()): string[] {\n\tconst prefixes = [profile?.envPrefix, ...LEGACY_ENV_PREFIXES].filter(\n\t\t(prefix): prefix is string => typeof prefix === \"string\" && prefix.length > 0,\n\t);\n\treturn [...new Set(prefixes)].map((prefix) => `${prefix}_${suffix}`);\n}\n\n/**\n * Reads one setting across the brand's prefix and the legacy prefixes, returning the first\n * DEFINED value so that an explicitly empty value keeps its existing meaning.\n */\nexport function envValue(suffix: string, env: NodeJS.ProcessEnv = process.env): string | undefined {\n\tfor (const name of brandEnvNames(suffix)) {\n\t\tconst value = env[name];\n\t\tif (value !== undefined) return value;\n\t}\n\treturn undefined;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ChangelogSource {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly path: string;
|
|
4
|
+
readonly version: string | undefined;
|
|
5
|
+
readonly rewriteLinks: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function resolveChangelogSource(): ChangelogSource;
|
|
8
|
+
//# sourceMappingURL=changelog-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changelog-source.d.ts","sourceRoot":"","sources":["../../src/core/changelog-source.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAC/B;AAeD,wBAAgB,sBAAsB,IAAI,eAAe,CAGxD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BRAND, getChangelogPath, VERSION } from "../config.js";
|
|
2
|
+
function brandSource(brand) {
|
|
3
|
+
const configured = brand.changelog;
|
|
4
|
+
if (!configured) {
|
|
5
|
+
return { id: brand.name.toLowerCase(), path: getChangelogPath(), version: undefined, rewriteLinks: false };
|
|
6
|
+
}
|
|
7
|
+
return {
|
|
8
|
+
id: brand.name.toLowerCase(),
|
|
9
|
+
path: configured.path,
|
|
10
|
+
version: configured.version,
|
|
11
|
+
rewriteLinks: false,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function resolveChangelogSource() {
|
|
15
|
+
if (BRAND)
|
|
16
|
+
return brandSource(BRAND);
|
|
17
|
+
return { id: "engine", path: getChangelogPath(), version: VERSION, rewriteLinks: true };
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=changelog-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changelog-source.js","sourceRoot":"","sources":["../../src/core/changelog-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAUhE,SAAS,WAAW,CAAC,KAAmB;IACvC,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC;IACnC,IAAI,CAAC,UAAU,EAAE,CAAC;QACjB,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IAC5G,CAAC;IACD,OAAO;QACN,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE;QAC5B,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,YAAY,EAAE,KAAK;KACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB;IACrC,IAAI,KAAK;QAAE,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;IACrC,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AACzF,CAAC","sourcesContent":["import { BRAND, getChangelogPath, VERSION } from \"../config.ts\";\nimport type { BrandProfile } from \"./brand.ts\";\n\nexport interface ChangelogSource {\n\treadonly id: string;\n\treadonly path: string;\n\treadonly version: string | undefined;\n\treadonly rewriteLinks: boolean;\n}\n\nfunction brandSource(brand: BrandProfile): ChangelogSource {\n\tconst configured = brand.changelog;\n\tif (!configured) {\n\t\treturn { id: brand.name.toLowerCase(), path: getChangelogPath(), version: undefined, rewriteLinks: false };\n\t}\n\treturn {\n\t\tid: brand.name.toLowerCase(),\n\t\tpath: configured.path,\n\t\tversion: configured.version,\n\t\trewriteLinks: false,\n\t};\n}\n\nexport function resolveChangelogSource(): ChangelogSource {\n\tif (BRAND) return brandSource(BRAND);\n\treturn { id: \"engine\", path: getChangelogPath(), version: VERSION, rewriteLinks: true };\n}\n"]}
|
|
@@ -5,6 +5,7 @@ export type CredentialAccountSource = "login" | "import" | "env";
|
|
|
5
5
|
/** Account metadata safe to surface: names and health only, never key material. */
|
|
6
6
|
export type CredentialAccountSummary = {
|
|
7
7
|
readonly name: string;
|
|
8
|
+
readonly displayName?: string;
|
|
8
9
|
readonly source: CredentialAccountSource;
|
|
9
10
|
readonly blocked: boolean;
|
|
10
11
|
readonly pinned: boolean;
|
|
@@ -20,6 +21,8 @@ export declare function assertValidAccountName(name: string): void;
|
|
|
20
21
|
export declare function getCredentialAccounts(storage: AuthStorage, provider: string, env?: NodeJS.ProcessEnv, repository?: CredentialSlotRepository): Promise<CredentialAccountSummary[]>;
|
|
21
22
|
/** Storage-free variant for callers that already hold the credential (e.g. auth check). */
|
|
22
23
|
export declare function summarizeCredentialAccounts(provider: string, stored: Credential | undefined, env?: NodeJS.ProcessEnv, repository?: CredentialSlotRepository): Promise<CredentialAccountSummary[]>;
|
|
24
|
+
/** Atomically rename/clear stored metadata without changing identity, health or environment state. */
|
|
25
|
+
export declare function renameCredentialAccount(storage: AuthStorage, provider: string, name: string, displayName: string | null): Promise<void>;
|
|
23
26
|
/** Pins one slot, or clears the pin when `name` is null. */
|
|
24
27
|
export declare function pinCredentialAccount(storage: AuthStorage, provider: string, name: string | null, env?: NodeJS.ProcessEnv, repository?: CredentialSlotRepository): Promise<void>;
|
|
25
28
|
/**
|