feat(cli): 'tht session set-schema-linking' (file/stdin, validated)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 16:44:36 +02:00
co-authored by Claude Opus 4.8
parent 92caaac18d
commit 00777922d8
2 changed files with 98 additions and 0 deletions
+31
View File
@@ -110,6 +110,37 @@ def set_question_cmd(
typer.secho(f"OK: question.md aggiornato ({path}).", fg=typer.colors.GREEN)
@session_app.command("set-schema-linking")
def set_schema_linking_cmd(
session_id: str = typer.Argument(...),
file: str = typer.Option(
..., "--file", "-f",
help="Path al JSON dello schema-linking, oppure '-' per leggere da stdin."),
config: Path = CONFIG_OPT,
) -> None:
"""Valida (modello SchemaLinking) e scrive schema_linking.json deterministicamente."""
import sys
from pydantic import ValidationError
from tht.session.store import set_schema_linking
cfg = _load_config_or_exit(config)
load_session_or_exit(cfg, session_id)
raw = sys.stdin.read() if file == "-" else Path(file).read_text()
try:
data = json.loads(raw)
except json.JSONDecodeError as e:
typer.secho(f"ERRORE: JSON non valido: {e}", fg=typer.colors.RED, err=True)
raise typer.Exit(code=5)
try:
path = set_schema_linking(session_id, data, cfg.paths.sessions)
except ValidationError as e:
typer.secho(f"ERRORE: schema_linking non valido:\n{e}", fg=typer.colors.RED, err=True)
raise typer.Exit(code=5)
typer.secho(f"OK: schema_linking.json aggiornato ({path}).", fg=typer.colors.GREEN)
@session_app.command("show")
def show_cmd(
session_id: str = typer.Argument(...),