skill

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsGitHubURL

func IsGitHubURL(rawURL string) bool

IsGitHubURL returns true if the URL points to github.com.

func RenderSkillMD

func RenderSkillMD(entry *SkillEntry) ([]byte, error)

RenderSkillMD renders a SkillEntry to SKILL.md format.

Types

type Executor

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

Executor safely executes skills.

func NewExecutor

func NewExecutor(logger *zap.SugaredLogger) *Executor

NewExecutor creates a new skill executor.

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, skill SkillEntry, params map[string]interface{}) (interface{}, error)

Execute runs a skill with the given parameters.

func (*Executor) ValidateScript

func (e *Executor) ValidateScript(script string) error

ValidateScript checks a script for dangerous patterns.

type FileSkillStore

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

FileSkillStore implements SkillStore using .lango/skills/<name>/SKILL.md files.

func NewFileSkillStore

func NewFileSkillStore(dir string, logger *zap.SugaredLogger) *FileSkillStore

NewFileSkillStore creates a new file-based skill store rooted at dir.

func (*FileSkillStore) Activate

func (s *FileSkillStore) Activate(ctx context.Context, name string) error

Activate sets a skill's status to active by rewriting its SKILL.md.

func (*FileSkillStore) Delete

func (s *FileSkillStore) Delete(_ context.Context, name string) error

Delete removes a skill's directory entirely.

func (*FileSkillStore) EnsureDefaults

func (s *FileSkillStore) EnsureDefaults(defaultFS fs.FS) error

EnsureDefaults deploys embedded default skills that don't already exist.

func (*FileSkillStore) Get

func (s *FileSkillStore) Get(_ context.Context, name string) (*SkillEntry, error)

Get reads and parses a skill's SKILL.md file.

func (*FileSkillStore) ListActive

func (s *FileSkillStore) ListActive(_ context.Context) ([]SkillEntry, error)

ListActive scans all skill directories and returns entries with status=active.

func (*FileSkillStore) Save

func (s *FileSkillStore) Save(_ context.Context, entry SkillEntry) error

Save creates or overwrites a skill's SKILL.md file.

func (*FileSkillStore) SaveResource

func (s *FileSkillStore) SaveResource(_ context.Context, skillName, relPath string, data []byte) error

SaveResource writes a resource file under a skill's directory.

type GitHubRef

type GitHubRef struct {
	Owner  string
	Repo   string
	Branch string
	Path   string
}

GitHubRef represents a parsed GitHub repository reference.

func ParseGitHubURL

func ParseGitHubURL(rawURL string) (*GitHubRef, error)

ParseGitHubURL parses a GitHub URL into owner, repo, branch, and path components. Supported formats:

type ImportConfig

type ImportConfig struct {
	MaxSkills   int
	Concurrency int
	Timeout     time.Duration
}

ImportConfig holds configuration for bulk import operations.

type ImportResult

type ImportResult struct {
	Imported []string
	Skipped  []string
	Errors   []string
}

ImportResult summarises the outcome of a bulk import operation.

type Importer

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

Importer fetches SKILL.md files from GitHub repositories or arbitrary URLs.

func NewImporter

func NewImporter(logger *zap.SugaredLogger) *Importer

NewImporter creates a new skill importer.

func NewImporterWithClient

func NewImporterWithClient(client *http.Client, logger *zap.SugaredLogger) *Importer

NewImporterWithClient creates an importer with a custom HTTP client (for testing).

func (*Importer) DiscoverSkills

func (im *Importer) DiscoverSkills(ctx context.Context, ref *GitHubRef) ([]string, error)

DiscoverSkills lists subdirectories at the given path in a GitHub repo. Each subdirectory is assumed to contain a SKILL.md file.

func (*Importer) FetchFromURL

func (im *Importer) FetchFromURL(ctx context.Context, rawURL string) ([]byte, error)

FetchFromURL fetches raw content from an arbitrary URL via HTTP GET.

func (*Importer) FetchSkillMD

func (im *Importer) FetchSkillMD(ctx context.Context, ref *GitHubRef, skillName string) ([]byte, error)

FetchSkillMD fetches a SKILL.md file from a GitHub repo at {path}/{skillName}/SKILL.md.

func (*Importer) ImportFromRepo

func (im *Importer) ImportFromRepo(ctx context.Context, ref *GitHubRef, store SkillStore, cfg ImportConfig) (*ImportResult, error)

ImportFromRepo discovers and imports all skills from a GitHub repository. Prefers git clone when available, falls back to GitHub HTTP API.

func (*Importer) ImportSingle

func (im *Importer) ImportSingle(ctx context.Context, raw []byte, sourceURL string, store SkillStore) (*SkillEntry, error)

ImportSingle imports a single skill from raw SKILL.md content.

func (*Importer) ImportSingleWithResources

func (im *Importer) ImportSingleWithResources(ctx context.Context, ref *GitHubRef, skillName string, store SkillStore) (*SkillEntry, error)

ImportSingleWithResources imports a single skill from a GitHub repo, including resource files.

type Registry

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

Registry manages skill lifecycle and converts file-based skills to executable tools.

func NewRegistry

func NewRegistry(store SkillStore, baseTools []*agent.Tool, logger *zap.SugaredLogger) *Registry

NewRegistry creates a new skill registry.

func (*Registry) ActivateSkill

func (r *Registry) ActivateSkill(ctx context.Context, name string) error

ActivateSkill activates a skill and reloads the skill tools.

func (*Registry) AllTools

func (r *Registry) AllTools() []*agent.Tool

AllTools returns baseTools combined with loaded dynamic skills.

func (*Registry) CreateSkill

func (r *Registry) CreateSkill(ctx context.Context, entry SkillEntry) error

CreateSkill validates and saves a new skill.

func (*Registry) GetSkillTool

func (r *Registry) GetSkillTool(name string) (*agent.Tool, bool)

GetSkillTool returns a specific loaded skill tool by name.

func (*Registry) ListActiveSkills

func (r *Registry) ListActiveSkills(ctx context.Context) ([]SkillEntry, error)

ListActiveSkills returns all active skill entries from the store.

func (*Registry) LoadSkills

func (r *Registry) LoadSkills(ctx context.Context) error

LoadSkills loads active skills from the store and converts them to agent tools.

func (*Registry) LoadedSkills

func (r *Registry) LoadedSkills() []*agent.Tool

LoadedSkills returns only the dynamically loaded skill tools (no base tools).

func (*Registry) Store

func (r *Registry) Store() SkillStore

Store returns the underlying SkillStore for direct access (e.g. by the importer).

type SkillEntry

type SkillEntry struct {
	Name             string
	Description      string
	Type             SkillType
	Definition       map[string]interface{}
	Parameters       map[string]interface{}
	Status           SkillStatus
	CreatedBy        string
	RequiresApproval bool
	Source           string   // import source URL (empty for locally created)
	AllowedTools     []string // pre-approved tools (from "allowed-tools" frontmatter)
}

SkillEntry is the domain type for skill CRUD operations. Replaces the former knowledge.SkillEntry, removing usage tracking fields.

func BuildCompositeSkill

func BuildCompositeSkill(name, description string, steps []SkillStep, params map[string]interface{}) SkillEntry

BuildCompositeSkill creates a SkillEntry for a multi-step tool chain.

func BuildInstructionSkill

func BuildInstructionSkill(name, description, content, source string) SkillEntry

BuildInstructionSkill creates a SkillEntry for an instruction-based reference skill. Instruction skills are agent reference documents, not executable code.

func BuildScriptSkill

func BuildScriptSkill(name, description, script string, params map[string]interface{}) SkillEntry

BuildScriptSkill creates a SkillEntry for a shell script.

func BuildTemplateSkill

func BuildTemplateSkill(name, description, tmpl string, params map[string]interface{}) SkillEntry

BuildTemplateSkill creates a SkillEntry for a template-based skill.

func ParseSkillMD

func ParseSkillMD(content []byte) (*SkillEntry, error)

ParseSkillMD parses a SKILL.md file into a SkillEntry. Format: YAML frontmatter (between --- delimiters) + markdown body with code blocks.

type SkillStatus

type SkillStatus string

SkillStatus represents the lifecycle status of a skill.

const (
	SkillStatusDraft    SkillStatus = "draft"
	SkillStatusActive   SkillStatus = "active"
	SkillStatusDisabled SkillStatus = "disabled"
)

func (SkillStatus) Valid

func (s SkillStatus) Valid() bool

Valid reports whether s is a known skill status.

func (SkillStatus) Values

func (s SkillStatus) Values() []SkillStatus

Values returns all known skill statuses.

type SkillStep

type SkillStep struct {
	Tool   string                 `json:"tool"`
	Params map[string]interface{} `json:"params"`
}

SkillStep represents one step in a composite skill.

type SkillStore

type SkillStore interface {
	Save(ctx context.Context, entry SkillEntry) error
	Get(ctx context.Context, name string) (*SkillEntry, error)
	ListActive(ctx context.Context) ([]SkillEntry, error)
	Activate(ctx context.Context, name string) error
	Delete(ctx context.Context, name string) error
	SaveResource(ctx context.Context, skillName, relPath string, data []byte) error
}

SkillStore defines the persistence interface for skills.

type SkillType

type SkillType string

SkillType represents the kind of skill definition.

const (
	SkillTypeInstruction SkillType = "instruction"
	SkillTypeComposite   SkillType = "composite"
	SkillTypeScript      SkillType = "script"
	SkillTypeTemplate    SkillType = "template"
)

func (SkillType) Valid

func (t SkillType) Valid() bool

Valid reports whether t is a known skill type.

func (SkillType) Values

func (t SkillType) Values() []SkillType

Values returns all known skill types.

Jump to

Keyboard shortcuts

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