@herbertgao/pi-extensions 2026.9.17 → 2026.9.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -15
- package/node_modules/@herbertgao/pi-bark/package.json +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +4 -1
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +4 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +75 -75
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/package.json +7 -7
- package/node_modules/@herbertgao/resume-from/package.json +4 -2
- package/node_modules/@herbertgao/sol-pi/package.json +6 -6
- package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +99 -99
- package/node_modules/@pi-plugins/fast-mode/package.json +1 -1
- package/node_modules/@tifan/pi-handoff/package.json +1 -1
- package/node_modules/@tifan/pi-handoff/src/index.ts +56 -26
- package/node_modules/@tifan/pi-mermaid-open/package.json +1 -1
- package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
- package/node_modules/@tifan/pi-recap/package.json +1 -1
- package/node_modules/@tifan/pi-rename/package.json +1 -1
- package/node_modules/pi-antigravity/package.json +2 -2
- package/node_modules/pi-lens/package.json +158 -158
- package/node_modules/pi-multi-account/package.json +2 -2
- package/node_modules/pi-typesafe/README.md +1 -1
- package/node_modules/pi-typesafe/dist/auth.d.ts +9 -5
- package/node_modules/pi-typesafe/dist/auth.js +7 -3
- package/node_modules/pi-typesafe/dist/backends.d.ts +33 -3
- package/node_modules/pi-typesafe/dist/backends.js +95 -1
- package/node_modules/pi-typesafe/dist/client.d.ts +5 -5
- package/node_modules/pi-typesafe/dist/client.js +12 -9
- package/node_modules/pi-typesafe/dist/credentials.d.ts +14 -8
- package/node_modules/pi-typesafe/dist/credentials.js +10 -7
- package/node_modules/pi-typesafe/dist/errors.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/index.js +1 -1
- package/node_modules/pi-typesafe/dist/login.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/login.js +2 -2
- package/node_modules/pi-typesafe/package.json +5 -5
- package/node_modules/pi-web-access/package.json +2 -2
- package/node_modules/remote-pi/package.json +5 -1
- package/package.json +16 -28
- package/node_modules/pi-mcp-adapter/CHANGELOG.md +0 -1013
- package/node_modules/pi-mcp-adapter/LICENSE +0 -21
- package/node_modules/pi-mcp-adapter/OAUTH.md +0 -369
- package/node_modules/pi-mcp-adapter/README.md +0 -1021
- package/node_modules/pi-mcp-adapter/abort.ts +0 -34
- package/node_modules/pi-mcp-adapter/agent-dir.ts +0 -68
- package/node_modules/pi-mcp-adapter/agent-plugin-loader.ts +0 -416
- package/node_modules/pi-mcp-adapter/agent-plugin-provenance.ts +0 -36
- package/node_modules/pi-mcp-adapter/app-bridge.bundle.js +0 -67
- package/node_modules/pi-mcp-adapter/banner.png +0 -0
- package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +0 -193
- package/node_modules/pi-mcp-adapter/claude-plugin-loader.ts +0 -365
- package/node_modules/pi-mcp-adapter/cli.js +0 -454
- package/node_modules/pi-mcp-adapter/commands.ts +0 -861
- package/node_modules/pi-mcp-adapter/config.ts +0 -1565
- package/node_modules/pi-mcp-adapter/consent-manager.ts +0 -95
- package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +0 -244
- package/node_modules/pi-mcp-adapter/direct-tools.ts +0 -428
- package/node_modules/pi-mcp-adapter/dist/abort.d.ts +0 -2
- package/node_modules/pi-mcp-adapter/dist/abort.js +0 -36
- package/node_modules/pi-mcp-adapter/dist/abort.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/agent-dir.d.ts +0 -10
- package/node_modules/pi-mcp-adapter/dist/agent-dir.js +0 -63
- package/node_modules/pi-mcp-adapter/dist/agent-dir.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.d.ts +0 -8
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js +0 -398
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.d.ts +0 -1
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js +0 -31
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +0 -6
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +0 -194
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.d.ts +0 -9
- package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js +0 -362
- package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/config.d.ts +0 -134
- package/node_modules/pi-mcp-adapter/dist/config.js +0 -1361
- package/node_modules/pi-mcp-adapter/dist/config.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +0 -18
- package/node_modules/pi-mcp-adapter/dist/consent-manager.js +0 -88
- package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +0 -17
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +0 -316
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/errors.d.ts +0 -131
- package/node_modules/pi-mcp-adapter/dist/errors.js +0 -278
- package/node_modules/pi-mcp-adapter/dist/errors.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +0 -8
- package/node_modules/pi-mcp-adapter/dist/http-ca.js +0 -88
- package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +0 -14
- package/node_modules/pi-mcp-adapter/dist/jev-client.js +0 -367
- package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +0 -77
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +0 -2
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +0 -51
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +0 -205
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +0 -2
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +0 -68
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +0 -56
- package/node_modules/pi-mcp-adapter/dist/lifecycle.js +0 -410
- package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/logger.d.ts +0 -51
- package/node_modules/pi-mcp-adapter/dist/logger.js +0 -131
- package/node_modules/pi-mcp-adapter/dist/logger.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +0 -26
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +0 -103
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +0 -118
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +0 -1097
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +0 -170
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +0 -1142
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +0 -24
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +0 -203
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +0 -53
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +0 -441
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +0 -148
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +0 -689
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +0 -6
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +0 -166
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +0 -102
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +0 -369
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +0 -95
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +0 -242
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.d.ts +0 -19
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +0 -301
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +0 -6
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +0 -505
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.d.ts +0 -2
- package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js +0 -144
- package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +0 -10
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +0 -312
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/resource-tools.d.ts +0 -1
- package/node_modules/pi-mcp-adapter/dist/resource-tools.js +0 -15
- package/node_modules/pi-mcp-adapter/dist/resource-tools.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +0 -13
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +0 -97
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +0 -17
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +0 -203
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +0 -11
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +0 -172
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +0 -157
- package/node_modules/pi-mcp-adapter/dist/server-manager.js +0 -1745
- package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +0 -34
- package/node_modules/pi-mcp-adapter/dist/session-approvals.js +0 -140
- package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +0 -26
- package/node_modules/pi-mcp-adapter/dist/session-recovery.js +0 -142
- package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/state.d.ts +0 -73
- package/node_modules/pi-mcp-adapter/dist/state.js +0 -2
- package/node_modules/pi-mcp-adapter/dist/state.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/types.d.ts +0 -642
- package/node_modules/pi-mcp-adapter/dist/types.js +0 -331
- package/node_modules/pi-mcp-adapter/dist/types.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.d.ts +0 -6
- package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js +0 -37
- package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +0 -17
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +0 -219
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/ui-stream-types.d.ts +0 -104
- package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js +0 -59
- package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.d.ts +0 -4
- package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js +0 -27
- package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +0 -15
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +0 -85
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/utils.d.ts +0 -41
- package/node_modules/pi-mcp-adapter/dist/utils.js +0 -417
- package/node_modules/pi-mcp-adapter/dist/utils.js.map +0 -1
- package/node_modules/pi-mcp-adapter/elicitation-handler.ts +0 -358
- package/node_modules/pi-mcp-adapter/error-signal.ts +0 -32
- package/node_modules/pi-mcp-adapter/errors.ts +0 -364
- package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +0 -85
- package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +0 -34
- package/node_modules/pi-mcp-adapter/failure-backoff.ts +0 -23
- package/node_modules/pi-mcp-adapter/glimpse-ui.ts +0 -80
- package/node_modules/pi-mcp-adapter/host-html-template.ts +0 -515
- package/node_modules/pi-mcp-adapter/http-ca.ts +0 -84
- package/node_modules/pi-mcp-adapter/index.ts +0 -2106
- package/node_modules/pi-mcp-adapter/init.ts +0 -721
- package/node_modules/pi-mcp-adapter/jev-client.ts +0 -300
- package/node_modules/pi-mcp-adapter/jev-contracts.ts +0 -53
- package/node_modules/pi-mcp-adapter/jev-key-store.ts +0 -192
- package/node_modules/pi-mcp-adapter/json-schema-validator.ts +0 -83
- package/node_modules/pi-mcp-adapter/lazy-loader.ts +0 -7
- package/node_modules/pi-mcp-adapter/lifecycle.ts +0 -457
- package/node_modules/pi-mcp-adapter/logger.ts +0 -169
- package/node_modules/pi-mcp-adapter/mcp-auth-fetch.ts +0 -113
- package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +0 -1296
- package/node_modules/pi-mcp-adapter/mcp-auth.ts +0 -1287
- package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -250
- package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +0 -534
- package/node_modules/pi-mcp-adapter/mcp-code.ts +0 -495
- package/node_modules/pi-mcp-adapter/mcp-install.ts +0 -60
- package/node_modules/pi-mcp-adapter/mcp-keyring-helper.cjs +0 -89
- package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +0 -819
- package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +0 -511
- package/node_modules/pi-mcp-adapter/mcp-panel-theme.ts +0 -104
- package/node_modules/pi-mcp-adapter/mcp-panel.ts +0 -1099
- package/node_modules/pi-mcp-adapter/mcp-probe.ts +0 -201
- package/node_modules/pi-mcp-adapter/mcp-references.ts +0 -373
- package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +0 -137
- package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +0 -747
- package/node_modules/pi-mcp-adapter/mcp-status.ts +0 -105
- package/node_modules/pi-mcp-adapter/mcp-tasks.ts +0 -467
- package/node_modules/pi-mcp-adapter/mcp-trace.ts +0 -306
- package/node_modules/pi-mcp-adapter/metadata-cache.ts +0 -362
- package/node_modules/pi-mcp-adapter/namespace-tools.ts +0 -334
- package/node_modules/pi-mcp-adapter/npx-resolver.ts +0 -543
- package/node_modules/pi-mcp-adapter/oauth-handler.ts +0 -30
- package/node_modules/pi-mcp-adapter/oauth.ts +0 -52
- package/node_modules/pi-mcp-adapter/onboarding-state.ts +0 -76
- package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +0 -156
- package/node_modules/pi-mcp-adapter/package.json +0 -219
- package/node_modules/pi-mcp-adapter/panel-keys.ts +0 -53
- package/node_modules/pi-mcp-adapter/prompts.ts +0 -385
- package/node_modules/pi-mcp-adapter/proxy-modes.ts +0 -1735
- package/node_modules/pi-mcp-adapter/request-headers-command.ts +0 -333
- package/node_modules/pi-mcp-adapter/resource-tools.ts +0 -17
- package/node_modules/pi-mcp-adapter/runtime-owner.ts +0 -106
- package/node_modules/pi-mcp-adapter/sampling-handler.ts +0 -261
- package/node_modules/pi-mcp-adapter/sandbox-proxy-template.ts +0 -144
- package/node_modules/pi-mcp-adapter/search-ranking.ts +0 -309
- package/node_modules/pi-mcp-adapter/secure-keyring.ts +0 -170
- package/node_modules/pi-mcp-adapter/semantic-search.ts +0 -186
- package/node_modules/pi-mcp-adapter/server-manager.ts +0 -2088
- package/node_modules/pi-mcp-adapter/session-approvals.ts +0 -201
- package/node_modules/pi-mcp-adapter/session-recovery.ts +0 -158
- package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +0 -49
- package/node_modules/pi-mcp-adapter/state.ts +0 -71
- package/node_modules/pi-mcp-adapter/tool-approval.ts +0 -205
- package/node_modules/pi-mcp-adapter/tool-metadata.ts +0 -302
- package/node_modules/pi-mcp-adapter/tool-registrar.ts +0 -255
- package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +0 -573
- package/node_modules/pi-mcp-adapter/ts-shape.ts +0 -149
- package/node_modules/pi-mcp-adapter/types.ts +0 -1120
- package/node_modules/pi-mcp-adapter/ui-app-bridge-helpers.ts +0 -40
- package/node_modules/pi-mcp-adapter/ui-resource-handler.ts +0 -266
- package/node_modules/pi-mcp-adapter/ui-server.ts +0 -993
- package/node_modules/pi-mcp-adapter/ui-session.ts +0 -624
- package/node_modules/pi-mcp-adapter/ui-stream-types.ts +0 -89
- package/node_modules/pi-mcp-adapter/ui-tool-visibility.ts +0 -25
- package/node_modules/pi-mcp-adapter/unix-socket-transport.ts +0 -85
- package/node_modules/pi-mcp-adapter/utils.ts +0 -464
|
@@ -1,543 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
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
|
-
import type { ServerEntry } from "./types.ts";
|
|
10
|
-
|
|
11
|
-
export type McpOAuthTokens = StoredTokens;
|
|
12
|
-
export type McpOAuthStorageOptions = AuthStorageOptions;
|
|
13
|
-
export interface McpOAuthTokenOptions {
|
|
14
|
-
authStorageOptions?: McpOAuthStorageOptions;
|
|
15
|
-
signal?: AbortSignal;
|
|
16
|
-
skipIssuerMetadataValidation?: boolean;
|
|
17
|
-
/** Explicit refresh configuration; never loaded from ambient config or stored with tokens. */
|
|
18
|
-
definition?: Pick<ServerEntry, "headers" | "oauth">;
|
|
19
|
-
}
|
|
20
|
-
export type McpOAuthTokenStatus =
|
|
21
|
-
| { status: "present"; tokens: McpOAuthTokens }
|
|
22
|
-
| { status: "absent" }
|
|
23
|
-
| { status: "unavailable"; message: string };
|
|
24
|
-
|
|
25
|
-
export async function getMcpOAuthTokensForUrl(
|
|
26
|
-
serverName: string,
|
|
27
|
-
serverUrl: string,
|
|
28
|
-
options: McpOAuthTokenOptions = {},
|
|
29
|
-
): Promise<McpOAuthTokens | undefined> {
|
|
30
|
-
return (await getValidToken(serverName, serverUrl, options)) ?? undefined;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function inspectMcpOAuthTokensForUrl(
|
|
34
|
-
serverName: string,
|
|
35
|
-
serverUrl: string,
|
|
36
|
-
options?: McpOAuthStorageOptions,
|
|
37
|
-
): McpOAuthTokenStatus {
|
|
38
|
-
const status = inspectAuthForUrl(serverName, serverUrl, options);
|
|
39
|
-
if (status.status !== "present") return status;
|
|
40
|
-
return status.entry.tokens
|
|
41
|
-
? { status: "present", tokens: status.entry.tokens }
|
|
42
|
-
: { status: "absent" };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function updateMcpOAuthTokensForUrl(
|
|
46
|
-
serverName: string,
|
|
47
|
-
serverUrl: string,
|
|
48
|
-
tokens: McpOAuthTokens,
|
|
49
|
-
options?: McpOAuthStorageOptions,
|
|
50
|
-
): Promise<void> {
|
|
51
|
-
updateTokens(serverName, tokens, serverUrl, options);
|
|
52
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
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
|
-
}
|