Skip to content

Commit 2c23bd1

Browse files
committed
fix(web): render persisted bash tool output in expanded turns
Claude Bash tool_result content was persisted but dropped on the wire and never copied onto the work-log entry, so expanded Command-run rows only showed the command and short detail. Project data.result through, pass it as output, and keep tool-only turns expandable.
1 parent d23b181 commit 2c23bd1

10 files changed

Lines changed: 545 additions & 23 deletions

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,58 @@ describe("buildThreadFeed", () => {
324324
expect(group.activities[0]?.getFullDetail()).toContain("repository.search");
325325
});
326326

327+
it("includes persisted Claude Bash result content in the expanded work row", () => {
328+
const turnId = TurnId.make("turn-bash");
329+
const output = "hello from bash\nsecond line";
330+
const thread = makeThread({
331+
id: ThreadId.make("thread-bash"),
332+
projectId: ProjectId.make("project-1"),
333+
title: "Bash output",
334+
latestTurn: {
335+
turnId,
336+
state: "completed",
337+
requestedAt: "2026-04-01T00:00:00.000Z",
338+
startedAt: "2026-04-01T00:00:01.000Z",
339+
completedAt: "2026-04-01T00:00:03.000Z",
340+
assistantMessageId: null,
341+
},
342+
activities: [
343+
makeActivity({
344+
id: EventId.make("bash-completed"),
345+
kind: "tool.completed",
346+
tone: "tool",
347+
summary: "Command run",
348+
createdAt: "2026-04-01T00:00:02.000Z",
349+
turnId,
350+
payload: {
351+
title: "Command run",
352+
itemType: "command_execution",
353+
detail: "Bash: printf hello",
354+
status: "completed",
355+
data: {
356+
toolName: "Bash",
357+
input: { command: "printf hello" },
358+
result: {
359+
type: "tool_result",
360+
content: output,
361+
is_error: false,
362+
},
363+
},
364+
},
365+
}),
366+
],
367+
});
368+
369+
const group = buildThreadFeed(thread)[0];
370+
expect(group).toMatchObject({ type: "activity-group" });
371+
if (!group || group.type !== "activity-group") {
372+
return;
373+
}
374+
375+
expect(group.activities[0]?.detail).toBe("printf hello");
376+
expect(group.activities[0]?.getFullDetail()).toBe(`printf hello\n\n${output}`);
377+
});
378+
327379
it("defers large tool output expansion until a work row is opened or copied", () => {
328380
let serializedToolOutputs = 0;
329381
const activities = Array.from({ length: 5_000 }, (_, index) =>

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ interface WorkLogEntry {
6868
detail?: string;
6969
command?: string;
7070
rawCommand?: string;
71+
output?: string;
7172
changedFiles?: ReadonlyArray<string>;
7273
tone: "thinking" | "tool" | "info" | "error";
7374
toolTitle?: string;
@@ -408,6 +409,10 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
408409
if (commandPreview.rawCommand) {
409410
entry.rawCommand = commandPreview.rawCommand;
410411
}
412+
const output = extractPersistedToolResult(payload);
413+
if (output && output !== entry.detail && output !== commandPreview.command) {
414+
entry.output = output;
415+
}
411416
if (changedFiles.length > 0) {
412417
entry.changedFiles = changedFiles;
413418
}
@@ -497,6 +502,7 @@ function mergeDerivedWorkLogEntries(
497502
const detail = next.detail ?? previous.detail;
498503
const command = next.command ?? previous.command;
499504
const rawCommand = next.rawCommand ?? previous.rawCommand;
505+
const output = next.output ?? previous.output;
500506
const toolTitle = next.toolTitle ?? previous.toolTitle;
501507
const itemType = next.itemType ?? previous.itemType;
502508
const requestKind = next.requestKind ?? previous.requestKind;
@@ -509,6 +515,7 @@ function mergeDerivedWorkLogEntries(
509515
...(detail ? { detail } : {}),
510516
...(command ? { command } : {}),
511517
...(rawCommand ? { rawCommand } : {}),
518+
...(output ? { output } : {}),
512519
...(changedFiles.length > 0 ? { changedFiles } : {}),
513520
...(toolTitle ? { toolTitle } : {}),
514521
...(itemType ? { itemType } : {}),
@@ -659,7 +666,7 @@ function buildWorkEntryExpandedBody(entry: WorkLogEntry): string | null {
659666
appendUniqueBlock(`MCP call\n${JSON.stringify(entry.toolData, null, 2)}`);
660667
}
661668
appendUniqueBlock(entry.rawCommand ?? entry.command);
662-
appendUniqueBlock(entry.detail);
669+
appendUniqueBlock(entry.output ?? entry.detail);
663670
if ((entry.changedFiles?.length ?? 0) > 0) {
664671
appendUniqueBlock(entry.changedFiles!.join("\n"));
665672
}
@@ -671,6 +678,7 @@ function workEntryHasExpandedBody(entry: WorkLogEntry): boolean {
671678
return (
672679
(entry.itemType === "mcp_tool_call" && entry.toolData !== undefined) ||
673680
Boolean((entry.rawCommand ?? entry.command)?.trim()) ||
681+
Boolean(entry.output?.trim()) ||
674682
Boolean(entry.detail?.trim()) ||
675683
(entry.changedFiles?.some((path) => path.trim().length > 0) ?? false)
676684
);
@@ -728,6 +736,54 @@ function asTrimmedString(value: unknown): string | null {
728736
return trimmed.length > 0 ? trimmed : null;
729737
}
730738

739+
function extractToolResultText(result: unknown): string | null {
740+
const direct = asTrimmedString(result);
741+
if (direct) {
742+
return direct;
743+
}
744+
745+
const record = asRecord(result);
746+
if (!record) {
747+
return null;
748+
}
749+
750+
const content = record.content;
751+
const contentText = asTrimmedString(content);
752+
if (contentText) {
753+
return contentText;
754+
}
755+
756+
if (!Array.isArray(content)) {
757+
return null;
758+
}
759+
760+
const chunks: string[] = [];
761+
for (const entryValue of content) {
762+
const text = asTrimmedString(entryValue) ?? asTrimmedString(asRecord(entryValue)?.text);
763+
if (text) {
764+
chunks.push(text);
765+
}
766+
}
767+
return chunks.length > 0 ? chunks.join("\n") : null;
768+
}
769+
770+
function extractPersistedToolResult(payload: Record<string, unknown> | null): string | null {
771+
const data = asRecord(payload?.data);
772+
const item = asRecord(data?.item);
773+
const candidates = [data?.result, item?.result];
774+
for (const candidate of candidates) {
775+
const text = extractToolResultText(candidate);
776+
if (!text) {
777+
continue;
778+
}
779+
const output = stripTrailingExitCode(text).output;
780+
if (output) {
781+
return output;
782+
}
783+
}
784+
return null;
785+
}
786+
731787
function trimMatchingOuterQuotes(value: string): string {
732788
const trimmed = value.trim();
733789
if (
@@ -886,11 +942,13 @@ function extractToolCommand(payload: Record<string, unknown> | null): {
886942
const itemInput = asRecord(item?.input);
887943
const itemType = asTrimmedString(payload?.itemType);
888944
const detail = asTrimmedString(payload?.detail);
945+
const dataInput = asRecord(data?.input);
889946
const candidates: unknown[] = [
890947
item?.command,
891948
itemInput?.command,
892949
itemResult?.command,
893950
data?.command,
951+
dataInput?.command,
894952
itemType === "command_execution" && detail ? stripTrailingExitCode(detail).output : null,
895953
];
896954

‎apps/server/src/orchestration/ActivityPayloadProjection.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,49 @@ describe("projectActivityPayload agent-field survival", () => {
151151
expect(JSON.stringify(projected.payload).length).toBeLessThan(500);
152152
});
153153

154+
it("keeps Claude Bash result content for the expanded command-run row", () => {
155+
const output = `hello from bash\n${"x".repeat(200)}`;
156+
const projected = projectActivityPayload(
157+
activity({
158+
itemType: "command_execution",
159+
data: {
160+
toolName: "Bash",
161+
input: { command: "printf hello && cat huge.txt" },
162+
result: {
163+
type: "tool_result",
164+
tool_use_id: "toolu_1",
165+
content: output,
166+
is_error: false,
167+
},
168+
},
169+
}),
170+
);
171+
const data = (projected.payload as Record<string, unknown>).data as Record<string, unknown>;
172+
expect(data.command).toBe("printf hello && cat huge.txt");
173+
expect(data.result).toEqual({ content: output });
174+
expect(data.toolName).toBeUndefined();
175+
});
176+
177+
it("bounds huge Claude Bash result content instead of dropping it", () => {
178+
const output = `first line\n${"y".repeat(40_000)}`;
179+
const projected = projectActivityPayload(
180+
activity({
181+
itemType: "command_execution",
182+
data: {
183+
toolName: "Bash",
184+
input: { command: "cat huge.txt" },
185+
result: { content: output, is_error: false },
186+
},
187+
}),
188+
);
189+
const data = (projected.payload as Record<string, unknown>).data as Record<string, unknown>;
190+
const result = data.result as { content: string };
191+
expect(result.content.startsWith("first line\n")).toBe(true);
192+
expect(result.content.endsWith("…")).toBe(true);
193+
expect(result.content.length).toBeLessThan(output.length);
194+
expect(result.content.length).toBeGreaterThan(30_000);
195+
});
196+
154197
it("passes task lifecycle payloads (no data field) through untouched", () => {
155198
const source = activity({
156199
taskId: "task-9",

‎apps/server/src/orchestration/ActivityPayloadProjection.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ function projectCommandData(data: Record<string, unknown>): Record<string, unkno
125125
return Object.keys(projectedItem).length > 0 ? projectedItem : undefined;
126126
}
127127

128+
/** Expanded Command-run rows render this; keep it bounded for the wire. */
129+
const MAX_PROJECTED_COMMAND_RESULT_CHARS = 32_768;
130+
128131
function summarizeToolTextOutput(value: string): string | null {
129132
const lines: string[] = [];
130133
for (const rawLine of value.split(/\r?\n/u)) {
@@ -252,6 +255,18 @@ function projectMcpToolCallData(data: Record<string, unknown>): Record<string, u
252255
return projectedData;
253256
}
254257

258+
function projectCommandResult(result: unknown): Record<string, unknown> | undefined {
259+
const text = extractMcpResultText(result);
260+
if (!text) {
261+
return undefined;
262+
}
263+
const content =
264+
text.length > MAX_PROJECTED_COMMAND_RESULT_CHARS
265+
? `${text.slice(0, MAX_PROJECTED_COMMAND_RESULT_CHARS).trimEnd()}\n…`
266+
: text;
267+
return { content };
268+
}
269+
255270
function projectRawOutput(value: unknown): Record<string, unknown> | undefined {
256271
const direct = asTrimmedString(value);
257272
if (direct) {
@@ -341,6 +356,16 @@ export function projectActivityPayload(
341356
}
342357
if ("command" in data) {
343358
projectedData.command = data.command;
359+
} else {
360+
const inputCommand = asRecord(data.input)?.command;
361+
if (inputCommand !== undefined) {
362+
projectedData.command = inputCommand;
363+
}
364+
}
365+
366+
const commandResult = projectCommandResult(data.result);
367+
if (commandResult) {
368+
projectedData.result = commandResult;
344369
}
345370

346371
const changedFiles: string[] = [];

‎apps/server/test/ActivityPayloadProjection.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,29 @@ describe("projectActivityPayload", () => {
184184
});
185185
});
186186

187+
it("projects Claude Bash result content so the work-log can render it", () => {
188+
const output = `hello from bash\n${"x".repeat(200)}`;
189+
const source = makeActivity("claude-bash", "command_execution", {
190+
toolName: "Bash",
191+
input: { command: "printf hello && cat huge.txt" },
192+
result: {
193+
type: "tool_result",
194+
tool_use_id: "toolu_1",
195+
content: output,
196+
is_error: false,
197+
},
198+
});
199+
const projected = projectActivityPayload(source);
200+
const data = (projected.payload as Record<string, unknown>).data as Record<string, unknown>;
201+
expect(data.command).toBe("printf hello && cat huge.txt");
202+
expect(data.result).toEqual({ content: output });
203+
expect(deriveWorkLogEntries([projected])).toEqual(deriveWorkLogEntries([source]));
204+
expect(deriveWorkLogEntries([projected])[0]).toMatchObject({
205+
command: "printf hello && cat huge.txt",
206+
output,
207+
});
208+
});
209+
187210
it("slims MCP tool data to the fields the expanded row renders", () => {
188211
expect(projectActivityPayload(fixtures[4]!).payload).toEqual({
189212
itemType: "mcp_tool_call",

0 commit comments

Comments
 (0)