mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
fix: sync must not prune registry entries for installed skills
Sync's registry prune logic removed entries for installed skills whose files were missing from disk. This was wrong: the registry is the authoritative record of installations managed by install/uninstall. Remove PruneStaleSkills calls from sync (CLI global, CLI project, and web UI handler). Reconcile (called during install) still uses prune with full metadata context, which is correct. Fixes: running 'sync' after 'install' would clear registry.yaml when the installed skill's source files were not yet on disk.
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## [0.18.8] - 2026-04-06
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **Sync no longer deletes registry entries for installed skills** — running `skillshare sync` (or project-mode `sync -p`) would silently remove `registry.yaml` entries for skills whose source files were not present on disk. This meant that installing a skill and then syncing could erase the installation record entirely. Sync now leaves the registry untouched — only `install` and `uninstall` manage registry entries
|
||||
|
||||
## [0.18.7] - 2026-04-04
|
||||
|
||||
### New Features
|
||||
|
||||
+3
-27
@@ -240,33 +240,9 @@ func cmdSync(args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Prune stale registry entries using already-discovered skills (avoids second walk)
|
||||
if !dryRun {
|
||||
regDir := cfg.RegistryDir
|
||||
if regDir == "" {
|
||||
regDir = config.SourceRoot(cfg.Source)
|
||||
}
|
||||
reg, regErr := config.LoadRegistry(regDir)
|
||||
if regErr == nil {
|
||||
live := make(map[string]bool, len(discoveredSkills))
|
||||
for _, s := range discoveredSkills {
|
||||
live[s.RelPath] = true
|
||||
}
|
||||
// Ignored skills still exist on disk — don't prune their registry entries
|
||||
if ignoreStats != nil {
|
||||
for _, p := range ignoreStats.IgnoredSkills {
|
||||
live[p] = true
|
||||
}
|
||||
}
|
||||
var pruneChanged bool
|
||||
reg.Skills, pruneChanged = config.PruneStaleSkills(reg.Skills, live, false)
|
||||
if pruneChanged {
|
||||
if err := reg.Save(regDir); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "warning: failed to save registry after prune: %v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Registry entries are managed by install/uninstall, not sync.
|
||||
// Sync only manages symlinks — it must not prune registry entries
|
||||
// for installed skills whose files may be missing from disk.
|
||||
|
||||
logSyncOp(config.ConfigPath(), syncLogStats{
|
||||
Targets: len(cfg.Targets),
|
||||
|
||||
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"skillshare/internal/config"
|
||||
@@ -136,24 +135,9 @@ func cmdSyncProject(root string, dryRun, force, jsonOutput bool) (syncLogStats,
|
||||
}
|
||||
}
|
||||
|
||||
// Prune stale registry entries using already-discovered skills (avoids second walk)
|
||||
live := make(map[string]bool, len(discoveredSkills))
|
||||
for _, s := range discoveredSkills {
|
||||
live[s.RelPath] = true
|
||||
}
|
||||
// Ignored skills still exist on disk — don't prune their registry entries
|
||||
if ignoreStats != nil {
|
||||
for _, p := range ignoreStats.IgnoredSkills {
|
||||
live[p] = true
|
||||
}
|
||||
}
|
||||
var pruneChanged bool
|
||||
runtime.registry.Skills, pruneChanged = config.PruneStaleSkills(runtime.registry.Skills, live, true)
|
||||
if pruneChanged {
|
||||
if err := runtime.registry.Save(filepath.Join(root, ".skillshare")); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "warning: failed to save registry after prune: %v\n", err)
|
||||
}
|
||||
}
|
||||
// Registry entries are managed by install/uninstall, not sync.
|
||||
// Sync only manages symlinks — it must not prune registry entries
|
||||
// for installed skills whose files may be missing from disk.
|
||||
}
|
||||
|
||||
if failedTargets > 0 {
|
||||
|
||||
@@ -2,10 +2,8 @@ package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"maps"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"skillshare/internal/config"
|
||||
@@ -80,34 +78,9 @@ func (s *Server) handleSync(w http.ResponseWriter, r *http.Request) {
|
||||
warnings = append(warnings, "source directory is empty (0 skills)")
|
||||
}
|
||||
|
||||
// Prune stale registry entries using already-discovered skills (avoids second walk).
|
||||
// Uses defer so early returns from target errors still trigger cleanup.
|
||||
if !body.DryRun {
|
||||
defer func() {
|
||||
live := make(map[string]bool, len(allSkills))
|
||||
for _, sk := range allSkills {
|
||||
live[sk.RelPath] = true
|
||||
}
|
||||
// Ignored skills still exist on disk — don't prune their registry entries
|
||||
if ignoreStats != nil {
|
||||
for _, p := range ignoreStats.IgnoredSkills {
|
||||
live[p] = true
|
||||
}
|
||||
}
|
||||
skillsOnly := s.IsProjectMode() // project registries also store agent entries
|
||||
var pruneChanged bool
|
||||
s.registry.Skills, pruneChanged = config.PruneStaleSkills(s.registry.Skills, live, skillsOnly)
|
||||
if pruneChanged {
|
||||
regDir := s.cfg.RegistryDir
|
||||
if s.IsProjectMode() {
|
||||
regDir = filepath.Join(s.projectRoot, ".skillshare")
|
||||
}
|
||||
if err := s.registry.Save(regDir); err != nil {
|
||||
log.Printf("warning: failed to save registry after prune: %v", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
// Registry entries are managed by install/uninstall, not sync.
|
||||
// Sync only manages symlinks — it must not prune registry entries
|
||||
// for installed skills whose files may be missing from disk.
|
||||
|
||||
results := make([]syncTargetResult, 0)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ package integration
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"skillshare/internal/testutil"
|
||||
@@ -110,6 +111,39 @@ func TestSyncProject_DryRun_NoChanges(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncProject_PreservesRegistryEntries(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
projectRoot := sb.SetupProjectDir("claude")
|
||||
|
||||
// Create a skill on disk that sync will discover
|
||||
sb.CreateProjectSkill(projectRoot, "local-skill", map[string]string{
|
||||
"SKILL.md": "# Local Skill",
|
||||
})
|
||||
|
||||
// Write a registry with a remote-installed skill that has NO files on disk.
|
||||
// Sync must NOT prune this entry — the registry is the source of truth for installations.
|
||||
registryPath := filepath.Join(projectRoot, ".skillshare", "registry.yaml")
|
||||
registryContent := "skills:\n - name: remote-tool\n source: github.com/someone/remote-tool\n"
|
||||
os.WriteFile(registryPath, []byte(registryContent), 0644)
|
||||
|
||||
result := sb.RunCLIInDir(projectRoot, "sync", "-p")
|
||||
result.AssertSuccess(t)
|
||||
|
||||
// Verify registry still contains the remote-tool entry
|
||||
data, err := os.ReadFile(registryPath)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to read registry: %v", err)
|
||||
}
|
||||
content := string(data)
|
||||
if !strings.Contains(content, "remote-tool") {
|
||||
t.Errorf("sync should preserve registry entry for installed skill without local files, got:\n%s", content)
|
||||
}
|
||||
if !strings.Contains(content, "github.com/someone/remote-tool") {
|
||||
t.Errorf("sync should preserve source in registry entry, got:\n%s", content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncProject_AutoDetectsMode(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"skillshare/internal/testutil"
|
||||
@@ -464,6 +465,41 @@ targets:
|
||||
}
|
||||
}
|
||||
|
||||
func TestSync_PreservesRegistryEntries(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
// Create a local skill that sync will discover
|
||||
sb.CreateSkill("local-skill", map[string]string{"SKILL.md": "# Local"})
|
||||
|
||||
targetPath := sb.CreateTarget("claude")
|
||||
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
||||
mode: merge
|
||||
targets:
|
||||
claude:
|
||||
path: ` + targetPath + `
|
||||
`)
|
||||
|
||||
// Write a registry with a remote-installed skill that has NO files on disk.
|
||||
// Sync must NOT prune this entry — registry is the source of truth for installations.
|
||||
registryPath := filepath.Join(sb.SourcePath, "registry.yaml")
|
||||
registryContent := "skills:\n - name: remote-tool\n source: github.com/someone/remote-tool\n"
|
||||
os.WriteFile(registryPath, []byte(registryContent), 0644)
|
||||
|
||||
result := sb.RunCLI("sync")
|
||||
result.AssertSuccess(t)
|
||||
|
||||
// Verify registry still contains the remote-tool entry
|
||||
data, err := os.ReadFile(registryPath)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to read registry: %v", err)
|
||||
}
|
||||
content := string(data)
|
||||
if !strings.Contains(content, "remote-tool") {
|
||||
t.Errorf("sync should preserve registry entry for installed skill without local files, got:\n%s", content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSync_MergeMode_IncludeFilter(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
@@ -9,6 +9,12 @@ All notable changes to skillshare are documented here. For the full commit histo
|
||||
|
||||
---
|
||||
|
||||
## [0.18.8] - 2026-04-06
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **Sync no longer deletes registry entries for installed skills** — running `skillshare sync` (or project-mode `sync -p`) would silently remove `registry.yaml` entries for skills whose source files were not present on disk. This meant that installing a skill and then syncing could erase the installation record entirely. Sync now leaves the registry untouched — only `install` and `uninstall` manage registry entries
|
||||
|
||||
## [0.18.7] - 2026-04-04
|
||||
|
||||
### New Features
|
||||
|
||||
Reference in New Issue
Block a user