next-issue 10.7.4 → 11.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 CHANGED
@@ -34,13 +34,13 @@ 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 (`--max`, `--verbose`, `--quiet`), `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`, `--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.
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
 
41
41
  Every command uses the main worktree of the repository as its root, the first one that `git worktree list` shows, even when it runs in a linked worktree. So `.next-issue/`, with the config, the locks, the worker socket, the saved state and the notes, and `.worktrees/` are always in the main worktree, and a run or worker started from a linked worktree gets the same refusal as one started from the main worktree.
42
42
 
43
- A run works on up to `concurrency` issues with an agent at the same time, 1 by default. Each claimed issue takes a slot. An approved issue frees its slot while it waits to land, while it lands and while it waits for the checks on the base, so the next issue's agents never wait for CI. When such an issue needs an agent again, for example the fixer for a conflict or for failed checks, it waits for a free slot, takes it before any new issue is claimed and frees it once the agent ends. So no more than `concurrency` agents run at once. When a slot frees up, the run claims the oldest unseen issue for it, and fetches the open issues again only when the last fetch left an unseen issue unclaimed or an issue has ended since. The run ends only once every issue has ended, including those waiting to land. Each issue has its own worktree and branch. Step 3 below and the removal of a worktree or branch run for one issue at a time, so two issues never change the git refs or worktrees of the repository at once. An issue skipped as blocked is tried again in that run once another issue is done, so an issue blocked by one that waits to land is claimed once its blocker closes. `--max <n>` counts the handled issues across the run, so with `--max 1` the run handles one issue. For each issue:
43
+ A run works on up to `concurrency` issues with an agent at the same time, 1 by default. Each claimed issue takes a slot. An approved issue frees its slot while it waits to land, while it lands and while it waits for the checks on the base, so the next issue's agents never wait for CI. When such an issue needs an agent again, for example the fixer for a conflict or for failed checks, it waits for a free slot, takes it before any new issue is claimed and frees it once the agent ends. So no more than `concurrency` agents run at once. When a slot frees up, the run claims the oldest unseen issue for it, and fetches the open issues again only when the last fetch left an unseen issue unclaimed or an issue has ended since. The run ends only once every issue has ended, including those waiting to land. Each issue has its own worktree and branch. Step 3 below and the removal of a worktree or branch run for one issue at a time, so two issues never change the git refs or worktrees of the repository at once. An issue skipped as blocked is tried again in that run once another issue is done, so an issue blocked by one that waits to land is claimed once its blocker closes. For each issue:
44
44
 
45
45
  1. Claim the issue only when it holds the `status:todo` label and holds no `status:in-progress` or `status:in-review` label. A `status:done`, `status:needs-human` or `status:blocked` label always stops the claim, a resume too, except a `status:needs-human` issue with an answer to its hand-over that the run made, and except an issue whose finish a stop cut short and that was not handed over (see step 7 below). An issue that GitHub lists as blocked by an open issue waits, because its blocker closes only when the change of the blocker lands. An issue with saved state under `.next-issue/` resumes instead, whatever its other labels and blockers.
46
46
  2. Add `status:in-progress` to the issue.
@@ -137,13 +137,13 @@ No person checks a change before it lands. To replace those checks, [ADR 0004](h
137
137
 
138
138
  Every run has an id, `<timestamp>`, and writes these under `.next-issue/runs/`:
139
139
 
140
- - `<id>.jsonl` — one JSON object per event, with `ts`, `runId`, `kind`, and the `issue`, `role` or `round` in scope;
140
+ - `<id>.jsonl` — one JSON object per event, with `ts`, `runId`, `kind`, and the `issue`, `role` or `round` in scope. A run whose fetch of the issues fails ends with an `issues.fail` event. A run that fails in any other way once this file is open, for example when `gh repo view` fails at the start or an issue crashes the run, ends with a `run.fail` event (after `run.end` when the run got that far). Both carry the `error`;
141
141
  - `<id>.summary.json` — token totals per agent role, event counts, and one report per issue with the outcome, the reason and the budgets used (in a watch run, an issue skipped in several passes gets one report, and an issue handled in more than one pass keeps a report for each; when an issue crashes the run, the file still holds the reports of the issues that finished);
142
142
  - `<id>/sessions/` — the full pi session of each agent call, with every message, tool call and tool result. The session id in a `usage` event is part of the file name.
143
143
 
144
144
  At the start of a run, the harness deletes the files and folders under `.next-issue/runs/` that are older than `keepRunDays`. The age of a folder is the time since the last change to it or to anything inside it, so the sessions of a long run stay while it still writes them. Set the field to `0` to keep them all.
145
145
 
146
- A short text summary of the same data goes to standard output. Use `--json` to get the full summary object there instead, so the harness fits in a pipe. All progress goes to standard error.
146
+ A short text summary of the same data goes to standard output. All progress goes to standard error.
147
147
 
148
148
  Recorded for each step: `claim`, `comments`, `reply`, `worktree`, `setup`, `editors`, `implement`, `review`, `fix`, `commit-fix`, `rebase`, `land`, `ci-checks`, `revert` and `hunt`, each with a `.start`, `.end` or `.error` event and a duration in `ms`. Every `git` and `gh` command is recorded with its exit code and duration. A `tool` event holds the tool name. For a `bash` tool it holds the command too, and for a `read`, `write`, `edit`, `grep`, `find` or `ls` tool the `path` it got, relative to the worktree when inside it. Each agent call adds a `usage` event with the tokens, the turn count, the tool-call count, the model and the session id. A call that times out, ends with a model error or is stopped after its session started adds one too, and its tokens count in the summary totals.
149
149
 
@@ -152,15 +152,9 @@ jq -r 'select(.kind=="usage") | [.issue,.role,.turns,.total] | @tsv' \
152
152
  .next-issue/runs/*.jsonl
153
153
  ```
154
154
 
155
- `next-issue logs` shows the newest run log, one readable line per event, and then prints new events as the run adds them, until `Ctrl-C`. In a terminal it starts with the last events that fit the screen; in a pipe it starts with all of them. It stops when the reader of the pipe closes it; on Linux it notices this only at the next event. When the worker restarts and starts a new run log, `logs` prints the rest of the old one, then a line `— new run: <file name> —`, then every event of the new one. With `--json` it prints the raw JSON lines and no such line. This also shows a run of the worker, whose progress goes to no terminal.
155
+ `next-issue logs` shows the newest run log, one readable line per event, and then prints new events as the run adds them, until `Ctrl-C`. In a terminal it starts with the last events that fit the screen; in a pipe it starts with all of them. It stops when the reader of the pipe closes it; on Linux it notices this only at the next event. When the worker restarts and starts a new run log, `logs` prints the rest of the old one, then a line `— new run: <file name> —`, then every event of the new one. This also shows a run of the worker, whose progress goes to no terminal.
156
156
 
157
- Three levels of console output:
158
-
159
- | Level | Shows |
160
- | ----------- | ---------------------------------------------------------------- |
161
- | `--quiet` | Run and issue milestones, verdicts, hand-overs, errors |
162
- | default | The above plus each step end, each tool call and failed commands |
163
- | `--verbose` | The above plus every command and all agent text |
157
+ The console shows the run and issue milestones, verdicts, hand-overs, errors, each step end, each tool call and failed commands. It leaves out each step start, each command that succeeds, the output of the checks and the agent text; the run log and the sessions hold them.
164
158
 
165
159
  ## Requirements
166
160
 
@@ -291,34 +285,34 @@ A hand-over marks the state file as handed over once its label and comment reach
291
285
 
292
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.
293
287
 
294
- The `--reset` flag does the same for any issue that the run handles, whether or not it was handed over. It touches only an issue that the run handles, so the state of an issue that a label still holds back stays as it was.
295
-
296
- 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 and does not count for `--max`. A `--watch` 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.
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 `--watch` 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.
297
289
 
298
290
  ## Commands and options
299
291
 
300
- | Argument | Effect |
301
- | ----------- | ---------------------------------------------------------------------------------------------------- |
302
- | `start` | Start a run: claim issues, fix them and push them to the base branch |
303
- | `init` | Write the config file with the defaults |
304
- | `serve` | Run the worker of this repository that pi extensions talk to, see [Worker](#worker) |
305
- | `stop` | Stop the worker of this repository, see [Worker](#worker) |
306
- | `logs` | Show the latest run log and follow it, see [Observability](#observability) |
307
- | `--force` | Replace an existing config file, with `init` |
308
- | `--max <n>` | Handle at most n issues, with `start` |
309
- | `--watch` | Keep running, and read the open issues again after each pass, with `start` |
310
- | `--hunt` | Hunt the repository for bugs alongside the issues, with `start`, see [Hunt for bugs](#hunt-for-bugs) |
311
- | `--reset` | Drop the saved budgets and findings, and keep the rest of the state, with `start` |
312
- | `--json` | Print the machine summary instead of the text one, or the raw JSON lines with `logs` |
313
- | `--verbose` | Show every command and all agent output |
314
- | `--quiet` | Show only the milestones and the summary |
315
- | `--help` | Show the option list |
316
-
317
- `--max <n>`, `--watch`, `--hunt` and `--reset` 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.
292
+ | Argument | Effect |
293
+ | --------- | ---------------------------------------------------------------------------------------------------- |
294
+ | `start` | Start a run: claim issues, fix them and push them to the base branch |
295
+ | `init` | Write the config file with the defaults |
296
+ | `serve` | Run the worker of this repository that pi extensions talk to, see [Worker](#worker) |
297
+ | `stop` | Stop the worker of this repository, see [Worker](#worker) |
298
+ | `logs` | Show the latest run log and follow it, see [Observability](#observability) |
299
+ | `--force` | Replace an existing config file, with `init` |
300
+ | `--watch` | Keep running, and read the open issues again after each pass, with `start` |
301
+ | `--hunt` | Hunt the repository for bugs alongside the issues, with `start`, see [Hunt for bugs](#hunt-for-bugs) |
302
+ | `--help` | Show the option list |
303
+
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.
318
305
 
319
306
  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.
320
307
 
321
- 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 --max 1`.
308
+ 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`, which does one pass and ends.
309
+
310
+ 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
+
312
+ - for `--max <n>`, take the ready label off the issues that the run should leave, or stop the run with `Ctrl-C`;
313
+ - for `--reset`, there is no direct replacement: a handed-over issue still resumes with its budgets and findings at zero once a person answers it or takes the needs-human label off, and closing an issue drops its saved state;
314
+ - for `start --json`, read `.next-issue/runs/<id>.summary.json`; for `logs --json`, read `.next-issue/runs/<id>.jsonl`;
315
+ - for `--verbose`, read the run log and the sessions under `.next-issue/runs/`; for `--quiet`, filter the output, for example with `grep`.
322
316
 
323
317
  ## Watch for new issues
324
318
 
@@ -326,7 +320,7 @@ A run without `--watch` ends when no unseen issue is left. With `next-issue star
326
320
 
327
321
  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.
328
322
 
329
- After each pass that handled an issue, the harness prints the summary of that pass. The token totals in it cover that pass only. The exit code at the end covers all passes. `--max <n>` counts the handled issues across all passes.
323
+ After each pass that handled an issue, the harness prints the summary of that pass. The token totals in it cover that pass only. The exit code at the end covers all passes.
330
324
 
331
325
  The watch stops:
332
326
 
@@ -356,11 +350,11 @@ In a run of the `serve` worker, a client can switch hunting and watching on or o
356
350
  - 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;
357
351
  - 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;
358
352
  - 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`;
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 `--max <n>`, `--watch`, `--hunt`, `--reset`, `--verbose` and `--quiet`, and refuses a command (`start` too), `--json`, `--force`, `--help` or an unknown argument with an `error` message;
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;
360
354
  - 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);
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 and at the level of the run (`--verbose`, `--quiet` or the default). The same lines still go to `.next-issue/worker.log`;
355
+ - 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`;
362
356
  - sends every client `{ "type": "pass", "root": "<path>", "summary": {...} }` after each pass of a run started with `--watch` or `--hunt` that handled an issue, with the summary of that pass that `next-issue start` prints;
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 that `next-issue start --json` prints (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`;
357
+ - 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`;
364
358
  - 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>" }`;
365
359
  - 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>" }`;
366
360
  - 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;
@@ -26,7 +26,7 @@ export async function openSession(recorder, log, request, agentDir) {
26
26
  ...(model === undefined ? {} : { model }),
27
27
  });
28
28
  if (modelFallbackMessage !== undefined) {
29
- log.event('agent.model', { note: modelFallbackMessage }, 'quiet');
29
+ log.event('agent.model', { note: modelFallbackMessage });
30
30
  }
31
31
  return session;
32
32
  }
package/dist/agents.mjs CHANGED
@@ -132,12 +132,7 @@ function observe(log, event, cwd) {
132
132
  log.event('tool', toolFields(event.toolName, event.args, cwd));
133
133
  }
134
134
  else if (event.type === 'tool_execution_end' && event.isError) {
135
- log.event('tool.error', { tool: event.toolName }, 'quiet');
136
- }
137
- else if (event.type === 'message_update' &&
138
- event.assistantMessageEvent.type === 'text_delta' &&
139
- log.level === 'verbose') {
140
- log.print(event.assistantMessageEvent.delta);
135
+ log.event('tool.error', { tool: event.toolName });
141
136
  }
142
137
  }
143
138
  const PATH_TOOLS = new Set(['read', 'write', 'edit', 'grep', 'find', 'ls']);
package/dist/args.mjs CHANGED
@@ -1,35 +1,24 @@
1
1
  import { CONFIG_FILE } from './config-fields.mjs';
2
2
  const SWITCHES = new Map([
3
3
  ['--force', 'force'],
4
- ['--json', 'json'],
5
4
  ['--help', 'help'],
6
5
  ['--watch', 'watch'],
7
6
  ['--hunt', 'hunt'],
8
- ['--reset', 'reset'],
9
- ]);
10
- const LEVELS = new Map([
11
- ['--verbose', 'verbose'],
12
- ['--quiet', 'quiet'],
13
7
  ]);
14
8
  export const USAGE = `next-issue <command> [options]
15
9
 
16
10
  start start a run: claim issues, fix them and push them to the base branch
17
- --max <n> handle at most n issues
18
11
  --watch keep running and read the issues again after each pass
19
12
  --hunt hunt the repository for bugs and file issues alongside the issues, turns on --watch
20
- --reset drop the saved budgets and findings first
21
13
  init write ${CONFIG_FILE} with the defaults and add .next-issue/ and .worktrees/ to info/exclude
22
14
  serve run the worker of this repository that pi extensions talk to
23
15
  stop stop the worker of this repository
24
16
  logs show the latest run log and follow it
25
17
 
26
- --json print the machine summary instead of the text one, or raw lines with logs
27
18
  --force replace an existing config file, with init
28
- --verbose show every command and all agent output
29
- --quiet show only the milestones and the summary
30
19
  --help show this text
31
20
  `;
32
- const RUN_FLAGS = new Set(['--max', '--watch', '--hunt', '--reset']);
21
+ const RUN_FLAGS = new Set(['--watch', '--hunt']);
33
22
  export function parseArgs(argv) {
34
23
  const { args, flag, runFlag } = readArgs(argv);
35
24
  if (args.help) {
@@ -49,12 +38,9 @@ export function parseArgs(argv) {
49
38
  function readArgs(argv) {
50
39
  const args = {
51
40
  help: false,
52
- json: false,
53
- reset: false,
54
41
  force: false,
55
42
  watch: false,
56
43
  hunt: false,
57
- level: 'normal',
58
44
  };
59
45
  let flag;
60
46
  let runFlag;
@@ -72,12 +58,6 @@ function readArgs(argv) {
72
58
  else if (SWITCHES.has(arg)) {
73
59
  args[SWITCHES.get(arg)] = true;
74
60
  }
75
- else if (LEVELS.has(arg)) {
76
- args.level = LEVELS.get(arg);
77
- }
78
- else if (arg === '--max') {
79
- args.max = whole(argv[++index], arg);
80
- }
81
61
  else {
82
62
  throw new Error(`Unknown argument: ${arg}`);
83
63
  }
@@ -91,14 +71,7 @@ function command(arg) {
91
71
  }
92
72
  return arg;
93
73
  }
94
- function whole(value, option) {
95
- const parsed = Number(value);
96
- if (value === undefined || !Number.isInteger(parsed) || parsed < 1) {
97
- throw new Error(`${option} needs a whole number of 1 or more`);
98
- }
99
- return parsed;
100
- }
101
- const OUTPUT_ONLY = ['json', 'force', 'help'];
74
+ const OUTPUT_ONLY = ['force', 'help'];
102
75
  export function parseStartArgs(argv) {
103
76
  const { args } = readArgs(argv);
104
77
  if (args.command !== undefined) {
package/dist/cli.mjs CHANGED
@@ -37,7 +37,7 @@ async function main() {
37
37
  return stop(root);
38
38
  }
39
39
  if (args.command === 'logs') {
40
- return logs(root, args.json);
40
+ return logs(root);
41
41
  }
42
42
  await excludeStateDirectories(root, process.stderr);
43
43
  if (args.command === 'serve') {
@@ -47,7 +47,7 @@ async function main() {
47
47
  }
48
48
  function run(root, args, argv) {
49
49
  process.stderr.on('error', () => { });
50
- return startInWorker(root, args, argv.slice(1).filter((arg) => arg !== '--json' && arg !== '--force'));
50
+ return startInWorker(root, args, argv.slice(1).filter((arg) => arg !== '--force'));
51
51
  }
52
52
  const STOPPED = {
53
53
  none: () => 'next-issue: no worker is running\n',
@@ -58,14 +58,14 @@ async function stop(root) {
58
58
  await write(process.stdout, STOPPED[stopped](pid));
59
59
  return 0;
60
60
  }
61
- async function logs(root, json) {
61
+ async function logs(root) {
62
62
  const file = await newestRunLog(root);
63
63
  if (file === undefined) {
64
64
  await write(process.stderr, `next-issue: no run log in ${STATE_DIR}/runs\n`);
65
65
  return 1;
66
66
  }
67
67
  const tail = process.stdout.isTTY ? Math.max(1, (process.stdout.rows || 24) - 1) : undefined;
68
- return followLog(root, file, { json, tail }, (text) => write(process.stdout, text));
68
+ return followLog(root, file, { tail }, (text) => write(process.stdout, text));
69
69
  }
70
70
  async function init(root, force) {
71
71
  const moved = await moveOldConfig(root, force);
@@ -2,13 +2,20 @@ import { AsyncLocalStorage } from 'node:async_hooks';
2
2
  import { setCommandObserver, succeeded } from './exec.mjs';
3
3
  const commandRecorder = new AsyncLocalStorage();
4
4
  setCommandObserver((record) => {
5
- commandRecorder.getStore()?.event(succeeded(record) ? 'command' : 'command.fail', {
5
+ const recorder = commandRecorder.getStore();
6
+ const fields = {
6
7
  cmd: `${record.command} ${record.args.join(' ')}`,
7
8
  code: record.code,
8
9
  ms: record.ms,
9
10
  stderr: record.stderr.length > 0 ? record.stderr : undefined,
10
11
  timedOut: record.timedOut ? true : undefined,
11
- }, succeeded(record) ? 'verbose' : 'quiet');
12
+ };
13
+ if (succeeded(record)) {
14
+ recorder?.record('command', fields);
15
+ }
16
+ else {
17
+ recorder?.event('command.fail', fields);
18
+ }
12
19
  });
13
20
  export function recordCommands(recorder, work) {
14
21
  return commandRecorder.run(recorder, work);
package/dist/conflict.mjs CHANGED
@@ -12,7 +12,7 @@ export async function rebase(job) {
12
12
  const before = await ports.revision(worktree);
13
13
  const { target, files, unmarked } = await log.step('rebase', { base }, () => ports.startMerge(worktree, base, config.remote));
14
14
  if (files !== undefined) {
15
- log.event('rebase.conflicts', { files }, 'quiet');
15
+ log.event('rebase.conflicts', { files });
16
16
  if (unmarked.length > 0) {
17
17
  await ports.abortMerge(worktree, before);
18
18
  return escalateAndFinish(job, `The change conflicts with ${base} in files that hold no conflict marker, such as a deleted, renamed or binary file: ${unmarked.join(', ')}.`, 'merge conflict');
package/dist/fix.mjs CHANGED
@@ -42,7 +42,7 @@ export async function fixRound(job, reason, detail, earlier, kind) {
42
42
  job.state.title = title;
43
43
  }
44
44
  if (!committed) {
45
- log.event('commit.empty', { reason }, 'quiet');
45
+ log.event('commit.empty', { reason });
46
46
  return { committed: false };
47
47
  }
48
48
  return { committed: true };
@@ -67,12 +67,12 @@ async function disputedFix(job, before, reason, note, kind) {
67
67
  const aside = `${branch}-dispute-${disputed.slice(0, 7)}`;
68
68
  await ports.setAside(worktree, before, aside);
69
69
  job.asides.push(aside);
70
- log.event('fix.aside', { branch: aside, saved }, 'quiet');
70
+ log.event('fix.aside', { branch: aside, saved });
71
71
  return disputedNote(job, reason, note, { stray: true, aside });
72
72
  }
73
73
  function disputedNote(job, reason, note, left) {
74
74
  const event = 'unrelated' in note ? 'fix.unrelated' : 'fix.resolved';
75
- job.log.event(event, { reason, note: Object.values(note)[0], ...left }, 'quiet');
75
+ job.log.event(event, { reason, note: Object.values(note)[0], ...left });
76
76
  return { committed: false, ...note, ...left };
77
77
  }
78
78
  export async function commitWork(job, before, subject, role, commit) {
@@ -107,7 +107,7 @@ async function hookFix(job, error, subject, role) {
107
107
  state.commitFixes = used + 1;
108
108
  await writeState(repo, state);
109
109
  const output = keepTail(message(error), config.logMaxChars);
110
- log.event('commit.fail', { role, output }, 'quiet');
110
+ log.event('commit.fail', { role, output });
111
111
  const fix = await log.step('commit-fix', { role, round: state.commitFixes, limit: config.maxCommitFixes }, () => runRole(job, role, hookPrompt(issue, comments, role, output), CODING));
112
112
  return parseCommitSubject(fix.text, subject);
113
113
  }
package/dist/gate.mjs CHANGED
@@ -133,7 +133,7 @@ async function failedChecksFix(job, sha, refused) {
133
133
  }
134
134
  const named = namedFile(logs, files);
135
135
  if (named !== undefined) {
136
- log.event('fix.refused', { file: named }, 'quiet');
136
+ log.event('fix.refused', { file: named });
137
137
  return failedChecksFix(job, sha, named);
138
138
  }
139
139
  }
@@ -114,7 +114,7 @@ async function waitingQuestion(repo, config, ports, writer, issue) {
114
114
  export async function writerComments(context, log, issue) {
115
115
  const { repo, ports } = context;
116
116
  const comments = (await ports.issueComments(repo, issue)).filter((comment) => !fromHarness(comment));
117
- return writerQuotes(comments, writers(repo, ports), (comment) => log.event('comment.skip', { author: comment.author }, 'quiet'));
117
+ return writerQuotes(comments, writers(repo, ports), (comment) => log.event('comment.skip', { author: comment.author }));
118
118
  }
119
119
  export async function handOverReply(context, issue, pending) {
120
120
  const { repo, ports } = context;
package/dist/handover.mjs CHANGED
@@ -19,7 +19,7 @@ export async function escalateAndFinish(job, note, reason) {
19
19
  throw error;
20
20
  }
21
21
  const failure = message(error);
22
- job.log.event('hand-over.error', { reason, error: failure }, 'quiet');
22
+ job.log.event('hand-over.error', { reason, error: failure });
23
23
  return {
24
24
  done: true,
25
25
  report: await finish(job, 'error', `${reason}; the hand-over failed: ${failure}`),
@@ -67,14 +67,14 @@ export async function finishClosing(context, issue, log, state, started) {
67
67
  return (await finishDone(job)).report;
68
68
  }
69
69
  export async function dropClosed(context, log, issue, branch) {
70
- log.event('issue.drop', { title: issue.title, reason: 'closed' }, 'quiet');
70
+ log.event('issue.drop', { title: issue.title, reason: 'closed' });
71
71
  try {
72
72
  await cleanUp(context, log, branch);
73
73
  await deleteBranches(context, log, branch);
74
74
  await dropState(context.repo, issue.number);
75
75
  }
76
76
  catch (error) {
77
- log.event('drop.error', { error: message(error) }, 'quiet');
77
+ log.event('drop.error', { error: message(error) });
78
78
  }
79
79
  return {
80
80
  issue: issue.number,
@@ -86,11 +86,11 @@ export async function dropClosed(context, log, issue, branch) {
86
86
  };
87
87
  }
88
88
  export function stop(job, reason) {
89
- job.log.event('issue.stop', { phase: job.state.phase, reason }, 'quiet');
89
+ job.log.event('issue.stop', { phase: job.state.phase, reason });
90
90
  return jobReport(job, 'stopped', reason);
91
91
  }
92
92
  export function stopNow(log, issue, state, started) {
93
- log.event('issue.stop', { phase: state.phase }, 'quiet');
93
+ log.event('issue.stop', { phase: state.phase });
94
94
  return issueReport(issue.number, 'stopped', state, started);
95
95
  }
96
96
  function jobReport(job, outcome, reason) {
@@ -131,7 +131,7 @@ async function deleteBranches(context, log, branch) {
131
131
  }
132
132
  async function removeOrKeep(context, log, kind, fields, remove) {
133
133
  if (!(await oneAtATime(context.repo.root, remove))) {
134
- log.event(kind, fields, 'quiet');
134
+ log.event(kind, fields);
135
135
  }
136
136
  }
137
137
  async function cleanUp(context, log, branch) {
@@ -144,12 +144,12 @@ async function cleanUp(context, log, branch) {
144
144
  await removeOrKeep(context, log, 'worktree.kept', { path }, () => ports.removeWorktree(repo, path));
145
145
  }
146
146
  catch (error) {
147
- log.event('worktree.error', { error: message(error) }, 'quiet');
147
+ log.event('worktree.error', { error: message(error) });
148
148
  }
149
149
  }
150
150
  async function handOver(context, log, issue, state, reason, earlier) {
151
151
  const { repo, ports, config } = context;
152
- log.event('hand-over', { reason }, 'quiet');
152
+ log.event('hand-over', { reason });
153
153
  const { pendingHandOver: _pending, ...rest } = state;
154
154
  // Once the label is on, the issue is taken back from a close (`finishDone`) it may have reached.
155
155
  const { closing: _closing, ...taken } = rest;
@@ -204,7 +204,7 @@ export async function claimedError(context, log, issue, state, error, started) {
204
204
  handedOver = true;
205
205
  }
206
206
  catch (failure) {
207
- log.event('hand-over.error', { error: message(failure) }, 'quiet');
207
+ log.event('hand-over.error', { error: message(failure) });
208
208
  }
209
209
  // The issue ends (and the waiting questions go out) only once the hand-over is done.
210
210
  logIssueError(log, error, started);
package/dist/hunt.mjs CHANGED
@@ -64,7 +64,7 @@ export async function hunt(context, count) {
64
64
  });
65
65
  const urls = await issuesOf(context, [...result.text.matchAll(FILED)].map((match) => match[1]));
66
66
  for (const url of urls.length === 0 ? ['none'] : urls) {
67
- recorder.event('hunt.issue', { url }, 'quiet');
67
+ recorder.event('hunt.issue', { url });
68
68
  }
69
69
  return urls.length > 0;
70
70
  });
@@ -40,7 +40,7 @@ async function askQuestions(job, before, questions) {
40
40
  await ports.editIssueBody(repo, issue.number, withOpenQuestions(fresh.body, questions));
41
41
  }
42
42
  catch (error) {
43
- log.event('questions.body-failed', { error: message(error) }, 'quiet');
43
+ log.event('questions.body-failed', { error: message(error) });
44
44
  state.unpostedQuestions = questions;
45
45
  }
46
46
  return escalateAndFinish(job, `The implementer has questions about the issue.\n\n${numbered(questions)}`, 'questions');
@@ -55,7 +55,7 @@ async function useEarlierCommit(job) {
55
55
  }
56
56
  return escalateAndFinish(job, noChangeNote(state.implementerReply ?? ''), 'no implementation commit');
57
57
  }
58
- log.event('implement.earlier', { subject: earlier }, 'quiet');
58
+ log.event('implement.earlier', { subject: earlier });
59
59
  state.title = earlier;
60
60
  return undefined;
61
61
  }
package/dist/land.mjs CHANGED
@@ -60,7 +60,7 @@ async function unblocked(job, work) {
60
60
  }
61
61
  // Landing now would build on a commit whose checks nobody read. The run claims no more issues, but it does not
62
62
  // set `context.halted`: a blocking issue already running must still resume and check its commit on the base.
63
- log.event('land.blocked', { issues: unchecked }, 'quiet');
63
+ log.event('land.blocked', { issues: unchecked });
64
64
  const held = await holdBack(job, 'base unchecked');
65
65
  return { ...held, report: { ...held.report, halt: true } };
66
66
  }
@@ -4,6 +4,6 @@ export async function updateLocalBase(job) {
4
4
  const { repo, ports, config, base } = context;
5
5
  const updated = await oneAtATime(repo.root, () => ports.fastForwardBase(repo, base, config.remote)).catch(() => false);
6
6
  if (!updated) {
7
- log.event('base.behind', { base }, 'quiet');
7
+ log.event('base.behind', { base });
8
8
  }
9
9
  }
@@ -46,7 +46,12 @@ async function runChecks(job) {
46
46
  await evenWhenStopped(() => ports.discardChanges(worktree, head));
47
47
  // A stop kills the command, so its failure is no finding: the next run checks again.
48
48
  refuseWhenStopped();
49
- log.event('check.output', { cmd: command, code: result.code, timedOut: result.timedOut, output: result.output }, 'verbose');
49
+ log.record('check.output', {
50
+ cmd: command,
51
+ code: result.code,
52
+ timedOut: result.timedOut,
53
+ output: result.output,
54
+ });
50
55
  if (!succeeded(result) || result.timedOut) {
51
56
  return { command, result };
52
57
  }
@@ -62,7 +67,7 @@ async function failedCheck(job, command, result) {
62
67
  const { context, log, state } = job;
63
68
  const { repo, base } = context;
64
69
  const note = failure(job, command, result);
65
- log.event('check.fail', { cmd: command, code: result.code, timedOut: result.timedOut }, 'quiet');
70
+ log.event('check.fail', { cmd: command, code: result.code, timedOut: result.timedOut });
66
71
  const { round, limit } = budgetUse(job, 'ciFixes');
67
72
  if (round >= limit) {
68
73
  return escalateAndFinish(job, `${note} The limit of ${limit} check fixes was reached, so the harness did not push the change to ${base}.${outputBlock(result.output)}`, `local checks failed: ${command}`);
package/dist/logs.mjs CHANGED
@@ -17,10 +17,7 @@ export async function newestRunLog(root) {
17
17
  .at(-1);
18
18
  return newest === undefined ? undefined : join(dir, newest);
19
19
  }
20
- function show(line, json) {
21
- if (json) {
22
- return `${line}\n`;
23
- }
20
+ function show(line) {
24
21
  try {
25
22
  return render(JSON.parse(line));
26
23
  }
@@ -43,9 +40,9 @@ function stdoutOpen() {
43
40
  return false;
44
41
  }
45
42
  }
46
- async function printLines(lines, json, print) {
43
+ async function printLines(lines, print) {
47
44
  if (lines.length > 0) {
48
- await print(lines.map((line) => show(line, json)).join(''));
45
+ await print(lines.map(show).join(''));
49
46
  }
50
47
  }
51
48
  const CHUNK_BYTES = 64 * 1024;
@@ -100,7 +97,7 @@ export async function followLog(root, start, options, print) {
100
97
  const complete = completeLines(rest, first ? options.tail : undefined);
101
98
  rest = complete.rest;
102
99
  first = false;
103
- await printLines(complete.shown, options.json, print);
100
+ await printLines(complete.shown, print);
104
101
  if (!stdoutOpen()) {
105
102
  control.stop();
106
103
  }
@@ -115,9 +112,7 @@ export async function followLog(root, start, options, print) {
115
112
  decoder = new StringDecoder('utf8');
116
113
  position = 0;
117
114
  rest = '';
118
- if (!options.json) {
119
- await print(`— new run: ${basename(file)} —\n`);
120
- }
115
+ await print(`— new run: ${basename(file)} —\n`);
121
116
  continue;
122
117
  }
123
118
  await control.pause();
package/dist/loop.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Slots } from './slots.mjs';
2
- export async function runIssues(args, loop, seen = new Set()) {
3
- const limit = args.max;
2
+ export async function runIssues(loop, seen = new Set()) {
4
3
  const slots = new Slots(loop.concurrency ?? 1);
5
4
  const reports = [];
6
5
  const running = new Map();
@@ -10,11 +9,10 @@ export async function runIssues(args, loop, seen = new Set()) {
10
9
  let claiming = true;
11
10
  let unclaimed = true;
12
11
  const tried = { ended: new Set(), labels: new Map(), blocked: new Set() };
13
- const room = () => slots.open() && (limit === undefined || handled(reports) + running.size < limit);
14
12
  for (;;) {
15
- if (claiming && unclaimed && room()) {
13
+ if (claiming && unclaimed && slots.open()) {
16
14
  try {
17
- ({ claiming, unclaimed } = await claimIssues(loop, seen, tried, { running, slots }, room));
15
+ ({ claiming, unclaimed } = await claimIssues(loop, seen, tried, { running, slots }));
18
16
  }
19
17
  catch (failure) {
20
18
  error = failure;
@@ -62,7 +60,7 @@ function loopResult(reports, stoppedAt, error, crash) {
62
60
  ...(crash === undefined ? {} : { crash }),
63
61
  };
64
62
  }
65
- async function claimIssues(loop, seen, tried, pool, room) {
63
+ async function claimIssues(loop, seen, tried, pool) {
66
64
  if (loop.stop()) {
67
65
  return { claiming: false, unclaimed: false };
68
66
  }
@@ -72,7 +70,7 @@ async function claimIssues(loop, seen, tried, pool, room) {
72
70
  }
73
71
  readmitChanged(issues, seen, tried);
74
72
  for (const issue of issues.filter((candidate) => !seen.has(candidate.number))) {
75
- if (!room()) {
73
+ if (!pool.slots.open()) {
76
74
  return { claiming: true, unclaimed: true };
77
75
  }
78
76
  seen.add(issue.number);
package/dist/observe.mjs CHANGED
@@ -6,21 +6,18 @@ import { message } from './errors.mjs';
6
6
  import { render } from './render.mjs';
7
7
  import { runsDir } from './state.mjs';
8
8
  import { addUsage, countsSince, emptyRoleTotals, rolesSince, } from './usage.mjs';
9
- const VISIBILITY = { quiet: 0, normal: 1, verbose: 2 };
10
9
  class Sink {
11
10
  totals = new Map();
12
11
  counts = new Map();
13
12
  stream;
14
- level;
15
13
  file;
16
14
  listener;
17
15
  output;
18
16
  /** Set once the run log fails: the run goes on, and its events reach only the listener. */
19
17
  failed = false;
20
- constructor(stream, level, file, listener, output) {
18
+ constructor(stream, file, listener, output) {
21
19
  this.stream = stream;
22
20
  this.output = output;
23
- this.level = level;
24
21
  this.file = file;
25
22
  this.listener = listener;
26
23
  // With no listener, a failed open or write (`ENOSPC`, `EIO`, `EMFILE`) would crash the process.
@@ -70,12 +67,12 @@ export class Recorder {
70
67
  this.base = base;
71
68
  this.runId = runId;
72
69
  }
73
- static async create(root, level, listener, open = (file) => createWriteStream(file, { flags: 'a' }), output = (text) => process.stderr.write(text)) {
70
+ static async create(root, listener, open = (file) => createWriteStream(file, { flags: 'a' }), output = (text) => process.stderr.write(text)) {
74
71
  const runId = new Date().toISOString().replace(/[:.]/g, '-');
75
72
  const dir = runsDir(root);
76
73
  await mkdir(dir, { recursive: true });
77
74
  const file = join(dir, `${runId}.jsonl`);
78
- const sink = new Sink(open(file), level, file, listener, output);
75
+ const sink = new Sink(open(file), file, listener, output);
79
76
  return new Recorder(sink, {}, runId);
80
77
  }
81
78
  get logFile() {
@@ -90,13 +87,14 @@ export class Recorder {
90
87
  get summaryFile() {
91
88
  return `${this.runStem}.summary.json`;
92
89
  }
93
- get level() {
94
- return this.sink.level;
95
- }
96
90
  scope(fields) {
97
91
  return new Recorder(this.sink, { ...this.base, ...fields }, this.runId);
98
92
  }
99
- event(kind, fields = {}, visibility = 'normal') {
93
+ event(kind, fields = {}) {
94
+ this.sink.output(render(this.record(kind, fields)));
95
+ }
96
+ /** Writes the event to the run log only, not to the console. */
97
+ record(kind, fields = {}) {
100
98
  this.sink.count(kind);
101
99
  const record = {
102
100
  ts: new Date().toISOString(),
@@ -106,9 +104,7 @@ export class Recorder {
106
104
  ...fields,
107
105
  };
108
106
  this.sink.write(record);
109
- if (VISIBILITY[this.sink.level] >= VISIBILITY[visibility]) {
110
- this.sink.output(render(record));
111
- }
107
+ return record;
112
108
  }
113
109
  print(text) {
114
110
  this.sink.output(text);
@@ -119,14 +115,14 @@ export class Recorder {
119
115
  }
120
116
  async step(kind, fields, run) {
121
117
  const started = Date.now();
122
- this.event(`${kind}.start`, fields, 'verbose');
118
+ this.record(`${kind}.start`, fields);
123
119
  try {
124
120
  const result = await run();
125
121
  this.event(`${kind}.end`, { ...fields, ms: elapsedMs(started) });
126
122
  return result;
127
123
  }
128
124
  catch (error) {
129
- this.event(`${kind}.error`, { ...fields, ms: elapsedMs(started), error: message(error) }, 'quiet');
125
+ this.event(`${kind}.error`, { ...fields, ms: elapsedMs(started), error: message(error) });
130
126
  throw error;
131
127
  }
132
128
  }
package/dist/open-job.mjs CHANGED
@@ -40,10 +40,10 @@ async function openWorktree(context, issue, log, branch, start) {
40
40
  const { repo, config, ports } = context;
41
41
  const added = await log.step('worktree', { branch }, () => oneAtATime(repo.root, () => ports.addWorktree(repo, issue.number, branch, context.base, config.remote, start)));
42
42
  if (!added.baseUpdated) {
43
- log.event('base.behind', { base: context.base }, 'quiet');
43
+ log.event('base.behind', { base: context.base });
44
44
  }
45
45
  if (!added.branchUpdated) {
46
- log.event('branch.behind', { branch }, 'quiet');
46
+ log.event('branch.behind', { branch });
47
47
  }
48
48
  return added.path;
49
49
  }
package/dist/pending.mjs CHANGED
@@ -26,7 +26,7 @@ export async function pendingIssues(context) {
26
26
  issues.push(issue);
27
27
  }
28
28
  }
29
- context.recorder.event('issues', { open: openCount }, 'quiet');
29
+ context.recorder.event('issues', { open: openCount });
30
30
  const blocking = await blockingIssues(context, saved);
31
31
  // An issue that blocks every landing goes first, so its resume can lift the block before an older issue reaches the landing.
32
32
  return issues.sort((a, b) => Number(blocking.has(b.number)) - Number(blocking.has(a.number)) ||
@@ -58,7 +58,7 @@ async function savedIssue(context, number) {
58
58
  }
59
59
  catch (error) {
60
60
  const log = context.recorder.scope({ issue: number });
61
- log.event('issue.unreadable', { error: message(error) }, 'quiet');
61
+ log.event('issue.unreadable', { error: message(error) });
62
62
  if (saved !== 'broken' && errorMatches(error, ISSUE_GONE)) {
63
63
  await releaseGone(context, saved);
64
64
  }
package/dist/pipeline.mjs CHANGED
@@ -33,8 +33,8 @@ export async function processIssue(context, issue, claimed = () => undefined, sl
33
33
  return skip;
34
34
  }
35
35
  claimed();
36
- log.event('issue.start', { title: issue.title, createdAt: issue.createdAt }, 'quiet');
37
- const state = startState(context, issue, saved, handedOver);
36
+ log.event('issue.start', { title: issue.title, createdAt: issue.createdAt });
37
+ const state = startState(issue, saved, handedOver);
38
38
  let report;
39
39
  try {
40
40
  report = closing
@@ -47,7 +47,7 @@ export async function processIssue(context, issue, claimed = () => undefined, sl
47
47
  }
48
48
  report = stopNow(log, issue, state, started);
49
49
  }
50
- log.event('issue.end', { outcome: report.outcome, reason: report.reason, ms: report.ms }, 'quiet');
50
+ log.event('issue.end', { outcome: report.outcome, reason: report.reason, ms: report.ms });
51
51
  return report;
52
52
  }
53
53
  /**
@@ -62,12 +62,12 @@ function wasHandedOver(context, issue, saved) {
62
62
  return (pending !== undefined &&
63
63
  (pending.labelled === true || hasLabel(issue.labels, context.config.labels.needsHuman)));
64
64
  }
65
- function startState(context, issue, saved, handedOver) {
65
+ function startState(issue, saved, handedOver) {
66
66
  if (saved === undefined) {
67
67
  return newState(issue.number, branchName(issue.number));
68
68
  }
69
69
  const { pendingHandOver: _pending, ...rest } = saved;
70
- return context.reset || handedOver ? resetState(saved, handedOver) : rest;
70
+ return handedOver ? resetState(saved) : rest;
71
71
  }
72
72
  async function work(context, issue, log, state, start, handedOver, pending, slot) {
73
73
  const { job, setup } = await beforeBaseSettled(state, context.base, async () => {
package/dist/review.mjs CHANGED
@@ -78,7 +78,7 @@ function recordVerdict(job, verdict, open) {
78
78
  minor: verdict.findings.length - blocking.length,
79
79
  open: open.length,
80
80
  summary: verdict.summary,
81
- }, 'quiet');
81
+ });
82
82
  }
83
83
  async function runReviewer(job, earlier) {
84
84
  const { context, issue, log, state, worktree, comments } = job;
@@ -87,7 +87,7 @@ async function runReviewer(job, earlier) {
87
87
  state.reviewing = before;
88
88
  await writeState(context.repo, state);
89
89
  if (await ports.discardChanges(worktree, before, job.branch)) {
90
- log.event('review.clean', { round: state.reviewRounds }, 'quiet');
90
+ log.event('review.clean', { round: state.reviewRounds });
91
91
  }
92
92
  const full = await ports.diff(worktree, context.base, config.remote);
93
93
  const patch = capDiff(full, config.diffMaxChars);
@@ -107,7 +107,7 @@ export async function undoingReview(job, before, review) {
107
107
  catch (error) {
108
108
  if (!runStopped()) {
109
109
  await undoReview(job, before).catch((cleanup) => {
110
- job.log.event('review.discard.error', { error: message(cleanup) }, 'quiet');
110
+ job.log.event('review.discard.error', { error: message(cleanup) });
111
111
  });
112
112
  }
113
113
  throw error;
@@ -125,7 +125,7 @@ export async function settleReview(job) {
125
125
  async function undoReview(job, before) {
126
126
  const { context, log, state, worktree } = job;
127
127
  if (await context.ports.discardChanges(worktree, before, job.branch)) {
128
- log.event('review.discard', { round: state.reviewRounds }, 'quiet');
128
+ log.event('review.discard', { round: state.reviewRounds });
129
129
  }
130
130
  state.reviewing = undefined;
131
131
  await writeState(context.repo, state);
package/dist/run.mjs CHANGED
@@ -26,14 +26,18 @@ export async function runRepo(root, args, controls) {
26
26
  async function runWithConfig(root, args, controls, config) {
27
27
  await checkGitVersion();
28
28
  const repo = await detectRepo(root, config.remote);
29
- const recorder = await Recorder.create(repo.root, args.level, controls.onEvent, undefined, controls.output);
29
+ const recorder = await Recorder.create(repo.root, controls.onEvent, undefined, controls.output);
30
30
  try {
31
31
  const pruned = await pruneRuns(repo.root, config.keepRunDays);
32
32
  if (pruned > 0) {
33
- recorder.event('runs.pruned', { files: pruned, keepDays: config.keepRunDays }, 'verbose');
33
+ recorder.record('runs.pruned', { files: pruned, keepDays: config.keepRunDays });
34
34
  }
35
35
  return await recordCommands(recorder, () => handle(args, config, repo, recorder, controls));
36
36
  }
37
+ catch (error) {
38
+ recorder.record('run.fail', { error: message(error) });
39
+ throw error;
40
+ }
37
41
  finally {
38
42
  await recorder.close();
39
43
  }
@@ -50,7 +54,7 @@ async function handle(args, config, repo, recorder, controls) {
50
54
  const print = controls.print ?? (async () => undefined);
51
55
  const { reports, stoppedAt, error, crash } = args.watch || controls.watching !== undefined
52
56
  ? await watchRun(args, loop, context, controls, print)
53
- : await runIssues(args, loop);
57
+ : await runIssues(loop);
54
58
  recordLoopEnd(recorder, stoppedAt, interrupts.afterIssue(), error);
55
59
  const summary = await endRun(recorder, reports);
56
60
  if (crash !== undefined) {
@@ -67,10 +71,10 @@ export function watchRun(args, loop, context, controls, print) {
67
71
  const { interrupts } = controls;
68
72
  let passStart = recorder.summary();
69
73
  const hunt = hunter(context);
70
- return watchIssues(args, {
74
+ return watchIssues({
71
75
  ...loop,
72
76
  wait: (minutes, refreshed) => {
73
- recorder.event('watch.wait', { minutes }, 'quiet');
77
+ recorder.event('watch.wait', { minutes });
74
78
  passStart = recorder.summary();
75
79
  return interrupts.sleep(minutesToMs(minutes), () => hunt.busy(), refreshed);
76
80
  },
@@ -83,13 +87,13 @@ export function watchRun(args, loop, context, controls, print) {
83
87
  }
84
88
  function recordLoopEnd(recorder, stoppedAt, stopped, error) {
85
89
  if (stoppedAt !== undefined) {
86
- recorder.event('run.stop', { issue: stoppedAt }, 'quiet');
90
+ recorder.event('run.stop', { issue: stoppedAt });
87
91
  }
88
92
  else if (stopped) {
89
- recorder.event('run.stop', {}, 'quiet');
93
+ recorder.event('run.stop', {});
90
94
  }
91
95
  if (error !== undefined) {
92
- recorder.event('issues.fail', { error: message(error) }, 'quiet');
96
+ recorder.event('issues.fail', { error: message(error) });
93
97
  }
94
98
  }
95
99
  async function startRun(args, config, repo, recorder, interrupts) {
@@ -99,15 +103,16 @@ async function startRun(args, config, repo, recorder, interrupts) {
99
103
  repo: slug(repo),
100
104
  base,
101
105
  log: recorder.logFile,
102
- }, 'quiet');
106
+ });
103
107
  if (config.labels.ready.length === 0) {
104
- recorder.event('labels.ready.empty', { note: 'labels.ready is empty, so every open issue can be claimed' }, 'quiet');
108
+ recorder.event('labels.ready.empty', {
109
+ note: 'labels.ready is empty, so every open issue can be claimed',
110
+ });
105
111
  }
106
112
  return {
107
113
  repo,
108
114
  config,
109
115
  base,
110
- reset: args.reset,
111
116
  stopAfterRound: interrupts.afterRound,
112
117
  halted: false,
113
118
  recorder,
@@ -121,7 +126,7 @@ async function endRun(recorder, reports) {
121
126
  failed: count(reports, 'error'),
122
127
  skipped: count(reports, 'skipped'),
123
128
  tokens: recorder.summary().total.total,
124
- }, 'quiet');
129
+ });
125
130
  const summary = { ...recorder.summary(), issues: reports };
126
131
  await writeJson(recorder.summaryFile, summary);
127
132
  return summary;
package/dist/skip.mjs CHANGED
@@ -86,7 +86,7 @@ function readError(log, issue, saved, error, started) {
86
86
  if (saved !== undefined) {
87
87
  return stopNow(log, issue, saved, started);
88
88
  }
89
- log.event('issue.stop', {}, 'quiet');
89
+ log.event('issue.stop', {});
90
90
  return { ...skipped(issue), outcome: 'stopped', ms: elapsedMs(started) };
91
91
  }
92
92
  export function unclaimedError(log, issue, error, started) {
@@ -96,7 +96,7 @@ export function unclaimedError(log, issue, error, started) {
96
96
  export function logIssueError(log, error, started) {
97
97
  const reason = message(error);
98
98
  const ms = elapsedMs(started);
99
- log.event('issue.error', { error: reason, ms }, 'quiet');
99
+ log.event('issue.error', { error: reason, ms });
100
100
  return { reason, ms };
101
101
  }
102
102
  function skipped(issue) {
package/dist/start.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { prettyJson } from './files.mjs';
3
2
  import { NOTES, onPresses } from './interrupt.mjs';
4
3
  import { formatSummary } from './summary.mjs';
5
4
  import { packageVersion } from './version.mjs';
@@ -35,7 +34,6 @@ export async function startInWorker(root, args, argv) {
35
34
  function follow(connection, root, args, argv, out) {
36
35
  const id = randomUUID();
37
36
  const stopId = randomUUID();
38
- const summaryText = (summary) => args.json ? prettyJson(summary) : formatSummary(summary);
39
37
  return new Promise((resolve) => {
40
38
  const stopListening = onPresses((presses) => {
41
39
  if (presses === 1) {
@@ -71,7 +69,7 @@ function follow(connection, root, args, argv, out) {
71
69
  out.print(process.stderr, message.text);
72
70
  }
73
71
  else if (message.type === 'pass') {
74
- out.print(process.stdout, summaryText(message.summary));
72
+ out.print(process.stdout, formatSummary(message.summary));
75
73
  }
76
74
  else if (message.type === 'stopping' && message.id === stopId) {
77
75
  out.print(process.stderr, `${firstNote(message)}\n`);
@@ -84,7 +82,7 @@ function follow(connection, root, args, argv, out) {
84
82
  }
85
83
  else if (message.type === 'end') {
86
84
  if (!args.watch && message.summary !== undefined) {
87
- out.print(process.stdout, summaryText(message.summary));
85
+ out.print(process.stdout, formatSummary(message.summary));
88
86
  }
89
87
  settle(message.code);
90
88
  }
package/dist/state.mjs CHANGED
@@ -90,18 +90,13 @@ export function newState(issue, branch) {
90
90
  return { issue, phase: 'claimed', branch, ciFixes: 0, reviewRounds: 0, reviewLog: [] };
91
91
  }
92
92
  /**
93
- * Drops the budgets and findings; a hand-over (`handedOver`) also cancels an approval, the closing mark, the review start and the squash start,
93
+ * Drops the budgets and findings of a handed-over issue, and cancels an approval, the closing mark, the review start and the squash start,
94
94
  * so a resume that stops before it finishes is resumed again rather than closed as done.
95
95
  */
96
- export function resetState(state, handedOver = false) {
97
- const { handedOver: _handedOver, pendingHandOver: _pending, closing, reviewing, squashing, ...rest } = state;
98
- const phase = handedOver && rest.phase === 'approved' ? 'review' : rest.phase;
99
- const kept = {
100
- ...(!handedOver && closing !== undefined ? { closing } : {}),
101
- ...(!handedOver && reviewing !== undefined ? { reviewing } : {}),
102
- ...(!handedOver && squashing !== undefined ? { squashing } : {}),
103
- };
104
- return { ...rest, ...kept, phase, ciFixes: 0, commitFixes: 0, reviewRounds: 0, reviewLog: [] };
96
+ export function resetState(state) {
97
+ const { handedOver: _handedOver, pendingHandOver: _pending, closing: _closing, reviewing: _reviewing, squashing: _squashing, ...rest } = state;
98
+ const phase = rest.phase === 'approved' ? 'review' : rest.phase;
99
+ return { ...rest, phase, ciFixes: 0, commitFixes: 0, reviewRounds: 0, reviewLog: [] };
105
100
  }
106
101
  export async function writeState(repo, state) {
107
102
  await mkdir(stateDir(repo.root), { recursive: true });
package/dist/watch.mjs CHANGED
@@ -1,7 +1,7 @@
1
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
- export async function watchIssues(args, watch) {
4
+ export async function watchIssues(watch) {
5
5
  const running = new Set();
6
6
  const failed = new Set();
7
7
  const ended = new AbortController();
@@ -10,7 +10,7 @@ export async function watchIssues(args, watch) {
10
10
  ? undefined
11
11
  : huntIssues(watch.hunter, watch.hunting ?? onOff(true), running, failed, claims, watch.refreshed, () => ended.signal.aborted || watch.stop(), ended.signal);
12
12
  try {
13
- return await watchPasses(args, failed, {
13
+ return await watchPasses(failed, {
14
14
  ...watch,
15
15
  process: async (issue, _claimed, slot) => {
16
16
  running.add(issue.number);
@@ -90,13 +90,12 @@ async function huntIssues(hunter, hunting, running, failed, claims, refreshes, s
90
90
  }
91
91
  }
92
92
  }
93
- async function watchPasses(args, failed, watch) {
94
- const limit = args.max;
93
+ async function watchPasses(failed, watch) {
95
94
  const reports = [];
96
95
  let step = 0;
97
96
  const watching = () => watch.watching?.on() ?? true;
98
97
  for (;;) {
99
- const pass = await runIssues({ max: limit === undefined ? undefined : limit - handled(reports) }, watch, new Set(failed));
98
+ const pass = await runIssues(watch, new Set(failed));
100
99
  addReports(reports, pass.reports);
101
100
  if (pass.crash !== undefined) {
102
101
  return { ...pass, reports };
@@ -109,7 +108,7 @@ async function watchPasses(args, failed, watch) {
109
108
  if (pass.error !== undefined || pass.stoppedAt !== undefined) {
110
109
  return { ...pass, reports };
111
110
  }
112
- if ((limit !== undefined && handled(reports) >= limit) || watch.stop() || !watching()) {
111
+ if (watch.stop() || !watching()) {
113
112
  return { reports };
114
113
  }
115
114
  const minutes = backOffMinutes(step);
@@ -33,7 +33,11 @@ async function runSetup(job) {
33
33
  }
34
34
  async function setupFailed(job, setup, unsettled, when = '') {
35
35
  const late = setup.timedOut === true;
36
- job.log.event('setup.fail', { code: setup.code, timedOut: late, stderr: keepTail(setup.stderr.trim(), 2000) }, 'quiet');
36
+ job.log.event('setup.fail', {
37
+ code: setup.code,
38
+ timedOut: late,
39
+ stderr: keepTail(setup.stderr.trim(), 2000),
40
+ });
37
41
  if (unsettled !== '') {
38
42
  job.mainBroken = true;
39
43
  job.state.halted = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "10.7.4",
3
+ "version": "11.0.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",