From ceb138faf4ee91534ca0be0806fb51179f317277 Mon Sep 17 00:00:00 2001 From: merefield Date: Sun, 16 Aug 2026 23:52:59 +0100 Subject: [PATCH 1/4] CHORE: upgrade Charm stack to v2 --- README.md | 10 ++--- go.mod | 30 +++++++------- go.sum | 69 +++++++++++++++++--------------- internal/ui/benchmark.go | 2 +- internal/ui/benchmark_test.go | 41 +++++++++---------- internal/ui/meters.go | 29 +++++++------- internal/ui/meters_test.go | 2 +- internal/ui/model.go | 41 +++++++++++-------- internal/ui/model_test.go | 59 ++++++++++++++++----------- internal/ui/monitor.go | 2 +- internal/ui/monitor_test.go | 18 ++++----- internal/ui/quota_api_eq_test.go | 4 +- internal/ui/quota_status.go | 5 ++- internal/ui/quota_status_test.go | 5 ++- internal/ui/tabs.go | 11 ++--- internal/ui/tabs_test.go | 30 ++++++-------- internal/ui/theme.go | 18 +++++---- internal/ui/view.go | 28 +++++++++---- internal/ui/view_test.go | 35 +++++++++++----- internal/version/version.go | 2 +- internal/version/version_test.go | 4 +- main.go | 9 ++--- main_test.go | 2 +- 23 files changed, 254 insertions(+), 202 deletions(-) diff --git a/README.md b/README.md index ef628081..430d1df9 100644 --- a/README.md +++ b/README.md @@ -1016,9 +1016,9 @@ need Go or Codexometer's source dependencies. ## Versioning Codexometer follows semantic versioning; the current source version is -`v0.7.5`. The Git tag is the release source of truth. Go automatically embeds +`v0.7.6`. The Git tag is the release source of truth. Go automatically embeds that tag in binaries built with -`go install github.com/merefield/codexometer@v0.7.5`; direct source builds fall +`go install github.com/merefield/codexometer@v0.7.6`; direct source builds fall back to the maintained value in `internal/version/version.go`. Both forms report the embedded version and exit without starting the interface: @@ -1031,7 +1031,7 @@ codexometer --version Release automation can override the source-build fallback without editing code: ```sh -go build -ldflags="-s -w -X github.com/merefield/codexometer/internal/version.Fallback=0.7.5" . +go build -ldflags="-s -w -X github.com/merefield/codexometer/internal/version.Fallback=0.7.6" . ``` ## How refresh works @@ -1126,8 +1126,8 @@ go test -cover ./... Codexometer uses: - Go 1.26.6+ -- Bubble Tea for the terminal event loop -- Lip Gloss for adaptive ANSI styling +- Bubble Tea v2 for the terminal event loop and declarative terminal modes +- Lip Gloss v2 for adaptive ANSI styling and layout - Starlark for deterministic, hermetic benchmark-code evaluation - Codex app-server JSON-RPC for authenticated quota data - Local Codex rollout `token_count` records for live Monitor telemetry diff --git a/go.mod b/go.mod index 3d35c397..a04baa55 100644 --- a/go.mod +++ b/go.mod @@ -3,26 +3,26 @@ module github.com/merefield/codexometer go 1.26.6 require ( - github.com/charmbracelet/bubbletea v1.2.4 - github.com/charmbracelet/lipgloss v1.0.0 - github.com/charmbracelet/x/ansi v0.4.5 + charm.land/bubbletea/v2 v2.0.8 + charm.land/lipgloss/v2 v2.0.6 + github.com/charmbracelet/x/ansi v0.11.8 github.com/gorilla/websocket v1.5.3 go.starlark.net v0.0.0-20260708150628-5395d018f003 - golang.org/x/sys v0.42.0 + golang.org/x/sys v0.47.0 ) require ( - github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect - github.com/charmbracelet/x/term v0.2.1 // indirect - github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect - github.com/lucasb-eyer/go-colorful v1.2.0 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-localereader v0.0.1 // indirect - github.com/mattn/go-runewidth v0.0.15 // indirect - github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect + github.com/charmbracelet/colorprofile v0.4.3 // indirect + github.com/charmbracelet/ultraviolet v0.0.0-20260811164956-006e29f97886 // indirect + github.com/charmbracelet/x/term v0.2.2 // indirect + github.com/charmbracelet/x/termios v0.1.1 // indirect + github.com/charmbracelet/x/windows v0.2.2 // indirect + github.com/clipperhouse/displaywidth v0.11.0 // indirect + github.com/clipperhouse/uax29/v2 v2.7.0 // indirect + github.com/lucasb-eyer/go-colorful v1.4.1 // indirect + github.com/mattn/go-runewidth v0.0.24 // indirect github.com/muesli/cancelreader v0.2.2 // indirect - github.com/muesli/termenv v0.15.2 // indirect github.com/rivo/uniseg v0.4.7 // indirect - golang.org/x/sync v0.9.0 // indirect - golang.org/x/text v0.3.8 // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect + golang.org/x/sync v0.22.0 // indirect ) diff --git a/go.sum b/go.sum index f2552ce5..51c7fedd 100644 --- a/go.sum +++ b/go.sum @@ -1,45 +1,48 @@ -github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= -github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= -github.com/charmbracelet/bubbletea v1.2.4 h1:KN8aCViA0eps9SCOThb2/XPIlea3ANJLUkv3KnQRNCE= -github.com/charmbracelet/bubbletea v1.2.4/go.mod h1:Qr6fVQw+wX7JkWWkVyXYk/ZUQ92a6XNekLXa3rR18MM= -github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg= -github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo= -github.com/charmbracelet/x/ansi v0.4.5 h1:LqK4vwBNaXw2AyGIICa5/29Sbdq58GbGdFngSexTdRM= -github.com/charmbracelet/x/ansi v0.4.5/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= -github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= -github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= -github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= +charm.land/bubbletea/v2 v2.0.8 h1:SxTJMhCAI3lbPmy4SgX5LWZ24AdINr4I6UEqzZvYJuY= +charm.land/bubbletea/v2 v2.0.8/go.mod h1:2SkdgoTXluXJHOUwAoRlRXF/28vklb1rFl6GcgV1/ss= +charm.land/lipgloss/v2 v2.0.6 h1:EaGKeuA8FvF+v2BT5VmZd2LoYLaMZJXA5n34th8nCIQ= +charm.land/lipgloss/v2 v2.0.6/go.mod h1:ipDDJNSGa1hlwDtSfW1s2/xR8Vdhbut4PXh2zEKZd0Q= +github.com/aymanbagabas/go-udiff v0.4.1 h1:OEIrQ8maEeDBXQDoGCbbTTXYJMYRCRO1fnodZ12Gv5o= +github.com/aymanbagabas/go-udiff v0.4.1/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w= +github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q= +github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q= +github.com/charmbracelet/ultraviolet v0.0.0-20260811164956-006e29f97886 h1:rdnVWKgJpTVXKuKuJyxDJ+NFJdUaUqGvyGy61OcvlbA= +github.com/charmbracelet/ultraviolet v0.0.0-20260811164956-006e29f97886/go.mod h1:nAw0d9PhFp1qdzi2xhQU5YOu5sVpDIHWlaW2Uz/bCro= +github.com/charmbracelet/x/ansi v0.11.8 h1:JMFwp0CgDC2+jcOB162HH5k7I3FVbgFSMMYg7dSPBQQ= +github.com/charmbracelet/x/ansi v0.11.8/go.mod h1:ZNN+3mXny/516oTQPLMPIBeSINvNJJQ8uQXDgbeJxY0= +github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA= +github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I= +github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk= +github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI= +github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8JawjaNZY= +github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo= +github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM= +github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k= +github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8= +github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0= +github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk= +github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= -github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= -github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= -github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= -github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= -github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= +github.com/lucasb-eyer/go-colorful v1.4.1 h1:1EO+WB73+EH8EVbzlrG3KLAfEypQWVHIBqlTf+2hNss= +github.com/lucasb-eyer/go-colorful v1.4.1/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-runewidth v0.0.24 h1:cpokDiIn0MGnhdHwuWnJBITySJ20QyNGnY2kR/ay2DU= +github.com/mattn/go-runewidth v0.0.24/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= -github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= -github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= go.starlark.net v0.0.0-20260708150628-5395d018f003 h1:cAxcqHgW8fnmT0cEBU3TzvVYHIFt8IIGDMWUF6rImk4= go.starlark.net v0.0.0-20260708150628-5395d018f003/go.mod h1:Iue6g6iirlfLoVi/DYCi5/x0h/bAOuWF3dULTKpt2Vo= -golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= -golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= -golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek= +golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= +golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= +golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= diff --git a/internal/ui/benchmark.go b/internal/ui/benchmark.go index 68eff751..158aa171 100644 --- a/internal/ui/benchmark.go +++ b/internal/ui/benchmark.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/charmbracelet/lipgloss" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" "github.com/merefield/codexometer/internal/codex" diff --git a/internal/ui/benchmark_test.go b/internal/ui/benchmark_test.go index a88a643e..bd615568 100644 --- a/internal/ui/benchmark_test.go +++ b/internal/ui/benchmark_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" "github.com/merefield/codexometer/internal/codex" @@ -216,15 +216,14 @@ func TestBenchmarkButtonSupportsHoverAndClick(t *testing.T) { model.width, model.height = 100, 30 model.meterView = viewBenchmark x, y := benchmarkControlCoordinates(t, model, footerButtonBenchmarkSelected) - mouse := tea.MouseMsg{X: x, Y: y, Action: tea.MouseActionMotion} + mouse := tea.MouseMotionMsg{X: x, Y: y} updated, command := model.Update(mouse) model = updated.(Model) if command != nil || model.hoveredButton != footerButtonBenchmarkSelected { t.Fatal("benchmark button hover was not recorded") } - mouse.Action = tea.MouseActionPress - mouse.Button = tea.MouseButtonLeft - updated, command = model.Update(mouse) + mouse.Button = tea.MouseLeft + updated, command = model.Update(tea.MouseClickMsg(mouse)) model = updated.(Model) if command == nil || model.benchmarkState != benchmarkRunning { t.Fatal("benchmark button click did not start suite") @@ -254,17 +253,17 @@ func TestBenchmarkPageKeysAndMouseWheelScrollResults(t *testing.T) { for index := 0; index < 30; index++ { model.benchmarkResults = append(model.benchmarkResults, codex.BenchmarkResult{DisplayName: "Model", Effort: "low"}) } - updated, command := model.Update(tea.KeyMsg{Type: tea.KeyPgUp}) + updated, command := model.Update(specialKey(tea.KeyPgUp)) model = updated.(Model) if command != nil || model.benchmarkScroll == 0 { t.Fatalf("Page Up did not scroll: offset=%d command=%v", model.benchmarkScroll, command != nil) } - updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyPgDown}) + updated, _ = model.Update(specialKey(tea.KeyPgDown)) model = updated.(Model) if model.benchmarkScroll != 0 { t.Fatalf("Page Down offset = %d, want 0", model.benchmarkScroll) } - updated, _ = model.Update(tea.MouseMsg{Button: tea.MouseButtonWheelUp}) + updated, _ = model.Update(tea.MouseWheelMsg{Button: tea.MouseWheelUp}) model = updated.(Model) if model.benchmarkScroll != 3 { t.Fatalf("mouse-wheel offset = %d, want 3", model.benchmarkScroll) @@ -282,18 +281,18 @@ func TestBenchmarkHeadingButtonsSortAndReverse(t *testing.T) { dashboard := model.dashboardLayout() geometry := layoutBenchmarkArea(dashboard.contentWidth, dashboard.meterHeight) headerX, headerY := renderedTextCoordinates(t, model, "[MODEL]") - mouse := tea.MouseMsg{ - X: headerX, - Y: headerY, - Action: tea.MouseActionMotion, + mouse := tea.MouseMotionMsg{ + X: headerX, + Y: headerY, } updated, command := model.Update(mouse) model = updated.(Model) if command != nil || !model.benchmarkSortHovered || model.benchmarkHoveredSort != benchmarkSortModel { t.Fatal("model heading did not highlight on hover") } - mouse.Button, mouse.Action = tea.MouseButtonLeft, tea.MouseActionPress - updated, command = model.Update(mouse) + mouse.Button = tea.MouseLeft + click := tea.MouseClickMsg(mouse) + updated, command = model.Update(click) model = updated.(Model) if command != nil || model.benchmarkSort != benchmarkSortModel || model.benchmarkSortDescending { t.Fatalf("first heading click did not select ascending model sort: %#v", model) @@ -302,7 +301,7 @@ func TestBenchmarkHeadingButtonsSortAndReverse(t *testing.T) { if ordered[0].DisplayName != "Alpha" { t.Fatalf("ascending model order = %q first, want Alpha", ordered[0].DisplayName) } - updated, _ = model.Update(mouse) + updated, _ = model.Update(click) model = updated.(Model) ordered = sortedBenchmarkResults(model.benchmarkResults, model.benchmarkSort, model.benchmarkSortDescending) if !model.benchmarkSortDescending || ordered[0].DisplayName != "Zulu" { @@ -566,7 +565,7 @@ func TestBenchmarkTaskSelectorRunAllGuardAndExactTurnCount(t *testing.T) { model.meterView = viewBenchmark model.benchmarkCombinations = 33 - updated, _ := model.Update(tea.KeyMsg{Type: tea.KeyRight}) + updated, _ := model.Update(specialKey(tea.KeyRight)) model = updated.(Model) if model.benchmarkSelectedTask != 1 { t.Fatalf("right arrow selected task %d, want 1", model.benchmarkSelectedTask) @@ -688,7 +687,7 @@ func TestBenchmarkPassFailFilterButtonsAndHotkey(t *testing.T) { }, } x, y := benchmarkControlCoordinates(t, model, footerButtonBenchmarkFilterFail) - updated, command := model.Update(tea.MouseMsg{X: x, Y: y, Button: tea.MouseButtonLeft, Action: tea.MouseActionPress}) + updated, command := model.Update(tea.MouseClickMsg{X: x, Y: y, Button: tea.MouseLeft}) model = updated.(Model) if command == nil || model.benchmarkFilter != benchmarkFilterFail { t.Fatal("FAIL filter button did not activate") @@ -714,7 +713,7 @@ func TestBenchmarkRankWeightButtonsAndHotkeyRecomputeImmediately(t *testing.T) { }, } x, y := benchmarkControlCoordinates(t, model, footerButtonBenchmarkRankCost) - updated, command := model.Update(tea.MouseMsg{X: x, Y: y, Button: tea.MouseButtonLeft, Action: tea.MouseActionPress}) + updated, command := model.Update(tea.MouseClickMsg{X: x, Y: y, Button: tea.MouseLeft}) model = updated.(Model) if command == nil || model.benchmarkRankMode != benchmarkRankCost || model.flashedButton != footerButtonBenchmarkRankCost { t.Fatalf("Cost rank button did not activate and flash: mode=%d flash=%d", model.benchmarkRankMode, model.flashedButton) @@ -738,7 +737,7 @@ func TestBenchmarkRankWeightButtonsAndHotkeyRecomputeImmediately(t *testing.T) { } x, y = benchmarkControlCoordinates(t, model, footerButtonBenchmarkRankBalanced) - updated, _ = model.Update(tea.MouseMsg{X: x, Y: y, Button: tea.MouseButtonLeft, Action: tea.MouseActionPress}) + updated, _ = model.Update(tea.MouseClickMsg{X: x, Y: y, Button: tea.MouseLeft}) model = updated.(Model) if model.benchmarkRankMode != benchmarkRankBalanced { t.Fatalf("Balanced rank button selected mode %d", model.benchmarkRankMode) @@ -773,7 +772,7 @@ func renderedTextCoordinates(t *testing.T, model Model, text string) (int, int) func renderedTextStart(t *testing.T, model Model, text string) (int, int) { t.Helper() - for y, line := range strings.Split(ansi.Strip(model.View()), "\n") { + for y, line := range strings.Split(ansi.Strip(model.render()), "\n") { if byteX := strings.Index(line, text); byteX >= 0 { return lipgloss.Width(line[:byteX]), y } diff --git a/internal/ui/meters.go b/internal/ui/meters.go index edc83480..8b0760f0 100644 --- a/internal/ui/meters.go +++ b/internal/ui/meters.go @@ -2,11 +2,12 @@ package ui import ( "fmt" + imagecolor "image/color" "math" "strings" "time" - "github.com/charmbracelet/lipgloss" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" "github.com/merefield/codexometer/internal/codex" @@ -225,15 +226,15 @@ func meterDetailLines(details string) []string { return visible } -func renderResetGauge(width, gaugeWidth int, window codex.Window, now time.Time, resetLabel string, color lipgloss.Color, colors palette) string { +func renderResetGauge(width, gaugeWidth int, window codex.Window, now time.Time, resetLabel string, color imagecolor.Color, colors palette) string { return renderResetGaugeWithOptions(width, gaugeWidth, window, now, resetLabel, color, colors, false, lipgloss.Left) } -func renderReverseResetGauge(width, gaugeWidth int, window codex.Window, now time.Time, resetLabel string, color lipgloss.Color, colors palette) string { +func renderReverseResetGauge(width, gaugeWidth int, window codex.Window, now time.Time, resetLabel string, color imagecolor.Color, colors palette) string { return renderResetGaugeWithOptions(width, gaugeWidth, window, now, resetLabel, color, colors, true, lipgloss.Center) } -func renderResetGaugeWithOptions(width, gaugeWidth int, window codex.Window, now time.Time, resetLabel string, color lipgloss.Color, colors palette, reverse bool, alignment lipgloss.Position) string { +func renderResetGaugeWithOptions(width, gaugeWidth int, window codex.Window, now time.Time, resetLabel string, color imagecolor.Color, colors palette, reverse bool, alignment lipgloss.Position) string { gaugeWidth = min(max(gaugeWidth, 1), max(width, 1)) progress, ok := resetProgress(window, now) if !ok { @@ -280,7 +281,7 @@ func consumptionPace(window codex.Window, now time.Time) (int, bool) { return min(max(elapsed-used, -100), 100), true } -func meterColor(used int, colors palette) lipgloss.Color { +func meterColor(used int, colors palette) imagecolor.Color { if used >= 90 { return colors.danger } @@ -290,11 +291,11 @@ func meterColor(used int, colors palette) lipgloss.Color { return colors.primary } -func renderVisualization(width, used int, view meterViewID, color lipgloss.Color, colors palette) string { +func renderVisualization(width, used int, view meterViewID, color imagecolor.Color, colors palette) string { return renderVisualizationSized(width, 0, used, view, color, colors) } -func renderVisualizationSized(width, height, used int, view meterViewID, color lipgloss.Color, colors palette) string { +func renderVisualizationSized(width, height, used int, view meterViewID, color imagecolor.Color, colors palette) string { switch view { case viewPie: return renderPieSized(width, height, used, color, colors) @@ -309,11 +310,11 @@ func renderVisualizationSized(width, height, used int, view meterViewID, color l } } -func renderClassicBar(width, used int, color lipgloss.Color, colors palette) string { +func renderClassicBar(width, used int, color imagecolor.Color, colors palette) string { return renderClassicBarSized(width, 0, used, color, colors) } -func renderClassicBarSized(width, height, used int, color lipgloss.Color, colors palette) string { +func renderClassicBarSized(width, height, used int, color imagecolor.Color, colors palette) string { filled := int(math.Round(float64(width) * float64(used) / 100)) bar := lipgloss.NewStyle().Foreground(color).Render(strings.Repeat("█", filled)) + lipgloss.NewStyle().Foreground(colors.dim).Render(strings.Repeat("░", width-filled)) @@ -332,11 +333,11 @@ func renderClassicBarSized(width, height, used int, color lipgloss.Color, colors return strings.Join(rows, "\n") } -func renderPie(width, used int, color lipgloss.Color, colors palette) string { +func renderPie(width, used int, color imagecolor.Color, colors palette) string { return renderPieSized(width, 0, used, color, colors) } -func renderPieSized(width, height, used int, color lipgloss.Color, colors palette) string { +func renderPieSized(width, height, used int, color imagecolor.Color, colors palette) string { const legendWidth = 11 showLegend := width >= legendWidth+8 reservedLegendWidth := 0 @@ -585,7 +586,7 @@ func projectionDuration(duration time.Duration) string { } } -func paceAxis(width, center, marker, pace int, available bool, markerColor lipgloss.Color, colors palette) string { +func paceAxis(width, center, marker, pace int, available bool, markerColor imagecolor.Color, colors palette) string { if width < 3 { value := "?" color := colors.warning @@ -667,11 +668,11 @@ func verticallyCenterLines(lines []string, height int) []string { return centered } -func renderFuelTank(width, used int, color lipgloss.Color, colors palette) string { +func renderFuelTank(width, used int, color imagecolor.Color, colors palette) string { return renderFuelTankSized(width, 6, used, color, colors) } -func renderFuelTankSized(width, height, used int, color lipgloss.Color, colors palette) string { +func renderFuelTankSized(width, height, used int, color imagecolor.Color, colors palette) string { height = max(height, 1) remaining := 100 - used tankWidth := max(width-6, 1) diff --git a/internal/ui/meters_test.go b/internal/ui/meters_test.go index db2a5a83..4f3bdcb2 100644 --- a/internal/ui/meters_test.go +++ b/internal/ui/meters_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/charmbracelet/lipgloss" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" "github.com/merefield/codexometer/internal/codex" diff --git a/internal/ui/model.go b/internal/ui/model.go index 92c9798d..27dd8962 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -7,7 +7,7 @@ import ( "strings" "time" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/merefield/codexometer/internal/codex" ) @@ -37,6 +37,7 @@ type Model struct { err error width int height int + inline bool loading bool lastRefresh time.Time nextRefresh time.Time @@ -305,13 +306,19 @@ func New(fetcher Fetcher, refreshEvery time.Duration) Model { return model } +// SetInline controls whether the dashboard renders in the current terminal +// buffer instead of Bubble Tea's alternate screen. +func (m *Model) SetInline(inline bool) { + m.inline = inline +} + func (m Model) Init() tea.Cmd { return tea.Batch(m.fetch(), secondTick(), refreshTick(m.refreshEvery)) } func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { switch message := message.(type) { - case tea.KeyMsg: + case tea.KeyPressMsg: switch strings.ToLower(message.String()) { case "ctrl+c", "esc": m.cancelBenchmark() @@ -383,60 +390,62 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { } } case tea.MouseMsg: - if tab, ok := m.mainTabAt(message.X, message.Y); ok { + mouse := message.Mouse() + _, clicked := message.(tea.MouseClickMsg) + if tab, ok := m.mainTabAt(mouse.X, mouse.Y); ok { m.mainTabHovered = true m.hoveredMainTab = tab m.viewHovered = false m.hoveredButton = footerButtonNone - if message.Button == tea.MouseButtonLeft && message.Action == tea.MouseActionPress { + if mouse.Button == tea.MouseLeft && clicked { return m.pressMainTab(tab) } return m, nil } m.mainTabHovered = false - if view, ok := m.quotaViewTabAt(message.X, message.Y); ok { + if view, ok := m.quotaViewTabAt(mouse.X, mouse.Y); ok { m.viewHovered = true m.hoveredView = view m.hoveredButton = footerButtonNone - if message.Button == tea.MouseButtonLeft && message.Action == tea.MouseActionPress { + if mouse.Button == tea.MouseLeft && clicked { return m.pressViewTab(view) } return m, nil } m.viewHovered = false - if column, ok := m.benchmarkHeaderAt(message.X, message.Y); ok { + if column, ok := m.benchmarkHeaderAt(mouse.X, mouse.Y); ok { m.benchmarkSortHovered = true m.benchmarkHoveredSort = column m.hoveredButton = footerButtonNone - if message.Button == tea.MouseButtonLeft && message.Action == tea.MouseActionPress { + if mouse.Button == tea.MouseLeft && clicked { m.sortBenchmarkBy(column) } return m, nil } m.benchmarkSortHovered = false if m.meterView == viewMonitor { - switch message.Button { - case tea.MouseButtonWheelUp: + switch mouse.Button { + case tea.MouseWheelUp: m.scrollMonitorRows(-1) return m, nil - case tea.MouseButtonWheelDown: + case tea.MouseWheelDown: m.scrollMonitorRows(1) return m, nil } } if m.meterView == viewBenchmark { - switch message.Button { - case tea.MouseButtonWheelUp: + switch mouse.Button { + case tea.MouseWheelUp: m.scrollBenchmarkRows(3) return m, nil - case tea.MouseButtonWheelDown: + case tea.MouseWheelDown: m.scrollBenchmarkRows(-3) return m, nil } } - button := m.footerButtonAt(message.X, message.Y) + button := m.footerButtonAt(mouse.X, mouse.Y) m.hoveredButton = button - if message.Button == tea.MouseButtonLeft && message.Action == tea.MouseActionPress && button != footerButtonNone { + if mouse.Button == tea.MouseLeft && clicked && button != footerButtonNone { return m.pressFooterButton(button) } case tea.WindowSizeMsg: diff --git a/internal/ui/model_test.go b/internal/ui/model_test.go index 9879d25d..9cb47336 100644 --- a/internal/ui/model_test.go +++ b/internal/ui/model_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" "github.com/merefield/codexometer/internal/codex" @@ -68,21 +68,29 @@ func TestThemeHotkeyCyclesAndWraps(t *testing.T) { func TestTabCyclesMainTabsAndShiftTabMovesBack(t *testing.T) { model := New(nil, time.Minute) for _, want := range []meterViewID{viewMonitor, viewBenchmark, viewBars} { - updated, _ := model.Update(tea.KeyMsg{Type: tea.KeyTab}) + updated, _ := model.Update(specialKey(tea.KeyTab)) model = updated.(Model) if model.meterView != want { t.Fatalf("got meter view %d, want %d", model.meterView, want) } } - updated, _ := model.Update(tea.KeyMsg{Type: tea.KeyShiftTab}) + updated, _ := model.Update(modifiedKey(tea.KeyTab, tea.ModShift)) model = updated.(Model) if model.meterView != viewBenchmark { t.Fatalf("reverse main-tab navigation got %d, want %d", model.meterView, viewBenchmark) } } -func key(r rune) tea.KeyMsg { - return tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}} +func key(r rune) tea.KeyPressMsg { + return tea.KeyPressMsg{Code: r, Text: string(r)} +} + +func specialKey(code rune) tea.KeyPressMsg { + return tea.KeyPressMsg{Code: code} +} + +func modifiedKey(code rune, mod tea.KeyMod) tea.KeyPressMsg { + return tea.KeyPressMsg{Code: code, Mod: mod} } func TestModelLifecycleMessages(t *testing.T) { @@ -205,10 +213,10 @@ func TestModelManualRefreshAndQuitKeys(t *testing.T) { t.Fatal("refresh action started a second fetch while one was already active") } - for _, quitKey := range []tea.KeyMsg{ + for _, quitKey := range []tea.KeyPressMsg{ key('q'), - {Type: tea.KeyEsc}, - {Type: tea.KeyCtrlC}, + specialKey(tea.KeyEsc), + modifiedKey('c', tea.ModCtrl), } { _, command = model.Update(quitKey) if command == nil { @@ -227,47 +235,47 @@ func TestFooterButtonsSupportHoverAndMouseClicks(t *testing.T) { button, _ := footerButtonByID(model, footerButtonTheme) colors := paletteFor(model.theme) wantDefault := lipgloss.NewStyle().Foreground(colors.dim).Background(colors.background).Render(button.label) - if !strings.Contains(model.View(), wantDefault) { + if !strings.Contains(model.render(), wantDefault) { t.Fatal("idle theme button did not use the subdued theme colour") } - hover := footerMouseMessage(t, model, footerButtonTheme, tea.MouseActionMotion) + hover := footerMouseMessage(t, model, footerButtonTheme, false) updated, command := model.Update(hover) model = updated.(Model) if command != nil || model.hoveredButton != footerButtonTheme { t.Fatalf("theme hover was not recorded: button=%d command=%v", model.hoveredButton, command) } wantHover := lipgloss.NewStyle().Bold(true).Foreground(colors.primary).Background(colors.background).Render(button.label) - if !strings.Contains(model.View(), wantHover) { + if !strings.Contains(model.render(), wantHover) { t.Fatal("hovered theme button was not highlighted") } - updated, _ = model.Update(tea.MouseMsg{X: 0, Y: 0, Action: tea.MouseActionMotion}) + updated, _ = model.Update(tea.MouseMotionMsg{X: 0, Y: 0}) model = updated.(Model) if model.hoveredButton != footerButtonNone { t.Fatalf("moving outside buttons left button %d hovered", model.hoveredButton) } - updated, _ = model.Update(footerMouseMessage(t, model, footerButtonTheme, tea.MouseActionPress)) + updated, _ = model.Update(footerMouseMessage(t, model, footerButtonTheme, true)) model = updated.(Model) if model.theme != themeRust || model.flashedButton != footerButtonTheme { t.Fatalf("theme click selected theme=%d flash=%d, want theme=%d flash=%d", model.theme, model.flashedButton, themeRust, footerButtonTheme) } - updated, command = model.Update(footerMouseMessage(t, model, footerButtonView, tea.MouseActionPress)) + updated, command = model.Update(footerMouseMessage(t, model, footerButtonView, true)) model = updated.(Model) if command == nil || model.meterView != viewConsumptionPace || model.flashedButton != footerButtonView { t.Fatalf("view click selected view=%d flash=%d", model.meterView, model.flashedButton) } - updated, command = model.Update(footerMouseMessage(t, model, footerButtonRefresh, tea.MouseActionPress)) + updated, command = model.Update(footerMouseMessage(t, model, footerButtonRefresh, true)) model = updated.(Model) if !model.loading || command == nil { t.Fatal("refresh click did not start a fetch") } model.loading = false - _, command = model.Update(footerMouseMessage(t, model, footerButtonQuit, tea.MouseActionPress)) + _, command = model.Update(footerMouseMessage(t, model, footerButtonQuit, true)) if command == nil { t.Fatal("quit click returned no command") } @@ -320,7 +328,8 @@ func TestFooterHitGeometryMatchesRenderedButtonsAcrossSizes(t *testing.T) { buttons, _ := footerButtonLayoutWithTheme(layout.contentWidth, paletteFor(model.theme).name, model.meterView.isQuota()) for _, visible := range buttons { id := visible.id - mouse := footerMouseMessage(t, model, id, tea.MouseActionMotion) + message := footerMouseMessage(t, model, id, false) + mouse := message.Mouse() if mouse.Y != layout.footerY+1 { t.Errorf("rendered footer y=%d, calculated y=%d", mouse.Y, layout.footerY+1) } @@ -355,7 +364,7 @@ func TestFooterButtonHotkeyFlashesAndLatestPulseWins(t *testing.T) { button, _ := footerButtonByID(model, footerButtonTheme) colors := paletteFor(model.theme) wantFlash := lipgloss.NewStyle().Bold(true).Foreground(colors.background).Background(colors.primary).Render(button.label) - if !strings.Contains(model.View(), wantFlash) { + if !strings.Contains(model.render(), wantFlash) { t.Fatal("theme hotkey pulse was not rendered") } @@ -443,19 +452,23 @@ func TestFooterLayoutNeverHitTestsControlsTruncatedByTheme(t *testing.T) { } } -func footerMouseMessage(t *testing.T, model Model, id footerButtonID, action tea.MouseAction) tea.MouseMsg { +func footerMouseMessage(t *testing.T, model Model, id footerButtonID, clicked bool) tea.MouseMsg { t.Helper() button, ok := footerButtonByID(model, id) if !ok { t.Fatalf("button %d is not in the current footer layout", id) } - for y, line := range strings.Split(ansi.Strip(model.View()), "\n") { + for y, line := range strings.Split(ansi.Strip(model.render()), "\n") { if x := strings.Index(line, button.label); x >= 0 { - return tea.MouseMsg{X: x + len(button.label)/2, Y: y, Button: tea.MouseButtonLeft, Action: action} + mouse := tea.Mouse{X: x + len(button.label)/2, Y: y, Button: tea.MouseLeft} + if clicked { + return tea.MouseClickMsg(mouse) + } + return tea.MouseMotionMsg(mouse) } } t.Fatalf("button %q was not rendered", button.label) - return tea.MouseMsg{} + return tea.MouseMotionMsg{} } func footerButtonByID(model Model, id footerButtonID) (footerButton, bool) { diff --git a/internal/ui/monitor.go b/internal/ui/monitor.go index a493ffc2..ff012e79 100644 --- a/internal/ui/monitor.go +++ b/internal/ui/monitor.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/charmbracelet/lipgloss" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" "github.com/merefield/codexometer/internal/codex" diff --git a/internal/ui/monitor_test.go b/internal/ui/monitor_test.go index e429b257..bd7c46a3 100644 --- a/internal/ui/monitor_test.go +++ b/internal/ui/monitor_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" "github.com/merefield/codexometer/internal/codex" @@ -544,17 +544,17 @@ func TestMonitorSessionPagesRespondToKeyboardAndMouse(t *testing.T) { }, } wantLastPage := max(model.visibleMonitorSessionCount()-model.monitorPageSize(), 0) - updated, command := model.Update(tea.KeyMsg{Type: tea.KeyPgDown}) + updated, command := model.Update(specialKey(tea.KeyPgDown)) model = updated.(Model) if command != nil || model.monitorScroll != wantLastPage { t.Fatalf("Page Down monitor scroll = %d; want %d", model.monitorScroll, wantLastPage) } - updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyPgUp}) + updated, _ = model.Update(specialKey(tea.KeyPgUp)) model = updated.(Model) if model.monitorScroll != 0 { t.Fatalf("Page Up monitor scroll = %d; want 0", model.monitorScroll) } - updated, _ = model.Update(tea.MouseMsg{Button: tea.MouseButtonWheelDown}) + updated, _ = model.Update(tea.MouseWheelMsg{Button: tea.MouseWheelDown}) model = updated.(Model) if model.monitorScroll != 1 { t.Fatalf("mouse wheel monitor scroll = %d; want 1", model.monitorScroll) @@ -619,7 +619,7 @@ func TestMonitorViewIsResponsiveAndGraphAutoScales(t *testing.T) { monitorStartedAt: time.Now().Add(-time.Minute), monitorSamples: []monitorSample{{intervalTokens: 250}, {intervalTokens: 6_000}}, } - output := model.View() + output := model.render() plain := ansi.Strip(output) for _, want := range []string{"MONITOR READOUT", "6,250 TOKENS", "(S)TART", "STO(P)", "LOCAL TOKEN BARS", "AUTO 0-10K", "█", "░"} { if !strings.Contains(plain, want) { @@ -717,7 +717,7 @@ func TestMonitorLargeButtonsAreClickableAcrossTheirBoxes(t *testing.T) { t.Errorf("disabled Start button hit = %d, want none", got) } model.monitorState = monitorIdle - updated, command := model.Update(tea.MouseMsg{X: hoverX, Y: hoverY, Action: tea.MouseActionMotion}) + updated, command := model.Update(tea.MouseMotionMsg{X: hoverX, Y: hoverY}) model = updated.(Model) if command != nil || model.hoveredButton != footerButtonMonitorGo { t.Fatal("hovering the Go box did not select it") @@ -728,9 +728,9 @@ func TestMonitorLargeButtonsAreClickableAcrossTheirBoxes(t *testing.T) { t.Fatal("hovering the Go box did not highlight its label") } - updated, command = model.Update(tea.MouseMsg{ + updated, command = model.Update(tea.MouseClickMsg{ X: originX + geometry.goRect.x + 1, Y: originY + geometry.goRect.y + 1, - Button: tea.MouseButtonLeft, Action: tea.MouseActionPress, + Button: tea.MouseLeft, }) model = updated.(Model) if command == nil || model.monitorState != monitorStarting { diff --git a/internal/ui/quota_api_eq_test.go b/internal/ui/quota_api_eq_test.go index 6e57fd5b..c3b426e4 100644 --- a/internal/ui/quota_api_eq_test.go +++ b/internal/ui/quota_api_eq_test.go @@ -318,13 +318,13 @@ func TestEveryQuotaViewDisplaysResponsiveAPIEqReadout(t *testing.T) { }} for _, view := range quotaViewOrder { model.meterView, model.quotaMeterView = view, view - rendered := ansi.Strip(model.View()) + rendered := ansi.Strip(model.render()) if !strings.Contains(rendered, "API-EQ") || !strings.Contains(rendered, "100%") { t.Errorf("%s omitted API-EQ readout:\n%s", view.name(), rendered) } } model.width = 48 - if view := ansi.Strip(model.View()); !strings.Contains(view, "EQ NOW") || !strings.Contains(view, "FULL") { + if view := ansi.Strip(model.render()); !strings.Contains(view, "EQ NOW") || !strings.Contains(view, "FULL") { t.Fatalf("narrow API-EQ readout was not responsive:\n%s", view) } } diff --git a/internal/ui/quota_status.go b/internal/ui/quota_status.go index 6f676ecb..6f284f6f 100644 --- a/internal/ui/quota_status.go +++ b/internal/ui/quota_status.go @@ -1,12 +1,13 @@ package ui import ( + imagecolor "image/color" "sort" "strconv" "strings" "time" - "github.com/charmbracelet/lipgloss" + "charm.land/lipgloss/v2" "github.com/merefield/codexometer/internal/codex" ) @@ -44,7 +45,7 @@ func (h quotaHealth) compactLabel() string { }[h] } -func (h quotaHealth) color(colors palette) lipgloss.Color { +func (h quotaHealth) color(colors palette) imagecolor.Color { switch h { case quotaHealthFresh, quotaHealthClear: return lipgloss.Color("#57FF8A") diff --git a/internal/ui/quota_status_test.go b/internal/ui/quota_status_test.go index 557e9055..38eb279e 100644 --- a/internal/ui/quota_status_test.go +++ b/internal/ui/quota_status_test.go @@ -1,11 +1,12 @@ package ui import ( + imagecolor "image/color" "strings" "testing" "time" - "github.com/charmbracelet/lipgloss" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" "github.com/merefield/codexometer/internal/codex" @@ -104,7 +105,7 @@ func TestQuotaHealthUsesSemanticSignalColors(t *testing.T) { colors := paletteFor(themeNightshade) for _, test := range []struct { health quotaHealth - want lipgloss.Color + want imagecolor.Color }{ {quotaHealthClear, lipgloss.Color("#57FF8A")}, {quotaHealthFresh, lipgloss.Color("#57FF8A")}, diff --git a/internal/ui/tabs.go b/internal/ui/tabs.go index 5ae54f63..7c495850 100644 --- a/internal/ui/tabs.go +++ b/internal/ui/tabs.go @@ -1,10 +1,11 @@ package ui import ( + imagecolor "image/color" "strings" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" ) type mainTabID int @@ -197,7 +198,7 @@ func (m Model) renderQuotaViewTabs(width int, colors palette) string { return strings.Join(parts, colors.dimmed().Render(separator)) + strings.Repeat(" ", max(width-used, 0)) } -func tabAppearance(active, hovered, flashed bool, colors palette) (lipgloss.Style, lipgloss.Color) { +func tabAppearance(active, hovered, flashed bool, colors palette) (lipgloss.Style, imagecolor.Color) { foreground, background := colors.dim, colors.background bold := false if active { @@ -215,7 +216,7 @@ func tabAppearance(active, hovered, flashed bool, colors palette) (lipgloss.Styl return lipgloss.NewStyle().Foreground(foreground).Background(background).Bold(bold), background } -func renderViewTabLabel(label string, base lipgloss.Style, background lipgloss.Color, recording bool, phase int, colors palette) string { +func renderViewTabLabel(label string, base lipgloss.Style, background imagecolor.Color, recording bool, phase int, colors palette) string { if !recording || !strings.Contains(label, "●") { return base.Render(label) } @@ -225,7 +226,7 @@ func renderViewTabLabel(label string, base lipgloss.Style, background lipgloss.C return base.Render(pieces[0]) + dot + base.Render(pieces[1]) } -func recordingDotColor(phase int, colors palette) lipgloss.Color { +func recordingDotColor(phase int, colors palette) imagecolor.Color { if phase%2 == 0 { return colors.danger } diff --git a/internal/ui/tabs_test.go b/internal/ui/tabs_test.go index c7f4fed7..2aa3fff0 100644 --- a/internal/ui/tabs_test.go +++ b/internal/ui/tabs_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" "github.com/merefield/codexometer/internal/codex" @@ -80,11 +80,10 @@ func TestMainTabsSupportHoverClickAndPulse(t *testing.T) { model.width, model.height = 100, 30 tabs, _ := mainTabLayout(model.contentWidth(), false) target := tabs[mainTabMonitor] - mouse := tea.MouseMsg{ + mouse := tea.MouseMotionMsg{ X: 2 + target.x + target.width/2, Y: model.dashboardLayout().tabsY, - Button: tea.MouseButtonLeft, - Action: tea.MouseActionMotion, + Button: tea.MouseLeft, } updated, command := model.Update(mouse) model = updated.(Model) @@ -92,8 +91,7 @@ func TestMainTabsSupportHoverClickAndPulse(t *testing.T) { t.Fatalf("monitor hover was not recorded: hovered=%v tab=%d", model.mainTabHovered, model.hoveredMainTab) } - mouse.Action = tea.MouseActionPress - updated, command = model.Update(mouse) + updated, command = model.Update(tea.MouseClickMsg(mouse)) model = updated.(Model) if command == nil || model.meterView != viewMonitor || !model.viewFlashing || model.flashedView != viewMonitor { t.Fatalf("monitor click did not select and pulse: view=%d flashing=%v", model.meterView, model.viewFlashing) @@ -107,11 +105,10 @@ func TestQuotaViewTabsSupportHoverClickAndPulse(t *testing.T) { model.width, model.height = 100, 30 tabs, _ := quotaViewTabLayout(model.contentWidth()) target := tabs[1] - mouse := tea.MouseMsg{ + mouse := tea.MouseMotionMsg{ X: 2 + target.x + target.width/2, Y: model.dashboardLayout().quotaTabsY, - Button: tea.MouseButtonLeft, - Action: tea.MouseActionMotion, + Button: tea.MouseLeft, } updated, command := model.Update(mouse) model = updated.(Model) @@ -119,8 +116,7 @@ func TestQuotaViewTabsSupportHoverClickAndPulse(t *testing.T) { t.Fatalf("consumption pace hover was not recorded: hovered=%v view=%d", model.viewHovered, model.hoveredView) } - mouse.Action = tea.MouseActionPress - updated, command = model.Update(mouse) + updated, command = model.Update(tea.MouseClickMsg(mouse)) model = updated.(Model) if command == nil || model.meterView != viewConsumptionPace || model.quotaMeterView != viewConsumptionPace || !model.viewFlashing || model.flashedView != viewConsumptionPace { t.Fatalf("consumption pace click did not select, remember, and pulse: view=%d remembered=%d flashing=%v", model.meterView, model.quotaMeterView, model.viewFlashing) @@ -157,22 +153,22 @@ func TestEveryRenderedTabCellIsClickableAcrossWidths(t *testing.T) { func TestQuotaStyleIsRememberedAcrossMainTabNavigation(t *testing.T) { model := Model{meterView: viewPie} - updated, _ := model.Update(tea.KeyMsg{Type: tea.KeyTab}) + updated, _ := model.Update(specialKey(tea.KeyTab)) model = updated.(Model) if model.meterView != viewMonitor { t.Fatalf("Tab selected %s, want Monitor", model.meterView.name()) } - updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyTab}) + updated, _ = model.Update(specialKey(tea.KeyTab)) model = updated.(Model) if model.meterView != viewBenchmark { t.Fatalf("second Tab selected %s, want Benchmark", model.meterView.name()) } - updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyTab}) + updated, _ = model.Update(specialKey(tea.KeyTab)) model = updated.(Model) if model.meterView != viewPie { t.Fatalf("return to Quota selected %s, want remembered Pie", model.meterView.name()) } - updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyShiftTab}) + updated, _ = model.Update(modifiedKey(tea.KeyTab, tea.ModShift)) model = updated.(Model) if model.meterView != viewBenchmark { t.Fatalf("Shift+Tab selected %s, want Benchmark", model.meterView.name()) @@ -214,7 +210,7 @@ func TestQuotaSubTabsOnlyRenderAndHitTestWithinQuota(t *testing.T) { colors := paletteFor(themeHacker) for _, view := range []meterViewID{viewBars, viewMonitor, viewBenchmark} { model := Model{snapshot: codex.DemoSnapshot(), width: 100, height: 30, meterView: view} - output := ansi.Strip(model.View()) + output := ansi.Strip(model.render()) layout := model.dashboardLayout() if view.isQuota() { if layout.quotaTabsY < 0 || !strings.Contains(output, "CONSUMPTION PACE") { diff --git a/internal/ui/theme.go b/internal/ui/theme.go index 30f6b6e0..9f12ea80 100644 --- a/internal/ui/theme.go +++ b/internal/ui/theme.go @@ -1,6 +1,10 @@ package ui -import "github.com/charmbracelet/lipgloss" +import ( + imagecolor "image/color" + + "charm.land/lipgloss/v2" +) type themeID int @@ -67,12 +71,12 @@ func (s meterViewID) name() string { type palette struct { name string - primary lipgloss.Color - dim lipgloss.Color - accent lipgloss.Color - warning lipgloss.Color - danger lipgloss.Color - background lipgloss.Color + primary imagecolor.Color + dim imagecolor.Color + accent imagecolor.Color + warning imagecolor.Color + danger imagecolor.Color + background imagecolor.Color } func paletteFor(theme themeID) palette { diff --git a/internal/ui/view.go b/internal/ui/view.go index 1c0f69b4..fdc0024f 100644 --- a/internal/ui/view.go +++ b/internal/ui/view.go @@ -2,17 +2,26 @@ package ui import ( "fmt" + imagecolor "image/color" "math" "strings" "time" - "github.com/charmbracelet/lipgloss" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" "github.com/merefield/codexometer/internal/codex" ) -func (m Model) View() string { +func (m Model) View() tea.View { + view := tea.NewView(m.render()) + view.AltScreen = !m.inline + view.MouseMode = tea.MouseModeAllMotion + return view +} + +func (m Model) render() string { colors := paletteFor(m.theme) layout := m.dashboardLayout() contentWidth := layout.contentWidth @@ -115,7 +124,7 @@ func (m Model) renderSignalStatus(width int, colors palette) string { return semantic.Render("●") + online.Render(" ONLINE // ") + semantic.Render(label) } -func renderColoredSignal(label string, color lipgloss.Color) string { +func renderColoredSignal(label string, color imagecolor.Color) string { return lipgloss.NewStyle().Bold(true).Foreground(color).Render("● " + label) } @@ -209,14 +218,14 @@ func renderError(width int, err error, colors palette) string { return frame(width, "SIGNAL FAULT", lipgloss.NewStyle().Foreground(colors.danger).Render(message), colors.danger, colors) } -func frame(width int, title, body string, color lipgloss.Color, colors palette) string { +func frame(width int, title, body string, color imagecolor.Color, colors palette) string { return frameSized(width, 0, title, body, color, colors) } -func frameSized(width, height int, title, body string, color lipgloss.Color, colors palette) string { +func frameSized(width, height int, title, body string, color imagecolor.Color, colors palette) string { width = max(width, 1) style := lipgloss.NewStyle(). - Width(max(width-2, 1)). + Width(width). Padding(0, 1). Border(lipgloss.RoundedBorder()). BorderTop(false). @@ -224,12 +233,15 @@ func frameSized(width, height int, title, body string, color lipgloss.Color, col Foreground(colors.primary). Background(colors.background) if height > 0 { - style = style.Height(height) + // Lip Gloss v2 includes the bottom border in Height. The title is + // rendered separately, so preserve the existing body allocation by + // reserving one extra row for that border. + style = style.Height(height + 1) } return renderFrameTitle(width, title, color, colors) + "\n" + style.Render(body) } -func renderFrameTitle(width int, title string, color lipgloss.Color, colors palette) string { +func renderFrameTitle(width int, title string, color imagecolor.Color, colors palette) string { width = max(width, 1) border := lipgloss.RoundedBorder() borderStyle := lipgloss.NewStyle().Foreground(color).Background(colors.background) diff --git a/internal/ui/view_test.go b/internal/ui/view_test.go index 2d913b5f..cd84904e 100644 --- a/internal/ui/view_test.go +++ b/internal/ui/view_test.go @@ -6,7 +6,8 @@ import ( "testing" "time" - "github.com/charmbracelet/lipgloss" + tea "charm.land/bubbletea/v2" + "charm.land/lipgloss/v2" "github.com/charmbracelet/x/ansi" "github.com/merefield/codexometer/internal/codex" @@ -23,7 +24,7 @@ func TestViewRendersEveryThemeAndViewWithinStandardTerminal(t *testing.T) { theme: theme, meterView: view, } - output := ansi.Strip(model.View()) + output := ansi.Strip(model.render()) if !strings.Contains(output, paletteFor(theme).name) { t.Errorf("theme %d name missing from view", theme) } @@ -48,6 +49,20 @@ func TestViewRendersEveryThemeAndViewWithinStandardTerminal(t *testing.T) { } } +func TestViewDeclaresTerminalModes(t *testing.T) { + model := Model{snapshot: codex.DemoSnapshot(), width: 80, height: 24} + view := model.View() + if !view.AltScreen || view.MouseMode != tea.MouseModeAllMotion { + t.Fatalf("default view modes = alt:%v mouse:%v", view.AltScreen, view.MouseMode) + } + + model.SetInline(true) + view = model.View() + if view.AltScreen || view.MouseMode != tea.MouseModeAllMotion { + t.Fatalf("inline view modes = alt:%v mouse:%v", view.AltScreen, view.MouseMode) + } +} + func TestViewReflowsAcrossTerminalDimensions(t *testing.T) { sizes := []struct{ width, height int }{{40, 16}, {40, 24}, {45, 24}, {60, 24}, {80, 24}, {120, 40}, {200, 60}} for _, size := range sizes { @@ -59,7 +74,7 @@ func TestViewReflowsAcrossTerminalDimensions(t *testing.T) { nextRefresh: time.Now().Add(time.Minute), meterView: view, } - output := model.View() + output := model.render() if got := lipgloss.Width(output); got > size.width { t.Errorf("%s at %dx%d rendered width %d", view.name(), size.width, size.height, got) } @@ -98,7 +113,7 @@ func TestQuotaViewsAccommodateFiveHourAdditionalAndMonthlyLimits(t *testing.T) { snapshot: snapshot, width: size.width, height: size.height, nextRefresh: now.Add(time.Minute), meterView: view, } - output := ansi.Strip(model.View()) + output := ansi.Strip(model.render()) if got := lipgloss.Width(output); got > size.width { t.Errorf("%s with five limits at %dx%d rendered width %d", view.name(), size.width, size.height, got) } @@ -249,7 +264,7 @@ func TestPieViewPlacesQuotaWindowsSideBySide(t *testing.T) { nextRefresh: time.Now().Add(time.Minute), meterView: viewPie, } - output := ansi.Strip(model.View()) + output := ansi.Strip(model.render()) foundSharedRow := false for _, line := range strings.Split(output, "\n") { if strings.Contains(line, "5 HOURS LOOP") && strings.Contains(line, "1 WEEK LOOP") { @@ -383,7 +398,7 @@ func TestRadialViewsPlaceQuotaWindowsSideBySide(t *testing.T) { nextRefresh: time.Now().Add(time.Minute), meterView: view, } - output := ansi.Strip(model.View()) + output := ansi.Strip(model.render()) foundSharedRow := false for _, line := range strings.Split(output, "\n") { if strings.Contains(line, "5 HOURS LOOP") && strings.Contains(line, "1 WEEK LOOP") { @@ -398,7 +413,7 @@ func TestRadialViewsPlaceQuotaWindowsSideBySide(t *testing.T) { } func TestViewCoversBootCompactErrorAndEmptyStates(t *testing.T) { - boot := ansi.Strip((Model{width: 50, loading: true, theme: themeRust}).View()) + boot := ansi.Strip((Model{width: 50, loading: true, theme: themeRust}).render()) if !strings.Contains(boot, "▰ CODEXOMETER ▰") || !strings.Contains(boot, "ACQUIRING SIGNAL") { t.Fatalf("compact boot view missing content: %q", boot) } @@ -410,12 +425,12 @@ func TestViewCoversBootCompactErrorAndEmptyStates(t *testing.T) { nextRefresh: time.Now().Add(time.Minute), theme: themeBlueSteel, } - staleOutput := ansi.Strip(stale.View()) + staleOutput := ansi.Strip(stale.render()) if !strings.Contains(staleOutput, "STALE SIGNAL") || !strings.Contains(staleOutput, "connection lost") { t.Fatalf("stale view missing error: %q", staleOutput) } - empty := ansi.Strip((Model{width: 80}).View()) + empty := ansi.Strip((Model{width: 80}).render()) if !strings.Contains(empty, "no quota windows returned") { t.Fatalf("empty view missing diagnostic: %q", empty) } @@ -453,7 +468,7 @@ func TestPalettesAndFallback(t *testing.T) { wants := []string{"HACKER", "RUST", "BLUE STEEL", "ULTRAVIOLET", "NIGHTSHADE"} for theme, want := range wants { colors := paletteFor(themeID(theme)) - if colors.name != want || colors.primary == "" || colors.dim == "" || colors.accent == "" || colors.background == "" { + if colors.name != want || colors.primary == nil || colors.dim == nil || colors.accent == nil || colors.background == nil { t.Fatalf("invalid palette %d: %#v", theme, colors) } if colors.header().GetForeground() != colors.primary || colors.label().GetForeground() != colors.accent { diff --git a/internal/version/version.go b/internal/version/version.go index 2e1d3b9c..be110500 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -11,7 +11,7 @@ import ( // checkout. Release automation may override it with: // // -X github.com/merefield/codexometer/internal/version.Fallback=1.2.3 -var Fallback = "0.7.5" +var Fallback = "0.7.6" // Current returns the module version embedded by Go for tagged installs, or // Fallback for ordinary source builds. The leading tag prefix is omitted so diff --git a/internal/version/version_test.go b/internal/version/version_test.go index abeefdfc..9b7af467 100644 --- a/internal/version/version_test.go +++ b/internal/version/version_test.go @@ -4,8 +4,8 @@ import "testing" func TestCurrentReportsMaintainedFallbackForSourceBuild(t *testing.T) { got := Current() - if got != "0.7.5" { - t.Fatalf("Current() = %q, want 0.7.5", got) + if got != "0.7.6" { + t.Fatalf("Current() = %q, want 0.7.6", got) } } diff --git a/main.go b/main.go index 4833dc21..f0717af4 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,7 @@ import ( "sync" "time" - tea "github.com/charmbracelet/bubbletea" + tea "charm.land/bubbletea/v2" "github.com/merefield/codexometer/internal/codex" "github.com/merefield/codexometer/internal/ui" @@ -212,14 +212,11 @@ func run(args []string, stdout, stderr io.Writer, deps dependencies) int { } func startUI(fetcher ui.Fetcher, refresh time.Duration, inline bool) error { - options := []tea.ProgramOption{tea.WithMouseAllMotion()} - if !inline { - options = append(options, tea.WithAltScreen()) - } model := ui.New(fetcher, refresh) if store, storeErr := ui.NewDefaultPreferenceStore(); storeErr == nil { model = ui.NewWithPreferences(fetcher, refresh, store) } - _, err := tea.NewProgram(model, options...).Run() + model.SetInline(inline) + _, err := tea.NewProgram(model).Run() return err } diff --git a/main_test.go b/main_test.go index ba7c0776..fd7691f6 100644 --- a/main_test.go +++ b/main_test.go @@ -16,7 +16,7 @@ func TestRunVersion(t *testing.T) { for _, flag := range []string{"-v", "--version"} { var stdout, stderr bytes.Buffer code := run([]string{flag}, &stdout, &stderr, dependencies{}) - if code != 0 || stdout.String() != "codexometer v0.7.5\n" || stderr.Len() != 0 { + if code != 0 || stdout.String() != "codexometer v0.7.6\n" || stderr.Len() != 0 { t.Errorf("flag=%s code=%d stdout=%q stderr=%q", flag, code, stdout.String(), stderr.String()) } } From a52e1d0522f6466a0f805b3174394220c4187339 Mon Sep 17 00:00:00 2001 From: merefield Date: Mon, 17 Aug 2026 14:47:14 +0100 Subject: [PATCH 2/4] FIX: align monitor controls with readout --- internal/ui/monitor.go | 4 ++-- internal/ui/monitor_test.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/internal/ui/monitor.go b/internal/ui/monitor.go index ff012e79..187e520d 100644 --- a/internal/ui/monitor.go +++ b/internal/ui/monitor.go @@ -173,8 +173,8 @@ func (m Model) renderMonitorButton(width, height int, label string, id footerBut foreground = colors.primary } style := lipgloss.NewStyle(). - Width(max(width-2, 1)). - Height(max(height-2, 1)). + Width(width). + Height(height). Align(lipgloss.Center). AlignVertical(lipgloss.Center). Border(lipgloss.RoundedBorder()). diff --git a/internal/ui/monitor_test.go b/internal/ui/monitor_test.go index bd7c46a3..9570198c 100644 --- a/internal/ui/monitor_test.go +++ b/internal/ui/monitor_test.go @@ -738,6 +738,25 @@ func TestMonitorLargeButtonsAreClickableAcrossTheirBoxes(t *testing.T) { } } +func TestMonitorHeaderComponentsHonorAllocatedDimensions(t *testing.T) { + model := Model{snapshot: codex.DemoSnapshot(), meterView: viewMonitor, monitorState: monitorIdle} + colors := paletteFor(themeHacker) + for _, size := range []struct{ width, height int }{{36, 10}, {56, 12}, {96, 18}, {156, 30}} { + geometry := layoutMonitorArea(size.width, size.height) + readout := model.renderMonitorReadout(geometry.readoutWidth, geometry.topHeight, colors) + if gotWidth, gotHeight := lipgloss.Width(readout), lipgloss.Height(readout); gotWidth != geometry.readoutWidth || gotHeight != geometry.topHeight { + t.Errorf("%dx%d readout rendered %dx%d, want %dx%d", size.width, size.height, gotWidth, gotHeight, geometry.readoutWidth, geometry.topHeight) + } + + for index, width := range geometry.buttonWidths { + button := model.renderMonitorButton(width, geometry.topHeight, "BUTTON", footerButtonMonitorGo, true, colors) + if gotWidth, gotHeight := lipgloss.Width(button), lipgloss.Height(button); gotWidth != width || gotHeight != geometry.topHeight { + t.Errorf("%dx%d button %d rendered %dx%d, want %dx%d", size.width, size.height, index, gotWidth, gotHeight, width, geometry.topHeight) + } + } + } +} + func TestMonitorButtonBoxesMatchEnabledHitSurfacesAcrossSizes(t *testing.T) { for _, size := range []struct{ width, height int }{{40, 16}, {40, 24}, {60, 24}, {100, 36}, {160, 45}} { for _, state := range []monitorState{monitorIdle, monitorRunning} { From 3996be197b8bf875b27491ecdba3ba1d68f1acc1 Mon Sep 17 00:00:00 2001 From: merefield Date: Mon, 17 Aug 2026 16:05:06 +0100 Subject: [PATCH 3/4] FEAT: dismiss monitor session rows --- README.md | 6 ++ internal/ui/model.go | 104 ++++++++++++++++++++++++++- internal/ui/monitor.go | 112 +++++++++++++++++++++++------ internal/ui/monitor_test.go | 140 ++++++++++++++++++++++++++++++++++++ internal/ui/view.go | 34 +++++++-- 5 files changed, 368 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 430d1df9..5f902c44 100644 --- a/README.md +++ b/README.md @@ -583,6 +583,12 @@ The other top-level views are: releases its per-thread writer lock and clears every attention badge. A session already included in the current Monitor recording can remain as an `IDLE` historical row so its completed metrics and graph are not discarded. + Click the themed `[×]` in a session metrics box to hide that row for the + current run without closing or altering the Codex session. Codexometer keeps + collecting its telemetry while hidden and restores the row automatically + when tokens, model calls, turn timing, durable activity, or attention moves + forward, or when an inactive session becomes active again. Starting a new + Monitor recording also restores every dismissed row. When the terminal cannot fit every root, use Page Up, Page Down, or the mouse wheel to page through the rows. Stop performs an immediate final local read instead of relying on the latest graph sample. diff --git a/internal/ui/model.go b/internal/ui/model.go index 27dd8962..9952e48c 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -95,6 +95,10 @@ type Model struct { monitorLastActivity time.Time monitorSessions int monitorSessionData []monitorSession + monitorDismissed map[string]monitorSessionDismissal + monitorDismissHover string + monitorDismissFlash string + monitorDismissSeq uint64 monitorScroll int monitorError string monitorQuotaWindows []monitorQuotaWindow @@ -143,6 +147,14 @@ type monitorSample struct { intervalTokens int64 } +type monitorSessionDismissal struct { + latest int64 + lastActivity time.Time + callSequence uint64 + turnSequence uint64 + inactiveObserved bool +} + type monitorSession struct { id string workingDirectory string @@ -202,6 +214,11 @@ type viewTabFlashExpiredMsg struct { sequence uint64 } +type monitorSessionDismissMsg struct { + id string + sequence uint64 +} + type benchmarkState int const ( @@ -423,6 +440,15 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { return m, nil } m.benchmarkSortHovered = false + if id, ok := m.monitorSessionDismissAt(mouse.X, mouse.Y); ok { + m.monitorDismissHover = id + m.hoveredButton = footerButtonNone + if mouse.Button == tea.MouseLeft && clicked { + return m.pressMonitorSessionDismiss(id) + } + return m, nil + } + m.monitorDismissHover = "" if m.meterView == viewMonitor { switch mouse.Button { case tea.MouseWheelUp: @@ -531,6 +557,12 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { if message.sequence == m.viewSequence && message.view == m.flashedView { m.viewFlashing = false } + case monitorSessionDismissMsg: + if message.sequence == m.monitorDismissSeq && message.id == m.monitorDismissFlash { + m.dismissMonitorSession(message.id) + m.monitorDismissFlash = "" + m.monitorDismissHover = "" + } case benchmarkEventMsg: if !message.ok { m.benchmarkState = benchmarkFinished @@ -621,6 +653,18 @@ func (m Model) pressFooterButton(button footerButtonID) (tea.Model, tea.Cmd) { return updated, tea.Batch(action, expire) } +func (m Model) pressMonitorSessionDismiss(id string) (tea.Model, tea.Cmd) { + if m.monitorSessionIndex(id) < 0 { + return m, nil + } + m.monitorDismissSeq++ + m.monitorDismissFlash = id + sequence := m.monitorDismissSeq + return m, tea.Tick(footerButtonFlashDuration, func(time.Time) tea.Msg { + return monitorSessionDismissMsg{id: id, sequence: sequence} + }) +} + func (m Model) activateFooterButton(button footerButtonID) (Model, tea.Cmd) { switch button { case footerButtonTheme: @@ -644,6 +688,10 @@ func (m Model) activateFooterButton(button footerButtonID) (Model, tea.Cmd) { m.monitorStoppedAt = time.Time{} m.monitorSamples = nil m.monitorSessionData = nil + m.monitorDismissed = nil + m.monitorDismissHover = "" + m.monitorDismissFlash = "" + m.monitorDismissSeq++ m.monitorScroll = 0 m.monitorBoundaryDue = false m.monitorLastActivity = time.Time{} @@ -1249,6 +1297,7 @@ func sameOptionalInt64(left, right *int64) bool { func (m *Model) startMonitorSessions(usage codex.LiveUsageSnapshot, observedAt time.Time) { m.monitorSessionData = nil + m.monitorDismissed = nil for _, session := range usage.Sessions { m.monitorSessionData = append(m.monitorSessionData, monitorSession{ id: session.ID, workingDirectory: session.WorkingDirectory, @@ -1310,6 +1359,7 @@ func (m *Model) syncMonitorSessions(usage codex.LiveUsageSnapshot, observedAt ti session.workingDirectory = update.WorkingDirectory } applyMonitorSessionTelemetry(session, update, time.Time{}) + m.restoreMonitorSessionOnActivity(session) } if len(usage.Sessions) == 0 && len(m.monitorSessionData) == 1 && m.monitorSessionData[0].id == "local" { session := &m.monitorSessionData[0] @@ -1317,7 +1367,59 @@ func (m *Model) syncMonitorSessions(usage codex.LiveUsageSnapshot, observedAt ti session.lastActivity = usage.LastActivity session.active = usage.SessionCount > 0 session.displayed = true + m.restoreMonitorSessionOnActivity(session) + } + for index := range m.monitorSessionData { + session := &m.monitorSessionData[index] + dismissal, dismissed := m.monitorDismissed[session.id] + if dismissed && !session.active { + dismissal.inactiveObserved = true + m.monitorDismissed[session.id] = dismissal + } + } +} + +func (m *Model) dismissMonitorSession(id string) { + index := m.monitorSessionIndex(id) + if index < 0 { + return + } + if m.monitorDismissed == nil { + m.monitorDismissed = make(map[string]monitorSessionDismissal) + } + session := m.monitorSessionData[index] + m.monitorDismissed[id] = monitorSessionDismissal{ + latest: session.latest, + lastActivity: session.lastActivity, + callSequence: session.callSequence, + turnSequence: session.turnSequence, + } + m.monitorSessions = m.visibleMonitorSessionCount() + maximumScroll := max(m.monitorSessions-m.monitorPageSize(), 0) + m.monitorScroll = min(m.monitorScroll, maximumScroll) +} + +func (m *Model) restoreMonitorSessionOnActivity(session *monitorSession) { + dismissal, dismissed := m.monitorDismissed[session.id] + if !dismissed { + return + } + if session.attention != codex.SessionAttentionNone || + session.latest > dismissal.latest || + session.lastActivity.After(dismissal.lastActivity) || + session.callSequence > dismissal.callSequence || + session.turnSequence > dismissal.turnSequence || + (dismissal.inactiveObserved && session.active) { + delete(m.monitorDismissed, session.id) + } +} + +func (m Model) monitorSessionVisible(session monitorSession) bool { + if !session.displayed { + return false } + _, dismissed := m.monitorDismissed[session.id] + return !dismissed || session.attention != codex.SessionAttentionNone } func applyMonitorSessionTelemetry(session *monitorSession, update codex.LiveUsageSession, since time.Time) { @@ -1414,7 +1516,7 @@ func (m *Model) monitorSessionIndex(id string) int { func (m Model) visibleMonitorSessionCount() int { count := 0 for _, session := range m.monitorSessionData { - if session.displayed { + if m.monitorSessionVisible(session) { count++ } } diff --git a/internal/ui/monitor.go b/internal/ui/monitor.go index 187e520d..cac96dfb 100644 --- a/internal/ui/monitor.go +++ b/internal/ui/monitor.go @@ -43,6 +43,8 @@ type monitorGeometry struct { stopRect monitorRect } +const monitorDismissLabel = "[×]" + func layoutMonitorArea(width, height int) monitorGeometry { width = max(width, 1) height = max(height, 1) @@ -195,14 +197,34 @@ func (m Model) renderMonitorGraph(width, height int, colors palette) string { } func (m Model) renderMonitorSessions(width, height int, colors palette) string { + visible, rowHeights, pageLabel := m.monitorSessionPage(height) + if len(visible) == 0 { + return m.renderMonitorGraph(width, height, colors) + } + rows := make([]string, 0, len(visible)) + for index, session := range visible { + rowPageLabel := "" + if index == len(visible)-1 { + rowPageLabel = pageLabel + } + rows = append(rows, m.renderMonitorSessionRow(width, rowHeights[index], session, rowPageLabel, colors)) + } + view := strings.Join(rows, "\n") + if padding := height - lipgloss.Height(view); padding > 0 { + view += strings.Repeat("\n", padding) + } + return view +} + +func (m Model) monitorSessionPage(height int) ([]monitorSession, []int, string) { visible := make([]monitorSession, 0, len(m.monitorSessionData)) for _, session := range m.monitorSessionData { - if session.displayed { + if m.monitorSessionVisible(session) { visible = append(visible, session) } } if len(visible) == 0 { - return m.renderMonitorGraph(width, height, colors) + return nil, nil, "" } // Every row needs a title, body, and bottom border. When the terminal is too @@ -216,33 +238,28 @@ func (m Model) renderMonitorSessions(width, height int, colors palette) string { pageLabel = fmt.Sprintf("ROWS %d-%d/%d", start+1, start+rowCount, visibleCount) } rowHeights := distributeSpace(max(height-(rowCount-1), rowCount), rowCount) - rows := make([]string, 0, rowCount) - for index, session := range visible { - rowPageLabel := "" - if index == rowCount-1 { - rowPageLabel = pageLabel - } - rows = append(rows, m.renderMonitorSessionRow(width, rowHeights[index], session, rowPageLabel, colors)) - } - view := strings.Join(rows, "\n") - if padding := height - lipgloss.Height(view); padding > 0 { - view += strings.Repeat("\n", padding) - } - return view + return visible, rowHeights, pageLabel } func (m Model) renderMonitorSessionRow(width, height int, session monitorSession, pageLabel string, colors palette) string { - const gap = 1 - if width <= gap+1 { + metricsWidth, graphWidth, ok := monitorSessionColumnWidths(width) + if !ok { return m.renderMonitorGraphSamples(width, height, session.samples, "TOKENS", colors) } - available := max(width-gap, 2) - metricsWidth := max(available/3, 1) - graphWidth := max(available-metricsWidth, 1) metrics := m.renderMonitorSessionMetrics(metricsWidth, height, session, pageLabel, colors) title := "TOKEN BARS" graph := m.renderMonitorGraphSamples(graphWidth, height, session.samples, title, colors) - return lipgloss.JoinHorizontal(lipgloss.Top, metrics, strings.Repeat(" ", gap), graph) + return lipgloss.JoinHorizontal(lipgloss.Top, metrics, " ", graph) +} + +func monitorSessionColumnWidths(width int) (int, int, bool) { + const gap = 1 + if width <= gap+1 { + return 0, width, false + } + available := max(width-gap, 2) + metricsWidth := max(available/3, 1) + return metricsWidth, max(available-metricsWidth, 1), true } func (m Model) renderMonitorSessionMetrics(width, height int, session monitorSession, pageLabel string, colors palette) string { @@ -314,7 +331,31 @@ func (m Model) renderMonitorSessionMetrics(width, height int, session monitorSes if session.attention != codex.SessionAttentionNone { borderColor = colors.warning } - return frameSized(width, max(height-2, 1), title, strings.Join(lines, "\n"), borderColor, colors) + action := "" + if _, ok := monitorSessionDismissRect(width, 0); ok { + action = m.renderMonitorSessionDismiss(session.id, colors) + } + return frameSizedWithTitleAction(width, max(height-2, 1), title, action, strings.Join(lines, "\n"), borderColor, colors) +} + +func (m Model) renderMonitorSessionDismiss(id string, colors palette) string { + style := lipgloss.NewStyle().Foreground(colors.dim).Background(colors.background) + if m.monitorDismissHover == id { + style = style.Bold(true).Foreground(colors.accent) + } + if m.monitorDismissFlash == id { + style = style.Bold(true).Foreground(colors.background).Background(colors.primary) + } + return style.Render(monitorDismissLabel) +} + +func monitorSessionDismissRect(metricsWidth, rowY int) (monitorRect, bool) { + const minimumTitleWidth = 2 + labelWidth := lipgloss.Width(monitorDismissLabel) + if metricsWidth < labelWidth+6+minimumTitleWidth { + return monitorRect{}, false + } + return monitorRect{x: metricsWidth - labelWidth - 2, y: rowY, width: labelWidth, height: 1}, true } func monitorAttentionLabel(attention codex.SessionAttention) string { @@ -604,6 +645,33 @@ func (m Model) monitorButtonAt(x, y int) footerButtonID { return footerButtonNone } +func (m Model) monitorSessionDismissAt(x, y int) (string, bool) { + if m.meterView != viewMonitor || (m.loading && len(m.snapshot.Meters()) == 0) { + return "", false + } + dashboard := m.dashboardLayout() + area := layoutMonitorArea(dashboard.contentWidth, dashboard.meterHeight) + metricsWidth, _, ok := monitorSessionColumnWidths(area.width) + if !ok { + return "", false + } + localX := x - 2 + localY := y - dashboard.meterY - area.topHeight - area.gap + 1 + if localY < 0 { + return "", false + } + sessions, rowHeights, _ := m.monitorSessionPage(area.graphHeight) + rowY := 0 + for index, session := range sessions { + rect, visible := monitorSessionDismissRect(metricsWidth, rowY) + if visible && rect.contains(localX, localY) { + return session.id, true + } + rowY += rowHeights[index] + } + return "", false +} + func (m Model) monitorGoEnabled() bool { return m.monitorState == monitorIdle || m.monitorState == monitorStopped } diff --git a/internal/ui/monitor_test.go b/internal/ui/monitor_test.go index 9570198c..89f924a4 100644 --- a/internal/ui/monitor_test.go +++ b/internal/ui/monitor_test.go @@ -561,6 +561,146 @@ func TestMonitorSessionPagesRespondToKeyboardAndMouse(t *testing.T) { } } +func TestDismissedMonitorSessionReturnsOnlyAfterRenewedActivity(t *testing.T) { + now := time.Date(2026, time.August, 17, 12, 0, 0, 0, time.UTC) + base := codex.LiveUsageSession{ID: "alpha", TotalTokens: 100, LastActivity: now, Active: true} + newDismissed := func(t *testing.T) Model { + t.Helper() + model := Model{monitorState: monitorRunning, monitorStartedAt: now, monitorLatest: 100, monitorGraphStart: 100} + model.startMonitorSessions(codex.LiveUsageSnapshot{Sessions: []codex.LiveUsageSession{base}}, now) + model.dismissMonitorSession(base.ID) + if model.visibleMonitorSessionCount() != 0 { + t.Fatal("dismissed session remained visible") + } + return model + } + + unchanged := newDismissed(t) + unchanged.syncMonitorSessions(codex.LiveUsageSnapshot{Sessions: []codex.LiveUsageSession{base}}, now.Add(time.Second)) + if unchanged.visibleMonitorSessionCount() != 0 { + t.Fatal("an unchanged refresh restored the dismissed session") + } + unchanged.captureMonitorSamples(now.Add(monitorSampleInterval)) + if len(unchanged.monitorSessionData[0].samples) != 1 { + t.Fatal("dismissed session stopped collecting graph telemetry") + } + + for _, test := range []struct { + name string + mutate func(*codex.LiveUsageSession) + }{ + {"tokens", func(session *codex.LiveUsageSession) { session.TotalTokens++ }}, + {"activity", func(session *codex.LiveUsageSession) { session.LastActivity = now.Add(time.Second) }}, + {"model call", func(session *codex.LiveUsageSession) { + session.ModelCalls = []codex.LiveModelCall{{Sequence: 1, At: now.Add(time.Second)}} + }}, + {"turn timing", func(session *codex.LiveUsageSession) { + session.TurnTimings = []codex.LiveTurnTiming{{Sequence: 1, At: now.Add(time.Second), Available: true}} + }}, + {"attention", func(session *codex.LiveUsageSession) { session.Attention = codex.SessionAttentionApproval }}, + } { + t.Run(test.name, func(t *testing.T) { + model := newDismissed(t) + update := base + test.mutate(&update) + model.syncMonitorSessions(codex.LiveUsageSnapshot{Sessions: []codex.LiveUsageSession{update}}, now.Add(time.Second)) + if model.visibleMonitorSessionCount() != 1 { + t.Fatalf("%s did not restore the dismissed session", test.name) + } + if _, dismissed := model.monitorDismissed[base.ID]; dismissed { + t.Fatalf("%s left a stale dismissal watermark", test.name) + } + }) + } + + restarted := newDismissed(t) + inactive := base + inactive.Active = false + restarted.syncMonitorSessions(codex.LiveUsageSnapshot{Sessions: []codex.LiveUsageSession{inactive}}, now.Add(time.Second)) + if restarted.visibleMonitorSessionCount() != 0 || !restarted.monitorDismissed[base.ID].inactiveObserved { + t.Fatal("inactive dismissed session lost its restart watermark") + } + restarted.syncMonitorSessions(codex.LiveUsageSnapshot{Sessions: []codex.LiveUsageSession{base}}, now.Add(2*time.Second)) + if restarted.visibleMonitorSessionCount() != 1 { + t.Fatal("restarted session did not regenerate its row") + } +} + +func TestMonitorSessionDismissControlRendersAndMatchesClickSurface(t *testing.T) { + for _, size := range []struct{ width, height int }{{40, 24}, {60, 24}, {100, 36}, {160, 45}} { + model := Model{ + snapshot: codex.DemoSnapshot(), width: size.width, height: size.height, + meterView: viewMonitor, monitorState: monitorRunning, monitorStartedAt: time.Now(), + monitorSessionData: []monitorSession{{id: "session-alpha", active: true, displayed: true}}, + } + x, y := renderedTextStart(t, model, monitorDismissLabel) + for offset := 0; offset < lipgloss.Width(monitorDismissLabel); offset++ { + if id, ok := model.monitorSessionDismissAt(x+offset, y); !ok || id != "session-alpha" { + t.Errorf("%dx%d dismiss cell %d hit (%q,%v)", size.width, size.height, offset, id, ok) + } + } + } + + multiple := Model{ + snapshot: codex.DemoSnapshot(), width: 100, height: 36, + meterView: viewMonitor, monitorState: monitorRunning, monitorStartedAt: time.Now(), + monitorSessionData: []monitorSession{ + {id: "session-alpha", active: true, displayed: true}, + {id: "session-beta", active: true, displayed: true}, + {id: "session-gamma", active: true, displayed: true}, + }, + } + var dismissRows []struct { + x, y int + } + for y, line := range strings.Split(ansi.Strip(multiple.render()), "\n") { + if byteX := strings.Index(line, monitorDismissLabel); byteX >= 0 { + dismissRows = append(dismissRows, struct{ x, y int }{lipgloss.Width(line[:byteX]), y}) + } + } + if len(dismissRows) != 3 { + t.Fatalf("multi-session dismiss controls = %d, want 3", len(dismissRows)) + } + for index, position := range dismissRows { + wantID := multiple.monitorSessionData[index].id + if id, ok := multiple.monitorSessionDismissAt(position.x+1, position.y); !ok || id != wantID { + t.Errorf("multi-session dismiss row %d hit (%q,%v), want %q", index, id, ok, wantID) + } + } + + model := Model{ + snapshot: codex.DemoSnapshot(), width: 100, height: 36, + meterView: viewMonitor, monitorState: monitorRunning, monitorStartedAt: time.Now(), + monitorSessionData: []monitorSession{{id: "session-alpha", active: true, displayed: true}}, + } + x, y := renderedTextStart(t, model, monitorDismissLabel) + updated, command := model.Update(tea.MouseMotionMsg{X: x + 1, Y: y}) + model = updated.(Model) + if command != nil || model.monitorDismissHover != "session-alpha" { + t.Fatal("dismiss control did not highlight on hover") + } + colors := paletteFor(model.theme) + wantHover := lipgloss.NewStyle().Bold(true).Foreground(colors.accent).Background(colors.background).Render(monitorDismissLabel) + if got := model.renderMonitorSessionDismiss("session-alpha", colors); got != wantHover { + t.Fatalf("hovered dismiss control = %q, want %q", got, wantHover) + } + + updated, command = model.Update(tea.MouseClickMsg{X: x + 1, Y: y, Button: tea.MouseLeft}) + model = updated.(Model) + if command == nil || model.monitorDismissFlash != "session-alpha" || model.visibleMonitorSessionCount() != 1 { + t.Fatal("dismiss click did not begin its confirmation flash") + } + wantFlash := lipgloss.NewStyle().Bold(true).Foreground(colors.background).Background(colors.primary).Render(monitorDismissLabel) + if got := model.renderMonitorSessionDismiss("session-alpha", colors); got != wantFlash { + t.Fatalf("flashed dismiss control = %q, want %q", got, wantFlash) + } + updated, _ = model.Update(monitorSessionDismissMsg{id: "session-alpha", sequence: model.monitorDismissSeq}) + model = updated.(Model) + if model.visibleMonitorSessionCount() != 0 || model.monitorDismissFlash != "" { + t.Fatal("dismiss control did not hide the session after flashing") + } +} + func TestMonitorSurfacesUnavailableAndFailedFinalUsage(t *testing.T) { model := Model{meterView: viewMonitor, monitorState: monitorStarting, monitorRequest: 1} updated, _ := model.Update(monitorFetchedMsg{ diff --git a/internal/ui/view.go b/internal/ui/view.go index fdc0024f..0d34e99e 100644 --- a/internal/ui/view.go +++ b/internal/ui/view.go @@ -223,6 +223,10 @@ func frame(width int, title, body string, color imagecolor.Color, colors palette } func frameSized(width, height int, title, body string, color imagecolor.Color, colors palette) string { + return frameSizedWithTitleAction(width, height, title, "", body, color, colors) +} + +func frameSizedWithTitleAction(width, height int, title, action, body string, color imagecolor.Color, colors palette) string { width = max(width, 1) style := lipgloss.NewStyle(). Width(width). @@ -238,10 +242,14 @@ func frameSized(width, height int, title, body string, color imagecolor.Color, c // reserving one extra row for that border. style = style.Height(height + 1) } - return renderFrameTitle(width, title, color, colors) + "\n" + style.Render(body) + return renderFrameTitleWithAction(width, title, action, color, colors) + "\n" + style.Render(body) } func renderFrameTitle(width int, title string, color imagecolor.Color, colors palette) string { + return renderFrameTitleWithAction(width, title, "", color, colors) +} + +func renderFrameTitleWithAction(width int, title, action string, color imagecolor.Color, colors palette) string { width = max(width, 1) border := lipgloss.RoundedBorder() borderStyle := lipgloss.NewStyle().Foreground(color).Background(colors.background) @@ -252,15 +260,31 @@ func renderFrameTitle(width int, title string, color imagecolor.Color, colors pa return borderStyle.Render(border.TopLeft + border.TopRight) } - title = strings.TrimSpace(ansi.Truncate(title, max(width-6, 0), "")) + actionWidth := lipgloss.Width(action) + if actionWidth > 0 && width < actionWidth+8 { + action = "" + actionWidth = 0 + } + titleWidth := max(width-6, 0) + if actionWidth > 0 { + titleWidth = max(width-actionWidth-6, 0) + } + title = strings.TrimSpace(ansi.Truncate(title, titleWidth, "")) if title == "" { return borderStyle.Render(border.TopLeft + strings.Repeat(border.Top, width-2) + border.TopRight) } prefix := border.TopLeft + border.Top + " " - suffixWidth := max(width-lipgloss.Width(prefix)-lipgloss.Width(title)-1, 1) - suffix := " " + strings.Repeat(border.Top, suffixWidth-1) + border.TopRight + suffix := borderStyle.Render(" " + border.TopRight) + if actionWidth > 0 { + suffix = borderStyle.Render(" ") + action + borderStyle.Render(" "+border.TopRight) + } + middleWidth := max(width-lipgloss.Width(prefix)-lipgloss.Width(title)-lipgloss.Width(suffix), 0) + middle := "" + if middleWidth > 0 { + middle = " " + strings.Repeat(border.Top, middleWidth-1) + } titleStyle := lipgloss.NewStyle().Bold(true).Foreground(color).Background(colors.background) - return borderStyle.Render(prefix) + titleStyle.Render(title) + borderStyle.Render(suffix) + return borderStyle.Render(prefix) + titleStyle.Render(title) + borderStyle.Render(middle) + suffix } func countdown(at time.Time) string { From 626bb8e5f43a265f9953243ab7d9b25514967d2d Mon Sep 17 00:00:00 2001 From: merefield Date: Mon, 17 Aug 2026 16:12:38 +0100 Subject: [PATCH 4/4] FIX: let monitor alerts be dismissed --- README.md | 6 ++++-- internal/ui/model.go | 21 ++++++++++++++++----- internal/ui/monitor_test.go | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5f902c44..28d85944 100644 --- a/README.md +++ b/README.md @@ -587,8 +587,10 @@ The other top-level views are: current run without closing or altering the Codex session. Codexometer keeps collecting its telemetry while hidden and restores the row automatically when tokens, model calls, turn timing, durable activity, or attention moves - forward, or when an inactive session becomes active again. Starting a new - Monitor recording also restores every dismissed row. + forward, or when an inactive session becomes active again. An alert already + visible when `[×]` is clicked is dismissed with its row; a later new or + changed alert restores it. Starting a new Monitor recording also restores + every dismissed row. When the terminal cannot fit every root, use Page Up, Page Down, or the mouse wheel to page through the rows. Stop performs an immediate final local read instead of relying on the latest graph sample. diff --git a/internal/ui/model.go b/internal/ui/model.go index 9952e48c..c2f59aaa 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -152,6 +152,8 @@ type monitorSessionDismissal struct { lastActivity time.Time callSequence uint64 turnSequence uint64 + attention codex.SessionAttention + attentionCleared bool inactiveObserved bool } @@ -1372,10 +1374,16 @@ func (m *Model) syncMonitorSessions(usage codex.LiveUsageSnapshot, observedAt ti for index := range m.monitorSessionData { session := &m.monitorSessionData[index] dismissal, dismissed := m.monitorDismissed[session.id] - if dismissed && !session.active { + if !dismissed { + continue + } + if !session.active { dismissal.inactiveObserved = true - m.monitorDismissed[session.id] = dismissal } + if dismissal.attention != codex.SessionAttentionNone && session.attention == codex.SessionAttentionNone { + dismissal.attentionCleared = true + } + m.monitorDismissed[session.id] = dismissal } } @@ -1393,6 +1401,7 @@ func (m *Model) dismissMonitorSession(id string) { lastActivity: session.lastActivity, callSequence: session.callSequence, turnSequence: session.turnSequence, + attention: session.attention, } m.monitorSessions = m.visibleMonitorSessionCount() maximumScroll := max(m.monitorSessions-m.monitorPageSize(), 0) @@ -1404,11 +1413,13 @@ func (m *Model) restoreMonitorSessionOnActivity(session *monitorSession) { if !dismissed { return } - if session.attention != codex.SessionAttentionNone || - session.latest > dismissal.latest || + newAttention := session.attention != codex.SessionAttentionNone && + (session.attention != dismissal.attention || dismissal.attentionCleared) + if session.latest > dismissal.latest || session.lastActivity.After(dismissal.lastActivity) || session.callSequence > dismissal.callSequence || session.turnSequence > dismissal.turnSequence || + newAttention || (dismissal.inactiveObserved && session.active) { delete(m.monitorDismissed, session.id) } @@ -1419,7 +1430,7 @@ func (m Model) monitorSessionVisible(session monitorSession) bool { return false } _, dismissed := m.monitorDismissed[session.id] - return !dismissed || session.attention != codex.SessionAttentionNone + return !dismissed } func applyMonitorSessionTelemetry(session *monitorSession, update codex.LiveUsageSession, since time.Time) { diff --git a/internal/ui/monitor_test.go b/internal/ui/monitor_test.go index 89f924a4..bcc00248 100644 --- a/internal/ui/monitor_test.go +++ b/internal/ui/monitor_test.go @@ -585,6 +585,26 @@ func TestDismissedMonitorSessionReturnsOnlyAfterRenewedActivity(t *testing.T) { t.Fatal("dismissed session stopped collecting graph telemetry") } + alerted := base + alerted.Attention = codex.SessionAttentionCheck + withCurrentAlert := Model{monitorState: monitorRunning, monitorStartedAt: now, monitorLatest: 100, monitorGraphStart: 100} + withCurrentAlert.startMonitorSessions(codex.LiveUsageSnapshot{Sessions: []codex.LiveUsageSession{alerted}}, now) + withCurrentAlert.dismissMonitorSession(alerted.ID) + withCurrentAlert.syncMonitorSessions(codex.LiveUsageSnapshot{Sessions: []codex.LiveUsageSession{alerted}}, now.Add(time.Second)) + if withCurrentAlert.visibleMonitorSessionCount() != 0 { + t.Fatal("the alert present when the session was dismissed immediately restored its row") + } + cleared := alerted + cleared.Attention = codex.SessionAttentionNone + withCurrentAlert.syncMonitorSessions(codex.LiveUsageSnapshot{Sessions: []codex.LiveUsageSession{cleared}}, now.Add(2*time.Second)) + if !withCurrentAlert.monitorDismissed[alerted.ID].attentionCleared { + t.Fatal("dismissal did not remember that the original alert cleared") + } + withCurrentAlert.syncMonitorSessions(codex.LiveUsageSnapshot{Sessions: []codex.LiveUsageSession{alerted}}, now.Add(3*time.Second)) + if withCurrentAlert.visibleMonitorSessionCount() != 1 { + t.Fatal("a newly raised alert did not regenerate the dismissed row") + } + for _, test := range []struct { name string mutate func(*codex.LiveUsageSession)