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: sweep checker reports into items; runner tiers and deps [N15,N16]
Corey Olsonac9e72c32142
diff --git a/src/board.js b/src/board.jsindex 407513e6..7a99e52b 100644--- a/src/board.js+++ b/src/board.js@@ -956,18 +956,19 @@ export function events(board, { itemId } = {}) {* while there is heavier work to do (B13). When nothing is free, the reasons say what everything* is waiting on.*- * With `runnable`, only items that carry a check command, which an unattended runner needs.+ * With `runnable`, only items that carry a check command, which an unattended runner needs; with+ * `routes`, only items on those routes, the ones a runner has an agent command for.** @param {any} board- * @param {{ agentId: string, lane: string, verify?: boolean, runnable?: boolean }} who+ * @param {{ agentId: string, lane: string, verify?: boolean, runnable?: boolean, routes?: string[] }} who* @returns {{ item: any | null, reasons: string[] }}*/-export function nextFor(board, { agentId, lane, verify = false, runnable = false }) {+export function nextFor(board, { agentId, lane, verify = false, runnable = false, routes = ROUTES }) {const route = routeOf(board, agentId);const tier = (entry) => ROUTES.indexOf(entry.item_route);const items = listItems(board).reverse()- .filter((entry) => canTake(route, entry.item_route) && (!runnable || entry.item_check))+ .filter((entry) => canTake(route, entry.item_route) && routes.includes(entry.item_route) && (!runnable || entry.item_check)).sort((first, second) => tier(second) - tier(first));const tiers = route === 'strong' ? '' : `${ROUTES.slice(0, ROUTES.indexOf(route) + 1).reverse().join(' or ')} `;const routed = `${tiers}${runnable ? 'runnable ' : ''}`;diff --git a/src/cli.js b/src/cli.jsindex aa14f19f..eee6fb56 100644--- a/src/cli.js+++ b/src/cli.js@@ -2,6 +2,7 @@* The pullboard command line: every command, bound to who is asking (B3). The main checkout is the* coordinator; every other worktree is the agent that joined from it.*/+import { spawnSync } from 'node:child_process';import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';import { basename, dirname, join, resolve } from 'node:path';import { pathToFileURL } from 'node:url';@@ -19,7 +20,7 @@ import {prePushProblems,} from './hooks.js';import { initRepo } from './init.js';-import { isLane, laneNames, outOfLane } from './lanes.js';+import { isLane, laneNames, laneOf, outOfLane } from './lanes.js';import { Refused } from './refused.js';import { commitCitations, committedIds } from './history.js';import { promptFor } from './skills.js';@@ -36,6 +37,7 @@ import {} from './spec.js';import { briefFiles } from './brief.js';import { runItems } from './run.js';+import { parseProblems, sweepItems } from './sweep.js';import { renderSpecView } from './view.js';const PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));@@ -63,6 +65,7 @@ Workpullboard run --agent "<command>" [--attempts 3] [--minutes 15] [--items N] [--wait M]build routed items unattended in this worktree: the agent command readsthe context pack at $PULLBOARD_PACK; green work is submitted, red escalated+ [--agent-light "..."] [--agent-mid "..."] [--agent-strong "..."] a command per tierpullboard list [lane] [--all] [--route light|mid|strong] open and active items; --all adds closed onespullboard show <id> an item, the criterion frozen at claim, its verdictspullboard next [--wait <minutes>] claim the next item in your lane that is free to start@@ -76,6 +79,8 @@ Workpullboard shout <lane|agent|all> <text> pullboard inboxCoordinator+ pullboard sweep --run "<checker>" --check "<checker on {file}>" [--route light] [--max 20] [--dry-run]+ file one item per file a linter, type checker or test reporter flagspullboard merged <id> <commit> record where verified work landedpullboard withdraw <id> <reason> drop an item nobody should buildpullboard refreeze <id> re-freeze a criterion after its spec rows changed@@ -114,9 +119,15 @@ const OPTIONS = {as: { type: 'string' },check: { type: 'string' },agent: { type: 'string' },+ 'agent-light': { type: 'string' },+ 'agent-mid': { type: 'string' },+ 'agent-strong': { type: 'string' },attempts: { type: 'string' },minutes: { type: 'string' },items: { type: 'string' },+ run: { type: 'string' },+ max: { type: 'string' },+ 'dry-run': { type: 'boolean' },wait: { type: 'string' },verify: { type: 'boolean' },all: { type: 'boolean' },@@ -583,7 +594,7 @@ function nextOnce(ctx, values) {return withBoard(ctx, (board) => {if (values.verify) checkMainVerifier(ctx, board, values);const me = whoAmI(ctx, board);- const { item, reasons } = store.nextFor(board, { agentId: me.id, lane: me.lane, verify: values.verify, runnable: values.runnable });+ const { item, reasons } = store.nextFor(board, { agentId: me.id, lane: me.lane, verify: values.verify, runnable: values.runnable, routes: values.routes });if (!item) return { reasons };if (values.verify) return { item };if (item.item_status === 'claimed') return { item, held: true };@@ -641,6 +652,52 @@ async function nextHere(io, values) {}}+/**+ * `pullboard sweep` (N15): run a checker, then file one routed item per file it flags, each with+ * the problems in its brief and the checker on that file as its check.+ *+ * @param {any} ctx+ * @param {any} board+ * @param {{ id: string }} me+ * @param {any} values+ * @returns {number}+ */+function sweepHere(ctx, board, me, values) {+ if (me.id !== COORDINATOR) throw new Refused('COORDINATOR_ONLY', 'the coordinator files sweep items, from the main checkout');+ const report = String(values.run ?? '').trim();+ const check = String(values.check ?? '').trim();+ if (!report || !check.includes('{file}')) {+ throw new Refused('USAGE', 'pullboard sweep --run "<checker over the repo>" --check "<the checker on one file, with {file} where its path goes>"');+ }+ const max = values.max === undefined ? 20 : idArg(values.max, 'a number after --max');+ const ran = spawnSync(report, { cwd: ctx.info.root, shell: true, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });+ const problems = parseProblems(`${ran.stdout ?? ''}\n${ran.stderr ?? ''}`, ctx.info.root);+ if (!problems.length) {+ ctx.io.say(`the checker reported no problems I can read (exit ${ran.status}); nothing to file`);+ return 0;+ }+ const covered = new Set(store.listItems(board).filter((item) => item.item_title.startsWith('fix ')).flatMap((item) => briefFiles(item.item_brief)));+ const { items, skipped } = sweepItems(problems, {+ laneOf: (path) => laneOf(ctx.config, path),+ covered,+ check,+ report,+ route: values.route ?? 'light',+ max,+ });+ for (const item of items) {+ if (values['dry-run']) {+ ctx.io.say(`would file: ${item.title} (${item.lane} lane, ${item.route})`);+ continue;+ }+ const id = store.addItem(board, { by: me.id, lane: item.lane, title: item.title, criterion: item.criterion, brief: item.brief, route: item.route, check: item.check });+ ctx.io.say(`#${id} ${item.title} (${item.lane} lane, ${item.route})`);+ }+ if (skipped.length) ctx.io.say(`already open: ${skipped.join(', ')}`);+ ctx.io.say(`${problems.length} problems in ${new Set(problems.map((problem) => problem.file)).size} files; ${values['dry-run'] ? 'would file' : 'filed'} ${items.length}`);+ return 0;+}+/*** The commands that change the board.*@@ -701,6 +758,7 @@ function workCommands(io, args) {return 0;}),run: () => runItems(io, values, { context, withBoard, whoAmI, nextOnce, submitHere, freezer }),+ sweep: () => act((ctx, board, me) => sweepHere(ctx, board, me, values)),next: () => nextHere(io, values),claim: () => act((ctx, board, me) => {const result = store.claim(board, idArg(first), { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: freezer(ctx) });diff --git a/src/run.js b/src/run.jsindex ffb4bce8..cf8fe834 100644--- a/src/run.js+++ b/src/run.js@@ -16,7 +16,7 @@ import * as store from './board.js';import { briefFiles } from './brief.js';import { COORDINATOR } from './config.js';import { runGate } from './gate.js';-import { git, headCommit, isClean, tryGit, untracked } from './git.js';+import { contains, git, headCommit, isClean, tryGit, untracked } from './git.js';import { laneNames, outOfLane } from './lanes.js';import { Refused } from './refused.js';@@ -123,10 +123,10 @@ function restore(root, start, paths) {** @param {string} root* @param {any} item- * @param {{ attempt: number, attempts: number, digest: string }} state+ * @param {{ attempt: number, attempts: number, digest: string, earlier?: string[] }} state* @returns {string}*/-export function packText(root, item, { attempt, attempts, digest }) {+export function packText(root, item, { attempt, attempts, digest, earlier = [] }) {const rows = item.item_frozen ? JSON.parse(item.item_frozen).rows : [];const files = briefFiles(item.item_brief);let budget = PACK_FILE_CHARS;@@ -157,6 +157,8 @@ export function packText(root, item, { attempt, attempts, digest }) {'- Never run git commands; the runner commits your work.','- Add no dependencies. Change a test only where the brief says to.','- Run the check yourself before you finish, and stop when it passes.',+ '- The runner handles the board and git: never run pullboard or git commands, whatever other instructions say.',+ ...(earlier.length ? ['', '## Earlier tries by a lighter model', ...earlier.map((note) => `- ${note}`), 'Start fresh from the files below; do not repeat what failed.'] : []),...(digest? ['', '## Your previous attempt', 'It left the files as they are below. Continue from them. It failed with:', '```', digest, '```', 'Fix exactly that.']: []),@@ -234,6 +236,29 @@ function pinAttempt(root, id) {}}+/**+ * Bring in the verified work an item waits on (B8), when it was built in another worktree, so a cli+ * item can use the store module the store lane just built. A merge that conflicts is aborted and+ * the item released: integrating it is the coordinator's call, not a model's.+ *+ * @param {any} ctx+ * @param {any} item+ * @param {any} deps+ */+function mergeDependencies(ctx, item, deps) {+ const { root } = ctx.info;+ const after = item.item_after ? item.item_after.split(',').map(Number) : [];+ const needed = deps.withBoard(ctx, (board) => after.map((id) => store.getItem(board, id)))+ .filter((before) => before.item_commit && !contains(root, before.item_commit, 'HEAD'));+ for (const before of needed) {+ const merged = spawnSync('git', ['merge', '--no-edit', '-q', before.item_commit], { cwd: root, encoding: 'utf8' });+ if (merged.status === 0) continue;+ spawnSync('git', ['merge', '--abort'], { cwd: root });+ deps.withBoard(ctx, (board) => store.release(board, item.item_id, deps.whoAmI(ctx, board).id));+ throw new Refused('MERGE_CONFLICT', `#${item.item_id} waits on #${before.item_id}, whose commit ${before.item_commit.slice(0, 12)} conflicts with this worktree; the coordinator integrates it, then run again`);+ }+}+/*** Build one claimed item: attempts until the check and the gate pass, then submit; or pin, reset* and escalate.@@ -243,10 +268,15 @@ function pinAttempt(root, id) {* @param {any} options* @returns {Promise<'submitted' | 'escalated'>}*/-async function buildItem(ctx, item, { agent, attempts, minutes, deps, me }) {+async function buildItem(ctx, item, { agents, attempts, minutes, deps, me }) {const { root } = ctx.info;const id = item.item_id;+ const agent = agents[item.item_route];+ mergeDependencies(ctx, item, deps);const start = headCommit(root) ?? '';+ const earlier = deps.withBoard(ctx, (board) => store.events(board, { itemId: id }))+ .filter((event) => event.event_kind === 'escalate')+ .map((event) => JSON.parse(event.event_detail).note.replace(/\s+/g, ' ').slice(0, 600));const listed = new Set(briefFiles(item.item_brief));const inScope = (path) => (!listed.size || listed.has(path)) && !outOfLane(ctx.config, item.item_lane, [path]).length;const packs = join(ctx.info.gitDir, 'pullboard', 'packs');@@ -257,12 +287,12 @@ async function buildItem(ctx, item, { agent, attempts, minutes, deps, me }) {store.claim(board, id, { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: deps.freezer(ctx) });return store.getItem(board, id);});- const pack = join(packs, `${id}-${attempt}.md`);- writeFileSync(pack, packText(root, fresh, { attempt, attempts, digest }));- ctx.io.say(`#${id} attempt ${attempt}/${attempts}: running the agent`);+ const pack = join(packs, `${id}-${item.item_route}-${attempt}.md`);+ writeFileSync(pack, packText(root, fresh, { attempt, attempts, digest, earlier }));+ ctx.io.say(`#${id} attempt ${attempt}/${attempts}: running the ${item.item_route} agent`);const env = { ...process.env, PULLBOARD_PACK: pack, PULLBOARD_ITEM: String(id), PULLBOARD_ATTEMPT: String(attempt) };const built = await runCommand(agent, { cwd: root, env, timeoutMs: minutes * 60_000 });- writeFileSync(join(packs, `${id}-${attempt}.log`), built.output);+ writeFileSync(join(packs, `${id}-${item.item_route}-${attempt}.log`), built.output);const outside = changedSince(root, start).filter((path) => !inScope(path));restore(root, start, outside);const reverted = outside.length ? `The runner reverted your changes outside the brief's files: ${outside.join(', ')}.\n` : '';@@ -320,9 +350,11 @@ export async function runItems(io, values, deps) {if (ctx.info.isMain) {throw new Refused('MAIN_IS_COORDINATOR', 'the runner builds lane items, so it runs in a lane worktree: pullboard worktree <lane> --route light, then run it there');}- const agent = String(values.agent ?? '').trim();- if (!agent) {- throw new Refused('USAGE', 'pullboard run --agent "<command>": the command that builds one item from the pack in $PULLBOARD_PACK, such as: opencode run "$(cat "$PULLBOARD_PACK")"');+ const agents = Object.fromEntries(+ store.ROUTES.map((route) => [route, String(values[`agent-${route}`] ?? values.agent ?? '').trim()]).filter(([, command]) => command),+ );+ if (!Object.keys(agents).length) {+ throw new Refused('USAGE', 'pullboard run --agent "<command>", or --agent-light, --agent-mid, --agent-strong: the command that builds one item from the pack in $PULLBOARD_PACK, such as: opencode run "$(cat "$PULLBOARD_PACK")"');}const attempts = boundedInt(values.attempts ?? '3', 1, 10, '--attempts');const minutes = boundedInt(values.minutes ?? '15', 1, 240, '--minutes');@@ -333,10 +365,15 @@ export async function runItems(io, values, deps) {throw new Refused('DIRTY', 'the runner starts from a clean worktree; commit or remove your changes first');}const me = deps.withBoard(ctx, (board) => deps.whoAmI(ctx, board));+ const above = Object.keys(agents).filter((route) => !store.canTake(me.route, route) && values[`agent-${route}`]);+ if (above.length) {+ throw new Refused('ROUTE', `this worktree joined on the ${me.route} route, so it cannot take ${above.join(' or ')} items; make one that can: pullboard worktree ${me.lane} --route ${above.at(-1)}`);+ }+ const routes = Object.keys(agents).filter((route) => store.canTake(me.route, route));const totals = { submitted: 0, escalated: 0 };const deadline = Date.now() + waitMinutes * 60_000;while (totals.submitted + totals.escalated < limit) {- const found = deps.nextOnce(ctx, { runnable: true });+ const found = deps.nextOnce(ctx, { runnable: true, routes });if (found.retry) continue;if (!found.item) {if (Date.now() >= deadline) {@@ -346,7 +383,7 @@ export async function runItems(io, values, deps) {await new Promise((done) => setTimeout(done, 5000));continue;}- totals[await buildItem(ctx, found.item, { agent, attempts, minutes, deps, me })] += 1;+ totals[await buildItem(ctx, found.item, { agents, attempts, minutes, deps, me })] += 1;}io.say(`runner done: ${totals.submitted} submitted, ${totals.escalated} escalated`);return 0;diff --git a/src/sweep.js b/src/sweep.jsnew file mode 100644index 00000000..379d3cc9--- /dev/null+++ b/src/sweep.js@@ -0,0 +1,138 @@+/**+ * `pullboard sweep` (N15): turns a checker's report into work a small model can do. A linter, a+ * type checker or any tool that names a file and a line finds the problems; the sweep files one+ * item per file, in the lane that owns it, with the exact problems in its brief and the same tool,+ * run on that file, as its check. Much of a codebase's rigor is just running that loop.+ */+import { relative, isAbsolute } from 'node:path';++const TSC_RE = /^(.+?)\((\d+),(\d+)\): (?:error|warning) (TS\d+): (.+)$/;+const LINE_RE = /^([^\s:][^:]*?):(\d+)(?::(\d+))?:?\s+(.+)$/;+const SEVERITY_RE = /^(?:error|warning|note|info)\s*:?\s*/i;+const RULE_FIRST_RE = /^\[?([A-Z]{1,4}\d{2,5}|[a-z@][\w-]*\/[\w-]+|[a-z][a-z0-9]*(?:-[a-z0-9]+)+)\]?:?\s+(.+)$/;+const RULE_LAST_RE = /^(.*?)\s+\[(?:(?:error|warning)\/)?([A-Za-z@][\w/-]*)\]$/i;+const MAX_LISTED = 30;++/**+ * Problems from ESLint's JSON report, or null when the text is not one.+ *+ * @param {string} text+ * @returns {{ file: string, line: number, col: number, rule: string, message: string }[] | null}+ */+function fromEslint(text) {+ const start = text.indexOf('[');+ if (start === -1) return null;+ let report;+ try {+ report = JSON.parse(text.slice(start));+ } catch {+ return null;+ }+ if (!Array.isArray(report) || !report.every((entry) => typeof entry?.filePath === 'string' && Array.isArray(entry.messages))) return null;+ return report.flatMap((entry) =>+ entry.messages.map((message) => ({+ file: entry.filePath,+ line: message.line ?? 0,+ col: message.column ?? 0,+ rule: message.ruleId ?? 'parse',+ message: String(message.message ?? '').trim(),+ })),+ );+}++/**+ * A problem's rule and message, in the shapes checkers print: a code or rule name first (`F401 ...`,+ * `no-var ...`), or a rule in brackets last (`... [return]`, `... [Error/no-var]`).+ *+ * @param {string} text+ * @returns {{ rule: string, message: string }}+ */+function ruleAndMessage(text) {+ const rest = text.replace(SEVERITY_RE, '').trim();+ const first = RULE_FIRST_RE.exec(rest);+ if (first) return { rule: first[1], message: first[2].trim() };+ const last = RULE_LAST_RE.exec(rest);+ if (last) return { rule: last[2], message: last[1].trim() };+ return { rule: '', message: rest };+}++/**+ * Problems from a report in lines: TypeScript's `file(line,col): error TS1234: message`, or the+ * `file:line:col: message` most other checkers print.+ *+ * @param {string} text+ * @returns {{ file: string, line: number, col: number, rule: string, message: string }[]}+ */+function fromLines(text) {+ return text.split('\n').flatMap((raw) => {+ const line = raw.trim();+ const tsc = TSC_RE.exec(line);+ if (tsc) return [{ file: tsc[1], line: Number(tsc[2]), col: Number(tsc[3]), rule: tsc[4], message: tsc[5] }];+ const plain = LINE_RE.exec(line);+ if (!plain || !/[./]/.test(plain[1])) return [];+ const [, file, row, col = '0', rest] = plain;+ return [{ file, line: Number(row), col: Number(col), ...ruleAndMessage(rest) }];+ });+}++/**+ * Every problem a checker reported, with paths relative to the repo.+ *+ * @param {string} text - The checker's output.+ * @param {string} root+ * @returns {{ file: string, line: number, col: number, rule: string, message: string }[]}+ */+export function parseProblems(text, root) {+ const problems = fromEslint(text) ?? fromLines(text);+ return problems.map((problem) => ({+ ...problem,+ file: isAbsolute(problem.file) ? relative(root, problem.file) : problem.file.replace(/^\.\//, ''),+ }));+}++/**+ * The items a sweep would file: one per file with problems, skipping files an open sweep item+ * already covers, at most `max`.+ *+ * @param {ReturnType<typeof parseProblems>} problems+ * @param {{ laneOf: (path: string) => string, covered: Set<string>, check: string, report: string, route: string, max: number }} options+ * @returns {{ items: any[], skipped: string[] }}+ */+export function sweepItems(problems, { laneOf, covered, check, report, route, max }) {+ const byFile = new Map();+ for (const problem of problems) {+ if (!problem.file || problem.file.startsWith('..')) continue;+ byFile.set(problem.file, [...(byFile.get(problem.file) ?? []), problem]);+ }+ const items = [];+ const skipped = [];+ for (const [file, found] of [...byFile].sort((first, second) => second[1].length - first[1].length)) {+ if (covered.has(file)) {+ skipped.push(file);+ continue;+ }+ if (items.length >= max) break;+ const listed = found.slice(0, MAX_LISTED).map((problem) => `- line ${problem.line}${problem.col ? `:${problem.col}` : ''}${problem.rule ? ` ${problem.rule}` : ''}: ${problem.message}`);+ const more = found.length > MAX_LISTED ? [`- and ${found.length - MAX_LISTED} more like these`] : [];+ items.push({+ file,+ lane: laneOf(file),+ route,+ title: `fix ${found.length} ${found.length === 1 ? 'problem' : 'problems'} in ${file}`,+ criterion: `\`${report}\` reports no problems in ${file}, and its behavior is unchanged: the gate stays green`,+ check: check.replaceAll('{file}', file),+ brief: [+ 'Files:',+ `- ${file}`,+ 'Change:',+ `- fix each problem the checker reported in ${file}, changing as little as each fix needs:`,+ ...listed,+ ...more,+ 'Test:',+ `- the check reports nothing for ${file}, and the existing tests still pass`,+ 'Out of scope: every other file; disabling the rule; ignore or suppression comments; changing what the code does',+ ].join('\n'),+ });+ }+ return { items, skipped };+}