skills

package
v1.1.21 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package skills discovers agent skills in git repositories the way the portal backend's /agent-skills endpoint does: every SKILL.md in a GitHub repository is one skill, its frontmatter name and description describe it, and its directory is the skill an agent mounts (url + path). kagent API v2 pins skills to immutable sources, so the ref that was read is resolved to its head commit and reported next to it: the skills entry a listing yields feeds create_agent as is. Results are cached per repository for a short time so a meta agent listing skills repeatedly does not exhaust GitHub's rate limit. The Resolver (resolve.go) is the same GitHub path for the composer: a branch or tag to its head commit, a repository to its default branch.

Index

Constants

This section is empty.

Variables

View Source
var (
	// CommitPattern is a full commit id (40 or 64 hex characters).
	CommitPattern = regexp.MustCompile(`^([0-9a-fA-F]{40}|[0-9a-fA-F]{64})$`)
	// DigestRefPattern is <repository>@sha256:<digest>.
	DigestRefPattern = regexp.MustCompile(`^[^\s@]+@sha256:[0-9a-f]{64}$`)
)

Immutable skill sources as the kagent.dev/v1alpha3 AgentTemplate requires them: a full git commit id, an OCI reference by digest.

View Source
var ErrUnresolvable = errors.New("unresolvable skill reference")

ErrUnresolvable marks a reference that could not be resolved to a pin; the message names the repository or image and the reason.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Repositories are the configured skill repositories (github.com URLs).
	Repositories []string
	// APIURL is the GitHub API base (https://api.github.com; tests override).
	APIURL string
	// Token authenticates GitHub requests (private repositories, higher rate
	// limit); empty is anonymous.
	Token string
	// CacheTTL keeps a repository's result before it is re-read.
	CacheTTL time.Duration
	// HTTPClient overrides the client (tests).
	HTTPClient *http.Client
}

Config tunes the discoverer and the resolver.

type Discoverer

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

Discoverer reads skills from GitHub with a per-repository cache.

func New

func New(cfg Config, log *slog.Logger) *Discoverer

New builds a discoverer.

func (*Discoverer) List

func (d *Discoverer) List(ctx context.Context, repository, ref string, refresh bool) (*Result, error)

List discovers skills. repository narrows to one repository (configured or not — any github.com URL is accepted); ref overrides the default branch; refresh bypasses the cache.

func (*Discoverer) Repositories

func (d *Discoverer) Repositories() []string

Repositories returns the configured repositories.

type Repository

type Repository struct {
	RepoURL string `json:"repoUrl"`
	Ref     string `json:"ref,omitempty"`
	// Commit is what Ref resolved to when the repository was read.
	Commit string  `json:"commit,omitempty"`
	Skills []Skill `json:"skills"`
	// Truncated is true when GitHub capped the tree or a SKILL.md read failed:
	// some skills may be missing.
	Truncated bool `json:"truncated"`
	// Error is set when the repository could not be read at all.
	Error     string     `json:"error,omitempty"`
	FetchedAt *time.Time `json:"fetchedAt,omitempty"`
}

Repository is the discovery result of one configured repository.

type Resolver added in v1.0.0

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

Resolver pins skill references: a git branch or tag to its head commit, a repository to its default branch, an OCI tag to its digest. It is the composer's path to immutable sources and the migration's.

func NewResolver added in v1.0.0

func NewResolver(apiURL, token string, client *http.Client, registry *oci.Registry) *Resolver

NewResolver builds a resolver for the GitHub API at apiURL (with token, empty for anonymous) and any OCI registry. registry may be nil.

func (*Resolver) GitHead added in v1.0.0

func (r *Resolver) GitHead(ctx context.Context, repoURL, ref string) (string, error)

GitHead resolves ref (a branch, tag or commit; empty for the default branch) of repoURL to the commit it points at. A ref that is already a full commit id is returned as it is without a lookup. A repository that cannot be read — private without a token, or missing — is ErrUnresolvable naming it.

func (*Resolver) OCIDigest added in v1.0.0

func (r *Resolver) OCIDigest(ctx context.Context, ref string) (string, error)

OCIDigest pins an OCI reference: one already carrying a digest is returned in its pinned form; a tagged one (no tag: latest) is resolved against the registry.

type Result

type Result struct {
	Repositories []Repository `json:"repositories"`
	// Skills flattens every repository's skills (stable order).
	Skills []Skill `json:"skills"`
}

Result is what list_skills returns.

type Skill

type Skill struct {
	// Name is the frontmatter name, else the directory (or repository) name.
	Name string `json:"name"`
	// Description is the frontmatter description ("" when absent).
	Description string `json:"description"`
	// RepoURL is the canonical https://github.com/<owner>/<repo>.
	RepoURL string `json:"repoUrl"`
	// Path is the skill directory; "" at the repository root.
	Path string `json:"path"`
	// Ref is the git ref (branch) the skill was read from.
	Ref string `json:"ref"`
	// Commit is the commit Ref resolved to when it was read: the immutable
	// reference an agent pins the skill to.
	Commit string `json:"commit"`
}

Skill is one discovered skill, shaped as the portal returns it.

func (Skill) Entry added in v1.0.0

func (s Skill) Entry() map[string]any

Entry is the skill as a create_agent/update_agent skills entry: pinned to the commit it was read at.

Jump to

Keyboard shortcuts

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