Make sidebar v2 attention states harder to miss

This commit is contained in:
Theo Browne committed 2026-08-07 03:39:42 -07:00
1 parent bfc69e4b4d
commit 8d9b77b131
5 files changed
+127 -25

No files matched your search

@@ -14,6 +14,7 @@ import {
isContextMenuPointerDown,
isTrailingDoubleClick,
orderItemsByPreferredIds,
isSidebarV2ThreadWoke,
resolveProjectStatusIndicator,
resolveSidebarStageBadgeLabel,
resolveThreadRowClassName,
@@ -736,6 +737,52 @@ describe("sortThreadsForSidebarV2", () => {
expect(sorted.map((thread) => thread.id)).toEqual(["a", "b"]);
});
it("puts woke threads first, then manually un-settled threads", () => {
const threads = [
sortable({ id: "ordinary-new", createdAt: "2026-03-09T12:00:00.000Z" }),
sortable({ id: "unsettled-old", createdAt: "2026-03-09T08:00:00.000Z" }),
sortable({ id: "woke-old", createdAt: "2026-03-09T07:00:00.000Z" }),
sortable({ id: "woke-new", createdAt: "2026-03-09T09:00:00.000Z" }),
];
const priorities: ReadonlyMap<string, "unsettled" | "woke"> = new Map([
["unsettled-old", "unsettled"],
["woke-old", "woke"],
["woke-new", "woke"],
] as const);
const sorted = sortThreadsForSidebarV2(
threads,
(thread) => priorities.get(thread.id) ?? "default",
);
expect(sorted.map((thread) => thread.id)).toEqual([
"woke-new",
"woke-old",
"unsettled-old",
"ordinary-new",
]);
});
});
describe("isSidebarV2ThreadWoke", () => {
const wokeAt = "2026-03-09T10:00:00.000Z";
it("stays woke until a visit at or after the wake", () => {
expect(isSidebarV2ThreadWoke({ wokeAt, lastVisitedAt: undefined })).toBe(true);
expect(
isSidebarV2ThreadWoke({
wokeAt,
lastVisitedAt: "2026-03-09T09:59:59.999Z",
}),
).toBe(true);
expect(isSidebarV2ThreadWoke({ wokeAt, lastVisitedAt: wokeAt })).toBe(false);
});
it("keeps a valid wake visible when local visit data is malformed", () => {
expect(isSidebarV2ThreadWoke({ wokeAt, lastVisitedAt: "not-a-date" })).toBe(true);
expect(isSidebarV2ThreadWoke({ wokeAt: "not-a-date", lastVisitedAt: undefined })).toBe(false);
});
});
describe("sortSettledThreadsForSidebarV2", () => {
+31 -5
View File
@@ -496,15 +496,41 @@ export function firstValidTimestamp(
return null;
}
// v2 sort: static creation order, newest thread on top. Activity NEVER
// reorders the list — a row holds its position from open until settled, so
// the screen only moves at lifecycle transitions. Status (including pending
// approval) is carried by each card's edge strip, not by position.
export type SidebarV2ThreadPriority = "woke" | "unsettled" | "default";
const SIDEBAR_V2_THREAD_PRIORITY_RANK: Record<SidebarV2ThreadPriority, number> = {
woke: 0,
unsettled: 1,
default: 2,
};
/** A wake remains attention-bearing until the user visits it. Invalid local
visit data must not silently clear a valid server-backed wake. */
export function isSidebarV2ThreadWoke(input: {
readonly wokeAt: string | null;
readonly lastVisitedAt: string | undefined;
}): boolean {
if (input.wokeAt === null) return false;
const wokeAtMs = Date.parse(input.wokeAt);
if (Number.isNaN(wokeAtMs)) return false;
if (input.lastVisitedAt === undefined) return true;
const lastVisitedAtMs = Date.parse(input.lastVisitedAt);
return Number.isNaN(lastVisitedAtMs) || lastVisitedAtMs < wokeAtMs;
}
// v2 sort: attention transitions come first (woke, then manually
// un-settled), with static creation order inside each group. Ordinary
// activity never reorders the list.
export function sortThreadsForSidebarV2<
T extends { readonly id: string; readonly createdAt: string },
>(threads: readonly T[]): T[] {
>(
threads: readonly T[],
getPriority: (thread: T) => SidebarV2ThreadPriority = () => "default",
): T[] {
return [...threads].toSorted(
(left, right) =>
SIDEBAR_V2_THREAD_PRIORITY_RANK[getPriority(left)] -
SIDEBAR_V2_THREAD_PRIORITY_RANK[getPriority(right)] ||
parseTimestampMs(right.createdAt) - parseTimestampMs(left.createdAt) ||
left.id.localeCompare(right.id),
);
+28 -20
View File
@@ -490,9 +490,7 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
// flag must not light up every historical thread as unread.
const isUnread = hasUnseenCompletion({ ...thread, lastVisitedAt });
const status = resolveSidebarV2Status(thread);
// 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:
// The visual Woke treatment clears only when the user re-engages:
// reading a completion-triggered wake, clicking the pill, sending a
// message, settling, archiving — or finishing the work outright (merged
// or closed PR). Timer wakes survive a mere visit. An unparseable visit
@@ -505,15 +503,10 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
(lastVisitedDate === null || lastVisitedDate < wokeAtDate) &&
prState !== "merged" &&
prState !== "closed";
// 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.
// Background work and approvals recede when read. Input requests stay
// fully prominent because the agent cannot continue without the user.
const isInFlight =
status === "working" || status === "monitoring" || status === "approval" || status === "input";
status === "working" || status === "monitoring" || status === "approval";
const shouldRecede =
(status === "ready" || isInFlight) && !isUnread && !isWoke && !props.isActive && !isSelected;
// Status hues follow the system-wide convention set by sidebar v1 and the
@@ -547,9 +540,10 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
}
: status === "input"
? {
label: "Input",
icon: null,
className: "text-indigo-600 dark:text-indigo-300",
label: "Input needed",
icon: "input" as const,
className:
"rounded-full bg-indigo-500/10 px-1.5 py-0.5 text-indigo-700 ring-1 ring-inset ring-indigo-500/25 dark:bg-indigo-400/10 dark:text-indigo-200 dark:ring-indigo-400/25",
}
: status === "failed"
? {
@@ -1050,6 +1044,8 @@ const SidebarV2Row = memo(function SidebarV2Row(props: {
<CircleDashedIcon aria-hidden className="size-4 shrink-0" />
) : topStatus.icon === "done" ? (
<CircleCheckIcon aria-hidden className="size-4 shrink-0" />
) : topStatus.icon === "input" ? (
<MessageSquareIcon aria-hidden className="size-3.5 shrink-0" />
) : null}
{/* The label alone is the live region: a role="status"
wrapper around the ticking duration would make
@@ -1695,6 +1691,7 @@ export default function SidebarV2() {
const active: EnvironmentThreadShell[] = [];
const snoozed: EnvironmentThreadShell[] = [];
const settled: EnvironmentThreadShell[] = [];
const wokeAtByThreadKey = new Map<string, string>();
for (const thread of visible) {
// Threads on servers without the settlement capability (old server,
// or descriptor not loaded yet) never classify as settled: the user
@@ -1707,12 +1704,13 @@ export default function SidebarV2() {
serverConfigs.get(thread.environmentId)?.environment.capabilities.threadSnooze === true;
const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
const changeRequestState = changeRequestStateByKey.get(threadKey) ?? null;
const wokeAt = supportsSnooze ? threadWokeAt(thread, { now: preciseNow }) : null;
if (wokeAt !== null) wokeAtByThreadKey.set(threadKey, wokeAt);
// Snooze outranks everything, including a pin: "hide until Tuesday"
// temporarily suspends "keep on top". The pin survives underneath —
// pinned cards are creation-ordered, so on wake the thread reappears
// at its original spot in the pinned block. (For unpinned threads
// this is also the snooze-beats-auto-settle rule: the wake time is a
// stronger statement about when the thread matters again.)
// pinned cards keep their explicit block. For unpinned threads this
// is also the snooze-beats-auto-settle rule: the wake time is a
// stronger statement about when the thread matters again.
if (supportsSnooze && effectiveSnoozed(thread, { now: preciseNow })) {
snoozed.push(thread);
// A pin otherwise overrides the lifecycle: pinned threads never
@@ -1723,7 +1721,12 @@ export default function SidebarV2() {
pinned.push(thread);
} else if (
supportsSettlement &&
effectiveSettled(thread, { now, autoSettleAfterDays, changeRequestState })
effectiveSettled(thread, {
now,
autoSettleAfterDays,
changeRequestState,
suppressAutoSettle: wokeAt !== null,
})
) {
settled.push(thread);
} else {
@@ -1734,7 +1737,12 @@ export default function SidebarV2() {
// Same static creation order as the inbox: a pin freezes prominence,
// it does not introduce a new ordering scheme.
pinnedThreads: sortThreadsForSidebarV2(pinned),
activeThreads: sortThreadsForSidebarV2(active),
activeThreads: sortThreadsForSidebarV2(active, (thread) => {
const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
if (wokeAtByThreadKey.has(threadKey)) return "woke";
if (thread.settledOverride === "active") return "unsettled";
return "default";
}),
// Soonest wake first: "what comes back next" is the shelf's question.
snoozedThreads: snoozed.toSorted(
(left, right) =>
@@ -281,6 +281,23 @@ describe("effectiveSettled", () => {
expect(effectiveSettled(boundary, { now: NOW, autoSettleAfterDays: 3 })).toBe(false);
expect(effectiveSettled(stale, { now: NOW, autoSettleAfterDays: null })).toBe(false);
});
it("suppresses automatic settlement while still honoring an explicit settle", () => {
const stale = makeShell({ activityAt: STALE });
const explicitlySettled = makeShell({
activityAt: STALE,
settledOverride: "settled",
});
const options = {
now: NOW,
autoSettleAfterDays: 3,
changeRequestState: "merged" as const,
suppressAutoSettle: true,
};
expect(effectiveSettled(stale, options)).toBe(false);
expect(effectiveSettled(explicitlySettled, options)).toBe(true);
});
});
describe("hasQueuedTurnStart", () => {
@@ -233,6 +233,9 @@ export function effectiveSettled(
readonly now: string;
readonly autoSettleAfterDays: number | null;
readonly changeRequestState?: ChangeRequestStateLike | null;
/** Keep an attention-bearing thread active while still honoring an
explicit user settle. Used by the sidebar while a wake is unvisited. */
readonly suppressAutoSettle?: boolean;
},
): boolean {
// Blocked work must remain visible even when a user explicitly settled it.
@@ -258,6 +261,7 @@ export function effectiveSettled(
// "active" is the explicit keep-active pin: it suppresses auto-settle
// until real activity clears it server-side.
if (shell.settledOverride === "active") return false;
if (options.suppressAutoSettle === true) return false;
if (options.changeRequestState === "merged" || options.changeRequestState === "closed") {
return true;
}