Repository navigation
Expand file tree
/
Copy pathbridge.py
More file actions
101 lines (79 loc) · 3 KB
/
Copy pathbridge.py
File metadata and controls
101 lines (79 loc) · 3 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# bridge.py — Scryptian skill runtime: state, profile, and notifications.
# No LLM access — each skill brings its own LLM endpoint.
import os
import json
import threading
_DATA_DIR = os.path.join(os.environ.get("LOCALAPPDATA", os.path.expanduser("~")), "Scryptian", "state")
_PROFILE_PATH = os.path.join(_DATA_DIR, "_profile.json")
_state_lock = threading.Lock()
def get_profile() -> dict:
"""Read shared user profile. Readable by all skills."""
try:
if os.path.exists(_PROFILE_PATH):
with open(_PROFILE_PATH, "r", encoding="utf-8") as f:
return json.load(f)
except Exception:
pass
return {}
def set_profile(data: dict) -> None:
"""Merge data into shared user profile."""
with _state_lock:
try:
os.makedirs(_DATA_DIR, exist_ok=True)
current = get_profile()
current.update(data)
with open(_PROFILE_PATH, "w", encoding="utf-8") as f:
json.dump(current, f, ensure_ascii=False, indent=2)
except Exception:
pass
def get_state(skill_id: str) -> dict:
"""Read per-skill isolated state."""
try:
path = os.path.join(_DATA_DIR, f"{skill_id}.json")
if os.path.exists(path):
with open(path, "r", encoding="utf-8") as f:
return json.load(f)
except Exception:
pass
return {}
def set_state(skill_id: str, data: dict) -> None:
"""Merge data into per-skill isolated state."""
with _state_lock:
try:
os.makedirs(_DATA_DIR, exist_ok=True)
current = get_state(skill_id)
current.update(data)
path = os.path.join(_DATA_DIR, f"{skill_id}.json")
with open(path, "w", encoding="utf-8") as f:
json.dump(current, f, ensure_ascii=False, indent=2)
except Exception:
pass
_root_ref = None
def set_root(root) -> None:
"""Register the Tk root so notify() can render the custom popup on the UI thread.
Called once by the host at startup. Skills never call this.
"""
global _root_ref
_root_ref = root
def notify(title: str, message: str, action=None) -> None:
"""Show a Scryptian notification. Safe to call from any skill or thread.
Uses the custom in-app popup (bottom-right, branded, with sound) when the UI
is available, marshalling onto the Tk main thread. Falls back to a native
tray notification if the UI root is not registered.
action (optional): {"label": "Open file", "hotkey": "alt+q", "callback": callable}
Skills should use this for long-running progress (start/finish) feedback.
"""
import tray
if _root_ref is not None:
try:
_root_ref.after(
0, lambda: tray.show_notify_popup(title, message, _root_ref, action=action)
)
return
except Exception:
pass
try:
tray.notify(title, message)
except Exception:
pass
# LLM access removed: each skill brings its own LLM endpoint.