branch: externals/ellama
commit 0207309a393ade9b195511c9ca5dd459e94e93e1
Merge: 5aaa98da44 351e0013c6
Author: Sergey Kostyaev <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #382 from s-kostyaev/make-shell-command-tool-async
Make shell command tool async
---
NEWS.org | 11 +++++++++++
ellama-tools.el | 25 ++++++++++++++++++++-----
ellama.el | 2 +-
skills/changelog/SKILL.md | 4 ++--
4 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index 30a8325db1..a7796271d5 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,3 +1,14 @@
+* Version 1.12.7
+- Fix bug when only single tool was available. This change fixes a duplicate
+ checking issue in the tool list by using ~llm-tool-name~ instead of
+ ~plist-get~ for proper duplicate detection.
+- Make ~shell_command~ tool async. The tool now executes commands
asynchronously
+ using a callback function for better performance.
+- Trim shell command output and return nil for async tools. This ensures proper
+ return value handling for async commands to maintain compatibility with the
+ llm library.
+- Add --no-pager flag to git commands in changelog generation. This prevents
+ output paging and ensures clean command output.
* Version 1.12.6
- Simplify file writing in ~ellama-tools-write-file-tool~. Replaced temp
buffer-based file writing with write-region to simplify implementation and
diff --git a/ellama-tools.el b/ellama-tools.el
index 0868cfb85e..1310be7106 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -243,8 +243,8 @@ TOOL-PLIST is a property list in the format expected by
`llm-make-tool'."
'ellama-tools-available
(apply 'llm-make-tool (ellama-tools-wrap-with-confirm tool-plist))
nil (lambda (a b)
- (string= (plist-get a :name)
- (plist-get b :name)))))
+ (string= (llm-tool-name a)
+ (llm-tool-name b)))))
(defun ellama-tools-enable-by-name-tool (name)
"Add to `ellama-tools-enabled' each tool that matches NAME."
@@ -512,15 +512,30 @@ 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
+ ;; we need to trim trailing newline
+ (string-trim-right
+ (with-current-buffer buf (buffer-string))
+ "\n"))
+ (kill-buffer buf)))))
+ ;; async tool should always return nil
+ ;; to work properly with the llm library
+ nil)
(ellama-tools-define-tool
'(:function
ellama-tools-shell-command-tool
:name
"shell_command"
+ :async t
:args
((:name
"cmd"
diff --git a/ellama.el b/ellama.el
index a8a96b7095..ae541f9259 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.6
+;; Version: 1.12.7
;; SPDX-License-Identifier: GPL-3.0-or-later
;; Created: 8th Oct 2023
diff --git a/skills/changelog/SKILL.md b/skills/changelog/SKILL.md
index 3bd4e4215b..8642cae6ce 100644
--- a/skills/changelog/SKILL.md
+++ b/skills/changelog/SKILL.md
@@ -5,14 +5,14 @@ description: Use this skill to generate changelog.
# Generating changelog
-Call shell_command tool with "git log --reverse main..HEAD" argument. Based on
+Call shell_command tool with "git --no-pager log --reverse main..HEAD"
argument. Based on
the output write changelog in org-mode list format. Use org quoting
(~quoted-text~) instead of markdown quoting (`quoted-text`). Every changelog
element should be ended with full stop. Changelog shouldn't be too short or too
long, use detailed description for major changes and concise description for
minor changes.
-Call shell_command tools with "git tag -l --points-at=main" argument to see
+Call shell_command tools with "git --no-pager tag -l --points-at=main"
argument to see
previously released version. Based on this information and minority/majority of
the changes you can fill version variable. If you are not sure, ask the user
using ask_user tool with your variants of the version.