diff --git a/cmd/skills.go b/cmd/skills.go index 7b8e0c5..26e5d02 100644 --- a/cmd/skills.go +++ b/cmd/skills.go @@ -14,7 +14,7 @@ import ( var skillsCmd = &cobra.Command{ Use: "skills", Short: "Manage Render agent skills for AI coding tools", - Long: `Install and manage Render agent skills for AI coding tools such as Claude Code, Codex, OpenCode, and Cursor. Skills add deployment, debugging, and monitoring capabilities to your AI coding assistant.`, + Long: `Install and manage Render agent skills for AI coding tools such as Claude Code, Codex, OpenCode, and Cursor (now Grok Build). Skills add deployment, debugging, and monitoring capabilities to your AI coding assistant.`, RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() if !command.IsInteractive(ctx) { diff --git a/cmd/skillsinstall.go b/cmd/skillsinstall.go index a2cf08a..d7c30e9 100644 --- a/cmd/skillsinstall.go +++ b/cmd/skillsinstall.go @@ -1,6 +1,9 @@ package cmd import ( + "os" + "path/filepath" + "github.com/spf13/cobra" "github.com/render-oss/cli/pkg/command" @@ -23,7 +26,7 @@ var skillsInstallCmd = &cobra.Command{ Short: "Install Render skills to AI coding tools", Long: `Install Render agent skills from https://github.com/render-oss/skills to detected AI coding tools. -Supported tools: Claude Code, Codex, OpenCode, Cursor. +Supported tools: Claude Code, Codex, OpenCode, Cursor (now Grok Build). Skills can be installed at two scopes: - user: Install to ~/.{tool}/skills/ (default, current user only) @@ -43,7 +46,7 @@ By default an interactive prompt lets you pick scope, tools, and skills. Use --s func init() { skillsCmd.AddCommand(skillsInstallCmd) - skillsInstallCmd.Flags().String("tool", "", "Install skills to a specific tool only (claude, codex, opencode, or cursor)") + skillsInstallCmd.Flags().String("tool", "", "Install skills to a specific tool only (claude, codex, opencode, cursor, or grok)") skillsInstallCmd.Flags().StringSlice("skill", nil, "Install specific skills only (use --skill multiple times)") skillsInstallCmd.Flags().Bool("dry-run", false, "Show what would be installed without making changes") skillsInstallCmd.Flags().String("scope", "", "Set installation scope to user or project (defaults to user)") @@ -76,11 +79,7 @@ func init() { Scope: scope, }) }, func(r *skills.InstallResult) string { - action := "Installed" - if r.DryRun { - action = "Would install" - } - return text.FormatStringF("%s %d skill(s) to %d tool(s)", action, len(r.Skills), len(r.Tools)) + return formatInstallResult(r, scope) }); err != nil { return err } else if nonInteractive { @@ -108,3 +107,32 @@ func interactiveSkillsInstall(cmd *cobra.Command, input SkillsInstallInput, scop Breadcrumb: "Install Skills", }) } + +// formatInstallResult describes an install for text output. With one tool it +// names the skills directory: relative to the current directory for project +// scope, and with ~ for the home directory otherwise. +func formatInstallResult(r *skills.InstallResult, scope skills.Scope) string { + action := "Installed" + if r.DryRun { + action = "Would install" + } + if len(r.Tools) != 1 { + return text.FormatStringF("%s %d skill(s) to %d tool(s)", action, len(r.Skills), len(r.Tools)) + } + + dir := r.Tools[0].SkillsDir + if scope == skills.ScopeProject { + if wd, err := os.Getwd(); err == nil { + // The repository root comes from git with symlinks resolved. + if resolved, err := filepath.EvalSymlinks(wd); err == nil { + wd = resolved + } + if rel, err := filepath.Rel(wd, dir); err == nil { + dir = rel + } + } + } else { + dir = skills.ShortenPath(dir) + } + return text.FormatStringF("%s %d skill(s) to %s", action, len(r.Skills), dir) +} diff --git a/cmd/skillsinstall_test.go b/cmd/skillsinstall_test.go new file mode 100644 index 0000000..b8ec1a5 --- /dev/null +++ b/cmd/skillsinstall_test.go @@ -0,0 +1,91 @@ +package cmd + +import ( + "os" + "path/filepath" + "runtime" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/render-oss/cli/pkg/skills" +) + +func TestFormatInstallResult(t *testing.T) { + home, err := os.UserHomeDir() + require.NoError(t, err) + repoRoot := t.TempDir() + t.Chdir(repoRoot) + + twoSkills := []skills.SkillInfo{{Name: "render-deploy"}, {Name: "render-debug"}} + userDir := filepath.Join(home, ".cursor", "skills") + projectDir := filepath.Join(repoRoot, ".grok", "skills") + shortUserDir := "~/.cursor/skills" + if runtime.GOOS == "windows" { + shortUserDir = userDir // ShortenPath leaves Windows paths unchanged + } + + tests := []struct { + name string + result skills.InstallResult + scope skills.Scope + want string + }{ + { + name: "one tool, user scope", + result: skills.InstallResult{Skills: twoSkills, Tools: []skills.Tool{{Name: "Grok Build", SkillsDir: userDir}}}, + scope: skills.ScopeUser, + want: "Installed 2 skill(s) to " + shortUserDir + "\n", + }, + { + name: "one tool, project scope", + result: skills.InstallResult{Skills: twoSkills, Tools: []skills.Tool{{Name: "Grok Build", SkillsDir: projectDir}}}, + scope: skills.ScopeProject, + want: "Installed 2 skill(s) to " + filepath.Join(".grok", "skills") + "\n", + }, + { + name: "dry run", + result: skills.InstallResult{Skills: twoSkills, Tools: []skills.Tool{{Name: "Grok Build", SkillsDir: projectDir}}, DryRun: true}, + scope: skills.ScopeProject, + want: "Would install 2 skill(s) to " + filepath.Join(".grok", "skills") + "\n", + }, + { + name: "several tools", + result: skills.InstallResult{Skills: twoSkills, Tools: []skills.Tool{ + {Name: "Claude Code", SkillsDir: filepath.Join(home, ".claude", "skills")}, + {Name: "Grok Build", SkillsDir: userDir}, + }}, + scope: skills.ScopeUser, + want: "Installed 2 skill(s) to 2 tool(s)\n", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.want, formatInstallResult(&tt.result, tt.scope)) + }) + } +} + +// The repository root comes from git with symlinks resolved, so a current +// directory reached through a symlink must be resolved too. +func TestFormatInstallResult_SymlinkedWorkingDirectory(t *testing.T) { + repoRoot, err := filepath.EvalSymlinks(t.TempDir()) + require.NoError(t, err) + require.NoError(t, os.MkdirAll(filepath.Join(repoRoot, "sub"), 0o755)) + link := filepath.Join(t.TempDir(), "link") + if err := os.Symlink(repoRoot, link); err != nil { + t.Skipf("symlinks unavailable: %v", err) + } + t.Chdir(filepath.Join(link, "sub")) + + result := skills.InstallResult{ + Skills: []skills.SkillInfo{{Name: "render-deploy"}}, + Tools: []skills.Tool{{Name: "Grok Build", SkillsDir: filepath.Join(repoRoot, ".grok", "skills")}}, + } + + got := formatInstallResult(&result, skills.ScopeProject) + + assert.Equal(t, "Installed 1 skill(s) to "+filepath.Join("..", ".grok", "skills")+"\n", got) +} diff --git a/cmd/skillsremove.go b/cmd/skillsremove.go index 0aa1e92..485e4fb 100644 --- a/cmd/skillsremove.go +++ b/cmd/skillsremove.go @@ -69,7 +69,7 @@ Use --scope to remove from a specific scope (user or project).`, func init() { skillsCmd.AddCommand(skillsRemoveCmd) skillsRemoveCmd.Flags().StringSlice("skill", nil, "Remove specific skills only (use --skill multiple times)") - skillsRemoveCmd.Flags().String("tool", "", "Remove skills from a specific tool only (claude, codex, opencode, or cursor)") + skillsRemoveCmd.Flags().String("tool", "", "Remove skills from a specific tool only (claude, codex, opencode, cursor, or grok)") skillsRemoveCmd.Flags().Bool("all", false, "Remove all installed Render skills") skillsRemoveCmd.Flags().String("scope", "", "Remove skills from the specified scope (user or project)") setFlagPlaceholder(skillsRemoveCmd.Flags(), "skill", "SKILL") @@ -121,10 +121,6 @@ func nonInteractiveSkillsRemove(cmd *cobra.Command, skillFilter []string, toolFi } // Filter tools. - detectedMap := make(map[string]skills.Tool, len(detectedTools)) - for _, t := range detectedTools { - detectedMap[t.Name] = t - } var selectedTools []skills.Tool if toolFilter != "" { selectedTools = skills.FilterTools(detectedTools, toolFilter) @@ -132,11 +128,7 @@ func nonInteractiveSkillsRemove(cmd *cobra.Command, skillFilter []string, toolFi return fmt.Errorf("no installed tool matching %q found", toolFilter) } } else { - for _, name := range state.Tools { - if t, ok := detectedMap[name]; ok { - selectedTools = append(selectedTools, t) - } - } + selectedTools = skills.IntersectToolsByState(detectedTools, state) } if len(selectedTools) == 0 { return fmt.Errorf("no matching tools found") diff --git a/pkg/skills/installer.go b/pkg/skills/installer.go index f1910a9..f8b6e76 100644 --- a/pkg/skills/installer.go +++ b/pkg/skills/installer.go @@ -8,6 +8,7 @@ import ( "io" "io/fs" "os" + "os/exec" "path/filepath" "runtime" "sort" @@ -21,6 +22,12 @@ const ( repoHTTPS = "https://github.com/render-oss/skills.git" ) +// Cursor is now Grok Build; saved names and --tool cursor still match it. +const ( + cursorName = "Cursor" + grokBuildName = "Grok Build" +) + // Tool represents an AI coding tool that supports skills. type Tool struct { Name string @@ -36,6 +43,14 @@ func DetectTools() ([]Tool, error) { return nil, fmt.Errorf("failed to determine home directory: %w", err) } + return detectTools(home, exec.LookPath), nil +} + +// detectTools implements DetectTools for the given home directory. lookPath +// finds an installed command, as exec.LookPath does. +func detectTools(home string, lookPath func(file string) (string, error)) []Tool { + cursorToolName, cursorDir := cursorTool(home, lookPath) + candidates := []struct { name string parentDir string @@ -58,7 +73,7 @@ func DetectTools() ([]Tool, error) { {"Command Code", filepath.Join(home, ".commandcode"), filepath.Join(home, ".commandcode", "skills")}, {"Continue", filepath.Join(home, ".continue"), filepath.Join(home, ".continue", "skills")}, {"Crush", filepath.Join(home, ".config", "crush"), filepath.Join(home, ".config", "crush", "skills")}, - {"Cursor", filepath.Join(home, ".cursor"), filepath.Join(home, ".cursor", "skills")}, + {cursorToolName, cursorDir, filepath.Join(cursorDir, "skills")}, {"Droid", filepath.Join(home, ".factory"), filepath.Join(home, ".factory", "skills")}, {"Gemini CLI", filepath.Join(home, ".gemini"), filepath.Join(home, ".gemini", "skills")}, {"GitHub Copilot", filepath.Join(home, ".copilot"), filepath.Join(home, ".copilot", "skills")}, @@ -103,7 +118,48 @@ func DetectTools() ([]Tool, error) { }) } - return tools, nil + return tools +} + +// cursorTool returns the name and config directory of Cursor, which is now +// Grok Build. The Grok Build desktop app keeps its files in ~/.cursor and +// installs a grok-build command; without that command, ~/.cursor is still +// detected as Cursor, even with the Grok CLI: it reads ~/.cursor/skills by +// default. The Grok CLI is recognized by ~/.grok/config.toml, since other +// tools also use ~/.grok. Render skills already in ~/.grok/skills keep Grok +// Build there either way. An empty parentDir means neither is present. +func cursorTool(home string, lookPath func(file string) (string, error)) (name, parentDir string) { + cursorDir := filepath.Join(home, ".cursor") + grokDir := filepath.Join(home, ".grok") + _, err := lookPath("grok-build") + hasGrokBuildCmd := err == nil + hasGrokSkills := hasRenderSkills(filepath.Join(grokDir, "skills")) + if !hasGrokBuildCmd && !hasGrokSkills && dirExists(cursorDir) { + return cursorName, cursorDir + } + if !dirExists(cursorDir) && !hasGrokSkills && !fileExists(filepath.Join(grokDir, "config.toml")) { + return grokBuildName, "" + } + return grokBuildName, grokBuildDir(home) +} + +// grokBuildDir returns the directory Grok Build's skills go in under root, a +// home directory or repository root. Grok Build reads skills from both .cursor +// and .grok, its CLI's own directory. Where root already has .cursor, it stays +// in use, unless Render skills are already in .grok/skills, so installed +// skills are neither left behind nor copied a second time. +func grokBuildDir(root string) string { + cursorDir := filepath.Join(root, ".cursor") + grokDir := filepath.Join(root, ".grok") + if dirExists(cursorDir) && !hasRenderSkills(filepath.Join(grokDir, "skills")) { + return cursorDir + } + return grokDir +} + +// hasRenderSkills reports whether skillsDir holds any installed Render skills. +func hasRenderSkills(skillsDir string) bool { + return len(DetectInstalledSkills(skillsDir)) > 0 } // FilterTools returns only the tools whose names contain the given filter @@ -112,13 +168,49 @@ func FilterTools(tools []Tool, filter string) []Tool { filter = strings.ToLower(filter) var filtered []Tool for _, t := range tools { - if strings.Contains(strings.ToLower(t.Name), filter) { + if matchesTool(t, filter) { filtered = append(filtered, t) } } return filtered } +// matchesTool reports whether filter (lowercase) is part of the tool's name; +// Grok Build also matches as Cursor. +func matchesTool(t Tool, filter string) bool { + names := []string{t.Name} + if savedToolName(t.Name) == cursorName { + names = []string{cursorName, grokBuildName} + } + for _, name := range names { + if strings.Contains(strings.ToLower(name), filter) { + return true + } + } + return false +} + +// LookupTool returns the tool with the given name. A tool name saved as Cursor +// finds Grok Build, and the other way around. +func LookupTool(tools []Tool, name string) (Tool, bool) { + for _, t := range tools { + if savedToolName(t.Name) == savedToolName(name) { + return t, true + } + } + return Tool{}, false +} + +// savedToolName returns the name a tool is saved under: Grok Build is saved +// as Cursor, so older versions of the CLI still find it, and the saved name +// doesn't depend on whether the grok-build command is on PATH. +func savedToolName(name string) string { + if name == grokBuildName { + return cursorName + } + return name +} + // CloneSkillsRepo performs a shallow clone of the render-oss/skills repo into // the given directory. The default branch is always used. func CloneSkillsRepo(destDir string) error { @@ -442,9 +534,9 @@ func ScanInstalledState(tools []Tool) (installed []InstalledSkill, toolNames []s if len(found) == 0 { continue } - if !toolSeen[t.Name] { - toolSeen[t.Name] = true - toolNames = append(toolNames, t.Name) + if name := savedToolName(t.Name); !toolSeen[name] { + toolSeen[name] = true + toolNames = append(toolNames, name) } for _, s := range found { key := "user:" + s.DirName @@ -469,9 +561,9 @@ func ScanInstalledState(tools []Tool) (installed []InstalledSkill, toolNames []s if len(found) == 0 { continue } - if !toolSeen[t.Name] { - toolSeen[t.Name] = true - toolNames = append(toolNames, t.Name) + if name := savedToolName(t.Name); !toolSeen[name] { + toolSeen[name] = true + toolNames = append(toolNames, name) } for _, s := range found { key := "project:" + s.DirName @@ -599,3 +691,8 @@ func dirExists(path string) bool { info, err := os.Stat(path) return err == nil && info.IsDir() } + +func fileExists(path string) bool { + info, err := os.Stat(path) + return err == nil && !info.IsDir() +} diff --git a/pkg/skills/installer_test.go b/pkg/skills/installer_test.go index ca430c3..cb2ebe0 100644 --- a/pkg/skills/installer_test.go +++ b/pkg/skills/installer_test.go @@ -1,8 +1,11 @@ package skills import ( + "fmt" "os" + "os/exec" "path/filepath" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -181,6 +184,156 @@ func TestFilterTools(t *testing.T) { result := FilterTools(tools, "vscode") assert.Empty(t, result) }) + + // Whether the tool is detected as Cursor or Grok Build depends on the + // grok-build command being on PATH, so both filters select it either way. + for _, name := range []string{"Cursor", "Grok Build"} { + t.Run("cursor and grok match "+name, func(t *testing.T) { + tools := []Tool{ + {Name: "Claude Code", SkillsDir: "/a"}, + {Name: name, SkillsDir: "/b"}, + } + for _, filter := range []string{"cursor", "grok"} { + result := FilterTools(tools, filter) + require.Len(t, result, 1, filter) + assert.Equal(t, name, result[0].Name, filter) + } + }) + } +} + +func TestDetectToolsCursorAndGrokBuild(t *testing.T) { + tests := []struct { + name string + paths []string // directories to create in the home directory, or files if they end in .toml + grokBuildCmd bool // whether the grok-build command is installed + wantName string // empty when neither Cursor nor Grok Build is detected + wantDir string // skills directory, relative to home + }{ + {"Cursor without Grok Build is unchanged", []string{".cursor"}, false, "Cursor", ".cursor/skills"}, + {"Cursor with the Grok CLI is unchanged", []string{".cursor", ".grok/config.toml"}, false, "Cursor", ".cursor/skills"}, + {"grok-build command renames Cursor", []string{".cursor"}, true, "Grok Build", ".cursor/skills"}, + {"grok-build command and the Grok CLI", []string{".cursor", ".grok/config.toml"}, true, "Grok Build", ".cursor/skills"}, + {"Grok CLI without Cursor", []string{".grok/config.toml"}, false, "Grok Build", ".grok/skills"}, + {"~/.grok without the Grok CLI's config", []string{".grok"}, false, "", ""}, + {"grok-build command and ~/.grok without the Grok CLI's config", []string{".grok"}, true, "", ""}, + {"grok-build command alone", nil, true, "", ""}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + home := t.TempDir() + for _, p := range tt.paths { + path := filepath.Join(home, filepath.FromSlash(p)) + if strings.HasSuffix(p, ".toml") { + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + require.NoError(t, os.WriteFile(path, nil, 0o644)) + continue + } + require.NoError(t, os.MkdirAll(path, 0o755)) + } + lookPath := func(file string) (string, error) { + if tt.grokBuildCmd && file == "grok-build" { + return filepath.Join("/usr/bin", file), nil + } + return "", exec.ErrNotFound + } + + var got []Tool + for _, tool := range detectTools(home, lookPath) { + if tool.Name == "Cursor" || tool.Name == "Grok Build" { + got = append(got, tool) + } + } + + if tt.wantName == "" { + assert.Empty(t, got) + return + } + want := Tool{Name: tt.wantName, SkillsDir: filepath.Join(home, filepath.FromSlash(tt.wantDir))} + assert.Equal(t, []Tool{want}, got) + }) + } + + // Detection creates the skills folder, so ~/.grok/skills must not be + // created for a ~/.grok that isn't the Grok CLI's. + t.Run("~/.grok without the Grok CLI's config gets no skills folder", func(t *testing.T) { + home := t.TempDir() + require.NoError(t, os.MkdirAll(filepath.Join(home, ".grok"), 0o755)) + + detectTools(home, func(string) (string, error) { return "", exec.ErrNotFound }) + + assert.NoDirExists(t, filepath.Join(home, ".grok", "skills")) + }) +} + +// Grok Build is saved under the name Cursor, so older versions of the CLI +// still find it, and the saved name doesn't depend on PATH. +func TestScanInstalledStateNamesGrokBuildCursor(t *testing.T) { + if _, err := exec.LookPath("git"); err != nil { + t.Skip("git not available") + } + writeSkill := func(skillsDir string) { + skillMD := filepath.Join(skillsDir, "render-deploy", "SKILL.md") + require.NoError(t, os.MkdirAll(filepath.Dir(skillMD), 0o755)) + require.NoError(t, os.WriteFile(skillMD, []byte("---\nname: render-deploy\n---\n"), 0o644)) + } + + for _, tc := range []struct { + name string + user, project bool + }{ + {"user scope", true, false}, + {"project scope", false, true}, + {"both scopes", true, true}, + } { + t.Run(tc.name, func(t *testing.T) { + repo := t.TempDir() + t.Chdir(repo) + require.NoError(t, exec.Command("git", "init", "-q").Run()) + userDir := t.TempDir() + if tc.user { + writeSkill(userDir) + } + if tc.project { + writeSkill(filepath.Join(repo, ".grok", "skills")) + } + + _, toolNames, _ := ScanInstalledState([]Tool{{Name: "Grok Build", SkillsDir: userDir}}) + + assert.Equal(t, []string{"Cursor"}, toolNames) + }) + } +} + +// Skills installed while only the Grok CLI was present stay in ~/.grok/skills +// after ~/.cursor appears, with or without the grok-build command. +func TestDetectToolsGrokBuildKeepsGrokSkills(t *testing.T) { + for _, grokBuildCmd := range []bool{true, false} { + t.Run(fmt.Sprintf("grok-build command %t", grokBuildCmd), func(t *testing.T) { + home := t.TempDir() + require.NoError(t, os.MkdirAll(filepath.Join(home, ".cursor"), 0o755)) + skillMD := filepath.Join(home, ".grok", "skills", "render-deploy", "SKILL.md") + require.NoError(t, os.MkdirAll(filepath.Dir(skillMD), 0o755)) + require.NoError(t, os.WriteFile(skillMD, []byte("---\nname: render-deploy\n---\n"), 0o644)) + lookPath := func(file string) (string, error) { + if grokBuildCmd && file == "grok-build" { + return filepath.Join("/usr/bin", file), nil + } + return "", exec.ErrNotFound + } + + var got []Tool + for _, tool := range detectTools(home, lookPath) { + if tool.Name == "Cursor" || tool.Name == "Grok Build" { + got = append(got, tool) + } + } + + want := Tool{Name: "Grok Build", SkillsDir: filepath.Join(home, ".grok", "skills")} + assert.Equal(t, []Tool{want}, got) + }) + } } func TestRemoveSkills(t *testing.T) { diff --git a/pkg/skills/listresult_test.go b/pkg/skills/listresult_test.go new file mode 100644 index 0000000..d26b5d6 --- /dev/null +++ b/pkg/skills/listresult_test.go @@ -0,0 +1,23 @@ +package skills + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +// skills.yaml from before the rename lists Cursor; once Cursor is detected as +// Grok Build, `render skills list -o text|json|yaml` still reports it as found. +func TestNewListResultFindsSavedCursorAsGrokBuild(t *testing.T) { + loaded := &LoadedState{ + State: &SkillsState{Tools: []string{"Cursor", "Windsurf"}}, + DetectedTools: []Tool{{Name: "Grok Build", SkillsDir: "/home/me/.cursor/skills"}}, + } + + result := NewListResult(loaded, "") + + assert.Equal(t, []ListedTool{ + {Name: "Grok Build", SkillsDir: "/home/me/.cursor/skills", Detected: true}, + {Name: "Windsurf", Detected: false}, + }, result.Tools) +} diff --git a/pkg/skills/scope.go b/pkg/skills/scope.go index bb1077a..b693686 100644 --- a/pkg/skills/scope.go +++ b/pkg/skills/scope.go @@ -76,6 +76,7 @@ var knownTools = map[string]ToolConfig{ "Gemini CLI": {Name: "Gemini CLI", ParentDir: ".gemini"}, "GitHub Copilot": {Name: "GitHub Copilot", ParentDir: ".copilot"}, "Goose": {Name: "Goose", ParentDir: ".config/goose"}, + "Grok Build": {Name: "Grok Build", ParentDir: ".grok"}, // or .cursor; see grokBuildDir "iFlow CLI": {Name: "iFlow CLI", ParentDir: ".iflow"}, "Junie": {Name: "Junie", ParentDir: ".junie"}, "Kilo Code": {Name: "Kilo Code", ParentDir: ".kilocode"}, @@ -112,6 +113,10 @@ func GetScopedSkillsDir(tool Tool, scope Scope, repoRoot string) string { return tool.SkillsDir } + if tool.Name == grokBuildName { + return filepath.Join(grokBuildDir(repoRoot), "skills") + } + // For project scope, compute the path from the tool name config, ok := GetToolConfig(tool.Name) if !ok { diff --git a/pkg/skills/scope_test.go b/pkg/skills/scope_test.go index 4cb832e..2080f07 100644 --- a/pkg/skills/scope_test.go +++ b/pkg/skills/scope_test.go @@ -1,8 +1,12 @@ package skills import ( + "os" "path/filepath" "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestScopeIsValid(t *testing.T) { @@ -62,6 +66,7 @@ func TestGetToolConfig(t *testing.T) { }{ {"Claude Code exists", "Claude Code", true}, {"Cursor exists", "Cursor", true}, + {"Grok Build exists", "Grok Build", true}, {"Unknown tool", "Unknown Tool", false}, } @@ -95,3 +100,41 @@ func TestGetScopedSkillsDir(t *testing.T) { t.Errorf("GetScopedSkillsDir(project) = %q, want %q", projectDir, expected) } } + +func TestGetScopedSkillsDirGrokBuildProject(t *testing.T) { + grokBuild := Tool{Name: "Grok Build", SkillsDir: "/home/user/.cursor/skills"} + + tests := []struct { + name string + dirs []string // directories to create in the repository + files []string // files to create in the repository + want string // skills directory, relative to the repository root + }{ + {name: "no .cursor uses .grok", want: ".grok/skills"}, + {name: "existing .cursor stays in use", dirs: []string{".cursor"}, want: ".cursor/skills"}, + { + name: "Render skills already in .grok stay there", + dirs: []string{".cursor"}, + files: []string{".grok/skills/render-deploy/SKILL.md"}, + want: ".grok/skills", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + repoRoot := t.TempDir() + for _, dir := range tt.dirs { + require.NoError(t, os.MkdirAll(filepath.Join(repoRoot, dir), 0o755)) + } + for _, file := range tt.files { + path := filepath.Join(repoRoot, filepath.FromSlash(file)) + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + require.NoError(t, os.WriteFile(path, []byte("---\nname: render-deploy\n---\n"), 0o644)) + } + + got := GetScopedSkillsDir(grokBuild, ScopeProject, repoRoot) + + assert.Equal(t, filepath.Join(repoRoot, filepath.FromSlash(tt.want)), got) + }) + } +} diff --git a/pkg/skills/service.go b/pkg/skills/service.go index 42913ef..4259808 100644 --- a/pkg/skills/service.go +++ b/pkg/skills/service.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "slices" "strings" ) @@ -128,9 +129,11 @@ func Install(input InstallInput) (*InstallResult, error) { selectedSkills = available } + scopedTools := ScopedTools(selectedTools, scope, repoRoot) + result := &InstallResult{ Skills: selectedSkills, - Tools: selectedTools, + Tools: scopedTools, DryRun: input.DryRun, } @@ -144,9 +147,8 @@ func Install(input InstallInput) (*InstallResult, error) { var installErrors []string successCount := 0 - for _, t := range selectedTools { - // Get the appropriate skills directory based on scope - skillsDir := GetScopedSkillsDir(t, scope, repoRoot) + for _, t := range scopedTools { + skillsDir := t.SkillsDir // For project scope, ensure the directory exists if scope == ScopeProject { @@ -216,13 +218,14 @@ func SaveInstallStateWithScope(installed []SkillInfo, selectedTools []Tool, tmpD } merged = append(merged, newSkills...) - // Merge tool names (union of existing and newly selected). + // Merge tool names (union of existing and newly selected), saving Grok + // Build as Cursor. toolSet := make(map[string]bool) for _, name := range existing.Tools { - toolSet[name] = true + toolSet[savedToolName(name)] = true } for _, name := range ToolNames(selectedTools) { - toolSet[name] = true + toolSet[savedToolName(name)] = true } var mergedTools []string for name := range toolSet { @@ -313,9 +316,9 @@ func ExecuteInstallWithScope(tools []Tool, skillNames []string, tmpDir string, s var installErrors []string successCount := 0 - for _, t := range tools { - // Get the appropriate skills directory based on scope - skillsDir := GetScopedSkillsDir(t, scope, repoRoot) + scopedTools := ScopedTools(tools, scope, repoRoot) + for _, t := range scopedTools { + skillsDir := t.SkillsDir // For project scope, ensure the directory exists if scope == ScopeProject { @@ -343,11 +346,20 @@ func ExecuteInstallWithScope(tools []Tool, skillNames []string, tmpDir string, s return &InstallResult{ Skills: lastInstalled, - Tools: tools, + Tools: scopedTools, DryRun: false, }, nil } +// ScopedTools returns the tools with each skills directory set for scope. +func ScopedTools(tools []Tool, scope Scope, repoRoot string) []Tool { + scoped := make([]Tool, len(tools)) + for i, t := range tools { + scoped[i] = Tool{Name: t.Name, SkillsDir: GetScopedSkillsDir(t, scope, repoRoot)} + } + return scoped +} + // ── State Loading ──────────────────────────────────────────────────────────── // LoadedState holds the result of loading skills state with fallback detection. @@ -409,11 +421,6 @@ type ListedTool struct { // NewListResult reports the installed skills at scope (all scopes when // empty) and the tools they were installed to. func NewListResult(loaded *LoadedState, scope Scope) *ListResult { - detected := make(map[string]Tool, len(loaded.DetectedTools)) - for _, t := range loaded.DetectedTools { - detected[t.Name] = t - } - result := &ListResult{ Skills: loaded.State.SkillsInScope(scope), Tools: []ListedTool{}, @@ -424,8 +431,11 @@ func NewListResult(loaded *LoadedState, scope Scope) *ListResult { result.Skills = []InstalledSkill{} } for _, name := range loaded.State.Tools { - t, ok := detected[name] - result.Tools = append(result.Tools, ListedTool{Name: name, SkillsDir: t.SkillsDir, Detected: ok}) + t, ok := LookupTool(loaded.DetectedTools, name) + if !ok { + t.Name = name + } + result.Tools = append(result.Tools, ListedTool{Name: t.Name, SkillsDir: t.SkillsDir, Detected: ok}) } return result } @@ -472,16 +482,12 @@ func ResolveInstalledSkillNames(installedSkills []InstalledSkill, names []string // ── Tool Helpers ───────────────────────────────────────────────────────────── -// IntersectToolsByState returns only the detected tools that match the state's tool names. +// IntersectToolsByState returns only the detected tools that match the state's +// tool names, each once. func IntersectToolsByState(detectedTools []Tool, state *SkillsState) []Tool { - detectedMap := make(map[string]Tool, len(detectedTools)) - for _, t := range detectedTools { - detectedMap[t.Name] = t - } - var selected []Tool for _, name := range state.Tools { - if t, ok := detectedMap[name]; ok { + if t, ok := LookupTool(detectedTools, name); ok && !slices.Contains(selected, t) { selected = append(selected, t) } } diff --git a/pkg/skills/service_test.go b/pkg/skills/service_test.go new file mode 100644 index 0000000..c06afb8 --- /dev/null +++ b/pkg/skills/service_test.go @@ -0,0 +1,80 @@ +package skills + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestIntersectToolsByState(t *testing.T) { + claude := Tool{Name: "Claude Code", SkillsDir: "/a"} + + t.Run("matches saved names", func(t *testing.T) { + state := &SkillsState{Tools: []string{"Claude Code", "Windsurf"}} + assert.Equal(t, []Tool{claude}, IntersectToolsByState([]Tool{claude}, state)) + }) + + t.Run("Cursor matches Grok Build", func(t *testing.T) { + grokBuild := Tool{Name: "Grok Build", SkillsDir: "/b"} + state := &SkillsState{Tools: []string{"Cursor"}} + assert.Equal(t, []Tool{grokBuild}, IntersectToolsByState([]Tool{claude, grokBuild}, state)) + }) + + t.Run("both names match Grok Build once", func(t *testing.T) { + grokBuild := Tool{Name: "Grok Build", SkillsDir: "/b"} + state := &SkillsState{Tools: []string{"Cursor", "Grok Build"}} + assert.Equal(t, []Tool{grokBuild}, IntersectToolsByState([]Tool{claude, grokBuild}, state)) + }) + + t.Run("Grok Build matches Cursor", func(t *testing.T) { + cursor := Tool{Name: "Cursor", SkillsDir: "/b"} + state := &SkillsState{Tools: []string{"Grok Build"}} + assert.Equal(t, []Tool{cursor}, IntersectToolsByState([]Tool{claude, cursor}, state)) + }) +} + +// Grok Build is saved under the name Cursor, so older versions of the CLI +// still find it, and the saved name doesn't depend on PATH. +func TestSaveInstallStateSavesGrokBuildAsCursor(t *testing.T) { + for _, tc := range []struct { + name string + existing []string + want []string + }{ + {"no state", nil, []string{"Cursor"}}, + {"saved as Cursor", []string{"Claude Code", "Cursor"}, []string{"Claude Code", "Cursor"}}, + {"saved as Grok Build", []string{"Grok Build"}, []string{"Cursor"}}, + } { + t.Run(tc.name, func(t *testing.T) { + dir := t.TempDir() + origPath := defaultStatePath + defaultStatePath = filepath.Join(dir, "skills.yaml") + t.Cleanup(func() { defaultStatePath = origPath }) + if tc.existing != nil { + require.NoError(t, (&SkillsState{Tools: tc.existing}).Save()) + } + + SaveInstallStateWithScope(nil, []Tool{{Name: "Grok Build", SkillsDir: "/b"}}, dir, ScopeUser) + + loaded, err := LoadState() + require.NoError(t, err) + assert.ElementsMatch(t, tc.want, loaded.Tools) + }) + } +} + +func TestScopedTools(t *testing.T) { + repoRoot := t.TempDir() + tools := []Tool{ + {Name: "Claude Code", SkillsDir: "/home/me/.claude/skills"}, + {Name: "Grok Build", SkillsDir: "/home/me/.cursor/skills"}, + } + + assert.Equal(t, tools, ScopedTools(tools, ScopeUser, repoRoot)) + assert.Equal(t, []Tool{ + {Name: "Claude Code", SkillsDir: filepath.Join(repoRoot, ".claude", "skills")}, + {Name: "Grok Build", SkillsDir: filepath.Join(repoRoot, ".grok", "skills")}, + }, ScopedTools(tools, ScopeProject, repoRoot)) +} diff --git a/pkg/tui/views/skillslist.go b/pkg/tui/views/skillslist.go index a942606..04e5c47 100644 --- a/pkg/tui/views/skillslist.go +++ b/pkg/tui/views/skillslist.go @@ -164,14 +164,9 @@ func RenderSkillsList(loaded *skills.LoadedState, scope skills.Scope) string { sb.WriteString("\n") // ── Tools ─────────────────────────────────────────────────────────── - detectedMap := make(map[string]skills.Tool, len(loaded.DetectedTools)) - for _, t := range loaded.DetectedTools { - detectedMap[t.Name] = t - } - sb.WriteString("Tools:\n\n") for _, name := range state.Tools { - if t, ok := detectedMap[name]; ok { + if t, ok := skills.LookupTool(loaded.DetectedTools, name); ok { fmt.Fprintf(&sb, " %s %s %s\n", iconCheck(), renderstyle.Bold(t.Name), dim.Render(skills.ShortenPath(t.SkillsDir))) } else { fmt.Fprintf(&sb, " %s %s %s\n", iconCross(), renderstyle.Bold(name), dim.Render("(not detected)"))