Skip to content

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.

feat(gate): run project static guards before proof [C7]

Corey Olson4bfc5e386fdd
diff --git a/bin/static-style-checks.js b/bin/static-style-checks.js
new file mode 100644
index 00000000..e72f5762
--- /dev/null
+++ b/bin/static-style-checks.js
@@ -0,0 +1,37 @@
+#!/usr/bin/env node
+/** The Pullboard repository's source-only preflight; no browser fixtures run [C7]. */
+import { readFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { spawnSync } from 'node:child_process';
+import { importStyleViolations } from '../src/static-import-style.js';
+import { declaredProseCommands } from '../src/static-prose-commands.js';
+import { doctrineReport } from '../src/doctrine-checks.js';
+import { loadConfig } from '../src/config.js';
+import { HELP } from '../src/cli.js';
+import { PULLBOARD_COMMANDS } from '../src/cockpit.js';
+
+const root = process.cwd();
+let failed = false;
+const sources = ['src/cli.js', 'src/cockpit.js', 'src/serve.js'].map(file => ({ file, source: readFileSync(join(root, file), 'utf8') }));
+for (const row of importStyleViolations(sources)) {
+ console.error(`${row.file}:${row.line}: one import binding per line (${row.count} bindings)`);
+ failed = true;
+}
+const declared = [...declaredProseCommands(HELP)].sort();
+const actual = [...PULLBOARD_COMMANDS].sort();
+if (JSON.stringify(declared) !== JSON.stringify(actual)) {
+ console.error('src/cockpit.js: prose command declaration differs from the CLI help catalog');
+ failed = true;
+}
+const clock = spawnSync(process.execPath, ['test/wall-clock-budgets.js'], { cwd: root, encoding: 'utf8' });
+if (clock.stdout) process.stdout.write(clock.stdout);
+if (clock.stderr) process.stderr.write(clock.stderr);
+if (clock.status !== 0) failed = true;
+for (const row of doctrineReport(root, loadConfig(root))) {
+ if (!row.holds) {
+ console.error(`doctrine ${row.id}: ${row.state}\n${row.problems.join('\n')}`);
+ failed = true;
+ }
+}
+if (!failed) console.log('static style, prose declarations, clock budgets and doctrine hold');
+process.exitCode = failed ? 1 : 0;
diff --git a/docs/api.md b/docs/api.md
index 323061ca..fa69f3cc 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -506,3 +506,5 @@ When the runner's own resource pool refuses the run's setup, the run fails at on
Agents and the coordinator can set explicit item ranks with `milestone order <name> <ids>` (comma-separated ids from that milestone). It replaces that milestone’s `order` list in board metadata; other items stay unranked. `next` compares milestone, explicit rank, then its existing route/recent-file/age tie-breaks. A never-ranked board keeps its existing order. Removing an item drops its rank; adding it again leaves it unranked. This does not change newcomer help or person flows.
`resume` on the coordinator seat includes `rigor: {undrafted: [...]}`, naming each repeated cause that has no live or approved proved draft. Each entry retains the ordinary Rigor cause key, item evidence and commits. The text resume names the proof-bearing `pullboard rigor draft` command. Declined repeats stay quiet until a new item repeats them. `needsYou` may contain an individual `kind: "rigor-draft"` call with `cause`, `evidence`, `proof`, a qualified spec or doctrine `target`, and `what: "Approve or Decline"`. An ordinary draft remains in the existing aggregate count; a Rigor draft is not counted twice. These fields add no person permission: the existing person-only approval and decline channels still apply.
+
+A project may declare a `staticChecks` command in `pullboard.json` (empty by default). Submit uses the command from accepted main, and an explicit item check uses its accepted policy, so candidate settings cannot remove the guard. It runs before the frozen check and affected proof; a refusal retains the static log and reports the offending source. The existing queue and conservative browser classification still apply. Pullboard's own command checks actual CLI/View import bindings, the source-only prose command declaration, wall-clock budget explanations and doctrine counts. Browser prose behavior remains in the ordinary test suite.
diff --git a/pullboard.json b/pullboard.json
index 6d14a716..1ed5b328 100644
--- a/pullboard.json
+++ b/pullboard.json
@@ -91,5 +91,6 @@
"fix"
],
"noEmoji": true
- }
+ },
+ "staticChecks": "node --experimental-vm-modules --disable-warning=ExperimentalWarning bin/static-style-checks.js"
}
diff --git a/src/cli.js b/src/cli.js
index 42cae954..5e892b3f 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -88,6 +88,7 @@ import {
runGate,
runProfiledShell,
runSubmitGate,
+ runStaticChecks,
submitGateReport,
timingDigest,
withGateSlot,
@@ -2726,7 +2727,7 @@ async function submitHere(ctx, id) {
for (const rule of doctrine) ctx.io.say(`doctrine: ${ruleLine(rule)}`);
// Every submit proves its frozen check and reachable tests anew on this exact commit (V4,V16).
// A full-gate stamp never substitutes for either proof; only an actual full fallback may stamp.
- const submitConfig = { ...ctx.config, submitGate: acceptedMain.config.submitGate,
+ const submitConfig = { ...ctx.config, submitGate: acceptedMain.config.submitGate, staticChecks: acceptedMain.config.staticChecks,
submitInvariants: acceptedMain.config.submitInvariants,
// The accepted project runner interprets its current invariant files; candidate config cannot replace it.
...(acceptedMain.config.submitInvariants.length ? { affectedTests: acceptedMain.config.affectedTests } : {}) };
@@ -3572,8 +3573,7 @@ function workCommands(io, args) {
});
const check = frozenCheck(item);
if (!check) throw new Refused('NO_CHECK', `#${item.item_id} has no check command; its proof is the project gate: pullboard gate`);
- if (item.item_claim_head) itemPolicy(ctx.info.root, item);
- else mainPolicy(ctx.info.root);
+ const policy = item.item_claim_head ? itemPolicy(ctx.info.root, item) : mainPolicy(ctx.info.root);
const by = author || 'unknown (legacy)';
const authorName = author ? agentDisplayName(agents, ctx.config, author) : by;
const notice = `check #${item.item_id} set by ${authorName}: ${check}`;
@@ -3587,6 +3587,7 @@ function workCommands(io, args) {
throw new Refused('CHECK_CONFIRM', `the check set by ${authorName} was not run: ${check}; run pullboard check ${item.item_id} --yes after reading the command, or answer yes at the prompt`);
}
}
+ await runStaticChecks(ctx.info.root, policy.config, { agent: caller, item: String(item.item_id), onWait: queuedItemLease(ctx, item, caller, 'build'), onBrowserFallback: browserAdmissionReporter(io, values.json) });
const browser = !browserFreeChecksEnabled() || await checkNeedsBrowser(ctx.info.root, check, { onFallback: browserAdmissionReporter(io, values.json) });
const shortEligible = Boolean(await explicitCheckFiles(ctx.info.root, check));
const run = await withGateSlot(ctx.info.root, (lease) => runProfiledShell(ctx.info.root, check, { waitMs: lease.waitMs, artifactPrefix: `pullboard-check-${item.item_id}`, persistLog: true, gateLease: lease }), { browser, agent: caller, item: String(item.item_id), kind: 'check', itemCheck: true, shortEligible, onWait: queuedItemLease(ctx, item, caller, 'build') });
diff --git a/src/config.js b/src/config.js
index aa6e73b9..fb74f5ba 100644
--- a/src/config.js
+++ b/src/config.js
@@ -45,6 +45,7 @@ export function defaults() {
practice: DOCTRINE_FILE,
gate: '',
submitInvariants: [],
+ staticChecks: '',
lease: '2h',
reviewLease: '30m',
worktrees: 'beside',
@@ -170,6 +171,7 @@ export function configProblems(config) {
if (config.landingShards !== undefined && (!Number.isSafeInteger(config.landingShards) || config.landingShards < 1 || config.landingShards > 64)) {
problems.push('"landingShards" is a whole number from 1 to 64: how many shards the landing gate splits its test files into');
}
+ if (typeof config.staticChecks !== 'string') problems.push('"staticChecks" is an optional project static-check command');
if (config.affectedTests !== undefined && (typeof config.affectedTests !== 'string' || !config.affectedTests.trim())) {
problems.push('"affectedTests" is a nonempty command prefix used to run selected test files');
}
diff --git a/src/gate.js b/src/gate.js
index 5f998052..88c7193b 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -553,6 +553,19 @@ function commandWord(value) {
return `'${String(value).replaceAll("'", "'\\''")}'`;
}
+/** Run the project's declared static guard before proof, retaining normal queue classification. */
+export async function runStaticChecks(root, config, { agent, item = '', onWait, onBrowserFallback } = {}) {
+ const command = config.staticChecks?.trim();
+ if (!command) return null;
+ const browser = !browserFreeChecksEnabled() || await checkNeedsBrowser(root, command, { onFallback: onBrowserFallback });
+ return withGateSlot(root, lease => {
+ const run = runProfiledShell(root, command, { waitMs: lease.waitMs, artifactPrefix: 'pullboard-static-checks', persistLog: true, gateLease: lease });
+ refuseSandboxBlocked(run);
+ if (!run.isGreen) throw new Refused('GATE_RED', `static checks are red; fix the named source before running proof:\n${digestOf(run.output)}`);
+ return run;
+ }, { browser, agent, item, kind: 'static', itemCheck: true, shortEligible: true, onWait });
+}
+
/**
* Prove the frozen item check and selected imports under one lease. Subsets neither read nor write
* the full-gate stamp. An uncertain selection runs the full configured gate and records its reason.
@@ -564,6 +577,7 @@ function commandWord(value) {
*/
export async function runSubmitGate(root, config, { base, trunk, changed, check, agent, item = '', kind = 'submit', onWait, onBrowserFallback }) {
if (!config.gate.trim()) throw new Refused('NO_GATE', 'no gate configured; set "gate" in pullboard.json, e.g. "npm test"');
+ await runStaticChecks(root, config, { agent, item, onWait, onBrowserFallback });
const selection = config.affectedTests
? selectAffectedTests(root, { base, trunk, changed })
: { full: true, reason: 'affected-test selection is not enabled for this project', files: [] };
diff --git a/src/static-import-style.js b/src/static-import-style.js
new file mode 100644
index 00000000..848fcdf1
--- /dev/null
+++ b/src/static-import-style.js
@@ -0,0 +1,62 @@
+/** Read actual static import bindings without executing repository source [C7]. */
+import vm from 'node:vm';
+
+const GAP = String.raw`(?:\s|/\*[\s\S]*?\*/|//[^\r\n\u2028\u2029]*(?:\r\n|[\r\n\u2028\u2029]|$))*`;
+const IDENTIFIER = String.raw`[\p{ID_Start}_$][\p{ID_Continue}$\u200c\u200d]*`;
+const NAMED = new RegExp(String.raw`\bimport${GAP}(?:(?<default>${IDENTIFIER})${GAP},${GAP})?\{(?<bindings>[^{}]*)\}`, 'dgu');
+const NAMESPACE = new RegExp(String.raw`\bimport${GAP}(?<default>${IDENTIFIER})${GAP},${GAP}\*${GAP}as${GAP}(?<namespace>${IDENTIFIER})`, 'dgu');
+
+/** Keep line positions while removing comments inside an import's binding list. */
+function withoutComments(text) {
+ return text.replace(/(['"])(?:\\[\s\S]|(?!\1)[^\\])*\1|\/\/[^\r\n\u2028\u2029]*|\/\*[\s\S]*?\*\//gu,
+ (part) => part.startsWith('/') ? part.replace(/[^\r\n\u2028\u2029]/gu, ' ') : part);
+}
+
+/** Read binding starts, treating quoted exported names and aliases as one binding each. */
+function bindingOffsets(text) {
+ const clean = withoutComments(text);
+ const starts = [];
+ let start = 0;
+ let quote = null;
+ for (let index = 0; index <= clean.length; index++) {
+ const character = clean[index];
+ if (quote) {
+ if (character === '\\') index++;
+ else if (character === quote) quote = null;
+ } else if (character === '"' || character === "'") quote = character;
+ else if (character === ',' || index === clean.length) {
+ const first = /\S/u.exec(clean.slice(start, index));
+ if (first) starts.push(start + first.index);
+ start = index + 1;
+ }
+ }
+ return starts;
+}
+
+/** Compile syntax without linking modules, treating embedded source text as data. */
+function compiles(source) {
+ try { new vm.SourceTextModule(source); return true; } catch { return false; }
+}
+
+/** Report only multiple actual bindings on one physical import line. */
+export function importStyleViolations(sources) {
+ if (typeof vm.SourceTextModule !== 'function') throw new Error('run static checks with node --experimental-vm-modules');
+ return sources.flatMap(({ file, source }) => {
+ if (!compiles(source)) throw new Error(`${file}: source does not compile`);
+ const named = [...source.matchAll(NAMED)].map(match => ({ at: match.index, offsets: [
+ ...(match.groups.default ? [match.indices.groups.default[0]] : []),
+ ...bindingOffsets(match.groups.bindings).map(offset => match.indices.groups.bindings[0] + offset),
+ ] }));
+ const spaces = [...source.matchAll(NAMESPACE)].map(match => ({ at: match.index,
+ offsets: [match.indices.groups.default[0], match.indices.groups.namespace[0]] }));
+ return [...named, ...spaces].flatMap(({ at, offsets }) => {
+ if (compiles(source.slice(0, at) + '\u0000' + source.slice(at))) return [];
+ const lines = new Map();
+ for (const offset of offsets) {
+ const line = source.slice(0, offset).split(/\r\n|[\n\r\u2028\u2029]/u).length;
+ lines.set(line, (lines.get(line) ?? 0) + 1);
+ }
+ return [...lines].filter(([, count]) => count > 1).map(([line, count]) => ({ file, line, count }));
+ });
+ });
+}
diff --git a/src/static-prose-commands.js b/src/static-prose-commands.js
new file mode 100644
index 00000000..27fa9bfd
--- /dev/null
+++ b/src/static-prose-commands.js
@@ -0,0 +1,32 @@
+/** The source-only prose oracle; browser chip behavior stays in the View suite [N26,C7]. */
+/** Read the CLI command declaration without starting a page or evaluating user prose. */
+export function declaredProseCommands(help) {
+ const declared = new Set();
+ const read = (text) => {
+ // Usage alternatives may follow an argument or an optional group: spec approve <ids> | decline <ids>, and
+ // spec fit [approve <batch>] | fit edit <row>, whose alternative restates the last word.
+ for (const branch of text.matchAll(/pullboard ((?:[a-z-]+ )+)(?:<[^>]+> |\[[^\]]+\] )?\| ([a-z-]+(?: [a-z-]+)*)/g)) {
+ const shared = branch[1].trim().split(' ').slice(0, -1);
+ read('pullboard ' + [...shared, branch[2]].join(' '));
+ }
+ for (const found of text.matchAll(/(?:^|[\s(`'"])pullboard ((?:\S+ ?)+?)(?= {2}|$|[;,.)](?:\s|$))/gm)) {
+ const tokens = found[1].trim().split(' ');
+ const phrase = [];
+ for (let n = 0; n < tokens.length; n++) {
+ const token = tokens[n];
+ if (/^[a-z][a-zA-Z-]*$/.test(token)) { phrase.push(token); continue; }
+ const choices = /^\[?([a-z][a-zA-Z-]*(?:\|[a-z][a-zA-Z-]*)+)\]?$/.exec(token);
+ if (choices) for (const choice of choices[1].split('|')) declared.add([...phrase, choice].join(' '));
+ else if (token === '|' && phrase.length === 1) {
+ for (let k = n + 1; k < tokens.length; k += 2) { if (!/^[a-z][a-zA-Z-]*$/.test(tokens[k])) break; declared.add(tokens[k]); if (tokens[k + 1] !== '|') break; }
+ }
+ break;
+ }
+ if (phrase.length) declared.add(phrase.join(' '));
+ }
+ };
+ read(help.all);
+ for (const name of Object.keys(help.commands)) declared.add(name);
+ for (const row of Object.values(help.commands)) for (const usage of row.usages) read(usage);
+ return declared;
+}
diff --git a/test/submit-gate.test.js b/test/submit-gate.test.js
index 78a3d751..9ef2fc15 100644
--- a/test/submit-gate.test.js
+++ b/test/submit-gate.test.js
@@ -1388,7 +1388,7 @@ test('a submit runs the static style checks first [C7]', t => {
const check = 'node -e "require(\'node:fs\').writeFileSync(process.env.ITEM_CHECK_MARKER, \'ran\')"';
put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node -e "process.exit(0)"',
affectedTests: 'node --test', submitGate: 'landing', staticChecks: 'node test/static-style-check.mjs',
- spec: 'SPEC.md', verify: 'any', lease: '2h' }));
+ spec: 'SPEC.md', verify: 'any', lease: '2h', shared: ['pullboard.json'] }));
put(box.root, 'src/cli.js', "import { join } from 'node:path';\nexport const fixture = join;\n");
const oracle = new URL('./import-style-helpers.js', import.meta.url).href;
put(box.root, 'test/static-style-check.mjs', [
@@ -1404,6 +1404,9 @@ test('a submit runs the static style checks first [C7]', t => {
const added = box.coordinator('add', 'build', 'Static style before proof', '--check', check);
assert.equal(added.code, 0, added.err);
assert.equal(box.run('claim', '1').code, 0);
+ const candidateConfig = JSON.parse(readFileSync(join(box.root, 'pullboard.json'), 'utf8'));
+ candidateConfig.staticChecks = '';
+ put(box.root, 'pullboard.json', JSON.stringify(candidateConfig));
put(box.root, 'src/cli.js', "import { join, resolve } from 'node:path';\nexport const fixture = join;\n");
commitAll(box, 'feat(core): expose the missed static guard [G1]');
rmSync(marker, { force: true });
@@ -1412,4 +1415,8 @@ test('a submit runs the static style checks first [C7]', t => {
assert.match(submitted.out + submitted.err, /src\/cli\.js:1: one import binding per line/u);
assert.equal(existsSync(marker), false, 'the frozen item check must not run after an early static refusal');
assert.equal(JSON.parse(box.run('show', '1', '--json').out).item_status, 'claimed');
+ const checked = box.run('check', '1', '--yes', '--json');
+ assert.notEqual(checked.code, 0, 'an explicit check must run the same accepted project guard first');
+ assert.match(checked.out + checked.err, /src\/cli\.js:1: one import binding per line/u);
+ assert.equal(existsSync(marker), false, 'neither a submit nor a check bypasses the failed static guard');
});