Your first plugin
This page walks through the whole cycle of writing a plugin: creating the files, packing them into one file, installing that file in the app, and installing a changed version. The plugin of the first part shows a message when it starts. The plugin of the second part refuses to delete the rows that carry the tag #keep.
The SDK, which provides definePlugin and the types of ctx, is published in the public repository tessera-plugins, together with the scripts that build a plugin and the plugins that come with the app. A plugin is written in a folder of a clone of that repository.
Set up the repository
Section titled “Set up the repository”You need Node.js 22 or later and Git. Clone the repository and install its dependencies once:
git clone https://github.com/tessera-plugins/tessera-plugins.gitcd tessera-pluginsnpm installThe repository contains the following folders.
| Folder | Content |
|---|---|
plugins/bundled/ |
The plugins that come with the app. |
plugins/examples/ |
Small plugins that show one idea each. They are good starting points to copy. |
sdk/ |
The code that a plugin imports as @tessera/plugin-sdk, and the code that builds and packs a plugin. |
types/ |
The TypeScript types of ctx, of the manifest, and of everything that a hook receives or returns. |
scripts/ |
The scripts behind npm run pack and npm run build, described in “Build a plugin” below. |
The folders sdk/ and types/ are generated by the maintainers of the app, so a change that you make in them is overwritten. Your plugin goes in a new folder under plugins/.
Build a plugin
Section titled “Build a plugin”Three commands, run in the root of the repository, check and build plugins:
| Command | What it does |
|---|---|
npm run typecheck |
Checks the code of every plugin in plugins/ against the types of ctx, without writing any file. A mistake such as a misspelled property of ctx, or a hook that returns the wrong kind of answer, is reported here, before the plugin runs in the app. |
npm run pack -- plugins/hello |
Builds one plugin and writes its plugin file. The argument is the folder of the plugin. A second argument, written after the folder, is the folder in which the file is written; without it, the file is written in the current folder. |
npm run build |
Does the same for every plugin of the repository, and writes the files in the folder dist/. |
Building a plugin takes its manifest.json and the file that the entry field names, and combines the code of that file with the few lines of the SDK that it uses (definePlugin and the answers allow, veto, amend and defer) into a single minified script. It then writes the manifest and the script together in one JSON file named after the id of the plugin, followed by .tessera-plugin.json. For example, the plugin com.example.hello becomes com.example.hello.tessera-plugin.json. The app reads exactly this file when a person installs the plugin.
Part 1: a plugin that shows a message
Section titled “Part 1: a plugin that shows a message”Create the folder and the two files
Section titled “Create the folder and the two files”Create a folder named plugins/hello, with the following two files in it. You can also copy a folder from plugins/examples/ and change it.
plugins/hello/manifest.json describes the plugin. The page Manifest and permissions explains every field.
{ "id": "com.example.hello", "name": "Hello", "version": "1.0.0", "minCoreVersion": "1.0.0", "description": "Shows a message when the app starts.", "author": "Your name", "permissions": ["ui"], "platforms": ["web"], "entry": "index.ts"}plugins/hello/index.ts is the code. The manifest names it in its entry field.
import { definePlugin, type PluginContext } from '@tessera/plugin-sdk';
export default definePlugin({ onload(ctx: PluginContext) { ctx.log('info', 'The plugin has started'); ctx.ui.notice({ text: 'Hello from my first plugin' }); },});The app calls onload once, when the plugin is turned on. ctx.log writes a line to the log of the plugin, and ctx.ui.notice shows a short message to the person. Showing a message requires the ui permission, which is why the manifest lists it.
Pack the folder into one file
Section titled “Pack the folder into one file”The app installs a plugin from a single file. The following command, run in the root of the repository, builds the code and writes the file (see “Build a plugin” above):
npm run pack -- plugins/helloThe command prints the name of the file that it wrote: com.example.hello.tessera-plugin.json, in the current folder. The name of the file is the id of the plugin followed by .tessera-plugin.json.
Install the file in the app
Section titled “Install the file in the app”- Open Settings, and then Plugins.
- In the section “Install a plugin”, choose “Choose a plugin file”, and select
com.example.hello.tessera-plugin.json. - The app shows the name, the version, the description and the author of the plugin, and below them the permissions that the plugin asks for, each with a checkbox. The person can clear a checkbox to refuse a permission. Leave the permission
uiselected. - Choose “Install and allow”.
The app installs the plugin and turns it on immediately. The message “Hello from my first plugin” appears, and the plugin is listed in Settings › Plugins with the label “On”.
The list entry of the plugin has a “Diagnostics” section, which shows the log of the plugin. It contains the line The plugin has started. The section also counts the calls of the plugin and the errors that it raised.
See what a missing permission does
Section titled “See what a missing permission does”Open manifest.json, change "permissions": ["ui"] to "permissions": [], pack the folder again, and install the new file, following the steps of the next section. The message no longer appears, because ctx.ui.notice requires the permission ui. The call throws an error named PermissionDenied, and the diagnostics of the plugin record it.
Installing a changed version
Section titled “Installing a changed version”The app refuses to install a plugin whose id is already installed. After each change to the code or to the manifest, the steps are therefore:
- Run
npm run pack -- plugins/helloagain. - In Settings › Plugins, choose “Uninstall” on the entry of the plugin, and confirm. The data that the plugin left in the outlines stays until the person discards it.
- Install the new file, as described above.
Part 2: a plugin that refuses a change
Section titled “Part 2: a plugin that refuses a change”The second plugin uses a hook, which is a function that the app calls when a change is about to happen. Create the folder plugins/protect-tagged, with the following files.
plugins/protect-tagged/manifest.json:
{ "id": "com.example.protect-tagged", "name": "Protect #keep", "version": "1.0.0", "minCoreVersion": "1.0.0", "description": "Rows tagged #keep cannot be deleted.", "author": "Your name", "permissions": ["read"], "platforms": ["web", "ios"], "entry": "index.ts"}plugins/protect-tagged/index.ts:
import { allow, definePlugin, veto, type PluginContext } from '@tessera/plugin-sdk';
export default definePlugin({ onload(ctx: PluginContext) { const tagsOf = ctx.facets.core.tags.tags;
ctx.hooks.shouldDelete({ on: 'row', onTimeout: 'veto' }, delta => { if (delta.kind !== 'deleted') return allow();
const facets = (delta.value as { facets?: Record<string, unknown> }).facets ?? {}; const tags = [...(tagsOf.of({ facets }) ?? [])];
return tags.some(tag => tag.toLowerCase() === 'keep') ? veto('protected', 'Tagged #keep: it cannot be deleted') : allow(); }); },});The hook runs each time a row is about to be deleted. It reads the tags of the row. When one of them is keep, it answers veto, with a code and a message that the person reads, and the app refuses the deletion. Otherwise it answers allow. The option onTimeout: 'veto' makes the app refuse the deletion when the hook itself fails, so that an error in the plugin never causes a protected row to be deleted. Registering a hook requires the read permission.
Pack the folder, and install the file in the same way as in the first part:
npm run pack -- plugins/protect-taggedTo try it, add the tag #keep to a row, and then delete the row. The app refuses the deletion, and the row stays.
Testing a plugin without the app
Section titled “Testing a plugin without the app”The tool that runs a plugin inside the real core from a test, without starting the app, is part of the app’s repository. The page Testing a plugin describes it and explains what to do without it.
Where to go next
Section titled “Where to go next”- The ctx object lists everything that a plugin can do, with the permission that each part requires.
- Examples presents ten complete plugins.
- How a change goes through explains the steps that a change takes, and where a hook can take part.
