Documentation
¶
Overview ¶
Package updatecheck queries GitHub for the latest commit on the CLI's main branch, caches the result for 24h, and prints a one-line stderr warning when the running binary is behind.
Design constraints:
- Must never block the parent command for noticeable time (we cap waits at a few hundred ms).
- Must never break the parent command on any failure (corrupt cache, network error, 4xx/5xx from GitHub — all swallowed).
- Must be opt-out-friendly: env var, config flag, --quiet, dirty tree, and a cobra annotation for special commands (MCP stdio).
Index ¶
Constants ¶
const ( DefaultAPIURL = "https://api.github.com/repos/taufinity/cli/commits/main" DefaultCacheMaxAge = 24 * time.Hour DefaultHTTPTimeout = 2 * time.Second // EnvDisable, when set to "1", skips both the network check and the // warning at exit. EnvDisable = "TAUFINITY_NO_UPDATE_CHECK" // AnnotationSuppress is the cobra command annotation that disables the // update check side effects (background goroutine + warning) for that // command. Used by `taufinity mcp stdio`. AnnotationSuppress = "suppress-update-warning" )
Defaults.
Variables ¶
This section is empty.
Functions ¶
func IsBehind ¶ added in v0.5.0
IsBehind reports whether the running binary's commit differs from the cached latest SHA. Returns false when either value is missing or too short to compare safely (dirty tree, built without VCS info, never checked). It is the pure staleness predicate — callers decide what to do with it.
Types ¶
type Cache ¶
type Cache struct {
// CheckedAt is when we last queried GitHub. Zero value means "never".
CheckedAt time.Time `json:"checked_at"`
// LatestSHA is the SHA returned by GitHub at CheckedAt, or "" if the call
// failed (we cache the failure for 24h to avoid hammering on a broken
// network).
LatestSHA string `json:"latest_sha"`
}
Cache is the on-disk record of the last GitHub commits-API check.
func LoadCache ¶
func LoadCache() Cache
LoadCache reads the cache from disk. A missing or unparseable file is NOT an error — it returns a zero-value Cache so callers can treat it as "never checked." We deliberately don't surface read errors to the caller: a corrupt cache must never break the parent CLI command.
type Options ¶
type Options struct {
// Quiet suppresses the warning unconditionally.
Quiet bool
// ConfigDisabled is the resolved value of the user-config opt-out
// (UserConfig.UpdateCheck == "false").
ConfigDisabled bool
// CommandSuppress is set by the caller when the running cobra command
// (or any ancestor) carries AnnotationSuppress.
CommandSuppress bool
}
Options controls MaybeWarn behavior.
type Runner ¶
type Runner struct {
APIURL string
HTTPClient *http.Client
Timeout time.Duration
Now func() time.Time // for tests
Debug io.Writer // non-nil to write debug lines on failure
// contains filtered or unexported fields
}
Runner controls a background staleness check.