plugin

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 19 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.

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 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 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

	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 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) 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) Name

func (p *Plugin) Name() string

Name returns the plugin name.

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.

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
}

ToolDecl declares a tool the plugin exposes to the model.

Jump to

Keyboard shortcuts

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