next-issue 2.21.2 → 3.0.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 +89 -124
- package/dist/agent-reply.mjs +13 -0
- package/dist/agent-session.mjs +56 -0
- package/dist/agents.mjs +47 -88
- package/dist/args.mjs +26 -31
- package/dist/base-checks.mjs +37 -0
- package/dist/budget.mjs +16 -0
- package/dist/check-poll.mjs +73 -0
- package/dist/checks.mjs +67 -0
- package/dist/children.mjs +52 -0
- package/dist/cli.mjs +25 -15
- package/dist/command-records.mjs +15 -0
- package/dist/config-fields.mjs +32 -0
- package/dist/config.mjs +36 -71
- package/dist/conflict.mjs +43 -42
- package/dist/durations.mjs +37 -0
- package/dist/enter-review.mjs +13 -0
- package/dist/errors.mjs +20 -0
- package/dist/exec.mjs +71 -107
- package/dist/files.mjs +28 -0
- package/dist/fix.mjs +61 -50
- package/dist/gate.mjs +31 -43
- package/dist/gh.mjs +55 -0
- package/dist/git-commit.mjs +36 -0
- package/dist/git-land.mjs +30 -0
- package/dist/git-merge.mjs +42 -0
- package/dist/git.mjs +42 -166
- package/dist/github.mjs +32 -386
- package/dist/gitignore.mjs +13 -0
- package/dist/hand-over-comments.mjs +81 -0
- package/dist/handover.mjs +62 -103
- package/dist/implement.mjs +32 -0
- package/dist/interrupt.mjs +6 -19
- package/dist/job.mjs +28 -17
- package/dist/labels.mjs +65 -0
- package/dist/land.mjs +66 -0
- package/dist/lock.mjs +54 -0
- package/dist/logs.mjs +84 -62
- package/dist/loop.mjs +12 -37
- package/dist/observe.mjs +24 -98
- package/dist/open-job.mjs +39 -0
- package/dist/pending.mjs +46 -0
- package/dist/pipeline.mjs +34 -217
- package/dist/poll.mjs +20 -0
- package/dist/ports.mjs +18 -3
- package/dist/progress.mjs +36 -23
- package/dist/prompts.mjs +31 -36
- package/dist/protocol.mjs +17 -11
- package/dist/prune-runs.mjs +33 -0
- package/dist/pull-requests.mjs +60 -0
- package/dist/questions.mjs +45 -0
- package/dist/records.mjs +3 -0
- package/dist/render.mjs +19 -0
- package/dist/revert.mjs +27 -0
- package/dist/review.mjs +63 -83
- package/dist/run-logs.mjs +23 -0
- package/dist/run.mjs +59 -58
- package/dist/serve.mjs +46 -214
- package/dist/setup.mjs +2 -5
- package/dist/skip.mjs +54 -0
- package/dist/state.mjs +27 -39
- package/dist/summary.mjs +11 -7
- package/dist/text.mjs +15 -0
- package/dist/usage.mjs +45 -0
- package/dist/verdict.mjs +20 -13
- package/dist/watch.mjs +38 -0
- package/dist/worker-paths.mjs +16 -0
- package/dist/worker-run.mjs +56 -0
- package/dist/worker-server.mjs +56 -0
- package/dist/worktree-setup.mjs +25 -0
- package/dist/worktree.mjs +58 -0
- package/package.json +1 -1
- package/dist/merge.mjs +0 -75
package/dist/pipeline.mjs
CHANGED
|
@@ -1,251 +1,68 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { commitWork } from './fix.mjs';
|
|
3
|
-
import { checkGate } from './gate.mjs';
|
|
1
|
+
import { enterReview } from './enter-review.mjs';
|
|
4
2
|
import { branchName } from './git.mjs';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { message } from './observe.mjs';
|
|
9
|
-
import { implementPrompt, parseCommitSubject } from './prompts.mjs';
|
|
3
|
+
import { claimedError, stop } from './handover.mjs';
|
|
4
|
+
import { implement } from './implement.mjs';
|
|
5
|
+
import { openJob } from './open-job.mjs';
|
|
10
6
|
import { reviewRound } from './review.mjs';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const labels = new Set(issue.labels);
|
|
15
|
-
const names = config.labels;
|
|
16
|
-
if (labels.has(names.done) || labels.has(names.needsHuman) || labels.has(names.skip)) {
|
|
17
|
-
return 'stop-label';
|
|
18
|
-
}
|
|
19
|
-
if (resuming) {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
if (names.ready.length > 0 && !labels.has(names.ready)) {
|
|
23
|
-
return 'not-ready';
|
|
24
|
-
}
|
|
25
|
-
if (labels.has(names.inProgress) || labels.has(names.inReview)) {
|
|
26
|
-
return 'in-flight';
|
|
27
|
-
}
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
export async function pendingIssues(context) {
|
|
31
|
-
const { repo, config, ports } = context;
|
|
32
|
-
const { ready, inProgress, inReview } = config.labels;
|
|
33
|
-
const labels = ready.length === 0 ? [] : [ready, inProgress, inReview];
|
|
34
|
-
const issues = await ports.openIssues(repo, config.issueLimit, labels);
|
|
35
|
-
const listed = new Set(issues.map((issue) => issue.number));
|
|
36
|
-
let openCount = issues.length;
|
|
37
|
-
for (const number of await savedIssues(repo)) {
|
|
38
|
-
if (listed.has(number)) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
const saved = await readState(repo, number).catch(() => 'broken');
|
|
42
|
-
if (saved === undefined) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
const { open, ...issue } = await ports.viewIssue(repo, number);
|
|
47
|
-
if (open) {
|
|
48
|
-
openCount += 1;
|
|
49
|
-
}
|
|
50
|
-
if (saved === 'broken' ||
|
|
51
|
-
open ||
|
|
52
|
-
(saved.pr !== undefined && (await ports.prMerged(repo, saved.pr)))) {
|
|
53
|
-
issues.push(issue);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
context.recorder
|
|
58
|
-
.scope({ issue: number })
|
|
59
|
-
.event('issue.error', { error: message(error) }, 'quiet');
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
context.recorder.event('issues', { open: openCount }, 'quiet');
|
|
63
|
-
return issues.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
64
|
-
}
|
|
7
|
+
import { skipReport, unclaimedError } from './skip.mjs';
|
|
8
|
+
import { newState, readState, resetState } from './state.mjs';
|
|
9
|
+
import { setUp } from './worktree-setup.mjs';
|
|
65
10
|
export async function processIssue(context, issue) {
|
|
11
|
+
const { repo } = context;
|
|
66
12
|
const started = Date.now();
|
|
67
13
|
const log = context.recorder.scope({ issue: issue.number });
|
|
68
14
|
let saved;
|
|
69
15
|
try {
|
|
70
|
-
saved = await readState(
|
|
16
|
+
saved = await readState(repo, issue.number);
|
|
71
17
|
}
|
|
72
18
|
catch (error) {
|
|
73
|
-
log
|
|
74
|
-
return {
|
|
75
|
-
...skipped(issue),
|
|
76
|
-
outcome: 'error',
|
|
77
|
-
reason: message(error),
|
|
78
|
-
ms: Date.now() - started,
|
|
79
|
-
};
|
|
19
|
+
return unclaimedError(log, issue, error, started);
|
|
80
20
|
}
|
|
81
|
-
const skip =
|
|
21
|
+
const skip = await skipReport(context, log, issue, saved, started);
|
|
82
22
|
if (skip !== undefined) {
|
|
83
|
-
|
|
84
|
-
return skipped(issue);
|
|
85
|
-
}
|
|
86
|
-
if (saved === undefined) {
|
|
87
|
-
let blockers;
|
|
88
|
-
try {
|
|
89
|
-
blockers = await context.ports.openBlockers(context.repo, issue.number);
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
log.event('issue.error', { error: message(error), ms: Date.now() - started }, 'quiet');
|
|
93
|
-
return {
|
|
94
|
-
...skipped(issue),
|
|
95
|
-
outcome: 'error',
|
|
96
|
-
reason: message(error),
|
|
97
|
-
ms: Date.now() - started,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
if (blockers.length > 0) {
|
|
101
|
-
log.event('issue.skip', { title: issue.title, reason: 'blocked', blockers });
|
|
102
|
-
return skipped(issue);
|
|
103
|
-
}
|
|
23
|
+
return skip;
|
|
104
24
|
}
|
|
105
25
|
log.event('issue.start', { title: issue.title, createdAt: issue.createdAt }, 'quiet');
|
|
106
|
-
const
|
|
107
|
-
issue: issue.number,
|
|
108
|
-
phase: 'claimed',
|
|
109
|
-
branch: branchName(issue.number),
|
|
110
|
-
ciFixes: 0,
|
|
111
|
-
reviewRounds: 0,
|
|
112
|
-
reviewLog: [],
|
|
113
|
-
};
|
|
114
|
-
const state = saved === undefined
|
|
115
|
-
? fresh
|
|
116
|
-
: context.reset || saved.handedOver === true
|
|
117
|
-
? resetState(saved)
|
|
118
|
-
: saved;
|
|
26
|
+
const state = startState(context, issue, saved);
|
|
119
27
|
try {
|
|
120
28
|
const report = await work(context, issue, log, state, saved === undefined, saved?.handedOver === true);
|
|
121
29
|
log.event('issue.end', { outcome: report.outcome, reason: report.reason, ms: report.ms }, 'quiet');
|
|
122
30
|
return report;
|
|
123
31
|
}
|
|
124
32
|
catch (error) {
|
|
125
|
-
log
|
|
126
|
-
try {
|
|
127
|
-
await handOver(context, log, issue.number, state, `The run failed: ${message(error)}`);
|
|
128
|
-
}
|
|
129
|
-
catch (failure) {
|
|
130
|
-
log.event('hand-over.error', { error: message(failure) }, 'quiet');
|
|
131
|
-
}
|
|
132
|
-
await cleanUp(context, log, state.branch);
|
|
133
|
-
return {
|
|
134
|
-
issue: issue.number,
|
|
135
|
-
outcome: 'error',
|
|
136
|
-
reason: message(error),
|
|
137
|
-
pr: state.pr,
|
|
138
|
-
ciFixes: state.ciFixes,
|
|
139
|
-
reviewRounds: state.reviewRounds,
|
|
140
|
-
ms: Date.now() - started,
|
|
141
|
-
};
|
|
33
|
+
return claimedError(context, log, issue, state, error, started);
|
|
142
34
|
}
|
|
143
35
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const branch = state.branch;
|
|
148
|
-
await log.step('claim', { label: config.labels.inProgress }, async () => {
|
|
149
|
-
await setStatus(context, issue.number, state.pr, config.labels.inProgress);
|
|
150
|
-
await writeState(repo, state);
|
|
151
|
-
});
|
|
152
|
-
const comments = await log.step('comments', {}, () => writerComments(context, log, issue.number));
|
|
153
|
-
const reply = handedOver
|
|
154
|
-
? await log.step('reply', {}, () => handOverReply(context, issue.number, state.pr))
|
|
155
|
-
: [];
|
|
156
|
-
const added = await log.step('worktree', { branch }, () => oneAtATime(repo.root, () => ports.addWorktree(repo, issue.number, branch, context.base, config.remote, start)));
|
|
157
|
-
const worktree = added.path;
|
|
158
|
-
if (!added.baseUpdated) {
|
|
159
|
-
log.event('base.behind', { base: context.base }, 'quiet');
|
|
36
|
+
function startState(context, issue, saved) {
|
|
37
|
+
if (saved === undefined) {
|
|
38
|
+
return newState(issue.number, branchName(issue.number));
|
|
160
39
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
comments,
|
|
169
|
-
reply,
|
|
170
|
-
started,
|
|
171
|
-
noChecks: false,
|
|
172
|
-
mainBroken: false,
|
|
173
|
-
};
|
|
174
|
-
const setupCommand = config.setupCommand ?? (await ports.detectSetupCommand(worktree));
|
|
175
|
-
if (setupCommand !== undefined) {
|
|
176
|
-
const setup = await log.step('setup', { cmd: setupCommand, found: config.setupCommand === undefined }, () => ports.runSetup(setupCommand, worktree, config.setupTimeoutMinutes * 60_000));
|
|
177
|
-
if (setup.code !== 0) {
|
|
178
|
-
const late = setup.timedOut === true;
|
|
179
|
-
log.event('setup.fail', { code: setup.code, timedOut: late, stderr: setup.stderr.trim().slice(-2000) }, 'quiet');
|
|
180
|
-
await escalate(job, late
|
|
181
|
-
? `The setup command did not finish in ${config.setupTimeoutMinutes} minutes.`
|
|
182
|
-
: 'The setup command failed in the worktree.');
|
|
183
|
-
return finish(job, 'needs-human', late ? 'setup timeout' : 'setup failed');
|
|
184
|
-
}
|
|
40
|
+
return context.reset || saved.handedOver === true ? resetState(saved) : saved;
|
|
41
|
+
}
|
|
42
|
+
async function work(context, issue, log, state, start, handedOver) {
|
|
43
|
+
const job = await openJob(context, issue, log, state, start, handedOver);
|
|
44
|
+
const setup = await setUp(job);
|
|
45
|
+
if (setup.done) {
|
|
46
|
+
return setup.report;
|
|
185
47
|
}
|
|
186
48
|
if (state.phase === 'claimed') {
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
cwd: worktree,
|
|
191
|
-
prompt: implementPrompt(issue, comments, reply),
|
|
192
|
-
profile: CODING,
|
|
193
|
-
model: config.models.implementer,
|
|
194
|
-
timeoutMs: config.agentTimeoutMinutes * 60_000,
|
|
195
|
-
}));
|
|
196
|
-
const subject = parseCommitSubject(result.text, `fix: resolve issue #${issue.number}`);
|
|
197
|
-
if (!(await commitWork(job, before, subject, 'implementer'))) {
|
|
198
|
-
const earlier = await ports.latestSubject(worktree, context.base, config.remote);
|
|
199
|
-
if (earlier === undefined) {
|
|
200
|
-
await escalate(job, 'The implementer produced no change.');
|
|
201
|
-
return finish(job, 'needs-human', 'no implementation commit');
|
|
202
|
-
}
|
|
203
|
-
log.event('implement.earlier', { subject: earlier }, 'quiet');
|
|
204
|
-
state.title = earlier;
|
|
49
|
+
const implemented = await implement(job);
|
|
50
|
+
if (implemented.done) {
|
|
51
|
+
return implemented.report;
|
|
205
52
|
}
|
|
206
|
-
state.phase = 'implemented';
|
|
207
|
-
await writeState(repo, state);
|
|
208
53
|
}
|
|
209
54
|
if (context.stopAfterRound()) {
|
|
210
55
|
return stop(job);
|
|
211
56
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (fixed.done) {
|
|
216
|
-
return fixed.report;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
else if (state.phase === 'review' &&
|
|
220
|
-
state.pr !== undefined &&
|
|
221
|
-
(await ports.prMerged(repo, state.pr))) {
|
|
222
|
-
log.event('pull-request.merged', { pr: state.pr }, 'quiet');
|
|
223
|
-
if (!context.merge) {
|
|
224
|
-
await setStatus(context, issue.number, state.pr, config.labels.done);
|
|
225
|
-
return finish(job, 'done');
|
|
226
|
-
}
|
|
227
|
-
const landed = await afterMerge(job);
|
|
228
|
-
if (landed.done) {
|
|
229
|
-
return landed.report;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
await log.step('push', { branch }, () => ports.push(worktree, config.remote, branch));
|
|
234
|
-
state.phase = 'review';
|
|
235
|
-
await openPr(job);
|
|
57
|
+
const reviewing = await enterReview(job);
|
|
58
|
+
if (reviewing.done) {
|
|
59
|
+
return reviewing.report;
|
|
236
60
|
}
|
|
61
|
+
return reviewLoop(job);
|
|
62
|
+
}
|
|
63
|
+
async function reviewLoop(job) {
|
|
237
64
|
for (;;) {
|
|
238
|
-
if (context.stopAfterRound()) {
|
|
239
|
-
return stop(job);
|
|
240
|
-
}
|
|
241
|
-
const gate = await checkGate(job);
|
|
242
|
-
if (gate.done) {
|
|
243
|
-
return gate.report;
|
|
244
|
-
}
|
|
245
|
-
if (gate.fixed) {
|
|
246
|
-
continue;
|
|
247
|
-
}
|
|
248
|
-
if (context.stopAfterRound()) {
|
|
65
|
+
if (job.context.stopAfterRound()) {
|
|
249
66
|
return stop(job);
|
|
250
67
|
}
|
|
251
68
|
const round = await reviewRound(job);
|
package/dist/poll.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
+
import { secondsToMs } from './durations.mjs';
|
|
3
|
+
export const REAL_CLOCK = {
|
|
4
|
+
now: () => Date.now(),
|
|
5
|
+
sleep: (ms) => delay(ms),
|
|
6
|
+
};
|
|
7
|
+
export function pause(clock, options, rest) {
|
|
8
|
+
return clock.sleep(Math.min(secondsToMs(options.intervalSeconds), rest));
|
|
9
|
+
}
|
|
10
|
+
export async function pollUntil(options, clock, probe, settled) {
|
|
11
|
+
const deadline = clock.now() + options.timeoutMs;
|
|
12
|
+
for (;;) {
|
|
13
|
+
const value = await probe();
|
|
14
|
+
const rest = deadline - clock.now();
|
|
15
|
+
if (settled(value) || rest <= 0) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
await pause(clock, options, rest);
|
|
19
|
+
}
|
|
20
|
+
}
|
package/dist/ports.mjs
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { runAgent } from './agents.mjs';
|
|
2
|
+
import { failedBaseLogs, waitForBaseChecks } from './base-checks.mjs';
|
|
3
|
+
import { failedCheckLogs, waitForChecks } from './checks.mjs';
|
|
2
4
|
import { run } from './exec.mjs';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
+
import { commitAll } from './git-commit.mjs';
|
|
6
|
+
import { pushToBase, revertOnBase, squashOnto } from './git-land.mjs';
|
|
7
|
+
import { abortMerge, commitMerge, startMerge } from './git-merge.mjs';
|
|
8
|
+
import { deleteBranch, diff, discardChanges, disputeBranches, isDirty, latestSubject, push, resetToBase, revision, setAside, } from './git.mjs';
|
|
9
|
+
import { canWrite, closeIssue, commentOnIssue, commentOnPr, issueComments, openBlockers, openIssues, reopenIssue, threadComments, viewIssue, } from './github.mjs';
|
|
10
|
+
import { setLabel } from './labels.mjs';
|
|
11
|
+
import { createPr, findPr, markPrReady, mergeCommit, mergePr, prConflicts, prMerged, } from './pull-requests.mjs';
|
|
5
12
|
import { detectSetupCommand } from './setup.mjs';
|
|
13
|
+
import { addWorktree, findWorktree, removeWorktree } from './worktree.mjs';
|
|
14
|
+
async function runSetup(command, cwd, timeoutMs) {
|
|
15
|
+
return run('bash', ['-lc', command], { cwd, timeoutMs });
|
|
16
|
+
}
|
|
6
17
|
export const PORTS = {
|
|
7
18
|
abortMerge,
|
|
8
19
|
addWorktree,
|
|
9
20
|
canWrite,
|
|
21
|
+
closeIssue,
|
|
10
22
|
commentOnIssue,
|
|
11
23
|
commentOnPr,
|
|
12
24
|
commitAll,
|
|
@@ -32,14 +44,17 @@ export const PORTS = {
|
|
|
32
44
|
prConflicts,
|
|
33
45
|
prMerged,
|
|
34
46
|
push,
|
|
47
|
+
pushToBase,
|
|
35
48
|
removeWorktree,
|
|
36
49
|
reopenIssue,
|
|
37
50
|
resetToBase,
|
|
51
|
+
revertOnBase,
|
|
38
52
|
revision,
|
|
39
53
|
runAgent,
|
|
40
|
-
runSetup
|
|
54
|
+
runSetup,
|
|
41
55
|
setAside,
|
|
42
56
|
setLabel,
|
|
57
|
+
squashOnto,
|
|
43
58
|
startMerge,
|
|
44
59
|
threadComments,
|
|
45
60
|
viewIssue,
|
package/dist/progress.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { truncate } from './text.mjs';
|
|
1
2
|
const TOOL_LINE_MAX = 80;
|
|
2
3
|
const NOT_STAGES = new Set(['issue.start', 'agent.start', 'run.start']);
|
|
3
4
|
export function startProgress() {
|
|
@@ -7,15 +8,20 @@ function toolLine(record) {
|
|
|
7
8
|
const tool = String(record['tool']);
|
|
8
9
|
const command = record['command'];
|
|
9
10
|
const line = typeof command === 'string' ? `${tool} ${command.split('\n')[0]}` : tool;
|
|
10
|
-
return line
|
|
11
|
+
return truncate(line, TOOL_LINE_MAX, '…');
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
+
function stageName(step, record) {
|
|
13
14
|
const cause = record['cause'];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
if (step === 'fix' && typeof cause === 'string') {
|
|
16
|
+
return `${cause} fix`;
|
|
17
|
+
}
|
|
18
|
+
if (step === 'commit-fix') {
|
|
19
|
+
return 'commit fix';
|
|
20
|
+
}
|
|
21
|
+
return step;
|
|
22
|
+
}
|
|
23
|
+
function stageOf(step, record) {
|
|
24
|
+
const name = stageName(step, record);
|
|
19
25
|
const round = record['round'];
|
|
20
26
|
const limit = record['limit'];
|
|
21
27
|
if (typeof round !== 'number') {
|
|
@@ -23,26 +29,37 @@ function stageOf(step, record) {
|
|
|
23
29
|
}
|
|
24
30
|
return typeof limit === 'number' ? `${name} ${round}/${limit}` : `${name} ${round}`;
|
|
25
31
|
}
|
|
32
|
+
function without(issues, issue) {
|
|
33
|
+
return issues.filter((current) => current.issue !== issue);
|
|
34
|
+
}
|
|
26
35
|
function change(progress, issue, update) {
|
|
27
36
|
return {
|
|
28
37
|
...progress,
|
|
29
38
|
issues: progress.issues.map((current) => (current.issue === issue ? update(current) : current)),
|
|
30
39
|
};
|
|
31
40
|
}
|
|
41
|
+
function addHandled(handled, issue, outcome) {
|
|
42
|
+
const repeated = handled.some((item) => item.issue === issue && item.outcome === outcome);
|
|
43
|
+
return !repeated && (outcome === 'done' || outcome === 'needs-human' || outcome === 'error')
|
|
44
|
+
? [...handled, { issue, outcome }]
|
|
45
|
+
: handled;
|
|
46
|
+
}
|
|
47
|
+
function started(issue, record) {
|
|
48
|
+
const next = {
|
|
49
|
+
issue,
|
|
50
|
+
tools: 0,
|
|
51
|
+
startedAt: Date.parse(String(record['ts'])),
|
|
52
|
+
};
|
|
53
|
+
if (typeof record['title'] === 'string') {
|
|
54
|
+
next.title = record['title'];
|
|
55
|
+
}
|
|
56
|
+
return next;
|
|
57
|
+
}
|
|
32
58
|
export function applyEvent(progress, record) {
|
|
33
59
|
const kind = String(record['kind']);
|
|
34
60
|
const issue = Number(record['issue']);
|
|
35
61
|
if (kind === 'issue.start') {
|
|
36
|
-
|
|
37
|
-
issue,
|
|
38
|
-
tools: 0,
|
|
39
|
-
startedAt: Date.parse(String(record['ts'])),
|
|
40
|
-
};
|
|
41
|
-
if (typeof record['title'] === 'string') {
|
|
42
|
-
next.title = record['title'];
|
|
43
|
-
}
|
|
44
|
-
const others = progress.issues.filter((current) => current.issue !== issue);
|
|
45
|
-
return { ...progress, issues: [...others, next] };
|
|
62
|
+
return { ...progress, issues: [...without(progress.issues, issue), started(issue, record)] };
|
|
46
63
|
}
|
|
47
64
|
if (kind === 'tool') {
|
|
48
65
|
return change(progress, issue, (current) => ({
|
|
@@ -53,12 +70,8 @@ export function applyEvent(progress, record) {
|
|
|
53
70
|
}
|
|
54
71
|
if (kind === 'issue.end' || kind === 'issue.error') {
|
|
55
72
|
const outcome = kind === 'issue.error' ? 'error' : record['outcome'];
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
? [...progress.handled, { issue, outcome }]
|
|
59
|
-
: progress.handled;
|
|
60
|
-
const issues = progress.issues.filter((current) => current.issue !== issue);
|
|
61
|
-
return { ...progress, issues, handled };
|
|
73
|
+
const handled = addHandled(progress.handled, issue, outcome);
|
|
74
|
+
return { ...progress, issues: without(progress.issues, issue), handled };
|
|
62
75
|
}
|
|
63
76
|
if (kind === 'issues') {
|
|
64
77
|
return { ...progress, open: Number(record['open']) };
|
package/dist/prompts.mjs
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
+
import { paragraphs } from './text.mjs';
|
|
1
2
|
const COMMIT_RULES = [
|
|
2
3
|
'Do not run git, gh or any push command. The harness commits for you.',
|
|
3
4
|
'End your final message with one line in the form `commit: <conventional commit subject>`.',
|
|
4
5
|
].join('\n');
|
|
5
6
|
function issueBlock(issue, comments) {
|
|
6
|
-
return [
|
|
7
|
+
return paragraphs([
|
|
7
8
|
`# Issue #${issue.number}: ${issue.title}`,
|
|
8
9
|
issue.body.length > 0 ? issue.body : '(no description)',
|
|
9
10
|
comments.length > 0 ? `## Comments\n${comments.join('\n\n')}` : '',
|
|
10
|
-
]
|
|
11
|
-
.filter((part) => part.length > 0)
|
|
12
|
-
.join('\n\n');
|
|
11
|
+
]);
|
|
13
12
|
}
|
|
14
13
|
function replyBlock(reply) {
|
|
15
14
|
return reply.length > 0
|
|
@@ -21,7 +20,7 @@ function replyBlock(reply) {
|
|
|
21
20
|
: '';
|
|
22
21
|
}
|
|
23
22
|
export function implementPrompt(issue, comments, reply = []) {
|
|
24
|
-
return [
|
|
23
|
+
return paragraphs([
|
|
25
24
|
'You are the implementer. Solve the issue below in this worktree.',
|
|
26
25
|
issueBlock(issue, comments),
|
|
27
26
|
replyBlock(reply),
|
|
@@ -29,27 +28,25 @@ export function implementPrompt(issue, comments, reply = []) {
|
|
|
29
28
|
'Read the repository conventions first. Keep the change minimal and focused on the issue.',
|
|
30
29
|
'Add or update tests when the repository has a test suite.',
|
|
31
30
|
COMMIT_RULES,
|
|
32
|
-
]
|
|
33
|
-
.filter((part) => part.length > 0)
|
|
34
|
-
.join('\n\n');
|
|
31
|
+
]);
|
|
35
32
|
}
|
|
36
33
|
export function hookPrompt(issue, comments, role, output) {
|
|
37
|
-
return [
|
|
34
|
+
return paragraphs([
|
|
38
35
|
`You are the ${role}. The harness could not commit your work for the issue below, because a git hook failed.`,
|
|
39
36
|
issueBlock(issue, comments),
|
|
40
37
|
`## Hook output\n${output}`,
|
|
41
38
|
'## Rules',
|
|
42
39
|
'Fix what the hook reports and keep the rest of the work in this worktree. Do not skip or weaken the hook.',
|
|
43
40
|
COMMIT_RULES,
|
|
44
|
-
]
|
|
41
|
+
]);
|
|
45
42
|
}
|
|
46
43
|
export function capDiff(diff, maxChars) {
|
|
47
44
|
return diff.length <= maxChars
|
|
48
45
|
? diff
|
|
49
46
|
: `${diff.slice(0, maxChars)}\n... The diff is cut here, after ${maxChars} characters.`;
|
|
50
47
|
}
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
function reviewScope(earlier) {
|
|
49
|
+
return earlier.length === 0
|
|
53
50
|
? 'Check correctness, scope, repository conventions and test cover.'
|
|
54
51
|
: [
|
|
55
52
|
'This is a later round. Judge two things only:',
|
|
@@ -59,6 +56,8 @@ export function reviewPrompt(issue, comments, diff, earlier) {
|
|
|
59
56
|
'Withdraw every finding of that round if the dispute is correct. Repeat them all if the dispute is wrong.',
|
|
60
57
|
`## Earlier findings\n${earlier.join('\n')}`,
|
|
61
58
|
].join('\n');
|
|
59
|
+
}
|
|
60
|
+
export function reviewPrompt(issue, comments, diff, earlier) {
|
|
62
61
|
return [
|
|
63
62
|
'You are the reviewer. Judge whether the diff solves the issue correctly.',
|
|
64
63
|
issueBlock(issue, comments),
|
|
@@ -70,7 +69,7 @@ export function reviewPrompt(issue, comments, diff, earlier) {
|
|
|
70
69
|
'Read files and run commands to prove what you say: the tests, the type check or the linter.',
|
|
71
70
|
'The worktree is ready to use. Do not change a file. Do not write with git or gh.',
|
|
72
71
|
'The harness discards each change that you make, so a change is only lost work.',
|
|
73
|
-
|
|
72
|
+
reviewScope(earlier),
|
|
74
73
|
'Mark a finding blocking only for a wrong result, a missing part of the issue, a regression or a broken convention.',
|
|
75
74
|
'End your final message with the result as a json block in a ```json fence, in the form {"summary": "<short summary>", "findings": [{"severity": "blocking" or "minor", "detail": "<what is wrong and where>"}]}.',
|
|
76
75
|
'Give one entry per finding, and an empty list when nothing is wrong. The findings decide the outcome, so a problem that you leave out counts as no problem.',
|
|
@@ -97,37 +96,33 @@ const KIND_RULES = {
|
|
|
97
96
|
review: DISPUTE_RULE,
|
|
98
97
|
conflict: CONFLICT_RULE,
|
|
99
98
|
};
|
|
99
|
+
function earlierBlock(earlier) {
|
|
100
|
+
return earlier.length > 0
|
|
101
|
+
? [
|
|
102
|
+
'## Earlier rounds',
|
|
103
|
+
earlier.join('\n'),
|
|
104
|
+
'Keep those earlier fixes. Do not undo work that a later round did not question.',
|
|
105
|
+
].join('\n')
|
|
106
|
+
: '';
|
|
107
|
+
}
|
|
100
108
|
export function fixPrompt(issue, reason, detail, earlier, kind, reply = []) {
|
|
101
|
-
return [
|
|
109
|
+
return paragraphs([
|
|
102
110
|
`You are the fixer. Correct the work for issue #${issue.number}: ${issue.title}.`,
|
|
103
111
|
`## Reason\n${reason}`,
|
|
104
112
|
`## Detail\n${detail}`,
|
|
105
|
-
earlier
|
|
106
|
-
? [
|
|
107
|
-
'## Earlier rounds',
|
|
108
|
-
earlier.join('\n'),
|
|
109
|
-
'Keep those earlier fixes. Do not undo work that a later round did not question.',
|
|
110
|
-
].join('\n')
|
|
111
|
-
: '',
|
|
113
|
+
earlierBlock(earlier),
|
|
112
114
|
replyBlock(reply),
|
|
113
115
|
'## Rules',
|
|
114
116
|
'Fix the cause, not the symptom. Keep the change minimal.',
|
|
115
117
|
KIND_RULES[kind],
|
|
116
118
|
COMMIT_RULES,
|
|
117
|
-
]
|
|
118
|
-
.filter((part) => part.length > 0)
|
|
119
|
-
.join('\n\n');
|
|
120
|
-
}
|
|
121
|
-
export function parseUnrelated(text) {
|
|
122
|
-
const match = [...text.matchAll(/^unrelated:\s*(.+)$/gim)].at(-1);
|
|
123
|
-
const note = match?.[1]?.trim();
|
|
124
|
-
return note !== undefined && note.length > 0 ? note : undefined;
|
|
119
|
+
]);
|
|
125
120
|
}
|
|
126
|
-
export function
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
121
|
+
export function history(rounds) {
|
|
122
|
+
return rounds.map((round) => {
|
|
123
|
+
const head = `Round ${round.round}:\n${round.findings}`;
|
|
124
|
+
return round.dispute === undefined
|
|
125
|
+
? head
|
|
126
|
+
: `${head}\nThe fixer disputed every finding of this round: ${round.dispute}`;
|
|
127
|
+
});
|
|
133
128
|
}
|
package/dist/protocol.mjs
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
export function isNewer(candidate, current) {
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const left = leftCore.split('.').map(Number);
|
|
5
|
-
const right = rightCore.split('.').map(Number);
|
|
2
|
+
const { core: left, prerelease: leftPrerelease } = parseVersion(candidate);
|
|
3
|
+
const { core: right, prerelease: rightPrerelease } = parseVersion(current);
|
|
6
4
|
for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
|
|
7
5
|
const difference = (left[index] ?? 0) - (right[index] ?? 0);
|
|
8
6
|
if (difference !== 0) {
|
|
9
7
|
return difference > 0;
|
|
10
8
|
}
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
return isNewerPrerelease(leftPrerelease, rightPrerelease);
|
|
11
|
+
}
|
|
12
|
+
function isNewerPrerelease(left, right) {
|
|
13
|
+
if (left.length === 0 || right.length === 0) {
|
|
14
|
+
return left.length === 0 && right.length > 0;
|
|
16
15
|
}
|
|
17
|
-
for (let index = 0; index < Math.max(
|
|
18
|
-
const leftPart =
|
|
19
|
-
const rightPart =
|
|
16
|
+
for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
|
|
17
|
+
const leftPart = left[index];
|
|
18
|
+
const rightPart = right[index];
|
|
20
19
|
if (leftPart === undefined || rightPart === undefined) {
|
|
21
20
|
return rightPart === undefined;
|
|
22
21
|
}
|
|
@@ -35,3 +34,10 @@ export function isNewer(candidate, current) {
|
|
|
35
34
|
}
|
|
36
35
|
return false;
|
|
37
36
|
}
|
|
37
|
+
function parseVersion(version) {
|
|
38
|
+
const [core = '', ...rest] = version.replace(/\+.*$/, '').split('-');
|
|
39
|
+
return {
|
|
40
|
+
core: core.split('.').map(Number),
|
|
41
|
+
prerelease: rest.length > 0 ? rest.join('-').split('.') : [],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { rm, stat } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { daysToMs } from './durations.mjs';
|
|
4
|
+
import { listOrEmpty } from './files.mjs';
|
|
5
|
+
import { runsDir } from './state.mjs';
|
|
6
|
+
export async function pruneRuns(root, keepDays) {
|
|
7
|
+
if (keepDays <= 0) {
|
|
8
|
+
return 0;
|
|
9
|
+
}
|
|
10
|
+
const dir = runsDir(root);
|
|
11
|
+
const names = await listOrEmpty(dir);
|
|
12
|
+
const cutoff = Date.now() - daysToMs(keepDays);
|
|
13
|
+
let dropped = 0;
|
|
14
|
+
for (const name of names) {
|
|
15
|
+
if (await dropIfOlder(join(dir, name), cutoff)) {
|
|
16
|
+
dropped += 1;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return dropped;
|
|
20
|
+
}
|
|
21
|
+
async function dropIfOlder(path, cutoff) {
|
|
22
|
+
try {
|
|
23
|
+
const info = await stat(path);
|
|
24
|
+
if (info.mtimeMs >= cutoff) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
await rm(path, { force: true, recursive: true });
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|