Skip to content

The agent that grows with you

fix: validate gateway launch options before first-run config checks

Tekniumbec94623041e
diff --git a/hermes_cli/gateway_chat.py b/hermes_cli/gateway_chat.py
index 76500a5ef42..e7f84e9ad95 100644
--- a/hermes_cli/gateway_chat.py
+++ b/hermes_cli/gateway_chat.py
@@ -80,6 +80,9 @@ def launch_from_args(args) -> int:
from websockets.exceptions import WebSocketException
try:
validate_options(args)
+ from hermes_cli.gateway_chat_startup import ensure_launch_provider
+ if not ensure_launch_provider(args):
+ return 0
query_file = getattr(args, "query_file", None)
if query_file:
args.query = sys.stdin.read() if query_file == "-" else Path(query_file).read_text(encoding="utf-8")
diff --git a/hermes_cli/gateway_chat_startup.py b/hermes_cli/gateway_chat_startup.py
index a53560131f0..7df48c810b5 100644
--- a/hermes_cli/gateway_chat_startup.py
+++ b/hermes_cli/gateway_chat_startup.py
@@ -1,30 +1,33 @@
"""Frontend startup checks shared by classic chat and top-level one-shot."""
from __future__ import annotations
+import os
+
+
+def ensure_launch_provider(args) -> bool:
+ from hermes_cli.main import _first_run_setup_guard, _has_any_provider_configured
+
+ # A resumed/remote session owns its provider policy. Explicit endpoint/key
+ # launches can also be usable without a configured local profile.
+ if (
+ getattr(args, "resume", None)
+ or os.environ.get("HERMES_TUI_GATEWAY_URL", "").strip()
+ or getattr(args, "base_url", None)
+ or getattr(args, "api_key", None)
+ or _has_any_provider_configured()
+ ):
+ return True
+ _first_run_setup_guard(args)
+ return False
+
def launch_gateway_chat(args) -> int:
try:
- from hermes_cli.main import (
- _confirm_startup_expensive_model_override,
- _first_run_setup_guard,
- _has_any_provider_configured,
- )
+ from hermes_cli.main import _confirm_startup_expensive_model_override
from hermes_cli.gateway_chat import launch_from_args
- import os
# Consent belongs before discovery/admission, even with --yolo.
_confirm_startup_expensive_model_override(args)
- # A resumed/remote session owns its provider policy. Explicit endpoint/key
- # launches can also be usable without a configured local profile.
- if not (
- getattr(args, "resume", None)
- or os.environ.get("HERMES_TUI_GATEWAY_URL", "").strip()
- or getattr(args, "base_url", None)
- or getattr(args, "api_key", None)
- or _has_any_provider_configured()
- ):
- _first_run_setup_guard(args)
- return 0
return launch_from_args(args)
except ImportError as exc:
from hermes_constants import emit_partial_update_hint
diff --git a/tests/hermes_cli/test_gateway_startup_validation.py b/tests/hermes_cli/test_gateway_startup_validation.py
new file mode 100644
index 00000000000..58122924482
--- /dev/null
+++ b/tests/hermes_cli/test_gateway_startup_validation.py
@@ -0,0 +1,13 @@
+"""Invalid launch options must not inspect configuration they bypass."""
+from argparse import Namespace
+
+
+def test_invalid_options_are_reported_before_reading_profile(monkeypatch, capsys):
+ from hermes_cli.gateway_chat_startup import launch_gateway_chat
+
+ def unexpected():
+ raise AssertionError("Unsupported launch read profile configuration")
+
+ monkeypatch.setattr("hermes_cli.main._has_any_provider_configured", unexpected)
+ assert launch_gateway_chat(Namespace(safe_mode=True)) == 2
+ assert "--safe-mode" in capsys.readouterr().err