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): show update recovery guidance
Alvin Unreal086fd368c2d4
diff --git a/cmd/lazyskills/main_test.go b/cmd/lazyskills/main_test.goindex de9c830..0aaf2be 100644--- a/cmd/lazyskills/main_test.go+++ b/cmd/lazyskills/main_test.go@@ -83,7 +83,7 @@ func TestCLIUpdate(t *testing.T) {}// Default channel should be "manual" on unix, or "windows" on windows.// Since we mock it, we just check if it returns one of the guidance/command values.- if !strings.Contains(out, "lazyskills update") && !strings.Contains(out, "To upgrade, please download") {+ if !strings.Contains(out, "lazyskills update") && !strings.Contains(out, "To upgrade, please download") && !strings.Contains(out, "Please download the release manually from") {t.Errorf("expected command preview or download guidance, got: %q", out)}diff --git a/internal/selfupdate/selfupdate.go b/internal/selfupdate/selfupdate.goindex 2064761..141f7f0 100644--- a/internal/selfupdate/selfupdate.go+++ b/internal/selfupdate/selfupdate.go@@ -658,3 +658,27 @@ func extractBinaryFromTarGz(tarGzBytes []byte, binaryName string) ([]byte, error}return nil, fmt.Errorf("binary %q not found in archive", binaryName)}++// RecoveryAdvice returns a suggested manual recovery instruction and command (or download URL)+// based on the installation channel and OS.+func RecoveryAdvice(channel string, goos string) (instruction string, command string) {+ switch channel {+ case "brew":+ return "To upgrade using Homebrew, run:", "brew upgrade --cask alvinunreal/tap/lazyskills"+ case "go", "dev":+ return "To rebuild from source, run:", "go install github.com/alvinunreal/lazyskills/cmd/lazyskills@latest"+ case "scoop":+ return "To upgrade using Scoop, run:", "scoop update lazyskills"+ case "winget":+ return "To upgrade using WinGet, run:", "winget upgrade --id alvinunreal.lazyskills"+ case "deb":+ return "To upgrade via apt, run:", "sudo apt update && sudo apt install --only-upgrade lazyskills"+ case "rpm":+ return "To upgrade via dnf, run:", "sudo dnf upgrade lazyskills"+ default:+ if goos == "windows" {+ return "To reinstall, run in PowerShell:", "irm https://lazyskills.sh/install.ps1 | iex"+ }+ return "To reinstall, run:", "curl -fsSL https://lazyskills.sh/install | sh"+ }+}diff --git a/internal/selfupdate/selfupdate_test.go b/internal/selfupdate/selfupdate_test.goindex 003ffc2..4d02a18 100644--- a/internal/selfupdate/selfupdate_test.go+++ b/internal/selfupdate/selfupdate_test.go@@ -10,6 +10,7 @@ import ("fmt""os""path/filepath"+ "runtime""strings""testing""time"@@ -228,7 +229,11 @@ func TestApplyAndChecksumMismatch(t *testing.T) {correctHashStr := fmt.Sprintf("%x", correctHash)// Write temp target executable paths- tmpDir, err := os.MkdirTemp("", "lazyskills-test-*")+ var parentDir string+ if home, err := os.UserHomeDir(); err == nil && home != "" {+ parentDir = home+ }+ tmpDir, err := os.MkdirTemp(parentDir, ".lazyskills-test-*")if err != nil {t.Fatalf("MkdirTemp failed: %v", err)}@@ -255,8 +260,11 @@ func TestApplyAndChecksumMismatch(t *testing.T) {TagName: "v1.1.0",}// We will determine our asset based on runtime OS/Arch- osName := "Linux"- archName := "x86_64"+ osName := strings.Title(runtime.GOOS)+ archName := runtime.GOARCH+ if archName == "amd64" {+ archName = "x86_64"+ }mockRel.Assets = append(mockRel.Assets, struct {Name string `json:"name"`BrowserDownloadURL string `json:"browser_download_url"`@@ -385,3 +393,36 @@ func TestApplyAndChecksumMismatch(t *testing.T) {t.Logf("skipping /var/tmp symlink safety test because /var/tmp is not writeable or available: %v", err)}}++func TestRecoveryAdvice(t *testing.T) {+ tests := []struct {+ channel string+ goos string+ wantInst string+ wantCmd string+ }{+ {"brew", "darwin", "To upgrade using Homebrew, run:", "brew upgrade --cask alvinunreal/tap/lazyskills"},+ {"brew", "linux", "To upgrade using Homebrew, run:", "brew upgrade --cask alvinunreal/tap/lazyskills"},+ {"scoop", "windows", "To upgrade using Scoop, run:", "scoop update lazyskills"},+ {"winget", "windows", "To upgrade using WinGet, run:", "winget upgrade --id alvinunreal.lazyskills"},+ {"deb", "linux", "To upgrade via apt, run:", "sudo apt update && sudo apt install --only-upgrade lazyskills"},+ {"rpm", "linux", "To upgrade via dnf, run:", "sudo dnf upgrade lazyskills"},+ {"go", "linux", "To rebuild from source, run:", "go install github.com/alvinunreal/lazyskills/cmd/lazyskills@latest"},+ {"dev", "linux", "To rebuild from source, run:", "go install github.com/alvinunreal/lazyskills/cmd/lazyskills@latest"},+ {"manual", "darwin", "To reinstall, run:", "curl -fsSL https://lazyskills.sh/install | sh"},+ {"manual", "linux", "To reinstall, run:", "curl -fsSL https://lazyskills.sh/install | sh"},+ {"manual", "windows", "To reinstall, run in PowerShell:", "irm https://lazyskills.sh/install.ps1 | iex"},+ {"windows", "windows", "To reinstall, run in PowerShell:", "irm https://lazyskills.sh/install.ps1 | iex"},+ {"unknown", "linux", "To reinstall, run:", "curl -fsSL https://lazyskills.sh/install | sh"},+ }++ for _, tt := range tests {+ t.Run(fmt.Sprintf("%s-%s", tt.channel, tt.goos), func(t *testing.T) {+ gotInst, gotCmd := RecoveryAdvice(tt.channel, tt.goos)+ if gotInst != tt.wantInst || gotCmd != tt.wantCmd {+ t.Errorf("RecoveryAdvice(%q, %q) = (%q, %q); want (%q, %q)",+ tt.channel, tt.goos, gotInst, gotCmd, tt.wantInst, tt.wantCmd)+ }+ })+ }+}diff --git a/internal/tui/update_test.go b/internal/tui/update_test.goindex bf621a1..b467cd1 100644--- a/internal/tui/update_test.go+++ b/internal/tui/update_test.go@@ -2,6 +2,7 @@ package tuiimport ("fmt"+ "runtime""strings""testing"@@ -186,3 +187,58 @@ func TestTUIAppUpdateModalStates(t *testing.T) {t.Errorf("expected error message to be surfaced, got: %s", viewOut)}}++func TestTUIAppUpdateModalFailureGuidance(t *testing.T) {+ t.Setenv("XDG_CACHE_HOME", t.TempDir())+ m := newModel("")+ m.width = 100+ m.height = 30+ m.updatePlan = &selfupdate.UpdatePlan{+ Current: "v1.0.0",+ Latest: "v1.1.0",+ Status: selfupdate.StatusAvailable,+ Channel: "manual",+ CanExecute: true,+ }++ // 1. Simulate update start+ modelTmp, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("U")})+ m = modelTmp.(appModel)++ // Simulate enter to start, then failure+ modelTmp, _ = m.Update(appUpdateResultMsg{err: fmt.Errorf("network disconnect")})+ m = modelTmp.(appModel)++ if !m.appUpdateModal {+ t.Fatal("expected modal to remain open on failure")+ }+ if m.updateError == nil || m.updateError.Error() != "network disconnect" {+ t.Errorf("expected updateError to be set to 'network disconnect', got: %v", m.updateError)+ }++ viewOut := m.View()+ if !strings.Contains(viewOut, "Update failed") {+ t.Errorf("expected Update failed heading, got: %s", viewOut)+ }+ if !strings.Contains(viewOut, "network disconnect") {+ t.Errorf("expected error message in view, got: %s", viewOut)+ }++ // Since we are running the test on the current runtime.GOOS, we check the expected recovery command.+ _, expectedCmd := selfupdate.RecoveryAdvice("manual", runtime.GOOS)+ if !strings.Contains(viewOut, expectedCmd) {+ t.Errorf("expected recovery command %q in view, got: %s", expectedCmd, viewOut)+ }++ // 2. Test with a different channel: package manager "brew"+ m.updateError = nil+ m.updatePlan.Channel = "brew"+ modelTmp, _ = m.Update(appUpdateResultMsg{err: fmt.Errorf("brew failure")})+ m = modelTmp.(appModel)++ viewOutBrew := m.View()+ _, expectedBrewCmd := selfupdate.RecoveryAdvice("brew", runtime.GOOS)+ if !strings.Contains(viewOutBrew, expectedBrewCmd) {+ t.Errorf("expected brew recovery command %q in view, got: %s", expectedBrewCmd, viewOutBrew)+ }+}diff --git a/internal/tui/view.go b/internal/tui/view.goindex ab3dcae..89baa24 100644--- a/internal/tui/view.go+++ b/internal/tui/view.go@@ -2,6 +2,7 @@ package tuiimport ("fmt"+ "runtime""strings""sync""time"@@ -1670,6 +1671,18 @@ func (m appModel) appUpdateModalOverlay(layout appLayout) string {sections = append(sections, errorStyle.Render("✗ Update failed:"))sections = append(sections, wrapText(m.updateError.Error(), modalWidth-4))sections = append(sections, "")++ var channel string+ if plan != nil {+ channel = plan.Channel+ }+ instruction, cmd := selfupdate.RecoveryAdvice(channel, runtime.GOOS)+ if cmd != "" {+ sections = append(sections, instruction)+ sections = append(sections, lipgloss.NewStyle().Foreground(lipgloss.Color("141")).Render(" "+cmd))+ sections = append(sections, "")+ }+sections = append(sections, dimStyle.Render("enter retry · esc/q close"))} else {if plan.CanExecute {