Documentation
¶
Overview ¶
Package skills provides types and interfaces for managing ToolHive skills.
Index ¶
- Constants
- Variables
- func CheckFilesystem(path string) error
- func Remove(skillDir string) error
- func ValidateScope(s Scope) error
- func ValidateSkillName(name string) error
- type BuildOptions
- type BuildResult
- type Dependency
- type ExtractResult
- type InfoOptions
- type InstallOptions
- type InstallResult
- type InstallStatus
- type InstalledSkill
- type Installer
- type ListOptions
- type ParseResult
- type PathResolver
- type PushOptions
- type Scope
- type SkillFrontmatter
- type SkillIndex
- type SkillIndexEntry
- type SkillInfo
- type SkillMetadata
- type SkillService
- type StringOrSlice
- type UninstallOptions
- type ValidationResult
Constants ¶
const ( // MaxTotalExtractSize is the maximum total decompressed size (500MB). MaxTotalExtractSize int64 = 500 * 1024 * 1024 // MaxFileExtractSize is the maximum size per file in the tar archive (100MB). // Matches the toolhive-core default. MaxFileExtractSize int64 = 100 * 1024 * 1024 // MaxExtractFileCount is the maximum number of files allowed in an archive. MaxExtractFileCount = 1000 )
const MaxCompatibilityLength = 500
MaxCompatibilityLength is the maximum allowed length for the compatibility field.
const MaxDependencies = 100
MaxDependencies is the maximum number of dependencies allowed per skill. This prevents resource exhaustion from malicious or misconfigured skills.
const MaxDescriptionLength = 1024
MaxDescriptionLength is the maximum allowed length for the description field.
const MaxFrontmatterSize = 64 * 1024 // 64KB
MaxFrontmatterSize is the maximum size of frontmatter content in bytes. This prevents YAML parsing attacks (e.g., billion laughs).
const RecommendedMaxSkillMDLines = 500
RecommendedMaxSkillMDLines is the recommended maximum number of lines in SKILL.md. Exceeding this generates a warning, not an error.
Variables ¶
var ErrInvalidFrontmatter = errors.New("invalid frontmatter")
ErrInvalidFrontmatter indicates that the SKILL.md frontmatter is malformed.
Functions ¶
func CheckFilesystem ¶ added in v0.10.0
CheckFilesystem walks the directory once, checking for symlinks and path traversal.
func Remove ¶ added in v0.10.0
Remove safely removes a skill directory. Returns nil if the directory does not exist.
func ValidateScope ¶ added in v0.9.4
ValidateScope checks that a scope value is valid. An empty scope is accepted (meaning "unscoped" / "all"). Otherwise only "user" and "project" are allowed.
func ValidateSkillName ¶ added in v0.9.4
ValidateSkillName checks that a skill name conforms to the Agent Skills specification. Names must be 2-64 lowercase alphanumeric characters or hyphens, starting and ending with alphanumeric, with no consecutive hyphens. See: https://agentskills.io/specification
Types ¶
type BuildOptions ¶
type BuildOptions struct {
// Path is the local directory path containing the skill definition.
Path string `json:"path"`
// Tag is the OCI tag to use for the built artifact.
Tag string `json:"tag,omitempty"`
}
BuildOptions configures the behavior of the Build operation.
type BuildResult ¶
type BuildResult struct {
// Reference is the OCI reference of the built skill artifact.
Reference string `json:"reference"`
}
BuildResult contains the outcome of a Build operation.
type Dependency ¶ added in v0.9.3
type Dependency struct {
// Name is the dependency name.
Name string `json:"name,omitempty"`
// Reference is the OCI reference for the dependency.
Reference string `json:"reference"`
// Digest is the OCI digest for upgrade detection.
Digest string `json:"digest,omitempty"`
}
Dependency represents an external skill dependency (OCI reference).
type ExtractResult ¶ added in v0.10.0
type ExtractResult struct {
// SkillDir is the absolute path where the skill was extracted.
SkillDir string
// Files is the number of files written.
Files int
}
ExtractResult contains the outcome of an Extract operation.
func Extract ¶ added in v0.10.0
func Extract(layerData []byte, targetDir string, force bool) (*ExtractResult, error)
Extract decompresses a tar.gz OCI layer and writes files to targetDir. If targetDir exists and force is false, an error is returned. If force is true, the existing directory is removed before extraction.
type InfoOptions ¶
type InfoOptions struct {
// Name is the skill name to look up.
Name string `json:"name"`
// Scope filters the lookup by installation scope.
Scope Scope `json:"scope,omitempty"`
}
InfoOptions configures the behavior of the Info operation.
type InstallOptions ¶
type InstallOptions struct {
// Name is the skill name or OCI reference to install.
Name string `json:"name"`
// Version is the specific version to install. Empty means latest.
Version string `json:"version,omitempty"`
// Scope is the installation scope.
Scope Scope `json:"scope,omitempty"`
// Client is the target client (e.g., "claude-code"). Empty means first skill-supporting client.
Client string `json:"client,omitempty"`
// Force allows overwriting unmanaged skill directories.
Force bool `json:"force,omitempty"`
// ProjectRoot is the project root path for project-scoped installs.
ProjectRoot string `json:"project_root,omitempty"`
// LayerData is the tar.gz content from an OCI layer. Internal use only — NOT exposed via HTTP API.
LayerData []byte `json:"-"`
// Reference is the full OCI reference (e.g. ghcr.io/org/skill:v1).
Reference string `json:"-"`
// Digest is the OCI digest for upgrade detection.
Digest string `json:"-"`
}
InstallOptions configures the behavior of the Install operation.
type InstallResult ¶
type InstallResult struct {
// Skill is the installed skill.
Skill InstalledSkill `json:"skill"`
}
InstallResult contains the outcome of an Install operation.
type InstallStatus ¶
type InstallStatus string
InstallStatus represents the current status of a skill installation.
const ( // InstallStatusInstalled indicates a skill is fully installed and ready. InstallStatusInstalled InstallStatus = "installed" // InstallStatusPending indicates a skill installation is in progress. InstallStatusPending InstallStatus = "pending" // InstallStatusFailed indicates a skill installation has failed. InstallStatusFailed InstallStatus = "failed" )
type InstalledSkill ¶
type InstalledSkill struct {
// Metadata contains the skill's metadata.
Metadata SkillMetadata `json:"metadata"`
// Scope is the installation scope (user or project).
Scope Scope `json:"scope"`
// ProjectRoot is the project root path for project-scoped skills. Empty for user-scoped.
ProjectRoot string `json:"project_root,omitempty"`
// Reference is the full OCI reference (e.g. ghcr.io/org/skill:v1).
Reference string `json:"reference,omitempty"`
// Tag is the OCI tag (e.g. v1.0.0).
Tag string `json:"tag,omitempty"`
// Digest is the OCI digest (sha256:...) for upgrade detection.
Digest string `json:"digest,omitempty"`
// Status is the current installation status.
Status InstallStatus `json:"status"`
// InstalledAt is the timestamp when the skill was installed.
InstalledAt time.Time `json:"installed_at"`
// Clients is the list of client identifiers the skill is installed for.
// TODO: Refactor client.ClientApp to a shared package so it can be used here instead of []string.
Clients []string `json:"clients,omitempty"`
// Dependencies is the list of external skill dependencies.
Dependencies []Dependency `json:"dependencies,omitempty"`
}
InstalledSkill represents a skill that has been installed locally.
type Installer ¶ added in v0.10.0
type Installer interface {
// Extract decompresses a tar.gz OCI layer and writes files to targetDir.
Extract(layerData []byte, targetDir string, force bool) (*ExtractResult, error)
// Remove safely removes a skill directory.
Remove(skillDir string) error
}
Installer handles filesystem operations for skill installation and removal.
func NewInstaller ¶ added in v0.10.0
func NewInstaller() Installer
NewInstaller returns a production Installer that delegates to the package-level Extract and Remove functions.
type ListOptions ¶
type ListOptions struct {
// Scope filters results by installation scope.
Scope Scope `json:"scope,omitempty"`
}
ListOptions configures the behavior of the List operation.
type ParseResult ¶ added in v0.9.3
type ParseResult struct {
Name string
Description string
Version string
AllowedTools []string
License string
Compatibility string
Metadata map[string]string
Requires []Dependency
Body []byte
}
ParseResult contains the parsed contents of a SKILL.md file.
func ParseSkillMD ¶ added in v0.9.3
func ParseSkillMD(content []byte) (*ParseResult, error)
ParseSkillMD parses a SKILL.md file and extracts frontmatter and body.
type PathResolver ¶ added in v0.10.0
type PathResolver interface {
// GetSkillPath returns the filesystem path where a skill should be installed.
GetSkillPath(clientType, skillName string, scope Scope, projectRoot string) (string, error)
// ListSkillSupportingClients returns all client identifiers that support skills.
ListSkillSupportingClients() []string
}
PathResolver resolves filesystem paths for skill installations. It uses string (not client.ClientApp) to avoid importing pkg/client from pkg/skills.
type PushOptions ¶
type PushOptions struct {
// Reference is the OCI reference to push.
Reference string `json:"reference"`
}
PushOptions configures the behavior of the Push operation.
type SkillFrontmatter ¶ added in v0.9.3
type SkillFrontmatter struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Version string `yaml:"version,omitempty"`
AllowedTools StringOrSlice `yaml:"allowed-tools,omitempty"`
Requires StringOrSlice `yaml:"toolhive.requires,omitempty"`
License string `yaml:"license,omitempty"`
Compatibility string `yaml:"compatibility,omitempty"`
Metadata map[string]string `yaml:"metadata,omitempty"`
}
SkillFrontmatter represents the raw YAML frontmatter from a SKILL.md file.
type SkillIndex ¶
type SkillIndex struct {
// Skills is the list of available skills.
Skills []SkillIndexEntry `json:"skills"`
}
SkillIndex represents a collection of available skills from a remote index.
type SkillIndexEntry ¶
type SkillIndexEntry struct {
// Metadata contains the skill's metadata.
Metadata SkillMetadata `json:"metadata"`
// Repository is the OCI repository reference for the skill.
Repository string `json:"repository"`
}
SkillIndexEntry represents a single skill entry in a remote skill index.
type SkillInfo ¶
type SkillInfo struct {
// Metadata contains the skill's metadata.
Metadata SkillMetadata `json:"metadata"`
// InstalledSkill contains the full installation record.
InstalledSkill *InstalledSkill `json:"installed_skill,omitempty"`
}
SkillInfo contains detailed information about an installed skill.
type SkillMetadata ¶
type SkillMetadata struct {
// Name is the unique name of the skill.
Name string `json:"name"`
// Version is the semantic version of the skill.
Version string `json:"version"`
// Description is a human-readable description of the skill.
Description string `json:"description"`
// Author is the skill author or maintainer.
Author string `json:"author"`
// Tags is a list of tags for categorization.
Tags []string `json:"tags,omitempty"`
}
SkillMetadata contains metadata about a skill.
type SkillService ¶
type SkillService interface {
// List returns all installed skills matching the given options.
List(ctx context.Context, opts ListOptions) ([]InstalledSkill, error)
// Install installs a skill from a remote source.
Install(ctx context.Context, opts InstallOptions) (*InstallResult, error)
// Uninstall removes an installed skill.
Uninstall(ctx context.Context, opts UninstallOptions) error
// Info returns detailed information about a skill.
Info(ctx context.Context, opts InfoOptions) (*SkillInfo, error)
// Validate checks whether a skill definition is valid.
Validate(ctx context.Context, path string) (*ValidationResult, error)
// Build builds a skill from a local directory into an OCI artifact.
Build(ctx context.Context, opts BuildOptions) (*BuildResult, error)
// Push pushes a built skill artifact to a remote registry.
Push(ctx context.Context, opts PushOptions) error
}
SkillService defines the interface for managing skills.
type StringOrSlice ¶ added in v0.9.3
type StringOrSlice []string
StringOrSlice is a custom type that can unmarshal from either a YAML string (space-delimited per spec, or comma-delimited for compatibility) or a YAML array.
func (*StringOrSlice) UnmarshalYAML ¶ added in v0.9.3
func (s *StringOrSlice) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implements yaml.Unmarshaler for StringOrSlice. Per the Agent Skills spec, allowed-tools is space-delimited, but we also support comma-delimited for compatibility with existing skills.
type UninstallOptions ¶
type UninstallOptions struct {
// Name is the skill name to uninstall.
Name string `json:"name"`
// Scope is the scope from which to uninstall.
Scope Scope `json:"scope,omitempty"`
// ProjectRoot is the project root path for project-scoped skills.
ProjectRoot string `json:"project_root,omitempty"`
}
UninstallOptions configures the behavior of the Uninstall operation.
type ValidationResult ¶
type ValidationResult struct {
// Valid indicates whether the skill definition is valid.
Valid bool `json:"valid"`
// Errors is a list of validation errors, if any.
Errors []string `json:"errors,omitempty"`
// Warnings is a list of non-blocking validation warnings, if any.
Warnings []string `json:"warnings,omitempty"`
}
ValidationResult contains the outcome of a Validate operation.
func ValidateSkillDir ¶ added in v0.9.3
func ValidateSkillDir(path string) (*ValidationResult, error)
ValidateSkillDir validates a skill directory at the given path. I/O errors are returned as error; validation issues are returned in ValidationResult.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client provides an HTTP client for the ToolHive Skills API.
|
Package client provides an HTTP client for the ToolHive Skills API. |
|
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
|
Package skillsvc provides the default implementation of skills.SkillService.
|
Package skillsvc provides the default implementation of skills.SkillService. |