skill

package
v1.3.11 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package skill 将技能指令按需注入 system prompt。 Keywords 匹配到用户输入(或未配置 Keywords)的 skill 才会被注入,节省 token。 技能源支持代码内定义(New)与文件系统目录加载(NewFromFS)。

文件布局遵循标准 skill 规范:dir/<skill>/SKILL.md 是唯一必需文件, frontmatter 提供元数据(name/description,缺省回落目录名与正文首行), frontmatter 之后的正文是指令。scripts/、references/、assets/ 等子资源 由正文相对路径引用(模型用文件工具按需读取),加载器不感知。

Index

Constants

View Source
const SkillFile = "SKILL.md"

SkillFile 是技能的指令文件名。

Variables

This section is empty.

Functions

func DirOf added in v1.3.7

func DirOf(path string) string

DirOf 从 SKILL.md 的 FS 路径提取技能目录名(技能的稳定身份: frontmatter name 仅是显示名,启停/删除按目录名定位)。 形如 dir/<skill>/SKILL.md → <skill>;无目录层级时返回空串。

Types

type Hook

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

func New

func New(skills ...Skill) *Hook

func NewFromFS

func NewFromFS(ctx context.Context, fsys fs.FileSystem, dir string) (*Hook, error)

NewFromFS 从文件系统加载技能:dir 下每个含 SKILL.md 的子目录是一个 技能;无 SKILL.md 的目录跳过。

func (*Hook) Name

func (h *Hook) Name() string

func (*Hook) OnStart

func (h *Hook) OnStart(_ context.Context, state *types.LoopState) error

type Skill

type Skill struct {
	Name        string
	Description string
	// Instructions 是注入给模型的完整指令内容(已剥离 frontmatter)。
	Instructions string
	// Keywords 命中用户输入则注入;为空表示总是注入(仅代码内定义用,
	// 文件加载不提供)。
	Keywords []string
	// Path 是 SKILL.md 的 FS 相对路径(宿主提示"全文见此"用)。
	Path string
}

func LoadDir

func LoadDir(ctx context.Context, fsys fs.FileSystem, dir string) ([]Skill, error)

func ParseSkill added in v1.3.11

func ParseSkill(dir string, data []byte) Skill

ParseSkill 从 SKILL.md 内容解析技能,供宿主内嵌技能加载(go:embed 等 非 FileSystem 来源)。dir 是技能目录名(name 缺省回落与 Path 用)。

Jump to

Keyboard shortcuts

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