@groupchatai/claude-runner 0.4.7 → 0.4.8
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/dist/index.js +37 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -114,6 +114,12 @@ ${comment.body}`
|
|
|
114
114
|
);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
+
const existingPrUrl = detail.pullRequestUrl ?? detail.task.pullRequestUrl;
|
|
118
|
+
if (existingPrUrl) {
|
|
119
|
+
parts.push(`
|
|
120
|
+
## Existing Pull Request
|
|
121
|
+
${existingPrUrl}`);
|
|
122
|
+
}
|
|
117
123
|
if (detail.task.dueDate) {
|
|
118
124
|
let dueStr = new Date(detail.task.dueDate).toLocaleDateString();
|
|
119
125
|
if (detail.task.dueTime != null) {
|
|
@@ -126,12 +132,18 @@ ${comment.body}`
|
|
|
126
132
|
parts.push(`
|
|
127
133
|
Due: ${dueStr}`);
|
|
128
134
|
}
|
|
135
|
+
const prRules = existingPrUrl ? [
|
|
136
|
+
`- This task already has a PR: ${existingPrUrl}. Push your changes to the EXISTING branch. Do NOT create a new PR.`,
|
|
137
|
+
"- You may push to existing branches and contribute to existing PRs."
|
|
138
|
+
] : [
|
|
139
|
+
"- When you have made code changes, you MUST create a new branch, commit your changes, push to the remote, and open a PR using `gh pr create`. Do NOT skip PR creation \u2014 always open a real PR.",
|
|
140
|
+
"- You may push to existing branches and contribute to existing PRs."
|
|
141
|
+
];
|
|
129
142
|
parts.push(
|
|
130
143
|
[
|
|
131
144
|
"\n---",
|
|
132
145
|
"RULES:",
|
|
133
|
-
|
|
134
|
-
"- You may push to existing branches and contribute to existing PRs.",
|
|
146
|
+
...prRules,
|
|
135
147
|
"- NEVER run `gh pr merge`. Do NOT merge any PR.",
|
|
136
148
|
"- NEVER run `gh pr close`. Do NOT close any PR.",
|
|
137
149
|
"- NEVER run `git push --force` or `git push -f`. No force pushes.",
|
|
@@ -315,7 +327,23 @@ function safeFormatRateLimitPayload(o) {
|
|
|
315
327
|
}
|
|
316
328
|
function parseClaudeNdjsonEvents(rawOutput) {
|
|
317
329
|
const events = [];
|
|
318
|
-
|
|
330
|
+
const cleaned = stripAnsi(rawOutput).trim();
|
|
331
|
+
try {
|
|
332
|
+
const parsed = JSON.parse(cleaned);
|
|
333
|
+
if (Array.isArray(parsed)) {
|
|
334
|
+
for (const item of parsed) {
|
|
335
|
+
if (item && typeof item === "object" && typeof item.type === "string") {
|
|
336
|
+
events.push(item);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return events;
|
|
340
|
+
}
|
|
341
|
+
if (parsed && typeof parsed === "object" && typeof parsed.type === "string") {
|
|
342
|
+
return [parsed];
|
|
343
|
+
}
|
|
344
|
+
} catch {
|
|
345
|
+
}
|
|
346
|
+
for (const line of cleaned.split("\n")) {
|
|
319
347
|
const t = line.trim();
|
|
320
348
|
if (!t.startsWith("{")) continue;
|
|
321
349
|
try {
|
|
@@ -381,11 +409,7 @@ function claudeRunShouldReportAsError(exitCode, events) {
|
|
|
381
409
|
return false;
|
|
382
410
|
}
|
|
383
411
|
function compactTaskErrorForApi(detail) {
|
|
384
|
-
|
|
385
|
-
if (/^rate limit \(/i.test(s)) {
|
|
386
|
-
return s.split(/\s*—\s*/)[0]?.trim() ?? s;
|
|
387
|
-
}
|
|
388
|
-
return s;
|
|
412
|
+
return detail.trim();
|
|
389
413
|
}
|
|
390
414
|
function spawnClaudeCode(prompt, config, runOptions, resumeSessionId, cwdOverride) {
|
|
391
415
|
const format = config.verbose ? "stream-json" : "json";
|
|
@@ -628,25 +652,16 @@ function createWorktree(repoDir, taskId, existingBranch) {
|
|
|
628
652
|
async function resolveExistingPrBranch(detail, workDir) {
|
|
629
653
|
try {
|
|
630
654
|
if (detail.branchName) return detail.branchName;
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
"gh",
|
|
635
|
-
["pr", "view", detail.pullRequestUrl, "--json", "headRefName", "--jq", ".headRefName"],
|
|
636
|
-
workDir
|
|
637
|
-
);
|
|
638
|
-
if (branch2?.trim()) return branch2.trim();
|
|
639
|
-
} catch {
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
const prUrls = [];
|
|
655
|
+
const candidatePrUrls = [];
|
|
656
|
+
if (detail.pullRequestUrl) candidatePrUrls.push(detail.pullRequestUrl);
|
|
657
|
+
if (detail.task.pullRequestUrl) candidatePrUrls.push(detail.task.pullRequestUrl);
|
|
643
658
|
for (const item of detail.activity) {
|
|
644
659
|
if (item.body) {
|
|
645
660
|
const matches = item.body.match(GITHUB_PR_URL_RE);
|
|
646
|
-
if (matches)
|
|
661
|
+
if (matches) candidatePrUrls.push(...matches);
|
|
647
662
|
}
|
|
648
663
|
}
|
|
649
|
-
const prUrl =
|
|
664
|
+
const prUrl = candidatePrUrls[0];
|
|
650
665
|
if (!prUrl) return void 0;
|
|
651
666
|
const branch = await runShellCommand(
|
|
652
667
|
"gh",
|