Class GitSkillRepository
- All Implemented Interfaces:
io.agentscope.core.skill.repository.AgentSkillRepository,AutoCloseable
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:
-
FileSystemSkillRepositoryAgentSkillRepository
-
Constructor Summary
ConstructorsConstructorDescriptionGitSkillRepository(String remoteUrl) Creates a GitSkillRepository with the specified remote URL using the default branch.GitSkillRepository(String remoteUrl, boolean autoSync) Creates a GitSkillRepository with the specified remote URL and auto-update option.GitSkillRepository(String remoteUrl, String branch) Creates a GitSkillRepository with the specified remote URL and branch.GitSkillRepository(String remoteUrl, String branch, Path localPath) Creates a GitSkillRepository with the specified remote URL, branch, and local path.GitSkillRepository(String remoteUrl, String branch, Path localPath, String source) Creates a GitSkillRepository with the specified remote URL, branch, local path, and source.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.GitSkillRepository(String remoteUrl, String branch, Path localPath, String source, boolean autoSync, String skillsRoot) Creates a GitSkillRepository with an explicit in-repo skills root directory.GitSkillRepository(String remoteUrl, Path localPath) Creates a GitSkillRepository with the specified remote URL and local path.GitSkillRepository(String remoteUrl, Path localPath, String source) Creates a GitSkillRepository with the specified remote URL, local path, and source. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanList<io.agentscope.core.skill.AgentSkill>io.agentscope.core.skill.repository.AgentSkillRepositoryInfoio.agentscope.core.skill.AgentSkillbooleanbooleanvoidsetWriteable(boolean writeable) booleanskillExists(String skillName) voidsync()Triggers a manual synchronization of the repository.
-
Constructor Details
-
GitSkillRepository
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 emptyRuntimeException- if temporary directory creation fails
-
GitSkillRepository
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 emptyRuntimeException- if temporary directory creation fails
-
GitSkillRepository
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 emptyRuntimeException- if temporary directory creation fails
-
GitSkillRepository
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 emptyRuntimeException- if temporary directory creation fails
-
GitSkillRepository
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 emptyRuntimeException- if temporary directory creation fails
-
GitSkillRepository
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 emptyRuntimeException- if temporary directory creation fails
-
GitSkillRepository
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 emptyRuntimeException- 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 emptyRuntimeException- 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.skillsRootpins where inside the cloned repository the skill folders live (each containing aSKILL.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 operationsskillsRoot- Optional in-repo subdirectory containing skill folders- Throws:
IllegalArgumentException- ifremoteUrlis blank, orskillsRootis absolute / contains a..segment / would escape the repo rootRuntimeException- if temporary directory creation fails
-
-
Method Details
-
getSkill
- Specified by:
getSkillin interfaceio.agentscope.core.skill.repository.AgentSkillRepository
-
getAllSkillNames
- Specified by:
getAllSkillNamesin interfaceio.agentscope.core.skill.repository.AgentSkillRepository
-
getAllSkills
- Specified by:
getAllSkillsin interfaceio.agentscope.core.skill.repository.AgentSkillRepository
-
skillExists
- Specified by:
skillExistsin interfaceio.agentscope.core.skill.repository.AgentSkillRepository
-
sync
public void sync()Triggers a manual synchronization of the repository. -
save
- Specified by:
savein interfaceio.agentscope.core.skill.repository.AgentSkillRepository
-
delete
- Specified by:
deletein interfaceio.agentscope.core.skill.repository.AgentSkillRepository
-
setWriteable
public void setWriteable(boolean writeable) - Specified by:
setWriteablein interfaceio.agentscope.core.skill.repository.AgentSkillRepository
-
isWriteable
public boolean isWriteable()- Specified by:
isWriteablein interfaceio.agentscope.core.skill.repository.AgentSkillRepository
-
close
public void close()- Specified by:
closein interfaceio.agentscope.core.skill.repository.AgentSkillRepository- Specified by:
closein interfaceAutoCloseable
-
getRepositoryInfo
public io.agentscope.core.skill.repository.AgentSkillRepositoryInfo getRepositoryInfo()- Specified by:
getRepositoryInfoin interfaceio.agentscope.core.skill.repository.AgentSkillRepository
-
getSource
- Specified by:
getSourcein interfaceio.agentscope.core.skill.repository.AgentSkillRepository
-