# F16: script plugins ## TypeScript The TypeScript client has one kind of TUI plugin: a TypeScript module (`Plugin.define({ id, setup })`) that it imports into the TUI's own process (`packages/tui/src/plugin/context.tsx`). The plugin draws with JSX on OpenTUI and Solid, imports npm packages, and has Bun's whole runtime: files, the network, processes, timers. Nothing bounds its time or its memory, and nothing is asked before a project's plugin runs. It reads no `plugin.toml`. A directory under `plugins` that holds only a `plugin.toml` and an `init.ts` has no TUI module, so it is left out and nothing is said (`resolve` answers `unsupported`, and a discovered directory is optional). Its CLI has no `plugin types`, and its `plugin check` checks installed packages for updates. ## Rust A directory with a `plugin.toml` whose entry is a `.ts` or `.js` file is a script plugin (`docs/plugins.md`, "Script plugins"; `crates/plugin/src/script`). It runs inside the client, on the UI thread, in a VM of its own for each activation. Script plugins replaced the former Luau carrier. - **On by default.** A script plugin loads unless `OPENCODE_PLUGIN_SCRIPT=0`. When turned off it is listed `Skipped`. A legacy directory whose only entry is `init.luau` is listed `Skipped` with a notice to port it to a script plugin. A build without the cargo feature `script` says "this build of opencode-native has no script plugin support (built without the script feature)". - **The directory is the script plugin's.** A `tui.tsx` beside the `plugin.toml` does not run in opencode-native; TS runs it and ignores the rest. `parity/scenarios/P.script/hello.script-pty.ts` uses this to compare the quick start with its TypeScript twin from one directory. - **The API is the contract, not the TS plugin API.** The plugin imports `opencode:plugin`, registers data in `setup`, returns trees of nodes and asks for effects. It has no JSX, no components and no `context`. - **The language is psychoscript, not Bun's JavaScript.** There are no npm packages, and no `fetch`, timers, file system, process, `eval`, `Intl`, `Proxy` or `WeakRef`. A `.ts` file's type syntax is stripped, and TypeScript that needs compiling, such as an `enum`, is a load error. `import` reaches the plugin's own files and `opencode:plugin` only. - **It is bounded.** A stretch of it between two waits may use 100 ms of CPU time, a VM may hold 32 MiB of live values, a value that crosses to the host holds at most 320,000 keys and values, and its sources are 1 MiB. Past one of the first three the plugin fails, and `try` does not keep it alive (`F16-plugin-budget-and-restart`, `F16-plugin-limits`). - **An uncaught error fails the plugin**, with none of the failed call's effects (`F16-plugin-panic-no-effects`). One case does not: a failed or cancelled wait that a task lets escape (a `HostError` or an `AbortError`) ends that task alone, with a line in the log. - **A wait gives the thread back.** `await host.fetch(..)` returns to the host, and the rest of the handler runs in the host call that brings the answer. A render, a view, a code block renderer and `setup` cannot wait. - **A project's script plugin waits for approval**, as every project plugin does in opencode-native (`F16-project-plugin-approval`). The approval is the script plugin's own: it does not approve the same directory as a TypeScript plugin. - **Text is UTF-16 inside the VM and UTF-8 outside.** A string with an unpaired surrogate crosses with the replacement character in its place. - **`console` writes to the client's log**, one line a call (`plugin printed: …`), with control characters escaped and cut at 4 KiB. - **Two forms of `plugin` are opencode-native's own.** `opencode-native plugin types [dir]` prints the type declarations of `opencode:plugin`, or writes them and the language's into `dir`. `opencode-native plugin check ` checks the script plugin in a local directory: one that holds a `plugin.toml`, or a path that is absolute or starts with `./` or `../`. Any other argument goes to the TypeScript CLI's `plugin check` as before. The tests that hold the command table and the help to TypeScript's recordings leave `types` out (`Spec::own`, as `D01-no-plugins` does for its flag), and the P-CLI completions cases mask its entries on both sides (`parity/scenarios/C.0/own-commands.ts`). The script plugins are held to their frozen traces from the former Luau carrier (`docs/testing.md`, "Plugin twins"). ## Reason The TypeScript plugin API needs a JavaScript runtime with OpenTUI and Solid. opencode-native runs that out of process, a frame late, and only where Bun is found (`F16-typescript-plugins-skipped`, `F16-v2-compat-layer`). A plugin that draws inside the frame, loads with no install and runs where there is no Bun needs a language the client carries. That was Luau. psychoscript replaces it because it is a confined JavaScript: authors write the language of the TypeScript plugins they port, with types generated from the same schema, and the client loses Luau's C++ and its patches. The limits are there because the plugin runs on the UI thread of the client's own process.