JSON output, exit origin, and script rules
On this page
--json turns a command's human report into a machine document. Use it for
anything automated: human wording can change in any release, while the JSON
contract is the one this help and the command reference describe for your
installed version. Before 1.0 that contract is not frozen, but an incompatible
change is an explicit decision, disclosed in the release notes and here, such as
the null unknowns under run explain below. A new field can appear without a
schema change, so ignore keys you do not know.
The envelope
Every JSON payload is wrapped the same way:
{ "schema_version": 1, "command": "<name>", "data": { ... } }
<name> is the command that produced it (status, changes, run.show, ...).
The envelope's schema_version versions the envelope itself. Provider contracts
carried inside data — awa-state/v1 for resolved state, awa-evidence/v1 for
run evidence — are versioned independently and appear as their own
provider_contract fields. A payload transition need not change either: the
explain unknowns below kept schema_version 1.
Payload goes to stdout. Diagnostics, notes, hints, and errors go to stderr, so a script can capture stdout alone and get only the document.
Which commands accept --json
Global options are honored per command, not universally: a command that does not
act on --json rejects it as a usage error rather than accepting and ignoring
it. The exhaustive list is in global options and
the per-command pages under commands.
One case worth stating: awa docs export has no --json. The export writes its
own machine contract, manifest.json, into the output directory.
Rules for scripts
Four rules make the difference between a robust consumer and one that occasionally believes a truncated document:
- Parse stdout only after the process exits. Streamed payloads are written as they are produced.
- A non-zero exit does not mean the document is invalid. For
awa runthe exit code is usually the wrapped command's own; the envelope is still one complete document. - Treat a
partial output:line on stderr as fatal for the document. It means the report failed part-way through. - Never salvage a partial document. Discard stdout and re-run; do not reconstruct the missing tail or parse the fragment that arrived.
Streaming surfaces such as awa changes --json and awa diff --json emit their
entries incrementally, so a mid-stream failure leaves the document deliberately
unterminated — it cannot parse as complete, which is the intended signal, paired
with the partial output: diagnostic and a non-zero exit.
Before their array they carry basis: token (observation-delta) and
scan_config with each side's recorded identity and agreement (match or
mismatch). A mismatch is not a failure, and a match is not proof of equal
ignore rules or scope — see awa help diff.
Each added/deleted element adds counterpart: side (left for added,
right for deleted) and qualification — absent, outside-observation,
skipped-boundary or unknown. It describes that side's recorded coverage,
not a creation or deletion, and is no provider verdict or restore permission.
After the array, scope carries ignore_sources: the ignore-source categories
enabled in the configuration this invocation loaded, as
ignore_sources_basis: "current-configuration" states. It is not a list of
ignore files read or rules matched on either side.
ignore_source_participation is unknown for left and right: no compared
observation records which sources took part, and unknown is not "none".
skipped_in_scope counts the skipped entries of this delta, not every skipped
input of either side.
Exit origin
awa run returns the wrapped command's own exit code, and that code can overlap
awa's own codes in the range 1–6. $? alone therefore cannot tell you who
failed.
The run envelope answers it explicitly: data.run.exit_origin is child,
alongside data.run.exit_code and data.run.signal. An awa-origin failure —
invalid configuration, a corrupt store, a lock timeout — is reported through the
error path with an awa exit code and never as a run envelope, so the presence of
the envelope is itself part of the classification. See
awa help exit-codes.
Human output modes are not JSON modes
--stat, --name-only, --oneline, and --time shape human output. Combining
any of them with --json is a usage error (exit 2) rather than a silent no-op,
because the JSON already carries the underlying facts. Timestamps in JSON are
always UTC RFC3339 regardless of the configured display mode.
Bounded and degraded results are labelled
A payload never quietly shrinks. Where a list is capped, the document carries a
completeness fact next to it — complete, shown, limit, and a reason —
for example candidates_bounded on awa gc --json, while the summary still
reports full totals. A capped list never changes what the summary says about
measurement either: bytes_planned_complete and bytes_deleted_complete state
whether those byte totals are exact or lower bounds, independently of
candidates_bounded and store_footprint.complete. A failed deletion is credited
0 bytes, so it makes bytes_deleted_complete false; it is still reported in
failures on its own. Each candidate's bytes_measurement is exact, partial,
or unmeasured. awa doctor --json reports the size of .awa/ in
store_capacity: measurement is exact, partial, unmeasured, or
disabled; observed_bytes is a number only for exact or partial (then a
lower bound) and threshold_bytes only while the advisory is enabled, otherwise
both are null; incomplete_reasons lists closed tokens such as work-budget.
watched_root_capacity is null unless --capacity ran; then search.complete,
each root's measurement, and roots_detail report search, sizing, and listing
coverage separately, and roots_total is null when the search was incomplete.
Similar fields elsewhere state whether a set of paths is complete, truncated, or
unavailable.
Degraded evidence is reported as a complete assessment rather than as an error:
awa state resolve, awa state compare, and awa run show --json exit 0 and
name the situation with a closed reason token (for example not-initialized,
not-found, ambiguous-reference, permission-denied). A degradation is always
named that way rather than left for you to infer from what is missing.
awa run explain --json states what it established about the current key's
entry in exact_match.assessment. complete means the lookup succeeded:
exists is false when no entry exists (then healthy is false too), or
true with its run_id and a boolean healthy. lookup-unavailable means the
entry could not be read, so exists and healthy are null: unknown, not
absent. health-unavailable keeps exists: true and the run_id, with
healthy: null: its stored output could not be verified, which is not the same
as unhealthy. When --no-cache, --refresh, or another policy already decides
the outcome, an unreadable entry keeps that outcome and reason, adds a
warning, and exits 0. A reader that decodes null as false misreads unknown
as absent or unhealthy.
An approved identity probe reports only during awa run, so diagnostics may lack
the current key. Explain then has current.assessment: "identity-unavailable"
(else complete), current.key: null, current.cacheable: null unless a policy
already proves false, and exact_match.assessment: "current-identity-unavailable" with exists and healthy null: nothing was
looked up. Unless --refresh or a policy decides, the outcome is incomplete
with reason external-facts-unacquired, exit 0. A candidate it disproves keeps
its reason without a score; that is not a miss. run ls --json adds
assessment (complete or incomplete) and an unassessed array of such rows
(id, command, cwd, recorded key, reason), never also in reusable or
near_misses. status --json marks review.runs.assessment as complete,
incomplete, or unavailable when the run listing failed (then see its
warning). When incomplete, review.runs.reusable and near are null;
known_reusable, known_near and unassessed count what was established, and
nearest is from the assessed rows. Read null as unknown, never as 0.
When a [[run.required_env]] declaration selects the command, explain adds
current.environment_requirement (declaration, origin, argv, cwd,
satisfied, and names with state set, unset or empty; never values).
Unsatisfied, the outcome is refused with reason env-requirement-unmet, exit
0: current.key is null, current.cacheable is false, and
exact_match.assessment is current-identity-unavailable (nothing looked up).
run ls keeps such a row assessed, not reusable with that reason. awa run --json instead exits 1 with empty stdout.
Optional keys, on the other hand, are omitted when they have no value: a
checkpoint with no message carries no message key, a run with capture disabled
carries no outputs block, and a binary with no VCS stamping carries no
revision. Read anything a document is not obliged to carry with a
present-or-default access rather than a direct index. What a version guarantees
is the envelope plus the keys a document always carries — awa run ls --json
always has its diagnostics.performance array, empty when nothing crossed the
latency threshold, so machine-readable latency facts never live only on stderr.
Reading the run audit
awa run audit --json (run.audit) counts retained recorded executions, not
invocations: a replayed hit leaves no record, so the document has no hit rate.
Its facts are separate, and an unknown total is never written as zero:
window—requested,selected, andmax;olderispresentwhen retained runs exist beyond the window, elsenone;coverageisnewest-window,all-retained, ornone;historyispresent,empty(history exists with no runs), ormissing(no run history exists in this store).reads—classifiedandunavailablesum toselected;completeis false when any selected run went unread.availabilitynames why, per state:corrupt,incompatible,vanished,unreadable,over-record-budget, orunread-budgetwhen the total byte budget ran out. A budget refusal is not corruption; the run stays readable elsewhere.classifications— one entry per storedkind/reasonwith itsgroup:reusable-when-stored,deliberate-recording,policy-blocker,changed-state,observation-unavailable, orfailure-cache-policy. Each run counts once, by its primary stored reason only;reusable-when-storedis history, not a claim that the run is reusable now.examples— at most a few fullrun_ids, with aboundedcompleteness fact separate from the exactcount.suggestions— typed{kind, reason, argv, display}drilldowns; useargv.
How to read and act on the audit is in awa help maintenance; the stored reason tokens are in awa help run.