diff --git a/apps/web/src/components/SidebarV2.tsx b/apps/web/src/components/SidebarV2.tsx index 72bffaab1e..493234ba6b 100644 --- a/apps/web/src/components/SidebarV2.tsx +++ b/apps/web/src/components/SidebarV2.tsx @@ -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 {formatWorkingDurationLabel(Date.now() - startedMs)}; } +/** + * 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 ( + + + {props.count} + + ); +} + 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({
{modelLabel}
) : null} + {tabCount > 1 ? ( +
+ +
+ {tabCount} tabs sharing this worktree and branch. Each tab keeps its own + conversation. +
+
+ ) : null} {thread.session?.lastError ? (
@@ -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: { /> {title} - {props.tabCount > 1 ? ( - - {props.tabCount} - - ) : null} + {props.tabCount > 1 ? : 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: {
{title} - {props.tabCount > 1 ? ( - - {props.tabCount} - - ) : null} + {props.tabCount > 1 ? : null}
{thread.branch ? ( diff --git a/apps/web/src/components/WorkspaceTaskTabs.tsx b/apps/web/src/components/WorkspaceTaskTabs.tsx index 267d4162a4..dc6aceaa61 100644 --- a/apps/web/src/components/WorkspaceTaskTabs.tsx +++ b/apps/web/src/components/WorkspaceTaskTabs.tsx @@ -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 ( + + + + ); + } + 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 ( + + ); + } + 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() {
-
- {workingCount > 0 ? ( - - ) : null} +
- New tab{newTabShortcut ? ` (${newTabShortcut})` : ""} + New empty tab{newTabShortcut ? ` (${newTabShortcut})` : ""} @@ -126,10 +208,32 @@ export function WorkspaceTaskTabs() { > - - {canForkContext - ? "Fork this tab’s context into a new tab" - : "Send the first message before forking context"} + + + {canForkContext + ? "New tab seeded with a one-time snapshot of this tab's conversation" + : "Send the first message before forking context"} + + + + {/* Stated once for the whole task, so individual tabs don't need to + repeat the shared-worktree / separate-history caveat. */} + + + } + > + + + + + {TASK_TABS_SHARED_SCOPE_EXPLANATION} +
diff --git a/apps/web/src/lib/taskTabContext.test.ts b/apps/web/src/lib/taskTabContext.test.ts new file mode 100644 index 0000000000..cd001d5ff5 --- /dev/null +++ b/apps/web/src/lib/taskTabContext.test.ts @@ -0,0 +1,123 @@ +import { describe, expect, it } from "@effect/vitest"; + +import { + describeTaskTabContexts, + taskTabDisplayTitle, + type TaskTabContextSource, +} from "./taskTabContext"; + +function tab( + overrides: Partial & { 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/); + } + }); +}); diff --git a/apps/web/src/lib/taskTabContext.ts b/apps/web/src/lib/taskTabContext.ts new file mode 100644 index 0000000000..18ad08b871 --- /dev/null +++ b/apps/web/src/lib/taskTabContext.ts @@ -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, +): ReadonlyArray { + 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); + }); +}