mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
Several tools now document the shared ~/.agents/skills directory as their primary skills path. Moving a built-in target there would break three things that assume a tool-specific path: init and the dashboard detect an installed tool through the parent of its skills path, and the overlap checks only consult also_scans, so configs pinned to the old path would silently lose their duplicate-skill warning. Add an optional `detect` install dir per target and derive overlap checks from every path a runtime reads (also_scans plus the built-in default), skipping the target's own configured path. No default changes here, so behaviour is unchanged until a target opts in. Refs #135
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package config
|
|
|
|
import "path/filepath"
|
|
|
|
// DetectPathOverlap returns the set of target names whose configured skill
|
|
// paths overlap with another enabled target — either by sharing the same
|
|
// 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 {
|
|
if len(targets) < 2 {
|
|
return nil
|
|
}
|
|
|
|
primaryByName := make(map[string]string, len(targets))
|
|
for name, target := range targets {
|
|
raw := target.SkillsConfig().Path
|
|
if raw == "" {
|
|
continue
|
|
}
|
|
primaryByName[name] = filepath.Clean(ExpandPath(raw))
|
|
}
|
|
|
|
writersByPath := make(map[string][]string, len(primaryByName))
|
|
for name, p := range primaryByName {
|
|
writersByPath[p] = append(writersByPath[p], name)
|
|
}
|
|
|
|
involved := make(map[string]struct{})
|
|
for _, names := range writersByPath {
|
|
if len(names) < 2 {
|
|
continue
|
|
}
|
|
for _, n := range names {
|
|
involved[n] = struct{}{}
|
|
}
|
|
}
|
|
|
|
for scanner := range primaryByName {
|
|
for _, p := range RuntimeScanPaths(scanner, isProject) {
|
|
resolved := filepath.Clean(p)
|
|
if resolved == primaryByName[scanner] {
|
|
// The scanner's own write path — the shared-primary pass above
|
|
// already covers anyone else writing there.
|
|
continue
|
|
}
|
|
writers, ok := writersByPath[resolved]
|
|
if !ok {
|
|
continue
|
|
}
|
|
for _, w := range writers {
|
|
if w == scanner {
|
|
continue
|
|
}
|
|
involved[scanner] = struct{}{}
|
|
involved[w] = struct{}{}
|
|
}
|
|
}
|
|
}
|
|
|
|
if len(involved) == 0 {
|
|
return nil
|
|
}
|
|
|
|
out := make([]string, 0, len(involved))
|
|
for n := range involved {
|
|
out = append(out, n)
|
|
}
|
|
return out
|
|
}
|