Documentation
¶
Overview ¶
Package update implements self-update against the public GitHub Releases repo (memcode-ai/memcode — the same source the curl|sh installer uses). Three surfaces: `memcode upgrade` (explicit, synchronous, replaces the running binary after checksum verification), the silent startup self-update (Auto — same daily cadence, stages the new binary in the background; the running session is untouched and the next launch runs it; MEMCODE_AUTO_UPDATE=off keeps it manual), and a passive "update available" notice (cached in ~/.memcode/update-check.json, never blocks, never nags a dev build).
Index ¶
- Constants
- func AssetName() string
- func Auto(ctx context.Context) string
- func BackgroundNotice(ctx context.Context) string
- func IsNewer(current, latest string) bool
- func LatestVersion(ctx context.Context) (string, error)
- func NoticeFromCache() string
- func ReexecStaged()
- func SyncUpdate(ctx context.Context)
- func Upgrade(ctx context.Context, out io.Writer) (string, error)
Constants ¶
const EnvAutoUpdate = "MEMCODE_AUTO_UPDATE"
EnvAutoUpdate opts OUT of the silent startup self-update ("0" | "false" | "off" | "no"): the daily check then only surfaces the passive notice, like before. Machine-scoped — set it in the global env file, like every knob.
const ReleaseRepo = "memcode-ai/memcode"
ReleaseRepo is the public binary repo (goreleaser's release target).
Variables ¶
This section is empty.
Functions ¶
func AssetName ¶
func AssetName() string
AssetName is the goreleaser archive name for this platform, e.g. "memcode_Darwin_arm64.tar.gz" or "memcode_Windows_x86_64.zip".
func Auto ¶
Auto is the startup self-update: BackgroundNotice's activist sibling, on the same daily cadence and the same silence contract (run it on a goroutine; boot never waits on it; a failed check or install must never surface as an error). When a newer release exists it downloads, checksum-verifies, and atomically swaps the binary ON DISK — the running session keeps its inode and is untouched; the next launch runs the new version. The returned line (printed after the TUI releases the terminal) reports what happened: the staged version, or the manual nudge when auto-update is off, mid-install elsewhere, or the install failed. Concurrent sessions single-flight through a lock file, and the release just staged is remembered in the check cache so still-running old binaries don't each re-download it. The kill-switch story for shipped policy bugs: cut a release, the fleet converges on next launch — no user action.
func BackgroundNotice ¶
BackgroundNotice refreshes the cache when stale (one network call per 24h) and returns the update line, or "". Errors are silent — a failed check must never surface in the product. Intended to run on a goroutine.
func IsNewer ¶
IsNewer reports whether latest is a strictly newer semver than current. Pre-release/build suffixes ("-dev+abc") are stripped before comparing; a malformed version compares as not-newer (never upgrade on garbage input).
func LatestVersion ¶
LatestVersion returns the newest release tag (e.g. "v0.3.1").
func NoticeFromCache ¶
func NoticeFromCache() string
NoticeFromCache is the zero-network variant: reads only the cached check. Safe to call from anywhere (version output, doctor).
func ReexecStaged ¶ added in v0.25.1
func ReexecStaged()
ReexecStaged replaces the current process with the already-staged newer binary, so "the next launch runs it" is THIS launch. Cache-only and instant: no network, no version probe — the staged marker is written only after a checksum-verified install. No-op on Windows (no exec) and for dev builds. Loop-proof twice over: the re-exec'd binary IS the staged version (IsNewer fails), and MEMCODE_REEXEC guards the pathological case.
func SyncUpdate ¶ added in v0.26.1
SyncUpdate is the boot contract: CHECK, UPDATE, RESTART — every launch. A bounded (3s) latest-version check; when a newer release exists it is downloaded, checksum-verified, installed over the binary, and the process re-execs into it before the TUI ever starts. Offline/rate-limited checks fall back to running whatever is already staged. Dev builds, MEMCODE_AUTO_UPDATE=off, and Windows (no exec — prints the restart nudge) opt out of the swap.
Types ¶
This section is empty.