feat: introduce FileTools for LLM-accessible file system operations including read, list, find, and grep.
This commit is contained in:
@@ -142,7 +142,10 @@ internal static class FileTools
|
|||||||
Log($"Searching file: {path}");
|
Log($"Searching file: {path}");
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
return $"ERROR: File not found: {path}";
|
if (Directory.Exists(path))
|
||||||
|
return $"ERROR: {path} is a directory, not a file.";
|
||||||
|
else
|
||||||
|
return $"ERROR: File not found: {path}";
|
||||||
|
|
||||||
Regex regex;
|
Regex regex;
|
||||||
try
|
try
|
||||||
@@ -178,7 +181,7 @@ internal static class FileTools
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return $"ERROR searching '{path}': {ex.Message}";
|
return $"ERROR searching '{path}': {ex.Message}\nThis is a bug, tell the user about it.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mode == "recursive")
|
else if (mode == "recursive")
|
||||||
@@ -186,7 +189,10 @@ internal static class FileTools
|
|||||||
Log($"Recursive grep: {pattern} in {path}" + (filePattern != null ? $" (files: {filePattern})" : ""));
|
Log($"Recursive grep: {pattern} in {path}" + (filePattern != null ? $" (files: {filePattern})" : ""));
|
||||||
|
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
return $"ERROR: Directory not found: {path}";
|
if (File.Exists(path))
|
||||||
|
return $"ERROR: {path} is a file, not a directory.";
|
||||||
|
else
|
||||||
|
return $"ERROR: Directory not found: {path}";
|
||||||
|
|
||||||
Regex regex;
|
Regex regex;
|
||||||
try
|
try
|
||||||
@@ -244,7 +250,7 @@ internal static class FileTools
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return $"ERROR in recursive grep: {ex.Message}";
|
return $"ERROR in recursive grep: {ex.Message}.\nThis is a bug, tell the user about it.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user