From 0a6fda01e3f4b4742f668606ffa2ca870613ba2c Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Fri, 24 Jul 2026 16:35:13 -0700 Subject: [PATCH] fix: restore utf-8-sig BOM tolerance at .env readers the sweep normalized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cherry-pick auto-resolution + AST sweep applied plain utf-8 at three .env reader sites where the salvaged PRs (#62617, #62123) deliberately use utf-8-sig — a Notepad BOM must not hide/duplicate the first key. Restore the contract (tests pin it). --- hermes_cli/main.py | 6 +++++- plugins/memory/hindsight/__init__.py | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/hermes_cli/main.py b/hermes_cli/main.py index 700d5e23623e..32292368fe05 100644 --- a/hermes_cli/main.py +++ b/hermes_cli/main.py @@ -13357,7 +13357,11 @@ def _render_distribution_plan(plan) -> None: env_path = plan.target_dir / ".env" if env_path.is_file(): try: - for raw in env_path.read_text(encoding="utf-8").splitlines(): + # .env is written as UTF-8 everywhere in the codebase, + # but a Notepad-edited file can carry a BOM — read as + # utf-8-sig so the first key isn't hidden behind + # U+FEFF (#62617). + for raw in env_path.read_text(encoding="utf-8-sig").splitlines(): line = raw.strip() if not line or line.startswith("#"): continue diff --git a/plugins/memory/hindsight/__init__.py b/plugins/memory/hindsight/__init__.py index e3d3df5f93a3..00b6d7a8f8ea 100644 --- a/plugins/memory/hindsight/__init__.py +++ b/plugins/memory/hindsight/__init__.py @@ -897,7 +897,8 @@ class HindsightMemoryProvider(MemoryProvider): env_path = Path(hermes_home) / ".env" existing_llm_key = "" if env_path.exists(): - for line in env_path.read_text(encoding="utf-8").splitlines(): + # utf-8-sig: a Notepad BOM must not hide the first key. + for line in env_path.read_text(encoding="utf-8-sig").splitlines(): if line.startswith("HINDSIGHT_LLM_API_KEY="): existing_llm_key = line.split("=", 1)[1] break @@ -927,7 +928,10 @@ class HindsightMemoryProvider(MemoryProvider): env_path.parent.mkdir(parents=True, exist_ok=True) existing_lines = [] if env_path.exists(): - existing_lines = env_path.read_text(encoding="utf-8").splitlines() + # utf-8-sig: a Notepad BOM would glue U+FEFF onto the first + # key, defeating the in-place update below and appending a + # duplicate line instead. + existing_lines = env_path.read_text(encoding="utf-8-sig").splitlines() updated_keys = set() new_lines = [] for line in existing_lines: