Shepherd is a bearer-protected MCP server that lets an MCP client, such as Grok Bot, start and drive coding CLIs like Kiro in terminal panes. The client starts a pane, types a prompt, waits for the turn to finish and reads the screen, all through MCP tools. The safety rules are enforced by Shepherd, not by the agent: which programs may start, where they run, which credentials they get, when typing is refused, and which answers a permission dialog may receive.
- Pane model. Shepherd owns the panes, not the client. Each pane is a program on its own
PTY, addressed by name. Under
openab-shepherd hold, a holder process owns the PTYs and a restartable front serves MCP; a bareopenab-shepherddoes both in one process. - Tools and scopes. Fourteen tools. A client holds explicit scopes (
observe,read,control,start,start:arbitrary,start:args,dialog,remove,routine, and the reservedattach,attach:write,lease:preempt); no scope implies another. See Scopes and docs/credentials.md. - Restart survival. Under
hold, the front can be killed or restarted withSIGUSR2and the panes keep running; the new front adopts them and replays their output silently. See Restart survival. - Routine. Shepherd can type a line into an idle pane on a schedule: a profile's idle
nudge, or an
every N secondsroutine an agent creates withroutine_create. See docs/routine.md. - Trust model. Shepherd assumes one operator account and trusted pane programs. It limits which programs start, with which credentials, and which dialog answers are sent; it does not isolate panes from each other or from the account. See docs/adr/trust-model.md.
- Loopback-only server with bearer auth.
--hostaccepts only the literal IPv4 or IPv6 loopback address, and IPv4 loopback is the default. Every request needsAuthorization: Bearer <token>, compared in constant time. The Host header is checked first, against loopback names and an optional allowlist (OPENAB_SHEPHERD_ALLOWED_HOSTS) for use behindtailscale serve. - Pane lifecycle tools. Ten MCP tools:
start_pane,send_input,read_output,get_status,wait_status,list_panes,interrupt_pane,answer_dialog,remove_paneanddraft_clear. Panes are addressed by name. Four more,routine_create,routine_list,routine_updateandroutine_delete, need theroutinescope (see the routine feature below).draft_clearneeds thelease:preemptscope; the other nine tools needobserve,read,control,start,dialogorremove. The scope table is in docs/operations.md. - Blocked-dialog handling.
send_inputrefuses to type while a pane is blocked on a dialog and returnspane_blocked.answer_dialogaccepts onlyallow_onceordeny_once; the rule-creating options cannot be chosen. It reads the dialog for the pane's agent (kiro,devin, oropencode), re-checks the dialog, its kind and its turn number before it presses Enter. A Devin dialog never selectsBypass mode. - Launch profiles.
start_panestarts only what the operator's profiles file allows: a fixedargv, a list of allowed working directories, and environment variables. Each variable is a literal value or is read when the pane starts from akeychain:(macOS Keychain) orenv:source. A profile names itsagent(kiro,devin, oropencode) and apermission_mode(normal,accept-edits, orbypass). Caller-chosen commands are off unless the file sets"allow_arbitrary_command": true, and such panes never get a profile's environment. Without a profiles file,start_panestarts nothing. - Routine (optional, per profile). A proactive in-process client for an
unattended agent that ends a turn with work left while no MCP client supervises
it. A profile's
routinesection makes Shepherd type itsnudge_textinto a pane whose finished turn sits idle pastidle_timeout_secs, with limits and a stderr log. Off unless a profile sets it; see docs/routine.md. - Agent-created routines (optional, per profile). An agent, or any client with the
routinescope, can ask Shepherd to type a line into a pane every N seconds withroutine_create: "every hour, check whether any todo work is left". A profile opts in withdynamic_routines, which sets the shortest interval, the number per pane and the longest life; without the key nothing changes. Missed or busy ticks are skipped, never queued. See docs/routine.md and theroutinescope in docs/operations.md. - Native terminal core. The default backend runs each pane on its own PTY with a
vt100emulator, a cleared child environment and at most 8 live panes. Programs report their state (idle,working,done,blocked, ...) with OSC 7501 escape sequences, which Shepherd parses into a status and a turn counter. It is the only backend.OPENAB_SHEPHERD_BACKENDaccepts only unset, empty ornative; any other value exits with status 2. - Process-tree cleanup.
remove_pane, a program's own exit and Shepherd's shutdown signal the pane's process group and every descendant Shepherd has seen, then kill what is left. Descendants are found by looking at the process table about every 250 ms (at most about 450 ms apart), so a process that fully detaches before the next look is missed. On Linux a look may use a snapshot up to 250 ms old: a descendant is seen within about 500 ms in the nominal case, and at most about 700 ms provided each scan finishes within 250 ms. On macOS the bound is about 450 ms (see Status and known limits). - Container image. The
Dockerfilebuilds a Debian image that runs as uid 1000 under tini, with kiro-cli pinned to 3.3.0 (the version the Kiro dialog parser was measured on) and checked against a SHA-256. The image holds no token and no profiles file. Its default command runs the pane holder (openab-shepherd hold -- ...); override the command with the bareopenab-shepherd --host ... --port ...for the single-process behaviour.
flowchart LR
C[MCP client or bot] -->|POST /mcp, bearer| F[Shepherd front]
F --> H[holder]
H --> P1[pane: kiro]
H --> P2[pane: devin]
H --> P3[pane: opencode]
F --- R[routine thread]
R -->|nudge text| F
F -.->|call and outcome lines| A[audit file]
A bare openab-shepherd runs the front and the panes in one process, with no holder.
Under openab-shepherd hold the holder owns the panes and starts the front, so the front can restart while the panes keep running.
- The MCP client sends JSON-RPC over HTTP
POST /mcpto the loopback listener, directly or throughtailscale serve. Shepherd checks the Host header, then the bearer token. - The tool layer validates the arguments it recognizes (unrecognized keys are
ignored, not rejected), then applies the safety rules: launch profiles, the
per-pane lock, refusing input to a blocked pane, and the dialog checks. It reaches panes only through the
TerminalBackendtrait. start_paneresolves a launch profile, reads its credentials, and the native backend spawns the program on a PTY with onlyHOME,PATH,USER,LANG,TERMand the profile's variables.- The program's output feeds the terminal emulator, which draws the screen and
passes OSC 7501 status reports to Shepherd.
wait_statusreturns when a turn ends (done), the pane blocks on a dialog (blocked), the program exits, or the wait times out. - When a pane is blocked on a permission dialog, the client reads the screen with
read_outputand answers withanswer_dialog. When the work is done,remove_panestops the program and its descendants and frees the slot.
Build on a build host with a Rust toolchain:
cargo build --releaseCreate a token file and a launch profiles file, both outside any git repository:
umask 077
openssl rand -hex 32 > <token-file>
chmod 600 <token-file>{
"allow_arbitrary_command": false,
"profiles": [
{
"name": "kiro",
"argv": ["kiro-cli", "chat"],
"cwds": ["<work-dir>"],
"env": { "KIRO_API_KEY": "keychain:<keychain-item>" }
}
]
}On Linux, use "env:<NAME>" instead of keychain:; Keychain sources are macOS only.
Start the server:
OPENAB_SHEPHERD_TOKEN_FILE=<token-file> \
OPENAB_SHEPHERD_PROFILES=<profiles-file> \
./target/release/openab-shepherd --port 8765To keep panes alive across a server restart, run it under the holder:
OPENAB_SHEPHERD_TOKEN_FILE=<token-file> OPENAB_SHEPHERD_PROFILES=<profiles-file> \
./target/release/openab-shepherd hold -- --port 8765kill -USR2 <holder-pid> then restarts only the front. The container image runs this by default.
Point the MCP client at http://<loopback-address>:8765/mcp with the header
Authorization: Bearer <token>. To reach it from another machine on the tailnet,
put it behind tailscale serve and allow that name, for example
OPENAB_SHEPHERD_ALLOWED_HOSTS=<mcp-host>.example-tailnet.ts.net:8445.
Two optional variables add named clients with limited scopes and an audit log:
OPENAB_SHEPHERD_CLIENTS (path of the clients file, JSON, mode 0600, outside any git
repository) and OPENAB_SHEPHERD_AUDIT_FILE (path of the audit log, JSON Lines, in a
mode 0700 directory; required when a clients file is set). Without them, the single
token (client default) keeps every scope that existed before shared panes. It holds none of attach,
attach:write, lease:preempt and routine, so draft_clear and the four routine_* tools answer it with forbidden; they need a clients file. With a clients file, a token file or token variable is a startup
error: each caller gets its own entry in the clients file. See
Clients, scopes and the audit log.
Every variable, profile field, tool argument, error code and bound is described in docs/operations.md.
How the operator signs in to the coding CLI or supplies its key is described in docs/credentials.md.
Notes on using Shepherd from a human terminal client, including a proposed pairing with openab-pty, are in docs/terminal-clients.md.
The OpenCode notes (launch, the permission dialog, the highlight check) are in docs/opencode.md.
Shepherd is an MVP. The latest release is 0.5.0 (see CHANGELOG.md). The native backend was verified against kiro-cli 3.1.0 with a real-Kiro probe; the results are in MVP-REPORT.md (a dated record, not a current status), and the native core's design is in docs/adr/native-core.md. The trust model (one account, pane programs trusted) and the non-goals are in docs/adr/trust-model.md. The restart-survival and shared-pane design is in docs/adr/restart-survival-and-shared-panes.md.
- No pane ownership. With the single token, anyone holding it controls every pane. With a clients file each client has its own scopes and an audit trail, but any client with a scope can use it on every pane. Pane ownership is a non-goal (see the trust model).
- Two dialog choices only.
answer_dialoganswersallow_onceordeny_onceand nothing else. Other dialog kinds (question,auth) are not answered. - Text-based dialog parsing. The dialog is parsed from screen text. Measured
agents: kiro-cli 3.3.0 (V3 shell, file write and edit, file read outside the workspace, MCP and web fetch permission dialogs; web search and wrapped commands are measured and refused; see docs/operations.md for the measured and not-measured kinds), Devin CLI 3000.12.43 and 3000.12.57
(shell commands) and OpenCode v2.2.7 (shell and edit dialogs, see below). For OpenCode,
deny_onceis answered with Esc;allow_oncepresses Enter only when the styled screen cells showAllow oncewith a background that differs from the other two options, which match each other. - A fast detached descendant escapes cleanup. A descendant that is re-parented and fully detaches (new session, no terminal, parents gone) before the first look at the process table that would see it is never seen and survives. That look comes within about 500 ms in the nominal case, and at most about 700 ms on Linux provided each scan finishes within 250 ms, and about 450 ms on macOS. macOS has no unprivileged way to close this gap. On Linux the holder is deliberately not a subreaper; an orphan that escapes the scan is reaped by PID 1 (tini in the image).
- Panes survive a server restart only under
hold. A bareopenab-shepherdowns its panes and they end with it.openab-shepherd hold -- <server flags>runs a holder that owns the panes and restarts the server (SIGUSR2), but stopping the holder ends them. See Restart survival.
The full list, including the output filter's limits, is in docs/operations.md.
- docs/operations.md: operator reference (variables, profiles, tools, errors, scopes, audit, restart survival, image).
- docs/routine.md: the idle routine and agent-created routines.
- docs/credentials.md: coding CLI credentials and an agent as an MCP client.
- docs/terminal-clients.md and docs/opencode.md: terminal clients and OpenCode notes.
- docs/adr/: design records (native core, trust model, restart survival and shared panes).
- docs/operator-e2e/: operator end-to-end runbooks.
- CHANGELOG.md.
MIT. See LICENSE.