skills

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDuplicateSkill indicates an attempt to register the same name twice.
	ErrDuplicateSkill = errors.New("skills: duplicate registration")
	// ErrUnknownSkill is returned by Execute/Get when a skill is missing.
	ErrUnknownSkill = errors.New("skills: unknown skill")
)

Functions

func SetReadFileForTest

func SetReadFileForTest(fn func(string) ([]byte, error)) (restore func())

SetReadFileForTest swaps the file reader; intended for white-box tests only.

Types

type Activation

type Activation struct {
	Skill  *Skill
	Score  float64
	Reason string
}

Activation is a resolved auto-activation candidate.

func (Activation) Definition

func (a Activation) Definition() Definition

Definition returns metadata for the activation.

type ActivationContext

type ActivationContext struct {
	Prompt   string
	Channels []string
	Tags     map[string]string
	Traits   []string
	Metadata map[string]any
}

ActivationContext captures conversational state used for auto-activation.

func (ActivationContext) Clone

Clone produces an isolated copy of the activation context.

type Definition

type Definition struct {
	Name        string
	Description string
	Priority    int
	MutexKey    string
	// DisableAutoActivation keeps the skill available for manual invocation
	// while excluding it from automatic activation matching.
	DisableAutoActivation bool
	Metadata              map[string]string
	Matchers              []Matcher
}

Definition describes a declarative skill registration entry.

func (Definition) Validate

func (d Definition) Validate() error

Validate performs cheap sanity checks before accepting a definition.

type Handler

type Handler interface {
	Execute(context.Context, ActivationContext) (Result, error)
}

Handler executes a skill.

type HandlerFunc

type HandlerFunc func(context.Context, ActivationContext) (Result, error)

HandlerFunc adapts ordinary functions to Handler.

func (HandlerFunc) Execute

func (fn HandlerFunc) Execute(ctx context.Context, ac ActivationContext) (Result, error)

Execute implements Handler.

type KeywordMatcher

type KeywordMatcher struct {
	All []string
	Any []string
}

KeywordMatcher inspects prompt text for keywords.

func (KeywordMatcher) Match

Match implements Matcher.

type LoaderOptions

type LoaderOptions struct {
	ProjectRoot string
	// Deprecated: user-level scanning has been removed; this field is ignored.
	UserHome string
	// Deprecated: user-level scanning has been removed; this flag is ignored.
	EnableUser bool
	// FS is the filesystem abstraction layer for loading skills.
	// If nil, falls back to os.* functions for backward compatibility.
	FS *config.FS
}

LoaderOptions controls how skills are discovered from the filesystem.

type MatchResult

type MatchResult struct {
	Matched bool
	Score   float64
	Reason  string
}

MatchResult represents the outcome of a matcher evaluation.

func (MatchResult) BetterThan

func (r MatchResult) BetterThan(other MatchResult) bool

BetterThan orders two match results. Unmatched entries always lose, then higher scores are preferred. When scores tie reasons act as a tiebreaker to keep deterministic ordering.

type Matcher

type Matcher interface {
	Match(ActivationContext) MatchResult
}

Matcher evaluates whether the activation context should trigger a skill.

type MatcherFunc

type MatcherFunc func(ActivationContext) MatchResult

MatcherFunc adapts a function to Matcher.

func (MatcherFunc) Match

Match implements Matcher.

type Registry

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

Registry coordinates skill registration and activation.

func NewRegistry

func NewRegistry() *Registry

NewRegistry builds an empty registry.

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, name string, ac ActivationContext) (Result, error)

Execute invokes a named skill.

func (*Registry) Get

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

Get fetches a skill by name.

func (*Registry) List

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

List returns the registered skill definitions sorted by priority + name.

func (*Registry) Match

func (r *Registry) Match(ctx ActivationContext) []Activation

Match evaluates all auto-activating skills against the provided context while enforcing priority ordering and mutex groups.

func (*Registry) Register

func (r *Registry) Register(def Definition, handler Handler) error

Register adds a skill definition + handler pair.

type Result

type Result struct {
	Skill    string
	Output   any
	Metadata map[string]any
}

Result captures the output from a skill execution.

type Skill

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

Skill represents a single registered skill.

func (*Skill) Definition

func (s *Skill) Definition() Definition

Definition returns an immutable copy of the skill metadata.

func (*Skill) Execute

func (s *Skill) Execute(ctx context.Context, ac ActivationContext) (Result, error)

Execute runs the skill handler.

func (*Skill) Handler

func (s *Skill) Handler() Handler

Handler exposes the underlying skill handler for observability and testing.

type SkillFile

type SkillFile struct {
	Name     string
	Path     string
	Metadata SkillMetadata
	// contains filtered or unexported fields
}

SkillFile captures an on-disk SKILL.md entry.

type SkillMetadata

type SkillMetadata struct {
	Name          string            `yaml:"name"`
	Description   string            `yaml:"description"`
	License       string            `yaml:"license,omitempty"`
	Compatibility string            `yaml:"compatibility,omitempty"`
	Metadata      map[string]string `yaml:"metadata,omitempty"`
	AllowedTools  ToolList          `yaml:"allowed-tools,omitempty"`
}

SkillMetadata mirrors the YAML frontmatter fields inside SKILL.md.

type SkillRegistration

type SkillRegistration struct {
	Definition Definition
	Handler    Handler
}

SkillRegistration wires a definition to its handler.

func LoadFromFS

func LoadFromFS(opts LoaderOptions) ([]SkillRegistration, []error)

LoadFromFS loads skills from the filesystem. Errors are aggregated so one broken file will not block others. Duplicate names are skipped with a warning entry in the error list.

type TagMatcher

type TagMatcher struct {
	Require map[string]string
	Exclude map[string]string
}

TagMatcher enforces metadata tag requirements/exclusions.

func (TagMatcher) Match

Match implements Matcher.

type ToolList added in v0.5.1

type ToolList []string

ToolList supports YAML string or sequence, normalizing to a de-duplicated list.

func (*ToolList) UnmarshalYAML added in v0.5.1

func (t *ToolList) UnmarshalYAML(value *yaml.Node) error

type TraitMatcher

type TraitMatcher struct {
	Traits []string
}

TraitMatcher matches against declared user/system traits.

func (TraitMatcher) Match

Match implements Matcher.

Jump to

Keyboard shortcuts

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