edit_workflow.hbs

  1<task_description>
  2
  3The user of a code editor wants to make a change to their codebase.
  4You must describe the change using the following XML structure:
  5
  6- <patch> - A group of related code changes.
  7  Child tags:
  8    - <title> (required) - A high-level description of the changes. This should be as short
  9      as possible, possibly using common abbreviations.
 10    - <edit> (1 or more) - An edit to make at a particular range within a file.
 11      Includes the following child tags:
 12        - <path> (required) - The path to the file that will be changed.
 13        - <description> (optional) - An arbitrarily-long comment that describes the purpose
 14          of this edit.
 15        - <old_text> (optional) - An excerpt from the file's current contents that uniquely
 16          identifies a range within the file where the edit should occur. If this tag is not
 17          specified, then the entire file will be used as the range.
 18        - <new_text> (required) - The new text to insert into the file.
 19        - <operation> (required) - The type of change that should occur at the given range
 20          of the file. Must be one of the following values:
 21            - `update`: Replaces the entire range with the new text.
 22            - `insert_before`: Inserts the new text before the range.
 23            - `insert_after`: Inserts new text after the range.
 24            - `create`: Creates a new file with the given path and the new text.
 25            - `delete`: Deletes the specified range from the file.
 26
 27<guidelines>
 28- Never provide multiple edits whose ranges intersect each other. Instead, merge them into one edit.
 29- Prefer multiple edits to smaller, disjoint ranges, rather than one edit to a larger range.
 30- There's no need to escape angle brackets within XML tags.
 31- Always ensure imports are added if you're referencing symbols that are not in scope.
 32</guidelines>
 33
 34Here are some concrete examples.
 35
 36<example>
 37<message role="user">
 38
 39```rs src/shapes.rs
 40pub mod rectangle;
 41pub mod circle;
 42```
 43
 44```rs src/shapes/rectangle.rs
 45pub struct Rectangle {
 46    width: f64,
 47    height: f64,
 48}
 49
 50impl Rectangle {
 51    pub fn new(width: f64, height: f64) -> Self {
 52        Rectangle { width, height }
 53    }
 54}
 55```
 56
 57```rs src/shapes/circle.rs
 58pub struct Circle {
 59    radius: f64,
 60}
 61
 62impl Circle {
 63    pub fn new(radius: f64) -> Self {
 64        Circle { radius }
 65    }
 66}
 67```
 68
 69Update all shapes to store their origin as an (x, y) tuple and implement Display.
 70</message>
 71
 72<message role="assistant">
 73We'll need to update both the rectangle and circle modules.
 74
 75<patch>
 76<title>Add origins and display impls to shapes</title>
 77<edit>
 78<path>src/shapes/rectangle.rs</path>
 79<description>Add the origin field to Rectangle struct</description>
 80<operation>insert_after</operation>
 81<old_text>
 82pub struct Rectangle {
 83</old_text>
 84<new_text>
 85origin: (f64, f64),
 86</new_text>
 87</edit>
 88
 89<edit>
 90<path>src/shapes/rectangle.rs</path>
 91<description>Update the Rectangle's new function to take an origin parameter</description>
 92<operation>update</operation>
 93<old_text>
 94fn new(width: f64, height: f64) -> Self {
 95    Rectangle { width, height }
 96}
 97</old_text>
 98<new_text>
 99fn new(origin: (f64, f64), width: f64, height: f64) -> Self {
100    Rectangle { origin, width, height }
101}
102</new_text>
103</edit>
104
105<edit>
106<path>src/shapes/circle.rs</path>
107<description>Add the origin field to Circle struct</description>
108<operation>insert_after</operation>
109<old_text>
110pub struct Circle {
111    radius: f64,
112</old_text>
113<new_text>
114    origin: (f64, f64),
115</new_text>
116</edit>
117
118<edit>
119<path>src/shapes/circle.rs</path>
120<description>Update the Circle's new function to take an origin parameter</description>
121<operation>update</operation>
122<old_text>
123fn new(radius: f64) -> Self {
124    Circle { radius }
125}
126</old_text>
127<new_text>
128fn new(origin: (f64, f64), radius: f64) -> Self {
129    Circle { origin, radius }
130}
131</new_text>
132</edit>
133</step>
134
135<edit>
136<path>src/shapes/rectangle.rs</path>
137<description>Add an import for the std::fmt module</description>
138<operation>insert_before</operation>
139<old_text>
140struct Rectangle {
141</old_text>
142<new_text>
143use std::fmt;
144
145</new_text>
146</edit>
147
148<edit>
149<path>src/shapes/rectangle.rs</path>
150<description>Add a Display implementation for Rectangle</description>
151<operation>insert_after</operation>
152<old_text>
153        Rectangle { width, height }
154    }
155}
156</old_text>
157<new_text>
158impl fmt::Display for Rectangle {
159    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
160        f.format_struct(f, "Rectangle")
161            .field("origin", &self.origin)
162            .field("width", &self.width)
163            .field("height", &self.height)
164            .finish()
165    }
166}
167</new_text>
168</edit>
169
170<edit>
171<path>src/shapes/circle.rs</path>
172<description>Add an import for the `std::fmt` module</description>
173<operation>insert_before</operation>
174<old_text>
175struct Circle {
176</old_text>
177<new_text>
178use std::fmt;
179</new_text>
180</edit>
181
182<edit>
183<path>src/shapes/circle.rs</path>
184<description>Add a Display implementation for Circle</description>
185<operation>insert_after</operation>
186<old_text>
187        Circle { radius }
188    }
189}
190</old_text>
191<new_text>
192impl fmt::Display for Rectangle {
193    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
194        f.format_struct(f, "Rectangle")
195            .field("origin", &self.origin)
196            .field("width", &self.width)
197            .field("height", &self.height)
198            .finish()
199    }
200}
201</new_text>
202</edit>
203</patch>
204
205</message>
206</example>
207
208</task_description>