# amelnagdy/delegate-skills architecture

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

- Interactive diagram: https://gitdiagram.com/amelnagdy/delegate-skills
- Repository: https://github.com/amelnagdy/delegate-skills

## Overview

#### Purpose and Distribution
`delegate-skills` is a Skills CLI package for delegating coding tasks from an orchestrating agent to locally installed AI implementer CLIs. Its product boundary is a reviewed working-tree diff plus a normalized result report; relays never commit. Package installation and skill selection are documented in `README.md`; each installed skill is invoked by an orchestrator rather than through a central application binary.

#### Primary Entry Points
- Per-implementer instructions and CLI-specific policy live in `skills/*-delegate/SKILL.md`, e.g. `skills/codex-delegate/SKILL.md` and `skills/claude-delegate/SKILL.md`.
- Each implementer dispatches through its own Node relay, e.g. `skills/codex-delegate/scripts/relay.mjs` and `skills/warp-delegate/scripts/relay.mjs`.
- Fleet setup is a separate, non-dispatching entry point: `skills/delegate-setup/SKILL.md`.
- CI exercises relay behavior via `.github/workflows/relays.yml`.

#### Fleet Setup and Configuration Boundary
`delegate-setup` discovers installed implementer CLIs, proposes named lanes, obtains explicit approval, and writes global or project-scoped fleet configuration. It is intentionally isolated from task execution:
- Discovery/probing: `skills/delegate-setup/scripts/discover.mjs`
- Config validation, persistence, and overlays: `skills/delegate-setup/scripts/config.mjs`
- Lane resolution and wrong-implementer enforcement: `skills/delegate-setup/scripts/lane.mjs`
- Shared supported-implementer registry: `skills/delegate-setup/scripts/implementers.mjs`

Project lane configuration is approval/content-bound and fails closed when copied or edited without reapproval. A lane selects an implementer and optional dials; explicit relay flags override permitted lane dials.

#### Delegation Relay Contract
Every `*-delegate` relay has the same lifecycle: validate arguments and lane state, preflight the local CLI, provide a self-contained brief, launch the implementer in a target worktree, await/process output, inspect Git-visible changes, and atomically publish `result.json`. The uniform `delegate-relay.result.v1` result includes status, exit/signal information, implementer report, touched files, and session data where available.

Representative implementations are `skills/aider-delegate/scripts/relay.mjs`, `skills/claude-delegate/scripts/relay.mjs`, and `skills/zcode-delegate/scripts/relay.mjs`. Relays use Node 18+ built-ins, local `git`, and the selected installed CLI; they make no independent network, credential, or telemetry calls.

#### Implementer Adapters and Safety Policy
Each relay is an adapter for a distinct external CLI and translates the shared concepts—write mode, read-only mode, models/effort, resume, structured output, timeout, and process termination—to vendor-specific flags and event formats. Supported external runtimes include Claude Code, Codex, Cursor Agent, OpenCode, Aider, Cline, Copilot CLI, Warp, and others, represented as parallel skill directories such as `skills/cursor-delegate/`, `skills/opencode-delegate/`, and `skills/copilot-delegate/`.

Safety is necessarily adapter-specific: some CLIs provide sandboxes or plan modes, while others only offer best-effort/read-only tripwires or full local-tool access. The universal hard boundary is that the relay does not issue commits; the reviewer runs project gates and lands changes.

#### Operational Flow and Human Boundary
The orchestrator writes a bounded brief, invokes either a direct implementer skill or a lane, then polls/reads the relay result. The implementer operates in a real local working tree. The orchestrator/reviewer subsequently inspects the diff, runs repository-specific validation, and commits if acceptable. Reusable orchestration guidance is packaged beside each adapter, for example `skills/codex-delegate/references/dispatch-and-poll.md` and `skills/codex-delegate/references/review-and-land.md`.

#### Verification Architecture
The repository uses Node-based contract, parity, isolated-process, timeout, abort, and smoke tests around the relay contract and platform launch behavior. Shared harness infrastructure is in `test/harness/create-harness.mjs` and `test/harness/install-shim.mjs`; broad relay coverage is organized through `test/relay/index.mjs`, with cross-adapter parity in `test/relay-parity.mjs`. This test structure is central because duplicated adapter scripts must preserve a common observable contract despite incompatible vendor CLIs.

Main entry points: [`skills/codex-delegate/scripts/relay.mjs`](https://github.com/amelnagdy/delegate-skills/blob/master/skills/codex-delegate/scripts/relay.mjs) (Relay lifecycle), [`skills/delegate-setup/scripts/lane.mjs`](https://github.com/amelnagdy/delegate-skills/blob/master/skills/delegate-setup/scripts/lane.mjs) (Lane resolution), [`test/relay/index.mjs`](https://github.com/amelnagdy/delegate-skills/blob/master/test/relay/index.mjs) (Relay contract suite), [`skills/delegate-setup/SKILL.md`](https://github.com/amelnagdy/delegate-skills/blob/master/skills/delegate-setup/SKILL.md) (Setup skill)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Fleet setup"]
  node_setup_skill["Setup skill<br/>skill instructions<br/>[SKILL.md]"]
  node_discovery["CLI discovery<br/>Node module<br/>[discover.mjs]"]
  node_config[("Fleet config<br/>Node module<br/>[config.mjs]")]
  node_lanes["Lane resolution<br/>Node module<br/>[lane.mjs]"]
  node_registry["Implementer registry<br/>Node module<br/>[implementers.mjs]"]
end

subgraph group_relay["Delegation relays"]
  node_adapter_skills["Implementer skills<br/>skill instructions<br/>[SKILL.md]"]
  node_relay["Relay lifecycle<br/>Node relay<br/>[relay.mjs]"]
  node_adapter_variants["CLI adapter variants<br/>parallel relays<br/>[relay.mjs]"]
  node_dispatch_guidance["Dispatch guidance<br/>orchestration reference"]
  node_review_guidance["Review guidance<br/>review reference<br/>[review-and-land.md]"]
end

subgraph group_external["Local execution and review"]
  node_local_cli{{"Installed implementer CLI<br/>external local runtime"}}
  node_working_tree[("Target working tree<br/>Git worktree")]
  node_result["Normalized result<br/>delegate-relay.result.v1"]
  node_reviewer(("Reviewer and project gates<br/>human boundary"))
end

subgraph group_verification["Contract verification"]
  node_relay_tests["Relay contract suite<br/>Node tests<br/>[index.mjs]"]
  node_harness["Test harness<br/>test infrastructure<br/>[create-harness.mjs]"]
  node_parity_tests["Cross-adapter parity<br/>Node tests<br/>[relay-parity.mjs]"]
  node_ci["Relay CI<br/>GitHub Actions workflow<br/>[relays.yml]"]
end

node_orchestrator(("Orchestrator<br/>task caller"))

node_setup_skill -->|"discovers"| node_discovery
node_discovery -->|"matches"| node_registry
node_setup_skill -->|"writes after approval"| node_config
node_registry -->|"defines supported CLIs"| node_lanes
node_config -->|"provides approved lanes"| node_lanes
node_orchestrator -->|"may select lane"| node_lanes
node_orchestrator -->|"selects direct skill"| node_adapter_skills
node_dispatch_guidance -.->|"guides dispatch and polling"| node_orchestrator
node_adapter_skills -->|"dispatches"| node_relay
node_lanes -->|"resolves implementer and dials"| node_relay
node_adapter_variants -.->|"implements shared lifecycle"| node_relay
node_relay -->|"launches and controls"| node_local_cli
node_local_cli -->|"edits"| node_working_tree
node_relay -->|"inspects Git-visible changes"| node_working_tree
node_relay -->|"atomically publishes"| node_result
node_result -->|"reports outcome"| node_orchestrator
node_working_tree -->|"diff for inspection"| node_reviewer
node_review_guidance -.->|"guides review and landing"| node_reviewer
node_harness -->|"supports"| node_relay_tests
node_relay_tests -.->|"feeds shared cases"| node_parity_tests
node_parity_tests -.->|"verifies contract parity"| node_adapter_variants
node_ci -->|"runs"| node_relay_tests

click node_setup_skill "https://github.com/amelnagdy/delegate-skills/blob/master/skills/delegate-setup/SKILL.md"
click node_discovery "https://github.com/amelnagdy/delegate-skills/blob/master/skills/delegate-setup/scripts/discover.mjs"
click node_config "https://github.com/amelnagdy/delegate-skills/blob/master/skills/delegate-setup/scripts/config.mjs"
click node_lanes "https://github.com/amelnagdy/delegate-skills/blob/master/skills/delegate-setup/scripts/lane.mjs"
click node_registry "https://github.com/amelnagdy/delegate-skills/blob/master/skills/delegate-setup/scripts/implementers.mjs"
click node_adapter_skills "https://github.com/amelnagdy/delegate-skills/blob/master/skills/codex-delegate/SKILL.md"
click node_relay "https://github.com/amelnagdy/delegate-skills/blob/master/skills/codex-delegate/scripts/relay.mjs"
click node_adapter_variants "https://github.com/amelnagdy/delegate-skills/blob/master/skills/aider-delegate/scripts/relay.mjs"
click node_dispatch_guidance "https://github.com/amelnagdy/delegate-skills/blob/master/skills/codex-delegate/references/dispatch-and-poll.md"
click node_review_guidance "https://github.com/amelnagdy/delegate-skills/blob/master/skills/codex-delegate/references/review-and-land.md"
click node_relay_tests "https://github.com/amelnagdy/delegate-skills/blob/master/test/relay/index.mjs"
click node_harness "https://github.com/amelnagdy/delegate-skills/blob/master/test/harness/create-harness.mjs"
click node_parity_tests "https://github.com/amelnagdy/delegate-skills/blob/master/test/relay-parity.mjs"
click node_ci "https://github.com/amelnagdy/delegate-skills/blob/master/.github/workflows/relays.yml"

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_setup_skill,node_discovery,node_config,node_lanes,node_registry toneBlue
class node_adapter_skills,node_relay,node_adapter_variants,node_dispatch_guidance,node_review_guidance toneAmber
class node_local_cli,node_working_tree,node_result,node_reviewer toneMint
class node_relay_tests,node_harness,node_parity_tests,node_ci toneRose
class node_orchestrator toneNeutral
```

## Components

### Fleet setup

Separate configuration path; it does not dispatch tasks.

- [Setup skill](https://github.com/amelnagdy/delegate-skills/blob/master/skills/delegate-setup/SKILL.md): skill instructions · `skills/delegate-setup/SKILL.md`
- [CLI discovery](https://github.com/amelnagdy/delegate-skills/blob/master/skills/delegate-setup/scripts/discover.mjs): Node module · Probes locally installed implementer CLIs. · `skills/delegate-setup/scripts/discover.mjs`
- [Fleet config](https://github.com/amelnagdy/delegate-skills/blob/master/skills/delegate-setup/scripts/config.mjs): Node module · Validates, persists, and overlays approved fleet configuration. · `skills/delegate-setup/scripts/config.mjs`
- [Lane resolution](https://github.com/amelnagdy/delegate-skills/blob/master/skills/delegate-setup/scripts/lane.mjs): Node module · Resolves lanes and rejects the wrong implementer. · `skills/delegate-setup/scripts/lane.mjs`
- [Implementer registry](https://github.com/amelnagdy/delegate-skills/blob/master/skills/delegate-setup/scripts/implementers.mjs): Node module · `skills/delegate-setup/scripts/implementers.mjs`

### Delegation relays

Parallel adapter skills share one observable lifecycle.

- [Implementer skills](https://github.com/amelnagdy/delegate-skills/blob/master/skills/codex-delegate/SKILL.md): skill instructions · Per-CLI policy and dispatch guidance. · `skills/codex-delegate/SKILL.md`
- [Relay lifecycle](https://github.com/amelnagdy/delegate-skills/blob/master/skills/codex-delegate/scripts/relay.mjs): Node relay · Validates, preflights, launches, processes output, inspects Git, and publishes a normalized result. · `skills/codex-delegate/scripts/relay.mjs`
- [CLI adapter variants](https://github.com/amelnagdy/delegate-skills/blob/master/skills/aider-delegate/scripts/relay.mjs): parallel relays · Vendor-specific flag, event, safety, and termination translations preserve the shared contract. · `skills/aider-delegate/scripts/relay.mjs`
- [Dispatch guidance](https://github.com/amelnagdy/delegate-skills/blob/master/skills/codex-delegate/references/dispatch-and-poll.md): orchestration reference · `skills/codex-delegate/references/dispatch-and-poll.md`
- [Review guidance](https://github.com/amelnagdy/delegate-skills/blob/master/skills/codex-delegate/references/review-and-land.md): review reference · `skills/codex-delegate/references/review-and-land.md`

### Local execution and review

- **Installed implementer CLI**: external local runtime · Claude, Codex, Cursor, OpenCode, Aider, Copilot, Warp, or another supported CLI.
- **Target working tree**: Git worktree · Implementer modifies local files; relays never commit.
- **Normalized result**: delegate-relay.result.v1 · Atomically published status, process outcome, report, changed files, and session data.
- **Reviewer and project gates**: human boundary · Inspects the diff, runs repository validation, and decides whether to commit.

### Contract verification

Tests enforce parity across duplicated adapter relays.

- [Relay contract suite](https://github.com/amelnagdy/delegate-skills/blob/master/test/relay/index.mjs): Node tests · Exercises contract, isolated-process, timeout, abort, and smoke behavior. · `test/relay/index.mjs`
- [Test harness](https://github.com/amelnagdy/delegate-skills/blob/master/test/harness/create-harness.mjs): test infrastructure · `test/harness/create-harness.mjs`
- [Cross-adapter parity](https://github.com/amelnagdy/delegate-skills/blob/master/test/relay-parity.mjs): Node tests · Checks that incompatible CLIs retain a common observable relay contract. · `test/relay-parity.mjs`
- [Relay CI](https://github.com/amelnagdy/delegate-skills/blob/master/.github/workflows/relays.yml): GitHub Actions workflow · `.github/workflows/relays.yml`

### Other components

- **Orchestrator**: task caller · Writes a bounded brief and invokes a direct skill or lane.

## Connections

- Setup skill → CLI discovery: discovers
- CLI discovery → Implementer registry: matches
- Setup skill → Fleet config: writes after approval
- Implementer registry → Lane resolution: defines supported CLIs
- Fleet config → Lane resolution: provides approved lanes
- Orchestrator → Lane resolution: may select lane
- Orchestrator → Implementer skills: selects direct skill
- Dispatch guidance → Orchestrator: guides dispatch and polling
- Implementer skills → Relay lifecycle: dispatches
- Lane resolution → Relay lifecycle: resolves implementer and dials
- CLI adapter variants → Relay lifecycle: implements shared lifecycle
- Relay lifecycle → Installed implementer CLI: launches and controls
- Installed implementer CLI → Target working tree: edits
- Relay lifecycle → Target working tree: inspects Git-visible changes
- Relay lifecycle → Normalized result: atomically publishes
- Normalized result → Orchestrator: reports outcome
- Target working tree → Reviewer and project gates: diff for inspection
- Review guidance → Reviewer and project gates: guides review and landing
- Test harness → Relay contract suite: supports
- Relay contract suite → Cross-adapter parity: feeds shared cases
- Cross-adapter parity → CLI adapter variants: verifies contract parity
- Relay CI → Relay contract suite: runs
