@mergeline/agent 0.7.1 → 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 CHANGED
@@ -283,9 +283,12 @@ After the engine, the worker checks that neither the worktree's `HEAD` nor
283
283
  the branch on origin moved; if one did, it sends nothing and releases the
284
284
  run. It runs the repository's `test` command (from `origin/main`) as a
285
285
  gate, and a failing one adds a blocking finding, "The test command fails",
286
- with its output as proof. A run with no `review.json`, or a malformed one,
287
- is released, and the board queues the review again (three tries, then the
288
- PR comes to a person marked not reviewed). The worktree is always removed:
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:
289
292
  what the engine changed there is never kept or pushed.
290
293
 
291
294
  The review goes to the PR through `gh`, as the person who runs the worker,
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. The end of its output:\n\n\`\`\`\n${tail(t.output)}\n\`\`\``;
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" : tailWithin(passed ? end : `exit ${t.code}\n${end}`, LIMITS.short),
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: tailWithin(`exit ${t.code}\n${end}`, LIMITS.proof - testCommand.length - 3),
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.1",
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",