Skip to content

The agent that grows with you

refactor: accept falsy scope in hermes_home_key, drop redundant guards

ethernet6e171c3aeac1
diff --git a/agent/browser_registry.py b/agent/browser_registry.py
index 068c79aa92c..1d78fb6b11f 100644
--- a/agent/browser_registry.py
+++ b/agent/browser_registry.py
@@ -93,10 +93,9 @@ def register_provider(provider: BrowserProvider, *, scope: Optional[str] = None)
def list_providers(*, scope: Optional[str] = None) -> List[BrowserProvider]:
"""Return all registered providers, sorted by name."""
- scope = hermes_home_key(scope) if scope is not None else None
with _lock:
merged = dict(_providers)
- merged.update(_scoped_providers.get(scope or hermes_home_key(), {}))
+ merged.update(_scoped_providers.get(hermes_home_key(scope), {}))
items = list(merged.values())
return sorted(items, key=lambda p: p.name)
@@ -105,10 +104,9 @@ def get_provider(name: str, *, scope: Optional[str] = None) -> Optional[BrowserP
"""Return the provider registered under *name*, or None."""
if not isinstance(name, str):
return None
- scope = hermes_home_key(scope) if scope is not None else None
with _lock:
key = name.strip()
- return _scoped_providers.get(scope or hermes_home_key(), {}).get(key) or _providers.get(key)
+ return _scoped_providers.get(hermes_home_key(scope), {}).get(key) or _providers.get(key)
def snapshot_registration(
@@ -122,7 +120,7 @@ def snapshot_registration(
def registry_generation(*, scope: Optional[str] = None) -> tuple[int, int]:
"""Return a cache fingerprint for the global base and one profile."""
- active_scope = hermes_home_key(scope) if scope is not None else hermes_home_key()
+ active_scope = hermes_home_key(scope)
with _lock:
return _generation, _scoped_generations.get(active_scope, 0)
diff --git a/agent/image_gen_registry.py b/agent/image_gen_registry.py
index 6239bbe891f..53a0bdaf18d 100644
--- a/agent/image_gen_registry.py
+++ b/agent/image_gen_registry.py
@@ -65,7 +65,7 @@ def list_providers(*, scope: Optional[str] = None) -> List[ImageGenProvider]:
"""Return all registered providers, sorted by name."""
with _lock:
merged = dict(_providers)
- merged.update(_scoped_providers.get(scope or hermes_home_key(), {}))
+ merged.update(_scoped_providers.get(hermes_home_key(scope), {}))
items = list(merged.values())
return sorted(items, key=lambda p: p.name)
@@ -76,7 +76,7 @@ def get_provider(name: str, *, scope: Optional[str] = None) -> Optional[ImageGen
return None
with _lock:
key = name.strip()
- return _scoped_providers.get(scope or hermes_home_key(), {}).get(key) or _providers.get(key)
+ return _scoped_providers.get(hermes_home_key(scope), {}).get(key) or _providers.get(key)
def snapshot_registration(
diff --git a/agent/secret_sources/registry.py b/agent/secret_sources/registry.py
index 745320af230..93c492ea5bf 100644
--- a/agent/secret_sources/registry.py
+++ b/agent/secret_sources/registry.py
@@ -169,9 +169,8 @@ def register_source(
def get_source(name: str, *, scope: Optional[str] = None) -> Optional[SecretSource]:
_ensure_builtin_sources()
- scope = hermes_home_key(scope) if scope is not None else None
with _REGISTRY_LOCK:
- return _SCOPED_SOURCES.get(scope or hermes_home_key(), {}).get(
+ return _SCOPED_SOURCES.get(hermes_home_key(scope), {}).get(
name
) or _SOURCES.get(name)
@@ -212,10 +211,9 @@ def restore_registration(
def list_sources(*, scope: Optional[str] = None) -> List[SecretSource]:
_ensure_builtin_sources()
- scope = hermes_home_key(scope) if scope is not None else None
with _REGISTRY_LOCK:
merged = dict(_SOURCES)
- merged.update(_SCOPED_SOURCES.get(scope or hermes_home_key(), {}))
+ merged.update(_SCOPED_SOURCES.get(hermes_home_key(scope), {}))
return list(merged.values())
diff --git a/agent/terminal_env_registry.py b/agent/terminal_env_registry.py
index 3c65cd2242b..0a3b1f491d8 100644
--- a/agent/terminal_env_registry.py
+++ b/agent/terminal_env_registry.py
@@ -101,7 +101,7 @@ def list_providers(*, scope: Optional[str] = None) -> List[TerminalEnvironmentPr
"""Return all registered providers, sorted by name."""
with _lock:
merged = dict(_providers)
- merged.update(_scoped_providers.get(scope or hermes_home_key(), {}))
+ merged.update(_scoped_providers.get(hermes_home_key(scope), {}))
items = list(merged.values())
return sorted(items, key=lambda p: p.name)
@@ -115,7 +115,7 @@ def get_provider(
key = name.strip().lower()
with _lock:
return (
- _scoped_providers.get(scope or hermes_home_key(), {}).get(key)
+ _scoped_providers.get(hermes_home_key(scope), {}).get(key)
or _providers.get(key)
)
@@ -179,7 +179,7 @@ def snapshot_registration(
def registry_generation(*, scope: Optional[str] = None) -> tuple:
"""Return a cache fingerprint for the global base and one profile."""
- active_scope = scope or hermes_home_key()
+ active_scope = hermes_home_key(scope)
with _lock:
return _generation, _scoped_generations.get(active_scope, 0)
diff --git a/agent/transcription_registry.py b/agent/transcription_registry.py
index a167e710b55..9b10b8c4e52 100644
--- a/agent/transcription_registry.py
+++ b/agent/transcription_registry.py
@@ -106,7 +106,7 @@ def list_providers(*, scope: Optional[str] = None) -> List[TranscriptionProvider
"""Return all registered providers, sorted by name."""
with _lock:
merged = dict(_providers)
- merged.update(_scoped_providers.get(scope or hermes_home_key(), {}))
+ merged.update(_scoped_providers.get(hermes_home_key(scope), {}))
items = list(merged.values())
return sorted(items, key=lambda p: p.name)
@@ -122,7 +122,7 @@ def get_provider(name: str, *, scope: Optional[str] = None) -> Optional[Transcri
return None
key = name.strip().lower()
with _lock:
- return _scoped_providers.get(scope or hermes_home_key(), {}).get(key) or _providers.get(key)
+ return _scoped_providers.get(hermes_home_key(scope), {}).get(key) or _providers.get(key)
def snapshot_registration(
diff --git a/agent/tts_registry.py b/agent/tts_registry.py
index 5e8f94b4598..e50315df064 100644
--- a/agent/tts_registry.py
+++ b/agent/tts_registry.py
@@ -116,7 +116,7 @@ def list_providers(*, scope: Optional[str] = None) -> List[TTSProvider]:
"""Return all registered providers, sorted by name."""
with _lock:
merged = dict(_providers)
- merged.update(_scoped_providers.get(scope or hermes_home_key(), {}))
+ merged.update(_scoped_providers.get(hermes_home_key(scope), {}))
items = list(merged.values())
return sorted(items, key=lambda p: p.name)
@@ -132,7 +132,7 @@ def get_provider(name: str, *, scope: Optional[str] = None) -> Optional[TTSProvi
return None
key = name.strip().lower()
with _lock:
- return _scoped_providers.get(scope or hermes_home_key(), {}).get(key) or _providers.get(key)
+ return _scoped_providers.get(hermes_home_key(scope), {}).get(key) or _providers.get(key)
def snapshot_registration(
diff --git a/agent/video_gen_registry.py b/agent/video_gen_registry.py
index 5b4c9cea549..80305367f87 100644
--- a/agent/video_gen_registry.py
+++ b/agent/video_gen_registry.py
@@ -69,7 +69,7 @@ def list_providers(*, scope: Optional[str] = None) -> List[VideoGenProvider]:
"""Return all registered providers, sorted by name."""
with _lock:
merged = dict(_providers)
- merged.update(_scoped_providers.get(scope or hermes_home_key(), {}))
+ merged.update(_scoped_providers.get(hermes_home_key(scope), {}))
items = list(merged.values())
return sorted(items, key=lambda p: p.name)
@@ -80,7 +80,7 @@ def get_provider(name: str, *, scope: Optional[str] = None) -> Optional[VideoGen
return None
with _lock:
key = name.strip()
- return _scoped_providers.get(scope or hermes_home_key(), {}).get(key) or _providers.get(key)
+ return _scoped_providers.get(hermes_home_key(scope), {}).get(key) or _providers.get(key)
def snapshot_registration(
diff --git a/agent/web_search_registry.py b/agent/web_search_registry.py
index 5260272133f..e425416c9cc 100644
--- a/agent/web_search_registry.py
+++ b/agent/web_search_registry.py
@@ -83,7 +83,7 @@ def list_providers(*, scope: Optional[str] = None) -> List[WebSearchProvider]:
"""Return all registered providers, sorted by name."""
with _lock:
merged = dict(_providers)
- merged.update(_scoped_providers.get(scope or hermes_home_key(), {}))
+ merged.update(_scoped_providers.get(hermes_home_key(scope), {}))
items = list(merged.values())
return sorted(items, key=lambda p: p.name)
@@ -94,7 +94,7 @@ def get_provider(name: str, *, scope: Optional[str] = None) -> Optional[WebSearc
return None
with _lock:
key = name.strip()
- return _scoped_providers.get(scope or hermes_home_key(), {}).get(key) or _providers.get(key)
+ return _scoped_providers.get(hermes_home_key(scope), {}).get(key) or _providers.get(key)
def snapshot_registration(
diff --git a/hermes_cli/dashboard_auth/registry.py b/hermes_cli/dashboard_auth/registry.py
index 33b58305179..b4c3bda2ab5 100644
--- a/hermes_cli/dashboard_auth/registry.py
+++ b/hermes_cli/dashboard_auth/registry.py
@@ -24,7 +24,7 @@ _scoped_providers: dict[str, dict[str, DashboardAuthProvider]] = {}
def _merged(scope: Optional[str] = None) -> dict[str, DashboardAuthProvider]:
providers = dict(_providers)
- providers.update(_scoped_providers.get(scope or hermes_home_key(), {}))
+ providers.update(_scoped_providers.get(hermes_home_key(scope), {}))
return providers
diff --git a/hermes_cli/plugins.py b/hermes_cli/plugins.py
index 5bbad05ff9d..1ec926e0b8d 100644
--- a/hermes_cli/plugins.py
+++ b/hermes_cli/plugins.py
@@ -3743,7 +3743,7 @@ class PluginManager:
# profile context, but every inverse must target the registration's
# original scope. Normalize through hermes_home_key so the scope
# matches the key the registries store under (normcase on Windows).
- self.scope_key = hermes_home_key(scope_key) if scope_key else hermes_home_key()
+ self.scope_key = hermes_home_key(scope_key)
self.home_path = Path(self.scope_key)
self._discovery_lock = threading.RLock()
self._plugins: Dict[str, LoadedPlugin] = {}
diff --git a/hermes_constants.py b/hermes_constants.py
index 4bd9d583b27..5da5ed5fea4 100644
--- a/hermes_constants.py
+++ b/hermes_constants.py
@@ -142,11 +142,12 @@ def get_hermes_home() -> Path:
def hermes_home_key(path: str | Path | None = None) -> str:
"""Return a stable key for a Hermes home/profile directory.
+ A falsy path (``None`` or empty) resolves to the active default home.
Runtime registries use this key to isolate plugin-owned entries while
keeping built-in registrations process-global. ``strict=False`` preserves
useful behavior for profiles whose directories have not been created yet.
"""
- candidate = Path(path) if path is not None else get_hermes_home()
+ candidate = Path(path) if path else get_hermes_home()
resolved = candidate.expanduser().resolve(strict=False)
return os.path.normcase(str(resolved))