---
name: 'step-03-generate'
description: 'Generate the technical specification document and save it to the output folder'

# Path Definitions
workflow_path: '{project-root}/bmad-custom-src/workflows/update-component-spec'

# File References
thisStepFile: '{workflow_path}/steps/step-03-generate.md'
workflowFile: '{workflow_path}/workflow.md'
outputFolder: '{project-root}/docs/specs'
templateFile: '{workflow_path}/templates/tech-spec-template.md'
---

# Step 3: Generate Tech Spec

## STEP GOAL:

To generate the complete technical specification document using the analysis results from step 2 and save it to the output folder.

## MANDATORY EXECUTION RULES (READ FIRST):

### Universal Rules:

- **CRITICAL**: Read the complete step file before taking any action
- Generate document autonomously using analysis data
- Save document to correct output location

### Role Reinforcement:

- You are a Technical Documentation Specialist
- If you already have been given a name, communication_style and identity, continue to use those while playing this new role
- You bring expertise in technical writing and documentation structure
- This step is mostly autonomous with final confirmation

### Step-Specific Rules:

- Focus ONLY on document generation and saving
- Use all analysis data from step 2
- Follow the template structure exactly
- Ensure output file is saved correctly

## EXECUTION PROTOCOLS:

- Load the tech spec template structure
- Populate all sections with analysis data
- Generate usage examples based on code patterns
- Save document to {outputFolder}/{component-name}.md
- Display success confirmation to user

## CONTEXT BOUNDARIES:

- All analysis data from step 2 is available
- Component name and language are known
- Template structure defines the output format
- This is the final step of the workflow

## GENERATION SEQUENCE:

### 1. Prepare Output

Determine output file path:
- Component name from step 1
- Output folder: `{outputFolder}`
- Full path: `{outputFolder}/{component-name}.md`

Ensure output folder exists.

### 2. Generate Document Content

Create the tech spec following this structure:

```markdown
# Component Tech Spec: {component-name}

> Generated: {current-date} | Source: {source-path}

## Overview

[Generate a clear description of what the component does and why it exists, based on:
- File-level documentation found
- Function names and purposes
- Overall structure and patterns
- Inferred purpose from code behavior]

## API / Interface

### Functions

[For each public/exported function:]

#### `functionName(param1: type, param2: type): returnType`

[Description from JSDoc/docstring or inferred from code]

**Parameters:**
- `param1` (type): [description]
- `param2` (type): [description]

**Returns:** [type] - [description]

### Methods / Properties

[For each class, list public methods and properties:]

#### Class: `ClassName`

**Constructor:**
- `new ClassName(params)`

**Methods:**
- `methodName(params): returnType` - [description]

**Properties:**
- `propertyName`: type - [description]

## Dependencies

### Internal

[List internal project imports:]
- `module/path` - [what is used]

### External

[List third-party packages:]
- `package-name` - [what is used, e.g., "HTTP client for API calls"]

### Services

[List external services/APIs:]
- [Service name] - [purpose]

## Data Flow / State

[Describe how data moves through the component:]

**Inputs:**
- [Input sources and their types]

**Processing:**
- [Key transformations and logic]

**Outputs:**
- [What the component produces/returns]

**State Management:**
- [Any state patterns used, or "Stateless" if none]

## Usage Examples

```{language}
// Example 1: Basic usage
[Generate realistic usage example based on the API]

// Example 2: With options/configuration
[Generate example showing common configuration]
```

---

*This spec was auto-generated. Review and update as needed.*
```

### 3. Populate Sections

For each section:

**Overview:**
- Synthesize purpose from code comments and structure
- Keep it concise but informative
- Focus on the "what" and "why"

**API / Interface:**
- Include all public/exported functions
- Document parameters with types
- Include return types
- Add descriptions from docstrings or infer from names

**Dependencies:**
- Categorize all imports found
- Note what is used from each dependency
- Include version info if available

**Data Flow:**
- Trace data from inputs to outputs
- Note any state management
- Describe key transformations

**Usage Examples:**
- Generate realistic examples
- Show common use cases
- Use correct syntax for the language

### 4. Write Output File

Save the generated document to: `{outputFolder}/{component-name}.md`

If file already exists, overwrite it (no change tracking per requirements).

### 5. Display Success

"**Tech Spec Generated Successfully!**

**File:** `{outputFolder}/{component-name}.md`

**Summary:**
- Component: {component-name}
- Language: {language}
- Sections: Overview, API/Interface, Dependencies, Data Flow, Usage Examples

The tech spec has been saved. You can review and edit it as needed.

---

**Workflow Complete**"

### 6. End Workflow

This is the final step. The workflow is complete.

No menu needed - workflow ends after success message.

## CRITICAL STEP COMPLETION NOTE

After saving the document and displaying the success message, the workflow is complete. No further steps are needed.

---

## SYSTEM SUCCESS/FAILURE METRICS

### SUCCESS:

- Tech spec document generated with all sections
- Document saved to correct output location
- All analysis data incorporated
- Success message displayed to user
- Workflow completed gracefully

### SYSTEM FAILURE:

- Missing sections in output
- Not saving to correct location
- Ignoring analysis data
- Not displaying completion status
- Attempting to load non-existent next step

**Master Rule:** Skipping steps, optimizing sequences, or not following exact instructions is FORBIDDEN and constitutes SYSTEM FAILURE.
