next-issue 11.0.0 → 12.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 +30 -24
- package/dist/args.mjs +43 -17
- package/dist/cli.mjs +5 -0
- package/dist/switch-run.mjs +49 -0
- package/dist/worker-client.mjs +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ flowchart TD
|
|
|
34
34
|
|
|
35
35
|
Before each issue, fetch the open issues again and take the oldest one not yet seen in this run. An issue seen once in a run is not tried again in that run while its labels stay as the first fetch after its attempt found them. When its labels change, for example once a person answers a hand-over or makes a skipped issue ready, the next fetch claims it again in the usual order. An issue that is done, or that failed with an error and was not handed over, is not tried again in that run. The run ends when no unseen issue is left. When the fetch fails, the run claims no new issue, ends once the running issues end, writes the summary of the issues it handled and exits with code 1.
|
|
36
36
|
|
|
37
|
-
`next-issue start` runs the work in the worker of the repository, see [Worker](#worker). It connects to the worker, or starts one in the background (`next-issue serve` of the same version, with its output in `.next-issue/worker.log`) when none answers, and then starts the run there with its flags. It prints the output of the run on standard error and the summary on standard output, and exits with the exit code of the run. When the terminal closes or the command ends some other way, the run keeps going in the worker, and pi and `next-issue logs` still show it. pi shows the run in `/next-issue` and the dashboard, and its Stop, Watch, Hunt and Refresh work on it. When the worker is older than `start` and no run is going, it closes and `start` starts a new one. When a newer client, such as a newer pi, connects while a run of `start` goes, the worker does not stop that run for an upgrade, even when it watches: the run keeps its flags (`--watch`, `--hunt`), `start` follows it to its end, and the worker upgrades once it ends. When a run is going in the worker already, `start` exits with code 1 and the error `a run is going in this repository already`, and leaves that run alone: it does not tell an older worker its version, so the worker does not stop a watching run for an upgrade. `start` ignores `--force`, as before.
|
|
37
|
+
`next-issue start` runs the work in the worker of the repository, see [Worker](#worker). It connects to the worker, or starts one in the background (`next-issue serve` of the same version, with its output in `.next-issue/worker.log`) when none answers, and then starts the run there with its flags. It prints the output of the run on standard error and the summary on standard output, and exits with the exit code of the run. When the terminal closes or the command ends some other way, the run keeps going in the worker, and pi and `next-issue logs` still show it. pi shows the run in `/next-issue` and the dashboard, and its Stop, Watch, Hunt and Refresh work on it. When the worker is older than `start` and no run is going, it closes and `start` starts a new one. When a newer client, such as a newer pi, connects while a run of `start` goes, the worker does not stop that run for an upgrade, even when it watches: the run keeps its flags (`--watch on|off`, `--hunt on|off`), `start` follows it to its end, and the worker upgrades once it ends. When a run is going in the worker already, `start` exits with code 1 and the error `a run is going in this repository already`, and leaves that run alone: it does not tell an older worker its version, so the worker does not stop a watching run for an upgrade. `start` ignores `--force`, as before.
|
|
38
38
|
|
|
39
39
|
Only one worker goes at a time in a repository. It holds the lock `.next-issue/worker.lock`, with the process id and the start time of that process, for its whole life. A run that the worker starts takes no lock of its own, since the worker runs at most one run at a time. When a process that does not take connections on the worker socket holds the lock for more than 2 seconds, `start` starts a worker anyway, which exits with `another worker is running`, so `start` claims no issue and exits with code 1 and the error `the next-issue worker exited before it listened: exit code 1 (see .next-issue/worker.log)`. A lock whose process is gone, or started at another time, is stale and taken over.
|
|
40
40
|
|
|
@@ -229,7 +229,7 @@ With no file, every field keeps its default. A field that is not in the file kee
|
|
|
229
229
|
| `commandTimeoutMinutes` | `10` | The limit for one `git` or `gh` command, at most `35791` |
|
|
230
230
|
| `concurrency` | `1` | The most issues that an agent works on at the same time; an issue waiting to land or for checks holds no slot |
|
|
231
231
|
| `diffMaxChars` | `60000` | The maximum length of the diff that the reviewer reads |
|
|
232
|
-
| `huntCap` | `1` | With `--hunt`, the hunter hunts only while fewer ready issues than this wait besides the running ones
|
|
232
|
+
| `huntCap` | `1` | With `--hunt on`, the hunter hunts only while fewer ready issues than this wait besides the running ones |
|
|
233
233
|
| `ignoredChecks` | `[]` | Names of GitHub Actions jobs, check runs and commit statuses, such as `release`, that the checks on the base branch do not wait for and whose failure does not count, unless GitHub cancels or skips another job of its run |
|
|
234
234
|
| `issueLimit` | `100` | The maximum number of open issues to read. With `labels.ready` set, only issues with the ready, in-progress or in-review label count |
|
|
235
235
|
| `keepRunDays` | `7` | The number of days to keep the run files; `0` keeps them all |
|
|
@@ -285,27 +285,33 @@ A hand-over marks the state file as handed over once its label and comment reach
|
|
|
285
285
|
|
|
286
286
|
To give guidance, answer the hand-over with a comment on the issue. When the run resumes the issue, it reads the comments posted after its last `### next-issue · Hand-over: needs help` comment there, or its last `next-issue needs help:` comment, the one-line heading of older versions. Only comments from users with write access to the repository count, for the hand-over comment too. A comment that starts with one of the headings of the harness never counts as an answer. The implementer and every fixer of that run get them in their prompt, under the heading `Answer of a person to the hand-over`. When the questions of the implementer did not reach the issue body, the implementer also gets them under that heading, before the answer, or alone when no comment answers them. A short reply such as "ready, take it" is enough. With no such comment, the run resumes with no guidance.
|
|
287
287
|
|
|
288
|
-
To drop an issue instead, close it. The next run that finds a saved state for an issue that a person closed removes that state file, the `<n>` branch, the `<n>-dispute-*` branches and the worktree of the issue. This holds for an issue that waits for a person and for one that a stop left behind. The run starts no agent and makes no push, revert, label change, close or comment, so a change that already landed stays on the base branch. A worktree or branch that cannot be removed stays, and the run log says so. The issue shows as `skipped` (`closed`) in the summary. A
|
|
288
|
+
To drop an issue instead, close it. The next run that finds a saved state for an issue that a person closed removes that state file, the `<n>` branch, the `<n>-dispute-*` branches and the worktree of the issue. This holds for an issue that waits for a person and for one that a stop left behind. The run starts no agent and makes no push, revert, label change, close or comment, so a change that already landed stays on the base branch. A worktree or branch that cannot be removed stays, and the run log says so. The issue shows as `skipped` (`closed`) in the summary. A watching run does not claim an issue again once it ended in `error` in that run, so it leaves such an issue for the next run to clean up.
|
|
289
289
|
|
|
290
290
|
## Commands and options
|
|
291
291
|
|
|
292
|
-
| Argument
|
|
293
|
-
|
|
|
294
|
-
| `start`
|
|
295
|
-
| `
|
|
296
|
-
| `
|
|
297
|
-
| `
|
|
298
|
-
| `
|
|
299
|
-
|
|
|
300
|
-
|
|
|
301
|
-
| `--
|
|
302
|
-
| `--
|
|
292
|
+
| Argument | Effect |
|
|
293
|
+
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
294
|
+
| `start` | Start a run: claim issues, fix them and push them to the base branch |
|
|
295
|
+
| `watch on\|off` | Switch watching of the going run, see [Watch for new issues](#watch-for-new-issues) |
|
|
296
|
+
| `hunt on\|off` | Switch hunting of the going run, see [Hunt for bugs](#hunt-for-bugs) |
|
|
297
|
+
| `init` | Write the config file with the defaults |
|
|
298
|
+
| `serve` | Run the worker of this repository that pi extensions talk to, see [Worker](#worker) |
|
|
299
|
+
| `stop` | Stop the worker of this repository, see [Worker](#worker) |
|
|
300
|
+
| `logs` | Show the latest run log and follow it, see [Observability](#observability) |
|
|
301
|
+
| `--force` | Replace an existing config file, with `init` |
|
|
302
|
+
| `--watch on\|off` | With `start`: on reads the open issues again after each pass, off does one pass and ends. On by default |
|
|
303
|
+
| `--hunt on\|off` | With `start`: hunt the repository for bugs alongside the issues, see [Hunt for bugs](#hunt-for-bugs). Off by default. On needs watching on |
|
|
304
|
+
| `--help` | Show the option list |
|
|
303
305
|
|
|
304
|
-
`--watch` and `--hunt` belong to `start`, and any other command refuses them. `next-issue` with no command prints the option list on standard error, starts nothing and exits with 1.
|
|
306
|
+
`--watch` and `--hunt` belong to `start`, and any other command refuses them. Each takes `on` or `off`: with no value or another value, `start` fails with `--watch takes on or off` (or `--hunt`) and exits with 1. `--hunt on` with `--watch off` fails with `hunting needs watching` and exits with 1. `next-issue` with no command prints the option list on standard error, starts nothing and exits with 1.
|
|
305
307
|
|
|
306
|
-
|
|
308
|
+
`next-issue watch on|off` and `next-issue hunt on|off` switch the run that is going in the worker of this repository, as Watch and Hunt in pi do, with no restart. They print the new settings, such as `next-issue: watching on, hunting off`, and exit with 0. `watch off` also turns hunting off, and `hunt on` also turns watching on. When no worker or no run is going, they print `next-issue: no run is going in this repository`, change nothing, start no worker and exit with 0. With no value or another value, they fail with `watch takes on or off` (or `hunt`) and exit with 1. When the worker is older than the command, they fail and exit with 1, since an older worker may not answer; stop the run and start it again.
|
|
307
309
|
|
|
308
|
-
|
|
310
|
+
The exit code of `next-issue start` is 1 when an issue needs a person or failed, and 0 when it does not, so a cron job or a CI step can read the result of the run. Since `next-issue start` watches by default and does not end on its own, such a job runs `next-issue start --watch off`.
|
|
311
|
+
|
|
312
|
+
Versions before 7.0.0 started a run with no command, as `next-issue` or `next-issue --once`. From 7.0.0 a run needs `next-issue start`, and the old form starts nothing and exits with 1. Later versions dropped `--once`: `next-issue start --once` fails with `Unknown argument: --once` and exits with 1, so use `next-issue start --watch off`, which does one pass and ends.
|
|
313
|
+
|
|
314
|
+
Version 12.0.0 made watching the default: `next-issue start` watches, and `next-issue start --watch off` does one pass and ends, as `next-issue start` did before. `--watch` and `--hunt` now take `on` or `off`, so `--watch` or `--hunt` with no value fails and exits with 1: use `--watch on` and `--hunt on`. Start in pi watches too.
|
|
309
315
|
|
|
310
316
|
Version 11.0.0 dropped `--max <n>`, `--reset`, `--json`, `--verbose` and `--quiet`. `next-issue start` with any of them, and `next-issue logs --json`, fail with `Unknown argument: <flag>` and exit with 1. Instead:
|
|
311
317
|
|
|
@@ -316,7 +322,7 @@ Version 11.0.0 dropped `--max <n>`, `--reset`, `--json`, `--verbose` and `--quie
|
|
|
316
322
|
|
|
317
323
|
## Watch for new issues
|
|
318
324
|
|
|
319
|
-
A run
|
|
325
|
+
A run with `--watch off` ends when no unseen issue is left. With `next-issue start`, or `next-issue start --watch on`, the harness then waits, reads the open issues again and runs another pass, so it picks up an issue that someone opens during the run, or one whose blocker closes. Each pass tries every open issue again, also one that an earlier pass skipped. An issue that failed with an error before the claim is not tried again until the next run. An issue that failed after the claim and was handed over with the needs-human label is tried again once a person answers the hand-over or takes the label off. Within a pass, the harness claims a tried issue again at the next read when its labels differ from those it had after its attempt, so an answered hand-over or an unblocked skipped issue does not wait for the next pass. An issue that is done, or that failed with an error and was not handed over, does not come back in the same pass. The hunter counts the same issues as ready.
|
|
320
326
|
|
|
321
327
|
The waits follow a fixed back-off in minutes: 1, 2, 3, 5, 10, then 10 from then on. A pass that handles an issue, with any outcome other than `skipped`, resets the back-off to 1 minute. A pass where every issue is skipped does not reset it. Each wait prints a line on standard error with the minutes until the next pass.
|
|
322
328
|
|
|
@@ -331,7 +337,7 @@ The watch stops:
|
|
|
331
337
|
|
|
332
338
|
## Hunt for bugs
|
|
333
339
|
|
|
334
|
-
With `next-issue start --hunt`, which
|
|
340
|
+
With `next-issue start --hunt on`, which needs watching on, the harness runs a hunter agent at the same time as the issues. Before each hunt it reads the open issues with the `labels.ready` label and counts those that are ready to claim and are not running. An issue that failed earlier in the run does not count, since the watch does not try it again. It counts a blocked issue only when each of its open blockers is in the same repository and is running or ready to claim, since those blockers can land and close; a blocker that cannot move, such as one with `labels.needsHuman`, `labels.skip` or `labels.done`, one without `labels.ready`, or one in another repository, leaves it out. It looks only at the direct blockers, and reads them one issue at a time, so it runs one `gh` call at a time. It hunts only while that count is less than `huntCap`, 1 by default. Otherwise it waits and checks again, with the same back-off as the watch: 1, 2, 3, 5, 10, then 10 minutes. After a hunt that files an issue, it waits 1 minute before it checks the count again, even when the count is still less than `huntCap`. Each wait writes a `hunt.wait` event with the `minutes` to the run log. A hunt that files nothing backs off like a failed one. When the harness claims an issue, the hunter wakes: it ends its wait at once, or skips the wait after a hunt that is going, and checks the count again. A wake keeps the back-off where it was. The hunter:
|
|
335
341
|
|
|
336
342
|
- works in its own worktree at `.worktrees/hunt`, on a detached `HEAD` at the remote base branch, which the harness fetches and checks out before each hunt. A branch that the hunter checks out keeps its commits, and an issue that resumes never uses the hunt worktree as its own;
|
|
337
343
|
- follows `next-issue.hunt.md` in the repository root, or a short built-in prompt when the file is missing;
|
|
@@ -340,7 +346,7 @@ With `next-issue start --hunt`, which turns on `--watch`, the harness runs a hun
|
|
|
340
346
|
|
|
341
347
|
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.
|
|
342
348
|
|
|
343
|
-
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 Hunt on or Watch on in `/next-issue` of the pi extension, see [Worker](#worker). This works for every run, since `next-issue start` runs in the worker too.
|
|
349
|
+
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 off`, or with Hunt on or Watch on in `/next-issue` of the pi extension, see [Worker](#worker). This works for every run, since `next-issue start` runs in the worker too.
|
|
344
350
|
|
|
345
351
|
## Worker
|
|
346
352
|
|
|
@@ -350,16 +356,16 @@ In a run of the `serve` worker, a client can switch hunting and watching on or o
|
|
|
350
356
|
- holds `.next-issue/worker.lock` in the repository, with its process id and the start time of that process, so only one worker goes per repository. A worker that starts while another process holds the lock exits with `another worker is running`. A lock is stale, and is taken over, when no process has that id or the process with that id started at another time, for example because the system gave the id of a worker that was killed or lost in a reboot to another process. A lock without a start time, from an older version, is held while a process with that id is alive, and stale otherwise. A worker that cannot read its own start time exits with an error and takes no lock. When several workers start at once, one takes the lock and the others exit with `another worker is running`. A worker that stops removes the lock file only while it still holds the lock, and the socket file only while it is still the socket it bound;
|
|
351
357
|
- refuses a `start`, `stop`, `watch`, `hunt`, `questions` or `upcoming` message whose `root` is not the exact path of its repository with an `error` message, and starts or stops nothing;
|
|
352
358
|
- sends each `error` as `{ "type": "error", "root": "<path>", "message": "<text>" }`. When a `start`, `stop`, `watch`, `hunt` or `refresh` message carries an `"id"`, the `error` that refuses it carries the same `id`;
|
|
353
|
-
- runs at most one run at a time. A client starts it with `{ "type": "start", "root": "<path>", "args": [...] }`. Each run is like `next-issue start` with those args, or with none when `args` is left out (the pi extension sends none). It takes `--watch` and `--hunt`, and refuses a command (`start` too), `--force`, `--help` or an unknown argument (such as `--max`, `--reset`, `--json`, `--verbose` or `--quiet`) with an `error` message;
|
|
359
|
+
- runs at most one run at a time. A client starts it with `{ "type": "start", "root": "<path>", "args": [...] }`. Each run is like `next-issue start` with those args, or with none when `args` is left out (the pi extension sends none). It takes `--watch on|off` and `--hunt on|off`, and so watches and does not hunt by default, and refuses a command (`start` too), `--force`, `--help` or an unknown argument (such as `--max`, `--reset`, `--json`, `--verbose` or `--quiet`) with an `error` message;
|
|
354
360
|
- sends every client the progress of every run when it connects and on every change: for each running issue the issue, the step, the tool count and the last tool, and the handled issues (an issue handled in more than one pass appears once for each);
|
|
355
361
|
- sends every client `{ "type": "output", "root": "<path>", "text": "<lines>" }` for each line of a run that `next-issue start` prints on standard error, as the run prints it. The same lines still go to `.next-issue/worker.log`;
|
|
356
|
-
- sends every client `{ "type": "pass", "root": "<path>", "summary": {...} }` after each pass of a run started with
|
|
362
|
+
- sends every client `{ "type": "pass", "root": "<path>", "summary": {...} }` after each pass of a run started with watching on that handled an issue, with the summary of that pass that `next-issue start` prints;
|
|
357
363
|
- sends every client one `{ "type": "end", "root": "<path>", "code": <n>, "summary": {...} }` message when a run ends. `code` is the exit code that `next-issue start` would return for the run, and `summary` is the summary of the whole run, as in `<id>.summary.json` (in a watch run, all passes). A run that fails has `code` 1, no `summary`, and the text that `next-issue start` prints after `next-issue failed: ` in `error`;
|
|
358
364
|
- sends every client a `questions` message for each repository: the open issues with the `needsHuman` label, each with its number, title, the reason of the hand-over, the url of the comment that holds it, the `owner/name` repository, and the `needsHuman`, `skip` and `ready` labels. It reads them from GitHub, so the list is the same after a restart. It sends them when a client connects, for its repository, after each issue of a run ends, and when a client sends `{ "type": "questions", "root": "<path>" }`. An issue that no longer has the label leaves the list, and so does an issue whose hand-over has an answer from a writer, the same answer that lets a run claim it. An issue that a person holds with the label stays in the list, even when an earlier hand-over has an answer. An issue with the label but no hand-over comment is in the list with an empty reason and url. The issues are read one at a time. A client never gets an older list after a newer one. When the client adds an `"id"` to its message, the list that answers it carries the same `id` and is read after the message arrived. When the list cannot be read, the client gets `{ "type": "questions-error", "root": "<path>", "message": "<text>" }`;
|
|
359
365
|
- answers `{ "type": "upcoming", "root": "<path>" }` with `{ "type": "upcoming", "root": "<path>", "claimable": [...], "blocked": [...] }`: the open issues with the `ready` label that a run would claim, oldest first, each with its `issue` number and `title`, without issues that have saved state or a label that stops a claim. An issue blocked by open issues is in `blocked` with their references in `blockers`. When the list cannot be read, the client gets `{ "type": "upcoming-error", "root": "<path>", "message": "<text>" }`;
|
|
360
366
|
- stops a run when a client sends `{ "type": "stop", "root": "<path>", "after": "issue" | "round" | "now" }`. With no `after`, it stops after `issue`. `issue` works like a first `Ctrl-C`: no new claim or hunt, and the held issues and a going hunt finish. `round` works like a second `Ctrl-C`: each running issue stops after its current round, with the state kept, and a going hunt ends first. `now` stops every agent, command and hunt of the run at once, and each running issue ends as `stopped` with its state and labels kept; the worker keeps running. A later point than one already asked for changes nothing, and an earlier one replaces it. An unknown `after` gets an `error` message. While a run is going, the client that sent the stop gets `{ "type": "stopping", "root": "<path>", "waiting": <bool>, "hunting": <bool> }`, with the `id` of the stop when it has one: `waiting` is `true` when the run waited between passes, and `hunting` is `true` when a hunt was going then. `next-issue start` picks its note from it;
|
|
361
|
-
- switches watching of a run on or off when a client sends `{ "type": "watch", "root": "<path>", "on": true | false }`. The run keeps its issues, worktrees and progress, and nothing restarts. A run
|
|
362
|
-
- switches hunting of a run on or off when a client sends `{ "type": "hunt", "root": "<path>", "on": true | false }`. The run keeps its issues, worktrees and progress, and nothing restarts. Every run of the worker has a hunter: a run started with `--hunt` starts with hunting on, and any other run with it off. Off lets a hunt that is going finish, so the issues it files stay, and starts no new hunt. On wakes the hunter at once, with no back-off wait, and also turns watching on. With no run going, the message gets an `error` and starts nothing. The settings last for the run only: a new run takes them from its own flags. The progress of each run carries `hunting`, `true` while hunting is on, and `watching`, `true` when the run watches for issues;
|
|
367
|
+
- switches watching of a run on or off when a client sends `{ "type": "watch", "root": "<path>", "on": true | false }`. The run keeps its issues, worktrees and progress, and nothing restarts. A run starts with watching on, unless it was started with `--watch off`. On keeps the run going after the current pass, as with `--watch on`. Off ends the run after the current pass, or at once when it waits between passes, and also turns hunting off. With no run going, the message gets an `error` and starts nothing;
|
|
368
|
+
- switches hunting of a run on or off when a client sends `{ "type": "hunt", "root": "<path>", "on": true | false }`. The run keeps its issues, worktrees and progress, and nothing restarts. Every run of the worker has a hunter: a run started with `--hunt on` starts with hunting on, and any other run with it off. Off lets a hunt that is going finish, so the issues it files stay, and starts no new hunt. On wakes the hunter at once, with no back-off wait, and also turns watching on. With no run going, the message gets an `error` and starts nothing. The settings last for the run only: a new run takes them from its own flags. The progress of each run carries `hunting`, `true` while hunting is on, and `watching`, `true` when the run watches for issues;
|
|
363
369
|
- asks a watching run to check for new issues now when a client sends `{ "type": "refresh", "root": "<path>" }`. A run that waits between passes starts a new pass at once, and its next wait starts again at 1 minute; a waiting hunter checks the ready count again. A refresh while a pass runs, for a run that is stopping or does not watch, or with no run going, changes nothing and gets no answer;
|
|
364
370
|
- exits, and removes its socket and lock files, when no run is going and no client is connected, or when no client connects in the 30 seconds after it starts;
|
|
365
371
|
- waits up to 5 seconds for the lock when a worker that is closing still holds it;
|
package/dist/args.mjs
CHANGED
|
@@ -2,23 +2,27 @@ import { CONFIG_FILE } from './config-fields.mjs';
|
|
|
2
2
|
const SWITCHES = new Map([
|
|
3
3
|
['--force', 'force'],
|
|
4
4
|
['--help', 'help'],
|
|
5
|
+
]);
|
|
6
|
+
const RUN_FLAGS = new Map([
|
|
5
7
|
['--watch', 'watch'],
|
|
6
8
|
['--hunt', 'hunt'],
|
|
7
9
|
]);
|
|
10
|
+
const COMMANDS = ['start', 'init', 'serve', 'stop', 'logs', 'watch', 'hunt'];
|
|
8
11
|
export const USAGE = `next-issue <command> [options]
|
|
9
12
|
|
|
10
|
-
start
|
|
11
|
-
--watch
|
|
12
|
-
--hunt
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
start start a run: claim issues, fix them and push them to the base branch
|
|
14
|
+
--watch on|off on: read the issues again after each pass; off: do one pass and end (default on)
|
|
15
|
+
--hunt on|off hunt the repository for bugs and file issues alongside the issues, needs watching (default off)
|
|
16
|
+
watch on|off switch watching of the going run; off also turns hunting off
|
|
17
|
+
hunt on|off switch hunting of the going run; on also turns watching on
|
|
18
|
+
init write ${CONFIG_FILE} with the defaults and add .next-issue/ and .worktrees/ to info/exclude
|
|
19
|
+
serve run the worker of this repository that pi extensions talk to
|
|
20
|
+
stop stop the worker of this repository
|
|
21
|
+
logs show the latest run log and follow it
|
|
17
22
|
|
|
18
|
-
--force
|
|
19
|
-
--help
|
|
23
|
+
--force replace an existing config file, with init
|
|
24
|
+
--help show this text
|
|
20
25
|
`;
|
|
21
|
-
const RUN_FLAGS = new Set(['--watch', '--hunt']);
|
|
22
26
|
export function parseArgs(argv) {
|
|
23
27
|
const { args, flag, runFlag } = readArgs(argv);
|
|
24
28
|
if (args.help) {
|
|
@@ -33,15 +37,25 @@ export function parseArgs(argv) {
|
|
|
33
37
|
if (args.command === 'serve' && flag !== undefined) {
|
|
34
38
|
throw new Error(`serve does not take ${flag}`);
|
|
35
39
|
}
|
|
40
|
+
if ((args.command === 'watch' || args.command === 'hunt') && args.on === undefined) {
|
|
41
|
+
throw new Error(`${args.command} takes on or off`);
|
|
42
|
+
}
|
|
36
43
|
return args;
|
|
37
44
|
}
|
|
45
|
+
function onOffValue(name, value) {
|
|
46
|
+
if (value !== 'on' && value !== 'off') {
|
|
47
|
+
throw new Error(`${name} takes on or off`);
|
|
48
|
+
}
|
|
49
|
+
return value === 'on';
|
|
50
|
+
}
|
|
38
51
|
function readArgs(argv) {
|
|
39
52
|
const args = {
|
|
40
53
|
help: false,
|
|
41
54
|
force: false,
|
|
42
|
-
watch:
|
|
55
|
+
watch: true,
|
|
43
56
|
hunt: false,
|
|
44
57
|
};
|
|
58
|
+
const given = {};
|
|
45
59
|
let flag;
|
|
46
60
|
let runFlag;
|
|
47
61
|
for (let index = 0; index < argv.length; index += 1) {
|
|
@@ -49,27 +63,39 @@ function readArgs(argv) {
|
|
|
49
63
|
if ((index !== 0 || arg.startsWith('-')) && arg !== '--help') {
|
|
50
64
|
flag ??= arg;
|
|
51
65
|
}
|
|
52
|
-
if (RUN_FLAGS.has(arg)) {
|
|
53
|
-
runFlag ??= arg;
|
|
54
|
-
}
|
|
55
66
|
if (index === 0 && !arg.startsWith('-')) {
|
|
56
67
|
args.command = command(arg);
|
|
57
68
|
}
|
|
69
|
+
else if (index === 1 &&
|
|
70
|
+
(args.command === 'watch' || args.command === 'hunt') &&
|
|
71
|
+
!arg.startsWith('-')) {
|
|
72
|
+
args.on = onOffValue(args.command, arg);
|
|
73
|
+
}
|
|
58
74
|
else if (SWITCHES.has(arg)) {
|
|
59
75
|
args[SWITCHES.get(arg)] = true;
|
|
60
76
|
}
|
|
77
|
+
else if (RUN_FLAGS.has(arg)) {
|
|
78
|
+
runFlag ??= arg;
|
|
79
|
+
index += 1;
|
|
80
|
+
given[RUN_FLAGS.get(arg)] = onOffValue(arg, argv[index]);
|
|
81
|
+
}
|
|
61
82
|
else {
|
|
62
83
|
throw new Error(`Unknown argument: ${arg}`);
|
|
63
84
|
}
|
|
64
85
|
}
|
|
65
|
-
|
|
86
|
+
if (given.hunt === true && given.watch === false) {
|
|
87
|
+
throw new Error('hunting needs watching: --hunt on does not go with --watch off');
|
|
88
|
+
}
|
|
89
|
+
args.watch = given.watch ?? true;
|
|
90
|
+
args.hunt = given.hunt ?? false;
|
|
66
91
|
return { args, flag, runFlag };
|
|
67
92
|
}
|
|
68
93
|
function command(arg) {
|
|
69
|
-
|
|
94
|
+
const found = COMMANDS.find((name) => name === arg);
|
|
95
|
+
if (found === undefined) {
|
|
70
96
|
throw new Error(`Unknown command: ${arg}`);
|
|
71
97
|
}
|
|
72
|
-
return
|
|
98
|
+
return found;
|
|
73
99
|
}
|
|
74
100
|
const OUTPUT_ONLY = ['force', 'help'];
|
|
75
101
|
export function parseStartArgs(argv) {
|
package/dist/cli.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { followLog, newestRunLog } from './logs.mjs';
|
|
|
10
10
|
import { serve } from './serve.mjs';
|
|
11
11
|
import { startInWorker } from './start.mjs';
|
|
12
12
|
import { STATE_DIR } from './state.mjs';
|
|
13
|
+
import { switchInWorker } from './switch-run.mjs';
|
|
13
14
|
import { workerPaths } from './worker-paths.mjs';
|
|
14
15
|
import { WORKTREE_DIR } from './worktree.mjs';
|
|
15
16
|
function write(stream, text) {
|
|
@@ -36,6 +37,10 @@ async function main() {
|
|
|
36
37
|
if (args.command === 'stop') {
|
|
37
38
|
return stop(root);
|
|
38
39
|
}
|
|
40
|
+
if (args.command === 'watch' || args.command === 'hunt') {
|
|
41
|
+
await write(process.stdout, await switchInWorker(root, args.command, args.on));
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
39
44
|
if (args.command === 'logs') {
|
|
40
45
|
return logs(root);
|
|
41
46
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { isNewer } from './protocol.mjs';
|
|
3
|
+
import { packageVersion } from './version.mjs';
|
|
4
|
+
import { CLOSED, findWorker, going } from './worker-client.mjs';
|
|
5
|
+
const FIELDS = { watch: 'watching', hunt: 'hunting' };
|
|
6
|
+
const NO_RUN = 'next-issue: no run is going in this repository\n';
|
|
7
|
+
function onOffText(on) {
|
|
8
|
+
return on === true ? 'on' : 'off';
|
|
9
|
+
}
|
|
10
|
+
export async function switchInWorker(root, name, on) {
|
|
11
|
+
const connection = await findWorker(root);
|
|
12
|
+
if (connection === undefined) {
|
|
13
|
+
return NO_RUN;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
if (!going(connection.runs[root])) {
|
|
17
|
+
return NO_RUN;
|
|
18
|
+
}
|
|
19
|
+
if (isNewer(await packageVersion(), connection.version)) {
|
|
20
|
+
throw new Error(`the worker of the going run is older than next-issue, so it cannot switch ${FIELDS[name]}. Stop the run, then start it again`);
|
|
21
|
+
}
|
|
22
|
+
const progress = await switched(connection, root, name, on);
|
|
23
|
+
return `next-issue: watching ${onOffText(progress.watching)}, hunting ${onOffText(progress.hunting)}\n`;
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
connection.close();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function switched(connection, root, name, on) {
|
|
30
|
+
const id = randomUUID();
|
|
31
|
+
let sent = false;
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
connection.listen((message) => {
|
|
34
|
+
if (!sent) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const progress = message.type === 'runs' ? message.runs[root] : undefined;
|
|
38
|
+
if (progress !== undefined && progress[FIELDS[name]] === on) {
|
|
39
|
+
resolve(progress);
|
|
40
|
+
}
|
|
41
|
+
else if (message.type === 'error' && message.id === id) {
|
|
42
|
+
reject(new Error(message.message));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
void connection.closed.then(() => reject(new Error(CLOSED)));
|
|
46
|
+
connection.send({ type: name, root, on, id });
|
|
47
|
+
sent = true;
|
|
48
|
+
});
|
|
49
|
+
}
|
package/dist/worker-client.mjs
CHANGED
|
@@ -70,7 +70,7 @@ function open(socketPath, version) {
|
|
|
70
70
|
else if (message.type === 'runs') {
|
|
71
71
|
ready = true;
|
|
72
72
|
clearTimeout(timer);
|
|
73
|
-
if (!Object.values(message.runs).some(going)) {
|
|
73
|
+
if (version !== undefined && !Object.values(message.runs).some(going)) {
|
|
74
74
|
socket.send(JSON.stringify({ type: 'hello', version }));
|
|
75
75
|
}
|
|
76
76
|
resolve({
|
|
@@ -154,6 +154,11 @@ export async function reachWorker(root, version) {
|
|
|
154
154
|
found.close();
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
+
export function findWorker(root) {
|
|
158
|
+
const { socketPath } = workerPaths(root);
|
|
159
|
+
checkSocketPath(socketPath);
|
|
160
|
+
return tryOpen(socketPath);
|
|
161
|
+
}
|
|
157
162
|
function exitText(code, signal) {
|
|
158
163
|
return signal === null ? `exit code ${code}` : `signal ${signal}`;
|
|
159
164
|
}
|