P2: Structured, Parseable Output

Definition

CLI tools MUST separate data from diagnostics and offer machine-readable output formats. Mixing status messages with data forces agents into fragile regex extraction that breaks on any format change.

Why Agents Need It

An agent calling a CLI needs three things from each invocation: the data, the error (if any), and the exit code. When data goes to stdout, diagnostics go to stderr, and errors carry machine-readable fields, the agent parses the result reliably without heuristics. Mix these channels or ship human-formatted output only, and the agent falls back to best-effort text parsing that fails unpredictably across versions, locales, and edge cases: silently at first, catastrophically later.

Requirements

Code Meaning
0 Success
1 General command error
2 Usage error (bad arguments)
77 Authentication / permission error
78 Configuration error

Evidence

Rust reference implementation:

Anti-Patterns

Measured by audit IDs p2-output-json, p2-output-format, p2-stderr-diagnostics. Run anc audit --principle 2 . against the CLI under test to see each.