Agent Reference
Machine-oriented reference for coding agents. For narrative and rationale, see the other docs sections.
Mental model
Section titled “Mental model”- Canonical truth:
spec-engine/<DOMAIN>/SPEC.jsonfiles in git, validated by one shared schema on every surface. Requirement IDs (KEY-NNN) are permanent; changes supersede, never overwrite. - Code binds to requirements with comment tags:
// @spec KEY-NNN(+ optional level token). - Tag kind is path-derived: implementation code = implements; test path = verifies.
- The index at
<platformDir>/.spec-engine/index.sqliteis derived and disposable — read commands build it transparently when missing. - Coverage/drift/propagation are SQL projections over tags — never authored. Drift compares a member’s pin (
spec-engine@N, one platform-wide scalar) against each referenced requirement’schanged_at_version, derived within its domain’s supersede DAG; the platform version is the max domain version, derived too.
Invocation
Section titled “Invocation”bun packages/engine/src/cli.ts <command> [...] # from a checkout./dist/spec <command> [...] # compiled binary- Almost every command takes an optional trailing
platformDirpositional (default: cwd) - All commands are non-interactive when stdin is not a TTY
--jsonoutput → stdout only; guidance, warnings, diagnostics → stderr
The agent loop
Section titled “The agent loop”Route — before changing code
Section titled “Route — before changing code”spec query "renewal charge" . --jsonspec resolve src/billing/renew.ts . --jsonTag — while implementing
Section titled “Tag — while implementing”export function renew() { /* … */ } // @spec BILLING-009it("charges current price", () => {}) // @spec BILLING-009 unitCheck — before finishing
Section titled “Check — before finishing”echo | spec req bil # next unused BILLING idspec index . --jsonspec check . --ci --json # exit 1 → fix before PRspec guard . --json # exit 1 → this change deletes a live requirementPath rules for spec resolve
Section titled “Path rules for spec resolve”- Multi-repo platform: pass
<repo>/<path>— e.g.,spec resolve api/src/renew.ts . - Single-repo (rung-1): both repo-relative (
src/orders.ts) and basename-prefixed forms accepted - Absolute paths normalized against
platformDir; paths outside it exit 2
Gotchas
Section titled “Gotchas”fixtures/is globally ignored by the tag scanner — planted fixture tags are test data, not coverage claims- The DB owns nothing — never edit
.spec-engine/index.sqlite; edit the SPEC.json source and re-runspec index - Empty ≠ error — read commands exit 0 with
[]on stdout and guidance on stderr - Determinism is contractual — JSON outputs are deterministically sorted, byte-stable across runs