next-issue 5.4.0 → 5.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.
package/README.md CHANGED
@@ -259,7 +259,7 @@ get the full summary object there instead, so the harness fits in a pipe. All
259
259
  progress goes to standard error.
260
260
 
261
261
  Recorded for each step: `claim`, `comments`, `reply`, `worktree`, `setup`,
262
- `implement`, `review`, `fix`, `commit-fix`, `rebase`, `land`, `main-checks` and `revert`, each with a
262
+ `implement`, `review`, `fix`, `commit-fix`, `rebase`, `land`, `main-checks`, `revert` and `hunt`, each with a
263
263
  `.start`, `.end` or `.error` event and a duration in `ms`. Every `git` and `gh`
264
264
  command is recorded with its exit code and duration. A `tool` event holds the
265
265
  tool name, and for a `bash` tool the command too. Each agent call adds a `usage`
@@ -443,21 +443,22 @@ state of an issue that a label still holds back stays as it was.
443
443
 
444
444
  ## Commands and options
445
445
 
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
- | `--reset` | Drop the saved budgets and findings, and keep the rest of the state |
457
- | `--json` | Print the machine summary instead of the text one, or the raw JSON lines with `logs` |
458
- | `--verbose` | Show every command and all agent output |
459
- | `--quiet` | Show only the milestones and the summary |
460
- | `--help` | Show the option list |
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 |
461
462
 
462
463
  The exit code is 1 when an issue needs a person or failed, and 0 when it does
463
464
  not, so a cron job or a CI step can read the result of the run.
@@ -490,6 +491,17 @@ The watch stops:
490
491
  branch failed;
491
492
  - when the open issues cannot be read.
492
493
 
494
+ ## Hunt for bugs
495
+
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:
497
+
498
+ - works in its own worktree at `.worktrees/hunt`, at the remote base branch, which the harness fetches and resets before each hunt;
499
+ - follows `next-issue.hunt.md` in the repository root, or a short built-in prompt when the file is missing;
500
+ - 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
+ - runs no test suite and changes no file. It gets the tools of the reviewer.
502
+
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.
504
+
493
505
  ## Worker
494
506
 
495
507
  `next-issue serve` runs one worker for the repository it is run in. The
package/dist/args.mjs CHANGED
@@ -4,6 +4,7 @@ const SWITCHES = new Map([
4
4
  ['--json', 'json'],
5
5
  ['--help', 'help'],
6
6
  ['--watch', 'watch'],
7
+ ['--hunt', 'hunt'],
7
8
  ['--reset', 'reset'],
8
9
  ['--once', 'once'],
9
10
  ]);
@@ -21,6 +22,7 @@ export const USAGE = `next-issue [command] [options]
21
22
  --once stop after the first handled issue
22
23
  --max <n> handle at most n issues
23
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
24
26
  --reset drop the saved budgets and findings first
25
27
  --json print the machine summary instead of the text one, or raw lines with logs
26
28
  --force replace an existing config file, with init
@@ -37,6 +39,7 @@ export function parseArgs(argv) {
37
39
  reset: false,
38
40
  force: false,
39
41
  watch: false,
42
+ hunt: false,
40
43
  level: 'normal',
41
44
  };
42
45
  for (let index = 0; index < argv.length; index += 1) {
@@ -57,6 +60,7 @@ export function parseArgs(argv) {
57
60
  throw new Error(`Unknown argument: ${arg}`);
58
61
  }
59
62
  }
63
+ args.watch ||= args.hunt;
60
64
  return args;
61
65
  }
62
66
  function command(arg) {
package/dist/hunt.mjs ADDED
@@ -0,0 +1,39 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { REVIEWING } from './agents.mjs';
4
+ import { minutesToMs } from './durations.mjs';
5
+ import { readTextIfPresent } from './files.mjs';
6
+ import { git, remoteRef, resetHard } from './git.mjs';
7
+ import { oneAtATime } from './lock.mjs';
8
+ import { huntPrompt } from './prompts.mjs';
9
+ import { WORKTREE_DIR } from './worktree.mjs';
10
+ export const HUNT_FILE = 'next-issue.hunt.md';
11
+ const FILED = /^issue:\s*(\S+)\s*$/m;
12
+ export async function huntWorktree(repo, base, remote) {
13
+ const path = join(repo.root, WORKTREE_DIR, 'hunt');
14
+ const target = remoteRef(remote, base);
15
+ await git(repo.root, ['fetch', remote]);
16
+ await git(repo.root, ['worktree', 'prune']);
17
+ if (existsSync(join(path, '.git'))) {
18
+ await resetHard(path, target);
19
+ }
20
+ else {
21
+ await git(repo.root, ['worktree', 'add', '--detach', path, target]);
22
+ }
23
+ return path;
24
+ }
25
+ export async function hunt(context) {
26
+ const { repo, config, base, recorder, ports } = context;
27
+ await recorder.step('hunt', {}, async () => {
28
+ const cwd = await oneAtATime(repo.root, () => ports.huntWorktree(repo, base, config.remote));
29
+ const instructions = await readTextIfPresent(join(repo.root, HUNT_FILE));
30
+ const result = await ports.runAgent(recorder, {
31
+ name: 'hunter',
32
+ cwd,
33
+ prompt: huntPrompt(instructions, config.labels.ready),
34
+ profile: REVIEWING,
35
+ timeoutMs: minutesToMs(config.agentTimeoutMinutes),
36
+ });
37
+ recorder.event('hunt.issue', { url: FILED.exec(result.text)?.[1] ?? 'none' }, 'quiet');
38
+ });
39
+ }
package/dist/ports.mjs CHANGED
@@ -6,6 +6,7 @@ import { pushToBase, revertOnBase, squashOnto } from './git-land.mjs';
6
6
  import { abortMerge, commitMerge, startMerge } from './git-merge.mjs';
7
7
  import { deleteBranch, diff, discardChanges, disputeBranches, isDirty, latestSubject, push, resetToBase, revision, setAside, } from './git.mjs';
8
8
  import { canWrite, closeIssue, commentOnIssue, issueComments, openBlockers, openIssues, reopenIssue, threadComments, viewIssue, } from './github.mjs';
9
+ import { huntWorktree } from './hunt.mjs';
9
10
  import { setLabel } from './labels.mjs';
10
11
  import { detectSetupCommand } from './setup.mjs';
11
12
  import { addWorktree, findWorktree, removeWorktree } from './worktree.mjs';
@@ -27,6 +28,7 @@ export const PORTS = {
27
28
  disputeBranches,
28
29
  failedBaseLogs,
29
30
  findWorktree,
31
+ huntWorktree,
30
32
  isDirty,
31
33
  issueComments,
32
34
  latestSubject,
package/dist/prompts.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { ISSUE_SECTIONS } from './issue-format.mjs';
1
2
  import { paragraphs } from './text.mjs';
2
3
  const COMMIT_RULES = [
3
4
  'Do not run git, gh or any push command. The harness commits for you.',
@@ -149,3 +150,25 @@ export function history(rounds) {
149
150
  : `${head}\nThe fixer disputed every finding of this round: ${round.dispute}`;
150
151
  });
151
152
  }
153
+ const HUNT_DEFAULT = [
154
+ 'Read the whole repository and look for bugs: wrong results, unhandled errors, races, security holes and documentation that contradicts the code.',
155
+ 'Prove each finding from the code. A guess is not a finding.',
156
+ ].join('\n');
157
+ export function huntPrompt(instructions, ready) {
158
+ const kept = instructions?.trim() ?? '';
159
+ const label = ready === '' ? '' : ` --label "${ready}"`;
160
+ return paragraphs([
161
+ 'You are the hunter. Find the most serious problem in this repository and file one issue for it.',
162
+ `## Instructions\n${kept === '' ? HUNT_DEFAULT : kept}`,
163
+ '## Rules',
164
+ [
165
+ 'Run no test suite and no build. Change no file. Do not commit or push.',
166
+ 'File one issue only, for your most serious finding. File nothing when you find no real problem.',
167
+ 'Before you file it, search the open and closed issues for a duplicate, for example with `gh issue list --state all --search "<words>"`. File nothing when a duplicate exists.',
168
+ `File it with \`gh issue create${label} --title "<conventional commit subject>" --body-file -\`.`,
169
+ `The body holds these sections as \`##\` headings, in this order: ${ISSUE_SECTIONS.map((section) => `\`## ${section}\``).join(', ')}.`,
170
+ 'Give the file and line of each piece of evidence. Leave the Open questions section empty.',
171
+ 'End your final message with one line in the form `issue: <url of the new issue>`, or `issue: none` when you filed nothing.',
172
+ ].join('\n'),
173
+ ]);
174
+ }
package/dist/run.mjs CHANGED
@@ -7,6 +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
11
  import { exitCode, runIssues } from './loop.mjs';
11
12
  import { Recorder } from './observe.mjs';
12
13
  import { pendingIssues } from './pending.mjs';
@@ -45,7 +46,7 @@ async function handle(args, config, repo, recorder, controls) {
45
46
  };
46
47
  const print = controls.print ?? (async () => undefined);
47
48
  const { reports, stoppedAt, error } = args.watch
48
- ? await watchRun(args, loop, recorder, interrupts, print)
49
+ ? await watchRun(args, loop, context, interrupts, print)
49
50
  : await runIssues(args, loop);
50
51
  recordLoopEnd(recorder, stoppedAt, error);
51
52
  const summary = await endRun(recorder, reports);
@@ -54,7 +55,8 @@ async function handle(args, config, repo, recorder, controls) {
54
55
  }
55
56
  return error === undefined ? exitCode(reports) : 1;
56
57
  }
57
- function watchRun(args, loop, recorder, interrupts, print) {
58
+ function watchRun(args, loop, context, interrupts, print) {
59
+ const { recorder } = context;
58
60
  let passStart = recorder.summary();
59
61
  return watchIssues(args, {
60
62
  ...loop,
@@ -64,6 +66,7 @@ function watchRun(args, loop, recorder, interrupts, print) {
64
66
  return interrupts.sleep(minutesToMs(minutes));
65
67
  },
66
68
  passEnd: (issues) => print({ ...recorder.summary(passStart), issues }),
69
+ ...(args.hunt ? { hunt: () => hunt(context).catch(() => undefined) } : {}),
67
70
  });
68
71
  }
69
72
  function recordLoopEnd(recorder, stoppedAt, error) {
package/dist/watch.mjs CHANGED
@@ -5,6 +5,7 @@ export async function watchIssues(args, watch) {
5
5
  const reports = [];
6
6
  const failed = new Set();
7
7
  let step = 0;
8
+ let hunting = true;
8
9
  for (;;) {
9
10
  const pass = await runIssues({ once: false, max: limit === undefined ? undefined : limit - handled(reports) }, watch, new Set(failed));
10
11
  reports.push(...pass.reports);
@@ -12,6 +13,7 @@ export async function watchIssues(args, watch) {
12
13
  if (handled(pass.reports) > 0) {
13
14
  await watch.passEnd(pass.reports);
14
15
  step = 0;
16
+ hunting = true;
15
17
  }
16
18
  if (pass.error !== undefined || pass.stoppedAt !== undefined) {
17
19
  return { ...pass, reports };
@@ -19,6 +21,10 @@ export async function watchIssues(args, watch) {
19
21
  if ((limit !== undefined && handled(reports) >= limit) || watch.stop()) {
20
22
  return { reports };
21
23
  }
24
+ if (hunting) {
25
+ hunting = false;
26
+ await watch.hunt?.();
27
+ }
22
28
  const minutes = backOffMinutes(step);
23
29
  step += 1;
24
30
  if (!(await watch.wait(minutes))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "5.4.0",
3
+ "version": "5.5.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",