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
- func Owner(name string) string
- func Remove(dir, folder string) error
- func SecretName(pluginName, credName string) string
- func SkillBodies(root string) map[string]string
- type CredentialDecl
- type Kind
- type Loaded
- type Manifest
- type OAuthDecl
- type OAuthProvider
- type Plugin
- type Set
- type ToolDecl
Constants ¶
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 ¶
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 Remove ¶ added in v0.3.0
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 SecretName ¶
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.
func SkillBodies ¶ added in v0.3.0
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 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 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.
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 Write ¶ added in v0.3.0
Write installs a JS plugin: <dir>/<folder>/{plugin.json,plugin.js}, where dir is a workspace's plugins/ 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.
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 ¶
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 ¶
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.
type Set ¶
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 ¶
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.