AgentSkillsCN

Task Distribution

支持多代理的任务分发机制,实现后端、前端与测试的并行执行

SKILL.md
--- frontmatter
description: Multi-agent task distribution for parallel BE/FE/Test execution
category: Planning
boundary: Monorepo (be/, fe/, e2e/)
version: 2.2

Task Distribution

How the main agent distributes tasks to sub-agents for parallel execution.

Agent Profiles

Agent profiles are in .claude/agents/:

  • backend.md – BE agent for be/
  • frontend.md – FE agent for fe/
  • test.md – Test agent for be/test/

Pre-Distribution: API Generation Decision

Think like a senior fullstack developer - decide if API generation is needed BEFORE spawning agents.

Decision Flow

code
1. What feature/module is this task for? (e.g., "product")
2. Check: Does `bff/<pkg>/<pkg>.proto` exist?
   - No → Skip generation, implement manually
   - Yes → Continue to step 3
3. Check: Is this task API-related?
   - Creates/modifies routes, services, hooks, api calls → Need generation
   - Only UI components, styling, state → Skip generation
4. Check: Are generated files already present?
   - `be/core/api/<pkg>/<pkg>.routes.ts` exists?
   - `fe/src/services/<pkg>/api.ts` exists?
   - If missing or proto changed → Run generation
   - If present and unchanged → Skip generation
5. Run: `npm run gen -- <pkg>` if needed

Quick Decision Table

Task TypeProto Exists?Generated Files?Action
New API endpointYesNonpm run gen -- <pkg>
New API endpointNo-Create proto first, then gen
Modify existing APIYesYes, outdatednpm run gen -- <pkg>
UI component only--Skip generation
Styling/design--Skip generation
Add service logicYesYesSkip (files exist)

Example

code
Task: T001 - Create product listing page

Analysis:
1. Feature: product
2. Proto: bff/product/product.proto ✅ exists
3. API-related: Yes (needs useGetProducts hook)
4. Generated files:
   - fe/src/services/product/api.ts ❌ missing
   - fe/src/services/product/useQuery.ts ❌ missing

Decision: Run `npm run gen -- product` before spawning Frontend Agent

Architecture

mermaid
flowchart TD
    MAIN[MAIN AGENT<br/>analyzes tasks, decides parallel vs sequential]
    MAIN -->|spawn| BE[Backend Agent]
    MAIN -->|spawn| FE[Frontend Agent]
    MAIN -->|spawn| TEST[Test Agent]
    BE --> BE_DIR[be/core/*]
    FE --> FE_DIR[fe/src/*]
    TEST --> TEST_DIR[be/test/*]

Note: E2E tests (e2e/) are run by user manually, not by agents.

Available Sub-Agents

AgentFileWorkspaceHandles
Backend.claude/agents/backend.mdbe/Repos, Services, Routes
Frontend.claude/agents/frontend.mdfe/Components, Hooks, UI
Test.claude/agents/test.mdbe/test/Integration tests only

When to Parallelize

Check these rules:

ConditionDecision
Tasks touch different workspaces (BE vs FE)✅ Parallel OK
Tasks touch same file❌ Sequential only
Task B depends on Task A output❌ Sequential only
Tasks are independent features✅ Parallel OK
Tasks share database schema changes❌ Sequential only

Decision Flow

code
1. Load pending tasks from progress.md
2. For each pair of tasks, check:
   - Same workspace? → Sequential
   - Same file? → Sequential
   - Dependency? → Sequential
   - Otherwise → Can Parallel
3. Group into waves
4. Ask user to confirm
5. Spawn sub-agents for parallel tasks

Wave Execution

mermaid
flowchart TD
    subgraph Wave1["Wave 1 (Parallel)"]
        BE[Backend Agent<br/>T001 be/]
        FE[Frontend Agent<br/>T002 fe/]
    end
    subgraph Wave2["Wave 2 (Sequential)"]
        TEST[Test Agent<br/>T003 tests T001]
    end
    Wave1 -->|sync point| Wave2

File Lock Rules

When spawning sub-agents, assign file locks:

yaml
# Example lock assignment
T001 (Backend Agent):
  locks:
    - be/core/repo/product.repo.ts
    - be/core/services/product.service.ts

T002 (Frontend Agent):
  locks:
    - fe/src/components/product-module/*

Rules:

  • One agent per file
  • Lock acquired before task starts
  • Lock released after verification
  • Conflicts → force sequential

Spawn Format

When spawning a sub-agent, provide:

code
🤖 Spawning BACKEND Agent

Task: T001 - Create product.repo.ts
Profile: .claude/agents/backend.md
Locked Files:
  - be/core/repo/product.repo.ts

Instructions:
1. Read the agent profile
2. Execute task following profile patterns
3. Report back with completion status

Sync After Wave

After all agents in a wave complete:

  1. Collect results from each agent
  2. Update progress.md with completed tasks
  3. Release locks for completed tasks
  4. Check next wave dependencies
  5. Ask user before proceeding

Max Parallel

  • Max 3 agents per wave
  • If more tasks, split into multiple waves