Documentation
¶
Index ¶
- Constants
- Variables
- func ResolveCommand(root, command string, args []string) (string, []string, error)
- func ResolvePath(root, rel string) (string, error)
- func ToolNamespaces(id string, servers []MCPServer) []string
- func ToolPrefix(id string) string
- func ValidPermissions() []string
- func ValidateID(id string) error
- type Caller
- type CharterRow
- type Entry
- type Host
- func (h *Host) AssetFS(id string) (fs.FS, bool)
- func (h *Host) CallTool(ctx context.Context, pluginID, toolName string, args any) (json.RawMessage, error)
- func (h *Host) Close() error
- func (h *Host) Entries() ([]Entry, error)
- func (h *Host) HookSources() []hooks.ExtraSource
- func (h *Host) Install(ctx context.Context, source string) (Summary, error)
- func (h *Host) KV(id string) (*KV, error)
- func (h *Host) List() ([]Summary, error)
- func (h *Host) OnStopped(fn func(id string, reason StopReason)) func()
- func (h *Host) Revision() uint64
- func (h *Host) Rollback(ctx context.Context, id string) (Summary, error)
- func (h *Host) SetEnabled(ctx context.Context, id string, enabled bool) error
- func (h *Host) SetPluginHooks(env func(Entry, uint64, map[string]string) error, stopped func(string))
- func (h *Host) SkillRoots() []string
- func (h *Host) Start(ctx context.Context) error
- func (h *Host) Store() *Store
- func (h *Host) Subscribe(fn func()) func()
- func (h *Host) ToolSet() *ToolSet
- func (h *Host) Tools() tool.Source
- func (h *Host) Uninstall(ctx context.Context, id string, opts UninstallOptions) error
- func (h *Host) UpdateFrom(ctx context.Context, id string, installer Installer) (Summary, error)
- type HostOptions
- type Installer
- type KV
- type MCPServer
- type Manifest
- type NewSourceFunc
- type NodeDecl
- type Options
- type Readiness
- type Root
- type Source
- type StopReason
- type Store
- func (s *Store) Asset(id, rel string) ([]byte, error)
- func (s *Store) CheckUninstall(id string) error
- func (s *Store) DataDir(id string) (string, error)
- func (s *Store) Enabled() ([]Entry, error)
- func (s *Store) Entries() ([]Entry, error)
- func (s *Store) Entry(id string) (Entry, bool)
- func (s *Store) Inspect(_ context.Context, source string) (Summary, error)
- func (s *Store) Install(ctx context.Context, source string) (Summary, error)
- func (s *Store) InstallZip(ctx context.Context, zipPath string) (Summary, error)
- func (s *Store) KV(id string) (*KV, error)
- func (s *Store) List() ([]Summary, error)
- func (s *Store) Options() Options
- func (s *Store) Revision() uint64
- func (s *Store) Rollback(ctx context.Context, id string) (Summary, error)
- func (s *Store) SetEnabled(id string, enabled bool) error
- func (s *Store) Subscribe(fn func()) func()
- func (s *Store) Uninstall(_ context.Context, id string, opts UninstallOptions) error
- func (s *Store) UpdateFrom(ctx context.Context, id string, installer Installer) (Summary, error)
- type Summary
- type ToolSet
- func (t *ToolSet) AddPlugin(id string, source Source) error
- func (t *ToolSet) Attach(registrar tool.Registrar)
- func (t *ToolSet) Attached() int
- func (t *ToolSet) Close() error
- func (t *ToolSet) Detach(registrar tool.Registrar)
- func (t *ToolSet) LazyTools() []tool.LazyTool
- func (t *ToolSet) RemovePlugin(ctx context.Context, id string) error
- func (t *ToolSet) Tools() []tool.Tool
- type UIManifest
- type UninstallOptions
- type UpdateApproval
- type UpdateApprover
- type UpdateDecl
- type UpdateInfo
Constants ¶
const ( MaxZipEntryBytes = 64 << 20 MaxZipBytes = 256 << 20 )
Zip limits, the archive counterpart of MaxAssetBytes: one entry may unpack to 64 MiB, a whole package to 256 MiB. They bound the temporary tree an install writes before the manifest is read, so an archive that is not what it claims cannot fill the disk first. The declared sizes are the gate — archive/zip refuses to read a stream that runs past its declared size, so a header that lies fails the unpack instead of beating the cap.
const DefaultDrainTimeout = 30 * time.Second
DefaultDrainTimeout bounds how long a stop waits for one plugin's in-flight calls before its source is closed anyway. It is HostOptions.DrainTimeout's zero value, and the bound every wait in this package takes when nothing else is configured: an unbounded one would let a single hung call keep a plugin — or the whole host — from ever stopping.
const DefaultEnableTimeout = 10 * time.Second
DefaultEnableTimeout bounds the readiness wait of an enable: how long Host.SetEnabled waits for a plugin's MCP servers before it stops waiting and records the plugin as enabled with the source still reconnecting in the background.
const MaxAssetBytes = 10 << 20
MaxAssetBytes caps one materialized plugin asset (10 MiB).
const (
MaxManifestBytes = 1 << 20
)
Manifest limits (shared with the design doc).
Variables ¶
var ( // ErrAssetEscape reports a path that leaves the directory it is // served from. Only a symlink can reach it: the lexical check runs // first. ErrAssetEscape = errors.New("plugin: asset escapes the plugin directory") // ErrAssetTooLarge reports an asset above MaxAssetBytes. ErrAssetTooLarge = errors.New("plugin: asset exceeds MaxAssetBytes") )
Asset failures. The tree view reports them wrapped in an *fs.PathError whose Path is the bundle-relative name, never an absolute one.
var Charter = []CharterRow{
{
Kind: "mcp", ManifestField: "MCP", Permission: "mcp:provide",
DropRule: "the mcp section is dropped: no child process starts, " +
"no host token is minted, and a plugin node bound to it " +
"fails with the missing grant",
},
{
Kind: "skills", ManifestField: "Skills",
Permission: "skills:provide",
DropRule: "the skills list is dropped: SkillRoots omits the " +
"plugin's skill directories",
},
{
Kind: "hooks", ManifestField: "Hooks", Permission: "hooks:provide",
DropRule: "the hooks list is dropped: HookSources omits the " +
"plugin's hook files",
},
{
Kind: "nodes", ManifestField: "Nodes", Permission: "nodes:provide",
DropRule: "the nodes section is dropped: no node resource and no " +
"engine dependency is synthesized",
},
{
Kind: "ui", ManifestField: "UI", Permission: "ui:webview",
DropRule: "nothing is dropped here: craft hands ui.entry to the " +
"shell without consulting the permission",
Exemption: "the shell's UI registry gates the bundle; craft only " +
"validates the path and publishes it",
},
{
Kind: "storage", Permission: "storage:kv",
DropRule: "nothing is dropped here: plugin KV stays reachable " +
"through the host regardless",
Exemption: "the shell binds plugin KV per plugin id; Host.KV is " +
"the host-side accessor and carries no gate",
},
}
Charter is the contribution table. charter_test scans it against Manifest and validPermissions in both directions; charter_source_test audits the gates behind it.
Functions ¶
func ResolveCommand ¶
ResolveCommand resolves a plugin-relative command and its arguments: every path that contains a separator stays inside the plugin root, bare names are looked up through PATH by the OS.
Arguments carrying a path are resolved whether or not the command itself has one, because the two are independent: the documented Python shape is a bare interpreter with a plugin-relative script ("command": "python3", "args": ["server/main.py"]), and the child's working directory is not the plugin root.
func ResolvePath ¶
ResolvePath confines rel inside root and returns the absolute path.
func ToolNamespaces ¶
ToolNamespaces returns the tool-name namespace of every MCP server of one plugin, in declaration order. A single-server plugin keeps the plugin namespace, ToolPrefix(id). A plugin with several servers adds the server's name — or its position, when the manifest does not name it — so two servers of one manifest cannot publish the same tool name: the registry keeps the first registration and the second server's tool would simply not exist. Manifest.Validate rejects the manifests where even that is not enough (two servers with the same name).
func ToolPrefix ¶
ToolPrefix is the tool-name namespace of a plugin: [a-z0-9_-] only, suffixed with the MCP prefix separator.
func ValidPermissions ¶
func ValidPermissions() []string
ValidPermissions returns the sorted permission whitelist.
Types ¶
type Caller ¶
type Caller interface {
CallTool(ctx context.Context, toolName string, args any) (json.RawMessage, error)
}
Caller is optionally implemented by sources that support direct tool invocation; plugin graph nodes use it.
type CharterRow ¶
type CharterRow struct {
// Kind names the contribution ("skills", "hooks", "mcp", "nodes",
// "ui").
Kind string
// ManifestField is the Go field name on Manifest.
ManifestField string
// Permission is the manifest permission that authorizes it.
Permission string
// DropRule is the fail-closed answer to a declaration that arrives
// without the permission: the host drops the section and keeps
// loading the plugin. It is the written record of the ignore;
// charter_source_test in package craft pairs it with a runtime
// probe that shows the drop.
DropRule string
// Exemption names the owner of a check that does not live in this
// module, for example the shell. Empty means the source audit must
// find a negated HasPermission gate for the permission; a set value
// makes the audit require the opposite, so an exemption cannot
// outlive its subject.
Exemption string
}
CharterRow documents one plugin-declared contribution: which manifest field carries it, which permission authorizes it, what happens when the declaration arrives without that permission, and why a permission might have no gate in this module.
type Entry ¶
type Entry struct {
ID string
Dir string
Manifest Manifest
Enabled bool
Builtin bool
// ShadowsBuiltin reports a user plugin overriding a builtin id.
ShadowsBuiltin bool
BuiltinVersion string
// Error holds the scan/validation error for an invalid plugin.
Error string
// Conflict names why a valid plugin cannot be published: another
// plugin claims one of the tool namespaces it would publish under.
// It is separate from Error because the plugin is not invalid — its
// manifest parses, its files are there — and the two states need
// different recoveries: a plugin with a conflict can be disabled
// (which is how a user resolves the collision), while an invalid one
// can be neither enabled nor disabled through the store's valid
// view.
Conflict string
}
Entry is one scanned plugin.
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host owns the enabled plugin processes: one tool source per plugin, shared by every runtime of a Craft.
func NewHost ¶
func NewHost(opts HostOptions) (*Host, error)
NewHost opens a plugin host over a store.
func (*Host) AssetFS ¶
AssetFS returns a read-only view of one plugin's UI bundle: the directory holding its ui.entry, addressed by bundle-relative paths. The second result is false when the id is unknown or invalid, when the plugin declares no ui.entry, or when the bundle is no longer there.
The bundle is what a shell loads, so the view is rooted at the entry's directory rather than at the plugin directory: index.js and the chunks next to it resolve exactly as the bundle's own relative imports do. Nothing outside that directory is reachable, and every path is re-validated on each open because a plugin directory is user-writable and can change under a running shell:
- anything but a slash-separated relative clean path is fs.ErrInvalid;
- a symlink leaving the bundle is ErrAssetEscape, one that stays inside is followed;
- a device, socket or fifo is fs.ErrInvalid, and a single asset above MaxAssetBytes is ErrAssetTooLarge — checked when the file is opened and again while it is read.
ui:webview is deliberately not consulted here: craft delivers assets and lifecycle, and the shell gates the bundle. The permission travels with the ui.Registry entries.
func (*Host) CallTool ¶
func (h *Host) CallTool( ctx context.Context, pluginID, toolName string, args any, ) (json.RawMessage, error)
CallTool invokes one tool on a running plugin's primary MCP server.
func (*Host) HookSources ¶
func (h *Host) HookSources() []hooks.ExtraSource
HookSources returns the hook files of every enabled plugin that declares hooks:provide, each anchored to its plugin directory and marked untrusted. Both facts matter to a runner: a plugin's hooks.json expects to run inside its own directory, and it is third-party content, so the runner strips the content-bearing payload fields before those commands see them. Sources are ordered by path, so hook execution order is stable across calls.
Like Host.SkillRoots, the empty list of an unreadable enable state is reported rather than passed off as "no plugin contributes hooks".
The signature is the one core's hooks.SourceProvider declares, and this method is what makes a craft host that provider, so the error cannot be returned from here; the runner reads its sources at every build, and a warning per build is what an application sees of a plugin tree it cannot read.
func (*Host) Install ¶
Install installs a plugin from a directory and keeps its process in step with what was installed. A zip package is unpacked by Store.InstallZip, which is the store's path and touches no process.
The store pipeline is the one Store.Install runs — the same checks, the same snapshot, the same restore on failure. What this method adds is the process side of it: an install replaces the directory a running plugin's process reads, so a running plugin is stopped for the change and started again afterwards, from what the store now holds. See [Host.changeLocked] for what happens when either half fails.
An id that was not installed at all is recorded disabled once the install succeeded: a change does not turn a plugin on, and the entry a fresh id would otherwise carry — a store with no record for it reads enabled — would say enabled about a plugin with no process behind it, the one state a running host does not leave behind. Host.SetEnabled is what starts it.
The summary describes what was installed. One kind of failure returns it alongside the error: a fresh install that landed but whose "disabled" record could not be written — the summary is what is on disk, and the error says what could not be recorded about it.
func (*Host) OnStopped ¶
func (h *Host) OnStopped(fn func(id string, reason StopReason)) func()
OnStopped subscribes to plugin stops. The callback receives the plugin id and why it stopped: StopRequested for a stop the application asked for, after the process is gone and its tools have left the shared set; StopRolledBack for an enable the host undid because the plugin could not come up; StopFailed for a process that stopped on its own and could not be reconnected, with the entry and its tools left as they are so the application decides what the loss means.
Multiple subscriptions are allowed and the returned function unsubscribes this one; calling it more than once is safe. Stops happen whether or not anyone subscribed — craft's own wiring (token revocation) is independent of these subscriptions. A callback runs on the goroutine that stopped the plugin (or, for StopFailed, on the MCP retry goroutine), so it should return promptly and must not call back into the host for the same plugin: that stop already holds the plugin's entry lock.
func (*Host) Rollback ¶
Rollback restores the last snapshot of one plugin and keeps its process in step with it.
A rollback whose version cannot come up is the one change this file cannot undo: the swap consumes the version it replaced, so the plugin is left stopped with its record disabled rather than saying enabled about a process that is not there. The error says what failed; installing a package is what repairs the plugin.
func (*Host) SetEnabled ¶
SetEnabled starts or stops one plugin and bumps the store revision.
Starting waits for the plugin's MCP servers to come up, bounded by HostOptions.EnableTimeout, so an enable reports a plugin that cannot come up at all — a command that is gone or not executable, a peer that refuses the connection — instead of recording an enable whose process never arrives. Such an enable is rolled back: the process is stopped and the entry is left disabled. An entry a previous session had recorded as enabled loses that record along with the process, because a record that says enabled about a plugin with no process is the disagreement this wait exists to prevent. A server that is merely not there yet (a remote endpoint that is down, a child that keeps dying during startup) is not a failure of enable: the wait gives up at the timeout, the entry is recorded enabled, and the source keeps reconnecting in the background.
Enabling a plugin that is still running starts nothing, and enabling one whose source gave up is a start: the process behind that source is gone (the application heard about it through Host.OnStopped), so the dead source is replaced and this call reports whether the replacement came up. A loss that arrives while the wait runs is that call's to narrate: the rollback is its report, and an enable that stands hands the loss on once it ends.
The wait runs while the plugin's entry lock is held, so a disable or a Close racing this enable waits for it, bounded by that timeout.
func (*Host) SetPluginHooks ¶
func (h *Host) SetPluginHooks( env func(Entry, uint64, map[string]string) error, stopped func(string), )
SetPluginHooks installs the per-plugin env injector and the stopped-plugin callback. It must be called before Start. An application that wants a stop notification of its own subscribes with Host.OnStopped instead: that seam is additive, so using it cannot displace this wiring.
The injector is handed the generation of the process it is preparing: it is where an application mints what that process is allowed to do (craft mints the plugin's host token there), and a generation that changes is what tells it the grants of the process being replaced have to go with it.
func (*Host) SkillRoots ¶
SkillRoots returns the absolute skill directories of every enabled plugin that declares skills:provide.
The empty list of an unreadable enable state is reported rather than passed off as "this host provides no skills": the state file is fail-closed everywhere (see [Store.scan]), so an empty answer is what the application was shown, and the reason has to be visible in the log. The signature carries no error because this method is also the `skills` half of the seam core's hooks runner reads (see Host.HookSources), and a demo whose plugin tree is unreadable is not a reason to refuse a runner its sources.
func (*Host) Start ¶
Start launches every enabled plugin. Individual plugin failures are aggregated; the remaining plugins still start.
Start does not wait for plugins to come up and does not undo the state they were enabled with: it replays what a previous session recorded, and an application's startup must not depend on a plugin's process. A plugin that cannot come up is reported through Host.OnStopped instead; Host.SetEnabled is the call that waits, because an application asking for this plugin now is entitled to know whether it arrived.
func (*Host) Subscribe ¶
func (h *Host) Subscribe(fn func()) func()
Subscribe delegates to the store.
func (*Host) Uninstall ¶
Uninstall stops one plugin and then removes it through the store. Stopping comes first and its failure aborts the uninstall: removing a directory out from under a running plugin would take the files its process still reads and leaves the drain waiting for work that will never finish.
It is one of the plugin's migrations, so it holds the entry lock and runs in the order the others do (see [Host.changeLocked]): what the uninstall would be refused for is asked before the stop — killing the process of a builtin plugin (or of an id that does not exist) and only then discovering the uninstall cannot happen leaves the record saying enabled about a plugin whose process is gone — and a store that refuses after the stop leaves a plugin that was running running again. The lock is what keeps an enable from starting a process while the store removes the directory that process is served from.
func (*Host) UpdateFrom ¶
UpdateFrom updates one installed plugin from its declared update source and keeps its process in step with what was installed. The update is refused and nothing is installed when the version rules or the installer's approval say no (see Store.UpdateFrom).
A running plugin is stopped for the update rather than after it: the install replaces the directory the process reads. An update that the source refuses — the network, the checksum, a version that is not newer — starts the installed version again before this call returns, so what the refusal costs a running plugin is a restart, not a stopped plugin.
type HostOptions ¶
type HostOptions struct {
Store *Store
NewSource NewSourceFunc
Env map[string]string
DrainTimeout time.Duration
// EnableTimeout bounds how long [Host.SetEnabled] waits for a plugin
// to come up. Zero means [DefaultEnableTimeout]; a negative value
// does not wait at all, which is what every enable did before the
// wait existed.
EnableTimeout time.Duration
}
HostOptions configures a plugin Host.
type Installer ¶
type Installer interface {
// Check fetches and returns the update manifest published at source,
// a plugin's update.url.
Check(ctx context.Context, source string) (UpdateInfo, error)
// Fetch downloads the package info describes and returns its path on
// disk plus the cleanup that removes it, and returns a cleanup even
// when it fails after writing something. craft verifies the checksum
// before it reads the file, so Fetch needs no opinion about what it
// downloaded.
Fetch(ctx context.Context, info UpdateInfo) (string, func(), error)
}
Installer is the remote half of an update: the seam an application implements because transport is the application's to decide — TLS settings, proxies, credentials for a private feed, and which hosts a plugin is allowed to reach at all. craft validates what comes back, checks the package against its checksum and installs it through the same pipeline as any other source, so the policy half (https only, private and loopback ranges refused, redirects capped, timeouts) can live where the network stack already is.
type KV ¶
type KV struct {
// contains filtered or unexported fields
}
KV is one plugin's namespaced key/value store.
type MCPServer ¶
type MCPServer struct {
Name string `json:"name,omitempty"`
Transport string `json:"transport,omitempty"`
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
URL string `json:"url,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Required bool `json:"required,omitempty"`
}
MCPServer declares one MCP server the plugin ships.
type Manifest ¶
type Manifest struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Version string `json:"version"`
MinHostVersion string `json:"minHostVersion,omitempty"`
Permissions []string `json:"permissions,omitempty"`
UI *UIManifest `json:"ui,omitempty"`
MCP *MCPServer `json:"mcp,omitempty"`
Update *UpdateDecl `json:"update,omitempty"`
Skills []string `json:"skills,omitempty"`
Hooks []string `json:"hooks,omitempty"`
Nodes []NodeDecl `json:"nodes,omitempty"`
// Legacy aliases accepted from opencraft manifests.
LegacyEntry string `json:"entry,omitempty"`
LegacyMCPServers []MCPServer `json:"mcpServers,omitempty"`
// Legacy features rejected with an upgrade hint.
Kraft json.RawMessage `json:"kraft,omitempty"`
Tools json.RawMessage `json:"tools,omitempty"`
}
Manifest is the decoded plugin.json.
func ParseManifest ¶
ParseManifest decodes and validates one plugin.json.
func (Manifest) HasPermission ¶
HasPermission reports whether the manifest declares permission.
type NewSourceFunc ¶
type NewSourceFunc func( ctx context.Context, entry Entry, env map[string]string, dataDir string, ) (Source, error)
NewSourceFunc builds one plugin's tool source. Tests inject fakes; production uses the MCP source factory.
type NodeDecl ¶
type NodeDecl struct {
Type string `json:"type"`
Tool string `json:"tool"`
Desc string `json:"desc,omitempty"`
Timeout string `json:"timeout,omitempty"`
}
NodeDecl declares one plugin-provided graph node.
type Options ¶
type Options struct {
// Roots are scanned in order; a later root shadows an earlier one
// with the same plugin id.
Roots []Root
// StateDir holds the enable state and plugin KV files.
StateDir string
// DataDirRoot holds one data directory per plugin.
DataDirRoot string
// HostVersion is reported to plugins and checked against
// minHostVersion when non-empty.
HostVersion string
}
Options configures a Store.
type Readiness ¶
Readiness is optionally implemented by sources that can report when they are up. An enable waits on it (Host.SetEnabled), so a plugin that cannot come up is reported by the call that asked for it; a source that does not implement it is enabled without a wait, which is how every source was treated before the seam existed.
WaitReady returns nil once every server of the plugin is serving, and an error when the bound (or ctx) elapses first. A Validation-class error is the terminal case — the source will not come up on its own — and is what makes an enable roll back; any other error means "not yet", and the enable stands with the source still reconnecting.
type Root ¶
Root is one directory scanned for plugin subdirectories. Builtin roots are read-only: they can be disabled or shadowed by a user root with the same plugin id, never uninstalled.
type Source ¶
type Source interface {
Tools() []tool.Tool
LazyTools() []tool.LazyTool
Attach(tool.Registrar)
Close() error
}
Source is one plugin's tool contributor: a mcp.Source in production, a fake in tests. A source may also implement Readiness, which is what lets an enable wait for the plugin instead of only spawning it.
type StopReason ¶
type StopReason string
StopReason explains why a plugin stopped.
const ( // StopRequested is a stop the application asked for: disabling the // plugin, uninstalling it, or closing the host. StopRequested StopReason = "requested" // StopFailed is a process the host did not stop: the plugin's MCP // server is gone and the background reconnect gave up on it, // because the command cannot be started at all (missing, not // executable) or because the server rejects the connection. The // entry keeps its state — enabled, with its tools still projected // — and the application decides what the loss means. StopFailed StopReason = "failed" // StopRolledBack is a stop that undid an enable: the host stopped a // process it had just started because the enable could not be // completed — the plugin never came up (the error [Host.SetEnabled] // returned says why), or the state write that would have recorded // the enable failed. The entry is left disabled, so the application // has nothing to correct. StopRolledBack StopReason = "rolled_back" )
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store scans plugin roots, keeps the enable state and plugin KV data, and publishes a revision on every mutation.
func (*Store) Asset ¶
Asset materializes one plugin-relative file: a plugin file outside the UI bundle, such as a pet pack. Paths are relative to the plugin directory; for bundle files use Host.AssetFS, whose paths are relative to the directory holding ui.entry.
func (*Store) CheckUninstall ¶
CheckUninstall reports whether id can be uninstalled at all, with the same verdict Store.Uninstall acts on: an invalid id, an unknown plugin, or a builtin, which is refused here as well. It exists for the caller that has to stop the plugin's process before the files go away: a refusal must arrive while the process is still running, because stopping it first and failing afterwards leaves a plugin the record calls enabled without the process that was serving it.
func (*Store) Enabled ¶
Enabled returns every valid, enabled plugin that can be published: a plugin whose tool namespace another plugin already claims is not in the list, because starting it would publish tools under a name that does not resolve. The entry stays readable (and disable-able) through Store.List and Store.Entry.
func (*Store) Entries ¶
Entries returns every valid scanned plugin. An unreadable state file is an error: nothing may act on the fail-closed view as if it were the recorded one.
func (*Store) Entry ¶
Entry returns one valid plugin by id. A plugin whose tool namespace collides with another's is returned too: it is valid, it is readable, and the conflict travels with it (see Entry.Conflict) — a caller that would start it has to refuse it, and a caller that would disable it must be able to find it.
func (*Store) Inspect ¶
Inspect reads and validates one plugin source directory without installing it.
func (*Store) Install ¶
Install copies a plugin directory into the writable root. Installing over an installed plugin requires a strictly newer version and keeps a rollback snapshot in <root>/.backups/<id>; installing a newer version over an id that exists only as a builtin creates the user copy that shadows it, and keeps nothing, because there is no copy of ours to restore.
func (*Store) InstallZip ¶
InstallZip installs a plugin from a zip package, the shape a release artifact arrives in. The archive may carry the plugin files at its root or under a single top-level directory; the directory holding plugin.json is unpacked into a temporary tree and installed through Install, so a package gets exactly the validation, version rule, snapshot and rollback of a directory install.
func (*Store) List ¶
List returns every scanned plugin, including invalid ones. A state file that could not be read is returned alongside the list: the plugins are still listed (so a UI can show them and the error), but their enabled flags are the fail-closed ones.
func (*Store) Rollback ¶
Rollback restores the last snapshot of one plugin. The id is validated first: every path below is built from it, and filepath.Join cleans "..", so an unvalidated one would resolve the snapshot — and the target it is swapped with — outside the plugin root.
func (*Store) SetEnabled ¶
SetEnabled toggles one plugin and bumps the revision.
func (*Store) Subscribe ¶
func (s *Store) Subscribe(fn func()) func()
Subscribe registers fn for revision changes and returns a cancel function.
func (*Store) Uninstall ¶
Uninstall removes an installed plugin: its directory, its rollback snapshot, its enable state and, unless UninstallOptions keeps them, its KV file and data directory. A builtin plugin is refused (disable it instead); uninstalling a user plugin that shadows a builtin removes the copy and uncovers the builtin again.
Nothing here stops a running plugin: Host.Uninstall drains the process first, and a direct caller owns that step. Application-sized state that happens to be keyed by plugin id (secrets, inference profiles) is not craft's to delete and is left alone.
func (*Store) UpdateFrom ¶
UpdateFrom checks one installed plugin's declared update source, verifies what it offers and installs it. The version rule is the one every install obeys (strictly newer than what is installed) and the package must hold the plugin that was asked for, so an endpoint cannot turn an update into a different plugin. An update that would add permissions, or that starts declaring an MCP server, needs the installer's approval (see UpdateApprover) before anything is installed.
type Summary ¶
type Summary struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Entry string `json:"entry,omitempty"`
Permissions []string `json:"permissions,omitempty"`
Enabled bool `json:"enabled"`
Builtin bool `json:"builtin,omitempty"`
ShadowsBuiltin bool `json:"shadows_builtin,omitempty"`
BuiltinVersion string `json:"builtin_version,omitempty"`
Error string `json:"error,omitempty"`
// Conflict names the tool namespace another plugin already
// publishes; the entry is listed, and cannot be enabled until one of
// the two is disabled or renamed.
Conflict string `json:"conflict,omitempty"`
}
Summary is the UI-facing view of one plugin.
type ToolSet ¶
type ToolSet struct {
// contains filtered or unexported fields
}
ToolSet aggregates every enabled plugin's tools and fans additions and removals out to every attached registry (one per runtime generation). It implements tool.Source, tool.RegistryAttacher and tool.RegistryDetacher, so it can be injected as the craft.plugins external: a generation attaches when it builds and detaches when it closes.
func (*ToolSet) Attach ¶
Attach implements tool.RegistryAttacher: a runtime registry attaches here and receives every current plugin tool.
func (*ToolSet) Attached ¶
Attached reports how many live downstream registries are attached. Closed registries detach, so the count tracks live runtime generations.
func (*ToolSet) Close ¶
Close removes every plugin and releases the sources.
Each plugin's drain is bounded by the host's drain timeout: a call that does not finish in time is reported, and the source is closed anyway — an unbounded close would let one hung call keep the whole process from shutting down.
func (*ToolSet) Detach ¶
Detach implements tool.RegistryDetacher: the generation that built the registrar has closed, so stop fanning plugin publications out to it. Without this, the retired generation stays reachable from this process-wide set for as long as the host lives.
func (*ToolSet) RemovePlugin ¶
RemovePlugin closes the plugin to new calls, removes its tools from every registry, waits for the calls in flight bounded by ctx, then closes the source.
type UIManifest ¶
type UIManifest struct {
Entry string `json:"entry"`
}
UIManifest points at the plugin's UI bundle.
type UninstallOptions ¶
type UninstallOptions struct {
// KeepKV leaves the plugin's key/value file in place.
KeepKV bool
// KeepData leaves the plugin's data directory in place.
KeepData bool
}
UninstallOptions selects what survives an uninstall. Both flags are off by default: plugin KV and the data directory belong to the plugin, so a reinstall starts clean, and keeping them is a decision the caller makes explicitly.
type UpdateApproval ¶
type UpdateApproval struct {
// Permissions are the grants the update adds, in name order.
Permissions []string
// ServerAdded reports an update that starts shipping an MCP server.
ServerAdded bool
}
UpdateApproval describes what an update would add on top of the installed plugin: the permissions the incoming manifest requests that the installed one did not, and whether it starts declaring an MCP server where the installed one declared none. The update source is the same source that served the version check, so nothing here verifies that the package is the same plugin asking for the same things; these are the parts a user would have to agree to, so craft asks before the package is installed.
func (UpdateApproval) Empty ¶
func (a UpdateApproval) Empty() bool
Empty reports whether the update asks for nothing the installed manifest did not already have.
func (UpdateApproval) String ¶
func (a UpdateApproval) String() string
String renders an approval for an error message.
type UpdateApprover ¶
type UpdateApprover interface {
ApproveUpdate(
ctx context.Context,
id string,
approval UpdateApproval,
) error
}
UpdateApprover is optionally implemented by an Installer that decides grants for the application. An update that requests new permissions or starts an MCP server is approved through it and refused when there is no approver: craft never approves a grant expansion on its own. A nil return approves; any error is reported to the caller and installs nothing. An update that asks for nothing new is not routed here at all.
type UpdateDecl ¶
type UpdateDecl struct {
URL string `json:"url"`
}
UpdateDecl declares where an application can look for a newer version of the plugin: a JSON manifest at url (see UpdateInfo). craft checks the shape and hands the URL to an Installer; it never fetches anything itself.
type UpdateInfo ¶
type UpdateInfo struct {
Version string `json:"version"`
DownloadURL string `json:"download_url"`
Checksum string `json:"checksum"`
Changelog string `json:"changelog,omitempty"`
}
UpdateInfo is the update manifest an update.url endpoint returns: the version it describes, where that version can be downloaded, and the checksum the package must have. It is the shape opencraft serves, so a plugin repository stays portable between the two.