Changesets · Branches · Tags · Compare
| Changeset | 7f567429e2fa98e1948acda56b45c8babbde441014ba884355339f194d8f35e4 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-09-25 16:19 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-09-25 16:19 -07:00 |
| Parents | 3297e898700c |
1 file changed
modified extensions/cli/src/tools/listFiles.ts +17 −11
| @@ -22,13 +22,27 @@ | ||
| 22 | 22 | readonly: true, |
| 23 | 23 | isBuiltIn: true, |
| 24 | 24 | preprocess: async (args) => { |
| 25 | + // Resolve relative paths | |
| 26 | + const normalizedPath = path.normalize(args.dirpath); | |
| 27 | + const dirPath = path.resolve(process.cwd(), normalizedPath); | |
| 28 | + | |
| 29 | + if (!fs.existsSync(dirPath)) { | |
| 30 | + throw new Error(`Directory does not exist: ${dirPath}`); | |
| 31 | + } | |
| 32 | + | |
| 33 | + if (!fs.statSync(dirPath).isDirectory()) { | |
| 34 | + throw new Error(`Error: Path is not a directory: ${dirPath}`); | |
| 35 | + } | |
| 36 | + | |
| 25 | 37 | return { |
| 26 | - args, | |
| 38 | + args: { | |
| 39 | + dirpath: dirPath, | |
| 40 | + }, | |
| 27 | 41 | preview: [ |
| 28 | 42 | { |
| 29 | 43 | type: "text", |
| 30 | - content: args.dirpath | |
| 31 | - ? `Will list files in: ${formatToolArgument(args.dirpath)}` | |
| 44 | + content: dirPath | |
| 45 | + ? `Will list files in: ${formatToolArgument(dirPath)}` | |
| 32 | 46 | : "Will list files in current directory", |
| 33 | 47 | }, |
| 34 | 48 | ], |
| @@ -36,14 +50,6 @@ | ||
| 36 | 50 | }, |
| 37 | 51 | run: async (args: { dirpath: string }): Promise<string> => { |
| 38 | 52 | try { |
| 39 | - if (!fs.existsSync(args.dirpath)) { | |
| 40 | - return `Error: Directory does not exist: ${args.dirpath}`; | |
| 41 | - } | |
| 42 | - | |
| 43 | - if (!fs.statSync(args.dirpath).isDirectory()) { | |
| 44 | - return `Error: Path is not a directory: ${args.dirpath}`; | |
| 45 | - } | |
| 46 | - | |
| 47 | 53 | const files = fs.readdirSync(args.dirpath); |
| 48 | 54 | const fileDetails = files.map((file) => { |
| 49 | 55 | const fullPath = path.join(args.dirpath, file); |