The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(hermes_cli/update): reflow short multi-line calls and signatures (AST-identical)
Teknium90052abfb97a
diff --git a/hermes_cli/update_cmd_fleet.py b/hermes_cli/update_cmd_fleet.pyindex c1ce2c152a5..c6d93cdfbc8 100644--- a/hermes_cli/update_cmd_fleet.py+++ b/hermes_cli/update_cmd_fleet.py@@ -321,12 +321,7 @@ def _is_hermes_gateway_unit(unit: str) -> bool:)-def _for_each_systemd_gateway_unit(- list_units_stdout: str,- *,- process_unit,- on_unit_timeout,-) -> None:+def _for_each_systemd_gateway_unit(list_units_stdout: str, *, process_unit, on_unit_timeout) -> None:"""Process each hermes-gateway*/hermes-serve* unit from ``systemctl list-units``.``TimeoutExpired`` from ``process_unit`` is isolated per unit via ``on_unit_timeout``@@ -387,9 +382,7 @@ def _warn_incomplete_gateway_fleet_restart(failed_units: list) -> None:print(" launchctl kickstart -k gui/$UID/<label> # macOS (or user/$UID)")-def _restart_launchd_gateway_after_update(- *, supervision_verify: bool = True-) -> tuple[list, list]:+def _restart_launchd_gateway_after_update(*, supervision_verify: bool = True) -> tuple[list, list]:"""Restart the invoking profile's launchd gateway after an update.No ``launchctl list`` gating: a booted-out job (plist present, definition@@ -502,9 +495,7 @@ def _restart_macos_launchd_gateways(f" Recover manually: launchctl kickstart -k {domain}/{label}")continue- if _wait_for_launchd_service_pid(- label, old_pid=old_pid, timeout=15.0, domain=domain- ):+ if _wait_for_launchd_service_pid(label, old_pid=old_pid, timeout=15.0, domain=domain):restarted_services.append(label)else:failed_or_stale_units.append(label)@@ -514,10 +505,7 @@ def _restart_macos_launchd_gateways()except subprocess.TimeoutExpired:failed_or_stale_units.append(label)- print(- f" ⚠ launchctl timed out restarting {label}; "- "continuing with remaining gateways"- )+ print(f" ⚠ launchctl timed out restarting {label}; continuing with remaining gateways")def _surviving_gateway_pids_after_failed_restart():@@ -544,11 +532,7 @@ def _gateway_service_matches_profile(profile: str, service: object) -> bool:name = str(service).removesuffix(".service")if profile == "default":return name in {"hermes-gateway", "ai.hermes.gateway", "gateway", "gateway-default"}- return name in {- f"hermes-gateway-{profile}",- f"ai.hermes.gateway-{profile}",- f"gateway-{profile}",- }+ return name in {f"hermes-gateway-{profile}", f"ai.hermes.gateway-{profile}", f"gateway-{profile}"}_MANUAL_GATEWAY_SKIP_REASON = (@@ -628,11 +612,7 @@ def _warn_gateway_restart_phase_aborted(exc: BaseException, pids) -> None:print(" hermes gateway status")-def _drain_or_signal_gateway_for_update(- pid: int,- drain_budget: float,- label: str,-) -> bool:+def _drain_or_signal_gateway_for_update(pid: int, drain_budget: float, label: str) -> bool:"""Three-way triage (shared by systemd and bare-process paths) for handing arunning gateway over to new code. Returns True when signalled/stopped.@@ -858,9 +838,7 @@ def _restart_systemd_gateway_units(on_unit_timeout=_on_unit_timeout,)finally:- restarted_scoped_units.update(- f"{scope}/{name}" for name in restarted_services[_scope_mark:]- )+ restarted_scoped_units.update(f"{scope}/{name}" for name in restarted_services[_scope_mark:])@dataclass@@ -1231,9 +1209,7 @@ def _verify_fleet_after_update(# Restart a managed dashboard via systemd or stop stale manual ones (raw-killing# a systemd-owned PID reads as clean stop and leaves the Cloudflare origin dead).# Failed Node refresh leaves it untouched; already-restarted units aren't redone.- _finish_dashboard_update_cleanup(- node_failures, already_restarted_units=set(restart.restarted_services)- )+ _finish_dashboard_update_cleanup(node_failures, already_restarted_units=set(restart.restarted_services))# Success-path twin of the abort-recovery probe: the restart phase only touches# units, so a unit-less `hermes serve` keeps stale sys.modules. Runs AFTER@@ -1368,11 +1344,7 @@ def _fleet_probe_expected_runtimes(return False-def _wait_for_service_active(- scope_cmd_: list,- svc_name_: str,- timeout: float = 10.0,-) -> bool:+def _wait_for_service_active(scope_cmd_: list, svc_name_: str, timeout: float = 10.0) -> bool:"""Poll ``systemctl is-active`` (0.5s) up to ``timeout``: the Stopped -> Startedtransition isn't instantaneous, so a one-shot check falsely reports down."""deadline = _time.monotonic() + max(timeout, 0.5)@@ -1389,11 +1361,7 @@ def _wait_for_service_active(_RESTART_SEC_UNITS = (("ms", 0.001), ("us", 0.000001), ("min", 60.0), ("s", 1.0))-def _service_restart_sec(- scope_cmd_: list,- svc_name_: str,- default: float = 0.0,-) -> float:+def _service_restart_sec(scope_cmd_: list, svc_name_: str, default: float = 0.0) -> float:"""Read the unit's ``RestartUSec`` in seconds. ``is-active`` pollers must wait>= RestartSec + slack or they give up *during* the cooldown and misreport."""try:diff --git a/hermes_cli/update_cmd_maint.py b/hermes_cli/update_cmd_maint.pyindex 9de3ffb06f9..e7bc050853e 100644--- a/hermes_cli/update_cmd_maint.py+++ b/hermes_cli/update_cmd_maint.py@@ -331,10 +331,7 @@ def _finish_dashboard_update_cleanup(returnprint()- print(- "⚠ A web dashboard/serve process was stopped during update and could "- "not be auto-restarted."- )+ print("⚠ A web dashboard/serve process was stopped during update and could not be auto-restarted.")print(" Re-launch it when you want the web UI back:")print(" hermes dashboard --port <port>")@@ -516,10 +513,7 @@ def _verify_and_restore_one_state_db(home: Path, *, label: str) -> None:logger.debug("Post-update state.db integrity OK (%s): %s", label, ok.get("message"))returnprint()- print(- f"⚠ state.db is corrupted after update ({label}): "- + ok.get("message", "unknown error")- )+ print(f"⚠ state.db is corrupted after update ({label}): " + ok.get("message", "unknown error"))snap_root = _quick_snapshot_root(home)if not snap_root.exists():print(" ⚠ No pre-update snapshot for this home")@@ -936,9 +930,7 @@ def _refresh_cua_driver_after_update() -> None:refresh_cua_driver = bool(_load_updates_cfg().get("refresh_cua_driver", True))if (- refresh_cua_driver- and sys.platform in ("darwin", "win32", "linux")- and shutil.which("cua-driver")+ refresh_cua_driver and sys.platform in ("darwin", "win32", "linux") and shutil.which("cua-driver")):from hermes_cli.tools_config import install_cua_driver@@ -947,11 +939,7 @@ def _refresh_cua_driver_after_update() -> None:# require_confirmed_update: install only when check-update positively reports a# newer release (update must stay fast; `computer-use install --upgrade` forces).# Windows defers even confirmed updates (installer may need console/UAC consent).- install_cua_driver(- upgrade=True,- require_confirmed_update=True,- show_installer_progress=False,- )+ install_cua_driver(upgrade=True, require_confirmed_update=True, show_installer_progress=False)def _print_post_update_notices_and_self_heals() -> None:diff --git a/hermes_cli/update_cmd_stash.py b/hermes_cli/update_cmd_stash.pyindex 216bca8d6e9..ca20deb0d9c 100644--- a/hermes_cli/update_cmd_stash.py+++ b/hermes_cli/update_cmd_stash.py@@ -77,10 +77,7 @@ def _stash_local_changes_if_needed(git_cmd: list[str], cwd: Path) -> Optional[stprint("✗ Could not stash local changes — update aborted.")if push.stderr.strip():print(f" {push.stderr.strip().splitlines()[0]}")- print(- " Commit, stash, or clean up your local changes manually, "- "then re-run `hermes update`."- )+ print(" Commit, stash, or clean up your local changes manually, then re-run `hermes update`.")raise subprocess.CalledProcessError(push.returncode, push.args, output=push.stdout, stderr=push.stderr)@@ -88,9 +85,7 @@ def _stash_local_changes_if_needed(git_cmd: list[str], cwd: Path) -> Optional[streturn stash_ref-def _resolve_stash_selector(- git_cmd: list[str], cwd: Path, stash_ref: str-) -> Optional[str]:+def _resolve_stash_selector(git_cmd: list[str], cwd: Path, stash_ref: str) -> Optional[str]:from hermes_cli.update_cmd import _git_runstash_list = _git_run(git_cmd, ["stash", "list", "--format=%gd %H"], cwd, check=True)for line in stash_list.stdout.splitlines():@@ -146,17 +141,13 @@ def _warn_orphaned_update_autostashes(git_cmd: list[str], cwd: Path) -> int:return 0-def _print_stash_cleanup_guidance(- stash_ref: str, stash_selector: Optional[str] = None-) -> None:+def _print_stash_cleanup_guidance(stash_ref: str, stash_selector: Optional[str] = None) -> None:print(" Check `git status` first so you don't accidentally reapply the same change twice.")print(" Find the saved entry with: git stash list --format='%gd %H %s'")if stash_selector:print(f" Remove it with: git stash drop {stash_selector}")else:- print(- f" Look for commit {stash_ref}, then drop its selector with: git stash drop stash@{{N}}"- )+ print(f" Look for commit {stash_ref}, then drop its selector with: git stash drop stash@{{N}}")def _stash_apply_failed_only_on_existing_untracked(stderr: str) -> bool:@@ -199,9 +190,7 @@ def _git_untracked_paths(git_cmd: list[str], cwd: Path) -> set[str] | None:return {path for path in result.stdout.split("\0") if path}-def _restored_python_paths(- git_cmd: list[str], cwd: Path-) -> tuple[str, ...] | None:+def _restored_python_paths(git_cmd: list[str], cwd: Path) -> tuple[str, ...] | None:"""Restored ``.py`` paths changed from ``HEAD``; deliberately Python-only (entry scripts stay outside the health check)."""from hermes_cli.update_cmd import _git_untracked_pathschanged = _git_quiet(@@ -320,10 +309,7 @@ def _restore_stashed_changes():# Tracked changes applied; only undeletable-at-stash-time untracked files# were refused. Their content is untouched — treat as restored.- print(- " ⚠ Some stashed untracked files already exist in the working "- "tree and were kept as-is."- )+ print(" ⚠ Some stashed untracked files already exist in the working tree and were kept as-is.")elif restore.returncode != 0 or has_conflicts:print("✗ Update pulled new code, but restoring local changes hit conflicts.")_print_nonempty(restore.stdout)@@ -346,9 +332,7 @@ def _restore_stashed_changes(return Falsedef reject(failing_target: str, detail) -> None:- _reject_unsafe_stash_restore(- git_cmd, cwd, stash_ref, preexisting_untracked, failing_target, detail- )+ _reject_unsafe_stash_restore(git_cmd, cwd, stash_ref, preexisting_untracked, failing_target, detail)restored_python = _restored_python_paths(git_cmd, cwd)if restored_python is None:@@ -369,9 +353,7 @@ def _restore_stashed_changes(stash_selector = _resolve_stash_selector(git_cmd, cwd, stash_ref)if stash_selector is None:print("⚠ Local changes were restored, but Hermes couldn't find the stash entry to drop.")- print(- " The stash was left in place. You can remove it manually after checking the result."- )+ print(" The stash was left in place. You can remove it manually after checking the result.")_print_stash_cleanup_guidance(stash_ref)else:drop = _git_run(git_cmd, ["stash", "drop", stash_selector], cwd)@@ -379,9 +361,7 @@ def _restore_stashed_changes(print("⚠ Local changes were restored, but Hermes couldn't drop the saved stash entry.")_print_nonempty(drop.stdout)_print_nonempty(drop.stderr)- print(- " The stash was left in place. You can remove it manually after checking the result."- )+ print(" The stash was left in place. You can remove it manually after checking the result.")_print_stash_cleanup_guidance(stash_ref, stash_selector)print("⚠ Local changes were restored on top of the updated codebase.")@@ -389,11 +369,7 @@ def _restore_stashed_changes(return True-def _discard_stashed_changes(- git_cmd: list[str],- cwd: Path,- stash_ref: str,-) -> bool:+def _discard_stashed_changes(git_cmd: list[str], cwd: Path, stash_ref: str) -> bool:"""Drop a pre-update stash without applying (non-interactive ``updates.non_interactive_local_changes: discard``).Unlike reset --hard + clean -fd this touches only what was stashed; ignored paths are never affected.@@ -411,10 +387,7 @@ def _discard_stashed_changes(drop = _git_run(git_cmd, ["stash", "drop", stash_selector], cwd)if drop.returncode != 0:- print(- "⚠ Configured to discard local changes, but Hermes couldn't drop "- "the saved stash entry."- )+ print("⚠ Configured to discard local changes, but Hermes couldn't drop the saved stash entry.")if drop.stderr.strip():print(f" {drop.stderr.strip().splitlines()[0]}")_print_stash_cleanup_guidance(stash_ref, stash_selector)diff --git a/hermes_cli/update_cmd_zip.py b/hermes_cli/update_cmd_zip.pyindex 9176bc943a6..001d41b6f81 100644--- a/hermes_cli/update_cmd_zip.py+++ b/hermes_cli/update_cmd_zip.py@@ -110,9 +110,7 @@ def _commit_staged_replacements(staged) -> None:_remove_path(backup, ignore_errors=True)-def _zip_overlay_block_reason(- root: Path, *, ignore_staging_artifacts: bool = False-) -> Optional[str]:+def _zip_overlay_block_reason(root: Path, *, ignore_staging_artifacts: bool = False) -> Optional[str]:"""Why overlaying a ZIP onto ``root`` would destroy work, or None if safe.The swap replaces every top-level entry (minus a tiny preserve set) and deletes backups, so uncommitted@@ -183,10 +181,7 @@ def _abort_zip_update_if_dirty_tree() -> None:if reason is None:returnprint(f"✗ ZIP fallback refused: {reason}.")- print(- " Overlaying the ZIP would overwrite uncommitted edits and permanently "- "delete untracked files."- )+ print(" Overlaying the ZIP would overwrite uncommitted edits and permanently delete untracked files.")print(" Stash or commit your changes, then rerun `hermes update`.")print(" To inspect: git status --porcelain")_m().sys.exit(1)@@ -285,9 +280,7 @@ def _download_and_swap_zip(branch: str, zip_url: str) -> None:try:# TOCTOU re-check right before the swap: download + extract + staging can take minutes and# work created meanwhile would be destroyed. Our own staging siblings are filtered out.- recheck_reason = _zip_overlay_block_reason(- _m().PROJECT_ROOT, ignore_staging_artifacts=True- )+ recheck_reason = _zip_overlay_block_reason(_m().PROJECT_ROOT, ignore_staging_artifacts=True)if recheck_reason is not None:_discard_staged(staged)print(f"✗ ZIP fallback aborted before the swap: {recheck_reason}.")@@ -363,11 +356,7 @@ def _reinstall_python_deps_after_zip(active_tool_dependencies) -> None:install_prefix = [uv_bin, "pip"] if uv_bin else pip_cmdinstall_env = uv_env if uv_bin else None- _m()._restore_active_tool_dependencies(- active_tool_dependencies,- install_prefix,- env=install_env,- )+ _m()._restore_active_tool_dependencies(active_tool_dependencies, install_prefix, env=install_env)# Parity with git-pull path: heal the active memory provider's bridge packages after the reinstall._m()._refresh_active_memory_provider_dependencies()@@ -400,7 +389,7 @@ def _update_via_zip(args, *, had_desktop_app_before_update: bool = False) -> boo# prevent. Refuse rather than lie.branch = _m()._resolve_update_branch(args)if branch != "main":- print(f"✗ --branch={branch} is not supported on the Windows ZIP-fallback " "update path.")+ print(f"✗ --branch={branch} is not supported on the Windows ZIP-fallback update path.")print(" This path runs when git file I/O is broken on the system. ""Either resolve the git-side breakage (typically an antivirus "