The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(skills): rescan skill commands cache when active profile changes
chelsealonga9b4ec312668
diff --git a/agent/skill_commands.py b/agent/skill_commands.pyindex a14aebb1187..e524d652d15 100644--- a/agent/skill_commands.py+++ b/agent/skill_commands.py@@ -23,6 +23,7 @@ logger = logging.getLogger(__name__)_skill_commands: Dict[str, Dict[str, Any]] = {}_skill_commands_platform: Optional[str] = None+_skill_commands_home: Optional[str] = None# Patterns for sanitizing skill names into clean hyphen-separated slugs._SKILL_INVALID_CHARS = re.compile(r"[^a-z0-9-]")_SKILL_MULTI_HYPHEN = re.compile(r"-{2,}")@@ -207,6 +208,22 @@ def _resolve_skill_commands_platform() -> Optional[str]:resolved_platform = os.getenv("HERMES_PLATFORM")return resolved_platform or None++def _resolve_skill_commands_home() -> str:+ """Return the effective Hermes home the skill scan should be scoped to.++ A gateway session can switch between profiles that each carry their own+ ``skills.external_dirs`` (via ``set_hermes_home_override``), but the+ module-level scan only tracked ``_resolve_skill_commands_platform()``.+ Switching profiles without a platform change left the previous profile's+ skill list cached, so ``get_skill_commands()`` reported a cache miss for+ skills that only exist under the new profile (#88023).+ """+ from hermes_constants import get_hermes_home++ return str(get_hermes_home())++def _load_skill_payload(skill_identifier: str, task_id: str | None = None) -> tuple[dict[str, Any], Path | None, str] | None:"""Load a skill by name/path and return (loaded_payload, skill_dir, display_name)."""raw_identifier = (skill_identifier or "").strip()@@ -405,8 +422,9 @@ def scan_skill_commands() -> Dict[str, Dict[str, Any]]:Returns:Dict mapping "/skill-name" to {name, description, skill_md_path, skill_dir}."""- global _skill_commands, _skill_commands_platform+ global _skill_commands, _skill_commands_platform, _skill_commands_home_skill_commands_platform = _resolve_skill_commands_platform()+ _skill_commands_home = _resolve_skill_commands_home()_skill_commands = {}try:from tools.skills_tool import SKILLS_DIR, _parse_frontmatter, skill_matches_platform, skill_matches_environment, _get_disabled_skill_names@@ -500,11 +518,14 @@ def get_skill_commands() -> Dict[str, Dict[str, Any]]:Rescans when the active platform scope changes (e.g. a gatewayprocess serving Telegram and Discord concurrently) so each platform- sees its own ``skills.platform_disabled`` view (#14536).+ sees its own ``skills.platform_disabled`` view (#14536), and when the+ active profile's Hermes home changes (e.g. Desktop switching profiles+ mid-session) so each profile sees its own ``skills.external_dirs`` (#88023)."""if (not _skill_commandsor _skill_commands_platform != _resolve_skill_commands_platform()+ or _skill_commands_home != _resolve_skill_commands_home()):scan_skill_commands()return _skill_commandsdiff --git a/tests/agent/test_skill_commands.py b/tests/agent/test_skill_commands.pyindex 28f683086d5..737a916df83 100644--- a/tests/agent/test_skill_commands.py+++ b/tests/agent/test_skill_commands.py@@ -200,6 +200,61 @@ class TestScanSkillCommands:assert "/telegram-only" in discord_commandsassert "/discord-only" not in discord_commands+ def test_get_skill_commands_rescans_when_profile_home_changes(self, tmp_path):+ """Switching profiles must rescan even when the platform is unchanged+ (#88023): a Desktop session that switches profiles mid-session keeps+ the same platform scope, so only ``HERMES_HOME`` moves. Each profile+ declares its own ``skills.external_dirs``, and the previous profile's+ skill list must not leak into the new one.+ """+ import agent.skill_commands as sc_mod+ from agent.skill_commands import get_skill_commands+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override++ empty_local_dir = tmp_path / "no-local-skills"+ empty_local_dir.mkdir()++ profile_a = tmp_path / "profile_a"+ profile_b = tmp_path / "profile_b"+ external_a = tmp_path / "external_a"+ external_b = tmp_path / "external_b"+ profile_a.mkdir()+ profile_b.mkdir()+ _make_skill(external_a, "a-only")+ _make_skill(external_b, "b-only")+ (profile_a / "config.yaml").write_text(+ f"skills:\n external_dirs:\n - {external_a}\n"+ )+ (profile_b / "config.yaml").write_text(+ f"skills:\n external_dirs:\n - {external_b}\n"+ )++ with (+ patch("tools.skills_tool.SKILLS_DIR", empty_local_dir),+ patch.object(sc_mod, "_skill_commands", {}),+ patch.object(sc_mod, "_skill_commands_platform", None),+ patch.object(sc_mod, "_skill_commands_home", None),+ ):+ token = set_hermes_home_override(profile_a)+ try:+ profile_a_commands = dict(get_skill_commands())+ finally:+ reset_hermes_home_override(token)++ assert "/a-only" in profile_a_commands+ assert "/b-only" not in profile_a_commands++ # Switching profiles without touching the cache directly must+ # rescan — not keep serving profile_a's stale view.+ token = set_hermes_home_override(profile_b)+ try:+ profile_b_commands = dict(get_skill_commands())+ finally:+ reset_hermes_home_override(token)++ assert "/b-only" in profile_b_commands+ assert "/a-only" not in profile_b_commands+def test_get_skill_commands_rescans_when_leaving_platform_scope(self, tmp_path, monkeypatch):"""Returning to no-platform-scope (CLI / cron / RL) after a gatewaysession must rescan so the unfiltered view is repopulated (#14536).