nodestep.workspace.integrations.virtual ¶
InMemoryWorkspace, which keeps an agent's files in memory.
See Workspaces.
InMemoryWorkspace¶
Workspace kept in memory, with the same rules as LocalWorkspace.
Subclass of Workspace.
root_dir | Path |
Not available; the workspace has no directory on disk. |
Methods
resolve_path(path)¶
Normalize a path, refusing anything outside the root.
resolve_path(path)¶resolve_path(path) -> tuple[Path, str]
path | str | None |
Path relative to the root; |
tuple[Path, str] |
The path under the placeholder root |
PathAccessError |
If the path leaves the root or fails |
read_file(path)¶
Read a file.
read_file(path)¶read_file(path) -> str
path | str |
Path relative to the workspace root. |
FileNotFoundError |
If the file does not exist. |
IsADirectoryError |
If the path is a directory. |
PathAccessError |
If the path leaves the root or fails |
write_file(path, content)¶
Write a file; parent directories exist as soon as a file is in them.
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. |
FileExistsError |
If a parent of the path is a file. |
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 or directory; the root cannot be deleted.
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. |
PathAccessError |
If the path leaves the root or fails |
glob(pattern, path)¶
List files matching a glob pattern.
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.
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; |
FileNotFoundError |
If |
error |
If |
PathAccessError |
If |