diff --git a/harness/.gitignore b/harness/.gitignore index e38bdab7..af38b5f0 100644 --- a/harness/.gitignore +++ b/harness/.gitignore @@ -4,6 +4,10 @@ __pycache__/ .venv/ sessions/ indexes/ +artifacts/ +# Per-customer active workspace (points at the customer repo via -c or symlink). +# The committed templates live in workspaces/*.example.yaml; config/ holds the active one. +config/tht.yaml *.egg-info/ dist/ build/ diff --git a/harness/tht/session/models.py b/harness/tht/session/models.py index beb0c22e..89d8c154 100644 --- a/harness/tht/session/models.py +++ b/harness/tht/session/models.py @@ -1,14 +1,30 @@ from datetime import datetime -from typing import Literal +from pathlib import Path +from typing import Literal, Self +import yaml from pydantic import BaseModel, Field, ConfigDict -# Stub locale di _YamlModel (in the reference implementation vive in mschema/models.py). -# Qui serve solo come base con populate_by_name; mschema/ sara' portato nel Task A9. +# Stub locale di _YamlModel. In the reference implementation questa base vive in +# mschema/models.py; qui la si replica perche' SessionManifest ha bisogno di +# populate_by_name=True (db_schema usa l'alias "schema"), che la base mschema non +# imposta. Identici to_yaml/from_yaml della controparte mschema. class _YamlModel(BaseModel): model_config = ConfigDict(populate_by_name=True) + def to_yaml(self, path: Path) -> None: + path.parent.mkdir(parents=True, exist_ok=True) + data = self.model_dump(by_alias=True, mode="json", exclude_defaults=False) + path.write_text( + yaml.safe_dump(data, sort_keys=False, allow_unicode=True, width=120) + ) + + @classmethod + def from_yaml(cls, path: Path) -> Self: + raw = yaml.safe_load(path.read_text()) + return cls.model_validate(raw) + class SessionManifest(_YamlModel): id: str