package tools import "unicode/utf8" // truncateUTF8 returns s truncated to at most maxBytes, backing off to the last // complete UTF-8 rune boundary so a multibyte rune (CJK, emoji, …) is never // split — a byte-boundary cut would hand the LLM invalid UTF-8 / replacement // chars. Used by the meta tools' input caps. func truncateUTF8(s string, maxBytes int) string { if len(s) <= maxBytes { return s } s = s[:maxBytes] for len(s) > 0 && !utf8.ValidString(s) { s = s[:len(s)-1] } return s }