skills

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package skills provides OpenClaw/ClawHub skill loading and management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSearchPaths

func DefaultSearchPaths() []string

DefaultSearchPaths returns the default skill directories to search.

func InjectIntoPrompt

func InjectIntoPrompt(systemPrompt string, skills []*Skill, cfg InjectConfig) string

InjectIntoPrompt appends skill content to the system prompt. Skills with missing requirements are skipped unless IncludeDisabled is true.

Types

type InjectConfig

type InjectConfig struct {
	MaxSkills       int    // Maximum skills to inject (0 = unlimited)
	IncludeDisabled bool   // Include skills with missing requirements
	Separator       string // Separator between skills
}

InjectConfig controls how skills are injected into prompts.

func DefaultInjectConfig

func DefaultInjectConfig() InjectConfig

DefaultInjectConfig returns sensible defaults.

type Installer

type Installer struct {
	ID      string   `json:"id"`
	Kind    string   `json:"kind"`              // brew, apt, go, npm, etc.
	Formula string   `json:"formula,omitempty"` // For brew
	Package string   `json:"package,omitempty"` // For apt
	Module  string   `json:"module,omitempty"`  // For go install
	Bins    []string `json:"bins,omitempty"`    // Binaries provided
	Label   string   `json:"label,omitempty"`   // Human-readable label
}

Installer specifies how to install a dependency.

type Manager added in v0.7.0

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

Manager handles loading and managing skills from multiple sources.

func NewManager added in v0.7.0

func NewManager(cfg ManagerConfig) *Manager

NewManager creates a new skill manager with the given configuration.

func (*Manager) All added in v0.7.0

func (m *Manager) All() []*Skill

All returns all loaded skills.

func (*Manager) Available added in v0.7.0

func (m *Manager) Available() []*Skill

Available returns skills that have all requirements met.

func (*Manager) AvailableCount added in v0.7.0

func (m *Manager) AvailableCount() int

AvailableCount returns the number of available skills.

func (*Manager) Count added in v0.7.0

func (m *Manager) Count() int

Count returns the total number of loaded skills.

func (*Manager) Get added in v0.7.0

func (m *Manager) Get(name string) *Skill

Get returns a skill by name, or nil if not found.

func (*Manager) Load added in v0.7.0

func (m *Manager) Load() error

Load discovers and loads skills from all configured sources. Skills from directories override embedded skills with the same name. Includes/excludes filters are applied after loading.

type ManagerConfig added in v0.7.0

type ManagerConfig struct {
	// Packs are embedded skill packs to load.
	Packs []fs.FS

	// Dirs are filesystem directories to search for skills.
	// Directory skills override embedded skills with the same name.
	Dirs []string

	// Includes limits loaded skills to only these names.
	// If empty, all skills are included.
	Includes []string

	// Excludes prevents these skills from being loaded.
	// Applied after includes.
	Excludes []string
}

ManagerConfig configures the skill manager.

type OpenClawMeta

type OpenClawMeta struct {
	Emoji    string      `json:"emoji,omitempty"`
	Requires *Requires   `json:"requires,omitempty"`
	Install  []Installer `json:"install,omitempty"`
	Always   bool        `json:"always,omitempty"`
}

OpenClawMeta is the openclaw-specific metadata block.

type RequirementError

type RequirementError struct {
	Type    string      // "binary" or "env"
	Name    string      // Name of the missing requirement
	Skill   string      // Skill that requires it
	Install []Installer // How to fix (for binaries)
}

RequirementError describes a missing requirement.

func (*RequirementError) Error

func (e *RequirementError) Error() string

func (*RequirementError) InstallHint

func (e *RequirementError) InstallHint() string

InstallHint returns a human-readable install suggestion.

type Requires

type Requires struct {
	Bins    []string `json:"bins,omitempty"`    // Required binaries on PATH
	AnyBins []string `json:"anyBins,omitempty"` // At least one required
	Env     []string `json:"env,omitempty"`     // Required environment variables
}

Requires specifies skill prerequisites.

type Skill

type Skill struct {
	// From YAML frontmatter
	Name        string    `yaml:"name"`
	Description string    `yaml:"description"`
	Homepage    string    `yaml:"homepage,omitempty"`
	Metadata    SkillMeta `yaml:"metadata"`

	// Parsed from file
	Content    string      `yaml:"-"` // Markdown body
	Path       string      `yaml:"-"` // Directory path (empty if embedded)
	Source     SkillSource `yaml:"-"` // Where the skill was loaded from
	HasHooks   bool        `yaml:"-"` // Has hooks/ directory
	HasScripts bool        `yaml:"-"` // Has scripts/ directory
}

Skill represents a loaded SKILL.md file.

func Discover

func Discover(dirs []string) ([]*Skill, error)

Discover finds all skills in the given directories. Skills are deduplicated by name (first occurrence wins).

func DiscoverFromFS added in v0.7.0

func DiscoverFromFS(fsys fs.FS, seen map[string]bool) ([]*Skill, error)

DiscoverFromFS finds all skills in an embedded filesystem. Skills are expected at skills/<name>/SKILL.md. The seen map is used to track already-loaded skills for deduplication.

func ExcludeByName

func ExcludeByName(skills []*Skill, names []string) []*Skill

ExcludeByName returns skills not matching any of the given names.

func FilterAvailable

func FilterAvailable(skills []*Skill) []*Skill

FilterAvailable returns only skills that have all requirements met.

func FilterByName

func FilterByName(skills []*Skill, names []string) []*Skill

FilterByName returns skills matching any of the given names.

func Load

func Load(skillDir string) (*Skill, error)

Load parses a single skill from its directory.

func Parse

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

Parse extracts skill data from SKILL.md content.

func (*Skill) CheckRequirements

func (s *Skill) CheckRequirements() []error

CheckRequirements verifies all skill prerequisites. Returns a slice of errors for missing requirements.

func (*Skill) Emoji

func (s *Skill) Emoji() string

Emoji returns the skill's emoji or empty string.

func (*Skill) IsAvailable

func (s *Skill) IsAvailable() bool

IsAvailable returns true if all requirements are met.

type SkillMeta

type SkillMeta struct {
	OpenClaw *OpenClawMeta `json:"openclaw,omitempty"`
}

SkillMeta contains platform-specific metadata.

type SkillSource added in v0.7.0

type SkillSource string

SkillSource indicates where a skill was loaded from.

const (
	// SourceDirectory indicates the skill was loaded from a filesystem directory.
	SourceDirectory SkillSource = "directory"
	// SourceEmbedded indicates the skill was loaded from an embedded skill pack.
	SourceEmbedded SkillSource = "embedded"
)

Directories

Path Synopsis
Package compiled provides interfaces for compiled Go skills.
Package compiled provides interfaces for compiled Go skills.
remote
mcp
Package mcp provides a compiled.Skill implementation that wraps an MCP server.
Package mcp provides a compiled.Skill implementation that wraps an MCP server.
openapi
Package openapi provides a compiled.Skill implementation that wraps an OpenAPI spec.
Package openapi provides a compiled.Skill implementation that wraps an OpenAPI spec.

Jump to

Keyboard shortcuts

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