fix(tui): remove outer backtick wrapper in session transcript tool formatting (#11566)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -80,17 +80,17 @@ export function formatPart(part: Part, options: TranscriptOptions): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (part.type === "tool") {
|
if (part.type === "tool") {
|
||||||
let result = `\`\`\`\nTool: ${part.tool}\n`
|
let result = `**Tool: ${part.tool}**\n`
|
||||||
if (options.toolDetails && part.state.input) {
|
if (options.toolDetails && part.state.input) {
|
||||||
result += `\n**Input:**\n\`\`\`json\n${JSON.stringify(part.state.input, null, 2)}\n\`\`\``
|
result += `\n**Input:**\n\`\`\`json\n${JSON.stringify(part.state.input, null, 2)}\n\`\`\`\n`
|
||||||
}
|
}
|
||||||
if (options.toolDetails && part.state.status === "completed" && part.state.output) {
|
if (options.toolDetails && part.state.status === "completed" && part.state.output) {
|
||||||
result += `\n**Output:**\n\`\`\`\n${part.state.output}\n\`\`\``
|
result += `\n**Output:**\n\`\`\`\n${part.state.output}\n\`\`\`\n`
|
||||||
}
|
}
|
||||||
if (options.toolDetails && part.state.status === "error" && part.state.error) {
|
if (options.toolDetails && part.state.status === "error" && part.state.error) {
|
||||||
result += `\n**Error:**\n\`\`\`\n${part.state.error}\n\`\`\``
|
result += `\n**Error:**\n\`\`\`\n${part.state.error}\n\`\`\`\n`
|
||||||
}
|
}
|
||||||
result += `\n\`\`\`\n\n`
|
result += `\n`
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,13 +119,38 @@ describe("transcript", () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
const result = formatPart(part, options)
|
const result = formatPart(part, options)
|
||||||
expect(result).toContain("Tool: bash")
|
expect(result).toContain("**Tool: bash**")
|
||||||
expect(result).toContain("**Input:**")
|
expect(result).toContain("**Input:**")
|
||||||
expect(result).toContain('"command": "ls"')
|
expect(result).toContain('"command": "ls"')
|
||||||
expect(result).toContain("**Output:**")
|
expect(result).toContain("**Output:**")
|
||||||
expect(result).toContain("file1.txt")
|
expect(result).toContain("file1.txt")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("formats tool output containing triple backticks without breaking markdown", () => {
|
||||||
|
const part: Part = {
|
||||||
|
id: "part_1",
|
||||||
|
sessionID: "ses_123",
|
||||||
|
messageID: "msg_123",
|
||||||
|
type: "tool",
|
||||||
|
callID: "call_1",
|
||||||
|
tool: "bash",
|
||||||
|
state: {
|
||||||
|
status: "completed",
|
||||||
|
input: { command: "echo '```hello```'" },
|
||||||
|
output: "```hello```",
|
||||||
|
title: "Echo backticks",
|
||||||
|
metadata: {},
|
||||||
|
time: { start: 1000, end: 1100 },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const result = formatPart(part, options)
|
||||||
|
// The tool header should not be inside a code block
|
||||||
|
expect(result).toStartWith("**Tool: bash**\n")
|
||||||
|
// Input and output should each be in their own code blocks
|
||||||
|
expect(result).toContain("**Input:**\n```json")
|
||||||
|
expect(result).toContain("**Output:**\n```\n```hello```\n```")
|
||||||
|
})
|
||||||
|
|
||||||
test("formats tool part without details when disabled", () => {
|
test("formats tool part without details when disabled", () => {
|
||||||
const part: Part = {
|
const part: Part = {
|
||||||
id: "part_1",
|
id: "part_1",
|
||||||
@@ -144,7 +169,7 @@ describe("transcript", () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
const result = formatPart(part, { ...options, toolDetails: false })
|
const result = formatPart(part, { ...options, toolDetails: false })
|
||||||
expect(result).toContain("Tool: bash")
|
expect(result).toContain("**Tool: bash**")
|
||||||
expect(result).not.toContain("**Input:**")
|
expect(result).not.toContain("**Input:**")
|
||||||
expect(result).not.toContain("**Output:**")
|
expect(result).not.toContain("**Output:**")
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user