Skip to content

Commit f891b41

Browse files
added 内容被截断
1 parent 9042d01 commit f891b41

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/bin/cratedocs.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,15 @@ async fn run_test_tool(config: TestToolConfig) -> Result<()> {
348348
if let Some(max_tokens) = max_tokens {
349349
match cratedocs_mcp::tools::count_tokens(&content_str) {
350350
Ok(token_count) if token_count > max_tokens => {
351-
// 🦨 skunky: This truncates by character, not token boundary. For true token-aware truncation, split and re-encode.
351+
// Truncate by character, then to previous word boundary, and append Mandarin to indicate truncation.
352352
let mut truncated = content_str.clone();
353353
while cratedocs_mcp::tools::count_tokens(&truncated).map_or(0, |c| c) > max_tokens && !truncated.is_empty() {
354354
truncated.pop();
355355
}
356+
if let Some(last_space) = truncated.rfind(' ') {
357+
truncated.truncate(last_space);
358+
}
359+
truncated.push_str(" 内容被截断");
356360
content_str = truncated;
357361
}
358362
_ => {}

0 commit comments

Comments
 (0)