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:
@@ -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(...),
|
||||
|
||||
Reference in New Issue
Block a user