Add VSCode workspace configuration mock to TerminalProcess.test.ts to handle PowerShell detection in terminal tests, matching the fix in TerminalProcessExec.test.ts
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Mock VSCode workspace configuration to handle PowerShell detection in terminal tests. This prevents TypeError when accessing getConfiguration() in TerminalProcess.run()
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
PowerShell requires special handling for command output due to two issues:
- A sleep delay is required to prevent the ]633;D marker from losing the
original output
- A counter is needed to work around a bug where identical commands are not executed
Changes:
- Add cmdCounter to Terminal class for unique command tracking
- Add PowerShell detection via platform and default shell profile
- Add sleep delay to ensure output is captured before command completion
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
This commit fixes an issue where subtasks weren't properly reporting back to parent tasks when cancelled and resumed. Previously, when a subtask was cancelled and a new task was started with the same message, the parent task would incorrectly resume, causing unexpected behavior.
The fix:
1. Stores parent-child relationship information before cancelling a task
2. Restores this relationship after task reinitialization
3. Ensures parent tasks only resume when explicitly instructed to do so
This approach maintains the correct task hierarchy throughout the cancellation and resumption process, preventing parent tasks from automatically resuming when unrelated tasks with similar messages are started.
Update TerminalProcessExec tests to properly handle shell integration
event sequences:
- Set terminal.running=true before command execution
- Remove duplicate command execution that could trigger extra events
- Replace arbitrary timeout with event-based waiting for output
- Ensure proper event sequence (run -> start -> output -> end)
This aligns the tests with the safeguards added in 62ffa797 that
prevent spurious shell integration events from corrupting terminal
state.
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Add explicit checks and error logging to handle problematic event sequence:
0. terminal.running=false
1. terminal.shellIntegration.executeCommand(command)
2. onDidEndTerminalShellExecution // from unexpected 'OSC 633 D' sequence
3. onDidStartTerminalShellExecution
4. stream begins
5. onDidEndTerminalShellExecution
The first onDidEndTerminalShellExecution (from unexpected OSC 633 D) is
ignored because terminal.running is false, preventing process=undefined
from being set prematurely. After the stream begins and sets
terminal.running to true, the second onDidEndTerminalShellExecution
proceeds normally.
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Fix issue where background processes (like compilers) couldn't broadcast their
output to new tasks after the launching task was closed. Previously commit
851a4cd prevented terminals from responding to any task except the one that
started them.
The fix allows background terminals (taskId undefined) to act as broadcast
sources that can update any task through getEnvironmentDetails, while still
maintaining proper isolation for task-specific terminals. This enables common
workflows where:
1. A task launches a background compiler
2. That task is closed and a new task is started
3. The new task can still receive compiler errors when making changes
This gives us the best of both worlds:
- Task isolation: Active tasks only see their own terminal output
- Background broadcasting: Background processes can inform any task that needs
their output
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Add Terminal.compressTerminalOutput static method to apply run-length encoding
before truncating terminal output. This significantly reduces output size for
repeated lines while maintaining readability.
- Add compressTerminalOutput static method to Terminal class
- Replace all truncateOutput calls with Terminal.compressTerminalOutput
- Import required functions from extract-text
Test program demonstrating compression:
```python
def generate_repeats():
patterns = [
("A\n", 10), # 10 lines
("AA\n", 100), # 100 lines
("AAA\n", 1000), # 1K lines
("AAAA\n", 10000), # 10K lines
("AAAAA\n", 100000), # 100K lines
("AAAAAA\n", 1000000) # 1M lines
]
for text, count in patterns:
print(text * count, end="")
```
Sample output showing compression:
```
A
A
A
A
A
A
A
A
A
A
AA
<previous line repeated 99 additional times>
AAA
<previous line repeated 999 additional times>
AAAA
<previous line repeated 9999 additional times>
AAAAA
<previous line repeated 99999 additional times>
AAAAAA
<previous line repeated 999999 additional times>
```
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Implement applyRunLengthEncoding function to compress repeated lines in text output:
- Add line repetition compression with count message
- Focus on single line repetitions
- Only compress when beneficial
- Add tests for empty input and single line repetitions
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Optimize terminal output handling to reduce memory pressure by:
- Remove continuous result accumulation during line processing
- Only store the same final output from the "completed" event that came from TerminalProcess
Also:
- Add clear error messages for undefined exit details
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Apply terminalOutputLineLimit to command output lines as they are received,
rather than only at the end of command execution. Also apply the limit to
terminal output shown in environment details.
This ensures consistent output truncation behavior across all terminal
output paths, preventing potential memory issues from large outputs.
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Use string indices to find line boundaries instead of splitting into array.
This avoids creating large arrays in memory when truncating big inputs.
- Replace split/join with indexOf/lastIndexOf for line counting
- Use slice to extract start/end sections directly from string
- Maintain same 20/80 ratio for before/after content
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
When a terminal command completes with an undefined exit code:
- Add explicit handling for undefined exit code case
- Include clear message in output that exit code is undefined
- Notify user to help diagnose potential terminal issues
This helps identify and debug cases where the terminal process
completes but the exit code is not properly captured.
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>