From c31dffc450599495ae639bf107b190be0e16ca5f Mon Sep 17 00:00:00 2001 From: Willie Date: Sun, 4 Oct 2026 22:56:12 +0800 Subject: [PATCH] fix(plugin): name Skillshare-installed packages in Pi project views Codex review on #399: piProjectState never set ManagedBy, unlike piGlobalState. A project's Extensions tab (@pi, or pi in project mode) therefore titled a plugin Skillshare installed by its state path and dropped the "Managed by Skillshare" tag, for both the project's own entries and the global entries it inherits. The lookup by source, then by resolved local path, moves into piManagedBy and runs for every package of both views. --- internal/plugin/pi_extensions.go | 14 ++++++++++---- internal/plugin/pi_extensions_project.go | 6 +++++- internal/plugin/pi_extensions_test.go | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/internal/plugin/pi_extensions.go b/internal/plugin/pi_extensions.go index 34e28298a..ff35857a5 100644 --- a/internal/plugin/pi_extensions.go +++ b/internal/plugin/pi_extensions.go @@ -594,10 +594,7 @@ func (s *Service) piGlobalState(ctx context.Context, target string) (*piTargetSt p := openPiPackage(e.source, agentDir, "", "user") st.packages[e.index] = p pkg.Kind, pkg.Identity, pkg.Install, pkg.Problem = p.src.kind, redactSource(p.src.identity), p.install, p.problem - pkg.ManagedBy = managed[strings.TrimSpace(e.source)] - if pkg.ManagedBy == "" && p.src.kind == "local" { - pkg.ManagedBy = managed[p.src.install] - } + pkg.ManagedBy = piManagedBy(managed, e.source, p.src) switch { case p.src.identity != "" && seen[p.src.identity]: // Pi keeps the first entry of a package and ignores the rest. @@ -643,6 +640,15 @@ func (s *Service) piManaged(target string) map[string]string { return result } +// piManagedBy is the plugin that owns a settings entry: Skillshare records a Pi +// binding by its source, or for a local package by the path it resolves to. +func piManagedBy(managed map[string]string, source string, src piSource) string { + if name := managed[strings.TrimSpace(source)]; name != "" || src.kind != "local" { + return name + } + return managed[src.install] +} + // piFolders lists the extensions Pi discovers in baseDir/extensions and the paths // listed in the settings' own "extensions", which apply to them as overrides. func (s *Service) piFolders(baseDir string, settings *piSettings) []PiExtensionFolder { diff --git a/internal/plugin/pi_extensions_project.go b/internal/plugin/pi_extensions_project.go index 116b6edc1..6420c44bd 100644 --- a/internal/plugin/pi_extensions_project.go +++ b/internal/plugin/pi_extensions_project.go @@ -89,6 +89,7 @@ func (s *Service) piProjectState(ctx context.Context, target string) (*piProject rows []piRowState problem string } + managed := s.piManaged(target) globals := map[string]*globalPkg{} globalOrder := []*globalPkg{} unresolvedGlobal := false @@ -146,8 +147,10 @@ func (s *Service) piProjectState(ctx context.Context, target string) (*piProject v.Packages = append(v.Packages, pkg) continue } - id := resolvePiSource(e.source, agentDir, projectDir, "project").identity + src := resolvePiSource(e.source, agentDir, projectDir, "project") + id := src.identity pkg.Identity = redactSource(id) + pkg.ManagedBy = piManagedBy(managed, e.source, src) if id != "" && lastProject[id] != e.index { pkg.Problem = "duplicate" v.Packages = append(v.Packages, pkg) @@ -217,6 +220,7 @@ func (s *Service) piProjectState(ctx context.Context, target string) (*piProject if g.entry.hasRules { pkg.Rules = g.entry.rules } + pkg.ManagedBy = piManagedBy(managed, g.entry.source, g.pkg.src) reference, readOnly := piOverrideReference(g.entry.source, g.pkg, agentDir, projectDir) pkg.ReadOnly = readOnly for _, r := range g.rows { diff --git a/internal/plugin/pi_extensions_test.go b/internal/plugin/pi_extensions_test.go index ad6bcb098..63ff337ab 100644 --- a/internal/plugin/pi_extensions_test.go +++ b/internal/plugin/pi_extensions_test.go @@ -425,6 +425,25 @@ func TestPiExtensionsUnruledInAnOverrideIsTheInheritedSelection(t *testing.T) { assertRows(t, got, "extensions/a.ts:loads", "extensions/c.ts:skipped", "extensions/b.ts:") } +// A project view names the plugin Skillshare installed, for the project's entry and an inherited global one. +func TestPiProjectExtensionsNameTheManagedPlugin(t *testing.T) { + for _, project := range []bool{true, false} { + f := newPiFixture(t) + root := filepath.Join(f.home, "code", "acme") + writeTree(t, f.home, map[string]string{"config.yaml": "plugins:\n packages:\n powers:\n bindings:\n pi:\n id: " + f.pkg + "\n"}) + f.global(map[string]any{"packages": []any{f.pkg}}) + entries := []any{} + if project { + entries = append(entries, map[string]any{"source": f.pkg, "autoload": false, "extensions": []string{"-extensions/a.ts"}}) + } + f.writeJSON(filepath.Join(root, ".pi", "settings.json"), map[string]any{"packages": entries}) + f.svc.ProjectRoot = root + if got := f.view("pi").Packages[0]; got.ManagedBy != "powers" { + t.Fatalf("project entry %v: managedBy = %q, scope %s", project, got.ManagedBy, got.Scope) + } + } +} + func TestPiExtensionsMarksAnExtraInPisFolder(t *testing.T) { f := newPiFixture(t) extra := filepath.Join(f.home, "extras", "pi-ext")