refactor(harness): route workflow persistence through repositories

This commit is contained in:
User
2026-07-16 18:01:29 +02:00
parent 259f021313
commit c1cddaa667
30 changed files with 925 additions and 348 deletions
+11 -9
View File
@@ -15,6 +15,7 @@ from dataclasses import dataclass
from pathlib import Path
from tht.phase import effective_decisions
from tht.session.models import SessionSnapshot
from tht.workflow import load_workflow
MAX_BODY_BYTES = 80_000 # ~20k token (target per task document di una fase)
@@ -50,7 +51,7 @@ def _slice_schema_linking(raw: str, promoted_tables: list[str] | None) -> str:
def generate_task_doc(
session_dir: Path | str,
session_dir: Path | str | SessionSnapshot,
phase: int,
promoted_tables: list[str] | None = None,
) -> TaskDoc:
@@ -62,20 +63,21 @@ def generate_task_doc(
- Brief delle decisioni effective (esclude stale post-rollback, esclude ritirate).
- Header del task con il numero/nome della fase.
"""
session_dir = Path(session_dir)
snapshot = session_dir if isinstance(session_dir, SessionSnapshot) else None
session_dir = None if snapshot is not None else Path(session_dir)
parts: list[str] = []
q = session_dir / "question.md"
if q.exists():
parts.append("## Domanda\n" + q.read_text())
question = snapshot.artifacts.get("question") if snapshot else (session_dir / "question.md").read_text() if (session_dir / "question.md").exists() else None
if question:
parts.append("## Domanda\n" + question)
sl = session_dir / "schema_linking.json"
if sl.exists() and phase >= 4:
sliced = _slice_schema_linking(sl.read_text(), promoted_tables)
linking = snapshot.artifacts.get("schema_linking") if snapshot else (session_dir / "schema_linking.json").read_text() if (session_dir / "schema_linking.json").exists() else None
if linking and phase >= 4:
sliced = _slice_schema_linking(linking, promoted_tables)
parts.append("## Schema linking (deciso)\n```json\n" + sliced + "\n```")
# Brief decisioni effective (D15-aware)
eff = effective_decisions(session_dir)
eff = effective_decisions(snapshot or session_dir)
if eff:
lines = [f"- {d.type} | {d.subject} | {d.detail}" for d in eff]
parts.append("## Decisioni effettive (effective)\n" + "\n".join(lines))