JSON contract

Every verb — capabilities included — emits the same envelope. Pass --json to get it. --json is the only machine selector: without it rf prints the human summary, also when the output goes to a pipe. The flag is accepted before or after the verb.

The seven keys

{
  "ok": true,
  "tool_version": "0.1.2",
  "data": { "items": [], "total": 0 },
  "meta": {},
  "warnings": [],
  "commands": [],
  "errors": []
}
Key Type Meaning
ok bool Did the operation succeed? true only for exit 0.
tool_version string The rf version that produced the envelope.
data object | null The result. List verbs (content, find) put rows in data.items and the count in data.total; no results is items: []. Other verbs put their fields directly in data. null when the call failed before it had a result.
meta object Request metadata — see below.
warnings array One entry per recovered miss or coverage note: { code, message, details }. For a miss, details.files lists the paths; otherwise details is null.
commands array Paste-ready shell commands that reproduce each recovery, so any result can be confirmed independently.
errors array One entry per error: { code, message, exit_code, remediation, arg, details, did_you_mean, path }. A key with no value is null. Empty when ok is true.

Every declared key is always present. A key with no value is null; it is never absent.

The meta block

"meta": {
  "verb": "content",
  "request_id": "req_cd35511094644afd",
  "ts_iso": "1970-01-01T00:00:00Z",
  "contract_version": "0.1",
  "data_hash": "sha256:b3841ec1…",
  "elapsed_ms": 0
}
  • contract_version — the value to branch on. It is currently "0.1", a major.minor JSON string in both meta and the capabilities contract’s data.contract_version. Compare it as a string. Before 1.0, a minor bump can be a breaking change.
  • verb — the verb that ran. It is null when the call failed before rf resolved a verb.
  • request_id — req_ plus 16 hex digits, unique for each invocation. Use it to correlate logs, not to compare results.
  • data_hash — sha256: plus the SHA-256 of data as compact JSON with sorted keys. The same data always gives the same hash.
  • ts_iso and elapsed_ms — the clock. SOURCE_DATE_EPOCH sets ts_iso and makes elapsed_ms 0.
  • Verbs add their own fields to meta. content and find add counts, query (the active match mode), pagination, and evidence.

data shapes

  • content rows are { file, file_bytes_hex, surfaced_by, matches, selection }; see content.
  • find rows are { file, file_bytes_hex, stage, fix, matches, matches_unavailable_reason }; see find.
  • why and doctor return one object in data; see why and doctor.
  • capabilities returns the whole contract as data.

file is the path as text. A name that is not valid UTF-8 is shown lossy in file, and file_bytes_hex holds its exact bytes in lowercase hex. For a UTF-8 name, file_bytes_hex is null. Use file_bytes_hex when it is not null: two rows can have the same file text but different bytes. --paths-envelope reads it the same way.

Each verb’s output_schema in rf capabilities --json is a JSON Schema for its data and meta.

Paging

content and find return at most 100 rows by default. --limit accepts 1 to 1000. When meta.pagination.has_more is true, send meta.pagination.cursor back with --cursor to get the next page. If the result set changed after the first page, the call exits 5 with CONFLICT; start the query again without the cursor.

Errors

{
  "arg": "pattern",
  "code": "MISSING_REQUIRED",
  "details": null,
  "did_you_mean": null,
  "exit_code": 1,
  "message": "content requires <pattern>",
  "path": null,
  "remediation": "Add the <pattern> argument."
}

data is null when the call failed before it had a result. A verb that ran and found a fault (exit 6) keeps its data and also fills errors. See Exit codes.

Determinism

With a fixed SOURCE_DATE_EPOCH and the same inputs, two runs give the same envelope except for meta.request_id. To compare two runs, compare meta.data_hash, or remove request_id first:

SOURCE_DATE_EPOCH=0 rf content token . --json | jq -cS 'del(.meta.request_id)' | sha256sum
SOURCE_DATE_EPOCH=0 rf content token . --json | jq -cS 'del(.meta.request_id)' | sha256sum   # same hash

rf output has no terminal decoration, so NO_COLOR and --no-color are accepted and have no effect. The authoritative, machine-readable version of everything on this page is rf capabilities --json.