feat(cli): add --output-format json to wrap single-query agent output#543
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new --output-format option to the CLI, allowing users to format the single-query agent response as either plain text (table) or structured JSON (json). This change is supported by new type definitions, constants, and unit tests. The feedback suggests a minor improvement to use ensure_ascii=False when serializing the JSON output to prevent escaping non-ASCII characters, which enhances CLI usability for international users.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Greptile SummaryThis PR adds JSON output for single-query agent runs. The main changes are:
Confidence Score: 5/5The change is narrowly scoped to CLI output formatting and includes coverage for the supported and unsupported command combinations. The implementation appears straightforward, preserves the default text behavior, and tests cover JSON wrapping, Unicode content, and invalid usage.
What T-Rex did
Reviews (2): Last reviewed commit: "fix(cli): reject --output-format json wi..." | Re-trigger Greptile |
|
@greptile review |
Closes #250 (reframed scope).
What
Adds a
--output-format table|jsonoption to thestartcommand's single-query path (-a/--ask-agent). Defaulttablekeeps the current plain-text behavior;jsonwraps the agent answer so it can be piped intojq:Logs already go to stderr, so stdout stays clean for scripting.
Why this scope
The original issue asked for row-structured
{query, results[], count}JSON. cgr's query path is agentic (an LLM RAG agent returns free-form text), not a row query engine, so row-shaped results don't map onto the architecture. Export to JSON already exists (cgr export). The achievable, useful piece is wrapping the single-query answer as JSON, mirroring the existingdead-code --format table|jsonprecedent.Changes
constants.py:QueryFormatStrEnum +KEY_QUERY/KEY_RESPONSEtypes_defs.py:QueryJsonOutputTypedDictcli_help.py: help text for the new optionmain.py:main_single_queryemits JSON when requestedcli.py:--output-formatoption onstart