From d0dbdd807a3a6b809389ddc10e9ce4178253434d Mon Sep 17 00:00:00 2001 From: jeay Date: Thu, 2 Jul 2026 09:18:45 +0800 Subject: [PATCH] fix(hindsight): specify UTF-8 encoding for file I/O on Windows On Windows with CJK locales (e.g. Chinese/GBK), pathlib.Path.read_text() defaults to the system encoding instead of UTF-8, causing UnicodeDecodeError when reading .env or .json config files that contain non-ASCII characters. Explicitly pass encoding='utf-8' to all read_text() and write_text() calls in the hindsight memory provider plugin. --- plugins/memory/hindsight/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/memory/hindsight/__init__.py b/plugins/memory/hindsight/__init__.py index 9f5974b7b5428..1c284f218b583 100644 --- a/plugins/memory/hindsight/__init__.py +++ b/plugins/memory/hindsight/__init__.py @@ -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) @@ -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 @@ -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: @@ -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)