A / core /content_sync.py
linxinhua's picture
Clone from v5-AI-ethic-HOT-socratic to v5-AI-ethic-HOT-socratic-frame
068faf9 verified
Raw
History Blame Contribute Delete
1.89 kB
"""Mirror generator-input data files from the SSOT
(`AI_Ethic_HOT_chatbot/shared_content/`) into this Space's local `data/`
folder.
Two files are mirrored:
- case_analysis.md (consolidated case material)
- ethics-frameworks.md (the three analytical frameworks)
Both are read by core/perfect_answer.py at session start to generate the
per-session perfect-answer essay.
Runs at app startup. On HF Spaces the SSOT folder doesn't exist (it's local
design infrastructure, never deployed); sync is a silent no-op and the
deployed copies in data/ are used as-is.
"""
import sys
import shutil
from core.config_loader import BASE_DIR
SSOT_PATH = BASE_DIR.parent / "shared_content"
LOCAL_DATA_PATH = BASE_DIR / "data"
GENERATOR_INPUT_FILES = {"case_analysis.md", "ethics-frameworks.md"}
def sync_chapters_from_ssot():
"""Mirror generator inputs from SSOT into local data/. Idempotent.
Function name kept for backwards compatibility with existing app.py
imports; it no longer mirrors chapter files.
"""
if not SSOT_PATH.exists():
return
LOCAL_DATA_PATH.mkdir(parents=True, exist_ok=True)
ssot_files = {
n: SSOT_PATH / n for n in GENERATOR_INPUT_FILES
if (SSOT_PATH / n).exists()
}
local_files = {
p.name: p for p in LOCAL_DATA_PATH.glob("*.md")
if p.name in GENERATOR_INPUT_FILES
}
changes = []
for name, src in ssot_files.items():
dst = local_files.get(name) or (LOCAL_DATA_PATH / name)
if not dst.exists() or src.read_bytes() != dst.read_bytes():
shutil.copy2(src, dst)
changes.append(f"+{name}" if not local_files.get(name) else f"~{name}")
for name in local_files.keys() - ssot_files.keys():
local_files[name].unlink()
changes.append(f"-{name}")
if changes:
print(f"[content_sync] {', '.join(changes)}", file=sys.stderr)