MCPcopy Create free account
hub / github.com/FareedKhan-dev/ai-long-task / extract_diffs

Function extract_diffs

utils/code_utils.py:90–106  ·  view source on GitHub ↗

Extract all SEARCH/REPLACE diff blocks from a given text. Args: diff_text: The text containing diff blocks. diff_pattern: The regex pattern for the SEARCH/REPLACE format. Returns: A list of tuples, where each tuple is (search_text, replace_text).

(
    diff_text: str, diff_pattern: str = r"<<<<<<< SEARCH\n(.*?)=======\n(.*?)>>>>>>> REPLACE"
)

Source from the content-addressed store, hash-verified

88
89
90def extract_diffs(
91 diff_text: str, diff_pattern: str = r"<<<<<<< SEARCH\n(.*?)=======\n(.*?)>>>>>>> REPLACE"
92) -> List[Tuple[str, str]]:
93 """
94 Extract all SEARCH/REPLACE diff blocks from a given text.
95
96 Args:
97 diff_text: The text containing diff blocks.
98 diff_pattern: The regex pattern for the SEARCH/REPLACE format.
99
100 Returns:
101 A list of tuples, where each tuple is (search_text, replace_text).
102 """
103 # Use re.findall with DOTALL flag to match across multiple lines
104 diff_blocks = re.findall(diff_pattern, diff_text, re.DOTALL)
105 # Strip trailing whitespace from both search and replace parts for clean matching
106 return [(match[0].rstrip(), match[1].rstrip()) for match in diff_blocks]
107
108
109def parse_full_rewrite(llm_response: str, language: str = "python") -> Optional[str]:

Callers 3

_run_iteration_workerFunction · 0.90
apply_diffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected