Skip to content

cli: exit-code map + structured JSON error envelopes #1564

Description

@cliffhall

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).

Metadata

Metadata

Assignees

Labels

v2Issues and PRs for v2

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions