fetch

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package fetch 提供从远程源发现和下载 Skill 的能力。

Index

Constants

This section is empty.

Variables

View Source
var TrustedRepos = map[string]bool{
	"openai/skills":      true,
	"anthropics/skills":  true,
	"huggingface/skills": true,
	"NVIDIA/skills":      true,
}

TrustedRepos 受信任的 GitHub 仓库列表。

Functions

func IsMacOSJunkPath added in v0.1.22

func IsMacOSJunkPath(path string) bool

IsMacOSJunkPath 判断路径是否为 macOS 归档时产生的元数据文件,安装时应忽略。 包括 __MACOSX 资源 fork 目录、._ 前缀的 AppleDouble 文件、以及 .DS_Store。

func TrustLevelForRepo

func TrustLevelForRepo(owner, repo string) string

TrustLevelForRepo 根据仓库判断信任级别。

Types

type BuiltinSource added in v0.1.1

type BuiltinSource struct {
	// contains filtered or unexported fields
}

BuiltinSource 通过 HTTP API 从 Leros 服务端获取内置 Skill。

func NewBuiltinSource added in v0.1.1

func NewBuiltinSource(serverAddr string) *BuiltinSource

NewBuiltinSource 创建 BuiltinSource。

func (*BuiltinSource) CanHandle added in v0.1.1

func (s *BuiltinSource) CanHandle(identifier string) bool

CanHandle 处理不含 "/"、"://" 和 ":" 的短名称/skill_id。 ":" 用于标识外部源(如 clawhub:<slug>@<version>)。

func (*BuiltinSource) Fetch added in v0.1.1

func (s *BuiltinSource) Fetch(ctx context.Context, identifier string) (*SkillBundle, error)

Fetch 调用服务端下载接口获取完整 Skill 包。

func (*BuiltinSource) FetchVersion added in v0.1.13

func (s *BuiltinSource) FetchVersion(ctx context.Context, identifier, version string) (*SkillBundle, error)

FetchVersion 实现 fetch.VersionedSource。 下载内置 Skill 的指定版本(通过查询参数传递),服务端目前可能忽略版本参数。

func (*BuiltinSource) Inspect added in v0.1.1

func (s *BuiltinSource) Inspect(ctx context.Context, identifier string) (*SkillMeta, error)

Inspect 通过搜索 API 查找指定 skill_id 的元数据。

func (*BuiltinSource) Search added in v0.1.1

func (s *BuiltinSource) Search(ctx context.Context, query string, limit int) ([]SkillMeta, error)

Search 调用服务端 marketplace 搜索接口。

func (*BuiltinSource) SourceID added in v0.1.1

func (s *BuiltinSource) SourceID() string

SourceID 返回源标识。

type ClawHubSource added in v0.1.13

type ClawHubSource struct {
	// contains filtered or unexported fields
}

ClawHubSource 通过 ClawHub API 发现和下载 Skill。

func NewClawHubSource added in v0.1.13

func NewClawHubSource() *ClawHubSource

NewClawHubSource 创建 ClawHubSource。

func (*ClawHubSource) CanHandle added in v0.1.13

func (c *ClawHubSource) CanHandle(identifier string) bool

CanHandle 处理纯 skill 名称(不含 / 和 https:// 前缀的标识符)。

func (*ClawHubSource) Fetch added in v0.1.13

func (c *ClawHubSource) Fetch(ctx context.Context, identifier string) (*SkillBundle, error)

Fetch 下载 ClawHub skill zip 包并提取内容。 identifier 为纯 skill 名称(不含 clawhub: 前缀)。

func (*ClawHubSource) FetchVersion added in v0.1.13

func (c *ClawHubSource) FetchVersion(ctx context.Context, slug, version string) (*SkillBundle, error)

FetchVersion 下载指定版本的 ClawHub skill zip 包并提取内容。 slug 为纯 skill 名称(不含 clawhub: 前缀)。 version 为空或 "latest" 时,download URL 不带 version 参数。

func (*ClawHubSource) GetDetail added in v0.1.13

func (c *ClawHubSource) GetDetail(ctx context.Context, slug, version string) (*SkillDetail, *SkillBundle, error)

GetDetail 通过 ClawHub API 获取 skill 元数据,并下载 zip 返回完整详情及 bundle。 从 /api/v1/skills/{slug} 获取 Author、Installs、Version、Tags、Icon 等字段, 再下载 zip 解析 SKILL.md 和文件列表。

func (*ClawHubSource) Inspect added in v0.1.13

func (c *ClawHubSource) Inspect(ctx context.Context, identifier string) (*SkillMeta, error)

Inspect 获取 ClawHub 上 Skill 的元数据。

func (*ClawHubSource) Search added in v0.1.13

func (c *ClawHubSource) Search(ctx context.Context, query string, limit int) ([]SkillMeta, error)

Search 调用 ClawHub search 或 list API。 有关键词时使用 /api/v1/search?q=;无关键词时使用 /api/v1/skills?limit=。

func (*ClawHubSource) SourceID added in v0.1.13

func (c *ClawHubSource) SourceID() string

SourceID 返回源标识。

type GitHubSource

type GitHubSource struct {
	// contains filtered or unexported fields
}

GitHubSource 通过下载 GitHub 仓库 ZIP 获取 Skill。

func NewGitHubSource

func NewGitHubSource() *GitHubSource

NewGitHubSource 创建 GitHubSource。

func (*GitHubSource) CanHandle

func (g *GitHubSource) CanHandle(identifier string) bool

CanHandle 含 "/" 的非 URL 标识符可由 GitHubSource 处理。

func (*GitHubSource) Fetch

func (g *GitHubSource) Fetch(ctx context.Context, identifier string) (*SkillBundle, error)

Fetch 下载 GitHub 仓库 ZIP 并提取 Skill。

func (*GitHubSource) FetchVersion added in v0.1.13

func (g *GitHubSource) FetchVersion(ctx context.Context, identifier, version string) (*SkillBundle, error)

FetchVersion 实现 fetch.VersionedSource。 使用 version 作为分支/tag 名下载 GitHub 仓库(如 v1.2.3 或 main)。

func (*GitHubSource) Inspect

func (g *GitHubSource) Inspect(ctx context.Context, identifier string) (*SkillMeta, error)

Inspect 获取 GitHub 上 Skill 的元数据(不下载附属文件)。

func (*GitHubSource) Search

func (g *GitHubSource) Search(ctx context.Context, query string, limit int) ([]SkillMeta, error)

Search GitHubSource 不支持搜索

func (*GitHubSource) SourceID

func (g *GitHubSource) SourceID() string

SourceID 返回源标识。

type SkillBundle

type SkillBundle struct {
	Meta    SkillMeta
	Content []byte            // SKILL.md 原始内容
	Files   map[string][]byte // 附属文件(相对路径 → 内容)
	TempDir string            // 临时解压目录(调用方负责清理)
}

SkillBundle Fetch 返回的完整 Skill 内容。

type SkillDetail added in v0.1.13

type SkillDetail struct {
	SkillID     string   `json:"skill_id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Version     string   `json:"version"`
	Author      string   `json:"author"`
	Category    string   `json:"category"`
	Tags        []string `json:"tags"`
	Icon        string   `json:"icon,omitempty"`
	SkillMD     string   `json:"skill_md"` // SKILL.md body(不含 frontmatter)
	Files       []string `json:"files"`
}

SkillDetail 表示从 ClawHub zip 中解析出的 skill 详细信息。

type SkillMeta

type SkillMeta struct {
	SkillID     string   `json:"skill_id"`
	Name        string   `json:"name,omitempty"`
	Identifier  string   `json:"identifier"`
	Source      string   `json:"source"`
	TrustLevel  string   `json:"trust_level"`
	Description string   `json:"description"`
	Version     string   `json:"version,omitempty"`
	Author      string   `json:"author,omitempty"`
	Category    string   `json:"category,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	Icon        string   `json:"icon,omitempty"`
	Installs    int64    `json:"installs,omitempty"`
}

SkillMeta 搜索或检查返回的轻量 Skill 信息。

type SkillSource

type SkillSource interface {
	Search(ctx context.Context, query string, limit int) ([]SkillMeta, error)
	Fetch(ctx context.Context, identifier string) (*SkillBundle, error)
	Inspect(ctx context.Context, identifier string) (*SkillMeta, error)
	SourceID() string
	CanHandle(identifier string) bool
}

SkillSource 远程 Skill 源接口。

type SkillsShSource

type SkillsShSource struct {
	// contains filtered or unexported fields
}

SkillsShSource 通过 skills.sh API 搜索 Skill。

func NewSkillsShSource

func NewSkillsShSource() *SkillsShSource

NewSkillsShSource 创建 SkillsShSource。

func (*SkillsShSource) CanHandle

func (s *SkillsShSource) CanHandle(identifier string) bool

CanHandle 含 "/" 的非 URL 标识符可由 SkillsShSource 处理。

func (*SkillsShSource) Fetch

func (s *SkillsShSource) Fetch(ctx context.Context, identifier string) (*SkillBundle, error)

Fetch 通过 skills.sh 搜索后委托 GitHubSource 下载。

func (*SkillsShSource) Inspect

func (s *SkillsShSource) Inspect(ctx context.Context, identifier string) (*SkillMeta, error)

Inspect 检查 skills.sh 上的 Skill 元数据。

func (*SkillsShSource) Search

func (s *SkillsShSource) Search(ctx context.Context, query string, limit int) ([]SkillMeta, error)

Search 调用 skills.sh 搜索 API。

func (*SkillsShSource) SourceID

func (s *SkillsShSource) SourceID() string

SourceID 返回源标识。

type SourceRouter

type SourceRouter struct {
	// contains filtered or unexported fields
}

SourceRouter 管理一组远程 Skill 源,按优先级路由请求。

func NewSourceRouter

func NewSourceRouter() *SourceRouter

NewSourceRouter 创建包含所有内置源的 SourceRouter。

func NewSourceRouterWithSources added in v0.1.1

func NewSourceRouterWithSources(sources ...SkillSource) *SourceRouter

NewSourceRouterWithSources 使用指定源列表创建 SourceRouter。

func (*SourceRouter) Fetch

func (r *SourceRouter) Fetch(ctx context.Context, identifier string) (*SkillBundle, error)

Fetch 按优先级遍历源,返回第一个成功获取的 SkillBundle。

func (*SourceRouter) FetchFromSource added in v0.1.13

func (r *SourceRouter) FetchFromSource(ctx context.Context, identifier, sourceID, version string) (*SkillBundle, error)

FetchFromSource 从指定 sourceID 的源中获取 Skill。 如果 identifier 能被该源直接处理,则直接获取;否则按名称搜索后再获取。 当源实现了 VersionedSource 且 version 非空时,会传入版本参数。

func (*SourceRouter) FetchVersion added in v0.1.13

func (r *SourceRouter) FetchVersion(ctx context.Context, identifier, version string) (*SkillBundle, error)

FetchVersion 按优先级遍历源,返回第一个成功获取的指定版本 SkillBundle。 对于实现了 VersionedSource 的源,会传入 version;否则退化为不带版本的 Fetch。

func (*SourceRouter) ResolveShortName

func (r *SourceRouter) ResolveShortName(ctx context.Context, name string) (*SkillBundle, error)

ResolveShortName 对不含 "/" 的短名称,按 source 优先级依次搜索精确匹配后安装。

func (*SourceRouter) Search

func (r *SourceRouter) Search(ctx context.Context, query string, limit int) ([]SkillMeta, error)

Search 并发向所有源发起搜索,合并结果并去重,按安装量降序排列。

func (*SourceRouter) SearchWithFilter added in v0.1.13

func (r *SourceRouter) SearchWithFilter(ctx context.Context, query string, limit int, filterSources []string) ([]SkillMeta, error)

SearchWithFilter 并发向指定源列表发起搜索;filterSources 为空时搜索全部源。

type UrlSource

type UrlSource struct {
	// contains filtered or unexported fields
}

UrlSource 通过 HTTP 直链下载 SKILL.md。

func NewUrlSource

func NewUrlSource() *UrlSource

NewUrlSource 创建 UrlSource。

func (*UrlSource) CanHandle

func (u *UrlSource) CanHandle(identifier string) bool

CanHandle 以 http:// 或 https:// 开头且路径以 .md 结尾的标识符由 UrlSource 处理。

func (*UrlSource) Fetch

func (u *UrlSource) Fetch(ctx context.Context, identifier string) (*SkillBundle, error)

Fetch 从 URL 下载 SKILL.md 内容。

func (*UrlSource) Inspect

func (u *UrlSource) Inspect(ctx context.Context, identifier string) (*SkillMeta, error)

Inspect 获取 URL 对应 SKILL.md 的元数据。

func (*UrlSource) Search

func (u *UrlSource) Search(ctx context.Context, query string, limit int) ([]SkillMeta, error)

Search UrlSource 不支持搜索。

func (*UrlSource) SourceID

func (u *UrlSource) SourceID() string

SourceID 返回源标识。

type VersionedSource added in v0.1.13

type VersionedSource interface {
	SkillSource
	FetchVersion(ctx context.Context, identifier string, version string) (*SkillBundle, error)
}

VersionedSource 支持版本化获取的 Skill 源接口。 实现此接口的源可处理指定版本的安装请求。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL