Repository navigation
fix(cli): escape control characters at the CLI's stdout and stderr writes - #4778
Conversation
Size Report
Startup median (7 runs, lower is better):
|
This comment has been minimized.
This comment has been minimized.
|
An independent correctness pass over bfda653, to fold in with the
Not blocking:
|
|
One more point on bfda653, from the line-by-line review, that would simplify the fix for item 1 in the comment above. Make the writer's escape valid inside JSON strings. Today The review also confirmed item 7: the screenshot default handler (screenshot.ts:45-51) and replay export warnings ( Not blocking: |
|
Thanks. All seven are in 72f363d, folded together with the addendum (#issuecomment-7019263508). Each fix has a test that fails when it is reverted.
Optional items:
Layering: |
|
Addendum applied in 72f363d; details are in the reply above.
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 5b55231. The verdict and the full list are in the summary comment.
This comment has been minimized.
This comment has been minimized.
|
Thanks for the update. At 3141391 the one-format change works: the shared writer emits A second, independent correctness pass found six more gaps. Two are regressions caused by escaping too early, and three are in the replay Escaping before a value is used for something other than display:
Replay reporter output still raw: These four share one cause. The reporter escapes some values early and writes others raw. Please make the rule "values stay raw until the last moment, and every reporter line goes through the escaping writer, except the reporter's own color and cursor codes". Fold newlines and tabs in every live-row field before measuring. That fixes items 1-4 together, and future fields can't slip through. Other direct writes: Not blocking: |
|
A few more items at 3141391 from the line-by-line review, to fold into the same push:
|
|
Thanks. All six are fixed in 435a07b, together with the line-by-line items. Each fix has a test that fails when it is reverted, and I checked that the four reporter tests fail against the 3141391 reporter files. 1–4, one rule: values stay raw until a display line is built.
5. 6. Docs: the command reference now lists only the built-in help and version text as unescaped. |
|
Applied in 435a07b.
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 435a07b. The verdict and the full list are in the summary comment.
This comment has been minimized.
This comment has been minimized.
|
At dc7384c every item from the 3141391 comments is fixed: reporter values stay raw until a display line is built, so JUnit keeps exact text and the trace lookup uses the raw path. A second, independent correctness pass found three more gaps that this PR introduces or exposes, so no label yet:
Not blocking:
|
|
Thanks. All three are fixed in b2b83cb. Each has a test that fails when the fix is reverted (checked by mutation).
Optional items:
Validation: |
|
At b2b83cb the three dc7384c gaps are fixed with tests that fail on the old code: malformed replay counters render as A second, independent correctness pass found that the warning de-duplication is still fragile, and that the new reporter hook opens a side door. No label yet, but I think one structural change ends this:
Not blocking:
|
This comment has been minimized.
This comment has been minimized.
|
Both fixed in 6964c8c. Warnings: the dispatcher is the only printer. Formatters never print response warnings.
Tests for both failure cases:
Command progress is internal.
Optional items:
I mutated every new test: each fails when its fix is reverted. Typecheck, lint, layering, the eager-closure and wire-compat suites, |
|
At 956ff51 (6964c8c plus a one-line test fix) both structural changes are in: warnings print only from the dispatcher, once each, with the text matching deleted, and
Not blocking:
|
|
Both gaps fixed in dd8d7b9.
I checked that each test fails when its fix is reverted. The PR body's warning item now lists the visible effects, including the moved |
|
This PR is ready at 87e371a. Since 956ff51 the two remaining gaps are fixed with tests that fail when reverted: Not blocking, as noted before: the process entry's fast help, version and outer error writes ( |
This comment has been minimized.
This comment has been minimized.
|
This now conflicts with |
87e371a to
c269d9d
Compare
|
Rebased onto current main. New head: c269d9d. Conflicts: only one, in Scope: the diff against main touches the same 67 files as before the rebase, and nothing from main is reverted. New output from main: none of it needed a fix.
Checks: build, typecheck, lint, layering, |
Apex Sentinel · ✅ Approve · review of
|
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
…ites Text the CLI prints can name values a device or a remote daemon chose, such as paths and labels. Every CLI write now goes through one writer: - text output shows C0 (except newline and tab), DEL and C1 characters as \xNN, so no formatter, current or future, can let a value drive the terminal; - JSON output escapes DEL and C1 as \uNNNN (JSON.stringify already escapes C0), so it stays valid and parses back exact; the --level full text output and the error details block use the same serializer. Colored diff and proxy output escapes its own values (colorize escapes the text it wraps) and is written through a narrow raw path, as is the output of a tool the CLI runs and passes through. Default open no longer prints a multi-line warning twice. The command reference documents the newline and tab layout rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The JSON writer and the progress sink live in the commands zone, so they no longer import the cli zone's writer: the JSON writer's output is already terminal-safe, and the progress sink applies the shared kernel escape itself. This removes the commands -> cli back-edge and the zone cycle it created. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The shared escape now writes \u00NN, which is also a JSON escape, so any JSON the CLI prints (get attrs, find, session list, Metro, snapshot --raw, --json, --level full, error details) stays valid and parses back exact. The separate JSON serializer is gone. - The built-in replay test reporter escapes daemon-supplied text before composing it, keeps live rows on one line, and the registry escapes a reporter hook error. - Proxy startup escapes its values with color off as well as on. - Remote upload progress goes to the CLI's progress sink, which escapes; without a sink the file name is escaped on stderr. - The proxy path's daemon takeover notice is a structured onTakeover callback the CLI renders. - doctor keeps its own status-marker colors: the summary escapes its values and is written raw, and streamed check lines carry their status as an optional marker that the CLI colors after escaping. - Screenshot and replay export warnings go through appendWarningLinesText, and snapshot notices fold newlines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…line The progress sink loads status-marker color asynchronously, and one timer tick was not always enough under coverage, so the line came out escaped but not yet colored. The test now waits until a line is colored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A test run hands progress to the replay reporter runtime, which had no route for command progress events, so upload progress was dropped. The runtime now writes a command progress line to stderr, escaped, as every other command does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t direct writes - The replay test reporter keeps run values raw: JUnit stores exact warnings (folding is separate from the terminal escape) and trace lookup uses the raw artifacts path. Values are folded and escaped where a display line is built, every value line goes through the escaping write, and only the reporter's own color and cursor codes are raw. Verbose timing lines are escaped and every live-row field stays on one row. - --debug diagnostics with no log path are escaped at their stderr write; the file form is unchanged. - agent-cdp child output is escaped by default. - debug and record warnings fold through appendWarningLinesText. - The daemon takeover notice has one formatter, shared by the startup fallback and proxy. - diff notices are no longer escaped twice, and the ledger rationale states how a released daemon's colored doctor lines now print. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… note Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…track shown warnings - Replay counters and durations a daemon reports are checked at runtime and shown as ? when malformed; every live-row field goes through the single-row display step. - A command progress line during a test run goes to the reporter that draws the live row: it clears the row first, and the next row starts on a fresh line. - appendWarningLinesText skips a warning only when it is shown on a line of its own, so a warning that also appears inside a path keeps its Warning line. - The command reference notes how MCP and AI SDK tool text show the escapes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…command progress internal Formatters no longer print response warnings. The dispatcher prints each one exactly once from the warnings channel, so the text-matching dedupe is gone. A parseable command (record) now warns on stderr instead of in its stdout path. Command progress during a test run is no longer part of the public reporter type. Only the built-in reporter writes it, escaped, and a failure to write it is reported without failing the run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng upload observer from stopping the upload The nested snapshot of open --foreground is not the response, so the dispatcher never prints its warnings. They now print once where the snapshot text is composed. An upload progress observer that throws is now contained in the progress transform, so the upload continues. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rivate-ax sample Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
c269d9d to
c4804b5
Compare
* origin/main: (70 commits) refactor(apple-runner): one RUNNER_ERROR_CODES row per runner error code with parity/docs gates (callstack#4774) fix(android): require acknowledgements for test IME typing (callstack#4722) feat(scroll): add scroll refresh for pull-to-refresh (callstack#4770) refactor(host-kit): add request Scope and use it for the wait capture deadline (callstack#4794) fix(android): let permission all change nothing on an app that declares no permissions (callstack#4796) fix(cli): replace the CLI session and generated remote config instead of rewriting them in place (callstack#4797) fix(host-kit): accept a group-writable script directory the user owns (callstack#4799) fix(cli): escape control characters at the CLI's stdout and stderr writes (callstack#4778) fix(audit): do not report rows under a persistent bar that scrolling reveals (callstack#4775) fix(daemon): refuse an unsafe state directory before first use (callstack#4783) refactor: settle remaining single-deadline races through settleWithin (callstack#4788) refactor(host-kit): settle deadline races via settleWithin with R87 race ratchet (callstack#4766) fix(android): authenticate and bound persistent snapshot helper sessions (callstack#4729) fix(daemon): bound upload ingress and finalization (callstack#4721) chore(gates): ratchet wire-published reason literals by value (R89) (callstack#4779) feat(audit): evaluate role-less clickable views on Android (callstack#4780) fix(mutation): keep umask-setting tests out of Stryker's thread pool (callstack#4785) feat(audit): report controls that share one accessible name (callstack#4771) fix(contracts): pair open runtime hints with their apply operation (callstack#4754) refactor(daemon): report startup progress over the launch channel instead of marker files (callstack#4777) ...
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.--json, files, JUnit) until a display line is built.src/cli/process-exit.ts, and lower zones applyescapeTerminalTextfromkernel/redactionthemselves.doctorsummary, and the replay reporter's own codes.testreporter (escaped values, checked counters, single-row live lines, command progress on its own row, written only by the built-in reporter);onTakeovercallback;--debugdiagnostics;agent-cdpchild output (a verbatim opt-in can follow if someone needs it);doctorlines, via an additive optionalmarkeronCommandProgressEventwith a ledger ack; the CLI colors the marker after escaping.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.\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: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.src,command-output, kernel, remote,daemon-client, daemon sessions, host-kit and wire-compat (19,154 tests) and the eager-closure check pass.check:layering,fallow audit --base origin/mainandcheck:production-exportsare clean.CI validates the head.
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.