mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-08-22 03:18:54 +08:00
fix(summary): keep every text block in structured tool results (#1619)
formatResultContent recognized structured tool output shaped like
`[{ type: "text", text: "..." }]` but read only `parsedContent[0].text`.
When a tool result split its output across several text blocks, the step
summary showed the first and silently dropped the rest, so extra findings,
file paths and follow-up instructions vanished from the rendered
Claude Code Report while remaining in the execution transcript.
Collect the text from every block instead of just the first. Blocks of other
types, such as images, are skipped rather than stringified into the summary.
Fixes #1572
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
8b8745859f
commit
a2489efcb9
@@ -164,9 +164,15 @@ export function formatResultContent(content: any): string {
|
|||||||
typeof parsedContent[0] === "object" &&
|
typeof parsedContent[0] === "object" &&
|
||||||
parsedContent[0]?.type === "text"
|
parsedContent[0]?.type === "text"
|
||||||
) {
|
) {
|
||||||
// Extract the text field from the first item. Tool output is arbitrary,
|
// Keep every text block, not just the first: a tool result may split its
|
||||||
// so `text` is not guaranteed to be a string.
|
// output across several, and dropping the rest silently loses findings,
|
||||||
contentStr = String(parsedContent[0]?.text || "");
|
// file paths and follow-up instructions from the rendered summary. Blocks
|
||||||
|
// of other types (for example images) are skipped. Tool output is
|
||||||
|
// arbitrary, so `text` is not guaranteed to be a string.
|
||||||
|
contentStr = parsedContent
|
||||||
|
.filter((block: any) => block?.type === "text")
|
||||||
|
.map((block: any) => String(block?.text || ""))
|
||||||
|
.join("\n");
|
||||||
} else {
|
} else {
|
||||||
contentStr = String(content).trim();
|
contentStr = String(content).trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,6 +111,42 @@ describe("formatResultContent", () => {
|
|||||||
const result = formatResultContent(JSON.stringify(structuredContent));
|
const result = formatResultContent(JSON.stringify(structuredContent));
|
||||||
expect(result).toBe("**→** Hello world\n\n");
|
expect(result).toBe("**→** Hello world\n\n");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("keeps every text block, not just the first", () => {
|
||||||
|
const structuredContent = [
|
||||||
|
{ type: "text", text: "first line" },
|
||||||
|
{ type: "text", text: "second line" },
|
||||||
|
{ type: "text", text: "third line" },
|
||||||
|
];
|
||||||
|
const result = formatResultContent(JSON.stringify(structuredContent));
|
||||||
|
|
||||||
|
expect(result).toContain("first line");
|
||||||
|
expect(result).toContain("second line");
|
||||||
|
expect(result).toContain("third line");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("keeps every text block when given an array directly", () => {
|
||||||
|
const result = formatResultContent([
|
||||||
|
{ type: "text", text: "alpha" },
|
||||||
|
{ type: "text", text: "beta" },
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(result).toContain("alpha");
|
||||||
|
expect(result).toContain("beta");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("skips non-text blocks while keeping the text ones", () => {
|
||||||
|
const structuredContent = [
|
||||||
|
{ type: "text", text: "visible" },
|
||||||
|
{ type: "image", source: { data: "ignored-binary" } },
|
||||||
|
{ type: "text", text: "also visible" },
|
||||||
|
];
|
||||||
|
const result = formatResultContent(JSON.stringify(structuredContent));
|
||||||
|
|
||||||
|
expect(result).toContain("visible");
|
||||||
|
expect(result).toContain("also visible");
|
||||||
|
expect(result).not.toContain("ignored-binary");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("formatToolWithResult", () => {
|
describe("formatToolWithResult", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user