template

package
v0.2.3 Latest Latest
Warning

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

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

Documentation

Overview

Copyright © 2025 Sun Asterisk Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const DefaultCacheTTL = 24 * time.Hour

DefaultCacheTTL is the default time-to-live for cached templates

Variables

View Source
var MergeableFiles = map[string]MergeType{
	".vscode/settings.json": MergeTypeJSON,
	".mcp.json":             MergeTypeJSON,
	".gitignore":            MergeTypeGitignore,
}

MergeableFiles defines which files should be merged instead of overwritten

Functions

func CleanupPartial

func CleanupPartial(targetDir string) error

CleanupPartial removes partially extracted files on error

func Download

func Download(url, checksum string, progress ProgressCallback) (string, error)

Download downloads a template from the given URL

func Extract

func Extract(zipPath, targetDir string) error

Extract extracts a ZIP file to the target directory

func ExtractWithMerge added in v0.2.3

func ExtractWithMerge(zipPath, targetDir string) error

ExtractWithMerge extracts a ZIP file to the target directory, merging config files instead of overwriting

func MergeGitignoreFiles added in v0.2.3

func MergeGitignoreFiles(existingPath, templatePath string) error

MergeGitignoreFiles appends unique lines from template .gitignore to existing .gitignore

func MergeJSONFiles added in v0.2.3

func MergeJSONFiles(existingPath, templatePath string) error

MergeJSONFiles performs a deep merge of template JSON into existing JSON file Template values are merged into existing values using deep merge strategy

func UpdateAIToolConfig

func UpdateAIToolConfig(aiTool, projectDir, githubToken, mcpServerEndpoint string) error

UpdateAIToolConfig updates the AI tool config with GitHub token This is the main entry point that delegates to the specific updater

Types

type Cache

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

Cache manages template caching for offline mode

func NewCache

func NewCache() (*Cache, error)

NewCache creates a new template cache

func (*Cache) Clear

func (c *Cache) Clear() error

Clear removes all cached templates

func (*Cache) Get

func (c *Cache) Get(aiTool string, ttl time.Duration) (*CacheEntry, error)

Get retrieves a cached template if available and not expired

func (*Cache) GetCachedFile

func (c *Cache) GetCachedFile(aiTool string) (io.ReadCloser, error)

GetCachedFile returns an io.ReadCloser for a cached template

func (*Cache) List

func (c *Cache) List() []CacheEntry

List returns all cached templates

func (*Cache) Prune

func (c *Cache) Prune(ttl time.Duration) error

Prune removes expired cache entries

func (*Cache) Put

func (c *Cache) Put(aiTool, version, originalURL string, data []byte) error

Put stores a template in the cache

func (*Cache) Remove

func (c *Cache) Remove(aiTool string) error

Remove removes a template from the cache

func (*Cache) Size

func (c *Cache) Size() int64

Size returns the total size of cached templates in bytes

func (*Cache) VerifyIntegrity

func (c *Cache) VerifyIntegrity() (bool, []string)

VerifyIntegrity checks that all cached files match their recorded checksums

type CacheEntry

type CacheEntry struct {
	AITool      string    `json:"ai_tool"`
	Version     string    `json:"version"`
	Checksum    string    `json:"checksum"`
	CachedAt    time.Time `json:"cached_at"`
	FilePath    string    `json:"file_path"`
	OriginalURL string    `json:"original_url"`
	Size        int64     `json:"size"`
}

CacheEntry represents a cached template

type CacheIndex

type CacheIndex struct {
	Version   string                `json:"version"`
	Entries   map[string]CacheEntry `json:"entries"` // Key is AI tool name
	UpdatedAt time.Time             `json:"updated_at"`
}

CacheIndex represents the cache index file

type ClaudeMCPConfig

type ClaudeMCPConfig struct {
	Servers map[string]ClaudeMCPServer `json:"mcpServers"`
}

ClaudeMCPConfig represents the structure of Claude's .mcp.json file

type ClaudeMCPServer

type ClaudeMCPServer struct {
	Type    string            `json:"type"`
	URL     string            `json:"url"`
	Headers map[string]string `json:"headers"`
}

ClaudeMCPServer represents a Claude MCP server configuration

type ConfigUpdater

type ConfigUpdater interface {
	ConfigureMCPServer(projectDir, githubToken, mcpServerEndpoint string) error
}

ConfigUpdater defines the interface for updating AI tool specific configs

func GetConfigUpdater

func GetConfigUpdater(aiTool string) ConfigUpdater

GetConfigUpdater returns the appropriate config updater for the given AI tool

type MergeType added in v0.2.3

type MergeType int

MergeType defines how to merge a specific file type

const (
	MergeTypeJSON MergeType = iota
	MergeTypeGitignore
)

func ShouldMerge added in v0.2.3

func ShouldMerge(relativePath string) (MergeType, bool)

ShouldMerge checks if a file should be merged based on its relative path

type ProgressCallback

type ProgressCallback func(downloaded, total int64)

ProgressCallback is a function called to report download progress

Jump to

Keyboard shortcuts

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