From 6a99d3edc93d91639d782ffbdb6fed1b533cd344 Mon Sep 17 00:00:00 2001 From: David Bruck <1393236+gorban@users.noreply.github.com> Date: Thu, 3 Dec 2026 15:49:43 -0600 Subject: [PATCH 1/6] Add tests for detecting Grok Build, the new name for Cursor Move DetectTools' body into detectTools, which takes the home directory and a command lookup, so tests can control both. Behavior is unchanged. The new tests cover when Cursor is detected as Grok Build, --tool cursor and --tool grok, saved tool names under either name, and Grok Build's project skills directory. The Cursor-only cases pass; the Grok Build cases fail until it is supported. Refs #81 --- pkg/skills/installer.go | 9 +++++- pkg/skills/installer_test.go | 59 +++++++++++++++++++++++++++++++++++ pkg/skills/listresult_test.go | 23 ++++++++++++++ pkg/skills/scope_test.go | 9 ++++++ pkg/skills/service_test.go | 51 ++++++++++++++++++++++++++++++ 5 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 pkg/skills/listresult_test.go create mode 100644 pkg/skills/service_test.go diff --git a/pkg/skills/installer.go b/pkg/skills/installer.go index f1910a9b..4951a3e7 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" @@ -36,6 +37,12 @@ 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 { candidates := []struct { name string parentDir string @@ -103,7 +110,7 @@ func DetectTools() ([]Tool, error) { }) } - return tools, nil + return tools } // FilterTools returns only the tools whose names contain the given filter diff --git a/pkg/skills/installer_test.go b/pkg/skills/installer_test.go index ca430c32..5ff250e7 100644 --- a/pkg/skills/installer_test.go +++ b/pkg/skills/installer_test.go @@ -2,6 +2,7 @@ package skills import ( "os" + "os/exec" "path/filepath" "testing" @@ -181,6 +182,64 @@ func TestFilterTools(t *testing.T) { result := FilterTools(tools, "vscode") assert.Empty(t, result) }) + + t.Run("cursor and grok match Grok Build", func(t *testing.T) { + tools := []Tool{ + {Name: "Claude Code", SkillsDir: "/a"}, + {Name: "Grok Build", SkillsDir: "/b"}, + } + for _, filter := range []string{"cursor", "grok"} { + result := FilterTools(tools, filter) + require.Len(t, result, 1, filter) + assert.Equal(t, "Grok Build", result[0].Name, filter) + } + }) +} + +func TestDetectToolsCursorAndGrokBuild(t *testing.T) { + tests := []struct { + name string + dirs []string // directories to create in the home directory + 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"}, 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"}, true, "Grok Build", ".cursor/skills"}, + {"Grok CLI without Cursor", []string{".grok"}, false, "Grok Build", ".grok/skills"}, + {"grok-build command alone", nil, true, "", ""}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + home := t.TempDir() + for _, dir := range tt.dirs { + require.NoError(t, os.MkdirAll(filepath.Join(home, dir), 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) + }) + } } func TestRemoveSkills(t *testing.T) { diff --git a/pkg/skills/listresult_test.go b/pkg/skills/listresult_test.go new file mode 100644 index 00000000..d26b5d6a --- /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_test.go b/pkg/skills/scope_test.go index 4cb832e7..ec77eb3d 100644 --- a/pkg/skills/scope_test.go +++ b/pkg/skills/scope_test.go @@ -62,6 +62,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}, } @@ -94,4 +95,12 @@ func TestGetScopedSkillsDir(t *testing.T) { if projectDir != expected { t.Errorf("GetScopedSkillsDir(project) = %q, want %q", projectDir, expected) } + + // Grok Build's project skills stay in .cursor/skills, wherever its user skills are + grokBuild := Tool{Name: "Grok Build", SkillsDir: "/home/user/.grok/skills"} + projectDir = GetScopedSkillsDir(grokBuild, ScopeProject, repoRoot) + expected = filepath.Join(repoRoot, ".cursor", "skills") + if projectDir != expected { + t.Errorf("GetScopedSkillsDir(Grok Build, project) = %q, want %q", projectDir, expected) + } } diff --git a/pkg/skills/service_test.go b/pkg/skills/service_test.go new file mode 100644 index 00000000..ff5d73fa --- /dev/null +++ b/pkg/skills/service_test.go @@ -0,0 +1,51 @@ +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)) + }) +} + +func TestSaveInstallStateReplacesCursorWithGrokBuild(t *testing.T) { + dir := t.TempDir() + origPath := defaultStatePath + defaultStatePath = filepath.Join(dir, "skills.yaml") + t.Cleanup(func() { defaultStatePath = origPath }) + + require.NoError(t, (&SkillsState{Tools: []string{"Claude Code", "Cursor"}}).Save()) + + SaveInstallStateWithScope(nil, []Tool{{Name: "Grok Build", SkillsDir: "/b"}}, dir, ScopeUser) + + loaded, err := LoadState() + require.NoError(t, err) + assert.ElementsMatch(t, []string{"Claude Code", "Grok Build"}, loaded.Tools) +} From 50bb058dba3872299643feccbf216a7531761d93 Mon Sep 17 00:00:00 2001 From: David Bruck <1393236+gorban@users.noreply.github.com> Date: Thu, 3 Dec 2026 15:54:25 -0600 Subject: [PATCH 2/6] Detect Grok Build, the new name for Cursor Cursor is now Grok Build. Its desktop app still keeps its files in ~/.cursor and installs a grok-build command. - With ~/.cursor and the grok-build command, render skills lists Grok Build in place of Cursor and keeps using ~/.cursor/skills. - With ~/.cursor and no grok-build command, Cursor is detected as before, even if ~/.grok exists: the Grok CLI reads ~/.cursor/skills by default, and other tools also use ~/.grok. - With ~/.grok and no ~/.cursor, Grok Build uses ~/.grok/skills. Project skills stay in .cursor/skills. Skills are never moved, so this change adds no second copy. --tool cursor and --tool grok both select Grok Build. Tool names saved as Cursor still match it, so update, remove and list keep finding existing installs, and a new install saves the new name in their place. Fixes #81 --- cmd/skills.go | 2 +- cmd/skillsinstall.go | 4 +-- cmd/skillsremove.go | 12 ++------ pkg/skills/installer.go | 59 +++++++++++++++++++++++++++++++++++-- pkg/skills/scope.go | 1 + pkg/skills/service.go | 30 +++++++++---------- pkg/tui/views/skillslist.go | 7 +---- 7 files changed, 78 insertions(+), 37 deletions(-) diff --git a/cmd/skills.go b/cmd/skills.go index 7b8e0c57..26e5d02d 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 a2cf08ab..eb338765 100644 --- a/cmd/skillsinstall.go +++ b/cmd/skillsinstall.go @@ -23,7 +23,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 +43,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)") diff --git a/cmd/skillsremove.go b/cmd/skillsremove.go index 0aa1e924..485e4fb0 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 4951a3e7..29ec75fc 100644 --- a/pkg/skills/installer.go +++ b/pkg/skills/installer.go @@ -22,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 @@ -43,6 +49,8 @@ func DetectTools() ([]Tool, error) { // 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 @@ -65,7 +73,7 @@ func detectTools(home string, lookPath func(file string) (string, error)) []Tool {"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")}, @@ -113,19 +121,66 @@ func detectTools(home string, lookPath func(file string) (string, error)) []Tool 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 detected as +// before, even if ~/.grok exists: the Grok CLI reads ~/.cursor/skills by +// default, and other tools also use ~/.grok. Only without ~/.cursor does Grok +// Build use ~/.grok, the Grok CLI's own directory. +func cursorTool(home string, lookPath func(file string) (string, error)) (name, parentDir string) { + cursorDir := filepath.Join(home, ".cursor") + grokDir := filepath.Join(home, ".grok") + if !dirExists(cursorDir) && dirExists(grokDir) { + return grokBuildName, grokDir + } + if _, err := lookPath("grok-build"); err == nil { + return grokBuildName, cursorDir + } + return cursorName, cursorDir +} + // FilterTools returns only the tools whose names contain the given filter // string (case-insensitive). Useful for the --tool flag. 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 { + if strings.Contains(strings.ToLower(t.Name), filter) { + return true + } + return t.Name == grokBuildName && strings.Contains(strings.ToLower(cursorName), filter) +} + +// 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 to compare saved tool names by, treating +// Grok Build as Cursor. +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 { diff --git a/pkg/skills/scope.go b/pkg/skills/scope.go index bb1077a4..ad9b2b59 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: ".cursor"}, "iFlow CLI": {Name: "iFlow CLI", ParentDir: ".iflow"}, "Junie": {Name: "Junie", ParentDir: ".junie"}, "Kilo Code": {Name: "Kilo Code", ParentDir: ".kilocode"}, diff --git a/pkg/skills/service.go b/pkg/skills/service.go index 42913ef6..f18485e2 100644 --- a/pkg/skills/service.go +++ b/pkg/skills/service.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "slices" "strings" ) @@ -216,10 +217,13 @@ 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). A selected + // tool replaces its former name, such as Cursor for Grok Build. toolSet := make(map[string]bool) for _, name := range existing.Tools { - toolSet[name] = true + if _, ok := LookupTool(selectedTools, name); !ok { + toolSet[name] = true + } } for _, name := range ToolNames(selectedTools) { toolSet[name] = true @@ -409,11 +413,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 +423,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 +474,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/tui/views/skillslist.go b/pkg/tui/views/skillslist.go index a9426065..04e5c478 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)")) From 64ace29216ef8e408a766fde32b0583d1e0cca9b Mon Sep 17 00:00:00 2001 From: David Bruck <1393236+gorban@users.noreply.github.com> Date: Thu, 3 Dec 2026 16:22:20 -0600 Subject: [PATCH 3/6] Add tests for Grok Build's skills folder and naming it after install Move the skills install text into formatInstallResult. Behavior is unchanged. The new tests cover: - Project scope: Grok Build uses .cursor/skills where the project already has .cursor, and .grok/skills otherwise, unless Render skills are already in .grok/skills. - User scope: Render skills already in ~/.grok/skills keep Grok Build there after ~/.cursor appears, with or without the grok-build command. - Install text: with one tool, name its skills folder, relative to the current directory for project scope (also when that directory is reached through a symlink) and with ~ for user scope. They fail until that is supported. Refs #81 --- cmd/skillsinstall.go | 15 ++++-- cmd/skillsinstall_test.go | 91 ++++++++++++++++++++++++++++++++++++ pkg/skills/installer_test.go | 31 ++++++++++++ pkg/skills/scope_test.go | 46 +++++++++++++++--- 4 files changed, 172 insertions(+), 11 deletions(-) create mode 100644 cmd/skillsinstall_test.go diff --git a/cmd/skillsinstall.go b/cmd/skillsinstall.go index eb338765..c31a2c96 100644 --- a/cmd/skillsinstall.go +++ b/cmd/skillsinstall.go @@ -76,11 +76,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 +104,12 @@ func interactiveSkillsInstall(cmd *cobra.Command, input SkillsInstallInput, scop Breadcrumb: "Install Skills", }) } + +// formatInstallResult describes an install for text output. +func formatInstallResult(r *skills.InstallResult, scope skills.Scope) 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)) +} diff --git a/cmd/skillsinstall_test.go b/cmd/skillsinstall_test.go new file mode 100644 index 00000000..b8ec1a59 --- /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/pkg/skills/installer_test.go b/pkg/skills/installer_test.go index 5ff250e7..5d7ecf61 100644 --- a/pkg/skills/installer_test.go +++ b/pkg/skills/installer_test.go @@ -1,6 +1,7 @@ package skills import ( + "fmt" "os" "os/exec" "path/filepath" @@ -242,6 +243,36 @@ func TestDetectToolsCursorAndGrokBuild(t *testing.T) { } } +// 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) { t.Run("removes selected skills", func(t *testing.T) { dir := t.TempDir() diff --git a/pkg/skills/scope_test.go b/pkg/skills/scope_test.go index ec77eb3d..2080f077 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) { @@ -95,12 +99,42 @@ func TestGetScopedSkillsDir(t *testing.T) { if projectDir != expected { t.Errorf("GetScopedSkillsDir(project) = %q, want %q", projectDir, expected) } +} - // Grok Build's project skills stay in .cursor/skills, wherever its user skills are - grokBuild := Tool{Name: "Grok Build", SkillsDir: "/home/user/.grok/skills"} - projectDir = GetScopedSkillsDir(grokBuild, ScopeProject, repoRoot) - expected = filepath.Join(repoRoot, ".cursor", "skills") - if projectDir != expected { - t.Errorf("GetScopedSkillsDir(Grok Build, 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) + }) } } From f0172cddee3680e2d6d27b210fdb69c9edba5ce7 Mon Sep 17 00:00:00 2001 From: David Bruck <1393236+gorban@users.noreply.github.com> Date: Thu, 3 Dec 2026 16:23:18 -0600 Subject: [PATCH 4/6] Use .grok/skills for Grok Build unless .cursor is in use, and name it Grok Build reads skills from both .cursor and .grok, its CLI's own directory. Where a project or home directory already has .cursor, Grok Build keeps using .cursor/skills; otherwise it uses .grok/skills. Render skills already in .grok/skills keep it there, so on one machine installs are neither left behind nor copied a second time when .cursor appears later. skills install now reports each tool's skills folder at the chosen scope (ScopedTools, shared with the interactive install), so -o json names the project folder rather than the user one. With one tool, the text output names that folder, resolving symlinks in the current directory as git does for the repository root: Installed 22 skill(s) to .grok/skills Refs #81 --- cmd/skillsinstall.go | 27 +++++++++++++++++++++++++-- pkg/skills/installer.go | 38 +++++++++++++++++++++++++++----------- pkg/skills/scope.go | 6 +++++- pkg/skills/service.go | 26 ++++++++++++++++++-------- pkg/skills/service_test.go | 14 ++++++++++++++ 5 files changed, 89 insertions(+), 22 deletions(-) diff --git a/cmd/skillsinstall.go b/cmd/skillsinstall.go index c31a2c96..d7c30e9f 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" @@ -105,11 +108,31 @@ func interactiveSkillsInstall(cmd *cobra.Command, input SkillsInstallInput, scop }) } -// formatInstallResult describes an install for text output. +// 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" } - return text.FormatStringF("%s %d skill(s) to %d tool(s)", action, len(r.Skills), len(r.Tools)) + 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/pkg/skills/installer.go b/pkg/skills/installer.go index 29ec75fc..921caafa 100644 --- a/pkg/skills/installer.go +++ b/pkg/skills/installer.go @@ -123,20 +123,36 @@ func detectTools(home string, lookPath func(file string) (string, error)) []Tool // 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 detected as -// before, even if ~/.grok exists: the Grok CLI reads ~/.cursor/skills by -// default, and other tools also use ~/.grok. Only without ~/.cursor does Grok -// Build use ~/.grok, the Grok CLI's own directory. +// installs a grok-build command; without that command, ~/.cursor is still +// detected as Cursor, even if ~/.grok exists: the Grok CLI reads +// ~/.cursor/skills by default, and other tools also use ~/.grok. Render skills +// already in ~/.grok/skills keep Grok Build there either way. func cursorTool(home string, lookPath func(file string) (string, error)) (name, parentDir string) { cursorDir := filepath.Join(home, ".cursor") - grokDir := filepath.Join(home, ".grok") - if !dirExists(cursorDir) && dirExists(grokDir) { - return grokBuildName, grokDir + _, err := lookPath("grok-build") + if err != nil && !hasRenderSkills(filepath.Join(home, ".grok", "skills")) && dirExists(cursorDir) { + return cursorName, cursorDir } - if _, err := lookPath("grok-build"); err == nil { - return grokBuildName, cursorDir - } - return cursorName, cursorDir + 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 diff --git a/pkg/skills/scope.go b/pkg/skills/scope.go index ad9b2b59..5dea434d 100644 --- a/pkg/skills/scope.go +++ b/pkg/skills/scope.go @@ -76,7 +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: ".cursor"}, + "Grok Build": {Name: "Grok Build", ParentDir: ".grok"}, "iFlow CLI": {Name: "iFlow CLI", ParentDir: ".iflow"}, "Junie": {Name: "Junie", ParentDir: ".junie"}, "Kilo Code": {Name: "Kilo Code", ParentDir: ".kilocode"}, @@ -113,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/service.go b/pkg/skills/service.go index f18485e2..3138d46e 100644 --- a/pkg/skills/service.go +++ b/pkg/skills/service.go @@ -129,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, } @@ -145,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 { @@ -317,9 +318,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 { @@ -347,11 +348,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. diff --git a/pkg/skills/service_test.go b/pkg/skills/service_test.go index ff5d73fa..a09f8810 100644 --- a/pkg/skills/service_test.go +++ b/pkg/skills/service_test.go @@ -49,3 +49,17 @@ func TestSaveInstallStateReplacesCursorWithGrokBuild(t *testing.T) { require.NoError(t, err) assert.ElementsMatch(t, []string{"Claude Code", "Grok Build"}, 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)) +} From c96b72cff1208a333cfd9440606d9ad179dfc7c9 Mon Sep 17 00:00:00 2001 From: David Bruck <1393236+gorban@users.noreply.github.com> Date: Thu, 3 Dec 2026 17:10:41 -0600 Subject: [PATCH 5/6] Add tests for --tool grok, saving Grok Build as Cursor, and the Grok CLI check The new tests cover: - `--tool cursor` and `--tool grok` selecting the tool whether it's detected as Cursor or as Grok Build, which depends on the grok-build command being on PATH. - Saving Grok Build under the name Cursor in ~/.render/skills.yaml, including state rebuilt from disk and state already saved as Grok Build, so older versions of the CLI still find it. - Detecting the Grok CLI by ~/.grok/config.toml, so a ~/.grok that belongs to another tool isn't detected and gets no skills folder. They fail until that is supported. Refs #81 --- pkg/skills/installer_test.go | 97 +++++++++++++++++++++++++++++------- pkg/skills/service_test.go | 37 ++++++++++---- 2 files changed, 106 insertions(+), 28 deletions(-) diff --git a/pkg/skills/installer_test.go b/pkg/skills/installer_test.go index 5d7ecf61..cb2ebe02 100644 --- a/pkg/skills/installer_test.go +++ b/pkg/skills/installer_test.go @@ -5,6 +5,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -184,40 +185,52 @@ func TestFilterTools(t *testing.T) { assert.Empty(t, result) }) - t.Run("cursor and grok match Grok Build", func(t *testing.T) { - tools := []Tool{ - {Name: "Claude Code", SkillsDir: "/a"}, - {Name: "Grok Build", SkillsDir: "/b"}, - } - for _, filter := range []string{"cursor", "grok"} { - result := FilterTools(tools, filter) - require.Len(t, result, 1, filter) - assert.Equal(t, "Grok Build", result[0].Name, filter) - } - }) + // 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 - dirs []string // directories to create in the home directory + 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"}, 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"}, true, "Grok Build", ".cursor/skills"}, - {"Grok CLI without Cursor", []string{".grok"}, false, "Grok Build", ".grok/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 _, dir := range tt.dirs { - require.NoError(t, os.MkdirAll(filepath.Join(home, dir), 0o755)) + 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" { @@ -241,6 +254,56 @@ func TestDetectToolsCursorAndGrokBuild(t *testing.T) { 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 diff --git a/pkg/skills/service_test.go b/pkg/skills/service_test.go index a09f8810..c06afb88 100644 --- a/pkg/skills/service_test.go +++ b/pkg/skills/service_test.go @@ -35,19 +35,34 @@ func TestIntersectToolsByState(t *testing.T) { }) } -func TestSaveInstallStateReplacesCursorWithGrokBuild(t *testing.T) { - dir := t.TempDir() - origPath := defaultStatePath - defaultStatePath = filepath.Join(dir, "skills.yaml") - t.Cleanup(func() { defaultStatePath = origPath }) +// 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()) + } - require.NoError(t, (&SkillsState{Tools: []string{"Claude Code", "Cursor"}}).Save()) + SaveInstallStateWithScope(nil, []Tool{{Name: "Grok Build", SkillsDir: "/b"}}, dir, ScopeUser) - SaveInstallStateWithScope(nil, []Tool{{Name: "Grok Build", SkillsDir: "/b"}}, dir, ScopeUser) - - loaded, err := LoadState() - require.NoError(t, err) - assert.ElementsMatch(t, []string{"Claude Code", "Grok Build"}, loaded.Tools) + loaded, err := LoadState() + require.NoError(t, err) + assert.ElementsMatch(t, tc.want, loaded.Tools) + }) + } } func TestScopedTools(t *testing.T) { From b9742e1d73f183ea93f5f8d7a6842b0b7fdf8863 Mon Sep 17 00:00:00 2001 From: David Bruck <1393236+gorban@users.noreply.github.com> Date: Thu, 3 Dec 2026 17:11:13 -0600 Subject: [PATCH 6/6] Select Grok Build with --tool grok, save it as Cursor, and check the Grok CLI - `--tool cursor` and `--tool grok` select the tool whether it's detected as Cursor or as Grok Build. Which one depends on the grok-build command being on PATH, so it can differ in cron, CI or an IDE terminal. - ~/.render/skills.yaml keeps the name Cursor for Grok Build, so older versions of the CLI still find it and the saved name doesn't change with PATH. A name saved as Grok Build is rewritten as Cursor. - The Grok CLI is detected by ~/.grok/config.toml rather than ~/.grok, since other tools also use ~/.grok. Render skills already in ~/.grok/skills still keep Grok Build there. Refs #81 --- pkg/skills/installer.go | 49 ++++++++++++++++++++++++++++------------- pkg/skills/scope.go | 2 +- pkg/skills/service.go | 10 ++++----- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/pkg/skills/installer.go b/pkg/skills/installer.go index 921caafa..f8b6e762 100644 --- a/pkg/skills/installer.go +++ b/pkg/skills/installer.go @@ -124,15 +124,22 @@ func detectTools(home string, lookPath func(file string) (string, error)) []Tool // 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 if ~/.grok exists: the Grok CLI reads -// ~/.cursor/skills by default, and other tools also use ~/.grok. Render skills -// already in ~/.grok/skills keep Grok Build there either way. +// 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") - if err != nil && !hasRenderSkills(filepath.Join(home, ".grok", "skills")) && dirExists(cursorDir) { + 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) } @@ -171,10 +178,16 @@ func FilterTools(tools []Tool, filter string) []Tool { // 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 { - if strings.Contains(strings.ToLower(t.Name), filter) { - return true + 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 t.Name == grokBuildName && strings.Contains(strings.ToLower(cursorName), filter) + return false } // LookupTool returns the tool with the given name. A tool name saved as Cursor @@ -188,8 +201,9 @@ func LookupTool(tools []Tool, name string) (Tool, bool) { return Tool{}, false } -// savedToolName returns the name to compare saved tool names by, treating -// Grok Build as Cursor. +// 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 @@ -520,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 @@ -547,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 @@ -677,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/scope.go b/pkg/skills/scope.go index 5dea434d..b6936861 100644 --- a/pkg/skills/scope.go +++ b/pkg/skills/scope.go @@ -76,7 +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"}, + "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"}, diff --git a/pkg/skills/service.go b/pkg/skills/service.go index 3138d46e..42598083 100644 --- a/pkg/skills/service.go +++ b/pkg/skills/service.go @@ -218,16 +218,14 @@ func SaveInstallStateWithScope(installed []SkillInfo, selectedTools []Tool, tmpD } merged = append(merged, newSkills...) - // Merge tool names (union of existing and newly selected). A selected - // tool replaces its former name, such as Cursor for Grok Build. + // Merge tool names (union of existing and newly selected), saving Grok + // Build as Cursor. toolSet := make(map[string]bool) for _, name := range existing.Tools { - if _, ok := LookupTool(selectedTools, name); !ok { - 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 {