Implementazione del piano di remediation progressiva sui difetti emersi dall'analisi dell'harness. Tutto verificato: 214 test Python (incl. L0 su Postgres reale), 14 test JS del gate, ruff pulito. Blocco 1 (CRITICA, integrazione gate↔CLI): - phase advance: gate usa --auto + exit 6; reviewer_confirm kind:phase fa advance esplicito che applica i prerequisiti (prima non avanzava per le fasi a conferma umana). - cte plan riceve i --name dal gate (param names); set-question con id posizionale; skill `tht search find`; nuovo comando `tht memory save-one` con dedup hash client-side in save_one_memory. Blocco 2 (D15, stato post-rollback): - campo `phase` su DecisionRecord + effective_decisions phase-aware per i subject "a nome" (cte_approved ecc.); _compute_promotions e finalize sulla vista effective; finalize confronta col piano CTE effettivo, non glob; `decision add --retracts` + comando `decision retract`. Blocco 3 (D7 read-only + D6 manifest): - assert_read_only su tutti e quattro i codepath (direct + REST); - manifest author/summary/updated_at/updated_by/schema_version popolati + helper touch_manifest sulle mutazioni. Blocco 4-5 (D14a/D14b): - decision_min_phase data-driven via `emits:` in workflow.yaml; - formula evidence: status auto, search_formulas, gruppo CLI `tht formula`, `search find --kind formula`, load_evidence_dir salta i .sql.md. Blocco 6 (robustezza): - taskdoc slice promoted_tables + bound enforced; report escaping/bound + rsplit note; filtro kind reader REST/direct; conteggio upserted robusto; guard REST run_query non-list; LSH disallineato -> LshIndexError. Blocco 7 (pulizia): - dead code gate e KIND_TO_TABLE morto rimossi; doc Postgres-only (README + connection.py). Blocco 0 (parziale): test di compatibilità firma gate↔CLI (tests/integration). Rinviati: fake-Pi runtime completo, artifact-gate da disco (#23), parità eligibility REST/direct (#28), unificazione reserved-labels (#30), memory_rejected da deselezione (#33). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
67 lines
2.5 KiB
Python
67 lines
2.5 KiB
Python
from pathlib import Path
|
|
from typing import Literal
|
|
|
|
import yaml
|
|
from pydantic import BaseModel, ValidationError
|
|
|
|
|
|
class EvidenceError(Exception):
|
|
pass
|
|
|
|
|
|
class EvidenceDoc(BaseModel):
|
|
id: str
|
|
title: str
|
|
# tier e status sono opzionali: la sola presenza di un documento basta a
|
|
# vettorizzarlo, quindi l'autore ETL non e' obbligato a compilarli.
|
|
tier: Literal["structural", "concept"] = "structural"
|
|
status: Literal["auto", "draft", "reviewed"] = "reviewed"
|
|
sources: list[str] = []
|
|
tables: list[str] = []
|
|
concepts: list[str] = []
|
|
body: str = ""
|
|
path: Path | None = None # valorizzato al load, escluso dal dump
|
|
|
|
@classmethod
|
|
def parse(cls, text: str, path: Path | None = None) -> "EvidenceDoc":
|
|
if not text.startswith("---\n"):
|
|
raise EvidenceError(f"frontmatter mancante in {path or '<testo>'}")
|
|
try:
|
|
_, fm, body = text.split("---\n", 2)
|
|
except ValueError as e:
|
|
raise EvidenceError(f"frontmatter malformato in {path or '<testo>'}") from e
|
|
meta = yaml.safe_load(fm)
|
|
if not isinstance(meta, dict):
|
|
raise EvidenceError(f"frontmatter non valido in {path or '<testo>'}")
|
|
try:
|
|
return cls.model_validate({**meta, "body": body.strip("\n"), "path": path})
|
|
except ValidationError as e:
|
|
raise EvidenceError(f"evidence non valida in {path or '<testo>'}:\n{e}") from e
|
|
|
|
def dump(self) -> str:
|
|
meta = self.model_dump(exclude={"body", "path"}, mode="json")
|
|
fm = yaml.safe_dump(meta, sort_keys=False, allow_unicode=True)
|
|
return f"---\n{fm}---\n{self.body}\n"
|
|
|
|
def save(self, path: Path) -> None:
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text(self.dump())
|
|
self.path = path
|
|
|
|
|
|
def load_evidence_dir(root: Path) -> list[EvidenceDoc]:
|
|
"""Carica ricorsivamente tutte le evidence sotto `root`, preservando la
|
|
gerarchia per dominio. I file README (di sola navigazione) sono ignorati."""
|
|
docs: list[EvidenceDoc] = []
|
|
if not root.is_dir():
|
|
return docs
|
|
for f in sorted(root.rglob("*.md")):
|
|
if f.name.upper().startswith("README"):
|
|
continue
|
|
# I file formula (concept->SQL, frontmatter diverso) vivono sotto formulas/ con
|
|
# estensione .sql.md: non sono EvidenceDoc, li gestisce formula_store (D14b).
|
|
if f.name.endswith(".sql.md"):
|
|
continue
|
|
docs.append(EvidenceDoc.parse(f.read_text(), path=f))
|
|
return docs
|