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): require verified signer receipts [S17,S18,S19,S20,S21]
Corey Olsonab25bca4cd73
diff --git a/src/cli.js b/src/cli.jsindex 0e74dd87..3a48ba79 100644--- a/src/cli.js+++ b/src/cli.js@@ -48,7 +48,7 @@ import { citedTestFiles, rowEvidence, rowStage } from './evidence.js';import { serveView } from './serve.js';import { doctorProblems } from './doctor.js';import { exportBoard, importBoard } from './exchange.js';-import { addSigner, defaultPrincipal, readSignerText } from './signature.js';+import { addSigner, defaultPrincipal, hasSignerFile } from './signature.js';const PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));export const VERSION = PACKAGE.version;@@ -125,7 +125,7 @@ Specpullboard spec view [--out file] the spec, open questions, sign-offs and practice as one pagepullboard spec show <id> | unmet [--must] | signoff <ids> [--by <principal>]signoff: --note "what was checked" stays with the receipt- pullboard spec signers add [--key <path>] [--by <principal>] opt into SSH-signed sign-offs+ pullboard spec signers add [--key <path>] [--by <principal>] opt into SSH-signed sign-offsprincipal defaults to Git user.email; --by overrides itRole guides@@ -1558,7 +1558,7 @@ function specCommand(io, { first, second, rest, values }) {for (const item of row.verified) io.say(` verified #${item.id}: ${item.note || '(no accepting note)'}`);}const note = textArg(io, values, 'note') ?? '';- const by = values.by ?? (readSignerText(ctx.info.root) ? defaultPrincipal(ctx.info.root) : '');+ const by = values.by ?? (hasSignerFile(ctx.info.root) ? defaultPrincipal(ctx.info.root) : '');const count = signOff(ctx.info.root, spec, { ids, by, on: new Date().toISOString(), note, commit: headCommit(ctx.info.root) ?? '' });io.result?.({ count, by, ids, evidence });io.say(`signed ${count} rows as ${by}; commit .pullboard/signoffs.jsonl`);diff --git a/src/signature.js b/src/signature.jsindex ebf9b660..b95930a1 100644--- a/src/signature.js+++ b/src/signature.js@@ -10,6 +10,10 @@ export const SIGNERS_FILE = '.pullboard/signers';export const FIRST_COMMIT_FILE = '.pullboard/first-commit';const INITIAL_SIGNERS_HASH_FILE = '.pullboard/signers.initial';export const SIGNOFF_NAMESPACE = 'pullboard-signoff';+const verifiedRows = new WeakSet();++/** Identify receipts verified against this repo's SSH signer list, without persisting a trust flag. */+export function isVerifiedSignoff(record) { return verifiedRows.has(record); }/** Hash the exact bytes the repo stores, so whitespace changes are signed changes too. */export function sha256(text) { return createHash('sha256').update(text).digest('hex'); }@@ -72,6 +76,9 @@ export function readSignerText(root) {return existsSync(file) ? readFileSync(file, 'utf8') : '';}+/** Treat the existence of the signer file as opt-in, including an incomplete empty file. */+export function hasSignerFile(root) { return existsSync(join(root, SIGNERS_FILE)); }+/** Find a valid principal in an OpenSSH allowed-signers file. */export function listsPrincipal(text, principal) {return text.split(/\r?\n/u).filter((line) => line.trim() && !line.trimStart().startsWith('#'))@@ -170,10 +177,11 @@ export function verifySignerHistory(root, records) {/** Verify signed rows and signer-list transitions when the repo has opted into SSH sign-offs. */export function verifySignedRecords(root, records) {const current = readSignerText(root);- if (!current) {+ if (!hasSignerFile(root)) {if (existsSync(join(root, FIRST_COMMIT_FILE))) throw new Refused('MISSING_SIGNERS', `${SIGNERS_FILE} was removed after SSH sign-offs were enabled`);return records;}+ if (!current.trim()) throw new Refused('EMPTY_SIGNERS', `${SIGNERS_FILE} is empty; restore its SSH signer list before signing or checking`);verifySignerHistory(root, records);const first = readFirstCommit(root);for (const record of records) {@@ -183,7 +191,9 @@ export function verifySignedRecords(root, records) {if (!listsPrincipal(current, record.by)) throw new Refused('UNLISTED_SIGNER', `${record.by} is not listed in ${SIGNERS_FILE}`);verifySignature(record, current);}- return records.filter((record) => record.type !== 'signers');+ const rows = records.filter((record) => record.type !== 'signers');+ rows.forEach((record) => verifiedRows.add(record));+ return rows;}/** Resolve the first commit once, refusing to guess when a shallow clone has no recorded root. */@@ -203,7 +213,7 @@ export function addSigner(root, { by, key } = {}) {const principal = by || defaultPrincipal(root);if (!/^(?!#)[^\s,]+$/u.test(principal)) throw new Refused('BAD_SIGNER', 'use --by with one SSH principal, or set git user.email');const entry = `${principal} namespaces="${SIGNOFF_NAMESPACE}" ${publicLine}`;- if (!text) {+ if (!hasSignerFile(root)) {const firstCommit = firstCommitFromGit(root);const next = `${entry}\n`;const folder = dirname(join(root, SIGNERS_FILE));diff --git a/src/spec.js b/src/spec.jsindex 1f6c2fd4..f99e022e 100644--- a/src/spec.js+++ b/src/spec.js@@ -11,7 +11,7 @@ import { createHash } from 'node:crypto';import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs';import { dirname, join } from 'node:path';import { Refused } from './refused.js';-import { readSignerText, signRows, verifySignedRecords } from './signature.js';+import { hasSignerFile, isVerifiedSignoff, signRows, verifySignedRecords } from './signature.js';export const STATUSES = ['approved', 'draft', 'pending', 'fact', 'wont', 'retired'];export const TIERS = ['must', 'aim'];@@ -23,6 +23,7 @@ const ROW_RE = new RegExp(`^- (${ID}) \\[([a-z]+)(?:,\\s*([a-z]+))?\\]\\s+(.+)$`const ROWISH_RE = new RegExp(`^- ${ID}\\s+\\[`);const SECTION_RE = /^##\s+(.+)$/;const SIGNER_RE = /^(?!#)[^\s,]+$/u;+const LEGACY_SIGNER_RE = /^[A-Z][A-Za-z]{1,11}$/;/*** One row's trailing fields, after the text: `| gate: ...`, `| serves: a, b` and `| signers: CO,AB`.@@ -258,8 +259,10 @@ export function readSignoffs(root) {*/export function standings(rows, signoffs) {const textOf = new Map(rows.map((row) => [row.id, row.text]));+ const required = new Set(rows.filter((row) => row.signers?.length).map((row) => row.id));const by = new Map();for (const signoff of signoffs) {+ if (required.has(signoff.id) && !isVerifiedSignoff(signoff)) continue;const standing = by.get(signoff.id) ?? { met: [], stale: [] };if (textOf.get(signoff.id) === signoff.text) standing.met.push(signoff);else standing.stale.push(signoff);@@ -289,17 +292,18 @@ export function unmetRows(rows, signoffs, { mustOnly = false } = {}) {}/**- * Record a person's sign-off on approved rows, with the text they read (S5). The signer is the- * exact SSH principal named by the key's allowed-signers entry.+ * Record a person's sign-off on approved rows, with the text they read (S5). Legacy receipts keep+ * initials or a name; SSH receipts name the exact principal in the key's allowed-signers entry.** @param {string} root* @param {ReturnType<typeof parseSpec>} spec- * @param {{ ids: string[], by: string, on: string, note?: string }} signoff+ * @param {{ ids: string[], by: string, on: string, note?: string, commit?: string }} signoff* @returns {number} How many rows were signed.*/export function signOff(root, spec, { ids, by, on, note = '', commit = '' }) {- if (!SIGNER_RE.test(by)) {- throw new Refused('BAD_SIGNER', 'sign with one principal: --by <principal>');+ const ssh = hasSignerFile(root);+ if (!(ssh ? SIGNER_RE : LEGACY_SIGNER_RE).test(by)) {+ throw new Refused('BAD_SIGNER', ssh ? 'sign with one principal: --by <principal>' : 'sign with initials or a first name: --by CO');}const byId = new Map(spec.rows.map((row) => [row.id, row]));const problems = ids.flatMap((id) => {@@ -310,7 +314,7 @@ export function signOff(root, spec, { ids, by, on, note = '', commit = '' }) {if (problems.length) throw new Refused('CANNOT_SIGN', problems.join('; '));const file = join(root, SIGNOFFS_FILE);mkdirSync(dirname(file), { recursive: true });- if (readSignerText(root)) {+ if (ssh) {if (!commit) throw new Refused('NO_SIGNING_COMMIT', 'signed sign-offs include the commit checked; commit or check out the repo first');const rows = ids.map((id) => ({ id, by, on, text: byId.get(id).text, commit, note }));signRows(root, rows);diff --git a/test/signoff.test.js b/test/signoff.test.jsindex c67c41c5..cabcc0de 100644--- a/test/signoff.test.js+++ b/test/signoff.test.js@@ -14,6 +14,9 @@ const SPEC = `# Sign-off fixture- G1 [approved, must] Exact row text is signed. | gate: test/proof.test.js | signers: CO,AB`;+/** Quote a source-runner path literally for the fixture's POSIX hook shim. */+function shellWord(value) { return `'${value.replaceAll("'", "'\\''")}'`; }+/** Create a throwaway OpenSSH Ed25519 private and public key pair. */function makeKey(path) {execFileSync('ssh-keygen', ['-q', '-t', 'ed25519', '-N', '', '-C', '[email protected]', '-f', path], { stdio: 'pipe' });@@ -32,7 +35,7 @@ function fixture(t) {const ab = makeKey(join(keys, 'ab'));const binDir = join(dir, 'bin');mkdirSync(binDir);- writeFileSync(join(binDir, 'pullboard'), `#!/bin/sh\nexec "${process.execPath}" "${BIN}" "$@"\n`);+ writeFileSync(join(binDir, 'pullboard'), `#!/bin/sh\nexec ${shellWord(process.execPath)} ${shellWord(BIN)} "$@"\n`);chmodSync(join(binDir, 'pullboard'), 0o755);const env = {...process.env,@@ -111,10 +114,22 @@ test('[S17,S18,S19,S20,S21] signed rows require every named principal and survivbox.git('reset', '--soft', first);box.git('commit', '-q', '-m', 'chore: squash signed receipt history');assert.match(succeeds(box, 'check').stdout, /0 errors/, 'squash keeps signed receipts valid');+ succeeds(box, 'signoff', 'G1', '--by', 'AB', '--note', 'checked after rewriting history');+ const rewritten = readFileSync(join(box.root, '.pullboard/signoffs.jsonl'), 'utf8').trim().split('\n').map(JSON.parse).at(-1);+ assert.equal(rewritten.firstCommit, first, 'new signatures after a rewrite use the recorded root');+ box.git('add', '.pullboard/signoffs.jsonl');+ box.git('commit', '-q', '-m', 'chore: sign after rewriting history');const clone = join(box.dir, 'shallow');execFileSync('git', ['clone', '-q', '--depth=1', `file://${box.root}`, clone], { env: box.env, stdio: 'pipe' });const shallowCheck = spawnSync(process.execPath, [BIN, 'spec', 'check'], { cwd: clone, env: box.env, encoding: 'utf8' });assert.equal(shallowCheck.status, 0, `${shallowCheck.stdout}${shallowCheck.stderr}`);+ execFileSync('git', ['config', 'user.signingkey', box.ab.privateKey], { cwd: clone, env: box.env });+ const shallowSign = spawnSync(process.execPath, [BIN, 'spec', 'signoff', 'G1', '--by', 'AB'], { cwd: clone, env: box.env, encoding: 'utf8' });+ assert.equal(shallowSign.status, 0, `${shallowSign.stdout}${shallowSign.stderr}`);+ const shallowRecord = readFileSync(join(clone, '.pullboard/signoffs.jsonl'), 'utf8').trim().split('\n').map(JSON.parse).at(-1);+ assert.equal(shallowRecord.firstCommit, first);+ const signedCheck = spawnSync(process.execPath, [BIN, 'spec', 'check'], { cwd: clone, env: box.env, encoding: 'utf8' });+ assert.equal(signedCheck.status, 0, `${signedCheck.stdout}${signedCheck.stderr}`);});test('[S19,S20] changed signatures, signer labels and unsigned signer-list edits are refused', (t) => {@@ -132,12 +147,13 @@ test('[S19,S20] changed signatures, signer labels and unsigned signer-list editsassert.match(badSignature.stderr, /BAD_SIGNATURE/);writeFileSync(file, original);- const changedNote = JSON.parse(original);- changedNote.note = 'a different check';- writeFileSync(file, `${JSON.stringify(changedNote)}\n`);- const badNote = box.run('spec', 'check');- assert.notEqual(badNote.status, 0);- assert.match(badNote.stderr, /BAD_SIGNATURE/);+ for (const [field, value] of Object.entries({ id: 'G2', text: 'a different row', commit: '0'.repeat(40), on: '2000-01-01T00:00:00.000Z', note: 'a different check', firstCommit: '0'.repeat(40) })) {+ const changed = { ...JSON.parse(original), [field]: value };+ writeFileSync(file, `${JSON.stringify(changed)}\n`);+ const refused = box.run('spec', 'check');+ assert.notEqual(refused.status, 0, `${field} is covered by the signature`);+ assert.match(refused.stderr, field === 'firstCommit' ? /BAD_SIGNOFF/u : /BAD_SIGNATURE/u);+ }writeFileSync(file, original);const foreign = makeKey(join(box.keys, 'foreign'));@@ -190,10 +206,10 @@ test('[S21] signer setup defaults to the configured Git key and email principalconst configured = makeKey(join(ssh, 'id_ed25519'));box.env.HOME = home;const globalConfig = join(box.dir, 'global.gitconfig');- writeFileSync(globalConfig, '[user]\n\temail = [email protected]\n');+ writeFileSync(globalConfig, '[user]\n\temail = [email protected]\n\tsigningkey = ~/.ssh/id_ed25519\n');box.env.GIT_CONFIG_GLOBAL = globalConfig;box.git('config', '--local', '--unset', 'user.email');- box.git('config', 'user.signingkey', '~/.ssh/id_ed25519');+ box.git('config', '--local', '--unset', 'user.signingkey');const result = box.run('spec', 'signers', 'add');assert.equal(result.status, 0, `${result.stdout}${result.stderr}`);assert.match(result.stdout, /added SSH signer global@example\.invalid/);@@ -219,3 +235,94 @@ test('[S21] signer setup falls back to ~/.ssh/id_ed25519.pub when Git has no sigassert.equal(result.status, 0, `${result.stdout}${result.stderr}`);assert.match(readFileSync(join(box.root, '.pullboard/signers'), 'utf8'), new RegExp(readFileSync(fallback.publicKey, 'utf8').trim().replace(/[.*+?^${}()|[\]\\]/gu, '\\$&')));});++test('[S5,S18] legacy receipts preserve their shape and cannot meet required SSH signers', (t) => {+ const box = fixture(t);+ succeeds(box, 'signoff', 'G1', '--by', 'CO', '--note', 'legacy evidence');+ succeeds(box, 'signoff', 'G1', '--by', 'AB');+ const file = join(box.root, '.pullboard/signoffs.jsonl');+ const original = readFileSync(file, 'utf8');+ const records = original.trim().split('\n').map(JSON.parse);+ assert.deepEqual(Object.keys(records[0]), ['id', 'by', 'on', 'text', 'note']);+ assert.match(records[0].on, /^\d{4}-\d\d-\d\d$/u);+ assert.equal(existsSync(join(box.root, '.pullboard/signers')), false);+ assert.ok(JSON.parse(succeeds(box, 'unmet', '--json').stdout).rows.some((row) => row.id === 'G1'));+ assert.equal(JSON.parse(succeeds(box, 'show', 'G1', '--json').stdout).standing.met.length, 0);+ const page = join(box.dir, 'legacy.html');+ succeeds(box, 'view', '--out', page);+ assert.doesNotMatch(readFileSync(page, 'utf8'), /so-met[^>]*>signed CO/u);+ records.forEach((record) => { record.signature = 'claimed without verification'; });+ writeFileSync(file, `${records.map((record) => JSON.stringify(record)).join('\n')}\n`);+ assert.ok(JSON.parse(succeeds(box, 'unmet', '--json').stdout).rows.some((row) => row.id === 'G1'), 'a stored signature flag cannot forge verification');+ writeFileSync(file, original);+ writeFileSync(join(box.root, 'SPEC.md'), SPEC.replace(' | signers: CO,AB', ''));+ assert.equal(JSON.parse(succeeds(box, 'unmet', '--json').stdout).rows.length, 0, 'ordinary legacy rows still accept unsigned receipts');+ const invalid = box.run('spec', 'signoff', 'G1', '--by', '[email protected]');+ assert.notEqual(invalid.status, 0);+ assert.match(invalid.stderr, /BAD_SIGNER/u);+ assert.equal(readFileSync(file, 'utf8'), original, 'legacy signer validation refuses before appending');+});++test('[S17,S19] an existing empty signer file cannot silently fall back to unsigned sign-offs', (t) => {+ const box = fixture(t);+ const signerFile = join(box.root, '.pullboard/signers');+ mkdirSync(join(box.root, '.pullboard'), { recursive: true });+ writeFileSync(signerFile, '');+ const receiptFile = join(box.root, '.pullboard/signoffs.jsonl');+ for (const args of [['check'], ['signoff', 'G1', '--by', 'CO']]) {+ const result = box.run('spec', ...args);+ assert.notEqual(result.status, 0);+ assert.match(result.stderr, /EMPTY_SIGNERS/u);+ assert.equal(existsSync(receiptFile), false);+ }+ rmSync(signerFile);+ succeeds(box, 'signers', 'add', '--by', 'CO');+ succeeds(box, 'signoff', 'G1', '--by', 'CO');+ const receipt = readFileSync(receiptFile, 'utf8');+ writeFileSync(signerFile, '');+ const check = box.run('spec', 'check');+ assert.notEqual(check.status, 0);+ assert.match(check.stderr, /EMPTY_SIGNERS/u);+ assert.equal(readFileSync(receiptFile, 'utf8'), receipt);+});++test('[S20] every signer-list transition is bound to its prior list, hash and authorized key', (t) => {+ const box = fixture(t);+ succeeds(box, 'signers', 'add', '--by', 'CO');+ succeeds(box, 'signers', 'add', '--by', 'AB', '--key', box.ab.publicKey);+ const file = join(box.root, '.pullboard/signoffs.jsonl');+ const original = readFileSync(file, 'utf8');+ const record = JSON.parse(original);+ for (const [field, value] of Object.entries({ previousHash: '0'.repeat(64), previousSigners: 'a different previous list', hash: '0'.repeat(64), firstCommit: '0'.repeat(40), by: 'AB', on: '2000-01-01T00:00:00.000Z', signature: 'invalid SSH signature' })) {+ writeFileSync(file, `${JSON.stringify({ ...record, [field]: value })}\n`);+ const refused = box.run('spec', 'check');+ assert.notEqual(refused.status, 0, `${field} cannot change independently`);+ assert.match(refused.stderr, /UNAUTHORIZED_SIGNERS_CHANGE|BAD_SIGNATURE/u);+ }+ const unauthorized = { ...record, by: 'AB' };+ const message = join(box.dir, 'unauthorized-transition');+ writeFileSync(message, canonical(unauthorized));+ execFileSync('ssh-keygen', ['-Y', 'sign', '-f', box.ab.privateKey, '-n', 'pullboard-signoff', message], { stdio: 'pipe' });+ unauthorized.signature = readFileSync(`${message}.sig`, 'utf8').trimEnd();+ writeFileSync(file, `${JSON.stringify(unauthorized)}\n`);+ const refused = box.run('spec', 'check');+ assert.notEqual(refused.status, 0);+ assert.match(refused.stderr, /UNAUTHORIZED_SIGNERS_CHANGE/u, 'a new key cannot authorize its own addition');+ writeFileSync(file, original);+ succeeds(box, 'check');+});++test('[S21] setup refuses inline key data and files containing a GPG public key', (t) => {+ const box = fixture(t);+ const publicLine = readFileSync(box.co.publicKey, 'utf8').trim();+ box.git('config', 'user.signingkey', publicLine);+ const inline = box.run('spec', 'signers', 'add');+ assert.notEqual(inline.status, 0);+ assert.match(inline.stderr, /NOT_SSH_KEY_PATH/u);+ const gpg = join(box.keys, 'gpg.pub');+ writeFileSync(gpg, '-----BEGIN PGP PUBLIC KEY BLOCK-----\nsynthetic\n-----END PGP PUBLIC KEY BLOCK-----\n');+ const wrongFormat = box.run('spec', 'signers', 'add', '--key', gpg);+ assert.notEqual(wrongFormat.status, 0);+ assert.match(wrongFormat.stderr, /NOT_SSH_KEY/u);+ assert.equal(existsSync(join(box.root, '.pullboard/signers')), false);+});