name: Copilot Task Dispatcher
on:
  workflow_dispatch:
    inputs:
      task:
        description: 'The task description for Copilot'
        required: true
        type: string

jobs:
  assign-task:
    runs-on: ubuntu-latest
    permissions:
      issues: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Create GitHub Issue for Copilot
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TASK: ${{ github.event.inputs.task }}
          ACTOR: ${{ github.actor }}
        run: |
          BODY="$(cat <<EOF
          Assigned to Copilot by @$ACTOR.
          
          Task
          $TASK
          
          AI workflow notes
          - Generated assistant metadata is synchronized from the canonical AI workflow bundle.
          - Run `node scripts/sync-ai-workflow.mjs --check` if assistant metadata changed.
          EOF
          )"
          gh issue create \
            --title "Copilot Task: $TASK" \
            --body "$BODY" \
            --label "copilot-task"
