Repository navigation
feat(skill): supports baseDir being treated as a single skill directory #1824
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
f52607f
409fae0
1ecbe6a
91013e1
6c62b0d
78acb24
9851351
cd0adc8
5d7b2f0
521c512
e537acc
75b43da
bb25982
89b6cd3
d0561e9
62e787e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,10 +126,22 @@ public static AgentSkill loadSkillFromDirectory( | |
| /** | ||
| * Retrieves all skill names by parsing SKILL.md metadata in each skill folder. | ||
| * | ||
| * <p>If {@code baseDir} itself contains a {@code SKILL.md} file, it is treated as a single | ||
| * skill directory and only that skill's name is returned. Otherwise, subdirectories are | ||
| * scanned for skills. | ||
| * | ||
| * @param baseDir The base directory containing skill folders | ||
| * @return A list of skill names sorted alphabetically | ||
| */ | ||
| public static List<String> getAllSkillNames(Path baseDir) { | ||
| // If baseDir itself is a skill directory, return only that skill | ||
| if (hasSkillFile(baseDir)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Root vs container mode is inferred from Two consequences of inferring rather than configuring:
A |
||
| List<String> names = new ArrayList<>(); | ||
| readSkillName(baseDir).ifPresent(names::add); | ||
| names.sort(String::compareTo); | ||
| return names; | ||
| } | ||
|
|
||
| List<String> skillNames = new ArrayList<>(); | ||
|
|
||
| try (Stream<Path> subdirs = Files.list(baseDir)) { | ||
|
|
@@ -160,6 +172,10 @@ public static List<AgentSkill> getAllSkills(Path baseDir, String source) { | |
| /** | ||
| * Retrieves all skills from the base directory. | ||
| * | ||
| * <p>If {@code baseDir} itself contains a {@code SKILL.md} file, it is treated as a single | ||
| * skill directory and only that skill is returned. Otherwise, subdirectories are scanned for | ||
| * skills. | ||
| * | ||
| * @param baseDir The base directory containing skill folders | ||
| * @param source The source identifier for created skills | ||
| * @param includeResources when {@code false}, each skill's resource map is left empty and | ||
|
|
@@ -168,6 +184,17 @@ public static List<AgentSkill> getAllSkills(Path baseDir, String source) { | |
| */ | ||
| public static List<AgentSkill> getAllSkills( | ||
| Path baseDir, String source, boolean includeResources) { | ||
| // If baseDir itself is a skill directory, return only that skill | ||
| if (hasSkillFile(baseDir)) { | ||
| List<AgentSkill> skills = new ArrayList<>(); | ||
| try { | ||
| skills.add(loadSkillFromDirectory(baseDir, source, includeResources)); | ||
| } catch (Exception e) { | ||
| logger.warn("Failed to load skill from '{}': {}", baseDir, e.getMessage(), e); | ||
| } | ||
| return skills; | ||
| } | ||
|
|
||
| List<AgentSkill> skills = new ArrayList<>(); | ||
|
|
||
| try (Stream<Path> subdirs = Files.list(baseDir)) { | ||
|
|
@@ -463,6 +490,16 @@ private static Optional<Path> findSkillDirectoryByName(Path baseDir, String skil | |
| return Optional.empty(); | ||
| } | ||
|
|
||
| // Check if baseDir itself is the skill | ||
| if (hasSkillFile(baseDir)) { | ||
| String rootName = readSkillName(baseDir).orElse(null); | ||
| if (skillName.equals(rootName)) { | ||
| return Optional.of(baseDir); | ||
| } | ||
| // baseDir is a single skill directory; no subdirectory skills to scan | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| try (Stream<Path> subdirs = Files.list(baseDir)) { | ||
| return subdirs.filter(Files::isDirectory) | ||
| .filter(SkillFileSystemHelper::hasSkillFile) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The root branch is ~35 lines copied from the container loop below (stat → mtime+size compare →
loadSkillFromDirectory(..., !lazy)→skillCache.put), and it returns beforeskillCache.keySet().retainAll(seenDirs)at line 253, so root and container mode handle cache eviction differently. Concretely: a repository that was in container mode accumulates per-skill snapshots, and oncebaseDirgains a rootSKILL.mdthose entries are never pruned again, because every subsequent call takes this early return.Worth also deciding what this branch is meant to return when the root file fails to parse: the container branch skips one bad skill and keeps the others, while this branch yields
List.of()for the whole repository — a defensible choice, but it is the only place a single malformedSKILL.mdblanks the repository, so it should be stated in the javadoc.Extracting the shared body into
private Optional<AgentSkill> loadWithCache(Path dir)used by both branches would remove the copy-paste and the eviction asymmetry in one go.