next-issue 6.3.6 → 6.4.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
@@ -522,7 +522,7 @@ The watch stops:
522
522
 
523
523
  ## Hunt for bugs
524
524
 
525
- 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 that files an issue. Each wait writes a `hunt.wait` event with the `minutes` to the run log. A hunt that files nothing backs off like a failed one. The hunter:
525
+ 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 that files an issue. Each wait writes a `hunt.wait` event with the `minutes` to the run log. A hunt that files nothing backs off like a failed one. When the harness claims an issue, the hunter wakes: it ends its wait at once, or skips the wait after a hunt that is going, and checks the count again. A wake keeps the back-off where it was. The hunter:
526
526
 
527
527
  - works in its own worktree at `.worktrees/hunt`, at the remote base branch, which the harness fetches and resets before each hunt;
528
528
  - follows `next-issue.hunt.md` in the repository root, or a short built-in prompt when the file is missing;
package/dist/budget.mjs CHANGED
@@ -4,10 +4,11 @@ const LIMITS = { ciFixes: 'maxCiFixes', reviewRounds: 'maxReviewRounds' };
4
4
  export function budgetUse(job, budget) {
5
5
  return { round: job.state[budget], limit: job.context.config[LIMITS[budget]] };
6
6
  }
7
- export async function spendBudget(job, budget, note, reason) {
7
+ export async function spendBudget(job, budget, note, reason, beforeHandOver) {
8
8
  const { context, state } = job;
9
9
  const { round, limit } = budgetUse(job, budget);
10
10
  if (round >= limit) {
11
+ await beforeHandOver?.();
11
12
  return escalateAndFinish(job, note, reason);
12
13
  }
13
14
  state[budget] += 1;
package/dist/conflict.mjs CHANGED
@@ -27,9 +27,8 @@ async function mergeBase(job, before, files) {
27
27
  const { context, worktree } = job;
28
28
  const { config, ports, base } = context;
29
29
  if (files.length > 0) {
30
- const exhausted = await spendBudget(job, 'ciFixes', `The change conflicts with ${base}, and the limit of ${config.maxCiFixes} check fixes was reached.`, 'merge conflict');
30
+ const exhausted = await spendBudget(job, 'ciFixes', `The change conflicts with ${base}, and the limit of ${config.maxCiFixes} check fixes was reached.`, 'merge conflict', () => ports.abortMerge(worktree, before));
31
31
  if (exhausted) {
32
- await ports.abortMerge(worktree, before);
33
32
  return exhausted;
34
33
  }
35
34
  }
package/dist/watch.mjs CHANGED
@@ -3,14 +3,16 @@ const BACK_OFF_MINUTES = [1, 2, 3, 5, 10];
3
3
  export async function watchIssues(args, watch) {
4
4
  const running = new Set();
5
5
  const ended = new AbortController();
6
+ const claims = claimAlarm();
6
7
  const hunting = watch.hunter === undefined
7
8
  ? undefined
8
- : huntIssues(watch.hunter, running, () => ended.signal.aborted || watch.stop(), ended.signal);
9
+ : huntIssues(watch.hunter, running, claims, () => ended.signal.aborted || watch.stop(), ended.signal);
9
10
  try {
10
11
  return await watchPasses(args, {
11
12
  ...watch,
12
13
  process: async (issue) => {
13
14
  running.add(issue.number);
15
+ claims.ring();
14
16
  try {
15
17
  return await watch.process(issue);
16
18
  }
@@ -25,10 +27,30 @@ export async function watchIssues(args, watch) {
25
27
  await hunting;
26
28
  }
27
29
  }
28
- async function huntIssues(hunter, running, stopped, signal) {
30
+ function claimAlarm() {
31
+ let rung = false;
32
+ let controller = new AbortController();
33
+ return {
34
+ ring: () => {
35
+ rung = true;
36
+ controller.abort();
37
+ },
38
+ take: () => {
39
+ const was = rung;
40
+ rung = false;
41
+ return was;
42
+ },
43
+ signal: () => {
44
+ controller = new AbortController();
45
+ return controller.signal;
46
+ },
47
+ };
48
+ }
49
+ async function huntIssues(hunter, running, claims, stopped, signal) {
29
50
  let step = 0;
30
51
  while (!stopped()) {
31
52
  const ready = await hunter.ready().catch(() => undefined);
53
+ claims.take();
32
54
  const waiting = ready?.filter((issue) => !running.has(issue.number)).length;
33
55
  if (waiting !== undefined && waiting < hunter.cap) {
34
56
  if (await hunter.hunt()) {
@@ -36,8 +58,13 @@ async function huntIssues(hunter, running, stopped, signal) {
36
58
  continue;
37
59
  }
38
60
  }
39
- await hunter.wait(backOffMinutes(step), signal);
40
- step += 1;
61
+ if (claims.take() || stopped()) {
62
+ continue;
63
+ }
64
+ await hunter.wait(backOffMinutes(step), AbortSignal.any([signal, claims.signal()]));
65
+ if (!claims.take()) {
66
+ step += 1;
67
+ }
41
68
  }
42
69
  }
43
70
  async function watchPasses(args, watch) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "6.3.6",
3
+ "version": "6.4.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",