Skip to content

feat(tui): display Execute tool command and streaming output#117

Open
echobt wants to merge 2 commits intomainfrom
feat/execute-tool-streaming-output
Open

feat(tui): display Execute tool command and streaming output#117
echobt wants to merge 2 commits intomainfrom
feat/execute-tool-streaming-output

Conversation

@echobt
Copy link
Contributor

@echobt echobt commented Feb 5, 2026

Summary

This PR enhances the Execute tool display in the TUI to show:

  1. Command header: The command being executed (e.g., '$ cargo build') is displayed as the tool call header
  2. Real-time streaming output: Up to 3 lines of output are displayed below the command during execution
  3. Clean completion: Live output is cleared when the command completes, replaced by the result summary

Changes

src/cortex-tui/src/runner/event_loop/input.rs

  • Modified AppEvent::ToolProgress handler to forward output chunks to the tool call's live_output buffer
  • The output is split by lines and non-empty lines are appended to the buffer

src/cortex-tui/src/app/methods.rs

  • Added call to clear_live_output() in update_tool_result() to clear streaming output when tool completes

src/cortex-tui/src/views/tool_call.rs

  • Enhanced format_tool_summary() to handle both string and array formats for command arguments
  • Added tests for live_output buffer management (append_output, clear_live_output)
  • Added test for array command format handling

Testing

  • All existing tests pass
  • Added new tests:
    • test_append_output_keeps_last_3_lines: Verifies buffer keeps only last 3 lines
    • test_clear_live_output: Verifies buffer is properly cleared
    • test_format_tool_summary_execute_array: Verifies array command format handling

Visual Example

Before:

● Execute $ cargo build
  ⎿ 35 lines of output

After:

● Execute $ cargo build
  │ Compiling cortex-core v0.0.7
  │ Compiling cortex-engine v0.0.7
  │ Compiling cortex-tui v0.0.7
  ⎿ 35 lines of output

The infrastructure for this feature (ToolCallDisplay.live_output, append_output(), rendering logic) already existed - this PR wires up the streaming output from command execution to the UI buffer.

- Wire AppEvent::ToolProgress to live_output buffer for real-time display
- Display command being executed (e.g., '$ cargo build') in tool call header
- Show up to 3 lines of real-time streaming output during command execution
- Clear live output when command completes, replaced by result summary
- Handle both string and array formats for command arguments
- Add tests for live_output buffer management and command format handling

The Execute tool now shows:
1. The command being run as a header (e.g., '$ cargo build --release')
2. Up to 3 lines of real-time output during execution
3. Result summary when command completes
@greptile-apps
Copy link

greptile-apps bot commented Feb 5, 2026

Greptile Overview

Greptile Summary

This PR successfully wires up streaming command output from the Execute tool to the TUI display, utilizing existing infrastructure (live_output buffer and rendering logic).

Key Changes:

  • Streaming output is now forwarded to tool call display buffers via AppEvent::ToolProgress handler in input.rs:672-680
  • Live output is properly cleared when tools complete in methods.rs:330
  • Command formatting enhanced to handle both string and array formats in tool_call.rs:145-161
  • Comprehensive test coverage added for the new behavior

The implementation is clean and straightforward - it connects existing components without introducing new architectural patterns. All three modified files have focused, well-tested changes.

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • The changes are minimal, well-tested, and leverage existing infrastructure. The implementation correctly handles streaming output with proper cleanup. All test cases cover the new functionality comprehensively.
  • No files require special attention

Important Files Changed

Filename Overview
src/cortex-tui/src/runner/event_loop/input.rs Forwards streaming output chunks to tool call display buffer by splitting into lines and filtering empty ones
src/cortex-tui/src/app/methods.rs Clears live output buffer when tool completes to prevent stale streaming output from persisting
src/cortex-tui/src/views/tool_call.rs Enhanced command formatting to support both string and array formats with comprehensive test coverage

Sequence Diagram

sequenceDiagram
    participant Backend as Execute Tool
    participant EventAdapter as Event Adapter
    participant EventLoop as Event Loop
    participant AppState as App State
    participant ToolDisplay as Tool Call Display
    participant UI as TUI Renderer

    Note over Backend,UI: Tool Execution Flow with Streaming Output

    Backend->>EventAdapter: ExecCommandOutputDeltaEvent<br/>(call_id, base64 chunk)
    EventAdapter->>EventAdapter: decode_output_chunk()
    EventAdapter->>EventLoop: AppEvent::ToolProgress<br/>(name=call_id, status=chunk)
    
    EventLoop->>EventLoop: Split status by lines
    loop For each non-empty line
        EventLoop->>AppState: append_tool_output(call_id, line)
        AppState->>ToolDisplay: append_output(line)
        ToolDisplay->>ToolDisplay: Push to live_output buffer<br/>(keep last 3 lines only)
    end
    
    UI->>ToolDisplay: Read live_output
    UI->>UI: Render streaming output<br/>(if status == Running)
    
    Note over Backend,UI: Tool Completion Flow
    
    Backend->>EventLoop: Tool completion event
    EventLoop->>AppState: update_tool_result(call_id, ...)
    AppState->>ToolDisplay: clear_live_output()
    ToolDisplay->>ToolDisplay: Clear live_output buffer
    AppState->>ToolDisplay: set_result(ToolResultDisplay)
    
    UI->>ToolDisplay: Read result summary
    UI->>UI: Render completion summary
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

…parate lines

- Show command on dedicated line with 8-space indentation (2x tabs) for Execute tool
- Display streaming output lines below command with consistent 8-space indentation
- Keep command visible while output streams in real-time
- Better visual structure for Execute tool execution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant