From fd7a8a0face77ea242f1d0e63cd4896c49046491 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 21:44:40 -0700 Subject: [PATCH] refactor(hermes_cli): collapse banner comments to one-liners across slice E --- hermes_cli/nous_billing.py | 20 +++++--------------- hermes_cli/nous_subscription.py | 6 +----- hermes_cli/process_identity.py | 17 ++++------------- 3 files changed, 10 insertions(+), 33 deletions(-) diff --git a/hermes_cli/nous_billing.py b/hermes_cli/nous_billing.py index c1114b86bb..354b1f1700 100644 --- a/hermes_cli/nous_billing.py +++ b/hermes_cli/nous_billing.py @@ -22,9 +22,7 @@ DEFAULT_PORTAL_BASE_URL = "https://portal.nousresearch.com" DEFAULT_TIMEOUT = 15.0 -# ============================================================================= -# Typed errors -# ============================================================================= +# --- Typed errors --- class BillingError(Exception): @@ -97,9 +95,7 @@ class BillingUpgradeCapExceeded(BillingTransient): """ -# ============================================================================= -# Base-URL + auth resolution -# ============================================================================= +# --- Base-URL + auth resolution --- def resolve_portal_base_url(state: Optional[dict[str, Any]] = None) -> str: @@ -180,9 +176,7 @@ def _resolve_token_and_base(*, use_cache: bool = True) -> tuple[str, str]: return resolved -# ============================================================================= -# HTTP plumbing -# ============================================================================= +# --- HTTP plumbing --- def _retry_after_seconds(headers: Any) -> Optional[int]: @@ -287,9 +281,7 @@ def _request( raise BillingError("Could not reach Nous Portal: timed out", error="network_error") from exc -# ============================================================================= -# Endpoints -# ============================================================================= +# --- Endpoints --- def _require_str(value: Any, message: str, error: str) -> str: @@ -342,9 +334,7 @@ def get_subscription_state(*, timeout: float = DEFAULT_TIMEOUT) -> dict[str, Any return _request("GET", "/api/billing/subscription", timeout=timeout) -# ============================================================================= -# Subscription change — preview + the pending-change resource + upgrade -# ============================================================================= +# --- Subscription change — preview + the pending-change resource + upgrade --- # Chargeless lane: preview (quote only) and PUT/DELETE pending-change (schedule/clear a downgrade # or cancellation, effective at period end). The ONE money route: POST upgrade (prorate + charge # + flip the plan in one Stripe op). All require ``billing:manage`` (403 insufficient_scope -> diff --git a/hermes_cli/nous_subscription.py b/hermes_cli/nous_subscription.py index 16e5abdd43..2c882d6652 100644 --- a/hermes_cli/nous_subscription.py +++ b/hermes_cli/nous_subscription.py @@ -558,9 +558,7 @@ def apply_nous_managed_defaults( return changed -# --------------------------------------------------------------------------- -# Tool Gateway offer — single Y/n prompt after model selection -# --------------------------------------------------------------------------- +# Tool Gateway offer — per-tool checklist after model selection def _get_gateway_direct_credentials() -> Dict[str, bool]: @@ -689,9 +687,7 @@ def prompt_enable_tool_gateway(config: Dict[str, object], *, force_fresh: bool = return changed -# --------------------------------------------------------------------------- # Inline Nous Portal login for the Tool Gateway picker (`hermes tools`) -# --------------------------------------------------------------------------- def ensure_nous_portal_access(*, capability: str = "the Nous Tool Gateway", coverage_category: Optional[str] = None) -> bool: diff --git a/hermes_cli/process_identity.py b/hermes_cli/process_identity.py index 3c621aa92a..a8bb8d6336 100644 --- a/hermes_cli/process_identity.py +++ b/hermes_cli/process_identity.py @@ -38,10 +38,6 @@ _JOB_HANDLE = None _LEDGER_LOCK = threading.Lock() -# --------------------------------------------------------------------------- -# Install identity -# --------------------------------------------------------------------------- - def install_id(project_root: Optional[Path] = None) -> str: """Stable 12-hex identifier for THIS install (derived from its path).""" if project_root is None: @@ -68,9 +64,8 @@ def _process_create_time(pid: Optional[int] = None) -> Optional[float]: return None -# --------------------------------------------------------------------------- # Layer 1 — spawn tags -# --------------------------------------------------------------------------- + @dataclass(frozen=True) class SpawnTag: @@ -107,14 +102,11 @@ def parse_spawn_tag(raw: object) -> Optional[SpawnTag]: create = None if create_s == "-" else float(create_s) except ValueError: return None - if pid <= 0: - return None - return SpawnTag(install=install, purpose=purpose, spawner_pid=pid, spawner_create=create) + return SpawnTag(install, purpose, pid, create) if pid > 0 else None -# --------------------------------------------------------------------------- # Layer 2 — spawn ledger -# --------------------------------------------------------------------------- + @dataclass class LedgerEntry: @@ -368,9 +360,8 @@ def reap_orphaned_mcp_helpers(*, project_root: Optional[Path] = None, kill_fn=No return reaped -# --------------------------------------------------------------------------- # Layer 3 — Windows job-object self-attach -# --------------------------------------------------------------------------- + def attach_self_to_kill_on_close_job() -> bool: """Place this process in a job that dies (whole tree) when we die. Windows-only, idempotent.