Drove Architecture Inside Herdr2
Architecture of Drove, the native single-daemon multi-agent DAG orchestrator inside Herdr2.
Drove is the multi-agent DAG orchestrator built natively inside herdr2 (herdr-core/crates/herdr2/src/drove/), combining single-daemon Rust execution with the Herdr2 Desktop UI (herdr-app) and the read-only macro observability workbench (drove-web/).
1. Single-Daemon Design (Zero External Node/acpx Processes)
Section titled “1. Single-Daemon Design (Zero External Node/acpx Processes)”All orchestration runs inside the existing herdr2 daemon (DroveRuntime):
- State & Secrets (
~/.local/state/herdr2/<session>/drove/):state.json: atomic persisted state for Runs, Tasks, Workers, Attempts, Messages, and DaemonEvents (store.rs).items/<worker_id>.jsonl: append-only worker transcript items streamed over SSE.secrets/(0700):ai.key(0600) andcoordinator.token(0600), plusartifacts/(verify-*logs andreview-*.patchdiffs).
- Config (
~/.config/herdr2/drove.json):- Stores role bindings (
coder,tester,writer,reviewer,researcher, custom roles), minimal AI Assistant settings (enabled,baseUrl,model, switches — raw API key never written here), and optionalmagpiequota toggle (defaultenabled: false).
- Stores role bindings (
- Worker Pool & Bottom-Left Agents Tree (
pool.rs,api/run.rs):- Every Drove worker spawns directly via
Coreas a headless ACPa*sub-agent (name: None,notify: false,inject_mcp: false,dangerously_skip_permissions: true,parent= coordinatort*ora*). - Live display text uses
a.title+labels["drove.display"]("<role> · <task_key>"while busy,"<role> · idle"when warm idle) so the bottom-left Agents tree inherdr-appdisplays worker teams natively without running intoAgent.nameuniqueness/charset rules. - Completed author, worktree, and reviewer workers stay
idle(and Git worktrees are merged and reset clean) across task completion andh2 drove completefor warm reuse viah2 drove add. Workers are closed only when the Coordinator session exits/is trashed, the user deletes/trashes the Run in Drove Web, or explicitly stopped. Core->DroveRuntimelifecycle events flow lock-free overmpsc::UnboundedSender<PoolSignal>, preventing lock-order deadlocks and keeping externalh2 kill <a*>and coordinator close/trash hooks synchronized with Drove worker/attempt lifecycle.
- Every Drove worker spawns directly via
- Process Sandboxing (
sandbox.rs):- Linux (
bwrap): Whenbwrapuser namespaces are available, worker launches bind<state>/droveread-only, shadow<state>/drove/secretsand<state>/secretswith--tmpfs, re-bind<cwd>writable when it is a worktree under<state>/drove/worktrees, and--ro-bind <cwd>forreadonlyroles. - macOS (
sandbox-exec): When/usr/bin/sandbox-exec(Seatbelt) is available, worker launches run with an inline SBPL profile that denies writes to<state>/drove,drove.json, andai.json(re-allowing writable worktrees under<state>/drove/worktrees), denies writes to<cwd>forreadonlyroles, and denies all reads & writes to<state>/drove/secretsand<state>/secrets. - Windows (
restricted-token): Worker launches run throughherdr2 __drove-sandbox -- <argv>using Win32CreateRestrictedToken(DISABLE_MAX_PRIVILEGE+NT AUTHORITY\RESTRICTEDS-1-5-12inSidsToRestrict) +CreateProcessAsUserW+KILL_ON_JOB_CLOSEJob Object containment, paired with idempotent NTFS Deny ACEs forS-1-5-12blocking read/write on<state>/drove/secrets&<state>/secretsand blocking write on<state>/drove,drove.json, andai.json(with a protected DACL on<state>/drove/worktreesso worktrees stay writable without mutating user repo ACLs;readonlyworkspace edits continue to be caught byroles.rsdiff guardrails).
- Linux (
2. UI Split: Herdr2 App (Settings -> Drove) vs Read-Only drove-web
Section titled “2. UI Split: Herdr2 App (Settings -> Drove) vs Read-Only drove-web”herdr-app(defaults/frame/settings/main.js->Drovetab):- Single control plane for configuring Drove across
This computerand SSH-paired machines:- Roles ONLY (
Agent,Model,Thinking Effort, optionalFallback,+ Add role). - AI Assistant (
enabled,Service URL, maskedAPI Key,Save,Test Connection— no vendor presets). - Magpie Quota (Optional) (
enableddefault OFF, optional gateway URL +Test).
- Roles ONLY (
- Secrets are written to temporary local JSON files and immediately deleted via
--file <tmp> --consumeso API keys never appear on CLIargv.
- Single control plane for configuring Drove across
drove-web/(127.0.0.1:7799/H2_DROVE_PORT):- Served directly by
herdr2’s localhost HTTP/1.1 + SSE server (http.rs,routes.rs) with injectedwindow.__DROVE_TOKEN__. - Shows DAG visualization, live worker item streams, review diff patches, verify logs, and read-only Role matrix + stats (
PUT /api/agents&PUT /api/ai/configreturn405 configured_in_app).
- Served directly by
3. Execution, Guardrails & SSH Federation
Section titled “3. Execution, Guardrails & SSH Federation”- DAG Scheduler & Router (
scheduler.rs,router.rs,protocol.rs):- Supports static
foreach, dynamicforeachFromJSON artifact expansion,whenconditions,triggerRule(all_success/any_success), nativekind: execshell steps, warm same-role worker reuse, and silence stall watchdogs. - Coordinator wakeups (
notify.rs) deliver terse summaries tot*viaCore::pty_send(when idle) ora*viaCore::send.
- Supports static
- Quality Gates (
roles.rs,verify.rs,integrate.rs,review.rs,ai.rs):- Role Scope: Diffs touched workspace paths against an attempt baseline; rejects
readonlyedits and out-of-patternscoped_writeedits with422 role_scope_violation. - Verify Gates: Executes task
spec.verifyand Runverify(goal.autoRepair), storing artifact logs and tracking stagnant output hashes. - Worktrees: Creates isolated detached Git / AOSP
./bin/harnessworktrees and serializes merge-back under a per-run async mutex. - Adversarial Review: Generates immutable candidate patches (Full diff R1, Delta diff R2..Rn) inspected by a read-only
reviewerACP turn until approved ormaxRoundsexhausted.
- Role Scope: Diffs touched workspace paths against an attempt baseline; rejects
- Multi-Machine SSH Federation (
http.rs,remote.rs,mod.rs):- Local
h2(:7799) aggregates<machine>/<run_id>from connected SSH daemons, proxies<machine>/*and?on=<machine>API calls viadrove.http_proxy, relays SSE events via frameddrove.subscribestreams, and handles$/drove_open_webnotifications soh2 drove webinside SSH sessions opens the user’s local browser cleanly.
- Local