| 1 | import { ToolImpl } from "."; |
| 2 | import { walkDir } from "../../indexing/walkDir"; |
| 3 | import { resolveRelativePathInDir } from "../../util/ideUtils"; |
| 4 | |
| 5 | export const lsToolImpl: ToolImpl = async (args, extras) => { |
| 6 | const uri = await resolveRelativePathInDir(args.dirPath, extras.ide); |
| 7 | if (!uri) { |
| 8 | throw new Error( |
| 9 | `Directory ${args.dirPath} not found. Make sure to use forward-slash paths. Do not use e.g. "."`, |
| 10 | ); |
| 11 | } |
| 12 | |
| 13 | const entries = await walkDir(uri, extras.ide, { |
| 14 | returnRelativeUrisPaths: true, |
| 15 | include: "both", |
| 16 | recursive: args.recursive ?? false, |
| 17 | }); |
| 18 | |
| 19 | const content = |
| 20 | entries.length > 0 |
| 21 | ? entries.join("\n") |
| 22 | : `No files/folders found in ${args.dirPath}`; |
| 23 | |
| 24 | return [ |
| 25 | { |
| 26 | name: "File/folder list", |
| 27 | description: `Files/folders in ${args.dirPath}`, |
| 28 | content, |
| 29 | }, |
| 30 | ]; |
| 31 | }; |