registry

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package registry provides template registry functionality for AGK. It handles fetching, caching, and validating templates from various sources including GitHub repositories, local paths, and the official AGK registry.

Index

Constants

View Source
const (
	FetcherTypeGit   = "git"
	FetcherTypeLocal = "local"
)
View Source
const (
	// DefaultRegistryURL is the URL of the official AGK template registry.
	// For production we'd point to the official repo.
	DefaultRegistryURL = "https://raw.githubusercontent.com/agk-templates/registry/main/index.json"
)
View Source
const (
	VersionLatest = "latest"
)

Variables

This section is empty.

Functions

func FindManifest

func FindManifest(dir string) (string, error)

FindManifest searches for agk-template.toml in the given directory.

Types

type CacheManager

type CacheManager struct {
	BaseDir string // Root cache directory (e.g., ~/.agk/templates)
}

CacheManager handles local storage of templates.

func NewCacheManager

func NewCacheManager(baseDir string) (*CacheManager, error)

NewCacheManager creates a new cache manager. If baseDir is empty, it defaults to ~/.agk/templates.

func (*CacheManager) Clear

func (c *CacheManager) Clear() error

Clear removes all cached templates.

func (*CacheManager) GetPath

func (c *CacheManager) GetPath(source, version string) string

GetPath returns the expected local path for a given source and version. Source should be a clean URL path like "github.com/user/repo". If version is empty, it uses "latest".

func (*CacheManager) List

func (c *CacheManager) List() ([]CachedTemplate, error)

List returns all templates currently in the cache.

func (*CacheManager) Remove

func (c *CacheManager) Remove(source, version string) error

Remove deletes a template from the cache. Source should include the domain, e.g., "github.com/user/repo". If version is provided, only that version is removed. If version is empty, ALL versions of that template are removed.

type CachedTemplate

type CachedTemplate struct {
	Name        string            // Template name from manifest (e.g., "rag-agent")
	Source      string            // Source URL/Path (e.g., "github.com/user/repo")
	Version     string            // Version tag or "latest"
	Description string            // Description from manifest
	LocalPath   string            // Absolute path to the template in cache
	Manifest    *TemplateManifest // Parsed manifest
}

CachedTemplate represents a template stored in the local cache.

type Fetcher

type Fetcher interface {
	// Fetch downloads the template from source/version to dest directory.
	Fetch(ctx context.Context, source, version, dest string) error
}

Fetcher defines the interface for fetching templates.

type FileConfig

type FileConfig struct {
	Include []string `toml:"include"` // Glob patterns to include
	Exclude []string `toml:"exclude"` // Glob patterns to exclude
}

FileConfig specifies which files to include/exclude from the template.

type GitFetcher

type GitFetcher struct{}

GitFetcher downloads templates from Git repositories.

func (*GitFetcher) Fetch

func (f *GitFetcher) Fetch(ctx context.Context, source, version, dest string) error

Fetch implements Fetcher for Git repositories. It supports cloning specific tags or the latest default branch.

type HookConfig

type HookConfig struct {
	PostCreate []string `toml:"post_create"` // Commands like "go mod tidy"
}

HookConfig defines commands to run after template generation.

type LocalFetcher

type LocalFetcher struct{}

LocalFetcher copies templates from a local path.

func (*LocalFetcher) Fetch

func (f *LocalFetcher) Fetch(ctx context.Context, source, version, dest string) error

Fetch implements Fetcher for local paths. Source is assumed to be an absolute or relative file path. Version is ignored for local paths.

type RegistryIndex

type RegistryIndex struct {
	Templates map[string]string `json:"templates"`
}

RegistryIndex represents the structure of the registry index.json file.

func FetchIndex

func FetchIndex(url string) (*RegistryIndex, error)

FetchIndex fetches and parses the registry index from the given URL.

type Resolver

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

Resolver handles resolving template references to cached templates. It orchestrates fetching and caching.

func NewResolver

func NewResolver(cache *CacheManager) *Resolver

NewResolver creates a new template resolver.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, sourceRef string) (*CachedTemplate, error)

Resolve locates a template, fetching it if necessary, and returns the cached template. Source can be: - GitHub URL: github.com/user/repo or https://github.com/user/repo - Versioned: github.com/user/repo@v1.0.0 - Local path: ./my-template or /abs/path/to/template Resolve locates a template, fetching it if necessary, and returns the cached template. Source can be: - GitHub URL: github.com/user/repo or https://github.com/user/repo - Versioned: github.com/user/repo@v1.0.0 - Local path: ./my-template or /abs/path/to/template

type TemplateInfo

type TemplateInfo struct {
	// Basic metadata
	Name        string `toml:"name"`
	Version     string `toml:"version"`
	Description string `toml:"description"`
	Author      string `toml:"author"`
	License     string `toml:"license"`

	// Compatibility
	MinAGKVersion string `toml:"min_agk_version"`

	// Template variables that users can customize
	Variables map[string]Variable `toml:"variables"`

	// File inclusion/exclusion rules
	Files FileConfig `toml:"files"`

	// Hooks to run after template generation
	Hooks HookConfig `toml:"hooks"`

	// Dependencies required by generated project
	Dependencies map[string]string `toml:"dependencies"`
}

TemplateInfo contains metadata and configuration for a template.

type TemplateManifest

type TemplateManifest struct {
	Template TemplateInfo `toml:"template"`
}

TemplateManifest represents the agk-template.toml file structure. This is the main configuration file for AGK templates.

func ParseManifest

func ParseManifest(path string) (*TemplateManifest, error)

ParseManifest reads and parses an agk-template.toml file.

func ParseManifestData

func ParseManifestData(data []byte) (*TemplateManifest, error)

ParseManifestData parses manifest content from bytes.

func (*TemplateManifest) GetVariable

func (m *TemplateManifest) GetVariable(name string) *Variable

GetVariable returns a variable by name, or nil if not found.

func (*TemplateManifest) HasHooks

func (m *TemplateManifest) HasHooks() bool

HasHooks returns true if the manifest defines any hooks.

func (*TemplateManifest) Validate

func (m *TemplateManifest) Validate() error

Validate checks if the manifest is valid.

type Variable

type Variable struct {
	Type        string   `toml:"type"` // "string", "bool", "choice"
	Description string   `toml:"description"`
	Required    bool     `toml:"required"`
	Default     any      `toml:"default"`
	Options     []string `toml:"options"` // For "choice" type
}

Variable defines a template variable that can be customized during init.

Jump to

Keyboard shortcuts

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