diff --git a/cmd/skillshare/install.go b/cmd/skillshare/install.go index e1f89e01a..e0e8ae2b5 100644 --- a/cmd/skillshare/install.go +++ b/cmd/skillshare/install.go @@ -1246,57 +1246,69 @@ func installFromGlobalConfig(cfg *config.Config, opts install.InstallOptions) (i installed := 0 for _, skill := range cfg.Skills { - skillName := strings.TrimSpace(skill.Name) - if skillName == "" { + groupDir, bareName := skill.EffectiveParts() + if strings.TrimSpace(bareName) == "" { continue } - destPath := filepath.Join(cfg.Source, skillName) + displayName := skill.FullName() + destPath := filepath.Join(cfg.Source, filepath.FromSlash(displayName)) if _, err := os.Stat(destPath); err == nil { - ui.StepDone(skillName, "skipped (already exists)") + ui.StepDone(displayName, "skipped (already exists)") continue } source, err := install.ParseSource(skill.Source) if err != nil { - ui.StepFail(skillName, fmt.Sprintf("invalid source: %v", err)) + ui.StepFail(displayName, fmt.Sprintf("invalid source: %v", err)) continue } - source.Name = skillName + source.Name = bareName if skill.Tracked { - trackedResult, err := install.InstallTrackedRepo(source, cfg.Source, opts) + trackOpts := opts + if groupDir != "" { + trackOpts.Into = groupDir + } + trackedResult, err := install.InstallTrackedRepo(source, cfg.Source, trackOpts) if err != nil { - ui.StepFail(skillName, err.Error()) + ui.StepFail(displayName, err.Error()) continue } if opts.DryRun { - ui.StepDone(skillName, trackedResult.Action) + ui.StepDone(displayName, trackedResult.Action) continue } - ui.StepDone(skillName, fmt.Sprintf("installed (tracked, %d skills)", trackedResult.SkillCount)) + ui.StepDone(displayName, fmt.Sprintf("installed (tracked, %d skills)", trackedResult.SkillCount)) if len(trackedResult.Skills) > 0 { summary.InstalledSkills = append(summary.InstalledSkills, trackedResult.Skills...) } else { - summary.InstalledSkills = append(summary.InstalledSkills, skillName) + summary.InstalledSkills = append(summary.InstalledSkills, displayName) } } else { - if err := validate.SkillName(skillName); err != nil { - ui.StepFail(skillName, fmt.Sprintf("invalid name: %v", err)) + if err := validate.SkillName(bareName); err != nil { + ui.StepFail(displayName, fmt.Sprintf("invalid name: %v", err)) continue } + // Ensure group directory exists + if groupDir != "" { + if err := os.MkdirAll(filepath.Join(cfg.Source, filepath.FromSlash(groupDir)), 0755); err != nil { + ui.StepFail(displayName, fmt.Sprintf("failed to create group directory: %v", err)) + continue + } + } result, err := install.Install(source, destPath, opts) if err != nil { - ui.StepFail(skillName, err.Error()) + ui.StepFail(displayName, err.Error()) continue } if opts.DryRun { - ui.StepDone(skillName, result.Action) + ui.StepDone(displayName, result.Action) continue } - ui.StepDone(skillName, "installed") - summary.InstalledSkills = append(summary.InstalledSkills, skillName) + ui.StepDone(displayName, "installed") + summary.InstalledSkills = append(summary.InstalledSkills, displayName) } installed++ diff --git a/cmd/skillshare/install_project.go b/cmd/skillshare/install_project.go index d23138280..71c7cf5b8 100644 --- a/cmd/skillshare/install_project.go +++ b/cmd/skillshare/install_project.go @@ -221,60 +221,72 @@ func installFromProjectConfig(runtime *projectRuntime, opts install.InstallOptio installed := 0 for _, skill := range runtime.config.Skills { - skillName := strings.TrimSpace(skill.Name) - if skillName == "" { + groupDir, bareName := skill.EffectiveParts() + if strings.TrimSpace(bareName) == "" { continue } - destPath := filepath.Join(runtime.sourcePath, skillName) + displayName := skill.FullName() + destPath := filepath.Join(runtime.sourcePath, filepath.FromSlash(displayName)) if _, err := os.Stat(destPath); err == nil { - ui.StepDone(skillName, "skipped (already exists)") + ui.StepDone(displayName, "skipped (already exists)") continue } source, err := install.ParseSource(skill.Source) if err != nil { - ui.StepFail(skillName, fmt.Sprintf("invalid source: %v", err)) + ui.StepFail(displayName, fmt.Sprintf("invalid source: %v", err)) continue } - source.Name = skillName + source.Name = bareName if skill.Tracked { - trackedResult, err := install.InstallTrackedRepo(source, runtime.sourcePath, opts) + trackOpts := opts + if groupDir != "" { + trackOpts.Into = groupDir + } + trackedResult, err := install.InstallTrackedRepo(source, runtime.sourcePath, trackOpts) if err != nil { - ui.StepFail(skillName, err.Error()) + ui.StepFail(displayName, err.Error()) continue } if opts.DryRun { - ui.StepDone(skillName, trackedResult.Action) + ui.StepDone(displayName, trackedResult.Action) continue } - ui.StepDone(skillName, fmt.Sprintf("installed (tracked, %d skills)", trackedResult.SkillCount)) + ui.StepDone(displayName, fmt.Sprintf("installed (tracked, %d skills)", trackedResult.SkillCount)) if len(trackedResult.Skills) > 0 { summary.InstalledSkills = append(summary.InstalledSkills, trackedResult.Skills...) } else { - summary.InstalledSkills = append(summary.InstalledSkills, skillName) + summary.InstalledSkills = append(summary.InstalledSkills, displayName) } } else { - if err := validate.SkillName(skillName); err != nil { - ui.StepFail(skillName, fmt.Sprintf("invalid name: %v", err)) + if err := validate.SkillName(bareName); err != nil { + ui.StepFail(displayName, fmt.Sprintf("invalid name: %v", err)) continue } + // Ensure group directory exists + if groupDir != "" { + if err := os.MkdirAll(filepath.Join(runtime.sourcePath, filepath.FromSlash(groupDir)), 0755); err != nil { + ui.StepFail(displayName, fmt.Sprintf("failed to create group directory: %v", err)) + continue + } + } result, err := install.Install(source, destPath, opts) if err != nil { - ui.StepFail(skillName, err.Error()) + ui.StepFail(displayName, err.Error()) continue } if opts.DryRun { - ui.StepDone(skillName, result.Action) + ui.StepDone(displayName, result.Action) continue } - if err := install.UpdateGitIgnore(filepath.Join(runtime.root, ".skillshare"), filepath.Join("skills", skillName)); err != nil { + if err := install.UpdateGitIgnore(filepath.Join(runtime.root, ".skillshare"), filepath.Join("skills", displayName)); err != nil { ui.Warning("Failed to update .skillshare/.gitignore: %v", err) } - ui.StepDone(skillName, "installed") - summary.InstalledSkills = append(summary.InstalledSkills, skillName) + ui.StepDone(displayName, "installed") + summary.InstalledSkills = append(summary.InstalledSkills, displayName) } installed++ diff --git a/cmd/skillshare/uninstall.go b/cmd/skillshare/uninstall.go index 6c5e70451..6661987cd 100644 --- a/cmd/skillshare/uninstall.go +++ b/cmd/skillshare/uninstall.go @@ -321,7 +321,7 @@ func cmdUninstall(args []string) error { if err == nil && len(cfg.Skills) > 0 { updated := make([]config.SkillEntry, 0, len(cfg.Skills)) for _, s := range cfg.Skills { - if s.Name != target.name { + if s.FullName() != target.name { updated = append(updated, s) } } diff --git a/cmd/skillshare/uninstall_project.go b/cmd/skillshare/uninstall_project.go index 38d33f7d8..889c639de 100644 --- a/cmd/skillshare/uninstall_project.go +++ b/cmd/skillshare/uninstall_project.go @@ -97,7 +97,7 @@ func cmdUninstallProject(args []string, root string) error { updatedSkills := make([]config.SkillEntry, 0, len(cfg.Skills)) for _, skill := range cfg.Skills { - if skill.Name != skillName { + if skill.FullName() != skillName { updatedSkills = append(updatedSkills, skill) } } diff --git a/internal/config/project.go b/internal/config/project.go index b19fe6cbe..b0c95315d 100644 --- a/internal/config/project.go +++ b/internal/config/project.go @@ -76,6 +76,32 @@ type SkillEntry struct { Name string `yaml:"name"` Source string `yaml:"source"` Tracked bool `yaml:"tracked,omitempty"` + Group string `yaml:"group,omitempty"` +} + +// FullName returns the full relative path for the skill entry. +// If Group is set, returns "group/name"; otherwise returns Name. +// For backward compatibility, if Name already contains "/" and Group is empty, +// returns Name as-is (legacy format). +func (s SkillEntry) FullName() string { + if s.Group != "" { + return s.Group + "/" + s.Name + } + return s.Name +} + +// EffectiveParts returns the effective (group, bareName) for this skill entry. +// If Group is set, returns (Group, Name). +// For backward compat, if Name contains "/" and Group is empty, +// splits at the last "/" to derive group and bare name. +func (s SkillEntry) EffectiveParts() (group, name string) { + if s.Group != "" { + return s.Group, s.Name + } + if idx := strings.LastIndex(s.Name, "/"); idx >= 0 { + return s.Name[:idx], s.Name[idx+1:] + } + return "", s.Name } // ProjectSkill is a type alias kept for backward compatibility. diff --git a/internal/config/project_reconcile.go b/internal/config/project_reconcile.go index ee942928b..a596e6cf8 100644 --- a/internal/config/project_reconcile.go +++ b/internal/config/project_reconcile.go @@ -23,7 +23,18 @@ func ReconcileProjectSkills(projectRoot string, projectCfg *ProjectConfig, sourc changed := false index := map[string]int{} for i, skill := range projectCfg.Skills { - index[skill.Name] = i + index[skill.FullName()] = i + } + + // Migrate legacy entries: name "frontend/pdf" → group "frontend", name "pdf" + for i := range projectCfg.Skills { + s := &projectCfg.Skills[i] + if s.Group == "" && strings.Contains(s.Name, "/") { + group, bare := s.EffectiveParts() + s.Group = group + s.Name = bare + changed = true + } } err := filepath.WalkDir(sourcePath, func(path string, d os.DirEntry, err error) error { @@ -66,10 +77,9 @@ func ReconcileProjectSkills(projectRoot string, projectCfg *ProjectConfig, sourc return nil } - // Use relative path as skill name (e.g. "frontend/pdf" or "_team-repo") - skillName := filepath.ToSlash(relPath) + fullPath := filepath.ToSlash(relPath) - if existingIdx, ok := index[skillName]; ok { + if existingIdx, ok := index[fullPath]; ok { if projectCfg.Skills[existingIdx].Source != source { projectCfg.Skills[existingIdx].Source = source changed = true @@ -79,16 +89,22 @@ func ReconcileProjectSkills(projectRoot string, projectCfg *ProjectConfig, sourc changed = true } } else { - projectCfg.Skills = append(projectCfg.Skills, SkillEntry{ - Name: skillName, + entry := SkillEntry{ Source: source, Tracked: tracked, - }) - index[skillName] = len(projectCfg.Skills) - 1 + } + if idx := strings.LastIndex(fullPath, "/"); idx >= 0 { + entry.Group = fullPath[:idx] + entry.Name = fullPath[idx+1:] + } else { + entry.Name = fullPath + } + projectCfg.Skills = append(projectCfg.Skills, entry) + index[fullPath] = len(projectCfg.Skills) - 1 changed = true } - if err := install.UpdateGitIgnore(filepath.Join(projectRoot, ".skillshare"), filepath.Join("skills", skillName)); err != nil { + if err := install.UpdateGitIgnore(filepath.Join(projectRoot, ".skillshare"), filepath.Join("skills", fullPath)); err != nil { return fmt.Errorf("failed to update .skillshare/.gitignore: %w", err) } diff --git a/internal/config/project_reconcile_test.go b/internal/config/project_reconcile_test.go index 157673dca..916157b00 100644 --- a/internal/config/project_reconcile_test.go +++ b/internal/config/project_reconcile_test.go @@ -127,3 +127,72 @@ func TestReconcileProjectSkills_MissingDir(t *testing.T) { t.Fatalf("ReconcileProjectSkills should not fail for missing dir: %v", err) } } + +func TestReconcileProjectSkills_NestedSkillSetsGroup(t *testing.T) { + root := t.TempDir() + skillsDir := filepath.Join(root, ".skillshare", "skills") + + // Create a nested skill: tools/my-skill + skillPath := filepath.Join(skillsDir, "tools", "my-skill") + if err := os.MkdirAll(skillPath, 0755); err != nil { + t.Fatal(err) + } + meta := map[string]string{"source": "github.com/user/repo"} + data, _ := json.Marshal(meta) + if err := os.WriteFile(filepath.Join(skillPath, ".skillshare-meta.json"), data, 0644); err != nil { + t.Fatal(err) + } + + cfg := &ProjectConfig{ + Targets: []ProjectTargetEntry{{Name: "claude"}}, + } + + if err := ReconcileProjectSkills(root, cfg, skillsDir); err != nil { + t.Fatalf("ReconcileProjectSkills failed: %v", err) + } + + if len(cfg.Skills) != 1 { + t.Fatalf("expected 1 skill, got %d", len(cfg.Skills)) + } + if cfg.Skills[0].Name != "my-skill" { + t.Errorf("expected bare name 'my-skill', got %q", cfg.Skills[0].Name) + } + if cfg.Skills[0].Group != "tools" { + t.Errorf("expected group 'tools', got %q", cfg.Skills[0].Group) + } +} + +func TestReconcileProjectSkills_MigratesLegacySlashName(t *testing.T) { + root := t.TempDir() + skillsDir := filepath.Join(root, ".skillshare", "skills") + + skillPath := filepath.Join(skillsDir, "tools", "my-skill") + if err := os.MkdirAll(skillPath, 0755); err != nil { + t.Fatal(err) + } + meta := map[string]string{"source": "github.com/user/repo"} + data, _ := json.Marshal(meta) + if err := os.WriteFile(filepath.Join(skillPath, ".skillshare-meta.json"), data, 0644); err != nil { + t.Fatal(err) + } + + // Start with legacy format + cfg := &ProjectConfig{ + Targets: []ProjectTargetEntry{{Name: "claude"}}, + Skills: []SkillEntry{{Name: "tools/my-skill", Source: "github.com/user/repo"}}, + } + + if err := ReconcileProjectSkills(root, cfg, skillsDir); err != nil { + t.Fatalf("ReconcileProjectSkills failed: %v", err) + } + + if len(cfg.Skills) != 1 { + t.Fatalf("expected 1 skill, got %d", len(cfg.Skills)) + } + if cfg.Skills[0].Name != "my-skill" { + t.Errorf("expected migrated name 'my-skill', got %q", cfg.Skills[0].Name) + } + if cfg.Skills[0].Group != "tools" { + t.Errorf("expected migrated group 'tools', got %q", cfg.Skills[0].Group) + } +} diff --git a/internal/config/reconcile.go b/internal/config/reconcile.go index 725215b66..ca0711fc8 100644 --- a/internal/config/reconcile.go +++ b/internal/config/reconcile.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "skillshare/internal/install" "skillshare/internal/utils" @@ -22,7 +23,18 @@ func ReconcileGlobalSkills(cfg *Config) error { changed := false index := map[string]int{} for i, skill := range cfg.Skills { - index[skill.Name] = i + index[skill.FullName()] = i + } + + // Migrate legacy entries: name "frontend/pdf" → group "frontend", name "pdf" + for i := range cfg.Skills { + s := &cfg.Skills[i] + if s.Group == "" && strings.Contains(s.Name, "/") { + group, bare := s.EffectiveParts() + s.Group = group + s.Name = bare + changed = true + } } err := filepath.WalkDir(sourcePath, func(path string, d os.DirEntry, err error) error { @@ -60,9 +72,9 @@ func ReconcileGlobalSkills(cfg *Config) error { return nil } - skillName := filepath.ToSlash(relPath) + fullPath := filepath.ToSlash(relPath) - if existingIdx, ok := index[skillName]; ok { + if existingIdx, ok := index[fullPath]; ok { if cfg.Skills[existingIdx].Source != source { cfg.Skills[existingIdx].Source = source changed = true @@ -72,12 +84,18 @@ func ReconcileGlobalSkills(cfg *Config) error { changed = true } } else { - cfg.Skills = append(cfg.Skills, SkillEntry{ - Name: skillName, + entry := SkillEntry{ Source: source, Tracked: tracked, - }) - index[skillName] = len(cfg.Skills) - 1 + } + if idx := strings.LastIndex(fullPath, "/"); idx >= 0 { + entry.Group = fullPath[:idx] + entry.Name = fullPath[idx+1:] + } else { + entry.Name = fullPath + } + cfg.Skills = append(cfg.Skills, entry) + index[fullPath] = len(cfg.Skills) - 1 changed = true } diff --git a/internal/config/reconcile_test.go b/internal/config/reconcile_test.go index ab5e774f9..386563fb1 100644 --- a/internal/config/reconcile_test.go +++ b/internal/config/reconcile_test.go @@ -146,3 +146,88 @@ func TestReconcileGlobalSkills_MissingDir(t *testing.T) { t.Fatalf("ReconcileGlobalSkills should not fail for missing dir: %v", err) } } + +func TestReconcileGlobalSkills_NestedSkillSetsGroup(t *testing.T) { + root := t.TempDir() + sourceDir := filepath.Join(root, "skills") + configPath := filepath.Join(root, "config.yaml") + + // Create a nested skill: frontend/pdf + skillPath := filepath.Join(sourceDir, "frontend", "pdf") + if err := os.MkdirAll(skillPath, 0755); err != nil { + t.Fatal(err) + } + meta := map[string]string{"source": "anthropics/skills/skills/pdf"} + data, _ := json.Marshal(meta) + if err := os.WriteFile(filepath.Join(skillPath, ".skillshare-meta.json"), data, 0644); err != nil { + t.Fatal(err) + } + + cfgData, _ := yaml.Marshal(&Config{Source: sourceDir}) + if err := os.WriteFile(configPath, cfgData, 0644); err != nil { + t.Fatal(err) + } + t.Setenv("SKILLSHARE_CONFIG", configPath) + + cfg := &Config{Source: sourceDir} + + if err := ReconcileGlobalSkills(cfg); err != nil { + t.Fatalf("ReconcileGlobalSkills failed: %v", err) + } + + if len(cfg.Skills) != 1 { + t.Fatalf("expected 1 skill, got %d", len(cfg.Skills)) + } + if cfg.Skills[0].Name != "pdf" { + t.Errorf("expected bare name 'pdf', got %q", cfg.Skills[0].Name) + } + if cfg.Skills[0].Group != "frontend" { + t.Errorf("expected group 'frontend', got %q", cfg.Skills[0].Group) + } + if cfg.Skills[0].FullName() != "frontend/pdf" { + t.Errorf("expected FullName 'frontend/pdf', got %q", cfg.Skills[0].FullName()) + } +} + +func TestReconcileGlobalSkills_MigratesLegacySlashName(t *testing.T) { + root := t.TempDir() + sourceDir := filepath.Join(root, "skills") + configPath := filepath.Join(root, "config.yaml") + + // Create nested skill on disk + skillPath := filepath.Join(sourceDir, "frontend", "pdf") + if err := os.MkdirAll(skillPath, 0755); err != nil { + t.Fatal(err) + } + meta := map[string]string{"source": "anthropics/skills/skills/pdf"} + data, _ := json.Marshal(meta) + if err := os.WriteFile(filepath.Join(skillPath, ".skillshare-meta.json"), data, 0644); err != nil { + t.Fatal(err) + } + + cfgData, _ := yaml.Marshal(&Config{Source: sourceDir}) + if err := os.WriteFile(configPath, cfgData, 0644); err != nil { + t.Fatal(err) + } + t.Setenv("SKILLSHARE_CONFIG", configPath) + + // Start with legacy format: name contains slash, no group + cfg := &Config{ + Source: sourceDir, + Skills: []SkillEntry{{Name: "frontend/pdf", Source: "anthropics/skills/skills/pdf"}}, + } + + if err := ReconcileGlobalSkills(cfg); err != nil { + t.Fatalf("ReconcileGlobalSkills failed: %v", err) + } + + if len(cfg.Skills) != 1 { + t.Fatalf("expected 1 skill, got %d", len(cfg.Skills)) + } + if cfg.Skills[0].Name != "pdf" { + t.Errorf("expected migrated name 'pdf', got %q", cfg.Skills[0].Name) + } + if cfg.Skills[0].Group != "frontend" { + t.Errorf("expected migrated group 'frontend', got %q", cfg.Skills[0].Group) + } +} diff --git a/internal/config/skill_entry_test.go b/internal/config/skill_entry_test.go new file mode 100644 index 000000000..5887b4416 --- /dev/null +++ b/internal/config/skill_entry_test.go @@ -0,0 +1,132 @@ +package config + +import "testing" + +func TestSkillEntry_FullName(t *testing.T) { + tests := []struct { + name string + entry SkillEntry + expected string + }{ + { + name: "simple name without group", + entry: SkillEntry{Name: "pdf"}, + expected: "pdf", + }, + { + name: "with group", + entry: SkillEntry{Name: "pdf", Group: "frontend"}, + expected: "frontend/pdf", + }, + { + name: "with multi-level group", + entry: SkillEntry{Name: "pdf", Group: "frontend/vue"}, + expected: "frontend/vue/pdf", + }, + { + name: "legacy slash name without group", + entry: SkillEntry{Name: "frontend/pdf"}, + expected: "frontend/pdf", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.entry.FullName() + if got != tt.expected { + t.Errorf("FullName() = %q, want %q", got, tt.expected) + } + }) + } +} + +func TestSkillEntry_EffectiveParts(t *testing.T) { + tests := []struct { + name string + entry SkillEntry + expectedGroup string + expectedName string + }{ + { + name: "simple name", + entry: SkillEntry{Name: "pdf"}, + expectedGroup: "", + expectedName: "pdf", + }, + { + name: "with group", + entry: SkillEntry{Name: "pdf", Group: "frontend"}, + expectedGroup: "frontend", + expectedName: "pdf", + }, + { + name: "with multi-level group", + entry: SkillEntry{Name: "pdf", Group: "frontend/vue"}, + expectedGroup: "frontend/vue", + expectedName: "pdf", + }, + { + name: "legacy slash name (backward compat)", + entry: SkillEntry{Name: "frontend/pdf"}, + expectedGroup: "frontend", + expectedName: "pdf", + }, + { + name: "legacy multi-level slash name", + entry: SkillEntry{Name: "frontend/vue/pdf"}, + expectedGroup: "frontend/vue", + expectedName: "pdf", + }, + { + name: "tracked repo no group", + entry: SkillEntry{Name: "_team-skills", Tracked: true}, + expectedGroup: "", + expectedName: "_team-skills", + }, + { + name: "tracked repo with group", + entry: SkillEntry{Name: "_team-skills", Group: "devops", Tracked: true}, + expectedGroup: "devops", + expectedName: "_team-skills", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + group, name := tt.entry.EffectiveParts() + if group != tt.expectedGroup { + t.Errorf("EffectiveParts() group = %q, want %q", group, tt.expectedGroup) + } + if name != tt.expectedName { + t.Errorf("EffectiveParts() name = %q, want %q", name, tt.expectedName) + } + }) + } +} + +func TestSkillEntry_RoundTrip(t *testing.T) { + // FullName should be consistent with EffectiveParts + entries := []SkillEntry{ + {Name: "pdf"}, + {Name: "pdf", Group: "frontend"}, + {Name: "pdf", Group: "frontend/vue"}, + {Name: "frontend/pdf"}, // legacy + } + + for _, entry := range entries { + fullName := entry.FullName() + group, bareName := entry.EffectiveParts() + + // Reconstruct from parts + var reconstructed string + if group != "" { + reconstructed = group + "/" + bareName + } else { + reconstructed = bareName + } + + if reconstructed != fullName { + t.Errorf("round-trip failed for %+v: FullName()=%q, reconstructed=%q", entry, fullName, reconstructed) + } + } +} diff --git a/tests/integration/install_group_test.go b/tests/integration/install_group_test.go new file mode 100644 index 000000000..d7164e73d --- /dev/null +++ b/tests/integration/install_group_test.go @@ -0,0 +1,161 @@ +//go:build !online + +package integration + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "skillshare/internal/testutil" +) + +func TestInstall_Into_RecordsGroupField(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: {} +`) + + // Create a local skill + localSkill := filepath.Join(sb.Root, "pdf-skill") + os.MkdirAll(localSkill, 0755) + os.WriteFile(filepath.Join(localSkill, "SKILL.md"), []byte("# PDF Skill"), 0644) + + // Install with --into frontend + result := sb.RunCLI("install", localSkill, "--into", "frontend") + result.AssertSuccess(t) + + // Verify skill was installed into subdirectory + if !sb.FileExists(filepath.Join(sb.SourcePath, "frontend", "pdf-skill", "SKILL.md")) { + t.Error("skill should be installed to source/frontend/pdf-skill/") + } + + // Read config and verify group field + configContent := sb.ReadFile(sb.ConfigPath) + if !strings.Contains(configContent, "group: frontend") { + t.Errorf("config should contain 'group: frontend', got:\n%s", configContent) + } + // Name should be the bare name, not "frontend/pdf-skill" + if strings.Contains(configContent, "name: frontend/pdf-skill") { + t.Errorf("config should NOT contain legacy slash name 'frontend/pdf-skill', got:\n%s", configContent) + } + if !strings.Contains(configContent, "name: pdf-skill") { + t.Errorf("config should contain bare 'name: pdf-skill', got:\n%s", configContent) + } +} + +func TestInstall_Into_MultiLevel_RecordsGroupField(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: {} +`) + + localSkill := filepath.Join(sb.Root, "ui-skill") + os.MkdirAll(localSkill, 0755) + os.WriteFile(filepath.Join(localSkill, "SKILL.md"), []byte("# UI Skill"), 0644) + + // Install with multi-level --into + result := sb.RunCLI("install", localSkill, "--into", "frontend/vue") + result.AssertSuccess(t) + + // Read config and verify group field + configContent := sb.ReadFile(sb.ConfigPath) + if !strings.Contains(configContent, "group: frontend/vue") { + t.Errorf("config should contain 'group: frontend/vue', got:\n%s", configContent) + } + if !strings.Contains(configContent, "name: ui-skill") { + t.Errorf("config should contain bare 'name: ui-skill', got:\n%s", configContent) + } +} + +func TestInstall_ConfigBased_WithGroup(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + // Create a local skill to use as source + sourceSkill := filepath.Join(sb.Root, "source-pdf") + os.MkdirAll(sourceSkill, 0755) + os.WriteFile(filepath.Join(sourceSkill, "SKILL.md"), []byte("# PDF Skill"), 0644) + + // First install normally with --into to populate config + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: {} +`) + result := sb.RunCLI("install", sourceSkill, "--into", "frontend") + result.AssertSuccess(t) + + // Verify skill exists + skillPath := filepath.Join(sb.SourcePath, "frontend", "source-pdf", "SKILL.md") + if !sb.FileExists(skillPath) { + t.Fatal("skill should exist after initial install") + } + + // Remove the installed skill (simulate fresh machine) + os.RemoveAll(filepath.Join(sb.SourcePath, "frontend")) + + // Now run config-based install — this is the bug fix test + result = sb.RunCLI("install") + result.AssertSuccess(t) + + // Verify skill was recreated in the correct group directory + if !sb.FileExists(skillPath) { + t.Error("config-based install should recreate skill at frontend/source-pdf/") + } +} + +func TestInstall_LegacySlashName_BackwardCompat(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + // Write config with legacy format (name contains slash, no group field) + // This is the format that existed before the group field was added + sourceSkill := filepath.Join(sb.Root, "source-pdf") + os.MkdirAll(sourceSkill, 0755) + os.WriteFile(filepath.Join(sourceSkill, "SKILL.md"), []byte("# PDF"), 0644) + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: {} +skills: + - name: frontend/pdf + source: ` + sourceSkill + ` +`) + + // Config-based install with legacy slash name should still work + result := sb.RunCLI("install") + result.AssertSuccess(t) + + // Verify skill was installed correctly + if !sb.FileExists(filepath.Join(sb.SourcePath, "frontend", "pdf", "SKILL.md")) { + t.Error("legacy slash-name install should place skill at frontend/pdf/") + } +} + +func TestInstallProject_Into_RecordsGroupField(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + projectRoot := sb.SetupProjectDir("claude") + + // Create a source skill + sourceSkill := filepath.Join(sb.Root, "my-skill") + os.MkdirAll(sourceSkill, 0755) + os.WriteFile(filepath.Join(sourceSkill, "SKILL.md"), []byte("---\nname: my-skill\n---\n# My Skill"), 0644) + + // Install with --into in project mode + result := sb.RunCLIInDir(projectRoot, "install", sourceSkill, "--into", "tools", "-p") + result.AssertSuccess(t) + + // Read project config and verify group field + configPath := filepath.Join(projectRoot, ".skillshare", "config.yaml") + configContent := sb.ReadFile(configPath) + if !strings.Contains(configContent, "group: tools") { + t.Errorf("project config should contain 'group: tools', got:\n%s", configContent) + } + if !strings.Contains(configContent, "name: my-skill") { + t.Errorf("project config should contain bare 'name: my-skill', got:\n%s", configContent) + } +} diff --git a/website/docs/concepts/declarative-manifest.md b/website/docs/concepts/declarative-manifest.md index f53553e08..8dd8c75f4 100644 --- a/website/docs/concepts/declarative-manifest.md +++ b/website/docs/concepts/declarative-manifest.md @@ -20,11 +20,13 @@ The `skills:` section in `config.yaml` serves as a **portable declaration** of y skills: - name: react-best-practices source: anthropics/skills/skills/react-best-practices + group: frontend # installed into frontend/ - name: _team-skills source: my-org/shared-skills tracked: true + group: devops # installed into devops/ - name: commit - source: anthropics/skills/skills/commit + source: anthropics/skills/skills/commit # no group → root level ``` ## How It Works @@ -64,6 +66,7 @@ Each entry in the `skills:` list has these fields: | `name` | Yes | Skill name (directory name in source) | | `source` | Yes | Install source (GitHub shorthand, HTTPS URL, SSH URL) | | `tracked` | No | `true` for tracked repositories (preserves `.git`) | +| `group` | No | Subdirectory path (e.g. `frontend` or `frontend/vue`). Corresponds to `--into` during install. | ## Use Cases @@ -102,12 +105,24 @@ Project maintainers declare recommended skills: skills: - name: react-best-practices source: anthropics/skills/skills/react-best-practices + group: frontend - name: commit source: anthropics/skills/skills/commit - name: project-conventions source: ./skills/project-conventions ``` +:::info Group field and `--into` +When you install with `--into`, the group is recorded automatically: + +```bash +skillshare install anthropics/skills/skills/pdf --into frontend +# config.yaml will contain: name: pdf, group: frontend +``` + +Running `skillshare install` (no args) recreates the same directory structure from the manifest. +::: + Contributors clone and run `skillshare install -p` to get project-specific AI context immediately. ## Workflow Summary