FilesystemBackend¶
FilesystemBackend
¶
Bases: BackendProtocol
Backend that reads and writes files directly from the filesystem.
Files are accessed using their actual filesystem paths. Relative paths are resolved relative to the current working directory. Content is read/written as plain text, and metadata (timestamps) are derived from filesystem stats.
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initialize filesystem backend. |
ls_info |
List files and directories in the specified directory (non-recursive). |
read |
Read file content with line numbers. |
write |
Create a new file with content. |
edit |
Edit a file by replacing string occurrences. |
grep_raw |
Search for a regex pattern in files. |
glob_info |
Find files matching a glob pattern. |
upload_files |
Upload multiple files to the filesystem. |
download_files |
Download multiple files from the filesystem. |
als_info |
Async version of ls_info. |
aread |
Async version of read. |
agrep_raw |
Async version of grep_raw. |
aglob_info |
Async version of glob_info. |
awrite |
Async version of write. |
aedit |
Async version of edit. |
aupload_files |
Async version of upload_files. |
adownload_files |
Async version of download_files. |
__init__
¶
__init__(
root_dir: str | Path | None = None,
virtual_mode: bool = False,
max_file_size_mb: int = 10,
) -> None
Initialize filesystem backend.
| PARAMETER | DESCRIPTION |
|---|---|
root_dir
|
Optional root directory for file operations. If provided, all file paths will be resolved relative to this directory. If not provided, uses the current working directory. |
virtual_mode
|
Enables sandboxed operation where all paths are treated as
virtual paths rooted at Path traversal (using
TYPE:
|
max_file_size_mb
|
Maximum file size in megabytes for operations like grep's Python fallback search. Files exceeding this limit are skipped during search. Defaults to 10 MB.
TYPE:
|
ls_info
¶
List files and directories in the specified directory (non-recursive).
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Absolute directory path to list files from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[FileInfo]
|
List of |
read
¶
Read file content with line numbers.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
Absolute or relative file path.
TYPE:
|
offset
|
Line offset to start reading from (0-indexed).
TYPE:
|
limit
|
Maximum number of lines to read.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Formatted file content with line numbers, or error message. |
write
¶
Create a new file with content.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
Path where the new file will be created.
TYPE:
|
content
|
Text content to write to the file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
WriteResult
|
|
edit
¶
Edit a file by replacing string occurrences.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
Path to the file to edit.
TYPE:
|
old_string
|
The text to search for and replace.
TYPE:
|
new_string
|
The replacement text.
TYPE:
|
replace_all
|
If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EditResult
|
|
grep_raw
¶
Search for a regex pattern in files.
Uses ripgrep if available, falling back to Python regex search.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
Regular expression pattern to search for.
TYPE:
|
path
|
Directory or file path to search in. Defaults to current directory.
TYPE:
|
glob
|
Optional glob pattern to filter which files to search.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[GrepMatch] | str
|
List of GrepMatch dicts containing path, line number, and matched text. |
list[GrepMatch] | str
|
Returns an error string if the regex pattern is invalid. |
glob_info
¶
Find files matching a glob pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
Glob pattern to match files against (e.g.,
TYPE:
|
path
|
Base directory to search from. Defaults to root (
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[FileInfo]
|
List of |
upload_files
¶
download_files
¶
aread
async
¶
Async version of read.
agrep_raw
async
¶
agrep_raw(
pattern: str, path: str | None = None, glob: str | None = None
) -> list[GrepMatch] | str
Async version of grep_raw.
aglob_info
async
¶
Async version of glob_info.
aedit
async
¶
Async version of edit.
aupload_files
async
¶
Async version of upload_files.