1
0

Compare commits

..

2 Commits

5 changed files with 37 additions and 38 deletions

View File

@@ -9,22 +9,22 @@ internal static class ToolRegistry
{
var jsonOptions = AppJsonContext.Default.Options;
return new List<AITool>
{
AIFunctionFactory.Create(FileTools.ReadFile, serializerOptions: jsonOptions),
AIFunctionFactory.Create(FileTools.Grep, serializerOptions: jsonOptions),
AIFunctionFactory.Create(FileTools.ListDir, serializerOptions: jsonOptions),
AIFunctionFactory.Create(EditTools.ReplaceLines, serializerOptions: jsonOptions),
AIFunctionFactory.Create(EditTools.DeleteRange, serializerOptions: jsonOptions),
AIFunctionFactory.Create(EditTools.BatchEdit, serializerOptions: jsonOptions),
AIFunctionFactory.Create(EditTools.Delete, serializerOptions: jsonOptions),
AIFunctionFactory.Create(FileTools.FindFiles, serializerOptions: jsonOptions),
AIFunctionFactory.Create(FileTools.GetFileInfo, serializerOptions: jsonOptions),
AIFunctionFactory.Create(EditTools.WriteToFile, serializerOptions: jsonOptions),
AIFunctionFactory.Create(CommandTool.ExecuteCommand, serializerOptions: jsonOptions),
AIFunctionFactory.Create(EditTools.MoveFile, serializerOptions: jsonOptions),
AIFunctionFactory.Create(DirTools.RenameDir, serializerOptions: jsonOptions),
AIFunctionFactory.Create(DirTools.CreateDir, serializerOptions: jsonOptions),
};
return
[
AIFunctionFactory.Create(FileTools.ReadFile, name: "read_file", serializerOptions: jsonOptions),
AIFunctionFactory.Create(FileTools.Grep, name: "grep", serializerOptions: jsonOptions),
AIFunctionFactory.Create(FileTools.ListDir, name: "list_dir", serializerOptions: jsonOptions),
AIFunctionFactory.Create(EditTools.ReplaceLines, name: "replace_lines", serializerOptions: jsonOptions),
AIFunctionFactory.Create(EditTools.DeleteRange, name: "delete_range", serializerOptions: jsonOptions),
AIFunctionFactory.Create(EditTools.BatchEdit, name: "batch_edit", serializerOptions: jsonOptions),
AIFunctionFactory.Create(EditTools.Delete, name: "delete_file", serializerOptions: jsonOptions),
AIFunctionFactory.Create(FileTools.FindFiles, name: "find_files", serializerOptions: jsonOptions),
AIFunctionFactory.Create(FileTools.GetFileInfo, name: "get_file_info", serializerOptions: jsonOptions),
AIFunctionFactory.Create(EditTools.WriteToFile, name: "write_to_file", serializerOptions: jsonOptions),
AIFunctionFactory.Create(CommandTool.ExecuteCommand, name: "execute_command", serializerOptions: jsonOptions),
AIFunctionFactory.Create(EditTools.MoveFile, name: "rename_file", serializerOptions: jsonOptions),
AIFunctionFactory.Create(DirTools.RenameDir, name: "rename_dir", serializerOptions: jsonOptions),
AIFunctionFactory.Create(DirTools.CreateDir, name: "create_dir", serializerOptions: jsonOptions),
];
}
}

View File

@@ -21,7 +21,7 @@ internal static class CommandTool
public static string ExecuteCommand(
[Description("The shell command to execute.")] string command)
{
Log($"Command request: {command}");
Log($" ● execute_command: {command}");
// Prompt for user approval
PauseSpinner?.Invoke();

View File

@@ -17,7 +17,7 @@ internal static class DirTools
{
sourcePath = ResolvePath(sourcePath);
destinationPath = ResolvePath(destinationPath);
Log($"Renaming/moving directory: {sourcePath} -> {destinationPath}");
Log($" ● rename_dir: {sourcePath} -> {destinationPath}");
if (!Directory.Exists(sourcePath))
return $"ERROR: Directory not found: {sourcePath}";
@@ -44,7 +44,7 @@ internal static class DirTools
[Description("Path to the directory to create.")] string path)
{
path = ResolvePath(path);
Log($"Creating directory: {path}");
Log($" ● create_dir: {path}");
if (Directory.Exists(path))
return $"ERROR: Directory already exists: {path}";

View File

@@ -70,9 +70,8 @@ internal static partial class EditTools
{
newLines = SanitizeNewLines(newLines);
path = FileTools.ResolvePath(path);
Log($"REPLACE_LINES: {path}");
Log($" Range: {startAnchor} -> {endAnchor}");
Log($" Replacing {endAnchor.Split(':')[0]}-{startAnchor.Split(':')[0]} lines with {newLines.Length} new lines");
Log($" ● replace_lines: {path}");
Log($" {startAnchor.Split(':')[0]}-{endAnchor.Split(':')[0]} lines -> {newLines.Length} new lines");
if (!File.Exists(path))
return $"ERROR: File not found: {path}\n Check the correct path and try again.";
@@ -107,7 +106,8 @@ internal static partial class EditTools
[Description("Last line's line:hash anchor (e.g. '6:19').")] string endAnchor)
{
path = FileTools.ResolvePath(path);
Log($"Deleting lines in file: {path}");
Log($" ● delete_range: {path}");
Log($" {startAnchor.Split(':')[0]}-{endAnchor.Split(':')[0]} lines");
if (!File.Exists(path))
return $"ERROR: File not found: {path}";
@@ -142,7 +142,7 @@ internal static partial class EditTools
{
path = FileTools.ResolvePath(path);
string targetType = mode.Equals("dir", StringComparison.CurrentCultureIgnoreCase) ? "directory" : "file";
Log($"Deleting {targetType}: {path}");
Log($" ● delete_{targetType}: {path}");
if (mode.Equals("dir", StringComparison.CurrentCultureIgnoreCase))
{
@@ -184,8 +184,8 @@ internal static partial class EditTools
{
sourcePath = FileTools.ResolvePath(sourcePath);
destinationPath = FileTools.ResolvePath(destinationPath);
string action = copy ? "Copying" : "Moving";
Log($"{action} file: {sourcePath} -> {destinationPath}");
string action = copy ? "copy" : "move";
Log($"{action}_file: {sourcePath} -> {destinationPath}");
if (!File.Exists(sourcePath))
return $"ERROR: Source file not found: {sourcePath}";
@@ -221,9 +221,8 @@ internal static partial class EditTools
{
content = SanitizeNewLines(content);
path = FileTools.ResolvePath(path);
Log($"WRITE_TO_FILE: {path}");
Log($" Mode: {mode}");
Log($" Writing {content.Length} lines");
Log($" ● write_to_file: {path}");
Log($" mode: {mode} with {content.Length} lines");
try
{
@@ -298,8 +297,8 @@ internal static partial class EditTools
[Description("Array of operations to apply. Operations are applied in bottom-to-top order automatically.")] BatchOperation[] operations)
{
path = FileTools.ResolvePath(path);
Log($"BATCH_EDIT: {path}");
Log($" Operations: {operations.Length}");
Log($" ● batch_edit: {path}");
Log($" operations: {operations.Length}");
if (!File.Exists(path))
return $"ERROR: File not found: {path}";

View File

@@ -27,7 +27,7 @@ internal static class FileTools
[Description("Last line to return (inclusive). Use 0 for EOF. Defaults to 0.")] int endLine = 0)
{
path = ResolvePath(path);
Log($"Reading file: {path} {startLine}:{endLine}L");
Log($" ● read_file: {path} {startLine}:{endLine}L");
if (!File.Exists(path))
return $"ERROR: File not found: {path}";
@@ -62,7 +62,7 @@ internal static class FileTools
[Description("Path to the directory.")] string path = ".")
{
path = ResolvePath(path);
Log($"Listing directory: {path}");
Log($" ● list_dir: {path}");
if (!Directory.Exists(path))
return $"ERROR: Directory not found: {path}";
@@ -95,7 +95,7 @@ internal static class FileTools
[Description("Glob pattern (supports * and **).")] string pattern)
{
path = ResolvePath(path);
Log($"Finding files: {pattern} in {path}");
Log($" ● find_files: {pattern} in {path}");
if (!Directory.Exists(path))
return $"ERROR: Directory not found: {path}";
@@ -139,7 +139,7 @@ internal static class FileTools
if (mode == "file")
{
Log($"Searching file: {path}");
Log($" ● grep_file: {path}");
if (!File.Exists(path))
if (Directory.Exists(path))
@@ -186,7 +186,7 @@ internal static class FileTools
}
else if (mode == "recursive")
{
Log($"Recursive grep: {pattern} in {path}" + (filePattern != null ? $" (files: {filePattern})" : ""));
Log($" ● grep_recursive: {pattern} in {path}" + (filePattern != null ? $" (files: {filePattern})" : ""));
if (!Directory.Exists(path))
if (File.Exists(path))
@@ -297,7 +297,7 @@ internal static class FileTools
[Description("Path to the file.")] string path)
{
path = ResolvePath(path);
Log($"Getting file info: {path}");
Log($" ● get_file_info: {path}");
if (!File.Exists(path))
return $"ERROR: File not found: {path}";