package manifest
import "github.com/nsgo-dev/game/pkg/gameplugin/manifest"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
Constants
const FileName = "plugin.yaml"FileName is the plugin manifest file's name at the root of a plugin's Go module.
const ManifestVersion = 1ManifestVersion 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(m Manifest) ([]byte, error)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.
func ValidateModulePath(modulePath string) errorValidateModulePath checks that modulePath is a valid Go module path.
func ValidateName(name string) errorValidateName 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(modulePath, pkgPath string) errorValidatePackagePath checks that pkgPath is a valid Go package import path equal to modulePath or strictly under modulePath + "/".
Types
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 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 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 struct {
// Runtime is the import path of the Go package that provides the plugin's runtime entry (func Plugin() gameplugin.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 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 (gameplugin.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(data []byte) (Manifest, error)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.
func ParseFS(fsys fs.FS, dir string) (Manifest, error)func (m Manifest) SupportsPlatform(platform string) boolSupportsPlatform reports whether m declares support for platform (one of Platforms). An empty Platforms list or one containing PlatformAll matches every known platform.
func (m Manifest) Validate() errorValidate 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.