mission control for agent skills
Go agent-skillsagent-toolsai-agentsai-toolsai-workflowclaude-codeclicoding-agentscommand-line-tooldeveloper-toolsgoopencodeproductivity-toolsskill-discoveryskill-managementskillsterminal-appterminal-uituiworkflow-automation
fix: stabilize registry modal rendering
Alvin Unreal3d04c0f59845
diff --git a/internal/tui/helpers.go b/internal/tui/helpers.goindex 74ea00c..eb81d61 100644--- a/internal/tui/helpers.go+++ b/internal/tui/helpers.go@@ -7,6 +7,7 @@ import ("github.com/alvinunreal/lazyskills/internal/compat""github.com/charmbracelet/lipgloss"+ xansi "github.com/charmbracelet/x/ansi""github.com/muesli/reflow/wordwrap")@@ -78,11 +79,31 @@ func formatMetaLine(key, val string, width int) string {}func truncate(s string, width int) string {- runes := []rune(s)- if width <= 1 || len(runes) <= width {+ if width <= 1 || xansi.StringWidth(s) <= width {return s}- return string(runes[:width-1]) + "…"+ return xansi.Truncate(s, width, "…")+}++func clampLineWidth(s string, width int) string {+ if width <= 0 {+ return ""+ }+ if xansi.StringWidth(s) <= width {+ return s+ }+ return xansi.Truncate(s, width, "")+}++func clampBlockWidth(s string, width int) string {+ if width <= 0 || s == "" {+ return ""+ }+ lines := strings.Split(s, "\n")+ for i, line := range lines {+ lines[i] = clampLineWidth(line, width)+ }+ return strings.Join(lines, "\n")}func fitLines(s string, height int) string {@@ -105,14 +126,7 @@ func fitToScreen(s string, width, height int) string {lines = lines[:height]}for i, line := range lines {- for lipgloss.Width(line) > width {- runes := []rune(line)- if len(runes) == 0 {- break- }- line = string(runes[:len(runes)-1])- }- lines[i] = line+ lines[i] = clampLineWidth(line, width)}return strings.Join(lines, "\n")}diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.goindex 9137e40..94a8fa3 100644--- a/internal/tui/tui_test.go+++ b/internal/tui/tui_test.go@@ -2305,8 +2305,8 @@ func TestRichSourceInventoryMetadataAndActions(t *testing.T) {if !strings.Contains(prevJoined, "press d to scan this source") {t.Errorf("expected available scan hint in preview, got %q", prevJoined)}- if !strings.Contains(prevJoined, "enter to browse · d to scan") {- t.Errorf("expected action hint in preview, got %q", prevJoined)+ if strings.Contains(prevJoined, "enter to browse") {+ t.Errorf("source preview should not duplicate footer actions, got %q", prevJoined)}// 3. Assert currentActions for source rowdiff --git a/internal/tui/update_test.go b/internal/tui/update_test.goindex 2add3e2..280f115 100644--- a/internal/tui/update_test.go+++ b/internal/tui/update_test.go@@ -11,6 +11,8 @@ import ("github.com/alvinunreal/lazyskills/internal/runner""github.com/alvinunreal/lazyskills/internal/selfupdate"tea "github.com/charmbracelet/bubbletea"+ "github.com/charmbracelet/lipgloss"+ xansi "github.com/charmbracelet/x/ansi")func TestTUIFooterUpdateNotice(t *testing.T) {@@ -753,6 +755,77 @@ func TestTUIRegistryPreviewScroll(t *testing.T) {}}+func TestTUIRegistryResultsScrollWithSelection(t *testing.T) {+ m := newModel("")+ m.width = 120+ m.height = 30+ m.registryModal = true+ m.registryQuery = "skill"+ m.registryFocusList = true+ m.registryPreviews = map[string]string{}+ for i := 1; i <= 30; i++ {+ m.registryResults = append(m.registryResults, registry.Skill{+ DisplayName: fmt.Sprintf("Skill Result %02d", i),+ Slug: fmt.Sprintf("skill-result-%02d", i),+ Source: "https://github.com/example/skills",+ })+ }+ m.registrySelected = 29++ view := m.View()+ if !strings.Contains(view, "> Skill Result 30") {+ t.Fatalf("expected selected result to stay visible near bottom of long list, got:\n%s", view)+ }+ if !strings.Contains(view, "↑ ") {+ t.Fatalf("expected registry result scroll indicator, got:\n%s", view)+ }+ if strings.Contains(view, "Skill Result 01") {+ t.Fatalf("expected top result to be scrolled out of the visible list, got:\n%s", view)+ }+}++func TestTUIRegistryModalDoesNotSoftWrapRows(t *testing.T) {+ m := newModel("")+ m.width = 110+ m.height = 32+ m.registryModal = true+ m.registryQuery = "cloudf"+ m.registryFocusList = true+ m.registryPreviews = map[string]string{}+ for i := 1; i <= 24; i++ {+ m.registryResults = append(m.registryResults, registry.Skill{+ DisplayName: fmt.Sprintf("cloudflare-email-service-with-a-very-long-display-name-%02d", i),+ Slug: fmt.Sprintf("cloudflare-email-service-with-a-very-long-slug-%02d", i),+ Source: "https://github.com/cloudflare/skills/tree/main/packages/skills/cloudflare-email-service-with-a-very-long-path",+ Installs: 13274,+ })+ }+ m.registrySelected = 18+ key := m.registryResults[m.registrySelected].Source + "\x00" + m.registryResults[m.registrySelected].Slug+ m.registryPreviews[key] = "# Cloudflare Skills\n" + strings.Repeat("https://example.com/this/is/a/very/long/url/that/must/not/soft/wrap/the/registry/modal\n", 8)++ view := m.View()+ for i, line := range strings.Split(view, "\n") {+ if got := lipgloss.Width(line); got > m.width {+ t.Fatalf("registry modal line %d exceeds terminal width: got %d want <= %d\n%s", i+1, got, m.width, view)+ }+ }+}++func TestTUIANSIClampKeepsStyledLinesValid(t *testing.T) {+ styled := selectedStyle.Render(strings.Repeat("cloudflare-email-service ", 12))+ clamped := clampLineWidth(styled, 32)+ if got := xansi.StringWidth(clamped); got > 32 {+ t.Fatalf("clamped styled line exceeds target width: got %d", got)+ }+ if strings.ContainsRune(clamped, '\uFFFD') {+ t.Fatalf("clamped styled line contains replacement characters: %q", clamped)+ }+ if strings.Contains(clamped, "\x1b[") && !strings.Contains(clamped, "\x1b[0m") {+ t.Fatalf("clamped styled line appears to have lost ANSI reset: %q", clamped)+ }+}+func TestTUIRegistryModeKeySeparation(t *testing.T) {m := newModel("")m.width = 100diff --git a/internal/tui/view.go b/internal/tui/view.goindex d220332..cf28e13 100644--- a/internal/tui/view.go+++ b/internal/tui/view.go@@ -664,7 +664,6 @@ func (m appModel) previewLinesForRows(rows []skillsRow, width int) []string {}}- lines = append(lines, "", dimStyle.Render("enter to browse · d to scan"))var wrapped []stringfor _, line := range lines {wrapped = append(wrapped, wrapText(line, width))@@ -798,6 +797,11 @@ func appendRegistryPreviewLines(lines []string, title string, markdown string, w}rendered := renderMarkdownPreview(markdown, width)lines = append(lines, "", sectionHeaderStyle.Render(title))+ if maxLines > 0 {+ if len(rendered) > maxLines {+ rendered = append(rendered[:maxLines], dimStyle.Render("…"))+ }+ }return append(lines, rendered...)}@@ -1827,7 +1831,7 @@ func (m appModel) registryModalOverlay(layout appLayout) string {if m.registryQuery == "" {inputLine = promptStyled + dimStyle.Render("Type to search...")} else {- inputLine = promptStyled + m.registryQuery+ inputLine = promptStyled + truncate(m.registryQuery, max(1, leftWidth-lipgloss.Width(focusPrompt)-2))}} else {// Search input is focused: prompt has high contrast@@ -1835,7 +1839,7 @@ func (m appModel) registryModalOverlay(layout appLayout) string {if m.registryQuery == "" {inputLine = promptStyled + dimStyle.Render("Type to search...")} else {- inputLine = promptStyled + m.registryQuery + "_"+ inputLine = promptStyled + truncate(m.registryQuery, max(1, leftWidth-lipgloss.Width(focusPrompt)-3)) + "_"}}@@ -1861,21 +1865,47 @@ func (m appModel) registryModalOverlay(layout appLayout) string {} else if len(m.registryResults) == 0 {leftContentLines = append(leftContentLines, " No skills found in registry.")} else {- // Show results+ // Show results in a real viewport. Registry searches can return many+ // matches; rendering the full list and clipping it leaves the selected+ // row off-screen and can make the fixed-height modal redraw incorrectly.rowIndent := " "rowWidth := leftWidth - lipgloss.Width(rowIndent)if rowWidth < 10 {rowWidth = leftWidthrowIndent = ""}- for idx, s := range m.registryResults {+ resultSlots := innerHeight - len(leftContentLines)+ if resultSlots < 1 {+ resultSlots = 1+ }+ visibleSlots := resultSlots+ showScrollIndicator := len(m.registryResults) > resultSlots+ if showScrollIndicator && visibleSlots > 1 {+ visibleSlots--+ }++ start := 0+ if showScrollIndicator {+ start = m.registrySelected - visibleSlots + 1+ if start < 0 {+ start = 0+ }+ maxStart := len(m.registryResults) - visibleSlots+ if start > maxStart {+ start = maxStart+ }+ }+ end := min(len(m.registryResults), start+visibleSlots)++ for idx, s := range m.registryResults[start:end] {+ actualIdx := start + idxisSel := falseif m.registrySelectedKeys != nil {_, isSel = m.registrySelectedKeys[s.Source+"\x00"+s.Slug]}focusMarker := " "- if idx == m.registrySelected {+ if actualIdx == m.registrySelected {focusMarker = ">"}selectMarker := " "@@ -1924,7 +1954,7 @@ func (m appModel) registryModalOverlay(layout appLayout) string {truncatedPlain := truncate(plainNameAndSource, availNameWidth)var styledText string- if idx == m.registrySelected {+ if actualIdx == m.registrySelected {// Highlighted row is formatted entirely by selectedStyle/inactiveSelectedStyle, keep plainstyledText = truncatedPlain} else {@@ -1952,7 +1982,7 @@ func (m appModel) registryModalOverlay(layout appLayout) string {}line += rightPart- if idx == m.registrySelected {+ if actualIdx == m.registrySelected {var lineStyled stringif m.registryFocusList {lineStyled = selectedStyle.Render(rowIndent + padRight(prefix+truncatedPlain, rowWidth-rightPartWidth-1) + " " + rightPart)@@ -1964,9 +1994,19 @@ func (m appModel) registryModalOverlay(layout appLayout) string {leftContentLines = append(leftContentLines, line)}}+ if showScrollIndicator && resultSlots > 1 {+ parts := []string{}+ if start > 0 {+ parts = append(parts, fmt.Sprintf("↑ %d more", start))+ }+ if end < len(m.registryResults) {+ parts = append(parts, fmt.Sprintf("↓ %d more", len(m.registryResults)-end))+ }+ leftContentLines = append(leftContentLines, " "+dimStyle.Render(strings.Join(parts, " ")))+ }}- leftPane := fitLines(strings.Join(leftContentLines, "\n"), innerHeight)+ leftPane := clampBlockWidth(fitLines(strings.Join(leftContentLines, "\n"), innerHeight), leftWidth)// Right pane: detail preview / bulk detailsvar rightContentLines []string@@ -1983,7 +2023,7 @@ func (m appModel) registryModalOverlay(layout appLayout) string {}rightContentLines = append(rightContentLines,- titleStyle.Render("Preview/Details: "+s.DisplayName),+ titleStyle.Render(truncate("Preview/Details: "+s.DisplayName, rightWidth)),"",)@@ -2074,7 +2114,7 @@ func (m appModel) registryModalOverlay(layout appLayout) string {rightContentLines = append(rightContentLines, dimStyle.Render("Select a registry search result to view details."))}- rightPane := scrollableFitLines(strings.Join(rightContentLines, "\n"), innerHeight, m.registryPreviewOffset)+ rightPane := clampBlockWidth(scrollableFitLines(strings.Join(rightContentLines, "\n"), innerHeight, m.registryPreviewOffset), rightWidth)// Vertical dividervar dividerLines []string