Skip to content

feat(cli): truncate shell output in UI history and improve active shell display#17438

Merged
jwhelangoog merged 45 commits intomainfrom
feature/ux-dev/shell-output-truncation-from-main
Feb 8, 2026
Merged

feat(cli): truncate shell output in UI history and improve active shell display#17438
jwhelangoog merged 45 commits intomainfrom
feature/ux-dev/shell-output-truncation-from-main

Conversation

@jwhelangoog
Copy link
Copy Markdown
Contributor

@jwhelangoog jwhelangoog commented Jan 24, 2026

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:

    • ToolResultDisplay and AnsiOutput now support maxLines for truncation.
    • Defined ACTIVE_SHELL_MAX_LINES (15) and COMPLETED_SHELL_MAX_LINES (15) in constants.ts.
    • Completed shell outputs in history are now truncated to 15 lines (previously proposed as 5, but increased to preserve more context).
    • Active shell outputs (unfocused) are also limited to 15 lines.
  • Performance & Rendering:

    • Virtualization: Active shell output in alternate buffer mode now uses ScrollableList (wrapping VirtualizedList) instead of Scrollable. This ensures O(1) rendering performance regardless of output size, preventing UI freezes with large command outputs (e.g., seq 1 10000).
    • Optimization: Memoized renderItem and keyExtractor callbacks in ToolResultDisplay to prevent unnecessary re-renders during rapid state updates.
    • Stability: Refactored ToolResultDisplay to separate content determination from container logic, preventing potential rendering loops.
  • Scrolling & Navigation:

    • Implemented Command.SHELL_SCROLL_UP, DOWN, PAGE_UP, and PAGE_DOWN in keyBindings.ts.
    • Mapped standard keybindings for shell scrolling:
      • Shift + Ctrl + Up/Down: Scroll line.
      • Shift + Ctrl + PageUp/PageDown: Scroll page.
    • Added Command.SHELL_LEAVE_FOCUS (Shift + Tab) to allow users to move focus out of the embedded shell back to the main prompt.
  • Documentation:

    • Updated docs/cli/keyboard-shortcuts.md with the new shell scrolling and focus navigation shortcuts.
  • Testing:

    • Added tests for AnsiOutput truncation.
    • Added tests for ShellInputPrompt scrolling and focus behavior.
    • Added tests for ToolResultDisplay truncation, verifying virtualization logic with real ScrollableList and AnsiOutput components (removed mocks for higher fidelity).

Related Issues

Fixes #14387

How to Validate

  1. Truncation:

    • Run a command with large output (e.g., seq 1 100).
    • Observe that once the command completes, the history entry shows the last 15 lines.
    • While the command is running (active shell), observe it shows up to 15 lines.
  2. Performance (Virtualization):

    • Run a massive output command (e.g., seq 1 10000).
    • Ensure the UI remains responsive and does not freeze while the command runs or when scrolling back up.
  3. Scrolling:

    • Start a long-running command or one with much output.
    • Focus the shell input.
    • Use Shift + Ctrl + Up/Down and Shift + Ctrl + PageUp/PageDown to scroll the output.
  4. Focus Navigation:

    • Focus the embedded shell.
    • Press Shift + Tab and verify that focus returns to the main input prompt.

@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Jan 24, 2026

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!

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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

  • Output Truncation: Implemented logic to truncate shell command output in the UI, limiting completed commands in history to 5 lines and active, unfocused sessions to 25 lines.
  • New Utility Function: Introduced a pruneShellOutput utility to handle truncation for both string and AnsiOutput types, ensuring consistent behavior across the UI.
  • Enhanced Scrolling: Added PageUp and PageDown scrolling support for active shell sessions, allowing users to navigate extensive outputs more efficiently.
  • Component Updates: Modified AnsiOutput and ToolResultDisplay components to accept a maxLines prop, providing granular control over the number of lines displayed.
  • Constant Definitions: Defined new constants ACTIVE_SHELL_MAX_LINES (25) and SHELL_HISTORY_MAX_LINES (5) to centralize and manage truncation limits.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

  1. 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.

@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Jan 24, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 24, 2026

Size Change: +9.44 kB (+0.04%)

Total Size: 23.9 MB

Filename Size Change
./bundle/gemini.js 23.8 MB +9.44 kB (+0.04%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB

compressed-size-action

@jwhelangoog
Copy link
Copy Markdown
Contributor Author

ACTIVE_SHELL_MAX_LINES (25) and SHELL_HISTORY_MAX_LINES (5) have been defined as constants here. If needed, could be exposed as settings.

@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Jan 24, 2026

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:
Add a keyword followed by the issue number (e.g., Fixes #123) in the description of your pull request. For more details, see the GitHub Documentation.

Thank you for your understanding and for being a part of our community!

@gemini-cli gemini-cli bot closed this Jan 24, 2026
@jwhelangoog jwhelangoog reopened this Jan 24, 2026
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.
@jwhelangoog jwhelangoog force-pushed the feature/ux-dev/shell-output-truncation-from-main branch from 2ef1a94 to 298f990 Compare January 24, 2026 17:59
@jwhelangoog
Copy link
Copy Markdown
Contributor Author

brief screencast of behavior

@jwhelangoog jwhelangoog marked this pull request as ready for review January 24, 2026 18:54
@jwhelangoog jwhelangoog requested a review from a team as a code owner January 24, 2026 18:54
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jacob314
Copy link
Copy Markdown
Contributor

This review is from /review-frontend and was reviewed by Jacob.

Summary

The PR successfully introduces truncation logic for shell output to reduce clutter and adds helpful scrolling support for active shell sessions.

Recommendations

1. Testing Best Practices

  • Snapshots: In and , please use for the new test cases instead of . This ensures we verify the overall layout and follow the project's established testing patterns.
  • waitFor: Ensure that any tests waiting for state updates use the project's custom from (which wraps in ) rather than .

2. Key Bindings & Documentation

  • Centralized Bindings: The new scrolling shortcuts () are currently hardcoded in . Please add these to the enum and in .
  • Documentation: Once added to the key bindings config, the shortcuts will be automatically included in . Please remember to test these combinations across iTerm2, VS Code, and Ghostty to ensure cross-platform compatibility.

3. Configuration & Settings

  • User Preferences: (5) and (25) are currently hardcoded constants. Consider moving these to user settings in (e.g., ) so users can customize the truncation behavior.

4. Model Quality Impact

  • Context Truncation: Does this truncation affect the history sent back to the model, or is it purely for display? If the model only receives the truncated 5-line output for previous shell commands, it might impact reasoning quality. Tagging @anj-s to confirm if this change requires a quality evaluation.

5. Code Quality

  • AnsiOutput.tsx: The logic in for and is a bit redundant. You might be able to simplify the slicing logic since already accounts for as a fallback.

jwhelangoog and others added 3 commits January 28, 2026 10:35
…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.
@jwhelangoog jwhelangoog force-pushed the feature/ux-dev/shell-output-truncation-from-main branch from 73deed5 to c4988a2 Compare February 3, 2026 03:17
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.
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

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)
@jwhelangoog jwhelangoog requested a review from a team as a code owner February 8, 2026 07:19
@jwhelangoog jwhelangoog added this pull request to the merge queue Feb 8, 2026
Merged via the queue into main with commit 4a48d7c Feb 8, 2026
27 checks passed
@jwhelangoog jwhelangoog deleted the feature/ux-dev/shell-output-truncation-from-main branch February 8, 2026 08:21
aswinashok44 pushed a commit to aswinashok44/gemini-cli that referenced this pull request Feb 9, 2026
kuishou68 pushed a commit to iOfficeAI/aioncli that referenced this pull request Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell command output is too verbose

2 participants