From 26ae5c282bafde789848edc05d2899ed828c9aaf Mon Sep 17 00:00:00 2001 From: Vineet Kumar Date: Sun, 24 May 2026 14:20:53 -0400 Subject: add write_file tool --- llm-tools.el | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/llm-tools.el b/llm-tools.el index 6476d15..a125e55 100644 --- a/llm-tools.el +++ b/llm-tools.el @@ -25,7 +25,38 @@ longer match after external changes." :confirm nil :include t) -;; TODO write_file (with-temp-buffer + insert) +;; write_file (write-region) +(gptel-make-tool + :name "write_file" + :function (lambda (file contents) + (write-region contents nil file)) + :description "\ +Overwrite an entire file with new contents. This is a destructive +operation that replaces all existing content. Use this tool for: + +- Creating new files from scratch +- Completely replacing small files where the new content is the + intended final state +- Writing generated output, configuration files, or test fixtures + +Do NOT use this for partial edits, appending, or modifying existing +files. Use `edit_file` instead for surgical changes to existing +content. Always call `read_file` first if the file already exists to +preserve content you intend to keep. This tool requires user +confirmation before executing." + :args '((:name "file" + :type string + :description "Path to the file to write to, relative to the working directory.") + (:name "contents" + :type string + :description "\ +Full file contents to write. This will replace all existing +content. Include newlines and indentation as they should appear in the +final file.")) + :async nil + :confirm t + :include t) + ;; TODO edit_file (hashline + patch apply) ;; TODO bash_readonly (shell-command-to-string, whitelisted commands) -- cgit v1.2.3