TypeScript
fix(mobile): expand single-line tool details in work logs (#10442)
Yash Singh8c9a49afb5a4
diff --git a/apps/mobile/src/features/threads/thread-work-log.tsx b/apps/mobile/src/features/threads/thread-work-log.tsxindex e812e77ef08..c6043a27bcd 100644--- a/apps/mobile/src/features/threads/thread-work-log.tsx+++ b/apps/mobile/src/features/threads/thread-work-log.tsx@@ -730,8 +730,7 @@ const ThreadWorkLogRow = memo(function ThreadWorkLogRow(const viewedImagePath = workEntryViewedImagePath(row.workEntry);const toolPresentation = resolveWorkEntryToolPresentation(row.workEntry);const previewText = workEntryRowLabel(row.workEntry);- const displayText =- !toolPresentation && expanded && row.workEntry.command?.trim() ? "Command" : previewText;+ const displayText = workEntryRowLabel(row.workEntry, expanded);const iconIsDestructive = row.icon === "alert" || row.icon === "warning";const failed = row.status === "failure";const toolIcon = row.workEntry.toolIcon ?? row.workEntry.toolSource?.icon;@@ -747,7 +746,9 @@ const ThreadWorkLogRow = memo(function ThreadWorkLogRow(accessibilityRole={canExpand ? "button" : undefined}accessibilityLabel={failed ? `${previewText}, tool call failed` : previewText}accessibilityHint={- canExpand ? "Double tap to show full details. Long press to copy." : "Long press to copy."+ canExpand+ ? `Double tap to ${expanded ? "hide" : "show"} full details. Long press to copy.`+ : "Long press to copy."}accessibilityState={canExpand ? { expanded } : undefined}hitSlop={4}@@ -761,7 +762,7 @@ const ThreadWorkLogRow = memo(function ThreadWorkLogRow(className="rounded-md px-0.5 py-0 active:bg-subtle"><View className="min-h-8 flex-row items-center gap-1.5">- {row.live ? (+ {row.live && !expanded ? (<ShimmeringWorkContentenvironmentId={props.environmentId}icon={icon}@@ -801,7 +802,7 @@ const ThreadWorkLogRow = memo(function ThreadWorkLogRow("min-w-0 flex-1 text-sm text-foreground-muted",iconIsDestructive && "font-t3-medium text-adaptive-rose-600-400",)}- numberOfLines={1}+ numberOfLines={expanded ? undefined : 1}>{displayText}</Text>@@ -842,7 +843,7 @@ const ThreadWorkLogRow = memo(function ThreadWorkLogRow(</View></Pressable>- {fullDetail ? (+ {expanded && (fullDetail || viewedImagePath) ? (<Animated.Viewentering={WORK_LOG_DETAIL_ENTER_TRANSITION}exiting={WORK_LOG_DETAIL_EXIT_TRANSITION}diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.tsindex 68f779f0657..dde67773d94 100644--- a/apps/mobile/src/lib/threadActivity.test.ts+++ b/apps/mobile/src/lib/threadActivity.test.ts@@ -561,8 +561,8 @@ describe("buildThreadFeed", () => {const [row] = group.activities;expect(row?.workEntry.detail).toBe(command);expect(row?.getFullDetail()).toBe(`${command}\n\n${command}`);- // Opening it would only repeat the command the row already shows.- expect(row?.canExpand).toBe(false);+ expect(row?.canExpand).toBe(true);+ expect(workEntryRowLabel(row!.workEntry, true)).toBe("Command");});it.each([@@ -594,7 +594,7 @@ describe("buildThreadFeed", () => {payload: { detail: "Bash is unusable in this environment" },},label: "Bash is unusable in this environment",- canExpand: false,+ canExpand: true,},{name: "a multi-line task report",@@ -630,7 +630,7 @@ describe("buildThreadFeed", () => {label: "printf hello",canExpand: true,},- ])("only lets $name expand when the body adds something: $canExpand", (input) => {+ ])("sets expansion availability for $name: $canExpand", (input) => {const thread = makeThread({id: ThreadId.make("thread-expand-rule"),projectId: ProjectId.make("project-1"),@@ -652,6 +652,107 @@ describe("buildThreadFeed", () => {expect(row?.canExpand).toBe(input.canExpand);});+ it.each(["runtime.error", "runtime.warning"] as const)(+ "shows and copies the message of %s without a duplicate expanded body",+ (kind) => {+ const message =+ "You've hit your usage limit for GPT-5.3-Codex-Spark. Switch to another model now, or try again at 5:21 AM.";+ const thread = makeThread({+ id: ThreadId.make("runtime-message"),+ projectId: ProjectId.make("project-1"),+ title: "Runtime message",+ activities: [+ makeActivity({+ id: EventId.make("runtime-message"),+ createdAt: "2026-09-01T00:00:00.000Z",+ kind,+ tone: "error",+ summary: "Runtime error",+ payload: { message },+ }),+ ],+ });+ const [group] = buildThreadFeed(thread);+ expect(group?.type).toBe("activity-group");+ if (group?.type !== "activity-group") return;+ const row = group.activities[0]!;+ expect(row.canExpand).toBe(true);+ expect(workEntryRowLabel(row.workEntry, true)).toBe(message);+ expect(row.getFullDetail()).toBeNull();+ expect(row.getCopyText()).toBe(`Runtime error\n${message}`);+ },+ );++ it.each([+ {+ message: "fallback message",+ detail: "More specific detail",+ expected: "More specific detail",+ },+ { message: " ", expected: undefined },+ { message: { error: "not a string" }, expected: undefined },+ ])("preserves existing runtime details and ignores invalid messages: $message", (input) => {+ const thread = makeThread({+ id: ThreadId.make("runtime-detail"),+ projectId: ProjectId.make("project-1"),+ title: "Runtime detail",+ activities: [+ makeActivity({+ id: EventId.make("runtime-detail"),+ createdAt: "2026-09-01T00:00:00.000Z",+ kind: "runtime.error",+ tone: "error",+ summary: "Runtime error",+ payload: { message: input.message, detail: input.detail },+ }),+ ],+ });+ const [group] = buildThreadFeed(thread);+ expect(group?.type).toBe("activity-group");+ if (group?.type !== "activity-group") return;+ expect(group.activities[0]?.workEntry.detail).toBe(input.expected);+ expect(group.activities[0]?.canExpand).toBe(Boolean(input.expected));+ });++ it.each([+ {+ summary: "Runtime error",+ kind: "runtime.error" as const,+ detail:+ "Request failed.\nThe service returned an unexpected response.\nRetry after checking the connection.",+ },+ {+ summary: "Web search",+ kind: "tool.completed" as const,+ detail: "https://itanium-cxx-abi.github.io/cxx-abi/abi.html",+ itemType: "web_search",+ },+ ])("expands the full $summary label once, retaining its formatting and copy text", (input) => {+ const thread = makeThread({+ id: ThreadId.make("expanded-label"),+ projectId: ProjectId.make("project-1"),+ title: "Expanded label",+ activities: [+ makeActivity({+ id: EventId.make("expanded-label"),+ createdAt: "2026-09-01T00:00:00.000Z",+ kind: input.kind,+ summary: input.summary,+ payload: { detail: input.detail, itemType: input.itemType },+ }),+ ],+ });+ const [group] = buildThreadFeed(thread);+ expect(group?.type).toBe("activity-group");+ if (group?.type !== "activity-group") return;+ const row = group.activities[0]!;+ expect(row.canExpand).toBe(true);+ expect(workEntryRowLabel(row.workEntry)).toBe(input.detail.replace(/\s+/g, " "));+ expect(workEntryRowLabel(row.workEntry, true)).toBe(input.detail);+ expect(row.getFullDetail()).toBeNull();+ expect(row.getCopyText()).toBe(`${input.summary}\n${input.detail}`);+ });+it("drops a truncated Claude echo of a long command", () => {const command = `git add -A && git commit -m "${"x".repeat(200)}"`;const thread = makeThread({@@ -1059,6 +1160,11 @@ describe("buildThreadFeed", () => {},],});+ if (group?.type !== "activity-group") return;+ const row = group.activities[0]!;+ expect(row.canExpand).toBe(true);+ expect(row.getFullDetail()).toBeNull();+ expect(workEntryRowLabel(row.workEntry, true)).toBe(`${imagePath.slice(0, 177)}...`);});it("keeps MCP inputs available to expanded mobile work rows", () => {@@ -1136,7 +1242,8 @@ describe("buildThreadFeed", () => {},});expect(group.activities[0]?.getFullDetail()).toContain('"query": "work log"');- expect(group.activities[0]?.getFullDetail()).toContain("repository.search");+ expect(workEntryRowLabel(group.activities[0]!.workEntry, true)).toBe("repository.search");+ expect(group.activities[0]?.getFullDetail()).not.toContain("repository.search");});it.each([diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.tsindex 42e0db669a7..f77f54cf625 100644--- a/apps/mobile/src/lib/threadActivity.ts+++ b/apps/mobile/src/lib/threadActivity.ts@@ -525,6 +525,10 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWoif (isTaskActivity && typeof payload?.error === "string" && payload.error.trim()) {entry.detail = payload.error;}+ if (!entry.detail && (activity.kind === "runtime.error" || activity.kind === "runtime.warning")) {+ const message = asTrimmedString(payload?.message);+ if (message) entry.detail = message;+ }if (viewedImagePath) {entry.viewedImagePath = viewedImagePath;}@@ -939,9 +943,12 @@ function workEntryIcon(entry: DerivedWorkLogEntry): ThreadFeedActivity["icon"] {function buildWorkEntryExpandedBody(entry: WorkLogEntry): string | null {if (entry.agentSpawn) return agentSpawnExpandedBody(entry.agentSpawn);const blocks: string[] = [];+ const visibleLabel = workEntryRowLabel(entry, true).trim();const appendBlock = (value: string | null | undefined) => {const trimmed = value?.trim();- if (trimmed && (entry.command || !blocks.includes(trimmed))) blocks.push(trimmed);+ if (trimmed && (entry.command || (trimmed !== visibleLabel && !blocks.includes(trimmed)))) {+ blocks.push(trimmed);+ }};if (entry.itemType === "mcp_tool_call" && entry.toolData !== undefined) {@@ -957,24 +964,15 @@ function buildWorkEntryExpandedBody(entry: WorkLogEntry): string | null {}/**- * A row only opens when its body says more than its collapsed line. A row- * whose only detail is the single-line text it already shows (a runtime- * warning, a task summary, a short command) has nothing to reveal.- * Multi-line text still expands: the collapsed row truncates it to one line.+ * Even single-line details can be truncated by the available screen width.* Cheap field checks come first so large tool payloads are not serialized* for every row (see the deferred-expansion test).*/-function workEntryHasExpandedBody(entry: WorkLogEntry, collapsedText: string): boolean {+function workEntryCanExpand(entry: WorkLogEntry): boolean {if (entry.agentSpawn) return agentSpawnMembers(entry.agentSpawn).length > 0;if (entry.itemType === "mcp_tool_call" && entry.toolData !== undefined) return true;if (entry.changedFiles?.some((path) => path.trim().length > 0)) return true;- const parts = [entry.rawCommand ?? entry.command, entry.detail]- .map((value) => value?.trim())- .filter((value): value is string => Boolean(value));- if (parts.length === 0) return false;- if (parts.length > 1 && new Set(parts).size > 1) return true;- const only = parts[0]!;- return only.includes("\n") || collapseWhitespace(only) !== collapseWhitespace(collapsedText);+ return Boolean((entry.rawCommand ?? entry.command)?.trim() || entry.detail?.trim());}function collapseWhitespace(value: string): string {@@ -987,12 +985,14 @@ function stripShellWrapper(value: string): string {return (match?.[1] ?? trimmed).trim();}-/** The one-line text a collapsed work row shows. */-export function workEntryRowLabel(entry: WorkLogEntry): string {+/** Expanded rows retain detail formatting; commands stay in the separate body. */+export function workEntryRowLabel(entry: WorkLogEntry, expanded = false): string {if (entry.agentSpawn) return agentSpawnLabel(entry.agentSpawn);const presentation = resolveWorkEntryToolPresentation(entry);if (presentation) return presentation.displayName;+ if (expanded && entry.command?.trim()) return "Command";const preview = workEntryPreview(entry);+ if (expanded) return preview?.trim() || workEntryHeading(entry);const compactPreview = preview === null ? null : collapseWhitespace(stripShellWrapper(preview));return compactPreview || workEntryHeading(entry);}@@ -2227,7 +2227,7 @@ function toThreadFeedActivityEntry(turnId: entry.turnId,summary,detail,- canExpand: workEntryHasExpandedBody(entry, workEntryRowLabel(entry)),+ canExpand: workEntryCanExpand(entry),getFullDetail,getCopyText,icon: workEntryIcon(entry),