diff --git a/src/filesystem/index.ts b/src/filesystem/index.ts index 23d989d0..cf9dbb92 100644 --- a/src/filesystem/index.ts +++ b/src/filesystem/index.ts @@ -13,6 +13,7 @@ import os from 'os'; import { z } from "zod"; import { zodToJsonSchema } from "zod-to-json-schema"; import { diffLines, createTwoFilesPatch } from 'diff'; +import minimatch from 'minimatch'; // Command line argument parsing const args = process.argv.slice(2); @@ -134,6 +135,7 @@ const MoveFileArgsSchema = z.object({ const SearchFilesArgsSchema = z.object({ path: z.string(), pattern: z.string(), + excludePatterns: z.array(z.string()).optional().default([]) }); const GetFileInfoArgsSchema = z.object({ @@ -183,6 +185,7 @@ async function getFileStats(filePath: string): Promise { async function searchFiles( rootPath: string, pattern: string, + excludePatterns: string[] = [] ): Promise { const results: string[] = []; @@ -191,11 +194,22 @@ async function searchFiles( for (const entry of entries) { const fullPath = path.join(currentPath, entry.name); - + try { // Validate each path before processing await validatePath(fullPath); + // Check if path matches any exclude pattern + const relativePath = path.relative(rootPath, fullPath); + const shouldExclude = excludePatterns.some(pattern => { + const globPattern = pattern.startsWith('*') ? pattern : `*/${pattern}/*`; + return minimatch(relativePath, globPattern, { dot: true }); + }); + + if (shouldExclude) { + continue; + } + if (entry.name.toLowerCase().includes(pattern.toLowerCase())) { results.push(fullPath); } @@ -574,4 +588,4 @@ async function runServer() { runServer().catch((error) => { console.error("Fatal error running server:", error); process.exit(1); -}); \ No newline at end of file +});