Plugins
A plugin is a Lua file (in a local directory or Git checkout) that returns a config table or a function accepting options and returning one. Tuse validates every enabled plugin individually and merges all plugins underneath the user's config. For a step-by-step guide to building and publishing plugins, see plugin-authoring.md.
Declaring Plugins
Declare plugins in the top-level plugins list of your user config (plugins themselves cannot declare plugins):
return {
plugins = {
"owner/repo", -- init.lua (else tuse.lua) at repo root
"ethanhamilthon/tuse/plugins/welcome", -- subfolder inside the repo
{ "owner/kit", opts = { name = "Yen" } }, -- options table passed to the plugin
{ "owner/pinned", ref = "v1.2.0" }, -- tag, branch, or commit metadata
{ "https://gitlab.com/me/stuff.git", path = "plugins/x" },
{ "git@github.com:me/private.git" },
{ "dev", dir = "~/code/my-plugin" }, -- local directory, no git layout
{ "owner/off", enabled = false }, -- skipped completely
},
}
plugins must be a 1-based sequence (unexpected map keys are rejected). Each entry is a string shorthand or a table with these keys (unknown keys are rejected):
| Key | Type | Default | Meaning |
|---|---|---|---|
[1] |
string (required) | — | GitHub owner/repo[/subpath], a Git URL (:// or git@), or a display name when dir is set. |
opts |
table | {} |
Options table passed to function plugins. |
ref |
string | unset | Tag, branch, or commit SHA synced on reload (and shown in /config and offline startup hints). A 40-char hex SHA (or 7–39-char hex string not matching any tag or remote branch) already at HEAD is treated as an immutable pin and skips fetching on reload; tags, branches, and omitted ref fetch on every reload. Multiple enabled entries from the same repository cannot specify conflicting ref values. |
dir |
string | unset | Local folder path (~/ expanded, relative paths resolved against the config file's directory). Re-read directly from disk on every reload with no Git or network commands. |
path |
string | unset | Subfolder inside the repository (appended to any subpath in [1]). Rejects any .. path segment, though it is not a filesystem confinement boundary (absolute paths and symlink targets are not restricted). |
enabled |
boolean | true |
false skips loading, checkout checks, URL/ref-conflict checks, Git sync, merging, and listing; the entry's own schema, keys, [1] spec, and path syntax are still validated. |
Checkout Paths and Entrypoints
| Entry form | Checkout root | Subpath |
|---|---|---|
"owner/repo" |
~/.tuse/plugins/<owner>/<repo> |
none (or path) |
"owner/repo/sub/dir" |
~/.tuse/plugins/<owner>/<repo> |
sub/dir (plus path if set) |
"https://host/owner/repo[.git]" or "git@host:owner/repo[.git]" |
~/.tuse/plugins/<host>/<owner>/<repo> |
none (or path) |
{ "name", dir = "<local>" } |
<local> resolved from config file dir |
none (or path) |
- GitHub shorthand requires at least
owner/repowith no empty,., or..segments; its clone URL ishttps://github.com/<owner>/<repo>.git. - Inside the resolved plugin directory (
<root>[/<subpath>]), Tuse looks forinit.luafirst, elsetuse.lua. - If a Git checkout root does not exist on disk, loading fails with an error showing the
git clone <url> <root>command (plusgit -C <root> checkout <ref>whenrefis set). If the root exists (ordiris used) withoutinit.luaortuse.lua, loading fails withno init.lua or tuse.lua in <dir>. - When the checkout root is a standard Git checkout,
/configand JSON-RPCconfig.getreport the 7-character short commit SHA ofHEAD(otherwisecommitis omitted and/configdisplayslocal).
Writing a Plugin
A plugin executes in Tuse's file environment (lua.md):
- Import host functions with
require("tuse");t.session()returns the pre-session snapshot (mode,configpath,cwd,home, withid == nil) at load time. - Relative
require("./util")resolves relative to the plugin file;os.getenv("THIS_PATH")returns the plugin file's path. - Return a config table,
nil(treated as{}), or afunction(opts)that returns a config table (ornil).optsis always a table ({}when omitted). Returning any other type fails.
local util = require("./util") -- relative to this file
return function(opts)
return {
systems = { "User's name is " .. (opts.name or "friend") },
commands = {
hello = function()
require("tuse").show("hello", util.greet(opts), false)
end,
},
}
end
Validation and Merging
- The user's top-level config table (excluding
plugins) is validated first. - Enabled plugin entries are parsed and checked for conflicting normalized URLs (stripping trailing
/and.gitwhile preserving scheme/host/user/path) and conflicting non-nilrefvalues on any shared checkout root before any Git command runs. - On reload (
/reload, JSON-RPCconfig.reload, or Luareload()), each unique enabled Git repository is synchronized at most once before loading. Startup,/new,/resume,session.new,session.resume, andtuse modelsstay offline and read existing checkouts on disk. - Each enabled plugin is loaded and validated strictly in list order (
plugin <name>: <path>: <message>). Plugins cannot declarepluginsor unknown keys. - Plugins merge in list order, then the user config merges on top:
systemsandmodels: concatenated, plugins first, then user config. Formodels, the last definition for a givennamewins.prompts,functions,hooks,commands,open: merged by key. If two plugins define the same key (includingfunctionsentries set to either a function orfalse), loading fails (plugins A and B both define <section>.<key>). The user config silently overrides any plugin entry (including disabling a plugin's configured function withfalse).settingsandtheme: merged deeply table-by-table; later plugins override earlier plugins on overlapping keys, and user config wins over all plugins.
- The final merged config is validated before
closehooks fire or the reload commits.
/config lists each enabled plugin with its name, optional @ref, 7-char commit (or local), and clickable directory path. JSON-RPC config.get returns them under plugins as { name, dir, ref?, commit? }.
Installing and Updating Checkouts (Reload Sync)
Initial startup (tuse, tuse json), session switches (/new, /resume, session.new, session.resume), and tuse models are offline and read existing checkouts on disk without touching the network. Reloading (/reload, JSON-RPC config.reload, or Lua reload()) automatically synchronizes every enabled Git plugin before loading and validating it:
- Shared-repo deduplication: multiple enabled entries pointing to subpaths of one repository share one sync per reload. If one entry sets
refand another omits it, the non-nilrefapplies to that repository; conflictingrefs or conflicting normalized URLs fail before Git runs. - Cross-process locking & non-interactive Git: every repository sync holds an exclusive advisory lock file under
~/.tuse/plugins/.locks/and runsgitnon-interactively (stdin closed,GIT_TERMINAL_PROMPT=0,GCM_INTERACTIVE=never,GIT_ASKPASS=/usr/bin/trueif unset,GIT_SSH_COMMAND="ssh -o BatchMode=yes"if unset) with a 60-second per-repository timeout (killing the Git process group on timeout). - Missing checkout (install): clones into a temporary staging directory under
~/.tuse/plugins/, resolvesref(or the remote's default branch), checks out the target commit in detachedHEAD, and atomically renames the staging directory into the checkout root. Any failure deletes the staging directory so no partial checkout is left behind. - Existing checkout (update):
- Verifies the directory is a valid Git repository whose
originremote URL matches the entry's normalized URL (never overwritesorigin). - Immutable commit pin: if
refis a 40-char hex SHA (or 7–39-char hex string matching no tag or remote branch) andHEADalready resolves to that commit, skips fetching and leaves the checkout untouched. - Otherwise fetches with pruning (
git fetch --prune --prune-tags --tags --force origin, plusgit remote set-head origin -awhenrefis omitted so default-branch renames such asmaster->mainare picked up). - Resolves target commit identically on clone and reload: when
refis omitted, usesrefs/remotes/origin/HEAD; whenrefis set, checks exact tagrefs/tags/<ref>, then exact remote branchrefs/remotes/origin/<ref>, then commit SHA (7–40 hex chars), else fails withplugin <name>: ref '<ref>' not found. - If
HEADalready equals the target commit, leaves the working tree untouched.
- Verifies the directory is a valid Git repository whose
- Local-work safety: before moving
HEADto a different commit on an existing checkout, Tuse checks for a clean working tree (no staged, unstaged, or untracked non-ignored files), no in-progress Git operation (merge, rebase, cherry-pick, revert, bisect), and verifies that currentHEAD(branch or detached) is reachable fromrefs/remotes/origin/*orrefs/tags/*. Checkout runs in detachedHEADwithout--force(so colliding ignored files are never overwritten). If any safety check fails, the working tree is left untouched and reload fails naming the plugin. - Removed plugins & failure rollback: removing a plugin from config unloads it on reload without deleting its checkout under
~/.tuse/plugins/. If any plugin fails sync, load, or validation, the reloading session performs in-memory rollback (keeping the previous working config active) without reverting already-synced sibling repositories on disk. - Offline bootstrap: if you want a new Git plugin present before first launch, clone it manually (
git clone <url> ~/.tuse/plugins/...) or add it topluginswhile running and run/reload. For local development, use{ "name", dir = "~/code/my-plugin" }.
Bundled Default Plugin: tuse/default
"tuse/default" is a reserved built-in plugin embedded directly in the tuse binary (source under plugins/default/). It loads completely offline without Git or network access and exposes two optional parts:
theme(defaulttrue) — applies Tuse's curated 10-token color palette (theme.md); userthemeoverrides still win token-by-token.subs(defaultfalse) — registers the/subscommand wrapping CLIProxyAPI as a loopback-only local provider (subs.md). All setup, login, proxy, and provider actions are explicit user opt-ins; loading or reloading never performs side effects.
return {
plugins = {
{
"tuse/default",
opts = {
theme = true,
subs = false,
},
},
},
}
- Because
opts.themedefaults totrue, asubs-only configuration must settheme = falseexplicitly (opts = { theme = false, subs = true }). ref,dir, andpathare rejected on"tuse/default"during validation (plugin tuse/default: bundled plugin does not accept ref, dir, or path).- Unknown keys or invalid values inside
optsoropts.subsfail config validation with diagnostics namingplugin tuse/defaultand the full key path. - Capability probe:
tuse models -c <temp_config>with{ plugins = { { "tuse/default", opts = { theme = false, subs = false } } } }exits0on binaries that bundle"tuse/default"and non-zero on older binaries.
Shipped Repository Plugin: welcome
ethanhamilthon/tuse/plugins/welcome ships in the Tuse Git repository (plugins/welcome), not embedded in the binary. Add "ethanhamilthon/tuse/plugins/welcome" to plugins and run /reload to install it automatically, or clone it beforehand for offline startup (or point dir at a local checkout):
git clone https://github.com/ethanhamilthon/tuse ~/.tuse/plugins/ethanhamilthon/tuse
Behavior:
- Activates only in TUI mode (
t.session().mode == "tui"); returns{}injsonmode. - Registers a
welcomehook onstart: whene.is_newistrue, renders an unpinnedshowblock containing an ASCII title banner, active model (display name and effort when not"default"), working directory, Git branch and status (2-second timeout), local date/time, config path, andtuse --version(2-second timeout). - Options:
title(string): banner text; defaults to the capitalized basename ofcwd(or"tuse").block(string):showblock name; defaults to"welcome".