All articles

Infrastructure / Swamp & agents

How to Shepherd the Herd

A Herdr and Codex setup guide: capture one Windows Server image, test it on Hyper-V and KVM, and review the exact bundle.

A hooded shepherd with a cyan-lit crook guides a flock of robotic sheep along a misty bridge.
A digital shepherd guides a flock of machines.

The digital frontier is moving fast. I’m increasingly interested in the tools and workflows that let me work with agents in a way I’m comfortable with, whether I’m writing code or not.

Working across multiple machines and agents has made me love shepherding them. I get to customize the experience and make the work itself better. The more I get the hang of it, the better a lot of my experiments feel, both in the homelab and at work.

Watch the simulation

53 seconds, no audio. The run trace at right explains what the panes are doing. No VMs were deployed for this video.

Download MP4

Read the video transcript
  1. 0:00–0:10: The lead claims the brief and starts the worker. Windows Server 2025 installs with an answer file. Sysprep generalizes and shuts down the reference VM.
  2. 0:10–0:17: WinPE captures the offline Windows partition into one WIM. The exchange records the capture digest and the lead requests review.
  3. 0:17–0:26: Hyper-V's VHDX boots. On KVM, WinPE can see the VirtIO SCSI disk, but the installed guest cannot boot from it. The reviewer refuses the bundle.
  4. 0:26–0:43: The worker stages the matching signed driver in the offline guest without recapturing the base WIM. The reviewer reruns both profiles. Both finish unattended setup.
  5. 0:43–0:53: The lead waits for explicit approval. The operator approves the revised bundle for two isolated test VMs, and the exchange retains the resulting receipts.

How the pieces fit

  1. Operator gives the brief

    Sets the output and boundaries. Only the operator can approve where the exact result goes.

  2. Codex lead dispatches

    Assigns one output per worker. Herdr keeps the sessions visible and carries short messages between them.

  3. Worker builds and captures

    Unattended setup, Sysprep, then offline WIM capture. One base WIM; separate deployment profiles.

  4. Reviewer checks both targets

    Tests the pinned bundle on Hyper-V (Gen 2, VHDX) and KVM (UEFI, qcow2). A failure goes back to the worker.

  5. Git keeps the evidence

    The exchange records the brief, candidate, review rounds, decision, and receipt. A terminal ping points to a record; it is not the record.

  6. Operator approves; lead delivers

    A pass is not approval. The lead delivers only the approved bundle to the named environment and records what happened.

Rework loop: Keep the failed verdict. Fix the profile, keep the same base WIM, record a new candidate, and rerun both targets.

Run the no-VM example on GitHub.

Set up a Codex lead, a capture worker, an independent reviewer, and a Git exchange. Then use them to follow the Nightwire demo: one unattended Windows Server 2025 build, one captured OS image, separate Hyper‑V and KVM profiles, and a release decision you make yourself.

What is real here: the Herdr/Git setup and the local manifest check below are executable. The video simulates image capture and VM boots. A passing manifest check is not evidence that Windows booted. Start on one Mac with the no-VM rehearsal; the lab workflow explains what real evidence would replace those stand-ins.

1. Set up the four panes

On a Mac, install Herdr Core, Codex CLI, Git, and Python 3. Sign in to Codex before opening the recording workspace. Start a fresh Herdr desktop space named windows-image. It makes the four panes visible; it doesn't run the agents or store the handoffs.

hc --version
hc server status     # If stopped: hc server start
codex --version
codex login status
git --version
python3 --version

The examples use the command shape of hc 0.1.22 and Codex CLI 0.172.0. Check hc run --help and codex --help if your versions differ.

Pane Owns
image-lead The brief, scopes, candidate IDs, and release decision. This is the Codex session you talk to.
capture-worker Answer-file and image work, or the fixture manifest in the rehearsal. One output, one writable worktree, one owner.
deploy-review Independent checks on the exact candidate. Read-only access to candidate files.
agent-exchange A shell viewing the local Git repo: request files, verdicts, approvals, and receipts. No model needed in this pane.

Two paths connect the panes. hc send is a ping, usually carrying a path and an ID. The exchange stores the evidence that survives a session restart. No Forgejo server is required on one host. Across hosts, transfer the candidate and the exchange revision via an authorized channel before sending the ping. A path alone doesn't transfer a file.

2. Create the no-VM rehearsal

Run this on the Mac in a normal shell. It creates a fresh directory, a target repo and a separate exchange repo. It does not install Windows, read a real WIM, or contact a hypervisor. The WIM stand-in is represented by a fixture digest in a JSON manifest.

ROOT=$(mktemp -d "${TMPDIR:-/tmp}/windows-image.XXXXXX")
IMAGE="$ROOT/image"
EXCHANGE="$ROOT/agent-exchange"
git init -q -b main "$IMAGE"
git init -q -b main "$EXCHANGE"
for repo in "$IMAGE" "$EXCHANGE"; do
  git -C "$repo" config user.name "Windows Image Demo"
  git -C "$repo" config user.email "demo@example.invalid"
done
cat > "$IMAGE/bundle.json" <<'JSON'
{
  "fixture_only": true,
  "base_wim_sha256": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
  "hyperv": {"firmware":"uefi","disk":"vhdx","generation":2},
  "kvm": {
    "firmware":"uefi","disk":"qcow2","controller":"virtio-scsi",
    "winpe_storage_driver":"vioscsi.inf","offline_guest_storage_driver":null
  }
}
JSON
git -C "$IMAGE" add bundle.json
git -C "$IMAGE" commit -qm "Seed disposable Windows image fixture"
BASE=$(git -C "$IMAGE" rev-parse HEAD)
git -C "$IMAGE" worktree add -qb demo/image "$ROOT/worker" "$BASE"
REQUEST="$EXCHANGE/workspaces/image-lead/in/from-operator/windows-image"
mkdir -p "$REQUEST" "$EXCHANGE/leases"
cat > "$REQUEST/syn.md" <<BRIEF
# Windows image rehearsal
Base: $BASE
Worker root: $ROOT/worker
Allowed changes: bundle.json, KVM target profile only.
Preserve the base WIM digest and Hyper-V profile. No VM access, no network,
no credentials, no push or publish. Reviewer checks the pinned commit.
Integrate only after the operator approves the exact reviewed commit.
BRIEF
printf 'owner: capture-worker\npath: bundle.json\nstate: assigned\n' \
  > "$EXCHANGE/leases/capture-worker.yaml"
git -C "$EXCHANGE" add workspaces leases
git -C "$EXCHANGE" commit -qm "Open Windows image rehearsal"
printf 'ROOT=%s\nBRIEF=%s\n' "$ROOT" "$REQUEST/syn.md"

The lease says who owns the file; the worktree separates Git checkout state. Neither is a filesystem security boundary. Keep workers in a sandbox, give them only the relevant directories, and keep private vaults and unrelated files out of the environment. For stronger read isolation, use a separate account or disposable VM. Keep deployment credentials out of the exchange and out of pasted prompts.

3. Start the sessions and make the handoff visible

Open an interactive Codex lead in the Herdr space, using the printed ROOT as its working directory. Set ROOT and REQUEST in the shell where you run the examples if it doesn't inherit them.

hc run --bg --name image-lead --cwd "$ROOT" \
  --label project=windows-image --label role=lead \
  -- codex --no-daemon -s workspace-write -a on-request \
  "Read $REQUEST/syn.md. Claim it in Git. Coordinate a worker and a separate reviewer. Do not deploy or merge without the exact operator approval."
hc get --json image-lead

Run worker and reviewer launches from the lead terminal so they're its children. If the lead already has a herdr.space label, copy that value into each launch with --label herdr.space=ACTUAL_SPACE_ID to group their panes.

hc run --bg --name capture-worker --cwd "$ROOT/worker" \
  --label project=windows-image --label role=worker \
  -- codex --no-daemon -s workspace-write -a on-request \
  'Only update the KVM profile in bundle.json after a review finding. Preserve the WIM digest. No web, VM access, secrets or push. Report to image-lead with hc send.'
hc get --json capture-worker

Put the task in the launch and verify delivery. If first_message.sent is false, use hc read --lines 80 capture-worker to inspect startup or trust prompts, and check whether the prompt already arrived before resending. Use hc wait capture-worker, or hc wait --children any once you have several children. A message, timeout, or idle status is not a verdict. Read the result and compare it with what's in Git.

For the exchange pane, open a shell in $EXCHANGE. Use git log --oneline -6 and look at the specific round rather than printing every file.

4. Run one failed review, one fix, and one approval

The first candidate is the seed commit: WinPE has its storage driver, but the deployed Windows OS manifest doesn't. Record the seed's full Git ID as the first candidate. Use a new request directory for each round:

workspaces/deploy-review/in/from-image-lead/windows-image-r1/
  syn.md        candidate ID, WIM digest, profiles, checks, scope
  syn-ack.md    claimed/done and verdict path
  ack.md        lead's receipt (returned for rework, or landed)
workspaces/deploy-review/out/windows-image/windows-image-r1-verdict.md

Here is the first round's request. For R2, use a new round directory and the full revised candidate ID.

ROUND=windows-image-r1
CANDIDATE="$BASE"
REVIEW_DIR="$EXCHANGE/workspaces/deploy-review/in/from-image-lead/$ROUND"
mkdir -p "$REVIEW_DIR"
REVIEW_REQUEST="$REVIEW_DIR/syn.md"
printf 'base: %s\ncandidate: %s\ncheck: fixture manifest only\n' \
  "$BASE" "$CANDIDATE" > "$REVIEW_REQUEST"
git -C "$EXCHANGE" add "${REVIEW_DIR#"$EXCHANGE"/}/syn.md"
git -C "$EXCHANGE" commit -m "Request review: $ROUND"

Write the round's syn.md before pinging the reviewer. Set REVIEW_REQUEST to its absolute path. Launch the reviewer from the lead as a fresh session; use a distinct terminal name for round two if round one's session is still alive.

hc run --bg --name deploy-review --cwd "$ROOT" \
  --label project=windows-image --label role=reviewer \
  -- codex --no-daemon -s read-only -a on-request \
  "Read $REVIEW_REQUEST. Check the candidate Git object, not a live worktree. Report PASS or FAIL and the full ID to image-lead. Do not edit or deploy."

Use the same independent check for both rounds. Set CANDIDATE to a full Git ID from the request. The reviewer reads from Git, then the lead commits the attributed verdict to the exchange.

git -C "$IMAGE" show "$CANDIDATE:bundle.json" | python3 -c '
import json, sys
m = json.load(sys.stdin)
h, k = m["hyperv"], m["kvm"]
ok = (
    m["fixture_only"] is True
    and h == {"firmware": "uefi", "disk": "vhdx", "generation": 2}
    and k["firmware"] == "uefi"
    and k["disk"] == "qcow2"
    and k["controller"] == "virtio-scsi"
    and k["winpe_storage_driver"] == "vioscsi.inf"
    and k["offline_guest_storage_driver"] == "vioscsi.inf"
)
print("PASS: fixture profiles agree" if ok else "FAIL: check boot-storage profile")
sys.exit(0 if ok else 1)'
  1. Round 1 fails. The reviewer identifies the unset guest storage driver. The lead records the verdict and sends the finding to the worker. Nobody touches a hypervisor.
  2. Rework. The worker changes only offline_guest_storage_driver to "vioscsi.inf". The lead checks the diff and compares the WIM digest to the seed before recording a new candidate commit on the worker branch. If sandbox rules prevent a linked-worktree commit, the lead records it rather than widening the worker's access.
  3. Round 2 passes. Rerun the same check against the new full ID. Keep Round 1 in the exchange. A passing verdict is still not an approval.
  4. Approve and close. In the rehearsal, approve that exact Git ID for disposable local main only. Verify the approved ID equals the passing ID; validate that main is clean and still at the planned base. Fast-forward to the exact approved ID, not the moving worker branch tip. Record the reviewed ID, your decision, destination, observed HEAD, and lease closeout in the exchange. If the branch moves, the new tip is not covered by the approval. If an earlier failed attempt is an ancestor of the approved tip, a fast-forward still preserves that history.

After you explicitly approve, the lead can use this guard in the disposable repo. Populate the two IDs from separate records: the PASS verdict and the operator's decision. This snippet deliberately never reads the worker branch tip.

test -n "${PASS_ID:-}" &&
test -n "${APPROVED_ID:-}" &&
test "$PASS_ID" = "$APPROVED_ID" &&
test "$(git -C "$IMAGE" rev-parse --verify "$APPROVED_ID^{commit}")" = "$APPROVED_ID" &&
test "$(git -C "$IMAGE" branch --show-current)" = main &&
test -z "$(git -C "$IMAGE" status --porcelain)" &&
test "$(git -C "$IMAGE" rev-parse HEAD)" = "$BASE" &&
git -C "$IMAGE" merge --ff-only "$APPROVED_ID" &&
test "$(git -C "$IMAGE" rev-parse HEAD)" = "$APPROVED_ID"

5. Swap the fixture for a real Windows lab

This is the same control flow as the video, with different evidence. Use isolated test VMs, approved Windows Server media and licensing, supported WinPE/DISM tooling, separate scratch disks, and a signed VirtIO package matching the Windows guest and controller. Keep unattended answer-file templates free of embedded passwords or product keys; supply per-guest values through your approved secret path. Do not apply a disk profile to an existing VM or disk.

Video step Real implementation and required evidence
Answer file Run Windows Setup on a disposable reference VM with Autounattend.xml. Validate the answer file for the specific media and verify installation completed without prompts.
Generalize and capture Generalize and power down the reference installation before capture. Boot WinPE, identify the offline Windows partition, and use DISM to capture it as a WIM. Record WIM index, OS build and SHA‑256. The WIM is the OS partition payload, not a bootable virtual disk. Sysprep · WIM capture and apply
Apply to each backend Build a fresh GPT/UEFI target disk per profile, apply the same WIM and create its EFI boot files with BCDBoot. Use a VHDX for Hyper‑V Gen 2 and a qcow2 disk with UEFI for QEMU/KVM. The profiles and outputs can differ even though the source WIM is identical. Hyper‑V Gen 2 · libvirt domain format
Fix the KVM profile For the simulated VirtIO SCSI setup, WinPE could see the disk, but the applied Windows OS did not have the boot storage driver. Stage the matching signed driver into the offline guest before first boot. WinPE separately needs its own matching driver if its path to the disk requires it. Keep the WIM unchanged and capture a new profile revision. Offline DISM driver servicing · VirtIO Windows drivers
Review and release Pin the WIM digest, profile revision and test results in the bundle manifest. Rerun both profiles in an isolated test lane already authorized for review. For each backend capture independent first-boot and unattended setup completion evidence. Then require operator approval naming the exact bundle and destination before any separate deployment. Save final boot receipts and close.

Keep the WIM and other large artifacts in a private artifact store when moving beyond the single-host rehearsal. Git keeps their digests, paths, configuration, and receipts. Track what was directly tested, not just what the worker reported. Swapping the lead or reviewer to a different CLI leaves that contract intact.

Questions or a different perspective?

LinkedIn follow-up
Back to all articles