polish task tab context UI

This commit is contained in:
Theo Browne committed 2026-07-24 16:54:54 -07:00
1 parent 9b5063bcd4
commit c8cf535780
4 files changed
+447 -84

No files matched your search

+32 -16
View File
@@ -32,6 +32,7 @@ import {
SearchIcon,
ServerIcon,
SquarePenIcon,
SquareStackIcon,
Trash2Icon,
Undo2Icon,
} from "lucide-react";
@@ -217,6 +218,23 @@ function WorkingDuration(props: { startedAt: string | null }) {
return <span className="tabular-nums">{formatWorkingDurationLabel(Date.now() - startedMs)}</span>;
}
/**
* A task row stands for every tab of that task, so the count is a quiet glyph
* badge rather than a bare number — the icon carries the meaning without color,
* and the row tooltip explains what the tabs do and don't share.
*/
function TaskTabCountBadge(props: { count: number }) {
return (
<span
className="inline-flex shrink-0 items-center gap-0.5 rounded bg-sidebar-accent px-1 font-mono text-[10px] text-sidebar-muted-foreground"
aria-label={`${props.count} task tabs`}
>
<SquareStackIcon aria-hidden className="size-2.5" />
{props.count}
</span>
);
}
function SidebarV2ThreadTooltip({
thread,
projectTitle,
@@ -226,11 +244,13 @@ function SidebarV2ThreadTooltip({
modelInstanceId,
modelLabel,
branchMismatch,
tabCount,
}: {
thread: SidebarThreadSummary;
projectTitle: string | null;
projectCwd: string | null;
environmentLabel: string | null;
tabCount: number;
driverKind: ProviderInstanceEntry["driverKind"] | null;
modelInstanceId: string;
modelLabel: string;
@@ -289,6 +309,15 @@ function SidebarV2ThreadTooltip({
<div className="min-w-0 wrap-break-word text-foreground/90">{modelLabel}</div>
</div>
) : null}
{tabCount > 1 ? (
<div className="flex min-w-0 items-start gap-2">
<SquareStackIcon aria-hidden className="mt-0.5 size-4 shrink-0 stroke-current" />
<div className="min-w-0 flex-1 wrap-break-word leading-5">
{tabCount} tabs sharing this worktree and branch. Each tab keeps its own
conversation.
</div>
</div>
) : null}
{thread.session?.lastError ? (
<div className="flex min-w-0 items-center gap-2 text-red-600 dark:text-red-400">
<CircleAlertIcon className="size-4 shrink-0 stroke-current" />
@@ -538,6 +567,7 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
modelInstanceId={modelInstanceId}
modelLabel={modelLabel}
branchMismatch={branchMismatch}
tabCount={props.tabCount}
/>
);
@@ -771,14 +801,7 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
/>
</span>
{title}
{props.tabCount > 1 ? (
<span
className="shrink-0 rounded bg-sidebar-accent px-1.5 font-mono text-[10px] text-sidebar-muted-foreground"
aria-label={`${props.tabCount} task tabs`}
>
{props.tabCount}
</span>
) : null}
{props.tabCount > 1 ? <TaskTabCountBadge count={props.tabCount} /> : null}
{/* The PR badge stays outside the hover-fading slot: it must
remain visible AND clickable while the row is hovered. Only
the time/jump label yields to the settle affordance. */}
@@ -956,14 +979,7 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
</div>
<div className="mt-1 flex min-w-0 items-center gap-1.5">
{title}
{props.tabCount > 1 ? (
<span
className="shrink-0 rounded bg-sidebar-accent px-1.5 font-mono text-[10px] text-sidebar-muted-foreground"
aria-label={`${props.tabCount} task tabs`}
>
{props.tabCount}
</span>
) : null}
{props.tabCount > 1 ? <TaskTabCountBadge count={props.tabCount} /> : null}
</div>
<div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground/75">
{thread.branch ? (
+172 -68
View File
@@ -1,16 +1,58 @@
import { GitForkIcon, PlusIcon, XIcon } from "lucide-react";
import { useState } from "react";
import { CircleDashedIcon, GitForkIcon, InfoIcon, PlusIcon, XIcon } from "lucide-react";
import { useMemo, useState } from "react";
import { shortcutLabelForCommand } from "../keybindings";
import { useClientSettings } from "../hooks/useSettings";
import { type WorkspaceTaskTab, useWorkspaceTaskTabs } from "../hooks/useWorkspaceTaskTabs";
import {
TASK_TABS_SHARED_SCOPE_EXPLANATION,
describeTaskTabContexts,
type TaskTabContextDescriptor,
} from "../lib/taskTabContext";
import { cn } from "../lib/utils";
import { Tooltip, TooltipPopup, TooltipProvider, TooltipTrigger } from "./ui/tooltip";
function tabStatusClass(tab: WorkspaceTaskTab): string {
if (tab.blocked) return "bg-amber-500";
if (tab.working) return "animate-pulse bg-sky-500 motion-reduce:animate-none";
return "bg-muted-foreground/35";
function tabThreadId(tab: WorkspaceTaskTab): string {
return String(tab.kind === "server" ? tab.threadRef.threadId : tab.threadId);
}
/**
* State is carried by shape and text as well as hue: blocked tabs get a filled
* ring plus "Waiting on you", working tabs get a dashed spinner glyph. Colour
* is the accent, never the only signal.
*/
function TabStateGlyph(props: { tab: WorkspaceTaskTab }) {
const { tab } = props;
if (tab.blocked) {
return (
<span
role="img"
aria-label="Waiting on you"
className="inline-flex size-3.5 shrink-0 items-center justify-center rounded-full border-[1.5px] border-amber-500 text-amber-600 dark:text-amber-400"
>
<span aria-hidden className="size-1.5 rounded-full bg-current" />
</span>
);
}
if (tab.working) {
// Duty-cycled steps() pulse from index.css, not a continuous spin: this
// strip can be on screen for hours on a 120Hz display.
return (
<CircleDashedIcon
role="img"
aria-label="Working"
className="size-3.5 shrink-0 animate-status-pulse text-sky-600 motion-reduce:animate-none dark:text-sky-400"
/>
);
}
return null;
}
function contextChipClass(kind: TaskTabContextDescriptor["kind"], active: boolean): string {
if (!active) return "border-border/30 bg-background/30 text-muted-foreground/60";
return kind === "snapshot"
? "border-border/60 bg-muted/80 text-muted-foreground/90"
: "border-border/45 bg-muted/60 text-muted-foreground/75";
}
export function WorkspaceTaskTabs() {
@@ -18,11 +60,31 @@ export function WorkspaceTaskTabs() {
const { tabs, keybindings, hasTask, canForkContext, createTab, closeTab, navigateToTab } =
useWorkspaceTaskTabs();
const [creatingMode, setCreatingMode] = useState<"fresh" | "portable" | null>(null);
const contexts = useMemo(
() =>
describeTaskTabContexts(
tabs.map((tab) => ({
kind: tab.kind,
threadId: tabThreadId(tab),
title: tab.title,
position: tab.position,
forkProvenance: tab.forkProvenance
? {
mode: tab.forkProvenance.mode,
sourceThreadId:
tab.forkProvenance.sourceThreadId === null
? null
: String(tab.forkProvenance.sourceThreadId),
}
: null,
})),
),
[tabs],
);
if (!sidebarV2Enabled || !hasTask) return null;
const newTabShortcut = shortcutLabelForCommand(keybindings, "chat.newTab");
const workingCount = tabs.filter((tab) => tab.working).length;
const create = (mode: "fresh" | "portable") => {
if (creatingMode !== null) return;
setCreatingMode(mode);
@@ -34,66 +96,86 @@ export function WorkspaceTaskTabs() {
<nav
aria-label="Task tabs"
data-testid="workspace-task-tabs"
className="flex h-10 shrink-0 items-end gap-1 border-b border-border/70 bg-background px-3 sm:px-5"
className="flex h-9 shrink-0 items-center gap-2 border-b border-border/60 bg-background px-3 sm:px-5"
>
<div className="flex min-w-0 flex-1 items-end gap-0.5 overflow-x-auto [scrollbar-width:none]">
{tabs.map((tab, index) => (
<div
key={tab.key}
className={cn(
"group/task-tab relative flex h-9 max-w-56 min-w-24 shrink-0 items-center rounded-t-md border border-b-0 px-2.5 text-xs transition-colors",
tab.active
? "border-border bg-card text-foreground shadow-[0_-1px_8px_hsl(var(--foreground)/0.03)]"
: "border-transparent text-muted-foreground hover:bg-muted/60 hover:text-foreground",
)}
>
<button
type="button"
className="flex min-w-0 flex-1 items-center gap-2 text-left outline-none"
onClick={() => void navigateToTab(tab)}
aria-current={tab.active ? "page" : undefined}
{/* One segmented control, not browser chrome: the tabs sit inside a
single inset track so the strip reads as a compact control. */}
<div className="flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto rounded-md bg-muted/40 p-0.5 [scrollbar-width:none]">
{tabs.map((tab, index) => {
const context = contexts[index];
return (
<div
key={tab.key}
className={cn(
"group/task-tab relative flex h-7 max-w-64 min-w-0 shrink-0 items-center rounded-[5px] pr-1 pl-2 text-xs transition-colors",
tab.active
? "bg-background text-foreground shadow-xs ring-1 ring-border/70"
: "text-muted-foreground hover:bg-background/60 hover:text-foreground",
)}
>
<span
aria-hidden
className={cn("size-1.5 shrink-0 rounded-full", tabStatusClass(tab))}
/>
<span className="truncate">
{index === 0 && tab.title === "Tab 1" ? "Main" : tab.title}
</span>
{tab.forkProvenance?.mode === "portable" ? (
<GitForkIcon aria-label="Context fork" className="size-3 shrink-0 opacity-50" />
<Tooltip>
<TooltipTrigger
render={
<button
type="button"
className="flex min-w-0 flex-1 items-center gap-1.5 text-left outline-none"
onClick={() => void navigateToTab(tab)}
aria-current={tab.active ? "page" : undefined}
/>
}
>
<TabStateGlyph tab={tab} />
{tab.forkProvenance?.mode === "portable" ? (
<GitForkIcon aria-hidden className="size-3 shrink-0 opacity-45" />
) : null}
<span className="truncate font-medium">
{context?.title ?? tab.title}
{/* Context stays legible to assistive tech even when the
chip is hidden at narrow widths. */}
{context ? <span className="sr-only"> — {context.label}</span> : null}
</span>
{context ? (
<span
aria-hidden
className={cn(
"hidden max-w-40 shrink-0 truncate rounded-sm border px-1 py-px text-[9px] leading-3.5 font-normal whitespace-nowrap md:inline-block",
contextChipClass(context.kind, tab.active),
)}
>
{context.label}
</span>
) : null}
</TooltipTrigger>
<TooltipPopup side="bottom" className="max-w-72">
<span className="block px-0.5 py-0.5 text-left leading-relaxed whitespace-normal">
<span className="font-medium text-foreground">
{context?.label ?? "Own context"}
</span>
{context ? (
<span className="mt-0.5 block text-muted-foreground">{context.detail}</span>
) : null}
</span>
</TooltipPopup>
</Tooltip>
{tabs.length > 1 && tab.position > 0 ? (
<button
type="button"
aria-label={`Close ${context?.title ?? tab.title}`}
disabled={tab.working || tab.blocked}
onClick={(event) => {
event.stopPropagation();
void closeTab(tab);
}}
className="ml-1 inline-flex size-4 shrink-0 items-center justify-center rounded-sm text-muted-foreground/50 opacity-0 transition-opacity hover:bg-muted hover:text-foreground focus-visible:opacity-100 disabled:cursor-not-allowed disabled:opacity-20 group-hover/task-tab:opacity-100"
>
<XIcon className="size-3" />
</button>
) : null}
</button>
{tabs.length > 1 && tab.position > 0 ? (
<button
type="button"
aria-label={`Close ${tab.title}`}
disabled={tab.working || tab.blocked}
onClick={(event) => {
event.stopPropagation();
void closeTab(tab);
}}
className="ml-1 inline-flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground/50 opacity-0 transition-opacity hover:bg-muted hover:text-foreground focus-visible:opacity-100 disabled:cursor-not-allowed disabled:opacity-20 group-hover/task-tab:opacity-100"
>
<XIcon className="size-3" />
</button>
) : null}
</div>
))}
</div>
);
})}
</div>
<div className="flex h-9 shrink-0 items-center gap-0.5 pb-1">
{workingCount > 0 ? (
<span
role="status"
className={cn(
"mr-1 hidden whitespace-nowrap font-mono text-[10px] sm:inline",
workingCount > 1 ? "text-amber-600 dark:text-amber-400" : "text-sky-600",
)}
title="Agents in this task share one worktree"
>
{workingCount} running · shared tree
</span>
) : null}
<div className="flex shrink-0 items-center gap-0.5">
<Tooltip>
<TooltipTrigger
render={
@@ -109,7 +191,7 @@ export function WorkspaceTaskTabs() {
<PlusIcon className="size-4" />
</TooltipTrigger>
<TooltipPopup side="bottom">
New tab{newTabShortcut ? ` (${newTabShortcut})` : ""}
New empty tab{newTabShortcut ? ` (${newTabShortcut})` : ""}
</TooltipPopup>
</Tooltip>
<Tooltip>
@@ -126,10 +208,32 @@ export function WorkspaceTaskTabs() {
>
<GitForkIcon className="size-3.5" />
</TooltipTrigger>
<TooltipPopup side="bottom">
{canForkContext
? "Fork this tab’s context into a new tab"
: "Send the first message before forking context"}
<TooltipPopup side="bottom" className="max-w-64">
<span className="block py-0.5 text-left whitespace-normal">
{canForkContext
? "New tab seeded with a one-time snapshot of this tab's conversation"
: "Send the first message before forking context"}
</span>
</TooltipPopup>
</Tooltip>
{/* Stated once for the whole task, so individual tabs don't need to
repeat the shared-worktree / separate-history caveat. */}
<Tooltip>
<TooltipTrigger
render={
<button
type="button"
aria-label="How task tabs share context"
className="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground/60 transition-colors hover:bg-muted hover:text-foreground"
/>
}
>
<InfoIcon className="size-3.5" />
</TooltipTrigger>
<TooltipPopup side="bottom" align="end" className="max-w-72">
<span className="block py-0.5 text-left leading-relaxed whitespace-normal">
{TASK_TABS_SHARED_SCOPE_EXPLANATION}
</span>
</TooltipPopup>
</Tooltip>
</div>
+123
View File
@@ -0,0 +1,123 @@
import { describe, expect, it } from "@effect/vitest";
import {
describeTaskTabContexts,
taskTabDisplayTitle,
type TaskTabContextSource,
} from "./taskTabContext";
function tab(
overrides: Partial<TaskTabContextSource> & { threadId: string },
): TaskTabContextSource {
return {
kind: "server",
title: overrides.threadId,
position: 0,
forkProvenance: null,
...overrides,
};
}
describe("task tab context descriptors", () => {
it("labels the first tab Main and gives it its own context", () => {
const [main] = describeTaskTabContexts([tab({ threadId: "root", title: "Tab 1" })]);
expect(main?.title).toBe("Main");
expect(main?.kind).toBe("main");
expect(main?.label).toBe("Own context");
expect(main?.detail).toContain("one-time context fork");
});
it("keeps an explicit tab label on the first tab", () => {
expect(taskTabDisplayTitle(tab({ threadId: "root", title: "Reviewer" }))).toBe("Reviewer");
});
it("describes an unsent draft tab as starting empty", () => {
const [, draft] = describeTaskTabContexts([
tab({ threadId: "root", title: "Main" }),
tab({
threadId: "draft-thread",
kind: "draft",
title: "Tab 2",
position: 1,
forkProvenance: { mode: "fresh", sourceThreadId: null },
}),
]);
expect(draft?.kind).toBe("empty");
expect(draft?.label).toBe("Starts empty");
expect(draft?.detail).toContain("no conversation yet");
});
it("describes a started sibling tab as independent, not shared", () => {
const [, started] = describeTaskTabContexts([
tab({ threadId: "root", title: "Main" }),
tab({
threadId: "second",
title: "Tab 2",
position: 1,
forkProvenance: { mode: "fresh", sourceThreadId: null },
}),
]);
expect(started?.kind).toBe("own");
expect(started?.label).toBe("Own context");
expect(started?.detail).toContain("does not follow the other tabs");
});
it("resolves a portable fork's source to the sibling tab label", () => {
const [, fork] = describeTaskTabContexts([
tab({ threadId: "root", title: "Tab 1" }),
tab({
threadId: "fork",
kind: "draft",
title: "Tab 2",
position: 1,
forkProvenance: { mode: "portable", sourceThreadId: "root" },
}),
]);
expect(fork?.kind).toBe("snapshot");
expect(fork?.sourceTitle).toBe("Main");
expect(fork?.label).toBe("Snapshot from Main");
expect(fork?.detail).toContain("bounded snapshot");
});
it("describes a started fork in the past tense once it owns a thread", () => {
const [, fork] = describeTaskTabContexts([
tab({ threadId: "root", title: "Main" }),
tab({
threadId: "fork",
title: "Retry",
position: 1,
forkProvenance: { mode: "portable", sourceThreadId: "root" },
}),
]);
expect(fork?.label).toBe("Snapshot from Main");
expect(fork?.detail).toContain("continued independently");
});
it("falls back to a neutral phrase when the source tab is gone", () => {
const [fork] = describeTaskTabContexts([
tab({
threadId: "fork",
title: "Retry",
position: 1,
forkProvenance: { mode: "portable", sourceThreadId: "closed-thread" },
}),
]);
expect(fork?.sourceTitle).toBeNull();
expect(fork?.label).toBe("Snapshot from another tab");
});
it("never invents message counts", () => {
const descriptors = describeTaskTabContexts([
tab({ threadId: "root", title: "Tab 1" }),
tab({
threadId: "fork",
title: "Tab 2",
position: 1,
forkProvenance: { mode: "portable", sourceThreadId: "root" },
}),
]);
for (const descriptor of descriptors) {
expect(`${descriptor.label} ${descriptor.detail}`).not.toMatch(/\d/);
}
});
});
+120
View File
@@ -0,0 +1,120 @@
/**
* Honest, metadata-only descriptions of what conversation context a task tab
* has. Tabs in one workspace task share a project/worktree/branch but never a
* live conversation, so the copy here must never imply synced history:
* - Main and any started tab own their transcript outright.
* - A fresh tab is literally empty until its first message.
* - A portable fork receives one bounded snapshot of its source tab on the
* first provider call, then continues on its own.
*
* Nothing here counts messages or tokens — only shape is known client-side.
*/
export type TaskTabContextKind = "main" | "empty" | "own" | "snapshot";
export interface TaskTabContextSource {
/** Server tabs have a real thread; drafts have not sent a message yet. */
readonly kind: "server" | "draft";
readonly threadId: string;
readonly title: string;
readonly position: number;
readonly forkProvenance: {
readonly mode: "fresh" | "portable";
readonly sourceThreadId: string | null;
} | null;
}
export interface TaskTabContextDescriptor {
readonly kind: TaskTabContextKind;
/** Tab name as rendered in the strip. */
readonly title: string;
/** Short chip label, e.g. "Snapshot from Main". */
readonly label: string;
/** One sentence expanding the label, for tooltips. */
readonly detail: string;
/** Resolved sibling tab title for portable forks, when still present. */
readonly sourceTitle: string | null;
}
/** Shared across every tab of a task, so it is stated once and not per tab. */
export const TASK_TABS_SHARED_SCOPE_EXPLANATION =
"Tabs in this task share the same project, worktree, and branch. Each keeps its own ongoing conversation. A context fork copies one bounded snapshot; it does not keep histories in sync.";
const FALLBACK_SOURCE_TITLE = "another tab";
/**
* Mirrors the legacy strip fallback: the first tab reads as "Main" even when a
* draft was persisted before tab labels existed.
*/
export function taskTabDisplayTitle(tab: TaskTabContextSource): string {
if (tab.position === 0 && (tab.title === "Tab 1" || tab.title.trim() === "")) return "Main";
return tab.title;
}
function describeOne(
tab: TaskTabContextSource,
sourceTitle: string | null,
): TaskTabContextDescriptor {
const title = taskTabDisplayTitle(tab);
const base = { title, sourceTitle } as const;
if (tab.forkProvenance?.mode === "portable") {
const from = sourceTitle ?? FALLBACK_SOURCE_TITLE;
return {
...base,
kind: "snapshot",
label: `Snapshot from ${from}`,
detail:
tab.kind === "draft"
? `On its first message this tab receives a bounded snapshot of ${from}'s conversation, then continues independently.`
: `Started from a bounded snapshot of ${from}'s conversation and has continued independently since.`,
};
}
if (tab.kind === "draft") {
return {
...base,
kind: "empty",
label: "Starts empty",
detail:
"This tab has no conversation yet. Once you send a message its context is its own — no history is carried over.",
};
}
if (tab.position === 0) {
return {
...base,
kind: "main",
label: "Own context",
detail:
"The task's first tab keeps its own conversation. Other tabs only receive it through a one-time context fork.",
};
}
return {
...base,
kind: "own",
label: "Own context",
detail: "This tab keeps an independent conversation and does not follow the other tabs.",
};
}
/**
* Describes every tab in one pass so a portable fork can name its source by
* the label that source currently shows in the strip. A source that was closed
* (or lives outside this task) degrades to "another tab" rather than leaking a
* thread id.
*/
export function describeTaskTabContexts(
tabs: ReadonlyArray<TaskTabContextSource>,
): ReadonlyArray<TaskTabContextDescriptor> {
const titleByThreadId = new Map(tabs.map((tab) => [tab.threadId, taskTabDisplayTitle(tab)]));
return tabs.map((tab) => {
const sourceThreadId = tab.forkProvenance?.sourceThreadId ?? null;
const sourceTitle =
sourceThreadId !== null && sourceThreadId !== tab.threadId
? (titleByThreadId.get(sourceThreadId) ?? null)
: null;
return describeOne(tab, sourceTitle);
});
}