惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
B
Blog
腾讯CDC
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - Franky
罗磊的独立博客
月光博客
月光博客
Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
Docker
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
V
Visual Studio Blog
I
InfoQ
有赞技术团队
有赞技术团队
D
DataBreaches.Net
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
Blog — PlanetScale
Blog — PlanetScale

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(discord): split CJK text at safe break points (#73960...
openclaw-clo · 2026-04-29 · via Recent Commits to openclaw:main

@@ -22,6 +22,7 @@ type OpenFence = {

2222

const DEFAULT_MAX_CHARS = 2000;

2323

const DEFAULT_MAX_LINES = 17;

2424

const FENCE_RE = /^( {0,3})(`{3,}|~{3,})(.*)$/;

25+

const CJK_PUNCTUATION_BREAK_AFTER_RE = /[]/u;

25262627

function countLines(text: string) {

2728

if (!text) {

@@ -63,6 +64,51 @@ function closeFenceIfNeeded(text: string, openFence: OpenFence | null) {

6364

return `${text}${closeLine}`;

6465

}

656667+

function isHighSurrogate(code: number) {

68+

return code >= 0xd800 && code <= 0xdbff;

69+

}

70+71+

function isLowSurrogate(code: number) {

72+

return code >= 0xdc00 && code <= 0xdfff;

73+

}

74+75+

function clampToCodePointBoundary(text: string, index: number) {

76+

const boundary = Math.min(Math.max(0, index), text.length);

77+

if (boundary <= 0 || boundary >= text.length) {

78+

return boundary;

79+

}

80+

const previous = text.charCodeAt(boundary - 1);

81+

const next = text.charCodeAt(boundary);

82+

if (isHighSurrogate(previous) && isLowSurrogate(next)) {

83+

return boundary > 1 ? boundary - 1 : boundary + 1;

84+

}

85+

return boundary;

86+

}

87+88+

function findWhitespaceBreak(window: string) {

89+

for (let i = window.length - 1; i >= 0; i--) {

90+

if (/\s/.test(window[i])) {

91+

// Return the separator index so whitespace stays with the next segment.

92+

return i;

93+

}

94+

}

95+

return -1;

96+

}

97+98+

function findCjkPunctuationBreak(window: string) {

99+

for (let end = window.length; end > 0; ) {

100+

const code = window.charCodeAt(end - 1);

101+

const start = isLowSurrogate(code) && end > 1 ? end - 2 : end - 1;

102+

const char = window.slice(start, end);

103+

if (start > 0 && CJK_PUNCTUATION_BREAK_AFTER_RE.test(char)) {

104+

// Return the exclusive end so CJK punctuation stays with the current segment.

105+

return end;

106+

}

107+

end = start;

108+

}

109+

return -1;

110+

}

111+66112

function splitLongLine(

67113

line: string,

68114

maxChars: number,

@@ -76,20 +122,18 @@ function splitLongLine(

76122

let remaining = line;

77123

while (remaining.length > limit) {

78124

if (opts.preserveWhitespace) {

79-

out.push(remaining.slice(0, limit));

80-

remaining = remaining.slice(limit);

125+

const breakIdx = clampToCodePointBoundary(remaining, limit);

126+

out.push(remaining.slice(0, breakIdx));

127+

remaining = remaining.slice(breakIdx);

81128

continue;

82129

}

83130

const window = remaining.slice(0, limit);

84-

let breakIdx = -1;

85-

for (let i = window.length - 1; i >= 0; i--) {

86-

if (/\s/.test(window[i])) {

87-

breakIdx = i;

88-

break;

89-

}

131+

let breakIdx = findWhitespaceBreak(window);

132+

if (breakIdx <= 0) {

133+

breakIdx = findCjkPunctuationBreak(window);

90134

}

91135

if (breakIdx <= 0) {

92-

breakIdx = limit;

136+

breakIdx = clampToCodePointBoundary(remaining, limit);

93137

}

94138

out.push(remaining.slice(0, breakIdx));

95139

// Keep the separator for the next segment so words don't get glued together.