From a5b44e4d45a4feb4fbaed9d912c13482e55cad60 Mon Sep 17 00:00:00 2001 From: David Bruck <1393236+gorban@users.noreply.github.com> Date: Thu, 3 Dec 2026 14:41:08 -0600 Subject: [PATCH 1/6] Add a regression test for render skills list outside interactive mode render skills list panics with a nil pointer dereference in tui.(*StackModel).Push when run with --output text, json or yaml, or without a TTY, which falls back to text. The command always pushes its TUI view onto the stack from the context, and the root command only puts a stack in the context in interactive mode. The test runs render skills list through the root command with no TTY and with each non-interactive format. It fails on this commit with the same panic as the issue. To run the command without reading the real home directory, the command is now built by newSkillsListCmd, which takes the function that loads skills state. The skills state path is fixed when the package loads, and tool detection reads the home directory, so setting HOME in a test can't isolate either. Building a fresh command per test also keeps flag values from carrying over between tests, as they do on a package-level command. Behavior is unchanged. Refs #79 --- cmd/skillslist.go | 30 +++++++++++------- cmd/skillslist_test.go | 69 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 cmd/skillslist_test.go diff --git a/cmd/skillslist.go b/cmd/skillslist.go index e698f790..c28914ab 100644 --- a/cmd/skillslist.go +++ b/cmd/skillslist.go @@ -8,19 +8,27 @@ import ( "github.com/render-oss/cli/pkg/tui/views" ) -var skillsListCmd = &cobra.Command{ - Use: "list", - Short: "List installed Render skills and detected tools", - Long: `List installed Render skills and the AI tools they've been installed in. This reads from local state only, so the command doesn't require network access. +// newSkillsListCmd builds `render skills list`. loadState reads the local +// skills state, so tests can supply it without touching the home directory. +func newSkillsListCmd(loadState func() (*skills.LoadedState, error)) *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Short: "List installed Render skills and detected tools", + Long: `List installed Render skills and the AI tools they've been installed in. This reads from local state only, so the command doesn't require network access. Use --scope to filter by installation scope (user or project).`, - Example: ` # List all installed skills + Example: ` # List all installed skills render skills list # List project-scoped skills only render skills list --scope project`, - SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { + SilenceUsage: true, + } + + cmd.Flags().String("scope", "", "Filter skills by installation scope (user or project)") + setFlagPlaceholder(cmd.Flags(), "scope", "SCOPE") + + cmd.RunE = func(cmd *cobra.Command, args []string) error { scopeFilter, _ := cmd.Flags().GetString("scope") var scope skills.Scope @@ -42,11 +50,11 @@ Use --scope to filter by installation scope (user or project).`, Breadcrumb: "List Skills", }) return nil - }, + } + + return cmd } func init() { - skillsCmd.AddCommand(skillsListCmd) - skillsListCmd.Flags().String("scope", "", "Filter skills by installation scope (user or project)") - setFlagPlaceholder(skillsListCmd.Flags(), "scope", "SCOPE") + skillsCmd.AddCommand(newSkillsListCmd(skills.LoadOrRebuildState)) } diff --git a/cmd/skillslist_test.go b/cmd/skillslist_test.go new file mode 100644 index 00000000..3dc199ef --- /dev/null +++ b/cmd/skillslist_test.go @@ -0,0 +1,69 @@ +package cmd + +import ( + "bytes" + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/render-oss/cli/pkg/command" + "github.com/render-oss/cli/pkg/dependencies" + "github.com/render-oss/cli/pkg/skills" +) + +// executeSkillsList runs `render skills list ` through the root command +// without a TTY, reading loaded in place of the local skills state. +func executeSkillsList(t *testing.T, loaded *skills.LoadedState, args ...string) (CommandResult, error) { + t.Helper() + return executeSkillsListWithLoader(t, func() (*skills.LoadedState, error) { + return loaded, nil + }, args...) +} + +func executeSkillsListWithLoader(t *testing.T, loadState func() (*skills.LoadedState, error), args ...string) (CommandResult, error) { + t.Helper() + + deps := dependencies.New(nil) + deps.DetectRuntimeSignals = func() (command.RuntimeSignals, error) { + return command.RuntimeSignals{}, nil + } + + root := newRootCmd() + skillsParent := &cobra.Command{Use: "skills"} + skillsParent.AddCommand(newSkillsListCmd(loadState)) + root.AddCommand(skillsParent) + setupRootCmdPersistentRun(root, deps) + + var stdout, stderr bytes.Buffer + root.SetOut(&stdout) + root.SetErr(&stderr) + root.SetArgs(append([]string{"skills", "list"}, args...)) + + err := root.Execute() + return CommandResult{Stdout: stdout.String(), Stderr: stderr.String()}, err +} + +// Regression test for https://github.com/render-oss/cli/issues/79: outside +// interactive mode there is no TUI stack, and pushing a view onto it panicked. +func TestSkillsList_NonInteractiveDoesNotPanic(t *testing.T) { + for _, tc := range []struct { + name string + args []string + }{ + {name: "no TTY", args: nil}, + {name: "text", args: []string{"-o", "text"}}, + {name: "json", args: []string{"-o", "json"}}, + {name: "yaml", args: []string{"-o", "yaml"}}, + } { + t.Run(tc.name, func(t *testing.T) { + loaded := &skills.LoadedState{State: &skills.SkillsState{}} + + result, err := executeSkillsList(t, loaded, tc.args...) + + require.NoError(t, err) + assert.NotEmpty(t, result.Stdout) + }) + } +} From cc6bdff430e6f493fe2d7785189c48e223009eb2 Mon Sep 17 00:00:00 2001 From: David Bruck <1393236+gorban@users.noreply.github.com> Date: Thu, 3 Dec 2026 14:41:57 -0600 Subject: [PATCH 2/6] Fix render skills list crash outside interactive mode render skills list pushed its TUI view onto the stack from the context on every run. Outside interactive mode (--output text, json or yaml, or any run without a TTY) the root command puts no stack in the context, so the push dereferenced a nil *StackModel and panicked. Route non-interactive output through command.NonInteractive, as skills install already does, and only push the view in interactive mode. - JSON and YAML print skills.ListResult: the installed skills with their version and scope (filtered by --scope), the tools recorded in the state file with whether each is detected and its skills directory, the install time and any warnings. Keys are camelCase like the CLI's other JSON output, empty lists print as [] rather than null, and a version of "unknown" is left out. - Text prints a skills table and a tools table in the same table style as other list commands' text output, using "-" for empty cells. - Warnings from reading installed skills also go to stderr, styled like other warnings there, so text output shows them without mixing them into the tables. The output type lives in pkg/skills next to InstallResult, and the table rendering in pkg/text next to the other tables. The --scope filter moves into skills.FilterSkillsByScope, which both the new output and the interactive view use, so the two can't disagree about which skills are at a scope. The view is otherwise unchanged. Fixes #79 --- cmd/skillslist.go | 28 +++++++++- cmd/skillslist_test.go | 106 ++++++++++++++++++++++++++++++++++++ pkg/skills/list.go | 77 ++++++++++++++++++++++++++ pkg/skills/list_test.go | 30 ++++++++++ pkg/text/skills.go | 33 +++++++++++ pkg/text/skills_test.go | 31 +++++++++++ pkg/tui/views/skillslist.go | 10 +--- 7 files changed, 305 insertions(+), 10 deletions(-) create mode 100644 pkg/skills/list.go create mode 100644 pkg/skills/list_test.go create mode 100644 pkg/text/skills.go create mode 100644 pkg/text/skills_test.go diff --git a/cmd/skillslist.go b/cmd/skillslist.go index c28914ab..2c15a359 100644 --- a/cmd/skillslist.go +++ b/cmd/skillslist.go @@ -1,9 +1,14 @@ package cmd import ( + "fmt" + "github.com/spf13/cobra" + "github.com/render-oss/cli/pkg/command" "github.com/render-oss/cli/pkg/skills" + "github.com/render-oss/cli/pkg/style" + "github.com/render-oss/cli/pkg/text" "github.com/render-oss/cli/pkg/tui" "github.com/render-oss/cli/pkg/tui/views" ) @@ -21,7 +26,10 @@ Use --scope to filter by installation scope (user or project).`, render skills list # List project-scoped skills only - render skills list --scope project`, + render skills list --scope project + + # Output as JSON + render skills list -o json`, SilenceUsage: true, } @@ -40,6 +48,24 @@ Use --scope to filter by installation scope (user or project).`, } } + if nonInteractive, err := command.NonInteractive(cmd, func() (*skills.ListResult, error) { + loaded, err := loadState() + if err != nil { + return nil, err + } + // JSON and YAML also carry the warnings, but print them to stderr + // too so text output shows them without mixing them into the tables. + warning := style.Status.Foreground(style.ColorWarning).Render("Warning:") + for _, w := range loaded.Warnings { + _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "%s %s\n", warning, w) + } + return skills.NewListResult(loaded, scope), nil + }, text.SkillTables); err != nil { + return err + } else if nonInteractive { + return nil + } + // Push TUI view onto the stack. // We push directly (not via AddToStackFunc) because skills are // purely local — there's no CLI command string to copy. diff --git a/cmd/skillslist_test.go b/cmd/skillslist_test.go index 3dc199ef..05dc248c 100644 --- a/cmd/skillslist_test.go +++ b/cmd/skillslist_test.go @@ -2,11 +2,14 @@ package cmd import ( "bytes" + "encoding/json" + "errors" "testing" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gopkg.in/yaml.v3" "github.com/render-oss/cli/pkg/command" "github.com/render-oss/cli/pkg/dependencies" @@ -67,3 +70,106 @@ func TestSkillsList_NonInteractiveDoesNotPanic(t *testing.T) { }) } } + +func skillsListTestState() *skills.LoadedState { + return &skills.LoadedState{ + State: &skills.SkillsState{ + Tools: []string{"Claude Code", "Cursor"}, + Skills: []skills.InstalledSkill{ + {Name: "render-deploy", Version: "1.2.0", Scope: skills.ScopeUser}, + {Name: "render-debug", Version: "unknown"}, + {Name: "render-monitor", Version: "0.3.0", Scope: skills.ScopeProject}, + }, + InstalledAt: "2026-11-30T12:00:00Z", + }, + DetectedTools: []skills.Tool{ + {Name: "Claude Code", SkillsDir: "/home/me/.claude/skills"}, + }, + } +} + +func TestSkillsList_JSON(t *testing.T) { + result, err := executeSkillsList(t, skillsListTestState(), "-o", "json") + require.NoError(t, err) + + var got skills.ListResult + require.NoError(t, json.Unmarshal([]byte(result.Stdout), &got)) + assert.Equal(t, skills.ListResult{ + Skills: []skills.ListedSkill{ + {Name: "render-deploy", Version: "1.2.0", Scope: skills.ScopeUser}, + {Name: "render-debug", Scope: skills.ScopeUser}, + {Name: "render-monitor", Version: "0.3.0", Scope: skills.ScopeProject}, + }, + Tools: []skills.ListedTool{ + {Name: "Claude Code", Detected: true, SkillsDir: "/home/me/.claude/skills"}, + {Name: "Cursor", Detected: false}, + }, + InstalledAt: "2026-11-30T12:00:00Z", + }, got) +} + +func TestSkillsList_ScopeFilter(t *testing.T) { + t.Run("json", func(t *testing.T) { + result, err := executeSkillsList(t, skillsListTestState(), "--scope", "project", "-o", "json") + require.NoError(t, err) + + var got skills.ListResult + require.NoError(t, json.Unmarshal([]byte(result.Stdout), &got)) + require.Len(t, got.Skills, 1) + assert.Equal(t, "render-monitor", got.Skills[0].Name) + }) + + t.Run("yaml", func(t *testing.T) { + result, err := executeSkillsList(t, skillsListTestState(), "--scope", "project", "-o", "yaml") + require.NoError(t, err) + + var got map[string]any + require.NoError(t, yaml.Unmarshal([]byte(result.Stdout), &got)) + assert.Equal(t, []any{ + map[string]any{"name": "render-monitor", "version": "0.3.0", "scope": "project"}, + }, got["skills"]) + }) +} + +func TestSkillsList_Text(t *testing.T) { + result, err := executeSkillsList(t, skillsListTestState(), "-o", "text") + require.NoError(t, err) + + assert.Regexp(t, `render-deploy\s+1\.2\.0\s+user`, result.Stdout) + assert.Regexp(t, `render-debug\s+-\s+user`, result.Stdout) + assert.Regexp(t, `render-monitor\s+0\.3\.0\s+project`, result.Stdout) + assert.Regexp(t, `Claude Code\s+true\s+/home/me/\.claude/skills`, result.Stdout) + assert.Regexp(t, `Cursor\s+false\s+-`, result.Stdout) +} + +func TestSkillsList_NoSkillsPrintsEmptyLists(t *testing.T) { + loaded := &skills.LoadedState{State: &skills.SkillsState{}} + + result, err := executeSkillsList(t, loaded, "-o", "json") + require.NoError(t, err) + + assert.JSONEq(t, `{"skills": [], "tools": []}`, result.Stdout) +} + +func TestSkillsList_Warnings(t *testing.T) { + loaded := skillsListTestState() + loaded.Warnings = []string{"could not hash render-debug: permission denied"} + + result, err := executeSkillsList(t, loaded, "-o", "json") + require.NoError(t, err) + + assert.Contains(t, result.Stderr, "Warning:") + assert.Contains(t, result.Stderr, "could not hash render-debug: permission denied") + + var got skills.ListResult + require.NoError(t, json.Unmarshal([]byte(result.Stdout), &got)) + assert.Equal(t, []string{"could not hash render-debug: permission denied"}, got.Warnings) +} + +func TestSkillsList_LoadError(t *testing.T) { + _, err := executeSkillsListWithLoader(t, func() (*skills.LoadedState, error) { + return nil, errors.New("failed to load skills state: boom") + }, "-o", "json") + + require.ErrorContains(t, err, "failed to load skills state: boom") +} diff --git a/pkg/skills/list.go b/pkg/skills/list.go new file mode 100644 index 00000000..eab9ce9f --- /dev/null +++ b/pkg/skills/list.go @@ -0,0 +1,77 @@ +package skills + +// ListResult is the JSON/YAML contract for `render skills list`. +type ListResult struct { + Skills []ListedSkill `json:"skills"` + Tools []ListedTool `json:"tools"` + InstalledAt string `json:"installedAt,omitempty"` + Warnings []string `json:"warnings,omitempty"` +} + +// ListedSkill is an installed Render skill. +type ListedSkill struct { + Name string `json:"name"` + Version string `json:"version,omitempty"` + Scope Scope `json:"scope"` +} + +// ListedTool is an AI coding tool that skills were installed to. Detected is +// false when the tool is recorded in state but is no longer on this machine. +type ListedTool struct { + Name string `json:"name"` + Detected bool `json:"detected"` + SkillsDir string `json:"skillsDir,omitempty"` +} + +// NewListResult builds the list of installed skills and their tools from +// loaded state. A non-empty scope keeps only the skills installed at that scope. +func NewListResult(loaded *LoadedState, scope Scope) *ListResult { + result := &ListResult{ + Skills: []ListedSkill{}, + Tools: []ListedTool{}, + InstalledAt: loaded.State.InstalledAt, + Warnings: loaded.Warnings, + } + + for _, sk := range FilterSkillsByScope(loaded.State.Skills, scope) { + version := sk.Version + if version == "unknown" { + version = "" + } + result.Skills = append(result.Skills, ListedSkill{ + Name: sk.Name, + Version: version, + Scope: sk.EffectiveScope(), + }) + } + + detected := make(map[string]Tool, len(loaded.DetectedTools)) + for _, t := range loaded.DetectedTools { + detected[t.Name] = t + } + for _, name := range loaded.State.Tools { + t, ok := detected[name] + result.Tools = append(result.Tools, ListedTool{ + Name: name, + Detected: ok, + SkillsDir: t.SkillsDir, + }) + } + + return result +} + +// FilterSkillsByScope returns the skills installed at scope, treating a skill +// with no recorded scope as user scope. An empty scope returns all skills. +func FilterSkillsByScope(installed []InstalledSkill, scope Scope) []InstalledSkill { + if scope == "" { + return installed + } + var filtered []InstalledSkill + for _, sk := range installed { + if sk.EffectiveScope() == scope { + filtered = append(filtered, sk) + } + } + return filtered +} diff --git a/pkg/skills/list_test.go b/pkg/skills/list_test.go new file mode 100644 index 00000000..bb099ab7 --- /dev/null +++ b/pkg/skills/list_test.go @@ -0,0 +1,30 @@ +package skills + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestFilterSkillsByScope(t *testing.T) { + user := InstalledSkill{Name: "render-deploy", Scope: ScopeUser} + legacy := InstalledSkill{Name: "render-debug"} // no scope recorded + project := InstalledSkill{Name: "render-monitor", Scope: ScopeProject} + installed := []InstalledSkill{user, legacy, project} + + t.Run("empty scope returns all", func(t *testing.T) { + assert.Equal(t, installed, FilterSkillsByScope(installed, "")) + }) + + t.Run("user scope includes skills with no recorded scope", func(t *testing.T) { + assert.Equal(t, []InstalledSkill{user, legacy}, FilterSkillsByScope(installed, ScopeUser)) + }) + + t.Run("project scope", func(t *testing.T) { + assert.Equal(t, []InstalledSkill{project}, FilterSkillsByScope(installed, ScopeProject)) + }) + + t.Run("no match", func(t *testing.T) { + assert.Empty(t, FilterSkillsByScope([]InstalledSkill{user}, ScopeProject)) + }) +} diff --git a/pkg/text/skills.go b/pkg/text/skills.go new file mode 100644 index 00000000..330a00cb --- /dev/null +++ b/pkg/text/skills.go @@ -0,0 +1,33 @@ +package text + +import ( + "github.com/jedib0t/go-pretty/table" + + "github.com/render-oss/cli/pkg/skills" +) + +// SkillTables renders installed skills and the tools they were installed to +// as two tables. +func SkillTables(r *skills.ListResult) string { + skillTable := newTable() + skillTable.AppendHeader(table.Row{"Name", "Version", "Scope"}) + for _, sk := range r.Skills { + version := sk.Version + if version == "" { + version = "-" + } + skillTable.AppendRow(table.Row{sk.Name, version, sk.Scope}) + } + + toolTable := newTable() + toolTable.AppendHeader(table.Row{"Tool", "Detected", "Skills Dir"}) + for _, t := range r.Tools { + dir := t.SkillsDir + if dir == "" { + dir = "-" + } + toolTable.AppendRow(table.Row{t.Name, t.Detected, dir}) + } + + return FormatString(skillTable.Render() + "\n\n" + toolTable.Render()) +} diff --git a/pkg/text/skills_test.go b/pkg/text/skills_test.go new file mode 100644 index 00000000..f2209ccf --- /dev/null +++ b/pkg/text/skills_test.go @@ -0,0 +1,31 @@ +package text_test + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/render-oss/cli/pkg/skills" + "github.com/render-oss/cli/pkg/text" +) + +func TestSkillTables_ContainsHeadersAndRows(t *testing.T) { + out := text.SkillTables(&skills.ListResult{ + Skills: []skills.ListedSkill{{Name: "render-deploy", Version: "1.2.0", Scope: skills.ScopeProject}}, + Tools: []skills.ListedTool{{Name: "Claude Code", Detected: true, SkillsDir: "/home/u/.claude/skills"}}, + }) + for _, want := range []string{"NAME", "VERSION", "SCOPE", "TOOL", "DETECTED", "SKILLS DIR", + "render-deploy", "1.2.0", "project", "Claude Code", "true", "/home/u/.claude/skills"} { + assert.True(t, strings.Contains(out, want), "expected %q in output:\n%s", want, out) + } +} + +func TestSkillTables_EmptyCellsShowDash(t *testing.T) { + out := text.SkillTables(&skills.ListResult{ + Skills: []skills.ListedSkill{{Name: "render-debug", Scope: skills.ScopeUser}}, + Tools: []skills.ListedTool{{Name: "Cursor"}}, + }) + assert.True(t, strings.Contains(out, "false"), "undetected tool should render as false:\n%s", out) + assert.Equal(t, 2, strings.Count(out, " - "), "missing version and skills dir should render as -:\n%s", out) +} diff --git a/pkg/tui/views/skillslist.go b/pkg/tui/views/skillslist.go index 9e4badb9..34d0d2f0 100644 --- a/pkg/tui/views/skillslist.go +++ b/pkg/tui/views/skillslist.go @@ -144,15 +144,7 @@ func (v *SkillsListView) renderOutput(warnings []string) string { } // Filter skills by scope if specified - filteredSkills := v.state.Skills - if v.scopeFilter != "" { - filteredSkills = nil - for _, sk := range v.state.Skills { - if sk.EffectiveScope() == v.scopeFilter { - filteredSkills = append(filteredSkills, sk) - } - } - } + filteredSkills := skills.FilterSkillsByScope(v.state.Skills, v.scopeFilter) // No skills installed. if len(filteredSkills) == 0 { From 445b3a3fa268285dd6f581b67f440193237e3023 Mon Sep 17 00:00:00 2001 From: David Bruck <1393236+gorban@users.noreply.github.com> Date: Thu, 3 Dec 2026 15:56:58 -0600 Subject: [PATCH 3/6] Add a regression test for render skills remove outside interactive mode Build the command with newSkillsRemoveCmd, as skills list does, so tests run it through the root command with a fresh command each time. The no-TTY harness moves into executeSkillsCommand, shared with the skills list tests. Behavior is unchanged. The test runs render skills remove without --all or --skill, with no TTY and with -o text and -o json. It fails with the same nil pointer panic as skills list did, from pushing the TUI view when there is no stack. Refs #79 --- cmd/skillslist_test.go | 12 +++++- cmd/skillsremove.go | 90 +++++++++++++++++++++------------------- cmd/skillsremove_test.go | 28 +++++++++++++ 3 files changed, 85 insertions(+), 45 deletions(-) create mode 100644 cmd/skillsremove_test.go diff --git a/cmd/skillslist_test.go b/cmd/skillslist_test.go index 05dc248c..90a0c649 100644 --- a/cmd/skillslist_test.go +++ b/cmd/skillslist_test.go @@ -27,6 +27,14 @@ func executeSkillsList(t *testing.T, loaded *skills.LoadedState, args ...string) func executeSkillsListWithLoader(t *testing.T, loadState func() (*skills.LoadedState, error), args ...string) (CommandResult, error) { t.Helper() + return executeSkillsCommand(t, newSkillsListCmd(loadState), args...) +} + +// executeSkillsCommand runs `render skills ` through the root +// command without a TTY. sub is a fresh command, so flag values don't carry +// over between tests. +func executeSkillsCommand(t *testing.T, sub *cobra.Command, args ...string) (CommandResult, error) { + t.Helper() deps := dependencies.New(nil) deps.DetectRuntimeSignals = func() (command.RuntimeSignals, error) { @@ -35,14 +43,14 @@ func executeSkillsListWithLoader(t *testing.T, loadState func() (*skills.LoadedS root := newRootCmd() skillsParent := &cobra.Command{Use: "skills"} - skillsParent.AddCommand(newSkillsListCmd(loadState)) + skillsParent.AddCommand(sub) root.AddCommand(skillsParent) setupRootCmdPersistentRun(root, deps) var stdout, stderr bytes.Buffer root.SetOut(&stdout) root.SetErr(&stderr) - root.SetArgs(append([]string{"skills", "list"}, args...)) + root.SetArgs(append([]string{"skills", sub.Name()}, args...)) err := root.Execute() return CommandResult{Stdout: stdout.String(), Stderr: stderr.String()}, err diff --git a/cmd/skillsremove.go b/cmd/skillsremove.go index 8304c1a9..6c769772 100644 --- a/cmd/skillsremove.go +++ b/cmd/skillsremove.go @@ -12,15 +12,16 @@ import ( "github.com/render-oss/cli/pkg/tui/views" ) -var skillsRemoveCmd = &cobra.Command{ - Use: "remove", - Short: "Remove installed Render skills from AI coding tools", - Long: `Remove previously installed Render skills from detected AI coding tools. +func newSkillsRemoveCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "remove", + Short: "Remove installed Render skills from AI coding tools", + Long: `Remove previously installed Render skills from detected AI coding tools. By default an interactive prompt lets you pick which skills to remove. Use --skill and --all flags to skip the prompts. Use --scope to remove from a specific scope (user or project).`, - Example: ` # Remove skills interactively + Example: ` # Remove skills interactively render skills remove # Remove specific skills @@ -28,50 +29,53 @@ Use --scope to remove from a specific scope (user or project).`, # Remove all project-scoped skills render skills remove --all --scope project`, - SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { - skillFilter, _ := cmd.Flags().GetStringSlice("skill") - toolFilter, _ := cmd.Flags().GetString("tool") - removeAll, _ := cmd.Flags().GetBool("all") - scopeFilter, _ := cmd.Flags().GetString("scope") - - // Parse scope if provided - var scope skills.Scope - if scopeFilter != "" { - var err error - scope, err = skills.ParseScope(scopeFilter) - if err != nil { - return err + SilenceUsage: true, + RunE: func(cmd *cobra.Command, args []string) error { + skillFilter, _ := cmd.Flags().GetStringSlice("skill") + toolFilter, _ := cmd.Flags().GetString("tool") + removeAll, _ := cmd.Flags().GetBool("all") + scopeFilter, _ := cmd.Flags().GetString("scope") + + // Parse scope if provided + var scope skills.Scope + if scopeFilter != "" { + var err error + scope, err = skills.ParseScope(scopeFilter) + if err != nil { + return err + } } - } - // Non-interactive path: flags provided. - if removeAll || len(skillFilter) > 0 { - return nonInteractiveSkillsRemove(cmd, skillFilter, toolFilter, removeAll, scope) - } + // Non-interactive path: flags provided. + if removeAll || len(skillFilter) > 0 { + return nonInteractiveSkillsRemove(cmd, skillFilter, toolFilter, removeAll, scope) + } - // Interactive path: push TUI view onto the stack. - // We push directly (not via AddToStackFunc) because skills are - // purely local — there's no CLI command string to copy. - ctx := cmd.Context() - stack := tui.GetStackFromContext(ctx) - stack.Push(tui.ModelWithCmd{ - Model: views.NewSkillsRemoveView(scope), - Breadcrumb: "Remove Skills", - }) - return nil - }, + // Interactive path: push TUI view onto the stack. + // We push directly (not via AddToStackFunc) because skills are + // purely local — there's no CLI command string to copy. + ctx := cmd.Context() + stack := tui.GetStackFromContext(ctx) + stack.Push(tui.ModelWithCmd{ + Model: views.NewSkillsRemoveView(scope), + Breadcrumb: "Remove Skills", + }) + return nil + }, + } + + cmd.Flags().StringSlice("skill", nil, "Remove specific skills only (use --skill multiple times)") + cmd.Flags().String("tool", "", "Remove skills from a specific tool only (claude, codex, opencode, or cursor)") + cmd.Flags().Bool("all", false, "Remove all installed Render skills") + cmd.Flags().String("scope", "", "Remove skills from the specified scope (user or project)") + setFlagPlaceholder(cmd.Flags(), "skill", "SKILL") + setFlagPlaceholder(cmd.Flags(), "tool", "TOOL") + setFlagPlaceholder(cmd.Flags(), "scope", "SCOPE") + return cmd } 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().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") - setFlagPlaceholder(skillsRemoveCmd.Flags(), "tool", "TOOL") - setFlagPlaceholder(skillsRemoveCmd.Flags(), "scope", "SCOPE") + skillsCmd.AddCommand(newSkillsRemoveCmd()) } // nonInteractiveSkillsRemove runs the remove flow without prompts. diff --git a/cmd/skillsremove_test.go b/cmd/skillsremove_test.go new file mode 100644 index 00000000..768701f3 --- /dev/null +++ b/cmd/skillsremove_test.go @@ -0,0 +1,28 @@ +package cmd + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +// Regression test for https://github.com/render-oss/cli/issues/79: without +// --all or --skill, `render skills remove` pushed its TUI view, and outside +// interactive mode there is no stack to push onto. +func TestSkillsRemove_NonInteractiveRequiresAllOrSkill(t *testing.T) { + for _, tc := range []struct { + name string + args []string + }{ + {name: "no TTY", args: nil}, + {name: "text", args: []string{"-o", "text"}}, + {name: "json", args: []string{"-o", "json"}}, + {name: "tool and scope", args: []string{"--confirm", "--tool", "grok", "--scope", "project", "-o", "text"}}, + } { + t.Run(tc.name, func(t *testing.T) { + _, err := executeSkillsCommand(t, newSkillsRemoveCmd(), tc.args...) + + assert.EqualError(t, err, "--all or --skill is required in non-interactive mode") + }) + } +} From 0c4e6948f33cf7e238185bfa2b2a2c10c54d2f86 Mon Sep 17 00:00:00 2001 From: David Bruck <1393236+gorban@users.noreply.github.com> Date: Thu, 3 Dec 2026 15:57:52 -0600 Subject: [PATCH 4/6] Fix render skills remove crash outside interactive mode Without --all or --skill, render skills remove opens a prompt to choose skills. Outside interactive mode (--output text, json or yaml, or no TTY) there is no TUI stack, and pushing the view onto it panicked. Return an error naming the flags instead, in the form other commands use for required non-interactive input. Fixes #79 --- cmd/skillsremove.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/skillsremove.go b/cmd/skillsremove.go index 6c769772..715a9b80 100644 --- a/cmd/skillsremove.go +++ b/cmd/skillsremove.go @@ -51,10 +51,16 @@ Use --scope to remove from a specific scope (user or project).`, return nonInteractiveSkillsRemove(cmd, skillFilter, toolFilter, removeAll, scope) } + // Choosing skills needs the interactive prompt, so outside + // interactive mode one of the flags is required. + ctx := cmd.Context() + if format := command.GetFormatFromContext(ctx); format != nil && !format.Interactive() { + return fmt.Errorf("--all or --skill is required in non-interactive mode") + } + // Interactive path: push TUI view onto the stack. // We push directly (not via AddToStackFunc) because skills are // purely local — there's no CLI command string to copy. - ctx := cmd.Context() stack := tui.GetStackFromContext(ctx) stack.Push(tui.ModelWithCmd{ Model: views.NewSkillsRemoveView(scope), From 24862f9d5c0200a8348287ef6e70718d6b454e52 Mon Sep 17 00:00:00 2001 From: David Bruck <1393236+gorban@users.noreply.github.com> Date: Thu, 3 Dec 2026 17:06:51 -0600 Subject: [PATCH 5/6] Add tests for the remaining render skills commands outside interactive mode Make `skills update` a constructor like `list` and `remove` so tests can run it. Behavior is unchanged. The new tests cover: - `skills update` and bare `render skills` without a TTY or with -o text or json, which still panic. - `skills list -o json --scope project`, which reports each tool's user skills folder rather than the project one. - Warnings, which `skills list -o json` prints to stderr as well as into the output. - Interactive mode, where `skills list` still opens its view. The test helper now uses a temporary HOME, so tool detection never reads the real one, and returns a panic as an error so it fails only the test that caused it. The remove test uses `--tool claude`, as in the issue. Refs #79 --- cmd/skills_test.go | 38 +++++++++++++ cmd/skillslist_test.go | 118 ++++++++++++++++++++++++++++++++++----- cmd/skillsremove_test.go | 2 +- cmd/skillsupdate.go | 70 ++++++++++++----------- 4 files changed, 181 insertions(+), 47 deletions(-) create mode 100644 cmd/skills_test.go diff --git a/cmd/skills_test.go b/cmd/skills_test.go new file mode 100644 index 00000000..01840533 --- /dev/null +++ b/cmd/skills_test.go @@ -0,0 +1,38 @@ +package cmd + +import ( + "fmt" + "testing" + + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// Outside interactive mode, `render skills update` and bare `render skills` +// have no TUI stack to push onto. They used to panic; see +// https://github.com/render-oss/cli/issues/79. +func TestSkillsUpdate_NonInteractive(t *testing.T) { + for _, args := range [][]string{nil, {"-o", "text"}, {"-o", "json"}, {"--force", "--scope", "user", "-o", "text"}} { + t.Run(fmt.Sprint(args), func(t *testing.T) { + _, err := executeSkillsCommand(t, newSkillsUpdateCmd(), args...) + + assert.EqualError(t, err, "`render skills update` can only be used in interactive mode") + }) + } +} + +func TestSkills_NonInteractivePrintsHelp(t *testing.T) { + for _, args := range [][]string{nil, {"-o", "text"}, {"-o", "json"}} { + t.Run(fmt.Sprint(args), func(t *testing.T) { + skills := &cobra.Command{Use: "skills", Short: skillsCmd.Short, RunE: skillsCmd.RunE} + skills.AddCommand(&cobra.Command{Use: "list", Short: "List installed Render skills", Run: func(*cobra.Command, []string) {}}) + + result, err := executeSkillsArgs(t, skills, args...) + + require.NoError(t, err) + assert.Contains(t, result.Stdout, "render skills [subcommand]") + assert.Regexp(t, `list\s+List installed Render skills`, result.Stdout) + }) + } +} diff --git a/cmd/skillslist_test.go b/cmd/skillslist_test.go index 90a0c649..134e5bb1 100644 --- a/cmd/skillslist_test.go +++ b/cmd/skillslist_test.go @@ -2,8 +2,12 @@ package cmd import ( "bytes" + "context" "encoding/json" "errors" + "fmt" + "os/exec" + "path/filepath" "testing" "github.com/spf13/cobra" @@ -14,6 +18,7 @@ import ( "github.com/render-oss/cli/pkg/command" "github.com/render-oss/cli/pkg/dependencies" "github.com/render-oss/cli/pkg/skills" + "github.com/render-oss/cli/pkg/tui" ) // executeSkillsList runs `render skills list ` through the root command @@ -32,9 +37,24 @@ func executeSkillsListWithLoader(t *testing.T, loadState func() (*skills.LoadedS // executeSkillsCommand runs `render skills ` through the root // command without a TTY. sub is a fresh command, so flag values don't carry -// over between tests. +// over between tests. HOME is a temporary directory, so tool detection never +// reads the real one. The skills state path is fixed when the package loads, +// so a test that gets past a command's argument checks must supply the state, +// as the list tests do. func executeSkillsCommand(t *testing.T, sub *cobra.Command, args ...string) (CommandResult, error) { t.Helper() + skillsParent := &cobra.Command{Use: "skills"} + skillsParent.AddCommand(sub) + return executeSkillsArgs(t, skillsParent, append([]string{sub.Name()}, args...)...) +} + +// executeSkillsArgs runs `render skills `, with skillsParent as the +// skills command, in the same way as executeSkillsCommand. A panic is returned +// as an error, so it fails only the test that caused it. +func executeSkillsArgs(t *testing.T, skillsParent *cobra.Command, args ...string) (result CommandResult, err error) { + t.Helper() + t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", t.TempDir()) deps := dependencies.New(nil) deps.DetectRuntimeSignals = func() (command.RuntimeSignals, error) { @@ -42,18 +62,21 @@ func executeSkillsCommand(t *testing.T, sub *cobra.Command, args ...string) (Com } root := newRootCmd() - skillsParent := &cobra.Command{Use: "skills"} - skillsParent.AddCommand(sub) root.AddCommand(skillsParent) setupRootCmdPersistentRun(root, deps) var stdout, stderr bytes.Buffer root.SetOut(&stdout) root.SetErr(&stderr) - root.SetArgs(append([]string{"skills", sub.Name()}, args...)) + root.SetArgs(append([]string{"skills"}, args...)) - err := root.Execute() - return CommandResult{Stdout: stdout.String(), Stderr: stderr.String()}, err + defer func() { + if r := recover(); r != nil { + err = fmt.Errorf("panic: %v", r) + } + result = CommandResult{Stdout: stdout.String(), Stderr: stderr.String()} + }() + return result, root.Execute() } // Regression test for https://github.com/render-oss/cli/issues/79: outside @@ -127,6 +150,34 @@ func TestSkillsList_ScopeFilter(t *testing.T) { assert.Equal(t, "render-monitor", got.Skills[0].Name) }) + t.Run("json reports the project skills folder", func(t *testing.T) { + repoRoot := newGitRepo(t) + + result, err := executeSkillsList(t, skillsListTestState(), "--scope", "project", "-o", "json") + require.NoError(t, err) + + var got skills.ListResult + require.NoError(t, json.Unmarshal([]byte(result.Stdout), &got)) + assert.Equal(t, []skills.ListedTool{ + {Name: "Claude Code", Detected: true, SkillsDir: filepath.Join(repoRoot, ".claude", "skills")}, + {Name: "Cursor", Detected: false}, + }, got.Tools) + }) + + t.Run("json outside a git repository omits the project skills folder", func(t *testing.T) { + t.Chdir(t.TempDir()) + + result, err := executeSkillsList(t, skillsListTestState(), "--scope", "project", "-o", "json") + require.NoError(t, err) + + var got skills.ListResult + require.NoError(t, json.Unmarshal([]byte(result.Stdout), &got)) + assert.Equal(t, []skills.ListedTool{ + {Name: "Claude Code", Detected: true}, + {Name: "Cursor", Detected: false}, + }, got.Tools) + }) + t.Run("yaml", func(t *testing.T) { result, err := executeSkillsList(t, skillsListTestState(), "--scope", "project", "-o", "yaml") require.NoError(t, err) @@ -163,15 +214,56 @@ func TestSkillsList_Warnings(t *testing.T) { loaded := skillsListTestState() loaded.Warnings = []string{"could not hash render-debug: permission denied"} - result, err := executeSkillsList(t, loaded, "-o", "json") - require.NoError(t, err) + t.Run("text prints them to stderr", func(t *testing.T) { + result, err := executeSkillsList(t, loaded, "-o", "text") + require.NoError(t, err) + + assert.Contains(t, result.Stderr, "Warning:") + assert.Contains(t, result.Stderr, "could not hash render-debug: permission denied") + assert.NotContains(t, result.Stdout, "could not hash") + }) - assert.Contains(t, result.Stderr, "Warning:") - assert.Contains(t, result.Stderr, "could not hash render-debug: permission denied") + t.Run("json carries them only in the output", func(t *testing.T) { + result, err := executeSkillsList(t, loaded, "-o", "json") + require.NoError(t, err) - var got skills.ListResult - require.NoError(t, json.Unmarshal([]byte(result.Stdout), &got)) - assert.Equal(t, []string{"could not hash render-debug: permission denied"}, got.Warnings) + assert.Empty(t, result.Stderr) + var got skills.ListResult + require.NoError(t, json.Unmarshal([]byte(result.Stdout), &got)) + assert.Equal(t, []string{"could not hash render-debug: permission denied"}, got.Warnings) + }) +} + +// In interactive mode the command still opens the list view. +func TestSkillsList_InteractivePushesView(t *testing.T) { + interactive := command.Interactive + stack := tui.NewStack() + ctx := command.SetFormatInContext(context.Background(), &interactive) + ctx = tui.SetStackInContext(ctx, stack) + + cmd := newSkillsListCmd(func() (*skills.LoadedState, error) { + t.Fatal("interactive mode should not load state in the command") + return nil, nil + }) + cmd.SetArgs(nil) + require.NoError(t, cmd.ExecuteContext(ctx)) + + assert.False(t, stack.IsEmpty()) +} + +// newGitRepo makes the current directory a new git repository and returns its +// root as git reports it. +func newGitRepo(t *testing.T) string { + t.Helper() + if _, err := exec.LookPath("git"); err != nil { + t.Skip("git not available") + } + dir := t.TempDir() + t.Chdir(dir) + require.NoError(t, exec.Command("git", "init", "-q").Run()) + root, err := skills.GetRepoRoot() + require.NoError(t, err) + return root } func TestSkillsList_LoadError(t *testing.T) { diff --git a/cmd/skillsremove_test.go b/cmd/skillsremove_test.go index 768701f3..d58191b3 100644 --- a/cmd/skillsremove_test.go +++ b/cmd/skillsremove_test.go @@ -17,7 +17,7 @@ func TestSkillsRemove_NonInteractiveRequiresAllOrSkill(t *testing.T) { {name: "no TTY", args: nil}, {name: "text", args: []string{"-o", "text"}}, {name: "json", args: []string{"-o", "json"}}, - {name: "tool and scope", args: []string{"--confirm", "--tool", "grok", "--scope", "project", "-o", "text"}}, + {name: "tool and scope", args: []string{"--confirm", "--tool", "claude", "--scope", "user", "-o", "text"}}, } { t.Run(tc.name, func(t *testing.T) { _, err := executeSkillsCommand(t, newSkillsRemoveCmd(), tc.args...) diff --git a/cmd/skillsupdate.go b/cmd/skillsupdate.go index 0a5e3432..113e7697 100644 --- a/cmd/skillsupdate.go +++ b/cmd/skillsupdate.go @@ -8,15 +8,16 @@ import ( "github.com/render-oss/cli/pkg/tui/views" ) -var skillsUpdateCmd = &cobra.Command{ - Use: "update", - Short: "Update previously installed Render skills", - Long: `Reinstall Render skills using the tool and skill selections saved by a previous "render skills install" run. +func newSkillsUpdateCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "update", + Short: "Update previously installed Render skills", + Long: `Reinstall Render skills using the tool and skill selections saved by a previous "render skills install" run. This fetches the latest version of each selected skill from the skills repository, compares with installed versions, and updates any that have changed. Use --scope to update skills at a specific scope (user or project).`, - Example: ` # Update installed skills + Example: ` # Update installed skills render skills update # Force reinstall all skills @@ -24,36 +25,39 @@ Use --scope to update skills at a specific scope (user or project).`, # Update project-scoped skills render skills update --scope project`, - SilenceUsage: true, - RunE: func(cmd *cobra.Command, args []string) error { - force, _ := cmd.Flags().GetBool("force") - scopeFilter, _ := cmd.Flags().GetString("scope") - - var scope skills.Scope - if scopeFilter != "" { - var err error - scope, err = skills.ParseScope(scopeFilter) - if err != nil { - return err + SilenceUsage: true, + RunE: func(cmd *cobra.Command, args []string) error { + force, _ := cmd.Flags().GetBool("force") + scopeFilter, _ := cmd.Flags().GetString("scope") + + var scope skills.Scope + if scopeFilter != "" { + var err error + scope, err = skills.ParseScope(scopeFilter) + if err != nil { + return err + } } - } - - // Push TUI view onto the stack. - // We push directly (not via AddToStackFunc) because skills are - // purely local — there's no CLI command string to copy. - ctx := cmd.Context() - stack := tui.GetStackFromContext(ctx) - stack.Push(tui.ModelWithCmd{ - Model: views.NewSkillsUpdateView(force, scope), - Breadcrumb: "Update Skills", - }) - return nil - }, + + // Push TUI view onto the stack. + // We push directly (not via AddToStackFunc) because skills are + // purely local — there's no CLI command string to copy. + ctx := cmd.Context() + stack := tui.GetStackFromContext(ctx) + stack.Push(tui.ModelWithCmd{ + Model: views.NewSkillsUpdateView(force, scope), + Breadcrumb: "Update Skills", + }) + return nil + }, + } + + cmd.Flags().Bool("force", false, "Reinstall all skills even if already up to date") + cmd.Flags().String("scope", "", "Update skills at the specified scope (user or project)") + setFlagPlaceholder(cmd.Flags(), "scope", "SCOPE") + return cmd } func init() { - skillsCmd.AddCommand(skillsUpdateCmd) - skillsUpdateCmd.Flags().Bool("force", false, "Reinstall all skills even if already up to date") - skillsUpdateCmd.Flags().String("scope", "", "Update skills at the specified scope (user or project)") - setFlagPlaceholder(skillsUpdateCmd.Flags(), "scope", "SCOPE") + skillsCmd.AddCommand(newSkillsUpdateCmd()) } From dc9dab36d1c1c3a35c188f18d732f868fef2ecb4 Mon Sep 17 00:00:00 2001 From: David Bruck <1393236+gorban@users.noreply.github.com> Date: Thu, 3 Dec 2026 17:07:49 -0600 Subject: [PATCH 6/6] Fix the remaining render skills commands outside interactive mode Outside interactive mode (no TTY, or -o text, json or yaml): - `skills update` returns "`render skills update` can only be used in interactive mode", the error other interactive-only commands use, instead of panicking. - Bare `render skills` prints its help instead of panicking. - `skills list -o json --scope project` reports each tool's skills folder in the current repository, and leaves it out outside one. - `skills list` prints warnings to stderr only for text; JSON and YAML carry them in the output. `skills remove` uses command.IsInteractive, like the commands above. Fixes #79 --- cmd/skills.go | 5 +++++ cmd/skillslist.go | 20 ++++++++++++++------ cmd/skillsremove.go | 2 +- cmd/skillsupdate.go | 7 +++++++ pkg/skills/list.go | 13 +++++++++++-- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/cmd/skills.go b/cmd/skills.go index a73f21a2..99a75670 100644 --- a/cmd/skills.go +++ b/cmd/skills.go @@ -6,6 +6,7 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/spf13/cobra" + "github.com/render-oss/cli/pkg/command" "github.com/render-oss/cli/pkg/tui" "github.com/render-oss/cli/pkg/tui/views" ) @@ -16,6 +17,10 @@ var skillsCmd = &cobra.Command{ 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.`, RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() + // The command palette needs the TUI; otherwise list the subcommands. + if !command.IsInteractive(ctx) { + return cmd.Help() + } stack := tui.GetStackFromContext(ctx) commands := []views.PaletteCommand{ diff --git a/cmd/skillslist.go b/cmd/skillslist.go index 2c15a359..8fde56c8 100644 --- a/cmd/skillslist.go +++ b/cmd/skillslist.go @@ -53,13 +53,21 @@ Use --scope to filter by installation scope (user or project).`, if err != nil { return nil, err } - // JSON and YAML also carry the warnings, but print them to stderr - // too so text output shows them without mixing them into the tables. - warning := style.Status.Foreground(style.ColorWarning).Render("Warning:") - for _, w := range loaded.Warnings { - _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "%s %s\n", warning, w) + // JSON and YAML carry the warnings in the output. Text prints them + // to stderr so they don't mix into the tables. + if format := command.GetFormatFromContext(cmd.Context()); format != nil && *format == command.TEXT { + warning := style.Status.Foreground(style.ColorWarning).Render("Warning:") + for _, w := range loaded.Warnings { + _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "%s %s\n", warning, w) + } } - return skills.NewListResult(loaded, scope), nil + // Project skills are listed for the current repository; outside + // one, their folders are unknown. + var repoRoot string + if scope == skills.ScopeProject { + repoRoot, _ = skills.GetRepoRoot() + } + return skills.NewListResult(loaded, scope, repoRoot), nil }, text.SkillTables); err != nil { return err } else if nonInteractive { diff --git a/cmd/skillsremove.go b/cmd/skillsremove.go index 715a9b80..1fb59c8d 100644 --- a/cmd/skillsremove.go +++ b/cmd/skillsremove.go @@ -54,7 +54,7 @@ Use --scope to remove from a specific scope (user or project).`, // Choosing skills needs the interactive prompt, so outside // interactive mode one of the flags is required. ctx := cmd.Context() - if format := command.GetFormatFromContext(ctx); format != nil && !format.Interactive() { + if !command.IsInteractive(ctx) { return fmt.Errorf("--all or --skill is required in non-interactive mode") } diff --git a/cmd/skillsupdate.go b/cmd/skillsupdate.go index 113e7697..1de384eb 100644 --- a/cmd/skillsupdate.go +++ b/cmd/skillsupdate.go @@ -1,8 +1,11 @@ package cmd import ( + "fmt" + "github.com/spf13/cobra" + "github.com/render-oss/cli/pkg/command" "github.com/render-oss/cli/pkg/skills" "github.com/render-oss/cli/pkg/tui" "github.com/render-oss/cli/pkg/tui/views" @@ -27,6 +30,10 @@ Use --scope to update skills at a specific scope (user or project).`, render skills update --scope project`, SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { + if !command.IsInteractive(cmd.Context()) { + return fmt.Errorf("`%s` can only be used in interactive mode", cmd.CommandPath()) + } + force, _ := cmd.Flags().GetBool("force") scopeFilter, _ := cmd.Flags().GetString("scope") diff --git a/pkg/skills/list.go b/pkg/skills/list.go index eab9ce9f..fbcd26e0 100644 --- a/pkg/skills/list.go +++ b/pkg/skills/list.go @@ -25,7 +25,9 @@ type ListedTool struct { // NewListResult builds the list of installed skills and their tools from // loaded state. A non-empty scope keeps only the skills installed at that scope. -func NewListResult(loaded *LoadedState, scope Scope) *ListResult { +// For project scope, each tool's skills folder is in repoRoot, and is left out +// when repoRoot is empty. +func NewListResult(loaded *LoadedState, scope Scope, repoRoot string) *ListResult { result := &ListResult{ Skills: []ListedSkill{}, Tools: []ListedTool{}, @@ -51,10 +53,17 @@ func NewListResult(loaded *LoadedState, scope Scope) *ListResult { } for _, name := range loaded.State.Tools { t, ok := detected[name] + skillsDir := t.SkillsDir + if ok && scope == ScopeProject { + skillsDir = "" + if repoRoot != "" { + skillsDir = GetScopedSkillsDir(t, scope, repoRoot) + } + } result.Tools = append(result.Tools, ListedTool{ Name: name, Detected: ok, - SkillsDir: t.SkillsDir, + SkillsDir: skillsDir, }) }