From 84ed67b13dcdd5aa593b1b384ec50b37f10eba2e Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 7 Oct 2026 23:51:37 +0800 Subject: [PATCH 1/3] 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 414d193114a5a47a844f51eac945bdc3a3bef7ca Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 7 Oct 2026 23:58:43 +0800 Subject: [PATCH 2/3] 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 3/3] 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) + } +}