Documentation
¶
Overview ¶
Package manifest parses, validates and canonically encodes plugin.yaml manifests for Go plugins.
A plugin.yaml file sits at the root of a plugin's Go module and declares its identity, Go module path, engine compatibility constraint, target plugin API version, supported platforms, Go entry packages (runtime, editor and CLI), module-keyed dependencies and conflicts, and contributed symbols.
There is deliberately no version field in plugin.yaml: a plugin's version is its Go module version, resolved by the game project's go.mod, and is never duplicated in the manifest.
Index ¶
Examples ¶
Constants ¶
const FileName = "plugin.yaml"
FileName is the plugin manifest file's name at the root of a plugin's Go module.
const ManifestVersion = 1
ManifestVersion is the plugin manifest schema version this package reads and writes.
const PlatformAll = "all"
PlatformAll is the wildcard value in Manifest.Platforms meaning every target platform is supported.
const SchemaURL = "https://game.nsgo.dev/schemas/plugin.v1.json"
SchemaURL is where the JSON Schema of version 1 plugin manifests (plugin.yaml) is published.
Variables ¶
var ErrInvalid = errors.New("plugin manifest: invalid manifest")
ErrInvalid reports that a plugin.yaml manifest breaks the schema or validation rules.
var Platforms = []string{"macos", "windows", "linux", "ios", "android", "web"}
Platforms lists every concrete target platform a plugin manifest may name under platforms.
Functions ¶
func Encode ¶
Encode validates m and writes it as deterministic 2-space YAML: fields in a fixed order, every list sorted in byte order (CLI entries by Name), and requires map keys sorted in byte order. A ManifestVersion of 0 (a manifest built in code) is written as ManifestVersion. Parse reads the output back as an equal manifest, and encoding that again gives the same bytes.
Example ¶
Encode validates a Manifest and writes canonical 2-space YAML with lists and maps sorted in byte order.
package main
import (
"fmt"
"github.com/nsgo-dev/game/pkg/plugin/manifest"
)
func main() {
data, err := manifest.Encode(manifest.Manifest{
Name: "healthkit",
Module: "example.com/healthkit",
Engine: ">=0.4.0 <0.5.0",
API: 1,
Platforms: []string{"web", "macos"},
Entries: manifest.Entries{
Runtime: "example.com/healthkit/health",
},
Requires: map[string]string{
"example.com/zeta": "^1.0.0",
"example.com/alpha": ">=0.2.0",
},
Conflicts: []string{"example.com/old", "example.com/ancient"},
})
if err != nil {
fmt.Println(err)
return
}
fmt.Print(string(data))
}
Output: manifestVersion: 1 name: healthkit module: example.com/healthkit engine: '>=0.4.0 <0.5.0' api: 1 platforms: [macos, web] entries: runtime: example.com/healthkit/health requires: example.com/alpha: '>=0.2.0' example.com/zeta: ^1.0.0 conflicts: [example.com/ancient, example.com/old]
func ValidateModulePath ¶
ValidateModulePath checks that modulePath is a valid Go module path.
func ValidateName ¶
ValidateName checks that name is a valid plugin name: 1 to 64 lower-case ASCII letters, digits and '-', starting with a letter or digit (the same rule as project.ValidatePackName).
func ValidatePackagePath ¶
ValidatePackagePath checks that pkgPath is a valid Go package import path equal to modulePath or strictly under modulePath + "/".
Types ¶
type CLIEntry ¶
type CLIEntry struct {
// Name is the subcommand name invoked as "game <name>": 1 to 64 lower-case ASCII letters, digits and '-', starting with a letter or digit.
Name string `yaml:"name" json:"name" schema:"required,minLength=1"`
// Package is the Go import path of the main package implementing the command, inside the plugin's module.
Package string `yaml:"package" json:"package" schema:"required,minLength=1"`
}
CLIEntry names one command package a plugin contributes to the game CLI.
type Contributes ¶
type Contributes struct {
// Components lists the names of scene components the plugin registers.
Components []string `yaml:"components,omitempty,flow" json:"components,omitempty"`
// Editor lists the panels, tools and commands the plugin adds to the scene editor.
Editor *EditorContributes `yaml:"editor,omitempty" json:"editor,omitempty"`
// AgentTools lists the MCP agent tool names the plugin exposes, such as "plugin.healthkit.heal_all".
AgentTools []string `yaml:"agentTools,omitempty,flow" json:"agentTools,omitempty"`
}
Contributes indexes the components, editor extensions and agent tools a plugin registers. Tools such as game plugin check compare it against the plugin's code.
type EditorContributes ¶
type EditorContributes struct {
// Panels lists the IDs of editor panels the plugin adds.
Panels []string `yaml:"panels,omitempty,flow" json:"panels,omitempty"`
// Tools lists the IDs of viewport tools the plugin adds.
Tools []string `yaml:"tools,omitempty,flow" json:"tools,omitempty"`
// Commands lists the IDs of editor commands the plugin adds.
Commands []string `yaml:"commands,omitempty,flow" json:"commands,omitempty"`
}
EditorContributes lists the editor extension IDs a plugin registers.
type Entries ¶
type Entries struct {
// Runtime is the import path of the Go package that provides the plugin's runtime entry (func Plugin() plugin.Plugin).
Runtime string `yaml:"runtime,omitempty" json:"runtime,omitempty"`
// Editor is the import path of the Go package that provides the plugin's editor entry (func Plugin() editor.Plugin).
Editor string `yaml:"editor,omitempty" json:"editor,omitempty"`
// CLI lists command packages that extend the game CLI via go.mod tool directives.
CLI []CLIEntry `yaml:"cli,omitempty" json:"cli,omitempty"`
}
Entries names the Go packages inside a plugin's module that integrate with the game runtime, the scene editor and the game CLI. At least one of Runtime, Editor or CLI must be set.
type Manifest ¶
type Manifest struct {
// ManifestVersion is the schema version of plugin.yaml. A file must state [ManifestVersion] (1); a manifest built in code may leave it 0, and [Encode] writes [ManifestVersion].
ManifestVersion int `yaml:"manifestVersion" json:"manifestVersion" schema:"required"`
// Name uniquely identifies the plugin: 1 to 64 lower-case ASCII letters, digits and '-', starting with a letter or digit.
Name string `yaml:"name" json:"name" schema:"required,minLength=1"`
// Module is the Go module path of the plugin, which must equal the module line of its go.mod.
Module string `yaml:"module" json:"module" schema:"required,minLength=1"`
// Description summarizes what the plugin provides on a single line.
Description string `yaml:"description,omitempty" json:"description,omitempty"`
// License is the plugin's license identifier, such as "MIT" or "Apache-2.0".
License string `yaml:"license,omitempty" json:"license,omitempty"`
// Authors names the people or organizations who maintain the plugin.
Authors []string `yaml:"authors,omitempty,flow" json:"authors,omitempty"`
// Repository is the HTTP or HTTPS URL of the plugin's source repository.
Repository string `yaml:"repository,omitempty" json:"repository,omitempty"`
// Engine is a semantic version constraint on github.com/nsgo-dev/game, such as ">=0.4.0 <0.5.0".
Engine string `yaml:"engine" json:"engine" schema:"required,minLength=1"`
// API is the plugin API version (plugin.APIVersion) the plugin targets; it must be a positive integer.
API int `yaml:"api" json:"api" schema:"required,minimum=1"`
// Platforms lists the target platforms the plugin supports: either ["all"] or a subset of macos, windows, linux, ios, android and web. When omitted, all platforms are supported.
Platforms []string `yaml:"platforms,omitempty,flow" json:"platforms,omitempty"`
// Entries names the Go packages inside Module that provide the plugin's runtime, editor and CLI integrations.
Entries Entries `yaml:"entries" json:"entries" schema:"required"`
// Requires maps Go module paths of plugins this plugin depends on to semantic version constraints.
Requires map[string]string `yaml:"requires,omitempty" json:"requires,omitempty"`
// Conflicts lists Go module paths of plugins that cannot be installed alongside this plugin.
Conflicts []string `yaml:"conflicts,omitempty,flow" json:"conflicts,omitempty"`
// Contributes summarizes the components, editor extensions and agent tools the plugin registers, for indexing and comparison by game plugin check.
Contributes *Contributes `yaml:"contributes,omitempty" json:"contributes,omitempty"`
}
Manifest describes a Go plugin module. Plugin authors write it as YAML in FileName (plugin.yaml) at the root of the plugin's Go module; Parse and ParseFS read it and Encode writes it.
func Parse ¶
Parse decodes and validates a plugin.yaml manifest. Unknown fields, duplicate keys, trailing YAML documents and a missing, unsupported or non-integer-literal manifestVersion are refused.
Its errors match ErrInvalid with errors.Is, and are *loaderr.Error values that give the line, field and fix. A caller that read data from a file names it with loaderr.WithFile, as ParseFS does.
Example ¶
Parse reads and validates a plugin.yaml manifest.
package main
import (
"fmt"
"github.com/nsgo-dev/game/pkg/plugin/manifest"
)
func main() {
m, err := manifest.Parse([]byte(`manifestVersion: 1
name: healthkit
module: example.com/healthkit
engine: ">=0.4.0 <0.5.0"
api: 1
platforms: [all]
entries:
runtime: example.com/healthkit/health
editor: example.com/healthkit/healtheditor
requires:
example.com/navkit: "^0.3.0"
`))
if err != nil {
fmt.Println(err)
return
}
fmt.Println(m.Name, m.Module, m.API)
fmt.Println(m.Entries.Runtime, m.SupportsPlatform("ios"))
}
Output: healthkit example.com/healthkit 1 example.com/healthkit/health true
func ParseFS ¶
ParseFS reads FileName (plugin.yaml) from dir in fsys and parses it with Parse, naming the file in any returned *loaderr.Error.
Example ¶
ParseFS reads plugin.yaml from a directory in an fs.FS and attaches the file path to any load error.
package main
import (
"fmt"
"testing/fstest"
"github.com/nsgo-dev/game/pkg/plugin/manifest"
)
func main() {
fsys := fstest.MapFS{
"healthkit/plugin.yaml": {Data: []byte("manifestVersion: 1\nname: healthkit\nmodule: example.com/healthkit\nengine: '>=0.4.0 <0.5.0'\napi: 1\nentries:\n runtime: example.com/healthkit/health\n")},
}
m, err := manifest.ParseFS(fsys, "healthkit")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(m.Name, m.Entries.Runtime)
}
Output: healthkit example.com/healthkit/health
func (Manifest) SupportsPlatform ¶
SupportsPlatform reports whether m declares support for platform (one of Platforms). An empty Platforms list or one containing PlatformAll matches every known platform.
func (Manifest) Validate ¶
Validate checks every field of m. ManifestVersion may be 0 for a manifest built in code, or ManifestVersion; Parse additionally requires a file to state ManifestVersion. Its errors are *loaderr.Error values that name the field at fault and how to fix it, and match ErrInvalid with errors.Is.