Marketplace

spec-generator

Generates implementation specifications from conversation context optionally enriched with GitHub issue data

model: claude-opus-4-5

$ インストール

git clone https://github.com/fractary/claude-plugins /tmp/claude-plugins && cp -r /tmp/claude-plugins/plugins/spec/skills/spec-generator ~/.claude/skills/claude-plugins

// tip: Run this command in your terminal to install the skill


name: spec-generator description: Generates implementation specifications from conversation context optionally enriched with GitHub issue data model: claude-opus-4-5

Spec Generator Skill

You are invoked directly by the /fractary-spec:create command to preserve full conversation context. This bypasses the agent layer to ensure planning discussions are captured in specs.

<CRITICAL_RULES>

  1. ALWAYS follow the workflow/generate-from-context.md workflow
  2. ALWAYS use full conversation context as primary source
  3. If work_id provided or auto-detected: fetch issue via repo plugin and merge contexts
  4. ALWAYS classify work type before selecting template
  5. ALWAYS use proper naming conventions:
    • Issue-linked: WORK-{issue:05d}-{slug}.md (e.g., WORK-00084-feature.md)
    • Standalone: SPEC-{timestamp}-{slug}.md (e.g., SPEC-20250115143000-feature.md)
    • Zero-pad issue numbers to 5 digits
  6. ALWAYS save specs to /specs directory (local path from config)
  7. ALWAYS include frontmatter with metadata
  8. ALWAYS link spec back to issue when work_id provided or auto-detected
  9. If repo plugin not found: gracefully degrade to standalone spec creation </CRITICAL_RULES>
{
  "work_id": "123",        // Optional: link to issue and enrich with issue data (auto-detected from branch if omitted)
  "template": "basic|feature|infrastructure|api|bug",  // Optional: override auto-detection
  "context": "Explicit additional context",  // Optional: extra context to consider
  "force": false           // Optional: force creation even if spec already exists (default: false)
}

Auto-Detection: If work_id is not provided, automatically attempt to read from repo plugin's git status cache to detect issue ID from current branch name (e.g., feat/123-name123). If repo plugin not found or no issue detected, creates standalone spec.

Graceful Degradation: Missing work_id + no repo plugin = standalone spec (SPEC-{timestamp}-* naming).

Idempotency: If spec(s) already exist for the work_id and force is false, skip creation and return existing spec info. Use force: true to create additional specs.

Follow workflow/generate-from-context.md for detailed step-by-step instructions.

High-level process:

  1. Auto-detect work_id from branch (if not provided and repo plugin available)
  2. Validate inputs
  3. Load configuration
  4. Check for existing specs (if work_id present)
    • If spec(s) exist AND force=false: Read existing spec(s), return "skipped" response
    • If spec(s) exist AND force=true: Continue with unique slug generation
    • If no specs exist: Continue normally
  5. Extract conversation context (primary source)
  6. Fetch issue data (if work_id detected or provided)
  7. Merge contexts (conversation + issue if available)
  8. Auto-detect template from merged context
  9. Generate spec filename (WORK-* or SPEC-* based on work_id presence)
    • If force=true and specs exist: Generate unique slug to avoid collision
  10. Parse merged context into template variables
  11. Select and fill template
  12. Add frontmatter with metadata
  13. Save spec to /specs directory
  14. Link to GitHub issue (if work_id present)
  15. Return confirmation

<COMPLETION_CRITERIA> You are complete when:

  • Spec file created in /specs directory
  • Spec contains valid frontmatter
  • Spec content filled from source data (conversation, issue, or merged)
  • GitHub issue commented with spec location (if work_id/issue_number present)
  • Success message returned with spec path and source information
  • No errors occurred

Additional criteria for context-based mode:

  • Full conversation context was analyzed and incorporated
  • If work_id provided: issue data was fetched and merged
  • Template was auto-detected from merged context (or override used)
  • Appropriate naming convention applied (WORK-* or SPEC-*) </COMPLETION_CRITERIA>

See: plugins/faber/docs/RESPONSE-FORMAT.md for complete specification.

Output structured messages:

Start:

🎯 STARTING: Spec Generator
Work ID: #123 (auto-detected from branch: feat/123-name) [or "not detected" or "provided"]
Template: feature (auto-detected) [or "override: feature"]
───────────────────────────────────────

During execution, log key steps:

  • ✓ Auto-detected issue #123 from branch (or ℹ No issue detected)
  • ✓ Conversation context extracted
  • ✓ Issue data fetched (if work_id)
  • ✓ Contexts merged (if applicable)
  • ✓ Work type classified: feature
  • ✓ Template selected: spec-feature.md.template
  • ✓ Spec generated
  • ✓ GitHub comment added (if applicable)

End:

✅ COMPLETED: Spec Generator
Spec created: /specs/WORK-00123-user-auth.md
Template used: feature
Source: Conversation + Issue #123
GitHub comment: ✓ Added
───────────────────────────────────────
Next: Begin implementation using spec as guide

Success Response (with work_id):

{
  "status": "success",
  "message": "Specification generated: WORK-00123-user-auth.md",
  "details": {
    "spec_path": "/specs/WORK-00123-user-auth.md",
    "work_id": "123",
    "issue_url": "https://github.com/org/repo/issues/123",
    "template": "feature",
    "source": "conversation+issue",
    "github_comment_added": true
  }
}

Success Response (standalone):

{
  "status": "success",
  "message": "Specification generated: SPEC-20250115143000-user-auth.md",
  "details": {
    "spec_path": "/specs/SPEC-20250115143000-user-auth.md",
    "template": "feature",
    "source": "conversation",
    "github_comment_added": false
  }
}

Skipped Response (Spec Already Exists):

{
  "status": "skipped",
  "message": "Specification already exists for issue #123",
  "details": {
    "work_id": "123",
    "existing_specs": [
      "/specs/WORK-00123-user-auth.md"
    ],
    "existing_spec_count": 1,
    "action": "read_existing"
  },
  "hint": "Use --force to create additional spec"
}

Output for skipped:

🎯 STARTING: Spec Generator
Work ID: #123 (auto-detected from branch)
───────────────────────────────────────

ℹ Existing spec(s) found for issue #123:
  1. /specs/WORK-00123-user-auth.md

✓ Reading existing specification(s)...
✓ Spec context loaded into session

⏭ SKIPPED: Spec already exists
Existing spec: /specs/WORK-00123-user-auth.md
───────────────────────────────────────
Hint: Use --force to create additional spec

Warning Response (Issue Data Incomplete):

{
  "status": "warning",
  "message": "Specification generated with incomplete issue data",
  "details": {
    "spec_path": "/specs/WORK-00123-user-auth.md",
    "work_id": "123",
    "template": "feature",
    "completeness_score": 0.75
  },
  "warnings": [
    "Issue description is empty - using conversation context only",
    "No acceptance criteria defined in issue"
  ],
  "warning_analysis": "The spec was generated but may be incomplete because the issue lacks detailed requirements",
  "suggested_fixes": [
    "Add description to issue #123",
    "Add acceptance criteria to issue",
    "Review generated spec and add missing sections"
  ]
}

Failure Response (Issue Not Found):

{
  "status": "failure",
  "message": "Failed to generate spec - issue #999 not found",
  "details": {
    "work_id": "999"
  },
  "errors": [
    "Issue #999 does not exist in repository"
  ],
  "error_analysis": "The specified work_id does not correspond to an existing issue",
  "suggested_fixes": [
    "Verify issue number is correct",
    "Create the issue first: /work:issue-create",
    "Generate standalone spec without work_id"
  ]
}

Failure Response (Write Failed):

{
  "status": "failure",
  "message": "Failed to write spec file",
  "details": {
    "spec_path": "/specs/WORK-00123-user-auth.md"
  },
  "errors": [
    "Permission denied: /specs/WORK-00123-user-auth.md"
  ],
  "error_analysis": "Unable to write to the specs directory - permission or path issue",
  "suggested_fixes": [
    "Check /specs directory exists",
    "Verify write permissions",
    "Run: mkdir -p specs"
  ]
}

<ERROR_HANDLING> Handle errors using the standard FABER response format:

  1. Spec Already Exists (when force=false): Return "skipped" status with existing spec paths (not an error)
  2. Repo Plugin Not Found: Info message, continue with standalone spec (warning status)
  3. Issue Not Found (when work_id provided or auto-detected): Report error, suggest checking issue number (failure status)
  4. Template Not Found: Fall back to spec-basic.md.template (warning status)
  5. File Write Failed: Report error, check permissions (failure status)
  6. GitHub Comment Failed: Log warning, continue (warning status - non-critical)
  7. Insufficient Context: Warn but continue, use what's available (warning status)
  8. Template Auto-Detection Failed: Fall back to spec-basic.md.template (warning status)
  9. Slug Generation Failed: Fall back to timestamp-only naming (warning status)
  10. Slug Collision on Force: Generate timestamp-based unique suffix (warning status)

Error Response Format:

{
  "status": "failure",
  "message": "Brief description of failure",
  "details": {
    "operation": "generate-spec",
    "work_id": "123"
  },
  "errors": [
    "Specific error 1",
    "Specific error 2"
  ],
  "error_analysis": "Root cause explanation",
  "suggested_fixes": [
    "Actionable fix 1",
    "Actionable fix 2"
  ]
}

</ERROR_HANDLING>