2026-03-09 07:02:06 +03:00
|
|
|
"""
|
|
|
|
|
Skills configuration for Hermes Agent.
|
|
|
|
|
`hermes skills` enters this module.
|
|
|
|
|
|
|
|
|
|
Toggle individual skills or categories on/off, globally or per-platform.
|
|
|
|
|
Config stored in ~/.hermes/config.yaml under:
|
|
|
|
|
|
|
|
|
|
skills:
|
|
|
|
|
disabled: [skill-a, skill-b] # global disabled list
|
|
|
|
|
platform_disabled: # per-platform overrides
|
|
|
|
|
telegram: [skill-c]
|
|
|
|
|
cli: []
|
|
|
|
|
"""
|
chore: remove ~100 unused imports across 55 files (#3016)
Automated cleanup via pyflakes + autoflake with manual review.
Changes:
- Removed unused stdlib imports (os, sys, json, pathlib.Path, etc.)
- Removed unused typing imports (List, Dict, Any, Optional, Tuple, Set, etc.)
- Removed unused internal imports (hermes_cli.auth, hermes_cli.config, etc.)
- Fixed cli.py: removed 8 shadowed banner imports (imported from hermes_cli.banner
then immediately redefined locally — only build_welcome_banner is actually used)
- Added noqa comments to imports that appear unused but serve a purpose:
- Re-exports (gateway/session.py SessionResetPolicy, tools/terminal_tool.py
is_interrupted/_interrupt_event)
- SDK presence checks in try/except (daytona, fal_client, discord)
- Test mock targets (auxiliary_client.py Path, mcp_config.py get_hermes_home)
Zero behavioral changes. Full test suite passes (6162/6162, 2 pre-existing
streaming test failures unrelated to this change).
2026-03-25 15:02:03 -07:00
|
|
|
from typing import List, Optional, Set
|
2026-03-11 03:06:15 -07:00
|
|
|
|
2026-03-09 07:02:06 +03:00
|
|
|
from hermes_cli.config import load_config, save_config
|
|
|
|
|
from hermes_cli.colors import Colors, color
|
refactor: remove dead code — 1,784 lines across 77 files (#9180)
Deep scan with vulture, pyflakes, and manual cross-referencing identified:
- 41 dead functions/methods (zero callers in production)
- 7 production-dead functions (only test callers, tests deleted)
- 5 dead constants/variables
- ~35 unused imports across agent/, hermes_cli/, tools/, gateway/
Categories of dead code removed:
- Refactoring leftovers: _set_default_model, _setup_copilot_reasoning_selection,
rebuild_lookups, clear_session_context, get_logs_dir, clear_session
- Unused API surface: search_models_dev, get_pricing, skills_categories,
get_read_files_summary, clear_read_tracker, menu_labels, get_spinner_list
- Dead compatibility wrappers: schedule_cronjob, list_cronjobs, remove_cronjob
- Stale debug helpers: get_debug_session_info copies in 4 tool files
(centralized version in debug_helpers.py already exists)
- Dead gateway methods: send_emote, send_notice (matrix), send_reaction
(bluebubbles), _normalize_inbound_text (feishu), fetch_room_history
(matrix), _start_typing_indicator (signal), parse_feishu_post_content
- Dead constants: NOUS_API_BASE_URL, SKILLS_TOOL_DESCRIPTION,
FILE_TOOLS, VALID_ASPECT_RATIOS, MEMORY_DIR
- Unused UI code: _interactive_provider_selection,
_interactive_model_selection (superseded by prompt_toolkit picker)
Test suite verified: 609 tests covering affected files all pass.
Tests for removed functions deleted. Tests using removed utilities
(clear_read_tracker, MEMORY_DIR) updated to use internal APIs directly.
2026-04-13 16:32:04 -07:00
|
|
|
from hermes_cli.platforms import PLATFORMS as _PLATFORMS
|
2026-03-09 07:02:06 +03:00
|
|
|
|
refactor: extract shared helpers to deduplicate repeated code patterns (#7917)
* refactor: add shared helper modules for code deduplication
New modules:
- gateway/platforms/helpers.py: MessageDeduplicator, TextBatchAggregator,
strip_markdown, ThreadParticipationTracker, redact_phone
- hermes_cli/cli_output.py: print_info/success/warning/error, prompt helpers
- tools/path_security.py: validate_within_dir, has_traversal_component
- utils.py additions: safe_json_loads, read_json_file, read_jsonl,
append_jsonl, env_str/lower/int/bool helpers
- hermes_constants.py additions: get_config_path, get_skills_dir,
get_logs_dir, get_env_path
* refactor: migrate gateway adapters to shared helpers
- MessageDeduplicator: discord, slack, dingtalk, wecom, weixin, mattermost
- strip_markdown: bluebubbles, feishu, sms
- redact_phone: sms, signal
- ThreadParticipationTracker: discord, matrix
- _acquire/_release_platform_lock: telegram, discord, slack, whatsapp,
signal, weixin
Net -316 lines across 19 files.
* refactor: migrate CLI modules to shared helpers
- tools_config.py: use cli_output print/prompt + curses_radiolist (-117 lines)
- setup.py: use cli_output print helpers + curses_radiolist (-101 lines)
- mcp_config.py: use cli_output prompt (-15 lines)
- memory_setup.py: use curses_radiolist (-86 lines)
Net -263 lines across 5 files.
* refactor: migrate to shared utility helpers
- safe_json_loads: agent/display.py (4 sites)
- get_config_path: skill_utils.py, hermes_logging.py, hermes_time.py
- get_skills_dir: skill_utils.py, prompt_builder.py
- Token estimation dedup: skills_tool.py imports from model_metadata
- Path security: skills_tool, cronjob_tools, skill_manager_tool, credential_files
- Non-atomic YAML writes: doctor.py, config.py now use atomic_yaml_write
- Platform dict: new platforms.py, skills_config + tools_config derive from it
- Anthropic key: new get_anthropic_key() in auth.py, used by doctor/status/config/main
* test: update tests for shared helper migrations
- test_dingtalk: use _dedup.is_duplicate() instead of _is_duplicate()
- test_mattermost: use _dedup instead of _seen_posts/_prune_seen
- test_signal: import redact_phone from helpers instead of signal
- test_discord_connect: _platform_lock_identity instead of _token_lock_identity
- test_telegram_conflict: updated lock error message format
- test_skill_manager_tool: 'escapes' instead of 'boundary' in error msgs
2026-04-11 13:59:52 -07:00
|
|
|
# Backward-compatible view: {key: label_string} so existing code that
|
|
|
|
|
# iterates ``PLATFORMS.items()`` or calls ``PLATFORMS.get(key)`` keeps
|
|
|
|
|
# working without changes to every call site.
|
|
|
|
|
PLATFORMS = {k: info.label for k, info in _PLATFORMS.items() if k != "api_server"}
|
2026-03-09 07:02:06 +03:00
|
|
|
|
|
|
|
|
# ─── Config Helpers ───────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
def get_disabled_skills(config: dict, platform: Optional[str] = None) -> Set[str]:
|
|
|
|
|
"""Return disabled skill names. Platform-specific list falls back to global."""
|
|
|
|
|
skills_cfg = config.get("skills", {})
|
|
|
|
|
global_disabled = set(skills_cfg.get("disabled", []))
|
|
|
|
|
if platform is None:
|
|
|
|
|
return global_disabled
|
|
|
|
|
platform_disabled = skills_cfg.get("platform_disabled", {}).get(platform)
|
|
|
|
|
if platform_disabled is None:
|
|
|
|
|
return global_disabled
|
|
|
|
|
return set(platform_disabled)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_disabled_skills(config: dict, disabled: Set[str], platform: Optional[str] = None):
|
|
|
|
|
"""Persist disabled skill names to config."""
|
|
|
|
|
config.setdefault("skills", {})
|
|
|
|
|
if platform is None:
|
|
|
|
|
config["skills"]["disabled"] = sorted(disabled)
|
|
|
|
|
else:
|
|
|
|
|
config["skills"].setdefault("platform_disabled", {})
|
|
|
|
|
config["skills"]["platform_disabled"][platform] = sorted(disabled)
|
|
|
|
|
save_config(config)
|
|
|
|
|
|
|
|
|
|
|
2026-03-11 03:06:15 -07:00
|
|
|
# ─── Skill Discovery ─────────────────────────────────────────────────────────
|
2026-03-09 07:02:06 +03:00
|
|
|
|
2026-03-11 03:06:15 -07:00
|
|
|
def _list_all_skills() -> List[dict]:
|
|
|
|
|
"""Return all installed skills (ignoring disabled state)."""
|
2026-03-09 07:02:06 +03:00
|
|
|
try:
|
2026-03-11 03:06:15 -07:00
|
|
|
from tools.skills_tool import _find_all_skills
|
|
|
|
|
return _find_all_skills(skip_disabled=True)
|
2026-03-09 07:02:06 +03:00
|
|
|
except Exception:
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_categories(skills: List[dict]) -> List[str]:
|
|
|
|
|
"""Return sorted unique category names (None -> 'uncategorized')."""
|
2026-03-11 03:06:15 -07:00
|
|
|
return sorted({s["category"] or "uncategorized" for s in skills})
|
2026-03-09 07:02:06 +03:00
|
|
|
|
|
|
|
|
|
2026-03-11 03:06:15 -07:00
|
|
|
# ─── Platform Selection ──────────────────────────────────────────────────────
|
2026-03-09 07:02:06 +03:00
|
|
|
|
|
|
|
|
def _select_platform() -> Optional[str]:
|
|
|
|
|
"""Ask user which platform to configure, or global."""
|
|
|
|
|
options = [("global", "All platforms (global default)")] + list(PLATFORMS.items())
|
|
|
|
|
print()
|
|
|
|
|
print(color(" Configure skills for:", Colors.BOLD))
|
|
|
|
|
for i, (key, label) in enumerate(options, 1):
|
|
|
|
|
print(f" {i}. {label}")
|
|
|
|
|
print()
|
|
|
|
|
try:
|
|
|
|
|
raw = input(color(" Select [1]: ", Colors.YELLOW)).strip()
|
|
|
|
|
except (KeyboardInterrupt, EOFError):
|
|
|
|
|
return None
|
|
|
|
|
if not raw:
|
|
|
|
|
return None # global
|
|
|
|
|
try:
|
|
|
|
|
idx = int(raw) - 1
|
|
|
|
|
if 0 <= idx < len(options):
|
|
|
|
|
key = options[idx][0]
|
|
|
|
|
return None if key == "global" else key
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
2026-03-11 03:06:15 -07:00
|
|
|
# ─── Category Toggle ─────────────────────────────────────────────────────────
|
2026-03-09 07:02:06 +03:00
|
|
|
|
|
|
|
|
def _toggle_by_category(skills: List[dict], disabled: Set[str]) -> Set[str]:
|
|
|
|
|
"""Toggle all skills in a category at once."""
|
2026-03-11 03:06:15 -07:00
|
|
|
from hermes_cli.curses_ui import curses_checklist
|
|
|
|
|
|
2026-03-09 07:02:06 +03:00
|
|
|
categories = _get_categories(skills)
|
2026-03-11 03:06:15 -07:00
|
|
|
cat_labels = []
|
|
|
|
|
# A category is "enabled" (checked) when NOT all its skills are disabled
|
|
|
|
|
pre_selected = set()
|
|
|
|
|
for i, cat in enumerate(categories):
|
2026-03-09 07:02:06 +03:00
|
|
|
cat_skills = [s["name"] for s in skills if (s["category"] or "uncategorized") == cat]
|
2026-03-11 03:06:15 -07:00
|
|
|
cat_labels.append(f"{cat} ({len(cat_skills)} skills)")
|
|
|
|
|
if not all(s in disabled for s in cat_skills):
|
|
|
|
|
pre_selected.add(i)
|
2026-03-09 07:02:06 +03:00
|
|
|
|
2026-03-11 03:06:15 -07:00
|
|
|
chosen = curses_checklist(
|
|
|
|
|
"Categories — toggle entire categories",
|
|
|
|
|
cat_labels, pre_selected, cancel_returns=pre_selected,
|
|
|
|
|
)
|
2026-03-09 07:02:06 +03:00
|
|
|
|
|
|
|
|
new_disabled = set(disabled)
|
|
|
|
|
for i, cat in enumerate(categories):
|
2026-03-11 03:06:15 -07:00
|
|
|
cat_skills = {s["name"] for s in skills if (s["category"] or "uncategorized") == cat}
|
|
|
|
|
if i in chosen:
|
|
|
|
|
new_disabled -= cat_skills # category enabled → remove from disabled
|
2026-03-09 07:02:06 +03:00
|
|
|
else:
|
2026-03-11 03:06:15 -07:00
|
|
|
new_disabled |= cat_skills # category disabled → add to disabled
|
2026-03-09 07:02:06 +03:00
|
|
|
return new_disabled
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ─── Entry Point ──────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
def skills_command(args=None):
|
|
|
|
|
"""Entry point for `hermes skills`."""
|
2026-03-11 03:06:15 -07:00
|
|
|
from hermes_cli.curses_ui import curses_checklist
|
|
|
|
|
|
2026-03-09 07:02:06 +03:00
|
|
|
config = load_config()
|
2026-03-11 03:06:15 -07:00
|
|
|
skills = _list_all_skills()
|
2026-03-09 07:02:06 +03:00
|
|
|
|
|
|
|
|
if not skills:
|
|
|
|
|
print(color(" No skills installed.", Colors.DIM))
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Step 1: Select platform
|
|
|
|
|
platform = _select_platform()
|
|
|
|
|
platform_label = PLATFORMS.get(platform, "All platforms") if platform else "All platforms"
|
|
|
|
|
|
|
|
|
|
# Step 2: Select mode — individual or by category
|
|
|
|
|
print()
|
|
|
|
|
print(color(f" Configure for: {platform_label}", Colors.DIM))
|
|
|
|
|
print()
|
|
|
|
|
print(" 1. Toggle individual skills")
|
|
|
|
|
print(" 2. Toggle by category")
|
|
|
|
|
print()
|
|
|
|
|
try:
|
|
|
|
|
mode = input(color(" Select [1]: ", Colors.YELLOW)).strip() or "1"
|
|
|
|
|
except (KeyboardInterrupt, EOFError):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
disabled = get_disabled_skills(config, platform)
|
|
|
|
|
|
|
|
|
|
if mode == "2":
|
|
|
|
|
new_disabled = _toggle_by_category(skills, disabled)
|
|
|
|
|
else:
|
2026-03-11 03:06:15 -07:00
|
|
|
# Build labels and map indices → skill names
|
|
|
|
|
labels = [
|
2026-03-09 07:02:06 +03:00
|
|
|
f"{s['name']} ({s['category'] or 'uncategorized'}) — {s['description'][:55]}"
|
|
|
|
|
for s in skills
|
|
|
|
|
]
|
2026-03-11 03:06:15 -07:00
|
|
|
# "selected" = enabled (not disabled) — matches the [✓] convention
|
|
|
|
|
pre_selected = {i for i, s in enumerate(skills) if s["name"] not in disabled}
|
|
|
|
|
chosen = curses_checklist(
|
|
|
|
|
f"Skills for {platform_label}",
|
|
|
|
|
labels, pre_selected, cancel_returns=pre_selected,
|
2026-03-09 07:02:06 +03:00
|
|
|
)
|
2026-03-11 03:06:15 -07:00
|
|
|
# Anything NOT chosen is disabled
|
|
|
|
|
new_disabled = {skills[i]["name"] for i in range(len(skills)) if i not in chosen}
|
2026-03-09 07:02:06 +03:00
|
|
|
|
|
|
|
|
if new_disabled == disabled:
|
|
|
|
|
print(color(" No changes.", Colors.DIM))
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
save_disabled_skills(config, new_disabled, platform)
|
|
|
|
|
enabled_count = len(skills) - len(new_disabled)
|
|
|
|
|
print(color(f"✓ Saved: {enabled_count} enabled, {len(new_disabled)} disabled ({platform_label}).", Colors.GREEN))
|