The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(doctor): honor disabled built-in memory stores
fangliquanflq21cebbfd6887
diff --git a/hermes_cli/doctor.py b/hermes_cli/doctor.pyindex 1af14d38820..3a3b45062b5 100644--- a/hermes_cli/doctor.py+++ b/hermes_cli/doctor.py@@ -405,6 +405,28 @@ def check_info(text: str):print(f" {color('→', Colors.CYAN)} {text}")+def _doctor_memory_config(hermes_home: Path | None = None) -> dict:+ """Return the effective memory section used by doctor diagnostics."""+ home = hermes_home if hermes_home is not None else HERMES_HOME+ try:+ from hermes_cli.config import _expand_env_vars, read_user_config_raw++ config_path = home / "config.yaml"+ if not config_path.exists():+ return {}+ config = _expand_env_vars(read_user_config_raw(config_path))+ try:+ from hermes_cli import managed_scope++ config = managed_scope.apply_managed_overlay(config)+ except Exception:+ pass+ section = config.get("memory") if isinstance(config, dict) else None+ return section if isinstance(section, dict) else {}+ except Exception:+ return {}++# ── state.db health/stats thresholds (advisory only — module constants,# deliberately NOT config: doctor warnings are guidance, not policy) ──STATE_DB_SIZE_WARN_BYTES = 1 * 1024 * 1024 * 1024 # 1 GiB logical size@@ -1980,8 +2002,19 @@ def run_doctor(args):else:check_warn(f"{_DHH} not found", "(will be created on first use)")- # Check expected subdirectories- expected_subdirs = ["cron", "sessions", "logs", "skills", "memories"]+ from tools.memory_tool import get_builtin_memory_store_flags++ _memory_config = _doctor_memory_config(hermes_home)+ _memory_enabled, _user_profile_enabled = get_builtin_memory_store_flags(+ {"memory": _memory_config}+ )++ # Check expected subdirectories. The built-in file store does not create or+ # consume memories/ when both targets are disabled, so stale migration files+ # are not an active diagnostic surface.+ expected_subdirs = ["cron", "sessions", "logs", "skills"]+ if _memory_enabled or _user_profile_enabled:+ expected_subdirs.append("memories")for subdir_name in expected_subdirs:subdir_path = hermes_home / subdir_nameif subdir_path.exists():@@ -2016,22 +2049,28 @@ def run_doctor(args):check_ok(f"Created {_DHH}/SOUL.md with basic template")fixed_count += 1- # Check memory directory+ # Check only enabled built-in stores. External providers are additive, but+ # users can explicitly disable either legacy file target; stale files left+ # by a migration must not be presented as active memory usage.memories_dir = hermes_home / "memories"- if memories_dir.exists():+ if not (_memory_enabled or _user_profile_enabled):+ check_info("Built-in memory files disabled by config")+ elif memories_dir.exists():check_ok(f"{_DHH}/memories/ directory exists")memory_file = memories_dir / "MEMORY.md"user_file = memories_dir / "USER.md"- if memory_file.exists():- size = len(memory_file.read_text(encoding="utf-8").strip())- check_ok(f"MEMORY.md exists ({size} chars)")- else:- check_info("MEMORY.md not created yet (will be created when the agent first writes a memory)")- if user_file.exists():- size = len(user_file.read_text(encoding="utf-8").strip())- check_ok(f"USER.md exists ({size} chars)")- else:- check_info("USER.md not created yet (will be created when the agent first writes a memory)")+ if _memory_enabled:+ if memory_file.exists():+ size = len(memory_file.read_text(encoding="utf-8").strip())+ check_ok(f"MEMORY.md exists ({size} chars)")+ else:+ check_info("MEMORY.md not created yet (will be created when the agent first writes a memory)")+ if _user_profile_enabled:+ if user_file.exists():+ size = len(user_file.read_text(encoding="utf-8").strip())+ check_ok(f"USER.md exists ({size} chars)")+ else:+ check_info("USER.md not created yet (will be created when the agent first writes a memory)")else:check_warn(f"{_DHH}/memories/ not found", "(will be created on first use)")if should_fix:@@ -3243,21 +3282,7 @@ def run_doctor(args):check_warn("No GITHUB_TOKEN", f"(60 req/hr rate limit — set in {_DHH}/.env for better rates)")_section("Memory Provider")- _active_memory_provider = ""- try:- from hermes_cli.config import read_user_config_raw as _read_raw_mem- _mem_cfg_path = HERMES_HOME / "config.yaml"- if _mem_cfg_path.exists():- # Raw-file diagnostic (+ managed overlay below, unchanged).- _raw_cfg = _read_raw_mem(_mem_cfg_path)- try:- from hermes_cli import managed_scope- _raw_cfg = managed_scope.apply_managed_overlay(_raw_cfg)- except Exception:- pass- _active_memory_provider = (_raw_cfg.get("memory") or {}).get("provider", "")- except Exception:- pass+ _active_memory_provider = _doctor_memory_config().get("provider", "")if not _active_memory_provider:check_ok("Built-in memory active", "(no external provider configured — this is fine)")diff --git a/tests/hermes_cli/test_doctor.py b/tests/hermes_cli/test_doctor.pyindex 9e37dc2cc2f..267388f3691 100644--- a/tests/hermes_cli/test_doctor.py+++ b/tests/hermes_cli/test_doctor.py@@ -285,18 +285,34 @@ def test_doctor_reports_vercel_backend_diagnostics(monkeypatch, tmp_path):class TestDoctorMemoryProviderSection:"""The ◆ Memory Provider section should respect memory.provider config."""- def _make_hermes_home(self, tmp_path, provider=""):+ def _make_hermes_home(self, tmp_path, provider="", memory_config=None):"""Create a minimal HERMES_HOME with config.yaml."""home = tmp_path / ".hermes"home.mkdir(parents=True, exist_ok=True)import yaml- config = {"memory": {"provider": provider}} if provider else {"memory": {}}+ config = dict(memory_config or {})+ if provider:+ config["provider"] = provider+ config = {"memory": config}(home / "config.yaml").write_text(yaml.dump(config))return home- def _run_doctor_and_capture(self, monkeypatch, tmp_path, provider=""):+ def _run_doctor_and_capture(+ self,+ monkeypatch,+ tmp_path,+ provider="",+ *,+ memory_config=None,+ stale_builtin_files=False,+ ):"""Run doctor and capture stdout."""- home = self._make_hermes_home(tmp_path, provider)+ home = self._make_hermes_home(tmp_path, provider, memory_config)+ if stale_builtin_files:+ memories = home / "memories"+ memories.mkdir()+ (memories / "MEMORY.md").write_text("stale memory", encoding="utf-8")+ (memories / "USER.md").write_text("stale user", encoding="utf-8")monkeypatch.setattr(doctor_mod, "HERMES_HOME", home)monkeypatch.setattr(doctor_mod, "PROJECT_ROOT", tmp_path / "project")monkeypatch.setattr(doctor_mod, "_DHH", str(home))@@ -340,6 +356,26 @@ class TestDoctorMemoryProviderSection:assert "Memory Provider" in outassert "Built-in memory active" not in out+ @pytest.mark.parametrize("memory_enabled", [False, True])+ def test_stale_builtin_files_reported_only_when_store_enabled(+ self, monkeypatch, tmp_path, memory_enabled+ ):+ # #100668: disabled built-in stores must not surface stale files as active.+ out = self._run_doctor_and_capture(+ monkeypatch,+ tmp_path,+ provider="mnemosyne",+ memory_config={+ "memory_enabled": memory_enabled,+ "user_profile_enabled": False,+ },+ stale_builtin_files=True,+ )++ assert ("MEMORY.md exists" in out) is memory_enabled+ assert "USER.md exists" not in out+ assert ("Built-in memory files disabled by config" in out) is not memory_enabled+def test_run_doctor_termux_treats_docker_and_browser_warnings_as_expected(monkeypatch, tmp_path):helper = TestDoctorMemoryProviderSection()