Skip to content

Plugins ​

A plugin adds shared services, session behavior, or TUI parts. See Your first plugin for a small example.

Install plugins ​

The plugins list in config.json loads your plugins, in order. Each entry is a local folder or a Git repository.

json
{
  "plugins": [
    "./plugins/hello",
    { "path": "./plugins/my-plugin", "options": { "greeting": "hi" } },
    { "git": "https://github.com/lostcoords/yuke-plugins", "folder": "plugins/vim" }
  ]
}

An entry is a path, or an object with path or git:

KeyDefaultDescription
path—A folder with a plugin.json. A relative path starts in the profile folder.
git—The URL of a Git repository, as git takes it.
folderThe repository rootThe plugin folder in the repository.
refThe default branchThe branch, tag, or commit to follow.
options—The options of the plugin.

yuke never downloads a plugin at startup. For a Git plugin that you add to config.json by hand, run yuke plugin sync or use /plugins in the TUI.

A plugin that does not load does not stop the others. This covers a plugin that is not installed, has a bad plugin.json, or fails in its code. yuke loads the other plugins, and it gives one error notice. For one failed plugin, the notice reads "Plugin NAME did not load: REASON". For more plugins, it names them: "2 plugins did not load: a, b · /plugins or yuke plugin list shows why". /plugins shows why each one failed. A bad config.json or plugins.lock stops the start.

CommandDescription
yuke plugin add URL [NAME...]Add the plugins of a Git repository to config.json by the names of their plugin.json, install them, and lock their commit in plugins.lock. yuke finds the folder of each one. A repository with one plugin needs no name. --ref selects the branch, tag, or commit to follow.
yuke plugin remove NAMERemove a plugin from config.json and plugins.lock. Its files stay on disk.
yuke plugin listShow each plugin and its state: local, installed at a commit, not installed, or failed with the reason.
yuke plugin syncInstall the locked commits, and lock each new Git plugin. If a plugin does not install, sync installs the others and then fails with the reason of each one. With --locked, fail instead when plugins.lock does not match config.json.
yuke plugin update NAME...Show the new commits of each plugin's ref that change its folder, and ask before it moves the lock. If update cannot check a plugin, it updates the others and then fails with the reason of each one. --all updates every Git plugin, and --yes skips the question. Without --yes, it needs a terminal for the question.

In the TUI, /plugins shows your plugins in three sections. Needs attention shows each plugin that is not installed or does not load, with the reason. Git and Local show the others. The state of a plugin is loaded, reload loads it, failed, or not installed.

KeyAction
sInstall each Git plugin that is not installed.
cCheck each Git plugin for new commits, and show them before the update.
uCheck the selected Git plugin for new commits.
aAdd a plugin. Paste the URL of a Git repository, and select a plugin when the repository has more.
dRemove the selected plugin. Its files stay on disk.
rReload, so the changes load.

A plugin runs with your user rights. Read its source before you install it.

Bundled plugins ​

yuke loads these plugins before yours. A bundled plugin adds the slash commands in the last column. See Use the TUI for the commands and the keys.

PluginWhat it doesOptionsSlash commands
compactionSummarizes old context, in every mode.——
themesLoads and selects themes.—/themes
chatDraws the chat panes and provides the chat service.emptyView: boolean, default true. Set false to hide the header of an empty chat pane./model, /new, /rename
sessionsBrowses saved sessions.—/sessions
filesCompletes @ file paths in a chat draft.——
barDraws the status bar.hide and order: lists of item keys, such as "core:keys".—
toastsShows notices and their history.—/messages
loginConnects providers from the TUI.—/login, /logout
pluginsManages your plugins with the /plugins dashboard.—/plugins

The TUI core adds /quit and /reload. These two do not belong to a plugin.

Use disable to turn off a bundled plugin, and bundled to give it options:

json
{
  "disable": ["toasts"],
  "bundled": { "bar": { "hide": ["core:keys"] }, "chat": { "emptyView": false } }
}

A name in disable or bundled must be the name of a bundled plugin. Another name stops the start.

To replace a bundled plugin, disable its name and add your own plugin with the same name. Your plugin must provide the services that other plugins use from the old plugin. The bundled sessions and files plugins use the chat service. If you disable chat, provide a chat service, or disable sessions and files too.

Plugin manifest ​

Each plugin folder has a plugin.json. yuke reads these fields:

json
{
  "name": "notes",
  "extensions": {
    "sh.yuke": {
      "entry": "./index.ts",
      "uses": ["chat"],
      "provides": ["acme.notes.v1"]
    }
  }
}
FieldMeaning
nameRequired. One folder name: not empty, not . or .., and with no / or \. It is the source of the notices, the prefix of the commands, and the name of the data folder plugins/<name>/.
extensions["sh.yuke"]Optional. The fields of yuke, below.
Field of sh.yukeMeaning
entryThe entry module, as a path in the plugin folder. It is a .ts or a .js file. Without entry, the plugin has no code.
usesThe services that the plugin reads with ctx.get. See Services.
providesThe services that the plugin publishes with ctx.provide.

A plugin can ship only a skills folder. Leave out entry, and the plugin adds the skills of its folder. See AGENTS.md and skills.

yuke ignores the other fields of plugin.json and the other keys of extensions. A field of sh.yuke that yuke does not know is an error, and the plugin does not load.

These rules make a plugin fail to load:

  • The name is not a folder name.
  • Another plugin has the same name. A bundled plugin has the same name, and it is not in disable.
  • provides names tui, sessions, or catalog. These services belong to yuke.
  • Another plugin provides a service of provides already.

Entry points ​

The entry module of a plugin exports apply, session, or both:

ExportScopeContext
apply(ctx)Once per runtimePluginContext from yuke:plugins
session(s)Once per open sessionSessionContext from yuke:plugins
optionsSchemaValidates plugin optionsObjectSchema from yuke:tools

Use apply for services, host listeners, and UI. Use session for model tools, engine hooks, and session jobs.

Without optionsSchema, a plugin accepts no options. With a schema, use Infer<typeof optionsSchema> from yuke:tools as the type parameter of both contexts. The host validates and freezes the options before setup.

Opening a session does not wait for session. The first request for its tools waits.

Lifecycle ​

Both entry functions can return a cleanup function, or a promise for one. This entry module returns cleanup for a host listener:

js
// Watch session opens. This plugin needs no service in `uses`.

/** @param {import("yuke:plugins").PluginContext} ctx */
export function apply(ctx) {
  return ctx.addListener("session.opened", (event) => {
    ctx.notify("info", `Opened ${event.sessionId}`);
  });
}

ctx.signal aborts when the plugin fails to load or the runtime closes. s.signal aborts when the session closes or that plugin's session fails. Pass the signal to I/O, and stop timers in cleanup.

Session close runs the session cleanups. Runtime close then runs the apply cleanups, last plugin first. A failed cleanup sends a notice and does not stop the others. A failed session setup removes only that plugin's tools and hooks from the session.

Module state lasts for one runtime. Use ctx.dataDir for files that must survive a reload.

Services ​

A service shares a typed value between plugins.

  • The provider names the service in provides in the sh.yuke extension of plugin.json.
  • The provider publishes the value with ctx.provide(name, value) during apply.
  • A consumer names the service in uses.
  • The consumer reads the value with ctx.get(name).
  • The provider adds the type of its service to the Services interface of yuke:plugins.

yuke orders the plugins itself: it loads each provider before the plugins that use it. The order of the plugins list does not matter for services. A plugin does not load in these cases:

  • No plugin provides a service that it uses.
  • The provider of a service that it uses did not load.
  • The uses of some plugins form a cycle.

Three services belong to yuke. No plugin can provide them, and a plugin must not list them in uses:

ServiceValue
tuiThe TUI of this plugin, or undefined outside the TUI.
sessionsSession creation, queries, and handles in every mode.
catalogProvider and model queries in every mode.

The bundled chat plugin provides the chat service. A consumer of chat needs a uses entry.

Events ​

ctx.addListener(event, listener) observes a host fact and returns a remover. The plugin signal also removes the listener.

EventData
session.openedsessionId, parent, state, jobs, and interactions
session.updatesessionId and update
session.closedsessionId
noticelevel, source, text, and sessionId
catalog.changedNo data. A login, a logout, or a credential changed the ready providers.
theme.changedTheme name and terminal background. Only the TUI sends it.

A session.opened listener first receives the sessions that are already open. A session.update has a kind, such as state.

ts
import type { PluginContext } from "yuke:plugins";

export function apply(ctx: PluginContext): undefined {
  ctx.addListener("session.update", (event) => {
    if (event.update.kind === "state") {
      ctx.notify("info", `${event.sessionId}: ${event.update.state}`);
    }
  });
  return undefined;
}

The host does not await listeners. A throw sends a notice, and the listener stays. Use an engine hook when work must block an action.

Find the API ​

The installer puts the public API of your release in ~/.local/lib/yuke:

PathContent
modules/*.tsyuke:plugins (PluginContext, SessionContext, SessionHooks, HostEvents, Sessions), yuke:tools, and yuke:protocol.
types/*.d.tsThe host modules: yuke:tui, yuke:chat, yuke:ai, yuke:transcript, yuke:fs, yuke:net, yuke:process, and yuke:test.
protocol/The RPC protocol reference and its types.
tsconfig.jsonThe configuration that maps each yuke:* import to these files.

The doc comments in these files describe each member. Do not import yuke:internal/*.

Test and debug ​

Check the types with tsc -p ~/.config/yuke/tsconfig.json. Use your actual profile path if it differs. See Your first plugin for the TypeScript version.

For behavior tests, run yuke test on *.test.ts files that use yuke:test:

sh
yuke test [PATHS]...

PATHS are test files or folders. A folder gives each *.test.ts file below it. Without PATHS, yuke searches the current folder. A path to a file that is not a *.test.ts file is an error. The command fails when it finds no *.test.ts file, and when a test fails.

A test uses an isolated app and a fake model, and needs no provider credentials. types/test.d.ts has the test API. A type check or a test does not show how the terminal draws: start a TUI session to check that.

/reload reads the configuration, providers, and plugin files again. Wait for active turns to end first. A reload replaces the JavaScript runtime, so module state resets and plugin jobs stop. A bad config.json, plugins.lock, or providers.json fails the reload, and yuke keeps the previous plugins and providers.

Console output becomes a notice from the source console. The TUI shows it as a notice. An RPC client gets it in a notice JSON-RPC notification. CLI startup errors go to stderr.