diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-02 10:33:34 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-02 10:33:34 -0400 |
| commit | 75cf36183811a1a9208baf6d75b56c274debebca (patch) | |
| tree | 5b81eae8299a603cfc2c19fd416f456ca4e39121 /modules/ai-term.el | |
| parent | 82b195278b551839314edf1bfab37d5f54c432cb (diff) | |
| download | dotemacs-75cf36183811a1a9208baf6d75b56c274debebca.tar.gz dotemacs-75cf36183811a1a9208baf6d75b56c274debebca.zip | |
feat(ai-term): auto-set each project's session color on fresh launch
Every project now maps to a stable Claude Code session color: an override alist wins, else a character-sum hash of the project basename picks one of the eight names. When a fresh tmux session is created (never on reattach), a poller waits for the TUI to boot and types /color <name> itself, with the Enter deferred a beat so the slash-command menu can't swallow it. Two refusals keep the injection safe: the bypass banner must be on screen (a bare shell never gets typed into) and the prompt line must still be empty (typed-ahead input is never corrupted).
Diffstat (limited to 'modules/ai-term.el')
| -rw-r--r-- | modules/ai-term.el | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/ai-term.el b/modules/ai-term.el index bd955292..b67245fd 100644 --- a/modules/ai-term.el +++ b/modules/ai-term.el @@ -154,6 +154,33 @@ The /color session accents get their own faces below." "Agent terminal rendering of Claude Code's cyan session color (dupre steel)." :group 'ai-term) +(defvar cj/--ai-term-color-names + '("red" "blue" "green" "yellow" "purple" "orange" "pink" "cyan") + "Claude Code's /color session-color names (v2.1.198's eb array). +The hash fallback in `cj/--ai-term-project-color' indexes into this +list, so its order changes which project lands on which color -- +append rather than reorder if Claude Code grows new names.") + +(defcustom cj/ai-term-project-colors nil + "Alist of (PROJECT-BASENAME . COLOR-NAME) overriding the hashed color. +BASENAME is the project directory's basename as shown in the agent +picker (e.g. \".emacs.d\"); COLOR-NAME is one of +`cj/--ai-term-color-names'. Projects not listed get a deterministic +color hashed from their basename, so every project always comes up in +the same color either way." + :type '(alist :key-type string :value-type string) + :group 'ai-term) + +(defun cj/--ai-term-project-color (dir) + "Return the /color name for project DIR: alist override, else hash. +The fallback sums the basename's characters mod the color count, so the +same project maps to the same color on every machine and session." + (let ((basename (file-name-nondirectory (directory-file-name dir)))) + (or (cdr (assoc-string basename cj/ai-term-project-colors)) + (nth (mod (apply #'+ (string-to-list basename)) + (length cj/--ai-term-color-names)) + cj/--ai-term-color-names)))) + (defvar cj/ai-term-palette-faces '((211 . cj/ai-term-accent) ; bypass banner (fixed, not a /color) (167 . cj/ai-term-color-red) |
