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
Clip picker lines to the terminal width; shorten two destination details
shukieshah8cf6ee24229f
diff --git a/cli/beacon/internal/onboarding/picker.go b/cli/beacon/internal/onboarding/picker.goindex aee6afc1..26dca911 100644--- a/cli/beacon/internal/onboarding/picker.go+++ b/cli/beacon/internal/onboarding/picker.go@@ -96,8 +96,16 @@ func selectOption(in *os.File, out io.Writer, options []choice, color bool) (intfmt.Fprint(out, ansiHideCur)+ // Every drawn line is clipped to the terminal width so nothing wraps: the redraw and+ // the final clear count lines, and a wrapped line would make them eat whatever the+ // caller printed above the menu.+ width, _, sizeErr := term.GetSize(fd)+ if sizeErr != nil {+ width = 0+ }+selected := 0- render(out, options, selected, color, true)+ render(out, options, selected, color, true, width)buf := make([]byte, 32)for {@@ -127,7 +135,7 @@ func selectOption(in *os.File, out io.Writer, options []choice, color bool) (int}}if moved {- render(out, options, selected, color, false)+ render(out, options, selected, color, false, width)}}}@@ -190,8 +198,10 @@ func decodeByte(c byte, total int) (keyEvent, bool) {}}-// render draws the option list plus its key hint, overwriting the previous draw.-func render(out io.Writer, options []choice, selected int, color bool, first bool) {+// render draws the option list plus its key hint, overwriting the previous draw. width is+// the terminal width in columns, or 0 when unknown; every line is clipped to it so the+// draw occupies exactly renderedLines rows.+func render(out io.Writer, options []choice, selected int, color bool, first bool, width int) {if !first {fmt.Fprintf(out, ansiUp, renderedLines(options))}@@ -202,19 +212,35 @@ func render(out io.Writer, options []choice, selected int, color bool, first boofor i, option := range options {fmt.Fprint(out, ansiClearLine)if i == selected {- fmt.Fprintf(out, " %s❯ %s%s\r\n", accent, option.Label, clear)+ fmt.Fprintf(out, " %s❯ %s%s\r\n", accent, clip(option.Label, width-4), clear)} else {- fmt.Fprintf(out, " %s\r\n", option.Label)+ fmt.Fprintf(out, " %s\r\n", clip(option.Label, width-4))}if option.Detail != "" {fmt.Fprint(out, ansiClearLine)- fmt.Fprintf(out, " %s%s%s\r\n", dimmed, option.Detail, clear)+ fmt.Fprintf(out, " %s%s%s\r\n", dimmed, clip(option.Detail, width-6), clear)}}fmt.Fprint(out, ansiClearLine)fmt.Fprintf(out, " %s↑/↓ move · ↵ select · ^C cancel%s\r\n", dimmed, clear)}+// clip shortens text to fit in width columns, ending it with an ellipsis. A width of zero+// or less means the terminal size is unknown and the text is left alone.+func clip(text string, width int) string {+ if width <= 0 {+ return text+ }+ runes := []rune(text)+ if len(runes) <= width {+ return text+ }+ if width == 1 {+ return "…"+ }+ return string(runes[:width-1]) + "…"+}+// clear erases the last n rendered lines and parks the cursor at their start.func clear(out io.Writer, n int) {fmt.Fprintf(out, ansiUp, n)diff --git a/cli/beacon/internal/onboarding/picker_test.go b/cli/beacon/internal/onboarding/picker_test.goindex 5af791ab..04390c2b 100644--- a/cli/beacon/internal/onboarding/picker_test.go+++ b/cli/beacon/internal/onboarding/picker_test.go@@ -83,7 +83,7 @@ func assertEvents(t *testing.T, got, want []keyEvent) {func TestRenderMarksTheSelectedOption(t *testing.T) {var out bytes.Buffer- render(&out, choices([]string{"Alpha", "Beta", "Gamma"}), 1, false, true)+ render(&out, choices([]string{"Alpha", "Beta", "Gamma"}), 1, false, true, 0)got := out.String()if !strings.Contains(got, "❯ Beta") {@@ -101,8 +101,8 @@ func TestRenderMarksTheSelectedOption(t *testing.T) {// printed above the menu.func TestRenderFirstDrawDoesNotMoveTheCursor(t *testing.T) {var first, redraw bytes.Buffer- render(&first, choices([]string{"A", "B"}), 0, false, true)- render(&redraw, choices([]string{"A", "B"}), 0, false, false)+ render(&first, choices([]string{"A", "B"}), 0, false, true, 0)+ render(&redraw, choices([]string{"A", "B"}), 0, false, false, 0)if strings.Contains(first.String(), "\x1b[3A") {t.Fatalf("first draw moved the cursor up:\n%q", first.String())@@ -114,13 +114,13 @@ func TestRenderFirstDrawDoesNotMoveTheCursor(t *testing.T) {func TestRenderHonorsColorOff(t *testing.T) {var out bytes.Buffer- render(&out, choices([]string{"Alpha", "Beta"}), 0, false, true)+ render(&out, choices([]string{"Alpha", "Beta"}), 0, false, true, 0)if strings.Contains(out.String(), colorAccnt) || strings.Contains(out.String(), colorDim) {t.Fatalf("colour escapes leaked with colour disabled:\n%q", out.String())}out.Reset()- render(&out, choices([]string{"Alpha", "Beta"}), 0, true, true)+ render(&out, choices([]string{"Alpha", "Beta"}), 0, true, true, 0)if !strings.Contains(out.String(), colorAccnt) {t.Fatalf("colour was requested but not emitted:\n%q", out.String())}@@ -194,7 +194,7 @@ func TestRenderDrawsDetailsAndCountsThem(t *testing.T) {t.Fatalf("renderedLines = %d, want 3 options + 2 details + hint", got)}var out bytes.Buffer- render(&out, rows, 0, true, true)+ render(&out, rows, 0, true, true, 0)got := out.String()if !strings.Contains(got, " "+colorDim+"first thing"+colorReset) || !strings.Contains(got, colorDim+"third thing") {t.Fatalf("details are not drawn dim under their options:\n%q", got)@@ -203,8 +203,28 @@ func TestRenderDrawsDetailsAndCountsThem(t *testing.T) {t.Fatalf("detail must sit between its option and the next:\n%s", got)}var redraw bytes.Buffer- render(&redraw, rows, 1, false, false)+ render(&redraw, rows, 1, false, false, 0)if !strings.HasPrefix(redraw.String(), "\x1b[6A") {t.Fatalf("redraw must move up over options, details and hint:\n%q", redraw.String())}}++// A line longer than the terminal is clipped, never wrapped: a wrapped line would throw+// off the line count that the redraw and the final clear rely on.+func TestRenderClipsToTerminalWidth(t *testing.T) {+ rows := []choice{{Label: "Alpha", Detail: strings.Repeat("d", 100)}, {Label: strings.Repeat("L", 100)}}+ var out bytes.Buffer+ render(&out, rows, 0, false, true, 40)+ for _, line := range strings.Split(strings.TrimSpace(out.String()), "\r\n") {+ visible := strings.NewReplacer(ansiClearLine, "").Replace(line)+ if n := len([]rune(visible)); n > 40 {+ t.Fatalf("line is %d columns wide on a 40-column terminal: %q", n, visible)+ }+ }+ if !strings.Contains(out.String(), "…") {+ t.Fatalf("clipped lines should end with an ellipsis:\n%q", out.String())+ }+ if clip("short", 0) != "short" || clip("short", 10) != "short" || clip("abcdef", 4) != "abc…" {+ t.Fatal("clip: unknown width leaves text alone; otherwise width-1 runes plus an ellipsis")+ }+}diff --git a/cli/beacon/internal/onboarding/prompt.go b/cli/beacon/internal/onboarding/prompt.goindex ca316bf9..75b88a63 100644--- a/cli/beacon/internal/onboarding/prompt.go+++ b/cli/beacon/internal/onboarding/prompt.go@@ -113,13 +113,15 @@ type destinationChoice struct {// destinationChoices lists the answers in display order. Local is first so that Enter// never forwards anything: sending telemetry off the machine is a choice, never a default.+// Labels and details are kept short enough to draw unwrapped on an 80-column terminal+// (a test pins this); the picker clips to the real width as a backstop.func destinationChoices(offerAsymptote bool) []destinationChoice {items := []destinationChoice{- {DestinationLocal, "Keep it on this machine", "Nothing is sent anywhere. Local JSONL and local dashboard; change it any time."},+ {DestinationLocal, "Keep it on this machine", "Nothing is sent anywhere. Local JSONL and dashboard; change it any time."},{DestinationOwnInfra, "Forward to your own infrastructure", "SIEM, observability platform, or an S3/GCS bucket you own."},}if offerAsymptote {- items = append(items, destinationChoice{DestinationAsymptote, "Forward to Asymptote Managed", "Opens your browser to approve this device; revoke it from the dashboard any time."})+ items = append(items, destinationChoice{DestinationAsymptote, "Forward to Asymptote Managed", "Approve this device in your browser; revoke from the dashboard any time."})}return items}diff --git a/cli/beacon/internal/onboarding/prompt_test.go b/cli/beacon/internal/onboarding/prompt_test.goindex a8080918..6aa97f5f 100644--- a/cli/beacon/internal/onboarding/prompt_test.go+++ b/cli/beacon/internal/onboarding/prompt_test.go@@ -188,7 +188,7 @@ func TestPromptAsksDestinationOnlyWhenRequested(t *testing.T) {"Where should this machine's agent telemetry go?","Keep it on this machine", "Nothing is sent anywhere.","Forward to your own infrastructure", "SIEM, observability platform, or an S3/GCS bucket you own.",- "Forward to Asymptote Managed", "revoke it from the dashboard",+ "Forward to Asymptote Managed", "revoke from the dashboard","Connecting after install.",} {if !strings.Contains(buf.String(), want) {@@ -261,3 +261,19 @@ func TestAskDestinationAlone(t *testing.T) {t.Fatalf("EOF should abort, got %v", err)}}++// Every destination row must draw without wrapping on a standard 80-column terminal, or+// the picker's line count is off and it eats the lines above it on redraw.+func TestDestinationRowsFitEightyColumns(t *testing.T) {+ for _, item := range destinationChoices(true) {+ if n := 4 + len([]rune(item.label)); n > 80 {+ t.Fatalf("label %q draws %d columns", item.label, n)+ }+ if n := 6 + len([]rune(item.detail)); n > 80 {+ t.Fatalf("detail %q draws %d columns", item.detail, n)+ }+ }+ if !strings.Contains(destinationChoices(true)[1].detail, "SIEM, observability platform, or an S3/GCS bucket you own.") {+ t.Fatal("the own-infrastructure wording is part of the product copy")+ }+}