Enforce session workspace boundaries

This commit is contained in:
武阳
2026-05-08 17:09:07 +08:00
parent 5b14f55736
commit 0bbba2b936
13 changed files with 509 additions and 52 deletions
+8 -5
View File
@@ -182,10 +182,6 @@ def _resolve_input_paths(root: str | Path, paths: list[str], *, max_files: int)
path = Path(raw).expanduser()
candidate = path if path.is_absolute() else root_path / path
candidate = candidate.resolve()
try:
candidate.relative_to(root_path)
except ValueError as exc:
raise DataAgentInputError(f'path escapes workspace root: {raw}') from exc
if not candidate.exists():
raise DataAgentInputError(f'path not found: {raw}')
if candidate.is_dir():
@@ -210,7 +206,7 @@ def _load_one_source(
max_cell_chars: int,
) -> dict[str, Any]:
suffix = path.suffix.lower()
rel_path = path.relative_to(root).as_posix()
rel_path = _display_input_path(path, root)
source: dict[str, Any] = {
'path': rel_path,
'kind': suffix.lstrip('.'),
@@ -238,6 +234,13 @@ def _load_one_source(
return source
def _display_input_path(path: Path, root: Path) -> str:
try:
return path.relative_to(root).as_posix()
except ValueError:
return path.as_posix()
def _load_xlsx(path: Path, source: dict[str, Any], *, max_tables: int, max_rows: int, max_cell_chars: int) -> None:
try:
import openpyxl # type: ignore[import-not-found]