gitresolver

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package gitresolver resolves skill installations from git repositories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsGitReference

func IsGitReference(name string) bool

IsGitReference returns true if name starts with "git://".

func ResolveAuth

func ResolveAuth(cloneURL string) transport.AuthMethod

ResolveAuth attempts to find authentication credentials from the environment scoped to the given clone URL. Returns nil if no credentials match.

Security: tokens are only sent to their designated hosts. GITHUB_TOKEN is only sent to github.com, GITLAB_TOKEN only to gitlab.com. GIT_TOKEN is a fallback sent to any host.

func ResolveAuthWith

func ResolveAuthWith(getenv EnvFunc, cloneURL string) transport.AuthMethod

ResolveAuthWith is like ResolveAuth but uses the provided function to look up environment variables, making it testable without modifying process state.

func WriteFiles

func WriteFiles(files []FileEntry, targetDir string, force bool) error

WriteFiles writes resolved skill files to the target directory. If force is true, any existing directory is removed before writing.

Security: targetDir is produced by PathResolver.GetSkillPath (a trusted internal source that builds paths from known base directories). File paths within the archive are validated via containment check against targetDir.

Types

type EnvFunc

type EnvFunc func(string) string

EnvFunc is a function that looks up an environment variable. The default is os.Getenv; tests can inject a custom implementation.

type FileEntry

type FileEntry struct {
	Path    string
	Content []byte
	Mode    fs.FileMode
}

FileEntry represents a single file from the cloned repository.

type GitReference

type GitReference struct {
	// URL is the HTTPS clone URL (e.g., https://github.com/org/repo)
	URL string
	// Path is the subdirectory within repo (e.g., "path/to/skill"), empty = repo root
	Path string
	// Ref is the git ref: branch, tag, or commit (e.g., "v1.0.0"), empty = default branch
	Ref string
}

GitReference represents a parsed git:// skill reference.

func ParseGitReference

func ParseGitReference(raw string) (*GitReference, error)

ParseGitReference parses a git:// skill reference.

Format: git://host/owner/repo[@ref][#path/to/skill]

Examples:

  • git://github.com/org/repo
  • git://github.com/org/repo@v1.0.0
  • git://github.com/org/repo#skills/my-skill
  • git://github.com/org/repo@main#skills/my-skill

func (*GitReference) SkillName

func (r *GitReference) SkillName() string

SkillName extracts the expected skill name from the reference. Uses the last component of Path if set, otherwise the last component of the repo URL.

type ResolveResult

type ResolveResult struct {
	// SkillConfig is the parsed SKILL.md
	SkillConfig *skills.ParseResult
	// Files is all files in the skill directory
	Files []FileEntry
	// CommitHash is the git commit hash (for digest/upgrade detection)
	CommitHash string
}

ResolveResult contains the outcome of resolving a git skill reference.

type Resolver

type Resolver interface {
	// Resolve clones the repo, validates the skill, and returns the skill
	// directory contents as files ready for installation.
	Resolve(ctx context.Context, ref *GitReference) (*ResolveResult, error)
}

Resolver clones a git repository and extracts skill files.

func NewResolver

func NewResolver(opts ...ResolverOption) Resolver

NewResolver creates a new git skill resolver.

type ResolverOption

type ResolverOption func(*defaultResolver)

ResolverOption configures a defaultResolver.

func WithGitClient

func WithGitClient(client git.Client) ResolverOption

WithGitClient sets a fixed git client, bypassing per-clone auth resolution. Primarily used for testing with mock clients.

Jump to

Keyboard shortcuts

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