MCPcopy
hub / github.com/continuedev/continue / createNewFileImpl

Function createNewFileImpl

core/tools/implementations/createNewFile.ts:9–49  ·  view source on GitHub ↗
(args, extras)

Source from the content-addressed store, hash-verified

7import { ContinueError, ContinueErrorReason } from "../../util/errors";
8
9export const createNewFileImpl: ToolImpl = async (args, extras) => {
10 const filepath = getStringArg(args, "filepath");
11 const contents = getStringArg(args, "contents", true);
12
13 const resolvedFileUri = await inferResolvedUriFromRelativePath(
14 filepath,
15 extras.ide,
16 );
17 if (resolvedFileUri) {
18 throwIfFileIsSecurityConcern(getCleanUriPath(resolvedFileUri));
19 const exists = await extras.ide.fileExists(resolvedFileUri);
20 if (exists) {
21 throw new ContinueError(
22 ContinueErrorReason.FileAlreadyExists,
23 `File ${filepath} already exists. Use the edit tool to edit this file`,
24 );
25 }
26 await extras.ide.writeFile(resolvedFileUri, contents);
27 await extras.ide.openFile(resolvedFileUri);
28 await extras.ide.saveFile(resolvedFileUri);
29 if (extras.codeBaseIndexer) {
30 void extras.codeBaseIndexer?.refreshCodebaseIndexFiles([resolvedFileUri]);
31 }
32 return [
33 {
34 name: getUriPathBasename(resolvedFileUri),
35 description: getCleanUriPath(resolvedFileUri),
36 content: "File created successfuly",
37 uri: {
38 type: "file",
39 value: resolvedFileUri,
40 },
41 },
42 ];
43 } else {
44 throw new ContinueError(
45 ContinueErrorReason.PathResolutionFailed,
46 "Failed to resolve path",
47 );
48 }
49};

Callers 1

callBuiltInToolFunction · 0.90

Calls 10

getStringArgFunction · 0.90
getCleanUriPathFunction · 0.90
getUriPathBasenameFunction · 0.90
fileExistsMethod · 0.65
writeFileMethod · 0.65
openFileMethod · 0.65
saveFileMethod · 0.65

Tested by

no test coverage detected