mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
config.yaml terminal.cwd is now the single source of truth for working directory. MESSAGING_CWD and TERMINAL_CWD in .env are deprecated with a migration warning. Changes: 1. config.py: Remove MESSAGING_CWD from OPTIONAL_ENV_VARS (setup wizard no longer prompts for it). Add warn_deprecated_cwd_env_vars() that prints a migration hint when deprecated env vars are detected. 2. gateway/run.py: Replace all MESSAGING_CWD reads with TERMINAL_CWD (which is bridged from config.yaml terminal.cwd). MESSAGING_CWD is still accepted as a backward-compat fallback with deprecation warning. Config bridge skips cwd placeholder values so they don't clobber the resolved TERMINAL_CWD. 3. cli.py: Guard against lazy-import clobbering — when cli.py is imported lazily during gateway runtime (via delegate_tool), don't let load_cli_config() overwrite an already-resolved TERMINAL_CWD with os.getcwd() of the service's working directory. (#10817) 4. hermes_cli/main.py: Add 'hermes memory reset' command with --target all/memory/user and --yes flags. Profile-scoped via HERMES_HOME. Migration path for users with .env settings: Remove MESSAGING_CWD / TERMINAL_CWD from .env Add to config.yaml: terminal: cwd: /your/project/path Addresses: #10225, #4672, #10817, #7663
157 lines
5.7 KiB
Python
157 lines
5.7 KiB
Python
"""Tests for the `hermes memory reset` CLI command.
|
|
|
|
Covers:
|
|
- Reset both stores (MEMORY.md + USER.md)
|
|
- Reset individual stores (--target memory / --target user)
|
|
- Skip confirmation with --yes
|
|
- Graceful handling when no memory files exist
|
|
- Profile-scoped reset (uses HERMES_HOME)
|
|
"""
|
|
|
|
import os
|
|
import pytest
|
|
from argparse import Namespace
|
|
from pathlib import Path
|
|
|
|
|
|
@pytest.fixture
|
|
def memory_env(tmp_path, monkeypatch):
|
|
"""Set up a fake HERMES_HOME with memory files."""
|
|
hermes_home = tmp_path / ".hermes"
|
|
memories = hermes_home / "memories"
|
|
memories.mkdir(parents=True)
|
|
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
|
|
|
|
# Create sample memory files
|
|
(memories / "MEMORY.md").write_text(
|
|
"§\nHermes repo is at ~/.hermes/hermes-agent\n§\nUser prefers dark themes",
|
|
encoding="utf-8",
|
|
)
|
|
(memories / "USER.md").write_text(
|
|
"§\nUser is Teknium\n§\nTimezone: US Pacific",
|
|
encoding="utf-8",
|
|
)
|
|
return hermes_home, memories
|
|
|
|
|
|
def _run_memory_reset(target="all", yes=False, monkeypatch=None, confirm_input="no"):
|
|
"""Invoke the memory reset logic from cmd_memory in main.py.
|
|
|
|
Simulates what happens when `hermes memory reset` is run.
|
|
"""
|
|
from hermes_constants import get_hermes_home, display_hermes_home
|
|
|
|
mem_dir = get_hermes_home() / "memories"
|
|
files_to_reset = []
|
|
if target in ("all", "memory"):
|
|
files_to_reset.append(("MEMORY.md", "agent notes"))
|
|
if target in ("all", "user"):
|
|
files_to_reset.append(("USER.md", "user profile"))
|
|
|
|
existing = [(f, desc) for f, desc in files_to_reset if (mem_dir / f).exists()]
|
|
if not existing:
|
|
return "nothing"
|
|
|
|
if not yes:
|
|
if confirm_input != "yes":
|
|
return "cancelled"
|
|
|
|
for f, desc in existing:
|
|
(mem_dir / f).unlink()
|
|
|
|
return "deleted"
|
|
|
|
|
|
class TestMemoryReset:
|
|
"""Tests for `hermes memory reset` subcommand."""
|
|
|
|
def test_reset_all_with_yes_flag(self, memory_env):
|
|
"""--yes flag should skip confirmation and delete both files."""
|
|
hermes_home, memories = memory_env
|
|
assert (memories / "MEMORY.md").exists()
|
|
assert (memories / "USER.md").exists()
|
|
|
|
result = _run_memory_reset(target="all", yes=True)
|
|
assert result == "deleted"
|
|
assert not (memories / "MEMORY.md").exists()
|
|
assert not (memories / "USER.md").exists()
|
|
|
|
def test_reset_memory_only(self, memory_env):
|
|
"""--target memory should only delete MEMORY.md."""
|
|
hermes_home, memories = memory_env
|
|
|
|
result = _run_memory_reset(target="memory", yes=True)
|
|
assert result == "deleted"
|
|
assert not (memories / "MEMORY.md").exists()
|
|
assert (memories / "USER.md").exists()
|
|
|
|
def test_reset_user_only(self, memory_env):
|
|
"""--target user should only delete USER.md."""
|
|
hermes_home, memories = memory_env
|
|
|
|
result = _run_memory_reset(target="user", yes=True)
|
|
assert result == "deleted"
|
|
assert (memories / "MEMORY.md").exists()
|
|
assert not (memories / "USER.md").exists()
|
|
|
|
def test_reset_no_files_exist(self, tmp_path, monkeypatch):
|
|
"""Should return 'nothing' when no memory files exist."""
|
|
hermes_home = tmp_path / ".hermes"
|
|
(hermes_home / "memories").mkdir(parents=True)
|
|
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
|
|
|
|
result = _run_memory_reset(target="all", yes=True)
|
|
assert result == "nothing"
|
|
|
|
def test_reset_confirmation_denied(self, memory_env):
|
|
"""Without --yes and without typing 'yes', should be cancelled."""
|
|
hermes_home, memories = memory_env
|
|
|
|
result = _run_memory_reset(target="all", yes=False, confirm_input="no")
|
|
assert result == "cancelled"
|
|
# Files should still exist
|
|
assert (memories / "MEMORY.md").exists()
|
|
assert (memories / "USER.md").exists()
|
|
|
|
def test_reset_confirmation_accepted(self, memory_env):
|
|
"""Typing 'yes' should proceed with deletion."""
|
|
hermes_home, memories = memory_env
|
|
|
|
result = _run_memory_reset(target="all", yes=False, confirm_input="yes")
|
|
assert result == "deleted"
|
|
assert not (memories / "MEMORY.md").exists()
|
|
assert not (memories / "USER.md").exists()
|
|
|
|
def test_reset_profile_scoped(self, tmp_path, monkeypatch):
|
|
"""Reset should work on the active profile's HERMES_HOME."""
|
|
profile_home = tmp_path / "profiles" / "myprofile"
|
|
memories = profile_home / "memories"
|
|
memories.mkdir(parents=True)
|
|
(memories / "MEMORY.md").write_text("profile memory", encoding="utf-8")
|
|
(memories / "USER.md").write_text("profile user", encoding="utf-8")
|
|
monkeypatch.setenv("HERMES_HOME", str(profile_home))
|
|
|
|
result = _run_memory_reset(target="all", yes=True)
|
|
assert result == "deleted"
|
|
assert not (memories / "MEMORY.md").exists()
|
|
assert not (memories / "USER.md").exists()
|
|
|
|
def test_reset_partial_files(self, memory_env):
|
|
"""Reset should work when only one memory file exists."""
|
|
hermes_home, memories = memory_env
|
|
(memories / "USER.md").unlink()
|
|
|
|
result = _run_memory_reset(target="all", yes=True)
|
|
assert result == "deleted"
|
|
assert not (memories / "MEMORY.md").exists()
|
|
|
|
def test_reset_empty_memories_dir(self, tmp_path, monkeypatch):
|
|
"""No memories dir at all should report nothing."""
|
|
hermes_home = tmp_path / ".hermes"
|
|
hermes_home.mkdir(parents=True)
|
|
# No memories dir
|
|
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
|
|
|
|
# The memories dir won't exist; get_hermes_home() / "memories" won't have files
|
|
result = _run_memory_reset(target="all", yes=True)
|
|
assert result == "nothing"
|