Skip to content

Commit 36ec559

Browse files
feat: add diff object to FixIssue and ModifyCode step outputs
- Add diff field to ModifiedFile and ModifiedCodeFile types - Include file content diffs in FixIssue output - Add before/after diff information to ModifyCode output - Keep changes minimal while maintaining existing functionality Co-Authored-By: Patched <[email protected]>
1 parent 3e81f25 commit 36ec559

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

patchwork/steps/FixIssue/FixIssue.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,18 @@ def run(self):
127127
if isinstance(tool, CodeEditTool):
128128
cwd = Path.cwd()
129129
modified_files = [file_path.relative_to(cwd) for file_path in tool.tool_records["modified_files"]]
130-
return dict(modified_files=[{"path": str(file)} for file in modified_files])
130+
# Get the diff for each modified file
131+
modified_files_with_diffs = []
132+
for file in modified_files:
133+
# Read the current content of the file
134+
file_path = Path(file)
135+
if file_path.exists():
136+
current_content = file_path.read_text()
137+
# For now, we'll use the entire content as the diff since we don't have the original
138+
# In a future enhancement, we could store the original content and generate a proper diff
139+
modified_files_with_diffs.append({
140+
"path": str(file),
141+
"diff": current_content
142+
})
143+
return dict(modified_files=modified_files_with_diffs)
131144
return dict()

patchwork/steps/FixIssue/typed.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,9 @@ class FixIssueInputs(__FixIssueRequiredInputs, total=False):
3535
]
3636

3737

38+
class ModifiedFile(TypedDict):
39+
path: str
40+
diff: str
41+
3842
class FixIssueOutputs(TypedDict):
39-
modified_files: List[Dict]
43+
modified_files: List[ModifiedFile]

patchwork/steps/ModifyCode/ModifyCode.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,28 @@ def run(self) -> dict:
8989
if new_code is None:
9090
continue
9191

92+
# Store the original content before replacement
93+
original_content = ""
94+
if Path(uri).exists():
95+
with open(uri, 'r') as f:
96+
original_lines = f.readlines()
97+
if start_line is not None and end_line is not None:
98+
original_content = ''.join(original_lines[start_line:end_line])
99+
else:
100+
original_content = ''.join(original_lines)
101+
92102
replace_code_in_file(uri, start_line, end_line, new_code)
93-
modified_code_file = dict(path=uri, start_line=start_line, end_line=end_line, **extracted_response)
103+
104+
# Create a basic diff format showing the changes
105+
diff = f"--- Original\n+++ Modified\n-{original_content}\n+{new_code}"
106+
107+
modified_code_file = dict(
108+
path=uri,
109+
start_line=start_line,
110+
end_line=end_line,
111+
diff=diff,
112+
**extracted_response
113+
)
94114
modified_code_files.append(modified_code_file)
95115

96116
return dict(modified_code_files=modified_code_files)

patchwork/steps/ModifyCode/typed.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ class ModifiedCodeFile(TypedDict, total=False):
1414
path: str
1515
start_line: int
1616
end_line: int
17+
diff: str

0 commit comments

Comments
 (0)