Skip to content

feat(core): phase 2 - add interactive task tree visualization (WIP)#21595

Open
TravisHaa wants to merge 5 commits intogoogle-gemini:mainfrom
TravisHaa:feat/task-tree-visualization
Open

feat(core): phase 2 - add interactive task tree visualization (WIP)#21595
TravisHaa wants to merge 5 commits intogoogle-gemini:mainfrom
TravisHaa:feat/task-tree-visualization

Conversation

@TravisHaa
Copy link
Copy Markdown

@TravisHaa TravisHaa commented Mar 7, 2026

Summary

Creates task tree visualization for tool/sub-agent calls

Closes Phase 2 of #21484

image
  • Add TaskTreeNode interface to ui/types.ts (wraps IndividualToolCallDisplay with children[], depth, isCollapsed, isFocused)
  • Implement useTaskTree hook: builds parent-child hierarchy from IndividualToolCallDisplay[] via parentCallId; promotes orphan children to roots; manages collapse/expand state (Set) and keyboard focus; holds last completed snapshot visible briefly after tool calls drain
  • Accumulate tool calls across entire agent turn: allCurrentTurnToolCalls reads from both uiState.history (completed batches) and uiState.pendingHistoryItems (live batch) so the tree persists across multi-round-trip tool sequences
  • Add TaskNode component: branch connectors (├─ / └─ / │), status glyphs (✓ ● ✗ ) + spinner, padded tool name, inline ToolResultDisplay, recursive children
  • capped tree branch lines to 15 and shows a +N more lines indicator for long outputs.
  • Add TaskTree component: wires TOGGLE_COLLAPSE, COLLAPSE_ALL, EXPAND_ALL keyboard commands; shows completion badge during hold window
  • Wire TaskTree into MainContent; suppress all current-turn tool_group history items when tree is active (index > lastUserPromptIndex)
  • Add TOGGLE_COLLAPSE / COLLAPSE_ALL / EXPAND_ALL keybindings (→/←, Ctrl+[, Ctrl+])
  • Add useTaskTree unit tests (17 tests)
  • WIP: display logic and hold-timer still being refined

Details

Prevously, in MainContent.tsx:43-51 — allPendingToolCalls is built only from pendingHistoryItems. When a batch of tool calls completes, those items are committed to uiState.history and removed from pendingHistoryItems. The tree then only sees the new (empty) pending batch → resets.

  • New Design: pull tool_group items from uiState.history that belong to the current turn (everything after
    lastUserPromptIndex), and combine them with the pending batch of tool calls. Suppressed all current-turn
    history tool_group items (not just the last one), since the tree now renders them.

    Pre-Merge Checklist

    Build & Quality

    • npm run build passes
    • npm run lint passes
    • npm run typecheck passes
    • npm test passes (useTaskTree — 17 tests)

    Visual / Manual

    • Tree renders for a single tool call
    • Tree renders for multiple parallel tool calls (flat list with ├─ / └─)
    • Tree persists across multi-round-trip sequences (model calls tools → gets results → calls more tools → tree accumulates, doesn't
      restart)
    • Tree with nested parent/child calls (subagent with parentCallId)
    • No duplicate flat ToolGroupMessage boxes visible while tree is active
    • Running calls show spinner, completed show ✓, errors show ✗, cancelled show ⊘ with strikethrough
    • Inline output renders correctly when node is expanded
    • 3s hold window shows "✓ completed" badge, then tree clears

    Keyboard Navigation

    • ↑/↓ moves focus between nodes
    • →/← toggles collapse on the focused node
    • Ctrl+[ collapses all nodes
    • Ctrl+] expands all nodes

    Platform

    • macOS (npm run start -w packages/cli)
    • Linux

@TravisHaa TravisHaa requested a review from a team as a code owner March 7, 2026 23:26
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 experience by introducing an interactive task tree visualization. This new feature provides a clear, hierarchical view of tool and sub-agent calls, improving the understanding of complex agent workflows. It ensures that the visualization remains consistent across multiple interaction rounds and offers intuitive keyboard controls for navigation and interaction.

Highlights

  • Interactive Task Tree Visualization: Introduced an interactive task tree visualization for tool and sub-agent calls, providing a clear hierarchical view of agent workflows.
  • Dynamic Tree Management: Implemented a useTaskTree hook to dynamically build the parent-child hierarchy from tool calls, manage collapse/expand states, and handle keyboard focus.
  • Persistent Visualization: Ensured the task tree visualization persists across multi-round-trip tool sequences by accumulating tool calls from both historical and pending items, and holding the last completed snapshot briefly.
  • UI Components and Keybindings: Added dedicated TaskNode and TaskTree React components for rendering the tree structure, including branch connectors, status glyphs, and inline tool results. New keyboard commands for navigation, collapsing, and expanding tree nodes were also integrated.
Changelog
  • packages/cli/src/config/keyBindings.ts
    • Added new Command enum values for TOGGLE_COLLAPSE, COLLAPSE_ALL, and EXPAND_ALL.
    • Assigned default keybindings for task tree interaction (Right/Left arrow for toggle, Ctrl+[ for collapse all, Ctrl+] for expand all).
    • Included the new task tree commands in the 'Task Tree' command category with corresponding descriptions.
  • packages/cli/src/ui/components/HistoryItemDisplay.tsx
    • Introduced a suppressToolGroup prop to conditionally prevent rendering of tool_group items.
    • Modified the component to return an empty Box when suppressToolGroup is true and the item is a tool_group, avoiding duplicate displays when the task tree is active.
  • packages/cli/src/ui/components/MainContent.tsx
    • Imported the new TaskTree component and useTaskTree hook.
    • Refactored tool call accumulation logic to gather all current turn tool calls from both uiState.history and uiState.pendingHistoryItems to feed the useTaskTree hook.
    • Integrated the TaskTree component into the rendering, displaying it when taskTree.hasHierarchy is true.
    • Updated augmentedHistory and historyItems to pass the new suppressToolGroup prop to HistoryItemDisplay for relevant tool_group items.
  • packages/cli/src/ui/components/TaskNode.tsx
    • Added a new React component TaskNode responsible for rendering a single node within the task tree.
    • Implemented logic for displaying branch connectors, status glyphs (✓ ● ✗), tool names, descriptions, and inline tool results.
    • Handled collapsed/expanded states and focus highlighting for individual nodes.
  • packages/cli/src/ui/components/TaskTree.tsx
    • Added a new React component TaskTree to render the overall task tree.
    • Utilized the useKeypress hook to handle keyboard navigation (up/down, left/right, Ctrl+[, Ctrl+]) for tree interaction.
    • Displayed a header with navigation hints or a 'completed' badge during the hold window.
    • Mapped TaskTreeNode data to TaskNode components for rendering.
    • Included a taskTreeToText utility function for accessibility.
  • packages/cli/src/ui/hooks/useTaskTree.test.ts
    • Added a new file containing unit tests for the useTaskTree hook.
    • Tested tree building from flat lists and hierarchies, orphan promotion, collapse/expand functionality, and keyboard focus navigation.
  • packages/cli/src/ui/hooks/useTaskTree.ts
    • Added a new React hook useTaskTree to manage the state and logic for the interactive task tree.
    • Implemented buildTree to construct the hierarchical TaskTreeNode structure from flat IndividualToolCallDisplay data, handling parent-child relationships and orphan nodes.
    • Managed collapsedIds and focusedId states.
    • Included logic to persist the last completed tree snapshot (heldNodes) for a brief period after tool calls drain.
    • Provided functions for toggleCollapse, collapseAll, expandAll, focusNext, and focusPrev.
    • Exported flattenVisibleNodes for traversing the visible tree.
  • packages/cli/src/ui/types.ts
    • Defined a new interface TaskTreeNode to represent a node in the interactive task tree, including toolCall, children, depth, isCollapsed, and isFocused properties.
Activity
  • No specific activity (comments, reviews, progress updates) was provided in the context.
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.

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 introduces an interactive task tree visualization. It has a security vulnerability related to ANSI injection, as LLM/tool output is rendered without sanitization, which could allow terminal UI manipulation. Sanitizing this data at the point of collection is crucial. Additionally, a functional issue in the collapseAll logic needs to be addressed to ensure all nodes are collapsed as expected.

TravisHaa and others added 4 commits March 8, 2026 11:24
- Add TaskTreeNode interface to ui/types.ts (wraps IndividualToolCallDisplay
  with children[], depth, isCollapsed, isFocused)
- Implement useTaskTree hook: builds parent-child hierarchy from
  IndividualToolCallDisplay[] via parentCallId; promotes orphan children
  to roots; manages collapse/expand state (Set<string>) and keyboard focus;
  holds last completed snapshot visible briefly after tool calls drain
- Accumulate tool calls across entire agent turn: allCurrentTurnToolCalls
  reads from both uiState.history (completed batches) and
  uiState.pendingHistoryItems (live batch) so the tree persists across
  multi-round-trip tool sequences
- Add TaskNode component: branch connectors (├─ / └─ / │), status glyphs
  (✓ ● ✗ ⊘ ◷ ◌) + spinner, padded tool name, inline ToolResultDisplay,
  recursive children
- Add TaskTree component: wires TOGGLE_COLLAPSE, COLLAPSE_ALL, EXPAND_ALL
  keyboard commands; shows completion badge during hold window
- Wire TaskTree into MainContent; suppress all current-turn tool_group
  history items when tree is active (index > lastUserPromptIndex)
- Add TOGGLE_COLLAPSE / COLLAPSE_ALL / EXPAND_ALL keybindings (→/←, Ctrl+[, Ctrl+])
- Add useTaskTree unit tests (17 tests)
- WIP: display logic and hold-timer still being refined
…e children nodes

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@TravisHaa TravisHaa force-pushed the feat/task-tree-visualization branch from a86e882 to 43cf587 Compare March 8, 2026 18:24
@TravisHaa
Copy link
Copy Markdown
Author

/gemini review

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 introduces an interactive task tree visualization for tool calls, which is a significant UI enhancement. The implementation includes new components for the tree and nodes, a custom hook to manage the tree state, and updates to keybindings and main content rendering. The code is well-structured and includes comprehensive unit tests for the new hook. I've identified one high-severity memory leak in the useTaskTree hook where tool call timings were not being cleared between turns, and the suggested fix addresses this issue appropriately.

@TravisHaa TravisHaa changed the title feat(core): add interactive task tree visualization (WIP) feat(core): phase 2 - add interactive task tree visualization (WIP) Mar 9, 2026
@gemini-cli gemini-cli bot added the 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. label Mar 9, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant