skills

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecutableConfig

type ExecutableConfig struct {
	// Runtime 运行时类型,例如 "bash"、"go"、"python"
	Runtime string

	// Entry 入口脚本或命令,例如 "scripts/pdf2md.go"
	Entry string

	// TimeoutSeconds 超时时间(秒),0 表示使用默认
	TimeoutSeconds int
}

ExecutableConfig 可执行 Skill 配置

type ExecutionResult

type ExecutionResult struct {
	SkillName string        // 技能名
	Command   string        // 实际执行的命令
	ExitCode  int           // 退出码
	Stdout    string        // 标准输出
	Stderr    string        // 标准错误
	Duration  time.Duration // 执行时长
}

ExecutionResult 可执行 Skill 的运行结果

type Info

type Info struct {
	// ID Skill 逻辑标识,例如 "pdf-to-markdown" 或 "workflows/code-review"
	// 不包含版本信息(如果有版本,则从目录名中去掉 @version 后得到)。
	ID string

	// Name YAML 中的 name 字段(如果存在)
	Name string

	// Description 描述
	Description string

	// Kind "knowledge" | "executable" | ""
	Kind string

	// Version 可选版本号, 如果目录名中包含 "@version" 后缀, 则提取为版本。
	Version string

	// Path Skill 目录相对 baseDir 的路径
	Path string
}

Info Skill 元信息(用于列表展示)

type Injector

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

Injector 技能注入器

func NewInjector

func NewInjector(ctx context.Context, config *InjectorConfig) (*Injector, error)

NewInjector 创建注入器

func (*Injector) ActivateSkills

func (i *Injector) ActivateSkills(ctx context.Context, skillContext SkillContext) []*SkillDefinition

ActivateSkills 根据上下文返回应当激活的 Skill 列表 这是对内部 getActiveSkills 的公开包装,方便在自定义流程中手动控制注入。

func (*Injector) EnhanceSystemPrompt

func (i *Injector) EnhanceSystemPrompt(ctx context.Context, basePrompt string, skillContext SkillContext) string

EnhanceSystemPrompt 增强系统提示词

func (*Injector) GetActiveSkillNames

func (i *Injector) GetActiveSkillNames(context SkillContext) []string

GetActiveSkillNames 获取激活的技能名称列表

func (*Injector) InjectToSystemPrompt

func (i *Injector) InjectToSystemPrompt(basePrompt string, skills []*SkillDefinition) string

InjectToSystemPrompt 将给定的 Skills 注入到 System Prompt。 与 EnhanceSystemPrompt 不同,这里假设调用方已经决定了要注入哪些 Skills。

func (*Injector) InjectToUserMessage

func (i *Injector) InjectToUserMessage(userMessage string, skills []*SkillDefinition) string

InjectToUserMessage 将激活的 Skills 作为知识库注入到用户消息前。 这主要用于不支持独立 system prompt 的模型。 为了符合「渐进式加载」的设计,这里只注入 Skill 元数据, 具体的 SKILL.md 内容仍然通过文件系统工具按需读取。

func (*Injector) PrepareUserMessage

func (i *Injector) PrepareUserMessage(message string, skillContext SkillContext) string

PrepareUserMessage 准备用户消息(为不支持 system prompt 的模型)

type InjectorConfig

type InjectorConfig struct {
	Loader        *SkillLoader
	EnabledSkills []string
	Provider      provider.Provider
	Capabilities  provider.ProviderCapabilities
}

InjectorConfig 注入器配置

type Manager

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

Manager Skill 管理器,负责在本地文件系统中安装、列出和卸载 Skills。 设计目标类似 Claude Skills API 的本地版本。

func NewManager

func NewManager(baseDir string, fs sandbox.SandboxFS) *Manager

NewManager 创建一个基于本地/沙箱文件系统的 Skill 管理器。 baseDir 为技能包根目录,例如 "skills" 或 "workspace/.claude/skills"。

func (*Manager) DeleteVersion

func (m *Manager) DeleteVersion(ctx context.Context, skillID, version string) error

DeleteVersion 删除某个 Skill 的特定版本。 如果 version 为空, 等价于 Uninstall(skillID)。

func (*Manager) InstallFromDir

func (m *Manager) InstallFromDir(ctx context.Context, skillID string, srcDir string) error

InstallFromDir 从本地目录复制一个 Skill(常用于开发测试)。 srcDir 应包含 SKILL.md。

func (*Manager) InstallFromFiles

func (m *Manager) InstallFromFiles(ctx context.Context, skillID string, files map[string]string) error

InstallFromFiles 从内存中的文件集合安装或更新 Skill。 files 的 key 为相对路径(相对于 skillID 根目录),value 为文件内容。

func (*Manager) InstallFromZip

func (m *Manager) InstallFromZip(ctx context.Context, skillID string, r io.ReaderAt, size int64) error

InstallFromZip 从 zip 数据安装一个 Skill。

  • skillID: 安装后的目录名,例如 "pdf-to-markdown"
  • r: zip 数据流

zip 内部应包含单个根目录或直接包含 SKILL.md;会被展开到 baseDir/skillID 下。

func (*Manager) InstallFromZipBytes

func (m *Manager) InstallFromZipBytes(ctx context.Context, skillID string, data []byte) error

Helper: 从 []byte 安装 zip(方便上层使用)

func (*Manager) InstallVersionFromFiles

func (m *Manager) InstallVersionFromFiles(ctx context.Context, skillID, version string, files map[string]string) error

InstallVersionFromFiles 安装指定 Skill 的某个版本。 如果 version 为空, 等价于 InstallFromFiles(skillID, files)。

func (*Manager) List

func (m *Manager) List(ctx context.Context) ([]Info, error)

List 列出当前 baseDir 下所有可用 Skill 的元信息。

func (*Manager) ListVersions

func (m *Manager) ListVersions(ctx context.Context, skillID string) ([]Info, error)

ListVersions 列出指定 Skill ID 的所有版本(包括无版本的主版本)。

func (*Manager) Uninstall

func (m *Manager) Uninstall(ctx context.Context, skillID string) error

Uninstall 卸载一个 Skill,即删除 baseDir/skillID 目录。 注意:这里直接使用 os.RemoveAll,因为 SandboxFS 暂未提供删除接口; 同时假设 baseDir 对应的是本地可写路径。

type ParamSpec

type ParamSpec struct {
	Type        string   // 参数类型,如 "string" | "number" | "boolean" | "object"
	Description string   // 参数说明
	Required    bool     // 是否必填
	Enum        []string // 枚举值(可选)
}

ParamSpec 参数定义

type ReturnSpec

type ReturnSpec struct {
	Type        string // 返回值类型
	Description string // 返回值说明
}

ReturnSpec 返回值定义

type Runtime

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

Runtime Skill 运行时:负责根据 SkillDefinition.Executable 调用底层 Sandbox 执行脚本

func NewRuntime

func NewRuntime(loader *SkillLoader, sb sandbox.Sandbox) *Runtime

NewRuntime 创建运行时

func (*Runtime) Execute

func (r *Runtime) Execute(ctx context.Context, skillName string, params map[string]string) (*ExecutionResult, error)

Execute 按名称执行一个可执行 Skill。 params 作为环境变量传入脚本(键会被转换为大写,并加上 SKILL_PARAM_ 前缀)。 具体参数到命令行的映射由脚本自身负责,Runtime 不做 Skill 特定解析。

type SkillContext

type SkillContext struct {
	UserMessage string                 // 用户输入
	Command     string                 // 当前命令(如 "/write")
	Files       []string               // 涉及的文件
	Metadata    map[string]interface{} // 额外元数据
}

SkillContext 技能上下文

type SkillDefinition

type SkillDefinition struct {
	// 基础信息
	Name         string   // 技能名 (YAML: name)
	Description  string   // 描述   (YAML: description)
	AllowedTools []string // 允许使用的工具 (YAML: allowed-tools)

	// 位置相关信息(用于在提示词中给出 SKILL.md 路径提示)
	// Path    : 相对于 Skills 根目录的技能路径,例如 "pdfmd" 或 "workflow/consistency-checker"
	// BaseDir : Skills 根目录,相对于沙箱工作目录,例如 "skills" 或 "workspace/skills"
	Path    string
	BaseDir string

	// 类型:
	// - 为空或 "knowledge": 只注入知识
	// - "executable": 可执行 Skill, 搭配 Executable 配置使用
	Kind string

	// 知识库内容
	KnowledgeBase string // 注入到 SystemPrompt 的内容

	// 可执行 Skill 的参数和返回值定义 (可选)
	Parameters map[string]ParamSpec
	Returns    map[string]ReturnSpec

	// 可执行配置 (可选)
	Executable *ExecutableConfig

	// 触发条件
	Triggers []TriggerConfig
}

SkillDefinition Skill 定义

type SkillLoader

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

SkillLoader 技能加载器

func NewLoader

func NewLoader(baseDir string, fs sandbox.SandboxFS) *SkillLoader

NewLoader 创建加载器

func (*SkillLoader) Discover

func (sl *SkillLoader) Discover(ctx context.Context) ([]string, error)

Discover 发现所有可用技能

func (*SkillLoader) Load

func (sl *SkillLoader) Load(ctx context.Context, skillPath string) (*SkillDefinition, error)

Load 加载技能定义

func (*SkillLoader) LoadMultiple

func (sl *SkillLoader) LoadMultiple(ctx context.Context, skillPaths []string) (map[string]*SkillDefinition, error)

LoadMultiple 批量加载技能

type TriggerConfig

type TriggerConfig struct {
	Type      string   // "keyword" | "context" | "always" | "file_pattern"
	Keywords  []string // 关键词列表 (type=keyword)
	Condition string   // 条件描述   (type=context)
	Pattern   string   // 文件模式   (type=file_pattern),例如 "**/*.go"
}

TriggerConfig 触发配置

Jump to

Keyboard shortcuts

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