mission control for agent skills
Go agent-skillsagent-toolsai-agentsai-toolsai-workflowclaude-codeclicoding-agentscommand-line-tooldeveloper-toolsgoopencodeproductivity-toolsskill-discoveryskill-managementskillsterminal-appterminal-uituiworkflow-automation
Implement interactive source detail modal with child navigation and selection
alvinrealcbfc3025945f
diff --git a/internal/tui/tui.go b/internal/tui/tui.goindex 69c3483..1866d91 100644--- a/internal/tui/tui.go+++ b/internal/tui/tui.go@@ -93,6 +93,8 @@ type appModel struct {focus focusStatecollapsedGroups map[string]booldiscovery map[string]SourceDiscovery+ modalSelected int+ modalSource string}type paneLayout struct {@@ -239,6 +241,7 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {m.runningTitle = ""m.confirming = falsem.confirmInput = ""+ m.modalSource = ""m.actionResult = &msg.resultsucceeded := msg.result.ExitCode == 0 && msg.result.Err == ""if msg.mutates && succeeded {@@ -260,23 +263,75 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {switch key {case "esc", "q":m.detailModal = false+ m.modalSource = ""m.syncViewport()case "ctrl+c":return m, tea.Quitcase "o":- m.detailModal = false- return m.startCurrentSkillActionByID("open_skill")+ if m.modalSource != "" {+ child, ok := m.currentModalSelectedChild()+ if ok && !child.isAvailable {+ m.detailModal = false+ m.modalSource = ""+ return m.startSkillActionByID(child.skill, "open_skill")+ }+ } else {+ m.detailModal = false+ return m.startCurrentSkillActionByID("open_skill")+ }+ case "u":+ if m.modalSource != "" {+ child, ok := m.currentModalSelectedChild()+ if ok && !child.isAvailable {+ m.detailModal = false+ m.modalSource = ""+ return m.startSkillActionByID(child.skill, "reinstall_update")+ }+ }+ case "x":+ if m.modalSource != "" {+ child, ok := m.currentModalSelectedChild()+ if ok && !child.isAvailable {+ m.detailModal = false+ m.modalSource = ""+ return m.startSkillActionByID(child.skill, "remove")+ }+ }case "c":m.detailModal = falsem.commands = truem.action = 0m.syncViewport()case "down", "j":- m.viewport.LineDown(1)- m.clampViewportOffset()+ if m.modalSource != "" {+ childRows := m.modalChildRows(m.modalSource)+ if len(childRows) > 0 {+ m.modalSelected+++ if m.modalSelected >= len(childRows) {+ m.modalSelected = len(childRows) - 1+ }+ }+ m.ensureSourceModalSelectionVisible()+ m.syncViewport()+ } else {+ m.viewport.LineDown(1)+ m.clampViewportOffset()+ }case "up", "k":- m.viewport.LineUp(1)- m.clampViewportOffset()+ if m.modalSource != "" {+ childRows := m.modalChildRows(m.modalSource)+ if len(childRows) > 0 {+ m.modalSelected--+ if m.modalSelected < 0 {+ m.modalSelected = 0+ }+ }+ m.ensureSourceModalSelectionVisible()+ m.syncViewport()+ } else {+ m.viewport.LineUp(1)+ m.clampViewportOffset()+ }case "pgdown", "ctrl+d":var cmd tea.Cmdm.viewport, cmd = m.viewport.Update(msg)@@ -286,7 +341,13 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {m.viewport, cmd = m.viewport.Update(msg)return m, cmdcase "home":- m.viewport.GotoTop()+ if m.modalSource != "" {+ m.modalSelected = 0+ m.viewport.GotoTop()+ m.syncViewport()+ } else {+ m.viewport.GotoTop()+ }}return m, nil}@@ -367,6 +428,7 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {switch key {case "esc", "c":m.commands = false+ m.modalSource = ""case "q", "ctrl+c":return m, tea.Quitcase "up", "k":@@ -378,11 +440,19 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {case "enter":return m.startAction()case "o":- return m.startCurrentSkillActionByID("open_skill")+ return m.startActionByID("open_skill")case "u":- return m.startActionByID(preferredUpdateActionID(m.selectedCount()))+ actionID := preferredUpdateActionID(m.selectedCount())+ if m.modalSource != "" {+ actionID = "reinstall_update"+ }+ return m.startActionByID(actionID)case "x":- return m.startActionByID(preferredRemoveActionID(m.selectedCount()))+ actionID := preferredRemoveActionID(m.selectedCount())+ if m.modalSource != "" {+ actionID = "remove"+ }+ return m.startActionByID(actionID)}m.syncViewport()return m, nil@@ -423,10 +493,23 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {if len(rows) > 0 && m.selected < len(rows) {row := rows[m.selected]if row.isHeader {- if m.isCollapsed(row.groupName) {- m.expandGroup(row.groupName)- } else {- m.collapseGroup(row.groupName)+ m.detailModal = true+ m.modalSource = row.groupName+ m.modalSelected = 0+ m.detailsFocused = true+ m.viewport.GotoTop()+ m.syncViewport()++ groupName := row.groupName+ disc, exists := m.discovery[groupName]+ if !exists || (disc.Status != DiscoveryLoading && disc.Status != DiscoveryReady && disc.Status != DiscoveryFailed) {+ var cmd tea.Cmd+ var modelTmp tea.Model+ modelTmp, cmd = m.startDiscovery(groupName)+ m = modelTmp.(appModel)+ m.viewport.GotoTop()+ m.syncViewport()+ return m, cmd}} else if row.isAvailable {m.focus = focusPreview@@ -434,6 +517,8 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {m.syncViewport()} else {m.detailModal = true+ m.modalSource = ""+ m.modalSelected = 0m.detailsFocused = truem.viewport.GotoTop()m.syncViewport()@@ -637,6 +722,15 @@ func (m *appModel) clampAction() {}func (m appModel) currentActions() []actions.CommandPreview {+ if m.modalSource != "" {+ child, ok := m.currentModalSelectedChild()+ if ok {+ if child.isAvailable {+ return actions.ForAvailableSkill(m.modalSource, child.discoveredSkill.Name)+ }+ return actions.ForSkill(child.skill)+ }+ }selected := m.selectedSkills()if len(selected) > 0 {return actions.ForSkills(selected)@@ -689,6 +783,19 @@ func (m appModel) startActionByID(id string) (tea.Model, tea.Cmd) {return m, nil}+func (m appModel) startSkillActionByID(sk *model.Skill, id string) (tea.Model, tea.Cmd) {+ for _, action := range actions.ForSkill(sk) {+ if action.ID == id {+ if !action.Available {+ return m, nil+ }+ m.commands = false+ return m.executeAction(action)+ }+ }+ return m, nil+}+func (m appModel) startCurrentSkillActionByID(id string) (tea.Model, tea.Cmd) {rows := m.visibleRows()if len(rows) == 0 || m.selected < 0 || m.selected >= len(rows) {@@ -698,16 +805,48 @@ func (m appModel) startCurrentSkillActionByID(id string) (tea.Model, tea.Cmd) {if row.isHeader {return m, nil}- for _, action := range actions.ForSkill(row.skill) {- if action.ID == id {- if !action.Available {- return m, nil+ return m.startSkillActionByID(row.skill, id)+}++type modalChildRow struct {+ isAvailable bool+ skill *model.Skill+ discoveredSkill *DiscoveredSkill+}++func (m appModel) modalChildRows(groupName string) []modalChildRow {+ var rows []modalChildRow+ // 1. Installed skills+ for _, sk := range m.sourceGroupSkills(groupName) {+ rows = append(rows, modalChildRow{+ isAvailable: false,+ skill: sk,+ })+ }+ // 2. Available skills+ disc, ok := m.discovery[groupName]+ if ok && disc.Status == DiscoveryReady {+ for i, ds := range disc.Skills {+ if !m.isSkillInstalled(ds.Name, groupName) {+ rows = append(rows, modalChildRow{+ isAvailable: true,+ discoveredSkill: &disc.Skills[i],+ })}- m.commands = false- return m.executeAction(action)}}- return m, nil+ return rows+}++func (m appModel) currentModalSelectedChild() (modalChildRow, bool) {+ if m.modalSource == "" {+ return modalChildRow{}, false+ }+ childRows := m.modalChildRows(m.modalSource)+ if len(childRows) == 0 || m.modalSelected < 0 || m.modalSelected >= len(childRows) {+ return modalChildRow{}, false+ }+ return childRows[m.modalSelected], true}func preferredUpdateActionID(selectedCount int) string {@@ -1979,6 +2118,9 @@ func (m appModel) previewLines(width int) []string {}func (m appModel) detailLines(width int) []string {+ if m.modalSource != "" {+ return m.sourceModalDetailLines(width)+ }rows := m.visibleRows()if len(rows) == 0 || m.selected < 0 || m.selected >= len(rows) {return m.metadataLines(width)@@ -2003,6 +2145,209 @@ func (m appModel) detailLines(width int) []string {return lines}+func (m appModel) sourceModalDetailLines(width int) []string {+ groupName := m.modalSource+ visible, total := m.getGroupCounts(groupName)+ stateStr := "expanded"+ if m.isCollapsed(groupName) {+ stateStr = "collapsed"+ }++ skills := m.sourceGroupSkills(groupName)+ var folders, refs, hashes []string+ var projectCount, globalCount int+ var skillIssues []display.HealthIssueView++ for _, sk := range skills {+ info := sourceInfo(sk)+ if info.Folder != "" {+ folders = append(folders, info.Folder)+ }+ if info.Ref != "" {+ refs = append(refs, info.Ref)+ }+ var h string+ if sk.LocalLock != nil && sk.LocalLock.ComputedHash != "" {+ h = sk.LocalLock.ComputedHash+ } else if sk.GlobalLock != nil && sk.GlobalLock.SkillFolderHash != "" {+ h = sk.GlobalLock.SkillFolderHash+ }+ if h != "" {+ hashes = append(hashes, h)+ }+ if sk.Scope == model.ScopeProject {+ projectCount+++ } else if sk.Scope == model.ScopeGlobal {+ globalCount+++ }++ view := display.Skill(sk)+ skillIssues = append(skillIssues, view.HealthIssues...)+ }++ scopeStr := "mixed"+ if projectCount > 0 && globalCount == 0 {+ scopeStr = "project"+ } else if globalCount > 0 && projectCount == 0 {+ scopeStr = "global"+ } else if projectCount == 0 && globalCount == 0 {+ scopeStr = "unknown"+ }++ lines := []string{+ formatMetaLine("Source:", groupName, width),+ formatMetaLine("State:", stateStr, width),+ formatMetaLine("Skills:", fmt.Sprintf("%d visible / %d total", visible, total), width),+ formatMetaLine("Scope:", scopeStr, width),+ }++ if len(folders) > 0 {+ lines = append(lines, formatMetaLine("Folder:", folders[0], width))+ }+ if len(refs) > 0 {+ lines = append(lines, formatMetaLine("Ref:", refs[0], width))+ }+ if len(hashes) > 0 {+ lines = append(lines, formatMetaLine("Hash:", hashes[0], width))+ }++ healthStr := "healthy"+ if len(skillIssues) > 0 {+ healthStr = "issues detected"+ }+ lines = append(lines, formatMetaLine("Health:", healthStr, width))++ if len(skillIssues) > 0 {+ lines = append(lines, "", healthHeaderStyle.Render("Health Issues"))+ for _, issue := range skillIssues {+ line := fmt.Sprintf("- %s: %s", humanHealthIssueType(issue.Type), humanHealthIssueMessage(issue.Type, issue.Message))+ if issue.Path != "" {+ line += " (" + issue.Path + ")"+ }+ style := warningStyle+ if issue.Severity == "error" {+ style = errorStyle+ }+ lines = append(lines, style.Render(wrapText(line, width)))+ }+ }++ lines = append(lines, "")++ childRows := m.modalChildRows(groupName)++ lines = append(lines, sectionHeaderStyle.Render("Installed Skills:"))+ installedCount := 0+ for idx, cr := range childRows {+ if !cr.isAvailable {+ installedCount+++ scopeBadgeStr := "P"+ if cr.skill.Scope == model.ScopeGlobal {+ scopeBadgeStr = "G"+ }+ label := fmt.Sprintf("%s [%s]", cr.skill.Name, scopeBadgeStr)+ if idx == m.modalSelected {+ lines = append(lines, selectedStyle.Render(fmt.Sprintf("> %s", label)))+ } else {+ lines = append(lines, fmt.Sprintf(" %s", label))+ }+ }+ }+ if installedCount == 0 {+ lines = append(lines, " No installed skills under this source.")+ }++ lines = append(lines, "")++ lines = append(lines, sectionHeaderStyle.Render("Available Skills:"))+ disc, ok := m.discovery[groupName]+ if !ok {+ discoverable, reason := m.isSourceDiscoverable(groupName)+ if !discoverable {+ lines = append(lines, errorStyle.Render(" Discovery unavailable: "+reason))+ } else {+ lines = append(lines, dimStyle.Render(" Discovery pending..."))+ }+ } else {+ switch disc.Status {+ case DiscoveryLoading:+ lines = append(lines, dimStyle.Render(" Scanning/cloning source..."))+ case DiscoveryFailed:+ lines = append(lines, errorStyle.Render(" Discovery failed: "+disc.Error))+ case DiscoveryReady:+ availableCount := 0+ for idx, cr := range childRows {+ if cr.isAvailable {+ availableCount+++ label := fmt.Sprintf("%s [available]", cr.discoveredSkill.Name)+ if idx == m.modalSelected {+ lines = append(lines, selectedStyle.Render(fmt.Sprintf("> %s", label)))+ } else {+ lines = append(lines, fmt.Sprintf(" %s", label))+ }+ }+ }+ if availableCount == 0 {+ lines = append(lines, " All discovered skills from this source are installed.")+ }+ }+ }++ if len(childRows) > 0 && m.modalSelected >= 0 && m.modalSelected < len(childRows) {+ selectedChild := childRows[m.modalSelected]+ lines = append(lines, "")+ previewDivider := lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render(strings.Repeat("─", max(1, width)))+ lines = append(lines, previewDivider)++ if selectedChild.isAvailable {+ ds := selectedChild.discoveredSkill+ lines = append(lines,+ titleStyle.Render(ds.Name+" [available]"),+ "",+ formatMetaLine("Status:", "available", width),+ formatMetaLine("Source:", ds.Source, width),+ )+ if ds.SkillPath != "" {+ lines = append(lines, formatMetaLine("Path:", ds.SkillPath, width))+ }+ if ds.Description != "" {+ lines = append(lines, "", wrapText(ds.Description, width))+ }+ if ds.Preview != "" {+ lines = append(lines, "", sectionHeaderStyle.Render("Preview"), "")+ previewLines := strings.Split(ds.Preview, "\n")+ for _, line := range previewLines {+ lines = append(lines, wrapText(line, width))+ }+ }+ } else {+ sk := selectedChild.skill+ view := display.Skill(sk)+ lines = append(lines,+ titleStyle.Render(view.Name),+ "",+ formatMetaLine("Scope:", string(view.Scope), width),+ formatMetaLine("Lock:", display.LockSummary(view), width),+ )+ if sourceLines := sourceDetailLines(sk, width); len(sourceLines) > 0 {+ lines = append(lines, sourceLines...)+ }+ if view.CanonicalPath != "" {+ lines = append(lines, formatMetaLine("Canonical:", view.CanonicalPath, width))+ }+ if view.Preview != "" {+ lines = append(lines, "", sectionHeaderStyle.Render("Preview"), "")+ previewLines := strings.Split(view.Preview, "\n")+ for _, line := range previewLines {+ lines = append(lines, wrapText(line, width))+ }+ }+ }+ }++ return lines+}+func (m appModel) visibilitySummary(view display.SkillView, width int) []string {if len(view.Visibility) == 0 {return nil@@ -2251,7 +2596,7 @@ func (m appModel) footerText(width int) string {if len(rows) > 0 && m.selected >= 0 && m.selected < len(rows) {row := rows[m.selected]if row.isHeader {- text = "enter toggle · c source actions · h/- collapse · l/+ expand · d discover · ? help"+ text = "enter details · c source actions · h/- collapse · l/+ expand · d discover · ? help"} else if row.isAvailable {text = "enter preview · c install actions · ? help"} else {@@ -2291,7 +2636,7 @@ func (m appModel) helpModalOverlay(layout appLayout) string {" / Initiate text search","",sectionHeaderStyle.Render("Actions & Selection:"),- " enter Open detail modal (Skill) or toggle collapse (Source row)",+ " enter Open detail modal for the selected source or skill"," space Mark / unmark selected skill for bulk actions"," s Mark all skills in the current source group"," o Open selected skill directly in editor",@@ -2335,10 +2680,10 @@ func (m appModel) detailModalOverlay(layout appLayout) string {m.viewport.Height = modalHeight - 6m.viewport.SetContent(m.detailText(modalWidth - 4))- helpLine := dimStyle.Render("esc/q close · o open in editor · c command picker · ↑/↓ scroll")+ helpLine := dimStyle.Render(m.detailModalHelpLine())content := []string{- titleStyle.Render("Skill Detail View"),+ titleStyle.Render(m.detailModalTitle()),"",m.viewport.View(),"",@@ -2356,6 +2701,70 @@ func (m appModel) detailModalOverlay(layout appLayout) string {return fitToScreen(lipgloss.Place(layout.Width, layout.Height, lipgloss.Center, lipgloss.Center, box), layout.Width, layout.Height)}+func (m appModel) detailModalTitle() string {+ if m.modalSource != "" {+ return "Source Detail View"+ }+ rows := m.visibleRows()+ if len(rows) == 0 || m.selected < 0 || m.selected >= len(rows) {+ return "Detail View"+ }+ row := rows[m.selected]+ if row.isHeader {+ return "Source Detail View"+ }+ if row.isAvailable {+ return "Available Skill Detail View"+ }+ return "Skill Detail View"+}++func (m appModel) detailModalHelpLine() string {+ if m.modalSource != "" {+ return "esc/q close · ↑/↓ select skill · c actions · o/u/x installed actions"+ }+ rows := m.visibleRows()+ if len(rows) > 0 && m.selected >= 0 && m.selected < len(rows) && rows[m.selected].isAvailable {+ return "esc/q close · c install actions · ↑/↓ scroll"+ }+ return "esc/q close · o open in editor · c command picker · ↑/↓ scroll"+}++func (m *appModel) ensureSourceModalSelectionVisible() {+ if m.modalSource == "" {+ return+ }+ // The source modal renders source metadata before the child list. Keep a+ // little context above the selected child rather than treating modalSelected+ // as a raw viewport line number.+ selectedLine := 8 + m.modalSelected+ if selectedLine < 0 {+ selectedLine = 0+ }+ height := m.viewport.Height+ if height <= 0 {+ // View() computes the final modal viewport height. Use the same rough+ // default here so keyboard movement updates the offset before render.+ height = 18+ }+ if selectedLine < m.viewport.YOffset+3 {+ offset := selectedLine - 3+ if offset < 0 {+ offset = 0+ }+ m.viewport.SetYOffset(offset)+ return+ }+ bottom := m.viewport.YOffset + height - 4+ if selectedLine > bottom {+ offset := selectedLine - height + 4+ if offset < 0 {+ offset = 0+ }+ m.viewport.SetYOffset(offset)+ }+}+func (m appModel) confirmationOverlay(layout appLayout) string {actions := m.currentActions()title := "Confirm action"@@ -2996,7 +3405,68 @@ func rawSourceRef(skill *model.Skill) string {return ""}+func validateRawSource(raw string) error {+ if raw == "" {+ return fmt.Errorf("source is empty")+ }+ // Check for escapes, control characters, or newlines+ for _, r := range raw {+ if r < 32 || r == 127 || (r >= 128 && r <= 159) {+ return fmt.Errorf("raw source contains control, newline, or escape characters")+ }+ }+ // Also check if sanitization changes it+ if compat.SanitizeMetadata(raw) != raw {+ return fmt.Errorf("raw source contains unsafe characters or is modified by sanitization")+ }+ return nil+}++func (m appModel) validateRawSourcesForGroup(groupName string) error {+ skills := m.sourceGroupSkills(groupName)+ if len(skills) == 0 {+ return nil+ }+ for _, sk := range skills {+ var raw string+ var hasLock bool+ if sk.Scope == model.ScopeProject && sk.LocalLock != nil {+ raw = sk.LocalLock.Source+ hasLock = true+ } else if sk.Scope == model.ScopeGlobal && sk.GlobalLock != nil {+ hasLock = true+ if sk.GlobalLock.Source != "" {+ raw = sk.GlobalLock.Source+ } else {+ raw = sk.GlobalLock.SourceURL+ }+ } else {+ if sk.LocalLock != nil {+ raw = sk.LocalLock.Source+ hasLock = true+ } else if sk.GlobalLock != nil {+ hasLock = true+ if sk.GlobalLock.Source != "" {+ raw = sk.GlobalLock.Source+ } else {+ raw = sk.GlobalLock.SourceURL+ }+ }+ }+ if !hasLock {+ continue+ }+ if err := validateRawSource(raw); err != nil {+ return err+ }+ }+ return nil+}+func (m appModel) isSourceDiscoverable(group string) (bool, string) {+ if err := m.validateRawSourcesForGroup(group); err != nil {+ return false, err.Error()+ }if root := m.resolveGroupSourceRoot(group); root != "" {return true, ""}diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.goindex cfa71d9..aa75563 100644--- a/internal/tui/tui_test.go+++ b/internal/tui/tui_test.go@@ -8,6 +8,7 @@ import ("strings""testing"+ "github.com/charmbracelet/bubbles/viewport"tea "github.com/charmbracelet/bubbletea""github.com/charmbracelet/lipgloss"@@ -1302,7 +1303,7 @@ func TestContextualFooterAndHelpModal(t *testing.T) {// 1b. Source row selected footerm.selected = 0outHeaderFooter := m.View()- if !strings.Contains(outHeaderFooter, "enter toggle · c source actions") {+ if !strings.Contains(outHeaderFooter, "enter details · c source actions") {t.Fatalf("expected source group footer in View, got:\n%s", outHeaderFooter)}m.selected = 1@@ -1463,16 +1464,14 @@ func TestCollapseExpandSourceGroups(t *testing.T) {}}- // Test enter on header row toggles expand/collapse+ // Test enter on header row opens source detail modal without toggling collapse.updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyEnter})m = updated.(appModel)- if m.isCollapsed("owner/one") {- t.Fatal("expected enter on collapsed header to expand it")+ if !m.detailModal {+ t.Fatal("expected enter on header to open source detail modal")}- updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyEnter})- m = updated.(appModel)if !m.isCollapsed("owner/one") {- t.Fatal("expected enter on expanded header to collapse it")+ t.Fatal("expected enter on header not to change collapsed state")}}@@ -1915,3 +1914,367 @@ func TestRemoteDiscoveryRawFallbackRefBypass(t *testing.T) {t.Fatal("gitClone was called but it should not have been")}}++func TestInteractiveSourceDetailModal(t *testing.T) {+ t.Setenv("EDITOR", "nano")++ // Mock git clone+ oldGitClone := gitClone+ defer func() { gitClone = oldGitClone }()+ gitClone = func(url, ref, tempDir string) error {+ return nil+ }++ // 1. Set up model with a header/source row and one installed skill+ m := appModel{+ width: 120,+ height: 32,+ focus: focusSkills,+ collapsedGroups: make(map[string]bool),+ result: model.ScanResult{+ Skills: []*model.Skill{+ {+ Name: "InstalledSkill",+ Scope: model.ScopeProject,+ CanonicalPath: "/path/to/InstalledSkill",+ Description: "This is installed.",+ LocalLock: &model.LocalLockEntry{Source: "owner/repo", Ref: "main"},+ },+ },+ },+ }+ m.discovery = make(map[string]SourceDiscovery)++ // In visibleRows, index 0 is the header "owner/repo", and index 1 is "InstalledSkill"+ rows := m.visibleRows()+ if len(rows) < 2 || !rows[0].isHeader {+ t.Fatalf("expected first row to be header, got visibleRows: %+v", rows)+ }++ // Select the header row+ m.selected = 0++ // 2. Open source modal (triggers discovery command when not checked)+ updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter})+ m = updated.(appModel)+ if !m.detailModal {+ t.Fatal("expected enter on header to open detail modal")+ }+ if m.modalSource != "owner/repo" {+ t.Fatalf("expected modalSource to be owner/repo, got %q", m.modalSource)+ }+ if cmd == nil {+ t.Fatal("expected opening unchecked source modal to trigger discovery command")+ }++ // 3. Opening source modal does not repeatedly trigger discovery when already loading/ready/failed+ m.discovery["owner/repo"] = SourceDiscovery{Status: DiscoveryLoading}+ _, cmdLoading := m.Update(tea.KeyMsg{Type: tea.KeyEnter})+ if cmdLoading != nil {+ t.Fatal("expected opening loading source modal not to trigger discovery command again")+ }++ // Let's set it to ready with some available skills+ m.discovery["owner/repo"] = SourceDiscovery{+ Status: DiscoveryReady,+ Skills: []DiscoveredSkill{+ {Name: "InstalledSkill", Description: "This is installed.", Source: "owner/repo"},+ {Name: "AvailableSkill", Description: "This is available.", Source: "owner/repo"},+ },+ }++ // 4. Test j/k inside source modal changes modal child selection+ childRows := m.modalChildRows("owner/repo")+ if len(childRows) != 2 {+ t.Fatalf("expected 2 child rows (1 installed, 1 available), got %d", len(childRows))+ }+ if childRows[0].isAvailable || childRows[0].skill.Name != "InstalledSkill" {+ t.Fatalf("expected first child row to be InstalledSkill, got: %+v", childRows[0])+ }+ if !childRows[1].isAvailable || childRows[1].discoveredSkill.Name != "AvailableSkill" {+ t.Fatalf("expected second child row to be AvailableSkill, got: %+v", childRows[1])+ }++ if m.modalSelected != 0 {+ t.Fatalf("expected initial modalSelected to be 0, got %d", m.modalSelected)+ }++ // Press 'j' to go to next child row+ updatedJ, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'j'}})+ m = updatedJ.(appModel)+ if m.modalSelected != 1 {+ t.Fatalf("expected modalSelected to be 1 after pressing j, got %d", m.modalSelected)+ }++ // Press 'k' to go back to first child row+ updatedK, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'k'}})+ m = updatedK.(appModel)+ if m.modalSelected != 0 {+ t.Fatalf("expected modalSelected to be 0 after pressing k, got %d", m.modalSelected)+ }++ // 5. Test 'c' on installed child exposes installed skill actions+ m.modalSelected = 0 // installed child+ updatedC, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'c'}})+ mC := updatedC.(appModel)+ if mC.detailModal {+ t.Fatal("expected 'c' to close detailModal")+ }+ if !mC.commands {+ t.Fatal("expected 'c' to open commands picker")+ }+ acts := mC.currentActions()+ hasOpen := false+ hasRemove := false+ for _, act := range acts {+ if act.ID == "open_skill" {+ hasOpen = true+ }+ if act.ID == "remove" {+ hasRemove = true+ }+ }+ if !hasOpen || !hasRemove {+ t.Fatalf("expected installed child actions to include open and remove, got: %+v", acts)+ }++ // 6. Test 'c' on available child exposes install action+ m.modalSelected = 1 // available child+ m.detailModal = true // reopen modal for test+ m.commands = false+ updatedCAvail, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'c'}})+ mCAvail := updatedCAvail.(appModel)+ if mCAvail.detailModal {+ t.Fatal("expected 'c' to close detailModal")+ }+ if !mCAvail.commands {+ t.Fatal("expected 'c' to open commands picker")+ }+ actsAvail := mCAvail.currentActions()+ hasInstall := false+ for _, act := range actsAvail {+ if act.ID == "install_skill" {+ hasInstall = true+ }+ }+ if !hasInstall {+ t.Fatalf("expected available child actions to include install_skill, got: %+v", actsAvail)+ }++ // 7. Verify Source modal shows installed and available sections after discovery+ m.detailModal = true+ m.modalSelected = 0+ viewOut := m.View()+ if !strings.Contains(viewOut, "Installed Skills:") {+ t.Fatal("expected view to contain Installed Skills: section header")+ }+ if !strings.Contains(viewOut, "InstalledSkill [P]") {+ t.Fatal("expected view to contain InstalledSkill [P]")+ }+ if !strings.Contains(viewOut, "Available Skills:") {+ t.Fatal("expected view to contain Available Skills: section header")+ }+ if !strings.Contains(viewOut, "AvailableSkill [available]") {+ t.Fatal("expected view to contain AvailableSkill [available]")+ }+}++func TestSourceDetailModalSelectionScrollsIntoView(t *testing.T) {+ discovered := make([]DiscoveredSkill, 0, 30)+ for i := 0; i < 30; i++ {+ discovered = append(discovered, DiscoveredSkill{+ Name: fmt.Sprintf("Available%02d", i),+ Description: "available skill",+ Source: "owner/repo",+ })+ }+ m := appModel{+ width: 120,+ height: 24,+ focus: focusSkills,+ selected: 0,+ detailModal: true,+ modalSource: "owner/repo",+ modalSelected: 0,+ viewport: viewport.New(80, 8),+ collapsedGroups: make(map[string]bool),+ discovery: map[string]SourceDiscovery{+ "owner/repo": {Status: DiscoveryReady, Skills: discovered},+ },+ result: model.ScanResult{Skills: []*model.Skill{{+ Name: "InstalledSkill",+ Scope: model.ScopeProject,+ LocalLock: &model.LocalLockEntry{Source: "owner/repo"},+ }}},+ }++ for i := 0; i < 12; i++ {+ updated, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'j'}})+ m = updated.(appModel)+ }+ if m.modalSelected != 12 {+ t.Fatalf("expected modalSelected to follow j navigation, got %d", m.modalSelected)+ }+ if m.viewport.YOffset == 0 {+ t.Fatal("expected source modal viewport to scroll down as selection moves")+ }+}++func TestRawSourceValidationBeforeRemoteDiscovery(t *testing.T) {+ oldGitClone := gitClone+ defer func() { gitClone = oldGitClone }()++ calledClone := false+ gitClone = func(url, ref, tempDir string) error {+ calledClone = true+ return nil+ }++ // Case 1: LocalLock.Source contains controls/escapes+ m1 := appModel{+ width: 120, height: 32, selected: 0,+ result: model.ScanResult{+ Skills: []*model.Skill{+ {+ Name: "BadLocal",+ Scope: model.ScopeProject,+ LocalLock: &model.LocalLockEntry{Source: "owner/repo\x1b[31m", Ref: "main"},+ },+ },+ },+ }+ m1.discovery = make(map[string]SourceDiscovery)+ // Open detail modal on header row+ updated1, cmd1 := m1.Update(tea.KeyMsg{Type: tea.KeyEnter})+ m1 = updated1.(appModel)+ if !m1.detailModal {+ t.Fatal("expected detailModal to be open")+ }+ if cmd1 != nil {+ t.Fatal("expected no discovery command to be generated due to raw local source validation failure")+ }+ disc1 := m1.discovery["owner/repo"]+ if disc1.Status != DiscoveryFailed {+ t.Fatalf("expected discovery to fail, got status: %s", disc1.Status)+ }+ if !strings.Contains(disc1.Error, "raw source contains control, newline, or escape characters") {+ t.Fatalf("expected validation error message, got: %s", disc1.Error)+ }++ // Case 2: GlobalLock.SourceURL contains newline+ m2 := appModel{+ width: 120, height: 32, selected: 0,+ result: model.ScanResult{+ Skills: []*model.Skill{+ {+ Name: "BadGlobal",+ Scope: model.ScopeGlobal,+ GlobalLock: &model.GlobalLockEntry{SourceURL: "owner/repo\nnext", Ref: "main"},+ },+ },+ },+ }+ m2.discovery = make(map[string]SourceDiscovery)+ updated2, cmd2 := m2.Update(tea.KeyMsg{Type: tea.KeyEnter})+ m2 = updated2.(appModel)+ if !m2.detailModal {+ t.Fatal("expected detailModal to be open")+ }+ if cmd2 != nil {+ t.Fatal("expected no discovery command to be generated due to raw global source validation failure")+ }+ disc2 := m2.discovery["owner/repo next"]+ if disc2.Status != DiscoveryFailed {+ t.Fatalf("expected discovery to fail, got status: %s", disc2.Status)+ }+ if !strings.Contains(disc2.Error, "raw source contains control, newline, or escape characters") {+ t.Fatalf("expected validation error message, got: %s", disc2.Error)+ }++ // Case 3: LocalLock.Source contains trailing space (sanitization changes it)+ m3 := appModel{+ width: 120, height: 32, selected: 0,+ result: model.ScanResult{+ Skills: []*model.Skill{+ {+ Name: "BadLocalSpace",+ Scope: model.ScopeProject,+ LocalLock: &model.LocalLockEntry{Source: "owner/repo ", Ref: "main"},+ },+ },+ },+ }+ m3.discovery = make(map[string]SourceDiscovery)+ updated3, cmd3 := m3.Update(tea.KeyMsg{Type: tea.KeyEnter})+ m3 = updated3.(appModel)+ if !m3.detailModal {+ t.Fatal("expected detailModal to be open")+ }+ if cmd3 != nil {+ t.Fatal("expected no discovery command to be generated due to raw local source sanitization check failure")+ }+ disc3 := m3.discovery["owner/repo"]+ if disc3.Status != DiscoveryFailed {+ t.Fatalf("expected discovery to fail, got status: %s", disc3.Status)+ }+ if !strings.Contains(disc3.Error, "raw source contains unsafe characters or is modified by sanitization") {+ t.Fatalf("expected validation error message, got: %s", disc3.Error)+ }++ if calledClone {+ t.Fatal("gitClone was unexpectedly called")+ }+}++func TestModalCommandPickerUXWithBulkSelection(t *testing.T) {+ t.Setenv("EDITOR", "nano")++ // Set up model with a header/source row, one installed skill, bulk selectedKeys, source modal open, modal selected installed child, commands open.+ m := appModel{+ width: 120,+ height: 32,+ focus: focusSkills,+ collapsedGroups: make(map[string]bool),+ selectedKeys: map[string]bool{"InstalledSkill": true},+ detailModal: false,+ commands: true,+ modalSource: "owner/repo",+ modalSelected: 0,+ result: model.ScanResult{+ Skills: []*model.Skill{+ {+ Name: "InstalledSkill",+ Scope: model.ScopeProject,+ CanonicalPath: "/path/to/InstalledSkill",+ Description: "This is installed.",+ LocalLock: &model.LocalLockEntry{Source: "owner/repo", Ref: "main"},+ },+ },+ },+ }++ // Pressing 'u' should set reinstall_update (single-skill modal child action) instead of bulk+ updatedU, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'u'}})+ mU := updatedU.(appModel)+ if mU.confirming {+ actions := mU.currentActions()+ if len(actions) == 0 || mU.action >= len(actions) || actions[mU.action].ID != "reinstall_update" {+ t.Fatalf("expected reinstall_update action to be selected, got actions: %+v, selected action: %d", actions, mU.action)+ }+ } else {+ t.Fatal("expected update action to trigger confirmation overlay")+ }++ // Pressing 'x' should set remove instead of bulk+ m.confirming = false+ updatedX, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'x'}})+ mX := updatedX.(appModel)+ if mX.confirming {+ actions := mX.currentActions()+ if len(actions) == 0 || mX.action >= len(actions) || actions[mX.action].ID != "remove" {+ t.Fatalf("expected remove action to be selected, got actions: %+v, selected action: %d", actions, mX.action)+ }+ } else {+ t.Fatal("expected remove action to trigger confirmation overlay")+ }+}