Class LocalFilesystemBackend
java.lang.Object
com.alibaba.cloud.ai.graph.agent.extension.file.LocalFilesystemBackend
- All Implemented Interfaces:
FilesystemBackend
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.
Security and search upgrades:
- Secure path resolution with root containment when in virtual_mode (sandboxed to cwd)
- Prevent symlink-following on file I/O
- Ripgrep-powered grep with JSON parsing, plus Java fallback with regex
and optional glob include filtering, while preserving virtual path behavior
-
Constructor Summary
ConstructorsConstructorDescriptionLocalFilesystemBackend(String rootDir) LocalFilesystemBackend(String rootDir, boolean virtualMode, int maxFileSizeMb) Initialize filesystem backend. -
Method Summary
Modifier and TypeMethodDescriptionEdit file by replacing string occurrences.Find files matching glob pattern.Search for pattern in files using regex.List files and directories in the specified directory (non-recursive).Read file content with line numbers and pagination.Write content to a new file.
-
Constructor Details
-
LocalFilesystemBackend
Initialize filesystem backend.- Parameters:
rootDir- 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.virtualMode- When true, treat incoming paths as virtual absolute paths under cwd, disallow traversal (.., ~) and ensure resolved path stays within root.maxFileSizeMb- Maximum file size in MB for reading operations
-
LocalFilesystemBackend
-
-
Method Details
-
lsInfo
Description copied from interface:FilesystemBackendList files and directories in the specified directory (non-recursive).- Specified by:
lsInfoin interfaceFilesystemBackend- Parameters:
path- Absolute directory path to list files from- Returns:
- List of FileInfo objects for files and directories directly in the directory. Directories have a trailing / in their path and isDir=true.
-
read
Description copied from interface:FilesystemBackendRead file content with line numbers and pagination.- Specified by:
readin interfaceFilesystemBackend- Parameters:
filePath- Absolute or relative file pathoffset- Line offset to start reading from (0-indexed)limit- Maximum number of lines to read- Returns:
- Formatted file content with line numbers, or error message
-
write
Description copied from interface:FilesystemBackendWrite content to a new file.- Specified by:
writein interfaceFilesystemBackend- Parameters:
filePath- Absolute or relative file pathcontent- Content to write- Returns:
- WriteResult with path or error. External storage sets filesUpdate=null.
-
edit
Description copied from interface:FilesystemBackendEdit file by replacing string occurrences.- Specified by:
editin interfaceFilesystemBackend- Parameters:
filePath- Absolute or relative file patholdString- String to replacenewString- Replacement stringreplaceAll- Whether to replace all occurrences- Returns:
- EditResult with occurrences count or error. External storage sets filesUpdate=null.
-
globInfo
Description copied from interface:FilesystemBackendFind files matching glob pattern.- Specified by:
globInfoin interfaceFilesystemBackend- Parameters:
pattern- Glob pattern (e.g., "*.py", "**/*.ts")path- Base path to search from- Returns:
- List of FileInfo objects for matching files
-
grepRaw
Description copied from interface:FilesystemBackendSearch for pattern in files using regex.- Specified by:
grepRawin interfaceFilesystemBackend- Parameters:
pattern- Regex pattern to search forpath- Base path to search from (null for current directory)glob- Glob pattern to filter files (null for all files)- Returns:
- List of GrepMatch objects or error message
-