@duckmind/dm-windows-x64 0.63.6 → 0.63.9
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/dm.exe +0 -0
- package/extensions/.dm-extensions.json +174 -11
- package/extensions/dm-mcp-adapter/OAUTH.md +3 -0
- package/extensions/dm-mcp-adapter/THIRD_PARTY_NOTICES.md +4 -0
- package/extensions/dm-mcp-adapter/abort.js +35 -0
- package/extensions/dm-mcp-adapter/agent-dir.js +45 -0
- package/extensions/dm-mcp-adapter/agent-plugin-loader.js +349 -0
- package/extensions/dm-mcp-adapter/app-bridge.bundle.js +5843 -0
- package/extensions/dm-mcp-adapter/cli.js +354 -0
- package/extensions/dm-mcp-adapter/commands.js +619 -0
- package/extensions/dm-mcp-adapter/config.js +1060 -0
- package/extensions/dm-mcp-adapter/consent-manager.js +60 -0
- package/extensions/dm-mcp-adapter/direct-tools.js +544 -0
- package/extensions/dm-mcp-adapter/dist/agent-dir.js +45 -0
- package/extensions/dm-mcp-adapter/dist/agent-plugin-loader.js +349 -0
- package/extensions/dm-mcp-adapter/dist/config.js +1060 -0
- package/extensions/dm-mcp-adapter/dist/mcp-bearer-store.js +311 -0
- package/extensions/dm-mcp-adapter/dist/metadata-cache.js +285 -0
- package/extensions/dm-mcp-adapter/dist/package-mcp-loader.js +144 -0
- package/extensions/dm-mcp-adapter/dist/resource-tools.js +7 -0
- package/extensions/dm-mcp-adapter/dist/types.js +247 -0
- package/extensions/dm-mcp-adapter/dist/ui-app-bridge-helpers.js +36 -0
- package/extensions/dm-mcp-adapter/dist/ui-stream-types.js +58 -0
- package/extensions/dm-mcp-adapter/dist/ui-tool-visibility.js +26 -0
- package/extensions/dm-mcp-adapter/dist/utils.js +307 -0
- package/extensions/dm-mcp-adapter/elicitation-handler.js +306 -0
- package/extensions/dm-mcp-adapter/error-signal.js +16 -0
- package/extensions/dm-mcp-adapter/errors.js +225 -0
- package/extensions/dm-mcp-adapter/failure-backoff.js +19 -0
- package/extensions/dm-mcp-adapter/glimpse-ui.js +61 -0
- package/extensions/dm-mcp-adapter/host-html-template.js +464 -0
- package/extensions/dm-mcp-adapter/index.js +1079 -0
- package/extensions/dm-mcp-adapter/init.js +624 -0
- package/extensions/dm-mcp-adapter/json-schema-validator.js +53 -0
- package/extensions/dm-mcp-adapter/lifecycle.js +385 -0
- package/extensions/dm-mcp-adapter/logger.js +115 -0
- package/extensions/dm-mcp-adapter/mcp-auth-flow.js +824 -0
- package/extensions/dm-mcp-adapter/mcp-auth.js +732 -0
- package/extensions/dm-mcp-adapter/mcp-bearer-store.js +311 -0
- package/extensions/dm-mcp-adapter/mcp-callback-server.js +388 -0
- package/extensions/dm-mcp-adapter/mcp-code.js +291 -0
- package/extensions/dm-mcp-adapter/mcp-keyring-helper.cjs +88 -0
- package/extensions/dm-mcp-adapter/mcp-oauth-provider.js +490 -0
- package/extensions/dm-mcp-adapter/mcp-output-guard.js +386 -0
- package/extensions/dm-mcp-adapter/mcp-panel.js +951 -0
- package/extensions/dm-mcp-adapter/mcp-probe.js +151 -0
- package/extensions/dm-mcp-adapter/mcp-references.js +263 -0
- package/extensions/dm-mcp-adapter/mcp-script-worker.mjs +126 -0
- package/extensions/dm-mcp-adapter/mcp-setup-panel.js +578 -0
- package/extensions/dm-mcp-adapter/mcp-status.js +80 -0
- package/extensions/dm-mcp-adapter/mcp-trace.js +215 -0
- package/extensions/dm-mcp-adapter/metadata-cache.js +292 -0
- package/extensions/dm-mcp-adapter/namespace-tools.js +155 -0
- package/extensions/dm-mcp-adapter/npx-resolver.js +465 -0
- package/extensions/dm-mcp-adapter/oauth-handler.js +17 -0
- package/extensions/dm-mcp-adapter/oauth.js +17 -0
- package/extensions/dm-mcp-adapter/onboarding-state.js +62 -0
- package/extensions/dm-mcp-adapter/package-mcp-loader.js +144 -0
- package/extensions/dm-mcp-adapter/package.json +68 -0
- package/extensions/dm-mcp-adapter/panel-keys.js +26 -0
- package/extensions/dm-mcp-adapter/prompts.js +258 -0
- package/extensions/dm-mcp-adapter/proxy-modes.js +1336 -0
- package/extensions/dm-mcp-adapter/request-headers-command.js +293 -0
- package/extensions/dm-mcp-adapter/resource-tools.js +7 -0
- package/extensions/dm-mcp-adapter/runtime-owner.js +79 -0
- package/extensions/dm-mcp-adapter/sampling-handler.js +222 -0
- package/extensions/dm-mcp-adapter/sandbox-proxy-template.js +190 -0
- package/extensions/dm-mcp-adapter/search-ranking.js +198 -0
- package/extensions/dm-mcp-adapter/server-manager.js +1258 -0
- package/extensions/dm-mcp-adapter/session-recovery.js +82 -0
- package/extensions/dm-mcp-adapter/skills/mcp-scripting/SKILL.md +39 -0
- package/extensions/dm-mcp-adapter/state.js +0 -0
- package/extensions/dm-mcp-adapter/test-runner.mjs +18 -0
- package/extensions/dm-mcp-adapter/tool-approval.js +151 -0
- package/extensions/dm-mcp-adapter/tool-metadata.js +247 -0
- package/extensions/dm-mcp-adapter/tool-registrar.js +212 -0
- package/extensions/dm-mcp-adapter/tool-result-renderer.js +355 -0
- package/extensions/dm-mcp-adapter/ts-shape.js +157 -0
- package/extensions/dm-mcp-adapter/types.js +264 -0
- package/extensions/dm-mcp-adapter/ui-app-bridge-helpers.js +36 -0
- package/extensions/dm-mcp-adapter/ui-resource-handler.js +209 -0
- package/extensions/dm-mcp-adapter/ui-server.js +815 -0
- package/extensions/dm-mcp-adapter/ui-session.js +455 -0
- package/extensions/dm-mcp-adapter/ui-stream-types.js +58 -0
- package/extensions/dm-mcp-adapter/ui-tool-visibility.js +26 -0
- package/extensions/dm-mcp-adapter/unix-socket-transport.js +83 -0
- package/extensions/dm-mcp-adapter/utils.js +307 -0
- package/package.json +13 -1
- package/extensions/dm-localllm-provider/detect.test.js +0 -1051
- package/extensions/dm-localllm-provider/index.test.js +0 -149
- package/extensions/dm-localllm-provider/keychain.test.js +0 -61
package/dm.exe
CHANGED
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"status": "ok",
|
|
3
|
-
"prepared_at": "2026-
|
|
3
|
+
"prepared_at": "2026-09-04T12:16:40.370686+00:00",
|
|
4
4
|
"managed_entries": [
|
|
5
5
|
{
|
|
6
6
|
"id": "dm-context",
|
|
@@ -46,6 +46,11 @@
|
|
|
46
46
|
"id": "dm-skills-manager",
|
|
47
47
|
"target_dir": "extensions/dm-skills-manager",
|
|
48
48
|
"bundle_mode": "source-package-with-runtime-deps"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"id": "dm-mcp-adapter",
|
|
52
|
+
"target_dir": "extensions/dm-mcp-adapter",
|
|
53
|
+
"bundle_mode": "source-package-with-runtime-deps"
|
|
49
54
|
}
|
|
50
55
|
],
|
|
51
56
|
"local_entries": [
|
|
@@ -588,18 +593,15 @@
|
|
|
588
593
|
"tool": "bun build --no-bundle",
|
|
589
594
|
"mode": "module-preserving-transpile",
|
|
590
595
|
"files": [
|
|
591
|
-
"detect.test.js",
|
|
592
596
|
"detect.js",
|
|
593
|
-
"index.test.js",
|
|
594
597
|
"index.js",
|
|
595
|
-
"keychain.test.js",
|
|
596
598
|
"keychain.js"
|
|
597
599
|
],
|
|
598
|
-
"file_count":
|
|
599
|
-
"before_bytes":
|
|
600
|
-
"after_bytes":
|
|
601
|
-
"runtime_specifier_rewrites":
|
|
602
|
-
"runtime_filename_rewrites":
|
|
600
|
+
"file_count": 3,
|
|
601
|
+
"before_bytes": 73770,
|
|
602
|
+
"after_bytes": 33235,
|
|
603
|
+
"runtime_specifier_rewrites": 1,
|
|
604
|
+
"runtime_filename_rewrites": 3,
|
|
603
605
|
"declaration_files_removed": 0
|
|
604
606
|
}
|
|
605
607
|
},
|
|
@@ -773,6 +775,143 @@
|
|
|
773
775
|
"declaration_files_removed": 0
|
|
774
776
|
}
|
|
775
777
|
},
|
|
778
|
+
{
|
|
779
|
+
"id": "dm-mcp-adapter",
|
|
780
|
+
"staged_dir": "extensions/dm-mcp-adapter",
|
|
781
|
+
"bundle_mode": "source-package-with-runtime-deps",
|
|
782
|
+
"dependencies_installed": false,
|
|
783
|
+
"dependency_mode": "platform-package-dependency",
|
|
784
|
+
"dependencies_declared": [
|
|
785
|
+
"@duckmind/dm-ai",
|
|
786
|
+
"@duckmind/dm-coding-agent",
|
|
787
|
+
"@duckmind/dm-tui",
|
|
788
|
+
"@modelcontextprotocol/client",
|
|
789
|
+
"@modelcontextprotocol/core",
|
|
790
|
+
"@modelcontextprotocol/ext-apps",
|
|
791
|
+
"@napi-rs/keyring",
|
|
792
|
+
"ajv",
|
|
793
|
+
"ajv-formats",
|
|
794
|
+
"cross-spawn",
|
|
795
|
+
"open",
|
|
796
|
+
"recheck",
|
|
797
|
+
"smol-toml",
|
|
798
|
+
"strip-json-comments",
|
|
799
|
+
"typebox",
|
|
800
|
+
"zod"
|
|
801
|
+
],
|
|
802
|
+
"dependency_patches": [
|
|
803
|
+
"dm.extensions ts->js",
|
|
804
|
+
"exports ts->js",
|
|
805
|
+
"drop-dependencies",
|
|
806
|
+
"drop-devDependencies",
|
|
807
|
+
"drop-peerDependencies",
|
|
808
|
+
"drop-repository",
|
|
809
|
+
"drop-bugs",
|
|
810
|
+
"drop-homepage",
|
|
811
|
+
"drop-scripts",
|
|
812
|
+
"drop-files",
|
|
813
|
+
"drop-types"
|
|
814
|
+
],
|
|
815
|
+
"stripped_documentation": [
|
|
816
|
+
"CHANGELOG.md",
|
|
817
|
+
"LICENSE",
|
|
818
|
+
"README.md",
|
|
819
|
+
"banner.png"
|
|
820
|
+
],
|
|
821
|
+
"javascript_compile": {
|
|
822
|
+
"tool": "bun build --no-bundle",
|
|
823
|
+
"mode": "module-preserving-transpile",
|
|
824
|
+
"files": [
|
|
825
|
+
"abort.js",
|
|
826
|
+
"agent-dir.js",
|
|
827
|
+
"agent-plugin-loader.js",
|
|
828
|
+
"app-bridge.bundle.js",
|
|
829
|
+
"cli.js",
|
|
830
|
+
"commands.js",
|
|
831
|
+
"config.js",
|
|
832
|
+
"consent-manager.js",
|
|
833
|
+
"direct-tools.js",
|
|
834
|
+
"dist/agent-dir.js",
|
|
835
|
+
"dist/agent-plugin-loader.js",
|
|
836
|
+
"dist/config.js",
|
|
837
|
+
"dist/mcp-bearer-store.js",
|
|
838
|
+
"dist/metadata-cache.js",
|
|
839
|
+
"dist/package-mcp-loader.js",
|
|
840
|
+
"dist/resource-tools.js",
|
|
841
|
+
"dist/types.js",
|
|
842
|
+
"dist/ui-app-bridge-helpers.js",
|
|
843
|
+
"dist/ui-stream-types.js",
|
|
844
|
+
"dist/ui-tool-visibility.js",
|
|
845
|
+
"dist/utils.js",
|
|
846
|
+
"elicitation-handler.js",
|
|
847
|
+
"error-signal.js",
|
|
848
|
+
"errors.js",
|
|
849
|
+
"failure-backoff.js",
|
|
850
|
+
"glimpse-ui.js",
|
|
851
|
+
"host-html-template.js",
|
|
852
|
+
"index.js",
|
|
853
|
+
"init.js",
|
|
854
|
+
"json-schema-validator.js",
|
|
855
|
+
"lifecycle.js",
|
|
856
|
+
"logger.js",
|
|
857
|
+
"mcp-auth-flow.js",
|
|
858
|
+
"mcp-auth.js",
|
|
859
|
+
"mcp-bearer-store.js",
|
|
860
|
+
"mcp-callback-server.js",
|
|
861
|
+
"mcp-code.js",
|
|
862
|
+
"mcp-keyring-helper.cjs",
|
|
863
|
+
"mcp-oauth-provider.js",
|
|
864
|
+
"mcp-output-guard.js",
|
|
865
|
+
"mcp-panel.js",
|
|
866
|
+
"mcp-probe.js",
|
|
867
|
+
"mcp-references.js",
|
|
868
|
+
"mcp-script-worker.mjs",
|
|
869
|
+
"mcp-setup-panel.js",
|
|
870
|
+
"mcp-status.js",
|
|
871
|
+
"mcp-trace.js",
|
|
872
|
+
"metadata-cache.js",
|
|
873
|
+
"namespace-tools.js",
|
|
874
|
+
"npx-resolver.js",
|
|
875
|
+
"oauth-handler.js",
|
|
876
|
+
"oauth.js",
|
|
877
|
+
"onboarding-state.js",
|
|
878
|
+
"package-mcp-loader.js",
|
|
879
|
+
"panel-keys.js",
|
|
880
|
+
"prompts.js",
|
|
881
|
+
"proxy-modes.js",
|
|
882
|
+
"request-headers-command.js",
|
|
883
|
+
"resource-tools.js",
|
|
884
|
+
"runtime-owner.js",
|
|
885
|
+
"sampling-handler.js",
|
|
886
|
+
"sandbox-proxy-template.js",
|
|
887
|
+
"search-ranking.js",
|
|
888
|
+
"server-manager.js",
|
|
889
|
+
"session-recovery.js",
|
|
890
|
+
"state.js",
|
|
891
|
+
"test-runner.mjs",
|
|
892
|
+
"tool-approval.js",
|
|
893
|
+
"tool-metadata.js",
|
|
894
|
+
"tool-registrar.js",
|
|
895
|
+
"tool-result-renderer.js",
|
|
896
|
+
"ts-shape.js",
|
|
897
|
+
"types.js",
|
|
898
|
+
"ui-app-bridge-helpers.js",
|
|
899
|
+
"ui-resource-handler.js",
|
|
900
|
+
"ui-server.js",
|
|
901
|
+
"ui-session.js",
|
|
902
|
+
"ui-stream-types.js",
|
|
903
|
+
"ui-tool-visibility.js",
|
|
904
|
+
"unix-socket-transport.js",
|
|
905
|
+
"utils.js"
|
|
906
|
+
],
|
|
907
|
+
"file_count": 81,
|
|
908
|
+
"before_bytes": 1437785,
|
|
909
|
+
"after_bytes": 1265238,
|
|
910
|
+
"runtime_specifier_rewrites": 39,
|
|
911
|
+
"runtime_filename_rewrites": 64,
|
|
912
|
+
"declaration_files_removed": 12
|
|
913
|
+
}
|
|
914
|
+
},
|
|
776
915
|
{
|
|
777
916
|
"id": "dm-cua",
|
|
778
917
|
"staged_dir": "extensions/dm-cua",
|
|
@@ -862,26 +1001,50 @@
|
|
|
862
1001
|
"turndown": "^7.2.0",
|
|
863
1002
|
"undici": "^8.9.0",
|
|
864
1003
|
"unpdf": "^1.6.2",
|
|
1004
|
+
"@modelcontextprotocol/client": "2.0.0",
|
|
1005
|
+
"@modelcontextprotocol/core": "2.0.0",
|
|
1006
|
+
"@modelcontextprotocol/ext-apps": "^1.2.2",
|
|
1007
|
+
"@napi-rs/keyring": "^1.3.0",
|
|
1008
|
+
"ajv": "^8.17.1",
|
|
1009
|
+
"ajv-formats": "^3.0.1",
|
|
1010
|
+
"cross-spawn": "^7.0.6",
|
|
1011
|
+
"open": "^10.2.0",
|
|
1012
|
+
"recheck": "^4.5.0",
|
|
1013
|
+
"smol-toml": "^1.6.1",
|
|
1014
|
+
"strip-json-comments": "^5.0.3",
|
|
1015
|
+
"zod": "^3.25.0 || ^4.0.0",
|
|
865
1016
|
"@sinclair/typebox": "^0.34.48"
|
|
866
1017
|
},
|
|
867
1018
|
"runtime_loader": {
|
|
868
1019
|
"status": "verified",
|
|
869
|
-
"entries":
|
|
1020
|
+
"entries": 13,
|
|
870
1021
|
"loader": "dm-coding-agent",
|
|
871
1022
|
"platform_dependencies": [
|
|
1023
|
+
"@modelcontextprotocol/client",
|
|
1024
|
+
"@modelcontextprotocol/core",
|
|
1025
|
+
"@modelcontextprotocol/ext-apps",
|
|
872
1026
|
"@mozilla/readability",
|
|
1027
|
+
"@napi-rs/keyring",
|
|
873
1028
|
"@sinclair/typebox",
|
|
874
1029
|
"acorn",
|
|
1030
|
+
"ajv",
|
|
1031
|
+
"ajv-formats",
|
|
1032
|
+
"cross-spawn",
|
|
875
1033
|
"defuddle",
|
|
876
1034
|
"jiti",
|
|
877
1035
|
"linkedom",
|
|
1036
|
+
"open",
|
|
878
1037
|
"p-limit",
|
|
879
1038
|
"promise.try",
|
|
1039
|
+
"recheck",
|
|
1040
|
+
"smol-toml",
|
|
1041
|
+
"strip-json-comments",
|
|
880
1042
|
"turndown",
|
|
881
1043
|
"typebox",
|
|
882
1044
|
"undici",
|
|
883
1045
|
"unpdf",
|
|
884
|
-
"yaml"
|
|
1046
|
+
"yaml",
|
|
1047
|
+
"zod"
|
|
885
1048
|
]
|
|
886
1049
|
}
|
|
887
1050
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function throwIfAborted(signal) {
|
|
2
|
+
if (!signal?.aborted)
|
|
3
|
+
return;
|
|
4
|
+
throw signal.reason instanceof Error ? signal.reason : new Error(String(signal.reason ?? "MCP request aborted"));
|
|
5
|
+
}
|
|
6
|
+
export async function abortable(promise, signal) {
|
|
7
|
+
if (!signal)
|
|
8
|
+
return promise;
|
|
9
|
+
throwIfAborted(signal);
|
|
10
|
+
return await new Promise((resolve, reject) => {
|
|
11
|
+
let settled = false;
|
|
12
|
+
const cleanup = () => signal.removeEventListener("abort", onAbort);
|
|
13
|
+
const onAbort = () => {
|
|
14
|
+
if (settled)
|
|
15
|
+
return;
|
|
16
|
+
settled = true;
|
|
17
|
+
cleanup();
|
|
18
|
+
reject(signal.reason instanceof Error ? signal.reason : new Error(String(signal.reason ?? "MCP request aborted")));
|
|
19
|
+
};
|
|
20
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
21
|
+
promise.then((value) => {
|
|
22
|
+
if (settled)
|
|
23
|
+
return;
|
|
24
|
+
settled = true;
|
|
25
|
+
cleanup();
|
|
26
|
+
resolve(value);
|
|
27
|
+
}, (error) => {
|
|
28
|
+
if (settled)
|
|
29
|
+
return;
|
|
30
|
+
settled = true;
|
|
31
|
+
cleanup();
|
|
32
|
+
reject(error);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
export function getConfigDirName() {
|
|
5
|
+
const configDir = readPiConfig()?.configDir;
|
|
6
|
+
return typeof configDir === "string" && configDir.trim() ? configDir.trim() : ".dm";
|
|
7
|
+
}
|
|
8
|
+
export function getAgentDir() {
|
|
9
|
+
const piConfig = readPiConfig();
|
|
10
|
+
const name = piConfig?.name;
|
|
11
|
+
const appName = typeof name === "string" && name.trim() ? name.trim() : "pi";
|
|
12
|
+
const configured = process.env[`${appName.toUpperCase()}_CODING_AGENT_DIR`]?.trim();
|
|
13
|
+
if (!configured) {
|
|
14
|
+
return join(homedir(), getConfigDirName(), "agent");
|
|
15
|
+
}
|
|
16
|
+
if (configured === "~") {
|
|
17
|
+
return homedir();
|
|
18
|
+
}
|
|
19
|
+
if (configured.startsWith("~/")) {
|
|
20
|
+
return resolve(homedir(), configured.slice(2));
|
|
21
|
+
}
|
|
22
|
+
return resolve(configured);
|
|
23
|
+
}
|
|
24
|
+
export function getAgentPath(...segments) {
|
|
25
|
+
return join(getAgentDir(), ...segments);
|
|
26
|
+
}
|
|
27
|
+
function readPiConfig() {
|
|
28
|
+
const dir = process.env.PI_PACKAGE_DIR?.trim();
|
|
29
|
+
if (!dir)
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
const manifest = JSON.parse(readFileSync(join(resolve(dir), "package.json"), "utf8"));
|
|
33
|
+
return manifest.piConfig;
|
|
34
|
+
} catch {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function getAppName() {
|
|
39
|
+
const name = readPiConfig()?.name;
|
|
40
|
+
return typeof name === "string" && name.trim() ? name.trim() : "pi";
|
|
41
|
+
}
|
|
42
|
+
export function getAppClientUri() {
|
|
43
|
+
const uri = readPiConfig()?.clientUri;
|
|
44
|
+
return typeof uri === "string" && uri.trim() ? uri.trim() : undefined;
|
|
45
|
+
}
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { getAgentPath } from "./agent-dir.js";
|
|
4
|
+
const PLUGIN_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json";
|
|
5
|
+
const MCP_SCHEMA = "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json";
|
|
6
|
+
const PLUGIN_NAME_PATTERN = /^(?!.*(?:--|\.\.))[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/;
|
|
7
|
+
const PLUGIN_MANIFEST_FIELDS = new Set([
|
|
8
|
+
"$schema",
|
|
9
|
+
"name",
|
|
10
|
+
"version",
|
|
11
|
+
"description",
|
|
12
|
+
"author",
|
|
13
|
+
"homepage",
|
|
14
|
+
"repository",
|
|
15
|
+
"license",
|
|
16
|
+
"keywords",
|
|
17
|
+
"extensions"
|
|
18
|
+
]);
|
|
19
|
+
const MCP_CONFIG_FIELDS = new Set(["$schema", "mcpServers"]);
|
|
20
|
+
const STDIO_FIELDS = new Set(["type", "command", "args", "env", "cwd"]);
|
|
21
|
+
const HTTP_FIELDS = new Set(["type", "url", "headers"]);
|
|
22
|
+
export function loadAgentPluginConfigs(paths, cwd = process.cwd()) {
|
|
23
|
+
const mcpServers = {};
|
|
24
|
+
for (const pluginPath of getPluginPaths(paths)) {
|
|
25
|
+
const loaded = loadAgentPluginMcpConfig(pluginPath, cwd);
|
|
26
|
+
if (!loaded)
|
|
27
|
+
continue;
|
|
28
|
+
for (const [serverName, server] of Object.entries(loaded.mcpServers)) {
|
|
29
|
+
if (mcpServers[serverName]) {
|
|
30
|
+
console.warn(`Agent Plugin at ${resolvePluginPath(pluginPath, cwd)} skips duplicate normalized MCP server ${serverName}`);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
mcpServers[serverName] = server;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { mcpServers };
|
|
37
|
+
}
|
|
38
|
+
export function getAgentPluginSummaries(paths, cwd = process.cwd()) {
|
|
39
|
+
return getPluginPaths(paths).map((path) => {
|
|
40
|
+
const pluginRoot = resolvePluginPath(path, cwd);
|
|
41
|
+
const loaded = loadAgentPluginMcpConfig(path, cwd);
|
|
42
|
+
const manifest = loaded ? readPluginManifest(pluginRoot, false) : null;
|
|
43
|
+
return {
|
|
44
|
+
path: pluginRoot,
|
|
45
|
+
...manifest?.name ? { name: manifest.name } : {},
|
|
46
|
+
serverCount: loaded ? Object.keys(loaded.mcpServers).length : 0
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function getPluginPaths(paths) {
|
|
51
|
+
return Array.isArray(paths) ? paths.filter((path) => typeof path === "string") : [];
|
|
52
|
+
}
|
|
53
|
+
function loadAgentPluginMcpConfig(path, cwd) {
|
|
54
|
+
const pluginRoot = resolvePluginPath(path, cwd);
|
|
55
|
+
const manifest = readPluginManifest(pluginRoot, true);
|
|
56
|
+
if (!manifest)
|
|
57
|
+
return null;
|
|
58
|
+
const mcpPath = resolve(pluginRoot, "mcp.json");
|
|
59
|
+
if (!existsSync(mcpPath))
|
|
60
|
+
return { mcpServers: {} };
|
|
61
|
+
if (!statSync(mcpPath).isFile()) {
|
|
62
|
+
console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: mcp.json is not a regular file`);
|
|
63
|
+
return { mcpServers: {} };
|
|
64
|
+
}
|
|
65
|
+
let raw;
|
|
66
|
+
try {
|
|
67
|
+
raw = JSON.parse(readFileSync(mcpPath, "utf8"));
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: failed to parse mcp.json`, error);
|
|
70
|
+
return { mcpServers: {} };
|
|
71
|
+
}
|
|
72
|
+
return translateAgentPluginMcpConfig(raw, manifest, pluginRoot);
|
|
73
|
+
}
|
|
74
|
+
function readPluginManifest(pluginRoot, report) {
|
|
75
|
+
const manifestPath = resolve(pluginRoot, "plugin.json");
|
|
76
|
+
if (!existsSync(manifestPath)) {
|
|
77
|
+
if (report)
|
|
78
|
+
console.warn(`Agent Plugin at ${pluginRoot} is invalid: missing plugin.json`);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
if (!statSync(manifestPath).isFile()) {
|
|
82
|
+
if (report)
|
|
83
|
+
console.warn(`Agent Plugin at ${pluginRoot} is invalid: plugin.json is not a regular file`);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
let raw;
|
|
87
|
+
try {
|
|
88
|
+
raw = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (report)
|
|
91
|
+
console.warn(`Agent Plugin at ${pluginRoot} is invalid: failed to parse plugin.json`, error);
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
95
|
+
if (report)
|
|
96
|
+
console.warn(`Agent Plugin at ${pluginRoot} is invalid: plugin.json must be an object`);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const manifest = raw;
|
|
100
|
+
for (const key of Object.keys(manifest)) {
|
|
101
|
+
if (!PLUGIN_MANIFEST_FIELDS.has(key) && report) {
|
|
102
|
+
console.warn(`Agent Plugin at ${pluginRoot} ignores unknown plugin.json field: ${key}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (manifest.$schema !== PLUGIN_SCHEMA) {
|
|
106
|
+
if (report)
|
|
107
|
+
console.warn(`Agent Plugin at ${pluginRoot} is invalid: unsupported plugin.json $schema`);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
if (typeof manifest.name !== "string" || manifest.name.length < 1 || manifest.name.length > 64 || !PLUGIN_NAME_PATTERN.test(manifest.name)) {
|
|
111
|
+
if (report)
|
|
112
|
+
console.warn(`Agent Plugin at ${pluginRoot} is invalid: plugin.json name is invalid`);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (manifest.extensions !== undefined && (!manifest.extensions || typeof manifest.extensions !== "object" || Array.isArray(manifest.extensions))) {
|
|
116
|
+
if (report)
|
|
117
|
+
console.warn(`Agent Plugin ${manifest.name} ignores non-object plugin.json extensions`);
|
|
118
|
+
}
|
|
119
|
+
return { name: manifest.name };
|
|
120
|
+
}
|
|
121
|
+
function translateAgentPluginMcpConfig(raw, manifest, pluginRoot) {
|
|
122
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
123
|
+
console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: mcp.json must be an object`);
|
|
124
|
+
return { mcpServers: {} };
|
|
125
|
+
}
|
|
126
|
+
const mcpConfig = raw;
|
|
127
|
+
for (const key of Object.keys(mcpConfig)) {
|
|
128
|
+
if (!MCP_CONFIG_FIELDS.has(key)) {
|
|
129
|
+
console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: unknown top-level field ${key}`);
|
|
130
|
+
return { mcpServers: {} };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (mcpConfig.$schema !== MCP_SCHEMA) {
|
|
134
|
+
console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: unsupported mcp.json $schema`);
|
|
135
|
+
return { mcpServers: {} };
|
|
136
|
+
}
|
|
137
|
+
if (!mcpConfig.mcpServers || typeof mcpConfig.mcpServers !== "object" || Array.isArray(mcpConfig.mcpServers)) {
|
|
138
|
+
console.warn(`Agent Plugin ${manifest.name} has invalid MCP config: mcpServers must be an object`);
|
|
139
|
+
return { mcpServers: {} };
|
|
140
|
+
}
|
|
141
|
+
const mcpServers = {};
|
|
142
|
+
for (const [serverName, entry] of Object.entries(mcpConfig.mcpServers)) {
|
|
143
|
+
const translated = translateAgentPluginServer(manifest, pluginRoot, serverName, entry);
|
|
144
|
+
if (!translated)
|
|
145
|
+
continue;
|
|
146
|
+
const normalizedName = formatAgentPluginServerName(manifest.name, serverName);
|
|
147
|
+
if (mcpServers[normalizedName]) {
|
|
148
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: normalized server name ${normalizedName} already exists`);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
mcpServers[normalizedName] = translated;
|
|
152
|
+
}
|
|
153
|
+
return { mcpServers };
|
|
154
|
+
}
|
|
155
|
+
function translateAgentPluginServer(manifest, pluginRoot, serverName, entry) {
|
|
156
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
157
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: entry must be an object`);
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
const raw = entry;
|
|
161
|
+
if (raw.type === "stdio")
|
|
162
|
+
return translateStdioServer(manifest, pluginRoot, serverName, raw);
|
|
163
|
+
if (raw.type === "streamable-http" || raw.type === "sse")
|
|
164
|
+
return translateHttpServer(manifest, serverName, raw, raw.type);
|
|
165
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: unsupported type`);
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
function translateStdioServer(manifest, pluginRoot, serverName, raw) {
|
|
169
|
+
for (const key of Object.keys(raw)) {
|
|
170
|
+
if (!STDIO_FIELDS.has(key))
|
|
171
|
+
return skipServer(manifest, serverName, `unknown field ${key}`);
|
|
172
|
+
}
|
|
173
|
+
if (typeof raw.command !== "string" || raw.command.length === 0)
|
|
174
|
+
return skipServer(manifest, serverName, "command must be a non-empty string");
|
|
175
|
+
if (!isBareCommand(raw.command) && !raw.command.startsWith("./"))
|
|
176
|
+
return skipServer(manifest, serverName, "command must be bare or plugin-relative");
|
|
177
|
+
const args = translateStringArray(raw.args, manifest, serverName, "args");
|
|
178
|
+
if (args === null)
|
|
179
|
+
return null;
|
|
180
|
+
const env = translateEnv(raw.env, manifest, serverName);
|
|
181
|
+
if (env === null)
|
|
182
|
+
return null;
|
|
183
|
+
const command = raw.command.startsWith("./") ? resolveContainedPath(pluginRoot, raw.command, pluginRoot) : raw.command;
|
|
184
|
+
if (command === null)
|
|
185
|
+
return skipServer(manifest, serverName, "command must stay inside the plugin directory");
|
|
186
|
+
const pluginDataDir = getAgentPath("agent-plugin-data", manifest.name);
|
|
187
|
+
const cwd = resolvePluginCwd(raw.cwd, pluginRoot, pluginDataDir);
|
|
188
|
+
if (cwd === null)
|
|
189
|
+
return skipServer(manifest, serverName, "cwd must be plugin-relative, PLUGIN_ROOT-rooted, or PLUGIN_DATA-rooted");
|
|
190
|
+
return {
|
|
191
|
+
command,
|
|
192
|
+
args: args.map((value) => expandPluginPlaceholders(value, pluginRoot, pluginDataDir)),
|
|
193
|
+
env: {
|
|
194
|
+
...Object.fromEntries(Object.entries(env).map(([key, value]) => [key, expandPluginPlaceholders(value, pluginRoot, pluginDataDir)])),
|
|
195
|
+
PLUGIN_ROOT: pluginRoot,
|
|
196
|
+
PLUGIN_DATA: pluginDataDir
|
|
197
|
+
},
|
|
198
|
+
cwd,
|
|
199
|
+
pluginDataDir,
|
|
200
|
+
literalEnv: true
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function translateHttpServer(manifest, serverName, raw, type) {
|
|
204
|
+
for (const key of Object.keys(raw)) {
|
|
205
|
+
if (!HTTP_FIELDS.has(key))
|
|
206
|
+
return skipServer(manifest, serverName, `unknown field ${key}`);
|
|
207
|
+
}
|
|
208
|
+
if (typeof raw.url !== "string" || raw.url.length === 0)
|
|
209
|
+
return skipServer(manifest, serverName, "url must be a non-empty string");
|
|
210
|
+
if (!isValidAgentPluginUrl(raw.url))
|
|
211
|
+
return skipServer(manifest, serverName, "url must be an allowed absolute HTTP(S) URL");
|
|
212
|
+
const headers = translateHeaders(raw.headers, manifest, serverName);
|
|
213
|
+
if (headers === null)
|
|
214
|
+
return null;
|
|
215
|
+
return {
|
|
216
|
+
url: raw.url,
|
|
217
|
+
httpTransport: type,
|
|
218
|
+
...headers ? { headers } : {}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function formatAgentPluginServerName(pluginName, serverName) {
|
|
222
|
+
const pluginPart = pluginName.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[_-]+|[_-]+$/g, "") || "plugin";
|
|
223
|
+
const serverPart = serverName.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[_-]+|[_-]+$/g, "") || "server";
|
|
224
|
+
return `${pluginPart}__${serverPart}`;
|
|
225
|
+
}
|
|
226
|
+
function skipServer(manifest, serverName, reason) {
|
|
227
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: ${reason}`);
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
function translateStringArray(value, manifest, serverName, field) {
|
|
231
|
+
if (value === undefined)
|
|
232
|
+
return [];
|
|
233
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
234
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: ${field} must be an array of strings`);
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
function translateEnv(value, manifest, serverName) {
|
|
240
|
+
if (value === undefined)
|
|
241
|
+
return {};
|
|
242
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
243
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: env must be an object of strings`);
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
const env = {};
|
|
247
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
248
|
+
if (key === "PLUGIN_ROOT" || key === "PLUGIN_DATA") {
|
|
249
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: env must not define ${key}`);
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
if (typeof entry !== "string") {
|
|
253
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: env values must be strings`);
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
env[key] = entry;
|
|
257
|
+
}
|
|
258
|
+
return env;
|
|
259
|
+
}
|
|
260
|
+
function translateHeaders(value, manifest, serverName) {
|
|
261
|
+
if (value === undefined)
|
|
262
|
+
return;
|
|
263
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
264
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: headers must be an object of strings`);
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
const headers = {};
|
|
268
|
+
const seen = new Set;
|
|
269
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
270
|
+
if (typeof entry !== "string") {
|
|
271
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: header values must be strings`);
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
const normalized = key.toLowerCase();
|
|
275
|
+
if (seen.has(normalized)) {
|
|
276
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: duplicate header ${key}`);
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
seen.add(normalized);
|
|
280
|
+
headers[key] = entry;
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
new Headers(headers);
|
|
284
|
+
} catch {
|
|
285
|
+
console.warn(`Agent Plugin ${manifest.name} skips invalid MCP server ${serverName}: headers are not valid HTTP fields`);
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
return Object.keys(headers).length > 0 ? headers : undefined;
|
|
289
|
+
}
|
|
290
|
+
function resolvePluginPath(path, cwd) {
|
|
291
|
+
if (path === "~")
|
|
292
|
+
return resolve(process.env.HOME ?? "", ".");
|
|
293
|
+
if (path.startsWith("~/"))
|
|
294
|
+
return resolve(process.env.HOME ?? "", path.slice(2));
|
|
295
|
+
return isAbsolute(path) ? resolve(path) : resolve(cwd, path);
|
|
296
|
+
}
|
|
297
|
+
function isBareCommand(command) {
|
|
298
|
+
return !command.includes("/") && !command.includes("\\") && !command.includes("${PLUGIN_ROOT}") && !command.includes("${PLUGIN_DATA}");
|
|
299
|
+
}
|
|
300
|
+
function resolvePluginCwd(value, pluginRoot, pluginDataDir) {
|
|
301
|
+
if (value === undefined)
|
|
302
|
+
return pluginRoot;
|
|
303
|
+
if (typeof value !== "string")
|
|
304
|
+
return null;
|
|
305
|
+
if (value.startsWith("./"))
|
|
306
|
+
return resolveContainedPath(pluginRoot, value, pluginRoot);
|
|
307
|
+
if (value === "${PLUGIN_ROOT}" || value.startsWith("${PLUGIN_ROOT}/")) {
|
|
308
|
+
return resolveContainedPath(pluginRoot, value.replace("${PLUGIN_ROOT}", "."), pluginRoot);
|
|
309
|
+
}
|
|
310
|
+
if (value === "${PLUGIN_DATA}" || value.startsWith("${PLUGIN_DATA}/")) {
|
|
311
|
+
return resolveContainedPath(pluginDataDir, value.replace("${PLUGIN_DATA}", "."), pluginDataDir);
|
|
312
|
+
}
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
function resolveContainedPath(root, value, containmentRoot) {
|
|
316
|
+
const resolved = resolve(root, value);
|
|
317
|
+
const rel = relative(containmentRoot, resolved);
|
|
318
|
+
if (rel === "" || !rel.startsWith("..") && !rel.startsWith(sep) && !isAbsolute(rel))
|
|
319
|
+
return resolved;
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
function expandPluginPlaceholders(value, pluginRoot, pluginDataDir) {
|
|
323
|
+
return value.replaceAll("${PLUGIN_ROOT}", pluginRoot).replaceAll("${PLUGIN_DATA}", pluginDataDir);
|
|
324
|
+
}
|
|
325
|
+
function isValidAgentPluginUrl(value) {
|
|
326
|
+
if (value.includes("${") || value.includes("$env:") || value.includes("{env:"))
|
|
327
|
+
return false;
|
|
328
|
+
let url;
|
|
329
|
+
try {
|
|
330
|
+
url = new URL(value);
|
|
331
|
+
} catch {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
335
|
+
return false;
|
|
336
|
+
if (url.username || url.password || url.hash)
|
|
337
|
+
return false;
|
|
338
|
+
if (url.protocol === "https:")
|
|
339
|
+
return true;
|
|
340
|
+
return isLoopbackHost(url.hostname);
|
|
341
|
+
}
|
|
342
|
+
function isLoopbackHost(hostname) {
|
|
343
|
+
const host = hostname.toLowerCase();
|
|
344
|
+
if (host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]")
|
|
345
|
+
return true;
|
|
346
|
+
if (/^127(?:\.\d{1,3}){3}$/.test(host))
|
|
347
|
+
return true;
|
|
348
|
+
return false;
|
|
349
|
+
}
|