Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit b7fd2dc

Browse files
committed
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.
1 parent cb83656 commit b7fd2dc

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ describe("getEnvironmentDetails", () => {
192192
expect(listFiles).not.toHaveBeenCalled()
193193
})
194194

195+
it("should handle home directory specially", async () => {
196+
// First call is for desktop check (return false), second is for home dir check (return true)
197+
;(arePathsEqual as Mock).mockReturnValueOnce(false).mockReturnValueOnce(true)
198+
const result = await getEnvironmentDetails(mockCline as Task, true)
199+
expect(result).toContain("Home directory files not shown automatically")
200+
expect(listFiles).not.toHaveBeenCalled()
201+
})
202+
195203
it("should skip file listing when maxWorkspaceFiles is 0", async () => {
196204
mockProvider.getState.mockResolvedValue({
197205
...mockState,

src/core/environment/getEnvironmentDetails.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,16 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
229229
if (includeFileDetails) {
230230
details += `\n\n# Current Workspace Directory (${cline.cwd.toPosix()}) Files\n`
231231
const isDesktop = arePathsEqual(cline.cwd, path.join(os.homedir(), "Desktop"))
232+
const isHomeDir = arePathsEqual(cline.cwd, os.homedir())
232233

233234
if (isDesktop) {
234235
// Don't want to immediately access desktop since it would show
235236
// permission popup.
236237
details += "(Desktop files not shown automatically. Use list_files to explore if needed.)"
238+
} else if (isHomeDir) {
239+
// Home directory can contain a huge number of files; skip automatic
240+
// listing but allow explicit list_files tool calls to work.
241+
details += "(Home directory files not shown automatically. Use list_files to explore if needed.)"
237242
} else {
238243
const maxFiles = maxWorkspaceFiles ?? 200
239244

src/services/glob/list-files.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os from "os"
21
import * as path from "path"
32
import * as fs from "fs"
43
import * as childProcess from "child_process"
@@ -158,7 +157,10 @@ function ensureFirstLevelDirectoriesIncluded(
158157
}
159158

160159
/**
161-
* Handle special directories (root, home) that should not be fully listed
160+
* Handle special directories (root) that should not be fully listed.
161+
* Note: The home directory is no longer blocked here. Instead, the home
162+
* directory is handled in getEnvironmentDetails() to skip automatic listing
163+
* while still allowing explicit list_files tool calls to work correctly.
162164
*/
163165
async function handleSpecialDirectories(dirPath: string): Promise<[string[], boolean] | null> {
164166
const absolutePath = path.resolve(dirPath)
@@ -170,13 +172,6 @@ async function handleSpecialDirectories(dirPath: string): Promise<[string[], boo
170172
return [[root], false]
171173
}
172174

173-
// Do not allow listing files in home directory
174-
const homeDir = os.homedir()
175-
const isHomeDir = arePathsEqual(absolutePath, homeDir)
176-
if (isHomeDir) {
177-
return [[homeDir], false]
178-
}
179-
180175
return null
181176
}
182177

0 commit comments

Comments
 (0)