An open-source, CI-friendly reimplementation of the Spectra
spec-driven development CLI — reverse-engineered from the closed-source binary,
starting with the drift command.
Status: The Rust CLI ships 26 subcommands —
init,drift,analyze,search,completion,schemas,schema,templates,status,instructions,validate,list,show,decisions,demo,park,unpark,in-progress,new(change,artifact),task(start,done),trace(migrate),update,archive,scope,impl, andconfig— covering the full SDD workflow. It runs on Linux/macOS with no bundled runtime dependencies (gitmust be onPATH).feedbackis intentionally not ported (owner ruling W12-1, option 2 of #64): the oracle's version submits nothing and only points at the Spectra.app issue tracker, so file OpenSpectra issues on this repository instead. The reverse-engineering write-ups are indocs/reverse-engineering/:analyze.md,archive.md,artifact-workflow.md,config.md,decisions.md,demo-feedback.md,drift.md,in-progress.md,init.md,list-show.md,park.md,schema.md,schemas.md,scope.md,search.md,task.md,templates.md,update.md, andvalidate.md.validate's rules are not oracle-verified: they follow the OSSopenspec validate2.0.0, not the macOS binary; only its default output shape follows the binary — see the validate write-up.
The upstream Spectra CLI is closed-source and updated infrequently. drift —
which detects when a change's spec artifacts have diverged from the codebase —
is the most valuable piece to run in CI as a gate. It turns out to be pure
git + filesystem + regex heuristics (no AI), so it reimplements cleanly and
runs anywhere.
Given a change under <spec_dir>/changes/<name>/, it scores drift across four
dimensions and prints a single recommended next step:
- Time — days since the change was created (fresh → aging → stale → abandoned).
- Structure — design-doc anchors (file paths, functions, symbols, CLI flags) that no longer resolve against the codebase.
- Tasks — pending tasks that collide with external commits
(
tasks_blocked_externalandtasks_maybe_resolved, calibrated against oracle v3.0.0). - Environment — commit volume since creation (display only).
It outputs a human-readable, conclusion-first report or --json for tooling.
Like the reference binary, a successful run always exits 0 regardless of
severity, so a CI gate keys on a JSON field — use the FilePath entries of
broken_anchors, not severity and not the whole array (see below).
spectra init [PATH] [--force] [--dir <DIR>] [--adopt] [--tools <TOOLS>] [--json] # scaffolds .spectra.yaml + <spec_dir>/config.yaml + <spec_dir>/{changes/archive,specs}/ (default spec_dir: docs/openspec; --force preserves an existing spec_dir)
spectra drift [CHANGE] [--json] # auto-detects if one active change
spectra validate [ITEM] [--type change|spec] [--changes] [--specs] [--all] [--archived] [--strict] [--report full|findings] [--json [--format oracle|openspec]] # OpenSpec 2.0.0 rules; no argument = every active change; output in the oracle shape unless --format openspec
spectra list [--changes|--specs|--parked] [--sort name|modified|created] [--json] # lists active changes (default), capability specs (--specs), or parked changes (--parked)
spectra show <CHANGE|SPEC> [--item-type change|spec] [--diff] [--json] # change: proposal + delta spec list (JSON: all artifacts); spec: every .md file; --item-type picks one kind; --deltas-only/-r are accepted and inert, as in the reference; --diff isolates requirement-level change lines
spectra decisions [KEYWORD] [--json] # lists `### ` decisions under `## Decisions` in every design.md (active, then archived) with **Supersedes** resolution
spectra demo # creates a sample change (random spx-<adjective>-<pokemon> name, one of eight themes)
spectra park <CHANGE> [--json] # marks a change on hold (excluded from the active listing)
spectra unpark <CHANGE> [--json] # resumes a parked change
spectra new change <NAME> [--schema S] [--agent A] [--description D] [--json] # creates a change dir + .openspec.yaml only (kebab-case name; artifact files come later via `new artifact`)
spectra new artifact <TYPE> [CAPABILITY] [--change <NAME>] [--stdin] [--force] [--json] # creates one artifact (proposal|design|tasks|spec) from stdin or its built-in template, with per-type validation
spectra schemas [--json] # lists built-in (spec-driven, no-spec), project, and user workflow schemas
spectra schema init <NAME> [--description TEXT] [--artifacts IDS] [--default|--no-default] [--force] [--json] # creates a project-local workflow schema
spectra schema fork <SOURCE> [NAME] [--force] [--json] # copies a schema with target identity preserved
spectra schema validate [NAME] [--verbose] [--json] # validates schema structure, templates, and dependency graph
spectra schema which [NAME] [--all] [--json] # lists every source holding the schema (project → user → built-in); defaults to spec-driven, needs no project
spectra status [--change <NAME>|--all] [--schema <NAME>] [--json] # shows one or every artifact DAG with dependencies and skip state
spectra instructions [ARTIFACT] [--change <NAME>] [--schema <NAME>] [--skill <SKILL>] [--agent <AGENT>] [--compact] [--summary] [--omit-context] [--type bug-fix|refactor] [--json] # prints the artifact's authoring instruction + template (or embedded skill with --skill); with all artifacts done, switches to apply mode
spectra analyze [CHANGE] [--json] # 4-dimension artifact consistency report (Coverage/Consistency/Ambiguity/Gaps); always exits 0
spectra task start <TASK_ID> [--change <NAME>] [--json] # captures a per-task git baseline (task-baselines/), leaves tasks.md alone
spectra task done <TASK_ID> [--change <NAME>] [--json] [--file PATH]... # marks a tasks.md checkbox done; records files changed since task start, or the --file paths
spectra scope [--change <NAME>] [--base <REV>] [--check-snapshot <ID>] [--json] # read-only implementation scope: per-file git diffs (committed/staged/unstaged/untracked) with patches, limitations, and a snapshot id
spectra archive [CHANGE] [-y|--yes] [--skip-specs] [--mark-tasks-complete] [--no-validate] [--preview] [--json] # transactional merge/move with rollback; honors skip_specs/retire_capabilities metadata; trace data goes to specs/<cap>/spec.trace.yaml
spectra trace migrate [--dry-run] [--check] [--json] # OpenSpectra-only: moves inline <!-- @trace --> footers into spec.trace.yaml sidecars (idempotent), reports stale trace names; --check is a CI gate
spectra impl [--json] # OpenSpectra-only: shows active implementation mode (oss|oracle|shadow), source, and paths
spectra completion generate [SHELL] # prints a shell completion script (bash|zsh|fish|elvish|powershell; detects $SHELL when omitted)
spectra completion install [SHELL] [--verbose] # writes it to the shell's user completion dir (bash|zsh|fish; never edits your rc files)
spectra completion uninstall [SHELL] [-y] # removes that file
spectra in-progress add <NAME> # records a write-only in-progress marker (no --json, no removal path, no effect on any listing)
spectra update [PATH] [--force] # rewrites instruction files for every detected AI tool (.claude/, .cursor/, … 6 tools); oracle-verified byte-for-byte
spectra config <path|list|get|set|unset|reset|edit> # manages the global user config (~/Library/Application Support/openspec/config.yaml on macOS, ${XDG_CONFIG_HOME:-~/.config}/openspec/config.yaml elsewhere, absolute XDG paths only); needs no project
spectra search <QUERY> [--limit N] [--json] # searches Markdown artifacts using dependency-free lexical ranking
spectra templates [--schema NAME] [--json] # shows template paths for the workflow schema (defaults to spec-driven when --schema is omitted; resolves built-in, project, and user schemas when specified)Exit codes for drift (pinned against the reference binary): 0 on any
successful run — severity does not map to the exit code — and 1 on errors
(e.g. change not found). To gate CI, check the FilePath entries of the JSON
broken_anchors array; neither severity nor the unfiltered array is usable as
a gate (see CI gate example).
validate is the deliberate exception: it is a pass/fail gate, so it exits
0 when every selected change/spec/archive check is valid and 1 when any is
invalid (also 1 on operational errors). Its rules follow OpenSpec 2.0.0;
its output follows the reference binary by default — ✓ <name> — valid /
✗ <name> — invalid with error:/warn: lines, and --json prints the
[{change|spec, errors, valid, warnings}] array. --json --format openspec
prints OpenSpec 2.0.0's own report instead (items, summary.totals.failed,
byType, root, --report findings), field for field except the deliberate
divergences listed in validate.md. See
docs/reverse-engineering/validate.md.
spectra drift's human-readable conclusion line is colored by severity
(green/yellow/red) when stdout is a terminal; --no-color or the
NO_COLOR env var disables it.
From crates.io:
cargo install spectra-cliRelease tarballs are attached to GitHub releases for Linux and macOS:
curl -L https://github.com/heyu-ai/openspectra/releases/download/v0.14.2/spectra-v0.14.2-x86_64-unknown-linux-musl.tar.gz \
| tar xz
sudo mv spectra-v0.14.2-x86_64-unknown-linux-musl/spectra /usr/local/bin/spectraSubstitute the latest release tag from https://github.com/heyu-ai/openspectra/releases.
Docker images are published as ghcr.io/heyu-ai/openspectra:<tag> and
ghcr.io/heyu-ai/openspectra:latest (linux/amd64 only; on other platforms use
the release tarballs). The image bundles git and the spectra binary, with
spectra as its entrypoint:
docker run --rm -v "$PWD:/repo" -w /repo ghcr.io/heyu-ai/openspectra:latest drift --jsonWhen OpenSpectra is installed as spectra on a Mac that also has the closed
reference app, it can hand calls to that app instead of running itself — for a
gradual migration and a one-step rollback:
OPENSPECTRA_IMPL |
behaviour |
|---|---|
oss (default) |
OpenSpectra runs the command; non-zero exits and panics are appended to errors.jsonl |
oracle |
the reference binary runs it (argv, stdin, stdout, stderr and exit code passed through unchanged) |
shadow |
the reference binary's result is what you get; for read-only commands (list, show, status, validate, analyze, drift, instructions, schemas, templates, scope) OpenSpectra also runs and any difference is appended to shadow.jsonl. Writing commands only run on the reference binary |
The mode comes from the OPENSPECTRA_IMPL environment variable, else the
project's .spectra/impl file, else $XDG_CONFIG_HOME/openspectra/impl
(~/.config/openspectra/impl), else oss; it is deliberately not a
.spectra.yaml key, because the reference binary reads that file too. The
reference binary is /Applications/Spectra.app/Contents/MacOS/spectra unless
OPENSPECTRA_ORACLE_BIN says otherwise; oracle/shadow fail loudly when it
is missing rather than falling back. Logs go to $XDG_STATE_HOME/openspectra
(~/.local/state/openspectra); spectra impl [--json] shows the active mode,
where it came from, and the paths, and scripts/shadow-report.py summarizes
the logs. In shadow mode the read-only output is captured, so it is not
coloured.
# .github/workflows/spec-drift.yml
name: Spec Drift
on:
# Pull requests only, deliberately. This gate asks "did *this branch* delete a
# file its design still cites", which needs a fork point to compare against. On
# a `push` to the default branch `origin/main` IS the pushed commit, the
# merge-base below is HEAD, every non-resolving path reads as a forward
# reference, and the gate can never fail — measurably worse than no gate, since
# without a baseline it would at least have caught the deletion.
pull_request:
jobs:
drift:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install spectra
run: |
# Pin to a release tag; see https://github.com/heyu-ai/openspectra/releases for the latest.
SPECTRA_VERSION=v0.14.2
curl -L "https://github.com/heyu-ai/openspectra/releases/download/${SPECTRA_VERSION}/spectra-${SPECTRA_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
| tar xz
sudo mv "spectra-${SPECTRA_VERSION}-x86_64-unknown-linux-musl/spectra" /usr/local/bin/spectra
- name: Restore drift baselines
# `spectra init` gitignores `.spectra/`, so a CI checkout has no
# `.started` baseline for any change and every unresolved path -- including
# one the change merely PROPOSES to create -- reads as broken. Rebuilding
# the baseline from the merge-base restores the distinction, and is the
# right question for a PR anyway: "did this branch delete it?"
# Needs the `fetch-depth: 0` above: a shallow checkout has no origin/<base>.
env:
# Via env, not `${{ }}` inline: a ref name is not guaranteed free of
# shell metacharacters, and inline expansion happens before bash parses.
BASE_REF: ${{ github.event.pull_request.base.ref }}
run: |
base=$(git merge-base "origin/$BASE_REF" HEAD)
# Capture each stage separately. `x=$(a | b) || guard` only ever sees
# b's status -- and `jq` on empty stdin exits 0, so a failing
# `spectra list` would silently write no baseline at all.
changes=$(spectra list --json) || { echo "list failed"; exit 1; }
names=$(printf '%s' "$changes" | jq -r '.changes[].name') || { echo "jq failed"; exit 1; }
mkdir -p .spectra/changes
for change in $names; do printf '%s' "$base" > ".spectra/changes/$change.started"; done
- name: Check spec drift
run: |
spectra drift --json | tee drift.json
jq -e '[.broken_anchors[] | select(.category == "FilePath")] | length == 0' drift.json > /dev/nullspectra drift itself always exits 0 on a successful run (matching the
reference binary), so the gate is the explicit jq check. Each entry prints its
anchor, category and reason, so a red build says what to fix:
jq -r '.broken_anchors[] | select(.category == "FilePath")
| "\(.anchor)\t\(.reason)"' drift.jsonDo not gate on the unfiltered broken_anchors array. Every extracted
--flag is reported broken (not in --help) — faithfully, because there is no
target binary whose --help the design could be diffed against. Measured on a
committed change that is entirely healthy and merely mentions two flags in
prose:
$ spectra drift c --json | jq -c '{structure: .dimensions[1].status, severity, broken: [.broken_anchors[] | .category + " " + .anchor]}'
{"structure":"2/4 anchors broken","severity":"heavy","broken":["CliFlag --force","CliFlag --json"]}An unfiltered gate is red on that change, and stays red for as long as the
design mentions a flag. severity fails the same probe — it reads heavy
here — and is separately dominated by Time, which no pull request can fix: a
change untouched for 61 days scores 4 on Time alone, already enough for
medium. On a 29-change corpus that inverted the ordering a gate needs: the
four medium changes each had 0 broken anchors and were merely 68–82 days
old, while the one change that did have broken anchors read light.
Filtering to FilePath leaves the one category whose verdict consults the
change's .started baseline, so it means close to what a gate needs it to mean:
this path resolved when the change began and does not resolve now. Two
caveats on "resolved at the baseline", both deliberate and both measured:
- No usable baseline → broken, and CI has no baseline by default. The
verdict comes from
.spectra/changes/<name>.started, andspectra initgitignores.spectra/— so a freshactions/checkouthas no baseline for any change, and every non-resolving path reads as broken, including one the change merely proposes to create. Measured: the same change that reportsunresolved / forward referenceon the author's machine reportsfile does not existin a clone. That is why the workflow above rebuilds the baseline from the merge-base before runningdrift; without that step the gate degrades to "does not resolve now" and is red on almost every spec-driven change. (spectra new changewrites the baseline locally, but only when the project root is already a git repo with a commit.) - "Resolved" uses the same widened rule as the present-day check — the path
as written or its oracle truncation (#123). A design citing
frontend/src/x.tsin a repo where an unrelatedsrc/x.tswas deleted is therefore reported broken — a false positive. The alternative was measured and is worse: restricting the baseline probe to the written path turns a real deletion into a missed one when the project root is itself the sub-project. Both layouts are tabulated in the RE doc.
That is the entire signal. Measured against the reference binary, not inferred:
| category | on a committed change | in the gate? |
|---|---|---|
| FilePath | does not resolve now and either resolved at the baseline (written path or truncation) or has no usable baseline | yes |
| FilePath | resolved at neither → unresolved / forward reference |
no — the change may be proposing to create it |
| CliFlag | always broken (not in --help), matching the oracle |
no — filtered out; unconditional, so it carries no signal |
| Function / Symbol | git grep searches all tracked files including the change's own design.md, so an anchor extracted from a committed design always matches itself and never breaks |
no |
The last row is the important one, and it applies to the reference binary too:
probed on a committed design citing a function and a struct that exist nowhere
in the codebase, both binaries report neither as broken or unresolved —
they self-resolve. So no gate on this tool's output can currently detect a
deleted function or type. Excluding the change directory from git grep would
expose those anchors, but it would also make every prose word in a freshly
scaffolded design.md break (#51), so it is not a drop-in fix; it is tracked as
a known limitation in the RE doc.
Adopt this gate for what it is — a deleted-file detector for spec artifacts —
and do not read a green build as "this design still matches the code". Narrow
and honest beats broad and wrong; neither is a substitute for review. See
docs/reverse-engineering/drift.md.
The step above expects a single active change — with several, spectra drift
exits 1 asking for a change name. Gate a multi-change repo on the union
instead:
fail=0
# Capture the listing first too: a failing command substitution in a `for` word
# list does not trip `set -e`, so the loop would run zero times and the job
# would go green having checked nothing.
changes=$(spectra list --json) || { echo "list failed"; exit 1; }
# Capture the parse too. Left inside the `for` word list, a jq failure (bad JSON,
# or jq simply absent -- the published Docker image does not ship it) expands to
# nothing: the loop runs zero times and the job goes green having checked nothing.
names=$(printf '%s' "$changes" | jq -r '.changes[].name') || { echo "jq failed"; exit 1; }
for change in $names; do
report=$(spectra drift "$change" --json) || { echo "drift failed: $change"; exit 1; }
# Same reason again: capture before `grep`, so a jq failure cannot masquerade
# as "no broken anchors". `grep .` is only allowed to decide the verdict.
broken=$(printf '%s' "$report" \
| jq -r --arg c "$change" '.broken_anchors[] | select(.category == "FilePath")
| "\($c)\t\(.anchor)\t\(.reason)"') || { echo "jq failed: $change"; exit 1; }
printf '%s' "$broken" | grep . && fail=1
done
exit $failFor a structural gate, spectra validate --changes --strict fails the job
directly on its own exit code (no jq needed) — it exits non-zero when any
change lacks a delta, or (under --strict) has a requirement missing a
normative SHALL/MUST or a #### Scenario: block:
- name: Validate OpenSpec changes
run: spectra validate --changes --strictUnlike the OSS @fission-ai/openspec validator, this traverses nested
specs/<Epic>/<Feature>/spec.md layouts, so nested-capability changes are
validated instead of skipped as "no deltas found".
Instead of installing the tarball, invoke spectra through the published image
(it bundles git + the binary). Run it as a docker run step after a
normal checkout — do not use it as a job-level container:. The image is
Alpine/musl, and GitHub's container-job runtime injects a glibc Node.js to run
JavaScript actions, which actions/checkout can't execute on musl:
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate OpenSpec changes
# Pin to a release tag; :latest tracks the newest stable release.
run: |
docker run --rm -v "$PWD:/repo" -w /repo \
ghcr.io/heyu-ai/openspectra:v0.14.2 validate --changes --strictspectra validate gates on its own exit code, so no jq is needed. For the
drift + jq broken-anchor gate, use the tarball job above (the runner has jq
preinstalled; the minimal image does not ship it).
cargo build --release # produces target/release/spectra
cargo test # unit + integration testsProbes against the v3.0.0 oracle establish the Function/CliFlag/Symbol extraction
and resolution rules, per-category over-cap sampling, Structure score formula,
severity bands, and recommendation mapping. Unit tests and synthetic-repository
integration tests preserve those formulas and mappings, but they do not
byte-compare complete current reports with the four captured drift JSON files:
those fixtures contain output only, no test reads them, and calibration.rs
asserts hand-copied score triples. These are oracle-derived rules, not evidence
that current report bytes match the captured outputs. The long-standing
"Symbol-anchor narrowing filter" unknown turned out not to be a semantic filter
at all — it was the per-category over-cap sampling, recovered in #119.
Two resolution divergences remain by choice, plus one on extraction. A design
path that did not exist at the change's baseline is reported as a forward
reference rather than broken (#83). FilePath anchors keep their leading path
segments instead of being truncated to a string absent from the design (#123);
that also widens resolution, since a path resolves if either the written form
or the oracle's truncation is present — trading #123's measured 0/6
true-positive false positives for a rarer false negative. Details and the
calibration method are in the RE doc. The reference binary is used as a golden
oracle to calibrate constants (crates/spectra-core/src/calibration.rs).
crates/spectra-core/ # change discovery, spec discovery, anchors, git, drift scoring (library)
crates/spectra-cli/ # clap CLI: init / drift / analyze / search / completion / schemas / schema / templates / status / instructions / validate / list / show / decisions / demo / park / unpark / in-progress add / new change / new artifact / task start / task done / trace migrate / update / archive / scope / impl / config
crates/spectra-core/assets/update/ # instruction-file templates captured verbatim from the oracle (generated; see update.md)
docs/reverse-engineering/ # how the original works (each doc separates probed from still-unverified behavior)
scripts/ # oracle calibration probes + template capture (capture-update-templates.py)
MIT