from pathlib import Path class WorkspacePathError(ValueError): pass def resolve_workspace_path(workspace: str, relative_path: str) -> Path: root = Path(workspace).resolve() path = (root / relative_path).resolve() if root != path and root not in path.parents: raise WorkspacePathError(f"Path escapes workspace: {relative_path}") return path