--- name: start description: Use when starting work on any task, when the user mentions metaswarm, or when the user wants to begin tracked development work auto_activate: true triggers: - "work on issue" - "start issue" - "start task" - "use metaswarm" - "@metaswarm" - "agent-ready label" --- # BEADS Multi-Agent Orchestration Skill This skill coordinates a swarm of specialized AI agents to autonomously handle GitHub Issues from creation to merged PR. --- ## Quick Start ### Start Work on a GitHub Issue ```bash # User triggers via any of: @beads start #123 /beads-start 123 ``` ### Check BEADS Status ```bash bd ready # Show tasks ready to work bd list # Show all tasks bd stats # Show project statistics bd doctor # Check system health ``` --- ## Agent Roster | Agent | Role | Spawned When | | ------------------------- | ------------------------------ | ---------------------------------- | | **Issue Orchestrator** | Main coordinator per Issue | Issue receives `agent-ready` label | | **Researcher Agent** | Codebase exploration | Orchestrator creates research task | | **Architect Agent** | Implementation planning | Research complete | | **Product Manager Agent** | Use case & user benefit review | Design review gate (parallel) | | **Designer Agent** | UX/API design review | Design review gate (parallel) | | **Security Design Agent** | Security threat modeling | Design review gate (parallel) | | **CTO Agent** | TDD readiness & plan review | Design review gate (parallel) | | **UX Reviewer Agent** | User flows, UI states, integration wiring | Design review gate (parallel) | | **Coder Agent** | TDD implementation | Design review gate approved | | **Adversarial Reviewer** | Internal code review | Implementation complete | | **Security Auditor** | Security review (code) | Implementation complete | | **Release Engineer Agent** | Safe delivery from merge through production | QA approves PR, PR reaches merge readiness | | **PR Shepherd** | PR lifecycle management | PR created | See `./agents/` directory for detailed agent definitions. --- ## Design Review Gate (NEW) For project-sized features (brainstorming sized the work as a project and committed its design doc; see [`./guides/workflow-enforcement.md`](./guides/workflow-enforcement.md)), an automatic **Design Review Gate** ensures quality before implementation: ``` Project-Sized Design Doc Committed │ ▼ ┌─────────────────────────────────────────────────┐ │ DESIGN REVIEW GATE │ │ │ │ Spawns 6 reviewers in PARALLEL: │ │ • PM Agent (use cases, user benefit) │ │ • Architect Agent (technical architecture) │ │ • Designer Agent (UX/API design) │ │ • Security Design Agent (threat model) │ │ • UX Reviewer (user flows, integration WUs) │ │ • CTO Agent (TDD readiness) │ │ │ │ ALL SIX must approve to proceed │ └─────────────────────────────────────────────────┘ │ ├── Any NEEDS_REVISION? → Iterate on design (severity-gated, cap 10 rounds) │ ALL APPROVED │ ▼ Create BEADS Epic → Begin Implementation ``` ### Triggering the Design Review Gate Load the `brainstorming-extension` skill at the start of brainstorming, not only after the commit: its assumption ledger, confirmation rule and Common misreadings checklist apply to every brainstorming session regardless of size, before any design is presented or committed. The gate is automatically triggered when brainstorming writes and commits a project-sized design doc (see [`./guides/workflow-enforcement.md`](./guides/workflow-enforcement.md)): - A project-sized design doc is committed to `docs/plans/*-design.md` or `docs/superpowers/specs/*-design.md` - User runs `/review-design ` ### Review Criteria by Agent | Agent | Focus Areas | | --------------- | ---------------------------------------------------------- | | Product Manager | Use case clarity, user benefits, scope, success metrics | | Architect | Service architecture, dependencies, patterns, integration | | Designer | API design, UX flows, developer experience, consistency | | Security Design | Threat modeling, auth/authz, data protection, OWASP Top 10 | | UX Reviewer | User flows, text wireframes, integration WUs, empty/error states | | CTO | TDD readiness, codebase alignment, completeness, risks | ### Iteration Protocol - **Severity-gated iteration** (cap 10 rounds; see `./guides/delivery-scope.md`): only `blocker: yes` findings keep the loop going; minor/nit findings become follow-ups. A Clarify signal (the user is needed or the reviews are not converging) stops the loop for a Clarification report - Each iteration: revise design → re-run all reviewers - Escalation options: Revise / Clarify the requirement / re-brainstorm / Narrow scope / Defer / Cancel. A Clarification report offers Answer / Keep iterating / Narrow scope / Defer / Cancel. Neither approves: a revised design gets a fresh review round See the `design-review-gate` skill for full details. --- ## Team Mode Coordination When multiple Claude Code sessions are active on the same repository (e.g., parallel worktrees), metaswarm automatically enters **Team Mode**. In Team Mode, agents behave as persistent teammates with context retention across sessions and direct inter-agent messaging for coordination. Mode detection is automatic based on the presence of concurrent sessions. For the full Team Mode protocol — including message routing, context sharing, and conflict resolution — see `./guides/agent-coordination.md`. --- ## Plan Review Gate Once an implementation plan is written, it passes through the **Plan Review Gate** before it is presented. In full orchestration that is before the Design Review Gate, which then reviews the plan; on the brainstorming path the Design Review Gate has already reviewed the design doc (see [`./guides/workflow-enforcement.md`](./guides/workflow-enforcement.md#two-pipelines)). Three adversarial reviewers validate the plan independently: | Reviewer | Focus | | --- | --- | | **Feasibility** | Technical viability, dependency risks, resource constraints | | **Completeness** | Missing work units, untested edge cases, gaps in Definition of Done | | **Scope & Alignment** | Plan stays within issue scope, aligns with codebase conventions | All 3 must APPROVE before the plan proceeds. See the `plan-review-gate` skill for the full skill definition. --- ## Orchestrated Execution After design review approval, implementation follows the **4-phase execution loop** per work unit. This replaces the previous linear "implement then review" flow with rigorous independent validation and adversarial review. ### Core Principle **Trust nothing. Verify everything. Review adversarially.** ### Plan Validation (Pre-Flight) Before submitting to the Design Review Gate, the orchestrator runs a pre-flight checklist covering architecture, dependency graph, API contracts, security, UI/UX, and external dependencies. This catches structural issues (missing service layer, wrong dependency graph, oversized WUs) before spending agent cycles on review. ### The 4-Phase Loop For each work unit (a discrete, spec-driven change with DoD items): 1. **IMPLEMENT** — Coding subagent executes against the spec using TDD, with the Project Context Document 2. **VALIDATE** — Orchestrator independently runs quality gates (tsc, eslint, vitest, coverage enforcement from `.coverage-thresholds.json`). **Never trust subagent self-reports.** Quality gates are **blocking state transitions**, not advisory. 3. **ADVERSARIAL REVIEW** — Fresh review subagent checks against spec contract. Binary PASS/FAIL with file:line evidence. Uses `adversarial-review-rubric.md`. When external tools are configured, cross-model review ensures the writer is always reviewed by a different AI model (see External Tools section below). 4. **COMMIT** — Only after adversarial PASS. Updates `SERVICE-INVENTORY.md` and Project Context Document. On FAIL: fix → re-validate → spawn **fresh** reviewer (role type `roleType("adversarial-reviewer")`; severity-gated iteration, cap 10 rounds; see `./guides/delivery-scope.md` → escalate to human when the rule says so). There is NO path from FAIL to COMMIT without passing through the retry loop. ### When to Use Orchestrated Execution - The task has a **written spec** with enumerable Definition of Done items - The implementation involves **multiple work units** (3+ logical changes) - You need **independent verification** — subagent self-reports aren't sufficient - The changes are **high-stakes** (schema changes, security, new architectural patterns) - You want **proactive human checkpoints** at planned review points ### When NOT to Use It - Single-file bug fixes or copy changes - Tasks without a written spec or DoD items - Quick prototyping or exploratory work - Tasks where the overhead of decomposition exceeds the work itself For simple tasks, the standard linear flow (implement → code review → PR) works fine. ### Key Concepts **Work Unit Decomposition**: Break the implementation plan into discrete work units, each with: - A spec section and enumerated DoD items - A declared file scope (which files it may modify) - Dependencies on other work units - An optional human checkpoint flag **Independent Validation**: The orchestrator runs `tsc`, `eslint`, and `vitest` directly — it does NOT ask the coding subagent "did the tests pass?" and accept the answer. **Adversarial Review**: Fundamentally different from collaborative code review. The reviewer is an independent auditor checking spec compliance, not a helpful colleague suggesting improvements. Binary PASS/FAIL verdict. Evidence required (file:line references). **Fresh Reviewer Rule**: On re-review after FAIL, a NEW reviewer instance (role type `roleType("adversarial-reviewer")`) is spawned with no memory of the previous review. This prevents anchoring bias. **Human Checkpoints**: Planned pauses at critical boundaries (schema changes, security code, first use of new patterns). The orchestrator waits for explicit human approval before continuing. **Final Comprehensive Review**: After all work units pass, a cross-unit review catches integration issues that per-unit reviews miss. See `orchestrated-execution` skill for the complete pattern, including work unit structure, parallel execution, recovery protocol, and anti-patterns. --- ## External AI Tools (Optional) When external AI CLI tools are configured (`.metaswarm/external-tools.yaml`), the orchestrator can delegate implementation and review tasks to OpenAI Codex CLI and Google Gemini CLI. This enables cost savings through cheaper models and cross-model adversarial review that eliminates single-model blind spots. ### How It Integrates External tools slot directly into the existing 4-phase execution loop: - **Phase 1 (IMPLEMENT)**: The orchestrator may delegate to an external tool instead of spawning a Claude subagent. The tool works in an isolated git worktree. - **Phase 2 (VALIDATE)**: Unchanged — the orchestrator independently runs all quality gates regardless of who implemented. - **Phase 3 (ADVERSARIAL REVIEW)**: Cross-model review — the writer is always reviewed by a different model (e.g., Codex writes, Gemini + Claude review). - **Phase 4 (COMMIT)**: Unchanged — merge worktree branch after all phases pass. ### Escalation Chain The orchestrator adapts based on tool availability: | Available Tools | Escalation Chain | Max Attempts | |---|---|---| | Both Codex + Gemini | A(2) → B(2) → Claude(1) → user | 5 | | One tool only | Tool(2) → Claude(1) → user | 3 | | No tools | Claude → user (existing behavior) | unchanged | Each escalated model receives the previous model's branch as a reference. See the `external-tools` skill for the full skill definition. ### Health Check ```bash /external-tools-health ``` Checks installation, authentication, and reachability of all configured adapters. --- ## Visual Review The `visual-review` skill enables agents to take screenshots of web pages, presentations, and UIs using Playwright for visual inspection. This bridges the gap where agents cannot see rendered output. ### Usage The skill is triggered when tasks involve visual output (web UIs, Reveal.js presentations, landing pages, email templates). It captures screenshots at configurable viewport sizes, and agents analyze them for layout, typography, colors, spacing, and content issues. ### Prerequisites ```bash npx playwright install chromium ``` For remote/headless environments, the skill serves screenshots via HTTP file server so users can view them in their local browser. See the `visual-review` skill for the complete workflow. --- ## Workflow Overview ``` GitHub Issue #123 (agent-ready label) │ ▼ ┌─────────────────────────────────────┐ │ Issue Orchestrator │ │ Creates BEADS epic, delegates work │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ Research Phase │ │ Researcher Agent explores codebase │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ Planning Phase │ │ Architect Agent creates plan │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ Plan Review Gate │ │ 3 adversarial reviewers: │ │ Feasibility, Completeness, │ │ Scope & Alignment │ │ ALL 3 must approve │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ External Dependency Detection │ │ Scans spec for API keys/creds │ │ Prompts user to configure them │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ Plan Validation (Pre-Flight) │ │ Architecture, deps, API contracts │ │ Security, UI/UX, external deps │ └─────────────────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────────────────────────────────┐ │ DESIGN REVIEW GATE (PARALLEL) │ │ │ │ ┌─────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌────────┐ ┌───────┐ │ │ │ PM │ │ Architect│ │ Designer │ │ Security │ │UX Revw.│ │ CTO │ │ │ │(users) │ │ (tech) │ │ (UX/API) │ │ (threats)│ │(flows) │ │ (TDD) │ │ │ └─────────┘ └──────────┘ └──────────┘ └──────────┘ └────────┘ └───────┘ │ │ │ │ ALL SIX must approve (severity-gated iteration, cap 10 rounds) │ └──────────────────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ Work Unit Decomposition │ │ Break plan into work units w/ DoD │ │ Build dependency graph │ └─────────────────────────────────────┘ │ ▼ ┌───────────────────────────────────────────────────────────────┐ │ ORCHESTRATED EXECUTION LOOP (per work unit) │ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────────┐ ┌──────┐ │ │ │IMPLEMENT │───→│ VALIDATE │───→│ ADVERSARIAL │──→│COMMIT│ │ │ │(Coder) │ │(Orchest.)│ │ REVIEW │ │ │ │ │ └──────────┘ └──────────┘ └──────┬───────┘ └──────┘ │ │ ▲ │ FAIL │ │ └─────────────────────────────────┘ │ │ │ │ Trust nothing. Verify everything. Review adversarially. │ └───────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ Final Comprehensive Review │ │ Cross-unit integration check │ │ Full test suite + type check │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ Pre-PR /self-reflect (required │ │ instruction review, one decision │ │ request, edits in the same commit) │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ PR Creation │ │ gh pr create │ │ → then /pr-shepherd │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ PR Shepherd (Automatic) │ │ Monitors CI, handles reviews, │ │ resolves threads automatically │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ Human Approval & Merge │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ Release Engineer │ │ Pre-merge verify → merge → CI → │ │ deploy → post-deploy QA → release │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ Close Epic (optional post-merge │ │ learnings follow-up) │ └─────────────────────────────────────┘ ``` ### GTG (Good-To-Go) Merge Gate GTG is the final merge gate. It consolidates CI status, comment classification, and thread resolution into a single deterministic check. Agents should use it as the primary readiness signal: ```bash # Check if PR is ready to merge gtg --format json \ --exclude-checks "Merge Ready (gtg)" \ --exclude-checks "CodeRabbit" \ --exclude-checks "Cursor Bugbot" \ --exclude-checks "claude" ``` **Statuses**: `READY` (merge), `ACTION_REQUIRED` (fix comments), `UNRESOLVED_THREADS` (resolve threads), `CI_FAILING` (fix CI). The `action_items` array tells agents exactly what to fix. **GTG reports, agents act**: GTG does not resolve threads or fix code. After addressing feedback, agents must resolve threads themselves via the GraphQL mutation documented in `handle-pr-comments.md` (Section 3: Resolving Review Threads). GTG will report `READY` on the next check once threads are resolved. If the CI check is stale: `gh workflow run gtg.yml -f pr_number=` ### Automatic PR Review Cycles Every PR gets the same cycle, however it was created: 1. **Run `/self-reflect` first**, with its required instruction review. In a subagent, return the "Instruction changes proposed" list to the parent before the PR; the main session asks and commits the approved edits 2. **Create the PR** with `gh pr create` and a proper title/body 3. **Start pr-shepherd** right away with `/pr-shepherd ` 4. **PR Shepherd monitors**: CI status, review comments, thread resolution 5. **Auto-fixes**: Lint, type errors, test failures in your code 6. **Reports when ready**: All CI green, all threads resolved --- ## BEADS Commands Reference ### Issue Management ```bash # Create epic for GitHub Issue bd create "Feature: User Auth" --type epic --external-ref gh-123 # Create task under epic bd create "Research auth patterns" --type task --parent bd-abc123 # Add dependency bd dep add # Update status bd update --status open|in_progress|blocked|closed # Close with reason bd close --reason "Completed successfully" ``` ### Task Discovery ```bash # Show ready (unblocked) tasks bd ready --json # List all tasks under epic bd list --parent # Show blocked tasks bd blocked # Show task details bd show --json ``` ### Labels for Custom States ```bash # Waiting for human input bd label add waiting:human # Waiting for CI bd label add waiting:ci # Agent failed, needs intervention bd label add agent:failed # Review iteration tracking bd label add review:iteration-1 ``` ### Sync Operations ```bash # Check version-control status (branch and uncommitted changes) bd vc status # If a Dolt remote is configured: pull updates (local-only workspaces need no sync) bd dolt pull # If a Dolt remote is configured: push your changes (local-only workspaces need no sync) bd dolt push # Export to JSONL bd export ``` --- ## Starting Work on an Issue ### Step 1: Verify Issue is Ready ```bash # Check Issue has agent-ready label gh issue view 123 --json labels | jq '.labels[].name' | grep agent-ready ``` ### Step 2: Create BEADS Epic ```bash # Get Issue details ISSUE=$(gh issue view 123 --json title,body,number) # Create epic linked to Issue bd create "$(echo $ISSUE | jq -r .title)" --type epic --external-ref gh-123 --json ``` ### Step 3: Post Acknowledgment ```bash gh issue comment 123 --body "🤖 Agent claiming this issue. BEADS epic created." ``` ### Step 4: Spawn Issue Orchestrator Use the Task tool to spawn the Issue Orchestrator agent: ```typescript Task({ subagent_type: roleType("issue-orchestrator"), description: "Issue Orchestrator for #123", prompt: `You are the ISSUE ORCHESTRATOR agent. Read the agent definition at: ./agents/issue-orchestrator.md Your task: - Epic ID: - GitHub Issue: #123 - Begin the orchestration workflow Follow the workflow phases exactly as specified. - Before gh pr create, RETURN the "Instruction changes proposed" list from /self-reflect Step 7 and stop. Do not ask the user and do not apply instruction edits.`, }); ``` **Handling the return**: the Issue Orchestrator is a subagent and cannot ask the user. When it returns the "Instruction changes proposed" list, the main session asks it as one decision request (see Decision requests in `guides/delivery-scope.md`), unless the list is `none, because ...`, which needs no instruction question. If the orchestrator also returned candidate learnings, still run `/self-reflect` Step 4 approval and Step 5 storage and commit them inside that orchestrator's worktree (`git -C ...`, on its branch) before PR creation. If you are yourself a subagent, relay the list upward until it reaches the main session. Then commit the approved edits with the knowledge-base updates inside that orchestrator's worktree (`git -C ...`, on its branch), and resume or message the orchestrator so it creates the PR. If the main session must hand off without an answer, the items stay unapplied and are listed in the PR body as open questions. --- ## Human Escalation Protocol ### When to Escalate 1. **Ambiguous Requirements**: Issue lacks clarity 2. **Conflicting Constraints**: Can't satisfy all requirements 3. **Risk Decision**: Security or data concerns 4. **Blocked > 1 Hour**: External dependency needed 5. **Severity Rule Escalates**: Review cap of 10 rounds hit, or a blocker recurs or is disputed (see `./guides/delivery-scope.md`) 6. **Clarify Signal**: the severity rule's line 2 fires (the user is needed or the reviews are not converging); this is a stop for the user, not an escalation ### How to Escalate **Every ask to the user uses the decision-request format**: lettered options (A, B, C) under numbered questions (reply `1 A 2 C`), each with its pros and cons, the recommended option marked, and why it is recommended (see Decision requests in `./guides/delivery-scope.md`). The Agent Request below, the Clarification report and the Review Escalation report all use those option blocks. Questions that only collect a fact are exempt. **Severity-rule escalations never use this template.** When a review gate escalates (the 10-round cap, or a recurring or disputed blocker), still mark the task waiting (`bd update --status blocked` and `bd label add waiting:human`), then post the Review Escalation report from the Escalation template in `./guides/delivery-scope.md` instead. Its options are **Revise**, **Clarify the requirement / re-brainstorm**, **Narrow scope**, **Defer** and **Cancel**, and any revised or narrowed work gets a fresh review round that it must pass. A Clarify signal (rule line 2) uses the Clarification report from the Clarify section of the same guide instead: run the misunderstanding analysis first, then wait for the user's answer. "Keep going" never defaults a `needs_user` question. There is no `@beads approve` for an escalated review gate: escalation never approves, and a Clarification never approves either. For triggers 1-4: ```bash # Mark task as waiting bd update --status blocked bd label add waiting:human # Post to GitHub Issue gh issue comment --body "$(cat <<'EOF' ## 🤖 Agent Request: **Task**: **Decision 1**: ### Options Every ask to the user uses the decision-request format (see Decision requests in `./guides/delivery-scope.md`): lettered options A, B, C (never numbers), each with pros and cons, and Why recommended on the recommended option only. **Option A: ** (Recommended) - Pros: ... - Cons: ... - Why recommended: **Option B: ** - Pros: ... - Cons: ... Reply with the decision number and a letter, like `1 A`. If there's no answer: . --- Reply: `@beads approve ` or `@beads respond