@devries-cameron20 / t3code-1 / commits / 8d846660ce
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

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

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Theo Browne committed Oct 3, 2026 at 15:03 UTC 8d846660cecfc69ef4e192322fced29fa07f374c
16 files changed +587 -103
apps/mobile/src/features/home/HomeScreen.tsx
+37 -2
@@ -44,6 +44,7 @@ import {
44 ThreadListV2SettledShelfHeader,
45 ThreadListV2ShowMoreRow,
46 ThreadListV2SnoozedShelfHeader,
47 + ThreadListV2WorkingShelfHeader,
48 } from "../threads/thread-list-v2-items";
49 import { useThreadRowProviderInstanceResolver } from "../threads/thread-provider-instance";
50 import {
@@ -51,6 +52,7 @@ import {
52 getThreadListV2OrderedSection,
53 buildThreadListV2ListItems,
54 threadListV2ListItemsAreEqual,
55 + threadListInboxReturns,
56 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
57 THREAD_LIST_V2_SETTLED_PAGE_COUNT,
58 type ThreadListV2ListItem,
@@ -466,8 +468,11 @@ export function HomeScreen(props: HomeScreenProps) {
468 loaded: shelfPreferencesLoaded,
469 settledShelfExpanded,
470 snoozedShelfExpanded,
471 + workingShelfEnabled,
472 + workingShelfExpanded,
473 toggleSettledShelf,
474 toggleSnoozedShelf,
475 + toggleWorkingShelf,
476 } = useThreadListV2ShelfPreferences();
477 // The queued-start and snooze helpers need a clock while the list stays open.
478 const [nowMinute, setNowMinute] = useState(() => new Date().toISOString().slice(0, 16));
@@ -520,8 +525,13 @@ export function HomeScreen(props: HomeScreenProps) {
525 queuedThreadKeys,
526 }),
527 });
523 - return new Map([...sectionAvailability("pinned"), ...sectionAvailability("active")]);
528 + // The Working beta orders the inbox by time, so only pins can move.
529 + return new Map([
530 + ...sectionAvailability("pinned"),
531 + ...(workingShelfEnabled ? [] : sectionAvailability("active")),
532 + ]);
533 }, [
534 + workingShelfEnabled,
535 pinReorderEnvironmentIds,
536 activeReorderEnvironmentIds,
537 props.threads,
@@ -533,6 +543,7 @@ export function HomeScreen(props: HomeScreenProps) {
543 snoozeWakeTick,
544 ]);
545 const threadListV2Layout = useMemo(() => {
546 + threadListInboxReturns.observe(workingShelfEnabled ? props.threads : null);
547 // Settled threads are live shells; archived threads keep their original
548 // "hidden from lists" meaning.
549 return buildThreadListV2Items({
@@ -547,11 +558,16 @@ export function HomeScreen(props: HomeScreenProps) {
558 queuedThreadKeys,
559 settledLimit: settledVisibleCount,
560 now: new Date().toISOString(),
561 + workingShelfEnabled,
562 + workingShelfExpanded,
563 + inboxReturnAt: threadListInboxReturns.returnedAt,
564 snoozedShelfExpanded,
565 settledShelfExpanded,
566 selectedThreadKey: null,
567 });
568 }, [
569 + workingShelfEnabled,
570 + workingShelfExpanded,
571 pendingOrder,
572 queuedThreadKeys,
573 nowMinute,
@@ -606,6 +622,9 @@ export function HomeScreen(props: HomeScreenProps) {
622 buildThreadListV2ListItems({
623 items: threadListV2Layout.items,
624 pendingTasks: v2PendingTasks,
625 + workingCount: threadListV2Layout.workingCount,
626 + workingShelfExpanded,
627 + workingShelfHeaderIndex: threadListV2Layout.workingShelfHeaderIndex,
628 snoozedCount: threadListV2Layout.snoozedCount,
629 snoozedShelfExpanded,
630 snoozedShelfHeaderIndex: threadListV2Layout.snoozedShelfHeaderIndex,
@@ -628,6 +647,7 @@ export function HomeScreen(props: HomeScreenProps) {
647 snoozeEnvironmentIds,
648 threadListV2Layout,
649 v2PendingTasks,
650 + workingShelfExpanded,
651 ],
652 );
653
@@ -662,6 +682,16 @@ export function HomeScreen(props: HomeScreenProps) {
682 />
683 );
684 }
685 + if (item.type === "v2-working-shelf") {
686 + return (
687 + <ThreadListV2WorkingShelfHeader
688 + count={item.count}
689 + disabled={item.disabled}
690 + expanded={item.expanded}
691 + onToggle={toggleWorkingShelf}
692 + />
693 + );
694 + }
695 if (item.type === "v2-snoozed-shelf") {
696 return (
697 <ThreadListV2SnoozedShelfHeader
@@ -730,7 +760,7 @@ export function HomeScreen(props: HomeScreenProps) {
760 reorderSupported={
761 item.item.pinned
762 ? pinReorderEnvironmentIds.has(thread.environmentId)
733 - : activeReorderEnvironmentIds.has(thread.environmentId)
763 + : !workingShelfEnabled && activeReorderEnvironmentIds.has(thread.environmentId)
764 }
765 canMoveUp={item.canMoveUp}
766 canMoveDown={item.canMoveDown}
@@ -782,8 +812,10 @@ export function HomeScreen(props: HomeScreenProps) {
812 titleRegenerationEnvironmentIds,
813 toggleSettledShelf,
814 toggleSnoozedShelf,
815 + toggleWorkingShelf,
816 v2ProjectTitleByProjectKey,
817 props.searchQuery,
818 + workingShelfEnabled,
819 ],
820 );
821 const v2KeyExtractor = useCallback((item: ThreadListV2ListItem) => item.key, []);
@@ -800,6 +832,8 @@ export function HomeScreen(props: HomeScreenProps) {
832 savedConnectionsById: props.savedConnectionsById,
833 searchQuery: props.searchQuery,
834 threadSearchMatchByKey,
835 + // Rows read it for their reorder menu items.
836 + workingShelfEnabled,
837 }),
838 [
839 projectByKey,
@@ -808,6 +842,7 @@ export function HomeScreen(props: HomeScreenProps) {
842 listEnvironments,
843 threadSearchMatchByKey,
844 v2ProjectTitleByProjectKey,
845 + workingShelfEnabled,
846 ],
847 );
848
apps/mobile/src/features/settings/SettingsThreadsRouteScreen.tsx
+30
@@ -45,6 +45,7 @@ export function SettingsThreadsRouteScreen() {
45 contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
46 >
47 <AutoSettleSettingsRows />
48 + <BetaSettingsSection />
49 <LegacySettingsSection />
50 </ScrollView>
51 </SettingsScreen>
@@ -239,6 +240,35 @@ function AutoSettleSettingsRows() {
240 );
241 }
242
243 +/**
244 + * Device-local beta toggles, the counterpart of web's Working section (beta)
245 + * in Settings → General.
246 + */
247 +function BetaSettingsSection() {
248 + const savePreferences = useAtomSet(updateMobilePreferencesAtom);
249 + const preferences = useAtomValue(mobilePreferencesAtom);
250 + const workingShelfEnabled =
251 + AsyncResult.isSuccess(preferences) && preferences.value.workingShelfEnabled === true;
252 +
253 + return (
254 + <View className="gap-3">
255 + <SettingsSection title="Beta">
256 + <SettingsSwitchRow
257 + icon="bolt.circle"
258 + label="Working section"
259 + value={workingShelfEnabled}
260 + onValueChange={(value) => savePreferences({ workingShelfEnabled: value })}
261 + />
262 + </SettingsSection>
263 + <Text className="px-2 text-sm text-foreground-muted">
264 + Fold working and monitoring threads into a Working section. They return to the top of the
265 + list when they need you. While this is on, active threads are ordered by time and cannot be
266 + moved.
267 + </Text>
268 + </View>
269 + );
270 +}
271 +
272 /**
273 * Device-local legacy toggles. Mobile has no client-settings sync, so this is
274 * the counterpart of web's Settings → General → Legacy features backed by
apps/mobile/src/features/threads/ThreadArrangementSheet.tsx
+13 -5
@@ -2,6 +2,7 @@ import { appAtomRegistry } from "../../state/atom-registry";
2 import { useAtomValue } from "@effect/atom-react";
3 import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
4 import { effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled";
5 +import { sortInboxThreadsByReturn } from "@t3tools/client-runtime/state/thread-inbox";
6 import { type ReactNode, useEffect, useMemo, useRef, useState } from "react";
7 import { Animated, FlatList, Modal, Pressable, View } from "react-native";
8 import { Gesture, GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";
@@ -26,7 +27,8 @@ import {
27 threadDragAction,
28 type ThreadMoveDestination,
29 } from "./threadOrder";
29 -import { getThreadListV2OrderedSection } from "./threadListV2";
30 +import { getThreadListV2OrderedSection, threadListInboxReturns } from "./threadListV2";
31 +import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-preferences";
32
33 const ROW_HEIGHT = 56;
34 const HEADER_HEIGHT = 48;
@@ -154,6 +156,7 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
156 const pendingOrder = useAtomValue(pendingThreadOrderAtom);
157 const dropBusy = useAtomValue(threadDropBusyAtom);
158 const { moveThread } = useThreadListActions();
159 + const { workingShelfEnabled } = useThreadListV2ShelfPreferences();
160 const [now, setNow] = useState(() => new Date().toISOString());
161 const [expanded, setExpanded] = useState({ snoozed: false, settled: false });
162 useEffect(() => {
@@ -195,23 +198,28 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
198 );
199 return {
200 pinned,
198 - active,
201 + // The Working beta orders the inbox by time; show that order here too.
202 + active: workingShelfEnabled
203 + ? sortInboxThreadsByReturn(active, threadListInboxReturns.returnedAt)
204 + : active,
205 snoozed: parked.filter((thread) => effectiveSnoozed(thread, { now })),
206 settled: parked.filter((thread) => !effectiveSnoozed(thread, { now })),
207 };
202 - }, [threads, configs, now, queuedThreadKeys, pendingOrder]);
208 + }, [threads, configs, now, queuedThreadKeys, pendingOrder, workingShelfEnabled]);
209 const planners = useMemo(() => {
210 const planner = (section: "pinned" | "active") =>
211 createThreadMovePlanner({
212 ordered: sections[section],
213 allThreads: threads,
214 section,
215 + // A time-ordered inbox has no slots, so Active takes no drops while
216 + // the Working beta is on. The saved arrangement stays untouched.
217 reorderableEnvironmentIds: new Set(
218 [...configs].flatMap(([id, config]) =>
219 (
220 section === "pinned"
221 ? config.environment.capabilities.threadPinReorder
214 - : config.environment.capabilities.threadActiveReorder
222 + : !workingShelfEnabled && config.environment.capabilities.threadActiveReorder
223 )
224 ? [id]
225 : [],
@@ -219,7 +227,7 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
227 ),
228 });
229 return { pinned: planner("pinned"), active: planner("active") };
222 - }, [sections, threads, configs]);
230 + }, [sections, threads, configs, workingShelfEnabled]);
231 const rows = useMemo(() => {
232 const result: Row[] = [];
233 let offset = 0;
apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
+37 -2
@@ -61,6 +61,7 @@ import {
61 ThreadListV2SettledShelfHeader,
62 ThreadListV2ShowMoreRow,
63 ThreadListV2SnoozedShelfHeader,
64 + ThreadListV2WorkingShelfHeader,
65 } from "./thread-list-v2-items";
66 import { useThreadRowProviderInstanceResolver } from "./thread-provider-instance";
67 import {
@@ -69,6 +70,7 @@ import {
70 buildThreadListV2ListItems,
71 isThreadListV2ListItem,
72 threadListV2ListItemsAreEqual,
73 + threadListInboxReturns,
74 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
75 THREAD_LIST_V2_SETTLED_PAGE_COUNT,
76 type ThreadListV2ListItem,
@@ -291,8 +293,11 @@ function ThreadNavigationSidebarPane(
293 loaded: shelfPreferencesLoaded,
294 settledShelfExpanded,
295 snoozedShelfExpanded,
296 + workingShelfEnabled,
297 + workingShelfExpanded,
298 toggleSettledShelf,
299 toggleSnoozedShelf,
300 + toggleWorkingShelf,
301 } = useThreadListV2ShelfPreferences();
302 // The queued-start and snooze helpers need a clock while the pane stays open.
303 const [nowMinute, setNowMinute] = useState(() => new Date().toISOString().slice(0, 16));
@@ -343,8 +348,13 @@ function ThreadNavigationSidebarPane(
348 queuedThreadKeys,
349 }),
350 });
346 - return new Map([...sectionAvailability("pinned"), ...sectionAvailability("active")]);
351 + // The Working beta orders the inbox by time, so only pins can move.
352 + return new Map([
353 + ...sectionAvailability("pinned"),
354 + ...(workingShelfEnabled ? [] : sectionAvailability("active")),
355 + ]);
356 }, [
357 + workingShelfEnabled,
358 pinReorderEnvironmentIds,
359 activeReorderEnvironmentIds,
360 threads,
@@ -356,6 +366,7 @@ function ThreadNavigationSidebarPane(
366 snoozeWakeTick,
367 ]);
368 const threadListV2Layout = useMemo(() => {
369 + threadListInboxReturns.observe(workingShelfEnabled ? threads : null);
370 return buildThreadListV2Items({
371 pendingOrder,
372 threads: threads.filter((thread) => thread.archivedAt === null),
@@ -368,11 +379,16 @@ function ThreadNavigationSidebarPane(
379 queuedThreadKeys,
380 settledLimit: settledVisibleCount,
381 now: new Date().toISOString(),
382 + workingShelfEnabled,
383 + workingShelfExpanded,
384 + inboxReturnAt: threadListInboxReturns.returnedAt,
385 snoozedShelfExpanded,
386 settledShelfExpanded,
387 selectedThreadKey: props.selectedThreadKey ?? null,
388 });
389 }, [
390 + workingShelfEnabled,
391 + workingShelfExpanded,
392 pendingOrder,
393 queuedThreadKeys,
394 nowMinute,
@@ -424,6 +440,9 @@ function ThreadNavigationSidebarPane(
440 const items: SidebarListItem[] = buildThreadListV2ListItems({
441 items: threadListV2Layout.items,
442 pendingTasks: v2PendingTasks,
443 + workingCount: threadListV2Layout.workingCount,
444 + workingShelfExpanded,
445 + workingShelfHeaderIndex: threadListV2Layout.workingShelfHeaderIndex,
446 snoozedCount: threadListV2Layout.snoozedCount,
447 snoozedShelfExpanded,
448 snoozedShelfHeaderIndex: threadListV2Layout.snoozedShelfHeaderIndex,
@@ -457,6 +476,7 @@ function ThreadNavigationSidebarPane(
476 snoozedShelfExpanded,
477 snoozeEnvironmentIds,
478 threadListV2Layout,
479 + workingShelfExpanded,
480 ]);
481 const listMenuActions = useMemo<MenuAction[]>(
482 () => [
@@ -587,6 +607,8 @@ function ThreadNavigationSidebarPane(
607 savedConnectionsById,
608 listEnvironments,
609 threadSearchMatchByKey,
610 + // Rows read it for their reorder menu items.
611 + workingShelfEnabled,
612 }),
613 [
614 props.selectedThreadKey,
@@ -595,6 +617,7 @@ function ThreadNavigationSidebarPane(
617 savedConnectionsById,
618 listEnvironments,
619 threadSearchMatchByKey,
620 + workingShelfEnabled,
621 ],
622 );
623 useThreadJumpShortcuts(listItems, handleSelectThread);
@@ -712,7 +735,7 @@ function ThreadNavigationSidebarPane(
735 reorderSupported={
736 item.item.pinned
737 ? pinReorderEnvironmentIds.has(thread.environmentId)
715 - : activeReorderEnvironmentIds.has(thread.environmentId)
738 + : !workingShelfEnabled && activeReorderEnvironmentIds.has(thread.environmentId)
739 }
740 canMoveUp={item.canMoveUp}
741 canMoveDown={item.canMoveDown}
@@ -729,6 +752,16 @@ function ThreadNavigationSidebarPane(
752 />
753 );
754 }
755 + case "v2-working-shelf":
756 + return (
757 + <ThreadListV2WorkingShelfHeader
758 + count={item.count}
759 + disabled={item.disabled}
760 + expanded={item.expanded}
761 + onToggle={toggleWorkingShelf}
762 + pane="sidebar"
763 + />
764 + );
765 case "v2-snoozed-shelf":
766 return (
767 <ThreadListV2SnoozedShelfHeader
@@ -797,9 +830,11 @@ function ThreadNavigationSidebarPane(
830 snoozeThread,
831 toggleSettledShelf,
832 toggleSnoozedShelf,
833 + toggleWorkingShelf,
834 unpinThread,
835 unsettleThread,
836 unsnoozeThread,
837 + workingShelfEnabled,
838 ],
839 );
840 // The list ignores sort/group options, so only the environment and project
apps/mobile/src/features/threads/thread-list-v2-items.tsx
+10 -2
@@ -191,10 +191,12 @@ type ThreadListV2ShelfHeaderProps = {
191 readonly pane?: "screen" | "sidebar";
192 };
193
194 +const SHELF_LABEL = { working: "Working", snoozed: "Snoozed", settled: "Settled" } as const;
195 +
196 function ThreadListV2ShelfHeader(
195 - props: ThreadListV2ShelfHeaderProps & { readonly kind: "snoozed" | "settled" },
197 + props: ThreadListV2ShelfHeaderProps & { readonly kind: keyof typeof SHELF_LABEL },
198 ) {
197 - const label = props.kind === "snoozed" ? "Snoozed" : "Settled";
199 + const label = SHELF_LABEL[props.kind];
200 return (
201 <ThreadListV2Section
202 label={props.expanded ? label : `${label} (${props.count})`}
@@ -211,6 +213,12 @@ function ThreadListV2ShelfHeader(
213 );
214 }
215
216 +export const ThreadListV2WorkingShelfHeader = memo(function ThreadListV2WorkingShelfHeader(
217 + props: ThreadListV2ShelfHeaderProps,
218 +) {
219 + return <ThreadListV2ShelfHeader {...props} kind="working" />;
220 +});
221 +
222 export const ThreadListV2SnoozedShelfHeader = memo(function ThreadListV2SnoozedShelfHeader(
223 props: ThreadListV2ShelfHeaderProps,
224 ) {
apps/mobile/src/features/threads/threadListV2.test.ts
+144
@@ -2158,3 +2158,147 @@ describe("buildThreadListV2ListItems row-state stamps", () => {
2158 expect(threadListV2ListItemsAreEqual(shelfLoading, shelfLoaded)).toBe(false);
2159 });
2160 });
2161 +
2162 +describe("Working section beta", () => {
2163 + const running = {
2164 + status: "running" as const,
2165 + activeRunId: null,
2166 + providerInstanceId: ProviderInstanceId.make("codex"),
2167 + providerName: "Codex",
2168 + lastError: null,
2169 + updatedAt: NOW,
2170 + };
2171 + const finishedAt = (id: string, completedAt: string) =>
2172 + makeThread({
2173 + id: ThreadId.make(id),
2174 + title: id,
2175 + createdAt: "2026-06-01T00:00:00.000Z",
2176 + latestRun: {
2177 + runId: RunId.make(`run-${id}`),
2178 + status: "completed",
2179 + requestedAt: "2026-06-01T00:00:00.000Z",
2180 + startedAt: "2026-06-01T00:00:00.000Z",
2181 + completedAt,
2182 + assistantMessageId: null,
2183 + },
2184 + });
2185 + const threads = [
2186 + finishedAt("finished-early", "2026-06-01T01:00:00.000Z"),
2187 + finishedAt("finished-late", "2026-06-01T03:00:00.000Z"),
2188 + makeThread({ id: ThreadId.make("working"), title: "working", runtime: running }),
2189 + makeThread({
2190 + id: ThreadId.make("asks-approval"),
2191 + title: "asks-approval",
2192 + createdAt: "2026-06-01T02:00:00.000Z",
2193 + runtime: running,
2194 + hasPendingApprovals: true,
2195 + }),
2196 + makeThread({
2197 + id: ThreadId.make("pinned-working"),
2198 + title: "pinned-working",
2199 + runtime: running,
2200 + pinnedAt: "2026-06-01T00:00:00.000Z",
2201 + }),
2202 + ];
2203 + const build = (input: Partial<Parameters<typeof buildThreadListV2Items>[0]> = {}) =>
2204 + buildThreadListV2Items({
2205 + threads,
2206 + environmentId: null,
2207 + searchQuery: "",
2208 + now: NOW,
2209 + workingShelfEnabled: true,
2210 + ...input,
2211 + });
2212 + const ids = (layout: ReturnType<typeof buildThreadListV2Items>) =>
2213 + layout.items.map((item) => item.thread.id);
2214 +
2215 + it("folds unpinned working threads into a collapsed shelf", () => {
2216 + const layout = build();
2217 + expect(ids(layout)).toEqual([
2218 + "pinned-working",
2219 + "finished-late",
2220 + "asks-approval",
2221 + "finished-early",
2222 + ]);
2223 + expect(layout.workingCount).toBe(1);
2224 + expect(layout.workingShelfHeaderIndex).toBe(4);
2225 +
2226 + const off = build({ workingShelfEnabled: false });
2227 + expect(ids(off)).toContain("working");
2228 + expect(off.workingCount).toBe(0);
2229 + });
2230 +
2231 + it("shows working rows as cards when expanded, or only the selected one when collapsed", () => {
2232 + expect(build({ workingShelfExpanded: true }).items.at(-1)).toMatchObject({
2233 + thread: { id: "working" },
2234 + variant: "card",
2235 + });
2236 + expect(ids(build({ selectedThreadKey: `${environmentId}:working` })).at(-1)).toBe("working");
2237 + });
2238 +
2239 + it("orders the inbox by the latest return this device observed", () => {
2240 + const layout = build({
2241 + inboxReturnAt: (thread) =>
2242 + thread.id === "finished-early" ? Date.parse("2026-06-01T04:00:00.000Z") : undefined,
2243 + });
2244 + expect(ids(layout).slice(1)).toEqual(["finished-early", "finished-late", "asks-approval"]);
2245 + });
2246 +
2247 + it("places the shelf after queued tasks and before snoozed and settled threads", () => {
2248 + const layout = buildThreadListV2Items({
2249 + threads: [
2250 + makeThread({ id: ThreadId.make("active"), title: "active" }),
2251 + makeThread({ id: ThreadId.make("working"), title: "working", runtime: running }),
2252 + makeThread({
2253 + id: ThreadId.make("snoozed"),
2254 + title: "snoozed",
2255 + runtime: running,
2256 + snoozedUntil: "2026-06-03T09:00:00.000Z",
2257 + snoozedAt: "2026-06-01T12:00:00.000Z",
2258 + }),
2259 + makeThread({
2260 + id: ThreadId.make("settled"),
2261 + title: "settled",
2262 + settledOverride: "settled",
2263 + settledAt: NOW,
2264 + }),
2265 + ],
2266 + environmentId: null,
2267 + searchQuery: "",
2268 + now: NOW,
2269 + workingShelfEnabled: true,
2270 + workingShelfExpanded: true,
2271 + snoozedShelfExpanded: true,
2272 + });
2273 + const items = buildThreadListV2ListItems({
2274 + items: layout.items,
2275 + pendingTasks: [makePendingTask("queued")],
2276 + workingCount: layout.workingCount,
2277 + workingShelfExpanded: true,
2278 + workingShelfHeaderIndex: layout.workingShelfHeaderIndex,
2279 + snoozedCount: layout.snoozedCount,
2280 + snoozedShelfExpanded: true,
2281 + snoozedShelfHeaderIndex: layout.snoozedShelfHeaderIndex,
2282 + settledCount: layout.settledCount,
2283 + settledShelfHeaderIndex: layout.settledShelfHeaderIndex,
2284 + });
2285 + expect(
2286 + items.map((item) =>
2287 + item.type === "v2-thread"
2288 + ? item.item.thread.id
2289 + : item.type === "v2-pending"
2290 + ? item.pendingTask.title
2291 + : item.type,
2292 + ),
2293 + ).toEqual([
2294 + "active",
2295 + "queued",
2296 + "v2-working-shelf",
2297 + "working",
2298 + "v2-snoozed-shelf",
2299 + "snoozed",
2300 + "v2-settled-shelf",
2301 + "settled",
2302 + ]);
2303 + });
2304 +});
apps/mobile/src/features/threads/threadListV2.ts
+91 -5
@@ -11,6 +11,11 @@ import type { SnoozePreset } from "@t3tools/client-runtime/state/thread-settled"
11 import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
12 import { resolveThreadProviderStack } from "@t3tools/client-runtime/state/models";
13 import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
14 +import {
15 + createInboxReturnTracker,
16 + isThreadWorking,
17 + sortInboxThreadsByReturn,
18 +} from "@t3tools/client-runtime/state/thread-inbox";
19 import {
20 sortActiveThreadsByOrderKey,
21 resolveSettledThreadTimestamp,
@@ -33,6 +38,11 @@ import {
38
39 export { snoozeWakeLabel };
40
41 +/** Working section beta: when this device saw each thread leave the Working
42 + shelf. One instance for Home and the iPad sidebar, so both lists order the
43 + inbox the same way and the order survives screens that unmount. */
44 +export const threadListInboxReturns = createInboxReturnTracker();
45 +
46 /**
47 * Provider drivers for a row's trailing icon stack, back to front. Instances
48 * missing from the environment's config are skipped, and an unresolved
@@ -269,6 +279,10 @@ export interface ThreadListV2Layout {
279 readonly items: ThreadListV2Item[];
280 /** Settled threads beyond the render limit (behind "Show more"). */
281 readonly hiddenSettledCount: number;
282 + /** Working threads folded away by the Working section beta. */
283 + readonly workingCount: number;
284 + /** Index in `items` where the Working shelf header belongs. */
285 + readonly workingShelfHeaderIndex: number | null;
286 /** Snoozed threads matching the current filters. */
287 readonly snoozedCount: number;
288 /** Index in `items` where the Snoozed shelf header belongs. The header is
@@ -325,6 +339,15 @@ export interface ThreadListV2PendingListItem {
339 readonly showTrailingDivider: boolean;
340 }
341
342 +export interface ThreadListV2WorkingShelfListItem {
343 + readonly type: "v2-working-shelf";
344 + readonly key: "v2-working-shelf";
345 + readonly count: number;
346 + readonly expanded: boolean;
347 + /** See the snoozed shelf header's field. */
348 + readonly disabled: boolean;
349 +}
350 +
351 export interface ThreadListV2SnoozedShelfListItem {
352 readonly type: "v2-snoozed-shelf";
353 readonly key: "v2-snoozed-shelf";
@@ -349,6 +372,7 @@ export interface ThreadListV2SettledShelfListItem {
372 export type ThreadListV2ListItem =
373 | ThreadListV2ThreadListItem
374 | ThreadListV2PendingListItem
375 + | ThreadListV2WorkingShelfListItem
376 | ThreadListV2SnoozedShelfListItem
377 | ThreadListV2SettledShelfListItem;
378
@@ -360,6 +384,7 @@ export function isThreadListV2ListItem(value: {
384 return (
385 value.type === "v2-thread" ||
386 value.type === "v2-pending" ||
387 + value.type === "v2-working-shelf" ||
388 value.type === "v2-snoozed-shelf" ||
389 value.type === "v2-settled-shelf"
390 );
@@ -401,6 +426,13 @@ export function threadListV2ListItemsAreEqual(
426 previous.showPendingDivider === item.showPendingDivider &&
427 previous.showTrailingDivider === item.showTrailingDivider
428 );
429 + case "v2-working-shelf":
430 + return (
431 + previous.type === "v2-working-shelf" &&
432 + previous.count === item.count &&
433 + previous.expanded === item.expanded &&
434 + previous.disabled === item.disabled
435 + );
436 case "v2-snoozed-shelf":
437 return (
438 previous.type === "v2-snoozed-shelf" &&
@@ -441,13 +473,17 @@ function resolveThreadListV2ItemTimeLabel(
473 }
474
475 /**
444 - * Builds the shared mobile order: active → pending → snoozed shelf → settled.
445 - * Pending tasks are waiting rather than asking, and parked work remains
446 - * reachable without competing with either the inbox or settled history.
476 + * Builds the shared mobile order: active → pending → working shelf (beta) →
477 + * snoozed shelf → settled. Pending tasks are waiting rather than asking, and
478 + * busy or parked work remains reachable without competing with either the
479 + * inbox or settled history.
480 */
481 export function buildThreadListV2ListItems(input: {
482 readonly items: ReadonlyArray<ThreadListV2Item>;
483 readonly pendingTasks: ReadonlyArray<PendingNewTask>;
484 + readonly workingCount?: number;
485 + readonly workingShelfExpanded?: boolean;
486 + readonly workingShelfHeaderIndex?: number | null;
487 readonly snoozedCount?: number;
488 readonly snoozedShelfExpanded?: boolean;
489 readonly snoozedShelfHeaderIndex?: number | null;
@@ -514,14 +550,27 @@ export function buildThreadListV2ListItems(input: {
550 showPendingDivider: index === 0,
551 showTrailingDivider: false,
552 }));
553 + const workingCount = input.workingCount ?? 0;
554 + const workingShelfHeaderIndex = input.workingShelfHeaderIndex ?? null;
555 const snoozedCount = input.snoozedCount ?? 0;
556 const snoozedShelfHeaderIndex = input.snoozedShelfHeaderIndex ?? null;
557 const settledCount = input.settledCount ?? 0;
558 const settledShelfHeaderIndex = input.settledShelfHeaderIndex ?? null;
521 - const activeEnd = snoozedShelfHeaderIndex ?? settledShelfHeaderIndex ?? threadItems.length;
559 const snoozedEnd = settledShelfHeaderIndex ?? threadItems.length;
560 + const workingEnd = snoozedShelfHeaderIndex ?? snoozedEnd;
561 + const activeEnd = workingShelfHeaderIndex ?? workingEnd;
562 const result: ThreadListV2ListItem[] = [...threadItems.slice(0, activeEnd), ...pendingItems];
563 const shelfDisabled = input.shelfPreferencesLoading === true;
564 + if (workingShelfHeaderIndex !== null && workingCount > 0) {
565 + result.push({
566 + type: "v2-working-shelf",
567 + key: "v2-working-shelf",
568 + count: workingCount,
569 + expanded: input.workingShelfExpanded === true,
570 + disabled: shelfDisabled,
571 + });
572 + result.push(...threadItems.slice(workingShelfHeaderIndex, workingEnd));
573 + }
574 if (snoozedShelfHeaderIndex !== null && snoozedCount > 0) {
575 result.push({
576 type: "v2-snoozed-shelf",
@@ -580,6 +629,15 @@ export function buildThreadListV2Items(input: {
629 readonly settledLimit?: number;
630 /** Second-precise clock used for time-based classification. */
631 readonly now: string;
632 + /** Working section beta: unpinned working threads fold into the Working
633 + shelf, and the inbox orders by when each thread came back to the user
634 + instead of the saved arrangement. */
635 + readonly workingShelfEnabled?: boolean;
636 + /** Expands the Working shelf into rows. Collapsed is the default. */
637 + readonly workingShelfExpanded?: boolean;
638 + /** Returns this device observed but the server does not stamp, such as an
639 + approval request mid-turn. Only read while the beta is on. */
640 + readonly inboxReturnAt?: (thread: EnvironmentThreadShell) => number | undefined;
641 /** Expands the snoozed shelf into rows. Collapsed is the default. */
642 readonly snoozedShelfExpanded?: boolean;
643 /** Expands the settled shelf into rows. Expanded is the default. */
@@ -609,8 +667,10 @@ export function buildThreadListV2Items(input: {
667 ? new Set(input.projectRefs.map((ref) => `${ref.environmentId}:${ref.projectId}`))
668 : null;
669
670 + const workingShelfEnabled = input.workingShelfEnabled === true;
671 const pinned: EnvironmentThreadShell[] = [];
672 const active: EnvironmentThreadShell[] = [];
673 + const working: EnvironmentThreadShell[] = [];
674 const settled: EnvironmentThreadShell[] = [];
675 const snoozed: EnvironmentThreadShell[] = [];
676 let nextSnoozeWakeAt: string | null = null;
@@ -656,17 +716,31 @@ export function buildThreadListV2Items(input: {
716 settled.push(thread);
717 } else if (thread.pinnedAt != null) {
718 pinned.push(thread);
719 + } else if (workingShelfEnabled && isThreadWorking(thread)) {
720 + working.push(thread);
721 } else {
722 active.push(thread);
723 }
724 }
725
664 - const orderedActive = applyPendingThreadOrder(sortThreadsForListV2(active), "active", pending);
726 + // The beta inbox is time-ordered, so the saved arrangement (and any move in
727 + // flight) is kept but not applied until the beta is off again.
728 + const orderedActive = workingShelfEnabled
729 + ? sortInboxThreadsByReturn(active, input.inboxReturnAt)
730 + : applyPendingThreadOrder(sortThreadsForListV2(active), "active", pending);
731 + // Newest work first, by the same clock as the inbox.
732 + const orderedWorking = sortInboxThreadsByReturn(working);
733 const orderedSnoozed = [...snoozed].sort(
734 (left, right) =>
735 parseTimestampMs(left.snoozedUntil ?? "") - parseTimestampMs(right.snoozedUntil ?? ""),
736 );
737 const selectedThreadKey = input.selectedThreadKey ?? null;
738 + const visibleWorking =
739 + input.workingShelfExpanded === true
740 + ? orderedWorking
741 + : orderedWorking.filter(
742 + (thread) => `${thread.environmentId}:${thread.id}` === selectedThreadKey,
743 + );
744 const visibleSnoozed =
745 input.snoozedShelfExpanded === true
746 ? orderedSnoozed
@@ -711,6 +785,16 @@ export function buildThreadListV2Items(input: {
785 isLast: false,
786 });
787 }
788 + const workingShelfHeaderIndex = orderedWorking.length > 0 ? items.length : null;
789 + for (const thread of visibleWorking) {
790 + items.push({
791 + thread,
792 + variant: "card",
793 + snoozed: false,
794 + pinned: false,
795 + isLast: false,
796 + });
797 + }
798 const snoozedShelfHeaderIndex = orderedSnoozed.length > 0 ? items.length : null;
799 for (const thread of visibleSnoozed) {
800 items.push({
@@ -738,6 +822,8 @@ export function buildThreadListV2Items(input: {
822 return {
823 items,
824 hiddenSettledCount: orderedSettled.length - pagedSettled.length,
825 + workingCount: orderedWorking.length,
826 + workingShelfHeaderIndex,
827 snoozedCount: orderedSnoozed.length,
828 snoozedShelfHeaderIndex,
829 settledCount: orderedSettled.length,
apps/mobile/src/features/threads/use-thread-list-v2-shelf-preferences.ts
+15
@@ -17,10 +17,16 @@ export function useThreadListV2ShelfPreferences() {
17 loaded && preferencesResult.value.threadListSnoozedShelfExpanded === true;
18 const settledShelfExpanded =
19 loaded && preferencesResult.value.threadListSettledShelfExpanded === true;
20 + // Working section beta: off until the preference loads and is enabled.
21 + const workingShelfEnabled = loaded && preferencesResult.value.workingShelfEnabled === true;
22 + const workingShelfExpanded =
23 + loaded && preferencesResult.value.threadListWorkingShelfExpanded === true;
24 const snoozedShelfExpandedRef = useRef(snoozedShelfExpanded);
25 const settledShelfExpandedRef = useRef(settledShelfExpanded);
26 + const workingShelfExpandedRef = useRef(workingShelfExpanded);
27 snoozedShelfExpandedRef.current = snoozedShelfExpanded;
28 settledShelfExpandedRef.current = settledShelfExpanded;
29 + workingShelfExpandedRef.current = workingShelfExpanded;
30
31 const toggleSnoozedShelf = useCallback(() => {
32 if (!loaded) return;
@@ -34,12 +40,21 @@ export function useThreadListV2ShelfPreferences() {
40 settledShelfExpandedRef.current = expanded;
41 savePreferences({ threadListSettledShelfExpanded: expanded });
42 }, [loaded, savePreferences]);
43 + const toggleWorkingShelf = useCallback(() => {
44 + if (!loaded) return;
45 + const expanded = !workingShelfExpandedRef.current;
46 + workingShelfExpandedRef.current = expanded;
47 + savePreferences({ threadListWorkingShelfExpanded: expanded });
48 + }, [loaded, savePreferences]);
49
50 return {
51 loaded,
52 settledShelfExpanded,
53 snoozedShelfExpanded,
54 + workingShelfEnabled,
55 + workingShelfExpanded,
56 toggleSettledShelf,
57 toggleSnoozedShelf,
58 + toggleWorkingShelf,
59 } as const;
60 }
apps/mobile/src/lib/storage.test.ts
+9 -1
@@ -232,24 +232,32 @@ describe("mobile connection storage", () => {
232 expect(fallback.updatedAt).toEqual(expect.any(Number));
233 });
234
235 - it("persists thread list shelf expansion preferences", async () => {
235 + it("persists thread list shelf preferences", async () => {
236 await expect(
237 savePreferencesPatch({
238 threadListSettledShelfExpanded: false,
239 threadListSnoozedShelfExpanded: true,
240 + threadListWorkingShelfExpanded: true,
241 + workingShelfEnabled: true,
242 }),
243 ).resolves.toEqual({
244 threadListSettledShelfExpanded: false,
245 threadListSnoozedShelfExpanded: true,
246 + threadListWorkingShelfExpanded: true,
247 + workingShelfEnabled: true,
248 });
249
250 await expect(loadPreferences()).resolves.toEqual({
251 threadListSettledShelfExpanded: false,
252 threadListSnoozedShelfExpanded: true,
253 + threadListWorkingShelfExpanded: true,
254 + workingShelfEnabled: true,
255 });
256 expect(JSON.parse(mocks.getPreferencesJson() ?? "")).toEqual({
257 threadListSettledShelfExpanded: false,
258 threadListSnoozedShelfExpanded: true,
259 + threadListWorkingShelfExpanded: true,
260 + workingShelfEnabled: true,
261 });
262 });
263
apps/mobile/src/persistence/mobile-preferences.ts
+11
@@ -41,6 +41,8 @@ export interface Preferences {
41 readonly projectGroupingMode?: SidebarProjectGroupingMode;
42 /** Device-local counterpart of desktop's `planModeEnabled` legacy flag. */
43 readonly planModeEnabled?: boolean;
44 + /** Device-local counterpart of web's `sidebarWorkingShelfEnabled` beta. */
45 + readonly workingShelfEnabled?: boolean;
46 /** Model favorites belong to this device, like the web client setting. */
47 readonly modelFavorites?: ReadonlyArray<{
48 readonly provider: ProviderInstanceId;
@@ -49,6 +51,7 @@ export interface Preferences {
51 /** Fresh keys reset both shelves to collapsed when users update. */
52 readonly threadListSettledShelfExpanded?: boolean;
53 readonly threadListSnoozedShelfExpanded?: boolean;
54 + readonly threadListWorkingShelfExpanded?: boolean;
55 }
56
57 export class MobilePreferencesLoadError extends Schema.TaggedError<MobilePreferencesLoadError>()(
@@ -107,9 +110,11 @@ function sanitizePreferences(parsed: Preferences): Preferences {
110 projectGroupingEnabled?: boolean;
111 projectGroupingMode?: SidebarProjectGroupingMode;
112 planModeEnabled?: boolean;
113 + workingShelfEnabled?: boolean;
114 modelFavorites?: Preferences["modelFavorites"];
115 threadListSettledShelfExpanded?: boolean;
116 threadListSnoozedShelfExpanded?: boolean;
117 + threadListWorkingShelfExpanded?: boolean;
118 } = {};
119
120 if (typeof parsed.liveActivitiesEnabled === "boolean") {
@@ -180,6 +185,9 @@ function sanitizePreferences(parsed: Preferences): Preferences {
185 if (typeof parsed.planModeEnabled === "boolean") {
186 preferences.planModeEnabled = parsed.planModeEnabled;
187 }
188 + if (typeof parsed.workingShelfEnabled === "boolean") {
189 + preferences.workingShelfEnabled = parsed.workingShelfEnabled;
190 + }
191 if (Array.isArray(parsed.modelFavorites)) {
192 preferences.modelFavorites = parsed.modelFavorites.filter(
193 (favorite) =>
@@ -197,6 +205,9 @@ function sanitizePreferences(parsed: Preferences): Preferences {
205 if (typeof parsed.threadListSnoozedShelfExpanded === "boolean") {
206 preferences.threadListSnoozedShelfExpanded = parsed.threadListSnoozedShelfExpanded;
207 }
208 + if (typeof parsed.threadListWorkingShelfExpanded === "boolean") {
209 + preferences.threadListWorkingShelfExpanded = parsed.threadListWorkingShelfExpanded;
210 + }
211 return preferences;
212 }
213
apps/web/src/components/Sidebar.logic.ts
+5 -45
@@ -1008,21 +1008,6 @@ export function shouldShowSidebarV2Duration(status: SidebarThreadStatus): boolea
1008 return status === "working";
1009 }
1010
1011 -/** Working beta: threads busy with work that does not need the user fold into
1012 - the Working shelf: a running run, or one stopped with background work
1013 - that will wake it. Approvals, questions, plan prompts, and failures stay in the
1014 - inbox. */
1015 -export function isSidebarThreadWorking(thread: ThreadStatusInput): boolean {
1016 - const status = resolveSidebarThreadStatus(thread);
1017 - if (status !== "working" && status !== "waiting") return false;
1018 - // A plan prompt outranks lingering background work: the user has to act on it.
1019 - return !(
1020 - thread.interactionMode === "plan" &&
1021 - thread.hasActionableProposedPlan &&
1022 - isLatestRunSettled(thread.latestRun, thread.runtime)
1023 - );
1024 -}
1025 -
1011 /** First VALID timestamp wins: `a ?? b` falls through on null, but a present-
1012 yet-malformed string must also fall through to the next candidate rather
1013 than sink the row to the epoch. */
@@ -1038,6 +1023,11 @@ export function firstValidTimestampMs(
1023 }
1024
1025 export { sortActiveThreadsByOrderKey as sortThreadsForSidebar } from "@t3tools/client-runtime/state/thread-sort";
1026 +// The Working section beta folds and orders the inbox the same way on mobile.
1027 +export {
1028 + isThreadWorking as isSidebarThreadWorking,
1029 + sortInboxThreadsByReturn,
1030 +} from "@t3tools/client-runtime/state/thread-inbox";
1031
1032 // Pinned-reorder key math and the keyed sort live in client-runtime
1033 // (state/thread-sort) so web and mobile compute identical pinned orders.
@@ -1119,36 +1109,6 @@ export function reduceSidebarProjectScopeMenuState(
1109 }
1110 }
1111
1122 -/** Working beta: the inbox lists threads newest first by when each last came
1123 - back to the user, so a thread that leaves the Working shelf lands on top.
1124 - `observedReturnAt` adds returns the server does not stamp, such as an
1125 - approval request mid-turn or background work ending. */
1126 -export function sortInboxThreadsByReturn<
1127 - T extends Pick<
1128 - SidebarThreadSummary,
1129 - "id" | "environmentId" | "createdAt" | "unsettledAt" | "latestRun"
1130 - >,
1131 ->(threads: readonly T[], observedReturnAt?: (thread: T) => number | undefined): T[] {
1132 - const timestamps = new Map(
1133 - threads.map((thread) => [
1134 - thread,
1135 - Math.max(
1136 - toSortableTimestamp(thread.createdAt) ?? 0,
1137 - toSortableTimestamp(thread.unsettledAt ?? undefined) ?? 0,
1138 - toSortableTimestamp(thread.latestRun?.requestedAt ?? undefined) ?? 0,
1139 - toSortableTimestamp(thread.latestRun?.completedAt ?? undefined) ?? 0,
1140 - observedReturnAt?.(thread) ?? 0,
1141 - ),
1142 - ]),
1143 - );
1144 - return [...threads].sort(
1145 - (left, right) =>
1146 - timestamps.get(right)! - timestamps.get(left)! ||
1147 - left.id.localeCompare(right.id) ||
1148 - left.environmentId.localeCompare(right.environmentId),
1149 - );
1150 -}
1151 -
1112 /** The timestamp a working thread's elapsed label counts from: when its
1113 current work started (request time until adoption). Background wakes do
1114 not reset it. Malformed timestamps fall through to the next candidate. */
apps/web/src/components/Sidebar.tsx
+5 -36
@@ -31,6 +31,7 @@ import {
31 effectiveSnoozed,
32 threadWokeAt,
33 } from "@t3tools/client-runtime/state/thread-settled";
34 +import { createInboxReturnTracker } from "@t3tools/client-runtime/state/thread-inbox";
35 import {
36 resolveSettledThreadTimestamp,
37 sortSettledThreads,
@@ -289,35 +290,7 @@ const WORKING_SHELF_EXPANDED_KEY = "t3code:sidebar:working-expanded";
290
291 // Working beta: when this client saw each thread leave the Working shelf.
292 // Module scope keeps the inbox order across routes that unmount the sidebar.
292 -let lastWorkingThreadKeys: ReadonlySet<string> | null = null;
293 -const observedInboxReturns = new Map<string, number>();
294 -
295 -/** Stamps threads that stopped working since the last call. The first call
296 - only takes a baseline, so mounting never reshuffles the inbox. Pass null
297 - to reset when the beta is off. */
298 -function observeInboxReturns(threads: readonly EnvironmentThreadShell[] | null): void {
299 - if (threads === null) {
300 - lastWorkingThreadKeys = null;
301 - observedInboxReturns.clear();
302 - return;
303 - }
304 - const working = new Set<string>();
305 - const present = new Set<string>();
306 - for (const thread of threads) {
307 - const key = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
308 - present.add(key);
309 - if (isSidebarThreadWorking(thread)) working.add(key);
310 - }
311 - // Drop deleted threads so the map stays bounded by the live thread list.
312 - for (const key of observedInboxReturns.keys()) {
313 - if (!present.has(key)) observedInboxReturns.delete(key);
314 - }
315 - const now = Date.now();
316 - for (const key of lastWorkingThreadKeys ?? []) {
317 - if (present.has(key) && !working.has(key)) observedInboxReturns.set(key, now);
318 - }
319 - lastWorkingThreadKeys = working;
320 -}
293 +const inboxReturns = createInboxReturnTracker();
294
295 function compactSidebarTimeLabel(label: string): string {
296 if (label === "just now") return "now";
@@ -2669,7 +2642,7 @@ export default function Sidebar() {
2642 // Subagent child threads live in the parent's Agents surface, not the
2643 // sidebar roster (v2 models them as real threads with lineage).
2644 const visible = filterSidebarV2VisibleThreads(threads, scopedProjectKeys);
2672 - observeInboxReturns(workingShelfEnabled ? threads : null);
2645 + inboxReturns.observe(workingShelfEnabled ? threads : null);
2646 const pinned: EnvironmentThreadShell[] = [];
2647 const active: EnvironmentThreadShell[] = [];
2648 const working: EnvironmentThreadShell[] = [];
@@ -2736,11 +2709,7 @@ export default function Sidebar() {
2709 // web and mobile from the same data.
2710 const sortedPinned = sortPinnedThreadsForSidebar(pinned);
2711 const sortedActive = workingShelfEnabled
2739 - ? sortInboxThreadsByReturn(active, (thread) =>
2740 - observedInboxReturns.get(
2741 - scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
2742 - ),
2743 - )
2712 + ? sortInboxThreadsByReturn(active, inboxReturns.returnedAt)
2713 : sortThreadsForSidebar(active);
2714 return {
2715 pinnedThreads:
@@ -3701,7 +3670,7 @@ export default function Sidebar() {
3670 ...activeThreads.filter((candidate) => key(candidate) !== dragState.activeKey),
3671 applySidebarThreadDrop(thread, "active", dragState.occurredAt),
3672 ],
3704 - (candidate) => observedInboxReturns.get(key(candidate)),
3673 + inboxReturns.returnedAt,
3674 ).map(key);
3675 }, [activeThreads, dragState, threadByKey, workingShelfEnabled]);
3676 const sidebarSortingStrategy = useMemo(
docs/user/thread-sidebar.md
+6 -5
@@ -111,13 +111,14 @@ open.
111
112 ### Fold working threads (beta)
113
114 -On web and desktop, turn on **Settings → General → Working section (beta)** to move threads that
115 -are working or monitoring into a collapsed **Working** section at the bottom of the sidebar. A
116 -thread returns to the top of the active list when it finishes, fails, or needs an approval or
117 -answer. Pinned threads stay in the pinned section.
114 +Turn on **Settings → General → Working section (beta)** on web and desktop, or **Settings →
115 +Thread behavior → Working section** on iOS and Android, to move threads that are working or
116 +monitoring into a collapsed **Working** section below the active list. A thread returns to the top
117 +of the active list when it finishes, fails, or needs an approval or answer. Pinned threads stay in
118 +the pinned section. Each device keeps its own choice.
119
120 While this is on, the active list is ordered by when each thread last came back to you, so you
120 -cannot drag to reorder it. Your saved order returns when you turn it off.
121 +cannot drag or move threads within it. Your saved order returns when you turn it off.
122
123 ## Settle finished work
124
packages/client-runtime/package.json
+4
@@ -259,6 +259,10 @@
259 "types": "./src/state/threadSort.ts",
260 "default": "./src/state/threadSort.ts"
261 },
262 + "./state/thread-inbox": {
263 + "types": "./src/state/threadInbox.ts",
264 + "default": "./src/state/threadInbox.ts"
265 + },
266 "./state/thread-relationships": {
267 "types": "./src/state/threadRelationships.ts",
268 "default": "./src/state/threadRelationships.ts"
packages/client-runtime/src/state/threadInbox.test.ts new
+59
@@ -0,0 +1,59 @@
1 +import { EnvironmentId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
2 +import { describe, expect, it } from "vite-plus/test";
3 +
4 +import { createInboxReturnTracker } from "./threadInbox.ts";
5 +
6 +const environmentId = EnvironmentId.make("environment-1");
7 +
8 +function thread(id: string, working: boolean) {
9 + return {
10 + id: ThreadId.make(id),
11 + environmentId,
12 + createdAt: "2026-06-01T00:00:00.000Z",
13 + unsettledAt: null,
14 + latestRun: null,
15 + hasActionableProposedPlan: false,
16 + hasPendingApprovals: false,
17 + hasPendingUserInput: false,
18 + interactionMode: "default" as const,
19 + runtime: working
20 + ? {
21 + status: "running" as const,
22 + activeRunId: null,
23 + providerInstanceId: ProviderInstanceId.make("codex"),
24 + providerName: "Codex",
25 + lastError: null,
26 + updatedAt: "2026-06-01T00:00:00.000Z",
27 + }
28 + : null,
29 + };
30 +}
31 +
32 +describe("createInboxReturnTracker", () => {
33 + it("stamps a thread when it stops working, but never on the first observation", () => {
34 + const tracker = createInboxReturnTracker();
35 + tracker.observe([thread("a", true), thread("b", false)]);
36 + expect(tracker.returnedAt(thread("a", true))).toBeUndefined();
37 + expect(tracker.returnedAt(thread("b", false))).toBeUndefined();
38 +
39 + tracker.observe([thread("a", false), thread("b", false)]);
40 + expect(tracker.returnedAt(thread("a", false))).toBeDefined();
41 + expect(tracker.returnedAt(thread("b", false))).toBeUndefined();
42 + });
43 +
44 + it("forgets deleted threads and resets when the beta turns off", () => {
45 + const tracker = createInboxReturnTracker();
46 + tracker.observe([thread("a", true), thread("b", true)]);
47 + tracker.observe([thread("a", false), thread("b", false)]);
48 + tracker.observe([thread("b", false)]);
49 + expect(tracker.returnedAt(thread("a", false))).toBeUndefined();
50 + expect(tracker.returnedAt(thread("b", false))).toBeDefined();
51 +
52 + tracker.observe(null);
53 + expect(tracker.returnedAt(thread("b", false))).toBeUndefined();
54 + // After a reset the next call is a fresh baseline again.
55 + tracker.observe([thread("b", true)]);
56 + tracker.observe([thread("b", false)]);
57 + expect(tracker.returnedAt(thread("b", false))).toBeDefined();
58 + });
59 +});
packages/client-runtime/src/state/threadInbox.ts new
+111
@@ -0,0 +1,111 @@
1 +import { threadRuntimeIsActive, type EnvironmentThreadShell } from "./models.ts";
2 +import { toSortableTimestamp } from "./threadSort.ts";
3 +
4 +// Working section beta, shared so web and mobile fold and order the inbox the
5 +// same way. Off by default; each client owns its own toggle.
6 +
7 +type WorkingThreadInput = Pick<
8 + EnvironmentThreadShell,
9 + | "hasActionableProposedPlan"
10 + | "hasPendingApprovals"
11 + | "hasPendingUserInput"
12 + | "interactionMode"
13 + | "latestRun"
14 + | "runtime"
15 +>;
16 +
17 +/** Threads busy with work that does not need the user fold into the Working
18 + section: a running run, or one stopped with background work that will wake
19 + it. Approvals, questions, plan prompts, and failures stay in the inbox. */
20 +export function isThreadWorking(thread: WorkingThreadInput): boolean {
21 + if (thread.hasPendingApprovals || thread.hasPendingUserInput) return false;
22 + if (!threadRuntimeIsActive(thread.runtime) && thread.runtime?.status !== "idle") return false;
23 + // A plan prompt outranks lingering background work: the user has to act on it.
24 + const run = thread.latestRun;
25 + const runSettled =
26 + run !== null &&
27 + run.status !== "preparing" &&
28 + run.status !== "queued" &&
29 + run.status !== "starting" &&
30 + run.status !== "running" &&
31 + run.status !== "waiting" &&
32 + thread.runtime?.activeRunId !== run.runId;
33 + return !(thread.interactionMode === "plan" && thread.hasActionableProposedPlan && runSettled);
34 +}
35 +
36 +type InboxThreadInput = Pick<
37 + EnvironmentThreadShell,
38 + "id" | "environmentId" | "createdAt" | "unsettledAt" | "latestRun"
39 +>;
40 +
41 +/** The inbox lists threads newest first by when each last came back to the
42 + user, so a thread that leaves the Working section lands on top.
43 + `observedReturnAt` adds returns the server does not stamp, such as an
44 + approval request mid-turn or background work ending. */
45 +export function sortInboxThreadsByReturn<T extends InboxThreadInput>(
46 + threads: readonly T[],
47 + observedReturnAt?: (thread: T) => number | undefined,
48 +): T[] {
49 + const timestamps = new Map(
50 + threads.map((thread) => [
51 + thread,
52 + Math.max(
53 + toSortableTimestamp(thread.createdAt) ?? 0,
54 + toSortableTimestamp(thread.unsettledAt ?? undefined) ?? 0,
55 + toSortableTimestamp(thread.latestRun?.requestedAt ?? undefined) ?? 0,
56 + toSortableTimestamp(thread.latestRun?.completedAt ?? undefined) ?? 0,
57 + observedReturnAt?.(thread) ?? 0,
58 + ),
59 + ]),
60 + );
61 + return [...threads].sort(
62 + (left, right) =>
63 + timestamps.get(right)! - timestamps.get(left)! ||
64 + left.id.localeCompare(right.id) ||
65 + left.environmentId.localeCompare(right.environmentId),
66 + );
67 +}
68 +
69 +/**
70 + * Remembers when this client saw each thread leave the Working section. Keep
71 + * one at module scope so the inbox order survives routes that unmount the
72 + * list. Call `observe` with every thread shell on each list rebuild, or with
73 + * null to reset while the beta is off. The first call only takes a baseline,
74 + * so mounting never reshuffles the inbox.
75 + */
76 +export function createInboxReturnTracker() {
77 + const keyOf = (thread: Pick<EnvironmentThreadShell, "environmentId" | "id">) =>
78 + `${thread.environmentId}:${thread.id}`;
79 + let lastWorkingKeys: ReadonlySet<string> | null = null;
80 + const returns = new Map<string, number>();
81 + return {
82 + observe(threads: ReadonlyArray<WorkingThreadInput & InboxThreadInput> | null): void {
83 + if (threads === null) {
84 + lastWorkingKeys = null;
85 + returns.clear();
86 + return;
87 + }
88 + const working = new Set<string>();
89 + const present = new Set<string>();
90 + for (const thread of threads) {
91 + const key = keyOf(thread);
92 + present.add(key);
93 + if (isThreadWorking(thread)) working.add(key);
94 + }
95 + // Drop deleted threads so the map stays bounded by the live thread list.
96 + for (const key of returns.keys()) {
97 + if (!present.has(key)) returns.delete(key);
98 + }
99 + // The moment this client saw the change is the data; there is no
100 + // server stamp to read instead.
101 + // @effect-diagnostics-next-line globalDate:off
102 + const at = Date.now();
103 + for (const key of lastWorkingKeys ?? []) {
104 + if (present.has(key) && !working.has(key)) returns.set(key, at);
105 + }
106 + lastWorkingKeys = working;
107 + },
108 + returnedAt: (thread: Pick<EnvironmentThreadShell, "environmentId" | "id">) =>
109 + returns.get(keyOf(thread)),
110 + };
111 +}