---
model: sonnet
---

# /tas-orchestrate $ARGUMENTS

Role: Tech Lead — Orchestrator
Execute the project master plan by spawning `software-engineer` agents per Feature in stage/track order. Blocking stages complete before next stage starts. Parallel stages batch by `max_parallel`. Tracks run concurrently across stacks. Supports resume — skips `done` Features on restart.

`$ARGUMENTS` is optional. If provided, must be a track name (e.g., `service`) to execute only that track.
`--autonomous=true|false` flag overrides `autonomy_mode` from `tas.yaml` for this run.

**Scope:** Execution coordination only — reads plan, spawns agents, tracks status.
**Out of scope:** Writing Features, writing Technical Plans, coding.

## Always / Ask / Never

| | Action |
|---|---|
| **Always** | Read `project-status.yaml` on start to skip `done` Features — never re-run completed work |
| **Always** | Show execution queue and ask for confirmation before spawning agents (manual mode only) |
| **Always** | In autonomous mode: skip confirmation, auto-spawn, report at end |
| **Always** | Batch parallel stages by `max_parallel` from `tas.yaml` (default: 3) |
| **Always** | Update `project-status.yaml` after each Feature completes |
| **Always** | Pause a blocked/errored track — continue other tracks |
| **Never** | Spawn next stage until all Features in current stage are `done` |
| **Never** | Re-run a Feature with status `done` or `skipped` |

## Prerequisites
- `docs/master-plan.md` exists (run `/tas-master-plan` first if missing)
- `project-status.yaml` has `master_plan` key

## Steps

**Step 1 — Load plan + current status**
- Read `docs/master-plan.md` — parse YAML block under `## Execution Plan`
- Read `project-status.yaml` — read `master_plan.tracks` for all Feature statuses
- Read `tas.yaml` → `workflow.develop.orchestration.max_parallel` (default: `3` if absent)
- Resolve autonomy mode (CLI flag wins over yaml):
  1. Parse `--autonomous=true|false` from `$ARGUMENTS`
  2. If absent → read `autonomy_mode` from `tas.yaml` (`manual` | `full`, default `manual`)
  3. `autonomous = true` iff CLI `true` OR (CLI absent AND `autonomy_mode: full`)
- Update `project-status.yaml`: `master_plan.status: in_progress`
- If `$ARGUMENTS` contains a track name → filter to that track only; otherwise run all tracks

**Step 2 — Build execution queue**

For each track (in parallel across tracks):
1. Skip Features already `done` or `skipped`
2. Find current stage (lowest stage number where not all Features are `done`)
3. Check blocking constraint: stage N Features only queue if all stage N-1 Features are `done`
4. Check cross-track `depends_on`: Feature only queues if all listed dependency Features are `done`
5. Note stage type (`blocking` / `sequential` / `parallel`)

Show queue:
```
Execution queue:

Track: service
  Stage 1 [blocking] → Feature-001 scaffold-service
Track: web
  Stage 1 [blocking] → Feature-002 scaffold-web

(Subsequent stages queue as each stage completes per track)
```

**Manual mode** (`autonomous = false`): show queue, ask `Proceed? (yes / abort)`, wait for user.
**Autonomous mode** (`autonomous = true`): show queue, skip confirmation, proceed immediately to Step 3.

**Step 3 — Execute features**

Spawn `software-engineer` agents. Pass feature context in prompt.

For each queued Feature:
```
Agent({
  subagent_type: "software-engineer",
  description: "Feature-{ID} {slug}",
  prompt: "feature_id: {Feature-ID}
slug: {slug}
feature_file: {feature_file_path}
technical_file: {technical_file_path}"
})
```

**Parallel stage batching:**
- Do NOT spawn all Features in a parallel stage at once
- Split stage Features into batches of `max_parallel`
- Batch 1: spawn `max_parallel` agents simultaneously (single message, multiple Agent calls)
- Wait for all in batch → update status (Step 4) → spawn next batch
- Only advance to next stage after all batches in current stage are done

Example — `max_parallel: 3`, 7 Features in parallel stage:
```
Batch 1: Feature-007, Feature-008, Feature-009  → wait → update
Batch 2: Feature-010, Feature-011, Feature-012  → wait → update
Batch 3: Feature-013                            → wait → update
→ stage done → queue next stage
```

Sequential stages: always spawn one Feature at a time regardless of `max_parallel`.

**Step 4 — Process results + update status**

After each agent returns, parse result prefix:

- `DONE: Feature-NNN` →
  - Update `project-status.yaml`:
    - `master_plan.tracks.{track}.stages.{N}.features.Feature-NNN: done`
    - `features.Feature-NNN.status: Done`
    - `features.Feature-NNN.done_date: {today}`
  - If all Features in stage `done` → set stage status: `done` → queue next stage

- `BLOCKED: Feature-NNN — {reason}` →
  - Update: `master_plan.tracks.{track}.stages.{N}.features.Feature-NNN: blocked`
  - Log reason, pause track, continue other tracks

- `ERROR: Feature-NNN — {reason}` →
  - Update: `master_plan.tracks.{track}.stages.{N}.features.Feature-NNN: error`
  - Log reason, pause track, continue other tracks

Always update: `master_plan.last_updated: {today}`

**Step 5 — Continue until all tracks exhausted**

Repeat Steps 3–4 until no Features remain to queue across all active tracks.

**Step 6 — Final report**

When all tracks complete:
- If all `done` → update `project-status.yaml`: `master_plan.status: completed`
- If any `blocked`/`error` → `master_plan.status: in_progress`

Output:
```
Orchestration complete.

✅ Done (N):    Feature-001, Feature-002, Feature-003
⚠️  Blocked (N): Feature-007 — auth service not responding
❌ Error (N):   Feature-008 — compilation failed in payment module

project-status.yaml updated.
Blocked/errored features require manual fix, then re-run /tas-orchestrate to resume.
```

---

## Resume behavior

On re-run when `master_plan.status: in_progress`:
1. Read current statuses from `project-status.yaml`
2. Skip all `done` Features
3. Features with `in_progress`: re-spawn (previous agent may have died)
4. Features with `blocked` or `error`: skip unless manually cleared in `project-status.yaml` first
5. Show updated queue → manual: confirm → continue | autonomous: auto-continue

## Final Step — Token Log

Follow `.tas/rules/common/token-logging.md`: write AI Usage Log to `docs/master-plan.md`.
