Documentation
¶
Overview ¶
Package textsafe cleans and reveals text that someone else wrote and that a person or a terminal is about to read: a command the model wants to run, the output of a process, a page that was fetched.
A terminal interprets bytes, not strings. Text that reaches it with an escape sequence intact can write the user's clipboard (OSC 52), draw a link whose visible text is not its target (OSC 8), move the cursor and repaint other parts of the screen, or retitle the window. Text that reaches a person with invisible or direction-changing characters can read differently from what it does: a command whose visible text is `ls` and whose real text is something else (the "Trojan Source" family). Both matter most where a person approves an action by reading it.
The sanitizing functions follow the approach of Freebuff (Codebuff, Apache-2.0) in common/src/util/terminal-safe-text.ts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeceptiveRune ¶
DeceptiveRune returns the first character of s that can make it read differently from what it does (see isDeceptive) and whether there is one.
func Reveal ¶
Reveal makes every invisible or control character of s visible as «U+XXXX», so that a person who is asked to approve the text sees what is really in it. Newlines and tabs stay. Visible text is returned unchanged.
func SanitizeOutput ¶
SanitizeOutput is SanitizeText for what a process printed. One difference: a bare carriage return is a progress bar redrawing its line, not a line break, so only the text after the last one on each line is kept, as a real terminal would show it.
func SanitizeText ¶
SanitizeText removes every escape sequence (OSC, DCS/SOS/PM/APC, CSI, short ESC, 7- and 8-bit forms), every other control character and the invisible characters. Newlines survive (CR and CRLF become a newline), a tab becomes two spaces. Printable text is otherwise unchanged and is not trimmed.
Types ¶
This section is empty.