Skip to content

The agent that grows with you

fix(onboarding): a returning user skips the first-run guide

ethernet9d371a96bedf
diff --git a/hermes_cli/setup_profile.py b/hermes_cli/setup_profile.py
index 4070e92c14c..ccd5af21c84 100644
--- a/hermes_cli/setup_profile.py
+++ b/hermes_cli/setup_profile.py
@@ -18,6 +18,7 @@ SETUP_PROFILE_NAME = "hermes-setup"
SETUP_PROFILE_DESCRIPTION = "Where Hermes met you — walks your first run, then checks in as you find your feet."
SETUP_CHAT_TITLE = "Welcome to Hermes"
MAX_FAILED_STARTS = 3
+RETURNING_USER_FLAG = "setup_intro" # config.yaml onboarding.seen.<flag>, see settle_returning_user
_FRESH_STATE = {"intro": "unseen", "failed_starts": 0}
_CARDS_DIR = "setup-cards"
_SETUP_TOOLSETS = ["setup", "start_chat", "connections", "no_mcp"]
@@ -123,7 +124,47 @@ def onboarding_eligible() -> bool:
def read_state() -> dict:
found = find_setup_profile()
- return dict(_FRESH_STATE) if found is None else _read_state(found[1])
+ if found is not None:
+ return _read_state(found[1])
+ return {**_FRESH_STATE, "intro": "seen"} if _returning_user_latched() else dict(_FRESH_STATE)
+
+
+def settle_returning_user() -> None:
+ """Latch the intro as seen for an install that was used before the first-run guide existed.
+
+ Only a first launch (no setup profile yet) can be a returning user; once the guide has started
+ its own marker is the authority. The latch is separate from the marker so an install that never
+ gets a setup profile still reads as ``seen`` on every later boot.
+ """
+ if find_setup_profile() is not None or _returning_user_latched():
+ return
+ if _install_has_history():
+ from agent.onboarding import mark_seen
+ mark_seen(get_hermes_home() / "config.yaml", RETURNING_USER_FLAG)
+
+
+def _returning_user_latched() -> bool:
+ from agent.onboarding import is_seen
+ from hermes_cli.config import read_user_config_raw
+ return is_seen(read_user_config_raw(get_hermes_home() / "config.yaml"), RETURNING_USER_FLAG)
+
+
+def _install_has_history() -> bool:
+ """A session row in the launch home, or a profile the user made. A fresh boot creates neither:
+ it leaves an empty ``state.db``, ``auth.json`` (the free-tier mint) and ``SOUL.md``, which is
+ why the signal is a session row and not a file."""
+ if any(not (path / profiles_mod.SETUP_PROFILE_MARKER).is_file()
+ for path in profiles_mod._iter_named_profile_dirs()):
+ return True
+ db_path = get_hermes_home() / "state.db"
+ if not db_path.is_file():
+ return False
+ from hermes_state_registry import acquire, release_or_close
+ db = acquire(db_path)
+ try:
+ return db.session_count_ge(1)
+ finally:
+ release_or_close(db)
def record_failed_start() -> dict:
diff --git a/tests/hermes_cli/test_setup_profile_returning_user.py b/tests/hermes_cli/test_setup_profile_returning_user.py
new file mode 100644
index 00000000000..3385c053352
--- /dev/null
+++ b/tests/hermes_cli/test_setup_profile_returning_user.py
@@ -0,0 +1,80 @@
+"""A user who has already used Hermes must not get the first-run guide when the guest flag turns on.
+
+``onboarding.state`` reports ``intro: unseen`` for any install without a setup profile, so a returning
+user looked brand new. ``settle_returning_user`` latches ``seen`` on first launch from real history.
+"""
+
+from pathlib import Path
+
+import pytest
+
+from hermes_cli import setup_profile
+from hermes_cli.config import read_user_config_raw
+from hermes_state import SessionDB
+
+
+def home(tmp_path, monkeypatch) -> Path:
+ root = tmp_path / ".hermes"
+ root.mkdir()
+ monkeypatch.setattr(Path, "home", lambda: tmp_path)
+ monkeypatch.setenv("HERMES_HOME", str(root))
+ return root
+
+
+def _add_session(home: Path) -> None:
+ db = SessionDB(home / "state.db")
+ try:
+ db.create_session("old-session", "desktop")
+ finally:
+ db.close()
+
+
+def _settled_intro() -> str:
+ setup_profile.settle_returning_user()
+ return setup_profile.read_state()["intro"]
+
+
+def test_fresh_install_stays_unseen(home):
+ assert _settled_intro() == "unseen"
+ assert "onboarding" not in read_user_config_raw(home / "config.yaml")
+
+
+def test_empty_state_db_from_a_boot_stays_unseen(home):
+ SessionDB(home / "state.db").close()
+ (home / "SOUL.md").write_text("default soul")
+
+ assert _settled_intro() == "unseen"
+
+
+def test_install_with_a_session_is_latched_seen(home):
+ _add_session(home)
+
+ assert _settled_intro() == "seen"
+ assert read_user_config_raw(home / "config.yaml")["onboarding"]["seen"][setup_profile.RETURNING_USER_FLAG] is True
+
+
+def test_latch_survives_the_history_going_away(home):
+ _add_session(home)
+ assert _settled_intro() == "seen"
+
+ (home / "state.db").unlink()
+
+ assert _settled_intro() == "seen"
+
+
+def test_install_with_a_user_profile_is_latched_seen(home):
+ from hermes_cli import profiles
+
+ profiles.create_profile("work", no_alias=True)
+
+ assert _settled_intro() == "seen"
+
+
+def test_a_user_mid_guide_is_left_to_the_setup_profile_marker(home):
+ setup_profile.ensure_setup_profile()
+ _add_session(home)
+
+ assert _settled_intro() == "unseen"
+ setup_profile.mark_intro_seen()
+ assert setup_profile.read_state()["intro"] == "seen"
diff --git a/tui_gateway/methods_onboarding.py b/tui_gateway/methods_onboarding.py
index 169aedf95f8..22ec1dbdfd0 100644
--- a/tui_gateway/methods_onboarding.py
+++ b/tui_gateway/methods_onboarding.py
@@ -50,8 +50,12 @@ def _(rid, params: dict) -> dict:
@method("onboarding.state")
def _(rid, params: dict) -> dict:
- from hermes_cli.setup_profile import read_state
- return _onboarding_state_result(rid, read_state)
+ from hermes_cli.setup_profile import read_state, settle_returning_user
+
+ def settle_then_read() -> dict:
+ settle_returning_user()
+ return read_state()
+ return _onboarding_state_result(rid, settle_then_read)
@method("onboarding.record_failed_start")