started manual refactor

This commit is contained in:
John Lancaster
2026-06-21 09:13:30 -05:00
parent 197fa32f2c
commit dab539489a
24 changed files with 999 additions and 1235 deletions
+43
View File
@@ -0,0 +1,43 @@
from collections.abc import Generator
from dataclasses import dataclass
from fnmatch import fnmatch
from functools import partial
from itertools import groupby
def get_skill_filemap(content: dict[str, str]) -> dict[str, list[str]]:
"""Get the map of skill slugs to their associated files."""
def get_skill_name(relpath: str) -> str | None:
if relpath.startswith("skills/"):
return relpath.split("/")[1]
grouped = groupby(content.keys(), key=get_skill_name)
return {k: list(v) for k, v in grouped if k is not None}
@dataclass(frozen=True, slots=True)
class SkillBundle:
slug: str
skill: str
references: list[str]
other: list[str]
def gen_skill_bundles(content: dict[str, str]) -> Generator[SkillBundle]:
"""Generate the skill bundles from the map of raw markdown content."""
matcher = partial(fnmatch, pat="skills/*/references/*.md")
for slug, paths in get_skill_filemap(content).items():
skill = next(iter(p for p in paths if fnmatch(p, "skills/*/SKILL.md")))
groups = {k: list(v) for k, v in groupby(paths, key=matcher)}
yield SkillBundle(
slug=slug,
skill=skill,
references=list(groups.get(True, [])),
other=[f for f in groups.get(False, []) if f != skill],
)
def get_all_skill_bundles(content: dict[str, str]) -> list[SkillBundle]:
"""Get all skill bundles from the map of raw markdown content."""
return list(gen_skill_bundles(content))