fix(plugin): drop VisibilityLabel and its proto import

When core/plugin imported core/internal/api/orchestrator/v1 for the
PluginVisibility enum, every consumer of core/plugin (including the
orchestrator) transitively pulled in core's generated bindings — and
those bindings register the same proto descriptors as the orchestrator's
own bindings, panicking at startup.

Move the label helper into the CLI's cmd package where it belongs;
core/plugin no longer references the proto package at all.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Alex Dunmow 2026-06-04 20:58:09 +08:00
parent 7fc20a990b
commit af7f44c34d
2 changed files with 25 additions and 25 deletions

View File

@ -85,7 +85,7 @@ func printPublicSection(ctx context.Context, cli *orchclient.Client) {
continue
}
for _, p := range gs.Msg.Plugins {
fmt.Printf(" @%s/%s [%s]\n", s.Slug, p.Name, core.VisibilityLabel(p.Visibility))
fmt.Printf(" @%s/%s [%s]\n", s.Slug, p.Name, visibilityLabel(p.Visibility))
}
}
}
@ -175,6 +175,29 @@ func newPluginDeleteVersionCmd() *cobra.Command {
return cmd
}
// visibilityLabel converts the proto PluginVisibility enum into the
// lowercase, user-facing form ("private", "public", ...). Kept here in the
// CLI rather than in core/plugin so that external consumers of core/plugin
// don't transitively pull in core/internal/api/... — every such pull-in
// races with the orchestrator's own generated bindings of the same proto
// file at proto-registration time.
func visibilityLabel(v v1.PluginVisibility) string {
switch v {
case v1.PluginVisibility_PLUGIN_VISIBILITY_PRIVATE:
return "private"
case v1.PluginVisibility_PLUGIN_VISIBILITY_UNDER_REVIEW:
return "under_review"
case v1.PluginVisibility_PLUGIN_VISIBILITY_PUBLIC,
v1.PluginVisibility_PLUGIN_VISIBILITY_UNSPECIFIED:
return "public"
case v1.PluginVisibility_PLUGIN_VISIBILITY_REJECTED:
return "rejected"
case v1.PluginVisibility_PLUGIN_VISIBILITY_TAKEN_DOWN:
return "taken_down"
}
return "unknown"
}
// parsePrivateCoord accepts either a bare plugin name ("myplugin") or the
// canonical "@private/name" form and returns just the plugin name. Any other
// scope is rejected to make accidental deletion of public plugins impossible.
@ -740,7 +763,7 @@ func newPluginStatusCmd() *cobra.Command {
continue
}
for _, p := range gs.Msg.Plugins {
fmt.Printf(" @%s/%s [%s]\n", s.Slug, p.Name, core.VisibilityLabel(p.Visibility))
fmt.Printf(" @%s/%s [%s]\n", s.Slug, p.Name, visibilityLabel(p.Visibility))
}
}
return nil

View File

@ -4,31 +4,8 @@ import (
"strings"
tomlpkg "github.com/BurntSushi/toml"
v1 "git.dev.alexdunmow.com/block/core/internal/api/orchestrator/v1"
)
// VisibilityLabel returns the lowercase, user-facing form of a PluginVisibility
// value (e.g. "private", "public", "under_review"). The default for the
// UNSPECIFIED zero value is "public", matching pre-enum behaviour for plugins
// that don't carry an explicit visibility.
func VisibilityLabel(v v1.PluginVisibility) string {
switch v {
case v1.PluginVisibility_PLUGIN_VISIBILITY_PRIVATE:
return "private"
case v1.PluginVisibility_PLUGIN_VISIBILITY_UNDER_REVIEW:
return "under_review"
case v1.PluginVisibility_PLUGIN_VISIBILITY_PUBLIC,
v1.PluginVisibility_PLUGIN_VISIBILITY_UNSPECIFIED:
return "public"
case v1.PluginVisibility_PLUGIN_VISIBILITY_REJECTED:
return "rejected"
case v1.PluginVisibility_PLUGIN_VISIBILITY_TAKEN_DOWN:
return "taken_down"
}
return "unknown"
}
type ModFile struct {
Plugin ModPlugin `toml:"plugin"`
Compatibility *ModCompat `toml:"compatibility"`