branch: externals/ellama
commit c1fc472cdf73159514b0372bbe6b1596c013a3e0
Author: Sergey Kostyaev <[email protected]>
Commit: Sergey Kostyaev <[email protected]>

    Add append file tool
    
    Added a new tool to append content to files. This includes:
    1. `ellama-tools-append-file-tool` - The core function to append content to 
a
    file
    2. `ellama-tools-append-file-tool-confirm` - A confirmation wrapper for the
    append tool
    3. Registration of the new tool in `ellama-tools-available` with appropriate
    arguments and description
    The tool allows appending text to files with proper file handling and
    confirmation.
---
 ellama-tools.el | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/ellama-tools.el b/ellama-tools.el
index 5e2ff71815..2eb1a1c194 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -255,6 +255,42 @@ otherwise."
                 :description
                 "Write CONTENT to the file located at the specified PATH."))
 
+(defun ellama-tools-append-file-tool (path content)
+  "Append CONTENT to the file located at the specified PATH."
+  (with-current-buffer (find-file-noselect path)
+    (goto-char (point-max))
+    (insert content)
+    (save-buffer)))
+
+(defun ellama-tools-append-file-tool-confirm (path content)
+  "Append CONTENT to the file located at the specified PATH."
+  (ellama-tools-confirm
+   (format "Allow appending file %s?" path)
+   'ellama-tools-append-file-tool
+   (list path content)))
+
+(add-to-list
+ 'ellama-tools-available
+ (llm-make-tool :function
+                'ellama-tools-append-file-tool-confirm
+                :name
+                "append_file"
+                :args
+                (list '(:name
+                        "path"
+                        :type
+                        string
+                        :description
+                        "Path to the file.")
+                      '(:name
+                        "content"
+                        :type
+                        string
+                        :description
+                        "Content to append to the file."))
+                :description
+                "Append CONTENT to the file located at the specified PATH."))
+
 (defun ellama-tools-directory-tree-tool (dir &optional depth)
   "Return a string representing the directory tree under DIR.
 DEPTH is the current recursion depth, used internally."

Reply via email to