opencode-agent-ghost-panel 0.1.6 → 0.1.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/index.js +42 -20
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2,23 +2,39 @@
|
|
|
2
2
|
* Agent Ghost Panel Plugin for OpenCode
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { spawn } from "child_process";
|
|
5
6
|
import { tool } from "@opencode-ai/plugin";
|
|
6
7
|
|
|
7
8
|
const z = tool.schema;
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
/**
|
|
11
|
+
* 执行 agp 命令
|
|
12
|
+
* @param {string[]} args - 命令参数
|
|
13
|
+
* @returns {Promise<string>} 命令输出
|
|
14
|
+
*/
|
|
15
|
+
function executeAgp(args) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const proc = spawn("agp", args, {
|
|
18
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
let stdout = "";
|
|
22
|
+
let stderr = "";
|
|
23
|
+
|
|
24
|
+
proc.stdout.on("data", (data) => {
|
|
25
|
+
stdout += data.toString();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
proc.stderr.on("data", (data) => {
|
|
29
|
+
stderr += data.toString();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
proc.on("close", (code) => {
|
|
33
|
+
if (code === 0) {
|
|
34
|
+
resolve(stdout.trim() || "Success");
|
|
35
|
+
} else {
|
|
36
|
+
reject(new Error(stderr.trim() || `Exit code: ${code}`));
|
|
37
|
+
}
|
|
22
38
|
});
|
|
23
39
|
|
|
24
40
|
proc.on("error", (error) => {
|
|
@@ -35,8 +51,11 @@ export const agpDiff = tool({
|
|
|
35
51
|
},
|
|
36
52
|
execute: async (args, context) => {
|
|
37
53
|
try {
|
|
38
|
-
const
|
|
39
|
-
|
|
54
|
+
const cmdArgs = ["diff"];
|
|
55
|
+
if (args.file) {
|
|
56
|
+
cmdArgs.push("--file", args.file);
|
|
57
|
+
}
|
|
58
|
+
const result = await executeAgp(cmdArgs);
|
|
40
59
|
return `✅ ${result}`;
|
|
41
60
|
} catch (error) {
|
|
42
61
|
return `❌ 执行失败: ${error}`;
|
|
@@ -66,8 +85,11 @@ export const agpInteractive = tool({
|
|
|
66
85
|
},
|
|
67
86
|
execute: async (args, context) => {
|
|
68
87
|
try {
|
|
69
|
-
const
|
|
70
|
-
|
|
88
|
+
const cmdArgs = ["interactive"];
|
|
89
|
+
if (args.command) {
|
|
90
|
+
cmdArgs.push(args.command);
|
|
91
|
+
}
|
|
92
|
+
const result = await executeAgp(cmdArgs);
|
|
71
93
|
return `✅ ${result}`;
|
|
72
94
|
} catch (error) {
|
|
73
95
|
return `❌ 执行失败: ${error}`;
|
|
@@ -127,8 +149,8 @@ export const agpStop = tool({
|
|
|
127
149
|
}
|
|
128
150
|
});
|
|
129
151
|
|
|
130
|
-
// OpenCode 插件入口 -
|
|
131
|
-
export
|
|
152
|
+
// OpenCode 插件入口 - 使用具名导出 (named export)
|
|
153
|
+
export const AgentGhostPanel = async (ctx) => {
|
|
132
154
|
return {
|
|
133
155
|
tool: {
|
|
134
156
|
"agp-diff": agpDiff,
|
|
@@ -140,4 +162,4 @@ export default async function(input) {
|
|
|
140
162
|
"agp-stop": agpStop
|
|
141
163
|
}
|
|
142
164
|
};
|
|
143
|
-
}
|
|
165
|
+
};
|