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 save writes only approved rows [S1]
Corey Olson8b3a00665ff6
diff --git a/src/blueprints.js b/src/blueprints.jsindex 3a00258b..11af0dce 100644--- a/src/blueprints.js+++ b/src/blueprints.js@@ -345,3 +345,84 @@ function insertSection(source, spec, { existing, name, lines: added }) {lines.push('', `## ${name}`, '', ...added, '');return lines.join(newline);}++// A row naming a file or a place on disk: any token with a slash or backslash between characters,+// or a home-relative path. Bare names such as Next.js are words, not paths.+const PATH_RE = /(?:^|[\s(`'"[])(?:~\/|\.{1,2}\/|\/)?[^\s/\\`'"()[\]]+[/\\][^\s`'"()[\]]+|(?:^|[\s(`'"[])~\//u;+const EMAIL_RE = /[^\s@<>()[\]`'"]+@[^\s@<>()[\]`'"]+\.[^\s@<>()[\]`'"]+/u;+const QUESTION_RE = /^(.+?): (.+)\. Choices: (.+)\.$/u;+const RULE_RE = /^(.+?) Why: (.+)$/u;++/**+ * Name why a piece of text may not leave this board, or return null when it may. Text that holds+ * a path, an email or any private name (a person, an agent, a model label or a machine) stays.+ *+ * @param {string} text+ * @param {string[]} names - Every private name known on this board and machine.+ * @returns {string | null}+ */+export function privateTextReason(text, names) {+ if (PATH_RE.test(text)) return 'a file path';+ if (EMAIL_RE.test(text)) return 'an email address';+ const lower = text.toLowerCase();+ for (const name of names) {+ const wanted = String(name ?? '').trim().toLowerCase();+ if (wanted.length < 3) continue;+ const escaped = wanted.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');+ if (new RegExp(`(?:^|[^\\p{L}\\p{N}_-])${escaped}(?:$|[^\\p{L}\\p{N}_-])`, 'u').test(lower)) return 'a private name';+ }+ return null;+}++/**+ * Turn a board's approved spec rows into a blueprint, writing only fields on an explicit+ * allow-list: the format, a name and title, a version, the gate when it is clean, each approved+ * rule's text, reason, tier and a review gate, and each answered question's ask, choices and+ * answer. Items, shouts, notes, decisions, signers, row gates, files, emails and the names of+ * people, agents and machines are never read into it. A row that would carry any of them, or a+ * rule with no "Why:" reason to carry, is left out and named in `left`, never rewritten [S1].+ *+ * @param {{ rows: any[] }} spec - The parsed SPEC.md.+ * @param {{ name: string, title: string, gate?: string, names: string[] }} board+ * @returns {{ blueprint: Blueprint, left: { id: string, reason: string }[] }}+ */+export function saveBlueprint(spec, { name, title, gate, names }) {+ const rules = [];+ const questions = [];+ const left = [];+ for (const row of spec.rows) {+ if (row.status !== 'approved') continue;+ const text = String(row.text ?? '').trim();+ const privacy = privateTextReason(text, names);+ if (privacy) { left.push({ id: row.id, reason: `it holds ${privacy}` }); continue; }+ const question = QUESTION_RE.exec(text);+ if (question) {+ const choices = question[3].split(', ').map((choice) => choice.trim()).filter(Boolean);+ const answer = question[2].trim();+ if (!choices.includes(answer)) choices.push(answer);+ if (choices.length < 2) { left.push({ id: row.id, reason: 'its question has fewer than two choices' }); continue; }+ questions.push({ key: row.id, ask: question[1].trim(), choices, default: answer });+ continue;+ }+ const rule = RULE_RE.exec(text);+ if (!rule) { left.push({ id: row.id, reason: 'it has no "Why:" reason to carry' }); continue; }+ rules.push({ key: row.id, text: rule[1].trim(), why: rule[2].trim(), tier: row.tier === 'aim' ? 'aim' : 'must', gate: 'review' });+ }+ const slug = String(name ?? '').normalize('NFKD').toLowerCase().replace(/[̀-ͯ]/gu, '').replace(/[^a-z0-9]+/gu, '-').replace(/^-|-$/gu, '') || 'board';+ const cleanTitle = String(title ?? '').trim();+ const value = {+ blueprint: BLUEPRINT_FORMAT,+ name: slug,+ title: cleanTitle && !/[\r\n|]/u.test(cleanTitle) && !privateTextReason(cleanTitle, names) ? cleanTitle : slug,+ version: 1,+ ...(gate?.trim() && !/[\r\n|]/u.test(gate) && !privateTextReason(gate.trim(), names) ? { gate: gate.trim() } : {}),+ ...(rules.length ? { rules } : {}),+ ...(questions.length ? { questions } : {}),+ };+ if (!rules.length && !questions.length) {+ throw new Refused('EMPTY_BLUEPRINT', `no approved row can leave this board${left.length ? ` (${left.length} left out: ${left.slice(0, 3).map((entry) => `${entry.id}, ${entry.reason}`).join('; ')})` : ''}; approve rules written as "<rule> Why: <reason>", then run pullboard blueprint save again`);+ }+ // Checked against the format blueprint add reads, then written exactly as allow-listed above.+ validateBlueprint(value, `${slug}.blueprint.json`);+ return { blueprint: value, left };+}diff --git a/src/cli.js b/src/cli.jsindex 068d2790..a4dd729f 100644--- a/src/cli.js+++ b/src/cli.js@@ -5,7 +5,7 @@import { createHash, randomUUID } from 'node:crypto';import { spawn, spawnSync } from 'node:child_process';import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';-import { loadavg } from 'node:os';+import { hostname, loadavg } from 'node:os';import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';import { performance } from 'node:perf_hooks';import { fileURLToPath, pathToFileURL } from 'node:url';@@ -56,7 +56,7 @@ import {standings,unmetRows,} from './spec.js';-import { bundledBlueprints, planBlueprint, readBlueprint } from './blueprints.js';+import { bundledBlueprints, planBlueprint, readBlueprint, saveBlueprint } from './blueprints.js';import { briefFiles } from './brief.js';import { checkBaseline, prepareCheckBaseline, sayCheckBaseline } from './check-baseline.js';import { retryCheckBaselines, startCheckBaseline } from './check-baseline-worker.js';@@ -2571,7 +2571,7 @@ function workCommands(io, args) {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(', ')}`);+ throw new Refused('USAGE', `pullboard blueprint add <name or file> | save [file]; bundled: ${bundledBlueprints().join(', ')}`);}await addBlueprint(ctx, board, me, readBlueprint(second, io.cwd));return 0;@@ -3488,6 +3488,22 @@ async function runCommand(argv, io) {io.say(result.linked ? `${result.link}\nrelay: sequence ${result.sequence}; ${result.behind} pending uploads${result.recovery?.pending ? `; recovery pending for sequence ${result.recovery.skip}; retry ${result.recovery.next}` : ''}` : (result.notice || 'relay off; the local board is complete'));return 0;}+ if (command === 'blueprint' && first === 'save') {+ if (rest.length) throw new Refused('USAGE', 'pullboard blueprint save [file]');+ const ctx = context(io);+ const { root, commonDir } = ctx.info;+ const project = ctx.config.project || ctx.config.name || basename(dirname(resolve(root, commonDir)));+ const file = resolve(io.cwd ?? process.cwd(), second ?? `${project}.blueprint.json`);+ if (existsSync(file)) throw new Refused('BLUEPRINT_EXISTS', `${file} already exists; name another file: pullboard blueprint save <file>`);+ const spec = loadSpec(root, ctx.config);+ const names = withBoard(ctx, (board) => privateNames(root, board, spec));+ const { blueprint, left } = saveBlueprint(spec, { name: project, title: project, gate: ctx.config.gate, names });+ writeFileSync(file, `${JSON.stringify(blueprint, null, 2)}\n`, { flag: 'wx' });+ io.result?.({ file, name: blueprint.name, rules: blueprint.rules?.length ?? 0, questions: blueprint.questions?.length ?? 0, left });+ io.say(`saved ${blueprint.rules?.length ?? 0} rules and ${blueprint.questions?.length ?? 0} answered questions to ${file}`);+ for (const entry of left) io.say(` left out ${entry.id}: ${entry.reason}`);+ return 0;+ }if (command === 'gate') {const ctx = context(io);let config;@@ -3519,6 +3535,34 @@ async function runCommand(argv, io) {}}+/**+ * Every private name a saved blueprint must never carry: each agent's id, display name, model+ * and family, the person's Git name, its parts and email, everyone who signed off or signs rows,+ * and this machine's host name. Missing sources add nothing; they never stop the save [S1].+ */+function privateNames(root, board, spec) {+ const names = new Set();+ const add = (value) => {+ const text = typeof value === 'string' ? value.trim() : '';+ if (!text) return;+ names.add(text);+ for (const part of text.split(/[\s@.<>()]+/u)) if (part.length >= 3) names.add(part);+ };+ for (const agent of store.listAgents(board)) {+ add(agent.agent_id); add(agent.agent_model); add(agent.agent_family); add(displayAgentName(agent)); add(displayAgentName(agent, 'prefix'));+ }+ for (const key of ['user.name', 'user.email']) add(tryGit(root, ['config', '--get', key]).stdout);+ for (const ident of ['GIT_AUTHOR_IDENT', 'GIT_COMMITTER_IDENT']) {+ const found = /^(.*?)\s*<([^>]*)>/u.exec(tryGit(root, ['var', ident]).stdout ?? '');+ if (found) { add(found[1]); add(found[2]); }+ }+ try { for (const record of readSignoffs(root)) add(record.by); } catch { /* An unreadable sign-off file adds no names. */ }+ for (const row of spec.rows) for (const signer of row.signers ?? []) add(signer);+ add(hostname());+ add(hostname().split('.')[0]);+ return [...names];+}+/** Retain the primary branch on every command without creating a board for global help. */function rememberTrunk(io) {let info;diff --git a/src/help.js b/src/help.jsindex ea73bbe9..cefd1782 100644--- a/src/help.js+++ b/src/help.js@@ -151,6 +151,8 @@ SpecDefaults to must and gate review.pullboard blueprint add <name or file> add a blueprint's rules and questions as drafts, and its starter itemsbundled: web-app; nothing is approved, and a repeat adds nothing+ pullboard blueprint save [file] write approved rules and answered questions as a blueprint+ never items, notes, paths, emails or names; defaults to <project>.blueprint.jsonpullboard 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@@ -176,7 +178,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', 'blueprint', 'blueprint add',+ 'roadmap', 'milestone', 'blueprint', 'blueprint add', 'blueprint save',];const HELP_GROUPS = [@@ -204,7 +206,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',+ 'blueprint add': 'pullboard blueprint add web-app', 'blueprint save': 'pullboard blueprint save','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',};diff --git a/test/blueprint.test.js b/test/blueprint.test.jsindex 75d67cea..292591eb 100644--- a/test/blueprint.test.js+++ b/test/blueprint.test.js@@ -1,11 +1,12 @@/** 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 { hostname, 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';+import { createE2eHelpers } from './e2e-helpers.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'));@@ -214,4 +215,60 @@ test('blueprint add files a blueprint as drafts after an add stopped part way [Sassert.deepEqual(retried.items.find((item) => item.key === '3').after, [first.item.item_id], 'the third starter still waits on the first');assert.equal(readFileSync(join(box.repo, 'SPEC.md'), 'utf8'), finished, 'the finished marker replaces the under-way one');assert.equal(json(box, 'blueprint', 'add', 'web-app').items.length, 0, 'and then a repeat adds nothing');++const e2e = createE2eHelpers();+after(e2e.cleanup);++test('a saved board adds back as the same rows [S1]', () => {+ const box = e2e.project();+ const machine = hostname().split('.')[0];+ box.git(box.repo, 'config', 'user.name', 'Dana Whitlock');+ box.git(box.repo, 'config', 'user.email', '[email protected]');+ const kept = [+ '- K1 [approved, must] Every change ships with a test that fails without it. Why: a test that passes either way proves nothing. | gate: web/page.test.js | signers: DW',+ '- K2 [approved, aim] Every page works at phone width. Why: a page that only works on a laptop is a bug nobody reports. | gate: review',+ '- K3 [approved, must] The app is built with: SvelteKit. Choices: Next.js, SvelteKit, Rails. | gate: review',+ ];+ const planted = [+ '- K4 [approved, must] Logs live in web/logs/app.js. Why: one place to look. | gate: review',+ '- K5 [approved, must] Escalations go to [email protected] first. Why: she owns releases. | gate: review',+ '- K6 [approved, must] Agent web-1 owns the header. Why: it wrote it. | gate: review',+ '- K7 [approved, must] Dana approves every release. Why: she carries the pager. | gate: review',+ `- K8 [approved, must] Builds run on ${machine} only. Why: it holds the signing key. | gate: review`,+ '- K9 [approved, must] The page renders without a reason. | gate: review',+ '- K10 [draft, must] A draft never leaves. Why: nobody decided it. | gate: review',+ '- K11 [pending, must] Deploys go to: Vercel. Choices: Vercel, Fly.io. | gate: review',+ ];+ writeFileSync(join(box.repo, 'SPEC.md'), `${readFileSync(join(box.repo, 'SPEC.md'), 'utf8')}\n## K · Kept\n\n<!-- pullboard-blueprint kept 1 -->\n<!-- pullboard-blueprint kept 2 adding K1=K1 K3=K3 -->\n${[...kept, ...planted].join('\n')}\n`);+ box.git(box.repo, 'add', 'SPEC.md');+ box.git(box.repo, 'commit', '-q', '-m', 'chore: plant private rows');+ const item = box.run(box.repo, 'add', 'web', 'Private item title zebra', '--specs', 'G1', '--criterion', 'secret criterion walrus');+ assert.equal(item.code, 0, item.err);+ assert.equal(box.run(box.web, 'shout', 'all', 'private shout narwhal').code, 0);++ const saved = box.run(box.repo, 'blueprint', 'save', '--json');+ assert.equal(saved.code, 0, `${saved.err}\n${saved.out}`);+ assert.deepEqual(JSON.parse(saved.out).left.map((entry) => entry.id).sort(), ['G1', 'G2', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9'], 'only clean, reasoned approved rows leave');+ const file = join(box.repo, 'repo.blueprint.json');+ const text = readFileSync(file, 'utf8');+ for (const secret of ['web/', '@', 'Dana', 'Whitlock', 'web-1', machine, 'zebra', 'walrus', 'narwhal', 'signers', 'DW', 'items', 'pullboard-blueprint', 'Logs live', 'draft never', 'Deploys go']) {+ assert.ok(!text.includes(secret), `the blueprint never carries ${JSON.stringify(secret)}`);+ }+ const blueprint = JSON.parse(text);+ assert.deepEqual(Object.keys(blueprint).sort(), ['blueprint', 'gate', 'name', 'questions', 'rules', 'title', 'version'], 'only allow-listed fields are written');+ assert.deepEqual(blueprint.rules.map((rule) => Object.keys(rule).sort()), [['gate', 'key', 'text', 'tier', 'why'], ['gate', 'key', 'text', 'tier', 'why']]);+ assert.deepEqual(blueprint.questions.map((question) => Object.keys(question).sort()), [['ask', 'choices', 'default', 'key']]);+ assert.equal(box.run(box.repo, 'blueprint', 'save', '--json').code, 1, 'an existing file is never overwritten');++ const fresh = e2e.project();+ const before = parseSpec(readFileSync(join(fresh.repo, 'SPEC.md'), 'utf8')).rows.map((row) => row.id);+ const added = fresh.run(fresh.repo, 'blueprint', 'add', file);+ assert.equal(added.code, 0, `${added.err}\n${added.out}`);+ const rows = parseSpec(readFileSync(join(fresh.repo, 'SPEC.md'), 'utf8')).rows.filter((row) => !before.includes(row.id));+ assert.deepEqual(rows.map((row) => [row.status, row.tier, row.text]), [+ ['draft', 'must', 'Every change ships with a test that fails without it. Why: a test that passes either way proves nothing.'],+ ['draft', 'aim', 'Every page works at phone width. Why: a page that only works on a laptop is a bug nobody reports.'],+ ['pending', 'must', 'The app is built with: SvelteKit. Choices: Next.js, SvelteKit, Rails.'],+ ], 'the approved rows come back as drafts, the answered question with its answer as the default');+ assert.deepEqual(JSON.parse(fresh.run(fresh.repo, 'list', '--json').out).items ?? [], [], 'a saved blueprint files no items');});