Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions agent-shell.el
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,15 @@ OUTGOING-REQUEST-DECORATOR (passed through to `acp-make-client')."
(defvar-local agent-shell--transcript-file nil
"Path to the shell's transcript file.")

(defvar-local agent-shell--temp-directory nil
"When non-nil, a temporary directory to delete when the buffer is killed.")

(defun agent-shell--cleanup-temp-directory ()
"Delete the temporary directory associated with the current buffer."
(when (and agent-shell--temp-directory
(file-directory-p agent-shell--temp-directory))
(delete-directory agent-shell--temp-directory t t)))

(defvar agent-shell--shell-maker-config nil)

;;;###autoload
Expand Down Expand Up @@ -1039,10 +1048,9 @@ When NO-DISPLAY is non-nil, don't display the shell buffer."
:config config
:no-display no-display)))
(with-current-buffer shell-buffer
(setq agent-shell--temp-directory location)
(add-hook 'kill-buffer-hook
(lambda ()
(when (file-directory-p location)
(delete-directory location t t)))
#'agent-shell--cleanup-temp-directory
nil t))
shell-buffer))

Expand Down Expand Up @@ -1106,12 +1114,16 @@ Works from both shell and viewport buffers."
(config (map-elt (buffer-local-value 'agent-shell--state shell-buffer)
:agent-config))
(shell-dir (buffer-local-value 'default-directory shell-buffer))
(temp-dir (buffer-local-value 'agent-shell--temp-directory shell-buffer))
;; Remember where the shell is currently displayed
(windows (get-buffer-window-list shell-buffer nil t)))
(with-current-buffer shell-buffer
(when (and (agent-shell--active-requests-p (agent-shell--state))
(not (y-or-n-p "Agent is busy. Restart anyway?")))
(user-error "Cancelled")))
(user-error "Cancelled"))
;; Prevent the temp directory from being deleted during restart.
(when temp-dir
(remove-hook 'kill-buffer-hook #'agent-shell--cleanup-temp-directory t)))
(kill-buffer shell-buffer)
(let* ((default-directory shell-dir)
(new-shell-buffer (agent-shell--start
Expand All @@ -1121,6 +1133,12 @@ Works from both shell and viewport buffers."
:new-session t
:no-focus t)))
(shell-maker-set-buffer-name new-shell-buffer shell-buffer-name)
(when temp-dir
(with-current-buffer new-shell-buffer
(setq agent-shell--temp-directory temp-dir)
(add-hook 'kill-buffer-hook
#'agent-shell--cleanup-temp-directory
nil t)))
(if (or from-viewport agent-shell-prefer-viewport-interaction)
(agent-shell-viewport--show-buffer
:shell-buffer new-shell-buffer)
Expand Down
Loading