Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cmd/agentop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ install updates itself.

The title bar shows one of these notices. When more than one applies, it shows the first:

1. `· updated to vX.Y.Z, restart agentop`
2. `· update to vX.Y.Z failed, see agentop doctor`
3. `· vX.Y.Z available`: only when vX.Y.Z is newer than the installed release or
1. `· vX.Y.Z installed, quit and reopen agentop`, in green. The proxy already runs
vX.Y.Z. Only the open agentop still runs the old binary, so you do not need

Copy link
Copy Markdown
Collaborator

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-service install, because setup's service step restarts the proxy when the binaries change. It does not hold for an --install-only install. There buildSetupSteps stops after the binaries and PATH steps, so a proxy the user started by hand keeps running the old binary. A manual agentop update there still writes updated, so this notice shows. Maybe add a short qualifier, e.g. "With a service or background proxy, the proxy already runs vX.Y.Z."

`agentop service restart`.
2. `· update to vX.Y.Z failed, see agentop doctor`, in red.
3. `· vX.Y.Z available`, in green: only when vX.Y.Z is newer than the installed release or
release candidate. A `dev` or `main` build shows no notice.
4. `· no update check since <date>`: service installs only, after 72 hours with no check.
4. `· no update check since <date>`, in amber: service installs only, after 72 hours with no check.

## Run

Expand Down
8 changes: 5 additions & 3 deletions cmd/agentop/tui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ type model struct {
serviceInstall bool
// updateNote is the update notice after the build on the title bar.
updateNote string
// updateInk is the color of updateNote.
updateInk lipgloss.Style
// lastHarvest is when the most recent harvest was STARTED. Read by TWO callers: the sessions
// pane's backoff gate, which asks whether untitledBackoff has elapsed since then, and the
// timeline pane's gate for unlabeled subagents (timelineLabelHarvestEvery). The picker
Expand Down Expand Up @@ -2612,7 +2614,7 @@ func (m *model) paneView() string {
// yet there is no box to draw, and the body shows as it is.
func (m *model) pickerView(title, body, footer string) string {
if m.width == 0 {
return lipgloss.JoinVertical(lipgloss.Left, renderTitle(title), body, footer)
return lipgloss.JoinVertical(lipgloss.Left, m.titleView(title), body, footer)
}
frameH := m.bodyHeight
if m.searching && m.searchPane != targetHelp {
Expand All @@ -2621,7 +2623,7 @@ func (m *model) pickerView(title, body, footer string) string {
if m.bodyHeight == 0 {
frameH = lipgloss.Height(body) // layout() has not run, so there is no reservation to fill
}
rows := []string{renderTitle(title), boxTop("", m.width)}
rows := []string{m.titleView(title), boxTop("", m.width)}
rows = append(rows, boxFrame(body, m.width, frameH)...)
rows = append(rows, boxBottom(m.width), footer)
return lipgloss.JoinVertical(lipgloss.Left, rows...)
Expand Down Expand Up @@ -2758,7 +2760,7 @@ func (m *model) paneContent() (title, body string) {
// framePane is a data pane's screen: the title, the spend band and its drawer, the body in the
// box at exactly the rows layout() reserved, and the footer on the last row.
func (m *model) framePane(title, body string) string {
header := renderTitle(title)
header := m.titleView(title)
// The band sits directly under the title because that is the whole requirement: spend
// read BEFORE the data rather than navigated to.
//
Expand Down
28 changes: 21 additions & 7 deletions cmd/agentop/tui/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ var titleMarkRe = regexp.MustCompile(` · |https?://\S+|\([^()]*\)`)

// renderTitle styles a pane title without changing its text: a leading "agentop" in
// accent bold, " · " dim, URLs and (…) groups muted, the rest bold.
func renderTitle(title string) string {
func renderTitle(title string) string { return renderTitleInk(title, "", styleNone) }

// renderTitleInk is renderTitle with the first copy of mark in bold ink. An empty
// mark, or one that is not in the title, leaves the title as renderTitle styles it.
func renderTitleInk(title, mark string, ink lipgloss.Style) string {
if !colorOn() {
return styleTitle.Render(title)
}
Expand All @@ -293,23 +297,33 @@ func renderTitle(title string) string {
b.WriteString(styleAccentBold.Render("agentop"))
rest = r
}
if i := strings.Index(rest, mark); mark != "" && i >= 0 {
writeTitleSegments(&b, rest[:i])
b.WriteString(ink.Bold(true).Render(mark))
rest = rest[i+len(mark):]
}
writeTitleSegments(&b, rest)
return b.String()
}

// writeTitleSegments writes s with " · " dim, URLs and (…) groups muted, the rest bold.
func writeTitleSegments(b *strings.Builder, s string) {
last := 0
for _, loc := range titleMarkRe.FindAllStringIndex(rest, -1) {
for _, loc := range titleMarkRe.FindAllStringIndex(s, -1) {
if loc[0] > last {
b.WriteString(styleBold.Render(rest[last:loc[0]]))
b.WriteString(styleBold.Render(s[last:loc[0]]))
}
m := rest[loc[0]:loc[1]]
m := s[loc[0]:loc[1]]
if m == " · " {
b.WriteString(styleDim.Render(m))
} else {
b.WriteString(styleMuted.Render(m))
}
last = loc[1]
}
if last < len(rest) {
b.WriteString(styleBold.Render(rest[last:]))
if last < len(s) {
b.WriteString(styleBold.Render(s[last:]))
}
return b.String()
}

// colorGroup is the meaning a cell's value carries, which picks its ink.
Expand Down
28 changes: 19 additions & 9 deletions cmd/agentop/tui/update_notice.go
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: The only note written today is cpexStatusNote ("cpex build removed; now the default cortex"). It tells the user that a build they chose, for laptop policy, was replaced. That is closer to a heads-up (amber, styleWarn) than to good news (green). Your call. If notes are meant to stay neutral "news", this is fine as 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
Expand All @@ -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)
}
65 changes: 59 additions & 6 deletions cmd/agentop/tui/update_notice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package tui
import (
"os"
"path/filepath"
"strings"
"testing"
"time"

"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
"github.com/muesli/termenv"

"github.com/rossoctl/cortex/cmd/agentop/updatestatus"
)

Expand All @@ -20,7 +25,7 @@ func TestUpdateSuffix(t *testing.T) {
want string
}{
{"updated", updatestatus.Status{Installed: "v0.9.6", Latest: "v0.9.6", Result: updatestatus.ResultUpdated, CheckedAt: noticeNow},
"v0.9.5", true, "· updated to v0.9.6, restart agentop"},
"v0.9.5", true, "· v0.9.6 installed, quit and reopen agentop"},
{"failed", updatestatus.Status{Installed: "v0.9.5", Latest: "v0.9.6", Result: updatestatus.ResultFailed, CheckedAt: noticeNow},
"v0.9.5", true, "· update to v0.9.6 failed, see agentop doctor"},
// A cpex replacement keeps the version, so the only sign is the note.
Expand All @@ -40,34 +45,34 @@ func TestUpdateSuffix(t *testing.T) {
{"rc release out", updatestatus.Status{Installed: "v0.10.0-rc.1", Latest: "v0.10.0", Result: updatestatus.ResultWaiting, CheckedAt: noticeNow},
"v0.10.0-rc.1", true, "· v0.10.0 available"},
{"rc updated", updatestatus.Status{Installed: "v0.10.0", Latest: "v0.10.0", Result: updatestatus.ResultUpdated, CheckedAt: noticeNow},
"v0.10.0-rc.1", true, "· updated to v0.10.0, restart agentop"},
"v0.10.0-rc.1", true, "· v0.10.0 installed, quit and reopen agentop"},
// Latest moved back: the update installs it, with no "available" before.
{"withdrawn", updatestatus.Status{Installed: "v0.10.0", Latest: "v0.9.5", Result: updatestatus.ResultWaiting, CheckedAt: noticeNow},
"v0.10.0", true, ""},
} {
if got := updateSuffix(tc.st, tc.version, tc.service, noticeNow); got != tc.want {
if got, _ := updateSuffix(tc.st, tc.version, tc.service, noticeNow); got != tc.want {
t.Errorf("%s: updateSuffix = %q, want %q", tc.name, got, tc.want)
}
}
}

func TestUpdateSuffixIgnoresEmptyLatest(t *testing.T) {
st := updatestatus.Status{Installed: "v0.9.5", Result: updatestatus.ResultUpdated, CheckedAt: noticeNow}
if got := updateSuffix(st, "v0.9.5", true, noticeNow); got != "" {
if got, _ := updateSuffix(st, "v0.9.5", true, noticeNow); got != "" {
t.Errorf("updateSuffix with empty latest = %q, want empty", got)
}
}

func TestUpdateSuffixDevBuild(t *testing.T) {
st := updatestatus.Status{Installed: "v0.9.6", Latest: "v0.9.6", Result: updatestatus.ResultCurrent, CheckedAt: noticeNow}
if got := updateSuffix(st, "dev-abc", true, noticeNow); got != "" {
if got, _ := updateSuffix(st, "dev-abc", true, noticeNow); got != "" {
t.Errorf("updateSuffix on a dev build = %q, want empty", got)
}
}

func TestUpdateSuffixStaleNeedsService(t *testing.T) {
st := updatestatus.Status{Installed: "v0.9.5", Latest: "v0.9.5", Result: updatestatus.ResultCurrent, CheckedAt: noticeNow.Add(-73 * time.Hour)}
if got := updateSuffix(st, "v0.9.5", false, noticeNow); got != "" {
if got, _ := updateSuffix(st, "v0.9.5", false, noticeNow); got != "" {
t.Errorf("updateSuffix with no service = %q, want empty", got)
}
}
Expand Down Expand Up @@ -103,3 +108,51 @@ func TestUpdateNoticeRereadOnRefreshTick(t *testing.T) {
t.Errorf("updateNote after a tick = %q, want %q", got, want)
}
}

// Green for news, red for a failure, amber for a missed check.
func TestUpdateSuffixInk(t *testing.T) {
// With no color, every style renders "x" alike and the test cannot fail.
withProfile(t, termenv.TrueColor)
for _, tc := range []struct {
name string
st updatestatus.Status
version string
want lipgloss.Style
}{
{"installed", updatestatus.Status{Installed: "v0.9.6", Latest: "v0.9.6", Result: updatestatus.ResultUpdated, CheckedAt: noticeNow}, "v0.9.5", styleOK},
{"note", updatestatus.Status{Installed: "v0.9.5", Latest: "v0.9.5", Result: updatestatus.ResultUpdated, Note: "n", CheckedAt: noticeNow}, "v0.9.5", styleOK},
{"failed", updatestatus.Status{Installed: "v0.9.5", Latest: "v0.9.6", Result: updatestatus.ResultFailed, CheckedAt: noticeNow}, "v0.9.5", styleError},
{"available", updatestatus.Status{Installed: "v0.9.5", Latest: "v0.9.6", Result: updatestatus.ResultWaiting, CheckedAt: noticeNow}, "v0.9.5", styleOK},
{"stale", updatestatus.Status{Installed: "v0.9.5", Latest: "v0.9.5", Result: updatestatus.ResultCurrent, CheckedAt: noticeNow.Add(-73 * time.Hour)}, "v0.9.5", styleWarn},
} {
_, ink := updateSuffix(tc.st, tc.version, true, noticeNow)
if got, want := ink.Render("x"), tc.want.Render("x"); got != want {
t.Errorf("%s: ink renders %q, want %q", tc.name, got, want)
}
}
}

// The title keeps its text, and only the notice takes the notice's ink.
func TestTitleViewInksTheNotice(t *testing.T) {
path := filepath.Join(t.TempDir(), updatestatus.FileName)
writeNoticeFile(t, path, "v0.9.6")
m := &model{version: "v0.9.5", updateFile: path}
m.readUpdateNotice()
withProfile(t, termenv.TrueColor)
in := m.appName() + " · http://127.0.0.1:47601"
got := m.titleView(in)
if s := ansi.Strip(got); s != in {
t.Fatalf("stripped = %q, want %q", s, in)
}
if want := styleOK.Bold(true).Render("v0.9.6 available"); !strings.Contains(got, want) {
t.Errorf("notice not green bold in %q", got)
}
if !strings.Contains(got, styleMuted.Render("http://127.0.0.1:47601")) {
t.Errorf("URL lost its style in %q", got)
}
// With no notice, titleView is renderTitle.
m.updateNote, m.updateInk = "", styleNone
if got, want := m.titleView(in), renderTitle(in); got != want {
t.Errorf("titleView with no notice = %q, want %q", got, want)
}
}
Loading