Skip to content

fix(tui): handle invisible codepoints when measuring label width#31880

Open
keypaa wants to merge 1 commit into
anomalyco:devfrom
keypaa:fix-tui-label-width
Open

fix(tui): handle invisible codepoints when measuring label width#31880
keypaa wants to merge 1 commit into
anomalyco:devfrom
keypaa:fix-tui-label-width

Conversation

@keypaa

@keypaa keypaa commented Jun 11, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #23376

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The TUI truncation functions (\ runcate, \ runcateLeft, \ runcateMiddle) in \packages/tui/src/util/locale.ts\ used \str.length\ to measure string width and iterate characters. This counts zero-width codepoints (U+200B ZWSP, U+200C ZWNJ, U+200D ZWJ, U+FEFF BOM) as having column width 1, which causes the last visible character to be eaten when the renderer tries to fit the string.

The fix replaces both width measurement and character iteration with \Bun.stringWidth(), which correctly reports 0 columns for zero-width codepoints and 2 columns for wide graphemes like CJK/emoji — matching the Unicode character-width specification.

The three affected functions are used by the TUI Label component to truncate agent names and other display strings.

How did you verify your code works?

Added \packages/tui/src/util/locale.test.ts\ with 16 test cases covering:

  • Plain ASCII truncation (unchanged behavior)
  • U+200B-prefixed strings at exact width boundary (not truncated)
  • U+200B-prefixed strings exceeding limit (truncated at visible boundary only)
  • All four zero-width codepoint variants (U+200B, U+200C, U+200D, U+FEFF)
  • Mixed CJK + ZWSP + ASCII strings
  • \ runcateLeft\ and \ runcateMiddle\ variants

All 13 tests pass via \�un test\ from the packages/tui directory.

Screenshots / recordings

N/A — this is a utility-level width calculation fix. The visual effect is that agent names and labels containing invisible width characters are no longer truncated prematurely.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Jun 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

bug(tui): agent label rendering corrupts when name contains invisible Unicode codepoints

1 participant