fix(commands): truncate session label by rune count, not byte count

Prevents splitting multi-byte UTF-8 characters (CJK, emoji) when
truncating session preview text in /session list output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
mingmxren 2026-03-05 22:10:46 +08:00
parent c917184375
commit e0e2cb0724

View file

@ -109,10 +109,11 @@ func sessionLabel(summary, preview string, maxLen int) string {
return "(empty)" return "(empty)"
} }
text = strings.ReplaceAll(text, "\n", " ") text = strings.ReplaceAll(text, "\n", " ")
if len(text) <= maxLen { runes := []rune(text)
if len(runes) <= maxLen {
return text return text
} }
return text[:maxLen] + "..." return string(runes[:maxLen]) + "..."
} }
// extractSessionTag returns the "#N" suffix from a session key, or "#1" for // extractSessionTag returns the "#N" suffix from a session key, or "#1" for