Documentation
¶
Index ¶
- Variables
- func BuildSkillPrompt(ctx context.Context, allowed ...string) string
- func FormatSkillMD(skill *Skill) (string, error)
- func HandleSkillCreate(ctx context.Context, name, description, author, content, keywordsStr string, ...) (result, warning string, err error)
- func LoadSkills(dir string) (skills map[string]Skill)
- func ParseSkill(path string, skill *Skill) error
- func Query(q string) (string, error)
- func ResetLocalStore()
- func ResolveSkillDir(name string) string
- func SetAutoInject(name string, autoInject, global bool) error
- func SkillFiles(dir string) (skillFiles []string)
- func Use(name string) (content string, err error)
- func ValidateSkillDir(dir string) []string
- type Resource
- type ScoredSkill
- type Skill
- type SkillInfo
- type Store
- func (store *Store) List() []string
- func (store *Store) Load() (err error)
- func (store *Store) Query(query string) (matched map[string]Skill)
- func (store *Store) QueryScored(query string) []ScoredSkill
- func (store *Store) Save() error
- func (store *Store) SetAutoInject(name string, autoInject bool) error
- func (store *Store) Use(name string) (content string, err error)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func BuildSkillPrompt ¶
BuildSkillPrompt builds the skill injection prompt.
It loads from local (.dscli/skills) and global (~/.dscli/skills) stores, merging with local priority. Two injection strategies:
- auto_inject skills: full content injected directly, no LLM fetch needed
- 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
FormatSkillMD 生成带 frontmatter 的 SKILL.md 内容,用于 skill_save 工具。 只序列化 frontmatter 必要字段(name, description, keywords, auto_inject), 正文部分直接拼接。
func HandleSkillCreate ¶ added in v0.7.8
func ParseSkill ¶
ParseSkill 解析指定路径的 SKILL.md 文件,填充 skill 对象。 path 必须是 SKILL.md 文件的完整路径。
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
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 ¶
SetAutoInject 设置技能的 auto_inject 属性。 优先修改本地 store;若指定了 global 则修改全局 store。
func SkillFiles ¶
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 ValidateSkillDir ¶ added in v0.7.9
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 ScoredSkill ¶ added in v0.7.8
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 ¶
FormatFull 格式化技能的完整信息,供 LLM 使用。 包含:摘要、正文、资源列表(仅路径和描述,不含内容,LLM 按需读取)。
func (*Skill) Score ¶ added in v0.7.9
Score computes a relevance score for this skill against a query string. Scoring rules:
- Exact name match: +100
- Query token in name or name tokens: +10 each
- Query token in explicit keywords: +5 each
- Query token in description: +1 each
type SkillInfo ¶
type SkillInfo struct {
Name string `json:"name"`
Scope string `json:"scope"` // "local" 或 "global"
AutoInject bool `json:"auto_inject"` // 是否自动注入到对话上下文
}
SkillInfo 包含技能的基本信息和作用域
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 (*Store) Query ¶
Query 使用 token 匹配搜索技能。 保留向后兼容的 map 返回类型。
func (*Store) QueryScored ¶ added in v0.7.8
func (store *Store) QueryScored(query string) []ScoredSkill
QueryScored 使用 token 匹配搜索技能,返回按分数降序排列的结果。
评分策略(按优先级):
- 精确名称匹配(大小写不敏感):+100
- 查询 token 命中名称整体或名称分词:每个 +10
- 查询 token 命中显式关键词(skill.Keywords):每个 +5
- 查询 token 命中描述词(回退):每个 +1
匹配采用双向子串包含:token 包含 keyword 或 keyword 包含 token。 所有匹配均为大小写不敏感。
func (*Store) SetAutoInject ¶
SetAutoInject 设置指定技能的 auto_inject 属性并保存。
Source Files
¶
- skill.go
- store.go
- validate.go