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
fix(blueprint): own drafts, starters checked first, marker last [S1,I1]
Corey Olsonb16c3402f777
diff --git a/src/blueprints.js b/src/blueprints.jsindex 69dab6c0..4cd649f5 100644--- a/src/blueprints.js+++ b/src/blueprints.js@@ -8,16 +8,16 @@** blueprint 1 required, the format version* name "web-app" required, lowercase letters, digits and dashes- * title "Solo web app" required, one line; the section heading+ * title "Web app" required, one line; the section heading* version 1 required, a positive integer, the blueprint's own version- * kind "app" optional: app, infrastructure, practice or beyond-code+ * kind "product" optional: product, infrastructure, practice or beyond-code* by "Pullboard" optional, who made it* summary "..." optional, one line* prefix "W" optional, the row id prefix it prefers; a free one is used if taken* gate "npm test" optional, set in pullboard.json only when it has no gate* rules [{ key, text, why, tier?, gate? }] tier must|aim (must), gate (review)* questions [{ key, ask, choices, default }] default is one of choices- * items [{ key, title, cites?, after?, lane?, route?, criterion?, brief? }]+ * items [{ key, title, cites?, after?, lane?, route?, criterion?, brief? }] route is strong** Rule and question keys ("W1", "Q1") are unique within the file; an item cites them by key and* waits on other items by their keys. On a board they get real ids from the section's prefix.@@ -32,13 +32,12 @@ import { insertSectionRows, nextRowId } from './spec.js';export const BLUEPRINT_FORMAT = 1;/** The kinds the gallery files blueprints under. */-export const BLUEPRINT_KINDS = ['app', 'infrastructure', 'practice', 'beyond-code'];+export const BLUEPRINT_KINDS = ['product', 'infrastructure', 'practice', 'beyond-code'];const BUNDLED_DIR = fileURLToPath(new URL('./blueprints/', import.meta.url));const NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;const KEY_RE = /^[A-Za-z0-9]+$/u;const PREFIX_RE = /^[A-Z][A-Z0-9]*$/u;-const ROUTES = ['light', 'mid', 'strong'];/*** The names of the blueprints shipped with Pullboard, sorted.@@ -162,7 +161,8 @@ export function validateBlueprint(value, source = 'blueprint') {if (!itemKeys.has(before) || before === item.key) fail(`${at}.after`, `names ${JSON.stringify(before)}, which is no earlier item key`);}line(`${at}.lane`, item.lane, { required: false });- if (item.route !== undefined && !ROUTES.includes(item.route)) fail(`${at}.route`, `must be one of ${ROUTES.join(', ')}`);+ // A light or mid item needs a coordinator's check and a cold brief, which a blueprint cannot carry.+ if (item.route !== undefined && item.route !== 'strong') fail(`${at}.route`, 'must be strong or left out; add a light or mid item later with pullboard add and its check');line(`${at}.criterion`, item.criterion, { required: false });if (item.brief !== undefined && typeof item.brief !== 'string') fail(`${at}.brief`, 'must be text');});@@ -178,8 +178,8 @@ export function validateBlueprint(value, source = 'blueprint') {}/**- * The marker line a blueprint leaves under its section heading, so the same version adds nothing- * twice even after the person rewords or declines its rows.+ * The marker line a blueprint leaves after its rows once everything is added, so the same version+ * adds nothing twice even after the person rewords or declines its rows.** @param {{ name: string, version: number }} blueprint* @returns {string}@@ -217,7 +217,7 @@ export function questionText(question) {* @param {{ source: string, spec: any, doctrine: any, itemTitles: Iterable<string>, gate: string }} board* source is SPEC.md's text and spec its parse; doctrine is loadDoctrine's result; itemTitles are* every item title on the board; gate is pullboard.json's gate now.- * @returns {{ marked: boolean, section: { prefix: string, name: string, isNew: boolean }, rows: { key: string, id: string, status: string, text: string, line: string }[], specAfter: string, ids: Record<string, string>, items: { key: string, title: string, specIds: string[], after: string[], lane?: string, route: string, criterion: string, brief: string }[], gate: string | null }}+ * @returns {{ marked: boolean, section: { prefix: string, name: string, isNew: boolean }, rows: { key: string, id: string, status: string, text: string, line: string }[], specRows: string, specAfter: string, ids: Record<string, string>, items: { key: string, title: string, specIds: string[], after: string[], lane?: string, route: string, criterion: string, brief: string }[], gate: string | null }}*/export function planBlueprint(blueprint, { source, spec, doctrine, itemTitles, gate }) {const marker = blueprintMarker(blueprint);@@ -233,8 +233,11 @@ export function planBlueprint(blueprint, { source, spec, doctrine, itemTitles, g].filter(Boolean));const prefix = existing ? prefixOf(existing.name) : freePrefix(blueprint, taken);const name = existing ? existing.name : `${prefix} · ${blueprint.title.trim()}`;- const byText = new Map(spec.rows.map((row) => [row.text, row.id]));- const askedIds = new Map(spec.rows.map((row) => [row.text.split(': ')[0], row.id]));+ // Only the blueprint's own section counts as already filed: a row elsewhere with the same words,+ // approved or not, belongs to the person's own spec, and the blueprint still files its drafts.+ const own = existing ? spec.rows.filter((row) => row.section === existing.name) : [];+ const byText = new Map(own.map((row) => [row.text, row.id]));+ const askedIds = new Map(own.map((row) => [row.text.split(': ')[0], row.id]));// The same rows spec draft numbers against: SPEC.md and the repo's own doctrine.const numberedRows = [...spec.rows, ...(doctrine?.repo?.rows ?? [])];const ids = {};@@ -266,8 +269,12 @@ export function planBlueprint(blueprint, { source, spec, doctrine, itemTitles, gkey: item.key, title: item.title.trim(), specIds: item.cites.map((cited) => ids[cited]).filter(Boolean), after: item.after,...(item.lane ? { lane: item.lane } : {}), route: item.route, criterion: item.criterion, brief: item.brief,}));- const specAfter = marked || (!rows.length && existing) ? source : insertSection(source, spec, { existing, name, marker, rows: rows.map((row) => row.line) });- return { marked, section: { prefix, name, isNew: !existing }, rows, specAfter, ids, items, gate: !gate?.trim() && blueprint.gate ? blueprint.gate : null };+ const rowLines = rows.map((row) => row.line);+ // Rows first, marker last: the caller writes specRows, adds the items, then writes specAfter, so a+ // failure part way leaves no marker and a retry adds what is missing.+ const specRows = marked || !rows.length ? source : insertSection(source, spec, { existing, name, lines: rowLines });+ const specAfter = marked ? source : insertSection(source, spec, { existing, name, lines: [...rowLines, marker] });+ return { marked, section: { prefix, name, isNew: !existing }, rows, specRows, specAfter, ids, items, gate: !gate?.trim() && blueprint.gate ? blueprint.gate : null };}/**@@ -288,19 +295,19 @@ function freePrefix(blueprint, taken) {}/**- * Put the rows into SPEC.md text: into the blueprint's existing section the way spec draft does,- * or as a new section at the end, each time after the blueprint's marker line.+ * Put lines into SPEC.md text: into the blueprint's existing section the way spec draft does, or+ * as a new section at the end.** @param {string} source* @param {any} spec- * @param {{ existing: any, name: string, marker: string, rows: string[] }} change+ * @param {{ existing: any, name: string, lines: string[] }} change* @returns {string}*/-function insertSection(source, spec, { existing, name, marker, rows }) {- if (existing) return insertSectionRows(source, spec, existing, [marker, ...rows]);+function insertSection(source, spec, { existing, name, lines: added }) {+ if (existing) return insertSectionRows(source, spec, existing, added);const newline = source.includes('\r\n') ? '\r\n' : '\n';const lines = source.split(/\r?\n/u);while (lines.length && !lines.at(-1).trim()) lines.pop();- lines.push('', `## ${name}`, '', marker, ...rows, '');+ lines.push('', `## ${name}`, '', ...added, '');return lines.join(newline);}diff --git a/src/blueprints/web-app.json b/src/blueprints/web-app.jsonindex 79d775f6..2b970ee1 100644--- a/src/blueprints/web-app.json+++ b/src/blueprints/web-app.json@@ -1,11 +1,11 @@{"blueprint": 1,"name": "web-app",- "title": "Solo web app",+ "title": "Web app","version": 1,- "kind": "app",+ "kind": "product","by": "Pullboard",- "summary": "For one person building a web app with AI agents. One agent builds each change, a second checks it against your rules before it reaches main, and only your decisions reach you.",+ "summary": "For building a web app with AI agents. One agent builds each change, a second checks it against your rules before it reaches main, and only your decisions reach you.","prefix": "W","gate": "npm test","rules": [diff --git a/src/cli.js b/src/cli.jsindex 4b0f0077..a3ef62b9 100644--- a/src/cli.js+++ b/src/cli.js@@ -2225,8 +2225,13 @@ async function addBlueprint(ctx, board, me, blueprint, { report = true } = {}) {const configSource = readFileSync(configFile, 'utf8');const plan = planBlueprint(blueprint, { source, spec, doctrine: ctx.doctrine,itemTitles: store.listItems(board, { all: true }).map((item) => item.item_title), gate: String(JSON.parse(configSource).gate ?? '') });+ // Every starter is checked before anything is written, so a refusal leaves the board as it was.+ const starters = plan.items.map((entry) => ({ key: entry.key, afterKeys: entry.after, item: { by: me.id,+ lane: entry.lane && entry.lane !== COORDINATOR && isLane(ctx.config, entry.lane) ? entry.lane : COORDINATOR,+ title: entry.title, criterion: entry.criterion, specIds: entry.specIds, parentId: null, after: [], brief: entry.brief, route: entry.route } }));+ for (const { item } of starters) store.validateItemAddition(board, item);const files = [];- if (plan.specAfter !== source) files.push({ file: ctx.config.spec, before: source, after: plan.specAfter });+ if (plan.specRows !== source) files.push({ file: ctx.config.spec, before: source, after: plan.specRows });if (plan.gate) {const newline = configSource.includes('\r\n') ? '\r\n' : '\n';files.push({ file: CONFIG_FILE, before: configSource,@@ -2237,20 +2242,22 @@ async function addBlueprint(ctx, board, me, blueprint, { report = true } = {}) {const added = [];try {const byKey = {};- for (const entry of plan.items) {- const lane = entry.lane && entry.lane !== COORDINATOR && isLane(ctx.config, entry.lane) ? entry.lane : COORDINATOR;- const item = { by: me.id, lane, title: entry.title, criterion: entry.criterion, specIds: entry.specIds,- parentId: null, after: entry.after.map((key) => byKey[key]).filter(Boolean), brief: entry.brief, route: entry.route };- store.validateItemAddition(board, item);+ for (const { key, afterKeys, item } of starters) {+ item.after = afterKeys.map((before) => byKey[before]).filter(Boolean);const id = await ordered(ctx, board, 'addItem', [item]);- byKey[entry.key] = id;- added.push({ id, key: entry.key, title: entry.title, lane, specIds: entry.specIds, after: item.after });+ byKey[key] = id;+ added.push({ id, key, title: item.title, lane: item.lane, specIds: item.specIds, after: item.after });}} catch (error) {- // Items already added are on the board for good; keep the rows they cite and say what landed.+ // Items already added stay on the board; with no marker yet, a retry adds only what is missing.if (!added.length) restoreRowApply(ctx.info.root, write);throw error;}+ // The marker goes in last, once every row and item is on the board.+ if (plan.specAfter !== plan.specRows) {+ writeRowApply(ctx.info.root, { records: [], files: [{ file: ctx.config.spec, before: plan.specRows, after: plan.specAfter }], signoffs: { before: null, receipts: [] } });+ }+ if (plan.specAfter !== source && !files.some((file) => file.file === ctx.config.spec)) files.unshift({ file: ctx.config.spec });const rows = plan.rows.map(({ key, id, status, text }) => ({ key, id, status, text }));const summary = { blueprint: { name: blueprint.name, title: blueprint.title, version: blueprint.version },section: plan.section.name, rows, items: added, gate: plan.gate, marked: plan.marked };diff --git a/test/blueprint.test.js b/test/blueprint.test.jsindex a6cfc612..d587b389 100644--- a/test/blueprint.test.js+++ b/test/blueprint.test.js@@ -58,12 +58,12 @@ test('blueprint add files a blueprint as drafts [S1,I1]', () => {const box = freshBoard();const before = readFileSync(join(box.repo, 'SPEC.md'), 'utf8');const added = json(box, 'blueprint', 'add', 'web-app');- assert.deepEqual(added.blueprint, { name: 'web-app', title: 'Solo web app', version: 1 });+ assert.deepEqual(added.blueprint, { name: 'web-app', title: 'Web app', version: 1 });const source = readFileSync(join(box.repo, 'SPEC.md'), 'utf8');assert.ok(source.startsWith(before.trimEnd()), 'the existing spec text is kept as it was');const spec = parseSpec(source);assert.deepEqual(spec.problems, []);- const section = spec.sections.filter((entry) => entry.name.endsWith('· Solo web app'));+ const section = spec.sections.filter((entry) => entry.name.endsWith('· Web app'));assert.equal(section.length, 1, 'one section named after the blueprint');assert.equal(added.section, section[0].name);const rows = spec.rows.filter((row) => row.section === section[0].name);@@ -85,6 +85,7 @@ test('blueprint add files a blueprint as drafts [S1,I1]', () => {for (const row of rows) assert.ok(!doctrine.rows.some((entry) => entry.id === row.id), `${row.id} is unique across SPEC.md and DOCTRINE.md`);const check = box.run('spec', 'check');assert.equal(check.status, 0, check.stdout + check.stderr);+ assert.doesNotMatch(check.stdout + check.stderr, /words; rows stay under/u, 'a reason or the choices do not count toward the row length');// Starter items: open, citing the new rows, the third waiting on the first.const items = json(box, 'list', '--all').items.sort((a, b) => a.item_id - b.item_id);@@ -128,3 +129,51 @@ test('blueprint add files a blueprint as drafts [S1,I1]', () => {json(gated, 'blueprint', 'add', 'web-app');assert.equal(JSON.parse(readFileSync(join(gated.repo, 'pullboard.json'), 'utf8')).gate, 'node --test');});++test('blueprint add files a blueprint as drafts even when approved rows say the same [S1,I1]', () => {+ // Rows elsewhere in the spec, approved, with a rule's exact text and a question's prompt: the+ // blueprint still files every rule as a draft and every question as a pending row of its own.+ const box = freshBoard();+ const file = join(box.repo, 'SPEC.md');+ const rule = `${PUBLISHED.rules[0].text} Why: ${PUBLISHED.rules[0].why}`;+ writeFileSync(file, readFileSync(file, 'utf8').replace('## G · Goals: what the client asked for\n',+ `## G · Goals: what the client asked for\n- G1 [approved, must] ${rule} | gate: review\n- G2 [approved, must] ${PUBLISHED.questions[0].ask}: Rails. Choices: Rails. | gate: review\n`));+ box.git('commit', '-q', '-am', 'chore: approve two rows first');+ const added = json(box, 'blueprint', 'add', 'web-app');+ assert.deepEqual(added.rows.map((row) => row.status), [...Array(6).fill('draft'), ...Array(4).fill('pending')]);+ const spec = parseSpec(readFileSync(file, 'utf8'));+ const own = spec.rows.filter((row) => row.section === added.section);+ assert.equal(own.length, 10, 'the blueprint section holds all its own rows');+ assert.deepEqual(spec.rows.filter((row) => row.status === 'approved').map((row) => row.id), ['G1', 'G2'], 'the approved rows are untouched');+ const items = json(box, 'list', '--all').items.sort((a, b) => a.item_id - b.item_id);+ assert.equal(items[0].item_spec_ids, `${added.rows[0].id},${added.rows[1].id}`, 'starter items cite the blueprint rows, not the approved ones');+});++test('blueprint add files a blueprint as drafts or nothing at all [S1,I1]', () => {+ const box = freshBoard();+ const spec = readFileSync(join(box.repo, 'SPEC.md'), 'utf8');+ const config = readFileSync(join(box.repo, 'pullboard.json'), 'utf8');+ /** Write a variant of the published blueprint and add it, returning the refusal. */+ const refused = (name, items) => {+ writeFileSync(join(box.repo, `${name}.json`), `${JSON.stringify({ ...PUBLISHED, name, items })}\n`);+ const result = box.run('blueprint', 'add', `${name}.json`, '--json');+ assert.equal(result.status, 1, result.stdout + result.stderr);+ assert.equal(readFileSync(join(box.repo, 'SPEC.md'), 'utf8'), spec, `${name}: nothing is written to the spec`);+ assert.equal(readFileSync(join(box.repo, 'pullboard.json'), 'utf8'), config, `${name}: the gate is left alone`);+ assert.equal(json(box, 'list', '--all').items.length, 0, `${name}: no item is added`);+ return JSON.parse(result.stdout).error;+ };+ // A later starter the board refuses (here a brief over its limit) stops the add before any write.+ const late = refused('late-refusal', [{ key: '1', title: 'First starter', cites: ['W1'] }, { key: '2', title: 'Second starter', brief: 'x'.repeat(8001) }]);+ assert.equal(late.code, 'BRIEF_TOO_LONG');+ // Light and mid starters need a coordinator's check and a cold brief, so a blueprint refuses them.+ for (const route of ['light', 'mid']) {+ const error = refused(`${route}-route`, [{ key: '1', title: 'First starter', cites: ['W1'] }, { key: '2', title: 'Second starter', route }]);+ assert.equal(error.code, 'BAD_BLUEPRINT');+ assert.match(error.message, new RegExp(`items\\[1\\]\\.route must be strong`, 'u'));+ }+ // After the refusals, the same blueprint fixed adds everything at once.+ const added = json(box, 'blueprint', 'add', 'web-app');+ assert.equal(added.rows.length, 10);+ assert.equal(added.items.length, 3);+});