Summary
Give the CLI a stable machine-readable failure surface: an exit-code map (0 ok · 1 usage · 2 no-app · 3 auth-required · 4 unreachable · 5 tool-error) and a one-line JSON ErrorEnvelope ({"error":{code,message,cause,status,url}}) on stderr for every non-zero exit.
Why
A programmatic driver (CI, scripts, agents) needs to branch on why the CLI failed without scraping prose stderr. This is the foundation for the whole CLI lane of the PR #1510 decomposition — --app-info (exit 2), stored-auth (exit 3), and --format json all build on it.
Reference implementation (PR #1510)
Re-implement informed by these changes at 33fac3f:
Depends on
Nothing — Wave 1 foundation, parallel-safe. Blocks the CLI ergonomics, --app-info/--format json, and stored-auth issues.
Notes
classifyError() should be pure and unit-testable; tests mock process.stderr.write for isolation.
- Document the exit-code map in
clients/cli/README.md (AGENTS.md docs rule).
- Coverage gate ≥90 on all four dimensions.
Part of the PR #1510 decomposition (see tracking issue).
Summary
Give the CLI a stable machine-readable failure surface: an exit-code map (
0ok ·1usage ·2no-app ·3auth-required ·4unreachable ·5tool-error) and a one-line JSONErrorEnvelope({"error":{code,message,cause,status,url}}) on stderr for every non-zero exit.Why
A programmatic driver (CI, scripts, agents) needs to branch on why the CLI failed without scraping prose stderr. This is the foundation for the whole CLI lane of the PR #1510 decomposition —
--app-info(exit 2), stored-auth (exit 3), and--format jsonall build on it.Reference implementation (PR #1510)
Re-implement informed by these changes at
33fac3f:EXIT_CODES,ErrorEnvelope,CliExitCodeError,classifyError(),formatErrorOutput(), refactoredhandleError()(+200/−14)Depends on
Nothing — Wave 1 foundation, parallel-safe. Blocks the CLI ergonomics,
--app-info/--format json, and stored-auth issues.Notes
classifyError()should be pure and unit-testable; tests mockprocess.stderr.writefor isolation.clients/cli/README.md(AGENTS.md docs rule).Part of the PR #1510 decomposition (see tracking issue).