agiledev-cli 0.1.4 → 0.3.0

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 (40) hide show
  1. package/README.md +300 -173
  2. package/SKILL.md +114 -98
  3. package/adev.js +1319 -1285
  4. package/autofix/agents/antigravity.js +379 -0
  5. package/autofix/agents/claude.js +147 -0
  6. package/autofix/agents/codex.js +179 -0
  7. package/autofix/agents/exec.js +230 -0
  8. package/autofix/agents/index.js +400 -0
  9. package/autofix/agents/opencode.js +233 -0
  10. package/autofix/agents/pi.js +247 -0
  11. package/autofix/agiledev.js +98 -0
  12. package/autofix/bridge.js +371 -0
  13. package/autofix/cli.js +712 -0
  14. package/autofix/context.js +152 -0
  15. package/autofix/conversation.js +302 -0
  16. package/autofix/coordinator.js +2892 -0
  17. package/autofix/git.js +459 -0
  18. package/autofix/policy.js +230 -0
  19. package/autofix/profile.js +578 -0
  20. package/autofix/public/app.js +3668 -0
  21. package/autofix/public/i18n-id.js +282 -0
  22. package/autofix/public/index.html +32 -0
  23. package/autofix/public/style.css +2463 -0
  24. package/autofix/queue.js +146 -0
  25. package/autofix/scheduler.js +994 -0
  26. package/autofix/scope.js +32 -0
  27. package/autofix/service.js +1940 -0
  28. package/autofix/store.js +375 -0
  29. package/autofix/workspace.js +298 -0
  30. package/autofix/worktree.js +379 -0
  31. package/docs/autofix-design.md +801 -0
  32. package/docs/autofix-profiles.example.json +65 -0
  33. package/imgs/Bug/350/247/243/345/206/263/345/244/207/346/263/250.png +0 -0
  34. package/imgs/logo.png +0 -0
  35. package/imgs//344/277/256/346/224/271Bug/347/212/266/346/200/201.png +0 -0
  36. package/imgs//345/270/256/346/210/221/344/277/256/345/244/215Bug-20260922-010.png +0 -0
  37. package/imgs//346/237/245/347/234/213/345/271/266/345/210/206/346/236/220/351/234/200/346/261/202/346/226/207/346/241/243.png +0 -0
  38. package/imgs//347/234/213/344/270/200/344/270/213/346/210/221/347/216/260/345/234/250/346/234/211/345/223/252/344/272/233/345/274/200/345/217/221/344/273/273/345/212/241.png +0 -0
  39. package/imgs//347/234/213/344/270/200/344/270/213/346/210/221/350/277/230/346/234/211/345/223/252/344/272/233Bug/346/234/252/350/247/243/345/206/263.png +0 -0
  40. package/package.json +39 -36
@@ -0,0 +1,371 @@
1
+ /**
2
+ * MCP stdio 工具桥。
3
+ *
4
+ * Claude Code / OpenCode 以 stdio 方式启动本进程,把 tools/call 转发到
5
+ * 本地服务(127.0.0.1 + 启动 token),由 coordinator 执行后返回结果。
6
+ *
7
+ * 只暴露本地 stdio,不开放网络端口;工具参数传任务 ID 与文本,不拼接 shell。
8
+ */
9
+ import readline from "node:readline";
10
+
11
+ const SUPPORTED_PROTOCOLS = ["2025-06-18", "2025-03-26", "2024-11-05"];
12
+ const DEFAULT_PROTOCOL = "2025-06-18";
13
+
14
+ /* ======================== 工具定义 ======================== */
15
+
16
+ const MAIN_TOOLS = [
17
+ {
18
+ name: "list_tasks",
19
+ description: "查看当前工作区的修复任务列表。不传 status 时返回全部任务。",
20
+ inputSchema: {
21
+ type: "object",
22
+ properties: {
23
+ status: {
24
+ type: "string",
25
+ description: "可选。不传或传 all 表示全部;也可传具体状态(discovered/queued/launching/running/verifying/review/done/needs_human/stopped),多个用逗号分隔",
26
+ },
27
+ },
28
+ },
29
+ },
30
+ {
31
+ name: "get_dispatch_plan",
32
+ description: "读取调度器算好的派工计划:按严重度/返工次数/等待时长排序,已扣除运行中任务与空闲槽位,并处理共享工作区的范围冲突。派工前调用一次即可,不必自己重新推导优先级。",
33
+ inputSchema: {
34
+ type: "object",
35
+ properties: {},
36
+ },
37
+ },
38
+ {
39
+ name: "dispatch_task",
40
+ description: "把一个缺陷分派给修复 Agent(后台并行执行,立即返回)。可以连续派多个互不冲突的缺陷。",
41
+ inputSchema: {
42
+ type: "object",
43
+ properties: {
44
+ taskId: { type: "string", description: "任务编号,如 BUG-20260922-011" },
45
+ worker: { type: "string", description: "修复 Agent 使用的 CLI:claude、opencode 或 antigravity" },
46
+ instruction: { type: "string", description: "给修复 Agent 的完整任务说明" },
47
+ scope: {
48
+ type: "array",
49
+ items: { type: "string" },
50
+ description: "本次修复预计改动的文件或目录(相对工作区路径),用于并行冲突检测与统计;开启工作树隔离后不做互斥,但建议照常填写",
51
+ },
52
+ },
53
+ required: ["taskId", "instruction"],
54
+ },
55
+ },
56
+ {
57
+ name: "send_message",
58
+ description: "给指定任务补充上下文或给用户发消息,形成共享记录",
59
+ inputSchema: {
60
+ type: "object",
61
+ properties: {
62
+ taskId: { type: "string" },
63
+ text: { type: "string" },
64
+ to: { type: "string", description: "可选:user 表示转达给用户" },
65
+ },
66
+ required: ["text"],
67
+ },
68
+ },
69
+ {
70
+ name: "request_review",
71
+ description: "复核某个任务:返回改动摘要、改动文件、验证结论,以及剩余复核轮次预算。看完后要么 dispatch_task 返工,要么 finish_task 交付。",
72
+ inputSchema: {
73
+ type: "object",
74
+ properties: { taskId: { type: "string" } },
75
+ required: ["taskId"],
76
+ },
77
+ },
78
+ {
79
+ name: "finish_task",
80
+ description: "复核通过后交付:自动把本任务改动 commit 到当前分支、合并进测试分支,再把缺陷转为待验证。验证命令缺失不影响调用;只有验证真正失败且未返工时才不能调用。",
81
+ inputSchema: {
82
+ type: "object",
83
+ properties: { taskId: { type: "string" }, notes: { type: "string", description: "复核结论与遗留点(会写进缺陷备注与提交信息)" } },
84
+ required: ["taskId"],
85
+ },
86
+ },
87
+ {
88
+ name: "ask_human",
89
+ description: "只在真的必须人工决定时调用:业务意图不明、方案有实质取舍、要改公开接口/权限/财务库存,或反复返工仍无法通过验证。会生成可点击选项;验证命令缺失、验证失败原因可疑、非阻塞的风格问题都不要调用它。",
90
+ inputSchema: {
91
+ type: "object",
92
+ properties: {
93
+ taskId: { type: "string" },
94
+ question: { type: "string", description: "要问的问题" },
95
+ context: { type: "string", description: "背景与为什么需要人工决定" },
96
+ options: {
97
+ type: "array",
98
+ description: "可选选项列表",
99
+ items: {
100
+ type: "object",
101
+ properties: {
102
+ id: { type: "string" },
103
+ label: { type: "string" },
104
+ consequence: { type: "string" },
105
+ },
106
+ },
107
+ },
108
+ },
109
+ required: ["question"],
110
+ },
111
+ },
112
+ {
113
+ name: "report_blocked",
114
+ description: "报告权限、环境或测试阻塞,不擅自选择处理办法",
115
+ inputSchema: {
116
+ type: "object",
117
+ properties: { taskId: { type: "string" }, reason: { type: "string" }, detail: { type: "string" } },
118
+ required: ["taskId", "reason"],
119
+ },
120
+ },
121
+ ];
122
+
123
+ const WORKER_TOOLS = [
124
+ {
125
+ name: "get_task_context",
126
+ description: "获取当前任务完整的共享上下文(缺陷详情、截图路径、评论、历史结论)",
127
+ inputSchema: { type: "object", properties: { taskId: { type: "string" } } },
128
+ },
129
+ {
130
+ name: "send_message",
131
+ description: "向主 Agent 或用户补充信息",
132
+ inputSchema: {
133
+ type: "object",
134
+ properties: { taskId: { type: "string" }, text: { type: "string" } },
135
+ required: ["text"],
136
+ },
137
+ },
138
+ {
139
+ name: "report_result",
140
+ description: "报告修复结果。必须使用固定结构,且不得自行修改缺陷状态。",
141
+ inputSchema: {
142
+ type: "object",
143
+ properties: {
144
+ taskId: { type: "string" },
145
+ outcome: { type: "string", enum: ["fixed", "no_change", "needs_human", "failed"] },
146
+ summary: { type: "string", description: "根因和修改摘要" },
147
+ changedFiles: { type: "array", items: { type: "string" } },
148
+ commands: {
149
+ type: "array",
150
+ items: {
151
+ type: "object",
152
+ properties: {
153
+ command: { type: "string" },
154
+ exitCode: { type: "number" },
155
+ summary: { type: "string" },
156
+ },
157
+ },
158
+ },
159
+ unresolved: { type: "array", items: { type: "string" } },
160
+ needsHumanReason: { type: "string" },
161
+ },
162
+ required: ["taskId", "outcome", "summary"],
163
+ },
164
+ },
165
+ ];
166
+
167
+ /**
168
+ * 只读复核 Agent 的工具集。
169
+ *
170
+ * 复核 Agent 只能读、只能报告,不能改代码、不能派工、不能动线上状态——
171
+ * 工具集里没有任何写代码或流转缺陷的能力,从协议层保证"只读复核"名副其实。
172
+ */
173
+ const REVIEWER_TOOLS = [
174
+ {
175
+ name: "get_task_context",
176
+ description: "获取当前任务完整的共享上下文(缺陷详情、截图路径、评论、历史结论)",
177
+ inputSchema: { type: "object", properties: { taskId: { type: "string" } } },
178
+ },
179
+ {
180
+ name: "report_review",
181
+ description: "提交只读复核结论。verdict 只能是 PASS 或 ISSUES;ISSUES 时必须在 issues 里写清每个问题的文件与位置。",
182
+ inputSchema: {
183
+ type: "object",
184
+ properties: {
185
+ taskId: { type: "string" },
186
+ verdict: { type: "string", enum: ["PASS", "ISSUES"] },
187
+ summary: { type: "string", description: "复核结论概述" },
188
+ issues: {
189
+ type: "array",
190
+ description: "发现的问题;PASS 时留空数组",
191
+ items: {
192
+ type: "object",
193
+ properties: {
194
+ file: { type: "string", description: "问题所在文件(相对工作区路径)" },
195
+ line: { type: "string", description: "行号或位置描述" },
196
+ detail: { type: "string", description: "问题是什么、为什么是问题" },
197
+ severity: { type: "string", description: "blocker | major | minor" },
198
+ },
199
+ },
200
+ },
201
+ checkedFiles: {
202
+ type: "array",
203
+ description: "本次实际查看过的文件",
204
+ items: { type: "string" },
205
+ },
206
+ },
207
+ required: ["taskId", "verdict", "summary"],
208
+ },
209
+ },
210
+ ];
211
+
212
+ export function toolsForRole(role) {
213
+ if (role === "worker") return WORKER_TOOLS;
214
+ if (role === "reviewer") return REVIEWER_TOOLS;
215
+ // Antigravity 的 MCP 配置是全局静态文件,无法按进程区分 main / worker,
216
+ // 这里提供合并工具集,由各自的提示词约束使用范围。
217
+ if (role === "all") {
218
+ const out = [];
219
+ const seen = new Set();
220
+ for (const tool of [...MAIN_TOOLS, ...WORKER_TOOLS, ...REVIEWER_TOOLS]) {
221
+ if (seen.has(tool.name)) continue;
222
+ seen.add(tool.name);
223
+ out.push(tool);
224
+ }
225
+ return out;
226
+ }
227
+ return MAIN_TOOLS;
228
+ }
229
+
230
+ /* ======================== 与本地服务通信 ======================== */
231
+
232
+ export function createTransport({ endpoint, token, attempt }) {
233
+ return async function call(name, args) {
234
+ const headers = {
235
+ "Content-Type": "application/json",
236
+ "X-Autofix-Token": token,
237
+ };
238
+ // 每次派工一个执行号:服务端据此拒绝上一轮残留进程迟到的汇报,
239
+ // 也能识别同一次执行的重复提交。
240
+ if (attempt) headers["X-Autofix-Attempt"] = attempt;
241
+ const res = await fetch(endpoint, {
242
+ method: "POST",
243
+ headers,
244
+ body: JSON.stringify({ name, arguments: args || {} }),
245
+ signal: AbortSignal.timeout(10 * 60 * 1000),
246
+ });
247
+ const payload = await res.json().catch(() => ({}));
248
+ if (!res.ok) {
249
+ return {
250
+ isError: true,
251
+ content: [{ type: "text", text: `工具 ${name} 调用失败(${res.status}):${payload.message || "未知错误"}` }],
252
+ };
253
+ }
254
+ return payload.result ?? { isError: true, content: [{ type: "text", text: "服务未返回结果" }] };
255
+ };
256
+ }
257
+
258
+ /* ======================== MCP 服务器 ======================== */
259
+
260
+ /**
261
+ * 启动 stdio MCP 服务器。
262
+ * role: main | worker —— 决定暴露哪些工具。
263
+ */
264
+ export function serveStdio({ role = "main", endpoint, token, attempt, input = process.stdin, output = process.stdout } = {}) {
265
+ const call = createTransport({ endpoint, token, attempt });
266
+ const rl = readline.createInterface({ input, terminal: false });
267
+
268
+ const send = (msg) => {
269
+ output.write(JSON.stringify(msg) + "\n");
270
+ };
271
+
272
+ rl.on("line", async (line) => {
273
+ const t = line.trim();
274
+ if (!t) return;
275
+ let msg;
276
+ try { msg = JSON.parse(t); } catch { return; }
277
+ if (!msg || msg.jsonrpc !== "2.0") return;
278
+
279
+ const id = msg.id;
280
+ const method = msg.method;
281
+
282
+ try {
283
+ if (method === "initialize") {
284
+ const requested = msg.params?.protocolVersion;
285
+ const protocolVersion = SUPPORTED_PROTOCOLS.includes(requested) ? requested : DEFAULT_PROTOCOL;
286
+ send({
287
+ jsonrpc: "2.0",
288
+ id,
289
+ result: {
290
+ protocolVersion,
291
+ capabilities: { tools: {} },
292
+ serverInfo: { name: "adev-autofix", version: "1.0.0" },
293
+ },
294
+ });
295
+ return;
296
+ }
297
+
298
+ if (method === "notifications/initialized" || method === "notifications/cancelled") return;
299
+
300
+ if (method === "tools/list") {
301
+ send({ jsonrpc: "2.0", id, result: { tools: toolsForRole(role) } });
302
+ return;
303
+ }
304
+
305
+ if (method === "tools/call") {
306
+ const name = msg.params?.name;
307
+ const args = msg.params?.arguments || {};
308
+ const result = await call(name, args);
309
+ send({ jsonrpc: "2.0", id, result });
310
+ return;
311
+ }
312
+
313
+ if (id !== undefined) {
314
+ send({ jsonrpc: "2.0", id, error: { code: -32601, message: `不支持的方法: ${method}` } });
315
+ }
316
+ } catch (e) {
317
+ if (id !== undefined) {
318
+ send({
319
+ jsonrpc: "2.0",
320
+ id,
321
+ error: { code: -32603, message: String(e?.message || e) },
322
+ });
323
+ }
324
+ }
325
+ });
326
+
327
+ rl.on("close", () => process.exit(0));
328
+ }
329
+
330
+ /* ======================== MCP 配置(给 --mcp-config 用) ======================== */
331
+
332
+ export function buildMcpConfig({ bridgePath, role, endpoint, token, attempt }) {
333
+ const args = [bridgePath, "--role", role, "--endpoint", endpoint, "--token", token];
334
+ if (attempt) args.push("--attempt", attempt);
335
+ return {
336
+ mcpServers: {
337
+ "adev-autofix": {
338
+ type: "stdio",
339
+ command: process.execPath,
340
+ args,
341
+ // Antigravity 的 MCP 配置是全局静态文件,命令行参数可能被复用;
342
+ // 环境变量让同一次派工的 bridge 始终带上正确的执行号。
343
+ env: attempt ? { ADEV_AUTOFIX_ATTEMPT: attempt } : {},
344
+ },
345
+ },
346
+ };
347
+ }
348
+
349
+ /* ======================== 命令行入口 ======================== */
350
+
351
+ export function isDirectInvocation(argv = process.argv) {
352
+ const entry = argv[1];
353
+ if (!entry) return false;
354
+ return /bridge(\.js)?$/i.test(entry);
355
+ }
356
+
357
+ if (isDirectInvocation()) {
358
+ const args = process.argv.slice(2);
359
+ const get = (flag) => {
360
+ const i = args.indexOf(flag);
361
+ return i >= 0 ? args[i + 1] : null;
362
+ };
363
+ // 除了命令行参数,也支持环境变量:Antigravity 的 MCP 配置只能写全局静态文件,
364
+ // 把 endpoint/token 放进 env 可以避免每次运行都重写参数。
365
+ serveStdio({
366
+ role: get("--role") || process.env.ADEV_AUTOFIX_ROLE || "main",
367
+ endpoint: get("--endpoint") || process.env.ADEV_AUTOFIX_ENDPOINT,
368
+ token: get("--token") || process.env.ADEV_AUTOFIX_TOKEN,
369
+ attempt: get("--attempt") || process.env.ADEV_AUTOFIX_ATTEMPT,
370
+ });
371
+ }