next-issue 6.0.2 → 6.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 +13 -4
- package/dist/agents.mjs +2 -1
- package/dist/children.mjs +44 -13
- package/dist/exec.mjs +4 -4
- package/dist/git.mjs +3 -0
- package/dist/handover.mjs +4 -0
- package/dist/land.mjs +9 -1
- package/dist/pipeline.mjs +10 -5
- package/dist/ports.mjs +2 -1
- package/dist/protocol.mjs +1 -0
- package/dist/serve.mjs +14 -8
- package/dist/worker-run.mjs +21 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -128,8 +128,9 @@ the run handles one issue. For each issue:
|
|
|
128
128
|
budget runs out, the harness reverts every commit of the change on the
|
|
129
129
|
base branch, pushes the revert and hands the issue to a person. A resume
|
|
130
130
|
that stopped while the checks of a landed commit ran waits for them
|
|
131
|
-
again,
|
|
132
|
-
|
|
131
|
+
again, even when more commits landed on the base since, and a fix that
|
|
132
|
+
was committed but not landed lands first. A problem that the reviewer
|
|
133
|
+
leaves out of the findings thus gets an approval: only the findings count.
|
|
133
134
|
8. With an open finding, run the fixer agent and go to step 5 again. The
|
|
134
135
|
budget is `maxReviewRounds`. A fixer that holds every finding to be wrong
|
|
135
136
|
changes nothing and gives its reason instead. The reason goes on the issue
|
|
@@ -558,8 +559,16 @@ affect another. The worker:
|
|
|
558
559
|
a newer one. When the client adds an `"id"` to its message, the list that
|
|
559
560
|
answers it carries the same `id` and is read after the message arrived. When the list cannot be read, the client gets
|
|
560
561
|
`{ "type": "questions-error", "root": "<path>", "message": "<text>" }`;
|
|
561
|
-
- stops a run
|
|
562
|
-
after
|
|
562
|
+
- stops a run when a client sends
|
|
563
|
+
`{ "type": "stop", "root": "<path>", "after": "issue" | "round" | "now" }`.
|
|
564
|
+
With no `after`, it stops after `issue`. `issue` works like a first
|
|
565
|
+
`Ctrl-C`: no new claim or hunt, and the held issues and a going hunt finish.
|
|
566
|
+
`round` works like a second `Ctrl-C`: each running issue stops after its
|
|
567
|
+
current round, with the state kept, and a going hunt ends first. `now`
|
|
568
|
+
stops every agent, command and hunt of the run at once, and each running
|
|
569
|
+
issue ends as `stopped` with its state and labels kept; the worker keeps
|
|
570
|
+
running. A later point than one already asked for changes nothing, and an
|
|
571
|
+
earlier one replaces it. An unknown `after` gets an `error` message;
|
|
563
572
|
- exits, and removes its socket and lock files, when no run is going and no
|
|
564
573
|
client is connected, or when no client connects in the 30 seconds after it
|
|
565
574
|
starts;
|
package/dist/agents.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getAgentDir, } from '@earendil-works/pi-coding-agent';
|
|
2
2
|
import { openSession } from './agent-session.mjs';
|
|
3
|
-
import { onStop } from './children.mjs';
|
|
3
|
+
import { onStop, refuseWhenStopped } from './children.mjs';
|
|
4
4
|
import { deadline, elapsedMs } from './durations.mjs';
|
|
5
5
|
import { isRecord } from './records.mjs';
|
|
6
6
|
import { emptyUsage } from './usage.mjs';
|
|
@@ -21,6 +21,7 @@ export async function runAgent(recorder, request) {
|
|
|
21
21
|
const unsubscribe = session.subscribe((event) => observe(log, event));
|
|
22
22
|
const release = onStop(() => void session.abort());
|
|
23
23
|
try {
|
|
24
|
+
refuseWhenStopped();
|
|
24
25
|
await session.bindExtensions({});
|
|
25
26
|
await session.prompt(request.prompt, { expandPromptTemplates: false });
|
|
26
27
|
if (timer.timedOut()) {
|
package/dist/children.mjs
CHANGED
|
@@ -1,38 +1,69 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
1
2
|
const groups = new Set();
|
|
2
3
|
const stoppers = new Set();
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return ()
|
|
4
|
+
const current = new AsyncLocalStorage();
|
|
5
|
+
export function runChildren() {
|
|
6
|
+
return { groups: new Set(), stoppers: new Set(), stopped: false };
|
|
6
7
|
}
|
|
7
|
-
export function
|
|
8
|
-
|
|
8
|
+
export function withRunChildren(children, body) {
|
|
9
|
+
return current.run(children, body);
|
|
10
|
+
}
|
|
11
|
+
function stopAll(children, signal) {
|
|
12
|
+
for (const stopper of children.stoppers) {
|
|
9
13
|
stopper();
|
|
10
14
|
}
|
|
11
|
-
stoppers.clear();
|
|
12
|
-
for (const pid of groups) {
|
|
15
|
+
children.stoppers.clear();
|
|
16
|
+
for (const pid of children.groups) {
|
|
13
17
|
try {
|
|
14
18
|
process.kill(-pid, signal);
|
|
15
19
|
}
|
|
16
20
|
catch { }
|
|
17
21
|
}
|
|
18
|
-
groups.clear();
|
|
22
|
+
children.groups.clear();
|
|
23
|
+
}
|
|
24
|
+
export function stopRunChildren(children) {
|
|
25
|
+
children.stopped = true;
|
|
26
|
+
stopAll(children, 'SIGINT');
|
|
27
|
+
}
|
|
28
|
+
export function runStopped() {
|
|
29
|
+
return current.getStore()?.stopped === true;
|
|
30
|
+
}
|
|
31
|
+
export function refuseWhenStopped() {
|
|
32
|
+
if (runStopped()) {
|
|
33
|
+
throw new Error('The run stopped.');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function onStop(stopper) {
|
|
37
|
+
const children = current.getStore();
|
|
38
|
+
stoppers.add(stopper);
|
|
39
|
+
children?.stoppers.add(stopper);
|
|
40
|
+
return () => {
|
|
41
|
+
stoppers.delete(stopper);
|
|
42
|
+
children?.stoppers.delete(stopper);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function stopChildren(signal) {
|
|
46
|
+
stopAll({ groups, stoppers }, signal);
|
|
19
47
|
process.off('SIGTERM', onTerminate);
|
|
20
48
|
process.kill(process.pid, signal);
|
|
21
49
|
}
|
|
22
50
|
const onTerminate = () => stopChildren('SIGTERM');
|
|
23
51
|
export function watch(pid) {
|
|
24
52
|
if (pid === undefined) {
|
|
25
|
-
return;
|
|
53
|
+
return () => undefined;
|
|
26
54
|
}
|
|
27
55
|
if (groups.size === 0) {
|
|
28
56
|
process.on('SIGTERM', onTerminate);
|
|
29
57
|
}
|
|
30
58
|
groups.add(pid);
|
|
59
|
+
const children = current.getStore();
|
|
60
|
+
children?.groups.add(pid);
|
|
61
|
+
return () => {
|
|
62
|
+
children?.groups.delete(pid);
|
|
63
|
+
unwatch(pid);
|
|
64
|
+
};
|
|
31
65
|
}
|
|
32
|
-
|
|
33
|
-
if (pid === undefined) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
66
|
+
function unwatch(pid) {
|
|
36
67
|
groups.delete(pid);
|
|
37
68
|
if (groups.size === 0) {
|
|
38
69
|
process.off('SIGTERM', onTerminate);
|
package/dist/exec.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
|
-
import { killTree,
|
|
3
|
+
import { killTree, refuseWhenStopped, watch } from './children.mjs';
|
|
4
4
|
import { deadline, elapsedMs, minutesToMs } from './durations.mjs';
|
|
5
5
|
import { keepTail } from './text.mjs';
|
|
6
6
|
let observer;
|
|
@@ -60,15 +60,15 @@ export function run(command, args, options = {}) {
|
|
|
60
60
|
const started = Date.now();
|
|
61
61
|
const limit = options.timeoutMs ?? defaultTimeout.getStore() ?? DEFAULT_TIMEOUT_MS;
|
|
62
62
|
return new Promise((resolve, reject) => {
|
|
63
|
+
refuseWhenStopped();
|
|
63
64
|
const child = spawnChild(command, args, options);
|
|
64
|
-
const
|
|
65
|
-
watch(pid);
|
|
65
|
+
const unwatch = watch(child.pid);
|
|
66
66
|
const output = collect(child, options);
|
|
67
67
|
const timer = deadline(limit, () => killTree(child));
|
|
68
68
|
let done = false;
|
|
69
69
|
const release = () => {
|
|
70
70
|
timer.clear();
|
|
71
|
-
unwatch(
|
|
71
|
+
unwatch();
|
|
72
72
|
};
|
|
73
73
|
const settle = (code) => {
|
|
74
74
|
release();
|
package/dist/git.mjs
CHANGED
|
@@ -88,6 +88,9 @@ export async function currentBranch(cwd) {
|
|
|
88
88
|
export async function isAncestor(cwd, ancestor, descendant) {
|
|
89
89
|
return succeeds(cwd, ['merge-base', '--is-ancestor', ancestor, descendant]);
|
|
90
90
|
}
|
|
91
|
+
export async function isLanded(cwd, base, remote) {
|
|
92
|
+
return isAncestor(cwd, 'HEAD', remoteRef(remote, base));
|
|
93
|
+
}
|
|
91
94
|
export async function deleteBranch(repo, branch) {
|
|
92
95
|
return succeeds(repo.root, ['branch', '-D', branch]);
|
|
93
96
|
}
|
package/dist/handover.mjs
CHANGED
|
@@ -30,6 +30,10 @@ export function stop(job) {
|
|
|
30
30
|
job.log.event('issue.stop', { phase: job.state.phase }, 'quiet');
|
|
31
31
|
return jobReport(job, 'stopped');
|
|
32
32
|
}
|
|
33
|
+
export function stopNow(log, issue, state, started) {
|
|
34
|
+
log.event('issue.stop', { phase: state.phase }, 'quiet');
|
|
35
|
+
return issueReport(issue.number, 'stopped', state, started);
|
|
36
|
+
}
|
|
33
37
|
function jobReport(job, outcome, reason) {
|
|
34
38
|
return issueReport(job.issue.number, outcome, job.state, job.started, reason);
|
|
35
39
|
}
|
package/dist/land.mjs
CHANGED
|
@@ -10,7 +10,7 @@ export function landApproved(job) {
|
|
|
10
10
|
}
|
|
11
11
|
export function resumeLanding(job, sha) {
|
|
12
12
|
return landing(job, async () => {
|
|
13
|
-
if (
|
|
13
|
+
if (await holdsUnlandedFix(job, sha)) {
|
|
14
14
|
job.mainBroken = true;
|
|
15
15
|
job.repairing = true;
|
|
16
16
|
return landLoop(job);
|
|
@@ -22,6 +22,14 @@ export function resumeLanding(job, sha) {
|
|
|
22
22
|
return gate.fixed ? landLoop(job) : finishDone(job);
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
+
async function holdsUnlandedFix(job, sha) {
|
|
26
|
+
const { context, worktree } = job;
|
|
27
|
+
const { ports, config, base } = context;
|
|
28
|
+
if ((await ports.revision(worktree)) === sha) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return !(await ports.isLanded(worktree, base, config.remote));
|
|
32
|
+
}
|
|
25
33
|
function landing(job, work) {
|
|
26
34
|
return oneAtATime(`${job.context.repo.root}#land`, work);
|
|
27
35
|
}
|
package/dist/pipeline.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { enterReview } from './enter-review.mjs';
|
|
2
2
|
import { branchName } from './git.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { runStopped } from './children.mjs';
|
|
4
|
+
import { claimedError, stop, stopNow } from './handover.mjs';
|
|
4
5
|
import { implement } from './implement.mjs';
|
|
5
6
|
import { openJob } from './open-job.mjs';
|
|
6
7
|
import { reviewRound } from './review.mjs';
|
|
@@ -24,14 +25,18 @@ export async function processIssue(context, issue) {
|
|
|
24
25
|
}
|
|
25
26
|
log.event('issue.start', { title: issue.title, createdAt: issue.createdAt }, 'quiet');
|
|
26
27
|
const state = startState(context, issue, saved);
|
|
28
|
+
let report;
|
|
27
29
|
try {
|
|
28
|
-
|
|
29
|
-
log.event('issue.end', { outcome: report.outcome, reason: report.reason, ms: report.ms }, 'quiet');
|
|
30
|
-
return report;
|
|
30
|
+
report = await work(context, issue, log, state, saved === undefined, saved?.handedOver === true);
|
|
31
31
|
}
|
|
32
32
|
catch (error) {
|
|
33
|
-
|
|
33
|
+
if (!runStopped()) {
|
|
34
|
+
return claimedError(context, log, issue, state, error, started);
|
|
35
|
+
}
|
|
36
|
+
report = stopNow(log, issue, state, started);
|
|
34
37
|
}
|
|
38
|
+
log.event('issue.end', { outcome: report.outcome, reason: report.reason, ms: report.ms }, 'quiet');
|
|
39
|
+
return report;
|
|
35
40
|
}
|
|
36
41
|
function startState(context, issue, saved) {
|
|
37
42
|
if (saved === undefined) {
|
package/dist/ports.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { run } from './exec.mjs';
|
|
|
4
4
|
import { commitAll } from './git-commit.mjs';
|
|
5
5
|
import { pushToBase, revertOnBase, squashOnto } from './git-land.mjs';
|
|
6
6
|
import { abortMerge, commitMerge, startMerge } from './git-merge.mjs';
|
|
7
|
-
import { deleteBranch, diff, discardChanges, disputeBranches, isDirty, latestSubject, push, resetToBase, revision, setAside, } from './git.mjs';
|
|
7
|
+
import { deleteBranch, diff, discardChanges, disputeBranches, isDirty, isLanded, latestSubject, push, resetToBase, revision, setAside, } from './git.mjs';
|
|
8
8
|
import { canWrite, closeIssue, commentOnIssue, issueComments, openBlockers, openIssues, reopenIssue, threadComments, viewIssue, } from './github.mjs';
|
|
9
9
|
import { huntWorktree } from './hunt.mjs';
|
|
10
10
|
import { ensureLabel, setLabel } from './labels.mjs';
|
|
@@ -32,6 +32,7 @@ export const PORTS = {
|
|
|
32
32
|
findWorktree,
|
|
33
33
|
huntWorktree,
|
|
34
34
|
isDirty,
|
|
35
|
+
isLanded,
|
|
35
36
|
issueComments,
|
|
36
37
|
latestSubject,
|
|
37
38
|
openBlockers,
|
package/dist/protocol.mjs
CHANGED
package/dist/serve.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { createServer } from 'node:http';
|
|
|
4
4
|
import { dirname } from 'node:path';
|
|
5
5
|
import { WebSocketServer } from 'ws';
|
|
6
6
|
import { parseStartArgs } from './args.mjs';
|
|
7
|
-
import { stopChildren } from './children.mjs';
|
|
7
|
+
import { stopChildren, withRunChildren } from './children.mjs';
|
|
8
8
|
import { message } from './errors.mjs';
|
|
9
9
|
import { lock } from './lock.mjs';
|
|
10
10
|
import { startProgress } from './progress.mjs';
|
|
@@ -13,7 +13,7 @@ import { listQuestions, questionSender, send } from './questions.mjs';
|
|
|
13
13
|
import { runRepo } from './run.mjs';
|
|
14
14
|
import { packageVersion } from './version.mjs';
|
|
15
15
|
import { checkSocketPath, workerPaths } from './worker-paths.mjs';
|
|
16
|
-
import { active, endStatus, requestStop, runControls, runsMessage, startRefusal, } from './worker-run.mjs';
|
|
16
|
+
import { active, endStatus, newRun, requestStop, runControls, runsMessage, startRefusal, stopPoint, } from './worker-run.mjs';
|
|
17
17
|
import { broadcast, closer, listen, parseMessage, shutdown, } from './worker-server.mjs';
|
|
18
18
|
const LOCK_WAIT_MS = 5_000;
|
|
19
19
|
const IDLE_MS = 30_000;
|
|
@@ -54,18 +54,26 @@ export async function startWorker(options) {
|
|
|
54
54
|
send(socket, { type: 'error', root, message: message(error) });
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
-
const run =
|
|
57
|
+
const run = newRun(startProgress());
|
|
58
58
|
runs.set(root, run);
|
|
59
59
|
const update = (next) => {
|
|
60
60
|
run.progress = next;
|
|
61
61
|
broadcast(sockets, runs);
|
|
62
62
|
};
|
|
63
63
|
broadcast(sockets, runs);
|
|
64
|
-
options
|
|
65
|
-
.runRepo(root, args, runControls(run, update, () => void sendQuestions(root, () => sockets.clients)))
|
|
64
|
+
withRunChildren(run.children, () => options.runRepo(root, args, runControls(run, update, () => void sendQuestions(root, () => sockets.clients))))
|
|
66
65
|
.then(() => update({ ...run.progress, status: endStatus(run) }), (error) => update({ ...run.progress, status: 'failed', error: message(error) }))
|
|
67
66
|
.finally(closeWhenIdle);
|
|
68
67
|
};
|
|
68
|
+
const stop = (socket, root, after) => {
|
|
69
|
+
const point = stopPoint(after);
|
|
70
|
+
if (point === undefined) {
|
|
71
|
+
send(socket, { type: 'error', root, message: `stop does not take --after ${String(after)}` });
|
|
72
|
+
}
|
|
73
|
+
else if (requestStop(runs.get(root), point)) {
|
|
74
|
+
broadcast(sockets, runs);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
69
77
|
const receive = (socket, value) => {
|
|
70
78
|
if (value.type === 'hello') {
|
|
71
79
|
if (isNewer(value.version, options.version)) {
|
|
@@ -77,9 +85,7 @@ export async function startWorker(options) {
|
|
|
77
85
|
start(socket, value.root, value.args ?? []);
|
|
78
86
|
}
|
|
79
87
|
else if (value.type === 'stop') {
|
|
80
|
-
|
|
81
|
-
broadcast(sockets, runs);
|
|
82
|
-
}
|
|
88
|
+
stop(socket, value.root, value.after);
|
|
83
89
|
}
|
|
84
90
|
else if (value.type === 'questions') {
|
|
85
91
|
void sendQuestions(value.root, () => [socket], value.id);
|
package/dist/worker-run.mjs
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import { runChildren, stopRunChildren } from './children.mjs';
|
|
1
2
|
import { wakeableSleep } from './durations.mjs';
|
|
2
3
|
import { applyEvent } from './progress.mjs';
|
|
4
|
+
import { STOP_POINTS } from './protocol.mjs';
|
|
5
|
+
export function newRun(progress) {
|
|
6
|
+
return { progress, children: runChildren() };
|
|
7
|
+
}
|
|
3
8
|
export function active(run) {
|
|
4
9
|
return run?.progress.status === 'running' || run?.progress.status === 'stopping';
|
|
5
10
|
}
|
|
6
11
|
export function endStatus(run) {
|
|
7
|
-
if (run.stop) {
|
|
12
|
+
if (run.stop !== undefined) {
|
|
8
13
|
return 'stopped';
|
|
9
14
|
}
|
|
10
15
|
return run.progress.error === undefined ? 'finished' : 'failed';
|
|
@@ -27,20 +32,29 @@ export function runsMessage(runs) {
|
|
|
27
32
|
function endsIssue(record) {
|
|
28
33
|
return record['kind'] === 'issue.end' || record['kind'] === 'issue.error';
|
|
29
34
|
}
|
|
30
|
-
export function
|
|
31
|
-
|
|
35
|
+
export function stopPoint(after) {
|
|
36
|
+
return STOP_POINTS.find((point) => point === (after ?? 'issue'));
|
|
37
|
+
}
|
|
38
|
+
function earlier(after, than) {
|
|
39
|
+
return than === undefined || STOP_POINTS.indexOf(after) > STOP_POINTS.indexOf(than);
|
|
40
|
+
}
|
|
41
|
+
export function requestStop(run, after) {
|
|
42
|
+
if (run === undefined || !active(run) || !earlier(after, run.stop)) {
|
|
32
43
|
return false;
|
|
33
44
|
}
|
|
34
|
-
run.stop =
|
|
45
|
+
run.stop = after;
|
|
35
46
|
run.wake?.();
|
|
47
|
+
if (after === 'now') {
|
|
48
|
+
stopRunChildren(run.children);
|
|
49
|
+
}
|
|
36
50
|
run.progress = { ...run.progress, status: 'stopping' };
|
|
37
51
|
return true;
|
|
38
52
|
}
|
|
39
53
|
function runInterrupts(run) {
|
|
40
54
|
return {
|
|
41
|
-
afterIssue: () => run.stop,
|
|
42
|
-
afterRound: () => run.stop,
|
|
43
|
-
sleep: (ms) => wakeableSleep(run, ms, run.stop),
|
|
55
|
+
afterIssue: () => run.stop !== undefined,
|
|
56
|
+
afterRound: () => run.stop === 'round' || run.stop === 'now',
|
|
57
|
+
sleep: (ms) => wakeableSleep(run, ms, run.stop !== undefined),
|
|
44
58
|
};
|
|
45
59
|
}
|
|
46
60
|
export function runControls(run, update, issueEnded) {
|