fix(components): keep serialized tool-input JSON out of Markdown math - #711
Merged
Merged
Conversation
Tool calls report their raw input as a text content block holding serialized JSON. Routing that text through the Markdown pipeline let single-$ inline math consume shell fragments like $(...) and drop the & in 2>&1, so an expanded tool call displayed a command that was not the command that ran. Detect JSON payloads in StandardToolContentBlock's text case via a pure leaf-module classifier and render them as verbatim pretty-printed code, matching the raw tool output treatment; prose keeps the Markdown path and its math. Model: kimi-code/k3
Model: kimi-code/k3
tommy0103
marked this pull request as ready for review
September 14, 2026 16:40
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f669025f6e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…xemes Review on LodyAI#711 pointed out that the parse/stringify round trip corrupts integers beyond 2^53 (64-bit IDs render as ...776000) and rewrites forms like 1e10, recreating the same displayed-differs-from-actual defect on the digits. JSON.parse now only validates; the original payload text is shown untouched. Pretty-printing is dropped rather than replaced with a lexeme-preserving formatter, which would hand-roll a JSON tokenizer into a display path. Model: kimi-code/k3
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.
Related issue
Closes #710
Problem / pressure
Expanding a tool call showed its raw input JSON mangled. Tool calls report their raw input as a text content block holding serialized JSON (e.g.
{"command":"…","timeout":60}); routing that text through the Markdown pipeline lets single-$inline math treat shell fragments like$(git -C …)as TeX and drop characters like the&in2>&1. The expanded view displayed a command that was not the command that ran — the stored history and the executed command were both intact, so the damage was render-time only.Summary
detectToolCallJsonText(packages/components/src/lib/tool-call-json-text.ts): returns the original text, trimmed but otherwise untouched, when a text block parses as a JSON object or array;nullotherwise (prose, primitives, broken JSON).JSON.parseonly validates — the payload is never re-serialized, so integer lexemes beyond 2^53 (64-bit IDs) and forms like1e10keep their exact digits. (Addresses the P1 review finding: a parse/stringify round trip would corrupt large numeric IDs and recreate the same displayed-differs-from-actual defect.)StandardToolContentBlock'stextcase renders a detected payload in the same monospace<pre>treatment already used for raw tool output; everything else continues toMarkdownBlockunchanged.view.tsximport graph into the test module graph (package rule).git commit --amendcommand with$(...),2>&1, nested quotes), integer lexemes beyond 2^53, exponent forms, plus prose/primitive/malformed-JSON negatives..agents/notes/implemented/bug-fix/2026-09-15-tool-call-json-markdown-math.md.Visual explanation
Simple change: one pure classifier plus one new branch in a render switch; the diff is the structure, and no multi-step flow changes.
Before / after
$(...)spans became italic TeX (user.name="(git−C/…)"),2>&1lost its&— displayed command ≠ executed command$...$mathTest plan
packages/components:tests/tool-call-json-text.test.ts8/8 pass; related suites (markdown-math-delimiters,markdown-autolink,assistant-turn-render-blocks,markdown-streamdown-mode,assistant-message-render-items) pass.packages/componentspnpm typecheck: clean.lint:i18n,check:code-collab-imports,check:platform-boundaries,check:public-boundary,docs check: all exit 0.pnpm check(monorepotest:ci). In a fresh worktree,markdown-idle-rerenderandmarkdown-streaming-reparsefail identically on the unmodified base (jotai storage environment), so they are unrelated to this change; verified by A/B against a stash of this branch.Context handoff
Instructions for reviewing agents
packages/components/src/lib/tool-call-json-text.ts(classifier contract, validation-only parse) and thetextcase ofStandardToolContentBlockinpackages/components/src/components/ai-gui/view.tsx(new render branch).resourcetext case was deliberately left on the Markdown path and can still hit the artifact.Authoring context
resourcetext blocks untouched; no new user-visible copy (no i18n changes); no new AGENTS.md rules (owning files are near their size gate; rationale lives in the Agent Note).test:ci(see test plan); live UI click-through;resourcetext case; lexeme-preserving pretty-printer (rejected as disproportionate tokenizer complexity for a display path).Original user prompt
Show original prompt