Skip to content

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.

fix(spec): anchor collision baseline to coordinator [A5]

Corey Olson2f3b31ec6679
diff --git a/docs/formats.md b/docs/formats.md
index c444d90e..7d63933d 100644
--- a/docs/formats.md
+++ b/docs/formats.md
@@ -44,7 +44,7 @@ The row object returned by `parseSpec` has these fields:
### ID namespaces and collisions
-A bare id names a row in `SPEC.md`. A doctrine row is cited as `doctrine:<id>` in item spec ids and commit headers, even when a row with the same bare id exists in `SPEC.md`. `spec check` compares the current rows in `SPEC.md` and `PRACTICE.md`, and rows within either file. Collisions already present in `HEAD` are reported as known warnings; adding a colliding row is an error that names both file paths and line numbers. A commit that cites a bare id shared with a doctrine row warns that the bare id resolves to `SPEC.md`; use the `doctrine:` prefix to cite the doctrine row.
+A bare id names a row in `SPEC.md`. A doctrine row is cited as `doctrine:<id>` in item spec ids and commit headers, even when a row with the same bare id exists in `SPEC.md`. `spec check` compares the current rows in `SPEC.md` and `PRACTICE.md`, and rows within either file. Collisions already present in the primary checkout's attached branch are reported as known warnings; adding a colliding row is an error that names both file paths and line numbers. A detached primary checkout cannot establish this baseline. A commit that cites a bare id shared with a doctrine row warns that the bare id resolves to `SPEC.md`; use the `doctrine:` prefix to cite the doctrine row.
`parseSpec` also returns `grammarVersion`, equal to `SPEC_GRAMMAR_VERSION` after the file's marker has been checked.
diff --git a/docs/formats.test.js b/docs/formats.test.js
index 316611aa..8d36563d 100644
--- a/docs/formats.test.js
+++ b/docs/formats.test.js
@@ -42,7 +42,7 @@ const guide = readFileSync(new URL('./formats.md', import.meta.url), 'utf8');
test('formats guide documents collision grandfathering and doctrine citations [A5]', () => {
assert.match(guide, /A bare id names a row in `SPEC\.md`/u);
assert.match(guide, /`doctrine:<id>` in item spec ids and commit headers/u);
- assert.match(guide, /Collisions already present in `HEAD` are reported as known warnings/u);
+ assert.match(guide, /Collisions already present in the primary checkout's attached branch are reported as known warnings/u);
assert.match(guide, /adding a colliding row is an error that names both file paths and line numbers/u);
});
diff --git a/src/cli.js b/src/cli.js
index 20ef7306..b5b46b88 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -11,7 +11,7 @@ import * as store from './board.js';
import { CONFIG_FILE, COORDINATOR, loadConfig } from './config.js';
import { loadDoctrine } from './doctrine.js';
import { digestOf, gateReport, runGate, runShell } from './gate.js';
-import { bareWorktreeFinding, contains, differFromHead, git, headCommit, headTree, isClean, repoInfo, resolveCommit, tryGit, untracked } from './git.js';
+import { bareWorktreeFinding, contains, differFromHead, git, gitChildEnv, headCommit, headTree, isClean, repoInfo, resolveCommit, tryGit, untracked } from './git.js';
import {
FIX_NOTE,
applyFixers,
@@ -60,6 +60,33 @@ import { relayOff, relayOn, relayStatus, syncRelay } from './relay.js';
const PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
export const VERSION = PACKAGE.version;
+/**
+ * Read the grandfather baseline from the primary checkout's attached branch, never a builder's head.
+ *
+ * @param {string} root
+ * @param {string} path
+ * @returns {{ status: number, stdout: string }}
+ */
+function coordinatorFile(root, path) {
+ const commonDir = git(root, ['rev-parse', '--path-format=absolute', '--git-common-dir']);
+ const coordinatorRoot = dirname(commonDir);
+ const env = { ...gitChildEnv(root), GIT_NO_REPLACE_OBJECTS: '1' };
+ const branch = spawnSync('git', ['symbolic-ref', '--quiet', 'HEAD'], {
+ cwd: coordinatorRoot, env, encoding: 'utf8',
+ });
+ const ref = (branch.stdout ?? '').trim();
+ if (branch.status !== 0 || !ref.startsWith('refs/heads/')) {
+ throw new Refused(
+ 'COORDINATOR_DETACHED',
+ 'the primary checkout must be on its attached local branch to establish the collision baseline; the coordinator returns it to its branch',
+ );
+ }
+ const result = spawnSync('git', ['--no-replace-objects', 'show', `${ref}:${path}`], {
+ cwd: coordinatorRoot, env, encoding: 'utf8',
+ });
+ return { status: result.status ?? 1, stdout: result.stdout ?? '' };
+}
+
export const HELP = `pullboard ${VERSION}: the local-first work board for teams of coding agents.
Nothing ships until a second agent verifies it.
@@ -1592,7 +1619,7 @@ function specCommand(io, { first, second, rest, values }) {
for (const [, parsed] of files) assertRequiredSigners(ctx.info.root, parsed.rows);
const collisionFiles = [[ctx.config.spec, spec], ...(practice.repoExists ? [[ctx.config.practice, practice.repo]] : [])];
const previousCounts = new Map(collisionFiles.map(([name]) => {
- const previous = tryGit(ctx.info.root, ['show', `HEAD:${name}`]);
+ const previous = coordinatorFile(ctx.info.root, name);
const rows = previous.status === 0 ? parseSpec(previous.stdout, { strictGrammarVersion: false }).rows : [];
const counts = new Map();
for (const row of rows) counts.set(row.id, (counts.get(row.id) ?? 0) + 1);
diff --git a/src/hooks.js b/src/hooks.js
index 3c89edc9..abe6801b 100644
--- a/src/hooks.js
+++ b/src/hooks.js
@@ -112,12 +112,16 @@ export function commitMsgProblems(raw, { rules, spec, doctrine = null }) {
export function commitCitationWarnings(raw, { spec, doctrine }) {
const ids = citedIds(raw.split('\n')[0] ?? '').filter((id) => !id.startsWith('doctrine:'));
return ids.flatMap((id) => {
- const locations = [
- ...spec.rows.filter((row) => row.id === id).map((row) => `${spec.name ?? 'SPEC.md'}:${row.line}`),
- ...(doctrine?.repo?.rows ?? []).filter((row) => row.id === id).map((row) => `${doctrine.name}:${row.line}`),
- ];
- if (locations.length < 2) return [];
- return [`${id} is a known collision at ${locations.slice(0, 2).join(' and ')}; bare ids cite SPEC.md, use doctrine:${id} for a doctrine row`];
+ const specRows = spec.rows.filter((row) => row.id === id);
+ const doctrineRows = (doctrine?.repo?.rows ?? []).filter((row) => row.id === id);
+ if (!specRows.length || specRows.length + doctrineRows.length < 2) return [];
+ const specLocations = specRows.map((row) => `${spec.name ?? 'SPEC.md'}:${row.line}`);
+ const doctrineLocations = doctrineRows.map((row) => `${doctrine.name}:${row.line}`);
+ const locations = [...specLocations, ...doctrineLocations].slice(0, 2);
+ const resolution = doctrineRows.length
+ ? `bare ids cite SPEC.md, use doctrine:${id} for a doctrine row`
+ : 'bare ids resolve to SPEC.md, which contains duplicate rows';
+ return [`${id} is a known collision at ${locations.join(' and ')}; ${resolution}`];
});
}
diff --git a/test/spec.test.js b/test/spec.test.js
index 062eef5c..023fc7c6 100644
--- a/test/spec.test.js
+++ b/test/spec.test.js
@@ -131,7 +131,7 @@ test('spec check names both locations when ids repeat within or across configure
assert.match(duplicatePracticeResult.stdout, /PRACTICE\.md:5 P1 error: duplicate id; also appears at PRACTICE\.md:4/u);
});
-test('spec check lists collisions already present in HEAD as known warnings [A5]', (t) => {
+test('spec check lists primary-branch collisions as known warnings [A5]', (t) => {
const practice = '# Practice\n\n## G\n- G1 [draft] A known local rule.\n';
const box = specBox(t, { practice });
const result = box.run('check');
@@ -140,6 +140,39 @@ test('spec check lists collisions already present in HEAD as known warnings [A5]
assert.match(result.stdout, /PRACTICE\.md:4 G1 warning: known duplicate id; also appears at SPEC\.md:6/u);
});
+test('spec check refuses a collision committed on a linked builder after coordinator trunk [A5]', (t) => {
+ const practice = '# Practice\n\n## P\n- P1 [draft] A local rule.\n';
+ const box = specBox(t, { practice });
+ const gitAt = (cwd, ...args) => execFileSync('git', args, { cwd, env: box.env, encoding: 'utf8', stdio: 'pipe' });
+ const runAt = (cwd, ...args) => spawnSync(process.execPath, [resolve(import.meta.dirname, '../bin/pullboard.js'), ...args], {
+ cwd, env: box.env, encoding: 'utf8',
+ });
+ gitAt(box.root, 'branch', '-m', 'trunk');
+ const configPath = join(box.root, 'pullboard.json');
+ const config = JSON.parse(readFileSync(configPath, 'utf8'));
+ config.lanes.spec = { owns: ['PRACTICE.md'] };
+ writeFileSync(configPath, JSON.stringify(config));
+ gitAt(box.root, 'add', 'pullboard.json');
+ gitAt(box.root, 'commit', '-q', '-m', 'chore: add the spec fixture lane');
+ const builder = join(box.root, 'builder');
+ gitAt(box.root, 'worktree', 'add', '-q', builder, '-b', 'builder');
+ const joined = spawnSync(process.execPath, [resolve(import.meta.dirname, '../bin/pullboard.js'), 'join', 'spec'], {
+ cwd: builder, env: box.env, encoding: 'utf8',
+ });
+ assert.equal(joined.status, 0, joined.stderr);
+ writeFileSync(join(builder, 'PRACTICE.md'), practice.replace('- P1 [draft] A local rule.', '- P1 [draft] A local rule.\n- G1 [draft] Duplicate.'));
+ gitAt(builder, 'add', 'PRACTICE.md');
+ gitAt(builder, 'commit', '-q', '-m', 'chore: add a colliding row');
+ const result = runAt(builder, 'spec', 'check');
+ assert.equal(result.status, 1);
+ assert.match(`${result.stdout}${result.stderr}`, /duplicate id; also appears at PRACTICE\.md:\d+/u);
+ gitAt(box.root, 'switch', '-q', '--detach');
+ const detached = runAt(builder, 'spec', 'check');
+ assert.equal(detached.status, 1);
+ assert.match(detached.stderr, /COORDINATOR_DETACHED/u);
+ gitAt(box.root, 'switch', '-q', 'trunk');
+});
+
test('a grammar-1 repair can commit after grammar 2 was already recorded [A5,S8]', (t) => {
const root = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-grammar-history-')));
t.after(() => rmSync(root, { recursive: true, force: true }));