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): questions default from the repo they land in [S1,I1]
Corey Olson09e51880ae0b
diff --git a/src/blueprints.js b/src/blueprints.jsindex 184a0efd..308b6e9d 100644--- a/src/blueprints.js+++ b/src/blueprints.js@@ -29,7 +29,7 @@* waits on other items by their keys. On a board they get real ids from the section's prefix.*/import { existsSync, readdirSync, readFileSync } from 'node:fs';-import { basename, resolve } from 'node:path';+import { basename, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { Refused } from './refused.js';import { insertSectionRows, nextRowId } from './spec.js';@@ -156,8 +156,13 @@ export function validateBlueprint(value, source = 'blueprint') {line(`${at}.ask`, question.ask);if (!Array.isArray(question.choices) || question.choices.length < 2) fail(`${at}.choices`, 'must list at least two answers');else question.choices.forEach((choice, n) => line(`${at}.choices[${n}]`, choice));- line(`${at}.default`, question.default);- if (Array.isArray(question.choices) && !question.choices.includes(question.default)) fail(`${at}.default`, 'must be one of its choices');+ // A question may leave its default out: it then lands unanswered unless the repo shows one.+ if (question.default !== undefined) {+ line(`${at}.default`, question.default);+ if (Array.isArray(question.choices) && !question.choices.includes(question.default)) fail(`${at}.default`, 'must be one of its choices');+ }+ if (Array.isArray(question.choices) && question.choices.includes(NO_ANSWER)) fail(`${at}.choices`, `must not offer ${NO_ANSWER}, which marks an unanswered question`);+ if (question.detect !== undefined && !BLUEPRINT_DETECTS.includes(question.detect)) fail(`${at}.detect`, `must be one of ${BLUEPRINT_DETECTS.join(', ')}`);});const itemKeys = new Set();items.forEach((item, index) => {@@ -236,13 +241,92 @@ export function ruleText(rule) {}/**- * One question's row text: the question with its default as the answer, then every choice.+ * One question's row text: the question with its default as the answer, then every choice. A+ * question with no default reads "(choose one)" as its answer, so the person sees it is open.*- * @param {{ ask: string, choices: string[], default: string }} question+ * @param {{ ask: string, choices: string[], default?: string }} question* @returns {string}*/export function questionText(question) {- return `${question.ask.trim()}: ${question.default.trim()}. Choices: ${question.choices.map((choice) => choice.trim()).join(', ')}.`;+ return `${question.ask.trim()}: ${(question.default ?? NO_ANSWER).trim()}. Choices: ${question.choices.map((choice) => choice.trim()).join(', ')}.`;+}++/** What a question with nothing to answer it shows as its answer, so the person picks one. */+export const NO_ANSWER = '(choose one)';++/**+ * What a question's detect field can name: each reads an answer from the repo a blueprint lands in.+ * A question may carry detect ("test-runner" or "framework") and may leave its default out. When+ * the repo shows an answer that is one of the question's choices, that answer is the default; else+ * the blueprint's own default stands; else the row is filed unanswered as "<ask>: (choose one)".+ */+export const BLUEPRINT_DETECTS = ['test-runner', 'framework'];++// A test script names its runner as a command word: node --test, vitest, jest or mocha.+const SCRIPT_RUNNERS = [+ ['node:test', /(?:^|[\s;&|(])node\s+(?:[^\s;&|]+\s+)*--test(?:[\s;&|)=]|$)/u],+ ['Vitest', /(?:^|[\s;&|(/])vitest(?:[\s;&|)]|$)/u],+ ['Jest', /(?:^|[\s;&|(/])jest(?:[\s;&|)]|$)/u],+ ['Mocha', /(?:^|[\s;&|(/])mocha(?:[\s;&|)]|$)/u],+];+const PACKAGE_RUNNERS = [['Vitest', 'vitest'], ['Jest', 'jest'], ['Mocha', 'mocha']];+const PACKAGE_FRAMEWORKS = [['Next.js', 'next'], ['SvelteKit', '@sveltejs/kit']];++/**+ * The one answer a list of candidates gives, or null when it gives none or more than one, so an+ * ambiguous repo leaves the question for the person instead of guessing.+ *+ * @param {string[]} found+ * @returns {string | null}+ */+function onlyAnswer(found) {+ const distinct = [...new Set(found)];+ return distinct.length === 1 ? distinct[0] : null;+}++/**+ * Read the answers a repo already shows, by detect name: the test runner from package.json's+ * scripts.test, then its devDependencies; the framework from its dependencies (and+ * devDependencies, where SvelteKit sits). Only package.json is read: nothing runs and nothing is+ * fetched, so the same repo always gives the same answers. A missing or unreadable package.json+ * gives none.+ *+ * @param {string} root - The repository root.+ * @returns {Record<string, string>}+ */+export function repoAnswers(root) {+ const file = join(root, 'package.json');+ if (!existsSync(file)) return {};+ let manifest;+ try { manifest = JSON.parse(readFileSync(file, 'utf8')); }+ catch { return {}; }+ if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) return {};+ const table = (name) => (manifest[name] && typeof manifest[name] === 'object' && !Array.isArray(manifest[name]) ? manifest[name] : {});+ const has = (name, pkg) => Object.hasOwn(table(name), pkg);+ const script = typeof table('scripts').test === 'string' ? table('scripts').test : '';+ const answers = {};+ const runner = onlyAnswer(SCRIPT_RUNNERS.filter(([, pattern]) => pattern.test(script)).map(([answer]) => answer))+ ?? onlyAnswer(PACKAGE_RUNNERS.filter(([, pkg]) => has('devDependencies', pkg)).map(([answer]) => answer));+ if (runner) answers['test-runner'] = runner;+ const framework = onlyAnswer(PACKAGE_FRAMEWORKS.filter(([, pkg]) => has('dependencies', pkg) || has('devDependencies', pkg)).map(([answer]) => answer));+ if (framework) answers.framework = framework;+ return answers;+}++/**+ * The blueprint as it lands in a repo: each question that detects an answer the repo shows, and+ * lists that answer among its choices, gets it as its default. An answer outside the choices is+ * never used, so a row never offers what the blueprint did not.+ *+ * @param {Blueprint} blueprint+ * @param {Record<string, string>} answers - From repoAnswers.+ * @returns {Blueprint}+ */+export function landBlueprint(blueprint, answers) {+ return { ...blueprint, questions: blueprint.questions.map((question) => {+ const answer = question.detect ? answers[question.detect] : undefined;+ return answer && question.choices.includes(answer) ? { ...question, default: answer } : question;+ }) };}/**@@ -404,6 +488,7 @@ function readQuestion(text) {}}if (readings.size === 1) return { question: [...readings.values()][0] };+ if (positions(text, CHOICES).some((at) => text.slice(0, at).endsWith(`: ${NO_ANSWER}`))) return { reason: 'its question has no answer yet' };return { reason: readings.size ? 'its question can be read more than one way' : 'its answer is not one of its choices, or its choices cannot be read back exactly' };}diff --git a/src/blueprints/test-reliability.json b/src/blueprints/test-reliability.jsonindex 3f5d603b..6dbaf9d4 100644--- a/src/blueprints/test-reliability.json+++ b/src/blueprints/test-reliability.json@@ -12,6 +12,6 @@{ "key": "TR2", "text": "A flake is pinned on a change only after a run without it.", "why": "a test that fails under load looks like a broken change until it fails without that change too." }],"questions": [- { "key": "Q1", "ask": "Tests run with", "choices": ["Vitest", "Jest", "pytest", "Something else"], "default": "Vitest" }+ { "key": "Q1", "ask": "Tests run with", "choices": ["node:test", "Vitest", "Jest", "Mocha", "pytest", "Something else"], "detect": "test-runner" }]}diff --git a/src/blueprints/web-app.json b/src/blueprints/web-app.jsonindex a4c821c7..42a80984 100644--- a/src/blueprints/web-app.json+++ b/src/blueprints/web-app.json@@ -17,7 +17,7 @@{ "key": "W6", "text": "An error a person sees says what to do next.", "why": "\"something went wrong\" is a support ticket waiting to happen." }],"questions": [- { "key": "Q1", "ask": "The app is built with", "choices": ["Next.js", "SvelteKit", "Rails", "Something else"], "default": "Next.js" },+ { "key": "Q1", "ask": "The app is built with", "choices": ["Next.js", "SvelteKit", "Rails", "Something else"], "detect": "framework" },{ "key": "Q2", "ask": "It deploys to", "choices": ["Vercel", "Netlify", "Fly.io", "My own server"], "default": "Vercel" },{ "key": "Q3", "ask": "People sign in with", "choices": ["Email links", "Passwords", "Google", "No sign-in yet"], "default": "Email links" },{ "key": "Q4", "ask": "A change is done when", "choices": ["It runs on a preview link", "Its tests pass", "I have looked at it"], "default": "It runs on a preview link" }diff --git a/src/cli.js b/src/cli.jsindex 950ef125..bde7d379 100644--- a/src/cli.js+++ b/src/cli.js@@ -58,7 +58,7 @@ import {standings,unmetRows,} from './spec.js';-import { bundledBlueprints, planBlueprint, readBlueprint, saveBlueprint } from './blueprints.js';+import { bundledBlueprints, landBlueprint, planBlueprint, readBlueprint, repoAnswers, 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';@@ -2315,7 +2315,9 @@ async function addBlueprint(ctx, board, me, blueprint, { report = true } = {}) {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,+ // A question takes the answer this repo already shows as its default, read from package.json+ // only: nothing runs and nothing is fetched (#725).+ const plan = planBlueprint(landBlueprint(blueprint, repoAnswers(ctx.info.root)), { source, spec, doctrine: ctx.doctrine,existingItems: store.listItems(board, { all: true }).map((item) => ({ id: item.item_id, title: item.item_title, specIds: item.item_spec_ids ? item.item_spec_ids.split(',') : [] })),gate: String(JSON.parse(configSource).gate ?? '') });// Every starter is checked before anything is written, so a refusal leaves the board as it was.diff --git a/test/blueprint.test.js b/test/blueprint.test.jsindex 1c732492..3aca9441 100644--- a/test/blueprint.test.js+++ b/test/blueprint.test.js@@ -76,7 +76,7 @@ test('blueprint add files a blueprint as drafts [S1,I1]', () => {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.',+ 'The app is built with: (choose one). 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.',@@ -390,6 +390,70 @@ test('blueprint add files a blueprint as drafts and runs nothing it supplies [S1}});+/** The text of the one pending row in the repo's SPEC.md whose question starts with the ask. */+function pendingQuestion(repo, ask) {+ const rows = parseSpec(readFileSync(join(repo, 'SPEC.md'), 'utf8')).rows.filter((row) => row.status === 'pending' && row.text.startsWith(`${ask}: `));+ assert.equal(rows.length, 1, `one pending "${ask}" row`);+ return rows[0].text;+}++const RUNNERS = 'Choices: node:test, Vitest, Jest, Mocha, pytest, Something else.';+const FRAMEWORKS = 'Choices: Next.js, SvelteKit, Rails, Something else.';++test('a question defaults from the repo it lands in [S1,I1]', () => {+ const runners = readBlueprint('test-reliability', import.meta.dirname).questions[0].choices;+ assert.ok(['node:test', 'Mocha', 'Vitest', 'Jest', 'pytest'].every((choice) => runners.includes(choice)), 'the test-runner question offers node:test and Mocha besides Vitest, Jest and pytest');++ // init --blueprint in a node --test project: the test runner is read from scripts.test.+ const node = emptyRepo();+ writeFileSync(join(node.repo, 'package.json'), `${JSON.stringify({ name: 'app', scripts: { test: 'node --test test/' } })}\n`);+ const started = node.run('init', '--blueprint', 'test-reliability');+ assert.equal(started.status, 0, started.stdout + started.stderr);+ assert.equal(pendingQuestion(node.repo, 'Tests run with'), `Tests run with: node:test. ${RUNNERS}`, 'a node --test project defaults to node:test');++ // blueprint add in a Next.js project: the framework is read from dependencies.+ const next = freshBoard();+ writeFileSync(join(next.repo, 'package.json'), `${JSON.stringify({ name: 'web', dependencies: { next: '15.0.0', react: '19.0.0' } })}\n`);+ next.git('add', '-A');+ next.git('commit', '-q', '-m', 'chore: a Next.js app');+ json(next, 'blueprint', 'add', 'web-app');+ assert.equal(pendingQuestion(next.repo, 'The app is built with'), `The app is built with: Next.js. ${FRAMEWORKS}`, 'a Next.js project defaults to Next.js');++ // No test script: one test runner among devDependencies is the answer.+ const mocha = freshBoard();+ writeFileSync(join(mocha.repo, 'package.json'), `${JSON.stringify({ name: 'lib', devDependencies: { mocha: '10.0.0' } })}\n`);+ mocha.git('add', '-A');+ mocha.git('commit', '-q', '-m', 'chore: a Mocha library');+ json(mocha, 'blueprint', 'add', 'test-reliability');+ assert.equal(pendingQuestion(mocha.repo, 'Tests run with'), `Tests run with: Mocha. ${RUNNERS}`, 'a devDependency names the test runner');++ // A detected answer the question does not offer is never used: the blueprint's own default stands.+ const narrow = { ...PUBLISHED, name: 'narrow', title: 'Narrow', prefix: 'NAR', items: [],+ questions: [{ key: 'Q1', ask: 'Its runner is', choices: ['Vitest', 'Jest'], default: 'Jest', detect: 'test-runner' }] };+ writeFileSync(join(mocha.repo, 'narrow.json'), `${JSON.stringify(narrow)}\n`);+ json(mocha, 'blueprint', 'add', 'narrow.json');+ assert.equal(pendingQuestion(mocha.repo, 'Its runner is'), 'Its runner is: Jest. Choices: Vitest, Jest.', 'an answer outside the choices is never used');+});++test('a question with nothing to read has no default [S1,I1]', () => {+ // No package.json at all, and one that names nothing a question asks about.+ const bare = emptyRepo();+ const started = bare.run('init', '--blueprint', 'test-reliability');+ assert.equal(started.status, 0, started.stdout + started.stderr);+ assert.equal(pendingQuestion(bare.repo, 'Tests run with'), `Tests run with: (choose one). ${RUNNERS}`, 'no package.json leaves the test runner unanswered');+ const plain = freshBoard();+ writeFileSync(join(plain.repo, 'package.json'), `${JSON.stringify({ name: 'web', scripts: { test: 'make check' }, dependencies: { express: '5.0.0' } })}\n`);+ plain.git('add', '-A');+ plain.git('commit', '-q', '-m', 'chore: an app with nothing to read');+ json(plain, 'blueprint', 'add', 'web-app');+ assert.equal(pendingQuestion(plain.repo, 'The app is built with'), `The app is built with: (choose one). ${FRAMEWORKS}`, 'no known framework leaves the question unanswered');+ // A blueprint without a default for a question it cannot detect is valid and files the same way.+ const own = { ...PUBLISHED, name: 'own', title: 'Own', prefix: 'OWN', items: [], questions: [{ key: 'Q1', ask: 'Its colour is', choices: ['Red', 'Blue'] }] };+ writeFileSync(join(plain.repo, 'own.json'), `${JSON.stringify(own)}\n`);+ json(plain, 'blueprint', 'add', 'own.json');+ assert.equal(pendingQuestion(plain.repo, 'Its colour is'), 'Its colour is: (choose one). Choices: Red, Blue.');+});+const e2e = createE2eHelpers();after(e2e.cleanup);