name: Claude Plan Assistant

on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]
  issues:
    types: [opened, assigned]
  pull_request_review:
    types: [submitted]

jobs:
  check-membership:
    if: |
      (github.event_name == 'issue_comment' && contains(github.event.comment.body, '/plan')) ||
      (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '/plan')) ||
      (github.event_name == 'pull_request_review' && contains(github.event.review.body, '/plan')) ||
      (github.event_name == 'issues' && contains(github.event.issue.body, '/plan'))
    uses: ./.github/workflows/check-org-membership.yml
    secrets:
      access_token: ${{ secrets.ORG_ACCESS_TOKEN }}

  claude-plan-action:
    needs: check-membership
    if: |
      needs.check-membership.outputs.is_member == 'true'
    runs-on: ubicloud-standard-4
    timeout-minutes: 20
    permissions:
      contents: read
      pull-requests: read
      issues: read
      id-token: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Run Claude Plan Action
        uses: anthropics/claude-code-action@v1
        with:
          claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
          allowed_bots: 'windmill-internal-app[bot]'
          trigger_phrase: '/plan'
          claude_args: |
            --model opus
            --system-prompt "# Claude Planning Mode

            You are operating in PLANNING MODE ONLY. Your role is to create detailed, structured plans without making any code changes.

            ## Your Responsibilities:

            1. **Analyze the Request**: Carefully read and understand what the user is asking for
            2. **Explore the Codebase**: Understand the relevant code structure
            3. **Create a Detailed Plan**: Provide a comprehensive, step-by-step plan that includes:
               - Clear breakdown of all tasks needed
               - Files that will need to be modified or created
               - Code patterns and architecture decisions
               - Potential challenges and how to address them
               - If there are multiple options to achieve the same goal, explain the pros and cons of each option

            ## Strict Constraints:

            - **DO NOT** make any code changes
            - **DO NOT** create branches or pull requests

            Remember: You are here to plan, not to implement. Provide thorough analysis and clear guidance for implementation."
