next-issue 15.0.0 → 16.1.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
@@ -36,7 +36,7 @@ Run the harness inside a git repository:
36
36
  npx -y next-issue@latest start
37
37
  ```
38
38
 
39
- Give an issue the `status:todo` label to have it picked up. See [Issue format](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#issue-format) for how to write one. Press `Ctrl-C` to stop the run, see [Stop a run](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#stop-a-run).
39
+ Give an issue the `status:todo` label to have it picked up. See [Issue format](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#issue-format) for how to write one. `start` exits once the run has started in the worker. Follow the run with `npx -y next-issue@latest logs` and stop it with `npx -y next-issue@latest stop`, see [Stop a run](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#stop-a-run).
40
40
 
41
41
  ### Skills for Claude Code
42
42
 
@@ -91,7 +91,6 @@ A field that is not in the file keeps its default. See [Configuration](https://g
91
91
  | `watch on\|off` | Switch watching of the going run |
92
92
  | `hunt on\|off` | Switch hunting of the going run |
93
93
  | `init` | Write the config file with the defaults |
94
- | `serve` | Run the worker of this repository that the clients talk to |
95
94
  | `stop` | Stop the going run after its current issues |
96
95
  | `logs` | Show the latest run log and follow it |
97
96
  | `update` | Install the `create-issue` and `answer-hand-over` skills for Claude Code |
@@ -1,156 +1,25 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { NOTES, onPresses } from '../shared/interrupt.mjs';
3
- import { isNewer, } from '../shared/protocol.mjs';
4
- import { formatSummary } from '../shared/summary.mjs';
2
+ import { isNewer } from '../shared/protocol.mjs';
5
3
  import { packageVersion } from '../shared/version.mjs';
6
- import { CLOSED, going, reachWorker, rejoinRun, } from '../shared/worker-client.mjs';
4
+ import { going, reachWorker, startedRun } from '../shared/worker-client.mjs';
7
5
  const RUN_GOING = 'a run is going in this repository already';
8
- function output() {
9
- let queue = Promise.resolve();
10
- return {
11
- print: (stream, text) => {
12
- queue = queue.then(() => new Promise((resolve) => stream.write(text, () => resolve())));
13
- },
14
- flushed: () => queue,
15
- };
16
- }
17
- function firstNote(message) {
18
- if (!message.waiting) {
19
- return NOTES.issue;
20
- }
21
- return message.hunting ? NOTES.hunt : NOTES.wait;
22
- }
23
- export async function startInWorker(root, args, argv) {
6
+ const STARTED = 'next-issue: the run started in the worker; follow it with next-issue logs and stop it with next-issue stop\n';
7
+ export async function startInWorker(root, argv) {
24
8
  const version = await packageVersion();
25
9
  const connection = await reachWorker(root, version);
26
- if (going(connection.runs[root])) {
10
+ try {
11
+ if (going(connection.runs[root])) {
12
+ throw new Error(isNewer(version, connection.version)
13
+ ? `${RUN_GOING}; the worker updates to ${version} after the running issues`
14
+ : RUN_GOING);
15
+ }
16
+ const id = randomUUID();
17
+ const accepted = startedRun(connection, root, id);
18
+ connection.send({ type: 'start', root, args: argv, id });
19
+ await accepted;
20
+ return STARTED;
21
+ }
22
+ finally {
27
23
  connection.close();
28
- throw new Error(isNewer(version, connection.version)
29
- ? `${RUN_GOING}; the worker updates to ${version} after the running issues`
30
- : RUN_GOING);
31
24
  }
32
- const out = output();
33
- const code = await follow(connection, root, args, argv, out);
34
- await out.flushed();
35
- return code;
36
- }
37
- function follow(first, root, args, argv, out) {
38
- const id = randomUUID();
39
- const stopId = randomUUID();
40
- let connection = first;
41
- let latest;
42
- let upgradeEnd;
43
- let earlierCode = 0;
44
- const held = [];
45
- const send = (message) => {
46
- if (upgradeEnd === undefined) {
47
- connection.send(message);
48
- }
49
- else {
50
- held.push(message);
51
- }
52
- };
53
- return new Promise((resolve) => {
54
- const stopListening = onPresses((presses) => {
55
- if (presses === 1) {
56
- send({ type: 'stop', root, after: 'issue', id: stopId });
57
- }
58
- else if (presses === 2) {
59
- out.print(process.stderr, `${NOTES.round}\n`);
60
- send({ type: 'stop', root, after: 'round' });
61
- }
62
- else {
63
- send({ type: 'stop', root, after: 'now' });
64
- }
65
- });
66
- let settled = false;
67
- const settle = (code) => {
68
- if (!settled) {
69
- settled = true;
70
- stopListening();
71
- connection.close();
72
- resolve(Math.max(code, earlierCode));
73
- }
74
- };
75
- const fail = (text) => {
76
- if (!settled) {
77
- out.print(process.stderr, `next-issue failed: ${text}\n`);
78
- }
79
- settle(1);
80
- };
81
- const onMessage = (message) => {
82
- if (message.type === 'runs') {
83
- latest = message.runs[root];
84
- }
85
- if (!('root' in message) || message.root !== root) {
86
- return;
87
- }
88
- if (message.type === 'output') {
89
- out.print(process.stderr, message.text);
90
- }
91
- else if (message.type === 'pass') {
92
- out.print(process.stdout, formatSummary(message.summary));
93
- }
94
- else if (message.type === 'stopping' && message.id === stopId) {
95
- out.print(process.stderr, `${firstNote(message)}\n`);
96
- }
97
- else if (message.type === 'error' && message.id === id) {
98
- fail(message.message);
99
- }
100
- else if (message.type === 'end' && message.error !== undefined) {
101
- fail(message.error);
102
- }
103
- else if (message.type === 'end') {
104
- if (!args.watch && message.summary !== undefined) {
105
- out.print(process.stdout, formatSummary(message.summary));
106
- }
107
- if (latest?.upgrade === undefined) {
108
- settle(message.code);
109
- }
110
- else {
111
- upgradeEnd = message.code;
112
- }
113
- }
114
- };
115
- const rejoin = async (upgrade) => {
116
- const found = await rejoinRun(root).catch(() => undefined);
117
- if (found === undefined) {
118
- fail(`${CLOSED}, and the run did not go on in the newer worker`);
119
- return;
120
- }
121
- if (settled) {
122
- found.close();
123
- return;
124
- }
125
- out.print(process.stderr, `next-issue: the worker was updated from ${upgrade.from} to ${upgrade.to}\n`);
126
- earlierCode = Math.max(earlierCode, upgradeEnd ?? 0);
127
- upgradeEnd = undefined;
128
- latest = found.runs[root];
129
- follows(found);
130
- for (const message of held.splice(0)) {
131
- found.send(message);
132
- }
133
- };
134
- const closed = () => {
135
- if (upgradeEnd === undefined) {
136
- fail(CLOSED);
137
- }
138
- else if (latest?.error !== undefined) {
139
- fail(latest.error);
140
- }
141
- else if (latest?.upgrade === undefined) {
142
- settle(upgradeEnd);
143
- }
144
- else {
145
- void rejoin(latest.upgrade);
146
- }
147
- };
148
- const follows = (next) => {
149
- connection = next;
150
- next.listen(onMessage);
151
- void next.closed.then(closed);
152
- };
153
- follows(first);
154
- first.send({ type: 'start', root, args: argv, id });
155
- });
156
25
  }
package/dist/cli.mjs CHANGED
@@ -51,11 +51,8 @@ async function main() {
51
51
  if (args.command === 'serve') {
52
52
  return serve(root);
53
53
  }
54
- return run(root, args, argv);
55
- }
56
- function run(root, args, argv) {
57
- process.stderr.on('error', () => { });
58
- return startInWorker(root, args, argv.slice(1));
54
+ await write(process.stderr, await startInWorker(root, argv.slice(1)));
55
+ return 0;
59
56
  }
60
57
  async function logs(root) {
61
58
  const file = await newestRunLog(root);
@@ -16,7 +16,6 @@ export const USAGE = `next-issue <command> [options]
16
16
  watch on|off switch watching of the going run; off also turns hunting off
17
17
  hunt on|off switch hunting of the going run; on also turns watching on
18
18
  init write ${CONFIG_FILE} with the defaults and add .next-issue/ and .worktrees/ to info/exclude
19
- serve run the worker of this repository that the clients talk to
20
19
  stop stop the going run after its current issues
21
20
  logs show the latest run log and follow it
22
21
  update install the create-issue and answer-hand-over skills for Claude Code
@@ -1,28 +1 @@
1
- export const NOTES = {
2
- hunt: 'Stopping after the current hunt. Press Ctrl-C twice more to stop now.',
3
- wait: 'Stopping now.',
4
- issue: 'Stopping after the running issues. Press Ctrl-C again to stop after the current round.',
5
- round: 'Stopping after the current round. Press Ctrl-C again to stop now.',
6
- };
7
- export function onPresses(handle) {
8
- let presses = 0;
9
- let lastPress = -Infinity;
10
- let ending;
11
- const press = () => {
12
- const now = performance.now();
13
- if (now - lastPress < 100) {
14
- return;
15
- }
16
- lastPress = now;
17
- presses += 1;
18
- if (presses >= 3) {
19
- ending = setTimeout(() => process.off('SIGINT', press), 100).unref();
20
- }
21
- handle(presses);
22
- };
23
- process.on('SIGINT', press);
24
- return () => {
25
- clearTimeout(ending);
26
- process.off('SIGINT', press);
27
- };
28
- }
1
+ export {};
@@ -161,9 +161,9 @@ export async function reachWorker(root, version) {
161
161
  found.close();
162
162
  }
163
163
  }
164
- function startedRun(found, root) {
164
+ export function startedRun(found, root, id) {
165
165
  return new Promise((resolve, reject) => {
166
- const timer = setTimeout(() => reject(new Error('the newer worker did not start the run')), ANSWER_TIMEOUT_MS);
166
+ const timer = setTimeout(() => reject(new Error('the worker did not start the run')), ANSWER_TIMEOUT_MS);
167
167
  const settle = (error) => {
168
168
  clearTimeout(timer);
169
169
  if (error === undefined) {
@@ -177,7 +177,7 @@ function startedRun(found, root) {
177
177
  if (message.type === 'runs' && going(message.runs[root])) {
178
178
  settle();
179
179
  }
180
- else if (message.type === 'error' && message.root === root) {
180
+ else if (message.type === 'error' && message.root === root && message.id === id) {
181
181
  settle(new Error(message.message));
182
182
  }
183
183
  });
@@ -197,20 +197,6 @@ export async function resumeOnSuccessor(root, how, args) {
197
197
  found.close();
198
198
  }
199
199
  }
200
- export async function rejoinRun(root) {
201
- const { socketPath } = workerPaths(root);
202
- const deadline = Date.now() + START_TIMEOUT_MS;
203
- while (Date.now() < deadline) {
204
- const found = await tryOpen(socketPath);
205
- if (found?.runs[root] !== undefined) {
206
- found.send({ type: 'rejoin', root });
207
- return found;
208
- }
209
- found?.close();
210
- await delay(POLL_MS);
211
- }
212
- return undefined;
213
- }
214
200
  export function findWorker(root) {
215
201
  const { socketPath } = workerPaths(root);
216
202
  checkSocketPath(socketPath);
@@ -1,9 +1,40 @@
1
+ const STEPS = {
2
+ 'implement.start': 'implementing',
3
+ 'review.start': 'reviewing',
4
+ 'fix.start': 'fixing',
5
+ 'commit-fix.start': 'fixing',
6
+ 'land.start': 'landing',
7
+ 'ci-checks.start': 'waiting-for-checks',
8
+ };
1
9
  export function startProgress(hunting = false) {
2
- return { status: 'running', hunting };
10
+ return { status: 'running', hunting, issues: [] };
3
11
  }
4
12
  export function applyEvent(progress, record) {
5
- if (record['kind'] === 'issues.fail') {
13
+ const kind = record['kind'];
14
+ if (kind === 'issues.fail') {
6
15
  return { ...progress, error: String(record['error']) };
7
16
  }
8
- return progress;
17
+ const issue = record['issue'];
18
+ if (typeof kind !== 'string' || typeof issue !== 'number') {
19
+ return progress;
20
+ }
21
+ if (kind === 'issue.start') {
22
+ return { ...progress, issues: [...withoutIssue(progress, issue), { issue }] };
23
+ }
24
+ if (kind === 'issue.end' || kind === 'issue.error') {
25
+ return { ...progress, issues: withoutIssue(progress, issue) };
26
+ }
27
+ const step = STEPS[kind];
28
+ if (step === undefined || !progress.issues.some((running) => running.issue === issue)) {
29
+ return progress;
30
+ }
31
+ const round = step === 'reviewing' && typeof record['round'] === 'number' ? record['round'] : undefined;
32
+ const entry = { issue, step, ...(round === undefined ? {} : { round }) };
33
+ return {
34
+ ...progress,
35
+ issues: progress.issues.map((running) => (running.issue === issue ? entry : running)),
36
+ };
37
+ }
38
+ function withoutIssue(progress, issue) {
39
+ return progress.issues.filter((running) => running.issue !== issue);
9
40
  }
@@ -165,6 +165,7 @@ export async function startWorker(options) {
165
165
  ...(summary === undefined ? {} : { summary }),
166
166
  });
167
167
  }, (error) => {
168
+ process.stderr.write(`next-issue failed: ${message(error)}\n`);
168
169
  update({ ...run.progress, status: 'failed', error: message(error) });
169
170
  return ended({ type: 'end', root, code: 1, error: message(error) });
170
171
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "15.0.0",
3
+ "version": "16.1.0",
4
4
  "description": "Autonomous issue harness driven by the Claude Agent SDK",
5
5
  "keywords": [
6
6
  "github",