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): every row writer reserves its id on the board first [S1,B26]
Corey Olson691e2bffa1a5
diff --git a/docs/formats.md b/docs/formats.mdindex 90751d33..0bc8057e 100644--- a/docs/formats.md+++ b/docs/formats.md@@ -148,7 +148,7 @@ Engine 42 adds ordered `recordHealthFindings` observations. A scan retains its bEngine 52 reopens an accepted item that conflicts with the trunk for a main merge. A `reopen` move may carry `conflict: {files, trunk}`: the files that conflict, and the full trunk commit they conflict with. The CLI takes one exact path per `--conflict <file>` flag and splits or trims nothing inside it, so a path with spaces or commas is named as Git reports it in `git merge-tree --write-tree --name-only -z`; `files` holds those exact paths, nonempty and without NUL. The CLI fills `trunk` from Git and refuses `NOT_CONFLICTING` when the accepted commit merges cleanly, or `CONFLICT_FILES` when a named file is not one Git reports as conflicting. The board refuses `NOT_ACCEPTED` unless the item is verified with an accept at its commit, and `BAD_CONFLICT` for a malformed conflict. A conflict needs no note and no landing failure; the event records `supersedes`, the accept it sets aside, `conflict`, and `cause: "refusal:MERGE_CONFLICT"`, never `landingFailure`, so rigor counts it as a merge conflict and never as a failing test. The item reads `needs main merge` until its next verdict, and the re-review checks the frozen check at the new head. A `reopen` move carrying `conflict` requires engine 52, and older engines refuse it with `RELAY_MOVE` before changing their board or cursor; a board replaying an older engine refuses it with `ENGINE_VERSION`. Moves recorded under engines 51 and earlier replay unchanged. The unlanded feature’s previous allocations were 36 and 47; it moved to 52 after the trunk reached engine 50 and milestone withdrawal was allocated engine 51, preserving every landed feature’s engine.-Engine 55 (`ROW_DRAFT_ENGINE`) adds `draftSpecRow`: an agent in a lane worktree records a drafted spec row on the board, since SPEC.md is the coordinator's file and a lane cannot write it. The move carries `row: {id, text, gate, tier, section}`; the sender plans the id across SPEC.md, the doctrine file and the board's earlier drafts, and the board refuses `ROW_ID_TAKEN` for an id it already holds. Until spec apply writes it, the commit-msg hook and `spec check` read a board draft as a draft row, so a lane cites the returned id at once and its worktree stays clean. The coordinator's `spec apply` writes each pending board draft into SPEC.md at its own id, and the person approves it there as before; a draft counts as applied once SPEC.md has its id. A move carrying `draftSpecRow` requires engine 55, and older engines refuse it before changing their board or cursor. Engine 54 is the strong-rejection notice above; engine 53 is allocated to another change.+Engine 55 (`ROW_DRAFT_ENGINE`) adds `draftSpecRow`: an agent in a lane worktree records a drafted spec row on the board, since SPEC.md is the coordinator's file and a lane cannot write it. The move carries `row: {id, text, gate, tier, section, target}` and `written`. Every writer of a new row reserves its id with this move, in one write transaction, before any file names the id: a lane's spec draft, the main checkout's spec draft and doctrine rulings, Rigor and blueprints. The sender plans the id from its files; the board takes that id or the next number after it that no draft holds, so writers that planned the same id at the same moment get distinct ids, and the same row again keeps the id it reserved. `written: true` marks a writer that puts the row in its own file now; only unwritten spec drafts, which come from lanes, are written by spec apply. Until spec apply writes it, the commit-msg hook and `spec check` read a board draft as a draft row, so a lane cites the returned id at once and its worktree stays clean. The coordinator's `spec apply` writes each pending board draft into SPEC.md at its own id, and the person approves it there as before; a draft counts as applied once SPEC.md has its id. A move carrying `draftSpecRow` requires engine 55, and older engines refuse it before changing their board or cursor. Engine 54 is the strong-rejection notice above; engine 53 is allocated to another change.The CLI declares its engine in every relay request's `X-Pullboard-Engine` header.A linked board requires at least engine 48 after issuing any agent token or machine credential, including@@ -372,7 +372,7 @@ The `event` table is a SQLite schema object governed by `SCHEMA_VERSION`; its ap| `pass` | coordinator | `shout`, `to`, `decision`, `request`, `answers` || `answer` | answerer | `shout`, `to`, `decision`, `request`, `answers`, `outcome`, `channel`, engine-20 `implies`, `supersedes` || `row_decision` | person | `record`, `channel` |-| `row_draft` | builder | engine-55 `row` |+| `row_draft` | builder | engine-55 `row`, `written` || `row_apply` | coordinator | `events` |<!-- events:end -->diff --git a/src/cli.js b/src/cli.jsindex 99fd9818..3af68cd2 100644--- a/src/cli.js+++ b/src/cli.js@@ -336,7 +336,7 @@ import {launchBackgroundView,reportView,} from './background-view.js';-import { rigorDraft } from './rigor-draft.js';+import { rigorDraftCommand } from './rigor-draft.js';import { serveApi } from './api.js';import { watchCommand } from './watch.js';import { serveMcp } from './mcp.js';@@ -942,6 +942,17 @@ function withBoard(ctx, work) {return result;}+/**+ * Reserve a new row's id on the board in one write transaction before any file names it, so writers+ * that plan the same id at the same moment get distinct ids (#878). written: the caller writes the row+ * into its own file now; otherwise it is a lane draft that spec apply writes. With no board yet there is+ * no other writer, and the planned id stands.+ */+async function reserveRow(ctx, row, written) {+ if (!existsSync(ctx.file)) return row;+ return withBoard(ctx, async (board) => ordered(ctx, board, 'draftSpecRow', [{ agentId: store.agentAt(board, ctx.info.root)?.agent_id ?? whoAmI(ctx, board).id, row, written }]));+}+/** Dispatch a board mutation locally, or seal it before any linked replica applies it. */async function ordered(ctx, board, operation, args) {// Every engine-27 registration records the seat that made it: the coordinator from the main@@ -2630,7 +2641,7 @@ function readCommands(io, { first, second, rest, values }) {return 0;},rigor: () => {- if (first === 'draft') return rigorDraftHere(io, { second, rest, values });+ if (first === 'draft') { const ctx = context(io); return rigorDraftCommand(io, { second, rest, values }, { root: ctx.info.root, config: ctx.config, read: () => withBoard(ctx, (board) => ({ events: store.events(board), actor: whoAmI(ctx, board).id })), reserve: (row) => reserveRow(ctx, row, true) }); }if (first || second || rest.length) throw new Refused('USAGE', 'pullboard rigor takes no arguments; to draft a rule: pullboard rigor draft <key> "<rule>" --check "<command>" --red <commit> --green <commit>');const ctx = context(io);const report = withBoard(ctx, (board) => rigorReport(store.events(board), { person: store.PERSON }));@@ -2649,28 +2660,6 @@ function readCommands(io, { first, second, rest, values }) {};}-/**- * Draft a rule from a repeated cause (#714): prove its check red then green on real commits, then- * write the pending row or rows through the spec draft writer. Nothing is approved or applied; the- * person approves the rows in pullboard view or with pullboard spec approve [D1,D3,S1].- *- * @param {any} io- * @param {{ second?: string, rest: string[], values: any }} args- * @returns {Promise<number>}- */-async function rigorDraftHere(io, { second, rest, values }) {- if (rest.length > 1) throw new Refused('USAGE', 'pullboard rigor draft <key> "<rule>" --check "<command>" --red <commit> --green <commit> [--section <letter>]');- const ctx = context(io);- const { events, actor } = withBoard(ctx, (board) => ({ events: store.events(board), actor: whoAmI(ctx, board).id }));- const result = await rigorDraft({ root: ctx.info.root, config: ctx.config, events, person: store.PERSON, agent: actor, reserved: () => (hookRead(ctx, (board) => store.rowDrafts(board)) ?? []).map((draft) => draft.id) },- { key: second, text: rest[0], check: values.check, red: values.red, green: values.green, section: values.section });- io.result?.(result);- io.say(`proved ${result.key}: red at ${result.proof.red.commit.slice(0, 12)} (${result.proof.red.problems} problem lines, exit ${result.proof.red.exit}), green at ${result.proof.green.commit.slice(0, 12)} (exit ${result.proof.green.exit})`);- for (const draft of result.drafts) io.say(`${draft.file}: ${draft.line}`);- io.say(`next: the person approves ${result.drafts.map((draft) => draft.id).join(' or ')} in pullboard view or with pullboard spec approve; commit ${[...new Set(result.drafts.map((draft) => draft.file))].join(' and ')}`);- return 0;-}-/*** Submit: a clean tree, nothing untracked, the gate green at HEAD, then the board (V4).*@@ -2883,6 +2872,8 @@ async function addBlueprint(ctx, board, me, blueprint, { report = true, result ='run the same pullboard blueprint add from the main checkout, where the coordinator works');}for (const { item } of starters) store.validateItemAddition(board, item);+ // Each new row's id is reserved on the board before SPEC.md names it; if another writer took one first, this add runs again for the next ids (#878).+ for (const row of plan.rows) if ((await ordered(ctx, board, 'draftSpecRow', [{ agentId: me.id, row: { id: row.id, text: row.text, target: 'spec' }, written: true }])).id !== row.id) throw new Refused('ROW_ID_TAKEN', `${row.id} was just reserved by another writer; run the same pullboard blueprint add again for the next free id`);const files = [];if (plan.specRows !== source) files.push({ file: ctx.config.spec, before: source, after: plan.specRows });if (plan.gate) {@@ -3984,21 +3975,19 @@ async function specCommand(io, { first, second, rest, values }) {withBoard(ctx, (board) => {if (!ctx.info.isMain || whoAmI(ctx, board).id !== COORDINATOR) throw new Refused('COORDINATOR_ONLY', 'only the coordinator proposes standing rulings; ask your coordinator to run spec draft --doctrine --source');});- const result = proposeDoctrine(ctx, values, second, (hookRead(ctx, (board) => store.rowDrafts(board)) ?? []).map((draft) => draft.id));+ const planned = proposeDoctrine(ctx, values, second, { reserved: (hookRead(ctx, (board) => store.rowDrafts(board)) ?? []).map((draft) => draft.id), write: false });+ const result = proposeDoctrine(ctx, values, second, { id: (await reserveRow(ctx, { ...planned.row, target: 'doctrine' }, true)).id });io.result?.(result);io.say(result.id);return 0;}if (values.source !== undefined) throw new Refused('FLAG_NOT_ALLOWED', 'spec draft --source belongs to --doctrine; use both when proposing a ruling');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), ...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, taken: (hookRead(ctx, (board) => store.rowDrafts(board)) ?? []).map((draft) => draft.id) });+ const plan = draftRow(ctx.info.root, ctx.config, { target: 'spec', text: second.trim(), gate: values.gate?.trim() ?? 'review', tier, section: values.section, write: false,+ taken: [...(hookRead(ctx, (board) => store.rowDrafts(board)) ?? []).map((draft) => draft.id), ...(ctx.info.isMain ? [] : trunkRowIds(ctx.info.root, primaryCheckoutRoot(ctx.info), ctx.config))] });+ // A lane cannot write SPEC.md, so its reservation is the draft, cited at once and written by spec apply; the main checkout writes its row now (#878).+ const entry = await reserveRow(ctx, plan.row, ctx.info.isMain);+ const { id, row } = ctx.info.isMain ? draftRow(ctx.info.root, ctx.config, { target: 'spec', text: plan.row.text, gate: plan.row.gate, tier, section: values.section, id: entry.id }) : { id: entry.id, row: entry };io.result?.({ id, row });io.say(id);return 0;diff --git a/src/doctrine-rulings.js b/src/doctrine-rulings.jsindex 983e2c67..f90a2c1a 100644--- a/src/doctrine-rulings.js+++ b/src/doctrine-rulings.js@@ -144,10 +144,11 @@ export function resumeDoctrineNotes(info, doctrine) {* @param {any} ctx the CLI context* @param {{ source?: string, section?: string, aim?: boolean, gate?: string }} values* @param {string} text the ruling- * @param {string[]} [reserved] ids the board's row drafts hold, which a new ruling skips (#878)+ * @param {{ id?: string, reserved?: string[], write?: boolean }} [options] id: the id the board reserved, to write+ * at (#878); reserved: ids the board's drafts hold, which a planned id skips; write false plans without writing.* @returns {{ id: string, row: { id: string, status: string, tier: string, text: string, gate: string, section: string } }}*/-export function proposeDoctrine(ctx, values, text, reserved = []) {+export function proposeDoctrine(ctx, values, text, { id: fixed, reserved = [], write = true } = {}) {const doctrine = ctx.doctrine;if (!doctrine.repoExists) throw new Refused('NO_SPEC', `no ${doctrine.name}; run pullboard init before proposing doctrine`);if (doctrine.repo.problems.length) throw new Refused('SPEC_INVALID', `fix the unparsed row in ${doctrine.name} before proposing a ruling`);@@ -158,11 +159,13 @@ export function proposeDoctrine(ctx, values, text, reserved = []) {if (!section && values.section) throw new Refused('SPEC_SECTION', `unknown section "${prefix}" in ${doctrine.name}; use a declared section or omit --section for rulings`);const used = [...loadSpec(ctx.info.root, ctx.config).rows, ...doctrine.rows, ...reserved.map((id) => ({ id }))];const numbers = used.map(row => new RegExp(`^${prefix}(\\d+)$`, 'u').exec(row.id)?.[1]).filter(Boolean).map(Number);- const id = `${prefix}${Math.max(0, ...numbers) + 1}`;+ const id = fixed ?? `${prefix}${Math.max(0, ...numbers) + 1}`;const tier = values.aim ? 'aim' : 'must';const gate = values.gate?.trim() ?? 'review';const ruling = `${text.trim()} Source: ${values.source.trim()}`;const row = `- ${id} [draft, ${tier}] ${ruling} | gate: ${gate}`;+ const planned = { id: 'doctrine:' + id, row: { id, status: 'draft', tier, text: ruling, gate, section: section?.name ?? 'DR · Rulings' } };+ if (!write) return planned;const source = readFileSync(doctrine.repo.file, 'utf8');const newline = source.includes('\r\n') ? '\r\n' : '\n';const lines = source.split(/\r?\n/u);@@ -177,5 +180,5 @@ export function proposeDoctrine(ctx, values, text, reserved = []) {}writeRowApply(ctx.info.root, { records: [], files: [{ file: doctrine.name, before: source, after: lines.join(newline) }],signoffs: { before: null, receipts: [] } });- return { id: 'doctrine:' + id, row: { id, status: 'draft', tier, text: ruling, gate, section: section?.name ?? 'DR · Rulings' } };+ return planned;}diff --git a/src/next-steps.js b/src/next-steps.jsindex bba6e36e..a76cc80c 100644--- a/src/next-steps.js+++ b/src/next-steps.js@@ -496,7 +496,7 @@ export const NEXT_STEPS = Object.freeze({ROUTE: 'take an item your route covers: pullboard next',ROW_DECISION: 'pullboard spec approve <ids>, or pullboard spec decline <ids>',ROW_DRAFT: 'pullboard spec draft "<text>" from an agent seat; the person approves the returned id',- ROW_ID_TAKEN: 'pullboard spec draft "<text>" again for the next free id',+ ROW_ID_TAKEN: 'run the same command again for the next free id',SEAL_AUTH_FAILED: 'fetch the board again, or pair this device again: pullboard relay on --all',SEAL_BINDING: 'upgrade Pullboard on this device, then retry',SEAL_CRYPTO: 'use Node 22 or newer, or a browser on a secure (https) page',diff --git a/src/rigor-draft.js b/src/rigor-draft.jsindex fa647ae3..35ac11a1 100644--- a/src/rigor-draft.js+++ b/src/rigor-draft.js@@ -5,6 +5,7 @@* proof is the check run on real commits: red on the bad one, green on the fix. Nothing here* approves or applies a row.*/+import { PERSON } from './board.js';import { Refused } from './refused.js';import {causeProblem,@@ -19,13 +20,14 @@ import { rigorSource } from './rigor-source.js';* has not repeated (pullboard rigor does not list it), the rule text is not one line, or the proof* does not hold. Returns the drafts with their evidence and proof.*- * @param {{ root: string, config: any, events: any[], person: string, reserved?: () => string[] }} board reserved: reads the ids- * the board's drafts hold, which a new row skips like any written row (#878). It is read after the proof, right- * before each write, so a lane draft made while a slow proof runs still counts.+ * @param {{ root: string, config: any, events: any[], person: string, reserve?: (row: any) => Promise<{ id: string }> }} board+ * reserve: reserves a planned row's id on the board and returns the id to write (#878). It runs after the+ * proof, right before each write, so a lane draft made while a slow proof runs, or at the same moment,+ * keeps its own id.* @param {{ key: string, text: string, check?: string, red?: string, green?: string, section?: string }} request* @returns {Promise<{ key: string, reads: string, evidence: { items: { id: number, commits: string[] }[], occurrences: number, neverAgain: boolean }, proof: object, drafts: object[] }>}*/-export async function rigorDraft({ root, config, events, person, agent, reserved = () => [] }, { key, text, check, red, green, section }) {+export async function rigorDraft({ root, config, events, person, agent, reserve = async (row) => row }, { key, text, check, red, green, section }) {const malformed = causeProblem(key ?? '');if (malformed) throw malformed;const cause = rigorReport(events, { person }).causes.find((entry) => entry.key === key);@@ -37,9 +39,37 @@ export async function rigorDraft({ root, config, events, person, agent, reservedconst why = `Why: rigor ${key.replaceAll('|', '/')} ${cause.neverAgain ? 'was marked never again by the person' : `failed on ${items}`}; red at ${proof.red.commit}, green at ${proof.green.commit}.`;const rowText = `${text.trim()} ${why}`;const source = rigorSource(cause, proof);+ /** Plan a row, reserve its id on the board, then write it at the reserved id. */+ const write = async (request) => {+ const planned = draftRow(root, config, { ...request, write: false });+ return draftRow(root, config, { ...request, id: (await reserve({ ...planned.row, target: request.target })).id });+ };const drafts = [];- if (cause.reads !== 'product') drafts.push(draftRow(root, config, { target: 'doctrine', text: rowText, gate: `check ${proof.countCheck}`, fields: ['count: 0', `source: ${source}`], section, taken: reserved() }));- if (cause.reads !== 'work') drafts.push(draftRow(root, config, { target: 'spec', text: rowText, gate: proof.check, fields: [`source: ${source}`], section, taken: reserved() }));+ if (cause.reads !== 'product') drafts.push(await write({ target: 'doctrine', text: rowText, gate: `check ${proof.countCheck}`, fields: ['count: 0', `source: ${source}`], section }));+ if (cause.reads !== 'work') drafts.push(await write({ target: 'spec', text: rowText, gate: proof.check, fields: [`source: ${source}`], section }));return { key, reads: cause.reads, evidence: { items: cause.items, occurrences: cause.occurrences, neverAgain: cause.neverAgain },proof: { check: proof.check, red: proof.red, green: proof.green }, drafts };}++/**+ * pullboard rigor draft (#714): prove the check red then green on real commits, then write the pending+ * row or rows through the spec draft writer. Nothing is approved or applied; the person approves the+ * rows in pullboard view or with pullboard spec approve [D1,D3,S1].+ *+ * @param {any} io+ * @param {{ second?: string, rest: string[], values: any }} args+ * @param {{ root: string, config: any, read: () => { events: any[], actor: string }, reserve: (row: any) => Promise<{ id: string }> }} deps+ * read: the board's events and the asking agent; reserve: the CLI's board reservation.+ * @returns {Promise<number>}+ */+export async function rigorDraftCommand(io, { second, rest, values }, { root, config, read, reserve }) {+ if (rest.length > 1) throw new Refused('USAGE', 'pullboard rigor draft <key> "<rule>" --check "<command>" --red <commit> --green <commit> [--section <letter>]');+ const { events, actor } = read();+ const result = await rigorDraft({ root, config, events, person: PERSON, agent: actor, reserve },+ { key: second, text: rest[0], check: values.check, red: values.red, green: values.green, section: values.section });+ io.result?.(result);+ io.say(`proved ${result.key}: red at ${result.proof.red.commit.slice(0, 12)} (${result.proof.red.problems} problem lines, exit ${result.proof.red.exit}), green at ${result.proof.green.commit.slice(0, 12)} (exit ${result.proof.green.exit})`);+ for (const draft of result.drafts) io.say(`${draft.file}: ${draft.line}`);+ io.say(`next: the person approves ${result.drafts.map((draft) => draft.id).join(' or ')} in pullboard view or with pullboard spec approve; commit ${[...new Set(result.drafts.map((draft) => draft.file))].join(' and ')}`);+ return 0;+}diff --git a/src/row-drafts.js b/src/row-drafts.jsindex c61d0540..388c6ad8 100644--- a/src/row-drafts.js+++ b/src/row-drafts.js@@ -4,7 +4,8 @@* relay like any recorded move. Every reader that asks whether a cited id is live counts a board draft* as a draft row, so the lane cites the returned id at once and its worktree stays clean. The* coordinator's spec apply writes the drafts into SPEC.md, and the person approves them there as before.- * A draft counts as applied once SPEC.md has its id, so applying needs no second move.+ * A draft counts as applied once SPEC.md has its id, so applying needs no second move. Every other+ * writer reserves its new id here too, so no two proposals share an id.*/import {atomic,@@ -28,22 +29,34 @@ export function rowDrafts(board) {}/**- * Record one drafted spec row on the board. The sender plans the id across SPEC.md, the doctrine file- * and the board's drafts; the board refuses an id it already holds.+ * Reserve one new row's id on the board, and for a lane, record the drafted row itself. Every writer+ * reserves here, in one write transaction, before any file names the id: a lane's spec draft, the+ * main checkout's spec draft and doctrine rulings, Rigor and blueprints. Writers that planned the same+ * id at the same moment get distinct ids, because the board takes the planned id or the next number+ * after it that no draft holds. A reservation marked written is the writer's own to put in its file;+ * spec apply writes only the unwritten spec drafts, which come from lanes.** @param {any} board- * @param {{ agentId: string, row: { id: string, text: string, gate: string, tier: string, section: string } }} move+ * @param {{ agentId: string, row: { id: string, text: string, gate?: string, tier?: string, section?: string, target?: string }, written?: boolean }} move*/-export function draftSpecRow(board, { agentId, row }) {+export function draftSpecRow(board, { agentId, row, written = false }) {if (!agentId || agentId === PERSON) throw new Refused('ROW_DRAFT', 'an agent drafts a row and the person approves it; run pullboard spec draft "<text>" from an agent seat');- if (!row || !/^[A-Z][A-Z0-9]*\d+$/u.test(String(row.id)) || ['text', 'gate', 'tier', 'section'].some((key) => typeof row[key] !== 'string' || !row[key].trim() || /[\r\n|]/u.test(row[key]))) {+ const needed = written ? ['text'] : ['text', 'gate', 'tier', 'section'];+ if (!row || !/^[A-Z][A-Z0-9]*\d+$/u.test(String(row.id)) || !['spec', 'doctrine', undefined].includes(row.target)+ || needed.some((key) => typeof row[key] !== 'string' || !row[key].trim() || /[\r\n|]/u.test(row[key]))) {throw new Refused('ROW_DRAFT', 'a drafted row needs its id and a one-line text, gate, tier and section; run pullboard spec draft "<text>"');}return atomic(board, () => {const current = rowDrafts(board);- if (current.some((draft) => draft.id === row.id)) throw new Refused('ROW_ID_TAKEN', `${row.id} is already drafted on this board; run pullboard spec draft again for the next free id`);- logEvent(board, agentId, 'row_draft', null, { row });- const entry = { id: row.id, text: row.text, gate: row.gate, tier: row.tier, section: row.section, by: agentId, event: board.lastEvent.event_id, at: board.lastEvent.event_at };+ // The same proposal again, as a resumed blueprint add, keeps the id it reserved.+ const same = current.find((draft) => draft.id === row.id && draft.text === row.text);+ if (same) return same;+ const [, prefix, number] = /^(.*?)(\d+)$/u.exec(row.id);+ let next = Number(number);+ while (current.some((draft) => draft.id === `${prefix}${next}`)) next += 1;+ logEvent(board, agentId, 'row_draft', null, { row, written: Boolean(written) });+ const entry = { id: `${prefix}${next}`, text: row.text, gate: row.gate ?? '', tier: row.tier ?? '', section: row.section ?? '', target: row.target ?? 'spec',+ written: Boolean(written), by: agentId, event: board.lastEvent.event_id, at: board.lastEvent.event_at };board.db.prepare('INSERT INTO board_meta(meta_key,meta_value) VALUES (?,?) ON CONFLICT(meta_key) DO UPDATE SET meta_value=excluded.meta_value').run('row_drafts', JSON.stringify([...current, entry]));return entry;@@ -68,10 +81,15 @@ export function trunkRowIds(root, mainRoot, config) {return ids.map((row) => row.id);}-/** Board drafts that SPEC.md does not have yet, for spec apply to write. */+/** A lane's spec drafts: the reservations spec apply writes, unlike a writer's own reservation. */+function laneDrafts(drafts) {+ return drafts.filter((draft) => !draft.written && (draft.target ?? 'spec') === 'spec');+}++/** Board drafts from lanes 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));+ return laneDrafts(drafts).filter((draft) => !present.has(draft.id));}/**@@ -79,7 +97,7 @@ export function pendingRowDrafts(spec, drafts) {* 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));+ return laneDrafts(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. */diff --git a/test/hooks.test.js b/test/hooks.test.jsindex 3be63fe9..7611d687 100644--- a/test/hooks.test.js+++ b/test/hooks.test.js@@ -3,10 +3,10 @@*/import assert from 'node:assert/strict';import { spawnSync } from 'node:child_process';-import { runFixtureExecFile as execFileSync, runFixtureGit } from './fixture-child.js';+import { runFixtureExecFile as execFileSync, runFixtureChildAsync, runFixtureGit } from './fixture-child.js';import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';-import { join } from 'node:path';+import { join, resolve } from 'node:path';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';@@ -322,6 +322,31 @@ test('a lane draft and a coordinator draft never share an id, in either order [Sassert.notEqual(approve.code, 0, 'a lane cannot approve its own draft; the person does');});+test('a lane draft and a main-checkout draft started at the same moment keep distinct ids [S1,B26]', async () => {+ const box = e2e.project('pullboard spec check');+ const cli = resolve(import.meta.dirname, '../bin/pullboard.js');+ /** Start one real spec draft without waiting for it. */+ const start = (cwd, text) => runFixtureChildAsync(process.execPath, [cli, 'spec', 'draft', text, '--json'], { cwd, env: box.env });+ const proposals = [];+ for (let pair = 1; pair <= 4; pair += 1) {+ const texts = [`A lane row from pair ${pair}`, `A coordinator row from pair ${pair}`];+ const results = await Promise.all([start(box.web, texts[0]), start(box.repo, texts[1])]);+ results.forEach((result, index) => {+ assert.equal(result.status, 0, result.context);+ proposals.push({ id: JSON.parse(result.stdout).id, text: texts[index] });+ });+ }+ assert.equal(new Set(proposals.map(({ id }) => id)).size, proposals.length, `every proposal keeps its own id: ${proposals.map(({ id }) => id).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 proposals) assert.ok(spec.includes(`- ${id} [draft, must] ${text} | gate: review`), `${id} keeps its own text as a draft after apply`);+ assert.notEqual(box.run(box.web, 'spec', 'approve', proposals[0].id).code, 0, 'a lane cannot approve its own draft; the person does');+});+test('a hook names a Pullboard version mismatch instead of running old rules [C1,I2]', (t) => {const box = stagedRepo(t);const hooks = join(box.root, '.githooks'), bin = join(box.root, '.fakebin'), local = join(box.root, 'node_modules', '.bin');