类 SkillFileSystemHelper
java.lang.Object
io.agentscope.core.skill.util.SkillFileSystemHelper
Utility class for file system operations related to skills.
This class provides reusable operations for loading, listing, saving, and deleting skills on the file system. It is designed to be shared by multiple repositories such as file system and Git based repositories.
-
方法概要
修饰符和类型方法说明static voiddeleteDirectory(Path directory) Recursively deletes a directory and all its contents.static booleandeleteSkill(Path baseDir, String skillName) Deletes a skill by name based on SKILL.md metadata.getAllSkillNames(Path baseDir) Retrieves all skill names by parsing SKILL.md metadata in each skill folder.static List<AgentSkill> getAllSkills(Path baseDir, String source) Retrieves all skills from the base directory.static booleanhasSkillFile(Path dir) Checks if a directory contains a SKILL.md file.static AgentSkillLoads a skill by name from the given base directory.static AgentSkillloadSkillFromDirectory(Path skillDir, String source) Loads a skill from a specific directory.static ThreadregisterTempDirectoryCleanup(Path directory) Registers a shutdown hook to delete the given directory on JVM exit.static booleansaveSkills(Path baseDir, List<AgentSkill> skills, boolean force) Saves skills to the base directory.static booleanskillExists(Path baseDir, String skillName) Checks whether a skill exists by scanning SKILL.md metadata.static PathvalidateAndResolvePath(Path baseDir, String skillName) Validates that a resolved path is within the base directory.
-
方法详细资料
-
loadSkill
Loads a skill by name from the given base directory.- 参数:
baseDir- The base directory containing skill foldersskillName- The skill name to loadsource- The source identifier for the created skill- 返回:
- The loaded AgentSkill
- 抛出:
IllegalArgumentException- if the skill cannot be found or is invalid
-
loadSkillFromDirectory
Loads a skill from a specific directory.- 参数:
skillDir- The directory containing SKILL.mdsource- The source identifier for the created skill- 返回:
- The loaded AgentSkill
- 抛出:
IllegalArgumentException- if SKILL.md is missing or invalid
-
getAllSkillNames
Retrieves all skill names by parsing SKILL.md metadata in each skill folder.- 参数:
baseDir- The base directory containing skill folders- 返回:
- A list of skill names sorted alphabetically
-
getAllSkills
Retrieves all skills from the base directory.- 参数:
baseDir- The base directory containing skill folderssource- The source identifier for created skills- 返回:
- A list of skills
-
saveSkills
Saves skills to the base directory.- 参数:
baseDir- The base directory to save skillsskills- The skills to saveforce- Whether to overwrite existing skills- 返回:
- true if all skills were saved, false otherwise
-
deleteSkill
Deletes a skill by name based on SKILL.md metadata.- 参数:
baseDir- The base directory containing skill foldersskillName- The skill name to delete- 返回:
- true if deleted, false if not found
-
skillExists
Checks whether a skill exists by scanning SKILL.md metadata.- 参数:
baseDir- The base directory containing skill foldersskillName- The skill name to check- 返回:
- true if a matching skill exists
-
validateAndResolvePath
Validates that a resolved path is within the base directory.- 参数:
baseDir- The base directory to constrain resolutionskillName- The skill name to resolve- 返回:
- The validated absolute path
- 抛出:
IllegalArgumentException- if the path escapes the base directory
-
hasSkillFile
Checks if a directory contains a SKILL.md file.- 参数:
dir- The directory to check- 返回:
- true if SKILL.md exists in the directory
-
deleteDirectory
Recursively deletes a directory and all its contents.- 参数:
directory- The directory to delete- 抛出:
IOException- if deletion fails
-
registerTempDirectoryCleanup
Registers a shutdown hook to delete the given directory on JVM exit.- 参数:
directory- The directory to delete at shutdown
-