specgate/docs v1.8.0

Existing project · 1 — Adopt, touching no code#

The short version of an existing project, in six commands: Start. This page is the same step in detail, with recorded output.

In this phase

When you finish: Specgate set up on a codebase that already works, without changing a line of it, and a gate that passes with your existing tests.

Before you start: Node.js 22 or later, a Git repository with a build file (package.json, pom.xml, build.gradle, go.mod, pyproject.toml, Cargo.toml, …), and a test suite that passes.

The example is a small Node invoicing service with two modules (src/invoices, src/customers) and its own tests. Maven, Gradle, Go, Python, Cargo and .NET projects go the same way. The code phase 3 tests is src/invoices/total.js, which takes the lines and the VAT rate:

js
/** Sum of the lines, VAT included, rounded to the cent. */
function total(lines, vatRate) {
  const net = lines.reduce((sum, l) => sum + l.quantity * l.unitPrice, 0);
  return Math.round(net * (1 + vatRate) * 100) / 100;
}

module.exports = { total };

Its test, test/total.test.js, calls total(lines, 0.21) and names no requirement yet: phase 3 adds the name.

WhoDoes what in this phase
YouRun five commands, read what they propose
SpecgateReads the build file and the layout; writes specification files only
The gateRuns your existing suite, to prove the wiring
Adopting a repository that already runs, then specifying it module by module Six steps. One: your repository, code that already runs, with a build file and a test suite that passes. Two: specgate init adopts it in place, the same as specgate adopt: it writes spec.md, AGENTS.md, docs/specs, the baseline scenario features/adoption/baseline.feature, the gate policy .specgate/gate.yaml and the CI job — only files that do not exist yet. Your src and tests folders stay as they are: git diff shows new specification files only. Three: specgate check is green on day one, with your own tests in it; it certifies the skeleton, not the code yet. Four: pick one module, by either of two roads. By hand, open a change for it with specgate propose describe-orders --capability orders. Or let specgate reverse --modules find the candidate modules — folders with their own build manifest, Go packages, code under src or apps — each with its stack; no agent runs. Five: your agent reads that module. On the reverse road, specgate reverse with the module and --agent writes the change reverse-orders; on the other, it writes the describe-orders delta. Every requirement is Draft; reverse also cites in source= the lines each was read from. Behaviour that looks like a bug becomes a question in questions.md, never a requirement, because written as one the bug would become the contract. A person reads each requirement against its lines before moving it past Draft. Six: from then on, one behaviour per bug fix — open a change for the behaviour that broke, write the scenario that reproduces it, name it in a test, and the fix applies it. 1 Your repository code that already runs, a build file and a test suite that passes 2 specgate init adopts it in place — the same as adopt: + spec.md + AGENTS.md + docs/specs/ + features/adoption/baseline.feature + .specgate/gate.yaml + the CI job only files that do not exist yet 3 Green on day one specgate check Gate passed, with your own tests in it — so far it certifies the skeleton, not the code src/ and tests/ stay as they are — git diff shows new specification files only 4 Pick one module by hand, a change for it: propose describe-orders --capability orders or let Specgate find them, no agent: specgate reverse --modules 5 Your agent reads one reverse orders --agent "…" writes reverse-orders — or, by hand, the describe-orders delta. All Draft; reverse cites the lines it read: source=…/Cancel.java:12 Looks like a bug? a question in questions.md, never a requirement: written as one, the bug would become the contract 6 From then on, one behaviour per bug fix Before a fix, open a change for the behaviour that broke and write the scenario that reproduces it; a test names it, and the fix applies it. The specification grows where the risk actually was. then, one module at a time suspect a person reads each against its lines, then moves it past Draft
Adopting writes specification files only and is green on day one; a change per module — by hand with propose --capability, or found by reverse — then turns each into Draft requirements, and a suspected bug stays a question.

1. Install Specgate in the project#

bash
cd your-existing-repo
npm install --save-dev @rsaglobaltech/specgate

These pages write commands as specgate status. Where you installed it this way, type npx specgate status. On a project without a package.json, run it without installing: prefix each command with npx @rsaglobaltech/specgate@latest.

2. Look before writing anything — specgate onboard#

bash
specgate onboard
Terminal
$ specgate onboard
  🧭 onboarding  ~/invoicing
 
  1. What this is
     stack:  Node.js
     tests:  npm test
     detected from package.json
 
  2. Specs
     · not adopted yet — `specgate adopt` writes the skeleton without touching code
 
  3. Capabilities this codebase already implies
     · Invoices             src/invoices  (2 files)
     · Customers            src/customers  (1 files)
 
     A proposal, not a verdict. Merge, split or rename them.
 
  Next
     specgate adopt

onboard writes nothing. It names the stack and test command it found, and the capabilities — areas of the product, such as invoices — your layout already implies. They are a proposal to argue with, not a verdict.

3. Adopt — specgate init#

bash
specgate init
Terminal
$ specgate init
  ◆ specgate · init
 
  ℹ  Existing code found (package.json) — adopting this repository in place. Nothing in your code is touched.
  ℹ  To scaffold a separate new project instead: specgate init --new
 
  Stack detection: package.json ──────────────────────────
    · Project: invoicing
    · Stack: Node.js
    · Test command: npm test
    + spec.md
    + features/adoption/baseline.feature
    + docs/specs/traceability.md
    + docs/specs/adr/README.md
    + docs/specs/glossary.md
    + AGENTS.md
    + docs/specs/adoption.md   2 areas found in the code
    + README.md   was missing
  ℹ  🚦 Policy: .specgate/gate.yaml — the standard preset; edit a rule to change what fails
  ℹ  🚦 CI: .github/workflows/spec-gate.yml — the spec gate; `specgate ci status` says what it checks
    · Traceability: generated from spec.md, tags and tests (`specgate matrix`)
 
  Summary ────────────────────────────────────────────────
    · Files written: 8
    · Files skipped (already present): 0
    · Areas found in the code: 2 — invoices, customers (docs/specs/adoption.md, not requirements)
  ▲  This does not certify your code yet — it certifies the skeleton.
     A green `validate` right now means the structure is in place, not that any
     behaviour is covered. It starts meaning something when the requirements below
… 20 more lines

init (the same as adopt on a repository with code) writes spec.md, AGENTS.md, a baseline scenario and the generated traceability matrix — and only files that do not exist yet. The areas it reads off the code (Invoices, Customers) go to docs/specs/adoption.md with their folders and tests — a map to specify from, not requirements. It saves the test command and the agent it detects, asking first, and ends with a readiness list. With no terminal to ask in — a script, CI, an agent's tool — it does not ask: it saves both, the agent as agent: claude --output-format stream-json --verbose --permission-mode acceptEdits -p < {prompt_file} | specgate harness events --from claude in harness.config.yaml. Read that line, and change it with specgate config set agent "<command>" if your agent must not edit unasked.

4. Check the test command it saved — or set it#

bash
specgate config set test_cmd "node --test"
Terminal
$ specgate config set test_cmd "node --test"
  ✔  test_cmd = node --test
     harness.config.yaml
     `check` and `apply` now run it.

5. Run the gate#

bash
specgate check
Terminal
$ specgate check
  ◆ specgate · check   invoicing
 
  ·  Policy         .specgate/gate.yaml (standard): coverage warning, use_cases warning, scope warning, controls warning
  ·  Ids            not compared with a base — no base branch (pass --base <branch>)
  ✔  Specification   validate --strict
  ✔  Tests           node --test
  ·  Architecture    not checked — specgate config set arch_cmd "<command>"
 
  ✔  Gate passed — the specification and `node --test`

Green, with your own tests in it — and a warning that is honest: so far this certifies the skeleton, not the code. Phase 2 changes that.

Old code has old findings. specgate quality init and then specgate quality baseline --accept record what is there today, so only what a change adds fails. See Quality and security checks.

You're done when…#

  • specgate check ends with ✔ Gate passed and your test command.
  • git diff shows new specification files and no change under src/ or your tests.

Variations#

  • Detection was wrong: specgate adopt --var STACK="Spring Boot 3, Java 21" --var TEST_CMD="./mvnw -B verify".
  • No proposals wanted: specgate init --no-capabilities.
  • A monorepo (Maven/Gradle modules, npm or pnpm workspaces, Cargo members, Go modules): specgate adopt --monorepo adopts each module and writes specops.config.yaml; specgate validate . then prints one line per module.
  • Already on OpenSpec: you may not need to adopt at all — specgate verify gates OpenSpec's archived changes on tests. See Already on OpenSpec.

If something goes wrong#

You seeIt meansDo
The gate failed with your tests redYour suite was already failingFix or skip those tests first — the gate will not certify a red suite
Gate passed — the specification and "nothing here runs your tests"No test commandspecgate config set test_cmd "<your command>"
A new <slug>/ folder appearedNo build file was found, so init scaffoldedRun it at the repository root, where the build file is; or adopt --var STACK=…

Want the whole path on one page first? A worked example: one service adopted end to end.

Next#

Phase 2 — write down what you rely on →