The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(install-state): a root's file linked into a protected folder is never opened
alt-glitchb577935fe923
diff --git a/hermes_cli/install_state.py b/hermes_cli/install_state.pyindex efa2158f0f4..fd3def7ff08 100644--- a/hermes_cli/install_state.py+++ b/hermes_cli/install_state.py@@ -324,7 +324,7 @@ def _launcher_root() -> Iterable[Path]:def root_evidence(root: Path, places: Places) -> Finding | None:if _is_protected(root, places):return Finding(Evidence.UNREADABLE, root)- home = _Root(root)+ home = _Root(root, places.protected)for evidence, check in CHECKS:try:if check(home):@@ -338,18 +338,31 @@ class _Root:"""One root's files, each read at most once. No ``load_config``: it writes SOUL.md and thedirectory skeleton into the root it reads."""- def __init__(self, path: Path) -> None:+ def __init__(self, path: Path, protected: tuple[Path, ...] = ()) -> None:self.path = path+ self.protected = protected++ def file(self, name: str) -> Path:+ """*name* in this root, resolved before anything opens it. A link into a protected folder+ raises: following it would raise the macOS permission prompt, so it counts as unreadable."""+ return _unprotected(self.path / name, self.protected)@cached_propertydef config(self) -> dict[str, Any]:- return _read_mapping(self.path / "config.yaml", _parse_yaml)+ return _read_mapping(self.file("config.yaml"), _parse_yaml)@cached_propertydef auth_stores(self) -> tuple[dict[str, Any], ...]:# The shared-auth override names the directory itself, so its file sits at the top.names = ("auth.json", "shared/nous_auth.json", "nous_auth.json")- return tuple(_read_mapping(self.path / name, json.loads) for name in names)+ return tuple(_read_mapping(self.file(name), json.loads) for name in names)+++def _unprotected(path: Path, protected: tuple[Path, ...]) -> Path:+ resolved = path.resolve()+ if _inside(resolved, protected):+ raise PermissionError(f"{path} leads into a protected folder")+ return resolveddef _onboarding_done(home: _Root) -> bool:@@ -360,11 +373,16 @@ def _onboarding_done(home: _Root) -> bool:def _named_profile(home: _Root) -> bool:from hermes_constants import PROFILE_ID_RE, named_profile_has_identity, named_profile_is_deleted- profiles = home.path / "profiles"- return profiles.is_dir() and any(- 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)- for entry in profiles.iterdir())+ profiles = home.file("profiles")+ if not profiles.is_dir():+ return False+ for entry in profiles.iterdir():+ if entry.name == "default" or not PROFILE_ID_RE.match(entry.name):+ continue+ entry = _unprotected(entry, home.protected)+ if entry.is_dir() and named_profile_has_identity(entry) and not named_profile_is_deleted(entry):+ return True+ return Falsedef _provider_config(home: _Root) -> bool:@@ -383,7 +401,7 @@ def _provider_key(home: _Root) -> bool:from agent.secret_scope import load_env_file- path = home.path / ".env"+ path = home.file(".env")if not path.is_file():return False_read_text(path) # too large or unreadable raises, so doubt counts as used; the tokenizer swallows both@@ -415,7 +433,7 @@ _DB_BUSY_ERRORS = frozenset({"SQLITE_BUSY", "SQLITE_LOCKED"})def _messages(home: _Root) -> bool:- db = home.path / "state.db"+ db = home.file("state.db")if not db.is_file():return False# Read-only URI, never the state registry: that opens a writer and migrates a schema we do not own.diff --git a/tests/hermes_cli/test_install_state.py b/tests/hermes_cli/test_install_state.pyindex cbfd4faa815..cdb71c21079 100644--- a/tests/hermes_cli/test_install_state.py+++ b/tests/hermes_cli/test_install_state.py@@ -98,6 +98,27 @@ def test_a_root_in_a_protected_folder_is_existing_without_being_opened(machine,assert install_state.probe().findings[0].evidence is Evidence.UNREADABLE[email protected]("name", ["config.yaml", ".env", "auth.json", "state.db", "profiles"])+def test_a_file_linked_into_a_protected_folder_is_existing_without_being_opened(machine, tmp_path, monkeypatch, name):+ """A root outside the protected folders whose file links into one: following the link would raise+ the macOS permission prompt, so the target counts as unreadable."""+ other, places = machine+ protected = tmp_path / "Documents"+ target = protected / "hermes" / name+ target.parent.mkdir(parents=True)+ if name == "profiles":+ target.mkdir()+ elif name == "state.db":+ sqlite3.connect(target).execute("CREATE TABLE messages (id INTEGER)").connection.close()+ else:+ target.write_text("{}\n", encoding="utf-8")+ (other / name).symlink_to(target)+ monkeypatch.setattr(install_state, "machine_places",+ lambda: Places(markers=places.markers, sources=places.sources, protected=(protected,)))++ assert [(f.evidence, f.where) for f in install_state.probe().findings] == [(Evidence.UNREADABLE, other.resolve())]++def test_a_launcher_in_a_protected_folder_names_its_folder_without_being_opened(tmp_path, monkeypatch):from types import SimpleNamespace