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(rigor): preserve lifecycle refusal boundaries [D1,M1,H16]
Corey Olson9b285b4cbbe8
diff --git a/src/rigor-auto-source.js b/src/rigor-auto-source.jsindex f7fbc227..9b3ff941 100644--- a/src/rigor-auto-source.js+++ b/src/rigor-auto-source.js@@ -1,6 +1,7 @@/** Evidence-only proposals are deliberately distinct from executed rigor: proofs [D1,S1]. */import { causeProblem } from './rigor.js';import { parseSpec } from './spec.js';+import { Refused } from './refused.js';import { readRigorSource } from './rigor-source.js';import {rowDecisionContext,@@ -41,7 +42,10 @@ export function automaticDecisionSource(record) {try {const rows = parseSpec(`## Decision\n${record.source ?? ''}\n`).rows;return rows.length === 1 ? automaticSourceFromText(rows[0].text) : null;- } catch { return null; /* An unreadable old decision cannot decide a new proposal. */ }+ } catch (error) {+ if (error instanceof Refused && error.code === 'A5_GRAMMAR_VERSION') return null;+ throw error;+ }}/** A proved replacement decision also answers older unproved advice about that same cause. */@@ -50,12 +54,16 @@ export function rigorDecisionKey(record) {const rows = parseSpec(`## Decision\n${record.source ?? ''}\n`).rows;return rows.length === 1 ? readRigorSource(rows[0].source)?.key?? readAutomaticRigorSource(automaticSourceFromText(rows[0].text))?.key ?? null : null;- } catch { return null; /* Only typed historical row provenance can answer a proposal. */ }+ } catch (error) {+ if (error instanceof Refused && error.code === 'A5_GRAMMAR_VERSION') return null;+ throw error;+ }}/** A materialized row must preserve the whole definition; merely occupying its id is a collision. */export function sameAutomaticRow(row, draft) {- const expected = parseSpec(`## Proposal\n- ${draft.id} [draft, ${draft.tier}] ${draft.text} | gate: ${draft.gate}\n`).rows[0];+ const expected = { id: draft.id, status: 'draft', tier: draft.tier, text: draft.text, gate: draft.gate,+ serves: [], signers: [], unknown: [] };return expected && ['id', 'status', 'tier', 'text', 'gate', 'serves', 'signers', 'unknown', 'count', 'runs', 'mode', 'files', 'source'].every(key => JSON.stringify(row[key]) === JSON.stringify(expected[key]));}diff --git a/src/rigor-auto.js b/src/rigor-auto.jsindex 11ffe748..b8c976d1 100644--- a/src/rigor-auto.js+++ b/src/rigor-auto.js@@ -5,10 +5,8 @@ import {PERSON,rowDecisions,} from './board.js';-import {- draftSpecRow,- rowDrafts,-} from './row-drafts.js';+import { recordRowDraft } from './row-draft-store.js';+import { rowDrafts } from './board-query.js';import {causeProblem,eventCauses,@@ -95,7 +93,7 @@ export function recordAutomaticRigorDrafts(board, trigger, shout) {const source = automaticRigorSource(cause, eventIds);const advice = cause.split ? splitProposal(cause.split).text: `Review how to prevent repeated ${JSON.stringify(cause.key).replaceAll('|', '\\u007c')} (${cause.items.map(item => `#${item.id}`).join(', ') || 'person-marked never again'}). No remedy or red/green proof has been established.`;- const entry = draftSpecRow(board, { agentId: 'rigor', row: { id: `RG${trigger.event_id}1`, target,+ const entry = recordRowDraft(board, { agentId: 'rigor', row: { id: `RG${trigger.event_id}1`, target,text: `${advice} Source: ${source}`, gate: 'review', tier: 'aim', section: 'RG' } });logEvent(board, 'rigor', 'rigor-draft', null, { engine: RIGOR_AUTO_ENGINE, id: entry.id, target, cause: cause.key,source, unproved: true, items: cause.items, occurrences: cause.occurrences });diff --git a/src/row-draft-store.js b/src/row-draft-store.jsnew file mode 100644index 00000000..dc44d37a--- /dev/null+++ b/src/row-draft-store.js@@ -0,0 +1,27 @@+/** Internal atomic persistence for validated public drafts and canonical automatic proposals [D1]. */+import {+ atomic,+ logEvent,+} from './board.js';+import { rowDrafts } from './board-query.js';++/** Reserve an id and record the exact proposal; callers establish their own input policy first. */+export function recordRowDraft(board, { agentId, row, written = false }) {+ return atomic(board, () => {+ const current = rowDrafts(board);+ // The same writer asking again for the same definition, as a resumed blueprint add does, keeps the id+ // it reserved; a different gate, tier, section, target or writer is another proposal and gets its own id.+ const same = current.find((draft) => draft.id === row.id && draft.by === agentId && draft.written === Boolean(written)+ && ['text', 'gate', 'tier', 'section'].every((key) => (draft[key] ?? '') === (row[key] ?? '')) && draft.target === (row.target ?? 'spec'));+ 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;+ });+}diff --git a/src/row-drafts.js b/src/row-drafts.jsindex 0b77ac7a..2f1744ae 100644--- a/src/row-drafts.js+++ b/src/row-drafts.js@@ -7,11 +7,7 @@* 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,- logEvent,- PERSON,-} from './board.js';+import { PERSON } from './board.js';import { Refused } from './refused.js';import { spawnSync } from 'node:child_process';import { loadDoctrine } from './doctrine.js';@@ -21,7 +17,7 @@ import {} from './spec.js';import { cleanGitEnvironment } from './git.js';import { trunkRef } from './trusted-policy-read.js';-import { rowDrafts } from './board-query.js';+import { recordRowDraft } from './row-draft-store.js';export { rowDrafts } from './board-query.js';/**@@ -42,23 +38,7 @@ export function draftSpecRow(board, { agentId, row, written = false }) {|| 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);- // The same writer asking again for the same definition, as a resumed blueprint add does, keeps the id- // it reserved; a different gate, tier, section, target or writer is another proposal and gets its own id.- const same = current.find((draft) => draft.id === row.id && draft.by === agentId && draft.written === Boolean(written)- && ['text', 'gate', 'tier', 'section'].every((key) => (draft[key] ?? '') === (row[key] ?? '')) && draft.target === (row.target ?? 'spec'));- 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;- });+ return recordRowDraft(board, { agentId, row, written });}/**diff --git a/test/machine.test.js b/test/machine.test.jsindex b62ea5da..afd9ebdf 100644--- a/test/machine.test.js+++ b/test/machine.test.js@@ -127,6 +127,9 @@ const CAUGHT = {'spec-approval.js#specApprovalState': ['board-query.js#specApprovalBaseline'],// Historical decline metadata is parsed inside a non-throwing boundary, covered by the Rigor history control.'board.js#reopen': ['rigor-notices.js#declinedRigorSource'],+ // Only an unsupported historical grammar is ignored; new caller refusals remain audited below.+ 'rigor-auto-source.js#automaticDecisionSource': ['spec.js#parseSpec'],+ 'rigor-auto-source.js#rigorDecisionKey': ['spec.js#parseSpec'],};/**@@ -551,6 +554,16 @@ test('a broken copy of the code fails the check: a refusal added wherever a move'MOON_PHASE is raised by refreeze but not declared there',], 'the caller is not exempt: only the exact reader call is inside its catch');+ for (const helper of ['automaticDecisionSource', 'rigorDecisionKey']) {+ const inHistoricalCaller = editedSource('rigor-auto-source.js',+ new RegExp(`^export function ${helper}\\(record\\) \\{$`, 'm'),+ "$&\n throw new Refused('MOON_PHASE', 'wait for the full moon');");+ assert.deepEqual(codeProblems(MACHINE, inHistoricalCaller).sort(), [+ 'MOON_PHASE is raised by accept and reject but not declared there',+ 'MOON_PHASE is raised by reopen but not declared there',+ ], 'a new refusal outside the historical parser catch still reaches lifecycle moves');+ }+const inFreeze = editedSource('spec.js', /^export function frozenCriterion\(spec, item, doctrine = null\) \{$/m, "$&\n if (item.item_title === 'moon') throw new Refused('MOON_PHASE', 'wait for the full moon');");assert.deepEqual(codeProblems(MACHINE, inFreeze).sort(), ['MOON_PHASE is raised by claim but not declared there',diff --git a/test/rigor-auto.test.js b/test/rigor-auto.test.jsindex 91da5694..79660a51 100644--- a/test/rigor-auto.test.js+++ b/test/rigor-auto.test.js@@ -16,6 +16,7 @@ import { loadConfig } from '../src/config.js';import { RIGOR_AUTO_ENGINE } from '../src/rigor-auto-engine.js';import { prepareEngineMove, applyEngineMove } from '../src/engine.js';import { conflictNote } from '../src/trunk-conflict.js';+import { automaticDecisionSource, rigorDecisionKey } from '../src/rigor-auto-source.js';const roots = [];after(() => { for (const root of roots) rmSync(root, { recursive: true, force: true }); });@@ -298,3 +299,13 @@ test('canonical conflict holds crossing the hot-file threshold also draft adviceassert.equal(box.git('status', '--porcelain').trim(), '', 'the automatic holds do not edit the repository');} finally { box.close(); }});++/** Unsupported historical grammar carries no authority; unrelated reader failures must remain visible. */+test('automatic decision readers ignore only unsupported historical grammar [D1,H16,M1]', () => {+ const source = '<!-- pullboard-grammar 999 -->\n- G9 [draft, aim] Historical proposal | gate: review';+ assert.equal(automaticDecisionSource({ source }), null);+ assert.equal(rigorDecisionKey({ source }), null);+ const broken = { get source() { throw new Error('unexpected metadata reader failure'); } };+ assert.throws(() => automaticDecisionSource(broken), /unexpected metadata reader failure/);+ assert.throws(() => rigorDecisionKey(broken), /unexpected metadata reader failure/);+});