AgentSkillsCN

task-planner

分析用户需求,深入研究代码库,将其分解为若干子任务,分配相应智能体,并返回包含各阶段任务安排的完整执行计划。

SKILL.md
--- frontmatter
name: task-planner
description: Analyze user request, explore codebase, decompose into subtasks, assign agents, and return complete execution plan with wave assignments.
context: fork
allowed-tools: Read, Grep, Glob, Bash, WebFetch, AskUserQuestion, TaskCreate, TaskUpdate, TaskList, TaskGet

Task Planner

Analyze the user's request and return a complete execution plan including agent assignments and wave scheduling.


Process

  1. Read environment configuration — Run echo ${CLAUDE_MAX_CONCURRENT:-8} via Bash to capture the max concurrent agents limit. This value will be included in the execution plan JSON.

  2. Parse intent — What does the user actually want? What's the success criteria?

  3. Check for ambiguities — If blocking, return questions. If minor, state assumptions and proceed.

  4. Explore codebase — Only if relevant for the user request: Find relevant files, patterns, test locations. Sample, don't consume.

  5. Decompose — Break into atomic subtasks with clear boundaries.

  6. Assign agents — Match each subtask to a specialized agent via keyword analysis.

  7. Map dependencies — What blocks what? What can parallelize?

  8. Assign waves — Group independent tasks into parallel waves.

  9. Flag risks — Complexity, missing tests, potential breaks.

  10. Populate Tasks — Create task entries using TaskCreate with structured metadata for execution.


Output

If Clarification Needed

When blocking ambiguities exist that prevent planning, use the AskUserQuestion tool to get clarification from the user.

Use AskUserQuestion with:

  • question: A clear, specific question about what's blocking
  • Include default assumptions in the question text so the user can simply confirm or override

Example:

code
AskUserQuestion(
  question: "Should this API support pagination? (Default: Yes, using cursor-based pagination)"
)

Format for multiple questions: Ask the most critical blocking question first. After receiving an answer, you can ask follow-up questions if still blocked.

If Ready — Complete Execution Plan

Output the following structured plan:


EXECUTION PLAN

Status: Ready

Goal: <one sentence>

Max Concurrent: <value from CLAUDE_MAX_CONCURRENT env var, default 8>

Success Criteria:

  • <verifiable outcome>

Assumptions:

  • <assumption made, if any>

Relevant Context:

  • Files: <paths>
  • Patterns to follow: <patterns>
  • Tests: <location>

Subtasks with Agent Assignments

IDDescriptionAgentDepends OnWave
1<description><agent-name>none0
2<description><agent-name>none0
3<description><agent-name>1, 21
...

Wave Breakdown

List EVERY task individually (no compression):

markdown
### Wave 0 (N parallel tasks)
  1: <description> -> <agent-name>
  2: <description> -> <agent-name>

### Wave 1 (M tasks)
  3: <description> -> <agent-name>

Prohibited patterns:

  • + notation: task1 + task2
  • Range notation: 1-3
  • Wildcard: root.1.*
  • Summaries: 4 test files

Task Creation with Tasks API

Note: Use TaskCreate for each subtask. Metadata is stored in structured fields, not encoded strings.

TaskCreate Parameters:

  • subject: Brief imperative title (e.g., "Create project structure")
  • description: Detailed description including requirements and context
  • activeForm: Present continuous form shown during execution (e.g., "Creating project structure")
  • metadata: Object containing wave, phase, agent, parallel execution info, and output_file path

Output File Assignment: Each task gets output_file: $CLAUDE_SCRATCHPAD_DIR/{sanitized_subject}.md in metadata. Agents write full results there, return ONLY DONE|{path} (nothing else - this preserves main agent context). The scratchpad directory is automatically session-isolated.

Agent Return Format (CRITICAL):

  • Agents MUST return exactly: DONE|{output_file_path}
  • Example: DONE|$CLAUDE_SCRATCHPAD_DIR/review_auth_module.md
  • PROHIBITED: summaries, findings, explanations, any other text
  • All content goes in the output file, NOT the return value

File Writing:

  • Agents HAVE Write tool access for /tmp/ paths
  • Agents write directly to output_file - do NOT delegate file writing
  • If Write is blocked, report error and stop (do not loop)

File naming rules:

  • Use $CLAUDE_SCRATCHPAD_DIR for output files (automatically session-isolated)
  • Sanitize subject: lowercase, replace spaces with underscores, remove special chars except hyphens
  • Example: Task "Review code-cleanup-optimizer" → $CLAUDE_SCRATCHPAD_DIR/review_code-cleanup-optimizer.md

Example TaskCreate calls:

code
TaskCreate:
  subject: "Create project structure"
  description: "Set up initial project directory structure with src/, tests/, and config files"
  activeForm: "Creating project structure"
  metadata: {"wave": 0, "phase_id": "1", "agent": "general-purpose", "parallel": true, "output_file": "$CLAUDE_SCRATCHPAD_DIR/create_project_structure.md"}

TaskCreate:
  subject: "Create database config"
  description: "Create database configuration with connection pooling and environment-based settings"
  activeForm: "Creating database config"
  metadata: {"wave": 0, "phase_id": "2", "agent": "general-purpose", "parallel": true, "output_file": "$CLAUDE_SCRATCHPAD_DIR/create_database_config.md"}

TaskCreate:
  subject: "Verify implementations"
  description: "Run all tests and verify implementations meet requirements"
  activeForm: "Verifying implementations"
  metadata: {"wave": 1, "phase_id": "3", "agent": "task-completion-verifier", "parallel": false, "output_file": "$CLAUDE_SCRATCHPAD_DIR/verify_implementations.md"}

After creating tasks, set up dependencies:

code
TaskUpdate:
  taskId: "3"
  addBlockedBy: ["1", "2"]

Risks

  • <what could go wrong and why>

→ CONTINUE TO EXECUTION


Available Specialized Agents

IMPORTANT - Agent Name Prefix:

  • Plugin mode: Use workflow-orchestrator:<agent-name> (e.g., workflow-orchestrator:task-completion-verifier)
  • Native install: Use just <agent-name> (e.g., task-completion-verifier)

To detect mode: Check if running as a plugin by looking for workflow-orchestrator: prefix in available agents list.

Agent (base name)KeywordsCapabilities
codebase-context-analyzeranalyze, understand, explore, architecture, patterns, structure, dependenciesRead-only code exploration and architecture analysis
tech-lead-architectdesign, approach, research, evaluate, best practices, architect, scalability, securitySolution design and architectural decisions
task-completion-verifierverify, validate, test, check, review, quality, edge casesTesting, QA, validation
code-cleanup-optimizerrefactor, cleanup, optimize, improve, technical debt, maintainabilityRefactoring and code quality improvement
code-reviewerreview, code review, critique, feedback, assess quality, evaluate codeCode review and quality assessment
devops-experience-architectsetup, deploy, docker, CI/CD, infrastructure, pipeline, configurationInfrastructure, deployment, containerization
documentation-expertdocument, write docs, README, explain, create guide, documentationDocumentation creation and maintenance
dependency-managerdependencies, packages, requirements, install, upgrade, manage packagesDependency management (Python/UV focused)
Explorereview, summarize, scan, list, catalogBuilt-in Haiku agent for breadth tasks (cheap, fast). READ-ONLY: Cannot write files.

Large-Scope Detection: If task mentions "all files" / "entire repo" / "summarize each" -> consider parallel agents with a final aggregation phase. Each agent handles one bounded scope; aggregation phase collects summaries. Important: If tasks need to write output files, use general-purpose instead of Explore (Explore is read-only).

When assigning agents in TaskCreate metadata and delegations, ALWAYS use the full prefixed name: workflow-orchestrator:<agent-name>


Agent Selection Algorithm

  1. Extract keywords from subtask (case-insensitive)
  2. Count matches per agent; select agent with >=2 matches (highest wins)
  3. Ties: first in table order; <2 matches: general-purpose

Explore Agent Constraint (CRITICAL):

  • Explore is READ-ONLY — it CANNOT write files (no Write, Edit, NotebookEdit tools)
  • NEVER assign Explore if task has output_file in metadata
  • NEVER assign Explore if description contains: "write", "create", "save", "generate", "produce", "output"
  • For parallel breadth tasks that need output files: use general-purpose instead of Explore

Complexity Scoring & Tier Classification

Score formula: action_verbs*2 + connectors*2 + domain + scope + risk (range 0-35)

ScoreTierMin Depth
< 511
5-1522
> 1533

Rule: Depth < tier minimum → MUST decompose further.


Atomicity Validation

Step 1: Depth >= tier minimum? If NO → DECOMPOSE (skip Step 2)

Step 2: Atomic if ALL true: single operation, ≤3 files modified, ≤5 files/10K lines input, single deliverable, implementation-ready, single responsibility

Split rules:

  • Unbounded input → split by module/directory
  • Multiple operations → one subtask each
  • CRUD → separate create/read/update/delete

Success Criteria & Iteration

  • requirements[] - What it must do
  • success_criterion - Verifiable command (optional); if present, agent loops until pass or max 5 attempts

Implementation Task Decomposition

When decomposing implementation tasks (create, build, implement):

ALWAYS decompose by function/component, not by file:

TaskDecompositionParallel?
"Create calculator with add, subtract, multiply, divide"4 tasks (one per operation)Yes
"Build user auth with login, logout, register"3 tasks (one per feature)Yes
"Implement CRUD operations"4 tasks (create, read, update, delete)Yes

Example - Calculator module:

WRONG (single task):

code
Wave 1: Create calculator module [1 task]

CORRECT (parallel tasks):

code
Wave 1 (Parallel):
- Implement add() function
- Implement subtract() function
- Implement multiply() function
- Implement divide() function

Detection patterns:

  • "with [list]" -> decompose each item
  • "basic operations" -> decompose: add, subtract, multiply, divide
  • "CRUD" -> decompose: create, read, update, delete
  • "auth" -> decompose: login, logout, register, etc.

Minimum decomposition: If a task mentions multiple operations/functions, create one subtask per operation.


Agent-Based Decomposition (NOT Item-Based)

WRONG: 16 files → 16 tasks (1 task per file) RIGHT: 16 files, 8 agents → 8 tasks (2 files per task)

When decomposing breadth tasks (same operation × multiple items):

  1. Identify total items (files, modules, components, etc.)
  2. Use agent count from CLAUDE_MAX_CONCURRENT (default 8, or user-specified)
  3. Create ONE task per agent, NOT one task per item
  4. Each task description includes its assigned items

Example:

  • Input: "Review 16 agent files"
  • Agent count: 8
  • Output: 8 tasks (NOT 16)
    • Task 1: "Review code-cleanup-optimizer.md, code-reviewer.md" → general-purpose
    • Task 2: "Review codebase-context-analyzer.md, dependency-manager.md" → general-purpose
    • Task 3: "Review devops-experience-architect.md, documentation-expert.md" → general-purpose
    • Task 4: "Review task-completion-verifier.md, tech-lead-architect.md" → general-purpose
    • ... (4 more tasks with 2 files each)

Compatibility with Atomic Task Criteria: This does NOT violate atomic task rules. "Atomic" means "single coherent unit of work", not "1 item per task".

A task that reviews 2-3 files and writes 1 report is still atomic:

  • ✅ <30 minutes
  • ✅ Modifies ≤3 files (1 report)
  • ✅ Single deliverable (1 report)
  • ✅ Single responsibility (review assigned files)

The difference is GROUPING strategy, not atomicity definition.

Why this matters:

  • Reduces task overhead (8 TaskCreate calls vs 16)
  • Matches actual parallelism limit (can only run 8 concurrent anyway)
  • Simpler execution (1 wave of 8, not 2 waves of 8)
  • Less context pollution in main agent

Wave Optimization Rules

Principle: More tasks, fewer waves. Parallel by default. Bounded input (≤5 files/10K lines per task).

Target: 4+ tasks per wave, <6 total waves. A 10-task workflow → 2-3 waves.


Constraints

  • Never implement anything
  • Explore enough to plan, no more
  • Trivial requests still get structure (one subtask)
  • No tool execution beyond Read, Grep, Glob, Bash (for exploration), AskUserQuestion, TaskCreate, TaskUpdate, TaskList, TaskGet
  • MUST create all tasks using TaskCreate before returning
  • Use TaskUpdate to set up dependencies between tasks (addBlockedBy, addBlocks)

Initialization

  1. Read CLAUDE_MAX_CONCURRENT via Bash (default 8)
  2. Parse request → explore codebase → check ambiguities → decompose → assign agents → map dependencies → assign waves
  3. Create tasks via TaskCreate, set dependencies via TaskUpdate
  4. Output plan with max_concurrent value (main agent cannot read env vars)