@@ -65,7 +65,7 @@ def apply_edits(self, edits, dry_run=False):
6565 start_hash , end_hash , operation = original
6666
6767 # Validate operation
68- if operation in ["replace" , "insert" , "delete" ]:
68+ if operation in ["replace" , "insert" , "delete" , "cancel" ]:
6969 # Validate hashline format
7070 if isinstance (start_hash , str ) and (
7171 operation == "insert" or isinstance (end_hash , str )
@@ -225,7 +225,7 @@ def apply_edits(self, edits, dry_run=False):
225225 res += (
226226 "The LOCATE section must be a valid JSON array in the format:\n "
227227 '["{start hashline}", "{end hashline}", "{operation}"]\n '
228- "Hashline prefixes must have the structure `{line_num}{hash_fragment }` (e.g., `20Bv`)"
228+ "Hashline prefixes must have the structure `{4 char hash }` (e.g., `20Bv`)"
229229 " and match one found directly in the file"
230230 )
231231 if passed :
@@ -650,14 +650,15 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE, valid_fnames=None)
650650 # Check if original_text is a hashline JSON block
651651 try :
652652 # Try to parse as JSON
653- parsed = json .loads (original_text_str .strip ())
653+ # parsed = json.loads(original_text_str.strip())
654+ parsed = extract_base64url_parts (original_text_str .strip ())
654655 # Check if it's a list with 3 elements (start_hash, end_hash, operation)
655656 if isinstance (parsed , list ) and len (parsed ) == 3 :
656657 # Validate the format: all strings
657658 if all (isinstance (item , str ) for item in parsed ):
658659 # Check if first two items look like hashline format (e.g., "1ab")
659660
660- if parsed [2 ] in ["replace" , "insert" , "delete" ]:
661+ if parsed [2 ] in ["replace" , "insert" , "delete" , "cancel" ]:
661662 # This is a hashline JSON block
662663 yield filename , parsed , updated_text_str
663664 continue
@@ -675,6 +676,17 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE, valid_fnames=None)
675676 i += 1
676677
677678
679+ def extract_base64url_parts (input_string ):
680+ # Remove any character that is NOT a-z, A-Z, 0-9, -, or _
681+ clean_str = re .sub (r"[^a-zA-Z0-9\-_]" , "" , input_string )
682+
683+ return [
684+ clean_str [:4 ], # First 4 chars
685+ clean_str [4 :8 ], # Second 4 chars
686+ clean_str [8 :], # The rest
687+ ]
688+
689+
678690def find_filename (lines , fence , valid_fnames ):
679691 """
680692 Deepseek Coder v2 has been doing this:
0 commit comments