Repository navigation
fix(tui): pad autocomplete rows by display width, not byte length - #1256
Merged
Merged
Conversation
TruncateText cuts to display columns (ansi.Truncate), but renderItems padded
the result with len() - bytes. Any description holding one multibyte rune
comes back longer in bytes than the column budget, so
strings.Repeat(" ", descWidth-len(description))
got a negative count and panicked the whole TUI the moment "/" was typed.
The contract flipped from bytes to columns in #667 without updating this
caller, and stayed dormant until the skills catalog shipped motion-graphics,
its first entry with a non-ASCII description (em dash, arrow).
Add formatting.PadText, which truncates and pads in the same unit, and route
both autocomplete columns through it. Measure the shortcut column budget with
ansi.StringWidth for the same reason. Guard the two task-manager separators
with the getSeparatorWidth helper that already existed for exactly this - one
copy was missing it, the other inlined a duplicate.
edenreich
commented
Sep 20, 2026
Contributor
|
🎉 This PR is included in version 0.205.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The crash
infer chatpanics and tears down the TUI the moment/is typed:Root cause — bytes used as display columns
formatting.TruncateTextcuts to display columns (ansi.StringWidth/ansi.Truncate), butrenderItemspadded the result withlen()— bytes:One multibyte rune in a description long enough to be truncated pushes
len()past the column budget and the count goes negative.Reproduced with the exact values from the trace: at a 214-column terminal
descWidth = 214 - 28 - 7 = 179(the0xb3). Themotion-graphicsskill description truncated to 179 columns is 181 bytes →strings.Repeat(" ", -2).Why it surfaced now
The code was correct until the contract changed under it:
TruncateTextfromlen(text) <= maxLength(bytes) toansi.StringWidth(columns) — this caller was not touched, and its padding silently became wronginference-gateway/skills#132addsmotion-graphics— the only one of 25 catalog entries with a non-ASCII description (—U+2014,→U+2192)Before #667
len(truncated) <= maxLengthwas guaranteed, so the subtraction could never go negative. Nothing in the CLI changed in September; the catalog data did.The fix
One helper beside the function whose contract caused it, so truncation and padding always happen in the same unit:
autocomplete.go— both columns route throughPadText;calculateMaxShortcutWidthmeasures withansi.StringWidthinstead oflen.task_management_view.go— the two separators now use thegetSeparatorWidth()guard that already existed for exactly this case (strings.Repeat("─", t.width-4)panics below 4 columns, andt.widthis 0 until the firstWindowSizeMsg). One copy had no guard; the other inlined a duplicate of it, now deleted.lipgloss.NewStyle().Width(n)was considered and rejected — it wraps overflow instead of truncating, which would turn one table row into several.Tests
TestPadText— table-driven, assertsansi.StringWidth(got) == widthand valid UTF-8 across narrow-multibyte, wide-rune and ASCII inputs.TestAutocomplete_RenderMultibyteDescription— feeds the real failing shape at 214/60/20 columns and asserts the rows stay column-aligned.Verified the regression test earns its keep: reverting just the two pad lines makes it panic with the identical
strings: negative Repeat count; restoring the fix passes.Checks
task precommit:run— 0 issuesgo test ./internal/presentation/... ./internal/platform/...— greenNotes
No docs ticket: bug fix, no public surface change. No cross-repo impact — the trigger data lives in
inference-gateway/skills, but nothing there needs changing.Found during the sweep, left for separate PRs:
task_management_view.go:1116-1152pads with%-38s(rune count) against a column budget — misalignment only, no panic.agent/infrastructure/formatter.go:258still does a rawtext[:maxLength-3]byte slice and emits invalid UTF-8 on multibyte input; its own test documents this atformatter_units_test.go:86.