aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-09 12:00:30 -0500
committerCraig Jennings <c@cjennings.net>2026-05-09 12:00:30 -0500
commita29ac8d9f31443279ba5897b13cf5cda49519975 (patch)
treec138750b0c5ed15afa5f78555d8ab35129e141b1 /modules
parent554b32db5da9630fa24fb2abf3f93f21b03ff7a0 (diff)
downloaddotemacs-a29ac8d9f31443279ba5897b13cf5cda49519975.tar.gz
dotemacs-a29ac8d9f31443279ba5897b13cf5cda49519975.zip
feat(ai-vterm): show [running] in picker and F9 redisplays last-used
The C-F9 project picker now flags projects whose claude buffer is alive with a " [running]" suffix on the abbreviated path. I added `cj/--ai-vterm-format-candidate` to compute the display name and routed the picker through it. Before the change, the picker showed every candidate identically, so you couldn't tell at a glance whether picking a project would attach to an existing session or start a fresh one. F9 with two or more alive claude buffers used to open the project picker. That meant after toggling claude-A off, opening claude-B via C-F9, then toggling B off, the next F9 dropped into a picker rather than redisplaying B (the one you just toggled off). I renamed `redisplay-single` to `redisplay-recent` in `cj/--ai-vterm-dispatch` and broadened the trigger from "exactly one alive" to "one or more alive". F9 now redisplays the MRU claude buffer, so it consistently means "toggle THE claude I was last using". The project picker stays explicit on C-F9 for "start a different project", and M-F9 still picks among existing claudes. 2 new tests for the indicator (`format-candidate` flagged + unflagged), 2 dispatch tests renamed to match the new contract. 80 ai-vterm tests pass. Full make test green.
Diffstat (limited to 'modules')
-rw-r--r--modules/ai-vterm.el36
1 files changed, 29 insertions, 7 deletions
diff --git a/modules/ai-vterm.el b/modules/ai-vterm.el
index 670aa43a..9b47e33d 100644
--- a/modules/ai-vterm.el
+++ b/modules/ai-vterm.el
@@ -434,12 +434,28 @@ Returns the buffer."
(display-buffer buf)
buf)))))
+(defun cj/--ai-vterm-format-candidate (path)
+ "Return the display name for PATH in the AI-vterm project picker.
+
+Appends \" [running]\" when the project's claude buffer exists with
+a live process, so the user sees at a glance which projects already
+have a session. Path is abbreviated via `abbreviate-file-name' so
+it reads as ~/code/foo rather than the full home-dir form."
+ (let* ((name (cj/--ai-vterm-buffer-name path))
+ (buf (get-buffer name))
+ (running (and buf (cj/--ai-vterm-process-live-p buf)))
+ (display-path (abbreviate-file-name path)))
+ (if running
+ (format "%s [running]" display-path)
+ display-path)))
+
(defun cj/--ai-vterm-pick-project ()
"Prompt for a Claude-template project; return its absolute path.
Candidates come from `cj/--ai-vterm-candidates'. Display uses
-`abbreviate-file-name' so paths read as ~/code/foo instead of the
-full home-dir form. Signals `user-error' when no candidates exist."
+`cj/--ai-vterm-format-candidate', which abbreviates the path and
+flags projects with a live session via a \" [running]\" suffix.
+Signals `user-error' when no candidates exist."
(let ((candidates (cj/--ai-vterm-candidates)))
(unless candidates
(user-error "No Claude-template projects found under %s"
@@ -448,7 +464,7 @@ full home-dir form. Signals `user-error' when no candidates exist."
cj/ai-vterm-container-roots)
", ")))
(let* ((display-alist
- (mapcar (lambda (p) (cons (abbreviate-file-name p) p))
+ (mapcar (lambda (p) (cons (cj/--ai-vterm-format-candidate p) p))
candidates))
(chosen (completing-read "AI vterm project: "
display-alist nil t)))
@@ -460,8 +476,14 @@ full home-dir form. Signals `user-error' when no candidates exist."
Returns one of:
- (toggle-off . WINDOW) -- claude is displayed in WINDOW; quit it.
-- (redisplay-single . BUFFER) -- exactly one alive claude buffer; show it.
-- (pick-project) -- zero or 2+ alive claude buffers; prompt.
+- (redisplay-recent . BUFFER) -- 1+ alive claude buffers; show MRU.
+- (pick-project) -- zero alive claude buffers; prompt.
+
+When 2+ claude buffers are alive, F9 redisplays the most-recently-
+selected one rather than opening the project picker. C-F9 is the
+explicit \"start a different project\" surface; M-F9 is the explicit
+\"switch among existing claudes\" surface. F9 keeps a single, simple
+job: toggle whichever claude was last in use.
A pure-decision helper so the dispatch logic is exercisable in tests
without firing real `display-buffer' or `quit-window' calls."
@@ -471,7 +493,7 @@ without firing real `display-buffer' or `quit-window' calls."
(t
(let ((buffers (cj/--ai-vterm-claude-buffers)))
(cond
- ((= (length buffers) 1) (cons 'redisplay-single (car buffers)))
+ (buffers (cons 'redisplay-recent (car buffers)))
(t '(pick-project))))))))
(defun cj/--ai-vterm-pick-buffer-candidates (buffers shown-buffer)
@@ -587,7 +609,7 @@ AI-vterm buffers without touching the project list."
(bury-buffer (window-buffer win))
(delete-window win))
nil)
- (`(redisplay-single . ,buf)
+ (`(redisplay-recent . ,buf)
(display-buffer buf)
(unless arg
(let ((w (get-buffer-window buf)))