The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(onboarding): the first desktop boot records that onboarding is due and the trial reserved
alt-glitch7580c33d3f9b
diff --git a/hermes_cli/free_tier_bootstrap.py b/hermes_cli/free_tier_bootstrap.pyindex c82e0744594..1caf4ade02c 100644--- a/hermes_cli/free_tier_bootstrap.py+++ b/hermes_cli/free_tier_bootstrap.py@@ -2,8 +2,9 @@``hermes serve`` runs this once at boot on a daemon thread. It never creates an identity: thedesktop's welcome-trial claim (``hermes_cli.welcome_trial``) and the first hosted connector action-are the only creators. On the desktop's local backend it first keeps the trial for a guest that-already ran on the free model (``welcome_trial.grandfather_existing_guest``). Then it inventories+are the only creators. On the desktop's local backend it first records a fresh install's onboarding+decision (``onboarding_run.latch_first_install``), then keeps the trial for a guest that already ran+on the free model (``welcome_trial.grandfather_existing_guest``). Then it inventoriescredentials cheap-first, resolves which provider carries inference, records the answer in processmemory, and tells every connected client with one ``setup.ready`` event. ``free_tier.status`` and``setup.status`` read the record; provider resolution never reaches the portal.@@ -196,6 +197,13 @@ def run_bootstrap(*, announce: bool = True) -> SetupRecord:return _record_started = True+ try:+ from hermes_cli import anon_auth+ from hermes_cli.onboarding_run import latch_first_install+ if anon_auth.on_local_desktop_backend():+ latch_first_install()+ except Exception: # the next boot tries again; onboarding.state still answers live+ logger.warning("onboarding: could not record the first-install decision", exc_info=True)try:from hermes_cli.welcome_trial import grandfather_existing_guestgrandfather_existing_guest()diff --git a/hermes_cli/install_state.py b/hermes_cli/install_state.pyindex 51441c673c0..18303f165ed 100644--- a/hermes_cli/install_state.py+++ b/hermes_cli/install_state.py@@ -105,17 +105,43 @@ def existing_install() -> bool:def mark_machine_used() -> None:- """Record that this machine has a used install, or just claimed the trial. Atomic, idempotent."""+ """Record that this OS user has a used install, or just claimed the trial. Atomic, idempotent.+ Overwrites a reservation (:func:`reserve_trial`): a claim consumes it."""+ _write_marker({})+++_TRIAL_RESERVED = {"trial": "reserved"}+++def reserve_trial() -> None:+ """The first desktop boot found a fresh install: keep the trial for it, so a later use (a chat+ before onboarding ran, a key added) does not take it away. The marker also makes the probe read+ "used" from now on; :func:`trial_reserved` is what the claim checks instead."""+ _write_marker(_TRIAL_RESERVED)+++def trial_reserved() -> bool:+ return any(_read_marker(marker) == _TRIAL_RESERVED for marker in machine_places().markers)+++def _write_marker(content: dict[str, str]) -> None:places = machine_places()if places.markers:from utils import atomic_json_writemarker = places.markers[0]marker.parent.mkdir(parents=True, exist_ok=True)- atomic_json_write(marker, {}) # unique temp name: two backends may mark at once+ atomic_json_write(marker, content) # unique temp name: two backends may mark at onceprobe.cache_clear()+def _read_marker(marker: Path) -> Any:+ try:+ return json.loads(_read_text(marker)) if marker.is_file() else None+ except (OSError, ValueError, UnicodeError):+ return None++# ── where to look ─────────────────────────────────────────────────────────────────────────────diff --git a/hermes_cli/onboarding_run.py b/hermes_cli/onboarding_run.pyindex 67f504f371c..8454c45dcf9 100644--- a/hermes_cli/onboarding_run.py+++ b/hermes_cli/onboarding_run.py@@ -21,16 +21,34 @@ def should_run(*, assume_fresh: bool = False) -> bool:"""The root config's explicit ``onboarding.run`` (managed overlay included) when it is a bool,else whether this machine has never used Hermes (``install_state``; *assume_fresh* is theunpackaged desktop's ``--fresh-install`` switch)."""+ value = _explicit_run()+ if value is not None:+ return value+ from hermes_cli.install_state import probe++ return assume_fresh or probe().fresh+++def _explicit_run() -> bool | None:from hermes_cli.config_effective import load_user_config_effective# Not load_config(): it resolves the launch profile and fills the default None for an unset flag.section = load_user_config_effective(_root_config()).get("onboarding")value = section.get("run") if isinstance(section, dict) else None- if isinstance(value, bool):- return value- from hermes_cli.install_state import probe+ return value if isinstance(value, bool) else None- return assume_fresh or probe().fresh++def latch_first_install() -> bool:+ """The desktop backend's first boot on a fresh install records the decision: ``onboarding.run:+ true`` and the trial reserved. A launch that misses the run (a late answer, the app closed, the+ user chatting first) then stays due until a run ends. True when it wrote them."""+ from hermes_cli.install_state import probe, reserve_trial++ if _explicit_run() is not None or not probe().fresh:+ return False+ set_run(True) # first: a crash before the reservation still leaves a fresh probe for the claim+ reserve_trial()+ return Truedef set_run(value: bool, *, mark_profile_offered: bool = False) -> None:diff --git a/hermes_cli/welcome_trial.py b/hermes_cli/welcome_trial.pyindex 47e5b5ff2ea..f79420ede19 100644--- a/hermes_cli/welcome_trial.py+++ b/hermes_cli/welcome_trial.py@@ -53,9 +53,9 @@ def inference_available(*, assume_fresh: bool = False) -> bool:def _machine_is_used(assume_fresh: bool) -> bool:- from hermes_cli.install_state import probe+ from hermes_cli.install_state import probe, trial_reserved- return not assume_fresh and probe().existing+ return not assume_fresh and probe().existing and not trial_reserved()# Cheapest first; the last one reads the disk. Each is a reason the trial cannot be claimed.diff --git a/tests/hermes_cli/test_welcome_trial.py b/tests/hermes_cli/test_welcome_trial.pyindex 1ea50386cb8..b19bb37947f 100644--- a/tests/hermes_cli/test_welcome_trial.py+++ b/tests/hermes_cli/test_welcome_trial.py@@ -224,3 +224,51 @@ def test_the_token_seam_refuses_an_inference_token_to_a_guest_without_the_trial(anon_auth.refresh_guest_state(state, client, purpose="inference")assert not [r for r in portal.token_requests if r["body"].get("purpose") != "connectors"]+++def _root_run():+ from hermes_cli.config_effective import load_user_config_effective+ from hermes_constants import get_default_hermes_root++ section = load_user_config_effective(get_default_hermes_root() / "config.yaml").get("onboarding") or {}+ return section.get("run")+++def _relaunch():+ from hermes_cli import free_tier_bootstrap++ install_state.probe.cache_clear()+ free_tier_bootstrap.reset_for_tests()+ free_tier_bootstrap.run_bootstrap(announce=False)++[email protected]("used", [False, True], ids=["fresh", "used"])+def test_the_first_desktop_boot_records_that_onboarding_is_due(portal, monkeypatch, used):+ from hermes_cli.onboarding_run import set_run++ as_local_desktop_backend(monkeypatch)+ if used:+ install_state.mark_machine_used()+ _relaunch()+ assert _root_run() is (None if used else True)++ if not used: # once: a run that ended is not made due again by a later boot+ set_run(False)+ _relaunch()+ assert _root_run() is False+++def test_a_missed_first_launch_stays_due_and_keeps_the_trial(portal, monkeypatch):+ from hermes_cli.onboarding_run import should_run+ from hermes_constants import get_hermes_home++ as_local_desktop_backend(monkeypatch)+ _relaunch() # first boot; the app never opened onboarding+ _chat(get_hermes_home() / "state.db", "anthropic/claude") # then the user chatted+ install_state.probe.cache_clear()++ assert install_state.probe().existing+ assert should_run() is True+ assert welcome_trial.claim_blocker() is None+ assert welcome_trial.claim_desktop_free_tier() is not None+ assert welcome_trial.claim_blocker() == "a Nous identity exists"