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(spec): reserve draft ids across doctrine [S1,C7]
Corey Olson8b6a0d119a3f
diff --git a/src/cli.js b/src/cli.jsindex 6da76760..44095191 100644--- a/src/cli.js+++ b/src/cli.js@@ -2908,9 +2908,15 @@ async function specCommand(io, { first, second, rest, values }) {? `choose one of: ${sections.map(section => section.prefix).join(', ')}`: 'add a section heading with an id prefix such as G · Goals'}`);const { prefix } = section;- const numbered = spec.rows.map((row) => new RegExp(`^${prefix}(\\d+)$`, 'u').exec(row.id)?.[1]).filter(Boolean).map(Number);+ const malformed = [[spec.file, spec.problems], [practice.repo.file, practice.repo.problems]].find(([, problems]) => problems.length);+ if (malformed) {+ throw new Refused('SPEC_INVALID', `fix the unparsed row in ${malformed[0]} before drafting; an existing id may be ambiguous`);+ }+ const usedRows = [...spec.rows, ...practice.repo.rows];+ const usedIds = new Set(usedRows.map((row) => row.id));+ const numbered = usedRows.map((row) => new RegExp(`^${prefix}(\\d+)$`, 'u').exec(row.id)?.[1]).filter(Boolean).map(Number);let next = Math.max(0, ...numbered) + 1;- while (spec.rows.some((row) => row.id === `${prefix}${next}`)) next += 1;+ while (usedIds.has(`${prefix}${next}`)) next += 1;const id = `${prefix}${next}`;const tier = values.aim ? 'aim' : 'must';const gate = values.gate?.trim() ?? 'review';diff --git a/test/spec.test.js b/test/spec.test.jsindex 53945d88..cf520e20 100644--- a/test/spec.test.js+++ b/test/spec.test.js@@ -352,7 +352,7 @@ test('the check command is part of the frozen bar; items without one keep their* A real repo and board with an isolated registry, so JSON exercises the command's lint and history* checks rather than just serializing the parser. Its files may use the configured names.*/-function specBox(t, { specName = 'SPEC.md', practiceName = 'PRACTICE.md', practice, specSource = SPEC } = {}) {+function specBox(t, { specName = 'SPEC.md', practiceName = 'PRACTICE.md', practice, specSource = SPEC, freshInit = false } = {}) {const root = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-spec-json-')));t.after(() => rmSync(root, { recursive: true, force: true }));const bin = join(root, '.bin');@@ -380,6 +380,11 @@ function specBox(t, { specName = 'SPEC.md', practiceName = 'PRACTICE.md', practiconst init = spawnSync(process.execPath, [resolve(import.meta.dirname, '../bin/pullboard.js'), 'init'], { cwd: root, env, encoding: 'utf8' });assert.equal(init.status, 0, init.stderr);const config = JSON.parse(readFileSync(join(root, 'pullboard.json'), 'utf8'));+ if (freshInit) {+ git('add', '-A');+ git('commit', '-q', '-m', 'chore: fresh pullboard init');+ return { root, run, command, env, git, specName: config.spec, practiceName: config.practice };+ }writeFileSync(join(root, 'pullboard.json'), JSON.stringify({ ...config, spec: specName, practice: practiceName, gate: 'true', lanes: { review: { owns: [] } } }));rmSync(join(root, 'SPEC.md'), { force: true });rmSync(join(root, 'PRACTICE.md'), { force: true });@@ -435,6 +440,40 @@ test('spec draft files a row in the named section [S1,C7]', (t) => {assert.match(misplaced.stderr, /FLAG_NOT_ALLOWED.*section/u);});+/** Exercise fresh-init examples, cross-file ID reservation, and fail-closed malformed rows. */+test('spec draft never reuses an existing id [S1,C7]', (t) => {+ const fresh = specBox(t, { freshInit: true });+ const freshSpec = join(fresh.root, fresh.specName);+ assert.equal(parseSpec(readFileSync(freshSpec, 'utf8')).rows.length, 0, 'the fenced examples are not real rows');+ const first = fresh.run('draft', 'The first real requirement');+ assert.equal(first.status, 0, first.stderr);+ assert.equal(first.stdout.trim(), 'G1', 'the first real requirement receives the first available id');+ assert.deepEqual(parseSpec(readFileSync(freshSpec, 'utf8')).rows.map(({ id, status }) => [id, status]), [['G1', 'draft']]);++ const doctrine = '# Doctrine\n\n## G · Goals\n- G3 [draft] A repo doctrine id occupies this number.\n';+ const crossFile = specBox(t, { practiceName: 'DOCTRINE.md', practice: doctrine });+ const next = crossFile.run('draft', 'The next requirement');+ assert.equal(next.status, 0, next.stderr);+ assert.equal(next.stdout.trim(), 'G4', 'the allocator reserves ids present in DOCTRINE.md as well as SPEC.md');+ const specRows = parseSpec(readFileSync(join(crossFile.root, crossFile.specName), 'utf8')).rows;+ const doctrineRows = parseSpec(readFileSync(join(crossFile.root, crossFile.practiceName), 'utf8')).rows;+ assert.ok(specRows.some((row) => row.id === 'G4'));+ assert.ok(doctrineRows.some((row) => row.id === 'G3'));++ for (const source of ['spec', 'doctrine']) {+ const malformed = specBox(t, {+ ...(source === 'doctrine' ? { practiceName: 'DOCTRINE.md', practice: '# Doctrine\n\n## G · Goals\n- G3 [draft, must\n' } : {}),+ ...(source === 'spec' ? { specSource: SPEC + '\n- G3 [draft, must\n' } : {}),+ });+ const target = join(malformed.root, source === 'spec' ? malformed.specName : malformed.practiceName);+ const before = readFileSync(target);+ const refused = malformed.run('draft', 'Cannot choose safely');+ assert.notEqual(refused.status, 0, `${source} with an unparsed row-like entry refuses a draft`);+ assert.match(refused.stderr, /SPEC_INVALID.*unparsed row/u);+ assert.deepEqual(readFileSync(target), before, 'refusal leaves the source bytes unchanged');+ }+});+test('a drafted row reads as draft [S1,C7]', (t) => {const specSource = SPEC.replace('- G2 [retired] Old idea.',