@@ -10,6 +10,7 @@ import {
1010 getProjectFileTree ,
1111} from '@codebuff/common/project-file-tree'
1212import { truncateStringWithMessage } from '@codebuff/common/util/string'
13+ import { formatCodeSearchOutput } from '@codebuff/common/util/format-code-search'
1314import micromatch from 'micromatch'
1415import { cyan , green , red , yellow } from 'picocolors'
1516
@@ -371,9 +372,10 @@ export const handleCodeSearch: ToolHandler<'code_search'> = async (
371372 }
372373 }
373374
374- const previewResults = limitedLines . slice ( 0 , 3 )
375- if ( previewResults . length > 0 ) {
376- console . log ( previewResults . join ( '\n' ) )
375+ const previewResults = limitedLines . slice ( 0 , 3 ) . join ( '\n' )
376+ if ( previewResults ) {
377+ const formattedPreview = formatCodeSearchOutput ( previewResults )
378+ console . log ( formattedPreview )
377379 if ( limitedLines . length > 3 ) {
378380 console . log ( '...' )
379381 }
@@ -408,7 +410,7 @@ export const handleCodeSearch: ToolHandler<'code_search'> = async (
408410 limitedStdout += `\n\n[${ truncationMessages . join ( '\n\n' ) } ]`
409411 }
410412
411- const finalStdout = limitedStdout
413+ const finalStdout = formatCodeSearchOutput ( limitedStdout )
412414
413415 const truncatedStdout = truncateStringWithMessage ( {
414416 str : finalStdout ,
@@ -421,8 +423,7 @@ export const handleCodeSearch: ToolHandler<'code_search'> = async (
421423 const result = {
422424 stdout : truncatedStdout ,
423425 ...( truncatedStderr && { stderr : truncatedStderr } ) ,
424- ...( code !== null && { exitCode : code } ) ,
425- message : 'Code search completed' ,
426+ message : code !== null ? `Exit code: ${ code } ` : '' ,
426427 }
427428 resolve ( [
428429 {
0 commit comments