refactor(hermes_cli): final micro-collapses across slice E (parse_spawn_tag, coerced_dataclass, base-url loop)
This commit is contained in:
@@ -523,9 +523,7 @@ def _tool_access_from_value(value: Any) -> Optional[NousToolAccessInfo]:
|
||||
|
||||
def _coerced_dataclass(cls, value: Any):
|
||||
"""Build ``cls`` from a payload dict (field names = payload keys), coercing by declared type."""
|
||||
if not isinstance(value, dict):
|
||||
return None
|
||||
return cls(**{f.name: _COERCERS[f.type](value.get(f.name)) for f in fields(cls)})
|
||||
return cls(**{f.name: _COERCERS[f.type](value.get(f.name)) for f in fields(cls)}) if isinstance(value, dict) else None
|
||||
|
||||
|
||||
def _subscription_from_payload(value: Any) -> Optional[NousPortalSubscriptionInfo]:
|
||||
|
||||
@@ -18,8 +18,7 @@ from typing import Any, Optional
|
||||
|
||||
DEFAULT_PORTAL_BASE_URL = "https://portal.nousresearch.com"
|
||||
|
||||
# Tight so a hung portal doesn't freeze the TUI (charge/poll calls are quick).
|
||||
DEFAULT_TIMEOUT = 15.0
|
||||
DEFAULT_TIMEOUT = 15.0 # tight so a hung portal doesn't freeze the TUI (charge/poll calls are quick)
|
||||
|
||||
|
||||
# --- Typed errors ---
|
||||
@@ -101,8 +100,7 @@ class BillingUpgradeCapExceeded(BillingTransient):
|
||||
def resolve_portal_base_url(state: Optional[dict[str, Any]] = None) -> str:
|
||||
"""Resolve the portal base URL with login-time precedence: env, stored state, default."""
|
||||
env = os.getenv("HERMES_PORTAL_BASE_URL") or os.getenv("NOUS_PORTAL_BASE_URL")
|
||||
stored = state.get("portal_base_url") if state else None
|
||||
for candidate in (env, stored):
|
||||
for candidate in (env, state.get("portal_base_url") if state else None):
|
||||
if isinstance(candidate, str) and candidate.strip():
|
||||
return candidate.strip().rstrip("/")
|
||||
return DEFAULT_PORTAL_BASE_URL
|
||||
|
||||
@@ -63,8 +63,7 @@ def _cmd_approve(store, platform: str, code: str):
|
||||
else:
|
||||
result = store.approve_code(platform, code.upper())
|
||||
if result:
|
||||
uid = result["user_id"]
|
||||
name = result.get("user_name") or ""
|
||||
uid, name = result["user_id"], result.get("user_name") or ""
|
||||
display = f"{name} ({uid})" if name else uid
|
||||
print(f"\n Approved! User {display} on {platform} can now use the bot~")
|
||||
print(" They'll be recognized automatically on their next message.\n")
|
||||
|
||||
@@ -89,9 +89,7 @@ def spawn_env(purpose: str, *, project_root: Optional[Path] = None) -> dict[str,
|
||||
|
||||
def parse_spawn_tag(raw: object) -> Optional[SpawnTag]:
|
||||
"""Parse a ``HERMES_SPAWN`` value; ``None`` for anything malformed."""
|
||||
if not isinstance(raw, str):
|
||||
return None
|
||||
parts = raw.split(":")
|
||||
parts = raw.split(":") if isinstance(raw, str) else []
|
||||
if len(parts) != 5 or parts[0] != _TAG_VERSION:
|
||||
return None
|
||||
_, install, purpose, pid_s, create_s = parts
|
||||
|
||||
Reference in New Issue
Block a user