feat(sync): name targets that sync one folder with different filters

When two targets sync skills into the same folder with different include
or exclude filters, each sync adds what one wants and prunes what the
other filters out, so the folder never settles and sync keeps showing the
same changes. The only hint was a vague overlap count.

sync, doctor and the dashboard's Sync page now name the targets and the
folder, and suggest turning skills off for all but one (universal when it
is among them) instead of removing a target. The Sync page offers the
existing stop-syncing dialog in place. Targets with identical filters are
not reported.
This commit is contained in:
Willie
2026-09-29 11:45:48 +08:00
parent 34db034262
commit e48784f16b
28 changed files with 534 additions and 28 deletions
+22 -2
View File
@@ -23,6 +23,16 @@ func sharedTargetPathsSuggestion(path string, targets []string, isProject bool)
path, targetRemoveDryRunCommand(isProject), strings.Join(targets, ", "))
}
// folderConflictSuggestion says which targets to stop syncing skills for when
// targets share a folder with different settings.
func folderConflictSuggestion(c config.SkillsFolderConflict, isProject bool) string {
cmds := make([]string, 0, len(c.Stop))
for _, name := range c.Stop {
cmds = append(cmds, "`"+skillsOffCommand(name, isProject)+"`")
}
return fmt.Sprintf("Keep %s syncing skills to %s and stop the rest with %s.", c.Keep, c.Path, strings.Join(cmds, ", "))
}
func crossTargetDiscoverySuggestion(scanner string, writers []string, isProject bool) string {
// Point at the scanner first: removing it only affects that runtime, while
// removing a writer also hides skills from every other tool reading its path.
@@ -71,12 +81,22 @@ func checkSharedTargetPaths(cfg *config.Config, result *doctorResult, isProject
return collisions[i].path < collisions[j].path
})
conflicts := make(map[string]config.SkillsFolderConflict)
for _, c := range config.SkillsFolderConflicts(cfg.Targets) {
conflicts[c.Path] = c
}
details := make([]string, 0, len(collisions))
suggestions := make([]string, 0, len(collisions))
for _, c := range collisions {
ui.Warning("Shared path %s ← %s", c.path, strings.Join(c.targets, ", "))
details = append(details, fmt.Sprintf("%s ← %s", c.path, strings.Join(c.targets, ", ")))
detail := fmt.Sprintf("%s ← %s", c.path, strings.Join(c.targets, ", "))
suggestion := sharedTargetPathsSuggestion(c.path, c.targets, isProject)
if conflict, ok := conflicts[c.path]; ok {
detail += " (different filters, so they undo each other on every sync)"
suggestion = folderConflictSuggestion(conflict, isProject)
}
ui.Warning("Shared path %s", detail)
details = append(details, detail)
fmt.Println(ui.DimText(" suggestion: " + suggestion))
suggestions = append(suggestions, suggestion)
result.addWarning()
@@ -271,3 +271,28 @@ func TestDoctorPathChecks_IgnoreSkillsOffTargets(t *testing.T) {
t.Errorf("targets with skills off should not overlap, got %d warning(s): %+v", r.warnings, r.checks)
}
}
func TestCheckSharedTargetPaths_DifferentFiltersSuggestsSkillsOff(t *testing.T) {
cfg := &config.Config{
Targets: map[string]config.TargetConfig{
"universal": {Skills: &config.ResourceTargetConfig{Path: "/tmp/.agents/skills", Exclude: []string{"feature-radar*"}}},
"codex": {Skills: &config.ResourceTargetConfig{Path: "/tmp/.agents/skills"}},
},
}
r := &doctorResult{}
checkSharedTargetPaths(cfg, r, true)
if len(r.checks) != 1 || r.checks[0].Status != checkWarning {
t.Fatalf("expected single warning check, got %+v", r.checks)
}
if detail := r.checks[0].Details[0]; !strings.Contains(detail, "undo each other") {
t.Errorf("detail %q should say the targets undo each other", detail)
}
suggestion := r.checks[0].Suggestions[0]
if !strings.Contains(suggestion, "skillshare target codex --skills=false -p") {
t.Errorf("suggestion %q should turn skills off for codex", suggestion)
}
if strings.Contains(suggestion, "target remove") {
t.Errorf("suggestion %q should not suggest removing a target", suggestion)
}
}
+44 -7
View File
@@ -1,20 +1,57 @@
package main
import (
"fmt"
"strings"
"skillshare/internal/config"
"skillshare/internal/ui"
)
// printSyncOverlapHint emits a single-line warning when enabled targets have
// overlapping skill paths (same primary path or cross-runtime discovery via
// also_scans). Quiet by design — points users at `doctor` for details.
// printSyncOverlapHint warns when enabled targets have overlapping skill paths
// (same primary path or cross-runtime discovery via also_scans). Targets that
// 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) {
if jsonOutput {
return
}
involved := config.DetectPathOverlap(targets, isProject)
if len(involved) == 0 {
return
explained := map[string]bool{}
for _, c := range config.SkillsFolderConflicts(targets) {
ui.Warning("%s sync skills to %s with different filters, so each sync undoes the other",
joinAnd(c.Targets), shortenPath(c.Path))
for _, name := range c.Stop {
fmt.Println(ui.DimText(" keep one: " + skillsOffCommand(name, isProject)))
}
for _, name := range c.Targets {
explained[name] = true
}
}
rest := 0
for _, name := range config.DetectPathOverlap(targets, isProject) {
if !explained[name] {
rest++
}
}
if rest > 0 {
ui.Warning("Skill path overlap across %d target(s) — run `skillshare doctor` for details", rest)
}
ui.Warning("Skill path overlap across %d target(s) — run `skillshare doctor` for details", len(involved))
}
// skillsOffCommand is the command that stops syncing skills to target name.
func skillsOffCommand(name string, isProject bool) string {
cmd := "skillshare target " + name + " --skills=false"
if isProject {
cmd += " -p"
}
return cmd
}
// joinAnd joins names as "a and b" or "a, b and c".
func joinAnd(names []string) string {
if len(names) < 2 {
return strings.Join(names, "")
}
return strings.Join(names[:len(names)-1], ", ") + " and " + names[len(names)-1]
}
+43
View File
@@ -0,0 +1,43 @@
package main
import (
"strings"
"testing"
"skillshare/internal/config"
)
func TestPrintSyncOverlapHint_NamesConflictAndFix(t *testing.T) {
targets := map[string]config.TargetConfig{
"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) })
for _, want := range []string{
"codex and universal sync skills to /tmp/agents/skills with different filters, so each sync undoes the other",
"keep one: skillshare target codex --skills=false -p",
} {
if !strings.Contains(out, want) {
t.Errorf("output missing %q:\n%s", want, out)
}
}
if strings.Contains(out, "Skill path overlap") {
t.Errorf("conflict fully explains the overlap, generic line should be gone:\n%s", out)
}
}
func TestPrintSyncOverlapHint_SameSettingsKeepsGenericLine(t *testing.T) {
targets := map[string]config.TargetConfig{
"universal": {Skills: &config.ResourceTargetConfig{Path: "/tmp/agents/skills"}},
"codex": {Skills: &config.ResourceTargetConfig{Path: "/tmp/agents/skills"}},
}
out := captureStdout(t, func() { printSyncOverlapHint(targets, false, false) })
if !strings.Contains(out, "Skill path overlap across 2 target(s)") {
t.Errorf("expected generic overlap line:\n%s", out)
}
if strings.Contains(out, "undoes") {
t.Errorf("same settings is not a conflict:\n%s", out)
}
}