nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] /expand rows still break when an emoji or CJK text sits at the cut point

Open theluckystrike opened this issue 1 month ago • 2 comments

Description

Bare /expand still breaks two kinds of row after #1543. The cut in summarizeToolCall counts UTF-16 code units, but the room it's given is a number of terminal columns.

An emoji at the cut point gets split in half. The row keeps the lone high surrogate, and the terminal prints a replacement character right before the ellipsis.

CJK text isn't cut when it should be. Each ideograph counts as 1 toward the room but takes 2 columns, so a 30 unit path fills 52 columns and the row wraps, leaving the path alone at column 0.

Environment

  • OS: macOS 26.6.2
  • Node version: v22.23.2
  • Nanocoder version: main at d57e5c1 (package.json 1.31.0), first seen on 8c50d68
  • Provider: any, since the bug is in how /expand renders recorded tool results and no provider call is involved
  • Model: any, for the same reason

Steps to Reproduce

  1. On main, set process.stdout.columns to 60.

  2. Record two read_file results with the paths below, the way expand.spec.ts does with recordExpandableToolResult.

  3. Run bare /expand and render the element it returns.

`notes/${'a'.repeat(27)}\u{1F680}-launch.md`
`docs/${'部署说明文档'.repeat(3)}更新日志.md`

Expected Behavior

Each row stays on one line inside the box. Row 1 ends in the ellipsis right after the last whole character, and row 2 is cut to fit the 50 columns of text room.

Actual Behavior

Row 1 keeps a lone high surrogate before the ellipsis. The terminal prints a replacement character there, and the row fails String.prototype.isWellFormed(). Row 2 isn't cut at all. It's 67 columns wide in a box with 50 columns of text room, so it wraps and the path starts at column 0.

Logs/Screenshots

  1  read_file notes/aaaaaaaaaaaaaaaaaaaaaaaaaaa�…
  2  read_file
docs/部署说明文档部署说明文档部署说明文档更新日志.md

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder

I reproduced it again today on main at d57e5c1, which is ahead of the 1.31.0 release. The fix is small. summarizeToolCall in source/commands/expand.ts would cut with cli-truncate, the way the shared truncate helper in useTerminalWidth.tsx has done since #1542, so the budget is counted in columns and an emoji or ideograph never gets split. I'd add a test that renders both rows above at 60 columns and checks each one stays on a single line.

Thank you, Michael Lip Founder of https://zovo.one, 108 Chrome extensions with 150,000+ users Also building https://makeroll.com and https://ml0x.com, open-source guardrails for Claude Code agents Open source has to win, and small fixes like this one are my part of it

theluckystrike avatar Oct 11 '26 09:10 theluckystrike

Assigning this to you, @theluckystrike. Before you open a PR, please edit the description to follow our bug report template: add the Environment section (OS, Node, Nanocoder version, provider, model), numbered Steps to Reproduce, separate Expected/Actual Behavior, and the checklist.

addyCooks avatar Oct 12 '26 07:10 addyCooks

@addyCooks, thanks for assigning it. I've rewritten the description to follow the bug report template, with the Environment section, numbered steps, separate Expected and Actual Behavior, and the checklist. Before ticking the boxes I reproduced it again on main at d57e5c1.

The fix is up in #1712. It cuts each row with cli-truncate so the room is counted in columns, and a new test renders both rows at 60 columns.

Thank you, Michael Lip Founder of https://zovo.one, 108 Chrome extensions with 150,000+ users Also building https://makeroll.com and https://ml0x.com, open-source guardrails for Claude Code agents Open source has to win, and small fixes like this one are my part of it

theluckystrike avatar Oct 12 '26 09:10 theluckystrike