skills

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package skills provides skill discovery, parsing, and installation functionality.

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = NewProviderRegistry()

DefaultRegistry is the global provider registry.

Functions

func CopyDir

func CopyDir(src, dst string) error

CopyDir recursively copies a directory, excluding .git directories and symlinks.

func ExtractInstallName

func ExtractInstallName(fm Frontmatter, dirName, fallbackName string) string

ExtractInstallName determines the installation name for a skill. Priority: metadata.install-name > directory name > name from frontmatter > fallback name

func FindAllSkillDirs

func FindAllSkillDirs(searchDir string) ([]string, error)

FindAllSkillDirs searches for all directories containing a SKILL.md file.

func FindSkillDir

func FindSkillDir(searchDir, skillName string) (string, error)

FindSkillDir searches for a SKILL.md file in a directory. If skillName is provided, it looks for a directory with that name containing SKILL.md. Otherwise, it returns the first directory containing SKILL.md.

func GetCacheDir

func GetCacheDir(repoURL, ref string) (string, error)

GetCacheDir returns the cache directory for a git repo URL and optional ref. Format: ~/.cache/mcphub/skills/<owner>/<repo> (or <owner>/<repo>@<ref> if ref specified)

func GetWellKnownSourceIdentifier

func GetWellKnownSourceIdentifier(u string) string

GetWellKnownSourceIdentifier returns the source identifier for a well-known URL.

func InstallSkill

func InstallSkill(skillDir, targetDir string) error

InstallSkill copies a skill from source to target directory. It removes any existing skill at the target location first.

func RegisterProvider

func RegisterProvider(p HostProvider)

RegisterProvider adds a provider to the default registry.

Types

type Frontmatter

type Frontmatter struct {
	Name        string         `yaml:"name"`
	Description string         `yaml:"description"`
	Metadata    map[string]any `yaml:"metadata"`
}

Frontmatter represents the YAML frontmatter of a SKILL.md file.

func ParseFrontmatter

func ParseFrontmatter(content string) (Frontmatter, string, error)

ParseFrontmatter extracts YAML frontmatter from markdown content. Returns the parsed frontmatter, remaining content, and any error. If no frontmatter is found, returns empty frontmatter with full content.

type GitSource

type GitSource struct {
	URL         string // Git clone URL
	Ref         string // Branch/tag reference (optional)
	Subpath     string // Path within repo (optional)
	SkillFilter string // Skill name filter (optional)
}

GitSource represents a git repository source for skills.

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient interface for HTTP operations (allows mocking in tests)

type HostProvider

type HostProvider interface {
	// ID returns a unique identifier for this provider (e.g., "mintlify", "huggingface")
	ID() string

	// DisplayName returns a human-readable name for this provider
	DisplayName() string

	// Match checks if a URL belongs to this provider
	Match(url string) ProviderMatch

	// FetchSkill fetches and parses a skill from the given URL
	FetchSkill(ctx context.Context, url string, client HTTPClient) (*RemoteSkill, error)

	// ToRawURL converts a user-facing URL to a raw content URL
	ToRawURL(url string) string

	// GetSourceIdentifier returns a stable identifier for telemetry/storage
	GetSourceIdentifier(url string) string
}

HostProvider interface for HTTP-based skill providers. Implementations: Mintlify, HuggingFace, Direct URL. Note: Git-based sources (GitHub, GitLab) use FetchGitSkill(), not this interface.

func FindProvider

func FindProvider(url string) HostProvider

FindProvider finds a provider in the default registry.

type LocalSkillDir

type LocalSkillDir struct {
	Path      string // Full path to skill directory
	SkillName string // Name of the skill (directory name)
}

LocalSkillDir represents a local skill directory.

func FetchAllGitSkills

func FetchAllGitSkills(ctx context.Context, src GitSource) ([]*LocalSkillDir, error)

FetchAllGitSkills clones or updates a git repo and finds all skill directories.

func FetchGitSkill

func FetchGitSkill(ctx context.Context, src GitSource) (*LocalSkillDir, error)

FetchGitSkill clones or updates a git repo and finds the skill directory.

type ParsedSource

type ParsedSource struct {
	Type        SourceType // github, gitlab, git, local, direct-url, well-known
	URL         string     // Git URL or HTTP URL
	LocalPath   string     // For local sources (resolved absolute path)
	Ref         string     // Branch/tag reference (optional)
	Subpath     string     // Path within repo (optional)
	SkillFilter string     // From @skill syntax (optional)
}

ParsedSource represents a parsed source input.

func ParseSource

func ParseSource(input string) (*ParsedSource, error)

ParseSource parses an input string into a structured ParsedSource. Supports: local paths, GitHub URLs, GitLab URLs, GitHub shorthand, direct skill.md URLs, well-known URLs, and generic git URLs.

type ProviderMatch

type ProviderMatch struct {
	Matches          bool
	SourceIdentifier string
}

ProviderMatch represents the result of matching a URL to a provider.

type ProviderRegistry

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

ProviderRegistry manages registered HTTP providers.

func NewProviderRegistry

func NewProviderRegistry() *ProviderRegistry

NewProviderRegistry creates a new provider registry.

func (*ProviderRegistry) FindProvider

func (r *ProviderRegistry) FindProvider(url string) HostProvider

FindProvider finds a provider that matches the given URL. Returns nil if no provider matches.

func (*ProviderRegistry) Providers

func (r *ProviderRegistry) Providers() []HostProvider

Providers returns all registered providers.

func (*ProviderRegistry) Register

func (r *ProviderRegistry) Register(p HostProvider)

Register adds a provider to the registry.

type RemoteSkill

type RemoteSkill struct {
	Name        string            // Display name from frontmatter
	Description string            // Description from frontmatter
	Content     string            // Full SKILL.md content
	InstallName string            // Directory name for installation
	SourceURL   string            // Original source URL
	Files       map[string]string // Additional files (for well-known multi-file skills)
	Metadata    map[string]any    // Extra frontmatter data
}

RemoteSkill represents a skill fetched from a remote source.

type SearchResult added in v0.2.4

type SearchResult struct {
	ID       string `json:"id"`
	SkillID  string `json:"skillId"`
	Name     string `json:"name"`
	Installs int    `json:"installs"`
	Source   string `json:"source"`
}

SearchResult represents a skill from the skills.sh registry.

func Search(ctx context.Context, query string, limit int) ([]SearchResult, error)

Search queries the skills.sh API for skills matching the query.

type SourceType

type SourceType string

SourceType represents the type of skill source.

const (
	SourceTypeGitHub    SourceType = "github"
	SourceTypeGitLab    SourceType = "gitlab"
	SourceTypeGit       SourceType = "git"
	SourceTypeLocal     SourceType = "local"
	SourceTypeDirectURL SourceType = "direct-url"
	SourceTypeWellKnown SourceType = "well-known"
)

type WellKnownIndex

type WellKnownIndex struct {
	Skills []WellKnownSkillEntry `json:"skills"`
}

WellKnownIndex represents the /.well-known/skills/index.json structure.

func DiscoverWellKnownSkills

func DiscoverWellKnownSkills(ctx context.Context, baseURL string, client HTTPClient) (*WellKnownIndex, string, error)

DiscoverWellKnownSkills fetches and validates the index from a well-known endpoint.

type WellKnownSkill

type WellKnownSkill struct {
	RemoteSkill
	IndexEntry WellKnownSkillEntry
}

WellKnownSkill represents a skill fetched from a well-known endpoint.

func FetchWellKnownSkill

func FetchWellKnownSkill(ctx context.Context, baseURL string, entry WellKnownSkillEntry, client HTTPClient) (*WellKnownSkill, error)

FetchWellKnownSkill fetches a single skill from a well-known endpoint.

type WellKnownSkillEntry

type WellKnownSkillEntry struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Files       []string `json:"files"`
}

WellKnownSkillEntry represents a skill entry in the index.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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