specgate/docs v1.8.0

How Specgate thinks#

Six ideas explain everything the CLI does. Read this once and every command, error and flag has a reason you can predict.

Without Specgate, a closed loop; with it, a gate the agent cannot edit Two panels side by side. Without Specgate, a closed loop: the same agent writes the code, writes the tests and grades itself, so all green is its own verdict; 16 of 36 exam runs, 44 percent, met the specification. With Specgate, a gate the agent cannot edit: the agents — Claude Code, Codex, OpenCode — hand their work to the gate, which holds the sealed spec, test first, the guard and the outside judge; a person approves what the gate holds; what passes is delivered, and shortcuts bounce back to the agents. 33 of 36 runs, 92 percent, met the specification. WITHOUT SPECGATE: A CLOSED LOOP WITH SPECGATE: A GATE IT CANNOT EDIT writes the code writes the tests grades itself person approves ✓ all green — its own verdict agents Claude Code · Codex OpenCode the gate sealed spec · test first guard · outside judge delivered shortcuts bounce back 44% of runs met the specification 16 of 36 92% of runs met the specification 33 of 36
An agent that writes its own tests grades its own work; behind a gate it cannot edit, more of its runs met the specification.
The compatibility exam, without and with Specgate Paired horizontal bars, without Specgate and with it, on an axis from 0 to 100 percent of runs. Met the specification: 16 of 36 runs, 44 percent, without; 33 of 36, 92 percent, with; p < 0.001. Delivered wrong or unrequested work, where lower is better: 15 of 36, 42 percent, without; 1 of 36, 3 percent, with; p < 0.001. Stopped at work nobody asked for and proposed a requirement instead: 0 of 9 without; 7 of 9, 78 percent, with; p = 0.002. Repaired a suite left red by another requirement, in its code and not its test: 4 of 9 without; 9 of 9 with; p = 0.029. Trap tasks, which hand the agent a test that contradicts the scenario, with acceptance tests written by a second agent and sealed: 12 of 18 without, 67 percent; 17 of 18, 94 percent, with; not significant at this size. 72 graded runs of Claude Haiku, Claude Sonnet and Codex on the released version, the arm with Specgate run on its final build, each doing the same four tasks three times, graded by a hidden check the agent never sees; p-values from a two-sided Fisher's exact test. agent on its own with Specgate 0% 25% 50% 75% 100% share of runs Did what the requirement says checked by a test the agent never saw p < 0.001 Wrong or unrequested work shipped — lower is better p < 0.001 “Also add a CSV export” no requirement: stopped, proposed one p = 0.002 Another feature’s test is red fixed that code, not its test p = 0.029 A test contradicts the spec followed the spec · sealed tests not significant at this size 16 of 36 · 44% 33 of 36 · 92% 15 of 36 · 42% 1 of 36 · 3% 0 of 9 · 0% 7 of 9 · 78% 4 of 9 · 44% 9 of 9 · 100% 12 of 18 · 67% 17 of 18 · 94%
72 graded runs on the released version — Claude Haiku, Claude Sonnet and Codex, the same four tasks with and without Specgate, graded by a hidden check; p from a two-sided Fisher's exact test.

1. A requirement is a sentence that can be wrong#

A requirement lives in spec.md (or in a capability spec under docs/specs/) as a numbered section:

markdown
## REQ-007 — Customers download invoices as PDF

<!-- specgate:trace status=Implemented -->

A customer with a paid invoice MUST be able to download it as a PDF from the
invoice page, within two seconds, with the invoice number in the file name.

The prose is for people. The specgate:trace comment is for the tool — it holds the status, and any link the tool cannot infer. You write the section in a change's delta (specgate propose), or specgate new writes it in spec.md with a draft sentence for you to rewrite; specgate apply records the status when the gate passes.

A requirement is useful when two people could test it and agree on the answer. "Invoices are easy to get" is a wish; the paragraph above is a requirement.

2. A scenario makes it executable#

Every requirement has at least one Gherkin scenario, tagged with its ids:

gherkin
@REQ-007 @SCN-007
Scenario: A paid invoice downloads as a PDF
  Given a customer with a paid invoice INV-2041
  When they download it from the invoice page
  Then they receive "INV-2041.pdf" within 2 seconds

The scenario is the acceptance criterion. Gherkin, rather than prose, because a runner can execute it — and because the gate can check things about it that it cannot check about prose: that it has steps, that its keywords are ones Cucumber recognises, that an Outline has Examples.

There is nothing to declare. A test or a source file that mentions REQ-007 is linked to it:

js
// REQ-007 SCN-007 — a paid invoice downloads as a PDF
test("a paid invoice downloads as a PDF", async () => { /* … */ });

That is the whole linking model. Rename the test and the link moves with it; delete it and the requirement loses its test — which the gate then reports.

4. The matrix is generated, never edited#

docs/specs/traceability.md is one row per scenario: requirement, scenario, feature file, test, code, status. Every column is already said somewhere else, so it is computed from those sources:

  1. REQ-001requirement
  2. SCN-001scenario
  3. load_pack.featureGherkin
  4. UC-001use case
  5. CMD-001command
  6. AGG-001aggregate
  7. EVT-001event
  8. src/…code
  9. …steps.tstest
  10. Verifiedstatus
One row of the matrix, read as a sentence. Break any link and specgate check fails — which is what stops a specification from quietly becoming false.
ColumnComes from
Requirement, titlethe ## REQ-NNN sections in spec.md and capability specs
Scenario, feature file@REQ-NNN @SCN-NNN tags in features/**/*.feature
Test, codefiles that mention REQ-NNN
Statusthe specgate:trace comment, written by specgate apply

specgate check and specgate apply regenerate it before they judge. specgate validate — what CI runs — fails with matrix_stale when the committed copy no longer matches its sources. It stays committed because people and tools read it; it just has no author.

5. A status is a promise, and the gate collects on it#

The gate is strict, but it only asks a requirement for what its status promises:

StatusWhat it owes
DraftNothing — except that its scenarios cannot lie: no scenario without steps, no keyword Cucumber would read as prose, no Outline without Examples.
Past Draft (Approved, In Dev, In Review, …)A test that mentions it (and, on a hand-kept matrix, a scenario id).
Delivered (Implemented, Verified, Released)All of the above, plus every file it points at exists and its scenario has no <placeholder> steps.
DeprecatedIts files may be gone; nothing is owed.

This is why the gate is green on the day you adopt it and means more with every requirement you deliver. It is also why it never lies about its own reach — a green run says how many rows were exempt:

text
- Strict TDD gate: passed (3 row(s) exempt — still Draft, so not checked)

specgate apply REQ-007 is how a requirement reaches a delivered status. It refuses while no test names the requirement, then runs the gate for it: if the gate would fail, nothing is written. (--no-check skips the gate, for the rare case it is wrong — say so in the pull request.)

6. One gate, one name#

There is exactly one gate: validate --strict on the specification, then your architecture check, your tests and your quality checks when they are configured. specgate check runs it, and so does everything else.

WhereWhat runs
Your machine, before a PRspecgate check — the gate, then your tests if a test command is configured
Delivering a requirementspecgate apply — the gate for that requirement, then the status
CIthe spec gate init and adopt install (specgate ci init writes it again) — specgate check with the project's JDK or Node set up; specgate ci status says what it checks
An agentthe /specgate:check command, the Stop hook, the harness

A gate that was slightly different in each place used to approve work in one and fail it in the next. Now a green in one place is a green everywhere.

Around the core#

Three things build on those six ideas. The first is the daily loop; the other two are not needed on day one.

Changes. New work and edits to what already shipped both go through a change: a folder under docs/specs/changes/<id>/ holding a proposal and a delta, which lists only the requirements and scenarios that move, never a copy of the spec. While it is open, its requirements count: status lists them, apply delivers them one by one, check judges the project as it will be after archive. specgate archive <id> merges it into the spec tree and writes the feature files once every requirement in it is Implemented. A change is archived when its code is done, on its branch, so the spec and the code land in one pull request (ADR-0035). → Change a shipped requirement

Layers. A change has three, each with its owner: discover.md, product's — what the business needs, its acceptance criteria, no technology; design.md, the architect's — how, answering each criterion; tasks.md, the developer's — the work, each task naming its requirement. Product reviews the story, the architect the design, and the story stays put while the design changes (ADR-0044).

A change comes from one of three places:

SourceCommandGuide
One behaviour you describe yourselfspecgate propose <change-id>Propose one change
A brief: a new product, or a large area of onespecgate propose --from-briefFrom a client brief
A Jira ticket with acceptance criteriaspecgate propose --from-ticket <KEY>From a Jira ticket

A change from a brief or a ticket is a draft: it is checked against its source text, and every value it uses must come from that text or be listed as an assumption.

Domain packs. A versioned, schema-validated set of requirements and scenarios for a domain (multi-tenancy, payments, …), installed like a dependency, pinned by digest in .specops.lock, and upgraded through a reviewable diff. → Domain packs

The harness. Hands one pending requirement at a time to any coding agent in its own git worktree, runs the gate on the result, and marks the requirement Implemented only when it passes. It never merges unless you ask for a chain (--chain), and specgate studio shows it at work at /live. → The harness

Before a change exists, specgate explore writes a brief of where the project stands for you or your agent to think with; specgate onboard --tour runs the whole loop on a temporary copy of your repository. → Command reference

Vocabulary#

TermMeaning
AssumptionA value a draft uses that its brief or ticket does not state (a price, a limit, a label), listed in the change's assumptions.md with the requirements that use it.
BriefYour plan for a product, saved as docs/brief.md, with a short front matter naming the product, its actors, their surfaces and its modules.
CapabilityOne area of the product (orders, invoices, …). Its requirements live in docs/specs/capabilities/<capability>/spec.md.
ChangeA folder under docs/specs/changes/<id>/ holding work in progress: a proposal and a delta. Opened by propose, closed by archive.
D-rulesThe drafting checklist (D1–D17) a draft from a brief must pass: a scenario per requirement and per surface, values with a source, quotes the brief really says, open questions that block, and more.
Definition of ReadyThe checks a Jira ticket must pass before it becomes a change: the T-rules.
DeliveredA status of Implemented, Verified or Released.
DeltaThe part of a change that says what moves: the requirements and scenarios it adds, modifies or removes.
DraftA change opened from a brief or a ticket, and checked against that source text before a person reviews it. Not to be confused with the status Draft, which a requirement has before work on it starts and which owes nothing to the gate.
Gatespecgate check: the specification checks (validate --strict), your architecture check if you set one, and your tests. apply runs it for one requirement; CI runs it on every pull request.
Harnessspecgate harness run: hands each pending requirement to a coding agent in its own git worktree, runs the gate, and marks the requirement Implemented only when it passes.
PackA versioned domain model installed with specgate specops add.
Question / Needs ClarificationWhat a draft's source cannot answer, listed in the change's questions.md. A requirement a question blocks has the status Needs Clarification: apply and the harness refuse it until someone answers.
Requirement (REQ-NNN)One obligation of the system, a numbered section in spec.md or a capability spec.
Scenario (SCN-NNN)A Gherkin example that demonstrates a requirement, in features/.
T-rulesThe ticket's Definition of Ready (T1–T9): acceptance criteria present, measurable and about behaviour, the ticket small enough, no open question, and more.
TicketA Jira story or bug used as the source text of a change: specgate propose --from-ticket <KEY>.
Traceability matrixdocs/specs/traceability.md: one row per scenario, linking requirement, scenario, feature file, test, code and status. Generated, never edited.

Next#