Repository navigation
Conversation
- If baseDir itself contains SKILL.md, only the skill information of this directory will be returned. - Modify the getAllSkillNames method to support root directory skill recognition - Modify the getAllSkills method to support root directory skill loading - Modify loadSkill method to support root directory skill name matching check - Modify the skillExists method to support root directory skill existence judgment - Add unit tests to cover the new root directory skill processing logic - Unit tests verify the correct name, loading and existence of root skills
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR adds support for treating baseDir itself as a single skill directory when it contains a SKILL.md file. The changes cover getAllSkillNames, getAllSkills, loadSkill (via findSkillDirectoryByName), and skillExists. Unit tests are included. However, there is a critical consistency defect: findSkillDirectoryByName does not early-return when baseDir has SKILL.md but the name doesn't match — it falls through to scan subdirectories, contradicting getAllSkillNames/getAllSkills which short-circuit in that case. Additionally, deleteSkill could accidentally delete the entire baseDir if the root-level skill name matches.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR adds support for treating baseDir itself as a single skill directory when it contains a SKILL.md file. The changes cover getAllSkillNames, getAllSkills, loadSkill (via findSkillDirectoryByName), and skillExists. Unit tests are included. However, there is a critical consistency defect: findSkillDirectoryByName does not early-return when baseDir has SKILL.md but the name doesn't match — it falls through to scan subdirectories, contradicting getAllSkillNames/getAllSkills which short-circuit in that case. Additionally, deleteSkill could accidentally delete the entire baseDir if the root-level skill name matches.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
|
Thanks for the review! Issue 1 — findSkillDirectoryByName consistency (fixed ✅) Issue 2 — deleteSkill might delete entire baseDir |
|
@chickenlj Hello, please help to see if this PR is reasonable? |
|
Is there anyone? |
Thanks for your contribution. I'm really sorry, there are quite a few PRs and heavy review tasks. I'll take a look later. |
jujn
left a comment
There was a problem hiding this comment.
FileSystemSkillRepository # getAllSkills() still only scans subdirectories, so a single-skill repository with SKILL.md directly under baseDir is still invisible on the main runtime path.
|
Thanks for the review! I've fixed Commit: 9851351 |
|
My PR didn't make it into RC5. 😭 |
| public static boolean deleteSkill(Path baseDir, String skillName) { | ||
| Optional<Path> skillDir = findSkillDirectoryByName(baseDir, skillName); | ||
| if (skillDir.isEmpty()) { | ||
| logger.warn("Skill directory does not exist: {}", skillName); |
There was a problem hiding this comment.
deleteSkill() reuse findSkillDirectoryByName().
If the deleteSkill method is triggered subsequently, and the passed in skill name exactly matches the name of the root directory, the entire baseDir directory will be deleted directly.
It is recommended to specially handle the root level skill in deleteSkill().
Maybe in 2.0 GA. ❤ |
|
@jujn Thanks for the review! Regarding the deleteSkill issue with root-level skills: When
This avoids accidentally deleting the entire repository root while still properly removing the skill. Does this approach look reasonable to you? |
Can we just delete skill.md? Because other files are equally important to users |
| deleteDirectory(skillDir.get()); | ||
| if (dirToDelete.equals(absoluteBaseDir)) { | ||
| // Root-level skill: only remove SKILL.md, keep other files intact | ||
| Files.delete(dirToDelete.resolve(SKILL_FILE_NAME)); |
There was a problem hiding this comment.
Suggest: Files.deleteIfExists
| return false; | ||
| } | ||
|
|
||
| Path dirToDelete = skillDir.get(); |
There was a problem hiding this comment.
Suggest: skillDir.get().toAbsolutePath().normalize();
|
@jujn Thanks for the review! I've updated the PR with the fix. |
| return false; | ||
| } | ||
|
|
||
| boolean ok = SkillFileSystemHelper.saveSkills(baseDir, skills, force); |
There was a problem hiding this comment.
Here call SkillFileSystemHelper.saveSkills. For a single skill warehouse such as baseDir/SKILL.md, success is returned, but it is actually written to baseDir/skillName/SKILL.md.
|
@jujn PR updated with saveSkills root-level skill handling and a potential null pointer fix in resource writing path. |
| boolean isRootSkill = | ||
| hasSkillFile(baseDir) | ||
| && skillName.equals(readSkillName(baseDir).orElse(null)); |
There was a problem hiding this comment.
When the saved skill name does not match the existing root skill.md name. A success will still be returned and written to the subdirectory, but the skill will not be visible later.
|
让 ai 帮忙多检查下吧,我刚看了下还有一些问题。我们必须要对用户负责 |
ok |
| * @param force Whether to overwrite existing skills | ||
| * @return true if all skills were saved, false otherwise | ||
| */ | ||
| public static boolean saveSkills(Path baseDir, List<AgentSkill> skills, boolean force) { |
There was a problem hiding this comment.
The root-level force=true save path is still destructive. When baseDir/SKILL.md exists, this branch walks baseDir and deletes every child before writing the new skill. For a single-skill repository, baseDir is also the repository root, so this can delete unrelated files, or any file that is not owned by the skill.
There was a problem hiding this comment.
@jujn The specification clearly states: a skill is a directory that must contain at least SKILL.md, optionally includes standard subdirectories such as scripts/, references/, assets/, as well as any other files or directories. In other words, everything under the skill directory belongs to that skill — there is no distinction between "skill files vs. user-irrelevant files." The entire directory serves as the carrier of the skill, making it difficult to determine whether a particular file should or should not belong to the skill.
There was a problem hiding this comment.
@jujn The specification clearly states: a skill is a directory that must contain at least SKILL.md, optionally includes standard subdirectories such as scripts/, references/, assets/, as well as any other files or directories. In other words, everything under the skill directory belongs to that skill — there is no distinction between "skill files vs. user-irrelevant files." The entire directory serves as the carrier of the skill, making it difficult to determine whether a particular file should or should not belong to the skill.
I respect your opinion. But let me remind you: you never know what users will do locally
There was a problem hiding this comment.
@jujn Can I proceed with the previously discussed approach of removing the root directory? This shouldn’t break any existing code—after all, single-skill support inside Git repositories isn’t implemented yet. If this works for you, I’ll submit the code.
| * @param force Whether to overwrite existing skills | ||
| * @return true if all skills were saved, false otherwise | ||
| */ | ||
| public static boolean saveSkills(Path baseDir, List<AgentSkill> skills, boolean force) { |
There was a problem hiding this comment.
saveSkills() still accepts multiple skills for a root-level repository, but a root-level repository can only expose one skill. With force=true, the loop will overwrite baseDir/SKILL.md once per input skill and return success for the whole list, while only the last skill remains visible through getAllSkills()/getSkill(). That makes the return value misleading and silently drops earlier saved skills.
There was a problem hiding this comment.
@jujn Strict validation + throw exception: when the root directory scenario occurs and skills.size() > 1, directly throw an IllegalArgumentException("Root-level skill repository can only contain one skill"). This is the cleanest approach and is consistent with the style of loadSkill/AgentSkill constructors throwing exceptions for illegal parameters. Does this seem reasonable?
There was a problem hiding this comment.
@jujn Strict validation + throw exception: when the root directory scenario occurs and skills.size() > 1, directly throw an IllegalArgumentException("Root-level skill repository can only contain one skill"). This is the cleanest approach and is consistent with the style of loadSkill/AgentSkill constructors throwing exceptions for illegal parameters. Does this seem reasonable?
It looks fine
|
@chickenlj @jujn Single-directory skills (where baseDir itself serves as a skill repository) are a widely used and essential scenario. Could you please share your thoughts on how we should proceed with this PR? Any guidance on further modifications would be greatly appreciated. |
There was a problem hiding this comment.
Summary
Lets baseDir itself be a single skill directory (contains SKILL.md) instead of a container of skill subdirectories, across getAllSkillNames, getAllSkills, loadSkill, skillExists, saveSkills and deleteSkill, plus 14 new tests. The read side is careful and the two defects raised in the earlier review thread are genuinely fixed — findSkillDirectoryByName now short-circuits (SkillFileSystemHelper.java:538-545) so a root skill can't be shadowed by subdirectories, and deleteSkill deletes only SKILL.md (:349). @jujn's ask of "let AI check it once more, there are still some problems" is fair: the write side is where the remaining problems are.
Two data-integrity problems stand out (this review is submitted as a comment, not a formal changes-requested — the review state is @jujn's to decide):
- [Critical] With
force=true, the root branch deletes every entry underbaseDir, not the previous skill's files (:256-270).baseDiris caller-supplied — a checked-out repo, a mounted workspace, a directory holding READMEs,.gitor other skills' subdirectories — and all of it is gone beforeSKILL.mdis rewritten. The container branch is much narrower: it deletes onlyvalidateAndResolvePath(baseDir, skillName). A mid-walkFiles.deletefailure also throws out of theforEach, leaving the directory half-emptied with nothing written back. - [Critical] The root branch never uses
skill.getName()and never callsvalidateAndResolvePath, so the mode check (hasSkillFile(baseDir)) is re-evaluated per skill inside the loop:saveSkills(rootDir, List.of(a, b), true)writesa, then iterationbwipesa'sSKILL.mdand resources and writes itself, andallSavedstill returnstruebecause both iterations incrementedsaveCount. Withforce=falsethe same call silently saves one of two and returnsfalse. A root-mode repository can hold exactly one skill, so the call needs a size/name guard rather than an implicit last-writer-wins.
Also flagged, inline: resource keys are still resolved with skillDir.resolve(entry.getKey()) and no containment check (:300), which matters more now that skillDir is the user's baseDir; the mode is inferred from the filesystem rather than configured, so a stray SKILL.md at the root of an existing container repository hides every sub-skill with no warning, and the two code paths use different predicates (hasSkillFile — a Files.walk(dir, 1) that also matches a directory named SKILL.md — vs Files.exists); FileSystemSkillRepository's new branch copies ~35 lines of the cache body, returns before skillCache.keySet().retainAll(seenDirs) (:253) so container-mode snapshots stop being pruned while root mode is active, and turns one bad root SKILL.md into an empty repository instead of skipping just that skill.
Suggested shape: resolve the mode once per operation behind an explicit singleSkillDirectory opt-in (or auto-detect only when no subdirectory contains a SKILL.md, and warn when both exist), share one isRootSkillDir(Path) predicate everywhere, scope the force cleanup to the previous skill's SKILL.md + its recorded resource keys, reject root-mode saves of more than one skill or a name mismatch, and extract the mtime+size cache lookup so the two branches cannot drift. The new tests are a good base — the three I'd add first are saveSkills(root, List.of(a, b), true), a mixed root+sub layout, and a .. resource key.
CLA is signed and CI is green; mergeable_state is blocked pending maintainer review. No merge action taken.
Automated review by github-manager-bot
| Path skillDir; | ||
| Path skillFile; | ||
| // Root-level skill: baseDir itself contains SKILL.md | ||
| if (hasSkillFile(baseDir)) { |
There was a problem hiding this comment.
The mode is re-decided inside the for (AgentSkill skill : skills) loop. When baseDir itself is the skill, every iteration resolves to the same baseDir/SKILL.md, so a batch save destroys all but the last skill:
Path root = ...; // root/SKILL.md exists (name = "A")
saveSkills(root, List.of(skillA, skillB), true);
// iter A: hasSkillFile(root) -> skillFile exists -> walk root, delete everything -> write A
// iter B: hasSkillFile(root) -> skillFile exists -> walk root, delete everything (incl. A)
// -> write B
// returns allSaved == true; A's SKILL.md and resources are gone silentlyWith force=false the second skill hits continue at line 250, so saveCount != size and the method returns false — the first skill was still written, and the caller cannot tell which one failed.
Since a root-level repository can hold exactly one skill by definition, the guard belongs above the loop: if hasSkillFile(baseDir) and skills.size() > 1, throw IllegalArgumentException (or fall back to the subdirectory layout) instead of letting iterations overwrite each other.
| continue; | ||
| } else { | ||
| logger.info("Overwriting existing root skill: {}", skillName); | ||
| // Delete all contents except baseDir itself |
There was a problem hiding this comment.
force=true in the root branch deletes the entire content of baseDir, not the files this skill owns:
try (Stream<Path> paths = Files.walk(skillDir)) { // skillDir == baseDir here
paths.sorted(Comparator.reverseOrder())
.filter(path -> !path.equals(skillDir))
.forEach(path -> Files.delete(path));
}baseDir is supplied by the embedding application — a skills directory under a user's workspace, a mounted repo root, a directory someone also keeps READMEs, dotfiles or an existing sub/SKILL.md in. The subdirectory branch is scoped to validateAndResolvePath(baseDir, skillName) and only ever deletes that one skill folder; the root branch has no such bound. If a Files.delete fails partway (permission, read-only file), the RuntimeException at line 262 leaves baseDir half-emptied, and the caller has no way to recover.
Could the cleanup be limited to what the previous root skill actually owned — its SKILL.md plus the resource keys recorded for that skill (mirroring SkillFileSystemHelper.loadResources) — with a hard refusal to delete any path outside that set? And a log line per deleted path so a half-emptied directory is diagnosable after the fact.
| skillDir = baseDir.toAbsolutePath().normalize(); | ||
| skillFile = skillDir.resolve(SKILL_FILE_NAME); | ||
| if (Files.exists(skillFile)) { | ||
| if (!force) { |
There was a problem hiding this comment.
The root branch never validates or even uses skillName, which drops two guarantees the subdirectory branch relies on:
validateAndResolvePath(line 383) normalizes the name and rejects..escapes. Nothing equivalent runs here, so the write target is unconditional.- The name is not compared with the existing root skill's name. Saving a skill called
otherinto a repository whose rootSKILL.mdis namedAoverwritesA's content; the file's front matter then saysother,getAllSkillNamesreturns["other"], and every consumer that cachedA(skill caches, sub-agent skill references) silently resolves to different content.loadSkillis strict about this exact mismatch —testLoadSkill_RootLevelSkillNameMismatchassertsIllegalArgumentException— sosaveSkillsbeing permissive is inconsistent with the read path.
Comparing skillName with readSkillName(baseDir) and rejecting a mismatch (or writing the skill into a subdirectory instead) would line the two paths up.
| */ | ||
| public static List<String> getAllSkillNames(Path baseDir) { | ||
| // If baseDir itself is a skill directory, return only that skill | ||
| if (hasSkillFile(baseDir)) { |
There was a problem hiding this comment.
Root vs container mode is inferred from hasSkillFile(baseDir) on every call, and hasSkillFile (line 407) is Files.walk(dir, 1).anyMatch(name equals "SKILL.md") — it also returns true for a directory named SKILL.md, and it costs a directory listing instead of one Files.isRegularFile(baseDir.resolve("SKILL.md")) stat. FileSystemSkillRepository.getAllSkills() uses Files.exists(baseDir/SKILL.md) for the same decision, so the two implementations infer the mode slightly differently.
Two consequences of inferring rather than configuring:
- An existing container-mode repository that gains a
SKILL.mdat its root (easy to do by accident — a saved skill, a doc file) instantly hides all of its sub-skills, with no warning. - After
deleteSkillremoves the rootSKILL.md, the mode flips back to container, and any leftover resource subdirectory that happens to contain aSKILL.mdnow surfaces as a skill — i.e. deleted skill data can come back intogetAllSkills().
A singleSkillDirectory flag (explicit opt-in on the repository/helper entry points) plus one shared isRootSkillDir(Path) predicate would make the mode deterministic, cheaper, and consistent with FileSystemSkillRepository. The call count also matters in the save path: hasSkillFile(baseDir) runs once per skill in the list.
| Map<String, String> resources = skill.getResources(); | ||
| for (Map.Entry<String, String> entry : resources.entrySet()) { | ||
| Path resourceFile = skillDir.resolve(entry.getKey()); | ||
| Files.createDirectories(resourceFile.getParent()); |
There was a problem hiding this comment.
Resource keys are still resolved without containment checks — skillDir.resolve(entry.getKey()) accepts .. and absolute paths, so Map.of("../../../../tmp/x", "...") writes outside the skill directory. The same guard the name path already has would fix it:
Path abs = skillDir.toAbsolutePath().normalize();
Path target = abs.resolve(entry.getKey()).normalize();
if (!target.startsWith(abs)) {
throw new IllegalArgumentException("resource path escapes skill directory: " + entry.getKey());
}This pre-dates the PR, but root mode changes the blast radius: skillDir is now the caller's baseDir rather than a per-skill folder, so an escaping key writes next to baseDir instead of next to one skill inside it. Since skills can be loaded from a git repository or an archive (this PR's stated use case is exactly "a skill repo checked out as baseDir"), the resource map is not trusted input.
Small related nit on the same hunk: Files.createDirectories(resourceFile.getParent()) runs before the new content != null check, so a null-content resource now creates an empty directory and writes nothing. Moving the createDirectories inside the null guard keeps the tree clean.
| @Override | ||
| public List<AgentSkill> getAllSkills() { | ||
| // If baseDir itself is a skill directory, return only that skill | ||
| Path baseDirKey = baseDir.toAbsolutePath().normalize(); |
There was a problem hiding this comment.
The root branch is ~35 lines copied from the container loop below (stat → mtime+size compare → loadSkillFromDirectory(..., !lazy) → skillCache.put), and it returns before skillCache.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 once baseDir gains a root SKILL.md those 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 malformed SKILL.md blanks 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.
|
Small correction on the review above: it was submitted as a comment, not a formal changes requested review, so my two [Critical] items shouldn't be read as a blocking review state from this account — the review decision stays with the maintainers (@jujn already has the PR in changes-requested). Flagging them as blocking issues in my analysis is what I meant: the Automated note by github-manager-bot |
Fixes #1790
AgentScope-Java Version
2.0.0-SNAPSHOT
Description
Background
When a skill repository's baseDir itself contains a SKILL.md file, the current implementation does not recognize it as a valid skill directory, requiring users to place SKILL.md in a subdirectory under baseDir.
Changes Made
getAllSkillNames()to support root directory skill recognitiongetAllSkills()to support root directory skill loadingloadSkill()to support root directory skill name matching checkskillExists()to support root directory skill existence judgmentHow to Test
getAllSkills()and verify the root skill is returnedskillExists()with the root skill name and verify it returns trueloadSkill()with the root skill name and verify it loads successfullyChecklist
mvn spotless:applymvn test)