template

package
v0.2.13-dev Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Environment variable names
	EnvVarUseLocalTemplates = "EIGENX_USE_LOCAL_TEMPLATES"
	EnvVarTemplatesPath     = "EIGENX_TEMPLATES_PATH"

	// Default repository URL for templates
	DefaultTemplateRepo = "https://github.com/Layr-Labs/eigenx-templates"

	// Default version/branch for templates
	DefaultTemplateVersion = "main"

	// Default catalog URL in the eigenx-templates repository
	DefaultCatalogURL = "https://raw.githubusercontent.com/Layr-Labs/eigenx-templates/main/templates.json"

	// Cache duration for the catalog (15 minutes)
	CatalogCacheDuration = 15 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CloneEvent

type CloneEvent struct {
	Type     CloneEventType
	Parent   string // for submodule events
	Module   string // current module path
	Name     string // submodule name or module path
	URL      string // for discovery
	Ref      string // current ref we are cloning from
	Progress int    // 0–100
}

CloneEvent is a single “thing that happened” during clone

type CloneEventType

type CloneEventType int

CloneEventType enumerates the kinds of things git clone can tell us

const (
	EventSubmoduleDiscovered CloneEventType = iota
	EventSubmoduleCloneStart
	EventProgress
	EventCloneComplete
	EventCloneFailed
)

type GitClient

type GitClient struct {
	Runner         Runner
	ReceivingRegex *regexp.Regexp
	CloningRegex   *regexp.Regexp
	SubmoduleRegex *regexp.Regexp
}

GitClient does our actual clone + parsing

func NewGitClient

func NewGitClient() *GitClient

NewGitClient builds a GitClient using the real exec

func NewGitClientWithRunner

func NewGitClientWithRunner(r Runner) *GitClient

NewGitClientWithRunner enables injecting a custom Runner (e.g. in tests)

func (*GitClient) Clone

func (g *GitClient) Clone(
	ctx context.Context,
	repoURL, ref, dest string,
	config GitFetcherConfig,
	reporter Reporter,
) error

Clone runs the following to enable clones from SHAs, tags and branches:

  • git clone --no-checkout --depth 1 <repoURL> <dest>
  • git -C <dest> checkout --quiet <ref>
  • git -C <dest> submodule update --init --recursive --progress

func (*GitClient) CloneSparse

func (g *GitClient) CloneSparse(
	ctx context.Context,
	repoURL, ref, subPath, dest string,
	config GitFetcherConfig,
	reporter Reporter,
) error

CloneSparse clones only a specific subdirectory using sparse-checkout This is more efficient than cloning the full repository when only a subdirectory is needed

func (*GitClient) ParseCloneOutput

func (g *GitClient) ParseCloneOutput(r io.Reader, rep Reporter, dest string, ref string) error

ParseCloneOutput scans git’s progress output and emits events

type GitFetcher

type GitFetcher struct {
	Client  *GitClient
	Metrics GitMetrics
	Config  GitFetcherConfig
	Logger  logger.ProgressLogger
}

GitFetcher wraps clone with metrics and reporting

func (*GitFetcher) Fetch

func (f *GitFetcher) Fetch(ctx context.Context, repoURL, ref, targetDir string) error

func (*GitFetcher) FetchSubdirectory

func (f *GitFetcher) FetchSubdirectory(ctx context.Context, repoURL, ref, subPath, targetDir string) error

FetchSubdirectory clones only a specific subdirectory using sparse-checkout for efficiency

type GitFetcherConfig

type GitFetcherConfig struct {
	Verbose bool
}

GitFetcherConfig holds options; we only care about Verbose here

type GitMetrics

type GitMetrics interface {
	CloneStarted(repo string)
	CloneFinished(repo string, err error)
}

TODO: implement metric transport

type Reporter

type Reporter interface {
	Report(CloneEvent)
}

Reporter consumes CloneEvents

func NewCloneReporter

func NewCloneReporter(repoURL string, lg logger.ProgressLogger, m GitMetrics) Reporter

type Runner

type Runner interface {
	// CommandContext mirrors exec.CommandContext
	CommandContext(ctx context.Context, name string, args ...string) *exec.Cmd
}

Runner lets us inject/mock command execution in tests

type SubmoduleReport

type SubmoduleReport struct {
	Name string
	Dest string
	URL  string
}

type TemplateCatalog added in v0.2.12

type TemplateCatalog struct {
	Languages map[string]map[string]TemplateEntry `json:"-"`
}

TemplateCatalog represents the structure of templates.json Organized by language first, then by category (e.g., "typescript" -> "minimal")

func FetchTemplateCatalog added in v0.2.12

func FetchTemplateCatalog() (*TemplateCatalog, error)

FetchTemplateCatalog fetches and parses the template catalog from the remote URL It uses a 15-minute in-memory cache to avoid excessive network requests If EIGENX_USE_LOCAL_TEMPLATES is set, it looks for a local templates.json file

func (*TemplateCatalog) GetCategoryDescriptions added in v0.2.12

func (tc *TemplateCatalog) GetCategoryDescriptions(language string) map[string]string

GetCategoryDescriptions returns a map of category names to their descriptions for a given language

func (*TemplateCatalog) GetSupportedLanguages added in v0.2.12

func (tc *TemplateCatalog) GetSupportedLanguages() []string

GetSupportedLanguages returns a list of all unique languages in the catalog

func (*TemplateCatalog) GetTemplate added in v0.2.12

func (tc *TemplateCatalog) GetTemplate(category, language string) (*TemplateEntry, error)

GetTemplate finds a template by language and category

func (*TemplateCatalog) UnmarshalJSON added in v0.2.12

func (tc *TemplateCatalog) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshalling to handle nested structure

type TemplateEntry added in v0.2.12

type TemplateEntry struct {
	Path        string `json:"path"`
	Description string `json:"description"`
	PostProcess struct {
		ReplaceNameIn []string `json:"replaceNameIn,omitempty"`
	} `json:"postProcess,omitempty"`
}

TemplateEntry represents a single template in the catalog

Jump to

Keyboard shortcuts

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