From 57d417f7a0410f8691d86e5e51b439599f584e68 Mon Sep 17 00:00:00 2001 From: naps62-yolo Date: Wed, 24 Jun 2026 15:41:52 +0000 Subject: [PATCH] feat(maestro): abbreviate paths in spawn dialog recent-dir picker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The working-directory picker showed raw absolute paths (`/home/naps62/...`), unlike the sidebar tree which collapses home to `~` and shrinks leading segments to initials. Reuse the sidebar's abbreviation so both read the same: `/home/naps62/git.naps.pt/naps62/maestro` → `~/g/n/maestro`, with the full path kept in the row tooltip and submitted verbatim. - types.ts: hoist `abbreviateFolderName` (+ a local `escapeHtml`) here so both the sidebar and spawn dialog share one implementation (catalog.ts imports spawn.ts, so the helper can't live in catalog without a cycle). - catalog.ts: import the shared helper instead of its own copy. - spawn.ts: abbreviate each recent-dir row via `abbreviateFolderName(abbreviateCwd(...))`. - styles.css: dim the collapsed stem in the picker too (`.recent-dir .folder-stem`). Co-Authored-By: Claude Opus 4.8 (1M context) --- web/src/catalog.ts | 17 +---------------- web/src/spawn.ts | 8 +++++++- web/src/styles.css | 6 ++++-- web/src/types.ts | 25 +++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/web/src/catalog.ts b/web/src/catalog.ts index f6f2d92..094d0cc 100644 --- a/web/src/catalog.ts +++ b/web/src/catalog.ts @@ -2,7 +2,7 @@ import { killSession } from "./api.js"; import { HUD_TOGGLE_EVENT, isHudEnabled, toggleHud } from "./debug.js"; import { CatalogStore } from "./events.js"; import type { DaemonInfo, Session } from "./types.js"; -import { abbreviateCwd, sessionCwd, sessionName } from "./types.js"; +import { abbreviateCwd, abbreviateFolderName, sessionCwd, sessionName } from "./types.js"; import { openSpawnModal } from "./spawn.js"; import { createThemeToggle } from "./theme.js"; @@ -188,21 +188,6 @@ function countLeaves(node: TreeNode): number { return node.children.reduce((n, c) => n + countLeaves(c), 0); } -/** `~/git.naps.pt/naps62/maestro` → `~/g/n/maestro`: keep the last segment - * verbatim, collapse every earlier one to its first character. Two-or-fewer - * segments are left alone (nothing to gain). Returns escaped HTML with the - * collapsed stem wrapped so CSS can dim it. */ -function abbreviateFolderName(name: string): string { - const parts = name.split("/"); - if (parts.length <= 2) return escapeHtml(name); - const last = parts[parts.length - 1]; - const stem = parts - .slice(0, -1) - .map((p) => (p === "~" ? "~" : Array.from(p)[0] ?? "")) - .join("/"); - return `${escapeHtml(stem)}/${escapeHtml(last)}`; -} - function escapeHtml(s: string): string { return s .replace(/&/g, "&") diff --git a/web/src/spawn.ts b/web/src/spawn.ts index d093b5d..e91fbba 100644 --- a/web/src/spawn.ts +++ b/web/src/spawn.ts @@ -8,6 +8,7 @@ import type { Session, SpawnPreset, } from "./types.js"; +import { abbreviateCwd, abbreviateFolderName } from "./types.js"; /** Seed values for the spawn form — used by "clone" to reopen the dialog with * the same daemon, cwd, command, and name as an existing session. */ @@ -288,8 +289,13 @@ export function openSpawnModal( row.type = "button"; row.className = "recent-row"; row.dataset.cwd = dir.cwd; + // Abbreviate exactly like the sidebar: home → `~`, then collapse leading + // segments to initials (`~/g/n/maestro`). The full path stays in the tooltip + // and `dataset.cwd` (what's actually submitted). + const home = daemons.get(selectedHostId)?.home_dir; + const display = abbreviateFolderName(abbreviateCwd(dir.cwd, home)); row.innerHTML = ` - ${escapeHtml(dir.cwd)} + ${display} ${escapeHtml(dir.last_command)}`; row.addEventListener("click", () => selectRecent(dir)); return row; diff --git a/web/src/styles.css b/web/src/styles.css index 663ea77..423cc45 100644 --- a/web/src/styles.css +++ b/web/src/styles.css @@ -756,8 +756,10 @@ textarea { } /* Earlier path segments collapse to their initial; the trailing segment (the - one that actually names the dir) stays full. Dim the collapsed prefix. */ -.folder-name .folder-stem { + one that actually names the dir) stays full. Dim the collapsed prefix. Shared + by the sidebar tree and the spawn dialog's recent-directory picker. */ +.folder-name .folder-stem, +.recent-dir .folder-stem { color: var(--faint); } diff --git a/web/src/types.ts b/web/src/types.ts index 2cb0f9c..c12952d 100644 --- a/web/src/types.ts +++ b/web/src/types.ts @@ -151,3 +151,28 @@ export function abbreviateCwd(cwd: string, home?: string): string { } return cwd; } + +/** `~/git.naps.pt/naps62/maestro` → `~/g/n/maestro`: keep the last segment + * verbatim, collapse every earlier one to its first character. Two-or-fewer + * segments are left alone (nothing to gain). Returns escaped HTML with the + * collapsed stem wrapped in `.folder-stem` so callers' CSS can dim it. Shared + * by the sidebar tree and the spawn dialog's recent-directory picker so both + * abbreviate paths identically. */ +export function abbreviateFolderName(name: string): string { + const parts = name.split("/"); + if (parts.length <= 2) return escapeHtml(name); + const last = parts[parts.length - 1]; + const stem = parts + .slice(0, -1) + .map((p) => (p === "~" ? "~" : Array.from(p)[0] ?? "")) + .join("/"); + return `${escapeHtml(stem)}/${escapeHtml(last)}`; +} + +function escapeHtml(s: string): string { + return s + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """); +}