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
+122
View File
@@ -0,0 +1,122 @@
import type { BackgroundApi } from "./backgrounds.ts";
import type { CompletionApi } from "./completion.ts";
import type { Contributions } from "./contributions.ts";
import type { GitApi } from "./git.ts";
import type { ActionIcon } from "./icons.ts";
import type { ActionMenuItem, ActionMenuOptions } from "./menu.ts";
/** Plugin API version 1. A compiled plugin exports `activate(api)`. */
export type Dispose = () => void | Promise<void>;
export interface PluginCommand { id: string; title: string; icon?: ActionIcon | PluginView["icon"]; category?: "open" | "action"; run: () => void | Promise<void> }
export interface PluginView { id: string; title: string; settings?: boolean; launcher?: boolean; launch?: () => void | Promise<void>; placement?: "dialog" | "editor" | "sidebar"; navigation?: boolean; toolbar?: boolean; pinned?: boolean; icon?: "list" | "kanban" | "puzzle" | "globe" | "git"; iconImage?: string | null; tabActions?: (context: { pinned: boolean }) => ActionMenuItem[]; tabDragData?: (context: { pinned: boolean }) => string | undefined; find?: () => void; saveTabState?: () => unknown; restoreTabState?: (state: unknown) => void | Promise<void>; mount: (container: HTMLElement, context?: { surface: "settings" | "view" }) => void | Dispose | Promise<void | Dispose> }
export interface PluginViewOpenOptions { split: "right" | "down"; relativeTo: string }
export interface PluginDocumentContext { id: string; path: string }
export interface PluginDocumentType {
id: string;
title: string;
icon?: "kanban" | "file";
extensions: string[];
content?: "text" | "binary";
identify(path: string, source: string): { id: string } | null;
create?: { label: string; defaultName: string; extension: string; contents(): string };
mount(container: HTMLElement, document: PluginDocumentContext): void | Dispose | Promise<void | Dispose>;
}
export interface PtyProfile { id: string; title: string; kind: string }
export interface PtyOpenOptions {
/** The workspace root of the window. The host rejects the request when the workspace changed. */
cwd: string;
cols: number;
rows: number;
profile?: string;
/** A start folder other than the workspace root. */
directory?: string;
/** Receives raw terminal output. UTF-8 characters can be split between two calls. */
onData(data: Uint8Array): void;
onExit?(code: number | null): void;
}
export interface PtySession {
readonly id: string;
write(data: string): Promise<void>;
resize(cols: number, rows: number): Promise<void>;
/** Stops the shell. Repeated calls return the same promise. */
close(): Promise<void>;
}
/** Terminal sessions. The host closes the sessions of a plugin when the plugin stops. */
export interface PtyApi {
readonly version: 1;
profiles(): Promise<PtyProfile[]>;
open(options: PtyOpenOptions): Promise<PtySession>;
openWindow(): Promise<void>;
dictation(): Promise<void>;
}
export interface FolderGrant { id: string; path: string; name: string }
export interface FolderEntry { name: string; size: number }
/** Folders outside the workspace that the user granted to this plugin. */
export interface FilesApi {
readonly version: 1;
chooseFolder(options?: { title?: string }): Promise<FolderGrant | null>;
pictureFolder(name: string): Promise<FolderGrant>;
grants(): Promise<FolderGrant[]>;
revoke(grant: string): Promise<boolean>;
list(grant: string): Promise<FolderEntry[]>;
readBytes(grant: string, name: string): Promise<Uint8Array>;
readSidecar(grant: string, name: string): Promise<string | null>;
writeSidecar(grant: string, name: string, contents: string, expected: string | null): Promise<void>;
}
export type ServiceMethods = Record<string, (...args: never[]) => unknown>;
/** Data that one plugin offers to other plugins in the same window. */
export interface ServicesApi {
readonly version: 1;
provide(name: string, methods: ServiceMethods): { notify(): void; dispose(): void };
get(plugin: string, name: string): Record<string, (...args: unknown[]) => Promise<unknown>> | null;
subscribe(listener: (plugin: string, name: string) => void): Dispose;
}
/** Files in the active workspace. All paths are relative to the workspace root. */
export interface WorkspaceApi {
list(path?: string): Promise<{ name: string; rel_path: string; kind: string }[]>;
listMarkdown?(): Promise<string[]>;
read(path: string): Promise<string>;
readMany?(paths: string[]): Promise<{ path: string; source?: string; error?: string }[]>;
readBytes?(path: string): Promise<Uint8Array>;
readOptional?(path: string): Promise<string | null>;
create?(path: string, contents: string): Promise<void>;
write(path: string, contents: string, expected: string): Promise<void>;
subscribe?(listener: () => void): Dispose;
}
/** The saved JSON settings of the plugin. */
export interface SettingsApi { read(): Promise<unknown>; write(value: unknown): Promise<void>; subscribe?(listener: () => void): Dispose }
/** The files in the plugin package. */
export interface AssetsApi { read(path: string): Promise<Uint8Array> }
/** Interface parts that the host draws. */
export interface UiApi { showActionMenu(options: ActionMenuOptions): { close(): void } }
export interface PluginApi {
pty?: PtyApi;
files?: FilesApi;
services?: ServicesApi;
backgrounds?: BackgroundApi;
ui?: UiApi;
git?: GitApi;
completion?: CompletionApi;
readonly id: string;
readonly signal: AbortSignal;
contribute<K extends keyof Contributions>(key: K, value: Contributions[K]): void;
registerCommand(command: PluginCommand): void;
registerView(view: PluginView): void;
registerTabDrop?(receive: (data: string) => void | Promise<void>): void;
updateViewTitle?(id: string, title: string): void;
updateViewIcon?(id: string, image: string | null): void;
registerDocumentType(type: PluginDocumentType): void;
openDocument(path: string): Promise<void>;
openFile?(path: string): Promise<void>;
renameDocument?(document: PluginDocumentContext, name: string): Promise<string>;
openView(id: string, options?: PluginViewOpenOptions): void;
closeView?(id: string): void;
replaceView?(currentId: string, nextId: string): void;
replaceDocumentWithView?(document: PluginDocumentContext, nextId: string): void;
onDispose(cleanup: Dispose): void;
workspace: WorkspaceApi;
settings: SettingsApi;
assets: AssetsApi;
}
/** The entry module of a plugin. */
export interface PluginModule { activate(api: PluginApi): void | Dispose | Promise<void | Dispose> }