skill

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewChiAPI

func NewChiAPI() (chi.Router, huma.API)

NewChiAPI creates a new Chi router and Huma API suitable for production and tests. Returns both so callers can mount additional middleware on the router or serve it directly.

func ParseFrontmatter

func ParseFrontmatter(content string) (map[string]interface{}, string, error)

ParseFrontmatter parses YAML frontmatter from content delimited by "---\n" blocks. It returns the frontmatter as a map, the body (content after the closing delimiter), and any error.

If no frontmatter is found (content does not start with "---\n"), it returns nil, content, nil.

func RegisterRoutes

func RegisterRoutes(api huma.API, router chi.Router, store *Store, storage platform.Storage, ext ...*scan.ExternalScanner)

RegisterRoutes wires up all skill-related HTTP endpoints onto the provided Huma API and Chi router. The router is needed for the two raw-response routes (download + scan) that stream bytes rather than returning JSON.

func Unpack

func Unpack(r io.Reader, destDir string) error

Unpack extracts a tar.gz archive from r into destDir. It rejects any archive entry whose resolved path would escape destDir (path traversal prevention), rejects symlinks and hardlinks, and enforces a 50 MB total extraction size limit.

Types

type Alias

type Alias struct {
	Alias     string    `json:"alias"`
	Canonical string    `json:"canonical"`
	CreatedAt time.Time `json:"created_at"`
}

type FileEntry

type FileEntry struct {
	Path string `json:"path"`
	Size int64  `json:"size"`
}

FileEntry describes a single file within a skill archive.

func Pack

func Pack(dir string) ([]byte, string, []FileEntry, error)

Pack creates a tar.gz archive of the directory at dir. It returns the archive bytes, a sha256 hex checksum, a file manifest, and any error encountered. Pack returns an error if SKILL.md is not present in dir.

type ListOptions added in v0.7.0

type ListOptions struct {
	Limit   int
	Offset  int
	Author  string
	Tag     string
	License string
}

ListOptions holds optional filter parameters for List.

type Skill

type Skill struct {
	ID             string          `json:"id"`
	Name           string          `json:"name"`
	DisplayName    string          `json:"display_name,omitempty"`
	Description    string          `json:"description"`
	Content        string          `json:"content,omitempty"`
	LatestVersion  int             `json:"latest_version"`
	Frontmatter    json.RawMessage `json:"frontmatter"`
	Author         string          `json:"author"`
	License        string          `json:"license"`
	Compatibility  string          `json:"compatibility"`
	Tags           []string        `json:"tags"`
	SpecCompliance string          `json:"spec_compliance"`
	CreatedAt      time.Time       `json:"created_at"`
	UpdatedAt      time.Time       `json:"updated_at"`
	ReviewedAt     *time.Time      `json:"reviewed_at"`
	ReviewedBy     string          `json:"reviewed_by"`
}

Skill represents a skill entry in the registry.

type SpecValidation added in v0.7.0

type SpecValidation struct {
	Compliance  string
	Author      string
	License     string
	Compat      string
	Tags        []string
	DisplayName string
	Warnings    []string
}

SpecValidation holds the result of validating a skill's frontmatter against the Agent Skills spec format.

func ValidateSpec added in v0.7.0

func ValidateSpec(fm map[string]interface{}, skillName string) *SpecValidation

ValidateSpec extracts spec-defined metadata from parsed frontmatter and computes a compliance level ("full", "partial", or "none").

type Store

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

Store handles Postgres persistence for skills and their versions.

func NewStore

func NewStore(pool *pgxpool.Pool) *Store

NewStore constructs a Store backed by the given connection pool.

func (*Store) BulkSetReview

func (s *Store) BulkSetReview(ctx context.Context, names []string, reviewedBy string) (int, error)

BulkSetReview marks multiple skills as reviewed in a single UPDATE. Returns the number of rows actually updated.

func (*Store) ClearReview

func (s *Store) ClearReview(ctx context.Context, name string) error

ClearReview removes the review mark from a skill.

func (*Store) Create

func (s *Store) Create(ctx context.Context, name, displayName, description, content string, frontmatter json.RawMessage) (*Skill, error)

Create inserts a new skill row and returns the created record.

func (*Store) CreateAlias

func (s *Store) CreateAlias(ctx context.Context, alias, canonical string) error

func (*Store) CreateVersion

func (s *Store) CreateVersion(
	ctx context.Context,
	skillID, archivePath, checksum, changelog string,
	description, content string,
	frontmatter json.RawMessage,
	manifest []FileEntry,
	scanResult json.RawMessage,
	publishedBy string,
) (*Version, error)

CreateVersion increments latest_version on the parent skill, updates its description/content/frontmatter, and inserts a new skill_versions row, all within a single transaction.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, name string) error

Delete removes a skill (and its versions via CASCADE) by name.

func (*Store) DeleteAlias

func (s *Store) DeleteAlias(ctx context.Context, alias string) error

func (*Store) GetByName

func (s *Store) GetByName(ctx context.Context, name string) (*Skill, error)

GetByName retrieves a skill by its unique name. Returns nil, nil when not found.

func (*Store) GetVersion

func (s *Store) GetVersion(ctx context.Context, skillName string, version int) (*Version, error)

GetVersion retrieves a specific version of a skill. Returns nil, nil if not found.

func (*Store) List

func (s *Store) List(ctx context.Context, opts ListOptions) ([]Skill, int, error)

List returns a paginated slice of skills along with the total row count. Filters are applied when the corresponding ListOptions fields are non-empty.

func (*Store) ListAliases

func (s *Store) ListAliases(ctx context.Context, canonical string) ([]Alias, error)

func (*Store) ListVersions

func (s *Store) ListVersions(ctx context.Context, skillName string) ([]Version, error)

ListVersions returns all versions for a skill ordered by version DESC.

func (*Store) Merge

func (s *Store) Merge(ctx context.Context, sourceName, targetName string) (*Skill, error)

func (*Store) ResolveAlias

func (s *Store) ResolveAlias(ctx context.Context, name string) (string, error)

func (*Store) Search

func (s *Store) Search(ctx context.Context, query string, limit int) ([]Skill, error)

Search returns skills matching the given query using a combination of Postgres full-text search (websearch_to_tsquery + ts_rank on search_vector) and pg_trgm fuzzy name matching (similarity()). Results are returned where either FTS matches OR name similarity exceeds 0.2, ordered by FTS rank then trigram rank. Limit caps the number of returned results.

func (*Store) SetReview

func (s *Store) SetReview(ctx context.Context, name, reviewedBy string) error

SetReview marks a skill as reviewed by the given reviewer.

func (*Store) UpdateSpecFields added in v0.7.0

func (s *Store) UpdateSpecFields(ctx context.Context, name, author, license, compat, compliance, displayName string, tags []string) error

UpdateSpecFields updates the spec-derived metadata columns on a skill row.

type Version

type Version struct {
	ID           string          `json:"id"`
	SkillID      string          `json:"skill_id"`
	Version      int             `json:"version"`
	ArchivePath  string          `json:"-"`
	Checksum     string          `json:"checksum"`
	Changelog    string          `json:"changelog"`
	Frontmatter  json.RawMessage `json:"frontmatter"`
	FileManifest []FileEntry     `json:"file_manifest"`
	ScanResult   json.RawMessage `json:"scan_result,omitempty"`
	PublishedBy  string          `json:"published_by"`
	CreatedAt    time.Time       `json:"created_at"`
}

Version represents a specific published version of a skill.

Jump to

Keyboard shortcuts

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