next-issue 6.6.124 → 6.7.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
@@ -190,7 +190,9 @@ the run handles one issue. For each issue:
190
190
  file as closing, sets `status:done` and closes the issue. When a run
191
191
  stops or dies before the close, the next run sees the mark, sets
192
192
  `status:done` and closes the issue, with no new push, revert or
193
- hand-over. When a run stops or dies after the close, before the state
193
+ hand-over. A hand-over clears the mark, so an issue taken back after
194
+ a failed label edit or close is resumed, not closed, by later runs.
195
+ When a run stops or dies after the close, before the state
194
196
  file goes away, the next run finds the closed issue through its state
195
197
  file and removes the worktree, the local branches and the state file,
196
198
  with no new push, revert, label, close or hand-over. A label or close
@@ -770,6 +772,8 @@ With `--hunt`, which turns on `--watch`, the harness runs a hunter agent at the
770
772
 
771
773
  With `huntCap` at 1 and no ready issue, a hunt files at most one issue. The hunter ends its reply with one `issue:` line for each issue it filed, or one `issue: none` line; a url that is not an issue of the repository of `remote` does not count as filed. When the `remote` url holds an old owner or name that GitHub redirects after a rename or transfer, the harness asks GitHub for the new one, so an issue url with the new name counts too. The run log holds one `hunt.issue` event with the `url` for each, or one with `none`. A hunt that fails writes a `hunt.error` event and the watch goes on. The hunter then waits before the next hunt, with a `hunt.wait` event and the same back-off, so a failure, or a hunt that files nothing, that repeats waits 1, 2, 3, 5, 10, then 10 minutes, and the back-off goes back to 1 minute after a hunt that files at least one issue. The next pass claims the new issues like any other. At the first `Ctrl-C` the hunter stops after its current hunt, and the watch ends once the hunt and the running issues end. A first `Ctrl-C` during the watch wait tells you so while a hunt runs, and the third press stops the hunter at once. The hunter stops too when the watch ends for another reason.
772
774
 
775
+ In a run of the `serve` worker, a client can switch hunting on or off while the run goes on, with no restart, for example with `/next-issue hunt on` in the pi extension, see [Worker](#worker). This works only for runs of the worker, not for a command-line run.
776
+
773
777
  ## Worker
774
778
 
775
779
  `next-issue serve` runs one worker for the repository it is run in. The
@@ -797,7 +801,7 @@ affect another. The worker:
797
801
  with `another worker is running`. A worker that stops removes the lock file
798
802
  only while it still holds the lock, and the socket file only while it is
799
803
  still the socket it bound;
800
- - refuses a `start`, `stop` or `questions` message whose `root` is not
804
+ - refuses a `start`, `stop`, `hunt` or `questions` message whose `root` is not
801
805
  the exact path of its repository with an `error` message, and starts or
802
806
  stops nothing;
803
807
  - runs at most one run at a time. A client starts it with
@@ -836,6 +840,19 @@ affect another. The worker:
836
840
  issue ends as `stopped` with its state and labels kept; the worker keeps
837
841
  running. A later point than one already asked for changes nothing, and an
838
842
  earlier one replaces it. An unknown `after` gets an `error` message;
843
+ - switches hunting of a run on or off when a client sends
844
+ `{ "type": "hunt", "root": "<path>", "on": true | false }`. The run keeps its
845
+ issues, worktrees and progress, and nothing restarts. Every watching run has
846
+ a hunter: a run started with `--hunt` starts with hunting on, and one
847
+ started with `--watch` alone starts with it off. Off lets a hunt that is
848
+ going finish, so the issues it files stay, and starts no new hunt. On wakes
849
+ the hunter at once, with no back-off wait. A run that does not watch
850
+ (`--once`, or `--max` without `--watch`) refuses on with an `error` message
851
+ that says why, and goes on unchanged. With no run going, the message gets
852
+ an `error` and starts nothing. The setting lasts for the run only: a new run
853
+ takes it from its own flags. Only runs of the worker can switch; a
854
+ command-line run keeps what `--hunt` gave it. The progress of each run
855
+ carries `hunting`, `true` while hunting is on;
839
856
  - exits, and removes its socket and lock files, when no run is going and no
840
857
  client is connected, or when no client connects in the 30 seconds after it
841
858
  starts;
package/dist/handover.mjs CHANGED
@@ -144,6 +144,8 @@ async function handOver(context, log, issue, state, reason, earlier) {
144
144
  const { repo, ports, config } = context;
145
145
  log.event('hand-over', { reason }, 'quiet');
146
146
  const { pendingHandOver: _pending, ...rest } = state;
147
+ // Once the label is on, the issue is taken back from a close (`finishDone`) it may have reached.
148
+ const { closing: _closing, ...taken } = rest;
147
149
  let pending = earlier;
148
150
  try {
149
151
  // A retry keeps the thread time and the labelled mark of its earlier try.
@@ -152,13 +154,13 @@ async function handOver(context, log, issue, state, reason, earlier) {
152
154
  await writeState(repo, { ...rest, pendingHandOver: pending });
153
155
  await setStatus(context, issue, config.labels.needsHuman);
154
156
  pending = { ...pending, labelled: true };
155
- await writeState(repo, { ...rest, pendingHandOver: pending });
157
+ await writeState(repo, { ...taken, pendingHandOver: pending });
156
158
  await ports.commentOnIssue(repo, issue, handOverComment(reason));
157
159
  }
158
160
  catch (error) {
159
161
  throw new HandOverFailed(reason, error, pending);
160
162
  }
161
- await writeState(repo, { ...rest, handedOver: true });
163
+ await writeState(repo, { ...taken, handedOver: true });
162
164
  }
163
165
  class HandOverFailed extends Error {
164
166
  reason;
@@ -0,0 +1,16 @@
1
+ export function huntSwitch(initial) {
2
+ let on = initial;
3
+ let controller = new AbortController();
4
+ return {
5
+ on: () => on,
6
+ changed: () => controller.signal,
7
+ set: (next) => {
8
+ if (next === on) {
9
+ return;
10
+ }
11
+ on = next;
12
+ controller.abort();
13
+ controller = new AbortController();
14
+ },
15
+ };
16
+ }
package/dist/pipeline.mjs CHANGED
@@ -21,7 +21,9 @@ export async function processIssue(context, issue, claimed = () => undefined) {
21
21
  catch (error) {
22
22
  return unclaimedError(log, issue, error, started);
23
23
  }
24
- const closing = saved?.closing === true && saved.handedOver !== true;
24
+ const handedOver = wasHandedOver(context, issue, saved);
25
+ // A hand-over takes a closing issue back: its resume may revert or add to the change.
26
+ const closing = saved?.closing === true && !handedOver;
25
27
  if (issue.closed === true && !closing) {
26
28
  return dropClosed(context, log, issue, saved?.branch ?? branchName(issue.number));
27
29
  }
@@ -31,7 +33,6 @@ export async function processIssue(context, issue, claimed = () => undefined) {
31
33
  }
32
34
  claimed();
33
35
  log.event('issue.start', { title: issue.title, createdAt: issue.createdAt }, 'quiet');
34
- const handedOver = wasHandedOver(context, issue, saved);
35
36
  const state = startState(context, issue, saved, handedOver);
36
37
  let report;
37
38
  try {
package/dist/progress.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { truncate } from './text.mjs';
2
2
  const TOOL_LINE_MAX = 80;
3
3
  const NOT_STAGES = new Set(['issue.start', 'agent.start', 'run.start']);
4
- export function startProgress() {
5
- return { status: 'running', issues: [], handled: [] };
4
+ export function startProgress(hunting = false) {
5
+ return { status: 'running', hunting, issues: [], handled: [] };
6
6
  }
7
7
  function toolLine(record) {
8
8
  const tool = String(record['tool']);
package/dist/run.mjs CHANGED
@@ -11,6 +11,7 @@ import { detectRepo } from './git.mjs';
11
11
  import { checkGitVersion } from './git-version.mjs';
12
12
  import { defaultBranch } from './github.mjs';
13
13
  import { hunter } from './hunt.mjs';
14
+ import { huntSwitch } from './hunt-switch.mjs';
14
15
  import { lock, lockHolder } from './lock.mjs';
15
16
  import { exitCode, runIssues } from './loop.mjs';
16
17
  import { Recorder } from './observe.mjs';
@@ -69,7 +70,7 @@ async function handle(args, config, repo, recorder, controls) {
69
70
  };
70
71
  const print = controls.print ?? (async () => undefined);
71
72
  const { reports, stoppedAt, error } = args.watch
72
- ? await watchRun(args, loop, context, interrupts, print)
73
+ ? await watchRun(args, loop, context, controls, print)
73
74
  : await runIssues(args, loop);
74
75
  recordLoopEnd(recorder, stoppedAt, error);
75
76
  const summary = await endRun(recorder, reports);
@@ -78,19 +79,21 @@ async function handle(args, config, repo, recorder, controls) {
78
79
  }
79
80
  return error === undefined ? exitCode(reports) : 1;
80
81
  }
81
- function watchRun(args, loop, context, interrupts, print) {
82
+ export function watchRun(args, loop, context, controls, print) {
82
83
  const { recorder } = context;
84
+ const { interrupts } = controls;
83
85
  let passStart = recorder.summary();
84
- const hunting = args.hunt ? hunter(context) : undefined;
86
+ const hunt = hunter(context);
85
87
  return watchIssues(args, {
86
88
  ...loop,
87
89
  wait: (minutes) => {
88
90
  recorder.event('watch.wait', { minutes }, 'quiet');
89
91
  passStart = recorder.summary();
90
- return interrupts.sleep(minutesToMs(minutes), () => hunting?.busy() === true);
92
+ return interrupts.sleep(minutesToMs(minutes), () => hunt.busy());
91
93
  },
92
94
  passEnd: (issues) => print({ ...recorder.summary(passStart), issues }),
93
- ...(hunting === undefined ? {} : { hunter: hunting }),
95
+ hunter: hunt,
96
+ hunting: controls.hunting ?? huntSwitch(args.hunt),
94
97
  });
95
98
  }
96
99
  function recordLoopEnd(recorder, stoppedAt, error) {
package/dist/serve.mjs CHANGED
@@ -14,7 +14,7 @@ import { runRepo } from './run.mjs';
14
14
  import { packageVersion } from './version.mjs';
15
15
  import { keepLogTrimmed, LOG_CHECK_MS } from './worker-log.mjs';
16
16
  import { checkSocketPath, workerPaths } from './worker-paths.mjs';
17
- import { active, endStatus, newRun, requestStop, runControls, runsMessage, startRefusal, stopPoint, } from './worker-run.mjs';
17
+ import { active, endStatus, huntRefusal, newRun, requestStop, runControls, runsMessage, setHunting, startRefusal, stopPoint, } from './worker-run.mjs';
18
18
  import { broadcast, closer, fileId, listen, parseMessage, removeOwned, shutdown, } from './worker-server.mjs';
19
19
  const LOCK_WAIT_MS = 5_000;
20
20
  const IDLE_MS = 30_000;
@@ -64,7 +64,7 @@ export async function startWorker(options) {
64
64
  send(socket, { type: 'error', root, message: message(error) });
65
65
  return;
66
66
  }
67
- const run = newRun(startProgress());
67
+ const run = newRun(startProgress(args.hunt), args.watch);
68
68
  runs.set(root, run);
69
69
  const update = (next) => {
70
70
  run.progress = next;
@@ -84,6 +84,16 @@ export async function startWorker(options) {
84
84
  broadcast(sockets, runs);
85
85
  }
86
86
  };
87
+ const hunt = (socket, root, on) => {
88
+ const run = runs.get(root);
89
+ const refusal = huntRefusal(run, on);
90
+ if (refusal !== undefined) {
91
+ send(socket, { type: 'error', root, message: refusal });
92
+ return;
93
+ }
94
+ setHunting(run, on);
95
+ broadcast(sockets, runs);
96
+ };
87
97
  const receive = (socket, value) => {
88
98
  if (value.type === 'hello') {
89
99
  if (isNewer(value.version, options.version)) {
@@ -104,6 +114,9 @@ export async function startWorker(options) {
104
114
  else if (value.type === 'stop') {
105
115
  stop(socket, value.root, value.after);
106
116
  }
117
+ else if (value.type === 'hunt') {
118
+ hunt(socket, value.root, value.on);
119
+ }
107
120
  else if (value.type === 'questions') {
108
121
  void sendQuestions(value.root, () => [socket], value.id);
109
122
  }
package/dist/state.mjs CHANGED
@@ -85,11 +85,15 @@ export async function savedIssues(repo) {
85
85
  export function newState(issue, branch) {
86
86
  return { issue, phase: 'claimed', branch, ciFixes: 0, reviewRounds: 0, reviewLog: [] };
87
87
  }
88
- /** Drops the budgets and findings; a hand-over (`handedOver`) also cancels an approval. */
88
+ /**
89
+ * Drops the budgets and findings; a hand-over (`handedOver`) also cancels an approval and the closing mark,
90
+ * so a resume that stops before it finishes is resumed again rather than closed as done.
91
+ */
89
92
  export function resetState(state, handedOver = false) {
90
- const { handedOver: _handedOver, pendingHandOver: _pending, ...rest } = state;
93
+ const { handedOver: _handedOver, pendingHandOver: _pending, closing, ...rest } = state;
91
94
  const phase = handedOver && rest.phase === 'approved' ? 'review' : rest.phase;
92
- return { ...rest, phase, ciFixes: 0, commitFixes: 0, reviewRounds: 0, reviewLog: [] };
95
+ const kept = !handedOver && closing !== undefined ? { closing } : {};
96
+ return { ...rest, ...kept, phase, ciFixes: 0, commitFixes: 0, reviewRounds: 0, reviewLog: [] };
93
97
  }
94
98
  export async function writeState(repo, state) {
95
99
  await mkdir(stateDir(repo.root), { recursive: true });
package/dist/watch.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { huntSwitch } from './hunt-switch.mjs';
1
2
  import { handled, runIssues } from './loop.mjs';
2
3
  const BACK_OFF_MINUTES = [1, 2, 3, 5, 10];
3
4
  export async function watchIssues(args, watch) {
@@ -7,7 +8,7 @@ export async function watchIssues(args, watch) {
7
8
  const claims = claimAlarm();
8
9
  const hunting = watch.hunter === undefined
9
10
  ? undefined
10
- : huntIssues(watch.hunter, running, failed, claims, () => ended.signal.aborted || watch.stop(), ended.signal);
11
+ : huntIssues(watch.hunter, watch.hunting ?? huntSwitch(true), running, failed, claims, () => ended.signal.aborted || watch.stop(), ended.signal);
11
12
  try {
12
13
  return await watchPasses(args, failed, {
13
14
  ...watch,
@@ -46,26 +47,45 @@ function claimAlarm() {
46
47
  },
47
48
  };
48
49
  }
49
- async function huntIssues(hunter, running, failed, claims, stopped, signal) {
50
+ function aborted(signal) {
51
+ return new Promise((resolve) => {
52
+ if (signal.aborted) {
53
+ resolve();
54
+ }
55
+ else {
56
+ signal.addEventListener('abort', () => resolve(), { once: true });
57
+ }
58
+ });
59
+ }
60
+ async function huntIssues(hunter, hunting, running, failed, claims, stopped, signal) {
50
61
  let step = 0;
51
62
  while (!stopped()) {
63
+ if (!hunting.on()) {
64
+ await aborted(AbortSignal.any([signal, hunting.changed()]));
65
+ step = 0;
66
+ continue;
67
+ }
52
68
  const ready = await hunter.ready(running, failed).catch(() => undefined);
53
69
  if (stopped()) {
54
70
  return;
55
71
  }
56
72
  claims.take();
57
73
  const waiting = ready?.filter((issue) => !running.has(issue.number)).length;
58
- if (waiting !== undefined && waiting < hunter.cap) {
74
+ if (waiting !== undefined && waiting < hunter.cap && hunting.on()) {
59
75
  if (await hunter.hunt(hunter.cap - waiting)) {
60
76
  step = 0;
61
77
  continue;
62
78
  }
63
79
  }
64
- if (claims.take() || stopped()) {
80
+ if (claims.take() || stopped() || !hunting.on()) {
65
81
  continue;
66
82
  }
67
- await hunter.wait(backOffMinutes(step), AbortSignal.any([signal, claims.signal()]));
68
- if (!claims.take()) {
83
+ const changed = hunting.changed();
84
+ await hunter.wait(backOffMinutes(step), AbortSignal.any([signal, claims.signal(), changed]));
85
+ if (changed.aborted) {
86
+ step = 0;
87
+ }
88
+ else if (!claims.take()) {
69
89
  step += 1;
70
90
  }
71
91
  }
@@ -1,9 +1,10 @@
1
1
  import { runChildren, stopRunChildren } from './children.mjs';
2
2
  import { wakeableSleep } from './durations.mjs';
3
+ import { huntSwitch } from './hunt-switch.mjs';
3
4
  import { applyEvent } from './progress.mjs';
4
5
  import { STOP_POINTS } from './protocol.mjs';
5
- export function newRun(progress) {
6
- return { progress, children: runChildren() };
6
+ export function newRun(progress, watching = false) {
7
+ return { progress, children: runChildren(), watching, hunting: huntSwitch(progress.hunting) };
7
8
  }
8
9
  export function active(run) {
9
10
  return run?.progress.status === 'running' || run?.progress.status === 'stopping';
@@ -50,6 +51,19 @@ export function requestStop(run, after) {
50
51
  run.progress = { ...run.progress, status: 'stopping' };
51
52
  return true;
52
53
  }
54
+ export function huntRefusal(run, on) {
55
+ if (run === undefined || !active(run)) {
56
+ return 'no run is going in this repository';
57
+ }
58
+ if (on && !run.watching) {
59
+ return 'the run does not watch for issues, so it cannot hunt: start a run with --watch or --hunt';
60
+ }
61
+ return undefined;
62
+ }
63
+ export function setHunting(run, on) {
64
+ run.hunting.set(on);
65
+ run.progress = { ...run.progress, hunting: on };
66
+ }
53
67
  function runInterrupts(run) {
54
68
  return {
55
69
  afterIssue: () => run.stop !== undefined,
@@ -60,6 +74,7 @@ function runInterrupts(run) {
60
74
  export function runControls(run, update, issueEnded) {
61
75
  return {
62
76
  interrupts: runInterrupts(run),
77
+ hunting: run.hunting,
63
78
  onEvent: (record) => {
64
79
  update(applyEvent(run.progress, record));
65
80
  if (endsIssue(record)) {
@@ -17,6 +17,9 @@ function isClientMessage(value) {
17
17
  if (typeof value['root'] !== 'string') {
18
18
  return false;
19
19
  }
20
+ if (value['type'] === 'hunt') {
21
+ return typeof value['on'] === 'boolean';
22
+ }
20
23
  if (value['type'] === 'questions') {
21
24
  return value['id'] === undefined || typeof value['id'] === 'string';
22
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.6.124",
3
+ "version": "6.7.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",