@cydm/magic-shell-agent-node 0.1.13 → 0.1.15
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.
|
@@ -46,6 +46,13 @@ function resolveWindowsCommand(command, args) {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
const lowerCommand = command.toLowerCase();
|
|
50
|
+
if (lowerCommand.endsWith(".cmd") || lowerCommand.endsWith(".bat")) {
|
|
51
|
+
return {
|
|
52
|
+
command: DEFAULT_WINDOWS_SHELL,
|
|
53
|
+
args: ["/d", "/s", "/c", [quoteWindowsArg(command), ...args.map(quoteWindowsArg)].join(" ")],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
49
56
|
if (command.includes("\\") || command.includes("/") || /^[a-zA-Z]:/.test(command)) {
|
|
50
57
|
return { command, args };
|
|
51
58
|
}
|
package/dist/plugin-loader.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { readFileSync, readdirSync, existsSync } from "fs";
|
|
2
2
|
import { join, extname, dirname, isAbsolute, resolve } from "path";
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
|
+
import { createRequire } from "module";
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
4
6
|
/**
|
|
5
7
|
* 加载单个插件配置
|
|
6
8
|
*/
|
|
@@ -29,12 +31,57 @@ export function loadPlugin(path) {
|
|
|
29
31
|
if (!["stdio", "pty", "rpc"].includes(config.type)) {
|
|
30
32
|
throw new Error(`Plugin ${path} invalid type: ${config.type}`);
|
|
31
33
|
}
|
|
32
|
-
return {
|
|
34
|
+
return normalizePluginConfigForRuntime({
|
|
33
35
|
...config,
|
|
34
36
|
command: resolveCommandPath(config.command, configDir, repoRoot),
|
|
35
37
|
args: resolveArgPaths(config.args, configDir, repoRoot),
|
|
36
38
|
cwd: resolveOptionalPath(config.cwd, configDir, repoRoot),
|
|
37
|
-
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function normalizePluginConfigForRuntime(config) {
|
|
42
|
+
if (process.platform !== "win32") {
|
|
43
|
+
return config;
|
|
44
|
+
}
|
|
45
|
+
if (config.name === "pie") {
|
|
46
|
+
const pieEntry = resolvePackageBinEntry("@cydm/pie", "pie");
|
|
47
|
+
if (pieEntry) {
|
|
48
|
+
return {
|
|
49
|
+
...config,
|
|
50
|
+
command: process.execPath,
|
|
51
|
+
args: [pieEntry, ...(config.args || [])],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if ((config.name === "claude-code" || config.name === "codex") && isShellCommand(config.command)) {
|
|
56
|
+
return {
|
|
57
|
+
...config,
|
|
58
|
+
command: process.env.ComSpec || "C:\\Windows\\System32\\cmd.exe",
|
|
59
|
+
args: ["/d", "/s", "/c", [config.command, ...(config.args || [])].join(" ")],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return config;
|
|
63
|
+
}
|
|
64
|
+
function resolvePackageBinEntry(packageName, binName) {
|
|
65
|
+
try {
|
|
66
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
67
|
+
const packageDir = dirname(packageJsonPath);
|
|
68
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
69
|
+
const binField = typeof pkg.bin === "string"
|
|
70
|
+
? pkg.bin
|
|
71
|
+
: pkg.bin && typeof pkg.bin[binName] === "string"
|
|
72
|
+
? pkg.bin[binName]
|
|
73
|
+
: null;
|
|
74
|
+
if (!binField)
|
|
75
|
+
return null;
|
|
76
|
+
const entry = resolve(packageDir, binField);
|
|
77
|
+
return existsSync(entry) ? entry : null;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function isShellCommand(command) {
|
|
84
|
+
return !!command && !isAbsolute(command) && !command.includes("/") && !command.includes("\\");
|
|
38
85
|
}
|
|
39
86
|
function resolveOptionalPath(value, configDir, repoRoot) {
|
|
40
87
|
if (!value)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "Magic Shell Agent Plugin",
|
|
4
|
+
"description": "Agent 插件配置 Schema",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["name", "type", "command", "capabilities"],
|
|
7
|
+
"properties": {
|
|
8
|
+
"name": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "插件唯一名称",
|
|
11
|
+
"pattern": "^[a-z0-9-]+$"
|
|
12
|
+
},
|
|
13
|
+
"type": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"enum": ["stdio", "pty", "rpc"],
|
|
16
|
+
"description": "连接模式"
|
|
17
|
+
},
|
|
18
|
+
"command": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "启动命令"
|
|
21
|
+
},
|
|
22
|
+
"args": {
|
|
23
|
+
"type": "array",
|
|
24
|
+
"items": { "type": "string" },
|
|
25
|
+
"description": "启动参数"
|
|
26
|
+
},
|
|
27
|
+
"env": {
|
|
28
|
+
"type": "object",
|
|
29
|
+
"additionalProperties": { "type": "string" },
|
|
30
|
+
"description": "环境变量"
|
|
31
|
+
},
|
|
32
|
+
"capabilities": {
|
|
33
|
+
"type": "array",
|
|
34
|
+
"items": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"enum": [
|
|
37
|
+
"terminal",
|
|
38
|
+
"pty",
|
|
39
|
+
"ansi256",
|
|
40
|
+
"file-edit",
|
|
41
|
+
"web-search",
|
|
42
|
+
"bash",
|
|
43
|
+
"json-rpc",
|
|
44
|
+
"tool-call",
|
|
45
|
+
"streaming",
|
|
46
|
+
"mouse"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"description": "能力列表"
|
|
50
|
+
},
|
|
51
|
+
"cwd": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"description": "工作目录(可选)"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|