feat(harness): port memory/search/evidence/db/decision cmd (Onda 3.2)
5 cmd foglia portati con rename + drift fix: - memory_cmd: portato col modello registry INTATTO (TODO marker per il drop registry decisione spec 5 — task separato, richiede L2 per validare il rewrite su vectordb) - search_cmd: creata search_app sub-app (era funzione standalone in ChironeWp3), registrata come 'tht search find' - evidence_cmd, db_cmd, decision_cmd: port verbatim Drift fix decision_cmd: DECISION_MIN_PHASE.get(type,1) -> load_workflow().decision_min_phase(type). Check grep-per-file: ~15 residui nsp/PSD_SSL_CA nei messaggi utente fixati (nsp <cmd> -> tht <cmd>, nsp.yaml -> workspace yaml, PSD_SSL_CA -> THT_SSL_CA). Suite: 165 passed. tht --help ora mostra 10 sottocomandi.
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
from pathlib import Path
|
||||
from typing import get_args
|
||||
|
||||
import typer
|
||||
|
||||
from tht.cli.config_cmd import CONFIG_OPT
|
||||
from tht.cli.schema_cmd import _load_config_or_exit
|
||||
from tht.cli.session_cmd import load_session_or_exit, session_dir
|
||||
|
||||
decision_app = typer.Typer(help="Decisioni del reviewer (per sessione, append-only)")
|
||||
|
||||
|
||||
@decision_app.command("add")
|
||||
def add_cmd(
|
||||
session: str = typer.Option(..., "--session", help="Id della sessione."),
|
||||
type: str = typer.Option(..., "--type", help="Tipo di decisione."),
|
||||
subject: str = typer.Option(..., "--subject", help="Oggetto (tabella, colonna, concetto)."),
|
||||
detail: str = typer.Option("", "--detail"),
|
||||
rationale: str = typer.Option("", "--rationale"),
|
||||
config: Path = CONFIG_OPT,
|
||||
) -> None:
|
||||
"""Registra una decisione del reviewer nella sessione."""
|
||||
from tht.decisions import DecisionType, append_decision
|
||||
|
||||
cfg = _load_config_or_exit(config)
|
||||
load_session_or_exit(cfg, session)
|
||||
valid = get_args(DecisionType)
|
||||
if type not in valid:
|
||||
typer.secho(
|
||||
f"ERRORE: tipo '{type}' non valido. Tipi: {', '.join(valid)}",
|
||||
fg=typer.colors.RED, err=True,
|
||||
)
|
||||
raise typer.Exit(code=1)
|
||||
from tht.cli.phase_cmd import require_phase_or_exit
|
||||
from tht.workflow import load_workflow
|
||||
|
||||
require_phase_or_exit(cfg, session, load_workflow().decision_min_phase(type))
|
||||
sdir = session_dir(cfg, session)
|
||||
if type == "cte_approved":
|
||||
# Un CTE si approva solo se appartiene al piano persistito. Senza piano
|
||||
# (o con subject fuori piano) l'approvazione e' priva di significato:
|
||||
# rifiutala (exit 5) invece di sporcare il ledger. Regressione quo-8,
|
||||
# dove fu registrato un cte_approved:cte_plan senza alcun cte_plan.json.
|
||||
from tht.phase import cte_plan
|
||||
|
||||
plan = cte_plan(sdir)
|
||||
if not plan:
|
||||
typer.secho(
|
||||
"ERRORE: nessun piano CTE (cte_plan.json) in sessione. Persisti prima "
|
||||
"il piano con reviewer_confirm kind:'cte_plan', poi approva i CTE.",
|
||||
fg=typer.colors.RED, err=True,
|
||||
)
|
||||
raise typer.Exit(code=5)
|
||||
if subject not in plan:
|
||||
typer.secho(
|
||||
f"ERRORE: '{subject}' non e' un CTE del piano ({', '.join(plan)}). "
|
||||
"Usa un nome di CTE del piano.",
|
||||
fg=typer.colors.RED, err=True,
|
||||
)
|
||||
raise typer.Exit(code=5)
|
||||
record = append_decision(
|
||||
sdir, type=type, subject=subject,
|
||||
detail=detail, rationale=rationale,
|
||||
)
|
||||
typer.secho(f"OK: decisione [{record.seq}] {record.type}: {record.subject}",
|
||||
fg=typer.colors.GREEN)
|
||||
|
||||
|
||||
@decision_app.command("list")
|
||||
def list_cmd(
|
||||
session: str = typer.Option(..., "--session"),
|
||||
config: Path = CONFIG_OPT,
|
||||
) -> None:
|
||||
"""Elenca le decisioni della sessione."""
|
||||
from tht.decisions import list_decisions
|
||||
|
||||
cfg = _load_config_or_exit(config)
|
||||
load_session_or_exit(cfg, session)
|
||||
decisions = list_decisions(session_dir(cfg, session))
|
||||
if not decisions:
|
||||
typer.echo("Nessuna decisione registrata.")
|
||||
return
|
||||
for d in decisions:
|
||||
line = f"[{d.seq}] {d.ts:%Y-%m-%d %H:%M} {d.type}: {d.subject}"
|
||||
if d.detail:
|
||||
line += f" — {d.detail}"
|
||||
if d.rationale:
|
||||
line += f" ({d.rationale})"
|
||||
typer.echo(line)
|
||||
Reference in New Issue
Block a user