branch: externals/ellama
commit 5aa4c16b3ac69914f733c5b7fc536366b2bfa15c
Author: Sergey Kostyaev <[email protected]>
Commit: Sergey Kostyaev <[email protected]>
Add grep_in_file tool
Introduced two new functions: `ellama-tools-grep-in-file-tool` that runs
`grep
--color=never -nh <search-string> <file>` and
`ellama-tools-grep-in-file-tool-confirm` which prompts the user to confirm
before executing the grep. Updated the `ellama-tools-available` list with a
new
tool entry named "grep_in_file" that registers these functions, specifying
their
arguments and description. This adds file‑level grepping capability as an
available command in ellama‑tools.
---
ellama-tools.el | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/ellama-tools.el b/ellama-tools.el
index 202862f5d6..ee9ff58062 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -477,6 +477,27 @@ Replace OLDCONTENT with NEWCONTENT."
:description
"Grep SEARCH-STRING in directory files."))
+(defun ellama-tools-grep-in-file-tool (search-string file)
+ "Grep SEARCH-STRING in FILE."
+ (shell-command-to-string (format "grep --color=never -nh %s %s"
search-string file)))
+
+(defun ellama-tools-grep-in-file-tool-confirm (search-string file)
+ "Confirm grepping for SEARCH-STRING in FILE."
+ (ellama-tools-confirm
+ (format "Allow grepping for %s in file %s?" search-string file)
+ 'ellama-tools-grep-in-file-tool
+ (list search-string file)))
+
+(add-to-list
+ 'ellama-tools-available
+ (llm-make-tool :function
+ 'ellama-tools-grep-in-file-tool-confirm
+ :name "grep_in_file"
+ :args (list
+ '(:name "search_string" :type string :description
"String to search for.")
+ '(:name "file" :type file :description "File to search
in."))
+ :description "Grep SEARCH-STRING in FILE."))
+
(defun ellama-tools-list-tool ()
"List all available tools."
(json-encode (mapcar