next-issue 12.0.2 → 12.2.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,7 +34,7 @@ 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 (`--watch on|off`, `--hunt on|off`), `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` watches, the worker upgrades it between issues like any other run (see [Worker](#worker)): the run stops after its running issues and starts again on the newer worker with watching on and its `--hunt` setting. `start` follows it across the upgrade: it connects to the newer worker, prints `next-issue: the worker was updated from <old> to <new>` once on standard error, goes on printing the output of the run, keeps `Ctrl-C` working (a press while it moves to the newer worker reaches the run there) and exits only when the run ends, with exit code 1 when an issue needed a person or failed before or after the upgrade. Lines that the run prints on the newer worker before `start` connects go only to `.next-issue/worker.log`. When the run does not go on in the newer worker within 30 seconds, `start` fails with `the worker closed the connection, and the run did not go on in the newer worker` and exits with 1. A run that does not watch is not upgraded: 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
 
@@ -369,7 +369,7 @@ In a run of the `serve` worker, a client can switch hunting and watching on or o
369
369
  - asks a watching run to check for new issues now when a client sends `{ "type": "refresh", "root": "<path>" }`. A run that waits between passes starts a new pass at once, and its next wait starts again at 1 minute; a waiting hunter checks the ready count again. While a pass runs, the run reads the open issues again, so its open-issue count is current, and claims a new issue only when a slot is free. A refresh for a run that is stopping or does not watch, or with no run going, changes nothing and gets no answer;
370
370
  - exits, and removes its socket and lock files, when no run is going and no client is connected, or when no client connects in the 30 seconds after it starts;
371
371
  - waits up to 5 seconds for the lock when a worker that is closing still holds it;
372
- - closes once no run is going when a client with a newer version connects, so that the client can start the newer worker. A run that watches is stopped between issues for that, as `stop` with `issue` does: it claims nothing new, and its running issues and its current hunt finish. Its progress then holds `"upgrade": { "from": "<worker version>", "to": "<client version>" }`. A stop by a person, or turning watching off, drops that field, so no client starts the run again. A run that does not watch, or that `next-issue start` started, is left alone. Meanwhile the worker refuses every start with `the worker is restarting, try again soon`. A `start` with `"resume": true` gets no error when the worker refuses it;
372
+ - closes once no run is going when a client with a newer version connects, so that the client can start the newer worker. The `hello` of a client can say how to start the worker of its version, as `"launch": { "command": "<command>", "args": ["<arg>", ...] }`: pi sends `npx -y next-issue@<version> serve`, and `next-issue start` its own `node <script> serve`. A run that watches is stopped between issues for that, as `stop` with `issue` does: it claims nothing new, and its running issues and its current hunt finish. Its progress then holds `"upgrade": { "from": "<worker version>", "to": "<client version>" }`, with `"resumes": true` when the first newer client gave a `launch`. A stop by a person, or turning watching off, drops that field, so the run does not start again. With `resumes`, once the run ends, the worker stops listening, runs that command in the repository with its output in `.next-issue/worker.log` (or uses a worker that already listens there), and asks the newer worker to start the run again with `--watch on` and the same `--hunt` setting, before it closes. This works with no client connected. When the newer worker does not start or does not start the run, the worker writes the reason to `.next-issue/worker.log`, and its clients see the run `failed` with an `error` that starts with `the worker could not start next-issue <version>`. Without `resumes`, a client starts the newer worker and the run again. A run that does not watch is left alone; a run that `next-issue start` started is not, and `start` follows it to the newer worker. Meanwhile the worker refuses every start with `the worker is restarting, try again soon`. A `start` with `"resume": true` gets no error when the worker refuses it;
373
373
  - stops every agent and command and exits on `SIGTERM`, `SIGHUP` or `SIGINT`, and removes its socket and lock files;
374
374
  - keeps `.next-issue/worker.log`, where the extension writes the output of the worker, within 10 MiB: when it starts and once a minute while it runs, it cuts a log of more than 10 MiB to its newest 5 MiB, from the start of a line. It skips the cut while a command that writes to the log runs. The run logs under `.next-issue/runs/` hold the same events.
375
375
 
package/dist/serve.mjs CHANGED
@@ -13,10 +13,11 @@ import { listQuestions, questionSender, send } from './questions.mjs';
13
13
  import { runRepo } from './run.mjs';
14
14
  import { listUpcoming, sendUpcoming } from './upcoming.mjs';
15
15
  import { packageVersion } from './version.mjs';
16
+ import { resumeOnSuccessor } from './worker-client.mjs';
16
17
  import { keepLogTrimmed, LOG_CHECK_MS } from './worker-log.mjs';
17
18
  import { checkSocketPath, workerPaths } from './worker-paths.mjs';
18
19
  import { active, dropUpgrade, endStatus, newRun, requestRefresh, requestStop, requestUpgrade, runControls, runsMessage, setHunting, setWatching, startRefusal, stoppingMessage, stopPoint, switchRefusal, } from './worker-run.mjs';
19
- import { broadcast, closer, fileId, listen, parseMessage, removeOwned, sendAll, shutdown, } from './worker-server.mjs';
20
+ import { broadcast, closer, fileId, isLaunch, listen, parseMessage, removeOwned, sendAll, shutdown, stopListening, } from './worker-server.mjs';
20
21
  const LOCK_WAIT_MS = 5_000;
21
22
  const IDLE_MS = 30_000;
22
23
  export async function startWorker(options) {
@@ -34,6 +35,7 @@ export async function startWorker(options) {
34
35
  };
35
36
  const runs = new Map();
36
37
  let restart;
38
+ let successor;
37
39
  const server = createServer();
38
40
  const sockets = new WebSocketServer({ server });
39
41
  const sendQuestions = questionSender(options.questions);
@@ -42,9 +44,29 @@ export async function startWorker(options) {
42
44
  const outsideRuns = AsyncLocalStorage.snapshot();
43
45
  const busy = () => [...runs.values()].some(active);
44
46
  let idleTimer;
47
+ const handOver = async (how, run) => {
48
+ const listening = stopListening(server);
49
+ removeOwned(owned);
50
+ try {
51
+ await resumeOnSuccessor(options.root, how, resumeArgs(run));
52
+ }
53
+ catch (error) {
54
+ const reason = `the worker could not start next-issue ${restart}: ${message(error)}`;
55
+ process.stderr.write(`next-issue: ${reason}\n`);
56
+ run.progress = { ...run.progress, status: 'failed', error: reason };
57
+ broadcast(sockets, runs);
58
+ }
59
+ await shutdown(server, sockets, owned, listening);
60
+ };
45
61
  const { closed, close } = closer(async () => {
46
62
  clearTimeout(idleTimer);
47
- await shutdown(server, sockets, owned);
63
+ const run = runs.get(options.root);
64
+ if (successor !== undefined && run !== undefined && upgradedRun(run)) {
65
+ await handOver(successor, run);
66
+ }
67
+ else {
68
+ await shutdown(server, sockets, owned);
69
+ }
48
70
  });
49
71
  const closeWhenIdle = () => {
50
72
  if ((restart !== undefined || sockets.clients.size === 0) && !busy()) {
@@ -52,11 +74,19 @@ export async function startWorker(options) {
52
74
  }
53
75
  };
54
76
  const upgradeBetweenIssues = (run) => {
55
- if (restart !== undefined && requestUpgrade(run, { from: options.version, to: restart })) {
77
+ if (restart === undefined) {
78
+ return;
79
+ }
80
+ const upgrade = {
81
+ from: options.version,
82
+ to: restart,
83
+ ...(successor === undefined ? {} : { resumes: true }),
84
+ };
85
+ if (requestUpgrade(run, upgrade)) {
56
86
  broadcast(sockets, runs);
57
87
  }
58
88
  };
59
- const start = (refuse, root, argv, resume, command) => {
89
+ const start = (refuse, root, argv, resume) => {
60
90
  const refusal = startRefusal(runs.get(root), restart !== undefined);
61
91
  if (refusal !== undefined) {
62
92
  if (!resume) {
@@ -72,7 +102,7 @@ export async function startWorker(options) {
72
102
  refuse(message(error));
73
103
  return;
74
104
  }
75
- const run = newRun({ ...startProgress(args.hunt), watching: args.watch }, command);
105
+ const run = newRun({ ...startProgress(args.hunt), watching: args.watch });
76
106
  runs.set(root, run);
77
107
  const update = (next) => {
78
108
  run.progress = next;
@@ -138,8 +168,14 @@ export async function startWorker(options) {
138
168
  if (typeof value.version !== 'string') {
139
169
  throw new Error('a hello message needs its version as a string');
140
170
  }
171
+ if (value.launch !== undefined && !isLaunch(value.launch)) {
172
+ throw new Error('a hello message needs its launch as a command and a list of args');
173
+ }
141
174
  if (isNewer(value.version, options.version)) {
142
- restart ??= value.version;
175
+ if (restart === undefined) {
176
+ restart = value.version;
177
+ successor = value.launch;
178
+ }
143
179
  runs.forEach(upgradeBetweenIssues);
144
180
  closeWhenIdle();
145
181
  }
@@ -148,7 +184,7 @@ export async function startWorker(options) {
148
184
  refuse(`the worker serves ${options.root} only`);
149
185
  }
150
186
  else if (value.type === 'start') {
151
- start(refuse, value.root, value.args ?? [], value.resume === true, value.command === true);
187
+ start(refuse, value.root, value.args ?? [], value.resume === true);
152
188
  }
153
189
  else if (value.type === 'stop') {
154
190
  stop(socket, refuse, value.root, value.after, value.id);
@@ -197,6 +233,12 @@ export async function startWorker(options) {
197
233
  idleTimer = setTimeout(closeWhenIdle, options.idleMs ?? IDLE_MS);
198
234
  return { closed, close, release: () => removeOwned(owned) };
199
235
  }
236
+ function upgradedRun(run) {
237
+ return run.progress.upgrade !== undefined && run.progress.status === 'stopped';
238
+ }
239
+ function resumeArgs(run) {
240
+ return ['--watch', 'on', '--hunt', run.progress.hunting ? 'on' : 'off'];
241
+ }
200
242
  function refuser(socket, value, served) {
201
243
  const root = value.type === 'hello' ? served : value.root;
202
244
  const id = 'id' in value ? value.id : undefined;
package/dist/start.mjs CHANGED
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
2
2
  import { NOTES, onPresses } from './interrupt.mjs';
3
3
  import { formatSummary } from './summary.mjs';
4
4
  import { packageVersion } from './version.mjs';
5
- import { CLOSED, going, reachWorker } from './worker-client.mjs';
5
+ import { CLOSED, going, reachWorker, rejoinRun } from './worker-client.mjs';
6
6
  const RUN_GOING = 'a run is going in this repository already';
7
7
  function output() {
8
8
  let queue = Promise.resolve();
@@ -27,24 +27,36 @@ export async function startInWorker(root, args, argv) {
27
27
  }
28
28
  const out = output();
29
29
  const code = await follow(connection, root, args, argv, out);
30
- connection.close();
31
30
  await out.flushed();
32
31
  return code;
33
32
  }
34
- function follow(connection, root, args, argv, out) {
33
+ function follow(first, root, args, argv, out) {
35
34
  const id = randomUUID();
36
35
  const stopId = randomUUID();
36
+ let connection = first;
37
+ let latest;
38
+ let upgradeEnd;
39
+ let earlierCode = 0;
40
+ const held = [];
41
+ const send = (message) => {
42
+ if (upgradeEnd === undefined) {
43
+ connection.send(message);
44
+ }
45
+ else {
46
+ held.push(message);
47
+ }
48
+ };
37
49
  return new Promise((resolve) => {
38
50
  const stopListening = onPresses((presses) => {
39
51
  if (presses === 1) {
40
- connection.send({ type: 'stop', root, after: 'issue', id: stopId });
52
+ send({ type: 'stop', root, after: 'issue', id: stopId });
41
53
  }
42
54
  else if (presses === 2) {
43
55
  out.print(process.stderr, `${NOTES.round}\n`);
44
- connection.send({ type: 'stop', root, after: 'round' });
56
+ send({ type: 'stop', root, after: 'round' });
45
57
  }
46
58
  else {
47
- connection.send({ type: 'stop', root, after: 'now' });
59
+ send({ type: 'stop', root, after: 'now' });
48
60
  }
49
61
  });
50
62
  let settled = false;
@@ -52,7 +64,8 @@ function follow(connection, root, args, argv, out) {
52
64
  if (!settled) {
53
65
  settled = true;
54
66
  stopListening();
55
- resolve(code);
67
+ connection.close();
68
+ resolve(Math.max(code, earlierCode));
56
69
  }
57
70
  };
58
71
  const fail = (text) => {
@@ -61,7 +74,10 @@ function follow(connection, root, args, argv, out) {
61
74
  }
62
75
  settle(1);
63
76
  };
64
- connection.listen((message) => {
77
+ const onMessage = (message) => {
78
+ if (message.type === 'runs') {
79
+ latest = message.runs[root];
80
+ }
65
81
  if (!('root' in message) || message.root !== root) {
66
82
  return;
67
83
  }
@@ -80,14 +96,55 @@ function follow(connection, root, args, argv, out) {
80
96
  else if (message.type === 'end' && message.error !== undefined) {
81
97
  fail(message.error);
82
98
  }
99
+ else if (message.type === 'end' && latest?.upgrade !== undefined) {
100
+ upgradeEnd = message.code;
101
+ }
83
102
  else if (message.type === 'end') {
84
103
  if (!args.watch && message.summary !== undefined) {
85
104
  out.print(process.stdout, formatSummary(message.summary));
86
105
  }
87
106
  settle(message.code);
88
107
  }
89
- });
90
- void connection.closed.then(() => fail(CLOSED));
91
- connection.send({ type: 'start', root, args: argv, command: true, id });
108
+ };
109
+ const rejoin = async (upgrade) => {
110
+ const found = await rejoinRun(root).catch(() => undefined);
111
+ if (found === undefined) {
112
+ fail(`${CLOSED}, and the run did not go on in the newer worker`);
113
+ return;
114
+ }
115
+ if (settled) {
116
+ found.close();
117
+ return;
118
+ }
119
+ out.print(process.stderr, `next-issue: the worker was updated from ${upgrade.from} to ${upgrade.to}\n`);
120
+ earlierCode = Math.max(earlierCode, upgradeEnd ?? 0);
121
+ upgradeEnd = undefined;
122
+ latest = found.runs[root];
123
+ follows(found);
124
+ for (const message of held.splice(0)) {
125
+ found.send(message);
126
+ }
127
+ };
128
+ const closed = () => {
129
+ if (upgradeEnd === undefined) {
130
+ fail(CLOSED);
131
+ }
132
+ else if (latest?.error !== undefined) {
133
+ fail(latest.error);
134
+ }
135
+ else if (latest?.upgrade === undefined) {
136
+ settle(upgradeEnd);
137
+ }
138
+ else {
139
+ void rejoin(latest.upgrade);
140
+ }
141
+ };
142
+ const follows = (next) => {
143
+ connection = next;
144
+ next.listen(onMessage);
145
+ void next.closed.then(closed);
146
+ };
147
+ follows(first);
148
+ first.send({ type: 'start', root, args: argv, id });
92
149
  });
93
150
  }
@@ -5,7 +5,7 @@ import { dirname } from 'node:path';
5
5
  import { setTimeout as delay } from 'node:timers/promises';
6
6
  import { WebSocket } from 'ws';
7
7
  import { lockHolder } from './lock.mjs';
8
- import { isNewer } from './protocol.mjs';
8
+ import { isNewer, } from './protocol.mjs';
9
9
  import { checkSocketPath, workerPaths } from './worker-paths.mjs';
10
10
  const ANSWER_TIMEOUT_MS = 5_000;
11
11
  const START_TIMEOUT_MS = 30_000;
@@ -29,6 +29,9 @@ function parse(text) {
29
29
  return undefined;
30
30
  }
31
31
  }
32
+ function ownLaunch() {
33
+ return { command: process.execPath, args: [...process.execArgv, process.argv[1], 'serve'] };
34
+ }
32
35
  function open(socketPath, version) {
33
36
  return new Promise((resolve, reject) => {
34
37
  const socket = new WebSocket('ws://localhost/', {
@@ -71,7 +74,7 @@ function open(socketPath, version) {
71
74
  ready = true;
72
75
  clearTimeout(timer);
73
76
  if (version !== undefined && !Object.values(message.runs).some(going)) {
74
- socket.send(JSON.stringify({ type: 'hello', version }));
77
+ socket.send(JSON.stringify({ type: 'hello', version, launch: ownLaunch() }));
75
78
  }
76
79
  resolve({
77
80
  version: workerVersion,
@@ -129,14 +132,14 @@ async function waitForStart(paths, version, exited) {
129
132
  }
130
133
  }
131
134
  }
132
- async function launch(root, version) {
135
+ async function launch(root, version, how) {
133
136
  const paths = workerPaths(root);
134
137
  const held = await waitForHolder(paths, version);
135
138
  if (held !== undefined) {
136
139
  return held;
137
140
  }
138
141
  let exited;
139
- spawnServe(root, (reason) => {
142
+ spawnServe(root, how, (reason) => {
140
143
  exited ??= reason;
141
144
  });
142
145
  return waitForStart(paths, version, () => exited);
@@ -145,7 +148,7 @@ export async function reachWorker(root, version) {
145
148
  const { socketPath } = workerPaths(root);
146
149
  checkSocketPath(socketPath);
147
150
  for (let tries = 1;; tries += 1) {
148
- const found = (await tryOpen(socketPath, version)) ?? (await launch(root, version));
151
+ const found = (await tryOpen(socketPath, version)) ?? (await launch(root, version, ownLaunch()));
149
152
  const busy = Object.values(found.runs).some(going);
150
153
  if (!isNewer(version, found.version) || busy || tries >= UPGRADE_TRIES) {
151
154
  return found;
@@ -154,6 +157,55 @@ export async function reachWorker(root, version) {
154
157
  found.close();
155
158
  }
156
159
  }
160
+ function startedRun(found, root) {
161
+ return new Promise((resolve, reject) => {
162
+ const timer = setTimeout(() => reject(new Error('the newer worker did not start the run')), ANSWER_TIMEOUT_MS);
163
+ const settle = (error) => {
164
+ clearTimeout(timer);
165
+ if (error === undefined) {
166
+ resolve();
167
+ }
168
+ else {
169
+ reject(error);
170
+ }
171
+ };
172
+ found.listen((message) => {
173
+ if (message.type === 'runs' && going(message.runs[root])) {
174
+ settle();
175
+ }
176
+ else if (message.type === 'error' && message.root === root) {
177
+ settle(new Error(message.message));
178
+ }
179
+ });
180
+ void found.closed.then(() => settle(new Error(CLOSED)));
181
+ });
182
+ }
183
+ export async function resumeOnSuccessor(root, how, args) {
184
+ const { socketPath } = workerPaths(root);
185
+ const found = (await tryOpen(socketPath)) ?? (await launch(root, undefined, how));
186
+ try {
187
+ if (!going(found.runs[root])) {
188
+ found.send({ type: 'start', root, args, resume: true });
189
+ await startedRun(found, root);
190
+ }
191
+ }
192
+ finally {
193
+ found.close();
194
+ }
195
+ }
196
+ export async function rejoinRun(root) {
197
+ const { socketPath } = workerPaths(root);
198
+ const deadline = Date.now() + START_TIMEOUT_MS;
199
+ while (Date.now() < deadline) {
200
+ const found = await tryOpen(socketPath);
201
+ if (found !== undefined && going(found.runs[root])) {
202
+ return found;
203
+ }
204
+ found?.close();
205
+ await delay(POLL_MS);
206
+ }
207
+ return undefined;
208
+ }
157
209
  export function findWorker(root) {
158
210
  const { socketPath } = workerPaths(root);
159
211
  checkSocketPath(socketPath);
@@ -162,12 +214,12 @@ export function findWorker(root) {
162
214
  function exitText(code, signal) {
163
215
  return signal === null ? `exit code ${code}` : `signal ${signal}`;
164
216
  }
165
- function spawnServe(root, onExit) {
217
+ function spawnServe(root, how, onExit) {
166
218
  const { logPath } = workerPaths(root);
167
219
  mkdirSync(dirname(logPath), { recursive: true });
168
220
  const log = openSync(logPath, 'a');
169
221
  try {
170
- const child = spawn(process.execPath, [...process.execArgv, process.argv[1], 'serve'], {
222
+ const child = spawn(how.command, how.args, {
171
223
  cwd: root,
172
224
  detached: true,
173
225
  stdio: ['ignore', log, log],
@@ -4,10 +4,9 @@ import { onOff } from './switch.mjs';
4
4
  import { applyEvent } from './progress.mjs';
5
5
  import { STOP_POINTS, } from './protocol.mjs';
6
6
  import { refresher } from './refresh.mjs';
7
- export function newRun(progress, command = false) {
7
+ export function newRun(progress) {
8
8
  return {
9
9
  progress,
10
- command,
11
10
  children: runChildren(),
12
11
  watching: onOff(progress.watching === true),
13
12
  hunting: onOff(progress.hunting),
@@ -70,7 +69,7 @@ export function stoppingMessage(root, run, id) {
70
69
  };
71
70
  }
72
71
  export function requestUpgrade(run, upgrade) {
73
- if (run.command || !run.watching.on() || run.stop !== undefined || !requestStop(run, 'issue')) {
72
+ if (!run.watching.on() || run.stop !== undefined || !requestStop(run, 'issue')) {
74
73
  return false;
75
74
  }
76
75
  run.progress = { ...run.progress, upgrade };
@@ -7,6 +7,9 @@ function isRecord(value) {
7
7
  function isStringArray(value) {
8
8
  return Array.isArray(value) && value.every((item) => typeof item === 'string');
9
9
  }
10
+ export function isLaunch(value) {
11
+ return isRecord(value) && typeof value['command'] === 'string' && isStringArray(value['args']);
12
+ }
10
13
  function isClientMessage(value) {
11
14
  if (!isRecord(value) || typeof value['type'] !== 'string') {
12
15
  return false;
@@ -61,6 +64,9 @@ export function listen(server, path) {
61
64
  function whenClosed(close) {
62
65
  return new Promise((resolve) => close(() => resolve()));
63
66
  }
67
+ export function stopListening(server) {
68
+ return whenClosed((done) => server.close(done));
69
+ }
64
70
  export function fileId(path) {
65
71
  const found = statSync(path, { throwIfNoEntry: false });
66
72
  return found?.isSocket() === true ? `${found.dev}:${found.ino}` : '';
@@ -73,12 +79,12 @@ export function removeOwned(owned) {
73
79
  rmSync(owned.lockPath, { force: true });
74
80
  }
75
81
  }
76
- export async function shutdown(server, sockets, owned) {
82
+ export async function shutdown(server, sockets, owned, listening) {
77
83
  for (const socket of sockets.clients) {
78
84
  socket.terminate();
79
85
  }
80
86
  await whenClosed((done) => sockets.close(done));
81
- await whenClosed((done) => server.close(done));
87
+ await (listening ?? stopListening(server));
82
88
  removeOwned(owned);
83
89
  }
84
90
  export function closer(stop) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "12.0.2",
3
+ "version": "12.2.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",