|
171 | 171 | {:original-full-content original-full-content |
172 | 172 | :new-full-content new-full-content}))) |
173 | 173 |
|
174 | | -(defn ^:private edit-file [arguments {:keys [db]}] |
| 174 | +(defn ^:private change-file [arguments {:keys [db]} diff?] |
175 | 175 | (or (tools.util/invalid-arguments arguments (concat (path-validations db) |
176 | 176 | [["path" fs/readable? "File $path is not readable"]])) |
177 | 177 | (let [path (get arguments "path") |
178 | 178 | original-content (get arguments "original_content") |
179 | 179 | new-content (get arguments "new_content") |
| 180 | + new-content (if diff? |
| 181 | + (str "<<<<<<< HEAD\n" |
| 182 | + original-content |
| 183 | + "\n=======\n" |
| 184 | + new-content |
| 185 | + "\n>>>>>>> eca\n") |
| 186 | + new-content) |
180 | 187 | all? (boolean (get arguments "all_occurrences"))] |
181 | 188 | (if-let [{:keys [new-full-content]} (file-change-full-content path original-content new-content all?)] |
182 | 189 | (do |
183 | 190 | (spit path new-full-content) |
184 | 191 | (tools.util/single-text-content (format "Successfully replaced content in %s." path))) |
185 | 192 | (tools.util/single-text-content (format "Original content not found in %s" path) :error))))) |
186 | 193 |
|
| 194 | +(defn ^:private edit-file [arguments components] |
| 195 | + (change-file arguments components false)) |
| 196 | + |
| 197 | +(defn ^:private plan-edit-file [arguments components] |
| 198 | + (change-file arguments components true)) |
| 199 | + |
187 | 200 | (defn ^:private move-file [arguments {:keys [db]}] |
188 | 201 | (let [workspace-dirs (tools.util/workspace-roots-strs db)] |
189 | 202 | (or (tools.util/invalid-arguments arguments [["source" fs/exists? "$source is not a valid path"] |
|
246 | 259 | {:description (str "Replace a specific string or content block in a file with new content. " |
247 | 260 | "Finds the exact original content and replaces it with new content. " |
248 | 261 | "Be extra careful to format the original-content exactly correctly, " |
249 | | - "taking extra care with whitespace and newlines. In addition to replacing strings, " |
250 | | - "this can also be used to prepend, append, or delete contents from a file.") |
| 262 | + "taking extra care with whitespace and newlines. " |
| 263 | + "Avoid replacing whole functions, methods, or classes, change only the needed code. " |
| 264 | + "In addition to replacing strings, this can also be used to prepend, append, or delete contents from a file.") |
251 | 265 | :parameters {:type "object" |
252 | 266 | :properties {"path" {:type "string" |
253 | 267 | :description "The absolute file path to do the replace."} |
|
259 | 273 | :description "Whether to replace all occurences of the file or just the first one (default)"}} |
260 | 274 | :required ["path" "original_content" "new_content"]} |
261 | 275 | :handler #'edit-file |
| 276 | + :enabled-fn (fn [{:keys [behavior]}] (not= "plan" behavior)) |
262 | 277 | :summary-fn (constantly "Editting file")} |
| 278 | + "eca_plan_edit_file" |
| 279 | + {:description (str "Plan a file change where user needs to apply or reject the change. " |
| 280 | + "Replace a specific string or content block in a file with new content. " |
| 281 | + "Finds the exact original content and replaces it with new content. " |
| 282 | + "Be extra careful to format the original-content exactly correctly, " |
| 283 | + "taking extra care with whitespace and newlines. " |
| 284 | + "Avoid replacing whole functions, methods, or classes, change only the needed code. " |
| 285 | + "In addition to replacing strings, this can also be used to prepend, append, or delete contents from a file.") |
| 286 | + :parameters {:type "object" |
| 287 | + :properties {"path" {:type "string" |
| 288 | + :description "The absolute file path to do the replace."} |
| 289 | + "original_content" {:type "string" |
| 290 | + :description "The exact content to find and replace"} |
| 291 | + "new_content" {:type "string" |
| 292 | + :description "The new content to replace the original content with"} |
| 293 | + "all_occurrences" {:type "boolean" |
| 294 | + :description "Whether to replace all occurences of the file or just the first one (default)"}} |
| 295 | + :required ["path" "original_content" "new_content"]} |
| 296 | + :handler #'plan-edit-file |
| 297 | + :enabled-fn (fn [{:keys [behavior]}] (= "plan" behavior)) |
| 298 | + :summary-fn (constantly "Planning edit")} |
263 | 299 | "eca_move_file" |
264 | 300 | {:description (str "Move or rename files and directories. Can move files between directories " |
265 | 301 | "and rename them in a single operation. If the destination exists, the " |
|
0 commit comments