Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,18 @@ private static Map<String, String> loadResources(Path skillDir, Path skillFile)
try (Stream<Path> paths = Files.walk(skillDir)) {
paths.filter(Files::isRegularFile)
.filter(p -> !p.equals(skillFile))
.filter(
p -> {
if (p.getFileName().toString().startsWith(".")) {
return false;
}
try {
return !Files.isHidden(p) && Files.isReadable(p);
} catch (IOException e) {
logger.warn("Failed to check attributes for file: {}", p, e);
return false;
}
})
.forEach(
p -> {
String relativePath =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,38 @@ void testSaveSkills_DecodesBase64ToBinary() throws IOException {
assertEquals("plain text", Files.readString(savedText, StandardCharsets.UTF_8));
}

@Test
@DisplayName(
"Should filter out hidden files and files starting with dot when loading resources")
void testLoadResources_FiltersHiddenFiles() throws IOException {
createSampleSkill("hidden-test-skill", "Test Hidden Files", "Test content");
Path skillDir = skillsBaseDir.resolve("hidden-test-skill");

Path normalFile = skillDir.resolve("normal_resource.txt");
Files.writeString(normalFile, "normal content", StandardCharsets.UTF_8);

Path hiddenFile = skillDir.resolve(".DS_Store");
Files.writeString(hiddenFile, "hidden garbage data", StandardCharsets.UTF_8);

// Attempt to set DOS hidden attribute for strict Windows environments
// (Wrap in try-catch because Linux/macOS might throw UnsupportedOperationException)
try {
Files.setAttribute(hiddenFile, "dos:hidden", true);
} catch (UnsupportedOperationException | IllegalArgumentException e) {
}

AgentSkill skill =
SkillFileSystemHelper.loadSkill(skillsBaseDir, "hidden-test-skill", "test-source");

assertNotNull(skill);
Map<String, String> resources = skill.getResources();

assertTrue(resources.containsKey("normal_resource.txt"), "Normal file should be loaded");
assertEquals("normal content", resources.get("normal_resource.txt"));

assertFalse(resources.containsKey(".DS_Store"), "Hidden file should be filtered out");
}

private void createSampleSkill(String name, String description, String content)
throws IOException {
Path skillDir = skillsBaseDir.resolve(name);
Expand Down
Loading