|
2 | 2 | (:require |
3 | 3 | [babashka.fs :as fs] |
4 | 4 | [clojure.string :as string] |
| 5 | + [eca.features.tools.util :as tools.util] |
5 | 6 | [eca.shared :as shared])) |
6 | 7 |
|
7 | 8 | (set! *warn-on-reflection* true) |
|
24 | 25 |
|
25 | 26 | (defn ^:private path-validations [db] |
26 | 27 | [["path" fs/exists? "$path is not a valid path"] |
27 | | - ["path" (partial allowed-path? db) "Access denied - path $path outside allowed directories"]]) |
28 | | - |
29 | | -(defn ^:private list-allowed-directories [_arguments db] |
30 | | - (single-text-content |
31 | | - (str "Allowed directories:\n" |
32 | | - (string/join "\n" |
33 | | - (map (comp shared/uri->filename :uri) (:workspace-folders db)))))) |
| 28 | + ["path" (partial allowed-path? db) (str "Access denied - path $path outside allowed directories: " (tools.util/workspace-roots-strs db))]]) |
34 | 29 |
|
35 | 30 | (defn ^:private list-directory [arguments db] |
36 | 31 | (let [path (delay (fs/canonicalize (get arguments "path")))] |
|
65 | 60 | (let [pattern (get arguments "pattern") |
66 | 61 | pattern (if (string/includes? pattern "*") |
67 | 62 | pattern |
68 | | - (format "**/%s/**" pattern)) |
| 63 | + (format "**/*%s*" pattern)) |
69 | 64 | paths (reduce |
70 | 65 | (fn [paths {:keys [uri]}] |
71 | 66 | (concat paths (fs/glob (shared/uri->filename uri) |
|
77 | 72 | "No matches found"))))) |
78 | 73 |
|
79 | 74 | (def definitions |
80 | | - {"list_allowed_directories" |
81 | | - {:description (str "Returns the list of directories that this server is allowed to access. " |
82 | | - "Use this to understand which directories are available before trying to access files.") |
83 | | - :parameters {:type "object" |
84 | | - :properties {} |
85 | | - :required []} |
86 | | - :handler #'list-allowed-directories} |
87 | | - "list_directory" |
| 75 | + {"list_directory" |
88 | 76 | {:description (str "Get a detailed listing of all files and directories in a specified path. " |
89 | 77 | "Results clearly distinguish between files and directories with [FILE] and [DIR] " |
90 | 78 | "prefixes. This tool is essential for understanding directory structure and " |
91 | | - "finding specific files within a directory. Only works within workspace root.") |
| 79 | + "finding specific files within a directory." |
| 80 | + "**Only works within the directories: $workspaceRoots.**") |
92 | 81 | :parameters {:type "object" |
93 | 82 | :properties {"path" {:type "string" |
94 | 83 | :description "The absolute path to the directory to list."}} |
|
100 | 89 | "if the file cannot be read. Use this tool when you need to examine " |
101 | 90 | "the contents of a single file. Use the 'head' parameter to read only " |
102 | 91 | "the first N lines of a file, or the 'tail' parameter to read only " |
103 | | - "the last N lines of a file. Only works within allowed directories.") |
| 92 | + "the last N lines of a file." |
| 93 | + "**Only works within the directories: $workspaceRoots.**") |
104 | 94 | :parameters {:type "object" |
105 | 95 | :properties {"path" {:type "string" |
106 | 96 | :description "The absolute path to the file to read."} |
|
113 | 103 | "search_files" |
114 | 104 | {:description (str "Recursively search for files and directories matching a pattern. " |
115 | 105 | "Searches through all subdirectories from the starting path. The search " |
116 | | - "is case-insensitive and matches partial names. Returns full paths to all " |
| 106 | + "is case-insensitive and matches partial names following java's FileSystem#getPathMatcher. Returns full paths to all " |
117 | 107 | "matching items. Great for finding files when you don't know their exact location. " |
118 | | - "Only searches within allowed directories.") |
| 108 | + "**Only works within the directories: $workspaceRoots.**") |
119 | 109 | :parameters {:type "object" |
120 | 110 | :properties {"path" {:type "string" |
121 | 111 | :description "The absolute path to start searching files from there."} |
122 | 112 | "pattern" {:type "string" |
123 | | - :description "Glob pattern matching files or directory names like *.txt or dir/* to include in the result"}} |
| 113 | + :description (str "Glob pattern following java FileSystem#getPathMatcher matching files or directory names." |
| 114 | + "Use '**/*' to match search in multiple levels like '**/*.txt'")}} |
124 | 115 | :required ["path" "pattern"]} |
125 | 116 | :handler #'search-files}}) |
0 commit comments