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.
- package/README.md +300 -173
- package/SKILL.md +114 -98
- package/adev.js +1319 -1285
- package/autofix/agents/antigravity.js +379 -0
- package/autofix/agents/claude.js +147 -0
- package/autofix/agents/codex.js +179 -0
- package/autofix/agents/exec.js +230 -0
- package/autofix/agents/index.js +400 -0
- package/autofix/agents/opencode.js +233 -0
- package/autofix/agents/pi.js +247 -0
- package/autofix/agiledev.js +98 -0
- package/autofix/bridge.js +371 -0
- package/autofix/cli.js +712 -0
- package/autofix/context.js +152 -0
- package/autofix/conversation.js +302 -0
- package/autofix/coordinator.js +2892 -0
- package/autofix/git.js +459 -0
- package/autofix/policy.js +230 -0
- package/autofix/profile.js +578 -0
- package/autofix/public/app.js +3668 -0
- package/autofix/public/i18n-id.js +282 -0
- package/autofix/public/index.html +32 -0
- package/autofix/public/style.css +2463 -0
- package/autofix/queue.js +146 -0
- package/autofix/scheduler.js +994 -0
- package/autofix/scope.js +32 -0
- package/autofix/service.js +1940 -0
- package/autofix/store.js +375 -0
- package/autofix/workspace.js +298 -0
- package/autofix/worktree.js +379 -0
- package/docs/autofix-design.md +801 -0
- package/docs/autofix-profiles.example.json +65 -0
- package/imgs/Bug/350/247/243/345/206/263/345/244/207/346/263/250.png +0 -0
- package/imgs/logo.png +0 -0
- package/imgs//344/277/256/346/224/271Bug/347/212/266/346/200/201.png +0 -0
- package/imgs//345/270/256/346/210/221/344/277/256/345/244/215Bug-20260922-010.png +0 -0
- 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
- 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
- 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
- package/package.json +39 -36
package/autofix/queue.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 确定性派工队列。
|
|
3
|
+
*
|
|
4
|
+
* 主 Agent 仍然可以做最终决策,但"哪些任务该先派、还能并行几个、会不会撞范围"
|
|
5
|
+
* 这些机械判断不该每次都交给 LLM 重新算。这里用纯函数算出一份派工计划:
|
|
6
|
+
* - 严重度优先(P1 < P2 < ...),同级按等待时长、返工次数、周期排序;
|
|
7
|
+
* - 自动扣除正在运行的任务与空闲槽位;
|
|
8
|
+
* - 共享工作区模式下做范围冲突过滤;工作树隔离模式下不再需要范围互斥。
|
|
9
|
+
*
|
|
10
|
+
* 队列只产出建议,不直接改状态;派工仍走 coordinator.dispatch_task。
|
|
11
|
+
*/
|
|
12
|
+
import { severityRank } from "./scheduler.js";
|
|
13
|
+
|
|
14
|
+
export const DISPATCHABLE_STATES = Object.freeze(["discovered", "queued"]);
|
|
15
|
+
|
|
16
|
+
/** 归一化范围路径,仅用于比较:统一斜杠、去掉 ./、忽略大小写。 */
|
|
17
|
+
export function normalizeScope(value) {
|
|
18
|
+
return String(value || "")
|
|
19
|
+
.trim()
|
|
20
|
+
.replace(/\\/g, "/")
|
|
21
|
+
.replace(/^\.\//, "")
|
|
22
|
+
.replace(/\/+$/, "")
|
|
23
|
+
.toLowerCase();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 两个范围是否重叠:相等,或一方是另一方的上级目录。 */
|
|
27
|
+
export function scopeOverlaps(a, b) {
|
|
28
|
+
const x = normalizeScope(a);
|
|
29
|
+
const y = normalizeScope(b);
|
|
30
|
+
if (!x || !y) return false;
|
|
31
|
+
return x === y || x.startsWith(`${y}/`) || y.startsWith(`${x}/`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 任务是否处于可派工状态。 */
|
|
35
|
+
export function isDispatchable(task) {
|
|
36
|
+
return !!task && DISPATCHABLE_STATES.includes(task.status);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 计算派工优先级:数值越小越先派。
|
|
41
|
+
*
|
|
42
|
+
* 严重度是硬优先级,任何等待时长都不能让 P2 越过 P1;
|
|
43
|
+
* 同级内部依次考虑:返工次数多的先处理(已经卡过)、周期新的先处理、等待久的先处理。
|
|
44
|
+
*/
|
|
45
|
+
export function dispatchPriority(task, now = Date.now()) {
|
|
46
|
+
const severity = severityRank(task);
|
|
47
|
+
const rework = Number(task?.reworkCount) || 0;
|
|
48
|
+
const cycle = Number(task?.cycle) || 1;
|
|
49
|
+
const created = Date.parse(task?.discoveredAt || task?.createdAt || task?.updatedAt || "") || 0;
|
|
50
|
+
const waitedMinutes = created ? Math.max(0, Math.min(100000, (now - created) / 60000)) : 0;
|
|
51
|
+
return severity * 1e12 - rework * 1e9 - cycle * 1e7 - waitedMinutes * 1e3;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 任务声明的改动范围(主 Agent 派工时写进 task.scope)。 */
|
|
55
|
+
export function taskScope(task) {
|
|
56
|
+
const raw = Array.isArray(task?.scope) ? task.scope : (task?.scope ? [task.scope] : []);
|
|
57
|
+
return raw.map(normalizeScope).filter(Boolean);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 生成派工计划。
|
|
62
|
+
*
|
|
63
|
+
* @param {object} opts
|
|
64
|
+
* @param {object[]} opts.tasks 全部任务
|
|
65
|
+
* @param {Set<string>|string[]} opts.runningIds 正在运行的任务
|
|
66
|
+
* @param {number} opts.maxWorkers 并行上限
|
|
67
|
+
* @param {Map<string,string[]>|object} opts.activeScopes 运行中任务的范围
|
|
68
|
+
* @param {boolean} opts.isolated 是否启用了任务级工作树隔离
|
|
69
|
+
* @param {number} opts.now
|
|
70
|
+
* @returns {{taskId:string,title:string,severity:string,status:string,reason:string}[]}
|
|
71
|
+
*/
|
|
72
|
+
export function selectDispatchPlan({
|
|
73
|
+
tasks = [], runningIds = [], maxWorkers = 3, activeScopes = new Map(), isolated = false, now = Date.now(),
|
|
74
|
+
} = {}) {
|
|
75
|
+
const running = runningIds instanceof Set ? runningIds : new Set(runningIds || []);
|
|
76
|
+
const slots = Math.max(0, Math.floor(Number(maxWorkers) || 0) - running.size);
|
|
77
|
+
if (!slots) return [];
|
|
78
|
+
|
|
79
|
+
const scopeEntries = activeScopes instanceof Map
|
|
80
|
+
? [...activeScopes.entries()]
|
|
81
|
+
: Object.entries(activeScopes || {});
|
|
82
|
+
|
|
83
|
+
// 先在"已被占用的范围"里放上运行中任务的范围;共享工作区时逐个面试
|
|
84
|
+
const reserved = [];
|
|
85
|
+
for (const [, scope] of scopeEntries) {
|
|
86
|
+
const list = (Array.isArray(scope) ? scope : [scope]).map(normalizeScope).filter(Boolean);
|
|
87
|
+
if (list.length) reserved.push(list);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const candidates = (tasks || [])
|
|
91
|
+
.filter(isDispatchable)
|
|
92
|
+
.filter(t => t?.taskId && !running.has(t.taskId))
|
|
93
|
+
.sort((a, b) => dispatchPriority(a, now) - dispatchPriority(b, now));
|
|
94
|
+
|
|
95
|
+
const plan = [];
|
|
96
|
+
for (const task of candidates) {
|
|
97
|
+
if (plan.length >= slots) break;
|
|
98
|
+
const scope = taskScope(task);
|
|
99
|
+
|
|
100
|
+
if (!isolated && scope.length) {
|
|
101
|
+
const clash = reserved.find(list => list.some(a => scope.some(b => scopeOverlaps(a, b))));
|
|
102
|
+
if (clash) continue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (scope.length) reserved.push(scope);
|
|
106
|
+
|
|
107
|
+
const severity = task.severity || "未分级";
|
|
108
|
+
const waited = Date.parse(task.discoveredAt || task.createdAt || task.updatedAt || "") || 0;
|
|
109
|
+
const waitedMinutes = waited ? Math.max(0, Math.round((now - waited) / 60000)) : 0;
|
|
110
|
+
const reasons = [severity];
|
|
111
|
+
if (Number(task.reworkCount) > 0) reasons.push(`已返工 ${task.reworkCount} 轮`);
|
|
112
|
+
if (waitedMinutes > 0) reasons.push(`等待 ${waitedMinutes} 分钟`);
|
|
113
|
+
if (isolated) reasons.push("工作树隔离");
|
|
114
|
+
else if (scope.length) reasons.push(`范围 ${scope.slice(0, 3).join(", ")}`);
|
|
115
|
+
|
|
116
|
+
plan.push({
|
|
117
|
+
taskId: task.taskId,
|
|
118
|
+
title: task.title || "",
|
|
119
|
+
severity: task.severity || null,
|
|
120
|
+
status: task.status,
|
|
121
|
+
reason: reasons.join(" · "),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return plan;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** 把计划渲染成主 Agent 可直接读的一段文字。 */
|
|
128
|
+
export function formatDispatchPlan(plan = []) {
|
|
129
|
+
if (!plan.length) return "-(当前没有可派工的任务,或并行槽位已满)";
|
|
130
|
+
return plan
|
|
131
|
+
.map((item, i) => `${i + 1}. ${item.taskId} [${item.status}] ${item.severity || "-"} ${item.title || ""}(${item.reason})`)
|
|
132
|
+
.join("\n");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 主 Agent 长时间没有推进时的兜底说明。
|
|
137
|
+
* 仍然把完整上下文交给 worker,不让它凭一句标题猜问题。
|
|
138
|
+
*/
|
|
139
|
+
export function defaultInstruction(task) {
|
|
140
|
+
const title = task?.title ? `「${task.title}」` : "该缺陷";
|
|
141
|
+
return [
|
|
142
|
+
`修复${title}。先用 get_task_context 读取复现步骤、预期/实际行为与截图,定位根因后做最小必要修改。`,
|
|
143
|
+
"只改本任务范围内的文件;改完运行与改动直接相关的测试;最后调用 report_result 报告 outcome、summary、changedFiles、commands。",
|
|
144
|
+
"不要提交、不要推送、不要修改缺陷状态。不要执行编译、打包或全量类型检查。",
|
|
145
|
+
].join("\n");
|
|
146
|
+
}
|