From 27ad93fae1efbfca0d7e06a206e5e3df603a8bf9 Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 7 Oct 2026 23:44:56 +0800 Subject: [PATCH 1/6] fix(config): reconcile tracked checkouts by exact metadata key Prevent nested tracked repositories from borrowing and migrating a top-level entry with the same basename. Preserve GetByPath fallback for ordinary skills and cover persisted metadata across two reconcile passes. --- internal/config/reconcile_core.go | 5 ++++- internal/config/reconcile_test.go | 36 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/internal/config/reconcile_core.go b/internal/config/reconcile_core.go index 644e305f7..e02e01edd 100644 --- a/internal/config/reconcile_core.go +++ b/internal/config/reconcile_core.go @@ -60,7 +60,10 @@ func reconcileSkillsWalk(sourcePath string, walk sourcewalk.Options, store *inst var source string tracked := install.IsTrackedCheckout(path) - existing := store.GetByPath(fullPath) + existing := store.Get(fullPath) + if !tracked { + existing = store.GetByPath(fullPath) + } if existing != nil && existing.Source != "" { source = existing.Source } else if tracked { diff --git a/internal/config/reconcile_test.go b/internal/config/reconcile_test.go index b5beb7588..e3aa94330 100644 --- a/internal/config/reconcile_test.go +++ b/internal/config/reconcile_test.go @@ -3,6 +3,7 @@ package config import ( "os" "path/filepath" + "reflect" "testing" "skillshare/internal/install" @@ -11,6 +12,41 @@ import ( "gopkg.in/yaml.v3" ) +func TestReconcileGlobalSkills_NestedTrackedRepoWithoutEntry(t *testing.T) { + root := t.TempDir() + sourceDir := filepath.Join(root, "skills") + t.Setenv("SKILLSHARE_CONFIG", filepath.Join(root, "config.yaml")) + remotes := map[string]string{} + for _, name := range []string{"_team", "org/_team"} { + repoRoot := filepath.Join(root, filepath.FromSlash(name)) + if err := os.MkdirAll(repoRoot, 0755); err != nil { + t.Fatal(err) + } + remote := testutil.SetupBareRemoteRepo(t, repoRoot) + testutil.SeedRemoteBranch(t, repoRoot, remote, "main", map[string]string{"README.md": name}) + testutil.RunGit(t, "", "clone", remote, filepath.Join(sourceDir, filepath.FromSlash(name))) + remotes[name] = remote + } + + top := install.MetadataEntry{Source: remotes["_team"], Tracked: true, Branch: "main", FileHashes: map[string]string{"README.md": "unchanged"}} + store := install.NewMetadataStore() + store.Set("_team", &top) + wantTop := top + cfg := &Config{Source: sourceDir} + for pass := 1; pass <= 2; pass++ { + if err := ReconcileGlobalSkills(cfg, store); err != nil { + t.Fatal(err) + } + store = install.LoadMetadataOrNew(sourceDir) + if got := store.Get("_team"); !reflect.DeepEqual(got, &wantTop) { + t.Errorf("pass %d: top-level entry = %+v, want %+v", pass, got, wantTop) + } + if got := store.Get("org/_team"); got == nil || got.Source != remotes["org/_team"] || !got.Tracked || got.Group != "org" || got.Branch != "main" { + t.Errorf("pass %d: nested entry = %+v, want source %q, tracked, group org, branch main", pass, got, remotes["org/_team"]) + } + } +} + func TestReconcileGlobalSkills_AddsNewSkill(t *testing.T) { root := t.TempDir() sourceDir := filepath.Join(root, "skills") From 84ed67b13dcdd5aa593b1b384ec50b37f10eba2e Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 7 Oct 2026 23:51:37 +0800 Subject: [PATCH 2/6] fix(update): accept the org/team shorthand for --into repos in every entry point A repo installed with `--track --into org` lives at `org/_team`. Only POST /api/update accepted `org/team`; the dashboard stream and `update -p` prefixed the whole name (`_org/team`), and global `update` compared the full name with the basename, so each reported not found. Move the candidate rule (the name as typed, then `_` added to the last segment, never leaving the source root) into install.FindTrackedCheckout and the basename match into install.MatchTrackedRepos, and use them from the single update, the stream, project and global CLI update. A shorthand resolves to its own `org/_team`, never to a top-level `_team`; plain names and full paths keep their behavior. --- cmd/skillshare/update_project.go | 13 +-- cmd/skillshare/update_resolve.go | 6 +- internal/install/tracked_resolve.go | 86 +++++++++++++++++++ internal/install/tracked_resolve_test.go | 58 +++++++++++++ internal/server/handler_skills.go | 55 ++---------- .../server/handler_update_shorthand_test.go | 57 ++++++++++++ internal/server/handler_update_stream.go | 15 +--- tests/integration/update_shorthand_test.go | 70 +++++++++++++++ website/docs/reference/commands/update.md | 2 +- .../current/reference/commands/update.md | 2 +- .../current/reference/commands/update.md | 2 +- .../current/reference/commands/update.md | 2 +- .../current/reference/commands/update.md | 2 +- 13 files changed, 287 insertions(+), 83 deletions(-) create mode 100644 internal/install/tracked_resolve.go create mode 100644 internal/install/tracked_resolve_test.go create mode 100644 internal/server/handler_update_shorthand_test.go create mode 100644 tests/integration/update_shorthand_test.go diff --git a/cmd/skillshare/update_project.go b/cmd/skillshare/update_project.go index 34b986a2d..bd3b938e1 100644 --- a/cmd/skillshare/update_project.go +++ b/cmd/skillshare/update_project.go @@ -4,7 +4,6 @@ import ( "fmt" "os" "path/filepath" - "strings" "skillshare/internal/install" "skillshare/internal/sourcewalk" @@ -87,17 +86,7 @@ func cmdUpdateProjectBatch(sourcePath string, opts *updateOptions, projectRoot s continue } - // Normalize _ prefix for tracked repos - repoName := name - if !strings.HasPrefix(repoName, "_") { - prefixed := filepath.Join(sourcePath, "_"+name) - if install.IsTrackedCheckout(prefixed) { - repoName = "_" + name - } - } - repoPath := filepath.Join(sourcePath, repoName) - - if install.IsTrackedCheckout(repoPath) { + if repoName, repoPath := install.FindTrackedCheckout(sourcePath, name); repoPath != "" { if !seen[repoPath] { seen[repoPath] = true targets = append(targets, updateTarget{name: repoName, path: repoPath, isRepo: true}) diff --git a/cmd/skillshare/update_resolve.go b/cmd/skillshare/update_resolve.go index 86b8d386e..ceb7a7af7 100644 --- a/cmd/skillshare/update_resolve.go +++ b/cmd/skillshare/update_resolve.go @@ -26,10 +26,8 @@ func resolveByBasename(sourceDir, name string, walks ...sourcewalk.Options) (upd // Search tracked repos repos, _ := install.GetTrackedRepos(sourceDir, walks...) - for _, r := range repos { - if r == name || filepath.Base(r) == "_"+name || filepath.Base(r) == name { - matches = append(matches, updateTarget{name: r, path: filepath.Join(sourceDir, r), isRepo: true}) - } + for _, r := range install.MatchTrackedRepos(repos, name) { + matches = append(matches, updateTarget{name: r, path: filepath.Join(sourceDir, r), isRepo: true}) } // Search updatable skills diff --git a/internal/install/tracked_resolve.go b/internal/install/tracked_resolve.go new file mode 100644 index 000000000..6f74139ec --- /dev/null +++ b/internal/install/tracked_resolve.go @@ -0,0 +1,86 @@ +package install + +import ( + "fmt" + "path" + "path/filepath" + "slices" + "strings" + + "skillshare/internal/sourcewalk" +) + +// FindTrackedCheckout maps a name typed by the user to a tracked checkout +// under sourceRoot. It tries the name as given, then with "_" added to the +// last path segment, so "org/team" finds the checkout "org/_team" that +// `install --track --into org` creates. A name that would leave sourceRoot +// never matches. It returns the slash-form name relative to sourceRoot and the +// checkout path, or empty strings when nothing matches. +func FindTrackedCheckout(sourceRoot, input string) (name, repoPath string) { + sourceRoot = filepath.Clean(sourceRoot) + for _, candidate := range trackedRepoCandidates(input) { + p := filepath.Join(sourceRoot, filepath.FromSlash(candidate)) + rel, err := filepath.Rel(sourceRoot, p) + if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) { + continue + } + if IsTrackedCheckout(p) { + return candidate, p + } + } + return "", "" +} + +// cleanName turns a typed name into a clean slash path ("org/team/" -> "org/team"). +func cleanName(input string) string { + return path.Clean(filepath.ToSlash(input)) +} + +// trackedRepoCandidates lists the slash-form names a tracked repo may have for +// input: input itself, then input with "_" added to its last path segment. +func trackedRepoCandidates(input string) []string { + input = cleanName(input) + if base := path.Base(input); !strings.HasPrefix(base, "_") { + return []string{input, path.Join(path.Dir(input), "_"+base)} + } + return []string{input} +} + +// MatchTrackedRepos returns the repos (slash paths, as GetTrackedRepos lists +// them) that input names: by full path, with "_" added to the last segment, or +// by basename, with or without its "_". +func MatchTrackedRepos(repos []string, input string) []string { + input = cleanName(input) + candidates := trackedRepoCandidates(input) + var matches []string + for _, repo := range repos { + base := path.Base(repo) + if slices.Contains(candidates, repo) || base == input || base == "_"+input { + matches = append(matches, repo) + } + } + return matches +} + +// ResolveTrackedRepo is FindTrackedCheckout plus a fallback to the one tracked +// repo whose basename matches the name (with or without its "_"). More than +// one such repo is an error. Returns empty strings and no error when nothing +// matches. +func ResolveTrackedRepo(sourceRoot, input string, walk ...sourcewalk.Options) (name, repoPath string, err error) { + if name, repoPath = FindTrackedCheckout(sourceRoot, input); repoPath != "" { + return name, repoPath, nil + } + repos, err := GetTrackedRepos(sourceRoot, walk...) + if err != nil { + return "", "", fmt.Errorf("failed to list tracked repositories: %w", err) + } + matches := MatchTrackedRepos(repos, input) + if len(matches) > 1 { + return "", "", fmt.Errorf("multiple tracked repositories match: %s — use the full path", input) + } + if len(matches) == 0 { + return "", "", nil + } + match := matches[0] + return match, filepath.Join(filepath.Clean(sourceRoot), filepath.FromSlash(match)), nil +} diff --git a/internal/install/tracked_resolve_test.go b/internal/install/tracked_resolve_test.go new file mode 100644 index 000000000..efd4bbf51 --- /dev/null +++ b/internal/install/tracked_resolve_test.go @@ -0,0 +1,58 @@ +package install + +import ( + "os" + "path/filepath" + "testing" +) + +func fakeTrackedRepo(t *testing.T, root, rel string) { + t.Helper() + if err := os.MkdirAll(filepath.Join(root, filepath.FromSlash(rel), ".git"), 0o755); err != nil { + t.Fatal(err) + } +} + +func TestResolveTrackedRepo(t *testing.T) { + root := t.TempDir() + fakeTrackedRepo(t, root, "_team") + fakeTrackedRepo(t, root, "org/_team") + fakeTrackedRepo(t, root, "org/_solo") + fakeTrackedRepo(t, root, "a/_dup") + fakeTrackedRepo(t, root, "b/_dup") + outside := filepath.Join(filepath.Dir(root), filepath.Base(root)+"-outside", "_x") + if err := os.MkdirAll(filepath.Join(outside, ".git"), 0o755); err != nil { + t.Fatal(err) + } + + cases := []struct{ input, want string }{ + {"team", "_team"}, + {"_team", "_team"}, + {"org/team", "org/_team"}, + {"org/_team", "org/_team"}, + {"solo", "org/_solo"}, + {"team/", "_team"}, + {"org/team/", "org/_team"}, + {"./org/_team", "org/_team"}, + {"../" + filepath.Base(root) + "-outside/x", ""}, + {"ghost", ""}, + } + for _, c := range cases { + t.Run(c.input, func(t *testing.T) { + got, path, err := ResolveTrackedRepo(root, c.input) + if err != nil { + t.Fatal(err) + } + if got != c.want { + t.Errorf("name = %q, want %q", got, c.want) + } + if wantPath := filepath.Join(root, filepath.FromSlash(c.want)); c.want != "" && path != wantPath { + t.Errorf("path = %q, want %q", path, wantPath) + } + }) + } + + if _, _, err := ResolveTrackedRepo(root, "dup"); err == nil { + t.Error("expected an ambiguity error for dup") + } +} diff --git a/internal/server/handler_skills.go b/internal/server/handler_skills.go index fb51777c3..9771a59d7 100644 --- a/internal/server/handler_skills.go +++ b/internal/server/handler_skills.go @@ -2,7 +2,6 @@ package server import ( "errors" - "fmt" "net/http" "os" "path/filepath" @@ -537,54 +536,12 @@ func (s *Server) handleUninstallSkill(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusNotFound, "skill not found: "+name) } -// resolveTrackedRepo resolves a repo name (flat or nested) to its directory name -// and absolute path under s.cfg.EffectiveSkillsSource(). Returns ("", "", nil) if not found. -// Returns a non-nil error for ambiguous matches or internal failures. +// resolveTrackedRepo resolves a repo name (flat or nested) to its slash-form +// name and absolute path under s.cfg.EffectiveSkillsSource(). Returns ("", "", nil) +// if not found, and a non-nil error for ambiguous matches or internal failures. func (s *Server) resolveTrackedRepo(input string, walks ...sourcewalk.Options) (string, string, error) { - sourceRoot := filepath.Clean(s.cfg.EffectiveSkillsSource()) - candidates := []string{input} - if !strings.HasPrefix(filepath.Base(input), "_") { - if dir := filepath.Dir(input); dir != "." && dir != "" { - candidates = append(candidates, filepath.ToSlash(filepath.Join(dir, "_"+filepath.Base(input)))) - } else { - candidates = append(candidates, "_"+input) - } + if len(walks) == 0 { + walks = []sourcewalk.Options{s.skillsWalk()} } - for _, candidate := range candidates { - repoPath := filepath.Clean(filepath.Join(sourceRoot, candidate)) - relPath, relErr := filepath.Rel(sourceRoot, repoPath) - if relErr != nil || relPath == ".." || strings.HasPrefix(relPath, ".."+string(filepath.Separator)) { - continue - } - if install.IsTrackedCheckout(repoPath) { - return candidate, repoPath, nil - } - } - - // Fallback: match nested tracked repos by basename. - var walk sourcewalk.Options - if len(walks) > 0 { - walk = walks[0] - } else { - walk = s.skillsWalk() - } - repos, err := install.GetTrackedRepos(s.cfg.EffectiveSkillsSource(), walk) - if err != nil { - return "", "", fmt.Errorf("failed to list tracked repositories: %w", err) - } - var match string - for _, repo := range repos { - base := filepath.Base(repo) - trimmed := strings.TrimPrefix(base, "_") - if base == input || trimmed == input { - if match != "" { - return "", "", fmt.Errorf("multiple tracked repositories match: %s — use the full path", input) - } - match = repo - } - } - if match != "" { - return match, filepath.Join(sourceRoot, match), nil - } - return "", "", nil + return install.ResolveTrackedRepo(s.cfg.EffectiveSkillsSource(), input, walks[0]) } diff --git a/internal/server/handler_update_shorthand_test.go b/internal/server/handler_update_shorthand_test.go new file mode 100644 index 000000000..3d7314b64 --- /dev/null +++ b/internal/server/handler_update_shorthand_test.go @@ -0,0 +1,57 @@ +package server + +import ( + "os" + "path/filepath" + "testing" + + "skillshare/internal/testutil" +) + +// addPendingTrackedRepo clones a tracked repo into src/rel and pushes one more +// commit to its remote, so an update moves HEAD. It returns the checkout path. +func addPendingTrackedRepo(t *testing.T, src, rel string) string { + t.Helper() + base := t.TempDir() + remote := testutil.SetupBareRemoteRepo(t, base) + testutil.SeedRemoteBranch(t, base, remote, "main", map[string]string{"child/SKILL.md": trackedCleanSkill}) + repo := filepath.Join(src, filepath.FromSlash(rel)) + testutil.RunGit(t, "", "clone", remote, repo) + seed := filepath.Join(base, "seed-main") + if err := os.WriteFile(filepath.Join(seed, "child", "SKILL.md"), []byte(trackedCleanSkill+"More help.\n"), 0o644); err != nil { + t.Fatal(err) + } + testutil.RunGit(t, seed, "add", "-A") + testutil.RunGit(t, seed, "commit", "-m", "update") + testutil.RunGit(t, seed, "push", "origin", "HEAD:main") + return repo +} + +// `update org/team` for a repo installed with --into org (org/_team) must +// update that repo and leave a top-level _team alone, on both dashboard routes. +func TestHandleUpdate_ShorthandIntoRepo(t *testing.T) { + for _, route := range []struct { + name string + stream bool + }{{"single", false}, {"stream", true}} { + t.Run(route.name, func(t *testing.T) { + s, src := newTestServer(t) + nested := addPendingTrackedRepo(t, src, "org/_team") + top := addPendingTrackedRepo(t, src, "_team") + topBefore := testutil.RunGit(t, top, "rev-parse", "HEAD") + nestedBefore := testutil.RunGit(t, nested, "rev-parse", "HEAD") + + results := runFollowUpdate(t, s, route.stream, "org/team") + + if len(results) != 1 || results[0].Name != "org/_team" || results[0].Action != "updated" { + t.Fatalf("results = %+v, want org/_team updated", results) + } + if got := testutil.RunGit(t, nested, "rev-parse", "HEAD"); got == nestedBefore { + t.Error("org/_team was not updated") + } + if got := testutil.RunGit(t, top, "rev-parse", "HEAD"); got != topBefore { + t.Error("top-level _team was updated by the org/team shorthand") + } + }) + } +} diff --git a/internal/server/handler_update_stream.go b/internal/server/handler_update_stream.go index b9c268f44..ac8cb7b86 100644 --- a/internal/server/handler_update_stream.go +++ b/internal/server/handler_update_stream.go @@ -59,22 +59,11 @@ func (s *Server) handleUpdateStream(w http.ResponseWriter, r *http.Request) { items = append(items, updateItem{name: name, invalid: true}) continue } - // Check if it's a tracked repo (a _-prefixed checkout; an unprefixed one is a regular skill) - repoName := name - if !strings.HasPrefix(repoName, "_") { - repoName = "_" + name - } - repoPath := filepath.Join(source, repoName) - if install.IsTrackedCheckout(repoPath) { + // A tracked repo (a _-prefixed checkout; an unprefixed one is a regular skill) + if repoName, repoPath := install.FindTrackedCheckout(source, name); repoPath != "" { items = append(items, updateItem{name: repoName, isRepo: true, path: repoPath}) continue } - // Check original name as repo - origPath := filepath.Join(source, name) - if install.IsTrackedCheckout(origPath) { - items = append(items, updateItem{name: name, isRepo: true, path: origPath}) - continue - } // Regular skill skillPath := filepath.Join(source, name) items = append(items, updateItem{name: name, isRepo: false, path: skillPath}) diff --git a/tests/integration/update_shorthand_test.go b/tests/integration/update_shorthand_test.go new file mode 100644 index 000000000..151d8e4f3 --- /dev/null +++ b/tests/integration/update_shorthand_test.go @@ -0,0 +1,70 @@ +//go:build !online + +package integration + +import ( + "path/filepath" + "strings" + "testing" + + "skillshare/internal/testutil" +) + +// addPendingTrackedRepo clones a tracked repo into sourceDir/rel and pushes one +// more commit to its remote, so an update changes my-skill/SKILL.md. +func addPendingTrackedRepo(t *testing.T, sb *testutil.Sandbox, sourceDir, rel string) string { + t.Helper() + repoPath := filepath.Join(sourceDir, filepath.FromSlash(rel)) + remoteDir := filepath.Join(t.TempDir(), "remote.git") + run(t, "", "git", "init", "--bare", remoteDir) + run(t, sb.Root, "git", "clone", remoteDir, repoPath) + sb.WriteFile(filepath.Join(repoPath, "my-skill", "SKILL.md"), "---\nname: my-skill\n---\n# Clean") + run(t, repoPath, "git", "add", "-A") + run(t, repoPath, "git", "commit", "-m", "init") + run(t, repoPath, "git", "push", "origin", "HEAD") + + workDir := filepath.Join(t.TempDir(), "work") + run(t, sb.Root, "git", "clone", remoteDir, workDir) + sb.WriteFile(filepath.Join(workDir, "my-skill", "SKILL.md"), "---\nname: my-skill\n---\n# Updated clean") + run(t, workDir, "git", "add", "-A") + run(t, workDir, "git", "commit", "-m", "update") + run(t, workDir, "git", "push", "origin", "HEAD") + return repoPath +} + +// `update org/team` for a repo installed with --into org (org/_team) must +// update that repo, never a top-level _team that sits next to it. +func assertShorthandUpdatesNestedRepo(t *testing.T, sb *testutil.Sandbox, sourceDir string, update func(name string) *testutil.Result) { + t.Helper() + nested := addPendingTrackedRepo(t, sb, sourceDir, "org/_team") + top := addPendingTrackedRepo(t, sb, sourceDir, "_team") + + update("org/team").AssertSuccess(t) + + if got := sb.ReadFile(filepath.Join(nested, "my-skill", "SKILL.md")); !strings.Contains(got, "Updated clean") { + t.Errorf("org/_team was not updated, got %q", got) + } + if got := sb.ReadFile(filepath.Join(top, "my-skill", "SKILL.md")); strings.Contains(got, "Updated clean") { + t.Errorf("top-level _team was updated by the org/team shorthand") + } +} + +func TestUpdate_ShorthandIntoRepo(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + setupGlobalConfig(sb) + + assertShorthandUpdatesNestedRepo(t, sb, sb.SourcePath, func(name string) *testutil.Result { + return sb.RunCLI("update", name) + }) +} + +func TestUpdateProject_ShorthandIntoRepo(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + projectRoot := sb.SetupProjectDir("claude") + + assertShorthandUpdatesNestedRepo(t, sb, filepath.Join(projectRoot, ".skillshare", "skills"), func(name string) *testutil.Result { + return sb.RunCLIInDir(projectRoot, "update", name, "-p") + }) +} diff --git a/website/docs/reference/commands/update.md b/website/docs/reference/commands/update.md index 6bc94444e..64cc15e7c 100644 --- a/website/docs/reference/commands/update.md +++ b/website/docs/reference/commands/update.md @@ -408,7 +408,7 @@ skillshare update --all -p --skip-audit # Skip security audit gate | **Local-path install** | Re-copy from the recorded path | Listed in `.metadata.json` with `type: local` | | **Local skill** | Skipped | Not listed in `.metadata.json` | -The `_` prefix is optional — `skillshare update team-skills -p` auto-detects `_team-skills`. +The `_` prefix is optional, on the last path segment too — `skillshare update team-skills -p` auto-detects `_team-skills`, and `skillshare update devops/team-skills` finds a repo installed with `--into devops` at `devops/_team-skills`. ### Lockfile diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/update.md b/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/update.md index 4411dbe8e..f7b40b17b 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/update.md +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/update.md @@ -408,7 +408,7 @@ skillshare update --all -p --skip-audit # security audit gate をスキップ | **ローカルパスからのインストール** | 記録されたパスから再コピー | `.metadata.json` に `type: local` で記載されている | | **Local skill** | スキップ | `.metadata.json` に記載されていない | -`_` prefix は省略可能です — `skillshare update team-skills -p` は自動的に `_team-skills` を検出します。 +`_` prefix は最後のパス区間でも省略可能です — `skillshare update team-skills -p` は自動的に `_team-skills` を検出し、`skillshare update devops/team-skills` は `--into devops` でインストールした `devops/_team-skills` を検出します。 ### ロックファイル diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/update.md b/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/update.md index a3d0cdfe2..cf2162996 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/update.md +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/update.md @@ -408,7 +408,7 @@ skillshare update --all -p --skip-audit # 보안 audit gate 건너뛰기 | **로컬 경로 설치** | 기록된 경로에서 다시 복사 | `.metadata.json`에 `type: local`로 등록됨 | | **Local skill** | 건너뜀 | `.metadata.json`에 등록되지 않음 | -`_` 접두사는 선택 사항입니다 — `skillshare update team-skills -p`는 `_team-skills`를 자동으로 감지합니다. +`_` 접두사는 경로의 마지막 구간에서도 선택 사항입니다 — `skillshare update team-skills -p`는 `_team-skills`를 자동으로 감지하고, `skillshare update devops/team-skills`는 `--into devops`로 설치한 `devops/_team-skills`를 찾습니다. ### Lockfile diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/update.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/update.md index 6f83b088d..1390ec6c3 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/update.md +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/update.md @@ -408,7 +408,7 @@ skillshare update --all -p --skip-audit # Skip security audit gate | **Local-path install** | Re-copy from the recorded path | Listed in `.metadata.json` with `type: local` | | **Local skill** | Skipped | Not listed in `.metadata.json` | -`_` 前缀是可选的——`skillshare update team-skills -p` 会自动检测为 `_team-skills`。 +`_` 前缀是可选的,路径的最后一段也一样——`skillshare update team-skills -p` 会自动检测为 `_team-skills`,`skillshare update devops/team-skills` 会找到以 `--into devops` 安装的 `devops/_team-skills`。 ### 锁定文件 diff --git a/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/update.md b/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/update.md index 782d0ebf2..b0736b6b7 100644 --- a/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/update.md +++ b/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/update.md @@ -408,7 +408,7 @@ skillshare update --all -p --skip-audit # 跳過安全性 audit 關卡 | **從本機路徑安裝** | 從記錄的路徑重新複製 | 列於 `.metadata.json`,且 `type: local` | | **本機 skill** | 跳過 | 未列於 `.metadata.json` | -`_` 前綴是選填的 — `skillshare update team-skills -p` 會自動偵測為 `_team-skills`。 +`_` 前綴是選填的,路徑最後一段也一樣 — `skillshare update team-skills -p` 會自動偵測為 `_team-skills`,`skillshare update devops/team-skills` 會找到以 `--into devops` 安裝的 `devops/_team-skills`。 ### Lockfile From 79e080cb13b65358c06f8d74f3069b22daa57d27 Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 7 Oct 2026 23:52:04 +0800 Subject: [PATCH 3/6] fix(config): preserve grouped legacy tracked metadata Keep exact checkout lookup first, but permit legacy basename metadata only when its group matches the checkout parent. This prevents unrelated sibling adoption while preserving custom source, branch and hashes during migration; add a regression for the Codex P2 finding. --- internal/config/reconcile_core.go | 5 ++++- internal/config/reconcile_test.go | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/internal/config/reconcile_core.go b/internal/config/reconcile_core.go index e02e01edd..b8e021854 100644 --- a/internal/config/reconcile_core.go +++ b/internal/config/reconcile_core.go @@ -61,8 +61,11 @@ func reconcileSkillsWalk(sourcePath string, walk sourcewalk.Options, store *inst tracked := install.IsTrackedCheckout(path) existing := store.Get(fullPath) - if !tracked { + if existing == nil || !tracked { existing = store.GetByPath(fullPath) + if tracked && existing != nil && existing.Group != group { + existing = nil + } } if existing != nil && existing.Source != "" { source = existing.Source diff --git a/internal/config/reconcile_test.go b/internal/config/reconcile_test.go index e3aa94330..fe43e62ff 100644 --- a/internal/config/reconcile_test.go +++ b/internal/config/reconcile_test.go @@ -47,6 +47,29 @@ func TestReconcileGlobalSkills_NestedTrackedRepoWithoutEntry(t *testing.T) { } } +func TestReconcileGlobalSkills_NestedTrackedRepoLegacyEntry(t *testing.T) { + root := t.TempDir() + sourceDir := filepath.Join(root, "skills") + t.Setenv("SKILLSHARE_CONFIG", filepath.Join(root, "config.yaml")) + remote := testutil.SetupBareRemoteRepo(t, root) + testutil.SeedRemoteBranch(t, root, remote, "main", map[string]string{"README.md": "# team"}) + testutil.RunGit(t, "", "clone", remote, filepath.Join(sourceDir, "org", "_team")) + store := install.NewMetadataStore() + want := install.MetadataEntry{Source: "github.com/example/team/custom", Tracked: true, Group: "org", Branch: "custom", FileHashes: map[string]string{"README.md": "unchanged"}} + entry := want + store.Set("_team", &entry) + if err := ReconcileGlobalSkills(&Config{Source: sourceDir}, store); err != nil { + t.Fatal(err) + } + store = install.LoadMetadataOrNew(sourceDir) + if got := store.Get("org/_team"); !reflect.DeepEqual(got, &want) { + t.Errorf("migrated entry = %+v, want %+v", got, want) + } + if store.Has("_team") { + t.Error("legacy key was not migrated") + } +} + func TestReconcileGlobalSkills_AddsNewSkill(t *testing.T) { root := t.TempDir() sourceDir := filepath.Join(root, "skills") From 414d193114a5a47a844f51eac945bdc3a3bef7ca Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 7 Oct 2026 23:58:43 +0800 Subject: [PATCH 4/6] fix(update): keep an existing skill ahead of the nested shorthand Codex review of #481 found three problems with the shorthand change: - `update org/team -p` and the dashboard stream updated the org/_team repo even when a skill exists at org/team, which used to win because the shorthand was not rewritten there. FindTrackedCheckoutUnlessSkill skips the nested shorthand when a directory exists at the typed path; plain names keep their repo-first behavior. - Global `update team/` cleaned the name for repo matching but not for skill matching, so it silently updated `_team` instead of reporting the skill/repo collision that `update team` reports. resolveByBasename now cleans the name once for both. - The update.md example sits in the Project Mode section but lacked -p (also in the four translations). --- cmd/skillshare/update_project.go | 2 +- cmd/skillshare/update_resolve.go | 2 ++ internal/install/tracked_resolve.go | 17 ++++++++++ .../server/handler_update_shorthand_test.go | 14 +++++++++ internal/server/handler_update_stream.go | 2 +- tests/integration/update_shorthand_test.go | 31 +++++++++++++++++++ website/docs/reference/commands/update.md | 2 +- .../current/reference/commands/update.md | 2 +- .../current/reference/commands/update.md | 2 +- .../current/reference/commands/update.md | 2 +- .../current/reference/commands/update.md | 2 +- 11 files changed, 71 insertions(+), 7 deletions(-) diff --git a/cmd/skillshare/update_project.go b/cmd/skillshare/update_project.go index bd3b938e1..65858fb78 100644 --- a/cmd/skillshare/update_project.go +++ b/cmd/skillshare/update_project.go @@ -86,7 +86,7 @@ func cmdUpdateProjectBatch(sourcePath string, opts *updateOptions, projectRoot s continue } - if repoName, repoPath := install.FindTrackedCheckout(sourcePath, name); repoPath != "" { + if repoName, repoPath := install.FindTrackedCheckoutUnlessSkill(sourcePath, name); repoPath != "" { if !seen[repoPath] { seen[repoPath] = true targets = append(targets, updateTarget{name: repoName, path: repoPath, isRepo: true}) diff --git a/cmd/skillshare/update_resolve.go b/cmd/skillshare/update_resolve.go index ceb7a7af7..d49b84c3c 100644 --- a/cmd/skillshare/update_resolve.go +++ b/cmd/skillshare/update_resolve.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "path" "path/filepath" "sort" "strings" @@ -22,6 +23,7 @@ type updateTarget struct { // resolveByBasename searches nested skills and tracked repos by their // directory basename. Returns an error when zero or multiple matches found. func resolveByBasename(sourceDir, name string, walks ...sourcewalk.Options) (updateTarget, error) { + name = path.Clean(filepath.ToSlash(name)) // "team/" names the same item as "team" var matches []updateTarget // Search tracked repos diff --git a/internal/install/tracked_resolve.go b/internal/install/tracked_resolve.go index 6f74139ec..40cdd82eb 100644 --- a/internal/install/tracked_resolve.go +++ b/internal/install/tracked_resolve.go @@ -2,6 +2,7 @@ package install import ( "fmt" + "os" "path" "path/filepath" "slices" @@ -31,6 +32,22 @@ func FindTrackedCheckout(sourceRoot, input string) (name, repoPath string) { return "", "" } +// FindTrackedCheckoutUnlessSkill is FindTrackedCheckout, except that the +// shorthand inside a folder (org/team -> org/_team) does not apply when a +// directory already exists at org/team: that is the skill the name refers to. +func FindTrackedCheckoutUnlessSkill(sourceRoot, input string) (name, repoPath string) { + name, repoPath = FindTrackedCheckout(sourceRoot, input) + if repoPath == "" { + return "", "" + } + if typed := cleanName(input); name != typed && path.Dir(name) != "." { + if info, err := os.Stat(filepath.Join(sourceRoot, filepath.FromSlash(typed))); err == nil && info.IsDir() { + return "", "" + } + } + return name, repoPath +} + // cleanName turns a typed name into a clean slash path ("org/team/" -> "org/team"). func cleanName(input string) string { return path.Clean(filepath.ToSlash(input)) diff --git a/internal/server/handler_update_shorthand_test.go b/internal/server/handler_update_shorthand_test.go index 3d7314b64..9f3537098 100644 --- a/internal/server/handler_update_shorthand_test.go +++ b/internal/server/handler_update_shorthand_test.go @@ -55,3 +55,17 @@ func TestHandleUpdate_ShorthandIntoRepo(t *testing.T) { }) } } + +// A skill that exists at org/team is what the name refers to; the shorthand +// must not send the update to org/_team instead. +func TestHandleUpdateStream_ExistingSkillBeatsShorthand(t *testing.T) { + s, src := newTestServer(t) + addSkill(t, src, "org/team") + addTrackedRepo(t, src, "org/_team") + + results := runFollowUpdate(t, s, true, "org/team") + + if len(results) != 1 || results[0].Name != "org/team" || results[0].IsRepo { + t.Fatalf("results = %+v, want the org/team skill, not the org/_team repo", results) + } +} diff --git a/internal/server/handler_update_stream.go b/internal/server/handler_update_stream.go index ac8cb7b86..1ab5fde81 100644 --- a/internal/server/handler_update_stream.go +++ b/internal/server/handler_update_stream.go @@ -60,7 +60,7 @@ func (s *Server) handleUpdateStream(w http.ResponseWriter, r *http.Request) { continue } // A tracked repo (a _-prefixed checkout; an unprefixed one is a regular skill) - if repoName, repoPath := install.FindTrackedCheckout(source, name); repoPath != "" { + if repoName, repoPath := install.FindTrackedCheckoutUnlessSkill(source, name); repoPath != "" { items = append(items, updateItem{name: repoName, isRepo: true, path: repoPath}) continue } diff --git a/tests/integration/update_shorthand_test.go b/tests/integration/update_shorthand_test.go index 151d8e4f3..e4240b386 100644 --- a/tests/integration/update_shorthand_test.go +++ b/tests/integration/update_shorthand_test.go @@ -68,3 +68,34 @@ func TestUpdateProject_ShorthandIntoRepo(t *testing.T) { return sb.RunCLIInDir(projectRoot, "update", name, "-p") }) } + +// A skill at org/team is what `update org/team -p` names; the shorthand must +// not send it to the org/_team checkout beside it. +func TestUpdateProject_ExistingSkillBeatsShorthand(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + projectRoot := sb.SetupProjectDir("claude") + source := filepath.Join(projectRoot, ".skillshare", "skills") + addPendingTrackedRepo(t, sb, source, "org/_team") + writeProjectMeta(t, sb.CreateProjectSkill(projectRoot, "org/team", map[string]string{"SKILL.md": "# Team"})) + + result := sb.RunCLIInDir(projectRoot, "update", "org/team", "--dry-run", "-p") + + result.AssertSuccess(t) + result.AssertOutputNotContains(t, "_team") +} + +// `update team/` names the same item as `update team`: both the skill and the +// _team repo match, so it is ambiguous either way. +func TestUpdate_TrailingSlashKeepsAmbiguity(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + setupGlobalConfig(sb) + addPendingTrackedRepo(t, sb, sb.SourcePath, "_team") + writeMeta(t, sb.CreateSkill("team", map[string]string{"SKILL.md": "# Team"})) + + result := sb.RunCLI("update", "team/") + + result.AssertFailure(t) + result.AssertAnyOutputContains(t, "matches multiple items") +} diff --git a/website/docs/reference/commands/update.md b/website/docs/reference/commands/update.md index 64cc15e7c..7be807e9d 100644 --- a/website/docs/reference/commands/update.md +++ b/website/docs/reference/commands/update.md @@ -408,7 +408,7 @@ skillshare update --all -p --skip-audit # Skip security audit gate | **Local-path install** | Re-copy from the recorded path | Listed in `.metadata.json` with `type: local` | | **Local skill** | Skipped | Not listed in `.metadata.json` | -The `_` prefix is optional, on the last path segment too — `skillshare update team-skills -p` auto-detects `_team-skills`, and `skillshare update devops/team-skills` finds a repo installed with `--into devops` at `devops/_team-skills`. +The `_` prefix is optional, on the last path segment too — `skillshare update team-skills -p` auto-detects `_team-skills`, and `skillshare update devops/team-skills -p` finds a repo installed with `--into devops` at `devops/_team-skills`. ### Lockfile diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/update.md b/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/update.md index f7b40b17b..54a5d4d06 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/update.md +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/update.md @@ -408,7 +408,7 @@ skillshare update --all -p --skip-audit # security audit gate をスキップ | **ローカルパスからのインストール** | 記録されたパスから再コピー | `.metadata.json` に `type: local` で記載されている | | **Local skill** | スキップ | `.metadata.json` に記載されていない | -`_` prefix は最後のパス区間でも省略可能です — `skillshare update team-skills -p` は自動的に `_team-skills` を検出し、`skillshare update devops/team-skills` は `--into devops` でインストールした `devops/_team-skills` を検出します。 +`_` prefix は最後のパス区間でも省略可能です — `skillshare update team-skills -p` は自動的に `_team-skills` を検出し、`skillshare update devops/team-skills -p` は `--into devops` でインストールした `devops/_team-skills` を検出します。 ### ロックファイル diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/update.md b/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/update.md index cf2162996..b8c88c768 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/update.md +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/update.md @@ -408,7 +408,7 @@ skillshare update --all -p --skip-audit # 보안 audit gate 건너뛰기 | **로컬 경로 설치** | 기록된 경로에서 다시 복사 | `.metadata.json`에 `type: local`로 등록됨 | | **Local skill** | 건너뜀 | `.metadata.json`에 등록되지 않음 | -`_` 접두사는 경로의 마지막 구간에서도 선택 사항입니다 — `skillshare update team-skills -p`는 `_team-skills`를 자동으로 감지하고, `skillshare update devops/team-skills`는 `--into devops`로 설치한 `devops/_team-skills`를 찾습니다. +`_` 접두사는 경로의 마지막 구간에서도 선택 사항입니다 — `skillshare update team-skills -p`는 `_team-skills`를 자동으로 감지하고, `skillshare update devops/team-skills -p`는 `--into devops`로 설치한 `devops/_team-skills`를 찾습니다. ### Lockfile diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/update.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/update.md index 1390ec6c3..850a161e1 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/update.md +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/update.md @@ -408,7 +408,7 @@ skillshare update --all -p --skip-audit # Skip security audit gate | **Local-path install** | Re-copy from the recorded path | Listed in `.metadata.json` with `type: local` | | **Local skill** | Skipped | Not listed in `.metadata.json` | -`_` 前缀是可选的,路径的最后一段也一样——`skillshare update team-skills -p` 会自动检测为 `_team-skills`,`skillshare update devops/team-skills` 会找到以 `--into devops` 安装的 `devops/_team-skills`。 +`_` 前缀是可选的,路径的最后一段也一样——`skillshare update team-skills -p` 会自动检测为 `_team-skills`,`skillshare update devops/team-skills -p` 会找到以 `--into devops` 安装的 `devops/_team-skills`。 ### 锁定文件 diff --git a/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/update.md b/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/update.md index b0736b6b7..27e68129a 100644 --- a/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/update.md +++ b/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/update.md @@ -408,7 +408,7 @@ skillshare update --all -p --skip-audit # 跳過安全性 audit 關卡 | **從本機路徑安裝** | 從記錄的路徑重新複製 | 列於 `.metadata.json`,且 `type: local` | | **本機 skill** | 跳過 | 未列於 `.metadata.json` | -`_` 前綴是選填的,路徑最後一段也一樣 — `skillshare update team-skills -p` 會自動偵測為 `_team-skills`,`skillshare update devops/team-skills` 會找到以 `--into devops` 安裝的 `devops/_team-skills`。 +`_` 前綴是選填的,路徑最後一段也一樣 — `skillshare update team-skills -p` 會自動偵測為 `_team-skills`,`skillshare update devops/team-skills -p` 會找到以 `--into devops` 安裝的 `devops/_team-skills`。 ### Lockfile From 8bf43f2480b5269195a55cece2b870b0cb07beed Mon Sep 17 00:00:00 2001 From: Willie Date: Thu, 8 Oct 2026 00:05:10 +0800 Subject: [PATCH 5/6] fix(update): clean the name before the single-update skill lookup Codex review of #481 round two: POST /api/update looked up an exact skill with the raw name before resolving a repo. The shared helper now accepts `org/team/`, so with a skill at org/team beside org/_team the raw lookup missed the skill and the shorthand updated the repo. Clean the name once at the top of updateSingleByKind so the skill lookup and repo resolution see the same name. --- internal/server/handler_update.go | 2 ++ internal/server/handler_update_shorthand_test.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/internal/server/handler_update.go b/internal/server/handler_update.go index 4b5365ca8..9e0cb5cca 100644 --- a/internal/server/handler_update.go +++ b/internal/server/handler_update.go @@ -6,6 +6,7 @@ import ( "log" "net/http" "os" + "path" "path/filepath" "strings" "time" @@ -166,6 +167,7 @@ func (s *Server) updateSingle(name string, force, skipAudit bool) updateResultIt } func (s *Server) updateSingleByKind(name, kind string, force, skipAudit bool) updateResultItem { + name = path.Clean(filepath.ToSlash(name)) // "org/team/" names the same item as "org/team" if kind == "agent" { return s.updateAgent(name, force, skipAudit) } diff --git a/internal/server/handler_update_shorthand_test.go b/internal/server/handler_update_shorthand_test.go index 9f3537098..e974a5f6d 100644 --- a/internal/server/handler_update_shorthand_test.go +++ b/internal/server/handler_update_shorthand_test.go @@ -69,3 +69,19 @@ func TestHandleUpdateStream_ExistingSkillBeatsShorthand(t *testing.T) { t.Fatalf("results = %+v, want the org/team skill, not the org/_team repo", results) } } + +// `org/team/` names the same skill as `org/team`, so the exact-skill lookup +// must see it before the shorthand can pick org/_team. +func TestHandleUpdate_TrailingSlashKeepsExistingSkill(t *testing.T) { + s, src := newTestServer(t) + addSkill(t, src, "org/team") + addSkillMeta(t, src, "org/team", "/nonexistent/skill-source") + addTrackedRepo(t, src, "org/_team") + s.reloadSkillsStore() // pick up the metadata written above + + results := runFollowUpdate(t, s, false, "org/team/") + + if len(results) != 1 || results[0].IsRepo { + t.Fatalf("results = %+v, want the org/team skill, not the org/_team repo", results) + } +} From 335dabd54d79dcad8fde1f4d98c0052540435368 Mon Sep 17 00:00:00 2001 From: Willie Date: Thu, 8 Oct 2026 00:21:32 +0800 Subject: [PATCH 6/6] fix(uninstall): resolve tracked repo shorthand under --into Reuse the shared tracked checkout resolver after checking the typed path so uninstall org/team finds org/_team without taking precedence over an existing skill or folder. Classify tracked targets by the underscore checkout rule across CLI uninstall entry points, retaining ambiguity errors and the shared inside-repo refusal. --- cmd/skillshare/uninstall.go | 32 +++++------ cmd/skillshare/uninstall_handlers.go | 2 +- cmd/skillshare/uninstall_test.go | 54 +++++++++++++++++-- skills/skillshare/references/install.md | 2 + website/docs/reference/commands/uninstall.md | 2 + .../current/reference/commands/uninstall.md | 2 + .../current/reference/commands/uninstall.md | 2 + .../current/reference/commands/uninstall.md | 2 + .../current/reference/commands/uninstall.md | 2 + 9 files changed, 78 insertions(+), 22 deletions(-) diff --git a/cmd/skillshare/uninstall.go b/cmd/skillshare/uninstall.go index 808656358..21c957ae3 100644 --- a/cmd/skillshare/uninstall.go +++ b/cmd/skillshare/uninstall.go @@ -146,25 +146,21 @@ func resolveUninstallTarget(skillName, sourceDir, sourceLabel string, walk sourc return nil, fmt.Errorf("invalid skill name: %q", skillName) } - // Normalize _ prefix for tracked repos - if !strings.HasPrefix(skillName, "_") { - prefixedPath := filepath.Join(sourceDir, "_"+skillName) - if install.IsGitRepo(prefixedPath) { - skillName = "_" + skillName - } - } - skillPath := filepath.Join(sourceDir, skillName) info, err := os.Stat(skillPath) if err != nil { if os.IsNotExist(err) { - // Fallback: search by basename in nested directories - resolved, resolveErr := resolveNestedSkillDir(sourceDir, skillName, sourceLabel, walk) - if resolveErr != nil { - return nil, resolveErr + // Preserve an existing typed path before trying tracked-repo shorthand. + if repoName, repoPath := install.FindTrackedCheckoutUnlessSkill(sourceDir, skillName); repoPath != "" { + skillName, skillPath = repoName, repoPath + } else { + resolved, resolveErr := resolveNestedSkillDir(sourceDir, skillName, sourceLabel, walk) + if resolveErr != nil { + return nil, resolveErr + } + skillName = resolved + skillPath = filepath.Join(sourceDir, resolved) } - skillName = resolved - skillPath = filepath.Join(sourceDir, resolved) } else { return nil, fmt.Errorf("cannot access skill: %w", err) } @@ -175,7 +171,7 @@ func resolveUninstallTarget(skillName, sourceDir, sourceLabel string, walk sourc return &uninstallTarget{ name: skillName, path: skillPath, - isTrackedRepo: install.IsGitRepo(skillPath), + isTrackedRepo: install.IsTrackedCheckout(skillPath), }, nil } @@ -197,7 +193,7 @@ func resolveUninstallByGlob(pattern, sourceDir string, walk sourcewalk.Options) targets = append(targets, &uninstallTarget{ name: e.Name(), path: skillPath, - isTrackedRepo: install.IsGitRepo(skillPath), + isTrackedRepo: install.IsTrackedCheckout(skillPath), }) } } @@ -256,7 +252,7 @@ func resolveGroupSkills(group, sourceDir string, walks ...sourcewalk.Options) ([ if _, statErr := os.Stat(filepath.Join(path, "SKILL.md")); statErr == nil { hasSkillMD = true } - isRepo := install.IsGitRepo(path) + isRepo := install.IsTrackedCheckout(path) if hasSkillMD || isRepo { rel, relErr := filepath.Rel(resolvedSourceDir, logicalPath) @@ -344,7 +340,7 @@ func countGroupSkills(dir string) []string { names = append(names, fi.Name()) return filepath.SkipDir } - if install.IsGitRepo(path) { + if install.IsTrackedCheckout(path) { names = append(names, fi.Name()) return filepath.SkipDir } diff --git a/cmd/skillshare/uninstall_handlers.go b/cmd/skillshare/uninstall_handlers.go index 16dfdaa7c..a1448a707 100644 --- a/cmd/skillshare/uninstall_handlers.go +++ b/cmd/skillshare/uninstall_handlers.go @@ -206,7 +206,7 @@ func runUninstallSkills(opts *uninstallOptions, mode *uninstallMode, rawArgs []s targets = append(targets, &uninstallTarget{ name: dir, path: skillPath, - isTrackedRepo: install.IsGitRepo(skillPath), + isTrackedRepo: install.IsTrackedCheckout(skillPath), }) seen[skillPath] = true } diff --git a/cmd/skillshare/uninstall_test.go b/cmd/skillshare/uninstall_test.go index 7939319d8..467e11c7b 100644 --- a/cmd/skillshare/uninstall_test.go +++ b/cmd/skillshare/uninstall_test.go @@ -5,7 +5,6 @@ import ( "path/filepath" "testing" - "skillshare/internal/install" "skillshare/internal/sourcewalk" ) @@ -116,5 +115,54 @@ func TestResolveUninstallByGlob_SkipsFiles(t *testing.T) { } } -// Verify unused imports are referenced -var _ = install.IsGitRepo +func TestResolveUninstallTarget_TrackedNames(t *testing.T) { + for _, tc := range []struct { + name, input, existing, want string + repo bool + }{ + {"nested shorthand", "org/team", "", "org/_team", true}, + {"nested explicit", "org/_team", "", "org/_team", true}, + {"trailing slash", "org/team/", "", "org/_team", true}, + {"nested skill wins", "org/team", "org/team", "org/team", false}, + {"nested folder wins", "org/folder", "org/folder", "org/folder", false}, + {"top-level skill wins", "team", "team", "team", false}, + {"top-level shorthand", "team", "", "_team", true}, + {"top-level explicit", "_team", "", "_team", true}, + {"plain git checkout", "plain", "plain/.git", "plain", false}, + } { + t.Run(tc.name, func(t *testing.T) { + src := t.TempDir() + for _, name := range []string{"_team/.git", "org/_team/.git", "org/_folder/.git", tc.existing} { + if name != "" { + if err := os.MkdirAll(filepath.Join(src, name), 0755); err != nil { + t.Fatal(err) + } + } + } + if tc.existing == "org/team" || tc.existing == "team" { + if err := os.WriteFile(filepath.Join(src, tc.existing, "SKILL.md"), []byte("# Skill"), 0644); err != nil { + t.Fatal(err) + } + } + got, err := resolveUninstallTarget(tc.input, src, "source", sourcewalk.Options{}) + if err != nil { + t.Fatal(err) + } + if got.name != tc.want || got.path != filepath.Join(src, tc.want) || got.isTrackedRepo != tc.repo { + t.Fatalf("target = %+v, want name %q, tracked %v", got, tc.want, tc.repo) + } + }) + } +} + +func TestResolveUninstallTarget_AmbiguousNestedName(t *testing.T) { + src := t.TempDir() + for _, name := range []string{"a/_team/.git", "b/_team/.git"} { + if err := os.MkdirAll(filepath.Join(src, name), 0755); err != nil { + t.Fatal(err) + } + } + if _, err := resolveUninstallTarget("team", src, "source", sourcewalk.Options{}); err == nil { + t.Fatal("ambiguous shorthand must fail") + } +} diff --git a/skills/skillshare/references/install.md b/skills/skillshare/references/install.md index 61fd61784..2d5ff987e 100644 --- a/skills/skillshare/references/install.md +++ b/skills/skillshare/references/install.md @@ -198,6 +198,8 @@ skillshare uninstall --group frontend --dry-run skillshare uninstall my-skill --json ``` +**Tracked repo names:** `uninstall org/team` accepts the shorthand for `org/_team` installed with `--into org`. An existing skill or folder at the typed path wins; use `org/_team` to explicitly remove the repo. Ambiguous short names require the full path. + **Safety:** Tracked repos with uncommitted changes are skipped, and repos whose git status cannot be read fail. Use `--force` to override both. **Group auto-detection:** When uninstalling a directory that contains sub-skills, the confirmation prompt shows `Uninstalling group (N skills)` with a list of contained skills. diff --git a/website/docs/reference/commands/uninstall.md b/website/docs/reference/commands/uninstall.md index 7fd043e47..c61f72bde 100644 --- a/website/docs/reference/commands/uninstall.md +++ b/website/docs/reference/commands/uninstall.md @@ -175,6 +175,7 @@ For tracked repositories (folders starting with `_`): - Automatically removes the entry from `.gitignore` - The `_` prefix is optional when uninstalling - A repo installed with `--into` is named by its path, such as `devops/_team-skills` +- For `--into` repos, the final `_` is optional too: `devops/team-skills` resolves to `devops/_team-skills`. An existing skill or folder at the typed path takes precedence; use the explicit `_` path to remove the repo. Ambiguous short names fail and require the full path. - A skill or folder inside a tracked repo cannot be removed on its own, even with `--force`; the command fails with `inside a tracked repo; uninstall the repo instead`. Skills below a followed source link can still be removed one at a time ```bash @@ -182,6 +183,7 @@ skillshare uninstall _team-skills # With prefix skillshare uninstall team-skills # Without prefix (auto-detected) skillshare uninstall _team-skills --force # Force remove with uncommitted changes skillshare uninstall devops/_team-skills # Repo installed with --into devops +skillshare uninstall devops/team-skills # Same repo, unless this path already exists ``` ## Examples diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md b/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md index 51214c182..c1dc88468 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md @@ -175,6 +175,7 @@ tracked repositories(`_` で始まるフォルダ)の場合: - `.gitignore` からエントリを自動的に削除します - uninstall 時に `_` prefix は省略可能です - `--into` でインストールしたリポジトリは `devops/_team-skills` のようにパスで指定します +- `--into` のリポジトリも末尾の `_` を省略できます。`devops/team-skills` は `devops/_team-skills` を指定します。入力したパスに既存の Skill やフォルダがある場合はそちらを優先するため、リポジトリを削除するには `_` を含むパスを指定してください。短い名前が複数に一致する場合は失敗し、完全なパスが必要です。 - 追跡リポジトリ内の Skill やフォルダは、`--force` を付けても単独では削除できず、`inside a tracked repo; uninstall the repo instead` で失敗します。followed source link 配下の Skill は 1 つずつ削除できます ```bash @@ -182,6 +183,7 @@ skillshare uninstall _team-skills # prefix 付き skillshare uninstall team-skills # prefix なし(自動検出) skillshare uninstall _team-skills --force # 未コミットの変更があっても強制削除 skillshare uninstall devops/_team-skills # --into devops でインストールしたリポジトリ +skillshare uninstall devops/team-skills # Same repo, unless this path already exists ``` ## 例 diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md b/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md index 69dcf1e05..7bbbff08e 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md @@ -175,6 +175,7 @@ tracked repository(`_`로 시작하는 폴더)의 경우: - `.gitignore`에서 항목을 자동으로 제거합니다 - uninstall 시 `_` 접두사는 선택 사항입니다 - `--into`로 설치한 repo는 `devops/_team-skills`처럼 경로로 지정합니다 +- `--into` repo도 마지막 `_`를 생략할 수 있습니다. `devops/team-skills`는 `devops/_team-skills`로 해석됩니다. 입력한 경로에 skill이나 폴더가 있으면 그것을 우선하므로 repo를 제거하려면 `_`가 포함된 경로를 사용하세요. 짧은 이름이 여러 항목과 일치하면 실패하며 전체 경로가 필요합니다. - tracked repo 안의 skill이나 폴더는 `--force`를 붙여도 따로 제거할 수 없으며, `inside a tracked repo; uninstall the repo instead`로 실패합니다. followed source link 아래의 skill은 하나씩 제거할 수 있습니다 ```bash @@ -182,6 +183,7 @@ skillshare uninstall _team-skills # With prefix skillshare uninstall team-skills # Without prefix (auto-detected) skillshare uninstall _team-skills --force # Force remove with uncommitted changes skillshare uninstall devops/_team-skills # Repo installed with --into devops +skillshare uninstall devops/team-skills # Same repo, unless this path already exists ``` ## 예시 diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md index be55bf789..ac030cb55 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md @@ -180,6 +180,7 @@ skillshare uninstall frontend/hooks -G frontend --force # hooks removed once - 自动从 `.gitignore` 中移除该条目 - Uninstall 时 `_` 前缀是可选的 - 用 `--into` 安装的 repo 以路径命名,例如 `devops/_team-skills` +- `--into` repo 最后一段的 `_` 也可以省略:`devops/team-skills` 会解析为 `devops/_team-skills`。输入路径上已有的 Skill 或文件夹优先;要移除 repo,请使用含 `_` 的完整路径。短名称匹配多个项目时会失败,必须指定完整路径。 - tracked repo 中的 Skill 或文件夹不能单独移除,加上 `--force` 也一样;命令会以 `inside a tracked repo; uninstall the repo instead` 失败。位于 followed source link 下的 Skill 仍可逐个移除 ```bash @@ -187,6 +188,7 @@ skillshare uninstall _team-skills # With prefix skillshare uninstall team-skills # Without prefix (auto-detected) skillshare uninstall _team-skills --force # Force remove with uncommitted changes skillshare uninstall devops/_team-skills # Repo installed with --into devops +skillshare uninstall devops/team-skills # Same repo, unless this path already exists ``` ## 示例 diff --git a/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md b/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md index ba6ecd5d0..7ee245514 100644 --- a/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md +++ b/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md @@ -175,6 +175,7 @@ skillshare uninstall frontend/hooks -G frontend --force # hooks 只會被移除 - 自動從 `.gitignore` 移除該項目 - 解除安裝時 `_` 前綴為選填 - 用 `--into` 安裝的 repo 以路徑命名,例如 `devops/_team-skills` +- `--into` repo 最後一段的 `_` 也可以省略:`devops/team-skills` 會解析為 `devops/_team-skills`。輸入路徑上既有的 skill 或資料夾優先;要移除 repo,請使用含 `_` 的完整路徑。短名稱匹配多個項目時會失敗,必須指定完整路徑。 - tracked repo 裡的 skill 或資料夾不能單獨移除,加上 `--force` 也一樣;指令會以 `inside a tracked repo; uninstall the repo instead` 失敗。位於 followed source link 底下的 skill 仍可逐一移除 ```bash @@ -182,6 +183,7 @@ skillshare uninstall _team-skills # 含前綴 skillshare uninstall team-skills # 不含前綴(自動偵測) skillshare uninstall _team-skills --force # 強制移除,即使有未提交的變更 skillshare uninstall devops/_team-skills # 用 --into devops 安裝的 repo +skillshare uninstall devops/team-skills # Same repo, unless this path already exists ``` ## 範例