Make Terminal a native feature

- Move the Terminal plugin into src/lib/features/terminal/ on the host Svelte runtime, with xterm 6.0.0 and addon-fit 0.11.0.
- Buttons, shortcuts, Help rows, and the close guard follow the Terminal switch. The first use loads the module.
- Add Settings → Terminal and the terminal settings section. The first start copies the old runestone.terminal key.
- The 16 ANSI colors come from the --rs-ansi-* tokens.
- Off asks first when a shell runs in any window (pty_running).
- Rust: no pty-data or pty-exit events, an owner check for write, resize, and close, output joined up to 64 KiB or 8 ms, and the sessions of a reloaded page close.
- Remove api.pty, the terminal contribution, TerminalSlot, and the plugin loader of the smoke harness.
- Check only the tested switches in the Background smoke test.
- Update the tests, the menu inventory, the docs, and UI-058.
This commit is contained in:
Knotty Wyvern
2026-10-29 19:02:58 -07:00
parent 53b9cea7f0
commit 833f793244
78 changed files with 2971 additions and 659 deletions
+4 -4
View File
@@ -66,7 +66,7 @@ A type-only import, such as `import type { PluginApi }`, adds no code to the bun
## Check for features
Members marked optional in `PluginApi` can be absent on older RuneStone versions. Examples are `api.pty`, `api.files`, and `api.workspace.readBytes`.
Members marked optional in `PluginApi` can be absent on older RuneStone versions. Examples are `api.files`, `api.backgrounds`, and `api.workspace.readBytes`.
Make sure that a member exists before you use it.
```ts
@@ -74,8 +74,8 @@ import { hasFeature, requireFeature, requireFeatures, type PluginApi } from "@ru
export function activate(api: PluginApi) {
// Stop the activation with one message that names each missing feature.
requireFeatures(api, ["pty", "workspace.readOptional"]);
const pty = requireFeature(api, "pty");
requireFeatures(api, ["files", "workspace.readOptional"]);
const files = requireFeature(api, "files");
// Hide a control when the feature is absent.
if (hasFeature(api, "ui.showActionMenu")) showMenuButton();
@@ -91,7 +91,7 @@ export function activate(api: PluginApi) {
When a feature is missing, `requireFeature` and `requireFeatures` throw a `MissingFeatureError`. Its `features` property lists the feature names.
Its message names each feature and its API path, and tells the user to update RuneStone. For example:
`This plugin needs the terminal API (api.pty). Update RuneStone to a version that has this feature.`
`This plugin needs the folder grant API (api.files). Update RuneStone to a version that has this feature.`
`pluginFeatures` lists all the feature names. The checks examine only whether the member exists.
-29
View File
@@ -20,34 +20,6 @@ export interface PluginDocumentType {
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. */
@@ -89,7 +61,6 @@ 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;
-15
View File
@@ -1,16 +1,5 @@
import type { Dispose } from "./api.ts";
export type TerminalAction = "toggle" | "new" | "window" | "split" | "previous" | "next" | "commands" | "directories";
export interface TerminalProps {
cwd: string; visible: boolean; maximized?: boolean; standalone?: boolean;
onClose: () => void; onMaximize?: () => void; activeFile?: boolean;
onRunFile?: () => Promise<string | null>; getSelection?: () => string; onConfigureTasks?: () => Promise<void>;
}
export interface TerminalMount {
update(props: TerminalProps): void;
command(action: Exclude<TerminalAction, "toggle">): void | Promise<void>;
dispose: Dispose;
}
/** Host features that `api.contribute(key, value)` registers. Only one enabled plugin can own each key. */
export interface Contributions {
browser: {
@@ -21,8 +10,4 @@ export interface Contributions {
/** Opens a web link from a document. False means that the system browser opens it. */
open(url: string): Promise<boolean>;
};
terminal: {
mount(container: HTMLElement, props: TerminalProps): TerminalMount;
shortcut(event: Pick<KeyboardEvent, "ctrlKey" | "metaKey" | "altKey" | "shiftKey" | "code" | "key">): TerminalAction | null;
};
}
+1 -3
View File
@@ -1,4 +1,4 @@
import type { FilesApi, PluginApi, PtyApi, ServicesApi, SettingsApi, UiApi, WorkspaceApi } from "./api.ts";
import type { FilesApi, PluginApi, ServicesApi, SettingsApi, UiApi, WorkspaceApi } from "./api.ts";
import type { BackgroundApi } from "./backgrounds.ts";
import type { CompletionApi } from "./completion.ts";
@@ -7,7 +7,6 @@ import type { CompletionApi } from "./completion.ts";
* Older RuneStone hosts can omit these members. Required members, such as `workspace.read`, are not listed.
*/
export interface PluginFeatures {
pty: PtyApi;
files: FilesApi;
services: ServicesApi;
backgrounds: BackgroundApi;
@@ -33,7 +32,6 @@ export interface PluginFeatures {
export type PluginFeature = keyof PluginFeatures;
const descriptions: { [K in PluginFeature]: string } = {
pty: "the terminal API",
files: "the folder grant API",
services: "the plugin service API",
backgrounds: "the background API",