host

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 13 Imported by: ? 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 host opens an installed package as a running plugin and calls it by dotted method name. It composes the store (verified content), the C engine's process runtime (launch, stderr capture, drain) and its session (handshake, admission); it chooses no install location and grants no authority beyond the descriptor the caller reviewed.

Index

Constants

View Source
const DefaultTimeout = 10 * time.Minute

DefaultTimeout bounds handshake and calls without an earlier caller deadline.

View Source
const DrainTimeout = 5 * time.Second

DrainTimeout is how long Close waits for admitted calls before aborting.

Variables

ErrExists is returned by a Registry for a contract that is already registered, or a reverse operation that is already routed.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Verify runs after package verification and before process launch. Use it
	// to recheck caller-owned trust or a separately installed runtime package.
	Verify func(context.Context) error
	// Launch overrides how the package starts, for example to run source files
	// under a runtime the consumer manages (Path is that runtime, Args begin
	// with the script). When nil, the package's first entrypoint artifact is
	// started with no arguments. Dir defaults to the package directory, not the
	// caller's working directory: a plugin that runs commands for the user needs
	// Dir set explicitly. This is the same type contract/host takes; the engine
	// does not use KillGrace.
	Launch *process.Command
	// Authorize runs before every call. When nil, any operation the reviewed
	// descriptor declares is allowed.
	Authorize func(context.Context, plugin.Request) error
	// Timeout bounds the handshake and calls without an earlier caller
	// deadline. Zero uses DefaultTimeout.
	Timeout time.Duration
	// Env adds KEY=value entries to the child's environment, which is otherwise
	// scrubbed (PATH only, plus SystemRoot on Windows). It applies to the default
	// launch and is added to Launch.Env when Launch is set. A name may appear only
	// once across both.
	Env []string
	// Reverse offers services to the plugin: calls from the plugin to this
	// host, limited to the operations its descriptor declares in Reverse. When
	// nil, every reverse call is denied.
	Reverse *ReverseOptions
	// Registry serves the plugin's reverse calls along the edges declared on it,
	// with forward calls to the processes registered there (see Registry).
	// Reverse must be set too: its Authorize runs first and its bounds apply, and
	// its Handle must be nil, since the registry is the handler.
	Registry *Registry
}

Options supplies the admission policy and launch choice.

type Process

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

Process is one plugin process behind a C engine session.

func Open

func Open(ctx context.Context, installed store.Installed, options Options) (*Process, error)

Open re-verifies the installed package, starts it and completes the handshake. Verification binds the launch to the installed content; it is not publisher trust, which stays with the consumer.

ctx bounds the start and the handshake only. It does not bound the process: cancelling it after Open returns does not stop the plugin or its calls. Close ends the process, and each Call takes its own context.

func OpenRuntime

func OpenRuntime(ctx context.Context, installed store.Installed, runtime RuntimeOptions) (*Process, error)

OpenRuntime re-verifies both installed packages and the reviewed runtime digest immediately before starting a source guest. The caller still owns plugin-package trust, runtime trust, and operation authorization.

func (*Process) Call

func (p *Process) Call(ctx context.Context, method string, params any, result any) error

Call invokes "<contract>.<operation>" (see plugin.Descriptor.ResolveMethod). params is JSON-encoded, with nil meaning JSON null. A non-nil result receives the decoded payload; a null payload leaves it untouched.

func (*Process) CallProgress

func (p *Process) CallProgress(ctx context.Context, method string, params any, result any, onProgress func(plugin.Progress), options ...plugin.CallOptions) error

CallProgress is Call for an operation that declares progress: onProgress receives its progress and log events while the call runs. It must not block. Events beyond the rate limit are dropped and counted in the next event's Dropped field. The result is unchanged.

func (*Process) Close

func (p *Process) Close() error

Close drains admitted calls for DrainTimeout, then aborts the child.

func (*Process) Descriptor

func (p *Process) Descriptor() plugin.Descriptor

Descriptor is a copy of the session's reviewed descriptor.

func (*Process) Done

func (p *Process) Done() <-chan struct{}

Done is closed once the plugin session has ended, whether by Close, an abort or a failed call. Anything whose lifetime is tied to the plugin, such as an endpoint grant (endpoint.Admit takes it), ends with it.

func (*Process) Stderr

func (p *Process) Stderr() string

Stderr returns bounded, untrusted diagnostic output from the child.

type Registry

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

Registry composes plugins through their host: a reverse call one plugin makes is served by a forward call to another plugin, along an edge the host declared with Route. It is the C engine's ext_plugin_registry (ext_plugin_host.h) through cengine/plugin.Registry. Its refusal codes and cycle rules are checked by lib/plugin/testdata/v1/registry-cases.json.

A process is a source when it is opened with Options.Registry, and a target once Register names the contract it serves. The contract is unregistered when the target's session ends. A Registry is safe for concurrent use.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty registry.

func (*Registry) Register

func (r *Registry) Register(contract plugin.ContractRef, p *Process) error

Register names p as the process that serves contract. p's descriptor must list the contract (ErrUnsupported otherwise); ErrExists when the contract is already registered. The contract is unregistered when p's session ends.

func (*Registry) Route

func (r *Registry) Route(from plugin.ContractRef, fromOperation string, to plugin.ContractRef, toOperation string) error

Route declares one edge: a reverse call of fromOperation in from is served by a call of toOperation in to. ErrExists when that reverse operation is already routed.

func (*Registry) Unregister

func (r *Registry) Unregister(contract plugin.ContractRef) error

Unregister removes contract and waits for the forward calls routed to its process to return. ErrNotFound when it is not registered.

type ReverseOptions

type ReverseOptions = plugin.ReverseOptions

ReverseOptions configures the services a host offers to its plugin; it is plugin.ReverseOptions, so a host need not import the root package for it.

type RuntimeOptions

type RuntimeOptions struct {
	Runtime         store.Installed
	ReviewedDigest  string
	RuntimeArtifact string
	Executable      string
	ScriptArtifact  string
	Arguments       []string
	Options         Options
}

RuntimeOptions binds a source plugin to a separately installed, reviewed runtime package. The runtime executable can be a file artifact or a file inside a verified tree artifact. ScriptArtifact belongs to the plugin package, so neither path is selected from ambient PATH.

Jump to

Keyboard shortcuts

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