Skip to content

Commit ddb2bce

Browse files
committed
fix(web): keep bash output raw and scoped to command tools
Do not scan persisted stdout for failure phrases, skip MCP result duplication, and only project large result bodies for command/bash tools. Keep copied output raw, including a trailing exit-code line, and stop Enter/Space from collapsing the expanded row.
1 parent 2c23bd1 commit ddb2bce

9 files changed

Lines changed: 271 additions & 30 deletions

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

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,105 @@ describe("buildThreadFeed", () => {
376376
expect(group.activities[0]?.getFullDetail()).toBe(`printf hello\n\n${output}`);
377377
});
378378

379+
it("does not duplicate MCP summarized result as a separate output block", () => {
380+
const turnId = TurnId.make("turn-mcp-result");
381+
const item = {
382+
server: "repository",
383+
tool: "search",
384+
arguments: { query: "work log" },
385+
result: { content: "first line of output" },
386+
};
387+
const thread = makeThread({
388+
id: ThreadId.make("thread-mcp-result"),
389+
projectId: ProjectId.make("project-1"),
390+
title: "MCP result",
391+
latestTurn: {
392+
turnId,
393+
state: "completed",
394+
requestedAt: "2026-04-01T00:00:00.000Z",
395+
startedAt: "2026-04-01T00:00:01.000Z",
396+
completedAt: "2026-04-01T00:00:03.000Z",
397+
assistantMessageId: null,
398+
},
399+
activities: [
400+
makeActivity({
401+
id: EventId.make("mcp-result-completed"),
402+
kind: "tool.completed",
403+
tone: "tool",
404+
summary: "Call repository tool",
405+
createdAt: "2026-04-01T00:00:02.000Z",
406+
turnId,
407+
payload: {
408+
title: "Call repository tool",
409+
itemType: "mcp_tool_call",
410+
detail: "repository.search",
411+
status: "completed",
412+
data: { item },
413+
},
414+
}),
415+
],
416+
});
417+
418+
const group = buildThreadFeed(thread)[0];
419+
expect(group).toMatchObject({ type: "activity-group" });
420+
if (!group || group.type !== "activity-group") {
421+
return;
422+
}
423+
424+
expect(group.activities[0]?.getFullDetail()).toBe(
425+
`MCP call\n${JSON.stringify(item, null, 2)}\n\nrepository.search`,
426+
);
427+
expect(group.activities[0]?.status).toBe("success");
428+
});
429+
430+
it("does not mark completed commands failed from stdout phrases", () => {
431+
const turnId = TurnId.make("turn-stdout-phrases");
432+
const output = "this tutorial mentions command not found, ENOENT, and exit code 1";
433+
const thread = makeThread({
434+
id: ThreadId.make("thread-stdout-phrases"),
435+
projectId: ProjectId.make("project-1"),
436+
title: "Stdout phrases",
437+
latestTurn: {
438+
turnId,
439+
state: "completed",
440+
requestedAt: "2026-04-01T00:00:00.000Z",
441+
startedAt: "2026-04-01T00:00:01.000Z",
442+
completedAt: "2026-04-01T00:00:03.000Z",
443+
assistantMessageId: null,
444+
},
445+
activities: [
446+
makeActivity({
447+
id: EventId.make("bash-stdout-phrases"),
448+
kind: "tool.completed",
449+
tone: "tool",
450+
summary: "Command run",
451+
createdAt: "2026-04-01T00:00:02.000Z",
452+
turnId,
453+
payload: {
454+
title: "Command run",
455+
itemType: "command_execution",
456+
detail: "cat notes.txt",
457+
status: "completed",
458+
data: {
459+
toolName: "Bash",
460+
input: { command: "cat notes.txt" },
461+
result: { content: output, is_error: false },
462+
},
463+
},
464+
}),
465+
],
466+
});
467+
468+
const group = buildThreadFeed(thread)[0];
469+
expect(group).toMatchObject({ type: "activity-group" });
470+
if (!group || group.type !== "activity-group") {
471+
return;
472+
}
473+
474+
expect(group.activities[0]?.status).toBe("success");
475+
expect(group.activities[0]?.getFullDetail()).toBe(`cat notes.txt\n\n${output}`);
476+
});
477+
379478
it("defers large tool output expansion until a work row is opened or copied", () => {
380479
let serializedToolOutputs = 0;
381480
const activities = Array.from({ length: 5_000 }, (_, index) =>

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
409409
if (commandPreview.rawCommand) {
410410
entry.rawCommand = commandPreview.rawCommand;
411411
}
412-
const output = extractPersistedToolResult(payload);
412+
const output = itemType === "mcp_tool_call" ? null : extractPersistedToolResult(payload);
413413
if (output && output !== entry.detail && output !== commandPreview.command) {
414414
entry.output = output;
415415
}
@@ -736,8 +736,12 @@ function asTrimmedString(value: unknown): string | null {
736736
return trimmed.length > 0 ? trimmed : null;
737737
}
738738

739+
function asPersistedResultText(value: unknown): string | null {
740+
return typeof value === "string" && value.length > 0 ? value : null;
741+
}
742+
739743
function extractToolResultText(result: unknown): string | null {
740-
const direct = asTrimmedString(result);
744+
const direct = asPersistedResultText(result);
741745
if (direct) {
742746
return direct;
743747
}
@@ -748,7 +752,7 @@ function extractToolResultText(result: unknown): string | null {
748752
}
749753

750754
const content = record.content;
751-
const contentText = asTrimmedString(content);
755+
const contentText = asPersistedResultText(content);
752756
if (contentText) {
753757
return contentText;
754758
}
@@ -759,7 +763,8 @@ function extractToolResultText(result: unknown): string | null {
759763

760764
const chunks: string[] = [];
761765
for (const entryValue of content) {
762-
const text = asTrimmedString(entryValue) ?? asTrimmedString(asRecord(entryValue)?.text);
766+
const text =
767+
asPersistedResultText(entryValue) ?? asPersistedResultText(asRecord(entryValue)?.text);
763768
if (text) {
764769
chunks.push(text);
765770
}
@@ -773,12 +778,8 @@ function extractPersistedToolResult(payload: Record<string, unknown> | null): st
773778
const candidates = [data?.result, item?.result];
774779
for (const candidate of candidates) {
775780
const text = extractToolResultText(candidate);
776-
if (!text) {
777-
continue;
778-
}
779-
const output = stripTrailingExitCode(text).output;
780-
if (output) {
781-
return output;
781+
if (text && text.trim().length > 0) {
782+
return text;
782783
}
783784
}
784785
return null;

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,42 @@ describe("projectActivityPayload agent-field survival", () => {
174174
expect(data.toolName).toBeUndefined();
175175
});
176176

177+
it("does not attach result bodies for Read/Grep dynamic tools", () => {
178+
const projected = projectActivityPayload(
179+
activity({
180+
itemType: "dynamic_tool_call",
181+
data: {
182+
toolName: "Read",
183+
input: { file_path: "README.md" },
184+
result: {
185+
type: "tool_result",
186+
content: `file body\n${"x".repeat(10_000)}`,
187+
is_error: false,
188+
},
189+
},
190+
}),
191+
);
192+
const data = (projected.payload as Record<string, unknown>).data as Record<string, unknown>;
193+
expect(data.result).toBeUndefined();
194+
expect(data.toolName).toBeUndefined();
195+
});
196+
197+
it("still attaches Bash-like dynamic tool result content", () => {
198+
const output = "hello from bash";
199+
const projected = projectActivityPayload(
200+
activity({
201+
itemType: "dynamic_tool_call",
202+
data: {
203+
toolName: "Bash",
204+
input: { command: "printf hello" },
205+
result: { content: output, is_error: false },
206+
},
207+
}),
208+
);
209+
const data = (projected.payload as Record<string, unknown>).data as Record<string, unknown>;
210+
expect(data.result).toEqual({ content: output });
211+
});
212+
177213
it("bounds huge Claude Bash result content instead of dropping it", () => {
178214
const output = `first line\n${"y".repeat(40_000)}`;
179215
const projected = projectActivityPayload(

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,29 @@ function projectMcpToolCallData(data: Record<string, unknown>): Record<string, u
255255
return projectedData;
256256
}
257257

258+
function isCommandLikeTool(
259+
payload: Record<string, unknown>,
260+
data: Record<string, unknown>,
261+
): boolean {
262+
if (payload.itemType === "command_execution") {
263+
return true;
264+
}
265+
const kind = asTrimmedString(data.kind)?.toLowerCase();
266+
if (kind === "execute") {
267+
return true;
268+
}
269+
const toolName = asTrimmedString(data.toolName)?.toLowerCase();
270+
if (!toolName) {
271+
return false;
272+
}
273+
return (
274+
toolName.includes("bash") ||
275+
toolName.includes("shell") ||
276+
toolName.includes("terminal") ||
277+
toolName.includes("command")
278+
);
279+
}
280+
258281
function projectCommandResult(result: unknown): Record<string, unknown> | undefined {
259282
const text = extractMcpResultText(result);
260283
if (!text) {
@@ -363,9 +386,11 @@ export function projectActivityPayload(
363386
}
364387
}
365388

366-
const commandResult = projectCommandResult(data.result);
367-
if (commandResult) {
368-
projectedData.result = commandResult;
389+
if (isCommandLikeTool(payload, data)) {
390+
const commandResult = projectCommandResult(data.result);
391+
if (commandResult) {
392+
projectedData.result = commandResult;
393+
}
369394
}
370395

371396
const changedFiles: string[] = [];

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

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

187+
it("does not attach result bodies for Read/Grep dynamic tools", () => {
188+
const source = makeActivity("read", "dynamic_tool_call", {
189+
toolName: "Read",
190+
input: { file_path: "README.md" },
191+
result: {
192+
type: "tool_result",
193+
content: `file body\n${"x".repeat(8_000)}`,
194+
is_error: false,
195+
},
196+
});
197+
const projected = projectActivityPayload(source);
198+
const data = (projected.payload as Record<string, unknown>).data as Record<string, unknown>;
199+
expect(data.result).toBeUndefined();
200+
expect(deriveWorkLogEntries([projected])[0]?.output).toBeUndefined();
201+
});
202+
187203
it("projects Claude Bash result content so the work-log can render it", () => {
188204
const output = `hello from bash\n${"x".repeat(200)}`;
189205
const source = makeActivity("claude-bash", "command_execution", {

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,8 +2150,8 @@ const ToolCallOutputBlock = memo(function ToolCallOutputBlock(props: {
21502150
<Button
21512151
type="button"
21522152
size="xs"
2153-
variant="ghost"
2154-
className="h-5 px-1.5 text-[11px] text-muted-foreground"
2153+
variant="ghost-muted"
2154+
className="h-5 px-1.5 text-[11px]"
21552155
onClick={props.onToggleExpanded}
21562156
>
21572157
{props.expanded ? "Show less" : "Show more"}
@@ -2423,6 +2423,7 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
24232423
className="mt-1 ms-7 cursor-default border-s border-border/45 ps-3 pt-0.5"
24242424
onClick={stopRowToggle}
24252425
onPointerDown={stopRowToggle}
2426+
onKeyDown={stopRowToggle}
24262427
>
24272428
{expandedSections.preamble ? (
24282429
<pre className={toolCallExpandedBodyClassName}>{expandedSections.preamble}</pre>
@@ -2435,7 +2436,9 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
24352436
/>
24362437
) : null}
24372438
{expandedSections.files ? (
2438-
<pre className={toolCallExpandedBodyClassName}>{expandedSections.files}</pre>
2439+
<pre className={cn(toolCallExpandedBodyClassName, "mt-2")}>
2440+
{expandedSections.files}
2441+
</pre>
24392442
) : null}
24402443
</div>
24412444
) : null}

‎apps/web/src/session-logic.command-output.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,55 @@ describe("deriveWorkLogEntries command output", () => {
9595
expect(selectWorkLogToolOutput({ detail: entry!.detail, command: entry!.command })).toBeNull();
9696
});
9797

98+
it("keeps a trailing <exited with exit code 0> line in persisted output", () => {
99+
const output = "hello\n<exited with exit code 0>";
100+
const [entry] = deriveWorkLogEntries([
101+
makeCommandActivity("claude-bash-exit-line", {
102+
itemType: "command_execution",
103+
title: "Command run",
104+
detail: "Bash: printf hello",
105+
data: {
106+
toolName: "Bash",
107+
input: { command: "printf hello" },
108+
result: {
109+
type: "tool_result",
110+
content: output,
111+
is_error: false,
112+
},
113+
},
114+
}),
115+
]);
116+
117+
expect(entry?.output).toBe(output);
118+
expect(selectWorkLogToolOutput(entry!)).toBe(output);
119+
});
120+
121+
it("does not copy MCP summarized result onto output", () => {
122+
const [entry] = deriveWorkLogEntries([
123+
makeCommandActivity("mcp-result", {
124+
itemType: "mcp_tool_call",
125+
title: "Call repository tool",
126+
detail: "repository.search",
127+
data: {
128+
item: {
129+
server: "repository",
130+
tool: "search",
131+
arguments: { query: "work log" },
132+
result: { content: "first line of output" },
133+
},
134+
},
135+
}),
136+
]);
137+
138+
expect(entry?.output).toBeUndefined();
139+
expect(entry?.toolData).toEqual({
140+
server: "repository",
141+
tool: "search",
142+
arguments: { query: "work log" },
143+
result: { content: "first line of output" },
144+
});
145+
});
146+
98147
it("reads Claude tool_result content blocks as output", () => {
99148
const [entry] = deriveWorkLogEntries([
100149
makeCommandActivity("claude-bash-blocks", {

‎apps/web/src/session-logic.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,20 @@ describe("workEntryIndicatesToolFailure", () => {
673673
).toBe(false);
674674
});
675675

676+
it("does not treat completed-success stdout phrases as failure", () => {
677+
expect(
678+
workEntryIndicatesToolFailure({
679+
...base,
680+
label: "Bash",
681+
tone: "tool",
682+
itemType: "command_execution",
683+
toolLifecycleStatus: "completed",
684+
command: "cat notes.txt",
685+
output: "this tutorial mentions command not found, ENOENT, and exit code 1",
686+
}),
687+
).toBe(false);
688+
});
689+
676690
it("treats successful tool rows as success candidates", () => {
677691
expect(
678692
workEntryIndicatesToolSuccess({

0 commit comments

Comments
 (0)