zensical docs skill

This commit is contained in:
John Lancaster
2026-06-19 00:24:08 -05:00
parent 07475f972f
commit 36abea5940
11 changed files with 164 additions and 44 deletions
+11 -36
View File
@@ -4,7 +4,7 @@ from typing import Any
import yaml
from fastmcp import FastMCP
from personal_mcp.skills.document_loader import load_skill_document
from personal_mcp.skills.document_loader import load_skill_document_from_metadata
catalog_server = FastMCP("catalog")
@@ -59,6 +59,10 @@ def _matches_query(pattern: dict[str, Any], query: str) -> bool:
if not lowered:
return True
query_terms = [term for term in lowered.replace("-", " ").split() if term]
if not query_terms:
return True
haystack = " ".join(
[
str(pattern.get("id", "")),
@@ -68,7 +72,7 @@ def _matches_query(pattern: dict[str, Any], query: str) -> bool:
" ".join(str(tag) for tag in pattern.get("tags", [])),
]
).lower()
return lowered in haystack
return all(term in haystack for term in query_terms)
def _matches_tags(pattern: dict[str, Any], tags: list[str] | None) -> bool:
@@ -83,34 +87,6 @@ def _matches_tags(pattern: dict[str, Any], tags: list[str] | None) -> bool:
return all(tag in pattern_tags for tag in requested)
def _resolve_skill_slug(*, skill_id: str, namespace: str, metadata: dict[str, Any]) -> str:
candidates: list[str] = []
slug = metadata.get("slug")
if isinstance(slug, str) and slug.strip():
candidates.append(slug.strip())
candidates.extend(
[
skill_id,
namespace.replace("_", "-"),
namespace,
]
)
seen: set[str] = set()
for candidate in candidates:
if candidate in seen:
continue
seen.add(candidate)
try:
load_skill_document(skill_id=skill_id, skill_slug=candidate)
return candidate
except FileNotFoundError:
continue
return skill_id
@catalog_server.resource("resource://catalog/skills_index")
def skills_index() -> dict[str, Any]:
"""Return a compact discovery index for all available pattern modules."""
@@ -184,14 +160,13 @@ def get_skill_document_by_id(skill_id: str) -> dict[str, Any]:
if pattern_id != skill_id:
continue
skill_slug = _resolve_skill_slug(
skill_id=skill_id,
namespace=namespace,
metadata=metadata,
)
return {
"found": True,
"document": load_skill_document(skill_id=skill_id, skill_slug=skill_slug),
"document": load_skill_document_from_metadata(
skill_id=skill_id,
namespace=namespace,
metadata=metadata,
),
}
return {"found": False, "id": skill_id}