Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plugins/disk-cleanup/disk_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ def load_tracked() -> List[Dict[str, Any]]:
return []

try:
return json.loads(tf.read_text())
return json.loads(tf.read_text(encoding="utf-8"))
except (json.JSONDecodeError, ValueError):
bak = tf.with_suffix(".json.bak")
if bak.exists():
try:
data = json.loads(bak.read_text())
data = json.loads(bak.read_text(encoding="utf-8"))
_log("WARN: tracked.json corrupted — restored from .bak")
return data
except Exception:
Expand All @@ -129,7 +129,7 @@ def save_tracked(tracked: List[Dict[str, Any]]) -> None:
tf = get_tracked_file()
tf.parent.mkdir(parents=True, exist_ok=True)
tmp = tf.with_suffix(".json.tmp")
tmp.write_text(json.dumps(tracked, indent=2))
tmp.write_text(json.dumps(tracked, indent=2), encoding="utf-8")
if tf.exists():
shutil.copy2(tf, tf.with_suffix(".json.bak"))
tmp.replace(tf)
Expand Down
6 changes: 3 additions & 3 deletions plugins/google_meet/realtime/openai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _read_queue(self) -> list[dict]:
if not self.queue_path.exists():
return []
out: list[dict] = []
for line in self.queue_path.read_text().splitlines():
for line in self.queue_path.read_text(encoding="utf-8").splitlines():
line = line.strip()
if not line:
continue
Expand All @@ -281,11 +281,11 @@ def _rewrite_queue(self, remaining: list[dict]) -> None:
if not remaining:
# Keep the file but empty — consumers may be watching for
# new writes via mtime, and delete-then-recreate is a race.
self.queue_path.write_text("")
self.queue_path.write_text("", encoding="utf-8")
return
self.queue_path.write_text(
"\n".join(json.dumps(e) for e in remaining) + "\n"
)
, encoding="utf-8")

def _append_processed(self, entry: dict, result: dict) -> None:
if self.processed_path is None:
Expand Down
12 changes: 6 additions & 6 deletions plugins/hermes-achievements/dashboard/plugin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ def load_state() -> Dict[str, Any]:
if not path.exists():
return {"unlocks": {}}
try:
return json.loads(path.read_text())
return json.loads(path.read_text(encoding="utf-8"))
except Exception:
return {"unlocks": {}}


def save_state(state: Dict[str, Any]) -> None:
path = state_path()
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(state, indent=2, sort_keys=True))
path.write_text(json.dumps(state, indent=2, sort_keys=True), encoding="utf-8")


def _json_safe(value: Any) -> Any:
Expand All @@ -185,7 +185,7 @@ def load_snapshot() -> Optional[Dict[str, Any]]:
if not path.exists():
return None
try:
data = json.loads(path.read_text())
data = json.loads(path.read_text(encoding="utf-8"))
if isinstance(data, dict):
return data
except Exception:
Expand All @@ -196,15 +196,15 @@ def load_snapshot() -> Optional[Dict[str, Any]]:
def save_snapshot(data: Dict[str, Any]) -> None:
path = snapshot_path()
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(_json_safe(data), indent=2, sort_keys=True))
path.write_text(json.dumps(_json_safe(data), indent=2, sort_keys=True), encoding="utf-8")


def load_checkpoint() -> Dict[str, Any]:
path = checkpoint_path()
if not path.exists():
return {"schema_version": 1, "generated_at": 0, "sessions": {}}
try:
data = json.loads(path.read_text())
data = json.loads(path.read_text(encoding="utf-8"))
if isinstance(data, dict):
data.setdefault("schema_version", 1)
data.setdefault("generated_at", 0)
Expand All @@ -219,7 +219,7 @@ def load_checkpoint() -> Dict[str, Any]:
def save_checkpoint(data: Dict[str, Any]) -> None:
path = checkpoint_path()
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(_json_safe(data), indent=2, sort_keys=True))
path.write_text(json.dumps(_json_safe(data), indent=2, sort_keys=True), encoding="utf-8")


def session_fingerprint(meta: Dict[str, Any]) -> Dict[str, Any]:
Expand Down
8 changes: 4 additions & 4 deletions plugins/memory/hindsight/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ def save_config(self, values, hermes_home):
existing = {}
if config_path.exists():
try:
existing = json.loads(config_path.read_text())
existing = json.loads(config_path.read_text(encoding="utf-8"))
except Exception:
pass
existing.update(values)
Expand Down Expand Up @@ -895,7 +895,7 @@ def post_setup(self, hermes_home: str, config: dict) -> None:
env_path = Path(hermes_home) / ".env"
existing_llm_key = ""
if env_path.exists():
for line in env_path.read_text().splitlines():
for line in env_path.read_text(encoding="utf-8").splitlines():
if line.startswith("HINDSIGHT_LLM_API_KEY="):
existing_llm_key = line.split("=", 1)[1]
break
Expand Down Expand Up @@ -925,7 +925,7 @@ def post_setup(self, hermes_home: str, config: dict) -> None:
env_path.parent.mkdir(parents=True, exist_ok=True)
existing_lines = []
if env_path.exists():
existing_lines = env_path.read_text().splitlines()
existing_lines = env_path.read_text(encoding="utf-8").splitlines()
updated_keys = set()
new_lines = []
for line in existing_lines:
Expand All @@ -938,7 +938,7 @@ def post_setup(self, hermes_home: str, config: dict) -> None:
for k, v in env_writes.items():
if k not in updated_keys:
new_lines.append(f"{k}={v}")
env_path.write_text("\n".join(new_lines) + "\n")
env_path.write_text("\n".join(new_lines) + "\n", encoding="utf-8")

if mode == "local_embedded":
materialized_config = dict(provider_config)
Expand Down
2 changes: 1 addition & 1 deletion plugins/memory/honcho/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def save_config(self, values, hermes_home):
existing = {}
if config_path.exists():
try:
existing = json.loads(config_path.read_text())
existing = json.loads(config_path.read_text(encoding="utf-8"))
except Exception:
pass
existing.update(values)
Expand Down
2 changes: 1 addition & 1 deletion plugins/memory/mem0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def save_config(self, values, hermes_home):
existing = {}
if config_path.exists():
try:
existing = json.loads(config_path.read_text())
existing = json.loads(config_path.read_text(encoding="utf-8"))
except Exception:
pass
existing.update(values)
Expand Down
10 changes: 5 additions & 5 deletions plugins/memory/mem0/_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _write_env(env_path: Path, env_writes: dict[str, str]) -> None:
env_path.parent.mkdir(parents=True, exist_ok=True)
existing_lines: list[str] = []
if env_path.exists():
existing_lines = env_path.read_text().splitlines()
existing_lines = env_path.read_text(encoding="utf-8").splitlines()

updated_keys: set[str] = set()
new_lines: list[str] = []
Expand All @@ -204,7 +204,7 @@ def _write_env(env_path: Path, env_writes: dict[str, str]) -> None:
if k not in updated_keys:
new_lines.append(f"{k}={v}")

env_path.write_text("\n".join(new_lines) + "\n")
env_path.write_text("\n".join(new_lines) + "\n", encoding="utf-8")


def _save_mem0_json(hermes_home: str, data: dict) -> None:
Expand All @@ -217,7 +217,7 @@ def _save_mem0_json(hermes_home: str, data: dict) -> None:
except Exception:
pass
existing.update(data)
config_path.write_text(json.dumps(existing, indent=2) + "\n")
config_path.write_text(json.dumps(existing, indent=2) + "\n", encoding="utf-8")


def _setup_platform(hermes_home: str, config: dict, flags: dict[str, str]) -> None:
Expand All @@ -237,7 +237,7 @@ def _setup_platform(hermes_home: str, config: dict, flags: dict[str, str]) -> No
config_path = Path(hermes_home) / "mem0.json"
if config_path.exists():
try:
existing_config = json.loads(config_path.read_text())
existing_config = json.loads(config_path.read_text(encoding="utf-8"))
except Exception:
pass

Expand Down Expand Up @@ -375,7 +375,7 @@ def _prompt_api_key(label: str, env_var: str, hermes_home: str) -> str:
if not existing:
env_path = Path(hermes_home) / ".env"
if env_path.exists():
for line in env_path.read_text().splitlines():
for line in env_path.read_text(encoding="utf-8").splitlines():
if line.startswith(f"{env_var}="):
existing = line.split("=", 1)[1].strip()
break
Expand Down
2 changes: 1 addition & 1 deletion plugins/platforms/discord/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6053,7 +6053,7 @@ async def _respond(
home = get_hermes_home()
response_path = home / ".update_response"
tmp = response_path.with_suffix(".tmp")
tmp.write_text(answer)
tmp.write_text(answer, encoding="utf-8")
tmp.replace(response_path)
logger.info(
"Discord update prompt answered '%s' by %s",
Expand Down
2 changes: 1 addition & 1 deletion plugins/platforms/feishu/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,7 @@ def _build_resolved_update_prompt_card(*, answer: str, user_name: str) -> Dict[s
def _write_update_prompt_response(answer: str) -> None:
response_path = get_hermes_home() / ".update_response"
tmp_path = response_path.with_suffix(".tmp")
tmp_path.write_text(answer)
tmp_path.write_text(answer, encoding="utf-8")
tmp_path.replace(response_path)

async def send_voice(
Expand Down
4 changes: 2 additions & 2 deletions plugins/platforms/google_chat/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def load(self) -> None:
self._counts = {}
return
try:
raw = self._path.read_text()
raw = self._path.read_text(encoding="utf-8")
data = json.loads(raw) if raw.strip() else {}
except json.JSONDecodeError as exc:
logger.warning(
Expand Down Expand Up @@ -417,7 +417,7 @@ def _save(self) -> None:
try:
self._path.parent.mkdir(parents=True, exist_ok=True)
tmp = self._path.with_suffix(self._path.suffix + ".tmp")
tmp.write_text(json.dumps(self._counts, separators=(",", ":")))
tmp.write_text(json.dumps(self._counts, separators=(",", ":")), encoding="utf-8")
os.replace(tmp, self._path)
except OSError as exc:
logger.warning(
Expand Down
4 changes: 2 additions & 2 deletions plugins/platforms/google_chat/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def store_client_secret(path: str) -> None:
sys.exit(1)

try:
data = json.loads(src.read_text())
data = json.loads(src.read_text(encoding="utf-8"))
except json.JSONDecodeError:
print("ERROR: File is not valid JSON.")
sys.exit(1)
Expand Down Expand Up @@ -459,7 +459,7 @@ def _load_pending_auth(email: Optional[str] = None) -> dict:
print("ERROR: No pending OAuth session found. Run --auth-url first.")
sys.exit(1)
try:
data = json.loads(pending.read_text())
data = json.loads(pending.read_text(encoding="utf-8"))
except Exception as exc:
print(f"ERROR: Could not read pending OAuth session: {exc}")
print("Run --auth-url again to start a fresh session.")
Expand Down
2 changes: 1 addition & 1 deletion plugins/platforms/telegram/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4464,7 +4464,7 @@ async def _handle_callback_query(
home = get_hermes_home()
response_path = home / ".update_response"
tmp = response_path.with_suffix(".tmp")
tmp.write_text(answer)
tmp.write_text(answer, encoding="utf-8")
tmp.replace(response_path)
logger.info("Telegram update prompt answered '%s' by user %s",
answer, getattr(query.from_user, "id", "unknown"))
Expand Down
8 changes: 4 additions & 4 deletions plugins/platforms/whatsapp/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _kill_stale_bridge_by_pidfile(session_path: Path) -> None:
try:
# Format: line 1 = pid, optional line 2 = kernel start time. Legacy
# files written before the guard existed have only the pid.
lines = pid_file.read_text().split("\n")
lines = pid_file.read_text(encoding="utf-8").split("\n")
pid = int(lines[0].strip())
if len(lines) > 1 and lines[1].strip():
recorded_start = int(lines[1].strip())
Expand Down Expand Up @@ -199,7 +199,7 @@ def _write_bridge_pidfile(session_path: Path, pid: int) -> None:
from gateway.status import get_process_start_time
start = get_process_start_time(pid)
text = str(pid) if start is None else "{}\n{}".format(pid, start)
(session_path / "bridge.pid").write_text(text)
(session_path / "bridge.pid").write_text(text, encoding="utf-8")
except OSError:
pass

Expand Down Expand Up @@ -481,7 +481,7 @@ async def connect(self) -> bool:
_deps_fresh = False
if (bridge_dir / "node_modules").exists():
try:
_deps_fresh = (_dep_stamp.read_text().strip() == _pkg_hash) and bool(_pkg_hash)
_deps_fresh = (_dep_stamp.read_text(encoding="utf-8").strip() == _pkg_hash) and bool(_pkg_hash)
except OSError:
_deps_fresh = False
if not _deps_fresh:
Expand All @@ -507,7 +507,7 @@ async def connect(self) -> bool:
print(f"[{self.name}] Dependencies installed")
if _pkg_hash:
try:
_dep_stamp.write_text(_pkg_hash)
_dep_stamp.write_text(_pkg_hash, encoding="utf-8")
except OSError:
pass # Stamp is an optimization; install still succeeded
except Exception as e:
Expand Down