mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Truncate files list for large projects
This commit is contained in:
@@ -514,20 +514,7 @@ export class ClaudeDev {
|
|||||||
async listFilesTopLevel(dirPath: string): Promise<string> {
|
async listFilesTopLevel(dirPath: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const files = await listFiles(dirPath, false)
|
const files = await listFiles(dirPath, false)
|
||||||
const result = files
|
const result = this.formatFilesList(dirPath, files)
|
||||||
.map((file) => {
|
|
||||||
const relativePath = path.relative(dirPath, file)
|
|
||||||
return file.endsWith("/") ? relativePath + "/" : relativePath
|
|
||||||
})
|
|
||||||
.sort((a, b) => {
|
|
||||||
const aIsDir = a.endsWith("/")
|
|
||||||
const bIsDir = b.endsWith("/")
|
|
||||||
if (aIsDir !== bIsDir) {
|
|
||||||
return aIsDir ? -1 : 1
|
|
||||||
}
|
|
||||||
return a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" })
|
|
||||||
})
|
|
||||||
.join("\n")
|
|
||||||
const { response, text } = await this.ask(
|
const { response, text } = await this.ask(
|
||||||
"tool",
|
"tool",
|
||||||
JSON.stringify({ tool: "listFilesTopLevel", path: dirPath, content: result } as ClaudeSayTool)
|
JSON.stringify({ tool: "listFilesTopLevel", path: dirPath, content: result } as ClaudeSayTool)
|
||||||
@@ -555,7 +542,7 @@ export class ClaudeDev {
|
|||||||
async listFilesRecursive(dirPath: string): Promise<string> {
|
async listFilesRecursive(dirPath: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const files = await listFiles(dirPath, true)
|
const files = await listFiles(dirPath, true)
|
||||||
const result = files.map((file) => path.relative(dirPath, file)).join("\n")
|
const result = this.formatFilesList(dirPath, files)
|
||||||
const { response, text } = await this.ask(
|
const { response, text } = await this.ask(
|
||||||
"tool",
|
"tool",
|
||||||
JSON.stringify({ tool: "listFilesRecursive", path: dirPath, content: result } as ClaudeSayTool)
|
JSON.stringify({ tool: "listFilesRecursive", path: dirPath, content: result } as ClaudeSayTool)
|
||||||
@@ -578,6 +565,32 @@ export class ClaudeDev {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
formatFilesList(dirPath: string, files: string[]): string {
|
||||||
|
const sorted = files
|
||||||
|
.map((file) => {
|
||||||
|
// convert absolute path to relative path
|
||||||
|
const relativePath = path.relative(dirPath, file)
|
||||||
|
return file.endsWith("/") ? relativePath + "/" : relativePath
|
||||||
|
})
|
||||||
|
.sort((a, b) => {
|
||||||
|
// sort directories before files
|
||||||
|
const aIsDir = a.endsWith("/")
|
||||||
|
const bIsDir = b.endsWith("/")
|
||||||
|
if (aIsDir !== bIsDir) {
|
||||||
|
return aIsDir ? -1 : 1
|
||||||
|
}
|
||||||
|
return a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" })
|
||||||
|
})
|
||||||
|
|
||||||
|
if (sorted.length > 1000) {
|
||||||
|
const truncatedList = sorted.slice(0, 1000).join("\n")
|
||||||
|
const remainingCount = sorted.length - 1000
|
||||||
|
return `${truncatedList}\n\n(${remainingCount} files not listed due to automatic truncation. Try listing files in subdirectories if you need to explore further.)`
|
||||||
|
} else {
|
||||||
|
return sorted.join("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async viewSourceCodeDefinitionsTopLevel(dirPath: string): Promise<string> {
|
async viewSourceCodeDefinitionsTopLevel(dirPath: string): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const result = await parseSourceCodeForDefinitionsTopLevel(dirPath)
|
const result = await parseSourceCodeForDefinitionsTopLevel(dirPath)
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export async function listFiles(dirPath: string, recursive: boolean): Promise<st
|
|||||||
markDirectories: true, // Append a / on any directories matched
|
markDirectories: true, // Append a / on any directories matched
|
||||||
gitignore: recursive, // globby ignores any files that are gitignored
|
gitignore: recursive, // globby ignores any files that are gitignored
|
||||||
ignore: recursive ? dirsToIgnore : undefined, // just in case there is no gitignore, we ignore sensible defaults
|
ignore: recursive ? dirsToIgnore : undefined, // just in case there is no gitignore, we ignore sensible defaults
|
||||||
onlyFiles: recursive, // true by default, false means it will list directories on their own too
|
onlyFiles: false, // true by default, false means it will list directories on their own too
|
||||||
}
|
}
|
||||||
// * globs all files in one dir, ** globs files in nested directories
|
// * globs all files in one dir, ** globs files in nested directories
|
||||||
const files = await globby(recursive ? "**" : "*", options)
|
const files = await globby(recursive ? "**" : "*", options)
|
||||||
|
|||||||
Reference in New Issue
Block a user