plugin

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 25 Imported by: 0 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 runs installed, sandboxed plugins as ordinary model tools. A plugin is an artifact (plugin.js on the shared embedded QuickJS, or plugin.wasm) plus a sidecar plugin.json manifest that declares the tools it exposes, which base tools its guest may call (its cage), and the credentials the host injects for it. The manifest is read and reviewed WITHOUT running the artifact.

A plugin's cage is a TOOLSET, not a bespoke boundary: `uses` names the base tools its guest may dispatch to, exactly as an agent's tool filter scopes a sub-agent. Everything past that is the ordinary gate — a host is approved by the human (HITL) per request, not by a static per-plugin target list. So a plugin never holds more authority than a subset of the base tools, each still gated the same way the model's own calls are.

Index

Constants

View Source
const (
	ManifestFile = "plugin.json"
	ScriptFile   = "plugin.js"
	// SkillFile is the optional instructions a plugin bundles: when to reach for its tools, and what
	// its arguments really take. Optional because a plugin whose tools are self-explanatory needs
	// none, and a skill nobody needed would cost prompt space in every turn.
	SkillFile = "SKILL.md"
)

File names inside a plugin's folder. Exported because installing one means writing exactly these.

View Source
const (
	ReachHost = "host "
	ReachUses = "uses "
)

The two kinds of line in a definition's reach: a host the plugin's code reaches, a base tool it uses.

Variables

This section is empty.

Functions

func Owner

func Owner(name string) string

Owner is the credential-injection owner id for the extension a plugin belongs to: "ext:<name>", its folder. A folder holding this plugin AND a skill explaining it is ONE extension with one owner.

func Points added in v0.5.0

func Points() []string

Points lists the extension points' names.

func Remove added in v0.3.0

func Remove(dir, folder string) error

Remove deletes a plugin's folder — its manifest, its artifact, and the secret shard beside them. Dropping the credential material with the code is the point: an uninstall that left a token behind would leave the next plugin of that name inheriting it.

func SecretNames added in v0.4.0

func SecretNames(m Manifest) (map[string]string, error)

SecretNames are the vault keys a plugin's credentials live under, by credential name. The key carries the host the credential was declared for (extension.SecretName), so a manifest re-pointed at another host cannot reuse the token issued for the old one.

func SkillBodies added in v0.3.0

func SkillBodies(root string) map[string]string

SkillBodies returns the SKILL.md of every plugin under root, keyed by folder.

A file scan, deliberately separate from Discover: the workspace needs these BEFORE it builds the tool set (the skill catalog is assembled first, and a plugin's guest is compiled with the base tools that come out of it), and reading two files is cheaper than reordering that assembly around a dependency that does not really exist.

Types

type Context added in v0.5.0

type Context struct {
	Settings map[string]any `json:"settings"`
	Profile  map[string]any `json:"profile"`
}

Context is what a plugin's code is handed beside its arguments on every call: its settings, typed, with their defaults, and the profile fields it may read. A JS tool receives it as its second argument, a wasm guest as "context" in its request.

type CredentialDecl

type CredentialDecl = extension.CredentialDecl

CredentialDecl declares a credential the host injects for the plugin (never seen by the plugin). It is the shared declaration — the same type a skill or an MCP server declares — so what a plugin asks for and what the injector registers cannot drift into two shapes.

type Kind

type Kind int

Kind is a plugin artifact form.

const (
	KindJS   Kind = iota // plugin.js, run on the shared embedded QuickJS interpreter
	KindWASM             // plugin.wasm, a wasm32-wasi guest run directly
)

type Loaded

type Loaded struct {
	Manifest Manifest
	Artifact []byte
	Kind     Kind
	Skill    string // the bundled SKILL.md, verbatim; empty when there is none
}

Loaded is a validated plugin package: manifest + artifact + kind, and the skill it bundles if it brought one.

A plugin answers two different questions and they belong in two different files. The manifest says what it MAY do and the artifact says HOW; neither says WHEN the assistant should reach for it, or which query syntax its search takes, or that reading a body costs context nobody asked to spend. That is skill material — instructions, no authority — so a plugin may ship a SKILL.md beside its code, and the workspace folds it into the same skill catalog a hand-written one lands in.

func Load

func Load(dir string) (Loaded, error)

Load reads dir/plugin.json (validated) and the artifact (plugin.wasm XOR plugin.js) WITHOUT executing anything.

type Manifest

type Manifest struct {
	Name    string      `json:"name"`
	Version string      `json:"version"`
	Tools   []ToolDecl  `json:"tools"`
	Uses    []string    `json:"uses"`  // base tool names the guest may call ("*" = all); its cage
	OAuth   []OAuthDecl `json:"oauth"` // OAuth2 providers the host runs on its behalf

	// The extension points beside the tools (ADR-37, extend.go): the exact hosts its code reaches, the
	// widget templates it offers, the settings a person fills in (a form schema; values in the
	// extension's config.json), and the fields of the household profile its code reads.
	Hosts    []string          `json:"hosts,omitempty"`
	Widgets  []widget.Template `json:"widgets,omitempty"`
	Settings json.RawMessage   `json:"settings,omitempty"`
	Profile  []string          `json:"profile,omitempty"`

	extension.Decl
}

Manifest is a plugin's static declaration (sidecar plugin.json).

The embedded extension.Decl is the half every installed thing has — the config a human supplies and the credentials the host injects. Only what is above it is a plugin's own: the tools it exposes, the cage it may call into, and the OAuth flows the host runs for it. Embedding rather than repeating is what makes "this needs a token before it works" one fact across skills, plugins and MCP servers instead of a field somebody added to one manifest.

func ParseManifest added in v0.5.0

func ParseManifest(data []byte, fallbackName string) (Manifest, error)

ParseManifest reads and validates a plugin.json, every extension point included (widget templates, settings, profile fields), without anything else of the plugin. fallbackName is the plugin's name when the manifest gives none (its folder). Load and the catalog's build both run it, so a manifest that would not load never ships.

func Write added in v0.3.0

func Write(dir, folder, manifest, script, bundledSkill string) (Manifest, error)

Write installs a JS plugin: <dir>/<folder>/{plugin.json,plugin.js}, where dir is a workspace's extensions/ folder.

Both files land or neither does, and the manifest is validated first — through Load, the same reader Discover uses, so a plugin that would be skipped at startup is refused here instead. A plugin that silently never appears is the one failure a person cannot act on, and it is worse for a plugin than for anything else: its tools simply are not there, and the model then says it cannot do the thing rather than that it was not installed.

It refuses to overwrite. A plugin's folder is also where its secret shard lives, so replacing the code under an existing name would point a credential that was authorized for one program at another one — the same argument mcp.Write makes about a server's URL.

WASM plugins are not installable this way on purpose: the catalog carries text, and a base64 artifact in a JSON document is a different review surface (and a different size class) than a readable plugin.js. Sideloading a folder is still how one arrives.

func (Manifest) DeclaredConfig added in v0.5.0

func (m Manifest) DeclaredConfig() ([]extension.ConfigDecl, error)

DeclaredConfig is the config entries the manifest's points declare beside its own config: what a person supplies for the plugin, in one store.

func (Manifest) DeclaredHosts added in v0.5.0

func (m Manifest) DeclaredHosts() []string

DeclaredHosts is the hosts the plugin declares its code reaches, sorted; nil when it declares none (its code may then reach every host its uses allow).

func (Manifest) Definitions added in v0.5.0

func (m Manifest) Definitions() ([]widget.Definition, error)

Definitions are the definitions of the plugin's templates, in order: what the owner accepts once, at install, for every widget made from them.

func (Manifest) Preview added in v0.5.0

func (m Manifest) Preview(t widget.Template, now time.Time, loc *time.Location) (*widget.Preview, error)

Preview is template t's widget drawn from its demo answer, through the registries the manifest's templates are validated against; nil when it brings none.

func (Manifest) ProfileFields added in v0.5.0

func (m Manifest) ProfileFields() []profile.Field

ProfileFields is the profile fields the plugin declares it reads.

func (Manifest) SettingsConfig added in v0.5.0

func (m Manifest) SettingsConfig() ([]extension.ConfigDecl, error)

SettingsConfig is the settings as config entries of the extension's declaration: one store, one validation, one `nocturn config`. A setting is typed, as every config value is — a free-text string would be the prompt-injection channel config refuses — and its name may not be a config's too.

func (Manifest) SettingsSchema added in v0.5.0

func (m Manifest) SettingsSchema() (*form.Schema, error)

SettingsSchema is the plugin's settings form, nil when it declares none.

func (Manifest) Validate

func (m Manifest) Validate() error

Validate rejects a malformed manifest fail-closed: a bad name, no tools, duplicate/odd tool names, a non-object schema, or a credential entry with an empty field.

type OAuthDecl

type OAuthDecl struct {
	Name         string   `json:"name"` // links to a CredentialDecl.Name (the injected secret)
	AuthURL      string   `json:"auth_url"`
	TokenURL     string   `json:"token_url"`
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret"`
	Scopes       []string `json:"scopes"`
}

OAuthDecl declares an OAuth2 provider the plugin needs — so the plugin brings its own instead of the host hard-coding every one. The host runs the authorization-code (+PKCE) flow via `nocturn auth <name>`, holds and refreshes the token, and injects it as the credential named Name (which must match a CredentialDecl). The guest never sees the token. ClientSecret may be "" for a public/PKCE client; a desktop-app client's secret is non-confidential and shipped in the manifest.

type OAuthProvider

type OAuthProvider struct {
	Name         string // provider id for `nocturn auth <name>` (links to a CredentialDecl.Name)
	SecretName   string // the owner+host-bound vault key the workspace binds this credential to
	AuthURL      string
	TokenURL     string
	ClientID     string
	ClientSecret string
	Scopes       []string
}

OAuthProvider is one plugin OAuth declaration flattened with the vault key its token lives under — the owner-namespaced SecretName, the SAME key installPlugins binds the credential's secret to, so an authorized token flows straight into that credential's injection. It is the neutral hand-off to the daemon's OAuth wiring, so plugin-manifest knowledge stays in this package.

func DiscoverOAuth

func DiscoverOAuth(wsDir string) []OAuthProvider

DiscoverOAuth scans one workspace's <wsDir>/plugins for declared OAuth providers. A plugin that fails to load is skipped (its own load path reports it on the real startup path); this is only about collecting providers, never running them. The caller (per-workspace secret assembly) owns scoping to a single workspace, so credentials never leak across workspace vaults.

type Plugin

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

Plugin is a loaded, sandboxed plugin. Its tools are exposed to the model as <name>_<tool>. Execution is STATELESS — a fresh sandbox instance per tool-call; cross-call state is host-mediated via the workspace filesystem (WorkDir, mounted at /work).

Its cage is a TOOLSET: `dispatch` is the base tools its guest may call, already narrowed to the manifest's `uses` — exactly how an agent's filter scopes a sub-agent. There is no bespoke per-plugin policy; a dispatched action runs under the SAME gate the model's own calls do (ctx carries the workspace policy + grants + approver), so a host is still approved by the human per request.

func New

func New(l Loaded, base agentkit.ToolSet) *Plugin

New builds a Plugin from a Loaded package. base is the workspace's base tools; the plugin's guest may call only the subset its manifest lists in `uses` — that narrowed set is its cage.

func (*Plugin) Close

func (p *Plugin) Close(ctx context.Context) error

Close releases a KindWASM plugin's own engine if it was built (no-op for KindJS / an uncalled KindWASM plugin).

func (*Plugin) Decl added in v0.4.0

func (p *Plugin) Decl() extension.Decl

Decl returns the plugin's shared declaration — its config and its credentials — so the workspace registers a plugin's bindings through the same path a skill's or an MCP server's take.

func (*Plugin) Manifest added in v0.5.0

func (p *Plugin) Manifest() Manifest

Manifest is the plugin's declaration.

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns the plugin name.

func (*Plugin) Proposals added in v0.5.0

func (p *Plugin) Proposals() map[string]extension.Target

Proposals are the target mappings read off the input schemas of the plugin's tools that declare none (extension.Propose), by tool name. They are never applied: they are for the owner to see and accept.

func (*Plugin) ReadOnly added in v0.5.0

func (p *Plugin) ReadOnly(tool string) bool

ReadOnly reports whether the manifest declares one of the plugin's tools, by its own name, as one that only reads (readOnly in plugin.json).

func (*Plugin) SetContext added in v0.5.0

func (p *Plugin) SetContext(fn func() Context)

SetContext gives the plugin what it hands its code on every call; nil hands an empty context. The workspace sets it when it builds the plugin, reading the profile grants at call time.

func (*Plugin) Target added in v0.5.0

func (p *Plugin) Target(tool string) extension.Target

Target is the target mapping the manifest declares for one of the plugin's tools, by its own name (not the exposed <plugin>_<tool>); the zero Target when it declares none.

func (*Plugin) Tools

func (p *Plugin) Tools() ([]agentkit.Tool, error)

Tools returns the plugin's model-facing tools, namespaced <plugin>_<tool>. Each tool's Call runs the plugin artifact for that tool.

func (*Plugin) Uses added in v0.5.0

func (p *Plugin) Uses() []string

Uses lists the base tools the plugin's guest may call — its cage — sorted.

type Point added in v0.5.0

type Point interface {
	Name() string
	Validate(m Manifest) error
}

Point is one extension point of plugin.json: the key it is declared under, and its validation of a manifest that declares it.

type Set

type Set map[string]*Plugin

Set is a collection of installed plugins, keyed by name (mirrors agentkit's ToolSet / SkillSet and agent.Set / mcp.Set). Build one with Discover; read it with Get and All.

func Discover

func Discover(root string, base agentkit.ToolSet, diag *agentkit.Diagnostics) Set

Discover builds every plugin under root — each subdirectory holding a plugin.json — into a Set, each caged to a subset of the base tools per its manifest. A missing root yields an empty Set. A malformed plugin is SKIPPED with a diagnostic rather than aborting the scan — a broken plugin's tools + credentials are then simply absent (fail-closed), and the other plugins still load. A duplicate name keeps the first (shadowing). The caller registers each plugin's tools and credential bindings.

func (Set) All

func (s Set) All() []*Plugin

All returns the plugins sorted by name.

func (Set) Get

func (s Set) Get(name string) (*Plugin, bool)

Get returns the named plugin.

type ToolDecl

type ToolDecl struct {
	Name        string           `json:"name"`
	Description string           `json:"description"`
	Parameters  json.RawMessage  `json:"parameters"` // JSON-schema object
	Target      extension.Target `json:"target,omitzero"`
	ReadOnly    bool             `json:"readOnly,omitempty"`
}

ToolDecl declares a tool the plugin exposes to the model.

Target says which arguments name what the tool acts on (extension.Target). With one, the tool's node in the permission tree has a target type and its patterns beneath it, and every call's targets are read host-side and decided before the guest runs. Without one the tool is decided whole.

ReadOnly declares that a call only reads: it changes nothing anywhere, so a widget may repeat it on its own (a template's source must be one). It is the publisher's claim, reviewed with the manifest; absent is false, so a tool nobody declared is never a source.

Jump to

Keyboard shortcuts

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