update

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package update checks the GitHub releases for a newer build and installs it. It is used only by kvit-coder-ui: the headless agent never checks, and the model is never offered it as a tool.

Releases are built by GoReleaser on v* tags with predictable asset names (kvit-coder_<number>_<os>_<arch>.tar.gz, zip on Windows) plus a checksums.txt, so the check needs no API token: the /releases/latest redirect names the tag, and the archive is verified against checksums.txt before anything is replaced.

On unix the new binaries are renamed over the old ones atomically. A running Windows .exe cannot be overwritten, but it can be renamed, so there the current file is renamed aside to .old and the staged .new takes its name; the .old is removed on the next start. No launcher shim or versioned directories are needed on either platform.

The short names kc and kcu are symlinks on unix, which Resolve follows to the binaries. On Windows they are kc.exe and kcu.exe, hard links or copies beside the binaries, so an update replaces them along with the binary they stand for.

Index

Constants

View Source
const DefaultInterval = 24 * time.Hour

DefaultInterval is the automatic check cadence when the config names none.

View Source
const NoCheckEnv = "KVIT_NO_UPDATE_CHECK"

NoCheckEnv disables the automatic check when set to 1/true/yes/on.

View Source
const Repo = "kvit-s/kvit-coder"

Repo is the GitHub repository releases are read from.

Variables

This section is empty.

Functions

func AssetName

func AssetName(tag, goos, goarch string) string

AssetName is the release file for a tag and platform, following GoReleaser's convention: the tag's number without the v.

func AssetURL

func AssetURL(tag, goos, goarch string) string

AssetURL serves one release file.

func BinaryNames

func BinaryNames(goos string) []string

BinaryNames are the two files a release archive holds for an OS.

func ChecksumsURL

func ChecksumsURL(tag string) string

ChecksumsURL serves the release's SHA256 list.

func CleanupBackups

func CleanupBackups(dirs ...string)

CleanupBackups removes leftover .old files from a previous Windows swap. Best effort: errors are ignored.

func CleanupForPaths

func CleanupForPaths(paths ...string)

CleanupForPaths removes leftover backups beside the UI and agent binaries.

func Compare

func Compare(a, b string) int

Compare orders two versions: -1 when a is older, 0 when equal, +1 when a is newer. Tags carry a leading v; normalization strips it, compares three numeric parts, and orders a bare release above its prereleases. Anything unparsable compares as zeros, so "dev" is older than any release.

A git-describe suffix (v0.4.0-1-gSHA, what git describe prints for commits past a tag) is newer than the tag itself, not a prerelease: it names real commits on top. Two such suffixes order by commit count.

func Destinations

func Destinations(uiExe, agentPath string) (uiDest, coderDest string, err error)

Destinations returns where the two running binaries live: the UI behind uiExe (empty means this process) and the agent behind agentPath.

func DisabledByEnv

func DisabledByEnv() bool

DisabledByEnv reports whether the environment turns the automatic check off.

func ExtractBinaries

func ExtractBinaries(archivePath, destDir string) (coderPath, uiPath string, err error)

ExtractBinaries unpacks the two binaries from a release archive into destDir (flat, ignoring the docs the archive also carries) and returns their paths.

func FetchRelease

func FetchRelease(ctx context.Context, tag, dir string) (string, error)

FetchRelease downloads a release's archive and checksums into dir, verifies the archive, and returns its path.

func Install

func Install(coderSrc, uiSrc, coderDest, uiDest string) error

Install replaces both binaries with freshly extracted ones. On unix each replacement is a copy into the destination directory followed by an atomic rename, so a crash never leaves half a binary. On Windows the running files cannot be overwritten, but renaming them aside is allowed, so the current files move to .old and the staged .new files take their names; the .old files are removed on the next start. When the swap cannot happen the staged .new files are left and a *Pending explains the manual move.

func IsDevVersion

func IsDevVersion(v string) bool

IsDevVersion reports whether a stamped version is a development build, which is never auto-checked: "dev" from a plain go build, or a -dirty tree.

func LatestTag

func LatestTag(ctx context.Context) (string, error)

LatestTag asks GitHub which release is newest by following the /releases/latest redirect to /releases/tag/<tag> and reading the tag.

func NewerThan

func NewerThan(current, latest string) bool

NewerThan reports whether latest is actually newer than current.

func NormalizeTag

func NormalizeTag(tag string) string

NormalizeTag accepts what a person types for :update ("0.5.0" or "v0.5.0") and returns the release tag form.

func NoteCheck

func NoteCheck(tag string)

NoteCheck records that a check just ran. An empty tag keeps the previous one, so even a failed (offline) attempt throttles the next one to the next interval instead of retrying on every start.

func PendingStaged

func PendingStaged(dirs ...string) []string

PendingStaged lists staged .new files waiting for a manual move.

func ReleaseURL

func ReleaseURL(tag string) string

ReleaseURL is the human page for a tag, where the notes live.

func Resolve

func Resolve(p string) string

Resolve returns the real file behind a path: bare names go through the PATH, symlinks (the ~/.local/bin farm scripts/install.sh builds) resolve to the checkout, and a missing file falls back to the absolute path.

func ShouldAutoCheck

func ShouldAutoCheck(now time.Time, current string, st *State, enabled bool, interval time.Duration) bool

ShouldAutoCheck reports whether a background check is due. The first run (no record) checks; afterwards the interval gates it.

func StatePath

func StatePath() (string, error)

StatePath is where the check record lives.

func VerifyArchive

func VerifyArchive(archivePath, sumsPath string) error

VerifyArchive checks the archive against its checksums.txt entry. The sums file lists every platform's archive, so only the downloaded file's line is compared.

Types

type Pending

type Pending struct {
	Pairs [][2]string
}

Pending names updates that were staged (.new) but could not be swapped into place, as new-file/destination pairs.

func (*Pending) Error

func (p *Pending) Error() string

type Result

type Result struct {
	Current    string
	Latest     string
	Available  bool
	ReleaseURL string
}

Result is one version check.

func Check

func Check(ctx context.Context, current string) (Result, error)

Check resolves the latest release and compares it to the running build.

type State

type State struct {
	LastCheck time.Time `json:"last_check"`
	LatestTag string    `json:"latest_tag"`
}

State is the on-disk record of the last check, kept so the UI checks at most once per interval.

func LoadState

func LoadState() *State

LoadState reads the check record. Absent, unreadable or corrupt means no record, not an error: the caller checks now.

Jump to

Keyboard shortcuts

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