TypeScript
fix(mobile): avoid nested dropdowns for single tools (#15674)
Wout Stiensd015325b7637
diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsxindex 1743560146b..762685e2f83 100644--- a/apps/mobile/src/features/threads/ThreadFeed.tsx+++ b/apps/mobile/src/features/threads/ThreadFeed.tsx@@ -987,7 +987,7 @@ function renderFeedEntry(readonly failedRunIds: ReadonlySet<RunId>;readonly onCopyWorkRow: (rowId: string, value: string) => void;readonly onToggleWorkGroup: (groupId: string, anchorKey?: string) => void;- readonly onToggleWorkRow: (rowId: string, anchorKey?: string) => void;+ readonly onToggleWorkRow: (rowId: string, anchorKey?: string, groupId?: string) => void;readonly onToggleTurnFold: (runId: RunId) => void;readonly onPressPreview: (source: FilePreviewSource) => void;readonly onPressVideo: (attachment: ChatFileAttachment, sourceIdentifier: string) => void;@@ -2344,16 +2344,22 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {[suspendEndScrollMaintenanceForDisclosure],);+ // A lone call's row stands in for its group header, so both disclosures move+ // together. Details the reader opened stay open when a second call turns the+ // row into a group.const onToggleWorkRow = useCallback(- (rowId: string, anchorKey?: string) => {+ (rowId: string, anchorKey?: string, groupId?: string) => {suspendEndScrollMaintenanceForDisclosure(anchorKey ?? null);- setInteractionState((current) => ({- ...current,- expandedWorkRows: {- ...current.expandedWorkRows,- [rowId]: !(current.expandedWorkRows[rowId] ?? false),- },- }));+ setInteractionState((current) => {+ const expanded = !(current.expandedWorkRows[rowId] ?? false);+ return {+ ...current,+ expandedWorkRows: { ...current.expandedWorkRows, [rowId]: expanded },+ ...(groupId === undefined+ ? {}+ : { expandedWorkGroups: { ...current.expandedWorkGroups, [groupId]: expanded } }),+ };+ });},[suspendEndScrollMaintenanceForDisclosure],);diff --git a/apps/mobile/src/features/threads/thread-work-log.tsx b/apps/mobile/src/features/threads/thread-work-log.tsxindex d875a39335b..925928a342a 100644--- a/apps/mobile/src/features/threads/thread-work-log.tsx+++ b/apps/mobile/src/features/threads/thread-work-log.tsx@@ -485,7 +485,8 @@ interface ThreadWorkLogProps {readonly edgeFadeColor: string;readonly themeAppearance: "light" | "dark";readonly onCopyRow: (rowId: string, value: string) => void;- readonly onToggleRow: (rowId: string, anchorKey: string) => void;+ /** `groupId` is the group a lone call stands in for; it opens and closes with the row. */+ readonly onToggleRow: (rowId: string, anchorKey: string, groupId?: string) => void;readonly renderImage: MarkdownImageRenderer;readonly renderReasoning: (text: string) => ReactNode;readonly onPressPreview: (source: FilePreviewSource) => void;@@ -1030,12 +1031,12 @@ const ThreadWorkLogRow = memo(function ThreadWorkLogRow(</Text>);const toolPresentation = resolveWorkEntryToolPresentation(row.workEntry);- const previewText = workEntryRowLabel(row.workEntry);+ const previewText = row.groupStandIn?.label ?? workEntryRowLabel(row.workEntry);const answerPreview = row.workEntry.questionAnswer? getQuestionAnswerPreview(row.workEntry.questionAnswer): null;const accessiblePreview = [previewText, answerPreview].filter(Boolean).join(": ");- const displayText = workEntryRowLabel(row.workEntry, expanded);+ const displayText = row.groupStandIn?.label ?? workEntryRowLabel(row.workEntry, expanded);const isSystemNotice = row.projectedItem.item.type === "system_notice";const isUsageLimit =row.projectedItem.item.type === "error" &&@@ -1080,7 +1081,7 @@ const ThreadWorkLogRow = memo(function ThreadWorkLogRow(}if (canExpand) {void Haptics.selectionAsync();- props.onToggleRow(row.id, props.anchorKey);+ props.onToggleRow(row.id, props.anchorKey, row.groupStandIn?.groupId);}}}onLongPress={() => props.onCopyRow(row.id, row.getCopyText())}diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.tsindex 6a31998b7a5..fbaecd0b031 100644--- a/apps/mobile/src/lib/threadActivity.test.ts+++ b/apps/mobile/src/lib/threadActivity.test.ts@@ -887,7 +887,7 @@ describe("buildThreadFeed", () => {"message","message","run-fold",- "work-toggle",+ "activity-group","message","message",]);@@ -1080,7 +1080,7 @@ describe("buildThreadFeed", () => {expect(expanded.map((entry) => entry.type)).toEqual(["message","run-fold",- "work-toggle",+ "activity-group","message",]);});@@ -1103,11 +1103,8 @@ describe("buildThreadFeed", () => {);expect(presented.some((entry) => entry.type === "run-fold")).toBe(false);- expect(presented.find((entry) => entry.type === "work-toggle")).toMatchObject({- summary: "vp check",- hiddenCount: 1,- hasFailure: true,- live: false,+ expect(presented.find((entry) => entry.type === "activity-group")).toMatchObject({+ activities: [{ status: "failure", live: false, groupStandIn: { label: "vp check" } }],});});@@ -1169,7 +1166,7 @@ describe("buildThreadFeed", () => {).toEqual(["user:launch","fold:Worked for 8.0s",- "work-toggle",+ "activity-group","assistant:launch-answer","user:resume","fold:Worked for 8.0s",@@ -1192,7 +1189,7 @@ describe("buildThreadFeed", () => {"fold:Worked for 8.0s","assistant:launch-answer","user:resume",- "work-toggle",+ "activity-group",]);});@@ -1274,10 +1271,9 @@ describe("buildThreadFeed", () => {startedAt,true,);- expect(presented.find((entry) => entry.type === "work-toggle")).toMatchObject({- summary: "Running vp",- live: true,- shimmer: true,+ expect(presented.find((entry) => entry.type === "activity-group")).toMatchObject({+ id: "live-activity-row",+ activities: [{ live: true, groupStandIn: { label: "Running vp" } }],});expect(presented.some((entry) => entry.type === "thinking")).toBe(false);});@@ -1412,6 +1408,112 @@ describe("buildThreadFeed", () => {});});+ describe("a lone call", () => {+ const wait = (overrides: Partial<OrchestrationV2TurnItem> = {}) =>+ ({+ ...base("wait", "2026-06-20T00:00:02.000Z", 1),+ type: "dynamic_tool",+ toolName: "t3-code.t3_thread_wait",+ input: { threadId: "thread-child", timeoutMs: 50_000 },+ output: { threadId: "thread-child", status: "timeout" },+ ...overrides,+ }) as OrchestrationV2TurnItem;+ const read = (overrides: Partial<OrchestrationV2TurnItem> = {}) =>+ ({+ ...base("read", "2026-06-20T00:00:03.000Z", 2),+ type: "dynamic_tool",+ toolName: "t3-code.t3_thread_read",+ input: { threadId: "thread-child" },+ output: { messages: [] },+ ...overrides,+ }) as OrchestrationV2TurnItem;+ const running = { status: "running", completedAt: null, output: null } as const;+ const startedAt = "2026-06-20T00:00:01.000Z";+ const liveRows = (items: ReadonlyArray<OrchestrationV2TurnItem>, groupIds: string[] = []) =>+ deriveThreadFeedPresentation(+ buildThreadFeed(items.map((item, position) => projected(item, position))),+ { runId, status: "running", startedAt, completedAt: null },+ new Set(),+ new Set(groupIds),+ startedAt,+ );+ const standIn = (rows: ReadonlyArray<ThreadFeedEntry>) => {+ const row = rows.find((entry) => entry.type === "activity-group");+ if (row?.type !== "activity-group") throw new Error("Expected the call's own row");+ return row.activities[0]?.groupStandIn;+ };++ it("is its own row, with no group header to open first", () => {+ // The second call never finished, so only one call is visible.+ for (const items of [[wait()], [wait(), read(running)]]) {+ const feed = buildThreadFeed(+ [userMessage(), ...items, assistantMessage("2026-06-20T00:00:04.000Z")].map(+ (item, position) => projected(item, position),+ ),+ );+ const rows = deriveThreadFeedPresentation(feed, null, new Set([runId]));+ expect(rows.map((entry) => entry.type)).toEqual([+ "message",+ "run-fold",+ "activity-group",+ "message",+ ]);+ expect(rows[2]).toMatchObject({+ activities: [{ canExpand: true, groupStandIn: { label: "Waited for a T3 thread" } }],+ });+ expect(rows[2]).not.toMatchObject({ activities: [{ groupedToolDetail: true }] });+ // The group's own disclosure adds nothing while the call is alone.+ expect(+ deriveThreadFeedPresentation(+ feed,+ null,+ new Set([runId]),+ new Set([standIn(rows)!.groupId]),+ ).map((entry) => entry.id),+ ).toEqual(rows.map((entry) => entry.id));+ }+ });++ it("offers no disclosure when it has nothing to show", () => {+ const rows = deriveThreadFeedPresentation(+ buildThreadFeed([projected(wait({ toolName: "example", input: {}, output: null }), 0)]),+ null,+ new Set([runId]),+ );+ expect(rows.map((entry) => entry.type)).toEqual(["run-fold", "activity-group"]);+ expect(rows[1]).toMatchObject({ activities: [{ canExpand: false }] });+ });++ it("holds the live slot until a second call makes it a group", () => {+ for (const item of [wait(running), wait()]) {+ const rows = liveRows([item]);+ expect(rows.map((entry) => entry.type)).toEqual(["activity-group"]);+ expect(rows[0]).toMatchObject({+ id: "live-activity-row",+ activities: [{ live: true, groupStandIn: { label: "Waiting for a T3 thread" } }],+ });+ }++ const groupId = standIn(liveRows([wait()]))!.groupId;+ const grouped = liveRows([wait(), read(running)], [groupId]);+ expect(grouped.map((entry) => entry.type)).toEqual(["work-toggle", "activity-group"]);+ expect(grouped[0]).toMatchObject({+ id: "live-activity-row",+ groupId,+ hiddenCount: 2,+ expanded: true,+ summary: "Reading a T3 thread",+ });+ expect(grouped[1]).toMatchObject({+ activities: [+ { groupedToolDetail: true, live: false },+ { groupedToolDetail: true, live: true },+ ],+ });+ expect(standIn(grouped)).toBeUndefined();+ });+ });+it("retains Claude Read image previews without tool output", () => {const item = {...base("image-read", "2026-06-20T00:00:04.000Z", 3),@@ -1818,11 +1920,11 @@ describe("retained v2 feed presentation", () => {});it.each([- ["failed", "Failed to click in the preview browser", true],- ["cancelled", "Stopped clicking in the preview browser", false],+ ["failed", "Failed to click in the preview browser", "failure"],+ ["cancelled", "Stopped clicking in the preview browser", "neutral"],] as const)("keeps %s calls terminal while the parent run remains live",- (status, summary, hasFailure) => {+ (status, label, activityStatus) => {const feed = buildThreadFeed([projected({@@ -1843,7 +1945,11 @@ describe("retained v2 feed presentation", () => {new Set(),"2026-06-20T00:00:01.000Z",);- expect(rows[0]).toMatchObject({ type: "work-toggle", summary, hasFailure, shimmer: false });+ expect(rows[0]).toMatchObject({+ type: "activity-group",+ activities: [{ status: activityStatus, live: false, groupStandIn: { label } }],+ });+ expect(rows.at(-1)?.type).toBe("thinking");},);diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.tsindex 1b811bb8171..8b7ac4aa469 100644--- a/apps/mobile/src/lib/threadActivity.ts+++ b/apps/mobile/src/lib/threadActivity.ts@@ -119,6 +119,11 @@ export interface ThreadFeedActivity {readonly workEntry: WorkLogPresentationEntry;readonly groupedToolDetail?: boolean;readonly live?: boolean;+ /**+ * Set on a lone call shown in place of its group header. Carries the header's+ * label and the group that takes over once a second call joins it.+ */+ readonly groupStandIn?: { readonly groupId: string; readonly label: string };readonly projectedItem: OrchestrationV2ProjectedTurnItem;}@@ -1340,7 +1345,7 @@ export function deriveThreadFeedPresentation(activeWorkStartedAt !== null &&!result.some((row) =>- (row.type === "work-toggle" && row.shimmer) ||+ row.id === LIVE_ACTIVITY_ROW_ID ||(row.type === "activity-group" &&isContextCompactionActivityGroup(row) &&row.runId === activeRunId &&@@ -1535,6 +1540,23 @@ function appendToolGroupRows(: singleActivity !== null && !singleActivity.toolLike? singleActivity.workEntry.label: groupSummary.summary;+ const id = shimmer ? LIVE_ACTIVITY_ROW_ID : `${live ? "work-live" : "work-toggle"}:${groupId}`;+ // A lone call needs no header. Its own row takes the header's place, label+ // and identity, and discloses its details directly. A lone thought keeps the+ // header, whose expansion already shows the text itself.+ if (singleActivity !== null && singleActivity.workEntry.itemType !== "reasoning") {+ result.push({+ type: "activity-group",+ id,+ createdAt: singleActivity.createdAt,+ runId: singleActivity.runId,+ activities: [{ ...singleActivity, live: shimmer, groupStandIn: { groupId, label: summary } }],+ // Like the header, the row has no trailing margin, so the Thinking+ // fallback and a growing group swap in without shifting the feed.+ continuesWorkLog: true,+ });+ return;+ }const primarySourceActivity = activities.find((activity) => activity.workEntry.toolSource !== undefined,);@@ -1558,14 +1580,10 @@ function appendToolGroupRows(.toolIcon;const summaryToolIcon = live? resolveWorkEntryToolPresentation(latestActivity.workEntry)?.icon- : singleActivity !== null &&- singleActivity.toolLike &&- toolGroupAction(singleActivity.workEntry) !== "edit"- ? resolveWorkEntryToolPresentation(singleActivity.workEntry, "completed")?.icon- : undefined;+ : undefined;result.push({type: "work-toggle",- id: shimmer ? LIVE_ACTIVITY_ROW_ID : `${live ? "work-live" : "work-toggle"}:${groupId}`,+ id,createdAt: sourceGroup.createdAt,runId: sourceGroup.runId,groupId,