File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -198,6 +198,30 @@ def dedup_diffs(diffs):
198198 groups [key ].append (value )
199199 return [[key , "\n " .join (values )] for key , values in groups .items ()]
200200
201+ # Special case: handle LLM-style patch delimiters
202+ if "*** Begin Patch" in diff_text :
203+ lines = diff_text .splitlines ()
204+ diffs = []
205+ current_lines = []
206+ current_file = None
207+ in_patch = False
208+ for line in lines :
209+ stripped = line .strip ()
210+ if stripped == "*** Begin Patch" :
211+ in_patch = True
212+ current_lines = []
213+ current_file = None
214+ elif stripped == "*** End Patch" :
215+ if current_file is not None :
216+ diffs .append ((current_file , "\n " .join (current_lines )))
217+ in_patch = False
218+ elif in_patch :
219+ if stripped .startswith ("*** Update File:" ):
220+ current_file = stripped .split (":" , 1 )[1 ].strip ()
221+ else :
222+ current_lines .append (line )
223+ return dedup_diffs (diffs )
224+
201225 header_re = re .compile (r'^(?:diff --git\s+)?(a/[^ ]+)\s+(b/[^ ]+)\s*$' , re .MULTILINE )
202226 lines = diff_text .splitlines ()
203227
Original file line number Diff line number Diff line change @@ -169,5 +169,19 @@ def test_parse_diff_per_file_unconventional_header():
169169 assert "+++ game.js" in patch , "Expected patch to include '+++ game.js'"
170170 assert "+let player" in patch , "Expected patch to include added lines"
171171
172+ def test_begin_patch_format ():
173+ diff_text = """*** Begin Patch
174+ *** Update File: services/clerkReportPdf.tsx
175+ @@
176+ -changes1
177+ +changes2
178+ *** End Patch"""
179+ result = parse_diff_per_file (diff_text )
180+ assert len (result ) == 1
181+ file_path , patch = result [0 ]
182+ assert file_path == "services/clerkReportPdf.tsx"
183+ assert "-changes1" in patch
184+ assert "+changes2" in patch
185+
172186if __name__ == '__main__' :
173187 unittest .main ()
You can’t perform that action at this time.
0 commit comments