MCPcopy Create free account
hub / github.com/continuedev/continue / validateAndResolveFilePath

Function validateAndResolveFilePath

extensions/cli/src/tools/edit.ts:20–58  ·  view source on GitHub ↗
(args: any)

Source from the content-addressed store, hash-verified

18import { generateDiff } from "./writeFile.js";
19
20export 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
60export interface EditArgs extends EditOperation {
61 file_path: string;

Callers 2

edit.tsFile · 0.85
multiEdit.tsFile · 0.85

Calls 1

Tested by

no test coverage detected