Architectural Decision Records (ADRs) & Evolution Lineage Specification
This reference document specifies the directory topology, dual-format grammar (optional YAML frontmatter plus mandatory Markdown AST sections), lineage state machine (total supersession vs. non-destructive amendment), DAG acyclicity invariants, and registry contract for Architectural Decision Records (ADRs) in SpecOps (Research Area 4, governed by ADR-0001, ADR-0008, and ADR-0022).
1. Directory Topology & Lifecycle Folders
All Architectural Decision Records reside under docs/project/adrs/ and progress through two primary lifecycle stage directories alongside an authoritative registry index:
docs/project/adrs/
βββ REGISTRY.md # Pipe-delimited index of all ADRs
βββ proposed/ # Draft decisions under architectural evaluation
β βββ adr-XXXX-<slug>.md
βββ accepted/ # Active, ratified, or historical decisions
βββ adr-XXXX-<slug>.md
Path Resolution & Discovery
The ADR engines (ADRSupersessionEngine in src/spec_ops/adrs/supersession.py and ADRAmendmentEngine in src/spec_ops/adrs/amendment.py) resolve the ADR root directory in the following priority order:
docs/project/adrs/(canonical PMaC location)docs/adrs/(legacy fallback)adrs/(minimal repository fallback)
When resolving an individual ADR via find_adr_file(adrs_dir, target) (src/spec_ops/adrs/supersede.py):
- Direct file paths or paths relative to
adrs_dir,adrs_dir.parent, oradrs_dir.parent.parentare checked first. - Otherwise, the target string is normalized via
normalize_adr_id(target)and matched against.mdfilenames (adr-XXXXstem match), frontmatteridfields, or the first H1 heading line acrossdocs/project/adrs//.md(excludingREGISTRY.mdandREADME.md). - If no matching file exists,
ADRNotFoundError(FileNotFoundErrorsubclass) is raised.
Filename Convention & Canonical Identifier
- Filename Pattern:
adr-XXXX-(regex:.md ^adr-(\d{4})(?:-[a-z0-9-]+)?\.md$), whereXXXXis a zero-padded 4-digit sequential integer andis a lowercase, hyphen-separated alphanumeric slug generated byslugify(title). - Canonical Identifier:
ADR-XXXX(e.g.,ADR-0001,ADR-0022). - Identifier Normalization (
normalize_adr_id): Any input reference ("1","0001","adr-0001-slug.md", or"ADR-0001") is normalized toADR-XXXXviaf"ADR-{int(num):04d}". - Sequential ID Allocation (
find_next_adr_id): Scansdocs/project/adrs/*/.mdforadr-(\d+)stems, computesmax_num + 1, and formats the next available identifier asADR-{next_num:04d}.
| Folder / File | Lifecycle Role | Allowed Statuses |
|---|---|---|
docs/project/adrs/proposed/ |
Candidate architectural decisions awaiting review or empirical spike graduation (spec-ops spike graduate). |
Proposed |
docs/project/adrs/accepted/ |
Ratified architectural invariants governing bounded contexts, plus historical records that were later superseded or amended. | Accepted, Superseded |
docs/project/adrs/REGISTRY.md |
Central index mapping every ADR-XXXX to its title, current status, and ratification date. |
N/A (Index file) |
2. Dual-Format Grammar (Optional YAML Frontmatter + Markdown AST)
Unlike Backlog Tasks, User Stories, and PRDsβwhich strictly require --- YAML frontmatter blocksβADRs intentionally support a Dual-Format Grammar:
- Pure Markdown Format: Foundational or hand-authored ADRs (such as
ADR-0001throughADR-0021) omit YAML frontmatter and encode their identifier, title, and status directly in Markdown headings. - Hybrid YAML Frontmatter + Markdown Format: ADRs generated or mutated by CLI workflows (
spec-ops spike graduate,spec-ops adr supersede,spec-ops adr amend, orADR-0022) include a YAML frontmatter block above the Markdown body.
Schema Audit Exemption (`is_specification_file`)
In src/spec_ops/core/schema_validator.py, is_specification_file(path) applies special handling when "adrs" is in the path:
REGISTRY.mdandREADME.mdare explicitly ignored.- An ADR
.mdfile underdocs/project/adrs/is audited againstADRFrontmatterif and only if its content begins with---(txt.startswith("---")). - Pure Markdown ADRs without
---bypass YAML frontmatter validation while remaining first-class nodes inparse_adr(src/spec_ops/core/adr_parser.py).
`ADRFrontmatter` Schema (`schema_validator.py`)
When YAML frontmatter is present on an ADR, it is validated against the ADRFrontmatter Pydantic model (SCHEMA_VERSION = "v2.0"):
class ADRFrontmatter(BaseModel):
"""Pydantic schema model for ADR frontmatter when present."""
model_config = ConfigDict(extra="allow")
id: Any
title: str
status: str = "Accepted"
domain: Optional[str] = "Architecture"
supersedes: Optional[Any] = None
superseded_by: Optional[Any] = None
amends: Optional[Any] = None
amended_by: Optional[Any] = None
| Field | Type | Required | Default | Semantics | |
|---|---|---|---|---|---|
id |
Any (`str \ |
int`) | Yes (if frontmatter exists) | β | Canonical ID ("ADR-0022" or "0022"). Normalized to ADR-XXXX. |
title |
str |
Yes (if frontmatter exists) | β | Human-readable decision title without the # ADR-XXXX: prefix. |
|
status |
str |
No | "Accepted" |
Lifecycle state ("Proposed", "Accepted", "Superseded"). |
|
domain |
Optional[str] |
No | "Architecture" |
Architectural domain or bounded context classification. | |
supersedes |
Optional[Any] |
No | None |
Canonical ID of the predecessor ADR retired by this decision (e.g., "ADR-0003"). |
|
superseded_by |
Optional[Any] |
No | None |
Canonical ID of the newer ADR that replaced this decision (e.g., "ADR-0015"). |
|
amends |
Optional[Any] |
No | None |
List of target ADR IDs (list[str] or str) incrementally refined by this ADR. |
|
amended_by |
Optional[Any] |
No | None |
List of amending ADR IDs (list[str] or str) that refine this ADR. |
|
| (extra keys) | Any |
No | Allowed | extra="allow" permits metadata such as date: YYYY-MM-DD or spike_id: SPIKE-XXXX. |
Reconciliation Between Frontmatter and Markdown (`parse_adr`)
parse_adr(file_path) in src/spec_ops/core/adr_parser.py constructs the ADR domain model (src/spec_ops/core/models.py) by reconciling YAML keys with Markdown regex extraction:
idResolution: Extractsadr-(\d+)fromfile_path.stemfirst (f"ADR-{num.zfill(4)}"), falling back tometa.get("id", file_path.stem.upper()). Note thatparse_adr_infoinsupersede.pyalso overrides withnormalize_adr_id(str(meta["id"]))whenmeta["id"]is present.titleResolution: Usesmeta.get("title")if non-empty; otherwise inspects the first non-empty line of the Markdown body and strips the H1 prefix viare.sub(r"^#\s(ADR-\d+:\s)?", "", title_line).strip().status&domain: Defaults tometa.get("status", "Accepted")andmeta.get("domain", "Architecture").- Lineage Lists (
amends,amended_by): Coerces scalar strings or YAML lists into uppercaselist[str](e.g.,["ADR-0002"]), whilesupersedesandsuperseded_byare normalized as strings.
Domain Model Representation (`ADR` Dataclass)
Parsed ADRs are materialized as ADR instances (src/spec_ops/core/models.py) with the following attributes:
id: strβ Canonical ID (ADR-XXXX).title: strβ Clean human-readable title.status: strβ Current status (Proposed,Accepted,Superseded).domain: strβ Architectural domain (default"Architecture").context: strβ Extracted body of## Context.decision: strβ Extracted body of## Decision.consequences: strβ Extracted body of## Consequences.raw_markdown: strβ Complete unparsed file content.file_path: Path | Noneβ Resolved filesystem location.supersedes: str/superseded_by: strβ Total replacement pointers.amends: list[str]/amended_by: list[str]β Non-destructive amendment pointers.
3. Mandatory Markdown Body AST Sections
Every ADR document must contain an H1 header followed by four canonical H2 sections (## Status, ## Context, ## Decision, ## Consequences).
Canonical Examples: Pure Markdown vs. Hybrid YAML+Markdown
Example A β Pure Markdown ADR (docs/project/adrs/accepted/adr-0001-specification-as-code-architecture.md):
# ADR-0001: Specification as Code and Opinionated SDLC Guardrails
## Status
Accepted
## Context
Traditional agile tooling isolates user stories and backlog items in external web silos, leading to specification drift, context blindness for coding agents, and merge conflicts across parallel streams.
## Decision
We adopt **Project Management as Code**:
1. All project specifications (Personas, PRDs, User Stories, ADRs, Backlog Tasks) live inside `docs/project/` as Markdown documents with YAML frontmatter.
2. Specifications branch, review, and merge directly alongside production code.
3. Automated tools parse documentation into machine-readable relational graphs, ensuring zero specification drift.
## Consequences
- **Positive**: Full version-locking of requirements and code; conflict-free parallel worker execution; living interactive visualizer directly from git history.
- **Negative**: Requires discipline to maintain frontmatter metadata and lean JIT buffers.
Example B β Hybrid YAML Frontmatter + Markdown ADR (with Amendment Lineage):
---
id: ADR-0022
title: Declarative Markdown and YAML Specification Grammar and Document Metamodel
status: Accepted
domain: Architecture
date: 2026-10-15
amends:
- ADR-0001
---
# ADR-0022: Declarative Markdown and YAML Specification Grammar and Document Metamodel
## Status
Accepted (amends [`ADR-0001`](file://adr-0001.md))
## Context
Exploratory architectural spike `SPIKE-0259` investigated the hypothesis...
## Decision
We adopt a formal **Declarative Markdown+YAML Specification Grammar & Metamodel**...
## Consequences
- **Positive**: Unifies frontmatter validation, markdown section linting, and directory topology rules.
- **Negative**: Requires keeping declarative grammar rules synchronized with reference documentation.
Section Grammar Rules
| Section Heading | Extraction Regex (adr_parser.py / supersede.py) |
Content Contract | ||
|---|---|---|---|---|
# ADR-XXXX: |
^#\s(ADR-\d+:\s)?(?P |
Top-level H1 heading declaring the canonical ADR ID and decision title. | ||
## Status |
## Status\s*\n([^\n]+) |
Declares current lifecycle state: Proposed, Accepted, Superseded (by ADR-YYYY), Superseded by ADR-YYYY, or Accepted (amends ADR-XXXX). |
||
## Context |
`## Context\s\n(.?)(?=\n##\ | \Z) (re.DOTALL`) |
Problem forces, constraints, technical debt, or empirical benchmark findings graduated via `spec-ops spike graduate |
disproven`. |
## Decision |
`## Decision\s\n(.?)(?=\n##\ | \Z) (re.DOTALL`) |
Normative, verifiable architectural rules and bounded context invariants ("We adopt...", numbered imperatives). | |
## Consequences |
`## Consequences\s\n(.?)(?=\n##\ | \Z) (re.DOTALL`) |
Explicit trade-off analysis detailing Positive benefits and Negative costs or operational obligations. |
4. Decision Evolution & Lineage State Machine
Architectural decisions evolve over time through two distinct mechanisms: Total Replacement (supersede) and Non-Destructive Refinement (amend).
stateDiagram-v2
[*] --> Proposed : Author in proposed/ or Spike Graduate
Proposed --> Accepted : Ratify & Move to accepted/
Accepted --> Accepted : spec-ops adr amend (amends / amended_by)
Accepted --> Superseded : spec-ops adr supersede (supersedes / superseded_by)
Superseded --> [*]
4.1 Total Replacement: `spec-ops adr supersede`
Implemented in src/spec_ops/adrs/supersede.py and src/spec_ops/adrs/supersession.py (ADRSupersessionEngine.supersede), supersession retires an obsolete decision in favor of a replacement ADR:
- Cycle Detection (
detect_supersession_cycles):
- Discovers existing supersession edges across
REGISTRY.md, YAML frontmatter (superseded_by), and Markdown body patterns (r"Superseded\s+by\s+(?:\[?)?(ADR-\d+)"`). - Flattens transitive chains (
A -> B -> CresolvesA -> C) and verifies that adding(old_id -> new_id)does not introduce a self-loop (old_id == new_id) or cycle (CircularSupersessionError).
- Predecessor ADR Mutation (
old_file):
- Sets YAML frontmatter
status: Supersededandsuperseded_by: ADR-YYYY. - Rewrites the Markdown
## Statusline toSuperseded (by ADR-YYYY).
- Successor ADR Mutation (
new_file):
- Scaffolds a new ADR in
docs/project/adrs/accepted/(if--titleis provided) or moves an existing proposed ADR intoaccepted/. - Sets YAML frontmatter
status: Acceptedandsupersedes: ADR-XXXX.
- Registry Synchronization (
update_registry_supersession):
- Updates
old_idstatus column indocs/project/adrs/REGISTRY.mdtoSuperseded (by ADR-YYYY)and ensuresnew_idis listed asAccepted.
- Downstream Backlog Impact (
find_tasks_citing_adr&ArchitecturalReconciler):
- Scans
docs/project/backlog/{refined,proposed}/*.mdfor tasks citingold_idingoverning_adrsor body text, emitting warnings:"Task TASK-XXXX cites superseded ADR-XXXX; requires architectural re-refinement". - When
ArchitecturalReconciler.reconcile_task(src/spec_ops/backlog/reconciler.py) runs, it automatically replaces superseded ADR references ingoverning_adrsand task body text with the transitive active successor (change_type="superseded_adr").
4.2 Non-Destructive Refinement: `spec-ops adr amend`
Implemented in src/spec_ops/adrs/amend.py and src/spec_ops/adrs/amendment.py (ADRAmendmentEngine.amend), amendment layers incremental refinements onto a foundational decision without retiring the predecessor:
- DAG Acyclicity & Cycle Detection (
detect_amendment_cycles):
discover_amended_adrsbuilds the directed graph{amending_id: [target_ids]}fromamendsfrontmatter, reverseamended_byfrontmatter, and Markdown body matches (r"amends\s+(?:\[?)?(ADR-\d+)"`).- Runs Depth-First Search (DFS) with a recursion stack (
stack) before modifying any files. Self-amendment (ADR-X -> ADR-X) or multi-hop cycles (ADR-A -> ADR-B -> ADR-A) raiseCircularAmendmentError.
- Bidirectional Frontmatter Linking:
- Predecessor ADR (
old_file): Preservesstatus: Acceptedand appendsnew_idtoamended_by: [ADR-YYYY]. - Amending ADR (
new_file): Placed indocs/project/adrs/accepted/withstatus: Acceptedand appendsold_idtoamends: [ADR-XXXX].
- Registry Synchronization (
update_registry_amendment):
- Keeps the predecessor ADR's status as
AcceptedinREGISTRY.mdwhile adding or updating the amending ADR row asAccepted.
- Downstream Hydration & DoR Gate Integration:
- DoR Gate (
src/spec_ops/backlog/dor_gate.py): Tasks citing an accepted base ADR passRULE_GOVERNING_ADRS; ifamended_byis non-empty,audit_task_healthappends an informational recommendation:"ADR ADR-XXXX has active amendments [ADR-YYYY]." - Reconciler (
src/spec_ops/backlog/reconciler.py): Emits a non-destructiveactive_amendment_notice(modified=False) so the base ADR citation remains intact. - Worker Contract Hydration (
src/spec_ops/worker/claimer.py):hydrate_task_promptcallsdiscover_amendments_by_target(adrs_dir)and injects both inline annotations (ADR-0002 (active amendments: ADR-0025)) and a dedicated- Active ADR Amendments:bullet into.task-prompt.mdso autonomous workers enforce both the foundational invariant and its amending deltas.
Comparison: Supersession vs. Amendment
| Dimension | Supersession (spec-ops adr supersede) |
Amendment (spec-ops adr amend) |
|---|---|---|
Predecessor status |
Transitions to Superseded |
Remains Accepted |
| Predecessor Frontmatter | superseded_by: ADR-YYYY (scalar) |
amended_by: [ADR-YYYY, ...] (list) |
| Successor Frontmatter | supersedes: ADR-XXXX (scalar) |
amends: [ADR-XXXX, ...] (list) |
REGISTRY.md Old Row |
Superseded (by ADR-YYYY) |
Accepted |
| Cycle Exception | CircularSupersessionError |
CircularAmendmentError |
DoR Gate (dor_gate.py) |
Fails if task only cites Superseded ADR |
Passes; emits amendment recommendation |
| Task Reconciler | Rewrites old_id -> new_id (modified=True) |
Preserves old_id; logs active_amendment_notice |
Worker .task-prompt.md |
Cites replacement ADR | Hydrates base ADR + Active ADR Amendments delta |
5. ADR Registry Specification (`docs/project/adrs/REGISTRY.md`)
docs/project/adrs/REGISTRY.md is the human- and machine-readable table indexing all Architectural Decision Records.
Format & Row Grammar
The file begins with # ADR Registry followed by a 4-column Markdown pipe table:
# ADR Registry
| ID | Title | Status | Date |
|---|---|---|---|
| ADR-0001 | Specification as Code and Opinionated SDLC Guardrails | Accepted | 2026-09-29 |
| ADR-0003 | Blackbox Frontdoor Verification and Zero Backdoor Testing | Superseded (by ADR-0015) | 2026-09-29 |
| ADR-0022 | Declarative Markdown and YAML Specification Grammar and Document Metamodel | Accepted | 2026-10-15 |
- Row Parsing Regex:
r"^\|\s([^|]+?)\s\|\s([^|]+?)\s\|\s([^|]+?)\s\|\s([^|]+?)\s\|$" - Columns:
ID: Canonical zero-padded identifier (ADR-XXXX).Title: Concise decision title matching the ADR's H1 / frontmattertitle.Status:Proposed,Accepted, orSuperseded (by ADR-YYYY).Date: ISO-8601 date (YYYY-MM-DD) when the decision was recorded or ratified.
- Schema Validator Exemption:
REGISTRY.mdis listed inignored_nameswithinis_specification_file()(src/spec_ops/core/schema_validator.py) so it is never flagged for lacking YAML frontmatter. - Automated Maintenance: Both
update_registry_supersession(src/spec_ops/adrs/supersede.py) andupdate_registry_amendment(src/spec_ops/adrs/amend.py) parse each pipe-delimited row in place, updating existing ADR rows or appending newly scaffolded ADR entries at the bottom of the table withdate.today().isoformat().