Class: Leash::Integration::FilesystemClient
- Inherits:
-
Object
- Object
- Leash::Integration::FilesystemClient
- Defined in:
- lib/leash/integration/filesystem.rb
Instance Method Summary collapse
-
#create_directory(path) ⇒ Object
Create a new directory or ensure a directory exists.
-
#directory_tree(path, excludepatterns: nil) ⇒ Object
Get a recursive tree view of files and directories as a JSON structure.
-
#edit_file(path, edits, dryrun: nil) ⇒ Object
Make line-based edits to a text file.
-
#get_file_info(path) ⇒ Object
Retrieve detailed metadata about a file or directory.
-
#initialize(leash) ⇒ FilesystemClient
constructor
Create a new Filesystem integration client.
-
#list_allowed_directories ⇒ Object
Returns the list of directories that this server is allowed to access.
-
#list_directory(path) ⇒ Object
Get a detailed listing of all files and directories in a specified path.
-
#list_directory_with_sizes(path, sortby: nil) ⇒ Object
Get a detailed listing of all files and directories in a specified path, including sizes.
-
#move_file(source, destination) ⇒ Object
Move or rename files and directories.
-
#read_file(path, tail: nil, head: nil) ⇒ Object
Read the complete contents of a file as text.
-
#read_media_file(path) ⇒ Object
Read an image or audio file.
-
#read_multiple_files(paths) ⇒ Object
Read the contents of multiple files simultaneously.
-
#read_text_file(path, tail: nil, head: nil) ⇒ Object
Read the complete contents of a file from the file system as text.
-
#search_files(path, pattern, excludepatterns: nil) ⇒ Object
Recursively search for files and directories matching a pattern.
-
#write_file(path, content) ⇒ Object
Create a new file or completely overwrite an existing file with new content.
Constructor Details
#initialize(leash) ⇒ FilesystemClient
Create a new Filesystem integration client.
11 12 13 |
# File 'lib/leash/integration/filesystem.rb', line 11 def initialize(leash) @leash = leash end |
Instance Method Details
#create_directory(path) ⇒ Object
Create a new directory or ensure a directory exists. Can create multiple nested directories in one operation. If the directory already exists, this operation will succeed silently. Perfect for sett…
99 100 101 102 103 104 |
# File 'lib/leash/integration/filesystem.rb', line 99 def create_directory(path) params = { 'path' => path }.compact @leash.call('filesystem', 'create_directory', params) end |
#directory_tree(path, excludepatterns: nil) ⇒ Object
Get a recursive tree view of files and directories as a JSON structure. Each entry includes ‘name’, ‘type’ (file/directory), and ‘children’ for directories. Files have no children array, while dire…
135 136 137 138 139 140 141 |
# File 'lib/leash/integration/filesystem.rb', line 135 def directory_tree(path, excludepatterns: nil) params = { 'path' => path, 'excludePatterns' => excludepatterns }.compact @leash.call('filesystem', 'directory_tree', params) end |
#edit_file(path, edits, dryrun: nil) ⇒ Object
Make line-based edits to a text file. Each edit replaces exact line sequences with new content. Returns a git-style diff showing the changes made. Only works within allowed directories.
86 87 88 89 90 91 92 93 |
# File 'lib/leash/integration/filesystem.rb', line 86 def edit_file(path, edits, dryrun: nil) params = { 'path' => path, 'edits' => edits, 'dryRun' => dryrun }.compact @leash.call('filesystem', 'edit_file', params) end |
#get_file_info(path) ⇒ Object
Retrieve detailed metadata about a file or directory. Returns comprehensive information including size, creation time, last modified time, permissions, and type. This tool is perfect for understand…
175 176 177 178 179 180 |
# File 'lib/leash/integration/filesystem.rb', line 175 def get_file_info(path) params = { 'path' => path }.compact @leash.call('filesystem', 'get_file_info', params) end |
#list_allowed_directories ⇒ Object
Returns the list of directories that this server is allowed to access. Subdirectories within these allowed directories are also accessible. Use this to understand which directories and their nested…
185 186 187 188 |
# File 'lib/leash/integration/filesystem.rb', line 185 def list_allowed_directories params = {} @leash.call('filesystem', 'list_allowed_directories', params) end |
#list_directory(path) ⇒ Object
Get a detailed listing of all files and directories in a specified path. Results clearly distinguish between files and directories with [FILE] and [DIR] prefixes. This tool is essential for underst…
110 111 112 113 114 115 |
# File 'lib/leash/integration/filesystem.rb', line 110 def list_directory(path) params = { 'path' => path }.compact @leash.call('filesystem', 'list_directory', params) end |
#list_directory_with_sizes(path, sortby: nil) ⇒ Object
Get a detailed listing of all files and directories in a specified path, including sizes. Results clearly distinguish between files and directories with [FILE] and [DIR] prefixes. This tool is usef…
122 123 124 125 126 127 128 |
# File 'lib/leash/integration/filesystem.rb', line 122 def list_directory_with_sizes(path, sortby: nil) params = { 'path' => path, 'sortBy' => sortby }.compact @leash.call('filesystem', 'list_directory_with_sizes', params) end |
#move_file(source, destination) ⇒ Object
Move or rename files and directories. Can move files between directories and rename them in a single operation. If the destination exists, the operation will fail. Works across different directorie…
148 149 150 151 152 153 154 |
# File 'lib/leash/integration/filesystem.rb', line 148 def move_file(source, destination) params = { 'source' => source, 'destination' => destination }.compact @leash.call('filesystem', 'move_file', params) end |
#read_file(path, tail: nil, head: nil) ⇒ Object
Read the complete contents of a file as text. DEPRECATED: Use read_text_file instead.
21 22 23 24 25 26 27 28 |
# File 'lib/leash/integration/filesystem.rb', line 21 def read_file(path, tail: nil, head: nil) params = { 'path' => path, 'tail' => tail, 'head' => head }.compact @leash.call('filesystem', 'read_file', params) end |
#read_media_file(path) ⇒ Object
Read an image or audio file. Returns the base64 encoded data and MIME type. Only works within allowed directories.
49 50 51 52 53 54 |
# File 'lib/leash/integration/filesystem.rb', line 49 def read_media_file(path) params = { 'path' => path }.compact @leash.call('filesystem', 'read_media_file', params) end |
#read_multiple_files(paths) ⇒ Object
Read the contents of multiple files simultaneously. This is more efficient than reading files one by one when you need to analyze or compare multiple files. Each file’s content is returned with its…
60 61 62 63 64 65 |
# File 'lib/leash/integration/filesystem.rb', line 60 def read_multiple_files(paths) params = { 'paths' => paths }.compact @leash.call('filesystem', 'read_multiple_files', params) end |
#read_text_file(path, tail: nil, head: nil) ⇒ Object
Read the complete contents of a file from the file system as text. Handles various text encodings and provides detailed error messages if the file cannot be read. Use this tool when you need to exa…
36 37 38 39 40 41 42 43 |
# File 'lib/leash/integration/filesystem.rb', line 36 def read_text_file(path, tail: nil, head: nil) params = { 'path' => path, 'tail' => tail, 'head' => head }.compact @leash.call('filesystem', 'read_text_file', params) end |
#search_files(path, pattern, excludepatterns: nil) ⇒ Object
Recursively search for files and directories matching a pattern. The patterns should be glob-style patterns that match paths relative to the working directory. Use pattern like ‘*.ext’ to match fil…
162 163 164 165 166 167 168 169 |
# File 'lib/leash/integration/filesystem.rb', line 162 def search_files(path, pattern, excludepatterns: nil) params = { 'path' => path, 'pattern' => pattern, 'excludePatterns' => excludepatterns }.compact @leash.call('filesystem', 'search_files', params) end |
#write_file(path, content) ⇒ Object
Create a new file or completely overwrite an existing file with new content. Use with caution as it will overwrite existing files without warning. Handles text content with proper encoding. Only wo…
72 73 74 75 76 77 78 |
# File 'lib/leash/integration/filesystem.rb', line 72 def write_file(path, content) params = { 'path' => path, 'content' => content }.compact @leash.call('filesystem', 'write_file', params) end |