Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces new filesystem tools—ReadFileTool, FileEditTool, and GrepTool—and updates the local and sandbox booters to support these operations. It also implements a security layer to restrict file access for non-admin users in local environments. The review feedback highlights potential memory issues when reading or editing large files in their entirety and suggests applying the documented default limit for file reads to prevent excessive memory consumption.
| with open(abs_path, "rb") as f: | ||
| raw_content = f.read() |
There was a problem hiding this comment.
Reading the entire file into memory using f.read() is inefficient and risky for large files, potentially leading to Out-Of-Memory (OOM) errors. Since the tool supports offset and limit, consider reading the file in chunks or using f.seek() if the encoding allows, to only load the required portion of the file.
| limit: int | None = None, | ||
| ) -> dict[str, Any]: | ||
| _ = encoding | ||
| content = await self._sandbox.filesystem.read_file(path) |
| with open(abs_path, encoding=encoding) as f: | ||
| content = f.read() |
| before_context=before_context, | ||
| line_number=True, | ||
| ) | ||
| return {"success": True, "content": "".join(results)} |
| def _validate_read_window( | ||
| offset: int | None, | ||
| limit: int | None, | ||
| ) -> tuple[int | None, int | None]: | ||
| if offset is not None and offset < 0: | ||
| raise ValueError("`offset` must be greater than or equal to 0.") | ||
| if limit is not None and limit < 1: | ||
| raise ValueError("`limit` must be greater than or equal to 1.") | ||
| return offset, limit |
There was a problem hiding this comment.
The limit parameter in ReadFileTool is documented to default to 4000, but this default is not applied in the validation logic. If the LLM does not provide a limit, the booter will receive None and attempt to read the entire file. Applying the default here ensures consistent behavior and protects against large reads.
| def _validate_read_window( | |
| offset: int | None, | |
| limit: int | None, | |
| ) -> tuple[int | None, int | None]: | |
| if offset is not None and offset < 0: | |
| raise ValueError("`offset` must be greater than or equal to 0.") | |
| if limit is not None and limit < 1: | |
| raise ValueError("`limit` must be greater than or equal to 1.") | |
| return offset, limit | |
| def _validate_read_window( | |
| offset: int | None, | |
| limit: int | None, | |
| ) -> tuple[int | None, int | None]: | |
| if offset is not None and offset < 0: | |
| raise ValueError("offset must be greater than or equal to 0.") | |
| if limit is not None and limit < 1: | |
| raise ValueError("limit must be greater than or equal to 1.") | |
| return offset, limit if limit is not None else 4000 |
Modifications / 改动点
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Add filesystem tools for searching, reading, and editing files across local, sandbox, and Shipyard runtimes, with user-aware access restrictions and pagination support.
New Features:
Enhancements:
Build: