diff --git a/cmd/skillshare/doctor.go b/cmd/skillshare/doctor.go index ce1c5940a..cd7d37a85 100644 --- a/cmd/skillshare/doctor.go +++ b/cmd/skillshare/doctor.go @@ -260,7 +260,7 @@ func runDoctorChecks(cfg *config.Config, result *doctorResult, isProject bool) { targetCache := checkTargets(cfg, result, isProject) printSymlinkCompatHint(cfg.Targets, cfg.Mode, isProject) checkSharedTargetPaths(cfg, result, isProject) - checkCrossTargetDiscovery(cfg, result, isProject) + checkCrossTargetDiscovery(cfg, result, isProject, discovered) checkSyncDrift(cfg, result, discovered, targetCache) checkBrokenSymlinks(cfg, walk.Follow, result) checkDuplicateSkills(cfg, result, discovered) diff --git a/cmd/skillshare/doctor_shared_paths.go b/cmd/skillshare/doctor_shared_paths.go index aadb54759..db52bef0d 100644 --- a/cmd/skillshare/doctor_shared_paths.go +++ b/cmd/skillshare/doctor_shared_paths.go @@ -3,10 +3,12 @@ package main import ( "fmt" "path/filepath" + "slices" "sort" "strings" "skillshare/internal/config" + "skillshare/internal/sync" "skillshare/internal/ui" ) @@ -40,6 +42,19 @@ func crossTargetDiscoverySuggestion(scanner string, writers []string, isProject scanner, scanner, strings.Join(writers, ", "), scanner, targetRemoveDryRunCommand(isProject), strings.Join(writers, ", ")) } +// scanOffHints says how a runtime can stop reading other targets' folders. +var scanOffHints = map[string]string{ + "opencode": "set OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1 to skip .claude/skills, or OPENCODE_DISABLE_EXTERNAL_SKILLS=1 to also skip .agents/skills", +} + +func leakedSkillsSuggestion(scanner string) string { + s := fmt.Sprintf("These skills are kept from %s by `targets:` or include/exclude, but %s also reads other targets' folders. Allow them for %s", scanner, scanner, scanner) + if hint := scanOffHints[scanner]; hint != "" { + s += ", or where " + scanner + " runs, " + hint + } + return s + "." +} + // checkSharedTargetPaths warns when two or more enabled targets resolve to the // same filesystem path after tilde expansion. // @@ -111,8 +126,9 @@ func checkSharedTargetPaths(cfg *config.Config, result *doctorResult, isProject // target writes to. Catches overlaps that checkSharedTargetPaths misses: // different primary paths but converging runtime discovery (e.g. Codex's // ~/.codex/skills primary plus its ~/.agents/skills also_scans means it sees -// the universal target's content too). -func checkCrossTargetDiscovery(cfg *config.Config, result *doctorResult, isProject bool) { +// the universal target's content too). For a runtime that prefers its own copy +// of a same-named skill, only the skills its filters leave out count. +func checkCrossTargetDiscovery(cfg *config.Config, result *doctorResult, isProject bool, discovered []sync.DiscoveredSkill) { primaryByName := make(map[string]string, len(cfg.Targets)) for name, target := range cfg.Targets { raw := target.SkillsConfig().Path @@ -131,11 +147,14 @@ func checkCrossTargetDiscovery(cfg *config.Config, result *doctorResult, isProje type pathOverlap struct { sharedPath string writers []string + leaked []string } type scannerOverlap struct { scanner string scannerPath string paths []pathOverlap + // known means leaked lists every skill the scanner should not load. + known bool } overlapsByScanner := make(map[string]*scannerOverlap) @@ -150,22 +169,32 @@ func checkCrossTargetDiscovery(cfg *config.Config, result *doctorResult, isProje if !ok { continue } - var others []string + var others, leaked []string + known := true for _, w := range writers { - if w != scanner { - others = append(others, w) + if w == scanner { + continue } + l, ok := sync.LeakedSkills(scanner, w, cfg.Targets, cfg.Mode, cfg.EffectiveSkillsSource(), discovered) + if ok && len(l) == 0 { + continue + } + known = known && ok + others = append(others, w) + leaked = append(leaked, l...) } if len(others) == 0 { continue } sort.Strings(others) + sort.Strings(leaked) so, exists := overlapsByScanner[scanner] if !exists { - so = &scannerOverlap{scanner: scanner, scannerPath: primaryByName[scanner]} + so = &scannerOverlap{scanner: scanner, scannerPath: primaryByName[scanner], known: true} overlapsByScanner[scanner] = so } - so.paths = append(so.paths, pathOverlap{sharedPath: resolved, writers: others}) + so.known = so.known && known + so.paths = append(so.paths, pathOverlap{sharedPath: resolved, writers: others, leaked: slices.Compact(leaked)}) } } @@ -200,6 +229,26 @@ func checkCrossTargetDiscovery(cfg *config.Config, result *doctorResult, isProje } sort.Strings(writers) + if so.known { + leakedSet := map[string]struct{}{} + for _, p := range so.paths { + for _, s := range p.leaked { + leakedSet[s] = struct{}{} + } + } + ui.Warning("%s loads %s kept out of it, from: %s", so.scanner, plural(len(leakedSet), "skill"), strings.Join(writers, ", ")) + for _, p := range so.paths { + ui.Note(fmt.Sprintf("%s ← %s: %s", shortenPath(p.sharedPath), strings.Join(p.writers, ", "), strings.Join(p.leaked, ", "))) + details = append(details, fmt.Sprintf("%s (%s) also scans %s ← %s and loads skills its filters leave out: %s", + so.scanner, so.scannerPath, p.sharedPath, strings.Join(p.writers, ", "), strings.Join(p.leaked, ", "))) + } + suggestion := leakedSkillsSuggestion(so.scanner) + ui.Note("suggestion: " + suggestion) + suggestions = append(suggestions, suggestion) + result.addWarning() + continue + } + ui.Warning("%s will see content from: %s", so.scanner, strings.Join(writers, ", ")) for _, p := range so.paths { ui.Note(fmt.Sprintf("%s ← %s", shortenPath(p.sharedPath), strings.Join(p.writers, ", "))) diff --git a/cmd/skillshare/doctor_shared_paths_test.go b/cmd/skillshare/doctor_shared_paths_test.go index cad8495f0..c385a67a0 100644 --- a/cmd/skillshare/doctor_shared_paths_test.go +++ b/cmd/skillshare/doctor_shared_paths_test.go @@ -6,6 +6,7 @@ import ( "testing" "skillshare/internal/config" + "skillshare/internal/sync" ) func TestCheckSharedTargetPaths_NoCollision(t *testing.T) { @@ -113,7 +114,7 @@ func TestCheckCrossTargetDiscovery_CodexSeesUniversal(t *testing.T) { }, } r := &doctorResult{} - checkCrossTargetDiscovery(cfg, r, false) + checkCrossTargetDiscovery(cfg, r, false, nil) if r.warnings != 1 { t.Fatalf("expected 1 warning, got %d (checks=%+v)", r.warnings, r.checks) @@ -146,7 +147,7 @@ func TestCheckCrossTargetDiscovery_NoOverlapWhenScannerAlone(t *testing.T) { }, } r := &doctorResult{} - checkCrossTargetDiscovery(cfg, r, false) + checkCrossTargetDiscovery(cfg, r, false, nil) if r.warnings != 0 { t.Errorf("expected 0 warnings, got %d", r.warnings) @@ -167,7 +168,7 @@ func TestCheckCrossTargetDiscovery_FirebenderMultiOverlap(t *testing.T) { }, } r := &doctorResult{} - checkCrossTargetDiscovery(cfg, r, false) + checkCrossTargetDiscovery(cfg, r, false, nil) // firebender overlaps with claude AND codex, but grouped into a single // per-scanner warning. The details array still contains one entry per @@ -183,6 +184,47 @@ func TestCheckCrossTargetDiscovery_FirebenderMultiOverlap(t *testing.T) { } } +func opencodeAndClaude(t *testing.T) *config.Config { + t.Setenv("HOME", t.TempDir()) + return &config.Config{ + Source: t.TempDir(), + Mode: "merge", + Targets: map[string]config.TargetConfig{ + "opencode": {Skills: &config.ResourceTargetConfig{Path: "~/.config/opencode/skills"}}, + "claude": {Skills: &config.ResourceTargetConfig{Path: "~/.claude/skills"}}, + }, + } +} + +func TestCheckCrossTargetDiscovery_OpenCodeSameSkillsPasses(t *testing.T) { + // OpenCode reads its own folder last and keeps one skill per name, so a + // skill synced to both folders loads once. + r := &doctorResult{} + checkCrossTargetDiscovery(opencodeAndClaude(t), r, false, []sync.DiscoveredSkill{{FlatName: "shared"}}) + + if r.warnings != 0 || r.checks[0].Status != checkPass { + t.Errorf("expected a passing check, got %+v", r.checks) + } +} + +func TestCheckCrossTargetDiscovery_OpenCodeNamesLeakedSkills(t *testing.T) { + r := &doctorResult{} + checkCrossTargetDiscovery(opencodeAndClaude(t), r, false, []sync.DiscoveredSkill{ + {FlatName: "shared"}, + {FlatName: "claude-only", Targets: []string{"claude"}}, + }) + + if r.warnings != 1 { + t.Fatalf("expected 1 warning, got %d (checks=%+v)", r.warnings, r.checks) + } + if detail := r.checks[0].Details[0]; !strings.Contains(detail, "loads skills its filters leave out: claude-only") { + t.Errorf("detail %q does not name the leaked skill", detail) + } + if s := r.checks[0].Suggestions[0]; !strings.Contains(s, "OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1") { + t.Errorf("suggestion %q does not say how to stop OpenCode reading .claude/skills", s) + } +} + func TestCheckCrossTargetDiscovery_ProjectMode(t *testing.T) { // In project mode, cursor.also_scans.project includes .claude/skills. // If claude (project) writes to .claude/skills, cursor overlaps. @@ -193,7 +235,7 @@ func TestCheckCrossTargetDiscovery_ProjectMode(t *testing.T) { }, } r := &doctorResult{} - checkCrossTargetDiscovery(cfg, r, true) + checkCrossTargetDiscovery(cfg, r, true, nil) if r.warnings == 0 { t.Errorf("expected project-mode warning (cursor scans claude's project path), got 0") @@ -211,7 +253,7 @@ func TestCheckCrossTargetDiscovery_IgnoresScannerOwnPath(t *testing.T) { }, } r := &doctorResult{} - checkCrossTargetDiscovery(cfg, r, false) + checkCrossTargetDiscovery(cfg, r, false, nil) if r.warnings != 0 { t.Errorf("expected 0 warnings, got %d (checks=%+v)", r.warnings, r.checks) @@ -236,7 +278,7 @@ func TestCheckCodexOnUniversalPath_ReportedOnceAsSharedPath(t *testing.T) { } cross := &doctorResult{} - checkCrossTargetDiscovery(cfg, cross, false) + checkCrossTargetDiscovery(cfg, cross, false, nil) if cross.warnings != 0 { t.Errorf("expected 0 cross_target_discovery warnings, got %d (checks=%+v)", cross.warnings, cross.checks) } @@ -268,7 +310,7 @@ func TestDoctorPathChecks_IgnoreSkillsOffTargets(t *testing.T) { } r := &doctorResult{} checkSharedTargetPaths(cfg, r, false) - checkCrossTargetDiscovery(cfg, r, false) + checkCrossTargetDiscovery(cfg, r, false, nil) if r.warnings != 0 { t.Errorf("targets with skills off should not overlap, got %d warning(s): %+v", r.warnings, r.checks) diff --git a/cmd/skillshare/sync.go b/cmd/skillshare/sync.go index 32cec3579..cb05277a2 100644 --- a/cmd/skillshare/sync.go +++ b/cmd/skillshare/sync.go @@ -430,7 +430,7 @@ func cmdSync(args []string) error { printIgnoredSkills(ignoreStats) // One-liner path-overlap hint — points users at `doctor` for details. - printSyncOverlapHint(cfg.Targets, false, jsonOutput) + printSyncOverlapHint(cfg.Targets, false, jsonOutput, cfg.Mode, cfg.EffectiveSkillsSource(), discoveredSkills) // Opportunistic cleanup of expired trash items if !dryRun { diff --git a/cmd/skillshare/sync_overlap_hint.go b/cmd/skillshare/sync_overlap_hint.go index cae58f171..ed8703a8d 100644 --- a/cmd/skillshare/sync_overlap_hint.go +++ b/cmd/skillshare/sync_overlap_hint.go @@ -5,6 +5,7 @@ import ( "strings" "skillshare/internal/config" + "skillshare/internal/sync" "skillshare/internal/theme" "skillshare/internal/ui" ) @@ -14,7 +15,7 @@ import ( // share a folder with different settings undo each other's sync, so they get // a specific line and the command to keep one; any other overlap keeps the // brief line pointing at `doctor`. -func printSyncOverlapHint(targets map[string]config.TargetConfig, isProject, jsonOutput bool) { +func printSyncOverlapHint(targets map[string]config.TargetConfig, isProject, jsonOutput bool, defaultMode, sourcePath string, discovered []sync.DiscoveredSkill) { if jsonOutput { return } @@ -30,7 +31,7 @@ func printSyncOverlapHint(targets map[string]config.TargetConfig, isProject, jso } } rest := 0 - for _, name := range config.DetectPathOverlap(targets, isProject) { + for _, name := range config.DetectPathOverlap(targets, isProject, sync.HarmlessOverlap(targets, defaultMode, sourcePath, discovered)) { if !explained[name] { rest++ } diff --git a/cmd/skillshare/sync_overlap_hint_test.go b/cmd/skillshare/sync_overlap_hint_test.go index 68afe47e7..6c3aae060 100644 --- a/cmd/skillshare/sync_overlap_hint_test.go +++ b/cmd/skillshare/sync_overlap_hint_test.go @@ -6,6 +6,7 @@ import ( "testing" "skillshare/internal/config" + "skillshare/internal/sync" ) func TestPrintSyncOverlapHint_NamesConflictAndFix(t *testing.T) { @@ -14,7 +15,7 @@ func TestPrintSyncOverlapHint_NamesConflictAndFix(t *testing.T) { "universal": {Skills: &config.ResourceTargetConfig{Path: "/tmp/agents/skills", Exclude: []string{"feature-radar*"}}}, "codex": {Skills: &config.ResourceTargetConfig{Path: "/tmp/agents/skills"}}, } - out := captureStdout(t, func() { printSyncOverlapHint(targets, true, false) }) + out := captureStdout(t, func() { printSyncOverlapHint(targets, true, false, "", "", nil) }) for _, want := range []string{ "codex and universal sync skills to " + filepath.FromSlash("/tmp/agents/skills") + " with different filters, so each sync undoes the other", @@ -34,7 +35,7 @@ func TestPrintSyncOverlapHint_SameSettingsKeepsGenericLine(t *testing.T) { "universal": {Skills: &config.ResourceTargetConfig{Path: "/tmp/agents/skills"}}, "codex": {Skills: &config.ResourceTargetConfig{Path: "/tmp/agents/skills"}}, } - out := captureStdout(t, func() { printSyncOverlapHint(targets, false, false) }) + out := captureStdout(t, func() { printSyncOverlapHint(targets, false, false, "", "", nil) }) if !strings.Contains(out, "2 targets share skill folders") { t.Errorf("expected generic overlap line:\n%s", out) @@ -43,3 +44,13 @@ func TestPrintSyncOverlapHint_SameSettingsKeepsGenericLine(t *testing.T) { t.Errorf("same settings is not a conflict:\n%s", out) } } + +func TestPrintSyncOverlapHint_OpenCodeSameSkillsIsQuiet(t *testing.T) { + cfg := opencodeAndClaude(t) + discovered := []sync.DiscoveredSkill{{FlatName: "shared"}} + out := captureStdout(t, func() { printSyncOverlapHint(cfg.Targets, false, false, cfg.Mode, cfg.Source, discovered) }) + + if strings.Contains(out, "share skill folders") { + t.Errorf("opencode loads nothing extra from claude's folder, expected no hint:\n%s", out) + } +} diff --git a/cmd/skillshare/sync_project.go b/cmd/skillshare/sync_project.go index 8fb99c0ed..de065e06d 100644 --- a/cmd/skillshare/sync_project.go +++ b/cmd/skillshare/sync_project.go @@ -129,7 +129,7 @@ func cmdSyncProject(root string, dryRun, force, jsonOutput, quiet bool) (syncLog printIgnoredSkills(ignoreStats) // One-liner path-overlap hint — points users at `doctor` for details. - printSyncOverlapHint(runtime.targets, true, jsonOutput) + printSyncOverlapHint(runtime.targets, true, jsonOutput, "", runtime.sourcePath, discoveredSkills) } // Compute context cost once — used by both text summary and JSON output diff --git a/internal/config/path_overlap.go b/internal/config/path_overlap.go index cda1d2ce4..b90ce853a 100644 --- a/internal/config/path_overlap.go +++ b/internal/config/path_overlap.go @@ -11,8 +11,9 @@ import ( // primary path or by being scanned via cross-runtime discovery (also_scans). // // Used by `sync` (CLI hint) and the Web UI sync handler to surface a brief -// warning that points users at `doctor` for the full breakdown. -func DetectPathOverlap(targets map[string]TargetConfig, isProject bool) []string { +// warning that points users at `doctor` for the full breakdown. A non-nil +// harmless leaves out a scanner reading a writer's folder when it reports true. +func DetectPathOverlap(targets map[string]TargetConfig, isProject bool, harmless func(scanner, writer string) bool) []string { if len(targets) < 2 { return nil } @@ -55,7 +56,7 @@ func DetectPathOverlap(targets map[string]TargetConfig, isProject bool) []string continue } for _, w := range writers { - if w == scanner { + if w == scanner || (harmless != nil && harmless(scanner, w)) { continue } involved[scanner] = struct{}{} diff --git a/internal/config/path_overlap_test.go b/internal/config/path_overlap_test.go index b02877482..37992b7f8 100644 --- a/internal/config/path_overlap_test.go +++ b/internal/config/path_overlap_test.go @@ -11,7 +11,7 @@ func TestDetectPathOverlap_CrossRuntimeDiscovery(t *testing.T) { involved := DetectPathOverlap(map[string]TargetConfig{ "codex": {Skills: &ResourceTargetConfig{Path: "~/.codex/skills"}}, "universal": {Skills: &ResourceTargetConfig{Path: "~/.agents/skills"}}, - }, false) + }, false, nil) for _, want := range []string{"codex", "universal"} { if !slices.Contains(involved, want) { @@ -25,7 +25,7 @@ func TestDetectPathOverlap_CodexSharesUniversalPath(t *testing.T) { involved := DetectPathOverlap(map[string]TargetConfig{ "codex": {Skills: &ResourceTargetConfig{Path: "~/.agents/skills"}}, "universal": {Skills: &ResourceTargetConfig{Path: "~/.agents/skills"}}, - }, false) + }, false, nil) for _, want := range []string{"codex", "universal"} { if !slices.Contains(involved, want) { @@ -40,7 +40,7 @@ func TestDetectPathOverlap_LegacyGoosePathStillWarns(t *testing.T) { involved := DetectPathOverlap(map[string]TargetConfig{ "goose": {Skills: &ResourceTargetConfig{Path: "~/.config/goose/skills"}}, "universal": {Skills: &ResourceTargetConfig{Path: "~/.agents/skills"}}, - }, false) + }, false, nil) for _, want := range []string{"goose", "universal"} { if !slices.Contains(involved, want) { @@ -55,7 +55,7 @@ func TestDetectPathOverlap_IgnoresScannerOwnPath(t *testing.T) { involved := DetectPathOverlap(map[string]TargetConfig{ "claude": {Skills: &ResourceTargetConfig{Path: "~/.claude/skills"}}, "junie": {Skills: &ResourceTargetConfig{Path: "~/.junie/skills"}}, - }, false) + }, false, nil) if len(involved) != 0 { t.Errorf("expected no overlap, got %v", involved) diff --git a/internal/config/skills_enabled_test.go b/internal/config/skills_enabled_test.go index 1cf3fce76..2015390bb 100644 --- a/internal/config/skills_enabled_test.go +++ b/internal/config/skills_enabled_test.go @@ -117,14 +117,14 @@ func TestDetectPathOverlap_IgnoresDisabledTargets(t *testing.T) { involved := DetectPathOverlap(map[string]TargetConfig{ "gemini": disabledAt("~/.gemini/skills"), "universal": {Skills: &ResourceTargetConfig{Path: "~/.agents/skills"}}, - }, false) + }, false, nil) if len(involved) != 0 { t.Fatalf("disabled scanner should not overlap, got %v", involved) } involved = DetectPathOverlap(map[string]TargetConfig{ "codex": disabledAt("~/.agents/skills"), "universal": {Skills: &ResourceTargetConfig{Path: "~/.agents/skills"}}, - }, false) + }, false, nil) if len(involved) != 0 { t.Fatalf("disabled writer should not overlap, got %v", involved) } diff --git a/internal/server/handler_sync.go b/internal/server/handler_sync.go index 0b1e10d2a..340a6a3cd 100644 --- a/internal/server/handler_sync.go +++ b/internal/server/handler_sync.go @@ -125,7 +125,8 @@ type syncOutcome struct { // folderConflicts returns the skills folders whose targets undo each other's // sync, never nil, plus how many targets overlap in a way they don't explain. -func folderConflicts(targets map[string]config.TargetConfig, isProject bool) ([]config.SkillsFolderConflict, int) { +// harmless is passed on to config.DetectPathOverlap. +func folderConflicts(targets map[string]config.TargetConfig, isProject bool, harmless func(scanner, writer string) bool) ([]config.SkillsFolderConflict, int) { conflicts := config.SkillsFolderConflicts(targets) explained := map[string]bool{} for _, c := range conflicts { @@ -134,7 +135,7 @@ func folderConflicts(targets map[string]config.TargetConfig, isProject bool) ([] } } rest := 0 - for _, name := range config.DetectPathOverlap(targets, isProject) { + for _, name := range config.DetectPathOverlap(targets, isProject, harmless) { if !explained[name] { rest++ } @@ -184,8 +185,6 @@ func (s *Server) syncResources(start time.Time, dryRun, force bool, kind, projec maps.Copy(invalid, s.unresolvedTargets) total := len(targets) + len(s.unresolvedTargets) - conflicts, overlap := folderConflicts(s.cfg.Targets, s.IsProjectMode()) - results := make([]syncTargetResult, 0) failed := make([]syncFailure, 0) @@ -384,6 +383,8 @@ func (s *Server) syncResources(start time.Time, dryRun, force bool, kind, projec } s.writeOpsLog("sync", status, start, logArgs, "") + conflicts, overlap := folderConflicts(s.cfg.Targets, s.IsProjectMode(), + ssync.HarmlessOverlap(s.cfg.Targets, globalMode, s.cfg.EffectiveSkillsSource(), allSkills)) return &syncOutcome{results: results, warnings: warnings, failed: failed, folderConflicts: conflicts, pathOverlap: overlap, skills: allSkills, ignoreStats: ignoreStats}, 0, nil } @@ -588,7 +589,7 @@ func (s *Server) handleDiff(w http.ResponseWriter, r *http.Request) { globalMode := s.cfg.Mode ignorePatterns := ssync.EffectiveFileIgnorePatterns(s.cfg.Ignore) targets := s.cloneTargets() - conflicts, _ := folderConflicts(targets, s.IsProjectMode()) + conflicts, _ := folderConflicts(targets, s.IsProjectMode(), nil) s.mu.RUnlock() if globalMode == "" { diff --git a/internal/sync/leaked.go b/internal/sync/leaked.go new file mode 100644 index 000000000..ef1b898fd --- /dev/null +++ b/internal/sync/leaked.go @@ -0,0 +1,58 @@ +package sync + +import ( + "sort" + + "skillshare/internal/config" +) + +// ownFolderLast lists targets whose runtime reads the folders it also scans +// first and its own skills folder last, keeping the last skill of each name. +// A skill synced to both folders then loads once, from the target's own copy. +// OpenCode: packages/opencode/src/skill/index.ts in anomalyco/opencode. +var ownFolderLast = map[string]bool{"opencode": true} + +// LeakedSkills returns the source skills scanner's runtime loads from writer's +// folder although scanner's own filters leave them out. known is false when +// that cannot be told (the runtime's rule for same-named skills is unknown, a +// filter is invalid, or nothing was discovered); every skill in writer's +// folder may then reach scanner. +func LeakedSkills(scanner, writer string, targets map[string]config.TargetConfig, defaultMode, sourcePath string, discovered []DiscoveredSkill) (leaked []string, known bool) { + if !ownFolderLast[scanner] || discovered == nil { + return nil, false + } + own, err := TargetSkills(scanner, targets[scanner], defaultMode, sourcePath, discovered) + if err != nil { + return nil, false + } + theirs, err := TargetSkills(writer, targets[writer], defaultMode, sourcePath, discovered) + if err != nil { + return nil, false + } + + loaded := make(map[string]bool, len(own)) + for _, s := range own { + loaded[s.FlatName] = true + } + // Skills the user put in writer's folder by hand are not skillshare's call. + fromSource := make(map[string]bool, len(discovered)) + for _, s := range discovered { + fromSource[s.FlatName] = true + } + for _, s := range theirs { + if fromSource[s.FlatName] && !loaded[s.FlatName] { + leaked = append(leaked, s.FlatName) + } + } + sort.Strings(leaked) + return leaked, true +} + +// HarmlessOverlap returns a check for config.DetectPathOverlap: scanner reading +// writer's folder is harmless when it loads nothing its own filters leave out. +func HarmlessOverlap(targets map[string]config.TargetConfig, defaultMode, sourcePath string, discovered []DiscoveredSkill) func(scanner, writer string) bool { + return func(scanner, writer string) bool { + leaked, known := LeakedSkills(scanner, writer, targets, defaultMode, sourcePath, discovered) + return known && len(leaked) == 0 + } +} diff --git a/internal/sync/leaked_test.go b/internal/sync/leaked_test.go new file mode 100644 index 000000000..1732fc172 --- /dev/null +++ b/internal/sync/leaked_test.go @@ -0,0 +1,43 @@ +package sync + +import ( + "path/filepath" + "slices" + "testing" + + "skillshare/internal/config" +) + +func leakTargets(t *testing.T, scanner string) map[string]config.TargetConfig { + dir := t.TempDir() + return map[string]config.TargetConfig{ + scanner: {Skills: &config.ResourceTargetConfig{Path: filepath.Join(dir, scanner)}}, + "claude": {Skills: &config.ResourceTargetConfig{Path: filepath.Join(dir, "claude")}}, + } +} + +func TestLeakedSkills_ListsSkillsFilteredFromScanner(t *testing.T) { + discovered := []DiscoveredSkill{ + {FlatName: "shared"}, + {FlatName: "claude-only", Targets: []string{"claude"}}, + } + leaked, known := LeakedSkills("opencode", "claude", leakTargets(t, "opencode"), "merge", t.TempDir(), discovered) + if !known || !slices.Equal(leaked, []string{"claude-only"}) { + t.Errorf("LeakedSkills = %v, %v; want [claude-only], true", leaked, known) + } +} + +func TestLeakedSkills_NoneWhenScannerGetsEverySkill(t *testing.T) { + discovered := []DiscoveredSkill{{FlatName: "shared"}} + leaked, known := LeakedSkills("opencode", "claude", leakTargets(t, "opencode"), "merge", t.TempDir(), discovered) + if !known || len(leaked) != 0 { + t.Errorf("LeakedSkills = %v, %v; want none, true", leaked, known) + } +} + +func TestLeakedSkills_UnknownForOtherRuntimes(t *testing.T) { + discovered := []DiscoveredSkill{{FlatName: "shared"}} + if _, known := LeakedSkills("codex", "claude", leakTargets(t, "codex"), "merge", t.TempDir(), discovered); known { + t.Error("codex's rule for same-named skills is not known; want known=false") + } +} diff --git a/website/docs/reference/commands/doctor.md b/website/docs/reference/commands/doctor.md index ab9802a30..85359d994 100644 --- a/website/docs/reference/commands/doctor.md +++ b/website/docs/reference/commands/doctor.md @@ -166,7 +166,16 @@ When the targets sharing a path have different `include` or `exclude` filters, e Resolution: start by removing the scanning target (`codex` above). Its runtime already reads the shared directory, and no other tool is affected. Preview with `skillshare target remove codex --dry-run`. Removing the writer (`universal`) instead also hides those skills from every other tool that reads `~/.agents/skills`. Keep both targets only if the scanning target carries skills the writer filters out, and accept the duplicate listings in the runtime picker. -Both checks are pure metadata — they read configured paths and the built-in `also_scans` table, no filesystem probing. +OpenCode reads `~/.claude/skills` and `~/.agents/skills` first and its own folder last, keeping one skill per name, so a skill synced to both loads once. For `opencode`, the check only warns about skills it loads from another target's folder although `targets:` or include/exclude keep them out of OpenCode, and names them: + +```text +! opencode loads 1 skill kept out of it, from: claude + ~/.claude/skills ← claude: claude-only +``` + +Resolution: allow those skills for `opencode`, or set `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1` (or `OPENCODE_DISABLE_EXTERNAL_SKILLS=1`, which also skips `.agents/skills`) where OpenCode runs. `doctor` cannot see OpenCode's environment, so the warning stays after you set either variable. + +`shared_target_paths` reads configured paths only. `cross_target_discovery` also reads the built-in `also_scans` table, and for `opencode` the skills each target receives. ### Version diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/doctor.md b/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/doctor.md index 66e9e0b44..e293a61cd 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/doctor.md +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/doctor.md @@ -166,7 +166,16 @@ Doctor は、ランタイムのピッカーに到達する前に、Skill 重複 解決方法: まずスキャンする側の Target(上の例では `codex`)を削除してください。そのランタイムは共有ディレクトリをすでに読み込んでおり、他のツールには影響しません。`skillshare target remove codex --dry-run` でプレビューできます。代わりに書き込み元(`universal`)を削除すると、`~/.agents/skills` を読み込む他のツールからもそれらの skill が見えなくなります。スキャンする側の Target が、書き込み元でフィルタされている skill を持つ場合に限り両方を残し、ランタイムのピッカーでの重複表示を受け入れてください。 -どちらのチェックも純粋なメタデータのみを扱います — 設定済みのパスと組み込みの `also_scans` テーブルを読み取るだけで、ファイルシステムへの実際の探査は行いません。 +OpenCode は `~/.claude/skills` と `~/.agents/skills` を先に読み、自分のフォルダを最後に読みます。同じ名前の skill は 1 つだけ残すため、両方に同期された skill は 1 回だけ読み込まれます。`opencode` については、`targets:` や include/exclude で OpenCode から外した skill を他の target のフォルダから読み込む場合にだけ警告し、その skill を表示します: + +```text +! opencode loads 1 skill kept out of it, from: claude + ~/.claude/skills ← claude: claude-only +``` + +対処:その skill を `opencode` にも許可するか、OpenCode を実行する環境で `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1`(`.agents/skills` も読まない場合は `OPENCODE_DISABLE_EXTERNAL_SKILLS=1`)を設定します。`doctor` からは OpenCode の環境が見えないため、設定後も警告は表示されます。 + +`shared_target_paths` は設定済みのパスだけを読みます。`cross_target_discovery` は組み込みの `also_scans` テーブルも読み、`opencode` については各 target が受け取る skill も確認します。 ### バージョン diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/doctor.md b/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/doctor.md index 1dc69f8b5..1ea03150f 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/doctor.md +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/doctor.md @@ -166,7 +166,16 @@ Doctor는 런타임 피커에 도달하기 전에 두 가지 종류의 중복 sk 해결 방법: 먼저 스캔하는 쪽 target(위 예시의 `codex`)을 제거하십시오. 해당 런타임은 이미 공유 디렉터리를 읽고 있으며, 다른 도구에는 영향을 주지 않습니다. `skillshare target remove codex --dry-run`으로 미리 확인할 수 있습니다. 대신 writer(`universal`)를 제거하면 `~/.agents/skills`를 읽는 다른 도구에서도 해당 skill이 보이지 않게 됩니다. 스캔하는 쪽 target에 writer가 필터링한 skill이 있는 경우에만 둘 다 유지하고, 런타임 피커에 중복 항목이 나타나는 것을 감수하십시오. -두 검사 모두 순수한 메타데이터 기반입니다 — 구성된 경로와 내장된 `also_scans` 테이블을 읽을 뿐, 파일시스템을 직접 프로빙하지 않습니다. +OpenCode는 `~/.claude/skills`와 `~/.agents/skills`를 먼저 읽고 자신의 폴더를 마지막에 읽으며, 이름이 같은 skill은 하나만 남깁니다. 따라서 양쪽에 동기화된 skill은 한 번만 로드됩니다. `opencode`의 경우, `targets:`나 include/exclude로 OpenCode에서 제외한 skill을 다른 target의 폴더에서 로드할 때만 경고하고 해당 skill을 표시합니다: + +```text +! opencode loads 1 skill kept out of it, from: claude + ~/.claude/skills ← claude: claude-only +``` + +해결: 해당 skill을 `opencode`에도 허용하거나, OpenCode를 실행하는 환경에 `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1`(`.agents/skills`도 건너뛰려면 `OPENCODE_DISABLE_EXTERNAL_SKILLS=1`)을 설정합니다. `doctor`는 OpenCode의 환경을 볼 수 없으므로 설정한 뒤에도 경고는 계속 표시됩니다. + +`shared_target_paths`는 구성된 경로만 읽습니다. `cross_target_discovery`는 내장된 `also_scans` 테이블도 읽고, `opencode`의 경우 각 target이 받는 skill도 확인합니다. ### Version diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/doctor.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/doctor.md index e69692fee..931981e45 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/doctor.md +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/doctor.md @@ -170,7 +170,16 @@ Doctor 会在两类重复 skill 风险到达运行时选择器之前将其标记 解决方法:先移除负责扫描的 target(上例中的 `codex`)。它的运行时本来就会读取共享目录,而且不会影响其他工具。可用 `skillshare target remove codex --dry-run` 预览。如果改为移除写入方(`universal`),其他读取 `~/.agents/skills` 的工具也会看不到这些 skill。只有当扫描端 target 带有被写入方过滤掉的 skill 时才同时保留两者,并接受运行时选择器中出现重复列表。 -这两项检查都是纯元数据操作——它们只读取已配置的路径和内置的 `also_scans` 表,不做文件系统探测。 +OpenCode 会先读 `~/.claude/skills` 和 `~/.agents/skills`,最后才读自己的文件夹,同名的 skill 只保留一个,所以同步到两边的 skill 只会加载一次。对 `opencode`,这项检查只在它从其他 target 的文件夹加载了被 `targets:` 或 include/exclude 排除在 OpenCode 之外的 skill 时才警告,并列出这些 skill: + +```text +! opencode loads 1 skill kept out of it, from: claude + ~/.claude/skills ← claude: claude-only +``` + +解决方法:让 `opencode` 也能拿到这些 skill,或在运行 OpenCode 的环境设置 `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1`(或 `OPENCODE_DISABLE_EXTERNAL_SKILLS=1`,连 `.agents/skills` 也跳过)。`doctor` 看不到 OpenCode 的环境,所以设置后警告仍会出现。 + +`shared_target_paths` 只读取已配置的路径。`cross_target_discovery` 也会读内置的 `also_scans` 表,对 `opencode` 还会看每个 target 拿到哪些 skill。 ### Version diff --git a/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/doctor.md b/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/doctor.md index 9a96e8293..3f1ce0a44 100644 --- a/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/doctor.md +++ b/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/doctor.md @@ -166,7 +166,16 @@ Doctor 會在兩類重複 skill 風險到達 runtime picker 之前先標示出 解決方式:先移除負責掃描的 target(上例中的 `codex`)。它的 runtime 本來就會讀取共用目錄,而且不會影響其他工具。可用 `skillshare target remove codex --dry-run` 預覽。若改為移除寫入者(`universal`),其他讀取 `~/.agents/skills` 的工具也會看不到這些 skill。只有在掃描端 target 帶有被寫入者過濾掉的 skill 時才同時保留兩者,並接受 runtime picker 出現重複列表。 -這兩項檢查都是純粹的 metadata 比對——它們讀取已設定的路徑與內建的 `also_scans` 表,不會進行檔案系統探測。 +OpenCode 會先讀 `~/.claude/skills` 和 `~/.agents/skills`,最後才讀自己的資料夾,同名的 skill 只保留一個,所以同步到兩邊的 skill 只會載入一次。對 `opencode`,這項檢查只在它從其他 target 的資料夾載入了被 `targets:` 或 include/exclude 排除在 OpenCode 之外的 skill 時才警告,並列出這些 skill: + +```text +! opencode loads 1 skill kept out of it, from: claude + ~/.claude/skills ← claude: claude-only +``` + +解決方式:讓 `opencode` 也能拿到這些 skill,或在執行 OpenCode 的環境設定 `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1`(或 `OPENCODE_DISABLE_EXTERNAL_SKILLS=1`,連 `.agents/skills` 也略過)。`doctor` 看不到 OpenCode 的環境,所以設定後警告仍會出現。 + +`shared_target_paths` 只讀取已設定的路徑。`cross_target_discovery` 也會讀內建的 `also_scans` 表,對 `opencode` 還會看每個 target 拿到哪些 skill。 ### Version