-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: resolve terminal working directory tracking after cd commands (#5424) #5425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…5424) - Enhanced TerminalRegistry.getOrCreateTerminal() to properly track working directory changes - Added strict working directory matching in all terminal selection priorities - Implemented task isolation to prevent inappropriate terminal reuse - Added comprehensive test coverage for working directory scenarios - Ensures subsequent commands run in correct directory after cd operations Fixes #5424
✅ No security or compliance issues detected. Reviewed everything up to 156698f. Security Overview
Detected Code Changes
Reply to this PR with |
if (!terminal) { | ||
terminal = terminals.find((t) => { | ||
if (t.busy || t.provider !== provider) { | ||
return false | ||
} | ||
|
||
// Don't reuse terminals assigned to different tasks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added check to avoid reusing terminals assigned to a different task is a good fix. Note that this same taskId check is repeated in both the second and third priority branches. Consider refactoring this logic into a helper function for clarity and maintainability.
I feel like we can probably solve this with better instructions or maybe letting the model know the current working directory of the terminal? With this change Roo Code will potentially create new terminal instances every time it uses a command with |
Automatically closed: PR created by @roomote-agent before 2025-07-16 |
I understand the concern about potential terminal proliferation. Let me review the current implementation and explore a better solution that addresses the working directory tracking issue without creating excessive terminal instances. I will investigate alternative approaches such as better instructions or providing current working directory information to the model. |
Summary of ChangesI have addressed your concern about terminal proliferation while maintaining the core functionality to track working directory changes. Here is what I implemented: Key Improvements:
How This Solves the Original Issue:
Benefits:✅ Prevents Terminal Proliferation: Task-specific terminals are reused by default The solution addresses the core issue from #5424 while implementing your feedback about avoiding excessive terminal creation. The model now receives proper working directory information to make informed decisions about subsequent commands. |
Description
Fixes #5424
This PR resolves the issue where subsequent execute_command calls would run in the wrong directory after the LLM used commands like cd
. The problem occurred because the terminal registry was reusing terminals whose working directory had changed via cd commands, without properly tracking these changes.Changes Made
Testing
Files Changed
Important
Fixes terminal working directory tracking in
TerminalRegistry.ts
to ensure correct execution aftercd
commands, with new tests added.TerminalRegistry.ts
to ensure commands run in correct directory aftercd
.TerminalRegistry.workingDirectory.spec.ts
to cover working directory changes and task-specific terminal reuse.getOrCreateTerminal()
to track working directory usingterminal.shellIntegration.cwd
and match strictly by directory.This description was created by
for 156698f. You can customize this summary. It will automatically update as commits are pushed.