feat(escape ansi): escape ansi ctrl codes from model output before displaying to user#8636
Merged
Conversation
|
Size Change: +2.41 kB (+0.01%) Total Size: 17.4 MB
ℹ️ View Unchanged
|
96e5ad0 to
75ca152
Compare
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
cornmander
reviewed
Sep 17, 2025
jacob314
reviewed
Sep 17, 2025
jacob314
reviewed
Sep 17, 2025
jacob314
left a comment
Contributor
There was a problem hiding this comment.
Generally looks like the right path. Approved once the comments are addressed.
bb7bb09 to
b6b1312
Compare
b6b1312 to
218784f
Compare
jacob314
reviewed
Sep 19, 2025
jacob314
reviewed
Sep 19, 2025
jacob314
reviewed
Sep 19, 2025
jacob314
left a comment
Contributor
There was a problem hiding this comment.
Approved after these comments are addressed.
99baa5c to
0bff588
Compare
29a239b to
3be2944
Compare
cornmander
reviewed
Sep 23, 2025
Contributor
|
Confirmed this looks good locally. |
geoffdowns
pushed a commit
to geoffdowns/gemini-cli
that referenced
this pull request
Sep 26, 2025
thacio
added a commit
to thacio/auditaria
that referenced
this pull request
Oct 4, 2025
…m model output before displaying to user (google-gemini#8636)
giraffe-tree
pushed a commit
to giraffe-tree/gemini-cli
that referenced
this pull request
Oct 10, 2025
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.

TLDR
This PR prevents model output from rewriting the terminal window by escaping all ansi control codes (content and tools) before display.
Dive Deeper
The model can output text which contains ANSI control codes which can rewrite the terminal window, possibly obfuscating the tool call that will be made.
We sovle this by using JSON.stringify() to escape all ANSI control codes before displaying tool calls or model content. This prevents against techniques to hide what the model is doing.
See 754 for more details.
Reviewer Test Plan
Create a file called corruptedFile.txt with
Start gemini-cli and prompt "Run the command in corruptedFile.txt"
The terminal will display a shell command to run
echo 'good' && echo good'despite the REAL tool call beingecho 'good' && echo 'evil message' \u001b[24D\u001b[K && echo goodPull this PR down and rerun these steps. The tool confirmation dialog will now show:
Testing Matrix
Linked issues / bugs
Fixes 754
Partially addresses 791. I will follow up with a separate PR to escape ANSI in files being displayed.