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.

feat(doctrine): share approved rulings on resume [D1,D3,B27]

Corey Olsone35935bf4468
diff --git a/docs/api.md b/docs/api.md
index dbafe4db..f76bddb7 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -51,7 +51,7 @@ For example: `flow: review wait average 61 min (1 measured; > 60 min); bottlenec
| `join` | `version:number`, `agent:string`, `lane:string`, `route:string`, `path:string`, `model:string`, `displayName:string` |
| `takeover` | `version:number`, `agent:string`, `path:string` |
| `worktree` | `version:number`, `agent:string`, `lane:string`, `route:string`, `path:string`, `branch:string`, `prompt:string`, `model:string`, `displayName:string` |
-| `resume` | `version:number`, `me:object`, `all:array`, `requests:array`, `holding:array`, `sentBack:array`, `awaiting:array`, `toVerify:array`, `toMerge:array`, `open:array`, `stale:array`, `holds:array`, `unread:number`, `newest:array`, `root:string`, `dirty:number`, `next:string` |
+| `resume` | `version:number`, `me:object`, `all:array`, `requests:array`, `holding:array`, `sentBack:array`, `awaiting:array`, `toVerify:array`, `toMerge:array`, `open:array`, `stale:array`, `doctrineNotes:array`, `holds:array`, `unread:number`, `newest:array`, `root:string`, `dirty:number`, `next:string` |
| `whoami` | `version:number`, `id:string`, `lane:string`, `path:string`, `model:string`, `displayName:string` |
| `lanes` | `version:number`, `lanes:object`, `shared:array`, `coordinator:string` |
| `resources` | `version:number`, `resources:array` |
@@ -122,6 +122,8 @@ For example: `flow: review wait average 61 min (1 measured; > 60 min); bottlenec
| `hook pre-push` | `version:number`, `messages:array` |
<!-- api-command-shapes:end -->
+`spec draft "<rule>" --doctrine --source "chat, 2026-10-16"` proposes a sourced doctrine row and returns a qualified `id`, such as `doctrine:DR1`, for the existing person approval commands. Resume adds `doctrineNotes`, an array of newly seen approved rules with `id`, `text` and `gate`; each checkout consumes its own notices. Drafts and pending applications are excluded. The shared approved doctrine also supplies frozen citations and stale-item comparisons in older checkouts.
+
`hook pre-merge-commit` runs the same staged checks as `hook pre-commit` before Git creates an automatic merge commit. `init` and `hooks` install it; `doctor` names it when absent at Git's effective hook path. Lane ownership comes from `HEAD:pullboard.json`, so an unstaged configuration edit cannot grant a lane new folders. Lane-sensitive checks refuse a repository with `info/grafts` in its Git common directory because grafts alter ancestry even when replacement objects are disabled.
`join` and `worktree` require a free-text `--model` label or `PULLBOARD_MODEL` environment value; labels are not inferred from a provider or family. Rejoining the same worktree preserves its agent id; the model label is required on every join, and omitting the optional `--family` preserves its prior declaration. `pullboard.json` may set `agents.names` to `suffix` (the default, `web-1 (Claude)`) or `prefix` (`claude-web-1`). CLI `agent` fields remain stable ids; `displayName` shows the chosen style. `resume.me` and API state `agents[]` carry `model` and `displayName`; older agents with no model display `unknown`. Each event records the actor model in `event_detail.model` for a registered agent, with `unknown` for legacy agents without a declaration. `show` includes `item_builder_family` and each verdict's `verdict_verifier_family`. These family fields are `null` when the agent did not declare a family, and later declarations do not rewrite prior submissions or verdicts.
diff --git a/docs/formats.md b/docs/formats.md
index 53745ece..152ae5fa 100644
--- a/docs/formats.md
+++ b/docs/formats.md
@@ -65,6 +65,14 @@ A bare id names a row in `SPEC.md`. A doctrine row is cited as `doctrine:<id>` i
| `line` | 1-based source line. |
<!-- parser-fields:end -->
+## Proposed rulings and resume doctrine notes
+
+The coordinator proposes a standing ruling with `pullboard spec draft "<rule>" --doctrine --source "chat, 2026-10-16"` (or a shout reference such as `"shout 42"`). A source is required. The draft lives in the configured doctrine file, with `Source: ...` in its text, and the returned id is qualified as `doctrine:DR1`. The person approves or declines that id through the existing `spec approve` or `spec decline` commands; the coordinator runs `spec apply`.
+
+`resume --json` includes `doctrineNotes`, an array of newly seen approved repo rules, each with `id`, `text` and `gate`. Drafts and pending applications are excluded. Text resume prints the same rules. Each checkout records its own displayed rule text under its Git directory, so a second checkout receives its own notice. Repeated resumes return an empty array until an approved rule changes.
+
+Resume and criterion freezing use the primary branch's committed doctrine together with the person's applied exact-row decisions. An older agent checkout can therefore read an approved ruling and detect that a frozen citation is stale without changing its branch or local doctrine file. Proposed or unapplied changes do not replace the in-force rule.
+
## Resume release notes
<!-- resume-release-notes:start -->
diff --git a/src/cli.js b/src/cli.js
index 9ccc8f9c..3d2df9c3 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -13,7 +13,12 @@ import { parseArgs } from 'node:util';
import * as store from './board.js';
import { CONFIG_FILE, COORDINATOR, DOCTRINE_FILE, LEGACY_DOCTRINE_FILE, loadConfig } from './config.js';
import { displayAgentName } from './agent-names.js';
-import { doctrineHistory, loadDoctrine } from './doctrine.js';
+import {
+ appliedDoctrine,
+ doctrineFromSource,
+ doctrineHistory,
+ loadDoctrine,
+} from './doctrine.js';
import { agentSessionDigest, requirePersonChannel } from './person.js';
import { bindLocalSession, localSessionMatches } from './agent-session.js';
import { decisionProjection, planRowApply, prepareRowDecisions, restoreRowApply, writeRowApply } from './row-decisions.js';
@@ -243,6 +248,8 @@ const OPTIONS = {
text: { type: 'string' },
gate: { type: 'string' },
aim: { type: 'boolean' },
+ doctrine: { type: 'boolean' },
+ source: { type: 'string' },
section: { type: 'string' },
route: { type: 'string' },
family: { type: 'string' },
@@ -659,7 +666,7 @@ function whoAmI(ctx, board) {
* @param {{ captureVerifyPolicy?: boolean }} [options]
* @returns {(item: any) => { text: string, digest: string }}
*/
-function freezer(ctx, { captureVerifyPolicy = false } = {}) {
+function freezer(ctx, { captureVerifyPolicy = false, board } = {}) {
/** Freeze the criterion and, when requested, the trunk lane and verifier policy. */
return (item) => {
const prior = item.item_frozen ? JSON.parse(item.item_frozen) : null;
@@ -678,7 +685,8 @@ function freezer(ctx, { captureVerifyPolicy = false } = {}) {
} else {
config = policy ? itemPolicy(ctx.info.root, { ...item, item_frozen: JSON.stringify({ policy }) }).config : ctx.config;
}
- const frozen = frozenCriterion(loadSpec(ctx.info.root, config), item, loadDoctrine(ctx.info.root, config));
+ const doctrine = board ? agentDoctrine(ctx, board) : loadDoctrine(ctx.info.root, config);
+ const frozen = frozenCriterion(loadSpec(ctx.info.root, config), item, doctrine);
if (!policy) return frozen; // Legacy criteria retain their original digest and committed claim base.
const text = JSON.stringify({ ...JSON.parse(frozen.text), policy });
return { text, digest: createHash('sha256').update(text).digest('hex') };
@@ -736,11 +744,11 @@ class MainSpecMerged extends Error {
* @param {any} ctx
* @returns {(item: any) => { text: string, digest: string }}
*/
-function claimFreezer(ctx) {
+function claimFreezer(ctx, board) {
return (item) => {
const rows = prepareClaimSpec(ctx, item);
if (rows) throw new MainSpecMerged(rows);
- return freezer(ctx)(item);
+ return freezer(ctx, { board })(item);
};
}
@@ -1095,6 +1103,48 @@ function resumeReleaseNotes(info) {
return releases.length ? { releases: releases.slice(0, 3), omitted: Math.max(0, releases.length - 3), notes: 'CHANGELOG.md' } : null;
}
+/** Read accepted-main doctrine plus applied person decisions, independent of this checkout's age. */
+function agentDoctrine(ctx, board) {
+ const root = ctx.info.root;
+ const primary = mainCheckout(root);
+ const retained = primary?.commit ? null : trunkRef(root);
+ const commit = primary?.commit ?? (retained ? resolveCommit(root, retained) : null);
+ let doctrine = ctx.doctrine;
+ let name = doctrine.name;
+ if (commit && tryGit(root, ['show', `${commit}:${CONFIG_FILE}`]).status === 0) {
+ const config = policyAt(root, commit).config;
+ name = config.practice;
+ let source = tryGit(root, ['show', `${commit}:${name}`]);
+ if (source.status !== 0 && [DOCTRINE_FILE, LEGACY_DOCTRINE_FILE].includes(name)) {
+ const alias = name === DOCTRINE_FILE ? LEGACY_DOCTRINE_FILE : DOCTRINE_FILE;
+ const other = tryGit(root, ['show', `${commit}:${alias}`]);
+ if (other.status === 0) { name = alias; source = other; }
+ }
+ doctrine = doctrineFromSource(source.status === 0 ? source.stdout : null, name);
+ }
+ const entry = git(root, ['worktree', 'list', '--porcelain', '-z']).split('\0')[0];
+ const primaryRoot = entry.startsWith('worktree ') ? entry.slice('worktree '.length) : null;
+ const file = primaryRoot && join(primaryRoot, name);
+ const current = file && existsSync(file) ? readFileSync(file, 'utf8') : null;
+ return appliedDoctrine(doctrine, store.rowDecisions(board), current);
+}
+
+/** Record each checkout's displayed approved rules so another checkout keeps its own notices. */
+function resumeDoctrineNotes(info, doctrine) {
+ const record = join(info.gitDir, 'pullboard-checkout', 'resume-doctrine.json');
+ let previous = {};
+ try { previous = JSON.parse(readFileSync(record, 'utf8')); } catch { /* First doctrine resume. */ }
+ if (!previous || typeof previous !== 'object' || Array.isArray(previous)) previous = {};
+ const approved = doctrine.rows.filter(row => row.origin === 'repo' && row.status === 'approved');
+ /** Identify the exact approved guidance this checkout has already displayed. */
+ const fingerprint = row => createHash('sha256').update(JSON.stringify([row.text, row.gate])).digest('hex');
+ const notes = approved.filter(row => previous[row.id] !== fingerprint(row))
+ .map(row => ({ id: 'doctrine:' + row.id, text: row.text, gate: row.gate }));
+ mkdirSync(dirname(record), { recursive: true });
+ writeFileSync(record, JSON.stringify({ ...previous, ...Object.fromEntries(approved.map(row => [row.id, fingerprint(row)])) }) + '\n', { mode: 0o600 });
+ return notes;
+}
+
/** Identify setup from this board's coordinator enrollment, independently of agent flags. */
function setupIdentity(board) {
return { boardId: store.boardId(board),
@@ -1233,8 +1283,10 @@ function resumeHere(io) {
const ctx = context(io);
const { root, isMain } = ctx.info;
let setupScope;
+ let doctrine;
const card = withBoard(ctx, (board) => {
setupScope = setupIdentity(board);
+ doctrine = agentDoctrine(ctx, board);
const me = whoAmI(ctx, board);
const all = store.listItems(board, { all: true });
const toMerge = all.filter((item) => item.item_status === 'verified' && !item.item_merged_commit);
@@ -1267,7 +1319,7 @@ function resumeHere(io) {
card.hookProblems = unwiredHookProblems(root);
const { me } = card;
const name = (id) => agentDisplayName(card.agents, ctx.config, id);
- card.stale = staleFrozenItems(card.all, loadSpec(root, ctx.config).rows, ctx.doctrine.rows).map((item) => ({ ...item, ...staleItemFinding(item) }));
+ card.stale = staleFrozenItems(card.all, loadSpec(root, ctx.config).rows, doctrine.rows).map((item) => ({ ...item, ...staleItemFinding(item) }));
if (isMain) {
card.staleFollowUps = { count: card.stale.length + card.staleIntegrations.length,
list: 'pullboard resume --json', items: card.stale, integrations: card.staleIntegrations };
@@ -1275,6 +1327,8 @@ function resumeHere(io) {
card.reviewQueue = { items: card.toVerify, awaiting: card.awaiting };
}
const say = (line) => io.say(line);
+ card.doctrineNotes = resumeDoctrineNotes(ctx.info, doctrine);
+ for (const row of card.doctrineNotes) say(`new doctrine ${row.id} — ${row.text}`);
const releaseNotes = card.whatsNew = resumeReleaseNotes(ctx.info);
for (const note of (releaseNotes?.releases ?? [])) {
say(`new in ${note.version} — ${note.headline}: ${note.paragraph}`);
@@ -2113,7 +2167,7 @@ async function submitHere(ctx, id) {
let digest = null;
let unusable = '';
try {
- digest = freezer(ctx)(item).digest;
+ digest = freezer(ctx, { board })(item).digest;
} catch (error) {
if (!(error instanceof Refused) || error.code === 'A5_GRAMMAR_VERSION') throw error;
unusable = error.message.replace(/^\[\w+\] /, '').split(';')[0];
@@ -2221,7 +2275,7 @@ async function verifyHere(ctx, id, { second, values }) {
let digest = 'missing';
let check;
try {
- digest = freezer(ctx)(item).digest;
+ digest = freezer(ctx, { board })(item).digest;
} catch (error) {
if (!(error instanceof Refused) || error.code === 'A5_GRAMMAR_VERSION') throw error;
}
@@ -2296,7 +2350,7 @@ async function nextOnce(ctx, values) {
const reviewSkipped = values.build && !held
? { offeredItem: offer?.item.item_id ?? null, ratio: ctx.config.verify.reviewRatio, ...store.reviewQueue(board) } : null;
try {
- await ordered(ctx, board, 'claim', [item.item_id, { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: claimFreezer(ctx), head: headCommit(ctx.info.root), reviewSkipped }]);
+ await ordered(ctx, board, 'claim', [item.item_id, { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: claimFreezer(ctx, board), head: headCommit(ctx.info.root), reviewSkipped }]);
} catch (error) {
if (error instanceof MainSpecMerged) return { retry: true, specMerged: { item: item.item_id, rows: error.rows } };
if (error instanceof Refused && ['HELD', 'ITEM_HELD', 'BLOCKED', 'ONE_CLAIM'].includes(error.code)) return { retry: true };
@@ -2652,7 +2706,7 @@ function workCommands(io, args) {
let result;
for (;;) {
try {
- result = await ordered(ctx, board, 'claim', [id, { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: claimFreezer(ctx), head: headCommit(ctx.info.root) }]);
+ result = await ordered(ctx, board, 'claim', [id, { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: claimFreezer(ctx, board), head: headCommit(ctx.info.root) }]);
break;
} catch (error) {
if (!(error instanceof MainSpecMerged)) throw error;
@@ -2763,7 +2817,7 @@ function workCommands(io, args) {
return 0;
}),
refreeze: () => act(async (ctx, board, me) => {
- const result = await ordered(ctx, board, 'refreeze', [idArg(first), { agentId: me.id, freeze: freezer(ctx, { captureVerifyPolicy: true }) }]);
+ const result = await ordered(ctx, board, 'refreeze', [idArg(first), { agentId: me.id, freeze: freezer(ctx, { captureVerifyPolicy: true, board }) }]);
io.result?.({ id: idArg(first), ...result });
io.say(`#${first} refrozen ${String(result.before).slice(0, 12)} -> ${result.after.slice(0, 12)}; ${result.retainedClaim ? 'claim retained' : 'open again'}`);
return 0;
@@ -2904,6 +2958,47 @@ function specProof(ctx) {
});
}
+/** Propose one source-backed ruling without approving it or changing existing doctrine rows. */
+function proposeDoctrine(ctx, values, text) {
+ if (typeof values.source !== 'string' || !values.source.trim() || /[\r\n|]/u.test(values.source)) {
+ throw new Refused('USAGE', 'a doctrine ruling needs its source; give --source "shout 42" or --source "chat, 2026-10-16"');
+ }
+ withBoard(ctx, (board) => {
+ const me = whoAmI(ctx, board);
+ if (!ctx.info.isMain || me.id !== COORDINATOR) throw new Refused('COORDINATOR_ONLY', 'only the coordinator proposes standing rulings; ask your coordinator to run spec draft --doctrine --source');
+ });
+ 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`);
+ const sections = doctrine.repo.sections.map(section => ({ ...section,
+ prefix: /^([A-Z][A-Z0-9]*)\s*[·.:-]/u.exec(section.name)?.[1] })).filter(section => section.prefix);
+ const prefix = values.section ?? 'DR';
+ const section = sections.find(section => section.prefix === prefix);
+ 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];
+ 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 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 source = readFileSync(doctrine.repo.file, 'utf8');
+ const newline = source.includes('\r\n') ? '\r\n' : '\n';
+ const lines = source.split(/\r?\n/u);
+ if (section) {
+ const following = doctrine.repo.sections.find(entry => entry.line > section.line);
+ let insertion = following ? following.line - 1 : lines.length;
+ while (insertion > section.line && !lines[insertion - 1].trim()) insertion -= 1;
+ lines.splice(insertion, 0, row);
+ } else {
+ while (lines.length && !lines.at(-1).trim()) lines.pop();
+ lines.push('', '## DR · Rulings', row, '');
+ }
+ 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' } };
+}
+
/**
* The spec commands: reads, sign-offs and person decisions applied by the coordinator.
*
@@ -2921,7 +3016,7 @@ async function specCommand(io, { first, second, rest, values }) {
unmet: ['must'],
signoff: ['by', 'note', 'note-file'],
signers: ['key', 'by'],
- draft: ['aim', 'gate', 'section'],
+ draft: ['aim', 'gate', 'section', 'doctrine', 'source'],
approve: ['by', 'text'],
decline: ['reason'],
apply: [],
@@ -2945,6 +3040,13 @@ async function specCommand(io, { first, second, rest, values }) {
if (values.gate !== undefined && (!values.gate.trim() || /[\r\n|]/u.test(values.gate))) {
throw new Refused('USAGE', 'give one nonempty, single-line gate without a field separator, or omit --gate to use review');
}
+ if (values.doctrine) {
+ const result = proposeDoctrine(ctx, values, second);
+ 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');
if (!spec.sections.length) throw new Refused('NO_SECTION', `no section in ${ctx.config.spec}; add a section heading, then draft the requirement`);
const sections = spec.sections.map(section => ({ ...section,
prefix: /^([A-Z][A-Z0-9]*)\s*[·.:-]/u.exec(section.name)?.[1] })).filter(section => section.prefix);
diff --git a/src/doctrine.js b/src/doctrine.js
index 4e093a66..9966262c 100644
--- a/src/doctrine.js
+++ b/src/doctrine.js
@@ -31,6 +31,40 @@ function declineReason(row) {
export function loadDoctrine(root, config = {}) {
const name = doctrineFile(root, config.practice);
const repo = loadSpec(root, { ...config, spec: name });
+ return composeDoctrine(repo, name);
+}
+
+/** Compose committed doctrine bytes without reading an unapproved checkout file. */
+export function doctrineFromSource(source, name) {
+ return composeDoctrine({ ...parseSpec(source ?? ''), source, name, file: name, exists: source !== null }, name);
+}
+
+/** Overlay only the person's applied exact-row decisions on the committed doctrine. */
+export function appliedDoctrine(doctrine, decisions, currentSource) {
+ const rows = new Map(doctrine.repo.rows.map(row => [row.id, row]));
+ const aliases = new Set([DOCTRINE_FILE, LEGACY_DOCTRINE_FILE]);
+ const current = parseSpec(currentSource ?? '');
+ const currentLines = (currentSource ?? '').split(/\r?\n/u);
+ const committedLines = (doctrine.repo.source ?? '').split(/\r?\n/u);
+ for (const record of decisions) {
+ if (record.kind !== 'doctrine' || !record.applied) continue;
+ if (record.file !== doctrine.name && !(aliases.has(record.file) && aliases.has(doctrine.name))) continue;
+ const matching = current.rows.filter(row => row.id === record.id);
+ if (matching.length !== 1 || currentLines[matching[0].line - 1] !== record.replacement) continue;
+ const committed = rows.get(record.id);
+ if (committed && doctrine.repo.source !== undefined
+ && ![record.source, record.replacement].includes(committedLines[committed.line - 1])) continue;
+ const parsed = parseSpec(`## Approved rulings\n${record.replacement}\n`);
+ const row = parsed.rows[0];
+ if (parsed.rows.length !== 1 || row.id !== record.id || row.text !== record.text
+ || row.status !== (record.decision === 'approve' ? 'approved' : 'wont')) continue;
+ rows.set(row.id, { ...row, section: rows.get(row.id)?.section ?? row.section });
+ }
+ return composeDoctrine({ ...doctrine.repo, rows: [...rows.values()] }, doctrine.name);
+}
+
+/** Combine one repo snapshot with the packaged standard using the same override rules. */
+function composeDoctrine(repo, name) {
const standard = standardDoctrine();
const inherited = new Set(standard.rows.map((row) => row.id));
const overrides = new Set(repo.rows.filter((row) => inherited.has(row.id)).map((row) => row.id));
diff --git a/src/help.js b/src/help.js
index d2485849..22a2f1d4 100644
--- a/src/help.js
+++ b/src/help.js
@@ -148,7 +148,8 @@ Spec
pullboard spec show <id> | unmet [--must] | signoff <ids> [--by <principal>]
signoff: --note "what was checked" stays with the receipt
pullboard spec draft <text> [--section <letter>] [--aim] [--gate "<gate>"] any agent appends a draft row; never approves it
- --section chooses the section prefix; defaults to G
+ [--doctrine --source "<shout id or chat, date>"] the coordinator proposes a sourced doctrine ruling
+ --section chooses the section prefix; defaults to G, or DR with --doctrine
Defaults to must and gate review.
pullboard spec signers add [--key <path>] [--by <principal>] opt into SSH-signed sign-offs
principal defaults to Git user.email; --by overrides it
@@ -234,6 +235,7 @@ const HELP_FLAG_EXPLANATIONS = {
'--after': 'claiming waits until those items are verified',
'--brief': 'what a cold agent needs',
'--check': 'the command that proves it',
+ '--doctrine': 'proposes a doctrine ruling; only the person can approve it',
'--family': 'records the family name',
'--model': 'identifies the agent model; required unless PULLBOARD_MODEL is set',
'--landing': 'prioritizes a trunk landing in the machine gate queue',
@@ -241,6 +243,7 @@ const HELP_FLAG_EXPLANATIONS = {
'--note': 'what was checked stays with the receipt',
'--note-file': 'keeps quotes, $ and backticks intact',
'--route': 'sets which work the model can take',
+ '--source': 'where the person gave the ruling; required with --doctrine',
};
/** Build command-specific help rows from the preserved full list so its syntax stays authoritative. */
diff --git a/src/json.js b/src/json.js
index cb556f2c..219d0abe 100644
--- a/src/json.js
+++ b/src/json.js
@@ -16,7 +16,7 @@ export const JSON_SHAPES = {
join: shape({ agent: 'string', lane: 'string', route: 'string', path: 'string', model: 'string', displayName: 'string' }),
takeover: shape({ agent: 'string', path: 'string' }),
worktree: shape({ agent: 'string', lane: 'string', route: 'string', path: 'string', branch: 'string', prompt: 'string', model: 'string', displayName: 'string' }),
- resume: shape({ me: 'object', all: 'array', requests: 'array', holding: 'array', sentBack: 'array', awaiting: 'array', toVerify: 'array', toMerge: 'array', open: 'array', stale: 'array', holds: 'array', unread: 'number', newest: 'array', root: 'string', dirty: 'number', next: 'string' }),
+ resume: shape({ me: 'object', all: 'array', requests: 'array', holding: 'array', sentBack: 'array', awaiting: 'array', toVerify: 'array', toMerge: 'array', open: 'array', stale: 'array', doctrineNotes: 'array', holds: 'array', unread: 'number', newest: 'array', root: 'string', dirty: 'number', next: 'string' }),
whoami: shape({ id: 'string', lane: 'string', path: 'string', model: 'string', displayName: 'string' }),
lanes: shape({ lanes: 'object', shared: 'array', coordinator: 'string' }),
resources: shape({ resources: 'array' }),
diff --git a/test/doctrine-rulings.test.js b/test/doctrine-rulings.test.js
new file mode 100644
index 00000000..4e3ad60a
--- /dev/null
+++ b/test/doctrine-rulings.test.js
@@ -0,0 +1,108 @@
+/** Person-approved rulings reach independent, unadvanced Git checkouts [D1,D3,B27]. */
+import assert from 'node:assert/strict';
+import {
+ readFileSync,
+ writeFileSync,
+} from 'node:fs';
+import { join } from 'node:path';
+import { test } from 'node:test';
+import { createE2eHelpers } from './e2e-helpers.js';
+import { parseSpec } from '../src/spec.js';
+
+test('a ruling the person approves reaches every agent once [D1,D3,B27]', (t) => {
+ const e2e = createE2eHelpers();
+ t.after(e2e.cleanup);
+ const box = e2e.project('true');
+ const other = join(box.dir, 'web-2');
+ box.git(box.repo, 'worktree', 'add', '-q', '-b', 'web/two', other);
+ const joined = box.run(other, 'join', 'web', '--model', 'Fixture');
+ assert.equal(joined.code, 0, joined.err || joined.out);
+ const checkouts = [box.repo, box.web, other];
+ const oldHeads = checkouts.map(path => box.git(path, 'rev-parse', 'HEAD'));
+ /** Run a real CLI command and require its public, versioned successful result. */
+ function json(path, ...args) {
+ const result = box.run(path, ...args, '--json');
+ assert.equal(result.code, 0, result.err || result.out);
+ return JSON.parse(result.out);
+ }
+ for (const path of checkouts) assert.deepEqual(json(path, 'resume').doctrineNotes ?? [], []);
+ const file = join(box.repo, 'DOCTRINE.md');
+ const before = readFileSync(file, 'utf8');
+ const missing = box.run(box.repo, 'spec', 'draft', 'Keep the approved ruling.', '--doctrine', '--json');
+ assert.notEqual(missing.code, 0, 'a proposal without its source is refused');
+ assert.equal(readFileSync(file, 'utf8'), before, 'a source-less proposal writes no row');
+
+ const rule = 'A builder escalates after two failed attempts.';
+ const drafted = json(box.repo, 'spec', 'draft', rule, '--doctrine', '--source', 'chat, 2026-10-16');
+ assert.match(JSON.parse(missing.out).error.message, /source/iu);
+ assert.equal(drafted.id, 'doctrine:' + drafted.row.id);
+ const row = parseSpec(readFileSync(file, 'utf8')).rows.find(row => row.id === drafted.row.id);
+ assert.equal(row.status, 'draft');
+ assert.ok(row.text.includes(rule) && row.text.includes('chat, 2026-10-16'), 'the proposed row keeps its source');
+ const foreign = box.run(box.web, 'spec', 'draft', 'A builder cannot propose standing rules.',
+ '--doctrine', '--source', 'shout 42', '--json');
+ assert.notEqual(foreign.code, 0);
+ assert.equal(JSON.parse(foreign.out).error.code, 'COORDINATOR_ONLY');
+ for (const path of checkouts) assert.deepEqual(json(path, 'resume').doctrineNotes, [], 'draft rulings are not announced');
+ box.git(box.repo, 'add', 'DOCTRINE.md');
+ box.git(box.repo, 'commit', '-q', '-m', 'docs(doctrine): propose ruling');
+ for (const path of checkouts) assert.deepEqual(json(path, 'resume').doctrineNotes, [], 'a committed draft is not in force either');
+ json(box.repo, 'spec', 'approve', drafted.id);
+ for (const path of checkouts) assert.deepEqual(json(path, 'resume').doctrineNotes, [], 'pending apply is not in force');
+ json(box.repo, 'spec', 'apply');
+ const mainNotes = json(box.repo, 'resume').doctrineNotes;
+ assert.equal(mainNotes.length, 1);
+ assert.equal(mainNotes[0].id, drafted.id);
+ assert.equal(mainNotes[0].text, row.text);
+ const text = box.run(box.web, 'resume');
+ assert.equal(text.code, 0, text.err || text.out);
+ assert.ok(text.out.includes(`new doctrine ${drafted.id} — ${row.text}`));
+ assert.deepEqual(json(other, 'resume').doctrineNotes, mainNotes, 'each checkout sees the same approved ruling');
+ for (const path of checkouts) assert.deepEqual(json(path, 'resume').doctrineNotes, [], 'the notice is consumed only in this checkout');
+ assert.equal(box.git(box.web, 'rev-parse', 'HEAD'), oldHeads[1]);
+ assert.equal(box.git(other, 'rev-parse', 'HEAD'), oldHeads[2]);
+ assert.ok(!readFileSync(join(box.web, 'DOCTRINE.md'), 'utf8').includes(rule), 'no fixture silently synchronizes the old worktree');
+
+ const item = json(box.repo, 'add', 'web', 'Follow the approved ruling', '--specs', drafted.id,
+ '--criterion', 'The builder follows the approved ruling.', '--check', 'true').item;
+ json(box.web, 'claim', String(item.item_id));
+ const frozen = JSON.parse(json(box.web, 'show', String(item.item_id)).item_frozen);
+ assert.deepEqual(frozen.rows.map(row => [row.id, row.text]), [[drafted.id, row.text]], 'claim freezes shared approved text');
+ assert.equal(box.git(box.web, 'rev-parse', 'HEAD'), oldHeads[1], 'a doctrine citation does not advance the checkout');
+ box.git(box.repo, 'add', 'DOCTRINE.md');
+ box.git(box.repo, 'commit', '-q', '-m', `docs(doctrine): approve ruling [${drafted.id}]`);
+
+ const replacement = 'A builder stops after two failed attempts. Source: chat, 2026-10-16';
+ json(box.repo, 'spec', 'approve', drafted.id, '--text', replacement);
+ assert.deepEqual(json(box.web, 'resume').stale, [], 'an unapplied change does not replace the in-force ruling');
+ json(box.repo, 'spec', 'apply');
+ const changed = json(box.web, 'resume');
+ assert.ok(changed.stale.some(entry => entry.id === item.item_id && entry.rows.includes(drafted.id)), 'the old checkout detects the changed frozen row');
+ assert.equal(changed.doctrineNotes[0].text, replacement);
+ const again = json(box.web, 'resume');
+ assert.deepEqual(again.doctrineNotes, []);
+ assert.ok(again.stale.some(entry => entry.id === item.item_id), 'staleness remains after its one-time notice');
+
+ const declined = json(box.repo, 'spec', 'draft', 'A ruling the person declines.', '--doctrine', '--source', 'shout 42');
+ json(box.repo, 'spec', 'decline', declined.id, '--reason', 'The person declines this proposal.');
+ json(box.repo, 'spec', 'apply');
+ assert.ok(json(other, 'resume').doctrineNotes.every(note => note.id !== declined.id), 'declined rulings are never announced');
+
+ box.git(box.repo, 'add', 'DOCTRINE.md');
+ box.git(box.repo, 'commit', '-q', '-m', `docs(doctrine): revise ruling [${drafted.id}]`);
+ const approvedSource = readFileSync(file, 'utf8');
+ const retiredSource = approvedSource.replace(`- ${drafted.row.id} [approved, must]`, `- ${drafted.row.id} [retired, must]`);
+ assert.notEqual(retiredSource, approvedSource);
+ writeFileSync(file, retiredSource);
+ box.git(box.repo, 'add', 'DOCTRINE.md');
+ box.git(box.repo, 'commit', '-q', '-m', 'docs(doctrine): retire ruling');
+ // An old applied receipt must not revive a retired committed rule via an unstaged restoration.
+ writeFileSync(file, approvedSource);
+ assert.ok(json(other, 'resume').doctrineNotes.every(note => note.id !== drafted.id), 'committed retirement wins over a stale receipt and working-copy restoration');
+ const retiredItem = json(box.repo, 'add', 'web', 'Do not revive the retired ruling', '--specs', drafted.id,
+ '--criterion', 'A stale applied receipt cannot revive committed retirement.', '--check', 'true').item;
+ const refused = box.run(other, 'claim', String(retiredItem.item_id), '--json');
+ assert.notEqual(refused.code, 0, 'the stale receipt cannot make a retired rule claimable');
+ assert.equal(JSON.parse(refused.out).error.code, 'UNKNOWN_SPEC');
+ assert.equal(json(other, 'show', String(retiredItem.item_id)).item_status, 'open', 'refusal leaves the item unclaimed');
+});