branch: externals/ellama
commit 56bb486665f49ea5928437f89683ea778c56b370
Merge: cbf3cb3247 7347a30381
Author: Sergey Kostyaev <[email protected]>
Commit: GitHub <[email protected]>

    Merge pull request #385 from 
s-kostyaev/fix-tool-confirmation-for-async-tools
    
    Fix tool confirmation for async tools
---
 NEWS.org        |  7 +++++++
 ellama-tools.el | 17 ++++++++++++-----
 ellama.el       |  7 ++++---
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index 19939c834c..ba38d92e30 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,3 +1,10 @@
+* Version 1.12.9
+- Fix result delivery for already approved async tools. Ensure results are
+  delivered via callback function for both interactive and pre‑approved tools.
+- Guard against nil project root tool result. Wrap
+  ~ellama-tools-project-root-tool~ result in an and expression to prevent 
errors
+  when the tool returns nil, protecting file-name-directory and 
expand-file-name
+  calls.
 * Version 1.12.8
 - Add fallback for AGENTS.md search when ~ellama-tools-project-root-tool~
   returns nil. This ensures reliable detection of the AGENTS.md file by falling
diff --git a/ellama-tools.el b/ellama-tools.el
index 1310be7106..a349f27492 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -137,10 +137,17 @@ approved, \"Forbidden by the user\" otherwise."
      ((or confirmation
          ellama-tools-allow-all
          (cl-find function ellama-tools-allowed))
-      (let ((result (apply function args)))
-       (if (stringp result)
-           result
-         (json-encode result))))
+      (let* ((result (apply function args))
+             (result-str (if (stringp result)
+                             result
+                           (when result
+                             (json-encode result))))
+             (cb (and args
+                      (functionp (car args))
+                      (car args))))
+        (if (and cb result-str)
+            (funcall cb result-str)
+          (or result-str "done"))))
      ;; Otherwise, ask for confirmation
      (t
       ;; Generate prompt with truncated string arguments
@@ -206,7 +213,7 @@ approved, \"Forbidden by the user\" otherwise."
           (let ((result-str (if (stringp result)
                                 result
                               (when result
-                                  (json-encode result))))
+                                (json-encode result))))
                 (cb (and args
                          (functionp (car args))
                          (car args))))
diff --git a/ellama.el b/ellama.el
index a3d50f0141..750ab48ecc 100644
--- a/ellama.el
+++ b/ellama.el
@@ -6,7 +6,7 @@
 ;; URL: http://github.com/s-kostyaev/ellama
 ;; Keywords: help local tools
 ;; Package-Requires: ((emacs "28.1") (llm "0.24.0") (plz "0.8") (transient 
"0.7") (compat "29.1") (yaml "1.2.3"))
-;; Version: 1.12.8
+;; Version: 1.12.9
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;; Created: 8th Oct 2023
 
@@ -1217,8 +1217,9 @@ Otherwire return current active session."
   "Search for AGENTS.md file from current directory up to project root.
 Returns the full path to AGENTS.md if found, or nil if not found."
   (let* ((current-dir (file-name-directory (expand-file-name 
default-directory)))
-         (project-root (or (file-name-directory (expand-file-name
-                                                
(ellama-tools-project-root-tool)))
+         (project-root (or (and (ellama-tools-project-root-tool)
+                               (file-name-directory (expand-file-name
+                                                     
(ellama-tools-project-root-tool))))
                           current-dir))
          found-path)
     ;; Walk up from current directory to project root

Reply via email to