File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed
Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff 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 _ => { }
You can’t perform that action at this time.
0 commit comments