sync update from LAN repo (source dhk-1 @ 3e87be55)

This commit is contained in:
gozeros committed 2026-10-21 15:06:08 +08:00
1 parent ab6068a7c1
commit 42f2a26fa8
1482 files changed
+227759 -9584

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]: