mod workspace_fs¶
- module workspace_fs¶
Sandboxed reads and edits for recipe workspaces.
eb_recipe_read,eb_recipe_list,eb_recipe_grep,eb_recipe_edit, andeb_recipe_writeresolve every path against one workspace root. A..component, an absolute path outside that root, or a symlink whose target leaves the root is rejected before the file is opened.Variables
- const MAX_GREP_MATCHES: usize¶
Default and upper bound for the number of lines
grep_workspacereturns.
- const MAX_WORKSPACE_FILE_BYTES: u64¶
Largest recipe-workspace file the file tools will read or write.
Functions
- fn apply_suggestion_workspace(root: &Path, requested: &Path, start: usize, end: usize, replacement: &str, expect: Option<&str>, first_seen: Option<&str>) -> Result<WorkspaceLineEdit, String>¶
replace_lines_workspacefor a review suggestion, with two guards (proof v7: an empty suggestion applied by line number after an earlier edit had moved the lines deleted a closing]):without
expect, when the file changed sincefirst_seen(the file as the review showed it, whose numbering the suggestion uses), the anchored lines offirst_seenare theexpect, so moved lines are found where they are now and a stale range writes nothing;a write that turns a valid file into invalid Python is undone and reported as an error.
- fn configured_workspace_root() -> Result<PathBuf, String>¶
Workspace root for the recipe file tools.
EB_STACK_WORKSPACEwins when it is set and non-empty. Otherwise the server’s current directory is the root.eb-stack mcp --workspacesets the environment variable before serving.
- fn edit_workspace(root: &Path, requested: &Path, old: &str, new: &str, replace_all: bool) -> Result<WorkspaceEdit, String>¶
Replace an exact
oldstring in a workspace file.oldis literal text. When it matches more than once andreplace_allis false, the file is left unchanged and the error tells the caller to passreplace_allor a longer unique string.
- fn edit_workspace_checked(root: &Path, requested: &Path, old: &str, new: &str, replace_all: bool, within: Option<&str>, occurrence: Option<usize>) -> Result<WorkspaceScopedEdit, String>¶
edit_workspace_scopedfor a Python module (.py) that refuses to turn valid Python into invalid Python: the file is written back as it was and the error names the line the edit broke. Other files, and a module that was already invalid, are edited as before.
- fn edit_workspace_scoped(root: &Path, requested: &Path, old: &str, new: &str, replace_all: bool, within: Option<&str>, occurrence: Option<usize>) -> Result<WorkspaceScopedEdit, String>¶
Like
edit_workspace, but able to address one list entry.withinnames a('name', ...)entry (a component, extension or dependency); only occurrences ofoldinside it are considered. When two entries share the name,occurrence(1-based) picks one of them, else the call fails and lists them. Withoutwithin,occurrencepicks the n-th match ofold. An ambiguous match fails with the line and entry of every occurrence, so near-identical components cannot be edited by accident; areplace_allthat changes several different entries succeeds and says which ones innote.
- fn exclusive_temp_path(prefix: &str) -> std::io::Result<PathBuf>¶
A new empty file under the temporary directory.
The name is not a function of the process id alone, so two calls in one process do not share a file.
create_newrefuses a path that already exists, including a symlink planted in a shared temporary directory.
- fn grep_workspace(root: &Path, requested: &Path, pattern: &str, regex: bool, max_matches: Option<usize>) -> Result<WorkspaceGrep, String>¶
Search UTF-8 files under
requested(a file or directory insideroot).patternis literal text unlessregexis true. Symlinks are not followed,.gitis skipped, and files that are not UTF-8 or are larger thanMAX_WORKSPACE_FILE_BYTESare skipped. At mostmax_matcheslines are returned (default and capMAX_GREP_MATCHES).
- fn list_workspace(root: &Path, requested: &Path) -> Result<WorkspaceList, String>¶
List one directory inside
rootwithout following symlinks.
- fn read_workspace(root: &Path, requested: &Path) -> Result<WorkspaceText, String>¶
Read a UTF-8 file that resolves inside
root.
- fn replace_lines_workspace(root: &Path, requested: &Path, start: usize, end: usize, replacement: &str, expect: Option<&str>) -> Result<WorkspaceLineEdit, String>¶
Replace lines
start..=end(1-based) withreplacement, the way GitHub applies a review suggestion to the lines its comment is anchored on: an emptyreplacementdeletes them. Withexpect(the anchored lines as the review showed them), the lines must match it ignoring surrounding whitespace; when they do not, a unique place where they do is used instead, otherwise the call fails and nothing is written.
- fn resolve_inside(root: &Path, requested: &Path) -> Result<(PathBuf, PathBuf), String>¶
Resolve
requestedinsideroot: the canonical root and the path, refusing.., absolute paths outside the root and symlinks that leave it.
- fn write_workspace(root: &Path, requested: &Path, content: &str) -> Result<WorkspaceWrite, String>¶
Create or overwrite a UTF-8 file inside
root.Parent directories must already exist. The call does not follow a symlink that leaves the workspace.
Structs and Unions
- struct WorkspaceEdit¶
Result of an exact string replacement.
- path: String¶
Edited path, relative to the workspace root.
- replaced: usize¶
Number of times
oldwas replaced.
- bytes: usize¶
Byte length after the edit.
- struct WorkspaceEntry¶
One directory entry. Symlinks are not followed.
- name: String¶
File name inside the listed directory.
- kind: String¶
file,dir,symlink, orother.
- escapes: bool¶
True when this entry is a symlink whose target leaves the workspace.
- struct WorkspaceGrep¶
Result of searching the workspace.
- pattern: String¶
The pattern searched for.
- regex: bool¶
True when
patternwas a regular expression, false for literal text.
- matches: Vec<WorkspaceMatch>¶
Matching lines, in path then line order.
- files_searched: usize¶
Number of UTF-8 text files read.
- truncated: bool¶
True when the search stopped at the match limit.
- struct WorkspaceLineEdit¶
Result of
replace_lines_workspace.- path: String¶
Edited path, relative to the workspace root.
- replaced_lines: (usize, usize)¶
1-based first and last line that were replaced (before the edit).
- removed: Vec<String>¶
The lines that were removed.
- added: usize¶
Number of lines written in their place (0 deletes them).
- relocated: bool¶
True when
expectwas found at another place than the given lines (earlier edits moved them).
- expect_from_first_seen: bool¶
True when no
expectwas passed and the anchored lines of the file as first seen were used asexpect(the file had changed since).
- bytes: usize¶
Byte length after the edit.
- struct WorkspaceList¶
Directory listing.
- path: String¶
Listed path, relative to the workspace root.
- entries: Vec<WorkspaceEntry>¶
Entries sorted by name.
- struct WorkspaceMatch¶
One matching line.
- path: String¶
File path relative to the workspace root.
- line: usize¶
1-based line number.
- text: String¶
The line, without its newline.
- struct WorkspaceScopedEdit¶
Result of
edit_workspace_scoped.- path: String¶
Edited path, relative to the workspace root.
- replaced: usize¶
Number of times
oldwas replaced.
- bytes: usize¶
Byte length after the edit.
- lines: Vec<usize>¶
1-based line of each replaced occurrence, in the file before the edit.
- entries: Vec<String>¶
Name of the list entry (component, extension, dependency tuple) each replaced occurrence sits in; empty for top-level text.
- note: Option<String>¶
Set when one call changed several different entries.