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

    Make shell_command tool async
    
    Updated ellama-tools-shell-command-tool to execute commands asynchronously 
using
    a callback function. The tool now creates a temporary buffer, starts a 
process,
    and notifies the callback with the result once execution completes.
---
 ellama-tools.el | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/ellama-tools.el b/ellama-tools.el
index 49fffa5487..4c1cc45a28 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -512,15 +512,23 @@ Replace OLDCONTENT with NEWCONTENT."
    :description
    "Edit file FILE_NAME. Replace OLDCONTENT with NEWCONTENT."))
 
-(defun ellama-tools-shell-command-tool (cmd)
-  "Execute shell command CMD."
-  (shell-command-to-string cmd))
+(defun ellama-tools-shell-command-tool (callback cmd)
+  "Execute shell command CMD.
+CALLBACK – function called once with the result string."
+  (let ((buf (get-buffer-create (concat (make-temp-name " *ellama shell 
command") "*"))))
+    (set-process-sentinel
+     (start-process "*ellama-shell-command*" buf shell-file-name 
shell-command-switch cmd)
+     (lambda (process _)
+       (when (not (process-live-p process))
+         (funcall callback (with-current-buffer buf (buffer-string)))
+         (kill-buffer buf))))))
 
 (ellama-tools-define-tool
  '(:function
    ellama-tools-shell-command-tool
    :name
    "shell_command"
+   :async t
    :args
    ((:name
      "cmd"

Reply via email to