Repository navigation
feat: Show the agentop update notice in color, and say to reopen agentop #2052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,34 @@ | ||
| package tui | ||
|
|
||
| import ( | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/charmbracelet/lipgloss" | ||
|
|
||
| "github.com/rossoctl/cortex/cmd/agentop/updatestatus" | ||
| ) | ||
|
|
||
| // updateSuffix is the update notice after the build on the title bar, or "". | ||
| // updateSuffix is the update notice after the build on the title bar, or "", and | ||
| // its ink: green for news, red for a failure, amber for a missed check. | ||
| // The first rule that matches wins. | ||
| func updateSuffix(st updatestatus.Status, version string, serviceInstall bool, now time.Time) string { | ||
| func updateSuffix(st updatestatus.Status, version string, serviceInstall bool, now time.Time) (string, lipgloss.Style) { | ||
| switch { | ||
| case st.Installed != version && updatestatus.IsRelease(st.Installed) && | ||
| (updatestatus.IsRelease(version) || updatestatus.IsRC(version)): | ||
| return "· updated to " + st.Installed + ", restart agentop" | ||
| // Not "restart agentop": that reads as agentop service restart, which this does not need. | ||
| return "· " + st.Installed + " installed, quit and reopen agentop", styleOK | ||
| case st.Note != "": | ||
| return "· " + st.Note | ||
| return "· " + st.Note, styleOK | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: The only note written today is |
||
| case st.Result == updatestatus.ResultFailed: | ||
| return "· update to " + st.Latest + " failed, see agentop doctor" | ||
| return "· update to " + st.Latest + " failed, see agentop doctor", styleError | ||
| // Only a newer release: a dev, main or RC build is often ahead of Latest. | ||
| case updatestatus.Newer(st.Latest, st.Installed): | ||
| return "· " + st.Latest + " available" | ||
| return "· " + st.Latest + " available", styleOK | ||
| case serviceInstall && now.Sub(st.CheckedAt) > 72*time.Hour: | ||
| return "· no update check since " + st.CheckedAt.Format("2006-01-02") | ||
| return "· no update check since " + st.CheckedAt.Format("2006-01-02"), styleWarn | ||
| } | ||
| return "" | ||
| return "", styleNone | ||
| } | ||
|
|
||
| // readUpdateNotice sets m.updateNote from m.updateFile. A missing or bad file | ||
|
|
@@ -37,5 +42,10 @@ func (m *model) readUpdateNotice() { | |
| if err != nil { | ||
| return | ||
| } | ||
| m.updateNote = updateSuffix(st, m.version, m.serviceInstall, time.Now()) | ||
| m.updateNote, m.updateInk = updateSuffix(st, m.version, m.serviceInstall, time.Now()) | ||
| } | ||
|
|
||
| // titleView is renderTitle with the update notice in its own ink, so it stands out. | ||
| func (m *model) titleView(title string) string { | ||
| return renderTitleInk(title, strings.TrimPrefix(m.updateNote, "· "), m.updateInk) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "The proxy already runs vX.Y.Z" holds for a service install and a
--no-serviceinstall, becausesetup's service step restarts the proxy when the binaries change. It does not hold for an--install-onlyinstall. TherebuildSetupStepsstops after the binaries and PATH steps, so a proxy the user started by hand keeps running the old binary. A manualagentop updatethere still writesupdated, so this notice shows. Maybe add a short qualifier, e.g. "With a service or background proxy, the proxy already runs vX.Y.Z."