From 50414e8b8c4e2547fc79a93725e48cd475b33af7 Mon Sep 17 00:00:00 2001 From: Tomi Eckert Date: Fri, 6 Mar 2026 01:23:19 +0100 Subject: [PATCH] feat: introduce FileTools for LLM-accessible file system operations including read, list, find, and grep. --- Tools/FileTools.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Tools/FileTools.cs b/Tools/FileTools.cs index c42ca84..8fad8bd 100644 --- a/Tools/FileTools.cs +++ b/Tools/FileTools.cs @@ -142,7 +142,10 @@ internal static class FileTools Log($"Searching file: {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; try @@ -178,7 +181,7 @@ internal static class FileTools } 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") @@ -186,7 +189,10 @@ internal static class FileTools Log($"Recursive grep: {pattern} in {path}" + (filePattern != null ? $" (files: {filePattern})" : "")); 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; try @@ -244,7 +250,7 @@ internal static class FileTools } 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