|
|
@@ -514,20 +514,7 @@ export class ClaudeDev {
|
|
|
async listFilesTopLevel(dirPath: string): Promise<string> {
|
|
|
try {
|
|
|
const files = await listFiles(dirPath, false)
|
|
|
- const result = 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 result = this.formatFilesList(dirPath, files)
|
|
|
const { response, text } = await this.ask(
|
|
|
"tool",
|
|
|
JSON.stringify({ tool: "listFilesTopLevel", path: dirPath, content: result } as ClaudeSayTool)
|
|
|
@@ -555,7 +542,7 @@ export class ClaudeDev {
|
|
|
async listFilesRecursive(dirPath: string): Promise<string> {
|
|
|
try {
|
|
|
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(
|
|
|
"tool",
|
|
|
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> {
|
|
|
try {
|
|
|
const result = await parseSourceCodeForDefinitionsTopLevel(dirPath)
|