skills

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxNameLength        = 64
	MaxDescriptionLength = 1024
)

Variables

This section is empty.

Functions

func BuildInstallMetadataForRegistryInstance

func BuildInstallMetadataForRegistryInstance(registry SkillRegistry, target, version string) (string, string)

func GitHubInstallDirNameFromToolsConfig

func GitHubInstallDirNameFromToolsConfig(cfg config.SkillsToolsConfig, target string) (string, error)

func NormalizeInstallTargetForRegistry

func NormalizeInstallTargetForRegistry(cfg config.SkillsToolsConfig, registryName, target string) string

func NormalizeInstallTargetForRegistryInstance

func NormalizeInstallTargetForRegistryInstance(registry SkillRegistry, target string) string

func RegisterRegistryProviderBuilder

func RegisterRegistryProviderBuilder(name string, builder RegistryProviderBuilder)

func ValidateInstallTarget

func ValidateInstallTarget(target string) error

func ValidateSkillName

func ValidateSkillName(name string) error

Types

type ClawHubConfig

type ClawHubConfig struct {
	Enabled         bool
	BaseURL         string
	AuthToken       string
	SearchPath      string // e.g. "/api/v1/search"
	SkillsPath      string // e.g. "/api/v1/skills"
	DownloadPath    string // e.g. "/api/v1/download"
	Timeout         int    // seconds, 0 = default (30s)
	MaxZipSize      int    // bytes, 0 = default (50MB)
	MaxResponseSize int    // bytes, 0 = default (2MB)
}

ClawHubConfig configures the ClawHub registry.

func (ClawHubConfig) BuildRegistry

func (c ClawHubConfig) BuildRegistry() SkillRegistry

func (ClawHubConfig) IsEnabled

func (c ClawHubConfig) IsEnabled() bool

type ClawHubRegistry

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

ClawHubRegistry implements SkillRegistry for the ClawHub platform.

func NewClawHubRegistry

func NewClawHubRegistry(cfg ClawHubConfig) *ClawHubRegistry

NewClawHubRegistry creates a new ClawHub registry client from config.

func (*ClawHubRegistry) DownloadAndInstall

func (c *ClawHubRegistry) DownloadAndInstall(
	ctx context.Context,
	slug, version, targetDir string,
) (*InstallResult, error)

DownloadAndInstall fetches metadata (with fallback), resolves version, downloads the skill ZIP, and extracts it to targetDir. Returns an InstallResult for the caller to use for moderation decisions.

func (*ClawHubRegistry) GetSkillMeta

func (c *ClawHubRegistry) GetSkillMeta(ctx context.Context, slug string) (*SkillMeta, error)

func (*ClawHubRegistry) Name

func (c *ClawHubRegistry) Name() string

func (*ClawHubRegistry) ResolveInstallDirName

func (c *ClawHubRegistry) ResolveInstallDirName(target string) (string, error)

func (*ClawHubRegistry) Search

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

func (*ClawHubRegistry) SkillURL

func (c *ClawHubRegistry) SkillURL(slug, _ string) string

type GitHubContent

type GitHubContent struct {
	Name        string `json:"name"`
	Path        string `json:"path"`
	Type        string `json:"type"` // "file" or "dir"
	DownloadURL string `json:"download_url"`
	URL         string `json:"url"` // API URL for subdirectories
}

GitHubContent represents a file or directory in GitHub API response

type GitHubRef

type GitHubRef struct {
	Owner    string // Repository owner
	RepoName string // Repository name
	Ref      string // Git reference (branch, tag, or commit)
	SubPath  string // Path within the repository
}

GitHubRef represents a parsed GitHub reference

type GitHubRegistry

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

func (*GitHubRegistry) DownloadAndInstall

func (r *GitHubRegistry) DownloadAndInstall(
	ctx context.Context,
	target, version, targetDir string,
) (*InstallResult, error)

func (*GitHubRegistry) GetSkillMeta

func (r *GitHubRegistry) GetSkillMeta(ctx context.Context, target string) (*SkillMeta, error)

func (*GitHubRegistry) Name

func (r *GitHubRegistry) Name() string

func (*GitHubRegistry) NormalizeInstallTarget

func (r *GitHubRegistry) NormalizeInstallTarget(target string) string

func (*GitHubRegistry) ResolveInstallDirName

func (r *GitHubRegistry) ResolveInstallDirName(target string) (string, error)

func (*GitHubRegistry) Search

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

func (*GitHubRegistry) SkillURL

func (r *GitHubRegistry) SkillURL(target, version string) string

type GitHubRegistryConfig

type GitHubRegistryConfig struct {
	Enabled   bool
	BaseURL   string
	AuthToken string
	Proxy     string
}

func (GitHubRegistryConfig) BuildRegistry

func (c GitHubRegistryConfig) BuildRegistry() SkillRegistry

func (GitHubRegistryConfig) IsEnabled

func (c GitHubRegistryConfig) IsEnabled() bool

type InstallResult

type InstallResult struct {
	Version          string
	IsMalwareBlocked bool
	IsSuspicious     bool
	Summary          string
}

InstallResult is returned by DownloadAndInstall to carry metadata back to the caller for moderation and user messaging.

type InstallTargetNormalizer

type InstallTargetNormalizer interface {
	NormalizeInstallTarget(target string) string
}

InstallTargetNormalizer is implemented by registries that can canonicalize user-provided install targets into a stable slug for origin metadata.

type RegistryConfig

type RegistryConfig struct {
	Providers             []RegistryProvider
	MaxConcurrentSearches int
}

RegistryConfig holds configuration for all skill registries. This is the input to NewRegistryManagerFromConfig.

type RegistryManager

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

RegistryManager coordinates multiple skill registries. It fans out search requests and routes installs to the correct registry.

func NewRegistryManager

func NewRegistryManager() *RegistryManager

NewRegistryManager creates an empty RegistryManager.

func NewRegistryManagerFromConfig

func NewRegistryManagerFromConfig(cfg RegistryConfig) *RegistryManager

NewRegistryManagerFromConfig builds a RegistryManager from config, instantiating only the enabled registries.

func NewRegistryManagerFromToolsConfig

func NewRegistryManagerFromToolsConfig(cfg config.SkillsToolsConfig) *RegistryManager

func (*RegistryManager) AddRegistry

func (rm *RegistryManager) AddRegistry(r SkillRegistry)

AddRegistry adds a registry to the manager.

func (*RegistryManager) GetRegistry

func (rm *RegistryManager) GetRegistry(name string) SkillRegistry

GetRegistry returns a registry by name, or nil if not found.

func (*RegistryManager) SearchAll

func (rm *RegistryManager) SearchAll(ctx context.Context, query string, limit int) ([]SearchResult, error)

SearchAll fans out the query to all registries concurrently and merges results sorted by score descending.

type RegistryProvider

type RegistryProvider interface {
	IsEnabled() bool
	BuildRegistry() SkillRegistry
}

RegistryProvider creates a registry instance from configuration. Different hubs can implement this to plug into the shared manager.

type RegistryProviderBuilder

type RegistryProviderBuilder func(name string, cfg config.SkillRegistryConfig) RegistryProvider

type SearchCache

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

SearchCache provides lightweight caching for search results. It uses trigram-based similarity to match similar queries to cached results, avoiding redundant API calls. Thread-safe for concurrent access.

func NewSearchCache

func NewSearchCache(maxEntries int, ttl time.Duration) *SearchCache

NewSearchCache creates a new search cache. maxEntries is the maximum number of cached queries (excess evicts LRU). ttl is how long each entry lives before expiration.

func (*SearchCache) Get

func (sc *SearchCache) Get(query string) ([]SearchResult, bool)

Get looks up results for a query. Returns cached results and true if found (either exact or similar match above threshold). Returns nil, false on miss.

func (*SearchCache) Len

func (sc *SearchCache) Len() int

Len returns the number of entries (for testing).

func (*SearchCache) Put

func (sc *SearchCache) Put(query string, results []SearchResult)

Put stores results for a query. Evicts the oldest entry if at capacity.

type SearchResult

type SearchResult struct {
	Score        float64 `json:"score"`
	Slug         string  `json:"slug"`
	DisplayName  string  `json:"display_name"`
	Summary      string  `json:"summary"`
	Version      string  `json:"version"`
	RegistryName string  `json:"registry_name"`
}

SearchResult represents a single result from a skill registry search.

type SkillInfo

type SkillInfo struct {
	Name        string `json:"name"`
	Path        string `json:"path"`
	Source      string `json:"source"`
	Description string `json:"description"`
}

type SkillInstaller

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

func NewSkillInstaller

func NewSkillInstaller(workspace, githubToken, proxy string) (*SkillInstaller, error)

NewSkillInstaller creates a new skill installer. proxy is an optional HTTP/HTTPS/SOCKS5 proxy URL for downloading skills.

func NewSkillInstallerWithBaseURL

func NewSkillInstallerWithBaseURL(workspace, githubBaseURL, githubToken, proxy string) (*SkillInstaller, error)

NewSkillInstallerWithBaseURL creates a new skill installer with a custom GitHub base URL. For github.com this can be left empty. For GitHub Enterprise, set it to the web URL.

func (*SkillInstaller) InstallFromGitHub

func (si *SkillInstaller) InstallFromGitHub(ctx context.Context, repo string) error

func (*SkillInstaller) InstallFromGitHubToDir

func (si *SkillInstaller) InstallFromGitHubToDir(
	ctx context.Context,
	repo, version, skillDirectory string,
) (*InstallResult, error)

func (*SkillInstaller) Uninstall

func (si *SkillInstaller) Uninstall(skillName string) error

type SkillMeta

type SkillMeta struct {
	Slug             string `json:"slug"`
	DisplayName      string `json:"display_name"`
	Summary          string `json:"summary"`
	LatestVersion    string `json:"latest_version"`
	IsMalwareBlocked bool   `json:"is_malware_blocked"`
	IsSuspicious     bool   `json:"is_suspicious"`
	RegistryName     string `json:"registry_name"`
}

SkillMeta holds metadata about a skill from a registry.

type SkillMetadata

type SkillMetadata struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

type SkillRegistry

type SkillRegistry interface {
	// Name returns the unique name of this registry (e.g., "clawhub").
	Name() string
	// ResolveInstallDirName returns the directory name to use under workspace/skills
	// for a given install target. Different registries can interpret the target
	// differently (for example, a slug vs owner/repo/path).
	ResolveInstallDirName(target string) (string, error)
	// SkillURL returns the web URL for a skill slug if the registry exposes one.
	// version is optional and can be used by registries whose URLs depend on a ref.
	SkillURL(slug, version string) string
	// Search searches the registry for skills matching the query.
	Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
	// GetSkillMeta retrieves metadata for a specific skill by slug.
	GetSkillMeta(ctx context.Context, slug string) (*SkillMeta, error)
	// DownloadAndInstall fetches metadata, resolves the version, downloads and
	// installs the skill to targetDir. Returns an InstallResult with metadata
	// for the caller to use for moderation and user messaging.
	DownloadAndInstall(ctx context.Context, slug, version, targetDir string) (*InstallResult, error)
}

SkillRegistry is the interface that all skill registries must implement. Each registry represents a different source of skills (e.g., clawhub.ai)

func LookupRegistryFromToolsConfig

func LookupRegistryFromToolsConfig(cfg config.SkillsToolsConfig, name string) SkillRegistry

type SkillsLoader

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

func NewSkillsLoader

func NewSkillsLoader(workspace string, globalSkills string, builtinSkills string) *SkillsLoader

func (*SkillsLoader) BuildSkillsSummary

func (sl *SkillsLoader) BuildSkillsSummary() string

func (*SkillsLoader) ListSkills

func (sl *SkillsLoader) ListSkills() []SkillInfo

func (*SkillsLoader) LoadSkill

func (sl *SkillsLoader) LoadSkill(name string) (string, bool)

func (*SkillsLoader) LoadSkillsForContext

func (sl *SkillsLoader) LoadSkillsForContext(skillNames []string) string

func (*SkillsLoader) SkillRoots

func (sl *SkillsLoader) SkillRoots() []string

SkillRoots returns all unique skill root directories used by this loader. The order follows resolution priority: workspace > global > builtin.

Jump to

Keyboard shortcuts

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