Repository navigation
fix(common): render tool-result content blocks as text, not escaped JSON or base64 - #90
Open
malihashar wants to merge 1 commit into
Open
malihashar wants to merge 1 commit into
malihashar wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #89
What is wrong
Many tools return their result as a list of blocks, for example one text block and one image block. Every MCP tool does this, and so does any screenshot or image-reading tool. txcript turns that whole list into one JSON string, in
view, in the MCPread_sessiontool, in search, and when converting to Codex, pi, Campfire, Cursor and OpenCode.So you see escaped text (
\nand\") instead of the real text. A screenshot shows up as its entire base64 data. Nothing warns you.How to see it
Make a Claude Code session with a tool result that has a text block and an image block of about 150 KB, then:
txcript view <id>[image: image/png]read_sessioncontinue --with codex --outWhat this PR changes
One helper,
ToolOutput::as_text, insrc/common.rs. It turns a tool result into readable text:[image: <media type>]. This is the same placeholder that PR fix(codec): preserve multimodal artifacts and images across harness conversions #46 uses. If there is no media type, it is[image].It replaces about 10 private copies of the same JSON-to-text code in
view, search, the pager, and the Codex, pi, Cursor, OpenCode, Grok and fx converters. Grok and fx already did the text part, but gave up and printed the whole JSON as soon as one block was an image. No new dependency, option or type.I left two converters alone on purpose: Antigravity and Cursor Desktop. They write compact JSON deliberately so it reads back as JSON, and changing that would break their round-trip tests. Images there still export as base64. Formats that keep the structure (Claude Code, Simple, Hermes, Grok Bot) are untouched.
How it was tested
tests/regression/tool_result_blocks.rs. They use one session with four results (a text block, text plus image, a plain string, a JSON object) and checkview, search, and the Codex, pi and Grok exports. The plain string and JSON object must stay byte for byte the same. These tests fail on the old code and pass on the new code.cargo fmtandcargo clippyare clean.What I could not test
Questions for the maintainer
[image: <media type>]the right placeholder?