@@ -216,12 +216,10 @@ func deleteContent(edit editContext, filePath, oldString string, replaceAll bool
216 oldContent, isCrlf := fsext.ToUnixLineEndings(string(content))
216 oldContent, isCrlf := fsext.ToUnixLineEndings(string(content))
218 var newContent string
218 var newContent string
219− var deletionCount int
221 if replaceAll {
220 if replaceAll {
222 newContent = strings.ReplaceAll(oldContent, oldString, "")
221 newContent = strings.ReplaceAll(oldContent, oldString, "")
223− deletionCount = strings.Count(oldContent, oldString)
222+ if newContent == oldContent {
224− if deletionCount == 0 {
225 return oldStringNotFoundErr, nil
223 return oldStringNotFoundErr, nil
@@ -236,13 +234,12 @@ func deleteContent(edit editContext, filePath, oldString string, replaceAll bool
238 newContent = oldContent[:index] + oldContent[index+len(oldString):]
236 newContent = oldContent[:index] + oldContent[index+len(oldString):]
242 sessionID := GetSessionFromContext(edit.ctx)
239 sessionID := GetSessionFromContext(edit.ctx)
244 if sessionID == "" {
241 if sessionID == "" {
245− return fantasy.ToolResponse{}, fmt.Errorf("session ID is required for creating a new file")
242+ return fantasy.ToolResponse{}, fmt.Errorf("session ID is required for deleting content")
248 _, additions, removals := diff.GenerateDiff(
245 _, additions, removals := diff.GenerateDiff(
@@ -299,7 +296,7 @@ func deleteContent(edit editContext, filePath, oldString string, replaceAll bool
301 // Store the new version
298 // Store the new version
302− _, err = edit.files.CreateVersion(edit.ctx, sessionID, filePath, "")
299+ _, err = edit.files.CreateVersion(edit.ctx, sessionID, filePath, newContent)
303 if err != nil {
300 if err != nil {
304 slog.Error("Error creating file history version", "error", err)
301 slog.Error("Error creating file history version", "error", err)
@@ -352,14 +349,9 @@ func replaceContent(edit editContext, filePath, oldString, newString string, rep
352 oldContent, isCrlf := fsext.ToUnixLineEndings(string(content))
349 oldContent, isCrlf := fsext.ToUnixLineEndings(string(content))
354 var newContent string
351 var newContent string
355− var replacementCount int
357 if replaceAll {
353 if replaceAll {
358 newContent = strings.ReplaceAll(oldContent, oldString, newString)
354 newContent = strings.ReplaceAll(oldContent, oldString, newString)
359− replacementCount = strings.Count(oldContent, oldString)
360− if replacementCount == 0 {
361− return oldStringNotFoundErr, nil
364 index := strings.Index(oldContent, oldString)
356 index := strings.Index(oldContent, oldString)
365 if index == -1 {
357 if index == -1 {
@@ -372,7 +364,6 @@ func replaceContent(edit editContext, filePath, oldString, newString string, rep
374 newContent = oldContent[:index] + newString + oldContent[index+len(oldString):]
366 newContent = oldContent[:index] + newString + oldContent[index+len(oldString):]
375− replacementCount = 1
378 if oldContent == newContent {
369 if oldContent == newContent {