Skip to content

The agent that grows with you

refactor(tools): mcp_oauth CIMD eligibility comments inline; lazy_deps install_specs/ensure guard folds

Teknium55ba3184b714
diff --git a/tools/lazy_deps.py b/tools/lazy_deps.py
index d73a88b1418..ed369a18e0c 100644
--- a/tools/lazy_deps.py
+++ b/tools/lazy_deps.py
@@ -491,7 +491,6 @@ def _venv_pip_install(specs: tuple[str, ...], *, timeout: int = 300) -> _Install
Independent of ``hermes_cli.tools_config._pip_install`` (no CLI dependency)."""
if not specs:
return _InstallResult(True, "", "")
-
target = _lazy_install_target()
constraints: Optional[Path] = None
extra_args: list[str] = []
@@ -601,12 +600,10 @@ def ensure(feature: str, *, prompt: bool = True) -> None:
# burning ~15s on ensurepip — unless a durable target is configured. The reason MUST start
# with "unsupported ": _refresh_features classifies skips by that prefix.
if _lazy_install_target() is None:
- try:
+ managed_by = "" # config unreadable — proceed with the install
+ with contextlib.suppress(Exception):
from hermes_cli.config import get_managed_system
-
managed_by = get_managed_system()
- except Exception:
- managed_by = "" # config unreadable — proceed with the install
if managed_by:
raise FeatureUnavailable(
feature, missing,
@@ -661,9 +658,7 @@ def feature_install_command(feature: str, *, venv_pip: bool = False) -> Optional
if feature not in LAZY_DEPS:
return None
joined = " ".join(repr(s) for s in LAZY_DEPS[feature])
- if venv_pip:
- return f"{sys.executable} -m pip install {joined}"
- return "uv pip install " + joined
+ return f"{sys.executable} -m pip install {joined}" if venv_pip else "uv pip install " + joined
@dataclass
@@ -694,14 +689,11 @@ def install_specs(specs: list[str] | tuple[str, ...], *, timeout: int = 300) ->
target = _lazy_install_target()
if not _allow_lazy_installs():
- if os.environ.get("HERMES_DISABLE_LAZY_INSTALLS") == "1" and target is None:
- reason = (
- "runtime installs are disabled on this deployment: the agent "
- "environment is immutable and no writable install target is "
- "configured (HERMES_LAZY_INSTALL_TARGET)"
- )
- else:
- reason = "runtime installs disabled (security.allow_lazy_installs=false)"
+ sealed = os.environ.get("HERMES_DISABLE_LAZY_INSTALLS") == "1" and target is None
+ reason = (
+ "runtime installs are disabled on this deployment: the agent environment is immutable "
+ "and no writable install target is configured (HERMES_LAZY_INSTALL_TARGET)"
+ ) if sealed else "runtime installs disabled (security.allow_lazy_installs=false)"
return InstallSpecsResult(ok=False, blocked=True, reason=reason)
display = "uv pip install " + (f"--target {target} " if target is not None else "") + " ".join(cleaned)
diff --git a/tools/mcp_oauth.py b/tools/mcp_oauth.py
index 9b17bb11044..610d6e19a7d 100644
--- a/tools/mcp_oauth.py
+++ b/tools/mcp_oauth.py
@@ -737,25 +737,19 @@ def _maybe_use_cimd(cfg: dict, storage: "HermesTokenStorage | None" = None) -> "
ineligible = (
cfg.get("cimd") is False
or not _is_valid_cimd_url(url)
- # A pinned client is the user's explicit choice; a secret means a confidential
- # client, which the document forbids.
+ # pinned client = explicit choice; a secret = confidential client, which the document forbids
or cfg.get("client_id") or cfg.get("client_secret")
- # The document supplies name and auth method; a caller setting either asks for an
- # identity CIMD cannot present (Figma's DCR name allowlist).
+ # the document supplies name + auth method; setting either asks for an identity CIMD can't present
or cfg.get("client_name") or (cfg.get("token_endpoint_auth_method") or "none") != "none"
- # Dashboard/desktop flows redirect to a deployment-specific server URL that can
- # never appear in a static document.
+ # dashboard/desktop flows redirect to a deployment-specific URL no static document declares
or get_dashboard_oauth_flow() is not None
or cfg.get("redirect_uri") or cfg.get("redirect_port")
or (cfg.get("redirect_host") or "127.0.0.1") not in _CIMD_REDIRECT_HOSTS
- # An existing registration is bound to its redirect URI; swapping in a CIMD
- # client_id now would invalidate stored tokens.
+ # an existing registration is bound to its redirect URI; swapping client_id would drop tokens
or _cached_client_info(storage) is not None
or (storage is not None and storage.cimd_rejected())
or _server_declined_cimd(storage))
- if ineligible:
- return None
- port = _pick_cimd_port()
+ port = None if ineligible else _pick_cimd_port()
return None if port is None else (url, port)
@@ -796,8 +790,7 @@ def _configure_callback_port(cfg: dict, storage: "HermesTokenStorage | None" = N
cfg["_cimd_url"], port = cimd
else:
port = int(cfg.get("redirect_port", 0)) or cached_port or _reserve_callback_port()
- # A cached port may be a pinned CIMD port left by an earlier CIMD login; claim it so a
- # sibling's _pick_cimd_port doesn't reuse it.
+ # A cached port may be a pinned CIMD port from an earlier login; claim it from siblings.
if port in _CIMD_PORTS and port not in _assigned_cimd_ports:
_assigned_cimd_ports.append(port)
cfg["_resolved_port"] = port