Skip to content

mission control for agent skills

Fix home global dirs as project roots

Alvin Unrealcf22ea55ceb4
diff --git a/internal/agents/agents.go b/internal/agents/agents.go
index 9e52f68..19f52ad 100644
--- a/internal/agents/agents.go
+++ b/internal/agents/agents.go
@@ -270,6 +270,7 @@ func Locations(cwd string) []Location { return LocationsWithEnv(cwd, DefaultEnv(
func LocationsWithEnv(cwd string, e Env) []Location {
var out []Location
seen := map[string]bool{}
+ globalRoots := map[string]bool{}
add := func(loc Location) {
key := string(loc.Scope) + "\x00" + loc.AgentName + "\x00" + loc.Root
if seen[key] {
@@ -279,8 +280,20 @@ func LocationsWithEnv(cwd string, e Env) []Location {
out = append(out, loc)
}
globalCanonical := filepath.Join(e.Home, ".agents", "skills")
- for _, a := range RegistryWithEnv(e, cwd) {
- add(Location{Root: filepath.Join(cwd, filepath.FromSlash(a.ProjectDir)), Scope: model.ScopeProject, AgentName: a.Name, Canonical: a.Universal})
+ registry := RegistryWithEnv(e, cwd)
+ for _, a := range registry {
+ if a.Universal && a.SupportsGlobal {
+ globalRoots[filepath.Clean(globalCanonical)] = true
+ }
+ if a.SupportsGlobal && a.GlobalDir != "" && a.GlobalDir != globalCanonical {
+ globalRoots[filepath.Clean(a.GlobalDir)] = true
+ }
+ }
+ for _, a := range registry {
+ projectRoot := filepath.Join(cwd, filepath.FromSlash(a.ProjectDir))
+ if !globalRoots[filepath.Clean(projectRoot)] {
+ add(Location{Root: projectRoot, Scope: model.ScopeProject, AgentName: a.Name, Canonical: a.Universal})
+ }
if a.Universal && a.SupportsGlobal {
add(Location{Root: globalCanonical, Scope: model.ScopeGlobal, AgentName: a.Name, Canonical: true})
}
diff --git a/internal/agents/agents_test.go b/internal/agents/agents_test.go
index fe74ba2..d6d4235 100644
--- a/internal/agents/agents_test.go
+++ b/internal/agents/agents_test.go
@@ -157,3 +157,32 @@ func TestZedDetectorUsesConfigAppDataAndFlatpak(t *testing.T) {
t.Fatalf("expected zed detected from Flatpak config")
}
}
+
+func TestLocationsDoNotTreatHomeGlobalDirsAsProjectDirs(t *testing.T) {
+ home := "/home/test"
+ locations := LocationsWithEnv(home, testEnv(home))
+
+ for _, loc := range locations {
+ if loc.Scope != "project" {
+ continue
+ }
+ switch filepath.Clean(loc.Root) {
+ case filepath.Join(home, ".agents", "skills"), filepath.Join(home, ".claude", "skills"), filepath.Join(home, ".codex", "skills"):
+ t.Fatalf("home global dir should not be project location: %#v", loc)
+ }
+ }
+}
+
+func TestLocationsKeepProjectDirsOutsideHome(t *testing.T) {
+ home := "/home/test"
+ cwd := "/repo"
+ locations := LocationsWithEnv(cwd, testEnv(home))
+
+ want := filepath.Join(cwd, ".agents", "skills")
+ for _, loc := range locations {
+ if loc.Scope == "project" && loc.Root == want {
+ return
+ }
+ }
+ t.Fatalf("expected project location %q outside home", want)
+}