Extract and Trace Commands for Code-to-Spec Traceability #739
steveardis
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal: Extract and Trace Commands for Code-to-Spec Traceability
Problem
OpenSpec’s workflow starts with specs and produces code. But there are many situations where the code already exists and the specs don’t:
Today, the only path into OpenSpec for existing code is to hand-write specs from scratch. There’s no tooling to derive specs from code, and no mechanism to verify that every line is accounted for.
Proposal
Add two new commands: extract and trace.
Extract (
/opsx:extract,openspec extract)Analyzes an entire repository and produces OpenSpec specifications.
openspec/specs/<domain>/spec.mdfiles in standard OpenSpec formatTrace (
/opsx:trace,openspec trace)Maps code to existing specs and identifies gaps. Produces a traceability map linking every qualifying line of production code to one or more specs.
openspec/specs/<domain>/traces/<target>.yamlwith mappings and an unmapped sectionWhat gets mapped
[start, end]inclusive — multiple ranges per file, multiple specs per rangeWhat is excluded
The constraint
The trace map must balance to zero per target. Every qualifying line is either mapped to a spec or listed in the unmapped section. No gray area.
Trace file structure
Each implementation target gets its own file, enabling multi-target traceability:
This structure supports:
The extract/trace loop
Integration with existing workflow
Minimal changes to existing commands:
/opsx:applyopenspec validate/opsx:archive— after merging delta specs (existing behavior), if trace files exist, archive calls trace as a final step. If unmapped lines are found, archive warns and recommends running/opsx:extractfollowed by/opsx:traceto close gaps. Archive does not fail on unmapped lines.The presence of trace files is the opt-in. No configuration flags. If trace files exist, the workflow maintains them. If they don’t, everything works exactly as it does today.
Use cases
Understand what you have
Run extract on any repo to produce specs that describe what the code actually does. Useful for onboarding, knowledge transfer, or simply getting a clear picture of a system you’re responsible for.
Prove coverage
Run trace against specs to verify every line of production code ties back to a documented behavior. Useful for compliance (SOC-2, ISO, regulatory), internal audits, or teams that want a hard guarantee their specs and code stay in sync.
Catch drift
When code is committed outside the OpenSpec workflow, trace surfaces it as unmapped lines. The archive step warns automatically when trace files are present. No silent divergence between specs and code.
Modernize with confidence
Use multiple targets against the same spec set. The legacy target traces the old codebase; the modernized target traces the new one. Diff them to see what’s been ported and what hasn’t. Decommission the old target by deleting its trace file.
Retroactive adoption
A team already has a working codebase and wants to bring it under OpenSpec. Extract produces the initial specs, trace verifies coverage, and the normal workflow takes over from there. No need to rewrite anything — just formalize what already exists.
Adoption on-ramp
Extract and trace can be adopted independently:
Scope of changes
openspec extractopenspec trace/opsx:extract,/opsx:traceopenspec/specs/<domain>/traces/openspec archivecalls trace when trace files are presentBeta Was this translation helpful? Give feedback.
All reactions