# Speckit Bugfix Workflow
#
# Streamlined bugfix workflow using the speckit methodology:
# specify → plan → tasks → implement → verify
#
# Skips clarification for faster bug resolution. Otherwise follows
# the same structure as the feature workflow (early PR, per-phase commits).
#
# Inputs:
#   - description: Bug description text (required)
#   - issue_url: GitHub issue URL for bug context (optional)
#   - short_name: Branch short name override (optional)
#
name: speckit-bugfix

description: |
  Streamlined bugfix workflow following spec-driven development.
  Creates a feature branch, generates specification, creates a draft PR,
  then proceeds through planning, task generation, and implementation —
  committing and pushing after each phase. Skips clarification for faster
  turnaround on bug fixes.

version: "1.3.0"

inputs:
  - name: description
    description: Bug description used to generate spec content
    type: string
    required: true

  - name: issue_url
    description: GitHub issue URL for additional context
    type: string
    required: false

  - name: issue_number
    description: GitHub issue number to use as feature number
    type: number
    required: false

  - name: short_name
    description: Optional short name for the feature branch
    type: string
    required: false

phases:
  # Phase 1: Setup
  - name: setup
    steps:
      - name: create-feature
        uses: speckit.create_feature
        with:
          description: ${{ inputs.description }}
          short_name: ${{ inputs.short_name }}
          number: ${{ inputs.issue_number }}

  # Phase 2: Specification
  - name: specification
    steps:
      - name: specify
        uses: speckit.specify
        with:
          feature_dir: ${{ steps.create-feature.output.feature_dir }}
          issue_url: ${{ inputs.issue_url }}
          timeout: 600
        timeout: 660000  # 11 min

      - name: commit-spec
        uses: shell
        command: 'git add -A && git commit -m "spec: add specification for ${{ steps.create-feature.output.branch_name }}" --allow-empty'
        continueOnError: true

      - name: push-spec
        uses: shell
        command: git push --force-with-lease -u origin HEAD
        continueOnError: true

      - name: create-pr
        uses: pr.create
        with:
          title: "fix: ${{ steps.create-feature.output.branch_name }}"
          body: |
            Closes #${{ inputs.issue_number }}

            ## Summary
            ${{ steps.specify.output.summary }}

            ---
            *Draft PR created by speckit-bugfix workflow. Implementation in progress.*
          draft: true
        continueOnError: true

  # Phase 3: Planning
  - name: planning
    steps:
      - name: plan
        uses: speckit.plan
        with:
          feature_dir: ${{ steps.create-feature.output.feature_dir }}
          timeout: 900
        timeout: 960000  # 16 min

      - name: commit-plan
        uses: shell
        command: 'git add -A && git commit -m "spec: add implementation plan" --allow-empty'
        continueOnError: true

      - name: push-plan
        uses: shell
        command: git push
        continueOnError: true

  # Phase 4: Task Generation
  - name: task-generation
    steps:
      - name: tasks
        uses: speckit.tasks
        with:
          feature_dir: ${{ steps.create-feature.output.feature_dir }}
          timeout: 600
        timeout: 660000  # 11 min

      - name: commit-tasks
        uses: shell
        command: 'git add -A && git commit -m "spec: add task breakdown" --allow-empty'
        continueOnError: true

      - name: push-tasks
        uses: shell
        command: git push
        continueOnError: true

  # Phase 5: Implementation
  - name: implementation
    steps:
      - name: implement
        uses: speckit.implement
        with:
          feature_dir: ${{ steps.create-feature.output.feature_dir }}
        timeout: 3600000  # 1 hour max
        continueOnError: true  # partial work should still be committed/pushed

      - name: commit-implementation
        uses: shell
        command: 'git add -A && git commit -m "fix: implement ${{ steps.create-feature.output.branch_name }}" --allow-empty'
        continueOnError: true

      - name: push-implementation
        uses: shell
        command: git push
        continueOnError: true

  # Phase 6: Verification
  # build.validate auto-detects the package manager and discovers available
  # validation scripts (test, lint, format:check, typecheck, etc.).
  - name: verification
    steps:
      - name: run-validate
        uses: build.validate
        continueOnError: true
