Skip to content

Commit ab62514

Browse files
committed
feat: open shell buffer from queue buffer
1 parent e909feb commit ab62514

2 files changed

Lines changed: 53 additions & 7 deletions

File tree

agent-shell-queue.el

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ before calling the format's serialize helper.")
435435
(agent-shell-queue-store-items agent-shell-queue--store)))
436436

437437
(defun agent-shell-queue-unpause-all-sessions ()
438-
"Clear the per-session pause list, resuming all individually paused sessions."
438+
"Clear the per-session pause list, resuming all individually paused sessions.
439+
When the global queue is also paused, prompts to resume it as well."
439440
(interactive)
440441
(setf (agent-shell-queue-queue-session-paused agent-shell-queue--queue) nil)
441442
(seq-do (lambda (item)
@@ -445,7 +446,9 @@ before calling the format's serialize helper.")
445446
(agent-shell-queue--save)
446447
(message "agent-shell-queue: all session pauses cleared")
447448
(agent-shell-queue--refresh-buffer)
448-
(unless (agent-shell-queue-queue-paused agent-shell-queue--queue)
449+
(if (agent-shell-queue-queue-paused agent-shell-queue--queue)
450+
(when (y-or-n-p "Global queue is paused; resume it too? ")
451+
(agent-shell-queue-resume))
449452
(seq-do (lambda (bucket)
450453
(when-let* ((buf (get-buffer (car bucket)))
451454
(_ (buffer-live-p buf)))
@@ -3006,6 +3009,12 @@ and the queue advances to the next item."
30063009
:annotation "Remove background task flag"
30073010
:if (lambda () (and (not (memq (agent-shell-queue--iv-status) '(done running aborted)))
30083011
(agent-shell-queue--iv-bg-p))))
3012+
(list :key "O"
3013+
:label "Open shell buffer"
3014+
:cmd 'agent-shell-queue-item-view-open-shell
3015+
:group "Manage Task"
3016+
:annotation "Switch to this item's target shell buffer"
3017+
:if nil)
30093018
(list :key "i"
30103019
:label "Inspect raw"
30113020
:cmd 'agent-shell-queue-item-view-inspect
@@ -4040,6 +4049,24 @@ function, offer to create a new buffer of the same type."
40404049
(pop-to-buffer new-buf)))
40414050
(user-error "Shell buffer %s is not live" buf-name)))))
40424051

4052+
(defun agent-shell-queue-item-view-open-shell ()
4053+
"Switch to the shell buffer for the item shown in this view.
4054+
If the buffer is not live and the item's executor provides a create
4055+
function, offer to create a new buffer of the same type."
4056+
(interactive)
4057+
(when-let* ((buf-name (agent-shell-queue--iv-target)))
4058+
(if-let* ((buf (get-buffer buf-name)))
4059+
(pop-to-buffer buf)
4060+
(if-let* ((item (agent-shell-queue--iv-item))
4061+
(executor-fn (agent-shell-queue-item-executor item))
4062+
(executor-name (agent-shell-queue--executor-name executor-fn))
4063+
(entry (agent-shell-queue--find-executor executor-name))
4064+
(create-fn (agent-shell-queue-executor-create entry)))
4065+
(when (y-or-n-p (format "Buffer %s is not live. Create a new one? " buf-name))
4066+
(when-let* ((new-buf (funcall create-fn)))
4067+
(pop-to-buffer new-buf)))
4068+
(user-error "Shell buffer %s is not live" buf-name)))))
4069+
40434070
;;;###autoload
40444071
(defun agent-shell-queue-capture (&optional buf)
40454072
"Open a capture buffer targeting BUF (nil adds to the unassigned queue).
@@ -4204,7 +4231,9 @@ format switch. Changes take effect immediately via `agent-shell-queue-buffer-re
42044231
:if (lambda () (and (agent-shell-queue--point-editable-p)
42054232
(agent-shell-queue--point-bg-p))))
42064233
("C-d" "Destructive…" agent-shell-queue-destructive-menu
4207-
:if agent-shell-queue--point-not-running-p)]
4234+
:if agent-shell-queue--point-not-running-p)
4235+
("O" "Open shell for item at point" agent-shell-queue-buffer-open-shell
4236+
:if agent-shell-queue--point-item)]
42084237
["Move / Assign" :if agent-shell-queue--point-editable-p
42094238
("M-<up>" "Move up" agent-shell-queue-buffer-move-up
42104239
:if agent-shell-queue--point-editable-p)
@@ -4241,8 +4270,6 @@ format switch. Changes take effect immediately via `agent-shell-queue-buffer-re
42414270
("v" "Export scope to YAML" agent-shell-queue-export)
42424271
("F" "Flush to disk" agent-shell-queue-flush)
42434272
("D" "Show disk state" agent-shell-queue-show-disk-state)
4244-
("O" "Open shell for item at point" agent-shell-queue-buffer-open-shell
4245-
:if agent-shell-queue--point-item)
42464273
("=" "Inspect item raw…" agent-shell-queue-buffer-inspect-item
42474274
:if agent-shell-queue--point-item)]
42484275
["Display"

test/test-agent-shell-queue.el

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ which populates item.response from the shell buffer content."
11571157
(kill-buffer buf)))))
11581158

11591159
(ert-deftest agent-shell-queue/unpause-all-sessions-skips-dispatch-when-globally-paused ()
1160-
"unpause-all-sessions does not dispatch when the global queue is paused."
1160+
"unpause-all-sessions does not dispatch when the global queue is paused and user declines."
11611161
(agent-shell-queue-test/isolate
11621162
(let ((dispatched nil)
11631163
(buf (get-buffer-create " *asq-unpause-global-paused-test*")))
@@ -1168,11 +1168,30 @@ which populates item.response from the shell buffer content."
11681168
(agent-shell-queue-test/make-item "q-1" "p" 'blocked.runner nil))))
11691169
(setf (agent-shell-queue-queue-paused agent-shell-queue--queue) t)
11701170
(cl-letf (((symbol-function 'agent-shell-queue--send-next-for-buffer)
1171-
(lambda (b) (push (buffer-name b) dispatched))))
1171+
(lambda (b) (push (buffer-name b) dispatched)))
1172+
((symbol-function 'y-or-n-p) (lambda (_) nil)))
11721173
(agent-shell-queue-unpause-all-sessions))
11731174
(should-not dispatched))
11741175
(kill-buffer buf)))))
11751176

1177+
(ert-deftest agent-shell-queue/unpause-all-sessions-resumes-global-when-confirmed ()
1178+
"unpause-all-sessions calls resume when globally paused and user confirms."
1179+
(agent-shell-queue-test/isolate
1180+
(let ((resumed nil)
1181+
(buf (get-buffer-create " *asq-unpause-global-resume-test*")))
1182+
(unwind-protect
1183+
(progn
1184+
(setf (agent-shell-queue-store-items agent-shell-queue--store)
1185+
(list (list (buffer-name buf)
1186+
(agent-shell-queue-test/make-item "q-1" "p" 'blocked.runner nil))))
1187+
(setf (agent-shell-queue-queue-paused agent-shell-queue--queue) t)
1188+
(cl-letf (((symbol-function 'agent-shell-queue-resume)
1189+
(lambda () (setq resumed t)))
1190+
((symbol-function 'y-or-n-p) (lambda (_) t)))
1191+
(agent-shell-queue-unpause-all-sessions))
1192+
(should resumed))
1193+
(kill-buffer buf)))))
1194+
11761195
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11771196
;;; Dispatch: editing-ids and buffer-paused prevent sends
11781197

0 commit comments

Comments
 (0)