| 17 | ), |
| 18 | }), |
| 19 | async execute(params) { |
| 20 | let search = params.path ?? Instance.directory |
| 21 | search = path.isAbsolute(search) ? search : path.resolve(Instance.directory, search) |
| 22 | |
| 23 | const limit = 100 |
| 24 | const files = [] |
| 25 | let truncated = false |
| 26 | for await (const file of Ripgrep.files({ |
| 27 | cwd: search, |
| 28 | glob: [params.pattern], |
| 29 | })) { |
| 30 | if (files.length >= limit) { |
| 31 | truncated = true |
| 32 | break |
| 33 | } |
| 34 | const full = path.resolve(search, file) |
| 35 | const stats = await Bun.file(full) |
| 36 | .stat() |
| 37 | .then((x) => x.mtime.getTime()) |
| 38 | .catch(() => 0) |
| 39 | files.push({ |
| 40 | path: full, |
| 41 | mtime: stats, |
| 42 | }) |
| 43 | } |
| 44 | files.sort((a, b) => b.mtime - a.mtime) |
| 45 | |
| 46 | const output = [] |
| 47 | if (files.length === 0) output.push("No files found") |
| 48 | if (files.length > 0) { |
| 49 | output.push(...files.map((f) => f.path)) |
| 50 | if (truncated) { |
| 51 | output.push("") |
| 52 | output.push("(Results are truncated. Consider using a more specific path or pattern.)") |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return { |
| 57 | title: path.relative(Instance.worktree, search), |
| 58 | metadata: { |
| 59 | count: files.length, |
| 60 | truncated, |
| 61 | }, |
| 62 | output: output.join("\n"), |
| 63 | } |
| 64 | }, |
| 65 | }) |