Skip to content

The agent that grows with you

fix(gateway): move _cmd_service above _GATEWAY_SUBCOMMANDS (NameError at import)

ethernet6393c7ef46e1
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py
index 3a7236127a0..73ba95b272b 100644
--- a/hermes_cli/gateway.py
+++ b/hermes_cli/gateway.py
@@ -442,7 +442,7 @@ def probe_gateway_loop_liveness(
from gateway.shutdown_watchdog import get_loop_heartbeat_path
path = get_loop_heartbeat_path(home)
mtime = path.stat().st_mtime
- payload = json.loads(path.read_text(encoding="utf-8"))
+ payload = json.loads(path.read_text(encoding=utf-8-sig))
heartbeat_pid = int(payload.get("pid", 0))
except Exception:
return GATEWAY_LOOP_UNKNOWN
@@ -1101,7 +1101,7 @@ def _hermes_home_from_systemd_unit_file(system: bool = False) -> str | None:
if not unit_path.exists():
return None
try:
- text = unit_path.read_text(encoding="utf-8")
+ text = unit_path.read_text(encoding=utf-8-sig)
except OSError:
return None
for line in text.splitlines():
@@ -2229,7 +2229,7 @@ def _find_legacy_hermes_units() -> list[tuple[str, Path, bool]]:
try:
if not unit_path.exists():
continue
- text = unit_path.read_text(encoding="utf-8", errors="ignore")
+ text = unit_path.read_text(encoding=utf-8-sig, errors="ignore")
except (OSError, PermissionError):
continue
if any(marker in text for marker in _LEGACY_UNIT_EXECSTART_MARKERS):
@@ -2365,7 +2365,7 @@ def _system_service_identity(run_as_user: str | None = None) -> tuple[str, str,
def _read_systemd_user_from_unit(unit_path: Path) -> str | None:
if not unit_path.exists():
return None
- for line in unit_path.read_text(encoding="utf-8").splitlines():
+ for line in unit_path.read_text(encoding=utf-8-sig).splitlines():
if line.startswith("User="):
return line.split("=", 1)[1].strip() or None
return None
@@ -2870,7 +2870,7 @@ def systemd_unit_is_current(system: bool = False) -> bool:
if not unit_path.exists():
return False
- installed = unit_path.read_text(encoding="utf-8")
+ installed = unit_path.read_text(encoding=utf-8-sig)
expected_user = _read_systemd_user_from_unit(unit_path) if system else None
expected = generate_systemd_unit(system=system, run_as_user=expected_user)
# Ignore directives older systemd drops (RestartMaxDelaySec, RestartSteps) to avoid a perpetual "outdated" flag.
@@ -3482,7 +3482,7 @@ def _append_launchd_reload_log(message: str) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
from datetime import datetime as _dt
stamp = _dt.now().astimezone().strftime("%Y-%m-%d %H:%M:%S %z")
- with path.open("a", encoding="utf-8") as fh:
+ with path.open("a", encoding=utf-8-sig) as fh:
fh.write(f"[{stamp}] {message}\n")
except OSError:
pass
@@ -3735,7 +3735,7 @@ def launchd_plist_is_current() -> bool:
plist_path = get_launchd_plist_path()
if not plist_path.exists():
return False
- installed = plist_path.read_text(encoding="utf-8")
+ installed = plist_path.read_text(encoding=utf-8-sig)
norm = _normalize_launchd_plist_for_comparison
return norm(installed) == norm(generate_launchd_plist())
@@ -6153,6 +6153,12 @@ def _cmd_migrate_legacy(args):
remove_legacy_hermes_units(interactive=not yes, dry_run=dry_run)
+def _cmd_service(args):
+ """Windows SCM frontend (MSIX HermesGateway service): translate the SCM
+ protocol onto the payload launcher (sealed-install surface)."""
+ _windows_scm_service_command(getattr(args, "gateway_service_action", None))
+
+
_GATEWAY_SUBCOMMANDS = {
None: _cmd_run, "run": _cmd_run, "setup": _cmd_setup, "install": _cmd_install,
"uninstall": _cmd_uninstall, "start": _cmd_start, "stop": _cmd_stop, "restart": _cmd_restart,
@@ -6376,8 +6382,4 @@ def _windows_scm_service_command(action: str | None) -> None:
print_error(f"Unknown service action: {action!r} (on|off|status)")
-def _cmd_service(args):
- """Windows SCM frontend (MSIX HermesGateway service): translate the SCM
- protocol onto the payload launcher (sealed-install surface)."""
- _windows_scm_service_command(getattr(args, "gateway_service_action", None))