Skip to content

The Drift Log · Governing agents that write code

Enforcing Pre‑Commit Invariant Checks on Agent Proposals

16 November 2026 · 3 min read · 600 words · established

A crystal shard held at a red-lit gateway in a black wall

A pre‑commit hook validates licensing, provenance, and runtime invariants before any agent‑generated write is persisted.

The hidden risk of unchecked agent writes

When an autonomous coding agent decides to modify a repository, the change lands directly in the main branch unless a gate intervenes. In practice most teams rely on human code review after the fact. The window between the agent’s intent and the commit is therefore unprotected. A mis‑configured licence, a missing provenance tag, or an inadvertent runtime I/O call can slip through, polluting the codebase and forcing a costly rollback. The failure mode is clear: the repository becomes a sink for unvetted artefacts, and the team loses confidence in the agent’s output.

A pre‑commit invariant hook

The remedy is to place a pre‑commit hook that validates the build intent before any write is persisted. The hook runs in the same environment that the agent uses to propose a change, so it can inspect the proposal’s metadata and the diff itself. Three checks are essential:

  • Licensing compliance – the hook extracts the licence identifier from the proposal’s header and compares it against an allow‑list defined by the organisation. If the licence is absent or disallowed, the hook aborts the write.
  • Provenance verification – every proposal must carry a signed provenance token. The hook validates the signature against the root‑of‑trust public key, ensuring the change originates from an authorised agent.
  • Runtime invariant enforcement – the hook parses the diff for new imports or system calls. Any addition that introduces undeclared I/O (e.g. fs.readFileSync in a library meant to be pure) triggers a failure.

A minimal Node‑based hook looks like this:

// pre-commit.js
const fs = require('fs');
const { verifyToken } = require('./provenance');
const allowedLicences = new Set(['MIT', 'Apache-2.0']);

function abort(msg) {
  console.error(`Pre‑commit invariant failed: ${msg}`);
  process.exit(1);
}

// 1. licence check
const licence = fs.readFileSync('PROPOSAL_LICENSE', 'utf8').trim();
if (!allowedLicences.has(licence)) abort(`Licence ${licence} not permitted`);

// 2. provenance check
const token = fs.readFileSync('PROPOSAL_TOKEN', 'utf8');
if (!verifyToken(token)) abort('Invalid provenance token');

// 3. runtime invariant check
const diff = fs.readFileSync('PROPOSAL_DIFF', 'utf8');
if (/fs\.\w+|process\.\w+/.test(diff)) abort('Undeclared runtime I/O detected');

The script is invoked by the version‑control system’s pre‑commit hook mechanism. If any check fails, the agent receives a rejection before any file is written.

Zero‑cost preview: why it matters

The hook runs in a preview mode that costs nothing beyond the compute already allocated to the agent. The preview stage registers the build intent, resolves invariants and licensing, and returns a terminal state. Because the preview does not persist any artefact, the repository remains unchanged until the gate explicitly grants entitlement. This design eliminates the “write‑then‑revert” cycle that plagues naïve pipelines.

From an operational perspective, the preview stage is a pure read‑only operation. It can be executed on the same CI runner that the agent uses, or on a dedicated sandbox that mirrors the target environment. The result is a binary verdict – CERTIFIED, PROVISIONAL, INCONCLUSIVE or FAILED – mirroring the certification harness used later in the deployment pipeline. The agent can act on the verdict immediately, either proceeding to the full write or adjusting its proposal.

How SHPBL implements the gate

SHPBL provides the same invariant‑checking logic as a built‑in Build Intent gate. Every write an agent proposes passes through this gate, where licensing, provenance and runtime invariants are validated before any artefact is persisted. The gate is exposed through the MCP server, the HTTP API and the typed TypeScript client, all sharing the same meter and policy set. For a concrete example see the Validating Licensing and Invariants at the Build Intent Gate support post. The implementation is model‑independent and repeatable; released archives are sealed by published checksums. Learn more at the root of trust and try a free repository evaluation at /evaluation.

Next steps for Monday

  1. Add the pre-commit.js script to your repository’s .git/hooks/pre-commit.
  2. Populate the allow‑list of licences and the public key for provenance verification.
  3. Run a dry‑run of an agent‑generated proposal and confirm the hook returns a terminal state.

With the hook in place, any agent‑initiated write will be vetted before it reaches the codebase, restoring confidence in automated contributions.

This post supports the longer argument in Placing an Invariant Gate in Front of Coding Agents.

Keep reading

Next in the log

The Strategic Master Library · written and reviewed under the house's own epistemic rules: nothing claimed that we cannot show.