Files
RuneStone/docs/plugins.md
T

11 KiB

Plugins

Back to development

RuneStone installs local JavaScript plugins from package files or folders. Open Settings → Plug-ins to install, enable, disable, or uninstall them. Terminal and Table formulas use the same installed package system as all other plugins.

Build and install the feature packages

  1. Run pnpm build:plugins from the repository root.
  2. In Settings → Plug-ins, choose Install from folder and select plugin-packages/.
  3. Review both packages, then choose Install and enable.

No plugin starts automatically in a fresh installation. The application build does not include these packages. Package builds include their JavaScript dependencies and terminal styles. Build them again after source changes, then uninstall the old package and install the new folder. The old bundled switches no longer apply. Existing terminal appearance settings remain available after installation. Formula source stays in Markdown files when the plugin is absent, disabled, or removed. Native pseudo-terminal services remain in the desktop host. The Terminal package supplies the interface, shortcuts, and session controls.

Install a plugin

  1. Choose Install from file or Install from folder.
  2. Select the packages to install in the review dialog.
  3. Choose Install to keep them disabled, or Install and enable to run them.

A plugin file uses the .runestone-plugin extension and ZIP format. You can also select plugin.json, its containing folder, or a collection folder containing plugin folders and package files. Collection discovery checks one level and accepts at most 100 entries. RuneStone copies packages into its per-user application data directory. It never modifies the selected source. The review shows the author, version, source, destination, and access level.

External plugins run with RuneStone's application access. Enable only code you trust. Package metadata and hashes do not verify a publisher's identity. This version has no permission sandbox or marketplace. Scanning and installation do not execute code, install dependencies, or run installation scripts.

Plugins cannot overwrite an existing ID. Uninstall the previous package before installing another version. Each package succeeds or fails independently. The result identifies any failures. A changed source requires a new review. Cancelling the review removes its temporary copies.

Try the example in fixtures/plugins/workspace-overview/. Install that folder, then choose Install and enable. Use the puzzle button in the main toolbar to run Show workspace overview or open the Workspace overview view.

Uninstall with one confirmation

  1. Choose Uninstall on the plugin's row.
  2. Check its name, author, version, folder, and deletion message, then choose Uninstall and delete files.

The dialog initially focuses Cancel. Escape cancels the uninstall flow. Cancel leaves the files and enabled state unchanged. Disable instead keeps every installed file and turns the plugin off. Each uninstall requires a new confirmation.

After confirmation, RuneStone disables the plugin in every window and waits for cleanup. It deletes only the installed package. Source downloads, plugin settings, generated data, and workspace documents remain intact. The app shows Restart required because already loaded JavaScript can remain in memory until RuneStone closes.

Cleanup failure blocks deletion and keeps the installed files. Restart RuneStone before trying again. An interrupted file deletion shows Removal incomplete. Retry cleanup continues only that previously confirmed removal. Changed files in the removal directory block further deletion. Inspect the path named in the error before retrying. Reinstallation requires a new enable decision and can reuse retained settings.

flowchart LR
    installed("Installed plugin") --> confirm("Confirm file deletion")
    confirm --> cleanup("Stop in all windows")
    cleanup --> removed("Delete package; retain data")

Storage and recovery

RuneStone resolves the root through Tauri's app_data_dir(). Settings shows the complete path.

<application-data>/
  plugins/<plugin-id>/
    plugin.json
    main.js
    assets/
  plugin-data/<plugin-id>/settings.json
  plugin-state.json
  plugin-staging/
  plugin-removals/

Rust stores desired enable states in plugin-state.json and broadcasts changes to open windows. The browser preview has no installed plugins unless a smoke test supplies a desktop mock.

Startup, window focus, Refresh, and a five-second poll scan installed files. Changed packages stop running and require another enable decision. Missing packages are never restored automatically. Valid packages copied directly into the managed directory appear disabled. Staging directories never participate in plugin discovery.

Each reviewed candidate belongs to one window and expires after 30 minutes. Rust checks the source and staged content hashes before publishing a complete directory. A duplicate destination blocks publication. A crash cannot enable a partial installation.

Removal plans belong to one window and expire after five minutes. The backend accepts a single-use removal token when the user confirms deletion. A changed package requires a new confirmation. Runtime cleanup must complete in every window before the package moves into plugin-removals/. A persisted record identifies that directory and the original file hashes. Recovery deletes only unchanged remaining files from that confirmed transaction. It cannot target a newly installed copy. Install and removal operations share one native service and serialize their state changes.

Package contract

Place plugin.json at the root of the folder or archive:

{
  "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"
}

The package API is version 1. Its interface lives in src/lib/plugins/sdk.ts. All packages use one API and the same installation, enable, disable, and removal lifecycle. Versions use three numeric parts. 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.

Plugin API

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.

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")
  });
}
API Contract
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 the toolbar's plugin menu
registerView({ id, title, mount }) Add a view that mounts into a supplied DOM element
openView(id) Open one of the plugin's registered views
onDispose(callback) Register synchronous or asynchronous cleanup
workspace.list(path?) List a directory in this window's active workspace
workspace.read(path) Read a workspace text file
workspace.write(path, contents, expected) Save only if the file still matches the original text
settings.read() / settings.write(value) Read or write retained JSON settings, with a 1 MiB limit
assets.read(path) Read package bytes as a Uint8Array

Command and view IDs must be unique within their respective plugin collections. 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.

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.

Modules and checks

Module Owns
src-tauri/src/plugins.rs Discovery, validation, installation, persistence, removal plans, and cleanup acknowledgments
src/lib/plugins/PluginManager.svelte Package review, switches, and the uninstall dialog
src/lib/plugins/sdk.ts External package types
src/lib/plugins/externalSession.ts Activation, contributions, view disposal, and shutdown
src/lib/plugins/external.ts Native state synchronization and external module loading
src/lib/plugins/PluginTools.svelte External commands and views
src/lib/plugins/registry.ts / contracts.ts Shared feature contributions and their types
src/lib/plugins/TerminalSlot.svelte The host element for terminal controls
plugins/terminal/ / plugins/table-formulas/ Separate feature packages
scripts/buildPlugins.mjs Package compilation into plugin-packages/

Run pnpm build:plugins, pnpm check, pnpm test, pnpm build, and cargo test --manifest-path src-tauri/Cargo.toml --lib --offline. The Rust tests use real temporary files and archives. Browser tests mock desktop calls and exercise the real UI and module loader. Run scripts/pluginInstall.smoke.mjs, scripts/plugins.smoke.mjs, and scripts/settings.smoke.mjs against the development server.

Native plugin packages and restricted permissions remain future work. The core keeps basic Markdown tables, file editing, selection, sorting, and document access when optional features stop.