fix(sidebar): smart path truncation for deeply-nested cwds (#2061)

AN
4d ago
+107-5

Summary

Fixes #2061

Sidebar entries for workspaces with a long shared directory prefix all truncate to identical strings, making it impossible to distinguish them:

Before

~/Desktop/YOKE/Claude Code/Ad...
~/Desktop/YOKE/Claude Code/Ad...
~/Desktop/YOKE/Claude Code/Ad...

After

…/Athlete Merch/nilclub
…/Cartoon Gen Gating/nilclub
…/Sport Routing Admin/nilclub

Implementation

SidebarPathFormatter.shortenedPath now applies smart left-truncation after the existing ~ substitution:

  • If the resulting path has 3 or fewer segments, it is displayed as-is (e.g. ~/projects/cmux unchanged).
  • If it has more than 3 segments, only the last 3 are kept and a …/ prefix is prepended (e.g. ~/a/b/c/d → …/b/c/d).

The threshold (maxDisplaySegments = 3) is a named constant so it can be tuned later without a search-and-replace.

This is a display-only change. No data model, settings, or socket API is affected. Both the vertical and compact branch/directory rows in TabItemView share the same formatter and benefit automatically.

Test plan

  • New unit tests in SidebarPathFormatterTests cover: exact 3-segment path (no truncation), 4-segment path (truncated), long home path, short home path, long absolute path, short absolute path.
  • Existing tests (testShortenedPathReplacesExactHomeDirectory, testShortenedPathReplacesHomeDirectoryPrefix, testShortenedPathLeavesExternalPathUnchanged) still pass unchanged.
  • Build succeeds with xcodebuild on macOS.

🤖 Generated with Claude Code


Summary by cubic

Improve sidebar path display by smartly truncating deep directories so similar entries stay distinguishable. Shows only the last 3 segments with a leading …/; shallow paths are unchanged.

  • Bug Fixes
    • Updated SidebarPathFormatter.shortenedPath to left-truncate after ~ replacement, keeping only the last 3 segments and prefixing …/.
    • Added maxDisplaySegments = 3 for easy tuning and corrected its doc comment example; display-only change used by both sidebar layouts.
    • Added unit tests for 3- vs 4-segment paths, home vs absolute, and long vs short paths.

Summary by CodeRabbit

  • New Features
    • Enhanced sidebar path display with smarter truncation: home directories show as ~ and long paths abbreviate to an ellipsis plus trailing segments for clearer, more readable location display.
  • Tests
    • Added unit tests covering the new truncation and tilde-handling behaviors to ensure consistent display across path varieties.