Expand description
roba’s stable machine contract, as a dependency-light library.
roba is meant to be consumed as a subprocess whose --json output and
exit code are a stable ABI. This crate is that ABI, extracted so a
downstream harness can deserialize against it and branch on the exit code
without depending on the whole roba binary (tokio, clap, termimad, …).
Two pieces:
- Exit codes (
EXIT_FAILURE..EXIT_MAX_BUDGET) – the full map the binary returns. Therobabinary references these same constants, so the crate and the binary cannot disagree. --jsonenvelopes (SuccessEnvelope,VersionedResult,ErrorEnvelope) – the uniform{ version, result[, refusal] }/{ version, error }shapes. Each is generic over the payload and derives bothSerialize(roba serializes a borrow, no clone) andDeserialize(a consumer deserializes owned), so there is one type per shape and no drift between producer and consumer.
The result payload is claude’s own QueryResult, re-exported here. This
crate pulls claude-wrapper with default-features = false, features = ["json"], so it carries serde but no async runtime.
Structs§
- Error
Body - The failure detail inside an
ErrorEnvelope. - Error
Envelope - The
--jsonfailure envelope, emitted on stderr:{ version, error }. - Query
Result - claude’s result payload – the shape inside a success envelope’s
result. Re-exported (not mirrored) so it cannot drift from claude’s contract. Result from a query with--output-format json. - Success
Envelope - The
--jsonsuccess envelope for a prompt run:{ version, result, refusal }.resultholds aQueryResult;refusalis true when the response looked like a refusal, so a consumer can branch on “got an answer” vs “got refused” without parsing the body. - Versioned
Result - The
--jsonsuccess envelope for the read-only management commands (cost,history,last,doctor,worktree list, …):{ version, result }, without the prompt-run-onlyrefusalflag. Generic over the payloadT, which differs per command.
Constants§
- EXIT_
AUTH - Authentication failure (
claudeis not logged in / the key is bad). - EXIT_
BUDGET - The wrapper’s own
BudgetTrackerceiling was hit (distinct from claude’s--max-budget-usdCLI cap, which isEXIT_MAX_BUDGET). - EXIT_
FAILURE - Generic failure – a
clauderun failed for a reason with no more specific code, or roba itself errored. - EXIT_
MAX_ BUDGET - The
--max-budget-usdCLI spend cap was hit. Recoverable, likeEXIT_MAX_TURNS: a guardrail tripped mid-run, not a defect. - EXIT_
MAX_ TURNS - The
--max-turnscap was hit. Recoverable: the run is usually complete and just needs its lifecycle finished (gates + commit), so a caller can tell this apart from a hard failure and resume. - EXIT_
TIMEOUT - The run exceeded its wall-clock
--timeout. - EXIT_
UNUSABLE_ RESULT - A run produced no usable result (empty /
is_error). Emitted by the binary directly (never as an error envelope); the reliable machine signal is this code, not stderr. - VERSION
- The current
--jsonABI version. Every envelope carries it as the first field a consumer should check before inspecting anything else.