Plugins

Mouser plugins add modes, tools, model providers and [mouser] line commands. This is phase 1 of docs/plans/mcp-agent.md: the manifest, registry, CLI, permission broker with approval popups, and the three transports. Mouser's MCP server (P2), the MCP client in the sidebar (P3), model providers (P4) and the chat mode (P5) build on it. Since P6 everything is a plugin, and since 1.4.0 no mode is compiled in: commander, chat and preferences are plugin programs installed from plugins.lock, the engines (mouser, skia) are libraries, and only the model providers are built in (§Built-in plugins); engines install, list and switch through the same registry.

Transports

transport what it is lifetime trust
mcp a program speaking MCP over stdio (run.command) started on demand installed: asks, then remembers what you choose
fuzzball a program running in a tab, over Fuzzball p (fuzzball docs/plugins.md) while it runs, that tab only untrusted; over ssh it asks every time
mode a mode plugin kept running, speaking the mode protocol over stdio: events in; views, effects and images (shared memory) out (docs/mode-protocol.md) started when first drawn; restarted after a crash (1 s, 2 s, 4 s), off after plugins.max_restarts crashes in 30 s installed: asks (run), then remembers; effects and events checked against its permissions
command an executable behind [mouser] line words: one JSON request on stdin, one JSON reply on stdout one run per command (10 s limit) installed: asks, then remembers
http a model provider reached over HTTP: a [model] table with api (openai, anthropic, google), url, models, default (docs/models.md) when a model is used built in or listed by you
library an engine: a native library over the engine C ABI, with an [engine] table (docs/engines.md) loaded when it draws installed by you; checked (name, ABI) at install and load
decoration a program that draws the window chrome and decides which PTYs exist (newline JSON, below) one process for the window; killed if a reply takes over 120 ms installed: asks (run), then remembers
builtin compiled into Mouser (commander, chat, preferences, the model adapters, the tabs decoration); reserved always there part of Mouser

Native libraries are only for engines (kind engine, transport library); their C ABI is unchanged (docs/engines.md).

Decoration plugins

A decoration draws window chrome and can ask for PTYs in that window. Every enabled decoration runs together. Registry order is priority: the first is the highest. With none, Mouser keeps its built-in tab bar (shown once there are two tabs) and one shell per tab.

The built-in tabs decoration is off until mouser plugin enable tabs. It draws a tab strip (including the one-tab case), and each tab can run its own shell or command from [tabs] in preferences.toml (docs/tabs.md).

An external one is kind = "decoration" and transport = "decoration", with run.command required. The name tabs is reserved. It needs run allowed or it never starts and the window stays on the built-in behaviour. The environment is scrubbed the same way as a command plugin.

The process speaks newline-delimited JSON. Each call is sent to every live decoration at once, with an id. Mouser waits for the slowest reply, and no longer than 120 ms. It then sends {"op":"kill","id":N} to anyone still working on that call. The plugin must stop and reply {"cancelled":true} (no chrome or ops for that call). A chrome or ops line after the kill is discarded. Silence for 80 ms after the kill ends the process and drops that decoration for this session. A panic or a bad reply drops it too. A kill that the plugin honours is only a miss: it stays loaded. Replies that made the deadline are still applied, in registry order. If none remain, the window uses the built-in sessions.

Mouser to the plugin:

op when
hello once, at start
kill the 120 ms deadline passed for id; stop that call
chrome each frame (id, width, height, cell_w, cell_h, pty)
event a key action or a hit id (action, id, pty)
note a PTY exited (exited), the focus moved (focused), or any decoration's chrome was clicked (chrome-hit: owner, id)

pty is { "focused", "list": [ { "id", "title", "alive", "kind", "program" } ] }.

The plugin replies:

{"chrome":{"top":32,"bottom":0,"left":0,"right":0,"ops":[{"text":{"x":8,"y":4,"text":"1 sh","color":"#c0caf5"}}],"hits":[{"id":"focus:1","x":0,"y":0,"w":80,"h":32}]},"ops":[{"focus":1}]}
        

ops is fill or text (pixel rects, colours #rrggbb). hits are pixel rects; a click sends that id back as an event. PTY ops are {"spawn":{"kind":"shell","program":"/bin/zsh"}}, {"spawn":{"kind":"command","program":"top","argv":[]}}, {"close":1}, {"focus":1}. The host owns the PTY; the plugin only asks.

In Rust the same contract is mouser_core::decoration::{Decoration, DecorEvent, Chrome, PtyOp}. mouser_core::decoration::TabsDecoration is the built-in.

Several decorations

The scheduler (compose, arbitrate, fanout_hit) sits between the host and every enabled decoration. Each decoration is Send and owned by a worker thread. A frame or event is one call id, sent to all of those workers at once. The wait is the slowest reply, capped at 120 ms, not the sum. Whoever is still out gets a cancel for that id only. A later call has a new id, so the old cancel cannot hit it. In-process code polls Cancel::is_cancelled and returns. An external process gets kill and should answer {"cancelled":true}. After the replies are in, merge order is registry priority, not arrival order.

The manifest: plugin.toml

name = "hello-command"          # a-z 0-9 - _ ; not a built-in name
        version = "0.1.0"
        api = 1                         # optional; plugin API version (1)
        description = "says hello from the [mouser] line"
        permissions = ["run", "notify"] # what it may ask for (below)
        
        [[provides]]                    # one or more
        kind = "command"                # mode | engine | model-provider | tool-provider | command | decoration
        id = "hello"                    # optional; defaults to the name
        
        [run]
        transport = "command"           # mcp | fuzzball | command | mode
        command = ["sh", "./hello.sh"]  # ./ is the plugin's directory; other names come from PATH
        commands = ["hello"]            # command plugins only
        

A mode plugin adds [mode] (hotkey and keys, §Mode plugins). An engine plugin provides only kind = "engine", uses transport = "library" and adds

[engine]
        abi = 1                         # engine C ABI version
        library = "libmouser_engine_flat.so"   # a file in the plugin directory
        

The older engine.toml (name, version, abi, library, description) is read as the same manifest, so existing engines keep working; an engine directory may hold either. mouser plugin install hands an engine directory to the engine installer (it lands in $MOUSER_HOME/engines/<name>). Bringing in a model is a plugin of kind model-provider. The llama.cpp/Gemma plugin (P4b) and the hosted adapters (P4) are the first of these, and anyone can add another.

CLI

mouser plugin list                       # by priority: version, transport, kinds, commands
        mouser plugin install <dir|plugin.toml>  # copies the directory into $MOUSER_HOME/plugins/<name>
        mouser plugin uninstall <name>           # also forgets its permissions
        mouser plugin enable|disable <name>
        mouser plugin priority <a> <b> ...       # the rest follow in their order
        mouser plugin move <name> first|last|up|down|<n>
        mouser plugin permissions                # every saved permission, by key
        mouser plugin permissions <key> [cap=allow|ask|never ...]    # `*=never` for all; fuzzball:<name>, ssh:… too
        mouser plugin permissions '<key>' revoke  # forget it; it asks again
        mouser plugin probe <name>               # MCP: handshake and list its tools
        

--kind mode|engine|model-provider|tool-provider|command limits any of these to one kind. mouser engine X is mouser plugin X --kind engine: the same parser and code (mouser engine list and mouser plugin list --kind engine print the same thing). Engines also have use <name> (put first, unskip) and unskip <name>|--all; without --kind, enable/disable/use/unskip with an engine's name reach the engine. install, update, rollback, remove, retry and cancel take the same sources and checks for plugins and engines (Downloads). State lives in $MOUSER_HOME/plugins/: one directory per plugin, state.toml (priority, disabled; engines' disabled flags too) and permissions.toml. The engine order stays in the engines preference (mouser engine priority), not in state.toml.

Where Mouser finds plugins

Mouser searches these folders in order. The first one with a given plugin name wins, and mouser plugin list marks where each one came from:

  1. $MOUSER_HOME/plugins/ (yours; install and uninstall act only here).
  2. plugins/ beside the Mouser executable (the -full offline bundle), and on macOS also Mouser.app/Contents/Resources/plugins/. Marked [bundle].
  3. /usr/lib/mouser/plugins/ and /usr/local/lib/mouser/plugins/, for system packagers (not on Windows). Marked [system].

MOUSER_PLUGIN_DIRS (a path list, like PATH) replaces folders 2 and 3; set it empty to search only $MOUSER_HOME/plugins/. Bundle and system plugins are read-only: uninstall refuses them, but disable works.

A plugin folder holds plugin.toml directly, or one folder per version (<name>/<version>/plugin.toml) with current choosing the active one. current can be a folder or symlink, or a file containing the version (Windows symlinks need admin rights). Uninstalling a versioned plugin removes every version.

The official modes' names and hotkeys (commander c, chat a, preferences p) belong to those plugins: your own build of one installs under the same name and replaces the official one (your copy in $MOUSER_HOME/plugins wins), and no other plugin may take those hotkeys. The built-in model providers' names stay reserved.

Built-in plugins

name kind hotkey can be disabled
openai, xai, openrouter, moonshot, anthropic, google, gemma-local model-provider yes

The engines mouser (can't be disabled; the last engine tried) and skia are libraries shipped with Mouser, not built in (Engines). The official modes are not in this table: they are plugins (mouser plugin list shows them with their versions). Disabling (or not installing) commander, chat and preferences leaves no mode: Mouser is then a plain terminal (the mode-less fallback), and mouser plugin list says so. A disabled engine is passed over when a window picks its engine and is hidden from the sidebar; MOUSER_ENGINE=a,b still forces an order for one run, as given.

Mode plugins

A mode plugin uses transport = "mode": Mouser starts the program once and keeps it running, talking the mode protocol over its stdin and stdout (Mode plugin protocol). It gets events, draws panels and images, and asks for effects, all checked against its permissions. Write one in Rust with the mouser-mode-api crate's Mode trait and serve().

The older transport = "command" (deprecated, removed in 2.0) runs the program once per event instead. Either way it's a plugin.toml with kind = "mode" and a [mode] table (example: examples/plugins/hello-mode):

[mode]
        hotkey = "h"                    # one letter/digit; not c, a (built-ins) or p
        keys = [{ id = "time", key = "t", describe = "show the time" }]
        

A key is plain, live only while the mode has the keyboard (docs/modes.md §Focus): a letter (case sensitive: R is Shift+R), digit or punctuation key (not :), alt+<key>, ctrl+alt+<letter>, or up, down, left, right, enter, pageup, pagedown, home, end, tab, space, backspace or f1 (since Mouser 1.5). Every key with its describe text is listed in the host's Keyboard help (docs/modes.md §Keyboard help). Without focus the mode gets no key at all (the focus toggle, ctrl+alt+k, is the host's).

It joins the mode switcher (esc :h; listed in ctrl+shift+m) after the official modes and docks above the prompt like them. Mouser runs its program once per event, off the UI thread, with the command-plugin contract (10 s limit, scrubbed environment): {"api":1,"command":"mode","args":[EVENT,ID],"cwd":...} with EVENT activate, key (ID = a [[mode.keys]] id, remappable in modes.toml) or cwd; the reply {"title":..., "lines":[...], "text":...} sets the dock (40 lines at most) and its status. It runs only once run is allowed (mouser plugin permissions NAME run=allow; until then the dock says how), and the shell's directory is sent only with files.read allowed. A mode plugin shows text and reacts to keys; it can't type into the shell or read the screen. Mode plugins over MCP are not supported yet (the manifest check says so); two plugins with the same hotkey: the later one is left out with a notice.

Permissions

capability meaning
run run its program on this computer
notify show notices
screen.read read the visible text of the tab
scrollback.read read the tab's scrollback
shell.type type or run commands in a shell
files.read / files.write read / change or delete files
themes.read / themes.write list or read themes / switch, create, duplicate or edit them (MCP)
network use the network
models.download download or start a model
remote.read list and read files on the shell's remote host (mode plugins)
agent.use talk to your AI models through Mouser; keys stay in Mouser (mode plugins)
prefs.write change your preferences (mode plugins; keys only through Mouser's popup)
net.fetch make web requests through Mouser (mode plugins)

Each plugin and capability is allow, ask (the default) or never. When a plugin needs a capability, the broker checks it:

The popup offers Allow once [y], Always [a], Deny [n]/Esc and Never [N]. Always and Never are saved.

The approval popup can't be spoofed

Command and MCP plugins run with a scrubbed environment (PATH, HOME, LANG, plus MOUSER_PLUGIN_API and MOUSER_PLUGIN_NAME), so tokens and API keys in your environment don't reach them.

Command plugins

On the [mouser] line (F10), a word that belongs to an enabled command plugin runs that plugin instead of going to the shell (!word still forces the shell). The first run asks for run. Then:

Plugins can't take Mouser's own words (theme, font, set, connect, …), and two plugins can't claim the same word.

MCP plugins

run.command starts a stdio MCP server (newline-delimited JSON-RPC 2.0). In P1, Mouser does initialize, notifications/initialized, tools/list and tools/call (mouser_core::mcp::Client); mouser plugin probe shows the result. Since P3 every enabled MCP plugin is also a connection in the sidebar's MCP section (plugin:<name>). It starts once its run permission is granted (click its row), and each tool call asks via the broker with capability tool.<name>. See docs/mcp.md §Client.

Fuzzball plugins

A program in a tab sends ESC P = F z p h ; id=1,name=…,caps=a+b ESC \, and Mouser answers after the popup (fuzzball docs/plugins.md). Grants belong to that tab and end with it. A plugin.toml with transport = "fuzzball" is optional; it only lists the plugin.

Examples (examples/plugins)

mouser plugin install examples/plugins/hello-command
        mouser plugin install examples/plugins/hello-mcp && mouser plugin probe hello-mcp
        sh examples/plugins/hello-fuzzball/hello-fuzzball.sh   # inside a Mouser tab
        

How it fits together (P6)

Source: docs/plugins.md