From 9da8c7ed54f25f58bf30e8eda2d2fb8d665c7223 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Fri, 1 Aug 2025 23:56:26 +0000 Subject: [PATCH] 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. --- src/services/glob/list-files.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/services/glob/list-files.ts b/src/services/glob/list-files.ts index 560af4ab4a..1c06588360 100644 --- a/src/services/glob/list-files.ts +++ b/src/services/glob/list-files.ts @@ -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]