Skip to content

fix(tui): sanitize foreground Bash tool output - #2919

Open
nhatduy227 wants to merge 1 commit into
MoonshotAI:mainfrom
nhatduy227:fix/sanitize-foreground-bash-output
Open

fix(tui): sanitize foreground Bash tool output#2919
nhatduy227 wants to merge 1 commit into
MoonshotAI:mainfrom
nhatduy227:fix/sanitize-foreground-bash-output

Conversation

@nhatduy227

@nhatduy227 nhatduy227 commented Aug 14, 2026

Copy link
Copy Markdown

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[?1049h switches 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 matching ESC[?1049l is emitted.

sanitizeShellOutput already guards ! shell mode and the background task views (#2863), but not the tool-call card.

What changed

Sanitize result.output in ShellExecutionComponent before styling. This single site covers both the accumulated live stdout/stderr and the final Bash result, since buildLiveOutputBlock renders live output through the same component.

Scoped to ShellExecutionComponent rather than TruncatedOutputComponent, which is the default result renderer and would change generic and MCP tool rendering too.

Includes a patch changeset for @moonshot-ai/kimi-code.

Verification

  • vitest run apps/kimi-code/test/tui/ (139 files, 1956 passed, 3 skipped)
  • pnpm --filter @moonshot-ai/kimi-code run typecheck
  • oxlint apps/kimi-code/src/tui/components/messages/shell-execution.ts (0 warnings, 0 errors)
  • Sanitizer cost at the 50k MAX_LIVE_OUTPUT_CHARS cap measured at ~0.075 ms on escape-heavy input.

@changeset-bot

changeset-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cec058a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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.
@nhatduy227
nhatduy227 force-pushed the fix/sanitize-foreground-bash-output branch from 910d9ef to cec058a Compare August 14, 2026 08:17
@nhatduy227

nhatduy227 commented Aug 14, 2026

Copy link
Copy Markdown
Author

@liruifengv — tagging you since this continues #2863 (which you merged). The foreground Bash tool card still passes captured output straight to pi-tui, so ESC[?1049h from command output flips the host terminal to the alternate screen and takes tmux scrollback with it.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Foreground Bash tool output renders raw terminal escape sequences (breaks tmux scrollback)

1 participant