nodestep.workspace.integrations.local ¶
LocalWorkspace, which keeps an agent's files in a folder on disk.
See Workspaces.
LocalWorkspace¶
LocalWorkspace(root_dir, *, create=False, max_file_read_bytes=256000)
Workspace backed by a directory on disk.
Subclass of Workspace.
Paths, globs and symlinks cannot reach outside the root, and paths follow
the rules of check_path listed in
Workspaces.
root_dir | str | Path |
Root directory. |
create | bool |
Create |
max_file_read_bytes | int |
Largest file |
WorkspaceError |
If |
root_dir | Path |
Absolute root directory. |
Methods
resolve_path(path)¶
Resolve a path inside the root, following symlinks.
resolve_path(path)¶resolve_path(path) -> tuple[Path, str]
path | str | None |
Path relative to the root; |
tuple[Path, str] |
Absolute resolved path and the relative path with |
PathAccessError |
If the path, or a symlink target in it, leaves the root, or the path
fails |
read_file(path)¶
Read a UTF-8 text file, keeping its line endings.
read_file(path)¶read_file(path) -> str
path | str |
Path relative to the workspace root. |
FileNotFoundError |
If the file does not exist. |
WorkspaceError |
If the file is larger than |
PathAccessError |
If the path leaves the root or fails |
write_file(path, content)¶
Write a UTF-8 text file as given, creating parent directories.
write_file(path, content)¶write_file(path, content) -> None
path | str |
Path relative to the workspace root. |
content | str | |
IsADirectoryError |
If the path is a directory. |
PathAccessError |
If the path leaves the root or fails |
list_dir(path)¶
List a directory; subdirectories end with /.
list_dir(path)¶list_dir(path='.') -> list[str]
path | str |
Path relative to the workspace root. |
list[str] |
Sorted entry names. |
FileNotFoundError |
If the path does not exist. |
NotADirectoryError |
If the path is a file. |
PathAccessError |
If the path leaves the root or fails |
exists(path)¶
Whether a file or directory exists.
exists(path)¶exists(path) -> bool
path | str |
Path relative to the workspace root. |
PathAccessError |
If the path leaves the root or fails |
delete(path)¶
Delete a file, directory or symlink (never its target).
delete(path)¶delete(path) -> bool
path | str |
Path relative to the workspace root. |
bool |
Whether something was deleted. |
WorkspaceError |
If |
PathAccessError |
If the path leaves the root or fails |
edit(path, old, new, ...)¶
Replace text in a file, keeping its line endings.
edit(path, old, new, ...)¶edit(path, old, new, *, replace_all=False) -> int
In a CRLF file, old and new written with LF match and are
written with CRLF.
path | str |
Path relative to the workspace root. |
old | str |
Text to find. |
new | str |
Its replacement. |
replace_all | bool |
Replace every occurrence instead of the first. |
int |
Number of replacements. |
ValueError |
If |
FileNotFoundError |
If the file does not exist. |
WorkspaceError |
If the file is larger than |
PathAccessError |
If the path leaves the root or fails |
glob(pattern, path)¶
List files matching a glob pattern, without symlinks leaving the root.
glob(pattern, path)¶glob(pattern, path='.') -> list[str]
pattern | str |
Pattern such as |
path | str |
Directory to search from, relative to the root. |
list[str] |
Sorted matching file paths relative to the root. |
FileNotFoundError |
If |
PathAccessError |
If |
grep(pattern, path, ...)¶
Find lines matching a regular expression inside the root.
grep(pattern, path, ...)¶grep(pattern, path='.', *, glob_pattern=None) -> GrepResult
pattern | str |
Regular expression, searched in each line. |
path | str |
File or directory to search, relative to the root. |
glob_pattern | str | None |
Only search the files of a directory |
GrepResult |
Matching lines by relative path, and in |
FileNotFoundError |
If |
error |
If |
PathAccessError |
If |