Flatten cases directory structure and unify paths

- Remove cases/new|in-progress|completed subdivision (status managed in DB)
- Rename documents/original → documents/originals (consistent plural)
- Move exports from global data/exports/ into cases/{num}/exports/
- Add documents/research/ for case law and analysis files
- Update all agents, scripts, config, web API endpoints, and DB paths

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-09 14:33:27 +00:00
parent 4d674bf475
commit 22e819363e
17 changed files with 1203 additions and 62 deletions

View File

@@ -53,28 +53,15 @@ GOOGLE_CLOUD_VISION_API_KEY = os.environ.get("GOOGLE_CLOUD_VISION_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"
EXPORTS_DIR = DATA_DIR / "exports" # legacy exports only
# 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")))
CASES_NEW = CASES_BASE / "new"
CASES_IN_PROGRESS = CASES_BASE / "in-progress"
CASES_COMPLETED = CASES_BASE / "completed"
CASES_DIR = CASES_NEW # backwards compatibility — new cases default here
_STATUS_DIRS = [CASES_NEW, CASES_IN_PROGRESS, CASES_COMPLETED]
# Cases directory — flat structure: data/cases/{case_number}/
CASES_DIR = DATA_DIR / "cases"
def find_case_dir(case_number: str) -> Path:
"""Find a case directory across all status folders.
Returns the existing directory, or defaults to CASES_NEW/{case_number}.
"""
for base in _STATUS_DIRS:
candidate = base / case_number
if candidate.exists():
return candidate
return CASES_NEW / case_number
"""Return the case directory for a given case number."""
return CASES_DIR / case_number
# Chunking parameters
CHUNK_SIZE_TOKENS = 600

View File

@@ -169,9 +169,9 @@ 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 — versioned under data/exports/{case_number}/
# Determine output path — versioned under cases/{case_number}/exports/
if not output_path:
export_dir = config.EXPORTS_DIR / case["case_number"]
export_dir = config.find_case_dir(case["case_number"]) / "exports"
export_dir.mkdir(parents=True, exist_ok=True)
# Find next version number
existing = sorted(export_dir.glob("טיוטה-v*.docx"))

View File

@@ -1,6 +1,6 @@
"""Lessons learned from comparing AI drafts to Dafna Tamir's final decisions.
Source: /data/uploads/לקחים-לעדכון-שרת-כתיבת-החלטות.md
Source: docs/legal-decision-lessons.md
Based on analysis of: Hecht 1180-1181 (rejection) and Beit HaKerem 1126/25+1141/25 (partial acceptance).
"""

View File

@@ -39,7 +39,7 @@ async def document_upload(
title = source.stem
# Copy file to case directory
case_dir = config.find_case_dir(case_number) / "documents"
case_dir = config.find_case_dir(case_number) / "documents" / "originals"
case_dir.mkdir(parents=True, exist_ok=True)
dest = case_dir / source.name
shutil.copy2(str(source), str(dest))