The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): doctor and terminal setup resolve the container runtime too
kshitijk4poore4739c6d2d69
diff --git a/hermes_cli/doctor_tools.py b/hermes_cli/doctor_tools.pyindex 0bba3cf52d3..661fb8bf003 100644--- a/hermes_cli/doctor_tools.py+++ b/hermes_cli/doctor_tools.py@@ -12,6 +12,7 @@ from hermes_cli.doctor_platform import _system_package_install_cmdfrom hermes_cli.doctor_report import Finding, _fail_and_issue, check_bool, check_info, check_ok, check_warn, doctor_checkfrom hermes_cli.vercel_auth import describe_vercel_authfrom hermes_constants import agent_browser_runnable, is_termux as _is_termux+from tools.environments.docker import docker_runtime_name, docker_runtime_start_hint, find_dockerdef _safe_which(cmd: str) -> str | None:@@ -146,23 +147,29 @@ _BUILTIN_TERMINAL_BACKENDS = {"local", "docker", "singularity", "modal", "managedef _check_docker_backend(terminal_env: str, running_in_container: bool, issues: list[str]) -> None:+ docker_exe = find_docker()if terminal_env == "docker":- if not _safe_which("docker"):- _fail_and_issue("Docker not installed", "(needed for the 'docker' terminal backend)",- "Install Docker, or run `hermes setup terminal` to switch backend.", issues)+ if not docker_exe:+ _fail_and_issue("Docker or Podman not installed", "(needed for the 'docker' terminal backend)",+ "Install Docker or Podman, or run `hermes setup terminal` to switch backend.", issues)else:- # `docker version` hits /version, which socket proxies (tecnativa) allow by default; `docker info`+ runtime = docker_runtime_name(docker_exe)+ hint = docker_runtime_start_hint(docker_exe)+ unreachable = (+ f"{runtime} daemon not running" if runtime == "Docker" else f"{runtime} not reachable")+ # `<cli> version` hits /version, which socket proxies (tecnativa) allow by default; `docker info`# needs /info and is commonly blocked, giving a false "daemon not running". The backend itself- # probes with `docker version` too (environments/docker.py).- _require(_run_ok(["docker", "version"], timeout=10), ("docker", "(daemon running)"),- ("Docker daemon not running", "(needed for the 'docker' terminal backend)"),- "Start Docker, or run `hermes setup terminal` to switch backend.", issues)- elif _safe_which("docker"):- check_ok("docker", "(optional)")+ # probes with `<cli> version` too (environments/docker.py).+ _require(_run_ok([docker_exe, "version"], timeout=10),+ (runtime, "(daemon running)" if runtime == "Docker" else "(reachable)"),+ (unreachable, "(needed for the 'docker' terminal backend)"),+ f"{hint[0].upper()}{hint[1:]}, or run `hermes setup terminal` to switch backend.", issues)+ elif docker_exe:+ check_ok(docker_runtime_name(docker_exe), "(optional)")elif _is_termux():check_info("Docker backend is not available inside Termux (expected on Android)")elif not running_in_container: # in-container case already explained by the caller- check_warn("docker not found", "(optional)")+ check_warn("Docker/Podman not found", "(optional)")def _check_ssh_backend(issues: list[str]) -> None:@@ -251,7 +258,7 @@ def _check_terminal_backend(should_fix: bool, f: Finding) -> None:running_in_container = _is_container()except Exception:running_in_container = False- # In our container docker-in-docker isn't set up, so local is intended: skip the noisy "docker not found"+ # In our container docker-in-docker isn't set up, so local is intended: skip the noisy "Docker/Podman not found"# warning. An explicit TERMINAL_ENV=docker (mounted docker.sock) still gets checked.if running_in_container and terminal_env != "docker":check_info("Running inside a container — using local terminal backend (docker-in-docker is not configured by default)")diff --git a/hermes_cli/setup_terminal.py b/hermes_cli/setup_terminal.pyindex dceba1abf58..5453c5419fb 100644--- a/hermes_cli/setup_terminal.py+++ b/hermes_cli/setup_terminal.py@@ -9,6 +9,7 @@ import shutilimport sysfrom pathlib import Pathfrom tools import tool_backend_helpers+from tools.environments.docker import docker_runtime_name, find_dockerfrom hermes_cli import nous_subscriptionlogger = logging.getLogger("hermes_cli.setup")@@ -144,9 +145,12 @@ def _setup_backend_local(config: dict) -> None:def _setup_backend_docker(config: dict) -> None:- _setup.print_success("Terminal backend: Docker")- _report_binary(shutil.which("docker"), "Docker not found in PATH!",- "Install Docker: https://docs.docker.com/get-docker/", "Docker found: ")+ _setup.print_success("Terminal backend: Docker / Podman")+ docker_exe = find_docker()+ _report_binary(docker_exe, "Docker or Podman not found in PATH!",+ "Install Docker: https://docs.docker.com/get-docker/ "+ "or Podman: https://podman.io/docs/installation",+ f"{docker_runtime_name(docker_exe)} found: " if docker_exe else "")# Image and resource limits use defaults; tune via `hermes setup terminal`.config["terminal"].setdefault("docker_image", _SANDBOX_IMAGE)_setup._info(None, "Docker sandboxes can be protected with the egress credential firewall.",@@ -275,7 +279,7 @@ def _setup_backend_plugin(config: dict, backend: str) -> None:_BUILTIN_TERMINAL_BACKENDS = [("local", "Local - run directly on this machine (default)"),- ("docker", "Docker - isolated container with configurable resources"),+ ("docker", "Docker/Podman - isolated container with configurable resources"),("modal", "Modal - serverless cloud sandbox"), ("ssh", "SSH - run on a remote machine"),("daytona", "Daytona - persistent cloud development environment"),("vercel_sandbox", "Vercel Sandbox - cloud microVM with snapshot filesystem persistence")]diff --git a/hermes_cli/web_routers/tools.py b/hermes_cli/web_routers/tools.pyindex eeb88d2bacd..c3aff0f0af3 100644--- a/hermes_cli/web_routers/tools.py+++ b/hermes_cli/web_routers/tools.py@@ -6,7 +6,6 @@ monkeypatching on web_server stays authoritative."""import asyncio-import osimport shutilimport subprocessimport sys@@ -55,11 +54,6 @@ def _terminal_backend_rows() -> List[Dict[str, str]]:return [*_TERMINAL_BACKENDS, *_plugin_terminal_backend_rows()]-def _docker_runtime_label(executable: str) -> str:- """User-facing name for the resolved docker/podman CLI."""- return "Podman" if "podman" in os.path.basename(executable).lower() else "Docker"--def _probe_docker_backend(_cfg) -> tuple:"""Health-check the docker terminal backend the same way the agent resolves it.@@ -68,7 +62,8 @@ def _probe_docker_backend(_cfg) -> tuple:because Podman has no ServerVersion field and the agent already probes with``version``."""- from tools.environments.docker import find_docker+ from tools.environments.docker import docker_runtime_name, docker_runtime_start_hint, find_docker+ from tools.environments.remote_common import run_capturedocker_exe = find_docker()if not docker_exe:@@ -76,17 +71,13 @@ def _probe_docker_backend(_cfg) -> tuple:"needs_setup","Docker CLI not found — install Docker Desktop, docker-ce, or Podman.",)- runtime = _docker_runtime_label(docker_exe)+ runtime = docker_runtime_name(docker_exe)try:- proc = subprocess.run(- [docker_exe, "version"],- capture_output=True, text=True, encoding="utf-8", errors="replace",- timeout=2, stdin=subprocess.DEVNULL)- if proc.returncode == 0:+ if run_capture([docker_exe, "version"], timeout=2).returncode == 0:return ("ready", "")- return ("needs_setup", f"{runtime} daemon not reachable — start {runtime} and retry.")+ return ("needs_setup", f"{runtime} not reachable — {docker_runtime_start_hint(docker_exe)}.")except subprocess.TimeoutExpired:- return ("needs_setup", f"{runtime} daemon not responding (timed out).")+ return ("needs_setup", f"{runtime} not responding (timed out).")except Exception as exc:return ("unavailable", f"{runtime} probe failed: {exc}")diff --git a/tests/hermes_cli/test_doctor.py b/tests/hermes_cli/test_doctor.pyindex 131fc7e04f2..eceddebdf5a 100644--- a/tests/hermes_cli/test_doctor.py+++ b/tests/hermes_cli/test_doctor.py@@ -426,6 +426,11 @@ def test_run_doctor_termux_treats_docker_and_browser_warnings_as_expected(monkeyreturn real_which(cmd)monkeypatch.setattr(shutil, "which", fake_which)+ # The docker check resolves through find_docker() (which also knows the macOS Docker+ # Desktop paths), so pin it off the host instead of relying on PATH alone.+ from hermes_cli import doctor_tools++ monkeypatch.setattr(doctor_tools, "find_docker", lambda: None)out = helper._run_doctor_and_capture(monkeypatch, tmp_path, provider="")@@ -1793,10 +1798,10 @@ def test_docker_daemon_probe_uses_version_not_info(monkeypatch):from hermes_cli import doctor_toolscalls: list = []- monkeypatch.setattr(doctor_tools, "_safe_which", lambda name: "/usr/bin/docker")+ monkeypatch.setattr(doctor_tools, "find_docker", lambda: "/usr/bin/docker")monkeypatch.setattr(doctor_tools, "_run_ok", lambda cmd, timeout, **kw: calls.append(cmd) or True)monkeypatch.setattr(doctor_tools, "_require", lambda *a, **k: None)doctor_tools._check_docker_backend("docker", False, [])- assert calls and calls[0][:2] == ["docker", "version"]+ assert calls == [["/usr/bin/docker", "version"]]diff --git a/tests/hermes_cli/test_doctor_terminal_backends.py b/tests/hermes_cli/test_doctor_terminal_backends.pyindex 7cb83026fe2..27414a39225 100644--- a/tests/hermes_cli/test_doctor_terminal_backends.py+++ b/tests/hermes_cli/test_doctor_terminal_backends.py@@ -16,16 +16,16 @@ def _joined(capsys) -> str:def test_docker_missing_line_names_backend_and_setup_command(monkeypatch, capsys, issues):- monkeypatch.setattr(doctor_tools, "_safe_which", lambda name: None)+ monkeypatch.setattr(doctor_tools, "find_docker", lambda: None)doctor_tools._check_docker_backend("docker", False, issues)out = _joined(capsys)- assert "Docker not installed" in out and "'docker' terminal backend" in out+ assert "Docker or Podman not installed" in out and "'docker' terminal backend" in outassert "TERMINAL_ENV" not in out- assert issues and "hermes setup terminal" in issues[0] and "Install Docker" in issues[0]+ assert issues and "hermes setup terminal" in issues[0] and "Install Docker or Podman" in issues[0]def test_docker_daemon_down_line_says_start_docker_or_switch(monkeypatch, capsys, issues):- monkeypatch.setattr(doctor_tools, "_safe_which", lambda name: "/usr/bin/docker")+ monkeypatch.setattr(doctor_tools, "find_docker", lambda: "/usr/bin/docker")monkeypatch.setattr(doctor_tools, "_run_ok", lambda cmd, timeout, **kw: False)doctor_tools._check_docker_backend("docker", False, issues)out = _joined(capsys)@@ -33,6 +33,29 @@ def test_docker_daemon_down_line_says_start_docker_or_switch(monkeypatch, capsysassert issues and "Start Docker" in issues[0] and "hermes setup terminal" in issues[0]+def test_docker_backend_ready_when_only_podman_resolves(monkeypatch, capsys, issues):+ """A podman-only machine runs the 'docker' backend, so doctor reports Podman as ready."""+ monkeypatch.setattr(doctor_tools, "find_docker", lambda: "/usr/bin/podman")+ probed: list[list[str]] = []+ monkeypatch.setattr(doctor_tools, "_run_ok", lambda cmd, timeout, **kw: probed.append(cmd) or True)+ doctor_tools._check_docker_backend("docker", False, issues)+ out = _joined(capsys)+ assert "Podman (reachable)" in out+ assert not issues+ assert probed == [["/usr/bin/podman", "version"]]+++def test_podman_down_line_advises_the_machine_not_a_daemon(monkeypatch, capsys, issues):+ """Podman is daemonless: the fix is `podman machine start`, never "start a daemon"."""+ monkeypatch.setattr(doctor_tools, "find_docker", lambda: "/opt/homebrew/bin/podman")+ monkeypatch.setattr(doctor_tools, "_run_ok", lambda cmd, timeout, **kw: False)+ doctor_tools._check_docker_backend("docker", False, issues)++ out = _joined(capsys)+ assert "Podman not reachable" in out+ assert issues and "podman machine start" in issues[0] and "hermes setup terminal" in issues[0]++def test_ssh_host_missing_line_points_at_setup_terminal(monkeypatch, capsys, issues):monkeypatch.delenv("TERMINAL_SSH_HOST", raising=False)doctor_tools._check_ssh_backend(issues)diff --git a/tests/hermes_cli/test_setup_terminal.py b/tests/hermes_cli/test_setup_terminal.pyindex 8623c27dbad..df00de480c8 100644--- a/tests/hermes_cli/test_setup_terminal.py+++ b/tests/hermes_cli/test_setup_terminal.py@@ -34,3 +34,15 @@ def test_ssh_port_non_default_still_saves(ssh_wizard):# Control: the deliberate skip is only for the default; a real port persists.ssh_wizard(["host.example.com", "me", "2222", "/tmp/key"])assert get_env_value("TERMINAL_SSH_PORT") == "2222"+++def test_docker_wizard_reports_the_resolved_podman_runtime(monkeypatch, capsys):+ """Podman satisfies the docker backend, so the wizard must name it instead of warning."""+ monkeypatch.setattr(setup_terminal, "find_docker", lambda: "/usr/bin/podman")+ monkeypatch.setattr(setup_mod, "prompt_yes_no", lambda label, default=True: False)++ setup_terminal._setup_backend_docker({"terminal": {}})++ out = capsys.readouterr().out+ assert "Podman found: /usr/bin/podman" in out+ assert "not found in PATH" not in outdiff --git a/tests/hermes_cli/test_terminal_backend_docker_probe.py b/tests/hermes_cli/test_terminal_backend_docker_probe.pyindex 3440708e226..4145c084a10 100644--- a/tests/hermes_cli/test_terminal_backend_docker_probe.py+++ b/tests/hermes_cli/test_terminal_backend_docker_probe.py@@ -14,6 +14,7 @@ import pytestfrom hermes_cli.web_routers import tools as tools_modfrom tools.environments import docker as docker_mod+from tools.environments import remote_common@pytest.fixture(autouse=True)@@ -45,7 +46,7 @@ def test_probe_ready_when_only_podman_is_configured(tmp_path, monkeypatch):captured.append(list(argv))return subprocess.CompletedProcess(argv, 0, stdout="podman version 5.0.0\n", stderr="")- monkeypatch.setattr(tools_mod.subprocess, "run", _run)+ monkeypatch.setattr(remote_common, "run_capture", _run)status, detail = tools_mod._probe_docker_backend({})assert status == "ready"diff --git a/tests/tools/test_docker_find.py b/tests/tools/test_docker_find.pyindex 72ae68ca858..efef0161732 100644--- a/tests/tools/test_docker_find.py+++ b/tests/tools/test_docker_find.py@@ -46,3 +46,19 @@ class TestFindDocker:with patch("tools.environments.docker.shutil.which", side_effect=which_side_effect):result = docker_mod.find_docker()assert result == "/usr/bin/docker"+++class TestRuntimeName:+ """The Docker/Podman wording every surface shows must follow the resolved CLI."""++ @pytest.mark.parametrize(+ ("executable", "runtime", "hint"),+ [+ ("/usr/bin/docker", "Docker", "start Docker and retry"),+ ("/opt/homebrew/bin/podman", "Podman", "run `podman machine start` and retry"),+ ("/usr/bin/podman-remote", "Podman", "run `podman machine start` and retry"),+ ],+ )+ def test_runtime_and_start_hint(self, executable, runtime, hint):+ assert docker_mod.docker_runtime_name(executable) == runtime+ assert docker_mod.docker_runtime_start_hint(executable) == hintdiff --git a/tools/environments/docker.py b/tools/environments/docker.pyindex 69417c5908e..45e9524c5c7 100644--- a/tools/environments/docker.py+++ b/tools/environments/docker.py@@ -228,6 +228,20 @@ def find_docker() -> Optional[str]:return found+def docker_runtime_name(executable: str) -> str:+ """User-facing runtime name (``"Podman"`` / ``"Docker"``) for the CLI at *executable*, so+ diagnostics and pickers name the runtime actually in use."""+ return "Podman" if "podman" in os.path.basename(executable).lower() else "Docker"+++def docker_runtime_start_hint(executable: str) -> str:+ """How to bring the runtime at *executable* back up, for a "not reachable" message. Docker has+ a daemon to start; Podman is daemonless (outside Linux it runs inside a VM)."""+ if docker_runtime_name(executable) != "Podman":+ return "start Docker and retry"+ return "run `podman machine start` and retry"++# Security flags applied to every container. The container is the security# boundary; all caps are dropped and the minimum added back:# DAC_OVERRIDE - root can write to bind-mounted dirs owned by the host user