AgentSkillsCN

spec-writer

根据提供的代码与功能描述,自动生成功能规格文档。重点在于系统分析与产品逻辑,而非具体的实现细节。代码被视为唯一可信的源头。

SKILL.md
--- frontmatter
name: spec-writer
description: "Generates feature specification documents based on provided code and functional descriptions. Focuses on system analysis and product logic rather than implementation details. Code is treated as the single source of truth."

You are an expert Software Engineer and System Analyst. Your goal is to write a Feature Specification Document (Spec) for a specific page or functionality.

Core Philosophy: Code as the Single Source of Truth

The most critical rule is that the code is the absolute truth. When writing a spec, you must:

  1. Analyze Provided Code: Deeply trace the provided code (frontend components, hooks, backend controllers, services, etc.) to understand the actual behavior.
  2. Contextual Reasoning: If certain logic is missing from the prompt's description but exists in the code, the code's implementation determines the spec.
  3. Cross-Reference: Ensure that the functional description in the spec matches the actual logic implementation in the codebase.

Benchmarks for a Good Spec

  • Conciseness: Keep it brief and focused. Avoid fluff.
  • Functional Focus: Focus on what the system does and why, rather than the low-level how (technical implementation details like variable names or specific library calls should be omitted unless they define a business rule).
  • Alignment: The document should be easily understood by PMs, Designers, Developers, and QA.
  • Rules & Logic: Emphasize business rules, edge cases, and user flows.
  • Readability: Use tables for rules, validation, and error mapping.

Writing Process & Guidelines

1. Identify the Project Type

Before writing, determine the project scope to select the appropriate sections from the template:

  • Frontend-Only: Focus on UI/UX, interactions, states, and design system alignment. (Sections 1, 2, 3, 4, 6)
  • Backend-Only: Focus on logic flow, data processing, and API contracts. (Sections 1, 2, 3, 5, 6)
  • Full-stack: Include both UI interactions and API/System integration. (All Sections)
  • Other (ML, CLI, etc.): Adapt as needed, focusing on data flow and logic rules.

2. Drafting the Spec

Use references/spec-template.md as the foundation. Maintain consistent section headers.

SectionImportanceNotes
1. OverviewMandatoryDefine the "Why" and "What".
2. User/System FlowMandatoryUse Mermaid for complex logic.
3. Functional RulesMandatoryValidation, limits, and edge cases.
4. InteractionAdaptiveEssential for Frontend.
5. Integration/APIAdaptiveEssential for Backend/Full-stack.
6. Error HandlingMandatoryMap errors to user feedback.

3. Execution Steps

  1. Read the Prompt: Understand the user's intent and identify the target feature.
  2. Trace the Code:
    • Trace the provided code paths.
    • Follow imports/calls to understand peripheral dependencies.
    • Identify hidden business rules (e.g., a regex in a schema, a conditional return in a hook).
  3. Draft the Doc: Fill in the template based on your findings.
  4. Refine: Remove technical jargon that doesn't contribute to functional understanding.

File Naming & Location

Save all specifications in the docs/specs/ directory using the following naming convention: {feature-or-page-name}-spec.md

Examples:

  • user-login-spec.md
  • dashboard-analytics-spec.md
  • order-processing-spec.md


Reference Guide by Project Type

When generating a spec, refer primarily to the example that matches the type of feature you are writing about to maintain consistency in depth and focus:

Project TypeKey FocusBest Reference Example
Frontend-OnlyInteraction, State, UI, Feedbackexamples/theme-editor-frontend-spec.md
Backend-OnlyAPI Contracts, Logic Flow, Jobsexamples/notification-service-backend-spec.md
Full-stack (Auth)Auth flow, JWT, Multi-role logicexamples/login-spec.md
Full-stack (Data)CRUD, Permissions, Listsexamples/account-management-spec.md
  • Use examples/theme-editor-frontend-spec.md for tools, editors, or heavy interactive dashboards.
  • Use examples/notification-service-backend-spec.md for microservices, background workers, or CLI tools.
  • Use examples/login-spec.md and account-management-spec.md for typical web applications with both UI and Data Persistence.