Show worktree names in workspace hover cards (#2711)

* fix(app): show worktree names in workspace hover cards

Managed worktree paths exposed Paseo's internal directory layout instead of the useful worktree name. Carry the owned worktree root through the sidebar model while preserving the full workspace path as the copy target.

* fix(workspaces): source owned worktree names from daemon

The daemon owns worktree path semantics, so expose the managed worktree slug and let the sidebar model produce a display-ready label. This keeps path parsing out of the hover-card component while preserving the full path for copying.

* fix(app): preserve worktree labels in replica cache
This commit is contained in:
Mohamed Boudra
2026-08-01 05:17:47 +08:00
committed by GitHub
parent d2de309fc3
commit 9d19e90323
15 changed files with 137 additions and 13 deletions
@@ -19,6 +19,8 @@ function makeWorkspace(id: string, statusBucket: SidebarWorkspaceEntry["statusBu
};
const entry: SidebarWorkspaceEntry = {
...placement,
workspaceDirectory: "",
workspaceDirectoryLabel: "",
title: null,
currentBranch: null,
statusBucket,
@@ -34,7 +34,6 @@ import { useBottomSheetModalInternal } from "@gorhom/bottom-sheet";
import type { SidebarWorkspaceEntry } from "@/hooks/use-sidebar-workspaces-list";
import type { PrHint } from "@/git/use-pr-status-query";
import { openExternalUrl } from "@/utils/open-external-url";
import { shortenPath } from "@/utils/shorten-path";
import { copyToClipboard } from "@/utils/copy-to-clipboard";
import { PrBadge } from "@/components/sidebar-workspace-list";
import { useHoverSafeZone } from "@/hooks/use-hover-safe-zone";
@@ -214,7 +213,6 @@ function WorkspaceHoverCardContent({
contentRef: React.RefObject<View | null>;
}): ReactElement | null {
const { t } = useTranslation();
const cwdDisplay = shortenPath(workspace.workspaceDirectory);
const bottomSheetInternal = useBottomSheetModalInternal(true);
const [triggerRect, setTriggerRect] = useState<Rect | null>(null);
const [contentSize, setContentSize] = useState<{ width: number; height: number } | null>(null);
@@ -297,11 +295,11 @@ function WorkspaceHoverCardContent({
testID="hover-card-workspace-branch"
/>
) : null}
{cwdDisplay ? (
{workspace.workspaceDirectoryLabel ? (
<CopyableInfoRow
icon={ThemedFolder}
value={cwdDisplay}
copyValue={workspace.workspaceDirectory ?? ""}
value={workspace.workspaceDirectoryLabel}
copyValue={workspace.workspaceDirectory}
copyLabel={t("workspace.hoverCard.copyPath")}
testID="hover-card-workspace-cwd"
/>
@@ -17,7 +17,8 @@ function ws(
projectViewKey: input.projectViewKey ?? "proj",
projectName: input.projectName ?? "Project",
projectRootPath: input.projectRootPath,
workspaceDirectory: input.workspaceDirectory,
workspaceDirectory: input.workspaceDirectory ?? "",
workspaceDirectoryLabel: input.workspaceDirectoryLabel ?? "",
projectKind: input.projectKind ?? "git",
workspaceKind: input.workspaceKind ?? "worktree",
name: input.name ?? "main",
@@ -64,6 +64,27 @@ describe("createSidebarWorkspaceEntry forge threading", () => {
});
});
describe("createSidebarWorkspaceEntry workspace directory label", () => {
it("uses the daemon-provided slug for a Paseo-owned worktree", () => {
const descriptor = workspaceWithForge(undefined, "https://github.com/acme/repo/pull/42");
descriptor.workspaceDirectory = "/worktrees/feature/packages/app";
descriptor.worktreeSlug = "feature";
const entry = createSidebarWorkspaceEntry({ serverId: "srv", workspace: descriptor });
expect(entry.workspaceDirectoryLabel).toBe("feature");
});
it("shortens the workspace path when the daemon omits a worktree slug", () => {
const descriptor = workspaceWithForge(undefined, "https://github.com/acme/repo/pull/42");
descriptor.workspaceDirectory = "/home/alice/external/feature";
const entry = createSidebarWorkspaceEntry({ serverId: "srv", workspace: descriptor });
expect(entry.workspaceDirectoryLabel).toBe("~/external/feature");
});
});
interface OrderedItem {
key: string;
}
@@ -8,6 +8,7 @@ import type {
WorkspaceStructureProject,
} from "@/projects/workspace-structure";
import { projectDisplayNameFromProjectId } from "@/utils/project-display-name";
import { shortenPath } from "@/utils/shorten-path";
import type { WorkspaceAgentActivity } from "@/utils/workspace-agent-activity";
import { resolveWorkspaceMapKeyByIdentity } from "@/utils/workspace-identity";
@@ -34,6 +35,8 @@ export interface SidebarStatusWorkspacePlacement extends SidebarWorkspacePlaceme
}
export interface SidebarWorkspaceEntry extends SidebarStatusWorkspacePlacement {
workspaceDirectory: string;
workspaceDirectoryLabel: string;
// Raw user-set title (null when the name is derived from branch/directory).
// Prefills the rename input and signals whether a reset is available.
title: string | null;
@@ -155,6 +158,8 @@ export function createSidebarWorkspaceEntry(input: {
projectName: projectNameForWorkspace(input.workspace),
projectRootPath: input.workspace.projectRootPath,
workspaceDirectory: input.workspace.workspaceDirectory,
workspaceDirectoryLabel:
input.workspace.worktreeSlug ?? shortenPath(input.workspace.workspaceDirectory),
projectKind: input.workspace.projectKind,
workspaceKind: input.workspace.workspaceKind,
name: input.workspace.name,
@@ -21,6 +21,7 @@ function workspace(projectKey: string, workspaceId: string): SidebarWorkspaceEnt
projectName: projectKey,
projectRootPath: `/repo/${projectKey}`,
workspaceDirectory: `/repo/${projectKey}/${workspaceId}`,
workspaceDirectoryLabel: `/repo/${projectKey}/${workspaceId}`,
projectKind: "git",
workspaceKind: "worktree",
name: workspaceId,
@@ -94,7 +94,16 @@ function seedSession(): void {
store.setAgents(SERVER_ID, new Map([["agent-1", agent("agent-1")]]));
store.setWorkspaces(
SERVER_ID,
new Map([["workspace-1", normalizeWorkspaceDescriptor(workspace())]]),
new Map([
[
"workspace-1",
normalizeWorkspaceDescriptor({
...workspace(),
workspaceKind: "worktree",
worktreeSlug: "owned-worktree",
}),
],
]),
);
store.setProjects(SERVER_ID, [
normalizeProjectDescriptor({
@@ -172,6 +181,7 @@ describe("ReplicaCache", () => {
expect(Array.from(session?.projects.keys() ?? [])).toEqual(["project-1"]);
expect(session?.agents.get("agent-1")?.updatedAt).toBeInstanceOf(Date);
expect(session?.workspaces.get("workspace-1")?.statusEnteredAt).toBeInstanceOf(Date);
expect(session?.workspaces.get("workspace-1")?.worktreeSlug).toBe("owned-worktree");
expect(session?.agentStreamTail.get("agent-1")).toEqual([message("message-1", "Cached")]);
expect(session?.agentAuthoritativeHistoryApplied.get("agent-1")).toBe(true);
expect(session?.agentTimelineCursor.get("agent-1")).toEqual({
@@ -199,6 +199,7 @@ function serializeWorkspace(workspace: WorkspaceDescriptor): WorkspaceDescriptor
projectCustomIconRevision: workspace.projectCustomIconRevision ?? null,
projectRootPath: workspace.projectRootPath,
workspaceDirectory: workspace.workspaceDirectory,
worktreeSlug: workspace.worktreeSlug,
projectKind: workspace.projectKind,
workspaceKind: workspace.workspaceKind,
name: workspace.name,
+2
View File
@@ -132,6 +132,7 @@ export interface WorkspaceDescriptor {
projectCustomIconRevision?: string | null;
projectRootPath: string;
workspaceDirectory: string;
worktreeSlug?: WorkspaceDescriptorPayload["worktreeSlug"];
projectKind: WorkspaceDescriptorPayload["projectKind"];
workspaceKind: WorkspaceDescriptorPayload["workspaceKind"];
name: string;
@@ -167,6 +168,7 @@ export function normalizeWorkspaceDescriptor(
// consumer can read workspace.workspaceDirectory directly. Empty means "no
// usable directory" (older daemons may omit it; the wire field is optional).
workspaceDirectory: normalizeWorkspacePath(payload.workspaceDirectory) ?? "",
worktreeSlug: payload.worktreeSlug,
projectKind: payload.projectKind,
workspaceKind: payload.workspaceKind,
name: payload.name,
@@ -18,6 +18,7 @@ function workspace(overrides: Partial<SidebarWorkspaceEntry> = {}): SidebarWorks
projectViewKey: "project-1",
projectName: "paseo",
workspaceDirectory: "/repo",
workspaceDirectoryLabel: "/repo",
projectKind: "git",
workspaceKind: "checkout",
name: "paseo",
@@ -27,6 +27,7 @@ function workspace(input: {
projectViewKey: input.projectKey ?? "project-default",
projectName: input.projectKey ?? "Project",
workspaceDirectory: input.workspaceDirectory,
workspaceDirectoryLabel: input.workspaceDirectory,
projectKind: "git",
workspaceKind: "checkout",
name: input.name,