# Generate Spec - Auto-Generate New Specifications

**Purpose:** Automatically create new specification files based on discovered patterns and meta-level insights.

## Usage

```bash
/generate-spec [source] [focus] [output_name]
```

### Parameters
- `source`: What to analyze - "patterns", "logs", "existing_specs", "all" (default: "all")
- `focus`: Generation focus - "novel", "variant", "evolution", "hybrid" (default: "novel")
- `output_name`: Output filename (default: auto-generated)

### Examples

```bash
# Generate completely novel spec from all patterns
/generate-spec all novel

# Create variant of existing specs
/generate-spec existing_specs variant custom_spec

# Evolve specs based on improvement logs
/generate-spec logs evolution

# Hybrid approach combining multiple sources
/generate-spec all hybrid advanced_spec
```

## Command Implementation

You are the **Auto-Specification Generator**. Your role is to analyze patterns and generate new, high-quality specification files using meta-prompting principles.

### Phase 1: Pattern Discovery

1. **Load Source Materials**

   Based on `{{source}}` parameter:

   - **patterns**: Analyze output files for recurring themes, structures, quality patterns
   - **logs**: Review improvement_log/ for meta-insights and successful strategies
   - **existing_specs**: Study specs/ directory for specification patterns
   - **all**: Comprehensive analysis of all sources

2. **Extract Structural Patterns** (Meta-Prompting Principle)

   Focus on **structure over content**:
   - What architectural patterns repeat?
   - What abstract frameworks are most successful?
   - What logical flows work best?
   - What syntax templates are most generalizable?

3. **Identify Meta-Level Insights**

   - Which specification elements drive best results?
   - What constraints enable creativity vs. limit it?
   - How do quality criteria correlate with outcomes?
   - What patterns emerge across 10+ iterations?

### Phase 2: Specification Synthesis

4. **Apply Generation Focus**

   **Novel Mode**: Create entirely new specification type
   - Identify unexplored problem domains
   - Combine patterns in novel ways
   - Introduce new quality dimensions
   - Define fresh creative constraints

   **Variant Mode**: Create variation of existing spec
   - Take best-performing existing spec
   - Modify key parameters (complexity, domain, constraints)
   - Maintain proven structural patterns
   - Add 2-3 innovative elements

   **Evolution Mode**: Evolve specs based on learnings
   - Start with baseline spec
   - Apply improvement log insights
   - Enhance quality criteria based on metrics
   - Refine constraints for better results

   **Hybrid Mode**: Combine multiple successful patterns
   - Merge structural elements from top specs
   - Create multi-dimensional quality criteria
   - Balance constraints from different domains
   - Synthesize meta-insights into unified spec

5. **Structure-Oriented Spec Design**

   Use meta-prompting template:

   ```markdown
   # [Spec Title] - Auto-Generated Specification

   **Generated From:** {{source}}
   **Focus:** {{focus}}
   **Created:** {{timestamp}}
   **Meta-Patterns Applied:** [list key patterns]

   ## Overview
   [Abstract description of what to generate]

   ## Structural Framework
   [High-level architecture and organization]

   ## Generation Patterns
   [Repeatable patterns for content creation]

   ### Pattern 1: [Name]
   - Abstract Structure: [template]
   - Reasoning Flow: [logical steps]
   - Quality Criteria: [measurable]

   ### Pattern 2: [Name]
   - Abstract Structure: [template]
   - Reasoning Flow: [logical steps]
   - Quality Criteria: [measurable]

   ## Quality Dimensions
   [Measurable criteria focusing on structure and principles]

   1. **Structural Integrity** (0-10)
      - Clear architectural patterns
      - Logical organization
      - Consistent abstraction levels

   2. **Generalizability** (0-10)
      - Pattern applicability across contexts
      - Minimal example-dependency
      - Principle-driven design

   3. **Innovation** (0-10)
      - Novel pattern combinations
      - Creative constraint application
      - Unexpected yet coherent results

   4. **Meta-Awareness** (0-10)
      - Self-referential understanding
      - Reflection on generation process
      - Evolution potential

   ## Creative Constraints
   [Constraints that enable creativity]

   - Must follow [structural pattern]
   - Should apply [abstract principle]
   - Cannot duplicate [specific anti-pattern]
   - Must demonstrate [meta-capability]

   ## Naming Convention
   [Pattern-based naming system]

   ## File Structure
   [Expected organization]

   ## Success Criteria
   [How to evaluate generated output]

   ## Meta-Instructions for Generators
   [Structure-oriented guidance for sub-agents]

   When generating content for this spec:
   1. Focus on STRUCTURE over content details
   2. Apply ABSTRACT frameworks, not specific examples
   3. Use PATTERN-based reasoning
   4. Maintain META-AWARENESS of your process
   5. Reflect and improve with each iteration

   ## Evolution Hooks
   [How this spec can evolve further]

   - Complexity progression: [path]
   - Domain variations: [options]
   - Pattern extensions: [possibilities]
   - Meta-level enhancements: [future capabilities]
   ```

### Phase 3: Validation and Enhancement

6. **Self-Validation**

   Review generated spec against criteria:
   - ✓ Is it structurally sound?
   - ✓ Are patterns generalizable?
   - ✓ Does it minimize example-dependency?
   - ✓ Is quality measurable?
   - ✓ Can it evolve further?
   - ✓ Does it embody meta-prompting principles?

7. **Enhancement Opportunities**

   - Add 2-3 creative constraints that enable uniqueness
   - Include meta-instructions for self-improvement
   - Design evolution hooks for future iterations
   - Ensure success criteria are objective

### Phase 4: Output Generation

8. **Write Specification File**

   Create `specs/{{output_name}}.md` with complete specification.

9. **Generate Companion Files**

   Create supporting materials:

   **specs/{{output_name}}_guide.md**: Usage guide
   ```markdown
   # Guide: {{output_name}}

   ## Quick Start
   [How to use this spec]

   ## Pattern Explanations
   [Detail each pattern]

   ## Quality Assessment
   [How to evaluate results]

   ## Evolution Path
   [How to extend this spec]
   ```

   **specs/{{output_name}}_examples.md**: Abstract examples
   ```markdown
   # Abstract Examples: {{output_name}}

   ## Structural Template 1
   [Framework without specific content]

   ## Reasoning Pattern 1
   [Logical flow template]

   ## Quality Benchmark
   [What excellence looks like structurally]
   ```

10. **Document Generation Process**

    Create `improvement_log/spec_generation_{{timestamp}}.md`:

    ```markdown
    # Spec Generation Log - {{output_name}}

    ## Source Analysis
    [What was analyzed]

    ## Patterns Discovered
    [Structural patterns found]

    ## Meta-Insights Applied
    [Meta-prompting principles used]

    ## Generation Decisions
    [Why certain choices were made]

    ## Validation Results
    [How spec was validated]

    ## Recommended Usage
    [Best practices for using this spec]

    ## Future Evolution
    [How this spec can improve]
    ```

### Phase 5: Integration

11. **Update Spec Index**

    Add entry to `specs/README.md`:

    ```markdown
    ### {{output_name}} (Auto-Generated)
    - **Focus:** {{focus}}
    - **Patterns:** [key patterns]
    - **Best For:** [use cases]
    - **Evolution:** [maturity level]
    ```

12. **Link to Meta-Prompts**

    Update `meta_prompts/spec_generator.md` with:
    - Successful generation patterns used
    - New structural templates discovered
    - Enhanced reasoning frameworks

## Meta-Prompting for Spec Generation

This command applies meta-prompting to generate specifications:

```
ABSTRACTION: Spec generation is pattern synthesis
STRUCTURE: Load sources → Extract patterns → Synthesize → Validate → Output
REASONING: Generalizable frameworks over specific examples

SELF_REFLECTION:
- Am I creating structural templates or just content?
- Are my patterns generalizable across domains?
- Does the spec enable meta-level capabilities?
- Can generators using this spec improve themselves?

META_PATTERN:
Specs should define HOW to think, not WHAT to create.
They provide frameworks, not examples.
They enable evolution, not just execution.
```

## Output Files

```
specs/
├── {{output_name}}.md
├── {{output_name}}_guide.md
├── {{output_name}}_examples.md
└── README.md (updated)

improvement_log/
├── spec_generation_{{timestamp}}.md
└── patterns_discovered_{{timestamp}}.json

meta_prompts/
└── spec_generator.md (updated)
```

## Advanced Features

### Pattern Library Evolution

Maintain `specs/pattern_library.md` with all discovered patterns:
- Structural templates
- Reasoning frameworks
- Quality dimensions
- Constraint types

### Spec Lineage Tracking

Document spec genealogy:
- Which specs influenced this one
- What patterns were combined
- How it evolved from parent specs
- Potential child spec variations

### Auto-Testing Integration

Generate test cases for new specs:
- Run small batch (3-5 iterations)
- Validate pattern effectiveness
- Measure quality metrics
- Refine spec based on results

## Success Criteria

A successfully generated spec:
1. Defines clear structural patterns
2. Minimizes example-dependency
3. Enables generalizable reasoning
4. Includes meta-awareness instructions
5. Has measurable quality criteria
6. Shows evolution potential
7. Embodies meta-prompting principles

---

*This command generates specifications using meta-prompting principles. It creates structural frameworks and abstract patterns that enable efficient, generalizable content generation while maintaining meta-level self-improvement capabilities.*
