TypeScript
fix(mobile): only make work rows expandable when the body adds something (#10210)
Julius Marminge7eda989d38a3
diff --git a/apps/mobile/src/features/threads/thread-work-log.tsx b/apps/mobile/src/features/threads/thread-work-log.tsxindex 57d9a5d91fe..0b22b35cfce 100644--- a/apps/mobile/src/features/threads/thread-work-log.tsx+++ b/apps/mobile/src/features/threads/thread-work-log.tsx@@ -34,7 +34,7 @@ import { AppText as Text } from "../../components/AppText";import { T3Wordmark } from "../../components/T3Wordmark";import { cn } from "../../lib/cn";import { THREAD_WORK_ROW_MIN_HEIGHT, type deriveThreadWorkLogSizing } from "../../lib/layout";-import type { ThreadFeedActivity } from "../../lib/threadActivity";+import { type ThreadFeedActivity, workEntryRowLabel } from "../../lib/threadActivity";import {resolveThreadWorkGroupInitialScroll,shouldFollowThreadWorkGroupAppend,@@ -307,21 +307,6 @@ export function ShimmeringWorkContent(props: {);}-function stripShellWrapper(value: string): string {- const trimmed = value.trim();- const match = trimmed.match(/^\/bin\/zsh -lc ['"]?([\s\S]*?)['"]?$/);- return (match?.[1] ?? trimmed).trim();-}--function compactActivityDetail(detail: string | null): string | null {- if (!detail) {- return null;- }-- const cleaned = stripShellWrapper(detail).replace(/\s+/g, " ").trim();- return cleaned.length > 0 ? cleaned : null;-}-function workRowSymbolName(icon: ThreadFeedActivity["icon"]): AppSymbolName {switch (icon) {case "agent":@@ -697,8 +682,7 @@ const ThreadWorkLogRow = memo(function ThreadWorkLogRow(const fullDetail = expanded ? row.getFullDetail() : null;const viewedImagePath = workEntryViewedImagePath(row.workEntry);const toolPresentation = resolveWorkEntryToolPresentation(row.workEntry);- const previewText =- toolPresentation?.displayName ?? compactActivityDetail(row.detail) ?? row.summary;+ const previewText = workEntryRowLabel(row.workEntry);const displayText =!toolPresentation && expanded && row.workEntry.command?.trim() ? "Command" : previewText;const iconIsDestructive = row.icon === "alert" || row.icon === "warning";diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.tsindex 8ab726226bd..c263a9f2fe9 100644--- a/apps/mobile/src/lib/threadActivity.test.ts+++ b/apps/mobile/src/lib/threadActivity.test.ts@@ -21,6 +21,7 @@ import {isPendingUserInputOptionSelected,setPendingUserInputCustomAnswer,togglePendingUserInputOptionSelection,+ workEntryRowLabel,type ThreadFeedActivity,type ThreadFeedEntry,} from "./threadActivity";@@ -702,6 +703,95 @@ 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);+ });++ it.each([+ {+ name: "a task summary that is its own detail",+ activity: {+ kind: "task.completed" as const,+ tone: "info" as const,+ summary: "Task completed",+ payload: {+ taskId: "bh2p996o4",+ status: "completed",+ title: "Check CI on the new head",+ summary: "Check CI on the new head",+ detail: "Check CI on the new head",+ agentKind: "background",+ taskType: "local_bash",+ },+ },+ label: "Check CI on the new head",+ canExpand: false,+ },+ {+ name: "a runtime warning with only its message",+ activity: {+ kind: "runtime.warning" as const,+ tone: "info" as const,+ summary: "Bash is unusable in this environment",+ payload: { detail: "Bash is unusable in this environment" },+ },+ label: "Bash is unusable in this environment",+ canExpand: false,+ },+ {+ name: "a multi-line task report",+ activity: {+ kind: "task.completed" as const,+ tone: "info" as const,+ summary: "Task completed",+ payload: {+ taskId: "ae3f85a",+ status: "completed",+ title: "Audit the PR",+ detail: "**Tooling note:** Bash is unusable.\n\n# Audit\n\nNo blockers.",+ agentKind: "agent",+ taskType: "local_agent",+ },+ },+ label: "**Tooling note:** Bash is unusable. # Audit No blockers.",+ canExpand: true,+ },+ {+ name: "a command whose output differs from the command",+ activity: {+ kind: "tool.completed" as const,+ tone: "tool" as const,+ summary: "Command run",+ payload: {+ itemType: "command_execution",+ title: "Command run",+ detail: "Bash: printf hello",+ data: { toolName: "Bash", command: "printf hello", rawOutput: { content: "hello" } },+ },+ },+ label: "printf hello",+ canExpand: true,+ },+ ])("only lets $name expand when the body adds something: $canExpand", (input) => {+ const thread = makeThread({+ id: ThreadId.make("thread-expand-rule"),+ projectId: ProjectId.make("project-1"),+ title: "Expand rule",+ activities: [+ makeActivity({+ id: EventId.make("expand-rule"),+ createdAt: "2026-09-01T00:00:00.000Z",+ ...input.activity,+ }),+ ],+ });++ const [group] = buildThreadFeed(thread);+ expect(group?.type).toBe("activity-group");+ if (group?.type !== "activity-group") return;+ const [row] = group.activities;+ expect(workEntryRowLabel(row!.workEntry)).toBe(input.label);+ expect(row?.canExpand).toBe(input.canExpand);});it("drops a truncated Claude echo of a long command", () => {diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.tsindex 8cb657f858f..fa01142d046 100644--- a/apps/mobile/src/lib/threadActivity.ts+++ b/apps/mobile/src/lib/threadActivity.ts@@ -878,13 +878,43 @@ function buildWorkEntryExpandedBody(entry: WorkLogEntry): string | null {return blocks.length > 0 ? blocks.join("\n\n") : null;}-function workEntryHasExpandedBody(entry: WorkLogEntry): boolean {- return (- (entry.itemType === "mcp_tool_call" && entry.toolData !== undefined) ||- Boolean((entry.rawCommand ?? entry.command)?.trim()) ||- Boolean(entry.detail?.trim()) ||- (entry.changedFiles?.some((path) => path.trim().length > 0) ?? false)- );+/**+ * 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.+ * 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 {+ 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);+}++function collapseWhitespace(value: string): string {+ return value.replace(/\s+/g, " ").trim();+}++function stripShellWrapper(value: string): string {+ const trimmed = value.trim();+ const match = trimmed.match(/^\/bin\/zsh -lc ['"]?([\s\S]*?)['"]?$/);+ return (match?.[1] ?? trimmed).trim();+}++/** The one-line text a collapsed work row shows. */+export function workEntryRowLabel(entry: WorkLogEntry): string {+ const presentation = resolveWorkEntryToolPresentation(entry);+ if (presentation) return presentation.displayName;+ const preview = workEntryPreview(entry);+ const compactPreview = preview === null ? null : collapseWhitespace(stripShellWrapper(preview));+ return compactPreview || workEntryHeading(entry);}function memoizeValue<T>(build: () => T): () => T {@@ -2098,7 +2128,7 @@ function toThreadFeedActivityEntry(turnId: entry.turnId,summary,detail,- canExpand: workEntryHasExpandedBody(entry),+ canExpand: workEntryHasExpandedBody(entry, workEntryRowLabel(entry)),getFullDetail,getCopyText,icon: workEntryIcon(entry),