diff --git a/automation/patcher.py b/automation/patcher.py index 08b4e79..50ec325 100644 --- a/automation/patcher.py +++ b/automation/patcher.py @@ -506,10 +506,22 @@ def sanitize_unified_patch(patch: str) -> str: # Look for the 'diff --git' header diff_start = text.find("diff --git") if diff_start == -1: - # No diff header means AI chose not to generate a patch - # This is normal for gated outputs or when AI determines no changes needed - return "" - return text[diff_start:] + "\n" + # Some providers omit diff header; synthesize one if we have +++ line. + plus_line = next((line for line in cleaned if line.startswith("+++ ")), None) + minus_line = next((line for line in cleaned if line.startswith("--- ")), None) + if plus_line: + plus_path = plus_line[4:].strip() + minus_path = minus_line[4:].strip() if minus_line else plus_path + if minus_path == "/dev/null": + minus_path = plus_path + text = f"diff --git {minus_path} {plus_path}\n{text}" + else: + # No diff header means AI chose not to generate a patch + # This is normal for gated outputs or when AI determines no changes needed + return "" + else: + text = text[diff_start:] + return text + "\n" def rewrite_patch_for_p0(patch: str) -> str: