Skip to content

feat: show session name on HUD line 1 - #1

Merged
staryxchen merged 1 commit into
mainfrom
worktree-session-name-feature
Jul 17, 2026
Merged

feat: show session name on HUD line 1#1
staryxchen merged 1 commit into
mainfrom
worktree-session-name-feature

Conversation

@staryxchen

Copy link
Copy Markdown
Owner

What

Append the current session name as a trailing segment on HUD line 1, so the status line reads e.g.:

[Claude-Sonnet-4.6-1M] │ my-project  git:(main*) │ session: PR#30777
Context ████░░░░░░ 41.8%
✓ Bash ×32  ✓ Read ×8  ✓ Edit ×5  ✓ WebFetch ×3  ✓ Grep ×2

The session: <name> segment is omitted entirely when the session has no title, so existing sessions render unchanged.

Why

CodeBuddy Code tracks a per-session title (set via the built-in /rename action, or auto-generated as an ai-title), but this information wasn't surfaced in the HUD. Showing it lets you tell sessions apart at a glance in the status line.

How

New get_session_name(transcript_path) in hud.py resolves the name from the same transcript already read for tool stats, but via a separate grep -E 'custom-title|ai-title' pass rather than the 800-line tail window — a rename can fall outside that window in a long session, and title entries are sparse so a full-file grep is cheap.

Resolution matches the UI's getCustomTitle semantics:

  • Return the last custom-title entry's customTitle (set via /rename).
  • Fallback to the last ai-title entry's aiTitle (auto-generated).
  • Return '' when neither exists → the line-1 segment is omitted.

As with the rest of the script, any failure (missing file, grep timeout) returns '' — the status line never crashes.

Coloring

The session: label is CYAN, matching line-1 structural labels (folder, git:). The name is MAGENTA, keeping it visually distinct from the YELLOW branch inside git:(...).

Tests

  • 8 unit tests for get_session_name: missing file, empty transcript, no title entries, custom-title returned, last custom wins, ai-title fallback, custom preferred over ai, empty custom falls back to ai.
  • 3 end-to-end tests: line 1 contains session: <name>; line 1 omits the segment when unnamed; ai-title shown end-to-end.

Full suite: 41 passed.

$ pytest tests/ -q
.........................................                                [100%]
41 passed in 0.30s

Notes

  • grep is added to README Requirements (the script now shells out to git, tail, and grep).
  • No new stdin fields — the statusLine payload has no name/title key (only an opaque session_id), so the name is derived from the transcript.
  • Verified against real transcripts: a custom-title session shows │ session: PR#30777; an ai-title-only session shows the auto-generated title; unnamed sessions are unchanged.

Append the current session name as a trailing segment on line 1, so the
status line reads e.g. `[Model] │ folder git:(branch*) │ session: name`.
The segment is omitted entirely when the session has no title.

The name is resolved from the transcript by get_session_name(): the last
`custom-title` entry's customTitle (set via the built-in /rename action),
falling back to the last `ai-title` entry's aiTitle (auto-generated). This
matches the UI's getCustomTitle semantics. Title entries are read via a
full-file `grep -E 'custom-title|ai-title'` rather than the 800-line tail
window, since a rename can fall outside that window in a long session and
title entries are sparse. As with the rest of the script, any failure
(missing file, grep timeout) returns '' and the segment is omitted — the
status line never crashes.

The `session:` label is CYAN (matching line-1 structural labels `folder`
and `git:`) and the name is MAGENTA, keeping it distinct from the YELLOW
branch.

Tests: 8 unit tests for get_session_name (missing file, empty, no titles,
custom returned, last custom wins, ai fallback, custom preferred over ai,
empty custom falls back to ai) plus 3 end-to-end tests. 41 tests pass.

Signed-off-by: staryxchen <staryxchen@tencent.com>
@staryxchen
staryxchen merged commit 1d96deb into main Jul 17, 2026
3 checks passed
@staryxchen
staryxchen deleted the worktree-session-name-feature branch July 17, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant