Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/core/environment/getEnvironmentDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 4 additions & 9 deletions src/services/glob/list-files.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os from "os"
import * as path from "path"
import * as fs from "fs"
import * as childProcess from "child_process"
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
Loading