@@ -219,19 +219,10 @@ async def edit_file_contents(
219
219
Args:
220
220
file_path (str): Path to the file to edit
221
221
expected_hash (str): Expected hash of the file before editing
222
- patches (List[EditPatch]): List of patches to apply
223
- - start (int): Starting line number (1-based, optional, default: 1)
224
- - end (Optional[int]): Ending line number (inclusive)
225
- - contents (str): New content to insert
226
- Edit file contents with hash-based conflict detection and multiple patches (supporting new file creation).
227
-
228
- Args:
229
- file_path (str): Path to the file to edit (parent directories are created automatically)
230
- expected_hash (str): Expected hash of the file before editing (empty string for new files)
231
222
patches (List[Dict[str, Any]]): List of patches to apply, each containing:
232
223
- start (int): Starting line number (1-based)
233
224
- end (Optional[int]): Ending line number (inclusive)
234
- - contents (str): New content to insert
225
+ - contents (str): New content to insert (if empty string, consider using delete_text_file_contents instead)
235
226
- range_hash (str): Expected hash of the content being replaced
236
227
237
228
Returns:
@@ -269,9 +260,14 @@ async def edit_file_contents(
269
260
encoding = "utf-8"
270
261
else :
271
262
# Read current file content and verify hash
272
- current_content , _ , _ , current_hash , total_lines , _ = (
273
- await self .read_file_contents (file_path , encoding = encoding )
274
- )
263
+ (
264
+ current_content ,
265
+ _ ,
266
+ _ ,
267
+ current_hash ,
268
+ total_lines ,
269
+ _ ,
270
+ ) = await self .read_file_contents (file_path , encoding = encoding )
275
271
276
272
# Treat empty file as new file
277
273
if not current_content :
@@ -396,6 +392,15 @@ async def edit_file_contents(
396
392
else :
397
393
contents = patch ["contents" ]
398
394
395
+ # Check if this is a deletion (empty content)
396
+ if not contents .strip ():
397
+ return {
398
+ "result" : "ok" ,
399
+ "file_hash" : current_hash , # Return current hash since no changes made
400
+ "hint" : "For content deletion, please consider using delete_text_file_contents instead of patch with empty content" ,
401
+ "suggestion" : "delete" ,
402
+ }
403
+
399
404
new_content = contents if contents .endswith ("\n " ) else contents + "\n "
400
405
new_lines = new_content .splitlines (keepends = True )
401
406
@@ -471,11 +476,16 @@ async def insert_text_file_contents(
471
476
}
472
477
473
478
try :
474
- current_content , _ , _ , current_hash , total_lines , _ = (
475
- await self .read_file_contents (
476
- file_path ,
477
- encoding = encoding ,
478
- )
479
+ (
480
+ current_content ,
481
+ _ ,
482
+ _ ,
483
+ current_hash ,
484
+ total_lines ,
485
+ _ ,
486
+ ) = await self .read_file_contents (
487
+ file_path ,
488
+ encoding = encoding ,
479
489
)
480
490
481
491
if current_hash != file_hash :
@@ -563,11 +573,16 @@ async def delete_text_file_contents(
563
573
self ._validate_file_path (request .file_path )
564
574
565
575
try :
566
- current_content , _ , _ , current_hash , total_lines , _ = (
567
- await self .read_file_contents (
568
- request .file_path ,
569
- encoding = request .encoding or "utf-8" ,
570
- )
576
+ (
577
+ current_content ,
578
+ _ ,
579
+ _ ,
580
+ current_hash ,
581
+ total_lines ,
582
+ _ ,
583
+ ) = await self .read_file_contents (
584
+ request .file_path ,
585
+ encoding = request .encoding or "utf-8" ,
571
586
)
572
587
573
588
# Check for conflicts
0 commit comments