fix(tui): decode JSON tool envelopes and fold untrusted wrappers for display - #15
Merged
Merged
Conversation
…display Tool results that return a JSON envelope (read_file, search_files, head_tail) rendered as raw JSON, exposing encoding/json's HTML-escaped (<) prompt-injection wrapper tags as transcript noise. resultPreview now normalizes for display only: - envelopes with a string content field are decoded, rendering the real content with remaining scalar metadata as a one-line footer - untrusted_content wrappers (literal and < escaped forms) fold into a "⚠ untrusted: <source>" badge line followed by the body - unknown or malformed shapes render byte-identical (fail-safe) Rendering only: persisted and model-bound data is never rewritten.
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.
Symptom
Tool results from tools returning a JSON envelope (
read_file,search_files,head_tail) rendered as raw JSON in the transcript, exposingencoding/jsonHTML-escaped prompt-injection wrapper tags:Root cause
odek wraps untrusted tool output in
<untrusted_content_<nonce> source="…">…</…>. Tools returning JSON serialize that string with Go'sencoding/json, which HTML-escapes<,>,&by default. The TUI rendered the raw envelope instead of decoding it first. Display noise only — the wrapper is a prompt-injection boundary and is not altered in any data sent back to the model.Fix (display layer only,
internal/tui)resultPreview(used by both livetool_resultevents and resumed transcripts) now normalizes before render:contentfield is decoded — the real content renders, with remaining scalar metadata (e.g.total_lines) as a one-line footer. Unknown shapes (nested values, missingcontent, invalid JSON) render byte-identical — fail-safe, never lossy.untrusted_contentwrappers become a dimmed badge line⚠ untrusted: <source>followed by the body. Both the literal tag form (live stream events) and the `` escaped form (undecoded envelopes) are recognized.Scope: rendering only. Nothing persisted, echoed back, or forwarded is rewritten.
Tests (TDD — written red first)
total_linesfooter presentVerification
make fmt && make vet && make lint— 0 issuesmake test— full-racesuite greengo build ./...