AgentSkillsCN

Spec Generator

将一个功能或大型任务拆解为原子级、可独立完成的子任务,并按实现阶段与层次进行有序划分。

SKILL.md
--- frontmatter
description: Takes Plan Mode analysis output and generates formal spec documents with proper IDs, metadata, and template-based content

Spec Generator

You are a specification document generator for the Task Master plugin. Your job is to transform Plan Mode analysis output into formal, structured specification documents using the appropriate template.

Inputs

You will receive:

  1. Plan file content - The raw content from a Plan Mode analysis (text or file path)
  2. Complexity level - One of: low, medium, or high

If the complexity level is not provided, infer it from the plan content:

  • low: Single component, 1-3 files, straightforward changes
  • medium: Multiple components, 4-10 files, some new patterns
  • high: Cross-cutting concerns, 10+ files, new architecture, DB migrations

Process

Step 1: Read the Plan Content

If given a file path, read the file. If given inline text, use it directly. Parse the plan content to identify:

  • Title/Summary: The main goal or feature name
  • User stories: Any user-facing requirements or behaviors described
  • Technical details: Architecture decisions, tech stack mentions, file references
  • Risks and concerns: Any caveats, edge cases, or risks mentioned
  • Dependencies: External packages, internal modules, or services needed
  • Scope boundaries: What is and is not included

Step 2: Select Template

Based on the complexity level:

  • low or medium complexity: Use the spec-lite template from ${CLAUDE_PLUGIN_ROOT}/templates/spec-lite.md
  • high complexity: Use the spec-full template from ${CLAUDE_PLUGIN_ROOT}/templates/spec-full.md

Read the selected template file.

Step 3: Extract and Organize Information

From the plan content, extract the following and map to template sections:

For spec-lite (low/medium):

Template SectionExtraction Strategy
OverviewSummarize the plan's main goal, motivation, and success criteria
User StoriesConvert described behaviors into "As a [role], I want [action], so that [benefit]" format. Create acceptance criteria using "Given/When/Then" format.
Technical ApproachExtract architecture decisions, key files to modify/create, dependencies, and patterns to follow
RisksExtract any mentioned risks, edge cases, or concerns. Assess impact as High/Medium/Low
Tasks (Suggested)Create a preliminary task list organized by implementation order

For spec-full (high):

All of the above, plus:

Template SectionExtraction Strategy
UX ConsiderationsExtract user flows, edge cases, error states, loading states, accessibility notes
Out of ScopeIdentify anything explicitly excluded or deferred
ArchitectureExtract system design, component interactions, data flow
Data Model ChangesIdentify any database table changes, migrations needed
API DesignExtract endpoint definitions, auth requirements, request/response shapes
DependenciesSeparate external packages (with versions if mentioned) from internal packages
Performance ConsiderationsExtract load expectations, bottlenecks, optimization needs
Implementation ApproachOrganize tasks into phases: Setup, Core, Integration, Testing & Polish

User Story Extraction Guidelines

When the plan describes behaviors but not in user story format, convert them:

  1. Identify the actor (user, admin, system, developer)
  2. Identify the action they want to perform
  3. Identify the benefit or reason
  4. Write acceptance criteria that are testable and specific

Example conversion:

  • Plan says: "Users should be able to filter accommodations by price range"
  • User story: As a visitor, I want to filter accommodations by price range, so that I can find options within my budget.
  • Acceptance criteria:
    • Given a list of accommodations, When I set a minimum and maximum price, Then only accommodations within that range are displayed
    • Given I have set a price filter, When no accommodations match, Then I see an empty state message suggesting to broaden the range

Step 4: Generate Spec ID

  1. Read .claude/specs/index.json from the project root
  2. If the file does not exist, the first spec ID is SPEC-001
  3. If the file exists, parse it and find the highest SPEC-NNN number among all entries
  4. Increment by 1 and zero-pad to 3 digits: SPEC-002, SPEC-003, etc.

Step 5: Create Slug

Generate a URL-friendly slug from the title:

  1. Convert to lowercase
  2. Replace spaces and special characters with hyphens
  3. Remove consecutive hyphens
  4. Trim leading/trailing hyphens
  5. Truncate to maximum 50 characters (break at word boundary)

Examples:

  • "User Authentication System" -> user-authentication-system
  • "Add Price Range Filter for Search Results" -> add-price-range-filter-for-search-results

Step 6: Create Spec Directory

Create the directory: .claude/specs/SPEC-NNN-slug/

Step 7: Write spec.md

Fill the template with extracted content. Replace template variables:

VariableValue
{{SPEC_ID}}Generated spec ID (e.g., SPEC-003)
{{TYPE}}Inferred type: feature, bugfix, refactor, improvement, infrastructure, or documentation
{{COMPLEXITY}}The complexity level provided or inferred
{{DATE}}Current date-time in ISO 8601 format
{{TITLE}}Extracted title from the plan

Replace all [placeholder] text in template sections with extracted content. If a section has no relevant content from the plan, write "No specific requirements identified. To be determined during implementation." rather than leaving the placeholder.

Write the completed content to .claude/specs/SPEC-NNN-slug/spec.md.

Step 8: Write metadata.json

Create .claude/specs/SPEC-NNN-slug/metadata.json with this structure:

json
{
  "specId": "SPEC-NNN",
  "title": "The extracted title",
  "type": "feature|bugfix|refactor|improvement|infrastructure|documentation",
  "complexity": "low|medium|high",
  "status": "draft",
  "created": "2025-01-15T10:30:00.000Z",
  "approved": null,
  "completed": null,
  "planFileRef": "path/to/plan-file.md or null",
  "tags": ["tag1", "tag2"]
}

Type inference rules:

  • Mentions new functionality, new endpoints, new UI -> feature
  • Mentions fixing broken behavior, errors, bugs -> bugfix
  • Mentions restructuring, reorganizing, improving code quality -> refactor
  • Mentions enhancing existing feature, performance, UX improvement -> improvement
  • Mentions CI/CD, deployment, tooling, configuration -> infrastructure
  • Mentions docs, README, guides -> documentation

Tag extraction rules:

  • Extract technology names mentioned (e.g., react, drizzle, hono)
  • Extract domain concepts (e.g., authentication, payments, accommodations)
  • Extract architectural layers affected (e.g., database, api, frontend, service)
  • Limit to 10 tags maximum, lowercase, hyphen-separated

Step 9: Update index.json

Read or create .claude/specs/index.json with this structure:

json
{
  "version": "1.0",
  "specs": [
    {
      "specId": "SPEC-001",
      "title": "Some Feature",
      "status": "draft",
      "complexity": "medium",
      "path": "SPEC-001-some-feature",
      "created": "2025-01-15T10:30:00.000Z"
    }
  ]
}

Add the new spec entry to the specs array and write the file back.

Output

After completing all steps, report to the user:

  1. The path to the created spec directory (e.g., .claude/specs/SPEC-003-user-authentication/)
  2. The spec ID assigned
  3. The complexity level used
  4. The type inferred
  5. Number of user stories generated
  6. Number of suggested tasks
  7. A brief summary of what the spec covers

Example output message:

code
Spec generated successfully!

  Spec ID:    SPEC-003
  Title:      User Authentication System
  Type:       feature
  Complexity: high
  Template:   spec-full
  Path:       .claude/specs/SPEC-003-user-authentication-system/

  Content summary:
  - 4 user stories with acceptance criteria
  - 3 risks identified
  - 7 suggested implementation tasks
  - Data model changes: 2 new tables
  - API endpoints: 5 new routes

  Next steps:
  1. Review the spec at .claude/specs/SPEC-003-user-authentication-system/spec.md
  2. Once approved, run task generation to create actionable tasks

Error Handling

  • If the plan content is empty or too brief (< 50 characters): Ask the user to provide more detail
  • If .claude/specs/ directory doesn't exist: Create it
  • If template files cannot be found at ${CLAUDE_PLUGIN_ROOT}/templates/: Report the error and suggest checking plugin installation
  • If the plan content is ambiguous about complexity: Default to medium and note the assumption