next-issue 8.6.0 → 8.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 +28 -14
- package/dist/run.mjs +4 -3
- package/dist/serve.mjs +29 -14
- package/dist/{hunt-switch.mjs → switch.mjs} +1 -1
- package/dist/watch.mjs +8 -6
- package/dist/worker-run.mjs +32 -13
- package/dist/worker-server.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -941,7 +941,7 @@ With `next-issue start --hunt`, which turns on `--watch`, the harness runs a hun
|
|
|
941
941
|
|
|
942
942
|
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.
|
|
943
943
|
|
|
944
|
-
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.
|
|
944
|
+
In a run of the `serve` worker, a client can switch hunting and watching on or off while the run goes on, with no restart, for example with `/next-issue hunt on` or `/next-issue watch on` in the pi extension, see [Worker](#worker). This works only for runs of the worker, not for a command-line run.
|
|
945
945
|
|
|
946
946
|
## Worker
|
|
947
947
|
|
|
@@ -970,12 +970,13 @@ affect another. The worker:
|
|
|
970
970
|
with `another worker is running`. A worker that stops removes the lock file
|
|
971
971
|
only while it still holds the lock, and the socket file only while it is
|
|
972
972
|
still the socket it bound;
|
|
973
|
-
- refuses a `start`, `stop`, `hunt` or `questions` message whose `root` is not
|
|
973
|
+
- refuses a `start`, `stop`, `watch`, `hunt` or `questions` message whose `root` is not
|
|
974
974
|
the exact path of its repository with an `error` message, and starts or
|
|
975
975
|
stops nothing;
|
|
976
976
|
- runs at most one run at a time. A client starts it with
|
|
977
977
|
`{ "type": "start", "root": "<path>", "args": [...] }`. Each run is like
|
|
978
|
-
`next-issue start` with those args, or with none when `args` is left out
|
|
978
|
+
`next-issue start` with those args, or with none when `args` is left out
|
|
979
|
+
(the pi extension sends none). It takes
|
|
979
980
|
`--max <n>`, `--watch`, `--hunt`, `--reset`, `--verbose` and
|
|
980
981
|
`--quiet`, and refuses a command (`start` too), `--json`, `--force`, `--help` or an
|
|
981
982
|
unknown argument with an `error` message;
|
|
@@ -1010,18 +1011,24 @@ affect another. The worker:
|
|
|
1010
1011
|
issue ends as `stopped` with its state and labels kept; the worker keeps
|
|
1011
1012
|
running. A later point than one already asked for changes nothing, and an
|
|
1012
1013
|
earlier one replaces it. An unknown `after` gets an `error` message;
|
|
1014
|
+
- switches watching of a run on or off when a client sends
|
|
1015
|
+
`{ "type": "watch", "root": "<path>", "on": true | false }`. The run keeps
|
|
1016
|
+
its issues, worktrees and progress, and nothing restarts. A run started with
|
|
1017
|
+
`--watch` or `--hunt` starts with watching on, and any other run with it
|
|
1018
|
+
off. On keeps the run going after the current pass, as with `--watch`. Off
|
|
1019
|
+
ends the run after the current pass, or at once when it waits between
|
|
1020
|
+
passes, and also turns hunting off. With no run going, the message gets an
|
|
1021
|
+
`error` and starts nothing;
|
|
1013
1022
|
- switches hunting of a run on or off when a client sends
|
|
1014
1023
|
`{ "type": "hunt", "root": "<path>", "on": true | false }`. The run keeps its
|
|
1015
|
-
issues, worktrees and progress, and nothing restarts. Every
|
|
1016
|
-
a hunter: a run started with `--hunt` starts with hunting on, and
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
takes it from its own flags. Only runs of the worker can switch; a
|
|
1024
|
-
command-line run keeps what `--hunt` gave it. The progress of each run
|
|
1024
|
+
issues, worktrees and progress, and nothing restarts. Every run of the
|
|
1025
|
+
worker has a hunter: a run started with `--hunt` starts with hunting on, and
|
|
1026
|
+
any other run with it off. Off lets a hunt that is going finish, so the
|
|
1027
|
+
issues it files stay, and starts no new hunt. On wakes the hunter at once,
|
|
1028
|
+
with no back-off wait, and also turns watching on. With no run going, the message gets
|
|
1029
|
+
an `error` and starts nothing. The settings last for the run only: a new run
|
|
1030
|
+
takes them from its own flags. Only runs of the worker can switch; a
|
|
1031
|
+
command-line run keeps what `--watch` and `--hunt` gave it. The progress of each run
|
|
1025
1032
|
carries `hunting`, `true` while hunting is on, and `watching`, `true` when
|
|
1026
1033
|
the run watches for issues;
|
|
1027
1034
|
- asks a watching run to check for new issues now when a client sends
|
|
@@ -1036,7 +1043,14 @@ affect another. The worker:
|
|
|
1036
1043
|
- waits up to 5 seconds for the lock when a worker that is closing still
|
|
1037
1044
|
holds it;
|
|
1038
1045
|
- closes once no run is going when a client with a newer version connects, so
|
|
1039
|
-
that the client can start the newer worker
|
|
1046
|
+
that the client can start the newer worker. A run that watches is stopped
|
|
1047
|
+
between issues for that, as `stop` with `issue` does: it claims nothing new,
|
|
1048
|
+
and its running issues and its current hunt finish. Its progress then holds
|
|
1049
|
+
`"upgrade": { "from": "<worker version>", "to": "<client version>" }`. A
|
|
1050
|
+
stop by a person drops that field, so no client starts the run again. A run
|
|
1051
|
+
that does not watch is left alone. Meanwhile the worker refuses every start
|
|
1052
|
+
with `the worker is restarting, try again soon`. A `start` with
|
|
1053
|
+
`"resume": true` gets no error when the worker refuses it;
|
|
1040
1054
|
- stops every agent and command and exits on `SIGTERM`, `SIGHUP` or `SIGINT`, and
|
|
1041
1055
|
removes its socket and lock files;
|
|
1042
1056
|
- keeps `.next-issue/worker.log`, where the extension writes the output of
|
package/dist/run.mjs
CHANGED
|
@@ -11,7 +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 {
|
|
14
|
+
import { onOff } from './switch.mjs';
|
|
15
15
|
import { lock, lockHolder } from './lock.mjs';
|
|
16
16
|
import { exitCode, runIssues } from './loop.mjs';
|
|
17
17
|
import { Recorder } from './observe.mjs';
|
|
@@ -69,7 +69,7 @@ async function handle(args, config, repo, recorder, controls) {
|
|
|
69
69
|
concurrency: config.concurrency,
|
|
70
70
|
};
|
|
71
71
|
const print = controls.print ?? (async () => undefined);
|
|
72
|
-
const { reports, stoppedAt, error } = args.watch
|
|
72
|
+
const { reports, stoppedAt, error } = args.watch || controls.watching !== undefined
|
|
73
73
|
? await watchRun(args, loop, context, controls, print)
|
|
74
74
|
: await runIssues(args, loop);
|
|
75
75
|
recordLoopEnd(recorder, stoppedAt, error);
|
|
@@ -93,7 +93,8 @@ export function watchRun(args, loop, context, controls, print) {
|
|
|
93
93
|
},
|
|
94
94
|
passEnd: (issues) => print({ ...recorder.summary(passStart), issues }),
|
|
95
95
|
hunter: hunt,
|
|
96
|
-
hunting: controls.hunting ??
|
|
96
|
+
hunting: controls.hunting ?? onOff(args.hunt),
|
|
97
|
+
watching: controls.watching,
|
|
97
98
|
refreshed: controls.refreshed,
|
|
98
99
|
});
|
|
99
100
|
}
|
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,
|
|
17
|
+
import { active, dropUpgrade, endStatus, newRun, requestRefresh, requestStop, requestUpgrade, runControls, runsMessage, setHunting, setWatching, startRefusal, stopPoint, switchRefusal, } 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;
|
|
@@ -32,7 +32,7 @@ export async function startWorker(options) {
|
|
|
32
32
|
socket: '',
|
|
33
33
|
};
|
|
34
34
|
const runs = new Map();
|
|
35
|
-
let restart
|
|
35
|
+
let restart;
|
|
36
36
|
const server = createServer();
|
|
37
37
|
const sockets = new WebSocketServer({ server });
|
|
38
38
|
const sendQuestions = questionSender(options.questions);
|
|
@@ -46,14 +46,21 @@ export async function startWorker(options) {
|
|
|
46
46
|
await shutdown(server, sockets, owned);
|
|
47
47
|
});
|
|
48
48
|
const closeWhenIdle = () => {
|
|
49
|
-
if ((restart || sockets.clients.size === 0) && !busy()) {
|
|
49
|
+
if ((restart !== undefined || sockets.clients.size === 0) && !busy()) {
|
|
50
50
|
void close();
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
const
|
|
54
|
-
|
|
53
|
+
const upgradeBetweenIssues = (run) => {
|
|
54
|
+
if (restart !== undefined && requestUpgrade(run, { from: options.version, to: restart })) {
|
|
55
|
+
broadcast(sockets, runs);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const start = (socket, root, argv, resume) => {
|
|
59
|
+
const refusal = startRefusal(runs.get(root), restart !== undefined);
|
|
55
60
|
if (refusal !== undefined) {
|
|
56
|
-
|
|
61
|
+
if (!resume) {
|
|
62
|
+
send(socket, { type: 'error', root, message: refusal });
|
|
63
|
+
}
|
|
57
64
|
return;
|
|
58
65
|
}
|
|
59
66
|
let args;
|
|
@@ -64,7 +71,7 @@ export async function startWorker(options) {
|
|
|
64
71
|
send(socket, { type: 'error', root, message: message(error) });
|
|
65
72
|
return;
|
|
66
73
|
}
|
|
67
|
-
const run = newRun({ ...startProgress(args.hunt), watching: args.watch }
|
|
74
|
+
const run = newRun({ ...startProgress(args.hunt), watching: args.watch });
|
|
68
75
|
runs.set(root, run);
|
|
69
76
|
const update = (next) => {
|
|
70
77
|
run.progress = next;
|
|
@@ -79,20 +86,24 @@ export async function startWorker(options) {
|
|
|
79
86
|
const point = stopPoint(after);
|
|
80
87
|
if (point === undefined) {
|
|
81
88
|
send(socket, { type: 'error', root, message: `stop does not take --after ${String(after)}` });
|
|
89
|
+
return;
|
|
82
90
|
}
|
|
83
|
-
|
|
91
|
+
const run = runs.get(root);
|
|
92
|
+
const dropped = dropUpgrade(run);
|
|
93
|
+
if (requestStop(run, point) || dropped) {
|
|
84
94
|
broadcast(sockets, runs);
|
|
85
95
|
}
|
|
86
96
|
};
|
|
87
|
-
const
|
|
97
|
+
const toggle = (socket, root, on, set) => {
|
|
88
98
|
const run = runs.get(root);
|
|
89
|
-
const refusal =
|
|
99
|
+
const refusal = switchRefusal(run);
|
|
90
100
|
if (refusal !== undefined) {
|
|
91
101
|
send(socket, { type: 'error', root, message: refusal });
|
|
92
102
|
return;
|
|
93
103
|
}
|
|
94
|
-
|
|
104
|
+
set(run, on);
|
|
95
105
|
broadcast(sockets, runs);
|
|
106
|
+
upgradeBetweenIssues(run);
|
|
96
107
|
};
|
|
97
108
|
const receive = (socket, value) => {
|
|
98
109
|
if (value.type === 'hello') {
|
|
@@ -100,7 +111,8 @@ export async function startWorker(options) {
|
|
|
100
111
|
throw new Error('a hello message needs its version as a string');
|
|
101
112
|
}
|
|
102
113
|
if (isNewer(value.version, options.version)) {
|
|
103
|
-
restart
|
|
114
|
+
restart ??= value.version;
|
|
115
|
+
runs.forEach(upgradeBetweenIssues);
|
|
104
116
|
closeWhenIdle();
|
|
105
117
|
}
|
|
106
118
|
}
|
|
@@ -112,13 +124,16 @@ export async function startWorker(options) {
|
|
|
112
124
|
});
|
|
113
125
|
}
|
|
114
126
|
else if (value.type === 'start') {
|
|
115
|
-
start(socket, value.root, value.args ?? []);
|
|
127
|
+
start(socket, value.root, value.args ?? [], value.resume === true);
|
|
116
128
|
}
|
|
117
129
|
else if (value.type === 'stop') {
|
|
118
130
|
stop(socket, value.root, value.after);
|
|
119
131
|
}
|
|
120
132
|
else if (value.type === 'hunt') {
|
|
121
|
-
|
|
133
|
+
toggle(socket, value.root, value.on, setHunting);
|
|
134
|
+
}
|
|
135
|
+
else if (value.type === 'watch') {
|
|
136
|
+
toggle(socket, value.root, value.on, setWatching);
|
|
122
137
|
}
|
|
123
138
|
else if (value.type === 'refresh') {
|
|
124
139
|
requestRefresh(runs.get(value.root));
|
package/dist/watch.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onOff } from './switch.mjs';
|
|
2
2
|
import { handled, runIssues } from './loop.mjs';
|
|
3
3
|
const BACK_OFF_MINUTES = [1, 2, 3, 5, 10];
|
|
4
4
|
export async function watchIssues(args, watch) {
|
|
@@ -8,7 +8,7 @@ export async function watchIssues(args, watch) {
|
|
|
8
8
|
const claims = claimAlarm();
|
|
9
9
|
const hunting = watch.hunter === undefined
|
|
10
10
|
? undefined
|
|
11
|
-
: huntIssues(watch.hunter, watch.hunting ??
|
|
11
|
+
: huntIssues(watch.hunter, watch.hunting ?? onOff(true), running, failed, claims, watch.refreshed, () => ended.signal.aborted || watch.stop(), ended.signal);
|
|
12
12
|
try {
|
|
13
13
|
return await watchPasses(args, failed, {
|
|
14
14
|
...watch,
|
|
@@ -94,6 +94,7 @@ async function watchPasses(args, failed, watch) {
|
|
|
94
94
|
const limit = args.max;
|
|
95
95
|
const reports = [];
|
|
96
96
|
let step = 0;
|
|
97
|
+
const watching = () => watch.watching?.on() ?? true;
|
|
97
98
|
for (;;) {
|
|
98
99
|
const pass = await runIssues({ max: limit === undefined ? undefined : limit - handled(reports) }, watch, new Set(failed));
|
|
99
100
|
addReports(reports, pass.reports);
|
|
@@ -105,14 +106,15 @@ async function watchPasses(args, failed, watch) {
|
|
|
105
106
|
if (pass.error !== undefined || pass.stoppedAt !== undefined) {
|
|
106
107
|
return { ...pass, reports };
|
|
107
108
|
}
|
|
108
|
-
if ((limit !== undefined && handled(reports) >= limit) || watch.stop()) {
|
|
109
|
+
if ((limit !== undefined && handled(reports) >= limit) || watch.stop() || !watching()) {
|
|
109
110
|
return { reports };
|
|
110
111
|
}
|
|
111
112
|
const minutes = backOffMinutes(step);
|
|
112
113
|
step += 1;
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
const signals = [watch.refreshed?.(), watch.watching?.changed()].filter((signal) => signal !== undefined);
|
|
115
|
+
const woken = signals.length === 0 ? undefined : AbortSignal.any(signals);
|
|
116
|
+
if (!(await watch.wait(minutes, woken))) {
|
|
117
|
+
if (woken?.aborted !== true || watch.stop() || !watching()) {
|
|
116
118
|
return { reports };
|
|
117
119
|
}
|
|
118
120
|
step = 0;
|
package/dist/worker-run.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { runChildren, stopRunChildren } from './children.mjs';
|
|
2
2
|
import { wakeableSleep } from './durations.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { onOff } from './switch.mjs';
|
|
4
4
|
import { applyEvent } from './progress.mjs';
|
|
5
|
-
import { STOP_POINTS } from './protocol.mjs';
|
|
5
|
+
import { STOP_POINTS, } from './protocol.mjs';
|
|
6
6
|
import { refresher } from './refresh.mjs';
|
|
7
|
-
export function newRun(progress
|
|
7
|
+
export function newRun(progress) {
|
|
8
8
|
return {
|
|
9
9
|
progress,
|
|
10
10
|
children: runChildren(),
|
|
11
|
-
watching,
|
|
12
|
-
hunting:
|
|
11
|
+
watching: onOff(progress.watching === true),
|
|
12
|
+
hunting: onOff(progress.hunting),
|
|
13
13
|
refresher: refresher(),
|
|
14
14
|
};
|
|
15
15
|
}
|
|
@@ -58,26 +58,44 @@ export function requestStop(run, after) {
|
|
|
58
58
|
run.progress = { ...run.progress, status: 'stopping' };
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
|
-
export function
|
|
62
|
-
if (run
|
|
63
|
-
return
|
|
61
|
+
export function requestUpgrade(run, upgrade) {
|
|
62
|
+
if (!run.watching.on() || run.stop !== undefined || !requestStop(run, 'issue')) {
|
|
63
|
+
return false;
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
run.progress = { ...run.progress, upgrade };
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
export function dropUpgrade(run) {
|
|
69
|
+
if (run?.progress.upgrade === undefined) {
|
|
70
|
+
return false;
|
|
67
71
|
}
|
|
68
|
-
|
|
72
|
+
run.progress = { ...run.progress, upgrade: undefined };
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
export function switchRefusal(run) {
|
|
76
|
+
return active(run) ? undefined : 'no run is going in this repository';
|
|
69
77
|
}
|
|
70
78
|
// Only a running watch run refreshes; a pass that is going or a stop is left alone.
|
|
71
79
|
export function requestRefresh(run) {
|
|
72
|
-
if (run?.progress.status !== 'running' || !run.watching || run.stop !== undefined) {
|
|
80
|
+
if (run?.progress.status !== 'running' || !run.watching.on() || run.stop !== undefined) {
|
|
73
81
|
return false;
|
|
74
82
|
}
|
|
75
83
|
run.refresher.refresh();
|
|
76
84
|
return true;
|
|
77
85
|
}
|
|
78
86
|
export function setHunting(run, on) {
|
|
87
|
+
if (on) {
|
|
88
|
+
run.watching.set(true);
|
|
89
|
+
}
|
|
79
90
|
run.hunting.set(on);
|
|
80
|
-
run.progress = { ...run.progress, hunting: on };
|
|
91
|
+
run.progress = { ...run.progress, hunting: on, watching: run.watching.on() };
|
|
92
|
+
}
|
|
93
|
+
export function setWatching(run, on) {
|
|
94
|
+
if (!on) {
|
|
95
|
+
run.hunting.set(false);
|
|
96
|
+
}
|
|
97
|
+
run.watching.set(on);
|
|
98
|
+
run.progress = { ...run.progress, watching: on, hunting: run.hunting.on() };
|
|
81
99
|
}
|
|
82
100
|
function runInterrupts(run) {
|
|
83
101
|
return {
|
|
@@ -90,6 +108,7 @@ export function runControls(run, update, issueEnded) {
|
|
|
90
108
|
return {
|
|
91
109
|
interrupts: runInterrupts(run),
|
|
92
110
|
hunting: run.hunting,
|
|
111
|
+
watching: run.watching,
|
|
93
112
|
refreshed: run.refresher.refreshed,
|
|
94
113
|
onEvent: (record) => {
|
|
95
114
|
update(applyEvent(run.progress, record));
|
package/dist/worker-server.mjs
CHANGED
|
@@ -17,7 +17,7 @@ function isClientMessage(value) {
|
|
|
17
17
|
if (typeof value['root'] !== 'string') {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
|
-
if (value['type'] === 'hunt') {
|
|
20
|
+
if (value['type'] === 'hunt' || value['type'] === 'watch') {
|
|
21
21
|
return typeof value['on'] === 'boolean';
|
|
22
22
|
}
|
|
23
23
|
if (value['type'] === 'questions') {
|