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
refactor(publish): keep captured receipt queries explicit [B3,R3]
Corey Olson032b733be24c
diff --git a/src/pr-proof-snapshot.js b/src/pr-proof-snapshot.jsindex 38923975..cf0b3e6a 100644--- a/src/pr-proof-snapshot.js+++ b/src/pr-proof-snapshot.js@@ -28,10 +28,11 @@ export function capturePrProof(board) {const captured = { ...board, db: {/** Supply fresh row lists to the existing receipt and withdrawal semantics. */prepare(sql) {- if (/FROM board_meta WHERE meta_key\s*=\s*\?/u.test(sql)) return { get: key => metadata.get(key) };- if (/FROM verdict WHERE item_id\s*=\s*\?/u.test(sql)) return { all: id => [...(verdicts.get(id) ?? [])] };- if (/FROM event(?:_history)? WHERE item_id\s*=\s*\?/u.test(sql)) {- const kinds = /event_kind\s*=\s*'reopen'/u.test(sql) ? ['reopen'] : ['accept', 'reject'];+ const query = sql.replace(/\s+/gu, ' ').trim();+ if (/^SELECT meta_value FROM board_meta WHERE meta_key\s*=\s*\?$/u.test(query)) return { get: key => metadata.get(key) };+ if (/^SELECT \* FROM verdict WHERE item_id\s*=\s*\? ORDER BY verdict_id$/u.test(query)) return { all: id => [...(verdicts.get(id) ?? [])] };+ if (/^SELECT (?:\*|event_kind, event_detail) FROM event(?:_history)? WHERE item_id\s*=\s*\? AND event_kind (?:IN \('accept', 'reject'\)|= 'reopen') ORDER BY event_id$/u.test(query)) {+ const kinds = /event_kind = 'reopen'/u.test(query) ? ['reopen'] : ['accept', 'reject'];return { all: id => (events.get(id) ?? []).filter(row => kinds.includes(row.event_kind)) };}throw new Refused('PUBLISH_STATE', 'the native receipt reader changed; update Pullboard before publishing');diff --git a/src/pr-publish.js b/src/pr-publish.jsindex e0cbc1d0..b4a420ce 100644--- a/src/pr-publish.js+++ b/src/pr-publish.js@@ -190,56 +190,56 @@ export async function publishPullRequests({ root, board, config, branch, remote,const verification = [];let failed = false;try {- const releases = [];- const findings = [];- const unattributed = [];- for (const proposal of state.proposals.filter(p => p.repository === repository)) {- const pull = client.read(proposal.number);- if (pull.head?.sha !== proposal.head) throw new Refused('PUBLISH_STATE', 'a proposal branch changed outside its recorded publication; inspect the PR before publishing');- if (pull.state === 'closed' && !pull.merged) throw new Refused('PUBLISH_STATE', 'the proposal was closed without merging; ask the coordinator whether to reopen it before publishing');- const ci = await observeCI(client, proposal, repository, write);- findings.push(...ci.findings); unattributed.push(...ci.unattributed);- const released = proposal.released ? null : await observeMerge(root, board, proposal, pull, config, repository, write);- if (released) {- proposal.released = true; releases.push(released);- say(`recorded PR #${proposal.number} merge by ${released.actor} (${released.recognizedPerson ? 'recognized person' : 'not a recognized person'}); no native person approval recorded`);+ const releases = [];+ const findings = [];+ const unattributed = [];+ for (const proposal of state.proposals.filter(p => p.repository === repository)) {+ const pull = client.read(proposal.number);+ if (pull.head?.sha !== proposal.head) throw new Refused('PUBLISH_STATE', 'a proposal branch changed outside its recorded publication; inspect the PR before publishing');+ if (pull.state === 'closed' && !pull.merged) throw new Refused('PUBLISH_STATE', 'the proposal was closed without merging; ask the coordinator whether to reopen it before publishing');+ const ci = await observeCI(client, proposal, repository, write);+ findings.push(...ci.findings); unattributed.push(...ci.unattributed);+ const released = proposal.released ? null : await observeMerge(root, board, proposal, pull, config, repository, write);+ if (released) {+ proposal.released = true; releases.push(released);+ say(`recorded PR #${proposal.number} merge by ${released.actor} (${released.recognizedPerson ? 'recognized person' : 'not a recognized person'}); no native person approval recorded`);+ }}- }- await saveState(root, state);- const releasedItems = new Set(state.proposals.filter(p => p.released).flatMap(p => p.entries.map(e => `${e.id}:${e.commit}`)));- const entries = releaseEntries(root, board, published, head).filter(e => !releasedItems.has(`${e.id}:${e.commit}`));- if (tryGit(root, ['merge-base', '--is-ancestor', head, published]).status === 0) return { head, published: true, red: [], releases, findings, unattributed, verification };- const digest = createHash('sha256').update(branch).digest('hex').slice(0, 12);- const repairRoots = new Map(store.events(board).filter(e => e.event_kind === 'pr-ci-finding').map(e => {- const detail = JSON.parse(e.event_detail); return [detail.repair, detail.item];- }));- const groups = config.publish.pullRequest === 'item' ? [...new Set(entries.map(e => repairRoots.get(e.id) ?? e.id))]- .map(id => ({ key: `item-${id}`, entries: entries.filter(e => (repairRoots.get(e.id) ?? e.id) === id) })) : [{ key: 'release', entries }];- const proposed = [];- if (!groups.length) return { head, published: false, waiting: true, red: [], releases, findings, unattributed, verification,- reason: 'No unpublished accepted item remains; per-item mode does not certify unrelated local commits.' };- for (const group of groups) {- const name = `pullboard/${group.key}-${digest}`;- const old = state.proposals.findLast(p => p.repository === repository && p.branch === name && !p.released);- if (old?.source === head) { proposed.push(old); continue; }- const added = group.entries.filter(entry => !old?.entries.some(e => e.merge === entry.merge));- if (old && config.publish.pullRequest === 'item' && !added.length) { proposed.push(old); continue; }- const candidate = config.publish.pullRequest === 'item'- ? itemComposition(root, old?.head ?? published, added) : releaseComposition(root, published, head);- const gate = await proveProposal({ root, config, remote, candidate, branch: name, onWait, onFailure });- if (!gate.isGreen) return { head, published: false, red: [{ file: null, name: 'publication whole gate failed', items: group.entries.map(e => e.id) }], findings, unattributed };- const body = receiptBody(candidate, group.entries);- const title = `Pullboard ${group.key === 'release' ? 'release' : group.key}`;- const existing = old ?? client.list(name)[0];- const pull = existing ? client.update(existing.number, { title, body }) : client.create({ title, body, head: name, base: branch });- if (!Number.isSafeInteger(pull.number) || pull.number < 1 || pull.head?.sha !== candidate) throw new Refused('PUBLISH_GITHUB', 'the PR response does not name the exact proven publication head; inspect it before continuing');- const proposal = { repository, branch: name, source: head, head: candidate, number: pull.number,- url: `https://github.com/${repository}/pull/${pull.number}`, entries: group.entries, released: false };- if (old) state.proposals.splice(state.proposals.indexOf(old), 1, proposal); else state.proposals.push(proposal);- await saveState(root, state); proposed.push(proposal);- }- say(`proposed ${proposed.length} pull request(s); only a person can merge them`);- return { head, published: false, waiting: true, proposed: true, pullRequests: proposed.map(p => ({ number: p.number, url: p.url, head: p.head, items: p.entries.map(e => e.id) })), red: [], releases, findings, unattributed, verification };+ await saveState(root, state);+ const releasedItems = new Set(state.proposals.filter(p => p.released).flatMap(p => p.entries.map(e => `${e.id}:${e.commit}`)));+ const entries = releaseEntries(root, board, published, head).filter(e => !releasedItems.has(`${e.id}:${e.commit}`));+ if (tryGit(root, ['merge-base', '--is-ancestor', head, published]).status === 0) return { head, published: true, red: [], releases, findings, unattributed, verification };+ const digest = createHash('sha256').update(branch).digest('hex').slice(0, 12);+ const repairRoots = new Map(store.events(board).filter(e => e.event_kind === 'pr-ci-finding').map(e => {+ const detail = JSON.parse(e.event_detail); return [detail.repair, detail.item];+ }));+ const groups = config.publish.pullRequest === 'item' ? [...new Set(entries.map(e => repairRoots.get(e.id) ?? e.id))]+ .map(id => ({ key: `item-${id}`, entries: entries.filter(e => (repairRoots.get(e.id) ?? e.id) === id) })) : [{ key: 'release', entries }];+ const proposed = [];+ if (!groups.length) return { head, published: false, waiting: true, red: [], releases, findings, unattributed, verification,+ reason: 'No unpublished accepted item remains; per-item mode does not certify unrelated local commits.' };+ for (const group of groups) {+ const name = `pullboard/${group.key}-${digest}`;+ const old = state.proposals.findLast(p => p.repository === repository && p.branch === name && !p.released);+ if (old?.source === head) { proposed.push(old); continue; }+ const added = group.entries.filter(entry => !old?.entries.some(e => e.merge === entry.merge));+ if (old && config.publish.pullRequest === 'item' && !added.length) { proposed.push(old); continue; }+ const candidate = config.publish.pullRequest === 'item'+ ? itemComposition(root, old?.head ?? published, added) : releaseComposition(root, published, head);+ const gate = await proveProposal({ root, config, remote, candidate, branch: name, onWait, onFailure });+ if (!gate.isGreen) return { head, published: false, red: [{ file: null, name: 'publication whole gate failed', items: group.entries.map(e => e.id) }], findings, unattributed };+ const body = receiptBody(candidate, group.entries);+ const title = `Pullboard ${group.key === 'release' ? 'release' : group.key}`;+ const existing = old ?? client.list(name)[0];+ const pull = existing ? client.update(existing.number, { title, body }) : client.create({ title, body, head: name, base: branch });+ if (!Number.isSafeInteger(pull.number) || pull.number < 1 || pull.head?.sha !== candidate) throw new Refused('PUBLISH_GITHUB', 'the PR response does not name the exact proven publication head; inspect it before continuing');+ const proposal = { repository, branch: name, source: head, head: candidate, number: pull.number,+ url: `https://github.com/${repository}/pull/${pull.number}`, entries: group.entries, released: false };+ if (old) state.proposals.splice(state.proposals.indexOf(old), 1, proposal); else state.proposals.push(proposal);+ await saveState(root, state); proposed.push(proposal);+ }+ say(`proposed ${proposed.length} pull request(s); only a person can merge them`);+ return { head, published: false, waiting: true, proposed: true, pullRequests: proposed.map(p => ({ number: p.number, url: p.url, head: p.head, items: p.entries.map(e => e.id) })), red: [], releases, findings, unattributed, verification };} catch (error) { failed = true; throw error; }finally {// One final pass sees every proposed PR. Returned objects retain this same result array.