feat: add --output-format json flag to goose run command#5525
feat: add --output-format json flag to goose run command#5525alexhancock merged 6 commits intoblock:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds JSON output format support to the Goose CLI, allowing users to receive structured JSON responses instead of text-based output. The feature is controlled via a new --output-format command-line argument that accepts either "text" (default) or "json" values.
Key changes:
- Added
output_formatfield to session configuration, builder, and CLI arguments - Introduced JSON data structures (
JsonOutput,JsonMessage,JsonToolCall,JsonToolResponse,JsonMetadata) for structured output - Modified message processing to capture and serialize messages, tool calls, and responses when JSON format is requested
- Suppressed text-based rendering when JSON output is active
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/goose-cli/src/session/mod.rs | Added JSON structs, output_format field to CliSession, and logic to collect/serialize session data as JSON |
| crates/goose-cli/src/session/builder.rs | Added output_format field to SessionBuilderConfig with default implementation, updated builder to pass format through |
| crates/goose-cli/src/cli.rs | Added --output-format CLI argument with default value "text" |
| crates/goose-cli/src/scenario_tests/scenario_runner.rs | Updated CliSession::new call to include default "text" output format |
| crates/goose-cli/src/commands/bench.rs | Updated SessionBuilderConfig to include default "text" output format |
Comments suppressed due to low confidence (1)
crates/goose-cli/src/session/mod.rs:1159
- Similar to Comment 6, this progress_bars.log call at line 1159 is not guarded by output_format check, potentially contaminating JSON output with text messages in non-JSON mode contexts.
progress_bars.log(&formatted_message);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
thanks for your contribution! please be sure to sign the DCO |
712537b to
1fad026
Compare
|
I've addressed all the Copilot AI suggestions from the recent code review. Happy to address any feedback. |
Thank you for reviewing and pointing this out. |
9abdac1 to
54f2414
Compare
Signed-off-by: sheikhlimon <sheikhlimon404@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: sheikhlimon <sheikhlimon404@gmail.com> Signed-off-by: Sheikh Limon <sheikhlimon404@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: sheikhlimon <sheikhlimon404@gmail.com> Signed-off-by: Sheikh Limon <sheikhlimon404@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: sheikhlimon <sheikhlimon404@gmail.com> Signed-off-by: Sheikh Limon <sheikhlimon404@gmail.com>
- Cache output_format check in process_agent_response to avoid repeated string comparisons - Prevent empty messages from being included in JSON output - Prevent MCP notification output leakage in JSON mode - Add documentation for manual Default implementation in SessionBuilderConfig - Fix test to include missing output_format field Signed-off-by: sheikhlimon <sheikhlimon404@gmail.com> Signed-off-by: Sheikh Limon <sheikhlimon404@gmail.com>
f96fe46 to
d923b5c
Compare
|
Working nicely for me! |
|
Getting a clippy error in |
- Remove separate JsonMessage, JsonToolCall, and JsonToolResponse structs - Use Vec<Message> directly in JsonOutput to preserve MessageContent structure - Fix conflict markers left from rebase in scenario_runner.rs and builder.rs Signed-off-by: sheikhlimon <sheikhlimon404@gmail.com>
cb211fd to
df3aae7
Compare
|
@sheikhlimon yeah those resolutions seem fine |
@alexhancock ok.. do i create an issue for this or are you aware already? this could be created by running |
|
@sheikhlimon we'll deal with the other computercontroller thing |
|
thanks! |
…est-and-fix * 'main' of github.com:block/goose: improve linux tray icon support (#5425) feat: log rotation (#5561) use app.isPackaged instead of checking for node env development (#5465) disable RPM build-ID generation to prevent package conflicts (#5563) Add Diagnostics Info to Q&A and Bug Report Templates (#5565) fix: improve server error messages to include HTTP status code (#5532) improvement: add useful error message when attempting to use unauthenticated cursor-agent (#5300) fix: unblock acp via databricks (#5562) feat: add --output-format json flag to goose run command (#5525)
* main: (85 commits) improve linux tray icon support (#5425) feat: log rotation (#5561) use app.isPackaged instead of checking for node env development (#5465) disable RPM build-ID generation to prevent package conflicts (#5563) Add Diagnostics Info to Q&A and Bug Report Templates (#5565) fix: improve server error messages to include HTTP status code (#5532) improvement: add useful error message when attempting to use unauthenticated cursor-agent (#5300) fix: unblock acp via databricks (#5562) feat: add --output-format json flag to goose run command (#5525) Sessions required (#5548) feat: add grouped extension loading notification (#5529) we should run this on main and also test open models at least via ope… (#5556) info: print location of sessions.db via goose info (#5557) chore: remove yarn usage from documentation (#5555) cli: adjust default theme to address #1905 (#5552) Manual compaction counting fix + cli cleanup (#5480) chore(deps): bump prismjs and react-syntax-highlighter in /ui/desktop (#5549) fix: remove qwen3-coder from provider/mcp smoke tests (#5551) fix: do not build unsigned desktop app bundles on every PR in ci. add manual option. (#5550) fix: update Husky prepare script to v9 format (#5522) ...
* main: (54 commits) add clippy warning for string_slice (#5422) improve linux tray icon support (#5425) feat: log rotation (#5561) use app.isPackaged instead of checking for node env development (#5465) disable RPM build-ID generation to prevent package conflicts (#5563) Add Diagnostics Info to Q&A and Bug Report Templates (#5565) fix: improve server error messages to include HTTP status code (#5532) improvement: add useful error message when attempting to use unauthenticated cursor-agent (#5300) fix: unblock acp via databricks (#5562) feat: add --output-format json flag to goose run command (#5525) Sessions required (#5548) feat: add grouped extension loading notification (#5529) we should run this on main and also test open models at least via ope… (#5556) info: print location of sessions.db via goose info (#5557) chore: remove yarn usage from documentation (#5555) cli: adjust default theme to address #1905 (#5552) Manual compaction counting fix + cli cleanup (#5480) chore(deps): bump prismjs and react-syntax-highlighter in /ui/desktop (#5549) fix: remove qwen3-coder from provider/mcp smoke tests (#5551) fix: do not build unsigned desktop app bundles on every PR in ci. add manual option. (#5550) ...
Signed-off-by: sheikhlimon <sheikhlimon404@gmail.com> Signed-off-by: Sheikh Limon <sheikhlimon404@gmail.com> Signed-off-by: fbalicchia <fbalicchia@gmail.com>
Signed-off-by: sheikhlimon <sheikhlimon404@gmail.com> Signed-off-by: Sheikh Limon <sheikhlimon404@gmail.com> Signed-off-by: Blair Allan <Blairallan@icloud.com>
Summary
This pull request implements the requested
--output-format jsonflag for the goose run command, enabling structured JSON output for programmatic parsing. The feature allows users to parse tool calls and responses programmatically, similar to Claude Code's--output-format jsonfunctionality.Key changes:
--output-formatflag with default value "text" (preserving backward compatibility)Type of Change
Testing
goose run --text "..." --output-format jsonand confirming structured JSON outputgoose run --text "..." --output-format textand default behavior to ensure existing functionality preserved--helpoutput and accepts valid valuescargo buildandcargo checkThe changes have been manually validated to work as specified in the feature request while maintaining all existing functionality.
Related Issues
Relates to #4419