feat(cli): truncate shell output in UI history and improve active shell display#17438
Conversation
|
Hi @jwhelangoog, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
Summary of ChangesHello @jwhelangoog, 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 improves the user experience of the CLI by managing the display of shell command output more efficiently. It introduces intelligent truncation for shell command results, ensuring that the UI history remains clean and readable by limiting completed command outputs to a concise 5 lines. For active shell sessions that are not currently focused, the output is limited to 25 lines, providing enough context without overwhelming the display. Additionally, it enhances usability by adding PageUp and PageDown scrolling capabilities to active shell prompts, allowing users to navigate extensive outputs more easily. 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 effectively introduces truncation for shell command outputs in the UI history, which is a great enhancement for readability. The logic for handling active versus historical shell output display limits is well-implemented. My main feedback is a critical improvement for the pruneShellOutput utility to ensure it is memory-efficient and correct, especially when dealing with very large command outputs, which is a primary use case this PR aims to improve.
|
Size Change: +9.44 kB (+0.04%) Total Size: 23.9 MB
ℹ️ View Unchanged
|
|
ACTIVE_SHELL_MAX_LINES (25) and SHELL_HISTORY_MAX_LINES (5) have been defined as constants here. If needed, could be exposed as settings. |
|
Hi there! Thank you for your contribution to Gemini CLI. To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md. This pull request is being closed because it is not currently linked to an issue. You can easily reopen this PR once you have linked it to an issue. How to link an issue: Thank you for your understanding and for being a part of our community! |
Refines the display of shell command outputs in the history to prevent excessive vertical scrolling and improve readability. Key changes: - Implemented pruneShellOutput utility in textUtils to safely truncate strings and AnsiOutput arrays. - Updated useShellCommandProcessor to prune shell execution results to a maximum of 10 lines before adding them to the history. - Updated toolMapping to apply truncation to run_shell_command results when mapping core status to display status. - Added maxLines prop to AnsiOutputText and ToolResultDisplay components to enforce line limits during rendering. - Configured ShellToolMessage to pass a 10-line limit to the display component. This ensures that long shell outputs are truncated in the UI history while retaining the full output for the model context.
… limits Improves the shell command experience by adding interactive scrolling and fine-tuning output truncation. Key changes: - Centralized shell output constants in ui/constants.ts. - Increased active shell visibility to 25 lines (when unfocused). - Decreased historical shell output to 5 lines for a more compact history. - Implemented full viewport scrolling for active shell processes when focused. - Added Ctrl+Shift+PageUp/Down keybindings for page-based scrolling. - Centralized all shell scrolling logic in ShellInputPrompt. - Refined mapping logic to ensure full output is available during execution.
2ef1a94 to
298f990
Compare
|
brief screencast of behavior |
jacob314
left a comment
There was a problem hiding this comment.
Alternate buffer mode supports scrolling. we should make these scrollable in alternate buffer mode. Use the ScrollableList class in alternate buffer mode to efficiently render. the scroll wheel over the box will allow scrolling in the region resolving the issue the PR currently has that it is impossible to view the history of a shell command. Right now the limit is so small that you can barely see if a test run succeeded or failed.
You should also wire these up to use Ctrl-o to expand when not in alternate buffer mode.
Be sure to sync first as that shortcut just changed from ctrl-s
|
This review is from /review-frontend and was reviewed by Jacob. SummaryThe PR successfully introduces truncation logic for shell output to reduce clutter and adds helpful scrolling support for active shell sessions. Recommendations1. Testing Best Practices
2. Key Bindings & Documentation
3. Configuration & Settings
4. Model Quality Impact
5. Code Quality
|
…ion-from-main Resolved conflicts in: - packages/cli/src/ui/hooks/shellCommandProcessor.ts: Integrated pruneShellOutput with upstream's new shellReducer logic. - packages/cli/src/ui/components/ShellInputPrompt.tsx: Maintained PageUp/PageDown scrolling support while adopting upstream key handling structure.
73deed5 to
c4988a2
Compare
Refactors several UI tests to remove manual component mocks, allowing tests to use real implementations for better coverage and reliability. Standardizes on the project's internal 'waitFor' utility instead of 'vi.waitFor'. Updates snapshots to reflect the changes in rendering behavior.
…ilable space Ensures that shell output in active mode does not exceed the available terminal height, resolving overflow issues in the alternate buffer that caused a suboptimal scrolling experience. Updates getShellMaxLines to cap output at ACTIVE_SHELL_MAX_LINES or (availableTerminalHeight - 2), whichever is smaller. Includes new tests and snapshots to verify the height constraints in both small and large terminal scenarios.
Decoupled mouse scrolling from keyboard focus in ScrollProvider and ensured that scrollable components consume keyboard events to prevent bubbling. Updated MainContent to yield focus when a shell pane is active, ensuring scrolling is correctly scoped to the focused component.
Removed redundant shell-specific scrolling commands and unified them under standard Shift+Up/Down and PageUp/Down shortcuts. Updated ShellInputPrompt to use these standard commands and verified the behavior with updated tests. Regenerated the keyboard shortcut documentation to reflect these changes.
After further review with UX team have modified ToolGroupMessage to apply a 4-character margin specifically to the right side, reverting the left side to its original 1-character margin. Updated width calculations and test snapshots to align with the new layout.
For consistency with other keybinding commands, SHELL_LEAVE_FOCUS has been renamed to UNFOCUS_SHELL. All usages have been updated to reflect this change.
- Refactor AnsiOutput.tsx to remove Infinity and use undefined for consistency - Refactor ShellToolMessage.test.tsx to use it.each to reduce verbosity
…nd `it.each` Reduce boilerplate with renderShell utility func, extracts shared test constants, and consolidates repetitive cases into parameterized tests to improve maintainability.
Updates ShellToolMessage to use the full available terminal height for output display when the shell is focused and running in Alternate Screen Buffer mode. This improves visibility of long-running command outputs.
Ensures MainContent passes the correct 'availableTerminalHeight' to HistoryItemDisplay in ASB mode, enabling child components like ShellToolMessage to expand their output pane.
Only capture scroll events when room to scroll exists, otherwise allow keypress events to bubble. (boundary tests added)
…l-output-truncation-from-main

Summary
This PR introduces truncation logic for shell command output in the UI history and improves the display management for active shell sessions. It limits both completed shell command output and active (but unfocused) shell sessions to 15 lines to reduce clutter while ensuring recent context remains visible. It also enhances the shell experience with improved scrolling keybindings, focus management, and high-performance virtualization for large outputs.
Details
Truncation Logic:
ToolResultDisplayandAnsiOutputnow supportmaxLinesfor truncation.ACTIVE_SHELL_MAX_LINES(15) andCOMPLETED_SHELL_MAX_LINES(15) inconstants.ts.Performance & Rendering:
ScrollableList(wrappingVirtualizedList) instead ofScrollable. This ensures O(1) rendering performance regardless of output size, preventing UI freezes with large command outputs (e.g.,seq 1 10000).renderItemandkeyExtractorcallbacks inToolResultDisplayto prevent unnecessary re-renders during rapid state updates.ToolResultDisplayto separate content determination from container logic, preventing potential rendering loops.Scrolling & Navigation:
Command.SHELL_SCROLL_UP,DOWN,PAGE_UP, andPAGE_DOWNinkeyBindings.ts.Shift + Ctrl + Up/Down: Scroll line.Shift + Ctrl + PageUp/PageDown: Scroll page.Command.SHELL_LEAVE_FOCUS(Shift + Tab) to allow users to move focus out of the embedded shell back to the main prompt.Documentation:
docs/cli/keyboard-shortcuts.mdwith the new shell scrolling and focus navigation shortcuts.Testing:
AnsiOutputtruncation.ShellInputPromptscrolling and focus behavior.ToolResultDisplaytruncation, verifying virtualization logic with realScrollableListandAnsiOutputcomponents (removed mocks for higher fidelity).Related Issues
Fixes #14387
How to Validate
Truncation:
seq 1 100).Performance (Virtualization):
seq 1 10000).Scrolling:
Shift + Ctrl + Up/DownandShift + Ctrl + PageUp/PageDownto scroll the output.Focus Navigation:
Shift + Taband verify that focus returns to the main input prompt.