next-issue 6.6.125 → 6.8.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 +22 -1
- package/dist/durations.mjs +6 -2
- package/dist/hunt-switch.mjs +16 -0
- package/dist/interrupt.mjs +2 -2
- package/dist/progress.mjs +2 -2
- package/dist/refresh.mjs +10 -0
- package/dist/run.mjs +10 -6
- package/dist/serve.mjs +18 -2
- package/dist/watch.mjs +33 -8
- package/dist/worker-run.mjs +34 -3
- package/dist/worker-server.mjs +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -772,6 +772,8 @@ With `--hunt`, which turns on `--watch`, the harness runs a hunter agent at the
|
|
|
772
772
|
|
|
773
773
|
With `huntCap` at 1 and no ready issue, a hunt files at most one issue. The hunter ends its reply with one `issue:` line for each issue it filed, or one `issue: none` line; a url that is not an issue of the repository of `remote` does not count as filed. When the `remote` url holds an old owner or name that GitHub redirects after a rename or transfer, the harness asks GitHub for the new one, so an issue url with the new name counts too. The run log holds one `hunt.issue` event with the `url` for each, or one with `none`. A hunt that fails writes a `hunt.error` event and the watch goes on. The hunter then waits before the next hunt, with a `hunt.wait` event and the same back-off, so a failure, or a hunt that files nothing, that repeats waits 1, 2, 3, 5, 10, then 10 minutes, and the back-off goes back to 1 minute after a hunt that files at least one issue. The next pass claims the new issues like any other. At the first `Ctrl-C` the hunter stops after its current hunt, and the watch ends once the hunt and the running issues end. A first `Ctrl-C` during the watch wait tells you so while a hunt runs, and the third press stops the hunter at once. The hunter stops too when the watch ends for another reason.
|
|
774
774
|
|
|
775
|
+
In a run of the `serve` worker, a client can switch hunting on or off while the run goes on, with no restart, for example with `/next-issue hunt on` in the pi extension, see [Worker](#worker). This works only for runs of the worker, not for a command-line run.
|
|
776
|
+
|
|
775
777
|
## Worker
|
|
776
778
|
|
|
777
779
|
`next-issue serve` runs one worker for the repository it is run in. The
|
|
@@ -799,7 +801,7 @@ affect another. The worker:
|
|
|
799
801
|
with `another worker is running`. A worker that stops removes the lock file
|
|
800
802
|
only while it still holds the lock, and the socket file only while it is
|
|
801
803
|
still the socket it bound;
|
|
802
|
-
- refuses a `start`, `stop` or `questions` message whose `root` is not
|
|
804
|
+
- refuses a `start`, `stop`, `hunt` or `questions` message whose `root` is not
|
|
803
805
|
the exact path of its repository with an `error` message, and starts or
|
|
804
806
|
stops nothing;
|
|
805
807
|
- runs at most one run at a time. A client starts it with
|
|
@@ -838,6 +840,25 @@ affect another. The worker:
|
|
|
838
840
|
issue ends as `stopped` with its state and labels kept; the worker keeps
|
|
839
841
|
running. A later point than one already asked for changes nothing, and an
|
|
840
842
|
earlier one replaces it. An unknown `after` gets an `error` message;
|
|
843
|
+
- switches hunting of a run on or off when a client sends
|
|
844
|
+
`{ "type": "hunt", "root": "<path>", "on": true | false }`. The run keeps its
|
|
845
|
+
issues, worktrees and progress, and nothing restarts. Every watching run has
|
|
846
|
+
a hunter: a run started with `--hunt` starts with hunting on, and one
|
|
847
|
+
started with `--watch` alone starts with it off. Off lets a hunt that is
|
|
848
|
+
going finish, so the issues it files stay, and starts no new hunt. On wakes
|
|
849
|
+
the hunter at once, with no back-off wait. A run that does not watch
|
|
850
|
+
(`--once`, or `--max` without `--watch`) refuses on with an `error` message
|
|
851
|
+
that says why, and goes on unchanged. With no run going, the message gets
|
|
852
|
+
an `error` and starts nothing. The setting lasts for the run only: a new run
|
|
853
|
+
takes it from its own flags. Only runs of the worker can switch; a
|
|
854
|
+
command-line run keeps what `--hunt` gave it. The progress of each run
|
|
855
|
+
carries `hunting`, `true` while hunting is on;
|
|
856
|
+
- asks a watching run to check for new issues now when a client sends
|
|
857
|
+
`{ "type": "refresh", "root": "<path>" }`. A run that waits between passes
|
|
858
|
+
starts a new pass at once, and its next wait starts again at 1 minute; a
|
|
859
|
+
waiting hunter checks the ready count again. A refresh while a pass runs,
|
|
860
|
+
for a run that is stopping or does not watch, or with no run going, changes
|
|
861
|
+
nothing and gets no answer;
|
|
841
862
|
- exits, and removes its socket and lock files, when no run is going and no
|
|
842
863
|
client is connected, or when no client connects in the 30 seconds after it
|
|
843
864
|
starts;
|
package/dist/durations.mjs
CHANGED
|
@@ -24,18 +24,22 @@ export function deadline(ms, onExpire) {
|
|
|
24
24
|
export function elapsedMs(started) {
|
|
25
25
|
return Date.now() - started;
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
// Resolves false when woken, or when `refreshed` aborts.
|
|
28
|
+
export function wakeableSleep(sleeper, ms, stopped, refreshed) {
|
|
28
29
|
return new Promise((resolve) => {
|
|
29
|
-
if (stopped) {
|
|
30
|
+
if (stopped || refreshed?.aborted === true) {
|
|
30
31
|
resolve(false);
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
34
|
const settle = (slept) => {
|
|
34
35
|
clearTimeout(timer);
|
|
36
|
+
refreshed?.removeEventListener('abort', onRefresh);
|
|
35
37
|
sleeper.wake = undefined;
|
|
36
38
|
resolve(slept);
|
|
37
39
|
};
|
|
40
|
+
const onRefresh = () => settle(false);
|
|
38
41
|
const timer = setTimeout(() => settle(true), timerMs(ms));
|
|
39
42
|
sleeper.wake = () => settle(false);
|
|
43
|
+
refreshed?.addEventListener('abort', onRefresh, { once: true });
|
|
40
44
|
});
|
|
41
45
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function huntSwitch(initial) {
|
|
2
|
+
let on = initial;
|
|
3
|
+
let controller = new AbortController();
|
|
4
|
+
return {
|
|
5
|
+
on: () => on,
|
|
6
|
+
changed: () => controller.signal,
|
|
7
|
+
set: (next) => {
|
|
8
|
+
if (next === on) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
on = next;
|
|
12
|
+
controller.abort();
|
|
13
|
+
controller = new AbortController();
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
package/dist/interrupt.mjs
CHANGED
|
@@ -33,9 +33,9 @@ export function listenForInterrupts(say) {
|
|
|
33
33
|
return {
|
|
34
34
|
afterIssue: () => presses >= 1,
|
|
35
35
|
afterRound: () => presses >= 2,
|
|
36
|
-
sleep: (ms, busy = () => false) => {
|
|
36
|
+
sleep: (ms, busy = () => false, refreshed) => {
|
|
37
37
|
hunting = busy;
|
|
38
|
-
return wakeableSleep(sleeper, ms, presses >= 1);
|
|
38
|
+
return wakeableSleep(sleeper, ms, presses >= 1, refreshed);
|
|
39
39
|
},
|
|
40
40
|
};
|
|
41
41
|
}
|
package/dist/progress.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { truncate } from './text.mjs';
|
|
2
2
|
const TOOL_LINE_MAX = 80;
|
|
3
3
|
const NOT_STAGES = new Set(['issue.start', 'agent.start', 'run.start']);
|
|
4
|
-
export function startProgress() {
|
|
5
|
-
return { status: 'running', issues: [], handled: [] };
|
|
4
|
+
export function startProgress(hunting = false) {
|
|
5
|
+
return { status: 'running', hunting, issues: [], handled: [] };
|
|
6
6
|
}
|
|
7
7
|
function toolLine(record) {
|
|
8
8
|
const tool = String(record['tool']);
|
package/dist/refresh.mjs
ADDED
package/dist/run.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { detectRepo } from './git.mjs';
|
|
|
11
11
|
import { checkGitVersion } from './git-version.mjs';
|
|
12
12
|
import { defaultBranch } from './github.mjs';
|
|
13
13
|
import { hunter } from './hunt.mjs';
|
|
14
|
+
import { huntSwitch } from './hunt-switch.mjs';
|
|
14
15
|
import { lock, lockHolder } from './lock.mjs';
|
|
15
16
|
import { exitCode, runIssues } from './loop.mjs';
|
|
16
17
|
import { Recorder } from './observe.mjs';
|
|
@@ -69,7 +70,7 @@ async function handle(args, config, repo, recorder, controls) {
|
|
|
69
70
|
};
|
|
70
71
|
const print = controls.print ?? (async () => undefined);
|
|
71
72
|
const { reports, stoppedAt, error } = args.watch
|
|
72
|
-
? await watchRun(args, loop, context,
|
|
73
|
+
? await watchRun(args, loop, context, controls, print)
|
|
73
74
|
: await runIssues(args, loop);
|
|
74
75
|
recordLoopEnd(recorder, stoppedAt, error);
|
|
75
76
|
const summary = await endRun(recorder, reports);
|
|
@@ -78,19 +79,22 @@ async function handle(args, config, repo, recorder, controls) {
|
|
|
78
79
|
}
|
|
79
80
|
return error === undefined ? exitCode(reports) : 1;
|
|
80
81
|
}
|
|
81
|
-
function watchRun(args, loop, context,
|
|
82
|
+
export function watchRun(args, loop, context, controls, print) {
|
|
82
83
|
const { recorder } = context;
|
|
84
|
+
const { interrupts } = controls;
|
|
83
85
|
let passStart = recorder.summary();
|
|
84
|
-
const
|
|
86
|
+
const hunt = hunter(context);
|
|
85
87
|
return watchIssues(args, {
|
|
86
88
|
...loop,
|
|
87
|
-
wait: (minutes) => {
|
|
89
|
+
wait: (minutes, refreshed) => {
|
|
88
90
|
recorder.event('watch.wait', { minutes }, 'quiet');
|
|
89
91
|
passStart = recorder.summary();
|
|
90
|
-
return interrupts.sleep(minutesToMs(minutes), () =>
|
|
92
|
+
return interrupts.sleep(minutesToMs(minutes), () => hunt.busy(), refreshed);
|
|
91
93
|
},
|
|
92
94
|
passEnd: (issues) => print({ ...recorder.summary(passStart), issues }),
|
|
93
|
-
|
|
95
|
+
hunter: hunt,
|
|
96
|
+
hunting: controls.hunting ?? huntSwitch(args.hunt),
|
|
97
|
+
refreshed: controls.refreshed,
|
|
94
98
|
});
|
|
95
99
|
}
|
|
96
100
|
function recordLoopEnd(recorder, stoppedAt, error) {
|
package/dist/serve.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import { runRepo } from './run.mjs';
|
|
|
14
14
|
import { packageVersion } from './version.mjs';
|
|
15
15
|
import { keepLogTrimmed, LOG_CHECK_MS } from './worker-log.mjs';
|
|
16
16
|
import { checkSocketPath, workerPaths } from './worker-paths.mjs';
|
|
17
|
-
import { active, endStatus, newRun, requestStop, runControls, runsMessage, startRefusal, stopPoint, } from './worker-run.mjs';
|
|
17
|
+
import { active, endStatus, huntRefusal, newRun, requestRefresh, requestStop, runControls, runsMessage, setHunting, startRefusal, stopPoint, } from './worker-run.mjs';
|
|
18
18
|
import { broadcast, closer, fileId, listen, parseMessage, removeOwned, shutdown, } from './worker-server.mjs';
|
|
19
19
|
const LOCK_WAIT_MS = 5_000;
|
|
20
20
|
const IDLE_MS = 30_000;
|
|
@@ -64,7 +64,7 @@ export async function startWorker(options) {
|
|
|
64
64
|
send(socket, { type: 'error', root, message: message(error) });
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
-
const run = newRun(startProgress());
|
|
67
|
+
const run = newRun(startProgress(args.hunt), args.watch);
|
|
68
68
|
runs.set(root, run);
|
|
69
69
|
const update = (next) => {
|
|
70
70
|
run.progress = next;
|
|
@@ -84,6 +84,16 @@ export async function startWorker(options) {
|
|
|
84
84
|
broadcast(sockets, runs);
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
|
+
const hunt = (socket, root, on) => {
|
|
88
|
+
const run = runs.get(root);
|
|
89
|
+
const refusal = huntRefusal(run, on);
|
|
90
|
+
if (refusal !== undefined) {
|
|
91
|
+
send(socket, { type: 'error', root, message: refusal });
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
setHunting(run, on);
|
|
95
|
+
broadcast(sockets, runs);
|
|
96
|
+
};
|
|
87
97
|
const receive = (socket, value) => {
|
|
88
98
|
if (value.type === 'hello') {
|
|
89
99
|
if (isNewer(value.version, options.version)) {
|
|
@@ -104,6 +114,12 @@ export async function startWorker(options) {
|
|
|
104
114
|
else if (value.type === 'stop') {
|
|
105
115
|
stop(socket, value.root, value.after);
|
|
106
116
|
}
|
|
117
|
+
else if (value.type === 'hunt') {
|
|
118
|
+
hunt(socket, value.root, value.on);
|
|
119
|
+
}
|
|
120
|
+
else if (value.type === 'refresh') {
|
|
121
|
+
requestRefresh(runs.get(value.root));
|
|
122
|
+
}
|
|
107
123
|
else if (value.type === 'questions') {
|
|
108
124
|
void sendQuestions(value.root, () => [socket], value.id);
|
|
109
125
|
}
|
package/dist/watch.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { huntSwitch } from './hunt-switch.mjs';
|
|
1
2
|
import { handled, runIssues } from './loop.mjs';
|
|
2
3
|
const BACK_OFF_MINUTES = [1, 2, 3, 5, 10];
|
|
3
4
|
export async function watchIssues(args, watch) {
|
|
@@ -7,7 +8,7 @@ export async function watchIssues(args, watch) {
|
|
|
7
8
|
const claims = claimAlarm();
|
|
8
9
|
const hunting = watch.hunter === undefined
|
|
9
10
|
? undefined
|
|
10
|
-
: huntIssues(watch.hunter, running, failed, claims, () => ended.signal.aborted || watch.stop(), ended.signal);
|
|
11
|
+
: huntIssues(watch.hunter, watch.hunting ?? huntSwitch(true), running, failed, claims, watch.refreshed, () => ended.signal.aborted || watch.stop(), ended.signal);
|
|
11
12
|
try {
|
|
12
13
|
return await watchPasses(args, failed, {
|
|
13
14
|
...watch,
|
|
@@ -46,26 +47,46 @@ function claimAlarm() {
|
|
|
46
47
|
},
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
function aborted(signal) {
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
if (signal.aborted) {
|
|
53
|
+
resolve();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
signal.addEventListener('abort', () => resolve(), { once: true });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async function huntIssues(hunter, hunting, running, failed, claims, refreshes, stopped, signal) {
|
|
50
61
|
let step = 0;
|
|
51
62
|
while (!stopped()) {
|
|
63
|
+
if (!hunting.on()) {
|
|
64
|
+
await aborted(AbortSignal.any([signal, hunting.changed()]));
|
|
65
|
+
step = 0;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
52
68
|
const ready = await hunter.ready(running, failed).catch(() => undefined);
|
|
53
69
|
if (stopped()) {
|
|
54
70
|
return;
|
|
55
71
|
}
|
|
56
72
|
claims.take();
|
|
57
73
|
const waiting = ready?.filter((issue) => !running.has(issue.number)).length;
|
|
58
|
-
if (waiting !== undefined && waiting < hunter.cap) {
|
|
74
|
+
if (waiting !== undefined && waiting < hunter.cap && hunting.on()) {
|
|
59
75
|
if (await hunter.hunt(hunter.cap - waiting)) {
|
|
60
76
|
step = 0;
|
|
61
77
|
continue;
|
|
62
78
|
}
|
|
63
79
|
}
|
|
64
|
-
if (claims.take() || stopped()) {
|
|
80
|
+
if (claims.take() || stopped() || !hunting.on()) {
|
|
65
81
|
continue;
|
|
66
82
|
}
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
const changed = hunting.changed();
|
|
84
|
+
const refreshed = refreshes?.() ?? new AbortController().signal;
|
|
85
|
+
await hunter.wait(backOffMinutes(step), AbortSignal.any([signal, claims.signal(), changed, refreshed]));
|
|
86
|
+
if (changed.aborted || refreshed.aborted) {
|
|
87
|
+
step = 0;
|
|
88
|
+
}
|
|
89
|
+
else if (!claims.take()) {
|
|
69
90
|
step += 1;
|
|
70
91
|
}
|
|
71
92
|
}
|
|
@@ -90,8 +111,12 @@ async function watchPasses(args, failed, watch) {
|
|
|
90
111
|
}
|
|
91
112
|
const minutes = backOffMinutes(step);
|
|
92
113
|
step += 1;
|
|
93
|
-
|
|
94
|
-
|
|
114
|
+
const refreshed = watch.refreshed?.();
|
|
115
|
+
if (!(await watch.wait(minutes, refreshed))) {
|
|
116
|
+
if (refreshed?.aborted !== true || watch.stop()) {
|
|
117
|
+
return { reports };
|
|
118
|
+
}
|
|
119
|
+
step = 0;
|
|
95
120
|
}
|
|
96
121
|
}
|
|
97
122
|
}
|
package/dist/worker-run.mjs
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { runChildren, stopRunChildren } from './children.mjs';
|
|
2
2
|
import { wakeableSleep } from './durations.mjs';
|
|
3
|
+
import { huntSwitch } from './hunt-switch.mjs';
|
|
3
4
|
import { applyEvent } from './progress.mjs';
|
|
4
5
|
import { STOP_POINTS } from './protocol.mjs';
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import { refresher } from './refresh.mjs';
|
|
7
|
+
export function newRun(progress, watching = false) {
|
|
8
|
+
return {
|
|
9
|
+
progress,
|
|
10
|
+
children: runChildren(),
|
|
11
|
+
watching,
|
|
12
|
+
hunting: huntSwitch(progress.hunting),
|
|
13
|
+
refresher: refresher(),
|
|
14
|
+
};
|
|
7
15
|
}
|
|
8
16
|
export function active(run) {
|
|
9
17
|
return run?.progress.status === 'running' || run?.progress.status === 'stopping';
|
|
@@ -50,16 +58,39 @@ export function requestStop(run, after) {
|
|
|
50
58
|
run.progress = { ...run.progress, status: 'stopping' };
|
|
51
59
|
return true;
|
|
52
60
|
}
|
|
61
|
+
export function huntRefusal(run, on) {
|
|
62
|
+
if (run === undefined || !active(run)) {
|
|
63
|
+
return 'no run is going in this repository';
|
|
64
|
+
}
|
|
65
|
+
if (on && !run.watching) {
|
|
66
|
+
return 'the run does not watch for issues, so it cannot hunt: start a run with --watch or --hunt';
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
// Only a running watch run refreshes; a pass that is going or a stop is left alone.
|
|
71
|
+
export function requestRefresh(run) {
|
|
72
|
+
if (run?.progress.status !== 'running' || !run.watching || run.stop !== undefined) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
run.refresher.refresh();
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
export function setHunting(run, on) {
|
|
79
|
+
run.hunting.set(on);
|
|
80
|
+
run.progress = { ...run.progress, hunting: on };
|
|
81
|
+
}
|
|
53
82
|
function runInterrupts(run) {
|
|
54
83
|
return {
|
|
55
84
|
afterIssue: () => run.stop !== undefined,
|
|
56
85
|
afterRound: () => run.stop === 'round' || run.stop === 'now',
|
|
57
|
-
sleep: (ms) => wakeableSleep(run, ms, run.stop !== undefined),
|
|
86
|
+
sleep: (ms, _hunting, refreshed) => wakeableSleep(run, ms, run.stop !== undefined, refreshed),
|
|
58
87
|
};
|
|
59
88
|
}
|
|
60
89
|
export function runControls(run, update, issueEnded) {
|
|
61
90
|
return {
|
|
62
91
|
interrupts: runInterrupts(run),
|
|
92
|
+
hunting: run.hunting,
|
|
93
|
+
refreshed: run.refresher.refreshed,
|
|
63
94
|
onEvent: (record) => {
|
|
64
95
|
update(applyEvent(run.progress, record));
|
|
65
96
|
if (endsIssue(record)) {
|
package/dist/worker-server.mjs
CHANGED
|
@@ -17,6 +17,9 @@ function isClientMessage(value) {
|
|
|
17
17
|
if (typeof value['root'] !== 'string') {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
|
+
if (value['type'] === 'hunt') {
|
|
21
|
+
return typeof value['on'] === 'boolean';
|
|
22
|
+
}
|
|
20
23
|
if (value['type'] === 'questions') {
|
|
21
24
|
return value['id'] === undefined || typeof value['id'] === 'string';
|
|
22
25
|
}
|