Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
feat(gate): agents see a digest of the gate, not its log [V10]
Corey Olsonef0239f49e7d
diff --git a/SPEC.md b/SPEC.mdindex 8b2d8dda..13a62f51 100644--- a/SPEC.md+++ b/SPEC.md@@ -38,6 +38,7 @@ Statuses: approved = decided · draft = proposed · pending = open question · f- V7 [approved, must] The verifier's checkout contains the submitted commit. | gate: test/e2e.test.js- V8 [approved, must] Every verdict binds the submitted commit and the frozen digest. | gate: test/board.test.js- V9 [approved, must] In the main checkout, verifying needs --as coordinator, so no agent's verdict is filed as the coordinator's. | gate: test/e2e.test.js | serves: V1+- V10 [draft, must] Agents see a gate digest: one line when green, the failures when red; the full log stays in .git. | gate: test/e2e.test.js | serves: V4## L · Lanes- L1 [approved, must] Lanes live in pullboard.json: folders owned, spec prefixes, when it starts. | gate: test/lanes.test.jsdiff --git a/src/cli.js b/src/cli.jsindex fb554d4d..4434af3c 100644--- a/src/cli.js+++ b/src/cli.js@@ -9,7 +9,7 @@ import { pathToFileURL } from 'node:url';import { parseArgs } from 'node:util';import * as store from './board.js';import { COORDINATOR, loadConfig } from './config.js';-import { runGate } from './gate.js';+import { gateReport, runGate } from './gate.js';import { contains, git, headCommit, headTree, isClean, repoInfo, resolveCommit, tryGit, untracked } from './git.js';import {FIX_NOTE,@@ -685,11 +685,11 @@ function submitHere(ctx, id) {const commit = headCommit(root);if (!commit) throw new Refused('NO_COMMIT', 'nothing committed yet');const gate = runGate(root, ctx.config);- if (!gate.isGreen) throw new Refused('GATE_RED', `the gate is red at ${commit.slice(0, 12)}; fix it, commit, submit again`);+ if (!gate.isGreen) throw new Refused('GATE_RED', `the gate is red at ${commit.slice(0, 12)}; fix it, commit, submit again. ${gateReport(gate)}`);withBoard(ctx, (board) => store.submit(board, id, { agentId: me.id, commit, tree: headTree(root) ?? '', files: filesSince(root, claimHead, commit) }));const pin = `refs/pullboard/items/${id}/${commit.slice(0, 12)}`;git(root, ['update-ref', pin, commit]);- ctx.io.say(`submitted #${id} at ${commit.slice(0, 12)}; gate green${gate.isCached ? ' (this tree already passed)' : ''}`);+ ctx.io.say(`submitted #${id} at ${commit.slice(0, 12)}; ${gateReport(gate)}`);ctx.io.say(`pinned as ${pin}, so this work can't be lost; keep your worktree until it is merged`);ctx.io.say(`next: another agent checks out ${commit.slice(0, 12)} and runs: pullboard verify ${id} accept|reject`);return 0;@@ -1111,7 +1111,7 @@ async function hookCommand(io, { first, second }) {if (!problems.length) {const gate = runGate(info.root, ctx.config);if (gate.isCached) io.say('pre-push: the gate passed on this exact tree; not running it twice');- if (!gate.isGreen) problems = ['the gate is red; fix it before pushing'];+ if (!gate.isGreen) problems = [`the gate is red; fix it before pushing. ${gateReport(gate)}`];}} else {throw new Refused('USAGE', 'pullboard hook pre-commit | commit-msg <file> | pre-push');@@ -1169,7 +1169,7 @@ export async function main(argv, streams) {if (command === 'gate') {const ctx = context(io);const gate = runGate(ctx.info.root, ctx.config);- io.say(gate.isGreen ? `gate green${gate.isCached ? ' (this tree already passed)' : ''}` : 'gate red');+ io.say(gateReport(gate));return gate.isGreen ? 0 : 1;}const commands = { ...setupCommands(io, args), ...readCommands(io, args), ...workCommands(io, args) };diff --git a/src/gate.js b/src/gate.jsindex 9799b836..a2239890 100644--- a/src/gate.js+++ b/src/gate.js@@ -1,7 +1,8 @@/*** The gate (V4, C3): the repo's own check command, run before submit and before every push. A green* run over a committed tree, with nothing untracked and nothing changed while it ran, leaves that- * tree's id in the git dir, so the same tree is never checked twice.+ * tree's id in the git dir, so the same tree is never checked twice. An agent sees a digest of the+ * run, not the run (V10): a passing suite's output costs tokens and says nothing.*/import { spawnSync } from 'node:child_process';import { existsSync, readFileSync, writeFileSync } from 'node:fs';@@ -9,6 +10,24 @@ import { gitPath, headTree, isClean, untracked } from './git.js';import { Refused } from './refused.js';const STAMP = 'pullboard-gate-green';+const LOG = 'pullboard-gate.log';+const DIGEST_CHARS = 3000;+const FAILURE_RE = /fail|error|expected|received|assert|not ok|✗|×|cannot|undefined|exception/i;++/**+ * The lines of a failure worth an agent's attention: those that look like failures first, then the+ * end of the output, capped, so a refusal or a retry carries the reason and not the whole log.+ *+ * @param {string} output+ * @returns {string}+ */+export function digestOf(output) {+ const lines = output.split('\n').map((line) => line.trimEnd()).filter(Boolean);+ const failing = lines.filter((line) => FAILURE_RE.test(line)).slice(0, 25);+ const tail = lines.slice(-15);+ const kept = [...new Set([...failing, ...tail])].join('\n');+ return kept.length > DIGEST_CHARS ? `${kept.slice(0, DIGEST_CHARS)}\n...` : kept;+}/*** The tree a gate run would check, or null when the working copy differs from HEAD or holds@@ -35,24 +54,40 @@ export function isStampedGreen(root) {}/**- * Run the configured gate in the repo, unless this exact tree already passed.+ * Run the configured gate in the repo, unless this exact tree already passed. Its output, both+ * streams in order, is kept whole in the git dir and returned for a digest.** @param {string} root* @param {any} config- * @param {{ stdio?: 'inherit' | 'pipe' }} [options]- * @returns {{ isGreen: boolean, isCached: boolean, output: string }}+ * @returns {{ isGreen: boolean, isCached: boolean, output: string, seconds: number, log: string }}*/-export function runGate(root, config, { stdio = 'inherit' } = {}) {+export function runGate(root, config) {if (!config.gate.trim()) {throw new Refused('NO_GATE', 'no gate configured; set "gate" in pullboard.json, e.g. "npm test"');}- if (isStampedGreen(root)) return { isGreen: true, isCached: true, output: '' };+ if (isStampedGreen(root)) return { isGreen: true, isCached: true, output: '', seconds: 0, log: '' };const before = committedTree(root);- const result = spawnSync(config.gate, { cwd: root, shell: true, stdio, encoding: 'utf8' });+ const started = Date.now();+ // Newlines, not spaces, around the command, so a trailing comment in it cannot swallow the `)`.+ const result = spawnSync(`(\n${config.gate}\n) 2>&1`, { cwd: root, shell: true, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8', maxBuffer: 2 ** 30 });const isGreen = result.status === 0;- const output = stdio === 'pipe' ? `${result.stdout ?? ''}${result.stderr ?? ''}` : '';+ const output = `${result.stdout ?? ''}${result.stderr ?? ''}`;+ const log = gitPath(root, LOG);+ writeFileSync(log, output);if (isGreen && before !== null && committedTree(root) === before) {writeFileSync(gitPath(root, STAMP), `${before}\n`);}- return { isGreen, isCached: false, output };+ return { isGreen, isCached: false, output, seconds: Math.round((Date.now() - started) / 1000), log };+}++/**+ * What an agent sees of a gate run (V10): one line when green; when red, the digest and where the+ * whole output is.+ *+ * @param {{ isGreen: boolean, isCached: boolean, output: string, seconds: number, log: string }} gate+ * @returns {string}+ */+export function gateReport(gate) {+ if (gate.isGreen) return gate.isCached ? 'gate green (this tree already passed)' : `gate green in ${gate.seconds}s`;+ return `gate red in ${gate.seconds}s:\n${digestOf(gate.output).replace(/^/gm, ' ')}\nthe whole output is in ${gate.log}`;}diff --git a/src/run.js b/src/run.jsindex af612a30..4fa1566c 100644--- a/src/run.js+++ b/src/run.js@@ -15,15 +15,13 @@ import { join } from 'node:path';import * as store from './board.js';import { briefFiles } from './brief.js';import { COORDINATOR } from './config.js';-import { runGate } from './gate.js';+import { digestOf, runGate } from './gate.js';import { contains, git, headCommit, isClean, tryGit, untracked } from './git.js';import { laneNames, outOfLane } from './lanes.js';import { Refused } from './refused.js';-const DIGEST_CHARS = 3000;const FILE_CHARS = 32_000;const PACK_FILE_CHARS = 96_000;-const FAILURE_RE = /fail|error|expected|received|assert|not ok|✗|×|cannot|undefined|exception/i;/*** A whole number from a flag, within bounds, or a refusal naming the flag.@@ -78,21 +76,6 @@ function runCommand(command, { cwd, env = process.env, timeoutMs, log }) {});}-/**- * The lines of a failure worth a model's attention: those that look like failures first, then the- * end of the output, capped, so a retry carries the reason and not the whole log.- *- * @param {string} output- * @returns {string}- */-export function digestOf(output) {- const lines = output.split('\n').map((line) => line.trimEnd()).filter(Boolean);- const failing = lines.filter((line) => FAILURE_RE.test(line)).slice(0, 25);- const tail = lines.slice(-15);- const kept = [...new Set([...failing, ...tail])].join('\n');- return kept.length > DIGEST_CHARS ? `${kept.slice(0, DIGEST_CHARS)}\n...` : kept;-}-/*** Every path that differs from the commit the item started at, committed or not, untracked included.*@@ -304,7 +287,7 @@ async function tryItem(ctx, item, { command, attempts, minutes, deps, me, start,} else {const isDirty = !isClean(root) || untracked(root).length > 0;const committed = isDirty ? commitWork(root, item, ctx.config, changedSince(root, start)) : { ok: true, output: '' };- const gate = committed.ok ? runGate(root, ctx.config, { stdio: 'pipe' }) : { isGreen: false, output: committed.output };+ const gate = committed.ok ? runGate(root, ctx.config) : { isGreen: false, output: committed.output };if (!gate.isGreen) {result = committed.ok ? 'gate-red' : 'commit-refused';digest = `${reverted}The check passed, but ${committed.ok ? "the repo's gate" : 'the commit'} failed:\n${digestOf(gate.output)}`;diff --git a/test/e2e.test.js b/test/e2e.test.jsindex c2f27703..400d65f8 100644--- a/test/e2e.test.js+++ b/test/e2e.test.js@@ -676,3 +676,35 @@ test('a fresh worktree with no install of its own runs pullboard from the main cassert.equal(committed.status, 0, committed.stderr);assert.match(resume().stdout, /^resume: web-1, web lane/);});++test('the gate reaches the agent as a digest: one line when green, the failure when red; the whole output stays in the git dir [V10]', () => {+ const box = project();+ writeFileSync(join(box.repo, 'gate.cjs'), [+ "const red = require('node:fs').existsSync('RED');",+ "for (let i = 0; i < 400; i++) console.log(`ok ${i} ${'x'.repeat(red ? 10 : 3000)}`);",+ "if (red) { console.error('not ok 401 - the page renders a heading'); for (let i = 0; i < 100; i++) console.log(`# note ${i}`); process.exit(1); }",+ '',+ ].join('\n'));+ writeFileSync(join(box.repo, 'pullboard.json'), JSON.stringify({ ...CONFIG, gate: 'node gate.cjs # prints a lot' }));+ box.git(box.repo, 'add', '-A');+ box.git(box.repo, 'commit', '-q', '-m', 'chore: a noisy gate');+ const log = join(box.repo, box.git(box.repo, 'rev-parse', '--git-path', 'pullboard-gate.log'));+ const green = box.run(box.repo, 'gate');+ assert.equal(green.code, 0, green.err);+ assert.match(green.out, /^gate green in \d+s\n$/);+ assert.ok(readFileSync(log, 'utf8').length > 1_200_000, 'more than the default 1 MB pipe buffer, read whole');+ writeFileSync(join(box.repo, 'RED'), 'red');+ box.git(box.repo, 'add', 'RED');+ box.git(box.repo, 'commit', '-q', '-m', 'chore: turn the gate red');+ const red = box.run(box.repo, 'gate');+ assert.equal(red.code, 1);+ assert.match(red.out, /^gate red in \d+s:\n {2}not ok 401 - the page renders a heading\n/);+ assert.match(red.out, / {2}# note 99\nthe whole output is in /);+ assert.ok(red.out.length < 4000, `${red.out.length} characters`);+ const lines = readFileSync(log, 'utf8').split('\n');+ assert.equal(lines.length, 502);+ assert.equal(lines[400], 'not ok 401 - the page renders a heading', 'stdout and stderr in one stream, in order');+ box.run(box.repo, 'add', 'coordinator', 'Coordinator work');+ box.run(box.repo, 'claim', '1');+ assert.match(box.run(box.repo, 'submit', '1').err, /GATE_RED[\s\S]*not ok 401 - the page renders a heading/);+});