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>
- 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>
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>
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>
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>
- 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>
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>
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>
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
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>
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>
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>
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>
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>
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