The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(skills): resolve hub installs by identifier slug, and fail loudly
pecalbezyshodnost-hue586dc0561f6e
diff --git a/hermes_cli/skills_hub.py b/hermes_cli/skills_hub.pyindex 244e04bd594..4ee55740ec7 100644--- a/hermes_cli/skills_hub.py+++ b/hermes_cli/skills_hub.py@@ -186,6 +186,32 @@ def _format_extra_metadata_lines(extra: Dict[str, Any]) -> list[str]:# --- Identifier / source resolution ---+def _slug_key(text: str) -> str:+ """Separator-insensitive comparison key ("Blender Bpy Enhanced" == "blender-bpy-enhanced")."""+ return re.sub(r"[^a-z0-9]+", "", str(text or "").lower())+++def _identifier_slug(identifier: str) -> str:+ """Trailing path segment of an identifier ("skills-sh/org/repo/blender-animation" -> the slug)."""+ return str(identifier or "").split("/")[-1]+++def _exact_name_hits(results, name: str):+ """Results that ARE `name`: display name as written first, then — only when that finds nothing —+ the separator-insensitive form of the display name or of the identifier's trailing slug. Catalogs+ that carry a prettified title (ClawHub rows read "Blender Bpy Enhanced") or a path-shaped+ identifier ("@org/my-skill") match by neither, so `hermes skills install my-skill` refused with+ "No exact match" while printing that very slug on the suggestion line."""+ query = str(name or "").strip().lower()+ hits = [r for r in results if str(r.name or "").strip().lower() == query]+ if hits:+ return hits+ key = _slug_key(query)+ if not key:+ return []+ return [r for r in results if key in (_slug_key(r.name), _slug_key(_identifier_slug(r.identifier)))]++def _resolve_short_name(name: str, sources, console: Console) -> str:"""Short name -> full identifier via search; "" when ambiguous/missing (one exact match wins,several -> the single official one, else they are listed)."""@@ -193,7 +219,7 @@ def _resolve_short_name(name: str, sources, console: Console) -> str:c = console or _consolec.print(f"[dim]Resolving '{name}'...[/]")results = unified_search(name, sources, source_filter="all", limit=20)- exact = [r for r in results if r.name.lower() == name.lower()]+ exact = _exact_name_hits(results, name)if len(exact) == 1:c.print(f"[dim]Resolved to: {exact[0].identifier}[/]")@@ -694,48 +720,56 @@ def _record_skill_install(identifier: str, bundle, outcome: str) -> None:def do_install(identifier: str, category: str = "", force: bool = False,console: Optional[Console] = None, skip_confirm: bool = False,invalidate_cache: bool = True, name_override: str = "",- source_id: Optional[str] = None) -> None:+ source_id: Optional[str] = None) -> Optional[bool]:"""Fetch, quarantine, scan, confirm, and install a skill. ``source_id`` pins resolution to oneadapter; callers that know the provenance (``do_update``) must pass it so a bare identifiercannot resolve to a same-named skill elsewhere.A first install is recorded once as an extension install; updates and ``--force`` reinstalls- of an installed skill run through here too and are not installs, nor is a cancelled prompt."""+ of an installed skill run through here too and are not installs, nor is a cancelled prompt.++ Returns True when the skill was installed, False when the install failed (unresolved name,+ fetch, scan block, bad path), None for a no-op the user owns (already installed, declined).+ The CLI router turns False into a non-zero exit — the Desktop Hub toasts failures off that+ exit code, so an exit-0 failure reads as "the button did nothing" (only the action log).+ """from tools.skills_hub import HubLockFilefresh = not HubLockFile().get_installed(identifier.rstrip("/").rsplit("/", 1)[-1])try:- bundle, outcome = _install_skill(identifier, category, force, console or _console,- skip_confirm, invalidate_cache, name_override, source_id)+ bundle, outcome, installed = _install_skill(identifier, category, force, console or _console,+ skip_confirm, invalidate_cache, name_override, source_id)except Exception:if fresh:_record_skill_install(identifier, None, "failed")raiseif fresh and outcome:_record_skill_install(identifier, bundle, outcome)+ return installeddef _install_skill(identifier: str, category: str, force: bool, c: Console, skip_confirm: bool,invalidate_cache: bool, name_override: str, source_id: Optional[str]) -> tuple:- """``do_install``'s body: ``(bundle, outcome)``, outcome None when this was no new install."""+ """``do_install``'s body: ``(bundle, outcome, installed)``. ``outcome`` is the extension-install+ event (None when this was no new install); ``installed`` is ``do_install``'s return value."""from tools.skills_hub import HubLockFile, ensure_hub_dirs, skills_hub_http_sessionfrom tools.skills_hub_install import install_from_quarantine, quarantine_bundlefrom tools.skills_guard import should_allow_installensure_hub_dirs()sources = _pinned_sources(c, _sources(), source_id, identifier)if sources is None:- return None, "failed"+ return None, "failed", False# One pooled guarded client for the whole resolve + fetch fan-out (tree, SKILL.md, N support files).with skills_hub_http_session():identifier = _full_identifier(identifier, sources, c)if not identifier:- return None, "failed"+ return None, "failed", Falsec.print(f"\n[bold]Fetching:[/] {identifier}")meta, bundle, _matched_source = _resolve_source_meta_and_bundle(identifier, sources)if not bundle:_print_fetch_failure(c, sources, identifier, meta=meta, source=_matched_source)- return None, "failed"+ return None, "failed", Falseif not _resolve_url_bundle_name(c, bundle, meta, identifier, name_override, skip_confirm):- return bundle, "failed"+ return bundle, "failed", False# URL-sourced skills: pick a category interactively when none was given (TTY only;# non-interactive installs fall through to flat install like every other source).@@ -751,7 +785,7 @@ def _install_skill(identifier: str, category: str, force: bool, c: Console, skipc.print(f"[yellow]Warning:[/] '{bundle.name}' is already installed at {existing['install_path']}")if not force:c.print("Use --force to reinstall.\n")- return bundle, None+ return bundle, None, Nonefailed = None if existing else "failed"extra_metadata = {**(getattr(meta, "extra", {}) or {}), **bundle.metadata}@@ -760,7 +794,7 @@ def _install_skill(identifier: str, category: str, force: bool, c: Console, skipq_path = quarantine_bundle(bundle)except ValueError as exc:_invalid_path(c, bundle, exc)- return bundle, failed+ return bundle, failed, Falsec.print(f"[dim]Quarantined to {q_path.relative_to(q_path.parent.parent.parent)}[/]")result = _scan_quarantined(c, q_path, bundle, meta, identifier)@@ -768,7 +802,7 @@ def _install_skill(identifier: str, category: str, force: bool, c: Console, skipif not allowed:_install_blocked(c, bundle, _scan_block_message(result, identifier), result.verdict,f"{len(result.findings)}_findings", q_path=q_path, lead="\n", label="Not installed:")- return bundle, failed+ return bundle, failed, False# Advisory second opinion — warn-and-continue by design (PII-class findings are# informational); the install confirmation below is where the user decides._print_tier1_advisory(q_path, c)@@ -779,19 +813,19 @@ def _install_skill(identifier: str, category: str, force: bool, c: Console, skip# skip_confirm bypasses the prompt (TUI mode, where input() hangs).if not force and not skip_confirm and not _confirm_install(c, bundle, category):shutil.rmtree(q_path, ignore_errors=True)- return bundle, None+ return bundle, None, Nonetry:install_dir = install_from_quarantine(q_path, bundle.name, category, bundle, result)except ValueError as exc:_invalid_path(c, bundle, exc, q_path)- return bundle, failed+ return bundle, failed, Falsefrom tools.skills_hub import SKILLS_DIRc.print(f"[bold green]Installed:[/] {install_dir.resolve().relative_to(Path(SKILLS_DIR).resolve()).as_posix()}")c.print(f"[dim]Files: {', '.join(bundle.files.keys())}[/]\n")_announce_blueprint(c, bundle.name)_finish_change(c, invalidate_cache, "Skill will be available", "activate")- return bundle, None if existing else "success"+ return bundle, None if existing else "success", Truedef _print_tier1_advisory(skill_dir, console) -> None:@@ -1421,7 +1455,11 @@ def skills_command(args) -> None:_console.print("Usage: hermes skills [browse|search|install|inspect|list|list-modified|diff|check|update|audit|uninstall|reset|opt-out|opt-in|publish|snapshot|tap]\n")_console.print("Run 'hermes skills <command> --help' for details.\n")return- handler(args)+ # A handler reporting a real failure (do_install's False) must exit non-zero: the Desktop Hub+ # reads the spawned action's exit code to decide whether to toast, so an exit-0 failure renders+ # as "the button did nothing" while the reason sits unread in the action log.+ if handler(args) is False:+ sys.exit(1)# --- Slash command entry point (/skills in chat) ---diff --git a/tests/hermes_cli/test_skills_hub.py b/tests/hermes_cli/test_skills_hub.pyindex 4ae60497a58..c56cbd97d15 100644--- a/tests/hermes_cli/test_skills_hub.py+++ b/tests/hermes_cli/test_skills_hub.py@@ -650,3 +650,91 @@ def test_do_install_generic_when_no_index_hit_or_rate_limited(monkeypatch, meta_assert "Could not download" in outassert "Stale index entry" not in outassert ("rate limit" in out) is meta_hit+++# ---------------------------------------------------------------------------+# Short-name resolution by identifier + failure exit code+# ---------------------------------------------------------------------------+++def _meta(name, identifier, source="clawhub"):+ from tools.skills_hub_models import SkillMeta++ return SkillMeta(name=name, description="", source=source, identifier=identifier,+ trust_level="community")+++def _sink_console():+ sink = StringIO()+ return Console(file=sink, force_terminal=False, color_system=None), sink+++def _stub_search(monkeypatch, results):+ """unified_search is late-bound inside _resolve_short_name, so patch its module."""+ import tools.skills_hub_search as search++ monkeypatch.setattr(search, "unified_search", lambda *args, **kwargs: list(results))+++def test_resolve_short_name_matches_identifier_slug(monkeypatch):+ """A catalog row whose title is prettified ("Blender Bpy Enhanced") still resolves when the+ user installs the slug the Hub lists — before this, `hermes skills install <slug>` answered+ "No exact match" while printing that very slug as the suggestion."""+ from hermes_cli.skills_hub import _resolve_short_name++ _stub_search(monkeypatch, [_meta("Blender Bpy Enhanced", "@emergencescience/blender-bpy-enhanced")])+ console, sink = _sink_console()++ resolved = _resolve_short_name("blender-bpy-enhanced", [], console)++ assert resolved == "@emergencescience/blender-bpy-enhanced"+ assert "No exact match" not in sink.getvalue()+++def test_resolve_short_name_keeps_display_name_precedence(monkeypatch):+ """Display-name matching still decides first: another row merely ending in the same slug must+ not turn a single exact display-name hit into the ambiguous list."""+ from hermes_cli.skills_hub import _resolve_short_name++ _stub_search(monkeypatch, [+ _meta("dream-loop", "official/creative/dream-loop", source="official"),+ _meta("Something Else", "skills-sh/org/repo/dream-loop"),+ ])+ console, sink = _sink_console()++ assert _resolve_short_name("dream-loop", [], console) == "official/creative/dream-loop"+ assert "Multiple skills" not in sink.getvalue()+++def test_do_install_reports_unresolved_name_as_failure(monkeypatch):+ """An unresolved short name is a real failure (False), not the None no-op."""+ import hermes_cli.skills_hub as cli_hub+ import tools.skills_hub as hub++ class _Source:+ def source_id(self):+ return "clawhub"++ monkeypatch.setattr(hub, "ensure_hub_dirs", lambda: None)+ monkeypatch.setattr(cli_hub, "_sources", lambda: [_Source()])+ monkeypatch.setattr(cli_hub, "_full_identifier", lambda identifier, sources, c: "")+ console, _ = _sink_console()++ assert cli_hub.do_install("no-such-skill", console=console, skip_confirm=True) is False++[email protected]("verdict, expected_exit", [(False, 1), (None, 0)])+def test_skills_command_exit_code_follows_install_verdict(monkeypatch, verdict, expected_exit):+ """`hermes skills install` exits non-zero only on a real failure: the Desktop Hub keys its+ failure toast off the spawned action's exit code, so an exit-0 failure reads as silence."""+ import hermes_cli.skills_hub as cli_hub++ monkeypatch.setattr(cli_hub, "_CLI_ACTIONS", {"install": lambda args: verdict})+ args = type("Args", (), {"skills_action": "install"})()++ if expected_exit:+ with pytest.raises(SystemExit) as excinfo:+ cli_hub.skills_command(args)+ assert excinfo.value.code == expected_exit+ else:+ cli_hub.skills_command(args)