Help us shape the future of Go! Take the 2026 Go Developer Survey

pluginspec

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package pluginspec is the lockfile plugin contract: the signed manifest a plugin ships with, and the rule that turns a plugin's stdout and exit status into an answer.

A plugin answers exactly one yes/no question about one file. Its only output is the byte 1 or 0 on stdout (one trailing newline tolerated) followed by exit status 0. Anything else is a failure, and every plugin-caused failure reaches the agent as the single code AgentErrorCode; the precise cause is kept for the audit only.

Index

Constants

View Source
const (
	MaxTimeout = 120 * time.Second
	MaxMemory  = 2 << 30
)

Bounds on what a manifest may ask for.

View Source
const AgentErrorCode = "plugin_error"

AgentErrorCode is the only error an agent sees for a plugin-caused failure, whatever the cause.

View Source
const ProtocolVersion = 1

ProtocolVersion is the only plugin protocol this package knows.

Variables

View Source
var MediaTypes = map[string]bool{
	"*/*":             true,
	"application/pdf": true,
	"application/zip": true,
	"application/vnd.openxmlformats-officedocument.wordprocessingml.document": true,
}

MediaTypes is the closed list of values allowed in a manifest's accepts.

Functions

func ParseBytes

func ParseBytes(s string) (int64, error)

ParseBytes reads a size such as "512MiB", "1GiB", "64KiB" or "4096".

func ValidName

func ValidName(s string) bool

ValidName reports whether s is a valid plugin name.

func ValidVersion

func ValidVersion(s string) bool

ValidVersion reports whether s is an exact X.Y.Z version.

Types

type FailureCause

type FailureCause string

FailureCause is why a plugin gave no answer. It is for the audit only.

const (
	CauseNone          FailureCause = ""
	CauseExitCode      FailureCause = "exit_code"
	CauseSignal        FailureCause = "signal"
	CauseTimeout       FailureCause = "timeout"
	CauseInvalidOutput FailureCause = "invalid_output"
	CauseOutputTooLong FailureCause = "output_too_long"
	CauseSandbox       FailureCause = "sandbox"
)

type Limits

type Limits struct {
	CPUSeconds int
	Memory     int64 // address space, bytes
	Timeout    time.Duration
}

Limits are the resources a plugin run may use.

type Manifest

type Manifest struct {
	Name     string
	Version  string
	Protocol int
	Question string
	One      string
	Zero     string
	Accepts  []string
	Limits   Limits
}

Manifest is a plugin's plugin.toml.

func ParseManifest

func ParseManifest(b []byte) (Manifest, error)

ParseManifest decodes and validates a plugin.toml. Unknown keys, notably params, are an error: plugins take no parameters.

func (Manifest) Validate

func (m Manifest) Validate() error

Validate checks a manifest against the contract.

type Outcome

type Outcome struct {
	Answer *bool
	Cause  FailureCause
}

Outcome is the result of one plugin run: an answer, or no answer and a cause. Answer is nil exactly when Cause is not CauseNone.

func Failed

func Failed(c FailureCause) Outcome

Failed builds an outcome without an answer.

func ParseAnswer

func ParseAnswer(stdout []byte, truncated bool, exitCode int, signaled bool) Outcome

ParseAnswer applies the contract to what a plugin process produced: stdout must be exactly "1" or "0", optionally followed by one "\n", and the process must have exited with status 0. truncated reports that the plugin wrote more than the read cap.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL