skill

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 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)

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 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"`
	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 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,
	frontmatter json.RawMessage,
	manifest []FileEntry,
	scanResult json.RawMessage,
) (*Version, error)

CreateVersion increments latest_version on the parent skill 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, limit, offset int) ([]Skill, int, error)

List returns a paginated slice of skills along with the total row count.

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) UpdateContent

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

UpdateContent updates a skill's description, content, and frontmatter, bumping updated_at.

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