From f53415ebbc0a14d403466debe2dc8c7cd313bfc5 Mon Sep 17 00:00:00 2001 From: Yiyang Liu <37043548+ianliuy@users.noreply.github.com> Date: Thu, 16 Apr 2026 14:10:13 -0700 Subject: [PATCH] fix(filesystem): normalize path separators in search_files results On Windows, path.relative() returns backslash-separated paths (e.g., src\index.ts), but minimatch expects forward slashes for glob pattern matching (e.g., **/*.ts). This causes search_files and directory_tree exclude patterns to fail on Windows. Fix by normalizing relativePath to use forward slashes via .split(path.sep).join('/') before passing to minimatch in both searchFilesWithValidation (lib.ts) and buildTree (index.ts). Fixes #3517 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Yiyang Liu <37043548+ianliuy@users.noreply.github.com> --- src/filesystem/index.ts | 3 ++- src/filesystem/lib.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index 7b67e63e58..4e9f36bbcd 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -554,7 +554,8 @@ server.registerTool( const result: TreeEntry[] = []; for (const entry of entries) { - const relativePath = path.relative(rootPath, path.join(currentPath, entry.name)); + // Normalize to forward slashes for consistent cross-platform glob matching + const relativePath = path.relative(rootPath, path.join(currentPath, entry.name)).split(path.sep).join('/'); const shouldExclude = excludePatterns.some(pattern => { if (pattern.includes('*')) { return minimatch(relativePath, pattern, { dot: true }); diff --git a/src/filesystem/lib.ts b/src/filesystem/lib.ts index 17e4654cd5..5d6f3eb292 100644 --- a/src/filesystem/lib.ts +++ b/src/filesystem/lib.ts @@ -389,7 +389,8 @@ export async function searchFilesWithValidation( try { await validatePath(fullPath); - const relativePath = path.relative(rootPath, fullPath); + // Normalize to forward slashes for consistent cross-platform glob matching + const relativePath = path.relative(rootPath, fullPath).split(path.sep).join('/'); const shouldExclude = excludePatterns.some(excludePattern => minimatch(relativePath, excludePattern, { dot: true }) );