@@ -4,6 +4,7 @@ import * as path from "path"
44import { arePathsEqual } from "../../utils/path"
55
66export async function listFiles ( dirPath : string , recursive : boolean , limit : number ) : Promise < [ string [ ] , boolean ] > {
7+ // First resolve the path normally - path.resolve doesn't care about glob special characters
78 const absolutePath = path . resolve ( dirPath )
89 // Do not allow listing files in root or home directory, which cline tends to want to do when the user's prompt is vague.
910 const root = process . platform === "win32" ? path . parse ( absolutePath ) . root : "/"
@@ -48,6 +49,7 @@ export async function listFiles(dirPath: string, recursive: boolean, limit: numb
4849 }
4950
5051 // * globs all files in one dir, ** globs files in nested directories
52+ // For non-recursive listing, we still use a simple pattern
5153 const filePaths = recursive ? await globbyLevelByLevel ( limit , options ) : ( await globby ( "*" , options ) ) . slice ( 0 , limit )
5254
5355 return [ filePaths , filePaths . length >= limit ]
@@ -80,7 +82,11 @@ async function globbyLevelByLevel(limit: number, options?: Options) {
8082 }
8183 results . add ( file )
8284 if ( file . endsWith ( "/" ) ) {
83- queue . push ( `${ file } *` )
85+ // Escape parentheses in the path to prevent glob pattern interpretation
86+ // This is crucial for NextJS folder naming conventions which use parentheses like (auth), (dashboard)
87+ // Without escaping, glob treats parentheses as special pattern grouping characters
88+ const escapedFile = file . replace ( / \( / g, "\\(" ) . replace ( / \) / g, "\\)" )
89+ queue . push ( `${ escapedFile } *` )
8490 }
8591 }
8692 }
0 commit comments