Skip to content

The agent that grows with you

fix: restore utf-8-sig BOM tolerance at .env readers the sweep normalized

teknium10a6fda01e3f4
diff --git a/hermes_cli/main.py b/hermes_cli/main.py
index 700d5e23623..32292368fe0 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 e3d3df5f93a..00b6d7a8f8e 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: