spec-writer
Scannednpx machina-cli add skill Bosh-Kuo/awesome-agent-toolkit/spec-writer --openclawYou 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:
- Analyze Provided Code: Deeply trace the provided code (frontend components, hooks, backend controllers, services, etc.) to understand the actual behavior.
- Contextual Reasoning: If certain logic is missing from the prompt's description but exists in the code, the code's implementation determines the spec.
- 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.
| Section | Importance | Notes |
|---|---|---|
| 1. Overview | Mandatory | Define the "Why" and "What". |
| 2. User/System Flow | Mandatory | Use Mermaid for complex logic. |
| 3. Functional Rules | Mandatory | Validation, limits, and edge cases. |
| 4. Interaction | Adaptive | Essential for Frontend. |
| 5. Integration/API | Adaptive | Essential for Backend/Full-stack. |
| 6. Error Handling | Mandatory | Map errors to user feedback. |
3. Execution Steps
- Read the Prompt: Understand the user's intent and identify the target feature.
- 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).
- Draft the Doc: Fill in the template based on your findings.
- 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.mddashboard-analytics-spec.mdorder-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 Type | Key Focus | Best Reference Example |
|---|---|---|
| Frontend-Only | Interaction, State, UI, Feedback | examples/theme-editor-frontend-spec.md |
| Backend-Only | API Contracts, Logic Flow, Jobs | examples/notification-service-backend-spec.md |
| Full-stack (Auth) | Auth flow, JWT, Multi-role logic | examples/login-spec.md |
| Full-stack (Data) | CRUD, Permissions, Lists | examples/account-management-spec.md |
- Use
examples/theme-editor-frontend-spec.mdfor tools, editors, or heavy interactive dashboards. - Use
examples/notification-service-backend-spec.mdfor microservices, background workers, or CLI tools. - Use
examples/login-spec.mdandaccount-management-spec.mdfor typical web applications with both UI and Data Persistence.
Source
git clone https://github.com/Bosh-Kuo/awesome-agent-toolkit/blob/main/skills/spec-writer/SKILL.mdView on GitHub Overview
Spec-writer generates a concise Feature Specification Document by analyzing the provided code and functional descriptions. It treats code as the single source of truth, tracing behavior, rules, and data flows to produce a spec aligned with PM, design, and QA needs.
How This Skill Works
It deeply traces code paths, imports, and service calls to uncover actual behavior. It cross-references this with the stated functional description and outputs a structured document using the project's template, highlighting business rules, edge cases, and user flows while omitting low-level implementation details.
When to Use It
- When you need a spec anchored in code for a new feature.
- When there are missing details in the narrative but code implements them.
- For frontend UI flows that must align with backend behavior.
- For API contracts and data processing logic in full-stack features.
- For handoff to PM/QA or during code refactors to update specifications.
Quick Start
- Step 1: Gather the feature name, code references, and functional description.
- Step 2: Run or invoke spec-writer to generate a draft spec using the code as truth.
- Step 3: Review the draft with PM/QA, adjust requirements or edge cases, and finalize.
Best Practices
- Start with the code as the truth and extract business rules directly from code paths.
- Use the prescribed template sections (Overview, User/System Flow, Functional Rules, Interaction, Integration/API, Error Handling).
- Capture edge cases, error mappings, and validation rules in a clear table.
- Keep language concise and aligned with stakeholder needs (PM/Design/QA).
- Cross-check the draft spec against the codebase to ensure traceability and accuracy.
Example Use Cases
- Spec for a login feature derived from the authentication module, capturing success/failure flows and security checks.
- Spec for an order processing workflow from backend services, detailing state transitions and error states.
- Spec for a feature-flag gated flow, outlining when and how UI and API behavior change.
- Spec for a dashboard data fetch page, defining data sources, caching rules, and rendering expectations.
- Spec for a file upload component with validation, size limits, and virus-scan integration.