fix(tui): sanitize foreground Bash tool output - #2919
Conversation
🦋 Changeset detectedLatest commit: cec058a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Captured Bash stdout/stderr reached pi-tui unsanitized in the tool-call card, so sequences such as ESC[?1049h switched the host terminal to the alternate screen and left tmux scrollback unavailable after exit. Sanitize the accumulated buffer in ShellExecutionComponent, which covers both streaming live output and the final result.
910d9ef to
cec058a
Compare
|
@liruifengv — tagging you since this continues #2863 (which you merged). The foreground Bash tool card still passes captured output straight to pi-tui, so Diff is one call site plus a changeset. Happy to add regression tests for the split-chunk and final-result paths if you'd like them in this PR. |
|
Friendly bump. Rechecked against current Regression tests for the split-chunk and final-result paths are ready to push if you want them in this PR — just say so. Happy to redirect to someone else if the TUI area has a different owner now. cc: @liruifengv |
Related Issue
Fixes #2915
Problem
Foreground Bash tool stdout/stderr reaches pi-tui unsanitized, both while streaming and in the final result. A captured
ESC[?1049hswitches the host terminal to the alternate screen; inside tmux this makes native scrollback unavailable, and the pane stays in that state after Kimi Code exits because no matchingESC[?1049lis emitted.sanitizeShellOutputalready guards!shell mode and the background task views (#2863), but not the tool-call card.What changed
Sanitize
result.outputinShellExecutionComponentbefore styling. This single site covers both the accumulated live stdout/stderr and the final Bash result, sincebuildLiveOutputBlockrenders live output through the same component. Sanitizing the complete accumulated buffer rather than each chunk means an escape sequence split acrossappendLiveOutputcalls cannot survive.Scoped to
ShellExecutionComponentrather thanTruncatedOutputComponent, which is thedefaultresult renderer and would change generic and MCP tool rendering too.Includes a patch changeset for
@moonshot-ai/kimi-code.Verification
CI has not been able to run on this fork PR yet, so every
ci.ymljob was reproduced locally oncec058a(Node 25.8.0, pnpm 10.33.0):ci.ymljobtestpnpm run testtest-pi-tuipnpm --filter @moonshot-ai/pi-tui testlintpnpm run lint/pnpm run sheriftypecheckpnpm run typecheckbuildpnpm run build+pnpm -C apps/kimi-code run smokeNix Buildwas not reproducible locally (nix not installed), but this PR touches no packaging or flake inputs.Also measured the sanitizer at the 50k
MAX_LIVE_OUTPUT_CHARScap: ~0.075 ms per call on escape-heavy input, so the per-render cost is negligible.Note on #2918
#2918 (interactive PTY
!commands) raises sanitize-vs-interpret for transcript rendering. That concerns!shell mode; the agent-invoked Bash tool is non-interactive by design, so sanitizing its captured output stays correct either way.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.