Files
RuneStone/docs/plugin-development.md
2026-11-16 04:21:21 -07:00

28 KiB

Plugin development reference

Development · Install and manage plugins · Plugin host internals

This reference gives the package contract, the build procedure, and the API for RuneStone plugin authors.

Install the SDK

The plugin SDK @runestone/plugin-sdk gives the API types, the feature checks, and the RuneStone icons and tooltip. Install it in each plugin project from the URL of its package file on the RuneStone releases page.

pnpm add -D "https://github.com/KnottyWyvern-GH/RuneStone/releases/download/plugin-sdk-v0.1.2/runestone-plugin-sdk-0.1.2.tgz"
  • Always give the full URL. The SDK is not on the npm registry, and another account owns the @runestone scope there.
  • npm accepts the same URL. The installation needs no access token and no .npmrc file.
  • To change the SDK version, change the version in both parts of the URL: the tag and the file name.
  • Bundle the SDK helpers into the entry module. A type-only import adds no code.
  • Do not copy RuneStone source files into a plugin, and do not import them from a RuneStone checkout. Use the SDK types and the host APIs.
SDK import Contents
@runestone/plugin-sdk PluginApi and its members, PluginManifest, API_VERSION, and the feature checks
@runestone/plugin-sdk/icons actionIcons and actionIcon(name). See Commands.
@runestone/plugin-sdk/tooltip attachTooltip(element, label), the tooltip of RuneStone controls

For menus, use api.ui.showActionMenu. See Menus. The SDK source is packages/plugin-sdk/ in this repository. For its versions and releases, see SDK releases. The SDK README has a minimal plugin in TypeScript.

Example: fixtures/plugins/workspace-overview/main.js uses JSDoc types from the SDK and needs no compile step. pnpm check checks it with fixtures/plugins/tsconfig.json.

Package contract

A plugin is one standard .zip file with plugin.json at the archive root. All plugins use the same package format and the same install, enable, disable, and removal lifecycle. The manifest type is PluginManifest in the SDK.

{
  "schemaVersion": 1,
  "id": "org.example.hello",
  "name": "Hello",
  "author": "Example author",
  "description": "Open a small example view.",
  "version": "1.0.0",
  "apiVersion": 1,
  "entry": "main.js",
  "access": "full-app"
}
Field Rule
schemaVersion Must be 1.
id Lowercase letters, digits, dots, and hyphens. Starts with a letter. At most 120 characters. Cannot end with a dot.
name, author, description Required text, at most 1,000 bytes each.
version Three numeric parts with an optional lowercase letter suffix, such as 1.0.0 or 0.2.28a.
apiVersion Must be 1.
entry Path of a compiled .js or .mjs module in the package.
access Must be "full-app".

The host rejects any other manifest field. The runestone.* ID prefix follows the same rules as other IDs. An ID does not prove the identity of the publisher.

Paths and limits

Package paths use ASCII letters, digits, dots, underscores, and hyphens, with / between folders. Each path segment has at most 120 characters, and the full path has at most 180 characters. The host rejects Windows device names, . and .. segments, and segments that end with a dot. It also rejects absolute paths, links, junctions, and paths that differ only in letter case.

Limit Value
Entries in the package 5,000
Expanded data 100 MiB
One file 25 MiB
Compressed ZIP 100 MiB
plugin.json 64 KiB
Installed path (application data folder, plugin ID, and package path) 240 characters

Entry module

The entry is one compiled JavaScript module. Bundle all dependencies into it. The host loads the module from a Blob URL, so relative imports do not resolve. Read packaged files with api.assets.read. The host does not accept raw TypeScript, Svelte source, native libraries, dependencies on other plugins, or automatic updates.

Package files

org.example.hello-1.0.0.zip
  plugin.json
  main.js
  assets/
  README.md
  LICENSE

The manifest and the entry module are required. Assets, a README, and a license are optional. In the README, give the RuneStone version that the plugin needs, its purpose, the install steps, and a help contact. Keep JavaScript readable. Do not minify or obfuscate code in a way that makes inspection difficult.

Build and package a plugin

Use this procedure for every plugin. Each plugin project defines its own compile step.

  1. Compile the plugin into a clean folder that contains plugin.json, the entry module, and the assets that it needs.
  2. From the RuneStone repository, run pnpm package:plugin <compiled-folder> [output-folder].
  3. Install the ZIP in RuneStone through Settings → Plug-ins.
  4. Test the plugin features, then test Disable and Uninstall.

From another repository, run node <RuneStone>/scripts/packagePlugin.mjs <compiled-folder> [output-folder]. The packager needs Node.js 24 or later.

The packager (scripts/packagePlugin.mjs) does these steps:

  • It applies the package contract checks to the manifest, paths, entry module, and limits.
  • It adds every file in the compiled folder. Keep dependencies, credentials, and unrelated build files out of that folder.
  • It writes <id>-<version>.zip. Without an output folder, it uses releases/ in the nearest parent folder that contains a package.json file.
  • It stops when the output folder is inside the compiled folder.
  • It writes the same bytes for the same input. It uses sorted paths, fixed timestamps, and DEFLATE compression.
  • It keeps an existing ZIP with identical contents. It stops when an existing ZIP has different contents. It never overwrites a ZIP.

Keep each completed plugin ZIP in the releases/ folder of its own plugin project, also when the RuneStone repository starts the build. Use an explicit output folder only for checks and staging.

Other build tools can make the same ZIP layout. Do not put a parent folder above plugin.json. The native installer applies the package checks again before installation. In user instructions, do not tell users to load JSON, select a build folder, rename a release file, or install dependencies.

Build examples

Each example is specific to one plugin. Read the package scripts of a plugin before you build it. For the RuneStone source setup, see Run from source.

Example: CSV Viewer

Source: the CSV Viewer repository, a private repository: its package.json, plugin.json, scripts/build.mjs, and README.md.

Item Value
Prerequisites Node.js 24 or later and pnpm. Run pnpm install --frozen-lockfile in the CSV Viewer folder. Put the RuneStone source checkout beside it, in a folder with the name RuneStone. The source imports shared interface files from ../../RuneStone/src/lib/ui/.
Working folder The CSV Viewer repository root
Command pnpm build
Output releases/runestone.csv-viewer-<version>.zip in the CSV Viewer folder. <version> is the version of plugin.json, for example 0.1.3.

The build compiles src/index.js with esbuild into a readable dist/main.js. It copies plugin.json and README.md into dist/ and writes dist/build.json. Then it runs scripts/packagePlugin.mjs of the RuneStone checkout on dist/. Set RUNESTONE_ROOT to use another RuneStone checkout for this step. The build stops when the versions in package.json and plugin.json are different. It also stops when the release ZIP of the version exists. Set the next version in both files first. To compile into dist/ without a ZIP, run pnpm compile.

Example: Workspace overview

Source: fixtures/plugins/workspace-overview/ in this repository. It contains plugin.json and a main.js that needs no compile step.

Item Value
Prerequisites Node.js 24 and the RuneStone source setup
Working folder The RuneStone repository root
Command pnpm package:plugin fixtures/plugins/workspace-overview <output-folder>
Output <output-folder>/org.runestone-example.workspace-overview-1.0.0.zip

Use an output folder outside the repository. Without one, the ZIP goes into the RuneStone releases/ folder, which is for installers. After you install and enable the ZIP, open Plug-in views → Workspace overview, or run Commands → Show workspace overview.

Versions and releases

For version numbers and hotfix suffixes, see Versions. To publish a plugin ZIP, see Publish a plugin release. For the release format that Gitea-link installation accepts, see Gitea downloads.

Plugin API

The entry module exports activate(api). Activation can return a cleanup function, or a promise for one.

export function activate(api) {
  api.registerView({
    id: "hello",
    title: "Hello",
    mount(container) {
      const text = document.createElement("p");
      text.textContent = "Hello from a RuneStone plugin.";
      container.append(text);
      return () => text.remove();
    }
  });
  api.registerCommand({
    id: "show-hello",
    title: "Show hello",
    run: () => api.openView("hello")
  });
}

Compatibility

Members marked optional can be absent on older RuneStone hosts. Before you call an optional member, make sure that it exists. If the plugin cannot work without it, show an error that tells the user to update RuneStone. The SDK feature checks do this. Their error names each missing feature and tells the user to update RuneStone.

import { hasFeature, requireFeature, requireFeatures } from "@runestone/plugin-sdk";

requireFeatures(api, ["files", "workspace.readBytes"]);
const files = requireFeature(api, "files");
if (hasFeature(api, "settings.subscribe")) watchSettings();

Without the SDK, examine the member directly: if (!api.workspace.readBytes) throw new Error("Update RuneStone to use this plugin.");

Older hosts ignore unknown fields in objects that you pass to the host, such as a view icon or launch handler.

The host has no api.backgrounds. Only the native Background feature shows images behind the interface, and plugins cannot set or read its frames.

Activation and cleanup

  • The host limits activation, each view mount, and each cleanup callback to five seconds. A timeout reports an error. After a cleanup timeout or failure, the user cannot enable or remove the plugin until RuneStone restarts.
  • Plugins activate in every RuneStone window except browser windows.
  • api.signal aborts when shutdown starts. Use it to stop pending work.
  • After shutdown starts, every API call throws an error. Ignore results that arrive after shutdown.
  • On disable, the host removes contributions, commands, and views first. Then it runs view cleanups and onDispose callbacks in reverse order.
  • Remove timers, listeners, and other resources in cleanup. Closing a view and disabling the plugin share the same cleanup promise.
  • Plugins have full application access. The SDK does not isolate plugin JavaScript.

API reference

Member Optional Contract
api.id The installed plugin ID.
api.signal An AbortSignal that aborts when shutdown starts.
onDispose(callback) Register synchronous or asynchronous cleanup.
contribute(key, value) Register a host feature. See Contributions.
registerCommand(command) Add a command. See Commands.
registerView(view) Add a view. See Views.
openView(id, options?) Open a view of this plugin. options is { split: "right" | "down", relativeTo }, where relativeTo is the ID of an open editor view of the same plugin.
closeView(id) yes Close the editor tabs of a view of this plugin.
replaceView(currentId, nextId) yes Show another editor view in the current tab. The tab keeps its position and pin state.
replaceDocumentWithView(document, nextId) yes Show an editor view in place of a document tab of this plugin.
updateViewTitle(id, title) yes Change a view title. At most 200 characters.
updateViewIcon(id, image) yes Set a tab icon from a base64 data:image/... URL (PNG, JPEG, GIF, WebP, ICO, or SVG) of at most 90,000 characters. null removes it.
registerTabDrop(receive) yes Accept a plugin tab that the user drags from another window. One receiver for each plugin.
registerDocumentType(type) Recognize workspace files and open them in a plugin editor. See Document types.
openDocument(path) Open a recognized document in its own tab. Rejects when no enabled plugin recognizes the file.
openFile(path) yes Open a workspace file in the normal RuneStone editor.
renameDocument(document, name) yes Rename a recognized document. Returns the new workspace path.
workspace.* Read and write files in the active workspace. See Workspace files.
settings.read() Read the saved JSON settings of the plugin. Returns null before the first write.
settings.write(value) Save JSON settings, at most 1 MiB.
settings.subscribe(listener) yes Receive a call when the saved settings change in any window. Returns a cleanup function.
assets.read(path) Read a package file as a Uint8Array.
ui.showActionMenu(options) yes Open the shared RuneStone action menu. See Menus.
completion yes Autocomplete fields and providers. See the completion API.
files yes Folders outside the workspace that the user granted to the plugin. See Folder grants.
services yes Data that one plugin offers to other plugins. See Plugin services.

Commands

api.registerCommand({ id: "next", title: "Next image", icon: "skip-forward", run: () => next() });
Field Rule
id Lowercase letters, digits, dots, and hyphens. Starts with a letter. Unique among the commands of the plugin.
title Required text.
run Required function. Can return a promise.
category "action" (default) adds the command to the Commands menu. "open" adds it to the Plug-in views menu.
icon Optional. An ActionIcon name from the SDK, such as play, pause, skip-forward, or refresh, or a view icon name.

Give each command a recognizable icon.

Views

Field Rule
id, title Same rules as for commands. View IDs are unique among the views of the plugin.
mount(container, context?) Required. Draws the view and can return a cleanup function or a promise. context.surface is "view" or "settings".
placement "dialog" (default), "editor" for a tab in the editor area, or "sidebar" for the left pane.
navigation true adds an icon button. See Navigation buttons.
icon list, kanban, puzzle (default), globe, or git.
settings true makes the view a configuration page in Settings. See Settings pages.
launcher false keeps the view out of the Plug-in views menu. Use it for dynamic views that already have tabs.
launch() Optional. Runs instead of openView when the user opens the view from a menu or a navigation button.
pinned Initial pin state of an editor tab.
tabActions({ pinned }) Returns extra ActionMenuItem entries for the tab menu.
find() Runs when the user starts Find in this tab.
tabDragData({ pinned }) Returns a string that moves with the tab to another window. The receiver is registerTabDrop.
saveTabState() / restoreTabState(state) Save and restore view state when an editor tab moves to another window.
toolbar Accepted. In the current host, it only removes the view from the ribbon.

Dialog views open in a modal window. Editor views open as tabs beside documents. Document tabs keep their buffers when the user changes views. Closing an editor tab or disabling the plugin disposes the view.

A launch() handler can select a default target and call api.openView(id). Explicit api.openView calls and restored tabs do not call launch().

Navigation buttons

  • A view with navigation: true and placement: "sidebar" gets a button beside Files, Search, and Bookmarks at the top of the left pane. It opens in the left pane, and the Plug-in views menu does not show it.
  • A view with navigation: true and another placement gets a button in the ribbon at the left edge of the window. The Plug-in views menu also shows it, unless launcher is false.
  • Each button shows the view title as a tooltip on hover and keyboard focus.

Settings pages

Register a view with settings: true to add a configuration page under the plugin name in Settings. The host mounts that view in the Settings window with context.surface set to "settings". The view does not appear in the Plug-in views menu. The Settings window loads enabled plugins, so the page is available there.

To react to a change from another window, call settings.subscribe(listener). Then read the new value with settings.read(). The notification contains no data. Ignore reads that finish after shutdown, and do not let an older read replace newer settings.

RuneStone translates only its own interface. It does not translate plugin text or supply a translation API.

Menus

ui.showActionMenu({ x, y, items, label?, parent? }) opens the shared action menu at a screen position. It returns { close() }. Each item is { label, icon?, shortcut?, run?, children?, disabled?, checked?, radio?, title? } or { separator: true }. The SDK types are ActionMenuItem and ActionMenuOptions. The menu closes on selection, outside click, resize, window blur, scroll, and plugin shutdown. Use this menu instead of a custom menu. See the interface design reference.

Document types

A document type lets a plugin open some workspace files in its own editor.

Field Rule
id, title Same rules as for views. Unique among the document types of the plugin.
extensions Required list of lowercase extensions without the dot, such as ["md"].
identify(path, source) Returns { id } with a stable document ID, or null.
mount(container, { id, path }) Draws the editor. Can return a cleanup function.
icon "file" (default) or "kanban". The file tree shows it.
content "text" (default) or "binary".
create Optional { label, defaultName, extension, contents() }. extension must be in extensions. contents() returns the complete file text.
  • Files that identify rejects, or that cause an error, stay available in the text editor.
  • Each document opens in its own tab. A second open of the same document selects its tab.
  • Closing a tab disposes only that mount. Disabling the plugin disposes all its mounts and removes its file tree icons.
  • Creation never replaces an existing file.
  • For binary types, identify receives an empty source. Identify the file from its path, then read bytes in mount with workspace.readBytes. Show errors about invalid data in the view.

renameDocument({ id, path }, name) renames a document that this plugin recognizes. The host checks the document ID and the owner. It keeps the folder and the extension, rejects name conflicts, and updates open tabs. Names can contain dots. Hidden names and reserved filename characters are invalid.

Workspace files

All paths are relative to the active workspace of the window. The host rejects paths outside the workspace.

Member Optional Contract
list(path?) List one folder. Returns { name, rel_path, kind } entries, where kind is "file" or "folder".
listMarkdown() yes Return all .md, .markdown, and .mdown paths in sorted order, in one request. Skips names that start with a dot, and links.
read(path) Read a UTF-8 text file.
readOptional(path) yes Read a text file, or return null when the file does not exist.
readMany(paths) yes Read at most 64 text files with a total of at most 16 MiB. Returns { path, source } or { path, error } for each path.
readBytes(path) yes Read a file of at most 64 MiB as a Uint8Array.
create(path, contents) yes Create a text file. Fails when the file exists.
write(path, contents, expected) Save the file only if it still contains expected. expected is required.
subscribe(listener) yes Receive a call when workspace files change: from a plugin, the host, another program, or another window. Changes in .runestone/ count too. Returns a cleanup function.

In readMany, one failed file does not stop the other reads. More than 64 paths make the whole call fail. write and renameDocument fail when the file is open in RuneStone with unsaved edits.

Contributions

contribute(key, value) registers a host feature. The SDK type is Contributions. Only one enabled plugin can own each key. The host removes contributions before cleanup starts.

Key Purpose Owner
browser The built-in browser. newTab(url?) opens a browser tab. open(url) returns false when the system browser must open a web link, for example before the engine is installed. RuneStone

Earlier hosts also had api.pty and a terminal key for the Terminal plugin. They are gone, because RuneStone now includes Terminal as a native feature.

Theme tokens

Style plugin views with the host CSS custom properties. The host sets them on the root element for the current theme. Do not hard-code colors, and do not choose colors from a theme ID.

Token Use
--rs-bg The page: document and editor surfaces
--rs-bg-elevated Side panes, menus, cards, and dialogs
--rs-bg-active Hover and pressed fills
--rs-border Dividers and control borders
--rs-text, --rs-text-dim, --rs-text-strong Body text, secondary text, and headings
--rs-accent, --rs-accent-2 Theme identity: active states, indicators, and icons
--rs-link Link and action text
--rs-focus Keyboard focus outlines
--rs-on-accent Text and icons on an accent fill
--rs-selection, --rs-selection-text Text selection. The fill is at most 65% opaque.
--rs-item-selection-bg, --rs-item-selection-border Selected rows, cards, and cells
--rs-highlight Highlighted text
--rs-scrim The backdrop behind a dialog
--rs-error, --rs-warn, --rs-warn-hot, --rs-ok Status. Show an icon or text with each status color.
--rs-special One more distinct color, for example for numbers
--rs-syntax-* Code colors. Functional color lists the roles.
--rs-ansi-black to --rs-ansi-white, --rs-ansi-bright-black to --rs-ansi-bright-white The 16 terminal colors. Each keeps its ANSI hue in every theme.

Interface design lists the size, menu, settings, and tooltip tokens.

The root element also has data-theme (light or dark) and data-palette (the theme ID). Use data-theme for differences between light and dark. The window sends a runestone-theme-changed event after each theme change. A plugin that copies token values, for example into a canvas or a terminal, reads them again on that event.

Use the SDK instead of native calls

Do not call invoke, listen, or other @tauri-apps/api functions from a plugin. Do not read the private files of other plugins. Use the api members of the API reference. They check plugin shutdown, and they will stay available when a later host runs each plugin in its own isolated context. Make sure that an optional member exists before you use it.

The Local Autocomplete and CSV Viewer plugins make no native calls. Their test scripts replace window.__TAURI_INTERNALS__ with a test double. That is test code and does not go into the package.

Folder grants

api.files (version: 1) gives access to folders outside the workspace. The user selects each folder. The plugin cannot supply a path. A grant is { id, path, name }. id is opaque. path and name are for display only.

Member Contract
chooseFolder({ title? }) Opens the folder picker. Returns a grant, or null on cancel. The same folder gives the same grant again.
pictureFolder(name) Creates RuneStone <name> in the Pictures folder of the user if necessary, and returns a grant for it. name has letters, digits, spaces, hyphens, and underscores, at most 64 characters.
grants() Returns the grants of this plugin.
revoke(grant) Removes a grant. Returns false when the plugin has no such grant.
list(grant) Returns { name, size } for the ordinary files directly in the folder. Skips folders and links.
readBytes(grant, name) Reads one file of at most 64 MiB as a Uint8Array.
readSidecar(grant, name) Reads a sidecar file as text, or returns null when it does not exist.
writeSidecar(grant, name, contents, expected) Saves a sidecar file only if it still contains expected. Use null when the file does not exist.

Each plugin has its own grants. The host keeps them with the retained data of the plugin, so they stay after a restart, an update, or a removal. A file name is one name without folder parts. The host rejects .., links, and files that resolve outside the granted folder. When the granted folder is removed or becomes a link, its grant stops working. Ask the user to choose the folder again.

A sidecar is a small JSON file that the plugin keeps beside the files of the user. Its name has the form .runestone-<name>.json, where <name> has letters, digits, hyphens, and underscores. A sidecar holds valid JSON of at most 1 MiB. The host writes no other files in a granted folder.

Store the grant id in the plugin settings. Before you use a saved grant, look for it in grants().

Example: the per-image settings of Background

The per-image settings file of the Background feature is .runestone-backgrounds.json in the image folder. It is JSON with "schema": 1 and an images object, at most 1 MiB. Each key is a file name. Each value can have fit (cover, contain, auto, or blurred), position, and overlay. A plugin with a folder grant can read and write the same file with files.readSidecar and files.writeSidecar. writeSidecar compares the current file to expected (null when the file does not exist). It fails when the file changed, so external edits are not lost. The host checks only that the text is JSON. The plugin checks the schema. Example: src/lib/features/background/imageSettings.ts reads the file and applies it.

Plugin services

api.services (version: 1) lets a plugin offer data to other plugins in the same window. The host passes the calls, so no plugin reads the private files of another plugin.

Member Contract
provide(name, methods) Offers an object of functions under a name. Returns { notify(), dispose() }. One plugin can offer each name once.
get(plugin, name) Returns the methods of a service of another plugin, or null when it is not available.
subscribe(listener) Calls listener(plugin, name) when a service starts, stops, or calls notify(). Returns a cleanup function.

A service name uses lowercase letters, digits, dots, and hyphens, and starts with a letter. Each method call returns a promise. The host copies the arguments and the result with structuredClone. Use only data that this function can copy, not functions or DOM nodes. When the provider stops, the host removes its services and notifies the subscribers. Calls through an old service object then fail. Call get again after a notification. Make the data of a service a documented contract of the provider. Give its name, methods, and result shapes in the documentation of the provider plugin.