diff --git a/internal/server/handler_install.go b/internal/server/handler_install.go index 560a599b8..ab61f824b 100644 --- a/internal/server/handler_install.go +++ b/internal/server/handler_install.go @@ -15,6 +15,17 @@ import ( "skillshare/internal/install" ) +// reloadSkillsStore refreshes the in-memory skills metadata store from disk. +// install.Install writes metadata to the file via its own store instance, so the +// server's cached s.skillsStore stays stale after an install — a freshly +// installed skill would then render with an empty source/type (shown as "Local" +// with a blank source in the UI) until the server restarts. +func (s *Server) reloadSkillsStore() { + if st, err := install.LoadMetadataWithMigration(s.cfg.EffectiveSkillsSource(), ""); err == nil && st != nil { + s.skillsStore = st + } +} + func discoverInstallSource(source *install.Source) (*install.DiscoveryResult, error) { if source.IsGit() { if source.HasSubdir() { @@ -276,6 +287,8 @@ func (s *Server) handleInstallBatch(w http.ResponseWriter, r *http.Request) { if st, loadErr := install.LoadMetadataWithMigration(s.agentsSource(), install.MetadataKindAgent); loadErr == nil && st != nil { s.agentsStore = st } + } else { + s.reloadSkillsStore() } if s.IsProjectMode() { if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.EffectiveSkillsSource()); rErr != nil { @@ -398,6 +411,7 @@ func (s *Server) handleInstall(w http.ResponseWriter, r *http.Request) { } // Reconcile config after tracked repo install if trackedKind == "skill" { + s.reloadSkillsStore() if s.IsProjectMode() { if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.EffectiveSkillsSource()); rErr != nil { log.Printf("warning: failed to reconcile project skills config: %v", rErr) @@ -486,6 +500,7 @@ func (s *Server) handleInstall(w http.ResponseWriter, r *http.Request) { } // Reconcile config after single install + s.reloadSkillsStore() if s.IsProjectMode() { if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.EffectiveSkillsSource()); rErr != nil { log.Printf("warning: failed to reconcile project skills config: %v", rErr) diff --git a/internal/server/handler_install_test.go b/internal/server/handler_install_test.go index 7acf09fb5..b1826286a 100644 --- a/internal/server/handler_install_test.go +++ b/internal/server/handler_install_test.go @@ -285,3 +285,36 @@ func TestHandleInstall_TrackPureAgentRepoInstallsIntoAgentsSource(t *testing.T) t.Fatalf("expected no tracked agent repo in skills source, got err=%v", err) } } + +// TestReloadSkillsStore_PicksUpNewEntry guards the "installed skill shows as +// Local with empty source" regression: install writes metadata to disk via its +// own store instance, so the server's cached skillsStore must be reloaded or a +// freshly installed skill renders with an empty source/type in the UI. +func TestReloadSkillsStore_PicksUpNewEntry(t *testing.T) { + s, sourceDir := newTestServer(t) + + if got := s.skillsStore.GetByPath("frontend/react-best-practices"); got != nil { + t.Fatalf("expected empty store at startup, got %+v", got) + } + + // Simulate an install persisting metadata through a separate store instance. + disk := install.NewMetadataStore() + disk.Set("frontend/react-best-practices", &install.MetadataEntry{ + Source: "https://github.com/vercel-labs/agent-skills/tree/main/skills/react-best-practices", + Type: "github-subdir", + Group: "frontend", + }) + if err := disk.Save(sourceDir); err != nil { + t.Fatalf("failed to save metadata: %v", err) + } + + s.reloadSkillsStore() + + got := s.skillsStore.GetByPath("frontend/react-best-practices") + if got == nil { + t.Fatal("reloadSkillsStore did not pick up the on-disk entry (skill would show as Local)") + } + if got.Type != "github-subdir" { + t.Errorf("Type = %q, want github-subdir", got.Type) + } +}