Skip to content

Add version update hint#46

Merged
jmetrikat merged 5 commits intomainfrom
feature/update-hint
Apr 19, 2026
Merged

Add version update hint#46
jmetrikat merged 5 commits intomainfrom
feature/update-hint

Conversation

@jmetrikat
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/updatecheck to fetch/cached the latest GitHub release tag and generate an update hint.
  • Hooks update checking into cmd/root.go via PersistentPreRun/PersistentPostRun and 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.

Comment thread core/updatecheck/updatecheck.go Outdated
return "", false
}

v := <-ch
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
v := <-ch
var v string
select {
case v = <-ch:
default:
return "", false
}

Copilot uses AI. Check for mistakes.
Comment on lines +116 to +121
tmp := path + ".tmp"
if err := os.WriteFile(tmp, data, 0644); err != nil {
return err
}
return os.Rename(tmp, path)
}
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +92 to +94
func cachePath() string {
return filepath.Join(config.GetConfigDir(), cacheFileName)
}
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +53 to +71
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
}
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@jmetrikat jmetrikat merged commit 187c066 into main Apr 19, 2026
5 checks passed
@jmetrikat jmetrikat deleted the feature/update-hint branch April 19, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants