sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)

This commit is contained in:
gozeros committed 2026-10-21 14:51:31 +08:00
1 parent 4f7f07504a
commit 8bc8b0e082
1651 files changed
+278599 -11416

No files matched your search

@@ -28,7 +28,7 @@ class Sandbox(ABC):
pass
@abstractmethod
def read_file(self, path: str) -> str:
def read_file(self, path: str) -> str:
"""Read the content of a file.
Args:
@@ -37,7 +37,38 @@ class Sandbox(ABC):
Returns:
The content of the file.
"""
pass
pass
def read_file_range(
self,
path: str,
*,
start_line: int = 1,
end_line: int | None = None,
max_chars: int = 32_000,
) -> tuple[str, int | None, bool]:
"""Read a bounded line range.
Providers should override this method to avoid loading the entire file.
The compatibility implementation remains bounded at the tool boundary,
though an older remote provider may still materialize its response.
"""
content = self.read_file(path)
selected: list[str] = []
chars = 0
next_line: int | None = None
for number, line in enumerate(content.splitlines(), start=1):
if number < start_line:
continue
if end_line is not None and number > end_line:
break
addition = len(line) + (1 if selected else 0)
if chars + addition > max_chars:
next_line = number
break
selected.append(line)
chars += addition
return "\n".join(selected), next_line, next_line is not None
@abstractmethod
def list_dir(self, path: str, max_depth=2) -> list[str]: