The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): refuse a --safe-mode TUI launch without --model before the TUI starts
Teknium19d752685717
diff --git a/hermes_cli/main_tui_launch.py b/hermes_cli/main_tui_launch.pyindex 641b7da4339..34a3b418d54 100644--- a/hermes_cli/main_tui_launch.py+++ b/hermes_cli/main_tui_launch.py@@ -348,6 +348,20 @@ def _setup_tui_worktree() -> dict:return wt_info+def _require_bypass_model(env: dict, model: Optional[str], resume_session_id: Optional[str]) -> None:+ """A --safe-mode / --ignore-user-config session reads no profile default model, so the owner+ refuses its session.create without one (bare invalid_params). Say so before the TUI starts,+ as classic chat does; a resume reuses the frozen route and needs none."""+ from utils import is_truthy_value+ bypass = any(is_truthy_value(env.get(name)) for name in ("HERMES_SAFE_MODE", "HERMES_IGNORE_USER_CONFIG"))+ if bypass and not resume_session_id and not (model or env.get("HERMES_MODEL", "").strip()):+ print("Error: --safe-mode / --ignore-user-config (or HERMES_IGNORE_USER_CONFIG=1) read no profile "+ "default model: pass --model explicitly.\n"+ " Example: hermes --tui --safe-mode --provider openrouter --model anthropic/claude-sonnet-4",+ file=sys.stderr)+ raise SystemExit(1)++def _launch_tui(resume_session_id: Optional[str] = None, tui_dev: bool = False, native_mode: Optional[bool] = None,model: Optional[str] = None,@@ -364,6 +378,7 @@ def _launch_tui(# the single factory; keep secrets (the TUI/agent needs provider creds).from tools.environments.local import build_subprocess_envenv = build_subprocess_env(scrub_secrets=False, inherit_profile_home=True)+ _require_bypass_model(env, model, resume_session_id)# The directory this launch was invoked from is the source of truth. An inherited# HERMES_CWD (exported by an outer `hermes --tui`, or by the user's own shell) merely# names *a* real directory, so the is_dir() repair in _apply_tui_python_env keeps itdiff --git a/tests/hermes_cli/test_tui_resume_flow.py b/tests/hermes_cli/test_tui_resume_flow.pyindex 3b3272bda79..6d6ab584851 100644--- a/tests/hermes_cli/test_tui_resume_flow.py+++ b/tests/hermes_cli/test_tui_resume_flow.py@@ -361,3 +361,23 @@ def test_launch_tui_local_session_starts_in_launch_dir_not_terminal_cwd(monkeypaelse:assert "HERMES_TUI_CWD" not in envassert Path(env["TERMINAL_CWD"]).resolve() == configured.resolve()++[email protected]("flag", ["HERMES_SAFE_MODE", "HERMES_IGNORE_USER_CONFIG"])+def test_launch_tui_bypass_without_model_refuses_before_the_tui_starts(monkeypatch, main_mod, capsys, flag):+ """`hermes --tui --safe-mode` (or an exported HERMES_IGNORE_USER_CONFIG=1) reads no profile+ default model: the owner refuses session.create with bare invalid_params, so the launcher must+ say "pass --model" before spawning the TUI, as classic chat does."""+ monkeypatch.setenv(flag, "1")+ monkeypatch.delenv("HERMES_MODEL", raising=False)+ monkeypatch.setattr(main_tui_launch, "_make_tui_argv",+ lambda tui_dir, tui_dev: (["node", "dist/entry.js"], Path(".")))+ spawned = []+ monkeypatch.setattr(main_mod.subprocess, "call", lambda argv, cwd=None, env=None: spawned.append(env) or 0)+ with pytest.raises(SystemExit) as exc:+ main_mod._launch_tui()+ assert exc.value.code == 1 and spawned == []+ assert "pass --model explicitly" in capsys.readouterr().err+ with pytest.raises(SystemExit):+ main_mod._launch_tui(model="stub-model")+ assert spawned and spawned[-1][flag] == "1" and spawned[-1]["HERMES_MODEL"] == "stub-model"