Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @jerop, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly enhances the CLI's utility for developers and automators by introducing a structured JSON output option. This change allows for seamless integration of the CLI's responses into scripts and other applications, moving beyond human-readable text to provide a consistent, machine-parseable data format for all interactions, including detailed operational metrics and error states.
Highlights
- New JSON Output Flag: Introduces a new
--output-format jsonflag to the CLI, enabling machine-readable JSON output for scripting and automation. - Structured Output Content: The JSON output includes the model's response, session statistics (e.g., token usage, tool calls), and detailed error information, providing comprehensive data for programmatic use.
- Enhanced Error Handling: Centralized error handling has been implemented to consistently format and output errors in JSON format when the
--output-format jsonflag is active, including general errors, tool execution errors, and cancellation events. - Configuration and Documentation Updates: The new output format can be configured via settings (
output.format) and is documented in the CLI configuration and main README, with examples for both text and JSON output. - New JSON Formatter and Tests: A new
JsonFormatterclass has been added to handle the serialization of responses, statistics, and errors into JSON, accompanied by dedicated integration and unit tests to ensure correctness and robustness.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This PR introduces a new --output-format json flag to the CLI, which is a valuable addition for scripting and automation. The implementation is well-structured, with a new JsonFormatter, dedicated error handling for JSON output, and comprehensive tests and documentation updates. My review focuses on ensuring the new functionality is robust for scripting use cases. I've identified a couple of high-severity issues: the integration tests use an incorrect flag, and the non-interactive mode doesn't consistently produce JSON output on success. I've provided suggestions to fix these. Overall, this is a great enhancement to the CLI.
341534a to
a8a9d34
Compare
|
Size Change: +5.97 kB (+0.05%) Total Size: 13.2 MB
ℹ️ View Unchanged
|
a8a9d34 to
f12238e
Compare
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
cf7f2b1 to
7097def
Compare
0dd3520 to
7b99a39
Compare
ca007b3 to
61be87c
Compare
61be87c to
454d31d
Compare
This change introduces a new `--output-format json` flag to the CLI, which allows users to get a machine-readable JSON output. This is particularly useful for scripting and automation.
When the `--output-format json` flag is used, the CLI will output a JSON object containing the model's response, session statistics, and any errors that occurred.
**Example:**
```bash
gemini -p "What is fine tuning?" --output-format json
```
**Output:**
```json
{
"response": "Fine tuning is...",
"stats": {
"models": {
"gemini-2.5-flash": {
"tokens": {
"total": 45
}
}
}
},
"error": null
}
```
This change also includes:
- A new `JsonFormatter` class to format the output as JSON.
- Updated documentation and integration tests.
- Updates to the non-interactive mode to support the JSON output format.
454d31d to
528303c
Compare
|
There is no |
This PR introduces a new
--output-format jsonflag to the CLI, which allows users to get a machine-readable JSON output. This is particularly useful for scripting and automation.When the
--output-format jsonflag is used, the CLI will output a JSON object containing the model's response, session statistics, and any errors that occurred.Example:
gemini -p "What is fine tuning?" --output-format jsonOutput:
{ "response": "Fine tuning is...", "stats": { "models": { "gemini-2.5-flash": { "tokens": { "total": 45 } } } }, "error": null }This PR also includes:
JsonFormatterclass to format the output as JSON.Fixes #8022