From 2cde87f08990adf78d5bc67a43a838f19277a792 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 11 May 2026 13:27:26 -0500 Subject: feat(ai-vterm): order the project picker by most-recently-used The picker's active group (projects with a live tmux session) used to sort alphabetically. It now leads with projects opened this session, most-recent first, then the rest of the active group alpha, then the no-session group alpha. An in-session list (`cj/--ai-vterm-mru'), pushed to the front by `cj/--ai-vterm-show-or-create' on every open, drives the order. An empty list reproduces the old alphabetical behavior. I also pulled in a fix: `cj/--ai-vterm-tmux-session-name' now sanitizes `.' and `:' in the basename to `_'. tmux disallows those chars in session names and silently rewrites them, so `.emacs.d' really runs in session `aiv-_emacs_d', not `aiv-.emacs.d'. The computed name never matched, so `.emacs.d' was wrongly treated as having no session and landed in the no-session picker group. (A crash-recovery would also spawn a duplicate instead of reattaching.) Sanitizing the same way tmux does keeps the names in sync. --- tests/test-ai-vterm--sort-candidates.el | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'tests/test-ai-vterm--sort-candidates.el') diff --git a/tests/test-ai-vterm--sort-candidates.el b/tests/test-ai-vterm--sort-candidates.el index 5e3d760a..26953604 100644 --- a/tests/test-ai-vterm--sort-candidates.el +++ b/tests/test-ai-vterm--sort-candidates.el @@ -3,8 +3,10 @@ ;;; Commentary: ;; The project picker lists candidates with a live tmux session first ;; (so an agent that survived an Emacs crash is easy to get back to), -;; then everything else. Within each group the order is alphabetical -;; by abbreviated path. +;; then everything else. Within the active group, projects opened this +;; session (`cj/--ai-vterm-mru') lead, most-recent first; the rest of the +;; active group, and the whole no-session group, sort alphabetically by +;; abbreviated path. With an empty MRU it's just active-first-then-alpha. ;;; Code: @@ -40,6 +42,27 @@ "Boundary: no candidates -> nil." (should (null (cj/--ai-vterm-sort-candidates nil '("aiv-foo"))))) +(ert-deftest test-ai-vterm--sort-candidates-active-group-mru-first () + "Normal: within the active group, recently-opened projects lead in MRU +order; active dirs not opened this session fall after them alpha; the +no-session group trails, alpha." + (let ((cj/ai-vterm-tmux-session-prefix "aiv-") + (cj/--ai-vterm-mru '("/c/baz" "/c/foo"))) + (should (equal (cj/--ai-vterm-sort-candidates + '("/c/foo" "/c/bar" "/c/baz" "/c/qux") + '("aiv-foo" "aiv-bar" "aiv-baz")) + '("/c/baz" "/c/foo" "/c/bar" "/c/qux"))))) + +(ert-deftest test-ai-vterm--sort-candidates-mru-does-not-bump-inactive () + "Boundary: an MRU dir whose tmux session has died sorts alpha in the +no-session group, not at the top." + (let ((cj/ai-vterm-tmux-session-prefix "aiv-") + (cj/--ai-vterm-mru '("/c/zed"))) + (should (equal (cj/--ai-vterm-sort-candidates + '("/c/foo" "/c/zed" "/c/bar") + '("aiv-foo")) + '("/c/foo" "/c/bar" "/c/zed"))))) + (ert-deftest test-ai-vterm--session-active-p-matches-by-derived-name () "Normal: a dir is active when its derived session name is in the set." (let ((cj/ai-vterm-tmux-session-prefix "aiv-")) -- cgit v1.2.3