Guides

Plugins

Define local tools with typed schemas, permission allowlists, timeouts, and circuit breakers.

Updated Nov 13, 20264 min readv0.3.0-beta
On this page6 sections

Plugins extend the runtime with tools, inference providers, stores, and lifecycle services. They load from the project directory, the user config directory, or a manifest, and tool calls pass through one validation and policy pipeline regardless of where the plugin came from.

What a plugin can register

FactoryCategoryRegisters
defineToolToolA callable with a declared schema, permissions, timeout, and breaker.
defineProviderInference providerA complete or stream implementation for a model backend.
defineStorageKey/value storeget, set, delete, keys, plus flush and stats.
defineVectorStoreVector storeupsert, query, delete, and count.
defineServiceLifecycle serviceHooks for start, turn start, tool call, tool result, turn end, and stop.
useOpenAPI / ingestMcpBridgeTools generated from an OpenAPI document or an existing MCP server.

A file registers itself with export default defineTool(...), or by calling another factory directly. A file that loads but registers nothing is reported as broken; it does not abort discovery of the remaining plugins.

Define a tool

TypeScript
// plugins/weather.ts
import { defineTool, z } from "sofuu";

export default defineTool({
  name: "weather",
  description: "Get current weather for a city",
  schema: z.object({ city: z.string() }),
  timeoutMs: 5000,
  permissions: { net: ["api.weatherapi.com"] }, // network allowlist
  circuitBreaker: { failureThreshold: 5, resetTimeoutMs: 30000 },
  async run({ city }, ctx) {
    const res = await ctx.fetch(
      `https://api.weatherapi.com/v1/current.json?q=${city}`,
    );
    return res.json();
  },
});
FieldPurpose
name, descriptionIdentity shown in the tool inventory and to the model.
schemaInput contract. Accepts the bundled micro-Zod subset or a plain JSON Schema object.
output / resultSchemaOptional output contract. A soft failure ({ok:false}) passes through untouched.
permissions.netHost allowlist applied by the guarded ctx.fetch.
requiresApprovalRisk hint surfaced to the host approval UI.
timeoutMsWatchdog deadline. The default is 15 seconds.
circuitBreakerFailure threshold and reset window. The default is 5 failures in 30 seconds.
run(args, ctx)The implementation. Every call receives the validated arguments.

ctx provides a guarded fetch, a filesystem jail scoped to the session root (readFile, writeFile, exists, readdir, mkdir, rm, and related helpers), an abort signal tied to the watchdog, a read-only environment snapshot, and prefixed logging. A blocked host raises E_DENIED, and the tool returns {ok:false, source:'plugin', error:{code,message}, text}.

Discovery and loading

SourcePathNotes
Project./plugins/*.{js,ts}Dotfiles and *.d.ts are ignored.
User~/.sofuu/plugins/*.{js,ts}Applies to every project.
Manifestsofuu.jsonplugins: [{ source, enabled? }]; source is a path, never a fetched URL.

TypeScript is stripped textually and then evaluated. There is no separate tsc step, and the stripper is not tsc: decorators, abstract, implements, overload signatures, and some annotated class forms are not transformed. Write the plain-JavaScript equivalent for those, and run sofuu plugin validate before relying on discovery.

Shell
sofuu plugin init weather --category=tool
sofuu plugin list                  # name, category, circuit state, timeout
sofuu plugin validate plugins/weather.ts
sofuu plugin test weather '{"city":"Guwahati"}'
sofuu plugin add llamacpp          # install from the provider catalog

The execution pipeline

Every tool call passes through the same ordered shields.

#ShieldFailure codeBehavior
1Input schemaE_SCHEMAValidated before run(); the callable never sees a bad argument.
2Policy and networkE_DENIEDChecked before execution. ctx.fetch and ctx.fs add their own checks. A denial does not trip the breaker.
3Circuit breakerE_CIRCUIT_OPENOpens after the configured failures. In half-open state, one trial is admitted at a time.
4WatchdogE_TIMEOUTDelivers an abort to ctx.signal at timeoutMs.
5Panic guardE_TOOLSynchronous throws, rejected promises, circular returns, and BigInt results become typed results.

The policy check denies when evaluation is unavailable, malformed, or fails. sofuu.plugins.invoke reads the evaluator's actual ask decision and requests approval when required, or accepts explicit host approval; an unattended ask is denied. A policy denial overrides a supplied approval. A host that calls the lower-level execute path directly must handle ask itself.

Limits before you ship

  • Plugin code runs in-process. The shields contain faults, not malice; a plugin that allocates without bound can still hurt the process.
  • Provider streams from JavaScript adapters are buffered and then replayed, not delivered incrementally. A body over 8 MB fails with E_BACKPRESSURE.
  • useOpenAPI generates one tool per operation but does not implement authentication flows. Pass headers through opts.headers and keep secrets in the environment.
  • useOpenAPI and ingestMcp never fetch a remote document. You supply the spec text or the server command.

Next steps