Class GitSkillRepository

java.lang.Object
io.agentscope.core.skill.repository.GitSkillRepository
All Implemented Interfaces:
io.agentscope.core.skill.repository.AgentSkillRepository, AutoCloseable

public class GitSkillRepository extends Object implements io.agentscope.core.skill.repository.AgentSkillRepository
Git-based read-only implementation of AgentSkillRepository.

This repository clones a remote Git repository to a local temporary directory and accesses skills directly from the file system. Synchronization is triggered on read operations (getSkill(String), getAllSkillNames(), getAllSkills(), skillExists(String)).

Each read performs a lightweight remote reference check; a pull is only executed when the remote HEAD changes, keeping freshness with minimal network overhead.

Auto-sync can be disabled via constructors that accept autoSync=false. When disabled, call sync() to initialize and refresh before read operations.

Features:

  • Read-only access to Git repositories
  • Automatic synchronization on each read operation
  • Support for both HTTPS and SSH URLs
  • Branch selection support
  • Progress logging for Git operations
  • Automatic cleanup of temporary directories

Authentication: This implementation relies on system-level Git configuration for authentication:

  • HTTPS: Uses credentials from ~/.gitconfig or credential helpers
  • SSH: Uses SSH keys from ~/.ssh/ and ssh-agent

Usage Examples:


 // Public repository with default branch
 GitSkillRepository repo = new GitSkillRepository(
     "https://github.com/agentscope/skills.git"
 );
 AgentSkill skill = repo.getSkill("calculator");
 repo.close();

 // Specify a branch
 GitSkillRepository repo = new GitSkillRepository(
     "https://github.com/agentscope/skills.git",
     "develop"
 );

 // Private repository (requires system Git credentials)
 GitSkillRepository repo = new GitSkillRepository(
     "git@github.com:myorg/private-skills.git"
 );
 

Temporary Directory: Uses Files.createTempDirectory(String, java.nio.file.attribute.FileAttribute[]) to create a temporary directory. The directory is automatically cleaned up on JVM shutdown or when close() is called.

See Also:
  • FileSystemSkillRepository
  • AgentSkillRepository
  • Constructor Details

    • GitSkillRepository

      public GitSkillRepository(String remoteUrl)
      Creates a GitSkillRepository with the specified remote URL using the default branch.
      Parameters:
      remoteUrl - The Git repository URL (HTTPS or SSH)
      Throws:
      IllegalArgumentException - if remoteUrl is null or empty
      RuntimeException - if temporary directory creation fails
    • GitSkillRepository

      public GitSkillRepository(String remoteUrl, Path localPath)
      Creates a GitSkillRepository with the specified remote URL and local path.
      Parameters:
      remoteUrl - The Git repository URL (HTTPS or SSH)
      localPath - The local path to clone the repository (null to use temporary directory)
      Throws:
      IllegalArgumentException - if remoteUrl is null or empty
      RuntimeException - if temporary directory creation fails
    • GitSkillRepository

      public GitSkillRepository(String remoteUrl, String branch)
      Creates a GitSkillRepository with the specified remote URL and branch.
      Parameters:
      remoteUrl - The Git repository URL (HTTPS or SSH)
      branch - The branch name to clone (null for remote default branch)
      Throws:
      IllegalArgumentException - if remoteUrl is null or empty
      RuntimeException - if temporary directory creation fails
    • GitSkillRepository

      public GitSkillRepository(String remoteUrl, Path localPath, String source)
      Creates a GitSkillRepository with the specified remote URL, local path, and source.
      Parameters:
      remoteUrl - The Git repository URL (HTTPS or SSH)
      localPath - The local path to clone the repository (null to use temporary directory)
      source - The custom source identifier (null to use default)
      Throws:
      IllegalArgumentException - if remoteUrl is null or empty
      RuntimeException - if temporary directory creation fails
    • GitSkillRepository

      public GitSkillRepository(String remoteUrl, String branch, Path localPath)
      Creates a GitSkillRepository with the specified remote URL, branch, and local path.
      Parameters:
      remoteUrl - The Git repository URL (HTTPS or SSH)
      branch - The branch name to clone (null for remote default branch)
      localPath - The local path to clone the repository (null to use temporary directory)
      Throws:
      IllegalArgumentException - if remoteUrl is null or empty
      RuntimeException - if temporary directory creation fails
    • GitSkillRepository

      public GitSkillRepository(String remoteUrl, boolean autoSync)
      Creates a GitSkillRepository with the specified remote URL and auto-update option.
      Parameters:
      remoteUrl - The Git repository URL (HTTPS or SSH)
      autoSync - Whether to auto-sync on read operations
      Throws:
      IllegalArgumentException - if remoteUrl is null or empty
      RuntimeException - if temporary directory creation fails
    • GitSkillRepository

      public GitSkillRepository(String remoteUrl, String branch, Path localPath, String source)
      Creates a GitSkillRepository with the specified remote URL, branch, local path, and source.
      Parameters:
      remoteUrl - The Git repository URL (HTTPS or SSH)
      branch - The branch name to clone (null for remote default branch)
      localPath - The local path to clone the repository (null to use temporary directory)
      source - The custom source identifier (null to use default)
      Throws:
      IllegalArgumentException - if remoteUrl is null or empty
      RuntimeException - if temporary directory creation fails
    • GitSkillRepository

      public GitSkillRepository(String remoteUrl, String branch, Path localPath, String source, boolean autoSync)
      Creates a GitSkillRepository with the specified remote URL, branch, local path, source, and auto-update option.
      Parameters:
      remoteUrl - The Git repository URL (HTTPS or SSH)
      branch - The branch name to clone (null for remote default branch)
      localPath - The local path to clone the repository (null to use temporary directory)
      source - The custom source identifier (null to use default)
      autoSync - Whether to auto-sync on read operations
      Throws:
      IllegalArgumentException - if remoteUrl is null or empty
      RuntimeException - if temporary directory creation fails
    • GitSkillRepository

      public GitSkillRepository(String remoteUrl, String branch, Path localPath, String source, boolean autoSync, String skillsRoot)
      Creates a GitSkillRepository with an explicit in-repo skills root directory.

      skillsRoot pins where inside the cloned repository the skill folders live (each containing a SKILL.md). When non-null, the value is treated as a path relative to the repo root; absolute paths and paths containing .. segments are rejected. When null, the implementation falls back to the legacy convention: use <repo>/skills/ if it exists, otherwise the repo root.

      Parameters:
      remoteUrl - The Git repository URL (HTTPS or SSH)
      branch - The branch name to clone (null for remote default branch)
      localPath - The local path to clone the repository (null to use temporary directory)
      source - The custom source identifier (null to use default)
      autoSync - Whether to auto-sync on read operations
      skillsRoot - Optional in-repo subdirectory containing skill folders
      Throws:
      IllegalArgumentException - if remoteUrl is blank, or skillsRoot is absolute / contains a .. segment / would escape the repo root
      RuntimeException - if temporary directory creation fails
  • Method Details

    • getSkill

      public io.agentscope.core.skill.AgentSkill getSkill(String name)
      Specified by:
      getSkill in interface io.agentscope.core.skill.repository.AgentSkillRepository
    • getAllSkillNames

      public List<String> getAllSkillNames()
      Specified by:
      getAllSkillNames in interface io.agentscope.core.skill.repository.AgentSkillRepository
    • getAllSkills

      public List<io.agentscope.core.skill.AgentSkill> getAllSkills()
      Specified by:
      getAllSkills in interface io.agentscope.core.skill.repository.AgentSkillRepository
    • skillExists

      public boolean skillExists(String skillName)
      Specified by:
      skillExists in interface io.agentscope.core.skill.repository.AgentSkillRepository
    • sync

      public void sync()
      Triggers a manual synchronization of the repository.
    • save

      public boolean save(List<io.agentscope.core.skill.AgentSkill> skills, boolean force)
      Specified by:
      save in interface io.agentscope.core.skill.repository.AgentSkillRepository
    • delete

      public boolean delete(String skillName)
      Specified by:
      delete in interface io.agentscope.core.skill.repository.AgentSkillRepository
    • setWriteable

      public void setWriteable(boolean writeable)
      Specified by:
      setWriteable in interface io.agentscope.core.skill.repository.AgentSkillRepository
    • isWriteable

      public boolean isWriteable()
      Specified by:
      isWriteable in interface io.agentscope.core.skill.repository.AgentSkillRepository
    • close

      public void close()
      Specified by:
      close in interface io.agentscope.core.skill.repository.AgentSkillRepository
      Specified by:
      close in interface AutoCloseable
    • getRepositoryInfo

      public io.agentscope.core.skill.repository.AgentSkillRepositoryInfo getRepositoryInfo()
      Specified by:
      getRepositoryInfo in interface io.agentscope.core.skill.repository.AgentSkillRepository
    • getSource

      public String getSource()
      Specified by:
      getSource in interface io.agentscope.core.skill.repository.AgentSkillRepository