refactor(harness): renaming prodotto tht (Onda -1)
Thoth (tht) è il prodotto, PSD è il cliente. Nessun riferimento al contesto
clinico nel codice.
Rinomine:
- comando+package nsp→tht (dir nsp/→tht/, 46 import, pyproject entry point)
- gate nsp-gate.js→tht-gate.js (+ rewrite token, relayIfNspFails→relayIfThtFails)
- workspace chirone.{example,test}.yaml→tht.{example,test}.yaml (generici)
- env THOTH_→THT_ (19 var) + NSP_ stragglers (NSP_HARNESS_ROOT, NSP_SESSION)
- commenti/docstring chirone/psdwp3/policlinico neutralizzati ('the reference
implementation', 'the DWH')
Aggiunto [tool.setuptools.packages.find] include=['tht*'] (necessario: l'auto-
discovery rompeva con tht/ + workspaces/ come top-level multipli).
.env operatore aggiornato in-place (prefissi THT_, valori preservati, gitignored).
Verifica: pytest 109 passed, npm test 14 pass, tht phase meta --json OK, zero
residui nsp/THOTH_/NSP_/chirone nel package.
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
DECISIONS_FILE = "review_decisions.jsonl"
|
||||
|
||||
# 22 tipi di the reference implementation (verified leggendo session/decisions.py) + 1 nuovo (D15):
|
||||
# `decision_retracted` per il rollback a granularità step (ritira una decisione
|
||||
# senza cancellarne la riga dal log di audit; effective_decisions la onora).
|
||||
DecisionType = Literal[
|
||||
"concept_clarified",
|
||||
"question_rewritten",
|
||||
"table_promoted",
|
||||
"table_excluded",
|
||||
"column_corrected",
|
||||
"join_modified",
|
||||
"evidence_accepted",
|
||||
"evidence_rejected",
|
||||
"ambiguity_open",
|
||||
"memory_rejected",
|
||||
"cte_approved",
|
||||
"cte_corrected",
|
||||
"cte_rejected",
|
||||
"sql_revised",
|
||||
"sql_approved",
|
||||
"sql_rejected",
|
||||
"phase_approved",
|
||||
"phase_auto_approved",
|
||||
"phase_reopened",
|
||||
"phase_skipped",
|
||||
"datamart_requested",
|
||||
"datamart_declined",
|
||||
# D15: marker di ritrazione. subject = "phase:N", retracts = decision_seq ritirata.
|
||||
# Resta nel log di audit (append-only); effective_decisions() la esclude dalla vista.
|
||||
"decision_retracted",
|
||||
# D14a: valore citato nella domanda ancorato a una o piu' colonne. subject =
|
||||
# "phase:4", detail = il valore (es. "ablazione"), rationale = la/e colonna/e scelta/e
|
||||
# dal reviewer (aggregate_lsh_multi le espone tutte senza collassare al miglior match).
|
||||
"value_grounded",
|
||||
# D14b: formula di concetto approvata/rifiutata dal reviewer. subject = "phase:4",
|
||||
# detail = il concetto (es. "fascia pediatrica"), rationale = la/e colonna/e o il motivo.
|
||||
# retrieve_formula restituisce i candidati; queste decisioni registrano la scelta.
|
||||
"concept_formula_approved",
|
||||
"concept_formula_rejected",
|
||||
]
|
||||
|
||||
|
||||
class DecisionRecord(BaseModel):
|
||||
seq: int
|
||||
ts: datetime
|
||||
type: DecisionType
|
||||
subject: str
|
||||
detail: str = ""
|
||||
rationale: str = ""
|
||||
# D15: se type == "decision_retracted", indica quale seq viene ritirata.
|
||||
retracts: int | None = None
|
||||
|
||||
|
||||
def list_decisions(session_dir: Path) -> list[DecisionRecord]:
|
||||
path = session_dir / DECISIONS_FILE
|
||||
if not path.exists():
|
||||
return []
|
||||
return [
|
||||
DecisionRecord.model_validate_json(line)
|
||||
for line in path.read_text().splitlines()
|
||||
if line.strip()
|
||||
]
|
||||
|
||||
|
||||
def append_decision(
|
||||
session_dir: Path,
|
||||
*,
|
||||
type: str,
|
||||
subject: str,
|
||||
detail: str = "",
|
||||
rationale: str = "",
|
||||
retracts: int | None = None,
|
||||
) -> DecisionRecord:
|
||||
record = DecisionRecord(
|
||||
seq=len(list_decisions(session_dir)) + 1,
|
||||
ts=datetime.now(UTC),
|
||||
type=type,
|
||||
subject=subject,
|
||||
detail=detail,
|
||||
rationale=rationale,
|
||||
retracts=retracts,
|
||||
)
|
||||
path = session_dir / DECISIONS_FILE
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with path.open("a") as f:
|
||||
f.write(record.model_dump_json() + "\n")
|
||||
return record
|
||||
Reference in New Issue
Block a user