Skip to content

Commit 2953ece

Browse files
rossdonaldMy Name
authored andcommitted
Skip thoughtSignature blocks during markdown export RooCodeInc#10199 (RooCodeInc#10932)
1 parent 1c19350 commit 2953ece

2 files changed

Lines changed: 84 additions & 1 deletion

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { describe, it, expect } from "vitest"
2+
import { formatContentBlockToMarkdown, ExtendedContentBlock } from "../export-markdown"
3+
4+
describe("export-markdown", () => {
5+
describe("formatContentBlockToMarkdown", () => {
6+
it("should format text blocks", () => {
7+
const block = { type: "text", text: "Hello, world!" } as ExtendedContentBlock
8+
expect(formatContentBlockToMarkdown(block)).toBe("Hello, world!")
9+
})
10+
11+
it("should format image blocks", () => {
12+
const block = {
13+
type: "image",
14+
source: { type: "base64", media_type: "image/png", data: "data" },
15+
} as ExtendedContentBlock
16+
expect(formatContentBlockToMarkdown(block)).toBe("[Image]")
17+
})
18+
19+
it("should format tool_use blocks with string input", () => {
20+
const block = { type: "tool_use", name: "read_file", id: "123", input: "file.txt" } as ExtendedContentBlock
21+
expect(formatContentBlockToMarkdown(block)).toBe("[Tool Use: read_file]\nfile.txt")
22+
})
23+
24+
it("should format tool_use blocks with object input", () => {
25+
const block = {
26+
type: "tool_use",
27+
name: "read_file",
28+
id: "123",
29+
input: { path: "file.txt", line_count: 10 },
30+
} as ExtendedContentBlock
31+
expect(formatContentBlockToMarkdown(block)).toBe("[Tool Use: read_file]\nPath: file.txt\nLine_count: 10")
32+
})
33+
34+
it("should format tool_result blocks with string content", () => {
35+
const block = { type: "tool_result", tool_use_id: "123", content: "File content" } as ExtendedContentBlock
36+
expect(formatContentBlockToMarkdown(block)).toBe("[Tool]\nFile content")
37+
})
38+
39+
it("should format tool_result blocks with error", () => {
40+
const block = {
41+
type: "tool_result",
42+
tool_use_id: "123",
43+
content: "Error message",
44+
is_error: true,
45+
} as ExtendedContentBlock
46+
expect(formatContentBlockToMarkdown(block)).toBe("[Tool (Error)]\nError message")
47+
})
48+
49+
it("should format tool_result blocks with array content", () => {
50+
const block = {
51+
type: "tool_result",
52+
tool_use_id: "123",
53+
content: [
54+
{ type: "text", text: "Line 1" },
55+
{ type: "text", text: "Line 2" },
56+
],
57+
} as ExtendedContentBlock
58+
expect(formatContentBlockToMarkdown(block)).toBe("[Tool]\nLine 1\nLine 2")
59+
})
60+
61+
it("should format reasoning blocks", () => {
62+
const block = { type: "reasoning", text: "Let me think about this..." } as ExtendedContentBlock
63+
expect(formatContentBlockToMarkdown(block)).toBe("[Reasoning]\nLet me think about this...")
64+
})
65+
66+
it("should skip thoughtSignature blocks", () => {
67+
const block = { type: "thoughtSignature" } as ExtendedContentBlock
68+
expect(formatContentBlockToMarkdown(block)).toBe("")
69+
})
70+
71+
it("should handle unexpected content types", () => {
72+
const block = { type: "unknown_type" as const } as any
73+
expect(formatContentBlockToMarkdown(block)).toBe("[Unexpected content type: unknown_type]")
74+
})
75+
})
76+
})

src/integrations/misc/export-markdown.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ interface ReasoningBlock {
99
text: string
1010
}
1111

12-
type ExtendedContentBlock = Anthropic.Messages.ContentBlockParam | ReasoningBlock
12+
interface ThoughtSignatureBlock {
13+
type: "thoughtSignature"
14+
}
15+
16+
export type ExtendedContentBlock = Anthropic.Messages.ContentBlockParam | ReasoningBlock | ThoughtSignatureBlock
1317

1418
export function getTaskFileName(dateTs: number): string {
1519
const date = new Date(dateTs)
@@ -98,6 +102,9 @@ export function formatContentBlockToMarkdown(block: ExtendedContentBlock): strin
98102
}
99103
case "reasoning":
100104
return `[Reasoning]\n${block.text}`
105+
case "thoughtSignature":
106+
// Not relevant for human-readable exports
107+
return ""
101108
default:
102109
return `[Unexpected content type: ${block.type}]`
103110
}

0 commit comments

Comments
 (0)