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 hermes_cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ def _load_auth_store(auth_file: Optional[Path] = None) -> Dict[str, Any]:
return {"version": AUTH_STORE_VERSION, "providers": {}}

try:
raw = json.loads(auth_file.read_text())
raw = json.loads(auth_file.read_text(encoding="utf-8"))
except Exception as exc:
corrupt_path = auth_file.with_suffix(".json.corrupt")
try:
Expand Down Expand Up @@ -3657,7 +3657,7 @@ def _import_codex_cli_tokens() -> Optional[Dict[str, str]]:
if not auth_path.is_file():
return None
try:
payload = json.loads(auth_path.read_text())
payload = json.loads(auth_path.read_text(encoding="utf-8"))
tokens = payload.get("tokens")
if not isinstance(tokens, dict):
return None
Expand Down Expand Up @@ -4823,7 +4823,7 @@ def _read_shared_nous_state() -> Optional[Dict[str, Any]]:
if not path.is_file():
return None
try:
payload = json.loads(path.read_text())
payload = json.loads(path.read_text(encoding="utf-8"))
except (OSError, ValueError) as exc:
logger.debug("Shared Nous auth store at %s is unreadable: %s", path, exc)
return None
Expand Down
5 changes: 3 additions & 2 deletions hermes_cli/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def check_for_updates() -> Optional[int]:
now = time.time()
try:
if cache_file.exists():
cached = json.loads(cache_file.read_text())
cached = json.loads(cache_file.read_text(encoding="utf-8"))
if (
now - cached.get("ts", 0) < _UPDATE_CHECK_CACHE_SECONDS
and cached.get("rev") == embedded_rev
Expand All @@ -331,7 +331,8 @@ def check_for_updates() -> Optional[int]:

try:
cache_file.write_text(
json.dumps({"ts": now, "behind": behind, "rev": embedded_rev, "ver": VERSION})
json.dumps({"ts": now, "behind": behind, "rev": embedded_rev, "ver": VERSION}),
encoding="utf-8",
)
except Exception:
pass
Expand Down
10 changes: 5 additions & 5 deletions hermes_cli/container_boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _maybe_migrate_legacy_gateway_run_state(
"desired_state": "running",
"timestamp": int(time.time()),
"migrated_from": "legacy-container-cmd",
}) + "\n")
}) + "\n", encoding="utf-8")
return "running"


Expand Down Expand Up @@ -270,7 +270,7 @@ def _read_desired_state(profile_dir: Path) -> str | None:
if not state_file.exists():
return None
try:
data = json.loads(state_file.read_text())
data = json.loads(state_file.read_text(encoding="utf-8"))
desired_state = data.get("desired_state")
if desired_state is not None:
return desired_state
Expand Down Expand Up @@ -326,22 +326,22 @@ def _register_service(scandir: Path, profile: str, *, start: bool) -> None:
tmp_dir.mkdir(parents=True)

try:
(tmp_dir / "type").write_text("longrun\n")
(tmp_dir / "type").write_text("longrun\n", encoding="utf-8")

# Reuse the manager's run-script rendering — single source of
# truth so register_profile_gateway and reconcile_profile_gateways
# stay consistent. extra_env is empty here; users who need
# per-profile env can set it via the profile's config.yaml
# (which the gateway itself loads).
run = tmp_dir / "run"
run.write_text(S6ServiceManager._render_run_script(profile, extra_env={}))
run.write_text(S6ServiceManager._render_run_script(profile, extra_env={}), encoding="utf-8")
run.chmod(0o755)

# Persistent log rotation (OQ8-C).
log_subdir = tmp_dir / "log"
log_subdir.mkdir()
log_run = log_subdir / "run"
log_run.write_text(S6ServiceManager._render_log_run(profile))
log_run.write_text(S6ServiceManager._render_log_run(profile), encoding="utf-8")
log_run.chmod(0o755)

# The presence of a `down` file tells s6-supervise to NOT
Expand Down
6 changes: 3 additions & 3 deletions hermes_cli/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def run_doctor(args):
check_ok(f"{_DHH}/.env file exists")

# Check for common issues. Pin encoding to UTF-8 because .env files are
# written as UTF-8 everywhere in the codebase, while Path.read_text()
# written as UTF-8 everywhere in the codebase, while Path.read_text(encoding="utf-8")
# defaults to the system locale — which crashes on non-UTF-8 Windows
# locales (e.g. GBK) as soon as the file contains any non-ASCII byte.
content = env_path.read_text(encoding="utf-8")
Expand Down Expand Up @@ -2126,7 +2126,7 @@ def _probe_azure_entra() -> _ConnectivityResult:
if lock_file.exists():
try:
import json
lock_data = json.loads(lock_file.read_text())
lock_data = json.loads(lock_file.read_text(encoding="utf-8"))
count = len(lock_data.get("installed", {}))
check_ok(f"Lock file OK ({count} hub-installed skill(s))")
except Exception:
Expand Down Expand Up @@ -2292,7 +2292,7 @@ def _gh_authenticated() -> bool:
if not wrapper.is_file():
continue
try:
content = wrapper.read_text()
content = wrapper.read_text(encoding="utf-8")
if "hermes -p" in content:
_m = _re.search(r"hermes -p (\S+)", content)
if _m and not profile_exists(_m.group(1)):
Expand Down
10 changes: 5 additions & 5 deletions hermes_cli/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,7 @@ def refresh_systemd_unit_if_needed(system: bool = False) -> bool:
if _refuse_temp_home_service_write(new_unit, "systemd unit"):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call already has encoding="utf-8" on current main (hermes_cli/gateway.py:2997). Adding it a second time produces duplicate keyword arguments and invalid Python; this hunk should be dropped during salvage.

return False

unit_path.write_text(new_unit, encoding="utf-8")
unit_path.write_text(new_unit, encoding="utf-8", encoding="utf-8")
_run_systemctl(["daemon-reload"], system=system, check=True, timeout=30)
print(
f"↻ Updated gateway {_service_scope_label(system)} service definition to match the current Hermes install"
Expand Down Expand Up @@ -2880,7 +2880,7 @@ def systemd_install(
if _refuse_temp_home_service_write(new_unit, "systemd unit"):
return
print(f"Installing {_service_scope_label(system)} systemd service to: {unit_path}")
unit_path.write_text(new_unit, encoding="utf-8")
unit_path.write_text(new_unit, encoding="utf-8", encoding="utf-8")

_run_systemctl(["daemon-reload"], system=system, check=True, timeout=30)
if enable_on_startup:
Expand Down Expand Up @@ -3514,7 +3514,7 @@ def refresh_launchd_plist_if_needed() -> bool:
if _refuse_temp_home_service_write(new_plist, "launchd plist"):
return False

plist_path.write_text(new_plist, encoding="utf-8")
plist_path.write_text(new_plist, encoding="utf-8", encoding="utf-8")
label = get_launchd_label()
domain = _launchd_domain()
target = f"{domain}/{label}"
Expand Down Expand Up @@ -3597,7 +3597,7 @@ def launchd_install(force: bool = False):
if _refuse_temp_home_service_write(new_plist, "launchd plist"):
return
print(f"Installing launchd service to: {plist_path}")
plist_path.write_text(new_plist)
plist_path.write_text(new_plist, encoding="utf-8")

try:
subprocess.run(
Expand Down Expand Up @@ -3648,7 +3648,7 @@ def launchd_start():
sys.exit(1)
print("↻ launchd plist missing; regenerating service definition")
plist_path.parent.mkdir(parents=True, exist_ok=True)
plist_path.write_text(new_plist, encoding="utf-8")
plist_path.write_text(new_plist, encoding="utf-8", encoding="utf-8")
try:
subprocess.run(
["launchctl", "bootstrap", _launchd_domain(), str(plist_path)],
Expand Down
8 changes: 4 additions & 4 deletions hermes_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def _resolve_sudo_user_profile_env(name: str) -> str | None:

active_path = get_default_hermes_root() / "active_profile"
if active_path.exists():
name = active_path.read_text().strip()
name = active_path.read_text(encoding="utf-8").strip()
if name and name != "default":
profile_name = name
consume = 0 # don't strip anything from argv
Expand Down Expand Up @@ -846,7 +846,7 @@ def _has_any_provider_configured() -> bool:
try:
import json

auth = json.loads(auth_file.read_text())
auth = json.loads(auth_file.read_text(encoding="utf-8"))
active = auth.get("active_provider")
if active:
status = get_auth_status(active)
Expand Down Expand Up @@ -4530,7 +4530,7 @@ def _gateway_prompt(prompt_text: str, default: str = "", timeout: float = 300.0)
while _time.monotonic() < deadline:
if response_path.exists():
try:
answer = response_path.read_text().strip()
answer = response_path.read_text(encoding="utf-8").strip()
response_path.unlink(missing_ok=True)
prompt_path.unlink(missing_ok=True)
return answer if answer else default
Expand Down Expand Up @@ -10907,7 +10907,7 @@ 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().splitlines():
for raw in env_path.read_text(encoding="utf-8").splitlines():
line = raw.strip()
if not line or line.startswith("#"):
continue
Expand Down
10 changes: 5 additions & 5 deletions hermes_cli/service_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,15 @@ def _write_gateway_desired_state(name: str, desired_state: str) -> None:
if not profile_dir.exists():
return
try:
data = json.loads(state_file.read_text()) if state_file.exists() else {}
data = json.loads(state_file.read_text(encoding="utf-8")) if state_file.exists() else {}
if not isinstance(data, dict):
data = {}
except (OSError, json.JSONDecodeError):
data = {}
data["desired_state"] = desired_state
data["updated_at"] = int(time.time())
tmp = state_file.with_suffix(state_file.suffix + ".tmp")
tmp.write_text(json.dumps(data, separators=(",", ":")) + "\n")
tmp.write_text(json.dumps(data, separators=(",", ":")) + "\n", encoding="utf-8")
tmp.replace(state_file)
except OSError:
return
Expand Down Expand Up @@ -949,18 +949,18 @@ def register_profile_gateway(
tmp_dir.mkdir(parents=True)

try:
(tmp_dir / "type").write_text("longrun\n")
(tmp_dir / "type").write_text("longrun\n", encoding="utf-8")

run_script = self._render_run_script(profile, extra_env or {})
run_path = tmp_dir / "run"
run_path.write_text(run_script)
run_path.write_text(run_script, encoding="utf-8")
run_path.chmod(0o755)

# Persistent log rotation (OQ8-C).
log_subdir = tmp_dir / "log"
log_subdir.mkdir()
log_run = log_subdir / "run"
log_run.write_text(self._render_log_run(profile))
log_run.write_text(self._render_log_run(profile), encoding="utf-8")
log_run.chmod(0o755)

# Pre-create the supervise/ skeleton with hermes ownership
Expand Down
4 changes: 2 additions & 2 deletions hermes_cli/uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def remove_path_from_shell_configs():

for config_path in configs:
try:
content = config_path.read_text()
content = config_path.read_text(encoding="utf-8")
original_content = content

# Remove lines containing hermes-agent or hermes PATH entries
Expand Down Expand Up @@ -108,7 +108,7 @@ def remove_wrapper_script():
if wrapper.exists():
try:
# Check if it's our wrapper (contains hermes_cli reference)
content = wrapper.read_text()
content = wrapper.read_text(encoding="utf-8")
if 'hermes_cli' in content or 'hermes-agent' in content:
wrapper.unlink()
removed.append(wrapper)
Expand Down