Skip to content
This repository was archived by the owner on Mar 27, 2026. It is now read-only.

Commit 7e70279

Browse files
committed
prepend instructions
1 parent d962536 commit 7e70279

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

src/utils/diff_parser.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,77 @@ impl DiffParser {
136136
pub fn reconstruct_patch(patch_dict: &HashMap<String, Vec<Hunk>>) -> String {
137137
let mut output = Vec::new();
138138

139+
// Only add instructions if the patch dictionary is not empty
140+
if !patch_dict.is_empty() {
141+
// Add instructions at the beginning of the output
142+
output.push("**Instructions for Interpreting Git Diff Output**".to_string());
143+
output.push("".to_string());
144+
output.push("This document provides a guide to understanding the diff output generated by RepoDiff.".to_string());
145+
output.push("".to_string());
146+
output.push("**Important Note:** The diff output in `repodiff_output.txt` has been sanitized to focus what's relevant for understanding the diffs.".to_string());
147+
output.push("Real-world Git diff output may contain more details.".to_string());
148+
output.push("".to_string());
149+
output.push("**1. Basic Structure:**".to_string());
150+
output.push("".to_string());
151+
output.push("A Git diff file describes the *differences* between two versions of a file. It's structured into *hunks*, which represent contiguous regions of change.".to_string());
152+
output.push("".to_string());
153+
output.push("* `diff --git a/<path> b/<path>`: Indicates the file being compared. `a/` refers to the \"old\" version, and `b/` refers to the \"new\" version. (Note that paths always use forward slashes in Git diff output, even on Windows systems.)".to_string());
154+
output.push("* `--- a/<path>`: Marks the beginning of the original file content.".to_string());
155+
output.push("* `+++ b/<path>`: Marks the beginning of the modified file content.".to_string());
156+
output.push("* `@@ -<start_line_old>,<num_lines_old> +<start_line_new>,<num_lines_new> @@ <section_header>`: This is the *hunk header*. (Optional in simplified output, but common in real diffs).".to_string());
157+
output.push(" * `-<start_line_old>,<num_lines_old>`: Indicates the starting line number and number of lines in the *old* version of the file that this hunk represents. If only one line is affected, `,<num_lines_old>` will be omitted.".to_string());
158+
output.push(" * `+<start_line_new>,<num_lines_new>`: Indicates the starting line number and number of lines in the *new* version of the file that this hunk represents. If only one line is affected, `,<num_lines_new>` will be omitted.".to_string());
159+
output.push(" * `<section_header>`: (Optional) This is often a function or method name, providing context for the change.".to_string());
160+
output.push("* Hunk Content: Lines within a hunk are marked with a prefix:".to_string());
161+
output.push(" * ` ` (space): Unchanged line (context).".to_string());
162+
output.push(" * `-`: Line removed from the old version.".to_string());
163+
output.push(" * `+`: Line added to the new version.".to_string());
164+
output.push("".to_string());
165+
output.push("**2. Simplified Example:**".to_string());
166+
output.push("".to_string());
167+
output.push("```".to_string());
168+
output.push("diff --git a/MyFile.cs b/MyFile.cs".to_string());
169+
output.push("--- a/MyFile.cs".to_string());
170+
output.push("+++ b/MyFile.cs ".to_string());
171+
output.push(" // Some code".to_string());
172+
output.push(" string oldValue = \"old\";".to_string());
173+
output.push("-// Removed line".to_string());
174+
output.push("+string newValue = \"new\";".to_string());
175+
output.push(" // More code".to_string());
176+
output.push("```".to_string());
177+
output.push("".to_string());
178+
output.push("**Explanation of the Example:**".to_string());
179+
output.push("".to_string());
180+
output.push("* The file being changed is `MyFile.cs`.".to_string());
181+
output.push("* `\" string oldValue = \"old\";\"`: This line is present in both versions.".to_string());
182+
output.push("* `-// Removed line`: This line was removed from the old version.".to_string());
183+
output.push("* `+string newValue = \"new\";`: This line was added to the new version.".to_string());
184+
output.push("* `\" // More code\"`: This line is present in both versions.".to_string());
185+
output.push("".to_string());
186+
output.push("**3. Key LLM Considerations:**".to_string());
187+
output.push("".to_string());
188+
output.push("* **Focus on Content Lines:** The most important part for understanding changes is the content prefixed with ` `, `-`, or `+`.".to_string());
189+
output.push("* **Context is Crucial:** Use the surrounding unchanged lines to understand the *purpose* of the change.".to_string());
190+
output.push("* **File Paths:** Pay attention to the file paths (`a/<path>`, `b/<path>`) to understand which files are being modified.".to_string());
191+
output.push("".to_string());
192+
output.push("**4. Application to your File:**".to_string());
193+
output.push("".to_string());
194+
output.push("* **\".cs\" Files:** Changes to C# source code. Focus on the addition (`+`) and removal (`-`) of code lines to understand logic changes.".to_string());
195+
output.push("* **\"Test*.cs\" Files:** Changes to unit test files. These are often important for understanding how the functionality is being tested and whether the changes are robust.".to_string());
196+
output.push("* **\".xml\" Files:** Changes to configuration or data files. Look for added, removed, or modified XML elements and attributes. Focus is usually on changes to properties.".to_string());
197+
output.push("".to_string());
198+
output.push("**5. Special Instructions for File Types based on the given filters:**".to_string());
199+
output.push("".to_string());
200+
output.push("* `.cs` code is assumed to not contain test code".to_string());
201+
output.push("* `*Test*.cs` contain test code, which should be helpful for understanding functionality.".to_string());
202+
output.push("* `*.xml` contains configuration.".to_string());
203+
output.push("".to_string());
204+
output.push("By focusing on these key elements, you can effectively extract meaningful information from Git diff output and summarize the changes made in a software project.".to_string());
205+
output.push("".to_string());
206+
output.push("---".to_string());
207+
output.push("".to_string());
208+
}
209+
139210
for (filename, hunks) in patch_dict {
140211
// Check if any hunks have rename information
141212
let is_rename = hunks.iter().any(|hunk| hunk.is_rename);

0 commit comments

Comments
 (0)