"""Sanitize CLI output to avoid absolute machine paths (§K4.9).""" from __future__ import annotations from pathlib import Path def sanitize_text(text: str, repo_root: Path) -> str: """Replace the resolved repo root prefix with ``.`` in free-form text.""" root = str(repo_root.resolve()) return text.replace(root, ".") def format_config_error(exc, repo_root: Path) -> str: """Format a config error without leaking absolute paths.""" return exc.message def config_exit_code(exc) -> int: """Map a ``ConfigError`` to its CLI exit code (default ``2``).""" code = getattr(exc, "exit_code", None) return code if isinstance(code, int) else 2