perf(mobile): defer work-log detail serialization (#4607)
This commit is contained in:
1 parent
d60f6e971f
commit
b4680cbfd0
3 files changed
+108
-31
No files matched your search
@@ -108,7 +108,8 @@ export function ThreadWorkLog(props: {
|
||||
<View className="gap-px">
|
||||
{rows.map((row) => {
|
||||
const expanded = props.expandedRows[row.id] ?? false;
|
||||
const canExpand = row.fullDetail !== null;
|
||||
const canExpand = row.canExpand;
|
||||
const fullDetail = expanded ? row.getFullDetail() : null;
|
||||
const displayText = row.detail ? `${row.summary} ${row.detail}` : row.summary;
|
||||
const iconIsDestructive = row.icon === "alert" || row.icon === "warning";
|
||||
|
||||
@@ -133,7 +134,7 @@ export function ThreadWorkLog(props: {
|
||||
props.onToggleRow(row.id);
|
||||
}
|
||||
}}
|
||||
onLongPress={() => props.onCopyRow(row.id, row.copyText)}
|
||||
onLongPress={() => props.onCopyRow(row.id, row.getCopyText())}
|
||||
style={({ pressed }) => ({
|
||||
backgroundColor: pressed ? pressedBackground : "transparent",
|
||||
})}
|
||||
@@ -204,7 +205,7 @@ export function ThreadWorkLog(props: {
|
||||
</View>
|
||||
</Pressable>
|
||||
|
||||
{expanded && row.fullDetail ? (
|
||||
{fullDetail ? (
|
||||
<View className="ml-7 border-l border-neutral-300/60 pb-1 pl-3 pt-0.5 dark:border-white/[0.12]">
|
||||
<ScrollView
|
||||
nestedScrollEnabled
|
||||
@@ -217,7 +218,7 @@ export function ThreadWorkLog(props: {
|
||||
selectable
|
||||
className="font-mono text-2xs leading-normal text-foreground-muted"
|
||||
>
|
||||
{row.fullDetail}
|
||||
{fullDetail}
|
||||
</Text>
|
||||
</ScrollView>
|
||||
</View>
|
||||
|
||||
@@ -161,20 +161,22 @@ describe("buildThreadFeed", () => {
|
||||
return;
|
||||
}
|
||||
|
||||
expect(group.activities).toEqual([
|
||||
{
|
||||
id: "tool-completed",
|
||||
createdAt: "2026-04-01T00:00:02.000Z",
|
||||
turnId: "turn-1",
|
||||
summary: "Run tests",
|
||||
detail: "bun run test",
|
||||
fullDetail: "/bin/zsh -lc 'bun run test'",
|
||||
copyText: "Run tests\nbun run test\n/bin/zsh -lc 'bun run test'",
|
||||
icon: "command",
|
||||
toolLike: true,
|
||||
status: "success",
|
||||
},
|
||||
]);
|
||||
expect(group.activities).toHaveLength(1);
|
||||
expect(group.activities[0]).toMatchObject({
|
||||
id: "tool-completed",
|
||||
createdAt: "2026-04-01T00:00:02.000Z",
|
||||
turnId: "turn-1",
|
||||
summary: "Run tests",
|
||||
detail: "bun run test",
|
||||
canExpand: true,
|
||||
icon: "command",
|
||||
toolLike: true,
|
||||
status: "success",
|
||||
});
|
||||
expect(group.activities[0]?.getFullDetail()).toBe("/bin/zsh -lc 'bun run test'");
|
||||
expect(group.activities[0]?.getCopyText()).toBe(
|
||||
"Run tests\nbun run test\n/bin/zsh -lc 'bun run test'",
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps MCP inputs available to expanded mobile work rows", () => {
|
||||
@@ -223,8 +225,55 @@ describe("buildThreadFeed", () => {
|
||||
}
|
||||
|
||||
expect(group.activities[0]?.icon).toBe("wrench");
|
||||
expect(group.activities[0]?.fullDetail).toContain('"query": "work log"');
|
||||
expect(group.activities[0]?.fullDetail).toContain("repository.search");
|
||||
expect(group.activities[0]?.getFullDetail()).toContain('"query": "work log"');
|
||||
expect(group.activities[0]?.getFullDetail()).toContain("repository.search");
|
||||
});
|
||||
|
||||
it("defers large tool output expansion until a work row is opened or copied", () => {
|
||||
let serializedToolOutputs = 0;
|
||||
const activities = Array.from({ length: 5_000 }, (_, index) =>
|
||||
makeActivity({
|
||||
id: EventId.make(`large-tool-${index}`),
|
||||
kind: "tool.completed",
|
||||
tone: "tool",
|
||||
summary: `Tool ${index}`,
|
||||
createdAt: new Date(Date.UTC(2026, 3, 1, 0, 0, index)).toISOString(),
|
||||
payload: {
|
||||
title: `Tool ${index}`,
|
||||
itemType: "mcp_tool_call",
|
||||
status: "completed",
|
||||
data: {
|
||||
item: {
|
||||
toJSON: () => {
|
||||
serializedToolOutputs += 1;
|
||||
return { output: "x".repeat(32_768) };
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("thread-large-tools"),
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "Large tools",
|
||||
activities,
|
||||
});
|
||||
|
||||
const feed = buildThreadFeed(thread);
|
||||
expect(serializedToolOutputs).toBe(0);
|
||||
|
||||
const group = feed[0];
|
||||
expect(group).toMatchObject({ type: "activity-group" });
|
||||
if (!group || group.type !== "activity-group") {
|
||||
return;
|
||||
}
|
||||
|
||||
expect(group.activities).toHaveLength(5_000);
|
||||
expect(group.activities[0]?.getFullDetail()).toContain('"output"');
|
||||
expect(serializedToolOutputs).toBe(1);
|
||||
expect(group.activities[0]?.getCopyText()).toContain('"output"');
|
||||
expect(serializedToolOutputs).toBe(1);
|
||||
});
|
||||
|
||||
it("folds settled turn work while leaving the terminal answer visible", () => {
|
||||
@@ -439,8 +488,9 @@ describe("buildThreadFeed", () => {
|
||||
turnId: null,
|
||||
summary: `Tool ${id}`,
|
||||
detail: null,
|
||||
fullDetail: null,
|
||||
copyText: id,
|
||||
canExpand: false,
|
||||
getFullDetail: () => null,
|
||||
getCopyText: () => id,
|
||||
icon: "command",
|
||||
toolLike: true,
|
||||
status,
|
||||
|
||||
@@ -36,8 +36,9 @@ export interface ThreadFeedActivity {
|
||||
readonly turnId: TurnId | null;
|
||||
readonly summary: string;
|
||||
readonly detail: string | null;
|
||||
readonly fullDetail: string | null;
|
||||
readonly copyText: string;
|
||||
readonly canExpand: boolean;
|
||||
readonly getFullDetail: () => string | null;
|
||||
readonly getCopyText: () => string;
|
||||
readonly icon:
|
||||
| "agent"
|
||||
| "alert"
|
||||
@@ -554,6 +555,27 @@ 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)
|
||||
);
|
||||
}
|
||||
|
||||
function memoizeValue<T>(build: () => T): () => T {
|
||||
let value: T;
|
||||
let initialized = false;
|
||||
return () => {
|
||||
if (!initialized) {
|
||||
value = build();
|
||||
initialized = true;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
}
|
||||
|
||||
function workEntryPreview(
|
||||
workEntry: Pick<WorkLogEntry, "detail" | "command" | "changedFiles">,
|
||||
): string | null {
|
||||
@@ -1353,7 +1375,14 @@ export function buildThreadFeed(
|
||||
.map<RawThreadFeedEntry>((entry) => {
|
||||
const summary = workEntryHeading(entry);
|
||||
const detail = workEntryPreview(entry);
|
||||
const fullDetail = buildWorkEntryExpandedBody(entry);
|
||||
const getFullDetail = memoizeValue(() => buildWorkEntryExpandedBody(entry));
|
||||
const getCopyText = memoizeValue(() =>
|
||||
[summary, detail, getFullDetail()]
|
||||
.filter((value, index, values): value is string => {
|
||||
return Boolean(value) && values.indexOf(value) === index;
|
||||
})
|
||||
.join("\n"),
|
||||
);
|
||||
return {
|
||||
type: "activity",
|
||||
id: entry.id,
|
||||
@@ -1365,13 +1394,10 @@ export function buildThreadFeed(
|
||||
turnId: entry.turnId,
|
||||
summary,
|
||||
detail,
|
||||
fullDetail,
|
||||
canExpand: workEntryHasExpandedBody(entry),
|
||||
getFullDetail,
|
||||
getCopyText,
|
||||
icon: workEntryIcon(entry),
|
||||
copyText: [summary, detail, fullDetail]
|
||||
.filter((value, index, values): value is string => {
|
||||
return Boolean(value) && values.indexOf(value) === index;
|
||||
})
|
||||
.join("\n"),
|
||||
toolLike: workLogEntryIsToolLike(entry),
|
||||
status: workEntryStatus(entry),
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user