Skip to content

CLI --json flag is ignored by most subcommands; output mode still tied to cli.mode=agent #126

@RandomOscillations

Description

@RandomOscillations

Summary

The global --json flag is advertised at root (extropy --help) and in docs as a per-command machine-output override, but most command handlers ignore it and only honor cli.mode=agent.

Repro

  1. Set human mode:
extropy config set cli.mode human
  1. Run inside a valid study:
cd examples/study-02
extropy --json results summary
  1. Observe output is human-formatted text, not JSON.

Additional behavior:

  • extropy results --json fails with No such option: --json (Click/Typer global option placement behavior).
  • Some error paths (e.g., outside-study DB resolution in query) print rich text errors even when --json is passed.

Expected

  • --json should force JSON output regardless of cli.mode.
  • Error paths should also return structured JSON in JSON mode.
  • Docs/UX should clearly reflect whether --json must be root-level (extropy --json <cmd>) or accepted on subcommands.

Likely Root Cause

Most command modules derive output mode via is_agent_mode() only, instead of get_json_mode() or is_agent_mode().

Observed references:

  • extropy/cli/commands/{results,query,sample,network,scenario,persona,spec,simulate,chat}.py
  • extropy/cli/commands/validate.py already uses helper logic combining both modes.

Suggested Fix

  1. Introduce common helper (e.g. _json_enabled()) in CLI layer: get_json_mode() or is_agent_mode().
  2. Replace command-local agent_mode = is_agent_mode() with helper.
  3. Route early resolver failures (study detection, etc.) through Output in JSON mode.
  4. Add regression tests:
    • cli.mode=human + root --json returns JSON for representative commands.
    • outside-study errors return JSON when --json passed.
  5. Update docs to clarify root option placement (extropy --json <command>) and/or add per-command passthrough if desired.

Severity

Medium-high (automation contract regression). Not simulation-core blocking, but breaks non-interactive pipelines that depend on explicit --json overrides.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions