Skip to content

stats --json also prints the human table, so the output is not machine readable #14

Description

@royalpinto007

Problem

agentrace stats --json writes both a human table and the JSON to stdout:

console.print(table)

if args.json:
    print(json.dumps({...}))

So the actual output is a Rich-rendered table followed by a JSON object, on the same stream. agentrace stats --json | jq . fails. The CI smoke test does not catch this because it runs the command without piping it anywhere.

The wider version of the problem: --json exists only on stats. list, check, and show have no machine readable output at all. That is awkward for a tool whose README pitches check --strict as a CI gate, because the exit code is all a CI job can consume. You cannot post findings to a PR comment, write them to a report artifact, or filter them with jq.

Suggested approach

  1. Fix stats --json first: when --json is passed, either suppress the table entirely or send it to stderr. Suppressing is the more conventional choice for a data flag. Decide, and say which in --help.
  2. Promote --json to a top level flag on the parser rather than a per subcommand one, so agentrace --json check works uniformly.
  3. Define the JSON shape for each command and document it in the README, because once someone scripts against it, it is an interface:
    • list: an array of runs with id, description, duration, char counts, background, error.
    • check: an array of {run_id, description, findings: [{check, severity, message, evidence}]} plus a summary object. Finding is already a dataclass, so dataclasses.asdict covers most of it.
    • show: one run object including full prompt and result.
  4. Add a schema version field, for example "schema": 1, so the shape can change later without silently breaking whoever scripted against it.
  5. Add tests that each command's --json output parses cleanly with nothing else on stdout. That case is exactly what is broken today.

Done when

  • agentrace stats --json | jq . works.
  • Every command supports --json with a documented shape.
  • The README documents the schema.
  • Tests assert stdout is valid JSON and nothing else.

If you want to take this on, comment on the issue to claim it and it will be assigned. Please keep to a maximum of 2 open claims per person at a time so other contributors get a chance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions