fix: apply numeric-aware sorting before limit in formatAndCombineResults

The previous implementation removed sorting entirely, which caused version-numbered files to be excluded when directories had 200+ files. This fix applies numeric-aware sorting (using localeCompare with numeric option) before the limit is applied, ensuring proper ordering of version sequences like v3.25, v3.25.1, v3.25.2, etc.
This commit is contained in:
Roo Code 2025-08-01 23:56:26 +00:00
parent ab481eac18
commit 9da8c7ed54

View file

@ -601,8 +601,20 @@ function formatAndCombineResults(files: string[], directories: string[], limit:
const uniquePathsSet = new Set(allPaths)
const uniquePaths = Array.from(uniquePathsSet)
// Note: Sorting is handled by formatFilesList with numeric-aware algorithm
// to properly handle version-numbered files (e.g., v3.25.1, v3.25.2, etc.)
// Apply numeric-aware sorting before limiting results
// This ensures version-numbered files are properly ordered before truncation
uniquePaths.sort((a: string, b: string) => {
const aIsDir = a.endsWith("/")
const bIsDir = b.endsWith("/")
// Directories come first
if (aIsDir && !bIsDir) return -1
if (!aIsDir && bIsDir) return 1
// For same type (both dirs or both files), use numeric-aware comparison
// This properly handles version numbers like v3.25.1, v3.25.2, etc.
return a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" })
})
const trimmedPaths = uniquePaths.slice(0, limit)
return [trimmedPaths, trimmedPaths.length >= limit]