tools

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinDir

func BinDir(annaHome string) string

BinDir returns the tools binary directory path within annaHome.

func DeduplicateByName

func DeduplicateByName(specs []pkgplugins.BinarySpec, logger *slog.Logger) []pkgplugins.BinarySpec

DeduplicateByName returns one spec per binary name, sorted by (Name, PluginID) for deterministic output. When two specs share a name but differ in version, a warning is logged and the first (alphabetically by PluginID) is kept.

func Download

func Download(ctx context.Context, tool *Tool, binDir, platform string) error

Download fetches and installs a single tool to binDir for the given platform. If the tool is already installed at the correct version, it is a no-op. Uses the tool's default version from the registry.

func DownloadLatest

func DownloadLatest(ctx context.Context, tool *Tool, binDir, platform string) error

DownloadLatest fetches the latest release from GitHub and installs it.

func DownloadVersion

func DownloadVersion(ctx context.Context, tool *Tool, version, binDir, platform string) error

DownloadVersion fetches and installs a specific version of a tool. The manifest check and save are serialized via manifestMu so concurrent goroutines cannot clobber each other's entries. Even when the manifest reports the correct version, the binary on disk is verified with binaryHealthy; a missing or corrupt file triggers a re-download.

func EnsurePluginBinaries

func EnsurePluginBinaries(ctx context.Context, specs []pkgplugins.BinarySpec, annaHome string, logger *slog.Logger)

EnsurePluginBinaries downloads each unique binary in specs that isn't already at the right version. Each binary downloads in its own goroutine; PostInstall runs immediately after its binary is ready. Specs are deduplicated by name before dispatching so the same binary never has two concurrent downloads.

func FetchLatestVersion

func FetchLatestVersion(ctx context.Context, tool *Tool) (string, error)

FetchLatestVersion queries the GitHub API for the latest release tag.

func InstallBinarySpec

func InstallBinarySpec(ctx context.Context, spec pkgplugins.BinarySpec, annaHome string, logger *slog.Logger) error

InstallBinarySpec downloads the binary declared by spec synchronously and runs PostInstall. Intended for CLI install commands where immediate feedback and error reporting are needed.

func Platform

func Platform() string

Platform returns "GOOS-GOARCH" for the current runtime.

func RunPostInstalls

func RunPostInstalls(_ context.Context, specs []pkgplugins.BinarySpec, annaHome string, logger *slog.Logger)

RunPostInstalls runs PostInstall hooks for specs whose binary is already present. Used at startup to refresh plugin assets without re-downloading.

func ToolPath

func ToolPath(annaHome, name string) string

ToolPath returns the full path to a named downloadable tool, or empty if not installed.

func UpgradeBinarySpec

func UpgradeBinarySpec(ctx context.Context, spec pkgplugins.BinarySpec, annaHome string, logger *slog.Logger) error

UpgradeBinarySpec upgrades the binary declared by spec to the latest GitHub release synchronously and runs PostInstall. Falls back to the pinned version when the latest-release API call fails and a pinned version is available.

Types

type Asset

type Asset struct {
	Tag       string
	File      string
	RawBinary bool
}

Asset is a resolved, ready-to-download asset.

type AssetTemplate

type AssetTemplate struct {
	File      string `json:"file"`
	RawBinary bool   `json:"raw_binary,omitempty"`
}

AssetTemplate describes a GitHub release asset pattern for a specific platform. The File field may contain "{version}" which is replaced at resolve time.

type InstalledTool

type InstalledTool struct {
	Version  string `json:"version"`
	Platform string `json:"platform"`
}

InstalledTool records the installed version and platform of a tool.

type Manifest

type Manifest struct {
	Tools map[string]InstalledTool `json:"tools"`
}

Manifest tracks installed tool versions.

func LoadManifest

func LoadManifest(binDir string) (*Manifest, error)

LoadManifest reads the manifest from binDir. If the file does not exist, an empty manifest is returned.

func (*Manifest) IsInstalled

func (m *Manifest) IsInstalled(name, version string) bool

IsInstalled reports whether the named tool is installed at the given version.

func (*Manifest) Save

func (m *Manifest) Save(binDir string) error

Save writes the manifest to binDir.

type Tool

type Tool struct {
	Name           string                   `json:"name"`
	DisplayName    string                   `json:"display_name"`
	Description    string                   `json:"description"`
	Version        string                   `json:"version"`
	Repo           string                   `json:"repo"`
	AssetTemplates map[string]AssetTemplate `json:"asset_templates"`
}

Tool describes a downloadable CLI tool.

func (*Tool) ResolveAsset

func (t *Tool) ResolveAsset(platform, version string) (Asset, bool)

ResolveAsset resolves the asset template for a given platform and version.

type ToolStatus

type ToolStatus struct {
	Name      string
	Version   string
	Installed bool
	Current   bool // installed version matches registry version
}

ToolStatus reports the install state of a tool.

func StatusFromSpecs

func StatusFromSpecs(specs []pkgplugins.BinarySpec, binDir string) []ToolStatus

StatusFromSpecs returns install status for each unique binary name in specs.

Jump to

Keyboard shortcuts

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