TRIGGER when: the operator explicitly approves the plan, or asks to
"delegate this", "run this plan", "execute the stories", or "parallelize"
the work. Writing or reading a plan is not approval. Runs the stories in .agro/tasks/<slug>/prd.json as
bounded workers in dependency waves. The active session verifies each result,
accepts it, and records it in prd.json.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Delegate?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/mifunedev-delegate)
---
name: delegate
description: |
TRIGGER when: the operator explicitly approves the plan, or asks to
"delegate this", "run this plan", "execute the stories", or "parallelize"
the work. Writing or reading a plan is not approval. Runs the stories in .agro/tasks/<slug>/prd.json as
bounded workers in dependency waves. The active session verifies each result,
accepts it, and records it in prd.json.
argument-hint: "[<task-slug> | --plan <path>] [--dry-run]"
---
# Delegate
## Task lifecycle
An explicit operator approval of the plan authorizes the full run: the issue,
`prd.json`, the draft PR, all waves, the review, Close, the push, and
`gh pr ready`. The
merge stays with the operator. This section is the only copy of the approval
scope.
After the draft PR steps check out the task branch in the task checkout, and
before the first wave, run `bash .agro/skills/delegate/scripts/next.sh --claim`
from that checkout as its own command. The claim applies to the checkout of
the current directory, not to the path of the script. The claim prints the
current state and records this session and the current branch as the owner of
the checkout. The Stop hook blocks and escalates only for the session that ran
the claim in that checkout, on that branch. The hook allows the stop for each
other session. After a branch switch, run the claim again. A claim by another session moves the
ownership and resets the block counter.
Run `bash .agro/skills/delegate/scripts/next.sh` to print the current state.
Do the next action of that state, then run the script again. The run stops
only at `done`, `blocked`, or `none`. If an action needs live spend, set
`blocked` in `prd.json` and ask the operator. To ask the operator a question
during the run, set `blocked` in `prd.json` with the question as the reason.
The Stop hook allows the stop at `blocked`.
The tracker conversion turns the review step on by default: it writes
`"review": true` in `prd.json`. The conversion flag `--no-review` turns the
review step off: it writes `"review": false`. When `review` is absent or
`false`, `next.sh` skips the review step. Without the review step, `next.sh` prints
the states in this order: `story`, `close`, `push`, `ci`, `ready`, `done`. When
`review` is `true`, `next.sh` prints the states in this order: `story`, `push`,
`ci`, `review`, `close`, `push`, `ci`, `ready`, `done`. In both orders,
`ci-red` can follow `ci`. The state table lists the states in the review order.
```text
OPERATOR ADVISOR (/delegate, next.sh loop) WORKERS / CI
/prd ──▶ prd.md
◆ APPROVE ◆ ─▶ prd §7: issue #N → prd.json → DRAFT PR
story <id> ──dispatch──────────────────────────▶ worker
▲ verify → passes:true ◀──report────────────┘
└─ next story / wave
┌─ review: true (set at conversion) ───────────────┐
│ push → ci ──ci-red──▶ reopen owning story │
│ review: harness review → repair → reviewed=<sha> │
└──────────────────────────────────────────────────┘
close (retro): checks + evidence + ## Lessons
push → ci ──ci-red──▶ reopen owning story
│ green
ready: gh pr ready
◆ MERGE ◆ ◀─── done
```
| State | Next action | Exit condition | Owner |
|---|---|---|---|
| `story <id>` | Dispatch, verify, and accept the story (§ Waves, § Acceptance) | The story has `passes: true` | Advisor; a worker implements |
| `push` | Push the task branch | The remote task branch head equals local `HEAD` | Advisor |
| `ci` | Wait for CI with `/ci-status` | No PR check is pending | Advisor |
| `ci-red` | Reopen the story that owns the failing path as a bounded repair (§ Acceptance) | The reopened story has `passes: true` | Advisor; the same worker repairs |
| `review` | Run the code review, repair each finding, and write `reviewed` (§ Review) | `prd.json` has a non-empty `reviewed`, the value is a hex commit SHA, and no task-branch commit after that SHA changes a file outside `.agro/tasks`. Merges of the base branch do not count | Advisor; a worker repairs |
| `close` | Write `## Lessons` and fill the PR evidence sections (§ Close) | `prd.md` has a non-empty `## Lessons` section | Advisor |
| `ready` | Run `gh pr ready` (`/git` § Ready for review) | The PR is not a draft | Advisor |
| `done` | Stop | The run ends | Operator merges |
| `blocked` | Stop. Write the reason in the `blocked` field of `prd.json`. Run `/escalate` one time | The operator clears `blocked` | Operator |
| `none` | Stop. No task is bound to this branch | The run ends | Operator |
## The advisor/worker pattern
The **advisor** is the active session. It decides, assigns bounded stories,
verifies each result, and accepts it. The advisor alone writes `prd.json`:
`passes`, `commit`, and `notes`.
A **worker** is a bounded execution context, not a project role. A worker
implements one assignment inside its owned paths. It reports each criterion as
executed or reasoned. A worker never accepts its own result.
Use a worker when the story is self-contained and gains from parallelism,
isolated context, or restricted tools. Keep the work in the active session when
phases share substantial context or need iterative refinement.
| Assign to a worker | Keep in the active session |
|---|---|
| Tracked implementation edits: code, tests, docs, repair | Goal interpretation, decomposition, verification, acceptance |
| Coupled implementation, in one continuing worker | Reconciliation of results that share substantial context |
| Verbose disposable output: logs, search dumps, test runs | Iterative refinement against operator feedback |
| Disjoint owned paths with no shared mutable state | `prd.json`, `prd.md`, and the PR body |
## Input
Resolve the input from the arguments:
1. `<task-slug>`: read `.agro/tasks/<slug>/prd.json`.
2. `--plan <path>`: read the `prd.json` at `<path>`.
3. A free-text plan with no `prd.json`: run `/prd` first to make the tracker.
To skip the tracker, dispatch once with no saved state. Tell the operator
which path you took.
4. No input: print the usage line from `argument-hint`, then stop.
Each story in `userStories` is one task:
- `priority` sets the order. A lower number runs first.
- `dependsOn` is optional. It lists the story IDs that must pass first.
- `acceptanceCriteria` are the checks that the advisor runs.
- `files` are the owned write paths of the worker.
The advisor skips each story with `passes: true`.
## Dispatch record
Write one record for each story before dispatch. Keep only these fields:
| Field | Value |
|---|---|
| Story ID | The `id` from `prd.json` |
| Dependencies | The `dependsOn` IDs, or none |
| Read scope | The files and directories that the worker reads |
| Owned write paths | The `files` of the story; the worker edits nothing else |
| Deliverable | One commit on the task branch, or on the branch of the story's worktree when `/worktrees` § DECIDE answers worktree |
| Verification | The commands and checks from `acceptanceCriteria`, with expected results. The location for acceptance is the main checkout (§ Acceptance) |
| Execution directory | The absolute path of the task checkout, or of the story's worktree when `/worktrees` § DECIDE answers worktree |
| Execution location | `host` or `sandbox`. When `/etc/agro/sandbox` exists, or `/.dockerenv` exists and `SANDBOX_NAME` is not empty, the advisor writes `sandbox` |
| Model and reason | The requested model, or the provider default, and the reason |
When the execution location is `host` and `agro --help` lists `agro run`, run
the baseline, the worker verification, and the acceptance commands as
`agro run -- <command>`. Without `agro run`, or in a sandbox, run these commands
directly.
## Waves
1. Before the first wave, run the test and type-check commands of the repository
on the task branch, in the command form of § Dispatch record. Record each
failing test in `.agro/tasks/<slug>/evidence/baseline.md`.
2. Put each story in a wave. A story is ready when every `dependsOn` story has
`passes: true`.
3. Before dispatch, run [`/worktrees` § DECIDE](../worktrees/SKILL.md) for each
story.
4. Stories with overlapping `files` run in sequence.
5. Give each worktree story one worker in one worktree, at most 5 workers per
wave. Branch each worktree from the current task branch. Before dispatch,
when a worktree has a `package.json`, run `pnpm install --frozen-lockfile` in
that worktree.
6. Run these workers in parallel, except as item 4 requires. The main checkout
gets no worker edits while these workers run.
7. Inspect each commit and bring it onto the task branch in the main checkout.
When a worktree holds the task branch, bring the commit onto the task branch
in that worktree. A conflict reopens the story (§ Repair).
8. Verify each of these stories in the main checkout (§ Acceptance).
9. Send a failed story to § Repair. Keep each worktree until the advisor accepts
every worktree story of the wave, because the same worker repairs the story.
Consolidation alone does not allow removal.
10. When the advisor accepts the last worktree story of the wave, remove the
worktrees and worker branches of the wave (§ Integration).
11. Run each story with the answer main checkout in the task checkout on the task
branch, one at a time. Verify and accept each story before the next story
starts.
12. Branch the worktrees of the next wave from the updated task branch.
13. Workers stay flat. Workers never spawn workers.
14. The advisor never sends parallel shell calls that change the working directory.
Each parallel call uses absolute paths, for example `git -C <path>`.
15. Wait for worker commits in a foreground call. The Stop hook blocks a stop
by the claiming session while the story is open, and the hook escalates
after 3 blocks.
16. Follow [`/supervisor` § Harness folder and operator
rules](../supervisor/SKILL.md#harness-folder-and-operator-rules). The
operator rule applies on every machine. The harness folder rule applies to
the supervisor and the advisors it spawns.
A single-story wave runs in the main checkout unless § DECIDE answers worktree.
## Worker brief
Give each worker the dispatch record, the exclusions, the baseline failures, and
these rules:
- A baseline failure does not fail a criterion of the worker.
- Edit only the owned write paths. Obey the exclusions.
- Work only in the execution directory.
- In a sandbox, never run `agro sandbox`, `agro destroy`, `agro stop`,
`agro restart`, or raw `docker compose` for the current project.
- Remove a worktree only with
`bash .agro/scripts/git-maintenance.sh worktree-remove <path>`. Delete a
branch only with `bash .agro/scripts/git-maintenance.sh branch-delete <branch>`.
[`/git`](../git/SKILL.md) lists the other maintenance commands.
- Stop each process that you start before you report. Report each process that
you cannot stop. Never stop a process that you did not start.
- Report each criterion as one of these:
- **executed**: the command and exit status.
- **reasoned**: a one-line argument.
- Commit on the branch of the execution directory. Never push.
- Never write `prd.json`.
- Use no bare `git stash` or `git stash pop`. The stash stack is shared with
other sessions.
- Never bypass a hook. A rerun of a blocked command through a script file, a
heredoc, or another tool is a bypass. So is a script on stdin, `docker exec`,
remote exec, or base64 text that reaches the blocked effect. You may use a
heredoc or file that only carries prose when the guard names it as the remedy.
Report a blocked action as `BLOCKED`.
- Create a local test database only from the credential-free URL that the
repository documents. Never read a database URL or password from the
environment, a container, or an env file. Without a credential-free route,
report the check as `BLOCKED`.
## Acceptance
A worker report is not acceptance. A worktree exists for isolated editing only.
A worker in a worktree can run checks for its own report, but that result is not
acceptance. For each story, the advisor does these steps:
1. Inspect the worker commit.
2. If the story used a worktree, bring the commit onto the task branch (§ Waves).
3. In the main checkout, on the integrated task branch, run
`pnpm install --frozen-lockfile` when the checkout has a `package.json`. Then
rerun the verification in the command form of § Dispatch record. When a
worktree holds the task branch, use § Verify when a worktree holds the task
branch.
4. Write `passes: true`, `commit`, and `notes` in `prd.json`. In `notes`,
mark each criterion executed or reasoned.
### Verify when a worktree holds the task branch
When `/worktrees` § DECIDE sent the whole task to a worktree, the main checkout
cannot check out the task branch. Do these steps from the main checkout:
1. Record the current branch with `git branch --show-current`.
2. Run `git status --porcelain --untracked-files=no`. If the command prints a
change, use `/git` § Isolating in-flight work or ask the operator.
3. Run `git switch --detach <task-branch-head>`.
4. Run `pnpm install --frozen-lockfile` when the checkout has a `package.json`.
Then run the verification.
5. Switch the main checkout back to the recorded branch.
6. If `pnpm-lock.yaml` differs between the two commits, run
`pnpm install --frozen-lockfile` again.
### Repair
A failed story check, a red CI check (`ci-red`), or a review finding
(§ Review) starts a repair. The advisor
reopens the story whose `files` hold the failing path: write `passes: false`
and add 1 to `rounds`. When `review` is `true`, a task-branch commit after the
`reviewed` SHA that changes a file outside `.agro/tasks` sends the task back
to `review`. Merges of the base branch do not count. The same worker repairs the story as a bounded repair.
The advisor does not repair. Dependents of a reopened story wait. Before a repair
in a worktree, the worker merges the current task branch into the worker branch.
The advisor writes `blocked` in `prd.json` and runs `/escalate` one time in
each of these cases:
- `rounds` is greater than 2.
- A round does not decrease the set of failed checks.
- No story owns the path of a failed story check or a red CI check.
- `/ci-status` reports `NO-RUN` or `TIMEOUT`.
## Integration
After acceptance, do these steps on the task branch:
1. Commit `prd.json` with the accepted story. Do not push it. `/git` § Draft PR
for a task names the push rule.
2. Tick the story in the PR `## Stories` checklist.
3. When the advisor accepts the last worktree story of the wave, remove the
worktrees and worker branches of the wave. Use the git maintenance shim that
`/git` names.
## Resume
There is no separate ledger. `prd.json` holds the state.
1. Run `bash .agro/skills/delegate/scripts/next.sh --claim` again before you
continue in a new session, after `/clear` or another change of session ID,
and when a task reopens after `done`.
2. Read `prd.json`.
3. Take the next story with `passes: false` whose dependencies passed.
4. Re-verify the stories it builds on.
5. Continue from **Waves**.
## Model policy
- Follow explicit operator selections and exclusions of models.
- Otherwise, choose a model for each story. Record the reason in the dispatch
record.
- Never substitute a model silently.
- A required control that is unavailable blocks the story. Ask the operator.
Provider defaults live in provider settings. For Claude Code, the default is
`CLAUDE_CODE_SUBAGENT_MODEL` in the `env` object of `.claude/settings.json`.
A per-dispatch model overrides the default.
## Review
`next.sh` prints `review` only when `prd.json` has `"review": true`. At
`review`, do these steps on the task branch:
1. Review the task PR. At `review`, `HEAD` equals the upstream, so a review of
the local diff is empty. In Claude Code, run `/code-review <pr>` with the
`pr` number from `prd.json`, or review the diff `<base>...HEAD`. In Codex,
Pi, or another harness, pick an option from the "Compare ways to get a
review" table at `https://code.claude.com/docs/en/code-review`. That page
is the reference for the review options.
2. Repair each finding with a required fix per § Repair. After a reopened
story, `next.sh` prints these states in order: `story`, `push`, `ci`,
`review`.
3. For a finding in a path with no owning story, apply § Close step 3: fold
the finding into the PR only under the conditions of that step. Otherwise,
propose an issue, or drop the finding with the reason. This finding does
not block the task.
4. When a review pass leaves no finding to repair, write the SHA of the
reviewed commit to `reviewed` in `prd.json`.
Close runs after `review` and writes the review findings to `## Lessons`
(§ Close step 3). When `## Lessons` already has content at a review pass, add
the findings of that pass to the same `## Lessons` section.
The managed Code Review service skips draft pull requests. The PR is a draft
at `review`, so the advisor does not wait for that service.
## Close
When `review` is `true`, start Close after `review`. When every story has
`passes: true`, do these steps:
1. In the main checkout, validate the integrated result with the checks of the
repository: lint, typecheck, test, and build. Record each exit status. When a
worktree holds the task branch, use § Acceptance § Verify when a worktree
holds the task branch.
2. List each task-level criterion from `prd.md` with its evidence. The
evidence must match the exact subject that the criterion names, for example
a job type, a command, or a file. When the evidence covers a different
subject, mark the criterion `unmet`. When any criterion is `unmet`, do not
report the task as done.
3. Write or extend `## Lessons` at the end of `prd.md`. Keep one
`## Lessons` section. Give each lesson a claim,
evidence, and exactly one outcome:
- fixed in this PR;
- issue #N; or
- dropped, with the reason.
When `review` is `true`, include each review finding in `## Lessons`.
Fold a finding into the PR only when one of these conditions is true:
its fix is in a file that the PR already changes and the PR caused or
exposed the finding, or the finding breaks the chain in use. Propose an
issue only for a correctness or security risk outside the PR, one issue
for each defect surface. If an open issue already covers the surface,
propose a comment on that issue. Drop every other finding with its
reason, including test flakes, tooling friction, judgment and process
observations, and findings that a test already catches. When the
repository has 10 or more open issues labeled `follow-up`, propose a
new issue only with the open follow-up it replaces. List the proposed
issues in the final report. Do not wait for an answer. Continue Close.
Create an issue only after the operator approves it. Label each approved
issue `follow-up`.
"None" is a valid body.
4. Fill the PR evidence sections from the `notes` in `prd.json`.
5. Fill the PR `## Manual review` section from the evidence of the last story.
Use the shape of [`.agro/skills/git/references/manual-review.md`](../git/references/manual-review.md).
Write only the expected results that the evidence observed.
6. Continue with the "Ready for review" step of `/git`.
## Dry run
With `--dry-run`, print the waves and the dispatch records. Write nothing.
The dry run dispatches nothing.