Documentation
¶
Overview ¶
Package skill 提供基于文件系统的 skill 管理系统(Hermes 风格)。 agent 可以创建、查看和管理 skill,以 SKILL.md 格式存储在 data/skills/ 目录下。 skill 使用 agentskills.io 兼容的 YAML frontmatter + markdown body 格式。
Index ¶
- func NewSkillManagerTool(store *SkillStore) tool.InvokableTool
- func WriteSkillMD(filePath string, meta SkillMeta, content string) error
- type ClawHubClient
- func (c *ClawHubClient) Detail(ctx context.Context, slug string) (*ClawHubSkillDetail, error)
- func (c *ClawHubClient) Download(ctx context.Context, slug, version string) (*DownloadResult, error)
- func (c *ClawHubClient) Search(ctx context.Context, query string, limit int) ([]ClawHubSearchResult, error)
- func (c *ClawHubClient) SecurityVerdicts(ctx context.Context, items []ClawHubSecurityVerdictRequest) ([]ClawHubSecurityVerdict, error)
- func (c *ClawHubClient) Verify(ctx context.Context, slug, version string) (*ClawHubSecurityVerdict, error)
- type ClawHubConfig
- type ClawHubGitHubHandoff
- type ClawHubSearchResult
- type ClawHubSecurityVerdict
- type ClawHubSecurityVerdictRequest
- type ClawHubSecurityVerdictsResponse
- type ClawHubSkillDetail
- type DownloadResult
- type Skill
- type SkillCardMeta
- type SkillClawHubMeta
- type SkillInstallSpec
- type SkillManageRequest
- type SkillManagerTool
- type SkillMeta
- type SkillRequirements
- type SkillSource
- type SkillState
- type SkillStore
- func (s *SkillStore) CreateSkill(ctx context.Context, meta SkillMeta, content string, source SkillSource) (*Skill, error)
- func (s *SkillStore) DeleteSkill(ctx context.Context, name string) error
- func (s *SkillStore) FormatSkillsForPrompt(ctx context.Context) string
- func (s *SkillStore) GetSkill(ctx context.Context, name string) (*Skill, error)
- func (s *SkillStore) GetSkillFile(ctx context.Context, name string, filePath string) ([]byte, error)
- func (s *SkillStore) ListSkills(ctx context.Context) ([]*Skill, error)
- func (s *SkillStore) PatchSkill(ctx context.Context, name string, oldStr string, newStr string) (*Skill, error)
- func (s *SkillStore) PinSkill(ctx context.Context, name string) error
- func (s *SkillStore) RecordUse(ctx context.Context, name string)
- func (s *SkillStore) RecordView(ctx context.Context, name string)
- func (s *SkillStore) UnpinSkill(ctx context.Context, name string) error
- func (s *SkillStore) UpdateState(ctx context.Context, name string, state SkillState) error
- type SkillUsage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSkillManagerTool ¶
func NewSkillManagerTool(store *SkillStore) tool.InvokableTool
Types ¶
type ClawHubClient ¶
type ClawHubClient struct {
// contains filtered or unexported fields
}
ClawHubClient provides a thin HTTP client for the ClawHub public registry.
func NewClawHubClient ¶
func NewClawHubClient(cfg ClawHubConfig) *ClawHubClient
NewClawHubClient creates a new client. Empty BaseURL defaults to https://clawhub.ai.
func (*ClawHubClient) Detail ¶
func (c *ClawHubClient) Detail(ctx context.Context, slug string) (*ClawHubSkillDetail, error)
Detail fetches the detail page for a single skill slug.
func (*ClawHubClient) Download ¶
func (c *ClawHubClient) Download(ctx context.Context, slug, version string) (*DownloadResult, error)
Download fetches a skill archive from ClawHub. Supports ZIP bytes and GitHub handoffs.
func (*ClawHubClient) Search ¶
func (c *ClawHubClient) Search(ctx context.Context, query string, limit int) ([]ClawHubSearchResult, error)
Search queries ClawHub for skills matching the given query.
func (*ClawHubClient) SecurityVerdicts ¶
func (c *ClawHubClient) SecurityVerdicts(ctx context.Context, items []ClawHubSecurityVerdictRequest) ([]ClawHubSecurityVerdict, error)
SecurityVerdicts fetches batch verdicts for the requested skill versions. Falls back to per-skill Verify when no API key is configured.
func (*ClawHubClient) Verify ¶
func (c *ClawHubClient) Verify(ctx context.Context, slug, version string) (*ClawHubSecurityVerdict, error)
Verify fetches a single skill security verdict via the public verify endpoint.
type ClawHubConfig ¶
ClawHubConfig configures the ClawHub registry client.
type ClawHubGitHubHandoff ¶
type ClawHubGitHubHandoff struct {
SourceRef string `json:"sourceRef"`
Repo string `json:"repo"`
Commit string `json:"commit"`
Path string `json:"path"`
ContentHash string `json:"contentHash"`
ArchiveURL string `json:"archiveUrl"`
}
ClawHubGitHubHandoff is returned for GitHub-backed skills.
type ClawHubSearchResult ¶
type ClawHubSearchResult struct {
Score float64 `json:"score"`
Slug string `json:"slug"`
DisplayName string `json:"displayName"`
Summary string `json:"summary,omitempty"`
Version string `json:"version,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
OwnerHandle string `json:"ownerHandle,omitempty"`
Owner *struct {
Handle string `json:"handle"`
DisplayName string `json:"displayName"`
Image string `json:"image,omitempty"`
} `json:"owner,omitempty"`
}
ClawHubSearchResult matches the frontend ClawHubSearchResult type.
type ClawHubSecurityVerdict ¶
type ClawHubSecurityVerdict struct {
Registry string `json:"registry"`
OK bool `json:"ok"`
Decision string `json:"decision"`
Reasons []string `json:"reasons"`
RequestedSlug string `json:"requestedSlug"`
RequestedVersion string `json:"requestedVersion"`
Slug string `json:"slug,omitempty"`
Version string `json:"version,omitempty"`
DisplayName string `json:"displayName,omitempty"`
PublisherHandle string `json:"publisherHandle,omitempty"`
PublisherDisplayName string `json:"publisherDisplayName,omitempty"`
CreatedAt int64 `json:"createdAt,omitempty"`
CheckedAt int64 `json:"checkedAt,omitempty"`
SkillURL string `json:"skillUrl,omitempty"`
SecurityAuditURL string `json:"securityAuditUrl,omitempty"`
SecurityStatus string `json:"securityStatus,omitempty"`
SecurityPassed bool `json:"securityPassed,omitempty"`
Error *struct {
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
} `json:"error,omitempty"`
}
ClawHubSecurityVerdict matches the frontend ClawHubSkillSecurityVerdict type.
type ClawHubSecurityVerdictRequest ¶
type ClawHubSecurityVerdictRequest struct {
Slug string `json:"slug"`
Version string `json:"version"`
}
ClawHubSecurityVerdictRequest is used for the batch verdict endpoint.
type ClawHubSecurityVerdictsResponse ¶
type ClawHubSecurityVerdictsResponse struct {
Schema string `json:"schema"`
Items []ClawHubSecurityVerdict `json:"items"`
}
ClawHubSecurityVerdictsResponse wraps the batch verdict endpoint.
type ClawHubSkillDetail ¶
type ClawHubSkillDetail struct {
Skill *struct {
Slug string `json:"slug"`
DisplayName string `json:"displayName"`
Summary string `json:"summary,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
CreatedAt int64 `json:"createdAt"`
UpdatedAt int64 `json:"updatedAt"`
} `json:"skill"`
LatestVersion *struct {
Version string `json:"version"`
CreatedAt int64 `json:"createdAt"`
Changelog string `json:"changelog,omitempty"`
} `json:"latestVersion,omitempty"`
Metadata *struct {
OS []string `json:"os,omitempty"`
Systems []string `json:"systems,omitempty"`
} `json:"metadata,omitempty"`
Owner *struct {
Handle string `json:"handle,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Image string `json:"image,omitempty"`
} `json:"owner,omitempty"`
}
ClawHubSkillDetail matches the frontend ClawHubSkillDetail type.
type DownloadResult ¶
type DownloadResult struct {
ContentType string
Body io.ReadCloser
// Handoff is set when ClawHub returns a GitHub source reference instead of bytes.
Handoff *ClawHubGitHubHandoff
}
DownloadResult holds either ZIP bytes or a GitHub source handoff.
type Skill ¶
type Skill struct {
Meta SkillMeta `json:"meta"`
Path string `json:"path"`
Content string `json:"content"`
Source SkillSource `json:"source"`
State SkillState `json:"state"`
UseCount int `json:"use_count"`
ViewCount int `json:"view_count"`
PatchCount int `json:"patch_count"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
PinnedAt *time.Time `json:"pinned_at,omitempty"`
}
Skill 完整 skill 对象
type SkillCardMeta ¶
type SkillCardMeta struct {
Path string `yaml:"path" json:"path"`
}
SkillCardMeta 技能卡片文件元信息
type SkillClawHubMeta ¶
type SkillClawHubMeta struct {
Registry string `yaml:"registry" json:"registry"`
Slug string `yaml:"slug" json:"slug"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
InstalledVersion string `yaml:"installed_version,omitempty" json:"installed_version,omitempty"`
InstalledAt int64 `yaml:"installed_at,omitempty" json:"installed_at,omitempty"`
}
SkillClawHubMeta 技能与 ClawHub 注册表的关联信息
type SkillInstallSpec ¶
type SkillInstallSpec struct {
ID string `yaml:"id" json:"id"`
Kind string `yaml:"kind" json:"kind"`
Label string `yaml:"label" json:"label"`
Bins []string `yaml:"bins,omitempty" json:"bins,omitempty"`
Command string `yaml:"command,omitempty" json:"command,omitempty"`
}
SkillInstallSpec 单个安装选项(对应前端 SkillInstallOption)
type SkillManageRequest ¶
type SkillManageRequest struct {
Action string `json:"action"` // list|view|create|edit|patch|delete|write_file|remove_file|pin|unpin
Name string `json:"name,omitempty"`
Category string `json:"category,omitempty"`
Description string `json:"description,omitempty"`
Content string `json:"content,omitempty"`
OldString string `json:"old_string,omitempty"`
NewString string `json:"new_string,omitempty"`
FilePath string `json:"file_path,omitempty"`
FileContent string `json:"file_content,omitempty"`
}
SkillManageRequest skill_manage 工具参数
type SkillManagerTool ¶
type SkillManagerTool struct {
// contains filtered or unexported fields
}
SkillManagerTool skill_manage Eino 工具
func (*SkillManagerTool) InvokableRun ¶
type SkillMeta ¶
type SkillMeta struct {
Name string `yaml:"name" json:"name"`
Description string `yaml:"description" json:"description"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
License string `yaml:"license,omitempty" json:"license,omitempty"`
Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"`
Platforms []string `yaml:"platforms,omitempty" json:"platforms,omitempty"`
CreatedBy string `yaml:"created_by,omitempty" json:"created_by,omitempty"`
Category string `yaml:"category,omitempty" json:"category,omitempty"`
// 以下字段为 OpenClaw Control UI 前端兼容而增加,均为可选。
Emoji string `yaml:"emoji,omitempty" json:"emoji,omitempty"`
Homepage string `yaml:"homepage,omitempty" json:"homepage,omitempty"`
Always bool `yaml:"always,omitempty" json:"always,omitempty"`
Bundled bool `yaml:"bundled,omitempty" json:"bundled,omitempty"`
PrimaryEnv string `yaml:"primary_env,omitempty" json:"primary_env,omitempty"`
Source string `yaml:"source,omitempty" json:"source,omitempty"`
Requirements SkillRequirements `yaml:"requirements,omitempty" json:"requirements,omitempty"`
Install []SkillInstallSpec `yaml:"install,omitempty" json:"install,omitempty"`
ClawHub *SkillClawHubMeta `yaml:"clawhub,omitempty" json:"clawhub,omitempty"`
SkillCard *SkillCardMeta `yaml:"skill_card,omitempty" json:"skill_card,omitempty"`
}
SkillMeta SKILL.md YAML frontmatter (agentskills.io 兼容)
type SkillRequirements ¶
type SkillRequirements struct {
AnyBins []string `yaml:"any_bins,omitempty" json:"any_bins,omitempty"`
Bins []string `yaml:"bins,omitempty" json:"bins,omitempty"`
Env []string `yaml:"env,omitempty" json:"env,omitempty"`
Config []string `yaml:"config,omitempty" json:"config,omitempty"`
OS []string `yaml:"os,omitempty" json:"os,omitempty"`
}
SkillRequirements 技能运行所需的环境/二进制/配置/操作系统
type SkillSource ¶
type SkillSource string
SkillSource skill 来源
const ( SkillSourceBundled SkillSource = "bundled" SkillSourceUser SkillSource = "user" SkillSourceAgent SkillSource = "agent" SkillSourceUploaded SkillSource = "uploaded" )
type SkillState ¶
type SkillState string
SkillState 生命周期状态
const ( SkillStateActive SkillState = "active" SkillStateStale SkillState = "stale" SkillStateArchived SkillState = "archived" SkillStatePinned SkillState = "pinned" )
type SkillStore ¶
type SkillStore struct {
// contains filtered or unexported fields
}
SkillStore 基于文件系统的 skill 管理器
func NewSkillStore ¶
func NewSkillStore(baseDir string, logger *zap.Logger) (*SkillStore, error)
NewSkillStore 创建 skill 管理器 baseDir 为空时默认为 "data/skills"
func (*SkillStore) CreateSkill ¶
func (s *SkillStore) CreateSkill(ctx context.Context, meta SkillMeta, content string, source SkillSource) (*Skill, error)
CreateSkill 创建新 skill
func (*SkillStore) DeleteSkill ¶
func (s *SkillStore) DeleteSkill(ctx context.Context, name string) error
DeleteSkill 删除 skill
func (*SkillStore) FormatSkillsForPrompt ¶
func (s *SkillStore) FormatSkillsForPrompt(ctx context.Context) string
FormatSkillsForPrompt 生成 Hermes 风格的 skill 提示注入
func (*SkillStore) GetSkillFile ¶
func (s *SkillStore) GetSkillFile(ctx context.Context, name string, filePath string) ([]byte, error)
GetSkillFile 加载 skill 的辅助文件(references/templates 中的文件)
func (*SkillStore) ListSkills ¶
func (s *SkillStore) ListSkills(ctx context.Context) ([]*Skill, error)
ListSkills 列出所有 skill(仅元数据,不含完整内容)
func (*SkillStore) PatchSkill ¶
func (s *SkillStore) PatchSkill(ctx context.Context, name string, oldStr string, newStr string) (*Skill, error)
PatchSkill 修补 skill 内容(find-and-replace)
func (*SkillStore) PinSkill ¶
func (s *SkillStore) PinSkill(ctx context.Context, name string) error
PinSkill 置顶 skill
func (*SkillStore) RecordUse ¶
func (s *SkillStore) RecordUse(ctx context.Context, name string)
RecordUse 记录 skill 使用
func (*SkillStore) RecordView ¶
func (s *SkillStore) RecordView(ctx context.Context, name string)
RecordView 记录 skill 查看
func (*SkillStore) UnpinSkill ¶
func (s *SkillStore) UnpinSkill(ctx context.Context, name string) error
UnpinSkill 取消置顶 skill
func (*SkillStore) UpdateState ¶
func (s *SkillStore) UpdateState(ctx context.Context, name string, state SkillState) error
UpdateState 更新 skill 生命周期状态
type SkillUsage ¶
type SkillUsage struct {
Name string `json:"name"`
UseCount int `json:"use_count"`
ViewCount int `json:"view_count"`
PatchCount int `json:"patch_count"`
LastActivityAt time.Time `json:"last_activity_at"`
State SkillState `json:"state"`
Pinned bool `json:"pinned"`
}
SkillUsage .usage.json 条目