specgate/docs v1.8.0

The agent contract#

How a machine drives this CLI. The rules are fixed by ADR-0017; this document is generated from the source so it cannot drift from it.

The rules#

  1. One JSON document per invocation. In --json mode stdout carries exactly one JSON document. Prose, progress and warnings go to stderr, so cmd --json 2>/dev/null | jq . always parses.

  2. One diagnostic envelope, everywhere:

    json
    {
      "severity": "error" | "warning" | "info",
      "code": "snake_case_stable_string",
      "message": "human sentence",
      "target": "the thing at fault (optional)",
      "fix": "one actionable sentence or command (optional)",
      "file": "relative/path.md (optional)",
      "line": 42
    }

    Branch on code, never on message. message is prose and may be reworded; code is the published surface.

  3. Failure carries the command's null-shape. A failure prints { ...nullShape, "status": [diagnostic] } and exits 1 — never bare stderr, never a partial document. A consumer never has to tell "it failed" apart from "it printed nothing".

  4. camelCase everywhere in command output. (The on-disk formats are not command output: pack.yaml keeps schema_version and .specops.lock keeps pack_id.)

  5. --json and --format json are the same flag. The second spelling predates the contract and keeps working.

Exit codes#

SituationExit
Success, including advisory warnings0
Command failure — one JSON document with status1
Gate failure (validate, doctor, change validate)1
Usage error — unknown flag, missing or malformed argument2
Required script missing (a broken installation)3
Cancelled by the user130

A gate command exits 1 when it finds something, which is not the same as failing to run. The status array tells the two apart: a gate that could not run reports an error about itself.

Commands#

CommandDocument keyGate
specgate reverse [module] --jsonreverseno
specgate doctor --jsondoctoryes
specgate status --jsonstatusno
specgate alm pull --jsonpulledno
specgate alm phase <change> --jsonphaseno
specgate alm move <change> [<phase>] --jsonmoveno
specgate check [dir] --jsoncheckyes
specgate scenarios <REQ> --jsonscenariosyes
`specgate reproduce --capability --title run --json`reproduce
`specgate evidence before … --json`evidence
specgate map [<REQ>] [--capability <c>] --jsonmapno
specgate eval <skill> [--runs <n>] --jsonevalno
`specgate compat runreport [--tool ] [--level ] [--runs ] --json`compat
specgate learn [promote <L> --title <rule>] --jsonlearnno
specgate trust [promote <capability>] --jsontrustno
specgate migrate 1.0 [--dry-run] --jsonmigrateno
`specgate workspace <initstatuscheck
specgate drift [dir] --jsondriftyes
specgate contract check [dir] --jsoncontractyes
`specgate quality <listdoctorrun> --json`
specgate draft --jsondraftyes
specgate verify --jsonverifyyes
specgate pet --jsonpetno
specgate matrix --jsonmatrixyes
specgate validate <dir> --jsonvalidationyes
specgate plan --jsonplanno
specgate report --jsonreportno
specgate done <REQ> --jsonrequirementno
specgate new <title> --jsonrequirementno
specgate change list --jsonchangesno
specgate change show <id> --jsonchangeno
specgate change status --jsonartifactsno
specgate change validate <id> --jsonchangeyes
specgate change archive <id> --jsonarchiveyes
specgate change instructions <artifact> --jsoninstructionsno
specgate change author <id> --jsonchangeyes
specgate propose <id> --jsonchangeno
specgate brief add <module> <text> --jsonbriefno
specgate brief import <board.json>… --jsonbriefno
specgate brief model --jsonmodelno
specgate brief export --jsonexportno
specgate questions --jsonquestionsno
specgate answer <Q> <answer> --jsonanswerno
specgate ask <REQ> <question> --jsonaskno
specgate explore [question] --jsonexploreno
specgate apply [REQ] --jsonrequirementno
specgate archive <id> --jsonarchiveyes
specgate specops diff --jsonchangesno
specgate harness run --format jsonresultsno
specgate harness report --jsonreportno
specgate harness sandboxes --jsonsandboxesno
specgate harness doctor --jsondoctorno
specgate harness stop --after-current --jsonstopno
specgate harness continue --jsonpauseno
specgate release-notes <from>..<to> --jsonreleaseNotesno
specgate acceptance <change> --jsonacceptanceno
specgate guide --jsonguideno
specgate stack --jsonstackno
specgate adr new <title> --jsonadrno
specgate adr supersede <NNNN> <title> --jsonadrno
specgate adr list --jsonadrno
specgate review <change> --jsonreviewno
specgate agent ask "<request>" --jsonplanno
specgate agent apply <plan-id> --jsonappliedno
specgate agent discard <plan-id> --jsondiscardedno
specgate agent plans --jsonplansno

The document key is what the payload carries on success and what is set to null on failure. Every document also carries status: an array of diagnostics, empty when there is nothing to report.

Diagnostic codes#

Harvested from the source. A trailing * marks a family whose suffix is computed — strict_tdd_* covers strict_tdd_1 through strict_tdd_3.

CodeEmitted by
events_header_missingscripts/validate_specs.ts
feature_not_in_matrixscripts/validate_specs.ts
missing_required_filescripts/validate_specs.ts
no_featuresscripts/validate_specs.ts
requirement_cyclescripts/validate_specs.ts
self_dependencyscripts/validate_specs.ts
strict_tdd_1scripts/validate_specs.ts
strict_tdd_2scripts/validate_specs.ts
strict_tdd_3scripts/validate_specs.ts
traceability_unrecognizedscripts/validate_specs.ts
unknown_dependencyscripts/validate_specs.ts
use_cases_header_missingscripts/validate_specs.ts
approve_needs_personscripts/cli/commands/change/ChangeCommand.ts
archive_change_name_requiredscripts/cli/commands/change/ChangeCommand.ts
archive_draft_not_readyscripts/cli/commands/change/ChangeCommand.ts
archive_evidence_pagescripts/cli/commands/change/ChangeCommand.ts
archive_no_beforescripts/cli/commands/change/ChangeCommand.ts
archive_requirements_pendingscripts/cli/commands/change/ChangeCommand.ts
archive_spec_update_failedscripts/cli/commands/change/ChangeCommand.ts
author_agent_failedscripts/cli/commands/change/ChangeCommand.ts
author_agent_unsetscripts/cli/commands/change/ChangeCommand.ts
author_contracts_firstscripts/cli/commands/change/ChangeCommand.ts
author_needs_gitscripts/cli/commands/change/ChangeCommand.ts
author_out_of_scopescripts/cli/commands/change/ChangeCommand.ts
author_tree_dirtyscripts/cli/commands/change/ChangeCommand.ts
change_errorscripts/cli/commands/change/ChangeCommand.ts
change_existsscripts/cli/commands/change/ChangeCommand.ts
change_feature_sharedscripts/cli/commands/change/ChangeCommand.ts
change_id_requiredscripts/cli/commands/change/ChangeCommand.ts
change_kind_unknownscripts/cli/commands/change/ChangeCommand.ts
change_name_requiredscripts/cli/commands/change/ChangeCommand.ts
change_not_approvablescripts/cli/commands/change/ChangeCommand.ts
change_not_foundscripts/cli/commands/change/ChangeCommand.ts
change_requiredscripts/cli/commands/change/ChangeCommand.ts
conflicting_seed_flagsscripts/cli/commands/change/ChangeCommand.ts
impact_target_not_foundscripts/cli/commands/change/ChangeCommand.ts
invalid_change_idscripts/cli/commands/change/ChangeCommand.ts
invalid_value_drift_specscripts/cli/commands/change/ChangeCommand.ts
layer_discover_rewrittenscripts/cli/commands/change/ChangeCommand.ts
modify_already_openscripts/cli/commands/change/ChangeCommand.ts
modify_requirement_not_foundscripts/cli/commands/change/ChangeCommand.ts
trace_value_cutscripts/cli/commands/change/ChangeCommand.ts
value_drift_already_matchesscripts/cli/commands/change/ChangeCommand.ts
value_drift_id_not_declaredscripts/cli/commands/change/ChangeCommand.ts
value_drift_no_code_valuescripts/cli/commands/change/ChangeCommand.ts
value_drift_requirement_not_foundscripts/cli/commands/change/ChangeCommand.ts
missing_proposalpackages/core/src/application/ValidateChangeUseCase.ts
no_deltaspackages/core/src/application/ValidateChangeUseCase.ts
delta_emptypackages/core/src/domain/DeltaSpec.ts
delta_unknown_sectionpackages/core/src/domain/DeltaSpec.ts
duplicate_requirementpackages/core/src/domain/DeltaSpec.ts
invalid_requirement_idpackages/core/src/domain/DeltaSpec.ts
no_rfc2119_keywordpackages/core/src/domain/DeltaSpec.ts
requirement_already_existspackages/core/src/domain/DeltaSpec.ts
requirement_without_scenariopackages/core/src/domain/DeltaSpec.ts
scenario_not_gherkinpackages/core/src/domain/DeltaSpec.ts
scenario_steps_unwrittenpackages/core/src/domain/DeltaSpec.ts
scenario_without_stepspackages/core/src/domain/DeltaSpec.ts
unknown_requirementpackages/core/src/domain/DeltaSpec.ts
archive_capability_retiredpackages/core/src/application/ArchiveChangeUseCase.ts
archive_change_not_foundpackages/core/src/application/ArchiveChangeUseCase.ts
archive_change_symlinkpackages/core/src/application/ArchiveChangeUseCase.ts
archive_feature_existspackages/core/src/application/ArchiveChangeUseCase.ts
archive_feature_regeneratedpackages/core/src/application/ArchiveChangeUseCase.ts
archive_feature_stalepackages/core/src/application/ArchiveChangeUseCase.ts
archive_no_deltaspackages/core/src/application/ArchiveChangeUseCase.ts
archive_retire_not_declaredpackages/core/src/application/ArchiveChangeUseCase.ts
archive_target_existspackages/core/src/application/ArchiveChangeUseCase.ts
traceability_upgradedpackages/core/src/application/ArchiveChangeUseCase.ts
artifact_requiredscripts/change/instructions.ts
artifact_unknownscripts/change/instructions.ts
change_not_foundscripts/change/instructions.ts
project_not_foundscripts/change/instructions.ts
ambiguous_packscripts/cli/commands/specops/ContributeCommand.ts
change_has_no_deltasscripts/cli/commands/specops/ContributeCommand.ts
change_not_foundscripts/cli/commands/specops/ContributeCommand.ts
change_requiredscripts/cli/commands/specops/ContributeCommand.ts
contribute_not_pushedscripts/cli/commands/specops/ContributeCommand.ts
contribute_stage_failedscripts/cli/commands/specops/ContributeCommand.ts
no_lockfilescripts/cli/commands/specops/ContributeCommand.ts
nothing_to_contributescripts/cli/commands/specops/ContributeCommand.ts
pack_has_no_reposcripts/cli/commands/specops/ContributeCommand.ts
pack_not_foundscripts/cli/commands/specops/ContributeCommand.ts

Shapes a tool depends on#

These are read by tools built on this CLI (specgate-studio among them), so they change only in a major version.

  • status --json, in a project: total, pending, counts, requirements[] (id, title, category, needs, change, changeKind, question), nextCommand (a sentence) and next — the same step as data: { command, argv, placeholder }, argv without specgate and null when the step is not a command, placeholder true while an argument is still <…> for a person to fill in (REQ-565). migrate appears while an open change is still written for 0.x.
  • status --json, in a workspace repository (specgate.workspace.yaml, no traceability.md): { workspace, next } — workspace holds the repositories and the stories, next is { command, why }. There is no requirements key: each repository answers its own status.
  • change show <id> --json: change.approvals — required, approved, approvedAt and layers[] with each layer's approvals and quorum — is whether the change may be built (REQ-564). change.config.approved is only the line change.yaml keeps, and outlives an edit of a layer approved before it.
  • config list --json: a harness.config.yaml that cannot be read is the finding harness_config_invalid, with its fix, and exit 1 (REQ-563).

Worked example#

bash
specgate change instructions specs --json 2>/dev/null | jq -r '.instructions.rules[]'

An agent that reads fix self-corrects; one that reads only message retries the same mistake. That is why a check without a fix is treated as unfinished.