Plugins

Add tools, a side panel and tool cards to your host; install a plugin by copying a directory, or write your own.

A plugin is a directory on the host. It can give the agent new tools, keep its own state per conversation, and bring UI to the web and desktop apps: a page in the side panel and a card for its tool calls in the transcript.

Plugin UI is a web and desktop feature. On the iPhone a plugin's tools still work, but its panel and cards don't show.

Install a plugin

Copy the plugin's directory into plugins/ in the host's data directory: ~/.pinomad/plugins/<name>/, or under --data-dir if you run the host with one. A symlink to a directory elsewhere works too.

The running host notices the new directory and loads the plugin; there is no need to restart it. It also follows the plugin's files: after you edit one, the agent's next tool call runs the new code, and removing the directory removes the plugin's tools. A call that is already running finishes on the code it started with.

Web and desktop apps that are open follow along without reconnecting. An edited panel or tool card is replaced where it is shown, a new plugin's panel appears with its state, and a removed plugin's panel and cards go away. Only the edited plugin's panel starts over; the others keep what they show. A state you make shared or host-only takes effect in the open app as well. On the iPhone the tools follow your edits the same way. An app older than the host may need the page reloaded to pick up a change.

A plugin that fails to build or load is skipped with a line in the host's log, and the host and the other plugins carry on. When an edit breaks a plugin that was loaded, the host logs why and keeps the version it had until a later edit builds again; open apps keep showing that version too. If a new web.tsx builds but throws in the browser, the app logs the error in its console and keeps the version it had.

Installing a plugin means trusting it. Its server half runs inside the host process with the host's permissions. Its UI runs in the same page as the web and desktop apps, so it can read what that page can, including the device's key for the host. Only install plugins whose code you trust.

There is no plugin store, npm install or per-project plugin yet.

Write a plugin

A plugin directory holds a package.json and up to two code files:

artifact/
  package.json
  server.ts   runs on the host: tools, state, methods
  web.tsx     runs in the web and desktop apps: side panel, tool cards

package.json:

{ "name": "artifact", "private": true, "type": "module" }
  • name is the plugin's name: lowercase letters, digits and -, starting with a letter. Keep the directory named the same.
  • server and web can each end in .ts, .tsx, .js or .mjs. Either can be left out: a plugin with only tools has no web.tsx, a plugin with only UI has no server.ts.

The host builds both files itself with esbuild, so write any TypeScript or JSX, and split your code into more files inside the directory if you like; imports between them are bundled in.

The API's types are in the PiNomad repository, in packages/plugin/src/v1.ts (server) and v1-web.ts (browser). They aren't published as a package. A plugin imports from @pinomad/plugin/v1 and @pinomad/plugin/v1/web only; the host supplies them when it runs the plugin.

Moving a plugin from plugin.json

Plugins written before the host built them had a plugin.json and a host.ts. The host no longer reads plugin.json and logs a line for such a directory. To move one:

  1. Add a package.json as above, with the plugin's name.
  2. Rename host.ts to server.ts, import definePlugin and wrap the default export in it (see below).
  3. Delete plugin.json. A hand-written web.js keeps working as it is; rename it to web.tsx if you want to write JSX.

The server half

server.ts default-exports definePlugin(fn). fn receives the host API and registers everything before it returns, without awaiting:

import { definePlugin } from "@pinomad/plugin/v1";

export default definePlugin((pinomad) => {
  // pinomad.state(…), pinomad.tool(…), pinomad.method(…), pinomad.secret(…)
});
  • state(name, { version, initial, shared }): JSON state kept per conversation. initial() gives the value for a conversation that never wrote it. With shared: false the state stays on the host; otherwise (the default) clients receive it and the UI can read it with useState. Shared state is synced to every client showing the conversation, so keep large content host-only and fetch it through a method.
  • tool({ name, description, parameters, run }): a tool the model can call. parameters is a JSON Schema object. run(args, ctx) returns { text }, which is what the model sees; if it throws, the model gets the error message as a failed result. Tool names use letters, digits and _, at most 64 characters, must not start with mcp__, and must not clash with another tool on the host. A plugin that takes a built-in tool's name is not loaded, or keeps its previous version when an edit adds the name; of two plugins with the same tool name, the one later in alphabetical order is skipped. A call cut off by a host restart isn't run again.
  • method(name, run): a function your UI calls with call or useCall. run(args, ctx) takes and returns JSON; if it throws, the call fails with its message.
  • secret(name, { description }): a credential the user enters, such as an API token; see Secrets below. Returns a handle for ctx.secret. Names use letters, digits, _ and -.

ctx is the conversation the tool or method runs for:

  • ctx.conversationId
  • ctx.read(state): the committed value.
  • ctx.change(async (tx) => { … }): one commit. await tx.get(state) returns a draft you change in place; every draft you change is stored together, or none is.
  • ctx.cwd: the conversation's working directory, in a tool; undefined in a method.
  • ctx.secret(handle): the secret's value as it is set now, or undefined while it isn't.

Plugin state follows the conversation's history like the rest of the conversation: a Fork starts with the state as it was at that point.

Secrets

A plugin that calls an outside service on the agent's behalf needs a credential the agent must not see. Declare it with secret, read it inside run with ctx.secret, and send the request from the host process: the agent calls your tool, and the token is never in the conversation, a tool result or the agent's environment, so the agent can't simply repeat it to a page it reads. The agent's commands still run as the same user as the host, which can read secrets.json.

const token = pinomad.secret("api_token", { description: "An API token with write access." });

pinomad.tool({
  name: "service_post",
  // …
  run: async (args, ctx) => {
    const value = await ctx.secret(token);
    if (value === undefined) throw new Error("The api_token secret is not set; set it in the plugin's settings.");
    const response = await fetch("https://api.example.com/posts", { method: "POST", headers: { authorization: `Bearer ${value}` } });
    return { text: `Posted: ${response.status}` };
  },
});

The host keeps secrets in secrets.json in its data directory, readable only by the host's user (mode 600), by plugin and name. Clients set a value with the setPluginSecret call and see which secrets are set, never their values. Until the apps have a place to enter them, write the file while the host is stopped: { "<plugin>": { "<secret>": "<value>" } }.

The host replaces every set secret of the plugin with [redacted] in what its tools return or throw. A value you derive from a secret, such as a base64-encoded header, isn't caught, so keep it out of your results. Never put a secret in an environment variable, a file the agent can read, or the arguments of a process: pass it only to the request or child process that needs it.

The browser half

web.tsx default-exports a function that receives the browser API. The host builds it into one script; each client checks the script against the hash the host announced before running it. JSX renders with the app's React, and import { useState } from "react" gets that same React, so hooks from either react or pinomad.React are the app's own. Other React packages, such as react-dom, aren't available. CSS and image imports aren't supported yet; use inline styles and data: URLs.

  • React: the app's React.
  • panel({ id, label, component }): a page in the side panel. label names its button in the chat header.
  • toolCard(toolName, component): replaces the detail of every call of that tool in the transcript (what you see when you expand the call). The component gets tool: name, args (parsed, or undefined while they stream in), output (the text the model saw, once the call finishes) and state.
  • useState(stateName): hook; this plugin's shared state for the conversation on screen, undefined until it arrives.
  • useCall(method, args, deps): hook; the method's result, called again when deps change. Pass undefined as args to skip the call.
  • call(method, args): calls a method for the conversation on screen and returns a promise.
  • openPanel(id): opens one of this plugin's panels.
  • Sandbox: a component that renders an HTML document, see below.

Register panels and cards while the default export runs; later registrations are ignored. If a plugin component throws, its slot shows a short message and the rest of the app keeps working.

The sandbox

Your plugin's UI is trusted code, but what the model writes isn't. Sandbox takes html (a whole document) and title (the frame's accessible name) and renders the document in a frame, scripts included. It fills the space it's given. A new html starts a new document.

What the sandbox promises: content in it can't reach anything of the client, not the device key, not its storage and not the app's page. It does not promise to keep the content offline. Fetches, navigation and external scripts, styles and images are blocked as best effort, but WebRTC is not, so a page can still send data out through STUN or DNS. Inline scripts and styles work, and images load from data: URLs.

Example: GitHub

examples/plugins/github gives the agent github_open_pr, github_comment and git_push, which add the github_token secret in the host process. git_push pushes the conversation checkout's HEAD to a branch. The git that holds the token runs in a scratch repository the host makes, so hooks and config the agent writes into its checkout never run with it, and the token goes only to the GitHub server, in a header only that process sees. The GITHUB_API_URL and GITHUB_SERVER_URL variables in the host's environment point it at GitHub Enterprise. Copy the directory to ~/.pinomad/plugins/github/ and set github_token to try it.

It also declares three Inbox event sources: issues for new open issues of a repository, filtered by label (acme/web label:bug), and pr-comments and ci for pull-request comments and finished workflow runs (acme/web), which only reach a task that follows the PR. These declarations are inactive while Inbox mode is temporarily unavailable. For the implementation's tests, the token needs Issues, Pull requests and Actions read access.

Example: artifact

The repository has a complete plugin in examples/plugins/artifact: the model writes a web page, its tool card shows the page's title with an Open button, and the Artifact panel shows the page in the sandbox. It isn't built in; copy the directory to ~/.pinomad/plugins/artifact/ to try it.

The server half keeps the page on the host and shares only its title and a revision number:

import { definePlugin } from "@pinomad/plugin/v1";

export default definePlugin((pinomad) => {
  const page = pinomad.state("page", { version: 1, shared: false, initial: () => ({ title: "", html: "" }) });
  const current = pinomad.state("current", { version: 1, initial: () => ({ title: "", revision: 0 }) });

  pinomad.tool({
    name: "artifact_write",
    description: "Show a page to the user in the side panel. …",
    parameters: {
      type: "object",
      properties: { title: { type: "string" }, html: { type: "string" } },
      required: ["title", "html"],
    },
    run: async (args, ctx) => {
      const title = String(args.title);
      const html = String(args.html);
      await ctx.change(async (tx) => {
        Object.assign(await tx.get(page), { title, html });
        const shown = await tx.get(current);
        shown.title = title;
        shown.revision += 1;
      });
      return { text: `Showing "${title}" in the side panel.` };
    },
  });

  pinomad.method("read", async (_args, ctx) => ctx.read(page));
});

The browser half reads the shared revision and fetches the page again whenever it changes:

import type { PluginToolCall, WebApi } from "@pinomad/plugin/v1/web";

export default function artifact(pinomad: WebApi): void {
  function Panel() {
    const current = pinomad.useState<{ title: string; revision: number }>("current");
    const revision = current === undefined ? 0 : current.revision;
    const page = pinomad.useCall<{ title: string; html: string }>("read", revision > 0 ? null : undefined, [revision]);
    if (revision === 0) return <p>No artifact yet. Ask the agent to make a page.</p>;
    if (page === undefined) return <p>Loading…</p>;
    return (
      <div style={{ display: "flex", height: "100%" }}>
        <pinomad.Sandbox title={page.title} html={page.html} />
      </div>
    );
  }

  function Card({ tool }: { tool: PluginToolCall }) {
    const args = tool.args as { title?: string } | undefined;
    return (
      <div>
        <span>{args?.title ?? "Untitled page"}</span>
        <button type="button" onClick={() => pinomad.openPanel("page")}>Open</button>
      </div>
    );
  }

  pinomad.panel({ id: "page", label: "Artifact", component: Panel });
  pinomad.toolCard("artifact_write", Card);
}

The card shows only the title: the arguments also carry the whole document, which doesn't belong in the transcript. The files in the repository add styling and comments.

On this page