fix(util): rune-safe truncation across formatters

firstLineOf (query) and truncateString (edit) sliced strings at a raw byte
offset, splitting a multibyte UTF-8 character into invalid bytes in
LLM-facing output (ast_query compact format and edit not-found errors are
hot paths). Extract the rune-boundary backoff already used by search's
truncateLine into util.RuneBoundary and route all three sites through it.

Adds table-driven tests for the primitive and a multibyte case for firstLineOf.
This commit is contained in:
2026-06-20 00:44:38 +01:00
parent 549ec2a177
commit 3195e353e2
6 changed files with 64 additions and 8 deletions
+1 -1
View File
@@ -583,7 +583,7 @@ func firstLineOf(s string, maxLen int) string {
continue
}
if len(line) > maxLen {
return line[:maxLen-1] + "…"
return line[:util.RuneBoundary(line, maxLen-1)] + "…"
}
return line
}