Help us shape the future of Go! Take the 2026 Go Developer Survey

skill

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package skill 实现 Agent Skills 开放标准(https://agentskills.io)。

一个技能就是一份带 YAML frontmatter 的 markdown 文档(SKILL.md):frontmatter 声明 name / description 等元信息,正文是指令内容。技能只做「上下文注入」,不是 可执行工具——采用渐进式披露(progressive disclosure):

  • 仅把技能元信息(name / description / location)以 XML 注入系统提示词;
  • 正文(Instructions)不注入,模型判断需要时按 location 自行读取 SKILL.md 文件。

设计参考 crush/internal/skills 与 opencode/internal/skills。

Index

Constants

View Source
const (
	// SkillFileName 是技能描述文件的文件名。
	SkillFileName = "SKILL.md"
	// MaxNameLength 是技能名允许的最大长度。
	MaxNameLength = 64
	// MaxDescriptionLength 是技能描述允许的最大长度。
	MaxDescriptionLength = 1024
)

Variables

This section is empty.

Functions

func DiscoverWithStates added in v0.1.5

func DiscoverWithStates(paths []string) ([]*Skill, []*SkillState)

DiscoverWithStates 发现给定路径下所有合法技能,并返回每个文件的发现状态。

func ToPromptXML added in v0.1.5

func ToPromptXML(skills []*Skill) string

ToPromptXML 生成注入系统提示词的 <available_skills> XML。

仅包含元信息(name / description / location),刻意不含指令正文——正文由模型 按需读取,避免一次性塞满上下文。DisableModelInvocation 的技能会被排除。

Types

type DiscoveryState added in v0.1.5

type DiscoveryState int

DiscoveryState 表示单个技能文件的发现结果。

const (
	// StateNormal 表示技能解析并校验成功。
	StateNormal DiscoveryState = iota
	// StateError 表示扫描 / 解析 / 校验失败。
	StateError
)

type Registry

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

Registry 持有一组已发现的技能,提供按名解析与提示词注入。

技能按名称唯一;同名后注册者覆盖先注册者(用户技能覆盖内置技能)。

Registry 支持在程序运行期热更新(Register / Unregister),因此内部用读写锁 保护:一次 Agent 运行读取技能元信息的同时,前端可以新增 / 修改 / 删除技能。

func NewRegistry

func NewRegistry() *Registry

NewRegistry 创建空注册表。

func NewRegistryWith

func NewRegistryWith(skills ...*Skill) *Registry

NewRegistryWith 创建注册表并注册给定技能。

func (*Registry) Filter added in v0.1.5

func (r *Registry) Filter(names ...string) *Registry

Filter 返回仅包含指定名称(保持升序、去重)的新注册表;names 为空时返回全部技能。

func (*Registry) Get

func (r *Registry) Get(name string) (*Skill, bool)

Get 按名称解析技能。

func (*Registry) Has

func (r *Registry) Has(name string) bool

Has 报告指定技能是否已注册。

func (*Registry) List

func (r *Registry) List() []*Skill

List 返回全部技能(按名称升序)。

func (*Registry) Names

func (r *Registry) Names() []string

Names 返回全部技能名(升序)。

func (*Registry) PromptBlock added in v0.1.5

func (r *Registry) PromptBlock(selected ...string) string

PromptBlock 把技能元信息(selected 为空表示全部)拼接为注入系统提示词的 markdown 块。

仅注入 name / description / location,不含指令正文;无匹配技能时返回空字符串。

func (*Registry) Register

func (r *Registry) Register(s *Skill)

Register 注册技能;nil 或空名技能会被忽略,同名覆盖。

func (*Registry) Unregister added in v0.1.5

func (r *Registry) Unregister(name string)

Unregister 按名称移除技能;不存在时无操作。

type Skill

type Skill struct {
	Name                   string `yaml:"name" json:"name"`
	Description            string `yaml:"description" json:"description"`
	UserInvocable          bool   `yaml:"user-invocable" json:"user_invocable"`
	DisableModelInvocation bool   `yaml:"disable-model-invocation" json:"disable_model_invocation"`

	// 以下字段不参与 frontmatter 解析,由加载过程填充。
	Instructions  string `yaml:"-" json:"instructions,omitempty"`    // 指令正文
	Path          string `yaml:"-" json:"path,omitempty"`            // 技能目录
	SkillFilePath string `yaml:"-" json:"skill_file_path,omitempty"` // SKILL.md 路径
}

Skill 表示一份解析后的 SKILL.md。

func Deduplicate added in v0.1.5

func Deduplicate(all []*Skill) []*Skill

Deduplicate 按名称去重;同名时后出现的覆盖先出现的(用户技能覆盖内置技能)。

func Discover added in v0.1.5

func Discover(paths []string) []*Skill

Discover 发现给定路径下所有合法技能。

func Filter added in v0.1.5

func Filter(all []*Skill, disabled []string) []*Skill

Filter 移除名称出现在 disabled 列表中的技能。

func Parse added in v0.1.5

func Parse(path string) (*Skill, error)

Parse 从磁盘解析一个 SKILL.md 文件。

func ParseContent added in v0.1.5

func ParseContent(content []byte) (*Skill, error)

ParseContent 从原始字节解析 SKILL.md。

func (*Skill) FormatInvocation added in v0.1.5

func (s *Skill) FormatInvocation() string

FormatInvocation 生成把技能正文加载到上下文时的 XML 块。

func (*Skill) Marshal added in v0.1.5

func (s *Skill) Marshal() ([]byte, error)

Marshal 把技能序列化为 SKILL.md 内容(YAML frontmatter + 正文)。

与 Parse / ParseContent 互逆:Save 出来的文件应能被 Parse 原样读回。

func (*Skill) Validate added in v0.1.5

func (s *Skill) Validate() error

Validate 校验技能是否满足规范要求。

type SkillState added in v0.1.5

type SkillState struct {
	Name  string
	Path  string
	State DiscoveryState
	Err   error
}

SkillState 描述单个技能文件的最新发现状态。

type Store added in v0.1.5

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

Store 把技能以 SKILL.md 的形式持久化到某个根目录(通常为 $BaseDir/.skills)。

磁盘是用户技能的唯一真实来源:运行期新增 / 修改 / 删除都会落盘,进程重启后 由 Discover 重新加载。这样既能保证「程序运行中也能改技能」,又不会因为进程 重启而丢失改动。内存中的 Registry 只是磁盘内容的一份可热更新的缓存。

func NewStore added in v0.1.5

func NewStore(dir string) *Store

NewStore 创建以 dir 为根目录的技能存储;dir 为空时视为未配置。

func (*Store) Available added in v0.1.5

func (s *Store) Available() bool

Available 报告存储是否已配置根目录。

func (*Store) Contains added in v0.1.5

func (s *Store) Contains(path string) bool

Contains 报告 path 是否位于该 Store 的根目录之下。 用于限制只允许删除 / 修改存储在用户技能目录内的技能,避免误删内置或外部技能。

func (*Store) Delete added in v0.1.5

func (s *Store) Delete(name string) error

Delete 删除名为 name 的技能目录;目录不存在时视为成功(幂等)。

func (*Store) Dir added in v0.1.5

func (s *Store) Dir() string

Dir 返回存储根目录。

func (*Store) Save added in v0.1.5

func (s *Store) Save(sk *Skill) error

Save 把技能写入 <dir>/<name>/SKILL.md(写入前做规范校验)。name 作为目录名。

func (*Store) SkillDir added in v0.1.5

func (s *Store) SkillDir(name string) string

SkillDir 返回名为 name 的技能目录 <dir>/<name>。

func (*Store) SkillPath added in v0.1.5

func (s *Store) SkillPath(name string) string

SkillPath 返回名为 name 的技能文件路径 <dir>/<name>/SKILL.md。

Jump to

Keyboard shortcuts

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