(args: any)
| 18 | import { generateDiff } from "./writeFile.js"; |
| 19 | |
| 20 | export function validateAndResolveFilePath(args: any): { |
| 21 | originalPath: string; |
| 22 | resolvedPath: string; |
| 23 | } { |
| 24 | const { file_path } = args; |
| 25 | |
| 26 | if (!file_path) { |
| 27 | throw new ContinueError( |
| 28 | ContinueErrorReason.FindAndReplaceMissingFilepath, |
| 29 | "file_path is required", |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | const absolutePath = path.isAbsolute(file_path) |
| 34 | ? file_path |
| 35 | : path.resolve(process.cwd(), file_path); |
| 36 | |
| 37 | const resolvedPath = fs.realpathSync(absolutePath); |
| 38 | |
| 39 | throwIfFileIsSecurityConcern(resolvedPath); |
| 40 | |
| 41 | // Check if file exists |
| 42 | if (!fs.existsSync(resolvedPath)) { |
| 43 | throw new ContinueError( |
| 44 | ContinueErrorReason.FileNotFound, |
| 45 | `File ${file_path} does not exist`, |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | // Check if file has been read |
| 50 | if (!readFilesSet.has(resolvedPath)) { |
| 51 | throw new ContinueError( |
| 52 | ContinueErrorReason.EditToolFileNotRead, |
| 53 | `You must use the ${readFileTool.name} tool to read ${file_path} before editing it.`, |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | return { originalPath: file_path, resolvedPath: resolvedPath }; |
| 58 | } |
| 59 | |
| 60 | export interface EditArgs extends EditOperation { |
| 61 | file_path: string; |
no test coverage detected