Share the path-abbreviation helpers with Rust clients #117

Closed
opened 2026-08-25 12:17:17 +01:00 by naps62-yolo · 0 comments
Collaborator

The TUI sidebar is about to group sessions by project, and its group rows must carry the same label the web's folder rows do. The web builds that label from three functions in web/src/types.ts and web/src/tree.ts:

  • abbreviateCwd(cwd, home) — collapse the daemon's home dir to ~.
  • mergeLinear(folder) — fold a chain of single-child directories into one node, so ~/git.naps.pt/naps62/maestro is one row rather than four nested ones.
  • abbreviateFolderName(name) — keep the last path segment verbatim, collapse every earlier one to its first character: ~/git.naps.pt/naps62/maestro reads ~/g/n/maestro. Two-or-fewer segments are left alone.

Port these to Rust so both clients abbreviate identically. maestro-protocol is the only crate both maestro-tui and maestro-cli already depend on, so put them in a display module there. The web version of abbreviateFolderName returns escaped HTML with the collapsed stem wrapped in .folder-stem; the Rust port must return the stem and the last segment separately instead, so a ratatui caller can style the stem dim without parsing markup.

maestro-cli already has its own abbreviate_dir in crates/maestro-cli/src/sessions.rs:143, doing the same job as abbreviateCwd. Move it into the new module and have the CLI call that, so one implementation serves everyone.

The grouping key is not part of this issue, but the port should cover what feeds it: the web derives a session's group from sessionTreePath (the worktree's base_repo when present, else the session cwd) — mirror that as a helper here too, since the TUI will need exactly the same rule.

Tests: port the web's existing cases, including the linear-chain merge and the two-segment no-op, so a future divergence between the clients fails a test rather than being noticed in a screenshot.

Non-goals: no rendering, no TUI changes. This issue ships helpers and their tests only.

The TUI sidebar is about to group sessions by project, and its group rows must carry the same label the web's folder rows do. The web builds that label from three functions in `web/src/types.ts` and `web/src/tree.ts`: - `abbreviateCwd(cwd, home)` — collapse the daemon's home dir to `~`. - `mergeLinear(folder)` — fold a chain of single-child directories into one node, so `~/git.naps.pt/naps62/maestro` is one row rather than four nested ones. - `abbreviateFolderName(name)` — keep the last path segment verbatim, collapse every earlier one to its first character: `~/git.naps.pt/naps62/maestro` reads `~/g/n/maestro`. Two-or-fewer segments are left alone. Port these to Rust so both clients abbreviate identically. `maestro-protocol` is the only crate both `maestro-tui` and `maestro-cli` already depend on, so put them in a `display` module there. The web version of `abbreviateFolderName` returns escaped HTML with the collapsed stem wrapped in `.folder-stem`; the Rust port must return the stem and the last segment separately instead, so a ratatui caller can style the stem dim without parsing markup. `maestro-cli` already has its own `abbreviate_dir` in `crates/maestro-cli/src/sessions.rs:143`, doing the same job as `abbreviateCwd`. Move it into the new module and have the CLI call that, so one implementation serves everyone. The grouping key is not part of this issue, but the port should cover what feeds it: the web derives a session's group from `sessionTreePath` (the worktree's `base_repo` when present, else the session cwd) — mirror that as a helper here too, since the TUI will need exactly the same rule. Tests: port the web's existing cases, including the linear-chain merge and the two-segment no-op, so a future divergence between the clients fails a test rather than being noticed in a screenshot. Non-goals: no rendering, no TUI changes. This issue ships helpers and their tests only.
naps62-yolo added this to the TUI shell milestone 2026-08-25 12:17:17 +01:00
naps62-yolo added the area/protocoltype/refactordifficulty/medium labels 2026-08-25 12:17:17 +01:00
naps62-yolo added a new dependency 2026-08-25 12:18:57 +01:00
This repo is archived. You cannot comment on issues.
1 Participants
Due Date
No due date set.
Reference: naps62/maestro#117