Просмотр исходного кода

Include the cwd in the terminal details (#4783)

Matt Rubens 6 месяцев назад
Родитель
Сommit
a13fd1cb7d

+ 52 - 2
src/core/environment/__tests__/getEnvironmentDetails.spec.ts

@@ -59,6 +59,7 @@ describe("getEnvironmentDetails", () => {
 		getLastCommand: Mock
 		getProcessesWithOutput: Mock
 		cleanCompletedProcessQueue?: Mock
+		getCurrentWorkingDirectory: Mock
 	}
 
 	let mockCline: Partial<Task>
@@ -208,6 +209,7 @@ describe("getEnvironmentDetails", () => {
 			id: "terminal-1",
 			getLastCommand: vi.fn().mockReturnValue("npm test"),
 			getProcessesWithOutput: vi.fn().mockReturnValue([]),
+			getCurrentWorkingDirectory: vi.fn().mockReturnValue("/test/path/src"),
 		} as MockTerminal
 
 		;(TerminalRegistry.getTerminals as Mock).mockReturnValue([mockActiveTerminal])
@@ -216,7 +218,9 @@ describe("getEnvironmentDetails", () => {
 		const result = await getEnvironmentDetails(mockCline as Task)
 
 		expect(result).toContain("# Actively Running Terminals")
-		expect(result).toContain("Original command: `npm test`")
+		expect(result).toContain("## Terminal terminal-1 (Active)")
+		expect(result).toContain("### Working Directory: `/test/path/src`")
+		expect(result).toContain("### Original command: `npm test`")
 		expect(result).toContain("Test output")
 
 		mockCline.didEditFile = true
@@ -234,8 +238,10 @@ describe("getEnvironmentDetails", () => {
 
 		const mockInactiveTerminal = {
 			id: "terminal-2",
+			getLastCommand: vi.fn().mockReturnValue("npm build"),
 			getProcessesWithOutput: vi.fn().mockReturnValue([mockProcess]),
 			cleanCompletedProcessQueue: vi.fn(),
+			getCurrentWorkingDirectory: vi.fn().mockReturnValue("/test/path/build"),
 		} as MockTerminal
 
 		;(TerminalRegistry.getTerminals as Mock).mockImplementation((active: boolean) =>
@@ -245,13 +251,56 @@ describe("getEnvironmentDetails", () => {
 		const result = await getEnvironmentDetails(mockCline as Task)
 
 		expect(result).toContain("# Inactive Terminals with Completed Process Output")
-		expect(result).toContain("Terminal terminal-2")
+		expect(result).toContain("## Terminal terminal-2 (Inactive)")
+		expect(result).toContain("### Working Directory: `/test/path/build`")
 		expect(result).toContain("Command: `npm build`")
 		expect(result).toContain("Build output")
 
 		expect(mockInactiveTerminal.cleanCompletedProcessQueue).toHaveBeenCalled()
 	})
 
+	it("should include working directory for terminals", async () => {
+		const mockActiveTerminal = {
+			id: "terminal-1",
+			getLastCommand: vi.fn().mockReturnValue("cd /some/path && npm start"),
+			getProcessesWithOutput: vi.fn().mockReturnValue([]),
+			getCurrentWorkingDirectory: vi.fn().mockReturnValue("/some/path"),
+		} as MockTerminal
+
+		const mockProcess = {
+			command: "npm test",
+			getUnretrievedOutput: vi.fn().mockReturnValue("Test completed"),
+		}
+
+		const mockInactiveTerminal = {
+			id: "terminal-2",
+			getLastCommand: vi.fn().mockReturnValue("npm test"),
+			getProcessesWithOutput: vi.fn().mockReturnValue([mockProcess]),
+			cleanCompletedProcessQueue: vi.fn(),
+			getCurrentWorkingDirectory: vi.fn().mockReturnValue("/another/path"),
+		} as MockTerminal
+
+		;(TerminalRegistry.getTerminals as Mock).mockImplementation((active: boolean) =>
+			active ? [mockActiveTerminal] : [mockInactiveTerminal],
+		)
+		;(TerminalRegistry.getUnretrievedOutput as Mock).mockReturnValue("Server started")
+
+		const result = await getEnvironmentDetails(mockCline as Task)
+
+		// Check active terminal working directory
+		expect(result).toContain("## Terminal terminal-1 (Active)")
+		expect(result).toContain("### Working Directory: `/some/path`")
+		expect(result).toContain("### Original command: `cd /some/path && npm start`")
+
+		// Check inactive terminal working directory
+		expect(result).toContain("## Terminal terminal-2 (Inactive)")
+		expect(result).toContain("### Working Directory: `/another/path`")
+
+		// Verify the methods were called
+		expect(mockActiveTerminal.getCurrentWorkingDirectory).toHaveBeenCalled()
+		expect(mockInactiveTerminal.getCurrentWorkingDirectory).toHaveBeenCalled()
+	})
+
 	it("should include warning when file writing is not allowed", async () => {
 		;(isToolAllowedForMode as Mock).mockReturnValue(false)
 		;(getModeBySlug as Mock).mockImplementation((slug: string) => {
@@ -310,6 +359,7 @@ describe("getEnvironmentDetails", () => {
 			id: "terminal-1",
 			getLastCommand: vi.fn().mockReturnValue("npm test"),
 			getProcessesWithOutput: vi.fn().mockReturnValue([]),
+			getCurrentWorkingDirectory: vi.fn().mockReturnValue("/test/path"),
 		} as MockTerminal
 
 		;(TerminalRegistry.getTerminals as Mock).mockReturnValue([mockErrorTerminal])

+ 7 - 2
src/core/environment/getEnvironmentDetails.ts

@@ -103,7 +103,10 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
 		terminalDetails += "\n\n# Actively Running Terminals"
 
 		for (const busyTerminal of busyTerminals) {
-			terminalDetails += `\n## Original command: \`${busyTerminal.getLastCommand()}\``
+			const cwd = busyTerminal.getCurrentWorkingDirectory()
+			terminalDetails += `\n## Terminal ${busyTerminal.id} (Active)`
+			terminalDetails += `\n### Working Directory: \`${cwd}\``
+			terminalDetails += `\n### Original command: \`${busyTerminal.getLastCommand()}\``
 			let newOutput = TerminalRegistry.getUnretrievedOutput(busyTerminal.id)
 
 			if (newOutput) {
@@ -145,7 +148,9 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
 
 			// Add this terminal's outputs to the details.
 			if (terminalOutputs.length > 0) {
-				terminalDetails += `\n## Terminal ${inactiveTerminal.id}`
+				const cwd = inactiveTerminal.getCurrentWorkingDirectory()
+				terminalDetails += `\n## Terminal ${inactiveTerminal.id} (Inactive)`
+				terminalDetails += `\n### Working Directory: \`${cwd}\``
 				terminalOutputs.forEach((output) => {
 					terminalDetails += `\n### New Output\n${output}`
 				})