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(core): extract sealed review helpers [E8,H16]
Corey Olsoncd61b11beb71
diff --git a/src/board.js b/src/board.jsindex 3dc2be26..c3d16be8 100644--- a/src/board.js+++ b/src/board.js@@ -6,6 +6,8 @@* every move lands in an append-only event log (R2). The caller supplies what only git and the* spec know: the commit, the verifier's checkout, the frozen criterion.*/+import { verdictReviewProblem, verdictsFor, acceptedVerdict, checkedLandingCommit } from './verdict-reviews.js';+export { verdictReviewProblem, verdictsFor, acceptedVerdict, checkedLandingCommit };import { randomBytes, randomUUID } from 'node:crypto';import { existsSync, mkdirSync } from 'node:fs';import { dirname } from 'node:path';@@ -1466,20 +1468,6 @@ function reserveWithin(board, id, { agentId, leaseMs, policy, familyPolicy = 'ofreturn getItem(board, id);}-/** Validate a sealed review without consulting Git or changing either replica [E8,H16]. */-export function verdictReviewProblem(review, commit, { checked } = {}) {- const valid = review && typeof review === 'object' && !Array.isArray(review)- && Object.keys(review).sort().join(',') === (checked === false ? 'commit,paths,trunk' : checked === true || Object.hasOwn(review, 'head') ? 'commit,head,paths,trunk' : 'commit,paths,trunk')- && (!checked || Object.hasOwn(review, 'head'))- && (!Object.hasOwn(review, 'head') || /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(review.head ?? ''))- && review.commit === commit && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(review.commit ?? '')- && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(review.trunk ?? '')- && Array.isArray(review.paths) && review.paths.every(path => typeof path === 'string' && !path.includes('\0')- && path.split('/').every(part => part && part !== '.' && part !== '..'))- && JSON.stringify(review.paths) === JSON.stringify([...new Set(review.paths)].sort());- return valid ? null : new Refused('BAD_VERDICT_REVIEW', checked ? 'the review must bind the current submitted commit, its checked commit, reviewed trunk and sorted unique candidate paths; use current Pullboard to review it again' : 'the review must bind the current submitted commit, its reviewed trunk and sorted unique candidate paths; use current Pullboard to review it again');-}-/*** Record a verdict on submitted work, or a sealed re-review of unlanded work (E8,V1,V3,V8).* An accept verifies it; a reject@@ -1812,34 +1800,6 @@ export function getItem(board, id) {return baseline ? { ...item, item_check_baseline: baseline } : item;}-/**- * Every verdict on an item, oldest first.- *- * @param {any} board- * @param {number} id- * @returns {any[]}- */-export function verdictsFor(board, id) {- const verdicts = board.db.prepare('SELECT * FROM verdict WHERE item_id = ? ORDER BY verdict_id').all(id);- const receipts = board.db.prepare("SELECT event_kind, event_detail FROM event WHERE item_id = ? AND event_kind IN ('accept', 'reject') ORDER BY event_id").all(id);- return verdicts.map((verdict, index) => {- let detail = {};- try { detail = JSON.parse(receipts[index]?.event_detail ?? '{}'); } catch { /* Malformed legacy details remain unknown. */ }- return { ...verdict, check: detail.check ?? 'unknown', ...(detail.review ? { review: detail.review } : {}) };- });-}--/** The latest matching acceptance; the submission stays immutable through later re-reviews. */-export function acceptedVerdict(board, item) {- return verdictsFor(board, item.item_id).findLast(verdict =>- verdict.verdict_decision === 'ACCEPT' && verdict.verdict_commit === item.item_commit);-}--/** The exact checked composition for a new acceptance, or the historical submitted candidate. */-export function checkedLandingCommit(board, item) {- return acceptedVerdict(board, item)?.review?.head ?? item.item_commit;-}-/*** Insert a shout within the caller's transaction.*diff --git a/src/verdict-reviews.js b/src/verdict-reviews.jsnew file mode 100644index 00000000..f1fb7594--- /dev/null+++ b/src/verdict-reviews.js@@ -0,0 +1,44 @@+/** Sealed review validation and immutable acceptance projections [E8,H16]. */+import { Refused } from './refused.js';++/** Validate a sealed review without consulting Git or changing either replica [E8,H16]. */+export function verdictReviewProblem(review, commit, { checked } = {}) {+ const valid = review && typeof review === 'object' && !Array.isArray(review)+ && Object.keys(review).sort().join(',') === (checked === false ? 'commit,paths,trunk' : checked === true || Object.hasOwn(review, 'head') ? 'commit,head,paths,trunk' : 'commit,paths,trunk')+ && (!checked || Object.hasOwn(review, 'head'))+ && (!Object.hasOwn(review, 'head') || /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(review.head ?? ''))+ && review.commit === commit && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(review.commit ?? '')+ && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(review.trunk ?? '')+ && Array.isArray(review.paths) && review.paths.every(path => typeof path === 'string' && !path.includes('\0')+ && path.split('/').every(part => part && part !== '.' && part !== '..'))+ && JSON.stringify(review.paths) === JSON.stringify([...new Set(review.paths)].sort());+ return valid ? null : new Refused('BAD_VERDICT_REVIEW', checked ? 'the review must bind the current submitted commit, its checked commit, reviewed trunk and sorted unique candidate paths; use current Pullboard to review it again' : 'the review must bind the current submitted commit, its reviewed trunk and sorted unique candidate paths; use current Pullboard to review it again');+}++/**+ * Every verdict on an item, oldest first.+ *+ * @param {any} board+ * @param {number} id+ * @returns {any[]}+ */+export function verdictsFor(board, id) {+ const verdicts = board.db.prepare('SELECT * FROM verdict WHERE item_id = ? ORDER BY verdict_id').all(id);+ const receipts = board.db.prepare("SELECT event_kind, event_detail FROM event WHERE item_id = ? AND event_kind IN ('accept', 'reject') ORDER BY event_id").all(id);+ return verdicts.map((verdict, index) => {+ let detail = {};+ try { detail = JSON.parse(receipts[index]?.event_detail ?? '{}'); } catch { /* Malformed legacy details remain unknown. */ }+ return { ...verdict, check: detail.check ?? 'unknown', ...(detail.review ? { review: detail.review } : {}) };+ });+}++/** The latest matching acceptance; the submission stays immutable through later re-reviews. */+export function acceptedVerdict(board, item) {+ return verdictsFor(board, item.item_id).findLast(verdict =>+ verdict.verdict_decision === 'ACCEPT' && verdict.verdict_commit === item.item_commit);+}++/** The exact checked composition for a new acceptance, or the historical submitted candidate. */+export function checkedLandingCommit(board, item) {+ return acceptedVerdict(board, item)?.review?.head ?? item.item_commit;+}