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#
One JSON document per invocation. In
--jsonmode stdout carries exactly one JSON document. Prose, progress and warnings go to stderr, socmd --json 2>/dev/null | jq .always parses.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 onmessage.messageis prose and may be reworded;codeis the published surface.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".camelCase everywhere in command output. (The on-disk formats are not command output:
pack.yamlkeepsschema_versionand.specops.lockkeepspack_id.)--jsonand--format jsonare the same flag. The second spelling predates the contract and keeps working.
Exit codes#
| Situation | Exit |
|---|---|
| Success, including advisory warnings | 0 |
Command failure — one JSON document with status | 1 |
Gate failure (validate, doctor, change validate) | 1 |
| Usage error — unknown flag, missing or malformed argument | 2 |
| Required script missing (a broken installation) | 3 |
| Cancelled by the user | 130 |
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#
| Command | Document key | Gate |
|---|---|---|
specgate reverse [module] --json | reverse | no |
specgate doctor --json | doctor | yes |
specgate status --json | status | no |
specgate alm pull --json | pulled | no |
specgate alm phase <change> --json | phase | no |
specgate alm move <change> [<phase>] --json | move | no |
specgate check [dir] --json | check | yes |
specgate scenarios <REQ> --json | scenarios | yes |
| `specgate reproduce | run | reproduce |
| `specgate evidence before | evidence | |
specgate map [<REQ>] [--capability <c>] --json | map | no |
specgate eval <skill> [--runs <n>] --json | eval | no |
| `specgate compat run | report [--tool | compat |
specgate learn [promote <L> --title <rule>] --json | learn | no |
specgate trust [promote <capability>] --json | trust | no |
specgate migrate 1.0 [--dry-run] --json | migrate | no |
| `specgate workspace <init | status | check |
specgate drift [dir] --json | drift | yes |
specgate contract check [dir] --json | contract | yes |
| `specgate quality <list | doctor | run> --json` |
specgate draft --json | draft | yes |
specgate verify --json | verify | yes |
specgate pet --json | pet | no |
specgate matrix --json | matrix | yes |
specgate validate <dir> --json | validation | yes |
specgate plan --json | plan | no |
specgate report --json | report | no |
specgate done <REQ> --json | requirement | no |
specgate new <title> --json | requirement | no |
specgate change list --json | changes | no |
specgate change show <id> --json | change | no |
specgate change status --json | artifacts | no |
specgate change validate <id> --json | change | yes |
specgate change archive <id> --json | archive | yes |
specgate change instructions <artifact> --json | instructions | no |
specgate change author <id> --json | change | yes |
specgate propose <id> --json | change | no |
specgate brief add <module> <text> --json | brief | no |
specgate brief import <board.json>… --json | brief | no |
specgate brief model --json | model | no |
specgate brief export --json | export | no |
specgate questions --json | questions | no |
specgate answer <Q> <answer> --json | answer | no |
specgate ask <REQ> <question> --json | ask | no |
specgate explore [question] --json | explore | no |
specgate apply [REQ] --json | requirement | no |
specgate archive <id> --json | archive | yes |
specgate specops diff --json | changes | no |
specgate harness run --format json | results | no |
specgate harness report --json | report | no |
specgate harness sandboxes --json | sandboxes | no |
specgate harness doctor --json | doctor | no |
specgate harness stop --after-current --json | stop | no |
specgate harness continue --json | pause | no |
specgate release-notes <from>..<to> --json | releaseNotes | no |
specgate acceptance <change> --json | acceptance | no |
specgate guide --json | guide | no |
specgate stack --json | stack | no |
specgate adr new <title> --json | adr | no |
specgate adr supersede <NNNN> <title> --json | adr | no |
specgate adr list --json | adr | no |
specgate review <change> --json | review | no |
specgate agent ask "<request>" --json | plan | no |
specgate agent apply <plan-id> --json | applied | no |
specgate agent discard <plan-id> --json | discarded | no |
specgate agent plans --json | plans | no |
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.
| Code | Emitted by |
|---|---|
events_header_missing | scripts/validate_specs.ts |
feature_not_in_matrix | scripts/validate_specs.ts |
missing_required_file | scripts/validate_specs.ts |
no_features | scripts/validate_specs.ts |
requirement_cycle | scripts/validate_specs.ts |
self_dependency | scripts/validate_specs.ts |
strict_tdd_1 | scripts/validate_specs.ts |
strict_tdd_2 | scripts/validate_specs.ts |
strict_tdd_3 | scripts/validate_specs.ts |
traceability_unrecognized | scripts/validate_specs.ts |
unknown_dependency | scripts/validate_specs.ts |
use_cases_header_missing | scripts/validate_specs.ts |
approve_needs_person | scripts/cli/commands/change/ChangeCommand.ts |
archive_change_name_required | scripts/cli/commands/change/ChangeCommand.ts |
archive_draft_not_ready | scripts/cli/commands/change/ChangeCommand.ts |
archive_evidence_page | scripts/cli/commands/change/ChangeCommand.ts |
archive_no_before | scripts/cli/commands/change/ChangeCommand.ts |
archive_requirements_pending | scripts/cli/commands/change/ChangeCommand.ts |
archive_spec_update_failed | scripts/cli/commands/change/ChangeCommand.ts |
author_agent_failed | scripts/cli/commands/change/ChangeCommand.ts |
author_agent_unset | scripts/cli/commands/change/ChangeCommand.ts |
author_contracts_first | scripts/cli/commands/change/ChangeCommand.ts |
author_needs_git | scripts/cli/commands/change/ChangeCommand.ts |
author_out_of_scope | scripts/cli/commands/change/ChangeCommand.ts |
author_tree_dirty | scripts/cli/commands/change/ChangeCommand.ts |
change_error | scripts/cli/commands/change/ChangeCommand.ts |
change_exists | scripts/cli/commands/change/ChangeCommand.ts |
change_feature_shared | scripts/cli/commands/change/ChangeCommand.ts |
change_id_required | scripts/cli/commands/change/ChangeCommand.ts |
change_kind_unknown | scripts/cli/commands/change/ChangeCommand.ts |
change_name_required | scripts/cli/commands/change/ChangeCommand.ts |
change_not_approvable | scripts/cli/commands/change/ChangeCommand.ts |
change_not_found | scripts/cli/commands/change/ChangeCommand.ts |
change_required | scripts/cli/commands/change/ChangeCommand.ts |
conflicting_seed_flags | scripts/cli/commands/change/ChangeCommand.ts |
impact_target_not_found | scripts/cli/commands/change/ChangeCommand.ts |
invalid_change_id | scripts/cli/commands/change/ChangeCommand.ts |
invalid_value_drift_spec | scripts/cli/commands/change/ChangeCommand.ts |
layer_discover_rewritten | scripts/cli/commands/change/ChangeCommand.ts |
modify_already_open | scripts/cli/commands/change/ChangeCommand.ts |
modify_requirement_not_found | scripts/cli/commands/change/ChangeCommand.ts |
trace_value_cut | scripts/cli/commands/change/ChangeCommand.ts |
value_drift_already_matches | scripts/cli/commands/change/ChangeCommand.ts |
value_drift_id_not_declared | scripts/cli/commands/change/ChangeCommand.ts |
value_drift_no_code_value | scripts/cli/commands/change/ChangeCommand.ts |
value_drift_requirement_not_found | scripts/cli/commands/change/ChangeCommand.ts |
missing_proposal | packages/core/src/application/ValidateChangeUseCase.ts |
no_deltas | packages/core/src/application/ValidateChangeUseCase.ts |
delta_empty | packages/core/src/domain/DeltaSpec.ts |
delta_unknown_section | packages/core/src/domain/DeltaSpec.ts |
duplicate_requirement | packages/core/src/domain/DeltaSpec.ts |
invalid_requirement_id | packages/core/src/domain/DeltaSpec.ts |
no_rfc2119_keyword | packages/core/src/domain/DeltaSpec.ts |
requirement_already_exists | packages/core/src/domain/DeltaSpec.ts |
requirement_without_scenario | packages/core/src/domain/DeltaSpec.ts |
scenario_not_gherkin | packages/core/src/domain/DeltaSpec.ts |
scenario_steps_unwritten | packages/core/src/domain/DeltaSpec.ts |
scenario_without_steps | packages/core/src/domain/DeltaSpec.ts |
unknown_requirement | packages/core/src/domain/DeltaSpec.ts |
archive_capability_retired | packages/core/src/application/ArchiveChangeUseCase.ts |
archive_change_not_found | packages/core/src/application/ArchiveChangeUseCase.ts |
archive_change_symlink | packages/core/src/application/ArchiveChangeUseCase.ts |
archive_feature_exists | packages/core/src/application/ArchiveChangeUseCase.ts |
archive_feature_regenerated | packages/core/src/application/ArchiveChangeUseCase.ts |
archive_feature_stale | packages/core/src/application/ArchiveChangeUseCase.ts |
archive_no_deltas | packages/core/src/application/ArchiveChangeUseCase.ts |
archive_retire_not_declared | packages/core/src/application/ArchiveChangeUseCase.ts |
archive_target_exists | packages/core/src/application/ArchiveChangeUseCase.ts |
traceability_upgraded | packages/core/src/application/ArchiveChangeUseCase.ts |
artifact_required | scripts/change/instructions.ts |
artifact_unknown | scripts/change/instructions.ts |
change_not_found | scripts/change/instructions.ts |
project_not_found | scripts/change/instructions.ts |
ambiguous_pack | scripts/cli/commands/specops/ContributeCommand.ts |
change_has_no_deltas | scripts/cli/commands/specops/ContributeCommand.ts |
change_not_found | scripts/cli/commands/specops/ContributeCommand.ts |
change_required | scripts/cli/commands/specops/ContributeCommand.ts |
contribute_not_pushed | scripts/cli/commands/specops/ContributeCommand.ts |
contribute_stage_failed | scripts/cli/commands/specops/ContributeCommand.ts |
no_lockfile | scripts/cli/commands/specops/ContributeCommand.ts |
nothing_to_contribute | scripts/cli/commands/specops/ContributeCommand.ts |
pack_has_no_repo | scripts/cli/commands/specops/ContributeCommand.ts |
pack_not_found | scripts/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) andnext— the same step as data:{ command, argv, placeholder },argvwithoutspecgateand null when the step is not a command,placeholdertrue while an argument is still<…>for a person to fill in (REQ-565).migrateappears while an open change is still written for 0.x.status --json, in a workspace repository (specgate.workspace.yaml, notraceability.md):{ workspace, next }—workspaceholds the repositories and the stories,nextis{ command, why }. There is norequirementskey: each repository answers its ownstatus.change show <id> --json:change.approvals—required,approved,approvedAtandlayers[]with each layer's approvals and quorum — is whether the change may be built (REQ-564).change.config.approvedis only the linechange.yamlkeeps, and outlives an edit of a layer approved before it.config list --json: aharness.config.yamlthat cannot be read is the findingharness_config_invalid, with its fix, and exit 1 (REQ-563).
Worked example#
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.