specgate/docs v1.8.0

Proyecto existente · 1 — Adopta sin tocar código#

La versión corta de un proyecto existente, en seis comandos: Empezar. Esta página es el mismo paso en detalle, con la salida grabada.

In this phase

Cuando termines: Specgate configurado sobre un código que ya funciona, sin cambiar una sola línea de él, y un gate que pasa con tus tests existentes.

Antes de empezar: Node.js 22 o posterior, un repositorio Git con un archivo de build (package.json, pom.xml, build.gradle, go.mod, pyproject.toml, Cargo.toml, …), y una suite de tests que pasa.

El ejemplo es un pequeño servicio de facturación en Node con dos módulos (src/invoices, src/customers) y sus propios tests. Los proyectos Maven, Gradle, Go, Python, Cargo y .NET siguen el mismo camino. El código que prueba la fase 3 es src/invoices/total.js, que recibe las líneas y el tipo de IVA:

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 };

Su test, test/total.test.js, llama a total(lines, 0.21) y todavía no nombra ningún requisito: la fase 3 añade el nombre.

QuiénHace qué en esta fase
TúEjecutas cinco comandos, lees lo que proponen
SpecgateLee el archivo de build y la estructura; solo escribe archivos de especificación
El gateEjecuta tu suite existente, para probar la instalación
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. Instala Specgate en el proyecto#

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

Estas páginas escriben los comandos como specgate status. Si lo instalaste así, escribe npx specgate status. En un proyecto sin package.json, ejecútalo sin instalarlo: antepón a cada comando npx @rsaglobaltech/specgate@latest.

2. Mira antes de escribir nada — 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 no escribe nada. Nombra el stack y el comando de tests que encontró, y las capacidades —áreas del producto, como las facturas— que tu estructura ya implica. Son una propuesta para discutir, no un veredicto.

3. Adopta — 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 (lo mismo que adopt en un repositorio con código) escribe spec.md, AGENTS.md, un escenario baseline y la matriz de trazabilidad generada, y solo archivos que aún no existen. Las áreas que lee del código (Invoices, Customers) van a docs/specs/adoption.md con sus carpetas y sus tests: un mapa desde el que especificar, no requisitos. Guarda el comando de tests y el agente que detecta, preguntando antes, y termina con una lista de lo que está listo. Sin terminal en la que preguntar —un script, CI, la herramienta de un agente— no pregunta: guarda ambos, el agente como agent: claude --output-format stream-json --verbose --permission-mode acceptEdits -p < {prompt_file} | specgate harness events --from claude en harness.config.yaml. Lee esa línea, y cámbiala con specgate config set agent "<command>" si tu agente no debe editar sin preguntar.

4. Comprueba el comando de tests que guardó, o configúralo#

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. Ejecuta el 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`

En verde, con tus propios tests dentro, y con una advertencia honesta: de momento esto certifica el esqueleto, no el código. La fase 2 lo cambia.

El código antiguo tiene hallazgos antiguos. specgate quality init y después specgate quality baseline --accept registran lo que hay hoy, para que solo falle lo que añade un change. Consulta Checks de calidad y seguridad.

Has terminado cuando…#

  • specgate check termina con ✔ Gate passed y tu comando de tests.
  • git diff muestra archivos de especificación nuevos y ningún cambio bajo src/ ni en tus tests.

Variaciones#

  • La detección se equivocó: specgate adopt --var STACK="Spring Boot 3, Java 21" --var TEST_CMD="./mvnw -B verify".
  • No quieres propuestas: specgate init --no-capabilities.
  • Un monorepo (módulos Maven/Gradle, workspaces de npm o pnpm, miembros de Cargo, módulos de Go): specgate adopt --monorepo adopta cada módulo y escribe specops.config.yaml; specgate validate . imprime entonces una línea por módulo.
  • Ya usas OpenSpec: puede que no necesites adoptar nada: specgate verify pone en el gate los changes archivados de OpenSpec contra los tests. Consulta Ya usas OpenSpec.

Si algo sale mal#

VesSignificaHaz
The gate failed con tus tests en rojoTu suite ya fallabaCorrige u omite primero esos tests: el gate no certificará una suite en rojo
Gate passed — the specification y "nothing here runs your tests"No hay comando de testsspecgate config set test_cmd "<your command>"
Apareció una carpeta nueva <slug>/No se encontró ningún archivo de build, así que init generó un proyectoEjecútalo en la raíz del repositorio, donde está el archivo de build; o adopt --var STACK=…

¿Quieres primero el camino entero en una página? Un ejemplo completo: un servicio adoptado de principio a fin.

Siguiente#

Fase 2: escribe aquello de lo que dependes →