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
feat(hooks): require outside author sign-offs [C1,C7]
Corey Olsonbdf464fc88d9
diff --git a/.github/workflows/gate.yml b/.github/workflows/gate.ymlindex 29bfa555..49e24447 100644--- a/.github/workflows/gate.yml+++ b/.github/workflows/gate.yml@@ -20,6 +20,19 @@ permissions:contents: readjobs:+ signoffs:+ name: contributor sign-offs+ if: github.event_name == 'push' || github.event_name == 'pull_request'+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v4+ with:+ fetch-depth: 0+ - uses: actions/setup-node@v4+ with:+ node-version: '22.13'+ - run: node bin/check-signoffs.js+linux:name: linux (${{ matrix.node }}) ${{ matrix.shard }}/${{ matrix.shards }}runs-on: ubuntu-latestdiff --git a/bin/check-signoffs.js b/bin/check-signoffs.jsnew file mode 100644index 00000000..a8b9bb5d--- /dev/null+++ b/bin/check-signoffs.js@@ -0,0 +1,26 @@+#!/usr/bin/env node+/** Check every incoming PR or main-push commit against the event's trusted base policy [C1,C7]. */+import { readFileSync } from 'node:fs';+import { contributionSignoffProblem } from '../src/commit-signoff.js';++/** Use structured event data rather than interpolating contributor-controlled values into a shell. */+function main() {+ const event = JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8'));+ let range;+ if (process.env.GITHUB_EVENT_NAME === 'pull_request') {+ range = { base: event.pull_request?.base?.sha, head: event.pull_request?.head?.sha };+ } else if (process.env.GITHUB_EVENT_NAME === 'push') {+ range = { base: /^0+$/u.test(event.before ?? '') ? null : event.before, head: event.after };+ } else throw new Error('Run the sign-off check for a pull_request or push event with its complete event file.');+ const result = contributionSignoffProblem(process.cwd(), range);+ if (result.problem) {+ process.stderr.write(result.problem + '\n');+ process.exitCode = 1;+ } else process.stdout.write('Contributor sign-offs checked: ' + result.checked + ' non-merge commits.\n');+}++try { main(); }+catch (error) {+ process.stderr.write('pullboard sign-off: ' + String(error.message).replace(/[\r\n]+/gu, ' ') + '\n');+ process.exitCode = 1;+}diff --git a/src/commands/hook.js b/src/commands/hook.jsindex 3b1c0863..8ed1a414 100644--- a/src/commands/hook.js+++ b/src/commands/hook.js@@ -1,5 +1,6 @@/** The pullboard hook command, in its own module so an item adding another command never edits these lines. */import * as store from '../board.js';+import { pendingCommitSignoffProblem } from '../commit-signoff.js';import { landingBatchOwnsRoot } from '../landing-candidates.js';import {hookRead,@@ -74,6 +75,8 @@ export async function hookCommand(io, { first, second }) {problems = preCommitProblems({ root: info.root, isMain: info.isMain || landing, config: ctx.config, agent, boardFile: ctx.file, preMergeHook: first === 'pre-merge-commit', onNotice: (message) => io.err(`pullboard pre-commit: warning: ${message}`) });} else if (first === 'commit-msg') {const message = readFileSync(second ?? '', 'utf8');+ const signoff = pendingCommitSignoffProblem(info.root, message);+ if (signoff) { io.err(signoff); return 1; }const spec = withRowDrafts(loadSpec(info.root, ctx.config), hookRead(ctx, (board) => store.rowDrafts(board)));commitCitationWarnings(message, { spec, doctrine: ctx.doctrine }).forEach((warning) => io.say(`pullboard commit-msg: warning: ${warning}`));diff --git a/src/commit-signoff.js b/src/commit-signoff.jsnew file mode 100644index 00000000..3ddbd182--- /dev/null+++ b/src/commit-signoff.js@@ -0,0 +1,103 @@+/** Check outside contributors' author-matching DCO trailers against committed policy [C1,C7]. */+import { spawnSync } from 'node:child_process';+import {+ existsSync,+ readFileSync,+} from 'node:fs';+import { resolve } from 'node:path';+import {+ cleanGitEnvironment,+ refuseGrafts,+} from './git.js';+import { Refused } from './refused.js';++/** Read exact Git objects without inherited repository selectors or replacement objects. */+function gitResult(root, args) {+ return spawnSync('git', ['--no-replace-objects', ...args], {+ cwd: root, env: cleanGitEnvironment(), encoding: 'utf8', maxBuffer: 8 * 1024 * 1024,+ });+}++/** Refuse incomplete history rather than silently omitting a contributor's commit. */+function gitText(root, args) {+ const result = gitResult(root, args);+ if (result.status !== 0) throw new Refused('BAD_CONFIG', 'Restore the complete Git history and committed maintainer policy, then retry the sign-off check.');+ return result.stdout;+}++/** Local hooks use HEAD; CI supplies its trusted base object, never the contribution's policy. */+function maintainersAt(root, commit, required) {+ let config;+ try { config = JSON.parse(gitText(root, ['show', commit + ':pullboard.json'])); }+ catch (error) {+ if (error instanceof Refused) throw error;+ throw new Refused('BAD_CONFIG', 'Restore valid JSON in the committed pullboard.json before checking sign-offs.');+ }+ if (config.maintainers === undefined && !required) return null;+ if (!Array.isArray(config.maintainers) || config.maintainers.some(email =>+ typeof email !== 'string' || !email || email.trim() !== email || /[<>\u0000-\u001f\u007f]/u.test(email))) {+ throw new Refused('BAD_CONFIG', 'The trusted pullboard.json must contain maintainers as a list of exact author emails; ask the maintainer to correct the base branch.');+ }+ return config.maintainers;+}++/** A committer's trailer cannot certify a different author; email matching is exact. */+function signedByAuthor(message, author) {+ return message.split(/\r?\n/u).some(line => {+ const match = /^Signed-off-by:[\t ]+(.+?) <([^<>]+)>[\t ]*$/iu.exec(line);+ return match?.[1] === author.name && match?.[2] === author.email;+ });+}++/** Keep the missing-sign-off refusal to one line with the concrete fix and contributor guide. */+function signoffProblem(message, author, maintainers, commit = null) {+ if (maintainers.includes(author.email) || signedByAuthor(message, author)) return null;+ return 'pullboard sign-off: ' + (commit ? 'commit ' + commit.slice(0, 12) : 'this outside commit')+ + ' needs Signed-off-by matching its author; git commit --amend -s; see '+ + '[CONTRIBUTING: How to sign off](CONTRIBUTING.md#how-to-sign-off-step-by-step)';+}++/** Check every new non-merge commit; a merge wrapper does not substitute for its parents. */+function rangeProblem(root, heads, base, maintainers) {+ refuseGrafts(root);+ const commits = gitText(root, ['rev-list', '--reverse', '--no-merges', ...heads, ...(base ? ['--not', base] : [])])+ .trim().split('\n').filter(Boolean);+ for (const commit of commits) {+ const [name, email, message] = gitText(root, ['show', '-s', '--format=%an%x00%ae%x00%B', commit]).split('\0');+ const problem = signoffProblem(message, { name, email }, maintainers, commit);+ if (problem) return { checked: commits.length, problem };+ }+ return { checked: commits.length, problem: null };+}++/** Apply this repository's opt-in policy before the ordinary message-format hook diagnostics. */+export function pendingCommitSignoffProblem(root, message) {+ const head = gitResult(root, ['rev-parse', '--verify', '--quiet', 'HEAD^{commit}']);+ if (head.status !== 0) return null; // The first commit has no committed policy yet.+ const commit = head.stdout.trim();+ const policyPath = gitText(root, ['ls-tree', '-z', commit, '--', 'pullboard.json']);+ if (!policyPath) return null;+ const maintainers = maintainersAt(root, commit, false);+ if (maintainers === null) return null; // Other repositories have no contribution policy enabled.+ const mergePath = resolve(root, gitText(root, ['rev-parse', '--git-path', 'MERGE_HEAD']).trim());+ if (existsSync(mergePath)) {+ const heads = readFileSync(mergePath, 'utf8').trim().split(/\s+/u);+ if (!heads.length || heads.some(head => !/^[0-9a-f]{40,64}$/u.test(head))) {+ throw new Refused('BAD_CONFIG', 'Restore the merge parents before checking contributor sign-offs.');+ }+ return rangeProblem(root, heads, commit, maintainers).problem;+ }+ const ident = gitText(root, ['var', 'GIT_AUTHOR_IDENT']).trim();+ const author = /^(.*) <([^<>]+)> \d+ [+-]\d{4}$/u.exec(ident);+ if (!author) throw new Refused('BAD_CONFIG', 'Set a valid Git author name and email before committing.');+ return signoffProblem(message, { name: author[1], email: author[2] }, maintainers);+}++/** Check a CI event's complete contribution range with the independently selected base policy. */+export function contributionSignoffProblem(root, { base, head }) {+ if (!/^[0-9a-f]{40,64}$/u.test(head ?? '') || /^0+$/u.test(head)+ || (base !== null && (!/^[0-9a-f]{40,64}$/u.test(base ?? '') || /^0+$/u.test(base)))) {+ throw new Refused('BAD_CONFIG', 'The sign-off check needs exact base and head commit ids from the CI event.');+ }+ return rangeProblem(root, [head], base, maintainersAt(root, base ?? head, true));+}diff --git a/test/ci.test.js b/test/ci.test.jsindex 144a44b1..06e1b5f6 100644--- a/test/ci.test.js+++ b/test/ci.test.js@@ -91,6 +91,9 @@ function job(name) {test('CI runs the gate on every push and pull request, Node 22.13 and 24, on Linux and, once public, macOS [C7]', () => {assert.match(WORKFLOW, /\non:\n {2}push:\n {4}branches: \[main\]\n {2}pull_request:\n/, 'pushes to main and pull requests');+ assert.match(job('signoffs'), /if: github\.event_name == 'push' \|\| github\.event_name == 'pull_request'/u);+ assert.match(job('signoffs'), /fetch-depth: 0/u, 'the sign-off job can read every incoming commit');+ assert.match(job('signoffs'), /run: node bin\/check-signoffs\.js/u, 'CI runs the range checker against its structured event');for (const [name, system] of [['linux', 'ubuntu-latest'], ['macos', 'macos-latest']]) {const text = job(name);assert.ok(text.includes(`\n runs-on: ${system}\n`), `${name} runs on ${system}`);diff --git a/test/commit-msg.test.js b/test/commit-msg.test.jsindex 04ec79e7..efd7d857 100644--- a/test/commit-msg.test.js+++ b/test/commit-msg.test.js@@ -89,6 +89,23 @@ test('an outside commit without a sign-off is refused with its fix [C1,C7]', ()'-m', 'Signed-off-by: Outside Person <[email protected]>');const accepted = check();assert.equal(accepted.status, 0, accepted.failure || accepted.stderr);++ const signedHead = box.git(incoming, 'rev-parse', 'HEAD').trim();+ box.git(incoming, 'checkout', '-q', '--detach', base);+ writeFileSync(join(incoming, 'other.txt'), 'A separately signed parent.\n');+ box.git(incoming, 'add', 'other.txt');+ box.git(incoming, 'commit', '-q', '-m', 'chore: signed other parent',+ '-m', 'Signed-off-by: Outside Person <[email protected]>');+ const otherParent = box.git(incoming, 'rev-parse', 'HEAD').trim();+ box.git(incoming, 'checkout', '-q', '--detach', signedHead);+ box.env.GIT_AUTHOR_NAME = 'Merge Bot';+ box.env.GIT_AUTHOR_EMAIL = '[email protected]';+ box.git(incoming, 'merge', '--no-ff', '--no-edit', otherParent);+ assert.equal(check().status, 0, 'a merge wrapper is checked through both non-merge parents');+ writeFileSync(join(incoming, 'bot.txt'), 'A bot contribution.\n');+ box.git(incoming, 'add', 'bot.txt');+ box.git(incoming, 'commit', '-q', '-m', 'chore: unsigned bot work');+ assert.equal(check().status, 1, 'a non-member bot commit still needs its own author sign-off');});/** Require a real CLI move to succeed before a dependent fixture step. */