The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(traces): measure trace browser text in terminal columns (#822)
Rudy Mizrahi Celekli529c1daa902e
diff --git a/cli/beacon/go.mod b/cli/beacon/go.modindex befffddb..923e0fa8 100644--- a/cli/beacon/go.mod+++ b/cli/beacon/go.mod@@ -21,7 +21,7 @@ require (github.com/antlr4-go/antlr/v4 v4.13.1 // indirectgithub.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirectgithub.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect- github.com/charmbracelet/x/ansi v0.10.1 // indirect+ github.com/charmbracelet/x/ansi v0.10.1github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirectgithub.com/charmbracelet/x/term v0.2.1 // indirectgithub.com/cpuguy83/go-md2man/v2 v2.0.4 // indirectdiff --git a/cli/beacon/internal/endpoint/traceview/terminal_cells_test.go b/cli/beacon/internal/endpoint/traceview/terminal_cells_test.gonew file mode 100644index 00000000..c70f0fc8--- /dev/null+++ b/cli/beacon/internal/endpoint/traceview/terminal_cells_test.go@@ -0,0 +1,80 @@+package traceview++import (+ "strings"+ "testing"++ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/dashboard"+ tea "github.com/charmbracelet/bubbletea"+ "github.com/charmbracelet/x/ansi"+)++func TestTraceTerminalCellTruncation(t *testing.T) {+ for _, tc := range []struct {+ name, input string+ width int+ want string+ }{+ {"wide", strings.Repeat("界", 15), 20, strings.Repeat("界", 9) + "…"},+ {"emoji-clusters", "👩💻👩💻👩💻", 5, "👩💻👩💻…"},+ {"combining", "ééé", 3, "ééé"},+ {"ascii", "abcdefgh", 5, "abcd…"},+ {"newlines", "one\ntwo", 20, "one two"},+ {"single-cell", "界", 1, "…"},+ {"unbounded", "界", 0, "界"},+ } {+ t.Run(tc.name, func(t *testing.T) {+ got := truncate(tc.input, tc.width)+ if got != tc.want {+ t.Fatalf("title=%q want=%q", got, tc.want)+ }+ if tc.width > 0 && ansi.StringWidth(got) > tc.width {+ t.Fatalf("rendered title exceeds terminal width: %q", got)+ }+ })+ }+}++func TestTraceTerminalCellWrapping(t *testing.T) {+ for _, tc := range []struct {+ name, input string+ width int+ want []string+ }{+ {"wide", strings.Repeat("界", 15), 20, []string{strings.Repeat("界", 10), strings.Repeat("界", 5)}},+ {"emoji-clusters", "👩💻👩💻👩💻", 4, []string{"👩💻👩💻", "👩💻"}},+ {"combining", "ééé", 2, []string{"éé", "é"}},+ {"ascii-spaces", "ab cd", 3, []string{"ab ", " cd"}},+ {"blank-crlf", "ab\r\n\ncd\r", 3, []string{"ab", "", "cd"}},+ } {+ t.Run(tc.name, func(t *testing.T) {+ got := wrapLines(tc.input, tc.width)+ if strings.Join(got, "\n") != strings.Join(tc.want, "\n") || len(got) != len(tc.want) {+ t.Fatalf("lines=%q want=%q", got, tc.want)+ }+ for _, line := range got {+ if ansi.StringWidth(line) > tc.width {+ t.Fatalf("line exceeds terminal width: %q", line)+ }+ }+ })+ }+}++func TestTraceViewCJKRowsStayWithinTerminal(t *testing.T) {+ model := NewModel(nil)+ updated, _ := model.Update(tea.WindowSizeMsg{Width: 80, Height: 30})+ model = updated.(Model)+ model.loading = false+ model.traces = []dashboard.TraceSummaryV1{{ID: "trace", Title: strings.Repeat("界", 40)}}+ model.totalMatched = 1+ view := model.View()+ if !strings.Contains(ansi.Strip(view), "界") {+ t.Fatal("list view omitted the CJK title")+ }+ for _, line := range strings.Split(view, "\n") {+ if strings.Contains(ansi.Strip(line), "界") && ansi.StringWidth(line) > 80 {+ t.Fatalf("list row exceeds 80 columns: width=%d %q", ansi.StringWidth(line), line)+ }+ }+}diff --git a/cli/beacon/internal/endpoint/traceview/traceview.go b/cli/beacon/internal/endpoint/traceview/traceview.goindex c31e4226..513d0188 100644--- a/cli/beacon/internal/endpoint/traceview/traceview.go+++ b/cli/beacon/internal/endpoint/traceview/traceview.go@@ -11,6 +11,7 @@ import (tea "github.com/charmbracelet/bubbletea""github.com/charmbracelet/lipgloss"+ "github.com/charmbracelet/x/ansi""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/dashboard")@@ -455,7 +456,9 @@ func (m Model) listView() string {lastDate = date}titleWidth := max(12, m.width-35)- line := fmt.Sprintf("%-8s %-*s %s", clock, titleWidth, truncate(trace.Title, titleWidth), trace.Harness.Name)+ title := truncate(trace.Title, titleWidth)+ title += strings.Repeat(" ", titleWidth-ansi.StringWidth(title))+ line := fmt.Sprintf("%-8s %s %s", clock, title, trace.Harness.Name)meta := fmt.Sprintf(" %s · %d events · %s%s", tracePath(trace), trace.EventCount, contentLabel(trace), sharingLabel(trace))if i == m.selected {b.WriteString(selectedStyle.Render(fit(" ❯ "+line, m.width)) + "\n")@@ -683,12 +686,7 @@ func wrapLines(value string, width int) []string {out = append(out, "")continue}- for len([]rune(line)) > width {- runes := []rune(line)- out = append(out, string(runes[:width]))- line = string(runes[width:])- }- out = append(out, line)+ out = append(out, strings.Split(ansi.Hardwrap(line, width, true), "\n")...)}return out}@@ -698,14 +696,11 @@ func fit(value string, width int) string {}func truncate(value string, width int) string {- runes := []rune(strings.ReplaceAll(value, "\n", " "))- if width <= 0 || len(runes) <= width {- return string(runes)- }- if width == 1 {- return "…"+ value = strings.ReplaceAll(value, "\n", " ")+ if width <= 0 {+ return value}- return string(runes[:width-1]) + "…"+ return ansi.Truncate(value, width, "…")}func firstNonEmpty(values ...string) string {