Rewrite the documentation and the agent instructions

Move the agent instructions from AGENTS.md to CLAUDE.md. AGENTS.md now
points to CLAUDE.md. The UI rules move to docs/ui-design.md. The version
and release policy moves to the new docs/releases.md.

Rewrite the README, the user guides, and the developer references.
Check each claim against the code. Remove old version history and
repeated warnings. Link to Gitea at git.knottywyvern.com instead of the
LAN address. Move the October 13 menu audit to the archive.
This commit is contained in:
Knotty Wyvern
2026-10-27 19:35:43 -07:00
parent d7a87795f5
commit 4240d7dad1
25 changed files with 2041 additions and 2017 deletions
+330 -340
View File
@@ -1,25 +1,22 @@
# Plugin development reference
[Development](development.md) · [Install and manage plugins](plugins.md)
[Development](development.md) · [Install and manage plugins](plugins.md) · [Plugin host internals](plugin-host.md)
This reference is for authors who develop, package, and release RuneStone plugins.
It covers the shared package contract, build examples, release requirements, and plugin APIs.
For installation internals and host tests, use the [plugin host reference](plugin-host.md).
For installation, updates, switches, and removal, use the [user guide for plugins](plugins.md).
All plugins use the same package and installation system.
This reference gives the package contract, the build procedure, and the API for RuneStone plugin authors.
- [Package contract](#package-contract)
- [Versioning](#versioning-for-plugin-authors-and-agents)
- [Build and release a plugin](#build-and-release-a-plugin)
- [Build and package a plugin](#build-and-package-a-plugin)
- [Build examples](#build-examples)
- [Publishing releases](#publishing-releases)
- [Versions and releases](#versions-and-releases)
- [Plugin API](#plugin-api)
- [Git API](#git-api)
- [Temporary background API](#temporary-background-api)
- [Background API](#background-api)
## Package contract
Place `plugin.json` at the root of the ZIP archive:
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
{
@@ -35,58 +32,42 @@ Place `plugin.json` at the root of the ZIP archive:
}
```
The package API is version 1. Its interface lives in `src/lib/plugins/sdk.ts`.
RuneStone 0.1.5 adds optional `placement: "editor"` for views that belong beside documents.
These views open in the editor area with a tab. Document tabs retain their buffers when users switch views.
Closing the plugin tab or disabling the package disposes the view.
The default placement is `"dialog"`, so existing packages keep their current behavior.
Older hosts ignore the placement field. Plugins that require editor placement need RuneStone 0.1.5 or later.
All packages use one API and the same installation, enable, disable, and removal lifecycle.
Versions use three numeric parts with an optional lowercase hotfix suffix, such as `0.2.28a`.
Schema and API versions must match the supported version exactly.
The `runestone.*` prefix follows the same rules as other package IDs. It does not prove the publisher's identity.
Package names use ASCII letters, digits, dots, underscores, and hyphens, with forward slashes between directories.
IDs use lowercase letters, digits, dots, and hyphens and start with a letter.
Windows device names, parent traversal, absolute paths, links, junctions, and case-insensitive collisions are invalid.
Limits are 5,000 entries, 100 MiB of expanded data, and 25 MiB per file.
The manifest has a 64 KiB limit. The final installed path cannot exceed 240 characters.
The entry is one compiled `.js` or `.mjs` module. Bundle dependencies into it.
Relative module imports cannot resolve from its Blob URL. Read packaged assets through the API instead.
Raw TypeScript, Svelte source, native libraries, plugin dependencies, and automatic updates are unsupported.
## Versioning for plugin authors and agents
Follow the shared [RuneStone versioning policy](../AGENTS.md#versioning). RuneStone and its plugins keep independent version numbers under this policy.
Use `zz.yy.xx` and keep routine implementation work in the current `zz.yy` series.
| Part | When to increase it |
| Field | Rule |
| --- | --- |
| `xx` | Each new completed regular plugin ZIP build. Hotfixes increase the letter suffix. |
| `yy` | A deliberate release ready for build testing, with user direction. Reset `xx` to zero. |
| `zz` | A full release, with user direction. Reset `yy` and `xx` to zero. |
| `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"`. |
Keep the current version during source edits, fixes, improvements, documentation work, and automated checks.
Set the next version when producing the ZIP. Intermediate compilation output does not count as a new build.
If no build completes, restore the previous version fields. Failed attempts and retries do not consume version numbers.
Report a new version as available only after its ZIP exists. Publishing an existing artifact does not increase its version.
Passing automated checks alone does not authorize a `yy` or `zz` increase.
A hotfix fixes one item or a narrowly scoped problem in an existing release.
Use letters in the actual package version: `0.2.28` → `0.2.28a` → `0.2.28b`.
Keep the numeric base for hotfix builds.
Advance hotfix suffixes in this order: `a`, `b`, `c`, through `z`, then `aa`, `ab`, and later suffixes.
The next regular build increases `xx` and removes the suffix: `0.2.28b` → `0.2.29`.
Keep the package version, manifest version, build metadata, ZIP name, release notes, and tag consistent.
For example, package version `0.2.28a` produces `runestone.pm-0.2.28a.zip` and uses tag `v0.2.28a`.
The shared packager and updated native installer accept these suffixes. Older hosts with numeric-only validation reject suffixed packages.
Do not substitute a numeric increment for a hotfix. Add suffix support or report a format blocker before building.
Do not bypass validation or overwrite an existing release ZIP.
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.
## Build and release a plugin
### Paths and limits
Use the same package contract for in-house and community plugins.
The ZIP is the release file. Its `plugin.json` describes the contents and is not a separate installer.
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
@@ -97,166 +78,101 @@ org.example.hello-1.0.0.zip
LICENSE
```
The manifest and entry module are required. Assets, a README, and a license are optional package files.
Include a README with the host requirement, purpose, install steps, and help contact.
Keep JavaScript readable where practical. Avoid minification and obfuscation that make inspection harder.
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.
1. Compile the plugin into a clean folder with `plugin.json`, its entry module, and the required assets.
2. Run `pnpm package:plugin <compiled-folder> [output-folder]` from the RuneStone repository.
3. Install the resulting ZIP in RuneStone and test its features, disable action, and uninstall action.
4. Share that same ZIP through the [publishing procedure](#publishing-releases).
## Build and package a plugin
Use Node.js 24 or later for the packaging command. The default output folder is `releases/` in the project that contains the compiled folder.
Keep plugin release ZIPs in that plugin project, including when the host calls the build.
Explicit output folders are for temporary checks or staging. Move completed releases into the owning project's `releases/` folder.
It checks the manifest, paths, entry module, and size limits before it writes `<id>-<version>.zip`.
It includes every file in the input folder. Keep dependencies, credentials, and unrelated build files outside that folder.
The output folder must be outside the input folder.
The command rejects an existing ZIP with different contents. Identical contents reuse the existing file.
Use the next build version for a changed release and preserve existing ZIPs.
Repeated runs with unchanged input produce the same archive bytes.
The native installer checks the package again before installation.
Use this procedure for every plugin. Each plugin project defines its own compile step.
Other build tools can create the same ZIP layout. Do not add a parent folder above `plugin.json`.
Do not tell users to load JSON, select a build folder, rename a new release, or install dependencies.
Authors in other repositories can run `node <RuneStone-path>/scripts/packagePlugin.mjs <compiled-folder> <output-folder>`.
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](plugins.md#install-a-plugin).
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](#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
These examples are for plugin developers. To install an existing ZIP, use the [plugin installation guide](plugins.md#install-a-plugin).
Complete the [source setup](development.md#run-from-source) before using host build commands.
Each plugin has its own build command. Check that project's package scripts before building it.
Apply the [versioning policy](#versioning-for-plugin-authors-and-agents) before producing a new release ZIP.
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-gitea/RuneStone_TableFormulas).
The host's [build script](../scripts/buildPlugins.mjs) defines this example.
Despite its plural name, `pnpm build:plugins` builds only Table Formulas.
Source: [Table Formulas repository](https://git.knottywyvern.com/kwyvern/RuneStone_TableFormulas) and the host script `scripts/buildPlugins.mjs`.
1. Clone the Table Formulas repository into `RuneStone_Table_Formulas` beside the RuneStone folder.
2. In that plugin folder, run `pnpm install --frozen-lockfile`.
3. In the RuneStone folder, run `pnpm build:plugins`.
4. Install the resulting ZIP through [Settings → Plug-ins](plugins.md#install-a-plugin).
| 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 | `<Table Formulas>/releases/runestone.table-formulas-<version>.zip` |
The ZIP is `../RuneStone_Table_Formulas/releases/runestone.table-formulas-<version>.zip`, relative to RuneStone.
The host stages compiled files in `plugin-packages/table-formulas/` for inspection and tests.
Set `RUNESTONE_TABLE_FORMULAS_ROOT` when the plugin checkout is elsewhere.
The plugin also supports `pnpm package:plugin` from its own folder.
Set `RUNESTONE_ROOT` there if its host checkout is elsewhere.
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-gitea/RuneStone_Terminal).
Its `package.json` and `scripts/build.mjs` define this example.
Source: [Terminal repository](https://git.knottywyvern.com/kwyvern/RuneStone_Terminal), its `package.json`, and its `scripts/build.mjs`.
1. Clone the Terminal repository into `RuneStone_Terminal` beside the RuneStone folder.
2. In that plugin folder, run `pnpm install --frozen-lockfile`.
3. In the same folder, run `pnpm build`.
4. Install the resulting ZIP through [Settings → Plug-ins](plugins.md#install-a-plugin).
| 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-<version>.zip` in the Terminal folder |
The ZIP is `releases/runestone.terminal-<version>.zip`, relative to the Terminal folder.
This build bundles its JavaScript dependencies and terminal styles.
The host supplies native pseudo-terminal services. The plugin supplies the interface, shortcuts, and session controls.
For session controls and appearance, use the [Terminal guide](guides/terminal.md).
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: the [Workspace overview fixture](../fixtures/plugins/workspace-overview/plugin.json) in this repository.
This small example already contains a JavaScript entry module.
Source: `fixtures/plugins/workspace-overview/` in this repository. It contains `plugin.json` and a `main.js` that needs no compile step.
1. From the RuneStone folder, run `pnpm package:plugin fixtures/plugins/workspace-overview`.
2. Install the resulting ZIP from the host's `releases/` folder.
3. Choose **Install and enable**.
4. Choose **Open tab or view → Workspace overview**.
| 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` |
You can also use **Commands → Show workspace overview**.
This fixture belongs to the host. Release ZIPs for separate plugin projects stay in each plugin's own `releases/` folder.
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**.
The RuneStone installer does not include optional plugin packages.
After source changes, build the affected package again and install its new ZIP.
## Versions and releases
## Publishing releases
These requirements apply to RuneStone plugins on any hosting service.
The hosting service stores the release files. RuneStone defines the package format, version policy, and installation checks.
Users can download a plugin ZIP from any service and install it through [Settings → Plug-ins](plugins.md#install-a-plugin).
Installation directly from a repository link depends on RuneStone's support for that service.
### Release standard for plugin writers and agents
Apply the [shared versioning rules](#versioning-for-plugin-authors-and-agents) when producing a new ZIP.
Use one plugin repository and one standard plugin ZIP per published release.
This is a RuneStone release requirement, independent of the hosting service.
No repository manifest or special branch layout is required.
1. Select the tested ZIP from the [shared build procedure](#build-and-release-a-plugin).
2. Create a release tag that identifies the source commit used for that ZIP.
3. Attach the tested `<id>-<version>.zip` and release notes to a release on your chosen service.
4. Publish the release and share its download page or package link.
5. Download the published ZIP and test its installation in RuneStone.
Use `v<version>` for ordinary release tags. Use a clearly named trial tag for temporary prereleases.
Identify prereleases clearly on the release page and supply their explicit tags.
Keep the manifest, package, metadata, filename, release notes, and tag consistent with the version policy.
Each new regular ZIP advances the numeric build version. Each hotfix ZIP advances the lowercase letter suffix.
Publishing an existing ZIP does not change its version. Keep published release files unchanged.
Moving an unchanged release to another service does not require a new package or version.
The ZIP must contain `plugin.json` at its root, the compiled entry module, and all required assets and dependencies.
Do not use a repository source archive as the plugin package.
Keep the single plugin ZIP separate from any source archives that the service generates automatically.
Other attachments, such as checksums and release notes, can accompany the plugin ZIP.
Keep release notes short. State the required RuneStone version, plugin version, changes, and known limits.
Give users a link to the plugin ZIP and the [ZIP installation procedure](plugins.md#install-a-plugin).
For a private release, users need permission to download the package.
Test local ZIP installation before publication.
After publication, test download, review, disabled installation, enable, disable, and removal with the published ZIP.
Check that cancellation leaves no installed package.
Check that an existing plugin ID enters the reviewed update flow and retains its settings and enabled state.
If RuneStone supports direct installation from that service, also test its repository link and explicit release tag.
### GitHub Releases
Attach the tested plugin ZIP to a GitHub release for its source tag.
GitHub's automatic source archives do not replace the attached plugin package.
See [GitHub's release instructions](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) for publication steps.
Users download the attached ZIP and install it through **Settings → Plug-ins → Install plugin ZIP**.
RuneStone does not yet support installation directly from a GitHub repository link.
That feature requires a GitHub download adapter and tests.
### Gitea releases
Attach the same standard plugin ZIP to a Gitea release for its source tag.
Users can download and install the ZIP, or use RuneStone's [experimental Gitea-link installation](plugins.md#install-from-a-gitea-link-experimental).
For direct installation, use a repository root link with an optional trailing `.git`.
The Gitea server must run at the host root. Use an explicit tag for a prerelease trial.
The latest-release route excludes drafts and prereleases. The downloader rejects drafts and releases without exactly one attached ZIP.
Automatic source archives do not count as release attachments.
Private repositories require read access to both the release metadata and the attachment.
Use HTTPS for remote releases. The metadata limit is 2 MiB, and the compressed ZIP limit is 100 MiB.
The [package limits](#package-contract) also apply to extracted files.
For credential handling, redirects, and staged file checks, see the [host download reference](plugin-host.md#gitea-downloads).
### Other hosting services
Publish the tested plugin ZIP and its release notes through your chosen service.
Users download the ZIP, then use the same local installation procedure.
RuneStone has no direct repository-link adapter for GitLab or other services.
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 current source adds an optional [completion API](completion.md) for local model providers and plugin-owned text fields.
This capability is not present in the existing 0.1.7 installer.
The entry exports `activate(api)`. Activation can return a cleanup function or a promise for that function.
The runtime limits activation and each cleanup callback to five seconds.
A timeout reports an error and blocks successful cleanup until the app restarts.
The entry module exports `activate(api)`. Activation can return a cleanup function, or a promise for one.
```js
export function activate(api) {
@@ -278,181 +194,255 @@ export function activate(api) {
}
```
| API | Contract |
### 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 |
| --- | --- |
| `api.id` | The installed plugin ID |
| `api.signal` | An abort signal triggered before shutdown |
| `contribute(key, value)` | Register a typed terminal or table formula contribution |
| `registerCommand({ id, title, run })` | Add a command to Commands in the toolbar |
| `registerCommand({ category: "open", ... })` | Add a launch action to Open tab or view |
| `registerView({ id, title, placement?, mount })` | Add a view in a dialog or the editor area |
| `registerView({ settings: true, ... })` | Add a configuration page to Settings |
| `registerView({ launcher: false, ... })` | Keep a dynamic view out of the launch menu |
| `registerView({ navigation: true, icon?, ... })` | Add an icon button to the ribbon left of the navigation pane |
| `registerDocumentType(type)` | Recognize document content, supply a navigation icon, and mount a document editor |
| `openDocument(path)` | Open a recognized document in its own tab |
| `renameDocument({ id, path }, name)` | Rename a recognized document and return its new workspace path. Optional API |
| `openView(id)` | Open one of the plugin's registered views |
| `openView(id, { split, relativeTo })` | Open an editor view beside another view. `split` accepts `right` or `down` |
| `closeView(id)` | Close an editor view owned by this plugin. Optional API |
| `registerView({ tabActions, find, pinned, ... })` | Supply tab actions, a Find handler, and the initial pin state |
| `registerView({ tabDragData, ... })` | Supply transfer data for a tab. The callback receives its pin state |
| `registerTabDrop(receive)` | Accept a tab from another window. Optional API |
| `onDispose(callback)` | Register synchronous or asynchronous cleanup |
| `workspace.list(path?)` | List a directory in this window's active workspace |
| `workspace.listMarkdown()` | Return sorted visible Markdown paths in one native request. Optional API |
| `workspace.read(path)` | Read a workspace text file |
| `workspace.readMany(paths)` | Optional batched text read. Accept at most 64 paths and return a source or error for each path |
| `workspace.readBytes(path)` | Read workspace bytes as a Uint8Array, with a 64 MiB limit. Requires the binary document host update |
| `workspace.readOptional(path)` | Read text, or return null when the file is absent. Added in 0.1.6 |
| `workspace.create(path, contents)` | Create complete text without replacing an existing file. Added in 0.1.6 |
| `workspace.write(path, contents, expected)` | Save only if the file still matches the original text |
| `workspace.subscribe(listener)` | Receive workspace change notifications. Returns a cleanup function |
| `settings.read()` / `settings.write(value)` | Read or write retained JSON settings, with a 1 MiB limit |
| `settings.subscribe(listener)` | Receive saved settings changes across windows. Optional API |
| `assets.read(path)` | Read package bytes as a `Uint8Array` |
| `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. |
### Workspace reads
Give each command a recognizable icon.
Check for `workspace.readMany` before calling it. Older hosts require individual reads.
Each result contains `path` and either `source` or `error`. One failed file does not discard the remaining results.
The native batch accepts at most 64 paths and 16 MiB of combined UTF-8 text.
Workspace path checks and plugin shutdown checks apply to these reads.
### Views
### Commands, views, and settings
| 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. |
Command and view IDs must be unique within their respective plugin collections.
Plugin commands can supply an optional `icon` from the shared action icon set in `src/lib/ui/actionIcons.ts`.
Use a recognizable action icon, such as `skip-forward` or `pause`, for each command. Older hosts can ignore this field.
Sidebar views belong in the left navigation. Views with a direct navigation button do not repeat in the plugin launch menu.
Plugin configuration appears in Settings under the plugin name.
Register a view with `settings: true` to add its configuration page.
The host mounts that view inside Settings and removes it from the launch menu.
Settings loads enabled plugins so their configuration pages remain available in the separate settings window.
The host calls `mount(container, context)` with `context.surface` set to `"settings"` or `"view"`.
Older hosts can omit the context argument.
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.
The language setting applies to RuneStone's interface. The host does not translate plugin interfaces or supply a plugin translation API.
Plugin authors can manage translations within their own packages.
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.
The Open tab or view menu contains plugin views and commands with `category: "open"`.
Other commands appear in Commands.
Set `launcher: false` on dynamic views that already have tabs.
Existing packages can omit these optional fields.
### Navigation buttons
Plugins can call `settings.subscribe(listener)` to receive notifications when their saved settings change.
The listener must read the new settings with `settings.read()`.
Notifications cross window boundaries and contain only the plugin ID.
The host removes subscriptions when the plugin stops.
Plugins must ignore pending reads after shutdown and prevent older reads from replacing newer settings.
- 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
Document type IDs must also be unique within their collection.
Document types declare file extensions, an `identify` function, and a `mount` function.
The identify function returns a stable document ID or null. Invalid documents remain available through the text editor.
An optional creation action supplies complete file text. Creation never replaces an existing file.
Each document opens in its own editor tab. Opening the same document focuses its existing tab.
Closing one tab disposes only that mount. Disabling the plugin disposes all its mounts and removes its navigation entries.
The host rejects plugin writes when a note has unsaved editor changes.
These document APIs require the current host source. The earlier 0.1.6 installer does not include them.
The optional API method `renameDocument({ id, path }, name)` renames a recognized document and returns its new workspace path.
The host checks the document ID and plugin owner. It keeps the folder and extension, rejects name collisions, and updates open tabs.
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.
Unsaved text edits block plugin renames. This method requires the updated host source.
Binary document types set `content: "binary"`. Text remains the default.
For binary types, `identify(path, source)` receives an empty source string and recognizes the path without reading its contents.
The mount reads bytes with `workspace.readBytes(path)` and reports invalid document data in its own view.
This avoids UTF-8 conversion and full file reads while the file tree identifies binary documents.
The native read command checks the active window's workspace boundary and rejects directories and files larger than 64 MiB.
Binary document support requires the updated host source. The earlier 0.1.6 installer does not include it.
Check for `api.workspace.readBytes` during activation and report a clear host update error when it is absent.
### Sidebar views and tab replacement
### Workspace files
Navigation views with `placement: "sidebar"` appear beside Files, Search, and Bookmarks in the top header.
Other navigation views appear as icon buttons in the ribbon left of the navigation pane.
The optional view `icon` accepts `list`, `kanban`, or `puzzle`. The default is `puzzle`.
Buttons show the view title in a tooltip on hover and keyboard focus.
The ribbon remains available when the navigation pane is closed.
All paths are relative to the active workspace of the window. The host rejects paths outside the workspace.
The optional `openFile(path)` method opens a workspace file.
The optional `replaceView(currentId, nextId)` method changes the current tab while preserving its position and pin state.
For document tabs, `replaceDocumentWithView(document, nextId)` supplies the same behavior.
Both methods restrict the source and destination to the calling plugin.
| 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. |
### View launch defaults
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.
Views can supply an optional `launch()` handler for entry through the plugin launcher or navigation button.
The handler can select a default view with `api.openView(id)`.
Explicit `api.openView` calls and restored tabs bypass the launch handler and retain their targets.
Views without a handler open as before. Older hosts ignore this optional field.
Example: [Project Management](../../RuneStone_Project_Management/development.md#workspace-default-board) uses this handler to open its fixed workspace default board.
### Contributions
### Cleanup and 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.
Views can return asynchronous cleanup. Closing a view and disabling its plugin share the same cleanup promise.
Remove timers, listeners, and other resources in cleanup. Use the abort signal to stop pending work.
The SDK rejects calls after shutdown starts, but it does not isolate JavaScript with full application access.
Packages activate in every RuneStone window, including standalone terminal windows.
| 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 |
Contribution types live in `src/lib/plugins/contracts.ts`.
Only one active package can own each contribution. The runtime removes contributions before cleanup starts.
Terminal controls mount into a host element and return update, command, and disposal functions.
The plugin must stop its mounted controls and native sessions in `onDispose` before cleanup completes.
A terminal contribution must stop its controls and native sessions before its cleanup finishes.
## Git API
The optional `git` API supplies status, diff, stage, unstage, commit, and blame operations.
The current host source also supplies `push()`, `pull()`, and `graph()`.
These methods require an updated host and remain subject to plugin shutdown checks.
The host returns structured history from `git.graph()`:
```js
{ commits: [{ id, parents, refs, summary, author, date }] }
```
The history contains at most 100 commits. Parent IDs can refer to commits outside that history.
Example: the [Git plugin](../../RuneStone_Git/docs/usage.md#commit-graph) renders these commits and parent links as a graph.
For the native service and test setup, see the [Git development guide](../../RuneStone_Git/docs/development.md).
## Temporary background API
RuneStone 0.1.25 adds optional `api.backgrounds` with `version: 1`.
Example: [Background Slideshow](../../RuneStone_Background_Slideshow/docs/development.md#integration) publishes frames from local image folders.
Example: [Project Management](../../RuneStone_Project_Management/development.md#pm-0229-slideshow-backgrounds) consumes frames for board backgrounds.
`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 |
| --- | --- |
| `chooseFolder()` | Open the native folder picker. Return an absolute path or null on cancellation. |
| `defaultFolder()` | Optional. Create and return Pictures/RuneStone Backgrounds for new settings. |
| `list(folder)` | List PNG, JPEG, GIF, and WebP filenames directly inside the folder. |
| `read(folder, name)` | Read one raster image as bytes, with a 50 MiB limit. |
| `set(target, frame)` | Apply a temporary frame. Pass null to remove this plugin's frame. |
| `get(target)` | Read the active frame or null. |
| `subscribe(listener)` | Receive the changed target. Return a cleanup function. |
| `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. |
Targets are `app`, `pm-all`, and `pm-board:<board UUID>`.
A frame contains `url`, `overlay`, `position`, and `size`.
It can also contain `previous` with those four fields and `transitionMs` from 0 to 5000.
Renderers fade between these frames unless reduced motion is active. Keep both blob URLs valid until replacement or cleanup.
Use a blob URL. The publishing plugin owns the URL and must release it after replacement or cleanup.
Overlay ranges from -1 to 1. Negative values lighten the image, and positive values darken it.
Position and size use the same choices as custom image settings.
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).
Frames belong to the plugin activation in the current window. They do not change saved background settings.
The last published frame wins. Removing it reveals an earlier active frame or the saved background.
Disable removes the plugin's frames and subscriptions before cleanup.
File access requires an active plugin lease. Pending reads fail after access is revoked.
Image reads reject path traversal, linked files, unsupported formats, and oversized files.
## Background API
Use the plugin settings API to share saved configuration across windows. Temporary frames remain local to each window.
`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.
### Per-image background 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. |
The optional background API adds `readImageSettings` and `writeImageSettings`.
The sidecar file is `.runestone-backgrounds.json` beside the images, with schema 1, an `images` object, and a 1 MiB limit.
Writes compare the previous file text to preserve external changes.
Temporary frames can supply `blurredUrl`. Each target scales the foreground and blurred layer separately.
The plugin owns all frame URLs and releases them after replacement or shutdown.
See the [Slideshow image settings example](../../RuneStone_Background_Slideshow/docs/development.md#per-image-settings) for its storage and rendering behavior.
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:<board UUID>` | 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.