"""Resolve server-side artifacts stored outside student workspaces.""" from __future__ import annotations import hashlib from pathlib import Path def private_workspace_dir(workspace_path: str | Path) -> Path: from architect.repo_cloner import WORKSPACES_DIR workspace = Path(workspace_path).resolve() root = Path(WORKSPACES_DIR).resolve() relative = workspace.relative_to(root) if ".private" in relative.parts: raise ValueError("Private artifacts cannot be nested as a student workspace") key = hashlib.sha256(relative.as_posix().encode("utf-8")).hexdigest() return root / ".private" / key def ensure_private_workspace_dir(workspace_path: str | Path) -> Path: directory = private_workspace_dir(workspace_path) directory.mkdir(parents=True, exist_ok=True) directory.chmod(0o700) return directory