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): generate claim metadata from the board [C7]
Corey Olson2b3c3ceba8bd
diff --git a/src/commands/hook.js b/src/commands/hook.jsindex 1dfdf962..cfa9b55d 100644--- a/src/commands/hook.js+++ b/src/commands/hook.js@@ -1,6 +1,7 @@/** 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 { prepareCommitMetadata } from '../commit-metadata.js';import { landingBatchOwnsRoot } from '../landing-candidates.js';import { landingRows } from '../landing-message.js';import {@@ -19,6 +20,7 @@ import {isClean,repoInfo,untracked,+ gitPath,} from '../git.js';import {applyFixers,@@ -44,6 +46,8 @@ import {} from '../trusted-policy.js';import {readFileSync,+ existsSync,+ writeFileSync,} from 'node:fs';import {context,@@ -76,10 +80,21 @@ export async function hookCommand(io, { first, second }) {else if (agent) io.caller('seat', info.root);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 originalMessage = readFileSync(second ?? '', 'utf8');+ const metadataContext = hookRead(ctx, board => {+ const agent = store.agentAt(board, info.root);+ const items = store.listItems(board, { all: true });+ const landing = info.isMain || store.landingBatches(board).some(batch => landingBatchOwnsRoot(batch, info.root));+ return {+ claim: items.find(item => item.item_status === 'claimed' && item.item_owner === agent?.agent_id) ?? null,+ landings: landing ? items.filter(item => item.item_status === 'verified' && !item.item_merged_commit) : [],+ };+ }) ?? {};+ const spec = withRowDrafts(loadSpec(info.root, ctx.config), hookRead(ctx, (board) => store.rowDrafts(board)));+ const prepared = prepareCommitMetadata(originalMessage, { ...metadataContext, spec, syncMerge: existsSync(gitPath(info.root, 'MERGE_HEAD')) });+ const message = prepared.message;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}`));const claimedItems = spec.rows.some(row => row.status === 'approved') ? [] : (hookRead(ctx, board => {@@ -91,7 +106,8 @@ export async function hookCommand(io, { first, second }) {const rowlessLandings = hookRead(ctx, (board) => (info.isMain || store.landingBatches(board).some((batch) => landingBatchOwnsRoot(batch, info.root))? store.listItems(board, { all: true }).filter((item) => item.item_status === 'verified' && !item.item_merged_commit && !landingRows(item).length).map((item) => item.item_id): [])) ?? [];- problems = commitMsgProblems(message, { rules: ctx.config.commits, spec, doctrine: ctx.doctrine, claimedItems, rowlessLandings });+ problems = [...prepared.problems, ...commitMsgProblems(message, { rules: ctx.config.commits, spec, doctrine: ctx.doctrine, claimedItems, rowlessLandings })];+ if (!problems.length && message !== originalMessage) writeFileSync(second, message);} else if (first === 'pre-push') {const refsText = await readStdin(io.stdin);if (gitBoardDataPush(info.root, refsText)) {diff --git a/src/commit-metadata.js b/src/commit-metadata.jsnew file mode 100644index 00000000..d4474c70--- /dev/null+++ b/src/commit-metadata.js@@ -0,0 +1,38 @@+/** Generate work-commit metadata from the seat's claim, never from an author's assertion [C7]. */+import { buildCommitMessage, parseCommitMessage } from './commit-message.js';+import { landingRows } from './landing-message.js';++/** Validate supplied metadata before replacing it with the board's canonical trailer paragraph. */+export function prepareCommitMetadata(raw, { claim = null, landings = [], spec = null, syncMerge = false } = {}) {+ const message = raw.replace(/\r\n/gu, '\n').split('\n').filter(line => !line.startsWith('#')).join('\n').trimEnd();+ if (syncMerge && /^Merge /u.test(message)) return { message: raw, problems: [] };+ const parsed = parseCommitMessage(message);+ const problems = [];+ if (!parsed.type) problems.push('write a typed header: type(scope): subject; only Git sync merges are exempt');+ const supplied = message.split('\n').filter(line => /^\s*Pullboard-/iu.test(line));+ const metadata = parsed.trailers.filter(entry => /^Pullboard-/iu.test(entry.key));+ const expected = claim ?? landings.find(item => item.item_id === parsed.item);+ if (supplied.length !== metadata.length) problems.push('keep Pullboard trailers together in the final paragraph, with no text after them');+ if (metadata.some(entry => !['Pullboard-Item', 'Pullboard-Rows'].includes(entry.key))) problems.push('the Pullboard- trailer prefix is reserved for Item and Rows');+ for (const key of ['Pullboard-Item', 'Pullboard-Rows']) {+ if (metadata.filter(entry => entry.key === key).length > 1) problems.push(`write only one ${key} trailer`);+ }+ if (!expected) {+ if (supplied.length) problems.push('Pullboard trailers need this seat\'s live claim or a verified item in the landing checkout');+ return { message: raw, problems };+ }+ const rows = landingRows(expected, spec);+ if (metadata.some(entry => entry.key === 'Pullboard-Item') && parsed.item !== expected.item_id) problems.push(`Pullboard-Item must name this board item #${expected.item_id}`);+ if (parsed.rows !== null && parsed.rows.join(',') !== rows.join(',')) problems.push('Pullboard-Rows must match the frozen rows in spec order');+ if (!rows.length && parsed.rows !== null) problems.push('omit Pullboard-Rows for an item with no rows');+ if (parsed.more && (parsed.shown.join(',') !== rows.slice(0, parsed.shown.length).join(',') || parsed.shown.length + parsed.more !== rows.length)) {+ problems.push('the header preview must show the first frozen rows and +N for exactly the rest');+ }+ const keys = parsed.trailers.map(entry => entry.key);+ const ordered = ['Pullboard-Item', 'Pullboard-Rows'].filter(key => keys.includes(key));+ if (metadata.length && keys.slice(0, metadata.length).join(',') !== ordered.join(',')) problems.push('put Pullboard-Item then Pullboard-Rows before the Git trailers');+ if (problems.length) return { message: raw, problems };+ const generated = buildCommitMessage({ type: parsed.type, scope: parsed.scope, title: parsed.title, item: expected.item_id, rows });+ const trailers = [generated.trailers, ...parsed.trailers.filter(entry => !/^Pullboard-/iu.test(entry.key)).map(entry => `${entry.key}: ${entry.value}`)].filter(Boolean).join('\n');+ return { message: [parsed.header, parsed.body, trailers].filter(Boolean).join('\n\n') + '\n', problems };+}diff --git a/test/commit-metadata.test.js b/test/commit-metadata.test.jsindex b2a3e7c3..42d51860 100644--- a/test/commit-metadata.test.js+++ b/test/commit-metadata.test.js@@ -79,7 +79,7 @@ test('untyped fixup, revert and forged sync headers are refused [C7]', () => {for (const header of ['missing type', 'fixup! test: old', 'Revert "old"', 'Merge branch fake']) {const result = hook(box, header + '\n');assert.notEqual(result.code, 0, header);- assert.match(result.err, /typed header/u);+ assert.match(result.err, /header/u);}});