(args: z.infer<typeof ArgsSchema>, ctx: ToolContext)
| 50 | argsSchema = ArgsSchema; |
| 51 | |
| 52 | async execute(args: z.infer<typeof ArgsSchema>, ctx: ToolContext): Promise<ToolResult> { |
| 53 | const base = args.path |
| 54 | ? (path.isAbsolute(args.path) ? args.path : path.resolve(ctx.cwd, args.path)) |
| 55 | : ctx.cwd; |
| 56 | const regex = globToRegex(args.pattern); |
| 57 | |
| 58 | const matches: Array<{ path: string; mtime: number }> = []; |
| 59 | const maxResults = 500; |
| 60 | |
| 61 | async function walk(dir: string): Promise<void> { |
| 62 | if (matches.length >= maxResults) return; |
| 63 | let entries; |
| 64 | try { |
| 65 | entries = await fs.readdir(dir, { withFileTypes: true }); |
| 66 | } catch { return; } |
| 67 | |
| 68 | for (const entry of entries) { |
| 69 | if (entry.name.startsWith('.') && entry.name !== '.env') continue; |
| 70 | if (entry.isDirectory()) { |
| 71 | if (IGNORED_DIRS.has(entry.name)) continue; |
| 72 | await walk(path.join(dir, entry.name)); |
| 73 | } else { |
| 74 | const full = path.join(dir, entry.name); |
| 75 | const rel = path.relative(base, full).split(path.sep).join('/'); |
| 76 | if (regex.test(rel)) { |
| 77 | try { |
| 78 | const stat = await fs.stat(full); |
| 79 | matches.push({ path: rel, mtime: stat.mtime.getTime() }); |
| 80 | } catch {} |
| 81 | } |
| 82 | } |
| 83 | if (matches.length >= maxResults) return; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | await walk(base); |
| 88 | matches.sort((a, b) => b.mtime - a.mtime); |
| 89 | |
| 90 | if (matches.length === 0) { |
| 91 | return { content: `[NO_MATCHES] No files match "${args.pattern}" in ${base}. Verify the pattern and base path.` }; |
| 92 | } |
| 93 | |
| 94 | const truncationNote = matches.length >= maxResults ? `\n[... result truncated at ${maxResults}]` : ''; |
| 95 | return { |
| 96 | content: matches.map(m => m.path).join('\n') + truncationNote, |
| 97 | metadata: { count: matches.length, pattern: args.pattern }, |
| 98 | }; |
| 99 | } |
| 100 | } |
nothing calls this directly
no test coverage detected