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): lane and coordinator drafts never share a row id [S1,B26]
Corey Olsonf80bc22f9c14
diff --git a/src/cli.js b/src/cli.jsindex cba63e13..2d1a10ef 100644--- a/src/cli.js+++ b/src/cli.js@@ -104,7 +104,9 @@ import {} from './gate.js';import { draftRow } from './spec-draft.js';import {+ clashingRowDrafts,pendingRowDrafts,+ trunkRowIds,withRowDrafts,} from './row-drafts.js';import { gateWaitReporter } from './gate-wait.js';@@ -3991,12 +3993,12 @@ async function specCommand(io, { first, second, rest, values }) {const tier = values.aim ? 'aim' : 'must';if (!ctx.info.isMain) {// A lane cannot write SPEC.md, so its draft is recorded on the board and cited at once; spec apply writes it (#878).- const entry = await withBoard(ctx, async (board) => ordered(ctx, board, 'draftSpecRow', [{ agentId: store.agentAt(board, ctx.info.root)?.agent_id, row: draftRow(ctx.info.root, ctx.config, { target: 'spec', text: second.trim(), gate: values.gate?.trim() ?? 'review', tier, section: values.section, taken: store.rowDrafts(board).map((draft) => draft.id), write: false }).row }]));+ const entry = await withBoard(ctx, async (board) => ordered(ctx, board, 'draftSpecRow', [{ agentId: store.agentAt(board, ctx.info.root)?.agent_id, row: draftRow(ctx.info.root, ctx.config, { target: 'spec', text: second.trim(), gate: values.gate?.trim() ?? 'review', tier, section: values.section, taken: [...store.rowDrafts(board).map((draft) => draft.id), ...trunkRowIds(ctx.info.root, primaryCheckoutRoot(ctx.info), ctx.config)], write: false }).row }]));io.result?.({ id: entry.id, row: entry });io.say(entry.id);return 0;}- const { id, row } = draftRow(ctx.info.root, ctx.config, { target: 'spec', text: second.trim(), gate: values.gate?.trim() ?? 'review', tier, section: values.section });+ const { id, row } = draftRow(ctx.info.root, ctx.config, { target: 'spec', text: second.trim(), gate: values.gate?.trim() ?? 'review', tier, section: values.section, taken: (hookRead(ctx, (board) => store.rowDrafts(board)) ?? []).map((draft) => draft.id) });io.result?.({ id, row });io.say(id);return 0;@@ -4051,6 +4053,7 @@ async function specCommand(io, { first, second, rest, values }) {// A lane's board drafts (#878) reach SPEC.md as draft rows at their own ids; the person approves them there as before.const drafted = pendingRowDrafts(loadSpec(ctx.info.root, ctx.config), store.rowDrafts(board)).map((draft) => draftRow(ctx.info.root, ctx.config, { target: 'spec', text: draft.text, gate: draft.gate, tier: draft.tier, section: /^(.*?)\d+$/u.exec(draft.id)[1], id: draft.id }));drafted.forEach((row) => io.say(`${row.file}: ${row.id} drafted from a lane, for the person to approve`));+ clashingRowDrafts(loadSpec(ctx.info.root, ctx.config), store.rowDrafts(board)).forEach((draft) => io.say(`${ctx.config.spec}: ${draft.id} holds other text, so the draft by ${draft.by} was not written; shout ${draft.by} to run pullboard spec draft again and cite the new id`));const plan = planRowApply(ctx.info.root, ctx.config, store.rowDecisions(board));writeRowApply(ctx.info.root, plan);let applied;diff --git a/src/engine.js b/src/engine.jsindex 2713c542..d825afd7 100644--- a/src/engine.js+++ b/src/engine.js@@ -20,7 +20,14 @@ import {} from './trunk-conflict.js';import { CHECK_ACCEPT_ENGINE } from './check-accept.js';import { HEALTH_SENTINEL_ENGINE } from './health-receipts.js';-import { CAUSE_ENGINE, ENGINE_VERSION, VERIFIER_STANDING_ENGINE, VERDICT_REVIEW_ENGINE, MILESTONE_RANK_ENGINE, ROW_DRAFT_ENGINE } from './machine.js';+import {+ CAUSE_ENGINE,+ ENGINE_VERSION,+ VERIFIER_STANDING_ENGINE,+ VERDICT_REVIEW_ENGINE,+ MILESTONE_RANK_ENGINE,+ ROW_DRAFT_ENGINE,+} from './machine.js';import {MILESTONE_SHIP_ENGINE,canonicalMilestoneTarget,diff --git a/src/row-drafts.js b/src/row-drafts.jsindex fded0107..c61d0540 100644--- a/src/row-drafts.js+++ b/src/row-drafts.js@@ -12,6 +12,14 @@ import {PERSON,} from './board.js';import { Refused } from './refused.js';+import { spawnSync } from 'node:child_process';+import { loadDoctrine } from './doctrine.js';+import {+ loadSpec,+ parseSpec,+} from './spec.js';+import { cleanGitEnvironment } from './git.js';+import { trunkRef } from './trusted-policy.js';/** The board's recorded row drafts, oldest first. */export function rowDrafts(board) {@@ -42,12 +50,38 @@ export function draftSpecRow(board, { agentId, row }) {});}+/**+ * Row ids the trunk holds that a lane's own files may lack: the primary checkout's working spec and+ * doctrine, which carry a coordinator's uncommitted draft, and the spec on the trunk branch, for a+ * primary checkout on another computer. A lane's new id skips them, so a lane draft and a coordinator+ * draft never share an id, whichever comes first.+ *+ * @param {string} root the lane worktree+ * @param {string | null} mainRoot the primary checkout on this computer, if any+ * @param {any} config+ */+export function trunkRowIds(root, mainRoot, config) {+ const ids = [];+ if (mainRoot) ids.push(...loadSpec(mainRoot, config).rows, ...loadDoctrine(mainRoot, config).repo.rows);+ const shown = spawnSync('git', ['show', `${trunkRef(root) ?? 'main'}:${config.spec}`], { cwd: root, env: cleanGitEnvironment(), encoding: 'utf8' });+ if (shown.status === 0) ids.push(...parseSpec(shown.stdout, { strictGrammarVersion: false }).rows);+ return ids.map((row) => row.id);+}+/** Board drafts that SPEC.md does not have yet, for spec apply to write. */export function pendingRowDrafts(spec, drafts) {const present = new Set(spec.rows.map((row) => row.id));return drafts.filter((draft) => !present.has(draft.id));}+/**+ * Board drafts whose id SPEC.md holds as a draft row with other text: a proposal that lost its id to+ * another writer. spec apply names each one instead of treating it as written.+ */+export function clashingRowDrafts(spec, drafts) {+ return drafts.filter((draft) => spec.rows.some((row) => row.id === draft.id && row.status === 'draft' && row.text !== draft.text));+}+/** A parsed spec with the board's pending drafts added as draft rows, for readers deciding whether an id is live. */export function withRowDrafts(spec, drafts) {const pending = pendingRowDrafts(spec, drafts ?? []);diff --git a/test/hooks.test.js b/test/hooks.test.jsindex dd8013ac..f7dab2fc 100644--- a/test/hooks.test.js+++ b/test/hooks.test.js@@ -288,3 +288,35 @@ test('a lane agent drafts a row and cites it without leaving its lane [S1,B26]',assert.equal(box.run(box.repo, 'spec', 'apply').code, 0);assert.match(row(), /\[approved, must\]/u, 'the approved row is applied');});++test('a lane draft and a coordinator draft never share an id, in either order [S1,B26]', () => {+ const box = e2e.project('pullboard spec check');+ const draft = (cwd, text) => {+ const result = box.run(cwd, 'spec', 'draft', text);+ assert.equal(result.code, 0, result.out + result.err);+ return result.out.trim().split('\n').at(-1);+ };+ // Lane first: the coordinator's next id skips the lane's board draft.+ const laneFirst = draft(box.web, 'A lane row drafted first');+ const coordinatorAfter = draft(box.repo, 'A coordinator row drafted after');+ // Coordinator first, committed through the installed hooks: the lane's older files lack it, and its next id still skips it.+ const coordinatorFirst = draft(box.repo, 'A coordinator row drafted first');+ box.git(box.repo, 'add', 'SPEC.md');+ const committed = box.tryGit(box.repo, 'commit', '-q', '-m', `docs(spec): draft two rows [${coordinatorAfter},${coordinatorFirst}]`);+ assert.equal(committed.status, 0, committed.stderr);+ const laneAfter = draft(box.web, 'A lane row drafted after');+ const ids = [laneFirst, coordinatorAfter, coordinatorFirst, laneAfter];+ assert.equal(new Set(ids).size, 4, `every proposal keeps its own id: ${ids.join(', ')}`);+ assert.equal(box.tryGit(box.web, 'status', '--porcelain').stdout, '', 'the lane edits no file outside its lane');++ const applied = box.run(box.repo, 'spec', 'apply');+ assert.equal(applied.code, 0, applied.out + applied.err);+ assert.doesNotMatch(applied.out, /holds other text/u);+ const spec = readFileSync(join(box.repo, 'SPEC.md'), 'utf8');+ for (const [id, text] of [[laneFirst, 'A lane row drafted first'], [coordinatorAfter, 'A coordinator row drafted after'],+ [coordinatorFirst, 'A coordinator row drafted first'], [laneAfter, 'A lane row drafted after']]) {+ assert.ok(spec.includes(`- ${id} [draft, must] ${text} | gate: review`), `${id} keeps its own text as a draft after apply`);+ }+ const approve = box.run(box.web, 'spec', 'approve', laneAfter);+ assert.notEqual(approve.code, 0, 'a lane cannot approve its own draft; the person does');+});