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(blueprint): blueprint add files a blueprint as drafts [S1,I1]
Corey Olsonae47f444e083
diff --git a/docs/api.md b/docs/api.mdindex e5e7d4b1..95c5cdba 100644--- a/docs/api.md+++ b/docs/api.md@@ -108,6 +108,7 @@ For example: `flow: review wait average 61 min (1 measured; > 60 min); bottlenec| `spec view` | `version:number`, `path:string` || `spec show` | `version:number`, `row:object`, `standing:object` || `spec draft` | `version:number`, `id:string`, `row:object` |+| `blueprint add` | `version:number`, `blueprint:object`, `section:string`, `rows:array`, `items:array`, `gate:string\|null` || `spec unmet` | `version:number`, `rows:array` || `spec signoff` | `version:number`, `count:number`, `by:string`, `ids:array`, `evidence:array` || `spec signers` | `version:number`, `added:boolean`, `by:string`, `path:string`, `initial:boolean` |diff --git a/src/cli.js b/src/cli.jsindex ed3f134a..2cf9ea16 100644--- a/src/cli.js+++ b/src/cli.js@@ -44,9 +44,11 @@ import { promptFor, skillProblems, updateSkills } from './skills.js';import {frozenCriterion,idProblems,+ insertSectionRows,lintSpec,loadSpec,legacyDoctrineRenameBase,+ nextRowId,permanenceProblems,parseSpec,readSignoffs,@@ -54,6 +56,7 @@ import {standings,unmetRows,} from './spec.js';+import { bundledBlueprints, planBlueprint, readBlueprint } from './blueprints.js';import { briefFiles } from './brief.js';import { checkBaseline, prepareCheckBaseline, sayCheckBaseline } from './check-baseline.js';import { retryCheckBaselines, startCheckBaseline } from './check-baseline-worker.js';@@ -2172,6 +2175,71 @@ function reportSubmission(ctx, id, commit, gate) {return 0;}+/**+ * Add a blueprint to this board in one step (I1): its rules and questions as draft and pending rows+ * in a new SPEC.md section, its starter items as open items citing them, and its gate when+ * pullboard.json has none. Rows are written the way spec draft writes them, so nothing is approved;+ * a repeat of the same blueprint version adds nothing.+ *+ * @param {any} ctx+ * @param {any} board+ * @param {{ id: string }} me+ * @param {import('./blueprints.js').Blueprint} blueprint+ * @returns {Promise<number>}+ */+async function addBlueprint(ctx, board, me, blueprint) {+ const { io } = ctx;+ const spec = loadSpec(ctx.info.root, ctx.config);+ if (!spec.exists) throw new Refused('NO_SPEC', `no ${ctx.config.spec}; run: pullboard init`);+ const malformed = [[spec.file, spec.problems], [ctx.doctrine.repo.file, ctx.doctrine.repo.problems]].find(([, problems]) => problems.length);+ if (malformed) throw new Refused('SPEC_INVALID', `fix the unparsed row in ${malformed[0]} before adding a blueprint; an existing id may be ambiguous`);+ const source = readFileSync(spec.file, 'utf8');+ const configFile = join(ctx.info.root, CONFIG_FILE);+ 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 ?? '') });+ const files = [];+ if (plan.specAfter !== source) files.push({ file: ctx.config.spec, before: source, after: plan.specAfter });+ if (plan.gate) {+ const newline = configSource.includes('\r\n') ? '\r\n' : '\n';+ files.push({ file: CONFIG_FILE, before: configSource,+ after: `${JSON.stringify({ ...JSON.parse(configSource), gate: plan.gate }, null, 2).replaceAll('\n', newline)}${newline}` });+ }+ const write = { records: [], files, signoffs: { before: null, receipts: [] } };+ writeRowApply(ctx.info.root, write);+ 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);+ 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 });+ }+ } catch (error) {+ // Items already added are on the board for good; keep the rows they cite and say what landed.+ if (!added.length) restoreRowApply(ctx.info.root, write);+ throw error;+ }+ const rows = plan.rows.map(({ key, id, status, text }) => ({ key, id, status, text }));+ io.result?.({ blueprint: { name: blueprint.name, title: blueprint.title, version: blueprint.version },+ section: plan.section.name, rows, items: added, gate: plan.gate });+ if (!rows.length && !added.length && !plan.gate) {+ io.say(`${blueprint.title} (version ${blueprint.version}) is already on this board; nothing added`);+ return 0;+ }+ io.say(`added ${blueprint.title} (version ${blueprint.version}) as drafts in ${ctx.config.spec}, section ${plan.section.name}`);+ for (const row of rows) io.say(` ${row.id} ${row.status} ${row.text}`);+ for (const item of added) io.say(` #${item.id} open ${item.title}${item.specIds.length ? ` cites ${item.specIds.join(', ')}` : ''}${item.after.length ? ` waits on #${item.after.join(', #')}` : ''}`);+ if (plan.gate) io.say(` gate set in ${CONFIG_FILE}: ${plan.gate}`);+ const changed = files.map((file) => file.file);+ io.say(`next: the person approves the rows in pullboard view or with pullboard spec approve <ids>${changed.length ? `; commit ${changed.join(' and ')}` : ''}`);+ return 0;+}+/*** Verify from this checkout (V3, V7): the submitted commit must be here, at or under HEAD, and the* criterion is re-read from the spec, so a verdict is never given against a moved bar.@@ -2464,6 +2532,12 @@ function workCommands(io, args) {return withBoard(ctx, (board) => work(ctx, board, whoAmI(ctx, board)));};return {+ blueprint: () => act(async (ctx, board, me) => {+ if (first !== 'add' || !second || rest.length) {+ throw new Refused('USAGE', `pullboard blueprint add <name or file>; bundled: ${bundledBlueprints().join(', ')}`);+ }+ return await addBlueprint(ctx, board, me, readBlueprint(second, io.cwd));+ }),fact: () => act(async (ctx, board, me) => {if (!first || !second || rest.length !== 1) throw new Refused('USAGE', 'pullboard fact <id> <kind> <text> [--supersedes <fact-id>] [--ref path:lines@full-sha]');const id = idArg(first);diff --git a/src/help.js b/src/help.jsindex ed35e087..ea73bbe9 100644--- a/src/help.js+++ b/src/help.js@@ -149,6 +149,8 @@ Specpullboard spec draft <text> [--section <letter>] [--aim] [--gate "<gate>"] any agent appends a draft row; never approves it--section chooses the section prefix; defaults to GDefaults to must and gate review.+ pullboard blueprint add <name or file> add a blueprint's rules and questions as drafts, and its starter items+ bundled: web-app; nothing is approved, and a repeat adds nothingpullboard spec signers add [--key <path>] [--by <principal>] opt into SSH-signed sign-offsprincipal defaults to Git user.email; --by overrides itpullboard spec approve <ids> | decline <ids> --reason "why" the person's exact-row decision@@ -174,7 +176,7 @@ const HELP_NAMES = ['sweep', 'merged', 'withdraw', 'refreeze', 'reopen', 'hold', 'stats', 'ledger', 'log', 'spec', 'spec check', 'spec view','spec show', 'spec unmet', 'spec signoff', 'spec draft', 'spec signers', 'spec signers add', 'forget', 'prompt', 'gate', 'hook','hook pre-commit', 'hook pre-merge-commit', 'hook commit-msg', 'hook pre-push', 'view export', 'version', 'lifecycle', 'help',- 'roadmap', 'milestone',+ 'roadmap', 'milestone', 'blueprint', 'blueprint add',];const HELP_GROUPS = [@@ -202,6 +204,7 @@ const HELP_EXAMPLES = {'spec check': 'pullboard spec check','spec view': 'pullboard spec view', 'spec show': 'pullboard spec show G1','spec draft': 'pullboard spec draft "Describe the first requirement"',+ 'blueprint add': 'pullboard blueprint add web-app','spec unmet': 'pullboard spec unmet', 'spec signoff': 'pullboard spec signoff G1','spec signers add': 'pullboard spec signers add', help: 'pullboard help claim', version: 'pullboard --version',};@@ -215,6 +218,8 @@ const HELP_ALIASES = {lifecycle: { usage: 'pullboard lifecycle', source: null },escalate: { usage: 'pullboard escalate <id> --note "..." [--note-file <file>]', source: 'escalate <id> --note "what was tried and how it failed"', extraFlags: ['--note-file <file>'] },'view export': { usage: 'pullboard view --export <dir>', source: 'view' },+ blueprint: { usage: 'pullboard blueprint add <name or file>', source: 'blueprint add' },+ 'blueprint add': { usage: 'pullboard blueprint add <name or file>', source: 'blueprint add' },'spec check': { usage: 'pullboard spec check', source: 'spec check' },'spec view': { usage: 'pullboard spec view [--out file]', source: 'spec view' },'spec show': { usage: 'pullboard spec show <id>', source: 'spec show', onlyFlags: [] },diff --git a/src/json.js b/src/json.jsindex cb556f2c..e913a164 100644--- a/src/json.js+++ b/src/json.js@@ -75,6 +75,7 @@ export const JSON_SHAPES = {'spec view': shape({ path: 'string' }),'spec show': shape({ row: 'object', standing: 'object' }),'spec draft': shape({ id: 'string', row: 'object' }),+ 'blueprint add': shape({ blueprint: 'object', section: 'string', rows: 'array', items: 'array', gate: 'string|null' }),'spec unmet': shape({ rows: 'array' }),'spec signoff': shape({ count: 'number', by: 'string', ids: 'array', evidence: 'array' }),'spec signers': shape({ added: 'boolean', by: 'string', path: 'string', initial: 'boolean' }),diff --git a/test/api.test.js b/test/api.test.jsindex 965afe14..cefc59bf 100644--- a/test/api.test.js+++ b/test/api.test.js@@ -623,6 +623,8 @@ test('[A1] command results match the catalog across roots and subcommands', () =json(box, repo, 'spec', ['show', 'G1'], 'show');json(box, repo, 'spec', ['unmet'], 'unmet');assert.equal(json(box, repo, 'spec', ['draft', 'A draft API catalogue row'], 'draft').id, 'G2');+ writeFileSync(join(box.dir, 'catalog-blueprint.json'), `${JSON.stringify({ blueprint: 1, name: 'catalog', title: 'Catalog', version: 1, rules: [{ key: 'R1', text: 'A catalog rule.', why: 'the API lists it.' }] })}\n`);+ assert.equal(json(box, repo, 'blueprint', ['add', join(box.dir, 'catalog-blueprint.json')], 'add').rows[0].status, 'draft');mkdirSync(join(repo, 'test'));writeFileSync(join(repo, 'test', 'proof.test.js'), "import { test } from 'node:test';\ntest('proof [G1]', () => {});\n");box.git(repo, 'add', 'SPEC.md', 'test/proof.test.js');diff --git a/test/blueprint.test.js b/test/blueprint.test.jsnew file mode 100644index 00000000..a6cfc612--- /dev/null+++ b/test/blueprint.test.js@@ -0,0 +1,130 @@+/** pullboard blueprint add: a blueprint lands on a board as drafts, once [S1,I1]. */+import assert from 'node:assert/strict';+import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join, resolve } from 'node:path';+import { after, test } from 'node:test';+import { runFixtureChild, runFixtureGit } from './fixture-child.js';+import { parseSpec } from '../src/spec.js';++const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');+const PUBLISHED = JSON.parse(readFileSync(resolve(import.meta.dirname, '../src/blueprints/web-app.json'), 'utf8'));+const MARKERS = ['CLAUDECODE', 'CLAUDE_CODE_ENTRYPOINT', 'CLAUDE_CODE_SESSION_ID', 'AI_AGENT', 'CODEX_THREAD_ID', 'CODEX_SESSION_ID', 'CODEX_CI', 'CODEX_SHELL'];+const DIRS = [];++after(() => { for (const dir of DIRS) rmSync(dir, { recursive: true, force: true }); });++/** A freshly initialized repo with a private board, Pullboard home and Git identity. */+function freshBoard(config = {}) {+ const dir = mkdtempSync(join(tmpdir(), 'pullboard-blueprint-'));+ DIRS.push(dir);+ // The hooks init installs call pullboard by name, so this checkout's CLI is the one on PATH.+ const bin = join(dir, 'bin');+ mkdirSync(bin);+ writeFileSync(join(bin, 'pullboard'), `#!/bin/sh\nexec '${process.execPath.replaceAll("'", "'\\''")}' '${BIN.replaceAll("'", "'\\''")}' "$@"\n`);+ chmodSync(join(bin, 'pullboard'), 0o755);+ const env = { ...process.env };+ for (const key of Object.keys(env)) if (key.startsWith('GIT_') || MARKERS.includes(key)) delete env[key];+ Object.assign(env, {+ PATH: `${bin}:${process.env.PATH}`,+ PULLBOARD_HOME: join(dir, 'home'), PULLBOARD_MACHINE_HOME: join(dir, 'machine-home'),+ GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1',+ GIT_AUTHOR_NAME: 'Blueprint fixture', GIT_AUTHOR_EMAIL: '[email protected]',+ GIT_COMMITTER_NAME: 'Blueprint fixture', GIT_COMMITTER_EMAIL: '[email protected]',+ });+ const repo = join(dir, 'repo');+ mkdirSync(repo);+ const git = (...args) => runFixtureGit(args, { cwd: repo, env });+ const run = (...args) => runFixtureChild(process.execPath, [BIN, ...args], { cwd: repo, env, encoding: 'utf8' });+ git('init', '-q', '-b', 'main');+ const init = run('init');+ assert.equal(init.status, 0, init.stdout + init.stderr);+ const file = join(repo, 'pullboard.json');+ writeFileSync(file, `${JSON.stringify({ ...JSON.parse(readFileSync(file, 'utf8')), ...config }, null, 2)}\n`);+ git('add', '-A');+ git('commit', '-q', '-m', 'chore: set up blueprint fixture');+ return { dir, repo, run, git };+}++/** Run one command with --json and return its document, failing with its output. */+function json(box, ...args) {+ const result = box.run(...args, '--json');+ assert.equal(result.status, 0, `${args.join(' ')}: ${result.stdout}${result.stderr}`);+ return JSON.parse(result.stdout);+}++test('blueprint add files a blueprint as drafts [S1,I1]', () => {+ // A fresh board: one new section, rules as drafts with reasons, questions as pending rows with defaults.+ 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 });+ 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'));+ 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);+ assert.equal(rows.length, 10, '6 rules and 4 questions');+ assert.equal(spec.rows.filter((row) => row.status === 'approved').length, 0, 'nothing is approved');+ const rules = rows.filter((row) => row.status === 'draft');+ assert.deepEqual(rules.map((row) => row.text), PUBLISHED.rules.map((rule) => `${rule.text} Why: ${rule.why}`));+ assert.equal(rules[0].text, 'Every change ships with a test that fails without it. Why: a test that passes either way proves nothing.');+ const questions = rows.filter((row) => row.status === 'pending');+ assert.deepEqual(questions.map((row) => row.text), [+ 'The app is built with: Next.js. Choices: Next.js, SvelteKit, Rails, Something else.',+ 'It deploys to: Vercel. Choices: Vercel, Netlify, Fly.io, My own server.',+ 'People sign in with: Email links. Choices: Email links, Passwords, Google, No sign-in yet.',+ 'A change is done when: It runs on a preview link. Choices: It runs on a preview link, Its tests pass, I have looked at it.',+ ]);+ const ids = Object.fromEntries(added.rows.map((row) => [row.key, row.id]));+ assert.deepEqual(added.rows.map((row) => row.id), rows.map((row) => row.id));+ const doctrine = parseSpec(readFileSync(join(box.repo, 'DOCTRINE.md'), 'utf8'));+ 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);++ // 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);+ assert.deepEqual(items.map((item) => [item.item_title, item.item_status, item.item_spec_ids, item.item_after]), [+ ['Set up the test runner with one passing test', 'open', `${ids.W1},${ids.W2}`, ''],+ ['The home page works at phone width', 'open', ids.W3, ''],+ ['Every change gets a preview link', 'open', `${ids.Q2},${ids.Q4}`, String(items[0].item_id)],+ ]);+ assert.equal(JSON.parse(readFileSync(join(box.repo, 'pullboard.json'), 'utf8')).gate, 'npm test', 'the gate is set when there was none');++ // A repeat adds nothing twice: no rows, no items, the same files.+ const specAfter = readFileSync(join(box.repo, 'SPEC.md'), 'utf8');+ const configAfter = readFileSync(join(box.repo, 'pullboard.json'), 'utf8');+ const repeat = json(box, 'blueprint', 'add', 'web-app');+ assert.deepEqual([repeat.rows, repeat.items, repeat.gate], [[], [], null]);+ assert.equal(readFileSync(join(box.repo, 'SPEC.md'), 'utf8'), specAfter);+ assert.equal(readFileSync(join(box.repo, 'pullboard.json'), 'utf8'), configAfter);+ assert.equal(json(box, 'list', '--all').items.length, 3);+ const text = box.run('blueprint', 'add', 'web-app');+ assert.match(text.stdout, /already on this board; nothing added/u);++ // A bad file is refused with its problems named, and changes nothing.+ writeFileSync(join(box.repo, 'bad.json'), `${JSON.stringify({ ...PUBLISHED, name: 'Bad Name', items: [{ key: '1', title: 'x', cites: ['Z9'] }] })}\n`);+ const bad = box.run('blueprint', 'add', 'bad.json', '--json');+ assert.equal(bad.status, 1, bad.stdout + bad.stderr);+ const error = JSON.parse(bad.stdout).error;+ assert.equal(error.code, 'BAD_BLUEPRINT');+ assert.match(error.message, /name must be lowercase/u);+ assert.match(error.message, /items\[0\]\.cites names "Z9"/u);+ writeFileSync(join(box.repo, 'broken.json'), '{ "blueprint": 1,');+ const broken = box.run('blueprint', 'add', 'broken.json', '--json');+ assert.equal(broken.status, 1);+ assert.equal(JSON.parse(broken.stdout).error.code, 'BAD_BLUEPRINT');+ const missing = box.run('blueprint', 'add', 'no-such-blueprint', '--json');+ assert.equal(JSON.parse(missing.stdout).error.code, 'NO_BLUEPRINT');+ assert.equal(readFileSync(join(box.repo, 'SPEC.md'), 'utf8'), specAfter, 'refusals leave the spec alone');+ assert.equal(json(box, 'list', '--all').items.length, 3, 'refusals add no items');++ // A board that already has a gate keeps it.+ const gated = freshBoard({ gate: 'node --test' });+ json(gated, 'blueprint', 'add', 'web-app');+ assert.equal(JSON.parse(readFileSync(join(gated.repo, 'pullboard.json'), 'utf8')).gate, 'node --test');+});