-
Notifications
You must be signed in to change notification settings - Fork 976
feat: add print mode flag to run command #533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
monotykamary
wants to merge
11
commits into
sst:dev
Choose a base branch
from
monotykamary:feat/print-mode-flag
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add -p/--print flag to run command with multiple output formats: - text (default): simple text output - json: structured JSON with metadata - stream-json: multiple JSON objects (requires --verbose) Includes validation, error handling, and maintains backward compatibility with existing run command behavior. Closes sst#278 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <[email protected]>
Replace static hard-coded arrays and strings in print mode with dynamic functions that reflect actual runtime configuration for tools, MCP servers, and API key sources. 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <[email protected]>
- Use existing TOOL mapping for consistent display names instead of custom switch statement - Add missing tools to TOOL mapping: webfetch, lsp_diagnostics, lsp_hover, patch - Simplify getAvailableTools function to leverage existing infrastructure - Ensure all tools have proper display names in print mode output 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <[email protected]>
Replace generic "Todo" display name with specific "TodoWrite" and "TodoRead" to clearly differentiate between the two todo-related tools in print mode output. 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <[email protected]>
- Create STREAM_TOOL_NAMES mapping for descriptive tool names in stream-json - Keep existing TOOL mapping short for interactive UI space constraints - Distinguish TodoWrite/TodoRead in stream-json while keeping "Todo" for UI - Shorten some UI tool names: WebFetch->Fetch, LSP tools->LSP - Maintain "List" as original for both UI and stream-json consistency 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <[email protected]>
Fixes issue where -p flag output was missing trailing newline character, causing shell to display % symbol indicating incomplete output. 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <[email protected]>
+1 for this! |
Resolved conflict in run.ts by keeping both print mode options and mode option from dev branch. 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
-p/--print
flag to therun
command that enables print mode with multiple output formats, solving the feature request in #278. The implementation uses dynamic data sources to accurately reflect the actual runtime configuration.Changes
-p/--print
flag torun
commandtext
(default),json
, andstream-json
formatsstream-json
format requires--verbose
flagrun
command behavior is unchangedUsage Examples
Text Output (Default)
$ opencode run -p "what is 2+2?" 4
JSON Output
Stream JSON Output (with verbose)
Validation & Error Handling
Stream-JSON requires verbose flag
$ opencode run -p --output-format stream-json "test" Error: When using --print, --output-format=stream-json requires --verbose
Empty message validation
Features
Multiple Output Formats:
text
: Simple text output (default)json
: Structured JSON with session metadata, timing, costs, and token usagestream-json
: Multiple JSON objects including system init, assistant message, and final resultDynamic Runtime Data: System init output reflects actual configuration:
Provider.tools()
and active MCP toolsMCP.clients()
Comprehensive Metadata: JSON formats include:
Validation:
stream-json
format requires--verbose
flagBackward Compatibility: Normal
run
command behavior is completely unchangedImplementation Details
RunCommand
rather than creating a separate commandrun
command functionality (continue, session, share, model options)Testing
All output formats and validation scenarios have been tested:
Closes #278
🤖 Generated with opencode