resource

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package resource provides types and utilities for discovering shareable aix resources (skills, commands, agents, and MCP servers) from repositories.

Package resource defines types for shareable aix resources (skills, commands, agents, and MCP servers) that can be discovered and installed from repositories.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoReposConfigured = errors.New("no repositories configured")

ErrNoReposConfigured is returned when no repositories are configured.

View Source
var ErrResourceNotFound = errors.New("resource not found")

ErrResourceNotFound is returned when a resource's source path does not exist.

Functions

func CopyToTemp

func CopyToTemp(res *Resource) (string, error)

CopyToTemp copies a resource from the repository cache to a temporary directory. The caller is responsible for cleanup (e.g., defer os.RemoveAll(tempPath)).

For skills (directory with SKILL.md), the entire directory is copied. For commands and agents, the behavior depends on whether the path is a directory or a flat file:

  • Directory-based (e.g., commands/foo with command.md): copies the directory
  • Flat file (e.g., commands/foo.md): copies just the file

Returns the path to the temporary directory containing the copied resource.

func CopyToTempFromCache

func CopyToTempFromCache(res *Resource, cacheDir string) (string, error)

CopyToTempFromCache copies a resource from the specified cache directory to a temporary directory. This variant allows overriding the cache directory for testing.

For directory-based resources (skills, directory commands, directory agents), the original directory name is preserved within the temp directory. This ensures that validators can verify the resource name matches its directory name. For example, copying "skills/implement" creates "/tmp/aix-install-xyz/implement/".

For flat files, the file is copied directly to the temp directory root.

func IsDirectoryResource

func IsDirectoryResource(res *Resource) bool

IsDirectoryResource returns true if the resource path represents a directory (e.g., skills/foo, commands/bar) rather than a flat file (e.g., commands/bar.md).

Types

type Resource

type Resource struct {
	// Name is the unique identifier for this resource within its repository.
	Name string `json:"name"`

	// Description provides a brief explanation of what this resource does.
	Description string `json:"description,omitempty"`

	// Type identifies the kind of resource (skill, command, agent, or mcp).
	Type ResourceType `json:"type"`

	// RepoName is the short name of the repository containing this resource.
	RepoName string `json:"repo_name"`

	// RepoURL is the full URL to the repository.
	RepoURL string `json:"repo_url,omitempty"`

	// Path is the relative path to this resource within the repository.
	Path string `json:"path"`

	// Metadata contains additional key-value pairs for extensibility.
	Metadata map[string]string `json:"metadata,omitempty"`
}

Resource represents a shareable aix resource that can be discovered and installed from a repository.

func FindByName

func FindByName(name string, resourceType ResourceType) ([]Resource, error)

FindByName scans all configured repositories and returns resources matching the given name and type exactly. Returns an empty slice if no matches found.

func FindByNameInRepo

func FindByNameInRepo(name string, resourceType ResourceType, repoName string) (*Resource, error)

FindByNameInRepo scans a specific repository and returns the resource matching the given name and type exactly. Returns nil if no match found.

func Search(resources []Resource, query string, opts SearchOptions) []Resource

Search finds resources matching the query and filter options. Matching is case-insensitive against Name and Description fields. An empty query returns all resources (subject to filters). Results are sorted by match quality (exact name > prefix > contains > description-only).

type ResourceType

type ResourceType string

ResourceType identifies the kind of resource.

const (
	TypeSkill   ResourceType = "skill"
	TypeCommand ResourceType = "command"
	TypeAgent   ResourceType = "agent"
	TypeMCP     ResourceType = "mcp"
)

Resource type constants.

type Scanner

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

Scanner scans cached repositories for resources.

func NewScanner

func NewScanner() *Scanner

NewScanner creates a new Scanner with a default discard logger.

func NewScannerWithLogger

func NewScannerWithLogger(logger *slog.Logger) *Scanner

NewScannerWithLogger creates a new Scanner with the given logger.

func (*Scanner) ScanAll

func (s *Scanner) ScanAll(repos []config.RepoConfig) ([]Resource, error)

ScanAll scans multiple repositories for resources concurrently. It uses a worker pool limited to GOMAXPROCS to parallelize scanning.

func (*Scanner) ScanRepo

func (s *Scanner) ScanRepo(repoPath, repoName, repoURL string) ([]Resource, error)

ScanRepo scans a single repository for resources. It looks for skills, commands, agents, and MCP servers in their respective directories.

type SearchOptions

type SearchOptions struct {
	// Type filters by resource type. Empty string matches all types.
	Type ResourceType
	// RepoName filters by repository name. Empty string matches all repos.
	RepoName string
}

SearchOptions configures resource search filtering.

Jump to

Keyboard shortcuts

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