next-issue 6.6.125 → 6.7.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 +16 -1
- package/dist/hunt-switch.mjs +16 -0
- package/dist/progress.mjs +2 -2
- package/dist/run.mjs +8 -5
- package/dist/serve.mjs +15 -2
- package/dist/watch.mjs +26 -6
- package/dist/worker-run.mjs +17 -2
- 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,19 @@ 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;
|
|
841
856
|
- exits, and removes its socket and lock files, when no run is going and no
|
|
842
857
|
client is connected, or when no client connects in the 30 seconds after it
|
|
843
858
|
starts;
|
|
@@ -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/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/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,21 @@ 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
89
|
wait: (minutes) => {
|
|
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());
|
|
91
93
|
},
|
|
92
94
|
passEnd: (issues) => print({ ...recorder.summary(passStart), issues }),
|
|
93
|
-
|
|
95
|
+
hunter: hunt,
|
|
96
|
+
hunting: controls.hunting ?? huntSwitch(args.hunt),
|
|
94
97
|
});
|
|
95
98
|
}
|
|
96
99
|
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, 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,9 @@ 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
|
+
}
|
|
107
120
|
else if (value.type === 'questions') {
|
|
108
121
|
void sendQuestions(value.root, () => [socket], value.id);
|
|
109
122
|
}
|
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, () => ended.signal.aborted || watch.stop(), ended.signal);
|
|
11
12
|
try {
|
|
12
13
|
return await watchPasses(args, failed, {
|
|
13
14
|
...watch,
|
|
@@ -46,26 +47,45 @@ 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, 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
|
+
await hunter.wait(backOffMinutes(step), AbortSignal.any([signal, claims.signal(), changed]));
|
|
85
|
+
if (changed.aborted) {
|
|
86
|
+
step = 0;
|
|
87
|
+
}
|
|
88
|
+
else if (!claims.take()) {
|
|
69
89
|
step += 1;
|
|
70
90
|
}
|
|
71
91
|
}
|
package/dist/worker-run.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
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
|
-
export function newRun(progress) {
|
|
6
|
-
return { progress, children: runChildren() };
|
|
6
|
+
export function newRun(progress, watching = false) {
|
|
7
|
+
return { progress, children: runChildren(), watching, hunting: huntSwitch(progress.hunting) };
|
|
7
8
|
}
|
|
8
9
|
export function active(run) {
|
|
9
10
|
return run?.progress.status === 'running' || run?.progress.status === 'stopping';
|
|
@@ -50,6 +51,19 @@ export function requestStop(run, after) {
|
|
|
50
51
|
run.progress = { ...run.progress, status: 'stopping' };
|
|
51
52
|
return true;
|
|
52
53
|
}
|
|
54
|
+
export function huntRefusal(run, on) {
|
|
55
|
+
if (run === undefined || !active(run)) {
|
|
56
|
+
return 'no run is going in this repository';
|
|
57
|
+
}
|
|
58
|
+
if (on && !run.watching) {
|
|
59
|
+
return 'the run does not watch for issues, so it cannot hunt: start a run with --watch or --hunt';
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
export function setHunting(run, on) {
|
|
64
|
+
run.hunting.set(on);
|
|
65
|
+
run.progress = { ...run.progress, hunting: on };
|
|
66
|
+
}
|
|
53
67
|
function runInterrupts(run) {
|
|
54
68
|
return {
|
|
55
69
|
afterIssue: () => run.stop !== undefined,
|
|
@@ -60,6 +74,7 @@ function runInterrupts(run) {
|
|
|
60
74
|
export function runControls(run, update, issueEnded) {
|
|
61
75
|
return {
|
|
62
76
|
interrupts: runInterrupts(run),
|
|
77
|
+
hunting: run.hunting,
|
|
63
78
|
onEvent: (record) => {
|
|
64
79
|
update(applyEvent(run.progress, record));
|
|
65
80
|
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
|
}
|