The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(hermes_cli): auth group B — pack signatures, move heal notice into _HealPass
Teknium856fd5613c97
diff --git a/hermes_cli/auth_codex.py b/hermes_cli/auth_codex.pyindex 02eaac9ba5d..f55cc77db9e 100644--- a/hermes_cli/auth_codex.py+++ b/hermes_cli/auth_codex.py@@ -105,9 +105,7 @@ def _read_codex_tokens(*, _lock: bool = True) -> Dict[str, Any]:def _sync_codex_pool_entries(- auth_store: Dict[str, Any],- tokens: Dict[str, str],- last_refresh: Optional[str],+ auth_store: Dict[str, Any], tokens: Dict[str, str], last_refresh: Optional[str],previous_singleton_tokens: Optional[Dict[str, str]] = None) -> None:"""Mirror a fresh Codex re-auth into the credential_pool OAuth entries.@@ -185,14 +183,9 @@ def _recover_codex_tokens_from_cli(reason: str) -> Optional[Dict[str, str]]:def _refresh_payload_access_token(- response: "httpx.Response",- *,- provider: str,- invalid_json: Tuple[str, str],- invalid_response: Optional[Tuple[str, str]],- missing_access: Tuple[str, str],- relogin_required: bool = True,- invalid_json_relogin: Optional[bool] = None,+ response: "httpx.Response", *, provider: str, invalid_json: Tuple[str, str],+ invalid_response: Optional[Tuple[str, str]], missing_access: Tuple[str, str],+ relogin_required: bool = True, invalid_json_relogin: Optional[bool] = None,strict_str: bool = True) -> Tuple[Dict[str, Any], str]:"""Parse a 200 token-refresh response; return ``(payload, stripped access_token)``.diff --git a/hermes_cli/auth_device_flow.py b/hermes_cli/auth_device_flow.pyindex ab377746465..a56d69a6033 100644--- a/hermes_cli/auth_device_flow.py+++ b/hermes_cli/auth_device_flow.py@@ -301,8 +301,7 @@ def _prompt_yes_no(prompt: str, *, default: str) -> bool:def _print_login_success(- provider_id: str, config_path: Path, *, show_auth_state: bool = False,-) -> None:+ provider_id: str, config_path: Path, *, show_auth_state: bool = False) -> None:print()print("Login successful!")if show_auth_state:diff --git a/hermes_cli/auth_nous.py b/hermes_cli/auth_nous.pyindex 83821d55e00..fb2f3f75625 100644--- a/hermes_cli/auth_nous.py+++ b/hermes_cli/auth_nous.py@@ -176,10 +176,7 @@ def _scope_values(raw_scope: Any) -> set[str]:def _nous_invoke_jwt_status(- token: Any,- *,- scope: Any = None,- expires_at: Any = None,+ token: Any, *, scope: Any = None, expires_at: Any = None,min_ttl_seconds: int = NOUS_INVOKE_JWT_MIN_TTL_SECONDS) -> Optional[str]:"""Return None when the token can be used for inference, else a reason."""from hermes_cli.auth import _is_expiring@@ -199,10 +196,7 @@ def _nous_invoke_jwt_status(def _nous_invoke_jwt_is_usable(- token: Any,- *,- scope: Any = None,- expires_at: Any = None,+ token: Any, *, scope: Any = None, expires_at: Any = None,min_ttl_seconds: int = NOUS_INVOKE_JWT_MIN_TTL_SECONDS) -> bool:from hermes_cli.auth import _nous_invoke_jwt_statusreturn _nous_invoke_jwt_status(diff --git a/hermes_cli/auth_oauth_grants.py b/hermes_cli/auth_oauth_grants.pyindex f22baaf453e..d6f188b8cb1 100644--- a/hermes_cli/auth_oauth_grants.py+++ b/hermes_cli/auth_oauth_grants.py@@ -246,25 +246,19 @@ def _singleton_as_row(path: Path) -> Optional[Dict[str, Any]]:"expires_at_ms": data.get("expiresAt")}-# One-time heal for installs that ALREADY forked a single-use grant (fleets created before the-# clone-strip / root-write-through). Those copies are one credential with several owners:-# whichever profile rotated last holds the only live refresh token and every other copy (root-# included) is spent; upgrading alone would keep each profile on its own doomed copy.-# ``heal_forked_single_use_oauth_grants`` runs at profile ``load_pool()`` time: it finds profile-# rows that share LINEAGE with a root row (same pool id, or same account identity / token-# material), keeps the copy most likely live (freshest rotation), writes it into ROOT when root's-# is older, and strips the profile's copy so the profile borrows root from then on. Idempotent,-# never touches API-key rows, never deletes a row with no root counterpart (an independent-# ``hermes -p <p> auth add`` grant, or the only surviving copy), and reads only the two auth.json-# files the existing root fallback already reads — no environ / secret-scope reads.--def heal_forked_single_use_oauth_grants(provider_id: str) -> Optional[Dict[str, Any]]:- """Consolidate a profile's forked copy of a single-use OAuth grant into root.-- Runs only in profile mode for ``SINGLE_USE_REFRESH_POOL_PROVIDERS``. Returns a summary- ``{"adopted": bool, "stripped_ids": [...], "files": [...], "providers_block": bool}`` when- something was healed, else ``None``. Never raises.+ """One-time heal for installs that ALREADY forked a single-use grant into a profile.++ Forked copies are one credential with several owners: whichever profile rotated last holds the+ only live refresh token and every other copy (root included) is spent. Runs at profile+ ``load_pool()`` time for ``SINGLE_USE_REFRESH_POOL_PROVIDERS``: finds profile rows sharing+ LINEAGE with a root row (same pool id, or same account identity / token material), keeps the+ freshest rotation, writes it into ROOT when root's is older, and strips the profile's copy so+ the profile borrows root from then on. Idempotent; never touches API-key rows; never deletes a+ row with no root counterpart (an independent ``hermes -p <p> auth add`` grant, or the only+ surviving copy); reads only the two auth.json files the root fallback already reads. Returns+ ``{"adopted", "stripped_ids", "files", "providers_block"}`` when something healed, else None.+ Never raises."""if provider_id not in SINGLE_USE_REFRESH_POOL_PROVIDERS:return None@@ -446,6 +440,23 @@ class _HealPass:def dirty(self) -> bool:return bool(self.profile_changed or self.root_changed or self.summary["adopted"])+ def notice(self, profile_name: str) -> str:+ summary = self.summary+ log_bits: List[str] = []+ if summary["stripped_ids"]:+ log_bits.append(f"pool rows {summary['stripped_ids']}")+ if summary["providers_block"]:+ log_bits.append(f"providers.{self.provider_id} block")+ if summary["files"]:+ log_bits.append(", ".join(summary["files"]))+ verdict = (+ "profile copy was the live pair; root updated"+ if summary["adopted"] else "root copy already newest; profile copy dropped")+ return (+ f"profile {profile_name}: consolidated forked {self.provider_id} OAuth grant "+ f"({'; '.join(log_bits) or 'no-op'}) into the root grant — {verdict}; "+ f"this profile now borrows the root grant (#100339)")+def _heal_forked_single_use_oauth_grants(provider_id: str) -> Optional[Dict[str, Any]]:from hermes_cli.auth import (@@ -508,20 +519,7 @@ def _heal_forked_single_use_oauth_grants(provider_id: str) -> Optional[Dict[str,if run.profile_changed and profile_path.exists():_save_auth_store(profile_store, target_path=profile_path)- log_bits: List[str] = []- if summary["stripped_ids"]:- log_bits.append(f"pool rows {summary['stripped_ids']}")- if summary["providers_block"]:- log_bits.append(f"providers.{provider_id} block")- if summary["files"]:- log_bits.append(", ".join(summary["files"]))- verdict = (- "profile copy was the live pair; root updated"- if summary["adopted"] else "root copy already newest; profile copy dropped")- message = (- f"profile {profile_home.name}: consolidated forked {provider_id} OAuth grant "- f"({'; '.join(log_bits) or 'no-op'}) into the root grant — {verdict}; "- f"this profile now borrows the root grant (#100339)")+ message = run.notice(profile_home.name)logger.info(message)_oauth_heal_notices.append(message)return summary