From 4000330e5e6536f64f404c1cabc8dc86d9556bb5 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 11 May 2026 07:18:20 -0500 Subject: refactor(ai-vterm): rename Claude-specific names to a generic "agent" I may add other terminal agents to this launcher (aider, an open-source LLM TUI), so the buffer prefix, the user knob, and the internal helpers shouldn't say "Claude". The module name (ai-vterm) and the `cj/ai-vterm-*` customs were already generic. This finishes the job: - buffer prefix `claude []` -> `agent []` (the `defconst` and the matching display-buffer-alist regex move together) - `cj/ai-vterm-claude-command` -> `cj/ai-vterm-agent-command` (the default still runs the `claude` CLI, with a docstring note on swapping it) - `cj/--ai-vterm-claude-buffers` / `-displayed-claude-window` / `-reuse-existing-claude` -> `-agent-*`, and their test files renamed to match - prose in the module commentary and docstrings, plus the matching test docstrings and buffer-name literals `vterm-config.el` hardcodes the same buffer prefix in `cj/--vterm-toggle-buffer-p` (F12 excludes agent buffers from its candidate set), so that literal moved too. Collapsing it into the shared `cj/--ai-vterm-name-prefix` is a cleanup for another day. After a reload, a project's buffer opens as `agent [foo]` instead of `claude [foo]`. Old buffers keep their names until killed. I also corrected two stale `eshell-vterm-config.el` references in ai-vterm.el docstrings (that module was split into `vterm-config.el`). Two things keep saying "Claude": the `cj/ai-vterm-agent-command` default value (the actual CLI), and the "Claude Code" example in `vterm-config.el`'s cursor-restore docstring (a concrete TUI example, not branding). 90 tests pass. `make validate-modules` clean. --- tests/test-ai-vterm--reuse-existing-claude.el | 99 --------------------------- 1 file changed, 99 deletions(-) delete mode 100644 tests/test-ai-vterm--reuse-existing-claude.el (limited to 'tests/test-ai-vterm--reuse-existing-claude.el') diff --git a/tests/test-ai-vterm--reuse-existing-claude.el b/tests/test-ai-vterm--reuse-existing-claude.el deleted file mode 100644 index 195e50a2..00000000 --- a/tests/test-ai-vterm--reuse-existing-claude.el +++ /dev/null @@ -1,99 +0,0 @@ -;;; test-ai-vterm--reuse-existing-claude.el --- Tests for reuse-existing-claude action -*- lexical-binding: t; -*- - -;;; Commentary: -;; The action looks for any window in the selected frame whose buffer -;; satisfies `cj/--ai-vterm-buffer-p'. When found, swaps that -;; window's buffer for the one being displayed and returns the -;; window. When not found, returns nil so the next action in the -;; chain runs. -;; -;; This is the action that keeps C-F9 (project-switch) from stealing -;; a non-claude window when the user is focused inside claude. - -;;; Code: - -(require 'ert) - -(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) -(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory)) -(require 'ai-vterm) -(require 'testutil-vterm-buffers) - -(ert-deftest test-ai-vterm--reuse-existing-claude-swaps-buffer-when-window-exists () - "Normal: a claude window exists -> swap its buffer, return the window." - (cj/test--kill-claude-buffers) - (save-window-excursion - (delete-other-windows) - (let ((existing (get-buffer-create "claude [existing]")) - (new-buf (get-buffer-create "claude [new]")) - (split (split-window (selected-window) nil 'right))) - (unwind-protect - (progn - (set-window-buffer split existing) - (let ((result (cj/--ai-vterm-reuse-existing-claude new-buf nil))) - (should (eq result split)) - (should (eq (window-buffer split) new-buf)))) - (kill-buffer existing) - (kill-buffer new-buf))))) - -(ert-deftest test-ai-vterm--reuse-existing-claude-returns-nil-when-no-claude-window () - "Boundary: no claude window in frame -> nil (chain continues to next action)." - (cj/test--kill-claude-buffers) - (save-window-excursion - (delete-other-windows) - (let ((new-buf (get-buffer-create "claude [no-existing]"))) - (unwind-protect - (should (null (cj/--ai-vterm-reuse-existing-claude new-buf nil))) - (kill-buffer new-buf))))) - -(ert-deftest test-ai-vterm--reuse-existing-claude-leaves-non-claude-windows-alone () - "Boundary: only non-claude windows in frame -> nil; other windows untouched." - (cj/test--kill-claude-buffers) - (save-window-excursion - (delete-other-windows) - (let ((code-buf (get-buffer-create "*test-code-buffer*")) - (new-claude (get-buffer-create "claude [new-here]")) - (other-win (split-window (selected-window) nil 'right))) - (unwind-protect - (progn - (set-window-buffer (selected-window) code-buf) - (set-window-buffer other-win code-buf) - (let ((result (cj/--ai-vterm-reuse-existing-claude - new-claude nil))) - (should (null result)) - (should (eq (window-buffer (selected-window)) code-buf)) - (should (eq (window-buffer other-win) code-buf)))) - (kill-buffer code-buf) - (kill-buffer new-claude))))) - -(ert-deftest test-ai-vterm--reuse-existing-claude-preserves-non-claude-window-when-swapping () - "Normal: swap claude window only; the other window keeps its buffer. - -This is the C-F9-from-claude regression: with claude at the bottom -and code on top, switching projects must replace the bottom window's -buffer, not the top window's." - (cj/test--kill-claude-buffers) - (save-window-excursion - (delete-other-windows) - (let* ((code-buf (get-buffer-create "*test-code-top*")) - (claude-a (get-buffer-create "claude [a]")) - (claude-b (get-buffer-create "claude [b]")) - (top-win (selected-window)) - (bottom-win (split-window top-win nil 'below))) - (unwind-protect - (progn - (set-window-buffer top-win code-buf) - (set-window-buffer bottom-win claude-a) - ;; Focus the claude window -- this is the regression scenario. - (select-window bottom-win) - (let ((result (cj/--ai-vterm-reuse-existing-claude - claude-b nil))) - (should (eq result bottom-win)) - (should (eq (window-buffer bottom-win) claude-b)) - (should (eq (window-buffer top-win) code-buf)))) - (kill-buffer code-buf) - (kill-buffer claude-a) - (kill-buffer claude-b))))) - -(provide 'test-ai-vterm--reuse-existing-claude) -;;; test-ai-vterm--reuse-existing-claude.el ends here -- cgit v1.2.3