Add the versioned plugin SDK package and its release script

The new package packages/plugin-sdk (@runestone/plugin-sdk) is the one source of the public plugin types.
It contains PluginApi and its members, the manifest type, API_VERSION, and feature checks
(hasFeature, requireFeature, requireFeatures, missingFeatures). It also contains the action icons and
the tooltip helper as DOM functions, because RuneStone has no API for them. Menus stay host-drawn through
api.ui.showActionMenu, so the SDK contains only the menu types. The SDK uses the Apache License 2.0.

The host imports the SDK with relative paths in src/lib/plugins/sdk.ts, src/lib/ui/actionIcons.ts, and
src/lib/ui/tooltip.ts. The completion, Git, background, and contribution contract files export the SDK types.
The menu files keep their types, because the Terminal plugin keeps copies of them. A unit test makes sure
that those types and the SDK types are the same. The menu inventory now scans the SDK source.

pnpm sdk:build compiles the SDK to dist/. pnpm release:sdk --version <v> builds it, then commits and tags
v<v> in a local clone of the public repository. It never pushes, and it prints the push commands.
It stops before a change in these conditions:
- The clone is missing, has changes, or is not on a branch.
- The tag exists, or the version is not greater than the current version.
- The package has no LICENSE file, or the SDK source has changes that are not committed.
A failed attempt restores the version and the clone.

pnpm check type checks the SDK and the example plugin. The example plugin now has JSDoc types from the SDK.
pnpm test covers the feature checks, the host and SDK parity, and the release script with temporary
Git repositories. The plugin development, release, development, and completion guides describe the SDK.
This commit is contained in:
Knotty Wyvern
2026-10-28 02:33:16 -07:00
parent 9591c251e9
commit bb0b8f88b6
37 changed files with 1710 additions and 438 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
`api.completion` (`version: 1`) lets plugins show autocomplete in RuneStone editors and in their own text fields, and supply the suggestions.
`api.completion` is optional. Older hosts do not have it, and `transport` can be absent. Make sure that a member exists before you call it.
The types are in `src/lib/completion/contracts.ts`.
The SDK type is `CompletionApi`. See [Install the SDK](plugin-development.md#install-the-sdk).
| Member | Contract |
| --- | --- |
+20 -2
View File
@@ -85,7 +85,7 @@ A new command needs an entry in `generate_handler!` in `lib.rs`, in the command
| `formulas/` | Table formulas: the parser and evaluator (`engine.ts`), the rendered results, the formula help, and the `tableFormulas` setting (`index.ts`) |
| `workspace/` | Tauri wrappers, document buffers, the note index and backlinks, paths, templates, and tab transfer (`tabTransfer.ts`) |
| `settings/` | The settings store (`store.ts`), and the code that moves the old browser values to the settings file (`migration.ts`) |
| `plugins/` | The plugin runtime, the SDK types (`sdk.ts`), and Settings → Plug-ins |
| `plugins/` | The plugin runtime, the host types (`sdk.ts`, which also exports the SDK types), and Settings → Plug-ins |
| `browser/` | The interface of the built-in browser |
| `completion/`, `git/` | Contracts and services that plugins use |
| `theme/` | Appearance settings, palettes, and the theme tokens (`tokens.css`) |
@@ -97,6 +97,7 @@ A new command needs an entry in `generate_handler!` in `lib.rs`, in the command
| Folder | Content |
| --- | --- |
| `browser-runtime/` | The browser engine, its tests, filter lists, and third-party notices |
| `packages/plugin-sdk/` | The plugin SDK `@runestone/plugin-sdk`. See [Plugin SDK](#plugin-sdk). |
| `tests/unit/<area>/` | Unit tests (`*.spec.ts`) that run in Node |
| `tests/smoke/<area>/` | Browser smoke tests (`*.smoke.mjs`) and their shared harness in `_harness/` |
| `tests/native/` | Tests that attach to a running desktop app |
@@ -169,7 +170,7 @@ Run these commands from the repository folder. They do not need an installer.
| Command | Checks |
| --- | --- |
| `pnpm check` | Svelte and TypeScript types of the app, then of the unit tests (`tests/tsconfig.json`) |
| `pnpm check` | Svelte and TypeScript types of the app, the unit tests (`tests/tsconfig.json`), the plugin SDK, and the example plugin |
| `pnpm test` | Unit tests in `tests/unit/` |
| `cargo test --manifest-path src-tauri/Cargo.toml --lib` | Rust unit tests |
| `pnpm smoke` | Browser smoke tests. See [Browser smoke tests](#browser-smoke-tests). |
@@ -184,6 +185,23 @@ Some tests need files from outside this repository. Without those files, the tes
- `tests/unit/release/installerVersion.spec.ts` needs the NSIS compiler that the Tauri CLI downloads on Windows.
- The Rust terminal tests start the real shells on the computer.
## Plugin SDK
The plugin SDK in `packages/plugin-sdk/` is the only source of the public plugin types.
The host imports it with relative paths in `src/lib/plugins/sdk.ts`, `src/lib/ui/actionIcons.ts`, and `src/lib/ui/tooltip.ts`.
Change a public type in the SDK, not in the host. Keep host-only types, such as the native transports, in `src/lib/plugins/sdk.ts`.
The menu types in `src/lib/ui/actionMenu.ts` and `src/lib/ui/managedActionMenu.ts` are the exception. The Terminal plugin keeps copies of these two files, and `pnpm check:menus` compares them.
`tests/unit/sdk/features.spec.ts` makes sure that their types and the SDK menu types are the same.
The SDK source must not import host files. It must use only TypeScript syntax that Node.js can remove, because the unit tests load it directly.
| Command | Result |
| --- | --- |
| `pnpm sdk:build` | Compiles the SDK into `packages/plugin-sdk/dist/` with declaration files. The folder is outside Git. |
| `pnpm release:sdk --version <version> [--dry-run]` | Builds the SDK, then commits and tags it in a local clone of the public repository. See [SDK releases](releases.md#sdk-releases). |
`pnpm check` type checks the SDK with `packages/plugin-sdk/tsconfig.json` and the example plugin with `fixtures/plugins/tsconfig.json`.
`pnpm test` runs the SDK tests in `tests/unit/sdk/` and the release script tests in `tests/unit/release/releaseSdk.spec.ts`.
## Browser smoke tests
Smoke tests run the real interface in headless Chromium with a mock of the desktop host.
+1 -1
View File
@@ -145,7 +145,7 @@
"design": "Shared action menu",
"check": "tests/smoke/menus/consistency.smoke.mjs"
},
"RuneStone/src/lib/plugins/sdk.ts": {
"RuneStone/packages/plugin-sdk/src/api.ts": {
"counts": {
"action": 1
},
+42 -8
View File
@@ -4,6 +4,7 @@
This reference gives the package contract, the build procedure, and the API for RuneStone plugin authors.
- [Install the SDK](#install-the-sdk)
- [Package contract](#package-contract)
- [Build and package a plugin](#build-and-package-a-plugin)
- [Build examples](#build-examples)
@@ -16,11 +17,37 @@ This reference gives the package contract, the build procedure, and the API for
- [Git API](#git-api)
- [Background API](#background-api)
## 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 a release tag of its public repository. The SDK is not on the npm registry.
```sh
pnpm add -D "git+https://git.knottywyvern.com/kwyvern/RuneStone_Plugin_SDK.git#v0.1.0"
```
- The repository is public. The installation needs no access token and no `.npmrc` file.
- Always give a tag. To change the SDK version, change the tag in `package.json`.
- 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](#compatibility) |
| `@runestone/plugin-sdk/icons` | `actionIcons` and `actionIcon(name)`. See [Commands](#commands). |
| `@runestone/plugin-sdk/tooltip` | `attachTooltip(element, label)`, the tooltip of RuneStone controls |
For menus, use `api.ui.showActionMenu`. See [Menus](#menus).
The SDK source is `packages/plugin-sdk/` in this repository. For its versions and releases, see [SDK releases](releases.md#sdk-releases).
The [SDK README](../packages/plugin-sdk/README.md) 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 interface types are in `src/lib/plugins/sdk.ts`.
The manifest type is `PluginManifest` in the [SDK](#install-the-sdk).
```json
{
@@ -184,11 +211,18 @@ export function activate(api) {
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.
```js
if (!api.workspace.readBytes) throw new Error("Update RuneStone to use this plugin.");
```ts
import { hasFeature, requireFeature, requireFeatures } from "@runestone/plugin-sdk";
requireFeatures(api, ["pty", "workspace.readBytes"]);
const pty = requireFeature(api, "pty");
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.
### Activation and cleanup
@@ -248,7 +282,7 @@ api.registerCommand({ id: "next", title: "Next image", icon: "skip-forward", run
| `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. |
| `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.
@@ -298,7 +332,7 @@ RuneStone translates only its own interface. It does not translate plugin text o
### 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`.
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](ui-design.md).
@@ -347,7 +381,7 @@ In `readMany`, one failed file does not stop the other reads. More than 64 paths
### Contributions
`contribute(key, value)` registers a host feature. The types are in `src/lib/plugins/contracts.ts`.
`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 |
@@ -382,7 +416,7 @@ Their test scripts replace `window.__TAURI_INTERNALS__` with a test double. That
## Terminal API
`api.pty` (`version: 1`) starts shells in pseudo terminals. The types are `PtyApi` and `PtySession` in `src/lib/plugins/sdk.ts`.
`api.pty` (`version: 1`) starts shells in pseudo terminals. The SDK types are `PtyApi` and `PtySession`.
| Member | Contract |
| --- | --- |
@@ -447,7 +481,7 @@ Make the data of a service a documented contract of the provider. Give its name,
## 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.
The SDK type is `GitApi`. Every method checks for plugin shutdown first.
| Method | Contract |
| --- | --- |
+51
View File
@@ -30,6 +30,7 @@ Development servers, test runs, and intermediate compilation output are not buil
| --- | --- |
| RuneStone | `package.json`, `src-tauri/tauri.conf.json`, the package version and `[package.metadata.runestone]` in `src-tauri/Cargo.toml`, and the `runestone` entry in `src-tauri/Cargo.lock` |
| Plugin | `plugin.json`, the project `package.json`, and any build metadata |
| Plugin SDK | `packages/plugin-sdk/package.json`. See [SDK releases](#sdk-releases). |
On Windows, `pnpm build:installer --version <version>` sets the RuneStone fields when the installer is complete. If the build fails, the fields keep the previous version.
See [Build the Windows installer](builds.md#build-the-windows-installer).
@@ -147,3 +148,53 @@ Gitea link installation needs these conditions:
For download limits, credential handling, and redirects, see [Gitea downloads](plugin-host.md#gitea-downloads).
For GitHub publication steps, see [GitHub's release instructions](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository).
## SDK releases
The plugin SDK `@runestone/plugin-sdk` has its own version, in `packages/plugin-sdk/package.json`. The first release is `0.1.0`.
The [version rules](#versions) and the [hotfix rules](#hotfix-versions) apply.
An SDK release is a commit and a tag in the public SDK repository. It is not a ZIP or an installer.
`pnpm sdk:build` output in `packages/plugin-sdk/dist/` is compilation output, not a release.
The source stays in this repository. The public repository is [RuneStone_Plugin_SDK](https://git.knottywyvern.com/kwyvern/RuneStone_Plugin_SDK).
It holds only the released files: `dist/`, `package.json`, `README.md`, `LICENSE`, and `NOTICE`.
Plugin authors install the SDK from a tag of that repository. See [Install the SDK](plugin-development.md#install-the-sdk).
### Prepare the clone
Do these steps one time.
1. On the Gitea server, create the public repository `kwyvern/RuneStone_Plugin_SDK`. It can be empty.
2. Clone it beside the RuneStone repository, as `RuneStone_Plugin_SDK`.
For a different folder, set `RUNESTONE_SDK_REPO` to the clone.
Without that variable, the script uses `RuneStone_Plugin_SDK` in the `RUNESTONE_PLUGIN_REPOS` folder, or else in the parent folder of RuneStone.
3. Set the Git user name and email in the clone, if your global Git configuration does not have them.
### Release the SDK
1. Commit the SDK changes in RuneStone. Run `pnpm check` and `pnpm test`.
2. In the clone, get the latest commits and tags: `git pull --tags`.
3. Run `pnpm release:sdk --version <version> --dry-run`. Read the plan.
4. Run `pnpm release:sdk --version <version>`.
5. Run the push commands that the script prints. The script never pushes.
6. In RuneStone, commit the new version in `packages/plugin-sdk/package.json`.
7. Install the tag in a plugin project, build the plugin, and test it in RuneStone.
The script builds the SDK, then replaces the released files in the clone. It commits them with the RuneStone commit in the message.
Then it creates the annotated tag `v<version>`.
The new version goes into `packages/plugin-sdk/package.json` only after the tag exists.
If a step fails, the script restores that version field. It also resets the clone to its commit before the attempt.
The script stops before it changes a file in these conditions:
| Condition | Action |
| --- | --- |
| The version is not greater than the version in `packages/plugin-sdk/package.json` or in the clone | Give a greater version. |
| `packages/plugin-sdk/` has no `LICENSE` or `README.md` file | Add the file. The SDK uses the Apache License 2.0. |
| `packages/plugin-sdk/` has changes that are not committed | Commit them, so that the release has a source commit. |
| The clone is missing or is not the root of a Git repository | Clone the public repository, or set `RUNESTONE_SDK_REPO`. |
| The clone has changes, or it is not on a branch | Commit or remove the changes. Check out the release branch. |
| The tag `v<version>` exists in the clone | Give a new version. Never move or replace a published tag. |
The tag is the release. Do not attach files to a repository release for the SDK, and do not put SDK files in `releases/`.
To move the SDK to another service, or to mirror it, push the same commits and tags. Plugin authors then change only the repository URL.