1
0

feat: Update chat session instructions to recommend batch editing for multiple operations.

This commit is contained in:
2026-03-06 03:04:34 +01:00
parent 8b48b0f866
commit 829ba7a7f2
2 changed files with 6 additions and 5 deletions

View File

@@ -11,7 +11,7 @@ public record BatchOperation(
[property: Description("Operation type: 'replace' or 'delete'")] string Type,
[property: Description("First line's line:hash anchor (e.g. '5:a3')")] string? StartAnchor,
[property: Description("Last line's line:hash anchor (e.g. '8:d4')")] string? EndAnchor,
[property: Description("Raw source code to insert. Required for 'replace' operations.")] string[]? NewLines);
[property: Description("Text content to insert. Required for 'replace' operations.")] string[]? Content);
/// <summary>
/// Mutating file tools exposed to the LLM as AIFunctions.
@@ -292,7 +292,7 @@ internal static partial class EditTools
}
}
[Description("Apply multiple edits atomically. All anchors are validated before any changes are made.")]
[Description("Atomically apply multiple replace/delete operations to a file. All anchors validated upfront against original content. Operations auto-sorted bottom-to-top to prevent line drift. Prefer over individual calls when making multiple edits.")]
public static string BatchEdit(
[Description("Path to the file.")] string path,
[Description("Array of operations to apply. Operations are applied in bottom-to-top order automatically.")] BatchOperation[] operations)
@@ -325,8 +325,8 @@ internal static partial class EditTools
if (opType != "replace" && opType != "delete")
return $"ERROR: Operation {i}: Invalid type '{op.Type}'. Must be 'replace' or 'delete'";
if (opType == "replace" && op.NewLines == null)
return $"ERROR: Operation {i}: 'replace' requires NewLines";
if (opType == "replace" && op.Content == null)
return $"ERROR: Operation {i}: 'replace' requires Content";
if (string.IsNullOrEmpty(op.StartAnchor) || string.IsNullOrEmpty(op.EndAnchor))
return $"ERROR: Operation {i}: StartAnchor and EndAnchor are required";
@@ -368,7 +368,7 @@ internal static partial class EditTools
// Apply operation
var opType = op.Type.ToLowerInvariant();
if (opType == "replace")
result.AddRange(SanitizeNewLines(op.NewLines!));
result.AddRange(SanitizeNewLines(op.Content!));
// delete: don't add anything (skip the range)
nextLineIdx = endIdx + 1;