Skip to content

Commit 185365a

Browse files
authored
Fix terminal reuse logic (#7157)
1 parent 0d90fac commit 185365a

File tree

3 files changed

+5
-33
lines changed

3 files changed

+5
-33
lines changed

src/core/tools/__tests__/executeCommand.spec.ts

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,7 @@ describe("executeCommand", () => {
213213

214214
// Verify
215215
expect(rejected).toBe(false)
216-
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(
217-
customCwd,
218-
true, // customCwd provided
219-
mockTask.taskId,
220-
"vscode",
221-
)
216+
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(customCwd, mockTask.taskId, "vscode")
222217
expect(result).toContain(`within working directory '${customCwd}'`)
223218
})
224219

@@ -248,12 +243,7 @@ describe("executeCommand", () => {
248243

249244
// Verify
250245
expect(rejected).toBe(false)
251-
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(
252-
resolvedCwd,
253-
true, // customCwd provided
254-
mockTask.taskId,
255-
"vscode",
256-
)
246+
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(resolvedCwd, mockTask.taskId, "vscode")
257247
expect(result).toContain(`within working directory '${resolvedCwd.toPosix()}'`)
258248
})
259249

@@ -302,12 +292,7 @@ describe("executeCommand", () => {
302292
await executeCommand(mockTask, options)
303293

304294
// Verify
305-
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(
306-
mockTask.cwd,
307-
false, // no customCwd
308-
mockTask.taskId,
309-
"vscode",
310-
)
295+
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(mockTask.cwd, mockTask.taskId, "vscode")
311296
})
312297

313298
it("should use execa provider when shell integration is disabled", async () => {
@@ -330,12 +315,7 @@ describe("executeCommand", () => {
330315
await executeCommand(mockTask, options)
331316

332317
// Verify
333-
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(
334-
mockTask.cwd,
335-
false, // no customCwd
336-
mockTask.taskId,
337-
"execa",
338-
)
318+
expect(TerminalRegistry.getOrCreateTerminal).toHaveBeenCalledWith(mockTask.cwd, mockTask.taskId, "execa")
339319
})
340320
})
341321

src/core/tools/executeCommandTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export async function executeCommand(
238238
}
239239
}
240240

241-
const terminal = await TerminalRegistry.getOrCreateTerminal(workingDir, !!customCwd, task.taskId, terminalProvider)
241+
const terminal = await TerminalRegistry.getOrCreateTerminal(workingDir, task.taskId, terminalProvider)
242242

243243
if (terminal instanceof Terminal) {
244244
terminal.terminal.show(true)

src/integrations/terminal/TerminalRegistry.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,11 @@ export class TerminalRegistry {
146146
* directory.
147147
*
148148
* @param cwd The working directory path
149-
* @param requiredCwd Whether the working directory is required (if false, may reuse any non-busy terminal)
150149
* @param taskId Optional task ID to associate with the terminal
151150
* @returns A Terminal instance
152151
*/
153152
public static async getOrCreateTerminal(
154153
cwd: string,
155-
requiredCwd: boolean = false,
156154
taskId?: string,
157155
provider: RooTerminalProvider = "vscode",
158156
): Promise<RooTerminal> {
@@ -194,12 +192,6 @@ export class TerminalRegistry {
194192
})
195193
}
196194

197-
// Third priority: Find any non-busy terminal (only if directory is not
198-
// required).
199-
if (!terminal && !requiredCwd) {
200-
terminal = terminals.find((t) => !t.busy && t.provider === provider)
201-
}
202-
203195
// If no suitable terminal found, create a new one.
204196
if (!terminal) {
205197
terminal = this.createTerminal(cwd, provider)

0 commit comments

Comments
 (0)