Structured output & CLI API hardening (output + errors + --describe)

Open
#2,622 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust
Domain
api, cli

Research direction

Start by reading the existing OutputFormat patterns in events.rs, fee_stats.rs, ledger/fetch.rs, and print.rs. Trace how command specs feed the parser and help output, then define the scope for structured envelopes, error metadata, and --describe. Done means the listed example envelopes reproduce, --describe emits args/output/errors[]/examples, and commands produce parseable JSON under output=json.

Written by the indexing model from the issue text.

Description

Part of the Improve Agent UX for Wallets epic.

Summary

Harden the CLI API so an agent/human can parse any command's result and chain commands together without scraping plain text. Three facets, tracked as one task: a global structured-output flag, a structured error catalog, and a --describe machine-readable schema.

1. Structured output

New global flag:

output=json|default
  • default — today's default (plain text for most commands, a few existing JSON exceptions).
  • json — an object with predictable keys representing the same data plus enriched output in some cases (e.g. errors paired with a resolution).

Example (ok):

{ "status": "ok", "result": "9999999500", "error": null }

Example (error):

{
  "status": "error",
  "result": null,
  "error": {
    "code": "tx_simulation_failed",
    "domain": "tx",
    "message": "host invocation failed: Error(Contract, #2)",
    "details": {
      "contract_id": "C...",
      "error_code": 2,
      "error_name": "InsufficientBalance",
      "diagnostic_events": ["..."]
    }
  }
}

2. Structured errors

commands return an object with a consistent set of keys.
errors add context along with raw error details to aid users/agents towards remediation of the error.

3. --describe

A projection of the command spec: a machine-readable schema for a command or the tree (args, output schema, errors[], examples). Backed by a command-spec source file feeding the parser / --help / --describe generator.

Build on existing OutputFormat patterns (events.rs, fee_stats.rs, ledger/fetch.rs) and print.rs.

Acceptance criteria

  • The spec's example envelopes (ok-result and error-with-remediation) reproduce.
  • --describe emits args / output / errors[] / examples.
  • commands emit parseable JSON under output=json.
Dominant language
Rust
Stars
123
Forks
141
Avg merge
2d 21h
Merged PRs (30d)
17

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stellar/stellar-cli

All issues in stellar/stellar-cli

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.