next-issue 14.4.9 → 14.4.10

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
@@ -93,7 +93,7 @@ A field that is not in the file keeps its default. See [Configuration](https://g
93
93
  | `refresh` | Ask the going run to check for new issues now |
94
94
  | `init` | Write the config file with the defaults |
95
95
  | `serve` | Run the worker of this repository that the clients talk to |
96
- | `stop` | Stop the worker of this repository |
96
+ | `stop` | Stop the going run after its current issues |
97
97
  | `logs` | Show the latest run log and follow it |
98
98
  | `update` | Install the `create-issue` and `answer-hand-over` skills for Claude Code |
99
99
  | `--force` | With `init`: replace an existing config file |
@@ -73,3 +73,21 @@ function switched(connection, root, name, on) {
73
73
  sent = true;
74
74
  });
75
75
  }
76
+ export async function stopInWorker(root) {
77
+ const connection = await findWorker(root);
78
+ if (connection === undefined) {
79
+ return NO_RUN;
80
+ }
81
+ const progress = connection.runs[root];
82
+ if (!going(progress)) {
83
+ connection.close();
84
+ return NO_RUN;
85
+ }
86
+ if (progress.status === 'stopping') {
87
+ connection.close();
88
+ return 'next-issue: the run is stopping already\n';
89
+ }
90
+ connection.send({ type: 'stop', root, after: 'issue' });
91
+ await connection.end();
92
+ return 'next-issue: the run will stop after its current issues\n';
93
+ }
package/dist/cli.mjs CHANGED
@@ -5,14 +5,12 @@ import { OLD_CONFIG_FILE } from './shared/config-fields.mjs';
5
5
  import { message } from './shared/errors.mjs';
6
6
  import { repoRoot } from './shared/git.mjs';
7
7
  import { ensureExcluded, excludeFile, removeIgnored } from './cli/ignore.mjs';
8
- import { stopWorker } from './shared/lock.mjs';
9
8
  import { followLog, newestRunLog } from './cli/logs.mjs';
10
9
  import { serve } from './worker/serve.mjs';
11
10
  import { startInWorker } from './cli/start.mjs';
12
11
  import { STATE_DIR } from './shared/state.mjs';
13
- import { refreshInWorker, switchInWorker } from './cli/switch-run.mjs';
12
+ import { refreshInWorker, stopInWorker, switchInWorker } from './cli/switch-run.mjs';
14
13
  import { chooseScope, installSkills } from './cli/update.mjs';
15
- import { workerPaths } from './shared/worker-paths.mjs';
16
14
  import { WORKTREE_DIR } from './shared/worktree.mjs';
17
15
  function write(stream, text) {
18
16
  return new Promise((resolve, reject) => {
@@ -39,7 +37,8 @@ async function main() {
39
37
  }
40
38
  await rejectOldConfig(root);
41
39
  if (args.command === 'stop') {
42
- return stop(root);
40
+ await write(process.stdout, await stopInWorker(root));
41
+ return 0;
43
42
  }
44
43
  if (args.command === 'watch' || args.command === 'hunt') {
45
44
  await write(process.stdout, await switchInWorker(root, args.command, args.on));
@@ -62,15 +61,6 @@ function run(root, args, argv) {
62
61
  process.stderr.on('error', () => { });
63
62
  return startInWorker(root, args, argv.slice(1));
64
63
  }
65
- const STOPPED = {
66
- none: () => 'next-issue: no worker is running\n',
67
- worker: (pid) => `next-issue: stopped the worker with process id ${pid}\n`,
68
- };
69
- async function stop(root) {
70
- const { stopped, pid } = await stopWorker(workerPaths(root));
71
- await write(process.stdout, STOPPED[stopped](pid));
72
- return 0;
73
- }
74
64
  async function logs(root) {
75
65
  const file = await newestRunLog(root);
76
66
  if (file === undefined) {
@@ -28,7 +28,7 @@ export const USAGE = `next-issue <command> [options]
28
28
  refresh ask the going run to check for new issues now
29
29
  init write ${CONFIG_FILE} with the defaults and add .next-issue/ and .worktrees/ to info/exclude
30
30
  serve run the worker of this repository that the clients talk to
31
- stop stop the worker of this repository
31
+ stop stop the going run after its current issues
32
32
  logs show the latest run log and follow it
33
33
  update install the create-issue and answer-hand-over skills for Claude Code
34
34
  --scope user|project
@@ -1,5 +1,3 @@
1
- import { repoArg } from './gh.mjs';
2
- import { heldByPerson, readState } from './state.mjs';
3
1
  import { AGENT_PREFIX, agentHeading } from './text.mjs';
4
2
  export const HAND_OVER = agentHeading('Hand-over', 'needs help');
5
3
  const OLD_HAND_OVER = 'next-issue needs help:';
@@ -54,18 +52,6 @@ async function handOverThread(repo, ports, writer, issue) {
54
52
  const comments = await ports.threadComments(repo, issue);
55
53
  return { comments, last: await lastHandOver(comments, writer) };
56
54
  }
57
- export async function waitingQuestions(repo, config, ports) {
58
- const writer = writers(repo, ports);
59
- const issues = await ports.openIssues(repo, config.issueLimit, [config.labels.needsHuman]);
60
- const questions = [];
61
- for (const issue of issues) {
62
- const question = await waitingQuestion(repo, config, ports, writer, issue);
63
- if (question) {
64
- questions.push(question);
65
- }
66
- }
67
- return questions;
68
- }
69
55
  function postedAfter(comment, since) {
70
56
  return since !== undefined && comment.createdAt !== undefined && comment.createdAt > since;
71
57
  }
@@ -79,38 +65,6 @@ function answerCandidates(comments, last, pending) {
79
65
  async function replyAfter(comments, last, writer, pending) {
80
66
  return writerQuotes(answerCandidates(comments, last, pending).filter((comment) => !fromHarness(comment)), writer);
81
67
  }
82
- async function savedState(repo, issue) {
83
- try {
84
- return await readState(repo, issue);
85
- }
86
- catch {
87
- return undefined;
88
- }
89
- }
90
- async function waitingQuestion(repo, config, ports, writer, issue) {
91
- const { comments, last } = await handOverThread(repo, ports, writer, issue.number);
92
- const saved = await savedState(repo, issue.number);
93
- const pending = saved?.pendingHandOver;
94
- if (!heldByPerson(saved) && (await replyAfter(comments, last, writer, pending)).length > 0) {
95
- return undefined;
96
- }
97
- const latest = comments[last];
98
- const comment = pending === undefined || (latest !== undefined && postedAfter(latest, pending.since))
99
- ? latest
100
- : undefined;
101
- return {
102
- issue: issue.number,
103
- title: issue.title,
104
- reason: (comment && handOverReason(comment)) ?? pending?.reason ?? '',
105
- url: comment?.url ?? '',
106
- repo: repoArg(repo),
107
- labels: {
108
- needsHuman: config.labels.needsHuman,
109
- skip: config.labels.skip,
110
- ready: config.labels.ready,
111
- },
112
- };
113
- }
114
68
  export async function writerComments(context, log, issue) {
115
69
  const { repo, ports } = context;
116
70
  const comments = (await ports.issueComments(repo, issue)).filter((comment) => !fromHarness(comment));
@@ -206,7 +206,6 @@ export async function claimedError(context, log, issue, state, error, started) {
206
206
  catch (failure) {
207
207
  log.event('hand-over.error', { error: message(failure) });
208
208
  }
209
- // The issue ends (and the waiting questions go out) only once the hand-over is done.
210
209
  logIssueError(log, error, started);
211
210
  await cleanUp(context, log, state.branch);
212
211
  const report = {
@@ -2,7 +2,6 @@ import { execFile } from 'node:child_process';
2
2
  import { randomUUID } from 'node:crypto';
3
3
  import { readFileSync, statSync } from 'node:fs';
4
4
  import { link, open, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
5
- import { createConnection } from 'node:net';
6
5
  import { basename, dirname, join } from 'node:path';
7
6
  import { setTimeout as delay } from 'node:timers/promises';
8
7
  import { promisify } from 'node:util';
@@ -151,26 +150,6 @@ async function removeDeadDrafts(path) {
151
150
  }
152
151
  }
153
152
  }
154
- function takesConnection(socketPath) {
155
- return new Promise((resolve) => {
156
- const socket = createConnection(socketPath);
157
- socket.once('connect', () => {
158
- socket.destroy();
159
- resolve(true);
160
- });
161
- socket.once('error', () => resolve(false));
162
- });
163
- }
164
- export async function stopWorker(paths) {
165
- const text = await readTextOrEmpty(paths.lockPath);
166
- const pid = await holderOf(text);
167
- const unverified = text.trim().split(' ').length === 1;
168
- if (pid === undefined || (unverified && !(await takesConnection(paths.socketPath)))) {
169
- return { stopped: 'none' };
170
- }
171
- process.kill(pid, 'SIGTERM');
172
- return { stopped: 'worker', pid };
173
- }
174
153
  function textOf(path) {
175
154
  try {
176
155
  return readFileSync(path, 'utf8');
@@ -1,4 +1,3 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
1
  import { mkdir, rename, rm } from 'node:fs/promises';
3
2
  import { createServer } from 'node:http';
4
3
  import { basename, dirname, join } from 'node:path';
@@ -9,15 +8,13 @@ import { message } from '../shared/errors.mjs';
9
8
  import { lock } from '../shared/lock.mjs';
10
9
  import { startProgress } from './progress.mjs';
11
10
  import { isNewer, } from '../shared/protocol.mjs';
12
- import { listQuestions, questionSender, send, } from './questions.mjs';
13
11
  import { runRepo } from './run.mjs';
14
- import { listUpcoming, sendUpcoming } from './upcoming.mjs';
15
12
  import { packageVersion } from '../shared/version.mjs';
16
13
  import { resumeOnSuccessor } from '../shared/worker-client.mjs';
17
14
  import { keepLogTrimmed, LOG_CHECK_MS } from './worker-log.mjs';
18
15
  import { checkSocketPath, workerPaths } from '../shared/worker-paths.mjs';
19
16
  import { active, dropUpgrade, endStatus, newRun, requestRefresh, requestStop, requestUpgrade, runControls, runsMessage, setHunting, setWatching, startRefusal, stoppingMessage, stopPoint, switchRefusal, } from './worker-run.mjs';
20
- import { broadcast, closer, fileId, isLaunch, listen, parseMessage, readBody, removeOwned, reply, sendAll, shutdown, stopListening, } from './worker-server.mjs';
17
+ import { broadcast, closer, fileId, isLaunch, listen, parseMessage, readBody, removeOwned, reply, send, sendAll, shutdown, stopListening, } from './worker-server.mjs';
21
18
  const LOCK_WAIT_MS = 5_000;
22
19
  const IDLE_MS = 30_000;
23
20
  export async function startWorker(options) {
@@ -38,10 +35,6 @@ export async function startWorker(options) {
38
35
  let successor;
39
36
  const server = createServer();
40
37
  const sockets = new WebSocketServer({ server });
41
- const sendQuestions = questionSender(options.questions);
42
- // Taken outside any run, so a question read that an issue end starts does not take on
43
- // the run's stop, command log, children or default timeout.
44
- const outsideRuns = AsyncLocalStorage.snapshot();
45
38
  const busy = () => [...runs.values()].some(active);
46
39
  let idleTimer;
47
40
  const idleMs = options.idleMs ?? IDLE_MS;
@@ -120,7 +113,7 @@ export async function startWorker(options) {
120
113
  broadcast(sockets, runs);
121
114
  let summary;
122
115
  withRunChildren(run.children, () => options.runRepo(root, args, {
123
- ...runControls(run, update, () => outsideRuns(() => void sendQuestions(root, () => sockets.clients))),
116
+ ...runControls(run, update),
124
117
  print: args.watch
125
118
  ? async (pass) => sendAll(sockets, { type: 'pass', root, summary: pass })
126
119
  : undefined,
@@ -208,18 +201,10 @@ export async function startWorker(options) {
208
201
  else if (value.type === 'refresh') {
209
202
  requestRefresh(runs.get(value.root));
210
203
  }
211
- else if (value.type === 'questions') {
212
- return sendQuestions(value.root, () => [socket], value.id);
213
- }
214
- else if (value.type === 'upcoming') {
215
- return sendUpcoming(options.upcoming ?? listUpcoming, socket, value.root);
216
- }
217
- return undefined;
218
204
  };
219
205
  sockets.on('connection', (socket) => {
220
206
  send(socket, { type: 'hello', version: options.version });
221
207
  send(socket, runsMessage(runs));
222
- void sendQuestions(options.root, () => [socket]);
223
208
  socket.on('close', closeWhenIdle);
224
209
  socket.on('error', () => socket.terminate());
225
210
  socket.on('message', (data) => {
@@ -229,7 +214,7 @@ export async function startWorker(options) {
229
214
  }
230
215
  const refuse = refuser(socket, value, options.root);
231
216
  try {
232
- void receive(socket, value, refuse);
217
+ receive(socket, value, refuse);
233
218
  }
234
219
  catch (error) {
235
220
  refuse(message(error));
@@ -269,7 +254,7 @@ export async function startWorker(options) {
269
254
  const peer = { send: (data) => replies.push(JSON.parse(data)) };
270
255
  const refuse = refuser(peer, value, options.root);
271
256
  try {
272
- await receive(peer, value, refuse);
257
+ receive(peer, value, refuse);
273
258
  }
274
259
  catch (error) {
275
260
  refuse(message(error));
@@ -305,7 +290,6 @@ export async function serve(root, logCheckMs = LOG_CHECK_MS) {
305
290
  ...paths,
306
291
  version: await packageVersion(),
307
292
  runRepo,
308
- questions: listQuestions,
309
293
  });
310
294
  if (worker === undefined) {
311
295
  stopTrimming();
@@ -37,9 +37,6 @@ export function runsMessage(runs) {
37
37
  runs: Object.fromEntries([...runs].map(([root, run]) => [root, run.progress])),
38
38
  };
39
39
  }
40
- function endsIssue(record) {
41
- return record['kind'] === 'issue.end' || record['kind'] === 'issue.error';
42
- }
43
40
  export function stopPoint(after) {
44
41
  return STOP_POINTS.find((point) => point === (after ?? 'issue'));
45
42
  }
@@ -128,17 +125,12 @@ function runInterrupts(run) {
128
125
  },
129
126
  };
130
127
  }
131
- export function runControls(run, update, issueEnded) {
128
+ export function runControls(run, update) {
132
129
  return {
133
130
  interrupts: runInterrupts(run),
134
131
  hunting: run.hunting,
135
132
  watching: run.watching,
136
133
  refreshed: run.refresher.refreshed,
137
- onEvent: (record) => {
138
- update(applyEvent(run.progress, record));
139
- if (endsIssue(record)) {
140
- issueEnded();
141
- }
142
- },
134
+ onEvent: (record) => update(applyEvent(run.progress, record)),
143
135
  };
144
136
  }
@@ -1,5 +1,4 @@
1
1
  import { rmSync, statSync } from 'node:fs';
2
- import { send } from './questions.mjs';
3
2
  import { runsMessage } from './worker-run.mjs';
4
3
  function isRecord(value) {
5
4
  return typeof value === 'object' && value !== null && !Array.isArray(value);
@@ -38,6 +37,9 @@ export function parseMessage(text) {
38
37
  }
39
38
  return isClientMessage(value) ? value : undefined;
40
39
  }
40
+ export function send(socket, value) {
41
+ socket.send(JSON.stringify(value));
42
+ }
41
43
  export function broadcast(sockets, runs) {
42
44
  sendAll(sockets, runsMessage(runs));
43
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "14.4.9",
3
+ "version": "14.4.10",
4
4
  "description": "Autonomous issue harness driven by the Claude Agent SDK",
5
5
  "keywords": [
6
6
  "github",
@@ -1,45 +0,0 @@
1
- import { loadConfig } from '../shared/config.mjs';
2
- import { message } from '../shared/errors.mjs';
3
- import { detectRepo } from '../shared/git.mjs';
4
- import { waitingQuestions } from '../shared/hand-over-comments.mjs';
5
- import { PORTS } from '../shared/ports.mjs';
6
- export async function listQuestions(root) {
7
- const config = await loadConfig(root);
8
- return waitingQuestions(await detectRepo(root, config.remote), config, PORTS);
9
- }
10
- async function readQuestions(list, root) {
11
- try {
12
- return { type: 'questions', root, questions: await list(root) };
13
- }
14
- catch (error) {
15
- return { type: 'questions-error', root, message: message(error) };
16
- }
17
- }
18
- function questionsReply(delivered, socket, root, delivery, id) {
19
- const seen = delivered.get(socket) ?? new Map();
20
- const last = seen.get(root);
21
- if (last === undefined || last.read < delivery.read) {
22
- seen.set(root, delivery);
23
- delivered.set(socket, seen);
24
- return id === undefined ? delivery.value : { ...delivery.value, id };
25
- }
26
- return id === undefined ? undefined : { ...last.value, id };
27
- }
28
- export function questionSender(list) {
29
- const reads = new Map();
30
- const delivered = new WeakMap();
31
- return async (root, targets, id) => {
32
- const read = (reads.get(root) ?? 0) + 1;
33
- reads.set(root, read);
34
- const value = await readQuestions(list, root);
35
- for (const socket of targets()) {
36
- const reply = questionsReply(delivered, socket, root, { read, value }, id);
37
- if (reply !== undefined) {
38
- send(socket, reply);
39
- }
40
- }
41
- };
42
- }
43
- export function send(socket, value) {
44
- socket.send(JSON.stringify(value));
45
- }
@@ -1,39 +0,0 @@
1
- import { loadConfig } from '../shared/config.mjs';
2
- import { message } from '../shared/errors.mjs';
3
- import { detectRepo } from '../shared/git.mjs';
4
- import { PORTS } from '../shared/ports.mjs';
5
- import { send } from './questions.mjs';
6
- import { listedIssues, skipReason } from '../shared/skip.mjs';
7
- import { savedIssues } from '../shared/state.mjs';
8
- /** The fresh issues the worker would claim, oldest first as it claims them; issues with saved state resume instead. */
9
- export async function upcomingIssues(repo, config, ports) {
10
- const issues = await listedIssues(ports, repo, config, []);
11
- const saved = new Set(await savedIssues(repo));
12
- const upcoming = { claimable: [], blocked: [] };
13
- for (const issue of issues) {
14
- if (saved.has(issue.number) || skipReason(issue, config, false) !== undefined) {
15
- continue;
16
- }
17
- const blockers = await ports.openBlockers(repo, issue.number);
18
- const item = { issue: issue.number, title: issue.title };
19
- if (blockers.length > 0) {
20
- upcoming.blocked.push({ ...item, blockers });
21
- }
22
- else {
23
- upcoming.claimable.push(item);
24
- }
25
- }
26
- return upcoming;
27
- }
28
- export async function listUpcoming(root) {
29
- const config = await loadConfig(root);
30
- return upcomingIssues(await detectRepo(root, config.remote), config, PORTS);
31
- }
32
- export async function sendUpcoming(list, socket, root) {
33
- try {
34
- send(socket, { type: 'upcoming', root, ...(await list(root)) });
35
- }
36
- catch (error) {
37
- send(socket, { type: 'upcoming-error', root, message: message(error) });
38
- }
39
- }