next-issue 2.21.1 → 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 -22
- 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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { stateDir } from './state.mjs';
|
|
3
|
+
export function workerPaths(root) {
|
|
4
|
+
const dir = stateDir(root);
|
|
5
|
+
return {
|
|
6
|
+
socketPath: join(dir, 'worker.sock'),
|
|
7
|
+
lockPath: join(dir, 'worker.lock'),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function checkSocketPath(path, platform = process.platform) {
|
|
11
|
+
const size = platform === 'linux' ? 108 : 104;
|
|
12
|
+
const length = Buffer.byteLength(path);
|
|
13
|
+
if (length >= size) {
|
|
14
|
+
throw new Error(`the socket path ${path} is too long for this system: ${length} bytes, at most ${size - 1}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { wakeableSleep } from './durations.mjs';
|
|
2
|
+
import { applyEvent } from './progress.mjs';
|
|
3
|
+
export function active(run) {
|
|
4
|
+
return run?.progress.status === 'running' || run?.progress.status === 'stopping';
|
|
5
|
+
}
|
|
6
|
+
export function endStatus(run) {
|
|
7
|
+
if (run.stop) {
|
|
8
|
+
return 'stopped';
|
|
9
|
+
}
|
|
10
|
+
return run.progress.error === undefined ? 'finished' : 'failed';
|
|
11
|
+
}
|
|
12
|
+
export function startRefusal(run, restart) {
|
|
13
|
+
if (active(run)) {
|
|
14
|
+
return 'a run is going in this repository already';
|
|
15
|
+
}
|
|
16
|
+
if (restart) {
|
|
17
|
+
return 'the worker is restarting, try again soon';
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
export function runsMessage(runs) {
|
|
22
|
+
return {
|
|
23
|
+
type: 'runs',
|
|
24
|
+
runs: Object.fromEntries([...runs].map(([root, run]) => [root, run.progress])),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function endsIssue(record) {
|
|
28
|
+
return record['kind'] === 'issue.end' || record['kind'] === 'issue.error';
|
|
29
|
+
}
|
|
30
|
+
export function requestStop(run) {
|
|
31
|
+
if (run === undefined || run.progress.status !== 'running') {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
run.stop = true;
|
|
35
|
+
run.wake?.();
|
|
36
|
+
run.progress = { ...run.progress, status: 'stopping' };
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
function runInterrupts(run) {
|
|
40
|
+
return {
|
|
41
|
+
afterIssue: () => run.stop,
|
|
42
|
+
afterRound: () => run.stop,
|
|
43
|
+
sleep: (ms) => wakeableSleep(run, ms, run.stop),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function runControls(run, update, issueEnded) {
|
|
47
|
+
return {
|
|
48
|
+
interrupts: runInterrupts(run),
|
|
49
|
+
onEvent: (record) => {
|
|
50
|
+
update(applyEvent(run.progress, record));
|
|
51
|
+
if (endsIssue(record)) {
|
|
52
|
+
issueEnded();
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { rm } from 'node:fs/promises';
|
|
2
|
+
import { send } from './questions.mjs';
|
|
3
|
+
import { runsMessage } from './worker-run.mjs';
|
|
4
|
+
export function parseMessage(text) {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(text);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function broadcast(sockets, runs) {
|
|
13
|
+
const value = runsMessage(runs);
|
|
14
|
+
for (const socket of sockets.clients) {
|
|
15
|
+
send(socket, value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function listen(server, path) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
server.once('error', reject);
|
|
21
|
+
const umask = process.umask(0o177);
|
|
22
|
+
try {
|
|
23
|
+
server.listen(path, () => {
|
|
24
|
+
server.off('error', reject);
|
|
25
|
+
resolve();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
process.umask(umask);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function whenClosed(close) {
|
|
34
|
+
return new Promise((resolve) => close(() => resolve()));
|
|
35
|
+
}
|
|
36
|
+
export async function shutdown(server, sockets, paths) {
|
|
37
|
+
for (const socket of sockets.clients) {
|
|
38
|
+
socket.terminate();
|
|
39
|
+
}
|
|
40
|
+
await whenClosed((done) => sockets.close(done));
|
|
41
|
+
await whenClosed((done) => server.close(done));
|
|
42
|
+
await rm(paths.socketPath, { force: true });
|
|
43
|
+
await rm(paths.lockPath, { force: true });
|
|
44
|
+
}
|
|
45
|
+
export function closer(stop) {
|
|
46
|
+
let finish = () => undefined;
|
|
47
|
+
const closed = new Promise((resolve) => {
|
|
48
|
+
finish = resolve;
|
|
49
|
+
});
|
|
50
|
+
let closing;
|
|
51
|
+
const close = () => {
|
|
52
|
+
closing ??= stop().then(finish);
|
|
53
|
+
return closing;
|
|
54
|
+
};
|
|
55
|
+
return { closed, close };
|
|
56
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { minutesToMs } from './durations.mjs';
|
|
2
|
+
import { succeeded } from './exec.mjs';
|
|
3
|
+
import { escalateAndFinish } from './handover.mjs';
|
|
4
|
+
import { ROUND_CONTINUE } from './job.mjs';
|
|
5
|
+
import { keepTail } from './text.mjs';
|
|
6
|
+
export async function setUp(job) {
|
|
7
|
+
const { context, log, worktree } = job;
|
|
8
|
+
const { config, ports } = context;
|
|
9
|
+
const setupCommand = config.setupCommand ?? (await ports.detectSetupCommand(worktree));
|
|
10
|
+
if (setupCommand === undefined) {
|
|
11
|
+
return ROUND_CONTINUE;
|
|
12
|
+
}
|
|
13
|
+
const setup = await log.step('setup', { cmd: setupCommand, found: config.setupCommand === undefined }, () => ports.runSetup(setupCommand, worktree, minutesToMs(config.setupTimeoutMinutes)));
|
|
14
|
+
if (succeeded(setup)) {
|
|
15
|
+
return ROUND_CONTINUE;
|
|
16
|
+
}
|
|
17
|
+
return setupFailed(job, setup);
|
|
18
|
+
}
|
|
19
|
+
async function setupFailed(job, setup) {
|
|
20
|
+
const late = setup.timedOut === true;
|
|
21
|
+
job.log.event('setup.fail', { code: setup.code, timedOut: late, stderr: keepTail(setup.stderr.trim(), 2000) }, 'quiet');
|
|
22
|
+
return escalateAndFinish(job, late
|
|
23
|
+
? `The setup command did not finish in ${job.context.config.setupTimeoutMinutes} minutes.`
|
|
24
|
+
: 'The setup command failed in the worktree.', late ? 'setup timeout' : 'setup failed');
|
|
25
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { currentBranch, discardChanges, git, isAncestor, remoteRef, succeeds, } from './git.mjs';
|
|
3
|
+
export const WORKTREE_DIR = '.worktrees';
|
|
4
|
+
function worktreePath(repo, issue) {
|
|
5
|
+
return join(repo.root, WORKTREE_DIR, String(issue));
|
|
6
|
+
}
|
|
7
|
+
export async function addWorktree(repo, issue, branch, base, remote, start) {
|
|
8
|
+
const upstream = remoteRef(remote, branch);
|
|
9
|
+
const remoteBase = remoteRef(remote, base);
|
|
10
|
+
await git(repo.root, ['fetch', remote]);
|
|
11
|
+
const baseUpdated = await updateBase(repo, base, remote);
|
|
12
|
+
await git(repo.root, ['worktree', 'prune']);
|
|
13
|
+
const pushed = await hasBranch(repo, upstream, '--remotes');
|
|
14
|
+
const existing = await findWorktree(repo, branch);
|
|
15
|
+
const path = existing ?? worktreePath(repo, issue);
|
|
16
|
+
const target = pushed ? upstream : remoteBase;
|
|
17
|
+
if (existing === undefined) {
|
|
18
|
+
const args = !start && (await hasWork(repo, branch, pushed, remoteBase))
|
|
19
|
+
? ['worktree', 'add', path, branch]
|
|
20
|
+
: ['worktree', 'add', '-B', branch, path, target];
|
|
21
|
+
await git(repo.root, args);
|
|
22
|
+
}
|
|
23
|
+
else if (start) {
|
|
24
|
+
await discardChanges(path, target);
|
|
25
|
+
}
|
|
26
|
+
if (pushed) {
|
|
27
|
+
await succeeds(path, ['merge', '--ff-only', upstream]);
|
|
28
|
+
}
|
|
29
|
+
return { path, baseUpdated };
|
|
30
|
+
}
|
|
31
|
+
async function hasWork(repo, branch, pushed, base) {
|
|
32
|
+
if (!(await hasBranch(repo, branch))) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return pushed || !(await isAncestor(repo.root, branch, base));
|
|
36
|
+
}
|
|
37
|
+
async function hasBranch(repo, name, ...flags) {
|
|
38
|
+
const list = await git(repo.root, ['branch', '--list', ...flags, name]);
|
|
39
|
+
return list.length > 0;
|
|
40
|
+
}
|
|
41
|
+
async function updateBase(repo, base, remote) {
|
|
42
|
+
const remoteBase = remoteRef(remote, base);
|
|
43
|
+
const args = (await currentBranch(repo.root)) === base
|
|
44
|
+
? ['merge', '--ff-only', remoteBase]
|
|
45
|
+
: ['fetch', '.', `${remoteBase}:${base}`];
|
|
46
|
+
return succeeds(repo.root, args);
|
|
47
|
+
}
|
|
48
|
+
export async function findWorktree(repo, branch) {
|
|
49
|
+
const list = await git(repo.root, ['worktree', 'list', '--porcelain']);
|
|
50
|
+
const entry = list
|
|
51
|
+
.split('\n\n')
|
|
52
|
+
.map((block) => block.split('\n'))
|
|
53
|
+
.find((lines) => lines.includes(`branch refs/heads/${branch}`));
|
|
54
|
+
return entry?.find((line) => line.startsWith('worktree '))?.slice('worktree '.length);
|
|
55
|
+
}
|
|
56
|
+
export async function removeWorktree(repo, path) {
|
|
57
|
+
return succeeds(repo.root, ['worktree', 'remove', path]);
|
|
58
|
+
}
|
package/package.json
CHANGED
package/dist/merge.mjs
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { fixRound } from './fix.mjs';
|
|
2
|
-
import { escalate, finish } from './handover.mjs';
|
|
3
|
-
import { openPr, setStatus } from './job.mjs';
|
|
4
|
-
import { writeState } from './state.mjs';
|
|
5
|
-
export async function afterMerge(job) {
|
|
6
|
-
const { context, issue, state } = job;
|
|
7
|
-
const watched = await watchBase(job);
|
|
8
|
-
if (watched.done) {
|
|
9
|
-
return { done: true, report: watched.report };
|
|
10
|
-
}
|
|
11
|
-
if (watched.fixed) {
|
|
12
|
-
return { done: false };
|
|
13
|
-
}
|
|
14
|
-
await setStatus(context, issue.number, state.pr, context.config.labels.done);
|
|
15
|
-
return { done: true, report: await finish(job, 'done') };
|
|
16
|
-
}
|
|
17
|
-
async function watchBase(job) {
|
|
18
|
-
const { context, log, state, worktree } = job;
|
|
19
|
-
const { repo, config, ports } = context;
|
|
20
|
-
const sha = await ports.mergeCommit(repo, state.pr, {
|
|
21
|
-
intervalSeconds: config.checkIntervalSeconds,
|
|
22
|
-
timeoutMs: config.checkTimeoutMinutes * 60_000,
|
|
23
|
-
});
|
|
24
|
-
if (sha === undefined) {
|
|
25
|
-
await escalate(job, 'The pull request did not merge in time, or it closed without a merge.');
|
|
26
|
-
return { done: true, report: await finish(job, 'needs-human', 'not merged') };
|
|
27
|
-
}
|
|
28
|
-
const checks = await log.step('main-checks', { pr: state.pr, sha }, () => ports.waitForBaseChecks(repo, sha, {
|
|
29
|
-
intervalSeconds: config.checkIntervalSeconds,
|
|
30
|
-
graceMs: config.checkGraceSeconds * 1000,
|
|
31
|
-
timeoutMs: config.checkTimeoutMinutes * 60_000,
|
|
32
|
-
}));
|
|
33
|
-
log.event('main-checks.state', { state: checks });
|
|
34
|
-
if (checks === 'pass' || checks === 'none') {
|
|
35
|
-
return { done: false, fixed: false };
|
|
36
|
-
}
|
|
37
|
-
job.mainBroken = true;
|
|
38
|
-
if (checks !== 'fail') {
|
|
39
|
-
await escalate(job, 'The checks on main did not finish in time.');
|
|
40
|
-
return { done: true, report: await finish(job, 'needs-human', 'main checks timeout') };
|
|
41
|
-
}
|
|
42
|
-
if (state.ciFixes >= config.maxCiFixes) {
|
|
43
|
-
await escalate(job, `The checks on main failed and the limit of ${config.maxCiFixes} check fixes was reached.`);
|
|
44
|
-
return { done: true, report: await finish(job, 'needs-human', 'check budget') };
|
|
45
|
-
}
|
|
46
|
-
await ports.resetToBase(worktree, context.base, config.remote);
|
|
47
|
-
state.ciFixes += 1;
|
|
48
|
-
state.baseFix = { sha, head: await ports.revision(worktree) };
|
|
49
|
-
await writeState(repo, state);
|
|
50
|
-
return fixBase(job);
|
|
51
|
-
}
|
|
52
|
-
export async function fixBase(job) {
|
|
53
|
-
const { context, issue, log, state } = job;
|
|
54
|
-
const { repo, config, ports } = context;
|
|
55
|
-
const { sha, head } = state.baseFix;
|
|
56
|
-
const logs = await ports.failedBaseLogs(repo, sha, config.logMaxChars);
|
|
57
|
-
log.event('main-checks.logs', { chars: logs.length });
|
|
58
|
-
const fix = await fixRound(job, 'The checks on main failed after the merge.', logs, [], 'checks', true, head);
|
|
59
|
-
if (!fix.committed) {
|
|
60
|
-
const note = fix.unrelated;
|
|
61
|
-
await escalate(job, note === undefined
|
|
62
|
-
? 'The fixer added no commit for the failed checks on main.'
|
|
63
|
-
: `The checks on main fail for a reason this change did not cause: ${note}`);
|
|
64
|
-
return {
|
|
65
|
-
done: true,
|
|
66
|
-
report: await finish(job, 'needs-human', note === undefined ? 'no fix commit' : 'unrelated failure'),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
await ports.reopenIssue(repo, issue.number);
|
|
70
|
-
state.reviewRounds = 0;
|
|
71
|
-
state.reviewLog = [];
|
|
72
|
-
state.baseFix = undefined;
|
|
73
|
-
await openPr(job);
|
|
74
|
-
return { done: false, fixed: true };
|
|
75
|
-
}
|