How-To: Adopt Brownfield Codebases and Manage Grandfathered Debt
This guide explains how to adopt SpecOps into an existing brownfield codebase without immediate file limit disruptions, and how to incrementally extract architectural seams.
Adopting an Existing Codebase
To bootstrap SpecOps into an existing repository with baseline architectural profiles:
spec-ops adopt --name "ExistingSystem" --profile core,bdd,ddd
By default, spec-ops adopt enables --grandfather-debt, which snapshots all existing files that exceed the 500-line file limit (ADR-0002) into .specops/grandfathered_debt.json and records them under [invariants.file_limits] in specops.toml. This ensures existing large files do not cause preflight or CI failures, while preventing those files from growing any larger.
To adopt without debt baselining:
spec-ops adopt --no-grandfather-debt
How Grandfathered Debt Works
When --grandfather-debt is active:
- Files already over 500 lines are recorded in
.specops/grandfathered_debt.jsonwith their exact line counts at adoption time. - In subsequent health checks (
spec-ops health), grandfathered files are reported as tracked debt: ``text âšī¸ 3 grandfathered files remain tracked debt items.`` - Ratchet Principle: If a grandfathered file expands beyond its recorded baseline,
spec-ops healthtriggers an expanded debt violation: ``text File Length Violation: src/legacy_monolith.py (620 lines > 580 line limit) src/legacy_monolith.py: 620 lines (expanded beyond recorded baseline 580 lines)`` - New files are always subject to the unexempt 500-line hard invariant limit.
Verifying Bounded Context Architecture
SpecOps inspects module dependencies and directory boundaries to enforce clean bounded context architecture:
spec-ops health --architecture
This verifies:
- Bounded Context Isolation: Code in domain contexts does not take unauthorized direct dependencies across isolated layers.
- Deterministic Dependency DAG: Dependency relationships between packages and modules form an acyclic directed graph with zero cyclic dependency traps.
Analyzing AST Seams and Generating Refactor Tasks
To analyze candidate extraction points in a large or monolithic file using Abstract Syntax Tree (AST) seam parsing:
spec-ops decompose src/spec_ops/core/parser.py
This parses top-level classes and functions, computes line boundaries and fan-out, and recommends cohesive module extraction seams.
To automatically inspect all files approaching or exceeding limits and suggest decomposition splits:
spec-ops health --suggest-splits
To automatically scaffold discrete refactoring tasks in docs/project/backlog/proposed/ based on AST seam extraction:
spec-ops health --suggest-splits --emit-task
Pre-Existing Documentation Bridging and Workflow Deconfliction
Brownfield repositories often have established documentation systems (such as MkDocs or Sphinx) and active GitHub Actions deployment workflows.
When running spec-ops adopt, SpecOps automatically inspects the repository for pre-existing doc frameworks and GitHub Pages deployment workflows:
spec-ops adopt --github-pages --deconflict-workflow --bridge-docs
- Conflict Detection & Deconfliction (
--deconflict-workflow): If existing workflows target thepagesconcurrency group orgithub-pagesenvironment, SpecOps prompts or automatically deconflicts them (e.g. archiving or renaming the legacy deploy trigger) so that competing workflows do not overwrite each other. - Documentation Bridging (
--bridge-docs): Generates navigation bridge stubs or links allowing legacy docs to seamlessly link directly to{base_url}visualizer/for interactive PMaC graph exploration.
Self-Contained GitHub Pages Scaffolding
To publish Diataxis documentation and the living 2D visualizer without declaring SpecOps as a runtime dependency in the target repository's lockfile (uv.lock or pyproject.toml), pass --github-pages:
spec-ops adopt --github-pages
This generates .github/workflows/spec-ops-pages.yml configured to execute via isolated tool runner:
- name: Build Diataxis Documentation & Visualizer
run: uv tool run --from git+https://github.com/tyevans/spec-ops.git spec-ops docs build --include-visualizer
This ensures zero dependency contamination in clean CI environments while deploying the full static site and interactive graph visualizer.
Automated Security Sentinel & Pre-Commit Hook Installation
SpecOps adoption automatically sets up repository supply-chain safeguards:
- Pre-Commit Hook:
spec-ops adoptscaffolds.git/hooks/pre-committo prevent unauthorized lockfile drift (spec-ops security sentinel) and block accidental credential leakage before commits land. - Lockfile Immutability: Enforces that autonomous agents and human developers do not mutate lockfiles without authorized architectural intent.
Brownfield Commit Provenance Baselining & Rev-Range Auditing
Existing repositories have long commit histories that precede SpecOps and lack RFC-822 specification trailers (SpecOps-Task: TASK-XXXX).
During adoption:
spec-ops adoptrecords the current HEAD commit inspecops.toml: ``toml [audit.provenance] baseline_commit = "adae3d7..."``- Subsequent provenance audits (
spec-ops audit provenance) automatically start frombaseline_commit, preventing grandfathered commits from failing compliance checks. - To audit a specific revision range manually: ``
bash spec-ops audit provenance --since origin/main``