fix(text): avoid breaking UTF-8 during truncation

Use rune-aware truncation for user-facing text and log previews so multibyte content is not corrupted in memory context, Telegram messages, or diagnostics.
This commit is contained in:
BBQ
2026-03-08 16:29:38 +08:00
committed by Ran
parent 09cdb8c87f
commit 3739def43f
8 changed files with 131 additions and 30 deletions
+2 -4
View File
@@ -28,6 +28,7 @@ import (
"github.com/memohai/memoh/internal/models"
"github.com/memohai/memoh/internal/schedule"
"github.com/memohai/memoh/internal/settings"
"github.com/memohai/memoh/internal/textutil"
)
const (
@@ -1972,10 +1973,7 @@ func nonNilModelMessages(m []conversation.ModelMessage) []conversation.ModelMess
}
func truncate(s string, n int) string {
if len(s) <= n {
return s
}
return s[:n] + "..."
return textutil.TruncateRunesWithSuffix(s, n, "...")
}
func parseResolverUUID(id string) (pgtype.UUID, error) {