skills

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFrontmatter = errors.New("invalid frontmatter format")

Functions

func BuildSkillPrompt

func BuildSkillPrompt(ctx context.Context, allowed ...string) string

BuildSkillPrompt builds the skill injection prompt.

It loads from local (.dscli/skills) and global (~/.dscli/skills) stores, merging with local priority. Two injection strategies:

  1. auto_inject skills: full content injected directly, no LLM fetch needed
  2. manual skills: name/description list only, LLM fetches via skill_by_name

Use skill_search tool for keyword-based discovery of manual skills. Store loading errors are gracefully degraded to empty stores so that skill failures never block conversation.

When allowed is empty or nil, all skills are included (backward compatible). When allowed contains "all", all skills are included. When allowed contains specific names, only those skills are included.

func FormatSkillMD added in v0.7.5

func FormatSkillMD(skill *Skill) (string, error)

FormatSkillMD 生成带 frontmatter 的 SKILL.md 内容,用于 skill_save 工具。 只序列化 frontmatter 必要字段(name, description, keywords, auto_inject), 正文部分直接拼接。

func HandleSkillCreate added in v0.7.8

func HandleSkillCreate(ctx context.Context, name, description, author, content, keywordsStr string, autoInject bool) (result, warning string, err error)

func LoadSkills

func LoadSkills(dir string) (skills map[string]Skill)

func ParseSkill

func ParseSkill(path string, skill *Skill) error

ParseSkill 解析指定路径的 SKILL.md 文件,填充 skill 对象。 path 必须是 SKILL.md 文件的完整路径。

func Query

func Query(q string) (string, error)

Query 在本地和全局 store 中搜索技能,返回按分数排序的格式化结果。

func ResetLocalStore added in v0.7.8

func ResetLocalStore()

ResetLocalStore clears the cached local store, forcing re-initialization on next LocalStore() call. This is primarily for tests that switch between different ProjectRoot directories.

func ResolveSkillDir added in v0.7.9

func ResolveSkillDir(name string) string

ResolveSkillDir resolves a skill name to its directory path by looking up local and global stores. Returns empty string if the skill is not found. The built-in dscli skill (virtual, no directory) is NOT resolved by this function.

func SetAutoInject

func SetAutoInject(name string, autoInject, global bool) error

SetAutoInject 设置技能的 auto_inject 属性。 优先修改本地 store;若指定了 global 则修改全局 store。

func SkillFiles

func SkillFiles(dir string) (skillFiles []string)

SkillFiles returns all skill files (SKILL.md) under `dir`. It walks the directory tree recursively and returns absolute paths. Skips common non-skill directories (.git, node_modules, etc.) and respects a max depth bound to prevent runaway scanning in large directory trees.

func Use

func Use(name string) (content string, err error)

func ValidateSkillDir added in v0.7.9

func ValidateSkillDir(dir string) []string

ValidateSkillDir validates a skill directory against the Agent Skills spec. Returns a list of human-readable validation errors, or empty slice if valid.

Checks performed (aligned with skills-ref validate command):

  • Path exists and is a directory
  • SKILL.md exists (prefers SKILL.md, accepts skill.md)
  • YAML frontmatter is valid
  • Frontmatter is a mapping (not a list or scalar)
  • Required fields: name, description
  • Name format: lowercase, Unicode letters allowed, no leading/trailing hyphens, no consecutive hyphens, max 64 chars
  • Directory name matches skill name (NFKC normalized)
  • Description: non-empty, max 1024 chars
  • Compatibility: if present, must be string, max 500 chars
  • No unexpected fields (spec allows 6 fields + dscli extensions: keywords, auto_inject)

Types

type Resource

type Resource struct {
	Name        string `yaml:"name,omitzero"`
	Description string `yaml:"description,omitzero"`
	Path        string `yaml:"path,omitzero"`
}

type ScoredSkill added in v0.7.8

type ScoredSkill struct {
	Skill Skill
	Score int
}

ScoredSkill 带匹配分数的技能,用于搜索结果排序。

type Skill

type Skill struct {
	Name        string     `yaml:"name,omitzero"`
	Description string     `yaml:"description,omitzero"`
	Author      string     `yaml:"author,omitzero"`  // 署名,如 "Bohr <bohr@dscli.io>"(可选)
	Path        string     `yaml:"path,omitzero"`    // 技能根目录
	Content     string     `yaml:"content,omitzero"` // SKILL.md 正文
	Keywords    []string   `yaml:"keywords,omitzero"`
	Scripts     []Resource `yaml:"scripts,omitzero"`
	References  []Resource `yaml:"references,omitzero"`
	Templates   []Resource `yaml:"templates,omitzero"`
	Examples    []Resource `yaml:"examples,omitzero"`    // 示例文件
	AutoInject  bool       `yaml:"auto_inject,omitzero"` // 自动注入到对话上下文,无需 LLM 主动获取
	Source      string     `yaml:"-"`                    // "local" 或 "global",由加载侧注入
}

func (*Skill) FormatFull

func (skill *Skill) FormatFull() string

FormatFull 格式化技能的完整信息,供 LLM 使用。 包含:摘要、正文、资源列表(仅路径和描述,不含内容,LLM 按需读取)。

func (*Skill) Score added in v0.7.9

func (skill *Skill) Score(query string) int

Score computes a relevance score for this skill against a query string. Scoring rules:

  1. Exact name match: +100
  2. Query token in name or name tokens: +10 each
  3. Query token in explicit keywords: +5 each
  4. Query token in description: +1 each

func (*Skill) Summary

func (skill *Skill) Summary() string

type SkillInfo

type SkillInfo struct {
	Name       string `json:"name"`
	Scope      string `json:"scope"`       // "local" 或 "global"
	AutoInject bool   `json:"auto_inject"` // 是否自动注入到对话上下文
}

SkillInfo 包含技能的基本信息和作用域

func ListAll

func ListAll() ([]SkillInfo, error)

ListAll 返回所有技能(本地、全局和内置)的列表。 优先级:local > global > built-in(同名时只保留最高优先级的)。

type Store

type Store struct {
	Skills   map[string]Skill    `yaml:"skills,omitzero"`
	Keywords map[string][]string `yaml:"keywords,omitzero"`
	// contains filtered or unexported fields
}

func GlobalStore

func GlobalStore() (*Store, error)

func LocalStore

func LocalStore() (*Store, error)

func NewSkillStore

func NewSkillStore(dir, source string) (*Store, error)

func (*Store) List

func (store *Store) List() []string

List 返回存储中的所有技能名称

func (*Store) Load

func (store *Store) Load() (err error)

func (*Store) Query

func (store *Store) Query(query string) (matched map[string]Skill)

Query 使用 token 匹配搜索技能。 保留向后兼容的 map 返回类型。

func (*Store) QueryScored added in v0.7.8

func (store *Store) QueryScored(query string) []ScoredSkill

QueryScored 使用 token 匹配搜索技能,返回按分数降序排列的结果。

评分策略(按优先级):

  1. 精确名称匹配(大小写不敏感):+100
  2. 查询 token 命中名称整体或名称分词:每个 +10
  3. 查询 token 命中显式关键词(skill.Keywords):每个 +5
  4. 查询 token 命中描述词(回退):每个 +1

匹配采用双向子串包含:token 包含 keyword 或 keyword 包含 token。 所有匹配均为大小写不敏感。

func (*Store) Save

func (store *Store) Save() error

func (*Store) SetAutoInject

func (store *Store) SetAutoInject(name string, autoInject bool) error

SetAutoInject 设置指定技能的 auto_inject 属性并保存。

func (*Store) Use

func (store *Store) Use(name string) (content string, err error)

Use looks up a skill by name within this specific store. It does not check global or built-in skills. For full resolution including fallback, use the package-level Use function.

Source Files

  • skill.go
  • store.go
  • validate.go

Jump to

Keyboard shortcuts

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