Writing a plugin

The folder layout, the manifest, the script and its permissions, how to try a plugin from a folder and how to publish it.

A plugin is a folder. This page covers what goes in it, how its script works and what it may ask for, and how to try it and publish it. For complete examples, the plugin API in the Kettu repository has the types, a reference of every call and event, and a sample plugin, all under the MIT license so you can copy the types into your own repository. Kettu’s own plugins are in KettuAI/plugins: ntfy, Feishu / Lark, Linear and Sentry, each with its tests.

The folder

my-plugin/
  plugin.json                the manifest
  assets/icon.png            the icon, up to 512 KB
  skills/review/SKILL.md     one folder for each skill
  mcp.json                   MCP servers
  sh.kettu/
    main.js                  the script
    commands/review.md       commands
    roles/reviewer.md        roles
    workflows/release.yaml   Workflows
    themes/dusk.json         themes
    templates/brief.json     artifact templates

Only plugin.json is required. plugin.json, skills/ and mcp.json follow the open Agent Plugins format, so a Kettu plugin’s skills and MCP servers also work in other tools that read it, and plugins written for that format by others install in Kettu. Everything of Kettu’s own sits under the format’s sh.kettu name: the sh.kettu entry of the manifest, and the sh.kettu folder. Other tools skip both.

Each item under sh.kettu is a file, or a folder of its own with the kind’s file in it: commands/review/command.md, roles/reviewer/role.md, workflows/release/workflow.yaml, themes/dusk/theme.json or templates/brief/template.json. The file’s name is the item’s name. A template’s template.json gives its type, document or slides, and guidance for the agent, and its folder may hold the starting content, document.md or slides.json and an images folder.

Kettu reads a folder without running any of it. A package holds up to 2,000 files and 50 MB, and no symbolic links. A plugin’s name is lowercase letters, digits, - and .. An item that doesn’t read, such as a command with no prompt, is left out and the install card says Left out with the reason; a bad manifest, a script that isn’t in the package or a path that leaves it refuses the whole package, and Kettu says why.

plugin.json

{
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
  "name": "tickets",
  "version": "1.0.0",
  "description": "Look up tickets from your agents.",
  "license": "MIT",
  "extensions": {
    "sh.kettu": {
      "format": 1,
      "title": { "en": "Tickets", "zh-CN": "工单" },
      "script": "./sh.kettu/main.js",
      "api": 1,
      "permissions": ["tools", "network:api.example.com"],
      "settings": [{ "key": "token", "type": "secret", "title": "Access token" }],
      "tools": [
        {
          "name": "find",
          "description": "Find tickets that match some words.",
          "inputSchema": {
            "type": "object",
            "properties": { "query": { "type": "string", "description": "What to look for" } },
            "required": ["query"]
          }
        }
      ]
    }
  }
}

The top level is the standard’s: $schema (version 1.0.0 or 1.1.0, which adds displayName), name, version, description, author, homepage, repository, license and keywords. A field it doesn’t define is ignored and the install card says so. The sh.kettu entry takes:

FieldWhat it is
format1, required. A Kettu that reads an older format asks you to update it first.
kettuA semver range of the Kettu versions the plugin supports. It isn’t installed on others.
title, descriptionA text by language, such as { "en": "…", "zh-CN": "…" }, or one text for English.
settings, toolsWhat a user can set, and what agents can call. See below.
script, api, permissions, eventsThe script, the plugin API version it is written for (1), what it may do and which Kettu events it listens to.
views, actions, mentions, links, channelsWhat Kettu draws or offers for the script. See Views and panes and the sections after it.

A field Kettu doesn’t know is ignored with a notice, so a plugin written for a later Kettu still installs. Kettu adds to a plugin API version and never changes or removes a call within it.

Settings, secrets and storage

settings declares what the plugin’s page in Settings › Plugins shows. Each has a key, a title, a type and optionally a description and a default:

TypeIs
booleanA switch.
stringA short text.
selectA choice, with options of value and title.
secretA text kept in the system’s key store and shown only as Set or Not set. It has no default.

The script reads them with kettu.call('settings.get', key) and kettu.call('settings.secret', key), and hears of a change as settings.changed. The settings, except the secrets, are also listed for agents, who may change them when you ask them to.

Each plugin also has a small storage of its own, storage.get, storage.set, storage.delete and storage.keys: at most 256 KB of JSON and 1,000 keys. It goes when the plugin does. Keep anything that must last there, not in the script’s variables.

For a secret of its own, such as a one-time token, the script can’t use Math.random, which is not safe for it. kettu.call('random.bytes', 16) gives 1 to 256 bytes from the system’s cryptographic source, as lowercase hex, and needs no permission.

The script

The script is one JavaScript file that talks to Kettu through a single global, kettu: kettu.call(name, ...args) returns a promise with a call’s result, and kettu.on(name, listener) listens to an event. A function the script exports under the name of a tool it declares is that tool.

// @ts-check
exports.find = async ({ query }) => {
  const token = await kettu.call('settings.secret', 'token')
  const url = 'https://api.example.com/search?q=' + encodeURIComponent(query)
  const { status, body } = await kettu.call('network.fetch', url, {
    headers: { authorization: `Bearer ${token}` },
  })
  return status === 200 ? body : `The service answered ${status}.`
}

It runs in a sandbox of its own on the computer, in a small JavaScript engine (QuickJS) compiled to WebAssembly. It has kettu, console, setTimeout and clearTimeout, and nothing else of Kettu or your computer: no files, no commands and no network of its own. The standard JavaScript language is there, but not URL, TextEncoder, btoa or crypto, so for random bytes it asks Kettu with random.bytes. The engine is much slower than Node.js, so keep the script to calls and small amounts of data. Lines it writes with console.log go to Kettu’s log under the plugin’s name.

When a script runs

Kettu loads a script when something it declares first happens: an event, a view that opens, a Search action, an @ source, a link, a tool an agent calls or a notification channel. A load runs the script from the top, so code outside a listener runs again each time.

Once loaded, the script stays loaded between calls, with its variables and its pending timers, until one of these happens:

  • The plugin is turned off, uninstalled, updated, rolled back or reloaded from its folder.
  • The script passes a limit and is stopped: a call, listener or timer callback that runs longer than 2 seconds without yielding (500 ms for the two hooks below), or memory past 64 MB. Three such stops in a minute turn the plugin off until you turn it on again, and its page says so.
  • Kettu restarts, as when the app quits or updates, or the part of it that runs scripts crashes.

Nothing unloads a script for being idle, and a timer neither keeps a script loaded nor brings it back. A script that polls with setTimeout can rely on staying loaded until one of the above happens, and on nothing more: its timers and everything in memory go with it, and it runs again only when something it declares wakes it. So start timers from code a declared trigger runs, keep what is needed to resume in storage and read it when the script loads. A script holds at most 256 pending timers and 256 calls that have not been answered.

To check the script against the types, copy index.d.ts from the plugin API (packages/plugin-api, MIT) into your repository, as Kettu’s own plugins do with their types/index.d.ts, start the script with // @ts-check and add /// <reference path="…/index.d.ts" />. Copy it again when the API adds calls. Those plugins also test their scripts with node:test against a fake kettu.

Permissions

A script may use only the calls of the permissions you list in permissions and the user agreed to for that version. A call without its permission fails, and the error names the permission. Ask for only what the plugin uses, and name the narrowest websites.

PermissionThe card calls itThe script may
noneRead its own settings and secrets, use its storage, ask for random bytes, and know the interface language and color mode.
network:api.example.com or network:*.example.comNetworkCall network.fetch over https to that host, or any host under the domain: the default port, no redirects, no address on this computer or a private network, and request and response bodies of text up to 256 KB.
sessions.summarySee sessionsList sessions with their title, project, agent, state and what each is doing, and hear of events about them, but not what was said in them.
toolsGive agents toolsGive agents the tools the manifest declares.
prompt.attachAttach to messagesAdd text to a message before it is sent, and offer @ sources.
requests.checkCheck permission requestsLook at a permission request first and deny it. It can never allow one.
sessions.contentRead conversations, in red with HighRead what was said in sessions. Notices sent to a channel then carry their words.
requests.answerRelay answers, HighReceive the commands an agent asks to run, and pass on the answer you gave elsewhere: allow once or deny, never always allow.
sessions.startStart sessions and send messages, HighStart sessions and send them messages, in a mode no wider than Auto, with at most 3 working at once and 10 started a day.

Whatever it holds, a script cannot run commands, read your project’s files, ask for system permissions, read an agent’s or GitHub’s credentials, reach another plugin’s data or touch Kettu’s window.

An update that adds a script or asks for a permission the installed version doesn’t have waits for the user, who sees only what is new. See Updates.

Tools

A plugin with the tools permission declares its tools under tools: a name of lowercase letters, digits and _ (up to 24), a description, and an inputSchema listing the arguments, each a string, number, integer or boolean, optionally with a description, an enum or a minimum and maximum. A plugin has up to 16 tools of up to 16 arguments. The script exports a function of the same name, which gets the arguments as one object and answers with the text the agent reads, as find does above. A throw, a crash or a call that is too slow is an error the agent reads.

Kettu lists the tool on its own tool service as tickets__find, the plugin’s name, two underscores and the tool’s name, and every agent can use it. An agent asks the user before it calls one, as it does for any tool.

Events and hooks

events names the Kettu events the script listens to, and each needs a permission. Events come only from sessions you work in, and never carry what was said without sessions.content.

EventPermissionHappens when
session.startedsessions.summaryA session comes into the sidebar.
session.toolFinishedsessions.summaryA tool call completed or failed.
session.turnEndedsessions.summaryA turn ended, and how.
session.needsUsersessions.summaryA request or an error waits for the user.
session.pullRequestChangedsessions.summaryA pull request of the session opened, or its state or checks changed.
task.stepStarted, task.stepEndedsessions.summaryA step of a Workflow task started or ended.
session.beforeSendprompt.attachA message is about to be sent. A hook.
session.permissionRequestedrequests.checkAn agent asks to use a tool. A hook.

app.locale, app.colorMode and settings.changed need no entry and no permission.

The two hooks may act, and must answer within 500 ms or are skipped:

  • session.beforeSend can return text to attach: up to 5 pieces and 32,000 characters. It is added to what the agent gets, never replaces what you wrote, and the thread shows it under the message as added by the plugin.
  • session.permissionRequested can return { deny: 'why' }. The request is refused with the reason, in the thread, with the plugin’s name. A hook can only deny: a late answer, an error or any other answer leaves the request to the user. It isn’t sent in Full access, where the agent doesn’t ask.
kettu.on('session.permissionRequested', ({ request }) => {
  if (request.command?.includes('rm -rf')) return { deny: 'A recursive delete is not allowed here.' }
})

Views and panes

A plugin never draws anything itself. It declares views, and Kettu draws their data with its own components, so every plugin looks like Kettu in the desktop app and in the web client.

"views": [{ "id": "open", "kind": "list", "title": "Open tickets", "icon": "list", "pane": true }]

A view has an id, a kind, a title by language, and optionally a description, an icon from the fixed list in the types and "pane": true. The script needs no permission for it. When a view opens, Kettu wakes the script, which answers view.data with the data the kind takes, and an action the user runs reaches view.action.

KindData
listrows, each with a title, subtitle, icon, badges, an end figure and actions
detaila title, fields and a Markdown body
formswitch, choice and text fields and a submit action
actionsa line of text and the buttons that run the script’s actions
kettu.on('view.data', async ({ view }) => {
  if (view !== 'open') return
  return {
    rows: [{ id: 'T-1', title: 'Fix the login page', subtitle: 'In progress', end: 'P1' }],
    empty: { title: 'No open tickets' },
  }
})

A view with pane is listed in the side panel, with the plugin’s icon, and opens as a tab of the session’s panel. A button can run an action or open another view of the plugin, and a destructive one is confirmed first. An answer that doesn’t fit, a script that throws or one that isn’t done in 30 seconds shows as an error in that view alone. A thrown error’s message is shown, so make it say what the user can do.

actions declares actions for Search: an id, a title and optionally a description and an icon. Search lists them in a group named for the plugin, and running one calls action.run, which answers like view.action; it may open a pane.

@ sources. mentions declares sources for the composer’s @ menu, each with an id, a title and optionally an icon, and needs prompt.attach. When the user types @, the script answers mention.search with up to 20 items, which the menu shows in a group of its own beside the project’s files. An item the user picks becomes a chip, and when the message is sent the script answers mention.content with the text the agent reads. The thread shows it under the message.

Links as references. links declares kinds of link, each with an id and patterns. A pattern is https://host/path in which a segment is a literal, * for any one segment or {name} for one the script is told, and a last ** stands for the rest. A pattern may name only hosts the plugin has a network: permission for. A link in a reply that matches is drawn as a reference once the script answers link.card with a title, a label, badges and fields; until then and when it doesn’t answer, the link stays as it was.

"mentions": [{ "id": "tickets", "title": { "en": "Tickets" }, "icon": "list" }],
"links": [{ "id": "ticket", "patterns": ["https://tickets.example.com/t/{id}"] }]

Notices and relayed answers

channels declares where a plugin can send Kettu’s notices, such as a chat or a phone: an id, a title and optionally a description. The user picks on the plugin’s page in Settings › Plugins which kinds go to each channel, none by default. A notice reaches the script as channel.notice, with its channel, kind and title. What it says, and the session it names, come only with sessions.content.

"channels": [{ "id": "chat", "title": { "en": "Team chat", "zh-CN": "团队聊天" } }]

A plugin with requests.answer is also told what a permission request that waits asks for, and may pass on the answer you gave elsewhere with kettu.call('requests.answer', { request, decision, from }). The decision is allow_once or deny, never always allow, and a question or a plan is never answered this way. The thread shows the answer with where it came from and the plugin’s name. This permission receives the commands an agent asks to run, which is why the install card marks it High.

Try it

Add the folder

In Marketplace, click Add and choose A plugin from a folder…. Kettu reads it, shows the same card as for any plugin and installs a copy. It is marked Dev, shows its folder, stays on this computer and is never updated from anywhere.

Reload after a change

Change the files, then click Reload on the plugin’s row in Marketplace › Installed, or in its More menu. Kettu copies the folder again, and an error from the script shows in the view that called it.

Check it

Ask an agent to run Kettu’s marketplace_check tool on the folder, or choose Publish › From a folder… in Marketplace › Published. Both need a Kettu account. The check uploads nothing: it says what the folder is, what an install adds and runs, and every problem in the way, such as a missing field or a secret left in a file.

Publish

To publish a plugin to the Kettu Marketplace you need a Kettu account. Open Marketplace › Published, click Publish, and choose Ask an agent, which starts a session that checks the folder and publishes it, or From a folder….

  • Every publish waits for you. A card in the session lists what it adds, who can see it, the files and the checks. Publish uploads it, and Not now keeps it as a draft. A new version asks again.
  • Who can see it. Everyone lists it in the Marketplace for anyone signed in to Kettu. Only me doesn’t list it, and installs it only on the computers signed in to your account, counting against your cloud storage. You can change it in Published later.
  • Publisher name. You pick it on your first publish, 1 to 32 lowercase letters, digits and hyphens, and it goes on everything you publish.
  • Versions. The version is the manifest’s version. A published version doesn’t change, and people who have the plugin get the next one at their next update, or after they agree, if it asks for more.
  • Review. Kettu checks a version before it lists it, and says why when one fails. A version that holds skills may be held for review first: Published shows it as Waiting for review, or wasn’t approved, with the reason, and the version before it stays listed.
  • Scripts. For now only Kettu’s own publisher can publish a plugin with a script, and the check says so before anything uploads. You can still share one on GitHub: people add it from Add › A plugin from GitHub…, and see its permissions first. Plugins with skills, MCP servers, commands, roles, Workflows, themes and templates can be published by anyone.

Have a Claude Code or Codex plugin? Choose Convert to a Kettu plugin when you publish its folder, or ask an agent to run marketplace_convert. Kettu writes a Kettu plugin to a new folder beside it and leaves the original as it is. Skills come over as they are, MCP servers in the standard form, commands as commands and agents as roles. Hooks don’t, and the result lists each part left out and why. Check the new folder before you publish it.