branch: externals/ellama
commit 9205cfb755adc5d488502631660f8909f014560b
Author: Sergey Kostyaev <[email protected]>
Commit: Sergey Kostyaev <[email protected]>
Scroll agent loop prompt insertions
Trigger auto-scroll after inserting the plan-and-act initial prompt,
controller continuation prompts, and subagent main-agent prompts. Cover each
insertion path with tests that verify the affected chat buffer is passed to the
scroll helper.
---
ellama-tools.el | 3 +++
ellama.el | 1 +
tests/test-ellama-tools.el | 14 ++++++++++++--
tests/test-ellama.el | 7 ++++++-
4 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/ellama-tools.el b/ellama-tools.el
index 2021b65e51..1a97a8369d 100644
--- a/ellama-tools.el
+++ b/ellama-tools.el
@@ -47,6 +47,7 @@
(declare-function ellama-get-session-buffer "ellama" (id))
(declare-function ellama-get-nick-prefix-for-mode "ellama" ())
(declare-function ellama--fill-long-lines "ellama" (string))
+(declare-function ellama--scroll "ellama" (&optional buffer point))
(declare-function ellama-image-file-p "ellama" (file-name))
(declare-function ellama--image-mime-type "ellama" (file-name))
(declare-function ellama--file-size "ellama" (file-name))
@@ -4215,6 +4216,7 @@ result/blocked fields instead."
"\n\n"
(ellama-get-nick-prefix-for-mode)
" " ellama-assistant-nick ":\n")
+ (ellama--scroll buffer (point))
(point))))
(defun ellama-tools--agent-apply-text-update (session text)
@@ -4470,6 +4472,7 @@ Return insertion point for sub-agent response."
(insert prefix " Main agent:\n"
(ellama--fill-long-lines description) "\n\n"
prefix " " ellama-assistant-nick ":\n")
+ (ellama--scroll buffer (point))
(point)))))
(defun ellama-tools--make-report-result-tool (callback session)
diff --git a/ellama.el b/ellama.el
index 038210c794..01cf120a09 100644
--- a/ellama.el
+++ b/ellama.el
@@ -4188,6 +4188,7 @@ after compaction."
(ellama--fill-long-lines prompt) "\n\n"
(ellama-get-nick-prefix-for-mode)
" " ellama-assistant-nick ":\n"))
+ (ellama--scroll buffer)
(let* ((agent
(if (and (not create-session)
(ellama-tools-agent-active-p session))
diff --git a/tests/test-ellama-tools.el b/tests/test-ellama-tools.el
index e3fcd68663..e058e753e1 100644
--- a/tests/test-ellama-tools.el
+++ b/tests/test-ellama-tools.el
@@ -3252,6 +3252,7 @@ Return list with result and prompt."
:completed nil
:system "System"))))
(stream-call nil)
+ (scroll-call nil)
(state-text
"BEGIN_ELLAMA_AGENT_STATE
phase: acting
@@ -3270,7 +3271,10 @@ END_ELLAMA_AGENT_STATE"))
buffer)))
((symbol-function 'ellama-stream)
(lambda (prompt &rest args)
- (setq stream-call (list prompt args)))))
+ (setq stream-call (list prompt args))))
+ ((symbol-function 'ellama--scroll)
+ (lambda (&optional scroll-buffer point)
+ (setq scroll-call (list scroll-buffer point)))))
(let ((ellama--current-session nil))
(funcall
(ellama-tools--make-agent-loop-handler
@@ -3292,6 +3296,7 @@ END_ELLAMA_AGENT_STATE"))
(car stream-call)))
(should (string-match-p "Next pending item: Inspect code"
(car stream-call)))
+ (should (eq (car scroll-call) buffer))
(with-current-buffer buffer
(should (string-match-p "Ellama Agent Plan:"
(buffer-string)))
@@ -3581,6 +3586,7 @@ END_ELLAMA_AGENT_STATE"))
(role-tool (llm-make-tool :name "read_file" :function #'ignore))
(system "System")
(stream-call nil)
+ (scroll-call nil)
(updated-extra nil)
(session
(make-ellama-session
@@ -3606,7 +3612,10 @@ END_ELLAMA_AGENT_STATE"))
(setq updated-extra extra)))
((symbol-function 'ellama-stream)
(lambda (prompt &rest args)
- (setq stream-call (list prompt args)))))
+ (setq stream-call (list prompt args))))
+ ((symbol-function 'ellama--scroll)
+ (lambda (&optional scroll-buffer point)
+ (setq scroll-call (list scroll-buffer point)))))
(with-temp-buffer
(let ((ellama--current-session nil))
(funcall
@@ -3625,6 +3634,7 @@ END_ELLAMA_AGENT_STATE"))
(should (equal (plist-get (cadr stream-call) :system)
system))
(should (functionp (plist-get (cadr stream-call) :on-done)))
+ (should (eq (car scroll-call) worker-buffer))
(with-current-buffer worker-buffer
(should (string-match-p "Previous response"
(buffer-string)))
diff --git a/tests/test-ellama.el b/tests/test-ellama.el
index 02daf841ff..230a3e452a 100644
--- a/tests/test-ellama.el
+++ b/tests/test-ellama.el
@@ -1060,7 +1060,8 @@ detailed comparison to help you decide:
:prompt nil
:extra '(:uid "agent-session-uid")))
(session-buffer (generate-new-buffer " *ellama-agent-chat-test*"))
- (stream-call nil))
+ (stream-call nil)
+ (scroll-call nil))
(unwind-protect
(progn
(with-current-buffer session-buffer
@@ -1068,6 +1069,9 @@ detailed comparison to help you decide:
(ellama--register-session session session-buffer t)
(cl-letf (((symbol-function 'display-buffer)
(lambda (&rest _args) nil))
+ ((symbol-function 'ellama--scroll)
+ (lambda (&optional buffer point)
+ (setq scroll-call (list buffer point))))
((symbol-function 'ellama-stream)
(lambda (prompt &rest args)
(setq stream-call (list prompt args)))))
@@ -1087,6 +1091,7 @@ detailed comparison to help you decide:
"agent_update_plan"
"agent_report_result"
"read_file")))
+ (should (eq (car scroll-call) session-buffer))
(with-current-buffer session-buffer
(let ((text (buffer-string)))
(should (string-match-p "User:" text))