Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1broseidon Ketch updatecheck Engine

From Leeroopedia
Knowledge Sources
Domains CLI, Updates
Last Updated 2026-10-27 00:00 GMT

Overview

A passive update-notice engine that probes GitHub Releases once per day, caches the result to a schema-versioned file, derives the install method (homebrew/go/manual) for the upgrade command, and shows a two-line stderr hint only when the cached status is recent and the user has not been told about this version in 24h.

Description

The `updatecheck` package surfaces a soft "newer version available" notice when ketch is run interactively. GetStatus is the entry point: it detects the install type (homebrew via the Cellar path, go via `$GOPATH/bin`/`$GOBIN`, manual, or `KETCH_INSTALL_METHOD`), resolves the upgrade command, and returns a `Status` with a `Source` of `cache`, `live`, or `none`. The network check happens at most once per day (`checkTTL=24h`); a failed probe enters a 6h failure backoff so a flaky network does not hammer GitHub. ShouldNotify suppresses the notice when the same version was already announced within `notifyTTL=24h`, and MarkNotified records that the user has seen it.

`KETCH_NO_UPDATE_NOTIFIER=1` disables everything; the CI env var also suppresses notices automatically. FormatNotice renders the short two-line reminder (version + command). Semver parsing is strict: a `vdev`/`v(devel)` build or a non-semver tag is not checkable and short-circuits to no notice. The cache is a schema-versioned JSON file in `os.UserCacheDir()/ketch/update-check.json`.

Usage

Wired into `cmd/version.go` and `cmd/update.go` for the passive notice. Use `GetStatus` to decide whether to show a notice; pair with `ShouldNotify`/`MarkNotified` to avoid nagging. Never call on a non-interactive run (CI suppresses it).

Code Reference

Source Location

Signature

type Status struct {
	CheckedAt     time.Time   `json:"checked_at,omitempty"`
	CacheStale    bool        `json:"cache_stale"`
	Available     bool        `json:"available"`
	LatestVersion string      `json:"latest_version,omitempty"`
	InstallType   InstallType `json:"install_type,omitempty"`
	Command       string      `json:"command,omitempty"`
	ReleaseURL    string      `json:"release_url,omitempty"`
	Source        string      `json:"source,omitempty"`
}

func GetStatus(ctx context.Context, opts Options) (Status, error)
func ShouldNotify(status Status) bool
func MarkNotified(status Status) error
func FormatNotice(status Status) string
func Disabled() bool

Import

import "github.com/1broseidon/ketch/updatecheck"

I/O Contract

Inputs

Name Type Required Description
ctx context.Context Yes Bounds the release fetch
opts.CurrentVersion string Yes Built-in version (semver); non-semver short-circuits
opts.AllowNetwork bool No false forces cache-only mode
opts.Timeout time.Duration No Bounds the fetch when > 0

Outputs

Name Type Description
Status updatecheck.Status Source=cache/live/none; Available + LatestVersion + Command
error error Fetch/decode error (non-fatal when a cache exists)
FormatNotice returns string Two-line stderr hint, "" when no update

Usage Examples

Passive notice (cmd/version.go pattern)

status, err := updatecheck.GetStatus(ctx, updatecheck.Options{
	CurrentVersion: buildVersion,
	AllowNetwork:   true,
	Timeout:        3 * time.Second,
})
if updatecheck.ShouldNotify(status) {
	fmt.Fprintln(os.Stderr, updatecheck.FormatNotice(status))
	_ = updatecheck.MarkNotified(status)
}

Cache-only mode

status, _ := updatecheck.GetStatus(ctx, updatecheck.Options{
	CurrentVersion: "v1.2.3",
	AllowNetwork:   false, // never probe; read the cache file only
})

Related Pages

Implements Principle

Uses Heuristic

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment