next-issue 9.8.2 → 9.9.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.
@@ -136,7 +136,7 @@ No person checks a change before it lands. To replace those checks, [ADR 0004](h
136
136
  Every run has an id, `<timestamp>`, and writes these under `.next-issue/runs/`:
137
137
 
138
138
  - `<id>.jsonl` — one JSON object per event, with `ts`, `runId`, `kind`, and the `issue`, `role` or `round` in scope;
139
- - `<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);
139
+ - `<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);
140
140
  - `<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.
141
141
 
142
142
  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.
@@ -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
 
@@ -354,7 +354,7 @@ In a run of the `serve` worker, a client can switch hunting and watching on or o
354
354
  - 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`;
355
355
  - 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;
356
356
  - 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);
357
- - 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` and `skip` 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>" }`;
357
+ - 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>" }`;
358
358
  - 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>" }`;
359
359
  - 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;
360
360
  - 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 started with `--watch` or `--hunt` starts with watching on, and any other run with it off. On keeps the run going after the current pass, as with `--watch`. 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;
package/dist/git.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { must, optionalFlag, run, succeeded } from './exec.mjs';
1
+ import { must, run, succeeded } from './exec.mjs';
2
2
  import { oneAtATime } from './lock.mjs';
3
3
  import { lines } from './text.mjs';
4
4
  const REMOTE_PATTERNS = [
@@ -28,7 +28,7 @@ async function sshHost(url, host) {
28
28
  if (host === 'github.com' || /^https?:/.test(url.trim())) {
29
29
  return host;
30
30
  }
31
- const result = await run('ssh', ['-G', host]).catch(() => undefined);
31
+ const result = await run('ssh', ['-G', '--', host]).catch(() => undefined);
32
32
  const resolved = /^hostname[^\S\r\n]+(\S+)$/m.exec(result?.stdout ?? '')?.[1];
33
33
  return result !== undefined && succeeded(result) && resolved !== undefined
34
34
  ? githubHost(resolved)
@@ -113,10 +113,6 @@ export async function saveSetupOutput(cwd) {
113
113
  }
114
114
  export async function setAside(cwd, target, branch) {
115
115
  await git(cwd, ['branch', branch]);
116
- if (await isDirty(cwd)) {
117
- await git(cwd, ['reset', '--soft', target]);
118
- return;
119
- }
120
116
  await discardChanges(cwd, target);
121
117
  }
122
118
  export async function disputeBranches(repo, branch) {
@@ -127,9 +123,6 @@ export async function disputeBranches(repo, branch) {
127
123
  ]);
128
124
  return lines(list);
129
125
  }
130
- export async function push(cwd, remote, branch, force = false) {
131
- await oneFetchAtATime(() => git(cwd, ['push', '-u', ...optionalFlag(force, '--force'), remote, branch]));
132
- }
133
126
  export async function fetchBase(cwd, base, remote) {
134
127
  await gitFetch(cwd, [remote, base]);
135
128
  return remoteRef(remote, base);
@@ -140,10 +133,6 @@ export function oneFetchAtATime(work) {
140
133
  export function gitFetch(cwd, args) {
141
134
  return oneFetchAtATime(() => git(cwd, ['fetch', ...args]));
142
135
  }
143
- export async function resetToBase(cwd, base, remote) {
144
- const target = await fetchBase(cwd, base, remote);
145
- await git(cwd, ['reset', '--hard', target]);
146
- }
147
136
  export async function latestSubject(cwd, base, remote) {
148
137
  const subject = await git(cwd, ['log', '-1', '--format=%s', `${remoteRef(remote, base)}..HEAD`]);
149
138
  return subject === '' ? undefined : subject;
@@ -92,7 +92,11 @@ async function waitingQuestion(repo, config, ports, writer, issue) {
92
92
  reason: comment?.body.slice(HAND_OVER.length).trim() ?? pending?.reason ?? '',
93
93
  url: comment?.url ?? '',
94
94
  repo: repoArg(repo),
95
- labels: { needsHuman: config.labels.needsHuman, skip: config.labels.skip },
95
+ labels: {
96
+ needsHuman: config.labels.needsHuman,
97
+ skip: config.labels.skip,
98
+ ready: config.labels.ready,
99
+ },
96
100
  };
97
101
  }
98
102
  export async function writerComments(context, log, issue) {
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,24 +30,25 @@ 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;
35
39
  }
36
40
  }
37
- if (crash !== undefined) {
38
- throw crash.failure;
39
- }
40
- return loopResult(reports, stoppedAt, error);
41
+ return loopResult(reports, stoppedAt, error, crash);
41
42
  }
42
- function loopResult(reports, stoppedAt, error) {
43
+ function loopResult(reports, stoppedAt, error, crash) {
43
44
  return {
44
45
  reports,
45
46
  ...(stoppedAt === undefined ? {} : { stoppedAt }),
46
47
  ...(error === undefined ? {} : { error }),
48
+ ...(crash === undefined ? {} : { crash }),
47
49
  };
48
50
  }
49
- async function claimIssues(loop, seen, running, room) {
51
+ async function claimIssues(loop, seen, tried, running, room) {
50
52
  if (loop.stop()) {
51
53
  return false;
52
54
  }
@@ -54,6 +56,7 @@ async function claimIssues(loop, seen, running, room) {
54
56
  if (loop.stop()) {
55
57
  return false;
56
58
  }
59
+ readmitChanged(issues, seen, tried);
57
60
  for (const issue of issues.filter((candidate) => !seen.has(candidate.number))) {
58
61
  if (!room()) {
59
62
  break;
@@ -63,6 +66,25 @@ async function claimIssues(loop, seen, running, room) {
63
66
  }
64
67
  return true;
65
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
+ }
66
88
  export function exitCode(reports) {
67
89
  return reports.some((report) => report.outcome === 'needs-human' || report.outcome === 'error')
68
90
  ? 1
package/dist/ports.mjs CHANGED
@@ -4,7 +4,7 @@ import { run } from './exec.mjs';
4
4
  import { commitAll } from './git-commit.mjs';
5
5
  import { baseMoved, pushToBase, reapplyRevert, revertOnBase, squashOnto } from './git-land.mjs';
6
6
  import { abortMerge, commitMerge, startMerge } from './git-merge.mjs';
7
- import { changedFiles, deleteBranch, diff, discardChanges, disputeBranches, isDirty, isLanded, isOnBase, latestSubject, push, resetToBase, revision, saveEdits, saveSetupOutput, setAside, } from './git.mjs';
7
+ import { changedFiles, deleteBranch, diff, discardChanges, disputeBranches, isDirty, isLanded, isOnBase, latestSubject, revision, saveEdits, saveSetupOutput, setAside, } from './git.mjs';
8
8
  import { canWrite, closeIssue, commentOnIssue, editIssueBody, issueComments, issueEditors, openBlockers, openIssues, reopenIssue, repositorySlug, threadComments, viewIssue, } from './github.mjs';
9
9
  import { huntWorktree } from './hunt.mjs';
10
10
  import { ensureLabel, setLabel } from './labels.mjs';
@@ -47,14 +47,12 @@ export const PORTS = {
47
47
  latestSubject,
48
48
  openBlockers,
49
49
  openIssues,
50
- push,
51
50
  pushToBase,
52
51
  reapplyRevert,
53
52
  removeWorktree,
54
53
  reopenIssue,
55
54
  repositorySlug,
56
55
  rerunFailedCi,
57
- resetToBase,
58
56
  revertOnBase,
59
57
  revision,
60
58
  runAgent,
package/dist/run.mjs CHANGED
@@ -69,11 +69,14 @@ async function handle(args, config, repo, recorder, controls) {
69
69
  concurrency: config.concurrency,
70
70
  };
71
71
  const print = controls.print ?? (async () => undefined);
72
- const { reports, stoppedAt, error } = args.watch || controls.watching !== undefined
72
+ const { reports, stoppedAt, error, crash } = args.watch || controls.watching !== undefined
73
73
  ? await watchRun(args, loop, context, controls, print)
74
74
  : await runIssues(args, loop);
75
75
  recordLoopEnd(recorder, stoppedAt, error);
76
76
  const summary = await endRun(recorder, reports);
77
+ if (crash !== undefined) {
78
+ throw crash.failure;
79
+ }
77
80
  if (!args.watch) {
78
81
  await print(summary);
79
82
  }
package/dist/watch.mjs CHANGED
@@ -98,6 +98,9 @@ async function watchPasses(args, failed, watch) {
98
98
  for (;;) {
99
99
  const pass = await runIssues({ max: limit === undefined ? undefined : limit - handled(reports) }, watch, new Set(failed));
100
100
  addReports(reports, pass.reports);
101
+ if (pass.crash !== undefined) {
102
+ return { ...pass, reports };
103
+ }
101
104
  recordFailures(failed, pass.reports);
102
105
  if (handled(pass.reports) > 0) {
103
106
  await watch.passEnd(pass.reports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "9.8.2",
3
+ "version": "9.9.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",
@@ -50,7 +50,6 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@earendil-works/pi-coding-agent": "^1.5.2",
53
- "typebox": "^1.4.7",
54
53
  "ws": "^8.23.0"
55
54
  }
56
55
  }