feat: add P2 harness machine contracts

This commit is contained in:
2026-08-11 05:24:44 +02:00
parent 783cc3bb34
commit b235132d89
6 changed files with 463 additions and 199 deletions
+35 -10
View File
@@ -1,3 +1,4 @@
# ruff: noqa: BLE001
from pathlib import Path
import typer
@@ -116,22 +117,18 @@ def init_cmd(
)
@vector_app.command("index-schema")
def index_schema_cmd(config: Path = CONFIG_OPT) -> None:
"""Embedda e sincronizza i record schema (tabelle e colonne) nel semantic store."""
def index_schema_data(config: Path) -> dict:
"""Synchronize schema records and return a bounded machine result."""
from tht.cli.schema_cmd import _machine_config
from tht.mschema.models import Annotations, PhysicalSchema
from tht.vectorstore.records import schema_records
cfg = _load_config_or_exit(config)
cfg = _machine_config(config)
require_vector_write_allowed(cfg, "vector index-schema")
require_vector_cfg(cfg)
phys_file = physical_path(cfg)
if not phys_file.exists():
typer.secho(
f"ERRORE: {phys_file} non trovato. Esegui prima `tht schema introspect`.",
fg=typer.colors.RED, err=True,
)
raise typer.Exit(code=1)
raise ValueError("physical schema missing")
physical = PhysicalSchema.from_yaml(phys_file)
annotations = Annotations.from_yaml(annotations_path(cfg))
records = schema_records(physical, annotations)
@@ -143,4 +140,32 @@ def index_schema_cmd(config: Path = CONFIG_OPT) -> None:
store=build_vector_store(cfg, require_write=True),
embedder=make_embedder(cfg.embeddings),
)
_print_stats(stats)
return {
"status": "succeeded",
"code": "ok",
"counts": {
"added": stats.added,
"updated": stats.updated,
"deleted": stats.deleted,
"unchanged": stats.unchanged,
},
}
@vector_app.command("index-schema")
def index_schema_cmd(
config: Path = CONFIG_OPT,
json_output: bool = typer.Option(False, "--json", help="Emetti JSON puro su stdout."),
) -> None:
"""Embedda e sincronizza i record schema (tabelle e colonne) nel semantic store."""
if json_output:
try:
payload = index_schema_data(config)
except Exception:
payload = {"status": "failed", "code": "schema_index_failed"}
typer.echo(__import__("json").dumps(payload, sort_keys=True, separators=(",", ":")))
raise typer.Exit(code=1) from None
typer.echo(__import__("json").dumps(payload, sort_keys=True, separators=(",", ":")))
return
payload = index_schema_data(config)
_print_stats(type("Stats", (), payload["counts"])())