termsafe

package
v0.0.0-...-a271580 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package termsafe strips the characters a terminal reads as commands from strings that came from somewhere untrusted.

sandbox-cli prints a lot of text the agent chose: session titles and project paths out of transcripts, filenames out of the workspace, model names out of a file the agent writes. All of it goes to the user's terminal, where an ESC is not a character but an instruction — screen clears, window titles, and on permissive terminals a clipboard write via OSC 52. A listing of what an agent did should not be able to act on the machine reading it.

This is a package rather than a helper in each caller because it was a helper in each caller: three near-identical copies existed, and an audit then found two more display paths that had none — `git status -z` filenames and the `context list` project column. One name to reach for is the difference between remembering and forgetting.

Sanitising is deliberately at the point where the value enters something the user will read, not at the point of print: a value that has been through Clean stays safe wherever it is later composed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean(s string) string

Clean replaces every control character with a space and collapses the runs, so the result is a single printable line.

The ranges are C0 (which includes ESC), DEL, and C1 — everything a terminal may interpret. Printable non-ASCII is kept, because a filename or a title in any language is ordinary text and mangling it would be its own bug.

func FirstLine

func FirstLine(s string) string

FirstLine is Clean for values where only the first line is wanted — a title, where the rest of a multi-line prompt is not a summary of it. The truncation happens before the control characters are replaced, so an embedded newline still ends the line rather than becoming a space.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL