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(init): find an older custom blueprint's kind or ask for it [S1,I1]
Corey Olsonafc2824256ea
diff --git a/docs/api.md b/docs/api.mdindex e497f365..687779f5 100644--- a/docs/api.md+++ b/docs/api.md@@ -336,7 +336,7 @@ Decision moves keep the CLI's routing: `shout` with `args.decision: true` may omOnly the coordinator runs `spec apply`. It preflights every pending row against the exact source text, refusing stale decisions before writing any file. Approval changes the status to `approved`; decline changes it to `wont` with the person's reason as the row text, preserving trailing fields. SSH-enabled approvals carry one signed `row-decision` receipt binding the file, source, replacement, decision, reason and row text. Apply copies that same receipt into `.pullboard/signoffs.jsonl`; it remains a current exact-text sign-off. Commit the changed files and receipts together.-`init` and `blueprint add` take `--blueprint` more than once, and the blueprints land in the order given. A board takes at most one product blueprint and one architecture blueprint, and any number of practice and beyond-code ones; a second product or architecture blueprint is refused with `BLUEPRINT_KIND_TAKEN`, naming both, before anything is written, whether the first is named in the same command or already on the board. A product or architecture blueprint leaves `<!-- pullboard-blueprint-kind <name> <kind> -->` beside its rows, which is how a later command finds it; a board added before that line existed is read from its bundled blueprint markers. Adding the blueprint the board already has again changes nothing and is no clash. A rule or question whose row text an earlier blueprint in the same command drafted is drafted once: the later blueprint cites that row and lists it in `shared` as `{ key, id }`. Each starter item in `items` carries `blueprint`, the name of the blueprint that filed it, and its add appends a `note` fact `blueprint starter: {"blueprint":"<name>","version":<version>,"key":"<key>"}` to the item. With several blueprints, `blueprint add` returns the first blueprint's fields with every blueprint's `rows`, `items`, `proposedLanes` and `checksNotRun`, and each one's own result in `blueprints`; `init` returns the first in `blueprint` and all of them in `blueprints`.+`init` and `blueprint add` take `--blueprint` more than once, and the blueprints land in the order given. A board takes at most one product blueprint and one architecture blueprint, and any number of practice and beyond-code ones; a second product or architecture blueprint is refused with `BLUEPRINT_KIND_TAKEN`, naming both, before anything is written, whether the first is named in the same command or already on the board. Every blueprint leaves `<!-- pullboard-blueprint-kind <name> <kind or none> -->` beside its rows, which is how a later command finds it. A blueprint an older Pullboard added has its marker alone: its kind is read from the bundled file of that name, else from `<name>.json` or `<name>.blueprint.json` at the repo root; failing both, its kind is unknown, and a product or architecture blueprint is refused with `BLUEPRINT_KIND_TAKEN` naming both until the person records the kind by adding that blueprint's file again. Adding the blueprint the board already has again changes nothing but that kind line and is no clash. A rule or question whose row text an earlier blueprint in the same command drafted is drafted once: the later blueprint cites that row and lists it in `shared` as `{ key, id }`. Each starter item in `items` carries `blueprint`, the name of the blueprint that filed it, and its add appends a `note` fact `blueprint starter: {"blueprint":"<name>","version":<version>,"key":"<key>"}` to the item. With several blueprints, `blueprint add` returns the first blueprint's fields with every blueprint's `rows`, `items`, `proposedLanes` and `checksNotRun`, and each one's own result in `blueprints`; `init` returns the first in `blueprint` and all of them in `blueprints`.To answer a pending question row (`<ask>: <default>. Choices: a, b.`, as `blueprint add` writes it), the person runs `spec answer <id> "<choice or text>"`, or the local view sends `spec-answer` with `args: {row: "B1", answer: "Postgres"}`. A listed choice matches in any case and keeps its listed spelling; other text joins the choices last. It refuses agent shells, agent worktrees and the API channel, records the same exact-row approval receipt, whose JSON `decisions` carry an `answer` read back from the signed text (never stored on its own), and the row leaves pending when the coordinator runs `spec apply`. `spec check` errors on a question that was pending at the trunk tip and now differs with no matching person decision.diff --git a/src/blueprint-set.js b/src/blueprint-set.jsindex c80301f4..45d01b69 100644--- a/src/blueprint-set.js+++ b/src/blueprint-set.js@@ -28,12 +28,15 @@ export function blueprintSlot(blueprint) {}/**- * The product and architecture blueprints a repo's board already has, read from its SPEC.md: the- * kind line each one's add leaves, and for a board added before that line existed, the marker of a- * bundled blueprint, whose kind its bundled file says. Nothing when the repo has no spec yet.+ * The blueprints a repo's board already has and the slot each fills, read from its SPEC.md: the+ * kind line each one's add leaves, with slot null for a kind a board takes any number of. A board+ * an older Pullboard set up has a blueprint's marker alone. Its kind then comes from the bundled+ * file of that name, else from its own file at the repo root (<name>.json or <name>.blueprint.json),+ * checked like any blueprint; else the slot is unknown, which may be the product or architecture+ * slot, so readBlueprints refuses either until the kind is recorded. Nothing without a spec.** @param {string} root - The repository root.- * @returns {{ name: string, slot: string }[]}+ * @returns {{ name: string, slot: string | null }[]}*/export function installedBlueprints(root) {let specFile = 'SPEC.md';@@ -45,19 +48,40 @@ export function installedBlueprints(root) {const file = join(root, String(specFile));if (!existsSync(file)) return [];const found = new Map();- const bundled = bundledBlueprints();+ const legacy = [];for (const line of readFileSync(file, 'utf8').split(/\r?\n/u)) {const kind = /^<!-- pullboard-blueprint-kind (\S+) (\S+) -->$/u.exec(line.trim());const marker = /^<!-- pullboard-blueprint (\S+) \d+(?: adding .*)? -->$/u.exec(line.trim());- if (kind && blueprintSlot({ kind: kind[2] })) found.set(kind[1], blueprintSlot({ kind: kind[2] }));- else if (marker && !found.has(marker[1]) && bundled.includes(marker[1])) {- const slot = blueprintSlot(readBlueprint(marker[1], root));- if (slot) found.set(marker[1], slot);- }+ if (kind) found.set(kind[1], blueprintSlot({ kind: kind[2] }));+ else if (marker) legacy.push(marker[1]);}+ for (const name of legacy) if (!found.has(name)) found.set(name, legacySlot(name, root));return [...found].map(([name, slot]) => ({ name, slot }));}+/**+ * The slot of a blueprint whose marker has no kind line: from the bundled file of that name, else+ * from its own file at the repo root when that file names it, else "unknown".+ *+ * @param {string} name+ * @param {string} root+ * @returns {string | null}+ */+function legacySlot(name, root) {+ if (bundledBlueprints().includes(name)) return blueprintSlot(readBlueprint(name, root));+ for (const candidate of [`${name}.json`, `${name}.blueprint.json`]) {+ if (!existsSync(join(root, candidate))) continue;+ try {+ const blueprint = readBlueprint(join(root, candidate), root);+ if (blueprint.name === name) return blueprintSlot(blueprint);+ } catch (error) {+ // A file there that is no valid blueprint says nothing about this one's kind.+ if (!(error instanceof Refused)) throw error;+ }+ }+ return 'unknown';+}+/*** Read every named blueprint, in the order given, before anything is written, so an unknown name* or a clash leaves the repository as it was. The same blueprint version named twice is read once.@@ -68,7 +92,7 @@ export function installedBlueprints(root) {* @param {string[]} references - Bundled names or paths, as --blueprint gave them.* @param {string} cwd* @param {string} command - The command to name in the next step, such as "init".- * @param {{ name: string, slot: string }[]} [installed] - The board's own, from installedBlueprints.+ * @param {{ name: string, slot: string | null }[]} [installed] - The board's own, from installedBlueprints.* @returns {{ reference: string, blueprint: import('./blueprints.js').Blueprint }[]}*/export function readBlueprints(references, cwd, command, installed = []) {@@ -77,7 +101,12 @@ export function readBlueprints(references, cwd, command, installed = []) {const blueprint = readBlueprint(reference, cwd);if (read.some((entry) => entry.blueprint.name === blueprint.name && entry.blueprint.version === blueprint.version)) continue;const slot = blueprintSlot(blueprint);- const onBoard = slot && installed.find((entry) => entry.slot === slot && entry.name !== blueprint.name);+ const onBoard = slot && installed.find((entry) => [slot, 'unknown'].includes(entry.slot) && entry.name !== blueprint.name);+ if (onBoard?.slot === 'unknown') {+ throw new Refused('BLUEPRINT_KIND_TAKEN',+ `${onBoard.name} and ${blueprint.name} may both be ${slot} blueprints: this board has ${onBoard.name}, added before Pullboard recorded a blueprint's kind, and a board takes one ${slot} blueprint; record its kind by adding its file again, which changes nothing else: pullboard blueprint add <${onBoard.name} file>`,+ `record ${onBoard.name}'s kind with pullboard blueprint add <${onBoard.name} file>, then run pullboard ${command} again`);+ }if (onBoard) {throw new Refused('BLUEPRINT_KIND_TAKEN',`${onBoard.name} and ${blueprint.name} are both ${slot} blueprints, and this board already has ${onBoard.name}; a board takes one ${slot} blueprint, so add ${blueprint.name} on a board of its own`,diff --git a/src/blueprints.js b/src/blueprints.jsindex 9664c57f..368c2666 100644--- a/src/blueprints.js+++ b/src/blueprints.js@@ -277,15 +277,34 @@ export function blueprintMarker(blueprint) {}/**- * The line a blueprint of a kind a board takes one of leaves beside its rows: its name and kind, so- * a later add or init finds which product or architecture blueprint the board already has, even- * one read from a local file (#720). Other kinds leave no such line.+ * The line every blueprint leaves beside its rows: its name and kind, or none when it names no+ * kind, so a later add or init finds which product or architecture blueprint the board already+ * has, even one read from a local file that is gone (#720).** @param {{ name: string, kind?: string }} blueprint- * @returns {string | null}+ * @returns {string}*/export function blueprintKindMarker(blueprint) {- return ['product', 'infrastructure', 'architecture'].includes(blueprint.kind) ? `<!-- pullboard-blueprint-kind ${blueprint.name} ${blueprint.kind} -->` : null;+ return `<!-- pullboard-blueprint-kind ${blueprint.name} ${blueprint.kind ?? 'none'} -->`;+}++/**+ * SPEC.md text with this blueprint's kind line after its finished marker, when the line is missing.+ * Why: a board an older Pullboard set up has the marker alone, and adding the same blueprint again+ * is how the person records its kind there; that add changes nothing else (#720).+ *+ * @param {string} source - SPEC.md's text.+ * @param {{ name: string, version: number, kind?: string }} blueprint+ * @returns {string}+ */+function withKindLine(source, blueprint) {+ const kindLine = blueprintKindMarker(blueprint);+ const parts = source.split(/(\r?\n)/u);+ if (parts.some((part) => part.trim() === kindLine)) return source;+ const at = parts.findIndex((part) => part.trim() === blueprintMarker(blueprint));+ if (at < 0) return source;+ parts.splice(at, 0, kindLine, source.includes('\r\n') ? '\r\n' : '\n');+ return parts.join('');}/**@@ -450,7 +469,10 @@ export function planBlueprint(blueprint, { source, spec, doctrine, existingItemsconst name = existingSection ? existingSection.name : `${prefix} · ${blueprint.title.trim()}`;const section = { prefix, name, isNew: !existingSection };const gateToSet = !gate?.trim() && blueprint.gate ? blueprint.gate : null;- if (marked) return { marked, resumed: false, section, rows: [], shared: [], specRows: source, specAfter: source, ids: {}, items: [], existing: {}, gate: null };+ if (marked) {+ const recorded = withKindLine(source, blueprint);+ return { marked, resumed: false, section, rows: [], shared: [], specRows: recorded, specAfter: recorded, ids: {}, items: [], existing: {}, gate: null };+ }const rows = [];const shared = [];let ids;@@ -490,7 +512,7 @@ export function planBlueprint(blueprint, { source, spec, doctrine, existingItemsrows.push({ key: question.key, id, status: 'pending', text, line: `- ${id} [pending, must] ${text} | gate: review` });}const kindLine = blueprintKindMarker(blueprint);- const kindLines = kindLine && !lines.some((text) => text.trim() === kindLine) ? [kindLine] : [];+ const kindLines = lines.some((text) => text.trim() === kindLine) ? [] : [kindLine];specRows = insertSection(source, spec, { existing: existingSection, name, lines: [...rows.map((row) => row.line), ...kindLines, blueprintAddingMarker(blueprint, ids)] });}const underWay = blueprintAddingMarker(blueprint, ids);diff --git a/src/cli.js b/src/cli.jsindex 1ffcbb8b..4ad869cf 100644--- a/src/cli.js+++ b/src/cli.js@@ -2488,6 +2488,8 @@ async function addBlueprint(ctx, board, me, blueprint, { report = true, result =io.result?.(summary);if (plan.marked) {io.say(`${blueprint.title} (version ${blueprint.version}) is already on this board; nothing added`);+ // A board an older Pullboard set up gets the blueprint's kind recorded beside its marker (#720).+ if (plan.specRows !== source) io.say(` recorded its kind (${blueprint.kind ?? 'none'}) in ${ctx.config.spec}; commit ${ctx.config.spec}`);return summary;}io.say(`added ${blueprint.title} (version ${blueprint.version}) as drafts in ${ctx.config.spec}, section ${plan.section.name}`);diff --git a/test/blueprint.test.js b/test/blueprint.test.jsindex cfac872f..b98afa62 100644--- a/test/blueprint.test.js+++ b/test/blueprint.test.js@@ -940,6 +940,7 @@ test('a second blueprint of the same kind is refused [S1,I1]', () => {writeFileSync(join(sequential.repo, 'other-product.json'), `${JSON.stringify({ ...PUBLISHED, name: 'other-product', title: 'Other product' })}\n`);json(sequential, 'blueprint', 'add', first);const spec = readFileSync(join(sequential.repo, 'SPEC.md'), 'utf8');+ assert.ok(spec.includes(`<!-- pullboard-blueprint-kind ${first.replace(/\.json$/u, '')} product -->`), 'the add records its kind beside its rows');const items = listed(sequential);const later = sequential.run('blueprint', 'add', second, '--json');assert.notEqual(later.status, 0, later.stdout);@@ -951,6 +952,68 @@ test('a second blueprint of the same kind is refused [S1,I1]', () => {assert.equal(readFileSync(join(sequential.repo, 'SPEC.md'), 'utf8'), spec);assert.equal(json(sequential, 'blueprint', 'add', 'serverless').blueprint.name, 'serverless', 'an architecture blueprint still joins a product one later');}+ // A board an older Pullboard set up: each blueprint's marker with no kind line. That Pullboard+ // wrote exactly today's add without the kind line, byte for byte, so the fixture is that (#720).+ const legacyAdd = (box, file) => {+ json(box, 'blueprint', 'add', file);+ const path = join(box.repo, 'SPEC.md');+ writeFileSync(path, readFileSync(path, 'utf8').split('\n').filter((line) => !line.startsWith('<!-- pullboard-blueprint-kind ')).join('\n'));+ assert.doesNotMatch(readFileSync(path, 'utf8'), /pullboard-blueprint-kind/u);+ };+ const refusedBoth = (box, first, second, args) => {+ const spec = readFileSync(join(box.repo, 'SPEC.md'), 'utf8');+ const items = listed(box);+ const later = box.run('blueprint', 'add', ...args, '--json');+ assert.notEqual(later.status, 0, later.stdout);+ const { error } = JSON.parse(later.stdout);+ assert.equal(error.code, 'BLUEPRINT_KIND_TAKEN');+ assert.match(error.message, new RegExp(`^${first} and ${second} `, 'u'), 'the refusal names both');+ assert.equal(readFileSync(join(box.repo, 'SPEC.md'), 'utf8'), spec, 'SPEC.md is unchanged');+ assert.equal(listed(box), items, 'no starter is filed');+ return error;+ };+ const custom = (box, name, kind, where) => {+ const file = join(where, `${name}.json`);+ writeFileSync(file, `${JSON.stringify({ ...PUBLISHED, name, title: name, kind })}\n`);+ return file;+ };+ // A custom product whose file is gone from the repo: its kind is unknown, so another product is+ // refused, naming both, with the step that records the kind. Adding its file again records it+ // and nothing else; a product is still refused after, and an architecture blueprint joins it.+ const away = freshBoard();+ const awayFile = custom(away, 'legacy-product', 'product', away.dir);+ legacyAdd(away, awayFile);+ const unknown = refusedBoth(away, 'legacy-product', 'web-app', ['web-app']);+ assert.match(unknown.next, /record legacy-product's kind with pullboard blueprint add/u, 'the next step says how to resolve it');+ const beforeRecord = readFileSync(join(away.repo, 'SPEC.md'), 'utf8');+ const items = listed(away);+ assert.equal(json(away, 'blueprint', 'add', awayFile).marked, true, 'adding its file again adds nothing');+ const recorded = readFileSync(join(away.repo, 'SPEC.md'), 'utf8');+ assert.deepEqual(recorded.split('\n').filter((line) => !beforeRecord.split('\n').includes(line)), ['<!-- pullboard-blueprint-kind legacy-product product -->'], 'it records only the kind');+ assert.equal(listed(away), items);+ refusedBoth(away, 'legacy-product', 'web-app', ['web-app']);+ assert.equal(json(away, 'blueprint', 'add', 'serverless').blueprint.name, 'serverless', 'an architecture blueprint joins the recorded product');+ // A custom product whose file is still at the repo root: its kind is read from it.+ const home = freshBoard();+ legacyAdd(home, custom(home, 'legacy-product', 'product', home.repo));+ assert.match(refusedBoth(home, 'legacy-product', 'web-app', ['web-app']).message, /are both product blueprints/u);+ // A custom practice blueprint: once its kind is recorded, a product joins it.+ const practiced = freshBoard();+ const practiceFile = custom(practiced, 'legacy-practice', 'practice', practiced.dir);+ legacyAdd(practiced, practiceFile);+ refusedBoth(practiced, 'legacy-practice', 'web-app', ['web-app']);+ json(practiced, 'blueprint', 'add', practiceFile);+ assert.equal(json(practiced, 'blueprint', 'add', 'web-app').blueprint.name, 'web-app', 'a product joins a recorded practice blueprint');+ // A bundled product from an older Pullboard is read from its bundled file; adding it again is a+ // no-op apart from recording its kind.+ const bundledLegacy = freshBoard();+ writeFileSync(join(bundledLegacy.repo, 'other-product.json'), `${JSON.stringify({ ...PUBLISHED, name: 'other-product', title: 'Other product' })}\n`);+ legacyAdd(bundledLegacy, 'web-app');+ refusedBoth(bundledLegacy, 'web-app', 'other-product', ['other-product.json']);+ const bundledItems = listed(bundledLegacy);+ assert.equal(json(bundledLegacy, 'blueprint', 'add', 'web-app').marked, true, 'the same bundled blueprint again adds nothing');+ assert.equal(listed(bundledLegacy), bundledItems);+const reinit = emptyRepo();const once = reinit.run('init', '--blueprint', 'web-app');assert.equal(once.status, 0, once.stdout + once.stderr);