Skip to content

fix(tui): stop ANSI escape leaks + drop redundant update_plan cards - #316

Merged
gnanam1990 merged 1 commit into
mainfrom
fix/tui-chat-clarity-render
Jun 25, 2026
Merged

fix(tui): stop ANSI escape leaks + drop redundant update_plan cards#316
gnanam1990 merged 1 commit into
mainfrom
fix/tui-chat-clarity-render

Conversation

@Vasanthdev2004

@Vasanthdev2004 Vasanthdev2004 commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

What

Two chat-clarity fixes from comparing Zero's output to a reference agent on a "build a website" task.

1. ANSI escape garbage in the final answer 🐛

The final text was leaking raw, truncated terminal color codes as literal characters next to code blocks:

[1;4;38;2;236;
[38;2;236;236;238m    [m[38;2;

Root cause: styleAssistantMarkdownLine treated already-styled input (syntax-highlighted code, headings, tables — which carry real ANSI) byte-by-byte as runes and re-wrapped the whole line in another base.Render. That doubled the SGR density, and a downstream width-truncation then sliced mid-escape, dropping the leading ESC and printing the leftover ([38;2;…) as text. Only styled segments were affected — plain prose has no embedded escapes to split.

Fix: real escape sequences now pass through verbatim (using the existing ansiSequenceEnd helper, exactly like truncateStyledLine); the synthetic bold markers are still matched first so their style switch is preserved. ~14 lines.

2. Redundant update_plan tool cards 🧹

The plan is already shown in two places — the pinned plan panel above the composer and the PLAN sidebar — so rendering every update_plan call as its own transcript card was pure duplication (it stacked 3× in the demo). Generalized the existing Task-card skip into toolCardSuppressedInTranscript and now skip update_plan's call+result rows too. The plan-panel sync and session events are unchanged.

Tests

  • TestStyleAssistantMarkdownLinePassesAnsiVerbatim — proves already-styled input passes through verbatim; verified it fails before the fix (output re-wraps the input escape inside base's \x1b[1m).
  • TestToolCardSuppressedInTranscriptTask/update_plan suppressed, everything else still shown.
  • Full ./internal/tui/... suite green; build + gofmt clean.

Part of a series

This is 1 of 3 from the chat-clarity comparison. Follow-ups: diff/code preview on write/edit cards (the render half + go-udiff already exist), and a system-prompt preamble so the agent briefly states its approach. Independent PRs.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Markdown styling in the TUI so pre-styled text with ANSI colors renders correctly without broken or duplicated formatting.
    • Reduced duplicate transcript entries by hiding tool cards that are already shown in other parts of the interface, including plan-related and specialist activity.

Two chat-clarity fixes surfaced by comparing Zero's output to a reference
agent on a "build a website" task.

1. ANSI escape garbage in the final answer. styleAssistantMarkdownLine
   treated already-styled input (syntax-highlighted code, headings, tables —
   which carry real ANSI) byte-by-byte as runes and re-wrapped the whole line
   in another base.Render. That doubled the SGR density and let a downstream
   width-truncation slice mid-escape, leaking "[38;2;…" / "[1;4;…" fragments
   as literal text next to code blocks. Now real escape sequences pass through
   verbatim (via the existing ansiSequenceEnd helper, like truncateStyledLine);
   the synthetic bold markers are still matched first so their style switch is
   kept. Only styled segments were affected — plain prose never had embedded
   escapes to split.

2. Redundant update_plan tool cards. The plan is already shown in the pinned
   plan panel AND the PLAN sidebar, so rendering each update_plan call as its
   own transcript card was pure duplication (it stacked 3x in the demo).
   Generalize the existing Task-card skip into toolCardSuppressedInTranscript
   and skip update_plan's call+result rows too; the plan-panel sync and session
   events are unchanged.

Tests: TestStyleAssistantMarkdownLinePassesAnsiVerbatim (fails before the fix),
TestToolCardSuppressedInTranscript.
@github-actions

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Tests: go test ./...
  • [pass] Build: go run ./cmd/zero-release build
  • [pass] Smoke build: go run ./cmd/zero-release smoke

Scope

Head: aa3aa4ba8db4
Changed files (3): internal/tui/assistant_markdown.go, internal/tui/model.go, internal/tui/rendering_lime_test.go

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 635b26c1-5244-4179-8f4a-17b74740c30f

📥 Commits

Reviewing files that changed from the base of the PR and between 46c44a8 and aa3aa4b.

📒 Files selected for processing (3)
  • internal/tui/assistant_markdown.go
  • internal/tui/model.go
  • internal/tui/rendering_lime_test.go

Walkthrough

This PR preserves ANSI escape sequences in assistant markdown rendering and centralizes transcript-card suppression for Task and update_plan tool events, with regression tests covering both behaviors.

Changes

ANSI assistant markdown styling

Layer / File(s) Summary
ANSI escape passthrough
internal/tui/assistant_markdown.go, internal/tui/rendering_lime_test.go
styleAssistantMarkdownLine now writes detected ANSI escape sequences verbatim after flushing buffered text, and the regression test checks ANSI token and reset preservation.

Tool transcript suppression

Layer / File(s) Summary
Transcript suppression helper
internal/tui/model.go, internal/tui/rendering_lime_test.go
toolCardSuppressedInTranscript returns true for Task and update_plan, and both tool-call and tool-result transcript rows use it before emitting cards.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

  • Gitlawb/zero#187: Modifies internal/tui/assistant_markdown.go, the same styling path extended here to pass ANSI escape sequences through verbatim.
  • Gitlawb/zero#83: Touches internal/tui/model.go tool transcript handling, which this PR updates to suppress Task and update_plan cards.

Suggested reviewers

  • gnanam1990
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes both main changes: ANSI escape passthrough fixes and redundant update_plan transcript card removal.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@gnanam1990
gnanam1990 merged commit 01fed03 into main Jun 25, 2026
7 checks passed
@Vasanthdev2004
Vasanthdev2004 deleted the fix/tui-chat-clarity-render branch June 28, 2026 08:27
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.

2 participants