opencode-agent-ghost-panel 0.1.0 → 0.1.3

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.
Files changed (2) hide show
  1. package/index.js +143 -21
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -54,13 +54,135 @@ function executeAgp(args) {
54
54
  });
55
55
  }
56
56
 
57
+ // 定义 AGP 工具
58
+ export const agpDiff = {
59
+ description: "在 tmux 新窗口显示 git diff(带语法高亮)",
60
+ args: {
61
+ file: z.string().optional().describe("文件路径(可选,默认当前目录)")
62
+ },
63
+ execute: async (args, context) => {
64
+ try {
65
+ const fileArg = args.file ? ` --file ${args.file}` : "";
66
+ const result = await executeAgp(["diff" + fileArg]);
67
+ return `✅ ${result}`;
68
+ } catch (error) {
69
+ return `❌ 执行失败: ${error}`;
70
+ }
71
+ }
72
+ };
73
+
74
+ export const agpLogs = {
75
+ description: "实时监控日志文件",
76
+ args: {
77
+ file: z.string().describe("日志文件路径")
78
+ },
79
+ execute: async (args, context) => {
80
+ try {
81
+ const result = await executeAgp(["logs", args.file]);
82
+ return `✅ ${result}`;
83
+ } catch (error) {
84
+ return `❌ 执行失败: ${error}`;
85
+ }
86
+ }
87
+ };
88
+
89
+ export const agpInteractive = {
90
+ description: "打开交互式终端(用于 ssh、sudo 等需要用户输入的命令)",
91
+ args: {
92
+ command: z.string().optional().describe("初始命令(可选)")
93
+ },
94
+ execute: async (args, context) => {
95
+ try {
96
+ const cmdArg = args.command ? ` ${args.command}` : "";
97
+ const result = await executeAgp(["interactive" + cmdArg]);
98
+ return `✅ ${result}`;
99
+ } catch (error) {
100
+ return `❌ 执行失败: ${error}`;
101
+ }
102
+ }
103
+ };
104
+
105
+ export const agpStatus = {
106
+ description: "查看 AGP 守护进程状态",
107
+ args: {},
108
+ execute: async (args, context) => {
109
+ try {
110
+ const result = await executeAgp(["status"]);
111
+ return result;
112
+ } catch (error) {
113
+ return `❌ AGP 未运行。请先运行: agp start`;
114
+ }
115
+ }
116
+ };
117
+
118
+ export const agpSessions = {
119
+ description: "列出所有 tmux 会话",
120
+ args: {},
121
+ execute: async (args, context) => {
122
+ try {
123
+ const result = await executeAgp(["sessions"]);
124
+ return result;
125
+ } catch (error) {
126
+ return `❌ 执行失败: ${error}`;
127
+ }
128
+ }
129
+ };
130
+
131
+ export const agpStart = {
132
+ description: "启动 AGP 守护进程",
133
+ args: {},
134
+ execute: async (args, context) => {
135
+ try {
136
+ const result = await executeAgp(["start"]);
137
+ return result;
138
+ } catch (error) {
139
+ return `❌ 启动失败: ${error}`;
140
+ }
141
+ }
142
+ };
143
+
144
+ export const agpStop = {
145
+ description: "停止 AGP 守护进程",
146
+ args: {},
147
+ execute: async (args, context) => {
148
+ try {
149
+ const result = await executeAgp(["stop"]);
150
+ return result;
151
+ } catch (error) {
152
+ return `❌ 停止失败: ${error}`;
153
+ }
154
+ }
155
+ };
156
+
157
+ // OpenCode 插件入口
158
+ export default async function(input) {
159
+ return {
160
+ tool: {
161
+ "agp-diff": agpDiff,
162
+ "agp-logs": agpLogs,
163
+ "agp-interactive": agpInteractive,
164
+ "agp-status": agpStatus,
165
+ "agp-sessions": agpSessions,
166
+ "agp-start": agpStart,
167
+ "agp-stop": agpStop
168
+ }
169
+ };
170
+ }
171
+ });
172
+
173
+ proc.on("error", (error) => {
174
+ reject(error);
175
+ });
176
+ });
177
+ }
178
+
57
179
  // 定义 AGP 工具
58
180
  export const agpDiff = tool({
59
181
  description: "在 tmux 新窗口显示 git diff(带语法高亮)",
60
182
  args: {
61
183
  file: z.string().optional().describe("文件路径(可选,默认当前目录)")
62
184
  },
63
- execute: async (args) => {
185
+ execute: async (args, context) => {
64
186
  try {
65
187
  const fileArg = args.file ? ` --file ${args.file}` : "";
66
188
  const result = await executeAgp(["diff" + fileArg]);
@@ -76,7 +198,7 @@ export const agpLogs = tool({
76
198
  args: {
77
199
  file: z.string().describe("日志文件路径")
78
200
  },
79
- execute: async (args) => {
201
+ execute: async (args, context) => {
80
202
  try {
81
203
  const result = await executeAgp(["logs", args.file]);
82
204
  return `✅ ${result}`;
@@ -91,7 +213,7 @@ export const agpInteractive = tool({
91
213
  args: {
92
214
  command: z.string().optional().describe("初始命令(可选)")
93
215
  },
94
- execute: async (args) => {
216
+ execute: async (args, context) => {
95
217
  try {
96
218
  const cmdArg = args.command ? ` ${args.command}` : "";
97
219
  const result = await executeAgp(["interactive" + cmdArg]);
@@ -105,7 +227,7 @@ export const agpInteractive = tool({
105
227
  export const agpStatus = tool({
106
228
  description: "查看 AGP 守护进程状态",
107
229
  args: {},
108
- execute: async () => {
230
+ execute: async (args, context) => {
109
231
  try {
110
232
  const result = await executeAgp(["status"]);
111
233
  return result;
@@ -118,7 +240,7 @@ export const agpStatus = tool({
118
240
  export const agpSessions = tool({
119
241
  description: "列出所有 tmux 会话",
120
242
  args: {},
121
- execute: async () => {
243
+ execute: async (args, context) => {
122
244
  try {
123
245
  const result = await executeAgp(["sessions"]);
124
246
  return result;
@@ -131,7 +253,7 @@ export const agpSessions = tool({
131
253
  export const agpStart = tool({
132
254
  description: "启动 AGP 守护进程",
133
255
  args: {},
134
- execute: async () => {
256
+ execute: async (args, context) => {
135
257
  try {
136
258
  const result = await executeAgp(["start"]);
137
259
  return result;
@@ -144,7 +266,7 @@ export const agpStart = tool({
144
266
  export const agpStop = tool({
145
267
  description: "停止 AGP 守护进程",
146
268
  args: {},
147
- execute: async () => {
269
+ execute: async (args, context) => {
148
270
  try {
149
271
  const result = await executeAgp(["stop"]);
150
272
  return result;
@@ -154,17 +276,17 @@ export const agpStop = tool({
154
276
  }
155
277
  });
156
278
 
157
- // 导出插件
158
- export default {
159
- name: "agent-ghost-panel",
160
- version: "0.2.0",
161
- tools: {
162
- "agp-diff": agpDiff,
163
- "agp-logs": agpLogs,
164
- "agp-interactive": agpInteractive,
165
- "agp-status": agpStatus,
166
- "agp-sessions": agpSessions,
167
- "agp-start": agpStart,
168
- "agp-stop": agpStop
169
- }
170
- };
279
+ // OpenCode 插件入口 - 必须是 async function
280
+ export default async function(input) {
281
+ return {
282
+ tool: {
283
+ "agp-diff": agpDiff,
284
+ "agp-logs": agpLogs,
285
+ "agp-interactive": agpInteractive,
286
+ "agp-status": agpStatus,
287
+ "agp-sessions": agpSessions,
288
+ "agp-start": agpStart,
289
+ "agp-stop": agpStop
290
+ }
291
+ };
292
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-agent-ghost-panel",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "基于 Tmux 的终端多路复用与交互增强",
5
5
  "main": "index.js",
6
6
  "type": "module",