agiledev-cli 0.1.5 → 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 -185
- 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
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 任务级 Git 工作树隔离。
|
|
3
|
+
*
|
|
4
|
+
* 并行修复最大的风险不是模型能力,而是多个 worker 同时改同一个工作目录:
|
|
5
|
+
* 基线 diff 互相污染、提交会顺带带上别人的改动、合并必须等所有 worker 停下。
|
|
6
|
+
* 这里给每个任务创建独立 `git worktree`,让"改代码 / 跑验证 / 提交"都发生在
|
|
7
|
+
* 任务自己的目录里,主工作区可以继续保持用户当前分支不动。
|
|
8
|
+
*
|
|
9
|
+
* 约束:
|
|
10
|
+
* - 只处理 Git 仓库;非 Git、空仓库、仓库不在工作区根下时明确返回失败,由上层退回共享工作区。
|
|
11
|
+
* - 工作树里没有 node_modules / .venv,默认用 junction/symlink 指回源仓库,避免验证命令因缺依赖失败。
|
|
12
|
+
* - 工作树与分支默认保留,便于人工排查;只有确认已合并或明确要求时才删除。
|
|
13
|
+
*/
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
import crypto from "node:crypto";
|
|
17
|
+
import { execFile } from "node:child_process";
|
|
18
|
+
import { promisify } from "node:util";
|
|
19
|
+
import { statePath } from "./store.js";
|
|
20
|
+
|
|
21
|
+
const execFileAsync = promisify(execFile);
|
|
22
|
+
|
|
23
|
+
const MARKER = ".autofix-worktree.json";
|
|
24
|
+
const DEFAULT_LINK_DIRS = ["node_modules", ".venv", "venv", "vendor"];
|
|
25
|
+
const DEFAULT_COPY_FILES = [".env", ".env.local", ".env.development", ".env.production"];
|
|
26
|
+
|
|
27
|
+
async function git(cwd, args, { timeout = 60000 } = {}) {
|
|
28
|
+
try {
|
|
29
|
+
const { stdout, stderr } = await execFileAsync("git", ["-C", cwd, ...args], {
|
|
30
|
+
timeout,
|
|
31
|
+
windowsHide: true,
|
|
32
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
33
|
+
env: {
|
|
34
|
+
...process.env,
|
|
35
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
36
|
+
GIT_EDITOR: "true",
|
|
37
|
+
GIT_MERGE_AUTOEDIT: "no",
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
return { ok: true, stdout: String(stdout || ""), stderr: String(stderr || "") };
|
|
41
|
+
} catch (e) {
|
|
42
|
+
return {
|
|
43
|
+
ok: false,
|
|
44
|
+
code: typeof e?.code === "number" ? e.code : null,
|
|
45
|
+
stdout: String(e?.stdout || ""),
|
|
46
|
+
stderr: String(e?.stderr || e?.message || ""),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function worktreeRoot() {
|
|
52
|
+
return statePath("worktrees");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function shortHash(value) {
|
|
56
|
+
return crypto.createHash("sha1").update(String(value)).digest("hex").slice(0, 10);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 路径转成可安全用于目录名 / 分支名的片段。 */
|
|
60
|
+
export function safeSegment(value) {
|
|
61
|
+
const text = String(value || "")
|
|
62
|
+
.replace(/[^A-Za-z0-9._-]+/g, "-")
|
|
63
|
+
.replace(/^-+|-+$/g, "")
|
|
64
|
+
.slice(0, 60);
|
|
65
|
+
return text || "task";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 每个任务的分支名;多仓库时附上仓库名,避免同一仓库里多个任务撞分支。 */
|
|
69
|
+
export function taskBranchName(taskId, repoName = null) {
|
|
70
|
+
const base = `autofix/${safeSegment(taskId)}`;
|
|
71
|
+
return repoName ? `${base}-${safeSegment(repoName)}` : base;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 是否应该尝试工作树隔离。
|
|
76
|
+
*
|
|
77
|
+
* 未显式关闭、且工作区看起来是 Git 仓库时启用。
|
|
78
|
+
* 真正的可用性仍由 createTaskWorktree 判断,失败会回退共享工作区。
|
|
79
|
+
*/
|
|
80
|
+
export function isWorktreeEnabled(workspace = {}) {
|
|
81
|
+
if (workspace?.isolateWorktrees === false) return false;
|
|
82
|
+
return workspace?.isolateWorktrees === true || workspace?.isRepo === true || workspace?.multiRepo === true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function isInside(child, parent) {
|
|
86
|
+
const c = path.resolve(child).toLowerCase();
|
|
87
|
+
const p = path.resolve(parent).toLowerCase();
|
|
88
|
+
return c === p || c.startsWith(p.endsWith(path.sep) ? p : p + path.sep);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function repoRelPath(repo) {
|
|
92
|
+
return String(repo?.relPath ?? repo?.name ?? "").replace(/\\/g, "/").replace(/^\.\//, "");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 规划任务工作树里要放哪些仓库。
|
|
97
|
+
* 单仓库:工作区根就是一个仓库。
|
|
98
|
+
* 多仓库:只支持所有仓库都在工作区根目录之下,且没有 "." 根仓库;
|
|
99
|
+
* 这样任务目录能镜像原来的多仓库结构,worker 的相对路径保持不变。
|
|
100
|
+
*/
|
|
101
|
+
export function planTaskRepos(workspace = {}) {
|
|
102
|
+
const repos = (Array.isArray(workspace.repos) ? workspace.repos : []).filter(r => r && r.enabled !== false);
|
|
103
|
+
if (!repos.length) {
|
|
104
|
+
return {
|
|
105
|
+
kind: "single",
|
|
106
|
+
repos: [{
|
|
107
|
+
name: path.basename(path.resolve(workspace.path || ".")) || "workspace",
|
|
108
|
+
relPath: ".",
|
|
109
|
+
source: path.resolve(workspace.path || "."),
|
|
110
|
+
}],
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 多文件夹项目(前端 / 后端 / 移动端并列)以公共父目录为根,
|
|
115
|
+
// repos 的相对路径也按这个根计算,任务工作树才能镜像原结构。
|
|
116
|
+
const root = path.resolve(workspace.rootPath || workspace.path || ".");
|
|
117
|
+
const normalized = repos.map(repo => ({
|
|
118
|
+
name: String(repo.name || path.basename(repo.path || "")).trim() || "repo",
|
|
119
|
+
relPath: repoRelPath(repo),
|
|
120
|
+
source: path.resolve(repo.path || path.join(root, repoRelPath(repo))),
|
|
121
|
+
role: repo.role || "other",
|
|
122
|
+
branch: repo.branch || null,
|
|
123
|
+
testBranch: repo.testBranch || null,
|
|
124
|
+
verify: Array.isArray(repo.verify) ? repo.verify : [],
|
|
125
|
+
push: repo.push ?? null,
|
|
126
|
+
enabled: repo.enabled !== false,
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
// 只映射了一个文件夹时,公共父目录就是该文件夹本身(relPath=".")。
|
|
130
|
+
// 这时等价于单仓库:工作树根就是仓库根,不需要镜像多仓库结构。
|
|
131
|
+
if (normalized.length === 1 && (!normalized[0].relPath || normalized[0].relPath === ".")) {
|
|
132
|
+
return { kind: "single", repos: normalized };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const invalid = normalized.find(r => {
|
|
136
|
+
const rel = r.relPath;
|
|
137
|
+
return !rel || rel === "." || rel.startsWith("../") || path.isAbsolute(rel) || !isInside(r.source, root);
|
|
138
|
+
});
|
|
139
|
+
if (invalid) {
|
|
140
|
+
return {
|
|
141
|
+
kind: "unsupported",
|
|
142
|
+
reason: "repos_not_under_root",
|
|
143
|
+
message: `仓库 ${invalid.name} 不在工作区根目录下,无法用单棵任务工作树隔离`,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return { kind: "multi", repos: normalized };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** 校验任务记录里的工作树是否仍然可用。 */
|
|
151
|
+
export function taskWorktreeValid(record) {
|
|
152
|
+
if (!record?.path || !Array.isArray(record.repos) || !record.repos.length) return false;
|
|
153
|
+
if (!fs.existsSync(record.path)) return false;
|
|
154
|
+
if (record.workdir && !fs.existsSync(record.workdir)) return false;
|
|
155
|
+
return record.repos.every(r => r?.path && fs.existsSync(r.path));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function readMarker(dir) {
|
|
159
|
+
// marker 放在工作树目录旁边而不是里面:单仓库工作树的根就是仓库检出目录,
|
|
160
|
+
// 放进去会变成未跟踪文件,让 git status 永远是脏的,合并会一直被跳过。
|
|
161
|
+
// 兼容旧版本放在目录内的 marker。
|
|
162
|
+
for (const file of [`${dir}.json`, path.join(dir, MARKER)]) {
|
|
163
|
+
try {
|
|
164
|
+
if (!fs.existsSync(file)) continue;
|
|
165
|
+
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
166
|
+
if (taskWorktreeValid(parsed)) return parsed;
|
|
167
|
+
} catch { /* 换下一个位置 */ }
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function linkDependencies(source, target, extra = []) {
|
|
173
|
+
const names = [...new Set([...DEFAULT_LINK_DIRS, ...(Array.isArray(extra) ? extra : [])])];
|
|
174
|
+
for (const name of names) {
|
|
175
|
+
const from = path.join(source, name);
|
|
176
|
+
const to = path.join(target, name);
|
|
177
|
+
try {
|
|
178
|
+
if (!fs.existsSync(from) || fs.existsSync(to)) continue;
|
|
179
|
+
const stat = fs.lstatSync(from);
|
|
180
|
+
if (!stat.isDirectory()) continue;
|
|
181
|
+
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
182
|
+
// Windows 用 junction,普通用户无需管理员权限
|
|
183
|
+
fs.symlinkSync(from, to, process.platform === "win32" ? "junction" : "dir");
|
|
184
|
+
} catch {
|
|
185
|
+
// 链接失败不阻断修复:验证时缺依赖会由验证结果/复核兜底
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function copyConfigFiles(source, target, extra = []) {
|
|
191
|
+
const names = [...new Set([...DEFAULT_COPY_FILES, ...(Array.isArray(extra) ? extra : [])])];
|
|
192
|
+
for (const name of names) {
|
|
193
|
+
const from = path.join(source, name);
|
|
194
|
+
const to = path.join(target, name);
|
|
195
|
+
try {
|
|
196
|
+
if (!fs.existsSync(from) || fs.existsSync(to)) continue;
|
|
197
|
+
if (!fs.statSync(from).isFile()) continue;
|
|
198
|
+
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
199
|
+
fs.copyFileSync(from, to);
|
|
200
|
+
} catch {
|
|
201
|
+
// 配置文件复制失败同样不阻断,worker 会在报告里说明
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async function resolveBase(repoRoot, wanted) {
|
|
207
|
+
if (wanted) {
|
|
208
|
+
const ref = await git(repoRoot, ["rev-parse", "--verify", `refs/heads/${wanted}`]);
|
|
209
|
+
if (ref.ok) return wanted;
|
|
210
|
+
}
|
|
211
|
+
const head = await git(repoRoot, ["rev-parse", "HEAD"]);
|
|
212
|
+
if (head.ok && head.stdout.trim()) return head.stdout.trim();
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async function branchExists(repoRoot, branch) {
|
|
217
|
+
const r = await git(repoRoot, ["rev-parse", "--verify", `refs/heads/${branch}`]);
|
|
218
|
+
return r.ok;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 为任务创建隔离工作树。
|
|
223
|
+
*
|
|
224
|
+
* @returns {Promise<{ok:boolean, reason?:string, message?:string, taskId?:string, path?:string,
|
|
225
|
+
* repos?:Array, branch?:string, createdAt?:string}>}
|
|
226
|
+
*/
|
|
227
|
+
export async function createTaskWorktree({
|
|
228
|
+
workspace = {}, taskId, linkDirs = null, copyFiles = null,
|
|
229
|
+
} = {}) {
|
|
230
|
+
if (!taskId) return { ok: false, reason: "missing_task", message: "缺少任务编号" };
|
|
231
|
+
const plan = planTaskRepos(workspace);
|
|
232
|
+
if (plan.kind === "unsupported") {
|
|
233
|
+
return { ok: false, reason: plan.reason, message: plan.message };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const root = path.join(
|
|
237
|
+
worktreeRoot(),
|
|
238
|
+
shortHash(path.resolve(workspace.path || ".")),
|
|
239
|
+
`${safeSegment(taskId)}-${shortHash(taskId)}`,
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
// 服务重启或重试时直接复用已有的工作树,保留上次未完成的修改
|
|
243
|
+
const reused = readMarker(root);
|
|
244
|
+
if (reused) return { ok: true, ...reused, reused: true };
|
|
245
|
+
|
|
246
|
+
const created = [];
|
|
247
|
+
try {
|
|
248
|
+
fs.mkdirSync(root, { recursive: true });
|
|
249
|
+
|
|
250
|
+
// 多仓库的公共根也可能放了 node_modules / .env(monorepo 根依赖),
|
|
251
|
+
// 带进任务目录后子仓库向上查找依赖才不会因缺包导致验证误失败。
|
|
252
|
+
if (plan.kind === "multi") {
|
|
253
|
+
const wsRoot = path.resolve(workspace.path || ".");
|
|
254
|
+
linkDependencies(wsRoot, root, linkDirs);
|
|
255
|
+
copyConfigFiles(wsRoot, root, copyFiles);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
for (const item of plan.repos) {
|
|
259
|
+
const top = await git(item.source, ["rev-parse", "--show-toplevel"]);
|
|
260
|
+
if (!top.ok || !top.stdout.trim()) {
|
|
261
|
+
throw new Error(`${item.name} 不是 Git 仓库(或还没有提交),无法创建隔离工作树`);
|
|
262
|
+
}
|
|
263
|
+
const repoRoot = top.stdout.trim();
|
|
264
|
+
const base = await resolveBase(repoRoot, item.branch);
|
|
265
|
+
if (!base) throw new Error(`${item.name} 还没有任何提交,无法创建隔离工作树`);
|
|
266
|
+
|
|
267
|
+
const target = plan.kind === "single" ? root : path.join(root, item.relPath);
|
|
268
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
269
|
+
const branch = taskBranchName(taskId, plan.kind === "multi" ? item.name : null);
|
|
270
|
+
|
|
271
|
+
let add;
|
|
272
|
+
if (await branchExists(repoRoot, branch)) {
|
|
273
|
+
// 复用旧分支:先清理指向已不存在目录的 worktree 注册
|
|
274
|
+
await git(repoRoot, ["worktree", "prune"]);
|
|
275
|
+
add = await git(repoRoot, ["worktree", "add", target, branch]);
|
|
276
|
+
} else {
|
|
277
|
+
add = await git(repoRoot, ["worktree", "add", "-b", branch, target, base]);
|
|
278
|
+
}
|
|
279
|
+
if (!add.ok) {
|
|
280
|
+
throw new Error(`${item.name} 创建工作树失败:${(add.stderr || add.stdout).trim().slice(-400)}`);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// 单仓库可能从仓库子目录启动:工作树检出的是整个仓库,
|
|
284
|
+
// worker 仍应回到原来的子目录,避免把仓库根当成工作区、改到工作区之外。
|
|
285
|
+
const sub = plan.kind === "single" ? path.relative(repoRoot, item.source) : "";
|
|
286
|
+
const workdir = sub && sub !== "." ? path.join(target, sub) : target;
|
|
287
|
+
fs.mkdirSync(workdir, { recursive: true });
|
|
288
|
+
|
|
289
|
+
linkDependencies(repoRoot, target, linkDirs);
|
|
290
|
+
if (workdir !== target) linkDependencies(item.source, workdir, linkDirs);
|
|
291
|
+
copyConfigFiles(repoRoot, target, copyFiles);
|
|
292
|
+
if (workdir !== target) copyConfigFiles(item.source, workdir, copyFiles);
|
|
293
|
+
created.push({
|
|
294
|
+
name: item.name,
|
|
295
|
+
relPath: plan.kind === "single" ? "." : item.relPath,
|
|
296
|
+
role: item.role,
|
|
297
|
+
branch: item.branch,
|
|
298
|
+
testBranch: item.testBranch,
|
|
299
|
+
verify: item.verify,
|
|
300
|
+
push: item.push,
|
|
301
|
+
enabled: item.enabled,
|
|
302
|
+
source: repoRoot,
|
|
303
|
+
sourcePath: item.source,
|
|
304
|
+
path: target,
|
|
305
|
+
workdir,
|
|
306
|
+
taskBranch: branch,
|
|
307
|
+
base,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const record = {
|
|
312
|
+
taskId,
|
|
313
|
+
createdAt: new Date().toISOString(),
|
|
314
|
+
path: root,
|
|
315
|
+
// 任务实际执行目录:单仓库可能是仓库里的某个子目录;多仓库统一是工作树根
|
|
316
|
+
workdir: plan.kind === "single" ? (created[0]?.workdir || root) : root,
|
|
317
|
+
branch: created[0]?.taskBranch || null,
|
|
318
|
+
repos: created,
|
|
319
|
+
};
|
|
320
|
+
fs.writeFileSync(`${root}.json`, JSON.stringify(record, null, 2));
|
|
321
|
+
return { ok: true, ...record };
|
|
322
|
+
} catch (e) {
|
|
323
|
+
// 回滚已经创建的部分,避免留下半棵工作树
|
|
324
|
+
for (const item of created.reverse()) {
|
|
325
|
+
await git(item.source, ["worktree", "remove", "--force", item.path]);
|
|
326
|
+
}
|
|
327
|
+
try { fs.rmSync(root, { recursive: true, force: true }); } catch { /* 忽略 */ }
|
|
328
|
+
try { fs.rmSync(`${root}.json`, { force: true }); } catch { /* 忽略 */ }
|
|
329
|
+
return { ok: false, reason: "worktree_failed", message: String(e?.message || e) };
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* 删除任务工作树。
|
|
335
|
+
* 默认保留分支,便于人工查看这次修复到底改了什么;deleteBranches 时才清理。
|
|
336
|
+
*/
|
|
337
|
+
export async function removeTaskWorktree(record, { deleteBranches = false } = {}) {
|
|
338
|
+
if (!record?.repos?.length) return { ok: true, removed: false };
|
|
339
|
+
const results = [];
|
|
340
|
+
for (const item of record.repos) {
|
|
341
|
+
const removed = await git(item.source, ["worktree", "remove", "--force", item.path]);
|
|
342
|
+
results.push({ name: item.name, ok: removed.ok, path: item.path });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// worktree remove 失败(目录被占用/已手动删除)时直接删目录,再 prune 注册
|
|
346
|
+
try { fs.rmSync(record.path, { recursive: true, force: true }); } catch { /* 忽略 */ }
|
|
347
|
+
try { fs.rmSync(`${record.path}.json`, { force: true }); } catch { /* 忽略 */ }
|
|
348
|
+
for (const item of record.repos) {
|
|
349
|
+
await git(item.source, ["worktree", "prune"]);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (deleteBranches) {
|
|
353
|
+
for (const item of record.repos) {
|
|
354
|
+
await git(item.source, ["branch", "-D", item.taskBranch]);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return { ok: true, removed: true, results };
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** 把工作树记录转成 commit / verify 需要的仓库声明(path 指向任务实际执行目录)。 */
|
|
362
|
+
export function worktreeRepos(record) {
|
|
363
|
+
if (!record?.repos?.length) return [];
|
|
364
|
+
return record.repos.map(item => ({
|
|
365
|
+
name: item.name,
|
|
366
|
+
relPath: item.relPath,
|
|
367
|
+
role: item.role,
|
|
368
|
+
branch: item.branch,
|
|
369
|
+
testBranch: item.testBranch,
|
|
370
|
+
verify: item.verify,
|
|
371
|
+
push: item.push,
|
|
372
|
+
enabled: item.enabled,
|
|
373
|
+
// path 是任务实际执行目录:单仓库可能是仓库里的子目录,多仓库则是镜像目录
|
|
374
|
+
path: item.workdir || item.path,
|
|
375
|
+
sourcePath: item.sourcePath || item.source,
|
|
376
|
+
taskBranch: item.taskBranch,
|
|
377
|
+
}));
|
|
378
|
+
}
|
|
379
|
+
|