GitSkillRepository
public class GitSkillRepository implements AgentSkillRepository
io/agentscope/core/skill/repository/GitSkillRepository.java:101–804Git 技能仓库,负责持久化与读取数据。位于 io.agentscope.core.skill.repository 包,实现 AgentSkillRepository。核心成员包括 getSkill、getAllSkillNames、getAllSkills、skillExists、sync、save。
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.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public GitSkillRepository(String remoteUrl) | 初始化 `GitSkillRepository` 实例。 Creates a GitSkillRepository with the specified remote URL using the default branch. |
public GitSkillRepository(String remoteUrl, Path localPath) | 初始化 `GitSkillRepository` 实例。 Creates a GitSkillRepository with the specified remote URL and local path. |
public GitSkillRepository(String remoteUrl, String branch) | 初始化 `GitSkillRepository` 实例。 Creates a GitSkillRepository with the specified remote URL and branch. |
public GitSkillRepository(String remoteUrl, Path localPath, String source) | 初始化 `GitSkillRepository` 实例。 Creates a GitSkillRepository with the specified remote URL, local path, and source. |
public GitSkillRepository(String remoteUrl, String branch, Path localPath) | 初始化 `GitSkillRepository` 实例。 Creates a GitSkillRepository with the specified remote URL, branch, and local path. |
public GitSkillRepository(String remoteUrl, boolean autoSync) | 初始化 `GitSkillRepository` 实例。 Creates a GitSkillRepository with the specified remote URL and auto-update option. |
public GitSkillRepository(String remoteUrl, String branch, Path localPath, String source) | 初始化 `GitSkillRepository` 实例。 Creates a GitSkillRepository with the specified remote URL, branch, local path, and source. |
public GitSkillRepository(String remoteUrl, String branch, Path localPath, String source, boolean autoSync) | 初始化 `GitSkillRepository` 实例。 Creates a GitSkillRepository with the specified remote URL, branch, local path, source,
and auto-update option. |
public GitSkillRepository(String remoteUrl, String branch, Path localPath, String source, boolean autoSync, String skillsRoot) | 初始化 `GitSkillRepository` 实例。 Creates a GitSkillRepository with an explicit in-repo skills root directory. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public AgentSkill getSkill(String name) | 获取技能。 Returns the skill. |
public List<String> getAllSkillNames() | 获取 `getAllSkillNames`。 Returns the all skill names. |
public List<AgentSkill> getAllSkills() | 获取所有技能。 Returns the all skills. |
public boolean skillExists(String skillName) | 设置该参数。 Performs the skill exists operation. |
public void sync() | 执行同步相关操作。 Triggers a manual synchronization of the repository. |
public boolean save(List<AgentSkill> skills, boolean force) | 保存数据到持久化存储。 Performs the save operation. |
public boolean delete(String skillName) | 删除数据。 Performs the delete operation. |
public void setWriteable(boolean writeable) | 设置 `setWriteable`。 Sets the writeable. |
public boolean isWriteable() | 判断是否 `isWriteable`。 Returns whether the writeable. |
public void close() | 关闭连接并释放相关资源。 Releases resources and connections. |
public AgentSkillRepositoryInfo getRepositoryInfo() | 获取仓库信息。 Returns the repository info. |
public String getSource() | 获取来源。 Returns the source. |
构造器详情Constructor Detail
GitSkillRepository
public GitSkillRepository(String remoteUrl)
初始化 GitSkillRepository 实例。
Creates a GitSkillRepository with the specified remote URL using the default branch.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
remoteUrl | String | 远程 URL(类型 `String`)。The Git repository URL (HTTPS or SSH) |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if remoteUrl is null or emptyRuntimeException可能抛出 `RuntimeException`。if temporary directory creation fails
io/agentscope/core/skill/repository/GitSkillRepository.java:123–125GitSkillRepository
public GitSkillRepository(String remoteUrl, Path localPath)
初始化 GitSkillRepository 实例。
Creates a GitSkillRepository with the specified remote URL and local path.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
remoteUrl | String | 远程 URL(类型 `String`)。The Git repository URL (HTTPS or SSH) |
localPath | Path | 本地路径(类型 `Path`)。The local path to clone the repository (null to use temporary directory) |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if remoteUrl is null or emptyRuntimeException可能抛出 `RuntimeException`。if temporary directory creation fails
io/agentscope/core/skill/repository/GitSkillRepository.java:135–137GitSkillRepository
public GitSkillRepository(String remoteUrl, String branch)
初始化 GitSkillRepository 实例。
Creates a GitSkillRepository with the specified remote URL and branch.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
remoteUrl | String | 远程 URL(类型 `String`)。The Git repository URL (HTTPS or SSH) |
branch | String | branch(类型 `String`)。The branch name to clone (null for remote default branch) |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if remoteUrl is null or emptyRuntimeException可能抛出 `RuntimeException`。if temporary directory creation fails
io/agentscope/core/skill/repository/GitSkillRepository.java:147–149GitSkillRepository
public GitSkillRepository(String remoteUrl, Path localPath, String source)
初始化 GitSkillRepository 实例。
Creates a GitSkillRepository with the specified remote URL, local path, and source.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
remoteUrl | String | 远程 URL(类型 `String`)。The Git repository URL (HTTPS or SSH) |
localPath | Path | 本地路径(类型 `Path`)。The local path to clone the repository (null to use temporary directory) |
source | String | 来源(类型 `String`)。The custom source identifier (null to use default) |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if remoteUrl is null or emptyRuntimeException可能抛出 `RuntimeException`。if temporary directory creation fails
io/agentscope/core/skill/repository/GitSkillRepository.java:160–162GitSkillRepository
public GitSkillRepository(String remoteUrl, String branch, Path localPath)
初始化 GitSkillRepository 实例。
Creates a GitSkillRepository with the specified remote URL, branch, and local path.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
remoteUrl | String | 远程 URL(类型 `String`)。The Git repository URL (HTTPS or SSH) |
branch | String | branch(类型 `String`)。The branch name to clone (null for remote default branch) |
localPath | Path | 本地路径(类型 `Path`)。The local path to clone the repository (null to use temporary directory) |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if remoteUrl is null or emptyRuntimeException可能抛出 `RuntimeException`。if temporary directory creation fails
io/agentscope/core/skill/repository/GitSkillRepository.java:173–175GitSkillRepository
public GitSkillRepository(String remoteUrl, boolean autoSync)
初始化 GitSkillRepository 实例。
Creates a GitSkillRepository with the specified remote URL and auto-update option.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
remoteUrl | String | 远程 URL(类型 `String`)。The Git repository URL (HTTPS or SSH) |
autoSync | boolean | auto 同步(类型 `boolean`)。Whether to auto-sync on read operations |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if remoteUrl is null or emptyRuntimeException可能抛出 `RuntimeException`。if temporary directory creation fails
io/agentscope/core/skill/repository/GitSkillRepository.java:185–187GitSkillRepository
public GitSkillRepository(String remoteUrl, String branch, Path localPath, String source)
初始化 GitSkillRepository 实例。
Creates a GitSkillRepository with the specified remote URL, branch, local path, and source.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
remoteUrl | String | 远程 URL(类型 `String`)。The Git repository URL (HTTPS or SSH) |
branch | String | branch(类型 `String`)。The branch name to clone (null for remote default branch) |
localPath | Path | 本地路径(类型 `Path`)。The local path to clone the repository (null to use temporary directory) |
source | String | 来源(类型 `String`)。The custom source identifier (null to use default) |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if remoteUrl is null or emptyRuntimeException可能抛出 `RuntimeException`。if temporary directory creation fails
io/agentscope/core/skill/repository/GitSkillRepository.java:199–201GitSkillRepository
public GitSkillRepository(String remoteUrl, String branch, Path localPath, String source, boolean autoSync)
初始化 GitSkillRepository 实例。
Creates a GitSkillRepository with the specified remote URL, branch, local path, source, and auto-update option.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
remoteUrl | String | 远程 URL(类型 `String`)。The Git repository URL (HTTPS or SSH) |
branch | String | branch(类型 `String`)。The branch name to clone (null for remote default branch) |
localPath | Path | 本地路径(类型 `Path`)。The local path to clone the repository (null to use temporary directory) |
source | String | 来源(类型 `String`)。The custom source identifier (null to use default) |
autoSync | boolean | auto 同步(类型 `boolean`)。Whether to auto-sync on read operations |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if remoteUrl is null or emptyRuntimeException可能抛出 `RuntimeException`。if temporary directory creation fails
io/agentscope/core/skill/repository/GitSkillRepository.java:215–218GitSkillRepository
public GitSkillRepository(String remoteUrl, String branch, Path localPath, String source, boolean autoSync, String skillsRoot)
初始化 GitSkillRepository 实例。
Creates a GitSkillRepository with an explicit in-repo skills root directory.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
remoteUrl | String | 远程 URL(类型 `String`)。The Git repository URL (HTTPS or SSH) |
branch | String | branch(类型 `String`)。The branch name to clone (null for remote default branch) |
localPath | Path | 本地路径(类型 `Path`)。The local path to clone the repository (null to use temporary directory) |
source | String | 来源(类型 `String`)。The custom source identifier (null to use default) |
autoSync | boolean | auto 同步(类型 `boolean`)。Whether to auto-sync on read operations |
skillsRoot | String | 技能根(类型 `String`)。Optional in-repo subdirectory containing skill folders |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if `remoteUrl` is blank, or `skillsRoot` is absolute / contains a `..` segment / would escape the repo rootRuntimeException可能抛出 `RuntimeException`。if temporary directory creation fails
io/agentscope/core/skill/repository/GitSkillRepository.java:239–275方法详情Method Detail
getSkill
public AgentSkill getSkill(String name)
获取技能。
Returns the skill.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 名称(类型 `String`)。The name. |
AgentSkillio/agentscope/core/skill/repository/GitSkillRepository.java:277–281getAllSkillNames
public List<String> getAllSkillNames()
获取 getAllSkillNames。
Returns the all skill names.
List<String>io/agentscope/core/skill/repository/GitSkillRepository.java:283–287getAllSkills
public List<AgentSkill> getAllSkills()
获取所有技能。
Returns the all skills.
List<AgentSkill>io/agentscope/core/skill/repository/GitSkillRepository.java:289–293skillExists
public boolean skillExists(String skillName)
设置该参数。
Performs the skill exists operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
skillName | String | 技能名称(类型 `String`)。The skill name. |
booleanio/agentscope/core/skill/repository/GitSkillRepository.java:295–299sync
public void sync()
执行同步相关操作。
Triggers a manual synchronization of the repository.
io/agentscope/core/skill/repository/GitSkillRepository.java:304–306save
public boolean save(List<AgentSkill> skills, boolean force)
保存数据到持久化存储。
Performs the save operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
skills | List<AgentSkill> | 技能(类型 `List`)。The skills. |
force | boolean | force(类型 `boolean`)。The force. |
booleanio/agentscope/core/skill/repository/GitSkillRepository.java:308–312delete
public boolean delete(String skillName)
删除数据。
Performs the delete operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
skillName | String | 技能名称(类型 `String`)。The skill name. |
booleanio/agentscope/core/skill/repository/GitSkillRepository.java:314–318setWriteable
public void setWriteable(boolean writeable)
设置 setWriteable。
Sets the writeable.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
writeable | boolean | writeable(类型 `boolean`)。The writeable. |
io/agentscope/core/skill/repository/GitSkillRepository.java:320–323isWriteable
public boolean isWriteable()
判断是否 isWriteable。
Returns whether the writeable.
booleanio/agentscope/core/skill/repository/GitSkillRepository.java:325–328close
public void close()
关闭连接并释放相关资源。
Releases resources and connections.
io/agentscope/core/skill/repository/GitSkillRepository.java:330–355getRepositoryInfo
public AgentSkillRepositoryInfo getRepositoryInfo()
获取仓库信息。
Returns the repository info.
AgentSkillRepositoryInfoio/agentscope/core/skill/repository/GitSkillRepository.java:357–360getSource
public String getSource()
获取来源。
Returns the source.
Stringio/agentscope/core/skill/repository/GitSkillRepository.java:362–365