mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
fix(sync): skip nested target dotdirs when discovering source skills
Installing a repo whose root is a skill copies the whole repo into the source, including any .claude/skills/ the author keeps for their own development. Install discovery already skips target dotdirs, but the source walk used by sync, check, and the dashboard only skipped .git, so those dev-only skills surfaced as nested skills and were synced to every target. Share the skip set through sourcewalk and apply it in both source walks. Only dotdirs nested below the source root are skipped: host-style paths directly under the root (.cursor/skills/*) stay visible because they drive target inference.
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"skillshare/internal/childproc"
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/install"
|
||||
"skillshare/internal/sourcewalk"
|
||||
"skillshare/internal/theme"
|
||||
"skillshare/internal/ui"
|
||||
versioncheck "skillshare/internal/version"
|
||||
@@ -84,7 +85,9 @@ func main() {
|
||||
versioncheck.Version = version
|
||||
|
||||
// Inject target dotdirs for skill discovery (avoids circular import)
|
||||
install.TargetDotDirs = config.ProjectTargetDotDirs()
|
||||
targetDotDirs := config.ProjectTargetDotDirs()
|
||||
install.TargetDotDirs = targetDotDirs
|
||||
sourcewalk.TargetDotDirs = targetDotDirs
|
||||
|
||||
if len(os.Args) < 2 {
|
||||
printUsage()
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"skillshare/internal/sourcewalk"
|
||||
)
|
||||
|
||||
// --- SkillKind tests ---
|
||||
@@ -15,6 +17,25 @@ func TestSkillKind_Kind(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSkillKind_Discover_SkipsTargetDotDirs(t *testing.T) {
|
||||
orig := sourcewalk.TargetDotDirs
|
||||
sourcewalk.TargetDotDirs = map[string]bool{".claude": true}
|
||||
defer func() { sourcewalk.TargetDotDirs = orig }()
|
||||
|
||||
dir := t.TempDir()
|
||||
os.MkdirAll(filepath.Join(dir, "ffmpeg-skill", ".claude", "skills", "code-review"), 0o755)
|
||||
os.WriteFile(filepath.Join(dir, "ffmpeg-skill", "SKILL.md"), []byte("---\nname: ffmpeg-skill\n---\n# FFmpeg"), 0o644)
|
||||
os.WriteFile(filepath.Join(dir, "ffmpeg-skill", ".claude", "skills", "code-review", "SKILL.md"), []byte("---\nname: code-review\n---\n# Dev only"), 0o644)
|
||||
|
||||
resources, err := SkillKind{}.Discover(dir)
|
||||
if err != nil {
|
||||
t.Fatalf("Discover error: %v", err)
|
||||
}
|
||||
if len(resources) != 1 || resources[0].RelPath != "ffmpeg-skill" {
|
||||
t.Fatalf("expected only ffmpeg-skill (skipping .claude), got %+v", resources)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSkillKind_Discover(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ func (SkillKind) Discover(sourceDir string) ([]DiscoveredResource, error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if info.IsDir() && info.Name() == ".git" {
|
||||
if (info.IsDir() && info.Name() == ".git") || sourcewalk.SkipTargetDotDir(walkRoot, path, info) {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,24 @@ import (
|
||||
"skillshare/internal/utils"
|
||||
)
|
||||
|
||||
// TargetDotDirs is the set of hidden directory names (e.g. ".claude", ".cursor")
|
||||
// that hold target-synced copies rather than source skills. Set by the CLI
|
||||
// entrypoint from config data to avoid a circular import.
|
||||
var TargetDotDirs map[string]bool
|
||||
|
||||
// SkipTargetDotDir reports whether a directory found while walking the source
|
||||
// should be skipped as a target dotdir. Only dotdirs nested below the source
|
||||
// root are skipped: a skill installed from a repo that ships its own
|
||||
// .claude/skills/ must not surface those as nested skills. Dotdirs directly
|
||||
// under the root (e.g. ".cursor/skills/*") stay visible because host-style
|
||||
// paths there are used to infer the skill's targets.
|
||||
func SkipTargetDotDir(walkRoot, path string, info os.FileInfo) bool {
|
||||
if !info.IsDir() || !TargetDotDirs[info.Name()] {
|
||||
return false
|
||||
}
|
||||
return filepath.Dir(path) != walkRoot
|
||||
}
|
||||
|
||||
// Options reserves the operation's traversal policy. The zero value preserves
|
||||
// existing traversal; following entries is not implemented.
|
||||
type Options struct{}
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"skillshare/internal/sourcewalk"
|
||||
)
|
||||
|
||||
func writeSkillMD(t *testing.T, dir, content string) {
|
||||
@@ -73,6 +75,31 @@ func TestDiscoverSourceSkills_SkipsGitDir(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoverSourceSkills_SkipsTargetDotDirs(t *testing.T) {
|
||||
orig := sourcewalk.TargetDotDirs
|
||||
sourcewalk.TargetDotDirs = map[string]bool{".claude": true, ".skillshare": true}
|
||||
defer func() { sourcewalk.TargetDotDirs = orig }()
|
||||
|
||||
src := t.TempDir()
|
||||
// A root-level skill installed from a repo that ships its own .claude/skills/
|
||||
writeSkillMD(t, filepath.Join(src, "ffmpeg-skill"), "---\nname: ffmpeg-skill\n---\n# FFmpeg")
|
||||
writeSkillMD(t, filepath.Join(src, "ffmpeg-skill", ".claude", "skills", "code-review"), "---\nname: code-review\n---\n# Dev only")
|
||||
// A root-level host-style path stays visible (used for target inference)
|
||||
writeSkillMD(t, filepath.Join(src, ".claude", "skills", "host-skill"), "---\nname: host-skill\n---\n# Host")
|
||||
|
||||
skills, err := DiscoverSourceSkills(src)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := map[string]bool{}
|
||||
for _, s := range skills {
|
||||
got[s.RelPath] = true
|
||||
}
|
||||
if len(skills) != 2 || !got["ffmpeg-skill"] || !got[".claude/skills/host-skill"] {
|
||||
t.Fatalf("expected ffmpeg-skill and .claude/skills/host-skill only, got %+v", skills)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoverSourceSkills_SkipsRoot(t *testing.T) {
|
||||
src := t.TempDir()
|
||||
// SKILL.md at root level should be skipped (relPath == ".")
|
||||
|
||||
@@ -165,8 +165,9 @@ func discoverSourceSkillsInternal(sourcePath string, opts discoverOptions) ([]Di
|
||||
return nil // Skip inaccessible paths
|
||||
}
|
||||
|
||||
// Skip .git directory
|
||||
if info.IsDir() && info.Name() == ".git" {
|
||||
// Skip .git and nested target dotdirs (.claude, .cursor, ...) so a skill
|
||||
// that ships its own target copies is not re-discovered as nested skills.
|
||||
if (info.IsDir() && info.Name() == ".git") || sourcewalk.SkipTargetDotDir(walkRoot, path, info) {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user