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): isolate landing environment guards [E28,E29]
Corey Olson630158758005
diff --git a/src/board.js b/src/board.jsindex 9f9efa34..50524751 100644--- a/src/board.js+++ b/src/board.js@@ -73,8 +73,7 @@ import {} from './machine.js';import { LOCAL_LANDING_ENGINE } from './land-engine.js';import { SPEC_APPROVAL_ENGINE } from './spec-approval-engine.js';-import { LANDING_ENVIRONMENT_ENGINE } from './landing-environment-engine.js';-import { carriesLandingEnvironment, environmentProblem } from './execution-environment.js';+import * as landingEnvironment from './landing-environment-guards.js';import { Refused } from './refused.js';import { refuseMaskedExit } from './check-mask.js';import {@@ -1573,8 +1572,7 @@ export function verify(board, id, { agentId, decision, reason, note = '', cause,const isAccept = verb === 'accept';const code = isAccept ? ACCEPT_REASON : reason;const engine = board.executionEngineVersion ?? ENGINE_VERSION;- if (environment !== undefined && engine < LANDING_ENVIRONMENT_ENGINE) throw new Refused('ENGINE_VERSION', `verdict environments require engine ${LANDING_ENVIRONMENT_ENGINE}`);- if (environment !== undefined && environment !== null && environmentProblem(environment)) throw new Refused('VERDICT_ENVIRONMENT', 'a verdict environment needs exact platform, arch and Node version');+ landingEnvironment.requireVerdict(board, environment);const declaration = MOVES.find(move => move.verb === verb);const newReview = engine >= VERDICT_REVIEW_ENGINE && review !== undefined;// Without the new sealed metadata, old moves keep their exact submitted-only semantics.@@ -2672,12 +2670,7 @@ export { landingBatches };/** Append one coordinator-owned batch revision without changing the board schema [B3,R3]. */export function recordLandingBatch(board, { agentId, batch, revision = 0, landingFence }) {coordinatorOnly(agentId, 'records landing batches');- if ((board.executionEngineVersion ?? ENGINE_VERSION) < LANDING_ENVIRONMENT_ENGINE && board.db.prepare("SELECT 1 FROM event WHERE event_kind = 'landing-test-defect' LIMIT 1").get()) throw new Refused('ENGINE_VERSION', `this trunk has test-defect holds requiring engine ${LANDING_ENVIRONMENT_ENGINE}`);- if (carriesLandingEnvironment(batch) && (board.executionEngineVersion ?? ENGINE_VERSION) < LANDING_ENVIRONMENT_ENGINE) throw new Refused('ENGINE_VERSION', `landing environments and test defects require engine ${LANDING_ENVIRONMENT_ENGINE}`);- if (batch?.environmentWarnings !== undefined && !Array.isArray(batch.environmentWarnings)) throw new Refused('LAND_BATCH', 'landing environment warnings are a list');- const environments = [batch?.environment, ...(Array.isArray(batch?.gateResults) ? batch.gateResults : []).map(gate => gate?.environment),- ...(batch?.environmentWarnings ?? []).flatMap(warning => [warning?.recorded, warning?.landing])];- if (environments.some(environment => environment !== undefined && environment !== null && environmentProblem(environment))) throw new Refused('LAND_BATCH', 'a landing executor needs exact platform, arch and Node version');+ landingEnvironment.requireBatch(board, batch);if (carriesFlakeDiagnostics(batch) && (board.executionEngineVersion ?? ENGINE_VERSION) < NATIVE_FLAKE_ENGINE) {throw new Refused('ENGINE_VERSION', `typed landing diagnostics require engine ${NATIVE_FLAKE_ENGINE}; upgrade Pullboard`);}@@ -2691,8 +2684,7 @@ export function recordLandingBatch(board, { agentId, batch, revision = 0, landinreturn atomic(board, () => {guardLandingWrite(board, landingFence);const previous = landingBatches(board).find((entry) => entry.id === batch.id);- if (carriesLandingEnvironment(previous) && (board.executionEngineVersion ?? ENGINE_VERSION) < LANDING_ENVIRONMENT_ENGINE) throw new Refused('ENGINE_VERSION', `this batch requires engine ${LANDING_ENVIRONMENT_ENGINE}`);- if (previous && ['environment', 'testDefects'].some(key => Object.hasOwn(previous, key) && !Object.hasOwn(batch, key))) throw new Refused('LAND_BATCH', 'a landing revision keeps its recorded executor and test defects');+ landingEnvironment.requireRevision(board, previous, batch);preserveInvariantEvidence(previous, evidence, board.executionEngineVersion ?? ENGINE_VERSION);validateLandingRevision(previous, batch, revision);const recorded = { ...batch, revision: revision + 1, updatedAt: now(board) };@@ -2766,12 +2758,12 @@ export function waivedLandingProof(board, tree) {/** Atomically record a pushed batch's first-containing merges and one main-moved receipt [B3,R3]. */export function finishLandingBatch(board, { agentId, id, tip, landingFence }) {coordinatorOnly(agentId, 'finishes a landing');- if ((board.executionEngineVersion ?? ENGINE_VERSION) < LANDING_ENVIRONMENT_ENGINE && board.db.prepare("SELECT 1 FROM event WHERE event_kind = 'landing-test-defect' LIMIT 1").get()) throw new Refused('ENGINE_VERSION', `this trunk has test-defect holds requiring engine ${LANDING_ENVIRONMENT_ENGINE}`);+ landingEnvironment.requireTrunk(board);return atomic(board, () => {guardLandingWrite(board, landingFence);const batch = landingBatches(board).find((entry) => entry.id === id);if (!batch || batch.tip !== tip) throw new Refused('LAND_BATCH', 'the pushed tip must match its recorded batch; run pullboard land --adopt');- if (carriesLandingEnvironment(batch) && (board.executionEngineVersion ?? ENGINE_VERSION) < LANDING_ENVIRONMENT_ENGINE) throw new Refused('ENGINE_VERSION', `this batch requires engine ${LANDING_ENVIRONMENT_ENGINE}`);+ landingEnvironment.requireStoredBatch(board, batch);if (batch.state === 'landed') return batch;if (batch.state !== 'pushed' && !(batch.state === 'trunk' && (board.executionEngineVersion ?? ENGINE_VERSION) >= LOCAL_LANDING_ENGINE)) throw new Refused('LAND_NOT_PUSHED', 'record a successful push before landing receipts; run pullboard land --adopt');for (const entry of batch.items) {diff --git a/src/commands/settings.js b/src/commands/settings.jsindex b7d18e8f..9f58e0f5 100644--- a/src/commands/settings.js+++ b/src/commands/settings.js@@ -16,7 +16,10 @@ import {setGateSlots,setLandingPool,} from '../settings.js';-import { context, withBoard } from '../cli.js';+import {+ context,+ withBoard,+} from '../cli.js';import { boardId } from '../board.js';/** Read or update machine-wide gate capacity. */diff --git a/src/gate.js b/src/gate.jsindex 2698e6ea..08595dd4 100644--- a/src/gate.js+++ b/src/gate.js@@ -37,7 +37,10 @@ import {tmpdir,} from 'node:os';import { fileURLToPath } from 'node:url';-import { environmentProblem, executionEnvironment } from './execution-environment.js';+import {+ environmentProblem,+ executionEnvironment,+} from './execution-environment.js';import { constrainedLandingHost } from './landing-host.js';import {gitChildEnv,diff --git a/src/land.js b/src/land.jsindex befed852..a629c0f4 100644--- a/src/land.js+++ b/src/land.js@@ -50,7 +50,10 @@ import {import { runLandingWorker } from './landing-worker.js';import { Refused } from './refused.js';import { requireLandingHost } from './landing-host.js';-import { environmentLabel, sameEnvironment } from './execution-environment.js';+import {+ environmentLabel,+ sameEnvironment,+} from './execution-environment.js';import { browserFreeChecksEnabled } from './settings.js';import { policyAt } from './trusted-policy.js';import { landingFileTimes } from './submit-invariants.js';diff --git a/src/landing-environment-guards.js b/src/landing-environment-guards.jsnew file mode 100644index 00000000..732109bd--- /dev/null+++ b/src/landing-environment-guards.js@@ -0,0 +1,43 @@+/** Board-only replay guards stay outside both the oversized board and the trusted runner runtime [E28,E29]. */+import {+ carriesLandingEnvironment,+ environmentProblem,+} from './execution-environment.js';+import { LANDING_ENVIRONMENT_ENGINE } from './landing-environment-engine.js';+import { ENGINE_VERSION } from './machine.js';+import { Refused } from './refused.js';++/** Preserve the replay engine instead of assigning current semantics to an old move. */+function engine(board) { return board.executionEngineVersion ?? ENGINE_VERSION; }++/** Validate optional verdict metadata while preserving historical absence and explicit unknowns. */+export function requireVerdict(board, environment) {+ if (environment !== undefined && engine(board) < LANDING_ENVIRONMENT_ENGINE) throw new Refused('ENGINE_VERSION', `verdict environments require engine ${LANDING_ENVIRONMENT_ENGINE}`);+ if (environment !== undefined && environment !== null && environmentProblem(environment)) throw new Refused('VERDICT_ENVIRONMENT', 'a verdict environment needs exact platform, arch and Node version');+}++/** An older engine cannot start or finish a batch around a durable test-defect hold. */+export function requireTrunk(board) {+ if (engine(board) < LANDING_ENVIRONMENT_ENGINE && board.db.prepare("SELECT 1 FROM event WHERE event_kind = 'landing-test-defect' LIMIT 1").get()) throw new Refused('ENGINE_VERSION', `this trunk has test-defect holds requiring engine ${LANDING_ENVIRONMENT_ENGINE}`);+}++/** Require the engine and exact executor identities before recording a batch. */+export function requireBatch(board, batch) {+ requireTrunk(board);+ if (carriesLandingEnvironment(batch) && engine(board) < LANDING_ENVIRONMENT_ENGINE) throw new Refused('ENGINE_VERSION', `landing environments and test defects require engine ${LANDING_ENVIRONMENT_ENGINE}`);+ if (batch?.environmentWarnings !== undefined && !Array.isArray(batch.environmentWarnings)) throw new Refused('LAND_BATCH', 'landing environment warnings are a list');+ const environments = [batch?.environment, ...(Array.isArray(batch?.gateResults) ? batch.gateResults : []).map(gate => gate?.environment),+ ...(batch?.environmentWarnings ?? []).flatMap(warning => [warning?.recorded, warning?.landing])];+ if (environments.some(environment => environment !== undefined && environment !== null && environmentProblem(environment))) throw new Refused('LAND_BATCH', 'a landing executor needs exact platform, arch and Node version');+}++/** An older replay cannot reinterpret an existing typed batch. */+export function requireStoredBatch(board, batch) {+ if (carriesLandingEnvironment(batch) && engine(board) < LANDING_ENVIRONMENT_ENGINE) throw new Refused('ENGINE_VERSION', `this batch requires engine ${LANDING_ENVIRONMENT_ENGINE}`);+}++/** Keep the executor and test-defect evidence across every batch revision. */+export function requireRevision(board, previous, batch) {+ requireStoredBatch(board, previous);+ if (previous && ['environment', 'testDefects'].some(key => Object.hasOwn(previous, key) && !Object.hasOwn(batch, key))) throw new Refused('LAND_BATCH', 'a landing revision keeps its recorded executor and test defects');+}diff --git a/src/landing-host.js b/src/landing-host.jsindex e9a8bf28..a41bfa92 100644--- a/src/landing-host.js+++ b/src/landing-host.js@@ -4,7 +4,11 @@ import { join } from 'node:path';import { repoInfo } from './git.js';import { mainPolicy } from './trusted-policy.js';import { loadMachineSettings } from './settings.js';-import { environmentLabel, executionEnvironment, sameEnvironment } from './execution-environment.js';+import {+ environmentLabel,+ executionEnvironment,+ sameEnvironment,+} from './execution-environment.js';import { Refused } from './refused.js';/** Check one machine's own choice; a board policy never opts another machine in. */diff --git a/src/landing-test-defects.js b/src/landing-test-defects.jsindex 26c205fe..fece3017 100644--- a/src/landing-test-defects.js+++ b/src/landing-test-defects.js@@ -1,5 +1,9 @@/** Durable test defects hold a trunk when bisection identifies no item culprit [E29]. */-import { addItem, atomic, logEvent } from './board.js';+import {+ addItem,+ atomic,+ logEvent,+} from './board.js';import { COORDINATOR } from './config.js';import { ENGINE_VERSION } from './machine.js';import { LANDING_ENVIRONMENT_ENGINE } from './landing-environment-engine.js';