next-issue 5.0.0 → 5.2.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
@@ -9,7 +9,7 @@ npx -y next-issue@latest
9
9
 
10
10
  ## Overview
11
11
 
12
- The harness claims the oldest open issue with the `status:todo` label and gives it its own git worktree and branch. An implementer agent does the work and the harness commits it. A reviewer agent judges the diff, and a fixer agent deals with any open finding, and the review runs again. With no open finding left, the harness rebases the change onto the base branch as one commit, pushes it there with no pull request and waits for the checks of that commit. The fixer repairs a red build, and the fix lands the same way. When the checks pass, the issue is closed and gets `status:done`. When a budget runs out or the work cannot go on, the issue gets `status:needs-human` and goes to a person. Then the harness takes the next issue.
12
+ The harness claims the oldest open issue with the `status:todo` label and gives it its own git worktree and branch. An implementer agent does the work and the harness commits it. A reviewer agent judges the diff, and a fixer agent deals with any open finding, and the review runs again. With no open finding left, the harness rebases the change onto the base branch as one commit, pushes it there with no pull request and waits for the checks of that commit. On a red build the harness reruns the failed jobs once, and only a second red build goes to the fixer, whose fix lands the same way. When the checks pass, the issue is closed and gets `status:done`. When a budget runs out or the work cannot go on, the issue gets `status:needs-human` and goes to a person. Then the harness takes the next issue.
13
13
 
14
14
  ```mermaid
15
15
  flowchart TD
@@ -66,8 +66,10 @@ the run handles one issue. For each issue:
66
66
  base when there is none. A fast-forward of the base that is not safe
67
67
  leaves the local base branch as it is and writes a `base.behind` event. A
68
68
  new branch then starts from the remote base.
69
- 4. Let the implementer agent do the work, then commit it. The branch is not
70
- pushed. When a git
69
+ 4. Let the implementer agent do the work, then commit it. For a behaviour
70
+ change, the implementer writes the test first and quotes its failing output
71
+ in its reply. The harness keeps that reply in the state file for the
72
+ reviewer. The branch is not pushed. When a git
71
73
  hook stops a commit, the agent that made the change gets the hook output,
72
74
  fixes it, and the harness commits again. A `commit:` line in the reply of
73
75
  the agent replaces the subject, so a hook that rejects the subject can pass.
@@ -80,6 +82,10 @@ the run handles one issue. For each issue:
80
82
  reviewer reads files and runs commands in the worktree, so it can prove a
81
83
  finding with the tests or the type check. The harness then throws away every
82
84
  change that the reviewer left, so no such change can reach a later commit.
85
+ The first reviewer also gets the reply of the implementer, and raises a
86
+ finding when a behaviour change has no failing run of its test. A later
87
+ reviewer gets the reply of the last review fixer instead, who quotes the
88
+ failing run of a test for a behaviour change.
83
89
  The reviewer ends its last message with its verdict as a json block: a
84
90
  summary and one entry per finding, each rated `blocking` or `minor`. A
85
91
  reply without a valid block hands the issue to a person. The findings are the only ground
@@ -109,7 +115,10 @@ the run handles one issue. For each issue:
109
115
  up to `checkTimeoutMinutes`. A read that fails is tried three times. When
110
116
  the checks pass, the harness closes the issue and sets `status:done`, and
111
117
  the worktree, the local branch and the state file go away. When the checks
112
- fail, the fixer gets their logs from the check budget, and its fix lands
118
+ fail, the harness reruns the failed jobs once with `gh run rerun <id>
119
+ --failed`, records a `main-checks.rerun` event, saves the rerun in the
120
+ state file and waits again once the runs restart. When the rerun cannot
121
+ start, or the checks fail again, the fixer gets their logs from the check budget, and its fix lands
113
122
  the same way. When the fixer cannot fix them, its fix cannot land, or the
114
123
  budget runs out, the harness reverts every commit of the change on the
115
124
  base branch, pushes the revert and hands the issue to a person. A resume
@@ -1,6 +1,9 @@
1
+ import { setTimeout as delay } from 'node:timers/promises';
1
2
  import { pollChecks } from './check-poll.mjs';
2
- import { ghJson } from './gh.mjs';
3
+ import { secondsToMs } from './durations.mjs';
4
+ import { gh, ghJson } from './gh.mjs';
3
5
  import { runLogs } from './run-logs.mjs';
6
+ const RESTART_TRIES = 10;
4
7
  const FAILED_CONCLUSIONS = new Set(['failure', 'timed_out', 'startup_failure']);
5
8
  async function baseRuns(repo, sha) {
6
9
  return ghJson(repo, [
@@ -9,7 +12,7 @@ async function baseRuns(repo, sha) {
9
12
  '--commit',
10
13
  sha,
11
14
  '--json',
12
- 'databaseId,name,status,conclusion',
15
+ 'databaseId,name,status,conclusion,attempt',
13
16
  ]);
14
17
  }
15
18
  function failedRun(entry) {
@@ -29,6 +32,24 @@ export function waitForBaseChecks(repo, sha, options) {
29
32
  watch: async () => baseState(await baseRuns(repo, sha)),
30
33
  }, options);
31
34
  }
35
+ export async function rerunFailedBase(repo, sha) {
36
+ const failed = (await baseRuns(repo, sha)).filter(failedRun);
37
+ for (const entry of failed) {
38
+ await gh(repo, ['run', 'rerun', String(entry.databaseId), '--failed']);
39
+ }
40
+ await waitForRestart(repo, sha, failed);
41
+ return failed.map((entry) => String(entry.databaseId));
42
+ }
43
+ async function waitForRestart(repo, sha, failed) {
44
+ for (let attempt = 1; attempt <= RESTART_TRIES; attempt += 1) {
45
+ const runs = await baseRuns(repo, sha);
46
+ const restarted = failed.every((entry) => runs.some((run) => run.databaseId === entry.databaseId && run.attempt > entry.attempt));
47
+ if (restarted) {
48
+ return;
49
+ }
50
+ await delay(secondsToMs(1));
51
+ }
52
+ }
32
53
  export async function failedBaseLogs(repo, sha, maxChars) {
33
54
  const failed = (await baseRuns(repo, sha))
34
55
  .filter(failedRun)
package/dist/fix.mjs CHANGED
@@ -19,6 +19,9 @@ export async function fixRound(job, reason, detail, earlier, kind) {
19
19
  const { ports } = context;
20
20
  const before = await ports.revision(worktree);
21
21
  const text = await runFixer(job, reason, detail, earlier, kind);
22
+ if (kind === 'review') {
23
+ job.state.fixerReply = text;
24
+ }
22
25
  const unrelated = parseUnrelated(text);
23
26
  if (unrelated !== undefined) {
24
27
  return disputedFix(job, before, reason, unrelated);
package/dist/gate.mjs CHANGED
@@ -1,15 +1,14 @@
1
1
  import { budgetUse } from './budget.mjs';
2
2
  import { checkWaiting } from './check-poll.mjs';
3
+ import { asError } from './errors.mjs';
3
4
  import { escalateCheckFix, fixRound } from './fix.mjs';
4
5
  import { escalateAndFinish } from './handover.mjs';
5
6
  import { GATE_FIXED, GATE_PASSED } from './job.mjs';
6
7
  import { revert } from './revert.mjs';
7
8
  import { writeState } from './state.mjs';
8
9
  export async function checkGate(job, sha) {
9
- const { context, log } = job;
10
- const { repo, config, ports, base } = context;
11
- const checks = await log.step('main-checks', { sha }, () => ports.waitForBaseChecks(repo, sha, checkWaiting(config, true)));
12
- log.event('main-checks.state', { state: checks });
10
+ const { base } = job.context;
11
+ const checks = await rerunOnce(job, sha, await waitForChecks(job, sha));
13
12
  if (checks === 'pass' || checks === 'none') {
14
13
  return GATE_PASSED;
15
14
  }
@@ -19,6 +18,30 @@ export async function checkGate(job, sha) {
19
18
  }
20
19
  return failedChecksFix(job, sha);
21
20
  }
21
+ async function waitForChecks(job, sha, fields = {}) {
22
+ const { context, log } = job;
23
+ const { repo, config, ports } = context;
24
+ const checks = await log.step('main-checks', { sha, ...fields }, () => ports.waitForBaseChecks(repo, sha, checkWaiting(config, true)));
25
+ log.event('main-checks.state', { state: checks, ...fields });
26
+ return checks;
27
+ }
28
+ async function rerunOnce(job, sha, checks) {
29
+ const { context, log, state } = job;
30
+ if (checks !== 'fail' || state.rerun === sha) {
31
+ return checks;
32
+ }
33
+ state.rerun = sha;
34
+ await writeState(context.repo, state);
35
+ try {
36
+ const runs = await context.ports.rerunFailedBase(context.repo, sha);
37
+ log.event('main-checks.rerun', { sha, runs });
38
+ }
39
+ catch (error) {
40
+ log.event('main-checks.rerun-failed', { sha, error: asError(error).message });
41
+ return checks;
42
+ }
43
+ return waitForChecks(job, sha, { rerun: true });
44
+ }
22
45
  async function failedChecksFix(job, sha) {
23
46
  const { context, log, state } = job;
24
47
  const { repo, config, ports, base } = context;
@@ -9,6 +9,7 @@ export async function implement(job) {
9
9
  const { context, issue, log, state, worktree, comments, reply } = job;
10
10
  const before = await context.ports.revision(worktree);
11
11
  const result = await log.step('implement', {}, () => runRole(job, 'implementer', implementPrompt(issue, comments, reply), CODING));
12
+ state.implementerReply = result.text;
12
13
  const subject = parseCommitSubject(result.text, fallbackTitle(issue));
13
14
  if (!(await commitWork(job, before, subject, 'implementer'))) {
14
15
  const escalated = await useEarlierCommit(job);
package/dist/ports.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { runAgent } from './agents.mjs';
2
- import { failedBaseLogs, waitForBaseChecks } from './base-checks.mjs';
2
+ import { failedBaseLogs, rerunFailedBase, waitForBaseChecks } from './base-checks.mjs';
3
3
  import { run } from './exec.mjs';
4
4
  import { commitAll } from './git-commit.mjs';
5
5
  import { pushToBase, revertOnBase, squashOnto } from './git-land.mjs';
@@ -36,6 +36,7 @@ export const PORTS = {
36
36
  pushToBase,
37
37
  removeWorktree,
38
38
  reopenIssue,
39
+ rerunFailedBase,
39
40
  resetToBase,
40
41
  revertOnBase,
41
42
  revision,
package/dist/prompts.mjs CHANGED
@@ -27,6 +27,7 @@ export function implementPrompt(issue, comments, reply = []) {
27
27
  '## Rules',
28
28
  'Read the repository conventions first. Keep the change minimal and focused on the issue.',
29
29
  'Add or update tests when the repository has a test suite.',
30
+ 'For a behaviour change, write the test first and run it before the change. Then quote its failing output in your final message.',
30
31
  COMMIT_RULES,
31
32
  ]);
32
33
  }
@@ -47,7 +48,10 @@ export function capDiff(diff, maxChars) {
47
48
  }
48
49
  function reviewScope(earlier) {
49
50
  return earlier.length === 0
50
- ? 'Check correctness, scope, repository conventions and test cover.'
51
+ ? [
52
+ 'Check correctness, scope, repository conventions and test cover.',
53
+ 'Raise a finding when a behaviour change has no failing run of its test in the reply of the implementer.',
54
+ ].join('\n')
51
55
  : [
52
56
  'This is a later round. Judge two things only:',
53
57
  'whether the earlier findings below are now fixed, and whether the new commits broke something.',
@@ -57,7 +61,8 @@ function reviewScope(earlier) {
57
61
  `## Earlier findings\n${earlier.join('\n')}`,
58
62
  ].join('\n');
59
63
  }
60
- export function reviewPrompt(issue, comments, diff, earlier) {
64
+ export function reviewPrompt(issue, comments, diff, earlier, reply) {
65
+ const role = earlier.length === 0 ? 'implementer' : 'fixer';
61
66
  return [
62
67
  'You are the reviewer. Judge whether the diff solves the issue correctly.',
63
68
  issueBlock(issue, comments),
@@ -65,6 +70,7 @@ export function reviewPrompt(issue, comments, diff, earlier) {
65
70
  '```diff',
66
71
  diff,
67
72
  '```',
73
+ `## Reply of the ${role}\n${reply ?? '(no reply)'}`,
68
74
  '## Rules',
69
75
  'Read files and run commands to prove what you say: the tests, the type check or the linter.',
70
76
  'The worktree is ready to use. Do not change a file. Do not write with git or gh.',
@@ -93,7 +99,10 @@ const CONFLICT_RULE = [
93
99
  ].join('\n');
94
100
  const KIND_RULES = {
95
101
  checks: UNRELATED_RULE,
96
- review: DISPUTE_RULE,
102
+ review: [
103
+ DISPUTE_RULE,
104
+ 'For a behaviour change, run its test before the change and quote its failing output in your final message.',
105
+ ].join('\n'),
97
106
  conflict: CONFLICT_RULE,
98
107
  };
99
108
  function earlierBlock(earlier) {
package/dist/review.mjs CHANGED
@@ -61,7 +61,7 @@ async function runReviewer(job, earlier) {
61
61
  cut: full.length > config.diffMaxChars,
62
62
  };
63
63
  const before = await ports.revision(worktree);
64
- const review = await log.step('review', fields, () => runRole(job, 'reviewer', reviewPrompt(issue, comments, patch, earlier), REVIEWING));
64
+ const review = await log.step('review', fields, () => runRole(job, 'reviewer', reviewPrompt(issue, comments, patch, earlier, earlier.length === 0 ? state.implementerReply : state.fixerReply), REVIEWING));
65
65
  if (await ports.discardChanges(worktree, before)) {
66
66
  log.event('review.discard', { round: state.reviewRounds }, 'quiet');
67
67
  }
package/dist/state.mjs CHANGED
@@ -47,9 +47,12 @@ function isState(value) {
47
47
  PHASES.includes(value.phase) &&
48
48
  typeof value.branch === 'string' &&
49
49
  isOptional(value.title, 'string') &&
50
+ isOptional(value.implementerReply, 'string') &&
51
+ isOptional(value.fixerReply, 'string') &&
50
52
  typeof value.ciFixes === 'number' &&
51
53
  isOptional(value.commitFixes, 'number') &&
52
54
  (value.landed === undefined || isLanded(value.landed)) &&
55
+ isOptional(value.rerun, 'string') &&
53
56
  typeof value.reviewRounds === 'number' &&
54
57
  Array.isArray(value.reviewLog) &&
55
58
  value.reviewLog.every(isReviewRound) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "5.0.0",
3
+ "version": "5.2.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",