# Plugin development reference [Development](development.md) · [Install and manage plugins](plugins.md) · [Plugin host internals](plugin-host.md) This reference gives the package contract, the build procedure, and the API for RuneStone plugin authors. - [Package contract](#package-contract) - [Build and package a plugin](#build-and-package-a-plugin) - [Build examples](#build-examples) - [Versions and releases](#versions-and-releases) - [Plugin API](#plugin-api) - [Git API](#git-api) - [Background API](#background-api) ## 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 interface types are in `src/lib/plugins/sdk.ts`. ```json { "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 ```text 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 [output-folder]`. 3. Install the ZIP in RuneStone through [Settings → Plug-ins](plugins.md#install-a-plugin). 4. Test the plugin features, then test Disable and Uninstall. From another repository, run `node /scripts/packagePlugin.mjs [output-folder]`. The packager needs Node.js 24 or later. The packager (`scripts/packagePlugin.mjs`) does these steps: - It applies the [package contract](#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 `-.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](development.md#run-from-source). ### Example: Table Formulas Source: [Table Formulas repository](https://git.knottywyvern.com/kwyvern/RuneStone_TableFormulas) and the host script `scripts/buildPlugins.mjs`. | Item | Value | | --- | --- | | Prerequisites | Node.js 24, pnpm 10, and the RuneStone source setup. A Table Formulas checkout in `RuneStone_Table_Formulas` beside the RuneStone folder, with `pnpm install --frozen-lockfile` complete. | | Working folder | The RuneStone repository root | | Command | `pnpm build:plugins` | | Output | `/releases/runestone.table-formulas-.zip` | The `build:plugins` script builds only Table Formulas. It runs the plugin's `scripts/build.mjs`, which compiles without a type check. It copies the compiled files to `plugin-packages/table-formulas/` in RuneStone. Host tests read that folder. Set `RUNESTONE_TABLE_FORMULAS_ROOT` when the Table Formulas checkout is in a different location. The plugin also has its own command. In the Table Formulas folder, `pnpm package:plugin` runs the type check, the build, and the RuneStone packager. It finds the packager in `../RuneStone`. Set `RUNESTONE_ROOT` when the RuneStone checkout is in a different location. ### Example: Terminal Source: [Terminal repository](https://git.knottywyvern.com/kwyvern/RuneStone_Terminal), its `package.json`, and its `scripts/build.mjs`. | Item | Value | | --- | --- | | Prerequisites | Node.js 24 and pnpm 10. Run `pnpm install --frozen-lockfile` in the Terminal folder. | | Working folder | The Terminal repository root | | Command | `pnpm build` | | Output | `releases/runestone.terminal-.zip` in the Terminal folder | The build compiles the Svelte interface and its dependencies into `dist/` (`main.js`, `style.css`, `plugin.json`, and `README.md`). Then it makes the ZIP. The build stops when the versions in `package.json` and `plugin.json` are different. To compile into `dist/` without a ZIP, run `node scripts/build.mjs --no-package`. RuneStone supplies the native terminal sessions. The plugin supplies the interface, shortcuts, and session controls. For use of the terminal, see the [Terminal guide](guides/terminal.md). ### 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 | `/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](releases.md#versions). To publish a plugin ZIP, see [Publish a plugin release](releases.md#publish-a-plugin-release). For the release format that Gitea-link installation accepts, see [Gitea downloads](plugin-host.md#gitea-downloads). ## Plugin API The entry module exports `activate(api)`. Activation can return a cleanup function, or a promise for one. ```js 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. ```js 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. ### 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, views, and background frames 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](#contributions). | | `registerCommand(command)` | | Add a command. See [Commands](#commands). | | `registerView(view)` | | Add a view. See [Views](#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](#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](#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](#menus). | | `completion` | yes | Autocomplete fields and providers. See the [completion API](completion.md). | | `git` | yes | Git operations for the active workspace. See [Git API](#git-api). | | `backgrounds` | yes | Background image frames. See [Background API](#background-api). | ### Commands ```js 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. A name from `src/lib/ui/actionIcons.ts`, 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](#navigation-buttons). | | `icon` | `list`, `kanban`, `puzzle` (default), `globe`, or `git`. | | `settings` | `true` makes the view a configuration page in Settings. See [Settings pages](#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()`. Example: [Project Management](https://git.knottywyvern.com/kwyvern/RuneStone_PM/src/branch/main/development.md#workspace-default-board) uses `launch()` to open the default board of the workspace. ### 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 type is `ActionMenuItem` in `src/lib/ui/actionMenu.ts`. 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](ui-design.md). ### 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 a plugin or the host changes workspace files. 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 types are in `src/lib/plugins/contracts.ts`. Only one enabled plugin can own each key. The host removes contributions before cleanup starts. | Key | Purpose | Owner | | --- | --- | --- | | `terminal` | Mounts terminal controls in a host element. Returns update, command, and dispose functions. | Terminal plugin | | `tableFormulas` | Evaluates and renders formulas in Markdown tables. | Table Formulas plugin | | `git` | Supplies line blame for the editor. | Git plugin | | `browser` | The built-in browser. | RuneStone | A terminal contribution must stop its controls and native sessions before its cleanup finishes. ## Git API `api.git` gives Git operations for the active workspace of the window. The host runs the `git` command, one operation at a time. The types are in `src/lib/git/contracts.ts`. Every method checks for plugin shutdown first. | Method | Contract | | --- | --- | | `status()` | Returns `{ available, repository, branch, changes }`. Each change has `path`, `originalPath?`, `index`, and `worktree`. | | `diff(path, staged)` | Returns the diff text of one file. | | `stage(paths)` / `unstage(paths)` | Change the index for 1 to 10,000 paths. | | `commit(message)` | Commit the staged changes. The message has 1 to 65,536 bytes. | | `push()` / `pull()` | Push or pull the current branch. | | `graph()` | Returns `{ commits }` with at most 100 commits from all refs. | | `commitDetails(commit)` | Returns `{ id, parents, author, date, message, files }` for a full commit ID. | | `commitDiff(commit, path)` | Returns the diff of one file in a commit, compared to the first parent. | | `blame(path, line)` | Returns `{ commit, author, date, summary }` for one line, or `null`. `date` is ISO 8601. | Each graph commit is `{ id, parents, refs, summary, author, date }`. Parent IDs can refer to commits outside the 100 returned commits. Older hosts can have `git` without `push`, `pull`, `graph`, `commitDetails`, or `commitDiff`. Make sure that a method exists before you call it. Example: the [Git plugin](https://git.knottywyvern.com/kwyvern/RuneStone_Git/src/branch/main/docs/usage.md#commit-graph) draws the graph from these commits. For its native service and test setup, see the [Git plugin development guide](https://git.knottywyvern.com/kwyvern/RuneStone_Git/src/branch/main/docs/development.md). ## Background API `api.backgrounds` (`version: 1`) lets a plugin show image frames behind the RuneStone interface. Frames stay in the current window and do not change the saved appearance settings. | Method | Optional | Contract | | --- | --- | --- | | `chooseFolder()` | | Open the folder picker. Returns an absolute path, or `null` on cancel. | | `defaultFolder()` | yes | Create `RuneStone Backgrounds` in the Pictures folder of the user and return its path. | | `list(folder)` | | Return `{ name }` for PNG, JPEG, GIF, and WebP files directly in the folder. | | `read(folder, name)` | | Read one image as bytes, at most 50 MiB. | | `readImageSettings(folder)` | yes | Read the per-image settings file text, or `null`. | | `writeImageSettings(folder, contents, expected)` | yes | Save the per-image settings file. See [Per-image settings](#per-image-settings). | | `set(target, frame)` | | Show a frame for a target. `null` removes the frame of this plugin. | | `get(target)` | | Return the active frame for a target, or `null`. | | `subscribe(listener)` | | Receive the target name when a frame changes. Returns a cleanup function. | Folders must be absolute paths without `..` segments. The host rejects links, files with other extensions, files that are not raster images, and files over the size limit. File access needs an enabled plugin in the current window. Pending reads fail after the plugin stops. ### Targets and frames | Target | Use | | --- | --- | | `app` | The host shows this frame behind the app. | | `pm-all` | Read by Project Management for all boards. | | `pm-board:` | Read by Project Management for one board. | | Frame field | Rule | | --- | --- | | `url` | Required `blob:` URL. | | `blurredUrl` | Optional `blob:` URL for a blurred layer. Each target scales it separately from the foreground. | | `overlay` | From -1 to 1. Negative values make the image lighter. Positive values make it darker. | | `position` | `center`, `top left`, `top`, `top right`, `left`, `right`, `bottom left`, `bottom`, or `bottom right`. | | `size` | `cover`, `contain`, or `auto`. | | `previous` | Optional earlier frame with the same fields, without `previous` or `transitionMs`. | | `transitionMs` | Optional fade time from 0 to 5,000 milliseconds. | The host fades from `previous` to the new frame, unless the user turns on reduced motion. The plugin owns all frame URLs. Keep them valid until a new frame replaces them or the plugin stops, then release them. When more than one plugin sets a frame for a target, the most recent frame is shown. When it is removed, the host shows the earlier frame or the saved background. Disable removes the frames and subscriptions of the plugin before cleanup. To share saved configuration across windows, use the plugin settings API. Example: [Background Slideshow](https://git.knottywyvern.com/kwyvern/RuneStone_BG_Slideshow/src/branch/main/docs/development.md#integration) sets frames from local image folders. Example: [Project Management](https://git.knottywyvern.com/kwyvern/RuneStone_PM/src/branch/main/development.md#pm-0229-slideshow-backgrounds) reads frames for board backgrounds. ### Per-image settings The per-image settings file is `.runestone-backgrounds.json` in the image folder. It must be JSON with `"schema": 1` and an `images` object, at most 1 MiB. `writeImageSettings` 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. Example: the [Background Slideshow image settings](https://git.knottywyvern.com/kwyvern/RuneStone_BG_Slideshow/src/branch/main/docs/development.md#per-image-settings) give the storage format and the rendering behavior.