fix(cli): escape control characters at the CLI's stdout and stderr writes
Merged
TH
8d ago+1748+1748+0123456789012345678901234567890123456789-334-334-012345678901234567890123456789
Summary
Text the CLI prints can name values that a device or a remote daemon chose. Every CLI write now escapes C0 (except newline and tab), DEL and C1 as \u00NN. That form is also a JSON escape, so any JSON the CLI prints, with or without --json, still parses back to the exact values.
- Design: values stay raw (data,
--json, files, JUnit) until a display line is built.- The cli zone writes through
src/cli/process-exit.ts, and lower zones applyescapeTerminalTextfromkernel/redactionthemselves. - Only intended color and cursor codes are written raw: colored diffs, proxy startup, the
doctorsummary, and the replay reporter's own codes.
- The cli zone writes through
- Paths covered:
- every formatter, warning line and error, including details;
- the replay
testreporter (escaped values, checked counters, single-row live lines, command progress on its own row, written only by the built-in reporter); - upload progress through the CLI's progress sink;
- the proxy takeover notice through a structured
onTakeovercallback; --debugdiagnostics;agent-cdpchild output (a verbatim opt-in can follow if someone needs it);- streamed
doctorlines, via an additive optionalmarkeronCommandProgressEventwith a ledger ack; the CLI colors the marker after escaping.
- Warning lines: every warning folds to one
Warning:line. Formatters never print response warnings: the dispatcher prints each one exactly once, on stderr for a parseable-output command such asrecord. Effects you can see:recordwarnings go to stderr, not into the stdout path.snapshotwarnings come after the tree asWarning:lines, not as plain lines above it.openwarnings come after the--foregroundsnapshot tree, not right afterOpened:. The nested snapshot warnings print once, after the tree and before theopenwarnings.
- Docs: the command reference documents the
\u00NNform, the layout rule, and the MCP and AI SDK text.
Split out of #4744, which stays a remote-only change. 63 files, +1553/โ294 (production about +440/โ240 across 37 files).
Validation
At b2b83cb50c:
- End-to-end tests cover each surface:
open,snapshot,snapshot diff,screenshot,close,get attrs,--json, errors, the replay reporter (TTY live row, malformed counters, JUnit exactness, trace lookup), upload progress, the takeover notice,doctor,debug,record,replay export,agent-cdpand--debugdiagnostics. - Mutations: each fix has a test that fails when it is reverted.
- Suites:
src,command-output, kernel, remote,daemon-client, daemon sessions, host-kit and wire-compat (19,154 tests) and the eager-closure check pass. - Gates: typecheck, lint,
check:layering,fallow audit --base origin/mainandcheck:production-exportsare clean.
CI validates the head.
๐ค Generated with Claude Code
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Open in [code]smith ยท Need help on this PR? Tag @codesmith-bot with what you need.