@@ -25,7 +25,7 @@ async function validateParams(
2525 relPath : string | undefined ,
2626 search : string | undefined ,
2727 replace : string | undefined ,
28- pushToolResult : PushToolResult
28+ pushToolResult : PushToolResult ,
2929) : Promise < boolean > {
3030 if ( ! relPath ) {
3131 cline . consecutiveMistakeCount ++
@@ -77,22 +77,20 @@ export async function searchAndReplaceTool(
7777 const startLine : number | undefined = block . params . start_line ? parseInt ( block . params . start_line , 10 ) : undefined
7878 const endLine : number | undefined = block . params . end_line ? parseInt ( block . params . end_line , 10 ) : undefined
7979
80- const sharedMessageProps : ClineSayTool = {
81- tool : "appliedDiff" ,
82- path : getReadablePath ( cline . cwd , removeClosingTag ( "path" , relPath ) ) ,
83- }
84-
8580 try {
8681 // Handle partial tool use
8782 if ( block . partial ) {
88- const partialMessage = JSON . stringify ( {
89- ...sharedMessageProps ,
90- search,
91- replace,
92- use_regex : block . params . use_regex ?? "false" ,
93- ignore_case : block . params . ignore_case ?? "false" ,
94- } )
95- await cline . ask ( "tool" , partialMessage , block . partial ) . catch ( ( ) => { } )
83+ const partialMessageProps = {
84+ tool : "searchAndReplace" as const ,
85+ path : getReadablePath ( cline . cwd , removeClosingTag ( "path" , relPath ) ) ,
86+ search : removeClosingTag ( "search" , search ) ,
87+ replace : removeClosingTag ( "replace" , replace ) ,
88+ useRegex : block . params . use_regex === "true" ,
89+ ignoreCase : block . params . ignore_case === "true" ,
90+ startLine,
91+ endLine,
92+ }
93+ await cline . ask ( "tool" , JSON . stringify ( partialMessageProps ) , block . partial ) . catch ( ( ) => { } )
9694 return
9795 }
9896
@@ -106,14 +104,25 @@ export async function searchAndReplaceTool(
106104 const validSearch = search as string
107105 const validReplace = replace as string
108106
107+ const sharedMessageProps : ClineSayTool = {
108+ tool : "searchAndReplace" ,
109+ path : getReadablePath ( cline . cwd , validRelPath ) ,
110+ search : validSearch ,
111+ replace : validReplace ,
112+ useRegex : useRegex ,
113+ ignoreCase : ignoreCase ,
114+ startLine : startLine ,
115+ endLine : endLine ,
116+ }
117+
109118 const absolutePath = path . resolve ( cline . cwd , validRelPath )
110119 const fileExists = await fileExistsAtPath ( absolutePath )
111120
112121 if ( ! fileExists ) {
113122 cline . consecutiveMistakeCount ++
114123 cline . recordToolError ( "search_and_replace" )
115124 const formattedError = formatResponse . toolError (
116- `File does not exist at path: ${ absolutePath } \nThe specified file could not be found. Please verify the file path and try again.`
125+ `File does not exist at path: ${ absolutePath } \nThe specified file could not be found. Please verify the file path and try again.` ,
117126 )
118127 await cline . say ( "error" , formattedError )
119128 pushToolResult ( formattedError )
@@ -138,15 +147,15 @@ export async function searchAndReplaceTool(
138147 pushToolResult ( formattedError )
139148 return
140149 }
141-
150+
142151 // Create search pattern and perform replacement
143152 const flags = ignoreCase ? "gi" : "g"
144153 const searchPattern = useRegex ? new RegExp ( validSearch , flags ) : new RegExp ( escapeRegExp ( validSearch ) , flags )
145-
154+
146155 let newContent : string
147156 if ( startLine !== undefined || endLine !== undefined ) {
148157 // Handle line-specific replacement
149- const lines = fileContent . split ( '\n' )
158+ const lines = fileContent . split ( "\n" )
150159 const start = Math . max ( ( startLine ?? 1 ) - 1 , 0 )
151160 const end = Math . min ( ( endLine ?? lines . length ) - 1 , lines . length - 1 )
152161
@@ -155,12 +164,12 @@ export async function searchAndReplaceTool(
155164 const afterLines = lines . slice ( end + 1 )
156165
157166 // Get and modify target section
158- const targetContent = lines . slice ( start , end + 1 ) . join ( '\n' )
167+ const targetContent = lines . slice ( start , end + 1 ) . join ( "\n" )
159168 const modifiedContent = targetContent . replace ( searchPattern , validReplace )
160- const modifiedLines = modifiedContent . split ( '\n' )
169+ const modifiedLines = modifiedContent . split ( "\n" )
161170
162171 // Reconstruct full content
163- newContent = [ ...beforeLines , ...modifiedLines , ...afterLines ] . join ( '\n' )
172+ newContent = [ ...beforeLines , ...modifiedLines , ...afterLines ] . join ( "\n" )
164173 } else {
165174 // Global replacement
166175 newContent = fileContent . replace ( searchPattern , validReplace )
0 commit comments