fix(cli): prevent truncate helpers from overflowing at small widths#11876
fix(cli): prevent truncate helpers from overflowing at small widths#11876Tamsi wants to merge 1 commit into
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge This update wraps the existing fix in Note: No changeset was added yet. This still fixes a user-visible TUI overflow bug ( Files Reviewed (2 files)
Previous Review Summary (commit b8b90ee)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit b8b90ee)Status: No Issues Found | Recommendation: Merge Note: No changeset was added. This fixes a user-visible TUI overflow bug ( Files Reviewed (2 files)
Reviewed by claude-sonnet-5-20260630 · Input: 32 · Output: 6.6K · Cached: 627.5K Review guidance: REVIEW.md from base branch |
`truncateLeft` and `truncateMiddle` build their tail with `str.slice(-keep)`. When `keep` is 0 — which happens at `maxLength` 1 (both) and 2 (middle) — `str.slice(-0)` is `str.slice(0)` and returns the *entire* string, so the "truncated" result is longer than the input instead of shorter. These helpers are called from TUI components with dynamic widths that reach 1 (e.g. `dialog-select.tsx` uses `Math.max(1, …)`), so a narrow pane could emit a value far wider than the available space and blow out the layout. Drop the tail explicitly when `keep <= 0`. The shared-file edits are wrapped in `kilocode_change` markers; the regression test lives under `test/kilocode/`.
b8b90ee to
27b9698
Compare
Summary
Locale.truncateLeftandLocale.truncateMiddle(packages/opencode/src/util/locale.ts) build their tail slice withstr.slice(-keep). Whenkeepis0,str.slice(-0)evaluates tostr.slice(0)and returns the entire string — so instead of truncating, the helper returns something longer than the input:keepreaches0atmaxLength1 for both helpers, and atmaxLength2 fortruncateMiddle.These aren't purely theoretical widths — the TUI calls these helpers with dynamic widths that bottom out at 1, e.g.
dialog-select.tsx:On a very narrow pane the "truncated" string is emitted at full length and blows out the layout it was supposed to fit.
Fix
Drop the tail explicitly when
keep <= 0(so the result is just head + ellipsis, or a lone ellipsis at width 1), leaving all larger-width behavior unchanged.locale.tsis a shared upstream (OpenCode) file, so the edits are wrapped inkilocode_changemarkers perAGENTS.md, andbun run script/check-opencode-annotations.tspasses. The regression test lives underpackages/opencode/test/kilocode/(Kilo-specific test path).Test plan
packages/opencode/test/kilocode/locale.test.tscovering the length-1 / length-2 edges and asserting the output never exceedsmaxLength.mainwithout the fix (5 failed — e.g.truncateMiddle(long, 2)returned"s…src/components/very-long-file-name.tsx"instead of"s…").bun run script/check-opencode-annotations.ts→ "All shared upstream changes are annotated with kilocode_change markers."