The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(tools): skills_tool compacts registry blocks, org header assembly, linked-files scan
Teknium1f7e2a8995df
diff --git a/tools/skills_sync.py b/tools/skills_sync.pyindex 1a49452e4b3..90d53eb5d54 100644--- a/tools/skills_sync.py+++ b/tools/skills_sync.py@@ -65,8 +65,8 @@ def _rel_skills_posix(path: Path) -> str:return path.relative_to(_skills_dir()).as_posix()-# Written by `hermes profile create --no-skills` / installer `--no-skills`: sync seeds-# only essential skills. Mirrors hermes_cli.profiles.NO_BUNDLED_SKILLS_MARKER (no CLI import here).+# Written by `hermes profile create --no-skills` / installer `--no-skills`: sync seeds only+# essential skills. Mirrors hermes_cli.profiles.NO_BUNDLED_SKILLS_MARKER (no CLI import here).NO_BUNDLED_SKILLS_MARKER = ".no-bundled-skills"@@ -218,9 +218,8 @@ class _SyncState:suppressed: List[str] = field(default_factory=list)relocated: List[str] = field(default_factory=list)shadowed_by_external: List[str] = field(default_factory=list)- # Rename-recovery indexes are expensive on bind mounts: built lazily, only when needed.- active_index: Optional[Dict[str, List[Path]]] = None- hub_paths: Set[str] = field(default_factory=set)+ active_index: Optional[Dict[str, List[Path]]] = None # rename-recovery indexes are expensive on+ hub_paths: Set[str] = field(default_factory=set) # bind mounts: built lazily, only when neededdef say(self, msg: str) -> None:if not self.quiet:@@ -228,8 +227,8 @@ class _SyncState:def _recover_orphan_backup(dest: Path) -> None:- """If an interrupted update left the user's only copy in ``dest.bak`` with- dest gone, move it back so the skill isn't misread as user-deleted."""+ """If an interrupted update left the user's only copy in ``dest.bak`` with dest gone, move it+ back so the skill isn't misread as user-deleted."""orphan = dest.with_suffix(".bak")if not orphan.exists() or dest.exists():return@@ -277,8 +276,7 @@ def _install_new_skill(st: _SyncState, skill_name: str, skill_src: Path, dest: Pdef _replace_skill_dir(skill_src: Path, dest: Path) -> None:- """Replace ``dest`` with a fresh copy of ``skill_src`` via a ``.bak`` sibling,- restoring the original on failure."""+ """Replace ``dest`` with a fresh copy of ``skill_src`` via a ``.bak`` sibling, restoring on failure."""backup = dest.with_suffix(".bak")if backup.exists(): # a stale .bak would make shutil.move() nest dest INSIDE it_rmtree_writable(backup)diff --git a/tools/skills_tool.py b/tools/skills_tool.pyindex bc43764562a..57875596be9 100644--- a/tools/skills_tool.py+++ b/tools/skills_tool.py@@ -59,8 +59,7 @@ def _skills_scan_signature(dirs_to_scan, disabled) -> tuple:return (tuple(sig), frozenset(disabled), getattr(getattr(_skill_utils, "sys", None), "platform", ""))-# All skills live in ~/.hermes/skills/ (seeded from bundled skills/ on install).-HERMES_HOME = get_hermes_home()+HERMES_HOME = get_hermes_home() # all skills live in ~/.hermes/skills/ (seeded from bundled skills/)SKILLS_DIR = HERMES_HOME / "skills"_SKILLS_DIR_AT_IMPORT = SKILLS_DIR@@ -277,8 +276,6 @@ def skills_list(category: str = None, task_id: str = None) -> str:return tool_error(str(e), success=False)-# ── skill_view helpers ─────────────────────────────────────────────────────-def _resolve_plugin_skill(name, file_path, task_id, preprocess):"""``plugin:skill`` dispatch: ``(result_json, None)`` when answered, else ``(None,local_category_name)`` to fall through to the flat-tree scan — categorized local skills@@ -386,12 +383,9 @@ def _skill_linked_files(skill_dir: Optional[Path]) -> dict:files: dict = {}for sub, globs, recursive, files_only in _LINKED_FILE_SPECS if skill_dir else ():base = skill_dir / sub- if not base.exists():- continuefound = [- str(f.relative_to(skill_dir))- for g in globs for f in (base.rglob(g) if recursive else base.glob(g))- if not files_only or f.is_file()]+ str(f.relative_to(skill_dir)) for g in globs if base.exists()+ for f in (base.rglob(g) if recursive else base.glob(g)) if not files_only or f.is_file()]if found:files[sub] = foundreturn files@@ -404,12 +398,13 @@ def _org_provenance_header(skill_dir: Path, active_skills_dir: Path):if not is_org_mirror_path(skill_dir, active_skills_dir):return None, ""prov_org = org_id_of_path(skill_dir, active_skills_dir)- author = ts = ""+ prov: dict = {}if prov_org:with suppress(Exception):- prov = json.loads(_read_skill_text(active_skills_dir / "_org" / prov_org / ORG_PROVENANCE_FILE))- author = str(prov.get("author_device") or prov.get("author_user_id") or "")- ts = str(prov.get("ts") or "")+ loaded = json.loads(_read_skill_text(active_skills_dir / "_org" / prov_org / ORG_PROVENANCE_FILE))+ prov = loaded if isinstance(loaded, dict) else {}+ author = str(prov.get("author_device") or prov.get("author_user_id") or "")+ ts = str(prov.get("ts") or "")header = ("> [!NOTE] ORG-SHARED SKILL — provenance\n"f"> This skill is shared by your organisation (org `{prov_org}`"@@ -585,16 +580,15 @@ def skill_view(readiness, readiness_extras = _skill_readiness(frontmatter, skill_name)rendered_content = content if not preprocess else _preprocess_skill(content, skill_dir, task_id, "Could not preprocess skill content for %s", skill_name)- org_provenance = None+ org_provenance, header = None, ""if skill_dir:try:org_provenance, header = _org_provenance_header(skill_dir, active_skills_dir)- rendered_content = header + rendered_contentexcept Exception:logger.debug("Could not resolve org provenance for %s", skill_name, exc_info=True)result = {"success": True, "name": skill_name, "description": frontmatter.get("description", ""),- "tags": tags, "related_skills": related_skills, "content": rendered_content, "path": rel_path,+ "tags": tags, "related_skills": related_skills, "content": header + rendered_content, "path": rel_path,"skill_dir": str(skill_dir) if skill_dir else None, "org_provenance": org_provenance,"linked_files": linked_files if linked_files else None,"usage_hint": "To view linked files, call skill_view(name, file_path) where file_path is e.g. 'references/api.md' or 'assets/config.yaml'" if linked_files else None,@@ -603,8 +597,7 @@ def skill_view("_source_path": str(skill_md),**readiness_extras}_mark_background_review_read(skill_md)- # agentskills.io optional fields- if frontmatter.get("compatibility"):+ if frontmatter.get("compatibility"): # agentskills.io optional fieldsresult["compatibility"] = frontmatter["compatibility"]if isinstance(metadata, dict):result["metadata"] = metadata@@ -613,8 +606,6 @@ def skill_view(return tool_error(str(e), success=False)-# ── Registry ────────────────────────────────────────────────────────────────-SKILLS_LIST_SCHEMA = {"name": "skills_list","description": "List available skills (name + description). Use skill_view(name) to load full content.",@@ -650,12 +641,9 @@ SKILL_VIEW_SCHEMA = {}registry.register(- name="skills_list",- toolset="skills",- schema=SKILLS_LIST_SCHEMA,+ name="skills_list", toolset="skills", schema=SKILLS_LIST_SCHEMA,handler=lambda args, **kw: skills_list(category=args.get("category"), task_id=kw.get("task_id")),- check_fn=check_skills_requirements,- emoji="📚")+ check_fn=check_skills_requirements, emoji="📚")def _skill_view_with_bump(args, **kw):@@ -681,9 +669,5 @@ def _skill_view_with_bump(args, **kw):registry.register(- name="skill_view",- toolset="skills",- schema=SKILL_VIEW_SCHEMA,- handler=_skill_view_with_bump,- check_fn=check_skills_requirements,- emoji="📚")+ name="skill_view", toolset="skills", schema=SKILL_VIEW_SCHEMA, handler=_skill_view_with_bump,+ check_fn=check_skills_requirements, emoji="📚")