File size: 1,362 Bytes
a02272f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37b748e
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Global config (~/.brainconfig) management."""

import json
from pathlib import Path

from brain.paths import get_config_path


def load_config() -> dict:
    """Read ~/.brainconfig. Returns empty dict if missing or malformed."""
    path = get_config_path()
    if not path.exists():
        return {}
    try:
        return json.loads(path.read_text(encoding="utf-8"))
    except (json.JSONDecodeError, OSError):
        return {}


def save_config(config: dict) -> None:
    """Write config to ~/.brainconfig."""
    path = get_config_path()
    path.write_text(json.dumps(config, indent=2), encoding="utf-8")


def get_active_brain() -> Path | None:
    """Return the active Brain Instance path, or None."""
    cfg = load_config()
    raw = cfg.get("active_brain")
    if raw:
        return Path(raw)
    return None


def set_active_brain(path: Path) -> None:
    """Set the active Brain Instance path."""
    cfg = load_config()
    cfg["active_brain"] = str(path.resolve())
    save_config(cfg)


def get_storage_mode() -> str:
    """Return the current project storage mode ('local' or 'global')."""
    cfg = load_config()
    return cfg.get("storage_mode", "local")


def set_storage_mode(mode: str) -> None:
    """Set the project storage mode ('local' or 'global')."""
    cfg = load_config()
    cfg["storage_mode"] = mode
    save_config(cfg)