mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
feat(uninstall): add --all flag to remove all skills from source
Support bulk uninstall via 'skillshare uninstall --all' in both global and project modes. Uses glob-based discovery to find all skills and tracked repos, with --dry-run preview and --force to skip confirmation. - Parse --all with mutual exclusion vs skill names and --group - Global: discover skills + tracked repos from source directory - Project: discover from .skillshare/skills/ directory - Prune orphan symlinks from targets after removal - Integration tests for --all, --all --dry-run, and conflict errors - Update uninstall docs with --all examples - Add AI runbook for uninstall --all glob testing
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
# CLI E2E Runbook: Uninstall --all + Shell Glob Detection
|
||||
|
||||
Validates the `--all` flag for batch removal and shell glob detection
|
||||
that intercepts accidentally expanded `*` arguments.
|
||||
|
||||
**Origin**: v0.15.5 — `ss uninstall *` without quotes caused shell expansion,
|
||||
resulting in many "not found" warnings.
|
||||
|
||||
## Scope
|
||||
|
||||
- `--all` removes every skill from source (global mode)
|
||||
- `--all` removes every skill from source (project mode)
|
||||
- `--all` cannot be combined with skill names or `--group`
|
||||
- `--all --dry-run` previews without removing
|
||||
- `--all --force` skips confirmation
|
||||
- Shell glob detection intercepts file-name-like args and suggests `--all`
|
||||
- `--all` followed by `sync` leaves no orphans in targets
|
||||
|
||||
## Environment
|
||||
|
||||
Run inside devcontainer with `ssenv` isolation.
|
||||
|
||||
## Steps
|
||||
|
||||
### 1. Setup: init and install multiple skills
|
||||
|
||||
```bash
|
||||
ss init --no-copy --all-targets --no-git --no-skill
|
||||
ss install sickn33/antigravity-awesome-skills/skills/pdf-official --name pdf
|
||||
ss install sickn33/antigravity-awesome-skills/skills/tdd-workflow
|
||||
ss install sickn33/antigravity-awesome-skills/skills/react-best-practices --into frontend
|
||||
ss sync
|
||||
```
|
||||
|
||||
Expected:
|
||||
- All 3 skills installed and synced
|
||||
- Symlinks exist in `~/.claude/skills/`
|
||||
|
||||
Verify:
|
||||
|
||||
```bash
|
||||
ls ~/.config/skillshare/skills/
|
||||
ls -la ~/.claude/skills/
|
||||
```
|
||||
|
||||
### 2. --all --dry-run previews without removing
|
||||
|
||||
```bash
|
||||
ss uninstall --all --dry-run
|
||||
```
|
||||
|
||||
Expected:
|
||||
- Output contains `dry-run` and `would move to trash`
|
||||
- All skills still exist in source
|
||||
|
||||
Verify:
|
||||
|
||||
```bash
|
||||
ls ~/.config/skillshare/skills/ | grep -c .
|
||||
# Should be >= 3 (pdf, tdd-workflow, frontend)
|
||||
```
|
||||
|
||||
### 3. --all --force removes all skills
|
||||
|
||||
```bash
|
||||
ss uninstall --all --force
|
||||
```
|
||||
|
||||
Expected:
|
||||
- Output contains `Uninstalled` for each top-level entry
|
||||
- Source directory is empty (no skill directories remain)
|
||||
- Config skills list is cleared
|
||||
|
||||
Verify:
|
||||
|
||||
```bash
|
||||
REMAINING=$(ls ~/.config/skillshare/skills/ 2>/dev/null | grep -v '.gitignore' | wc -l | tr -d ' ')
|
||||
echo "Remaining skills: $REMAINING (expected: 0)"
|
||||
|
||||
grep -c 'name:' ~/.config/skillshare/config.yaml || echo "no skills in config"
|
||||
```
|
||||
|
||||
### 4. Sync after --all leaves no orphans
|
||||
|
||||
```bash
|
||||
ss sync
|
||||
```
|
||||
|
||||
Expected:
|
||||
- Symlinks removed from all targets
|
||||
- No orphan directories remain
|
||||
|
||||
Verify:
|
||||
|
||||
```bash
|
||||
TARGET=~/.claude/skills
|
||||
for skill in pdf tdd-workflow frontend__react-best-practices; do
|
||||
[ ! -e "$TARGET/$skill" ] && echo "$skill: cleaned" || echo "$skill: STILL EXISTS (FAIL)"
|
||||
done
|
||||
```
|
||||
|
||||
### 5. --all mutual exclusion
|
||||
|
||||
```bash
|
||||
ss uninstall --all some-skill 2>&1; echo "exit: $?"
|
||||
ss uninstall --all --group frontend 2>&1; echo "exit: $?"
|
||||
```
|
||||
|
||||
Expected:
|
||||
- First command: error containing `--all cannot be used with skill names`
|
||||
- Second command: error containing `--all cannot be used with --group`
|
||||
- Both exit non-zero
|
||||
|
||||
### 6. Shell glob detection
|
||||
|
||||
Simulate what happens when shell expands `*` in a typical project directory:
|
||||
|
||||
```bash
|
||||
ss uninstall README.md go.mod go.sum Makefile cmd internal 2>&1; echo "exit: $?"
|
||||
```
|
||||
|
||||
Expected:
|
||||
- Output contains suggestion to use `--all`
|
||||
- Exits non-zero
|
||||
- No skills are removed
|
||||
|
||||
### 7. --all in project mode
|
||||
|
||||
```bash
|
||||
mkdir -p /tmp/e2e-project && cd /tmp/e2e-project
|
||||
ss init -p --no-copy --no-git --no-skill --target claude
|
||||
ss install sickn33/antigravity-awesome-skills/skills/pdf-official --name pdf -p
|
||||
ss install sickn33/antigravity-awesome-skills/skills/tdd-workflow -p
|
||||
ss sync -p
|
||||
ss uninstall --all --force -p
|
||||
```
|
||||
|
||||
Expected:
|
||||
- Both skills removed from `.skillshare/skills/`
|
||||
- Project config skills list cleared
|
||||
|
||||
Verify:
|
||||
|
||||
```bash
|
||||
REMAINING=$(ls /tmp/e2e-project/.skillshare/skills/ 2>/dev/null | grep -v '.gitignore' | wc -l | tr -d ' ')
|
||||
echo "Remaining project skills: $REMAINING (expected: 0)"
|
||||
```
|
||||
|
||||
## Pass Criteria
|
||||
|
||||
- [ ] `--all --dry-run` shows preview without removing skills
|
||||
- [ ] `--all --force` removes all skills from source
|
||||
- [ ] Config `skills:` list cleared after `--all`
|
||||
- [ ] `sync` after `--all` cleans up target symlinks
|
||||
- [ ] `--all` + skill names → mutual exclusion error
|
||||
- [ ] `--all` + `--group` → mutual exclusion error
|
||||
- [ ] Shell glob detection intercepts file-name args
|
||||
- [ ] `--all` works in project mode (`-p`)
|
||||
+234
-17
@@ -12,6 +12,7 @@ import (
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/install"
|
||||
"skillshare/internal/oplog"
|
||||
"skillshare/internal/sync"
|
||||
"skillshare/internal/trash"
|
||||
"skillshare/internal/ui"
|
||||
)
|
||||
@@ -20,6 +21,7 @@ import (
|
||||
type uninstallOptions struct {
|
||||
skillNames []string // positional args (0+)
|
||||
groups []string // --group/-G values (repeatable)
|
||||
all bool // --all: remove ALL skills from source
|
||||
force bool
|
||||
dryRun bool
|
||||
}
|
||||
@@ -45,6 +47,8 @@ func parseUninstallArgs(args []string) (*uninstallOptions, bool, error) {
|
||||
for i := 0; i < len(args); i++ {
|
||||
arg := args[i]
|
||||
switch {
|
||||
case arg == "--all":
|
||||
opts.all = true
|
||||
case arg == "--force" || arg == "-f":
|
||||
opts.force = true
|
||||
case arg == "--dry-run" || arg == "-n":
|
||||
@@ -64,6 +68,17 @@ func parseUninstallArgs(args []string) (*uninstallOptions, bool, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// --all mutual exclusion checks
|
||||
if opts.all {
|
||||
if len(opts.skillNames) > 0 {
|
||||
return nil, false, fmt.Errorf("--all cannot be used with skill names")
|
||||
}
|
||||
if len(opts.groups) > 0 {
|
||||
return nil, false, fmt.Errorf("--all cannot be used with --group")
|
||||
}
|
||||
return opts, false, nil
|
||||
}
|
||||
|
||||
if len(opts.skillNames) == 0 && len(opts.groups) == 0 {
|
||||
return nil, true, fmt.Errorf("skill name or --group is required")
|
||||
}
|
||||
@@ -71,6 +86,29 @@ func parseUninstallArgs(args []string) (*uninstallOptions, bool, error) {
|
||||
return opts, false, nil
|
||||
}
|
||||
|
||||
// topLevelDir returns the first path component of a relative path.
|
||||
// e.g. "frontend/react/hooks" → "frontend", "my-skill" → "my-skill"
|
||||
func topLevelDir(relPath string) string {
|
||||
parts := strings.SplitN(relPath, "/", 2)
|
||||
return parts[0]
|
||||
}
|
||||
|
||||
// looksLikeShellGlob detects when positional args appear to be shell-expanded
|
||||
// file names rather than real skill names. Heuristic: ≥3 warnings, warnings ≥50%
|
||||
// of names, and ≥2 names contain a dot (file extension characteristic).
|
||||
func looksLikeShellGlob(names []string, warnings []string) bool {
|
||||
if len(warnings) < 3 || len(warnings)*2 < len(names) {
|
||||
return false
|
||||
}
|
||||
dotCount := 0
|
||||
for _, name := range names {
|
||||
if strings.Contains(name, ".") {
|
||||
dotCount++
|
||||
}
|
||||
}
|
||||
return dotCount >= 2
|
||||
}
|
||||
|
||||
// resolveUninstallTarget resolves skill name to path and checks existence.
|
||||
// Supports short names for nested skills (e.g. "react-best-practices" resolves
|
||||
// to "frontend/react/react-best-practices").
|
||||
@@ -363,7 +401,33 @@ func confirmUninstall(target *uninstallTarget) (bool, error) {
|
||||
return input == "y" || input == "yes", nil
|
||||
}
|
||||
|
||||
// performUninstall moves the skill to trash and cleans up
|
||||
// performUninstallQuiet moves the skill to trash and cleans up without printing output.
|
||||
// Used by batch mode; returns the type label for StepDone display.
|
||||
func performUninstallQuiet(target *uninstallTarget, cfg *config.Config) (typeLabel string, err error) {
|
||||
groupSkillCount := 0
|
||||
if !target.isTrackedRepo {
|
||||
groupSkillCount = len(countGroupSkills(target.path))
|
||||
}
|
||||
|
||||
// For tracked repos, clean up .gitignore
|
||||
if target.isTrackedRepo {
|
||||
install.RemoveFromGitIgnore(cfg.Source, target.name) //nolint:errcheck
|
||||
}
|
||||
|
||||
if _, err := trash.MoveToTrash(target.path, target.name, trash.TrashDir()); err != nil {
|
||||
return "", fmt.Errorf("failed to move to trash: %w", err)
|
||||
}
|
||||
|
||||
if target.isTrackedRepo {
|
||||
return "tracked repo", nil
|
||||
}
|
||||
if groupSkillCount > 0 {
|
||||
return fmt.Sprintf("group, %d skills", groupSkillCount), nil
|
||||
}
|
||||
return "skill", nil
|
||||
}
|
||||
|
||||
// performUninstall moves the skill to trash and cleans up (verbose single-target output)
|
||||
func performUninstall(target *uninstallTarget, cfg *config.Config) error {
|
||||
// Read metadata before moving (for reinstall hint)
|
||||
meta, _ := install.ReadMeta(target.path)
|
||||
@@ -456,6 +520,30 @@ func cmdUninstall(args []string) error {
|
||||
seen := map[string]bool{} // dedup by path
|
||||
var resolveWarnings []string
|
||||
|
||||
if opts.all {
|
||||
discovered, err := sync.DiscoverSourceSkills(cfg.Source)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to discover skills: %w", err)
|
||||
}
|
||||
if len(discovered) == 0 {
|
||||
return fmt.Errorf("no skills found in source")
|
||||
}
|
||||
// Collect unique top-level directories to avoid nested skill duplication
|
||||
topDirs := map[string]bool{}
|
||||
for _, d := range discovered {
|
||||
topDirs[topLevelDir(d.RelPath)] = true
|
||||
}
|
||||
for dir := range topDirs {
|
||||
skillPath := filepath.Join(cfg.Source, dir)
|
||||
targets = append(targets, &uninstallTarget{
|
||||
name: dir,
|
||||
path: skillPath,
|
||||
isTrackedRepo: install.IsGitRepo(skillPath),
|
||||
})
|
||||
seen[skillPath] = true
|
||||
}
|
||||
}
|
||||
|
||||
for _, name := range opts.skillNames {
|
||||
t, err := resolveUninstallTarget(name, cfg)
|
||||
if err != nil {
|
||||
@@ -486,6 +574,14 @@ func cmdUninstall(args []string) error {
|
||||
ui.Warning("%s", w)
|
||||
}
|
||||
|
||||
// Shell glob detection: if positional args look like shell-expanded filenames,
|
||||
// intercept early and suggest --all instead
|
||||
if !opts.all && looksLikeShellGlob(opts.skillNames, resolveWarnings) {
|
||||
ui.Warning("It looks like '*' was expanded by your shell into file names.")
|
||||
ui.Info("To uninstall all skills, use: skillshare uninstall --all")
|
||||
return fmt.Errorf("shell glob expansion detected")
|
||||
}
|
||||
|
||||
// --- Phase 2: VALIDATE ---
|
||||
if len(targets) == 0 {
|
||||
if len(resolveWarnings) > 0 {
|
||||
@@ -501,19 +597,34 @@ func cmdUninstall(args []string) error {
|
||||
displayUninstallInfo(targets[0])
|
||||
} else {
|
||||
ui.Header(fmt.Sprintf("Uninstalling %d %s", len(targets), summary.noun()))
|
||||
if summary.noun() == "target(s)" {
|
||||
if len(targets) > 20 {
|
||||
// Compressed: only list non-skill items (groups, tracked repos) individually
|
||||
ui.Info("Includes: %s", summary.details())
|
||||
}
|
||||
for _, t := range targets {
|
||||
label := t.name
|
||||
if t.isTrackedRepo {
|
||||
label += " (tracked repository)"
|
||||
} else if c := summary.groupSkillCount[t.path]; c > 0 {
|
||||
label += fmt.Sprintf(" (group, %d skills)", c)
|
||||
} else {
|
||||
label += " (skill)"
|
||||
for _, t := range targets {
|
||||
if t.isTrackedRepo {
|
||||
fmt.Printf(" - %s (tracked repository)\n", t.name)
|
||||
} else if c := summary.groupSkillCount[t.path]; c > 0 {
|
||||
fmt.Printf(" - %s (group, %d skills)\n", t.name, c)
|
||||
}
|
||||
}
|
||||
if summary.skills > 0 {
|
||||
fmt.Printf(" ... and %d skill(s)\n", summary.skills)
|
||||
}
|
||||
} else {
|
||||
if summary.noun() == "target(s)" {
|
||||
ui.Info("Includes: %s", summary.details())
|
||||
}
|
||||
for _, t := range targets {
|
||||
label := t.name
|
||||
if t.isTrackedRepo {
|
||||
label += " (tracked repository)"
|
||||
} else if c := summary.groupSkillCount[t.path]; c > 0 {
|
||||
label += fmt.Sprintf(" (group, %d skills)", c)
|
||||
} else {
|
||||
label += " (skill)"
|
||||
}
|
||||
fmt.Printf(" - %s\n", label)
|
||||
}
|
||||
fmt.Printf(" - %s\n", label)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
@@ -579,14 +690,112 @@ func cmdUninstall(args []string) error {
|
||||
}
|
||||
|
||||
// --- Phase 6: EXECUTE ---
|
||||
batch := len(targets) > 1
|
||||
type batchResult struct {
|
||||
target *uninstallTarget
|
||||
typeLabel string
|
||||
errMsg string
|
||||
}
|
||||
|
||||
var succeeded []*uninstallTarget
|
||||
var failed []string
|
||||
for _, t := range targets {
|
||||
if err := performUninstall(t, cfg); err != nil {
|
||||
failed = append(failed, fmt.Sprintf("%s: %v", t.name, err))
|
||||
ui.Warning("Failed to uninstall %s: %v", t.name, err)
|
||||
|
||||
if batch {
|
||||
sp := ui.StartSpinner(fmt.Sprintf("Uninstalling %d %s", len(targets), summary.noun()))
|
||||
var results []batchResult
|
||||
|
||||
for _, t := range targets {
|
||||
typeLabel, err := performUninstallQuiet(t, cfg)
|
||||
if err != nil {
|
||||
results = append(results, batchResult{target: t, errMsg: err.Error()})
|
||||
failed = append(failed, fmt.Sprintf("%s: %v", t.name, err))
|
||||
} else {
|
||||
results = append(results, batchResult{target: t, typeLabel: typeLabel})
|
||||
succeeded = append(succeeded, t)
|
||||
}
|
||||
}
|
||||
|
||||
// Spinner end state
|
||||
if len(failed) > 0 && len(succeeded) == 0 {
|
||||
sp.Fail(fmt.Sprintf("Failed to uninstall %d %s", len(failed), summary.noun()))
|
||||
} else if len(failed) > 0 {
|
||||
sp.Warn(fmt.Sprintf("Uninstalled %d, failed %d", len(succeeded), len(failed)))
|
||||
} else {
|
||||
succeeded = append(succeeded, t)
|
||||
sp.Success(fmt.Sprintf("Uninstalled %d %s", len(succeeded), summary.noun()))
|
||||
}
|
||||
|
||||
// Failures always shown individually
|
||||
var successes []batchResult
|
||||
var failures []batchResult
|
||||
for _, r := range results {
|
||||
if r.errMsg != "" {
|
||||
failures = append(failures, r)
|
||||
} else {
|
||||
successes = append(successes, r)
|
||||
}
|
||||
}
|
||||
|
||||
useSections := len(results) > 10
|
||||
|
||||
if len(failures) > 0 {
|
||||
if useSections {
|
||||
ui.SectionLabel("Failed")
|
||||
} else {
|
||||
fmt.Println()
|
||||
}
|
||||
for _, r := range failures {
|
||||
ui.StepFail(r.target.name, r.errMsg)
|
||||
}
|
||||
}
|
||||
|
||||
// Successes: condensed when many
|
||||
if len(successes) > 0 {
|
||||
if useSections {
|
||||
ui.SectionLabel("Removed")
|
||||
} else {
|
||||
fmt.Println()
|
||||
}
|
||||
switch {
|
||||
case len(successes) > 50:
|
||||
ui.StepDone(fmt.Sprintf("%d uninstalled", len(successes)), "")
|
||||
case len(successes) > 10:
|
||||
const maxShown = 10
|
||||
names := make([]string, 0, maxShown)
|
||||
for i := 0; i < maxShown && i < len(successes); i++ {
|
||||
names = append(names, successes[i].target.name)
|
||||
}
|
||||
detail := strings.Join(names, ", ")
|
||||
if len(successes) > maxShown {
|
||||
detail = fmt.Sprintf("%s ... +%d more", detail, len(successes)-maxShown)
|
||||
}
|
||||
ui.StepDone(fmt.Sprintf("%d uninstalled", len(successes)), detail)
|
||||
default:
|
||||
for _, r := range successes {
|
||||
ui.StepDone(r.target.name, r.typeLabel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Batch summary
|
||||
if useSections {
|
||||
ui.SectionLabel("Next Steps")
|
||||
} else {
|
||||
fmt.Println()
|
||||
}
|
||||
ui.Info("Moved to trash (7 days).")
|
||||
ui.Info("Run 'skillshare sync' to update all targets")
|
||||
|
||||
// Opportunistic cleanup of expired trash items
|
||||
if n, _ := trash.Cleanup(trash.TrashDir(), 0); n > 0 {
|
||||
ui.Info("Cleaned up %d expired trash item(s)", n)
|
||||
}
|
||||
} else {
|
||||
for _, t := range targets {
|
||||
if err := performUninstall(t, cfg); err != nil {
|
||||
failed = append(failed, fmt.Sprintf("%s: %v", t.name, err))
|
||||
} else {
|
||||
succeeded = append(succeeded, t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,6 +835,9 @@ func cmdUninstall(args []string) error {
|
||||
|
||||
// Build names list for oplog
|
||||
var opNames []string
|
||||
if opts.all {
|
||||
opNames = append(opNames, "--all")
|
||||
}
|
||||
for _, name := range opts.skillNames {
|
||||
opNames = append(opNames, name)
|
||||
}
|
||||
@@ -672,6 +884,7 @@ func isRepoDirty(repoPath string) (bool, error) {
|
||||
func printUninstallHelp() {
|
||||
fmt.Println(`Usage: skillshare uninstall <name>... [options]
|
||||
skillshare uninstall --group <group> [options]
|
||||
skillshare uninstall --all [options]
|
||||
|
||||
Remove one or more skills or tracked repositories from the source directory.
|
||||
Skills are moved to trash and kept for 7 days before automatic cleanup.
|
||||
@@ -683,6 +896,7 @@ For tracked repositories (_repo-name):
|
||||
- The _ prefix is optional (automatically detected)
|
||||
|
||||
Options:
|
||||
--all Remove ALL skills from source (requires confirmation)
|
||||
--group, -G <name> Remove all skills in a group (prefix match, repeatable)
|
||||
--force, -f Skip confirmation and ignore uncommitted changes
|
||||
--dry-run, -n Preview without making changes
|
||||
@@ -693,6 +907,9 @@ Options:
|
||||
Examples:
|
||||
skillshare uninstall my-skill # Remove a single skill
|
||||
skillshare uninstall a b c --force # Remove multiple skills at once
|
||||
skillshare uninstall --all # Remove all skills
|
||||
skillshare uninstall --all --force # Remove all without confirmation
|
||||
skillshare uninstall --all -n # Preview what would be removed
|
||||
skillshare uninstall --group frontend # Remove all skills in frontend/
|
||||
skillshare uninstall --group frontend -n # Preview group removal
|
||||
skillshare uninstall x -G backend --force # Mix names and groups
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/install"
|
||||
"skillshare/internal/sync"
|
||||
"skillshare/internal/trash"
|
||||
"skillshare/internal/ui"
|
||||
)
|
||||
@@ -47,6 +48,30 @@ func resolveProjectUninstallTarget(skillName, sourceDir string) (*uninstallTarge
|
||||
}, nil
|
||||
}
|
||||
|
||||
// performProjectUninstallQuiet moves a project skill to trash without printing output.
|
||||
// Used by batch mode; returns the type label for StepDone display.
|
||||
func performProjectUninstallQuiet(target *uninstallTarget, root, trashDir string) (typeLabel string, err error) {
|
||||
groupSkillCount := 0
|
||||
if !target.isTrackedRepo {
|
||||
groupSkillCount = len(countGroupSkills(target.path))
|
||||
}
|
||||
|
||||
// Clean up .gitignore (all project skills have gitignore entries)
|
||||
install.RemoveFromGitIgnore(filepath.Join(root, ".skillshare"), filepath.Join("skills", target.name)) //nolint:errcheck
|
||||
|
||||
if _, err := trash.MoveToTrash(target.path, target.name, trashDir); err != nil {
|
||||
return "", fmt.Errorf("failed to move to trash: %w", err)
|
||||
}
|
||||
|
||||
if target.isTrackedRepo {
|
||||
return "tracked repo", nil
|
||||
}
|
||||
if groupSkillCount > 0 {
|
||||
return fmt.Sprintf("group, %d skills", groupSkillCount), nil
|
||||
}
|
||||
return "skill", nil
|
||||
}
|
||||
|
||||
func cmdUninstallProject(args []string, root string) error {
|
||||
opts, showHelp, err := parseUninstallArgs(args)
|
||||
if showHelp {
|
||||
@@ -71,6 +96,29 @@ func cmdUninstallProject(args []string, root string) error {
|
||||
seen := map[string]bool{}
|
||||
var resolveWarnings []string
|
||||
|
||||
if opts.all {
|
||||
discovered, err := sync.DiscoverSourceSkills(sourceDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to discover skills: %w", err)
|
||||
}
|
||||
if len(discovered) == 0 {
|
||||
return fmt.Errorf("no skills found in project source")
|
||||
}
|
||||
topDirs := map[string]bool{}
|
||||
for _, d := range discovered {
|
||||
topDirs[topLevelDir(d.RelPath)] = true
|
||||
}
|
||||
for dir := range topDirs {
|
||||
skillPath := filepath.Join(sourceDir, dir)
|
||||
targets = append(targets, &uninstallTarget{
|
||||
name: dir,
|
||||
path: skillPath,
|
||||
isTrackedRepo: install.IsGitRepo(skillPath),
|
||||
})
|
||||
seen[skillPath] = true
|
||||
}
|
||||
}
|
||||
|
||||
for _, name := range opts.skillNames {
|
||||
t, err := resolveProjectUninstallTarget(name, sourceDir)
|
||||
if err != nil {
|
||||
@@ -101,6 +149,13 @@ func cmdUninstallProject(args []string, root string) error {
|
||||
ui.Warning("%s", w)
|
||||
}
|
||||
|
||||
// Shell glob detection
|
||||
if !opts.all && looksLikeShellGlob(opts.skillNames, resolveWarnings) {
|
||||
ui.Warning("It looks like '*' was expanded by your shell into file names.")
|
||||
ui.Info("To uninstall all skills, use: skillshare uninstall --all")
|
||||
return fmt.Errorf("shell glob expansion detected")
|
||||
}
|
||||
|
||||
// --- Phase 2: VALIDATE ---
|
||||
if len(targets) == 0 {
|
||||
if len(resolveWarnings) > 0 {
|
||||
@@ -116,19 +171,34 @@ func cmdUninstallProject(args []string, root string) error {
|
||||
displayUninstallInfo(targets[0])
|
||||
} else {
|
||||
ui.Header(fmt.Sprintf("Uninstalling %d %s", len(targets), summary.noun()))
|
||||
if summary.noun() == "target(s)" {
|
||||
if len(targets) > 20 {
|
||||
// Compressed: only list non-skill items (groups, tracked repos) individually
|
||||
ui.Info("Includes: %s", summary.details())
|
||||
}
|
||||
for _, t := range targets {
|
||||
label := t.name
|
||||
if t.isTrackedRepo {
|
||||
label += " (tracked repository)"
|
||||
} else if c := summary.groupSkillCount[t.path]; c > 0 {
|
||||
label += fmt.Sprintf(" (group, %d skills)", c)
|
||||
} else {
|
||||
label += " (skill)"
|
||||
for _, t := range targets {
|
||||
if t.isTrackedRepo {
|
||||
fmt.Printf(" - %s (tracked repository)\n", t.name)
|
||||
} else if c := summary.groupSkillCount[t.path]; c > 0 {
|
||||
fmt.Printf(" - %s (group, %d skills)\n", t.name, c)
|
||||
}
|
||||
}
|
||||
if summary.skills > 0 {
|
||||
fmt.Printf(" ... and %d skill(s)\n", summary.skills)
|
||||
}
|
||||
} else {
|
||||
if summary.noun() == "target(s)" {
|
||||
ui.Info("Includes: %s", summary.details())
|
||||
}
|
||||
for _, t := range targets {
|
||||
label := t.name
|
||||
if t.isTrackedRepo {
|
||||
label += " (tracked repository)"
|
||||
} else if c := summary.groupSkillCount[t.path]; c > 0 {
|
||||
label += fmt.Sprintf(" (group, %d skills)", c)
|
||||
} else {
|
||||
label += " (skill)"
|
||||
}
|
||||
fmt.Printf(" - %s\n", label)
|
||||
}
|
||||
fmt.Printf(" - %s\n", label)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
@@ -192,39 +262,138 @@ func cmdUninstallProject(args []string, root string) error {
|
||||
}
|
||||
|
||||
// --- Phase 6: EXECUTE ---
|
||||
batch := len(targets) > 1
|
||||
type batchResult struct {
|
||||
target *uninstallTarget
|
||||
typeLabel string
|
||||
errMsg string
|
||||
}
|
||||
|
||||
var succeeded []*uninstallTarget
|
||||
var failed []string
|
||||
for _, t := range targets {
|
||||
meta, _ := install.ReadMeta(t.path)
|
||||
groupSkillCount := 0
|
||||
if !t.isTrackedRepo {
|
||||
groupSkillCount = len(countGroupSkills(t.path))
|
||||
|
||||
if batch {
|
||||
sp := ui.StartSpinner(fmt.Sprintf("Uninstalling %d %s", len(targets), summary.noun()))
|
||||
var results []batchResult
|
||||
|
||||
for _, t := range targets {
|
||||
typeLabel, err := performProjectUninstallQuiet(t, root, trashDir)
|
||||
if err != nil {
|
||||
results = append(results, batchResult{target: t, errMsg: err.Error()})
|
||||
failed = append(failed, fmt.Sprintf("%s: %v", t.name, err))
|
||||
} else {
|
||||
results = append(results, batchResult{target: t, typeLabel: typeLabel})
|
||||
succeeded = append(succeeded, t)
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up .gitignore (all project skills have gitignore entries)
|
||||
if _, err := install.RemoveFromGitIgnore(filepath.Join(root, ".skillshare"), filepath.Join("skills", t.name)); err != nil {
|
||||
ui.Warning("Could not update .skillshare/.gitignore: %v", err)
|
||||
}
|
||||
|
||||
trashPath, err := trash.MoveToTrash(t.path, t.name, trashDir)
|
||||
if err != nil {
|
||||
failed = append(failed, fmt.Sprintf("%s: %v", t.name, err))
|
||||
ui.Warning("Failed to uninstall %s: %v", t.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if t.isTrackedRepo {
|
||||
ui.Success("Uninstalled tracked repository: %s", t.name)
|
||||
} else if groupSkillCount > 0 {
|
||||
ui.Success("Uninstalled group: %s", t.name)
|
||||
// Spinner end state
|
||||
if len(failed) > 0 && len(succeeded) == 0 {
|
||||
sp.Fail(fmt.Sprintf("Failed to uninstall %d %s", len(failed), summary.noun()))
|
||||
} else if len(failed) > 0 {
|
||||
sp.Warn(fmt.Sprintf("Uninstalled %d, failed %d", len(succeeded), len(failed)))
|
||||
} else {
|
||||
ui.Success("Uninstalled skill: %s", t.name)
|
||||
sp.Success(fmt.Sprintf("Uninstalled %d %s", len(succeeded), summary.noun()))
|
||||
}
|
||||
ui.Info("Moved to trash (7 days): %s", trashPath)
|
||||
if meta != nil && meta.Source != "" {
|
||||
ui.Info("Reinstall: skillshare install %s --project", meta.Source)
|
||||
|
||||
// Failures always shown individually
|
||||
var successes []batchResult
|
||||
var failures []batchResult
|
||||
for _, r := range results {
|
||||
if r.errMsg != "" {
|
||||
failures = append(failures, r)
|
||||
} else {
|
||||
successes = append(successes, r)
|
||||
}
|
||||
}
|
||||
|
||||
useSections := len(results) > 10
|
||||
|
||||
if len(failures) > 0 {
|
||||
if useSections {
|
||||
ui.SectionLabel("Failed")
|
||||
} else {
|
||||
fmt.Println()
|
||||
}
|
||||
for _, r := range failures {
|
||||
ui.StepFail(r.target.name, r.errMsg)
|
||||
}
|
||||
}
|
||||
|
||||
// Successes: condensed when many
|
||||
if len(successes) > 0 {
|
||||
if useSections {
|
||||
ui.SectionLabel("Removed")
|
||||
} else {
|
||||
fmt.Println()
|
||||
}
|
||||
switch {
|
||||
case len(successes) > 50:
|
||||
ui.StepDone(fmt.Sprintf("%d uninstalled", len(successes)), "")
|
||||
case len(successes) > 10:
|
||||
const maxShown = 10
|
||||
names := make([]string, 0, maxShown)
|
||||
for i := 0; i < maxShown && i < len(successes); i++ {
|
||||
names = append(names, successes[i].target.name)
|
||||
}
|
||||
detail := strings.Join(names, ", ")
|
||||
if len(successes) > maxShown {
|
||||
detail = fmt.Sprintf("%s ... +%d more", detail, len(successes)-maxShown)
|
||||
}
|
||||
ui.StepDone(fmt.Sprintf("%d uninstalled", len(successes)), detail)
|
||||
default:
|
||||
for _, r := range successes {
|
||||
ui.StepDone(r.target.name, r.typeLabel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Batch summary
|
||||
if useSections {
|
||||
ui.SectionLabel("Next Steps")
|
||||
} else {
|
||||
fmt.Println()
|
||||
}
|
||||
ui.Info("Moved to trash (7 days).")
|
||||
ui.Info("Run 'skillshare sync' to clean up symlinks")
|
||||
|
||||
// Opportunistic cleanup of expired trash items
|
||||
if n, _ := trash.Cleanup(trashDir, 0); n > 0 {
|
||||
ui.Info("Cleaned up %d expired trash item(s)", n)
|
||||
}
|
||||
} else {
|
||||
for _, t := range targets {
|
||||
meta, _ := install.ReadMeta(t.path)
|
||||
groupSkillCount := 0
|
||||
if !t.isTrackedRepo {
|
||||
groupSkillCount = len(countGroupSkills(t.path))
|
||||
}
|
||||
|
||||
// Clean up .gitignore (all project skills have gitignore entries)
|
||||
if _, err := install.RemoveFromGitIgnore(filepath.Join(root, ".skillshare"), filepath.Join("skills", t.name)); err != nil {
|
||||
ui.Warning("Could not update .skillshare/.gitignore: %v", err)
|
||||
}
|
||||
|
||||
trashPath, err := trash.MoveToTrash(t.path, t.name, trashDir)
|
||||
if err != nil {
|
||||
failed = append(failed, fmt.Sprintf("%s: %v", t.name, err))
|
||||
ui.Warning("Failed to uninstall %s: %v", t.name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if t.isTrackedRepo {
|
||||
ui.Success("Uninstalled tracked repository: %s", t.name)
|
||||
} else if groupSkillCount > 0 {
|
||||
ui.Success("Uninstalled group: %s", t.name)
|
||||
} else {
|
||||
ui.Success("Uninstalled skill: %s", t.name)
|
||||
}
|
||||
ui.Info("Moved to trash (7 days): %s", trashPath)
|
||||
if meta != nil && meta.Source != "" {
|
||||
ui.Info("Reinstall: skillshare install %s --project", meta.Source)
|
||||
}
|
||||
succeeded = append(succeeded, t)
|
||||
}
|
||||
succeeded = append(succeeded, t)
|
||||
}
|
||||
|
||||
// --- Phase 7: FINALIZE ---
|
||||
@@ -263,12 +432,14 @@ func cmdUninstallProject(args []string, root string) error {
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
ui.Info("Run 'skillshare sync' to clean up symlinks")
|
||||
if !batch {
|
||||
fmt.Println()
|
||||
ui.Info("Run 'skillshare sync' to clean up symlinks")
|
||||
|
||||
// Opportunistic cleanup of expired trash items
|
||||
if n, _ := trash.Cleanup(trashDir, 0); n > 0 {
|
||||
ui.Info("Cleaned up %d expired trash item(s)", n)
|
||||
// Opportunistic cleanup of expired trash items
|
||||
if n, _ := trash.Cleanup(trashDir, 0); n > 0 {
|
||||
ui.Info("Cleaned up %d expired trash item(s)", n)
|
||||
}
|
||||
}
|
||||
|
||||
if len(failed) > 0 && len(succeeded) == 0 {
|
||||
|
||||
@@ -461,8 +461,9 @@ targets: {}
|
||||
result := sb.RunCLI("uninstall", "fix-review", "security/", "--force")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertOutputContains(t, "Uninstalling 2 group(s)")
|
||||
result.AssertOutputContains(t, "Uninstalled group: fix-review")
|
||||
result.AssertOutputContains(t, "Uninstalled group: security")
|
||||
result.AssertAnyOutputContains(t, "Uninstalled 2 group(s)")
|
||||
result.AssertAnyOutputContains(t, "fix-review")
|
||||
result.AssertAnyOutputContains(t, "security")
|
||||
|
||||
if sb.FileExists(filepath.Join(sb.SourcePath, "fix-review")) {
|
||||
t.Error("fix-review group should be removed")
|
||||
@@ -511,3 +512,125 @@ skills:
|
||||
t.Error("config should still contain keep from other group")
|
||||
}
|
||||
}
|
||||
|
||||
// --- --all tests ---
|
||||
|
||||
func TestUninstall_AllFlag(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
sb.CreateSkill("alpha", map[string]string{"SKILL.md": "# Alpha"})
|
||||
sb.CreateSkill("beta", map[string]string{"SKILL.md": "# Beta"})
|
||||
sb.CreateSkill("gamma", map[string]string{"SKILL.md": "# Gamma"})
|
||||
|
||||
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
||||
targets: {}
|
||||
skills:
|
||||
- name: alpha
|
||||
source: github.com/org/alpha
|
||||
- name: beta
|
||||
source: github.com/org/beta
|
||||
- name: gamma
|
||||
source: github.com/org/gamma
|
||||
`)
|
||||
|
||||
result := sb.RunCLI("uninstall", "--all", "--force")
|
||||
result.AssertSuccess(t)
|
||||
|
||||
for _, name := range []string{"alpha", "beta", "gamma"} {
|
||||
if sb.FileExists(filepath.Join(sb.SourcePath, name)) {
|
||||
t.Errorf("skill %s should be removed after --all", name)
|
||||
}
|
||||
}
|
||||
|
||||
// Config skills should be cleared
|
||||
cfg := sb.ReadFile(sb.ConfigPath)
|
||||
if strings.Contains(cfg, "alpha") || strings.Contains(cfg, "beta") || strings.Contains(cfg, "gamma") {
|
||||
t.Error("config should not contain any skills after --all uninstall")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUninstall_AllProject(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
projectRoot := sb.SetupProjectDir("claude")
|
||||
projectSource := filepath.Join(projectRoot, ".skillshare", "skills")
|
||||
|
||||
sb.CreateProjectSkill(projectRoot, "skill-a", map[string]string{"SKILL.md": "# A"})
|
||||
sb.CreateProjectSkill(projectRoot, "skill-b", map[string]string{"SKILL.md": "# B"})
|
||||
|
||||
sb.WriteProjectConfig(projectRoot, `skills:
|
||||
- name: skill-a
|
||||
source: github.com/org/a
|
||||
- name: skill-b
|
||||
source: github.com/org/b
|
||||
targets: {}
|
||||
`)
|
||||
|
||||
result := sb.RunCLIInDir(projectRoot, "uninstall", "--all", "--force", "-p")
|
||||
result.AssertSuccess(t)
|
||||
|
||||
for _, name := range []string{"skill-a", "skill-b"} {
|
||||
if sb.FileExists(filepath.Join(projectSource, name)) {
|
||||
t.Errorf("skill %s should be removed after --all in project mode", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUninstall_AllMutualExclusion(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
||||
targets: {}
|
||||
`)
|
||||
|
||||
// --all + skill names
|
||||
result := sb.RunCLI("uninstall", "--all", "skill-a")
|
||||
result.AssertFailure(t)
|
||||
result.AssertAnyOutputContains(t, "--all cannot be used with skill names")
|
||||
|
||||
// --all + --group
|
||||
result = sb.RunCLI("uninstall", "--all", "--group", "frontend")
|
||||
result.AssertFailure(t)
|
||||
result.AssertAnyOutputContains(t, "--all cannot be used with --group")
|
||||
}
|
||||
|
||||
func TestUninstall_AllDryRun(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
sb.CreateSkill("dry-all-a", map[string]string{"SKILL.md": "# A"})
|
||||
sb.CreateSkill("dry-all-b", map[string]string{"SKILL.md": "# B"})
|
||||
|
||||
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
||||
targets: {}
|
||||
`)
|
||||
|
||||
result := sb.RunCLI("uninstall", "--all", "-n")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertOutputContains(t, "would move to trash")
|
||||
|
||||
// Skills should NOT be removed
|
||||
if !sb.FileExists(filepath.Join(sb.SourcePath, "dry-all-a")) {
|
||||
t.Error("dry-all-a should not be removed in dry-run")
|
||||
}
|
||||
if !sb.FileExists(filepath.Join(sb.SourcePath, "dry-all-b")) {
|
||||
t.Error("dry-all-b should not be removed in dry-run")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUninstall_ShellGlobDetection(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
||||
targets: {}
|
||||
`)
|
||||
|
||||
// Simulate what happens when shell expands * in a Go project directory
|
||||
result := sb.RunCLI("uninstall", "README.md", "go.mod", "go.sum", "cmd", "internal", "--force")
|
||||
result.AssertFailure(t)
|
||||
result.AssertAnyOutputContains(t, "--all")
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ Remove one or more skills or tracked repositories from the source directory. Ski
|
||||
```bash
|
||||
skillshare uninstall my-skill # Remove a single skill
|
||||
skillshare uninstall a b c --force # Remove multiple skills at once
|
||||
skillshare uninstall --all # Remove all skills
|
||||
skillshare uninstall --group frontend # Remove all skills in a group
|
||||
skillshare uninstall team-repo # Remove tracked repository (_ prefix optional)
|
||||
```
|
||||
@@ -18,6 +19,7 @@ skillshare uninstall team-repo # Remove tracked repository (_ prefix
|
||||
- Remove skills you no longer need (they move to trash for 7 days)
|
||||
- Clean up a tracked repository you've stopped using
|
||||
- Batch-remove an entire group of skills at once
|
||||
- Remove **all** skills at once with `--all`
|
||||
|
||||

|
||||
|
||||
@@ -36,6 +38,7 @@ flowchart TD
|
||||
|
||||
| Flag | Description |
|
||||
|------|-------------|
|
||||
| `--all` | Remove **all** skills from source (requires confirmation) |
|
||||
| `--group, -G <name>` | Remove all skills in a group (prefix match, repeatable) |
|
||||
| `--force, -f` | Skip confirmation and ignore uncommitted changes |
|
||||
| `--dry-run, -n` | Preview without making changes |
|
||||
@@ -51,6 +54,22 @@ skillshare uninstall alpha beta gamma --force
|
||||
|
||||
When some skills are not found, the command **skips them with a warning** and continues removing the rest. It only fails if **all** specified skills are invalid.
|
||||
|
||||
## Remove All
|
||||
|
||||
Use `--all` to remove every skill from the source directory at once:
|
||||
|
||||
```bash
|
||||
skillshare uninstall --all # Interactive confirmation
|
||||
skillshare uninstall --all --force # Skip confirmation
|
||||
skillshare uninstall --all -n # Preview what would be removed
|
||||
```
|
||||
|
||||
`--all` cannot be combined with skill names or `--group`.
|
||||
|
||||
:::tip Shell glob protection
|
||||
Running `skillshare uninstall *` without quotes causes your shell to expand `*` into file names in the current directory. Skillshare detects this and suggests using `--all` instead. Always quote the wildcard (`"*"`) or use `--all`.
|
||||
:::
|
||||
|
||||
## Group Removal
|
||||
|
||||
When you uninstall a directory that contains sub-skills, skillshare automatically detects it as a **group** and lists the contained skills before asking for confirmation:
|
||||
@@ -117,6 +136,11 @@ skillshare uninstall my-skill
|
||||
# Remove multiple skills
|
||||
skillshare uninstall skill-a skill-b skill-c --force
|
||||
|
||||
# Remove all skills
|
||||
skillshare uninstall --all
|
||||
skillshare uninstall --all --force
|
||||
skillshare uninstall --all -n # Preview
|
||||
|
||||
# Remove by group
|
||||
skillshare uninstall --group frontend --force
|
||||
|
||||
@@ -140,12 +164,45 @@ Uninstalled skills are **moved to trash**, not permanently deleted:
|
||||
- **Reinstall hint:** If the skill was installed from a remote source, the reinstall command is shown
|
||||
- **Restore:** Use `skillshare trash restore <name>` to recover from trash
|
||||
|
||||
Single skill (verbose):
|
||||
|
||||
```
|
||||
✓ Uninstalled: my-skill
|
||||
✓ Uninstalled skill: my-skill
|
||||
ℹ Moved to trash (7 days): ~/.local/share/skillshare/trash/my-skill_2026-01-20_15-30-00
|
||||
ℹ Reinstall: skillshare install github.com/user/repo/my-skill
|
||||
```
|
||||
|
||||
Multiple skills (compact batch, ≤10):
|
||||
|
||||
```
|
||||
✓ Uninstalled 4 skill(s) (0.1s)
|
||||
|
||||
✓ pdf skill
|
||||
✓ tdd skill
|
||||
✓ security group, 2 skills
|
||||
✗ bad-skill failed to move to trash: ...
|
||||
|
||||
ℹ Moved to trash (7 days).
|
||||
ℹ Run 'skillshare sync' to update all targets
|
||||
```
|
||||
|
||||
Large batch (>10 targets) uses section labels for readability:
|
||||
|
||||
```
|
||||
✓ Uninstalled 920, failed 2 (1.2s)
|
||||
|
||||
Failed
|
||||
✗ bad-a failed to move to trash: permission denied
|
||||
✗ bad-b failed to move to trash: permission denied
|
||||
|
||||
Removed
|
||||
✓ 920 uninstalled
|
||||
|
||||
Next Steps
|
||||
ℹ Moved to trash (7 days).
|
||||
ℹ Run 'skillshare sync' to update all targets
|
||||
```
|
||||
|
||||
To restore an accidentally uninstalled skill:
|
||||
|
||||
```bash
|
||||
@@ -170,6 +227,7 @@ Uninstall skills or tracked repos from the project's `.skillshare/skills/`:
|
||||
```bash
|
||||
skillshare uninstall my-skill -p # Remove a skill
|
||||
skillshare uninstall a b c -p -f # Remove multiple skills
|
||||
skillshare uninstall --all -p -f # Remove all project skills
|
||||
skillshare uninstall --group frontend -p -f # Remove a group
|
||||
skillshare uninstall team-skills -p # Tracked repo (_ prefix optional)
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user