runtime-herdr
runtime-herdr (crates/runtime-herdr) is a runtime for people who use
herdr. It runs each Fleet Task in a terminal of
herdr-core, the terminal runtime
that herdr's desktop app is a client of. Fleet drives it through
the runtime protocol, as it drives
runtime-mux. Fleet does not link it.
Its configuration is in Fleet's configuration. To set it up and run a first Task, follow Fleet for herdr users.
How it reaches herdr-core #
Fleet ── runtime-herdr <verb> ──▶ herdr-core connect JSON-RPC 2.0, one message per line
│ (starts the core when it does not run)
▼
herdr-core ── holder ── terminal t7
labels: fleet.key=<key>
fleet.place=<place>
herdr.space=<key>, or the place's space
herdr.tab=<key>
fleet.role=shell (the shell only)
- Each call runs
herdr-core connectand speaks herdr-core's API over its stdin and stdout.connectstarts the core when it does not run. - The first request is
hellowith protocol generation 1. A core of another generation answers Unknown. - A place's
sessionselects a herdr-core session (HC_SESSION): a separate core, with terminals of its own. - The runtime needs herdr-core 0.1.22 or newer. CI tests it with the version
that
nix/herdr-core.nixpins.
The verbs #
runtime-herdr speaks protocol 2. It answers these verbs:
| Verb | What it does in herdr-core |
|---|---|
manifest |
Reports each place asked about. A place is ready when its core answers hello. As every verb does, it starts the core when the core does not run. |
start |
Writes the key's start record, then terminal.run with the argv, env and dir, and the labels above, then records the terminal's address and pid. A live terminal of the key, with the process start started, is adopted. So is the live terminal of a start cut short before it recorded the address. |
inspect |
running while the key's terminal is live and holds the process start started. paused after a pause, or Unknown while a pause cut short left a terminal open, until the next pause closes it. exited with the terminal's exit code once it has finished, or with no code when the core no longer has it. none when the key has no start record. |
stop |
terminal.kill, then terminal.rm, for each terminal of the key at the place, its shell among them. release: true also releases the key's workspace at the place. |
pause |
Writes a pause mark for the key, then ends its terminals as stop does. The start record stays, so a later start runs the key again. A pause of a paused key ends any terminal a pause cut short left open. |
input |
terminal.send with the text and force, which pastes it and presses Enter even when herdr-core reads the program as blocked: Fleet decides when to send. Fleet always sends submit: true; submit: false answers Unknown, because herdr-core cannot paste without Enter. |
capture |
terminal.read and the terminal's title. herdr-core reports no cursor and no foreground process, so both are null. |
exec |
Runs the command on this machine, in: host only, bounded by timeoutMs and outputCap. When the command ends, or at the deadline, it kills the command's process group, so nothing it started outlives the answer. Its output readers get up to 500 ms more to drain the pipes. |
attach |
A stream answer: runtime-herdr view [--session <session>] <terminal> (the stream). |
shell |
A shell terminal beside the key's, in the directory the key's terminal is in, labelled fleet.role=shell. A second call opens the same shell. The answer is a stream on it, as for attach. |
list |
Every key with a start record at the place, and every key that holds a workspace. |
workspace |
Runs workspace-git, as runtime-mux does, under a root of the place's own. |
The environment goes over the API. It is in no process's argv.
The stream #
runtime-herdr view speaks the terminal stream
on its stdin and stdout. It relays herdr-core's framed terminal.attach
(herdr-core connect, hello with framed: true):
| The view sends | runtime-herdr sends herdr-core |
|---|---|
its first resize |
terminal.attach with that size and 2000 lines of history |
input |
the bytes as DATA on the stream's channel |
paste |
the text as DATA, bracketed when the program last asked for bracketed paste |
resize |
RESIZE |
detach, or the end of its stdin |
CLOSE: the process keeps running |
| herdr-core sends | runtime-herdr sends the view |
|---|---|
| the first paint (screen, history, title), then the program's output | output, and CREDIT back for each byte written |
RESIZE |
resized |
CLOSE with the program's exit |
exit with its code |
hellocomes first, before the stream reads anything: thurbox's stream pane waits for it before it sends its size, as runtime-mux's view answers it.hellolistsresizeonly. herdr-core sends its first paint as bytes, so the view builds its grid fromoutput, as on psmux.- A view that cannot reach herdr-core gets
exitwith Unknown and why.
Persistence #
herdr-core's holder processes own the terminals, so a terminal keeps its process while the core restarts or updates.
| Event | What inspect answers |
|---|---|
| A core restart or update | running: the process is the same. |
| A core stop, a reboot or a lost holder | exited: the core marks the terminal finished. Fleet revives the Task. |
| The core removes a finished terminal (after 24 h) | exited with no code, from the start record. |
herdr's app keeps a terminal (keep) and the core gives it a new shell |
exited: the start record holds the first process's pid, and the shell has another. The next start ends the shell. |
inspect never answers none for a key that start started and stop did
not stop: Fleet reads none as a gone worker and does not revive it.
herdr's desktop app #
herdr's app shows each terminal that has the labels herdr.space and
herdr.tab, and makes a space or a tab for an id it does not know
(herdr-app's defaults/AGENTS.md). So each Task appears in the app as a
space of its own, which the app names after the folder its terminal runs
in, with the Task's agent and its shell inside. A place that sets space
puts all its Tasks in that one space instead, each in a tab named after its
key. The tests check the labels; the clip in
Fleet for herdr users shows the app.
Files #
| Path | Content |
|---|---|
${XDG_STATE_HOME:-~/.local/state}/runtime-herdr/<core>/<place>/<key>.start |
The start record: the key's terminal address and its process's pid. Before terminal.run, it holds neither. |
${XDG_STATE_HOME:-~/.local/state}/runtime-herdr/<core>/<place>/lock |
Starts and stops at one place hold this lock, one at a time. |
${XDG_DATA_HOME:-~/.local/share}/runtime-herdr/workspaces/<place>/ |
The workspaces that workspace-git makes for the place. |
<core> is the core's id from hello, so two herdr-core sessions keep
separate records. <place> is the place's name. With it and the
fleet.place label, two places on one session each start, stop, list and
release only their own terminals and workspaces. The state directory is
0700.
Limits #
- Linux and macOS only. On another system,
manifestreports each place not ready. - Places are herdr-core sessions on this machine. A herdr-core machine
(
hc machine) is not a place. - The herdr 1 terminal interface (the
herdrprogram) does not share herdr-core's terminals, so it does not show the Tasks. terminal.sendwaits while a person has an unfinished draft in the terminal, up to herdr-core'sdraft_wait(60 s by default). A wait past the runtime's call bound reads as Unknown, and Fleet does not send the entry again until a hook proves where it stands.
Tests #
crates/fleet-cli/tests/e2e_runtime_exec.rs runs a real herdr-core on a
private runtime directory (XDG_RUNTIME_DIR):
fleet runtime checkpasses againstruntime-herdr;- an exited process answers its exit code;
- a key stays running across a core restart, and a start adopts it;
- a key lost to a core stop answers
exited, and the nextstartruns it again; - a key's terminal has its environment and the labels herdr's app reads;
- two places on one session list only their own keys, and each keeps its own terminal and workspace for a key;
- a start cut short before it recorded the terminal is adopted;
- a key that holds only a workspace is listed;
inputtypes into a key's terminal andcapturereads it back;attachnamesruntime-herdr viewon the key's terminal;execanswers a command's code and output, or its deadline;- the stream shows the first paint after the view's first resize, types what the view sends, leaves the process running on a detach, and ends with the program's exit code;
shellandpausepass the conformance suite's cases;- a Task is briefed through
input, reports idle through its hooks, and is revived on its conversation under the same session after its process ends.