From b7fd2dc93621c2a1a43c1deb9559d44334542a97 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Thu, 16 Apr 2026 14:26:56 +0000 Subject: [PATCH] fix: allow list_files to work on home directory (#12121) Remove home directory restriction from handleSpecialDirectories() in list-files.ts so that explicit list_files tool calls return actual file listings instead of "No files found." Add a home directory check in getEnvironmentDetails() to skip automatic file listing for home directory workspaces (similar to the existing Desktop check), keeping the initial system prompt lightweight while still allowing list_files to work correctly. Add test for the new home directory handling in getEnvironmentDetails. --- .../__tests__/getEnvironmentDetails.spec.ts | 8 ++++++++ src/core/environment/getEnvironmentDetails.ts | 5 +++++ src/services/glob/list-files.ts | 13 ++++--------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/core/environment/__tests__/getEnvironmentDetails.spec.ts b/src/core/environment/__tests__/getEnvironmentDetails.spec.ts index f05a5066fb3..c28c10579ce 100644 --- a/src/core/environment/__tests__/getEnvironmentDetails.spec.ts +++ b/src/core/environment/__tests__/getEnvironmentDetails.spec.ts @@ -192,6 +192,14 @@ describe("getEnvironmentDetails", () => { expect(listFiles).not.toHaveBeenCalled() }) + it("should handle home directory specially", async () => { + // First call is for desktop check (return false), second is for home dir check (return true) + ;(arePathsEqual as Mock).mockReturnValueOnce(false).mockReturnValueOnce(true) + const result = await getEnvironmentDetails(mockCline as Task, true) + expect(result).toContain("Home directory files not shown automatically") + expect(listFiles).not.toHaveBeenCalled() + }) + it("should skip file listing when maxWorkspaceFiles is 0", async () => { mockProvider.getState.mockResolvedValue({ ...mockState, diff --git a/src/core/environment/getEnvironmentDetails.ts b/src/core/environment/getEnvironmentDetails.ts index 99b3951cd1d..759072c121b 100644 --- a/src/core/environment/getEnvironmentDetails.ts +++ b/src/core/environment/getEnvironmentDetails.ts @@ -229,11 +229,16 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo if (includeFileDetails) { details += `\n\n# Current Workspace Directory (${cline.cwd.toPosix()}) Files\n` const isDesktop = arePathsEqual(cline.cwd, path.join(os.homedir(), "Desktop")) + const isHomeDir = arePathsEqual(cline.cwd, os.homedir()) if (isDesktop) { // Don't want to immediately access desktop since it would show // permission popup. details += "(Desktop files not shown automatically. Use list_files to explore if needed.)" + } else if (isHomeDir) { + // Home directory can contain a huge number of files; skip automatic + // listing but allow explicit list_files tool calls to work. + details += "(Home directory files not shown automatically. Use list_files to explore if needed.)" } else { const maxFiles = maxWorkspaceFiles ?? 200 diff --git a/src/services/glob/list-files.ts b/src/services/glob/list-files.ts index 5366bbb84b4..a58155e4bb1 100644 --- a/src/services/glob/list-files.ts +++ b/src/services/glob/list-files.ts @@ -1,4 +1,3 @@ -import os from "os" import * as path from "path" import * as fs from "fs" import * as childProcess from "child_process" @@ -158,7 +157,10 @@ function ensureFirstLevelDirectoriesIncluded( } /** - * Handle special directories (root, home) that should not be fully listed + * Handle special directories (root) that should not be fully listed. + * Note: The home directory is no longer blocked here. Instead, the home + * directory is handled in getEnvironmentDetails() to skip automatic listing + * while still allowing explicit list_files tool calls to work correctly. */ async function handleSpecialDirectories(dirPath: string): Promise<[string[], boolean] | null> { const absolutePath = path.resolve(dirPath) @@ -170,13 +172,6 @@ async function handleSpecialDirectories(dirPath: string): Promise<[string[], boo return [[root], false] } - // Do not allow listing files in home directory - const homeDir = os.homedir() - const isHomeDir = arePathsEqual(absolutePath, homeDir) - if (isHomeDir) { - return [[homeDir], false] - } - return null }