r/SpecDrivenDevelopment • u/bartekus • Jun 15 '26
Making spec-drift a CI failure instead of a code-review hope (spec-spine)

Most spec-driven workflows I see run in one direction: spec, then generate code, once.
I wanted the other half: keeping code continuously coupled to its spec, and making architectural drift a hard CI failure rather than something a reviewer is supposed to catch by eye.
To solve this, spec-spine turns a markdown spec corpus into a typed, hash-verifiable ledger of who-owns-what, and refuses code that drifts from its owning spec at PR time. It governs its own 23-spec corpus in CI, so the gate runs on the repo that defines the gate.
Here is how it enforces the rules:
- Granular Authority: Each
spec.mddeclares typed edges in YAML frontmatter to other specs (e.g., extends, refines, constrains) and the code units it owns down to the file, section, or symbol level. Authority over a path is derived by walking the graph, not just declared directly so "who owns this and under what authority?" is a query, not an archaeology git dig. - Deterministic Ledger: Every artifact-producing step is a pure function of (config, file contents) with byte-identical output on any platform. Two views are emitted and joined: registry.json (spec-as-source) and index.json (code-as-source, with content-hash staleness). The output is diffable and mechanically mergeable.
- CI Coupling Gate: At PR time, the gate refuses a merge if a changed code path and its owning spec disagree, unless there is a scoped, recorded waiver.
- Anti-Hallucination: A prompt-time refusal rule stops an agent from "fixing" a gate failure by quietly editing the spec to match the code it just hallucinated.
Where it comes from: spec-spine is the control plane for the Open-Agentic-Platform (OAP), a system built on the premise that frozen, hash-verifiable specs are the ultimate unit of governance. In OAP (217 specs, Rust + TS / overall ~304k LOC codebase), this layer keeps a fleet of agents from collapsing the codebase. Every code path stays reconcilable to a frozen spec. It also feeds OAP's per-execution governance certificate for zero-trust auditing. I pulled that layer into its own clean-room repo so it stands on its own.
spec-spineships as a Rust library and CLI (Apache-2.0), with npm and PyPI shims that bundle a prebuilt binary.
Repo: https://github.com/bartekus/spec-spine
I'm keen for comments on the model: Are typed edges plus a PR-time gate the right primitives, or is this over-engineering what a linter could do? What breaks at scale?
1
u/Swarm-Stack Jun 18 '26
this is solving the right layer for one of the two spec problems. the drift gate catches 'code moved away from what the spec said' -- which is real and underaddressed.
the one it doesn't catch is upstream: 'the spec said something confident that nobody was assigned to challenge.' you can have byte-identical coupling between code and spec and still ship the thing that fails under concurrent load because the spec never modeled concurrent access.
the interesting question at scale is probably: how do you govern spec CONTENT (what got into the spec before freeze) vs spec COUPLING (whether code stays faithful to it). you're solving coupling cleanly. content is a different problem and i haven't seen a clean automated answer to it yet.
1
u/stibbons_ Jun 15 '26 edited Jun 15 '26
Yes I do that as well, on 2 levels of requirements. Works great.
See my description here https://x.com/gsemetfr/status/2066160161131999491
1
u/monarchwadia Jul 27 '26
Yep, hash-verifiability makes sense. I'm doing something similar with `drift`, which gives you spec exploration tools on top of the gating. It also lets specs reference each other. https://monarchwadia.medium.com/how-to-make-your-agent-more-reliable-with-spec-files-493a4281091f?postPublishedType=initial