Documentation
Writing a plugin for herdr and shefrd
A herdr plugin runs on shefrd without changes. Write for herdr, and say you need shefrd only when the plugin cannot work without something shefrd alone has.
01 · Write it for herdr
Keep the herdr-plugin GitHub topic, ship herdr-plugin.toml, and
set min_herdr_version as you would for herdr. You don't need to add anything
for shefrd. The plugin installs and runs on both:
herdr plugin install you/your-plugin
shefrd plugin install you/your-plugin
Read the HERDR_* variables, call the herdr binary, and talk to
herdr.sock. shefrd provides all three under those names.
02 · What shefrd keeps
- The
herdrcommand.scripts/install.shlinksherdrto the shefrd binary. If anotherherdris already on PATH, the installer leaves it in place, and that one runs instead. Prefer$HERDR_BIN_PATH: shefrd sets it to the binary that started your plugin. -
~/.config/herdrstays the config directory. It holdsplugins/,plugins.json,agent-detection/, the session files and both sockets. Plugin state stays under~/.local/state/herdr. -
herdr.sockandherdr-client.sockare the sockets.shefrd.sockis an extra name for the same server. - Every
HERDR_*variable herdr sets for a plugin is set, with the same meaning. - Every socket API method herdr has is kept, with the same parameters and results. shefrd only adds methods.
Two differences a plugin can hit
- Writing herdr's
config.toml. shefrd reads it again onserver reload-config, but a key that shefrd's own file also sets keeps shefrd's value.[[keys.command]]is the exception: shefrd merges the two lists, herdr's first, so the bindings your README tells users to add to herdr's file work. Only a key both files bind takes shefrd's entry. -
min_herdr_versionis checked against shefrd's version. That version follows the herdr release shefrd has caught up with, so a plugin that needs the newest herdr is refused until shefrd catches up.
03 · shefrd-only plugins
A plugin is shefrd-only when it cannot do its job on herdr at all, because it depends on one of these:
- A socket API method herdr doesn't have. Compare
docs/next/api/herdr-api.schema.jsonin shefrd's repository with herdr's copy of that file. A method only shefrd's file names is shefrd-only. - A shefrd-only config key.
python3 -m scripts.shefrd_only_config_keysin shefrd's repository lists them. - A shefrd-only manifest field (
regions,knowledge,icon,[[build]] requires,[[link_handlers]] match_kind). herdr ignores fields it doesn't know, so such a field is shefrd-only only if the plugin doesn't work without it.
SHEFRD_* variables are not on this list. Each one is a copy
of a HERDR_* variable. Read the HERDR_* name. Reading only the
SHEFRD_* copy stops the plugin working on herdr and gains nothing.
A shefrd-only plugin says so in two places:
-
the
shefrd-plugintopic instead ofherdr-plugin, so herdr's users don't find a plugin they can't run -
a
shefrd-plugin.tomlmanifest instead ofherdr-plugin.toml. herdr doesn't read this file, so it refuses the install withplugin_manifest_not_foundinstead of loading a plugin that can't work.
A plugin that uses shefrd features when they exist and still works on herdr is a herdr
plugin. Keep herdr-plugin and herdr-plugin.toml. If the manifest
needs a shefrd-only field, you can ship shefrd-plugin.toml next to it. shefrd
reads that file first, and herdr keeps reading its own.
04 · Detecting the host
Test for the feature, not the product. Send the request you want on
$HERDR_SOCKET_PATH. A host without that method answers with an
invalid_request error whose message names the method. Fall back to what
herdr offers when that happens.
→ {"id":"1","method":"theme.get","params":{}}
← {"id":"1","result":{"type":"theme", ...}} shefrd
← {"id":"1","error":{"code":"invalid_request",
"message":"invalid request: unknown variant `theme.get`, ..."}} herdr
To ask which product started the process, check SHEFRD_ENV_MIRRORS_HERDR.
shefrd sets it for every plugin command and pane, and herdr sets no SHEFRD_*
variable at all. Don't use the version from ping for this: shefrd reports a
herdr version number.
05 · Marketplace listing
shefrd's marketplace index searches both topics and merges the results, so a repository
with both topics is listed once. In each repository it reads both manifest names and lists
one plugin per directory. Where a directory has both files it lists
shefrd-plugin.toml, the one shefrd loads.
Each listing has hosts: ["herdr", "shefrd"] when its directory
has a herdr-plugin.toml, and ["shefrd"] when it doesn't. That
comes from the files, not the topic, because herdr loads a plugin by its manifest name
whatever topics the repository has.
06 · Using mate
mate is shefrd's ask field. A plugin can ask it what a line means, have jev judge shell
commands, read what was typed into it, and count questions from shefrd's own records.
The user turns this on with features.mate_api = true. Until then every
method below answers mate_api_disabled. herdr has none of these methods, so
test for them as 04 describes.
The model and jev calls run in the server, with the keys models.env_file or
the server's environment holds. A plugin needs no key of its own, and every ask spends the
user's.
mate.ask
Says what a line comes to. It chooses and never runs: run the choice yourself with
keys.run or plugin.action.invoke.
→ {"id":"1","method":"mate.ask","params":{"line":"run Deploy preview"}}
← {"id":"1","result":{"type":"mate_ask","decision":{
"line":"run Deploy preview","kind":"plugin_action","by":"mate",
"action":{"id":"plugin:acme.deploy:preview","label":"Deploy preview",
"plugin_id":"acme.deploy","action_id":"preview"}}}} kind is one of:
action: one of shefrd's actions.action.idis akeys.listid.plugin_action: a plugin's manifest action, withplugin_idandaction_id.question: a question mate counts. Passquestiontomate.data.query.reply: a model answered in words, inreply.build_plugin: a request for a new plugin, with thebuildmodel and its coding agent.commands: shell commands inplan, with jev's judgement. Only when you pass"commands": true. A line asking for several things — spaces, tabs, a command in each — is planned as steps; itsplan.summarysays what they do in plain words,plan.commandslists every command they run, and the judgement is of the plan as a whole.nothing: nothing answered, andwhysays what stopped each model.
by names the model that decided, or mate when the line's own words
matched and no model was asked. notes lists what each model that did not
answer said, such as jev being out of credits before a fast model answered. A line that
names nothing goes to a model only while models.router is on.
Your plugin's actions
Every enabled plugin's manifest actions are among the options. run <title>,
the bare title, or <plugin_id>.<action_id> picks one with no model
asked, and the router can pick one from a looser line. A title two plugins share is left to
the router. With features.mate on as well, the same lines work in mate's field,
which asks before running a plugin's action unless mate.run is
everything.
mate.judge
→ {"id":"2","method":"mate.judge","params":{"commands":["rm -rf build"],"line":"clean up"}}
← {"id":"2","result":{"type":"mate_judge","judgement":{
"percent":88,"by":"jev-1.13.0",
"destructive":"a recursive delete outside a temp directory",
"runs_without_asking":false,
"asks_because":"a recursive delete outside a temp directory always asks"}}} percent is jev's probability that the commands are safe to run here. When jev
can't be reached, or no key is set, percent is absent and why says
why. runs_without_asking is what mate's own field would do under
mate.run and mate.auto_threshold. A destructive command always
asks, whatever jev says.
mate.history.list and mate.data.query
→ {"id":"3","method":"mate.history.list","params":{"limit":5}}
← {"id":"3","result":{"type":"mate_history_list","requests":[
{"at_unix_ms":1790700000000,"line":"split right","by":"mate","came_to":"split vertical"}]}}
→ {"id":"4","method":"mate.data.query","params":{"question":"how many panes are open"}}
← {"id":"4","result":{"type":"mate_data_query","answer":{
"question":"how many panes are open","counted":true,"text":"6 panes open now"}}}
The history is the newest lines typed into mate's field, oldest first. Lines a plugin asks
with mate.ask are not added to it. A question mate can't read is refused with
question_not_understood, and the message lists the forms it counts. When the
records hold nothing for a question, counted is false and
text says why. It never answers 0 in that case.
The mate.decided event
Subscribe to mate.decided with events.subscribe to receive every
decision mate makes, in the same shape mate.ask answers with.
source says where it was made: socket for a
mate.ask, which arrives before the ask's answer is written, or
field for a line the user typed into mate's field, which arrives before the
field acts on it. A field decision can also be kind: "mate_command", one of
the field's own commands such as a setting written or a tab made. It is not a manifest
event hook.
Limits and errors
- Four asks and judgements run at once. The next one is refused with
mate_busy. invalid_linemeans an empty line.invalid_commandsmeans no commands.- An ask that reaches a model can take several seconds, so don't block your UI on it.
From a script, shefrd mate ask, judge, history and
query send the same requests and print the answer as JSON.