next-issue 9.8.3 → 9.10.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
@@ -32,13 +32,13 @@ flowchart TD
32
32
 
33
33
  ## What it does
34
34
 
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, also a skipped or failed one, 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.
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
37
  Only one worker or command-line run goes at a time in a repository. Both hold one lock, `.next-issue/worker.lock`, with the process id and the start time of that process: the worker for its whole life, and a command-line run from its start to its end. A run that the worker starts takes no lock of its own, since the worker runs at most one run at a time. A command-line run that starts while any worker is alive, busy or idle, or while another command-line run is going, claims no issue and exits with code 1 and the error `another next-issue worker or run (process id <n>) is going in this repository`. Run `next-issue stop` first to stop the worker. A lock whose process is gone, or started at another time, is stale and taken over.
38
38
 
39
39
  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.
40
40
 
41
- A run handles up to `concurrency` issues at the same time, 1 by default. When an issue ends, the run fetches the open issues again and claims the oldest unseen one for the free slot. 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 blocked by a running issue is skipped and not tried again in that run, even when the blocker closes before the run ends. `--max <n>` counts the handled issues across the run, so with `--max 1` the run handles one issue. For each issue:
41
+ A run handles up to `concurrency` issues at the same time, 1 by default. When an issue ends, the run fetches the open issues again and claims the oldest unseen one for the free slot. 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 blocked by a running issue is skipped and not tried again in that run, even when the blocker closes before the run ends, unless its labels change. `--max <n>` counts the handled issues across the run, so with `--max 1` the run handles one issue. For each issue:
42
42
 
43
43
  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.
44
44
  2. Add `status:in-progress` to the issue.
@@ -143,7 +143,7 @@ At the start of a run, the harness deletes the files and folders under `.next-is
143
143
 
144
144
  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.
145
145
 
146
- 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, and for a `bash` tool the command too. 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.
146
+ 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.
147
147
 
148
148
  ```bash
149
149
  jq -r 'select(.kind=="usage") | [.issue,.role,.turns,.total] | @tsv' \
@@ -318,7 +318,7 @@ Versions before 7.0.0 started a run with no command, as `next-issue` or `next-is
318
318
 
319
319
  ## Watch for new issues
320
320
 
321
- A run without `--watch` ends when no unseen issue is left. With `next-issue start --watch`, 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 in a later pass once a person answers the hand-over or takes the label off. The hunter counts the same issues as ready.
321
+ A run without `--watch` ends when no unseen issue is left. With `next-issue start --watch`, 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.
322
322
 
323
323
  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.
324
324
 
package/dist/agents.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { readFileSync } from 'node:fs';
2
- import { dirname, join } from 'node:path';
2
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { getAgentDir, } from '@earendil-works/pi-coding-agent';
5
5
  import { openSession } from './agent-session.mjs';
@@ -50,7 +50,7 @@ export async function runAgent(recorder, request) {
50
50
  throw timeoutError(request);
51
51
  }
52
52
  opened = session;
53
- const unsubscribe = session.subscribe((event) => observe(log, event));
53
+ const unsubscribe = session.subscribe((event) => observe(log, event, request.cwd));
54
54
  const release = onStop(end);
55
55
  try {
56
56
  refuseWhenStopped();
@@ -127,9 +127,9 @@ function sessionResult(recorder, request, session, started) {
127
127
  sessionId: stats.sessionId,
128
128
  };
129
129
  }
130
- function observe(log, event) {
130
+ function observe(log, event, cwd) {
131
131
  if (event.type === 'tool_execution_start') {
132
- log.event('tool', toolFields(event.toolName, event.args));
132
+ log.event('tool', toolFields(event.toolName, event.args, cwd));
133
133
  }
134
134
  else if (event.type === 'tool_execution_end' && event.isError) {
135
135
  log.event('tool.error', { tool: event.toolName }, 'quiet');
@@ -140,10 +140,24 @@ function observe(log, event) {
140
140
  process.stderr.write(event.assistantMessageEvent.delta);
141
141
  }
142
142
  }
143
- export function toolFields(name, input) {
144
- if (name !== 'bash' || !isRecord(input)) {
143
+ const PATH_TOOLS = new Set(['read', 'write', 'edit', 'grep', 'find', 'ls']);
144
+ export function toolFields(name, input, cwd) {
145
+ if (!isRecord(input)) {
145
146
  return { tool: name };
146
147
  }
147
- const { command } = input;
148
- return typeof command === 'string' ? { tool: name, command } : { tool: name };
148
+ const { command, path } = input;
149
+ if (name === 'bash' && typeof command === 'string') {
150
+ return { tool: name, command };
151
+ }
152
+ if (PATH_TOOLS.has(name) && typeof path === 'string') {
153
+ return { tool: name, path: shortPath(path, cwd) };
154
+ }
155
+ return { tool: name };
156
+ }
157
+ function shortPath(path, cwd) {
158
+ const inside = relative(cwd, resolve(cwd, path));
159
+ if (inside === '') {
160
+ return '.';
161
+ }
162
+ return inside === '..' || inside.startsWith(`..${sep}`) || isAbsolute(inside) ? path : inside;
149
163
  }
package/dist/loop.mjs CHANGED
@@ -7,11 +7,12 @@ export async function runIssues(args, loop, seen = new Set()) {
7
7
  let error;
8
8
  let crash;
9
9
  let claiming = true;
10
+ const tried = { ended: new Set(), labels: new Map() };
10
11
  const room = () => running.size < concurrency && (limit === undefined || handled(reports) + running.size < limit);
11
12
  for (;;) {
12
13
  if (claiming && room()) {
13
14
  try {
14
- claiming = await claimIssues(loop, seen, running, room);
15
+ claiming = await claimIssues(loop, seen, tried, running, room);
15
16
  }
16
17
  catch (failure) {
17
18
  error = failure;
@@ -29,6 +30,9 @@ export async function runIssues(args, loop, seen = new Set()) {
29
30
  continue;
30
31
  }
31
32
  reports.push(report);
33
+ if (retryable(report)) {
34
+ tried.ended.add(issue);
35
+ }
32
36
  if (claiming && (loop.stop() || report.halt === true)) {
33
37
  stoppedAt = issue;
34
38
  claiming = false;
@@ -44,7 +48,7 @@ function loopResult(reports, stoppedAt, error, crash) {
44
48
  ...(crash === undefined ? {} : { crash }),
45
49
  };
46
50
  }
47
- async function claimIssues(loop, seen, running, room) {
51
+ async function claimIssues(loop, seen, tried, running, room) {
48
52
  if (loop.stop()) {
49
53
  return false;
50
54
  }
@@ -52,6 +56,7 @@ async function claimIssues(loop, seen, running, room) {
52
56
  if (loop.stop()) {
53
57
  return false;
54
58
  }
59
+ readmitChanged(issues, seen, tried);
55
60
  for (const issue of issues.filter((candidate) => !seen.has(candidate.number))) {
56
61
  if (!room()) {
57
62
  break;
@@ -61,6 +66,25 @@ async function claimIssues(loop, seen, running, room) {
61
66
  }
62
67
  return true;
63
68
  }
69
+ function retryable(report) {
70
+ return report.outcome !== 'done' && (report.outcome !== 'error' || report.handedOver === true);
71
+ }
72
+ function readmitChanged(issues, seen, tried) {
73
+ const listed = new Map(issues.map((issue) => [issue.number, labelKey(issue)]));
74
+ for (const [number, labels] of tried.labels) {
75
+ if (listed.has(number) && listed.get(number) !== labels) {
76
+ tried.labels.delete(number);
77
+ seen.delete(number);
78
+ }
79
+ }
80
+ for (const number of tried.ended) {
81
+ tried.labels.set(number, listed.get(number));
82
+ }
83
+ tried.ended.clear();
84
+ }
85
+ function labelKey(issue) {
86
+ return [...issue.labels].sort().join('\n');
87
+ }
64
88
  export function exitCode(reports) {
65
89
  return reports.some((report) => report.outcome === 'needs-human' || report.outcome === 'error')
66
90
  ? 1
package/dist/progress.mjs CHANGED
@@ -7,7 +7,12 @@ export function startProgress(hunting = false) {
7
7
  function toolLine(record) {
8
8
  const tool = String(record['tool']);
9
9
  const command = record['command'];
10
- const line = typeof command === 'string' ? `${tool} ${command.split('\n')[0]}` : tool;
10
+ const path = record['path'];
11
+ const line = typeof command === 'string'
12
+ ? `${tool} ${command.split('\n')[0]}`
13
+ : typeof path === 'string'
14
+ ? `${tool} ${path}`
15
+ : tool;
11
16
  return truncate(line, TOOL_LINE_MAX, '…');
12
17
  }
13
18
  function stageName(step, record) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "9.8.3",
3
+ "version": "9.10.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",