From 1b912a5d918b7b3b657cc5ab75a36a77e039bf1c Mon Sep 17 00:00:00 2001 From: agent-core-bot Date: Sun, 26 Apr 2026 14:56:27 +0000 Subject: [PATCH] chore: sync core lib and CLAUDE.md from agent-core --- lib/cross-platform/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/cross-platform/index.js b/lib/cross-platform/index.js index 78d002b..e72ea5f 100644 --- a/lib/cross-platform/index.js +++ b/lib/cross-platform/index.js @@ -303,15 +303,21 @@ function formatSection(title, content) { */ /** - * Truncate text to limit with ellipsis + * Truncate text to limit with ellipsis. + * + * Slices on Unicode code points (not UTF-16 code units) so multi-byte + * chars like emoji never end up as orphan surrogates. Non-positive + * maxLength returns the original string unchanged. * * @param {string} text - Text to truncate - * @param {number} maxLength - Maximum length + * @param {number} maxLength - Maximum length (in code points) * @returns {string} Truncated text */ function truncate(text, maxLength) { - if (text.length <= maxLength) return text; - return text.substring(0, maxLength - 3) + '...'; + if (maxLength <= 0) return text; + const codePoints = [...text]; + if (codePoints.length <= maxLength) return text; + return codePoints.slice(0, maxLength - 3).join('') + '...'; } /**