From f1cdd43b69e84c8840d413a6f3f5a2abf310b8a7 Mon Sep 17 00:00:00 2001 From: Advait Date: Wed, 25 Nov 2026 15:40:41 +0000 Subject: [PATCH] Move a gateway an old ghost ran from ~/.hermes On Linux the old ghost's gateway service ran its engine from ~/.hermes, so an update stopped it without recognising it as ghost's, and it stayed stopped. It's known by ghost's state now, whichever engine it runs. --- bin/ghost-uninstall | 2 +- scripts/fork-engine.sh | 3 ++- tests/test_fork_engine.py | 20 ++++++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/bin/ghost-uninstall b/bin/ghost-uninstall index 0fd731e..3692f07 100644 --- a/bin/ghost-uninstall +++ b/bin/ghost-uninstall @@ -50,7 +50,7 @@ if [ -x "$ENG/.hermes/bin/hermes" ]; then HERMES_HOME="$GHOST_HOME" "$ENG/.hermes/bin/hermes" -p uncensored gateway stop /dev/null 2>&1 UNIT="$HOME/Library/LaunchAgents/ai.hermes.gateway-uncensored.plist" [ -f "$UNIT" ] || UNIT="$HOME/.config/systemd/user/hermes-gateway-uncensored.service" - if [ -f "$UNIT" ] && grep -qF "$ENG/" "$UNIT"; then + if [ -f "$UNIT" ] && grep -qF -e "$ENG/" -e "$GHOST_HOME/" "$UNIT"; then HERMES_HOME="$GHOST_HOME" "$ENG/.hermes/bin/hermes" -p uncensored gateway uninstall /dev/null 2>&1 fi fi diff --git a/scripts/fork-engine.sh b/scripts/fork-engine.sh index 98299a8..803e6c0 100755 --- a/scripts/fork-engine.sh +++ b/scripts/fork-engine.sh @@ -36,7 +36,8 @@ case "$(uname -s)" in *) UNIT="$HOME/.config/systemd/user/hermes-gateway-uncensored.service" service_running() { systemctl --user is-active --quiet hermes-gateway-uncensored.service 2>/dev/null; } ;; esac -service_installed() { [ -f "$UNIT" ] && grep -qF "$ENG/" "$UNIT"; } +# Ours, whichever engine it runs: an old ghost on Linux ran its gateway from ~/.hermes, with ghost's state. +service_installed() { [ -f "$UNIT" ] && grep -qF -e "$ENG/" -e "$GHOST_HOME/" "$UNIT"; } # The engine's package manager must see only its own toolchain: install.sh exports # UV_PROJECT_ENVIRONMENT for ghost's privacy venv, and uv would happily sync the engine into it. diff --git a/tests/test_fork_engine.py b/tests/test_fork_engine.py index 4fa3547..8732841 100644 --- a/tests/test_fork_engine.py +++ b/tests/test_fork_engine.py @@ -84,14 +84,14 @@ def process(self, shape, *args): time.sleep(0.05) return proc - def service(self, running): + def service(self, running, runs=None): if running: (self.home / "gateway-on").touch() rel = ("Library/LaunchAgents/ai.hermes.gateway-uncensored.plist" if platform.system() == "Darwin" else ".config/systemd/user/hermes-gateway-uncensored.service") unit = self.home / rel unit.parent.mkdir(parents=True) - unit.write_text(f"{self.engine}/.hermes/bin/hermes --profile uncensored gateway run") + unit.write_text(runs or f"{self.engine}/.hermes/bin/hermes --profile uncensored gateway run") @pytest.fixture @@ -236,6 +236,22 @@ def test_running_gateway_is_stopped_then_restarted_on_the_new_engine(box): assert not box.restart.exists() +def test_a_gateway_an_old_ghost_ran_from_elsewhere_is_moved_too(box): + """On Linux it ran from ~/.hermes/hermes-agent, with ghost's state. Left alone it stayed stopped.""" + assert box.run(src=box.source("one")).returncode == 0 + box.service(running=True, runs=f"HERMES_HOME={box.state}/profiles/uncensored\n{box.home}/.hermes/hermes-agent/venv/bin/python -m hermes_cli.main") + assert box.run(src=box.source("two")).returncode == 0 and box.restart.exists() + assert box.run("--refresh-gateway").returncode == 0 + assert box.calls()[-1] == "-p uncensored gateway install --force --start-now --start-on-login" + + +def test_someone_elses_gateway_is_not_touched(box): + assert box.run(src=box.source("one")).returncode == 0 + box.service(running=True, runs=f"HERMES_HOME={box.home}/.hermes/profiles/uncensored\n{box.home}/.hermes/hermes-agent/venv/bin/python") + assert box.run(src=box.source("two")).returncode == 0 and not box.restart.exists() + assert box.run("--refresh-gateway").returncode == 0 and not [c for c in box.calls() if "gateway install" in c] + + def test_gateway_is_started_again_when_the_build_fails(box): assert box.run(src=box.source("one")).returncode == 0 box.service(running=True)