11import * as fs from "fs-extra" ;
22import * as path from "path" ;
3+ import { writeFile as writeFilePromise } from "fs/promises" ;
34import { ToolResult , EditorCommand } from "../types/index.js" ;
45import { ConfirmationService } from "../utils/confirmation-service.js" ;
56
@@ -134,10 +135,10 @@ export class TextEditorTool {
134135 }
135136 }
136137
137- const newContent = replaceAll
138+ const newContent = replaceAll
138139 ? content . split ( oldStr ) . join ( newStr )
139140 : content . replace ( oldStr , newStr ) ;
140- await fs . writeFile ( resolvedPath , newContent , "utf-8" ) ;
141+ await writeFilePromise ( resolvedPath , newContent , "utf-8" ) ;
141142
142143 this . editHistory . push ( {
143144 command : "str_replace" ,
@@ -201,7 +202,7 @@ export class TextEditorTool {
201202
202203 const dir = path . dirname ( resolvedPath ) ;
203204 await fs . ensureDir ( dir ) ;
204- await fs . writeFile ( resolvedPath , content , "utf-8" ) ;
205+ await writeFilePromise ( resolvedPath , content , "utf-8" ) ;
205206
206207 this . editHistory . push ( {
207208 command : "create" ,
@@ -289,8 +290,8 @@ export class TextEditorTool {
289290 const replacementLines = newContent . split ( "\n" ) ;
290291 lines . splice ( startLine - 1 , endLine - startLine + 1 , ...replacementLines ) ;
291292 const newFileContent = lines . join ( "\n" ) ;
292-
293- await fs . writeFile ( resolvedPath , newFileContent , "utf-8" ) ;
293+
294+ await writeFilePromise ( resolvedPath , newFileContent , "utf-8" ) ;
294295
295296 this . editHistory . push ( {
296297 command : "str_replace" ,
@@ -335,7 +336,7 @@ export class TextEditorTool {
335336 lines . splice ( insertLine - 1 , 0 , content ) ;
336337 const newContent = lines . join ( "\n" ) ;
337338
338- await fs . writeFile ( resolvedPath , newContent , "utf-8" ) ;
339+ await writeFilePromise ( resolvedPath , newContent , "utf-8" ) ;
339340
340341 this . editHistory . push ( {
341342 command : "insert" ,
@@ -375,7 +376,7 @@ export class TextEditorTool {
375376 lastEdit . new_str ,
376377 lastEdit . old_str
377378 ) ;
378- await fs . writeFile ( lastEdit . path , revertedContent , "utf-8" ) ;
379+ await writeFilePromise ( lastEdit . path , revertedContent , "utf-8" ) ;
379380 }
380381 break ;
381382
@@ -390,7 +391,7 @@ export class TextEditorTool {
390391 const content = await fs . readFile ( lastEdit . path , "utf-8" ) ;
391392 const lines = content . split ( "\n" ) ;
392393 lines . splice ( lastEdit . insert_line - 1 , 1 ) ;
393- await fs . writeFile ( lastEdit . path , lines . join ( "\n" ) , "utf-8" ) ;
394+ await writeFilePromise ( lastEdit . path , lines . join ( "\n" ) , "utf-8" ) ;
394395 }
395396 break ;
396397 }
0 commit comments