version

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package version checks GitHub for latest releases, compares semantic versions, and manages update workflows for the sidecar and td binaries.

Index

Constants

View Source
const InstallTimeout = 15 * time.Minute

InstallTimeout bounds one confirmed first-install. A package manager that never returns must not leave the UI claiming to be working.

Variables

View Source
var ErrNoFormula = errors.New("no Homebrew formula for this product")

ErrNoFormula reports a product with no Homebrew formula to install from.

View Source
var ErrNoGo = errors.New("go is not installed")

ErrNoGo reports that the Go toolchain is not available on this machine.

View Source
var ErrNoGoPackages = errors.New("no automated Go install for this product")

ErrNoGoPackages reports a product with no safe go-install package set.

View Source
var ErrNoHomebrew = errors.New("homebrew is not installed")

ErrNoHomebrew reports that Homebrew is not available on this machine.

View Source
var ErrNoInstaller = errors.New("no supported installer is available")

ErrNoInstaller reports that neither Homebrew nor Go can run a first install.

Functions

func CheckProductAsync added in v0.96.0

func CheckProductAsync(d Descriptor, currentVersion string, force bool) tea.Cmd

CheckProductAsync returns a Bubble Tea command that discovers one product's installed version, release status, and install provenance in the background.

currentVersion is the in-process version for Sidecar; pass "" for products whose version must be read from the installed executable. Callers only schedule this for products that are effectively enabled, so a disabled feature adds no startup process or network work.

func CommandAvailable added in v1.0.0

func CommandAvailable(env *Environment, d Descriptor) bool

CommandAvailable reports whether a product's primary executable is on PATH.

func FailureDetail added in v1.0.2

func FailureDetail(r Result, maxOutputLines int) []string

FailureDetail returns the diagnostic lines to show for a failed result: the error itself, followed by the tail of the failing command's combined output.

The output is the part that matters and it used to be discarded entirely, so a failed update reported only the command and "exit status 1" — enough to see that `go install` failed, never enough to see why. The tail is what carries the compiler or toolchain message; earlier lines are download progress.

State-free so the exact reported lines are testable without a UI.

func GoAvailable added in v1.3.0

func GoAvailable(env *Environment) bool

GoAvailable reports whether `go` is on PATH.

func GoCommandEnv added in v1.0.1

func GoCommandEnv(base []string) []string

GoCommandEnv returns the environment an automated `go install` runs with, derived from base (os.Environ() form). It is a pure function so the exact resulting environment is testable.

Two adjustments matter:

  • GOWORK=off. Sidecar usually runs with its own repository as the working directory, and that repository has a go.work with local `replace` directives. A workspace must not influence `go install pkg@version`: it either fails outright or resolves the release against local, possibly unbuildable, checkouts.
  • CGO_CFLAGS gains the warning suppressions above, appended to whatever the user already set rather than replacing it.

func GoInstallCommand added in v1.3.0

func GoInstallCommand(d Descriptor) string

GoInstallCommand is the exact `go install` Sidecar would run, joined so it can be shown and copied as one instruction. GOWORK=off is part of the command: ExecRunner applies it, and a pasted copy must behave the same way.

func HomebrewAvailable added in v1.0.0

func HomebrewAvailable(env *Environment) bool

HomebrewAvailable reports whether `brew` is on PATH.

func InstallCommand added in v1.0.0

func InstallCommand(d Descriptor) string

InstallCommand is the exact Homebrew command a brew-backed install would run, so the confirmation, the copyable instruction, and the execution are the same string when Homebrew is the chosen method.

func InstallCommands added in v0.96.0

func InstallCommands(t Target) [][]string

InstallCommands returns the exact commands an automated update runs for a target, or nil when the target is not safely updatable.

func InstalledVersion added in v0.96.0

func InstalledVersion(ctx context.Context, env *Environment, d Descriptor) string

InstalledVersion reads a product's installed version by running its executable. It returns "" when the product is not installed, the command fails, or the output carries no release version (a development build).

func IsCacheValid

func IsCacheValid(entry *CacheEntry, currentVersion string) bool

IsCacheValid checks if cache exists and is not expired. Also invalidates if user version changed (upgrade or downgrade).

func NormalizeVersion added in v0.96.0

func NormalizeVersion(s string) string

NormalizeVersion extracts a comparable version from arbitrary `--version` output (e.g. "tasks version 1.5.0" or "v1.5.0"). It returns "" when the output carries no release version, which is how development builds and unparsable output are told apart from a real release.

func RefreshPackageMetadata added in v0.96.0

func RefreshPackageMetadata(ctx context.Context, env *Environment, plan []Target)

RefreshPackageMetadata refreshes Homebrew metadata once per confirmed batch so `brew upgrade` can see new releases. Best effort: a failure here is not a target failure.

func RestartRequired added in v0.96.0

func RestartRequired(results []Result) bool

RestartRequired reports whether any settled result changed Sidecar itself. Standalone td/Tasks updates do not require quitting Sidecar.

func SameVersion added in v0.96.0

func SameVersion(a, b string) bool

SameVersion reports whether two version strings name the same release.

func SaveCacheFile added in v0.96.0

func SaveCacheFile(name string, entry *CacheEntry) error

SaveCacheFile writes a version check result to a named cache file.

func Summarize added in v0.96.0

func Summarize(results []Result) string

Summarize renders a one-line summary of a settled batch for a toast.

Types

type CacheEntry

type CacheEntry struct {
	LatestVersion  string    `json:"latestVersion"`
	CurrentVersion string    `json:"currentVersion"`
	CheckedAt      time.Time `json:"checkedAt"`
	HasUpdate      bool      `json:"hasUpdate"`
}

CacheEntry stores cached version check result.

func LoadCacheFile added in v0.96.0

func LoadCacheFile(name string) (*CacheEntry, error)

LoadCacheFile reads a cached version check result for a named cache file.

type CheckResult

type CheckResult struct {
	CurrentVersion string
	LatestVersion  string
	UpdateURL      string
	ReleaseNotes   string
	HasUpdate      bool
	Error          error
}

CheckResult holds the result of a version check.

func Check

func Check(currentVersion string) CheckResult

Check fetches the latest release from GitHub and compares versions.

func CheckRepo

func CheckRepo(owner, repo, currentVersion string) CheckResult

CheckRepo fetches the latest release for a repo and compares versions.

type Descriptor added in v0.96.0

type Descriptor struct {
	Product     ProductID
	DisplayName string

	RepoOwner string
	RepoName  string

	// Executable is the command used to read the installed version and to
	// resolve install provenance.
	Executable string
	// SuiteBinaries lists every binary the release ships, with the exact
	// arguments each one accepts for printing its version. A product is only
	// verified as updated when all of them report the released version; for
	// Tasks that is the distribution contract.
	//
	// The arguments are per binary because they genuinely differ: `tasks` is
	// subcommand-dispatched and wants `tasks version`, while `tasks-tui` and
	// `tasks-api` parse flags and reject positional arguments.
	SuiteBinaries []SuiteBinary

	// Formula is the fully qualified Homebrew formula name.
	Formula string
	// GoPackages are the packages an automated `go install` update must build.
	// Empty means a Go install cannot be expressed safely and must be manual.
	GoPackages []string
	// GoLdflags stamps the version into main.Version (Sidecar's release does
	// this; the other products embed their version at tag time).
	GoLdflags bool

	// CacheFile is the per-product release-check cache file name. Distinct per
	// product so similarly numbered releases cannot collide.
	CacheFile string

	ReleasesURL string
}

Descriptor describes how to discover and update one product. Everything that differs between products lives here so the checking, planning, install, and verification code stays product-neutral.

func DescriptorFor added in v0.96.0

func DescriptorFor(id ProductID) (Descriptor, bool)

DescriptorFor returns the descriptor for a product id.

func SidecarDescriptor added in v0.96.0

func SidecarDescriptor() Descriptor

SidecarDescriptor describes Sidecar itself.

func TasksDescriptor added in v0.96.0

func TasksDescriptor() Descriptor

TasksDescriptor describes the standalone Tasks command suite.

func TdDescriptor added in v0.96.0

func TdDescriptor() Descriptor

TdDescriptor describes the td CLI.

func (Descriptor) InstallHint added in v0.96.0

func (d Descriptor) InstallHint() string

InstallHint is the supported Homebrew command to install a product that is not installed at all. The updater never runs it — a confirmed update is never a new product installation. First-install runs this string (or a go-install fallback) only after the user has read it and confirmed.

func (Descriptor) UnmanagedHint added in v0.96.0

func (d Descriptor) UnmanagedHint() string

UnmanagedHint is what to tell someone whose installed copy Sidecar does not manage — a downloaded binary, a packaged build, or an active development selector. Deliberately not `brew install`: that would create a second, shadowing installation rather than updating the one they actually run.

func (Descriptor) VersionArgs added in v0.96.0

func (d Descriptor) VersionArgs() []string

VersionArgs returns the arguments that make the product's primary executable print its version.

type Environment added in v0.96.0

type Environment struct {
	Runner       Runner
	LookPath     func(string) (string, error)
	EvalSymlinks func(string) (string, error)
	// Self resolves the running Sidecar binary.
	Self func() (string, error)
}

Environment is the adapter edge for everything the updater needs from the host: process execution and executable resolution. Tests substitute it to assert exact commands without invoking real package managers.

func DefaultEnvironment added in v0.96.0

func DefaultEnvironment() *Environment

DefaultEnvironment returns the real host environment.

func (*Environment) ResolveExecutable added in v0.96.0

func (e *Environment) ResolveExecutable(d Descriptor) (string, error)

ResolveExecutable returns the resolved on-disk path of a product's primary executable, following symlinks.

type ExecRunner added in v0.96.0

type ExecRunner struct{}

ExecRunner is the real process runner.

func (ExecRunner) Run added in v0.96.0

func (ExecRunner) Run(ctx context.Context, name string, args ...string) (string, error)

Run executes name with args and returns combined output. `go` invocations get the adjusted environment from GoCommandEnv so an automated update is not broken by an active workspace or by SDK header warnings.

type InstallMethod

type InstallMethod string

InstallMethod represents how a product was installed.

const (
	InstallMethodHomebrew InstallMethod = "homebrew"
	InstallMethodGo       InstallMethod = "go"
	// InstallMethodBinary covers anything Sidecar does not manage: a
	// downloaded binary, a packaged build, or an active local development
	// selector. These are never overwritten automatically.
	InstallMethodBinary InstallMethod = "binary"
)

func (InstallMethod) String added in v0.96.0

func (m InstallMethod) String() string

String returns the human-readable name of an install method.

type InstallOutcome added in v1.0.0

type InstallOutcome struct {
	// Installed is true only when the product's command resolves afterwards.
	Installed bool
	// Command is exactly what was run, for a message the user can act on.
	Command string
	Output  string
	Err     error
}

InstallOutcome is the settled result of one confirmed install attempt.

func Install added in v1.3.0

func Install(ctx context.Context, env *Environment, d Descriptor) InstallOutcome

Install runs PlanInstall and verifies the product's command is resolvable afterwards. It is never called without an explicit user confirmation.

func InstallWithHomebrew added in v1.0.0

func InstallWithHomebrew(ctx context.Context, env *Environment, d Descriptor) InstallOutcome

InstallWithHomebrew installs a product's formula. It is never called without an explicit user confirmation, and it verifies the result rather than trusting the package manager's exit code. Callers that should fall back to go install use Install instead.

type InstallPlan added in v1.3.0

type InstallPlan struct {
	Method  InstallMethod
	Command string
	Steps   [][]string
}

InstallPlan is the exact first-install Sidecar would run for a product on this machine. Confirmation, the copyable instruction, and execution share Command so the user has read the same string that will run.

func PlanInstall added in v1.3.0

func PlanInstall(env *Environment, d Descriptor) (InstallPlan, error)

PlanInstall chooses Homebrew when brew is on PATH, otherwise go install. The returned Command is what Install will run; a caller that shows a different string is offering a command it will not honour.

type Installation added in v0.96.0

type Installation struct {
	Method         InstallMethod
	ExecutablePath string
	// Managed is true only when Sidecar can safely run an automated update for
	// this exact executable. An unmanaged target is reported with a manual
	// command instead of being overwritten.
	Managed       bool
	ManualCommand string
	// Detail explains an unmanaged target (e.g. a local development selector).
	Detail string
}

Installation records how one product's resolved executable is managed.

func DetectInstallation added in v0.96.0

func DetectInstallation(ctx context.Context, env *Environment, d Descriptor, latestVersion string) Installation

DetectInstallation resolves how the product the user actually runs was installed. Provenance is per product: a Homebrew Sidecar may coexist with a Go-installed td or a local Tasks development selector.

type ProductID added in v0.96.0

type ProductID string

ProductID identifies an updatable product Sidecar knows how to check.

const (
	// ProductSidecar is Sidecar itself.
	ProductSidecar ProductID = "sidecar"
	// ProductTd is the td issue tracker CLI.
	ProductTd ProductID = "td"
	// ProductTasks is the standalone Tasks command suite. Sidecar embeds the
	// Tasks TUI library at build time; this target is the separately installed
	// tasks/tasks-tui/tasks-api commands, which only their own package manager
	// can refresh.
	ProductTasks ProductID = "tasks"
)

type ProductStatusMsg added in v0.96.0

type ProductStatusMsg struct {
	Target       Target
	ReleaseNotes string
	ReleaseURL   string
}

ProductStatusMsg reports the discovered state of one product. It is the single product-neutral result of a release check; the app stores one per product instead of parallel per-product fields.

type Release

type Release struct {
	TagName     string    `json:"tag_name"`
	Name        string    `json:"name"`
	Body        string    `json:"body"`
	PublishedAt time.Time `json:"published_at"`
	HTMLURL     string    `json:"html_url"`
}

Release represents a GitHub release response.

type Result added in v0.96.0

type Result struct {
	Target Target
	Status ResultStatus
	// Version is the version actually verified after a successful update.
	Version string
	Output  string
	Err     error
}

Result is the immutable outcome of attempting one target.

func Apply added in v0.96.0

func Apply(ctx context.Context, env *Environment, t Target) Result

Apply installs and verifies one target. It never infers success from exit status alone: every binary the release ships must report the exact version that was confirmed.

type ResultStatus added in v0.96.0

type ResultStatus string

ResultStatus is the settled outcome of one target in a confirmed batch.

const (
	StatusUpdated ResultStatus = "updated"
	StatusManual  ResultStatus = "manual"
	StatusFailed  ResultStatus = "failed"
)

type Runner added in v0.96.0

type Runner interface {
	Run(ctx context.Context, name string, args ...string) (string, error)
}

Runner executes an external command and returns its combined output.

type SuiteBinary added in v0.96.0

type SuiteBinary struct {
	Name        string
	VersionArgs []string
}

SuiteBinary is one executable a release ships.

type Target added in v0.96.0

type Target struct {
	Product        ProductID
	DisplayName    string
	Installed      bool
	Enabled        bool
	CurrentVersion string
	LatestVersion  string
	HasUpdate      bool
	// CheckFailed marks a release check that could not complete. It is
	// "unknown", never "up to date".
	CheckFailed bool
	Install     Installation
}

Target is one product Sidecar may offer to update.

func RetryTargets added in v0.96.0

func RetryTargets(results []Result) []Target

RetryTargets returns the targets from a settled batch that are worth retrying: failures only. Successful upgrades are never re-run.

func SelectPlan added in v0.96.0

func SelectPlan(targets []Target) []Target

SelectPlan returns, in deterministic order, the targets a confirmed update will act on. It is a state-free function over discovered products: only enabled, installed products with a real available update take part.

Jump to

Keyboard shortcuts

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