Conversation
There was a problem hiding this comment.
Pull request overview
Adds a background “new version available” hint to the Anytype CLI by checking GitHub releases and surfacing a message after command execution, with caching and opt-out support.
Changes:
- Introduces
core/updatecheckto fetch/cached the latest GitHub release tag and generate an update hint. - Hooks update checking into
cmd/root.goviaPersistentPreRun/PersistentPostRunand adds--no-update-check. - Disables update checking for interactive shell runs to avoid repeated checks.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| core/updatecheck/updatecheck.go | New package implementing latest-release fetch, caching, and hint generation. |
| cmd/root.go | Starts update check in background and prints hint post-command; adds --no-update-check. |
| cmd/shell/shell.go | Disables update checks in interactive shell mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return "", false | ||
| } | ||
|
|
||
| v := <-ch |
There was a problem hiding this comment.
Hint blocks on a channel receive (v := <-ch). If the update-check goroutine hasn’t finished yet, PersistentPostRun will wait here (up to the 400ms deadline), adding latency to fast commands. Consider making Hint non-blocking (e.g., select with a default / short timeout) so the hint is shown only when the result is already available.
| v := <-ch | |
| var v string | |
| select { | |
| case v = <-ch: | |
| default: | |
| return "", false | |
| } |
| tmp := path + ".tmp" | ||
| if err := os.WriteFile(tmp, data, 0644); err != nil { | ||
| return err | ||
| } | ||
| return os.Rename(tmp, path) | ||
| } |
There was a problem hiding this comment.
writeCache uses os.Rename(tmp, path) to replace the cache file. On Windows, os.Rename fails if the destination already exists, so the cache may never refresh after the first successful write (and the CLI may re-fetch on every run once CheckedAt becomes stale). Handle Windows/overwrite semantics explicitly (e.g., remove existing destination or retry with an OS-specific replace strategy) and consider surfacing/logging the error instead of ignoring it upstream.
| func cachePath() string { | ||
| return filepath.Join(config.GetConfigDir(), cacheFileName) | ||
| } |
There was a problem hiding this comment.
cachePath() joins config.GetConfigDir() with the cache filename, but GetConfigDir() can return an empty string when os.UserHomeDir() fails. In that case the cache file will be read/written relative to the current working directory, which is surprising and can cause permission issues. Consider returning an empty path / disabling caching when the config dir is unavailable, and have latestVersion treat that as a non-fatal "no cache" condition.
| func Hint(ch <-chan string, current string) (string, bool) { | ||
| if ch == nil || !strings.HasPrefix(current, "v") { | ||
| return "", false | ||
| } | ||
|
|
||
| v := <-ch | ||
| if v == "" { | ||
| return "", false | ||
| } | ||
|
|
||
| base := current | ||
| if i := strings.Index(base, "-"); i != -1 { | ||
| base = base[:i] | ||
| } | ||
| if semver.Compare(base, v) >= 0 { | ||
| return "", false | ||
| } | ||
| return fmt.Sprintf("A new version (%s) is available. Run: anytype update", v), true | ||
| } |
There was a problem hiding this comment.
New update-check behavior is introduced here (version comparison / hint formatting / cache fallback), but there are no unit tests for the updatecheck package. Adding focused tests for Hint (including pre-release versions) and for latestVersion’s cache/refresh behavior (with a stubbed HTTP client or httptest server) would help prevent regressions.
No description provided.