Description
The preview() function in src/tool/shell.ts uses text.length (UTF-16 code units) to check if output exceeds the metadata limit, but truncation should be based on byte length. This causes incorrect truncation for multi-byte characters like CJK, emoji, etc.
Additionally, text.slice(-MAX_METADATA_LENGTH) can split a surrogate pair, producing invalid UTF-16 output.
Contrast with the tail() function in the same file which correctly uses Buffer.byteLength(text, "utf-8").
Expected behavior
- Byte length should be used for truncation decisions
- Truncated output should not split multi-byte characters
Description
The
preview()function insrc/tool/shell.tsusestext.length(UTF-16 code units) to check if output exceeds the metadata limit, but truncation should be based on byte length. This causes incorrect truncation for multi-byte characters like CJK, emoji, etc.Additionally,
text.slice(-MAX_METADATA_LENGTH)can split a surrogate pair, producing invalid UTF-16 output.Contrast with the
tail()function in the same file which correctly usesBuffer.byteLength(text, "utf-8").Expected behavior