feat: Add file editing tools with anchor validation and improve context compaction by redacting stale ReadFile results based on deduplication and time-to-live.
This commit is contained in:
@@ -52,12 +52,12 @@ internal static partial class EditTools
|
||||
return result;
|
||||
}
|
||||
|
||||
[Description("Replace a range of lines in a file, identified by Hashline anchors. Both the line number and hash must match the current file state.")]
|
||||
[Description("Replace a range of lines. Both line number and hash in the line:hash anchor must match.")]
|
||||
public static string ReplaceLines(
|
||||
[Description("Path to the file.")] string path,
|
||||
[Description("line:hash anchor of the first line to replace (e.g. '5:a3'). Both the line number AND hash must match.")] string startAnchor,
|
||||
[Description("line:hash anchor of the last line to replace (e.g. '7:0e'). Use the same as startAnchor to replace a single line.")] string endAnchor,
|
||||
[Description("New lines to insert in place of the replaced range. Each element becomes one line in the file. IMPORTANT: Write raw source code only. Do NOT include 'lineNumber:hash|' prefixes — those are display-only metadata from ReadFile, not part of the actual file content.")] string[] newLines)
|
||||
[Description("First line's line:hash anchor (e.g. '5:a3').")] string startAnchor,
|
||||
[Description("Last line's line:hash anchor. Use same as startAnchor for a single line.")] string endAnchor,
|
||||
[Description("Raw source code to insert. Do NOT include 'lineNumber:hash|' prefixes.")] string[] newLines)
|
||||
{
|
||||
newLines = SanitizeNewLines(newLines);
|
||||
path = FileTools.ResolvePath(path);
|
||||
@@ -90,11 +90,11 @@ internal static partial class EditTools
|
||||
}
|
||||
}
|
||||
|
||||
[Description("Insert new lines immediately after the line identified by a Hashline anchor.")]
|
||||
[Description("Insert lines after the specified line:hash anchor.")]
|
||||
public static string InsertAfter(
|
||||
[Description("Path to the file.")] string path,
|
||||
[Description("line:hash anchor of the line to insert after (e.g. '3:0e'). Both the line number AND hash must match.")] string anchor,
|
||||
[Description("Lines to insert after the anchor line. Each element becomes one line in the file. IMPORTANT: Write raw source code only. Do NOT include 'lineNumber:hash|' prefixes — those are display-only metadata from ReadFile, not part of the actual file content.")] string[] newLines)
|
||||
[Description("line:hash anchor to insert after (e.g. '3:0e').")] string anchor,
|
||||
[Description("Raw source code to insert. Do NOT include 'lineNumber:hash|' prefixes.")] string[] newLines)
|
||||
{
|
||||
newLines = SanitizeNewLines(newLines);
|
||||
path = FileTools.ResolvePath(path);
|
||||
@@ -129,11 +129,11 @@ internal static partial class EditTools
|
||||
}
|
||||
}
|
||||
|
||||
[Description("Delete a range of lines from a file, identified by Hashline anchors.")]
|
||||
[Description("Delete a range of lines.")]
|
||||
public static string DeleteRange(
|
||||
[Description("Path to the file.")] string path,
|
||||
[Description("line:hash anchor of the first line to delete (e.g. '4:7c'). Both the line number AND hash must match.")] string startAnchor,
|
||||
[Description("line:hash anchor of the last line to delete (e.g. '6:19'). Both the line number AND hash must match.")] string endAnchor)
|
||||
[Description("First line's line:hash anchor (e.g. '4:7c').")] string startAnchor,
|
||||
[Description("Last line's line:hash anchor (e.g. '6:19').")] string endAnchor)
|
||||
{
|
||||
path = FileTools.ResolvePath(path);
|
||||
Log($"Deleting lines in file: {path}");
|
||||
@@ -162,10 +162,10 @@ internal static partial class EditTools
|
||||
}
|
||||
}
|
||||
|
||||
[Description("Create a new empty file, or a file with initial content. Creates missing parent directories automatically. If the agent doesn't succeed with initial content, they can also create an empty file first and add the content using AppendToFile.")]
|
||||
[Description("Create a new file (parents auto-created). Max initial lines: 200. Alternatively, append lines later.")]
|
||||
public static string CreateFile(
|
||||
[Description("Path to the new file to create.")] string path,
|
||||
[Description("Optional initial content lines. If omitted, creates an empty file. IMPORTANT: Write raw source code only. Do NOT include 'lineNumber:hash|' prefixes — those are display-only metadata from ReadFile, not part of the actual file content.")] string[]? initialLines = null)
|
||||
[Description("Optional initial raw source code. Do NOT include 'lineNumber:hash|' prefixes.")] string[]? initialLines = null)
|
||||
{
|
||||
path = FileTools.ResolvePath(path);
|
||||
Log($"Creating file: {path}");
|
||||
@@ -194,7 +194,7 @@ internal static partial class EditTools
|
||||
}
|
||||
}
|
||||
|
||||
[Description("Delete a file permanently from the disk.")]
|
||||
[Description("Delete a file permanently.")]
|
||||
public static string DeleteFile(
|
||||
[Description("Path to the file to delete.")] string path)
|
||||
{
|
||||
@@ -215,7 +215,7 @@ internal static partial class EditTools
|
||||
}
|
||||
}
|
||||
|
||||
[Description("Rename or move a file. Can move a file to a new directory (which will be created if it doesn't exist).")]
|
||||
[Description("Rename or move a file. Auto-creates target dirs.")]
|
||||
public static string RenameFile(
|
||||
[Description("Current path to the file.")] string sourcePath,
|
||||
[Description("New path for the file.")] string destinationPath)
|
||||
@@ -273,10 +273,10 @@ internal static partial class EditTools
|
||||
}
|
||||
}
|
||||
|
||||
[Description("Append lines to the end of a file without reading it first. Creates the file if it doesn't exist.")]
|
||||
[Description("Append lines to EOF (auto-creating the file if missing).")]
|
||||
public static string AppendToFile(
|
||||
[Description("Path to the file to append to.")] string path,
|
||||
[Description("Lines to append to the end of the file. IMPORTANT: Write raw source code only. Do NOT include 'lineNumber:hash|' prefixes — those are display-only metadata from ReadFile, not part of the actual file content.")] string[] lines)
|
||||
[Description("Raw source code to append. Do NOT include 'lineNumber:hash|' prefixes.")] string[] lines)
|
||||
{
|
||||
lines = SanitizeNewLines(lines);
|
||||
path = FileTools.ResolvePath(path);
|
||||
|
||||
Reference in New Issue
Block a user