Skip to content

The agent that grows with you

fix(footguns): utf-8-sig on all reads flagged by check-windows-footguns

ethernet588f65f95602
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 9a859bfc950..9487059dce2 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -9812,7 +9812,7 @@ def _managed_local_netloc() -> str:
try:
from hermes_cli.local_runtime.supervisor import state_path
- raw = state_path().read_text(encoding="utf-8")
+ raw = state_path().read_text(encoding="utf-8-sig")
base = str((json.loads(raw) or {}).get("base_url", ""))
netloc = urlparse(base).netloc.lower()
except Exception:
diff --git a/agent/model_metadata.py b/agent/model_metadata.py
index aa85f2d99d3..d69474babe0 100644
--- a/agent/model_metadata.py
+++ b/agent/model_metadata.py
@@ -378,7 +378,7 @@ def _endpoint_disk_cache_get(normalized: str) -> Optional[Dict[str, Dict[str, An
memoized: their loaded context is transient (LM Studio reloads).
"""
try:
- with _get_endpoint_metadata_cache_path().open("r", encoding="utf-8") as f:
+ with _get_endpoint_metadata_cache_path().open("r", encoding="utf-8-sig") as f:
data = json.load(f)
entry = data.get(normalized) if isinstance(data, dict) else None
if not isinstance(entry, dict):
@@ -397,7 +397,7 @@ def _endpoint_disk_cache_put(normalized: str, cache: Dict[str, Dict[str, Any]])
path = _get_endpoint_metadata_cache_path()
data: Dict[str, Any] = {}
if path.exists():
- with path.open("r", encoding="utf-8") as f:
+ with path.open("r", encoding="utf-8-sig") as f:
loaded = json.load(f)
if isinstance(loaded, dict):
now = time.time()
diff --git a/agent/review_idle_queue.py b/agent/review_idle_queue.py
index 2d31501c8e4..45012ec3cc6 100644
--- a/agent/review_idle_queue.py
+++ b/agent/review_idle_queue.py
@@ -261,7 +261,7 @@ def _managed_server_idle() -> bool:
try:
from hermes_cli.local_runtime.supervisor import state_path
- state = json.loads(state_path().read_text(encoding="utf-8"))
+ state = json.loads(state_path().read_text(encoding="utf-8-sig"))
base = str(state.get("base_url", "")).rsplit("/v1", 1)[0]
key = str(state.get("api_key", ""))
if not base:
diff --git a/cron/scheduler.py b/cron/scheduler.py
index 3c4da065f56..641b764bfcd 100644
--- a/cron/scheduler.py
+++ b/cron/scheduler.py
@@ -5475,7 +5475,7 @@ def _primary_profile_routes_for_current_home() -> list:
import yaml
- with open(config_path, encoding="utf-8") as f:
+ with open(config_path, encoding="utf-8-sig") as f:
raw = yaml.safe_load(f) or {}
routes_raw = raw.get("profile_routes")
if routes_raw is None and isinstance(raw.get("gateway"), dict):
@@ -8269,7 +8269,7 @@ def _launch_external_cron_worker(job: dict) -> bool:
while time.monotonic() < deadline:
if ack_path.exists():
try:
- acknowledgement = json.loads(ack_path.read_text(encoding="utf-8"))
+ acknowledgement = json.loads(ack_path.read_text(encoding="utf-8-sig"))
except Exception:
logger.exception(
"Cron external worker %s published an unreadable acknowledgement; "
@@ -8347,7 +8347,7 @@ def _run_external_worker_payload(payload_path: Path, ack_path: Path) -> bool:
unless that durable ownership transfer succeeds.
"""
try:
- payload = json.loads(payload_path.read_text(encoding="utf-8"))
+ payload = json.loads(payload_path.read_text(encoding="utf-8-sig"))
job = payload["job"]
profile_home = Path(payload["profile_home"]).resolve()
execution_id = str(job["execution_id"])
diff --git a/hermes_cli/auth.py b/hermes_cli/auth.py
index 1c4e1116350..43c2a5171e3 100644
--- a/hermes_cli/auth.py
+++ b/hermes_cli/auth.py
@@ -1981,7 +1981,7 @@ def _adopt_oauth_material(target: Dict[str, Any], winner: Dict[str, Any]) -> Dic
def _singleton_as_row(path: Path) -> Optional[Dict[str, Any]]:
"""Read a ``.anthropic_oauth.json`` as a pool-row-shaped dict, or None."""
try:
- data = json.loads(path.read_text(encoding="utf-8"))
+ data = json.loads(path.read_text(encoding="utf-8-sig"))
except (OSError, ValueError):
return None
if not isinstance(data, dict) or not str(data.get("accessToken") or "").strip():
@@ -7931,7 +7931,7 @@ def _external_process_auth_evidence(provider_id: str) -> tuple[bool, Optional[st
try:
cli_config = os.path.expanduser("~/.copilot/config.json")
if os.path.isfile(cli_config):
- with open(cli_config, "r", encoding="utf-8", errors="ignore") as fh:
+ with open(cli_config, "r", encoding="utf-8-sig", errors="ignore") as fh:
raw = "\n".join(
line for line in fh.read().splitlines()
if not line.lstrip().startswith("//")
diff --git a/hermes_cli/backup.py b/hermes_cli/backup.py
index 5ff7c10dac7..aa50d752496 100644
--- a/hermes_cli/backup.py
+++ b/hermes_cli/backup.py
@@ -2275,7 +2275,7 @@ def _read_raw_yaml_dict(path: Path) -> Optional[Dict[str, Any]]:
try:
import yaml
- with open(path, "r", encoding="utf-8") as f:
+ with open(path, "r", encoding="utf-8-sig") as f:
data = yaml.safe_load(f)
except Exception:
return None
diff --git a/hermes_cli/config.py b/hermes_cli/config.py
index 6483685ecbc..13e74aabd2c 100644
--- a/hermes_cli/config.py
+++ b/hermes_cli/config.py
@@ -825,7 +825,7 @@ def require_parseable_user_config(*, ignore_user_config: bool = False) -> None:
config_path = get_config_path()
try:
- with open(config_path, encoding="utf-8") as f:
+ with open(config_path, encoding="utf-8-sig") as f:
data = fast_safe_load(f)
except FileNotFoundError:
return
diff --git a/hermes_cli/gateway_windows.py b/hermes_cli/gateway_windows.py
index e47bd49a64d..c90fd5fd18d 100644
--- a/hermes_cli/gateway_windows.py
+++ b/hermes_cli/gateway_windows.py
@@ -1309,7 +1309,7 @@ def _attested_pid_exited_cleanly(pid: int) -> bool:
from hermes_cli.config import get_hermes_home
sentinel_path = get_lifecycle_sentinel_path(Path(get_hermes_home()))
- data = _json.loads(sentinel_path.read_text(encoding="utf-8"))
+ data = _json.loads(sentinel_path.read_text(encoding="utf-8-sig"))
except Exception:
return False
return (
@@ -1340,7 +1340,7 @@ def check_start_attestation(current_pids: list[int] | None = None) -> str | None
try:
path = _start_attestation_path()
- data = _json.loads(path.read_text(encoding="utf-8"))
+ data = _json.loads(path.read_text(encoding="utf-8-sig"))
except (OSError, ValueError):
return None
if not isinstance(data, dict):
diff --git a/hermes_cli/linux_desktop_entry.py b/hermes_cli/linux_desktop_entry.py
index e33675590ea..3c0a145e2de 100644
--- a/hermes_cli/linux_desktop_entry.py
+++ b/hermes_cli/linux_desktop_entry.py
@@ -785,7 +785,7 @@ def install_desktop_entry(project_root: Path) -> Optional[Path]:
entry_path.parent.mkdir(parents=True, exist_ok=True)
# When nothing changed, skip the rewrite. Then a launch does not
# churn the menu caches.
- if entry_path.is_file() and entry_path.read_text(encoding="utf-8") == contents:
+ if entry_path.is_file() and entry_path.read_text(encoding="utf-8-sig") == contents:
return entry_path
# Atomic replace: an interrupted plain write can leave a zero-byte
# entry, which permanently breaks the taskbar pin (nothing later
diff --git a/hermes_cli/local_runtime/binaries.py b/hermes_cli/local_runtime/binaries.py
index bcd7d32a1d7..da9d81c762f 100644
--- a/hermes_cli/local_runtime/binaries.py
+++ b/hermes_cli/local_runtime/binaries.py
@@ -92,7 +92,7 @@ def installed_tags() -> list[str]:
continue
for manifest in entry.glob("*/manifest.json"):
try:
- if json.loads(manifest.read_text(encoding="utf-8")).get("verified_version"):
+ if json.loads(manifest.read_text(encoding="utf-8-sig")).get("verified_version"):
found.append(entry.name)
break
except (json.JSONDecodeError, OSError):
@@ -308,7 +308,7 @@ def ensure_runtime_installed(tag: str, backend: str,
manifest_path = install_dir / "manifest.json"
if manifest_path.exists():
try:
- manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
+ manifest = json.loads(manifest_path.read_text(encoding="utf-8-sig"))
if manifest.get("verified_version"):
return install_dir
except (json.JSONDecodeError, OSError):
diff --git a/hermes_cli/local_runtime/endpoint.py b/hermes_cli/local_runtime/endpoint.py
index b80a663d031..00d0691fc1d 100644
--- a/hermes_cli/local_runtime/endpoint.py
+++ b/hermes_cli/local_runtime/endpoint.py
@@ -49,7 +49,7 @@ def _state_endpoint() -> dict | None:
if not path.exists():
return None
try:
- state = json.loads(path.read_text(encoding="utf-8"))
+ state = json.loads(path.read_text(encoding="utf-8-sig"))
except (json.JSONDecodeError, OSError):
return None
base_url = state.get("base_url", "")
@@ -185,7 +185,7 @@ def _boot_in_flight(config: dict | None) -> bool:
for manifest in runtimes_root().glob("*/*/manifest.json"):
try:
- if _json.loads(manifest.read_text(encoding="utf-8")).get("verified_version"):
+ if _json.loads(manifest.read_text(encoding="utf-8-sig")).get("verified_version"):
return True
except (ValueError, OSError):
continue
diff --git a/hermes_cli/local_runtime/growth.py b/hermes_cli/local_runtime/growth.py
index 484f2ff9f50..0615b3459fa 100644
--- a/hermes_cli/local_runtime/growth.py
+++ b/hermes_cli/local_runtime/growth.py
@@ -34,7 +34,7 @@ def window_overrides_path():
def load_window_overrides() -> dict:
"""model_id -> granted window (int). Empty on any read problem."""
try:
- with open(window_overrides_path(), encoding="utf-8") as fh:
+ with open(window_overrides_path(), encoding="utf-8-sig") as fh:
data = json.load(fh)
return {str(k): int(v) for k, v in data.items()}
except Exception: # noqa: BLE001
diff --git a/hermes_cli/local_runtime/supervisor.py b/hermes_cli/local_runtime/supervisor.py
index 44f162cf48a..360f25d2ee9 100644
--- a/hermes_cli/local_runtime/supervisor.py
+++ b/hermes_cli/local_runtime/supervisor.py
@@ -86,7 +86,7 @@ def _stable_api_key() -> str:
"""
key_path = runtimes_root() / ".api_key"
try:
- existing = key_path.read_text(encoding="utf-8").strip()
+ existing = key_path.read_text(encoding="utf-8-sig").strip()
if len(existing) >= 16:
return existing
except OSError:
diff --git a/hermes_cli/models.py b/hermes_cli/models.py
index 8334e4f15c6..100ed516093 100644
--- a/hermes_cli/models.py
+++ b/hermes_cli/models.py
@@ -4299,7 +4299,7 @@ def _resolve_copilot_catalog_api_key() -> str:
cli_config = os.path.expanduser("~/.copilot/config.json")
if os.path.isfile(cli_config):
- with open(cli_config, "r", encoding="utf-8", errors="ignore") as fh:
+ with open(cli_config, "r", encoding="utf-8-sig", errors="ignore") as fh:
raw_text = "\n".join(
line for line in fh.read().splitlines()
if not line.lstrip().startswith("//")
diff --git a/hermes_cli/web_routers/local_models.py b/hermes_cli/web_routers/local_models.py
index 5bc3d8d1c85..af734b882cf 100644
--- a/hermes_cli/web_routers/local_models.py
+++ b/hermes_cli/web_routers/local_models.py
@@ -1034,7 +1034,7 @@ async def local_models_server(body: ServerActionBody):
from hermes_cli.local_runtime.supervisor import state_path
- state = json.loads(state_path().read_text(encoding="utf-8"))
+ state = json.loads(state_path().read_text(encoding="utf-8-sig"))
pid = int(state.get("pid") or 0)
if pid > 0 and psutil.pid_exists(pid):
psutil.Process(pid).terminate()
diff --git a/plugins/platforms/buzz/adapter.py b/plugins/platforms/buzz/adapter.py
index 94a5bd6c4af..f6aaf675b70 100644
--- a/plugins/platforms/buzz/adapter.py
+++ b/plugins/platforms/buzz/adapter.py
@@ -2038,7 +2038,7 @@ class BuzzAdapter(BasePlatformAdapter):
path = self._cursor_path()
if not path.exists():
return
- data = json.loads(path.read_text(encoding="utf-8"))
+ data = json.loads(path.read_text(encoding="utf-8-sig"))
except Exception:
logger.debug("Buzz: could not read channel cursors", exc_info=True)
return
diff --git a/scripts/aa_quality_sync.py b/scripts/aa_quality_sync.py
index 66e61c7f7d1..ca6b1e9dd44 100644
--- a/scripts/aa_quality_sync.py
+++ b/scripts/aa_quality_sync.py
@@ -57,7 +57,7 @@ def main() -> int:
"https://artificialanalysis.ai and export it.", file=sys.stderr)
return 2
- catalog = json.loads(CATALOG_PATH.read_text(encoding="utf-8"))
+ catalog = json.loads(CATALOG_PATH.read_text(encoding="utf-8-sig"))
aa = fetch_aa_models(api_key)
print(f"{'entry':24s} {'catalog q':>9s} {'AA index':>9s} note")
diff --git a/scripts/ci/classify_changes.py b/scripts/ci/classify_changes.py
index 4aeb35d4c9b..44f8b08b2f0 100644
--- a/scripts/ci/classify_changes.py
+++ b/scripts/ci/classify_changes.py
@@ -276,7 +276,7 @@ def _pull_request_number() -> str | None:
if not event_path:
return None
try:
- with open(event_path, encoding="utf-8") as fh:
+ with open(event_path, encoding="utf-8-sig") as fh:
payload = json.load(fh)
except (OSError, json.JSONDecodeError):
return None
diff --git a/scripts/e2e_shared_metrics_staging.py b/scripts/e2e_shared_metrics_staging.py
index 666c9e51e92..9fe836e85db 100644
--- a/scripts/e2e_shared_metrics_staging.py
+++ b/scripts/e2e_shared_metrics_staging.py
@@ -50,7 +50,7 @@ def main() -> int:
import yaml
resolved = resolve_send_config(
- yaml.safe_load((scratch / "config.yaml").read_text(encoding="utf-8"))
+ yaml.safe_load((scratch / "config.yaml").read_text(encoding="utf-8-sig"))
)
if not resolved.send or resolved.endpoint != STAGING:
print(f"FAIL: config did not resolve to staging: {resolved}")
diff --git a/scripts/probe_active_session_exclusivity.py b/scripts/probe_active_session_exclusivity.py
index 57c6bcfbaa2..54fa2952ba0 100644
--- a/scripts/probe_active_session_exclusivity.py
+++ b/scripts/probe_active_session_exclusivity.py
@@ -115,7 +115,7 @@ def reason_of(response: dict):
def registry(home: Path):
path = home / "runtime" / "active_sessions.json"
try:
- return json.loads(path.read_text(encoding="utf-8")).get("entries", [])
+ return json.loads(path.read_text(encoding="utf-8-sig")).get("entries", [])
except Exception:
return []
diff --git a/tools/browser_lightpanda.py b/tools/browser_lightpanda.py
index 800c05aa054..5e95c7e807c 100644
--- a/tools/browser_lightpanda.py
+++ b/tools/browser_lightpanda.py
@@ -404,7 +404,7 @@ def reap_orphaned_lightpanda() -> int:
for record_path in sorted(state_dir.glob("*.json")):
session_name = record_path.stem
try:
- record = json.loads(record_path.read_text(encoding="utf-8"))
+ record = json.loads(record_path.read_text(encoding="utf-8-sig"))
except (OSError, ValueError):
record_path.unlink(missing_ok=True)
continue
diff --git a/tools/browser_tool.py b/tools/browser_tool.py
index c9b79e6be87..5bb4d9862d9 100644
--- a/tools/browser_tool.py
+++ b/tools/browser_tool.py
@@ -5939,7 +5939,7 @@ def _release_session_resources(task_id: str, session_info: Dict[str, Any]) -> No
if os.path.isfile(pid_file):
try:
from tools.process_registry import ProcessRegistry
- daemon_pid = int(Path(pid_file).read_text(encoding="utf-8").strip())
+ daemon_pid = int(Path(pid_file).read_text(encoding="utf-8-sig").strip())
# The .pid file lives in a world-writable temp dir and
# PIDs recycle: verify this really is our daemon for
# this session before tree-killing, and pin the
diff --git a/tools/mcp_tool.py b/tools/mcp_tool.py
index f7cf11213ab..15f54267698 100644
--- a/tools/mcp_tool.py
+++ b/tools/mcp_tool.py
@@ -1153,7 +1153,7 @@ def _npx_cached_bin(args: list) -> Optional[tuple]:
for entry in entries:
manifest = os.path.join(npx_root, entry, "package.json")
try:
- with open(manifest, "r", encoding="utf-8") as fh:
+ with open(manifest, "r", encoding="utf-8-sig") as fh:
deps = (json.load(fh) or {}).get("dependencies") or {}
except (OSError, ValueError, TypeError):
continue
@@ -1162,7 +1162,7 @@ def _npx_cached_bin(args: list) -> Optional[tuple]:
pkg_json = os.path.join(npx_root, entry, "node_modules", spec, "package.json")
try:
- with open(pkg_json, "r", encoding="utf-8") as fh:
+ with open(pkg_json, "r", encoding="utf-8-sig") as fh:
bin_field = (json.load(fh) or {}).get("bin")
except (OSError, ValueError, TypeError):
continue
diff --git a/tools/osv_check.py b/tools/osv_check.py
index 19acdfb065a..4c4024c0fc8 100644
--- a/tools/osv_check.py
+++ b/tools/osv_check.py
@@ -93,7 +93,7 @@ def _load_disk_cache() -> None:
return
try:
- with open(path, "r", encoding="utf-8") as f:
+ with open(path, "r", encoding="utf-8-sig") as f:
data = json.load(f)
except FileNotFoundError:
data = None
diff --git a/tools/terminal_scope.py b/tools/terminal_scope.py
index da79538ab73..9c969be34c8 100644
--- a/tools/terminal_scope.py
+++ b/tools/terminal_scope.py
@@ -222,7 +222,7 @@ def build_profile_terminal_scope(hermes_home: "Any") -> Dict[str, str]:
from hermes_cli.config import fast_safe_load
try:
- with open(config_path, encoding="utf-8") as f:
+ with open(config_path, encoding="utf-8-sig") as f:
raw = fast_safe_load(f)
except Exception as exc:
raise TerminalPolicyUnavailable(