Skip to content

Commit e119cb4

Browse files
Apply PR #11566: fix(tui): remove outer backtick wrapper in session transcript tool formatting
2 parents 88d0d3e + 70a9917 commit e119cb4

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

packages/opencode/src/cli/cmd/tui/util/transcript.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ export function formatPart(part: Part, options: TranscriptOptions): string {
8080
}
8181

8282
if (part.type === "tool") {
83-
let result = `\`\`\`\nTool: ${part.tool}\n`
83+
let result = `**Tool: ${part.tool}**\n`
8484
if (options.toolDetails && part.state.input) {
85-
result += `\n**Input:**\n\`\`\`json\n${JSON.stringify(part.state.input, null, 2)}\n\`\`\``
85+
result += `\n**Input:**\n\`\`\`json\n${JSON.stringify(part.state.input, null, 2)}\n\`\`\`\n`
8686
}
8787
if (options.toolDetails && part.state.status === "completed" && part.state.output) {
88-
result += `\n**Output:**\n\`\`\`\n${part.state.output}\n\`\`\``
88+
result += `\n**Output:**\n\`\`\`\n${part.state.output}\n\`\`\`\n`
8989
}
9090
if (options.toolDetails && part.state.status === "error" && part.state.error) {
91-
result += `\n**Error:**\n\`\`\`\n${part.state.error}\n\`\`\``
91+
result += `\n**Error:**\n\`\`\`\n${part.state.error}\n\`\`\`\n`
9292
}
93-
result += `\n\`\`\`\n\n`
93+
result += `\n`
9494
return result
9595
}
9696

packages/opencode/test/cli/tui/transcript.test.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,38 @@ describe("transcript", () => {
119119
},
120120
}
121121
const result = formatPart(part, options)
122-
expect(result).toContain("Tool: bash")
122+
expect(result).toContain("**Tool: bash**")
123123
expect(result).toContain("**Input:**")
124124
expect(result).toContain('"command": "ls"')
125125
expect(result).toContain("**Output:**")
126126
expect(result).toContain("file1.txt")
127127
})
128128

129+
test("formats tool output containing triple backticks without breaking markdown", () => {
130+
const part: Part = {
131+
id: "part_1",
132+
sessionID: "ses_123",
133+
messageID: "msg_123",
134+
type: "tool",
135+
callID: "call_1",
136+
tool: "bash",
137+
state: {
138+
status: "completed",
139+
input: { command: "echo '```hello```'" },
140+
output: "```hello```",
141+
title: "Echo backticks",
142+
metadata: {},
143+
time: { start: 1000, end: 1100 },
144+
},
145+
}
146+
const result = formatPart(part, options)
147+
// The tool header should not be inside a code block
148+
expect(result).toStartWith("**Tool: bash**\n")
149+
// Input and output should each be in their own code blocks
150+
expect(result).toContain("**Input:**\n```json")
151+
expect(result).toContain("**Output:**\n```\n```hello```\n```")
152+
})
153+
129154
test("formats tool part without details when disabled", () => {
130155
const part: Part = {
131156
id: "part_1",
@@ -144,7 +169,7 @@ describe("transcript", () => {
144169
},
145170
}
146171
const result = formatPart(part, { ...options, toolDetails: false })
147-
expect(result).toContain("Tool: bash")
172+
expect(result).toContain("**Tool: bash**")
148173
expect(result).not.toContain("**Input:**")
149174
expect(result).not.toContain("**Output:**")
150175
})

0 commit comments

Comments
 (0)