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
perf(cli): load policy readers without execution machinery [C7]
Corey Olsondf0e75d95754
diff --git a/src/check-accept.js b/src/check-accept.jsindex 3205b7f7..e8b1346a 100644--- a/src/check-accept.js+++ b/src/check-accept.js@@ -3,7 +3,7 @@* until the person accepts that exact check [V2,V4,B26].*/import { createHash } from 'node:crypto';-import { provingCheck } from './check-baseline.js';+import { provingCheck } from './check-baseline-format.js';import {PERSON,atomic,@@ -14,7 +14,7 @@ import {import { COORDINATOR } from './config.js';import { requirePersonChannel } from './person.js';import { Refused } from './refused.js';-import { mainPolicy } from './trusted-policy.js';+import { mainPolicy } from './trusted-policy-read.js';/** The engine that first replays a person's check acceptance; older engines refuse the move unread [H16]. */export const CHECK_ACCEPT_ENGINE = 24;diff --git a/src/check-baseline-format.js b/src/check-baseline-format.jsnew file mode 100644index 00000000..81ff4bd5--- /dev/null+++ b/src/check-baseline-format.js@@ -0,0 +1,33 @@+/** Present recorded check observations without loading a shell runner [C7,V2]. */+/**+ * A check that would prove the work (#917): one that runs the item's new test file. The file is the one the+ * criterion or brief names, or one named after the item; the runner is the item's own Node test runner when it uses+ * one, and node --test otherwise, so an agent that set `npm test` gets a command it can paste.+ *+ * @param {{ item_title?: string, item_check?: string|null, item_criterion?: string|null, item_brief?: string|null }} item+ * @returns {string}+ */+export function provingCheck(item) {+ const named = /\b(test\/[\w./-]+\.test\.[cm]?js)\b/u.exec(`${item.item_criterion ?? ''}\n${item.item_brief ?? ''}`)?.[1];+ const slug = String(item.item_title ?? '').toLowerCase().replace(/[^a-z0-9]+/gu, '-').replace(/^-+|-+$/gu, '').slice(0, 48) || 'the-work';+ const runner = /^node\s+bin\/run-tests\.js\b/u.test(item.item_check ?? '') ? 'node bin/run-tests.js' : 'node --test';+ return `${runner} ${named ?? `test/${slug}.test.js`}`;+}++/** Print a recorded observation, including the warning every reviewer must see before work. */+export function sayCheckBaseline(io, item) {+ const base = item.item_check_baseline;+ if (!base) return;+ if (base.result === 'pending') {+ io.say(`check baseline running in the background at main ${base.main}: ${base.command}`);+ return;+ }+ if (base.result === 'unavailable') {+ io.say(`check baseline unavailable: ${base.reason}`);+ return;+ }+ io.say(`check baseline ${base.result} at main ${base.main}${base.reason ? ` (${base.reason})` : ''}: ${base.command}`);+ if (base.result === 'green') {+ io.say(`warning: [CRITERION_PROVES_NOTHING] this check already passes on main; use a check that fails before the work and passes after it, such as one that runs the new test: pullboard edit ${item.item_id} --check "${provingCheck(item)}"`);+ }+}diff --git a/src/check-baseline.js b/src/check-baseline.jsindex ee0b12a1..76bb3742 100644--- a/src/check-baseline.js+++ b/src/check-baseline.js@@ -1,3 +1,4 @@+export { provingCheck, sayCheckBaseline } from './check-baseline-format.js';/** Observe a proposed check on an isolated copy of main before recording its move [V2,H16]. */import { spawnSync } from 'node:child_process';import { randomUUID } from 'node:crypto';@@ -65,36 +66,3 @@ export function prepareCheckBaseline(root, command) {const base = { command, main: primary.commit };return { ...base, result: 'pending', request: randomUUID() };}--/**- * A check that would prove the work (#917): one that runs the item's new test file. The file is the one the- * criterion or brief names, or one named after the item; the runner is the item's own Node test runner when it uses- * one, and node --test otherwise, so an agent that set `npm test` gets a command it can paste.- *- * @param {{ item_title?: string, item_check?: string|null, item_criterion?: string|null, item_brief?: string|null }} item- * @returns {string}- */-export function provingCheck(item) {- const named = /\b(test\/[\w./-]+\.test\.[cm]?js)\b/u.exec(`${item.item_criterion ?? ''}\n${item.item_brief ?? ''}`)?.[1];- const slug = String(item.item_title ?? '').toLowerCase().replace(/[^a-z0-9]+/gu, '-').replace(/^-+|-+$/gu, '').slice(0, 48) || 'the-work';- const runner = /^node\s+bin\/run-tests\.js\b/u.test(item.item_check ?? '') ? 'node bin/run-tests.js' : 'node --test';- return `${runner} ${named ?? `test/${slug}.test.js`}`;-}--/** Print a recorded observation, including the warning every reviewer must see before work. */-export function sayCheckBaseline(io, item) {- const base = item.item_check_baseline;- if (!base) return;- if (base.result === 'pending') {- io.say(`check baseline running in the background at main ${base.main}: ${base.command}`);- return;- }- if (base.result === 'unavailable') {- io.say(`check baseline unavailable: ${base.reason}`);- return;- }- io.say(`check baseline ${base.result} at main ${base.main}${base.reason ? ` (${base.reason})` : ''}: ${base.command}`);- if (base.result === 'green') {- io.say(`warning: [CRITERION_PROVES_NOTHING] this check already passes on main; use a check that fails before the work and passes after it, such as one that runs the new test: pullboard edit ${item.item_id} --check "${provingCheck(item)}"`);- }-}diff --git a/src/cli-context.js b/src/cli-context.jsindex e38fe906..2a6db6f0 100644--- a/src/cli-context.js+++ b/src/cli-context.js@@ -25,7 +25,7 @@ import {tryGit,} from './git.js';import { Refused } from './refused.js';-import { mainPolicy } from './trusted-policy.js';+import { mainPolicy } from './trusted-policy-read.js';import { MAIN_MERGE_LABEL } from './trunk-conflict.js';/**diff --git a/src/cli-main.js b/src/cli-main.jsindex 31c694f0..ca38607a 100644--- a/src/cli-main.js+++ b/src/cli-main.js@@ -202,7 +202,7 @@ async function rememberTrunk(io, { repoInfo, mainCheckout }) {}if (!info.isMain) return;const primary = mainCheckout(info.root);- if (primary?.branch) (await import('./trusted-policy.js')).trunkRef(info.root, primary.branch);+ if (primary?.branch) (await import('./trusted-policy-read.js')).trunkRef(info.root, primary.branch);}/** Whether a parsed command line only prints version or help, which asks Git nothing. */diff --git a/src/commands/show.js b/src/commands/show.jsindex 30055ff9..7ae6c86b 100644--- a/src/commands/show.js+++ b/src/commands/show.js@@ -15,7 +15,7 @@ import {} from '../spec-approval.js';import {sayCheckBaseline,-} from '../check-baseline.js';+} from '../check-baseline-format.js';import * as infraNotes from '../infra-note.js';import {mainMergeFor,@@ -39,17 +39,17 @@ import { relayStateExists } from '../local-state.js';export async function run(io, { first, values }) {const ctx = context(io);const id = idArg(first);- const { item, verdicts, moves, thread, related, reviewer, agents, mainMerge, infra, approval } = withBoardRead(ctx, (board) => ({- item: verdictProjector(ctx.info.root, board).project(store.getItem(board, id)),- verdicts: store.verdictsFor(board, id),- moves: store.events(board, { itemId: id }).filter((event) => ['attempt', 'escalate'].includes(event.event_kind)),- thread: store.itemThread(board, id),- related: store.relatedItems(board, store.getItem(board, id)),- reviewer: store.reviewHolder(board, store.getItem(board, id)),- agents: store.listAgents(board), mainMerge: mainMergeFor(board, id), infra: infraNotes.infraNoteOf(store.events(board, { itemId: id })),- approval: specApprovalState(ctx.info.root, { board, config: ctx.config }),- }));- const agentName = (id) => displayAgentName(agents.find((agent) => agent.agent_id === id) ?? { agent_id: id }, ctx.config.agents.names);+ const { item, verdicts, moves, thread, related, reviewer, agents, mainMerge, infra, approval } = withBoardRead(ctx, (board) => {+ const item = verdictProjector(ctx.info.root, board).project(store.getItem(board, id));+ const result = { item, verdicts: store.verdictsFor(board, id), thread: store.itemThread(board, id),+ approval: specApprovalState(ctx.info.root, { board, config: ctx.config }) };+ // JSON retains every public detail field; text-only labels and related-item searches add nothing to it.+ if (values.json) return result;+ const history = store.events(board, { itemId: id });+ return { ...result, moves: history.filter((event) => ['attempt', 'escalate'].includes(event.event_kind)),+ related: store.relatedItems(board, item), reviewer: store.reviewHolder(board, item),+ agents: store.listAgents(board), mainMerge: mainMergeFor(board, id), infra: infraNotes.infraNoteOf(history) };+ });const agentApproved = itemAgentApprovals(item, approval);const approvalQualification = agentApprovalLine(agentApproved);// #922: moves on this item made while the relay was down wait in this machine's relay outbox until it answers.@@ -60,6 +60,7 @@ export async function run(io, { first, values }) {io.result({ ...item, verdicts, thread, agentApproved, approvalQualification, ...(relayPending.length ? { relayPending } : {}) });return 0;}+ const agentName = (id) => displayAgentName(agents.find((agent) => agent.agent_id === id) ?? { agent_id: id }, ctx.config.agents.names);io.say(itemLine(item, agentName, Boolean(mainMerge)));if (item.item_status === 'verified' && approvalQualification) io.say(approvalQualification);if (item.item_verdict_state) io.say(staleVerdictRefusal(item, item.item_verdict_state).message);diff --git a/src/row-drafts.js b/src/row-drafts.jsindex 1aabfb33..a5d141ea 100644--- a/src/row-drafts.js+++ b/src/row-drafts.js@@ -20,7 +20,7 @@ import {parseSpec,} from './spec.js';import { cleanGitEnvironment } from './git.js';-import { trunkRef } from './trusted-policy.js';+import { trunkRef } from './trusted-policy-read.js';/** The board's recorded row drafts, oldest first. */export function rowDrafts(board) {diff --git a/src/trunk-revision.js b/src/trunk-revision.jsindex d794b5bd..00178c45 100644--- a/src/trunk-revision.js+++ b/src/trunk-revision.js@@ -4,7 +4,7 @@ import {statSync,} from 'node:fs';import { join } from 'node:path';-import { trunkRef } from './trusted-policy.js';+import { trunkRef } from './trusted-policy-read.js';/** Invalidate a retained branch lookup only when its local configuration changes. */function fileMarkerForPath(path) {diff --git a/src/trusted-policy-read.js b/src/trusted-policy-read.jsnew file mode 100644index 00000000..8acd5f1c--- /dev/null+++ b/src/trusted-policy-read.js@@ -0,0 +1,50 @@+/** Read committed coordinator policy without loading check execution or resource admission [C7,V4]. */+import { spawnSync } from 'node:child_process';+import { configFromSource } from './config.js';+import {+ cleanGitEnvironment,+ gitConfig,+ invalidateGitFacts,+ localConfigIs,+ mainCheckout,+} from './git.js';+import { Refused } from './refused.js';++/** Read raw Git output, retaining NUL-delimited names without exposing Git diagnostics. */+export function policyGit(root, args) {+ const result = spawnSync('git', ['-c', 'core.quotepath=false', ...args], { cwd: root, env: cleanGitEnvironment(), encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 });+ if (result.status !== 0) throw new Refused('NO_POLICY', 'the committed coordinator policy or claim base is missing; restore its Git objects or ask the coordinator to refreeze the item');+ return result.stdout;+}++/** Resolve the primary checkout's committed HEAD, independently of a linked or detached checkout. */+export function mainPolicy(root) {+ const checkout = mainCheckout(root);+ if (!checkout) throw new Refused('NO_POLICY', 'the coordinator checkout is detached for review; ask it to return to its main branch before claiming or running the project gate');+ if (!checkout.commit) throw new Refused('NO_POLICY', 'the coordinator checkout has no commit on ' + checkout.branch + '; create its first commit before claiming or running the project gate');+ return policyAt(root, checkout.commit);+}++/** Retain the local primary branch outside replicated board data and read-only diagnostics [B34,V6]. */+export function trunkRef(root, branch) {+ // A trunk already recorded as this branch needs no Git process to confirm and nothing written.+ if (branch !== undefined && localConfigIs(root, 'pullboard', 'trunk', branch)) return branch;+ const read = gitConfig(root, 'pullboard.trunk', { local: true, clean: true, flags: false, noReplace: true });+ if (read.status !== 0 && read.status !== 1) throw new Refused('NO_POLICY', 'the retained trunk cannot be read; restore the local Git configuration and retry');+ const current = read.status === 0 ? read.stdout.trim() : null;+ if (branch === undefined || branch === current) return current;+ const saved = spawnSync('git', ['--no-replace-objects', 'config', '--local', '--replace-all', 'pullboard.trunk', branch], {+ cwd: root, env: cleanGitEnvironment(), encoding: 'utf8',+ });+ invalidateGitFacts();+ if (saved.status !== 0) throw new Refused('NO_POLICY', 'the trunk branch cannot be recorded; restore writable local Git configuration and retry');+ return branch;+}++/** Re-read coordinator settings from a pinned Git object; never from the candidate filesystem. */+export function policyAt(root, commit) {+ if (!/^[0-9a-f]{40,64}$/.test(commit ?? '')) throw new Refused('NO_POLICY', 'this item has no recorded claim base; ask the coordinator to refreeze it and claim it again');+ const config = configFromSource(policyGit(root, ['show', commit + ':pullboard.json']));+ return { version: 1, commit, config };+}+diff --git a/src/trusted-policy.js b/src/trusted-policy.jsindex f9888d3b..479ea6d7 100644--- a/src/trusted-policy.js+++ b/src/trusted-policy.js@@ -1,3 +1,5 @@+import { mainPolicy, policyAt, policyGit, trunkRef } from './trusted-policy-read.js';+export { mainPolicy, policyAt, trunkRef } from './trusted-policy-read.js';/** Coordinator policy and immutable submission checks cannot come from a builder's candidate [V4,V16,L3,M3]. */import { randomUUID } from 'node:crypto';import { spawnSync } from 'node:child_process';@@ -31,12 +33,8 @@ import {GATE_SLOT_HELD_ENV,gateSlotEnvironment,} from './resources.js';-import { configFromSource } from './config.js';import {cleanGitEnvironment,- gitConfig,- invalidateGitFacts,- localConfigIs,mainCheckout,refuseGrafts,} from './git.js';@@ -44,37 +42,6 @@ import { secretsIn } from './hooks.js';import { outOfLane } from './lanes.js';import { Refused } from './refused.js';-/** Read raw Git output, retaining NUL-delimited names without exposing Git diagnostics. */-function policyGit(root, args) {- const result = spawnSync('git', ['-c', 'core.quotepath=false', ...args], { cwd: root, env: cleanGitEnvironment(), encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 });- if (result.status !== 0) throw new Refused('NO_POLICY', 'the committed coordinator policy or claim base is missing; restore its Git objects or ask the coordinator to refreeze the item');- return result.stdout;-}--/** Resolve the primary checkout's committed HEAD, independently of a linked or detached checkout. */-export function mainPolicy(root) {- const checkout = mainCheckout(root);- if (!checkout) throw new Refused('NO_POLICY', 'the coordinator checkout is detached for review; ask it to return to its main branch before claiming or running the project gate');- if (!checkout.commit) throw new Refused('NO_POLICY', 'the coordinator checkout has no commit on ' + checkout.branch + '; create its first commit before claiming or running the project gate');- return policyAt(root, checkout.commit);-}--/** Retain the local primary branch outside replicated board data and read-only diagnostics [B34,V6]. */-export function trunkRef(root, branch) {- // A trunk already recorded as this branch needs no Git process to confirm and nothing written.- if (branch !== undefined && localConfigIs(root, 'pullboard', 'trunk', branch)) return branch;- const read = gitConfig(root, 'pullboard.trunk', { local: true, clean: true, flags: false, noReplace: true });- if (read.status !== 0 && read.status !== 1) throw new Refused('NO_POLICY', 'the retained trunk cannot be read; restore the local Git configuration and retry');- const current = read.status === 0 ? read.stdout.trim() : null;- if (branch === undefined || branch === current) return current;- const saved = spawnSync('git', ['--no-replace-objects', 'config', '--local', '--replace-all', 'pullboard.trunk', branch], {- cwd: root, env: cleanGitEnvironment(), encoding: 'utf8',- });- invalidateGitFacts();- if (saved.status !== 0) throw new Refused('NO_POLICY', 'the trunk branch cannot be recorded; restore writable local Git configuration and retry');- return branch;-}-/** Resolve the trunk snapshot and refuse a conflict without touching an index or worktree [B34,V6].** Returning the exact ref and tip lets later candidate checks use the same snapshot this merge@@ -115,13 +82,6 @@ export function trunkMerge(root, commit, retainedRef = trunkRef(root)) {return { ref: branchRef, commit: tip.stdout.trim(), files: records.slice(0, end < 0 ? records.length : end) };}-/** Re-read coordinator settings from a pinned Git object; never from the candidate filesystem. */-export function policyAt(root, commit) {- if (!/^[0-9a-f]{40,64}$/.test(commit ?? '')) throw new Refused('NO_POLICY', 'this item has no recorded claim base; ask the coordinator to refreeze it and claim it again');- const config = configFromSource(policyGit(root, ['show', commit + ':pullboard.json']));- return { version: 1, commit, config };-}-/** Use new claims' frozen policy; legacy claims retain their committed claim-base settings. */export function itemPolicy(root, item) {let frozen;diff --git a/src/verdict-freshness.js b/src/verdict-freshness.jsindex cc2aecf1..1194ba2d 100644--- a/src/verdict-freshness.js+++ b/src/verdict-freshness.js@@ -5,7 +5,7 @@ import {cleanGitEnvironment,mainCheckout,} from './git.js';-import { trunkRef } from './trusted-policy.js';+import { trunkRef } from './trusted-policy-read.js';import { Refused } from './refused.js';import { trunkRevisionReader } from './trunk-revision.js';