branch: externals/ellama
commit c3e937930b1ed11ed3e306b828cf9ffe4706eb0d
Author: Sergey Kostyaev <[email protected]>
Commit: Sergey Kostyaev <[email protected]>
Fix directory tree function and update tool enable documentation
The changes include:
1. Modified ellama-tools-enable-by-name to return nil after enabling a tool
2. Updated the documentation for ellama-tools-enable-by-name to mention
that the
agent needs to reply to the user before using newly enabled tools
3. Enhanced ellama-tools--directory-tree to check if the directory exists
before
processing it, returning an error message if it doesn't exist
4. Maintained the existing functionality of directory tree generation while
adding error handling for non-existent directories
---
ellama-tools.el | 39 +++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/ellama-tools.el b/ellama-tools.el
index c1149c2a52..9fedec53b9 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -84,7 +84,8 @@ otherwise."
(let* ((tool-name name)
(tool (seq-find (lambda (tool) (string= tool-name (llm-tool-name
tool)))
ellama-tools-available)))
- (add-to-list 'ellama-tools-enabled tool)))
+ (add-to-list 'ellama-tools-enabled tool)
+ nil))
(defun ellama-tools-enable-by-name (&optional name)
"Add to `ellama-tools-enabled' each tool that matches NAME."
@@ -122,7 +123,7 @@ otherwise."
:description
"Name of the tool to enable."))
:description
- "Enable each tool that matches NAME."))
+ "Enable each tool that matches NAME. You need to reply to the
user before using newly enabled tool."))
(defun ellama-tools--disable-by-name (name)
"Remove from `ellama-tools-enabled' each tool that matches NAME."
@@ -241,22 +242,24 @@ otherwise."
(defun ellama-tools--directory-tree (dir &optional depth)
"Return a string representing the directory tree under DIR.
DEPTH is the current recursion depth, used internally."
- (let ((indent (make-string (* (or depth 0) 2) ? ))
- (tree ""))
- (dolist (f (sort (cl-remove-if
- (lambda (f)
- (string-prefix-p "." f))
- (directory-files dir))
- #'string-lessp))
- (let* ((full (expand-file-name f dir))
- (name (file-name-nondirectory f))
- (type (if (file-directory-p full) "|-" "`-"))
- (line (concat indent type name "\n")))
- (setq tree (concat tree line))
- (when (file-directory-p full)
- (setq tree (concat tree
- (ellama-tools--directory-tree full (+ (or depth
0) 1)))))))
- tree))
+ (if (not (file-exists-p dir))
+ ("Directory %s doesn't exists" dir)
+ (let ((indent (make-string (* (or depth 0) 2) ? ))
+ (tree ""))
+ (dolist (f (sort (cl-remove-if
+ (lambda (f)
+ (string-prefix-p "." f))
+ (directory-files dir))
+ #'string-lessp))
+ (let* ((full (expand-file-name f dir))
+ (name (file-name-nondirectory f))
+ (type (if (file-directory-p full) "|-" "`-"))
+ (line (concat indent type name "\n")))
+ (setq tree (concat tree line))
+ (when (file-directory-p full)
+ (setq tree (concat tree
+ (ellama-tools--directory-tree full (+ (or depth
0) 1)))))))
+ tree)))
(defun ellama-tools-directory-tree (dir)
"Return a string representing the directory tree under DIR."