local handler = require("chatgpt_nvim.handler") local M = {} M.run = function(tool_call, conf, prompt_user_tool_accept, is_subpath, read_file) local path = tool_call.path local new_content = tool_call.content if not path or not new_content then return "[edit_file] Missing 'path' or 'content'." end local root = vim.fn.getcwd() if not is_subpath(root, path) then return string.format("Tool [edit_file for '%s'] REJECTED. Path outside project root.", path) end handler.write_file(path, new_content, conf) local msg = {} msg[#msg+1] = string.format("Tool [edit_file for '%s'] Result:\nThe content was successfully saved to %s.", path, path) msg[#msg+1] = "\nHere is the full, updated content of the file that was saved:\n" msg[#msg+1] = string.format("\n%s\n", path, new_content) msg[#msg+1] = "\nIMPORTANT: For any future changes to this file, use the final_file_content shown above as your reference.\n" return table.concat(msg, "") end return M