next-issue 7.1.0 → 7.2.1
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 +17 -9
- package/dist/gate.mjs +34 -2
- package/dist/git.mjs +21 -0
- package/dist/ports.mjs +2 -1
- package/dist/prompts.mjs +17 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -283,6 +283,18 @@ Every agent prompt holds the body of the issue and the comments of users with wr
|
|
|
283
283
|
|
|
284
284
|
The list lives in `src/issue-format.mts`. The `create-issue` skill of [`@ravshansbox/pi-next-issue`](../pi-next-issue) writes an issue in this format, and a contract test fails when its template and the list disagree. The harness does not reject an issue without the format.
|
|
285
285
|
|
|
286
|
+
## Rules for the agents
|
|
287
|
+
|
|
288
|
+
The implementer and the fixer get these rules in their prompt, and the first reviewer checks them:
|
|
289
|
+
|
|
290
|
+
- update the documentation for a change of behaviour or a feature that is added or removed;
|
|
291
|
+
- remove the tests of a feature or behaviour that is removed;
|
|
292
|
+
- test behaviour that a user can observe, and give each test a description that names the actor, the action and the observable outcome;
|
|
293
|
+
- reuse existing code and patterns, stay consistent with the repository and pick the simpler option;
|
|
294
|
+
- check an API, a command or a url in the repository or its dependencies before using it, and invent none.
|
|
295
|
+
|
|
296
|
+
The reviewer rates a missing documentation update or a test that is not observable as a finding. In every round, it gives the file and line, or the command output, that supports each finding. Personal style rules, such as spelling, code comments or binding names, belong in the `AGENTS.md` of each repository.
|
|
297
|
+
|
|
286
298
|
## Stops for a loop
|
|
287
299
|
|
|
288
300
|
The harness hands the issue to a person, with the `status:needs-human` label,
|
|
@@ -300,7 +312,11 @@ and comments the reason on the issue, when:
|
|
|
300
312
|
not stay there: its edits are committed with no hooks on top of any commit
|
|
301
313
|
of its own, that commit moves to a new local `<n>-dispute-<commit>` branch,
|
|
302
314
|
and the hand-over comment names that branch. The branch goes away with the
|
|
303
|
-
`<n>` branch when the issue is done
|
|
315
|
+
`<n>` branch when the issue is done. For the checks on the base, a failure
|
|
316
|
+
in a file that the change added or changed is never unrelated: when the
|
|
317
|
+
failed logs name such a file (by its path, or by a tail of its path that
|
|
318
|
+
keeps a folder), the harness refuses the claim and gives the fixer another
|
|
319
|
+
round from `maxCiFixes`, with a note that names the file;
|
|
304
320
|
- a fixer disputes or settles the findings and leaves a change behind, either
|
|
305
321
|
in the worktree or in a commit of its own. A dispute carries a reason, not a
|
|
306
322
|
diff, and a retry of the issue cleans the worktree before the next review,
|
|
@@ -683,14 +699,6 @@ issue to the next. The implementer and the fixer may add a short note to it, and
|
|
|
683
699
|
the prompt asks them to keep only what still holds. The reviewer and the hunter
|
|
684
700
|
only read it.
|
|
685
701
|
|
|
686
|
-
Every agent also reads each `AGENTS.md` that pi finds, such as the one in your
|
|
687
|
-
home folder and the one in the repository. The other rules there, such as code
|
|
688
|
-
conventions and test style, still apply. But the harness owns the issue, the
|
|
689
|
-
worktree, the branch, git, the commit, the push and the checks, and the prompt
|
|
690
|
-
says so: a workflow rule in `AGENTS.md` about these, such as "push to main" or
|
|
691
|
-
"watch ci", does not apply to the agent. The hunter still files its issues with
|
|
692
|
-
`gh issue create`.
|
|
693
|
-
|
|
694
702
|
## Retry an issue that waits for a person
|
|
695
703
|
|
|
696
704
|
When the implementer makes no change, the hand-over comment holds its full
|
package/dist/gate.mjs
CHANGED
|
@@ -87,7 +87,7 @@ async function rerunFailed(job, sha) {
|
|
|
87
87
|
}
|
|
88
88
|
return restarted;
|
|
89
89
|
}
|
|
90
|
-
async function failedChecksFix(job, sha) {
|
|
90
|
+
async function failedChecksFix(job, sha, refused) {
|
|
91
91
|
const { context, log, state } = job;
|
|
92
92
|
const { repo, config, ports, base } = context;
|
|
93
93
|
const { round, limit } = budgetUse(job, 'ciFixes');
|
|
@@ -108,12 +108,26 @@ async function failedChecksFix(job, sha) {
|
|
|
108
108
|
log.event('main-checks.logs', { chars: logs.length });
|
|
109
109
|
let fix;
|
|
110
110
|
try {
|
|
111
|
-
fix = await refundOnKill(job, 'ciFixes', () => fixRound(job, `The checks on ${base} failed after the change landed there
|
|
111
|
+
fix = await refundOnKill(job, 'ciFixes', () => fixRound(job, `The checks on ${base} failed after the change landed there.${refusedNote(refused)}`, logs, [], 'checks'));
|
|
112
112
|
}
|
|
113
113
|
catch (error) {
|
|
114
114
|
await refundStopped(job);
|
|
115
115
|
return escalateError(job, error, `The fixer for the failed checks on ${base} failed`, 'fixer error');
|
|
116
116
|
}
|
|
117
|
+
if (!fix.committed && fix.unrelated !== undefined) {
|
|
118
|
+
let files;
|
|
119
|
+
try {
|
|
120
|
+
files = await ports.changedFiles(job.worktree, state.landed ?? []);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
return escalateError(job, error, 'The read of the files of the change failed', 'files error');
|
|
124
|
+
}
|
|
125
|
+
const named = namedFile(logs, files);
|
|
126
|
+
if (named !== undefined) {
|
|
127
|
+
log.event('fix.refused', { file: named }, 'quiet');
|
|
128
|
+
return failedChecksFix(job, sha, named);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
117
131
|
if (!fix.committed) {
|
|
118
132
|
const reverted = await revertOrReport(job);
|
|
119
133
|
return escalateCheckFix(job, fix.unrelated, `checks on ${base}`, reverted, fix.aside);
|
|
@@ -121,6 +135,24 @@ async function failedChecksFix(job, sha) {
|
|
|
121
135
|
job.repairing = true;
|
|
122
136
|
return GATE_FIXED;
|
|
123
137
|
}
|
|
138
|
+
function refusedNote(refused) {
|
|
139
|
+
return refused === undefined
|
|
140
|
+
? ''
|
|
141
|
+
: ` The last fixer called the failure unrelated, but the failed logs name \`${refused}\`, a file of this change, so the failure is not unrelated.`;
|
|
142
|
+
}
|
|
143
|
+
/** The first file of the change that the logs name, by its path or by a tail of its path that keeps a folder. */
|
|
144
|
+
function namedFile(logs, files) {
|
|
145
|
+
return files.find((file) => {
|
|
146
|
+
const parts = file.split('/');
|
|
147
|
+
const tails = parts.length === 1
|
|
148
|
+
? [file]
|
|
149
|
+
: parts.slice(0, -1).map((_, index) => parts.slice(index).join('/'));
|
|
150
|
+
return tails.some((tail) => new RegExp(`(?<![\\w.-])${escapeRegExp(tail)}(?![\\w.-])`).test(logs));
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function escapeRegExp(text) {
|
|
154
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
155
|
+
}
|
|
124
156
|
async function refundStopped(job) {
|
|
125
157
|
if (runStopped()) {
|
|
126
158
|
await refundBudget(job, 'ciFixes');
|
package/dist/git.mjs
CHANGED
|
@@ -59,6 +59,27 @@ export async function isDirty(cwd) {
|
|
|
59
59
|
export async function diff(cwd, base, remote) {
|
|
60
60
|
return git(cwd, ['diff', `${remoteRef(remote, base)}...HEAD`]);
|
|
61
61
|
}
|
|
62
|
+
/** The files that the commits added or changed, as paths from the repository root. */
|
|
63
|
+
export async function changedFiles(cwd, shas) {
|
|
64
|
+
if (shas.length === 0) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
const output = await git(cwd, [
|
|
68
|
+
'show',
|
|
69
|
+
'--no-renames',
|
|
70
|
+
'--diff-filter=d',
|
|
71
|
+
'--name-only',
|
|
72
|
+
'-z',
|
|
73
|
+
'--format=',
|
|
74
|
+
...shas,
|
|
75
|
+
]);
|
|
76
|
+
return [
|
|
77
|
+
...new Set(output
|
|
78
|
+
.split('\0')
|
|
79
|
+
.map((path) => path.trim())
|
|
80
|
+
.filter(Boolean)),
|
|
81
|
+
];
|
|
82
|
+
}
|
|
62
83
|
export async function discardChanges(cwd, target, branch) {
|
|
63
84
|
const moved = branch !== undefined && (await currentBranch(cwd)) !== branch;
|
|
64
85
|
if (!moved &&
|
package/dist/ports.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { run } from './exec.mjs';
|
|
|
4
4
|
import { commitAll } from './git-commit.mjs';
|
|
5
5
|
import { pushToBase, reapplyRevert, revertOnBase, squashOnto } from './git-land.mjs';
|
|
6
6
|
import { abortMerge, commitMerge, startMerge } from './git-merge.mjs';
|
|
7
|
-
import { deleteBranch, diff, discardChanges, disputeBranches, isDirty, isLanded, isOnBase, latestSubject, push, resetToBase, revision, saveEdits, setAside, } from './git.mjs';
|
|
7
|
+
import { changedFiles, deleteBranch, diff, discardChanges, disputeBranches, isDirty, isLanded, isOnBase, latestSubject, push, resetToBase, revision, saveEdits, setAside, } from './git.mjs';
|
|
8
8
|
import { canWrite, closeIssue, commentOnIssue, issueComments, openBlockers, openIssues, reopenIssue, repositorySlug, threadComments, viewIssue, } from './github.mjs';
|
|
9
9
|
import { huntWorktree } from './hunt.mjs';
|
|
10
10
|
import { ensureLabel, setLabel } from './labels.mjs';
|
|
@@ -22,6 +22,7 @@ export const PORTS = {
|
|
|
22
22
|
abortMerge,
|
|
23
23
|
addWorktree,
|
|
24
24
|
canWrite,
|
|
25
|
+
changedFiles,
|
|
25
26
|
closeIssue,
|
|
26
27
|
commentOnIssue,
|
|
27
28
|
commitAll,
|
package/dist/prompts.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ISSUE_SECTIONS } from './issue-format.mjs';
|
|
2
2
|
import { paragraphs } from './text.mjs';
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
'
|
|
6
|
-
|
|
3
|
+
const ENGINEERING_RULES = [
|
|
4
|
+
'Update the documentation when you change behaviour or add or remove a feature.',
|
|
5
|
+
'Remove the tests of a feature or behaviour that you remove.',
|
|
6
|
+
'Test behaviour that a user can observe, not internals. Give each test a description that names the actor, the action and the observable outcome.',
|
|
7
|
+
'Reuse existing code and patterns, stay consistent with the repository and pick the simpler option.',
|
|
8
|
+
'Check an API, a command or a url in the repository or its dependencies before you use it. Do not invent one.',
|
|
7
9
|
].join('\n');
|
|
8
10
|
const COMMIT_RULES = [
|
|
9
|
-
HARNESS_RULES,
|
|
10
11
|
'Do not run git, gh or any push command. The harness commits for you.',
|
|
11
12
|
'End your final message with one line in the form `commit: <conventional commit subject>`.',
|
|
12
13
|
].join('\n');
|
|
@@ -33,6 +34,7 @@ export function implementPrompt(issue, comments, reply = []) {
|
|
|
33
34
|
replyBlock(reply),
|
|
34
35
|
'## Rules',
|
|
35
36
|
'Read the repository conventions first. Keep the change minimal and focused on the issue.',
|
|
37
|
+
ENGINEERING_RULES,
|
|
36
38
|
'Add or update tests when the repository has a test suite.',
|
|
37
39
|
'For a behaviour change, write the test first and run it before the change. Then quote its failing output in your final message.',
|
|
38
40
|
COMMIT_RULES,
|
|
@@ -72,6 +74,10 @@ function reviewScope(earlier) {
|
|
|
72
74
|
? [
|
|
73
75
|
'Check correctness, scope, repository conventions and test cover.',
|
|
74
76
|
'Raise a finding when a behaviour change has no failing run of its test in the reply of the implementer.',
|
|
77
|
+
'Check that the change updates the documentation when it changes behaviour or adds or removes a feature, and that it removes the tests of a removed feature or behaviour.',
|
|
78
|
+
'Check that each test checks behaviour that a user can observe, and that its description names the actor, the action and the observable outcome.',
|
|
79
|
+
'Check that the change reuses existing code and patterns, stays consistent with the repository and picks the simpler option, and that it uses no invented API, command or url.',
|
|
80
|
+
'A missing documentation update or a test that is not observable is a finding.',
|
|
75
81
|
].join('\n')
|
|
76
82
|
: [
|
|
77
83
|
'This is a later round. Judge two things only:',
|
|
@@ -98,8 +104,8 @@ export function reviewPrompt(issue, comments, diff, earlier, reply) {
|
|
|
98
104
|
'Read files and run commands to prove what you say: the tests, the type check or the linter.',
|
|
99
105
|
'The worktree is ready to use. Do not change a file. Do not write with git or gh, and do not check out another commit or branch.',
|
|
100
106
|
'The harness discards each change that you make, so a change is only lost work.',
|
|
101
|
-
HARNESS_RULES,
|
|
102
107
|
reviewScope(earlier),
|
|
108
|
+
'Give the file and line, or the command output, that supports each finding. A guess is not a finding.',
|
|
103
109
|
'Mark a finding blocking only for a wrong result, a missing part of the issue, a regression or a broken convention.',
|
|
104
110
|
'End your final message with the result as a json block in a ```json fence, in the form {"summary": "<short summary>", "findings": [{"severity": "blocking" or "minor", "detail": "<what is wrong and where>"}]}.',
|
|
105
111
|
'Give one entry per finding, and an empty list when nothing is wrong. The findings decide the outcome, so a problem that you leave out counts as no problem.',
|
|
@@ -126,7 +132,10 @@ const CONFLICT_RULE = [
|
|
|
126
132
|
'Leave the merge in progress. The harness commits the merge and pushes it.',
|
|
127
133
|
].join('\n');
|
|
128
134
|
const KIND_RULES = {
|
|
129
|
-
checks:
|
|
135
|
+
checks: [
|
|
136
|
+
UNRELATED_RULE,
|
|
137
|
+
'A failure in a file that this change added or changed is never unrelated. When the failed logs name such a file, the harness refuses an `unrelated` line and gives you another round.',
|
|
138
|
+
].join('\n'),
|
|
130
139
|
local: UNRELATED_RULE,
|
|
131
140
|
review: [
|
|
132
141
|
DISPUTE_RULE,
|
|
@@ -153,6 +162,7 @@ export function fixPrompt(issue, comments, reason, detail, earlier, kind, reply
|
|
|
153
162
|
replyBlock(reply),
|
|
154
163
|
'## Rules',
|
|
155
164
|
'Fix the cause, not the symptom. Keep the change minimal.',
|
|
165
|
+
ENGINEERING_RULES,
|
|
156
166
|
KIND_RULES[kind],
|
|
157
167
|
COMMIT_RULES,
|
|
158
168
|
]);
|
|
@@ -185,8 +195,6 @@ export function huntPrompt(instructions, ready, source, count, repository) {
|
|
|
185
195
|
'## Rules',
|
|
186
196
|
[
|
|
187
197
|
'Run no test suite and no build. Change no file. Do not commit or push.',
|
|
188
|
-
'The harness owns the worktree, git and the checks. The workflow rules of `AGENTS.md` about these do not apply to you.',
|
|
189
|
-
OTHER_RULES,
|
|
190
198
|
`File up to ${issues}, your most serious findings first. File nothing when you find no real problem.`,
|
|
191
199
|
`Before you file an issue, search the open and closed issues for a duplicate, for example with \`gh issue list --repo ${repository} --state all --search "<words>"\`. Do not file a finding when a duplicate exists.`,
|
|
192
200
|
`File each issue with \`gh issue create --repo ${repository}${label} --title "<conventional commit subject>" --body-file -\`.`,
|