aboutsummaryrefslogtreecommitdiff
path: root/modules/ai-term-sessions.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-18 14:06:46 -0500
committerCraig Jennings <c@cjennings.net>2026-07-18 14:06:46 -0500
commiteeafb35ff25a8fe060fd1f98b51a758bf88e2aa1 (patch)
treef403d84ea5e90998dcda199c9f806d6cedd690bc /modules/ai-term-sessions.el
parentb426cd089503053fd203a034f3cbbe173252d5c3 (diff)
downloaddotemacs-eeafb35ff25a8fe060fd1f98b51a758bf88e2aa1.tar.gz
dotemacs-eeafb35ff25a8fe060fd1f98b51a758bf88e2aa1.zip
fix(ai-term): key teardown session names off the buffer name
ghostel retargets default-directory via OSC 7 on every cd in the agent shell, so close (and quit with no project argument) computed the wrong aiv- session name after a cd. The kill then missed the real session and orphaned the agent, or hit a different project's session. The buffer name ("agent [basename]") never changes, so teardown now derives the basename from it.
Diffstat (limited to 'modules/ai-term-sessions.el')
-rw-r--r--modules/ai-term-sessions.el14
1 files changed, 14 insertions, 0 deletions
diff --git a/modules/ai-term-sessions.el b/modules/ai-term-sessions.el
index fab6b0a6..58532f7e 100644
--- a/modules/ai-term-sessions.el
+++ b/modules/ai-term-sessions.el
@@ -65,6 +65,20 @@ the start so names like \"foo agent [bar]\" do not match."
(buffer-live-p buffer)
(string-prefix-p cj/--ai-term-name-prefix (buffer-name buffer))))
+(defun cj/--ai-term-buffer-basename (buffer)
+ "Return the project basename embedded in BUFFER's AI-term name, or nil.
+
+The buffer name is \"agent [<basename>]\" (see
+`cj/--ai-term-buffer-name') and never changes for the buffer's life,
+unlike `default-directory', which ghostel retargets via OSC 7 every time
+the shell cds. Teardown paths must key tmux-session lookups off this,
+not the directory, or a close after a cd kills the wrong aiv- session.
+Returns nil when BUFFER is not a live AI-term buffer."
+ (when (cj/--ai-term-buffer-p buffer)
+ (let ((name (buffer-name buffer)))
+ (when (string-suffix-p "]" name)
+ (substring name (length cj/--ai-term-name-prefix) -1)))))
+
(defun cj/--ai-term-agent-buffers ()
"Return the live AI-term buffers in `buffer-list' order.