Skip to content

The agent that grows with you

feat(onboarding): onboarding.run flag in the root config

alt-glitch543de95199e7
diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.py
index a1fd8a0eee0..313f67146e9 100644
--- a/hermes_cli/config_defaults.py
+++ b/hermes_cli/config_defaults.py
@@ -2319,12 +2319,12 @@ DEFAULT_CONFIG = {
# per session, so full-DB backups of small sessions work.
"max_export_messages": 20000,
},
- # First-touch onboarding hints (agent/onboarding.py). Each hint shows once and is latched under
- # `seen`; wipe the section to re-see all hints.
+ # First-touch onboarding hints (agent/onboarding.py), each latched under `seen` once shown.
"onboarding": {
"seen": {},
- # First-ever message: ask = offer; off = plain intro only.
- "profile_build": "ask",
+ "profile_build": "ask", # first-ever message: ask = offer; off = plain intro only
+ # Desktop first run, root profile only (onboarding_run.py): None = fresh install; true = next launch; false = done
+ "run": None,
},
# Privacy-safe aggregate metrics in this profile's local telemetry dir. Collection (`enabled`)
# and transmission to Nous (`send`) are SEPARATE opt-ins; see
diff --git a/hermes_cli/onboarding_run.py b/hermes_cli/onboarding_run.py
new file mode 100644
index 00000000000..fbb842c9b87
--- /dev/null
+++ b/hermes_cli/onboarding_run.py
@@ -0,0 +1,75 @@
+"""``onboarding.run``: whether the desktop first-run questionnaire opens on the next launch.
+
+The flag lives in the ROOT profile's ``config.yaml`` (``get_default_hermes_root()``), never in the
+launch profile's: a pooled backend launched under ``-p work`` must read and write the same file as
+one launched under ``default``, because the questionnaire always targets the default profile.
+Unset means "only on a fresh install"; ``true`` re-runs it once; ``false`` means done.
+"""
+
+from __future__ import annotations
+
+from pathlib import Path
+
+from hermes_constants import (
+ PROFILE_ID_RE,
+ get_default_hermes_root,
+ named_profile_has_identity,
+ named_profile_is_deleted,
+)
+
+# The agentic setup profile's marker file (hermes_cli/profiles.py SETUP_PROFILE_MARKER), spelled out
+# because that constant goes away with the agentic setup while this check must keep skipping the dir.
+_SETUP_PROFILE_MARKER = ".setup-profile.json"
+
+
+def _root_config() -> Path:
+ return get_default_hermes_root() / "config.yaml"
+
+
+def install_has_history(root: Path) -> bool:
+ """A session row in the root ``state.db``, or a named 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 / _SETUP_PROFILE_MARKER).is_file() for path in _named_profiles(root)):
+ return True
+ db_path = root / "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 _named_profiles(root: Path) -> list[Path]:
+ """Live named profiles under *root*, with the same filter as ``profiles._iter_named_profile_dirs``."""
+ profiles = root / "profiles"
+ if not profiles.is_dir():
+ return []
+ return [entry for entry in profiles.iterdir()
+ if entry.is_dir() and entry.name != "default" and PROFILE_ID_RE.match(entry.name)
+ and named_profile_has_identity(entry) and not named_profile_is_deleted(entry)]
+
+
+def should_run() -> bool:
+ """The root file's explicit ``onboarding.run`` when it is a bool, else whether the install is fresh."""
+ from hermes_cli.config import read_user_config_raw
+
+ # Raw read on purpose: load_config() resolves the launch profile and fills the default None.
+ section = read_user_config_raw(_root_config()).get("onboarding")
+ value = section.get("run") if isinstance(section, dict) else None
+ return value if isinstance(value, bool) else not install_has_history(get_default_hermes_root())
+
+
+def set_run(value: bool) -> None:
+ """Persist ``onboarding.run`` in the root ``config.yaml``, keeping every other key and comment."""
+ from hermes_cli.config import atomic_config_write, read_user_config_raw
+
+ path = _root_config()
+ config = read_user_config_raw(path)
+ if not isinstance(config.get("onboarding"), dict):
+ config["onboarding"] = {}
+ config["onboarding"]["run"] = value
+ atomic_config_write(path, config)
diff --git a/hermes_cli/setup_profile.py b/hermes_cli/setup_profile.py
index fe1c1d22824..ea4fb99981d 100644
--- a/hermes_cli/setup_profile.py
+++ b/hermes_cli/setup_profile.py
@@ -10,7 +10,8 @@ from pathlib import Path
from typing import Callable, NamedTuple, Optional
from hermes_cli import profiles as profiles_mod
-from hermes_constants import get_hermes_home, profile_name_for_home
+from hermes_cli.onboarding_run import install_has_history
+from hermes_constants import get_default_hermes_root, get_hermes_home, profile_name_for_home
logger = logging.getLogger(__name__)
@@ -159,7 +160,7 @@ def settle_returning_user() -> None:
"""
if find_setup_profile() is not None or _returning_user_latched():
return
- if _install_has_history():
+ if install_has_history(get_default_hermes_root()):
from agent.onboarding import mark_seen
mark_seen(get_hermes_home() / "config.yaml", RETURNING_USER_FLAG)
@@ -170,24 +171,6 @@ def _returning_user_latched() -> bool:
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:
def change(state: dict) -> dict:
failed = min(state["failed_starts"] + 1, MAX_FAILED_STARTS)
diff --git a/tests/hermes_cli/test_onboarding_run.py b/tests/hermes_cli/test_onboarding_run.py
new file mode 100644
index 00000000000..3467568cd22
--- /dev/null
+++ b/tests/hermes_cli/test_onboarding_run.py
@@ -0,0 +1,102 @@
+"""``onboarding.run`` lives in the root profile's config.yaml: unset runs the questionnaire only on a
+fresh install, an explicit bool wins, and a backend launched under a named profile reads and writes
+the same root file."""
+
+from __future__ import annotations
+
+from pathlib import Path
+
+import pytest
+
+from hermes_cli import onboarding_run, profiles
+from hermes_cli.config import read_user_config_raw
+from hermes_state import SessionDB
+
+
+def root(tmp_path, monkeypatch) -> Path:
+ home = tmp_path / ".hermes"
+ home.mkdir()
+ monkeypatch.setattr(Path, "home", lambda: tmp_path)
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ return home
+
+
+def _add_session(home: Path) -> None:
+ db = SessionDB(home / "state.db")
+ try:
+ db.create_session("old-session", "desktop")
+ finally:
+ db.close()
+
+
+def _launch_under(monkeypatch, root: Path, name: str) -> Path:
+ """A pooled backend launched under ``-p <name>``: HERMES_HOME is the profile's home."""
+ home = profiles.create_profile(name, no_alias=True)
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ assert onboarding_run.get_default_hermes_root() == root
+ return home
+
+
+def test_fresh_install_runs(root):
+ SessionDB(root / "state.db").close() # a boot leaves an empty state.db behind
+
+ assert onboarding_run.should_run() is True
+
+
+def test_root_with_a_session_does_not_run(root):
+ _add_session(root)
+
+ assert onboarding_run.should_run() is False
+
+
+def test_a_user_profile_is_history_but_a_setup_profile_is_not(root):
+ setup = profiles.create_profile("hermes-setup", no_alias=True)
+ (setup / ".setup-profile.json").write_text("{}", encoding="utf-8")
+ assert onboarding_run.should_run() is True
+
+ profiles.create_profile("work", no_alias=True)
+ assert onboarding_run.should_run() is False
+
+
+def test_explicit_true_runs_despite_history(root):
+ _add_session(root)
+ onboarding_run.set_run(True)
+
+ assert onboarding_run.should_run() is True
+
+
+def test_set_run_false_persists_and_keeps_comments(root):
+ (root / "config.yaml").write_text("# my notes\nmodel:\n default: some-model # pinned\n", encoding="utf-8")
+
+ onboarding_run.set_run(False)
+
+ text = (root / "config.yaml").read_text(encoding="utf-8-sig")
+ assert "# my notes" in text and "# pinned" in text
+ assert read_user_config_raw(root / "config.yaml")["model"] == {"default": "some-model"}
+ assert onboarding_run.should_run() is False
+
+
+def test_named_profile_launch_uses_the_root_file(root, monkeypatch):
+ work = _launch_under(monkeypatch, root, "work")
+
+ onboarding_run.set_run(True)
+
+ assert read_user_config_raw(root / "config.yaml")["onboarding"]["run"] is True
+ assert "run" not in (read_user_config_raw(work / "config.yaml").get("onboarding") or {})
+ assert onboarding_run.should_run() is True
+
+ (work / "config.yaml").write_text("onboarding:\n run: true\n", encoding="utf-8")
+ onboarding_run.set_run(False)
+ assert onboarding_run.should_run() is False
+
+
+def test_named_profile_launch_reads_the_root_state_db(root, monkeypatch):
+ # Launched under the setup profile, the one named profile that is not history.
+ setup = _launch_under(monkeypatch, root, "hermes-setup")
+ (setup / ".setup-profile.json").write_text("{}", encoding="utf-8")
+ _add_session(setup)
+ assert onboarding_run.should_run() is True
+
+ _add_session(root)
+ assert onboarding_run.should_run() is False