ADR-0018 — Use SpecTree Specification-First Ingestion for the Documentation Pipeline¶
Status¶
Accepted
Context¶
The pipeline's traceability chain currently starts at artefacts that already exist: MoSCoW tables, ADR front-matter, Rego metadocs, .NET policy IDs. Everything upstream of those — the stakeholder requests, functional requirements, API contracts, test matrices that motivated the work — lives only in human prose that no gate can read.
The SpecTree specification-first format family (SRS, AI, Test, API, Model, NS, ADR, and Solution-Manifest grammars) closes that gap: specifications are written in a small line-based EBNF grammar, so they are reviewable as text and machine-parseable. The missing piece in this repository is the ingestion layer: deterministic parsers that turn those specifications into JSON ASTs the pipeline can validate and render.
Two properties are non-negotiable, mirroring the rest of the estate:
- Determinism — parsing the same tree twice must produce byte-identical output (the architecture catalog, ADR-0012, already holds this bar).
- No silent degradation — an unparseable specification must fail loudly with file, line, and expected/actual tokens.
Decision¶
Adopt SpecTree as the specification-first input layer, ingested by one
deterministic, stdlib-only Python CLI, scripts/spectree-parse.py:
-
Grammar provenance — the eight grammar files are vendored under
spectree/grammars/, pinned to Minotaur-Grammars commitde45cd55169d. The grammars are documentation of the accepted syntax; the parser is line-based and does not read them at runtime (no runtime dependency on the external repository). -
Parser surface — the CLI parses all eight grammars (
SrsSpec,AiSpec,TestSpec,ApiSpec,ModelSpec,NsSpec,AdrSpec,SolutionManifest), each into a typed AST document. A--selftestmode runs the full negative/positive fixture suite (120 checks);--allparses every spec underspectree/specs/;--specparses a single file. Unknown extensions and malformed lines fail with file:line diagnostics and a non-zero exit. -
AST contract — every output is a versioned envelope:
{schema: "spectree-ast", schemaVersion: 1, astType, source: {path, grammar, grammarCommit}, ast}. The contract is committed as a JSON Schema (2020-12) atspectree/schemas/spectree-ast-v1.schema.json, and the CLI embeds a minimal validator that checks every emitted AST against it before writing — an AST that cannot be validated is never produced. -
Output territory — ASTs are written to
docs/generated/spectree/<name>.ast.jsonand are git-ignored (like alldocs/generated/artefacts they are rebuild outputs, not sources); the committed schema is the durable contract. Sample specifications mirroring the real MyApp solution live underspectree/specs/and serve as the pipeline's living fixtures. -
Pipeline wiring —
scripts/generate-docs.sh(Step 5) runs--selftestthen--allso a broken parser or specification fails the docs build; the CIdocs-buildjob runs the same step.
Consequences¶
Positive¶
- Specifications become first-class pipeline inputs: the traceability chain can now start at requirements-level text, not at rendered artefacts.
- Byte-identical ASTs across runs (verified by md5 across repeated runs) — the same bar the architecture catalog holds.
- Stdlib-only Python: no runtime dependencies to pin, no network access at parse time, runnable in the existing CI image.
- The
AdrSpecformat gives ADRs a machine-parseable twin, and theSolutionManifestformat binds projects to the specs and generators that consume them — the composition layer for later issues. - Negative fixtures in
--selftestkeep the error paths as tested as the happy path.
Negative / Trade-offs¶
- Eight grammars vendored is eight surfaces to re-pin when
Minotaur-Grammars evolves; the pinned commit is recorded in each AST's
source.grammarCommit, so provenance is always visible. - A line-based EBNF cannot express every specification style; complex prose stays in companion Markdown documents.
- The embedded JSON-Schema validator is a minimal subset (type, required,
properties, enum, oneOf,
$defs, arrays) — deliberate, to stay stdlib-only; exotic schema keywords would require a fulljsonschemadependency.
Alternatives Considered¶
| Alternative | Pros | Cons / Rejected Because |
|---|---|---|
| Parse specs with a general grammar tool (ANTLR/lark) | Full EBNF fidelity | Non-stdlib runtime dependency; grammar-tool version pinning; overkill for line-based grammars |
| Hand-write one parser per grammar as separate CLIs | Smaller units | Eight entry points, eight behaviours to keep consistent; one CLI keeps the envelope contract uniform |
| YAML/JSON specs instead of SpecTree grammars | Off-the-shelf parsing | Loses the human-reviewable line format and the SpecTree cross-repo standard |
| Generate ASTs at build time only, no committed schema | Less to maintain | No durable contract for downstream consumers; AST shape could drift silently between runs |
Related¶
- ADR-0003 — MkDocs for Publishing
- ADR-0012 — Machine-Readable ADR Traceability Kit
- MoSCoW requirements: S-006, M-005
- Grammar source: https://github.com/DevelApp-ai/Minotaur-Grammars (commit
de45cd55169d)