Files
ThothII/harness/nsp/workspace.py
T
marcopan 6ba3336775 feat(harness): config.py + workspace.py (D3 confine) + chirone.example.yaml
- config.py ported from ChironeWp3, PSD_PROFILE -> THOTH_PROFILE; dual vector key
  (vector_rest/vector_write_rest top-level) preserved verbatim
- workspace.py: thin boundary wrapper (D3) around load_config
- workspaces/chirone.example.yaml: aligned to the real Config shape
- tests/test_workspace.py: 2 tests (env expand + dual key; missing env raises)
- .env.example: added DWH + DOCS_ROOT vars
All tests pass (2/2).
2026-06-26 22:25:00 +02:00

32 lines
1.1 KiB
Python

"""Workspace YAML loading — the single boundary for workspace configuration (spec D3).
Reads workspaces/<name>.yaml, expands ${VAR} from env, validates via the Config model
(ported from ChironeWp3). Future migration to a DB store would replace only this module.
La struttura YAML rispecchia esattamente nsp/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 nsp.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 ChironeWp3) per la validazione del modello Config.
"""
path = Path(path)
try:
return load_config(path)
except ConfigError as e:
raise WorkspaceError(str(e)) from e