next-issue 4.0.0 → 5.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 +14 -14
- package/dist/args.mjs +0 -3
- package/dist/base-checks.mjs +23 -2
- package/dist/config-fields.mjs +0 -6
- package/dist/config.mjs +4 -5
- package/dist/gate.mjs +27 -4
- package/dist/gh.mjs +1 -4
- package/dist/handover.mjs +3 -4
- package/dist/job.mjs +2 -19
- package/dist/open-job.mjs +1 -1
- package/dist/pending.mjs +1 -3
- package/dist/poll.mjs +0 -11
- package/dist/ports.mjs +2 -12
- package/dist/review.mjs +1 -1
- package/dist/serve.mjs +3 -3
- package/dist/state.mjs +1 -1
- package/dist/summary.mjs +0 -3
- package/package.json +1 -1
- package/dist/checks.mjs +0 -67
- package/dist/pull-requests.mjs +0 -60
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ npx -y next-issue@latest
|
|
|
9
9
|
|
|
10
10
|
## Overview
|
|
11
11
|
|
|
12
|
-
The harness claims the oldest open issue with the `status:todo` label and gives it its own git worktree and branch. An implementer agent does the work and the harness commits it. A reviewer agent judges the diff, and a fixer agent deals with any open finding, and the review runs again. With no open finding left, the harness rebases the change onto the base branch as one commit, pushes it there with no pull request and waits for the checks of that commit.
|
|
12
|
+
The harness claims the oldest open issue with the `status:todo` label and gives it its own git worktree and branch. An implementer agent does the work and the harness commits it. A reviewer agent judges the diff, and a fixer agent deals with any open finding, and the review runs again. With no open finding left, the harness rebases the change onto the base branch as one commit, pushes it there with no pull request and waits for the checks of that commit. On a red build the harness reruns the failed jobs once, and only a second red build goes to the fixer, whose fix lands the same way. When the checks pass, the issue is closed and gets `status:done`. When a budget runs out or the work cannot go on, the issue gets `status:needs-human` and goes to a person. Then the harness takes the next issue.
|
|
13
13
|
|
|
14
14
|
```mermaid
|
|
15
15
|
flowchart TD
|
|
@@ -51,8 +51,7 @@ the run handles one issue. For each issue:
|
|
|
51
51
|
resume too. An issue that GitHub lists as blocked by an open issue waits,
|
|
52
52
|
because its blocker closes only when the change of the blocker lands.
|
|
53
53
|
An issue with saved state under `.next-issue/` resumes instead, whatever its
|
|
54
|
-
other labels and blockers.
|
|
55
|
-
closed, if its pull request is merged.
|
|
54
|
+
other labels and blockers.
|
|
56
55
|
2. Add `status:in-progress` to the issue.
|
|
57
56
|
3. Fetch the remote, fast-forward the local copy of the default branch when
|
|
58
57
|
that is safe, then add a git worktree at `.worktrees/<n>` in the
|
|
@@ -110,7 +109,10 @@ the run handles one issue. For each issue:
|
|
|
110
109
|
up to `checkTimeoutMinutes`. A read that fails is tried three times. When
|
|
111
110
|
the checks pass, the harness closes the issue and sets `status:done`, and
|
|
112
111
|
the worktree, the local branch and the state file go away. When the checks
|
|
113
|
-
fail, the
|
|
112
|
+
fail, the harness reruns the failed jobs once with `gh run rerun <id>
|
|
113
|
+
--failed`, records a `main-checks.rerun` event, saves the rerun in the
|
|
114
|
+
state file and waits again once the runs restart. When the rerun cannot
|
|
115
|
+
start, or the checks fail again, the fixer gets their logs from the check budget, and its fix lands
|
|
114
116
|
the same way. When the fixer cannot fix them, its fix cannot land, or the
|
|
115
117
|
budget runs out, the harness reverts every commit of the change on the
|
|
116
118
|
base branch, pushes the revert and hands the issue to a person. A resume
|
|
@@ -169,7 +171,7 @@ and comments the reason on the issue, when:
|
|
|
169
171
|
- the setup command fails, or does not finish in `setupTimeoutMinutes`;
|
|
170
172
|
- a step of the run fails with an error. A `gh` call that is safe to repeat,
|
|
171
173
|
such as a read or a label edit, is tried up to three times first when the
|
|
172
|
-
network fails. A `gh
|
|
174
|
+
network fails. A `gh issue comment` is
|
|
173
175
|
tried once, so a lost reply never makes a duplicate.
|
|
174
176
|
|
|
175
177
|
The fixer sees the findings of all earlier rounds, not only the last one, with
|
|
@@ -237,8 +239,7 @@ Every run has an id, `<timestamp>`, and writes these under `.next-issue/runs/`:
|
|
|
237
239
|
- `<id>.jsonl` — one JSON object per event, with `ts`, `runId`, `kind`, and the
|
|
238
240
|
`issue`, `role` or `round` in scope;
|
|
239
241
|
- `<id>.summary.json` — token totals per agent role, event counts, and
|
|
240
|
-
one report per issue with the outcome, the reason
|
|
241
|
-
and the budgets used;
|
|
242
|
+
one report per issue with the outcome, the reason and the budgets used;
|
|
242
243
|
- `<id>/sessions/` — the full pi session of each agent call, with every
|
|
243
244
|
message, tool call and tool result. The session id in a `usage` event is
|
|
244
245
|
part of the file name.
|
|
@@ -251,7 +252,7 @@ get the full summary object there instead, so the harness fits in a pipe. All
|
|
|
251
252
|
progress goes to standard error.
|
|
252
253
|
|
|
253
254
|
Recorded for each step: `claim`, `comments`, `reply`, `worktree`, `setup`,
|
|
254
|
-
`implement`, `
|
|
255
|
+
`implement`, `review`, `fix`, `commit-fix`, `rebase`, `land`, `main-checks` and `revert`, each with a
|
|
255
256
|
`.start`, `.end` or `.error` event and a duration in `ms`. Every `git` and `gh`
|
|
256
257
|
command is recorded with its exit code and duration. A `tool` event holds the
|
|
257
258
|
tool name, and for a `bash` tool the command too. Each agent call adds a `usage`
|
|
@@ -308,7 +309,9 @@ project.
|
|
|
308
309
|
With no file, every field keeps its default. A field that is not in the file
|
|
309
310
|
keeps its default. A file that cannot be read, a file that is not valid
|
|
310
311
|
JSON, a field with a value of the wrong type and a field name that the harness
|
|
311
|
-
does not know all stop the run, so a typo cannot pass without a word.
|
|
312
|
+
does not know all stop the run, so a typo cannot pass without a word. An old
|
|
313
|
+
`draftPullRequest` field stops the run with an error that says to remove it,
|
|
314
|
+
because no pull request is opened.
|
|
312
315
|
|
|
313
316
|
```json
|
|
314
317
|
{
|
|
@@ -327,7 +330,6 @@ does not know all stop the run, so a typo cannot pass without a word.
|
|
|
327
330
|
"logMaxChars": 20000,
|
|
328
331
|
"diffMaxChars": 60000,
|
|
329
332
|
"keepRunDays": 7,
|
|
330
|
-
"draftPullRequest": true,
|
|
331
333
|
"models": {
|
|
332
334
|
"implementer": null,
|
|
333
335
|
"reviewer": null,
|
|
@@ -361,7 +363,6 @@ does not know all stop the run, so a typo cannot pass without a word.
|
|
|
361
363
|
| `logMaxChars` | `20000` | The maximum length of the failed job logs, shared between the failed jobs |
|
|
362
364
|
| `diffMaxChars` | `60000` | The maximum length of the diff that the reviewer reads |
|
|
363
365
|
| `keepRunDays` | `7` | The number of days to keep the run files; `0` keeps them all |
|
|
364
|
-
| `draftPullRequest` | `true` | Open the pull request as a draft, until the review approves |
|
|
365
366
|
| `setupCommand` | from the lock file | A shell command to run in a new worktree, before the implementer |
|
|
366
367
|
| `models` | `null` per role | The pi model per agent role, as `provider/model`: `implementer`, `reviewer`, `fixer` |
|
|
367
368
|
| `labels` | see above | The names of the labels that the harness reads and sets |
|
|
@@ -436,7 +437,6 @@ state of an issue that a label still holds back stays as it was.
|
|
|
436
437
|
| `--force` | Replace an existing config file, with `init` |
|
|
437
438
|
| `--once` | Stop after the first handled issue |
|
|
438
439
|
| `--max <n>` | Handle at most n issues |
|
|
439
|
-
| `--merge` | No effect: an approved change always lands on the base branch |
|
|
440
440
|
| `--watch` | Keep running, and read the open issues again after each pass |
|
|
441
441
|
| `--reset` | Drop the saved budgets and findings, and keep the rest of the state |
|
|
442
442
|
| `--json` | Print the machine summary instead of the text one, or the raw JSON lines with `logs` |
|
|
@@ -452,7 +452,7 @@ not, so a cron job or a CI step can read the result of the run.
|
|
|
452
452
|
A run without `--watch` ends when no unseen issue is left. With `--watch`, the
|
|
453
453
|
harness then waits, reads the open issues again and runs another pass, so it
|
|
454
454
|
picks up an issue that someone opens during the run, or one whose blocker
|
|
455
|
-
|
|
455
|
+
closes. Each pass tries every open issue again, also one that an earlier pass
|
|
456
456
|
skipped. An issue that failed in an earlier pass is not tried again until the
|
|
457
457
|
next run.
|
|
458
458
|
|
|
@@ -490,7 +490,7 @@ of one repository never affect another. The worker:
|
|
|
490
490
|
only one worker runs per repository. A lock whose process is no longer alive
|
|
491
491
|
is taken over;
|
|
492
492
|
- runs at most one run at a time. Each run is like `next-issue` without
|
|
493
|
-
`--watch
|
|
493
|
+
`--watch`;
|
|
494
494
|
- sends every client the progress of every run when it connects and on every
|
|
495
495
|
change: for each running issue the issue, the step, the tool count and the
|
|
496
496
|
last tool, and the handled issues;
|
package/dist/args.mjs
CHANGED
|
@@ -3,7 +3,6 @@ const SWITCHES = new Map([
|
|
|
3
3
|
['--force', 'force'],
|
|
4
4
|
['--json', 'json'],
|
|
5
5
|
['--help', 'help'],
|
|
6
|
-
['--merge', 'merge'],
|
|
7
6
|
['--watch', 'watch'],
|
|
8
7
|
['--reset', 'reset'],
|
|
9
8
|
['--once', 'once'],
|
|
@@ -21,7 +20,6 @@ export const USAGE = `next-issue [command] [options]
|
|
|
21
20
|
|
|
22
21
|
--once stop after the first handled issue
|
|
23
22
|
--max <n> handle at most n issues
|
|
24
|
-
--merge no effect: an approved change always lands on the base branch
|
|
25
23
|
--watch keep running and read the issues again after each pass
|
|
26
24
|
--reset drop the saved budgets and findings first
|
|
27
25
|
--json print the machine summary instead of the text one, or raw lines with logs
|
|
@@ -38,7 +36,6 @@ export function parseArgs(argv) {
|
|
|
38
36
|
json: false,
|
|
39
37
|
reset: false,
|
|
40
38
|
force: false,
|
|
41
|
-
merge: false,
|
|
42
39
|
watch: false,
|
|
43
40
|
level: 'normal',
|
|
44
41
|
};
|
package/dist/base-checks.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
1
2
|
import { pollChecks } from './check-poll.mjs';
|
|
2
|
-
import {
|
|
3
|
+
import { secondsToMs } from './durations.mjs';
|
|
4
|
+
import { gh, ghJson } from './gh.mjs';
|
|
3
5
|
import { runLogs } from './run-logs.mjs';
|
|
6
|
+
const RESTART_TRIES = 10;
|
|
4
7
|
const FAILED_CONCLUSIONS = new Set(['failure', 'timed_out', 'startup_failure']);
|
|
5
8
|
async function baseRuns(repo, sha) {
|
|
6
9
|
return ghJson(repo, [
|
|
@@ -9,7 +12,7 @@ async function baseRuns(repo, sha) {
|
|
|
9
12
|
'--commit',
|
|
10
13
|
sha,
|
|
11
14
|
'--json',
|
|
12
|
-
'databaseId,name,status,conclusion',
|
|
15
|
+
'databaseId,name,status,conclusion,attempt',
|
|
13
16
|
]);
|
|
14
17
|
}
|
|
15
18
|
function failedRun(entry) {
|
|
@@ -29,6 +32,24 @@ export function waitForBaseChecks(repo, sha, options) {
|
|
|
29
32
|
watch: async () => baseState(await baseRuns(repo, sha)),
|
|
30
33
|
}, options);
|
|
31
34
|
}
|
|
35
|
+
export async function rerunFailedBase(repo, sha) {
|
|
36
|
+
const failed = (await baseRuns(repo, sha)).filter(failedRun);
|
|
37
|
+
for (const entry of failed) {
|
|
38
|
+
await gh(repo, ['run', 'rerun', String(entry.databaseId), '--failed']);
|
|
39
|
+
}
|
|
40
|
+
await waitForRestart(repo, sha, failed);
|
|
41
|
+
return failed.map((entry) => String(entry.databaseId));
|
|
42
|
+
}
|
|
43
|
+
async function waitForRestart(repo, sha, failed) {
|
|
44
|
+
for (let attempt = 1; attempt <= RESTART_TRIES; attempt += 1) {
|
|
45
|
+
const runs = await baseRuns(repo, sha);
|
|
46
|
+
const restarted = failed.every((entry) => runs.some((run) => run.databaseId === entry.databaseId && run.attempt > entry.attempt));
|
|
47
|
+
if (restarted) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
await delay(secondsToMs(1));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
32
53
|
export async function failedBaseLogs(repo, sha, maxChars) {
|
|
33
54
|
const failed = (await baseRuns(repo, sha))
|
|
34
55
|
.filter(failedRun)
|
package/dist/config-fields.mjs
CHANGED
|
@@ -18,12 +18,6 @@ export function whole(value, field, least) {
|
|
|
18
18
|
}
|
|
19
19
|
return value;
|
|
20
20
|
}
|
|
21
|
-
export function flag(value, field) {
|
|
22
|
-
if (typeof value !== 'boolean') {
|
|
23
|
-
throw new Error(`${CONFIG_FILE}: ${field} must be true or false.`);
|
|
24
|
-
}
|
|
25
|
-
return value;
|
|
26
|
-
}
|
|
27
21
|
export function text(value, field, allowEmpty) {
|
|
28
22
|
if (typeof value !== 'string' || (!allowEmpty && value.length === 0)) {
|
|
29
23
|
throw new Error(`${CONFIG_FILE}: ${field} must be ${allowEmpty ? 'text' : 'text that is not empty'}.`);
|
package/dist/config.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
-
import { CONFIG_FILE,
|
|
2
|
+
import { CONFIG_FILE, record, rejectUnknown, text, whole } from './config-fields.mjs';
|
|
3
3
|
import { hasCode, message, parseJson } from './errors.mjs';
|
|
4
4
|
import { readTextIfPresent, writeJson } from './files.mjs';
|
|
5
5
|
const DEFAULTS = {
|
|
@@ -18,7 +18,6 @@ const DEFAULTS = {
|
|
|
18
18
|
logMaxChars: 20000,
|
|
19
19
|
diffMaxChars: 60000,
|
|
20
20
|
keepRunDays: 7,
|
|
21
|
-
draftPullRequest: true,
|
|
22
21
|
models: {},
|
|
23
22
|
labels: {
|
|
24
23
|
ready: 'status:todo',
|
|
@@ -86,6 +85,9 @@ export async function loadConfig(root) {
|
|
|
86
85
|
}
|
|
87
86
|
function parseConfig(value) {
|
|
88
87
|
const file = record(value, 'the file');
|
|
88
|
+
if (file.draftPullRequest !== undefined) {
|
|
89
|
+
throw new Error(`${CONFIG_FILE}: draftPullRequest is no longer used, because changes land on the base branch with no pull request. Remove the field.`);
|
|
90
|
+
}
|
|
89
91
|
rejectUnknown(file, FIELDS, 'field');
|
|
90
92
|
const config = defaults();
|
|
91
93
|
if (file.remote !== undefined) {
|
|
@@ -96,9 +98,6 @@ function parseConfig(value) {
|
|
|
96
98
|
config[field] = whole(file[field], field, least);
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
|
-
if (file.draftPullRequest !== undefined) {
|
|
100
|
-
config.draftPullRequest = flag(file.draftPullRequest, 'draftPullRequest');
|
|
101
|
-
}
|
|
102
101
|
if (file.setupCommand !== undefined) {
|
|
103
102
|
config.setupCommand = text(file.setupCommand, 'setupCommand', false);
|
|
104
103
|
}
|
package/dist/gate.mjs
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { budgetUse } from './budget.mjs';
|
|
2
2
|
import { checkWaiting } from './check-poll.mjs';
|
|
3
|
+
import { asError } from './errors.mjs';
|
|
3
4
|
import { escalateCheckFix, fixRound } from './fix.mjs';
|
|
4
5
|
import { escalateAndFinish } from './handover.mjs';
|
|
5
6
|
import { GATE_FIXED, GATE_PASSED } from './job.mjs';
|
|
6
7
|
import { revert } from './revert.mjs';
|
|
7
8
|
import { writeState } from './state.mjs';
|
|
8
9
|
export async function checkGate(job, sha) {
|
|
9
|
-
const {
|
|
10
|
-
const
|
|
11
|
-
const checks = await log.step('main-checks', { sha }, () => ports.waitForBaseChecks(repo, sha, checkWaiting(config, true)));
|
|
12
|
-
log.event('main-checks.state', { state: checks });
|
|
10
|
+
const { base } = job.context;
|
|
11
|
+
const checks = await rerunOnce(job, sha, await waitForChecks(job, sha));
|
|
13
12
|
if (checks === 'pass' || checks === 'none') {
|
|
14
13
|
return GATE_PASSED;
|
|
15
14
|
}
|
|
@@ -19,6 +18,30 @@ export async function checkGate(job, sha) {
|
|
|
19
18
|
}
|
|
20
19
|
return failedChecksFix(job, sha);
|
|
21
20
|
}
|
|
21
|
+
async function waitForChecks(job, sha, fields = {}) {
|
|
22
|
+
const { context, log } = job;
|
|
23
|
+
const { repo, config, ports } = context;
|
|
24
|
+
const checks = await log.step('main-checks', { sha, ...fields }, () => ports.waitForBaseChecks(repo, sha, checkWaiting(config, true)));
|
|
25
|
+
log.event('main-checks.state', { state: checks, ...fields });
|
|
26
|
+
return checks;
|
|
27
|
+
}
|
|
28
|
+
async function rerunOnce(job, sha, checks) {
|
|
29
|
+
const { context, log, state } = job;
|
|
30
|
+
if (checks !== 'fail' || state.rerun === sha) {
|
|
31
|
+
return checks;
|
|
32
|
+
}
|
|
33
|
+
state.rerun = sha;
|
|
34
|
+
await writeState(context.repo, state);
|
|
35
|
+
try {
|
|
36
|
+
const runs = await context.ports.rerunFailedBase(context.repo, sha);
|
|
37
|
+
log.event('main-checks.rerun', { sha, runs });
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
log.event('main-checks.rerun-failed', { sha, error: asError(error).message });
|
|
41
|
+
return checks;
|
|
42
|
+
}
|
|
43
|
+
return waitForChecks(job, sha, { rerun: true });
|
|
44
|
+
}
|
|
22
45
|
async function failedChecksFix(job, sha) {
|
|
23
46
|
const { context, log, state } = job;
|
|
24
47
|
const { repo, config, ports, base } = context;
|
package/dist/gh.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
2
|
import { secondsToMs } from './durations.mjs';
|
|
3
3
|
import { errorMatches } from './errors.mjs';
|
|
4
|
-
import { must, optionalFlag, run
|
|
4
|
+
import { must, optionalFlag, run } from './exec.mjs';
|
|
5
5
|
const NETWORK_TRIES = 3;
|
|
6
6
|
const NETWORK_FAULT = /unexpected EOF|connection reset|connection refused|i\/o timeout|TLS handshake timeout|HTTP 50[234]/i;
|
|
7
7
|
export function slug(repo) {
|
|
@@ -47,9 +47,6 @@ export async function ghApi(repo, path, jq, { paginate = false } = {}) {
|
|
|
47
47
|
jq,
|
|
48
48
|
]);
|
|
49
49
|
}
|
|
50
|
-
export async function ghSucceeds(repo, args) {
|
|
51
|
-
return succeeded(await ghRun(repo, args));
|
|
52
|
-
}
|
|
53
50
|
export function names(items) {
|
|
54
51
|
return items.map((item) => item.name);
|
|
55
52
|
}
|
package/dist/handover.mjs
CHANGED
|
@@ -12,8 +12,8 @@ export async function escalateAndFinish(job, note, reason) {
|
|
|
12
12
|
return { done: true, report: await finish(job, 'needs-human', reason) };
|
|
13
13
|
}
|
|
14
14
|
export async function finishDone(job) {
|
|
15
|
-
const { context, issue
|
|
16
|
-
await setStatus(context, issue.number,
|
|
15
|
+
const { context, issue } = job;
|
|
16
|
+
await setStatus(context, issue.number, context.config.labels.done);
|
|
17
17
|
await context.ports.closeIssue(context.repo, issue.number);
|
|
18
18
|
return { done: true, report: await finish(job, 'done') };
|
|
19
19
|
}
|
|
@@ -29,7 +29,6 @@ function issueReport(issue, outcome, state, started, reason) {
|
|
|
29
29
|
issue,
|
|
30
30
|
outcome,
|
|
31
31
|
reason,
|
|
32
|
-
pr: state.pr,
|
|
33
32
|
ciFixes: state.ciFixes,
|
|
34
33
|
reviewRounds: state.reviewRounds,
|
|
35
34
|
ms: elapsedMs(started),
|
|
@@ -76,7 +75,7 @@ async function handOver(context, log, issue, state, reason) {
|
|
|
76
75
|
const { repo, ports, config } = context;
|
|
77
76
|
log.event('hand-over', { reason }, 'quiet');
|
|
78
77
|
await writeState(repo, { ...state, handedOver: true });
|
|
79
|
-
await setStatus(context, issue,
|
|
78
|
+
await setStatus(context, issue, config.labels.needsHuman);
|
|
80
79
|
await ports.commentOnIssue(repo, issue, `${HAND_OVER} ${reason}`);
|
|
81
80
|
}
|
|
82
81
|
export async function claimedError(context, log, issue, state, error, started) {
|
package/dist/job.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { managedLabels } from './config.mjs';
|
|
2
2
|
import { minutesToMs } from './durations.mjs';
|
|
3
|
-
import { writeState } from './state.mjs';
|
|
4
3
|
export const ROUND_CONTINUE = { done: false };
|
|
5
4
|
export const GATE_PASSED = { done: false, fixed: false };
|
|
6
5
|
export const GATE_FIXED = { done: false, fixed: true };
|
|
@@ -24,23 +23,7 @@ export function runRole(job, role, prompt, profile) {
|
|
|
24
23
|
export function fallbackTitle(issue) {
|
|
25
24
|
return `fix: resolve issue #${issue.number}`;
|
|
26
25
|
}
|
|
27
|
-
export async function
|
|
28
|
-
const { context, issue, log, state, branch } = job;
|
|
26
|
+
export async function setStatus(context, issue, label) {
|
|
29
27
|
const { repo, config, ports } = context;
|
|
30
|
-
|
|
31
|
-
const existing = await ports.findPr(repo, branch);
|
|
32
|
-
return (existing ??
|
|
33
|
-
ports.createPr(repo, branch, context.base, state.title ?? fallbackTitle(issue), `Closes #${issue.number}\n\nOpened by next-issue.`, config.draftPullRequest));
|
|
34
|
-
});
|
|
35
|
-
state.pr = pr;
|
|
36
|
-
await writeState(repo, state);
|
|
37
|
-
log.event('pull-request.ready', { pr }, 'quiet');
|
|
38
|
-
}
|
|
39
|
-
export async function setStatus(context, issue, pr, label) {
|
|
40
|
-
const { repo, config, ports } = context;
|
|
41
|
-
const managed = managedLabels(config);
|
|
42
|
-
await ports.setLabel(repo, 'issue', issue, label, managed);
|
|
43
|
-
if (pr !== undefined) {
|
|
44
|
-
await ports.setLabel(repo, 'pr', pr, label, managed);
|
|
45
|
-
}
|
|
28
|
+
await ports.setLabel(repo, 'issue', issue, label, managedLabels(config));
|
|
46
29
|
}
|
package/dist/open-job.mjs
CHANGED
|
@@ -7,7 +7,7 @@ export async function openJob(context, issue, log, state, start, handedOver) {
|
|
|
7
7
|
const { repo, config } = context;
|
|
8
8
|
const branch = state.branch;
|
|
9
9
|
await log.step('claim', { label: config.labels.inProgress }, async () => {
|
|
10
|
-
await setStatus(context, issue.number,
|
|
10
|
+
await setStatus(context, issue.number, config.labels.inProgress);
|
|
11
11
|
await writeState(repo, state);
|
|
12
12
|
});
|
|
13
13
|
const comments = await log.step('comments', {}, () => writerComments(context, log, issue.number));
|
package/dist/pending.mjs
CHANGED
|
@@ -30,9 +30,7 @@ async function savedIssue(context, number) {
|
|
|
30
30
|
}
|
|
31
31
|
try {
|
|
32
32
|
const { open, ...issue } = await ports.viewIssue(repo, number);
|
|
33
|
-
if (saved === 'broken' ||
|
|
34
|
-
open ||
|
|
35
|
-
(saved.pr !== undefined && (await ports.prMerged(repo, saved.pr)))) {
|
|
33
|
+
if (saved === 'broken' || open) {
|
|
36
34
|
return { open, issue };
|
|
37
35
|
}
|
|
38
36
|
return { open };
|
package/dist/poll.mjs
CHANGED
|
@@ -7,14 +7,3 @@ export const REAL_CLOCK = {
|
|
|
7
7
|
export function pause(clock, options, rest) {
|
|
8
8
|
return clock.sleep(Math.min(secondsToMs(options.intervalSeconds), rest));
|
|
9
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,6 +1,5 @@
|
|
|
1
1
|
import { runAgent } from './agents.mjs';
|
|
2
|
-
import { failedBaseLogs, waitForBaseChecks } from './base-checks.mjs';
|
|
3
|
-
import { failedCheckLogs, waitForChecks } from './checks.mjs';
|
|
2
|
+
import { failedBaseLogs, rerunFailedBase, waitForBaseChecks } from './base-checks.mjs';
|
|
4
3
|
import { run } from './exec.mjs';
|
|
5
4
|
import { commitAll } from './git-commit.mjs';
|
|
6
5
|
import { pushToBase, revertOnBase, squashOnto } from './git-land.mjs';
|
|
@@ -8,7 +7,6 @@ import { abortMerge, commitMerge, startMerge } from './git-merge.mjs';
|
|
|
8
7
|
import { deleteBranch, diff, discardChanges, disputeBranches, isDirty, latestSubject, push, resetToBase, revision, setAside, } from './git.mjs';
|
|
9
8
|
import { canWrite, closeIssue, commentOnIssue, issueComments, openBlockers, openIssues, reopenIssue, threadComments, viewIssue, } from './github.mjs';
|
|
10
9
|
import { setLabel } from './labels.mjs';
|
|
11
|
-
import { createPr, findPr, markPrReady, mergeCommit, mergePr, prConflicts, prMerged, } from './pull-requests.mjs';
|
|
12
10
|
import { detectSetupCommand } from './setup.mjs';
|
|
13
11
|
import { addWorktree, findWorktree, removeWorktree } from './worktree.mjs';
|
|
14
12
|
async function runSetup(command, cwd, timeoutMs) {
|
|
@@ -22,30 +20,23 @@ export const PORTS = {
|
|
|
22
20
|
commentOnIssue,
|
|
23
21
|
commitAll,
|
|
24
22
|
commitMerge,
|
|
25
|
-
createPr,
|
|
26
23
|
deleteBranch,
|
|
27
24
|
detectSetupCommand,
|
|
28
25
|
diff,
|
|
29
26
|
discardChanges,
|
|
30
27
|
disputeBranches,
|
|
31
28
|
failedBaseLogs,
|
|
32
|
-
failedCheckLogs,
|
|
33
|
-
findPr,
|
|
34
29
|
findWorktree,
|
|
35
30
|
isDirty,
|
|
36
31
|
issueComments,
|
|
37
32
|
latestSubject,
|
|
38
|
-
markPrReady,
|
|
39
|
-
mergeCommit,
|
|
40
|
-
mergePr,
|
|
41
33
|
openBlockers,
|
|
42
34
|
openIssues,
|
|
43
|
-
prConflicts,
|
|
44
|
-
prMerged,
|
|
45
35
|
push,
|
|
46
36
|
pushToBase,
|
|
47
37
|
removeWorktree,
|
|
48
38
|
reopenIssue,
|
|
39
|
+
rerunFailedBase,
|
|
49
40
|
resetToBase,
|
|
50
41
|
revertOnBase,
|
|
51
42
|
revision,
|
|
@@ -58,5 +49,4 @@ export const PORTS = {
|
|
|
58
49
|
threadComments,
|
|
59
50
|
viewIssue,
|
|
60
51
|
waitForBaseChecks,
|
|
61
|
-
waitForChecks,
|
|
62
52
|
};
|
package/dist/review.mjs
CHANGED
|
@@ -14,7 +14,7 @@ export async function reviewRound(job) {
|
|
|
14
14
|
if (exhausted) {
|
|
15
15
|
return exhausted;
|
|
16
16
|
}
|
|
17
|
-
await setStatus(context, issue.number,
|
|
17
|
+
await setStatus(context, issue.number, config.labels.inReview);
|
|
18
18
|
const earlier = history(state.reviewLog);
|
|
19
19
|
const verdict = parseVerdict(await runReviewer(job, earlier));
|
|
20
20
|
if (verdict === undefined) {
|
package/dist/serve.mjs
CHANGED
|
@@ -40,7 +40,7 @@ export async function startWorker(options) {
|
|
|
40
40
|
void close();
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
const start = (socket, root
|
|
43
|
+
const start = (socket, root) => {
|
|
44
44
|
const refusal = startRefusal(runs.get(root), restart);
|
|
45
45
|
if (refusal !== undefined) {
|
|
46
46
|
send(socket, { type: 'error', root, message: refusal });
|
|
@@ -54,7 +54,7 @@ export async function startWorker(options) {
|
|
|
54
54
|
};
|
|
55
55
|
broadcast(sockets, runs);
|
|
56
56
|
options
|
|
57
|
-
.runRepo(root,
|
|
57
|
+
.runRepo(root, parseArgs([]), runControls(run, update, () => void sendQuestions(root, () => sockets.clients)))
|
|
58
58
|
.then(() => update({ ...run.progress, status: endStatus(run) }), (error) => update({ ...run.progress, status: 'failed', error: message(error) }))
|
|
59
59
|
.finally(closeWhenIdle);
|
|
60
60
|
};
|
|
@@ -66,7 +66,7 @@ export async function startWorker(options) {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
else if (value.type === 'start') {
|
|
69
|
-
start(socket, value.root
|
|
69
|
+
start(socket, value.root);
|
|
70
70
|
}
|
|
71
71
|
else if (value.type === 'stop') {
|
|
72
72
|
if (requestStop(runs.get(value.root))) {
|
package/dist/state.mjs
CHANGED
|
@@ -46,11 +46,11 @@ function isState(value) {
|
|
|
46
46
|
typeof value.issue === 'number' &&
|
|
47
47
|
PHASES.includes(value.phase) &&
|
|
48
48
|
typeof value.branch === 'string' &&
|
|
49
|
-
isOptional(value.pr, 'number') &&
|
|
50
49
|
isOptional(value.title, 'string') &&
|
|
51
50
|
typeof value.ciFixes === 'number' &&
|
|
52
51
|
isOptional(value.commitFixes, 'number') &&
|
|
53
52
|
(value.landed === undefined || isLanded(value.landed)) &&
|
|
53
|
+
isOptional(value.rerun, 'string') &&
|
|
54
54
|
typeof value.reviewRounds === 'number' &&
|
|
55
55
|
Array.isArray(value.reviewLog) &&
|
|
56
56
|
value.reviewLog.every(isReviewRound) &&
|
package/dist/summary.mjs
CHANGED
|
@@ -18,9 +18,6 @@ export function count(reports, outcome) {
|
|
|
18
18
|
}
|
|
19
19
|
function issueLine(report) {
|
|
20
20
|
const parts = [`#${report.issue} ${report.outcome.padEnd(11)}`];
|
|
21
|
-
if (report.pr !== undefined) {
|
|
22
|
-
parts.push(`pr ${report.pr}`);
|
|
23
|
-
}
|
|
24
21
|
if (report.ciFixes > 0) {
|
|
25
22
|
parts.push(`ci fixes ${report.ciFixes}`);
|
|
26
23
|
}
|
package/package.json
CHANGED
package/dist/checks.mjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { pollChecks } from './check-poll.mjs';
|
|
2
|
-
import { failedWith, succeeded } from './exec.mjs';
|
|
3
|
-
import { ghRun } from './gh.mjs';
|
|
4
|
-
import { isAncestor } from './git.mjs';
|
|
5
|
-
import { prField } from './pull-requests.mjs';
|
|
6
|
-
import { runLogs } from './run-logs.mjs';
|
|
7
|
-
const CHECK_PENDING_CODE = 8;
|
|
8
|
-
const NO_CHECKS = /no checks reported/i;
|
|
9
|
-
function failedCheck(check) {
|
|
10
|
-
return check.bucket === 'fail';
|
|
11
|
-
}
|
|
12
|
-
async function readChecks(repo, pr) {
|
|
13
|
-
const result = await ghRun(repo, [
|
|
14
|
-
'pr',
|
|
15
|
-
'checks',
|
|
16
|
-
String(pr),
|
|
17
|
-
'--json',
|
|
18
|
-
'name,bucket,link,description',
|
|
19
|
-
]);
|
|
20
|
-
const output = result.stdout.trim();
|
|
21
|
-
if (output.length === 0) {
|
|
22
|
-
if (NO_CHECKS.test(result.stderr)) {
|
|
23
|
-
return 'none';
|
|
24
|
-
}
|
|
25
|
-
throw new Error(failedWith(`gh pr checks ${pr}`, result));
|
|
26
|
-
}
|
|
27
|
-
const checks = JSON.parse(output);
|
|
28
|
-
return checks.length === 0 ? 'none' : checks;
|
|
29
|
-
}
|
|
30
|
-
async function watchOnce(repo, pr, intervalSeconds, timeoutMs, show) {
|
|
31
|
-
const watch = await ghRun(repo, ['pr', 'checks', String(pr), '--watch', '--fail-fast', '--interval', String(intervalSeconds)], { show, timeoutMs });
|
|
32
|
-
if (watch.timedOut) {
|
|
33
|
-
return 'timeout';
|
|
34
|
-
}
|
|
35
|
-
if (succeeded(watch)) {
|
|
36
|
-
return 'pass';
|
|
37
|
-
}
|
|
38
|
-
if (watch.code === CHECK_PENDING_CODE) {
|
|
39
|
-
return 'pending';
|
|
40
|
-
}
|
|
41
|
-
const checks = await readChecks(repo, pr);
|
|
42
|
-
if (checks !== 'none' && checks.some(failedCheck)) {
|
|
43
|
-
return 'fail';
|
|
44
|
-
}
|
|
45
|
-
throw new Error(`gh pr checks ${pr} --watch failed with code ${watch.code} and no check failed: ${watch.stderr.trim()}`);
|
|
46
|
-
}
|
|
47
|
-
export function waitForChecks(repo, pr, options) {
|
|
48
|
-
return pollChecks({
|
|
49
|
-
head: () => prField(repo, pr, 'headRefOid'),
|
|
50
|
-
lags: (head) => options.head === undefined
|
|
51
|
-
? Promise.resolve(true)
|
|
52
|
-
: isAncestor(repo.root, head, options.head),
|
|
53
|
-
list: async () => ((await readChecks(repo, pr)) === 'none' ? 'none' : 'some'),
|
|
54
|
-
watch: (timeoutMs) => watchOnce(repo, pr, options.intervalSeconds, timeoutMs, options.show),
|
|
55
|
-
}, options);
|
|
56
|
-
}
|
|
57
|
-
export async function failedCheckLogs(repo, pr, maxChars) {
|
|
58
|
-
const checks = await readChecks(repo, pr);
|
|
59
|
-
if (checks === 'none') {
|
|
60
|
-
return 'The checks failed, but gh reports no check for the pull request.';
|
|
61
|
-
}
|
|
62
|
-
const failed = checks.filter(failedCheck).map((check) => ({
|
|
63
|
-
heading: `## ${check.name}\n${check.description}`,
|
|
64
|
-
runId: /\/actions\/runs\/(\d+)/.exec(check.link)?.[1],
|
|
65
|
-
}));
|
|
66
|
-
return runLogs(repo, failed, maxChars);
|
|
67
|
-
}
|
package/dist/pull-requests.mjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { optionalFlag } from './exec.mjs';
|
|
2
|
-
import { gh, ghJson, ghOnce, ghSucceeds, viewJson } from './gh.mjs';
|
|
3
|
-
import { pollUntil, REAL_CLOCK } from './poll.mjs';
|
|
4
|
-
export async function findPr(repo, branch) {
|
|
5
|
-
const parsed = await ghJson(repo, [
|
|
6
|
-
'pr',
|
|
7
|
-
'list',
|
|
8
|
-
'--head',
|
|
9
|
-
branch,
|
|
10
|
-
'--state',
|
|
11
|
-
'open',
|
|
12
|
-
'--json',
|
|
13
|
-
'number',
|
|
14
|
-
]);
|
|
15
|
-
return parsed[0]?.number;
|
|
16
|
-
}
|
|
17
|
-
export async function createPr(repo, branch, base, title, body, draft) {
|
|
18
|
-
const created = await ghOnce(repo, [
|
|
19
|
-
'pr',
|
|
20
|
-
'create',
|
|
21
|
-
'--head',
|
|
22
|
-
branch,
|
|
23
|
-
'--base',
|
|
24
|
-
base,
|
|
25
|
-
'--title',
|
|
26
|
-
title,
|
|
27
|
-
'--body',
|
|
28
|
-
body,
|
|
29
|
-
...optionalFlag(draft, '--draft'),
|
|
30
|
-
]);
|
|
31
|
-
const number = prNumber(created) ?? (await findPr(repo, branch));
|
|
32
|
-
if (number === undefined) {
|
|
33
|
-
throw new Error(`The pull request for ${branch} was not found after creation.`);
|
|
34
|
-
}
|
|
35
|
-
return number;
|
|
36
|
-
}
|
|
37
|
-
export function prNumber(output) {
|
|
38
|
-
const match = /\/pull\/(\d+)\b/.exec(output);
|
|
39
|
-
return match === null ? undefined : Number(match[1]);
|
|
40
|
-
}
|
|
41
|
-
export async function prField(repo, pr, field) {
|
|
42
|
-
return gh(repo, ['pr', 'view', String(pr), '--json', field, '--jq', `.${field}`]);
|
|
43
|
-
}
|
|
44
|
-
export async function markPrReady(repo, pr) {
|
|
45
|
-
return ghSucceeds(repo, ['pr', 'ready', String(pr)]);
|
|
46
|
-
}
|
|
47
|
-
export async function mergePr(repo, pr) {
|
|
48
|
-
return ghSucceeds(repo, ['pr', 'merge', String(pr), '--squash', '--delete-branch']);
|
|
49
|
-
}
|
|
50
|
-
export async function prConflicts(repo, pr, options, clock = REAL_CLOCK) {
|
|
51
|
-
const mergeable = await pollUntil(options, clock, () => prField(repo, pr, 'mergeable'), (value) => value !== 'UNKNOWN');
|
|
52
|
-
return mergeable === 'CONFLICTING';
|
|
53
|
-
}
|
|
54
|
-
export async function prMerged(repo, pr) {
|
|
55
|
-
return (await prField(repo, pr, 'state')) === 'MERGED';
|
|
56
|
-
}
|
|
57
|
-
export async function mergeCommit(repo, pr, options, clock = REAL_CLOCK) {
|
|
58
|
-
const view = await pollUntil(options, clock, () => viewJson(repo, 'pr', pr, 'state,mergeCommit'), (value) => (value.state === 'MERGED' && !!value.mergeCommit?.oid) || value.state === 'CLOSED');
|
|
59
|
-
return (view.state === 'MERGED' && view.mergeCommit?.oid) || undefined;
|
|
60
|
-
}
|