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.
11 KiB
Plugin host internals
Development · Plugin development · Install and manage plugins
This reference describes how RuneStone stores, installs, downloads, and removes plugins, for developers who change the plugin host.
Storage and recovery
The native plugin service is in src-tauri/src/plugins.rs. Its root is the Tauri app_data_dir().
<application-data>/
plugin-state.json catalog: manifest, hash, enabled state, install time, removal record
plugins/<plugin-id>/ installed packages
plugin-data/<plugin-id>/settings.json
plugin-staging/ review copies, update backups, and update-<uuid>.json journals
plugin-removals/<token>/ packages during confirmed removal
Settings → Plug-ins → Open plugins folder opens plugins/.
The service writes plugin-state.json to a temporary file, then renames it. It reads at most 4 MiB from that file.
After each change, the service sends the plugins-changed event to all windows. A settings write sends plugin-settings-changed with the plugin ID.
The browser preview (pnpm dev) has no installed plugins unless a smoke test supplies a desktop mock.
Scans
Each window asks for a new snapshot at these times:
| Trigger | Source |
|---|---|
| Window start | startExternalPlugins in src/lib/plugins/external.ts |
| Window focus | The same function |
| Every 5 seconds | The same function. It finds changes from a file manager. |
| Refresh in Settings → Plug-ins | PluginManager.svelte |
plugins-changed event |
Any change from another window |
A scan reads files and hashes only. It does not run code, install dependencies, or run scripts.
- A package with a changed hash gets an error and becomes disabled. The user must review it and enable it again.
- When a package folder is missing, the service removes its catalog entry. It never restores a missing package.
- A valid package that someone copies directly into
plugins/appears as disabled, with an unknown install time. - The service never scans
plugin-staging/.
Install and update
- The ZIP picker accepts at most 100
.zipfiles. Folders and loose manifests are not installation inputs. - For each ZIP, the service applies the package contract and writes a review copy to
plugin-staging/<token>/. It does not change the source file. - The review shows the name, author, version, description, source, and destination. For an update, it also shows the installed and new versions. Each review belongs to one window and expires after 30 minutes. Closing the window discards it.
- At install, the service makes sure that the source and the review copy still have the reviewed hash.
- The service saves the new catalog entry as disabled and moves the review copy into
plugins/<id>/. Then it enables the plugin if the user chose Install and enable. A crash cannot enable a partial package.
A package with an installed ID starts an update:
- The service disables the plugin and waits up to 10 seconds for every window to stop it.
- It writes an
update-<uuid>.jsonjournal, moves the old package to a backup folder, and moves the new package into place. - It saves the catalog with the new hash and the previous enabled state. Settings in
plugin-data/stay the same. - At startup, an uncommitted journal restores the old package, disabled. A committed journal deletes the backup.
Each package succeeds or fails independently. Cancel deletes the review copies.
Removal
- Uninstall makes a removal plan with a hash of the package folder. The plan belongs to one window and expires after 5 minutes.
- Confirmation uses the plan token once. A changed package needs a new confirmation.
- The service disables the plugin and waits up to 10 seconds for every window to finish cleanup. A cleanup failure blocks removal until RuneStone restarts.
- The service saves a removal record with the SHA-256 hash of each file. Then it moves the folder to
plugin-removals/<token>/and deletes it. - If deletion stops, Settings shows Removal incomplete and Retry cleanup. Retry deletes the folder only when every remaining file matches its recorded hash. Otherwise it stops and names the folder.
- At startup, the service examines each removal record. If the package is still in
plugins/and its removal folder does not exist, the service clears the record. The plugin stays disabled.
Removal keeps plugin-data/, source ZIPs, and workspace documents. Loaded JavaScript can stay in memory, so RuneStone asks for a restart.
The uninstall dialog puts focus on Cancel. Escape cancels.
Runtime leases
plugins_load returns the entry module and records a lease for the window. plugins_release ends the lease and records any cleanup error.
Updates and removals wait for all leases to end. A recorded cleanup error blocks enable, update, and removal until RuneStone restarts.
Native services for plugins, such as the background file commands, need a lease for the calling window.
Gitea downloads
src-tauri/src/plugin_sources.rs gets a plugin ZIP from a Gitea release. It is separate from package checks and installation.
It does not clone the repository, compile code, install dependencies, or run scripts.
For the user procedure, see Install from a Gitea link.
Accepted links and releases
- The link is a repository root,
https://<host>/<owner>/<repository>, with an optional.gitor trailing slash. Gitea must run at the root of the host. - Links with credentials, a query, or a fragment are invalid. SSH links and branch links are invalid.
- Without a tag, the service reads
/api/v1/repos/<owner>/<repository>/releases/latest. Gitea excludes drafts and prereleases from this route. - With a tag (at most 200 characters), it reads
/releases/tags/<tag>. Use an explicit tag for a prerelease. - The release must not be a draft. It must have exactly one
.zipattachment. Automatic source archives are not attachments.
Limits
| Limit | Value |
|---|---|
| Release metadata | 2 MiB |
| Plugin ZIP | 100 MiB |
| Redirects for each request | 5 |
| Total time for each request | 60 seconds |
| Connection time | 10 seconds |
The package limits also apply to the extracted files.
HTTPS, HTTP, and credentials
- For an HTTPS repository link, the ZIP link must use HTTPS. The service refuses a redirect from HTTPS to HTTP.
- HTTP links work for trusted local servers. The form shows a warning that HTTP sends the token and the package without encryption.
- The service sends the token as
Authorization: token <value>, only to the origin of the release API. Redirects to another origin do not get the token. - The form clears the token after each request and when it closes. RuneStone does not save the token.
- A private repository needs a token with read access to the release metadata and the attachment.
Review
The service writes the downloaded bytes to plugin-staging/, applies the same checks as a local ZIP, and deletes the archive.
The review shows the repository, the tag, and the attachment link without its query. It pins the downloaded hash.
A change to the remote release after review does not change the pending installation.
The same ID, enable, update, and removal rules apply to local and remote packages.
Modules and checks
| Module | Owns |
|---|---|
src-tauri/src/plugins.rs |
Package checks, discovery, installation, updates, persistence, removal, leases, settings, and assets |
src-tauri/src/plugin_sources.rs |
Gitea link parsing and release downloads |
src-tauri/src/backgrounds.rs |
Background folder and image commands |
src/lib/plugins/sdk.ts |
The public package API types |
src/lib/plugins/externalSession.ts |
Activation, API checks, contributions, mounts, and shutdown |
src/lib/plugins/external.ts |
Native state sync, module loading, scans, views, tabs, and document types |
src/lib/plugins/registry.ts / contracts.ts |
Shared contributions and their types |
src/lib/plugins/access.ts / PluginAccessMenu.svelte |
The Plug-in views and Commands menus |
src/lib/plugins/PluginManager.svelte |
Settings → Plug-ins: review, switches, Gitea form, and uninstall dialog |
src/lib/plugins/PluginSettings.svelte |
Plugin configuration pages in Settings |
src/lib/plugins/PluginTools.svelte / PluginEditor.svelte |
Dialog views and editor views |
src/lib/plugins/backgrounds.ts |
Background frames |
src/lib/completion/ |
The completion API |
scripts/packagePlugin.mjs |
The packager for plugin authors |
scripts/buildPlugins.mjs |
The Table Formulas build |
Run the plugin checks
Run these commands from the RuneStone repository root. For the general checks, see Checks. For the browser setup, see Browser smoke tests.
Some tests load the compiled feature plugins:
pnpm build:pluginsmakesplugin-packages/table-formulas/.scripts/plugins.spec.tsand the feature smoke tests need it.- The smoke tests read Terminal from
../RuneStone_Terminal/dist/. To make it without a release ZIP, runnode scripts/build.mjs --no-packagein the Terminal folder. SetRUNESTONE_TERMINAL_DISTto use another folder.
Unit tests:
node --experimental-strip-types --test scripts/plugins.spec.ts scripts/externalPlugins.spec.ts scripts/pluginPackaging.spec.ts scripts/pluginHostExtensions.spec.ts scripts/pluginDocuments.spec.ts scripts/pluginAccess.spec.ts scripts/completion.spec.ts scripts/backgrounds.spec.ts
Native tests use real temporary files and archives:
cargo test --manifest-path src-tauri/Cargo.toml --lib plugin
Browser smoke tests mock desktop calls and use the real interface and module loader. Run them while pnpm dev runs:
node scripts/pluginInstall.smoke.mjs
node scripts/plugins.smoke.mjs
node scripts/pluginAccess.smoke.mjs
node scripts/pluginChoiceMenus.smoke.mjs
node scripts/pluginFind.smoke.mjs
node scripts/pluginTabOrder.smoke.mjs
node scripts/settings.smoke.mjs
pluginInstall.smoke.mjs covers the link form, download errors, token clearing, cancel, focus, and disabled installation.
The native tests cover link parsing, release selection, redirects, credential boundaries, size limits, changed review copies, and invalid ZIPs.
Two native release tests are ignored by default:
| Test | Setup |
|---|---|
four_plugin_release_trial |
Set RUNESTONE_GIT_TRIAL_PACKAGES to a folder that contains exactly four plugin ZIPs. |
live_gitea_release_trial |
Set RUNESTONE_GIT_TRIAL_URL, RUNESTONE_GIT_TRIAL_TAG, and RUNESTONE_GIT_TRIAL_ZIP (the expected ZIP). Set RUNESTONE_GIT_TRIAL_TOKEN for a private repository. |
cargo test --manifest-path src-tauri/Cargo.toml --lib four_plugin_release_trial -- --ignored --nocapture