feat: keep the outer terminal window title in sync with the session - #2627
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe change adds ChangesOuter terminal window title
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant PTY
participant App
participant HeadlessServer
participant ForegroundClient
PTY->>App: Report terminal-title change
App->>HeadlessServer: Provide resolved configured title
HeadlessServer->>ForegroundClient: Deliver sanitized title
ForegroundClient->>HeadlessServer: Set or clear API override
HeadlessServer->>ForegroundClient: Deliver override or configured fallback
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
48f3df4 to
7f01988
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
Greptile SummaryThe PR adds configurable synchronization of the outer terminal window title with active server-side session state.
Confidence Score: 5/5The PR appears safe to merge. The previously reported handoff failure is fixed: the active API title override is exported in the handoff manifest and restored before the replacement server starts rendering or accepting client activity, so no blocking failure remains.
|
| Filename | Overview |
|---|---|
| src/server/headless.rs | Adds foreground-client title synchronization and now transfers the API override into and out of live handoffs before rendering begins. |
| src/server/handoff.rs | Extends the backward-compatible handoff manifest with the current API window-title override. |
| src/app/window_title.rs | Renders configured title templates from current server-side workspace, tab, pane, terminal, and hostname state. |
| src/config/window_title.rs | Implements bounded template parsing, diagnostics, token handling, and control-character sanitization. |
| src/app/terminal_titles.rs | Restricts terminal-title synchronization to pending pane sources while preserving sidebar and outer-title update signals. |
| src/render_signal.rs | Tracks terminal-title sources independently from generic and PTY render damage. |
| src/client/mod.rs | Routes server-provided window titles through the shared terminal-effect writer. |
| tests/client_mode.rs | Adds end-to-end PTY coverage for configured titles and focused terminal-title changes. |
Sequence Diagram
sequenceDiagram
participant Pane as Pane PTY
participant App as Server App
participant Server as Headless Server
participant Client as Foreground Client
participant Host as Outer Terminal
Pane->>App: OSC 0/2 title change
App->>App: Update terminal title state
App->>Server: Pending render/title source
Server->>Server: Render ui.window_title template
alt API override is active
Server->>Server: Use api_window_title
end
Server->>Client: ServerMessage::WindowTitle
Client->>Host: Write OSC 0
Note over Server: Live handoff transfers api_window_title
Reviews (6): Last reviewed commit: "fix: make outer window title updates eve..." | Re-trigger Greptile
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 74df9e3a-ec3e-4cce-a864-ad93c9e3e78f
📒 Files selected for processing (18)
docs/next/CHANGELOG.mddocs/next/website/src/content/docs/cli-reference.mdxdocs/next/website/src/content/docs/configuration.mdxdocs/next/website/src/content/docs/ja/cli-reference.mdxdocs/next/website/src/content/docs/ja/configuration.mdxdocs/next/website/src/content/docs/ja/socket-api.mdxdocs/next/website/src/content/docs/socket-api.mdxdocs/next/website/src/content/docs/zh-cn/cli-reference.mdxdocs/next/website/src/content/docs/zh-cn/configuration.mdxdocs/next/website/src/content/docs/zh-cn/socket-api.mdxdocs/next/website/src/data/config-reference.jsonsrc/app/mod.rssrc/app/window_title.rssrc/config.rssrc/config/model.rssrc/config/window_title.rssrc/main.rssrc/server/headless.rs
|
Fixed in ce86589.
|
|
Fixed in 90fb47a. You were right that the replacement server started with
Tests: |
90fb47a to
547487d
Compare
Herdr emulates the terminals in its panes, so an OSC 0/OSC 2 title
written inside a pane stops at Herdr and never reaches the terminal
Herdr itself runs in. That outer title is what window managers read for
title bars, tab bars, and group bars, so it kept showing whatever the
shell or ssh happened to leave behind.
Add `ui.window_title`, rendered from {hostname}, {workspace}, {tab},
{pane}, and {terminal_title}, and push it to the foreground client
whenever it changes. It renders on the server, so {hostname} names the
machine the panes actually run on rather than the machine a thin remote
client runs on, and it is gated on a pending render so an idle loop
never pays for it.
A title is only remembered as delivered once a foreground client takes
it, so the first client to attach is written to rather than skipped.
`client.window_title.set` still wins over the configured title, and
clearing it now hands the title back to `ui.window_title` instead of
only "herdr".
ClientConnected assigns the foreground client directly rather than going through promote_client_to_foreground, so clearing the sent-title cache there missed the case that matters most: attaching a second terminal to a running session. The title was usually unchanged, so the sync returned early and the new terminal kept whatever its shell or ssh had left. Key the cache on the client that received the title instead of relying on every foreground assignment to invalidate it.
Output from a hidden or background pane sets needs_render without setting needs_full_render, and the retained render plan then skips presentation for it entirely. Syncing the title on needs_render meant every coalesced hidden-output tick still formatted, sanitized, and allocated a title that could not have changed, against the hidden-source early exit AGENTS.md requires. Every input to the title is app state, which always requests a full render, so gate on that instead. The one exception is the focused pane's own terminal title, which arrives through PTY parsing, so ask for a full render when that changes and the configured title uses it.
547487d to
1fc207a
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/app/terminal_titles.rs (1)
26-90: 🚀 Performance & Scalability | 🔵 Trivial | ⚖️ Poor tradeoffConsider narrowing the per-pane scan for terminal-title sync.
sync_terminal_titlesscans every workspace, tab, and pane and checkssources.contains(pane_id)for each one.sync_all_terminal_titlesbuildssourcesas the full pane set, so that containment check is always true for the all-titles path.runtime.terminal_title()locks the pane's terminal-core mutex for every scanned pane.
handle_api_request_after_internal_events_drainedcallssync_all_terminal_titles()before dispatching every API request, so every API call now pays this full-pane scan and per-pane terminal-core lock cost, regardless of whether the request needs terminal-title data.Use a direct pane lookup (for example, an existing
find_pane-style index) for the filteredsync_terminal_titlespath, and confirm whethersync_all_terminal_titlescan skip the redundantcontainscheck when it already knows it wants every pane.Source: Path instructions
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6d1d0c0e-c2e0-4bd3-afc8-c6023c7b6cec
📒 Files selected for processing (14)
src/app/api.rssrc/app/mod.rssrc/app/terminal_titles.rssrc/client/mod.rssrc/config.rssrc/config/window_title.rssrc/pane.rssrc/pane/osc.rssrc/pane/terminal.rssrc/render_signal.rssrc/server/handoff.rssrc/server/headless.rssrc/terminal_effects.rstests/client_mode.rs
🚧 Files skipped from review as they are similar to previous changes (3)
- src/config.rs
- src/app/mod.rs
- src/server/headless.rs
1fc207a to
9e0e527
Compare
|
Addressed CodeRabbit’s terminal-title sync performance note in 9e0e527. API requests now snapshot only pending title-source pane IDs, and title synchronization resolves those panes directly instead of scanning and locking every pane runtime. |
|
this was on backlog for a long while. ty! |
Problem
Herdr emulates the terminals in its panes, so an
OSC 0/OSC 2title written inside a pane stops at Herdr and never reaches the terminal Herdr itself runs in. That outer title is what window managers and terminal tab bars read, so it keeps showing whatever the shell orsshhappened to leave behind.It shows up most clearly over SSH.
tmuxhasset-titles on/set-titles-string, so an SSH'd tmux session labels the window with the remote host and window name and a tiled window manager's tab or group bar follows along. Herdr has no equivalent — the only thing that ever writes an outer title is the manualclient.window_title.setAPI.Change
Adds
ui.window_title, a format string rendered against current session state and pushed to the foreground client whenever it changes:Tokens are
{hostname},{workspace},{tab},{pane}(the focused pane's manual name), and{terminal_title}(the focused pane's own terminal title with spinner frames stripped).{{/}}are literal braces, an unknown token is a config diagnostic that leaves the outer title alone, andwindow_title = ""disables the feature.Notes on the design:
{hostname}names the machine the panes actually run on, so it stays correct forherdr --remotethin clients and for runningherdrover SSH — same semantics as tmux's#h. This also reuses the existingServerMessage::WindowTitlepath thatclient.window_title.setalready goes through, rather than adding a second one.client.window_title.setstill wins over the configured title. Clearing it now hands the title back toui.window_titleinstead of only"herdr".Verification
just checkequivalent locally:cargo fmt --check, clippy, 3392 nextest tests, and the maintenance script suites all pass. Six new tests cover template parsing, rendering, the once-per-change push, the API override and hand-back, first-attach delivery, and client promotion.Also driven end to end against a real PTY on a throwaway session, reading the OSC bytes off the wire while switching and renaming the active workspace:
One emission per change, and nothing while idle.
Docs
docs/nextconfiguration guide (English, ja, zh-cn), the config reference data, the generated default config comments, the changelog, and theclient.window_title.clearwording in the CLI and socket API docs.