Skip to content
🛡

The twelve-layer system

Twelve composable guardrails — hooks, MCP servers, subagents, and supervisors — that bound what an AI agent can do to your .NET production code.

The twelve-layer system is what we install during Sprint Zero. Each layer is a separate piece of plumbing — a hook, an MCP tool method, a subagent, or a supervisor — and the value is in how they compose.

Most teams running AI coding agents have zero to two of these layers — usually a CLAUDE.md and a CI pipeline. That is not a criticism; it is the maturity curve. Six of the layers below are established practice you will find across the industry. The other six are Code Majesty terms: mechanisms we built because nothing public existed when we needed them.

The closest first-party analogue is GitHub Copilot’s modernize-dotnet workflow — assess → plan → execute. It structures the plan. The twelve layers cover the same ground and then keep going: they also police the execution.

The layers

1. Investigation-gate hook — our contribution

A PreToolUse hook that blocks any edit or command referencing a symbol the agent has not read into context. No edit without evidence: the agent must open the file before it may change the call. Confabulated APIs die here — before the compiler or a reviewer ever sees them. Full definition →

2. Code-extracted pattern snapshots — established practice

A generated, agent-readable catalogue of the conventions actually present in your repo — naming, folder layout, modifier discipline — read by every implementing subagent before it writes code. The output reads as if your team wrote it, because the conventions came from your team’s code. Full definition →

3. Bayesian build-outcome confidence — our contribution

Every plan step carries a live probability of success, updated from observed build and test outcomes. High confidence proceeds; middling confidence batches steps so one build verdict covers them; low confidence pauses for review before the tokens are spent. Full definition →

4. AUTO-TABLE inventories — our contribution

A per-PR-rebuilt table of entities × layers × invariants × tests × last-touched. Every session opens against the same architectural snapshot of the codebase, and the table’s diff doubles as the PR’s architectural diff — audit evidence as a side effect of normal work. Full definition →

5. Hybrid BM25 + embedding search — established practice

One MCP search tool backed by lexical BM25 and dense vectors, merged by reciprocal-rank fusion. Identifier-grade lookups and concept-grade questions both land — the agent doesn’t need to know which kind of query it is asking. Full definition →

6. Roslyn .NET MCP server — established practice

Compiler truth exposed as agent tools: symbol resolution, reference finding, type lookups. The agent edits what the symbol is, not what it looks like in text — overloads, interface implementations, and renames included. Full definition →

7. Subagents with model tiering — established practice

Haiku for searches, Sonnet for implementation, Opus for planning. Token budget goes where reasoning actually pays off, and per-PR cost becomes a function of plan size rather than session length. Full definition →

8. Runtime supervisors — established practice

A long-running monitor beside the session — watching token budget, oscillation hashes, and plan drift — with the authority to stop the session and escalate to a human. Hooks report; the supervisor decides. Full definition →

9. Oscillation detector hook — our contribution

Transition-hash detection that catches edit-thrashing — the agent flipping the same lines back and forth — and blocks the reversing edit before it lands, with a diagnostic that points the agent at the underlying contradiction. Full definition →

10. Code-existence inline annotations — our contribution

Every symbol reference in a plan is marked [VERIFIED], [ASSUMED], or [MISSING], with evidence attached. Unverified references cannot execute — confabulation becomes a mechanically checkable error instead of a code-review surprise. Full definition →

11. Spec-driven CLAUDE.md — established practice

The repository’s operating manual for agents: conventions, boundaries, commands, and the definition of done — written as spec, not prose, and versioned with the code it governs. Every session starts from the same contract.

12. PostToolUse build gate — our contribution

dotnet build and scoped dotnet test after every multi-file edit, with a trimmed failure report fed straight back into the agent’s context. Broken intermediate states never accumulate past a single step. Full definition →

How they compose

No single layer is the moat — the composition is. The annotation layer (10) feeds the investigation gate (1); the build gate (12) feeds Bayesian confidence (3); the oscillation detector (9) reports to the supervisor (8); and AUTO-TABLE (4) plus pattern snapshots (2) give every fresh session the context all the others assume. Remove one layer and its neighbors weaken. Install all twelve and the system fails safe by default.

Want to see it against your own codebase? Book a one-hour walkthrough of the twelve-layer setup — $80, no engagement required.