Files
adnaan a5b161f047 fix(tools): stop truncation from splitting surrogate pairs
truncateToolResult sliced by UTF-16 code unit, so a non-BMP character
(emoji, CJK ext) straddling the head/tail boundary was cut in half. The
lone surrogate rendered as U+FFFD and went verbatim into the tool message
sent to the model - one of the ways a tool result turns into garbage.

Added surrogate-safe sliceHead/sliceTailFrom and routed the two
line-boundary helpers through them. Proven against the pre-fix code: the
mixed ASCII+emoji case fails at pad=1, where parity puts headSize
exactly mid-pair.
2026-08-21 12:01:26 +08:00
..