refactor: extract shared curses checklist, fix skill discovery perf
Four cleanups to code merged today: 1. New hermes_cli/curses_ui.py — shared curses_checklist() used by both hermes tools and hermes skills. Eliminates ~140 lines of near-identical curses code (scrolling, key handling, color setup, numbered fallback). 2. Fix _find_all_skills() perf — was calling load_config() per skill (~100+ YAML parses). Now loads disabled set once via _get_disabled_skill_names() and does a set lookup. 3. Eliminate _list_all_skills_unfiltered() duplication — _find_all_skills() now accepts skip_disabled=True for the config UI, removing 30 lines of copy-pasted discovery logic from skills_config.py. 4. Fix fragile label round-trip in skills_command — was building label strings, passing to checklist, then mapping labels back to skill names (collision-prone). Now works with indices directly, like tools_config.
This commit is contained in:
parent
f1510ec33e
commit
4864a5684a
5 changed files with 257 additions and 319 deletions
|
|
@ -146,8 +146,8 @@ class TestIsSkillDisabled:
|
|||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestFindAllSkillsFiltering:
|
||||
@patch("tools.skills_tool._is_skill_disabled")
|
||||
@patch("tools.skills_tool.skill_matches_platform")
|
||||
@patch("tools.skills_tool._get_disabled_skill_names", return_value={"my-skill"})
|
||||
@patch("tools.skills_tool.skill_matches_platform", return_value=True)
|
||||
@patch("tools.skills_tool.SKILLS_DIR")
|
||||
def test_disabled_skill_excluded(self, mock_dir, mock_platform, mock_disabled, tmp_path):
|
||||
skill_dir = tmp_path / "my-skill"
|
||||
|
|
@ -156,14 +156,12 @@ class TestFindAllSkillsFiltering:
|
|||
skill_md.write_text("---\nname: my-skill\ndescription: A test skill\n---\nContent")
|
||||
mock_dir.exists.return_value = True
|
||||
mock_dir.rglob.return_value = [skill_md]
|
||||
mock_platform.return_value = True
|
||||
mock_disabled.return_value = True
|
||||
from tools.skills_tool import _find_all_skills
|
||||
skills = _find_all_skills()
|
||||
assert not any(s["name"] == "my-skill" for s in skills)
|
||||
|
||||
@patch("tools.skills_tool._is_skill_disabled")
|
||||
@patch("tools.skills_tool.skill_matches_platform")
|
||||
@patch("tools.skills_tool._get_disabled_skill_names", return_value=set())
|
||||
@patch("tools.skills_tool.skill_matches_platform", return_value=True)
|
||||
@patch("tools.skills_tool.SKILLS_DIR")
|
||||
def test_enabled_skill_included(self, mock_dir, mock_platform, mock_disabled, tmp_path):
|
||||
skill_dir = tmp_path / "my-skill"
|
||||
|
|
@ -172,12 +170,25 @@ class TestFindAllSkillsFiltering:
|
|||
skill_md.write_text("---\nname: my-skill\ndescription: A test skill\n---\nContent")
|
||||
mock_dir.exists.return_value = True
|
||||
mock_dir.rglob.return_value = [skill_md]
|
||||
mock_platform.return_value = True
|
||||
mock_disabled.return_value = False
|
||||
from tools.skills_tool import _find_all_skills
|
||||
skills = _find_all_skills()
|
||||
assert any(s["name"] == "my-skill" for s in skills)
|
||||
|
||||
@patch("tools.skills_tool._get_disabled_skill_names", return_value={"my-skill"})
|
||||
@patch("tools.skills_tool.skill_matches_platform", return_value=True)
|
||||
@patch("tools.skills_tool.SKILLS_DIR")
|
||||
def test_skip_disabled_returns_all(self, mock_dir, mock_platform, mock_disabled, tmp_path):
|
||||
"""skip_disabled=True ignores the disabled set (for config UI)."""
|
||||
skill_dir = tmp_path / "my-skill"
|
||||
skill_dir.mkdir()
|
||||
skill_md = skill_dir / "SKILL.md"
|
||||
skill_md.write_text("---\nname: my-skill\ndescription: A test skill\n---\nContent")
|
||||
mock_dir.exists.return_value = True
|
||||
mock_dir.rglob.return_value = [skill_md]
|
||||
from tools.skills_tool import _find_all_skills
|
||||
skills = _find_all_skills(skip_disabled=True)
|
||||
assert any(s["name"] == "my-skill" for s in skills)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# _get_categories
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue