(args, extras)
| 8 | import { ContinueError, ContinueErrorReason } from "../../util/errors"; |
| 9 | |
| 10 | export const readFileImpl: ToolImpl = async (args, extras) => { |
| 11 | const filepath = getStringArg(args, "filepath"); |
| 12 | |
| 13 | // Resolve the path first to get the actual path for security check |
| 14 | const resolvedPath = await resolveInputPath(extras.ide, filepath); |
| 15 | if (!resolvedPath) { |
| 16 | throw new ContinueError( |
| 17 | ContinueErrorReason.FileNotFound, |
| 18 | `File "${filepath}" does not exist or is not accessible. You might want to check the path and try again.`, |
| 19 | ); |
| 20 | } |
| 21 | |
| 22 | // Security check on the resolved display path |
| 23 | throwIfFileIsSecurityConcern(resolvedPath.displayPath); |
| 24 | |
| 25 | const content = await extras.ide.readFile(resolvedPath.uri); |
| 26 | |
| 27 | await throwIfFileExceedsHalfOfContext( |
| 28 | resolvedPath.displayPath, |
| 29 | content, |
| 30 | extras.config.selectedModelByRole.chat, |
| 31 | ); |
| 32 | |
| 33 | return [ |
| 34 | { |
| 35 | name: getUriPathBasename(resolvedPath.uri), |
| 36 | description: resolvedPath.displayPath, |
| 37 | content, |
| 38 | uri: { |
| 39 | type: "file", |
| 40 | value: resolvedPath.uri, |
| 41 | }, |
| 42 | }, |
| 43 | ]; |
| 44 | }; |
no test coverage detected