Execute function that handles patch operations. This function receives the operation input and should return a string describing the result (success or failure message).
The operation types are:
create_file: Create a new file at the specified path with the diff contentupdate_file: Modify an existing file using V4A diff formatdelete_file: Remove a file at the specified pathexecute: async (operation) => {
if (operation.type === "create_file") {
const content = applyDiff("", operation.diff, "create");
await fs.writeFile(operation.path, content);
return `Created ${operation.path}`;
}
if (operation.type === "update_file") {
const current = await fs.readFile(operation.path, "utf-8");
const newContent = applyDiff(current, operation.diff);
await fs.writeFile(operation.path, newContent);
return `Updated ${operation.path}`;
}
if (operation.type === "delete_file") {
await fs.unlink(operation.path);
return `Deleted ${operation.path}`;
}
return "Unknown operation type";
}
Options for the Apply Patch tool.