@humain/terminal 0.0.2 → 0.0.3-beta.1
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 +251 -24
- package/README.md +143 -119
- package/dist/cli/args.d.ts +4 -2
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +37 -39
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/auth-check.d.ts +19 -0
- package/dist/cli/auth-check.d.ts.map +1 -0
- package/dist/cli/auth-check.js +50 -0
- package/dist/cli/auth-check.js.map +1 -0
- package/dist/cli/auth-command.d.ts +24 -0
- package/dist/cli/auth-command.d.ts.map +1 -0
- package/dist/cli/auth-command.js +103 -0
- package/dist/cli/auth-command.js.map +1 -0
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +2 -2
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/credential-print.d.ts +5 -15
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +42 -83
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/cli/experimental/auth.d.ts +16 -0
- package/dist/cli/experimental/auth.d.ts.map +1 -0
- package/dist/cli/experimental/auth.js +13 -0
- package/dist/cli/experimental/auth.js.map +1 -0
- package/dist/cli/experimental/cli.d.ts +6 -0
- package/dist/cli/experimental/cli.d.ts.map +1 -0
- package/dist/cli/experimental/cli.js +5 -0
- package/dist/cli/experimental/cli.js.map +1 -0
- package/dist/cli/experimental/command-options.d.ts +17 -0
- package/dist/cli/experimental/command-options.d.ts.map +1 -0
- package/dist/cli/experimental/command-options.js +35 -0
- package/dist/cli/experimental/command-options.js.map +1 -0
- package/dist/cli/experimental/command.d.ts +63 -0
- package/dist/cli/experimental/command.d.ts.map +1 -0
- package/dist/cli/experimental/command.js +130 -0
- package/dist/cli/experimental/command.js.map +1 -0
- package/dist/cli/experimental/commands/client.d.ts +13 -0
- package/dist/cli/experimental/commands/client.d.ts.map +1 -0
- package/dist/cli/experimental/commands/client.js +25 -0
- package/dist/cli/experimental/commands/client.js.map +1 -0
- package/dist/cli/experimental/commands/pi.d.ts +15 -0
- package/dist/cli/experimental/commands/pi.d.ts.map +1 -0
- package/dist/cli/experimental/commands/pi.js +28 -0
- package/dist/cli/experimental/commands/pi.js.map +1 -0
- package/dist/cli/experimental/commands/server.d.ts +13 -0
- package/dist/cli/experimental/commands/server.d.ts.map +1 -0
- package/dist/cli/experimental/commands/server.js +25 -0
- package/dist/cli/experimental/commands/server.js.map +1 -0
- package/dist/cli/experimental/transport-address.d.ts +10 -0
- package/dist/cli/experimental/transport-address.d.ts.map +1 -0
- package/dist/cli/experimental/transport-address.js +38 -0
- package/dist/cli/experimental/transport-address.js.map +1 -0
- package/dist/cli/list-models.d.ts +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +2 -2
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/startup-ui.d.ts +1 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +2 -2
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +3 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/remote-session.d.ts +53 -0
- package/dist/client/remote-session.d.ts.map +1 -0
- package/dist/client/remote-session.js +340 -0
- package/dist/client/remote-session.js.map +1 -0
- package/dist/client/transcript.d.ts +12 -0
- package/dist/client/transcript.d.ts.map +1 -0
- package/dist/client/transcript.js +98 -0
- package/dist/client/transcript.js.map +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -3
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +1 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -10
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +72 -70
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +25 -9
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +237 -39
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +60 -41
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +2 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +3 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +27 -4
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +5 -0
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/keybindings.d.ts +45 -5
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +29 -5
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +4 -0
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -3
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +13 -10
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +4 -3
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +42 -10
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +30 -13
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +233 -73
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/models-store.d.ts +12 -7
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +83 -14
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/package-manager.d.ts +6 -3
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +80 -61
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-manifest.d.ts +8 -0
- package/dist/core/pi-manifest.d.ts.map +1 -0
- package/dist/core/pi-manifest.js +28 -0
- package/dist/core/pi-manifest.js.map +1 -0
- package/dist/core/provider-composer.d.ts +4 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +36 -15
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +73 -67
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +2 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +5 -5
- package/dist/core/runtime-credentials.d.ts.map +1 -1
- package/dist/core/runtime-credentials.js +11 -8
- package/dist/core/runtime-credentials.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +2 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +3 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +12 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +40 -16
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +8 -0
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts +5 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +16 -15
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +4 -0
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +11 -7
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +7 -0
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +16 -19
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +4 -0
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +5 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts +4 -0
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +5 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts +4 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +7 -3
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/write.d.ts +4 -0
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +6 -2
- package/dist/core/tools/write.js.map +1 -1
- package/dist/extensions/llama/index.d.ts.map +1 -1
- package/dist/extensions/llama/index.js +11 -2
- package/dist/extensions/llama/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +21 -7
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/humain/agent-execution-protocol.d.ts +218 -0
- package/dist/humain/agent-execution-protocol.d.ts.map +1 -0
- package/dist/humain/agent-execution-protocol.js +204 -0
- package/dist/humain/agent-execution-protocol.js.map +1 -0
- package/dist/humain/agent-execution-runtime.d.ts +35 -0
- package/dist/humain/agent-execution-runtime.d.ts.map +1 -0
- package/dist/humain/agent-execution-runtime.js +170 -0
- package/dist/humain/agent-execution-runtime.js.map +1 -0
- package/dist/humain/index.d.ts.map +1 -1
- package/dist/humain/index.js +8 -7
- package/dist/humain/index.js.map +1 -1
- package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +673 -0
- package/dist/humain/mcp-adapter/vendor/LICENSE +21 -0
- package/dist/humain/mcp-adapter/vendor/README.md +736 -0
- package/dist/humain/mcp-adapter/vendor/abort.ts +34 -0
- package/dist/humain/mcp-adapter/vendor/agent-dir.ts +68 -0
- package/dist/humain/mcp-adapter/vendor/agent-plugin-loader.ts +377 -0
- package/dist/humain/mcp-adapter/vendor/app-bridge.bundle.js +67 -0
- package/dist/humain/mcp-adapter/vendor/banner.png +0 -0
- package/dist/humain/mcp-adapter/vendor/cli.js +230 -0
- package/dist/humain/mcp-adapter/vendor/commands.ts +627 -0
- package/dist/humain/mcp-adapter/vendor/config.ts +1226 -0
- package/dist/humain/mcp-adapter/vendor/consent-manager.ts +64 -0
- package/dist/humain/mcp-adapter/vendor/direct-tools.ts +607 -0
- package/dist/humain/mcp-adapter/vendor/elicitation-handler.ts +348 -0
- package/dist/humain/mcp-adapter/vendor/error-signal.ts +21 -0
- package/dist/humain/mcp-adapter/vendor/errors.ts +223 -0
- package/dist/humain/mcp-adapter/vendor/glimpse-ui.ts +80 -0
- package/dist/humain/mcp-adapter/vendor/host-html-template.ts +461 -0
- package/dist/humain/mcp-adapter/vendor/index.bundle.d.mts +4 -0
- package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +16279 -0
- package/dist/humain/mcp-adapter/vendor/index.ts +898 -0
- package/dist/humain/mcp-adapter/vendor/init.ts +649 -0
- package/dist/humain/mcp-adapter/vendor/json-schema-validator.ts +69 -0
- package/dist/humain/mcp-adapter/vendor/lifecycle.ts +147 -0
- package/dist/humain/mcp-adapter/vendor/logger.ts +169 -0
- package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +993 -0
- package/dist/humain/mcp-adapter/vendor/mcp-auth.ts +1000 -0
- package/dist/humain/mcp-adapter/vendor/mcp-callback-server.ts +510 -0
- package/dist/humain/mcp-adapter/vendor/mcp-code.ts +354 -0
- package/dist/humain/mcp-adapter/vendor/mcp-keyring-helper.cjs +89 -0
- package/dist/humain/mcp-adapter/vendor/mcp-oauth-provider.ts +616 -0
- package/dist/humain/mcp-adapter/vendor/mcp-output-guard.ts +408 -0
- package/dist/humain/mcp-adapter/vendor/mcp-panel.ts +1015 -0
- package/dist/humain/mcp-adapter/vendor/mcp-probe.ts +187 -0
- package/dist/humain/mcp-adapter/vendor/mcp-script-worker.mjs +130 -0
- package/dist/humain/mcp-adapter/vendor/mcp-setup-panel.ts +667 -0
- package/dist/humain/mcp-adapter/vendor/mcp-status.ts +109 -0
- package/dist/humain/mcp-adapter/vendor/mcp-trace.ts +306 -0
- package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +363 -0
- package/dist/humain/mcp-adapter/vendor/npx-resolver.ts +543 -0
- package/dist/humain/mcp-adapter/vendor/oauth-handler.ts +30 -0
- package/dist/humain/mcp-adapter/vendor/oauth.ts +48 -0
- package/dist/humain/mcp-adapter/vendor/onboarding-state.ts +76 -0
- package/dist/humain/mcp-adapter/vendor/package.json +179 -0
- package/dist/humain/mcp-adapter/vendor/panel-keys.ts +53 -0
- package/dist/humain/mcp-adapter/vendor/prompts.ts +353 -0
- package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +1331 -0
- package/dist/humain/mcp-adapter/vendor/request-headers-command.ts +336 -0
- package/dist/humain/mcp-adapter/vendor/resource-tools.ts +17 -0
- package/dist/humain/mcp-adapter/vendor/runtime-owner.ts +91 -0
- package/dist/humain/mcp-adapter/vendor/sampling-handler.ts +284 -0
- package/dist/humain/mcp-adapter/vendor/search-ranking.ts +206 -0
- package/dist/humain/mcp-adapter/vendor/server-manager.ts +1129 -0
- package/dist/humain/mcp-adapter/vendor/session-recovery.ts +151 -0
- package/dist/humain/mcp-adapter/vendor/skills/mcp-scripting/SKILL.md +38 -0
- package/dist/humain/mcp-adapter/vendor/state.ts +62 -0
- package/dist/humain/mcp-adapter/vendor/tool-approval.ts +182 -0
- package/dist/humain/mcp-adapter/vendor/tool-metadata.ts +296 -0
- package/dist/humain/mcp-adapter/vendor/tool-registrar.ts +253 -0
- package/dist/humain/mcp-adapter/vendor/tool-result-renderer.ts +423 -0
- package/dist/humain/mcp-adapter/vendor/ts-shape.ts +149 -0
- package/dist/humain/mcp-adapter/vendor/types.ts +942 -0
- package/dist/humain/mcp-adapter/vendor/ui-app-bridge-helpers.ts +40 -0
- package/dist/humain/mcp-adapter/vendor/ui-resource-handler.ts +250 -0
- package/dist/humain/mcp-adapter/vendor/ui-server.ts +866 -0
- package/dist/humain/mcp-adapter/vendor/ui-session.ts +570 -0
- package/dist/humain/mcp-adapter/vendor/ui-stream-types.ts +89 -0
- package/dist/humain/mcp-adapter/vendor/ui-tool-visibility.ts +25 -0
- package/dist/humain/mcp-adapter/vendor/unix-socket-transport.ts +85 -0
- package/dist/humain/mcp-adapter/vendor/utils.ts +310 -0
- package/dist/humain/mcp-adapter.d.ts +3 -0
- package/dist/humain/mcp-adapter.d.ts.map +1 -0
- package/dist/humain/mcp-adapter.js +5 -0
- package/dist/humain/mcp-adapter.js.map +1 -0
- package/dist/humain/pi-agent-execution-host.d.ts +34 -0
- package/dist/humain/pi-agent-execution-host.d.ts.map +1 -0
- package/dist/humain/pi-agent-execution-host.js +77 -0
- package/dist/humain/pi-agent-execution-host.js.map +1 -0
- package/dist/humain/web-access/host.d.ts +4 -0
- package/dist/humain/web-access/host.d.ts.map +1 -0
- package/dist/humain/web-access/host.js +3 -0
- package/dist/humain/web-access/host.js.map +1 -0
- package/dist/humain/web-access/index.d.ts +3 -0
- package/dist/humain/web-access/index.d.ts.map +1 -0
- package/dist/humain/web-access/index.js +5 -0
- package/dist/humain/web-access/index.js.map +1 -0
- package/dist/humain/web-access/vendor/activity.d.ts +34 -0
- package/dist/humain/web-access/vendor/activity.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/activity.js +68 -0
- package/dist/humain/web-access/vendor/activity.js.map +1 -0
- package/dist/humain/web-access/vendor/anysearch.d.ts +8 -0
- package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/anysearch.js +167 -0
- package/dist/humain/web-access/vendor/anysearch.js.map +1 -0
- package/dist/humain/web-access/vendor/auth-fetch.d.ts +13 -0
- package/dist/humain/web-access/vendor/auth-fetch.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/auth-fetch.js +134 -0
- package/dist/humain/web-access/vendor/auth-fetch.js.map +1 -0
- package/dist/humain/web-access/vendor/bocha.d.ts +4 -0
- package/dist/humain/web-access/vendor/bocha.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/bocha.js +219 -0
- package/dist/humain/web-access/vendor/bocha.js.map +1 -0
- package/dist/humain/web-access/vendor/brave.d.ts +4 -0
- package/dist/humain/web-access/vendor/brave.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/brave.js +194 -0
- package/dist/humain/web-access/vendor/brave.js.map +1 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts +12 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.js +230 -0
- package/dist/humain/web-access/vendor/brightdata-unlocker.js.map +1 -0
- package/dist/humain/web-access/vendor/brightdata.d.ts +8 -0
- package/dist/humain/web-access/vendor/brightdata.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/brightdata.js +519 -0
- package/dist/humain/web-access/vendor/brightdata.js.map +1 -0
- package/dist/humain/web-access/vendor/chrome-cookies.d.ts +23 -0
- package/dist/humain/web-access/vendor/chrome-cookies.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/chrome-cookies.js +522 -0
- package/dist/humain/web-access/vendor/chrome-cookies.js.map +1 -0
- package/dist/humain/web-access/vendor/content-find.d.ts +11 -0
- package/dist/humain/web-access/vendor/content-find.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/content-find.js +117 -0
- package/dist/humain/web-access/vendor/content-find.js.map +1 -0
- package/dist/humain/web-access/vendor/credential-source.d.ts +28 -0
- package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/credential-source.js +151 -0
- package/dist/humain/web-access/vendor/credential-source.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-page.d.ts +30 -0
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/curator-page.js +3556 -0
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts +94 -0
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/curator-server.js +690 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts +60 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.js +416 -0
- package/dist/humain/web-access/vendor/datalab-pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/declared-web-links.d.ts +16 -0
- package/dist/humain/web-access/vendor/declared-web-links.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/declared-web-links.js +168 -0
- package/dist/humain/web-access/vendor/declared-web-links.js.map +1 -0
- package/dist/humain/web-access/vendor/duckduckgo.d.ts +4 -0
- package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/duckduckgo.js +123 -0
- package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -0
- package/dist/humain/web-access/vendor/exa.d.ts +10 -0
- package/dist/humain/web-access/vendor/exa.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/exa.js +426 -0
- package/dist/humain/web-access/vendor/exa.js.map +1 -0
- package/dist/humain/web-access/vendor/extract.d.ts +48 -0
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/extract.js +1126 -0
- package/dist/humain/web-access/vendor/extract.js.map +1 -0
- package/dist/humain/web-access/vendor/feature-config.d.ts +3 -0
- package/dist/humain/web-access/vendor/feature-config.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/feature-config.js +27 -0
- package/dist/humain/web-access/vendor/feature-config.js.map +1 -0
- package/dist/humain/web-access/vendor/fetch-params.d.ts +27 -0
- package/dist/humain/web-access/vendor/fetch-params.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/fetch-params.js +71 -0
- package/dist/humain/web-access/vendor/fetch-params.js.map +1 -0
- package/dist/humain/web-access/vendor/firecrawl.d.ts +19 -0
- package/dist/humain/web-access/vendor/firecrawl.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/firecrawl.js +370 -0
- package/dist/humain/web-access/vendor/firecrawl.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-api.d.ts +27 -0
- package/dist/humain/web-access/vendor/gemini-api.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-api.js +230 -0
- package/dist/humain/web-access/vendor/gemini-api.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts +9 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.js +85 -0
- package/dist/humain/web-access/vendor/gemini-pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-search.d.ts +40 -0
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-search.js +832 -0
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-url-context.d.ts +4 -0
- package/dist/humain/web-access/vendor/gemini-url-context.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-url-context.js +101 -0
- package/dist/humain/web-access/vendor/gemini-url-context.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web-config.d.ts +4 -0
- package/dist/humain/web-access/vendor/gemini-web-config.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web-config.js +42 -0
- package/dist/humain/web-access/vendor/gemini-web-config.js.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web.d.ts +18 -0
- package/dist/humain/web-access/vendor/gemini-web.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/gemini-web.js +385 -0
- package/dist/humain/web-access/vendor/gemini-web.js.map +1 -0
- package/dist/humain/web-access/vendor/github-api.d.ts +7 -0
- package/dist/humain/web-access/vendor/github-api.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/github-api.js +160 -0
- package/dist/humain/web-access/vendor/github-api.js.map +1 -0
- package/dist/humain/web-access/vendor/github-extract.d.ts +13 -0
- package/dist/humain/web-access/vendor/github-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/github-extract.js +635 -0
- package/dist/humain/web-access/vendor/github-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/index.d.ts +4 -0
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/index.js +3076 -0
- package/dist/humain/web-access/vendor/index.js.map +1 -0
- package/dist/humain/web-access/vendor/jina-search.d.ts +8 -0
- package/dist/humain/web-access/vendor/jina-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/jina-search.js +255 -0
- package/dist/humain/web-access/vendor/jina-search.js.map +1 -0
- package/dist/humain/web-access/vendor/kagi.d.ts +15 -0
- package/dist/humain/web-access/vendor/kagi.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/kagi.js +262 -0
- package/dist/humain/web-access/vendor/kagi.js.map +1 -0
- package/dist/humain/web-access/vendor/ollama.d.ts +15 -0
- package/dist/humain/web-access/vendor/ollama.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/ollama.js +216 -0
- package/dist/humain/web-access/vendor/ollama.js.map +1 -0
- package/dist/humain/web-access/vendor/openai-search.d.ts +15 -0
- package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/openai-search.js +459 -0
- package/dist/humain/web-access/vendor/openai-search.js.map +1 -0
- package/dist/humain/web-access/vendor/page-query.d.ts +16 -0
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/page-query.js +79 -0
- package/dist/humain/web-access/vendor/page-query.js.map +1 -0
- package/dist/humain/web-access/vendor/parallel.d.ts +12 -0
- package/dist/humain/web-access/vendor/parallel.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/parallel.js +343 -0
- package/dist/humain/web-access/vendor/parallel.js.map +1 -0
- package/dist/humain/web-access/vendor/pdf-extract.d.ts +44 -0
- package/dist/humain/web-access/vendor/pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/pdf-extract.js +298 -0
- package/dist/humain/web-access/vendor/pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/perplexity.d.ts +20 -0
- package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/perplexity.js +159 -0
- package/dist/humain/web-access/vendor/perplexity.js.map +1 -0
- package/dist/humain/web-access/vendor/querit.d.ts +10 -0
- package/dist/humain/web-access/vendor/querit.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/querit.js +335 -0
- package/dist/humain/web-access/vendor/querit.js.map +1 -0
- package/dist/humain/web-access/vendor/render-search-error.d.ts +57 -0
- package/dist/humain/web-access/vendor/render-search-error.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/render-search-error.js +130 -0
- package/dist/humain/web-access/vendor/render-search-error.js.map +1 -0
- package/dist/humain/web-access/vendor/rsc-extract.d.ts +12 -0
- package/dist/humain/web-access/vendor/rsc-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/rsc-extract.js +329 -0
- package/dist/humain/web-access/vendor/rsc-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/search1api.d.ts +10 -0
- package/dist/humain/web-access/vendor/search1api.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/search1api.js +251 -0
- package/dist/humain/web-access/vendor/search1api.js.map +1 -0
- package/dist/humain/web-access/vendor/searchinfinity.d.ts +8 -0
- package/dist/humain/web-access/vendor/searchinfinity.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/searchinfinity.js +229 -0
- package/dist/humain/web-access/vendor/searchinfinity.js.map +1 -0
- package/dist/humain/web-access/vendor/searxng.d.ts +4 -0
- package/dist/humain/web-access/vendor/searxng.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/searxng.js +238 -0
- package/dist/humain/web-access/vendor/searxng.js.map +1 -0
- package/dist/humain/web-access/vendor/serpbase.d.ts +4 -0
- package/dist/humain/web-access/vendor/serpbase.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/serpbase.js +211 -0
- package/dist/humain/web-access/vendor/serpbase.js.map +1 -0
- package/dist/humain/web-access/vendor/serpdive.d.ts +8 -0
- package/dist/humain/web-access/vendor/serpdive.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/serpdive.js +267 -0
- package/dist/humain/web-access/vendor/serpdive.js.map +1 -0
- package/dist/humain/web-access/vendor/source-check.d.ts +99 -0
- package/dist/humain/web-access/vendor/source-check.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/source-check.js +205 -0
- package/dist/humain/web-access/vendor/source-check.js.map +1 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts +50 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/ssrf-protection.js +466 -0
- package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -0
- package/dist/humain/web-access/vendor/storage.d.ts +55 -0
- package/dist/humain/web-access/vendor/storage.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/storage.js +485 -0
- package/dist/humain/web-access/vendor/storage.js.map +1 -0
- package/dist/humain/web-access/vendor/summary-model-scope.d.ts +25 -0
- package/dist/humain/web-access/vendor/summary-model-scope.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/summary-model-scope.js +98 -0
- package/dist/humain/web-access/vendor/summary-model-scope.js.map +1 -0
- package/dist/humain/web-access/vendor/summary-review.d.ts +26 -0
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/summary-review.js +344 -0
- package/dist/humain/web-access/vendor/summary-review.js.map +1 -0
- package/dist/humain/web-access/vendor/tavily.d.ts +8 -0
- package/dist/humain/web-access/vendor/tavily.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/tavily.js +194 -0
- package/dist/humain/web-access/vendor/tavily.js.map +1 -0
- package/dist/humain/web-access/vendor/tinyfish.d.ts +11 -0
- package/dist/humain/web-access/vendor/tinyfish.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/tinyfish.js +331 -0
- package/dist/humain/web-access/vendor/tinyfish.js.map +1 -0
- package/dist/humain/web-access/vendor/utils.d.ts +20 -0
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/utils.js +91 -0
- package/dist/humain/web-access/vendor/utils.js.map +1 -0
- package/dist/humain/web-access/vendor/video-extract.d.ts +16 -0
- package/dist/humain/web-access/vendor/video-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/video-extract.js +335 -0
- package/dist/humain/web-access/vendor/video-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/xai-search.d.ts +13 -0
- package/dist/humain/web-access/vendor/xai-search.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/xai-search.js +331 -0
- package/dist/humain/web-access/vendor/xai-search.js.map +1 -0
- package/dist/humain/web-access/vendor/youtube-extract.d.ts +27 -0
- package/dist/humain/web-access/vendor/youtube-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/youtube-extract.js +282 -0
- package/dist/humain/web-access/vendor/youtube-extract.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +2 -2
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +169 -102
- package/dist/main.js.map +1 -1
- package/dist/modes/agent-exec-mode.d.ts +14 -0
- package/dist/modes/agent-exec-mode.d.ts.map +1 -0
- package/dist/modes/agent-exec-mode.js +92 -0
- package/dist/modes/agent-exec-mode.js.map +1 -0
- package/dist/modes/index.d.ts +4 -2
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js +2 -1
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +5 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +13 -4
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +7 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
- package/dist/modes/interactive/components/earendil-announcement.js +40 -0
- package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/markdown-transform.d.ts +3 -0
- package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
- package/dist/modes/interactive/components/markdown-transform.js +19 -0
- package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
- package/dist/modes/interactive/components/mermaid.d.ts +11 -0
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
- package/dist/modes/interactive/components/mermaid.js +75 -0
- package/dist/modes/interactive/components/mermaid.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +16 -4
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +4 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +26 -0
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +8 -2
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +30 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +3 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +9 -2
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +45 -9
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +581 -211
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/dark.json +1 -0
- package/dist/modes/interactive/theme/light.json +1 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts +3 -0
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.js +10 -1
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
- package/dist/modes/interactive/theme/theme-schema.json +5 -1
- package/dist/modes/interactive/theme/theme.d.ts +2 -2
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +24 -6
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/json-event.d.ts +28 -0
- package/dist/modes/json-event.d.ts.map +1 -0
- package/dist/modes/json-event.js +12 -0
- package/dist/modes/json-event.js.map +1 -0
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +12 -2
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +12 -5
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +55 -1
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +13 -3
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +15 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +11 -9
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/rpc-entry.d.ts.map +1 -1
- package/dist/rpc-entry.js +3 -2
- package/dist/rpc-entry.js.map +1 -1
- package/dist/server/create-harness.d.ts +26 -0
- package/dist/server/create-harness.d.ts.map +1 -0
- package/dist/server/create-harness.js +104 -0
- package/dist/server/create-harness.js.map +1 -0
- package/dist/utils/abort.d.ts +5 -0
- package/dist/utils/abort.d.ts.map +1 -0
- package/dist/utils/abort.js +48 -0
- package/dist/utils/abort.js.map +1 -0
- package/dist/utils/clipboard.d.ts +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +22 -2
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/management-http.d.ts +23 -0
- package/dist/utils/management-http.d.ts.map +1 -0
- package/dist/utils/management-http.js +50 -0
- package/dist/utils/management-http.js.map +1 -0
- package/dist/utils/paths.d.ts +3 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +23 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/tool-result-images.d.ts +19 -0
- package/dist/utils/tool-result-images.d.ts.map +1 -0
- package/dist/utils/tool-result-images.js +45 -0
- package/dist/utils/tool-result-images.js.map +1 -0
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +13 -25
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts +4 -0
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +23 -5
- package/dist/utils/version-check.js.map +1 -1
- package/docs/compaction.md +2 -2
- package/docs/custom-provider.md +7 -5
- package/docs/extensions.md +30 -5
- package/docs/humain-terminal.md +21 -1
- package/docs/json.md +24 -19
- package/docs/keybindings.md +46 -14
- package/docs/models.md +32 -11
- package/docs/providers.md +9 -1
- package/docs/quickstart.md +39 -37
- package/docs/rpc.md +31 -11
- package/docs/sdk.md +21 -2
- package/docs/security.md +21 -21
- package/docs/session-format.md +14 -14
- package/docs/settings.md +4 -1
- package/docs/themes.md +5 -3
- package/docs/usage.md +7 -0
- package/examples/extensions/custom-compaction.ts +3 -18
- package/examples/extensions/custom-provider-anthropic/index.ts +5 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +5 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/handoff.ts +4 -13
- package/examples/extensions/qna.ts +5 -9
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/summarize.ts +9 -20
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/rpc-extension-ui.ts +11 -2
- package/examples/sdk/02-custom-model.ts +2 -3
- package/examples/sdk/09-api-keys-and-oauth.ts +1 -1
- package/examples/sdk/12-full-control.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +2771 -535
- package/package.json +40 -11
- package/src/humain/mcp-adapter/UPSTREAM.md +15 -0
- package/src/humain/mcp-adapter/upstream.json +7 -0
- package/src/humain/mcp-adapter/vendor/CHANGELOG.md +673 -0
- package/src/humain/mcp-adapter/vendor/LICENSE +21 -0
- package/src/humain/web-access/UPSTREAM.md +17 -0
- package/src/humain/web-access/upstream.json +23 -0
- package/src/humain/web-access/vendor/LICENSE +21 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
// npx-resolver.ts - Resolve npx/npm exec binaries to avoid npm parent processes
|
|
2
|
+
import { existsSync, readFileSync, realpathSync, readdirSync, statSync, writeFileSync, renameSync, mkdirSync, openSync, readSync, closeSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { join, dirname, extname, resolve, sep } from "node:path";
|
|
4
|
+
import { getAgentPath } from "./agent-dir.ts";
|
|
5
|
+
import { throwIfAborted } from "./abort.ts";
|
|
6
|
+
import crossSpawn from "cross-spawn";
|
|
7
|
+
|
|
8
|
+
const CACHE_VERSION = 2;
|
|
9
|
+
const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
10
|
+
const EXACT_PACKAGE_VERSION_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;
|
|
11
|
+
|
|
12
|
+
interface NpxCacheEntry {
|
|
13
|
+
resolvedBin: string;
|
|
14
|
+
resolvedAt: number;
|
|
15
|
+
packageVersion?: string;
|
|
16
|
+
isJs: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface NpxCache {
|
|
20
|
+
version: number;
|
|
21
|
+
entries: Record<string, NpxCacheEntry>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface NpxResolution {
|
|
25
|
+
binPath: string;
|
|
26
|
+
extraArgs: string[];
|
|
27
|
+
isJs: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface ParsedInvocation {
|
|
31
|
+
packageSpec: string;
|
|
32
|
+
binName?: string;
|
|
33
|
+
extraArgs: string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ParsedPackageSpec {
|
|
37
|
+
packageName: string;
|
|
38
|
+
exactVersion?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function resolveNpxBinary(
|
|
42
|
+
command: string,
|
|
43
|
+
args: string[],
|
|
44
|
+
signal?: AbortSignal,
|
|
45
|
+
): Promise<NpxResolution | null> {
|
|
46
|
+
throwIfAborted(signal);
|
|
47
|
+
const parsed = command === "npx"
|
|
48
|
+
? parseNpxArgs(args)
|
|
49
|
+
: command === "npm"
|
|
50
|
+
? parseNpmExecArgs(args)
|
|
51
|
+
: null;
|
|
52
|
+
|
|
53
|
+
if (!parsed) return null;
|
|
54
|
+
|
|
55
|
+
const packageSpec = parsePackageSpec(parsed.packageSpec);
|
|
56
|
+
const cacheKey = JSON.stringify([command, parsed.packageSpec, parsed.binName ?? ""]);
|
|
57
|
+
const cache = loadCache();
|
|
58
|
+
const cached = cache?.entries?.[cacheKey];
|
|
59
|
+
|
|
60
|
+
if (
|
|
61
|
+
cached
|
|
62
|
+
&& Date.now() - cached.resolvedAt < CACHE_TTL_MS
|
|
63
|
+
&& existsSync(cached.resolvedBin)
|
|
64
|
+
&& (!packageSpec?.exactVersion || cached.packageVersion === packageSpec.exactVersion)
|
|
65
|
+
) {
|
|
66
|
+
return { binPath: cached.resolvedBin, extraArgs: parsed.extraArgs, isJs: cached.isJs };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const resolved = resolveFromNpmCache(parsed.packageSpec, parsed.binName);
|
|
70
|
+
if (resolved) {
|
|
71
|
+
saveCacheEntry(cacheKey, resolved);
|
|
72
|
+
return { binPath: resolved.resolvedBin, extraArgs: parsed.extraArgs, isJs: resolved.isJs };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Slow path: force npx cache population
|
|
76
|
+
await forceNpxCache(parsed.packageSpec, signal);
|
|
77
|
+
const resolvedAfterInstall = resolveFromNpmCache(parsed.packageSpec, parsed.binName);
|
|
78
|
+
if (resolvedAfterInstall) {
|
|
79
|
+
saveCacheEntry(cacheKey, resolvedAfterInstall);
|
|
80
|
+
return { binPath: resolvedAfterInstall.resolvedBin, extraArgs: parsed.extraArgs, isJs: resolvedAfterInstall.isJs };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function parseNpxArgs(args: string[]): ParsedInvocation | null {
|
|
87
|
+
const separatorIndex = args.indexOf("--");
|
|
88
|
+
const before = separatorIndex >= 0 ? args.slice(0, separatorIndex) : args;
|
|
89
|
+
const after = separatorIndex >= 0 ? args.slice(separatorIndex + 1) : [];
|
|
90
|
+
|
|
91
|
+
const positionals: string[] = [];
|
|
92
|
+
let packageSpec: string | undefined;
|
|
93
|
+
let sawPackageFlag = false;
|
|
94
|
+
let foundFirstPositional = false;
|
|
95
|
+
|
|
96
|
+
for (let i = 0; i < before.length; i++) {
|
|
97
|
+
const arg = before[i];
|
|
98
|
+
if (arg === undefined) return null;
|
|
99
|
+
if (foundFirstPositional) {
|
|
100
|
+
positionals.push(arg);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (arg === "-y" || arg === "--yes") continue;
|
|
104
|
+
if (arg === "-p" || arg === "--package") {
|
|
105
|
+
const value = before[i + 1];
|
|
106
|
+
if (!value || value.startsWith("-")) return null;
|
|
107
|
+
if (!packageSpec) packageSpec = value;
|
|
108
|
+
sawPackageFlag = true;
|
|
109
|
+
i++;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (arg.startsWith("--package=")) {
|
|
113
|
+
const value = arg.slice("--package=".length);
|
|
114
|
+
if (!value) return null;
|
|
115
|
+
if (!packageSpec) packageSpec = value;
|
|
116
|
+
sawPackageFlag = true;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (arg.startsWith("-")) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
positionals.push(arg);
|
|
123
|
+
foundFirstPositional = true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const separatedAfter = separatorIndex >= 0 && after.length > 0 ? ["--", ...after] : after;
|
|
127
|
+
|
|
128
|
+
if (sawPackageFlag) {
|
|
129
|
+
const binName = positionals[0];
|
|
130
|
+
if (!packageSpec || !binName) return null;
|
|
131
|
+
const extraArgs = positionals.slice(1).concat(separatedAfter);
|
|
132
|
+
return { packageSpec, binName, extraArgs };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const packagePositional = positionals[0];
|
|
136
|
+
if (!packagePositional) return null;
|
|
137
|
+
const extraArgs = positionals.slice(1).concat(separatedAfter);
|
|
138
|
+
return { packageSpec: packagePositional, extraArgs };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function parseNpmExecArgs(args: string[]): ParsedInvocation | null {
|
|
142
|
+
if (args[0] !== "exec") return null;
|
|
143
|
+
const execArgs = args.slice(1);
|
|
144
|
+
const separatorIndex = execArgs.indexOf("--");
|
|
145
|
+
if (separatorIndex < 0) return null;
|
|
146
|
+
|
|
147
|
+
const before = execArgs.slice(0, separatorIndex);
|
|
148
|
+
const after = execArgs.slice(separatorIndex + 1);
|
|
149
|
+
|
|
150
|
+
let packageSpec: string | undefined;
|
|
151
|
+
for (let i = 0; i < before.length; i++) {
|
|
152
|
+
const arg = before[i];
|
|
153
|
+
if (arg === undefined) return null;
|
|
154
|
+
if (arg === "-y" || arg === "--yes") continue;
|
|
155
|
+
if (arg === "--package") {
|
|
156
|
+
const value = before[i + 1];
|
|
157
|
+
if (!value || value.startsWith("-")) return null;
|
|
158
|
+
if (!packageSpec) packageSpec = value;
|
|
159
|
+
i++;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (arg.startsWith("--package=")) {
|
|
163
|
+
const value = arg.slice("--package=".length);
|
|
164
|
+
if (!value) return null;
|
|
165
|
+
if (!packageSpec) packageSpec = value;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (arg.startsWith("-")) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const binName = after[0];
|
|
174
|
+
if (!packageSpec || !binName) return null;
|
|
175
|
+
const extraArgs = after.slice(1);
|
|
176
|
+
return { packageSpec, binName, extraArgs };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function resolveFromNpmCache(packageSpec: string, binName?: string): NpxCacheEntry | null {
|
|
180
|
+
const cacheDir = getNpmCacheDir();
|
|
181
|
+
if (!cacheDir) return null;
|
|
182
|
+
|
|
183
|
+
const parsedSpec = parsePackageSpec(packageSpec);
|
|
184
|
+
if (!parsedSpec) return null;
|
|
185
|
+
|
|
186
|
+
const { packageName, exactVersion } = parsedSpec;
|
|
187
|
+
const packageDir = findCachedPackageDir(cacheDir, packageName, exactVersion);
|
|
188
|
+
if (!packageDir) return null;
|
|
189
|
+
|
|
190
|
+
const packageJsonPath = join(packageDir, "package.json");
|
|
191
|
+
if (!existsSync(packageJsonPath)) return null;
|
|
192
|
+
|
|
193
|
+
let pkg: { bin?: string | Record<string, string>; version?: string } | null = null;
|
|
194
|
+
try {
|
|
195
|
+
pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as {
|
|
196
|
+
bin?: string | Record<string, string>;
|
|
197
|
+
version?: string;
|
|
198
|
+
};
|
|
199
|
+
} catch {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const binField = pkg?.bin;
|
|
204
|
+
if (!binField) return null;
|
|
205
|
+
|
|
206
|
+
const candidates = buildBinCandidates(packageName, binName);
|
|
207
|
+
let chosenBinName: string | undefined;
|
|
208
|
+
let binRel: string | undefined;
|
|
209
|
+
|
|
210
|
+
if (typeof binField === "string") {
|
|
211
|
+
chosenBinName = defaultBinName(packageName);
|
|
212
|
+
binRel = binField;
|
|
213
|
+
} else {
|
|
214
|
+
for (const candidate of candidates) {
|
|
215
|
+
if (binField[candidate]) {
|
|
216
|
+
chosenBinName = candidate;
|
|
217
|
+
binRel = binField[candidate];
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (!binRel) {
|
|
222
|
+
const firstEntry = Object.entries(binField)[0];
|
|
223
|
+
if (firstEntry) {
|
|
224
|
+
chosenBinName = firstEntry[0];
|
|
225
|
+
binRel = firstEntry[1];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (!binRel) return null;
|
|
231
|
+
|
|
232
|
+
const nodeModulesDir = findNodeModulesDir(packageDir);
|
|
233
|
+
const binLink = chosenBinName ? join(nodeModulesDir, ".bin", chosenBinName) : null;
|
|
234
|
+
let resolvedBin = binLink && existsSync(binLink) ? safeRealpath(binLink) : "";
|
|
235
|
+
if (!resolvedBin) {
|
|
236
|
+
resolvedBin = resolve(packageDir, binRel);
|
|
237
|
+
if (!existsSync(resolvedBin)) return null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const isJs = detectJsBinary(resolvedBin);
|
|
241
|
+
return {
|
|
242
|
+
resolvedBin,
|
|
243
|
+
resolvedAt: Date.now(),
|
|
244
|
+
...(pkg?.version !== undefined ? { packageVersion: pkg.version } : {}),
|
|
245
|
+
isJs,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const FORCE_CACHE_TIMEOUT_MS = 30_000;
|
|
250
|
+
|
|
251
|
+
async function forceNpxCache(packageSpec: string, signal?: AbortSignal): Promise<void> {
|
|
252
|
+
throwIfAborted(signal);
|
|
253
|
+
try {
|
|
254
|
+
await new Promise<void>((resolve, reject) => {
|
|
255
|
+
const proc = crossSpawn(
|
|
256
|
+
"npm",
|
|
257
|
+
["exec", "--yes", "--package", packageSpec, "--", "node", "-e", "1"],
|
|
258
|
+
{ stdio: "ignore" }
|
|
259
|
+
);
|
|
260
|
+
const timer = setTimeout(() => {
|
|
261
|
+
proc.kill();
|
|
262
|
+
reject(new Error("timeout"));
|
|
263
|
+
}, FORCE_CACHE_TIMEOUT_MS);
|
|
264
|
+
const abort = () => {
|
|
265
|
+
proc.kill();
|
|
266
|
+
reject(signal?.reason instanceof Error ? signal.reason : new Error("MCP request aborted"));
|
|
267
|
+
};
|
|
268
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
269
|
+
timer.unref();
|
|
270
|
+
proc.on("close", () => {
|
|
271
|
+
clearTimeout(timer);
|
|
272
|
+
signal?.removeEventListener("abort", abort);
|
|
273
|
+
resolve();
|
|
274
|
+
});
|
|
275
|
+
proc.on("error", (err) => {
|
|
276
|
+
clearTimeout(timer);
|
|
277
|
+
signal?.removeEventListener("abort", abort);
|
|
278
|
+
reject(err);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
} catch (error) {
|
|
282
|
+
if (signal?.aborted) throwIfAborted(signal);
|
|
283
|
+
// Ignore failures, resolution will fall back to original command
|
|
284
|
+
}
|
|
285
|
+
throwIfAborted(signal);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function buildBinCandidates(packageName: string, explicitBin?: string): string[] {
|
|
289
|
+
const candidates: string[] = [];
|
|
290
|
+
if (explicitBin) candidates.push(explicitBin);
|
|
291
|
+
|
|
292
|
+
if (packageName.startsWith("@")) {
|
|
293
|
+
const namePart = packageName.split("/")[1] ?? "";
|
|
294
|
+
const scopePart = packageName.split("/")[0]?.replace("@", "") ?? "";
|
|
295
|
+
if (namePart) candidates.push(namePart);
|
|
296
|
+
if (scopePart && namePart) candidates.push(`${scopePart}-${namePart}`);
|
|
297
|
+
} else {
|
|
298
|
+
candidates.push(packageName);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return [...new Set(candidates.filter(Boolean))];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function parsePackageSpec(spec: string): ParsedPackageSpec | null {
|
|
305
|
+
const trimmed = spec.trim();
|
|
306
|
+
if (!trimmed) return null;
|
|
307
|
+
|
|
308
|
+
let packageName: string;
|
|
309
|
+
let requestedVersion: string | undefined;
|
|
310
|
+
if (trimmed.startsWith("@")) {
|
|
311
|
+
const slashIndex = trimmed.indexOf("/");
|
|
312
|
+
if (slashIndex < 0) return null;
|
|
313
|
+
const atIndex = trimmed.lastIndexOf("@");
|
|
314
|
+
if (atIndex > slashIndex) {
|
|
315
|
+
packageName = trimmed.slice(0, atIndex);
|
|
316
|
+
requestedVersion = trimmed.slice(atIndex + 1);
|
|
317
|
+
} else {
|
|
318
|
+
packageName = trimmed;
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
const atIndex = trimmed.indexOf("@");
|
|
322
|
+
if (atIndex >= 0) {
|
|
323
|
+
packageName = trimmed.slice(0, atIndex);
|
|
324
|
+
requestedVersion = trimmed.slice(atIndex + 1);
|
|
325
|
+
} else {
|
|
326
|
+
packageName = trimmed;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (!packageName) return null;
|
|
331
|
+
const normalizedVersion = requestedVersion?.replace(/^=/, "").replace(/^v/i, "");
|
|
332
|
+
return {
|
|
333
|
+
packageName,
|
|
334
|
+
...(normalizedVersion && EXACT_PACKAGE_VERSION_RE.test(normalizedVersion)
|
|
335
|
+
? { exactVersion: normalizedVersion }
|
|
336
|
+
: {}),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function defaultBinName(packageName: string): string {
|
|
341
|
+
if (packageName.startsWith("@")) {
|
|
342
|
+
const parts = packageName.split("/");
|
|
343
|
+
return parts[1] ?? packageName.replace("@", "").replace("/", "-");
|
|
344
|
+
}
|
|
345
|
+
return packageName;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function findCachedPackageDir(cacheDir: string, packageName: string, exactVersion?: string): string | null {
|
|
349
|
+
const npxDir = join(cacheDir, "_npx");
|
|
350
|
+
if (!existsSync(npxDir)) return null;
|
|
351
|
+
|
|
352
|
+
const packagePathParts = packageName.startsWith("@")
|
|
353
|
+
? packageName.split("/")
|
|
354
|
+
: [packageName];
|
|
355
|
+
|
|
356
|
+
const candidates = readdirSync(npxDir, { withFileTypes: true })
|
|
357
|
+
.filter(entry => entry.isDirectory())
|
|
358
|
+
.map(entry => {
|
|
359
|
+
const full = join(npxDir, entry.name);
|
|
360
|
+
const mtime = safeStatMtime(full);
|
|
361
|
+
return { name: entry.name, mtime };
|
|
362
|
+
})
|
|
363
|
+
.sort((a, b) => b.mtime - a.mtime);
|
|
364
|
+
|
|
365
|
+
for (const entry of candidates) {
|
|
366
|
+
const pkgDir = join(npxDir, entry.name, "node_modules", ...packagePathParts);
|
|
367
|
+
const packageJsonPath = join(pkgDir, "package.json");
|
|
368
|
+
if (!existsSync(packageJsonPath)) continue;
|
|
369
|
+
if (exactVersion) {
|
|
370
|
+
try {
|
|
371
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as { version?: unknown };
|
|
372
|
+
if (pkg.version !== exactVersion) continue;
|
|
373
|
+
} catch {
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return pkgDir;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function findNodeModulesDir(packageDir: string): string {
|
|
384
|
+
const parts = packageDir.split(sep);
|
|
385
|
+
const idx = parts.lastIndexOf("node_modules");
|
|
386
|
+
if (idx >= 0) {
|
|
387
|
+
return parts.slice(0, idx + 1).join(sep);
|
|
388
|
+
}
|
|
389
|
+
return join(packageDir, "..");
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function detectJsBinary(binPath: string): boolean {
|
|
393
|
+
const ext = extname(binPath).toLowerCase();
|
|
394
|
+
if (ext === ".js" || ext === ".mjs" || ext === ".cjs") return true;
|
|
395
|
+
try {
|
|
396
|
+
const fd = openSync(binPath, "r");
|
|
397
|
+
try {
|
|
398
|
+
const buf = Buffer.alloc(256);
|
|
399
|
+
readSync(fd, buf, 0, 256, 0);
|
|
400
|
+
const firstLine = buf.toString("utf-8").split("\n")[0] ?? "";
|
|
401
|
+
return firstLine.startsWith("#!") && firstLine.includes("node");
|
|
402
|
+
} finally {
|
|
403
|
+
closeSync(fd);
|
|
404
|
+
}
|
|
405
|
+
} catch {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
let npmCacheDirCached: string | null | undefined;
|
|
411
|
+
|
|
412
|
+
function getNpmCacheDir(): string | null {
|
|
413
|
+
if (npmCacheDirCached !== undefined) return npmCacheDirCached;
|
|
414
|
+
if (process.env.NPM_CONFIG_CACHE) {
|
|
415
|
+
npmCacheDirCached = process.env.NPM_CONFIG_CACHE;
|
|
416
|
+
return npmCacheDirCached;
|
|
417
|
+
}
|
|
418
|
+
try {
|
|
419
|
+
const result = crossSpawn.sync("npm", ["config", "get", "cache"], { encoding: "utf-8" });
|
|
420
|
+
if (result.status === 0) {
|
|
421
|
+
const path = String(result.stdout).trim();
|
|
422
|
+
npmCacheDirCached = path || null;
|
|
423
|
+
return npmCacheDirCached;
|
|
424
|
+
}
|
|
425
|
+
} catch {
|
|
426
|
+
npmCacheDirCached = null;
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
npmCacheDirCached = null;
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function getNpxCachePath(): string {
|
|
434
|
+
return getAgentPath("mcp-npx-cache.json");
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function readNpxCachePayload(cachePath: string): unknown | null {
|
|
438
|
+
if (!existsSync(cachePath)) return null;
|
|
439
|
+
try {
|
|
440
|
+
return JSON.parse(readFileSync(cachePath, "utf-8")) as unknown;
|
|
441
|
+
} catch {
|
|
442
|
+
return null;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function asRecord(value: unknown): Record<string, unknown> | null {
|
|
447
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
448
|
+
? value as Record<string, unknown>
|
|
449
|
+
: null;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function createCacheEntries(): Record<string, NpxCacheEntry> {
|
|
453
|
+
return Object.create(null) as Record<string, NpxCacheEntry>;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function toNpxCacheEntry(value: unknown): NpxCacheEntry | null {
|
|
457
|
+
const raw = asRecord(value);
|
|
458
|
+
if (!raw) return null;
|
|
459
|
+
if (typeof raw.resolvedBin !== "string") return null;
|
|
460
|
+
if (typeof raw.resolvedAt !== "number" || !Number.isFinite(raw.resolvedAt)) return null;
|
|
461
|
+
if (typeof raw.isJs !== "boolean") return null;
|
|
462
|
+
if (raw.packageVersion !== undefined && typeof raw.packageVersion !== "string") return null;
|
|
463
|
+
return {
|
|
464
|
+
resolvedBin: raw.resolvedBin,
|
|
465
|
+
resolvedAt: raw.resolvedAt,
|
|
466
|
+
...(raw.packageVersion !== undefined ? { packageVersion: raw.packageVersion } : {}),
|
|
467
|
+
isJs: raw.isJs,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function toNpxCache(value: unknown): NpxCache | null {
|
|
472
|
+
const raw = asRecord(value);
|
|
473
|
+
if (!raw || raw.version !== CACHE_VERSION) return null;
|
|
474
|
+
const rawEntries = asRecord(raw.entries);
|
|
475
|
+
if (!rawEntries) return null;
|
|
476
|
+
|
|
477
|
+
const entries = createCacheEntries();
|
|
478
|
+
for (const [key, rawEntry] of Object.entries(rawEntries)) {
|
|
479
|
+
const entry = toNpxCacheEntry(rawEntry);
|
|
480
|
+
if (entry) entries[key] = entry;
|
|
481
|
+
}
|
|
482
|
+
return { version: CACHE_VERSION, entries };
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function clearLegacyCache(): boolean {
|
|
486
|
+
const cachePath = getNpxCachePath();
|
|
487
|
+
const raw = asRecord(readNpxCachePayload(cachePath));
|
|
488
|
+
if (raw?.version !== 1) return false;
|
|
489
|
+
try {
|
|
490
|
+
unlinkSync(cachePath);
|
|
491
|
+
} catch {
|
|
492
|
+
try {
|
|
493
|
+
writeFileSync(cachePath, "", "utf-8");
|
|
494
|
+
} catch {
|
|
495
|
+
// Cache cleanup is best effort; resolution must still proceed.
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return true;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
clearLegacyCache();
|
|
502
|
+
|
|
503
|
+
function loadCache(): NpxCache | null {
|
|
504
|
+
if (clearLegacyCache()) return null;
|
|
505
|
+
|
|
506
|
+
return toNpxCache(readNpxCachePayload(getNpxCachePath()));
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function saveCacheEntry(key: string, entry: NpxCacheEntry): void {
|
|
510
|
+
try {
|
|
511
|
+
const cachePath = getNpxCachePath();
|
|
512
|
+
const dir = dirname(cachePath);
|
|
513
|
+
mkdirSync(dir, { recursive: true });
|
|
514
|
+
|
|
515
|
+
const existing = toNpxCache(readNpxCachePayload(cachePath));
|
|
516
|
+
const entries = createCacheEntries();
|
|
517
|
+
if (existing) Object.assign(entries, existing.entries);
|
|
518
|
+
const merged: NpxCache = { version: CACHE_VERSION, entries };
|
|
519
|
+
|
|
520
|
+
merged.entries[key] = entry;
|
|
521
|
+
const tmpPath = `${cachePath}.${process.pid}.tmp`;
|
|
522
|
+
writeFileSync(tmpPath, JSON.stringify(merged, null, 2), "utf-8");
|
|
523
|
+
renameSync(tmpPath, cachePath);
|
|
524
|
+
} catch {
|
|
525
|
+
// Cache writes are best effort; resolution must still proceed.
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function safeRealpath(path: string): string {
|
|
530
|
+
try {
|
|
531
|
+
return realpathSync(path);
|
|
532
|
+
} catch {
|
|
533
|
+
return "";
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function safeStatMtime(path: string): number {
|
|
538
|
+
try {
|
|
539
|
+
return statSync(path).mtimeMs;
|
|
540
|
+
} catch {
|
|
541
|
+
return 0;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// oauth-handler.ts - OAuth token compatibility helpers for MCP servers
|
|
2
|
+
import type { OAuthTokens } from "@modelcontextprotocol/client";
|
|
3
|
+
import { getAuthEntry } from "./mcp-auth.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get stored OAuth tokens for a server (if any).
|
|
7
|
+
* Returns undefined if no tokens exist or tokens are expired.
|
|
8
|
+
*
|
|
9
|
+
* Persistent credentials are read from the OS secure credential store. Legacy
|
|
10
|
+
* plaintext entries are imported through mcp-auth.ts before this returns.
|
|
11
|
+
*/
|
|
12
|
+
export function getStoredTokens(serverName: string): OAuthTokens | undefined {
|
|
13
|
+
const tokens = getAuthEntry(serverName)?.tokens;
|
|
14
|
+
if (!tokens) return undefined;
|
|
15
|
+
|
|
16
|
+
if (tokens.expiresAt !== undefined && tokens.expiresAt < Date.now() / 1000) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
access_token: tokens.accessToken,
|
|
22
|
+
token_type: "Bearer",
|
|
23
|
+
refresh_token: tokens.refreshToken,
|
|
24
|
+
expires_in: tokens.expiresAt !== undefined
|
|
25
|
+
? Math.max(0, Math.floor(tokens.expiresAt - Date.now() / 1000))
|
|
26
|
+
: undefined,
|
|
27
|
+
scope: tokens.scope,
|
|
28
|
+
...(tokens.issuer !== undefined ? { issuer: tokens.issuer } : {}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getValidToken } from "./mcp-auth-flow.ts";
|
|
2
|
+
import {
|
|
3
|
+
inspectAuthForUrl,
|
|
4
|
+
updateTokens,
|
|
5
|
+
type AuthStorageOptions,
|
|
6
|
+
type StoredTokens,
|
|
7
|
+
} from "./mcp-auth.ts";
|
|
8
|
+
|
|
9
|
+
export type McpOAuthTokens = StoredTokens;
|
|
10
|
+
export type McpOAuthStorageOptions = AuthStorageOptions;
|
|
11
|
+
export interface McpOAuthTokenOptions {
|
|
12
|
+
authStorageOptions?: McpOAuthStorageOptions;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
skipIssuerMetadataValidation?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type McpOAuthTokenStatus =
|
|
17
|
+
| { status: "present"; tokens: McpOAuthTokens }
|
|
18
|
+
| { status: "absent" }
|
|
19
|
+
| { status: "unavailable"; message: string };
|
|
20
|
+
|
|
21
|
+
export async function getMcpOAuthTokensForUrl(
|
|
22
|
+
serverName: string,
|
|
23
|
+
serverUrl: string,
|
|
24
|
+
options: McpOAuthTokenOptions = {},
|
|
25
|
+
): Promise<McpOAuthTokens | undefined> {
|
|
26
|
+
return (await getValidToken(serverName, serverUrl, options)) ?? undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function inspectMcpOAuthTokensForUrl(
|
|
30
|
+
serverName: string,
|
|
31
|
+
serverUrl: string,
|
|
32
|
+
options?: McpOAuthStorageOptions,
|
|
33
|
+
): McpOAuthTokenStatus {
|
|
34
|
+
const status = inspectAuthForUrl(serverName, serverUrl, options);
|
|
35
|
+
if (status.status !== "present") return status;
|
|
36
|
+
return status.entry.tokens
|
|
37
|
+
? { status: "present", tokens: status.entry.tokens }
|
|
38
|
+
: { status: "absent" };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function updateMcpOAuthTokensForUrl(
|
|
42
|
+
serverName: string,
|
|
43
|
+
serverUrl: string,
|
|
44
|
+
tokens: McpOAuthTokens,
|
|
45
|
+
options?: McpOAuthStorageOptions,
|
|
46
|
+
): void {
|
|
47
|
+
updateTokens(serverName, tokens, serverUrl, options);
|
|
48
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { getAgentPath } from "./agent-dir.ts";
|
|
4
|
+
|
|
5
|
+
export interface McpOnboardingState {
|
|
6
|
+
version: 1;
|
|
7
|
+
sharedConfigHintShown: boolean;
|
|
8
|
+
setupCompleted: boolean;
|
|
9
|
+
lastDiscoveryFingerprint?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const DEFAULT_STATE: McpOnboardingState = {
|
|
13
|
+
version: 1,
|
|
14
|
+
sharedConfigHintShown: false,
|
|
15
|
+
setupCompleted: false,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function getOnboardingStatePath(): string {
|
|
19
|
+
return getAgentPath("mcp-onboarding.json");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function loadOnboardingState(): McpOnboardingState {
|
|
23
|
+
const path = getOnboardingStatePath();
|
|
24
|
+
if (!existsSync(path)) return { ...DEFAULT_STATE };
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const raw = JSON.parse(readFileSync(path, "utf-8")) as Partial<McpOnboardingState>;
|
|
28
|
+
if (!raw || typeof raw !== "object") return { ...DEFAULT_STATE };
|
|
29
|
+
return {
|
|
30
|
+
version: 1,
|
|
31
|
+
sharedConfigHintShown: raw.sharedConfigHintShown === true,
|
|
32
|
+
setupCompleted: raw.setupCompleted === true,
|
|
33
|
+
...(typeof raw.lastDiscoveryFingerprint === "string"
|
|
34
|
+
? { lastDiscoveryFingerprint: raw.lastDiscoveryFingerprint }
|
|
35
|
+
: {}),
|
|
36
|
+
};
|
|
37
|
+
} catch {
|
|
38
|
+
return { ...DEFAULT_STATE };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function saveOnboardingState(state: McpOnboardingState): void {
|
|
43
|
+
const path = getOnboardingStatePath();
|
|
44
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
45
|
+
const tmpPath = `${path}.${process.pid}.tmp`;
|
|
46
|
+
writeFileSync(tmpPath, `${JSON.stringify(state, null, 2)}\n`, "utf-8");
|
|
47
|
+
renameSync(tmpPath, path);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function updateOnboardingState(updater: (state: McpOnboardingState) => McpOnboardingState): McpOnboardingState {
|
|
51
|
+
const next = updater(loadOnboardingState());
|
|
52
|
+
saveOnboardingState(next);
|
|
53
|
+
return next;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function markSharedConfigHintShown(fingerprint?: string): McpOnboardingState {
|
|
57
|
+
return updateOnboardingState((state) => {
|
|
58
|
+
const lastDiscoveryFingerprint = fingerprint ?? state.lastDiscoveryFingerprint;
|
|
59
|
+
return {
|
|
60
|
+
...state,
|
|
61
|
+
sharedConfigHintShown: true,
|
|
62
|
+
...(lastDiscoveryFingerprint !== undefined ? { lastDiscoveryFingerprint } : {}),
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function markSetupCompleted(fingerprint?: string): McpOnboardingState {
|
|
68
|
+
return updateOnboardingState((state) => {
|
|
69
|
+
const lastDiscoveryFingerprint = fingerprint ?? state.lastDiscoveryFingerprint;
|
|
70
|
+
return {
|
|
71
|
+
...state,
|
|
72
|
+
setupCompleted: true,
|
|
73
|
+
...(lastDiscoveryFingerprint !== undefined ? { lastDiscoveryFingerprint } : {}),
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
}
|