-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
53 lines (39 loc) · 1.68 KB
/
Copy pathsettings.py
File metadata and controls
53 lines (39 loc) · 1.68 KB
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
"""Persisted user settings, stored at ./.tuffy/settings.json (gitignored,
same as .tuffy/mcp.json). Today this only holds the user's chosen default
model id, set via '/models default <id>', so it survives restarts without
editing code."""
import json
import os
# Resolved against this package's own location, not the caller's cwd — see
# src/models/registry.py and src/memory.py for the same fix and why it
# matters once tuffy is imported from a different cwd (e.g. tuffy-ui/backend).
_REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SETTINGS_PATH = os.path.join(_REPO_ROOT, ".tuffy", "settings.json")
def _load() -> dict:
if not os.path.exists(SETTINGS_PATH):
return {}
try:
with open(SETTINGS_PATH, "r") as f:
return json.load(f)
except (json.JSONDecodeError, OSError):
return {}
def _save(data: dict) -> None:
os.makedirs(os.path.dirname(SETTINGS_PATH), exist_ok=True)
with open(SETTINGS_PATH, "w") as f:
json.dump(data, f, indent=2)
def get_default_model() -> str | None:
"""Returns the user's persisted default model id, or None if never set
(first run) - caller falls back to the hardcoded DEFAULT_MODEL."""
return _load().get("default_model")
def set_default_model(model_id: str) -> None:
data = _load()
data["default_model"] = model_id
_save(data)
def get_network_mode() -> str | None:
"""Returns the user's last-chosen network mode ('online'/'offline'), or
None if never set (first run) - caller decides the first-run default."""
return _load().get("network_mode")
def set_network_mode(mode: str) -> None:
data = _load()
data["network_mode"] = mode
_save(data)