# giuseppecrj/pi-herdr-agents architecture

> Architecture diagram of the GitHub repository giuseppecrj/pi-herdr-agents, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/giuseppecrj/pi-herdr-agents
- Repository: https://github.com/giuseppecrj/pi-herdr-agents

## Overview

Pi Herdr Agents adds asynchronous child-agent delegation to Pi, running child Pi processes in legacy Herdr panes or Herdr Core terminals. The main workflow is parent delegation, surface selection and resource acquisition, child execution, live supervision, then result delivery and presentation. The README also documents managed worktrees, conversation handoff, persistent specialists, and an optional sidebar plugin. The excerpts show extension wiring and parts of both surface implementations; several Maestro runtime details are documented but not present in the sampled source.

Main entry points: [`pi-extension/subagents`](https://github.com/giuseppecrj/pi-herdr-agents/tree/main/pi-extension/subagents) (Subagent engine), [`maestro/surfaces/herdr/herdr-surface-provider.ts`](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-surface-provider.ts) (Legacy surface provider), [`maestro/surfaces/herdr/herdr-core-surface-provider.ts`](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-core-surface-provider.ts) (Core surface provider), [`pi-extension/subagents/index.ts`](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/pi-extension/subagents/index.ts) (Extension entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["Pi extension"]
  node_entry["Extension entry<br/>[index.ts]"]
  node_binding["Host surface binding<br/>[host-surface.ts]"]
  node_engine["Subagent engine"]
  node_child["Child Pi process<br/>[subagent-done.ts]"]
  node_specialists["Persistent specialists"]
end

subgraph group_legacy["Legacy Herdr"]
  node_legacy_provider["Legacy surface provider"]
  node_legacy_runtime["Legacy orchestration<br/>[herdr.ts]"]
  node_pane["Pane inspection<br/>[herdr-pane.ts]"]
  node_cli["Herdr CLI<br/>[herdr-cli.ts]"]
  node_terminal["Terminal support<br/>[terminal.ts]"]
  node_worktrees["Managed worktrees"]
  node_handoff["Conversation handoff"]
end

subgraph group_core["Herdr Core"]
  node_core_provider["Core surface provider"]
  node_core_protocol["Core protocol"]
  node_core_socket["Core socket<br/>[herdr-socket.ts]"]
end

subgraph group_presentation["Supervision and display"]
  node_widgets["Status widgets<br/>[widgets.ts]"]
  node_renderers["Message renderers<br/>[renderers.ts]"]
  node_tool_renderers["Tool renderers<br/>[tool-renderers.ts]"]
end

subgraph group_integrations["Optional integrations"]
  node_sidebar["Sidebar focus plugin<br/>[sidebar.mjs]"]
end

node_parent(("Pi parent session"))
node_herdr["Herdr environment"]
node_core_terminal["Core terminal"]
node_sidebar_user(("Herdr user"))

node_parent -->|"delegates to"| node_entry
node_entry -->|"configures"| node_binding
node_entry -->|"creates"| node_engine
node_binding -->|"selects provider"| node_legacy_provider
node_binding -->|"selects provider"| node_core_provider
node_engine -->|"launches child"| node_child
node_legacy_provider -->|"delegates to"| node_legacy_runtime
node_legacy_provider -->|"inspects panes"| node_pane
node_legacy_provider -->|"invokes"| node_cli
node_legacy_provider -->|"uses"| node_terminal
node_legacy_runtime -->|"runs commands"| node_cli
node_pane -->|"runs commands"| node_cli
node_legacy_runtime -->|"provisions panes"| node_herdr
node_core_provider -->|"uses protocol"| node_core_protocol
node_core_provider -.->|"communicates through"| node_core_socket
node_core_provider -->|"manages terminals"| node_core_terminal
node_core_provider -->|"runs child"| node_child
node_engine -->|"creates"| node_widgets
node_engine -->|"registers"| node_renderers
node_engine -->|"registers"| node_tool_renderers
node_child -->|"returns result"| node_parent
node_parent -->|"manages"| node_worktrees
node_parent -->|"hands off"| node_handoff
node_parent -->|"runs sequential tasks"| node_specialists
node_sidebar_user -.->|"enables focus"| node_sidebar
node_sidebar -->|"hides marked panes"| node_herdr

click node_entry "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/pi-extension/subagents/index.ts"
click node_binding "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/pi-extension/subagents/host-surface.ts"
click node_engine "https://github.com/giuseppecrj/pi-herdr-agents/tree/main/pi-extension/subagents"
click node_child "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/adapters/pi/child/subagent-done.ts"
click node_legacy_provider "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-surface-provider.ts"
click node_legacy_runtime "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr.ts"
click node_pane "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-pane.ts"
click node_cli "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-cli.ts"
click node_terminal "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/terminal.ts"
click node_core_provider "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-core-surface-provider.ts"
click node_core_protocol "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-core-protocol.ts"
click node_core_socket "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-socket.ts"
click node_widgets "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/pi-extension/subagents/widgets.ts"
click node_renderers "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/pi-extension/subagents/renderers.ts"
click node_tool_renderers "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/pi-extension/subagents/tool-renderers.ts"
click node_worktrees "https://github.com/giuseppecrj/pi-herdr-agents/tree/main/maestro/surfaces/herdr"
click node_handoff "https://github.com/giuseppecrj/pi-herdr-agents/tree/main/maestro/surfaces/herdr"
click node_specialists "https://github.com/giuseppecrj/pi-herdr-agents/tree/main/pi-extension/subagents"
click node_sidebar "https://github.com/giuseppecrj/pi-herdr-agents/blob/main/plugins/sidebar/sidebar.mjs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_binding,node_engine,node_child,node_specialists,node_sidebar_user toneBlue
class node_legacy_provider,node_legacy_runtime,node_pane,node_cli,node_terminal,node_worktrees,node_handoff toneAmber
class node_core_provider,node_core_protocol,node_core_socket toneMint
class node_widgets,node_renderers,node_tool_renderers toneRose
class node_sidebar,node_parent,node_herdr,node_core_terminal toneIndigo
```

## Components

### Pi extension

- [Extension entry](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/pi-extension/subagents/index.ts): `pi-extension/subagents/index.ts`
- [Host surface binding](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/pi-extension/subagents/host-surface.ts): `pi-extension/subagents/host-surface.ts`
- [Subagent engine](https://github.com/giuseppecrj/pi-herdr-agents/tree/main/pi-extension/subagents): `pi-extension/subagents`
- [Child Pi process](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/adapters/pi/child/subagent-done.ts): `maestro/adapters/pi/child/subagent-done.ts`
- [Persistent specialists](https://github.com/giuseppecrj/pi-herdr-agents/tree/main/pi-extension/subagents): `pi-extension/subagents`

### Legacy Herdr

- [Legacy surface provider](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-surface-provider.ts): `maestro/surfaces/herdr/herdr-surface-provider.ts`
- [Legacy orchestration](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr.ts): `maestro/surfaces/herdr/herdr.ts`
- [Pane inspection](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-pane.ts): `maestro/surfaces/herdr/herdr-pane.ts`
- [Herdr CLI](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-cli.ts): `maestro/surfaces/herdr/herdr-cli.ts`
- [Terminal support](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/terminal.ts): `maestro/surfaces/herdr/terminal.ts`
- [Managed worktrees](https://github.com/giuseppecrj/pi-herdr-agents/tree/main/maestro/surfaces/herdr): `maestro/surfaces/herdr`
- [Conversation handoff](https://github.com/giuseppecrj/pi-herdr-agents/tree/main/maestro/surfaces/herdr): `maestro/surfaces/herdr`

### Herdr Core

- [Core surface provider](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-core-surface-provider.ts): `maestro/surfaces/herdr/herdr-core-surface-provider.ts`
- [Core protocol](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-core-protocol.ts): `maestro/surfaces/herdr/herdr-core-protocol.ts`
- [Core socket](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/maestro/surfaces/herdr/herdr-socket.ts): `maestro/surfaces/herdr/herdr-socket.ts`

### Supervision and display

- [Status widgets](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/pi-extension/subagents/widgets.ts): `pi-extension/subagents/widgets.ts`
- [Message renderers](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/pi-extension/subagents/renderers.ts): `pi-extension/subagents/renderers.ts`
- [Tool renderers](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/pi-extension/subagents/tool-renderers.ts): `pi-extension/subagents/tool-renderers.ts`

### Optional integrations

- [Sidebar focus plugin](https://github.com/giuseppecrj/pi-herdr-agents/blob/main/plugins/sidebar/sidebar.mjs): `plugins/sidebar/sidebar.mjs`

### Other components

- **Pi parent session**
- **Herdr environment**
- **Core terminal**
- **Herdr user**

## Connections

- Pi parent session → Extension entry: delegates to (evidence: `README.md`)
- Extension entry → Host surface binding: configures (evidence: `pi-extension/subagents/index.ts`)
- Extension entry → Subagent engine: creates (evidence: `pi-extension/subagents/index.ts`)
- Host surface binding → Legacy surface provider: selects provider (evidence: `pi-extension/subagents/host-surface.ts`)
- Host surface binding → Core surface provider: selects provider (evidence: `pi-extension/subagents/host-surface.ts`)
- Subagent engine → Child Pi process: launches child (evidence: `pi-extension/subagents/index.ts`)
- Legacy surface provider → Legacy orchestration: delegates to (evidence: `maestro/surfaces/herdr/herdr-surface-provider.ts`)
- Legacy surface provider → Pane inspection: inspects panes (evidence: `maestro/surfaces/herdr/herdr-surface-provider.ts`)
- Legacy surface provider → Herdr CLI: invokes (evidence: `maestro/surfaces/herdr/herdr-surface-provider.ts`)
- Legacy surface provider → Terminal support: uses (evidence: `maestro/surfaces/herdr/herdr-surface-provider.ts`)
- Legacy orchestration → Herdr CLI: runs commands (evidence: `maestro/surfaces/herdr/herdr.ts`)
- Pane inspection → Herdr CLI: runs commands (evidence: `maestro/surfaces/herdr/herdr-pane.ts`)
- Legacy orchestration → Herdr environment: provisions panes (evidence: `README.md`)
- Core surface provider → Core protocol: uses protocol (evidence: `maestro/surfaces/herdr/herdr-core-surface-provider.ts`)
- Core surface provider → Core socket: communicates through
- Core surface provider → Core terminal: manages terminals (evidence: `maestro/surfaces/herdr/herdr-core-surface-provider.ts`)
- Core surface provider → Child Pi process: runs child (evidence: `README.md`)
- Subagent engine → Status widgets: creates (evidence: `pi-extension/subagents/index.ts`)
- Subagent engine → Message renderers: registers (evidence: `pi-extension/subagents/index.ts`)
- Subagent engine → Tool renderers: registers (evidence: `pi-extension/subagents/index.ts`)
- Child Pi process → Pi parent session: returns result (evidence: `README.md`)
- Pi parent session → Managed worktrees: manages (evidence: `README.md`)
- Pi parent session → Conversation handoff: hands off (evidence: `README.md`)
- Pi parent session → Persistent specialists: runs sequential tasks (evidence: `README.md`)
- Herdr user → Sidebar focus plugin: enables focus (evidence: `README.md`)
- Sidebar focus plugin → Herdr environment: hides marked panes (evidence: `README.md`)
