Interface AbstractFilesystem
- All Known Subinterfaces:
AbstractSandboxFilesystem
- All Known Implementing Classes:
BakedContextFilesystem,BaseSandboxFilesystem,CompositeFilesystem,LocalFilesystem,LocalFilesystemWithShell,OverlayFilesystem,PinnedSandboxFilesystem,ProjectAwareOverlay,RemoteFilesystem,RoutedSandboxFilesystem,SandboxBackedFilesystem
Implementations may target the local disk, a sandbox, a key-value store, or other storage.
Host-rooted types LocalFilesystem and LocalFilesystemWithShell also expose
constructors that take the workspace root as a String path (same semantics as
Path).
Every operation accepts a RuntimeContext so stores can scope work to the current
session, user, or sandbox. Callers that are not inside a tool/agent call with a merged context
should pass RuntimeContext.empty().
-
Method Summary
Modifier and TypeMethodDescriptionDelete a file or directory (recursive for directories).downloadFiles(io.agentscope.core.agent.RuntimeContext runtimeContext, List<String> paths) Download multiple files.edit(io.agentscope.core.agent.RuntimeContext runtimeContext, String filePath, String oldString, String newString, boolean replaceAll) Perform exact string replacements in an existing file.booleanCheck whether a file or directory exists.Find files matching a glob pattern.grep(io.agentscope.core.agent.RuntimeContext runtimeContext, String pattern, String path, String glob) Search for a literal text pattern in files.List all files in a directory with metadata.Move (rename) a file or directory fromfromPathtotoPath.read(io.agentscope.core.agent.RuntimeContext runtimeContext, String filePath, int offset, int limit) Read file content with optional line-based pagination.uploadFiles(io.agentscope.core.agent.RuntimeContext runtimeContext, List<Map.Entry<String, byte[]>> files) Upload multiple files.static voidvalidatePath(String path) Validates thatpathis safe (non-null, non-blank, no..traversal).Write content to a new file, error if file already exists.
-
Method Details
-
ls
List all files in a directory with metadata.- Parameters:
runtimeContext- per-call agent runtime;RuntimeContext.empty()when nonepath- absolute path to the directory to list (must start with '/')- Returns:
- LsResult with directory entries or error
-
read
ReadResult read(io.agentscope.core.agent.RuntimeContext runtimeContext, String filePath, int offset, int limit) Read file content with optional line-based pagination.- Parameters:
runtimeContext- per-call agent runtime;RuntimeContext.empty()when nonefilePath- absolute path to the file to read (must start with '/')offset- line number to start reading from (0-indexed). Default: 0limit- maximum number of lines to read. Default: 2000- Returns:
- ReadResult with file data on success or error on failure
-
write
WriteResult write(io.agentscope.core.agent.RuntimeContext runtimeContext, String filePath, String content) Write content to a new file, error if file already exists.- Parameters:
runtimeContext- per-call agent runtime;RuntimeContext.empty()when nonefilePath- absolute path where the file should be createdcontent- string content to write to the file- Returns:
- WriteResult with path on success, or error if the file already exists or write fails
-
edit
EditResult edit(io.agentscope.core.agent.RuntimeContext runtimeContext, String filePath, String oldString, String newString, boolean replaceAll) Perform exact string replacements in an existing file.- Parameters:
runtimeContext- per-call agent runtime;RuntimeContext.empty()when nonefilePath- absolute path to the file to editoldString- exact string to search for and replacenewString- string to replace oldString with (must be different from oldString)replaceAll- if true, replace all occurrences; if false, oldString must be unique- Returns:
- EditResult with path and occurrence count on success, or error on failure
-
grep
GrepResult grep(io.agentscope.core.agent.RuntimeContext runtimeContext, String pattern, String path, String glob) Search for a literal text pattern in files.- Parameters:
runtimeContext- per-call agent runtime;RuntimeContext.empty()when nonepattern- literal string to search for (not regex)path- optional directory path to search in (null searches current working directory)glob- optional glob pattern to filter which files to search (e.g., "*.java")- Returns:
- GrepResult with matches or error
-
glob
GlobResult glob(io.agentscope.core.agent.RuntimeContext runtimeContext, String pattern, String path) Find files matching a glob pattern.- Parameters:
runtimeContext- per-call agent runtime;RuntimeContext.empty()when nonepattern- glob pattern with wildcards to match file pathspath- base directory to search from (default: "/")- Returns:
- GlobResult with matching files or error
-
uploadFiles
List<FileUploadResponse> uploadFiles(io.agentscope.core.agent.RuntimeContext runtimeContext, List<Map.Entry<String, byte[]>> files) Upload multiple files.- Parameters:
runtimeContext- per-call agent runtime;RuntimeContext.empty()when nonefiles- list of path-to-content mappings to upload- Returns:
- list of FileUploadResponse objects, one per input file (order matches input order)
-
downloadFiles
List<FileDownloadResponse> downloadFiles(io.agentscope.core.agent.RuntimeContext runtimeContext, List<String> paths) Download multiple files.- Parameters:
runtimeContext- per-call agent runtime;RuntimeContext.empty()when nonepaths- list of file paths to download- Returns:
- list of FileDownloadResponse objects, one per input path (order matches input order)
-
delete
Delete a file or directory (recursive for directories).Idempotent: deleting a path that does not exist is treated as success.
- Parameters:
runtimeContext- per-call agent runtime;RuntimeContext.empty()when nonepath- absolute path to the file or directory to delete- Returns:
- WriteResult success when deleted (or already absent), failure on I/O error
-
move
WriteResult move(io.agentscope.core.agent.RuntimeContext runtimeContext, String fromPath, String toPath) Move (rename) a file or directory fromfromPathtotoPath.Implementations that span multiple stores (e.g.
CompositeFilesystem) may fall back to a read + write + delete sequence when source and destination live in different backend filesystems.- Parameters:
runtimeContext- per-call agent runtime;RuntimeContext.empty()when nonefromPath- absolute source pathtoPath- absolute destination path- Returns:
- WriteResult success on completion, failure on I/O error or missing source
-
exists
Check whether a file or directory exists.Implementations may approximate this with a lightweight read probe where a dedicated
existsAPI is unavailable, but should avoid reading full file content.- Parameters:
runtimeContext- per-call agent runtime;RuntimeContext.empty()when nonepath- absolute path to check- Returns:
trueif the path exists,falseotherwise
-
validatePath
Validates thatpathis safe (non-null, non-blank, no..traversal).- Parameters:
path- the path to validate- Throws:
IllegalArgumentException- if the path is invalid
-