feat(harness): tht session documents --json read command
This commit is contained in:
@@ -218,6 +218,25 @@ def delete_cmd(session_id: str = typer.Argument(...), config: Path = CONFIG_OPT)
|
||||
typer.secho(f"OK: sessione {session_id} eliminata.", fg=typer.colors.GREEN)
|
||||
|
||||
|
||||
@session_app.command("documents")
|
||||
def documents_cmd(
|
||||
session_id: str = typer.Argument(...),
|
||||
json_out: bool = typer.Option(False, "--json", help="Emetti JSON su stdout (pristine)."),
|
||||
config: Path = CONFIG_OPT,
|
||||
) -> None:
|
||||
"""Documenti di sola lettura della sessione (domanda, rivista, schema, SQL, report, decisioni)."""
|
||||
from tht.session.store import build_documents
|
||||
|
||||
cfg = _load_config_or_exit(config)
|
||||
manifest = load_session_or_exit(cfg, session_id)
|
||||
docs = build_documents(manifest, session_dir(cfg, session_id))
|
||||
if json_out:
|
||||
typer.echo(json.dumps(docs, ensure_ascii=False, indent=2))
|
||||
return
|
||||
for d in docs:
|
||||
typer.echo(f"[{d['phase']}] {d['title']} ({d['format']})")
|
||||
|
||||
|
||||
def session_problems(cfg, session_id: str) -> list[str]:
|
||||
"""Problemi del Blocco 3 (decisioni + schema_linking). Riusato da check e finalize."""
|
||||
import json
|
||||
|
||||
@@ -164,3 +164,27 @@ def delete_session(session_id: str, sessions_root: Path) -> None:
|
||||
"""Hard-delete the session directory. SessionError if it does not exist."""
|
||||
load_session(session_id, sessions_root) # raises SessionError if absent
|
||||
shutil.rmtree(sessions_root / session_id)
|
||||
|
||||
|
||||
def build_documents(manifest: SessionManifest, session_dir: Path) -> list[dict]:
|
||||
"""Ordered, read-only document bundle for the UI panel. Only documents that exist
|
||||
on disk are returned. CTE artifacts (F6) are intentionally excluded (intermediate)."""
|
||||
docs: list[dict] = [{
|
||||
"phase": "—", "key": "question", "title": "Domanda originale",
|
||||
"format": "text", "content": manifest.question,
|
||||
}]
|
||||
spec = [
|
||||
("question.md", "F3", "revised_question", "Domanda rivista", "markdown"),
|
||||
("schema_linking.json", "F4", "schema_linking", "Schema linking", "schema-linking"),
|
||||
("sql_final.sql", "F7", "sql", "SQL finale", "sql"),
|
||||
("validation_report.md", "finalize", "validation_report", "Report di validazione", "markdown"),
|
||||
("review_decisions.jsonl", "—", "decisions", "Decisioni", "decisions"),
|
||||
]
|
||||
for filename, phase, key, title, fmt in spec:
|
||||
path = session_dir / filename
|
||||
if path.exists():
|
||||
docs.append({
|
||||
"phase": phase, "key": key, "title": title,
|
||||
"format": fmt, "content": path.read_text(),
|
||||
})
|
||||
return docs
|
||||
|
||||
Reference in New Issue
Block a user