mission control for agent skills
Go agent-skillsagent-toolsai-agentsai-toolsai-workflowclaude-codeclicoding-agentscommand-line-tooldeveloper-toolsgoopencodeproductivity-toolsskill-discoveryskill-managementskillsterminal-appterminal-uituiworkflow-automation
fix(tui): restore context after confirmation cancel
Alvin Unreal057e46027a31
diff --git a/internal/tui/tui.go b/internal/tui/tui.goindex 7e4b8df..a8a9f02 100644--- a/internal/tui/tui.go+++ b/internal/tui/tui.go@@ -97,6 +97,11 @@ type appModel struct {modalSource stringpendingG bool // saw a lone "g"; a second "g" jumps to toppendingAction *actions.CommandPreview // action awaiting confirm (decoupled from selection)+ confirmReturnDetailModal bool+ confirmReturnModalSource string+ confirmReturnModalSelected int+ confirmReturnModalYOffset int+ confirmReturnCommands boolupdatePlan *selfupdate.UpdatePlanupdatePlanErr errorappUpdateModal booldiff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.goindex 4c2e559..2b18c90 100644--- a/internal/tui/tui_test.go+++ b/internal/tui/tui_test.go@@ -2842,11 +2842,137 @@ func TestModalEnterInstallsAvailableSkill(t *testing.T) {if next.pendingAction.ID != "install_skill" {t.Fatalf("expected pending install_skill action, got %q", next.pendingAction.ID)}- // Cancel clears the pending action.+ // Cancel clears the pending action and restores the state of the detail modal.updated, _ = next.Update(tea.KeyMsg{Type: tea.KeyEsc})- if c := updated.(appModel); c.confirming || c.pendingAction != nil {+ c := updated.(appModel)+ if c.confirming || c.pendingAction != nil {t.Fatalf("expected esc to clear confirm, confirming=%v pending=%v", c.confirming, c.pendingAction)}+ if !c.detailModal {+ t.Fatal("expected esc to restore detailModal=true")+ }+ if c.modalSource != "owner/repo" {+ t.Fatalf("expected esc to restore modalSource=owner/repo, got %q", c.modalSource)+ }+ if c.modalSelected != 1 {+ t.Fatalf("expected esc to restore modalSelected=1, got %d", c.modalSelected)+ }+}++func TestModalEnterInstallsAvailableSkillSuccessPath(t *testing.T) {+ // Mock gitClone to do nothing+ oldGit := gitClone+ gitClone = func(url, ref, dir string) error { return nil }+ t.Cleanup(func() { gitClone = oldGit })++ m := appModel{width: 120, height: 32, detailModal: true, modalSource: "owner/repo", modalSelected: 1,+ result: model.ScanResult{Skills: []*model.Skill{+ {Name: "Installed", Scope: model.ScopeProject, LocalLock: &model.LocalLockEntry{Source: "owner/repo"}},+ }}}+ m.discovery = map[string]SourceDiscovery{+ "owner/repo": {Status: DiscoveryReady, Skills: []DiscoveredSkill{+ {Name: "Installed", Source: "owner/repo"},+ {Name: "Available", Source: "owner/repo"},+ }},+ }++ // Press Enter to go from detail modal to confirmation+ updated, _ := m.Update(tea.KeyMsg{Type: tea.KeyEnter})+ next := updated.(appModel)+ if !next.confirming {+ t.Fatal("expected confirmation to be active")+ }++ // Press Enter on confirmation screen to execute and succeed+ finalModel, cmd := next.Update(tea.KeyMsg{Type: tea.KeyEnter})+ f := finalModel.(appModel)+ if f.confirming || f.pendingAction != nil {+ t.Fatal("expected confirmation and pending action to be cleared")+ }+ if f.confirmReturnDetailModal {+ t.Fatal("expected confirmReturnDetailModal to be cleared on success")+ }+ if cmd == nil {+ t.Fatal("expected interactive cmd to be returned")+ }+ if !f.running {+ t.Fatal("expected f.running to be true")+ }+}++func TestModalCommandsMenuExitAndCancels(t *testing.T) {+ m := appModel{width: 120, height: 32, detailModal: true, modalSource: "owner/repo", modalSelected: 0,+ result: model.ScanResult{Skills: []*model.Skill{+ {Name: "Installed", Scope: model.ScopeProject, LocalLock: &model.LocalLockEntry{Source: "owner/repo"}},+ }}}+ m.discovery = map[string]SourceDiscovery{+ "owner/repo": {Status: DiscoveryReady, Skills: []DiscoveredSkill{+ {Name: "Installed", Source: "owner/repo"},+ }},+ }++ // 1. Press 'c' to open commands (action picker) from detail modal+ updated, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'c'}})+ next := updated.(appModel)+ if next.detailModal {+ t.Fatal("expected detailModal = false when opening commands")+ }+ if !next.commands {+ t.Fatal("expected commands = true when opening action picker")+ }+ if next.modalSource != "owner/repo" {+ t.Fatalf("expected modalSource preserve, got %q", next.modalSource)+ }++ // 2. Cancel commands menu with Esc -> should return to detailModal=true+ canceledCommands, _ := next.Update(tea.KeyMsg{Type: tea.KeyEsc})+ cc := canceledCommands.(appModel)+ if !cc.detailModal {+ t.Fatal("expected detailModal = true after canceling commands menu")+ }+ if cc.commands {+ t.Fatal("expected commands = false after canceling commands menu")+ }+ if cc.modalSource != "owner/repo" {+ t.Fatalf("expected modalSource restore, got %q", cc.modalSource)+ }++ // 3. Open commands menu again+ updated, _ = cc.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'c'}})+ next = updated.(appModel)++ // 4. Trigger "reinstall_update" using hotkey 'u' inside commands menu (which requires confirm)+ updated, _ = next.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'u'}})+ confirmState := updated.(appModel)+ if !confirmState.confirming {+ t.Fatal("expected hotkey 'u' in commands to arm confirmation")+ }+ if confirmState.commands {+ t.Fatal("expected commands = false when confirmation is active")+ }++ // 5. Cancel confirmation with Esc -> should return to commands menu+ canceledConfirm, _ := confirmState.Update(tea.KeyMsg{Type: tea.KeyEsc})+ cc2 := canceledConfirm.(appModel)+ if cc2.confirming {+ t.Fatal("expected confirming = false after cancel")+ }+ if !cc2.commands {+ t.Fatal("expected commands = true (returned to action picker)")+ }++ // 6. Cancel commands menu with Esc -> should return to detailModal+ finalModel, _ := cc2.Update(tea.KeyMsg{Type: tea.KeyEsc})+ fm := finalModel.(appModel)+ if !fm.detailModal {+ t.Fatal("expected final model to return to detailModal = true")+ }+ if fm.commands {+ t.Fatal("expected commands = false")+ }+ if fm.modalSource != "owner/repo" {+ t.Fatalf("expected modalSource = owner/repo, got %q", fm.modalSource)+ }}func TestSourceDetailModalSelectionScrollsIntoView(t *testing.T) {diff --git a/internal/tui/update.go b/internal/tui/update.goindex 8d3a136..933d529 100644--- a/internal/tui/update.go+++ b/internal/tui/update.go@@ -112,6 +112,11 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {m.confirming = falsem.confirmInput = ""m.modalSource = ""+ m.confirmReturnDetailModal = false+ m.confirmReturnModalSource = ""+ m.confirmReturnModalSelected = 0+ m.confirmReturnModalYOffset = 0+ m.confirmReturnCommands = falsem.actionResult = &msg.resultsucceeded := msg.result.ExitCode == 0 && msg.result.Err == ""if msg.mutates && succeeded {@@ -247,17 +252,23 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {if a.ID != "install_skill" || !a.Available {continue}- m.detailModal = false- m.modalSource = ""if a.RequiresConfirm {armed := am.pendingAction = &armedm.confirming = truem.confirmInput = ""m.confirmError = ""+ m.confirmReturnDetailModal = true+ m.confirmReturnModalSource = m.modalSource+ m.confirmReturnModalSelected = m.modalSelected+ m.confirmReturnModalYOffset = m.viewport.YOffset+ m.detailModal = false+ m.modalSource = ""m.syncViewport()return m, nil}+ m.detailModal = false+ m.modalSource = ""return m.executeAction(a)}} else {@@ -339,6 +350,30 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {m.confirmInput = ""m.confirmError = ""m.pendingAction = nil+ if m.confirmReturnDetailModal {+ m.detailModal = true+ m.modalSource = m.confirmReturnModalSource+ m.modalSelected = m.confirmReturnModalSelected+ m.viewport.SetYOffset(m.confirmReturnModalYOffset)+ m.ensureSourceModalSelectionVisible()++ m.confirmReturnDetailModal = false+ m.confirmReturnModalSource = ""+ m.confirmReturnModalSelected = 0+ m.confirmReturnModalYOffset = 0+ m.confirmReturnCommands = false+ } else if m.confirmReturnCommands {+ m.commands = true+ m.modalSource = m.confirmReturnModalSource+ m.modalSelected = m.confirmReturnModalSelected+ m.viewport.SetYOffset(m.confirmReturnModalYOffset)+ m.ensureSourceModalSelectionVisible()++ m.confirmReturnCommands = false+ m.confirmReturnModalSource = ""+ m.confirmReturnModalSelected = 0+ m.confirmReturnModalYOffset = 0+ }case "pgdown", "ctrl+d", "pgup", "ctrl+u":var cmd tea.Cmdm.viewport, cmd = m.viewport.Update(msg)@@ -395,7 +430,12 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {switch key {case "esc", "c":m.commands = false- m.modalSource = ""+ if m.modalSource != "" {+ m.detailModal = true+ m.ensureSourceModalSelectionVisible()+ } else {+ m.modalSource = ""+ }case "q", "ctrl+c":return m, tea.Quitcase "up", "k":@@ -863,6 +903,12 @@ func (m appModel) startActionByID(id string) (tea.Model, tea.Cmd) {for i, action := range m.currentActions() {if action.ID == id {m.action = i+ if m.commands {+ m.confirmReturnCommands = true+ m.confirmReturnModalSource = m.modalSource+ m.confirmReturnModalSelected = m.modalSelected+ m.confirmReturnModalYOffset = m.viewport.YOffset+ }m.commands = falsereturn m.startAction()}@@ -874,6 +920,12 @@ func (m appModel) startToggleAction() (tea.Model, tea.Cmd) {for i, action := range m.currentActions() {if (action.ID == "enable_skill" || action.ID == "disable_skill") && action.Available {m.action = i+ if m.commands {+ m.confirmReturnCommands = true+ m.confirmReturnModalSource = m.modalSource+ m.confirmReturnModalSelected = m.modalSelected+ m.confirmReturnModalYOffset = m.viewport.YOffset+ }m.commands = falsereturn m.startAction()}@@ -980,6 +1032,11 @@ func (m appModel) confirmAction() (tea.Model, tea.Cmd) {return m, nil}m.pendingAction = nil+ m.confirmReturnDetailModal = false+ m.confirmReturnModalSource = ""+ m.confirmReturnModalSelected = 0+ m.confirmReturnModalYOffset = 0+ m.confirmReturnCommands = falsereturn m.executeAction(action)}