feat(cli): implement compact tool output#20974
Conversation
|
Size Change: +28.9 kB (+0.11%) Total Size: 26.5 MB
ℹ️ View Unchanged
|
a72642f to
26d83d5
Compare
79cbd3c to
3dc7dc9
Compare
87cc10e to
251a79f
Compare
|
Compact Tool Output Vid: http://screencast/cast/NjEwNjgzMzAyOTY5MzQ0MHw2MGMyZDJjYi1mMQ |
211a5b2 to
f357b17
Compare
73e7db3 to
ba264fa
Compare
Summary of ChangesHello, 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 enhances the user interface for tool output in the CLI by introducing a 'Compact Tool Output' feature. It refactors how tool results are displayed, moving towards a more structured and ergonomic presentation. The changes aim to provide users with high-signal information at a glance, with the option to delve into details, thereby streamlining the interaction with agent and tool responses in the terminal. 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new UI setting for compact tool output, allowing tool results like file diffs and directory listings to be displayed in a more concise, structured format. It refactors tool call ID generation to ensure uniqueness and updates UI components to support toggleable expansion of tool outputs, especially in alternate buffer mode. A code review comment highlights a duplication of logic for identifying target tool call IDs in AppContainer.tsx that should be extracted into a reusable helper function to improve maintainability and prevent inconsistencies.
Note: Security Review did not run due to the size of the PR.
45d9438 to
038daab
Compare
5655b88 to
55f98e7
Compare
|
Is it normal to include SVGs as part of the UI tests? |
This was recently added by Jacob I believe as an option to support color validation within the tests. |
974fd7a to
fdb33f5
Compare
…e safety This commit establishes the structural foundation and required infrastructure to support the upcoming compact tool output changes. It includes identity management improvements, layout fixes, and type-safety enhancements that stand independently. 1. Identity & History Management: - useHistoryManager: Ensure strictly increasing IDs for history items, even with identical timestamps. - acpClient: Introduced callIdCounter to prevent callId collisions during rapid execution. - MainContent: Implemented negative ID logic for pending items to ensure stable React keys and prevent collisions. - historyUtils: New file containing extracted history logic (isToolExecuting, getAllToolCalls) hoisted from AppContainer. 2. UI Infrastructure & Layout: - test-utils/render: Modernized renderWithProviders and removed legacy props. - AskUserDialog: Fixed layout, scroll visibility, and alignment issues. - toolLayoutUtils: Increased TOOL_RESULT_STANDARD_RESERVED_LINE_COUNT for better spacing. - ShellToolMessage/ToolGroupMessage: Updated line-count expectations and snapshots to align with layout changes. 3. IDE & Diffing Improvements: - ToolActionsContext: Refactored IdeClient initialization to fix a race condition and potential memory leak. - edit/diffOptions: Improved accuracy of diff stat derivation, ensuring "full content" stats are available for the model. - coreToolScheduler: Automatically derive diff stats from patches if missing. - state-manager: Ensure diffStat preservation for rejected tool calls. 4. Type Safety & Constants: - types/tools: Added foundational types like DiffStat, FileDiff, and StructuredToolResult. - Type Guards: Added guards for isFileDiff, isTodoList, isAnsiOutput, and hasSummary. - CodeColorizer: Added function overloads to gracefully handle null language detection. - tool-names: Introduced DISPLAY_NAME constants for consistent tool labeling. This commit passes all workspace tests and builds successfully. Feature-specific logic for compact output is excluded.
This commit introduces the compactToolOutput feature to optimize terminal vertical space usage for common, high-volume tools. 1. Compact Tool Output UI: - Added DenseToolMessage component for rendering compact, single-line tool summaries. - Updated ToolGroupMessage to detect contiguous compact tools and render them with stitched borders for a streamlined look. - Added Ctrl+O shortcut in AppContainer to toggle full expansion of tool results from the last turn. - Implemented useGeminiStream border logic to correctly render borders around dense sections. 2. Core Tool Structured Results: - grep: Updated to return GrepResult with matches, file paths, and line numbers instead of a raw formatted string. - ls (list_directory): Updated to return ListDirectoryResult with an array of files. - read_many_files: Updated to return ReadManyFilesResult with read files, skipped files, and reasons. - Modified ToolResultDisplay and isStructuredToolResult type guards to support these new structured interfaces. 3. User Settings & Documentation: - Added compactToolOutput to the UI settings schema (default: true). - Updated configuration docs and schema to reflect the new setting. - Adjusted compact subview line limits (COMPACT_TOOL_SUBVIEW_MAX_LINES). test(cli): refine settings and tool action mocks to resolve test rig regressions This update addresses incomplete settings store contracts and default state mismatches that caused snapshot runtime errors and verification failures in compact tool output tests. 1. Settings Mock Completeness: - Updated `createMockSettings` in `mockConfig.ts` to include required functional methods (`subscribe`, `getSnapshot`, `setValue`) to satisfy React's `useSyncExternalStore` contract. This resolves "store.getSnapshot is not a function" errors in snapshot tests. 2. Tool Actions Provider Configuration: - Modified `renderWithProviders` to accept a `toolActions` options object, allowing individual tests to inject specific tool expansion states. - Changed the default mock for `isExpanded` from `true` to `false` to align with the application's default behavior (collapsed outputs) in alternate buffer mode. 3. Test Refactoring: - Refactored `ToolGroupMessage.compact.test.tsx` to use the standardized `createMockSettings` utility rather than a manual generic object, ensuring proper context evaluation during rendering. refactor(cli): address nuanced snapshot rendering scenarios through layout and padding refinements - Refined height calculation logic in ToolGroupMessage to ensure consistent spacing between compact and standard tools. - Adjusted padding and margins in StickyHeader, ToolConfirmationQueue, ShellToolMessage, and ToolMessage for visual alignment. - Updated TOOL_RESULT_STANDARD_RESERVED_LINE_COUNT to account for internal layout changes. - Improved ToolResultDisplay height handling in alternate buffer mode. - Updated test snapshots to reflect layout and spacing corrections. refactor(cli): cleanup and simplify UI components - Reduced UI refresh delay in AppContainer.tsx for a more responsive user experience. - Reorder imports and hook definitions within AppContainer.tsx to reduce diff 'noise'. refactor(cli): enhance compact output robustness and visual regression testing Addressing automated review feedback to improve code maintainability and layout stability. 1. Robust File Extension Parsing: - Introduced getFileExtension utility in packages/cli/src/ui/utils/fileUtils.ts using node:path for reliable extension extraction. - Updated DenseToolMessage and DiffRenderer to use the new utility, replacing fragile string splitting. 2. Visual Regression Coverage: - Added SVG snapshot tests to DenseToolMessage.test.tsx to verify semantic color rendering and layout integrity in compact mode. fix(cli): resolve dense tool output code quality issues - Replaced manual string truncation with Ink's `wrap="truncate-end"` to adhere to UI guidelines. - Added `isReadManyFilesResult` type guard to `packages/core/src/tools/tools.ts` to improve typing for structured tool results. - Fixed an incomplete test case in `DenseToolMessage.test.tsx` to properly simulate expansion via context instead of missing mouse events.
- Abstracted hardcoded padding, margin, and width calculations in `DenseToolMessage` into explicit constants to improve readability.
- Made `terminalWidth` a required property on `DenseToolMessageProps` to ensure consistent layout calculations, simplifying internal ternary checks.
- Updated `DenseToolMessage` tests to provide the now-required `terminalWidth` prop.
- Removed expensive `node:crypto` usage in `DiffRenderer` key generation, opting for a simpler optional key.
- Simplified terminal refresh logic in `AppContainer` by removing `setTimeout` from the "show more lines" handler, as it was redundant.
- Streamlined `staticHeight` calculation loop in `ToolGroupMessage` to use layout constants.
- Removed redundant `height={0}` properties on Box borders in `ToolGroupMessage`.
- Simplified `effectiveMaxHeight` assignment in `ToolResultDisplay` by using the pre-calculated `availableHeight` directly.
- Restore tool message padding by moving `paddingTop={1}` from `ToolMessage` and `ShellToolMessage` content boxes back to `paddingBottom={1}` in `StickyHeader`.
- Restore `ToolConfirmationQueue` layout.
- Removed excluded file information from ReadManyFiles tool's compact output
fdb33f5 to
91a73c9
Compare

Summary
(Part 2 of 2 - Follows foundational layout and diff accuracy improvements in #23286)
This PR provides the core implementation of the Compact Tool Output feature, building upon the original proposal in #18728. It introduces a compact, high-signal rendering mode for tool outputs that improves terminal ergonomics and reduces the visual gap between user prompts and system/agent responses.
Details
Key architectural and UI improvements include:
ui.compactToolOutputsetting (defaults tofalse).grep,ls, andread_many_filesinpackages/coreto return structured payloads (GrepResult,ListDirectoryResult,ReadManyFilesResult). This allows the UI to render concise summaries while preserving the full data payload for sub-views or agent context.DenseToolMessagecomponent for single-line tool summaries (status, description, and diff stats), complete with an interactive toggle to expand file diffs within the Alternate Screen Buffer (ASB).ToolGroupMessagewith a segment-based rendering approach. It densely packs consecutive compact outputs while isolating standard, verbose tools (likeShellToolMessage) into their own bordered boxes with consistent spacing.ToolActionsContextto manage tool confirmations, cancellations, and IDE side-effects, cleanly separating this logic from the presentation layer.Related Issues
How to Validate
ui.compactToolOutput: truein your settings.edit). Verify the output is a single line and that clicking the status expands the diff correctly.ls,read_many_files, andgrep_search. Verify they output clean, 1-2 line summaries instead of their full payloads.run_shell_command). Verify that shell commands are properly isolated in their own boxes with correct spacing.