Add exports panel: versioned drafts, download, upload revisions, mark final

Export DOCX now saves to data/exports/{case_number}/ with auto-versioning
(טיוטה-v1, v2...). The case view UI shows all drafts with download buttons,
allows uploading revised versions (עריכה-v1...), and marking a version as
final (copies to training corpus for style learning).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-08 12:10:02 +00:00
parent b2f60d51f4
commit 5a8d5cac0a
4 changed files with 293 additions and 4 deletions

View File

@@ -53,6 +53,7 @@ ANTHROPIC_API_KEY = os.environ.get("ANTHROPIC_API_KEY", "")
# Data directory
DATA_DIR = Path(os.environ.get("DATA_DIR", str(Path.home() / "legal-ai" / "data")))
TRAINING_DIR = DATA_DIR / "training"
EXPORTS_DIR = DATA_DIR / "exports"
# Cases directory — new structure: cases/{new,in-progress,completed}/{case_number}/
CASES_BASE = Path(os.environ.get("CASES_BASE", str(Path.home() / "legal-ai" / "cases")))

View File

@@ -169,11 +169,20 @@ async def export_decision(case_id: UUID, output_path: str | None = None) -> str:
_write_block_to_docx(doc, block_id, block["title"], content)
# Determine output path
# Determine output path — versioned under data/exports/{case_number}/
if not output_path:
case_dir = config.find_case_dir(case["case_number"]) / "output"
case_dir.mkdir(parents=True, exist_ok=True)
output_path = str(case_dir / f"החלטה-{case['case_number']}.docx")
export_dir = config.EXPORTS_DIR / case["case_number"]
export_dir.mkdir(parents=True, exist_ok=True)
# Find next version number
existing = sorted(export_dir.glob("טיוטה-v*.docx"))
next_ver = 1
for p in existing:
try:
ver = int(p.stem.split("-v")[1])
next_ver = max(next_ver, ver + 1)
except (IndexError, ValueError):
pass
output_path = str(export_dir / f"טיוטה-v{next_ver}.docx")
Path(output_path).parent.mkdir(parents=True, exist_ok=True)
doc.save(output_path)