plugin

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 18 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

This section is empty.

Variables

This section is empty.

Functions

func Owner

func Owner(name string) string

Owner is the credential-injection owner id for a plugin: "plugin:<name>". The typed prefix keeps plugins (and later other injecting owners, e.g. an MCP connection) in one owner namespace without colliding — a plugin "github" and an MCP server "github" get distinct owners.

func SecretName

func SecretName(pluginName, credName string) string

SecretName is the vault key (and binding secret name) for a plugin credential, owner-namespaced so two plugins declaring the same credential name never share a stored value or overwrite each other's OAuth resolver: "plugin:<plugin>/<cred>". This mirrors mcp.SecretName; the owner prefix is the same boundary Owner enforces for injection, now reflected in the value's identity too.

Types

type CredentialDecl

type CredentialDecl struct {
	Name   string `json:"name"`
	Host   string `json:"host"`
	Header string `json:"header"`
	Prefix string `json:"prefix"`
}

CredentialDecl declares a credential the host injects for the plugin (never seen by the plugin), mirroring secret.Binding. Host is the sole scoping dimension — a request credential is inherently a network credential, so the host IS the discriminator; a bearer is injected on any request to it.

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
}

Loaded is a validated plugin package: manifest + artifact + kind.

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
	Credentials []CredentialDecl `json:"credentials"` // host-injected credentials it uses
	OAuth       []OAuthDecl      `json:"oauth"`       // OAuth2 providers the host runs on its behalf
}

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

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 // SecretName(plugin, cred) — the owner-namespaced vault key installPlugins binds 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) Credentials

func (p *Plugin) Credentials() []CredentialDecl

Credentials returns the plugin's declared credential bindings, so the caller can register them on the shared injector under this plugin's owner.

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