|
130 | 130 |
|
131 | 131 | (defn ^:private grep |
132 | 132 | "Searches for files containing patterns using regular expressions. |
133 | | - |
| 133 | +
|
134 | 134 | This function provides a fast content search across files using three different |
135 | 135 | backends depending on what's available: |
136 | 136 | 1. ripgrep (rg) - fastest, preferred when available |
|
182 | 182 | (format "Successfully replaced content in %s." path)) |
183 | 183 | (format "Original content not found in %s" path)))))) |
184 | 184 |
|
| 185 | +(defn ^:private move-file [arguments db] |
| 186 | + (let [workspace-dirs (tools.util/workspace-roots-strs db)] |
| 187 | + (or (invalid-arguments arguments [["source" fs/exists? "$source is not a valid path"] |
| 188 | + ["source" (partial allowed-path? db) (str "Access denied - path $source outside allowed directories: " workspace-dirs)] |
| 189 | + ["destination" (partial allowed-path? db) (str "Access denied - path $destination outside allowed directories: " workspace-dirs)] |
| 190 | + ["destination" (complement fs/exists?) "Path $destination already exists"]]) |
| 191 | + (let [source (get arguments "source") |
| 192 | + destination (get arguments "destination")] |
| 193 | + (fs/move source destination {:replace-existing false}) |
| 194 | + (single-text-content (format "Successfully moved %s to %s" source destination)))))) |
| 195 | + |
185 | 196 | (def definitions |
186 | 197 | {"list_directory" |
187 | 198 | {:description (str "Get a detailed listing of all files and directories in a specified path. " |
|
260 | 271 | :description "Whether to replace all occurences of the file or just the first one (default)"}} |
261 | 272 | :required ["path" "original_content" "new_content"]} |
262 | 273 | :handler #'replace-in-file} |
263 | | - ;; TODO move-file |
| 274 | + "move_file" |
| 275 | + {:description (str "Move or rename files and directories. Can move files between directories " |
| 276 | + "and rename them in a single operation. If the destination exists, the " |
| 277 | + "operation will fail. Works across different directories and can be used " |
| 278 | + "for simple renaming within the same directory. " |
| 279 | + "Both source and destination must be within the directories: $workspaceRoots.") |
| 280 | + :parameters {:type "object" |
| 281 | + :properties {"source" {:type "string" |
| 282 | + :description "The absolute origin file path to move."} |
| 283 | + "destination" {:type "string" |
| 284 | + :description "The new absolute file path to move to."}} |
| 285 | + :required ["source" "destination"]} |
| 286 | + :handler #'move-file} |
264 | 287 | ;; TODO write-file |
265 | 288 | ;; TODO delete-files |
266 | 289 | }) |
0 commit comments