From 72f8c1a4e52aa1a31c6c98d3a1e90c315e571ad0 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Sat, 16 Aug 2025 22:59:59 -0700 Subject: [PATCH] Fix terminal reuse logic --- .../tools/__tests__/executeCommand.spec.ts | 28 +++---------------- src/core/tools/executeCommandTool.ts | 2 +- src/integrations/terminal/TerminalRegistry.ts | 8 ------ 3 files changed, 5 insertions(+), 33 deletions(-) diff --git a/src/core/tools/__tests__/executeCommand.spec.ts b/src/core/tools/__tests__/executeCommand.spec.ts index 68dec5c4560..2e973a24cb8 100644 --- a/src/core/tools/__tests__/executeCommand.spec.ts +++ b/src/core/tools/__tests__/executeCommand.spec.ts @@ -213,12 +213,7 @@ describe("executeCommand", () => { // Verify expect(rejected).toBe(false) - expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith( - customCwd, - true, // customCwd provided - mockTask.taskId, - "vscode", - ) + expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(customCwd, mockTask.taskId, "vscode") expect(result).toContain(`within working directory '${customCwd}'`) }) @@ -248,12 +243,7 @@ describe("executeCommand", () => { // Verify expect(rejected).toBe(false) - expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith( - resolvedCwd, - true, // customCwd provided - mockTask.taskId, - "vscode", - ) + expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(resolvedCwd, mockTask.taskId, "vscode") expect(result).toContain(`within working directory '${resolvedCwd.toPosix()}'`) }) @@ -302,12 +292,7 @@ describe("executeCommand", () => { await executeCommand(mockTask, options) // Verify - expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith( - mockTask.cwd, - false, // no customCwd - mockTask.taskId, - "vscode", - ) + expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(mockTask.cwd, mockTask.taskId, "vscode") }) it("should use execa provider when shell integration is disabled", async () => { @@ -330,12 +315,7 @@ describe("executeCommand", () => { await executeCommand(mockTask, options) // Verify - expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith( - mockTask.cwd, - false, // no customCwd - mockTask.taskId, - "execa", - ) + expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(mockTask.cwd, mockTask.taskId, "execa") }) }) diff --git a/src/core/tools/executeCommandTool.ts b/src/core/tools/executeCommandTool.ts index c346526a2e0..2c7ce0d023e 100644 --- a/src/core/tools/executeCommandTool.ts +++ b/src/core/tools/executeCommandTool.ts @@ -238,7 +238,7 @@ export async function executeCommand( } } - const terminal = await TerminalRegistry.getOrCreateTerminal(workingDir, !!customCwd, task.taskId, terminalProvider) + const terminal = await TerminalRegistry.getOrCreateTerminal(workingDir, task.taskId, terminalProvider) if (terminal instanceof Terminal) { terminal.terminal.show(true) diff --git a/src/integrations/terminal/TerminalRegistry.ts b/src/integrations/terminal/TerminalRegistry.ts index af334611c38..6e0531bebe8 100644 --- a/src/integrations/terminal/TerminalRegistry.ts +++ b/src/integrations/terminal/TerminalRegistry.ts @@ -146,13 +146,11 @@ export class TerminalRegistry { * directory. * * @param cwd The working directory path - * @param requiredCwd Whether the working directory is required (if false, may reuse any non-busy terminal) * @param taskId Optional task ID to associate with the terminal * @returns A Terminal instance */ public static async getOrCreateTerminal( cwd: string, - requiredCwd: boolean = false, taskId?: string, provider: RooTerminalProvider = "vscode", ): Promise { @@ -194,12 +192,6 @@ export class TerminalRegistry { }) } - // Third priority: Find any non-busy terminal (only if directory is not - // required). - if (!terminal && !requiredCwd) { - terminal = terminals.find((t) => !t.busy && t.provider === provider) - } - // If no suitable terminal found, create a new one. if (!terminal) { terminal = this.createTerminal(cwd, provider)