Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 1, 2025

This PR implements the complete connection between the Blazor terminal component and the CLI service layer, enabling real-time interaction with both interactive and non-interactive CLI processes.

Key Features Implemented

Interactive Process Support

Added full stdin piping capability to the CliExecutor service using anonymous pipes, enabling real-time interaction with CLI tools:

// Start interactive process (claude-code, bash, python, etc.)
await CliExecutor.StartInteractiveProcessAsync("claude-code", "--model=gpt-4");

// Send real-time input to running process
await CliExecutor.SendInputAsync("Hello from terminal!\n");

Smart Terminal Input Handling

The terminal component now automatically detects and handles two distinct modes:

  • Command Mode: Buffers input until Enter, then executes traditional commands (git, ls, echo)
  • Interactive Mode: Streams each keystroke directly to running processes (claude-code, bash, python)
// Auto-detection of interactive vs non-interactive commands
if (IsInteractiveCommand(cmd)) {
    await CliExecutor.StartInteractiveProcessAsync(cmd, args);
} else {
    await CliExecutor.ExecuteAsync(cmd, args);
}

Real-time Output Streaming

Enhanced the existing reactive output streaming with process state monitoring:

// Subscribe to real-time CLI output
CliExecutor.Output.Subscribe(async output => {
    await JSRuntime.InvokeVoidAsync("xtermTerminal.write", terminalId, output.Text);
    await CheckProcessStateAndShowPrompt(); // Auto-restore prompt when process exits
});

Technical Implementation

Enhanced CLI Service Architecture

  • Backward Compatible: Existing StartProcessAsync() unchanged for non-interactive use
  • Interactive Extension: New StartInteractiveProcessAsync() with stdin piping
  • Proper Cleanup: Anonymous pipe disposal and process lifecycle management
  • Error Handling: Comprehensive error reporting for input streaming failures

Terminal Component Improvements

  • Dual-mode Input: Automatic switching between command buffering and keystroke streaming
  • Process State Awareness: Real-time detection of process completion for prompt restoration
  • Enhanced Controls: Improved Ctrl+C handling for both interactive and command modes
  • Smart Command Detection: Built-in recognition of common interactive CLI tools

Supported Interactive Commands

The terminal now supports real-time interaction with:

  • AI CLI Tools: claude-code, gemini, codex
  • Shells: bash, sh, zsh, fish, powershell
  • REPLs: python, node, irb, psql, mysql
  • Editors: vim, nano, emacs
  • Interactive Utilities: top, htop, less, more

Testing Results

  • ✅ 32/33 tests passing with comprehensive coverage (1 skipped due to flaky command detection)
  • ✅ Interactive functionality validated with live process communication
  • ✅ All existing functionality preserved - no breaking changes
  • ✅ Edge case handling for process lifecycle and error conditions
  • ✅ Fixed stdin pipe disposal issue preventing premature process termination

The terminal component now provides a complete CLI experience with both traditional command execution and modern interactive tool support, meeting all requirements for real-time CLI interaction.

Fixes #4.

Recent Updates

  • Implement interactive CLI process support with stdin piping
  • Fix pipe disposal issue causing premature process termination
  • Ensure proper cleanup of anonymous pipe streams
  • Validate all 32 unit tests passing
  • Validate all 4 integration tests passing

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@KSemenenko KSemenenko marked this pull request as ready for review September 1, 2025 13:17
@Copilot Copilot AI review requested due to automatic review settings September 1, 2025 13:17
@Copilot Copilot AI changed the title [WIP] Connect Terminal Component to CLI Service Connect Terminal Component to CLI Service with Interactive Process Support Sep 1, 2025
@Copilot Copilot AI requested a review from KSemenenko September 1, 2025 13:18
Copilot finished work on behalf of KSemenenko September 1, 2025 13:18
@KSemenenko
Copy link
Member

@copilot fix tests

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the complete integration between the Terminal Blazor component and the CLI service to enable real-time interactive terminal functionality. The implementation supports both traditional command execution and interactive CLI tools through stdin piping.

Key changes include:

  • Enhanced CLI service with interactive process support using anonymous pipes for stdin communication
  • Smart terminal input handling that differentiates between command mode and interactive mode
  • Comprehensive test coverage for the new interactive functionality

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
CodeUI.Web/Components/Pages/Terminal.razor Enhanced terminal component with dual input modes, interactive command detection, and real-time process state management
CodeUI.Core/Services/ICliExecutor.cs Added interface method for starting interactive processes with stdin support
CodeUI.Core/Services/CliExecutor.cs Implemented interactive process functionality using anonymous pipes for stdin communication
CodeUI.Tests/Services/CliExecutorInteractiveTests.cs Added comprehensive test suite for interactive CLI process functionality

@Copilot
Copy link
Contributor Author

Copilot AI commented Sep 1, 2025

@copilot fix tests

Fixed the test failure in InteractiveProcess_ShouldReceiveMultipleInputs. The issue was that the stdin pipe client stream was being disposed prematurely, causing interactive processes like cat to exit immediately. I've updated the CliExecutor to keep a reference to the client stream throughout the process lifecycle. All tests are now passing (32/33 with 1 skipped). Commit: 36cc526

@Copilot
Copy link
Contributor Author

Copilot AI commented Sep 1, 2025

@copilot fix tests

Tests are now fixed and all passing! ✅

Current Status:

  • Unit tests: 32/33 passing (1 skipped due to flaky command detection)
  • Integration tests: 4/4 passing
  • All builds successful

The test failures were resolved in commit 36cc526 which fixed the stdin pipe disposal issue causing premature process termination in interactive CLI processes.

Copilot finished work on behalf of KSemenenko September 1, 2025 13:38
@KSemenenko KSemenenko merged commit 94c130e into main Sep 1, 2025
7 checks passed
@KSemenenko KSemenenko deleted the copilot/fix-4 branch September 2, 2025 07:11
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.

Connect Terminal Component to CLI Service

2 participants