Commit graph

5236 commits

Author SHA1 Message Date
Eric Wheeler
4e0f868261 fix: improve error handling when start sequence not received but stream started
When VSCE start sequence (]633;C or ]133;C) is not received, but the
stream has started:

- Emit no_shell_integration event with clear error message
- Include preOutput in completed event for bug reporting
- Call continue() to ensure proper cleanup
- Return early to prevent further processing

This helps diagnose potential upstream VSCE bugs by providing more context
in the error messages and ensuring proper cleanup of terminal state.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
8de202ba09 fix: prevent UI freeze when terminal stream is unavailable
Add timeout and error handling to terminal stream initialization to prevent
UI from freezing when a stream is unavailable or never starts. This ensures
that if the VSCE shell integration stream does not start within 3 seconds:

- The streamAvailable promise is rejected with a clear error
- Event listeners are cleaned up to prevent memory leaks
- Terminal state is properly reset
- Execution continues rather than hanging indefinitely

This fixes a potential deadlock where the UI could freeze waiting for a
stream that never becomes available.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
f2891d7bc6 test: update no_shell_integration event test
Update test to handle string message parameter in no_shell_integration event

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
a867595a6a doc: enhance shell integration error messages
Add descriptive messages to shell integration failures to help users
understand and resolve integration issues more effectively. This improves
the debugging experience by providing specific details about why shell
integration failed.

- Add message parameter to no_shell_integration event
- Update UI to display specific error messages
- Update troubleshooting documentation link

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
7dadf4cd1b refactor: remove redundant terminal ID from event handling
As pointed out by @cte, passing and checking terminal IDs in events is
unnecessary since a TerminalProcess instance can never be associated with a
different Terminal instance. The event handling is already properly scoped
to the specific TerminalProcess instance.

- Remove terminal ID parameter from shell_execution_complete event
- Remove terminal ID parameter from stream_available event
- Update all event handlers to remove ID checks
- Update all test cases to match new event signatures

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
1601401888 cleanup: remove unused stream property from Terminal
@cte reported that the stream property is not used anywhere in the codebase.
The stream is passed directly to the process via event emitter and does not need to be stored.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
5de0133929 docs: fix test file path in comment
Update the test file path in the comment to match the actual test file name,
making it easier to run the specific test file directly.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
e3b682f119 perf: use string instead of array for terminal output
Use a string instead of array for terminal output since it is faster
than splitting and joining. Also note that 'line' events may contain
multiple lines, so concatenating directly is more efficient.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
5c9f7722b6 docs: document TerminalProcess stability guidelines
The TerminalProcess class is a critical component for VSCode shell integration.
This documentation explains why changes must be minimal and carefully considered:

- Performance optimizations using index-based operations and zero-copy implementation
- Accuracy requirements for handling terminal output and escape sequences
- Complex integration with VSCode shell features and command execution
- Careful handling of stream data and escape sequence processing
- Backwards compatibility considerations for VSCode releases

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
2319f968e2 test: update Terminal constructor calls
Notice: this comment required updating system test snapshots with new
execute_command XML schema feature `cwd`

- Add required cwd parameter to Terminal constructor calls in tests
  - Use './' for TerminalProcess.test.ts
  - Use '/test/path' for TerminalProcessExec.test.ts to match shellIntegration.cwd

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
1a1432d1d1 fix: remove forced directory changes that break shell integration
Forcing terminals to `cd` back to the project directory was disrupting
shell state without providing feedback to the model. This caused issues
with capturing output from subsequent commands, particularly with custom
shell prompts.

Instead of forcing directory changes, we now track terminal state
through shell integration with a fallback mechanism, and provide
explicit working directory feedback to the model. This allows terminals
to maintain their natural state while ensuring accurate command output
capture.

Changes:
- Remove forced `cd` commands that were disrupting terminal state
- Add getCurrentWorkingDirectory() method with shell integration fallback
- Add customCwd parameter to executeCommandTool for flexible directory handling
- Add requiredCwd parameter to control terminal selection behavior
- Refactor terminal selection logic for more consistent state management
- Modify environment details to include terminal working directory feedback
- Update XML schema to include optional working directory parameter in execute_command

The environment details now provide explicit feedback about terminal state:
Command executed in terminal N from '/path/to/dir'. Exit code: 0

Fixes: #1388
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
e27c6aadc1 fix: terminal process isolation between parallel Cline tasks
These changes ensure proper isolation by preventing terminal process
output from one Cline task appearing in another task's context when
multiple Cline instances are running in parallel.

- Add taskId parameter to TerminalRegistry.getTerminals to filter terminals by Cline task ID
- Update Cline.ts to use taskId-filtered terminals

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
25e46a244d fix: terminal output not showing after command completion
Fix an issue where background running terminals that complete their
execution do not report the final output of their command. Previously,
output was reported while the command was active, but after termination
the remaining output was not provided within the 'inactive terminals'
section of environment details.

- Implement terminal process queue system to track completed processes
- Store command and output retrieval state per process
- Add helper methods to manage the process queue efficiently
- Update getEnvironmentDetails to properly display output from completed processes

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
24d8ef91ce fix: emit line event when command output starts
This fixes an issue where commands that wait for input (like 'cat'
without arguments) would hang indefinitely because no 'line' event was
emitted. The terminal would receive the VSCode shell integration marker
indicating command output has started, but since there was no actual
output yet, the UI would not proceed.

By emitting an empty line event when command output starts, we ensure
the UI can proceed even when a command is waiting for input, preventing
the task from hanging.

Thank you @cte for pointing this out in the PR development process.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
d25bcb1913 test: suppress stderr output in TerminalProcessExec tests
Redirect stderr to /dev/null when executing test commands to prevent
'command not found' messages from appearing in test output. This improves
test output readability while maintaining the same test functionality.

The test still verifies that nonexistent commands return exit code 127,
but does so without printing potentially confusing error messages.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
9f5a67ecf8 refactor: remove TerminalManager after migration
- Delete TerminalManager.ts as functionality has been migrated
- Remove TerminalManager import and usage from tests
- Remove outdated TerminalManager references from comments
- Fix TypeScript types in TerminalRegistry event handlers

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
bc8cfc919f fix: prevent terminal sharing between Roo tasks
This change improves terminal management by tracking which task owns
each terminal and prioritizing terminal selection based on task
ownership.

Terminal selection now follows a priority order:

1. First try to find a terminal already assigned to this task with matching directory
2. If not found, try to find any available terminal with matching directory
3. If still not found, try to find any non-busy terminal
4. Only create a new terminal as a last resort

When a task ends, all terminals associated with it are released for use
by other tasks.

This prevents the issue where multiple Roo task instances could
inadvertently share terminals, which could lead to confusion when
terminal output from one task appears in another task's context.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
bf2ce7e1ee refactor: move terminal functionality to Terminal class
Move terminal lifecycle management to improve organization:

1. Move runCommand to Terminal class
2. Move getOrCreateTerminal to TerminalRegistry

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
1973f87c6b fix: prevent duplicate terminal handler registration
Move terminal shell execution handlers from TerminalManager to TerminalRegistry to
permanently solve duplicate handler registration issue. Previously handlers were
registered per-task, now they are registered once at extension startup:

- Initialize handlers when extension loads
- Add safety check to prevent multiple initializations by throwing an
  error if initialize() is called more than once.
- Add cleanup on extension deactivation
- Remove handler registration from TerminalManager

Fixes: #1364
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
3157bf29a8 refactor: move interpretExitCode from TerminalManager to TerminalProcess
- Make interpretExitCode a static method in TerminalProcess
- Update all references to use the static method
- Add comprehensive unit tests for exit code interpretation
- Test with real shell commands for different exit conditions

This change improves code organization by moving the exit code interpretation
logic to the appropriate class, making it more maintainable and reusable.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
2412986f65 test: properly handle exit codes in terminal tests
Improved exit code handling in TerminalProcessExec.test.ts:
- Modified createRealCommandStream to capture real exit codes from execSync
- Added signal handling to convert signal names to exit codes (128 + signal number)
- Added tests for various exit code scenarios (normal, signals, command not found)
- Ensured exit codes flow correctly through terminal events
- Added minimal debug output for unrecognized signals

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
59745a7058 refactor: establish natural terminal hierarchy
Move terminal state access from TerminalManager to TerminalRegistry to establish
a clear hierarchical relationship between components. This change centralizes
terminal management in TerminalRegistry and eliminates duplicate state tracking
in TerminalManager.

The hierarchy flows from TerminalRegistry (managing all terminals) to Terminal
(encapsulating a terminal instance) to TerminalProcess (running within a terminal).

Key changes:
- Remove `processes` map from TerminalManager
- Add static getUnretrievedOutput and isProcessHot methods to TerminalRegistry, which manages all terminals globally

Test updates:
- Modify test setup to create Terminal instances
- Remove processes map usage from tests
- Update process creation and command execution flow in tests

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
304fcf2fbc fix: improve terminal execution with shell integration status
When shell integration is not available, the system now provides clear feedback
about command execution status and maintains consistent event flow.

- Removed waitForShellIntegration property to simplify code flow
- Consolidated event emission to ensure consistent behavior
- Updated tests to verify correct event sequence
- Simplified shell integration detection with pWaitFor
2025-03-10 20:55:05 -07:00
Eric Wheeler
0e41241faa fix: replace echo -e with printf in terminal tests
Replace echo -e with printf command in terminal tests for better portability.

- Replace echo -e with printf to ensure consistent behavior across different shell implementations
- Not all implementations of echo support the -e flag for interpreting backslash escapes
- Using printf provides a more reliable way to handle escape sequences

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
e24e5b24d4 refactor: move getTerminalContents to Terminal class
This commit partially addresses the issue of duplicate handler calls by
removing an unnecessary instantiation of TerminalManager in
registerTerminalActions.ts.

Move the getTerminalContents method from TerminalManager to Terminal
class as a static method and update all references to use the new
location.

Fixes: #1380

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
daf36f38ea refactor: move interpretExitCode from TerminalManager to TerminalProcess
This commit moves the interpretExitCode method from TerminalManager to
TerminalProcess class, as part of the terminal refactoring effort. The
method is responsible for translating exit codes into detailed results,
including signal information.

Changes include:
- Moved interpretExitCode method to TerminalProcess class
- Updated imports in TerminalManager and Cline to reference
  ExitCodeDetails from TerminalProcess
- Added findTerminalIdByVscodeTerminal helper method in TerminalManager
- Added comprehensive unit tests for interpretExitCode in
  TerminalProcess
- Tests cover undefined exit codes, normal exit codes (0-127), and
  signal exit codes (128+)

This change improves code organization by placing the exit code
interpretation logic closer to where it's primarily used, in the
TerminalProcess class.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
3a950bbc15 refactor: Rename TerminalInfo to Terminal and relocate to Terminal.ts
Transformed the TerminalInfo interface into a proper Terminal class and
moved it to its own file. This improves code organization and
encapsulation by centralizing terminal-related functionality.

The change establishes a clearer object model for terminal management,
setting the foundation for a more maintainable terminal architecture.
All references throughout the codebase have been updated to use the new
Terminal class while preserving existing functionality.

Tests have been updated and verified to ensure compatibility with the
new structure.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
60c14d8f5e test: add comprehensive terminal command execution testing
This commit combines three related improvements to terminal testing:

- Create a reusable function for testing terminal commands with real output
- Update tests to properly invoke terminal shell execution handlers
- Add microsecond timing to measure execution performance

Key improvements:
- Added testTerminalCommand function that takes command and expected output
- Use child_process.execSync to run real commands and feed output into mock terminal stream
- Properly trigger VSCode onDidStartTerminalShellExecution and onDidEndTerminalShellExecution events
- Add timeout mechanism to prevent hanging tests
- Measure execution time from terminal process creation to command completion
- Display both microseconds and milliseconds in test output
- Add test for base64 encoded zeros with configurable line count
- Increase buffer size for execSync to handle large outputs
- Limit output display to avoid cluttering the terminal

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-10 20:55:05 -07:00
Eric Wheeler
070a36baa2 Revert "Smart truncation for terminal output"
This reverts commit 7eee3e0878.

Middle-out truncation is a really great feature and it should still be
implemented, however it unnecessarily interferes with #1365 because it
hooked into the low-level chunk management that comes directly from VSCE
shell integration.

The best place to hook OutputBuilder is as follows depending on the
state of terminal interaction:

1. Foreground terminals:

Cline.ts:
	 executeCommandTool(...) {
	     process.on("line", (line) => {
		    lines.push(line)
		    ...
	    }
	 }

2. For background terminals: hook in at the point that getUnretrievedOutput is consumed for active or
   inactive terminals in Cline.ts:getEnvironmentDetails()

Please note:

The Terminal classes are very sensitive to change, partially because of
the complicated way that shell integration works with VSCE, and
partially because of the way that Cline interacts with the Terminal*
class abstractions that make VSCE shell integration easier to work with.

At the point that PR#1365 is merged, it is unlikely that any Terminal*
classes will need to be modified substantially.  Generally speaking, we
should think of this is a stable interface and minimize changes.

Reverts: #1390
2025-03-10 20:54:53 -07:00
Eric Wheeler
13c75a19d1 Revert "Disable terminal actions for now"
This reverts commit 93a394dd93 which has
been fixed by PR #1365.

Fixes: #1380
2025-03-10 20:53:39 -07:00
Eric Wheeler
75de043ded Revert "Remove terminal actions"
This reverts commit 75dcc2ffcf which has
been fixed by PR #1365.

Fixes: #1380
2025-03-10 20:53:36 -07:00
Eric Wheeler
384b469bf1 Revert "Handle outputless commands"
This reverts commit 710284cc3d which has
been superseded by PR #1365.

Fixes: #1416
2025-03-10 20:50:10 -07:00
Eric Wheeler
7e0a4dd426 Revert "Try to prevent additional cases in which terminal commands lock the task UI"
This reverts commit eee7bbe104 which has
been superseded by PR #1365.

Fixes: #1435
2025-03-10 20:50:10 -07:00
Chris Estreich
edb53bf433
Merge pull request #1546 from RooVetGit/cte/roo-code-api
Rename ClineAPI to RooCodeAPI and improve types
2025-03-10 20:45:39 -07:00
Chris Estreich
33f232ab67
Merge pull request #1548 from RooVetGit/cte/npm-install-all
Simplify `npm install` by automatically installing npm-run-all
2025-03-10 20:30:25 -07:00
Matt Rubens
ebb5a571d9
Merge pull request #1558 from RooVetGit/fix_open_ai_usage
Fix usage tracking for SiliconFlow etc
2025-03-10 23:29:45 -04:00
Chris Estreich
90a607f111
Merge branch 'main' into cte/roo-code-api 2025-03-10 20:29:36 -07:00
Chris Estreich
13be66fd53
Merge pull request #1560 from cannuri/cannuri/fix-alert-dialog-theme
refactor alert dialog styles, use vscode theme
2025-03-10 20:25:25 -07:00
cannuri
8c21f0ece3 refactor alert dialog styles, use vscode theme 2025-03-11 03:59:46 +01:00
Matt Rubens
f306461276 Fix usage tracking for SiliconFlow etc 2025-03-10 22:59:08 -04:00
Matt Rubens
9eab941d5c
Merge pull request #1550 from Smartsheet-JB-Brown/jbbrown/aws_custom_arn_for_intelligent_prompt_routing
Users need the ability to use custom ARNs (Amazon Resource Names) with AWS Bedrock for intelligent prompt routing.
2025-03-10 22:21:36 -04:00
Matt Rubens
77186e8ee0 Cleanup 2025-03-10 22:15:52 -04:00
Matt Rubens
d6a9e0fbe9
Merge pull request #1552 from RooVetGit/mcp-home-dir
fix: update MCP servers directory path for platform compatibility
2025-03-10 21:47:08 -04:00
Chris Estreich
00bca30695
Merge pull request #1545 from RooVetGit/cte/action-registraion-cleanup 2025-03-10 18:45:00 -07:00
Matt Rubens
6cfc1cd4c9
Merge pull request #1528 from afshawnlotfi/chrome-remote-webtools
Chrome remote webtools
2025-03-10 21:37:20 -04:00
Hannes Rudolph
7462906b7a
Update ClineProvider.ts
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
2025-03-10 18:49:25 -06:00
Matt Rubens
9dfdc424c6
Merge pull request #1556 from cannuri/cannuri/fix-browser-system-prompt
fix browser system prompt inclusion rules
2025-03-10 20:45:11 -04:00
cannuri
a9773b70c8 fix browser_action system prompt 2025-03-11 01:03:18 +01:00
Hannes Rudolph
abcb7c18b4
Update src/core/webview/ClineProvider.ts
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
2025-03-10 16:23:43 -06:00
Afshawn Lotfi
ce3e22ecfe Refactor Docker gateway IP retrieval to use a dedicated shell command execution function 2025-03-10 21:40:08 +00:00