Cowboy
Persistent agents on infrastructure you control.
Cowboy runs persistent AI agents on infrastructure you control, using Nix to configure their tools, credentials, message access, and approved actions.
The strongest documented deployment is managed NixOS on Linux/x86-64. Local and ordinary Docker paths have different boundaries and hold credentials locally. The OCI runtime is a specialized optional route for Cowboy’s own payload.
Why run an agent this way?
A maintenance task can produce a reviewed change without giving the agent the credential that publishes it. The repository’s effects runner check exercises adding a documentation post to a Git repository: it describes a commit bundle, applies it, and verifies the remote branch. This is a recorded test workflow, not a claim about production adoption.
In a deployment with the effects bridge and Discord approvals configured, the agent requests publication. The publishing runner checks the bundle and produces a card naming the target, execution identity, exact SHA, changed files, and diffstat. An authorized human reacts ✅ to push exactly that commit or ❌ to reject it. The runner executes under the configured publishing identity, checks policy again, and refuses a branch that moved after review. The result appears in the agent’s effects inbox and the configured operator status channel. Gated effects explains the configuration.
Choose a deployment
| Goal | Route | Boundary |
|---|---|---|
| Evaluate in a terminal | Local CLI and Zellij | Invoking user’s permissions; local credentials |
| Run a persistent managed service | NixOS systemd service running Montana | Per-agent component, shared service hardening envelope, network namespace, credential proxy, Sheepdog, and broker controls |
| Run on an ordinary Docker host | Self-contained image | Docker isolation; credentials in the container’s state volume |
| Integrate Cowboy’s payload with an OCI engine | Optional Cowboy OCI runtime | Bundle policy and configured cage; specialized command surface |
The full deployment matrix includes host requirements and state locations. “Production path” means the intended supported managed configuration, not measured adoption or general runtime certification. Its agent daemon runs Montana directly, without the OCI runtime.
Network restrictions, filesystem access, tool policy, and approval gates are separate controls. HTTP policy restricts methods and destinations; it does not promise that every permitted request leaves external state unchanged. Data an agent can read can leave through permitted requests or replies. Read the security model before granting sensitive access.
Start here
Continue to Installation, which maintains release availability and source-build instructions. Then use First request and daily operation and Troubleshooting.
Configuration explains how to change the
agent. Architecture explains the implementation
and the cowboy:agent@0.2.0 component contract.
Deployment paths
Choose the boundary before installing. The strongest documented deployment is managed NixOS on Linux/x86-64. Local and ordinary Docker paths deliberately hold credentials; the optional OCI route runs Cowboy’s own payload. These paths do not form a ladder, and tool behavior depends on each path’s policy.
| Path | Host requirements | Process identity and controls | Credentials | Mutable state | Primary limitation |
|---|---|---|---|---|---|
| Local evaluation | Nix source build; Zellij for the UI; Linux or macOS with the dependencies | Invoking user; Zellij harness or native Montana | Environment, user/system key files, or readable agenix files | Local XDG data/config directories and workspace | File and shell tools have the user’s permissions; no managed proxy or service envelope |
| Managed NixOS | NixOS, Linux/x86-64; configured operator and provider secret | Configured agent user; Montana under systemd, shared hardening envelope, network namespace, credential proxy, Sheepdog, broker ACLs | Proxy-readable secret files outside the agent; agent receives placeholders | Agent home, configured writable mounts, broker/bridge state | Controls depend on configuration; readable data is not confidential from permitted egress |
| Ordinary Docker | Source-built image; Docker on a matching Linux image architecture | Container root; ordinary Docker isolation; wizard uses Zellij, settings-based service uses Montana | Mode 0600 key file in the configuration volume | Configuration and workspace volumes; explicitly persist the data directory | No managed credential proxy or Cowboy cage; settings-based CLI launch does not itself mount the default data directory |
| Optional OCI cage | Linux/x86-64, Nix-built seed/rootfs, registered Cowboy runtime and resolver, Docker, companion images | uid 0 / gid 0 with no capabilities or user namespace (other identities refused); Cowboy runtime runs linked Montana with bundle syscall/filesystem policy | OpenRouter credential in companion; placeholder in agent | Bundle-selected writable mounts; companion scratch on host | Current CLI companion supports OpenRouter only; Redis companion has no durable volume; not a general container runtime |
Managed NixOS
Nix builds a per-agent component and declares the daemon, tools, proxy, message access, and service controls. The daemon launches Montana directly under systemd. It joins the configured Cowboy network namespace; the shared service envelope limits its writable world to the agent home and declared mounts. Sheepdog mediates tool execution. The daemon requires the credential proxy.
The module can also build an OCI bundle. That bundle is a separate deployment artifact, not an intermediate step in the systemd daemon launch. “Production” here describes the intended supported configuration, not adoption or runtime certification.
Local and ordinary Docker
Local UI sessions use the Zellij harness. Local headless sessions use Montana. Changing hosts does not add the managed security controls.
The ordinary image has two startup paths. The interactive wizard launches Zellij. A settings-based first boot generates and builds a Nix configuration, then its supervisor launches Montana on a Unix socket. Both keep real keys inside the container. The Docker walkthrough sets an explicit persistent data directory for the interactive path.
OCI and embedding
The OCI runtime accepts Cowboy payloads and a narrow lifecycle command surface. It does not run arbitrary image commands. See the OCI contract before integrating it with an engine.
A custom host can implement cowboy:agent@0.2.0, but must supply and authorize
its own effects and filesystem access. Component portability alone supplies
no host security policy. Bare, user, and container are design
classifications, not three runtime selectors.
Continue to Installation. The security model describes the conditions behind the controls in this table.
Installation
Choose a route in the deployment matrix first. Local, managed NixOS, ordinary Docker, and the optional OCI cage have different credential and process boundaries. Policy can change which tools work.
Release availability
Nothing has been published to a package registry. There is no published Python package or prebuilt Cowboy image. This page is the maintained release availability statement; all installation routes below build from source.
Start with a checkout and Nix with flakes enabled:
git clone https://github.com/dmadisetti/cowboy.git
cd cowboy
Keep the revision and lock file used for a deployment. The commands below run from this checkout unless they explicitly refer to your host configuration.
Local evaluation
Build the CLI:
nix build .#get-cowboy --out-link /tmp/cowboy-cli
export PATH=/tmp/cowboy-cli/bin:$PATH
read -rsp 'Anthropic API key: ' ANTHROPIC_API_KEY
export ANTHROPIC_API_KEY
cowboy --model anthropic:claude-opus-4-5-20251101
The CLI’s wrapper puts the repository’s Zellij variant, which raises the plugin memory limit the harness needs, and the Docker client ahead of your PATH; no separate Zellij build is needed. The key is in the launching environment. The CLI packages its harness WASM; a plain Python install from the checkout stages neither that artifact nor the Zellij variant.
In Zellij, send:
Read README.md and summarize what this project does. Do not change files.
Expect tool activity and a model reply in the session, not a predetermined answer. File and shell tools run with your permissions. From another shell in the same environment, stop it with:
cowboy stop cowboy
For a local headless evaluation, build Montana and the component explicitly.
The get-cowboy CLI does not carry the native runtime binaries. cowboy serve
takes them from these variables, then from PATH, and otherwise runs nix build
against the revision the CLI was built from; a CLI built from an uncommitted
tree has no pinned revision and needs COWBOY_FLAKE set to this checkout:
nix build .#montana --out-link /tmp/cowboy-montana
nix build .#agent-component-lite --out-link /tmp/cowboy-component
export MONTANA_BIN=/tmp/cowboy-montana/bin/montana
export MONTANA_WASM=/tmp/cowboy-component/share/cowboy/cowboy-agent.wasm
cowboy serve --model anthropic:claude-opus-4-5-20251101
This prints a Unix socket connection command. Connect to that socket and send one JSON line:
{"submit":"Say hello and describe your available tools."}
The socket emits display frames containing activity and the answer. This
cowboy serve runs in the foreground: stop it with Ctrl-C in its terminal.
cowboy stop with no name stops the unnamed instance only when it was started
with --daemon; for a foreground one it reports the socket and exits non-zero.
This path still holds real keys and runs with your permissions; headless
operation adds no confinement.
cowboy serve --expose also runs the cowboy-runtime forwarder. Build it with
nix build .#cowboy-runtime --out-link /tmp/cowboy-runtime and set
COWBOY_RUNTIME_BIN=/tmp/cowboy-runtime/bin/cowboy-runtime. On Linux,
.#cowboy-harness wraps the same CLI with Montana and cowboy-runtime on its
PATH, so it needs neither binary variable.
Managed NixOS
Use an existing Linux/x86-64 NixOS host configuration. Add Cowboy as a flake
input, import the Cowboy and Home Manager modules into that host’s module
list, and keep its lock file under version control. The fragment below assumes the host
already imports agenix and has an operator account named alice; substitute
your operator name. The encrypted key must be decryptable by this host.
# Add to the inputs of your host flake:
inputs.cowboy.url = "github:dmadisetti/cowboy";
# Include in the host's nixosSystem modules list:
modules = [
./configuration.nix
cowboy.nixosModules.default
cowboy.inputs.home-manager.nixosModules.home-manager
./cowboy-agent.nix
];
Save this module as cowboy-agent.nix beside the host flake:
{ lib, ... }:
{
programs.fish.enable = true;
services.cowboy.broker = "alice";
services.cowboy.agents.dev = {
enable = true;
user = "dev";
uid = 1338; # Choose an unused UID.
model = "anthropic:claude-opus-4-5-20251101";
daemon.enable = true;
daemon.expose = 4312;
};
age.secrets.anthropic-key = {
file = ./secrets/anthropic-key.age;
owner = "cowboy-proxy";
};
services.cowboy.secretsProxy.domainMappings = lib.mkForce {
"api.anthropic.com" = {
secretPath = "/run/agenix/anthropic-key";
headerName = "x-api-key";
};
};
}
The encrypted file is part of your host configuration; the plaintext key never belongs in Nix text or the store. Its runtime reference is the proxy mapping’s secret path. Restricting the mapping to this provider avoids provisioning unneeded provider and search credentials.
Build and activate from your host configuration directory, replacing HOST with its NixOS configuration name:
sudo nixos-rebuild switch --flake .#HOST
systemctl status cowboy-serve-dev --no-pager
cowboy connect 127.0.0.1:4312#/var/lib/cowboy/expose/dev.token
Run the connection command as the configured operator. It opens the Zellij
client to the managed agent. Send “Say hello and describe your available
tools.” Expect activity and a reply there; inspect service diagnostics with
journalctl -u cowboy-serve-dev. The localhost control token grants control,
including the ability to answer approval prompts. A read-only observer needs
the separate observer endpoint and token.
The daemon runs Montana directly under systemd as dev, with its per-agent
component, namespace, proxy, Sheepdog, and shared service envelope. It does not
invoke the OCI runtime. To leave the daemon stopped:
sudo systemctl stop cowboy-serve-dev
A socket quit is insufficient: the unit restarts automatically. Set
daemon.autostart = false and rebuild if it should remain off at boot.
Docker
Build on a Nix machine matching the target image architecture, then load the archive on the Docker host. The target host needs Docker, not Nix:
nix build .#docker-image --out-link /tmp/cowboy-image
docker load < /tmp/cowboy-image
docker run -it --name cowboy-eval \
-e XDG_DATA_HOME=/etc/cowboy/data \
-v cowboy-etc:/etc/cowboy \
-v cowboy-workspace:/opt/workspace \
cowboy:latest
For separate machines, transfer the image archive before loading it. On first
boot the wizard asks for provider, model, and key. It writes the key with mode
0600 into the configuration volume, then opens the setup agent in Zellij.
Tell it what work you want help with, your communication preferences, and when
it should ask before acting. It saves the agreed profile to
/opt/workspace/.cowboy/prompt.md; an otherwise empty workspace is normal.
Choosing a role such as calendar assistant does not authorize or configure a
calendar integration. Setup should state which capabilities work and which
still need access, while preserving existing workspace files.
The explicit data directory keeps session state in the named volume, including
on later starts. Tools run as container root with ordinary Docker isolation;
there is no managed credential proxy or Cowboy cage.
When the profile is saved, stop and resume from the Docker host. The normal agent loads that profile and resumes the conversation from persistent state:
docker stop cowboy-eval
docker start -ai cowboy-eval
Without a TTY or staged settings, a fresh image exits with “no configuration found.” For a settings-based headless service, the CLI can stage a bootstrap settings file and build a per-agent generation. That route is distinct from the interactive wizard. Its current launcher mounts config and workspace but does not set a persistent Montana data directory; account for that before relying on it for durable sessions. See daily operation.
Optional OCI cage
This specialized route requires Linux/x86-64, Docker, a source checkout, and a
registered Cowboy runtime with its imageless resolver. Follow the registration
instructions in crates/runtime/smoke.sh and the
OCI contract.
Registration changes Docker’s daemon configuration; it is not supplied by
installing the CLI. The runtime serves the cage’s control port only behind the
bearer-token file that COWBOY_CONTROL_TOKEN_FILE names in Docker’s daemon
environment. When the variable is unset, the runtime refuses the container, so
docker run fails instead of starting a cage you cannot connect to.
The CLI writes that file at /run/cowboy-oci/control.tok, or at the path
COWBOY_CONTROL_TOKEN_FILE names in its own environment. It never creates the
directory: only root can create one under /run, which is what stops another
local user from creating it first with a token they know. Provision it once,
owned by the user who runs cowboy serve, so it survives reboots:
echo "d /run/cowboy-oci 0700 $USER - -" | sudo tee /etc/tmpfiles.d/cowboy-oci.conf
sudo systemd-tmpfiles --create /etc/tmpfiles.d/cowboy-oci.conf
On NixOS, declare the same rule in the host configuration instead:
systemd.tmpfiles.rules = [ "d /run/cowboy-oci 0700 <user> - -" ];.
Earlier releases kept the token at /tmp/cowboy-oci/control.tok. If Docker’s
daemon environment still sets COWBOY_CONTROL_TOKEN_FILE to that path, change
it to /run/cowboy-oci/control.tok and restart Docker. Otherwise the runtime
keeps trusting a file in /tmp, which another local user can create, while
the CLI writes its token under /run. The CLI cannot read Docker’s
environment, so it cannot warn you about this.
The CLI refuses a token directory that is missing, a symlink, owned by another user, or writable by group or other. It reuses an existing token only if it is a regular file owned by that user with no group or other access and no second hard link; otherwise it refuses rather than hand the forwarder a token someone else may have written.
cowboy list and cowboy status connect to a running cage’s control port to
show what the agent is doing. They send the token only when the socket that
accepted the connection belongs to root, as the runtime’s forwarder does, or to
you. Another local user can bind the port before the forwarder does; the
forwarder then fails to bind while the cage keeps running. In that case the
activity shows as unavailable and the token is not sent.
Once the runtime is registered, prepare the Cowboy payload and the placeholder image, then launch from the checkout with the CLI available:
nix build .#cowboy-agent-seed --out-link /tmp/cowboy-seed
nix build .#cowboy-agent-rootfs --no-link
tar -C /tmp/cowboy-seed/rootfs -c . | docker import - cowboy-imageless:latest
read -rsp 'OpenRouter API key: ' OPENROUTER_API_KEY
export OPENROUTER_API_KEY
cowboy serve demo --sandbox cage --expose 4210
The companion currently injects only OpenRouter credentials; another provider’s key will not work here. It holds the real key and exposes egress through Unix sockets. Docker runs the payload with the Cowboy runtime and networking disabled; the runtime launches linked Montana under the bundle’s policy.
The published rootfs trusts only the system CA bundle. The companion’s mitmproxy mints its own CA, and the CLI hands Montana that certificate at launch through the companion’s socket directory, so no proxy CA is built into the seed or the rootfs. A deployment with its own credential proxy supplies its CA the same way; see TLS trust in the OCI contract.
Use the printed cowboy connect command and send the same hello request.
Expect display frames in the client. The component and model come from the
seed configuration. Stop the cage and its companions with cowboy stop demo.
cowboy serve returns once the containers are running, so --daemon changes
nothing on this rung. If any docker run fails, the CLI prints Docker’s error and removes the
containers that launch started, including the companions holding the key.
The companion Redis has no persistent volume; this is not the managed NixOS
service’s persistence contract.
On a NixOS node, enabling services.imageless with Cowboy’s module registers
the agent release as an issuer. The node then substitutes the agent rootfs
from the cache the release names, default, and never evaluates Nix. Cowboy
publishes no binary cache for it. Build cowboy-agent-rootfs for each node
system and push it to a cache you control. Then set that cache in
services.imageless.policy.issuers.cowboy.caches.default, giving its
substituter and publicKeys. Until you do, the configuration fails to
evaluate.
Continue with First request and daily operation.
First request and daily operation
Use one of the complete routes in Installation. Start with a request whose result you can check, such as “Read README.md and summarize what this project does. Do not change files.” Check the tool results and answer in the client. A successful launch alone says nothing about model authentication or useful work.
cowboy ask "<prompt>" runs one prompt to completion without a client and
prints the final answer. Each run gets a Zellij session of its own, so it
neither waits on nor ends an interactive session attached under the same name,
even with --fresh. With -a <name> naming a managed agent, the run stays
inside that agent’s launch envelope and reports completion instead of printing
the answer, with the command that reads the run’s transcript as the agent user.
A managed run that fails to launch exits non-zero with the reason. A local run
that produces no answer, because Zellij never started it or the turn failed,
also exits non-zero with the reason. A run of either kind still going after
--timeout seconds (default 3600; 0 removes the bound) is stopped and exits
non-zero.
Inventory, status, and health
cowboy list
cowboy status
cowboy doctor
These answer different questions. The list shows registered agents that can run. Status shows runtime instances and their last reported activity. Doctor checks whether services are up, the event loop responds, and inbox consumers are still reading. A local session need not have a registry entry, and doctor cannot verify every deployment from every account. An unknown result is not a pass. Use Troubleshooting to interpret it.
For a named managed agent:
cowboy status dev
cowboy doctor dev --json
journalctl -u cowboy-serve-dev --since today
cowboy logs reads the launch log of a backgrounded local serve process; it is
not a general transcript or journal reader. For example, cowboy logs reads
the unnamed headless instance’s log when it was started with --daemon. A verb
given no name — bare cowboy, serve, stop, restart, logs, connect,
ask — addresses the agent_name saved by onboarding, else cowboy.
Use the system journal for managed units, Docker logs for containers, and the
client/session history for conversation content.
Review external actions
Approvals are configured per bridge or effect. For a gated Git push, review the runner’s target, execution identity, commit SHA, changed files, and diffstat. The agent’s prose is not the runner’s description. An authorized approver chooses ✅ to push exactly that SHA or ❌ to reject it. An expired request needs a new review; a branch that moved requires a newly prepared request.
The operation result returns to the agent’s inbox and the configured status channel. Keep the request ID and SHA if delivery or execution is uncertain. An accepted message or approval is not proof that the push or rebuild finished. See approvals and gated effects.
Restart and recover
Managed daemons restart after exit, including clean socket quits, with a
five-second delay and a start-rate limit. A changed per-agent component also
triggers a restart on NixOS activation. Use systemd for an explicit restart;
cowboy restart dev runs the same systemctl restart for a declared daemon:
sudo systemctl restart cowboy-serve-dev
cowboy doctor dev
A deliberate systemd stop leaves the daemon down. Ordinary containers in the
installation example have no Docker restart policy; start them explicitly.
A container that cowboy init --mode docker finishes, or that cowboy serve
or cowboy restart relaunches from its declared volume, runs with
--restart unless-stopped.
For local headless and cage launches, and a cowboy-serve-<name> unit that
cowboy serve <name> started rather than the NixOS module, retain the original
launch command: cowboy restart cannot reconstruct their transient socket,
sandbox, and exposure flags. It stops those instances and asks you to relaunch. For a
settings-based Docker agent it can reuse the declared volume.
After a crash, a sender may receive no answer even though a request was accepted, or see a duplicate after redelivery. Resumed work can also lose the original reply destination; inspect state and external outcomes before resubmitting. Message reliability gives the exact recovery contract.
Back up mutable state
Stop the agent and its writers before copying state. Keep ownership and modes, especially for keys. A Nix closure rebuilds software; it does not restore conversations, working files, credentials, or pending approvals.
- Local: preserve the workspace and Cowboy’s XDG data/config directories
(normally under
~/.local/shareand~/.config). - Managed: preserve the configured agent home and writable mounts, plus the enabled broker/bridge services’ persistent state and secret sources. Include Redis persistence when recovering queued messages and approvals matters.
- Docker walkthrough: preserve both named volumes, including the explicit data directory under the configuration volume. Container removal does not remove these named volumes.
- Settings-based Docker CLI: config and workspace are under
~/.local/share/cowboy/agents/<name>/by default. The current supervisor leaves Montana’s default data directory in the container layer. Preserve it separately before replacing the container, or configure a data directory in a mounted volume in the generated supervisor. The config/workspace mounts alone are not a complete session backup. - OCI: preserve the writable mounts you declared in the bundle; do not treat runtime scratch or the CLI companion’s Redis as a durable backup.
Upgrade and rebuild
Keep the old revision, lock file, and a state backup until the new deployment has answered a test request. Build the new CLI or image from the chosen source revision. On NixOS, update the host’s Cowboy input and rebuild the host, then check doctor and the first real request.
For the Docker walkthrough, stop and remove the old container after backing up,
load the new image, and repeat the run command with the same named volumes. A
settings-based container also has a generated flake and result link under its
configuration volume. Edit that persistent configuration and run cowboy bake
inside the container to build a generation; restarting with an existing result
link does not itself rebuild it. A new base image alone does not replace that
existing generation.
An approval-gated rebuild pins the main commit and resolved input overrides before asking for approval. The result reports when a successful build produced the same system or home generation. Treat that as no deployment change, not evidence that the requested behavior reached the running agent. See rebuild diagnostics.
Stop and remove
Stop local or CLI-managed agents with cowboy stop <name>. A foreground
cowboy serve stops with Ctrl-C in its terminal; cowboy stop reports it and
exits non-zero. A local serve with the name comes first: a resident of the
same name is left running, and cowboy stop says so. For a resident,
cowboy stop (like cowboy harness <name> --stop) also stops a running
cowboy-serve-<name> unit and names it. To
retire a managed daemon, stop its systemd unit, disable the agent in the NixOS
configuration, and rebuild. For the Docker walkthrough, stop and remove the
named container. Keep backups, then deliberately remove only the state and
volumes you no longer need. Removing software or disabling a service is
separate from erasing its history and keys. Revoke provider or publishing credentials when retiring
the deployment.
Continue with Configuration to change models, tools, message access, and service settings.
Troubleshooting
Start with cowboy doctor. A service can be up while the agent has stopped
reading messages.
cowboy list
cowboy status
cowboy doctor
cowboy doctor dev --json
The list is the registered inventory. Status observes running instances and
last reported activity. A failed serve row is a managed daemon whose
systemd unit failed. A container that carries Cowboy’s labels but has no
Cowboy launch record is shown as unverified and never probed, because any
image can declare those labels. Doctor separates three observations:
| Observation | What it establishes | What it does not establish |
|---|---|---|
| Process/service exists | The host still has a running process | The event loop is making progress |
| Event loop responds | The agent’s event loop acknowledged a diagnostic request | Inbox polling still runs |
| Inbox consumer is active | Redis records recent reads | The model finished a turn or a reply reached its destination |
A replayed status frame can outlive a stalled loop. Doctor asks the loop to acknowledge a request instead. Its attention check examines inbox consumer activity independently.
Checks report ok, fail, or unknown. Unknown means the probe could not establish an answer, for example because the caller cannot read an agent’s Redis socket or the deployment has no supported probe. Read the reason; do not translate it into healthy. On a managed host, rerun as an authorized operator with the required privilege if the reason is access. Do not broaden socket permissions to make a diagnostic green.
Find the right log
# Managed service:
systemctl status cowboy-serve-dev --no-pager
journalctl -u cowboy-serve-dev --since today
systemctl list-units 'cowboy-*'
# Backgrounded local serve (default agent name):
cowboy logs
# Docker walkthrough:
docker logs cowboy-eval
Inspect the first failed service and its dependencies. The managed daemon requires the namespace and credential proxy; it does not launch an OCI bundle. A cage startup failure instead belongs to Docker, its runtime registration, the seed/rootfs, bundle policy, or companion services.
The CLI or Zellij is missing
Use the source-build installation. Select the CLI package explicitly; the default flake package is not the Python launcher. A Python source install alone does not bundle the harness WASM. Zellij is required for interactive sessions and the connect client, not for Montana’s headless service.
The client opens but the model fails
Check the provider/model specification, the credential source for this route, and the upstream response. Local and ordinary Docker paths hold real keys; managed agents use placeholders and need the proxy’s secret path to be readable by its service user. User and system keys files accessible to group or others are ignored. See secret discovery.
On a managed daemon, a runtime provider switch also needs provider access in
the Nix configuration. A proxy credential alone does not supply the component’s
provider key placeholder. Declare the provider through a model option or
extraProviders and rebuild.
Record the provider, model, HTTP status, and request ID without copying keys. A method or destination denial calls for reviewing the configured policy, not bypassing the proxy.
A tool is denied
Identify the layer from its result: tool approval, filesystem permissions, Sheepdog syscall policy, service hardening, proxy methods/destinations, or OCI policy on the cage route. Compare the operation to that deployment’s declared access. A successful local run is not evidence that the managed policy should permit it.
An approval or reply seems stuck
Follow the request through ingest, the agent inbox, the agent turn, and the outbox. For Discord, the receipt reaction establishes that the bridge queued the message, not that the agent answered. Check doctor for continued inbox consumption and inspect whether an approval is pending, rejected, expired, or superseded. Only configured approvers can resolve a gated Discord request.
For Git effects, preserve the request ID and SHA. The approval must match the runner’s description and the applied SHA. A branch moving after review causes a refusal; fetch and prepare a fresh request instead of treating the old approval as permission for another commit. A push can succeed while its verification fetch fails: inspect the remote before retrying.
After interrupted work, a request may have no reply, be redelivered, or resume without its original reply destination. Inspect external results before asking for the same side effect again. See message reliability.
A rebuild succeeds but nothing changes
The rebuild service compares the built system closure with the running system, or the new home activation path with the prior one when it can read that state. An identical result gets an explicit no-change note. A successful command can therefore mean no new deployment.
First check the rebuild type: a home rebuild cannot deploy system services,
networking, or system packages. Check that the approved commit contains the
change, that it reached the tracked branch, and that the flake imports the
edited file. Check resolved input overrides in the approval and result. Then check the deployed generation and whether the daemon restarted
onto the new component. Doctor compares the unit definition the daemon recorded when it started
with the one deployed now, and fails when they differ; the unit carries the daemon’s arguments and
the store paths of its component and message sources. Files in the agent’s home, such as judge.json,
are outside that comparison. If the rebuild could not establish a prior home generation, absence
of a no-change note is not proof of change.
For settings-based containers, an existing result link is reused at startup.
Build the edited generated configuration with cowboy bake inside the container
before restarting; merely editing JSON or replacing the base image does not
necessarily replace that generation.
Restart without losing the evidence
Copy mutable state before repair. Managed daemons restart after exit, but a live stalled process need not exit; record doctor and journal output before an explicit systemd restart. Recheck health and send a small request afterward. See daily operation for restart limits, backup, and removal.
Report a useful bug
Include the source revision, OS/architecture, deployment route, redacted command or Nix configuration, expected and observed behavior, doctor output, and a bounded log excerpt. For bridge/effect problems include the request ID and commit SHA. Report at GitHub issues.
A failure the CLI expects, such as a bad setting or name, a failed command, a
missing precondition, or an unreadable file, prints one cowboy: <message>
line and exits non-zero (2 for a bad setting or name, 1 otherwise). Rerun with
COWBOY_DEBUG=1 to get the full traceback for the report.
Configuration
CLI launch settings, persistent JSON, generated NixOS configuration, and secret discovery are different inputs. A provider key is not another level in ordinary settings precedence.
Local settings
Inside the Zellij harness, /settings or Ctrl+, opens the session settings
screen. It shares the bootstrap star header and centered layout. Type to filter
models, use arrow keys to select, and review a change before applying it. The
star hangs left of the title, and navigation stays at the bottom of the pane.
Escape cancels; an existing chat draft is preserved when opening by shortcut.
Model changes in that picker affect the current session only. When attached to
a remote agent, the screen is informational and directs changes to that host.
cowboy init offers only Harness or Docker in Python, then opens the Rust name
screen unless a name was supplied. Harness enters the local
Zellij session; Docker provisions a container and opens its existing Rust
bootstrap wizard. --mode harness or --mode docker bypasses the picker.
Persistent local settings UI integration with the Rust wizard is still pending.
Noninteractive local configuration remains available through init --settings.
The settings backend supports explicit credential references; it has no
discovery of existing setup. Choosing Codex in the local wizard asks which
codex login credential file to use, suggesting $CODEX_HOME/auth.json
(~/.codex/auth.json by default) without reading it. Enter confirms the
suggestion; the save refuses a missing file or one group or others can read.
Checks establish credential presence, not successful provider authentication.
A failed save preserves the previously committed setup.
After setup completes, selected provider references take precedence over the legacy discovery order below. Unselected environment credentials and project configuration cannot replace them. Existing managed credential provisioning retains its own launch path. See operator settings for persistence and ownership semantics.
The launcher merges JSON objects in this order, with later files winning:
/etc/cowboy/config.json~/.config/cowboy/config.json(under the configured XDG config directory).cowboy/config.jsonin the current directory
Missing, unreadable, malformed, and non-object files contribute no settings. Explicit CLI options override the corresponding ordinary settings.
For provider and main model, merged files override generated agent JSON,
which overrides built-in defaults. A merged provider without a model
beside it drops the agent JSON’s model, so the provider’s default applies, as
--model <provider> does. Heartbeat and chrome come from CLI options or
merged files only. An explicit false counts: --no-chrome turns chrome off
even when a merged file turns it on. For secondary models and memory/rerank
settings, generated agent JSON overrides merged files; supported CLI options
still win. The main log level comes from CLI options or merged files only.
max_output_tokens, sweep_floor and qmd_min_score come from generated
agent JSON only, so a resident launched with harness, cowboy ask or
cowboy serve <name> gets the values its daemon unit has. Do not assume one
precedence order covers every field. The declared systemd daemon takes its
arguments from NixOS configuration directly, rather than reading the
operator’s local launch defaults.
A local config can contain:
{
"provider": "openai",
"model": "served-model",
"openai_base_url": "https://inference.example/v1",
"log_level": "info"
}
openai_base_url selects an arbitrary OpenAI-compatible Chat Completions
endpoint. The value should include the API prefix (commonly /v1); Cowboy
normalizes trailing slashes before appending /chat/completions. It can also
come from OPENAI_BASE_URL when no JSON or generated agent setting supplies
one. A configured endpoint may be keyless for local servers, or use the normal
OPENAI_API_KEY/openai_api_key credential path for bearer authentication.
Custom endpoints always use Chat Completions, even for model names that the
first-party OpenAI service would route through its Responses API.
cowboy config set <key> <value> edits the user file. It accepts only the
settings the launcher reads and stores each as its JSON type: chrome as
true or false, heartbeat, rerank_top_n and codex_quota_threshold (1–100)
as positive integers, and rerank_min_score as a number. It refuses any other
key or value and leaves the file unchanged.
Common settings subset
This is a common subset, not the entire recognized surface. The implementation
inventory is crates/contracts/src/keys.rs; a host or launcher need not expose
every component key as a CLI option.
| Key | Meaning |
|---|---|
provider | Provider for the main model |
model | Bare model ID in local JSON; provider comes from the separate key |
openai_base_url | Base URL for an OpenAI-compatible Chat Completions endpoint |
summary_model | Provider:model specification for summarization |
compact_model | Provider:model specification for compaction |
subagent_model | Provider:model specification for sub-agents |
vision_model | Native vision or a separate provider:model specification |
memory_backend | Memory search backend |
heartbeat | Launcher heartbeat interval, in seconds |
log_level | Logging verbosity |
The component key for heartbeat is heartbeat_interval; the launcher’s JSON
setting and flag use heartbeat and --heartbeat. Model availability and
provider access are separate: selecting a model does not provision credentials.
Use cowboy models to inspect the bundled catalog and each command’s --help
for its options.
Secrets
Outside proxy deployments, discovery checks each key in this order and uses the first nonempty value:
- Provider environment variable, such as
ANTHROPIC_API_KEY. - User keys file,
~/.config/cowboy/keys.json. - System keys file,
/etc/cowboy/keys.json. - The provider’s agenix file, if readable.
Keys files map component key names, such as anthropic_api_key, to secret
values. They must have mode 0600: files accessible to group or other users are
skipped with a warning. Local and noninteractive --settings Docker
deployments can store real credentials in those files. Interactive
cowboy init --mode docker uses the separate credential proxy: its
/etc/cowboy/keys.json contains the literal "proxy" placeholder, while
the encrypted credential and age identity stay in the proxy’s private volume.
See Docker connector setup for the separate status of
connector credentials.
Managed daemons receive proxy placeholders. The actual key belongs at the secret path named by the proxy domain mapping, readable by the proxy service user. The managed installation shows an agenix declaration with that ownership.
First-boot settings
A --settings file for cowboy init or cowboy serve is a validated bootstrap
input, not the general config file. It accepts a key reference through
api_key_env or api_key_file; a literal api_key is rejected. For example:
{
"agent_name": "myagent",
"posture": "container",
"provider": "anthropic",
"model": "claude-opus-4-5-20251101",
"api_key_env": "ANTHROPIC_API_KEY"
}
An authenticated OpenAI-compatible endpoint can be bootstrapped without putting its secret in the settings file:
{
"provider": "openai",
"model": "served-model",
"openai_base_url": "https://inference.example/v1",
"api_key_env": "INFERENCE_API_KEY"
}
Omit api_key_env/api_key_file for a keyless local compatible server.
The host resolves the reference and writes the key into the agent’s configuration volume with mode 0600. A bootstrapped volume rejects restaging; edit its persistent configuration instead. See daily operation for generation and backup considerations.
NixOS module
Import the default NixOS module and enable individual agents under
services.cowboy.agents. There is no top-level service enable switch. Keep
agent usernames equal to their agent names when using Redis ACLs, and give
each enabled agent a unique UID.
The main model option takes a provider:model specification. Common per-agent
options include homeDirectory, prompts.system, mounts, daemon.enable,
and daemon.expose. The latter provides an authenticated control endpoint;
daemon.observe provides a separate read-only endpoint and credential.
Nix generates per-agent launch configuration and components, and message-source
configuration for agents and bridges. Edit the Nix declaration, not the
generated files under /etc/cowboy. The full per-agent schema is in
modules/options/user.nix.
Managed provider access is provisioned from the model options. To keep another
keyed provider available for a runtime model switch, declare it in
extraProviders and provision its proxy secret. This grants provider access;
it does not select the main model.
For a managed agent, set openaiBaseUrl beside an openai:<model> model.
Credential provisioning remains separate: configure the secrets proxy domain
mapping for the endpoint and its key. The URL is ordinary configuration; the
key must remain in the existing secret-reference/proxy path.
Continue with tools and skills and bridge integration.
Docker bootstrap handoff
Docker’s Zellij wizard asks which connectors the user wants to discuss, using an optional filtered checklist. It records interests, not connected accounts. Setup chat then establishes the agent’s purpose and configures selected connectors one at a time when access is ready. Harness setup stays brief. A prose profile does not provision a service.
When a connector needs a credential, the setup agent can hand the terminal back to the host. The existing masked Zellij wizard lets the user paste it; the wizard encrypts it to the proxy’s age recipient before writing output. The user can instead provision an age file at the printed private host path. Setup chat resumes afterward, with only credential status exposed to the agent. The agent must keep configured, verified, and missing capabilities distinct.
Before the setup chat, Cowboy seeds flake.nix, agent.nix, and
environment.nix in the configuration volume. Edit environment.nix to add
packages and local build checks; packages reach both nix develop and the
persistent agent’s PATH. Scripts belong in the persistent workspace and should
be tested against safe fixtures during setup. Unfinished setup resumes with
these edits intact; a seeded flake alone does not mark setup complete.
After the user agrees to finish, cowboy __finish-bootstrap checks the saved
profile, runs nix flake check, and builds the edited configuration.
Only successful checks and a build writes the completion marker and closes the setup
session. Missing external credentials can remain explicitly pending, but do
not prevent independent package and script work.
Ctrl-Q exits the setup terminal without marking setup complete. After successful completion, host init restarts the container into the configured supervisor and opens its chat client. Closing that client leaves the supervisor running.
Docker credential entry stays in the masked Zellij wizard. The Rust plugin
age-encrypts credentials in memory to a host-generated public recipient before
writing its output. Only ciphertext leaves the plugin; the host stores it and
the private identity under the agent volume’s private proxy/ directory. Only
the companion mounts that directory and decrypts credentials. The agent receives
placeholders and a public CA bundle. The companion starts before setup chat and
runs the credential proxy and Redis; individual bridge configuration and shared
connector forms remain separate work.
Docker Connector Setup
title: Docker Connector Setup tags: [docker, onboarding, connectors]
Docker connector setup
This guide describes the current Docker bootstrap image, not the managed NixOS module. Read it before searching connector source during onboarding.
Start with the route
Ask what the agent should watch, where it should send a result, and whether
the user wants approval before sending. For a Discord-to-Slack notification,
the minimum choices are Discord server/channel scope and a Slack destination.
Ask whether the user has the bot credentials ready for private provisioning;
remind them not to paste credentials into chat. The selected connector names in
/opt/workspace/.cowboy/connector-interests.json express interest, not working
accounts. The seeded /etc/cowboy/agent.nix already has the agent name and
model.
What the image actually starts
cowboy init --mode docker starts the setup agent, a separate credential proxy,
and Redis. The proxy holds the age identity and encrypted provider credential;
the agent’s /etc/cowboy/keys.json contains only a "proxy" placeholder for
that provider. The proxy and Redis require a per-agent client password, which
the agent receives in its proxy settings, REDIS_URL and REDISCLI_AUTH; a
bridge must take its broker address from REDIS_URL, not
REDIS_HOST/REDIS_PORT alone. The CLI starts the agent only after the proxy
reports that both services enforce the password. A cached image from an
earlier release does not, so the CLI refuses it and asks you to pull the image
that matches the CLI. An agent container created by an earlier release has no
password in its environment. Once its proxy is recreated, the proxy and Redis
refuse that container until cowboy serve <name> recreates it too. The Docker container template builds a
cowboy-supervisor that starts one Cowboy serve process. It does not start Discord, Hermes/Slack,
or another connector process, and it does not generate bridge routing.
The image includes the Discord bridge executable. The Hermes Slack bridge is
available as cowboy.packages.${system}.hermes-service in the source flake but
is not part of the base image. The NixOS options in
docs/src/guides/chat-platforms.md and pkgs/{discord,hermes}/module.nix
configure systemd services on a managed NixOS host; putting those options in
the Docker template does not create services in this container.
cowboy __request-secret can hand the user to the masked credential screen and
store encrypted connector files in the proxy volume. That handoff alone does
not make a bridge able to authenticate. There is presently no Docker
connector declaration that starts the bridge, generates its sources.json,
and arranges proxy-side use of its credential. Do not read an encrypted file
from the agent, export a token into its environment, or claim a connector works
because the ciphertext exists.
Discord to Slack today
The intended path needs all of these pieces:
- A Discord ingest process with the bot’s access to the chosen channels.
- Routing from that source to the named Cowboy agent, plus a rule for which messages merit notification.
- A Slack outbox process with the destination channel and its own bot/app access.
- Connector credentials used by the proxy or another isolated companion, without exposing plaintext to the agent.
- Supervision, restart, and an end-to-end smoke check for both bridges.
The current Docker bootstrap supplies none of that service wiring. Save the user’s exact scope and approval choices in the agent profile, mark both connectors pending, and explain the missing Docker integration plainly. Do not burn the setup session surveying source files or improvise a background process that disappears on restart. Continue any independent setup the user requested. If the user wants a working connector now, a managed NixOS deployment has declarative Discord and Hermes modules; its configuration and secret paths are a different deployment path.
For Docker connector development, the focused starting files are
templates/container/flake.nix, cowboy/companion.py,
pkgs/discord/{ingest,outbox}.py, pkgs/hermes/outbox.py, and
pkgs/bridge/redis_utils.py. Treat this as product work with a bridge runtime
and tests, not as a one-off onboarding script.
CLI and onboarding direction
This is the agreed target API, not a description of commands already shipped. The current supported commands remain documented in the installation and daily operation guides. No compatibility aliases are required for this transition.
Public commands
| Command | Intended behavior |
|---|---|
cowboy | Open the configured default experience; offer onboarding when unconfigured. |
cowboy init [name] | Create an agent configuration using the shared settings UI. |
cowboy start [name] | Start a configured persistent agent. |
cowboy attach [target] | Attach to an existing agent by name or endpoint; never implicitly create one. |
cowboy stop [name] | Stop an agent. |
cowboy restart [name] | Restart an agent. |
cowboy list | Show all configured/discovered agents, including stopped agents and status. |
cowboy logs [name] | Show logs; --follow follows new output. |
cowboy ask "prompt" | One-shot request; --agent chooses an agent. |
cowboy doctor [name] | Diagnose runtime, provider and connection readiness. |
cowboy help [command] | Help and examples; also support --help and per-command --help. |
Omitted names use the configured default. cowboy list --status running filters
by state; --json supports scripts. Running describes process liveness, not
successful authentication or responsiveness. Unknown inspection results remain
unknown. Detaching leaves a persistent agent running.
Expose the version through --version. Shell completion is a documented
integration feature (cowboy completions <shell>), not part of the standard
verb list or the primary help overview.
Implementation progress
- Reopenable session settings in the harness.
- Reuse the Rust bootstrap wizard for first launch and persistent settings.
- Atomic XDG configuration and credential-reference saves, including noninteractive local settings files.
- Explicit opt-in discovery of existing setup.
- Include Zellij in the Nix-packaged CLI.
- Minimal Python
initpicker: Harness or Docker only. - Wheel delivery of Zellij.
- Persistent Docker agent with independent terminal and browser clients.
- Browser settings selected by a flag for Docker/Nix.
- Complete managed Nix settings view and declaration export.
- Migrate the public CLI to the verb set above and update internal callers.
- Fresh-distribution smoke tests across every supported runtime.
Python owns only the runtime picker. Without an explicit name, one Rust wizard collects name and provider/tool settings through confirmation. Naming advances in place; Docker consumes the confirmed settings without reopening the wizard. Harness enters a normal session without an onboarding conversation. Docker’s bootstrap system prompt establishes the user’s intended work in chat, then guides creation and testing of scripts, schedules, and relevant connectors. The Docker wizard records optional connector interests; the use case and actual connector configuration are discussed in chat. Full persistent connector settings remain unfinished; session model settings are separate.
CLI migration
Remove the redundant run command: bare cowboy covers interactive launch.
Do not add run --daemon: start owns persistent launch. Remove public serve
after migrating its detached-launch and container callers to the lifecycle
implementation. Service managers and container entry points invoke the runtime
internally; foreground Montana debugging does not need a public Cowboy verb.
Rename connect to attach outright. Fold status into list. Do not add a
public setup or settings verb. Retire public bake, config, models,
plugins, and the version verb as their replacements land. harness is an
internal managed-launch entry point, not a public command to teach newcomers.
Build/apply belongs to settings; use a function, or an internal __bake only
if a process boundary actually requires a command.
One settings flow, multiple runtimes
The initial lightweight Python terminal picker offers Harness or Docker. It needs neither runtime until the user chooses. Check that mode’s prerequisites before proceeding.
The TUI is the default onboarding and settings interface in every mode. Ship
Zellij with the supported Cowboy runtime rather than making it an optional
interface. Docker and Nix users can explicitly choose the browser interface
with --browser; this is a flag, not another mode picker or public verb. Both
interfaces use the same settings, validation, persistence and ownership rules.
- Harness requires Zellij. Launch it directly into Cowboy settings on first
use, then switch to chat after configuration. Reopen settings with
/settingsand a visible keyboard shortcut. Do not build a second terminal chat implementation just to eliminate Zellij. - Docker requires Docker, not host Zellij. Explain agent name, image download,
persistent storage and explicit workspace mounts before provisioning. Ship
Zellij inside the image and attach an interactive terminal to its settings
TUI by default. Montana owns the persistent agent; Zellij is a client, so
detaching must not stop the agent or container. With
--browser, serve the setup/settings UI from the container, bound to localhost and authenticated. This browser UI is planned, not currently shipped. - Full Nix uses the same logical settings view with values prefilled and their
ownership shown. Include Zellij in the distribution and default to the TUI;
--browserselects the browser interface to the managed service. Nix-owned fields are read-only in either interface; explain the declaration to change. There is no parallel imperative infrastructure configuration store.
OpenCode’s TUI is a reference for focused, reopenable provider/model dialogs reached from the conversation, rather than a separate application. Cowboy should reuse its existing bootstrap widgets and model data while separating rendering, validation, persistence and activation. A settings dialog is UI state, not a prompt sent to the model.
Configuration and credentials
Use XDG config for local preferences and setup schema version; XDG data for conversations/workspaces; XDG state for logs; XDG cache for disposable runtime artifacts. Apply standard defaults when variables are unset. Credentials are separate from ordinary settings and restricted to the operator. Never place secrets in chat, model context, logs, exported configuration or the Nix store.
Discovery of credentials or configuration from other applications is opt-in. Provide an explicit “Discover existing setup” action, show candidate references without secret values, and require selection before use. Do not scan or import on startup. Reading Cowboy’s own saved configuration and checking runtime availability are normal operations, not discovery consent.
A settings field identifies whether it is locally configured, container-owned or managed by Nix. Managed secrets initially use guided provisioning and validation of the configured reference (for example agenix), not plaintext key entry into the agent. A future operator credential service can support writing an approved backend without granting that authority to agent tools. A proxy’s credential presence cannot be inferred from a stub token inside the agent.
Interactive missing-provider/authentication cases open the relevant settings field. Tokenless configurations remain valid. Rejected credentials, unchecked authentication and unavailable checks are distinct states. Headless launches fail before model work if required configuration is absent. Preserve existing conversations and offer targeted repair rather than resetting setup.
Save setup completion atomically only after required validation. Preserve the working configuration when save/build/activation fails. Returning to settings must preserve current selections and let the user cancel without changes. Offer export to local configuration or a Nix declaration with secret references, so initial interactive setup can bootstrap a declarative deployment.
Dependencies
Harness interaction requires Zellij. Include it in Docker images and Nix
packages even when an operator uses the browser interface. The wheel’s local
harness path must also provide a compatible Zellij runtime; its native binary
delivery mechanism remains a packaging decision. Docker provisioning/lifecycle
requires Docker, with no host Zellij dependency. Nix-managed lifecycle uses
the provisioned service manager. Keep the Python wheel lean: bundle
the harness WASM and model data, but not the native Montana runtime. Ship
Montana through Nix packages and Docker images. Wheel users can manage Docker
agents without installing Montana on the host; native headless launch is not
a wheel-only feature. Current local ask uses Zellij; do not claim otherwise until
its execution path changes. Help, version, completions and the initial picker
need neither. Inventory should degrade gracefully when a runtime is absent.
Approvals & Outbox
title: Outbox Approval Protocol tags: [pubsub, approval, discord, email]
Outbox Approval Protocol
Outbox services can hold an outbound message for human approval before sending it. The agent never sends directly; it writes to an outbox stream, and a broker service decides whether to forward the message, optionally gating it behind a human reaction.
Source: pkgs/bridge/base.py (OutboxService), pkgs/bridge/outcomes.py
(how each decision settles), pkgs/bridge/approval_client.py (the gate
client), with per-platform implementations in pkgs/discord/ and
pkgs/email/.
See also Security Model.
Transport
Messages move over Redis Streams. Each bridge {name} has an inbox stream
({name}:inbox) and an outbox stream ({name}:outbox). OutboxService reads
its outbox via a consumer group ({name}-outbox / worker {name}-worker) and
acknowledges each entry after handling it.
Two approval planes
A host keeps its decisions on one of two planes:
- The operator gate, when
services.cowboy.approvals.enableis set. Every bridge is givenCOWBOY_APPROVAL_SOCKETand asks thecowboy-approvalsservice over it to create, read, claim and settle a request. Requests live inapproval-gate:v1:*, which no bridge credential can read or write. The bridge’s gate policy sets the window and the methods that may answer: a security key, and a Discord reaction or an email reply only where the policy names that transport. See the gate’s README. - The Redis plane, otherwise. The decision is a plain
approval:{uuid}hash in the message Redis, and a reaction or reply from a listed approver answers it.
Both planes use the same park-and-poll loop in OutboxService, and both read
a decision into one outcome, so each outcome settles the entry, and reads to
the agent, the same way whichever plane decided it (see
Outcomes).
Flow on the Redis plane
When approval_required is set, an outbound message is held and routed through
a notification channel:
- The agent writes a message to its outbox —
{agent}:{source}:outboxunder the per-agent ACL (the flat{source}:outboxon a shared Redis). OutboxService.process_one()seesapproval_requiredand the message has noapproval_id, so it parks the entry (_resume_or_start_approval):- creates
approval:{uuid}withstatus=pending,source,channel_id, acontent_preview(first 200 chars),created_atandexpires_at - writes a notification to the configured notify outbox
(
{approval_notify}:outbox) carrying theapproval_id - returns without acking, so the rest of the stream keeps moving
- creates
- The notify service (e.g. Discord) sends the notification. Because the message
carries an
approval_idand the send returns anexternal_id, the base loop records the mapping inapproval:{source}_map(external id → approval id). - A human reacts to the notification.
- The notify service’s ingest handler calls
OutboxService.resolve_approval(), which looks up the approval id from the map and, if the record is stillpendingand inside its window, setsstatustoapprovedorrejectedplus theapprover. A late answer — a record already decided, pastexpires_at, or already settled and deleted — is ignored; the map entry is dropped either way. - The original outbox service checks its parked entries once per loop
(
poll_awaiting, viacheck_approval, which reads the deadline before the decision); it sends the message onapproved, or acks it and tells the agent on its inbox that the operator declined it (rejected) or that it was rejected automatically (expired).
Email answers with a reply to the notification from an allowed sender. The
first non-blank line must be exactly one decision word (approve, approved,
yes, ok, lgtm, or reject, rejected, no, deny, denied), with at
most one trailing . or !. A reply such as “ok but not before Friday” is
not a decision and reaches the agent as a message. The bridge trusts the
From: header without checking DKIM, SPF or DMARC; see
threat model N-17.
Flow under the operator gate
- The agent writes a message to its outbox, as above.
process_one()parks the entry. It asks the gate tocreatea request for the prepared operation, and the gate answers with the existing request when it already has one for that entry. While the request is pending, and this process has not announced it yet, the bridge writes a notification carrying the request id to{approval_notify}:outbox. The card says which methods the policy accepts and when the request expires.- The notify service posts the card and tells the gate the message id it got
(
delivery). It does this only for a notification on its own flat stream, never for one on an agent’s stream. - An operator answers with a security key (
cowboy-approvals reviewordecide), or, where the policy allows it, by reacting to or replying to the card. For a reaction or a reply the notify service’s ingest callsOutboxService.resolve_approval(), which passes it to the gate (transport_decision). The gate records it only if the request’s policy accepts that transport, the answering identity maps to one of the policy’s operators, and the request is still pending. poll_awaiting()reads the request once per loop. Onapprovedit checks that the prepared operation still matches the approved one, claims the request (a request can be claimed once), sends, and reports the outcome to the gate assucceededorfailed. Any other outcome settles as the Outcomes table says.
The Redis plane’s record
approval:{uuid} = {
status: pending | approved | rejected
source: email | discord | ...
channel_id: destination (email address, channel id, ...)
content_preview: first 200 chars of the message body
pinned: the bridge's private preparation notes for this prompt
created_at: unix timestamp
expires_at: unix timestamp; past it the record reads as expired.
`never` for a timeout of -1: the request has no deadline
approver: who resolved it (set on resolution)
external_id: the prompt message that was answered (set on resolution)
}
pending --+-- approve --> approved --> send
+-- reject --> rejected --> drop, notify the agent
+-- timeout --> expired --> drop, notify the agent
expired is never written: it is what check_approval answers for a record
past expires_at, whatever its status field says, and for a missing record.
An expires_at that is missing or unreadable also reads as expired; never
does not, and that record waits until it is decided.
poll_awaiting deletes the approval hash when it settles the entry.
Outcomes
Each plane’s answer is read into one outcome, and each outcome has one row in
pkgs/bridge/outcomes.py that says what becomes of the entry and what the
agent is told on its inbox.
| Outcome | Redis plane | Operator gate | The entry | The agent is told |
|---|---|---|---|---|
pending | status=pending, inside the window | pending | stays parked | nothing yet |
approved | status=approved, inside the window | approved, not yet claimed | sent (under the gate, claimed first) | nothing: it was sent |
rejected | status=rejected, inside the window | rejected | acknowledged | rejected: the operator declined it; do not resubmit without addressing the reason |
expired | past expires_at, or no record | past the policy’s window | acknowledged | expired: rejected automatically; the operator may not be monitoring approvals; resubmit only if it must be done |
superseded | never | the bridge’s gate configuration changed, or the key or identity behind the grant was revoked, before it was claimed | acknowledged | superseded: rejected automatically; resubmit only if it must be done |
| retired | never | only the request’s reference outlived retention | acknowledged | expired: the same as an expired request |
| interrupted | never | this bridge holds the claim, and an attempt under it may have run | recorded as uncertain | it could not be confirmed; inspect before resubmitting |
| claim used | never | the claim was already used and its outcome reported | recorded as uncertain | it could not be confirmed; inspect before resubmitting |
A refusal reaches the agent as Your request was NOT delivered (<label>).
followed by the row’s notice, then a preview of the entry:
- declined by an operator: “The operator declined it. Nothing ran. Do not resubmit without addressing the reason.”
- expired or retired: “Rejected automatically: this isn’t available. The operator may not be monitoring approvals. If you must do this, resubmit the tool call.”
- superseded under the gate: “Rejected automatically: this isn’t available. If you must do this, resubmit the tool call.”
Nothing ran in any of these cases. The automatic rejection is only what the
agent is told: the records still read expired and superseded, so an
operator or an audit can tell a request nobody answered from one an operator
declined.
The outbox’s own supersession is a different case. Once a newer entry for the
same operation has been filed, the older one is dropped rather than run, and
the agent is told
Your request was NOT delivered (superseded). Superseded by <entry>., naming
the entry that replaced it.
This bridge holding the claim with every attempt under it ended cleanly (a
send the transport refused) reads as approved: it is retried under the same
claim, without a second decision.
An answer that arrives after its request was decided, expired, superseded or
settled is ignored on both planes. resolve_approval() still reports that the
message answered a prompt, so it never reaches the agent as a message either.
Delivery, retry and uncertainty
An entry stays unacknowledged until it is settled. Recovery re-claims one idle for 30 seconds on each pass, once a minute. How the entry is settled depends on how its last attempt ended:
- The send failed.
send()returned an error. Recovery retries the entry up toOUTBOX_MAX_DELIVERIESattempts (five by default). After the last attempt the entry goes to{source}:deadand is acknowledged, and the agent is told on its inbox. Under the approval gate the retries reuse the claim the first attempt took, and a dead-lettered claim is recorded asfailed. The Redis plane deletes a decision once it has been read, so each retry is gated again. - The send partly succeeded. The email bridge’s SMTP server accepted the
message for some recipients and refused the rest. The entry is not retried,
because the recipients that accepted it would get it twice. It is
acknowledged, the agent is told which recipients were refused, and a gate
claim is recorded as
failedwith the same detail. - The attempt may have run. Either the process stopped during the send or
the bridge could not confirm completion. The entry is not retried. It is
recorded on
{stream}:uncertain, the gate request is markeduncertain, and the agent is told the request could not be confirmed. - Handling the entry raised an error. The error counts as a failed attempt for that entry only, with the same bounded retries and dead letter. Other entries keep moving.
- The bridge refused the entry. For example,
runasrefuses a re-claimed entry once its declared unit has changed. The requester is told why, the entry is acknowledged, and a request or prompt it already had is settled: an unclaimed gate request readssuperseded, a claimed one is given its outcome, and the prompt is marked withdrawn. - The gate retired the request. The entry is acknowledged, and the agent is told it was rejected automatically, as for an expired request.
Acknowledging an entry does not delete it. At the end of each recovery pass the
bridge trims settled entries older than OUTBOX_RETAIN_S seconds (seven days
by default) from each outbox stream it reads. The cut never passes the oldest
entry any consumer group has pending or not yet read, so an unsettled entry is
never trimmed. A refusal recorded against a trimmed entry is forgotten with it.
Redis keys
On the Redis plane:
approval:{uuid} # HASH — approval state
approval:{source}_map # HASH — external message id -> approval id
The requesting service writes and polls approval:{uuid}. The notify service
owns approval:{source}_map. Bridges share only the key format — Discord and
email do not know about each other.
Under the operator gate a bridge holds none of these. The gate keeps its
requests, deliveries and decisions under approval-gate:v1:*, which only the
cowboy-approvals service can reach. Enabling the gate removes every bridge’s
access to the approval:* hashes, so an old record cannot authorize anything.
Implementation
The park-and-poll flow (process_one(), poll_awaiting()), the static
resolve_approval(), and the recording of which message carried which prompt
all live in the shared OutboxService, for both planes. A per-platform bridge
only needs to:
- Return
SendResult(ok=True, external_id=...)from itssend(). - Call
OutboxService.resolve_approval(pubsub, source, external_id, status, approver)from its ingest handler when a reaction or reply arrives, withstatusset toapprovedorrejected. It returns true whenever the message answered a prompt, whether or not the answer was honoured, so the ingest can keep a late answer from reaching the agent as a message.
systemd services
Each bridge {name} runs cowboy-{name}-outbox, plus cowboy-{name}-ingest
and cowboy-{name}-ping when its package has those entry points. The
rebuild, effects and runas bridges have only an outbox; hermes and
howdy have no ingest, because their outbox owns the connection in both
directions.
Configuration
Approval is configured per bridge under
services.cowboy.bridges.<name>.approval (and equivalently on
services.cowboy.pubsub.sources.<name>.approval):
services.cowboy.bridges.discord.approval = {
required = false; # hold outbound messages for manual approval
notify = "discord"; # which outbox to send approval notifications to
notify_channel = ""; # channel id within that outbox
timeout = 3600; # seconds before an unanswered request expires
};
If required is true, notify_channel must be set. Under the operator gate
(services.cowboy.approvals), the bridge’s gate policy sets the window and
the methods that may answer, and the bridge’s timeout is not read. The
rebuild-request and effects-request records report the terms in force:
approval.timeout_seconds and approval.via are the policy’s timeout and
methods under the gate, and the bridge’s timeout and notify otherwise.
A bridge’s timeout and a gate policy’s
(services.cowboy.approvals.policies.<name>.timeout) mean the same thing,
and both default to 3600:
- A positive number is the seconds a request waits for a decision. At that deadline it expires: the entry is acknowledged and the agent is told the request was rejected automatically.
- -1 means the request never expires. It has no deadline, and waits until
an operator decides it or it is superseded, however long that takes. The
Redis plane records
expires_atasnever, the gate recordsexpiresasnull, a card that would give the deadline says it does not expire, and the request tools reporttimeout_secondsasnull. A parked request holds one of the bridge’s parking slots for as long as it waits. The gate keeps a request with a deadline until seven days after that deadline, and one without until seven days after it first finds it settled (see the gate’s README). - 0 means every request expires as it is created, so each one is refused unanswered and nothing is sent.
Anything below -1 fails evaluation, and a bridge or the gate refuses it when it loads a configuration written by hand.
The Redis ACL enforcement option keeps the agent restricted to stream commands so it cannot touch the approval hashes directly.
Two bridges use this protocol for something other than a message. rebuild
gates a system rebuild, and effects gates a declared action on the world
(a git push, for instance) — see Gated Effects. For effects,
approval.required is read-only true: there is no unapproved mode, and the
approval is bound to a specific commit sha rather than to the request text,
so what the operator approved is what runs, byte for byte.
Adding a new approval channel
To approve via something other than Discord:
- Have the new service’s outbox return
external_idfromsend(). - Have its ingest call
OutboxService.resolve_approval(...). - Set
approval.notify = "<service>"on the bridge that needs approval.
Under the operator gate the new service’s answers decide only when the
requesting bridge’s policy lists <service> in its methods and
services.cowboy.approvals.transportIdentities.<service> maps the answering
identity to one of the policy’s operators. Without both, the card is still
posted, but an answer left on it decides nothing.
No changes to OutboxService or the requesting service are required.
Gated Effects
An effect is an action on the world that an agent may propose but must not
perform: pushing to a branch someone else consumes, publishing, deploying.
services.cowboy.pubsub.effects gives each declared effect a fixed shape —
the agent names a commit, a human sees exactly that commit on an approval
card, and after ✅ the host applies exactly that commit as a user of the
operator’s choosing. Nothing the agent says on the card is trusted; nothing
the agent can do between the card and the push changes what gets pushed.
It reuses the Outbox Approval Protocol unchanged. What is new
is the seam on the far side of the gate: a bridge with no privilege of its own
starts a static systemd template unit through polkit, and that unit — running
as the declared runAs user inside the standard sandbox — does the work.
The flow
agent effects bridge host
----- -------------- ----
commit in workspace
effects-request tool ───▶ effects:outbox entry
(git bundle into pre_send:
the handoff dir) systemctl start --wait
cowboy-effect-<name>@describe-<sha> ──▶ unit (User=runAs):
unbundle, fetch, policy,
write results/describe-<sha>.json
read the result; refuse ⇒ ack + message
ok ⇒ pin sha/base/description
approval card → notify channel
⏳ … human reacts ✅
send():
guard pinned sha == requested sha
mark_effect
systemctl start --wait
cowboy-effect-<name>@apply-<sha> ─────▶ unit: re-fetch, re-run policy,
push --force-with-lease,
verify, write apply-<sha>.json
result → agent inbox [effects <id>] …
→ notify channel (untagged copy)
Two runs of the same program, addressed by the same 40-hex sha: describe before the card, apply after it. The sha in the unit instance name is the whole of what the bridge can choose; polkit permits only that one action, on only those unit names, for only the bridge user.
Declaring an effect
services.cowboy.pubsub.effects = {
enable = true;
approval.notify_channel = "<discord channel id>"; # required; there is no unapproved mode
declared.blog = {
runAs = "<user>"; # the unit's User=; never root, never the bridge
gitPush = {
remoteUrl = "git@github.com:me/blog.git"; # ssh://, git@, or file:/// — never https
branch = "main";
webUrl = "https://github.com/me/blog"; # optional; result messages link the commit
allowedPaths = [ "docs/posts/" ]; # directories (or exact files) every commit must stay inside
maxCommits = 3;
knownHosts = "github.com ssh-ed25519 AAAA…"; # required for ssh remotes
};
credentials.sshkey = "/home/<user>/.ssh/keys/github"; # loaded with LoadCredential=, readable by root only
};
};
approval.required is read-only true. An effects bridge that starts without
approval configured exits at authenticate(), and the module refuses to
evaluate without a notify channel or with the notify bridge disabled — the
failure mode where a “gated” effect quietly evaluates to an ungated one is the
one this module exists to close.
Each declared effect produces:
- a group
cowboy-effect-<name>whose members are the agents plusrunAs(never the bridge), and a setgid handoff directory/var/lib/cowboy-handoff/<name>(2770) where the agent’s bundles land; - a state directory
/var/lib/cowboy-effect-<name>owned byrunAsholding the mirrorrepo.git(0700),results/, and the lock; - a template unit
cowboy-effect-<name>@.servicewithUser=runAs,NoNewPrivileges,ProtectSystem=strict,ProtectHome, an empty capability set,IPAddressDenyoutside the remote, and the docker socket inaccessible; - one polkit rule allowing
cowboy-bridge-effectstostart(and only start)cowboy-effect-<name>@(describe|apply)-<40 hex>.service; - an
effects-requesttool visible to the effect’s agents.
Set runner instead of gitPush to supply your own program. It receives the
instance name (describe-<sha> or apply-<sha>) as $1, runs as runAs
with STATE_DIRECTORY set, and must write
$STATE_DIRECTORY/results/<verb>-<sha>.json with at least {"ok": bool, "message": str}; a describe result should also carry what the card shows
(base, count, commits, files, diffstat, policy).
What the agent does
The effects-request tool takes effect, sha, repo, and content. It
verifies the sha is a commit in repo and that refs/remotes/origin/<branch>
exists there, writes a git bundle of sha ^origin/<branch> into the handoff
directory (size-capped), and files one entry on effects:outbox. It returns
{"status": "pending_approval", "request_id": …} and nothing has run.
The outcome arrives later in the agent’s inbox as a message starting
[effects <request_id>]. A refusal — the branch moved, a file outside
allowedPaths, a merge commit, too many commits, a symlink — is text, not a
retry: the agent rebases and files a new sha, which is a new approval. The
policy is checked on every commit in the range, not on the net diff, so an
add-then-revert pair cannot smuggle a path into history that the card never
showed. A newer request for the same effect from the same agent supersedes
an older one still waiting; a refused request supersedes nothing.
What the human sees
Approval needed [effects/blog]: push to git@github.com:me/blog.git main (as <user>)
Requested by agent: `publish monix — reviewed, no blockers`
Commit 3f9c2a1e… (fast-forward from 096ab9d, 1 commit, policy ok)
3f9c2a1 blog: publish monix (agent-gated) (agent, 2026-08-25)
Files:
A docs/posts/2026-08-25-monix.md
1 file changed, 118 insertions(+)
Inspect: git -C /var/lib/cowboy-effect-blog/repo.git show 3f9c2a1
React ✅ to push exactly this commit, ❌ to reject. Expires in 60 min; if the branch moves first the push refuses itself.
Every line but the quoted Requested by one comes from the describe run,
which read the bundle as runAs, not from the agent. The agent’s own text
is a single quoted line, capped, with backticks neutralised, so it cannot
imitate the trusted lines. The Inspect: path is a real mirror on the host
for a second look before reacting.
What can still go wrong
- The branch moves.
applyrefetches and requires the branch to be at the basedescriberecorded; the push itself is--force-with-leaseagainst that base. Either check failing is a refusal with the new head named. - The unit is interrupted. The bridge marks the entry
phase=effectbefore startingapply, so a restart mid-push reports uncertainty instead of re-running. Anapplyunit that leaves no result file, including one whosesystemctl --waittimed out (the unit keeps running), is uncertain too, not a failure.on_uncertainreadsresults/applied-<sha>.jsonand says whether the push in fact completed. - A stale result. The bridge treats a result file older than the unit it just started as absent — a describe that failed to run (polkit said no, say) cannot be answered by the previous run’s file.
runAsis a login user. The unit inherits that user’s DB groups (the module warns). The sandbox is what bounds them; a dedicated uid with a deploy key is the better end state, and is a one-line change torunAsandcredentials.sshkey.
See Approvals & Outbox for the protocol underneath and the threat model’s residual authorities for the authorities this adds.
Rebuilds and generated environments
The rebuild bridge is separate from a declared Git effect. Enable it through
services.cowboy.pubsub.rebuild and configure its repository and approval
settings. The rebuild-request tool queues a system or home rebuild and returns
a request ID. A queued or pending-approval result is not a completed rebuild.
The later outcome arrives in the agent inbox tagged [rebuild <request_id>].
A system request builds the configured remote revision with nixos-rebuild boot, then starts activation in a separate systemd unit. A home request builds
and activates the requesting agent’s home-manager profile, for an agent listed
in pubsub.rebuild.approval.homeUsers. Under sheepdog this is how an agent
applies its own home configuration: the sandbox refuses the activation step of
a switch the agent runs itself, so the generated prompt names this route, or
the operator for an agent not in that list. A home rebuild
cannot apply system service or networking changes. Local unpushed edits are
not the remote revision the bridge builds.
For system requests, the bridge reports that the build finished and the switch
is queued in cowboy-activate.service. That is the last thing it reports: the
switch runs after the message, and the bridge does not report how it ends. The
approval gate records the claim’s outcome as succeeded at that point, with
the same queued detail. Inspect the activation unit and running service before
calling the change live:
sudo systemctl status cowboy-activate.service
sudo journalctl -u cowboy-activate.service
cowboy doctor
The bridge compares the built system with the previously running generation,
or the built home profile with the previous home generation. When it can prove
they are equal, its result says the rebuild deployed no change. Check the
request type, pushed revision and selected flake inputs before retrying. An
unreadable generation is unknown, not evidence of a no-op. After an interrupted
activation, inspect the running system and the bridge’s status record at
/var/lib/cowboy-rebuild/last-rebuild.json before submitting again.
Ordinary Docker also has implemented generation machinery: settings can scaffold
a flake in the persistent configuration volume, bake its container output and
launch the resulting supervisor. The host records generation metadata for
cowboy list; that record is not a liveness check. Configuration and workspace
volumes are mutable state to preserve across replacement. See
Deployment Paths for launch setup.
These mechanisms generate and apply environments. They do not implement an autonomous rollback or pull-request review workflow.
Publish a canonical GitHub file (no bundle)
For a blog queue, githubFile replaces gitPush:
services.cowboy.pubsub.effects.declared.blog = {
runAs = "dylan";
githubFile = {
sourceRepo = "dmadisetti/blog-queue";
sourceBranch = "master";
sourcePrefixes = [ "drafts/" "scheduled/" ];
targetRepo = "dmadisetti/blog";
branch = "main";
knownHosts = "github.com ssh-ed25519 <pinned public host key>";
};
credentials.sshkey = "/path/to/operator/github-key";
};
The generated script and tool take only a repository-relative filename:
publish-blog drafts/topical/my-post.md
The helper resolves that file through GitHub, then submits its blob ID to its own Redis effects outbox. It does not submit local content, create a Git bundle, or write to a handoff directory. The host independently fetches the fixed source branch and requires exactly one matching regular Markdown file in the permitted folders. Ambiguous identical blobs are refused rather than silently choosing a filename.
The host prepares a single commit against the current destination branch, without executing repository code, hooks, or filters. The body is unchanged; the publication date is stamped in frontmatter. The card links the immutable GitHub source and identifies the exact candidate and destination. Only an operator’s approval triggers the push. Describe units use the source blob ID; apply units use the immutable candidate commit ID, so retrying a rejected or stale request cannot replace an older approved candidate. Source/target movement or a changed publication date invalidates approval. Nothing removes or rewrites the queue.
The initial implementation publishes one Markdown file, not an asset tree. Missing relative assets, draft markers, missing required metadata, destination collisions, and publication within the preceding seven Pacific calendar days are refusals. Editorial/link review remains Cowboy’s job. Suggestions go in a source-repository PR for the operator to review and merge; unmerged local fixes are never part of this operation. A queued request is not a successful publish.
The existing static unit, polkit scope, runAs identity, credential isolation,
and mandatory approval remain in force. A file effect creates no handoff group
or directory, and is not exposed through the Git-bundle effects-request tool.
AI Governance
Cowboy constrains what an agent can do through several independent mechanisms. They overlap deliberately: a command rejected by one layer is not relied upon to be caught by another.
| Layer | Where | What it does |
|---|---|---|
| Approvals | bridge / Redis | hold outbound messages for a human reaction |
| Egress allowlist | secrets proxy | restrict HTTP methods and destinations, inject credentials |
| Sheepdog | seccomp sandbox | enforce file/network/exec rules at the syscall level |
This page summarizes how they are configured. There is no runtime rule engine
or FilterAction-style API in the harness — governance is the sum of the
mechanisms below. Command, path, and syscall enforcement is done by sheepdog at
the kernel boundary (see below), not by a separate string-matching filter layer.
Approvals (human in the loop)
For outbound messages that should not be sent autonomously, the bridge approval protocol holds a message until a human reacts to a notification. Configure it per bridge:
services.cowboy.bridges.discord.approval = {
required = true;
notify = "discord";
notify_channel = "<channel-id>";
timeout = 3600;
};
Approval state is tracked in Redis hashes and resolved from human reactions. See Approvals & Outbox for the full protocol.
Egress allowlist (secrets proxy)
In the managed proxy deployment, network rules route HTTP through the proxy and the agent uses placeholder provider credentials. Local and ordinary Docker launches hold credentials instead. With egress control enabled, GET, HEAD and OPTIONS pass the method gate; every other method needs an allowed destination or receives HTTP 403. TRACE receives HTTP 403 everywhere, whatever the allowlist or egress setting, because a server that echoes it would return the injected credential. Allowed requests can still change external state or disclose readable data. See Security Model.
services.cowboy.secretsProxy = {
enable = true;
domainMappings = {
"api.anthropic.com" = {
secretPath = "/run/agenix/anthropic-key";
headerName = "x-api-key";
};
};
# Extra write-allowed domains. Domains in domainMappings are implicitly
# write-allowed.
allowedWriteDomains = [ "github.com" "api.github.com" "*.githubusercontent.com" ];
# Prefer an exact grant when a whole host does not need write access.
allowedWriteRoutes = [ {
scheme = "https";
hostname = "api.example.com";
port = 443;
path = "/v1/messages";
methods = [ "POST" ];
contentTypes = [ "application/json" ];
queryPolicy = "forbid";
} ];
# Networks the proxy refuses to connect to. Setting this replaces the
# default (link-local, which holds most clouds' metadata services, and AWS's
# IPv6 metadata address), so keep those entries. This adds the home LAN.
deniedNetworks = [ "169.254.0.0/16" "fe80::/10" "fd00:ec2::254/128" "192.168.0.0/16" ];
# Empty means any destination not denied. When non-empty, only these
# networks are reachable. Deny wins over allow.
allowedNetworks = [ ];
};
allowedWriteRoutes is additive with the backward-compatible
allowedWriteDomains list. Each structured entry is exact: it has no hostname
wildcards and a write must match its scheme, destination hostname, explicit
port, normalized path, method, and media type. queryPolicy = "forbid" rejects
any query string; "allow" permits arbitrary query parameters. The proxy
fails startup on malformed policy and refuses ambiguous paths (including raw,
encoded, or double-encoded dot segments and encoded separators), rather than
letting an upstream server normalize them into a different route. Content type
parameters such as charset do not affect the media-type comparison.
Because every domainMappings key is still implicitly copied to
allowedWriteDomains for compatibility, use allowedWriteRoutes for hosts
that are not also credential mappings when route-level narrowing is required.
The proxy connects from the host’s network namespace, so these two options
bound what an agent reaches from the host. By default, only link-local and
AWS’s IPv6 metadata address are refused. Loopback and private networks stay
reachable, so agents can use local services and each other. The proxy judges
the address a name resolves to and the peer it actually connected to. Routes
in passthroughPorts and sshDestinations bypass the proxy and this policy.
The allowlist enforcement lives in the mitmproxy addon (proxy/addon.py);
write methods, legacy wildcard-domain checks, exact structured route checks and
the destination policy are implemented there. See Security Model.
Sheepdog (seccomp sandbox)
Sheepdog enforces file, network, and exec rules at the syscall level rather than
by string matching. Rules are verb-granular — Bash, Read, Edit, Create,
Delete, and Connect — and resolve to allow or deny, with optional
runtime-granted exceptions (lazy permissions) taking precedence over baked-in
denies.
services.cowboy.sheepdog = {
enable = true;
lazyPerms = true; # allow runtime permission grants
};
services.cowboy.agents.alice.sheepdog = {
extraDeny = [ "Read(/home/alice/workspace/credentials/**)" ];
extraAllow = [ "Bash(make)" ];
extraBlockedSyscalls = [ "keyctl" ];
extraReadonlyPaths = [ "/home/alice/workspace/vendor" ];
extraMaskedPaths = [ "/proc/interrupts" ];
};
Each extra* option adds to a shipped baseline. The baseline already lets
the agent read, edit, create and delete under its own home directory
(/home/alice here), which is where managed tools run, and blocks the
sandbox-escape syscalls and /proc paths.
Setting deny, allow, blockedSyscalls, readonlyPaths or maskedPaths
instead replaces that baseline. Evaluation fails if a replacement drops a
shipped deny rule, blocked syscall, masked path or read-only path that is not
named in dropBaseline. A replacement allow list that drops shipped rules
is only a warning, but every dropped rule is a tool or path the agent loses.
Sheepdog is Linux-only. See crates/sheepdog/src/policy.rs and
modules/options/sheepdog.nix.
See also
Plan state is advisory
The agent can call update_plan_state to record an objective, tasks, blockers
and the next step. Each task is pending, in progress or completed. Updates
replace the supplied fields, keep at most one task in progress and record an
update timestamp.
The state is saved as plan_state.json in the session directory and loaded
on resume. Each update_plan_state result echoes the whole plan, including up
to eight tasks, and the model reads its current plan there. While such a
result is in the conversation, the model’s transient context packet leaves the
plan out and says where it is. Once compaction has removed the result, the
packet carries the plan instead. The packet is added to the conversation when
its content changes, and the latest one is current. For controlled
experiments the plan_packet launch setting changes this: append puts every
changed plan in a new packet and keeps the older ones, and rewrite does the
same but keeps only the latest packet. Neither echoes the plan in the result.
The default is transcript, the behaviour described above.
The first wake after at least an hour without a model request, when the prompt cache has likely expired, adds a note with the plan. The note asks the agent to check the plan against what is left and to update it if it is stale. See Compaction.
This is a memory aid, not an approval gate. Plan state does not restrict the tool list, impose a read-only planning phase or enforce that actions follow the listed tasks. Use bridge approvals and host policy for enforced controls.
Memory System
Persistent, cross-session memory for the agent. Notes are stored as Markdown files and surfaced back into the model’s context via a search step before the agent acts.
Source: crates/core/src/memory.rs. Tools are registered in
crates/core/src/tools/builtin.rs.
Backends
Memory is pluggable behind the MemoryBackend trait. Two backends exist:
ZkBackend— zettelkasten built on thezkCLI. Keyword-based full-text search. Always available, including lite builds. This is the default for lite.QmdBackend— hybrid BM25 + vector search via theqmdCLI, usingzkfor note authoring. Available only in ranch (non-lite) builds, where it is the default (memory_backend = "qmd").
The backend is selected by the memory_backend config key ("qmd" or "zk").
qmd_min_score (default 0.4) sets the relevance cutoff for the qmd backend.
If a lite build is asked for qmd, it falls back to zk.
Memory backends return shell command strings. Core asks its host to execute them and parses stdout into notes. This works through either Zellij or Montana; the required memory CLI must be available in the host’s execution environment.
Tools
The agent interacts with memory through two built-in tools:
__MEMORY_SAVE__— write a note.__MEMORY_SEARCH__— search notes.
Notes
A parsed note (MemoryNote) has:
| Field | Meaning |
|---|---|
id | identifier, usually the filename without extension |
title | title from the note’s frontmatter |
path | full path to the note file |
tags | tags associated with the note |
body | note body (may be truncated) |
score | relevance score 0.0–1.0; only set by QmdBackend |
Directory layout
Notes live under <cowboy_dir>/memory/, a zettelkasten managed by zk:
<cowboy_dir>/memory/
.zk/ # zk configuration and index
daily/ # YYYY-MM-DD.md journals
facts/ # atomic knowledge notes
decisions/ # decision records
templates/ # zk note templates
<cowboy_dir> is $HOME on a ranch install and $XDG_DATA_HOME/cowboy
(default ~/.local/share/cowboy) in lite mode.
Pre-tool retrieval
Memory search is wired in as a retrieval step before the agent runs tools,
gated by the pre_tool_retrieval config flag (default on). When enabled, the
harness searches memory based on the conversation and injects matching notes
into context so the model can use prior knowledge without an explicit search.
Retrieval does not fire inside sub-agents.
The MemoryBackend trait also exposes init_commands(), recent(limit),
search_deep(query), remember(title, content, template), journal(entry),
and an optional search_skills_deep(query) for searching skill files alongside
memory.
Sub-Agents
Sub-agents are child agent instances spawned by the harness to run a scoped task with a filtered toolset. The Zellij host opens a plugin pane; Montana starts another component instance on a thread in the same process. Both use files to communicate with the parent. Montana peers share its preopened directories and HTTP client; spawning a peer does not create another OS security boundary.
Source: crates/core/src/subagent.rs, crates/core/src/spawn.rs,
crates/core/src/subagent_config.rs.
How spawning works
The parent calls the built-in spawn_subagent tool. The harness then:
- Writes the task to
prompt.mdand the filtered tool manifest totools.jsonin a new directory under<cowboy_dir>/subagents/. - Requests a peer through the host, passing a JSON-encoded
SubagentConfigunder thesubagent_configkey. Zellij loads a visible plugin pane; Montana’s supervisor creates a component instance with its own agent ID. - The child, on its first heartbeat tick, writes a
lockfile and itspane_id, readsprompt.md+tools.json, and processes the prompt as a user message. - When the child finishes, it writes
response.mdand removeslock. - The parent detects completion on its heartbeat poll and injects the response back into its own conversation.
The shared spawn protocol uses host-executed shell commands for its spool files. WebAssembly does not itself forbid file I/O: Montana also grants direct WASI access to preopened directories. Pane visibility is a Zellij affordance; Montana has no terminal panes.
Directory layout
Each sub-agent gets a directory named <type>-<short_uuid>:
<cowboy_dir>/subagents/<type>-<id>/
prompt.md # task + metadata, written by parent
tools.json # filtered tool manifest, written by parent
lock # present while running, written by child
pane_id # host instance id (a pane id under Zellij)
response.md # final output, written by child on completion
<cowboy_dir> is $HOME on a ranch install and
$XDG_DATA_HOME/cowboy (default ~/.local/share/cowboy) in lite mode.
Sub-agent types
Three types are defined in the SubAgentType enum. Each restricts the tools
the child may call:
| Type | Allowed tools |
|---|---|
| Research | read, search, find, web-search, ls |
| Code | read, write, search, find, bash, ls, __HASHLINE_READ__, __HASHLINE_EDIT__ |
| Review | read, search, find, bash, ls |
Only Code gets write and the hashline edit tool. Review still has bash,
so its tool list does not enforce read-only filesystem access. The configured
host and tool policy determine what commands can do.
Models
SubagentConfig::cheap_defaults() selects the child’s provider and model.
Its fallback model names are:
| Provider | Default sub-agent model |
|---|---|
| OpenAI | gpt-4o-mini |
| OpenRouter | openai/gpt-4o-mini |
| Anthropic | claude-3-5-haiku-latest |
| Ollama | mistral:7b |
| Codex | gpt-5.6-luna |
| Vercel | zai/glm-5.3-flash |
An explicit subagent_model wins when that provider has a non-empty key.
Otherwise the main harness provider/model is
used when it is usable (a key, or a keyless Ollama/Codex provider), falling back
to the first keyed provider in the order OpenRouter, Anthropic, OpenAI, Vercel —
so the Ollama and Codex defaults above are only reached through the main
model.
Status
The parent tracks each child with the SubAgentStatus enum:
Starting— directory created, peer startingRunning—lockpresentCompleted—response.mdpresent,lockremovedFailed(String)—lockremoved without aresponse.md
Polling happens on the heartbeat timer, one poll at a time. A poll that has not answered after 30 seconds is replaced, and if it answers later its result is ignored, since it reports the children as they were before the newer poll looked.
Hashline Edit Format
Hashline is the harness’s read/edit format. Each line is tagged with a short hash of its content, so an edit can be rejected when the file has changed since the agent last read it.
Source: crates/core/src/hashline.rs. Exposed as the built-in tools
__HASHLINE_READ__ and __HASHLINE_EDIT__.
Format
Lines are formatted as {line_num}:{hash}|{content}:
1:a3|fn main() {
2:7f| println!("hello");
3:b2|}
__HASHLINE_READ__ returns a file in this form. The agent then references
lines by line:hash when editing.
Hash function
The hash is FNV-1a (offset basis 2166136261, prime 16777619) truncated to the
low byte (hash & 0xff) and formatted as two lowercase hex characters. With
256 possible values it is meant for change detection, not collision resistance.
Edit operations
__HASHLINE_EDIT__ takes an array of operations. Each references a target line
by line:hash:
replace— replace lines fromstartto optionalend(inclusive) with new contentinsert_before— insert content before the referenced lineinsert_after— insert content after the referenced linedelete— delete lines fromstartto optionalend(inclusive)
Every referenced line’s hash is validated against a fresh read of the file
before anything is applied. If any hash does not match, the whole edit is
rejected and the agent is told to re-read. Operations are applied in reverse
line order (so earlier edits don’t shift later line numbers), then the file is
rewritten in place with exactly the computed bytes — a file without a trailing
newline stays without one, and a blank last line stays. The write itself
re-checks that the file still holds the bytes that were read (cksum, in the
same shell invocation): if it changed in between, nothing is written and the
error names the stale line references. That check needs cksum on the agent’s
PATH and allowed by its sandbox policy (Bash(cksum) is in the default allow
list); if the check itself cannot run, the edit is refused with the shell’s
error rather than a retry hint. Files that are not valid UTF-8 or that contain
NUL bytes are refused, since the write cannot reproduce them byte-exact.
The parser accepts either operations or edits for the array key, and either
content or new_text for the text field.
Evals
The eval platform measures how a change to the harness affects agent outcomes. It covers a prompt, a launch key, a tool, or a whole revision. Each run records, per trial:
- whether the task’s verifier passed;
- the tokens used and an estimated cost;
- the agent and trial wall time;
- the model.
Runs go into a SQLite database that operators can read without root. It is opt-in, Linux-only, and runs Harbor tasks under rootless Podman through an approval-gated declared operation.
The Harness² loop names the surrounding improvement method Propose → Probe → Compose → Select → Reflect. This eval platform is its existing Harbor-based Probe engine; the terminology does not introduce another runner or automatic promotion path.
Enabling it
services.cowboy.pubsub.runas.enable = true; # the approval-gated operations
services.cowboy.evals = {
agents = [ "cb" ]; # may stage inputs and request `eval`
readers = [ "alice" ]; # may read results; eval agents always can
};
This generates:
- the
evaloperation, which runs as thecowboy-evalsystem account; - the database directory
/var/lib/cowboy-eval; - the inbox
/var/lib/cowboy-eval-inbox, bind-mounted writable into each eval agent; - the
cowboy-evalcommand on every user’s PATH. - a host firewall rule for the
cowboy-evalaccount: task containers may reach the public internet (benchmarks such as Terminal-Bench install packages), but not private, link-local or loopback addresses, except the resolver and the credential proxy. It needsnetworking.firewallornetworking.nftablesenabled.
Nothing is generated while agents is empty. timeout (default 6 hours),
memoryMax, tasksMax and cpuQuota bound a single run.
Experiments
An experiment is a directory: experiment.json plus Harbor tasks and any files the
arms install. For example:
{
"schema_version": 2,
"name": "terse-prompt",
"hypothesis": "A terse system prompt does not lower task success.",
"harness_loop": {
"cycle": "terse-prompt-1",
"stage": "probe",
"baseline_arm": "shipped",
"candidate_arms": ["terse"]
},
"arms": {
"shipped": {},
"terse": { "files": { "prompt.md": "terse.md" } }
},
"suite": { "tasks": "tasks", "images": ["python:3.12-slim@sha256:…"] },
"design": { "tasks": ["01-fix", "02-refactor"], "replicates_per_task": 5,
"randomization_seed": 7, "pairing": "paired", "agent_timeout_sec": 300 },
"budget": { "max_trials": 20, "max_usd": 2 },
"primary_outcome": "Harbor verifier reward == 1"
}
An arm may set:
launch: string launch keys;files: agent config files, as destination → path in the experiment;expect_stderr: lines that must appear inmontana.log, which proves the arm took effect;modelorprovider: a per-arm override. The runner reaches a provider only through the credential proxy, so an arm may name onlyopenrouterorvercel;revision: the arm runs another build, described below.
Every trial launches with oneshot_nudges=3: a reply that ends the turn
without a tool call or TASK COMPLETE is answered with a request to continue,
up to three times, because nobody else will answer it. An arm may set its own
value, 0 included. Keys the controller owns are refused. These include the provider, the model, credentials, sockets and paths.
design.agent_timeout_sec sets one runner budget for every task. If it is
omitted, or set to "task", each task gets its own task.toml agent timeout
minus 30 seconds, which a benchmark with mixed timeouts needs. Either way, the
Harbor agent timeout must leave 30 seconds for setup and collection. The agent
works in the task’s last Dockerfile WORKDIR, or design.workspace, or /app.
The schedule is deterministic. Each replicate shuffles the tasks and each
block (one task and replicate) shuffles the arms, from the seed. A payload runs
a slice of the schedule, so a large experiment can be run and paid for in
parts. A slice must hold whole blocks, because a block’s arms are compared only
with each other: with two arms it starts at an odd sequence number and holds an
even number of trials. payload --dir and the runner refuse a slice that
splits a block. cowboy-eval schedule DIR [--start N --limit N] prints the
schedule, or a slice of it, as CSV with its sequence numbers. cowboy-eval analyze pools the parts (see
Reading results).
cowboy-eval validate DIR checks a definition and prints its digest and the
arm table that goes on the approval card. An experiment does not have to be on
main. cowboy-eval pack REF PATH archives it into the inbox from any git ref,
and the run records the commit and tree it came from.
Comparing revisions
An arm with no revision runs the deployed build. To compare builds, pack the
other revision’s runtime closure:
cowboy-eval pack-arm github:you/cowboy/<commit> > b.json
This builds <commit>#harbor-runtime-closure. The closure contains Montana, the lite
component and a minimal Python. For revisions that predate that output, the
current tree packs the old revision’s Montana and component. The binding goes
into the payload as --arm NAME=b.json.
The approver sees the closure’s hash. The claim that it was built from
<commit> is only attested, not verified. The closure runs only inside the task
container; the controller, the Harbor adapter and the trigger are always the
deployed build. A commit that crashes at launch counts as a failure of its arm,
not as infrastructure.
Running
cowboy-eval pack HEAD evals/experiments/terse-prompt > exp.json
cowboy-eval payload --experiment exp.json --model z-ai/glm-5.3-flash \
--price z-ai/glm-5.3-flash=0.07,0.01,0.4 --limit 20 --max-usd 2 \
--dir evals/experiments/terse-prompt > payload.json
The provider is OpenRouter unless payload --provider vercel selects the
Vercel AI Gateway, whose model ids look like zai/glm-5.2. Either way the
credential proxy injects the key, and a run’s relay admits only its provider.
--price MODEL=IN,CACHE_READ,OUT gives USD per million fresh input,
cache-read and output tokens. A fourth value, CACHE_WRITE, prices cache
writes; input counts include cache reads and writes, so each is priced once.
A model that reports no cache writes needs only the three. If a trial reports
cache writes and its model has no cache-write price, the trial has no cost
estimate and the run aborts, starting no more trials, rather than price the
writes at zero.
pack and pack-arm write into the inbox. To add an archive built some other way, use
cowboy-eval stage FILE. It names the file by its hash and makes it readable to the
runner (mode 0440). A plain cp usually leaves a file mode 0600, and the runner refuses it.
payload prints the canonical payload on stdout and the approval card on
stderr. The agent submits the payload with runas-request, using operation eval. A
human approves that exact payload, budget included. The payload’s
max_trials and max_usd may not exceed the experiment’s budget, which
bounds any one run; payload --dir and the runner both refuse one that does.
The runner does not add up what several runs of an experiment spend. The
runner then does the following:
- It copies each named archive out of the inbox and checks its hash.
- It pre-pulls the pinned images.
- It runs each scheduled trial in a fresh Harbor environment. A trial that runs past its task’s timeouts plus a margin is stopped, then killed a minute later, and any container it left is removed.
- It records every attempt, including failures, with the stage where it stopped.
The runner stops before a trial the estimate says would pass max_usd. It
aborts after three consecutive infrastructure failures, meaning environment or
agent setup, unless the experiment freezes a different list. A trial with no
Harbor result, or whose trigger or artifact collection fails in the runner, is
an infrastructure failure at stage controller. A run that has already
stopped starting trials, because it was drained or reached its budget or time
limit, keeps that reason even if the trials still running then fail this way.
A run the runner itself cannot finish is recorded as failed, not left
running.
Concurrent trials
By default trials run one at a time. payload --concurrency N asks for up to
N at once, and the card shows it. The runner uses the least of that, the
experiment’s optional design.max_concurrency and the host’s
services.cowboy.evals.maxConcurrency (unlimited by default). The first trial
always starts. Each further one starts only if both of these hold:
- its task’s memory fits
memoryMax, less 1 GiB, beside the trials already running; - the host has memory available for it and for the trials already running, plus 2 GiB, and memory pressure is under 10%. A running trial’s memory is counted in full because a trial just started has not claimed any yet.
Otherwise it waits for a trial to finish. The budget forecast counts the trials still running. Attempts are recorded as trials finish.
While a run is going, any reader can lower its limit or drain it:
cowboy-eval throttle 3f1c 2 # at most 2 trials at once from now on
cowboy-eval drain 3f1c # start no more; running trials finish
Each reader’s command replaces that reader’s own earlier limit. The runner
takes the lowest limit any reader has set and never goes above the approved
one. A drained run ends stopped (drained).
The reply on the approval channel summarises the run:
eval terse-prompt 3f1c…: completed, 20/20 trials
shipped: 8/10 pass, 4.1k in/0.3k out, $0.0004 per trial, $0.0005 per pass, agent 38s med
terse: 7/9 pass (not scored: 1 infra), 3.6k in/0.3k out, $0.0004 per trial, $0.0005 per pass, agent 35s med
paired shipped/terse: 2 shipped-only / 1 terse-only of 9 pairs (not scored: 1 infra), sign p=1.000, cost shipped-terse $+0.0000/trial
estimated $0.0079 (advisory budget); key usage +$0.0081 incl. concurrent use
full report: cowboy-eval report 3f1c…
What a score leaves out
An arm’s score is its passes over its valid attempts. Model errors, timeouts
and a revision that crashes at launch are valid attempts that failed. The
runner never runs a trial twice, so four kinds of scheduled trial are left
out of the denominator. The reply and cowboy-eval report count each kind
beside the score:
infra: attempts that failed as infrastructure, at a stage the experiment’sexclusions.infrastructure_stagesnames (environment or agent setup by default) or at stagecontroller;interrupted: trials in flight when the run was stopped (see Rebuilding the host stops runs), left out like infrastructure failures;skipped for time: trials the run’s time limit left out;not started: trials that never started because the run reached its budget, was drained or was aborted.
The paired analysis drops a whole block when either of its arms failed as
infrastructure (infra) and counts a block missing an arm as incomplete.
To run such blocks again, approve a payload whose slice holds them, then pool
the runs with cowboy-eval analyze. Tasks that payload --exclude leaves out
are different: the approver removes them before the run, the card lists them,
and they are never scheduled, so none of these counts includes them.
Rebuilding the host stops runs
Each run executes in an instance of the eval operation’s runas unit, whose
name carries a digest of its configuration. Rebuilding and switching the host
(nixos-rebuild switch, or anything that runs switch-to-configuration)
stops that instance whenever the unit changed, and any change to the deployed
Cowboy changes it. Nothing holds a rebuild back for a run, so check
cowboy-eval runs before switching.
A stopped run is not resumed. The trials in flight are lost, together with what they had already spent at the provider. On the unit’s SIGTERM the controller records what it can before systemd kills what is left:
- the run ends with status
interrupted, stop reasoninterrupted (service stopped), and afinished_at; - each trial in flight is recorded at stage
interruptedwith that cause, classified as infrastructure. It is counted asinterrupted, apart frominfra, and like an infrastructure failure it is left out of the score and invalidates its block, which a later run can replace; - trials that had already finished stay recorded as they were.
If the controller was killed before it could record anything, the run is left
running. The next run ends it as interrupted before it starts: it holds the
host’s one-run lock, so any other run still marked running has no controller.
A controller records its process and boot id, so a run whose process is still
alive is never touched. To end such runs without waiting for another run, run
sudo -u cowboy-eval cowboy-eval reconcile on the host (--dry-run shows
what it would change). It marks a run only when its recorded process is gone,
or, for a run recorded before controllers were, when systemd reports its unit
inactive.
To run the remainder, approve a payload with the same slice, or a slice that
holds the blocks the stopped run did not finish. Use payload --exclude to
leave out tasks the stopped run already completed validly in every block,
since each trial spends money again. Then pool the runs with
cowboy-eval analyze: a block that was interrupted counts from the later run,
and a block that ran validly keeps its first result (see
Reading results).
Terminal-Bench 2.1
The flake builds Terminal-Bench 2.1 as an experiment: the dataset version
published on Harbor Hub (terminal-bench/terminal-bench-2-1), downloaded at a
pinned version and checked against a fixed hash. No git commit of the task
repositories matches that version exactly. The experiment has 89 tasks, with
reference solutions removed and each task image pinned by digest. It has one
arm, the deployed build, and is scored as a benchmark rather than a
comparison. Pack the directory and run it in slices:
cowboy-eval pack-dir $(nix build --print-out-paths github:you/cowboy/<commit>#terminal-bench-2-1) > tb.json
cowboy-eval payload --experiment tb.json --model … --price … --start 1 --limit 20 --concurrency 4 > payload.json
Tasks use their own images and the public internet. Their agent timeouts range
from 10 minutes to over 3 hours. The runner starts the slice’s longest trials
first, and skips any trial whose timeouts could run past the run’s timeout;
the rest still run, and the run ends stopped, naming the skipped tasks.
payload --exclude <task> (repeatable, shown on the card) leaves tasks out of
a slice, for example build-pov-ray and sam-cell-seg, which each hold a slot
for hours. It refuses a slice with any task that asks for more memory than
memoryMax less 1 GiB. The full set needs memoryMax = "9G", and a timeout
of at least 26100 for build-pov-ray. The images total about 20 GB compressed;
set services.cowboy.evals.keepImages to keep them between runs.
Published scores, such as tbench.ai and Artificial Analysis, run this dataset with other harnesses and sandboxes, and usually average 3 trials per task. A score here measures Cowboy with the run’s model on this host, so treat a published score for the same model as a reference point, not a like-for-like comparison.
Reading results
cowboy-eval runs
cowboy-eval report 3f1c # per-arm and per-trial tables
cowboy-eval report 3f1c --json
cowboy-eval analyze 3f1c 9e02 51ab # one analysis over several runs
cowboy-eval sql 'SELECT arm, avg(success), sum(cost_estimate_usd) FROM attempts GROUP BY arm'
analyze pools runs of one experiment definition, such as the slices of a
large one, and prints the per-arm summaries and paired analysis as JSON. With
more than two arms in a paired design, the paired analysis runs for every arm
pair, in definition order, under pairwise; with two, that one comparison is
also paired. Beside success, each arm reports estimated cost per trial and
per pass (everything its valid attempts spent over its passes), and cache-read
tokens, cache-write tokens and responses per trial. Each comparison reports the
macro per-pair cost difference, with a task-stratified bootstrap CI over the
pairs both arms priced, and each arm’s cost per pass over those pairs. It
refuses runs of different definitions, or where an arm used a different
provider or model; builds_per_arm shows whether an arm’s build changed
between runs. Each block counts once, from the oldest run in which every arm
ran and none failed as infrastructure. A block no run completed that way
counts from the oldest run that holds it. So a block that failed as
infrastructure and was run again in a later payload counts from the later run.
A block that ran validly is never replaced, whatever a later run of it scored.
The database opens read-only for readers. Each trial’s Harbor artifacts
(result.json, montana.log, frames.ndjson) are stored by hash under
/var/lib/cowboy-eval/blobs, and artifacts maps them to attempts. Up to
200 files of at most 64 MiB each are kept per trial. Once a run is recorded,
or refused, the runner deletes its working tree under the cowboy-eval
account’s runs/ directory, which holds copies of its archives and Harbor’s
job directories. A run the runner itself could not finish keeps its tree for
diagnosis.
Limits
- The budget is advisory (
specs/THREAT-MODEL.mdN-18). It is estimated from the usage the harness reports inside the task container. The key-usage delta is recorded as a cross-check, not enforced. Trials already running when the budget is reached still finish, so a run can end past it; its stop reason then gives the estimate that exceeded the budget. - One run holds the proxy relay at a time; a run’s own trials may overlap.
- The runner has host network access so it can reach the credential proxy.
Each task container still gets its own network mode. The pinned local tasks
use
no-network, with the provider reachable only through a relay socket. A task with network, such as every Terminal-Bench task, can also reach the credential proxy directly and use every credential route it has on the host (specs/THREAT-MODEL.md). - Readers see everything recorded, including trajectories.
Harness² loop
Cowboy uses Propose → Probe → Compose → Select → Reflect as the vocabulary for improving its soft harness. This is a method around the existing eval platform, not a second benchmark runner. Harbor remains the only trial runner.
The five stages
| Stage | Cowboy meaning | Current automation |
|---|---|---|
| Propose | Author bounded, data-only harness variants as ordinary experiment arms. | The experiment schema, content digest, approval card, and Git review freeze the proposal. |
| Probe | Run the baseline and candidates against the same Harbor task suite. | The approval-gated eval operation schedules, runs, and records the trials. |
| Compose | Form a new candidate from sanitized trajectory and deliverable evidence. | External and reviewed; the eval runner does not rewrite its experiment or deployment. |
| Select | Compare frozen candidates with the baseline and permit an explicit abstention. | External and reviewed; reports provide evidence but never silently declare a winner. |
| Reflect | Record evidence-backed lessons and prepare the next reviewed Git change. | External and reviewed; there is no automatic production promotion. |
An eval report’s statistical aggregation supports review, but it does not turn
that review into an automatic Compose, Select, or Reflect action. Likewise,
attempts.stage records where a Harbor trial ended; it is unrelated to these
five method stages.
Marking a Probe
Schema-v2 experiments may include an optional harness_loop block:
{
"harness_loop": {
"cycle": "terse-prompt-1",
"stage": "probe",
"baseline_arm": "shipped",
"candidate_arms": ["terse", "tool-guidance"]
}
}
The block is descriptive, content-addressed metadata. Validation requires:
- exactly the four fields shown above;
- a short lowercase cycle slug;
stageto beprobe, because that is the outer-loop stage Harbor executes;- one existing baseline arm and at least one unique existing candidate arm;
- every experiment arm to be classified exactly once as baseline or candidate.
The approval card shows the cycle and arm roles. Omitting the block preserves the behavior of existing schema-v2 benchmarks.
The metadata does not choose a winner, grant authority, or execute another
stage. In particular, abstention is a selection action—not a fake arm or a
zero-cost trial—so it does not appear in candidate_arms.
Candidate boundary
The block classifies arm roles only. It does not certify that a candidate has a typed soft-harness profile; ordinary arm validation still decides what can run. Until a typed candidate compiler exists, the following restrictions are an explicit author-and-reviewer convention rather than a validator guarantee.
A near-term soft candidate should lower to fields ordinary arms already support:
- prompt or configuration overlays through
files; - allowlisted string launch-map settings through
launch; - a fixed combination of those data-only changes.
A cross-revision arm remains an existing revision comparison, not a soft
candidate. Authors and reviewers must reject soft candidates carrying shell
commands, executable plugins, URLs, host paths, secrets, arbitrary environment
variables, task or verifier edits, Nix authority, bridge policy, sandbox policy,
or network policy. Existing arm and controller validation remains authoritative
for execution safety; the narrower soft-candidate convention is not yet inferred
from candidate_arms.
Evidence separation
Harbor’s verifier result—not an agent claim—determines trial success. The current archive and runtime provide execution-role separation, but they do not prove independently owned verifier provenance or author blindness. Do not claim stronger separation than that.
cowboy-eval report and cowboy-eval analyze contain verifier-derived scores.
Those scored documents may inform a human selection review, but must not be
fed back to a pre-selection proposer or composer that is meant to remain blind
to hidden tests, answer keys, verifier source, or grader verdicts. Any future
automation must materialize explicit score-free views for those roles.
Keep proposer, trial agent, composer, selector, and verifier contexts separate. A later stage receives only its declared, frozen evidence—not ambient access to the experiment tree or another role’s hidden inputs.
Selection and promotion
Selection considers exactly:
- the baseline;
- each declared candidate; and
abstain.
Selecting the baseline means retaining the known deployment. Abstaining means the evidence is insufficient; it is not a failed trial. Missing, invalid, or infrastructure-dominated evidence should favor abstention rather than automatic promotion.
A selection produces a recommendation and evidence bundle only. Promotion is a separate, human-reviewed Git change that re-expresses the selected data in canonical configuration. The eval account has no reason to mutate the running experiment, deployed configuration, repository, approval policy, or its own runner.
Future orchestration
If more of the loop is automated later, each generative boundary must stop and materialize canonical artifacts before proceeding:
- run proposal work through Harbor;
- save typed candidates without applying them;
- content-address and approve a new baseline-plus-candidates experiment;
- run its Probe through the existing
evaloperation; - select from baseline, candidates, and abstention using frozen evidence;
- emit a recommendation for human Git review.
No approved run recursively extends its own schedule or changes its own arm. Model-mediated proposal or selection remains a Harbor job, with a fresh approval boundary where authority or paid work changes.
Browser Automation
The harness can drive a real browser through Camoufox, an anti-detection Firefox fork. Agents navigate pages, read accessibility snapshots, interact with elements, run JavaScript, and take screenshots.
Source: pkgs/camoufox/, modules/camoufox.nix,
modules/options/camoufox.nix.
Components
camoufox— the Camoufox browser binary (anti-detection Firefox, daijro/camoufox).camofox-server— a Node.js REST server wrapping Camoufox (jo-inc/camofox-browser).cowboy-browser— a shell CLI (pkgs/camoufox/cowboy-browser.sh) that the agent calls; it talks to the server’s REST API.
All three are exposed as flake packages: nix build .#camoufox,
.#camofox-server, .#cowboy-browser.
Deployment
The server runs inside a shared NixOS container (cowboy-camoufox) with one
camoufox-<user> systemd service per agent. Each agent’s server listens on
basePort + (uid - 1338), where basePort defaults to 9377. Browsing happens
under a headless Xvfb display.
Enable it with:
services.cowboy.camoufox.enable = true;
This requires services.cowboy.secretsProxy.enable = true — the camoufox
container uses the proxy’s veth networking, and the module asserts this.
Options under services.cowboy.camoufox:
| Option | Default | Meaning |
|---|---|---|
enable | false | enable the camoufox container |
basePort | 9377 | base port; per-agent port derives from UID |
CLI
cowboy-browser keeps a session id in a file under $XDG_RUNTIME_DIR and
targets the server at $CAMOFOX_URL (default http://10.200.0.1:9377, the
veth host address — localhost does not reach the container). Subcommands:
cowboy-browser navigate <url> Open URL (creates a session if needed), return a snapshot
cowboy-browser snapshot [--full] Accessibility-tree snapshot of the current page
cowboy-browser click <ref> Click an element by ref
cowboy-browser type <ref> <text> Type text into an element
cowboy-browser scroll <direction> Scroll (up/down/left/right)
cowboy-browser press <key> Press a key (Enter, Escape, Tab, ...)
cowboy-browser back Navigate back
cowboy-browser eval <js> | eval - Run JS in the page ('-' reads from stdin)
cowboy-browser screenshot [file] Save a screenshot (default /tmp/cowboy-browser-screenshot.png)
cowboy-browser downloads List captured download metadata for the current tab
cowboy-browser download <id> <path> Stream one captured file to a local path
cowboy-browser close Close the browser session
Elements are referenced as @e1, @e2, … from the snapshot output (the @
is optional).
Captured downloads
Browser-triggered downloads are retained by the server and shown by
cowboy-browser downloads. The metadata includes an opaque download ID,
suggested filename, media type, size, timestamp, and capture failure (if any).
It intentionally omits the source URL because download URLs commonly contain
short-lived credentials or signatures.
Save a file without putting it in JSON or memory:
cowboy-browser downloads
cowboy-browser download 550e8400-e29b-41d4-a716-446655440000 ./artifact.tar.zst
The save command streams with curl into a mode-0600 temporary file beside the
destination, then atomically renames it after a successful response. It has a
connection timeout but no whole-transfer timeout, so multi-GB downloads are not
cut off. Failed and interrupted transfers do not replace the destination.
Both listing and file transfer are authorized against the current userId,
sessionKey, and tabId. The file endpoint supports a single HTTP byte range
(Range: bytes=...) for resumable clients and sends Content-Disposition.
Download IDs remain opaque and never become filesystem paths. Reading a file
does not consume it; files remain available until the tab/session is closed or
normal server retention cleanup removes them. The legacy API’s explicit
consume=true list option still deletes retained downloads and should only be
used intentionally.
Example
cowboy-browser navigate https://example.com
# snapshot lists interactive elements with @eN refs
cowboy-browser type @e3 "search query"
cowboy-browser click @e7
cowboy-browser screenshot ./result.png
The agent invokes these through its bash tool. cowboy-browser unsets the
HTTP proxy variables for its own requests, since the camofox server is local to
the veth and does not need credential injection.
API Integration
Provider code formats requests and parses responses in core. The host carries them out asynchronously: the Zellij adapter uses its web-request API, while Montana implements the component’s HTTP import with a native client and sends the completion back as a host event. Provider logic does not depend on a terminal or Zellij panes. Proxy routing, credentials and network policy still depend on the deployment.
Source: crates/core/src/provider/.
Providers
Six providers implement the LlmProvider trait, selected by ProviderType:
ClaudeProvider(Anthropic Messages API)OpenAIProvider(Chat Completions / Responses API)CodexProvider(ChatGPT subscription Responses API with SSE)OpenRouterProviderVercelProvider(Vercel AI Gateway, Chat Completions)OllamaProvider(local, keyless)
The LlmProvider trait
The trait does not perform transport I/O. It only serializes requests and deserializes responses:
#![allow(unused)]
fn main() {
pub trait LlmProvider {
fn name(&self) -> &str;
fn format_request(
&self,
messages: &[Message],
tools: &[Tool],
system: &str,
) -> (String, BTreeMap<String, String>, Vec<u8>);
fn parse_response(&self, body: &[u8]) -> Result<LlmResponse, ProviderError>;
fn parse_error(&self, status: u16, body: &[u8]) -> ProviderError;
fn set_model(&mut self, model: &str);
fn api_key(&self) -> &str;
}
}
The request flow is:
format_request()produces(url, headers, body).- Core requests HTTP through its host interface.
- The host delivers the correlated HTTP result: a Zellij event or, through Montana, a WIT host event mapped back into core.
parse_response()(on HTTP 200) orparse_error()(otherwise) interprets it.
set_model() supports switching the model at runtime (the /model command).
Credentials
In the managed credential-proxy deployment
(services.cowboy.secretsProxy.enable), the agent sends placeholder keys and
the proxy injects the real credentials on the wire based on per-domain mappings.
Codex is the same pattern: its rotating ChatGPT subscription token is injected
outside the agent. Local and ordinary Docker launches hold credentials.
See Security Model. For keyless
providers (Ollama) api_key() is empty.
Provider defaults
Every main-model request carries an output cap of 32768 tokens, reasoning
included. The max_output_tokens launch key changes it; a managed agent sets
it with maxOutputTokens. A reasoning model that spends the whole cap
thinking returns neither text nor a tool call, and a one-shot turn then ends
as if the agent had finished. Summarization, compaction and the judge keep
their own smaller caps.
ClaudeProvider targets https://api.anthropic.com/v1/messages; there is no
base-URL override, so no Bedrock or Vertex route. Its defaults: model
claude-sonnet-5, max_tokens 32768, thinking on. The model id decides how
thinking is spelled, because the shapes are not interchangeable:
| Model id | Thinking on | Thinking off |
|---|---|---|
| Claude 3.x, 4.0–4.5 | {"type":"enabled","budget_tokens":4096} | field omitted |
| Opus 4.6–5, Sonnet 4.6–5 | {"type":"adaptive", …} | {"type":"disabled"} |
| Opus 5.5 and later, Fable, Mythos, unrecognized ids | {"type":"adaptive", …} | field omitted |
A budget is rejected by current models, and disabled is rejected by models
that always think; an unrecognized id is treated as one of those. Adaptive
thinking is sent with block_binding.prefix_mismatch_behavior: "drop_block"
under the thinking-binding-controls-2026-08-01 beta: Cowboy edits earlier
turns (microcompacted tool results), and where the API binds a thinking block
to the conversation before it, the stale block is dropped instead of the
request failing. By default the context packet (a plan no longer shown by an
update_plan_state result, abandoned tool processes) is not such an edit: it
joins the conversation where its content changes and stays there, so a plan
update leaves earlier turns byte-identical.
The experiment-only plan_packet=rewrite launch setting instead removes the
superseded packet, which is such an edit. temperature is sent only to models
that accept sampling parameters (before 4.7, not Fable or Mythos); the utility
path (summaries, the idle judge) is the only caller that sets it.
Every Messages request asks for prompt caching: the system prompt goes as one
text block carrying a cache_control breakpoint (tools render ahead of it, so
it caches both), and a top-level cache_control puts an automatic breakpoint
on the conversation’s last block. The cache fields of the response’s usage
are logged on the LLM usage: line.
OpenAIProvider defaults to gpt-4o and auto-selects the Responses API for
reasoning models (o-series, gpt-5, codex) to capture reasoning summaries, which
are mapped onto thinking content blocks. On that path, and on Codex, the
session id is sent as prompt_cache_key, so one session’s requests share a
prompt cache.
With openai_base_url (or the managed openaiBaseUrl option), the same
provider targets an arbitrary OpenAI-compatible endpoint. Cowboy strips
trailing slashes, appends /chat/completions, and sends the configured model
name unchanged. Custom endpoints always use Chat Completions—even for names
such as gpt-5-*—and use the broadly supported max_tokens request field.
They may be keyless; when an OpenAI key is configured Cowboy adds bearer
authorization, otherwise it omits the Authorization header. The endpoint is
also retained for summarization, compaction, judge, delegated vision, and
sub-agent requests.
Message model
Messages carry a string role and a vector of ContentBlocks, matching the
Claude API’s native content-block model. A block’s block_type is one of
text, tool_use, tool_result, image, thinking, redacted_thinking, or
reasoning.
Reasoning replay
Some reasoning has to go back to the provider that produced it, unchanged:
- Anthropic
thinkingblocks (text andsignature; the text may be empty) andredacted_thinkingblocks (data). The signature covers the block, and on some models the conversation before it. - Codex
reasoningitems. Codex runs stateless (store: false), so each request asks forinclude: ["reasoning.encrypted_content"], and the item (less itsid) is sent back as aninputitem ahead of the function call that followed it.
A provider stamps its reasoning with a replay key when it parses the response
(claude; codex/<model>, since encrypted reasoning is readable only by the
model that wrote it). The assistant turn in the transcript keeps those blocks
in reasoning, each anchored ahead of the turn’s text, ahead of a tool call,
or after the rest, and the view puts them back in place. A provider sends only
blocks carrying its own key and complete enough to replay (a thinking block
needs its signature); other providers never see them. The display text stays
in thinking and is never sent.
The session log writes reasoning only when its secret redaction would leave
every block byte-identical, since a rewritten block fails its signature on
every later request. Codex encrypted_content is opaque ciphertext, so
redaction leaves it alone: random base64url often contains a run that reads
like a key. A turn that quotes a credential in its thinking therefore
replays that thinking live but not after a resume. Session files written before
this field existed load and replay no reasoning. Compaction replaces the
transcript, so no block bound to the old history is replayed after it.
Errors and retries
ProviderError includes ParseError, ApiError, NetworkError,
RateLimited, Timeout, InvalidRequest, AuthenticationError, and
Overloaded. is_retryable() marks rate limits (429), network errors, server
errors (5xx), and timeouts as retryable; auth and other 4xx errors are not.
Automatic retry is wired in: a RetryState with exponential backoff drives a
bounded retry of failed LLM calls from the ranch handlers
(crates/core/src/handlers.rs, schedule_llm_retry) — a retryable error
schedules a backed-off retry until max_attempts is exhausted, after which the
failure surfaces as an error message.
Bridges
Bridge services (Discord, email) do not use the provider layer. They reach the agent through the pub/sub message system: inbound messages are polled and processed as user input, and replies flow back out the same way. See Approvals & Outbox.
Slack and Other Chat Platforms
title: Slack and Other Chat Platforms tags: [pubsub, hermes, slack, access]
Slack and Other Chat Platforms
Cowboy reaches Slack, Telegram, Mattermost and the other platforms Hermes Agent
supports through Hermes’ own platform adapters. One bridge package hosts any
of them (pkgs/hermes/): the adapter connects to the platform, and the driver
moves messages between it and the agent’s Redis streams. Adding a platform is
configuration, not code.
The platforms available are the ones in pkgs/hermes/platforms.json, which is
generated from the packaged Hermes build.
Who may talk to the bot
A chat bot in a shared workspace is reachable by everyone in it, so access is
Hermes’ model, enforced by Hermes’ own code (pkgs/hermes/access.py) on every
inbound message:
- Deny by default. Nobody is admitted until you say who.
allowedUsersadmits the listed platform user ids. An empty list admits nobody, exactly as an unset one does.pairing = truelets anyone who DMs the bot request access. They receive a one-time code; you approve it on the host and they are admitted from then on. Codes expire after an hour and requests are rate-limited.allowAllUsers = trueadmits everyone who can reach the bot. It cannot be combined with the other two, since it makes them meaningless.
Every enabled platform must choose at least one of these; a configuration that admits nobody fails to build. Messages from people who are not admitted never reach the agent. In a DM they may be offered a pairing code; in a channel they are dropped silently.
Platform-specific filters are Hermes’ own and go in settings, for example
Slack’s require_mention (on by default: the bot answers in channels only when
mentioned, or inside a thread it is already in), allowed_channels and
free_response_channels.
A group bot should be its own agent. Each agent has its own session and memory, so what the group says never mixes with a private conversation held elsewhere.
Slack
1. Create the Slack app
At https://api.slack.com/apps, choose Create New App, then From an app
manifest, pick your workspace, and paste pkgs/hermes/slack-manifest.json.
It enables Socket Mode (no public URL is needed), the Messages tab for DMs, and
the minimum scopes: reading the conversations the bot is in, posting, looking
up display names, and adding the 👀 reaction that shows a message was seen.
Then:
- Settings → Basic Information → App-Level Tokens: generate a token with
the
connections:writescope. It starts withxapp-. - Settings → Install App: install the app to the workspace and copy the
Bot User OAuth Token. It starts with
xoxb-. - Invite the bot to each channel it should read (
/invite @cowboy).
2. Store the tokens
Put both tokens in an agenix secret, one KEY=value per line:
SLACK_BOT_TOKEN=xoxb-...
SLACK_APP_TOKEN=xapp-...
3. Configure the bridge
services.cowboy.agents.team = {
enable = true;
# ...
};
services.cowboy.pubsub.hermes.platforms.slack = {
enable = true;
env = config.age.secrets.slack-env.path;
defaultAgent = "team";
# Pick who may talk to it:
pairing = true; # people you approve by code
# allowedUsers = [ "U01ABCDEF" ]; # and/or these member ids
# allowAllUsers = true; # or everyone in the workspace
settings = {
require_mention = true;
# allowed_channels = [ "C0123" ]; # only these channels
};
};
A member id is under a person’s Slack profile: ⋮ → Copy member ID.
4. Admit people
With pairing on, someone DMs the bot and receives a code. Approve it on the
host:
sudo cowboy-pairing hermes-slack approve <code>
sudo cowboy-pairing hermes-slack list # pending and approved
sudo cowboy-pairing hermes-slack revoke <member-id>
What people see
The bot answers in a thread under the message that mentioned it, and replies to a message inside a thread land in that thread. A 👀 reaction appears when the agent has read a message, and turns into ✅ when it replies.
Limits
- Text only. Attachments and voice messages are not passed to the agent yet.
- Hermes’ slash commands (
/model,/newand so on) are not registered; the app manifest above has none. - The seen marker is added but not removed on failure; the ✅ appears when a reply is sent.
Plugin Architecture
title: Plugin Architecture tags: [architecture, plugins, extensibility] created: 2026-04-24 updated: 2026-09-06
Plugin Architecture
Cowboy’s NixOS module system is the extension surface. An external module
(a “plugin”) adds capability to agents by registering into cowboy’s
option tree rather than forking the core. The in-tree
Home Assistant skill is the
worked example of per-agent content; the examples below use a hypothetical
myplugin that runs a service on the host and teaches an agent to drive it.
Everything below is grounded in the implementation under modules/.
The three layers
A plugin separates into layers so that only the top one couples to cowboy:
| Layer | What it is | Couples to cowboy? |
|---|---|---|
| Infrastructure | systemd services / scripts providing the raw capability (game server, DB, hardware) | No — runs standalone |
| Packages | derivations giving the programmatic interface (Python env, CLI) — built via callPackage | No — self-contained |
| Harness integration | conditional blocks registering skills/tools/bridges and pushing packages into agent homes | Yes — guarded by hasCowboy |
In myplugin this maps to: services.nix (infrastructure), default.nix
(packages, built once and imported by both of the others), and the config
block in module.nix guarded by hasCowboy (integration). Disable cowboy
and the service still runs.
The plugin contract
1. Own your namespace
Declare options under your own top-level namespace, never inside
services.cowboy.*:
# Good
options.services.myplugin = { enable = ...; dataDir = ...; };
# Bad — destabilizes cowboy's option tree and breaks standalone use
options.services.cowboy.myplugin = { ... };
2. Read cowboy state via cowboyLib
Cowboy injects a cowboyLib module argument
(modules/lib/default.nix). This is the supported module interface today, not a
versioned binary ABI or a promise of compatibility across future revisions.
Pin the Cowboy input and evaluate extensions when updating it. Members:
cowboyLib.enabledAgents # attrset of enabled agents (name -> agentConfig)
cowboyLib.agentNames # [ "agent" ... ] — for building `agents = [ ... ]` selectors
cowboyLib.forAgents (acfg: {…}) # map an HM config fn over every enabled agent, keyed by user
cowboyLib.forAgentsWhere pred f # …only agents matching `pred name acfg` (generic haAgents)
cowboyLib.singleAgent "context" # the one enabled agent, or a lazy throw under multi
cowboyLib.broker # human operator user (may be null)
cowboyLib.serviceUser # cowboy's service-account prefix / shared bridge group
cowboyLib.userFor / homeFor name # agent user / home dir by name
cowboyLib.caBundleFor name # the trust store the agent's TLS clients must use ($SSL_CERT_FILE)
cowboyLib.inNamespace # is agent traffic proxied?
Accept it with a fallback so the plugin still evaluates when cowboy is absent:
{ config, lib, pkgs,
cowboyLib ? { enabledAgents = {}; forAgents = _: {}; },
... }:
let hasCowboy = cowboyLib.enabledAgents != {}; in
Per-agent targeting:
forAgentsand theskills/toolsregistries fan out to all enabled agents by default. To scope a skill/tool to specific agents, set itsagents = [ "name" … ](empty = all). For per-agent content (prompts that differ by agent), useforAgentsWheredirectly — see the Home Assistant pattern.
3. Guard harness integration
Keep infrastructure unconditional; gate cowboy registration on hasCowboy:
config = lib.mkIf cfg.enable {
# Infrastructure — always
systemd.services."myplugin-setup" = { ... };
# Integration — only with cowboy
services.cowboy.skills = lib.mkIf hasCowboy { ... };
home-manager.users = lib.mkIf hasCowboy (
cowboyLib.forAgents (acfg: { home.packages = [ pluginCli ]; })
);
};
4. Don’t block cowboy.target
Plugin services join the agent lifecycle with a soft pull-in:
- Use
wantedBy = [ "cowboy.target" ]for startup with the target. Add stop and restart coupling only when the plugin needs that lifecycle. - Bound restart loops with
StartLimitBurstandStartLimitIntervalSecwhen usingRestart = "on-failure". - Use
requires/after/partOfamong the plugin’s own services for internal ordering.
5. Keep packages self-contained
callPackage your own dependencies, and build each one once — a
default.nix that both module.nix and services.nix import, rather than
two copies of the same derivation kept in sync by hand. Don’t assume cowboy
provides any particular package on PATH (the base set is just bash coreutils ripgrep fd jq gh nix git curl, plus camoufox’s browser — see
modules/tools.nix).
Extension points
Skills — knowledge + prompt + packages
A skill is a markdown prompt the agent can load, optionally with packages
and extra tools. Registered into the global services.cowboy.skills
attrset (modules/skills/default.nix):
services.cowboy.skills.myplugin-guide = {
description = "Drive myplugin from the CLI";
prompt = ./skills/myplugin-guide.md; # or promptText = "...inline...";
requires = [ pluginCli ]; # installed for every targeted agent
additionalTools = [ "bash" "read" "write" ];
tags = [ "myplugin" "control" ];
autoLoad = false; # true = loaded at agent startup
agents = [ ]; # [] = all enabled agents; or [ "pilot" ]
};
For each agent the skill targets, the module writes
~/.config/cowboy/skills/<name>.md (the harness discovers skills by
reading this directory) plus a per-agent skills.json, and installs the
skill’s requires packages onto that agent’s PATH — regardless of
autoLoad, so an on-demand skill’s binaries are present when the agent
loads it. The agents selector filters which agents receive the skill.
Tools — schema’d executable capabilities
A tool is a command template the harness can call with structured args
(modules/tools.nix). The default set (bash, web-search,
spawn_subagent, view_image) merges with anything a plugin adds:
services.cowboy.tools.myplugin-eval = {
package = pluginCli;
command = "myplugin run {{script}}"; # placeholders are {{double-brace}}, NOT {single}
description = "Run a myplugin control script";
sandbox = "standard"; # "none" | "standard" | "strict"
timeout = 60;
agents = [ ]; # [] = all enabled agents (defaults always reach every agent)
schema = {
type = "object";
properties.script = { type = "string"; description = "Path to script"; };
required = [ "script" ];
};
};
Each placeholder expands to its argument as one shell-quoted word: a string,
number or boolean. A call that leaves an argument out, or sends it as null,
is not run; its tool result names the missing argument. The exception is an
argument the schema declares optional (listed in properties, absent from
required), which expands to ''. An array or object argument is always
refused.
Tools are baked per-agent into the harness WASM and written to a per-agent
~/.config/cowboy/tools.json; the agents selector scopes a tool to
specific agents (the default tools — bash, web-search,
spawn_subagent, view_image — leave it empty, so they reach everyone). A plugin can
also expose a capability through a skill alone (prompt + its binary on
PATH), which is the lighter path when the agent only needs a CLI.
Plugin registry — be discoverable
Register the plugin in the informational registry so the agent (via its
system prompt) and the operator (cowboy plugins / /etc/cowboy/plugins.json)
can enumerate what’s installed:
services.cowboy.plugins.myplugin = {
description = "Host service control";
version = "1";
extensionPoints = [ "skills" "units" ];
units = [ "myplugin-setup.service" "myplugin-daemon.service" ]; # the real units it owns
agents = [ ]; # [] = surfaced to all agents
};
This is purely descriptive — it wires up no capability, it just makes the
plugin enumerable. The per-agent tools.json system_prompt_suffix
carries the list to the agent with no harness changes.
Bridges — bidirectional message channels
A bridge connects an external platform to the agent’s pubsub
(modules/bridges.nix, options in modules/options/bridges.nix). Each
declaration auto-generates a pubsub source plus a systemd unit per entry point
its package ships (cowboy-<name>-outbox, and cowboy-<name>-{ingest,ping}
where it has them) under cowboy-bridges.target:
services.cowboy.bridges.discord = {
pkg = myBridgePkg; # provides bin/discord-{ping,ingest,outbox}
env = "/run/agenix/discord-env"; # EnvironmentFile
icon = "💬";
approval = {
required = true;
notify = "discord"; # which outbox sends the approval prompt
notify_channel = "1489..."; # channel id within that outbox
timeout = 3600; # seconds; -1 never expires, 0 expires at once
};
};
Bridges default to dedicated service accounts. Keep their identities separate
from agents and the operator when overriding user. Configure outbound
approval on the bridge and inbound routing with routes / defaultAgent.
The Security Model explains the separate Redis authorities.
The systemd target
A unit can be started with the agent target:
systemd.services.my-capability.wantedBy = [ "cowboy.target" ];
Per-agent skills: the Home Assistant pattern
The global skills registry distributes to all agents by default and supports
an agents selector. For content that differs per agent, the in-tree HA skill
(modules/skills/home-assistant.nix) shows the escape hatch: it
bypasses the registry and writes the prompt directly into the homes of
agents that opted in via a per-agent option (agentOpts.skills.homeAssistant):
let haAgents = lib.filterAttrs (_: a: a.skills.homeAssistant.enable) enabledAgents; in
home-manager.users = lib.mapAttrs' (_: acfg:
lib.nameValuePair acfg.user {
home.file.".config/cowboy/skills/home-assistant.md".source = mkHaSkillPrompt acfg;
home.packages = [ pkgs.curl pkgs.jq ];
}
) haAgents;
The agents selector handles per-agent selection directly in the
registry, so a plain skill that only needs targeting does not need this
bypass. HA uses it because its prompt is per-agent content — the
endpoint, token, and managed units differ per agent — which a
selection-only list can’t express. Use cowboyLib.forAgentsWhere for that
case; HA is the worked example.
Worked example: myplugin end to end
myplugin/
├── module.nix # options + integration layer (skills, agent packages, registry entry)
├── services.nix # infrastructure: myplugin-setup / myplugin-daemon units
├── default.nix # packages: the CLI and its client library (callPackage), built once
└── skills/*.md # skill prompts
Consumer wiring (machines/<host>.nix):
imports = [
inputs.cowboy.nixosModules.default
../modules/myplugin/module.nix
];
services.myplugin = {
enable = true;
dataDir = "/home/<user>/myplugin";
user = "<user>";
};
What lights up because cowboy is present:
- The plugin’s skills, written into the agent’s
~/.config/cowboy/skills/. pluginClion the agent’s PATH.- The agent’s polkit-managed unit list (
managedServices.units) so it can cycle the stack itself.
Managed units must exist. Every name in
managedServices.unitsmust be a unit the configuration declares; a polkit rule over a unit that does not exist advertises a control that silently does nothing.modules/services.nixchecks this at eval time and warns rather than asserts (services.cowboy.managedServices.validateUnits, defaulttrue), because a host’s units may be legitimately conditional — a feature flag, an optional submodule — and a hard assertion would force every consumer to mirror that logic into its unit list. The registry’splugins.<name>.unitslist is informational and is not validated.
Checklist for a new plugin
- Options under your own namespace, with an
enableflag. -
cowboyLibaccepted with a{ enabledAgents = {}; forAgents = _: {}; }fallback. - All cowboy registration guarded by
hasCowboy. - Packages via
callPackage, built once indefault.nix; not assumed present. - Plugin services declare startup dependencies and bounded restart behavior.
- A skill’s binaries go in its
requires(installed for every targeted agent, on-demand or not). - Scope to specific agents with
agents = [ … ]; for per-agent content, useforAgentsWhere. - Register in
services.cowboy.plugins.<name>so the plugin is discoverable. - Every unit in
managedServices.unitsactually exists (the validator warns otherwise);plugins.<name>.unitsis informational.
Different contracts
The Nix module interface configures deployments. The component interface is
separately versioned as cowboy:agent@0.2.0; its WIT source defines commands,
effects and carriers. The JSON inside a snapshot remains an opaque display
model, not a versioned presentation schema. Native control and descriptor
records have their own CDDL definitions.
The A2A adapter exposes a limited profile over the root agent. It does not provide general A2A task persistence, peer addressing or every protocol method. See the Component ABI and A2A profile.
Design Overview
Cowboy runs persistent AI agents on infrastructure you control, using Nix to configure their tools, credentials, message access, and approved actions.
The strongest documented deployment is managed NixOS on Linux/x86-64. Local and ordinary Docker launches have different credential and process boundaries. The OCI runtime is a specialized optional route for Cowboy’s own payload. See Deployment Paths for that choice before selecting a host or changing its controls.
Core and the two hosts
The core owns the agent loop, provider request formatting, tools, session state, memory and message polling. Two hosts run it:
| Host | Core integration | Interaction |
|---|---|---|
| Zellij plugin | Links core into a wasm32-wasip1 plugin | Terminal input and ANSI display |
| Montana | Loads a wasm32-wasip2 component through cowboy:agent@0.2.0 | Commands in and JSON frames out over the native control socket |
Zellij implements asynchronous commands, HTTP requests, timers and peer spawning through its plugin API. Montana implements those operations natively and delivers completions to the component. Both use the same semantic intents and provider logic; terminal navigation and pane controls belong to Zellij. Montana runs peers as component instances on separate threads in the same process, sharing its filesystem view and HTTP client.
Two paths to the outside world
Custom asynchronous effects cross the core’s host interface: execution, HTTP, timers and peer lifecycle requests. The component adapter maps these to WIT imports. An effect request does not grant permission to perform it.
Direct filesystem access is a separate path. Montana gives the component WASI preopens for its resolved workspace, home, config, data and temporary directories. Config loading, plan persistence and other direct file operations use those preopens without an execution effect. WASI clocks and randomness are also available; WASI sockets are not enabled.
Montana maps each preopened host directory to the same guest path. This matters because execution effects run native processes: a path computed in the guest must name the same file when passed to a shell command.
To reason about access, inspect both the host’s effect handling and its WASI grants, then the enclosing process identity, mounts and network policy. Sheepdog’s tool-command policy alone does not describe direct guest file access. See Security Model.
Launch branches
cowboy-core
├── Zellij plugin: interactive terminal
└── WASI component → Montana
├── managed NixOS: systemd agent service
├── local headless launch
├── ordinary Docker: image supervisor
└── optional Cowboy OCI runtime: embedded Montana
The managed daemon runs Montana directly with a per-agent component, under the shared systemd hardening envelope, agent user, configured network namespace, credential proxy and Sheepdog policy. It does not launch the agent through the OCI runtime. Optional socket forwarders use a helper from that runtime package; that does not turn the daemon into an OCI container.
Local and ordinary Docker launches hold provider credentials. The managed proxy deployment keeps them outside the agent. The OCI route has its own mount, seccomp and egress controls; it is not a general container runtime. Tool behavior can differ under these policies. The terms bare, user and container classify a design progression; they are not three switches offered by the runtime binary.
Messages and configuration
Bridge services connect external platforms to Redis streams. Core polls its configured sources and sends replies through their outboxes. Bridge approval can hold an outbound message for a human decision. Recovery does not guarantee completion or preserve reply routing across a restart; see Inbound Message Reliability.
Both hosts pass a flat string configuration map to core. The CLI, persistent JSON, generated NixOS configuration and secret discovery are different inputs; see Configuration. Skills, tools and bridges extend the agent through the module interface.
Implementation map
| Area | Location |
|---|---|
| Agent state and tools | crates/core/ |
| Terminal host | crates/harness/ |
| WIT adapter | crates/component/ |
| Headless host and WASI grants | crates/montana/ |
| Specialized OCI runtime | crates/runtime/ |
| Native protocol types | crates/contracts/ |
| CLI and launch selection | cowboy/ |
| Managed services and policy | modules/ |
| Credential injection | proxy/ |
| Message bridge framework | pkgs/bridge/ |
The Component ABI describes WIT and the native control protocol. The embedding guide explains how to add a host.
Security Model
The strongest documented deployment is managed NixOS on Linux/x86-64. Its agent daemon runs Montana directly under systemd with a per-agent component, an agent user, the shared hardening envelope, a network namespace, the credential proxy and Sheepdog. It does not use the OCI runtime to launch the agent. Local, ordinary Docker and optional OCI launches have different boundaries; see Deployment Paths.
This page explains the controls. The threat model states their conditions and limitations. In particular, Cowboy does not guarantee confidentiality of anything the agent can read. A prompt-injected worker with permitted outbound access can disclose readable data. The agent can also damage its own writable workspace, memory and state.
What is enforced by default
The Nix modules enable the credential proxy by default, and enable Redis ACLs and Sheepdog by default on Linux. These are deployment settings, not properties of an arbitrary core or component build. Managed daemons require the proxy; turning it off is not a supported way to run that daemon with real keys.
Process and filesystem isolation
Each managed daemon runs as its configured agent user. The systemd envelope makes the system read-only, hides other homes, binds the agent’s home back in, and applies private temporary storage, device restrictions, an empty capability bounding set and no-new-privileges. Configured mounts add access to that view. The home, runtime and explicitly writable paths remain mutable.
Inside Montana, direct guest file access uses WASI preopens. These map the workspace, home, config, data and temporary directories at their host paths, so guest reads and native execution agree about filenames. Preopens grant file access separately from custom execution effects; a review of tool policy alone is not a review of all filesystem access.
Montana sub-agents share the host process and its preopens. A filtered child tool list is not a separate OS identity or filesystem boundary.
Network isolation
The managed Linux module creates one shared namespace, cowboy-ns, with a
veth pair to the host. The daemons and agent user services join it. It is not
one namespace per agent.
Outbound TCP outside the configured subnet is redirected to the proxy. The egress filter allows loopback, the subnet, established replies and DNS to the host resolver, then drops other traffic. Operator-configured SSH destinations and passthrough ports grant direct egress exceptions.
The host Nix daemon is another network authority: its builders run outside the agent namespace. The default denial of direct Nix daemon access is a Sheepdog connect rule. Disabling Sheepdog removes that enforcement. Rebuild requests can instead go through the broker’s configured approval workflow.
Darwin uses a UID-scoped packet-filter redirect and has neither the Linux namespace boundary nor Sheepdog or the Linux Redis ACL implementation.
Credential-injecting proxy
Managed daemons require the proxy and use placeholder provider keys. The proxy
reads the real secret from its configured file and injects it on a matching
TLS destination route. Exact host routes take priority over wildcard routes;
more specific wildcard suffixes take priority over broader ones. A route with
a pathPrefix injects only on that path or beneath it, matched on a /
boundary; a path with a . or .. segment never matches. A mismatched
Host header is rejected before credentials are attached. Upstream certificate
verification is enabled by default; the explicit insecure option disables it.
These claims apply to the proxy deployment. Local and ordinary Docker agents hold credentials. Proxy configuration does not remove credentials supplied through some other input.
With egress control enabled, GET, HEAD and OPTIONS pass the method gate. Every other method needs an allowed destination or receives HTTP 403. TRACE receives HTTP 403 on every destination, allowed or not and whatever the egress setting, because a server that echoes it back would return the credential the proxy injected. These are method-and-destination restrictions, not a guarantee that external state cannot change. There is no content inspection that prevents readable data from leaving through an allowed request, and WebSocket messages after an upgrade are not method-gated.
The proxy carries HTTP and nothing else: plain, or inside TLS it intercepts.
A CONNECT tunnel that carries another protocol, such as SSH, relays nothing,
and a 101 switch to any protocol but WebSocket is killed. To reach an SSH
host, list it in sshDestinations, which bypasses the proxy.
The proxy runs in the host’s network namespace, so a request relayed through it reaches whatever the host can reach. Two options limit where it connects:
deniedNetworkslists networks the proxy refuses. The default,169.254.0.0/16,fe80::/10andfd00:ec2::254/128, covers link-local addresses, where most clouds’ metadata services, which hand out the host’s credentials, live. It does not cover a provider whose metadata service sits elsewhere, such as Alibaba Cloud’s100.100.100.200; add that address on such a host. Setting the option replaces this default, so keep these entries unless you mean to open them.allowedNetworks, empty by default, makes the proxy connect only to the networks it lists when it is non-empty.
A destination is refused if it is in any deniedNetworks entry, or if
allowedNetworks is non-empty and it is in none of its entries. Deny wins
when an address is in both lists.
The proxy judges the address it actually connects to, for plain HTTP and for CONNECT tunnels:
- A name is judged by every address it resolves to, in the same lookup the connection is made with.
- The connected peer is judged again, so a name that re-resolves to another address (DNS rebinding) cannot swap in a refused one.
::ffff:169.254.169.254counts as169.254.169.254, and0.0.0.0and::count as the loopback addresses they reach.
A refused request gets an error naming the rule, and the proxy logs a
BLOCKED line.
Loopback and private networks stay reachable by default, so an agent can use
services on the host and other agents. Such a service answers the agent as it
would answer the host. If a service should not be reachable, list its network
in deniedNetworks. The policy covers only traffic the proxy relays:
passthroughPorts and sshDestinations bypass the proxy, so it does not apply
to them.
Sheepdog policy
On Linux/x86-64, the managed build bakes a per-agent Sheepdog policy into the component’s tool execution path. Sheepdog uses seccomp notification to mediate selected file, execution and connection syscalls. Its policy includes read, edit, create, delete, execution and connection rules. Runtime permission grants can take precedence over baked rules when enabled.
This is conditional on the sandbox being enabled and present in the build. Portable lite builds do not enforce this policy. The optional OCI route uses its own bundle restrictions; it does not inherit all managed-service controls. The policy authority and limitations are specified in Sheepdog policy.
A command can exit successfully even when part of it was denied. Core preserves recognized Sheepdog denial messages in the tool result so the agent can see that a refused read or connection was not an empty successful result.
Per-agent message isolation
With the Linux Redis ACL configuration enabled, each agent has its own inbox and outbox streams and an identity restricted to its name prefix. It cannot read another agent’s streams or edit approval records.
The agent reaches Redis through its own Unix socket at
/run/cowboy/<agent>.sock, owned by its user with mode 0600. The host auth proxy
selects the Redis identity from the accepting socket and injects the password.
The agent holds no Redis password. Per-agent source configuration names these
streams and the socket.
Bridges route inbound messages to an agent’s inbox and consume each agent’s outbox. The outbox stream prefix determines the requester; a message’s claimed user does not. Bridge bookkeeping lives outside agent-writable prefixes. Each bridge has its own service user and Redis identity, scoped to its streams and required approval roles. A bridge that creates or resolves approvals still has authority over shared approval records; those roles must be trusted.
This separates agent mail while provider credentials remain shared through the host’s proxy. It is not a tenant boundary between mutually untrusted operators.
Approvals and operational authority
Bridge approvals hold configured outbound messages for a human decision and reject them on timeout, unless the timeout is -1, which holds them until they are decided or superseded. Declared Git effects bind approval to a host-inspected commit and base; apply rechecks policy before pushing. The rebuild bridge has privileged activation authority through its configured wrappers. Treat bridge identities and approval resolvers as part of the trusted host.
See Approvals & Outbox and Gated Effects. After a restart, inspect outcomes before retrying: message recovery can repeat work without restoring the reply’s source binding.
Agent users do not receive journal access by default. Enabling
services.cowboy.agents.<name>.allowJournal grants access to host logs as well
as the corresponding log-path policy. Logs can contain data from other trust
domains. The proxy omits query strings from its own request logs; that does not
sanitize output from other services.
System Patterns
Keep credentials behind a service
In the credential-proxy deployment, provider secrets live outside the agent. The agent sends placeholders; the proxy selects the destination route and injects the credential. Local and ordinary Docker launches deliberately hold credentials, so this is a property of the proxy deployment, not of core.
The proxy restricts HTTP by method and destination. With egress control enabled, GET, HEAD and OPTIONS pass the method gate; every other method requires an allowed destination. TRACE is refused everywhere, because a server that echoes it would return the injected credential. This does not prove that an allowed request leaves external state unchanged.
Cowboy does not guarantee confidentiality of data the agent can read. A prompt-injected worker with permitted outbound access can disclose that data. Keeping provider keys outside the worker does not make its workspace private. See Security Model.
Separate proposal from authority
An agent can prepare a commit or request a rebuild. The bridge and configured host service perform the approved action with their own identity. For declared Git effects, the approval binds the commit and base that the host inspected; the apply step checks them again. See Gated Effects.
Extend configuration before core
Tools, skills, packages and bridges can be registered through Nix modules. Per-agent selectors determine who receives them; the current module interface provides accessors for enabled agents and their homes. Adding such an extension does not require changing the agent state machine. See Plugin Architecture.
Separate shared behavior from host affordances
The two hosts share agent state and semantic commands. Zellij owns terminal navigation; Montana owns the native control socket and component instances. A host must supply both effect handling and the filesystem access its guest uses. Host independence does not imply identical security boundaries.
Component ABI
The agent core (cowboy-core) shares its state machine across hosts. Its
custom asynchronous interface is effects out (a Host trait) and
inputs in — split into
semantic Intents (the shared vocabulary) and raw HarnessEvents (the Zellij
transport plus effect completions). This chapter is its ABI: the WIT world
cowboy:agent@0.2.0 at
specs/wit/cowboy-agent.wit
— the single WIT source every bindgen consumer reads — which lets a runtime
embed core without linking Rust in-process.
The world is small enough to state in a sentence. It exports one interface,
agent, with five functions — initialize, handle-command,
handle-host-event, snapshot, describe — and imports one, host, for
the effects a component requests: exec, http, set-timer, close-self,
spawn-peer, and own-agent-id.
Two host paths
Core has two adapters, and only one goes through WIT:
| Host | Crate | Path to core | Input | Output |
|---|---|---|---|---|
| Zellij plugin | cowboy-harness (wasm32-wasip1) | links cowboy-core natively, calls the Rust trait | keys/mouse/paste → navigation stays local, semantic keys → Intent | ANSI to stdout (Zellij captures) |
Headless embedder montana | cowboy-component (wasm32-wasip2) | WIT cowboy-agent world | command + host-event | JSON display model via snapshot |
The Zellij adapter deliberately bypasses the component ABI. It needs keystroke-level fidelity to drive the terminal UI (prompt-line editing, navigation, expand/collapse), and it can link Rust, so paying the component-boundary tax buys it nothing. The WIT world exists for hosts that cannot link Rust — and those hosts don’t remote a TUI, they render the JSON display model and build their own input affordances.
The TUI lives in the adapter.
cowboy-coreis a headless agent model: it owns theDisplayItemdata andAgentHarness::frame_json, while the renderers, syntax highlighting (syntect), modal input, and view state (ViewState) live incrates/harness/src/tui— wrapped around the core asTui { agent, view }, which derefs toAgentHarness. The generic ANSI atoms (colors, symbols, text, spinner, key types) live incowboy-ui. Core depends on neithercowboy-uinorsyntect, so the WASI component sheds both. Every view↔core coupling crosses theHostseam as a defaulted hook (below), never a field poke.
The named-intent seam
Raw keystrokes never cross the ABI. Core’s input surface splits in two:
- Navigation / view — scroll, expand/collapse, search, prompt-line editing. Client-local: the Zellij adapter owns it (it holds the TUI projection); a JSON client navigates its own copy of the frame. Never crosses WIT.
- Semantic intents — the handful of actions that change agent/session state:
submit/interrupt/approval/debug/quit. The type isIntent, owned bycowboy-contractsand re-exported bycowboy_core::intentso the native adapters and the component adapter cannot drift.
Both adapters converge on one vocabulary via AgentHarness::handle_intent —
no bifurcation. The Zellij adapter’s semantic key arms (in
crates/harness/src/tui/input: prompt.rs Enter → Submit, navigate.rs
Esc → Interrupt and d → Debug, mod.rs sentry y/o/A/n →
Approval) call the same method the WIT component maps command’s cases onto.
Intent derives serde, so it is also the montana driver’s inbound wire shape
({"submit":"hi"}, "interrupt", {"approval":"once"}, "debug", "quit",
specified by specs/control.cddl)
— one vocabulary end to end, not a second protocol.
Commands vs. host events
The world’s inbound surface is two types, delivered through two exports, because they have different producers and different trust semantics — a transport command must never be confusable with an effect completion:
command— semantic operations an operator or protocol adapter applies to the instance:submit(string),interrupt,approval(approval),shutdown. Delivered byhandle-command.host-event— completions and notifications the host produces:timer,command-result,web-result,permission-result. Delivered byhandle-host-event.
Both return bool: true when observable state changed and a fresh snapshot
is worth pulling.
debug is deliberately not a WIT command — it opens a local log viewer, so
it is a host diagnostic rather than an agent operation, and it stays in the
native Intent vocabulary only. Intent::Quit is what command.shutdown maps
onto guest-side.
Neither type carries key, mouse, or paste. Core keeps the full
Key/KeyEvent/Pasted + HarnessEvent types for the Zellij transport.
One component instance has one foreground turn. The world exposes no task
handle, no detach/background operation, and no reattachment; submitting while
work is active queues the input, and interrupt asks the guest to abandon its
turn without promising cancellation of already-issued host effects. Peers
spawned via host.spawn-peer are separate instances, not background tasks of
the spawner.
Rust-only host verbs
Some seams stay in the Rust Host trait and never enter the world at all,
because they are meaningless off a terminal.
The pane verb is one: pane visibility is client-local view state a windowed
host acts on, so montana/remote never needs it. pane_op lives in the Rust
trait (the native Zellij adapter implements it); the WASI component no-ops it.
Defaulted view hooks
Four more Rust-only Host methods carry the view couplings — all defaulted,
so headless hosts inherit them for free (they carry no meaning off a terminal),
and only ZellijHost overrides them:
reveal_latest()— “a new item was appended; snap the view to it.” Core calls it wherever the view must follow appended output;ZellijHostrecords a bit itsTuidrains after the event (honoring the user’s mode).open_debug(path)—ZellijHostopens the debug log in a floating pane; headless no-ops. Keeps thezellij action new-pane … less +Fexec out of core.has_draft_input() -> bool— core’s idle judge/autoreprompt guard; the draft lives in the adapter’s view state, so the default isfalse.editor_active() -> bool— core’s heartbeat cadence; the$EDITORround-trip is a Zellij-only affordance, so the default isfalse.
ZellijHost and its Tui share an Rc<HostSignals> cell block: core→view for
reveal_latest, view→core for has_draft_input/editor_active. Like pane_op,
none of these are in the WIT world — they are Rust-trait seams a windowed host
implements and everyone else ignores.
The opaque-correlation rule
Every effect that expects a reply carries a correlation — an opaque
list<tuple<string, string>> created by the guest (core holds it as Ctx, an
ordered map, and converts at the boundary). The host echoes it back verbatim
on the matching host-event and never reads or writes it. The request “kind”
lives inside it as a string, meaningful only to core (see dispatch.rs).
A correlation identifies an effect callback, not a foreground or background agent task — it is not a handle a host can hold, poll, or reattach to.
The payoff: new command/web kinds are new correlation string values, not new ABI surface. The world never changes when core grows a new internal effect kind. A host that treats the correlation as bytes-in/bytes-out is forward-compatible by construction.
Effects are requests, not grants
An exec or http call across the host import is a request. Nothing about
crossing the boundary authorizes it: the host evaluates it under the active
backend and capability policy (sheepdog, the credential proxy, the OCI
sandbox — see Security) and may refuse. The same is true of
initialize’s config map: its entries are configuration, not capability
grants. own-agent-id is the one purely informational import — the instance’s
own id, which core’s heartbeat uses to address itself.
exec carries no stdin
exec takes an argv, a working directory and a correlation, and nothing
else. A command gets no standard input across the boundary, so whatever core
writes travels inside an argument, and Linux refuses any single execve
argument of MAX_ARG_STRLEN (128 KiB) or more with E2BIG before a shell
starts. Core holds every exec to that ceiling itself, above the Host trait,
so it applies on both host paths:
- Content-carrying writes go through one write layer
(
crates/core/src/write.rs). This covers the session and debug logs, artifacts, compaction transcripts, the prompt dump, sub-agent prompts and responses, and/connectintents. The content is a positional parameter, never script text. Up to 64 KiB is one exec. Anything longer is staged in 64 KiB pieces by a chain of execs, each dispatched when the previous result arrives, and then committed: renamed over its target, appended in one step, or fed to the command’s stdin. The caller gets onecommand-resultunder its own correlation. The links in between carry achunked_writecorrelation that core consumes itself. While a chain is in flight, later writes to its target wait for it, so none lands inside or ahead of it. Execs themselves may run concurrently (Montana runs each on its own thread), so this ordering is core’s, not the host’s. The session transcript goes further. It sends one append at a time, each after the previous one’s result arrives, and reports a failed append to the operator. Each line carries aseq(specs/transcript.cddl), so a resume can report lines that are out of order or missing. - Any other exec with an argument at or over the ceiling is replaced, before it reaches the host, by a command that prints the reason on stderr and exits 126. The result is then a failure its handler can report, not an exec the host can only describe as one that never started.
A host therefore only sees execs whose every argument fits. A chain advances
on results, so it relies on every exec producing its command-result, which
the correlation rule already assumes.
How Montana runs an exec
The world does not say how a host runs a command. This is Montana’s answer; the Zellij adapter does none of it.
- One process group per exec. The command’s first process leads a new process group, so everything it starts, such as a pipeline’s other stages or a subshell’s children, can be signalled together.
- A hard deadline. An exec that has not finished (its first process
exited and both output pipes closed) within
exec_deadline_secsseconds (default 1800, thirty minutes; the managed service andcowboy serve <name>passservices.cowboy.agents.<name>.daemon.execDeadlineSecswhen it is set) has its whole group sent SIGTERM, then SIGKILL two seconds later. Itscommand-resultthen carries a note on stderr. This is a backstop, not the tool timeout. Core keeps its per-tool timeouts to itself (an exec carries only its argv and the opaque correlation), so a core timeout only stops core waiting: the model is given the PID and told the process may still be running. An exec that finished is never signalled, so a job it deliberately started in the background keeps running. - Capped output. Montana keeps the first 128 MiB of each stream and counts
the rest. A truncated stream ends with a line of the form
[montana: stdout truncated: kept the first N of M bytes](orstderr). The marker is part of the bytes becausecommand-resulthas no field for it, and core drops stderr from a successful result. - Bounded guest stores. Each agent’s store lets a linear memory grow to
at most 2 GiB and holds at most 32 instances, 32 tables, 8 memories and
100,000 elements per table. A
memory.growpast the limit returns -1. - Stopping. Montana treats SIGTERM and SIGINT as quit for every agent
(see
CONTROL.md). A client’squitreaches only the agent it addresses, so the managed service stops Montana with SIGTERM and waits for it to exit. Once the root agent has closed, whether by a signal or by a client’squit, Montana waits up to 3 seconds for execs in flight, the final log writes among them, then stops the groups still running. If Montana itself is killed with SIGKILL, nothing stops its exec groups; the managed service’s control group does that when the unit stops.
Additive timer semantics
host.set-timer(secs) is additive and one-shot: each call arms an
independent timer, and there is no cancellation. This mirrors Zellij’s
set_timeout, which has no cancel API. Core’s heartbeat (heartbeat.rs)
compensates with an armed_count that culls the resulting fan-out down to a
single live chain.
A host must not “improve” this to one cancelable timer. Core’s re-arm logic
assumes additive delivery; a cancel-on-rearm host would stall or double-fire the
heartbeat. A headless embedder implements this as a plain deadline min-heap:
push on set-timer, pop-and-deliver when the earliest deadline passes.
The JSON frame contract
snapshot() returns one line of literal JSON:
{"status": "WaitingForInput", "items": [ /* DisplayItem… */ ]}
status is AgentStatus; items is the DisplayItem list core also renders
to ANSI. ANSI highlight caches (highlighted_lines, highlighted_input) are
#[serde(skip)]’d — they are render artifacts, not state.
Deliberately unstabilized. WIT specifies only the carrier — a string holding one JSON object. The shape inside tracks core’s display model and will change as that model settles; a typed, versioned presentation contract is deferred work, so no host may treat this serialization as a stable interface by accident.
montana’s ndjson stream wraps these frames per agent as{"seq", "agent", "frame"}— that envelope is specified, by thecontrol-framerule inspecs/control.cddl. The one exception is thestatusnames: the A2A adapter maps them as text, so tests on both sides pin them (seespecs/A2A.md).
The describe contract
describe() returns the protocol-neutral agent descriptor, also as one JSON
object in a string: name, description, version, provider, model, capabilities,
and the skill list (one entry per tool, carrying its JSON Schema input schema
verbatim). Unlike the snapshot, this record is specified — by
specs/descriptor.cddl,
with Descriptor in cowboy-contracts as the Rust shape.
It exists so a host can advertise the agent without knowing anything about
Cowboy’s internals: crates/a2a maps this one export onto an A2A agent card and
its skill list, and montana serves that mapping. Protocol adapters are bindings
onto describe + handle-command, not alternative agent APIs.
/connect — a harness as a client of another harness
/connect <host:port>#<secret-path> (or /connect <montana-uds-path>) turns a
Zellij harness into a thin client of a remote agent, built entirely on the two
contracts above: inbound, montana’s ndjson envelope rehydrates into
Vec<DisplayItem> (pinned by display_item_round_trips_through_json);
outbound, every user action is one Intent wire line (pinned by
intent_wire_shapes). The fragment names a bearer-token file — the token
is the first line of the connection, exactly the cowboy-runtime __forward
handshake; the token itself never enters plugin config or argv.
Mechanically it is drop-and-connect: the plugin writes a request JSON to
connect_request_path and quits; the Python launcher’s relaunch loop
(cli._run) starts a fresh Zellij whose plugin sees connect_target at
load() and comes up in client mode (crates/core/src/client.rs) — no
providers, no session, no API keys. Because a WASM plugin cannot hold a
socket, a cowboy _connect bridge process owns the connection and streams
each frame line in via zellij pipe --name connect-frame; sends go out as
one-shot cowboy _connect --send connections. /disconnect is the same
sentinel dance back to a local session. Standalone entry:
cowboy connect TARGET#SECRET-PATH.
Caveats: in a full NixOS (netns) deployment, outbound TCP is DNAT’d to the
secrets proxy — a /connect target port must be in
secretsProxy.passthroughPorts (UDS targets are unaffected; sheepdog always
allows AF_UNIX), and the in-session handoff loop exists only in lite launches
(full mode: run cowboy connect from a host shell — a client session needs no
agent config anyway). A read-only __forward --ro port works as an observer:
frames flow, intents are dropped server-side.
Known Zellij leaks in core
A few Zellij-isms survive in cowboy-core. None break a headless host; they
degrade gracefully and are tracked here for eventual promotion to proper host
verbs. (The two obvious candidates are already out: the $EDITOR round-trip is
Tui-local, and the debug pane is the open_debug host hook.)
- Subagent wasm path (
spawn.rs) — the fallback peer path assumes a Zellij plugin layout (data_dir()/zellij/plugins/cowboy-harness.wasm). A headless host overrides it via config /AGENT_HARNESS_WASM. - Model-facing prose (
config/loaders.rs) — thespawn_subagenttool description says “in a separate Zellij pane”. Cosmetic; visible to the model, not load-bearing.
Filesystem access alongside WIT
Core also uses direct filesystem operations for configuration, plan state and metadata. Montana grants these through WASI preopens, mapping host directories to identical guest paths so native execution effects see the same files. These grants are separate from the custom WIT imports. An embedder must review both the preopens and effect policy; see Design Overview.
Hacking
Cowboy’s core is a headless state machine shared by the Zellij plugin and Montana. Hosts supply asynchronous effects and the filesystem access the guest uses. The optional OCI runtime embeds Montana. This guide explains where to extend that implementation.
| You want to | Start from |
|---|---|
| Run the agent under your own UI, transport or runtime | The WIT world and templates/host |
| Ship the agent to a machine without linking Rust | packages.agent-component |
| See a complete host with threads, sockets and peers | crates/montana/ |
| Add an effect the agent can perform | The Host trait in crates/core/src/host.rs |
The contract: the WIT world
specs/wit/cowboy-agent.wit defines cowboy:agent@0.2.0, the one interface
every non-Zellij host programs against. It exports agent — initialize,
handle-command, handle-host-event, snapshot, describe — and imports
host — exec, http, set-timer, close-self, spawn-peer,
own-agent-id. Commands and host events are separate exports so a transport
message can never be mistaken for an effect completion; effect results carry
an opaque correlation the host echoes back unchanged; and an effect request
is not an authorization, so the host stays responsible for policy. The
Component ABI chapter walks through each of those
rules; the file itself is short enough to read first.
WIT defines the custom interface; the guest also needs WASI filesystem grants.
The JSON inside snapshot is an opaque display model, not a stable schema.
The config map given to initialize is the flat string map core parses;
crates/contracts/src/keys.rs inventories recognized keys. A new host-provided
capability needs an import and implementations in the affected adapters.
The artifact: packages.agent-component
Build from source; see Installation for
release availability. nix build .#agent-component produces share/cowboy/cowboy-agent.wasm, the
agent core compiled to wasm32-wasip2 and wrapped by crates/component/ so
it exports exactly the world above. The wrapper, crates/component/src/lib.rs,
is small: it maps initialize onto AgentHarness::on_load, handle-command
onto AgentHarness::handle_intent, handle-host-event onto
AgentHarness::handle_event, and snapshot and describe onto
AgentHarness::frame_json and AgentHarness::describe_json, and it
implements the core’s Host trait by calling the world’s imports. A second
output, agent-component-lite, is the portable build without the NixOS-only
pieces.
An external flake gets it as cowboy.packages.<system>.agent-component. That
is how a host stays on one cowboy revision for both the component and the WIT
it was built from.
The starting point: templates/host
nix flake init -t github:dmadisetti/cowboy#host
nix develop --command cargo run
The template is the smallest embedder that runs: a flake taking cowboy as an
input, and one Rust binary (templates/host/src/main.rs) that instantiates
the component with wasmtime, answers the six imports in-process, calls
initialize with a tiny config map, submits one prompt, prints every
snapshot as a JSON line and exits. Its HTTP handler returns an error, timers
are delivered without waiting, and peer spawning is ignored. Replace those
stubs before using it for real agent work. Its devShell links wit/ to the cowboy
input’s specs/wit so the bindgen! bindings track the same revision as the
component. templates/host/README.md explains each export, each import, and
what to replace to put a real UI, HTTP client and clock around the loop.
The headless reference: montana
crates/montana/ is the host cowboy itself ships: the daemon under systemd on
NixOS, the process inside the container image, and the library the OCI
runtime (crates/runtime/) calls in-process. crates/montana/src/agent.rs implements the imports with threads —
exec and http run off the guest thread and post their results back into
one channel, timers are additive sleepers — and crates/montana/src/lib.rs
assembles the config map, resolves and preopens the agent’s directories at
their own paths, and starts the control socket. Frames stream out as ndjson
and intents come in the same way (specs/CONTROL.md); the optional A2A front
in crates/a2a/ is a protocol adapter over describe and handle-command
(specs/A2A.md). Read it when the template’s answer to a question is “a real
host does more here”.
Inside the component: the Host seam
Hosts that can link Rust do not need the component at all. The Zellij plugin
(crates/harness/) links cowboy-core directly and supplies a Host
implementation of its own. That trait, in crates/core/src/host.rs, is the
seam the WIT world mirrors. Commands and HTTP requests return results later
as events correlated by an opaque Ctx map. Timers, pane operations and peer
lifecycle requests also go through the host. AgentHarness::with_host takes the implementation; the entry point
after that is AgentHarness::on_load, in crates/core/src/harness.rs.
For a new asynchronous effect, update the Rust host trait and its adapters. If component hosts need it, update WIT and the component and Montana bindings as well. Terminal-only view hooks can remain Rust-side; headless adapters have no terminal view to update.
What is not an extension point
- Configuration keys are parsed in one place,
crates/core/src/config/; a new knob is a new key there and a new line in the launcher that emits it, not a host-specific side channel. - Tools and skills have configuration and module interfaces; see Plugin Architecture.
- A host’s boundary includes effect policy, WASI preopens and the enclosing process permissions, mounts and network controls. The Security Model describes the managed deployment; a new embedder must supply its own controls.
Concurrency Locking
The agent runs one session as an event loop. SessionLock
(crates/core/src/lock.rs) keeps LLM requests, tool execution and tool-output
summarization from interleaving, and queues user input that arrives while any
of them is in flight. Every hold on the lock is bounded: one that goes too long
without evidence of progress is reclaimed by a sweep the heartbeat runs.
What holds the lock
SessionLock tracks three kinds of hold:
llm: Option<Lease>— an LLM request is in flight.summarizing: Option<Lease>— a tool output is at the summary model.active_tools: HashMap<String, ActiveToolState>— tool executions keyed by their uniquecall_id, each with its ownstarted_atandtimeout.
is_locked() is true while any of them is set. at_tool_boundary() is the
inverse — no request, no summarization, no registered tool — and is the only
point at which queued input is replayed.
Leases and epochs
A Lease is a hold with a deadline: started_at, a timeout, and an epoch
naming this particular hold. The budgets live in lock::lease: llm_for
covers one main-model round trip with no intermediate signal, long enough to
generate a full max_output_tokens reply at 40 tokens/s and never under LLM
(300s); SUMMARIZING (180s) covers one cheap-model summarization of a single
tool output. Both llm_for and Montana’s HTTP timeouts derive from
cowboy_contracts::model_wait, and Montana’s stay above the lease so a long
reply is never cut off in the transport first.
Under Montana a main-model turn is normally streamed. Montana answers requests
under its own relay root (MONTANA_RELAY in crates/contracts/src/relay.rs) in
process, and core’s stream_relay defaults to it unless the launch sets
stream_relay (empty opts out) or codex_base_url. Montana reads the
upstream reply on a relay thread while core polls it, so each poll that brings
new bytes refreshes the lease: llm_for then bounds a silence, not the whole
reply. Montana stops reading a stream nobody has polled for two minutes, which
is how a stream core gave up on is let go.
A successful final poll requires a complete provider terminal event: Responses
completed/failed/incomplete, Chat Completions [DONE] or finish_reason, or Messages
message_stop. A complete plain JSON envelope is also accepted, including
trailing quota telemetry. EOF after progress alone is a transport failure; core
does not commit partial text or dispatch tool items from it. Montana and core
use the same completion check in crates/contracts/src/relay.rs.
The deadline means “time since the work last moved”, not “time since
dispatch”. touch_llm() resets started_at on evidence the turn advanced — a
stream poll whose transcript grew, a compaction reply that starts its second
round trip — so a long but healthy streamed turn is never reaped, while a relay
that answers every poll with an unchanged buffer does not push the deadline
out.
try_acquire_llm(timeout) takes the LLM lease and returns its epoch, or None
when a request is already out. acquire_or_current_llm(timeout) returns the
live epoch when the lease is already held and takes it otherwise; compaction
uses it because it is reached both from inside a turn and from a free lock.
set_summarizing(timeout) takes the summarization lease and returns its epoch.
force_release_llm() and clear_summarizing() release them.
Epochs come from one monotonic counter shared by both leases, so an epoch
names exactly one hold for the life of the session. A dispatch stamps its
epoch into the request’s Ctx (dispatch::stamp_epoch, key EPOCH_KEY) and
the host echoes it back with the reply. Before any reply reaches a handler,
AgentHarness reads it (dispatch::ctx_epoch) and asks
epoch_is_current(epoch); a reply whose lease has been reaped or re-taken
belongs to a turn that has moved on and is dropped. A reply carrying no epoch
passes through — failing closed there would turn a host that drops the key
into a starved agent.
Tool tracking
register_tool(call_id, tool_name, timeout) records an ActiveToolState;
complete_tool(call_id) removes and returns it. Results are matched by
call_id, never by tool name, so concurrent calls to the same tool are tracked
independently. set_exec_kind(call_id, kind) attaches the execution-policy
classification made at dispatch, so a continuation of the same call is held to
the same policy. release_all_tools() drops every registration at once and
hands the states back: an interrupt settles the whole set, and the caller still
owes each one an abandoned-process record.
The sweep
sweep_expired() reclaims every hold whose deadline has passed — the LLM
lease, the summarization lease and timed-out tools alike — and returns them as
ExpiredLock values (Llm { waited, epoch }, Summarizing { waited, epoch },
Tool(ActiveToolState)). The leases come first so their handlers settle the
turn before a tool result handled afterwards can start the next request.
AgentHarness::sweep_session_lock (crates/core/src/heartbeat.rs) runs it at
the head of every timer fire, before any branch can return, and settles each
entry:
- an expired LLM lease drops any stranded relay stream, resets an active
status to
WaitingForInputand drains queued input; a late reply is then dropped by the epoch guard; - an expired summarization routes a synthetic 504 through
handle_summarization_response, which truncates the output it still holds, appends the tool result the model is waiting on and continues the turn; - a timed-out tool gets a synthetic tool result saying the harness stopped
waiting, naming the PID that was not cancelled —
Host::execis fire-and-forget, so a timeout can only stop waiting — and the process is tracked as abandoned. The result tells the model to confirm the PID withpsbefore signalling it, because the host may stop the process itself (Montana stops an exec’s process group at its own deadline) and the number can then name another process, and to stop it together with its direct children.
hold_summary() renders what holds the lock and how long each hold has left;
submit logs it whenever input is queued, so a quiet agent says what it is
waiting on.
The same sweep bounds the idle judge’s request, which is not a hold on the
lock: the judge runs while the agent is idle and must not queue input. While a
judge request is in flight no other is sent. IdleJudge::begin_request records
each one as a Lease with the JUDGE_DEADLINE budget (180s, below Montana’s
600s HTTP bound, so core decides when to give up on every host) and stamps its
epoch into the request’s Ctx under its own key, judge::EPOCH_KEY, which the
session-lock guard does not read. A request past its deadline is released with
a warning, and the next idle tick asks again; handle_judge_response drops a
reply whose request was already given up on.
Input queueing and coalescing
submit (crates/core/src/intent.rs) calls queue_user_input(content) when
input_can_run_now() is false. Besides the lock, that predicate holds input
while startup config loads are unanswered and, once permissions are granted,
while the session has not started (session_start_pending): a headless
client can submit before the first Timer runs init_context, and a turn
admitted then had no session to record its transcript or plan state in. Both
waits are bounded (10s each), and a failed session init releases input at
once. boundary_reached() returns None unless
at_tool_boundary() holds, and otherwise drains the queue through
drain_ready_inputs():
- a single queued input is returned verbatim;
- several are coalesced into one message under a
[Multiple inputs received while processing:]header, joined by---.
execute_next_tool_call calls boundary_reached() after a tool result is
recorded, gated on the same input_can_run_now() predicate submit queues on,
so a rate-limit backoff — which holds no lease — cannot let queued input
through. The heartbeat’s tick also drains the queue (check_queued_inputs,
behind the same predicate), so input stranded by a lock-free window is picked
up without another turn event.
Tests
lock.rs covers LLM mutual exclusion, boundary detection, coalescing, tool
timeout removal, the combined locked-state predicate, the sweep reclaiming all
three kinds of hold in lease-first order, touch_llm keeping a live stream
from being reaped, and an epoch ceasing to be current once its lease is gone.
Result Summarization
Large tool outputs are stored on disk as recallable artifacts and replaced in the context window with a short stub. When summarization is enabled, the stub’s body is produced by a cheap “summary” model instead of blunt truncation.
Implementation: crates/core/src/tools/summarize.rs (classification,
prompts, request formatting, stubs, fallback truncation) integrated through
harness.rs (handle_command_result) and handlers.rs
(handle_summarization_response).
Threshold
A tool output is summarized when its length exceeds
DEFAULT_SUMMARIZE_THRESHOLD = 12000 characters; no launch-configuration key
changes that. Input sent to the summary model is capped at
MAX_SUMMARIZABLE_LENGTH = 50000 characters.
Summary models
The summary model’s provider is taken from the summary_model config and
resolved through the shared key chain. Default model per provider:
| Provider | Default model |
|---|---|
| Anthropic | claude-sonnet-5 |
| OpenAI | gpt-4.1 |
| OpenRouter | openai/gpt-4.1 |
| Vercel | zai/glm-5.3-flash |
Those four are the only summarizers there are (ResolvedProvider); there is no
Ollama or Codex summarizer. ollama — like any unrecognized provider name —
resolves to the OpenAI key and the OpenAI request shape, so a summary_model of
ollama:<model> does not reach a local Ollama server, it sends <model> to
OpenAI. codex resolves to the first key available in the order OpenAI,
Anthropic, OpenRouter, Vercel, and because that is not a direct hit the configured model
name is dropped in favour of that provider’s default above. With no key at all,
no summarizer is built and outputs are truncated instead.
Requests use max_tokens: 2048 (or the provider-appropriate
completion-tokens parameter for OpenAI-compatible APIs) and ask for
temperature: 0.3. The Anthropic request drops the temperature for models that
reject a non-default one: Sonnet 5 (the default summarizer above), Opus 4.7 and
later, Fable, Mythos and any model id it does not recognize. Those requests run
at the API’s default temperature.
Output classification
The tool name determines an output type, which selects a type-specific prompt
and fallback head/tail ratio (ToolOutputType::from_tool_name):
| Type | Tool names | Head ratio |
|---|---|---|
| FileContent | read, cat, __HASHLINE_READ__ | 0.7 |
| SearchResults | grep, rg, search, ast-grep | 0.5 |
| DirectoryListing | ls, find, fd, glob | 0.3 |
| CommandOutput | bash, sh (and any unknown tool) | 0.6 |
| StructuredData | nix-search, gh | 0.5 |
| WebContent | web-search, web-fetch | 0.5 |
Each type has its own prompt: command output preserves errors and exit codes verbatim, search results are grouped by file with line numbers, directory listings are grouped by kind, structured data extracts names and versions, and web content extracts main facts and quotes.
Code-file handling
For FileContent, SummarizationRequest::code_file splits the file into three
parts: a before-section and after-section (summarized) around a relevant range
that is reproduced exactly with hashlines. When no range is supplied the
relevant range defaults to the middle third of the file. The prompt instructs
the model to keep the surrounding summaries to one or two sentences and preserve
the hashline section verbatim.
Pipeline
- A tool result arrives in
handle_command_result. The full output is logged to the session’smessages.jsonlexactly once, regardless of what enters context. - If the output exceeds the threshold and the session is ready, it is stored as a disk artifact and kept in memory for UI expansion.
- If summarization is enabled, a
PendingSummaryis queued, the request is dispatched to the summary model, andset_summarizing(true)gates user input until the response returns. - In
handle_summarization_response, the lock is cleared, the provider-specific response is parsed, and the summary is wrapped in an artifact stub. On a parse failure or non-200 status,fallback_truncateis used instead.
If summarization is disabled, step 3 is skipped and the artifact stub is built
directly from fallback_truncate.
Artifact stubs and recall
format_artifact_stub wraps the summary with a header and a footer noting that
the full output is stored:
[Artifact <call_id> | <tool> | <bytes> bytes, <lines> lines]
<summary>
[Full output stored — use recall_artifact("<call_id>") to search or read more]
The agent retrieves the full output on demand through the recall_artifact
builtin tool (wire name __RECALL_ARTIFACT__), which reads or searches the
stored artifact by call_id.
Fallback truncation
fallback_truncate splits at line boundaries using the type’s head/tail ratio,
operates on character counts to stay UTF-8 safe, and inserts a
[...N chars omitted...] marker between the kept head and tail. It is used
whenever the summary model is disabled, unreachable, or returns an unparseable
response.
Compaction
Compaction replaces the conversation with a summary when it grows too large.
The agent keeps working from that summary. Implementation:
crates/core/src/compaction.rs, with the triggers in crates/core/src/llm.rs
and the response handlers in crates/core/src/handlers.rs.
When it runs
Compaction starts in one of four ways:
- Turn boundary. A turn ends with the prompt at or above the threshold
(100,000 tokens by default; the experiment-only
compact_thresholdlaunch key changes it, with a floor of 8,000). - Hard cap. A request is about to go out at twice the threshold in the
middle of a turn (at the threshold itself when
compact_thresholdis set). The request is not sent. A pending user message is replayed after the summary lands. - Operator.
/compact [focus]compacts now, with an optional focus for the summary. - Agent. The model calls the
compacttool (below).
The summary comes from the compaction model (compact_model, which defaults to
the main model). A verification pass then has the main model revise it into a
handoff briefing. If the compaction model cannot be reached, the main model
writes the summary instead. The local stub, which keeps only the last request
and the file list, is used only when no model can be reached. Below the hard
cap, a failed compaction keeps the transcript and is retried at the next turn
boundary.
Each applied compaction prints [INFO] Compaction applied: messages_before=<n>
on stderr, whichever trigger or rung produced it. The eval runner counts these
lines. The transcript and summary from before the compaction are saved as
artifacts/compaction-<n>.jsonl and .txt in the session directory.
Plan state and abandoned tool processes are harness state, not transcript, so
they survive compaction. The context packet carries them into the next
request. By default the plan otherwise lives in the latest update_plan_state
result; compaction removes that result, so the next packet carries the plan
until the agent updates it again.
The compact tool
{
"type": "object",
"properties": {
"focus": {
"type": "string",
"description": "Optional: what the summary should prioritize"
}
}
}
compact is an in-process builtin (__COMPACT__). Its execution policy is
InProcess, and it never runs a shell command.
The tool does not compact on the spot. Its call is part of an assistant turn
whose other calls may still be running, and their results must pair with that
turn. So the tool records the request and answers its call at once. The rest of
the batch then runs. When the last result is in and the harness is about to
send the results to the model, it compacts instead. The whole turn goes into
the summary, including the compact call and its result, so no tool_use is
left without its tool_result. After the summary is applied, the same turn
continues. The next request carries the summary and then a harness note saying
that the compaction the agent asked for has finished. If user input cut the
tool loop short, that input is replayed instead of the note, as the hard cap
replays it.
The tool is refused, with an error result and nothing recorded, when:
- compaction is disabled (
compact.enabled, which no launch setting turns off today); - a compaction is already requested in this turn or running;
- the prompt is below 8,000 tokens (
MIN_SELF_COMPACT_TOKENS). A freshly compacted prompt is just under 8,000 tokens, so compacting a smaller prompt would not make room.
If the requested compaction fails below the hard cap, the transcript is kept.
The turn continues with its results and a note giving the reason. An interrupt
drops a requested compaction that has not started yet. An agent-requested
compaction also prints [INFO] Compaction requested by the agent on stderr.
Idle resume note
A provider’s prompt cache expires while the agent is idle. The first request after a long idle period rebuilds the cache whatever it contains. That makes it a good moment to point the agent back at its goals, and the cheapest moment to compact.
The note is added on the first wake after PROMPT_CACHE_TTL: one hour since
the last main-model request. A wake is any input that starts a turn, such as a
user or bridge message, a judge reprompt or the idle nudge. The hour is
deliberately long. Anthropic’s ephemeral cache lasts five minutes and its
extended option one hour. OpenAI’s in-memory cache keeps a prefix for five to
ten minutes, up to an hour. Extended 24-hour retention is not covered.
What the note says:
- With a recorded plan: the objective, open tasks, blockers and next step,
and a request to check them against what is left and update the plan with
update_plan_stateif it is stale. When the wake is the harness’s own idle nudge, this text replaces the nudge rather than joining it. - Without a plan: a user or bridge message gets no goals note, because the message is the goal. The idle nudge stays unchanged.
- With a large context: a closing line says the agent can call
compactnow at no extra cache cost. This line is added in both cases above. A large context means at least half of the threshold, and never below 8,000 tokens. It needs thecompacttool and compaction enabled.
The note is a suggestion. Nothing on this path compacts. It is given at most once per idle period, because each request the agent sends starts a new period.
The note is stored in the transcript with the role note
(specs/transcript.cddl) and logged where it was added. Requests carry it as
user content at that place, and a resumed session sends it at the same place.
Code that looks for what the user said matches the role user, so a note is
never taken for the user’s words. The continuation after an agent-requested
compaction uses the same role.
Inbound Message Reliability
A sender can receive no reply even though the agent started the work. A restart can also cause work or an external action to happen again. Before resubmitting a silent request, the operator must inspect the session, outbox, bridge outcome and any action the request could have caused.
A turn that fails on a provider error, or on a response the agent cannot
parse, still replies. Its reply to the sender is the failure text, such as
API Error: …, the same text the session records. That text is redacted and
cut to its first 500 characters, since a provider error can carry the
provider’s whole response body; the agent log keeps the full error.
Redis recovery retries delivery to dispatch, not to successful completion. The agent queues acknowledgment when it hands a message to the agent loop, without waiting for an answer. Once that acknowledgment lands, Redis will not recover an interrupted turn. If it does not land, reclaim can dispatch the message again. There is no exactly-once guarantee for completion or effects.
Session recovery is separate. On restart, the agent resumes its saved session, and an idle reprompt can act on the unanswered request again. The active message and reply-source binding lived only in process memory. The work can recur while the reply loses its source binding: a resumed answer may reach the session but no source outbox, leaving the original sender with silence.
| Observation | What it establishes |
|---|---|
| Service is running | The process is up; useful progress still needs inspection |
| No pending Redis entries | No entries await acknowledgment in that group |
| Acknowledgment landed | Dispatch was acknowledged, not completion |
| Reply in the agent outbox | A reply was queued for the bridge |
| Session resumed | Conversation state returned; source routing may not have |
There is no durable deduplication across agent restarts and no durable binding that reconnects a resumed turn to its source. Within a process, a bounded seen window suppresses repeat dispatch. Failed acknowledgments retry the acknowledgment first; exhausting that budget allows reclaim to offer the request again. External effects are not transactional with acknowledgment.
This page covers messages into the agent. Bridge outboxes carry messages and requests out of it. An outbox retries a failed send a limited number of times, then dead-letters it and tells the agent. It never retries an attempt that may already have taken effect; instead it tells the agent the request could not be confirmed. See delivery, retry and uncertainty.
The operator procedure
Use the host-side operator identity to inspect missing or duplicate replies.
Check the agent with cowboy status and cowboy doctor first. A running
service does not prove that a request completed or reached its sender.
The identity. Not the agent’s. Every agent credential is scoped to
~<agent>:* and holds only the verbs the poll issues, which does not include
XPENDING — the agent has no use for it, and an agent that could enumerate its
own pending list still could not see another’s. modules/pubsub.nix generates
one identity for a person instead: operator, readable across the whole
keyspace, with no @admin (it cannot rewrite the ACL) and no @dangerous (no
CONFIG, FLUSHALL, KEYS, SHUTDOWN). Its URL is root-only, and Redis
binds inside the namespace, so every command below is ip netns exec:
sudo -i
. /run/cowboy/operator-redis.env # sets REDIS_URL
r() { ip netns exec cowboy-ns redis-cli -u "$REDIS_URL" "$@"; }
Three names come from the generated configuration rather than from memory. For
agent <agent> and source <source>, /etc/cowboy/<agent>/sources.json names
the stream; the group is cowboy; the consumer is harness-<source> — the
SOURCE, not the agent (RedisStreamsSource::new names it after the source it
polls; two agents on the same source carry the same consumer name on their
own separate streams):
stream=$(jq -r '.sources["<source>"].stream' /etc/cowboy/<agent>/sources.json)
group=cowboy
consumer=harness-<source>
1. Is anything stuck? The pending list is the only record of an entry the agent read and did not acknowledge:
r XPENDING "$stream" "$group"
A summary of 0 means the group has no pending entries. It does not prove
that every stream entry was read or that dispatched requests were answered.
2. Which entry, and how long has it been stuck? The extended form lists one line per entry — id, consumer, idle milliseconds, delivery count:
r XPENDING "$stream" "$group" - + 10
An entry whose idle time is under ten minutes is not yet eligible for reclaim.
It may be queued, or its reader may have stopped; age alone does not prove
progress. Reclaim waits until RECLAIM_IDLE_MS has passed. An entry idle for longer
than that whose delivery count is not rising is one no poll is reaching — check
that the agent is running at all before doing anything else.
3. What was in it?
r XRANGE "$stream" <id> <id>
4. Did the turn already have an effect? Ask this before step 5, because step 5 is the one action in this procedure that can do harm. The agent’s reply goes to its own outbox, and that stream is the record of it:
r XRANGE "<agent>:<source>:outbox" - + COUNT 20
The bridge keeps settled outbox entries for OUTBOX_RETAIN_S (seven days by
default), so an older reply may already be trimmed. An outbox entry shows a
reply was queued, not that the external platform delivered it. Inspect bridge delivery state and the destination before
resubmitting. Also check files, rebuild results and other requested actions.
Do not assume reclaim will discard a request that already had an effect. Deduplication is bounded and lives in process memory; after restart the same entry can dispatch again. Neither reclaim nor manual resubmission is an exactly-once operation. If work already happened, reconcile that outcome rather than blindly replaying the original request.
5. Resubmit only after reconciliation. If retrying is appropriate, submit a new entry. Keep in mind that the old pending entry can still be reclaimed. This minimal command submits content only; it does not restore the original sender or channel metadata and therefore does not promise a routed reply:
r XADD "$stream" '*' content '<the content from step 3>'
Implementation
What one poll does
poll_command emits three redis-cli calls in one sh -c:
XGROUP CREATE … 0-0 MKSTREAM, idempotent, so a stream that does not exist yet is not an error.XAUTOCLAIM <stream> <group> <consumer> <idle> <cursor> COUNT 10— the recovery step.XREADGROUP >moves an entry into the group’s Pending Entries List under the consumer that read it, and never offers a pending entry again —>means “entries no consumer has read”. So an entry a crashed run had taken is invisible to every subsequent>, and the reclaim is the only thing that hands it back. The consumer name is deliberately stable across restarts (RedisStreamsSourcedefaults it toharness-<source>, and the comment there says why): a fresh name per process would leave the whole previous pending list keyed to a consumer that will never ask for anything again. Stability keeps the list reachable; the reclaim is what reaches it.XREADGROUP GROUP … COUNT 10 STREAMS <stream> '>'— new entries.
Reclaim before read, so a message stranded by a restart is not queued behind
messages that just arrived. A marker line separates the two replies; both are
parsed by the same hand-rolled reader over redis-cli --no-raw output.
The scan carries its cursor. XAUTOCLAIM scans the pending list from a
cursor and answers with the one to resume from. A scan that spends its COUNT
on entries too young to claim returns an empty batch and a non-zero cursor;
restarting from 0-0 every poll re-walks that same head, and an orphan behind
a full scan’s worth of young entries is only reached once the head drains on
its own. RedisStreamsSource::reclaim_cursor keeps the returned cursor, which
is why poll_command and parse_poll_result take &mut self. Redis answers
0-0 when the scan wraps, so the walk returns to the head on its own.
An entry with no usable content is still emitted, with an empty one. It
has to be: an entry nothing returns is an entry nothing acknowledges, and since
the poll reclaims the pending list it would come back on every poll forever,
masking the ten entries behind it. The manager acknowledges and drops it.
Acknowledgment semantics
XACK answers with the number of entries it removed from the pending list.
The reply is examined, not the exit code alone: redis-cli prints a refused
command’s error text on stdout and exits zero, so an ACL that does not grant
XACK used to read as an acknowledgment that landed. The generated command
requires the reply to be a run of digits — zero included, which is the
idempotent case — and exits ACK_REPLY_NOT_A_COUNT otherwise.
The acknowledgment is queued at dispatch, not at completion.
process_pubsub_messages calls SourceManager::mark_processed on each message
as soon as the prompt has been handed to process_user_input, and the same
poll tick then calls send_pubsub_acks. Nothing waits for the turn to produce
an answer. Redis’s redelivery therefore covers exactly one window — from the
XREADGROUP that read the entry to the XACK that follows its dispatch — and
nothing after it. A process that dies mid-turn has already acknowledged the
entry it was working on; the pending list holds no record of it, and no reclaim
will bring it back. That is the deliberate trade: the alternative, acking at
completion, makes every crashed turn a guaranteed re-answer, including the ones
that had already sent their reply.
A failed acknowledgment retries the acknowledgment, not the request.
SourceManager::retry_ack queues the same XACK again, up to
MAX_ACK_ATTEMPTS. Only once that budget is spent does the manager forget the
entry, which hands it back to the reclaim. Forgetting on the first failure —
before the retry budget is spent — gives the reclaim a message the agent
has already answered, and the next poll starts a second turn on it.
Runas handoff: read-only bridge ACL
The root-owned handoff directory remains mode 3770, with the per-operation
agent handoff group. The bridge remains outside that group, unprivileged and
with no supplementary groups. One non-recursive tmpfiles a+ rule adds an
explicit named bridge access ACL (r-x) and default file ACL (r--). The full
base entries explicitly preserve directory group rwx, access mask rwx, and
other ---. Consequently stat still reports 3770; using mask r-x instead
would both remove agent write permission and break the root claim predicate.
Default entries are owner rw-, bridge r--, group r--, mask r--, other
---. The request tool creates the final manifest name directly, with a
noclobber redirection: an existing name is refused atomically, and there is no
temporary name for the requester to delete. Because the directory has a default
ACL, the tool’s umask 0227 does not apply. The new file takes the default
entries, limited by the redirection’s creation mode, so bridge and group can
read it from creation and others cannot. The tool’s chmod 0440 then drops the
owner’s write bit and leaves the mask at r--, so the bridge never gains write
or execute permission. Setgid inheritance preserves the handoff gid. Extended
ACLs are compatible with the helper’s directory 3770, file 0440, gid and
single-link checks; no relaxation of those checks is needed.
The ACL is deliberately not recursive: old pending files do not acquire named
bridge entries retroactively. The agent can remove an inherited ACL on its own
file and deny service; that does not elevate bridge rights. This rule is not a
sanitizer for arbitrary pre-existing ACLs: a+ merges the declared entries.
The parent directory must remain root-controlled. Only the directory’s named
bridge ACL, not group membership, authorizes bridge traversal.
Validation
tests/test_runas_handoff_acl.py checks the declaration in
pkgs/runas/module.nix: the exact a+ rule, the 3770 directory, the
noclobber create and chmod 0440 with no mktemp or rm -f, and a bridge with
no groups and no privilege. Its native test applies the tmpfiles rule twice to a
scratch directory and creates a manifest exclusively with mode 0440. It then
compares the exact directory and file ACL entries, the inherited gid, the mode
and the link count. It runs the root helper’s own directory and file predicates
against that file, and shows that setfacl -b removes the bridge entry without
widening the mode. The bridge is a distinct numeric uid, not an account, and
only the helper’s expected directory owner is changed, so this is not a root
claim test. It skips when systemd-tmpfiles, getfacl or setfacl is missing
or the sandbox refuses to run them.
The vm-runas-security flake check boots a NixOS guest with the generated rules
and the real agent, bridge and operator accounts. The agent publishes a
manifest. The bridge, which is in no handoff group, reads it, and is refused
opening it for writing, unlinking it and creating a file in the directory. The
root claim, started through systemd and polkit as the bridge, accepts the
extended-ACL file and consumes it.
Neither covers the request tool’s own shell write path: both create the manifest from Python. Neither has the bridge list or rename in the directory, reapplies tmpfiles on a running system, or shows that stripping a file’s ACL yields a clean read failure with no privileged fallback.