next-issue 5.5.0 → 5.6.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
@@ -325,6 +325,7 @@ because no pull request is opened.
325
325
  "remote": "origin",
326
326
  "issueLimit": 100,
327
327
  "concurrency": 1,
328
+ "huntCap": 1,
328
329
  "maxCiFixes": 5,
329
330
  "maxCommitFixes": 10,
330
331
  "maxReviewRounds": 5,
@@ -358,6 +359,7 @@ because no pull request is opened.
358
359
  | `remote` | `origin` | The git remote for the repository and the branches |
359
360
  | `issueLimit` | `100` | The maximum number of open issues to read. With `labels.ready` set, only issues with the ready, in-progress or in-review label count |
360
361
  | `concurrency` | `1` | The most issues that a run handles at the same time |
362
+ | `huntCap` | `1` | With `--hunt`, the hunter hunts only while fewer ready issues than this wait besides the running ones |
361
363
  | `maxCiFixes` | `5` | The budget for check fixes per issue |
362
364
  | `maxCommitFixes` | `10` | The budget for fixes of a commit that a git hook stopped, per issue |
363
365
  | `maxReviewRounds` | `5` | The budget for review rounds per issue |
@@ -443,22 +445,22 @@ state of an issue that a label still holds back stays as it was.
443
445
 
444
446
  ## Commands and options
445
447
 
446
- | Argument | Effect |
447
- | ----------- | ------------------------------------------------------------------------------------------ |
448
- | `init` | Write the config file with the defaults |
449
- | `serve` | Run the worker of this repository that pi extensions talk to, see [Worker](#worker) |
450
- | `stop` | Stop the worker of this repository, see [Worker](#worker) |
451
- | `logs` | Show the latest run log and follow it, see [Observability](#observability) |
452
- | `--force` | Replace an existing config file, with `init` |
453
- | `--once` | Stop after the first handled issue |
454
- | `--max <n>` | Handle at most n issues |
455
- | `--watch` | Keep running, and read the open issues again after each pass |
456
- | `--hunt` | Hunt the repository for a bug when the issues run out, see [Hunt for bugs](#hunt-for-bugs) |
457
- | `--reset` | Drop the saved budgets and findings, and keep the rest of the state |
458
- | `--json` | Print the machine summary instead of the text one, or the raw JSON lines with `logs` |
459
- | `--verbose` | Show every command and all agent output |
460
- | `--quiet` | Show only the milestones and the summary |
461
- | `--help` | Show the option list |
448
+ | Argument | Effect |
449
+ | ----------- | -------------------------------------------------------------------------------------- |
450
+ | `init` | Write the config file with the defaults |
451
+ | `serve` | Run the worker of this repository that pi extensions talk to, see [Worker](#worker) |
452
+ | `stop` | Stop the worker of this repository, see [Worker](#worker) |
453
+ | `logs` | Show the latest run log and follow it, see [Observability](#observability) |
454
+ | `--force` | Replace an existing config file, with `init` |
455
+ | `--once` | Stop after the first handled issue |
456
+ | `--max <n>` | Handle at most n issues |
457
+ | `--watch` | Keep running, and read the open issues again after each pass |
458
+ | `--hunt` | Hunt the repository for bugs alongside the issues, see [Hunt for bugs](#hunt-for-bugs) |
459
+ | `--reset` | Drop the saved budgets and findings, and keep the rest of the state |
460
+ | `--json` | Print the machine summary instead of the text one, or the raw JSON lines with `logs` |
461
+ | `--verbose` | Show every command and all agent output |
462
+ | `--quiet` | Show only the milestones and the summary |
463
+ | `--help` | Show the option list |
462
464
 
463
465
  The exit code is 1 when an issue needs a person or failed, and 0 when it does
464
466
  not, so a cron job or a CI step can read the result of the run.
@@ -493,14 +495,14 @@ The watch stops:
493
495
 
494
496
  ## Hunt for bugs
495
497
 
496
- With `--hunt`, which turns on `--watch`, the harness runs a hunter agent once when the issues run out, before the wait. It hunts again only after a pass that handled an issue, so an idle watch does not start a hunter before each wait. The hunter:
498
+ With `--hunt`, which turns on `--watch`, the harness runs a hunter agent at the same time as the issues. Before each hunt it reads the open issues with the `labels.ready` label and counts those that are ready to claim, have no open blocker and are not running. It hunts only while that count is less than `huntCap`, 1 by default. Otherwise it waits and checks again, with the same back-off as the watch: 1, 2, 3, 5, 10, then 10 minutes, back to 1 minute after a hunt. Each wait writes a `hunt.wait` event with the `minutes` to the run log. A hunt that files nothing does not stop the next one. The hunter:
497
499
 
498
500
  - works in its own worktree at `.worktrees/hunt`, at the remote base branch, which the harness fetches and resets before each hunt;
499
501
  - follows `next-issue.hunt.md` in the repository root, or a short built-in prompt when the file is missing;
500
502
  - files one issue, for its most serious finding, with the `labels.ready` label and the sections of the [issue format](#issue-format), after a search for duplicates. It files nothing when it finds no real problem or a duplicate exists;
501
503
  - runs no test suite and changes no file. It gets the tools of the reviewer.
502
504
 
503
- The hunter ends its reply with an `issue:` line, and the run log holds it as a `hunt.issue` event with the `url`, or `none`. A hunt that fails writes a `hunt.error` event and the watch goes on. The next pass claims the new issue like any other. The hunter does not run alongside the issues.
505
+ The hunter ends its reply with an `issue:` line, and the run log holds it as a `hunt.issue` event with the `url`, or `none`. A hunt that fails writes a `hunt.error` event and the watch goes on. The next pass claims the new issue 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.
504
506
 
505
507
  ## Worker
506
508
 
package/dist/args.mjs CHANGED
@@ -22,7 +22,7 @@ export const USAGE = `next-issue [command] [options]
22
22
  --once stop after the first handled issue
23
23
  --max <n> handle at most n issues
24
24
  --watch keep running and read the issues again after each pass
25
- --hunt hunt the repository for a bug and file an issue when the issues run out, turns on --watch
25
+ --hunt hunt the repository for bugs and file issues alongside the issues, turns on --watch
26
26
  --reset drop the saved budgets and findings first
27
27
  --json print the machine summary instead of the text one, or raw lines with logs
28
28
  --force replace an existing config file, with init
package/dist/config.mjs CHANGED
@@ -6,6 +6,7 @@ const DEFAULTS = {
6
6
  remote: 'origin',
7
7
  issueLimit: 100,
8
8
  concurrency: 1,
9
+ huntCap: 1,
9
10
  maxCiFixes: 5,
10
11
  maxCommitFixes: 10,
11
12
  maxReviewRounds: 5,
@@ -35,6 +36,7 @@ const FIELDS = [...Object.keys(DEFAULTS), 'setupCommand'];
35
36
  const WHOLE_FIELDS = [
36
37
  ['issueLimit', 1],
37
38
  ['concurrency', 1],
39
+ ['huntCap', 1],
38
40
  ['maxCiFixes', 0],
39
41
  ['maxCommitFixes', 0],
40
42
  ['maxReviewRounds', 1],
package/dist/hunt.mjs CHANGED
@@ -1,11 +1,13 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { setTimeout as delay } from 'node:timers/promises';
3
4
  import { REVIEWING } from './agents.mjs';
4
5
  import { minutesToMs } from './durations.mjs';
5
6
  import { readTextIfPresent } from './files.mjs';
6
7
  import { git, remoteRef, resetHard } from './git.mjs';
7
8
  import { oneAtATime } from './lock.mjs';
8
9
  import { huntPrompt } from './prompts.mjs';
10
+ import { skipReason } from './skip.mjs';
9
11
  import { WORKTREE_DIR } from './worktree.mjs';
10
12
  export const HUNT_FILE = 'next-issue.hunt.md';
11
13
  const FILED = /^issue:\s*(\S+)\s*$/m;
@@ -37,3 +39,31 @@ export async function hunt(context) {
37
39
  recorder.event('hunt.issue', { url: FILED.exec(result.text)?.[1] ?? 'none' }, 'quiet');
38
40
  });
39
41
  }
42
+ export function hunter(context) {
43
+ const { repo, config, recorder, ports } = context;
44
+ const { ready } = config.labels;
45
+ const labels = ready.length === 0 ? [] : [ready];
46
+ let hunting = false;
47
+ return {
48
+ cap: config.huntCap,
49
+ ready: async () => {
50
+ const open = (await ports.openIssues(repo, config.issueLimit, labels)).filter((issue) => skipReason(issue, config, false) === undefined);
51
+ const blockers = await Promise.all(open.map((issue) => ports.openBlockers(repo, issue.number)));
52
+ return open.filter((_issue, index) => blockers[index].length === 0);
53
+ },
54
+ hunt: async () => {
55
+ hunting = true;
56
+ try {
57
+ await hunt(context).catch(() => undefined);
58
+ }
59
+ finally {
60
+ hunting = false;
61
+ }
62
+ },
63
+ wait: (minutes, signal) => {
64
+ recorder.event('hunt.wait', { minutes });
65
+ return delay(minutesToMs(minutes), undefined, { signal }).catch(() => undefined);
66
+ },
67
+ busy: () => hunting,
68
+ };
69
+ }
@@ -3,10 +3,13 @@ import { wakeableSleep } from './durations.mjs';
3
3
  export function listenForInterrupts(say) {
4
4
  let presses = 0;
5
5
  const sleeper = {};
6
+ let hunting = () => false;
6
7
  const press = () => {
7
8
  presses += 1;
8
9
  if (presses === 1 && sleeper.wake !== undefined) {
9
- say('Stopping now.');
10
+ say(hunting()
11
+ ? 'Stopping after the current hunt. Press Ctrl-C twice more to stop now.'
12
+ : 'Stopping now.');
10
13
  sleeper.wake();
11
14
  }
12
15
  else if (presses === 1) {
@@ -24,6 +27,9 @@ export function listenForInterrupts(say) {
24
27
  return {
25
28
  afterIssue: () => presses >= 1,
26
29
  afterRound: () => presses >= 2,
27
- sleep: (ms) => wakeableSleep(sleeper, ms, presses >= 1),
30
+ sleep: (ms, busy = () => false) => {
31
+ hunting = busy;
32
+ return wakeableSleep(sleeper, ms, presses >= 1);
33
+ },
28
34
  };
29
35
  }
package/dist/run.mjs CHANGED
@@ -7,7 +7,7 @@ import { writeJson } from './files.mjs';
7
7
  import { slug } from './gh.mjs';
8
8
  import { detectRepo } from './git.mjs';
9
9
  import { defaultBranch } from './github.mjs';
10
- import { hunt } from './hunt.mjs';
10
+ import { hunter } from './hunt.mjs';
11
11
  import { exitCode, runIssues } from './loop.mjs';
12
12
  import { Recorder } from './observe.mjs';
13
13
  import { pendingIssues } from './pending.mjs';
@@ -58,15 +58,16 @@ async function handle(args, config, repo, recorder, controls) {
58
58
  function watchRun(args, loop, context, interrupts, print) {
59
59
  const { recorder } = context;
60
60
  let passStart = recorder.summary();
61
+ const hunting = args.hunt ? hunter(context) : undefined;
61
62
  return watchIssues(args, {
62
63
  ...loop,
63
64
  wait: (minutes) => {
64
65
  recorder.event('watch.wait', { minutes }, 'quiet');
65
66
  passStart = recorder.summary();
66
- return interrupts.sleep(minutesToMs(minutes));
67
+ return interrupts.sleep(minutesToMs(minutes), () => hunting?.busy() === true);
67
68
  },
68
69
  passEnd: (issues) => print({ ...recorder.summary(passStart), issues }),
69
- ...(args.hunt ? { hunt: () => hunt(context).catch(() => undefined) } : {}),
70
+ ...(hunting === undefined ? {} : { hunter: hunting }),
70
71
  });
71
72
  }
72
73
  function recordLoopEnd(recorder, stoppedAt, error) {
package/dist/watch.mjs CHANGED
@@ -1,11 +1,49 @@
1
1
  import { handled, runIssues } from './loop.mjs';
2
2
  const BACK_OFF_MINUTES = [1, 2, 3, 5, 10];
3
3
  export async function watchIssues(args, watch) {
4
+ const running = new Set();
5
+ const ended = new AbortController();
6
+ const hunting = watch.hunter === undefined
7
+ ? undefined
8
+ : huntIssues(watch.hunter, running, () => ended.signal.aborted || watch.stop(), ended.signal);
9
+ try {
10
+ return await watchPasses(args, {
11
+ ...watch,
12
+ process: async (issue) => {
13
+ running.add(issue.number);
14
+ try {
15
+ return await watch.process(issue);
16
+ }
17
+ finally {
18
+ running.delete(issue.number);
19
+ }
20
+ },
21
+ });
22
+ }
23
+ finally {
24
+ ended.abort();
25
+ await hunting;
26
+ }
27
+ }
28
+ async function huntIssues(hunter, running, stopped, signal) {
29
+ let step = 0;
30
+ while (!stopped()) {
31
+ const ready = await hunter.ready().catch(() => undefined);
32
+ const waiting = ready?.filter((issue) => !running.has(issue.number)).length;
33
+ if (waiting !== undefined && waiting < hunter.cap) {
34
+ step = 0;
35
+ await hunter.hunt();
36
+ continue;
37
+ }
38
+ await hunter.wait(backOffMinutes(step), signal);
39
+ step += 1;
40
+ }
41
+ }
42
+ async function watchPasses(args, watch) {
4
43
  const limit = args.once ? 1 : args.max;
5
44
  const reports = [];
6
45
  const failed = new Set();
7
46
  let step = 0;
8
- let hunting = true;
9
47
  for (;;) {
10
48
  const pass = await runIssues({ once: false, max: limit === undefined ? undefined : limit - handled(reports) }, watch, new Set(failed));
11
49
  reports.push(...pass.reports);
@@ -13,7 +51,6 @@ export async function watchIssues(args, watch) {
13
51
  if (handled(pass.reports) > 0) {
14
52
  await watch.passEnd(pass.reports);
15
53
  step = 0;
16
- hunting = true;
17
54
  }
18
55
  if (pass.error !== undefined || pass.stoppedAt !== undefined) {
19
56
  return { ...pass, reports };
@@ -21,10 +58,6 @@ export async function watchIssues(args, watch) {
21
58
  if ((limit !== undefined && handled(reports) >= limit) || watch.stop()) {
22
59
  return { reports };
23
60
  }
24
- if (hunting) {
25
- hunting = false;
26
- await watch.hunt?.();
27
- }
28
61
  const minutes = backOffMinutes(step);
29
62
  step += 1;
30
63
  if (!(await watch.wait(minutes))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "5.5.0",
3
+ "version": "5.6.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",