Commit graph

3464 commits

Author SHA1 Message Date
Chris Estreich
80d1fae033
Update src/shared/globalState.ts
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
2025-03-11 14:27:18 -07:00
cte
4b6def5f31 ContextProxy fix - constructor should not be async 2025-03-11 14:24:21 -07:00
Chris Estreich
b73bc39c8d
Merge pull request #1365 from KJ7LNW/roo-fix-terminal-undefined-exit-code
refactor terminal architecture to address critical issues with the current design
2025-03-11 13:59:04 -07:00
Matt Rubens
3b2d6bce64
Merge pull request #1564 from cannuri/cannuri/fix_subtask_cancel_resume_bug
fix: Preserve parent-child relationship when cancelling subtasks
2025-03-11 14:47:17 -04:00
aheizi
5e788fc5f1 remove rejectUnauthorized 2025-03-12 01:11:22 +08:00
aheizi
f534e80f78 fix ut 2025-03-12 00:46:04 +08:00
Matt Rubens
99258e4a9c
Merge pull request #1572 from RooVetGit/fix_openrouter_generation_check
Use baseURL in OpenRouter generation check
2025-03-11 12:00:37 -04:00
aheizi
29aa464ce3 Merge remote-tracking branch 'origin/main' into feature/add_sse_mcp 2025-03-11 23:06:12 +08:00
aheizi
8b76206cc1 update MCP prompt instructions 2025-03-11 22:58:57 +08:00
Matt Rubens
b5f6e37982
Merge pull request #1543 from shohei-ihaya/vertex
add gemini-2.0-pro-exp-02-05 model to vertex
2025-03-11 09:57:24 -04:00
Matt Rubens
76f91819c1 Use baseURL in OpenRouter generation check 2025-03-11 09:41:57 -04:00
dongqing
9d0b824b90 fix test error for wrong arguments after additional base url added 2025-03-11 17:37:07 +08:00
dongqing
a3a5592654 add config for gemini custom base url 2025-03-11 16:46:40 +08:00
dqroid
8b0956666c
Merge branch 'main' into support-custom-baseUrl-for-google-ai-studio-gemini 2025-03-11 16:15:52 +08:00
lightrabbit
7114cef03e feat: openai-compatible deepseek/qwq reasoning support 2025-03-11 14:13:17 +08:00
Matt Rubens
ff54c63ffa
Merge pull request #1526 from qdaxb/fix_progress_status
Fix progress status
2025-03-11 01:23:45 -04:00
axb
8917ab7591 fix duplicate ask 2025-03-11 13:08:02 +08:00
axb
621fc0e867 Revert "Merge pull request #1518 from RooVetGit/revert_tool_progress_for_now"
This reverts commit dba9116d26, reversing
changes made to 85dd1a1977.
2025-03-11 13:07:55 +08:00
cannuri
6ce8e56db5 fix: Preserve parent-child relationship when cancelling subtasks
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.
2025-03-11 06:05:48 +01:00
Eric Wheeler
701b5a7d87 test: align terminal tests with shell integration safeguards
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>
2025-03-10 21:22:19 -07:00
Eric Wheeler
62ffa7973c fix: prevent spurious onDidEndTerminalShellExecution from breaking terminal output
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>
2025-03-10 20:55:05 -07:00
Eric Wheeler
e3adee4f15 fix: allow background terminals to broadcast output across tasks
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>
2025-03-10 20:55:05 -07:00
Eric Wheeler
0b4fa0b1d6 feat: compress repeated terminal output lines
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>
2025-03-10 20:55:05 -07:00
Eric Wheeler
131f9ad0d9 feat: add run-length encoding for repeated lines
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>
2025-03-10 20:55:05 -07:00
Eric Wheeler
269ddf9a0e fix: avoid duplicate terminal output accumulation
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>
2025-03-10 20:55:05 -07:00
Eric Wheeler
5be49e1d15 fix: apply terminal output line limits consistently
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>
2025-03-10 20:55:05 -07:00
Eric Wheeler
c31a5e5bcd perf: optimize truncateOutput for large inputs
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>
2025-03-10 20:55:05 -07:00
Eric Wheeler
8b8c4fde50 fix: handle undefined exit codes in terminal output
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>
2025-03-10 20:55:05 -07:00
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