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:
/** 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.
| Who | Does what in this phase |
|---|---|
| You | Run five commands, read what they propose |
| Specgate | Reads the build file and the layout; writes specification files only |
| The gate | Runs your existing suite, to prove the wiring |
1. Install Specgate in the project#
cd your-existing-repo
npm install --save-dev @rsaglobaltech/specgateThese 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#
specgate onboard$ 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 adoptonboard 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#
specgate init$ 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 linesinit (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#
specgate config set test_cmd "node --test"$ specgate config set test_cmd "node --test"
✔ test_cmd = node --test
harness.config.yaml
`check` and `apply` now run it.5. Run the gate#
specgate check$ 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 checkends with✔ Gate passedand your test command.git diffshows new specification files and no change undersrc/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 --monorepoadopts each module and writesspecops.config.yaml;specgate validate .then prints one line per module. - Already on OpenSpec: you may not need to adopt at all —
specgate verifygates OpenSpec's archived changes on tests. See Already on OpenSpec.
If something goes wrong#
| You see | It means | Do |
|---|---|---|
The gate failed with your tests red | Your suite was already failing | Fix 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 command | specgate config set test_cmd "<your command>" |
A new <slug>/ folder appeared | No build file was found, so init scaffolded | Run 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.