Skip to content

The agent that grows with you

fix(setup): Codex image post-setup names the auth command instead of starting a device login without a terminal

teknium1f7f000de993f
diff --git a/hermes_cli/subcommands/tools.py b/hermes_cli/subcommands/tools.py
index f83ac9dca73..7baee8c3a4e 100644
--- a/hermes_cli/subcommands/tools.py
+++ b/hermes_cli/subcommands/tools.py
@@ -40,10 +40,10 @@ def build_tools_parser(subparsers, *, cmd_tools: Callable) -> None:
description="Run the install/bootstrap hook a tool backend declares — the\n"
"same step `hermes tools` runs after you pick a provider that\n"
"needs extra dependencies (browser Chromium, Camofox, cua-driver,\n"
- "KittenTTS/Piper, ddgs, Spotify, Langfuse, xAI). Stable,\n"
+ "KittenTTS/Piper, ddgs, Spotify, Langfuse, xAI, Codex). Stable,\n"
"non-interactive target the dashboard spawns to drive backend\n"
"setup. Keys: agent_browser, camofox, cua_driver, kittentts,\n"
- "piper, ddgs, spotify, langfuse, xai_grok.")
+ "piper, ddgs, spotify, langfuse, xai_grok, openai_codex.")
tools_postsetup_p.add_argument(
"post_setup_key", metavar="KEY",
help="Post-setup hook key (e.g. agent_browser, camofox, kittentts)")
diff --git a/hermes_cli/tools_config_post_setup.py b/hermes_cli/tools_config_post_setup.py
index 5304257adb4..089b6622363 100644
--- a/hermes_cli/tools_config_post_setup.py
+++ b/hermes_cli/tools_config_post_setup.py
@@ -360,12 +360,17 @@ def _post_setup_openai_codex() -> None:
_print_info(" OpenAI (Codex auth) needs credentials.")
try:
from hermes_cli.auth import _codex_device_code_login, _save_codex_tokens
- from hermes_cli.setup import prompt_choice
+ from hermes_cli.setup import is_noninteractive, prompt_choice
except Exception as exc:
_print_warning(f" Could not load setup helpers: {exc}")
_info_lines(f"Run later: {relogin}")
return
+ if is_noninteractive():
+ # Dashboard/Desktop spawn this hook with stdin=DEVNULL: nobody can finish a device-code
+ # login here, and the panel already shows the needs_auth pill.
+ _info_lines(f"No terminal to sign in from. Run: {relogin}")
+ return
idx = prompt_choice(
" How do you want to sign in?", default=0,
choices=["Sign in with ChatGPT/Codex OAuth — browser login",
diff --git a/tests/hermes_cli/test_image_gen_picker.py b/tests/hermes_cli/test_image_gen_picker.py
index 67b9019563b..70968d553db 100644
--- a/tests/hermes_cli/test_image_gen_picker.py
+++ b/tests/hermes_cli/test_image_gen_picker.py
@@ -195,6 +195,22 @@ class TestCodexOAuthBootstrapHook:
# Side-tool sign-in must not make Codex the active inference provider.
assert saved == ([] if logged_in else [{"set_active": False}])
+ def test_hook_prints_auth_command_instead_of_device_login_when_noninteractive(self, monkeypatch, capsys):
+ """Desktop's PostSetupRunner spawns `hermes tools post-setup openai_codex` with stdin=DEVNULL and
+ HERMES_NONINTERACTIVE=1: nobody can complete a device-code login there, so the hook must name
+ the real command and return instead of starting one."""
+ from hermes_cli import auth, tools_config_post_setup
+
+ monkeypatch.setenv("HERMES_NONINTERACTIVE", "1")
+ monkeypatch.setattr(auth, "get_codex_auth_status", lambda: {"logged_in": False})
+ monkeypatch.setattr("hermes_cli.setup.prompt_choice", lambda *a, **kw: 0)
+ monkeypatch.setattr(auth, "_codex_device_code_login",
+ lambda: pytest.fail("device-code login must not start without a human"))
+
+ tools_config_post_setup._POST_SETUP_HOOKS["openai_codex"]()
+
+ assert "hermes auth add openai-codex" in capsys.readouterr().out
+
def test_readiness_reports_codex_row_from_auth_store(self, monkeypatch):
from hermes_cli import auth, tools_config