"""Workspace YAML loading — the single boundary for workspace configuration (spec D3). Reads workspaces/.yaml, expands ${VAR} from env, validates via the Config model (ported from the reference implementation). Future migration to a DB store would replace only this module. La struttura YAML rispecchia esattamente tht/config.py: database + rest (DWH), vector_rest + vector_write_rest (pgvector, doppia key top-level), vector_db (loading diretto, server-only), embeddings, evidence, execution. """ from __future__ import annotations from pathlib import Path from tht.config import Config, ConfigError, load_config class WorkspaceError(Exception): """Errore di caricamento del workspace (file mancante, env var non definita, yaml invalido).""" def load_workspace(path: str | Path) -> Config: """Carica e valida un workspace YAML. Espande ${VAR} dall'ambiente; se una variabile referenziata manca, raises WorkspaceError. Delega a load_config (portato da the reference implementation) per la validazione del modello Config. """ path = Path(path) try: return load_config(path) except ConfigError as e: raise WorkspaceError(str(e)) from e