-
Notifications
You must be signed in to change notification settings - Fork 66
CM-71972: Collect Claude Code skills in the Guardrails session sweep #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Altruistus
merged 6 commits into
main
from
CM-71972-be-implement-skills-gathering-using-cli
Sep 7, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ad495ca
CM-71972: Collect Claude Code skills in the Guardrails session sweep
Altruistus 7b4a87f
CM-71972: Collect plugin skills for every IDE, not just Claude Code
Altruistus 8d1595f
CM-71972: Resolve the skills directory at call time, not at import
Altruistus aae1c18
CM-71972: Patch home with a plain function in the regression test
Altruistus ad02e57
CM-71972: Collect user-scope skills for every IDE, not just Claude Code
Altruistus 1e1b7ca
CM-71972: Name the home fixture without the underscore prefix
Altruistus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| """Shared skill-collection helpers for IDE integrations. | ||
|
|
||
| A skill is a directory holding a ``SKILL.md``: ``<skills root>/<skill name>/SKILL.md``. | ||
| The same layout is used for user-scope skills (``~/.claude/skills/``) and for the skills a | ||
| plugin ships (``<plugin dir>/skills/``), so one walker serves both. | ||
|
|
||
| Unlike an MCP config - a small JSON file at a known path - a ``SKILL.md`` body is unbounded | ||
| prose, and the number of installed skills is unbounded too. Both are capped here rather than | ||
| downstream: the whole session-context report is one request, so an oversized skill would cost | ||
| the device its MCP inventory as well. | ||
| """ | ||
|
|
||
| from pathlib import Path | ||
| from typing import Optional | ||
|
|
||
| from cycode.logger import get_logger | ||
|
|
||
| logger = get_logger('AI Guardrails Skills') | ||
|
|
||
| SKILL_FILE_NAME = 'SKILL.md' | ||
|
|
||
| # Where a plugin keeps its skills, relative to the plugin directory. A property of the plugin format | ||
| # rather than of any one IDE, so Claude Code, Codex and Copilot plugins all use it. | ||
| PLUGIN_SKILLS_SUBDIR = 'skills' | ||
|
|
||
| # A skill is instructions, not data. Anything larger is not a skill we can usefully inventory, | ||
| # and sending it would push the one-request report toward the API's body limit. | ||
| MAX_SKILL_FILE_BYTES = 256 * 1024 | ||
|
|
||
| # Per skills root, not per device: a developer with more installed skills than this in one place | ||
| # is an outlier we would rather truncate than let define the payload size. | ||
| MAX_SKILLS_PER_ROOT = 200 | ||
|
|
||
|
|
||
| def _read_skill_file(skill_file: Path) -> Optional[dict]: | ||
| """Read one ``SKILL.md`` into the session-context file shape, or None if unusable.""" | ||
| try: | ||
| size = skill_file.stat().st_size | ||
| except OSError as e: | ||
| logger.debug('Failed to stat skill file, %s', {'path': str(skill_file)}, exc_info=e) | ||
| return None | ||
|
|
||
| if size > MAX_SKILL_FILE_BYTES: | ||
| logger.debug( | ||
| 'Skill file exceeds the size cap; skipping, %s', | ||
| {'path': str(skill_file), 'size': size, 'cap': MAX_SKILL_FILE_BYTES}, | ||
| ) | ||
| return None | ||
|
|
||
| try: | ||
| content = skill_file.read_text(encoding='utf-8') | ||
| except Exception as e: | ||
| logger.debug('Failed to read skill file, %s', {'path': str(skill_file)}, exc_info=e) | ||
| return None | ||
|
|
||
| if not content.strip(): | ||
| return None | ||
|
|
||
| return {'path': str(skill_file), 'content': content} | ||
|
|
||
|
|
||
| def walk_skill_dirs(skills_root: Path) -> list[dict]: | ||
| """Collect every ``<skills_root>/<name>/SKILL.md`` as ``{"path", "content"}``. | ||
|
|
||
| Exactly one directory level is scanned. A skill directory may hold nested references and | ||
| scripts, but its ``SKILL.md`` always sits at the top of it, so there is nothing to recurse | ||
| into - which is also what keeps this bounded without a depth cap. | ||
|
|
||
| Results are sorted by path: the session-context report is deduplicated by hashing the whole | ||
| payload, so an unstable order would re-send an unchanged inventory. | ||
| """ | ||
| if not skills_root.is_dir(): | ||
| return [] | ||
|
|
||
| try: | ||
| skill_dirs = sorted(d for d in skills_root.iterdir() if d.is_dir()) | ||
| except OSError as e: | ||
| logger.debug('Failed to list skills root, %s', {'path': str(skills_root)}, exc_info=e) | ||
| return [] | ||
|
|
||
| skills: list[dict] = [] | ||
| for skill_dir in skill_dirs: | ||
| if len(skills) >= MAX_SKILLS_PER_ROOT: | ||
| logger.debug( | ||
| 'Skills root exceeds the count cap; truncating, %s', | ||
| {'path': str(skills_root), 'cap': MAX_SKILLS_PER_ROOT}, | ||
| ) | ||
| break | ||
|
|
||
| skill = _read_skill_file(skill_dir / SKILL_FILE_NAME) | ||
| if skill: | ||
| skills.append(skill) | ||
|
|
||
| return skills | ||
|
|
||
|
|
||
| def walk_plugin_skills(plugin_dir: Path) -> list[dict]: | ||
| """Collect the skills a plugin ships, from ``<plugin_dir>/skills/<name>/SKILL.md``. | ||
|
|
||
| Shared by every IDE with a plugin system: the layout belongs to the plugin format, so a plugin | ||
| shipping skills is inventoried whichever IDE loaded it. | ||
| """ | ||
| return walk_skill_dirs(plugin_dir / PLUGIN_SKILLS_SUBDIR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.