Skip to content

The agent that grows with you

fix(config): add a collision-safe env var name for custom endpoint keys

Brooklyn Nicholsonbfe7460c79fa
diff --git a/hermes_cli/config.py b/hermes_cli/config.py
index d4e9ed843ca..cc03c5a57b5 100644
--- a/hermes_cli/config.py
+++ b/hermes_cli/config.py
@@ -8209,6 +8209,25 @@ def save_env_value(key: str, value: str):
invalidate_env_cache()
+def custom_endpoint_key_env(identity: str) -> str:
+ """Env var name holding a custom endpoint's API key.
+
+ ``identity`` is whatever names the endpoint on the calling path — the
+ Desktop panel's endpoint id, or ``host:port`` for the CLI setup flow.
+ Two properties matter:
+
+ - It keys off the endpoint's own identity, not just its hostname, so two
+ endpoints on one host (``127.0.0.1:8000`` and ``:8001``) get separate
+ slots instead of the second save clobbering the first's credential.
+ - The fixed ``HERMES_CUSTOM_`` prefix keeps the result a valid POSIX name
+ even when the slug starts with a digit, which every IP-based local
+ endpoint does (``127.0.0.1`` → ``127_0_0_1``). ``save_env_value``
+ rejects digit-leading names outright.
+ """
+ slug = re.sub(r"[^A-Z0-9]+", "_", str(identity or "").upper()).strip("_")
+ return f"HERMES_CUSTOM_{slug}_API_KEY" if slug else "HERMES_CUSTOM_API_KEY"
+
+
def remove_env_value(key: str) -> bool:
"""Remove a key from ~/.hermes/.env and os.environ.