@mergeline/agent 0.7.0 → 0.7.2
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 +31 -12
- package/dist/init.js +7 -1
- package/dist/review.js +83 -0
- package/dist/worker.js +6 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@ secrets; commit it), so in that repository, and in the agents' worktrees of
|
|
|
26
26
|
it, the commands below use that board. The file also holds the kit's
|
|
27
27
|
version, which every claim sends with the package's: when the board expects
|
|
28
28
|
a newer kit, the claim's answer says to run
|
|
29
|
-
`npx -y @mergeline/agent@latest init --claude` again
|
|
29
|
+
`npx -y @mergeline/agent@latest init --claude` again; it keeps the file's
|
|
30
|
+
other keys (`test`, `review`). `login` checks the key with the
|
|
30
31
|
board and saves it in `~/.config/mergeline/credentials.json` (readable only
|
|
31
32
|
by you, outside any repository), per board and agent: `fe-1` on two boards
|
|
32
33
|
is two saved keys. `login` takes the address typed with `--url` (or
|
|
@@ -235,15 +236,15 @@ to inspect.
|
|
|
235
236
|
#### The reviewer: the same worker with a reviewer's key
|
|
236
237
|
|
|
237
238
|
An agent with the role `reviewer` runs the same command. Its worker claims
|
|
238
|
-
the board's review runs (a
|
|
239
|
+
the board's review runs (a developer's PR waiting in Agent review), never a
|
|
239
240
|
ticket of its own:
|
|
240
241
|
|
|
241
242
|
```sh
|
|
242
243
|
board watch --agent rv-1 --engine codex --follow
|
|
243
244
|
```
|
|
244
245
|
|
|
245
|
-
Every 0.7.0
|
|
246
|
-
rework, review); which one it gets decides what it does. A
|
|
246
|
+
Every worker from 0.7.0 on asks the board for all three kinds of run (implement,
|
|
247
|
+
rework, review); which one it gets decides what it does. A developer's
|
|
247
248
|
rework run (after the reviewer's or a person's return) is worked as any
|
|
248
249
|
other run, and its prompt says the run is done when each point of the
|
|
249
250
|
note is fixed or answered.
|
|
@@ -260,21 +261,39 @@ loses data, is a security issue, a red gate, a broken rule or a missed
|
|
|
260
261
|
requirement, and it comes with proof; nitpicks are not reported.
|
|
261
262
|
|
|
262
263
|
`rules.md` is the project's rules for reviews: the file that
|
|
263
|
-
`.mergeline.json`'s `review` key names
|
|
264
|
-
added by hand
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
264
|
+
`.mergeline.json`'s `review` key names. Both of the worker's keys are
|
|
265
|
+
added by hand, next to what `board init` wrote; `board init` keeps them
|
|
266
|
+
when it updates the file (0.7.1 and later):
|
|
267
|
+
|
|
268
|
+
```json
|
|
269
|
+
{
|
|
270
|
+
"board": "https://acme.mergeline.app",
|
|
271
|
+
"kit": 5,
|
|
272
|
+
"test": "npm test",
|
|
273
|
+
"review": "docs/review-rules.md"
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
The worker reads both from `origin/main`, never from the PR's branch, so a
|
|
278
|
+
PR cannot change the rules it is judged by. With no `review` key or no
|
|
279
|
+
file, the engine reviews by the prompt alone; with no `test` key, no test
|
|
280
|
+
command runs.
|
|
268
281
|
|
|
269
282
|
After the engine, the worker checks that neither the worktree's `HEAD` nor
|
|
270
283
|
the branch on origin moved; if one did, it sends nothing and releases the
|
|
271
284
|
run. It runs the repository's `test` command (from `origin/main`) as a
|
|
272
285
|
gate, and a failing one adds a blocking finding, "The test command fails",
|
|
273
|
-
with its output as proof.
|
|
274
|
-
|
|
275
|
-
|
|
286
|
+
with its output as proof. The proof starts with the lines that name the
|
|
287
|
+
failure (`FAIL`, `not ok`, `✕`, each with the line after it; a passing
|
|
288
|
+
check's line never counts), then the end of the output; the gate's detail
|
|
289
|
+
and a developer's question do the same. A run with no `review.json`, or a
|
|
290
|
+
malformed one, is released, and the board queues the review again (three
|
|
291
|
+
tries, then the PR comes to a person marked not reviewed). The worktree is always removed:
|
|
276
292
|
what the engine changed there is never kept or pushed.
|
|
277
293
|
|
|
294
|
+
The review goes to the PR through `gh`, as the person who runs the worker,
|
|
295
|
+
when `gh` is logged in on that machine; to the board in any case.
|
|
296
|
+
|
|
278
297
|
When `gh` is installed and logged in, the worker reads the PR's checks
|
|
279
298
|
(as gates) and posts the review to the PR as one review comment, with a
|
|
280
299
|
line comment for each finding on a line of the diff, **as the person who
|
package/dist/init.js
CHANGED
|
@@ -215,9 +215,15 @@ export function init(opts) {
|
|
|
215
215
|
/** .mergeline.json: the kit's version and the board's address (from --url, else the one there). */
|
|
216
216
|
function repoFile(path, url) {
|
|
217
217
|
let current = {};
|
|
218
|
+
// Every key the file already has (test, review, and any of the project's own) is kept:
|
|
219
|
+
// init sets only board (when given) and kit.
|
|
220
|
+
let keep = {};
|
|
218
221
|
if (existsSync(path)) {
|
|
219
222
|
try {
|
|
220
223
|
current = readRepoFile(path);
|
|
224
|
+
const data = JSON.parse(readFileSync(path, "utf8"));
|
|
225
|
+
if (data && typeof data === "object" && !Array.isArray(data))
|
|
226
|
+
keep = data;
|
|
221
227
|
}
|
|
222
228
|
catch (err) {
|
|
223
229
|
if (!url) {
|
|
@@ -227,7 +233,7 @@ export function init(opts) {
|
|
|
227
233
|
}
|
|
228
234
|
}
|
|
229
235
|
const board = url ?? current.board;
|
|
230
|
-
const content = JSON.stringify({ ...(board ? { board } : {}), kit: KIT_VERSION }, null, 2) + "\n";
|
|
236
|
+
const content = JSON.stringify({ ...keep, ...(board ? { board } : {}), kit: KIT_VERSION }, null, 2) + "\n";
|
|
231
237
|
if (!existsSync(path)) {
|
|
232
238
|
write(path, content, "create");
|
|
233
239
|
record(path, "create");
|
package/dist/review.js
CHANGED
|
@@ -215,6 +215,89 @@ export function tailWithin(text, max) {
|
|
|
215
215
|
const lead = "… ";
|
|
216
216
|
return lead + t.slice(-(max - lead.length));
|
|
217
217
|
}
|
|
218
|
+
/** The last lines of a command's output (a question's "The end of its output"). */
|
|
219
|
+
export function tail(text, lines = 40, chars = 4000) {
|
|
220
|
+
const end = text.replace(/\s+$/, "").split("\n").slice(-lines).join("\n");
|
|
221
|
+
return end.length > chars ? end.slice(-chars) : end;
|
|
222
|
+
}
|
|
223
|
+
/** The most failure lines a test's output is shown with, and the most of each line. */
|
|
224
|
+
const FAILURES_MAX = 10;
|
|
225
|
+
const FAILURE_LINE = 300;
|
|
226
|
+
/**
|
|
227
|
+
* A line that names a failure: FAIL or FAILED in capitals (this repository's suites, Jest, Vitest, pytest, Go's
|
|
228
|
+
* --- FAIL), a TAP `not ok`, or a line that starts with ✕ or ✗. Lowercase "failed" does not count: a summary reads
|
|
229
|
+
* "139 passed, 1 failed", and a passing check can say "failed ones too". A passing check never names a failure,
|
|
230
|
+
* whatever it says: a line that starts with `ok` (TAP, this repository's suites), `✓`, `✔` or `PASS`. Indents and
|
|
231
|
+
* colour codes are ignored.
|
|
232
|
+
*/
|
|
233
|
+
function namesFailure(line) {
|
|
234
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: the ESC of a colour code
|
|
235
|
+
const l = line.replace(/\x1b\[[0-9;]*m/g, "");
|
|
236
|
+
if (/^\s*(?:ok\b|[✓✔]|PASS\b)/.test(l))
|
|
237
|
+
return false;
|
|
238
|
+
return /(?:^|[^A-Za-z0-9_])FAIL(?:ED)?(?![A-Za-z0-9_])/.test(l) || /^\s*not ok\b/.test(l) || /^\s*[✕✗]/.test(l);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The lines of a test command's output that name a failure, each with the line after it (where this repository's
|
|
242
|
+
* suites print `got: …`): the first 10, each line cut to 300 characters with the worker's mark.
|
|
243
|
+
*
|
|
244
|
+
* shortcut: the output is what the worker keeps of it, its last 256 KB; a failure printed before that is not found.
|
|
245
|
+
* `npm test` here chains its suites with &&, so the failing suite is the last one.
|
|
246
|
+
*/
|
|
247
|
+
export function failureLines(output) {
|
|
248
|
+
// A line keeps its indent (cut trims) unless it is cut.
|
|
249
|
+
const fit = (l) => (l.length <= FAILURE_LINE ? l : cut(l, FAILURE_LINE));
|
|
250
|
+
const lines = output.replace(/\s+$/, "").split("\n");
|
|
251
|
+
const out = [];
|
|
252
|
+
let found = 0;
|
|
253
|
+
for (let i = 0; i < lines.length && found < FAILURES_MAX; i++) {
|
|
254
|
+
if (!namesFailure(lines[i]))
|
|
255
|
+
continue;
|
|
256
|
+
found++;
|
|
257
|
+
out.push(fit(lines[i].replace(/\s+$/, "")));
|
|
258
|
+
const next = lines[i + 1];
|
|
259
|
+
// A next line that names a failure is its own (or one past the 10).
|
|
260
|
+
if (next !== undefined && next.trim() && !namesFailure(next))
|
|
261
|
+
out.push(fit(next.replace(/\s+$/, "")));
|
|
262
|
+
}
|
|
263
|
+
return out;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* A failed test command's output for one place, within max characters: the lines that name a failure first, under
|
|
267
|
+
* "Failures:", then the end of the output (tail) cut to what is left. With no such line the text is as before R9.2:
|
|
268
|
+
* head and the tail within max.
|
|
269
|
+
* - head: what goes first (`exit N\n`), counted in max.
|
|
270
|
+
* - first: only the first failure line, no labels (a gate's detail of 500).
|
|
271
|
+
* - fence: each part in a ``` block, the end under "The end of its output:" (a question to the person, head its
|
|
272
|
+
* sentence): head, then " " and that label and block as before, or a blank line and both parts.
|
|
273
|
+
*/
|
|
274
|
+
export function testOutputWithin(output, max, opts = {}) {
|
|
275
|
+
const head = opts.head ?? "";
|
|
276
|
+
const end = tail(output);
|
|
277
|
+
const block = (label, body) => (opts.fence ? `${label}\n\n\`\`\`\n${body}\n\`\`\`` : `${label}\n${body}`);
|
|
278
|
+
const failures = failureLines(output);
|
|
279
|
+
// The end within room characters; nothing when too little is left to show anything.
|
|
280
|
+
const endWithin = (room) => (room >= 20 ? tailWithin(end, room) : "");
|
|
281
|
+
if (!failures.length) {
|
|
282
|
+
if (opts.fence)
|
|
283
|
+
return `${head}${head ? " " : ""}${block("The end of its output:", end)}`;
|
|
284
|
+
return tailWithin(head + end, max);
|
|
285
|
+
}
|
|
286
|
+
if (opts.first) {
|
|
287
|
+
const line = cut(failures[0], Math.max(1, max - head.length));
|
|
288
|
+
const rest = endWithin(max - head.length - line.length - 1);
|
|
289
|
+
return `${head}${line}${rest ? `\n${rest}` : ""}`;
|
|
290
|
+
}
|
|
291
|
+
const lead = opts.fence && head ? `${head}\n\n` : head;
|
|
292
|
+
const shell = block("Failures:", "").length + 2 + block("The end of its output:", "").length;
|
|
293
|
+
const room = max - lead.length - shell;
|
|
294
|
+
let lines = failures.join("\n");
|
|
295
|
+
// The failure lines come first, but not at the cost of the whole end: past two thirds of the room they are cut.
|
|
296
|
+
if (lines.length > room - Math.min(end.length, Math.floor(room / 3)))
|
|
297
|
+
lines = cut(lines, Math.max(1, room - Math.min(end.length, Math.floor(room / 3))));
|
|
298
|
+
const rest = endWithin(room - lines.length);
|
|
299
|
+
return `${lead}${block("Failures:", lines)}\n\n${block("The end of its output:", rest)}`;
|
|
300
|
+
}
|
|
218
301
|
/**
|
|
219
302
|
* The number the board will give each finding (R5's mergeFindings): an earlier finding's own, else the next F<n>
|
|
220
303
|
* in the order they are sent.
|
package/dist/worker.js
CHANGED
|
@@ -33,7 +33,7 @@ import { closeSync, existsSync, lstatSync, mkdirSync, mkdtempSync, openSync, rea
|
|
|
33
33
|
import { homedir, tmpdir } from "node:os";
|
|
34
34
|
import { join, resolve } from "node:path";
|
|
35
35
|
import { reviewPrompt } from "./engines.js";
|
|
36
|
-
import { badPath, boardNumbers, ciGates, diffHunks, findingMarkdown, fitFindings, fitGate, ghFailure, githubBody, githubPr, inHunks, LIMITS, newRefs, readReview, reviewTicketFile, rulesFile, tailWithin, TEST_FINDING, withTestFinding, } from "./review.js";
|
|
36
|
+
import { badPath, boardNumbers, ciGates, diffHunks, findingMarkdown, fitFindings, fitGate, ghFailure, githubBody, githubPr, inHunks, LIMITS, newRefs, readReview, reviewTicketFile, rulesFile, tail, tailWithin, testOutputWithin, TEST_FINDING, withTestFinding, } from "./review.js";
|
|
37
37
|
import { BoardError, BoardPaused, } from "./service.js";
|
|
38
38
|
import { hasWork, isUnreachable, label, sleep, takeLock, untilAnswered } from "./watch.js";
|
|
39
39
|
const FAILURE_STOP = 3;
|
|
@@ -374,11 +374,6 @@ function readFrom(file, offset, max) {
|
|
|
374
374
|
closeSync(fd);
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
|
-
/** The last lines of a command's output, for a question. */
|
|
378
|
-
export function tail(text, lines = 40, chars = 4000) {
|
|
379
|
-
const end = text.replace(/\s+$/, "").split("\n").slice(-lines).join("\n");
|
|
380
|
-
return end.length > chars ? end.slice(-chars) : end;
|
|
381
|
-
}
|
|
382
377
|
/** Runs the worker until a stop condition; returns the exit code for the CLI. */
|
|
383
378
|
export async function work(opts) {
|
|
384
379
|
const { board, engine, log, repo } = opts;
|
|
@@ -818,7 +813,7 @@ export async function work(opts) {
|
|
|
818
813
|
if (t.code === 0 && !t.killed)
|
|
819
814
|
return null;
|
|
820
815
|
const how = t.killed ? "ran past the timeout" : `failed (exit ${t.code})`;
|
|
821
|
-
return `The test command \`${testCommand}\` ${how} after the engine said done
|
|
816
|
+
return testOutputWithin(t.output, LONG_MAX, { head: `The test command \`${testCommand}\` ${how} after the engine said done.`, fence: true });
|
|
822
817
|
};
|
|
823
818
|
if (result.outcome === "done") {
|
|
824
819
|
const failed = await runTest();
|
|
@@ -1148,18 +1143,19 @@ export async function work(opts) {
|
|
|
1148
1143
|
held();
|
|
1149
1144
|
checkConfig();
|
|
1150
1145
|
const passed = t.code === 0 && !t.killed;
|
|
1151
|
-
const end = tail(t.output);
|
|
1152
1146
|
gates.push(fitGate({
|
|
1153
1147
|
name: testCommand,
|
|
1154
1148
|
result: t.killed ? "not_run" : passed ? "passed" : "failed",
|
|
1155
|
-
detail: t.killed ? "stopped: it ran past the worker's timeout" :
|
|
1149
|
+
detail: t.killed ? "stopped: it ran past the worker's timeout" : passed
|
|
1150
|
+
? tailWithin(tail(t.output), LIMITS.short)
|
|
1151
|
+
: testOutputWithin(t.output, LIMITS.short, { head: `exit ${t.code}\n`, first: true }),
|
|
1156
1152
|
source: "worker",
|
|
1157
1153
|
}));
|
|
1158
1154
|
if (!t.killed) {
|
|
1159
1155
|
findings = withTestFinding(findings, review.findings, {
|
|
1160
1156
|
command: testCommand,
|
|
1161
1157
|
passed,
|
|
1162
|
-
output:
|
|
1158
|
+
output: passed ? "" : testOutputWithin(t.output, LIMITS.proof - testCommand.length - 3, { head: `exit ${t.code}\n` }),
|
|
1163
1159
|
});
|
|
1164
1160
|
}
|
|
1165
1161
|
if (!passed)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mergeline/agent",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "The agent's side of a Mergeline board: an MCP server and the `board` CLI. Works with any agent tool that runs MCP servers or shell commands.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "frontender-ua",
|