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): inherit labelled standard rules [D1,D2,D3,D4]

Corey Olsonc0f9b4d61831
diff --git a/src/cli.js b/src/cli.js
index 1b7fc430..9f0cb288 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -9,6 +9,7 @@ import { pathToFileURL } from 'node:url';
import { parseArgs } from 'node:util';
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 { contains, differFromHead, git, headCommit, headTree, isClean, repoInfo, resolveCommit, tryGit, untracked } from './git.js';
import {
@@ -329,7 +330,7 @@ function context(io) {
const info = repoInfo(io.cwd);
const config = configHere(info);
const file = join(info.commonDir, 'pullboard', 'board.sqlite');
- return { info, config, file, io, clock: io.clock ?? store.systemClock };
+ return { info, config, file, doctrine: loadDoctrine(info.root, config), io, clock: io.clock ?? store.systemClock };
}
/**
@@ -1460,7 +1461,7 @@ function specCommand(io, { first, second, rest, values }) {
}
const spec = loadSpec(ctx.info.root, ctx.config);
if (!spec.exists) throw new Refused('NO_SPEC', `no ${ctx.config.spec}; run: pullboard init`);
- const practice = loadSpec(ctx.info.root, { ...ctx.config, spec: ctx.config.practice });
+ const practice = ctx.doctrine;
if (first === 'check' || first === undefined) {
const files = [[ctx.config.spec, spec], ...(practice.exists ? [[ctx.config.practice, practice]] : [])];
let errors = 0;
@@ -1470,7 +1471,7 @@ function specCommand(io, { first, second, rest, values }) {
findings.forEach((finding) => messages.push(`${name}:${finding.line} ${finding.id ?? ''} ${finding.level}: ${finding.message}`.replace(' ', ' ')));
const history = committedIds(ctx.info.root, name);
const cited = name === ctx.config.spec ? citations(ctx, history) : new Map();
- const lost = permanenceProblems(parsed, { committed: history.ids, cited });
+ const lost = permanenceProblems(parsed === practice ? practice.repo : parsed, { committed: history.ids, cited });
lost.forEach((problem) => messages.push(`${name}: ${problem.id} error: ${problem.message}`));
const fileErrors = findings.filter((finding) => finding.level === 'error').length + lost.length;
errors += fileErrors;
@@ -1480,8 +1481,9 @@ function specCommand(io, { first, second, rest, values }) {
unnamed.forEach((problem) => messages.push(`${ctx.config.spec}: error: ${problem}`));
errors += unnamed.length;
if (values.json && !errors) {
- const rows = files.flatMap(([file, parsed]) => parsed.rows.map(({ id, status, tier, text, gate, serves, section, line }) => (
- { id, status, tier, text, gate, serves, section, line, file }
+ const rows = files.flatMap(([file, parsed]) => parsed.rows.map(({ id, status, tier, text, gate, serves, section, line, origin, version, reason, file: source }) => (
+ { id, status, tier, text, gate, serves, section, line, file: source ?? file,
+ ...(origin ? { origin, version, reason } : {}) }
)));
io.result({ rows });
} else messages.forEach((message) => io.say(message));
diff --git a/src/doctrine.js b/src/doctrine.js
new file mode 100644
index 00000000..9d76bf93
--- /dev/null
+++ b/src/doctrine.js
@@ -0,0 +1,63 @@
+/** The shared house rules (D1–D4): one packaged standard and a repo's explicit changes to it. */
+import { readFileSync } from 'node:fs';
+import { loadSpec, parseSpec } from './spec.js';
+
+export const STANDARD_VERSION = 1;
+
+/** Read the shipped rows, preserving their source lines and marking the standard's version. */
+export function standardDoctrine() {
+ const source = readFileSync(new URL('./standard-doctrine.md', import.meta.url), 'utf8');
+ const parsed = parseSpec(source);
+ const name = 'standard doctrine ' + STANDARD_VERSION;
+ return {
+ ...parsed, name, exists: true, version: STANDARD_VERSION,
+ sections: parsed.sections.map((section) => ({ ...section, origin: 'standard ' + STANDARD_VERSION })),
+ rows: parsed.rows.map((row) => ({ ...row, origin: 'standard ' + STANDARD_VERSION, version: STANDARD_VERSION, reason: '', file: name })),
+ };
+}
+
+/** A decline's reason is its row text; a trailing-field-only row has no reason. */
+function declineReason(row) {
+ const text = row.text.trim();
+ return row.status === 'wont' && !/^\|\s*[a-z]+\s*:/i.test(text) ? text : '';
+}
+
+/**
+ * Merge the inherited standard with the repo's rows. Overrides replace only the matching PB row;
+ * duplicate repo rows remain visible to lint, and a decline must state its reason explicitly.
+ */
+export function loadDoctrine(root, config = {}) {
+ const name = config.practice ?? 'PRACTICE.md';
+ const repo = loadSpec(root, { ...config, spec: 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));
+ const problems = [...standard.problems, ...repo.problems];
+ for (const row of repo.rows) {
+ if (/^PB\d/.test(row.id) && !inherited.has(row.id)) {
+ problems.push({ line: row.line, id: row.id, message: 'no such rule in standard ' + STANDARD_VERSION });
+ }
+ if (inherited.has(row.id) && row.status === 'wont' && !declineReason(row)) {
+ problems.push({ line: row.line, id: row.id, message: 'declining a standard rule needs a reason in its text: - PB2 [wont] <why>' });
+ }
+ }
+ return {
+ title: repo.title || 'Doctrine', intro: repo.intro, name, file: repo.file,
+ exists: true, repoExists: repo.exists, version: STANDARD_VERSION, repo,
+ problems,
+ sections: [...standard.sections, ...repo.sections.map((section) => ({ ...section, origin: 'repo' }))],
+ rows: [
+ ...standard.rows.filter((row) => !overrides.has(row.id)),
+ ...repo.rows.map((row) => ({ ...row, origin: 'repo', version: null, reason: declineReason(row), file: name })),
+ ],
+ };
+}
+
+/** A current, labelled rules list for AGENTS.md and cold-start run packs. */
+export function doctrineText(doctrine) {
+ return doctrine.rows.map((row) => {
+ const state = row.status + (row.tier ? ', ' + row.tier : '');
+ const reason = row.reason && row.reason !== row.text ? ' Reason: ' + row.reason : '';
+ return '- ' + row.id + ' (' + row.origin + ') [' + state + '] ' + row.text + reason;
+ }).join('\n');
+}
diff --git a/src/index.js b/src/index.js
index 6b7d0bec..0347bc3c 100644
--- a/src/index.js
+++ b/src/index.js
@@ -9,3 +9,4 @@ export { parseSpec, lintSpec, frozenCriterion, citedIds } from './spec.js';
export { commitMsgProblems, secretsIn, blockedPaths } from './hooks.js';
export { Refused } from './refused.js';
export { main } from './cli.js';
+export { loadDoctrine, standardDoctrine, STANDARD_VERSION } from './doctrine.js';
diff --git a/src/init.js b/src/init.js
index 214685d0..9f08fc56 100644
--- a/src/init.js
+++ b/src/init.js
@@ -6,11 +6,12 @@
*/
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { basename, join } from 'node:path';
-import { CONFIG_FILE, COORDINATOR } from './config.js';
+import { CONFIG_FILE, COORDINATOR, loadConfig } from './config.js';
+import { loadDoctrine } from './doctrine.js';
import { installHooks } from './hooks.js';
import { Refused } from './refused.js';
import { installSkills } from './skills.js';
-import { AGENTS_START, agentsBlock, configTemplate, practiceTemplate, specTemplate } from './templates.js';
+import { AGENTS_END, AGENTS_START, agentsBlock, configTemplate, practiceTemplate, specTemplate } from './templates.js';
const NPM_DEFAULT_TEST = 'echo "Error: no test specified" && exit 1';
@@ -88,13 +89,27 @@ function writeNew(file, text, name) {
function writeAgentDocs(root) {
const notes = [];
const agents = join(root, 'AGENTS.md');
+ const block = agentsBlock(loadDoctrine(root, loadConfig(root)));
if (!existsSync(agents)) {
- writeFileSync(agents, `# AGENTS.md\n\n${agentsBlock()}`);
+ writeFileSync(agents, `# AGENTS.md\n\n${block}`);
notes.push('wrote AGENTS.md');
} else if (!readFileSync(agents, 'utf8').includes(AGENTS_START)) {
- appendFileSync(agents, `\n${agentsBlock()}`);
+ appendFileSync(agents, `\n${block}`);
notes.push('added the pullboard section to AGENTS.md');
- } else notes.push('kept AGENTS.md');
+ } else {
+ const previous = readFileSync(agents, 'utf8');
+ const start = previous.indexOf(AGENTS_START);
+ const end = previous.indexOf(AGENTS_END, start);
+ if (end < 0) notes.push('kept AGENTS.md (incomplete pullboard markers; restore the closing marker to refresh)');
+ else {
+ const updated = previous.slice(0, start) + block.trimEnd() + previous.slice(end + AGENTS_END.length);
+ if (updated === previous) notes.push('kept AGENTS.md');
+ else {
+ writeFileSync(agents, updated);
+ notes.push('updated the pullboard section in AGENTS.md');
+ }
+ }
+ }
const claude = join(root, 'CLAUDE.md');
if (!existsSync(claude)) {
writeFileSync(claude, '@AGENTS.md\n');
diff --git a/src/run.js b/src/run.js
index 4fa1566c..4ba49067 100644
--- a/src/run.js
+++ b/src/run.js
@@ -14,7 +14,8 @@ import { appendFileSync, existsSync, mkdirSync, readFileSync, rmSync, statSync,
import { join } from 'node:path';
import * as store from './board.js';
import { briefFiles } from './brief.js';
-import { COORDINATOR } from './config.js';
+import { CONFIG_FILE, COORDINATOR, loadConfig } from './config.js';
+import { doctrineText, loadDoctrine } from './doctrine.js';
import { digestOf, runGate } from './gate.js';
import { contains, git, headCommit, isClean, tryGit, untracked } from './git.js';
import { laneNames, outOfLane } from './lanes.js';
@@ -114,6 +115,8 @@ function restore(root, start, paths) {
*/
export function packText(root, item, { attempt, attempts, digest, earlier = [], related = [] }) {
const rows = item.item_frozen ? JSON.parse(item.item_frozen).rows : [];
+ const config = existsSync(join(root, CONFIG_FILE)) ? loadConfig(root) : {};
+ const doctrine = loadDoctrine(root, config);
const files = briefFiles(item.item_brief);
let budget = PACK_FILE_CHARS;
const contents = files.map((path) => {
@@ -135,6 +138,9 @@ export function packText(root, item, { attempt, attempts, digest, earlier = [],
`The check that proves it, which the runner runs after you finish: \`${item.item_check}\``,
...(rows.length ? ['', '## Spec rows it serves', ...rows.map((row) => `- ${row.id}: ${row.text}`)] : []),
'',
+ '## Doctrine: standard 1 and this repo',
+ doctrineText(doctrine),
+ '',
'## Brief',
item.item_brief || '(none)',
'',
diff --git a/src/standard-doctrine.md b/src/standard-doctrine.md
new file mode 100644
index 00000000..4f730e63
--- /dev/null
+++ b/src/standard-doctrine.md
@@ -0,0 +1,18 @@
+# Pullboard standard doctrine
+
+Version: 1
+
+## Rules
+- PB1 [approved, must] Ask, don't guess: a decision only the person can make waits for them. | gate: review
+- PB2 [approved, must] Destructive or irreversible actions wait for the person's OK. | gate: review
+- PB3 [approved, must] Claims come with evidence: say what ran and what it showed, never "should work". | gate: review
+- PB4 [approved, must] A test must be able to fail: see it fail on broken code before trusting it. | gate: review
+- PB5 [approved, must] Never weaken a test or a check to make it pass; fix the code. | gate: review
+- PB6 [approved, must] Tests pass before a change merges. | gate: the project's gate
+- PB7 [pending, aim] Tests touch nothing outside a temporary sandbox. | gate: review
+- PB8 [approved, must] No secrets or sensitive info in the repo; test data is synthetic. | gate: review
+- PB9 [approved, must] Headers: type(scope): subject [ids], 72 characters at most. A body only for a non-obvious why, three sentences at most. | gate: commit-msg hook, review
+- PB10 [approved, must] Comments explain why, not what; no commented-out code. | gate: review
+- PB11 [approved, must] A new dependency states why it is needed and what it pulls in. | gate: review
+- PB12 [approved, must] Questions go on the board, one step up the chain, and the asker keeps working on what it can meanwhile. | gate: review
+- PB7: is "nothing outside a temporary sandbox" universal? Integration tests against local services may need more room.
diff --git a/src/templates.js b/src/templates.js
index f5ff5710..f17dead0 100644
--- a/src/templates.js
+++ b/src/templates.js
@@ -2,6 +2,7 @@
* What `pullboard init` writes into a repo: the config, a starter spec, and the agent instructions
* every coding agent reads (AGENTS.md, which CLAUDE.md points at).
*/
+import { doctrineText, standardDoctrine } from './doctrine.js';
export const AGENTS_START = '<!-- pullboard:start -->';
export const AGENTS_END = '<!-- pullboard:end -->';
@@ -55,56 +56,27 @@ Write each requirement as one row under its section, in this format. The fence k
}
/**
- * A starter PRACTICE.md: the house rules as rows, in the spec's own format. A standard to edit, not
- * a law: the project keeps, changes or retires each row, and approves what it keeps. A row whose gate
- * names a check is enforced by that check; a row gated by review guides agents and reviewers.
+ * A repo's own rule sections. The package supplies the inherited rows once, rather than copying
+ * them into every repo and leaving each copy to drift.
*
* @returns {string}
*/
export function practiceTemplate() {
return `# Practice
-How this project is built: the house rules, as rows. SPEC.md says what to build; this file says how. Edit it for your project: keep, change or retire each row, and approve what you keep. A row whose gate names a check fails the build when broken; a row gated by review guides agents and reviewers.
-
-Statuses: approved = in force · draft = proposed · wont = considered and declined, id kept · retired = dropped, id kept. Ids are permanent: never delete or renumber a row. Tiers: must · aim.
+Inherits Pullboard standard doctrine version 1.
## W · Writing
-- W1 [approved, must] Numbers over adjectives. No hedges, no filler. | gate: review
-- W2 [approved, must] Commit headers are type(scope): subject [ids], 72 characters at most. | gate: commit-msg hook
-- W3 [draft, aim] Ban the filler words basically, simply, just, very, robust, seamless, leverage. | gate: commit-msg hook, commits.banned
-- W4 [approved, must] Spec ids go in commits and code headers, never in words meant for people. | gate: review
-- W5 [draft, aim] One record per decision, at most 100 words, citing rows and naming who decided. | gate: review
## C · Code
-- C1 [draft, must] Files under 1,000 lines; functions under 60; complexity 10; nesting 3; parameters 3. | gate: linter
-- C2 [draft, must] Every exported function has a doc comment saying why, not restating its name. | gate: linter
-- C3 [draft, must] Comments explain why and sit above the code; no commented-out code in the main line. | gate: linter, review
-- C4 [draft, must] Errors and logs never echo input values. | gate: review
-- C5 [draft, aim] Plain over clever: early returns, named intermediate values, one idea per line. | gate: review
-- C6 [draft, must] No inline ignore comments; exceptions live in config, each with its reason. | gate: linter
-- C7 [approved, must] One implementation per concern: use another lane's module, never a copy of it. | gate: review
## T · Tests
-- T1 [approved, must] Every feature and fix cites the spec rows it serves, and a test proves each one. | gate: commit-msg hook, review
-- T2 [draft, must] A test fails when the code is wrong: break the code once and watch it go red. | gate: mutation testing on critical code
-- T3 [draft, must] No test marked as expected to fail without an open item. | gate: review
-- T4 [draft, aim] Tests use real dependencies where practical, not mocks of them. | gate: review
-- T5 [approved, must] Tests and checks never write outside a temporary directory. | gate: review
## G · Git and the gate
-- G1 [approved, must] The gate passes on a clean tree before every push. | gate: pre-push hook
-- G2 [approved, must] Never bypass a hook. Never rewrite the main line, except to remove a secret. | gate: review
-- G3 [approved, must] Work stays in its lane; changes elsewhere go through the lane's owner. | gate: pre-commit lane check
-- G4 [approved, must] The builder never verifies its own work. | gate: pullboard verify
## D · Dependencies
-- D1 [draft, must] A new dependency states its need, the built-in it replaces, and what it pulls in. | gate: review
-- D2 [draft, aim] Install scripts only from native drivers. | gate: package manager allowlist
## S · Security and data
-- S1 [approved, must] No secrets and no env files in git. | gate: pre-commit secret scan
-- S2 [draft, must] Real customer data never enters the repo or an agent's context; test data is synthetic. | gate: review
-- S3 [draft, must] Every entry point declares who may use it; anything undeclared is denied. | gate: review
`;
}
@@ -113,7 +85,7 @@ Statuses: approved = in force · draft = proposed · wont = considered and decli
*
* @returns {string}
*/
-export function agentsBlock() {
+export function agentsBlock(doctrine = standardDoctrine()) {
return `${AGENTS_START}
## Working here: pullboard
@@ -121,7 +93,11 @@ This repo runs on pullboard: a work board, lanes and a spec that live in git. No
**Source of truth.** \`SPEC.md\` holds every requirement as a row with an id, like \`G1.2\`. Code follows the spec. Commits cite the ids they serve: \`feat(scope): subject [G1.2]\`. Only a person approves or changes an approved row. Ids are permanent: a row the person cuts stays, marked \`wont\` (won't build), so every commit that cites it keeps its meaning.
-**House rules.** \`PRACTICE.md\` holds how this project is built, in the same row format. Its approved rows are in force; follow them as you would the spec.
+**House rules.** This repo inherits Pullboard standard doctrine version 1. PRACTICE.md adds the repo's own rows, overrides a standard rule by its PB id, or declines it with a wont row and its reason as the row text: - PB7 [wont] <why>. Approved rows are in force; follow them as you would the spec. Run pullboard spec --json to read the current merged rules. Re-run pullboard init after changing PRACTICE.md to refresh this managed guidance.
+
+### Current doctrine
+
+${doctrineText(doctrine)}
**Role guides.** \`pullboard prompt run\`, \`decompose\`, \`plan\`, \`signoff\`, \`review\` and \`verify\` print the guide for each role. Claude Code also has them as skills. The agent in the main checkout runs the whole team by the run guide (the pullboard-run skill).
diff --git a/test/doctrine.test.js b/test/doctrine.test.js
new file mode 100644
index 00000000..d41368cb
--- /dev/null
+++ b/test/doctrine.test.js
@@ -0,0 +1,77 @@
+/** Standard doctrine and repo overrides (D1–D4), using real private files. */
+import assert from 'node:assert/strict';
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { test } from 'node:test';
+import { packText } from '../src/run.js';
+import { doctrineText, loadDoctrine, standardDoctrine, STANDARD_VERSION } from '../src/doctrine.js';
+import { lintSpec, parseSpec } from '../src/spec.js';
+
+/** A private repo's configured practice file, automatically removed after its test. */
+function practiceBox(t, text, name = 'PRACTICE.md') {
+ const root = mkdtempSync(join(tmpdir(), 'pullboard-doctrine-'));
+ t.after(() => rmSync(root, { recursive: true, force: true }));
+ if (text !== undefined) writeFileSync(join(root, name), text);
+ return { root, config: { practice: name } };
+}
+
+test('standard version1 ships exactly the twelve RFC rules and is inherited without a practice file [D1,D2]', (t) => {
+ const standard = standardDoctrine();
+ const rfc = parseSpec(readFileSync(new URL('../docs/rfcs/0001-standard-doctrine.md', import.meta.url), 'utf8'));
+ /** Comparable rule fields; the packaged file legitimately has different source lines. */
+ const fields = ({ id, status, tier, text, gate, serves }) => ({ id, status, tier, text, gate, serves });
+ assert.deepEqual(standard.rows.map(fields), rfc.rows.filter((row) => /^PB\d/.test(row.id)).map(fields));
+ assert.equal(standard.rows.length, 12);
+ assert.equal(STANDARD_VERSION, 1);
+ assert.match(readFileSync(new URL('../src/standard-doctrine.md', import.meta.url), 'utf8'), /\nVersion: 1\n/);
+ const box = practiceBox(t);
+ const merged = loadDoctrine(box.root, box.config);
+ assert.equal(merged.repoExists, false);
+ assert.deepEqual(merged.rows, standard.rows);
+ assert.deepEqual(lintSpec(merged), []);
+ assert.ok(merged.rows.every((row) => row.origin === 'standard 1' && row.version === 1));
+});
+
+test('repo rules override and decline inherited rows with a reason, keeping source labels and legacy text [D2,D3,D4]', (t) => {
+ const text = '# Local rules\n\n## Team\n- PB2 [approved, must] Deletion needs two approvals. | gate: review\n- PB8 [wont] No persistent data is stored.\n- R1 [fact] An existing local rule.\n';
+ const box = practiceBox(t, text, 'ways.md');
+ const merged = loadDoctrine(box.root, box.config);
+ assert.deepEqual(lintSpec(merged), []);
+ assert.equal(merged.rows.length, 13);
+ const own = merged.rows.filter((row) => row.origin === 'repo');
+ assert.deepEqual(own.map((row) => row.id), ['PB2', 'PB8', 'R1']);
+ assert.ok(own.every((row) => row.file === 'ways.md' && row.version === null));
+ assert.ok(merged.rows.every(row => 'origin' in row && 'version' in row && 'reason' in row));
+ assert.equal(merged.rows.filter((row) => row.id === 'PB2').length, 1);
+ assert.equal(own[0].text, 'Deletion needs two approvals.');
+ assert.equal(own[1].reason, 'No persistent data is stored.');
+ assert.equal(readFileSync(join(box.root, 'ways.md'), 'utf8'), text);
+ assert.match(doctrineText(merged), /PB1 \(standard 1\)/);
+ assert.match(doctrineText(merged), /PB8 \(repo\).*No persistent data/);
+});
+
+test('a missing or blank decline reason fails lint, and duplicate repo overrides are not silently discarded [D3]', (t) => {
+ const box = practiceBox(t);
+ for (const trailing of [' ', ' | gate: review']) {
+ writeFileSync(join(box.root, 'PRACTICE.md'), '# Rules\n\n## Local\n- PB2 [wont]' + trailing + '\n');
+ const findings = lintSpec(loadDoctrine(box.root, box.config));
+ assert.ok(findings.some((finding) => finding.level === 'error' && finding.id === 'PB2' && /reason/.test(finding.message)));
+ }
+ writeFileSync(join(box.root, 'PRACTICE.md'), '# Rules\n\n## Local\n- PB2 [fact] First.\n- PB2 [fact] Second.\n');
+ assert.ok(lintSpec(loadDoctrine(box.root, box.config)).some((finding) => /duplicate id/.test(finding.message)));
+});
+
+
+test('cold-start run pack uses configured legacy practice and labels each source [D2,D3,D4]', (t) => {
+ const text = '# Legacy rules\n\n## Local\n- PB2 [fact] Delete only after review.\n- PB8 [wont] This fixture stores no secrets.\n- R1 [fact] The legacy rule stays.\n';
+ const box = practiceBox(t, text, 'ways.md');
+ writeFileSync(join(box.root, 'pullboard.json'), JSON.stringify({ gate: 'true', spec: 'SPEC.md', practice: 'ways.md', lanes: { core: { owns: ['src/'] } } }));
+ const pack = packText(box.root, { item_id: 1, item_title: 'Fixture', item_criterion: 'A local proof.', item_lane: 'core', item_brief: '', item_check: 'true' }, { attempt: 1, attempts: 1, digest: '', earlier: [] });
+ assert.match(pack, /PB1 \(standard 1\)/);
+ assert.match(pack, /PB2 \(repo\) \[fact\] Delete only after review/);
+ assert.match(pack, /PB8 \(repo\) \[wont\] This fixture stores no secrets/);
+ assert.match(pack, /R1 \(repo\).*The legacy rule stays/);
+ assert.doesNotMatch(pack, /PB2 \(standard 1\)/);
+ assert.equal(readFileSync(join(box.root, 'ways.md'), 'utf8'), text);
+});
diff --git a/test/e2e.test.js b/test/e2e.test.js
index f38b3ce4..6a248d00 100644
--- a/test/e2e.test.js
+++ b/test/e2e.test.js
@@ -128,7 +128,12 @@ test('init writes config, spec, agent docs and hooks once, and never clobbers [I
assert.equal(readFileSync(join(repo, 'CLAUDE.md'), 'utf8'), '@AGENTS.md\n');
assert.equal(box.git(repo, 'config', '--get', 'core.hooksPath'), '.githooks');
for (const hook of ['pre-commit', 'commit-msg', 'pre-push']) assert.ok(existsSync(join(repo, '.githooks', hook)));
- assert.ok(readFileSync(join(repo, 'PRACTICE.md'), 'utf8').startsWith('# Practice'));
+ const practice = readFileSync(join(repo, 'PRACTICE.md'), 'utf8');
+ assert.ok(practice.startsWith('# Practice'));
+ assert.deepEqual(parseSpec(practice).rows, [], 'fresh init copies no standard rules [D4]');
+ assert.equal(parseSpec(practice).sections.length, 6);
+ assert.equal(practice.split('Inherits Pullboard standard doctrine version 1.').length, 2);
+ assert.match(agents, /PB1 \(standard 1\)/, 'fresh guidance shows inherited rules [D3]');
assert.ok(existsSync(join(repo, '.claude', 'skills', 'pullboard-decompose', 'SKILL.md')));
assert.match(second.out, /kept PRACTICE.md/);
assert.match(second.out, /kept the Claude Code skills/);
@@ -1368,3 +1373,59 @@ test('the view rebuilds the page only when the board changed, so a refresh canno
const page = cockpitSource();
assert.match(page, /if \(text !== seen\) \{\s*seen = text;\s*data = next;\s*render\(\);\s*\}/);
});
+
+test('doctrine init preserves legacy rules and outside guidance, refreshes labels and refuses empty declines [D1,D2,D3,D4,S8]', () => {
+ const box = sandbox();
+ const repo = join(box.dir, 'doctrine');
+ mkdirSync(repo);
+ box.git(repo, 'init', '-q', '-b', 'main');
+ const legacy = '# Legacy practice\n\n## Local\n- L1 [fact] Keep the existing local rule.\n';
+ const ways = '# Our ways\n\n## Rules\n- PB2 [fact] Delete only after team review.\n- PB8 [wont] This fixture stores only generated data.\n- R1 [fact] Keep the configured legacy rule.\n';
+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify({ ...CONFIG, gate: 'true', practice: 'ways.md' }));
+ writeFileSync(join(repo, 'PRACTICE.md'), legacy);
+ writeFileSync(join(repo, 'ways.md'), ways);
+ writeFileSync(join(repo, 'AGENTS.md'), '# Owner guidance\n\nKeep this prefix.\n');
+ const first = box.run(repo, 'init');
+ assert.equal(first.code, 0, first.err);
+ assert.equal(readFileSync(join(repo, 'PRACTICE.md'), 'utf8'), legacy);
+ assert.equal(readFileSync(join(repo, 'ways.md'), 'utf8'), ways);
+ let agents = readFileSync(join(repo, 'AGENTS.md'), 'utf8');
+ assert.match(agents, /PB1 \(standard 1\)/);
+ assert.match(agents, /PB2 \(repo\) \[fact\] Delete only after team review/);
+ assert.match(agents, /PB8 \(repo\) \[wont\] This fixture stores only generated data/);
+ assert.doesNotMatch(agents, /PB2 \(standard 1\)/);
+ const shown = box.run(repo, 'spec', '--json');
+ assert.equal(shown.code, 0, shown.out);
+ const document = JSON.parse(shown.out);
+ assert.equal(document.version, 1);
+ assert.equal(document.rows.length, 13);
+ assert.deepEqual(document.rows.filter(row => row.origin === 'repo').map(row => [row.id, row.version, row.reason, row.file]), [
+ ['PB2', null, '', 'ways.md'], ['PB8', null, 'This fixture stores only generated data.', 'ways.md'], ['R1', null, '', 'ways.md'],
+ ]);
+ writeFileSync(join(repo, 'AGENTS.md'), agents + '\nKeep this footer.\n');
+ const updatedWays = ways.replace('Delete only after team review.', 'Delete only after pair review.');
+ writeFileSync(join(repo, 'ways.md'), updatedWays);
+ const refreshed = box.run(repo, 'init');
+ assert.equal(refreshed.code, 0, refreshed.err);
+ assert.match(refreshed.out, /updated the pullboard section/);
+ agents = readFileSync(join(repo, 'AGENTS.md'), 'utf8');
+ assert.ok(agents.startsWith('# Owner guidance\n\nKeep this prefix.\n'));
+ assert.ok(agents.endsWith('\nKeep this footer.\n'));
+ assert.match(agents, /PB2 \(repo\).*Delete only after pair review/);
+ assert.equal(agents.split('<!-- pullboard:start -->').length, 2);
+ assert.equal(box.run(repo, 'init').code, 0);
+ assert.equal(readFileSync(join(repo, 'AGENTS.md'), 'utf8'), agents, 'managed guidance refresh is idempotent');
+ writeFileSync(join(repo, 'ways.md'), '# Our ways\n\n## Rules\n- PB2 [wont] \n');
+ const bad = box.run(repo, 'spec', '--json');
+ assert.equal(bad.code, 1);
+ assert.match(JSON.parse(bad.out).error.message, /declining a standard rule needs a reason in its text/);
+ writeFileSync(join(repo, 'ways.md'), '# Our ways\n\n## Rules\n- PB2 [wont] Declined. | reason: outside syntax\n');
+ assert.match(box.run(repo, 'spec', 'check').out, /unknown field/);
+ writeFileSync(join(repo, 'ways.md'), updatedWays);
+ box.git(repo, 'add', '-A');
+ box.git(repo, 'commit', '-q', '-m', 'chore: retain local doctrine');
+ writeFileSync(join(repo, 'ways.md'), updatedWays.replace('- PB2 [fact] Delete only after pair review.\n', ''));
+ const removed = box.run(repo, 'spec', 'check');
+ assert.equal(removed.code, 1);
+ assert.match(removed.out, /ways.md: PB2 error:.*ids are permanent/, 'inherited PB2 cannot hide removal of a committed repo override');
+});
diff --git a/test/package.test.js b/test/package.test.js
index a514eafe..14b99998 100644
--- a/test/package.test.js
+++ b/test/package.test.js
@@ -198,3 +198,11 @@ test('every import is a node: built-in or a relative file [P3]', () => {
const seen = found.flat().length;
assert.ok(seen > 50, `the scan found ${seen} imports in src/ and bin/; expected every file's`);
});
+
+test('the installable package includes the single inherited doctrine file [D1]', () => {
+ const packed = spawnSync('npm', ['pack', '--dry-run', '--json', '--ignore-scripts'], { cwd: ROOT, encoding: 'utf8' });
+ assert.equal(packed.status, 0, packed.stderr);
+ const files = JSON.parse(packed.stdout)[0].files.map(file => file.path);
+ assert.equal(files.filter(file => file === 'src/standard-doctrine.md').length, 1);
+ assert.ok(files.includes('src/doctrine.js'));
+});
diff --git a/test/practice.test.js b/test/practice.test.js
index 36cb4ea8..91f2f18b 100644
--- a/test/practice.test.js
+++ b/test/practice.test.js
@@ -9,13 +9,18 @@ import { join } from 'node:path';
import { test } from 'node:test';
import { ROLES, installSkills, promptFor, withoutFrontMatter } from '../src/skills.js';
import { lintSpec, parseSpec } from '../src/spec.js';
+import { standardDoctrine } from '../src/doctrine.js';
import { agentsBlock, practiceTemplate } from '../src/templates.js';
test('the standard practice lints clean, and every approved must-row names its enforcer [S6]', () => {
const practice = parseSpec(practiceTemplate());
assert.deepEqual(lintSpec(practice), []);
- assert.ok(practice.rows.length >= 20);
- const approvedMusts = practice.rows.filter((row) => row.status === 'approved' && row.tier === 'must');
+ assert.equal(practice.rows.length, 0, 'the repo starter no longer copies inherited rules [D4]');
+ assert.equal(practice.sections.length, 6);
+ assert.equal(practice.intro.filter(line => line === 'Inherits Pullboard standard doctrine version 1.').length, 1);
+ const standard = standardDoctrine();
+ assert.deepEqual(lintSpec(standard), []);
+ const approvedMusts = standard.rows.filter((row) => row.status === 'approved' && row.tier === 'must');
assert.ok(approvedMusts.length >= 8);
assert.ok(approvedMusts.every((row) => row.gate));
});
diff --git a/test/spec.test.js b/test/spec.test.js
index 91f60883..15cfc836 100644
--- a/test/spec.test.js
+++ b/test/spec.test.js
@@ -7,6 +7,7 @@ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSy
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { test } from 'node:test';
+import { standardDoctrine } from '../src/doctrine.js';
import {
citedIds,
deletedIds,
@@ -211,7 +212,11 @@ test('spec --json emits one versioned document with every field, including empty
const shown = box.run('--json');
assert.equal(shown.status, 0, shown.stderr);
const data = JSON.parse(shown.stdout);
- assert.deepEqual(data, {
+ const inherited = data.rows.filter(row => row.origin === 'standard 1');
+ assert.equal(data.rows.length, 4 + standardDoctrine().rows.length);
+ assert.deepEqual(inherited.map(row => row.id), standardDoctrine().rows.map(row => row.id));
+ assert.ok(inherited.every(row => row.file === 'standard doctrine 1' && row.version === 1 && row.reason === ''));
+ assert.deepEqual({ version: data.version, rows: data.rows.filter(row => row.file === 'SPEC.md') }, {
version: 1,
rows: [
{ id: 'G1', status: 'approved', tier: 'must', text: 'Same file twice is a no-op.', gate: 'idempotency test', serves: [], section: 'G · Goals', line: 6, file: 'SPEC.md' },
@@ -229,12 +234,13 @@ test('spec --json combines both configured files and keeps every row status [S13
assert.equal(shown.status, 0, shown.stderr);
const data = JSON.parse(shown.stdout);
assert.equal(data.version, 1);
- assert.equal(data.rows.length, 7);
+ assert.equal(data.rows.length, 7 + standardDoctrine().rows.length);
+ assert.equal(data.rows.filter(row => row.origin === 'standard 1').length, standardDoctrine().rows.length);
assert.ok(data.rows.slice(0, 4).every((row) => row.file === 'requirements.md'));
- assert.deepEqual(data.rows.slice(4), [
- { id: 'P1', status: 'fact', tier: '', text: 'A fact.', gate: '', serves: [], section: 'P · Practice', line: 4, file: 'ways.md' },
- { id: 'P2', status: 'pending', tier: 'must', text: 'A question.', gate: '', serves: [], section: 'P · Practice', line: 5, file: 'ways.md' },
- { id: 'P3', status: 'wont', tier: '', text: 'An old plan.', gate: '', serves: [], section: 'P · Practice', line: 6, file: 'ways.md' },
+ assert.deepEqual(data.rows.filter(row => row.file === 'ways.md'), [
+ { id: 'P1', status: 'fact', tier: '', text: 'A fact.', gate: '', serves: [], section: 'P · Practice', line: 4, file: 'ways.md', origin: 'repo', version: null, reason: '' },
+ { id: 'P2', status: 'pending', tier: 'must', text: 'A question.', gate: '', serves: [], section: 'P · Practice', line: 5, file: 'ways.md', origin: 'repo', version: null, reason: '' },
+ { id: 'P3', status: 'wont', tier: '', text: 'An old plan.', gate: '', serves: [], section: 'P · Practice', line: 6, file: 'ways.md', origin: 'repo', version: null, reason: 'An old plan.' },
]);
});
@@ -278,7 +284,7 @@ test('warning-only specs keep spec-check success while JSON stays a single docum
assert.match(check.stdout, /warning: 25 words/);
const shown = box.run('--json');
assert.equal(shown.status, 0, shown.stderr);
- assert.equal(JSON.parse(shown.stdout).rows.length, 5);
+ assert.equal(JSON.parse(shown.stdout).rows.length, 5 + standardDoctrine().rows.length);
});
test('signoff prints cited tests, preserves its note and escapes that note in the spec view [S14, S15]', (t) => {