feat(mobile): beta Working section hides busy threads until they need you (#15346)

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Theo BrowneandClaude Opus 5.5 authored and GitHub committed 2026-10-03 15:03:59 -07:00
1 parent a78760e5e7
commit 8d846660ce
16 files changed
+587 -103

No files matched your search

+5 -45
View File
@@ -1008,21 +1008,6 @@ export function shouldShowSidebarV2Duration(status: SidebarThreadStatus): boolea
return status === "working";
}
/** Working beta: threads busy with work that does not need the user fold into
the Working shelf: a running run, or one stopped with background work
that will wake it. Approvals, questions, plan prompts, and failures stay in the
inbox. */
export function isSidebarThreadWorking(thread: ThreadStatusInput): boolean {
const status = resolveSidebarThreadStatus(thread);
if (status !== "working" && status !== "waiting") return false;
// A plan prompt outranks lingering background work: the user has to act on it.
return !(
thread.interactionMode === "plan" &&
thread.hasActionableProposedPlan &&
isLatestRunSettled(thread.latestRun, thread.runtime)
);
}
/** First VALID timestamp wins: `a ?? b` falls through on null, but a present-
yet-malformed string must also fall through to the next candidate rather
than sink the row to the epoch. */
@@ -1038,6 +1023,11 @@ export function firstValidTimestampMs(
}
export { sortActiveThreadsByOrderKey as sortThreadsForSidebar } from "@t3tools/client-runtime/state/thread-sort";
// The Working section beta folds and orders the inbox the same way on mobile.
export {
isThreadWorking as isSidebarThreadWorking,
sortInboxThreadsByReturn,
} from "@t3tools/client-runtime/state/thread-inbox";
// Pinned-reorder key math and the keyed sort live in client-runtime
// (state/thread-sort) so web and mobile compute identical pinned orders.
@@ -1119,36 +1109,6 @@ export function reduceSidebarProjectScopeMenuState(
}
}
/** Working beta: the inbox lists threads newest first by when each last came
back to the user, so a thread that leaves the Working shelf lands on top.
`observedReturnAt` adds returns the server does not stamp, such as an
approval request mid-turn or background work ending. */
export function sortInboxThreadsByReturn<
T extends Pick<
SidebarThreadSummary,
"id" | "environmentId" | "createdAt" | "unsettledAt" | "latestRun"
>,
>(threads: readonly T[], observedReturnAt?: (thread: T) => number | undefined): T[] {
const timestamps = new Map(
threads.map((thread) => [
thread,
Math.max(
toSortableTimestamp(thread.createdAt) ?? 0,
toSortableTimestamp(thread.unsettledAt ?? undefined) ?? 0,
toSortableTimestamp(thread.latestRun?.requestedAt ?? undefined) ?? 0,
toSortableTimestamp(thread.latestRun?.completedAt ?? undefined) ?? 0,
observedReturnAt?.(thread) ?? 0,
),
]),
);
return [...threads].sort(
(left, right) =>
timestamps.get(right)! - timestamps.get(left)! ||
left.id.localeCompare(right.id) ||
left.environmentId.localeCompare(right.environmentId),
);
}
/** The timestamp a working thread's elapsed label counts from: when its
current work started (request time until adoption). Background wakes do
not reset it. Malformed timestamps fall through to the next candidate. */
+5 -36
View File
@@ -31,6 +31,7 @@ import {
effectiveSnoozed,
threadWokeAt,
} from "@t3tools/client-runtime/state/thread-settled";
import { createInboxReturnTracker } from "@t3tools/client-runtime/state/thread-inbox";
import {
resolveSettledThreadTimestamp,
sortSettledThreads,
@@ -289,35 +290,7 @@ const WORKING_SHELF_EXPANDED_KEY = "t3code:sidebar:working-expanded";
// Working beta: when this client saw each thread leave the Working shelf.
// Module scope keeps the inbox order across routes that unmount the sidebar.
let lastWorkingThreadKeys: ReadonlySet<string> | null = null;
const observedInboxReturns = new Map<string, number>();
/** Stamps threads that stopped working since the last call. The first call
only takes a baseline, so mounting never reshuffles the inbox. Pass null
to reset when the beta is off. */
function observeInboxReturns(threads: readonly EnvironmentThreadShell[] | null): void {
if (threads === null) {
lastWorkingThreadKeys = null;
observedInboxReturns.clear();
return;
}
const working = new Set<string>();
const present = new Set<string>();
for (const thread of threads) {
const key = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
present.add(key);
if (isSidebarThreadWorking(thread)) working.add(key);
}
// Drop deleted threads so the map stays bounded by the live thread list.
for (const key of observedInboxReturns.keys()) {
if (!present.has(key)) observedInboxReturns.delete(key);
}
const now = Date.now();
for (const key of lastWorkingThreadKeys ?? []) {
if (present.has(key) && !working.has(key)) observedInboxReturns.set(key, now);
}
lastWorkingThreadKeys = working;
}
const inboxReturns = createInboxReturnTracker();
function compactSidebarTimeLabel(label: string): string {
if (label === "just now") return "now";
@@ -2669,7 +2642,7 @@ export default function Sidebar() {
// Subagent child threads live in the parent's Agents surface, not the
// sidebar roster (v2 models them as real threads with lineage).
const visible = filterSidebarV2VisibleThreads(threads, scopedProjectKeys);
observeInboxReturns(workingShelfEnabled ? threads : null);
inboxReturns.observe(workingShelfEnabled ? threads : null);
const pinned: EnvironmentThreadShell[] = [];
const active: EnvironmentThreadShell[] = [];
const working: EnvironmentThreadShell[] = [];
@@ -2736,11 +2709,7 @@ export default function Sidebar() {
// web and mobile from the same data.
const sortedPinned = sortPinnedThreadsForSidebar(pinned);
const sortedActive = workingShelfEnabled
? sortInboxThreadsByReturn(active, (thread) =>
observedInboxReturns.get(
scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
),
)
? sortInboxThreadsByReturn(active, inboxReturns.returnedAt)
: sortThreadsForSidebar(active);
return {
pinnedThreads:
@@ -3701,7 +3670,7 @@ export default function Sidebar() {
...activeThreads.filter((candidate) => key(candidate) !== dragState.activeKey),
applySidebarThreadDrop(thread, "active", dragState.occurredAt),
],
(candidate) => observedInboxReturns.get(key(candidate)),
inboxReturns.returnedAt,
).map(key);
}, [activeThreads, dragState, threadByKey, workingShelfEnabled]);
const sidebarSortingStrategy = useMemo(