plugin

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 26 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package plugin is the modules a script calls, the one shape they all have, and the few ways out they all go through. Everything that comes with Corbie is built through this package, and an extension uses the same.

Index

Constants

View Source
const (
	NotFound     = "not_found"     // the thing asked for is not there
	Refused      = "refused"       // the other side said no
	TimedOut     = "timeout"       // it took too long
	NotPermitted = "not_permitted" // the system, not Corbie, would not allow it
	BadInput     = "bad_input"     // the call was written wrong
	Failed       = "failed"        // anything else
)

The codes an error has.

View Source
const HomeVariable = "HOME"

HomeVariable is the variable that names the runner's user's home directory.

View Source
const MaxWhole = 64 << 20

MaxWhole is the most of anything that is handed to a script whole, and so held in the job's memory: a file's contents, a body, what a program printed, something unpacked, a blob read at once, one item of a blob. It is the one such size there is. Anything larger is had as a blob, which is read a part at a time and written as it arrives.

Variables

This section is empty.

Functions

func Certificates

func Certificates(text []byte) (*x509.CertPool, error)

Certificates reads the certificates a script gives to be trusted in place of the machine's own, as PEM text. Only those are then trusted. One that cannot be read is refused, not passed over: a call that went ahead trusting fewer certificates than were written would hide the mistake.

func EscapedAddress

func EscapedAddress(address string) string

EscapedAddress gives an address as it goes out, with what cannot go out as it is escaped, byte for byte: a blank and a letter beyond ASCII anywhere, and before the query the marks no path may hold. An address left with one of those in its path would have the whole path written out afresh as it is sent, and what was escaped in it already, such as %2F, would come out unescaped.

func FileError

func FileError(err error, path string) error

FileError gives a file system's error the one shape, for a plugin.

func JSON

func JSON(v any) ([]byte, error)

JSON writes data as JSON. A handle anywhere in it is refused, as it is wherever a handle would be written out as data.

func Names

func Names() []string

Names lists the modules.

func Plain

func Plain(v any) any

Plain gives data with every blob in it as its reference, which a blob has only once it is in the store, so that it can be written as JSON.

func Refusal

func Refusal(err error) error

Refusal gives the refusal inside an error, or nil. What a way out refused can come back to a plugin inside the error of a library it wraps, and the plugin passes the refusal on as it is.

func Register

func Register(m *Module)

Register adds a module. It refuses a name a script's own things have.

func StandIn

func StandIn(names func(ctx context.Context, host string) ([]string, error), connect func(ctx context.Context, address string) (net.Conn, error))

StandIn puts a stand-in in place of the network for every job of this process: names gives the addresses a name has, and connect opens a connection to an address. Every check is made as on the real network, on the name and on the addresses given. It is for tests that run scripts as they are written, against servers of the tests' own.

func Text

func Text(first any, what string) (string, error)

Text reads the first thing of a call as text.

func TextOf

func TextOf(v any) any

TextOf gives a number or a true or false as the text it is written as, and anything else as it is. It is for a place that takes text or a handle, where a script may as well write a number.

func TooLarge

func TooLarge(what string) error

TooLarge is the one failure of something too large to hand a script whole. It says the way out, which is the same everywhere.

func TypeOf

func TypeOf(name string) string

TypeOf is the type contents have that come from a file of a name.

Types

type Blob

type Blob struct {
	Type string
	Size int64
	// Ref is where the blob is in the store, once it is there.
	Ref *blob.Ref
	// contains filtered or unexported fields
}

A Blob is a blob as a plugin and a script hold it: a type, a size, and contents that can be read. One a job makes stays with the job until its reference leaves, in an emit or in the result; only then is it sent to the store.

func NewBlob

func NewBlob(typ string, contents []byte) *Blob

NewBlob makes a blob of contents the job holds.

func StoredBlob

func StoredBlob(ref blob.Ref) *Blob

StoredBlob is a blob that is in the store.

func (*Blob) All

func (b *Blob) All(j *Job) ([]byte, error)

All reads the whole of a blob, which may be no larger than what is held whole.

func (*Blob) Read

func (b *Blob) Read(j *Job, from, length int64) ([]byte, error)

Read reads part of a blob's contents.

func (*Blob) Reader

func (b *Blob) Reader(j *Job) io.Reader

Reader gives the blob to be read from start to end, a part at a time.

func (*Blob) Source

func (b *Blob) Source(j *Job) io.ReaderAt

Source gives the blob to be read at any place in it, a part at a time.

func (*Blob) Store

func (b *Blob) Store(j *Job) (blob.Ref, error)

Store sends the blob to the store, if it is not there yet, and gives its reference.

type Bytes

type Bytes []byte

Bytes is the one type bytes have everywhere.

type Call

type Call struct {
	Options []string
	// Variadic is for the rare call that the language itself makes with
	// several things, as a tag on a template is called: first is then the
	// list of everything it was called with.
	Variadic bool
	Do       func(job *Job, first any, options Options) (any, error)
}

A Call is one thing a script can ask of a plugin: the one obvious thing first, then named options. An option the call does not list is refused.

func (*Call) Invoke

func (c *Call) Invoke(job *Job, module, name string, first any, options Options) (any, error)

Invoke makes a call for a script, refusing options it does not list.

type Channel

type Channel interface {
	Emit(name string, data any) error
	Variable(name string) (value string, set bool, err error)
	ReadBlob(ref blob.Ref, from, length int64) ([]byte, error)
	WriteBlob(typ string, size int64, contents io.Reader) (blob.Ref, error)
	Define(source string, files map[string]string) (blob.Ref, error)
}

The Channel is a job's own way to its runner: what it emits, its blobs, the machines it defines, and the runner's variables it is allowed.

type Draining

type Draining struct {
	To  io.Writer
	Err error
}

Draining passes on what a program prints, and never holds the program up: once what it writes to takes no more, the rest is let go, and the failure kept.

func (*Draining) Write

func (d *Draining) Write(p []byte) (int, error)

type Error

type Error struct {
	Code    string
	Message string
}

An Error is the one shape a plugin's error has: a short code from a short list, and what happened.

func Errorf

func Errorf(code, format string, args ...any) *Error

Errorf makes an error with a code.

func (*Error) Error

func (e *Error) Error() string

type Job

type Job struct {
	Context context.Context
	// Perms is every layer that applies to the job.
	Perms *permission.Set
	// Scratch is the job's own directory: a path with no leading slash is in
	// it.
	Scratch string
	// Wrapper is the exec wrapper: the runner's own command, put in front
	// of every program started.
	Wrapper []string
	// Path is where programs are looked for.
	SearchPath string
	// Secrets are the values of the secrets the job was sent, by name.
	Secrets map[string]string
	// Channel is the job's own channel, which every job has.
	Channel Channel
	// Noted, where it is set, is told each further form a secret's value
	// is about to leave in, before the value is handed over. The job's
	// runner searches what the job's process prints, which the process
	// cannot do for itself, and learns the forms this way.
	Noted func(form, names string)
	// contains filtered or unexported fields
}

A Job is what a plugin is given of the job its script runs in: the few ways out, which Corbie keeps. A plugin never opens anything by itself. It asks here for a way to connect, a path, a program or a variable; every layer of the job's permissions is checked, what was used is noted, and the thing is handed over or refused.

func (*Job) As

func (j *Job) As(data []byte, form, typ string) (any, error)

As gives bytes to a script in the form it asked for: "text", "bytes", "json" or "blob". A byte order mark at the start of text or data is dropped.

func (*Job) Contents

func (j *Job) Contents(v any) ([]byte, string, error)

Contents gives the bytes of something a script hands a plugin as contents: text, bytes, a blob, or any other data, which is written as JSON. The second result is the type such contents have.

func (*Job) Dial

func (j *Job) Dial(ctx context.Context, address string, with ...*Secret) (net.Conn, error)

Dial opens a connection, plain, for a plugin to use or to encrypt. The destination is checked by the name asked for and again by the address the name resolves to, and only an address that was checked is connected to. A plugin that is handed further addresses dials each the same way.

With secrets, the connection is one they may travel over: each must be bound to this destination, as it must be when its value is asked for.

func (*Job) Directory

func (j *Job) Directory(pattern string) (string, error)

Directory makes a fresh directory inside the job's scratch directory, for a plugin's own working files. It goes with the scratch directory when the job ends.

func (*Job) End

func (j *Job) End()

End does what was left for the job's end.

func (*Job) Entry

func (j *Job) Entry(path string) (string, error)

Entry gives the real location of a name in its directory, for the name itself to be removed. The directory is taken where it really is, and the name is not followed if it is a link: removing a link removes the link and not what it points to. It is checked against fs.write.

func (*Job) File added in v0.5.0

func (j *Job) File(pattern string, contents []byte) (string, error)

File makes a fresh file inside the job's scratch directory, holding the contents, for a plugin to hand a program. Only the runner's user can read it, and it goes with the scratch directory when the job ends.

func (*Job) FileBlob

func (j *Job) FileBlob(path, typ string) (*Blob, error)

FileBlob makes a blob of a file, read where it lies and not copied. The file is held open until the job ends, and is read to the size it had when it was opened.

func (*Job) Give

func (j *Job) Give(form, typ, what string, fill func(w io.Writer) error) (any, error)

Give hands a script what a plugin produces, in the form the script asked for. fill writes it. As a blob it goes into a file in the job's scratch directory as it is written, whatever its size, and is sent to the store only if it leaves the job. In any other form it is held whole, and one too large to hold fails with the advice to ask for a blob.

func (*Job) Headers

func (j *Job) Headers(given map[string]any, address string, encrypted bool, own ...string) (http.Header, error)

Headers gives the headers a script wrote for a web request that goes over a connection to an address, host:port. Each is sent as written, name and value, with a secret or without, and a value that holds secrets is revealed for the connection, as RevealOver does it. A header that is not sent as written is refused before any value is taken: the framing ones, and those the plugin says are its own to write. So is a value that holds a line break or a zero byte, which would start a header of its own.

func (*Job) Key

func (j *Job) Key(value any) ([]byte, error)

Key gives a secret's value to be used as a key, to sign or to make a keyed hash. What comes out is ordinary data, so only a secret bound to anywhere may be used this way.

func (*Job) Mask

func (j *Job) Mask(text string) string

Mask takes every secret's value out of a text that is going back to the script, or out of the job: the value as it is and in the usual encodings, each replaced with the secret's name. It catches accidents, such as a server that echoes a header.

func (*Job) MayRead

func (j *Job) MayRead(real string) bool

MayRead says whether the job may read what is at a path, given as it really is, without noting it as used: a listing leaves out what the job may not read.

func (*Job) Note

func (j *Job) Note(form, names string)

Note has a text searched for like the other forms a secret's value leaves in: a text an encoding wrote with the secrets named in it. A form that was not known is passed on to Noted.

func (*Job) OnEnd

func (j *Job) OnEnd(do func())

OnEnd has something done when the job ends, however it ends.

func (*Job) Path

func (j *Job) Path(path string, write bool) (string, error)

Path gives a file's real location, to read or to write. The path is checked where it really points, after links are followed.

func (*Job) Program

func (j *Job) Program(ctx context.Context, name string, opt ProgramOptions) (*exec.Cmd, error)

Program starts a program. The program the script named is checked before it is looked for, and it is what is noted as used; the exec wrapper, if there is one, goes in front.

func (*Job) Reading

func (j *Job) Reading(v any) (io.Reader, int64, string, error)

Reading gives something a script hands a plugin as contents to be read from start to end, with its size and its type. A blob is read a part at a time, however large it is, and never held whole.

func (*Job) Reveal

func (j *Job) Reveal(value any, destination string) (string, error)

Reveal gives the real text of a value that may hold secrets, for the program or the file it is going into: "exec:program" or "fs.write:/path". A plugin calls it only together with the way out the value is going into. Every secret in the value must be bound to that destination, and if one is not, nothing is given.

func (*Job) RevealOver

func (j *Job) RevealOver(value any, address string, encrypted bool) (string, error)

RevealOver gives the real text of a value that may hold secrets, for the connection it is going into, to an address written host:port. encrypted is the plugin's word that the connection is encrypted at this moment, and that nothing it wraps can fall back to a plain one. Without the word, a secret goes only when its entry lets it go to the host over a connection that is not encrypted, or anywhere.

func (*Job) Sent

func (j *Job) Sent(name string) bool

Sent says whether the job was sent a secret of a name.

func (*Job) Source

func (j *Job) Source(v any) (io.ReaderAt, int64, error)

Source gives contents to be read at any place in them, with their size: a blob where it lies, anything else from memory.

func (*Job) Telling

func (j *Job) Telling(name string) *Told

Telling gives a way to emit a text under a name as it arrives, a piece at a time. The pieces are searched for secrets across their joins: the end of what has arrived is held back until enough has followed to know it is not the start of a value.

func (*Job) Variable

func (j *Job) Variable(name string) (string, bool, error)

Variable gives the value of one of the runner's variables.

func (*Job) Whole

func (j *Job) Whole(group string) error

Whole checks that the job is allowed the whole of a group: "network", "disk" or "all". It is for something a plugin starts that does its own reaching, which Corbie cannot hold to a scope: it may be had only where everything it could use is allowed, and its use is noted.

type Module

type Module struct {
	Name string
	// Page is the module's page of the manual, which is its specification:
	// each call, its options and the permissions it needs, with examples.
	Page string
	// Calls are what a plugin gives a script, by name.
	Calls map[string]*Call
	// Library is the source of a library written in script: the body of a
	// function that fills in exports.
	Library string
}

A Module is a plugin, or a library written in script. A script gets it with require and its name.

func Find

func Find(name string) (*Module, bool)

Find gives the module of a name.

type Object

type Object struct {
	Calls map[string]*Call
	Close func() error
}

An Object is something that stays open, such as a connection: its own calls, and a close.

type Options

type Options map[string]any

Options are the named options of a call. Each getter gives the default where the option was not given, and an error where it is the wrong kind of thing.

func (Options) Bool

func (o Options) Bool(name string, otherwise bool) (bool, error)

func (Options) Duration

func (o Options) Duration(name string, otherwise time.Duration) (time.Duration, error)

Duration reads a length of time: a number of seconds, or text such as "30s" or "5m".

func (Options) Has

func (o Options) Has(name string) bool

func (Options) Int

func (o Options) Int(name string, otherwise int) (int, error)

func (Options) List

func (o Options) List(name string) ([]any, error)

func (Options) Map

func (o Options) Map(name string) (map[string]any, error)

func (Options) Text

func (o Options) Text(name, otherwise string) (string, error)

func (Options) Texts

func (o Options) Texts(name string) ([]string, error)

Texts reads a list of texts.

type ProgramOptions

type ProgramOptions struct {
	Args  []string
	Env   []string // name=value
	Dir   string
	Stdin io.Reader
	// Secrets are the secrets that go to the program, in its arguments, its
	// variables or its input.
	Secrets []*Secret
}

ProgramOptions are what a started program is given.

type Secret

type Secret struct {
	// contains filtered or unexported fields
}

A Secret is a handle to a secret: it stands for the value and can be put wherever a value goes out. It cannot be turned into text, compared, measured or read a piece at a time. Text and handles are joined into a new handle, which is how a secret is put inside other text. A handle holds names and never a value, so however it is printed it shows only names.

func Join

func Join(pieces ...any) (*Secret, error)

Join makes one handle of texts and handles. Each piece keeps the way it is written: a handle told to be encoded is encoded by itself, and the text around it is left as it was written.

func NewSecret

func NewSecret(name string) *Secret

NewSecret makes the handle to the secret of a name.

func (*Secret) Encoded

func (s *Secret) Encoded(how string) (*Secret, error)

Encoded gives the handle with its whole text written another way: "base64", "url", as for a part of an address, or "json", as for the inside of a text in JSON. A value is escaped at most twice.

func (*Secret) GoString

func (s *Secret) GoString() string

GoString shows the handle as String does.

func (*Secret) MarshalJSON

func (s *Secret) MarshalJSON() ([]byte, error)

MarshalJSON refuses: nothing stands in for a secret where data is written out.

func (*Secret) Names

func (s *Secret) Names() []string

Names lists the secrets the handle holds.

func (*Secret) Shape

func (s *Secret) Shape() string

Shape gives the handle's text with nothing where its secrets are, for a plugin to learn where a value is going before it asks for the value.

func (*Secret) String

func (s *Secret) String() string

String shows the handle by the names of its secrets.

type Told

type Told struct {
	// contains filtered or unexported fields
}

Told is a text being emitted as it arrives.

func (*Told) Add

func (t *Told) Add(piece string)

Add takes the next piece, and emits what can no longer be part of a value: all but the end, as long as the longest form less one.

func (*Told) End

func (t *Told) End()

End emits what was held back: nothing more is coming.

type Whole

type Whole struct {
	Over bool
	// contains filtered or unexported fields
}

Whole keeps what is written to it, up to the most that is held whole. Past that it takes no more, and says so.

func (*Whole) Text

func (h *Whole) Text() string

Text is what was kept.

func (*Whole) Write

func (h *Whole) Write(p []byte) (int, error)

Directories

Path Synopsis
Package blobs is the plugin that makes and reads blobs.
Package blobs is the plugin that makes and reads blobs.
Package bundled is every plugin that comes with Corbie.
Package bundled is every plugin that comes with Corbie.
Package compress is the plugin for packing and unpacking: gzip, and archives of files.
Package compress is the plugin for packing and unpacking: gzip, and archives of files.
Package crypto is the plugin for hashes, keyed hashes, random bytes, signing and checking, encryption, and writing bytes as text.
Package crypto is the plugin for hashes, keyed hashes, random bytes, signing and checking, encryption, and writing bytes as text.
Package env is the plugin that gives a script the runner's variables.
Package env is the plugin that gives a script the runner's variables.
Package exec is the plugin for starting a program and getting what it printed.
Package exec is the plugin for starting a program and getting what it printed.
Package fs is the plugin for files and directories.
Package fs is the plugin for files and directories.
Package html is the plugin for reading a page as a tree.
Package html is the plugin for reading a page as a tree.
Package http is the plugin for web requests.
Package http is the plugin for web requests.
llm
Package llm is the plugin that calls a model.
Package llm is the plugin that calls a model.
claudecode
Package claudecode is the model service that is a program: it starts Claude Code on the runner's machine and has it write one reply.
Package claudecode is the model service that is a program: it starts Claude Code on the runner's machine and has it write one reply.
standin
Package standin is a model service for tests: it speaks Anthropic's Messages API, streams each reply as server-sent events, and keeps every call it is sent.
Package standin is a model service for tests: it speaks Anthropic's Messages API, streams each reply as server-sent events, and keeps every call it is sent.
Package machines is the plugin that defines a machine while a job runs.
Package machines is the plugin that defines a machine while a job runs.
mcp
Package mcp is the plugin for an MCP server: its tools, and calls to them, over the web or from a program it starts.
Package mcp is the plugin for an MCP server: its tools, and calls to them, over the web or from a program it starts.
standin
Package standin is an MCP server for tests: a server of notes, which speaks MCP 2026-07-28 or only an earlier version, over a program's standard streams or over the web.
Package standin is an MCP server for tests: a server of notes, which speaks MCP 2026-07-28 or only an earlier version, over a program's standard streams or over the web.
Package net is the plugin for a raw connection, plain or encrypted.
Package net is the plugin for a raw connection, plain or encrypted.
Package secrets is the plugin that gives a script handles to secrets.
Package secrets is the plugin that gives a script handles to secrets.
Package ssh is the plugin for running a command on another machine.
Package ssh is the plugin for running a command on another machine.
Package websocket is the plugin for a connection that carries messages both ways, kept alive while the script works.
Package websocket is the plugin for a connection that carries messages both ways, kept alive while the script works.
Package xml is the plugin for reading a document as a tree, and writing a tree as a document.
Package xml is the plugin for reading a document as a tree, and writing a tree as a document.
Package yaml is the plugin for reading a YAML document as data, and writing data as YAML.
Package yaml is the plugin for reading a YAML document as data, and writing data as YAML.

Jump to

Keyboard shortcuts

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