Agent guide

rf is built to be driven by programs, not only read by people. Three properties make it safe to script.

1. Learn the surface once

rf capabilities --json emits the full machine contract: every verb, flag, exit code, error code, warning code, and output schema. An agent reads it once and never has to discover behavior by trial and error.

rf capabilities --json

Do not hardcode the surface. Read it, and branch on the contract_version in meta (currently "0.1", a string). Before 1.0, a minor bump can break.

The verbs are content, find, why, doctor, conformance, capabilities, robot-docs, and help. rf robot-docs guide prints ready-to-run workflow recipes.

Always pass --json. Without it rf prints the human summary, also to a pipe.

2. Trust the exit codes

Exit Meaning What to do
0 Success, including empty results (data.items is []) Continue
1 User-input error (bad flag, absent argument, bad regex, path not found) Fix the call
3 Tool-environment error (unreadable path, absent program, failed history scan) Fix the environment
5 Conflict: the result set changed after an earlier page Start the query again without the cursor
6 Findings present: doctor or conformance found a fault Read errors; data holds the report
7 Internal defect in rf Report it

“No matches” is exit 0, never an error. Do not treat an empty result as a failure. The full dictionary, with the signal exits, is in Exit codes.

3. Parse one envelope

Every verb — capabilities included — emits the same JSON envelope. Read ok and data; read warnings to learn what a naive search would have missed; read commands for the paste-ready invocations that reproduce each recovery. See the JSON contract.

rf content DB_DSN . --json | jq '.data.items[] | select(.surfaced_by != "default")'

To see where in each file the pattern occurs, add --matches. Each row then carries up to 16 occurrences as { line, column_byte, text }.

To ask about one file, use why:

rf why DB_DSN config/prod.env --json | jq '.data | {matched, surfaced_by, ignore_source}'

Results are comparable

rf honors SOURCE_DATE_EPOCH, and meta.data_hash is the SHA-256 of data. With a fixed epoch and the same inputs, two runs differ only in meta.request_id, which is unique for each invocation. For a golden test, compare data_hash or remove request_id:

SOURCE_DATE_EPOCH=0 rf content DB_DSN . --json | jq -S 'del(.meta.request_id)' > a.json
SOURCE_DATE_EPOCH=0 rf content DB_DSN . --json | jq -S 'del(.meta.request_id)' > b.json
diff a.json b.json && echo identical

Internal defects are typed

A defect in rf is caught by the totality wrapper and returned as an error envelope with code INTERNAL and exit 7. An absent git degrades find to a warning (GIT_ABSENT). find --structural without ast-grep exits 3.

Self-check in place

rf conformance --json runs the release self-check profile against the running binary. data holds profile, counts (pass, fail, not_applicable), and one verdict for each case in cases. Exit 0 means no case failed. Exit 6 means one or more cases failed; errors has one CASE_FAILED entry for each. Use it as a smoke test after install or in CI.

rf doctor --json checks the environment the same way: exit 6 when git or ast-grep is absent or does not run. See doctor.