From 1eadaa205e0bd0d78275378061ce2e507c2606cb Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 12 Nov 2026 12:28:02 +0000 Subject: [PATCH] FIX: prioritise actual statusline width over goal footer time --- README.md | 8 +-- internal/ui/monitor_goal.go | 6 ++- internal/ui/monitor_goal_test.go | 85 ++++++++++++++++++++++++++++++- internal/ui/monitor_statusline.go | 4 +- 4 files changed, 96 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ed516c73..1a648060 100644 --- a/README.md +++ b/README.md @@ -1887,9 +1887,11 @@ come from Codex—not inactivity guesses—and do not replace WORKING, approvals TURN COMPLETE. Unavailable refreshes mark retained observations **GOAL STALE**. Terminal goal labels include Codex's reported pursuit duration when it fits, for example `PURSUING GOAL // 1d 1h 23m`. Zero units are omitted; less than a -minute is shown as `<1m`. The duration is omitted before crowding other footer -controls, and stale observations do not show a duration. This is accumulated -wall-clock pursuit time recorded by Codex (including tool execution), not time +minute is shown as `<1m`. The full statusline and footer controls take priority: +the duration is omitted first, then the goal label if it still cannot fit, +rather than shortening the statusline to make room. Stale observations do not +show a duration. This is accumulated wall-clock pursuit time recorded by Codex +(including tool execution), not time since the goal was created or a model-only thinking timer. It updates when Codex reports accounting progress, not on a locally invented ticking clock. Codex retains its goal accounting across Codexometer restarts; replacing the goal diff --git a/internal/ui/monitor_goal.go b/internal/ui/monitor_goal.go index 9521f11e..a593e9ef 100644 --- a/internal/ui/monitor_goal.go +++ b/internal/ui/monitor_goal.go @@ -67,8 +67,10 @@ func (m Model) monitorGoalFooter(width int, controls string, colors palette) str if controls != "" { available -= ansi.StringWidth(controls) + 2 } - if m.monitorStatusLineText(width, controls) != "" { - available -= 12 + // Reserve the statusline as it would render without a goal. The optional + // duration/label must yield first, never shorten configured status fields. + if status := m.monitorStatusLineText(width, controls); status != "" { + available -= max(ansi.StringWidth(status), monitorStatusLineMinTextWidth) } goal := m.monitorGoalStatus(s, available, colors) if goal == "" || ansi.StringWidth(goal) > available { diff --git a/internal/ui/monitor_goal_test.go b/internal/ui/monitor_goal_test.go index ca4b2d3d..7169c2b8 100644 --- a/internal/ui/monitor_goal_test.go +++ b/internal/ui/monitor_goal_test.go @@ -334,6 +334,7 @@ func TestMonitorGoalFooterDropsDurationBeforeStatus(t *testing.T) { m := completedCopyModel() m.setRowContext("root-one", contextFull) m.monitorSessionData[0].goal = &codex.SessionGoal{Status: "active", TimeUsedSeconds: 91439} + m.monitorSessionData[0].latest = 1200 colors := paletteFor(m.theme) label, timed := "PURSUING GOAL", "PURSUING GOAL // 1d 1h 23m" for _, fields := range [][]string{{}, {"used-tokens"}} { @@ -344,7 +345,7 @@ func TestMonitorGoalFooterDropsDurationBeforeStatus(t *testing.T) { reserve += ansi.StringWidth(controls) + 2 } if len(fields) > 0 { - reserve += 12 + reserve += len("1.2K tokens") } for _, available := range []int{len(label) - 1, len(label), len(timed) - 1, len(timed), len(timed) + 20} { width := reserve + available @@ -399,6 +400,88 @@ func TestMonitorGoalFooterKeepsCopyTarget(t *testing.T) { } } +func TestMonitorGoalFooterPreservesActualStatusline(t *testing.T) { + for _, status := range []struct{ raw, text string }{ + {"short", "short"}, + {strings.Repeat("long-session-name-", 6), strings.Repeat("long-session-name-", 6)}, + {strings.Repeat("作業", 12), strings.Repeat("作業", 12)}, + {"\x1b[31mHighlighted name\x1b[0m", "Highlighted name"}, + } { + m := completedCopyModel() + m.setRowContext("root-one", contextFull) + m.monitorStatusLine = []string{"thread-name"} + m.monitorSessionData[0].name = status.raw + m.monitorSessionData[0].goal = &codex.SessionGoal{Status: "active", TimeUsedSeconds: 91439} + colors := paletteFor(m.theme) + label, timed := "PURSUING GOAL", "PURSUING GOAL // 1d 1h 23m" + for _, controls := range []string{"", colors.label().Foreground(colors.primary).Render("[ (C)OPY ]")} { + // Existing footer layout keeps at least nine text cells even when + // a selected field is shorter; otherwise the statusline disappears. + reserve := max(ansi.StringWidth(status.text), 9) + 6 + if controls != "" { + reserve += ansi.StringWidth(controls) + 2 + } + for _, available := range []int{len(label) - 1, len(label), len(timed) - 1, len(timed)} { + width := reserve + available + footer := m.monitorGoalFooter(width, controls, colors) + if got := m.monitorStatusLineText(width, footer); got != status.text { + t.Fatalf("width %d goal shortened statusline: %q, want %q", width, got, status.text) + } + wantGoal := "" + if available >= len(timed) { + wantGoal = timed + } else if available >= len(label) { + wantGoal = label + } + want := wantGoal + if controls != "" { + if want != "" { + want += " " + } + want += ansi.Strip(controls) + } + if got := ansi.Strip(footer); got != want { + t.Fatalf("width %d footer = %q, want %q", width, got, want) + } + panel := frameSizedWithActions(width, 2, "DETAIL", "", footer, "", colors.primary, colors) + panel = m.withMonitorStatusLine(panel, width, footer, colors) + lines := strings.Split(ansi.Strip(panel), "\n") + line := lines[len(lines)-1] + if !strings.Contains(line, status.text) || want != "" && !strings.Contains(line, want) || ansi.StringWidth(line) != width { + t.Fatalf("footer content overlapped or overflowed: %q", line) + } + if controls != "" { + at := strings.Index(line, "[ (C)OPY ]") + if at < 0 || ansi.StringWidth(line[:at]) != width-ansi.StringWidth(controls)-2 { + t.Fatal("goal changed Copy's column:", line) + } + } + } + } + } +} + +func TestMonitorGoalFooterYieldsToTruncatedStatusline(t *testing.T) { + m := completedCopyModel() + m.setRowContext("root-one", contextFull) + m.monitorStatusLine = []string{"thread-name"} + m.monitorSessionData[0].name = strings.Repeat("session-name-", 40) + m.monitorSessionData[0].goal = &codex.SessionGoal{Status: "active", TimeUsedSeconds: 91439} + colors := paletteFor(m.theme) + for _, width := range []int{40, 80, 120, 200} { + for _, controls := range []string{"", benchmarkDetailCopyLabel} { + before := m.monitorStatusLineText(width, controls) + if !strings.HasSuffix(before, "…") { + t.Fatal("fixture did not exercise an already-truncated statusline") + } + footer := m.monitorGoalFooter(width, controls, colors) + if footer != controls || m.monitorStatusLineText(width, footer) != before { + t.Fatalf("width %d displaced a full statusline with a goal", width) + } + } + } +} + func TestMonitorGoalStatusStaleAndSync(t *testing.T) { m := completedCopyModel() usage := codex.LiveUsageSnapshot{Sessions: []codex.LiveUsageSession{{ID: "root-one", Active: true, Goal: &codex.SessionGoal{Status: "active", Objective: "Goal"}}}} diff --git a/internal/ui/monitor_statusline.go b/internal/ui/monitor_statusline.go index 73dd9976..e375fd49 100644 --- a/internal/ui/monitor_statusline.go +++ b/internal/ui/monitor_statusline.go @@ -92,12 +92,14 @@ func (m Model) monitorPriorityFields(s monitorSession) ([]string, map[string]boo return lines, selected } +const monitorStatusLineMinTextWidth = 9 + func (m Model) monitorStatusLineText(width int, copyLabel string) string { end := width - 2 if copyLabel != "" { end = width - ansi.StringWidth(copyLabel) - 3 } - if end < 12 { + if end < monitorStatusLineMinTextWidth+3 { return "" } text := statusline.Text(m.monitorStatusLine, m.monitorStatusValues())