AgentSkillsCN

routing

分析规范内容,将任务路由至合适的代理。

SKILL.md
--- frontmatter
name: routing
description: Analyze spec content and route /implement to appropriate agents.

Routing Skill

Analyze spec content and route /implement to appropriate agents based on what the spec defines.

When Used

CommandRouting Logic
/implementRead approved spec → detect type → route agents

NOT used by: /start, /design, /ship, /review, /reconcile (direct routing)

Implement Routing

Decision Flow

text
/implement
    │
    ▼
┌────────────────────────────────────────────────────┐
│  1. FIND: Locate approved spec                     │
│     Resolve: resolveSpecPath(feature)              │
│     Verify: "Status: Approved" in frontmatter      │
└────────────────────────────────────────────────────┘
    │
    ▼
┌────────────────────────────────────────────────────┐
│  2. ANALYZE: Read spec content                     │
│     Parse: design.md sections and keywords         │
│     Identify: Backend, frontend, docs, eval scope  │
└────────────────────────────────────────────────────┘
    │
    ▼
┌────────────────────────────────────────────────────┐
│  3. ROUTE: Based on detected type                  │
└────────────────────────────────────────────────────┘
    │
    ├── Backend only → code-agent
    │
    ├── Frontend only → ui-agent
    │
    ├── Backend + Frontend → code-agent → ui-agent (sequential)
    │
    ├── Documentation only → docs-agent
    │
    ├── Evaluation only → eval-agent
    │
    └── Mixed → Route to multiple agents per section

Spec Content Detection

Detected In SpecTypeRoutes To
tRPC, Prisma, API, database, model, schema, serverBackendcode-agent
React, component, form, UI, hook, page, layoutFrontendui-agent
README, documentation, guide, tutorialDocsdocs-agent
evaluation, grader, benchmark, pass@k, LLM testEvaleval-agent

Section-Based Detection

The spec's design.md sections determine routing:

text
## Architecture
├── "Database" subsection → Backend component
├── "API" subsection → Backend component
├── "Components" subsection → Frontend component
└── "Pages" subsection → Frontend component

## Implementation
├── Tasks mention Prisma/tRPC → Backend
├── Tasks mention React/shadcn → Frontend
└── Tasks mention both → Mixed (code-agent → ui-agent)

Examples

Spec ContentDetected TypeRoute
Prisma schema + tRPC router onlyBackendcode-agent
React components + forms onlyFrontendui-agent
Prisma + tRPC + React componentsFull-stackcode-agent → ui-agent
README + API docsDocsdocs-agent
Grader + test cases + benchmarksEvaleval-agent
Prisma + READMEMixedcode-agent + docs-agent

No Spec Found

When /implement is called but no approved spec exists:

text
┌─────────────────────────────────────────────────────────────────┐
│  /implement                                                      │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  ERROR: No approved spec found                                   │
│                                                                  │
│  Searched using: resolveSpecPath(feature)                        │
│  • Checked project and feature directories                       │
│  • No design.md or requirements.md found                         │
│                                                                  │
│  To create a spec, run:                                          │
│  /design                                                           │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

Ambiguous Spec

When spec content is unclear:

text
┌─────────────────────────────────────────────────────────────────┐
│  /implement                                                      │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  Spec found but type unclear: specs/utils/design.md              │
│                                                                  │
│  What type of implementation is this?                            │
│                                                                  │
│  1. Backend (API, database, server logic)     → code-agent       │
│  2. Frontend (UI, components, styling)        → ui-agent         │
│  3. Full-stack (both)                         → code → ui        │
│  4. Documentation                             → docs-agent       │
│  5. LLM evaluation                            → eval-agent       │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

Routing Decision Matrix

Spec ContentDetected ScopeRoute
Prisma, tRPC, API onlyBackendcode-agent
React, components, UI onlyFrontendui-agent
Both backend + frontend sectionsFull-stackcode-agent → ui-agent
README, documentation onlyDocsdocs-agent
Evaluation, grader, benchmarks onlyEvaleval-agent
Backend + docs sectionsMixedcode-agent → docs-agent
Frontend + eval sectionsMixedui-agent → eval-agent
Unclear or empty specUnknownAsk for clarification

Algorithm

typescript
interface RoutingResult {
  agents: ("code-agent" | "ui-agent" | "docs-agent" | "eval-agent")[];
  reason: string;
  spec: { path: string; sections: string[] };
}

function routeImplement(feature: string): RoutingResult {
  // 1. Resolve spec path
  const { path: specPath } = resolveSpecPath(feature);

  // 2. Read and parse spec
  const spec = readSpec(specPath);
  if (!spec) {
    throw new Error("No approved spec found. Run /design first.");
  }

  // 3. Detect sections
  const sections = detectSections(spec.content);

  // 4. Build agent sequence
  const agents: RoutingResult["agents"] = [];

  if (hasBackendIndicators(sections)) {
    agents.push("code-agent");
  }

  if (hasFrontendIndicators(sections)) {
    agents.push("ui-agent");
  }

  if (hasDocsIndicators(sections)) {
    agents.push("docs-agent");
  }

  if (hasEvalIndicators(sections)) {
    agents.push("eval-agent");
  }

  // 5. Handle ambiguous case
  if (agents.length === 0) {
    throw new Error(
      "Unable to determine implementation type. Please clarify: backend, frontend, full-stack, docs, or eval?"
    );
  }

  return {
    agents,
    reason: `Detected: ${agents.join(", ")}`,
    spec: { path: specPath, sections },
  };
}

function detectSections(content: string): string[] {
  const indicators = {
    backend: /prisma|trpc|api|database|schema|mutation|query|server/i,
    frontend: /react|component|form|ui|hook|page|layout|shadcn/i,
    docs: /readme|documentation|guide|tutorial/i,
    eval: /evaluation|grader|benchmark|pass@k|llm test/i,
  };

  return Object.entries(indicators)
    .filter(([_, regex]) => regex.test(content))
    .map(([type]) => type);
}

Error Handling

ScenarioHandling
No spec foundError: Run /design first
Spec not approvedError: Get spec approved first
Spec unreadableError: Cannot parse spec file
No sections detectedAsk user to clarify implementation type
Multiple agent typesExecute sequentially (code → ui → docs → eval)

Output

Successful Routing

markdown
## Routing: SUCCESS

**Spec:** /home/user/project/specs/user-authentication/design.md (resolved)
**Detected:** Full-stack (backend + frontend)

### Execution Chain

1. **code-agent** (backend)
   - code-researcher → code-writer → quality-validator
   - Scope: Prisma schema, tRPC router
   - spec_path: /home/user/project/specs/user-authentication/

2. **ui-agent** (frontend)
   - ui-researcher → ui-builder → ui-validator
   - Scope: Login form, auth context
   - spec_path: /home/user/project/specs/user-authentication/

3. **check-agent** (verification)
   - Parallel: build, types, lint, tests, security

No Spec Found

markdown
## Routing: ERROR

**Reason:** No approved spec found

### Next Steps

1. Run `/design` to create a spec
2. Review and approve the spec
3. Run `/implement` again

Clarification Needed

markdown
## Routing: CLARIFY

**Spec:** /home/user/project/specs/utils/design.md (resolved)
**Reason:** Unable to determine implementation type

### Detected Content

- No backend keywords (Prisma, tRPC, API)
- No frontend keywords (React, component, UI)
- No docs keywords (README, guide)
- No eval keywords (grader, benchmark)

### Question

What type of implementation is this?

1. Backend (code-agent)
2. Frontend (ui-agent)
3. Full-stack (code-agent → ui-agent)
4. Documentation (docs-agent)
5. Evaluation (eval-agent)