Compare commits
2 Commits
e2ab10813c
...
46d32c43ba
| Author | SHA1 | Date | |
|---|---|---|---|
| 46d32c43ba | |||
| 35c8840ed4 |
@@ -9,22 +9,22 @@ internal static class ToolRegistry
|
|||||||
{
|
{
|
||||||
var jsonOptions = AppJsonContext.Default.Options;
|
var jsonOptions = AppJsonContext.Default.Options;
|
||||||
|
|
||||||
return new List<AITool>
|
return
|
||||||
{
|
[
|
||||||
AIFunctionFactory.Create(FileTools.ReadFile, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(FileTools.ReadFile, name: "read_file", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(FileTools.Grep, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(FileTools.Grep, name: "grep", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(FileTools.ListDir, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(FileTools.ListDir, name: "list_dir", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(EditTools.ReplaceLines, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(EditTools.ReplaceLines, name: "replace_lines", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(EditTools.DeleteRange, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(EditTools.DeleteRange, name: "delete_range", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(EditTools.BatchEdit, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(EditTools.BatchEdit, name: "batch_edit", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(EditTools.Delete, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(EditTools.Delete, name: "delete_file", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(FileTools.FindFiles, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(FileTools.FindFiles, name: "find_files", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(FileTools.GetFileInfo, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(FileTools.GetFileInfo, name: "get_file_info", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(EditTools.WriteToFile, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(EditTools.WriteToFile, name: "write_to_file", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(CommandTool.ExecuteCommand, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(CommandTool.ExecuteCommand, name: "execute_command", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(EditTools.MoveFile, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(EditTools.MoveFile, name: "rename_file", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(DirTools.RenameDir, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(DirTools.RenameDir, name: "rename_dir", serializerOptions: jsonOptions),
|
||||||
AIFunctionFactory.Create(DirTools.CreateDir, serializerOptions: jsonOptions),
|
AIFunctionFactory.Create(DirTools.CreateDir, name: "create_dir", serializerOptions: jsonOptions),
|
||||||
};
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ internal static class CommandTool
|
|||||||
public static string ExecuteCommand(
|
public static string ExecuteCommand(
|
||||||
[Description("The shell command to execute.")] string command)
|
[Description("The shell command to execute.")] string command)
|
||||||
{
|
{
|
||||||
Log($"Command request: {command}");
|
Log($" ● execute_command: {command}");
|
||||||
|
|
||||||
// Prompt for user approval
|
// Prompt for user approval
|
||||||
PauseSpinner?.Invoke();
|
PauseSpinner?.Invoke();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ internal static class DirTools
|
|||||||
{
|
{
|
||||||
sourcePath = ResolvePath(sourcePath);
|
sourcePath = ResolvePath(sourcePath);
|
||||||
destinationPath = ResolvePath(destinationPath);
|
destinationPath = ResolvePath(destinationPath);
|
||||||
Log($"Renaming/moving directory: {sourcePath} -> {destinationPath}");
|
Log($" ● rename_dir: {sourcePath} -> {destinationPath}");
|
||||||
|
|
||||||
if (!Directory.Exists(sourcePath))
|
if (!Directory.Exists(sourcePath))
|
||||||
return $"ERROR: Directory not found: {sourcePath}";
|
return $"ERROR: Directory not found: {sourcePath}";
|
||||||
@@ -44,7 +44,7 @@ internal static class DirTools
|
|||||||
[Description("Path to the directory to create.")] string path)
|
[Description("Path to the directory to create.")] string path)
|
||||||
{
|
{
|
||||||
path = ResolvePath(path);
|
path = ResolvePath(path);
|
||||||
Log($"Creating directory: {path}");
|
Log($" ● create_dir: {path}");
|
||||||
|
|
||||||
if (Directory.Exists(path))
|
if (Directory.Exists(path))
|
||||||
return $"ERROR: Directory already exists: {path}";
|
return $"ERROR: Directory already exists: {path}";
|
||||||
|
|||||||
@@ -70,9 +70,8 @@ internal static partial class EditTools
|
|||||||
{
|
{
|
||||||
newLines = SanitizeNewLines(newLines);
|
newLines = SanitizeNewLines(newLines);
|
||||||
path = FileTools.ResolvePath(path);
|
path = FileTools.ResolvePath(path);
|
||||||
Log($"REPLACE_LINES: {path}");
|
Log($" ● replace_lines: {path}");
|
||||||
Log($" Range: {startAnchor} -> {endAnchor}");
|
Log($" {startAnchor.Split(':')[0]}-{endAnchor.Split(':')[0]} lines -> {newLines.Length} new lines");
|
||||||
Log($" Replacing {endAnchor.Split(':')[0]}-{startAnchor.Split(':')[0]} lines with {newLines.Length} new lines");
|
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
return $"ERROR: File not found: {path}\n Check the correct path and try again.";
|
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)
|
[Description("Last line's line:hash anchor (e.g. '6:19').")] string endAnchor)
|
||||||
{
|
{
|
||||||
path = FileTools.ResolvePath(path);
|
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))
|
if (!File.Exists(path))
|
||||||
return $"ERROR: File not found: {path}";
|
return $"ERROR: File not found: {path}";
|
||||||
@@ -142,7 +142,7 @@ internal static partial class EditTools
|
|||||||
{
|
{
|
||||||
path = FileTools.ResolvePath(path);
|
path = FileTools.ResolvePath(path);
|
||||||
string targetType = mode.Equals("dir", StringComparison.CurrentCultureIgnoreCase) ? "directory" : "file";
|
string targetType = mode.Equals("dir", StringComparison.CurrentCultureIgnoreCase) ? "directory" : "file";
|
||||||
Log($"Deleting {targetType}: {path}");
|
Log($" ● delete_{targetType}: {path}");
|
||||||
|
|
||||||
if (mode.Equals("dir", StringComparison.CurrentCultureIgnoreCase))
|
if (mode.Equals("dir", StringComparison.CurrentCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
@@ -184,8 +184,8 @@ internal static partial class EditTools
|
|||||||
{
|
{
|
||||||
sourcePath = FileTools.ResolvePath(sourcePath);
|
sourcePath = FileTools.ResolvePath(sourcePath);
|
||||||
destinationPath = FileTools.ResolvePath(destinationPath);
|
destinationPath = FileTools.ResolvePath(destinationPath);
|
||||||
string action = copy ? "Copying" : "Moving";
|
string action = copy ? "copy" : "move";
|
||||||
Log($"{action} file: {sourcePath} -> {destinationPath}");
|
Log($" ● {action}_file: {sourcePath} -> {destinationPath}");
|
||||||
|
|
||||||
if (!File.Exists(sourcePath))
|
if (!File.Exists(sourcePath))
|
||||||
return $"ERROR: Source file not found: {sourcePath}";
|
return $"ERROR: Source file not found: {sourcePath}";
|
||||||
@@ -221,9 +221,8 @@ internal static partial class EditTools
|
|||||||
{
|
{
|
||||||
content = SanitizeNewLines(content);
|
content = SanitizeNewLines(content);
|
||||||
path = FileTools.ResolvePath(path);
|
path = FileTools.ResolvePath(path);
|
||||||
Log($"WRITE_TO_FILE: {path}");
|
Log($" ● write_to_file: {path}");
|
||||||
Log($" Mode: {mode}");
|
Log($" mode: {mode} with {content.Length} lines");
|
||||||
Log($" Writing {content.Length} lines");
|
|
||||||
|
|
||||||
try
|
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)
|
[Description("Array of operations to apply. Operations are applied in bottom-to-top order automatically.")] BatchOperation[] operations)
|
||||||
{
|
{
|
||||||
path = FileTools.ResolvePath(path);
|
path = FileTools.ResolvePath(path);
|
||||||
Log($"BATCH_EDIT: {path}");
|
Log($" ● batch_edit: {path}");
|
||||||
Log($" Operations: {operations.Length}");
|
Log($" operations: {operations.Length}");
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
return $"ERROR: File not found: {path}";
|
return $"ERROR: File not found: {path}";
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ internal static class FileTools
|
|||||||
[Description("Last line to return (inclusive). Use 0 for EOF. Defaults to 0.")] int endLine = 0)
|
[Description("Last line to return (inclusive). Use 0 for EOF. Defaults to 0.")] int endLine = 0)
|
||||||
{
|
{
|
||||||
path = ResolvePath(path);
|
path = ResolvePath(path);
|
||||||
Log($"Reading file: {path} {startLine}:{endLine}L");
|
Log($" ● read_file: {path} {startLine}:{endLine}L");
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
return $"ERROR: File not found: {path}";
|
return $"ERROR: File not found: {path}";
|
||||||
@@ -62,7 +62,7 @@ internal static class FileTools
|
|||||||
[Description("Path to the directory.")] string path = ".")
|
[Description("Path to the directory.")] string path = ".")
|
||||||
{
|
{
|
||||||
path = ResolvePath(path);
|
path = ResolvePath(path);
|
||||||
Log($"Listing directory: {path}");
|
Log($" ● list_dir: {path}");
|
||||||
|
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
return $"ERROR: Directory not found: {path}";
|
return $"ERROR: Directory not found: {path}";
|
||||||
@@ -95,7 +95,7 @@ internal static class FileTools
|
|||||||
[Description("Glob pattern (supports * and **).")] string pattern)
|
[Description("Glob pattern (supports * and **).")] string pattern)
|
||||||
{
|
{
|
||||||
path = ResolvePath(path);
|
path = ResolvePath(path);
|
||||||
Log($"Finding files: {pattern} in {path}");
|
Log($" ● find_files: {pattern} in {path}");
|
||||||
|
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
return $"ERROR: Directory not found: {path}";
|
return $"ERROR: Directory not found: {path}";
|
||||||
@@ -139,7 +139,7 @@ internal static class FileTools
|
|||||||
|
|
||||||
if (mode == "file")
|
if (mode == "file")
|
||||||
{
|
{
|
||||||
Log($"Searching file: {path}");
|
Log($" ● grep_file: {path}");
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
if (Directory.Exists(path))
|
if (Directory.Exists(path))
|
||||||
@@ -186,7 +186,7 @@ internal static class FileTools
|
|||||||
}
|
}
|
||||||
else if (mode == "recursive")
|
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 (!Directory.Exists(path))
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
@@ -297,7 +297,7 @@ internal static class FileTools
|
|||||||
[Description("Path to the file.")] string path)
|
[Description("Path to the file.")] string path)
|
||||||
{
|
{
|
||||||
path = ResolvePath(path);
|
path = ResolvePath(path);
|
||||||
Log($"Getting file info: {path}");
|
Log($" ● get_file_info: {path}");
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
return $"ERROR: File not found: {path}";
|
return $"ERROR: File not found: {path}";
|
||||||
|
|||||||
Reference in New Issue
Block a user