feat(web): beta Working section hides busy threads until they need you #13926
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 2 commits into
main fromrefs/pull/13926/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/Sidebar.tsx lines 279 to 283OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -260,0 +263,21 @@263+const WORKING_SHELF_EXPANDED_KEY = "t3code:sidebar:working-expanded";264+265+// Working beta: when this client saw each thread leave the Working shelf.266+// Module scope keeps the inbox order across routes that unmount the sidebar.267+let lastWorkingThreadKeys: ReadonlySet<string> | null = null;268+const observedInboxReturns = new Map<string, number>();269+270+/** Stamps threads that stopped working since the last call. The first call271+ only takes a baseline, so mounting never reshuffles the inbox. Pass null272+ to reset when the beta is off. */273+function observeInboxReturns(threads: readonly EnvironmentThreadShell[] | null): void {274+ if (threads === null) {275+ lastWorkingThreadKeys = null;276+ observedInboxReturns.clear();277+ return;278+ }279+ const working = new Set(280+ threads281+ .filter(isSidebarThreadWorking)282+ .map((thread) => scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id))),283+ );@@ -260,0 +265,21 @@265+// Working beta: when this client saw each thread leave the Working shelf.266+// Module scope keeps the inbox order across routes that unmount the sidebar.267+let lastWorkingThreadKeys: ReadonlySet<string> | null = null;268+const observedInboxReturns = new Map<string, number>();269+270+/** Stamps threads that stopped working since the last call. The first call271+ only takes a baseline, so mounting never reshuffles the inbox. Pass null272+ to reset when the beta is off. */273+function observeInboxReturns(threads: readonly EnvironmentThreadShell[] | null): void {274+ if (threads === null) {275+ lastWorkingThreadKeys = null;276+ observedInboxReturns.clear();277+ return;278+ }279+ const working = new Set(280+ threads281+ .filter(isSidebarThreadWorking)282+ .map((thread) => scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id))),283+ );284+ const now = Date.now();285+ for (const key of lastWorkingThreadKeys ?? []) {
- @@ -951,2 +986,21 @@951986 }952987988+/** Working beta: the inbox lists threads newest first by when each last came989+ back to the user, so a thread that leaves the Working shelf lands on top.990+ `observedReturnAt` adds returns the server does not stamp, such as an991+ approval request mid-turn or background work ending. */992+export function sortInboxThreadsByReturn<993+ T extends Pick<994+ SidebarThreadSummary,995+ "id" | "environmentId" | "createdAt" | "unsettledAt" | "latestTurn"996+ >,997+>(threads: readonly T[], observedReturnAt?: (thread: T) => number | undefined): T[] {998+ const timestamps = new Map(999+ threads.map((thread) => [1000+ thread,1001+ Math.max(1002+ toSortableTimestamp(thread.createdAt) ?? 0,1003+ toSortableTimestamp(thread.unsettledAt ?? undefined) ?? 0,1004+ toSortableTimestamp(thread.latestTurn?.requestedAt) ?? 0,1005+ toSortableTimestamp(thread.latestTurn?.completedAt ?? undefined) ?? 0,1006+ observedReturnAt?.(thread) ?? 0,@@ -260,0 +274,21 @@274+ if (threads === null) {275+ lastWorkingThreadKeys = null;276+ observedInboxReturns.clear();277+ return;278+ }279+ const working = new Set<string>();280+ const present = new Set<string>();281+ for (const thread of threads) {282+ const key = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));283+ present.add(key);284+ if (isSidebarThreadWorking(thread)) working.add(key);285+ }286+ // Drop deleted threads so the map stays bounded by the live thread list.287+ for (const key of observedInboxReturns.keys()) {288+ if (!present.has(key)) observedInboxReturns.delete(key);289+ }290+ const now = Date.now();291+ for (const key of lastWorkingThreadKeys ?? []) {292+ if (present.has(key) && !working.has(key)) observedInboxReturns.set(key, now);293+ }294+ lastWorkingThreadKeys = working;
juliusmarminge added labelsmacroscope-review
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.

macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed