Doing final pass of adjustments with anythingllm

This commit is contained in:
2026-02-22 09:54:36 -05:00
parent 34ed257cd6
commit 254ca8cbda
5 changed files with 77 additions and 31 deletions

View File

@@ -43,6 +43,7 @@ import re as _re
# base_dirs : set of resolved absolute Path dirs that act as roots
_allowed_paths: set[Path] = set()
_base_dirs: set[Path] = set()
_primary_base_dir: Path | None = None
def configure(file_items: list[dict], extra_base_dirs: list[str] | None = None):
@@ -53,9 +54,10 @@ def configure(file_items: list[dict], extra_base_dirs: list[str] | None = None):
file_items : list of dicts from aggregate.build_file_items()
extra_base_dirs : additional directory roots to allow traversal of
"""
global _allowed_paths, _base_dirs
global _allowed_paths, _base_dirs, _primary_base_dir
_allowed_paths = set()
_base_dirs = set()
_primary_base_dir = Path(extra_base_dirs[0]).resolve() if extra_base_dirs else Path.cwd()
for item in file_items:
p = item.get("path")
@@ -96,7 +98,10 @@ def _resolve_and_check(raw_path: str) -> tuple[Path | None, str]:
Returns (resolved_path, error_string). error_string is empty on success.
"""
try:
p = Path(raw_path).resolve()
p = Path(raw_path)
if not p.is_absolute() and _primary_base_dir:
p = _primary_base_dir / p
p = p.resolve()
except Exception as e:
return None, f"ERROR: invalid path '{raw_path}': {e}"
if not _is_allowed(p):