The host never played these files. A theme with an interactive script can play its own sounds, so a second way is not needed. Old manifests still load and get the usual notice about a field the host does not know. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
842 lines
32 KiB
Go
842 lines
32 KiB
Go
// Package plugin implements the Reims-Go plugin kernel: unified extension
|
|
// registry, reversible scopes, dependency-driven reconciliation, hook dispatch,
|
|
// start-intent argument ownership ledger, package lifecycle, security broker,
|
|
// L1 declarative rules, and L3 Sidecar supervision.
|
|
package plugin
|
|
|
|
import (
|
|
"encoding/json"
|
|
"sort"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/Nwflower/reims-go/internal/i18n"
|
|
)
|
|
|
|
const (
|
|
// PluginAPIVersion is the host plugin API contract version (SemVer).
|
|
PluginAPIVersion = "1.2.0"
|
|
// UIAPIVersion is the frontend UI contract version (SemVer); the contract
|
|
// itself lives in frontend/src/styles/ui-contract.ts (§5.1, §6.3).
|
|
UIAPIVersion = "2.1.0"
|
|
// BridgeAPIVersion is the plugin view/panel bridge protocol version (§5.6);
|
|
// methods are listed in BridgeMethodCatalog.
|
|
BridgeAPIVersion = "1.0.0"
|
|
// ManifestSchemaVersion is the current plugin.json schema version.
|
|
ManifestSchemaVersion = 1
|
|
)
|
|
|
|
// State represents the runtime lifecycle state of a plugin (§4.1).
|
|
type State string
|
|
|
|
const (
|
|
StateOff State = "off"
|
|
StatePending State = "pending"
|
|
StateActive State = "active"
|
|
StateDegraded State = "degraded"
|
|
StateFailed State = "failed"
|
|
)
|
|
|
|
// TrustLevel classifies the provenance and signature trust of a plugin (§7.2).
|
|
type TrustLevel string
|
|
|
|
const (
|
|
TrustOfficial TrustLevel = "official"
|
|
TrustVerified TrustLevel = "verified"
|
|
TrustCommunity TrustLevel = "community"
|
|
TrustDev TrustLevel = "dev"
|
|
)
|
|
|
|
// Tier identifies the execution isolation layer derived from package contents (§3.1).
|
|
type Tier string
|
|
|
|
const (
|
|
TierBuiltin Tier = "builtin"
|
|
TierL1 Tier = "L1"
|
|
TierRuntime Tier = "runtime"
|
|
TierL2 Tier = "L2"
|
|
TierL3 Tier = "L3"
|
|
TierL4 Tier = "L4"
|
|
)
|
|
|
|
// SourceKind distinguishes where a plugin came from.
|
|
type SourceKind string
|
|
|
|
const (
|
|
SourceBuiltin SourceKind = "builtin"
|
|
SourceBundled SourceKind = "bundled"
|
|
SourceLocal SourceKind = "local"
|
|
SourceMarket SourceKind = "market"
|
|
SourceDevLink SourceKind = "dev"
|
|
)
|
|
|
|
// LocalizedText holds localized strings readable without executing code (§6.2).
|
|
// ZhCN and EnUS remain first-class fields for backward compatibility; any other
|
|
// BCP-47 locale tags (e.g. "ja-JP", "zh-TW") are stored in Extra.
|
|
type LocalizedText struct {
|
|
ZhCN string `json:"zh-CN,omitempty"`
|
|
EnUS string `json:"en-US,omitempty"`
|
|
Extra map[string]string `json:"extra,omitempty"`
|
|
}
|
|
|
|
// HasAny reports whether at least one localized string is non-empty.
|
|
func (lt LocalizedText) HasAny() bool {
|
|
if lt.ZhCN != "" || lt.EnUS != "" {
|
|
return true
|
|
}
|
|
for _, v := range lt.Extra {
|
|
if strings.TrimSpace(v) != "" {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// Get returns the best localized string for locale using Reims-Go's multi-hop
|
|
// fallback chain (e.g. zh-HK -> zh-TW -> zh-CN -> en-US) and en-XA pseudo-locale.
|
|
func (lt LocalizedText) Get(locale string) string {
|
|
chain := i18n.FallbackChain(i18n.ResolveLocale(locale))
|
|
for _, step := range chain {
|
|
switch step {
|
|
case i18n.EnXA:
|
|
base := lt.EnUS
|
|
if base == "" {
|
|
base = lt.ZhCN
|
|
}
|
|
if base != "" {
|
|
return i18n.PseudoLocalize(base)
|
|
}
|
|
case i18n.ZhCN:
|
|
if lt.ZhCN != "" {
|
|
return lt.ZhCN
|
|
}
|
|
case i18n.EnUS:
|
|
if lt.EnUS != "" {
|
|
return lt.EnUS
|
|
}
|
|
default:
|
|
if v := lt.Extra[string(step)]; v != "" {
|
|
return v
|
|
}
|
|
}
|
|
}
|
|
if len(lt.Extra) > 0 {
|
|
keys := make([]string, 0, len(lt.Extra))
|
|
for k := range lt.Extra {
|
|
keys = append(keys, k)
|
|
}
|
|
sort.Strings(keys)
|
|
for _, k := range keys {
|
|
if v := lt.Extra[k]; v != "" {
|
|
return v
|
|
}
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// SetIfEmpty assigns a localized value only when the target locale slot is empty.
|
|
func (lt *LocalizedText) SetIfEmpty(locale, val string) {
|
|
if lt == nil || strings.TrimSpace(val) == "" {
|
|
return
|
|
}
|
|
canon, ok := i18n.ParseLocale(locale)
|
|
if !ok {
|
|
return
|
|
}
|
|
switch canon {
|
|
case i18n.ZhCN:
|
|
if lt.ZhCN == "" {
|
|
lt.ZhCN = val
|
|
}
|
|
case i18n.EnUS:
|
|
if lt.EnUS == "" {
|
|
lt.EnUS = val
|
|
}
|
|
default:
|
|
if lt.Extra[string(canon)] == "" {
|
|
if lt.Extra == nil {
|
|
lt.Extra = make(map[string]string)
|
|
}
|
|
lt.Extra[string(canon)] = val
|
|
}
|
|
}
|
|
}
|
|
|
|
// Set assigns a localized value for a canonical BCP-47 locale tag.
|
|
func (lt *LocalizedText) Set(locale, val string) {
|
|
if lt == nil || strings.TrimSpace(val) == "" {
|
|
return
|
|
}
|
|
canon, ok := i18n.ParseLocale(locale)
|
|
if !ok {
|
|
return
|
|
}
|
|
switch canon {
|
|
case i18n.ZhCN:
|
|
lt.ZhCN = val
|
|
case i18n.EnUS:
|
|
lt.EnUS = val
|
|
default:
|
|
if lt.Extra == nil {
|
|
lt.Extra = make(map[string]string)
|
|
}
|
|
lt.Extra[string(canon)] = val
|
|
}
|
|
}
|
|
|
|
// UnmarshalJSON accepts a plain string or an object {"zh-CN": ..., "en-US": ..., "<bcp47>": ...}.
|
|
func (lt *LocalizedText) UnmarshalJSON(data []byte) error {
|
|
var plain string
|
|
if err := json.Unmarshal(data, &plain); err == nil {
|
|
lt.ZhCN = plain
|
|
lt.EnUS = plain
|
|
lt.Extra = nil
|
|
return nil
|
|
}
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return err
|
|
}
|
|
out := LocalizedText{}
|
|
for k, v := range raw {
|
|
if k == "extra" {
|
|
var extra map[string]string
|
|
if err := json.Unmarshal(v, &extra); err == nil {
|
|
for ek, ev := range extra {
|
|
out.Set(ek, ev)
|
|
}
|
|
}
|
|
continue
|
|
}
|
|
var s string
|
|
if err := json.Unmarshal(v, &s); err != nil || s == "" {
|
|
continue
|
|
}
|
|
out.Set(k, s)
|
|
}
|
|
*lt = out
|
|
return nil
|
|
}
|
|
|
|
// Engines specifies host compatibility ranges checked before install (§6.2).
|
|
type Engines struct {
|
|
ReimsGo string `json:"reims-go,omitempty"`
|
|
PluginAPI string `json:"pluginApi,omitempty"`
|
|
UIAPI string `json:"uiApi,omitempty"`
|
|
BridgeAPI string `json:"bridgeApi,omitempty"`
|
|
}
|
|
|
|
// Entry declares executable/script/panel entrypoints. Tier is inferred from this (§6.2).
|
|
type Entry struct {
|
|
Sidecar string `json:"sidecar,omitempty"`
|
|
Script string `json:"script,omitempty"`
|
|
PanelDir string `json:"panelDir,omitempty"`
|
|
UIScript string `json:"uiScript,omitempty"`
|
|
}
|
|
|
|
// ServiceRequirement declares a service dependency with an optional SemVer range.
|
|
type ServiceRequirement struct {
|
|
Service string `json:"service"`
|
|
Version string `json:"version,omitempty"`
|
|
Optional bool `json:"optional,omitempty"`
|
|
}
|
|
|
|
// ServiceProvision declares a service provided by a plugin.
|
|
type ServiceProvision struct {
|
|
Service string `json:"service"`
|
|
Version string `json:"version"`
|
|
}
|
|
|
|
// Provenance records upstream build and source archive metadata (mandatory for runtime packages).
|
|
type Provenance struct {
|
|
UpstreamRepo string `json:"upstreamRepo,omitempty"`
|
|
Commit string `json:"commit,omitempty"`
|
|
Patches []string `json:"patches,omitempty"`
|
|
PatchHashes []string `json:"patchHashes,omitempty"`
|
|
SourcePackage string `json:"sourcePackage,omitempty"`
|
|
}
|
|
|
|
// Manifest is the declarative plugin.json descriptor (§6.2).
|
|
type Manifest struct {
|
|
Schema int `json:"schema"`
|
|
ID string `json:"id"`
|
|
Version string `json:"version"`
|
|
Name LocalizedText `json:"name"`
|
|
Description LocalizedText `json:"description"`
|
|
Publisher string `json:"publisher,omitempty"`
|
|
License string `json:"license,omitempty"`
|
|
Homepage string `json:"homepage,omitempty"`
|
|
Engines Engines `json:"engines,omitempty"`
|
|
Platforms []string `json:"platforms,omitempty"`
|
|
L10n string `json:"l10n,omitempty"` // relative directory holding <locale>.json bundles for plugin:<id>:*
|
|
Entry Entry `json:"entry,omitempty"`
|
|
Contributes Contributes `json:"contributes,omitempty"`
|
|
Requires []ServiceRequirement `json:"requires,omitempty"`
|
|
Provides []ServiceProvision `json:"provides,omitempty"`
|
|
Permissions []string `json:"permissions,omitempty"`
|
|
Activation []string `json:"activation,omitempty"`
|
|
Settings *SettingsSchema `json:"settings,omitempty"`
|
|
DefaultEnabled bool `json:"defaultEnabled,omitempty"`
|
|
Provenance *Provenance `json:"provenance,omitempty"`
|
|
}
|
|
|
|
// InferTier derives the plugin's execution tier from manifest contents (never trusting self-claims).
|
|
func (m Manifest) InferTier(isBuiltin bool) Tier {
|
|
if isBuiltin {
|
|
return TierBuiltin
|
|
}
|
|
if strings.TrimSpace(m.Entry.Sidecar) != "" {
|
|
return TierL3
|
|
}
|
|
if strings.TrimSpace(m.Entry.Script) != "" {
|
|
return TierL2
|
|
}
|
|
if strings.TrimSpace(m.Entry.PanelDir) != "" || len(m.Contributes.Panels) > 0 || len(m.Contributes.ImageSources) > 0 {
|
|
return TierL4
|
|
}
|
|
if len(m.Contributes.Runtimes) > 0 {
|
|
return TierRuntime
|
|
}
|
|
return TierL1
|
|
}
|
|
|
|
// Contributes enumerates all extension-point declarations in plugin.json (§4.2).
|
|
type Contributes struct {
|
|
Themes []ThemeContribution `json:"themes,omitempty"`
|
|
Channels []ChannelContribution `json:"channels,omitempty"`
|
|
UIScripts []UIScriptContribution `json:"uiScripts,omitempty"`
|
|
Locales []LocaleContribution `json:"locales,omitempty"`
|
|
InputFilters []InputFilterContribution `json:"inputFilters,omitempty"`
|
|
VMTemplates []VMTemplateContribution `json:"vmTemplates,omitempty"`
|
|
RuntimeSources []RuntimeSourceContribution `json:"runtimeSources,omitempty"`
|
|
RuntimeKinds []RuntimeKindContribution `json:"runtimeKinds,omitempty"`
|
|
Runtimes []RuntimePackContribution `json:"runtimes,omitempty"`
|
|
GuestDrivers []GuestDriverContribution `json:"guestDrivers,omitempty"`
|
|
Downloaders []DownloaderContribution `json:"downloaders,omitempty"`
|
|
Hooks []HookContribution `json:"hooks,omitempty"`
|
|
RuleHooks []RuleHook `json:"ruleHooks,omitempty"`
|
|
Commands []CommandContribution `json:"commands,omitempty"`
|
|
Menus []MenuContribution `json:"menus,omitempty"`
|
|
VMCards []VMCardContribution `json:"vmCards,omitempty"`
|
|
SettingsPages []SettingsPageContribution `json:"settingsPages,omitempty"`
|
|
StatusItems []StatusItemContribution `json:"statusItems,omitempty"`
|
|
Panels []PanelContribution `json:"panels,omitempty"`
|
|
ImageSources []ImageSourceContribution `json:"imageSources,omitempty"`
|
|
Views []ViewContribution `json:"views,omitempty"`
|
|
Diagnostics []DiagnosticsContribution `json:"diagnostics,omitempty"`
|
|
}
|
|
|
|
// ChannelContribution declares a framed message channel exposed through
|
|
// `reims-go plugin connect`. The host validates the declaration before it
|
|
// forwards any client data to the Sidecar.
|
|
type ChannelContribution struct {
|
|
ID string `json:"id"`
|
|
Framing string `json:"framing"`
|
|
}
|
|
|
|
// DownloaderContribution registers a pluggable file/region downloader (Builtin or L3 Sidecar).
|
|
type DownloaderContribution struct {
|
|
ID string `json:"id"`
|
|
Name LocalizedText `json:"name"`
|
|
Priority int `json:"priority,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// ThemeContribution describes a L1 token/style theme or tier-3 interactive theme (§5.1).
|
|
type ThemeContribution struct {
|
|
ID string `json:"id"`
|
|
Name LocalizedText `json:"name"`
|
|
Description LocalizedText `json:"description,omitempty"`
|
|
Appearance string `json:"appearance,omitempty"` // "light" | "dark" | "both"
|
|
Seeds map[string]string `json:"seeds,omitempty"`
|
|
Schemes []ThemeScheme `json:"schemes,omitempty"`
|
|
DeriveRules []TokenDeriveRule `json:"deriveRules,omitempty"`
|
|
Tokens map[string]string `json:"tokens,omitempty"`
|
|
DarkTokens map[string]string `json:"darkTokens,omitempty"`
|
|
Fonts []ThemeFont `json:"fonts,omitempty"`
|
|
Icons map[string]string `json:"icons,omitempty"`
|
|
BrandMark string `json:"brandMark,omitempty"`
|
|
Background string `json:"background,omitempty"`
|
|
Stylesheet string `json:"stylesheet,omitempty"` // relative path inside package
|
|
Decorations []ThemeDecoration `json:"decorations,omitempty"`
|
|
UIScript string `json:"uiScript,omitempty"` // requires ui:script
|
|
Layout *ThemeLayout `json:"layout,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// ThemeScheme is a named seed-color preset inside a theme pack.
|
|
type ThemeScheme struct {
|
|
ID string `json:"id"`
|
|
Name LocalizedText `json:"name"`
|
|
Appearance string `json:"appearance,omitempty"` // "light" | "dark" | "both"
|
|
Seeds map[string]string `json:"seeds"`
|
|
}
|
|
|
|
// TokenDeriveRule derives a CSS custom property from a seed color using
|
|
// declarative lightness/chroma/alpha adjustments per light/dark appearance.
|
|
type TokenDeriveRule struct {
|
|
Token string `json:"token"`
|
|
FromSeed string `json:"fromSeed"`
|
|
Appearance string `json:"appearance,omitempty"` // "" (both) | "light" | "dark"
|
|
Lightness float64 `json:"lightness,omitempty"` // delta in [-1, 1]
|
|
Chroma float64 `json:"chroma,omitempty"` // scale multiplier (0 = unchanged)
|
|
Alpha float64 `json:"alpha,omitempty"` // 0 = opaque / unchanged, (0,1] sets alpha
|
|
}
|
|
|
|
// ThemeFont declares a bundled font face.
|
|
type ThemeFont struct {
|
|
Family string `json:"family"`
|
|
File string `json:"file"`
|
|
Weight string `json:"weight,omitempty"`
|
|
Style string `json:"style,omitempty"`
|
|
UnicodeRange string `json:"unicodeRange,omitempty"`
|
|
}
|
|
|
|
// ThemeDecoration defines a declarative state-driven sprite/frame decoration anchored to a slot.
|
|
type ThemeDecoration struct {
|
|
ID string `json:"id"`
|
|
Slot string `json:"slot"` // e.g. "sidebar.footer", "vm.preview.br"
|
|
Width int `json:"width,omitempty"`
|
|
Height int `json:"height,omitempty"`
|
|
Alt LocalizedText `json:"alt,omitempty"`
|
|
States []ThemeDecorationState `json:"states"`
|
|
}
|
|
|
|
// ThemeDecorationState maps a state expression (e.g. "vmState==running") to a static/animated asset.
|
|
type ThemeDecorationState struct {
|
|
When string `json:"when"` // "default", "vmState==running", "busy==true", etc.
|
|
Asset string `json:"asset,omitempty"`
|
|
Frames []string `json:"frames,omitempty"`
|
|
FPS int `json:"fps,omitempty"`
|
|
}
|
|
|
|
// UIScriptContribution registers a trusted interactive theme script.
|
|
type UIScriptContribution struct {
|
|
ID string `json:"id"`
|
|
ThemeID string `json:"themeId"`
|
|
Script string `json:"script"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// PluginManifestOverride translates manifest metadata of a target third-party plugin.
|
|
type PluginManifestOverride struct {
|
|
Name string `json:"name,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
Fields map[string]string `json:"fields,omitempty"` // "settingKey.title", "settingKey.description", "commandId.title", etc.
|
|
}
|
|
|
|
// PluginLocaleOverride allows an independent Language Pack plugin to localize
|
|
// another plugin's manifest metadata and private message namespace (VS Code style).
|
|
type PluginLocaleOverride struct {
|
|
Manifest *PluginManifestOverride `json:"manifest,omitempty"`
|
|
ManifestFile string `json:"manifestFile,omitempty"`
|
|
Messages map[string]string `json:"messages,omitempty"`
|
|
MessagesFile string `json:"messagesFile,omitempty"`
|
|
}
|
|
|
|
// ResolvedLocaleFont is a ready-to-load @font-face descriptor served via AssetServer.
|
|
type ResolvedLocaleFont struct {
|
|
Family string `json:"family"`
|
|
URL string `json:"url"`
|
|
Weight string `json:"weight,omitempty"`
|
|
Style string `json:"style,omitempty"`
|
|
UnicodeRange string `json:"unicodeRange,omitempty"`
|
|
}
|
|
|
|
// LocaleContribution registers additional UI and/or backend/CLI translations,
|
|
// optional bundled CJK/regional WebFonts, and cross-plugin translation overrides.
|
|
type LocaleContribution struct {
|
|
Locale string `json:"locale"`
|
|
Label string `json:"label,omitempty"`
|
|
Fallback string `json:"fallback,omitempty"`
|
|
Priority int `json:"priority,omitempty"`
|
|
File string `json:"file,omitempty"`
|
|
BackendFile string `json:"backendFile,omitempty"`
|
|
Files map[string]string `json:"files,omitempty"` // domain -> relative JSON path (core, vm, wizard, settings, plugins, native, macosGlossary)
|
|
Messages map[string]string `json:"messages,omitempty"`
|
|
Backend map[string]string `json:"backend,omitempty"`
|
|
Fonts []ThemeFont `json:"fonts,omitempty"`
|
|
PluginOverrides map[string]PluginLocaleOverride `json:"pluginOverrides,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
TrustRank int `json:"-"`
|
|
}
|
|
|
|
// ResolvedLocalePack is the merged, ready-to-use UI language pack contributed
|
|
// by one or more active plugins for a single canonical locale tag.
|
|
type ResolvedLocalePack struct {
|
|
Locale string `json:"locale"`
|
|
Label string `json:"label"`
|
|
Fallback string `json:"fallback,omitempty"`
|
|
HasUIMessages bool `json:"has_ui_messages,omitempty"`
|
|
Messages map[string]string `json:"messages,omitempty"`
|
|
PluginMessages map[string]map[string]string `json:"plugin_messages,omitempty"`
|
|
Fonts []ResolvedLocaleFont `json:"fonts,omitempty"`
|
|
PluginIDs []string `json:"pluginIds,omitempty"`
|
|
}
|
|
|
|
// InputFilterContribution declares a host-side input filter rule (§5.4).
|
|
type InputFilterContribution struct {
|
|
ID string `json:"id"`
|
|
Event string `json:"event"` // "mouse_wheel"
|
|
Axis string `json:"axis,omitempty"` // "vertical" | "horizontal" | "both"
|
|
Transform string `json:"transform"` // "invert"
|
|
Scope string `json:"scope"` // "vm_foreground"
|
|
SettingKey string `json:"settingKey,omitempty"` // VM-scoped boolean key
|
|
HorizKey string `json:"horizontalKey,omitempty"`
|
|
VertKey string `json:"verticalKey,omitempty"`
|
|
Name LocalizedText `json:"name,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// VMTemplateContribution contributes a VM creation preset.
|
|
type VMTemplateContribution struct {
|
|
ID string `json:"id"`
|
|
DriverID string `json:"driverId,omitempty"`
|
|
Name LocalizedText `json:"name"`
|
|
Description LocalizedText `json:"description,omitempty"`
|
|
Defaults map[string]any `json:"defaults,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// RuntimeSourceContribution contributes an additional runtime download mirror/source.
|
|
type RuntimeSourceContribution struct {
|
|
ID string `json:"id"`
|
|
Kind string `json:"kind"`
|
|
Name LocalizedText `json:"name"`
|
|
IndexURL string `json:"indexUrl"`
|
|
Channel string `json:"channel,omitempty"`
|
|
License string `json:"license,omitempty"`
|
|
Publisher string `json:"publisher,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// RuntimeKindContribution registers a new runtime kind (e.g. "qemu-ovmf").
|
|
type RuntimeKindContribution struct {
|
|
Kind string `json:"kind"`
|
|
Name LocalizedText `json:"name"`
|
|
Description LocalizedText `json:"description,omitempty"`
|
|
RequiredFiles []string `json:"requiredFiles,omitempty"`
|
|
DefaultAPIVer string `json:"defaultApiVersion,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// RuntimePackContribution declares an archive/binary runtime package inside a plugin.
|
|
type RuntimePackContribution struct {
|
|
Kind string `json:"kind"`
|
|
Version string `json:"version"`
|
|
RuntimeAPI string `json:"runtimeApi"`
|
|
Capabilities []string `json:"capabilities,omitempty"`
|
|
Dir string `json:"dir,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// GuestDriverContribution declares a guest VM driver provided by an L3 Sidecar or builtin.
|
|
type GuestDriverContribution struct {
|
|
ID string `json:"id"`
|
|
Name LocalizedText `json:"name"`
|
|
Description LocalizedText `json:"description,omitempty"`
|
|
RuntimeKind string `json:"runtimeKind"`
|
|
RuntimeAPIRange string `json:"runtimeApiRange,omitempty"`
|
|
Capabilities []string `json:"capabilities,omitempty"`
|
|
VMRoots []string `json:"vmRoots,omitempty"` // slash-separated paths relative to DataRoot
|
|
CreateSchema *SettingsSchema `json:"createSchema,omitempty"`
|
|
SettingsSchema *SettingsSchema `json:"settingsSchema,omitempty"`
|
|
// ConsoleEndpoint selects who serves screenshots and input: "qmp" (the
|
|
// host's QMP proxy, default) or "driver". Experimental until the console
|
|
// router lands.
|
|
ConsoleEndpoint string `json:"consoleEndpoint,omitempty"`
|
|
// PasteCombo is the key combination that pastes in the guest, such as
|
|
// "meta_l+v" or "ctrl+v".
|
|
PasteCombo string `json:"pasteCombo,omitempty"`
|
|
Keymap string `json:"keymap,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// VMRef identifies a VM by owning driver and name on the Sidecar wire.
|
|
type VMRef struct {
|
|
DriverID string `json:"driver_id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
// VMEndpoint is one way to reach a guest, as a Sidecar reports it. The
|
|
// internal/driver package validates and acts on it.
|
|
type VMEndpoint struct {
|
|
Kind string `json:"kind"`
|
|
Host string `json:"host,omitempty"`
|
|
Port int `json:"port,omitempty"`
|
|
User string `json:"user,omitempty"`
|
|
Distro string `json:"distro,omitempty"`
|
|
VM string `json:"vm,omitempty"`
|
|
Serial string `json:"serial,omitempty"`
|
|
Ready bool `json:"ready"`
|
|
}
|
|
|
|
// GuestOSInfo describes the guest operating system on the Sidecar wire.
|
|
type GuestOSInfo struct {
|
|
Family string `json:"family,omitempty"`
|
|
Distro string `json:"distro,omitempty"`
|
|
Version string `json:"version,omitempty"`
|
|
Arch string `json:"arch,omitempty"`
|
|
}
|
|
|
|
// ReportedVMState is the payload of `host/vm.reportState`.
|
|
type ReportedVMState struct {
|
|
Ref VMRef `json:"ref"`
|
|
State string `json:"state"`
|
|
Ready *bool `json:"ready,omitempty"`
|
|
Phase string `json:"phase,omitempty"`
|
|
Endpoints []VMEndpoint `json:"endpoints,omitempty"`
|
|
GuestOS *GuestOSInfo `json:"guest_os,omitempty"`
|
|
}
|
|
|
|
// HookContribution subscribes a Sidecar or L2 script to a lifecycle event.
|
|
type HookContribution struct {
|
|
Event string `json:"event"`
|
|
Priority int `json:"priority,omitempty"`
|
|
Blocking bool `json:"blocking,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// CommandContribution exposes a command callable via CLI (`plugin run`) or GUI menu.
|
|
type CommandContribution struct {
|
|
ID string `json:"id"`
|
|
Title LocalizedText `json:"title"`
|
|
Description LocalizedText `json:"description,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// MenuContribution contributes a button/menu item to a declared UI slot (e.g. vm.toolbar).
|
|
type MenuContribution struct {
|
|
ID string `json:"id"`
|
|
Slot string `json:"slot"` // "vm.toolbar"
|
|
Command string `json:"command"`
|
|
Title LocalizedText `json:"title"`
|
|
When string `json:"when,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// VMCardContribution contributes key-value info to `vm.card`.
|
|
type VMCardContribution struct {
|
|
ID string `json:"id"`
|
|
Title LocalizedText `json:"title"`
|
|
Value LocalizedText `json:"value,omitempty"`
|
|
Badge string `json:"badge,omitempty"` // "ok" | "warn" | "idle" | "error"
|
|
When string `json:"when,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// SettingsPageContribution declares a plugin settings group.
|
|
type SettingsPageContribution struct {
|
|
ID string `json:"id"`
|
|
Title LocalizedText `json:"title"`
|
|
Group string `json:"group,omitempty"` // e.g. "keyboard", "collaboration", "general"
|
|
Scope string `json:"scope,omitempty"` // "app" | "vm"
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// StatusItemContribution contributes an item to `statusbar.right`.
|
|
type StatusItemContribution struct {
|
|
ID string `json:"id"`
|
|
Slot string `json:"slot"` // "statusbar.right"
|
|
Text LocalizedText `json:"text"`
|
|
Tooltip LocalizedText `json:"tooltip,omitempty"`
|
|
Command string `json:"command,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// PanelContribution declares an L4 sandboxed iframe panel in a declared slot.
|
|
type PanelContribution struct {
|
|
ID string `json:"id"`
|
|
Slot string `json:"slot"` // "settings.plugin" | "vm.card" | "sidebar.footer"
|
|
Title LocalizedText `json:"title"`
|
|
Entry string `json:"entry"` // relative HTML file under entry.panelDir
|
|
Height int `json:"height,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// ImageSourceContribution registers a tab entry in the top-level Images page
|
|
// segmented control. External plugins provide a sandboxed L4 iframe Entry under
|
|
// entry.panelDir; compiled-in builtins may set Native to mount a host view.
|
|
type ImageSourceContribution struct {
|
|
ID string `json:"id"`
|
|
Title LocalizedText `json:"title"`
|
|
Description LocalizedText `json:"description,omitempty"`
|
|
Order int `json:"order,omitempty"`
|
|
Entry string `json:"entry,omitempty"`
|
|
Height int `json:"height,omitempty"`
|
|
Native string `json:"native,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// ViewContribution declares a sandboxed iframe view with its own page, tab or
|
|
// dialog (§5.6). Entry is relative to entry.panelDir; Location is one of
|
|
// ViewLocationCatalog.
|
|
type ViewContribution struct {
|
|
ID string `json:"id"`
|
|
Title LocalizedText `json:"title"`
|
|
Icon string `json:"icon,omitempty"` // packaged monochrome SVG, tinted by the host
|
|
Location string `json:"location"` // "sidebar" | "vm.tab" | "settings" | "dialog"
|
|
Entry string `json:"entry"`
|
|
Order int `json:"order,omitempty"`
|
|
When string `json:"when,omitempty"`
|
|
MinWidth int `json:"minWidth,omitempty"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// ThemeLayout declares layout options of a theme (§5.1). Values come from
|
|
// ThemeLayoutCatalog; they move and size regions but never hide operation entries.
|
|
type ThemeLayout struct {
|
|
SidebarPosition string `json:"sidebarPosition,omitempty"`
|
|
SidebarMode string `json:"sidebarMode,omitempty"`
|
|
Density string `json:"density,omitempty"`
|
|
Titlebar string `json:"titlebar,omitempty"`
|
|
}
|
|
|
|
// DiagnosticsContribution declares a diagnostics collector.
|
|
type DiagnosticsContribution struct {
|
|
ID string `json:"id"`
|
|
Title LocalizedText `json:"title"`
|
|
PluginID string `json:"pluginId,omitempty"`
|
|
}
|
|
|
|
// SettingsSchema is a JSON Schema subset with Reims-Go extensions (§6.2).
|
|
type SettingsSchema struct {
|
|
Title LocalizedText `json:"title,omitempty"`
|
|
Group string `json:"x-group,omitempty"` // e.g. "keyboard", "collaboration"
|
|
Scope string `json:"x-scope,omitempty"` // "app" | "vm" | "both"
|
|
Properties map[string]SettingProperty `json:"properties"`
|
|
Order []string `json:"x-order,omitempty"`
|
|
}
|
|
|
|
// SettingProperty describes one configurable field.
|
|
type SettingProperty struct {
|
|
Type string `json:"type"` // "boolean" | "string" | "number" | "integer"
|
|
Title LocalizedText `json:"title"`
|
|
Description LocalizedText `json:"description,omitempty"`
|
|
Default any `json:"default,omitempty"`
|
|
Enum []string `json:"enum,omitempty"`
|
|
EnumLabels []LocalizedText `json:"x-enumLabels,omitempty"`
|
|
Minimum *float64 `json:"minimum,omitempty"`
|
|
Maximum *float64 `json:"maximum,omitempty"`
|
|
Secret bool `json:"x-secret,omitempty"`
|
|
Effect string `json:"x-effect,omitempty"` // "immediate" | "next_start"
|
|
Scope string `json:"x-scope,omitempty"` // "app" | "vm" | "both"
|
|
Group string `json:"x-group,omitempty"` // VM settings section id
|
|
Required bool `json:"required,omitempty"`
|
|
}
|
|
|
|
// PermissionLevel categorizes permission risk (§7.1).
|
|
type PermissionLevel string
|
|
|
|
const (
|
|
PermLow PermissionLevel = "low"
|
|
PermMedium PermissionLevel = "medium"
|
|
PermHigh PermissionLevel = "high"
|
|
PermForbidden PermissionLevel = "forbidden"
|
|
)
|
|
|
|
// PermissionSpec classifies a declared permission string.
|
|
type PermissionSpec struct {
|
|
Name string `json:"name"`
|
|
Level PermissionLevel `json:"level"`
|
|
}
|
|
|
|
// ClassifyPermission returns the risk tier of a permission per §7.1.
|
|
func ClassifyPermission(perm string) PermissionLevel {
|
|
p := strings.TrimSpace(perm)
|
|
switch p {
|
|
case "vm:read", "ui:notify", "task:progress", "fs:plugin_data", "log:read":
|
|
return PermLow
|
|
case "vm:intent", "runtime:source", "ui:slot", "input:filter", "fs:pick":
|
|
return PermMedium
|
|
case "driver:vm", "runtime:provider", "process:spawn", "vm:control", "vm:screen",
|
|
"qmp:write", "fs:vm_dir", "fs:shared", "host:clipboard", "ui:script":
|
|
return PermHigh
|
|
}
|
|
if strings.HasPrefix(p, "net:") && len(p) > len("net:") {
|
|
return PermMedium
|
|
}
|
|
return PermForbidden
|
|
}
|
|
|
|
// HasHighRiskPermission returns all high-risk permissions in perms.
|
|
func HighRiskPermissions(perms []string) []string {
|
|
var out []string
|
|
for _, p := range perms {
|
|
if ClassifyPermission(p) == PermHigh {
|
|
out = append(out, p)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// ForbiddenPermissions returns any unrecognized/forbidden permissions in perms.
|
|
func ForbiddenPermissions(perms []string) []string {
|
|
var out []string
|
|
for _, p := range perms {
|
|
if ClassifyPermission(p) == PermForbidden {
|
|
out = append(out, p)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// DeclaredUISlots lists the host-declared UI slots and their max item caps
|
|
// (§4.2), derived from UISlotCatalog.
|
|
var DeclaredUISlots = func() map[string]int {
|
|
out := make(map[string]int, len(UISlotCatalog))
|
|
for id, spec := range UISlotCatalog {
|
|
out[id] = spec.Max
|
|
}
|
|
return out
|
|
}()
|
|
|
|
// IsDeclaredSlot checks whether slot is a host-recognized UI slot.
|
|
func IsDeclaredSlot(slot string) bool {
|
|
_, ok := UISlotCatalog[slot]
|
|
return ok
|
|
}
|
|
|
|
// PluginInfo is the read-only UI/CLI view of an installed or builtin plugin.
|
|
type PluginInfo struct {
|
|
ID string `json:"id"`
|
|
Version string `json:"version"`
|
|
Name LocalizedText `json:"name"`
|
|
Description LocalizedText `json:"description"`
|
|
Publisher string `json:"publisher,omitempty"`
|
|
License string `json:"license,omitempty"`
|
|
Homepage string `json:"homepage,omitempty"`
|
|
Source SourceKind `json:"source"`
|
|
Trust TrustLevel `json:"trust"`
|
|
Tier Tier `json:"tier"`
|
|
State State `json:"state"`
|
|
Enabled bool `json:"enabled"`
|
|
Removable bool `json:"removable"`
|
|
System bool `json:"system,omitempty"`
|
|
InUse bool `json:"in_use"`
|
|
Error string `json:"error,omitempty"`
|
|
DegradedReason string `json:"degraded_reason,omitempty"`
|
|
Permissions []PermissionSpec `json:"permissions,omitempty"`
|
|
ApprovedPermissions []string `json:"approved_permissions,omitempty"`
|
|
NeedsApproval bool `json:"needs_approval"`
|
|
Risks []string `json:"risks,omitempty"`
|
|
Locales []string `json:"locales,omitempty"` // UI languages the plugin contributes
|
|
Requires []string `json:"requires,omitempty"`
|
|
Provides []string `json:"provides,omitempty"`
|
|
Settings *SettingsSchema `json:"settings,omitempty"`
|
|
InstallDir string `json:"install_dir,omitempty"`
|
|
EntryHash string `json:"entry_hash,omitempty"`
|
|
EntryPath string `json:"entry_path,omitempty"`
|
|
LogPath string `json:"log_path,omitempty"`
|
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
|
}
|
|
|
|
// DiagnosticsEntry is one redacted diagnostic section contributed by a plugin.
|
|
type DiagnosticsEntry struct {
|
|
PluginID string `json:"plugin_id"`
|
|
Title string `json:"title"`
|
|
Data map[string]any `json:"data,omitempty"`
|
|
Text string `json:"text,omitempty"`
|
|
}
|