update

package
v0.159.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 12 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 update checks whether a newer Caprock release exists and works out the command that would install it.

This is the ONE place in Caprock that talks to the network, and it is off until the user turns it on. Engineering rule 4 ("no outbound calls") is not bent quietly: the check is opt-in, asked for once, visible in the UI with the time of the last check, and revocable. The request carries no body, no identifiers, and no usage data — GitHub learns an IP asked for a release tag, which is what any `brew update` already tells it.

Caprock deliberately does NOT install the update itself. Upgrading means replacing the running binary, so the daemon would be killing the process executing the command — a race whose failure mode is a user left with no working Caprock. Running a package manager on the user's behalf from a web page is also exactly the surface a local tool should not open. Instead we name the exact command for how this copy was installed, and the user runs it.

The desktop app is the one exception, and it is the app, not this package: its own signed updater replaces the app bundle, which carries the daemon with it (ADR-042), on a click or — when the user chose Update automatically — once no agent is busy (GET /v1/update/busy). The daemon still never overwrites its own binary.

Index

Constants

View Source
const AppCask = "caprock-app"

AppCask is the Homebrew cask that installs the desktop app.

View Source
const FailRetry = 15 * time.Minute

FailRetry spaces the checks after a failed one.

View Source
const Interval = 15 * time.Minute

Interval is how often a background release check is due: every 15 minutes, so a release published while someone works shows within minutes rather than within the hour (owner, 2026-10-16: 0.124.0 was out for twelve minutes and nothing said so). The daemon asks on a shorter tick (its updateTick) so a check due during sleep runs within minutes of waking.

View Source
const ReleasesPage = "https://github.com/dspv/caprock/releases/latest"

ReleasesPage is where a user without a package manager goes.

View Source
const SoonInterval = 10 * time.Minute

SoonInterval is the floor for a check the page asks for when its window is focused or shown (CheckSoon): never more than one unforced check per ten minutes, however often the window is switched to.

Variables

View Source
var LatestURL = "https://api.github.com/repos/dspv/caprock/releases/latest"

LatestURL is the release endpoint. Overridable in tests.

Functions

func InstallCommand

func InstallCommand() string

InstallCommand returns the upgrade command for how this copy was installed, inferred from the executable's path. When we cannot tell, we say nothing rather than suggest a command that might do the wrong thing — an empty result means the UI offers the release page instead.

func Newer

func Newer(current, latest string) bool

Newer reports whether latest is a strictly newer release than current. A non-release build ("dev", or a `git describe` string with a commit suffix) is never told it is out of date: the person running it built it themselves.

Types

type Checker

type Checker struct {
	// Now is injectable for tests.
	Now func() time.Time
	// HTTPClient is injectable for tests.
	HTTPClient *http.Client
	// MinInterval throttles the background checks (default Interval, 15
	// minutes). Releases ship several times a day, and the request is a
	// conditional one (ETag): an unchanged answer is a 304 with no body,
	// which GitHub does not count against the rate limit.
	MinInterval time.Duration
	// SoonAfter is the floor for a check asked for because the app's window
	// came to the front (default SoonInterval, 10 minutes): CheckSoon runs
	// only when the last check is at least this old. Both kinds share one
	// last-checked time, so unforced checks never run more than once per
	// SoonAfter between them.
	SoonAfter time.Duration
	// RetryAfter is how long a failed check waits before the next one that
	// was not asked for (default FailRetry): a laptop offline for a day
	// tries every quarter hour, not on every tick.
	RetryAfter time.Duration
	// CaskRoots are where Homebrew keeps installed casks; the app was
	// installed by the cask when one of them holds caprock-app.
	CaskRoots []string
	// IsDir is os.Stat's view of a directory; injectable for tests.
	IsDir func(string) bool
	// contains filtered or unexported fields
}

Checker holds the cached result. It never checks on its own: the caller decides when, so "opt-in" is enforced at the call site as well as here.

func New

func New() *Checker

New returns a Checker with sane defaults.

func (*Checker) Check

func (c *Checker) Check(ctx context.Context, force bool) error

Check asks GitHub for the latest release tag, respecting MinInterval unless forced. A failure is recorded and returned but never escalated: not knowing about an update must not degrade a working dashboard.

func (*Checker) CheckSoon added in v0.125.0

func (c *Checker) CheckSoon(ctx context.Context) error

CheckSoon is the check asked for when the app's window comes to the front: unforced, but due once the last check is SoonAfter old rather than MinInterval, so a release published since shows when the user looks. A failed check still waits RetryAfter.

func (*Checker) Status

func (c *Checker) Status(enabled bool, current string) Status

Status returns the cached view. It performs no I/O, so the settings endpoint stays instant and a disabled checker can never touch the network.

type Status

type Status struct {
	// Enabled reports whether the user turned checking on.
	Enabled bool `json:"enabled"`
	// Current is the running version.
	Current string `json:"current"`
	// Latest is the newest published version, "" if never checked.
	Latest string `json:"latest,omitempty"`
	// UpdateAvailable is true only when Latest is genuinely newer than Current.
	UpdateAvailable bool `json:"update_available"`
	// Command is how to install it, given how this copy was installed.
	Command string `json:"command,omitempty"`
	// AppCommand is how to upgrade the desktop app, when Homebrew's cask
	// installed it on this machine (F12). Set beside Command, not instead of
	// it: the cask and the caprock formula are upgraded separately.
	AppCommand string `json:"app_command,omitempty"`
	// URL is the release page, always safe to offer.
	URL string `json:"url,omitempty"`
	// CheckedAt is the last successful check (unix ms), 0 if never.
	CheckedAt int64 `json:"checked_at,omitempty"`
	// Error is the last failure, if any. A failed check is never fatal.
	Error string `json:"error,omitempty"`
	// Notes is the published release's own description of what changed, as
	// written on GitHub. It arrives in the same response as the tag — asking
	// for the version and then asking again for the notes would be a second
	// request for something we already had.
	Notes string `json:"notes,omitempty"`
	// NotesFor is the version Notes describes. Without it a stale note could
	// be shown beside a different version after a failed check.
	NotesFor string `json:"notes_for,omitempty"`
}

Status is what the UI renders.

Jump to

Keyboard shortcuts

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