MCPcopy Index your code
hub / github.com/Stevenic/codepilot / addCreateFile

Function addCreateFile

lib/functions/createFile.js:63–85  ·  view source on GitHub ↗

* Adds the createFile function to the codepilot instance.

(codepilot)

Source from the content-addressed store, hash-verified

61 * Adds the createFile function to the codepilot instance.
62 */
63function addCreateFile(codepilot) {
64 codepilot.addFunction(createFileFunction, (args) => __awaiter(this, void 0, void 0, function* () {
65 const { filePath, contents } = args;
66 // Check if the file already exists
67 if (yield fs.access(path.join(process.cwd(), filePath)).then(() => true).catch(() => false)) {
68 return `A file already exists at that path.\nGive the user detailed instructions for how they should modify that file instead.`;
69 }
70 try {
71 // Create the directory path if it doesn't exist
72 const directoryPath = path.dirname(filePath);
73 yield fs.mkdir(directoryPath, { recursive: true });
74 // Write the code to the file
75 yield fs.writeFile(path.join(process.cwd(), filePath), contents);
76 // Add the file to the code index
77 yield codepilot.index.upsertDocument(filePath);
78 console.log(internals_1.Colorize.highlight(`Created a new file: ${filePath}`));
79 return `Successfully created file at ${filePath}`;
80 }
81 catch (error) {
82 return `Failed to create file at ${filePath} due to the following error:\n${error.message}`;
83 }
84 }));
85}
86exports.addCreateFile = addCreateFile;
87//# sourceMappingURL=createFile.js.map

Callers

nothing calls this directly

Calls 3

addFunctionMethod · 0.45
upsertDocumentMethod · 0.45
highlightMethod · 0.45

Tested by

no test coverage detected