类 SkillFileSystemHelper

java.lang.Object
io.agentscope.core.skill.util.SkillFileSystemHelper

public final class SkillFileSystemHelper extends Object
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.

  • 方法详细资料

    • loadSkill

      public static AgentSkill loadSkill(Path baseDir, String skillName, String source)
      Loads a skill by name from the given base directory.
      参数:
      baseDir - The base directory containing skill folders
      skillName - The skill name to load
      source - The source identifier for the created skill
      返回:
      The loaded AgentSkill
      抛出:
      IllegalArgumentException - if the skill cannot be found or is invalid
    • loadSkillFromDirectory

      public static AgentSkill loadSkillFromDirectory(Path skillDir, String source)
      Loads a skill from a specific directory.
      参数:
      skillDir - The directory containing SKILL.md
      source - The source identifier for the created skill
      返回:
      The loaded AgentSkill
      抛出:
      IllegalArgumentException - if SKILL.md is missing or invalid
    • getAllSkillNames

      public static List<String> getAllSkillNames(Path baseDir)
      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

      public static List<AgentSkill> getAllSkills(Path baseDir, String source)
      Retrieves all skills from the base directory.
      参数:
      baseDir - The base directory containing skill folders
      source - The source identifier for created skills
      返回:
      A list of skills
    • saveSkills

      public static boolean saveSkills(Path baseDir, List<AgentSkill> skills, boolean force)
      Saves skills to the base directory.
      参数:
      baseDir - The base directory to save skills
      skills - The skills to save
      force - Whether to overwrite existing skills
      返回:
      true if all skills were saved, false otherwise
    • deleteSkill

      public static boolean deleteSkill(Path baseDir, String skillName)
      Deletes a skill by name based on SKILL.md metadata.
      参数:
      baseDir - The base directory containing skill folders
      skillName - The skill name to delete
      返回:
      true if deleted, false if not found
    • skillExists

      public static boolean skillExists(Path baseDir, String skillName)
      Checks whether a skill exists by scanning SKILL.md metadata.
      参数:
      baseDir - The base directory containing skill folders
      skillName - The skill name to check
      返回:
      true if a matching skill exists
    • validateAndResolvePath

      public static Path validateAndResolvePath(Path baseDir, String skillName)
      Validates that a resolved path is within the base directory.
      参数:
      baseDir - The base directory to constrain resolution
      skillName - The skill name to resolve
      返回:
      The validated absolute path
      抛出:
      IllegalArgumentException - if the path escapes the base directory
    • hasSkillFile

      public static boolean hasSkillFile(Path dir)
      Checks if a directory contains a SKILL.md file.
      参数:
      dir - The directory to check
      返回:
      true if SKILL.md exists in the directory
    • deleteDirectory

      public static void deleteDirectory(Path directory) throws IOException
      Recursively deletes a directory and all its contents.
      参数:
      directory - The directory to delete
      抛出:
      IOException - if deletion fails
    • registerTempDirectoryCleanup

      public static Thread registerTempDirectoryCleanup(Path directory)
      Registers a shutdown hook to delete the given directory on JVM exit.
      参数:
      directory - The directory to delete at shutdown