chore: sync core lib and CLAUDE.md from agent-core#21
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 20b876a. Configure here.
| if (maxLength <= 0) return text; | ||
| const codePoints = [...text]; | ||
| if (codePoints.length <= maxLength) return text; | ||
| return codePoints.slice(0, maxLength - 3).join('') + '...'; |
There was a problem hiding this comment.
Negative slice index produces longer-than-original output
Medium Severity
When maxLength is 1 or 2, the expression maxLength - 3 becomes negative. Array.prototype.slice interprets a negative second argument as an offset from the end of the array, so it returns most of the array rather than an empty prefix. The resulting "truncated" string can be significantly longer than the input — the opposite of the function's purpose. The old code using substring didn't have this problem because substring clamps negatives to 0.
Reviewed by Cursor Bugbot for commit 20b876a. Configure here.


Automated sync of lib/ and CLAUDE.md from agent-core.
Note
Low Risk
Low risk utility change, but it alters
truncatesemantics (code-point counting andmaxLength<=0behavior) which could slightly change truncated output in consumers.Overview
Updates
truncateinlib/cross-platform/index.jsto truncate by Unicode code points (via spreading into an array) instead of UTF-16 code units, preventing broken surrogate pairs (e.g., emoji) in truncated strings.Also changes edge-case handling so non-positive
maxLengthreturns the original text unchanged, and clarifies the JSDoc to document code-point length semantics.Reviewed by Cursor Bugbot for commit 20b876a. Configure here.