next-issue 16.2.0 → 16.4.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
@@ -40,23 +40,17 @@ Give an issue the `status:todo` label to have it picked up. See [Issue format](h
40
40
 
41
41
  ### Skills for Claude Code
42
42
 
43
- To install the `create-issue` skill, which writes an issue that the harness can claim, and the `answer-hand-over` skill, which helps you answer a hand-over, run:
44
-
45
- ```bash
46
- npx -y next-issue@latest update
47
- ```
48
-
49
- It asks whether to install them for your user or for the project. See [Skills](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#skills).
43
+ `init` (see [Configuration](#configuration)) installs the `create-issue` skill, which writes an issue that the harness can claim, and the `answer-hand-over` skill, which helps you answer a hand-over. It asks whether to install them for your user or for the project; `--scope user|project` answers in advance. Run `init` again after an upgrade of next-issue to get the skills of that version. See [Skills](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#skills).
50
44
 
51
45
  ## Configuration
52
46
 
53
- To write `.next-issue/config.json` with the defaults, run:
47
+ To set up a repository, run:
54
48
 
55
49
  ```bash
56
50
  npx -y next-issue@latest init
57
51
  ```
58
52
 
59
- A field that is not in the file keeps its default. See [Configuration](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#configuration) for the details.
53
+ It writes `.next-issue/config.json` with the defaults, or keeps the file when it is there already, and installs the skills. A field that is not in the file keeps its default. See [Configuration](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#configuration) for the details.
60
54
 
61
55
  | Field | Default | Effect |
62
56
  | ----------------------- | ------------------ | ------------------------------------------------------------------- |
@@ -90,15 +84,14 @@ A field that is not in the file keeps its default. See [Configuration](https://g
90
84
  | `start` | Start a run: claim issues, fix them and push them to the base branch |
91
85
  | `watch on\|off` | Switch watching of the going run |
92
86
  | `hunt on\|off` | Switch hunting of the going run |
93
- | `init` | Write the config file with the defaults |
87
+ | `init` | Write the config file with the defaults and install the skills |
94
88
  | `stop` | Stop the going run after its current issues |
95
89
  | `status` | Show the going run, its worker and its running issues |
96
90
  | `logs` | Show the latest run log and follow it |
97
- | `update` | Install the `create-issue` and `answer-hand-over` skills for Claude Code |
98
91
  | `--force` | With `init`: replace an existing config file |
99
92
  | `--watch on\|off` | With `start`: read the open issues again after each pass. On by default |
100
93
  | `--hunt on\|off` | With `start`: hunt the repository for bugs. Off by default. Needs watching |
101
- | `--scope user\|project` | With `update`: install for the user (`~/.claude/skills/`) or the project |
94
+ | `--scope user\|project` | With `init`: install for the user (`~/.claude/skills/`) or the project |
102
95
  | `--help` | Show the option list |
103
96
 
104
97
  See [Commands and options](https://github.com/ravshansbox/next-issue/blob/main/packages/next-issue/docs/behaviour.md#commands-and-options) for the details.
@@ -31,7 +31,7 @@ export async function chooseScope(scope) {
31
31
  return scope;
32
32
  }
33
33
  if (process.stdin.isTTY !== true) {
34
- throw new Error('update needs --scope user|project when there is no terminal to ask where to install the skills');
34
+ throw new Error('init needs --scope user|project when there is no terminal to ask where to install the skills');
35
35
  }
36
36
  return askScope(process.stdin, process.stdout);
37
37
  }
@@ -1,17 +1,37 @@
1
1
  import { randomUUID } from 'node:crypto';
2
+ import { givenStartFlags } from '../shared/args.mjs';
2
3
  import { isNewer } from '../shared/protocol.mjs';
3
4
  import { packageVersion } from '../shared/version.mjs';
4
- import { going, reachWorker, startedRun } from '../shared/worker-client.mjs';
5
- const RUN_GOING = 'a run is going in this repository already';
5
+ import { ANSWER_TIMEOUT_MS, CLOSED, going, reachWorker, startedRun, } from '../shared/worker-client.mjs';
6
+ import { statusText, switched } from './switch-run.mjs';
7
+ const REFUSED_GOING = [
8
+ 'a run is going in this repository already',
9
+ 'the worker is restarting, try again soon',
10
+ ];
11
+ const SILENT = 'the next-issue worker did not answer';
6
12
  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
13
  export async function startInWorker(root, argv) {
8
14
  const version = await packageVersion();
15
+ const given = givenStartFlags(argv);
9
16
  const connection = await reachWorker(root, version);
10
17
  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);
18
+ const progress = connection.runs[root];
19
+ if (going(progress)) {
20
+ const join = await joined(connection, root, argv, progress);
21
+ if (join.joined) {
22
+ return statusText(connection.version, join.progress);
23
+ }
24
+ if (!isNewer(version, connection.version) || !REFUSED_GOING.includes(join.refusal)) {
25
+ throw new Error(join.refusal);
26
+ }
27
+ let latest = join.progress;
28
+ if (given.watch !== undefined) {
29
+ latest = await switched(connection, root, 'watch', given.watch);
30
+ }
31
+ if (given.hunt !== undefined) {
32
+ latest = await switched(connection, root, 'hunt', given.hunt);
33
+ }
34
+ return statusText(connection.version, latest);
15
35
  }
16
36
  const id = randomUUID();
17
37
  const accepted = startedRun(connection, root, id);
@@ -23,3 +43,32 @@ export async function startInWorker(root, argv) {
23
43
  connection.close();
24
44
  }
25
45
  }
46
+ function joined(connection, root, argv, known) {
47
+ const id = randomUUID();
48
+ let latest = known;
49
+ return new Promise((resolve, reject) => {
50
+ const timer = setTimeout(() => reject(new Error(SILENT)), ANSWER_TIMEOUT_MS);
51
+ const settle = (join) => {
52
+ clearTimeout(timer);
53
+ resolve(join);
54
+ };
55
+ connection.listen((message) => {
56
+ if (message.type === 'runs' && message.runs[root] !== undefined) {
57
+ latest = message.runs[root];
58
+ if (message.id === id) {
59
+ settle({ joined: true, progress: latest });
60
+ }
61
+ }
62
+ else if (message.type === 'error' &&
63
+ message.root === root &&
64
+ (message.id === id || message.id === undefined)) {
65
+ settle({ joined: false, progress: latest, refusal: message.message });
66
+ }
67
+ });
68
+ void connection.closed.then(() => {
69
+ clearTimeout(timer);
70
+ reject(new Error(CLOSED));
71
+ });
72
+ connection.send({ type: 'start', root, args: argv, id });
73
+ });
74
+ }
@@ -32,7 +32,7 @@ async function inWorker(root, act) {
32
32
  connection.close();
33
33
  }
34
34
  }
35
- function switched(connection, root, name, on) {
35
+ export function switched(connection, root, name, on) {
36
36
  const id = randomUUID();
37
37
  let sent = false;
38
38
  return new Promise((resolve, reject) => {
@@ -67,20 +67,21 @@ export function stopInWorker(root) {
67
67
  });
68
68
  }
69
69
  export function statusInWorker(root) {
70
- return inWorker(root, async (connection, progress) => {
71
- const lines = [
72
- `next-issue: the run is ${progress.status} in worker ${connection.version}`,
73
- `watching ${onOffText(progress.watching)}, hunting ${onOffText(progress.hunting)}`,
74
- ];
75
- if (progress.upgrade !== undefined) {
76
- lines.push(`stopping for an upgrade to ${progress.upgrade.to}`);
77
- }
78
- if (progress.issues.length === 0) {
79
- lines.push('no issue is running');
80
- }
81
- lines.push(...progress.issues.map(issueLine));
82
- return `${lines.join('\n')}\n`;
83
- });
70
+ return inWorker(root, async (connection, progress) => statusText(connection.version, progress));
71
+ }
72
+ export function statusText(version, progress) {
73
+ const lines = [
74
+ `next-issue: the run is ${progress.status} in worker ${version}`,
75
+ `watching ${onOffText(progress.watching)}, hunting ${onOffText(progress.hunting)}`,
76
+ ];
77
+ if (progress.upgrade !== undefined) {
78
+ lines.push(`stopping for an upgrade to ${progress.upgrade.to}`);
79
+ }
80
+ if (progress.issues.length === 0) {
81
+ lines.push('no issue is running');
82
+ }
83
+ lines.push(...progress.issues.map(issueLine));
84
+ return `${lines.join('\n')}\n`;
84
85
  }
85
86
  function issueLine({ issue, step, round }) {
86
87
  const roundText = round === undefined ? '' : ` (round ${round})`;
package/dist/cli.mjs CHANGED
@@ -10,7 +10,7 @@ import { serve } from './worker/serve.mjs';
10
10
  import { startInWorker } from './cli/start.mjs';
11
11
  import { STATE_DIR } from './shared/state.mjs';
12
12
  import { statusInWorker, stopInWorker, switchInWorker } from './cli/switch-run.mjs';
13
- import { chooseScope, installSkills } from './cli/update.mjs';
13
+ import { chooseScope, installSkills } from './cli/skills.mjs';
14
14
  import { WORKTREE_DIR } from './shared/worktree.mjs';
15
15
  function write(stream, text) {
16
16
  return new Promise((resolve, reject) => {
@@ -28,12 +28,9 @@ async function main() {
28
28
  await write(process.stderr, USAGE);
29
29
  return 1;
30
30
  }
31
- if (args.command === 'update') {
32
- return update(args);
33
- }
34
31
  const root = await repoRoot(process.cwd());
35
32
  if (args.command === 'init') {
36
- return init(root, args.force);
33
+ return init(root, args);
37
34
  }
38
35
  await rejectOldConfig(root);
39
36
  if (args.command === 'stop') {
@@ -67,22 +64,20 @@ async function logs(root) {
67
64
  const tail = process.stdout.isTTY ? Math.max(1, (process.stdout.rows || 24) - 1) : undefined;
68
65
  return followLog(root, file, { tail }, (text) => write(process.stdout, text));
69
66
  }
70
- async function update(args) {
67
+ async function init(root, args) {
71
68
  const scope = await chooseScope(args.scope);
72
- for (const folder of await installSkills(scope)) {
73
- await write(process.stdout, `wrote ${folder}\n`);
74
- }
75
- return 0;
76
- }
77
- async function init(root, force) {
78
- const moved = await moveOldConfig(root, force);
69
+ const moved = await moveOldConfig(root, args.force);
79
70
  if (moved === undefined) {
80
- await write(process.stdout, `wrote ${await writeDefaultConfig(root, force)}\n`);
71
+ const { path, written } = await writeDefaultConfig(root, args.force);
72
+ await write(process.stdout, `${written ? 'wrote' : 'kept'} ${path}\n`);
81
73
  }
82
74
  else {
83
75
  await write(process.stdout, `moved ${OLD_CONFIG_FILE} to ${moved}\n`);
84
76
  }
85
77
  await excludeStateDirectories(root, process.stdout);
78
+ for (const folder of await installSkills(scope)) {
79
+ await write(process.stdout, `wrote ${folder}\n`);
80
+ }
86
81
  return 0;
87
82
  }
88
83
  async function excludeStateDirectories(root, stream) {
@@ -7,17 +7,7 @@ const RUN_FLAGS = new Map([
7
7
  ['--watch', 'watch'],
8
8
  ['--hunt', 'hunt'],
9
9
  ]);
10
- const COMMANDS = [
11
- 'start',
12
- 'init',
13
- 'serve',
14
- 'stop',
15
- 'status',
16
- 'logs',
17
- 'watch',
18
- 'hunt',
19
- 'update',
20
- ];
10
+ const COMMANDS = ['start', 'init', 'serve', 'stop', 'status', 'logs', 'watch', 'hunt'];
21
11
  export const USAGE = `next-issue <command> [options]
22
12
 
23
13
  start start a run: claim issues, fix them and push them to the base branch
@@ -25,13 +15,12 @@ export const USAGE = `next-issue <command> [options]
25
15
  --hunt on|off hunt the repository for bugs and file issues alongside the issues, needs watching (default off)
26
16
  watch on|off switch watching of the going run; off also turns hunting off
27
17
  hunt on|off switch hunting of the going run; on also turns watching on
28
- init write ${CONFIG_FILE} with the defaults and add .next-issue/ and .worktrees/ to info/exclude
18
+ init set up the repository: write ${CONFIG_FILE}, add .next-issue/ and .worktrees/ to info/exclude and install the skills; run it again after an upgrade
19
+ --scope user|project
20
+ user: in ~/.claude/skills; project: in .claude/skills of the main worktree (asks when not given)
29
21
  stop stop the going run after its current issues
30
22
  status show the going run, its worker and its running issues
31
23
  logs show the latest run log and follow it
32
- update install the create-issue and answer-hand-over skills for Claude Code
33
- --scope user|project
34
- user: in ~/.claude/skills; project: in .claude/skills of the main worktree (asks when not given)
35
24
 
36
25
  --force replace an existing config file, with init
37
26
  --help show this text
@@ -47,8 +36,8 @@ export function parseArgs(argv) {
47
36
  if (args.command !== undefined && args.command !== 'start' && runFlag !== undefined) {
48
37
  throw new Error(`${args.command} does not take ${runFlag}: it belongs to start`);
49
38
  }
50
- if (args.command !== undefined && args.command !== 'update' && args.scope !== undefined) {
51
- throw new Error(`${args.command} does not take --scope: it belongs to update`);
39
+ if (args.command !== undefined && args.command !== 'init' && args.scope !== undefined) {
40
+ throw new Error(`${args.command} does not take --scope: it belongs to init`);
52
41
  }
53
42
  if ((args.command === 'watch' || args.command === 'hunt') && args.on === undefined) {
54
43
  throw new Error(`${args.command} takes on or off`);
@@ -115,7 +104,7 @@ function readArgs(passed) {
115
104
  }
116
105
  args.watch = given.watch ?? true;
117
106
  args.hunt = given.hunt ?? false;
118
- return { args, flag, runFlag };
107
+ return { args, flag, runFlag, given };
119
108
  }
120
109
  function command(arg) {
121
110
  const found = COMMANDS.find((name) => name === arg);
@@ -139,3 +128,7 @@ export function parseStartArgs(argv) {
139
128
  }
140
129
  return { ...args, command: 'start' };
141
130
  }
131
+ export function givenStartFlags(argv) {
132
+ parseStartArgs(argv);
133
+ return readArgs(argv).given;
134
+ }
@@ -93,11 +93,11 @@ export async function writeDefaultConfig(root, force) {
93
93
  }
94
94
  catch (error) {
95
95
  if (hasCode(error, 'EEXIST')) {
96
- throw existsAlready();
96
+ return { path, written: false };
97
97
  }
98
98
  throw error;
99
99
  }
100
- return path;
100
+ return { path, written: true };
101
101
  }
102
102
  export async function moveOldConfig(root, force) {
103
103
  const old = join(root, OLD_CONFIG_FILE);
@@ -35,10 +35,9 @@ async function sshHost(url, host) {
35
35
  : host;
36
36
  }
37
37
  export async function repoRoot(cwd) {
38
- const top = await git(cwd, ['rev-parse', '--show-toplevel']);
39
38
  const list = await git(cwd, ['worktree', 'list', '--porcelain']);
40
- const [first = '', second = ''] = list.split('\n');
41
- return first.startsWith('worktree ') && second !== 'bare' ? first.slice('worktree '.length) : top;
39
+ const [first = ''] = list.split('\n');
40
+ return first.slice('worktree '.length);
42
41
  }
43
42
  export async function detectRepo(cwd, remote) {
44
43
  const root = await repoRoot(cwd);
@@ -1,55 +1,3 @@
1
- const OUTCOMES = ['done', 'needs-human', 'error', 'skipped', 'stopped'];
2
- export function formatSummary(summary) {
3
- const tally = OUTCOMES.map((outcome) => `${count(summary.issues, outcome)} ${outcome}`).join(', ');
4
- const roles = Object.entries(summary.roles)
5
- .map(([role, totals]) => `${role} ${tokens(totals.total)} in ${totals.calls}`)
6
- .join(', ');
7
- const lines = [
8
- `run ${summary.runId}`,
9
- `issues ${summary.issues.length}: ${tally}`,
10
- ...summary.issues.map((report) => ` ${issueLine(report)}`),
11
- `tokens ${tokens(summary.total.total)}${roles.length > 0 ? ` (${roles})` : ''}`,
12
- `log ${summary.logFile}`,
13
- ];
14
- return `${lines.join('\n')}\n`;
15
- }
16
1
  export function count(reports, outcome) {
17
2
  return reports.filter((report) => report.outcome === outcome).length;
18
3
  }
19
- function issueLine(report) {
20
- const parts = [`#${report.issue} ${report.outcome.padEnd(11)}`];
21
- if (report.ciFixes > 0) {
22
- parts.push(`ci fixes ${report.ciFixes}`);
23
- }
24
- if (report.reviewRounds > 0) {
25
- parts.push(`reviews ${report.reviewRounds}`);
26
- }
27
- if (report.ms > 0) {
28
- parts.push(duration(report.ms));
29
- }
30
- if (report.reason !== undefined) {
31
- parts.push(`(${report.reason})`);
32
- }
33
- return parts.join(' ').trimEnd();
34
- }
35
- function duration(ms) {
36
- const seconds = Math.round(ms / 1000);
37
- if (seconds < 120) {
38
- return seconds < 60 ? `${seconds}s` : `1m${String(seconds - 60).padStart(2, '0')}s`;
39
- }
40
- const minutes = Math.round(seconds / 60);
41
- if (minutes < 60) {
42
- return `${minutes}m`;
43
- }
44
- const spare = minutes % 60;
45
- return spare === 0 ? `${Math.floor(minutes / 60)}h` : `${Math.floor(minutes / 60)}h${spare}m`;
46
- }
47
- function tokens(value) {
48
- if (value < 1000) {
49
- return String(value);
50
- }
51
- if (value < 1_000_000) {
52
- return `${(value / 1000).toFixed(1)}k`;
53
- }
54
- return `${(value / 1_000_000).toFixed(2)}M`;
55
- }
@@ -7,7 +7,7 @@ import { WebSocket } from 'ws';
7
7
  import { lockHolder } from './lock.mjs';
8
8
  import { isNewer, } from './protocol.mjs';
9
9
  import { checkSocketPath, workerPaths } from './worker-paths.mjs';
10
- const ANSWER_TIMEOUT_MS = 5_000;
10
+ export const ANSWER_TIMEOUT_MS = 5_000;
11
11
  const START_TIMEOUT_MS = 120_000;
12
12
  const HOLDER_GRACE_MS = 2_000;
13
13
  const POLL_MS = 200;
@@ -2,23 +2,22 @@ import { mkdir, rename, rm } from 'node:fs/promises';
2
2
  import { createServer, STATUS_CODES } from 'node:http';
3
3
  import { basename, dirname, join } from 'node:path';
4
4
  import { WebSocketServer } from 'ws';
5
- import { parseStartArgs } from '../shared/args.mjs';
5
+ import { givenStartFlags, parseStartArgs } from '../shared/args.mjs';
6
6
  import { stopChildren, withRunChildren } from '../shared/children.mjs';
7
7
  import { message } from '../shared/errors.mjs';
8
8
  import { lock } from '../shared/lock.mjs';
9
9
  import { startProgress } from './progress.mjs';
10
- import { isNewer, } from '../shared/protocol.mjs';
10
+ import { isNewer } from '../shared/protocol.mjs';
11
11
  import { runRepo } from './run.mjs';
12
12
  import { packageVersion } from '../shared/version.mjs';
13
13
  import { resumeOnSuccessor } from '../shared/worker-client.mjs';
14
14
  import { latestVersion, NPM_LATEST, npxLaunch } from './latest-version.mjs';
15
15
  import { keepLogTrimmed, LOG_CHECK_MS } from './worker-log.mjs';
16
16
  import { checkSocketPath, workerPaths } from '../shared/worker-paths.mjs';
17
- import { active, dropUpgrade, endStatus, newRun, requestStop, requestUpgrade, runControls, runsMessage, setHunting, setWatching, startRefusal, stoppingMessage, stopPoint, switchRefusal, } from './worker-run.mjs';
17
+ import { active, dropUpgrade, endStatus, joinRun, newRun, requestStop, requestUpgrade, runControls, runsMessage, setHunting, setWatching, startRefusal, stoppingMessage, stopPoint, switchRefusal, } from './worker-run.mjs';
18
18
  import { broadcast, closer, fileId, isLaunch, listen, parseMessage, removeOwned, send, sendAll, sendAllSent, shutdown, stopListening, } from './worker-server.mjs';
19
19
  const LOCK_WAIT_MS = 5_000;
20
20
  const IDLE_MS = 30_000;
21
- const REJOIN_GRACE_MS = 5_000;
22
21
  export async function startWorker(options) {
23
22
  checkSocketPath(options.socketPath);
24
23
  await mkdir(dirname(options.lockPath), { recursive: true });
@@ -38,23 +37,6 @@ export async function startWorker(options) {
38
37
  const server = createServer();
39
38
  const sockets = new WebSocketServer({ server });
40
39
  const busy = () => [...runs.values()].some(active);
41
- let followed = false;
42
- let lateEnd;
43
- const awaitRejoin = (end) => {
44
- if (followed) {
45
- return Promise.resolve();
46
- }
47
- return new Promise((resolve) => {
48
- const timer = setTimeout(resolve, REJOIN_GRACE_MS);
49
- lateEnd = {
50
- end,
51
- sent: () => {
52
- clearTimeout(timer);
53
- resolve();
54
- },
55
- };
56
- });
57
- };
58
40
  let idleTimer;
59
41
  const idleMs = options.idleMs ?? IDLE_MS;
60
42
  const handOver = async (how, run) => {
@@ -82,7 +64,7 @@ export async function startWorker(options) {
82
64
  }
83
65
  });
84
66
  const closeWhenIdle = () => {
85
- if ((restart !== undefined || sockets.clients.size === 0) && !busy() && lateEnd === undefined) {
67
+ if ((restart !== undefined || sockets.clients.size === 0) && !busy()) {
86
68
  void close();
87
69
  }
88
70
  };
@@ -110,10 +92,29 @@ export async function startWorker(options) {
110
92
  }
111
93
  upgradeBetweenIssues(run, true);
112
94
  };
113
- const start = (refuse, root, argv, resume) => {
114
- const refusal = lateEnd === undefined
115
- ? startRefusal(runs.get(root), restart !== undefined)
116
- : 'the worker is closing, try again soon';
95
+ const joinGoing = (socket, refuse, run, argv, id) => {
96
+ let refusal;
97
+ try {
98
+ refusal = joinRun(run, givenStartFlags(argv));
99
+ }
100
+ catch (error) {
101
+ refusal = message(error);
102
+ }
103
+ if (refusal !== undefined) {
104
+ refuse(refusal);
105
+ return;
106
+ }
107
+ broadcast(sockets, runs);
108
+ upgradeBetweenIssues(run);
109
+ send(socket, runsMessage(runs, id));
110
+ };
111
+ const start = (socket, refuse, root, argv, resume, id) => {
112
+ const going = runs.get(root);
113
+ if (active(going) && !resume) {
114
+ joinGoing(socket, refuse, going, argv, id);
115
+ return;
116
+ }
117
+ const refusal = startRefusal(going, restart !== undefined);
117
118
  if (refusal !== undefined) {
118
119
  if (!resume) {
119
120
  refuse(refusal);
@@ -136,12 +137,6 @@ export async function startWorker(options) {
136
137
  };
137
138
  broadcast(sockets, runs);
138
139
  let summary;
139
- const ended = async (end) => {
140
- await sendAllSent(sockets, end);
141
- if (resume) {
142
- await awaitRejoin(end);
143
- }
144
- };
145
140
  withRunChildren(run.children, () => options.runRepo(root, args, {
146
141
  ...runControls(run, update),
147
142
  beforeClaim: () => upgradeToLatest(run),
@@ -158,7 +153,7 @@ export async function startWorker(options) {
158
153
  }))
159
154
  .then((code) => {
160
155
  update({ ...run.progress, status: endStatus(run) });
161
- return ended({
156
+ return sendAllSent(sockets, {
162
157
  type: 'end',
163
158
  root,
164
159
  code,
@@ -167,7 +162,7 @@ export async function startWorker(options) {
167
162
  }, (error) => {
168
163
  process.stderr.write(`next-issue failed: ${message(error)}\n`);
169
164
  update({ ...run.progress, status: 'failed', error: message(error) });
170
- return ended({ type: 'end', root, code: 1, error: message(error) });
165
+ return sendAllSent(sockets, { type: 'end', root, code: 1, error: message(error) });
171
166
  })
172
167
  .finally(() => void close());
173
168
  };
@@ -219,7 +214,7 @@ export async function startWorker(options) {
219
214
  refuse(`the worker serves ${options.root} only`);
220
215
  }
221
216
  else if (value.type === 'start') {
222
- start(refuse, value.root, value.args ?? [], value.resume === true);
217
+ start(socket, refuse, value.root, value.args ?? [], value.resume === true, value.id);
223
218
  }
224
219
  else if (value.type === 'stop') {
225
220
  stop(socket, refuse, value.root, value.after, value.id);
@@ -230,13 +225,6 @@ export async function startWorker(options) {
230
225
  else if (value.type === 'watch') {
231
226
  toggle(refuse, value.root, value.on, setWatching);
232
227
  }
233
- else if (value.type === 'rejoin') {
234
- followed = true;
235
- if (lateEnd !== undefined) {
236
- const { end, sent } = lateEnd;
237
- socket.send(JSON.stringify(end), () => sent());
238
- }
239
- }
240
228
  };
241
229
  sockets.on('connection', (socket) => {
242
230
  send(socket, { type: 'hello', version: options.version });
@@ -29,12 +29,30 @@ export function startRefusal(run, restart) {
29
29
  }
30
30
  return undefined;
31
31
  }
32
- export function runsMessage(runs) {
32
+ export function runsMessage(runs, id) {
33
33
  return {
34
34
  type: 'runs',
35
35
  runs: Object.fromEntries([...runs].map(([root, run]) => [root, run.progress])),
36
+ ...(id === undefined ? {} : { id }),
36
37
  };
37
38
  }
39
+ export function joinRun(run, given) {
40
+ if (run.stoppedByPerson === true) {
41
+ if (run.stop !== 'issue') {
42
+ return 'the run is stopping';
43
+ }
44
+ run.stop = undefined;
45
+ run.stoppedByPerson = false;
46
+ run.progress = { ...run.progress, status: 'running' };
47
+ }
48
+ if (given.watch !== undefined) {
49
+ setWatching(run, given.watch);
50
+ }
51
+ if (given.hunt !== undefined) {
52
+ setHunting(run, given.hunt);
53
+ }
54
+ return undefined;
55
+ }
38
56
  export function stopPoint(after) {
39
57
  return STOP_POINTS.find((point) => point === (after ?? 'issue'));
40
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "16.2.0",
3
+ "version": "16.4.0",
4
4
  "description": "Autonomous issue harness driven by the Claude Agent SDK",
5
5
  "keywords": [
6
6
  "github",