feat(nix): container-aware CLI — auto-route hermes chat into managed container - #7470
feat(nix): container-aware CLI — auto-route hermes chat into managed container#7470alt-glitch wants to merge 1 commit into
hermes chat into managed container#7470Conversation
…container When container.enable = true in the NixOS module, running 'hermes chat' on the host now automatically execs into the managed container via docker/podman exec. This means the interactive CLI runs in the same environment as the gateway service, with access to all container-installed packages and tools. Implementation: - NixOS activation script writes .container-mode metadata file to HERMES_HOME with backend, container_name, and hermes_bin path - File is removed when container mode is disabled (nixos-rebuild switch) - hermes_cli/config.py: _is_inside_container() detects Docker/Podman indicators (/.dockerenv, /run/.containerenv, cgroup) - hermes_cli/config.py: get_container_exec_info() reads .container-mode metadata, returns None when already inside a container - hermes_cli/main.py: _exec_in_container() validates the container is running, then os.execvp() replaces the process with the container exec - cmd_chat intercepts before normal flow, checks container info, execs Safety: - --host flag bypasses container routing (run on host regardless) - Falls back to host CLI if: container runtime not found, container not running, inspect fails, or any detection error - Strips --host from forwarded args (not meaningful inside container) - Already-inside-container detection prevents infinite exec loops Closes #7380
|
@BugBot review |
PR SummaryMedium Risk Overview Adds host-side container detection to prevent infinite re-exec, validates runtime availability and container running state with graceful fallback to host execution, and introduces Reviewed by Cursor Bugbot for commit 611b89c. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 611b89c. Configure here.
| _exec_in_container(container_info, sys.argv[1:]) | ||
| # _exec_in_container calls os.execvp which replaces the process. | ||
| # If we get here, the exec failed. | ||
| sys.exit(1) |
There was a problem hiding this comment.
Fallback to host CLI broken by unconditional sys.exit(1)
High Severity
_exec_in_container returns normally in all fallback scenarios (runtime not found, container not running, inspect timeout), but cmd_chat unconditionally calls sys.exit(1) after it returns. This means the graceful "fall back to host CLI" behavior never actually works — the process just exits with an error. The warning messages even say "falling back to host CLI" but the host CLI path is never reached. Only when os.execvp raises an exception does the except Exception: pass block allow fallthrough.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 611b89c. Configure here.
|
Superseded by #7543 (clean rebase on main with subprocess.run fix and Podman sudo support). |


Summary
When
container.enable = truein the NixOS module, runninghermes chaton the host now automatically execs into the managed container viadocker/podman exec. The interactive CLI runs in the same environment as the gateway service — with access to all container-installed packages and tools.Previously, users had to manually run:
Now they just run:
How it works
NixOS activation script writes a
.container-modemetadata file toHERMES_HOMEcontainingbackend,container_name, andhermes_bin. File is removed when container mode is disabled.Host CLI detection (
hermes_cli/config.py):_is_inside_container()— detects/.dockerenv,/run/.containerenv, and cgroup markers to prevent infinite exec loopsget_container_exec_info()— reads.container-mode, returnsNoneif already inside a container or file doesn't existContainer exec (
hermes_cli/main.py):_exec_in_container()validates the container runtime exists and is running, thenos.execvp()replaces the processcmd_chatintercepts before normal flow to check for container routingSafety & fallback
--hostflag bypasses container routing--hostis stripped from forwarded args (not meaningful inside container)Files changed
hermes_cli/config.py_is_inside_container(),get_container_exec_info()hermes_cli/main.py_exec_in_container(),--hostflag,cmd_chatinterceptnix/nixosModules.nix.container-modein activation scripttests/hermes_cli/test_container_aware_cli.pywebsite/docs/getting-started/nix-setup.mdTest plan
container.enable = true+addToSystemPackages = true--hostbypasses container routingCloses #7380