next-issue 16.4.0 → 16.5.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.
@@ -1,7 +1,7 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { isNewer } from '../shared/protocol.mjs';
3
3
  import { packageVersion } from '../shared/version.mjs';
4
- import { CLOSED, findWorker, going } from '../shared/worker-client.mjs';
4
+ import { ANSWER_TIMEOUT_MS, CLOSED, findWorker, going, } from '../shared/worker-client.mjs';
5
5
  const FIELDS = { watch: 'watching', hunt: 'hunting' };
6
6
  const NO_RUN = 'next-issue: no run is going in this repository\n';
7
7
  function onOffText(on) {
@@ -58,14 +58,46 @@ export function stopInWorker(root) {
58
58
  if (progress.status === 'stopping' && progress.upgrade === undefined) {
59
59
  return 'next-issue: the run is stopping already\n';
60
60
  }
61
- connection.send({ type: 'stop', root, after: 'issue' });
62
- await connection.end();
63
- if (progress.upgrade !== undefined) {
64
- return 'next-issue: the run will stop after its current issues and not start again\n';
65
- }
66
- return 'next-issue: the run will stop after its current issues\n';
61
+ const reply = await stopReply(connection, root);
62
+ return `next-issue: ${stopText(progress, reply)}\n`;
67
63
  });
68
64
  }
65
+ function stopReply(connection, root) {
66
+ const id = randomUUID();
67
+ return new Promise((resolve) => {
68
+ const timer = setTimeout(() => resolve(undefined), ANSWER_TIMEOUT_MS);
69
+ connection.listen((message) => {
70
+ if (message.type === 'stopping' && message.id === id) {
71
+ clearTimeout(timer);
72
+ resolve(message);
73
+ }
74
+ });
75
+ void connection.closed.then(() => {
76
+ clearTimeout(timer);
77
+ resolve(undefined);
78
+ });
79
+ connection.send({ type: 'stop', root, after: 'issue', id });
80
+ });
81
+ }
82
+ function stopText(progress, reply) {
83
+ const upgrading = progress.upgrade !== undefined;
84
+ const ending = upgrading ? ' and not start again' : '';
85
+ if (reply === undefined) {
86
+ return `the run will stop after its current issues${ending}`;
87
+ }
88
+ const waits = progress.issues.map(({ issue }) => `#${issue}`);
89
+ if (reply.hunting) {
90
+ waits.push('its current hunt');
91
+ }
92
+ if (waits.length > 0) {
93
+ return `the run will stop after ${listText(waits)}${ending}`;
94
+ }
95
+ const state = reply.waiting ? 'the run stopped' : 'the run is stopping';
96
+ return upgrading ? `${state} and will not start again` : state;
97
+ }
98
+ function listText(items) {
99
+ return items.length === 1 ? items[0] : `${items.slice(0, -1).join(', ')} and ${items.at(-1)}`;
100
+ }
69
101
  export function statusInWorker(root) {
70
102
  return inWorker(root, async (connection, progress) => statusText(connection.version, progress));
71
103
  }
@@ -72,12 +72,13 @@ export function watchRun(args, loop, context, controls, print) {
72
72
  const { interrupts } = controls;
73
73
  let passStart = recorder.summary();
74
74
  const hunt = hunter(context);
75
+ controls.onHunter?.(() => hunt.busy());
75
76
  return watchIssues({
76
77
  ...loop,
77
78
  wait: (minutes, woken) => {
78
79
  recorder.event('watch.wait', { minutes });
79
80
  passStart = recorder.summary();
80
- return interrupts.sleep(minutesToMs(minutes), () => hunt.busy(), woken);
81
+ return interrupts.sleep(minutesToMs(minutes), woken);
81
82
  },
82
83
  passEnd: (issues) => print({ ...recorder.summary(passStart), issues }),
83
84
  hunter: hunt,
@@ -77,7 +77,7 @@ export function stoppingMessage(root, run, id) {
77
77
  type: 'stopping',
78
78
  root,
79
79
  waiting,
80
- hunting: waiting && run.huntBusy?.() === true,
80
+ hunting: run.huntBusy?.() === true,
81
81
  ...(id === undefined ? {} : { id }),
82
82
  };
83
83
  }
@@ -127,8 +127,7 @@ function runInterrupts(run) {
127
127
  return {
128
128
  afterIssue: () => run.stop !== undefined,
129
129
  afterRound: () => run.stop === 'round' || run.stop === 'now',
130
- sleep: (ms, hunting, woken) => {
131
- run.huntBusy = hunting;
130
+ sleep: (ms, woken) => {
132
131
  return wakeableSleep(run, ms, run.stop !== undefined, woken);
133
132
  },
134
133
  };
@@ -139,5 +138,8 @@ export function runControls(run, update) {
139
138
  hunting: run.hunting,
140
139
  watching: run.watching,
141
140
  onEvent: (record) => update(applyEvent(run.progress, record)),
141
+ onHunter: (busy) => {
142
+ run.huntBusy = busy;
143
+ },
142
144
  };
143
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "16.4.0",
3
+ "version": "16.5.0",
4
4
  "description": "Autonomous issue harness driven by the Claude Agent SDK",
5
5
  "keywords": [
6
6
  "github",