Skip to content

Commit a13fd1c

Browse files
authored
Include the cwd in the terminal details (#4783)
1 parent 9d0c636 commit a13fd1c

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

src/core/environment/__tests__/getEnvironmentDetails.spec.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ describe("getEnvironmentDetails", () => {
5959
getLastCommand: Mock
6060
getProcessesWithOutput: Mock
6161
cleanCompletedProcessQueue?: Mock
62+
getCurrentWorkingDirectory: Mock
6263
}
6364

6465
let mockCline: Partial<Task>
@@ -208,6 +209,7 @@ describe("getEnvironmentDetails", () => {
208209
id: "terminal-1",
209210
getLastCommand: vi.fn().mockReturnValue("npm test"),
210211
getProcessesWithOutput: vi.fn().mockReturnValue([]),
212+
getCurrentWorkingDirectory: vi.fn().mockReturnValue("/test/path/src"),
211213
} as MockTerminal
212214

213215
;(TerminalRegistry.getTerminals as Mock).mockReturnValue([mockActiveTerminal])
@@ -216,7 +218,9 @@ describe("getEnvironmentDetails", () => {
216218
const result = await getEnvironmentDetails(mockCline as Task)
217219

218220
expect(result).toContain("# Actively Running Terminals")
219-
expect(result).toContain("Original command: `npm test`")
221+
expect(result).toContain("## Terminal terminal-1 (Active)")
222+
expect(result).toContain("### Working Directory: `/test/path/src`")
223+
expect(result).toContain("### Original command: `npm test`")
220224
expect(result).toContain("Test output")
221225

222226
mockCline.didEditFile = true
@@ -234,8 +238,10 @@ describe("getEnvironmentDetails", () => {
234238

235239
const mockInactiveTerminal = {
236240
id: "terminal-2",
241+
getLastCommand: vi.fn().mockReturnValue("npm build"),
237242
getProcessesWithOutput: vi.fn().mockReturnValue([mockProcess]),
238243
cleanCompletedProcessQueue: vi.fn(),
244+
getCurrentWorkingDirectory: vi.fn().mockReturnValue("/test/path/build"),
239245
} as MockTerminal
240246

241247
;(TerminalRegistry.getTerminals as Mock).mockImplementation((active: boolean) =>
@@ -245,13 +251,56 @@ describe("getEnvironmentDetails", () => {
245251
const result = await getEnvironmentDetails(mockCline as Task)
246252

247253
expect(result).toContain("# Inactive Terminals with Completed Process Output")
248-
expect(result).toContain("Terminal terminal-2")
254+
expect(result).toContain("## Terminal terminal-2 (Inactive)")
255+
expect(result).toContain("### Working Directory: `/test/path/build`")
249256
expect(result).toContain("Command: `npm build`")
250257
expect(result).toContain("Build output")
251258

252259
expect(mockInactiveTerminal.cleanCompletedProcessQueue).toHaveBeenCalled()
253260
})
254261

262+
it("should include working directory for terminals", async () => {
263+
const mockActiveTerminal = {
264+
id: "terminal-1",
265+
getLastCommand: vi.fn().mockReturnValue("cd /some/path && npm start"),
266+
getProcessesWithOutput: vi.fn().mockReturnValue([]),
267+
getCurrentWorkingDirectory: vi.fn().mockReturnValue("/some/path"),
268+
} as MockTerminal
269+
270+
const mockProcess = {
271+
command: "npm test",
272+
getUnretrievedOutput: vi.fn().mockReturnValue("Test completed"),
273+
}
274+
275+
const mockInactiveTerminal = {
276+
id: "terminal-2",
277+
getLastCommand: vi.fn().mockReturnValue("npm test"),
278+
getProcessesWithOutput: vi.fn().mockReturnValue([mockProcess]),
279+
cleanCompletedProcessQueue: vi.fn(),
280+
getCurrentWorkingDirectory: vi.fn().mockReturnValue("/another/path"),
281+
} as MockTerminal
282+
283+
;(TerminalRegistry.getTerminals as Mock).mockImplementation((active: boolean) =>
284+
active ? [mockActiveTerminal] : [mockInactiveTerminal],
285+
)
286+
;(TerminalRegistry.getUnretrievedOutput as Mock).mockReturnValue("Server started")
287+
288+
const result = await getEnvironmentDetails(mockCline as Task)
289+
290+
// Check active terminal working directory
291+
expect(result).toContain("## Terminal terminal-1 (Active)")
292+
expect(result).toContain("### Working Directory: `/some/path`")
293+
expect(result).toContain("### Original command: `cd /some/path && npm start`")
294+
295+
// Check inactive terminal working directory
296+
expect(result).toContain("## Terminal terminal-2 (Inactive)")
297+
expect(result).toContain("### Working Directory: `/another/path`")
298+
299+
// Verify the methods were called
300+
expect(mockActiveTerminal.getCurrentWorkingDirectory).toHaveBeenCalled()
301+
expect(mockInactiveTerminal.getCurrentWorkingDirectory).toHaveBeenCalled()
302+
})
303+
255304
it("should include warning when file writing is not allowed", async () => {
256305
;(isToolAllowedForMode as Mock).mockReturnValue(false)
257306
;(getModeBySlug as Mock).mockImplementation((slug: string) => {
@@ -310,6 +359,7 @@ describe("getEnvironmentDetails", () => {
310359
id: "terminal-1",
311360
getLastCommand: vi.fn().mockReturnValue("npm test"),
312361
getProcessesWithOutput: vi.fn().mockReturnValue([]),
362+
getCurrentWorkingDirectory: vi.fn().mockReturnValue("/test/path"),
313363
} as MockTerminal
314364

315365
;(TerminalRegistry.getTerminals as Mock).mockReturnValue([mockErrorTerminal])

src/core/environment/getEnvironmentDetails.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
103103
terminalDetails += "\n\n# Actively Running Terminals"
104104

105105
for (const busyTerminal of busyTerminals) {
106-
terminalDetails += `\n## Original command: \`${busyTerminal.getLastCommand()}\``
106+
const cwd = busyTerminal.getCurrentWorkingDirectory()
107+
terminalDetails += `\n## Terminal ${busyTerminal.id} (Active)`
108+
terminalDetails += `\n### Working Directory: \`${cwd}\``
109+
terminalDetails += `\n### Original command: \`${busyTerminal.getLastCommand()}\``
107110
let newOutput = TerminalRegistry.getUnretrievedOutput(busyTerminal.id)
108111

109112
if (newOutput) {
@@ -145,7 +148,9 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
145148

146149
// Add this terminal's outputs to the details.
147150
if (terminalOutputs.length > 0) {
148-
terminalDetails += `\n## Terminal ${inactiveTerminal.id}`
151+
const cwd = inactiveTerminal.getCurrentWorkingDirectory()
152+
terminalDetails += `\n## Terminal ${inactiveTerminal.id} (Inactive)`
153+
terminalDetails += `\n### Working Directory: \`${cwd}\``
149154
terminalOutputs.forEach((output) => {
150155
terminalDetails += `\n### New Output\n${output}`
151156
})

0 commit comments

Comments
 (0)