@@ -44,6 +44,11 @@ type EditResponseMetadata struct {
4444
4545const EditToolName = "edit"
4646
47+var (
48+ oldStringNotFoundErr = fantasy.NewTextErrorResponse("old_string not found in file. Make sure it matches exactly, including whitespace and line breaks.")
49+ oldStringMultipleMatchesErr = fantasy.NewTextErrorResponse("old_string appears multiple times in the file. Please provide more context to ensure a unique match, or set replace_all to true")
50+)
51+
4752//go:embed edit.md
4853var editDescription []byte
4954
@@ -217,12 +222,12 @@ func deleteContent(edit editContext, filePath, oldString string, replaceAll bool
217222 newContent = strings.ReplaceAll(oldContent, oldString, "")
218223 deletionCount = strings.Count(oldContent, oldString)
219224 if deletionCount == 0 {
220− return fantasy.NewTextErrorResponse("old_string not found in file. Make sure it matches exactly, including whitespace and line breaks"), nil
225+ return oldStringNotFoundErr, nil
221226 }
222227 } else {
223228 index := strings.Index(oldContent, oldString)
224229 if index == -1 {
225− return fantasy.NewTextErrorResponse("old_string not found in file. Make sure it matches exactly, including whitespace and line breaks"), nil
230+ return oldStringNotFoundErr, nil
226231 }
227232
228233 lastIndex := strings.LastIndex(oldContent, oldString)
@@ -287,7 +292,7 @@ func deleteContent(edit editContext, filePath, oldString string, replaceAll bool
287292 }
288293 }
289294 if file.Content != oldContent {
290− // User Manually changed the content store an intermediate version
295+ // User manually changed the content; store an intermediate version
291296 _, err = edit.files.CreateVersion(edit.ctx, sessionID, filePath, oldContent)
292297 if err != nil {
293298 slog.Error("Error creating file history version", "error", err)
@@ -353,17 +358,17 @@ func replaceContent(edit editContext, filePath, oldString, newString string, rep
353358 newContent = strings.ReplaceAll(oldContent, oldString, newString)
354359 replacementCount = strings.Count(oldContent, oldString)
355360 if replacementCount == 0 {
356− return fantasy.NewTextErrorResponse("old_string not found in file. Make sure it matches exactly, including whitespace and line breaks"), nil
361+ return oldStringNotFoundErr, nil
357362 }
358363 } else {
359364 index := strings.Index(oldContent, oldString)
360365 if index == -1 {
361− return fantasy.NewTextErrorResponse("old_string not found in file. Make sure it matches exactly, including whitespace and line breaks"), nil
366+ return oldStringNotFoundErr, nil
362367 }
363368
364369 lastIndex := strings.LastIndex(oldContent, oldString)
365370 if index != lastIndex {
366− return fantasy.NewTextErrorResponse("old_string appears multiple times in the file. Please provide more context to ensure a unique match, or set replace_all to true"), nil
371+ return oldStringMultipleMatchesErr, nil
367372 }
368373
369374 newContent = oldContent[:index] + newString + oldContent[index+len(oldString):]
@@ -425,7 +430,7 @@ func replaceContent(edit editContext, filePath, oldString, newString string, rep
425430 }
426431 }
427432 if file.Content != oldContent {
428− // User Manually changed the content store an intermediate version
433+ // User manually changed the content; store an intermediate version
429434 _, err = edit.files.CreateVersion(edit.ctx, sessionID, filePath, oldContent)
430435 if err != nil {
431436 slog.Debug("Error creating file history version", "error", err)