TypeScript
fix(sidebar): mute background working threads (#9759)
maria45bd3b631bf1
diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.tsindex 62204d9d4a3..bf3d37d0edc 100644--- a/apps/web/src/components/Sidebar.logic.test.ts+++ b/apps/web/src/components/Sidebar.logic.test.ts@@ -29,6 +29,7 @@ import {formatWorkingDurationLabel,shouldNavigateAfterProjectRemoval,shouldClearThreadSelectionOnMouseDown,+ shouldRecedeSidebarThread,sortLogicalProjectsForSidebar,sortSettledThreadsForSidebar,pinOrderKeyBetween,@@ -295,6 +296,51 @@ describe("hasUnseenCompletion", () => {});});+describe("shouldRecedeSidebarThread", () => {+ it.each(["working", "monitoring"] as const)(+ "recedes an inactive %s thread even when it is unread and woke",+ (status) => {+ expect(+ shouldRecedeSidebarThread({+ status,+ isUnread: true,+ isWoke: true,+ isActive: false,+ isSelected: false,+ }),+ ).toBe(true);+ },+ );++ it.each(["ready", "approval", "input"] as const)(+ "keeps an unread %s thread prominent",+ (status) => {+ expect(+ shouldRecedeSidebarThread({+ status,+ isUnread: true,+ isWoke: false,+ isActive: false,+ isSelected: false,+ }),+ ).toBe(false);+ },+ );++ it("keeps active and selected working threads prominent", () => {+ const input = {+ status: "working" as const,+ isUnread: true,+ isWoke: true,+ isActive: false,+ isSelected: false,+ };++ expect(shouldRecedeSidebarThread({ ...input, isActive: true })).toBe(false);+ expect(shouldRecedeSidebarThread({ ...input, isSelected: true })).toBe(false);+ });+});+describe("createThreadJumpHintVisibilityController", () => {beforeEach(() => {vi.useFakeTimers();diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.tsindex 6a2d44da1a7..8e88aea37f4 100644--- a/apps/web/src/components/Sidebar.logic.ts+++ b/apps/web/src/components/Sidebar.logic.ts@@ -532,6 +532,21 @@ export type SidebarThreadStatus =| "failed"| "ready";+export function shouldRecedeSidebarThread(input: {+ status: SidebarThreadStatus;+ isUnread: boolean;+ isWoke: boolean;+ isActive: boolean;+ isSelected: boolean;+}): boolean {+ if (input.isActive || input.isSelected) return false;+ if (input.status === "working" || input.status === "monitoring") return true;+ if (input.status === "ready" || input.status === "approval" || input.status === "input") {+ return !input.isUnread && !input.isWoke;+ }+ return false;+}+type SidebarThreadStatusInput = Pick<SidebarThreadSummary,"hasPendingApprovals" | "hasPendingUserInput" | "session" | "backgroundLiveness"diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsxindex 0719f873e6a..4509fde6ceb 100644--- a/apps/web/src/components/Sidebar.tsx+++ b/apps/web/src/components/Sidebar.tsx@@ -144,6 +144,7 @@ import {resolveSidebarThreadStatus,searchSidebarThreadsByTitle,shouldCreateNewThreadInCurrentProject,+ shouldRecedeSidebarThread,resolveWorkingStartedAt,sortLogicalProjectsForSidebar,sortPinnedThreadsForSidebar,@@ -874,6 +875,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {// switching sidebars must not light up every historical thread as unread.const isUnread = hasUnseenCompletion({ ...thread, lastVisitedAt });const status = resolveSidebarThreadStatus(thread);+ const isInFlight =+ status === "working" || status === "monitoring" || status === "approval" || status === "input";// A woken thread reappears at its original position (the sort is// deliberately static), so the pill has to carry the weight. Snoozing is// an explicit act, so the pill clears only when the user re-engages:@@ -887,17 +890,16 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {wokeAtDate !== null &&(lastVisitedDate === null || lastVisitedDate < wokeAtDate) &&thread.settledOverride !== "settled";- // In-flight rows (working, or waiting on approval/input) fade as a whole:- // there is nothing for the user to do yet, so prominence is reserved for- // rows that need a human — done (unread), read-but-unsettled, failed, and- // freshly woken. The status label keeps its hue, so waiting rows stay- // findable. In-flight rows recede the same as read-ready ones (inbox-zero:- // working threads aren't your problem yet) — only the colored status label- // stands out.- const isInFlight =- status === "working" || status === "monitoring" || status === "approval" || status === "input";- const shouldRecede =- (status === "ready" || isInFlight) && !isUnread && !isWoke && !props.isActive && !isSelected;+ // Background work always recedes when it is not selected: an unread parent+ // completion must not pull a still-working thread back into the foreground.+ // Ready and action-required rows keep their unread and wake prominence.+ const shouldRecede = shouldRecedeSidebarThread({+ status,+ isUnread,+ isWoke,+ isActive: props.isActive,+ isSelected,+ });// Status hues follow the system-wide convention set by sidebar v1 and the// mobile Live Activity/widgets (amber approval, indigo input, sky working)// so a thread reads the same color everywhere it surfaces.@@ -1210,21 +1212,23 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {variant === "card"? cn("truncate",- isUnread || isWoke- ? "text-foreground"- : shouldRecede- ? "text-secondary-label"+ shouldRecede+ ? "text-secondary-label"+ : isUnread || isWoke+ ? "text-foreground": status === "failed"? "text-foreground/95": "text-foreground/90",): cn("truncate group-hover/sidebar-row:text-foreground",- props.isActive || isWoke- ? "text-foreground"- : isUnread- ? "text-muted-foreground"- : "text-secondary-label/70",+ shouldRecede+ ? "text-secondary-label/70"+ : props.isActive || isWoke+ ? "text-foreground"+ : isUnread+ ? "text-muted-foreground"+ : "text-secondary-label/70",),isRegeneratingTitle && "opacity-[0.55]",)}