next-issue 5.3.0 → 5.5.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 +42 -26
- package/dist/args.mjs +4 -0
- package/dist/hand-over-comments.mjs +1 -1
- package/dist/hunt.mjs +39 -0
- package/dist/ports.mjs +2 -0
- package/dist/prompts.mjs +23 -0
- package/dist/run.mjs +5 -2
- package/dist/skip.mjs +18 -3
- package/dist/watch.mjs +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,7 +48,8 @@ the run handles one issue. For each issue:
|
|
|
48
48
|
1. Claim the issue only when it holds the `status:todo` label and holds no
|
|
49
49
|
`status:in-progress` or `status:in-review` label. A `status:done`,
|
|
50
50
|
`status:needs-human` or `status:blocked` label always stops the claim, a
|
|
51
|
-
resume too
|
|
51
|
+
resume too, except a `status:needs-human` issue with an answer to its
|
|
52
|
+
hand-over. An issue that GitHub lists as blocked by an open issue waits,
|
|
52
53
|
because its blocker closes only when the change of the blocker lands.
|
|
53
54
|
An issue with saved state under `.next-issue/` resumes instead, whatever its
|
|
54
55
|
other labels and blockers.
|
|
@@ -258,7 +259,7 @@ get the full summary object there instead, so the harness fits in a pipe. All
|
|
|
258
259
|
progress goes to standard error.
|
|
259
260
|
|
|
260
261
|
Recorded for each step: `claim`, `comments`, `reply`, `worktree`, `setup`,
|
|
261
|
-
`implement`, `review`, `fix`, `commit-fix`, `rebase`, `land`, `main-checks` and `
|
|
262
|
+
`implement`, `review`, `fix`, `commit-fix`, `rebase`, `land`, `main-checks`, `revert` and `hunt`, each with a
|
|
262
263
|
`.start`, `.end` or `.error` event and a duration in `ms`. Every `git` and `gh`
|
|
263
264
|
command is recorded with its exit code and duration. A `tool` event holds the
|
|
264
265
|
tool name, and for a `bash` tool the command too. Each agent call adds a `usage`
|
|
@@ -419,19 +420,22 @@ the prompt asks them to keep only what still holds. The reviewer only reads it.
|
|
|
419
420
|
## Retry an issue that waits for a person
|
|
420
421
|
|
|
421
422
|
A hand-over marks the state file as handed over. To give the issue another try,
|
|
422
|
-
take the `status:needs-human` label off. The next run
|
|
423
|
-
the budgets and the findings back to zero, clears
|
|
424
|
-
and the step that the last run reached, so the
|
|
425
|
-
stopped. After a revert, the branch holds the change
|
|
426
|
-
revert, so the change goes back to the review. An issue
|
|
423
|
+
take the `status:needs-human` label off, or answer the hand-over. The next run
|
|
424
|
+
that claims the issue puts the budgets and the findings back to zero, clears
|
|
425
|
+
the mark and keeps the branch and the step that the last run reached, so the
|
|
426
|
+
work carries on where it stopped. After a revert, the branch holds the change
|
|
427
|
+
again on top of the revert, so the change goes back to the review. An issue
|
|
428
|
+
that still has the label is not claimed, unless it has an answer to the
|
|
429
|
+
hand-over: then the run claims it and takes the label off.
|
|
427
430
|
|
|
428
431
|
To give guidance, answer the hand-over with a comment on the issue. When the run
|
|
429
432
|
resumes the issue, it reads the comments posted after its last
|
|
430
433
|
`next-issue needs help:` comment there. Only comments from users with write
|
|
431
|
-
access to the repository count, for the hand-over comment too.
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
434
|
+
access to the repository count, for the hand-over comment too. A comment that
|
|
435
|
+
starts with one of the headings of the harness never counts as an answer. The
|
|
436
|
+
implementer and every fixer of that run get them in their prompt, under the
|
|
437
|
+
heading `Answer of a person to the hand-over`. A short reply such as "ready,
|
|
438
|
+
take it" is enough. With no such comment, the run resumes with no guidance.
|
|
435
439
|
|
|
436
440
|
The `--reset` flag does the same for any issue that the run handles, whether or
|
|
437
441
|
not it was handed over. It touches only an issue that the run handles, so the
|
|
@@ -439,21 +443,22 @@ state of an issue that a label still holds back stays as it was.
|
|
|
439
443
|
|
|
440
444
|
## Commands and options
|
|
441
445
|
|
|
442
|
-
| Argument | Effect
|
|
443
|
-
| ----------- |
|
|
444
|
-
| `init` | Write the config file with the defaults
|
|
445
|
-
| `serve` | Run the worker of this repository that pi extensions talk to, see [Worker](#worker)
|
|
446
|
-
| `stop` | Stop the worker of this repository, see [Worker](#worker)
|
|
447
|
-
| `logs` | Show the latest run log and follow it, see [Observability](#observability)
|
|
448
|
-
| `--force` | Replace an existing config file, with `init`
|
|
449
|
-
| `--once` | Stop after the first handled issue
|
|
450
|
-
| `--max <n>` | Handle at most n issues
|
|
451
|
-
| `--watch` | Keep running, and read the open issues again after each pass
|
|
452
|
-
| `--
|
|
453
|
-
| `--
|
|
454
|
-
| `--
|
|
455
|
-
| `--
|
|
456
|
-
| `--
|
|
446
|
+
| Argument | Effect |
|
|
447
|
+
| ----------- | ------------------------------------------------------------------------------------------ |
|
|
448
|
+
| `init` | Write the config file with the defaults |
|
|
449
|
+
| `serve` | Run the worker of this repository that pi extensions talk to, see [Worker](#worker) |
|
|
450
|
+
| `stop` | Stop the worker of this repository, see [Worker](#worker) |
|
|
451
|
+
| `logs` | Show the latest run log and follow it, see [Observability](#observability) |
|
|
452
|
+
| `--force` | Replace an existing config file, with `init` |
|
|
453
|
+
| `--once` | Stop after the first handled issue |
|
|
454
|
+
| `--max <n>` | Handle at most n issues |
|
|
455
|
+
| `--watch` | Keep running, and read the open issues again after each pass |
|
|
456
|
+
| `--hunt` | Hunt the repository for a bug when the issues run out, see [Hunt for bugs](#hunt-for-bugs) |
|
|
457
|
+
| `--reset` | Drop the saved budgets and findings, and keep the rest of the state |
|
|
458
|
+
| `--json` | Print the machine summary instead of the text one, or the raw JSON lines with `logs` |
|
|
459
|
+
| `--verbose` | Show every command and all agent output |
|
|
460
|
+
| `--quiet` | Show only the milestones and the summary |
|
|
461
|
+
| `--help` | Show the option list |
|
|
457
462
|
|
|
458
463
|
The exit code is 1 when an issue needs a person or failed, and 0 when it does
|
|
459
464
|
not, so a cron job or a CI step can read the result of the run.
|
|
@@ -486,6 +491,17 @@ The watch stops:
|
|
|
486
491
|
branch failed;
|
|
487
492
|
- when the open issues cannot be read.
|
|
488
493
|
|
|
494
|
+
## Hunt for bugs
|
|
495
|
+
|
|
496
|
+
With `--hunt`, which turns on `--watch`, the harness runs a hunter agent once when the issues run out, before the wait. It hunts again only after a pass that handled an issue, so an idle watch does not start a hunter before each wait. The hunter:
|
|
497
|
+
|
|
498
|
+
- works in its own worktree at `.worktrees/hunt`, at the remote base branch, which the harness fetches and resets before each hunt;
|
|
499
|
+
- follows `next-issue.hunt.md` in the repository root, or a short built-in prompt when the file is missing;
|
|
500
|
+
- files one issue, for its most serious finding, with the `labels.ready` label and the sections of the [issue format](#issue-format), after a search for duplicates. It files nothing when it finds no real problem or a duplicate exists;
|
|
501
|
+
- runs no test suite and changes no file. It gets the tools of the reviewer.
|
|
502
|
+
|
|
503
|
+
The hunter ends its reply with an `issue:` line, and the run log holds it as a `hunt.issue` event with the `url`, or `none`. A hunt that fails writes a `hunt.error` event and the watch goes on. The next pass claims the new issue like any other. The hunter does not run alongside the issues.
|
|
504
|
+
|
|
489
505
|
## Worker
|
|
490
506
|
|
|
491
507
|
`next-issue serve` runs one worker for the repository it is run in. The
|
package/dist/args.mjs
CHANGED
|
@@ -4,6 +4,7 @@ const SWITCHES = new Map([
|
|
|
4
4
|
['--json', 'json'],
|
|
5
5
|
['--help', 'help'],
|
|
6
6
|
['--watch', 'watch'],
|
|
7
|
+
['--hunt', 'hunt'],
|
|
7
8
|
['--reset', 'reset'],
|
|
8
9
|
['--once', 'once'],
|
|
9
10
|
]);
|
|
@@ -21,6 +22,7 @@ export const USAGE = `next-issue [command] [options]
|
|
|
21
22
|
--once stop after the first handled issue
|
|
22
23
|
--max <n> handle at most n issues
|
|
23
24
|
--watch keep running and read the issues again after each pass
|
|
25
|
+
--hunt hunt the repository for a bug and file an issue when the issues run out, turns on --watch
|
|
24
26
|
--reset drop the saved budgets and findings first
|
|
25
27
|
--json print the machine summary instead of the text one, or raw lines with logs
|
|
26
28
|
--force replace an existing config file, with init
|
|
@@ -37,6 +39,7 @@ export function parseArgs(argv) {
|
|
|
37
39
|
reset: false,
|
|
38
40
|
force: false,
|
|
39
41
|
watch: false,
|
|
42
|
+
hunt: false,
|
|
40
43
|
level: 'normal',
|
|
41
44
|
};
|
|
42
45
|
for (let index = 0; index < argv.length; index += 1) {
|
|
@@ -57,6 +60,7 @@ export function parseArgs(argv) {
|
|
|
57
60
|
throw new Error(`Unknown argument: ${arg}`);
|
|
58
61
|
}
|
|
59
62
|
}
|
|
63
|
+
args.watch ||= args.hunt;
|
|
60
64
|
return args;
|
|
61
65
|
}
|
|
62
66
|
function command(arg) {
|
package/dist/hunt.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { REVIEWING } from './agents.mjs';
|
|
4
|
+
import { minutesToMs } from './durations.mjs';
|
|
5
|
+
import { readTextIfPresent } from './files.mjs';
|
|
6
|
+
import { git, remoteRef, resetHard } from './git.mjs';
|
|
7
|
+
import { oneAtATime } from './lock.mjs';
|
|
8
|
+
import { huntPrompt } from './prompts.mjs';
|
|
9
|
+
import { WORKTREE_DIR } from './worktree.mjs';
|
|
10
|
+
export const HUNT_FILE = 'next-issue.hunt.md';
|
|
11
|
+
const FILED = /^issue:\s*(\S+)\s*$/m;
|
|
12
|
+
export async function huntWorktree(repo, base, remote) {
|
|
13
|
+
const path = join(repo.root, WORKTREE_DIR, 'hunt');
|
|
14
|
+
const target = remoteRef(remote, base);
|
|
15
|
+
await git(repo.root, ['fetch', remote]);
|
|
16
|
+
await git(repo.root, ['worktree', 'prune']);
|
|
17
|
+
if (existsSync(join(path, '.git'))) {
|
|
18
|
+
await resetHard(path, target);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
await git(repo.root, ['worktree', 'add', '--detach', path, target]);
|
|
22
|
+
}
|
|
23
|
+
return path;
|
|
24
|
+
}
|
|
25
|
+
export async function hunt(context) {
|
|
26
|
+
const { repo, config, base, recorder, ports } = context;
|
|
27
|
+
await recorder.step('hunt', {}, async () => {
|
|
28
|
+
const cwd = await oneAtATime(repo.root, () => ports.huntWorktree(repo, base, config.remote));
|
|
29
|
+
const instructions = await readTextIfPresent(join(repo.root, HUNT_FILE));
|
|
30
|
+
const result = await ports.runAgent(recorder, {
|
|
31
|
+
name: 'hunter',
|
|
32
|
+
cwd,
|
|
33
|
+
prompt: huntPrompt(instructions, config.labels.ready),
|
|
34
|
+
profile: REVIEWING,
|
|
35
|
+
timeoutMs: minutesToMs(config.agentTimeoutMinutes),
|
|
36
|
+
});
|
|
37
|
+
recorder.event('hunt.issue', { url: FILED.exec(result.text)?.[1] ?? 'none' }, 'quiet');
|
|
38
|
+
});
|
|
39
|
+
}
|
package/dist/ports.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { pushToBase, revertOnBase, squashOnto } from './git-land.mjs';
|
|
|
6
6
|
import { abortMerge, commitMerge, startMerge } from './git-merge.mjs';
|
|
7
7
|
import { deleteBranch, diff, discardChanges, disputeBranches, isDirty, latestSubject, push, resetToBase, revision, setAside, } from './git.mjs';
|
|
8
8
|
import { canWrite, closeIssue, commentOnIssue, issueComments, openBlockers, openIssues, reopenIssue, threadComments, viewIssue, } from './github.mjs';
|
|
9
|
+
import { huntWorktree } from './hunt.mjs';
|
|
9
10
|
import { setLabel } from './labels.mjs';
|
|
10
11
|
import { detectSetupCommand } from './setup.mjs';
|
|
11
12
|
import { addWorktree, findWorktree, removeWorktree } from './worktree.mjs';
|
|
@@ -27,6 +28,7 @@ export const PORTS = {
|
|
|
27
28
|
disputeBranches,
|
|
28
29
|
failedBaseLogs,
|
|
29
30
|
findWorktree,
|
|
31
|
+
huntWorktree,
|
|
30
32
|
isDirty,
|
|
31
33
|
issueComments,
|
|
32
34
|
latestSubject,
|
package/dist/prompts.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ISSUE_SECTIONS } from './issue-format.mjs';
|
|
1
2
|
import { paragraphs } from './text.mjs';
|
|
2
3
|
const COMMIT_RULES = [
|
|
3
4
|
'Do not run git, gh or any push command. The harness commits for you.',
|
|
@@ -149,3 +150,25 @@ export function history(rounds) {
|
|
|
149
150
|
: `${head}\nThe fixer disputed every finding of this round: ${round.dispute}`;
|
|
150
151
|
});
|
|
151
152
|
}
|
|
153
|
+
const HUNT_DEFAULT = [
|
|
154
|
+
'Read the whole repository and look for bugs: wrong results, unhandled errors, races, security holes and documentation that contradicts the code.',
|
|
155
|
+
'Prove each finding from the code. A guess is not a finding.',
|
|
156
|
+
].join('\n');
|
|
157
|
+
export function huntPrompt(instructions, ready) {
|
|
158
|
+
const kept = instructions?.trim() ?? '';
|
|
159
|
+
const label = ready === '' ? '' : ` --label "${ready}"`;
|
|
160
|
+
return paragraphs([
|
|
161
|
+
'You are the hunter. Find the most serious problem in this repository and file one issue for it.',
|
|
162
|
+
`## Instructions\n${kept === '' ? HUNT_DEFAULT : kept}`,
|
|
163
|
+
'## Rules',
|
|
164
|
+
[
|
|
165
|
+
'Run no test suite and no build. Change no file. Do not commit or push.',
|
|
166
|
+
'File one issue only, for your most serious finding. File nothing when you find no real problem.',
|
|
167
|
+
'Before you file it, search the open and closed issues for a duplicate, for example with `gh issue list --state all --search "<words>"`. File nothing when a duplicate exists.',
|
|
168
|
+
`File it with \`gh issue create${label} --title "<conventional commit subject>" --body-file -\`.`,
|
|
169
|
+
`The body holds these sections as \`##\` headings, in this order: ${ISSUE_SECTIONS.map((section) => `\`## ${section}\``).join(', ')}.`,
|
|
170
|
+
'Give the file and line of each piece of evidence. Leave the Open questions section empty.',
|
|
171
|
+
'End your final message with one line in the form `issue: <url of the new issue>`, or `issue: none` when you filed nothing.',
|
|
172
|
+
].join('\n'),
|
|
173
|
+
]);
|
|
174
|
+
}
|
package/dist/run.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { writeJson } from './files.mjs';
|
|
|
7
7
|
import { slug } from './gh.mjs';
|
|
8
8
|
import { detectRepo } from './git.mjs';
|
|
9
9
|
import { defaultBranch } from './github.mjs';
|
|
10
|
+
import { hunt } from './hunt.mjs';
|
|
10
11
|
import { exitCode, runIssues } from './loop.mjs';
|
|
11
12
|
import { Recorder } from './observe.mjs';
|
|
12
13
|
import { pendingIssues } from './pending.mjs';
|
|
@@ -45,7 +46,7 @@ async function handle(args, config, repo, recorder, controls) {
|
|
|
45
46
|
};
|
|
46
47
|
const print = controls.print ?? (async () => undefined);
|
|
47
48
|
const { reports, stoppedAt, error } = args.watch
|
|
48
|
-
? await watchRun(args, loop,
|
|
49
|
+
? await watchRun(args, loop, context, interrupts, print)
|
|
49
50
|
: await runIssues(args, loop);
|
|
50
51
|
recordLoopEnd(recorder, stoppedAt, error);
|
|
51
52
|
const summary = await endRun(recorder, reports);
|
|
@@ -54,7 +55,8 @@ async function handle(args, config, repo, recorder, controls) {
|
|
|
54
55
|
}
|
|
55
56
|
return error === undefined ? exitCode(reports) : 1;
|
|
56
57
|
}
|
|
57
|
-
function watchRun(args, loop,
|
|
58
|
+
function watchRun(args, loop, context, interrupts, print) {
|
|
59
|
+
const { recorder } = context;
|
|
58
60
|
let passStart = recorder.summary();
|
|
59
61
|
return watchIssues(args, {
|
|
60
62
|
...loop,
|
|
@@ -64,6 +66,7 @@ function watchRun(args, loop, recorder, interrupts, print) {
|
|
|
64
66
|
return interrupts.sleep(minutesToMs(minutes));
|
|
65
67
|
},
|
|
66
68
|
passEnd: (issues) => print({ ...recorder.summary(passStart), issues }),
|
|
69
|
+
...(args.hunt ? { hunt: () => hunt(context).catch(() => undefined) } : {}),
|
|
67
70
|
});
|
|
68
71
|
}
|
|
69
72
|
function recordLoopEnd(recorder, stoppedAt, error) {
|
package/dist/skip.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { elapsedMs } from './durations.mjs';
|
|
2
2
|
import { message } from './errors.mjs';
|
|
3
|
-
|
|
3
|
+
import { handOverReply } from './hand-over-comments.mjs';
|
|
4
|
+
export function skipReason(issue, config, resuming, answered = false) {
|
|
4
5
|
const labels = new Set(issue.labels);
|
|
5
6
|
const names = config.labels;
|
|
6
|
-
|
|
7
|
+
const waiting = labels.has(names.needsHuman) && !answered;
|
|
8
|
+
if (labels.has(names.done) || waiting || labels.has(names.skip)) {
|
|
7
9
|
return 'stop-label';
|
|
8
10
|
}
|
|
9
11
|
if (resuming) {
|
|
@@ -18,7 +20,14 @@ export function skipReason(issue, config, resuming) {
|
|
|
18
20
|
return undefined;
|
|
19
21
|
}
|
|
20
22
|
export async function skipReport(context, log, issue, saved, started) {
|
|
21
|
-
|
|
23
|
+
let answered;
|
|
24
|
+
try {
|
|
25
|
+
answered = await hasAnswer(context, issue);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return unclaimedError(log, issue, error, started);
|
|
29
|
+
}
|
|
30
|
+
const skip = skipReason(issue, context.config, saved !== undefined, answered);
|
|
22
31
|
if (skip !== undefined) {
|
|
23
32
|
log.event('issue.skip', { title: issue.title, reason: skip });
|
|
24
33
|
return skipped(issue);
|
|
@@ -39,6 +48,12 @@ export async function skipReport(context, log, issue, saved, started) {
|
|
|
39
48
|
}
|
|
40
49
|
return undefined;
|
|
41
50
|
}
|
|
51
|
+
async function hasAnswer(context, issue) {
|
|
52
|
+
if (!issue.labels.includes(context.config.labels.needsHuman)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return (await handOverReply(context, issue.number)).length > 0;
|
|
56
|
+
}
|
|
42
57
|
export function unclaimedError(log, issue, error, started) {
|
|
43
58
|
const { reason, ms } = logIssueError(log, error, started);
|
|
44
59
|
return { ...skipped(issue), outcome: 'error', reason, ms };
|
package/dist/watch.mjs
CHANGED
|
@@ -5,6 +5,7 @@ export async function watchIssues(args, watch) {
|
|
|
5
5
|
const reports = [];
|
|
6
6
|
const failed = new Set();
|
|
7
7
|
let step = 0;
|
|
8
|
+
let hunting = true;
|
|
8
9
|
for (;;) {
|
|
9
10
|
const pass = await runIssues({ once: false, max: limit === undefined ? undefined : limit - handled(reports) }, watch, new Set(failed));
|
|
10
11
|
reports.push(...pass.reports);
|
|
@@ -12,6 +13,7 @@ export async function watchIssues(args, watch) {
|
|
|
12
13
|
if (handled(pass.reports) > 0) {
|
|
13
14
|
await watch.passEnd(pass.reports);
|
|
14
15
|
step = 0;
|
|
16
|
+
hunting = true;
|
|
15
17
|
}
|
|
16
18
|
if (pass.error !== undefined || pass.stoppedAt !== undefined) {
|
|
17
19
|
return { ...pass, reports };
|
|
@@ -19,6 +21,10 @@ export async function watchIssues(args, watch) {
|
|
|
19
21
|
if ((limit !== undefined && handled(reports) >= limit) || watch.stop()) {
|
|
20
22
|
return { reports };
|
|
21
23
|
}
|
|
24
|
+
if (hunting) {
|
|
25
|
+
hunting = false;
|
|
26
|
+
await watch.hunt?.();
|
|
27
|
+
}
|
|
22
28
|
const minutes = backOffMinutes(step);
|
|
23
29
|
step += 1;
|
|
24
30
|
if (!(await watch.wait(minutes))) {
|