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(hooks): give rowless commits a real next step [S1,B26]
Corey Olsonc2c40c0e15b5
diff --git a/src/hooks.js b/src/hooks.jsindex e2903e81..762b56a1 100644--- a/src/hooks.js+++ b/src/hooks.js@@ -83,7 +83,7 @@ function headerProblems(header, rules) {const merge = /^merge\b/i.test(header) ? '. For a merge, keep the message git writes, which is exempt: git merge --no-edit' : '';return {problems: [- `write the header as type(scope): subject [ids], like "feat(store): save tasks to a file [G7]" (saw "${header.slice(0, 60)}"); types: ${rules.types.join(', ')}${merge}`,+ `write the header as type(scope): subject [ids] (saw "${header.slice(0, 60)}"); types: ${rules.types.join(', ')}${merge}`,],type: '',};@@ -100,6 +100,15 @@ function headerProblems(header, rules) {return { problems, type: match[1] };}+/** Name usable approved citations, or the real draft-and-approval path when none are available. */+function citationGuide(spec, type) {+ const ids = [...new Set(spec.rows.filter(row => row.status === 'approved')+ .map(row => row.id).filter(id => !idProblems(spec, [id]).length))].slice(0, 2);+ return ids.length+ ? `end the header with the spec rows this ${type} serves, like [${ids.join(',')}]; docs, test and chore commits may cite none`+ : `no approved spec row is available to cite; fenced format examples are not spec rows; run pullboard spec draft "<text>" for this requirement, ask the person to approve the returned id, then cite it in this ${type || 'commit'} header`;+}+/*** Every rule a commit message breaks (C1, C2). Merges, reverts and fixups git wrote are exempt.*@@ -116,12 +125,12 @@ export function commitMsgProblems(raw, { rules, spec, doctrine = null }) {const ids = citedIds(header);problems.push(...idProblems(spec, ids, doctrine).map(- (problem) => `cite only rows that exist and are live, separated by commas like [G1,G2] (${problem})`,+ (problem) => `cite only rows that exist and are live, separated by commas (${problem}); ${citationGuide(spec, type)}`,),);if (type && rules.requireIds.includes(type) && !ids.length) {problems.push(- `end the header with the spec rows this ${type} serves, like [G1,G2]; docs, test and chore commits may cite none`,+ citationGuide(spec, type),);}if (second !== undefined && second.trim()) problems.push('leave a blank line after the header');diff --git a/src/spec.js b/src/spec.jsindex 9e2ddbd7..16defe71 100644--- a/src/spec.js+++ b/src/spec.js@@ -97,11 +97,18 @@ function splitFields(rest) {export function parseSpec(source, { strictGrammarVersion = true } = {}) {const spec = { grammarVersion: SPEC_GRAMMAR_VERSION, title: '', intro: [], sections: [], rows: [], problems: [] };let section = null;- let isFenced = false;+ let fence = '';source.split(/\r?\n/).forEach((line, index) => {const lineNo = index + 1;- if (line.startsWith('```')) isFenced = !isFenced;- if (isFenced || line.startsWith('```')) return;+ const marker = /^ {0,3}(`{3,}|~{3,})(.*)$/u.exec(line);+ if (fence) {+ if (marker && marker[1][0] === fence[0] && marker[1].length >= fence.length && !marker[2].trim()) fence = '';+ return;+ }+ if (marker && (marker[1][0] === '~' || !marker[2].includes('`'))) {+ fence = marker[1];+ return;+ }const grammar = /^\uFEFF?\s*<!--\s*pullboard-grammar(?:\s+(.*?))?\s*-->\s*$/.exec(line);if (grammar) {const declared = grammar[1]?.trim() ?? '';diff --git a/test/hooks.test.js b/test/hooks.test.jsindex 4df57777..eab71bba 100644--- a/test/hooks.test.js+++ b/test/hooks.test.js@@ -3,14 +3,18 @@*/import assert from 'node:assert/strict';import { runFixtureExecFile as execFileSync, runFixtureGit } from './fixture-child.js';-import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';-import { test } from 'node:test';+import { after, test } from 'node:test';import { defaults } from '../src/config.js';import { addedLines, blockedPaths, commitCitationWarnings, commitMsgProblems, hookScript, matchesPattern, preCommitProblems, secretsIn, unwiredHookProblems } from '../src/hooks.js';import { parseSpec } from '../src/spec.js';import { Refused } from '../src/refused.js';+import { createE2eHelpers } from './e2e-helpers.js';++const e2e = createE2eHelpers();+after(e2e.cleanup);const SPEC = { ...parseSpec('## G\n- G1 [approved, must] One. | gate: t\n- G2 [retired] Gone.\n'), name: 'SPEC.md' };const RULES = defaults().commits;@@ -81,7 +85,7 @@ test('a clean header citing a live id passes [C1, C2]', () => {});test('feat and fix cite ids; cited ids exist and are not retired [C2]', () => {- assert.match(check('feat(web): add the page')[0], /end the header with the spec rows this feat serves, like \[G1,G2\]/);+ assert.match(check('feat(web): add the page')[0], /end the header with the spec rows this feat serves, like \[G1\]/);assert.match(check('fix: patch [G9]')[0], /G9 is not in SPEC.md/);assert.match(check('fix: patch [G2]')[0], /G2 is retired/);});@@ -109,7 +113,8 @@ test('header format, length, case and period [C1]', () => {'start the subject with a lowercase letter (saw "Explain lanes.")','remove the period at the end of the subject',]);- assert.match(check('feat: x [G K P D]')[0], /cite only rows that exist and are live, separated by commas like \[G1,G2\]/);+ assert.match(check('feat: x [G K P D]')[0], /cite only rows that exist and are live, separated by commas \(/);+ assert.match(check('feat: x [G K P D]')[0], /like \[G1\]/, 'invalid-id guidance names only an approved row that exists');assert.deepEqual(check('docs: explain lanes\nsecond line'), ['leave a blank line after the header']);});@@ -194,3 +199,57 @@ test('a refused merge message points to the message git writes, which is exemptassert.match(check('merge: include store date validation')[0], /For a merge, keep the message git writes, which is exempt: git merge --no-edit/);assert.deepEqual(check("Merge branch 'store/1'"), []);});+++test('a spec-less feature commit is told a path that works [S1,B26]', () => {+ const box = e2e.sandbox();+ const root = join(box.dir, 'newcomer');+ mkdirSync(root);+ box.git(root, 'init', '-q', '-b', 'main');+ const initialized = box.run(root, 'init');+ assert.equal(initialized.code, 0, initialized.err || initialized.out);+ const source = readFileSync(join(root, 'SPEC.md'), 'utf8');+ assert.match(source, /- G1 \[draft, must\]/u, 'the fresh spec visibly contains a fenced format example');+ const listed = box.run(root, 'spec', '--json');+ assert.equal(listed.code, 0, listed.err || listed.out);+ assert.deepEqual(JSON.parse(listed.out).rows.filter(row => row.file === 'SPEC.md'), [], 'the example is not a real row');+ assert.equal(box.run(root, 'lane', 'add', 'app', '--owns', 'app/').code, 0);+ mkdirSync(join(root, 'app'));+ box.git(root, 'add', '-A');+ box.git(root, 'commit', '-q', '-m', 'chore: set up the private board');+ const added = box.run(root, 'add', 'app', 'Build the first useful thing', '--criterion', 'The first useful thing works.', '--json');+ assert.equal(added.code, 0, added.err || added.out);+ assert.equal(JSON.parse(added.out).item.item_spec_ids, '');+ writeFileSync(join(root, 'app/first.txt'), 'first useful thing\n');+ box.git(root, 'add', '--', 'app/first.txt');+ const missing = box.tryGit(root, 'commit', '-q', '-m', 'feat(app): build the first useful thing');+ assert.notEqual(missing.status, 0);+ assert.match(missing.stderr, /pullboard spec draft "<text>"/u, 'the actual installed hook names a supported command');+ assert.match(missing.stderr, /person.*approv/iu, 'the next step honestly names the person approval');+ assert.doesNotMatch(missing.stderr, /like \[G1,G2\]|as a chore|use chore/iu, 'the hook neither invents ids nor mislabels the feature');+ const malformed = box.tryGit(root, 'commit', '-q', '-m', 'Added the first useful thing');+ assert.notEqual(malformed.status, 0);+ assert.doesNotMatch(malformed.stderr, /\[G7\]/u, 'format guidance also avoids an invented citation');+ const copiedExample = box.tryGit(root, 'commit', '-q', '-m', 'feat(app): build the first useful thing [G1]');+ assert.notEqual(copiedExample.status, 0);+ assert.match(copiedExample.stderr, /G1 is not in SPEC\.md/u);+ assert.match(copiedExample.stderr, /fenced.*example.*not.*rows/iu, 'the refusal explains why the visible format example is not a row');+ const drafted = box.run(root, 'spec', 'draft', 'The first useful thing works.', '--json');+ assert.equal(drafted.code, 0, drafted.err || drafted.out);+ const id = JSON.parse(drafted.out).id;+ for (const args of [['spec', 'approve', id], ['spec', 'apply']]) {+ const result = box.run(root, ...args);+ assert.equal(result.code, 0, result.err || result.out);+ }+ box.git(root, 'add', '-A');+ const committed = box.tryGit(root, 'commit', '-q', '-m', `feat(app): build the first useful thing [${id}]`);+ assert.equal(committed.status, 0, committed.failure || committed.stderr || committed.stdout);++ for (const [open, close] of [['```markdown', '```'], ['~~~markdown', '~~~'], [' ````markdown', ' ````'], ['````markdown\n```', '````']]) {+ const fenced = parseSpec(`## G\n${open}\n- G1 [approved, must] Example only. | gate: true\n${close}\n- R9 [approved, must] Real requirement. | gate: true\n`);+ assert.deepEqual(fenced.rows.map(row => row.id), ['R9'], `only real rows are read around ${open}`);+ const advice = commitMsgProblems('feat(app): add a feature', { rules: RULES, spec: { ...fenced, name: 'SPEC.md' } });+ assert.match(advice.join('\n'), /\[R9\]/u, 'an approved board names an id that really exists');+ assert.doesNotMatch(advice.join('\n'), /\[G1(?:,G2)?\]/u, 'a fenced example is never suggested as a citation');+ }+});