B
File size: 1,892 Bytes
f5f3917
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""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)