fix(cli): Prevent stdout/stderr patching for extension commands#13600
fix(cli): Prevent stdout/stderr patching for extension commands#13600
Conversation
The function was being called unconditionally at the start of the CLI, redirecting all and output to an event emitter. This caused non-interactive commands, specifically , to hang because their prompts were not being displayed to the user. This commit modifies to conditionally call only when the executed command is not an 'extensions' command. This ensures that and function normally for extension commands, allowing prompts to be displayed and user input to be handled correctly.
Summary of ChangesHello @chrstnb, 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 addresses a critical bug in the CLI where extension commands would become unresponsive because their standard output and error streams were being inappropriately redirected. The fix involves making the stream patching conditional, ensuring that extension commands can properly display prompts and receive user input, thereby restoring their intended interactive functionality. Highlights
Using Gemini Code AssistThe 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 by creating a comment using either
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 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
|
There was a problem hiding this comment.
Code Review
This pull request correctly identifies and fixes an issue where stdout/stderr patching caused extension commands to hang. The approach of conditionally patching stdio is sound. However, the implementation for detecting an extension command is too broad and could lead to false positives if a user's prompt contains the word 'extension'. My review provides a more robust implementation to prevent this potential bug.
| const isExtensionsCommand = | ||
| process.argv.includes('extension') || process.argv.includes('extensions'); |
There was a problem hiding this comment.
Using process.argv.includes() to detect an extension command is too broad and can lead to incorrect behavior. For example, a regular query like gemini "what is a chrome extension?" would be misidentified as an extension command. This would cause patchStdio() to be skipped, breaking the interactive UI rendering for that query.
To make this check more robust, you should specifically check the command argument, which is the third element in process.argv (i.e., process.argv[2]).
| const isExtensionsCommand = | |
| process.argv.includes('extension') || process.argv.includes('extensions'); | |
| const isExtensionsCommand = process.argv[2] === 'extension' || process.argv[2] === 'extensions'; |
|
Size Change: +388 B (0%) Total Size: 21.1 MB ℹ️ View Unchanged
|
|
|
||
| const argv = await parseArguments(settings.merged); | ||
|
|
||
| if ( |
There was a problem hiding this comment.
where is extension command processing happening before this change? point is to not have a separate code path for it if you can avoid it. alternately if you can point me to where it is happening you can just create a shared helper for the initialization done early in runNonInteractive that makes stdout and stderr function normally now that we know the user is not interactive.
| process.exit(0); | ||
| } | ||
|
|
||
| // If yargs handled --help/--version it will have exited; nothing to do here. |
There was a problem hiding this comment.
great to have this removed! was quite magical.
| describe: 'Manage MCP servers', | ||
| builder: (yargs: Argv) => | ||
| yargs | ||
| .middleware(() => initializeOutputListenersAndFlush()) |
Longer term this test should stop mocking Yargs. That is a silly thing to mock.
…extension commands (google-gemini#13600)
…le-gemini#13600) Co-authored-by: jacob314 <jacob314@gmail.com>
Co-authored-by: jacob314 <jacob314@gmail.com>
|
/patch stable |
|
✅ Patch workflow(s) dispatched successfully! 📋 Details:
🔗 Track Progress: |
Co-authored-by: jacob314 <jacob314@gmail.com>
|
🚀 Patch PR Created! 📋 Patch Details:
📝 Next Steps:
🔗 Track Progress: |
|
🚀 Patch Release Started! 📋 Release Details:
⏳ Status: The patch release is now running. You'll receive another update when it completes. 🔗 Track Progress: |
|
✅ Patch Release Complete! 📦 Release Details:
🎉 Status: Your patch has been successfully released and published to npm! 📝 What's Available:
🔗 Links: |
…le-gemini#13600) Co-authored-by: jacob314 <jacob314@gmail.com>

Ended up refactoring so extension/MCP commands handle their own exiting
Details
Related Issues
How to Validate
Pre-Merge Checklist