Writing a dog
A dog is an ordinary binary. The shepherd starts it, hands it a socket and asks it two questions on the command line; everything else is the protocol it speaks back.
Writing your own
shep adopt <path> [--name <name>] [--yes]Third-party extension. The path can be given as-is, with a leading ~/, or as a bare name already on $PATH (where cargo install puts one). --name is optional and defaults to the binary's file stem with a leading shep- stripped, the way cargo strips cargo- from its own external subcommands. Vets the binary once, at adopt time: refusing a path that doesn't resolve to anything that exists, isn't a file, has no execute bit, or is world-writable, and refusing a name that already belongs to a built-in verb or alias, since such a dog could never be reached. Passing all of that, it actually spawns the binary and kills it immediately, because the only honest way to know whether this kernel can exec a file is to ask this kernel. The --version probe below is that spawn, so the exec proof and the version answer cost one child rather than two.
shep delete <name>disable's counterpart for a third-party dog: stops it if running and forgets where its binary lived, rather than leaving it disabled-but-known. That is one file, the registration in shep.toml. The dog's own [<name>] section in dogs.toml stays, webhook URLs and all, exactly as disable leaves it: those settings are yours rather than the adoption's, so adopting the same dog again finds them waiting. Delete that section by hand when you want them gone. What disable keeps and this does not is the adopted path, so bringing the dog back takes a fresh shep adopt.
$ shep adopt ./bin/my-watchdog --name watchdog NAME SOURCE SHEPHERD STATUS watchdog adopted true online $ shep delete watchdog NAME SOURCE SHEPHERD STATUS watchdog adopted true stopped
Once adopted, shep watchdog [args...] runs it directly — git and cargo's own precedent (git foo runs git-foo), resolved against adopted dogs only, never a $PATH scan. It's a second invocation mode, distinct from the shepherd's own: an adopted dog the shepherd starts gets no argv and the two variables shep names it by, beside whatever the operator set in its env; a dog you name on the command line gets whatever you typed after it, plus those same two. A built-in dog is the exception, and not one you can write: the shepherd starts it as shep dog <name>. A built-in verb or alias, help included, always wins over a same-named dog.
An adopted dog is part of shep's listing from then on: it appears in the Dogs group of shep --help, and completion offers it. An undeclared dog is listed bare. Nothing a manifest declares claims a top-level verb: a dog gets exactly shep <name>.
What gets recorded in shep.toml is the canonicalized, absolute path because the daemon may resolve it again after a reboot from a different working directory than the one adopt ran from.
The wire a third-party dog speaks is the client protocol every other client uses: connect to the Unix socket at $SHEP_HOME/run/shep.sock, send Hello, wait for HelloAck, then send Request::DogConfig { name } to fetch your own section as opaque text. Send Request::DogConfigResolved { name } instead to have each {{secret:...}} replaced by its value; DogConfig still gives the text as written. A Rust dog on shep-client gets this from dog_config unchanged. Against a shepherd too old to know the request it reads the plain section, and refuses one naming a reference as unsupported. Shep sets two variables of its own on a dog: $SHEP_HOME, which is how it finds that socket in the first place, and $SHEP_DOG_NAME, which is the name to put in that request. No [<name>] value rides along beside them. A third, $SHEP_DOG_FD on unix or $SHEP_DOG_PIPE on Windows, names a connection open before the socket is, and on unix survives a shepherd upgrade. Use it first and fall back to the socket.DogRuntime does.
Put that name in the Hello too, as dog_name. It is optional, and nothing breaks without it right up until the shepherd is replaced by one your binary is too old to speak to. A refused handshake never reaches a request, so the name in DogConfig is unreadable at exactly the moment it is needed: which dog to restart. With it, the shepherd restarts you once from the binary on disk, which fixes the ordinary case where the package already replaced your file and the running process is merely old, and reports you stale rather than looping if that restart is refused too. shep daemon reload prints that report to the operator, after your reconnect rather than before it: what the old image knew about you described a process that was about to stop existing. Without it you go quiet.
A dog written against shep-client gets both halves from ReconnectingClient::connect_as_dog, which fills the name in and also re-establishes the connection when the shepherd is replaced. Client does neither on its own, deliberately: the CLI uses it, and a shep stop that silently retried could stop a sheep twice. It reconnects when asked, through Client::reconnect, which reports whether the daemon now answering is the one from before. The rest every dog repeats, from section to exit codes, is in shep_client::dogs.
That is what shep daemon reload asks of a dog. A dog is carried across the reload the way a sheep is: the process is a child of a shepherd whose pid does not change, so it keeps its own pid and its restart count stays where it was. What does not survive is the accepted connection, which dies with the old image — so a dog that does not dial again is a live process holding a dead socket. Both built-in dogs are measured holding their pid and restarts 0 across ten reloads, still serving and delivering.
A subscription belongs to one connection too, so a dog that has one asks for a new one. Nothing re-arms it for you, on purpose: a stream that papered over the gap between one connection dying and the successor accepting a fresh Subscribe would leave you no way to know there had been a gap. Ask again, and treat the gap as a gap, since whatever the bus carried in between is gone and only the shepherd knows what changed.
A dog waits five seconds for a shepherd to answer again and exits if none does. Both halves matter. A dog that exits the moment its connection drops restarts once per reload, which reads as an unhealthy dog on the one column that judges it; a dog that waits forever is still running when an unrelated shepherd binds that socket later, and attaches itself to that one beside its own dog of the same kind. A handover never comes near five seconds: measured over ten shep daemon reload runs against a three-sheep flock, the socket turned away a full connect, handshake and request for 38ms at the shortest and 254ms at the longest. ReconnectingClient::link_lost and connected_within are what a third-party dog imposes that bound with; the client itself reconnects for as long as it is alive.
Check the budget at the top of your own retry loop. connected_within answers Ok for a link that is already up without consulting the budget, so it cannot be the thing that ends one. A shepherd that answers the handshake and then fails whatever you ask it, which one slow enough to miss your request's deadline does, leaves a loop bounded only by that call running for as long as it stays up, and a dog doing that stays online on every column a listing has while doing nothing. shep's own bark dog had this bug during development, written like this:
loop {
let left = budget.saturating_sub(started.elapsed());
client.connected_within(left).await?;
match client.subscribe(topics.clone()).await {
Ok(stream) => return Ok(stream),
Err(_) => continue,
}
}Check the budget at the top of your own loop and return when it is spent.
Three answers in the EXIT column, not two. A dog that gave up waiting exits 5. One a shepherd refused on protocol-version skew exits 6 without waiting, since the shepherd that refused is the party that can fix it. And a dog whose shepherd answered and then refused its request exits on that refusal's own code, 13 for an unsupported request, the same code it would have exited had the refusal come at startup rather than after a handover.
Those are what shep adds, not the whole environment. A dog is a supervised process like any other, so it also starts from the small base every sheep gets: PATH, plus whichever of HOME, USER, LANG and TZ the shepherd itself has, plus SHEP_INSTANCE, SHEP_NAME and SHEP_ENVIRONMENT. SHEP_NAME carries the same value SHEP_DOG_NAME does; SHEP_ENVIRONMENT is the same one a provider dog reads when it decides which environment to fetch and push, since a dog has no environment field of its own and falls back to [daemon] environment the same as any sheep would. Nothing from [<name>] is in there. What an operator sets in env beside your path in [daemon.adopted_dogs] is, resolved the way a sheep's env is, and SHEP_HOME and SHEP_DOG_NAME are set over anything it claims for those two names.
$SHEP_DOG_NAME rather than hardcoding a name. It
holds the name you are registered under, which is the operator's --name if they gave one and otherwise your own file stem
with a leading shep- stripped. Shep sets it every way it
runs you: supervised, shep <name>, and the exec
probe during adopt itself. Getting the name wrong is silent, which is the whole reason
the variable exists: a DogConfig for a name nobody
adopted comes back empty, exactly what a registered dog with no
section gets, so a one-character mismatch discards the operator's
whole section, uses every default instead, and prints nothing on
either side. If the variable is absent you are not being run by a
shep that sets it, and the fallback is the pid: your process knows
its own, ListFlock reports one per entry, and the entry
marked as a dog carrying your pid is you.
Request::Flush as part of rotating anything.
Its name reads like settling a buffer and it does the opposite of
what a rotator wants: it flushes what is pending and then truncates the recorded paths. That is shep flush, an operator deliberately emptying logs.
Reaching for it before a rename deletes the lines you were about to
rotate. Rename, then Reopen: that shape has no such
hole.
Somebody else has probably already written the dog you're about to build; see the community list before you start, or run shep dogs --available to browse the same index without leaving a terminal.
Answering --shep-manifest
shep adopt asks --shep-manifest first. A dog answers on stdout with one JSON object and exits 0; manifest (the version, 3; 1 and 2 still read), name, version and protocol are required, and a field shep doesn't know is ignored. The fields are listed in docs/dogs.md.
A non-zero exit, no output, or output that isn't a manifest means the dog has none, and shep asks --version and --schema as before. Otherwise the manifest's version, protocol, channel and settings replace those answers. It is cached in $SHEP_HOME/manifests by the binary's sha256: a build is asked once, and a rebuilt binary is asked again.
defaults is TOML text for the body of the dog's own section. When a manifest carries it and dogs.toml holds no section for the dog, shep adopt writes it as that section: the adopted dog arrives with its knobs filled in, where the operator edits them, so a dog needs no --print-config-style flag of its own any more. A section the operator already wrote is never touched, and a defaults that is not valid TOML earns a warning, not a refusal.
notice[dog_defaults_written]: otel's manifest defaults are now its `[otel]` section in dogs.toml, where you can edit them notice[dog_defaults_unreadable]: otel shipped a manifest whose `defaults` is not valid TOML, so nothing was added to dogs.toml for it. The dog is adopted and runs normally; this is a bug to report to whoever wrote it
depends names the dogs a dog needs and the oldest shep it supports. shep adopt and shep enable warn when a named dog isn't adopted or this shep is older, and go ahead anyway. shep install goes further: see Dependencies.
validate says the dog has checks its settings schema cannot state. They run over the channel, so it needs channel: shep adopt refuses a manifest declaring one without it. Being asked is below.
pane says the dog answers shep.pane with a status pane for lookout to draw. It needs channel: without one the manifest reads pane as false and shep adopt says the dog has none. Nothing asks for a pane yet.
launch says the dog runs a sheep's command, as <path> launch <sheep> -- <cmd>. shep adopt refuses a dog adopted as sandbox without it. Under any other name it is never asked.
verb is how shep describes shep <name>: its description is the dog's line in the Dogs group of shep --help, its subcommands are what shep <name> --help prints and what completion offers, each with an optional usage of the words after its name, and its examples are up to three command lines, each without the $ shep prints. A Rust dog on clap writes none of it by hand: Verb::from_clap(&Command), behind shep-client's clap feature, reads the about, every visible subcommand's name, about and override_usage, and the Examples: block render_examples writes to after_help. shep adopt warns, and adopts anyway, past 60 columns of description or a fourth example. Every adopted dog gets shep's page for shep <name> --help, -h and shep help <name>; shep <name> help still reaches the dog. No verb gets a stub: name, version, cached index description. Neither fetches the index or runs the binary, and completion is generated from the registry, so generate the script again after an adopt. A manifest's text prints as one line: braces, newlines and escapes go. A name a shell would read as code is not completed.
notice[dog_dependency_missing]: `otel` depends on `log-rotate`, which is not adopted, so `otel` may not work until you run `shep adopt` for `log-rotate` notice[dog_needs_newer_shep]: `otel` needs shep 0.20.0 or newer, and this is shep 0.16.1, so `otel` may not work until you upgrade shep notice[dog_verb_declaration]: `otel` declares more in its manifest `verb` than shep's help holds: a description of 71 columns, where shep's help fits 60. The dog is adopted and its help still prints; this is a bug to report to whoever wrote it
Showing a pane
A dog that declares pane answers shep.pane with what the operator should read: sections of label and value pairs, tables with a key per row, and the actions that go with them. Lookout draws the answer as written, so every value is a string the dog has already formatted. Probe::pane sets the flag and needs ask_for_channel: shep adopt reads a pane without a channel as no pane, and says so. pane_answer writes the reply body, from a pane built afresh on each ask.
use std::sync::{Arc, Mutex};
use shep_client::dogs::{Destructive, PANE_ACTION, Pane, Probe, Row, pane_answer};
fn build(models: &[String]) -> Pane {
Pane::new()
.fields("host", [("VRAM", "20 GiB")])
.table(
"models",
["MODEL", "STATE"],
models.iter().map(|m| Row::new(m, [m.as_str(), "loaded"])),
)
.row_action("unload", "Unload", Destructive::Yes)
}
fn main() {
Probe::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
.ask_for_channel()
.pane()
.action("unload", "Unload a model")
.answer::<MyDogConfig>();
let models = Arc::new(Mutex::new(vec!["qwen3-32b".to_string()]));
let shown = Arc::clone(&models);
let shepherd = shep_channel::serve();
shepherd.on_action(PANE_ACTION, move |params, _name| {
pane_answer(params, || build(&shown.lock().unwrap()))
});
// A row action arrives as {"row": "<key>"}.
shepherd.on_action("unload", move |params, _name| {
let row = params
.and_then(|p| serde_json::from_str::<serde_json::Value>(p).ok())
.and_then(|p| p["row"].as_str().map(str::to_owned));
models.lock().unwrap().retain(|m| Some(m) != row.as_ref());
"unloaded".to_string()
});
// ...the dog's own loop.
}The body is one JSON object, which a dog in any language can write by hand:
{"sections":[
{"kind":"fields","id":"host","title":"host","refresh_on":[],
"fields":[{"label":"VRAM","value":"20 GiB"}]},
{"kind":"table","id":"models","title":"models","refresh_on":[],
"columns":["MODEL","STATE"],
"rows":[{"key":"qwen3-32b","cells":["qwen3-32b","loaded"]}],
"row_actions":[{"action":"unload","label":"Unload","destructive":true}]}
],"actions":[]}A row holds one cell per column, and a section id or a row key may not repeat: Pane::body refuses them, and shep cannot read a body that has them. A row action is triggered with {"row": "<key>"} and a pane action with no params. Each name is declared with Probe::action and answered by its own on_action handler.
Answering --version
A dog answers --version on stdout and exits 0. Two numbers come back, and they answer different questions.
shep-protocol Whether this dog can handshake with this shepherd at all. Below the floor it can't connect; above it, shep accepts it.shep-channel Optional. true asks for the shepherd channel.shep-log-rotate 0.1.3 shep-protocol: 8
Line 1 is <name> <version>. Shep takes the last whitespace-separated field as the version and ignores the name, so a crate whose name differs from the dog's registered name is fine. That's the line clap already prints for free. Every later line is <key>: <value>, one pair to a line, and shep-protocol carries in decimal the PROTOCOL_VERSION the binary was compiled against.
Unknown keys, blank lines and the order of the key lines are all ignored. Keys beginning shep- are reserved, so a third number can get its own line later without breaking a parser that predates it. Put keys of your own under a prefix of your own.
Lines rather than JSON, because a human runs --version far more often than shep does, and because a stranger writing a dog in a language shep has never seen gets two printf calls right on the first try. Hand written JSON is where the quoting and the trailing comma go wrong, and nothing here nests.
A dog written against shep-client answers this probe and the schema one below with a single call, as the first line of main:
fn main() {
shep_client::dogs::probe::<MyDogConfig>(
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
);
// ...normal startup, reached only when this run is not a probe.
}It prints the answer and exits when shep asked a question, and returns when it didn't, so nothing after it runs on a probe: put it before anything has been opened. The name and the version are arguments because env! expands where it's written, and they're the two facts only the dog knows. The flag names, the shep-protocol key and the number it carries all come from shep. That's the point of the call: they were hand-typed from this page until it existed, and a typo in any of them read as "protocol unknown" with nothing saying so.
What shep adopt does with the answer
shep adopt asks the candidate before it records anything. The vet was already spawning the binary to prove this kernel can exec it, so the question costs one argument on a process that was going to start anyway.
shep-protocol below the floor Refuses, before shep.toml is touched.The refusal names both numbers and both ways out:
/usr/local/bin/shep-otel: this dog was built for shep protocol 6, and this shep needs 8 or newer; reinstall the dog without --locked so it builds against the current shep-core, or run a shep that accepts protocol 6
Only a stated protocol can refuse an adopt. The version is never compared with anything, because a third-party dog's crate version has no relationship to shep's own: shep-log-rotate 0.1.3 against shep 0.1.24 is the ordinary case, not a skew, and comparing the two would report every dog that exists.
A candidate gets one second to exit and another to have its output read, and an adopt runs up to three probes, so roughly six seconds is the worst case. It is killed either way, so a dog that ignores every flag and runs costs that time and is adopted with an unknown protocol. It can't hang the adopt that's vetting it.
Only a channel ask is written down. A protocol stored at adopt time would be a copy of a number that can change on disk with nothing watching, so shep asks the binary again rather than remembering what it said.
Asking for the shepherd channel
A dog gets no channel unless it asks. One that wants shep trigger <dog> <action>, or to be stopped by a message, adds a line to its answer:
shep-otel 0.2.0 shep-protocol: 12 shep-channel: true
shep adopt records the ask in [daemon] channel_dogs, and shep starts the dog with channel and shutdown_with_message set. Only true asks. shep adopt reads the line again, and a running dog picks up the change at shep disable then shep enable.
use shep_client::dogs::{Probe, Stop};
fn main() {
Probe::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
.ask_for_channel()
.answer::<MyDogConfig>();
let (stop, request) = Stop::new();
let shepherd = shep_channel::serve();
shepherd.on_action("rotate", |_params, _name| "rotated".to_string());
shepherd.on_shutdown(move || request.request());
// ...the dog's own loop, watching `stop`.
}Serve it with shep-channel. A stop is the shutdown message with no signal behind it, so a dog that ignores it is killed once kill_timeout runs out.
Declaring actions and reading the caller
Probe::action declares an action in the manifest, and shep trigger <dog> lists them. A handler registered with on_action_with_caller is told the dog that triggered it, or None for an operator.
Probe::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
.ask_for_channel()
.action("rotate", "rotates the signing key")
.answer::<MyDogConfig>();
// ...later, once the channel is served:
shepherd.on_action_with_caller("rotate", |_params, _name, caller| {
format!("rotated for {}", caller.unwrap_or("the operator"))
});Publishing events
Probe::event declares a kind in the manifest, and DogRuntime::publish sends it with a JSON payload the shepherd never reads. Subscribers hear it as dog.<name>.<kind> and need events:dog.<name>. A kind the manifest does not list is refused by name, and so is a publish from the control socket or from a dog whose name has a dot in it.
Probe::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
.event("exported", "a batch was sent")
.answer::<MyDogConfig>();
// ...later, with a DogRuntime:
runtime.publish("exported", serde_json::json!({ "batch": 3 })).await?;Work longer than a trigger
A trigger's reply waits at most the callee's action_timeout. Work that runs longer answers at once with an id, then reports its result as one of the callee's own events. The shepherd keeps no state for it.
- The callee returns the body from
ActionId::accept, which carries a fresh id, and runs the work elsewhere. - When the work ends,
DogRuntime::finish_actionpublishesaction.donewith that id and either a result or an error. The callee declares the kindDONE_KINDlike any other. DogRuntime::trigger_and_waitsubscribes before it triggers, so a result published at once is not missed, then waits for the event with that id. Its timeout starts when the callee has answered.
use shep_client::dogs::{ActionId, Probe};
Probe::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
.ask_for_channel()
.action("build", "build the site, reporting when it is done")
.event(shep_client::dogs::DONE_KIND, "a long action ended")
.answer::<MyDogConfig>();
// ...later, with the runtime in an Arc and a tokio Handle:
shepherd.on_action("build", move |_params, _name| {
let (id, reply) = ActionId::accept();
let runtime = Arc::clone(&runtime);
handle.spawn(async move {
let outcome = run_build().await.map_err(|err| err.to_string());
if let Err(err) = runtime.finish_action(&id, outcome).await {
eprintln!("build result not published: {err}");
}
});
reply
});// Needs dogs.trigger:builder and events:dog.builder.
let done = runtime
.trigger_and_wait("builder", "build", None, Duration::from_secs(600))
.await?;
println!("action {} returned {}", done.id, done.result);The caller needs events:dog.<callee> as well as dogs.trigger:<callee>, and the error names the one it lacks. Every holder of events:dog.<callee> hears every result, so the id correlates and keeps nothing private. The subscription replaces any other the caller's connection holds. A callee with a dot in its name cannot publish, so it cannot finish a long action.
Being asked about a write to its settings
A schema says what a value looks like, not what it means. A dog holding checks of that kind declares validate, and shep asks it before it writes: a shep.validate action on the dog's channel, carrying the table the write would leave behind.
use shep_client::dogs::{Probe, Stop, Verdict, validate_answer};
fn main() {
Probe::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
.ask_for_channel()
.validate()
.answer::<MyDogConfig>();
let (stop, request) = Stop::new();
let shepherd = shep_channel::serve();
shepherd.on_action("shep.validate", |params, _name| {
validate_answer(params, |proposed| {
match proposed.table().get("checkout").and_then(|v| v.as_str()) {
Some("/srv/api") => Verdict::Accept,
_ => Verdict::refuse("this checkout belongs to another project"),
}
})
});
shepherd.on_shutdown(move || request.request());
// ...the dog's own loop, watching `stop`.
}The reply is an ordinary action-reply whose body is one JSON object: accept true, or accept false beside areason the operator reads. validate_answer writes that body from the dog's own check. A body shep cannot read is a refusal.
The params carry table: the dog's whole table on that sheep, or its own dogs.toml section when there is no sheep. It is the table after the write, so a shep unset is judged on what would be left. Silence refuses: a dog that answers nothing inside its action_timeout has not cleared the write.
Two cases ask nobody, and the write lands: a dog the shepherd has no live channel for (not in the flock, stopped, or started before it asked for one), and a dog with no manifest. A dog has no manifest when this machine never adopted it, and when it answers --shep-manifest with nothing at all: a build older than the flag, one whose argument parser rejects an unknown flag, one that ignores the flag and starts its loop. None of those ever declared validate. What shep cannot read is never an acceptance: a cached manifest for this exact binary that neither reads nor answers, and a shep.toml that will not parse, both stop the write and name it.
validate without channel is refused at adopt, because the check could never run:
error[invalid_config]: this dog's manifest asks to be consulted before a write to its settings, and declares no channel to be consulted on; declare `channel` in the manifest, or drop `validate`
What shep restart <dog> does with the answer
cargo install replaces a file and never touches a process, so a dog upgraded on disk leaves a working system: the dog running now is the old binary, still connected, still doing its job. The two only meet at the next restart, which may be days away and for a reason that has nothing to do with the upgrade.
shep restart <name> is that restart, so it asks the same question first:
notice[dog_binary_skew]: `log-rotate`'s binary at /usr/local/bin/shep-log-rotate was built for shep protocol 6, and this shep needs 8 or newer; restarting it brings it back on that binary, unable to connect. Run a shep that accepts protocol 6, or reinstall the dog against protocol 8, and restart it again
Then it restarts the dog. This is a warning and never a refusal: the operator asked for the restart, the binary on disk may be exactly what they just installed, and there are two ways out of the state rather than one, so the message names both and picks neither.
shep-protocol below the floor Warns, then restarts.Unknown is not stale. Every dog written before this contract is in the last two rows, and a line on stderr for each of them is how an operator learns to skip the one that matters.
Three things are never asked at all. A built-in dog has no binary of its own, so there is nothing to be stale. A selector that sweeps rather than names, all or a /regex/, doesn't reach a dog in the first place. And a dog named by id rather than by name is restarted without a check, because looking up its name would cost a round trip before the restart the operator asked for.
The cost is the same second adopt spends, and it's paid only by a restart that named an adopted dog. A binary that hangs is killed when the second is up and the restart goes ahead unwarned, so the slowest a dog can make shep restart is two seconds, never indefinitely.
A named restart briefly runs your dog twice. To read the binary on disk, shep runs it with --version, and a dog that does not recognise that flag ignores it and starts doing its ordinary job instead, with SHEP_HOME pointing at the live shepherd. So a rotator can rotate once, and a bark dog can open a second subscription, before the process is killed.
Only dogs that ignore the flag are affected. A dog that recognises --version and exits, even without naming a protocol, does no work: its protocol is unknown and nothing overlaps. The trade is deliberate: the command is about to restart that dog anyway, so the only question is whether it briefly overlaps itself, and the alternative is not asking at all. Adding --version to your dog removes the overlap, since a dog that answers exits immediately.
Why the binary is the only thing that can answer
A dog's crate version doesn't imply its protocol, and neither does knowing that somebody installed it. Which shep-core a dog ends up carrying depends on how it was built:
cargo install <crate>, first time shep-core is re-resolved to the newest compatible release, so the protocol is current.cargo install <crate>, already installed Nothing is built. Cargo prints already installed, use --force to override and exits 0, so the protocol stays exactly as stale as it was.cargo install <crate> --force Rebuilt and re-resolved, so the protocol is current. This is the one that upgrades a dog after you upgrade shep.cargo install --locked, and most CI The shipped lockfile is honoured, so the protocol is whatever was pinned on publish day.<crate> is the package name on crates.io, which is not always what you call the dog. A dog's adopted name, its binary name and its crate name are three separate things: shep-log-rotate installs a binary of the same name that is usually adopted as log-rotate. Cargo wants the crate.
The middle row is the one that catches people, because it looks like it worked. A dog's own version does not change when the shep it was built against does, so the rebuild you need after upgrading shep is exactly the case cargo declines to do, and it says so in one line before exiting successfully. Reach for --force whenever you are reinstalling a dog rather than installing one.
Measured 2026-08-31: shep-log-rotate 0.1.3 installed plain compiled shep-core 0.1.24, ignoring the packaged lockfile, while the same crate built --locked produced a protocol 1 dog. Both published dogs were shipping a lockfile pinning a protocol 1 shep-core that day, and both repositories' CI had been red on it for two days. The crate version was identical either way. That's the whole argument for asking the binary: nothing outside it knows.
The built-in dogs are outside this
metrics and bark are not separate binaries. The shepherd starts them as <its own binary> dog <name>, so a built-in dog is the shep binary that spawned it and cannot skew from it on disk. There's no question here for a contract to answer:
$ shep --version shep 0.1.24 speaks protocol 9, accepts 8 and newer $ shep dog metrics --version shep-dog 0.1.24 speaks protocol 9, accepts 8 and newer
Neither prints the shep-protocol: line an external dog's probe answers with, and that isn't a gap to close. The protocol a built-in dog speaks is the shepherd's own, because it is the shepherd's binary.
What this doesn't catch
Two dogs can clear the protocol floor and still be different code. RpcError gained a public daemon_version field inside the 0.1.x range; its fields are public and it has no constructor, so every literal built outside shep-client stopped compiling while PROTOCOL_VERSION stood still. Speaking a protocol shep accepts is necessary and not sufficient.
Closing that is deferred, and the reason is that --version can't close it. A break of that kind is source level: it lands when the dog is compiled, in the dog's own repository, and a dog nobody rebuilt keeps running. Shep has no table of which shep-client versions build against which daemon, and a version comparison standing in for one would report dogs that are fine. What catches it is the dog's own CI building against a current shep-core, which is where both published dogs' breakage was already visible and unread.
Answering --schema
shep adopt asks a second question straight after the first: --schema, answered on stdout with a JSON Schema for the dog's own [<name>] section. Same shape as --version and the same budget: spawn, read, kill.
Asked of the binary rather than over the socket, because the dog most in need of configuring is the one that's disabled or has never started, and it has no connection to answer on. Configure then enable is the order an operator wants.
probe answers this flag too, from its type parameter. Put #[dog_config] above the derives on the type the dog deserializes its config into, and mark every field holding a credential:
use shep_client::dogs::dog_config;
use shep_client::shep_core::values::{MemSize, UpDuration};
#[dog_config]
#[derive(Default, serde::Deserialize, schemars::JsonSchema)]
#[serde(deny_unknown_fields, default)]
struct MyDogConfig {
/// Where to POST. Doc comments become the schema's descriptions.
#[shep(secret)]
webhook: String,
/// What to watch.
path: String,
/// How much to buffer before posting: `4M`, `512K`, or a byte count.
batch: Option<MemSize>,
/// How long to wait between posts: `30s`, `500ms`, `2h`.
every: Option<UpDuration>,
}#[shep(secret)] says the field is a bearer credential, and shep renders one as <set>: replaceable, never read back. The attribute exists rather than the schemars extension it writes because that extension key is a string the author types, and a transposed letter in it compiles, validates, marks nothing, and paints the credential on screen.
#[dog_config] before reaching it, so a JsonSchema derive listed first has already built its impl
by the time the mark goes on the field. That's a compile error naming
the fix, not a field that quietly ships unmarked.
The mark travels with the field. A #[serde(rename)] carries it to the renamed property, and a credential inside a nested struct or a map's values is marked in every config that holds that type. Mark the field holding the credential, at whatever depth it sits. Bark marks its sinks map as well as each sink's URL, which redacts the collapsed map a pane shows before anyone opens it.
MemSize and UpDuration need no dependency of their own. A dog configuring a size or a timer reads them out of shep_client::shep_core::values, and shep-client's schema feature turns on the shep-core feature those two JsonSchema impls sit behind. Neither type has a Default, so a field holding one is an Option or carries #[serde(default = "...")].
A schema's own bounds are checked in the editor rather than after the write: a pattern, a minimum, a maximum, an exclusiveMinimum, an exclusiveMaximum or an enum of numbers refuses the value there and says what the field does take, and a range with nothing in it says so once. Another reason to publish the narrow thing over a bare string, since shep writes the section without reading it.
--version is. A dog
that says nothing is adopted, recorded as having no schema, and
refused nothing, which is every dog written before this contract. What
it gives up is the pane below: with no schema to render a form from,
its section stays a file an operator hand-edits.
What answering buys is a config pane. e on the dog's row in shep lookout, whether that row sits in the dashboard's own Dogs section or on the settings screen's dog row, opens a form over its [<name>] section: one row per property, the value the section sets beside it, (unset) where it sets none, and <set> where a field is marked as a credential. A property the schema gives a default still reads (unset): the pane shows the file, not the dog's own fallback. It writes too, behind --allow-control, and it writes the section whole, so the comments in dogs.toml survive an edit shep made. The lookout page has the keys and the rest of the rules.
The schema is asked for again when the pane opens, not cached from when the dog was adopted, so the dog does not have to be running. Configure then enable is the order an operator wants, and it works.
--schema, waits a second for an answer, then kills
it, on the same terms shep adopt asks on. That is a third
party's code executing because somebody pressed a key, so it is worth
knowing before browsing the config of a dog you did not write. A
built-in dog is shep's own binary and is never spawned.
A dog that answers something that isn't JSON gets one line, and is adopted anyway:
notice[dog_schema_unreadable]: pydog answered `--schema` with something that is not JSON, so shep has no description of its settings and they stay a hand-edited section. The dog is adopted and runs normally; this is a bug to report to whoever wrote it
Silence earns no such line, for the reason an unstated protocol earns none: it's the ordinary case, and a notice for every dog is how an operator learns to skip the one that matters.
The answer isn't written down, on the same rule the protocol number follows. cargo install replaces a binary with nothing watching, and a stale schema is worse than a stale version number, because it mislabels which field is a credential. Shep asks the binary again when it needs one.
Reading a sheep's own table
A dog declares one settings type. Its [<dog>] section is the value for every sheep, and a sheep's own [app.dogs.<dog>] table overrides any key the type doesn't mark #[shep(dog_wide)]. A dog-wide key is set in the section only, for a thing with one value per dog, such as a poll interval.
use shep_client::dogs::{DogRuntime, Probe, Serves, dog_config};
#[dog_config]
#[derive(Default, serde::Deserialize, schemars::JsonSchema)]
#[serde(default)]
struct Jobs {
/// How often to look. One value for the dog.
#[shep(dog_wide)]
poll: String,
/// Which model reviews this sheep.
model: String,
}
// First thing in main, before `DogRuntime::start`.
fn declare() {
Probe::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
.serves_every_sheep()
.answer::<Jobs>();
}
async fn run(runtime: DogRuntime) -> Result<(), Box<dyn core::error::Error>> {
let poll = runtime.config::<Jobs>()?.poll;
for (sheep, settings) in runtime.sheep_settings::<Jobs>(Serves::EverySheep).await? {
match settings {
Ok(jobs) => review(&sheep, &jobs.model, &poll),
Err(err) => eprintln!("{sheep}: {err}"),
}
}
Ok(())
}serves_every_sheep() puts serves in the manifest. Left out, a dog serves only the sheep that carry a table, which is also what a manifest from before the field means. sheep_settings takes the same value and returns one entry per served sheep, each its own Result, so a table that doesn't fit never hides the rest. A dog serving every sheep gets an entry for one with no table, equal to the section without its dog-wide keys.
A dog-wide key set in a sheep's table is an error for that sheep, and the error names the key. A dog-wide key is also left out of every sheep's settings, so give the field a serde default and read its value from runtime.config(). The layering runs in shep-client, over requests that already exist. Subscribe to config.sheep.<dog> to hear one table change.
A {{secret:...}} in the section resolves in the dog's environment, and one in a sheep's table in that sheep's own. sheep_settings needs the schema feature.
Publishing a per-sheep schema
The one type is the schema. answer::<T> publishes it for shep lookout, and #[shep(dog_wide)] writes x-shep-dog-wide: true on the property, beside x-shep-secret. Both marks can sit on one field: #[shep(secret, dog_wide)].
The older form, probe_with_sheep::<T, S> and answer_with_sheep, keeps working. It publishes a second schema under x-shep-sheep and leaves the layering to the dog. It stays until no published dog uses it.
Your dog's own docs page
A row in web/public/dogs.json whose repo is under github.com/shep-pm/ gets a page at /docs/dogs/<adopt_as>, which the community list links once the build has one. That page is your repository's README.md read at the tag of its latest GitHub release. Nothing is copied into this repository, and a README no release has reached never shows up here.
A relative .md link becomes a page under your dog's page, at any depth, and keeps its #fragment. A relative image or other file points at the repository at that same tag. An absolute URL is left alone, so a link off this site is one you write as absolute.
Your repository dispatches this site's pages.yml when it publishes a release, which is what rebuilds the page. A release made with the default GITHUB_TOKEN fires no release: published another workflow can hear, so a release-plz setup handed GITHUB_TOKEN never dispatches: it needs a real PAT.
Releasing a dog
shep install downloads a prebuilt binary when the index row holds a hash for the machine's target, and builds the row's version from source when it doesn't. One job in your release workflow produces both.
name: Release
on:
release:
types: [published]
jobs:
binaries:
permissions:
contents: write
actions: read
uses: shep-pm/shep/.github/workflows/dog-release.yml@<full commit sha>
with:
package: shep-log-rotate
tag: ${{ github.event.release.tag_name }}
# Optional: targets this dog can't build, space separated. Any but
# x86_64-unknown-linux-gnu, which the row's permissions are read from.
# skip-targets: x86_64-pc-windows-msvc
secrets:
index-token: ${{ secrets.SHEP_INDEX_TOKEN }}For every target shep ships for, the workflow runs cargo build --release --locked and attaches the bare binary to your release as <package>-<version>-<target>, with .exe on Windows and no archive. It then opens a pull request on shep-pm/shep that sets your row's version, sha256 and permissions. Merging it is the review; until then shep install approves the old version.
The permissions come from the binary itself. The workflow runs the x86_64-unknown-linux-gnu one with --shep-manifest and writes each permission's name and whether it is required, in your manifest's order. Nothing else in the manifest reaches the index. A dog that asks for nothing prints no permissions key, and its row gets the empty list that says so. A binary that answers no manifest, or runs past 60s, costs the row its list and not the release: the run says so in its job summary.
The tag must be v<version>, matching Cargo.toml at that tag. A real run needs the release to exist before the job runs; a dry run doesn't. The workflow updates a row, never adds one, and the row needs source.kind set to cargo. For a first release, add the row by hand with its version and no hashes; shep install builds that version from source until a later release adds them. Pass bin when the binary isn't named after the package.
Pin uses: to a full commit sha, not main or a tag. The workflow runs with your contents: write and your index-token, so a ref that can move lets a later change to it run with both. Move the sha when you choose to.
The job needs contents: write, actions: read and an index-tokensecret: a GitHub App token or a personal access token that can push a branch and open a pull request on shep-pm/shep. GITHUB_TOKEN can't write to another repository.
To see the hashes without releasing, run Dog release from the Actions tab of shep-pm/shep with your package, an existing tag and your repository. It uploads and opens nothing. dry-run: true does the same from your own job.