ralph-cursor 0.1.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 +724 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +60 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +69 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +162 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/logs.d.ts +3 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +28 -0
- package/dist/commands/logs.js.map +1 -0
- package/dist/commands/loop.d.ts +3 -0
- package/dist/commands/loop.d.ts.map +1 -0
- package/dist/commands/loop.js +186 -0
- package/dist/commands/loop.js.map +1 -0
- package/dist/commands/once.d.ts +3 -0
- package/dist/commands/once.d.ts.map +1 -0
- package/dist/commands/once.js +187 -0
- package/dist/commands/once.js.map +1 -0
- package/dist/commands/run.d.ts +3 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +328 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/status.d.ts +3 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +33 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/task.d.ts +3 -0
- package/dist/commands/task.d.ts.map +1 -0
- package/dist/commands/task.js +161 -0
- package/dist/commands/task.js.map +1 -0
- package/dist/lib/config.d.ts +8 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +48 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/last-run.d.ts +12 -0
- package/dist/lib/last-run.d.ts.map +1 -0
- package/dist/lib/last-run.js +33 -0
- package/dist/lib/last-run.js.map +1 -0
- package/dist/lib/ralph-dir.d.ts +6 -0
- package/dist/lib/ralph-dir.d.ts.map +1 -0
- package/dist/lib/ralph-dir.js +96 -0
- package/dist/lib/ralph-dir.js.map +1 -0
- package/dist/lib/spawn.d.ts +11 -0
- package/dist/lib/spawn.d.ts.map +1 -0
- package/dist/lib/spawn.js +29 -0
- package/dist/lib/spawn.js.map +1 -0
- package/dist/lib/tail.d.ts +9 -0
- package/dist/lib/tail.d.ts.map +1 -0
- package/dist/lib/tail.js +58 -0
- package/dist/lib/tail.js.map +1 -0
- package/dist/loop/index.d.ts +32 -0
- package/dist/loop/index.d.ts.map +1 -0
- package/dist/loop/index.js +165 -0
- package/dist/loop/index.js.map +1 -0
- package/dist/loop/prompt.d.ts +5 -0
- package/dist/loop/prompt.d.ts.map +1 -0
- package/dist/loop/prompt.js +77 -0
- package/dist/loop/prompt.js.map +1 -0
- package/dist/loop/retry.d.ts +22 -0
- package/dist/loop/retry.d.ts.map +1 -0
- package/dist/loop/retry.js +65 -0
- package/dist/loop/retry.js.map +1 -0
- package/dist/parallel/lock.d.ts +7 -0
- package/dist/parallel/lock.d.ts.map +1 -0
- package/dist/parallel/lock.js +110 -0
- package/dist/parallel/lock.js.map +1 -0
- package/dist/parallel/merge.d.ts +5 -0
- package/dist/parallel/merge.d.ts.map +1 -0
- package/dist/parallel/merge.js +39 -0
- package/dist/parallel/merge.js.map +1 -0
- package/dist/parallel/run.d.ts +18 -0
- package/dist/parallel/run.d.ts.map +1 -0
- package/dist/parallel/run.js +407 -0
- package/dist/parallel/run.js.map +1 -0
- package/dist/parallel/worktree.d.ts +12 -0
- package/dist/parallel/worktree.d.ts.map +1 -0
- package/dist/parallel/worktree.js +69 -0
- package/dist/parallel/worktree.js.map +1 -0
- package/dist/stream-parser/index.d.ts +18 -0
- package/dist/stream-parser/index.d.ts.map +1 -0
- package/dist/stream-parser/index.js +248 -0
- package/dist/stream-parser/index.js.map +1 -0
- package/dist/task-parser/index.d.ts +21 -0
- package/dist/task-parser/index.d.ts.map +1 -0
- package/dist/task-parser/index.js +195 -0
- package/dist/task-parser/index.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import { spawn, execSync } from "child_process";
|
|
2
|
+
import { appendFileSync, copyFileSync, mkdirSync, writeFileSync, unlinkSync } from "fs";
|
|
3
|
+
import { join, relative } from "path";
|
|
4
|
+
import { tmpdir } from "os";
|
|
5
|
+
import { getTaskFilePath } from "../task-parser/index.js";
|
|
6
|
+
import { getPendingGroups, getTasksByGroup, markTaskComplete, parseTasks, } from "../task-parser/index.js";
|
|
7
|
+
import { acquireParallelLock } from "./lock.js";
|
|
8
|
+
import { createAgentWorktree, cleanupAgentWorktree, deleteLocalBranch, generateRunId, getWorktreeBase, canUseWorktrees, } from "./worktree.js";
|
|
9
|
+
import { mergeAgentBranch, abortMerge } from "./merge.js";
|
|
10
|
+
const PARALLEL_STATE_DIR = ".ralph/parallel";
|
|
11
|
+
function getRunDir(workspace, runId) {
|
|
12
|
+
const runDir = join(workspace, PARALLEL_STATE_DIR, runId);
|
|
13
|
+
mkdirSync(runDir, { recursive: true });
|
|
14
|
+
return runDir;
|
|
15
|
+
}
|
|
16
|
+
function buildAgentPrompt(taskDesc, displayNum, jobId, reportRel) {
|
|
17
|
+
return `# Parallel Agent Task
|
|
18
|
+
|
|
19
|
+
You are Agent ${displayNum} (job: ${jobId}) working on a specific task in isolation.
|
|
20
|
+
|
|
21
|
+
## Your Task
|
|
22
|
+
${taskDesc}
|
|
23
|
+
|
|
24
|
+
## Instructions
|
|
25
|
+
1. Implement this specific task completely
|
|
26
|
+
2. Write tests if appropriate
|
|
27
|
+
3. Do NOT touch .ralph/progress.md in parallel mode (it causes merge conflicts)
|
|
28
|
+
4. Write a short report to: ${reportRel}
|
|
29
|
+
- What you changed
|
|
30
|
+
- Files touched
|
|
31
|
+
- How to run tests
|
|
32
|
+
- Any gotchas
|
|
33
|
+
5. Commit your changes (including the report) with a message like: ralph: [task summary]
|
|
34
|
+
|
|
35
|
+
## Important
|
|
36
|
+
- You are in an isolated worktree - your changes will not affect other agents
|
|
37
|
+
- Focus ONLY on your assigned task
|
|
38
|
+
- Do NOT modify RALPH_TASK.md - that will be handled by the orchestrator
|
|
39
|
+
- Commit frequently so your work is saved
|
|
40
|
+
|
|
41
|
+
## Conflict Prevention (CRITICAL)
|
|
42
|
+
Do NOT modify these files unless your task EXPLICITLY requires it:
|
|
43
|
+
- README.md, CHANGELOG.md, CONTRIBUTING.md
|
|
44
|
+
- package.json, package-lock.json, pnpm-lock.yaml, yarn.lock
|
|
45
|
+
- pyproject.toml, setup.py, requirements.txt, poetry.lock
|
|
46
|
+
- Cargo.toml, Cargo.lock, go.mod, go.sum
|
|
47
|
+
- .env.example, .gitignore, Makefile, Dockerfile
|
|
48
|
+
|
|
49
|
+
These are common merge conflict hotspots. If your task does not specifically
|
|
50
|
+
mention updating one of these files, leave them alone.
|
|
51
|
+
|
|
52
|
+
Begin by reading any relevant files, then implement the task.`;
|
|
53
|
+
}
|
|
54
|
+
function runAgentInWorktree(workspace, worktreeDir, taskId, taskDesc, jobId, displayNum, runId, baseSha, model, runDir, logPath) {
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
const reportRel = `.ralph/parallel/${runId}/agent-${jobId}.md`;
|
|
57
|
+
const prompt = buildAgentPrompt(taskDesc, displayNum, jobId, reportRel);
|
|
58
|
+
mkdirSync(join(worktreeDir, ".ralph", "parallel", runId), { recursive: true });
|
|
59
|
+
const ts = new Date().toLocaleTimeString("en-GB", { hour12: false });
|
|
60
|
+
appendFileSync(logPath, `[${ts}] Agent ${displayNum} (job ${jobId}, task ${taskId}) starting: ${taskDesc}\n`);
|
|
61
|
+
const args = [
|
|
62
|
+
"-p",
|
|
63
|
+
"--approve-mcps",
|
|
64
|
+
"--force",
|
|
65
|
+
"--output-format",
|
|
66
|
+
"stream-json",
|
|
67
|
+
"--model",
|
|
68
|
+
model,
|
|
69
|
+
prompt,
|
|
70
|
+
];
|
|
71
|
+
const child = spawn("cursor-agent", args, {
|
|
72
|
+
cwd: worktreeDir,
|
|
73
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
74
|
+
});
|
|
75
|
+
if (child.stdout)
|
|
76
|
+
child.stdout.on("data", (chunk) => appendFileSync(logPath, chunk));
|
|
77
|
+
if (child.stderr)
|
|
78
|
+
child.stderr.on("data", (chunk) => appendFileSync(logPath, chunk));
|
|
79
|
+
if (child.stdin) {
|
|
80
|
+
child.stdin.end();
|
|
81
|
+
}
|
|
82
|
+
child.on("close", (code) => {
|
|
83
|
+
const ts2 = new Date().toLocaleTimeString("en-GB", { hour12: false });
|
|
84
|
+
appendFileSync(logPath, `[${ts2}] Agent ${displayNum} (job ${jobId}) finished\n`);
|
|
85
|
+
if (code === 0) {
|
|
86
|
+
try {
|
|
87
|
+
const countOut = execSync(`git rev-list --count HEAD ^"${baseSha}"`, {
|
|
88
|
+
cwd: worktreeDir,
|
|
89
|
+
encoding: "utf-8",
|
|
90
|
+
});
|
|
91
|
+
const count = parseInt(countOut.trim(), 10) || 0;
|
|
92
|
+
resolve({ status: "done", outputStatus: count > 0 ? "success" : "no_commits" });
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
resolve({ status: "done", outputStatus: "no_commits" });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
resolve({ status: "failed", outputStatus: "error" });
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export async function runParallelTasks(workspace, options) {
|
|
105
|
+
const { maxParallel = 3, model, baseBranch: baseBranchOpt, integrationBranch, skipMerge = false, createPr = false, taskFilePath, } = options;
|
|
106
|
+
const release = acquireParallelLock(workspace);
|
|
107
|
+
if (!release) {
|
|
108
|
+
return { success: false, mergedCount: 0 };
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const taskPath = getTaskFilePath(workspace, taskFilePath);
|
|
112
|
+
const taskRel = relative(workspace, taskPath);
|
|
113
|
+
try {
|
|
114
|
+
const statusOut = execSync(`git status --porcelain -- "${taskRel}"`, {
|
|
115
|
+
cwd: workspace,
|
|
116
|
+
encoding: "utf-8",
|
|
117
|
+
}).trim();
|
|
118
|
+
if (statusOut.startsWith("??")) {
|
|
119
|
+
console.error("");
|
|
120
|
+
console.error("❌ RALPH_TASK.md is untracked (not committed to git).");
|
|
121
|
+
console.error("");
|
|
122
|
+
console.error(" Parallel mode requires RALPH_TASK.md to be committed so merges and reruns are deterministic.");
|
|
123
|
+
console.error("");
|
|
124
|
+
console.error(" To fix, run:");
|
|
125
|
+
console.error("");
|
|
126
|
+
console.error(" git add RALPH_TASK.md");
|
|
127
|
+
console.error(" git commit -m \"chore: init ralph task file\"");
|
|
128
|
+
console.error("");
|
|
129
|
+
return { success: false, mergedCount: 0 };
|
|
130
|
+
}
|
|
131
|
+
if (statusOut && (statusOut.startsWith(" M") || statusOut.startsWith("M ") || statusOut.startsWith("MM"))) {
|
|
132
|
+
console.error("");
|
|
133
|
+
console.error("⚠️ RALPH_TASK.md has uncommitted changes.");
|
|
134
|
+
console.error(" Worktrees will use the last committed version, not your local edits.");
|
|
135
|
+
console.error(" Consider committing first: git add RALPH_TASK.md && git commit -m \"update tasks\"");
|
|
136
|
+
console.error("");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// no git or path not in repo
|
|
141
|
+
}
|
|
142
|
+
let baseBranch = baseBranchOpt;
|
|
143
|
+
if (!baseBranch) {
|
|
144
|
+
baseBranch = execSync("git rev-parse --abbrev-ref HEAD", {
|
|
145
|
+
cwd: workspace,
|
|
146
|
+
encoding: "utf-8",
|
|
147
|
+
}).trim();
|
|
148
|
+
}
|
|
149
|
+
const baseSha = execSync(`git rev-parse "${baseBranch}"`, {
|
|
150
|
+
cwd: workspace,
|
|
151
|
+
encoding: "utf-8",
|
|
152
|
+
}).trim();
|
|
153
|
+
if (!canUseWorktrees(workspace)) {
|
|
154
|
+
console.error("❌ Cannot use worktrees (already in a worktree or no .git directory)");
|
|
155
|
+
return { success: false, mergedCount: 0 };
|
|
156
|
+
}
|
|
157
|
+
const runId = generateRunId();
|
|
158
|
+
const runDir = getRunDir(workspace, runId);
|
|
159
|
+
const worktreeBase = getWorktreeBase(workspace);
|
|
160
|
+
let mergeTarget = integrationBranch ?? baseBranch;
|
|
161
|
+
if (createPr && !integrationBranch) {
|
|
162
|
+
mergeTarget = `ralph/parallel-${runId}`;
|
|
163
|
+
}
|
|
164
|
+
console.log("");
|
|
165
|
+
console.log("═══════════════════════════════════════════════════════════════════");
|
|
166
|
+
console.log("🚀 Parallel Execution: Up to", maxParallel, "agents");
|
|
167
|
+
console.log("═══════════════════════════════════════════════════════════════════");
|
|
168
|
+
console.log("");
|
|
169
|
+
console.log("Base branch: ", baseBranch);
|
|
170
|
+
console.log("Base SHA: ", baseSha);
|
|
171
|
+
console.log("Worktree base: ", worktreeBase);
|
|
172
|
+
console.log("Run state dir: ", runDir);
|
|
173
|
+
console.log("");
|
|
174
|
+
if (mergeTarget !== baseBranch) {
|
|
175
|
+
execSync(`git checkout -B "${mergeTarget}" "${baseSha}"`, {
|
|
176
|
+
cwd: workspace,
|
|
177
|
+
stdio: "pipe",
|
|
178
|
+
});
|
|
179
|
+
console.log("🔀 Integration branch:", mergeTarget, "(from", baseBranch + ")");
|
|
180
|
+
console.log("");
|
|
181
|
+
}
|
|
182
|
+
const groups = getPendingGroups(workspace, taskFilePath);
|
|
183
|
+
if (groups.length === 0) {
|
|
184
|
+
console.log("✅ No pending tasks!");
|
|
185
|
+
return { success: true, mergedCount: 0 };
|
|
186
|
+
}
|
|
187
|
+
const groupsDisplay = groups.map((g) => (g === 999999 ? "unannotated" : String(g))).join(" ");
|
|
188
|
+
console.log("📋 Found", groups.length, "group(s) to process:", groupsDisplay);
|
|
189
|
+
console.log("");
|
|
190
|
+
let totalMerged = 0;
|
|
191
|
+
let totalSucceeded = 0;
|
|
192
|
+
let totalFailed = 0;
|
|
193
|
+
let globalJobNum = 0;
|
|
194
|
+
for (const currentGroup of groups) {
|
|
195
|
+
parseTasks(workspace, taskFilePath);
|
|
196
|
+
const tasks = getTasksByGroup(workspace, currentGroup, taskFilePath);
|
|
197
|
+
if (tasks.length === 0)
|
|
198
|
+
continue;
|
|
199
|
+
const groupLabel = currentGroup === 999999 ? "unannotated (999999)" : String(currentGroup);
|
|
200
|
+
console.log("");
|
|
201
|
+
console.log("═══════════════════════════════════════════════════════════════════");
|
|
202
|
+
console.log("📦 Group", groupLabel + ":", tasks.length, "task(s)");
|
|
203
|
+
console.log("═══════════════════════════════════════════════════════════════════");
|
|
204
|
+
console.log("");
|
|
205
|
+
let taskIdx = 0;
|
|
206
|
+
const successfulItems = [];
|
|
207
|
+
while (taskIdx < tasks.length) {
|
|
208
|
+
const batchEnd = Math.min(taskIdx + maxParallel, tasks.length);
|
|
209
|
+
const batch = tasks.slice(taskIdx, batchEnd);
|
|
210
|
+
const batchNum = Math.floor(taskIdx / maxParallel) + 1;
|
|
211
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
212
|
+
console.log("📦 Batch", batchNum + ": Spawning", batch.length, "parallel agent(s)");
|
|
213
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
214
|
+
console.log("");
|
|
215
|
+
const results = [];
|
|
216
|
+
const promises = batch.map((t, i) => {
|
|
217
|
+
globalJobNum++;
|
|
218
|
+
const jobId = `job${globalJobNum}`;
|
|
219
|
+
const batchSlot = i + 1;
|
|
220
|
+
const [worktreeDir, branchName] = createAgentWorktree(workspace, runId, baseSha, t.id, t.description, jobId);
|
|
221
|
+
try {
|
|
222
|
+
copyFileSync(taskPath, join(worktreeDir, "RALPH_TASK.md"));
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
// ignore if copy fails (e.g. custom task path)
|
|
226
|
+
}
|
|
227
|
+
const logPath = join(runDir, `${jobId}.log`);
|
|
228
|
+
writeFileSync(logPath, "");
|
|
229
|
+
console.log(" 🔄 Agent", batchSlot + "/" + batch.length, `(job ${jobId}, task ${t.id}):`, t.description.slice(0, 50) + "...");
|
|
230
|
+
return runAgentInWorktree(workspace, worktreeDir, t.id, t.description, jobId, batchSlot, runId, baseSha, model, runDir, logPath).then((result) => {
|
|
231
|
+
results.push({
|
|
232
|
+
worktreeDir,
|
|
233
|
+
branchName,
|
|
234
|
+
taskId: t.id,
|
|
235
|
+
taskDesc: t.description,
|
|
236
|
+
jobId,
|
|
237
|
+
batchSlot,
|
|
238
|
+
result,
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
await Promise.all(promises);
|
|
243
|
+
console.log("");
|
|
244
|
+
for (const r of results) {
|
|
245
|
+
const { status, outputStatus } = r.result;
|
|
246
|
+
let icon = "❓";
|
|
247
|
+
if (status === "done" && outputStatus === "success") {
|
|
248
|
+
icon = "✅";
|
|
249
|
+
totalSucceeded++;
|
|
250
|
+
}
|
|
251
|
+
else if (status === "done") {
|
|
252
|
+
icon = "⚠️ ";
|
|
253
|
+
totalFailed++;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
icon = "❌";
|
|
257
|
+
totalFailed++;
|
|
258
|
+
}
|
|
259
|
+
console.log(" ", icon, "Agent", r.batchSlot, `(job ${r.jobId}):`, r.taskDesc.slice(0, 40), "→", r.branchName);
|
|
260
|
+
const worktreeLeft = cleanupAgentWorktree(workspace, r.worktreeDir, r.branchName);
|
|
261
|
+
if (worktreeLeft === "left_in_place") {
|
|
262
|
+
console.log(" ⚠️ Worktree preserved (uncommitted changes):", r.worktreeDir);
|
|
263
|
+
}
|
|
264
|
+
if (status === "done" && outputStatus === "success") {
|
|
265
|
+
successfulItems.push({ branchName: r.branchName, taskId: r.taskId, worktreeLeft });
|
|
266
|
+
}
|
|
267
|
+
else if (worktreeLeft !== "left_in_place" && (outputStatus === "no_commits" || outputStatus === "error")) {
|
|
268
|
+
deleteLocalBranch(workspace, r.branchName);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
taskIdx = batchEnd;
|
|
272
|
+
}
|
|
273
|
+
if (successfulItems.length > 0 && skipMerge && !createPr) {
|
|
274
|
+
console.log("");
|
|
275
|
+
console.log("📝 Group", groupLabel + ": Branches created (merge skipped):");
|
|
276
|
+
for (const item of successfulItems) {
|
|
277
|
+
console.log(" -", item.branchName);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else if (successfulItems.length > 0 && (!skipMerge || createPr)) {
|
|
281
|
+
console.log("");
|
|
282
|
+
console.log("───────────────────────────────────────────────────────────────────");
|
|
283
|
+
console.log("📦 Group", groupLabel + ": Merging", successfulItems.length, "branch(es) into", mergeTarget);
|
|
284
|
+
console.log("───────────────────────────────────────────────────────────────────");
|
|
285
|
+
const integratedTaskIds = [];
|
|
286
|
+
const failedBranches = [];
|
|
287
|
+
for (const item of successfulItems) {
|
|
288
|
+
process.stdout.write(` Merging ${item.branchName.padEnd(55)} `);
|
|
289
|
+
const result = mergeAgentBranch(workspace, item.branchName, mergeTarget);
|
|
290
|
+
if (result === "success") {
|
|
291
|
+
console.log("✅");
|
|
292
|
+
totalMerged++;
|
|
293
|
+
integratedTaskIds.push(item.taskId);
|
|
294
|
+
if (item.worktreeLeft !== "left_in_place") {
|
|
295
|
+
deleteLocalBranch(workspace, item.branchName);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
else if (result === "conflict") {
|
|
299
|
+
console.log("⚠️ (conflict)");
|
|
300
|
+
abortMerge(workspace);
|
|
301
|
+
failedBranches.push(item.branchName);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
console.log("❌");
|
|
305
|
+
failedBranches.push(item.branchName);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if (integratedTaskIds.length > 0) {
|
|
309
|
+
console.log("");
|
|
310
|
+
console.log("✅ Group", groupLabel + ": Integrated", integratedTaskIds.length, "task(s) into", mergeTarget);
|
|
311
|
+
}
|
|
312
|
+
if (failedBranches.length > 0) {
|
|
313
|
+
console.log("⚠️ Failed/conflicted branches preserved for manual review:");
|
|
314
|
+
for (const b of failedBranches) {
|
|
315
|
+
console.log(" -", b);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
for (const taskId of integratedTaskIds) {
|
|
319
|
+
markTaskComplete(workspace, taskId, taskFilePath);
|
|
320
|
+
}
|
|
321
|
+
if (integratedTaskIds.length > 0) {
|
|
322
|
+
try {
|
|
323
|
+
const status = execSync("git status --porcelain -- RALPH_TASK.md", {
|
|
324
|
+
cwd: workspace,
|
|
325
|
+
encoding: "utf-8",
|
|
326
|
+
});
|
|
327
|
+
if (status.trim()) {
|
|
328
|
+
execSync("git add RALPH_TASK.md", { cwd: workspace, stdio: "pipe" });
|
|
329
|
+
const mergedBranches = successfulItems
|
|
330
|
+
.filter((it) => integratedTaskIds.includes(it.taskId))
|
|
331
|
+
.map((it) => it.branchName);
|
|
332
|
+
const body = `Run: ${runId}
|
|
333
|
+
Group: ${groupLabel}
|
|
334
|
+
|
|
335
|
+
Merged branches:
|
|
336
|
+
${mergedBranches.map((b) => ` - ${b}`).join("\n")}
|
|
337
|
+
|
|
338
|
+
Tasks completed:
|
|
339
|
+
${integratedTaskIds.map((tid) => ` - ${tid}`).join("\n")}`;
|
|
340
|
+
const msg = `ralph: mark ${integratedTaskIds.length} task(s) complete (group ${groupLabel})\n\n${body}`;
|
|
341
|
+
const msgFile = join(tmpdir(), `ralph-commit-${runId}-${Date.now()}.txt`);
|
|
342
|
+
writeFileSync(msgFile, msg);
|
|
343
|
+
try {
|
|
344
|
+
execSync(`git -c user.name=ralph-parallel -c user.email=ralph-parallel@localhost commit -F "${msgFile}"`, { cwd: workspace, stdio: "pipe" });
|
|
345
|
+
}
|
|
346
|
+
finally {
|
|
347
|
+
try {
|
|
348
|
+
unlinkSync(msgFile);
|
|
349
|
+
}
|
|
350
|
+
catch {
|
|
351
|
+
// ignore
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
catch {
|
|
357
|
+
// ignore
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
parseTasks(workspace, taskFilePath);
|
|
361
|
+
const remainingInGroup = getTasksByGroup(workspace, currentGroup, taskFilePath).length;
|
|
362
|
+
if (remainingInGroup > 0) {
|
|
363
|
+
console.log("");
|
|
364
|
+
console.log("⚠️ Group", groupLabel, "still has", remainingInGroup, "pending task(s) after merge phase");
|
|
365
|
+
console.log(" (failed merges leave tasks incomplete - fix conflicts and re-run)");
|
|
366
|
+
}
|
|
367
|
+
console.log("");
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (createPr && mergeTarget !== baseBranch && totalMerged > 0) {
|
|
371
|
+
console.log("");
|
|
372
|
+
console.log("═══════════════════════════════════════════════════════════════════");
|
|
373
|
+
console.log("📝 Creating PR:", mergeTarget, "->", baseBranch);
|
|
374
|
+
console.log("═══════════════════════════════════════════════════════════════════");
|
|
375
|
+
try {
|
|
376
|
+
execSync("git remote get-url origin", { cwd: workspace, stdio: "pipe" });
|
|
377
|
+
execSync(`git push -u origin "${mergeTarget}"`, { cwd: workspace, stdio: "inherit" });
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
console.log("⚠️ No remote 'origin' or push failed. Push and create PR manually.");
|
|
381
|
+
}
|
|
382
|
+
try {
|
|
383
|
+
execSync(`gh pr create --base "${baseBranch}" --head "${mergeTarget}" --fill`, {
|
|
384
|
+
cwd: workspace,
|
|
385
|
+
stdio: "inherit",
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
catch {
|
|
389
|
+
console.log("⚠️ gh CLI not found or pr create failed. Create PR manually.");
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
console.log("");
|
|
393
|
+
console.log("═══════════════════════════════════════════════════════════════════");
|
|
394
|
+
console.log("📊 Parallel Execution Complete");
|
|
395
|
+
console.log("═══════════════════════════════════════════════════════════════════");
|
|
396
|
+
console.log(" Integrated:", totalMerged);
|
|
397
|
+
console.log(" Succeeded: ", totalSucceeded);
|
|
398
|
+
console.log(" Failed: ", totalFailed);
|
|
399
|
+
console.log(" Run dir: ", runDir);
|
|
400
|
+
console.log("");
|
|
401
|
+
return { success: true, mergedCount: totalMerged };
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
release();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/parallel/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AACxF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,UAAU,GACX,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE1D,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAE7C,SAAS,SAAS,CAAC,SAAiB,EAAE,KAAa;IACjD,MAAM,MAAM,GAAG,IAAI,CA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AAS,CAAC;QACT,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function getWorktreeBase(workspace: string): string;
|
|
2
|
+
/** .git must be a directory (not a file, i.e. not already a worktree). */
|
|
3
|
+
export declare function canUseWorktrees(workspace: string): boolean;
|
|
4
|
+
export declare function generateRunId(): string;
|
|
5
|
+
/**
|
|
6
|
+
* Create a worktree for an agent. Returns [worktreeDir, branchName].
|
|
7
|
+
*/
|
|
8
|
+
export declare function createAgentWorktree(workspace: string, runId: string, baseSha: string, taskId: string, taskDesc: string, jobId: string): [string, string];
|
|
9
|
+
/** Remove worktree. Returns "cleaned" or "left_in_place" if uncommitted changes. */
|
|
10
|
+
export declare function cleanupAgentWorktree(workspace: string, worktreeDir: string, branchName: string): "cleaned" | "left_in_place";
|
|
11
|
+
export declare function deleteLocalBranch(workspace: string, branch: string): void;
|
|
12
|
+
//# sourceMappingURL=worktree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worktree.d.ts","sourceRoot":"","sources":["../../src/parallel/worktree.ts"],"names":[],"mappings":"AAMA,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAIzD;AAED,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAG1D;AAUD,wBAAgB,aAAa,IAAI,MAAM,CAItC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACZ,CAAC,MAAM,EAAE,MAAM,CAAC,CAelB;AAED,oFAAoF;AACpF,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,SAAS,GAAG,eAAe,CAc7B;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAMzE"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
import { existsSync, rmSync, mkdirSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
const WORKTREE_BASE_DIR = ".ralph-worktrees";
|
|
5
|
+
export function getWorktreeBase(workspace) {
|
|
6
|
+
const base = join(workspace, WORKTREE_BASE_DIR);
|
|
7
|
+
mkdirSync(base, { recursive: true });
|
|
8
|
+
return base;
|
|
9
|
+
}
|
|
10
|
+
/** .git must be a directory (not a file, i.e. not already a worktree). */
|
|
11
|
+
export function canUseWorktrees(workspace) {
|
|
12
|
+
const gitPath = join(workspace, ".git");
|
|
13
|
+
return existsSync(gitPath) && existsSync(join(gitPath, "HEAD"));
|
|
14
|
+
}
|
|
15
|
+
function slugify(text) {
|
|
16
|
+
return text
|
|
17
|
+
.toLowerCase()
|
|
18
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
19
|
+
.replace(/^-|-$/g, "")
|
|
20
|
+
.slice(0, 40);
|
|
21
|
+
}
|
|
22
|
+
export function generateRunId() {
|
|
23
|
+
const t = Date.now().toString(36);
|
|
24
|
+
const r = Math.random().toString(36).slice(2, 6);
|
|
25
|
+
return `${t}-${r}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a worktree for an agent. Returns [worktreeDir, branchName].
|
|
29
|
+
*/
|
|
30
|
+
export function createAgentWorktree(workspace, runId, baseSha, taskId, taskDesc, jobId) {
|
|
31
|
+
const base = getWorktreeBase(workspace);
|
|
32
|
+
const branchName = `ralph/parallel-${runId}-${jobId}-${taskId}-${slugify(taskDesc)}`;
|
|
33
|
+
const worktreeDir = join(base, `${runId}-${jobId}`);
|
|
34
|
+
if (existsSync(worktreeDir)) {
|
|
35
|
+
rmSync(worktreeDir, { recursive: true, force: true });
|
|
36
|
+
execSync("git worktree prune", { cwd: workspace, stdio: "pipe" });
|
|
37
|
+
}
|
|
38
|
+
execSync(`git worktree add -B "${branchName}" "${worktreeDir}" "${baseSha}"`, { cwd: workspace, stdio: "pipe" });
|
|
39
|
+
return [worktreeDir, branchName];
|
|
40
|
+
}
|
|
41
|
+
/** Remove worktree. Returns "cleaned" or "left_in_place" if uncommitted changes. */
|
|
42
|
+
export function cleanupAgentWorktree(workspace, worktreeDir, branchName) {
|
|
43
|
+
if (!existsSync(worktreeDir))
|
|
44
|
+
return "cleaned";
|
|
45
|
+
try {
|
|
46
|
+
const status = execSync("git status --porcelain", { cwd: worktreeDir, encoding: "utf-8" });
|
|
47
|
+
if (status.trim())
|
|
48
|
+
return "left_in_place";
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return "left_in_place";
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
execSync(`git worktree remove -f "${worktreeDir}"`, { cwd: workspace, stdio: "pipe" });
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// ignore
|
|
58
|
+
}
|
|
59
|
+
return "cleaned";
|
|
60
|
+
}
|
|
61
|
+
export function deleteLocalBranch(workspace, branch) {
|
|
62
|
+
try {
|
|
63
|
+
execSync(`git branch -D "${branch}"`, { cwd: workspace, stdio: "pipe" });
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// ignore
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=worktree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worktree.js","sourceRoot":"","sources":["../../src/parallel/worktree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;A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AAiB,EAAE,MAAc;IACjE,IAAI,CAAC;QACH,QAAQ,CAAC,kBAAkB,MAAM,GAAG,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3E,CAAC;IAAC,MAAM,CAAC;QACP,SAAS;IACX,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Returns true if the error message matches retryable patterns (rate limit, timeout, 5xx). */
|
|
2
|
+
export declare function isRetryableError(msg: string): boolean;
|
|
3
|
+
export interface StreamParserOptions {
|
|
4
|
+
warnThreshold?: number;
|
|
5
|
+
rotateThreshold?: number;
|
|
6
|
+
promptChars?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface StreamParser {
|
|
9
|
+
processLine(line: string): void;
|
|
10
|
+
onSignal(cb: (signal: "WARN" | "ROTATE" | "GUTTER" | "COMPLETE" | "DEFER") => void): void;
|
|
11
|
+
getTokens(): number;
|
|
12
|
+
/** Write session start banner to activity.log. */
|
|
13
|
+
startSession(): void;
|
|
14
|
+
/** Write token status line to activity.log. */
|
|
15
|
+
logTokenStatus(): void;
|
|
16
|
+
}
|
|
17
|
+
export declare function createStreamParser(workspace: string, options?: StreamParserOptions): StreamParser;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stream-parser/index.ts"],"names":[],"mappings":"AAyBA,+FAA+F;AAC/F,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,MAAM,WAAW,mBAAmB;IAClC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,KAAK,IAAI,GAAG,IAAI,CAAC;IAC1F,SAAS,IAAI,MAAM,CAAC;IACpB,kDAAkD;IAClD,YAAY,IAAI,IAAI,CAAC;IACrB,+CAA+C;IAC/C,cAAc,IAAI,IAAI,CAAC;CACxB;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,mBAAwB,GAChC,YAAY,CAiPd"}
|