The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat: keep declined gateway wizard starts unmanaged
Teknium7500930d9f62
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.pyindex 090f5a7542f..61f66ac16f6 100644--- a/hermes_cli/gateway.py+++ b/hermes_cli/gateway.py@@ -5915,6 +5915,9 @@ def _cmd_install(args):)else:_handle_no_backend("install", wsl=True, s6=True)+ if backend is not None and _is_service_installed():+ from hermes_cli.gateway_setup_service import record_service_choice+ record_service_choice("install")def _cmd_uninstall(args):diff --git a/hermes_cli/gateway_setup_service.py b/hermes_cli/gateway_setup_service.pyindex 7aecbd36222..40ac5a30039 100644--- a/hermes_cli/gateway_setup_service.py+++ b/hermes_cli/gateway_setup_service.py@@ -102,41 +102,47 @@ def ensure_gateway_service(context: str = "setup", *, interactive: bool = False,def _wizard_install_service(backend: str) -> None:- """Fresh install from the wizard: ask start-now / start-on-login, install, then start."""+ """Choose persistence once; start-now without persistence stays unmanaged."""import subprocess- from hermes_cli.gateway import (- is_wsl, prompt_yes_no, _WIZARD_BACKEND_LABELS, print_info,- supports_systemd_services, install_linux_gateway_from_setup,- launchd_install, _gw_windows, _setup_service_action, print_error,- )+ from hermes_cli import gateway as gw+ from hermes_cli._subprocess_compat import windows_detach_popen_kwargs- wsl_note = " (note: services may not survive WSL restarts)" if is_wsl() else ""- start_now = prompt_yes_no(" Start the gateway now?", True)- start_on_login = prompt_yes_no(- f" Start the gateway automatically on login/boot as a {_WIZARD_BACKEND_LABELS[backend]} service?"- f"{wsl_note}",- True,- )- if not (start_now or start_on_login):- print_info(" Skipped start and auto-start setup.")- print_info(" You can install later: hermes gateway install")- if supports_systemd_services():- print_info(" Or as a boot-time service: sudo hermes gateway install --system")- print_info(" Or run in foreground: hermes gateway run")+ if not sys.stdin.isatty():+ return+ start_now = gw.prompt_yes_no(" Start the gateway now?", True)+ if not wants_service_install(interactive=True):+ gw.print_info("Without a service, messaging and scheduled jobs stop at logout/reboot; jobs cannot run while the host is off.")+ if start_now:+ log_dir = gw.get_hermes_home() / "logs"+ log_dir.mkdir(parents=True, exist_ok=True)+ # A setup start is not a request to evict an existing runtime.+ command = [arg for arg in gw._timestamped_stderr_gateway_command(+ log_dir / "gateway.error.log"+ ) if arg != "--replace"]+ try:+ with (log_dir / "gateway.log").open("ab") as output:+ subprocess.Popen(command, stdin=subprocess.DEVNULL, stdout=output,+ stderr=subprocess.DEVNULL, **windows_detach_popen_kwargs())+ gw.print_info("Gateway launch requested without installing a service. Check: hermes gateway status")+ except OSError as exc:+ gw.print_error(f"Gateway launch failed: {exc}")+ else:+ gw.print_info("Run later: hermes gateway run. Install later: hermes gateway install")returntry:- installed_scope, did_install = None, True+ scope, did_install = None, Trueif backend == "systemd":- installed_scope, did_install = install_linux_gateway_from_setup(- force=False, enable_on_startup=start_on_login- )+ scope, did_install = gw.install_linux_gateway_from_setup(force=False, enable_on_startup=True)elif backend == "launchd":- launchd_install(force=False)+ gw.launchd_install(force=False)else:- _gw_windows().install(force=False)- print()- if did_install and start_now:- _setup_service_action("start", failed_label="Start failed", system=installed_scope == "system")- except subprocess.CalledProcessError as e:- print_error(f" Install failed: {e}")- print_info(" You can try manually: hermes gateway install")+ gw._gw_windows().install(force=False, start_now=start_now, start_on_login=True)+ if not did_install or not gw._is_service_installed():+ gw.print_warning("Gateway service install did not complete. Retry: hermes gateway install")+ return+ record_service_choice("install")+ if start_now and backend != "windows":+ gw._setup_service_action("start", failed_label="Start failed", system=scope == "system")+ except (subprocess.CalledProcessError, SystemExit) as exc:+ gw.print_error(f"Install failed: {exc}")+ gw.print_info("You can try manually: hermes gateway install")diff --git a/tests/hermes_cli/test_gateway_service_choice.py b/tests/hermes_cli/test_gateway_service_choice.pyindex 393576ab58f..cf0fcc814a5 100644--- a/tests/hermes_cli/test_gateway_service_choice.py+++ b/tests/hermes_cli/test_gateway_service_choice.py@@ -105,10 +105,13 @@ def test_explicit_setup_consent_is_durable_only_after_success(supervisor, monkey@pytest.mark.linux_only[email protected]("start_now", [False])[email protected]("start_now", [False, True])def test_wizard_declined_service_does_not_install(supervisor, monkeypatch, start_now):profile, calls = supervisorconfig_api.save_config({"gateway": {"service_install_choice": None}})+ stream = io.StringIO()+ stream.isatty = lambda: True+ monkeypatch.setattr(sys, "stdin", stream)answers = iter([start_now, False])monkeypatch.setattr(gateway, "prompt_yes_no", lambda *args: next(answers))monkeypatch.setattr(gateway, "prompt_choice", lambda *args, **kwargs: 0)@@ -126,3 +129,24 @@ def test_wizard_declined_service_does_not_install(supervisor, monkeypatch, startsetup_service._wizard_install_service("systemd")assert not gateway.get_systemd_unit_path().exists()assert bool(spawned) is start_now+ assert config_api.load_config()["gateway"]["service_install_choice"] == "decline"+ if spawned:+ assert "--replace" not in spawned[0][0]++[email protected]_only[email protected]("fail", [False, True])+def test_explicit_install_records_only_completed_install(supervisor, monkeypatch, fail):+ from argparse import Namespace+ import subprocess++ config_api.save_config({"gateway": {"service_install_choice": "decline"}})+ if fail:+ monkeypatch.setenv("CHOICE_FAIL", "1")+ args = Namespace(start_now=False, start_on_login=True)+ if fail:+ with pytest.raises(subprocess.CalledProcessError):+ gateway._cmd_install(args)+ else:+ gateway._cmd_install(args)+ assert config_api.load_config()["gateway"]["service_install_choice"] == ("decline" if fail else "install")